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;
}
示例#2
0
文件: complete.php 项目: n2i/xvnkb
function setComplete($id)
{
    global $AppUI;
    $task = new CTask();
    if ($task->load($id)) {
        $q = new DBQuery();
        $q->addTable('user_tasks');
        $q->addQuery('user_id');
        $q->addWhere('task_id = ' . $id);
        $q->addWhere('user_id = ' . $AppUI->user_id);
        $r = $q->loadResult();
        if ($r != $AppUI->user_id) {
            $p = new CProject($task->task_project);
            if (!$p->project_id || $p->getManager() != $AppUI->user_id) {
                return 'Error';
            }
        }
        $q->addTable('tasks');
        $q->addUpdate('task_percent_complete', '100');
        $q->addWhere('task_id = ' . $id);
        $q->exec();
        return 'OK';
    }
    return 'Error';
}
/**
 * @param $AppUI
 * @param $task_id
 */
function __extract_from_tasks_pinning($AppUI, $task_id)
{
    if (isset($_GET['pin'])) {
        $pin = (int) w2PgetParam($_GET, 'pin', 0);
        $task = new CTask();
        // load the record data
        if (1 == $pin) {
            $result = $task->pinTask($AppUI->user_id, $task_id);
        }
        if (-1 == $pin) {
            $result = $task->unpinTask($AppUI->user_id, $task_id);
        }
        if (!$result) {
            $AppUI->setMsg('Pinning ', UI_MSG_ERROR, true);
        }
        $task->load($task_id);
        $AppUI->redirect('m=projects&a=view&project_id=' . $task->task_project, -1);
    }
}
示例#4
0
     // patch 2.12.04 tasks finished in the last 7 days
     //$q->addTable('user_tasks');
     $q->addTable('user_tasks');
     $q->addWhere('user_tasks.user_id = ' . (int) $user_id);
     $q->addWhere('user_tasks.task_id = tasks.task_id');
     $q->addWhere('task_percent_complete = 100');
     //TODO: use date class to construct date.
     $q->addWhere('task_end_date >= \'' . date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m'), date('d') - 7, date('Y'))) . '\'');
     break;
 case 'children':
     $q->addWhere('task_parent = ' . (int) $task_id);
     $q->addWhere('tasks.task_id <> ' . $task_id);
     break;
 case 'deepchildren':
     $taskobj = new CTask();
     $taskobj->load((int) $task_id);
     $deepchildren = $taskobj->getDeepChildren();
     $q->addWhere('tasks.task_id IN (' . implode(',', $deepchildren) . ')');
     $q->addWhere('tasks.task_id <> ' . $task_id);
     break;
 case 'myproj':
     $q->addWhere('project_owner = ' . (int) $user_id);
     break;
 case 'mycomp':
     if (!$AppUI->user_company) {
         $AppUI->user_company = 0;
     }
     $q->addWhere('project_company = ' . (int) $AppUI->user_company);
     break;
 case 'myunfinished':
     $q->addTable('user_tasks');
示例#5
0
 public function getDeepChildren()
 {
     $children = $this->getChildren();
     if ($children) {
         $deep_children = array();
         $tempTask = new CTask();
         foreach ($children as $child) {
             $tempTask->load($child);
             $deep_children = array_merge($deep_children, $tempTask->getDeepChildren());
         }
         return array_merge($children, $deep_children);
     }
     return array();
 }
/**
 * Used to check if a user has task_access to see the task in task list context
 * (This function was optimized to try to use the DB the least possible)
 * TODO:  Remove for v4.0 - caseydk 20 September 2012
 *
 * @param mixed $task_id
 * @param mixed $task_access
 * @param mixed $task_owner
 * @return true if user has task access to it, or false if he doesn't
 *
 * @deprecated
 */
function canTaskAccess($task_id)
{
    trigger_error("canTaskAccess has been deprecated in v3.0 and will be removed by v4.0. Please use CTask->canAccess() instead.", E_USER_NOTICE);
    global $AppUI;
    $task = new CTask();
    $task->load($task_id);
    return $task->canAccess($AppUI->user_id);
}
 /**	Import tasks from another project
  *
  *	@param	int		Project ID of the tasks come from.
  *	@return	bool
  **/
 public function importTasks($from_project_id)
 {
     global $AppUI;
     $errors = array();
     // Load the original
     $origProject = new CProject();
     $origProject->load($from_project_id);
     $q = $this->_query;
     $q->addTable('tasks');
     $q->addQuery('task_id');
     $q->addWhere('task_project =' . (int) $from_project_id);
     $tasks = array_flip($q->loadColumn());
     $q->clear();
     $origDate = new w2p_Utilities_Date($origProject->project_start_date);
     $destDate = new w2p_Utilities_Date($this->project_start_date);
     $timeOffset = $origDate->dateDiff($destDate);
     if ($origDate->compare($origDate, $destDate) > 0) {
         $timeOffset = -1 * $timeOffset;
     }
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $origDate->addDays($timeOffset);
         $destDate = $origDate;
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         if (!empty($newTask->task_end_date) && $newTask->task_end_date != '0000-00-00 00:00:00') {
             $origDate->setDate($newTask->task_end_date);
             $origDate->addDays($timeOffset);
             $destDate = $origDate;
             $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
         }
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         $result = $newTask->store($AppUI);
         $newTask->addReminder();
         $importedTasks[] = $newTask->task_id;
         if (is_array($result) && count($result)) {
             foreach ($result as $key => $error_msg) {
                 $errors[] = $newTask->task_name . ': ' . $error_msg;
             }
         }
     }
     // end Fix record integrity
     // We have errors, so rollback everything we've done so far
     if (count($errors)) {
         foreach ($importedTasks as $badTask) {
             $delTask = new CTask();
             $delTask->task_id = $badTask;
             $delTask->delete($AppUI);
         }
     }
     return $errors;
 }
