$start_hour = rand(0, 22);
            $start_min = rand(0, 59);
            $start_index = sprintf('%s-%02d-%02dT%02d:%02d:00-07:00', $year, $start_month, $start_day, $start_hour, $start_min);
            $durindex = rand(0, 3);
            $duration = $durations[$durindex];
            $cyclicity = rand(1, 127);
            $end_month = $start_month + rand(1, 12);
            if ($end_month > 12) {
                $end_month -= 12;
                $year++;
            }
            $index = sprintf('%04d-%02d-01T00:00:00-07:00', $year, $end_month);
            $ts = strtotime($index);
            $end_day = rand(1, date('t', $ts));
            $end_hour = rand(0, 23);
            $end_min = rand(0, 59);
            $end_index = sprintf('%s-%02d-%02dT%02d:%02d:00-07:00', $year, $end_month, $end_day, $end_hour, $end_min);
            $string[$i] = array($start_index, $duration, $cyclicity, $end_index);
        }
        $content_r = json_encode($string);
        //var_dump( $content_r ); exit();
        $record = array();
        $record[] = array(':author', $account_no, PDO::PARAM_STR);
        $record[] = array(':content', $content_r, PDO::PARAM_STR);
        bind_params($record, $query[14]);
        $query[14]->execute();
    }
    //$result = json_decode( $content_r, TRUE );
    //var_dump( $result );
}
exit;
Example #2
0
/*
* 8.0 Serialize view if allowed to 
*/
try {
    if ($presentation->cache_allowed) {
        /* if new view was created, then use 'INSERT' query. Use 'UPDATE' if viwe was unserialized (view record already exists) */
        $params = array(0 => array(':session_id', $session_id, PDO::PARAM_STR), 1 => array(':session_token', session_token(), PDO::PARAM_STR), 2 => array(':data', serialize($presentation), PDO::PARAM_STR), 3 => array(':ttl', CACHE_TIME, PDO::PARAM_INT));
        if ($view_regen) {
            // delete former cached view(s) from session_cache
            $query[3]->bindParam(':session_id', $session_id, PDO::PARAM_STR);
            $query[3]->execute();
            /* insert view into session_cache table */
            bind_params($params, $query[5]);
            if (!$query[5]->execute()) {
                error_log(sprintf($warnings['18'], $_SESSION['user']['view'], $session_id));
            }
        } else {
            /* update view in the session_cache table */
            $params[] = array(':id', $result[2]['id'], PDO::PARAM_INT);
            // this is done bc session_token is not primary key, id is and UPDATE statement needs to update by primary key
            bind_params($params, $query[4]);
            if (!$query[4]->execute()) {
                throw new CustomException(sprintf($errors['22'], $_SESSION['user']['view'], $session_id));
            }
        }
        unset($params);
    }
} catch (CustomException $e) {
    echo $e;
    exit;
}
Example #3
0
 function update_event_cycles($group, $cat)
 {
     global $query;
     if (!isset($this->cycle[$cat][$group])) {
         // define this function for the array_walk callback as it turns out the callback funcs need to be declared before the array_walk and cannot be outside of the current func
         $params = array(0 => array(':user_group', sprintf('["%s"]', $group), PDO::PARAM_STR), 1 => array(':cat', sprintf('["%s"]', $cat), PDO::PARAM_STR), 2 => array(':city', $this->city, PDO::PARAM_STR));
         bind_params($params, $query[11]);
         $query[11]->execute();
         $this->cycle[$cat][$group] = $query[11]->fetchAll(PDO::FETCH_ASSOC);
         // unpack json strings in cont_categories into arrays
         //array_walk( $this->cycle[$cat][$group], 'myjason_decode', 'cont_categories' );
         //var_dump( $this->cycle[$cat][$group] );
     }
 }
 function __toString()
 {
     global $site_settings, $query;
     $mask = array(1 => 0b1000000, 2 => 0b100000, 3 => 0b10000, 4 => 0b1000, 5 => 0b100, 6 => 0b10, 7 => 0b1);
     //masks used for bitwise ops on the cyclicity flag of each appointment
     foreach ($site_settings['cats'] as $cat) {
         /* Fetch all cycles of given cat */
         $params = array(0 => array(':author', $_SESSION['user']['account_no'], PDO::PARAM_STR), 1 => array(':cat', sprintf('["%s"]', $cat), PDO::PARAM_STR));
         bind_params($params, $query[32]);
         $query[32]->execute();
         $this->cycle[$cat][$this->group] = $query[32]->fetchAll(PDO::FETCH_ASSOC);
         /* Reserve arrays for calendar participants for each category of their events. This avoids missing indicies problem when merging arrays */
         $this->cal['members'][$cat][$this->group]['f.l'] = array();
         $this->cal['members'][$cat][$this->group]['l.f'] = array();
         /* Unpack event cycles into $this->events[<group>] and fill in members that occur into $this->cal['members'][<group>] */
         foreach ($this->cycle[$cat][$this->group] as $l) {
             // pull each fetched content record done by query[11]
             $content = json_decode($l['content'], TRUE);
             // TRUE makes array instead of objects. Schedule content is stored as collection of enumerations.
             foreach ($content as $cycle) {
                 // record is in the format: array( 'YYYY-MM-DDTHH:MM:SS+00:00',<duration>,<cyclicity>,'YYYY-MM-DDTHH:MM:SS+00:00' )
                 $event['cycle_start_ts'] = strtotime($cycle[0]);
                 $event['cycle_end_ts'] = strtotime($cycle[3]);
                 /* check if event cycle falls within our calendar scope */
                 if ($event['cycle_end_ts'] > $this->cal['start_ts'] || $event['cycle_start_ts'] < $this->cal['end_ts']) {
                     /* check if event cycle needs to be cut to match either $this->cal['start_ts'] or $this->cal['end_ts'] plus corresponding weekday and hour offsets */
                     if ($event['cycle_start_ts'] < $this->cal['start_ts']) {
                         $offset['hour'] = date('G', $event['cycle_start_ts']) * 3600;
                         $offset['min'] = date('i', $event['cycle_start_ts']) * 60;
                         $event['cycle_start_ts'] = $this->cal['start_ts'] + array_sum($offset);
                     }
                     if ($event['cycle_end_ts'] > $this->cal['end_ts']) {
                         $event['cycle_end_ts'] = $this->cal['end_ts'];
                     }
                     for ($ts = $event['cycle_start_ts']; $ts <= $event['cycle_end_ts'];) {
                         $dow = date('N', $ts);
                         // get ISO-8601 numeric representation of the day of the week 1(Monday), 7(Sunday)
                         /* Mask for day of the week returns itself if corresponding bits are set in the cycle[2], otherwise 0 */
                         if ($mask[$dow] & $cycle[2]) {
                             // returns $this->mask[$dow] if corresponding bits are set in $cycle[2]
                             $event['start_ts'] = $ts;
                             $date = date('Y-m-d', $ts);
                             $length = $cycle[1] * 60;
                             $event['end_ts'] = $ts + $length;
                             /* It is assumed that no event has length over 24 hours. Split up the event if goes over into nex day */
                             $start_hour = date('G', $event['start_ts']);
                             //'G' 24-hour format of an hour without leading zeros
                             $end_hour = date('G', $event['end_ts']);
                             if ($end_hour < $start_hour) {
                                 $event['end_ts1'] = strtotime(substr_replace(date('c', $event['start_ts']), '23:59:59', 11, 8));
                                 $this->events[$cat][$this->group][$date][$_SESSION['user']['account_no']][] = array('start' => $event['start_ts'], 'end' => $event['end_ts1'], 'first_name' => $_SESSION['user']['first_name'], 'last_name' => $_SESSION['user']['last_name']);
                                 if ($length - ($event['end_ts1'] + 1 - $event['start_ts'])) {
                                     $date = date('Y-m-d', $ts + 24 * 3600);
                                     $event['start_ts1'] = $event['end_ts1'] + 1;
                                     $this->events[$cat][$this->group][$date][$_SESSION['user']['account_no']][] = array('start' => $event['start_ts1'], 'end' => $event['end_ts'], 'first_name' => $_SESSION['user']['first_name'], 'last_name' => $_SESSION['user']['last_name']);
                                 }
                             } else {
                                 $this->events[$cat][$this->group][$date][$_SESSION['user']['account_no']][] = array('start' => $event['start_ts'], 'end' => $event['end_ts'], 'first_name' => $_SESSION['user']['first_name'], 'last_name' => $_SESSION['user']['last_name']);
                             }
                             $this->cal['members'][$cat][$this->group]['f.l'][$_SESSION['user']['account_no']] = sprintf('%s.%s', $_SESSION['user']['first_name'], $_SESSION['user']['last_name']);
                             // 'f.l' is the sort order
                             $this->cal['members'][$cat][$this->group]['l.f'][$_SESSION['user']['account_no']] = sprintf('%s.%s', $_SESSION['user']['last_name'], $_SESSION['user']['first_name']);
                             // 'l.f' is the sort order
                             /* add hours worked for the month */
                             $index = date('Y-m-01', $ts);
                             $this->cal['hours_monthly'][$cat][$index] += ($event['end_ts'] - $event['start_ts']) / 3600;
                             /* increment timestamp: shift to next day, because cyclicity is daily, i.e. by day of the week */
                             $ts = $event['start_ts'] + 24 * 3600;
                         } else {
                             $ts += 24 * 3600;
                         }
                     }
                 }
             }
             // next event cycle record
         }
     }
     // merge members for the 'work' and 'offtime' categories bc work and off times are presented in the same calendar
     //var_dump($this->cal['members']['offtime']); exit();
     $this->cal['members']['all'][$this->group]['f.l'] = array_merge($this->cal['members']['work'][$this->group]['f.l'], $this->cal['members']['offtime'][$this->group]['f.l']);
     //var_dump( $this->cal['members']['all'][$this->group]['f.l'] ); exit();
     unset($this->cal['members']['work'][$this->group]['f.l'], $this->cal['members']['offtime'][$this->group]['f.l']);
     array_multisort($this->cal['members']['all'][$this->group]['f.l'], SORT_ASC, SORT_STRING);
     $this->cal['members']['all'][$this->group]['l.f'] = array_merge($this->cal['members']['work'][$this->group]['l.f'], $this->cal['members']['offtime'][$this->group]['l.f']);
     unset($this->cal['members']['work'][$this->group]['l.f'], $this->cal['members']['offtime'][$this->group]['l.f']);
     array_multisort($this->cal['members']['all'][$this->group]['l.f'], SORT_ASC, SORT_STRING);
     //exit();
     $today = date('Y-m-d');
     // get today's date so that it will be highlighted in the calendar
     /* output monthly view calendar with events */
     $output = sprintf('<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><div id="%s" class="bloc">', $this->block_id);
     //get slide number. Weekly view has clickable title for the calendar month
     if (isset($_GET['m'])) {
         $slide = $_GET['m'];
     } else {
         $slide = 3;
     }
     $output .= sprintf('<div id="calendar_holder" slide="%s">', $slide);
     // slide = 3 because we generate calendar scope starting from three months back.
     // start and end date timestamps are already in $this->cal['start_ts'] and $this->cal['end_ts']
     foreach ($this->cal['wks'] as $index => $cal) {
         // $cal is array of j ank i values for the week number (j) and day number placeholder (i) (0...6)
         $index_ts = strtotime($index);
         //$this->cal['hours_monthly'][$index] = 0;
         //var_dump( date( 'c', $index_ts ) ); exit();
         $title = sprintf('%s %s %s %s', date('F', $index_ts), date('Y', $index_ts), $_SESSION['user']['first_name'], $_SESSION['user']['last_name']);
         $output .= sprintf('<div class="calendar"><div class="title">%s</div>', $title);
         $output .= '<table><thead><tr>';
         /* output names of days of the week in header */
         foreach ($this->cal['wkh'] as $v) {
             // remember that $this->cal['wkh'] holds number of the day of the week from the starting number. I.e., if calendar starts with Sunday, then $this->cal['wkh'][0] = 7
             $output .= "<th>{$this->cal['day_names'][$v]}</th>";
         }
         $output .= '</tr></thead><tbody>';
         foreach ($cal as $j => $i) {
             $output .= '<tr>';
             $url = $site_settings['site_settings']['http'] . $_SERVER['SERVER_NAME'] . '/' . VIRT_HOST_PATH . 'index.php';
             //this is needed for links for the weekly view
             foreach ($i as $data) {
                 if ($data) {
                     // check if events exist in the event table for the given calendar cell. $data would contain FALSE if weekday placeholder for this month belongs to another month (1st and last week of the month)
                     $date = date('Y-m-d', $index_ts + ($data['d'] - 1) * 24 * 3600);
                     // figure index for the events array bc $this->events is referenced by [$index]
                     $event_list = '<ul>';
                     foreach ($site_settings['cats'] as $cat) {
                         $duration = array();
                         // keeps track of how many hours everybody is scheduled for that day
                         //$header[$cat] = NULL;
                         if (isset($this->events[$cat][$this->group][$date])) {
                             if ('work' == $cat) {
                                 $li_class = NULL;
                                 $event_list .= sprintf('<li class="%s">Work Time:</li>', $li_class);
                             } else {
                                 $li_class = 'off-list';
                                 $event_list .= sprintf('<li class="%s">Off Time:</li>', $li_class);
                             }
                             $event_start = array();
                             // used for sorting in array_multisort by starting timestamp first
                             $event_li = array();
                             // this contains formatted <li> string for each event author
                             foreach ($this->events[$cat][$this->group][$date] as $account_no => $n) {
                                 // $n is another array with keys as event number (ordinal)
                                 $duration[$account_no] = 0;
                                 foreach ($n as $l) {
                                     // $l contains event details
                                     $duration[$account_no] += ($l['end'] - $l['start']) / 3600;
                                     $event_start[] = $l['start'];
                                     $event_li[] = sprintf('<li class="%s"><span class="%s">%s</span>-<span class="%s">%s</span></li>', $li_class, date('A', $l['start']), date('H:i', $l['start']), date('A', $l['end']), date('H:i', $l['end']));
                                 }
                             }
                             //array_multisort( $event_start, SORT_ASC, SORT_NUMERIC, $event_author, SORT_ASC, SORT_STRING, $event_li );
                             array_multisort($event_start, SORT_ASC, SORT_NUMERIC, $event_li);
                             foreach ($event_start as $k => $v) {
                                 $event_list .= $event_li[$k];
                             }
                         }
                         $sum[$cat] = array_sum($duration);
                     }
                     $event_list .= '</ul>';
                     // mark today's date on calendar
                     $class = NULL;
                     $holiday = NULL;
                     if (isset($data['h'])) {
                         $holiday = $data['h'];
                         $class = 'class="holiday"';
                     }
                     if ($date == $today) {
                         $class = 'class="today"';
                     }
                     /* print calendar cell */
                     $output .= sprintf('<td %s><div class="day">%s</div><div class="circle">%s</div><div class="holiday_name">%s</div>%s</td>', $class, $data['d'], round($sum['work'], 1), $holiday, $event_list);
                 } else {
                     $output .= '<td colspan="1" class="padding"></td>';
                 }
             }
             $output .= '</tr>';
         }
         // end foreach ( $cal as $j => $i )
         /* fill in additional rows in calendar to add up to 5 rows total */
         $output .= '</tbody></table></div>';
         //var_dump( $this->cal['hours_monthly'] ); exit();
     }
     $output .= '</div><!--end calendar holder-->';
     $output .= '<div class="calendar_nav"><a id="prev" href="#" class="prev"></a><a id="next" href="#" class="next"></a></div></div><!--End class="block"--></div><!--End sizing div-->';
     $this->events = array();
     // clean the events array for the next rendering
     return $output;
 }