2 require_once('pre.php');
3 include_once 'includes/init.php';
4 include_once 'includes/site_extras.php';
5 load_user_categories ();
11 if ( ! empty ( $override ) && ! empty ( $override_date ) ) {
12 // override date specified. user is going to create an exception
13 // to a repeating event.
17 // Remember previous cal_goup_id if present
18 $old_id = ( ! empty ( $parent ) ? $parent : $old_id );
20 if ( empty ( $TZ_OFFSET ) ) {
24 if ( empty ( $endhour ) ) {
27 // Modify the time to be server time rather than user time.
28 if ( ! empty ( $hour ) && ( $timetype == 'T' ) ) {
29 // Convert to 24 hour before subtracting TZ_OFFSET so am/pm isn't confused.
30 // Note this obsoltes any code in the file below that deals with am/pm
31 // so the code can be deleted
32 if ( $TIME_FORMAT == '12' && $hour < 12 ) {
35 } elseif ($TIME_FORMAT == '12' && $hour == '12' && $ampm == 'am' ) {
38 if ( $GLOBALS['TIMED_EVT_LEN'] == 'E') {
39 if ( isset ( $endhour ) && $TIME_FORMAT == '12' ) {
40 // Convert end time to a twenty-four hour time scale.
41 if ( $endampm == 'pm' && $endhour < 12 ) {
43 } elseif ( $endampm == 'am' && $endhour == 12 ) {
53 $date = mktime ( 3, 0, 0, $month, $day, $year );
55 $month = date ( "m", $date );
56 $day = date ( "d", $date );
57 $year = date ( "Y", $date );
62 $date = mktime ( 3, 0, 0, $month, $day, $year );
64 $month = date ( "m", $date );
65 $day = date ( "d", $date );
66 $year = date ( "Y", $date );
69 // Must adjust $endhour too
71 $endhour -= $TZ_OFFSET;
72 if ( $endhour < 0 ) $endhour += 24;
73 if ( $endhour >= 24 ) $endhour -= 24;
77 // Make sure this user is really allowed to edit this event.
78 // Otherwise, someone could hand type in the URL to edit someone else's
83 // - user created event
84 // - user is participant
86 // value may be needed later for recreating event
87 $old_create_by = ( ! empty ( $user )? $user : '');
88 if ( empty ( $id ) ) {
92 // event owner or assistant event ?
93 $sql = "SELECT cal_create_by FROM webcal_entry WHERE cal_id = '$id'";
94 $res = dbi_query($sql);
96 $row = dbi_fetch_row ( $res );
97 // value may be needed later for recreating event
98 $old_create_by = $row[0];
99 if (( $row[0] == $login ) || (( $user == $row[0] ) && ( $is_assistant || $is_nonuser_admin )))
101 dbi_free_result ( $res );
103 $error = translate("Database error") . ": " . dbi_error ();
108 if ( empty ( $error ) && ! $can_edit ) {
109 // is user a participant of that event ?
110 $sql = "SELECT cal_id FROM webcal_entry_user WHERE cal_id = '$id' " .
111 "AND cal_login = '$login' AND cal_status IN ('W','A')";
112 $res = dbi_query ( $sql );
114 $row = dbi_fetch_row ( $res );
115 if ( ! empty( $row[0] ) )
116 $can_edit = true; // is participant
117 dbi_free_result ( $res );
119 $error = translate("Database error") . ": " . dbi_error ();
122 if ( ! $can_edit && empty ( $error ) ) {
123 $error = translate ( "You are not authorized" );
126 // If display of participants is disabled, set the participant list
127 // to the event creator. This also works for single-user mode.
128 // Basically, if no participants were selected (because there
129 // was no selection list available in the form or because the user
130 // refused to select any participant from the list), then we will
131 // assume the only participant is the current user.
132 if ( empty ( $participants[0] ) ) {
133 $participants[0] = $login;
134 // There might be a better way to do this, but if Admin sets this value,
135 // WebCalendar should respect it
136 if ( ! empty ( $public_access_default_selected ) &&
137 $public_access_default_selected == "Y" ) {
138 $participants[1] = "__public__";
141 // If "all day event" was selected, then we set the event time
142 // to be 12AM with a duration of 24 hours.
143 // We don't actually store the "all day event" flag per se. This method
144 // makes conflict checking much simpler. We just need to make sure
145 // that we don't screw up the day view (which normally starts the
146 // view with the first timed event).
147 // Note that if someone actually wants to create an event that starts
148 // at midnight and lasts exactly 24 hours, it will be treated in the
151 $duration_h = getValue ( "duration_h" );
152 $duration_m = getValue ( "duration_m" );
154 if ( $timetype == "A" ) {
161 $duration = ( $duration_h * 60 ) + $duration_m;
162 if ( $hour > 0 && $timetype != 'U' ) {
163 if ( $TIME_FORMAT == '12' ) {
165 //This way, a user can pick am and still
166 //enter a 24 hour clock time.
167 if ($hour > 12 && $ampm == 'am') {
171 if ( $ampmt == 'pm' ) {
176 //echo "SERVER HOUR: $hour $ampm";
178 if ( $GLOBALS['TIMED_EVT_LEN'] == 'E' && $timetype == "T" ) {
179 if ( ! isset ( $endhour ) ) {
182 // Calculate duration.
183 $endmins = ( 60 * (int) ( $endhour ) ) + $endminute;
184 $startmins = ( 60 * $hour ) + $minute;
185 $duration = $endmins - $startmins;
187 if ( $duration < 0 ) {
192 // handle external participants
193 $ext_names = array ();
194 $ext_emails = array ();
197 if ( $single_user == "N" &&
198 ! empty ( $allow_external_users ) &&
199 $allow_external_users == "Y" &&
200 ! empty ( $externalparticipants ) ) {
201 $lines = explode ( "\n", $externalparticipants );
202 if ( ! is_array ( $lines ) ) {
203 $lines = array ( $externalparticipants );
205 if ( is_array ( $lines ) ) {
206 for ( $i = 0; $i < count ( $lines ); $i++ ) {
207 $ext_words = explode ( " ", $lines[$i] );
208 if ( ! is_array ( $ext_words ) ) {
209 $ext_words = array ( $lines[$i] );
211 if ( is_array ( $ext_words ) ) {
212 $ext_names[$ext_count] = "";
213 $ext_emails[$ext_count] = "";
214 for ( $j = 0; $j < count ( $ext_words ); $j++ ) {
215 // use regexp matching to pull email address out
216 $ext_words[$j] = chop ( $ext_words[$j] ); // remove \r if there is one
217 if ( preg_match ( "/<?\\S+@\\S+\\.\\S+>?/", $ext_words[$j],
219 $ext_emails[$ext_count] = $matches[0];
220 $ext_emails[$ext_count] = preg_replace ( "/[<>]/", "",
221 $ext_emails[$ext_count] );
223 if ( strlen ( $ext_names[$ext_count] ) ) {
224 $ext_names[$ext_count] .= " ";
226 $ext_names[$ext_count] .= $ext_words[$j];
229 // Test for duplicate Names
231 for ( $k = $i ; $k > 0 ; $k-- ) {
232 if ( $ext_names[$i] == $ext_names[$k] ) {
233 $ext_names[$i] .= "[$k]";
237 if ( strlen ( $ext_emails[$ext_count] ) &&
238 empty ( $ext_names[$ext_count] ) ) {
239 $ext_names[$ext_count] = $ext_emails[$ext_count];
247 // first check for any schedule conflicts
248 if ( empty ( $allow_conflict_override ) || $allow_conflict_override != "Y" ) {
249 $confirm_conflicts = ""; // security precaution
251 if ( $allow_conflicts != "Y" && empty ( $confirm_conflicts ) &&
252 strlen ( $hour ) > 0 && $timetype != 'U' ) {
253 $date = mktime ( 3, 0, 0, $month, $day, $year );
254 $str_cal_date = date ( "Ymd", $date );
255 if ( strlen ( $hour ) > 0 ) {
256 $str_cal_time = sprintf ( "%02d%02d00", $hour, $minute );
258 if ( ! empty ( $rpt_end_use ) ) {
259 $endt = mktime ( 3, 0, 0, $rpt_month, $rpt_day,$rpt_year );
264 if ($rpt_type == 'weekly') {
265 $dayst = ( empty( $rpt_sun ) ? 'n' : 'y' )
266 . ( empty( $rpt_mon ) ? 'n' : 'y' )
267 . ( empty( $rpt_tue ) ? 'n' : 'y' )
268 . ( empty( $rpt_wed ) ? 'n' : 'y' )
269 . ( empty( $rpt_thu ) ? 'n' : 'y' )
270 . ( empty( $rpt_fri ) ? 'n' : 'y' )
271 . ( empty( $rpt_sat ) ? 'n' : 'y' );
276 // Load exception days... but not for a new event (which can't have
277 // exception dates yet)
279 if ( ! empty ( $id ) ) {
280 $res = dbi_query ( "SELECT cal_date FROM webcal_entry_repeats_not " .
281 "WHERE cal_id = $id" );
283 while ( $row = dbi_fetch_row ( $res ) ) {
284 $ex_days[] = $row[0];
286 dbi_free_result ( $res );
288 $error = translate("Database error") . ": " . dbi_error ();
292 $dates = get_all_dates ( $date, $rpt_type, $endt, $dayst,
293 $ex_days, $rpt_freq );
295 $conflicts = check_for_conflicts ( $dates, $duration, $hour, $minute,
296 $participants, $login, empty ( $id ) ? 0 : $id );
298 if ( empty ( $error ) && ! empty ( $conflicts ) ) {
299 $error = translate("The following conflicts with the suggested time") .
300 ": <ul>$conflicts</ul>";
302 //Avoid Undefined variable message
304 if ( empty ( $error ) ) {
306 // now add the entries
307 if ( empty ( $id ) || $do_override ) {
308 $res = dbi_query ( "SELECT MAX(cal_id) FROM webcal_entry" );
310 $row = dbi_fetch_row ( $res );
312 dbi_free_result ( $res );
318 // save old status values of participants
319 $sql = "SELECT cal_login, cal_status, cal_category FROM webcal_entry_user " .
320 "WHERE cal_id = $id ";
321 $res = dbi_query ( $sql );
323 for ( $i = 0; $tmprow = dbi_fetch_row ( $res ); $i++ ) {
324 $old_status[$tmprow[0]] = $tmprow[1];
325 $old_category[$tmprow[0]] = $tmprow[2];
327 dbi_free_result ( $res );
329 $error = translate("Database error") . ": " . dbi_error ();
331 if ( empty ( $error ) ) {
332 dbi_query ( "DELETE FROM webcal_entry WHERE cal_id = $id" );
333 dbi_query ( "DELETE FROM webcal_entry_user WHERE cal_id = $id" );
334 dbi_query ( "DELETE FROM webcal_entry_ext_user WHERE cal_id = $id" );
335 dbi_query ( "DELETE FROM webcal_entry_repeats WHERE cal_id = $id" );
336 dbi_query ( "DELETE FROM webcal_site_extras WHERE cal_id = $id" );
341 if ( $do_override ) {
342 $sql = "INSERT INTO webcal_entry_repeats_not ( cal_id, cal_date ) " .
343 "VALUES ( $old_id, $override_date )";
344 if ( ! dbi_query ( $sql ) ) {
345 $error = translate("Database error") . ": " . dbi_error ();
348 $sql = "INSERT INTO webcal_entry ( cal_id, " .
349 ( $old_id > 0 ? " cal_group_id, " : "" ) .
350 "cal_create_by, cal_date, " .
351 "cal_time, cal_mod_date, cal_mod_time, cal_duration, cal_priority, " .
352 "cal_access, cal_type, cal_name, cal_description ) " .
354 ( $old_id > 0 ? " $old_id, " : "" ) .
355 "'" . ( ! empty ( $old_create_by ) &&
356 ( ( $is_admin && ! $newevent ) || $is_assistant ||
357 $is_nonuser_admin ) ? $old_create_by : $login ) . "', ";
359 $date = mktime ( 3, 0, 0, $month, $day, $year );
360 $sql .= date ( "Ymd", $date ) . ", ";
361 if ( strlen ( $hour ) > 0 && $timetype != 'U' ) {
362 $sql .= sprintf ( "%02d%02d00, ", $hour, $minute );
366 $sql .= date ( "Ymd" ) . ", " . date ( "Gis" ) . ", ";
367 $sql .= sprintf ( "%d, ", $duration );
368 $sql .= ! empty ( $priority ) ? sprintf ( "%d,", $priority ) : "2,";
369 $sql .= empty ( $access ) ? "'P', " : "'$access', ";
370 if ( ! empty ( $rpt_type ) && $rpt_type != 'none' ) {
376 if ( strlen ( $name ) == 0 ) {
377 $name = translate("Unnamed Event");
379 $sql .= "'" . $name . "', ";
380 if ( strlen ( $description ) == 0 ) {
381 $description = $name;
383 $sql .= "'" . $description . "' )";
385 if ( empty ( $error ) ) {
386 if ( ! dbi_query ( $sql ) ) {
387 $error = translate("Database error") . ": " . dbi_error ();
394 plugin_hook('add_cal_link_father_event',$params);
399 activity_log ( $id, $login, ($is_assistant || $is_nonuser_admin ? $user : $login),
400 $newevent ? $LOG_CREATE : $LOG_UPDATE, "" );
402 if ( $single_user == "Y" ) {
403 $participants[0] = $single_user_login;
406 // check if participants have been removed and send out emails
407 if ( ! $newevent && count ( $old_status ) > 0 ) { // nur bei Update!!!
408 while ( list ( $old_participant, $dummy ) = each ( $old_status ) ) {
410 for ( $i = 0; $i < count ( $participants ); $i++ ) {
411 if ( $participants[$i] == $old_participant ) {
416 $is_nonuser_admin = user_is_nonuser_admin ( $login, $old_participant );
417 // Don't send mail if we are editing a non-user calendar
418 // and we are the admin
419 if ( !$found_flag && !$is_nonuser_admin) {
420 // only send mail if their email address is filled in
421 $do_send = get_pref_setting ( $old_participant, "EMAIL_EVENT_DELETED" );
422 $user_TZ = get_pref_setting ( $old_participant, "TZ_OFFSET" );
423 $user_language = get_pref_setting ( $old_participant, "LANGUAGE" );
424 user_load_variables ( $old_participant, "temp" );
425 if ( $old_participant != $login && strlen ( $tempemail ) &&
426 $do_send == "Y" && $send_email != "N" ) {
428 // Want date/time in user's timezone
429 $user_hour = $hour + $user_TZ;
430 if ( $user_hour < 0 ) {
433 $user_date = mktime ( 3, 0, 0, $month, $day, $year );
434 $user_date -= $ONE_DAY;
435 $user_month = date ( "m", $date );
436 $user_day = date ( "d", $date );
437 $user_year = date ( "Y", $date );
438 } elseif ( $user_hour >= 24 ) {
441 $user_date = mktime ( 3, 0, 0, $month, $day, $year );
442 $user_date += $ONE_DAY;
443 $user_month = date ( "m", $date );
444 $user_day = date ( "d", $date );
445 $user_year = date ( "Y", $date );
447 $user_month = $month;
451 if (($GLOBALS['LANGUAGE'] != $user_language) &&
452 ! empty ( $user_language ) && ( $user_language != 'none' )){
453 reset_language ( $user_language );
455 //do_debug($user_language);
456 $fmtdate = sprintf ( "%04d%02d%02d", $user_year, $user_month, $user_day );
457 $msg = translate("Hello") . ", " . $tempfullname . ".\n\n" .
458 translate("An appointment has been canceled for you by") .
459 " " . $login_fullname . ". " .
460 translate("The subject was") . " \"" . $name . "\"\n\n" .
461 translate("The description is") . " \"" . $description . "\"\n" .
462 translate("Date") . ": " . date_to_str ( $fmtdate ) . "\n" .
463 ( ( empty ( $user_hour ) && empty ( $minute ) ) ? "" :
464 translate("Time") . ": " .
465 display_time ( ( $user_hour * 10000 ) + ( $minute * 100 ), true ) ) .
467 // add URL to event, if we can figure it out
469 if ( ! empty ( $server_url ) ) {
470 $url = $server_url . "view_entry.php?id=" . $id;
471 $msg .= $url . "\n\n";
474 if ( strlen ( $login_email ) ) {
475 $extra_hdrs = "From: $login_email\r\nX-Mailer: " . translate($application_name);
477 $extra_hdrs = "From: $email_fallback_from\r\nX-Mailer: " . translate($application_name);
480 translate($application_name) . " " . translate("Notification") . ": " . $name,
481 utf8_decode(html_to_8bits ($msg)), $extra_hdrs );
482 activity_log ( $id, $login, $old_participant, $LOG_NOTIFICATION,
483 "User removed from participants list" );
489 // now add participants and send out notifications
491 for ( $i = 0; $i < count ( $participants ); $i++ ) {
494 // Is the person adding the nonuser calendar admin
495 $is_nonuser_admin = user_is_nonuser_admin ( $login, $participants[$i] );
497 // if public access, require approval unless
498 // $public_access_add_needs_approval is set to "N"
499 if ( $login == "__public__" ) {
500 if ( ! empty ( $public_access_add_needs_approval ) &&
501 $public_access_add_needs_approval == "N" ) {
502 $status = "A"; // no approval needed
505 $status = "W"; // approval required
507 $my_cat_id = $cat_id;
508 } else if ( ! $newevent ) {
509 // keep the old status if no email will be sent
510 $send_user_mail = ( empty ( $old_status[$participants[$i]] ) ||
511 $entry_changed ) ? true : false;
512 $tmp_status = ( ! empty ( $old_status[$participants[$i]] ) && ! $send_user_mail ) ?
513 $old_status[$participants[$i]] : "W";
514 $status = ( $participants[$i] != $login && boss_must_approve_event ( $login, $participants[$i] ) && $require_approvals == "Y" && ! $is_nonuser_admin ) ?
516 $tmp_cat = ( ! empty ( $old_category[$participants[$i]]) ) ?
517 $old_category[$participants[$i]] : 'NULL';
518 $tmp_cat = ( $participants[$i] == $user ) ? $cat_id : $tmp_cat;
519 // Allow cat to be changed for public access (if admin user)
520 if ( $participants[$i] == "__public__" && $is_admin ) {
524 // If user is admin and this event was previously approved for public,
525 // keep it as approved even though date/time may have changed
526 // This goes against stricter security, but it confuses users to have
527 // to re-approve events they already approved.
528 if ( $participants[$i] == "__public__" && $is_admin &&
529 $old_status['__public__'] == 'A' ) {
532 $my_cat_id = ( $participants[$i] != $login ) ? $tmp_cat : $cat_id;
533 // If user is admin and
534 // if it's a global cat, then set it for other users as well.
535 if ( $is_admin && ! empty ( $categories[$cat_id] ) &&
536 empty ( $category_owners[$cat_id] ) ) {
537 // found categ. and owner set to NULL; it is global
538 $my_cat_id = $cat_id;
540 } else { // New Event
542 $send_user_mail = true;
543 $status = ( $participants[$i] != $login &&
544 boss_must_approve_event ( $login, $participants[$i] ) &&
545 $require_approvals == "Y" && ! $is_nonuser_admin ) ?
547 // If admin, no need to approve Public Access Events
548 if ( $participants[$i] == "__public__" && $is_admin ) {
551 if ( $participants[$i] == $login ) {
552 $my_cat_id = $cat_id;
554 // if it's a global cat, then set it for other users as well.
555 if ( ! empty ( $categories[$cat_id] ) &&
556 empty ( $category_owners[$cat_id] ) ) {
557 // found cat. and owner set to NULL; it is global
558 $my_cat_id = $cat_id;
560 // not global category
566 // Some users report that they get an error on duplicate keys
567 // on the following add... As a safety measure, delete any
568 // existing entry with the id. Ignore the result.
569 dbi_query ( "DELETE FROM webcal_entry_user WHERE cal_id = $id " .
570 "AND cal_login = '$participants[$i]'" );
571 if ( empty ( $my_cat_id ) ) $my_cat_id = 'NULL';
572 $sql = "INSERT INTO webcal_entry_user " .
573 "( cal_id, cal_login, cal_status, cal_category ) VALUES ( $id, '" .
574 $participants[$i] . "', '$status', $my_cat_id )";
575 if ( ! dbi_query ( $sql ) ) {
576 $error = translate("Database error") . ": " . dbi_error ();
579 // Don't send mail if we are editing a non-user calendar
580 // and we are the admin
581 if (!$is_nonuser_admin) {
583 if ( empty ( $from ) && ! empty ( $email_fallback_from ) )
584 $from = $email_fallback_from;
585 // only send mail if their email address is filled in
586 $do_send = get_pref_setting ( $participants[$i],
587 $newevent ? "EMAIL_EVENT_ADDED" : "EMAIL_EVENT_UPDATED" );
588 $user_TZ = get_pref_setting ( $participants[$i], "TZ_OFFSET" );
589 $user_language = get_pref_setting ( $participants[$i], "LANGUAGE" );
590 user_load_variables ( $participants[$i], "temp" );
593 if ( $participants[$i] != $login &&
594 boss_must_be_notified ( $login, $participants[$i] ) &&
595 strlen ( $tempemail ) &&
596 $do_send == "Y" && $send_user_mail && $send_email != "N" ) {
598 // Want date/time in user's timezone
599 $user_hour = $hour + $user_TZ;
600 if ( $user_hour < 0 ) {
603 $user_date = mktime ( 3, 0, 0, $month, $day, $year );
604 $user_date -= $ONE_DAY;
605 $user_month = date ( "m", $date );
606 $user_day = date ( "d", $date );
607 $user_year = date ( "Y", $date );
608 } elseif ( $user_hour >= 24 ) {
611 $user_date = mktime ( 3, 0, 0, $month, $day, $year );
612 $user_date += $ONE_DAY;
613 $user_month = date ( "m", $date );
614 $user_day = date ( "d", $date );
615 $user_year = date ( "Y", $date );
617 $user_month = $month;
621 if (($GLOBALS['LANGUAGE'] != $user_language) &&
622 ! empty ( $user_language ) && ( $user_language != 'none' )) {
623 reset_language ( $user_language );
625 //do_debug($user_language);
626 $fmtdate = sprintf ( "%04d%02d%02d", $user_year, $user_month, $user_day );
627 $msg = translate("Hello") . ", " . $tempfullname . ".\n\n";
628 if ( $newevent || ( empty ( $old_status[$participants[$i]] ) ) ) {
629 $msg .= translate("A new appointment has been made for you by");
631 $msg .= translate("An appointment has been updated by");
633 $msg .= " " . $login_fullname . ". " .
634 translate("The subject is") . " \"" . $name . "\"\n\n" .
635 translate("The description is") . " \"" . $description . "\"\n" .
636 translate("Date") . ": " . date_to_str ( $fmtdate ) . "\n" .
637 ( ( empty ( $user_hour ) && empty ( $minute ) ) ? "" :
638 translate("Time") . ": " .
639 display_time ( ( $user_hour * 10000 ) + ( $minute * 100 ), true ) . "\n" ) .
640 translate("Please look on") . " " . translate($application_name) . " " .
641 ( $require_approvals == "Y" ?
642 translate("to accept or reject this appointment") :
643 translate("to view this appointment") ) . ".";
644 // add URL to event, if we can figure it out
646 if ( ! empty ( $server_url ) ) {
647 $url = $server_url . "view_entry.php?id=" . $id;
648 $msg .= "\n\n" . $url;
651 if ( strlen ( $from ) ) {
652 $extra_hdrs = "From: $from\r\nX-Mailer: " . translate($application_name);
654 $extra_hdrs = "X-Mailer: " . translate($application_name);
659 translate($application_name) . " " . translate("Notification") . ": " . $name,
660 utf8_decode(html_to_8bits ($msg)), $extra_hdrs );
661 activity_log ( $id, $login, $participants[$i], $LOG_NOTIFICATION, "" );
668 // add external participants
669 // send notification if enabled.
670 if ( is_array ( $ext_names ) && is_array ( $ext_emails ) ) {
671 for ( $i = 0; $i < count ( $ext_names ); $i++ ) {
672 if ( strlen ( $ext_names[$i] ) ) {
673 $sql = "INSERT INTO webcal_entry_ext_user " .
674 "( cal_id, cal_fullname, cal_email ) VALUES ( " .
675 "$id, '$ext_names[$i]', ";
676 if ( strlen ( $ext_emails[$i] ) ) {
677 $sql .= "'$ext_emails[$i]' )";
681 if ( ! dbi_query ( $sql ) ) {
682 $error = translate("Database error") . ": " . dbi_error ();
684 // send mail notification if enabled
685 // TODO: move this code into a function...
686 if ( $external_notifications == "Y" && $send_email != "N" &&
687 strlen ( $ext_emails[$i] ) > 0 ) {
688 $fmtdate = sprintf ( "%04d%02d%02d", $year, $month, $day );
689 // Strip [\d] from duplicate Names before emailing
690 $ext_names[$i] = trim(preg_replace( '/\[[\d]]/', "", $ext_names[$i]) );
691 $msg = translate("Hello") . ", " . $ext_names[$i] . ".\n\n";
693 $msg .= translate("A new appointment has been made for you by");
695 $msg .= translate("An appointment has been updated by");
697 $msg .= " " . $login_fullname . ". " .
698 translate("The subject is") . " \"" . $name . "\"\n\n" .
699 translate("The description is") . " \"" . $description . "\"\n" .
700 translate("Date") . ": " . date_to_str ( $fmtdate ) . "\n" .
701 ( ( empty ( $hour ) && empty ( $minute ) ) ? "" :
702 translate("Time") . ": " .
703 display_time ( ( $hour * 10000 ) + ( $minute * 100 ) ) . "\n" ) .
704 translate("Please look on") . " " . translate($application_name) .
706 // add URL to event, if we can figure it out
708 if ( ! empty ( $server_url ) ) {
709 $url = $server_url . "view_entry.php?id=" . $id;
710 $msg .= "\n\n" . $url;
713 if ( strlen ( $from ) ) {
714 $extra_hdrs = "From: $from\r\nX-Mailer: " . translate($application_name);
716 $extra_hdrs = "X-Mailer: " . translate($application_name);
718 mail ( $ext_emails[$i],
719 translate($application_name) . " " .
720 translate("Notification") . ": " . $name,
721 utf8_decode(html_to_8bits ($msg)), $extra_hdrs );
729 for ( $i = 0; $i < count ( $site_extras ) && empty ( $error ); $i++ ) {
731 $extra_name = $site_extras[$i][0];
732 $extra_type = $site_extras[$i][2];
733 $extra_arg1 = $site_extras[$i][3];
734 $extra_arg2 = $site_extras[$i][4];
735 $value = $$extra_name;
736 //echo "Looking for $extra_name... value = " . $value . " ... type = " .
737 // $extra_type . "<br />\n";
738 if ( strlen ( $$extra_name ) || $extra_type == $EXTRA_DATE ) {
739 if ( $extra_type == $EXTRA_URL || $extra_type == $EXTRA_EMAIL ||
740 $extra_type == $EXTRA_TEXT || $extra_type == $EXTRA_USER ||
741 $extra_type == $EXTRA_MULTILINETEXT ||
742 $extra_type == $EXTRA_SELECTLIST ) {
743 $sql = "INSERT INTO webcal_site_extras " .
744 "( cal_id, cal_name, cal_type, cal_data ) VALUES ( " .
745 "$id, '$extra_name', $extra_type, '$value' )";
746 } else if ( $extra_type == $EXTRA_REMINDER && $value == "1" ) {
747 if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_DATE ) > 0 ) {
748 $yname = $extra_name . "year";
749 $mname = $extra_name . "month";
750 $dname = $extra_name . "day";
751 $edate = sprintf ( "%04d%02d%02d", $$yname, $$mname, $$dname );
752 $sql = "INSERT INTO webcal_site_extras " .
753 "( cal_id, cal_name, cal_type, cal_remind, cal_date ) VALUES ( " .
754 "$id, '$extra_name', $extra_type, 1, $edate )";
755 } else if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET ) > 0 ) {
756 $dname = $extra_name . "_days";
757 $hname = $extra_name . "_hours";
758 $mname = $extra_name . "_minutes";
759 $minutes = ( $$dname * 24 * 60 ) + ( $$hname * 60 ) + $$mname;
760 $sql = "INSERT INTO webcal_site_extras " .
761 "( cal_id, cal_name, cal_type, cal_remind, cal_data ) VALUES ( " .
762 "$id, '$extra_name', $extra_type, 1, '" . $minutes . "' )";
764 $sql = "INSERT INTO webcal_site_extras " .
765 "( cal_id, cal_name, cal_type, cal_remind ) VALUES ( " .
766 "$id, '$extra_name', $extra_type, 1 )";
768 } else if ( $extra_type == $EXTRA_DATE ) {
769 $yname = $extra_name . "year";
770 $mname = $extra_name . "month";
771 $dname = $extra_name . "day";
772 $edate = sprintf ( "%04d%02d%02d", $$yname, $$mname, $$dname );
773 $sql = "INSERT INTO webcal_site_extras " .
774 "( cal_id, cal_name, cal_type, cal_date ) VALUES ( " .
775 "$id, '$extra_name', $extra_type, $edate )";
778 if ( strlen ( $sql ) && empty ( $error ) ) {
779 //echo "SQL: $sql<BR>\n";
780 if ( ! dbi_query ( $sql ) ) {
781 $error = translate("Database error") . ": " . dbi_error ();
786 // clearly, we want to delete the old repeats, before inserting new...
787 if ( empty ( $error ) ) {
788 if ( ! dbi_query ( "DELETE FROM webcal_entry_repeats WHERE cal_id = $id") ) {
789 $error = translate("Database error") . ": " . dbi_error ();
791 // add repeating info
792 if ( ! empty ( $rpt_type ) && strlen ( $rpt_type ) && $rpt_type != 'none' ) {
793 $freq = ( $rpt_freq ? $rpt_freq : 1 );
794 if ( ! empty ( $rpt_end_use ) ) {
795 $end = sprintf ( "%04d%02d%02d", $rpt_year, $rpt_month, $rpt_day );
799 if ($rpt_type == 'weekly') {
800 $days = ( empty( $rpt_sun ) ? 'n' : 'y' )
801 . ( empty( $rpt_mon ) ? 'n' : 'y' )
802 . ( empty( $rpt_tue ) ? 'n' : 'y' )
803 . ( empty( $rpt_wed ) ? 'n' : 'y' )
804 . ( empty( $rpt_thu ) ? 'n' : 'y' )
805 . ( empty( $rpt_fri ) ? 'n' : 'y' )
806 . ( empty( $rpt_sat ) ? 'n' : 'y' );
811 $sql = "INSERT INTO webcal_entry_repeats ( cal_id, " .
812 "cal_type, cal_end, cal_days, cal_frequency ) VALUES " .
813 "( $id, '$rpt_type', $end, '$days', $freq )";
815 $msg .= "<span style=\"font-weight:bold;\">SQL:</span> $sql<br />\n<br />";
820 // If we were editing this event, then go back to the last view (week, day,
821 // month). If this is a new event, then go to the preferred view for
822 // the date range that this event was added to.
823 if ( empty ( $error ) ) {
824 $xdate = sprintf ( "%04d%02d%02d", $year, $month, $day );
825 $user_args = ( empty ( $user ) ? '' : "user=$user" );
826 send_to_preferred_view ( $xdate, $user_args );
830 if ( strlen ( $conflicts ) ) {
832 <h2><?php etranslate("Scheduling Conflict")?></h2>
834 <?php etranslate("Your suggested time of")?> <span style="font-weight:bold;">
836 if ( ! empty ( $allday ) && $allday == "Y" ) {
837 etranslate("All day event");
839 $time = sprintf ( "%d%02d00", $hour, $minute );
840 echo display_time ( $time );
842 echo "-" . display_time ( add_duration ( $time, $duration ) );
844 ?></span> <?php etranslate("conflicts with the following existing calendar entries")?>:
846 <?php echo $conflicts; ?>
850 // user can confirm conflicts
851 echo "<form name=\"confirm\" method=\"post\">\n";
852 if ( ! is_array ( $_POST ) && is_array ( $HTTP_POST_VARS ) )
853 $_POST = $HTTP_POST_VARS;
854 foreach ($_POST as $xkey=>$xval ) {
855 if (is_array($xval)) {
857 foreach ( $xval as $ykey=>$yval ) {
858 if (get_magic_quotes_gpc())
859 $yval = stripslashes($yval);
860 $yval = htmlentities ( $yval );
861 echo "<input type=\"hidden\" name=\"$xkey\" value=\"$yval\" />\n";
864 if (get_magic_quotes_gpc())
865 $xval = stripslashes($xval);
866 $xval = htmlentities ( $xval );
867 echo "<input type=\"hidden\" name=\"$xkey\" value=\"$xval\" />\n";
874 // Allow them to override a conflict if server settings allow it
875 if ( ! empty ( $allow_conflict_override ) &&
876 $allow_conflict_override == "Y" ) {
877 echo "<td><input type=\"submit\" name=\"confirm_conflicts\" " .
878 "value=\"" . translate("Save") . "\" /></td>\n";
881 <td><input type="button" value="<?php etranslate("Cancel")?>"
882 onclick="history.back()" /><td>
888 <h2><?php etranslate("Error")?></h2>
890 <?php echo $error; ?>
894 <?php print_trailer(); ?>