示例#8
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
 }
示例#9
0
 /**
  * Delete Request Handler
  *
  * This method is called when a request is a DELETE
  *
  * @return array
  */
 public function executeDelete()
 {
     $valid = $this->hasRequiredParameters($this->requiredParams);
     if ($valid instanceof Frapi_Error) {
         return $valid;
     }
     $username = $this->getParam('username');
     $password = $this->getParam('password');
     $task_id = $this->getParam('task_id', self::TYPE_INT);
     // Attempt to login as user, a little bit of a hack as we currently
     // require the $_POST['login'] var to be set as well as a global AppUI
     $AppUI = new CAppUI();
     $GLOBALS['AppUI'] = $AppUI;
     $_POST['login'] = '******';
     if (!$AppUI->login($username, $password)) {
         throw new Frapi_Error('INVALID_LOGIN');
     }
     $task = new CTask();
     $task->load($task_id);
     if (!$task->delete($AppUI)) {
         throw new Frapi_Error('PERMISSION_ERROR');
     }
     $this->data['success'] = true;
     return $this->toArray();
 }
示例#10
0
 /**
  * Put Request Handler
  *
  * This method is called when a request is a PUT
  *
  * @return array
  */
 public function executePut()
 {
     /**
      * @todo Remove this once we figure out how to reference vars in file
      * that is autoloaded
      */
     global $tracking_dynamics;
     $valid = $this->hasRequiredParameters($this->requiredParams);
     if ($valid instanceof Frapi_Error) {
         return $valid;
     }
     $username = $this->getParam('username');
     $password = $this->getParam('password');
     $hassign = $this->getParam('hassign');
     $hdependencies = $this->getParam('hdependencies');
     $notify = $this->getParam('task_notify');
     $comment = $this->getParam('email_comment');
     $task_id = $this->getParam('task_id');
     $adjustStartDate = $this->getParam('set_task_start_date');
     // Attempt to login as user, a little bit of a hack as we currently
     // require the $_POST['login'] var to be set as well as a global AppUI
     $AppUI = new CAppUI();
     $GLOBALS['AppUI'] = $AppUI;
     $_POST['login'] = '******';
     if (!$AppUI->login($username, $password)) {
         throw new Frapi_Error('INVALID_LOGIN');
     }
     $post_data = array('task_id' => 0, 'task_name' => $this->getParam('task_name'), 'task_status' => $this->getParam('task_status'), 'task_percent_complete' => $this->getParam('task_percent_complete'), 'task_milestone' => $this->getParam('task_milestone'), 'task_owner' => $this->getParam('task_owner'), 'task_access' => $this->getParam('task_access'), 'task_related_url' => $this->getParam('task_related_url'), 'task_parent' => $this->getParam('task_parent'), 'task_type' => $this->getParam('task_type'), 'task_target_budget' => $this->getParam('task_target_budget'), 'task_description' => $this->getParam('task_description'), 'task_start_date' => $this->getParam('task_start_date'), 'task_end_date' => $this->getParam('task_end_date'), 'task_duration' => $this->getParam('task_duration'), 'task_duration_type' => $this->getParam('task_duration_type'), 'task_dynamic' => $this->getParam('task_dynamic'), 'task_allow_other_user_tasklogs' => $this->getParam('task_allow_other_user_tasklogs'), 'task_project' => $this->getParam('task_project'), 'task_priority' => $this->getParam('task_priority'));
     // Include any files for handling module-specific requirements
     foreach (findTabModules('tasks', 'addedit') as $mod) {
         $fname = W2P_BASE_DIR . '/modules/' . $mod . '/tasks_dosql.addedit.php';
         if (file_exists($fname)) {
             require_once $fname;
         }
     }
     // Find the task if we are set
     $task_end_date = null;
     if ($task_id) {
         $task->load($task_id);
         $task_end_date = new w2p_Utilities_Date($task->task_end_date);
     }
     $task = new CTask();
     if (!$task->bind($post_data)) {
         throw new Frapi_Error('SAVE_ERROR', $task->getError());
     }
     if ($task->task_dynamic != 1) {
         $task_dynamic_delay = $this->getParam('task_dynamic_nodelay') ? $this->getParam('task_dynamic_nodelay') : '0';
         if (in_array($task->task_dynamic, $tracking_dynamics)) {
             $task->task_dynamic = $task_dynamic_delay ? 21 : 31;
         } else {
             $task->task_dynamic = $task_dynamic_delay ? 11 : 0;
         }
     }
     // Let's check if task_dynamic is unchecked
     if (!$this->getParam('task_dynamic')) {
         $task->task_dynamic = false;
     }
     // Make sure task milestone is set or reset as appropriate
     if ($this->getParam('task_milestone')) {
         $task->task_milestone = false;
     }
     //format hperc_assign user_id=percentage_assignment;user_id=percentage_assignment;user_id=percentage_assignment;
     $tmp_ar = explode(';', $this->getParam('hperc_assign'));
     $i_cmp = sizeof($tmp_ar);
     $hperc_assign_ar = array();
     for ($i = 0; $i < $i_cmp; $i++) {
         $tmp = explode('=', $tmp_ar[$i]);
         if (count($tmp) > 1) {
             $hperc_assign_ar[$tmp[0]] = $tmp[1];
         } elseif ($tmp[0] != '') {
             $hperc_assign_ar[$tmp[0]] = 100;
         }
     }
     // let's check if there are some assigned departments to task
     $task->task_departments = implode(',', $this->getParam('dept_ids', self::TYPE_ARRAY));
     // convert dates to SQL format first
     if ($task->task_start_date) {
         $date = new w2p_Utilities_Date($task->task_start_date);
         $task->task_start_date = $date->format(FMT_DATETIME_MYSQL);
     }
     $end_date = null;
     if ($task->task_end_date) {
         if (strpos($task->task_end_date, '2400') !== false) {
             $task->task_end_date = str_replace('2400', '2359', $task->task_end_date);
         }
         $end_date = new w2p_Utilities_Date($task->task_end_date);
         $task->task_end_date = $end_date->format(FMT_DATETIME_MYSQL);
     }
     $error_array = $task->store($AppUI);
     // Return all the validation messages
     if ($error_array !== true) {
         $error_message = '';
         foreach ($error_array as $error) {
             $error_message .= $error . '. ';
         }
         throw new Frapi_Error('SAVE_ERROR', $error_message);
     }
     $task_parent = $this->getParam('task_parent') ? $this->getParam('task_parent', SELF::TYPE_INT) : 0;
     $old_task_parent = $this->getParam('old_task_parent') ? $this->getParam('old_task_parent', SELF::TYPE_INT) : 0;
     if ($task_parent != $old_task_parent) {
         $oldTask = new CTask();
         $oldTask->load($old_task_parent);
         $oldTask->updateDynamics(false);
     }
     // How to handle custom fields? Do we support it in api?
     // Now add any task reminders
     // If there wasn't a task, but there is one now, and
     // that task date is set, we need to set a reminder.
     if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) {
         $task->addReminder();
     }
     if (isset($hassign)) {
         $task->updateAssigned($hassign, $hperc_assign_ar);
     }
     if (isset($hdependencies)) {
         // && !empty($hdependencies)) {
         // there are dependencies set!
         // backup initial start and end dates
         $tsd = new w2p_Utilities_Date($task->task_start_date);
         $ted = new w2p_Utilities_Date($task->task_end_date);
         // updating the table recording the
         // dependency relations with this task
         $task->updateDependencies($hdependencies, $task_parent);
         // we will reset the task's start date based upon dependencies
         // and shift the end date appropriately
         if ($adjustStartDate && !is_null($hdependencies)) {
             // load already stored task data for this task
             $tempTask = new CTask();
             $tempTask->load($task->task_id);
             // shift new start date to the last dependency end date
             $nsd = new w2p_Utilities_Date($tempTask->get_deps_max_end_date($tempTask));
             // prefer Wed 8:00 over Tue 16:00 as start date
             $nsd = $nsd->next_working_day();
             // prepare the creation of the end date
             $ned = new w2p_Utilities_Date();
             $ned->copy($nsd);
             if (empty($task->task_start_date)) {
                 // appropriately calculated end date via start+duration
                 $ned->addDuration($task->task_duration, $task->task_duration_type);
             } else {
                 // calc task time span start - end
                 $d = $tsd->calcDuration($ted);
                 // Re-add (keep) task time span for end date.
                 // This is independent from $obj->task_duration.
                 // The value returned by Date::Duration() is always in hours ('1')
                 $ned->addDuration($d, '1');
             }
             // prefer tue 16:00 over wed 8:00 as an end date
             $ned = $ned->prev_working_day();
             $task->task_start_date = $nsd->format(FMT_DATETIME_MYSQL);
             $task->task_end_date = $ned->format(FMT_DATETIME_MYSQL);
             $q = new w2p_Database_Query();
             $q->addTable('tasks', 't');
             $q->addUpdate('task_start_date', $task->task_start_date);
             $q->addUpdate('task_end_date', $task->task_end_date);
             $q->addWhere('task_id = ' . (int) $task->task_id);
             $q->addWhere('task_dynamic <> 1');
             $q->exec();
             $q->clear();
         }
         $task->pushDependencies($task->task_id, $task->task_end_date);
     }
     unset($task->_query, $task->_error, $task->_tbl_prefix, $task->_tbl, $task->_tbl_key, $task->_tbl_module);
     $task = (array) $task;
     $this->data['task'] = $task;
     $this->data['success'] = true;
     return new Frapi_Response(array('code' => 201, 'data' => $this->data));
 }
