function display_week() { global $vars; $heading_html = tag('tr'); $heading_html->add(tag('th', __p('Week', 'W'))); for ($i = 0; $i < 7; $i++) { $d = ($i + day_of_week_start()) % 7; $heading_html->add(tag('th', day_name($d))); } if (!isset($vars['week']) || !isset($vars['year'])) { soft_error(__('Invalid date.')); } $week_of_year = intval($vars['week']); $year = intval($vars['year']); $day_of_year = 1 + ($week_of_year - 1) * 7 - day_of_week(1, 1, $year); $from_stamp = mktime(0, 0, 0, 1, $day_of_year, $year); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp); $last_day = $day_of_year + 6; $to_stamp = mktime(23, 59, 59, 1, $last_day, $year); $end_month = date("n", $to_stamp); $end_year = date("Y", $to_stamp); $heading = month_name($start_month) . " {$start_year}"; if ($end_month != $start_month) { $heading .= " - " . month_name($end_month) . " {$end_year}"; } return tag('', tag("div", attributes('id="phpc-summary-view"'), tag("div", attributes('id="phpc-summary-head"'), tag("div", attributes('id="phpc-summary-title"'), ''), tag("div", attributes('id="phpc-summary-author"'), ''), tag("div", attributes('id="phpc-summary-category"'), ''), tag("div", attributes('id="phpc-summary-time"'), '')), tag("div", attributes('id="phpc-summary-body"'), '')), tag('table', attributes('class="phpc-main phpc-calendar"'), tag('caption', $heading), tag('colgroup', tag('col', attributes('class="phpc-week"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"')), tag('col', attributes('class="phpc-day"'))), tag('thead', $heading_html), create_week($week_of_year, $from_stamp, $to_stamp, $year))); }
function create_month($month, $year) { global $phpcdb, $phpc_cal, $phpcid; $weeks = weeks_in_month($month, $year); $first_day = 1 - day_of_week($month, 1, $year); $from_stamp = mktime(0, 0, 0, $month, $first_day, $year); $last_day = $weeks * 7 - day_of_week($month, 1, $year); $to_stamp = mktime(23, 59, 59, $month, $last_day, $year); $days_events = get_events($from_stamp, $to_stamp); $week_list = array(); for ($week_of_month = 1; $week_of_month <= $weeks; $week_of_month++) { // We could be showing a week from the previous or next year $days = ($week_of_month - 1) * 7; $start_stamp = strtotime("+{$days} day", $from_stamp); $week_list[] = create_week($start_stamp, $year, $days_events); } return $week_list; }
function display_week() { global $vars, $phpc_home_url, $phpcid, $phpc_year, $phpc_month, $phpc_day; if (!isset($vars['week'])) { $week_of_year = week_of_year($phpc_month, $phpc_day, $phpc_year); } else { if (!is_numeric($vars['week'])) { soft_error(__('Invalid date.')); } $week_of_year = $vars['week']; } $day_of_year = 1 + ($week_of_year - 1) * 7 - day_of_week(1, 1, $phpc_year); $from_stamp = mktime(0, 0, 0, 1, $day_of_year, $phpc_year); $start_day = date("j", $from_stamp); $start_month = date("n", $from_stamp); $start_year = date("Y", $from_stamp); $last_day = $day_of_year + 6; $to_stamp = mktime(23, 59, 59, 1, $last_day, $phpc_year); $end_day = date("j", $to_stamp); $end_month = date("n", $to_stamp); $end_year = date("Y", $to_stamp); $title = month_name($start_month) . " {$start_year}"; if ($end_month != $start_month) { $title .= " - " . month_name($end_month) . " {$end_year}"; } $prev_week = $week_of_year - 1; $prev_year = $phpc_year; if ($prev_week < 1) { $prev_year--; $prev_week = week_of_year($start_month, $start_day - 7, $start_year); } $next_week = $week_of_year + 1; $next_year = $phpc_year; if ($next_week > weeks_in_year($phpc_year)) { $next_week = week_of_year($end_month, $end_day + 1, $end_year); $next_year++; } $heading = tag('', tag('a', attrs('class="phpc-icon-link"', "href=\"{$phpc_home_url}?action=display_week&phpcid={$phpcid}&week={$prev_week}&year={$prev_year}\""), tag('span', attrs('class="fa fa-chevron-left"'), '')), $title, tag('a', attrs('class="phpc-icon-link"', "href=\"{$phpc_home_url}?action=display_week&phpcid={$phpcid}&week={$next_week}&year={$next_year}\""), tag('span', attrs('class="fa fa-chevron-right"'), ''))); return create_display_table($heading, create_week($from_stamp, $phpc_year, get_events($from_stamp, $to_stamp))); }
function format_todos() { $todos = array(); foreach ($this->todos as $i => $t) { $todo_time = substr($t['deadline'], 11); $todo_dow = day_of_week($t['deadline']); $i = 0; while (isset($this->timetable[$i]) && $this->timetable[$i]['time'] <= $todo_time) { $i++; } $time = $this->timetable[$i - 1]['time']; if (!isset($todos[$time][$todo_dow])) { $todos[$time][$todo_dow] = array(); } $todos[$time][$todo_dow][] = $t; } return $todos; }
function week_of_year($month, $day, $year) { $timestamp = mktime(0, 0, 0, $month, $day, $year); // week_start = 1 uses ISO 8601 and contains the Jan 4th, // Most other places the first week contains Jan 1st // There are a few outliers that start weeks on Monday and use // Jan 1st for the first week. We'll ignore them for now. if (day_of_week_start() == 1) { $year_contains = 4; // if the week is in December and contains Jan 4th, it's a week // from next year if ($month == 12 && $day - 24 >= $year_contains) { $year++; $month = 1; $day -= 31; } } else { $year_contains = 1; } // $day is the first day of the week relative to the current month, // so it can be negative. If it's in the previous year, we want to use // that negative value, unless the week is also in the previous year, // then we want to switch to using that year. if ($day < 1 && $month == 1 && $day > $year_contains - 7) { $day_of_year = $day - 1; } else { $day_of_year = date('z', $timestamp); $year = date('Y', $timestamp); } /* Days in the week before Jan 1. */ $days_before_year = day_of_week(1, $year_contains, $year); // Days left in the week $days_left = 8 - day_of_week_ts($timestamp) - $year_contains; /* find the number of weeks by adding the days in the week before * the start of the year, days up to $day, and the days left in * this week, then divide by 7 */ return ($days_before_year + $day_of_year + $days_left) / 7; }
function load_nameids() { $day = day_of_week($this->date); global $db; $select_old = "person.id as person_id, person.nk as nameid, timetable.name as lesson_name, stunde.id as lesson_id FROM\r\n person, pg,gruppe, stunde,timetable WHERE\r\n person.nk is not null AND\r\n person.id=pg.pid AND\r\n pg.gid=gruppe.id AND\r\n gruppe.id=stunde.gid AND\r\n stunde.zeit=timetable.time AND\r\n stunde.tag='" . $day . "'"; $select = "person.id as person_id, person.nid as nameid, timetable.name as lesson_name, lesson.id as lesson_id FROM\r\n person, pg,gruppe, lesson,timetable WHERE\r\n person.nid is not null AND\r\n person.id=pg.pid AND\r\n pg.gid=gruppe.id AND\r\n gruppe.id=lesson.gid AND\r\n lesson.time=timetable.time AND\r\n lesson.day='" . $day . "'"; $db->select($select); $nameids = $lessons = array(); foreach ($db->data as $i => $entry) { $nid = $entry['nameid']; $lesson = $entry['lesson_name']; $nameids[$nid] = $entry['person_id']; $lessons[$nid][$lesson] = $entry; } $this->nameids = $nameids; $this->lessons = $lessons; }
private function calc_salary_per_hour() { //เดือนที่ทำการคำนวณมีกี่วัน $number_days = days_in_month($this->month, $this->year); $this->load->model('Shiftwork_model'); $query = $this->Shiftwork_model->getDetailByUserId($this->user_id); $query = $query->result_array(); $total_hour = 0; for ($i = 1; $i <= $number_days; $i++) { $day = day_of_week($this->year . "-" . $this->month . "-" . $i); foreach ($query as $row) { if (intval($row['swdday']) == $day && intval($row['swdiswork']) == 1) { $total_hour = $total_hour + intval($row['swdtotaltime']); break; } } } if ($total_hour == 0) { $total_hour = 168; } $this->my_salary_per_hour = round($this->my_salary / $total_hour); }
function create_week($week_of_month, $month, $year, $days_events) { $start_day = 1 + ($week_of_month - 1) * 7 - day_of_week($month, 1, $year); $week_of_year = week_of_year($month, $start_day, $year); $args = array('week' => $week_of_year, 'year' => $year); $click = create_plain_link($week_of_year, 'display_week', false, false, false, false, $args); $week_html = tag('tr', tag('th', attrs('class="ui-state-default"', "onclick=\"window.location.href='{$click}'\""), create_action_link($week_of_year, 'display_week', $args))); for ($day_of_week = 0; $day_of_week < 7; $day_of_week++) { $day = $start_day + $day_of_week; $week_html->add(create_day($month, $day, $year, $days_events)); } return $week_html; }
function reader_phone_shortcode($atts) { $a = shortcode_atts(array('reader' => ''), $atts); $reader = $a['reader']; $reader_keys = get_reader_keys(); $output = ''; if (in_array($reader, $reader_keys)) { $phone_numbers = get_phone_numbers(); $today = strtolower(day_of_week()); $now = strtotime(now()); $in = strtotime(reader_in($reader, $today)); $out = strtotime(reader_out($reader, $today)); manage_buttons($reader); $available = '<h2 style="text-align: center; color: #17de9b; font-weight: bold;">' . $phone_numbers[$reader] . '</h2>'; $not_available = '<div class="margin-top-0 ' . $reader . '-not-available ' . '"><a class=" ' . '" href="#">Not Available</a></div>'; $busy = '<div class="' . $reader . '-busy>' . '<a class="white ' . '" href="#">Busy with Client</a></div>'; if ($in <= $now && $now <= $out) { if (is_reader_busy($reader) == '0') { // Reader Available $output = $available; } else { // Reader Busy $output = $busy; } } else { // Reader Not Available $output = $not_available; } } return $output; }
function firstday_prevweek($day, $month, $year) { $w = day_of_week($day, $month, $year); $add = $w == 0 ? 13 : 6 + $w; $d = date('d/m/Y', strtotime("-{$add} day", mktime(7, 30, 0, $month, $day, $year))); list($a, $b, $c) = explode("/", $d); return array(day => $a, month => $b, year => $c); }