Ejemplo n.º 1
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 ($start_date->compare($start_date, $eventStart) <= 0 && $end_date->compare($end_date, $eventEnd) >= 0) {
         // 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.º 2
0
     foreach ($res as $rw) {
         switch ($rw['perc_assignment']) {
             case 100:
                 $caption = $caption . '' . $rw['contact_first_name'] . ' ' . $rw['contact_last_name'] . ';';
                 break;
             default:
                 $caption = $caption . '' . $rw['contact_first_name'] . ' ' . $rw['contact_last_name'] . ' [' . $rw['perc_assignment'] . '%];';
                 break;
         }
     }
     $q->clear();
     $caption = mb_substr($caption, 0, mb_strlen($caption) - 1);
 }
 if ($flags == 'm') {
     $start = new CDate($start);
     $start->addDays(0);
     $s = $start->format($df);
     if ($caller == 'todo') {
         $bar = new MileStone($row++, array($name, $pname, '', $s, $s), $a['task_start_date'], $s);
     } else {
         $bar = new MileStone($row++, array($name, '', $s, $s), $a['task_start_date'], $s);
     }
     $bar->title->SetFont(FF_CUSTOM, FS_NORMAL, 8);
     //caption of milestone should be date
     if ($showLabels == '1') {
         $caption = $start->format($df);
     }
     $bar->title->SetColor('#CC0000');
     $graph->Add($bar);
 } else {
     $type = $a['task_duration_type'];
Ejemplo n.º 3
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool
  **/
 function importTasks($from_project_id, $scale_project = false)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     //Pristine Start and End Dates of Source and Destination Projects
     $origStartDate = new CDate($origProject->project_start_date);
     $origEndDate = new CDate($origProject->project_end_date);
     $destStartDate = new CDate($this->project_start_date);
     $destEndDate = new CDate($this->project_end_date);
     $dateOffset = $destStartDate->dateDiff($origStartDate);
     //Check that we have enough information to scale properly
     //(i.e. no information is missing or "zero")
     if (empty($origProject->project_start_date) || empty($origProject->project_end_date) || empty($this->project_start_date) || empty($this->project_end_date) || $origProject->project_start_date == '0000-00-00 00:00:00' || $origProject->project_end_date == '0000-00-00 00:00:00' || $this->project_start_date == '0000-00-00 00:00:00' || $this->project_end_date == '0000-00-00 00:00:00') {
         $scale_project = false;
     }
     if ($scale_project) {
         //get ratio for scaling, protect from division by 0
         $ratio = (abs($destEndDate->dateDiff($destStartDate)) + 1) / (abs($origEndDate->dateDiff($origStartDate)) + 1);
     }
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     $origDate = new CDate($origProject->project_start_date);
     $origStartHour = new CDate($this->project_start_date);
     $destDate = new CDate($this->project_start_date);
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             $task_date_vars = array('task_start_date', 'task_end_date');
             //Adjust task dates based on calculated offsets
             foreach ($task_date_vars as $my_date) {
                 if (!empty($newTask->{$my_date}) && $newTask->{$my_date} != '0000-00-00 00:00:00') {
                     $origDate->setDate($newTask->{$my_date});
                     $origStartHour->setDate($newTask->{$my_date});
                     $origStartHour->setTime(intval(dPgetConfig('cal_day_start')));
                     $destDate->setDate($newTask->{$my_date});
                     $destDate->addDays($dateOffset);
                     if ($scale_project) {
                         $offsetAdd = round($origDate->dateDiff($origStartDate) * $ratio) - $origDate->dateDiff($origStartDate);
                         $destDate->addDays($offsetAdd);
                         $hours_in = $origStartHour->calcDuration($origDate);
                         $offsetAddHours = round($hours_in * $ratio) - $hours_in;
                         if ($offsetAddHours % dPgetConfig('daily_working_hours')) {
                             $destDate->addDuration($offsetAddHours);
                         }
                     }
                     $destDate = $destDate->next_working_day();
                     $newTask->{$my_date} = $destDate->format(FMT_DATETIME_MYSQL);
                 }
             }
             //Adjust durration to scale
             if ($scale_project) {
                 $newTask->task_duration = round($newTask->task_duration * $ratio, 2);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }
Ejemplo n.º 4
0
 if ($key) {
     $upd_task->load($key);
 }
 //Action: Modify Percent Complete
 if (isset($_POST['bulk_task_percent_complete']) && $bulk_task_percent_complete != '' && $bulk_task_percent_complete) {
     if ($upd_task->task_id) {
         $upd_task->task_percent_complete = $bulk_task_percent_complete;
         $upd_task->store();
     }
 }
 //Action: Move Task Date
 if (isset($_POST['bulk_move_date']) && $bulk_move_date != '' && $bulk_move_date) {
     if ($upd_task->task_id && (intval($upd_task->task_dynamic) != 1 && !$upd_task->getDependencies($upd_task->task_id))) {
         $offSet = $bulk_move_date;
         $start_date = new CDate($upd_task->task_start_date);
         $start_date->addDays($offSet);
         $upd_task->task_start_date = $start_date->format(FMT_DATETIME_MYSQL);
         $end_date = new CDate($upd_task->task_end_date);
         $end_date->addDays($offSet);
         $upd_task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL);
         $upd_task->store();
         $upd_task->shiftDependentTasks();
     }
 }
 //Action: Modify Start Date
 if (isset($_POST['add_task_bulk_start_date']) && $bulk_task_start_date != '' && $bulk_start_date) {
     if ($upd_task->task_id) {
         $upd_task->task_start_date = $bulk_start_date;
         $upd_task->store();
     }
 }
