function taskstyle_pd($task)
{
    $now = new CDate();
    $start_date = intval($task["task_start_date"]) ? new CDate($task["task_start_date"]) : null;
    $end_date = intval($task["task_end_date"]) ? new CDate($task["task_end_date"]) : null;
    if ($start_date && !$end_date) {
        $end_date = $start_date;
        $end_date->addSeconds(@$task["task_duration"] * $task["task_duration_type"] * SEC_HOUR);
    } else {
        if (!$start_date) {
            return '';
        }
    }
    $style = 'class=';
    if ($task['task_percent_complete'] == 0) {
        $style .= $now->before($start_date) ? '"task_future"' : '"task_notstarted"';
    } else {
        if ($task['task_percent_complete'] == 100) {
            $t = new CTask();
            $t->load($task['task_id']);
            $actual_end_date = new CDate(get_actual_end_date_pd($t->task_id, $t));
            $style .= $actual_end_date->after($end_date) ? '"task_late"' : '"task_done"';
        } else {
            $style .= $now->after($end_date) ? '"task_overdue"' : '"task_started"';
        }
    }
    return $style;
}
Ejemplo n.º 2
0
    $p_end_date = $project->project_end_date;
}
foreach ($proTasks as $row) {
    //Check if start date exists, if not try giving it the end date.
    //If the end date does not exist then set it for today.
    //This avoids jpgraphs internal errors that render the gantt completely useless
    if ($row['task_start_date'] == '0000-00-00 00:00:00') {
        if ($row['task_end_date'] == '0000-00-00 00:00:00') {
            $todaydate = new CDate();
            $row['task_start_date'] = $todaydate->format(FMT_TIMESTAMP_DATE);
        } else {
            $row['task_start_date'] = $row['task_end_date'];
        }
    }
    $tsd = new CDate($row['task_start_date']);
    if ($tsd->before(new CDate($start_min))) {
        $start_min = $row['task_start_date'];
    }
    //Check if end date exists, if not try giving it the start date.
    //If the start date does not exist then set it for today.
    //This avoids jpgraphs internal errors that render the gantt completely useless
    if ($row['task_end_date'] == '0000-00-00 00:00:00') {
        if ($row['task_duration']) {
            $row['task_end_date'] = db_unix2dateTime(db_dateTime2unix($row['task_start_date']) + SECONDS_PER_DAY * convert2days($row['task_duration'], $row['task_duration_type']));
        } else {
            $todaydate = new CDate();
            $row['task_end_date'] = $todaydate->format(FMT_TIMESTAMP_DATE);
        }
    }
    $ted = new CDate($row['task_end_date']);
    if ($ted->after(new CDate($end_max))) {
Ejemplo n.º 3
0
/**
* Sub-function to collect tasks within a period
*
* @param Date the starting date of the period
* @param Date the ending date of the period
* @param array by-ref an array of links to append new items to
* @param int the length to truncate entries by
* @param int the company id to filter by
* @author Andrew Eddie <*****@*****.**>
*/
function getTaskLinks($startPeriod, $endPeriod, &$links, $strMaxLen, $company_id = 0)
{
    global $a, $AppUI, $dPconfig;
    $tasks = CTask::getTasksForPeriod($startPeriod, $endPeriod, $company_id, $AppUI->user_id, true);
    $durnTypes = dPgetSysVal('TaskDurationType');
    $link = array();
    $sid = 3600 * 24;
    // assemble the links for the tasks
    foreach ($tasks as $row) {
        // the link
        $link['href'] = "?m=tasks&a=view&task_id=" . $row['task_id'];
        $link['alt'] = $row['project_name'] . ":\n" . $row['task_name'];
        // the link text
        if (strlen($row['task_name']) > $strMaxLen) {
            $row['task_name'] = substr($row['task_name'], 0, $strMaxLen) . '...';
        }
        $link['text'] = '<span style="color:' . bestColor($row['color']) . ';background-color:#' . $row['color'] . '">' . $row['task_name'] . '</span>';
        // determine which day(s) to display the task
        $start = new CDate($row['task_start_date']);
        $end = $row['task_end_date'] ? new CDate($row['task_end_date']) : null;
        $durn = $row['task_duration'];
        $durnType = $row['task_duration_type'];
        if (($start->after($startPeriod) || $start->equals($startPeriod)) && ($start->before($endPeriod) || $start->equals($endPeriod))) {
            $temp = $link;
            $temp['alt'] = "START [" . $row['task_duration'] . ' ' . $AppUI->_($durnTypes[$row['task_duration_type']]) . "]\n" . $link['alt'];
            if ($a != 'day_view') {
                $temp['text'] = dPshowImage(dPfindImage('block-start-16.png')) . $temp['text'];
            }
            $links[$start->format(FMT_TIMESTAMP_DATE)][] = $temp;
        }
        if ($end && $end->after($startPeriod) && $end->before($endPeriod) && $start->before($end)) {
            $temp = $link;
            $temp['alt'] = "FINISH\n" . $link['alt'];
            if ($a != 'day_view') {
                $temp['text'] .= dPshowImage(dPfindImage('block-end-16.png'));
            }
            $links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
        }
        // convert duration to days
        if ($durnType < 24.0) {
            if ($durn > $dPconfig['daily_working_hours']) {
                $durn /= $dPconfig['daily_working_hours'];
            } else {
                $durn = 0.0;
            }
        } else {
            $durn *= $durnType / 24.0;
        }
        // fill in between start and finish based on duration
        // notes:
        // start date is not in a future month, must be this or past month
        // start date is counted as one days work
        // business days are not taken into account
        $target = $start;
        $target->addSeconds($durn * $sid);
        if (Date::compare($target, $startPeriod) < 0) {
            continue;
        }
        if (Date::compare($start, $startPeriod) > 0) {
            $temp = $start;
            $temp->addSeconds($sid);
        } else {
            $temp = $startPeriod;
        }
        // Optimised for speed, AJD.
        while (Date::compare($endPeriod, $temp) > 0 && Date::compare($target, $temp) > 0 && ($end == null || $temp->before($end))) {
            $links[$temp->format(FMT_TIMESTAMP_DATE)][] = $link;
            $temp->addSeconds($sid);
        }
    }
}
Ejemplo n.º 4
0
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 .= '&nbsp;</td>';
        $sd->addSeconds(7 * 24 * 3600);
        //add one week
    }
    return $row;
}
Ejemplo n.º 5
0
if ($start === null) {
    $start = 8;
}
if ($end === null) {
    $end = 17;
}
if ($inc === null) {
    $inc = 15;
}
//display adjusted events
$this_day->setTime($start, 0, 0);
$events2 = array();
foreach ($events as $row) {
    $start_date = new CDate($row['event_start_date']);
    $end_date = new CDate($row['event_end_date']);
    if ($start_date->before($this_day)) {
        $events2[$this_day->format('%H%M%S')][] = $row;
    } else {
        $events2[$start_date->format('%H%M%S')][] = $row;
    }
}
// calculate colums per each time row
$this_day->setTime($start, 0, 0);
$disp_columns = array();
for ($i = 0, $n = ($end - $start) * 60 / $inc; $i < $n; $i++) {
    $disp_columns[$i] = 0;
}
for ($i = 0, $n = ($end - $start) * 60 / $inc; $i < $n; $i++) {
    $timeStamp = $this_day->format('%H%M%S');
    if (@$events2[$timeStamp]) {
        $count = count($events2[$timeStamp]);
Ejemplo n.º 6
0
 /**
 * Calculating if an recurrent date is in the given period
 * @param Date Start date of the period
 * @param Date End date of the period
 * @param Date Start date of the Date Object
 * @param Date End date of the Date Object
 * @param integer Type of Recurrence
 * @param integer Times of Recurrence
 * @param integer Time of Recurrence
 * @return array Calculated Start and End Dates for the recurrent Event for the given Period
 */
 function getRecurrentEventforPeriod($start_date, $end_date, $event_start_date, $event_end_date, $event_recurs, $event_times_recuring, $j)
 {
     //this array will be returned
     $transferredEvent = array();
     //create Date Objects for Event Start and Event End
     $eventStart = new CDate($event_start_date);
     $eventEnd = new CDate($event_end_date);
     //Time of Recurence = 0 (first occurence of event) has to be checked, too.
     if ($j > 0) {
         switch ($event_recurs) {
             case 1:
                 $eventStart->addSpan(new Date_Span(3600 * $j));
                 $eventEnd->addSpan(new Date_Span(3600 * $j));
                 break;
             case 2:
                 $eventStart->addDays($j);
                 $eventEnd->addDays($j);
                 break;
             case 3:
                 $eventStart->addDays(7 * $j);
                 $eventEnd->addDays(7 * $j);
                 break;
             case 4:
                 $eventStart->addDays(14 * $j);
                 $eventEnd->addDays(14 * $j);
                 break;
             case 5:
                 $eventStart->addMonths($j);
                 $eventEnd->addMonths($j);
                 break;
             case 6:
                 $eventStart->addMonths(3 * $j);
                 $eventEnd->addMonths(3 * $j);
                 break;
             case 7:
                 $eventStart->addMonths(6 * $j);
                 $eventEnd->addMonths(6 * $j);
                 break;
             case 8:
                 $eventStart->addMonths(12 * $j);
                 $eventEnd->addMonths(12 * $j);
                 break;
             default:
                 break;
         }
     }
     if ($eventStart->before($end_date) && $eventEnd->after($start_date)) {
         // add temporarily moved Event Start and End dates to returnArray
         $transferredEvent = array($eventStart, $eventEnd);
     }
     // return array with event start and end dates for given period (positive case)
     // or an empty array (negative case)
     return $transferredEvent;
 }
Ejemplo n.º 7
0
/**
 * Sub-function to collect tasks within a period
 *
 * @param Date the starting date of the period
 * @param Date the ending date of the period
 * @param array by-ref an array of links to append new items to
 * @param int the length to truncate entries by
 * @param int the company id to filter by
 * @author Andrew Eddie <*****@*****.**>
 */
function getTaskLinks($startPeriod, $endPeriod, &$links, $strMaxLen, $company_id = 0, $minical = false)
{
    global $a, $AppUI, $w2Pconfig;
    $tasks = CTask::getTasksForPeriod($startPeriod, $endPeriod, $company_id, 0);
    $df = $AppUI->getPref('SHDATEFORMAT');
    $tf = $AppUI->getPref('TIMEFORMAT');
    //subtract one second so we don't have to compare the start dates for exact matches with the startPeriod which is 00:00 of a given day.
    $startPeriod->subtractSeconds(1);
    $link = array();
    $sid = 3600 * 24;
    // assemble the links for the tasks
    foreach ($tasks as $row) {
        // the link
        $link['task'] = true;
        if (!$minical) {
            $link['href'] = '?m=tasks&a=view&task_id=' . $row['task_id'];
            // the link text
            if (mb_strlen($row['task_name']) > $strMaxLen) {
                $row['short_name'] = mb_substr($row['task_name'], 0, $strMaxLen) . '...';
            } else {
                $row['short_name'] = $row['task_name'];
            }
            $link['text'] = '<span style="color:' . bestColor($row['color']) . ';background-color:#' . $row['color'] . '">' . $row['short_name'] . ($row['task_milestone'] ? '&nbsp;' . w2PshowImage('icons/milestone.gif') : '') . '</span>';
        }
        // determine which day(s) to display the task
        $start = new CDate($row['task_start_date']);
        $end = $row['task_end_date'] ? new CDate($row['task_end_date']) : null;
        // First we test if the Tasks Starts and Ends are on the same day, if so we don't need to go any further.
        if ($start->after($startPeriod) && ($end && $end->after($startPeriod) && $end->before($endPeriod) && !$start->dateDiff($end))) {
            if ($minical) {
                $temp = array('task' => true);
            } else {
                $temp = $link;
                if ($a != 'day_view') {
                    $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], true, true, $tasks), true) . w2PshowImage('block-start-16.png') . $start->format($tf) . ' ' . $temp['text'] . ' ' . $end->format($tf) . w2PshowImage('block-end-16.png') . w2PendTip();
                }
            }
            $links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
        } else {
            // If they aren't, we will now need to see if the Tasks Start date is between the requested period
            if ($start->after($startPeriod) && $start->before($endPeriod)) {
                if ($minical) {
                    $temp = array('task' => true);
                } else {
                    $temp = $link;
                    if ($a != 'day_view') {
                        $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], true, false, $tasks), true) . w2PshowImage('block-start-16.png') . $start->format($tf) . ' ' . $temp['text'] . w2PendTip();
                    }
                }
                $links[$start->format(FMT_TIMESTAMP_DATE)][] = $temp;
            }
            // And now the Tasks End date is checked if it is between the requested period too.
            if ($end && $end->after($startPeriod) && $end->before($endPeriod) && $start->before($end)) {
                if ($minical) {
                    $temp = array('task' => true);
                } else {
                    $temp = $link;
                    if ($a != 'day_view') {
                        $temp['text'] = w2PtoolTip($row['task_name'], getTaskTooltip($row['task_id'], false, true, $tasks), true) . ' ' . $temp['text'] . ' ' . $end->format($tf) . w2PshowImage('block-end-16.png') . w2PendTip();
                    }
                }
                $links[$end->format(FMT_TIMESTAMP_DATE)][] = $temp;
            }
        }
    }
}