create event from calendar clicking on date

briinums-gdo's picture

I`m trying to make a calendar block with clickable dates. this is for a guest house to make reservations.Clicking on date would take to /node/add/my_event/2009-06-05 or /node/add/my_event/?date=05-05-2009 or similar. I want to pass the date as argument to "create content" form. any guest has access to create this type of node, but the default state is "unpublished" so that only administrator can approve (publish) the node. after that the created event would appear in calendar block and have CSS "has-event" definition (e.g. red color).
the problem is i have no idea how to pass date as argument. i can achieve this if i set the date field as simple text field by outputting the value with PHP (checking the $_GET['date']), but then it would not work as an event and wouldnt be displayed in calendar, since its just a textfield.
the date field allows only 3 default values - BLANK, NOW, and RELATIVE. it does not accept tokkens or php given arguments.
Can somebody help me out with this?

i need it in three simple steps:
1) guest visitor clicks on date
2) guest visitor has already filled date, fills out other fields and creates node (does not publish it)
3) admin checks and approves reservation node, publishes (doesnt show public), and the date appears in red color on the calendar block.

Thanks.
Valters

Comments

did it with javascript

briinums-gdo's picture

since i got no answer, had to continue on my own. so basically i edited calendar-mini.tpl.php to show different links, e.g. domain.com/go_reserve/?10.06.2009 . with .htaccess i created redirect from /go_reserve/* to /node/add/reservation?* so the link looks like domain.com/node/add/reservation?10.06.2009 or similar. in the end i edited page.tpl.php and added some javascript something like: if substring(0,45,document.location.href) = domain.com/node/add/reservation, then document.getElementById(some_datefield_id).value = substring(45,55,document.location.href);
that is the best i could do. but it works.

I would have said use the

joachim's picture

I would have said use the default value setting for the CCK date field, and theme your calendar view to put an add node link into each date.
Then your link is /node/add/event/2009-06-19

Same sort of approach :)

this info is exactly what I need

papps's picture

this info is exactly what I need - however the info is very condensed. I have a few questions joachim if you don't mind. Does you answer mean (und theme your calendar view to put an add node link ino each date.) that one has to do that with script in the templete? I was looking all over the internet to work out views and how to do that without scripting. I am a newbie to drupal but very excited about it. I think I could manage to insert some script somewhere if you would point out where to.
What I would like to achieve is that I have a link in each date and with this link a certain content type opens up-ready for content to be entered.
Thanks -

theme your calendar view to

joachim's picture

theme your calendar view to put an add node link ino each date

You're best off starting with the Drupal 6 theme guide.
Theming does involve coding in PHP, but this particular change should be simple. Just a question of finding the right template.

As for the URL prepopulating the new node form, I'm not sure what I mean....
There's prepopulate module for one; the other thing you can do is write default code for the CCK field that reads from arg(). Again, that's coding.

Thanks for pointing out the

papps's picture

Thanks for pointing out the right direction - I should be able to take it from here. And also I am impressed by the drupal community.
cheers !

What works for me

brockfanning's picture

In case it helps anyone else, here is what works for me, for allowing people to add events directly from the week and month views of the Calendar module:

  1. Copy the calendar-datebox-tpl.php file from the calendar/theme directory into your theme directory.

  2. Add this code before the existing code in calendar-datebox-tpl.php:
    (replace 'event' with the name of your content type)

    <?php if ($add_event_link): ?>
      <span class="add-event-link"><?php print $add_event_link; ?></span>
    <?php endif; ?>

  3. In a custom module, add two functions:
    (If you don't have a custom module, create one first. In Drupal 6 all you need is the .info file and the .module file. Try here for a guide: http://drupal.org/developing/modules)

    <?php
    // This function adds a '+' next to each datebox with a link to the event node creation page,
    // if the current user has permission to create events.
    // Replace 'mymodule' with the name of your module.
    // Replace 'event' with the name of your CCK content type.
    function mymodule_preprocess_calendar_datebox(&$vars) {
        global
    $user;
      if (
    user_access('create event content', $user)) {
           
    $vars['add_event_link'] = l('+', 'node/add/event/' . $vars['date'], array('attributes' => array('title' => 'Add an event')));
      }
    }
    // This function prepopulates the time field when the event is created.
    // Replace 'mymodule' with the name of your module.
    // Replace 'event' with the name of your CCK content type.
    // Replace 'time' with the name of your date field.
    function mymodule_form_alter(&$form, $form_state, $form_id) {
    if (
    $form_id == 'event_node_form' && arg(3) != '') {
          
    $form['field_time']['#default_value']['value'] = arg(3) . ' 12:00:00';
        
    $form['field_time']['#default_value']['value2'] = arg(3) . ' 13:00:00';
        }
    }
    ?>

  4. Add some css styling to make the '+' link appear correctly. This probably depends a lot on what you're already done as far as css, but for me this css code puts the '+' link right up against the datebox:

    .add-event-link {
    margin-left: 70%;
      padding-left: 2px;
    }

Hope that helps.

For me

trianam's picture

Hi,
Brockfanning for me the form_alter hook must be:

<?php
function mymodule_form_alter(&$form, $form_state, $form_id) {
if (
$form_id == 'event_node_form' && arg(3) != '') {
    
$form['field_time'][0]['#default_value']['value'] = arg(3) . ' 12:00:00';
    
$form['field_time'][0]['#default_value']['value2'] = arg(3) . ' 13:00:00';
    }
}
?>

(also look at http://drupal.org/node/726282)

Thanks

Renee S's picture

Thanks, this worked great for me. I omitted changing the time on the form, since they're likely going to set that to something different anyway. :)

This is great! A couple of

mtconto's picture

This is great! A couple of questions...

1) I use Drupal Commons and when I implement the above code, it effects my groups calendar in addition to the view of a cloned calendar I created. I want the "+" sign and corresponding form to show up only for the view for the cloned calendar (named "calendarlog").

2) When I click on the plus sign, the form doesn't have the date field! Yet, when if I go to content manage, create content and click on my content, the date field is in the form. I'm using 'field_date' as my field, not 'field_time'. I noticed if I leave 'field_time' I see the date field, but if I put field_date, which is the field I should have, the date field disappears on the form... but only when I click the '+'.

3) Finally, I want the form to "popup" rather then go to the form page. I found a module that creates popups rather then redirecting to a new page. Conveniently, its called "popup". Any ideas how to integrate "popup" with the '+' sign?

Thanks for any help!

Hi, mtconto, for the first

trianam's picture

Hi, mtconto, for the first point: I think that you should change the template calendar-datebox.tpl.php adding a control on variable $view, making the code

<?php if ($add_event_link): ?>
  <span class="add-event-link"><?php print $add_event_link; ?></span>
<?php endif; ?>

visible only in case you are viewing the right view.
Maybe a better alternative can be putting that code only in a template of your view (see the theme information link of your view administration).
Bye.

Any workaround available for

apoc1's picture

Any workaround available for D7?

i want to do it in D7 too!

adamtong's picture

i want to do it in D7 too!

Event Management Systems

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week