Ejemplo n.º 5
0
        //print "<pre>$sql</pre>";
        $result = db_loadList($sql);
        foreach ($result as $row) {
            $people[$row['task_log_creator']][$i] = $row['hours'];
        }
        $date = $start_day->format("%Y-%m-%d") . " 12:00:00";
        $start_day->setDate($date, DATE_FORMAT_ISO);
        $start_day->addDays(-7);
    }
}
$sql = "SELECT company_id, company_name FROM companies WHERE " . getPermsWhereClause("companies", "company_id") . " ORDER BY company_name";
//print "<pre>$sql</pre>";
$companies = arrayMerge(array(0 => $AppUI->_('All Entities')), db_loadHashList($sql));
$next_day = new CDate();
$next_day->copy($start_day);
$next_day->addDays($week_count * 7 * 2);
?>
<form name="frmCompanySelect" action="" method="get">
	<input type="hidden" name="m" value="timecard">
	<input type="hidden" name="report_type" value="weekly_by_user">
	<input type="hidden" name="tab" value="<?php 
echo $tab;
?>
">
	<table cellspacing="1" cellpadding="2" border="0" width="100%">
	<tr>
		<td width="95%"><?php 
echo arraySelect($companies, 'company_id', 'size="1" class="text" id="medium" onchange="document.frmCompanySelect.submit()"', $company_id);
?>
</td>
                <?php 
Ejemplo n.º 6
0
<?php 
    $total_sum += $sum_project;
}
?>
    <tr>
        <td>&nbsp;</th>
        <td style="text-align:center; font-weight:bold;"><?php 
echo $AppUI->_('Total');
?>
:</td>
<?php 
$date = new CDate($start_report);
for ($i = 1; $i <= $start_report->getDaysInMonth(); $i++) {
    ?>
	<td style="text-align:center; font-weight:bold; "><?php 
    echo sprintf("%.1f", $user_by_day[$date->format('%Y-%m-%d')]);
    ?>
</td>
<?php 
    $date->addDays(1);
}
?>
    <td style="text-align:center;"><strong> <?php 
echo sprintf("%.1f", $total_sum);
?>
</strong></td>
    </tr>