示例#11
0
}
$titleBlock->show();
//Clear the file id if checking out so a new version is created.
if ($ci) {
    $file_id = 0;
}
if ($file->file_project) {
    $file_project = $file->file_project;
}
if ($file->file_task) {
    $file_task = $file->file_task;
    $task_name = $file->getTaskName();
} else {
    if ($file_task) {
        $task = new CTask();
        $task->load($file_task);
        $task_name = $task->task_name;
    } else {
        $task_name = '';
    }
}
if (isset($file->file_helpdesk_item)) {
    $file_helpdesk_item = $file->file_helpdesk_item;
}
$folders = getFolderSelectList();
?>
<script language="javascript">
function submitIt() {
	var f = document.uploadFrm;
	f.submit();
}
 /**	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);
     $timeOffset = $destDate->getTime() - $origDate->getTime();
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps
     foreach ($tasks as $orig => $void) {
         $objTask = new CTask();
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
         $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($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
             $destDate = $destDate->next_working_day();
             $newTask->task_end_date = $destDate->format(FMT_DATETIME_MYSQL);
         }
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         $newTask->store();
     }
     // end Fix record integrity
 }
 /**	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);
     $timeOffset = $destDate->getTime() - $origDate->getTime();
     $objTask = new CTask();
     // Dependencies array
     $deps = array();
     // Copy each task into this project and get their deps, y tambien copia los usuarios asignados
     foreach ($tasks as $orig => $void) {
         $objTask->load($orig);
         $destTask = $objTask->copy($this->project_id);
         $tasks[$orig] = $destTask;
         if ($this->project_company == $origProject->project_company) {
             // guarda en user_tasks todos los usuarios asignados a la tarea original, solo si this y
             //  origProy pertenecen a la misma compañía.
             $sql = "select * from user_tasks where task_id = {$orig}";
             $rows = db_LoadList($sql);
             foreach ($rows as $row) {
                 $sql2 = "INSERT INTO user_tasks (user_id, user_type, task_id, perc_assignment, user_task_priority) \n\t\t\t\t\t\t\t\tVALUES (" . $row['user_id'] . "," . $row['user_type'] . "," . $destTask->task_id . "," . $row['perc_assignment'] . "," . $row['user_task_priority'] . ")";
                 db_exec($sql2);
             }
         }
         $deps[$orig] = $objTask->getDependencies();
     }
     // Fix record integrity
     foreach ($tasks as $old_id => $newTask) {
         // Fix parent Task
         // This task had a parent task, adjust it to new parent task_id
         if ($newTask->task_id != $newTask->task_parent) {
             $newTask->task_parent = $tasks[$newTask->task_parent]->task_id;
         }
         // Fix task start date from project start date offset
         $origDate->setDate($newTask->task_start_date);
         $destDate->setDate($origDate->getTime() + $timeOffset, DATE_FORMAT_UNIXTIME);
         $destDate = $newTask->next_working_day($destDate);
         $newTask->task_start_date = $destDate->format(FMT_DATETIME_MYSQL);
         // Fix task end date from start date + work duration
         $newTask->calc_task_end_date();
         // Dependencies
         if (!empty($deps[$old_id])) {
             $oldDeps = explode(',', $deps[$old_id]);
             // New dependencies array
             $newDeps = array();
             foreach ($oldDeps as $dep) {
                 $newDeps[] = $tasks[$dep]->task_id;
             }
             // Update the new task dependencies
             $csList = implode(',', $newDeps);
             $newTask->updateDependencies($csList);
         }
         // end of update dependencies
         //Asignados
         $newTask->store();
     }
     // end Fix record integrity
 }
示例#14
0
 if ($taskRecount) {
     $myTask = new CTask();
     CProject::updateTaskCount($taskRecount, $myTask->getTaskCount($taskRecount));
 }
 //$obj->task_project
 if (is_array($result)) {
     $AppUI->setMsg($result, UI_MSG_ERROR, true);
     $AppUI->holdObject($obj);
     $AppUI->redirect('m=tasks&a=addedit');
 }
 if ($result) {
     $task_parent = (int) w2PgetParam($_POST, 'task_parent', 0);
     $old_task_parent = (int) w2PgetParam($_POST, 'old_task_parent', 0);
     if ($task_parent != $old_task_parent) {
         $oldTask = new CTask();
         $oldTask->load($old_task_parent);
         $oldTask->updateDynamics(false);
     }
     $custom_fields = new CustomFields($m, 'addedit', $obj->task_id, 'edit');
     $custom_fields->bind($_POST);
     $sql = $custom_fields->store($obj->task_id);
     // Store Custom Fields
     // Now add any task reminders
     // If there wasn't a task, but there is one now, and
     // that task date is set, we need to set a reminder.
     if (empty($task_end_date) || !empty($end_date) && $task_end_date->dateDiff($end_date)) {
         $obj->addReminder();
     }
     $AppUI->setMsg($task_id ? 'Task updated' : 'Task added', UI_MSG_OK);
     if (isset($hassign)) {
         $obj->updateAssigned($hassign, $hperc_assign_ar);
示例#15
0
 /** @deprecated */
 public function getTaskName()
 {
     trigger_error("The CFile->getTaskName method has been deprecated in v3.0 and will be removed in v4.0. Please use just load a CTask object instead", E_USER_NOTICE);
     $task = new CTask();
     $task->load((int) $this->file_task);
     return $task->task_name;
 }
