[ Index ] |
|
Code source de WebCalendar 1.0.5 |
1 <?php 2 /* 3 * $Id: get_reminders.php,v 1.1 2004/06/24 02:18:30 cknudsen Exp $ 4 * 5 * Description: 6 * Web Service functionality for reminders. 7 * Uses XML (but not SOAP at this point since that would be 8 * overkill and require extra packages to install). 9 * 10 * Comments: 11 * Some of this code was borrowed from send_reminders.php. 12 * 13 * This functionality works somewhat independent of the email-based 14 * send_reminders.php script. If the end user intends to use 15 * client-side reminders, they should set "Event Reminders" to "No" 16 * in the "Email" section on the Prefernces page. 17 * 18 * This is read-only for the client side, so the client must 19 * keep track of whether or not they have displayed the reminder 20 * to the user. (No where in the database will it be recorded that 21 * the user received a reminder through this functionality.) 22 * 23 * Client apps must use the same authentication as the web browser. 24 * If WebCalendar is setup to use web-based authentication, then 25 * the login.php found in this directory should be used to obtain 26 * a session cookie. 27 * 28 */ 29 30 // How many days ahead should we look for events. 31 // To handle case of an event 30 days from now where the user asked 32 // for a reminder 30 days before the event. 33 $DAYS_IN_ADVANCE = 30; 34 //$DAYS_IN_ADVANCE = 365; 35 36 37 // Show reminders for the next N days 38 $CUTOFF = 7; 39 40 41 // Load include files. 42 $basedir = ".."; // points to the base WebCalendar directory relative to 43 // current working directory 44 $includedir = "../includes"; 45 46 include "$includedir/config.php"; 47 include "$includedir/php-dbi.php"; 48 include "$includedir/functions.php"; 49 include "$includedir/$user_inc"; 50 include "$includedir/validate.php"; 51 include "$includedir/connect.php"; 52 load_global_settings (); 53 load_user_preferences (); 54 include "$includedir/site_extras.php"; 55 56 include "$includedir/translate.php"; 57 58 $debug = false; // set to true to print debug info... 59 60 Header ( "Content-type: text/xml" ); 61 //Header ( "Content-type: text/plain" ); 62 63 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 64 echo "<reminders>\n"; 65 66 // If login is public user, make sure public can view others... 67 if ( $login == "__public__" && $login != $user ) { 68 if ( $public_access_others != 'Y' ) { 69 echo "<error>" . translate("Not authorized") . "</error>\n"; 70 echo "</reminders>\n"; 71 exit; 72 } 73 echo "<!-- Allowing public user to view other user's calendar -->\n"; 74 } 75 76 if ( empty ( $user ) ) 77 $user = $login; 78 79 // If viewing different user then yourself... 80 if ( $login != $user ) { 81 if ( $allow_view_other != 'Y' ) { 82 echo "<error>" . translate("Not authorized") . "</error>\n"; 83 echo "</reminders>\n"; 84 exit; 85 } 86 echo "<!-- Allowing user to view other user's calendar -->\n"; 87 } 88 89 // Make sure this user has enabled email reminders. 90 //if ( $EMAIL_REMINDER == 'N' ) { 91 // echo "Error: email reminders disabled for user \"$user\"\n"; 92 // dbi_close ( $c ); 93 // exit; 94 //} 95 96 $startdate = date ( "Ymd" ); 97 $enddate = date ( "Ymd", time() + ( $DAYS_IN_ADVANCE * 24 * 3600 ) ); 98 99 // Now read events all the repeating events 100 $repeated_events = query_events ( $user, true, 101 "AND (webcal_entry_repeats.cal_end > $startdate OR " . 102 "webcal_entry_repeats.cal_end IS NULL) " ); 103 104 // Read non-repeating events 105 if ( $debug ) 106 echo "Checking for events for $user from date $startdate to date $enddate\n"; 107 $events = read_events ( $user, $startdate, $enddate ); 108 if ( $debug ) 109 echo "Found " . count ( $events ) . " events in time range.\n"; 110 111 112 function indent ( $str ) { 113 return " " . str_replace ( "\n", "\n ", $str ); 114 } 115 116 117 function escapeXml ( $str ) 118 { 119 return ( str_replace ( "<", "<", str_replace ( ">", ">", $str ) ) ); 120 } 121 122 // Send a reminder for a single event for a single day. 123 function list_reminder ( $id, $event_date, $remind_time ) { 124 global $site_extras, $debug, 125 $server_url, $application_name; 126 global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, 127 $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $LANGUAGE, $LOG_REMINDER; 128 129 $pri[1] = translate("Low"); 130 $pri[2] = translate("Medium"); 131 $pri[3] = translate("High"); 132 133 // get participants first... 134 135 $sql = "SELECT cal_login FROM webcal_entry_user " . 136 "WHERE cal_id = $id AND cal_status IN ('A','W') " . 137 "ORDER BY cal_login"; 138 $res = dbi_query ( $sql ); 139 $participants = array (); 140 $num_participants = 0; 141 if ( $res ) { 142 while ( $row = dbi_fetch_row ( $res ) ) { 143 $participants[$num_participants++] = $row[0]; 144 } 145 } 146 147 // get external participants 148 $ext_participants = array (); 149 $num_ext_participants = 0; 150 if ( ! empty ( $allow_external_users ) && $allow_external_users == "Y" && 151 ! empty ( $external_reminders ) && $external_reminders == "Y" ) { 152 $sql = "SELECT cal_fullname, cal_email FROM webcal_entry_ext_user " . 153 "WHERE cal_id = $id AND cal_email IS NOT NULL " . 154 "ORDER BY cal_fullname"; 155 $res = dbi_query ( $sql ); 156 if ( $res ) { 157 while ( $row = dbi_fetch_row ( $res ) ) { 158 $ext_participants[$num_ext_participants] = $row[0]; 159 $ext_participants_email[$num_ext_participants++] = $row[1]; 160 } 161 } 162 } 163 164 if ( ! $num_participants && ! $num_ext_participants ) { 165 if ( $debug ) 166 echo "No participants found for event id: $id\n"; 167 return; 168 } 169 170 171 // get event details 172 $res = dbi_query ( 173 "SELECT cal_create_by, cal_date, cal_time, cal_mod_date, " . 174 "cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, " . 175 "cal_name, cal_description FROM webcal_entry WHERE cal_id = $id" ); 176 if ( ! $res ) { 177 echo "Db error: could not find event id $id.\n"; 178 return; 179 } 180 181 182 if ( ! ( $row = dbi_fetch_row ( $res ) ) ) { 183 echo "Error: could not find event id $id in database.\n"; 184 return; 185 } 186 187 $create_by = $row[0]; 188 $name = $row[9]; 189 $description = $row[10]; 190 191 echo "<reminder>\n"; 192 echo " <remindDate>" . date ( "Ymd", $remind_time ) . "</remindDate>\n"; 193 echo " <remindTime>" . date ( "Hi", $remind_time ) . "</remindTime>\n"; 194 echo " <untilRemind>" . ( $remind_time - time() ) . "</untilRemind>\n"; 195 echo " <event>\n"; 196 echo " <id>$id</id>\n"; 197 echo " <name>" . escapeXml ( $name ) . "</name>\n"; 198 if ( ! empty ( $server_url ) ) { 199 if ( substr ( $server_url, -1, 1 ) == "/" ) { 200 echo " <url>" . $server_url . "view_entry.php?id=" . $id . "</url>\n"; 201 } else { 202 echo " <url>" . $server_url . "/view_entry.php?id=" . $id . "</url>\n"; 203 } 204 } 205 echo " <description>" . escapeXml ( $description ) . "</description>\n"; 206 echo " <dateFormatted>" . date_to_str ( $event_date ) . "</dateFormatted>\n"; 207 echo " <date>" . $event_date . "</date>\n"; 208 if ( $row[2] >= 0 ) { 209 echo " <time>" . sprintf ( "%04d", $row[2] / 100 ) . "</time>\n"; 210 echo " <timeFormatted>" . display_time ( $row[2] ) . "</timeFormatted>\n"; 211 } 212 if ( $row[5] > 0 ) 213 echo " <duration>" . $row[5] . "</duration>\n"; 214 if ( ! $disable_priority_field ) 215 echo " <priority>" . $pri[$row[6]] . "</priority>\n"; 216 if ( ! $disable_access_field ) 217 echo " <access>" . 218 ( $row[8] == "P" ? translate("Public") : translate("Confidential") ) . 219 "</access>\n"; 220 if ( ! strlen ( $single_user_login ) ) 221 echo " <createdBy>" . $row[0] . "</createdBy>\n"; 222 echo " <updateDate>" . date_to_str ( $row[3] ) . "</updateDate>\n"; 223 echo " <updateTime>" . display_time ( $row[4] ) . "</updateTime>\n"; 224 225 // site extra fields 226 $extras = get_site_extra_fields ( $id ); 227 echo " <siteExtras>\n"; 228 for ( $i = 0; $i < count ( $site_extras ); $i++ ) { 229 $extra_name = $site_extras[$i][0]; 230 $extra_descr = $site_extras[$i][1]; 231 $extra_type = $site_extras[$i][2]; 232 if ( $extras[$extra_name]['cal_name'] != "" ) { 233 $tag = preg_replace ( "/[^A-Za-z0-9]+/", "", translate ( $extra_descr ) ); 234 $tag = strtolower ( $tag ); 235 $tagname = str_replace ( '"', '', $extra_name ); 236 echo " <siteExtra>\n"; 237 echo " <number>$i</number>\n"; 238 echo " <name>" . escapeXml ( $extra_name ) . "</name>\n"; 239 echo " <description>" . escapeXml ( $extra_descr ) . "</description>\n"; 240 echo " <type>" . $extra_type . "</type>\n"; 241 echo " <value>"; 242 if ( $extra_type == $EXTRA_DATE ) { 243 //echo date_to_str ( $extras[$extra_name]['cal_date'] ); 244 echo $extras[$extra_name]['cal_date']; 245 } else if ( $extra_type == $EXTRA_MULTILINETEXT ) { 246 echo escapeXml ( $extras[$extra_name]['cal_data'] ); 247 } else if ( $extra_type == $EXTRA_REMINDER ) { 248 echo ( $extras[$extra_name]['cal_remind'] > 0 ? 249 translate("Yes") : translate("No") ); 250 } else { 251 // default method for $EXTRA_URL, $EXTRA_TEXT, etc... 252 echo escapeXml ( $extras[$extra_name]['cal_data'] ); 253 } 254 echo "</value>\n </siteExtra>\n"; 255 } 256 } 257 echo " </siteExtras>\n"; 258 if ( $single_user != "Y" && ! $disable_participants_field ) { 259 echo " <participants>\n"; 260 for ( $i = 0; $i < count ( $participants ); $i++ ) { 261 echo " <participant>" . $participants[$i] . 262 "</participant>\n"; 263 } 264 for ( $i = 0; $i < count ( $ext_participants ); $i++ ) { 265 echo " <participant>" . $ext_participants[$i] . 266 "</participant>\n"; 267 } 268 echo " </participants>\n"; 269 } 270 echo " </event>\n"; 271 echo "</reminder>\n"; 272 273 } 274 275 276 277 // Process an event for a single day. Check to see if it has 278 // a reminder, when it needs to be sent and when the last time it 279 // was sent. 280 function process_event ( $id, $name, $event_date, $event_time ) { 281 global $site_extras, $debug; 282 global $EXTRA_REMINDER_WITH_OFFSET, $EXTRA_REMINDER_WITH_DATE, $CUTOFF; 283 284 if ( $debug ) 285 printf ( "Event %d: \"%s\" at %s on %s \n", 286 $id, $name, $event_time, $event_date ); 287 288 // Check to see if this event has any reminders 289 $extras = get_site_extra_fields ( $id ); 290 for ( $j = 0; $j < count ( $site_extras ); $j++ ) { 291 $extra_name = $site_extras[$j][0]; 292 $extra_type = $site_extras[$j][2]; 293 $extra_arg1 = $site_extras[$j][3]; 294 $extra_arg2 = $site_extras[$j][4]; 295 //if ( $debug ) 296 // printf ( " name: %s\n type: %d\n arg1: %s\n arg2: %s\n", 297 // $extra_name, $extra_type, $extra_arg1, $extra_arg2 ); 298 if ( ! empty ( $extras[$extra_name]['cal_remind'] ) ) { 299 if ( $debug ) 300 echo " Reminder set for event. \n"; 301 // how many minutes before event should we send the reminder? 302 $ev_h = (int) ( $event_time / 10000 ); 303 $ev_m = ( $event_time / 100 ) % 100; 304 $ev_year = substr ( $event_date, 0, 4 ); 305 $ev_month = substr ( $event_date, 4, 2 ); 306 $ev_day = substr ( $event_date, 6, 2 ); 307 $event_time = mktime ( $ev_h, $ev_m, 0, $ev_month, $ev_day, $ev_year ); 308 if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET ) > 0 ) { 309 $minsbefore = $extras[$extra_name]['cal_data']; 310 $remind_time = $event_time - ( $minsbefore * 60 ); 311 } else if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_DATE ) > 0 ) { 312 $rd = $extras[$extra_name]['cal_date']; 313 $r_year = substr ( $rd, 0, 4 ); 314 $r_month = substr ( $rd, 4, 2 ); 315 $r_day = substr ( $rd, 6, 2 ); 316 $remind_time = mktime ( 0, 0, 0, $r_month, $r_day, $r_year ); 317 } else { 318 $minsbefore = $extra_arg1; 319 $remind_time = $event_time - ( $minsbefore * 60 ); 320 } 321 if ( $debug ) 322 echo " Mins Before: $minsbefore \n"; 323 if ( $debug ) { 324 echo " Event time is: " . date ( "m/d/Y H:i", $event_time ) . "\n"; 325 echo " Remind time is: " . date ( "m/d/Y H:i", $remind_time ) . "\n"; 326 } 327 // Send a reminder 328 if ( time() >= $remind_time - ( $CUTOFF * 24 * 3600 ) ) { 329 if ( $debug ) 330 echo " SENDING REMINDER! \n"; 331 list_reminder ( $id, $event_date, $remind_time ); 332 } 333 } 334 } 335 } 336 337 338 echo "<!-- reminders for user \"$user\", login \"$login\" -->\n"; 339 340 $startdate = time(); // today 341 for ( $d = 0; $d < $DAYS_IN_ADVANCE; $d++ ) { 342 $date = date ( "Ymd", time() + ( $d * 24 * 3600 ) ); 343 //echo "Date: $date\n"; 344 // Get non-repeating events for this date. 345 // An event will be included one time for each participant. 346 $ev = get_entries ( $user, $date ); 347 // Keep track of duplicates 348 $completed_ids = array ( ); 349 for ( $i = 0; $i < count ( $ev ); $i++ ) { 350 $id = $ev[$i]['cal_id']; 351 if ( ! empty ( $completed_ids[$id] ) ) 352 continue; 353 $completed_ids[$id] = 1; 354 process_event ( $id, $ev[$i]['cal_name'], $date, $ev[$i]['cal_time'] ); 355 } 356 $rep = get_repeating_entries ( $user, $date ); 357 for ( $i = 0; $i < count ( $rep ); $i++ ) { 358 $id = $rep[$i]['cal_id']; 359 if ( ! empty ( $completed_ids[$id] ) ) 360 continue; 361 $completed_ids[$id] = 1; 362 process_event ( $id, $rep[$i]['cal_name'], $date, $rep[$i]['cal_time'] ); 363 } 364 } 365 366 echo "</reminders>\n"; 367 368 if ( $debug ) 369 echo "Done.\n"; 370 371 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Nov 30 19:09:19 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |