PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/phpical2/functions/template.php

https://gitlab.com/endomorphosis/fusenews
PHP | 1145 lines | 955 code | 110 blank | 80 comment | 281 complexity | 6631a8f4e0a61406ebaf5e87ebcf21c3 MD5 | raw file
  1. <?php
  2. //print_r($master_array);
  3. class Page {
  4. var $page;
  5. function draw_subscribe($template_p) {
  6. global $phpiCal_config, $getdate, $cal, $ALL_CALENDARS_COMBINED, $subscribe_path, $download_filename;
  7. if ($cal != $ALL_CALENDARS_COMBINED && $subscribe_path != '' && $download_filename != '') {
  8. $this->page = str_replace('{SUBSCRIBE_PATH}', $subscribe_path, $this->page);
  9. $this->page = str_replace('{DOWNLOAD_FILENAME}', $download_filename, $this->page);
  10. } else {
  11. $this->page = preg_replace('!<\!-- switch display_download on -->.*<\!-- switch display_download off -->!Uis', '', $this->page);
  12. }
  13. }
  14. function draw_admin() {
  15. global $phpiCal_config, $getdate, $cal, $master_array, $is_loged_in;
  16. $delete_table = '';
  17. if ($is_loged_in == TRUE) {
  18. // Print Calendar Checkboxes
  19. $COLUMNS_TO_PRINT = 3;
  20. $column = 1;
  21. $filelist = availableCalendars('', '', '', true);
  22. foreach ($filelist as $file) {
  23. if ($column > $COLUMNS_TO_PRINT) {
  24. $delete_table .= '</tr>';
  25. $column = 1;
  26. }
  27. if ($column == 1) {
  28. $delete_table .= '<tr>';
  29. }
  30. $cal_filename_tmp = getCalendarName($file);
  31. $cal_tmp = urlencode($file);
  32. $cal_displayname_tmp = str_replace("32", " ", $cal_filename_tmp);
  33. $delete_table .= '<td align="left"><input name="delete_calendar[]" value="'.$cal_tmp.'" type="checkbox" />'.$cal_displayname_tmp.'</td>';
  34. $column++;
  35. }
  36. // Print remaining empty columns if necessary
  37. $number_of_columns = count($filelist);
  38. while (gettype($number_of_columns/$COLUMNS_TO_PRINT) != "integer") {
  39. $delete_table .= '<td>&nbsp;</td>';
  40. $number_of_columns++;
  41. }
  42. $this->page = str_replace('{DELETE_TABLE}', $delete_table, $this->page);
  43. } else {
  44. $this->page = preg_replace('!<\!-- switch logged_in on -->.*<\!-- switch logged_in off -->!Uis', '', $this->page);
  45. $this->page = preg_replace('!<\!-- switch logged_in2 on -->.*<\!-- switch logged_in2 off -->!Uis', '', $this->page);
  46. }
  47. }
  48. function draw_print($template_p) {
  49. global $phpiCal_config, $getdate, $cal, $master_array, $printview, $dateFormat_day, $timeFormat, $week_start, $week_end, $lang;
  50. preg_match("!<\!-- loop events on -->(.*)<\!-- loop events off -->!Uis", $this->page, $match1);
  51. preg_match("!<\!-- switch some_events on -->(.*)<\!-- loop events on -->!Uis", $this->page, $match3);
  52. $loop_event = trim($match1[1]);
  53. $loop_day = trim($match3[1]);
  54. $parse_month = date ("Ym", strtotime($getdate));
  55. $parse_year = date ("Y", strtotime($getdate));
  56. $seen_events = array();
  57. $final = '';
  58. $events_week = 0;
  59. foreach($master_array as $key => $val) {
  60. preg_match ('/([0-9]{6})([0-9]{2})/', $key, $regs);
  61. if (((@$regs[1] == $parse_month) && ($printview == 'month')) || (($key == $getdate) && ($printview == 'day')) || ((($key >= $week_start) && ($key <= $week_end)) && ($printview == 'week')) || ((substr(@$regs[1],0,4) == $parse_year) && ($printview == 'year'))) {
  62. $events_week++;
  63. $dayofmonth = strtotime ($key);
  64. $dayofmonth = localizeDate ($dateFormat_day, $dayofmonth);
  65. $events_tmp = $loop_event;
  66. $day_tmp = $loop_day;
  67. $day_events = 0;
  68. // Pull out each day
  69. $some_events = '';
  70. foreach ($val as $new_val) {
  71. foreach ($new_val as $new_key2 => $new_val2) {
  72. if (isset($seen_events["$new_key2"]) && isset($new_val2['spans_day']) && $new_val2['spans_day'] == 1){
  73. $new_val2['event_text'] .= " second instance of ".$new_key2;
  74. continue;
  75. }
  76. $seen_events["$new_key2"] = 1;
  77. $day_events++;
  78. if (isset($new_val2['event_text'])) {
  79. $event_text = stripslashes(urldecode($new_val2['event_text']));
  80. $location = stripslashes(urldecode($new_val2['location']));
  81. $description = stripslashes(urldecode($new_val2['description']));
  82. $event_start = $new_val2['event_start'];
  83. $event_end = $new_val2['event_end'];
  84. if (isset($new_val2['display_end'])) $event_end = $new_val2['display_end'];
  85. if (!isset($new_val2['event_start'])) {
  86. $event_start = $lang['l_all_day'];
  87. $event_start2 = '';
  88. $event_end = '';
  89. } else {
  90. $event_start = date ($timeFormat, strtotime ($event_start));
  91. $event_end = date ($timeFormat, strtotime ($event_end));
  92. $event_start = $event_start .' - '.$event_end;
  93. if (date("Ymd", $new_val2['start_unixtime']) != date("Ymd", $new_val2['end_unixtime'])) $event_start .= " ".localizeDate($dateFormat_day, $new_val2['end_unixtime']);
  94. }
  95. }
  96. if ($description == '') {
  97. $events_tmp = preg_replace('!<\!-- switch description_events on -->.*<\!-- switch description_events off -->!Uis', '', $events_tmp);
  98. }
  99. if ($location == '') {
  100. $events_tmp = preg_replace('!<\!-- switch location_events on -->.*<\!-- switch location_events off -->!Uis', '', $events_tmp);
  101. }
  102. $search = array('{EVENT_START}', '{EVENT_TEXT}', '{DESCRIPTION}', '{LOCATION}');
  103. $replace = array($event_start, $event_text, $description, $location);
  104. $events_tmp = str_replace($search, $replace, $events_tmp);
  105. $some_events .= $events_tmp;
  106. $events_tmp = $loop_event;
  107. }
  108. }
  109. if ($day_events == 0) continue;
  110. $day_tmp = str_replace('{DAYOFMONTH}', $dayofmonth, $day_tmp);
  111. $final .= $day_tmp.$some_events;
  112. unset ($day_tmp);
  113. $some_events = '';
  114. }
  115. }
  116. if ($events_week < 1) {
  117. $this->page = preg_replace('!<\!-- switch some_events on -->.*<\!-- switch some_events off -->!Uis', '', $this->page);
  118. } else {
  119. $this->page = preg_replace('!<\!-- switch some_events on -->.*<\!-- switch some_events off -->!Uis', $final, $this->page);
  120. $this->page = preg_replace('!<\!-- switch no_events on -->.*<\!-- switch no_events off -->!Uis', '', $this->page);
  121. }
  122. }
  123. function draw_search($template_p) {
  124. global $phpiCal_config, $getdate, $cal, $the_arr, $printview, $dateFormat_day, $timeFormat, $week_start, $week_end, $lang;
  125. preg_match("!<\!-- switch results on -->(.*)<\!-- switch results off -->!Uis", $this->page, $match1);
  126. preg_match("!<\!-- switch recur on -->(.*)<\!-- loop recur off -->!Uis", $this->page, $match2);
  127. preg_match("!<\!-- switch exceptions on -->(.*)<\!-- switch exceptions off -->!Uis", $this->page, $match3);
  128. $loop_event = trim($match1[1]);
  129. $loop_recur = trim($match2[1]);
  130. $loop_except = trim($match3[1]);
  131. $parse_month = date ("Ym", strtotime($getdate));
  132. if (isset($the_arr)){
  133. // Pull out each event
  134. foreach($the_arr as $key => $val) {
  135. $events_found++;
  136. $dayofmonth = strtotime($val['date']);
  137. $dayofmonth = localizeDate ('%A, %B %e %Y', $dayofmonth);
  138. $events_tmp = $loop_event;
  139. $recur_tmp = $loop_recur;
  140. if ($val['event_text']) {
  141. $event_text = stripslashes(urldecode($val['event_text']));
  142. $description = stripslashes(urldecode($val['description']));
  143. $location = stripslashes(urldecode($val['location']));
  144. $event_start = $val['event_start'];
  145. $event_end = $val['event_end'];
  146. if (isset($val['display_end'])) $event_end = $val['display_end'];
  147. if (!$val['event_start']) {
  148. $event_start = $lang['l_all_day'];
  149. $event_start2 = '';
  150. $event_end = '';
  151. } else {
  152. $event_start = date ($timeFormat, strtotime ($event_start));
  153. $event_end = date ($timeFormat, strtotime ($event_end));
  154. $event_start = $event_start .' - '.$event_end;
  155. }
  156. }
  157. if ($description == '') {
  158. $events_tmp = preg_replace('!<\!-- switch description_events on -->.*<\!-- switch description_events off -->!Uis', '', $events_tmp);
  159. }
  160. if (!isset($val['exceptions'])) {
  161. $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', '', $events_tmp);
  162. }else{
  163. $some_exceptions = "";
  164. foreach ($val['exceptions'] as $except_val){
  165. $except_tmp = $loop_except;
  166. $except_date = strtotime($except_val['date']);
  167. $except_date = localizeDate ('%A, %B %e %Y', $except_date);
  168. $except_tmp = str_replace('{DAYOFMONTH}', $except_date, $except_tmp);
  169. $except_event_start = date ($timeFormat, strtotime ($except_val['event_start']));
  170. $except_event_end = date ($timeFormat, strtotime ($except_val['event_end']));
  171. $except_event_start = $except_event_start .' - '.$except_event_end;
  172. $except_tmp = str_replace('{EVENT_START}', $except_event_start, $except_tmp);
  173. $except_event_text = stripslashes(urldecode($except_val['event_text']));
  174. $except_tmp = str_replace('{EVENT_TEXT}', $except_event_text, $except_tmp);
  175. #is there a recur in the exception?
  176. if (!$except_val['recur']) {
  177. $except_tmp = preg_replace('!<\!-- switch except_recur on -->.*<\!-- switch except_recur off -->!Uis', '', $except_tmp);
  178. }else{
  179. $except_tmp = str_replace('{EXCEPT_RECUR}', $except_val['recur'], $except_tmp);
  180. }
  181. #is there a description in the exception?
  182. if (!$except_val['description']) {
  183. $except_tmp = preg_replace('!<\!-- switch except_description on -->.*<\!-- switch except_description off -->!Uis', '', $except_tmp);
  184. }else{
  185. $except_description = stripslashes(urldecode($except_val['description']));
  186. $except_tmp = str_replace('{EXCEPT_DESCRIPTION}', $except_description, $except_tmp);
  187. }
  188. $some_exceptions .= $except_tmp;
  189. }
  190. $events_tmp = preg_replace('!<\!-- switch exceptions on -->.*<\!-- switch exceptions off -->!Uis', $some_exceptions,$events_tmp );
  191. }
  192. if (!$val['recur']) {
  193. $events_tmp = preg_replace('!<\!-- switch recur on -->.*<\!-- switch recur off -->!Uis', '', $events_tmp);
  194. $events_tmp = str_replace('{L_STARTING_ON}', '', $events_tmp);
  195. }else{
  196. $events_tmp = str_replace('{RECUR}', $val['recur'], $events_tmp);
  197. }
  198. $search = array('{EVENT_START}', '{EVENT_TEXT}', '{DESCRIPTION}','{LOCATION}');
  199. $replace = array($event_start, $event_text, $description, $location);
  200. $events_tmp = str_replace($search, $replace, $events_tmp);
  201. $some_events .= $events_tmp;
  202. $events_tmp = $loop_event;
  203. $some_events = str_replace('{KEY}', $val['date'], $some_events);
  204. $some_events = str_replace('{DAYOFMONTH}', $dayofmonth, $some_events);
  205. $final .= $day_tmp.$some_events;
  206. unset ($day_tmp, $some_events);
  207. }
  208. }
  209. if ($events_found < 1) {
  210. $this->page = preg_replace('!<\!-- switch results on -->.*<\!-- switch results off -->!Uis', '', $this->page);
  211. } else {
  212. $this->page = preg_replace('!<\!-- switch results on -->.*<\!-- switch results off -->!Uis', $final, $this->page);
  213. $this->page = preg_replace('!<\!-- switch no_results on -->.*<\!-- switch no_results off -->!Uis', '', $this->page);
  214. #echo "<hr>this->page: $this->page<br><hr>";
  215. }
  216. }#end draw_search
  217. function draw_week($template_p) {
  218. global $phpiCal_config, $start_week_time, $getdate, $cal, $master_array, $dateFormat_week_list, $current_view, $day_array, $timeFormat, $timeFormat_small;
  219. // Figure out colspans and initialize weekarray
  220. $thisdate = $start_week_time;
  221. $swt = $start_week_time;
  222. for ($i=0;$i < $phpiCal_config->week_length;$i++) {
  223. $thisday = date("Ymd", $thisdate);
  224. $nbrGridCols[$thisday] = 1;
  225. if (isset($master_array[$thisday])) {
  226. foreach($master_array[($thisday)] as $ovlKey => $ovlValue) {
  227. # ovlKey is a time slot; $ovlValue is an array with key=uid
  228. if ($ovlKey != "-1") {
  229. foreach($ovlValue as $ovl2Value) {
  230. $nbrGridCols[($thisday)] = kgv($nbrGridCols[($thisday)], ($ovl2Value["event_overlap"] + 1));
  231. }
  232. }
  233. }
  234. }
  235. $weekarray[$i] = $thisday;
  236. $event_length[$thisday] = array ();
  237. $thisdate = ($thisdate + (25 * 60 * 60));
  238. }
  239. #echo "<pre>";print_r($nbrGridCols);
  240. // Replaces the allday events
  241. preg_match("!<\!-- loop allday row on -->(.*)<\!-- loop alldaysofweek on -->!Uis", $this->page, $match1);
  242. $loop_row_begin = trim($match1[1]); # <tr>etc
  243. preg_match("!<\!-- loop allday on -->(.*)<\!-- loop allday off -->!Uis", $this->page, $match1);
  244. preg_match("!<\!-- loop alldaysofweek on -->(.*)<\!-- loop allday on -->!Uis", $this->page, $match2);
  245. preg_match("!<\!-- loop allday off -->(.*)<\!-- loop alldaysofweek off -->!Uis", $this->page, $match3);
  246. $loop_ad = trim($match1[1]); # one day cell
  247. $loop_begin = trim($match2[1]); # <td>
  248. $loop_end = trim($match3[1]); # </td>
  249. preg_match("!<\!-- loop alldaysofweek off -->(.*)<\!-- loop allday row off -->!Uis", $this->page, $match3);
  250. $loop_row_end = trim($match3[1]); # </tr>
  251. $allday_uids = array();
  252. $allday_uid_dates = array();
  253. $weekreplace = '';
  254. foreach ($weekarray as $i=>$get_date){
  255. if (isset($master_array[$get_date]['-1']) && is_array($master_array[$get_date]['-1']) && !empty($master_array[$get_date]['-1'])){
  256. foreach ($master_array[$get_date]['-1'] as $uid => $allday){
  257. if (!array_key_exists($uid, $allday_uids)) $allday_uids[$uid] = $get_date;
  258. $allday_uid_dates[$uid][] = $get_date;
  259. }
  260. }
  261. }
  262. # new allday routine is better for multiday events
  263. while(!empty($allday_uids)){
  264. $row = $loop_row_begin;
  265. $day = 0;
  266. $replace ='';
  267. while ($day < $phpiCal_config->week_length){
  268. $colspan = 0;
  269. $replace .= $loop_begin; # <td>
  270. if(array_search($weekarray[$day], $allday_uids)){
  271. $uid = array_search($weekarray[$day], $allday_uids);
  272. unset($allday_uids[$uid]);
  273. $allday = $master_array[$weekarray[$day]]['-1'][$uid];
  274. foreach ($allday_uid_dates[$uid] as $date){
  275. #$ev = (!isset($ev)) ? " $uid ":"";
  276. #$replace .= $ev;
  277. $colspan += $nbrGridCols[$weekarray[$day]];
  278. $day++;
  279. }
  280. $event_calno = $allday['calnumber'];
  281. $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
  282. $event = openevent($get_date, -1, $uid, $allday, $phpiCal_config->allday_week_lines, (8*$colspan), 'psf');
  283. $loop_tmp = str_replace('{ALLDAY}', $event, $loop_ad);
  284. $loop_tmp = str_replace('{CALNO}', $event_calno, $loop_tmp);
  285. $replace .= $loop_tmp;
  286. $replace .= $loop_end;
  287. }else{
  288. $colspan = $nbrGridCols[$weekarray[$day]];
  289. $replace .= $loop_end;
  290. $day++;
  291. }
  292. unset ($ev);
  293. $replace = str_replace('{COLSPAN}', "colspan='$colspan'", $replace);
  294. }
  295. $row .= "$replace $loop_row_end\n";
  296. $weekreplace .= "$row\n";
  297. }
  298. /* old routine
  299. foreach ($weekarray as $i=>$get_date) {
  300. $replace = $loop_begin;
  301. $colspan = 'colspan="'.$nbrGridCols[$get_date].'"';
  302. $replace = str_replace('{COLSPAN}', $colspan, $replace);
  303. if (isset($master_array[$get_date]['-1']) && is_array($master_array[$get_date]['-1']) && !empty($master_array[$get_date]['-1']) ) {
  304. foreach ($master_array[$get_date]['-1'] as $uid => $allday) {
  305. $event_calno = $allday['calnumber'];
  306. $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
  307. $event = openevent($get_date, -1, $uid, $allday, $phpiCal_config->allday_week_lines, 11, 'psf');
  308. $loop_tmp = str_replace('{ALLDAY}', $event, $loop_ad);
  309. $loop_tmp = str_replace('{CALNO}', $event_calno, $loop_tmp);
  310. $replace .= $loop_tmp;
  311. }
  312. }
  313. $replace .= $loop_end;
  314. $weekreplace .= $replace;
  315. }
  316. */
  317. $this->page = preg_replace('!<\!-- loop alldaysofweek on -->.*<\!-- loop alldaysofweek off -->!Uis', $weekreplace, $this->page);
  318. // Replaces the daysofweek
  319. preg_match("!<\!-- loop daysofweek on -->(.*)<\!-- loop daysofweek off -->!Uis", $this->page, $match1);
  320. $loop_dof = trim($match1[1]);
  321. $start_wt = strtotime(dateOfWeek($getdate, $phpiCal_config->week_start_day));
  322. $weekday_loop = '';
  323. for ($i=0; $i<$phpiCal_config->week_length; $i++) {
  324. $daylink = date('Ymd', $start_wt);
  325. $weekday = localizeDate($dateFormat_week_list, strtotime($daylink));
  326. if ($daylink == $getdate) {
  327. $row1 = 'rowToday';
  328. $row2 = 'rowOn';
  329. $row3 = 'rowToday';
  330. }else{
  331. $row1 = 'rowOff';
  332. $row2 = 'rowOn';
  333. $row3 = 'rowOff';
  334. }
  335. $start_wt = strtotime("+1 day", $start_wt);
  336. $colspan = 'colspan="'.$nbrGridCols[$daylink].'"';
  337. $search = array('{DAY}', '{DAYLINK}', '{ROW1}', '{ROW2}', '{ROW3}', '{COLSPAN}');
  338. $replace = array($weekday, $daylink, $row1, $row2, $row3, $colspan);
  339. $loop_tmp = str_replace($search, $replace, $loop_dof);
  340. $weekday_loop .= $loop_tmp;
  341. }
  342. $this->page = preg_replace('!<\!-- loop daysofweek on -->.*<\!-- loop daysofweek off -->!Uis', $weekday_loop, $this->page);
  343. // Build the body
  344. preg_match("!<\!-- loop row on -->(.*)<\!-- loop row off -->!Uis", $this->page, $match2);
  345. preg_match("!<\!-- loop event on -->(.*)<\!-- loop event off -->!Uis", $this->page, $match3);
  346. $loop_hours = trim($match2[1]);
  347. $loop_event = trim($match3[1]);
  348. $event_length = array ();
  349. $border = 0;
  350. preg_match ('/([0-9]{4})([0-9]{2})([0-9]{2})/', $getdate, $day_array2);
  351. $this_day = $day_array2[3];
  352. $this_month = $day_array2[2];
  353. $this_year = $day_array2[1];
  354. $thisdate = $swt;
  355. $weekdisplay = '';
  356. #day_array is an array of time blocks of length $phpiCal_config->gridLength
  357. foreach ($day_array as $key) {
  358. $cal_time = $key;
  359. preg_match('/([0-9]{2})([0-9]{2})/', $key, $regs_tmp);
  360. $key = mktime($regs_tmp[1],$regs_tmp[2],0,$this_month,$this_day,$this_year);
  361. $key = date ($timeFormat, $key);
  362. if (ereg("([0-9]{1,2}):00", $key)) {
  363. # column of times colspan = 4 to cover navigation links at top
  364. $weekdisplay .= '<tr>';
  365. $weekdisplay .= '<td colspan="4" rowspan="' . (60 / $phpiCal_config->gridLength) . '" align="center" valign="top" width="60" class="timeborder">'.$key.'</td>';
  366. $weekdisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>';
  367. } elseif ($cal_time == $phpiCal_config->day_start) {
  368. $size_tmp = 60 - (int)substr($cal_time,2,2);
  369. $weekdisplay .= '<tr>';
  370. $weekdisplay .= '<td colspan="4" rowspan="' . ($size_tmp / $phpiCal_config->gridLength) . '" align="center" valign="top" width="60" class="timeborder">'.$key.' </td>';
  371. $weekdisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>';
  372. } else {
  373. # empty row for each gridLength, to the right of times and left of first weekday
  374. $weekdisplay .= '<tr>';
  375. $weekdisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>';
  376. }
  377. /* add columns in the $cal_time grid slot for each day
  378. each cell will have $this_time_arr of events */
  379. foreach ($weekarray as $thisday) {
  380. $this_time_arr = array();
  381. $dayborder = 0;
  382. if ($phpiCal_config->day_start == $cal_time && isset($master_array[$thisday]) && is_array($master_array[$thisday])) {
  383. # want to pile up all the events before day_start that end in the displayed times
  384. foreach($master_array[$thisday] as $time_key => $time_arr) {
  385. if ((int)$time_key <= (int)$cal_time && is_array($time_arr) && $time_key != '-1') {
  386. foreach($time_arr as $uid => $event_tmp) {
  387. if ((int)$event_tmp['display_end'] > (int)$cal_time) $this_time_arr[$uid] = $event_tmp;
  388. }
  389. }
  390. }
  391. } else {
  392. # events that start in internal cal_times the grid
  393. if (isset($master_array[$thisday][$cal_time]) && sizeof($master_array[$thisday][$cal_time]) > 0) {
  394. $this_time_arr = $master_array[$thisday][$cal_time];
  395. }
  396. }
  397. // go through $this_time_array and fill the event_length array
  398. foreach ($this_time_arr as $eventKey => $loopevent) {
  399. $drawEvent = drawEventTimes ($cal_time, $loopevent["display_end"]);
  400. $j = 0;
  401. while (isset($event_length[$thisday][$j])) {
  402. if ($event_length[$thisday][$j]["state"] == "ended") {
  403. $event_length[$thisday][$j] = array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin");
  404. break;
  405. }
  406. $j++;
  407. }
  408. if ($j == sizeof(@$event_length[$thisday])) {
  409. $event_length[$thisday][] = array ("length" => ($drawEvent["draw_length"] / $phpiCal_config->gridLength), "key" => $eventKey, "overlap" => $loopevent["event_overlap"],"state" => "begin");
  410. }
  411. }
  412. if (empty($event_length[$thisday])) {
  413. # no events
  414. if ($dayborder == 0) {
  415. $class = ' class="weekborder"';
  416. $dayborder++;
  417. } else {
  418. $class = '';
  419. $dayborder = 0;
  420. }
  421. $drawWidth = 1;
  422. $colspan_width = round((80 / $nbrGridCols[$thisday]) * $drawWidth);
  423. $weekdisplay .= '<td width="' . $colspan_width . '" colspan="' . $nbrGridCols[$thisday] . '" ' . $class . '>&nbsp;</td>'."\n";
  424. } else {
  425. # have events
  426. $emptyWidth = $nbrGridCols[$thisday];
  427. // Used to "join" ended events, so the ended case below results in one colspan'd td instead of multiple tds.
  428. $ended_counter = 0;
  429. foreach($event_length[$thisday] as $i=>$el) {
  430. $drawWidth = $nbrGridCols[$thisday] / ($el["overlap"] + 1);
  431. $emptyWidth = $emptyWidth - $drawWidth;
  432. switch ($el["state"]) {
  433. case "begin":
  434. if ($ended_counter) {
  435. $weekdisplay .= '<td colspan="' . $ended_counter . '" '.$class.'>&nbsp;</td>';
  436. $ended_counter = 0;
  437. }
  438. $event_length[$thisday][$i]["state"] = "started";
  439. $uid = $event_length[$thisday][$i]["key"];
  440. $event_start = $this_time_arr[$uid]['start_unixtime'];
  441. $event_start = date ($timeFormat_small, $event_start);
  442. $event_calno = $this_time_arr[$uid]['calnumber'];
  443. $event_status = strtolower($this_time_arr[$uid]['status']);
  444. $event_recur = $this_time_arr[$uid]['recur'];
  445. $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
  446. $confirmed = '';
  447. if (is_array($event_recur)) $confirmed .= '<img src="images/recurring.gif" width="9" height="9" alt="" border="0" hspace="0" vspace="0" />&nbsp;';
  448. if ($event_status != '') {
  449. $confirmed .= '<img src="images/'.$event_status.'.gif" width="9" height="9" alt="" border="0" hspace="0" vspace="0" />&nbsp;';
  450. }
  451. $colspan_width = round((80 / $nbrGridCols[$thisday]) * $drawWidth);
  452. $event_temp = $loop_event;
  453. $event = openevent($thisday, $cal_time, $uid, $this_time_arr[$uid], $phpiCal_config->week_events_lines, 25, 'ps');
  454. $weekdisplay .= '<td width="'.$colspan_width.'" rowspan="' . $event_length[$thisday][$i]['length'] . '" colspan="' . $drawWidth . '" align="left" valign="top" class="eventbg2_'.$event_calno.'">'."\n";
  455. // Start drawing the event
  456. $event_temp = str_replace('{EVENT}', $event, $event_temp);
  457. $event_temp = str_replace('{EVENT_START}', $event_start, $event_temp);
  458. $event_temp = str_replace('{CONFIRMED}', $confirmed, $event_temp);
  459. $event_temp = str_replace('{EVENT_CALNO}', $event_calno, $event_temp);
  460. $weekdisplay .= $event_temp;
  461. $weekdisplay .= '</td>';
  462. // End event drawing
  463. break;
  464. case "started":
  465. if ($ended_counter) {
  466. $weekdisplay .= '<td colspan="' . $ended_counter . '" '.$class.'>&nbsp;</td>';
  467. $ended_counter = 0;
  468. }
  469. break;
  470. case "ended":
  471. $ended_counter += $drawWidth;
  472. break;
  473. }
  474. $event_length[$thisday][$i]["length"]--;
  475. if ($event_length[$thisday][$i]["length"] == 0) {
  476. $event_length[$thisday][$i]["state"] = "ended";
  477. }
  478. }
  479. // Clean up
  480. $emptyWidth += $ended_counter;
  481. //fill empty space on the right
  482. if ($emptyWidth > 0) {
  483. $weekdisplay .= "<td colspan=\"" . $emptyWidth . "\" $class>&nbsp;</td>\n";
  484. }
  485. while (isset($event_length[$thisday][(sizeof($event_length[$thisday]) - 1)]["state"]) && $event_length[$thisday][(sizeof($event_length[$thisday]) - 1)]["state"] == "ended") {
  486. array_pop($event_length[$thisday]);
  487. }
  488. }
  489. }
  490. $weekdisplay .= "</tr>\n";
  491. }
  492. $this->page = preg_replace('!<\!-- loop row on -->.*<\!-- loop event off -->!Uis', $weekdisplay, $this->page);
  493. }
  494. function draw_day($template_p) {
  495. global $getdate, $cal, $master_array, $dateFormat_week_list, $current_view, $day_array, $timeFormat, $phpiCal_config, $daysofweek_lang;
  496. // Replaces the allday events
  497. $replace = '';
  498. $weekday_loop = '';
  499. $daydisplay = '';
  500. if (is_array(@$master_array[$getdate]['-1'])) {
  501. preg_match("!<\!-- loop allday on -->(.*)<\!-- loop allday off -->!Uis", $this->page, $match1);
  502. $loop_ad = trim($match1[1]);
  503. foreach ($master_array[$getdate]['-1'] as $uid => $allday) {
  504. $event_calno = $allday['calnumber'];
  505. $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
  506. $event = openevent($getdate, -1, $uid, $allday);
  507. $loop_tmp = str_replace('{ALLDAY}', $event, $loop_ad);
  508. $loop_tmp = str_replace('{CALNO}', $event_calno, $loop_tmp);
  509. $replace .= $loop_tmp;
  510. }
  511. }
  512. $this->page = preg_replace('!<\!-- loop allday on -->.*<\!-- loop allday off -->!Uis', $replace, $this->page);
  513. // Replaces the daysofweek
  514. preg_match("!<\!-- loop daysofweek on -->(.*)<\!-- loop daysofweek off -->!Uis", $this->page, $match1);
  515. $loop_dof = trim($match1[1]);
  516. $start_wt = strtotime(dateOfWeek($getdate, $phpiCal_config->week_start_day));
  517. $start_day = strtotime(dateOfWeek($getdate, $phpiCal_config->week_start_day));
  518. for ($i=0; $i< $phpiCal_config->week_length; $i++) {
  519. $day_num = date("w", $start_day);
  520. $daylink = date('Ymd', $start_wt);
  521. if ($current_view == 'day') {
  522. $weekday = $daysofweek_lang[$day_num];
  523. } else {
  524. $weekday = localizeDate($dateFormat_week_list, strtotime($daylink));
  525. }
  526. if ($daylink == $getdate) {
  527. $row1 = 'rowToday';
  528. $row2 = 'rowOn';
  529. $row3 = 'rowToday';
  530. } else {
  531. $row1 = 'rowOff';
  532. $row2 = 'rowOn';
  533. $row3 = 'rowOff';
  534. }
  535. $start_day = strtotime("+1 day", $start_day);
  536. $start_wt = strtotime("+1 day", $start_wt);
  537. $search = array('{DAY}', '{DAYLINK}', '{ROW1}', '{ROW2}', '{ROW3}');
  538. $replace = array($weekday, $daylink, $row1, $row2, $row3);
  539. $loop_tmp = str_replace($search, $replace, $loop_dof);
  540. $weekday_loop .= $loop_tmp;
  541. }
  542. $this->page = preg_replace('!<\!-- loop daysofweek on -->.*<\!-- loop daysofweek off -->!Uis', $weekday_loop, $this->page);
  543. // Build the body
  544. $dayborder = 0;
  545. $nbrGridCols = 1;
  546. if (isset($master_array[($getdate)])) {
  547. foreach($master_array[($getdate)] as $ovlKey => $ovlValue) {
  548. if ($ovlKey != '-1') {
  549. foreach($ovlValue as $ovl2Value) {
  550. $nbrGridCols = kgv($nbrGridCols, ($ovl2Value['event_overlap'] + 1));
  551. }
  552. }
  553. }
  554. }
  555. preg_match("!<\!-- loop row on -->(.*)<\!-- loop row off -->!Uis", $this->page, $match2);
  556. preg_match("!<\!-- loop event on -->(.*)<\!-- loop event off -->!Uis", $this->page, $match3);
  557. $loop_hours = trim($match2[1]);
  558. $loop_event = trim($match3[1]);
  559. $event_length = array ();
  560. $border = 0;
  561. preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})/', $getdate, $day_array2);
  562. $this_day = $day_array2[3];
  563. $this_month = $day_array2[2];
  564. $this_year = $day_array2[1];
  565. foreach ($day_array as $key) {
  566. preg_match('/([0-9]{2})([0-9]{2})/', $key, $regs_tmp);
  567. $cal_time = $key;
  568. $key = mktime($regs_tmp[1],$regs_tmp[2],0,$this_month,$this_day,$this_year);
  569. $key = date ($timeFormat, $key);
  570. unset($this_time_arr);
  571. // add events that overlap $phpiCal_config->day_start instead of cutting them out completely
  572. if (($phpiCal_config->day_start == $cal_time) && (isset($master_array[$getdate]))) {
  573. foreach($master_array[$getdate] as $time_key => $time_arr) {
  574. if ((int)$time_key <= (int)$cal_time) {
  575. if (is_array($time_arr) && $time_key != '-1') {
  576. foreach($time_arr as $uid => $event_tmp) {
  577. if ((int)$event_tmp['event_end'] > (int)$cal_time) {
  578. $this_time_arr[$uid] = $event_tmp;
  579. }
  580. }
  581. }
  582. } else {
  583. break;
  584. }
  585. }
  586. } else {
  587. // add events that overlap the start time
  588. if (isset($master_array[$getdate][$cal_time]) && sizeof($master_array[$getdate][$cal_time]) > 0) {
  589. $this_time_arr = $master_array[$getdate][$cal_time];
  590. }
  591. }
  592. // check for eventstart
  593. if (isset($this_time_arr) && sizeof($this_time_arr) > 0) {
  594. foreach ($this_time_arr as $eventKey => $loopevent) {
  595. $drawEvent = drawEventTimes ($cal_time, $loopevent['display_end']);
  596. $j = 0;
  597. while (isset($event_length[$j])) {
  598. if ($event_length[$j]['state'] == 'ended') {
  599. $event_length[$j] = array ('length' => ($drawEvent['draw_length'] / $phpiCal_config->gridLength), 'key' => $eventKey, 'overlap' => $loopevent['event_overlap'],'state' => 'begin');
  600. break;
  601. }
  602. $j++;
  603. }
  604. if ($j == sizeof($event_length)) {
  605. array_push ($event_length, array ('length' => ($drawEvent['draw_length'] / $phpiCal_config->gridLength), 'key' => $eventKey, 'overlap' => $loopevent['event_overlap'],'state' => 'begin'));
  606. }
  607. }
  608. }
  609. if (preg_match('/([0-9]{1,2}):00/', $key)) {
  610. $daydisplay .= '<tr>'."\n";
  611. $daydisplay .= '<td rowspan="' . (60 / $phpiCal_config->gridLength) . '" align="center" valign="top" width="60" class="timeborder">'.$key.'</td>'."\n";
  612. $daydisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>'."\n";
  613. } elseif($cal_time == $phpiCal_config->day_start) {
  614. $size_tmp = 60 - (int)substr($cal_time,2,2);
  615. $daydisplay .= '<tr>'."\n";
  616. $daydisplay .= "<td rowspan=\"" . ($size_tmp / $phpiCal_config->gridLength) . "\" align=\"center\" valign=\"top\" width=\"60\" class=\"timeborder\">$key</td>\n";
  617. $daydisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>'."\n";
  618. } else {
  619. $daydisplay .= '<tr>'."\n";
  620. $daydisplay .= '<td bgcolor="#a1a5a9" width="1" height="' . $phpiCal_config->gridLength . '"></td>'."\n";
  621. }
  622. if ($dayborder == 0) {
  623. $class = ' class="dayborder"';
  624. $dayborder++;
  625. } else {
  626. $class = ' class="dayborder2"';
  627. $dayborder = 0;
  628. }
  629. if (sizeof($event_length) == 0) {
  630. $daydisplay .= '<td colspan="' . $nbrGridCols . '" '.$class.'>&nbsp;</td>'."\n";
  631. } else {
  632. $emptyWidth = $nbrGridCols;
  633. // Used to "join" ended events, so the ended case below results in one colspan'd td instead of multiple tds.
  634. $ended_counter = 0;
  635. for ($i=0;$i<sizeof($event_length);$i++) {
  636. $drawWidth = $nbrGridCols / ($event_length[$i]['overlap'] + 1);
  637. $emptyWidth = $emptyWidth - $drawWidth;
  638. switch ($event_length[$i]['state']) {
  639. case 'begin':
  640. if ($ended_counter) {
  641. $daydisplay .= '<td colspan="' . $ended_counter . '" '.$class.'>&nbsp;</td>';
  642. $ended_counter = 0;
  643. }
  644. $event_length[$i]['state'] = 'started';
  645. $uid = $event_length[$i]['key'];
  646. $event_calno = $this_time_arr[$uid]['calnumber'];
  647. $event_recur = $this_time_arr[$uid]['recur'];
  648. $event_status = strtolower($this_time_arr[$uid]['status']);
  649. $event_calno = (($event_calno - 1) % $phpiCal_config->unique_colors) + 1;
  650. $confirmed = '';
  651. if (is_array($event_recur)) $confirmed .= '<img src="images/recurring.gif" width="9" height="9" alt="" border="0" hspace="0" vspace="0" />&nbsp;';
  652. if ($event_status != '') $confirmed .= '<img src="images/'.$event_status.'.gif" width="9" height="9" alt="" border="0" hspace="0" vspace="0" />&nbsp;';
  653. $colspan_width = round((460 / $nbrGridCols) * $drawWidth);
  654. $daydisplay .= '<td rowspan="' . $event_length[$i]['length'] . '" width="'.$colspan_width.'" colspan="' . $drawWidth . '" align="left" valign="top" class="eventbg2_'.$event_calno.'">'."\n";
  655. // Start drawing the event
  656. $event_temp = $loop_event;
  657. $event = openevent($getdate, $cal_time, $uid, $this_time_arr[$uid], 0, 0, 'ps');
  658. $event_temp = str_replace('{EVENT}', $event, $event_temp);
  659. $event_temp = str_replace('{EVENT_START}', date($timeFormat, $this_time_arr[$uid]['start_unixtime']), $event_temp);
  660. $event_temp = str_replace('{EVENT_END}', date($timeFormat, $this_time_arr[$uid]['end_unixtime']), $event_temp);
  661. $event_temp = str_replace('{CONFIRMED}', $confirmed, $event_temp);
  662. $event_temp = str_replace('{EVENT_CALNO}', $event_calno, $event_temp);
  663. $daydisplay .= $event_temp;
  664. $daydisplay .= '</td>';
  665. // End event drawing
  666. break;
  667. case 'started':
  668. if ($ended_counter) {
  669. $daydisplay .= '<td colspan="' . $ended_counter . '" '.$class.'>&nbsp;</td>';
  670. $ended_counter = 0;
  671. }
  672. break;
  673. case 'ended':
  674. $daydisplay .= '<td colspan="' . $drawWidth . '" ' . $class . '>&nbsp;</td>'."\n";
  675. break;
  676. }
  677. $event_length[$i]['length']--;
  678. if ($event_length[$i]['length'] == 0) {
  679. $event_length[$i]['state'] = 'ended';
  680. }
  681. }
  682. // Clean up.
  683. $emptyWidth += $ended_counter;
  684. //fill empty space on the right
  685. if ($emptyWidth > 0) {
  686. $daydisplay .= '<td colspan="' . $emptyWidth . '" ' . $class . '>&nbsp;</td>'."\n";
  687. }
  688. while (isset($event_length[(sizeof($event_length) - 1)]) && $event_length[(sizeof($event_length) - 1)]['state'] == 'ended') {
  689. array_pop($event_length);
  690. }
  691. }
  692. $daydisplay .= '</tr>'."\n";
  693. }
  694. $this->page = preg_replace('!<\!-- loop row on -->.*<\!-- loop event off -->!Uis', $daydisplay, $this->page);
  695. }
  696. function tomorrows_events() {
  697. global $phpiCal_config, $getdate, $master_array, $next_day, $timeFormat, $tomorrows_events_lines;
  698. preg_match("!<\!-- switch t_allday on -->(.*)<\!-- switch t_allday off -->!Uis", $this->page, $match1);
  699. preg_match("!<\!-- switch t_event on -->(.*)<\!-- switch t_event off -->!Uis", $this->page, $match2);
  700. $loop_t_ad = trim($match1[1]);
  701. $loop_t_e = trim($match2[1]);
  702. $replace_ad = '';
  703. $replace_e = '';
  704. $return_adtmp = '';
  705. $return_etmp = '';
  706. if (isset($master_array[$next_day]) && is_array($master_array[$next_day]) && sizeof($master_array[$next_day]) > 0) {
  707. foreach ($master_array[$next_day] as $cal_time => $event_times) {
  708. foreach ($event_times as $uid => $val) {
  709. $event_text = stripslashes(urldecode($val["event_text"]));
  710. $event_text = strip_tags($event_text, '<b><i><u>');
  711. if ($event_text != "") {
  712. if (!isset($val["event_start"])) {
  713. $return_adtmp = openevent($next_day, $cal_time, $uid, $val, $phpiCal_config->tomorrows_events_lines, 21, 'psf');
  714. $replace_ad .= str_replace('{T_ALLDAY}', $return_adtmp, $loop_t_ad);
  715. } else {
  716. $return_etmp = openevent($next_day, $cal_time, $uid, $val, $phpiCal_config->tomorrows_events_lines, 21, 'ps3');
  717. $replace_e .= str_replace('{T_EVENT}', $return_etmp, $loop_t_e);
  718. }
  719. }
  720. }
  721. }
  722. $this->page = preg_replace('!<\!-- switch t_allday on -->.*<\!-- switch t_allday off -->!Uis', $replace_ad, $this->page);
  723. $this->page = preg_replace('!<\!-- switch t_event on -->.*<\!-- switch t_event off -->!Uis', $replace_e, $this->page);
  724. } else {
  725. $this->page = preg_replace('!<\!-- switch tomorrows_events on -->.*<\!-- switch tomorrows_events off -->!Uis', '', $this->page);
  726. }
  727. }
  728. function get_vtodo() {
  729. global $phpiCal_config, $getdate, $master_array, $next_day, $timeFormat, $tomorrows_events_lines;
  730. preg_match("!<\!-- switch show_completed on -->(.*)<\!-- switch show_completed off -->!Uis", $this->page, $match1);
  731. preg_match("!<\!-- switch show_important on -->(.*)<\!-- switch show_important off -->!Uis", $this->page, $match2);
  732. preg_match("!<\!-- switch show_normal on -->(.*)<\!-- switch show_normal off -->!Uis", $this->page, $match3);
  733. $completed = trim($match1[1]);
  734. $important = trim($match2[1]);
  735. $normal = trim($match3[1]);
  736. $nugget2 = '';
  737. $todo_popup_data_index = 0;
  738. if (is_array(@$master_array['-2'])) {
  739. foreach ($master_array['-2'] as $vtodo_times) {
  740. foreach ($vtodo_times as $val) {
  741. $vtodo_text = stripslashes(urldecode($val["vtodo_text"]));
  742. if ($vtodo_text != "") {
  743. if (isset($val["description"])) {
  744. $description = stripslashes(urldecode($val["description"]));
  745. } else {
  746. $description = "";
  747. }
  748. $completed_date = $val['completed_date'];
  749. $event_calna = $val['calname'];
  750. $status = $val["status"];
  751. $priority = $val['priority'];
  752. $start_date = $val["start_date"];
  753. $due_date = $val['due_date'];
  754. $vtodo_array = array(
  755. 'cal' => $event_calna,
  756. 'completed_date'=> $completed_date,
  757. 'description' => $description,
  758. 'due_date' => $due_date,
  759. 'priority' => $priority,
  760. 'start_date' => $start_date,
  761. 'status' => $status,
  762. 'vtodo_text' => $vtodo_text);
  763. $vtodo_array = base64_encode(urlencode(serialize($vtodo_array)));
  764. $todo = "
  765. <script language=\"Javascript\" type=\"text/javascript\"><!--
  766. var todoData = new TodoData('$vtodo_array','$vtodo_text');
  767. document.todo_popup_data[$todo_popup_data_index] = todoData;
  768. // --></script>";
  769. $todo .= '<a class="psf" title="'.@$title.'" href="#" onclick="openTodoInfo('.$todo_popup_data_index.'); return false;">';
  770. $todo_popup_data_index++;
  771. $vtodo_array = $todo;
  772. $vtodo_text = word_wrap(strip_tags(str_replace('<br />',' ',$vtodo_text), '<b><i><u>'), 21, $phpiCal_config->tomorrows_events_lines);
  773. $data = array ('{VTODO_TEXT}', '{VTODO_ARRAY}');
  774. $rep = array ($vtodo_text, $vtodo_array);
  775. // Reset this TODO's category.
  776. $temp = '';
  777. if ($status == 'COMPLETED' || ($val['completed_date'] !='' && $val['completed_time'] !='')) {
  778. if ($phpiCal_config->show_completed == 'yes') {
  779. $temp = $completed;
  780. }
  781. } elseif (isset($val['priority']) && ($val['priority'] != 0) && ($val['priority'] <= 5)) {
  782. $temp = $important;
  783. } else {
  784. $temp = $normal;
  785. }
  786. // Do not include TODOs which do not have the
  787. // category set.
  788. if ($temp != '') {
  789. $nugget1 = str_replace($data, $rep, $temp);
  790. $nugget2 .= $nugget1;
  791. }
  792. }
  793. }
  794. }
  795. }
  796. // If there are no TODO items, completely hide the TODO list.
  797. if (($nugget2 == '') || ($phpiCal_config->show_todos != 'yes')) {
  798. $this->page = preg_replace('!<\!-- switch vtodo on -->.*<\!-- switch vtodo off -->!Uis', '', $this->page);
  799. }
  800. // Otherwise display the list of TODOs.
  801. else {
  802. $this->page = preg_replace('!<\!-- switch show_completed on -->.*<\!-- switch show_normal off -->!Uis', $nugget2, $this->page);
  803. }
  804. }
  805. function draw_month($template_p, $offset = '+0', $type) {
  806. global $phpiCal_config, $getdate, $master_array, $this_year, $this_month, $dateFormat_month, $cal, $minical_view, $month_event_lines, $daysofweekreallyshort_lang, $daysofweekshort_lang, $daysofweek_lang, $timeFormat_small, $timeFormat;
  807. $unique_colors = $phpiCal_config->unique_colors;
  808. preg_match("!<\!-- loop weekday on -->(.*)<\!-- loop weekday off -->!Uis", $template_p, $match1);
  809. preg_match("!<\!-- loop monthdays on -->(.*)<\!-- loop monthdays off -->!Uis", $template_p, $match2);
  810. preg_match("!<\!-- switch notthismonth on -->(.*)<\!-- switch notthismonth off -->!Uis", $template_p, $match3);
  811. preg_match("!<\!-- switch istoday on -->(.*)<\!-- switch istoday off -->!Uis", $template_p, $match4);
  812. preg_match("!<\!-- switch ismonth on -->(.*)<\!-- switch ismonth off -->!Uis", $template_p, $match5);
  813. preg_match("!<\!-- loop monthweeks on -->(.*)<\!-- loop monthdays on -->!Uis", $template_p, $match6);
  814. preg_match("!<\!-- loop monthdays off -->(.*)<\!-- loop monthweeks off -->!Uis", $template_p, $match7);
  815. $loop_wd = trim($match1[1]);
  816. $loop_md = trim($match2[1]);
  817. $t_month[0] = trim($match3[1]);
  818. $t_month[1] = trim($match4[1]);
  819. $t_month[2] = trim($match5[1]);
  820. $startweek = trim($match6[1]);
  821. $endweek = trim($match7[1]);
  822. if ($type != 'medium') {
  823. $fake_getdate_time = strtotime($this_year.'-'.$this_month.'-15');
  824. $fake_getdate_time = strtotime("$offset month", $fake_getdate_time);
  825. } else {
  826. $fake_getdate_time = strtotime($this_year.'-'.$offset.'-15');
  827. }
  828. $minical_month = date("m", $fake_getdate_time);
  829. $minical_year = date("Y", $fake_getdate_time);
  830. $first_of_month = $minical_year.$minical_month."01";
  831. $first_of_year = $minical_year."0101";
  832. // Add links in to the month/year views.
  833. $dateFormat_month_local = str_replace("%B", "<a class=\"ps3\" href=\"month.php?cal=$cal&amp;getdate=$first_of_month\">%B</a>", $dateFormat_month);
  834. $dateFormat_month_local = str_replace("%Y", "<a class=\"ps3\" href=\"year.php?cal=$cal&amp;getdate=$first_of_year\">%Y</a>", $dateFormat_month_local);
  835. //$start_day = strtotime($phpiCal_config->week_start_day);
  836. $start_day = strtotime(dateOfWeek($getdate, $phpiCal_config->week_start_day));
  837. $month_title = localizeDate ($dateFormat_month_local, $fake_getdate_time);
  838. $month_date = date ('Ymd', $fake_getdate_time);
  839. if ($type == 'small') {
  840. $langtype = $daysofweekreallyshort_lang;
  841. } elseif ($type == 'medium') {
  842. $langtype = $daysofweekshort_lang;
  843. } elseif ($type == 'large') {
  844. $langtype = $daysofweek_lang;
  845. }
  846. $weekday_loop = '';
  847. $middle = '';
  848. for ($i=0; $i< $phpiCal_config->week_length; $i++) {
  849. $day_num = date("w", $start_day);
  850. $weekday = $langtype[$day_num];
  851. $start_day = strtotime("+1 day", $start_day);
  852. $loop_tmp = str_replace('{LOOP_WEEKDAY}', $weekday, $loop_wd);
  853. $weekday_loop .= $loop_tmp;
  854. }
  855. $start_day = strtotime(dateOfWeek($first_of_month, $phpiCal_config->week_start_day));
  856. $i = 0;
  857. $whole_month = TRUE;
  858. do {
  859. if ($i == 0) $middle .= $startweek; $i++;
  860. #$temp_middle = $loop_md;
  861. $switch = array('ALLDAY' => '', 'CAL' => $cal, 'MINICAL_VIEW' => $minical_view);
  862. $check_month = date ("m", $start_day);
  863. $daylink = date ("Ymd", $start_day);
  864. $switch['DAY'] = date ("j", $start_day);
  865. $switch['DAYLINK'] = date ("Ymd", $start_day);
  866. if ($check_month != $minical_month) {
  867. $temp = $t_month[0];
  868. } elseif ($daylink == $getdate) {
  869. $temp = $t_month[1];
  870. } else {
  871. $temp = $t_month[2];
  872. }
  873. $switch['ALLDAY'] = $switch['EVENT'] = '';
  874. if (isset($master_array[$daylink]) && $i <= $phpiCal_config->week_length) {
  875. if ($type != 'small') {
  876. foreach ($master_array[$daylink] as $cal_time => $event_times) {
  877. foreach ($event_times as $uid => $val) {
  878. if (!isset($val['calnumber'])) continue;
  879. $event_calno = $val['calnumber'];
  880. $event_calno = (($event_calno - 1) % $unique_colors) + 1;
  881. if ($cal_time == -1) {
  882. if ($type == 'large') {
  883. $switch['ALLDAY'] .= '<div class="V10"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
  884. $switch['ALLDAY'] .= openevent($daylink, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 15, 'psf');
  885. $switch['ALLDAY'] .= (isset($val['location']) && $val['location'] != '' && $phpiCal_config->month_locations == 'yes') ? $val['location']."<br />" : '';
  886. $switch['ALLDAY'] .= '</div>';
  887. } else {
  888. $switch['ALLDAY'] = '<img src="templates/'.$phpiCal_config->template.'/images/allday_dot.gif" alt=" " width="11" height="10" border="0" />';
  889. }
  890. } else {
  891. $start2 = date($timeFormat_small, $val['start_unixtime']);
  892. if ($type == 'large') {
  893. $switch['EVENT'] .= '<div class="V9"><img src="templates/'.$phpiCal_config->template.'/images/monthdot_'.$event_calno.'.gif" alt="" width="9" height="9" border="0" />';
  894. $switch['EVENT'] .= openevent($daylink, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 10, 'ps3', "$start2 ").'';
  895. $switch['EVENT'] .= (isset($val['location']) && $val['location'] != '' && $phpiCal_config->month_locations == 'yes') ? "<br />".$val['location']."<br />" : '';
  896. $switch['EVENT'] .= '</div>';
  897. } else {
  898. $switch['EVENT'] = '<img src="templates/'.$phpiCal_config->template.'/images/event_dot.gif" alt=" " width="11" height="10" border="0" />';
  899. }
  900. }
  901. }
  902. }
  903. }
  904. }
  905. $switch['EVENT'] = (isset($switch['EVENT'])) ? $switch['EVENT'] : '';
  906. $switch['ALLDAY'] = (isset($switch['ALLDAY'])) ? $switch['ALLDAY'] : '';
  907. #echo "<pre>";print_r($switch);echo "</pre>";
  908. foreach ($switch as $tag => $data) {
  909. $temp = str_replace('{'.$tag.'}', $data, $temp);
  910. }
  911. $middle .= $temp;
  912. $start_day = strtotime("+1 day", $start_day);
  913. if ($i == $phpiCal_config->week_length) {
  914. if ($phpiCal_config->week_length != 7) {
  915. $start_day = strtotime("+".(7-$phpiCal_config->week_length)." day", $start_day);
  916. }
  917. $i = 0;
  918. $middle .= $endweek;
  919. $checkagain = date ("m", $start_day);
  920. if ($checkagain != $minical_month) $whole_month = FALSE;
  921. }
  922. } while ($whole_month == TRUE);
  923. $return = str_replace('<!-- loop weekday on -->'.$match1[1].'<!-- loop weekday off -->', $weekday_loop, $template_p);
  924. $return = preg_replace('!<\!-- loop monthweeks on -->.*<\!-- loop monthweeks off -->!Uis', $middle, $return);
  925. $return = str_replace('{MONTH_TITLE}', $month_title, $return);
  926. $return = str_replace('{CAL}', $cal, $return);
  927. $return = str_replace('{MONTH_DATE}', $month_date, $return);
  928. return $return;
  929. }
  930. function nomonthbottom() {
  931. $this->page = preg_replace('!<\!-- switch showbottom on -->.*<\!-- switch showbottom off -->!Uis','', $this->page);
  932. }
  933. function nosearch() {
  934. $this->page = preg_replace('!<\!-- switch show_search on -->.*<\!-- switch show_search off -->!Uis','', $this->page);
  935. }
  936. function monthbottom() {
  937. global $phpiCal_config, $getdate, $master_array, $this_year, $this_month, $cal, $timeFormat, $timeFormat_small, $dateFormat_week_list, $lang;
  938. preg_match("!<\!-- loop showbottomevents_odd on -->(.*)<\!-- loop showbottomevents_odd off -->!Uis", $this->page, $match1);
  939. preg_match("!<\!-- loop showbottomevents_even on -->(.*)<\!-- loop showbottomevents_even off -->!Uis", $this->page, $match2);
  940. $loop[0] = trim($match1[1]);
  941. $loop[1] = trim($match2[1]);
  942. $m_start = $this_year.$this_month.'01';
  943. $u_start = strtotime($m_start);
  944. $i=0;
  945. $seen_events = array();
  946. $middle = '';
  947. do {
  948. if (isset($master_array[$m_start])) {
  949. foreach ($master_array[$m_start] as $cal_time => $event_times) {
  950. # $switch['CAL'] = $cal;
  951. # $switch['START_DATE'] = localizeDate ($dateFormat_week_list, $u_start);
  952. $start_date = localizeDate ($dateFormat_week_list, $u_start);
  953. foreach ($event_times as $uid => $val) {
  954. if (isset($seen_events[$uid]) && @$val['spans_day'] == 1) continue;
  955. $seen_events[$uid] = 1;
  956. $switch['CAL'] = $cal;
  957. $switch['START_DATE'] = $start_date;
  958. $switch['CALNAME'] = $val['calname'];
  959. if (!isset($val['event_start'])) {
  960. $switch['START_TIME'] = $lang['l_all_day'];
  961. $switch['EVENT_TEXT'] = openevent($m_start, $cal_time, $uid, $val, $phpiCal_config->month_event_lines, 15, 'psf');
  962. $switch['DESCRIPTION'] = urldecode($val['description']);
  963. } else {
  964. $event_start = $val['start_unixtime'];
  965. $event_end = (isset($val['display_end'])) ? $val['display_end'] : $val["event_end"];
  966. $event_start = date($timeFormat, $val['start_unixtime']);
  967. $event_end = date($timeFormat, $val['end_unixtime']);
  968. $switch['START_TIME'] = $event_start . ' - ' . $event_end;
  969. $switch['EVENT_TEXT'] = openevent($m_start, $cal_time, $uid, $val, 0, 15, 'psf');
  970. $switch['DESCRIPTION'] = urldecode($val['description']);
  971. }
  972. if ($switch['EVENT_TEXT'] != '') {
  973. $switch['DAYLINK'] = $m_start;
  974. $temp = $loop[$i];
  975. foreach ($switch as $tag => $data) {
  976. $temp = str_replace('{'.$tag.'}', $data, $temp);
  977. }
  978. $middle .= $temp;
  979. $i = ($i == 1) ? 0 : 1;
  980. }
  981. unset ($switch);
  982. }
  983. }
  984. }
  985. $u_start = strtotime("+1 day", $u_start);
  986. $m_start = date('Ymd', $u_start);
  987. $check_month = date('m', $u_start);
  988. # unset ($switch);
  989. } while ($this_month == $check_month);
  990. $this->page = preg_replace('!<\!-- loop showbottomevents_odd on -->.*<\!-- loop showbottomevents_even off -->!Uis', $middle, $this->page);
  991. }
  992. function Page($file = 'std.tpl') {
  993. global $phpiCal_config;
  994. if (!file_exists($file)){
  995. #look for it in default if not found
  996. $file = str_replace("templates/$phpiCal_config->template","templates/default",$file);
  997. if (!file_exists($file)) die("Template file $file not found.");
  998. }
  999. $this->page = join('', file($file));
  1000. return;
  1001. }
  1002. function parse($file) {
  1003. global $phpiCal_config; $lang;
  1004. if (basename(dirname($file)) == "$phpiCal_config->template" || $file =='./functions/event.js'){
  1005. if (!is_file($file)){
  1006. #look for it in default if not found
  1007. $file = str_replace("templates/$phpiCal_config->template","templates/default",$file);
  1008. }
  1009. if (!is_file($file)){
  1010. exit(error($lang['l_error_path'], $file));
  1011. }
  1012. ob_start();
  1013. include($file);
  1014. $buffer = ob_get_contents();
  1015. ob_end_clean();
  1016. return $buffer;
  1017. }
  1018. }
  1019. function replace_tags($tags = array()) {
  1020. if (sizeof($tags) > 0)
  1021. foreach ($tags as $tag => $data) {
  1022. // This removes any unfilled tags
  1023. if (!$data) {
  1024. $this->page = preg_replace('!<\!-- switch ' . $tag . ' on -->.*<\!-- switch ' . $tag . ' off -->!Uis', '', $this->page);
  1025. }
  1026. // This replaces any tags
  1027. $this->page = str_replace('{' . strtoupper($tag) . '}', $data, $this->page);
  1028. }
  1029. else
  1030. die('No tags designated for replacement.');
  1031. }
  1032. function replace_files($tags = array()) {
  1033. if (sizeof($tags) > 0)
  1034. foreach ($tags as $tag => $data) {
  1035. // This opens up another template and parses it