示例#16
0
 /**
  * Updates the variable information on the task.
  *
  * @param int $task_log_task that task id of task this task log is for
  *
  * @return void
  *
  * @access private
  */
 protected function updateTaskSummary($AppUI = null, $task_id)
 {
     $q = $this->_getQuery();
     if ($this->_perms->checkModuleItem('tasks', 'edit', $task_id)) {
         if ($this->task_log_percent_complete < 100) {
             $q->addQuery('task_log_percent_complete, task_log_date');
             $q->addTable('task_log');
             $q->addWhere('task_log_task = ' . (int) $task_id);
             $q->addOrder('task_log_date DESC, task_log_id DESC');
             $q->setLimit(1);
             $results = $q->loadHash();
             $percentComplete = $results['task_log_percent_complete'];
         } else {
             $percentComplete = 100;
         }
         $task = new CTask();
         $task->overrideDatabase($this->_query);
         $task->load($task_id);
         $task->task_percent_complete = $percentComplete;
         $diff = strtotime($this->task_log_task_end_date) - strtotime($task->task_end_date);
         $task->task_end_date = 0 == $diff ? $task->task_end_date : $this->task_log_task_end_date;
         $success = $task->store();
         if (!$success) {
             $this->_AppUI->setMsg($task->getError(), UI_MSG_ERROR, true);
         }
         $task->pushDependencies($task_id, $task->task_end_date);
     }
     $q->addQuery('SUM(task_log_hours)');
     $q->addTable('task_log');
     $q->addWhere('task_log_task = ' . (int) $task_id);
     $totalHours = $q->loadResult();
     CTask::updateHoursWorked($task_id, $totalHours);
 }
