[ Index ] |
|
Code source de WebCalendar 1.0.5 |
1 <?php 2 /* 3 * $Id: get_events.php,v 1.1 2004/06/24 02:18:30 cknudsen Exp $ 4 * 5 * Description: 6 * Web Service functionality to get events. 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 * Client apps must use the same authentication as the web browser. 12 * If WebCalendar is setup to use web-based authentication, then 13 * the login.php found in this directory should be used to obtain 14 * a session cookie. 15 * 16 */ 17 18 // Load include files. 19 $basedir = ".."; // points to the base WebCalendar directory relative to 20 // current working directory 21 $includedir = "../includes"; 22 23 include "$includedir/config.php"; 24 include "$includedir/php-dbi.php"; 25 include "$includedir/functions.php"; 26 include "$includedir/$user_inc"; 27 include "$includedir/validate.php"; 28 include "$includedir/connect.php"; 29 load_global_settings (); 30 load_user_preferences (); 31 include "$includedir/site_extras.php"; 32 33 include "$includedir/translate.php"; 34 35 $debug = false; // set to true to print debug info... 36 37 //Header ( "Content-type: text/xml" ); 38 Header ( "Content-type: text/plain" ); 39 40 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 41 echo "<events>\n"; 42 43 // If login is public user, make sure public can view others... 44 if ( $login == "__public__" && $login != $user ) { 45 if ( $public_access_others != 'Y' ) { 46 echo "<error>" . translate("Not authorized") . "</error>\n"; 47 echo "</events>\n"; 48 exit; 49 } 50 echo "<!-- Allowing public user to view other user's calendar -->\n"; 51 } 52 53 if ( empty ( $user ) ) 54 $user = $login; 55 56 // If viewing different user then yourself... 57 if ( $login != $user ) { 58 if ( $allow_view_other != 'Y' ) { 59 echo "<error>" . translate("Not authorized") . "</error>\n"; 60 echo "</events>\n"; 61 exit; 62 } 63 echo "<!-- Allowing user to view other user's calendar -->\n"; 64 } 65 66 if ( empty ( $startdate ) ) 67 $startdate = date ( "Ymd" ); 68 if ( empty ( $enddate ) ) 69 $enddate = $startdate; 70 71 // Now read events all the repeating events (for all users) 72 $repeated_events = query_events ( $user, true, 73 "AND (webcal_entry_repeats.cal_end > $startdate OR " . 74 "webcal_entry_repeats.cal_end IS NULL) " ); 75 76 // Read non-repeating events (for all users) 77 if ( $debug ) 78 echo "Checking for events for $user from date $startdate to date $enddate\n"; 79 $events = read_events ( $user, $startdate, $enddate ); 80 if ( $debug ) 81 echo "Found " . count ( $events ) . " events in time range.\n"; 82 83 84 85 function escapeXml ( $str ) 86 { 87 return ( str_replace ( "<", "<", str_replace ( ">", ">", $str ) ) ); 88 } 89 90 // Send a single event 91 function print_event_xml ( $id, $event_date ) { 92 global $site_extras, $debug, 93 $server_url, $application_name; 94 global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE, 95 $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $LANGUAGE; 96 97 $pri[1] = translate("Low"); 98 $pri[2] = translate("Medium"); 99 $pri[3] = translate("High"); 100 101 // get participants first... 102 103 $sql = "SELECT cal_login FROM webcal_entry_user " . 104 "WHERE cal_id = $id AND cal_status IN ('A','W') " . 105 "ORDER BY cal_login"; 106 $res = dbi_query ( $sql ); 107 $participants = array (); 108 $num_participants = 0; 109 if ( $res ) { 110 while ( $row = dbi_fetch_row ( $res ) ) { 111 $participants[$num_participants++] = $row[0]; 112 } 113 } 114 115 // get external participants 116 $ext_participants = array (); 117 $num_ext_participants = 0; 118 if ( ! empty ( $allow_external_users ) && $allow_external_users == "Y" && 119 ! empty ( $external_reminders ) && $external_reminders == "Y" ) { 120 $sql = "SELECT cal_fullname, cal_email FROM webcal_entry_ext_user " . 121 "WHERE cal_id = $id AND cal_email IS NOT NULL " . 122 "ORDER BY cal_fullname"; 123 $res = dbi_query ( $sql ); 124 if ( $res ) { 125 while ( $row = dbi_fetch_row ( $res ) ) { 126 $ext_participants[$num_ext_participants] = $row[0]; 127 $ext_participants_email[$num_ext_participants++] = $row[1]; 128 } 129 } 130 } 131 132 if ( ! $num_participants && ! $num_ext_participants ) { 133 if ( $debug ) 134 echo "No participants found for event id: $id\n"; 135 return; 136 } 137 138 139 // get event details 140 $res = dbi_query ( 141 "SELECT cal_create_by, cal_date, cal_time, cal_mod_date, " . 142 "cal_mod_time, cal_duration, cal_priority, cal_type, cal_access, " . 143 "cal_name, cal_description FROM webcal_entry WHERE cal_id = $id" ); 144 if ( ! $res ) { 145 echo "Db error: could not find event id $id.\n"; 146 return; 147 } 148 149 150 if ( ! ( $row = dbi_fetch_row ( $res ) ) ) { 151 echo "Error: could not find event id $id in database.\n"; 152 return; 153 } 154 155 $create_by = $row[0]; 156 $name = $row[9]; 157 $description = $row[10]; 158 159 echo "<event>\n"; 160 echo " <id>$id</id>\n"; 161 echo " <name>" . escapeXml ( $name ) . "</name>\n"; 162 if ( ! empty ( $server_url ) ) { 163 if ( substr ( $server_url, -1, 1 ) == "/" ) { 164 echo " <url>" . $server_url . "view_entry.php?id=" . $id . "</url>\n"; 165 } else { 166 echo " <url>" . $server_url . "/view_entry.php?id=" . $id . "</url>\n"; 167 } 168 } 169 echo " <description>" . escapeXml ( $description ) . "</description>\n"; 170 echo " <dateFormatted>" . date_to_str ( $event_date ) . "</dateFormatted>\n"; 171 echo " <date>" . $event_date . "</date>\n"; 172 if ( $row[2] >= 0 ) { 173 echo " <time>" . sprintf ( "%04d", $row[2] / 100 ) . "</time>\n"; 174 echo " <timeFormatted>" . display_time ( $row[2] ) . "</timeFormatted>\n"; 175 } 176 if ( $row[5] > 0 ) 177 echo " <duration>" . $row[5] . "</duration>\n"; 178 if ( ! $disable_priority_field ) 179 echo " <priority>" . $pri[$row[6]] . "</priority>\n"; 180 if ( ! $disable_access_field ) 181 echo " <access>" . 182 ( $row[8] == "P" ? translate("Public") : translate("Confidential") ) . 183 "</access>\n"; 184 if ( ! strlen ( $single_user_login ) ) 185 echo " <createdBy>" . $row[0] . "</createdBy>\n"; 186 echo " <updateDate>" . date_to_str ( $row[3] ) . "</updateDate>\n"; 187 echo " <updateTime>" . display_time ( $row[4] ) . "</updateTime>\n"; 188 189 // site extra fields 190 $extras = get_site_extra_fields ( $id ); 191 echo " <siteExtras>\n"; 192 for ( $i = 0; $i < count ( $site_extras ); $i++ ) { 193 $extra_name = $site_extras[$i][0]; 194 $extra_descr = $site_extras[$i][1]; 195 $extra_type = $site_extras[$i][2]; 196 if ( $extras[$extra_name]['cal_name'] != "" ) { 197 $tag = preg_replace ( "/[^A-Za-z0-9]+/", "", translate ( $extra_descr ) ); 198 $tag = strtolower ( $tag ); 199 $tagname = str_replace ( '"', '', $extra_name ); 200 echo " <siteExtra>\n"; 201 echo " <number>$i</number>\n"; 202 echo " <name>" . escapeXml ( $extra_name ) . "</name>\n"; 203 echo " <description>" . escapeXml ( $extra_descr ) . "</description>\n"; 204 echo " <type>" . $extra_type . "</type>\n"; 205 echo " <value>"; 206 if ( $extra_type == $EXTRA_DATE ) { 207 //echo date_to_str ( $extras[$extra_name]['cal_date'] ); 208 echo $extras[$extra_name]['cal_date']; 209 } else if ( $extra_type == $EXTRA_MULTILINETEXT ) { 210 echo escapeXml ( $extras[$extra_name]['cal_data'] ); 211 } else if ( $extra_type == $EXTRA_REMINDER ) { 212 echo ( $extras[$extra_name]['cal_remind'] > 0 ? 213 translate("Yes") : translate("No") ); 214 } else { 215 // default method for $EXTRA_URL, $EXTRA_TEXT, etc... 216 echo escapeXml ( $extras[$extra_name]['cal_data'] ); 217 } 218 echo "</value>\n </siteExtra>\n"; 219 } 220 } 221 echo " </siteExtras>\n"; 222 if ( $single_user != "Y" && ! $disable_participants_field ) { 223 echo " <participants>\n"; 224 for ( $i = 0; $i < count ( $participants ); $i++ ) { 225 echo " <participant>" . $participants[$i] . 226 "</participant>\n"; 227 } 228 for ( $i = 0; $i < count ( $ext_participants ); $i++ ) { 229 echo " <participant>" . $ext_participants[$i] . 230 "</participant>\n"; 231 } 232 echo " </participants>\n"; 233 } 234 echo "</event>\n"; 235 } 236 237 238 239 // Process an event for a single day. Check to see if it has 240 // a reminder, when it needs to be sent and when the last time it 241 // was sent. 242 function process_event ( $id, $name, $event_date, $event_time ) { 243 global $debug; 244 245 if ( $debug ) 246 printf ( "Event %d: \"%s\" at %s on %s \n", 247 $id, $name, $event_time, $event_date ); 248 249 print_event_xml ( $id, $event_date ); 250 } 251 252 253 echo "<!-- events for user \"$user\", login \"$login\" -->\n"; 254 echo "<!-- date range: $startdate - $enddate -->\n"; 255 256 $startyear = substr ( $startdate, 0, 4 ); 257 $startmonth = substr ( $startdate, 4, 2 ); 258 $startday = substr ( $startdate, 6, 2 ); 259 $endyear = substr ( $enddate, 0, 4 ); 260 $endmonth = substr ( $enddate, 4, 2 ); 261 $endday = substr ( $enddate, 6, 2 ); 262 263 $starttime = mktime ( 3, 0, 0, $startmonth, $startday, $startyear ); 264 $endtime = mktime ( 3, 0, 0, $endmonth, $endday, $endyear ); 265 266 for ( $d = $starttime; $d <= $endtime; $d += $ONE_DAY ) { 267 $completed_ids = array (); 268 $date = date ( "Ymd", $d ); 269 //echo "Date: $date\n"; 270 // Get non-repeating events for this date. 271 // An event will be included one time for each participant. 272 $ev = get_entries ( $user, $date ); 273 // Keep track of duplicates 274 $completed_ids = array ( ); 275 for ( $i = 0; $i < count ( $ev ); $i++ ) { 276 $id = $ev[$i]['cal_id']; 277 if ( ! empty ( $completed_ids[$id] ) ) 278 continue; 279 $completed_ids[$id] = 1; 280 process_event ( $id, $ev[$i]['cal_name'], $date, $ev[$i]['cal_time'] ); 281 } 282 $rep = get_repeating_entries ( $user, $date ); 283 for ( $i = 0; $i < count ( $rep ); $i++ ) { 284 $id = $rep[$i]['cal_id']; 285 if ( ! empty ( $completed_ids[$id] ) ) 286 continue; 287 $completed_ids[$id] = 1; 288 process_event ( $id, $rep[$i]['cal_name'], $date, $rep[$i]['cal_time'] ); 289 } 290 } 291 292 echo "</events>\n"; 293 294 if ( $debug ) 295 echo "Done.\n"; 296 297 ?>
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 |
![]() |