function events($link, $d_date5, $d_date6, $d_date10) { $str_ajax_output = ''; //$cur_mkt = h99(); $cur_mysql_date = $d_date5; //$mkt_cur_mysql_date = mktime_mysql($cur_mysql_date); $mkt_cur_mysql_date = time(); $gt_firstload = @$_GET['firstload']; //echo $cur_mkt; // $r = $link->query("SELECT * FROM diary_events WHERE status!='expired' ORDER BY due asc"); $str_ajax_output .= '<table id="ev">'; $ev_cntr = 1; while ($rw = $r->fetch()) { $db_id = $rw['id']; $db_due = $rw['due']; $db_due_b = $db_due; //$str_ajax_output.= $db_due; $expl_db_due = explode(" ", $db_due); $db_descr = $rw['descr']; $mkt_db_due = mktime_mysqldt($db_due); $db_date_due = $expl_db_due[0]; $mkt_db_due2 = mktime_mysql($db_date_due); //$diff1 = ($mkt_db_due > $cur_mkt) ? $mkt_db_due - $cur_mkt : $cur_mkt - $mkt_db_due; $diff1 = $mkt_db_due - time(); $diff_x = $mkt_db_due - $mkt_cur_mysql_date; //$diff2 = ($mkt_db_due2 > $mkt_cur_mysql_date) ? $mkt_db_due2 - $mkt_cur_mysql_date : $mkt_cur_mysql_date - $mkt_db_due2; $diff2 = $mkt_db_due2 - $mkt_cur_mysql_date; $db_freq = $rw['freq']; $diff3 = $diff2 / 60 / 60 / 24; $diff3 = floor($diff3); //$diff3 = floor($diff2/60/60/24); //$str_ajax_output.= $diff3 . ' day(s):'; if ($diff3 <= 0 && $db_freq == '14 days') { // Forthnightly recurring event - Add 14 days if current is in the past //echo $db_due; $db_due_b = date('Y-m-d H:i:s', $mkt_db_due + 14 * 86400); $db_due2 = date('Y-m-d', $mkt_db_due2 + 14 * 86400); // Only update if there is a new value: // if ($db_due_b != $db_due) { //$db2 = new DB_diary; $r2 = $link->query("UPDATE diary_events SET due='{$db_due_b}' WHERE id={$db_id}"); // } $mkt_db_due = mktime_mysql($db_due2); // Problem where the event expires at midnight on the day of event rather than when the exact time of the event is reached //$diff2 = ($mkt_db_due > $mkt_cur_mysql_date) ? $mkt_db_due - $mkt_cur_mysql_date : $cur_mkt - $mkt_db_due; $diff2 = $mkt_db_due2 - $mkt_cur_mysql_date; } if ($db_freq == "regular") { // Like 'Enders: four times a week $db_det = $rw['det']; // Example: Mon@20:00;Tue@19:30;Thu@19:30;Fri@20:00 $det_split = explode(";", $db_det); $num = count($det_split); // Number of times event occurs in a week $arr1 = array(); for ($i = 0; $i < $num; $i++) { array_push($arr1, $det_split[$i]); } $num2 = count($arr1); // Number of times event occurs in a week, $num == $num2 ? //$arr2 = array(); $arr_days = array(); $arr_times = array(); $arr4 = array(); for ($i = 0; $i < $num2; $i++) { $dayandtime = explode("@", $arr1[$i]); $time = $dayandtime[1]; $expl_time = explode(":", $time); array_push($arr_days, $dayandtime[0]); array_push($arr_times, $time); } $num3 = count($arr_days); for ($i = 0; $i < $num3; $i++) { $elem = $arr_days[$i]; // Get the date for the next event on day '$elem' array_push($arr4, NextWDay(date("Y-m-d"), $elem, 'decimal')); } // array_multisort() saves the day! earliest date occupies first index array_multisort($arr4, SORT_ASC, $arr_times); // Generate different descr - only works when current time is before event 'on the day event occurs' $db_due_b = $arr4[0] . ' ' . $arr_times[0] . ':00'; // Get earliest date and time $db_due2 = $arr4[0]; // Get earliest date only if ($arr4[0] == $cur_mysql_date && $d_date10 > $arr_times[0]) { // Get the next highest value from arrays i.e one with index 1 $db_due_b = $arr4[1] . ' ' . $arr_times[1] . ':00'; $db_due2 = $arr4[1]; //$str_ajax_output.= (date("H:i:s") > $arr_times[0]) . '<br />'; } $mkt_db_due2 = mktime_mysqldt($db_due_b); // Subtract CURRENT TIMESTAMP from the timestamp of the date and time of event //$diff = ($mkt_db_due > $cur_mkt) ? $mkt_db_due - $cur_mkt : $cur_mkt - $mkt_db_due; $diff1 = $mkt_db_due2 - time(); // Subtract TIMESTAMP FROM CURRENT DAY AT MIDNIGHT from the timestamp of the date and time of event //$diff2 = ($mkt_db_due2 > $mkt_cur_mysql_date) ? $mkt_db_due2 - $cur_mkt : $mkt_cur_mysql_date - $mkt_db_due2; // Subtract the UNIX timestamp for the start of the current day from the datetime of the due time $diff2 = $mkt_db_due2 - $mkt_cur_mysql_date; if ($diff1 < 0) { // Find next value //$str_ajax_output.= $db_due_b . '<br />'; } //$db2 = new DB_diary; $r2 = $link->query("UPDATE diary_events SET due='{$db_due_b}' WHERE id={$db_id}"); } // end if freq=regular $diff4 = $diff1 / 60 / 60; // Hours to event $diff5 = $diff2 / 60 / 60; // Hours to event $diff6 = floor($diff4 / 24); // Days to event $diff7 = floor($diff5 / 24); // Days to event //$str_ajax_output.= $diff1 . '<br />'; // //$str_ajax_output.= $diff1 . '<br />'; // //$str_ajax_output.= $diff2 . '<br />'; // //$str_ajax_output.= $diff4 . '<br />'; //$str_ajax_output.= $diff5 . '<br />'; //$str_ajax_output.= $diff6 . '<br />'; //$str_ajax_output.= $diff7 . '<br />'; if ($diff6 == 0) { // On the day of event $hours = floor($diff4); $mins = floor(($diff4 - $hours) * 60); // $secs = floor(); $str_hrs_mins = $hours . ' hrs and ' . $mins . ' mins'; if ($hours < 0) { $days1 = '<span style="color: #c00; font-weight: bold">' . $str_hrs_mins . '</span>'; } else { $days1 = '<span style="color: #000; font-weight: bold">' . $str_hrs_mins . '</span>'; } } else { if ($diff6 == 1) { // Tomorrow? //$days1 = $diff3 . ' day\'s time1'; // Day after tomorrow or later $days1 = 'Tommorrow'; // Day after tomorrow or later } else { if ($diff6 > 1) { $days1 = $diff3 . ' day\'s time'; } else { $days1 = 'in ' . $diff3 . ' days ago!'; } } } // In the past $days1 = '(' . $days1 . ')'; // Echo details for the most imminent event if ($ev_cntr == 1) { if (!isset($hours)) { $hours = 0; } if (!isset($mins)) { $mins = 0; } $nxt_evnt_hrs = sing_num($hours); $nxt_evnt_mns = sing_num($mins); } // Don't show if event has passed! if ($diff1 <= 0) { $days1 = ''; $tdclassexpired = ' id="expired"'; } else { $tdclassexpired = ' class="not_expired"'; } $str_ajax_output .= '<tr valign="top"> <!-- <td>' . $rw['id'] . '</td> --> <td><a href="javascript://" title="View Full Details and Options" onclick="eventsFunc(\'editeventfrm\', ' . $db_id . ');">' . $db_descr . '</a></td> <td><a href="javascript://" title="Go to date in diary" onclick="gotoday(\'' . TOOLS_SCRIPT . '?act=gotoday&dt_d=' . $db_date_due . '\')">' . date("D", $mkt_db_due2) . '</a></td> <td ' . @$tdclassexpired . '><a href="javascript://" title="Go to date in diary" onclick="gotoday(\'' . TOOLS_SCRIPT . '?act=gotoday&dt_d=' . $db_date_due . '\')">' . formatmydate($db_due_b, 0) . ' ' . $days1 . '</a></td> <td>' . $rw['Location'] . '</td> <td><a href="javascript://" title="Delete Event" onlick="if(confirmDelete(\'Delete Event?\')){eventsFunc(\'delevent\');}else{return false;}">X</a></td> <!-- <td><a href="" title="Just Remove from list">Remove</a></td> <td><a href="" title="Delete completely">Delete</a></td> --> <!-- <td>' . $rw['notes'] . '</td> --> </tr>'; $ev_cntr++; } // end while $r = $link->query("SELECT upd FROM diary_events ORDER BY upd desc"); $rw = $r->fetch(); $str_ajax_output .= ' <tr valign="top"> <td colspan="5" align="center"> Page Load Time: <div id="time2"></div> <!--<input id="chk_t" type="checkbox" name="chk_title" value="" /> | --> <a href="javascript://" onclick="eventsFunc(\'addeventfrm\');">New Event</a> | '; $db_update_d = gmktime_mysqldt($rw['upd']); //$str_ajax_output.= 'Page Load/Refresh: ' . @date("d-m-Y H:i:s", $gt_firstload) . ' | '; $str_ajax_output .= 'Last Database Update: ' . date("d-m-Y H:i:s", $db_update_d) . " | Pane Update Time: {$d_date10}</td>\r\n</tr></table>"; if (isset($nxt_evnt_mns)) { $hours = $nxt_evnt_hrs; $mins = $nxt_evnt_mns; } // If no event is expected today (or event has passed), 00:00:00 is passed as first part of array! if (!isset($hours) || $hours < 0) { $hours = $mins = $secs = 0; } if (!isset($mins)) { $mins = 0; } echo sing_num($hours) . ':' . sing_num($mins) . ':00' . '==||==' . $gt_firstload . '==||==' . $str_ajax_output; }
function helpcal($link, $i, $subsequentrowcellcounter, $subseq = 0) { global $tootipchars, $arr_d, $colspan_1; $full_date = "{$_GET['y']}-" . sing_num($_GET['m']) . '-' . sing_num($i); $full_date2 = date('l jS F, Y', strtotime($full_date)); $popuptxt = get_info($link, $full_date, $tootipchars); if (strlen($popuptxt) > 0) { $popuptxt2 = '<div class="date_s">' . "{$full_date2}<br />[" . days_from_days_to($full_date) . "]</div>\r\n <p>{$popuptxt}</p>"; $tdclass = 'three_col'; } else { // No entry $popuptxt2 = ''; $tdclass = 'four_col'; } // End if. $str = ''; if ($subseq and $subsequentrowcellcounter > 6) { $subsequentrowcellcounter = $subsequentrowcellcounter % 7; } if (date("j") == $i and date("n") == $_GET['m'] and date("Y") == $_GET['y']) { // Highlight current date $str .= writetdcell('curDate', $popuptxt2, $full_date, $arr_d[$subsequentrowcellcounter], 1, $i); } else { if (isset($_GET['d']) and $_GET['d'] == $i) { // Selected day that is not the current day: $str .= writetdcell('sel_col', $popuptxt2, $full_date, $arr_d[$subsequentrowcellcounter], isCurWk($full_date), $i); } else { // $str .= writetdcell($tdclass, $popuptxt2, $full_date, $arr_d[$subsequentrowcellcounter], isCurWk($full_date), $i); } } // End if. return $str; }