示例#17
0
                        //copy task
                        if (isset($children)) {
                            $t2 = $t->deepCopy($new_project, $new_task);
                        } else {
                            $t2 = $t->copy($new_project, $new_task);
                        }
                        $t2->store();
                    } else {
                        if ($action > -2 && $action < 2) {
                            //set priority
                            $t->task_priority = $action;
                            $t->store();
                            if (isset($children)) {
                                foreach ($children as $child_id) {
                                    $child_t = new CTask();
                                    $child_t->load($child_id);
                                    $child_t->task_priority = $action;
                                    $child_t->store();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
$AppUI->savePlace();
$proj = new CProject();
$tobj = new CTask();
$q = new DBQuery();
function showtask_pr_ed(&$arr, $level = 0, $today_view = false)
{
    global $AppUI, $done;
    //Check for Tasks Access
    $tmpTask = new CTask();
    $tmpTask->load($arr['task_id']);
    $canAccess = $tmpTask->canAccess();
    if (!$canAccess) {
        return false;
    }
    $htmlHelper = new w2p_Output_HTMLHelper($AppUI);
    $htmlHelper->df .= ' ' . $AppUI->getPref('TIMEFORMAT');
    $done[] = $arr['task_id'];
    $s = '<tr>';
    // dots
    $s .= '<td style="width: ' . ($today_view ? '20%' : '50%') . '" class="data _name">';
    for ($y = 0; $y < $level; $y++) {
        if ($y + 1 == $level) {
            $image = w2PfindImage('corner-dots.gif', $m);
        } else {
            $image = w2PfindImage('shim.gif', $m);
        }
        $s .= '<img src="' . $image . '" width="16" height="12"  border="0" alt="" />';
    }
    // name link
    $alt = mb_strlen($arr['task_description']) > 80 ? mb_substr($arr['task_description'], 0, 80) . '...' : $arr['task_description'];
    // instead of the statement below
    $alt = mb_str_replace('"', "&quot;", $alt);
    $alt = mb_str_replace("\r", ' ', $alt);
    $alt = mb_str_replace("\n", ' ', $alt);
    $open_link = w2PshowImage('collapse.gif');
    if ($arr['task_milestone'] > 0) {
        $s .= '&nbsp;<b>' . $arr["task_name"] . '</b><!--</a>--> <img src="' . w2PfindImage('icons/milestone.gif', $m) . '" border="0" alt="" />';
    } elseif ($arr['task_dynamic'] == '1') {
        $s .= $open_link;
        $s .= '<strong>' . $arr['task_name'] . '</strong>';
    } else {
        $s .= $arr['task_name'];
    }
    $s .= '</td>';
    $s .= $htmlHelper->createCell('task_percent_complete', $arr['task_percent_complete']);
    $s .= $htmlHelper->createCell('task_start_date', $arr['task_start_date']);
    $s .= $htmlHelper->createCell('task_end_date', $arr['task_end_date']);
    $s .= $htmlHelper->createCell('last_update', $arr['last_update']);
    $s .= '</tr>';
    return $s;
}
示例#19
0
$log = new CTaskLog();
if ($task_log_id) {
    if (!$canEdit) {
        $AppUI->redirect("m=public&a=access_denied");
    }
    $log->load($task_log_id);
} else {
    if (!$canAdd) {
        $AppUI->redirect("m=public&a=access_denied");
    }
    $log->task_log_task = $task_id;
    $log->task_log_name = $obj->task_name;
}
// Check that the user is at least assigned to a task
$task = new CTask();
$task->load($task_id);
if (!$task->canAccess($AppUI->user_id)) {
    $AppUI->redirect('m=public&a=access_denied');
}
// Lets check which cost codes have been used before
/*$sql = "select distinct task_log_costcode
        from task_log
        where task_log_costcode != ''
        order by task_log_costcode";
$task_log_costcodes = array(""); // Let's add a blank default option
$task_log_costcodes = array_merge($task_log_costcodes, db_loadColumn($sql));
*/
$proj =& new CProject();
$proj->load($obj->task_project);
$sql = "SELECT billingcode_id, billingcode_name\n        FROM billingcode\n        WHERE billingcode_status=0\n        AND (company_id='{$proj->project_company}' OR company_id = 0)\n        ORDER BY billingcode_name";
$task_log_costcodes[0] = '';
示例#20
0
                    </td>
                </tr>
                <tr>
                    <td align="right" nowrap="nowrap"><?php 
echo $AppUI->_('Task');
?>
:</td>
                    <td class="hilite"><strong><?php 
echo $obj->task_name;
?>
</strong></td>
                </tr>
                <?php 
if ($obj->task_parent != $obj->task_id) {
    $obj_parent = new CTask();
    $obj_parent->load($obj->task_parent);
    ?>
                <tr>
                    <td align="right" nowrap="nowrap"><?php 
    echo $AppUI->_('Task Parent');
    ?>
:</td>
                    <td class="hilite"><a href="<?php 
    echo "./index.php?m=tasks&a=view&task_id=" . $obj_parent->task_id;
    ?>
"><?php 
    echo $obj_parent->task_name;
    ?>
</a></td>
                </tr>
                <?php 
示例#21
0
    $link_id = $link->link_id;
} else {
    $link->loadFull($AppUI, $link_id);
}
if (!$link && $link_id > 0) {
    $AppUI->setMsg('Link');
    $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
    $AppUI->redirect();
} elseif (0 == $link_id && ($project_id || $task_id)) {
    // We are creating a link, so if we have them lets figure out the project
    // and task id
    $link->link_project = $project_id;
    $link->link_task = $task_id;
    if ($task_id) {
        $link_task = new CTask();
        $link_task->load($task_id);
        $link->task_name = $link_task->task_name;
    }
}
// setup the title block
$ttl = $link_id ? 'Edit Link' : 'Add Link';
$titleBlock = new CTitleBlock($AppUI->_($ttl), 'folder5.png', $m, $m . '.' . $a);
$titleBlock->addCrumb('?m=' . $m, 'links list');
$canDelete = $perms->checkModuleItem($m, 'delete', $link_id);
if ($canDelete && $link_id) {
    $titleBlock->addCrumbDelete('delete link', $canDelete, $msg);
}
$titleBlock->show();
$prj = new CProject();
$projects = $prj->getAllowedProjects($AppUI->user_id, false);
foreach ($projects as $project_id => $project_info) {
示例#22
0
$stype = array('' => '(' . $AppUI->_('Type') . ')') + $type;
$priority = w2Pgetsysval('TaskPriority');
$spriority = array('' => '(' . $AppUI->_('Priority') . ')') + $priority;
$task_access = array(CTask::ACCESS_PUBLIC => $AppUI->_('Public'), CTask::ACCESS_PROTECTED => $AppUI->_('Protected'), CTask::ACCESS_PARTICIPANT => $AppUI->_('Participant'), CTask::ACCESS_PRIVATE => $AppUI->_('Private'));
$stask_access = array('' => '(' . $AppUI->_('Access') . ')') + $task_access;
$durntype = w2PgetSysval('TaskDurationType');
$sdurntype = array('' => '(' . $AppUI->_('Duration Type') . ')') + $durntype;
$sother = array('' => '(' . $AppUI->_('Other Operations') . ')', '1' => $AppUI->_('Mark Tasks as Finished'), '8' => $AppUI->_('Mark Tasks as Active'), '9' => $AppUI->_('Mark Tasks as Inactive'), '2' => $AppUI->_('Mark Tasks as Milestones'), '3' => $AppUI->_('Mark Tasks as Non Milestone'), '4' => $AppUI->_('Mark Tasks as Dynamic'), '5' => $AppUI->_('Mark Tasks as Non Dynamic'), '6' => $AppUI->_('Add Task Reminder'), '7' => $AppUI->_('Remove Task Reminder'), '10' => $AppUI->_('Remove Tasks Description'), '99' => $AppUI->_('Delete Tasks'));
//Pull all users
$users = $perms->getPermittedUsers();
$sowners = array('' => '(' . $AppUI->_('Task Owner') . ')') + $perms->getPermittedUsers('tasks');
$sassign = array('' => '(' . $AppUI->_('Assign User') . ')') + $perms->getPermittedUsers('tasks');
$sunassign = array('' => '(' . $AppUI->_('Unassign User') . ')') + $users;
$obj = new CTask();
$allowedTasks = $obj->getAllowedSQL($AppUI->user_id, 'tasks.task_id');
$obj->load($task_id);
$task_project = $project_id ? $project_id : ($obj->task_project ? $obj->task_project : 0);
// let's get root tasks
$q = new w2p_Database_Query();
$q->addQuery('task_id, task_name, task_end_date, task_start_date, task_milestone, task_parent, task_dynamic');
$q->addTable('tasks');
$q->addWhere('task_project = ' . (int) $task_project);
$q->addWhere('task_id = task_parent');
$q->addOrder('task_start_date');
$root_tasks = $q->loadHashList('task_id');
$q->clear();
$projTasks = array();
global $task_parent_options;
$task_parent_options = '';
// Now lets get non-root tasks, grouped by the task parent
$q = new w2p_Database_Query();
示例#23
0
     if ($upd_task->task_project && $upd_task->task_id && $upd_task->task_notify) {
         $upd_task->notify();
     }
 }
 //Action: Unassign User
 if (isset($_POST['bulk_task_unassign']) && $bulk_task_unassign != '') {
     $upd_task = new CTask();
     $upd_task->load($key);
     if ($upd_task->task_id) {
         $upd_task->removeAssigned($bulk_task_unassign);
     }
 }
 // Action: Allow user to add task logs for others
 if (isset($_POST['bulk_task_allow_other_user_tasklogs']) && $bulk_task_allow_other_user_tasklogs != '') {
     $upd_task = new CTask();
     $upd_task->load($key);
     if ($upd_task->task_id) {
         $upd_task->task_allow_other_user_tasklogs = $bulk_task_allow_other_user_tasklogs;
         $result = $upd_task->store($AppUI);
         if (is_array($result)) {
             break;
         }
     }
 }
 //Action: Other Actions
 if (isset($_POST['bulk_task_other']) && $bulk_task_other != '') {
     if ($upd_task->task_id) {
         //Option 1 - Mark as finished
         if ($bulk_task_other == '1') {
             $upd_task->task_percent_complete = 100;
             if (!$upd_task->task_end_date || $upd_task->task_end_date == '0000-00-00 00:00:00') {
示例#24
0
 function notifyContacts()
 {
     global $AppUI, $dPconfig, $locale_char_set;
     //if no project specified than we will not do anything
     if ($this->file_project != 0) {
         $project = new CProject();
         $project->load($this->file_project);
         $mail = new Mail();
         if (intval($this->file_task) != 0) {
             //notify task contacts
             $task = new CTask();
             $task->load($this->file_task);
             $mail->Subject($project->project_name . '::' . $task->task_name . '::' . $this->file_name, $locale_char_set);
         } else {
             //notify project contacts
             $mail->Subject($project->project_name . '::' . $this->file_name, $locale_char_set);
         }
         $body = $AppUI->_('Project') . ': ' . $project->project_name;
         $body .= "\n" . $AppUI->_('URL') . ': ' . DP_BASE_URL . '/index.php?m=projects&amp;a=view&amp;project_id=' . $this->file_project;
         $users = array();
         if (intval($this->file_task) != 0) {
             $body .= "\n\n" . $AppUI->_('Task') . ': ' . $task->task_name;
             $body .= "\n" . $AppUI->_('URL') . ': ' . DP_BASE_URL . '/index.php?m=tasks&amp;a=view&amp;task_id=' . $this->file_task;
             $body .= "\n" . $AppUI->_('Description') . ":\n" . $task->task_description;
             $this->_query->clear();
             $this->_query->addTable('project_contacts', 'pc');
             $this->_query->addJoin('contacts', 'c', 'c.contact_id = pc.contact_id');
             $this->_query->addQuery('c.contact_email as contact_email' . ', c.contact_first_name as contact_first_name' . ', c.contact_last_name as contact_last_name');
             $this->_query->addWhere('pc.project_id = ' . $this->file_project);
             $pc_users = $this->_query->loadList();
             $this->_query->clear();
             $this->_query->addTable('task_contacts', 'tc');
             $this->_query->addJoin('contacts', 'c', 'c.contact_id = tc.contact_id');
             $this->_query->addQuery('c.contact_email as contact_email' . ', c.contact_first_name as contact_first_name' . ', c.contact_last_name as contact_last_name');
             $this->_query->addWhere('tc.task_id = ' . $this->file_task);
             $tc_users = $this->_query->loadList();
             $this->_query->clear();
             $users = array_merge($pc_users, $tc_users);
         } else {
             $this->_query->addTable('project_contacts', 'pc');
             $this->_query->addJoin('contacts', 'c', 'c.contact_id = pc.contact_id');
             $this->_query->addQuery('c.contact_email as contact_email' . ', c.contact_first_name as contact_first_name' . ', c.contact_last_name as contact_last_name');
             $this->_query->addWhere('pc.project_id = ' . $this->file_project);
             $users = $this->_query->loadList();
             $this->_query->clear();
         }
         $body .= "\n\nFile " . $this->file_name . ' was ' . $this->_message . ' by ' . $AppUI->user_first_name . ' ' . $AppUI->user_last_name;
         if ($this->_message != 'deleted') {
             $body .= "\n" . $AppUI->_('URL') . ': ' . DP_BASE_URL . '/fileviewer.php?file_id=' . $this->file_id;
             $body .= "\n" . $AppUI->_('Description') . ":\n" . $this->file_description;
             if ($this->file_co_reason != '') {
                 $body .= "\n" . $AppUI->_('Checkout Reason') . ':' . "\n" . $this->file_co_reason;
             }
         }
         // send mail
         $mail->Body($body, isset($GLOBALS['locale_char_set']) ? $GLOBALS['locale_char_set'] : '');
         $mail->From('"' . $AppUI->user_first_name . ' ' . $AppUI->user_last_name . '" <' . $AppUI->user_email . '>');
         foreach ($users as $row) {
             if ($mail->ValidEmail($row['contact_email'])) {
                 $mail->To($row['contact_email'], true);
                 $mail->Send();
             }
         }
     }
     return '';
 }
示例#25
0
 function update_dep_dates($task_id)
 {
     global $tracking_dynamics;
     $q = new DBQuery();
     $newTask = new CTask();
     $newTask->load($task_id);
     // Do not update tasks that are not tracking dependencies
     if (!in_array($newTask->task_dynamic, $tracking_dynamics)) {
         return;
     }
     // load original task dates and calculate task time span
     $tsd = new CDate($newTask->task_start_date);
     $ted = new CDate($newTask->task_end_date);
     $duration = $tsd->calcDuration($ted);
     // reset start date
     $nsd = new CDate($newTask->get_deps_max_end_date($newTask));
     // prefer Wed 8:00 over Tue 16:00 as start date
     $nsd = $nsd->next_working_day();
     $new_start_date = $nsd->format(FMT_DATETIME_MYSQL);
     // Add task time span to End Date again
     $ned = new CDate();
     $ned->copy($nsd);
     $ned->addDuration($duration, '1');
     // make sure one didn't land on a non-working day
     $ned = $ned->next_working_day(true);
     // prefer tue 16:00 over wed 8:00 as an end date
     $ned = $ned->prev_working_day();
     $new_end_date = $ned->format(FMT_DATETIME_MYSQL);
     // update the db
     $q->addTable('tasks');
     $q->addUpdate('task_start_date', $new_start_date);
     $q->addUpdate('task_end_date', $new_end_date);
     $q->addWhere('task_dynamic <> 1 AND task_id = ' . $task_id);
     $q->exec();
     $q->clear();
     if ($newTask->task_parent != $newTask->task_id) {
         $newTask->updateDynamics();
     }
     return;
 }
示例#26
0
<?php

/* TASKS $Id$ */
if (!defined('DP_BASE_DIR')) {
    die('You should not access this file directly.');
}
/*
 * Tasks :: Add/Edit Form
 */
$task_id = intval(dPgetParam($_REQUEST, 'task_id', 0));
//load the record data
$obj = new CTask();
$q = new DBQuery();
$projTasks = array();
//check if we are in a subform
if ($task_id > 0 && !$obj->load($task_id)) {
    $AppUI->setMsg('Task');
    $AppUI->setMsg('invalidID', UI_MSG_ERROR, true);
    $AppUI->redirect();
}
$task_parent = isset($_REQUEST['task_parent']) ? $_REQUEST['task_parent'] : $obj->task_parent;
//check for a valid project parent
$task_project = intval($obj->task_project);
if (!$task_project) {
    $task_project = dPgetParam($_REQUEST, 'task_project', 0);
    if (!$task_project) {
        $AppUI->setMsg('badTaskProject', UI_MSG_ERROR);
        $AppUI->redirect();
    }
}
//check permissions
示例#27
0
 /**
  * Tests that the max end date based on dependencies for a task is properly returned
  */
 public function testGetDepsMaxEndDate()
 {
     /**
      * Tests when a dependency is tracked and has an end date
      */
     $task = new CTask();
     $task->load(28);
     $max_end_date = $this->obj->get_deps_max_end_date($task);
     $this->assertEquals('2009-11-02 00:00:00', $max_end_date);
     /**
      * Tests when no dependency is tracked and/or has an end date
      * so default to project start date
      */
     $task = new CTask();
     $task->load(1);
     $max_end_date = $this->obj->get_deps_max_end_date($task);
     $this->assertEquals('2009-10-10 00:00:00', $max_end_date);
 }
示例#28
0
        $AppUI->setMsg($msg, UI_MSG_ERROR);
    } else {
        $AppUI->setMsg('deleted', UI_MSG_ALERT);
    }
    $AppUI->redirect();
} else {
    $obj->task_log_costcode = cleanText($obj->task_log_costcode);
    if ($msg = $obj->store()) {
        $AppUI->setMsg($msg, UI_MSG_ERROR);
        $AppUI->redirect();
    } else {
        $AppUI->setMsg(@$_POST['task_log_id'] ? 'updated' : 'inserted', UI_MSG_OK, true);
    }
}
$task = new CTask();
$task->load($obj->task_log_task);
$task->htmlDecode();
$task->check();
$task_end_date = new CDate($task->task_end_date);
$task->task_percent_complete = dPgetParam($_POST, 'task_percent_complete', null);
if (dPgetParam($_POST, 'task_end_date', '') != '') {
    $new_date = new CDate($_POST['task_end_date']);
    $new_date->setTime($task_end_date->hour, $task_end_date->minute, $task_end_date->second);
    $task->task_end_date = $new_date->format(FMT_DATETIME_MYSQL);
}
if ($task->task_percent_complete >= 100 && (!$task->task_end_date || $task->task_end_date == '0000-00-00 00:00:00')) {
    $task->task_end_date = $obj->task_log_date;
}
if ($msg = $task->store()) {
    $AppUI->setMsg($msg, UI_MSG_ERROR, true);
}
 public function getAllTasksForPeriod($start_date, $end_date, $company_id = 0, $user_id = null)
 {
     global $AppUI;
     $q = new w2p_Database_Query();
     // convert to default db time stamp
     $db_start = $start_date->format(FMT_DATETIME_MYSQL);
     $db_end = $end_date->format(FMT_DATETIME_MYSQL);
     // Allow for possible passing of user_id 0 to stop user filtering
     if (!isset($user_id)) {
         $user_id = $AppUI->user_id;
     }
     // check permissions on projects
     $proj = new CProject();
     $task_filter_where = $proj->getAllowedSQL($AppUI->user_id, 't.task_project');
     // exclude read denied projects
     $deny = $proj->getDeniedRecords($AppUI->user_id);
     // check permissions on tasks
     $obj = new CTask();
     $allow = $obj->getAllowedSQL($AppUI->user_id, 't.task_id');
     $q->addTable('tasks', 't');
     if ($user_id) {
         $q->innerJoin('user_tasks', 'ut', 't.task_id=ut.task_id');
     }
     $q->innerJoin('projects', 'projects', 't.task_project = projects.project_id');
     $q->innerJoin('companies', 'companies', 'projects.project_company = companies.company_id');
     $q->leftJoin('project_departments', '', 'projects.project_id = project_departments.project_id');
     $q->leftJoin('departments', '', 'departments.dept_id = project_departments.department_id');
     $q->addQuery('DISTINCT t.task_id, t.task_name, t.task_start_date, t.task_end_date, t.task_percent_complete, t.task_duration' . ', t.task_duration_type, projects.project_color_identifier AS color, projects.project_name, t.task_milestone, task_description, task_type, company_name, task_access, task_owner');
     $q->addWhere('task_status > -1' . ' AND (task_start_date <= \'' . $db_end . '\'  AND t.task_percent_complete<100  OR task_end_date = \'0000-00-00 00:00:00\' OR task_end_date = NULL )');
     $q->addWhere('project_active = 1');
     if (($template_status = w2PgetConfig('template_projects_status_id')) != '') {
         $q->addWhere('project_status <> ' . $template_status);
     }
     if ($user_id) {
         $q->addWhere('ut.user_id = ' . (int) $user_id);
     }
     if ($company_id) {
         $q->addWhere('projects.project_company = ' . (int) $company_id);
     }
     if (count($task_filter_where) > 0) {
         $q->addWhere('(' . implode(' AND ', $task_filter_where) . ')');
     }
     if (count($deny) > 0) {
         $q->addWhere('(t.task_project NOT IN (' . implode(', ', $deny) . '))');
     }
     if (count($allow) > 0) {
         $q->addWhere('(' . implode(' AND ', $allow) . ')');
     }
     $q->addOrder('t.task_start_date');
     // assemble query
     $tasks = $q->loadList(-1, 'task_id');
     // check tasks access
     $result = array();
     foreach ($tasks as $key => $row) {
         $obj->load($row['task_id']);
         $canAccess = $obj->canAccess();
         if (!$canAccess) {
             continue;
         }
         $result[$key] = $row;
     }
     // execute and return
     return $result;
 }
示例#30
0
 public function getAllowedTaskList($notUsed = null, $task_project = 0, $orderby = '')
 {
     $results = array();
     $q = $this->_getQuery();
     $q->addQuery('task_id, task_name, task_parent, task_access, task_owner');
     $q->addQuery('task_start_date, task_end_date, task_percent_complete');
     $q->addQuery('task_duration, task_duration_type');
     $q->addOrder('task_parent, task_parent = task_id desc');
     $q->addTable('tasks', 't');
     if ($task_project) {
         $q->addWhere('task_project = ' . (int) $task_project);
     }
     $orderby = property_exists($this, $orderby) ? $orderby : 'task_parent, task_id desc';
     $q->addOrder($orderby);
     $task_list = $q->loadList();
     $obj = new CTask();
     foreach ($task_list as $task) {
         $obj->load($task['task_id']);
         $canAccess = $obj->canAccess();
         if ($canAccess) {
             $results[] = $task;
         }
     }
     return $results;
 }