function displayWeeks($list, $task, $level, $fromPeriod, $toPeriod) { //start of week $sd = new CDate($fromPeriod); $days_from_start = $sd->getDayOfWeek(); for ($i = 0; $i < $days_from_start; $i++) { $stmp = $sd->getPrevDay(); $sd = new CDate($stmp->format('%Y-%m-%d 00:00:00')); } //end of week $ed = new CDate($toPeriod); $days_spent = $ed->getDayOfWeek(); for ($i = 6 - $days_spent; $i > 0; $i--) { $etmp = $ed->getNextDay(); $ed = new CDate($etmp->format('%Y-%m-%d 23:59:59')); } $st = new CDate($task->task_start_date); $et = new CDate($task->task_end_date); $row = ''; while ($sd->before($ed)) { $sd_end = new CDate($sd->format('%Y-%m-%d 00:00:00')); $sd_end->addSeconds(7 * 24 * 3600); //add one week if ($sd->after($st) && $sd_end->before($et) || $st->before($sd_end) && !$st->before($sd) || $et->after($sd) && !$et->after($sd_end)) { /* * generate visually distiguishable colors for up to 12 task levels * Color will just be blue (#0000FF) for levels 12th and up. */ $red_key = 12 - floor($level / 3) * 3; $red_key = $red_key > 15 ? 15 : ($red_key < 0 ? 0 : $red_key); $green_key_1 = $red_key + 4 - $level % 3 * 4; $green_key_1 = $green_key_1 > 15 ? 15 : ($green_key_1 < 0 ? 0 : $green_key_1); $green_key_2 = $green_key_1 == $red_key ? 0 : $green_key_1; $color_hex = mb_strtoupper('#' . dechex($red_key) . '0' . dechex($green_key_1) . dechex($green_key_2) . 'FF'); $row .= '<td nowrap="nowrap" style="background:' . $color_hex . ';" >'; } else { $row .= '<td nowrap="nowrap">'; } $row .= ' </td>'; $sd->addSeconds(7 * 24 * 3600); //add one week } return $row; }
$rowspan_count = 0; $total_hours_daily = 0; $total_hours_weekly = 0; $dow = 0; $last_day = new CDate(); $last_day->copy($start_day); $no_results = true; $first = 1; for ($dow = 0; $dow < 7; $dow++) { $dmsg = $last_day->getDayName(false) . ' ' . $last_day->format($df); writeDayLine($last_day, $df, $AppUI->_('Add Task Log'), $is_my_timesheet, $user_id); $ntasks = 0; $pname = ''; foreach ($result as $task) { $task_date = new CDate($task['task_log_date']); $task_dow = $task_date->getDayOfWeek(); if ($task_dow == $dow) { $ntasks++; $total_hours_daily += $task['task_log_hours']; if ($pname != $task['project_name']) { $pname = $task['project_name']; echo '<tr class="second" onclick="viewProject(' . $task['project_id'] . ')">' . '<td colspan="100%" style="padding-left: 24px"><b>' . $pname . '</b></td></tr>'; } ?> <tr class="second"> <td nowrap="nowrap" style="padding-left: 24px" valign="top"> <?php if ($task['task_log_creator'] == $AppUI->user_id || $can_edit_other_timesheets) { ?> <img class="clickable" src="images/edit_log.gif" title="Edit" onclick="editLog(<?php
$df = $AppUI->getPref('SHDATEFORMAT'); //How many weeks are we going to show? $week_count = 4; if (isset($_GET['start_date'])) { $AppUI->setState('TimecardWeeklyReportStartDate', $_GET['start_date']); } $start_day = new CDate($AppUI->getState('TimecardWeeklyReportStartDate') ? $AppUI->getState('TimecardWeeklyReportStartDate') : NULL); if (isset($_GET['company_id'])) { $AppUI->setState('TimecardWeeklyReportCompanyId', $_GET['company_id']); } $company_id = $AppUI->getState('TimecardWeeklyReportCompanyId') ? $AppUI->getState('TimecardWeeklyReportCompanyId') : 0; //print $company_id; //set that to just midnight so as to grab the whole day $date = $start_day->format("%Y-%m-%d") . " 00:00:00"; $start_day->setDate($date, DATE_FORMAT_ISO); $today_weekday = $start_day->getDayOfWeek(); //roll back to the first day of that week, regardless of what day was specified $rollover_day = '0'; $new_start_offset = $rollover_day - $today_weekday; $start_day->addDays($new_start_offset); //last day of that week, add 6 days $end_day = new CDate(); $end_day->copy($start_day); $end_day->addDays(6); //set that to just before midnight so as to grab the whole day $date = $end_day->format("%Y-%m-%d") . " 23:59:59"; $end_day->setDate($date, DATE_FORMAT_ISO); $selects = array(); $join = array(); $where = getPermsWhereClause("companies", "user_company"); $sql = "\n\t\tSELECT \n\t\t\tuser_id,\n\t\t\tconcat(contact_last_name,' ',contact_first_name) as name,\n\t\t\tcontact_email,\n\t\t\tcompany_name\n\t\tFROM \n\t\t\tusers\n\t\t\tLEFT JOIN contacts ON users.user_contact=contacts.contact_id\n\t\t\tLEFT JOIN companies ON companies.company_id=contacts.contact_company\n\t\tWHERE \n\t\t" . $where . "\n\t";
public function calcFinish($durn, $durnType) { // since one will alter the date ($this) one better copies it to a new instance $f = new CDate(); $f->copy($this); // get w2P time constants $cal_day_start = intval(w2PgetConfig('cal_day_start')); $cal_day_end = intval(w2PgetConfig('cal_day_end')); $workHours = intval(w2PgetConfig('daily_working_hours')); $workingDays = w2PgetConfig('cal_working_days'); $working_days = explode(',', $workingDays); //temporary variables $inc = floor($durn); $hoursToAddToLastDay = 0; $hoursToAddToFirstDay = $durn; $fullWorkingDays = 0; $int_st_hour = $f->getHour(); //catch the gap between the working hours and the open hours (like lunch periods) $workGap = $cal_day_end - $cal_day_start - $workHours; // calculate the number of non-working days $k = 7 - count($working_days); $durnMins = ($durn - $inc) * 60; if ($f->getMinute() + $durnMins >= 60) { $inc++; } $mins = ($f->getMinute() + $durnMins) % 60; if ($mins > 38) { $f->setMinute(45); } elseif ($mins > 23) { $f->setMinute(30); } elseif ($mins > 8) { $f->setMinute(15); } else { $f->setMinute(0); } // jump over to the first working day for ($i = 0; $i < $k; $i++) { if (array_search($f->getDayOfWeek(), $working_days) === false) { $f->addDays(1); } } if ($durnType == 24) { if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) { $fullWorkingDays = ceil($inc); $f->setMinute(0); } else { $fullWorkingDays = ceil($inc) + 1; } // Include start day as a working day (if it is one) if (!(array_search($f->getDayOfWeek(), $working_days) === false)) { $fullWorkingDays--; } for ($i = 0; $i < $fullWorkingDays; $i++) { $f->addDays(1); if (array_search($f->getDayOfWeek(), $working_days) === false) { $i--; } } if ($f->getHour() == $cal_day_start && $f->getMinute() == 0) { $f->setHour($cal_day_end); $f->setMinute(0); } } else { $hoursToAddToFirstDay = $inc; if ($f->getHour() + $inc > $cal_day_end - $workGap) { $hoursToAddToFirstDay = $cal_day_end - $workGap - $f->getHour(); } if ($hoursToAddToFirstDay > $workHours) { $hoursToAddToFirstDay = $workHours; } $inc -= $hoursToAddToFirstDay; $hoursToAddToLastDay = $inc % $workHours; $fullWorkingDays = floor(($inc - $hoursToAddToLastDay) / $workHours); if ($hoursToAddToLastDay <= 0 && !($hoursToAddToFirstDay == $workHours)) { $f->setHour($f->getHour() + $hoursToAddToFirstDay); } elseif ($hoursToAddToLastDay == 0) { $f->setHour($f->getHour() + $hoursToAddToFirstDay + $workGap); } else { $f->setHour($cal_day_start + $hoursToAddToLastDay); $f->addDays(1); } if (($f->getHour() == $cal_day_end || $f->getHour() - $int_st_hour == $workHours + $workGap) && $mins > 0) { $f->addDays(1); $f->setHour($cal_day_start); } // boolean for setting later if we just found a non-working day // and therefore do not have to add a day in the next loop // (which would have caused to not respecting multiple non-working days after each other) $g = false; for ($i = 0, $i_cmp = ceil($fullWorkingDays); $i < $i_cmp; $i++) { if (!$g) { $f->addHours(1); } $g = false; // calculate overriden non-working days if (array_search($f->getDayOfWeek(), $working_days) === false) { $f->addDays(1); $i--; $g = true; } } } // if there was no fullworkingday we have to check whether the end day is a working day // and in the negative case postpone the end date by appropriate days for ($i = 0, $i_cmp = 7 - count($working_days); $i < $i_cmp; $i++) { // override possible non-working enddays if (array_search($f->getDayOfWeek(), $working_days) === false) { $f->addDays(1); } } return $f; }