</table>
	
	
Ejemplo n.º 7
0
//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);
//date of the first day of the previous week.
$prev_date = new CDate();
$prev_date->copy($start_day);
$prev_date->addDays(-7);
//date of the first day of the next week.
$next_date = new CDate();
$next_date->copy($start_day);
$next_date->addDays(7);
//***MOD 20050525 pedroa $is_my_timesheet = $user_id == $AppUI->user_id;
$is_my_timesheet = $user_id == $AppUI->user_id || $can_edit_other_timesheets;
?>
	<script>
		function viewLog(id) {
			go('index.php?m=tasks&a=view&task_id='+id);
		}

		function editLog(id) {
			go('index.php?m=timecard&tab=1&tid='+id);
		}

		function deleteLog(id, name, day) {
			if (confirm('Are you sure you want to delete task log\n[ '+name+' ]\ncreated on '+day+'?')) {
				var f = document.DelLog;
Ejemplo n.º 8
0
}
$wk = $AppUI->getState('TmsWk') !== NULL && $wk >= 0 ? $AppUI->getState('TmsWk') : 0;
$thisDate = new CDate();
// set date for displaying and timesheet_date
//get working days from config system
$working_days = explode(',', dPgetConfig('cal_working_days'));
$wd_nb = count($working_days);
// set the start of the week. 1 for monday, 0 for sunday.
if (in_array(LOCALE_FIRST_DAY, $working_days)) {
    $rollover_day = LOCALE_FIRST_DAY;
} else {
    //if the first day determined by user isn't an working day, retrieve the min working day
    $rollover_day = min($working_days);
}
$time_set = new CDate();
$time_set->addDays(-7 * $wk);
$time_set = CUtils::getStartOfWeek($time_set, $rollover_day);
//Get list of dates for current timesheet
$timestampArray = CUtils::getListDateOfTheWeek($time_set, $working_days);
//Build week header's string
$header = $AppUI->_('Week from') . " ";
$header .= $AppUI->_(date("l", min($timestampArray))) . ' ' . date("d/m/Y", min($timestampArray));
$header .= ' ' . $AppUI->_('to') . ' ';
$header .= $AppUI->_(date("l", max($timestampArray))) . ' ' . date("d/m/Y", max($timestampArray));
?>

<!-- Display week header with appropriate arrows for prev/next  week-->
<table width="100%" class="motitle" cellspacing="0" cellpadding="3" border="0">
	<tr>
	<?php 
$prev = dPshowImage(dPfindImage('prev.gif'), 16, 16, $AppUI->_('Previous week'), 'Previous week');
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 /**** Add tasks to an array and check conflicts ****/
 // Select tasks without children (sub tasks)
 $sql = "select a.*, !a.task_dynamic AS fixed FROM tasks AS a " . "LEFT JOIN tasks AS b ON a.task_id = b.task_parent AND a.task_id != b.task_id " . "WHERE (b.task_id IS NULL or b.task_id = b.task_parent) " . "AND (a.task_project = {$project_id}) " . "ORDER BY a.task_priority desc, a.task_order desc";
 $dtrc = mysql_query($sql);
 while ($row = mysql_fetch_array($dtrc, MYSQL_ASSOC)) {
     // check durations
     // OBS: agregue if (task_end_date)
     if (!$row["task_duration"] && $row["task_end_date"] == $NO_DATE) {
         log_error("Task " . task_link($row) . " has no duration.", "Please enter the expected duration: " . "<input class=input type=text name='set_duration[" . $row["task_id"] . "]' size=3>" . "<select name='dayhour[" . $row["task_id"] . "]'>" . "<option value='1'>hour(s)</option>" . "<option value='24'>day(s)</option>" . "</select>");
         $errors = true;
     }
     // calculate or set blank task_end_date if unset
     if (!$row["task_dynamic"] && $row["task_end_date"] == $NO_DATE) {
         $end_date = new CDate($row["task_start_date"]);
         $durn = convert2days($row["task_duration"], $row["task_duration_type"]);
         $end_date->addDays($durn);
         $row["task_end_date"] = $end_date->getDate();
         if ($do == "ask" && $option_no_end_date_warning) {
             log_warning("Task " . task_link($row) . " has no end date. Using tasks duration instead.", '<input type="checkbox" name="set_end_date[' . $row['task_id'] . ']" id="set_end_date[' . $row['task_id'] . ']" value="1" /> ' . '<label for="set_end_date[' . $row['task_id'] . ']">Set end date to ' . $row["task_end_date"] . '</label>');
         }
     }
     // check delayed tasks
     if ($do == "ask") {
         if (!$row["task_dynamic"] && $row["task_percent_complete"] == 0) {
             // nothing has be done yet
             $end_time = new CDate(db_dateTime2unix($row["task_end_date"]));
             if ($end_time < time()) {
                 if ($option_check_delayed_tasks) {
                     log_warning("Task " . task_link($row) . " started on " . $row["task_start_date"] . " and ended on " . formatTime($end_time) . ".", '<input type="checkbox" name="set_dynamic[' . $row["task_id"] . ']" id="set_dynamic[' . $row["task_id"] . ']" value="1" checked="checked" /> <label for="set_dynamic[' . $row["task_id"] . ']">Set as dynamic task and reorganize</label><br />' . '<input type="checkbox" name="set_priority[' . $row["task_id"] . ']" id="set_priority[' . $row["task_id"] . ']" value="1" checked="checked" /> <label for="set_priority[' . $row["task_id"] . ']">Set priority to high</label><br />');
                 }
             }
function calc_duration($start_date = null, $end_date = null)
{
    //
    global $AppUI;
    $cal_day_start = intval(dPgetConfig('cal_day_start'));
    $cal_day_end = intval(dPgetConfig('cal_day_end'));
    $count = new CDate($start_date);
    $end = new CDate($end_date);
    $total_dias = 0;
    while ($count <= $end) {
        if ($count->isWorkingDay()) {
            $total_dias++;
        }
        $count->addDays(1);
    }
    return $total_dias;
}
Ejemplo n.º 12
0
} else {
    $AppUI->redirect();
}
$tasksId = CUtils::getProjectLeaderTasks($projectsId);
//Retrieve parameters from GET request
$ago = isset($_GET['ago']) ? $_GET['ago'] : 0;
$dago = isset($_GET['ago']) ? $_GET['ago'] : 0;
$vw = isset($_GET['vw']) ? $_GET['vw'] : 'week';
$time_set = new CDate();
//Build reporting period summary and determine
//the beginning ($sdate) and the end ($edate)
//of the period
$header = $AppUI->_("Activities of ");
switch ($vw) {
    case 'week':
        $time_set->addDays(7 * $ago);
        $sdate = CUtils::getStartOfWeek($time_set, $rollover_day);
        $edate = new CDate(CUtils::getEndOfWeek($sdate));
        $header = $AppUI->_("Week's activities from") . " " . $AppUI->_($sdate->format('%A')) . " " . $sdate->format('%d/%m/%Y') . " " . $AppUI->_(" to ") . " " . $AppUI->_($edate->format('%A')) . " " . $edate->format('%d/%m/%Y');
        break;
    case 'month':
        $time_set->addMonths($ago);
        $sdate = clone $time_set;
        $sdate->setDay(1);
        $edate = clone $sdate;
        $edate->addMonths(1);
        $edate->addDays(-1);
        $header .= " " . $AppUI->_($time_set->format("%B")) . " " . $time_set->format("%Y");
        break;
    case 'year':
        $time_set->addMonths(12 * $ago);
Ejemplo n.º 13
0
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool	
  **/
 function importTasks($from_project_id)
 {
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = new DBQuery();
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $from_project_id);
     $sql = $q->prepare();
     $q->clear();
     $tasks = array_flip(db_loadColumn($sql));
     $origDate = new CDate($origProject->project_start_date);
     $destDate = new CDate($this->project_start_date);
     $dateOffset = $destDate->dateDiff($origDate);
     // Old dependencies array from imported tasks
     $deps = array();
     // New dependencies array for new copies of imported tasks
     $newDeps = array();
     // Old2New task ID array
     $taskXref = array();
     // New task ID to old parent array
     $nid2op = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         // Grab the old parent id
         $oldParent = (int) $objTask->task_parent;
         $deps[$orig] = $objTask->getDependencies();
         $destTask = $objTask->copy($this->project_id, 0);
         $nid2op[$destTask->task_id] = $oldParent;
         $tasks[$orig] = $destTask;
         $taskXref[$orig] = (int) $destTask->task_id;
     }
     // Build new dependencies array
     foreach ($deps as $odkey => $od) {
         $ndt = '';
         $ndkey = $taskXref[$odkey];
         $odep = explode(',', $od);
         foreach ($odep as $odt) {
             $ndt = $ndt . $taskXref[$odt] . ',';
         }
         $ndt = rtrim($ndt, ',');
         $newDeps[$ndkey] = $ndt;
     }
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . $this->project_id);
     $tasks = $q->loadColumn();
     // Update dates based on new project's start date.
     foreach ($tasks as $task_id) {
         $newTask = new CTask();
         $newTask->load($task_id);
         if (in_array($task_id, $taskXref)) {
             // Fix task start date from project start date offset
             $origDate->setDate($newTask->task_start_date);
             $destDate->setDate($newTask->task_start_date);
             $destDate->addDays($dateOffset);
             $destDate = $destDate->next_working_day();
             $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
             // Fix task end date from start date + work duration
             //$newTask->calc_task_end_date();
             if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
                 $origDate->setDate($newTask->task_end_date);
                 $destDate->setDate($newTask->task_end_date);
                 $destDate->addDays($dateOffset);
                 $destDate = $destDate->next_working_day();
                 $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
             }
             $newTask->task_parent = $taskXref[$nid2op[$newTask->task_id]];
             $newTask->store();
             $newTask->updateDependencies($newDeps[$task_id]);
         }
         // end check if imported task
         $newTask->store();
     }
     // end Fix record integrity
 }