Пример #1
0
 function multi_task_action()
 {
     ajx_current("empty");
     $ids = explode(',', array_var($_POST, 'ids'));
     $action = array_var($_POST, 'action');
     $options = array_var($_POST, 'options');
     if (!is_array($ids) || trim(array_var($_POST, 'ids')) == '' || count($ids) <= 0) {
         flash_error(lang('no items selected'));
         return;
     }
     $count_tasks = ProjectTasks::count('object_id in (' . implode(',', $ids) . ')');
     $tasksToReturn = array();
     $showSuccessMessage = true;
     try {
         DB::beginWork();
         foreach ($ids as $id) {
             $task = Objects::findObject($id);
             switch ($action) {
                 case 'complete':
                     if ($task->canEdit(logged_user())) {
                         $task->completeTask($options);
                         // if task is repetitive, generate a complete instance of this task and modify repeat values
                         if ($task->isRepetitive()) {
                             $complete_last_task = false;
                             // calculate next repetition date
                             $opt_rep_day = array('saturday' => false, 'sunday' => false);
                             $new_dates = $this->getNextRepetitionDates($task, $opt_rep_day, $new_st_date, $new_due_date);
                             // if this is the last task of the repetetition, complete it, do not generate a new instance
                             if ($task->getRepeatNum() > 0) {
                                 $task->setRepeatNum($task->getRepeatNum() - 1);
                                 if ($task->getRepeatNum() == 0) {
                                     $complete_last_task = true;
                                 }
                             }
                             if (!$complete_last_task && $task->getRepeatEnd() instanceof DateTimeValue) {
                                 if ($task->getRepeatBy() == 'start_date' && array_var($new_dates, 'st') > $task->getRepeatEnd() || $task->getRepeatBy() == 'due_date' && array_var($new_dates, 'due') > $task->getRepeatEnd()) {
                                     $complete_last_task = true;
                                 }
                             }
                             if (!$complete_last_task) {
                                 // generate new pending task
                                 $new_task = $task->cloneTask(array_var($new_dates, 'st'), array_var($new_dates, 'due'));
                                 $reload_view = true;
                             }
                         }
                         $tasksToReturn[] = $task->getArrayInfo();
                     }
                     break;
                 case 'delete':
                     if ($task->canDelete(logged_user())) {
                         $tasksToReturn[] = array('id' => $task->getId());
                         $task->trash();
                         ApplicationLogs::createLog($task, ApplicationLogs::ACTION_TRASH);
                         if ($options == "news" || $options == "all") {
                             $tasksToReturn_related = $this->repetitive_tasks_related($task, "delete", $options);
                             foreach ($tasksToReturn_related as $tasksToReturn_rel) {
                                 $tasksToReturn[] = array('id' => $tasksToReturn_rel);
                             }
                         }
                     }
                     break;
                 case 'archive':
                     if ($task->canEdit(logged_user())) {
                         $tasksToReturn[] = $task->getArrayInfo();
                         $task->archive();
                         ApplicationLogs::createLog($task, ApplicationLogs::ACTION_ARCHIVE);
                         if ($options == "news" || $options == "all") {
                             $tasksToReturn_related = $this->repetitive_tasks_related($task, "archive", $options);
                             foreach ($tasksToReturn_related as $tasksToReturn_rel) {
                                 $tasksToReturn[] = array('id' => $tasksToReturn_rel);
                             }
                         }
                     }
                     break;
                 case 'start_work':
                     if ($task->canEdit(logged_user())) {
                         $task->addTimeslot(logged_user());
                         ApplicationLogs::createLog($task, ApplicationLogs::ACTION_EDIT, false, true);
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'close_work':
                     if ($task->canEdit(logged_user())) {
                         $task->closeTimeslots(logged_user(), array_var($_POST, 'options'));
                         ApplicationLogs::createLog($task, ApplicationLogs::ACTION_EDIT, false, true);
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'pause_work':
                     if ($task->canEdit(logged_user())) {
                         $task->pauseTimeslots(logged_user());
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'resume_work':
                     if ($task->canEdit(logged_user())) {
                         $task->resumeTimeslots(logged_user());
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'markasread':
                     $task->setIsRead(logged_user()->getId(), true);
                     $tasksToReturn[] = $task->getArrayInfo();
                     $showSuccessMessage = false;
                     break;
                 case 'markasunread':
                     $task->setIsRead(logged_user()->getId(), false);
                     $tasksToReturn[] = $task->getArrayInfo();
                     $showSuccessMessage = false;
                     break;
                 default:
                     DB::rollback();
                     flash_error(lang('invalid action'));
                     return;
             }
             // end switch
         }
         // end foreach
         DB::commit();
         if (count($tasksToReturn) < $count_tasks) {
             flash_error(lang('tasks updated') . '. ' . lang('some tasks could not be updated due to permission restrictions'));
         } else {
             if ($showSuccessMessage) {
                 flash_success(lang('tasks updated'));
             }
         }
         ajx_extra_data(array('tasks' => $tasksToReturn));
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
     }
 }
 /**
  * Return number of completed tasks
  *
  * @access public
  * @param void
  * @return integer
  */
 function countCompletedTasks()
 {
     if (is_null($this->count_completed_tasks)) {
         if (is_array($this->completed_tasks)) {
             $this->count_completed_tasks = count($this->completed_tasks);
         } else {
             $this->count_completed_tasks = ProjectTasks::count('`task_list_id` = ' . DB::escape($this->getId()) . ' AND `completed_on` > ' . DB::escape(EMPTY_DATETIME));
         }
         // if
     }
     // if
     return $this->count_completed_tasks;
 }
  <?php 
    echo lang('new account step start workspace info', '<span class="ico-workspace-add" style="padding: 5px 16px 0 0">&nbsp;</span>', logged_user()->getPersonalProject()->getName());
    ?>
<br/><br/>
<?php 
}
$step++;
?>
  

<b><?php 
echo lang('new account step actions', $step);
?>
</b>
	<?php 
$task_count = ProjectTasks::count('`created_by_id` = ' . logged_user()->getId());
$note_count = ProjectMessages::count('`created_by_id` = ' . logged_user()->getId());
//$contact = ProjectContacts::findOne(array('conditions'=>'created_by_id='.logged_user()->getId()));
if ($task_count > 0 || $note_count > 0) {
    echo '<img src="' . image_url('16x16/complete.png') . '" />';
}
?>
<br/>
<?php 
echo lang('new account step actions info');
?>
<br/>

<span class="ico-message" style="padding: 5px 16px 0 0">&nbsp;</span>
<a class='internalLink dashboard-link' href='<?php 
echo get_url('message', 'add');
Пример #4
0
 function multi_task_action()
 {
     ajx_current("empty");
     $ids = explode(',', array_var($_POST, 'ids'));
     $action = array_var($_POST, 'action');
     $options = array_var($_POST, 'options');
     if (!is_array($ids) || trim(array_var($_POST, 'ids')) == '' || count($ids) <= 0) {
         flash_error(lang('no items selected'));
         return;
     }
     $count_tasks = ProjectTasks::count('object_id in (' . implode(',', $ids) . ')');
     $tasksToReturn = array();
     $subt_info = array();
     $showSuccessMessage = true;
     $application_logs = array();
     try {
         DB::beginWork();
         $all_tasks = array();
         foreach ($ids as $id) {
             $task = Objects::findObject($id);
             $task->setDontMakeCalculations(true);
             // all the calculations should be after all tasks are saved
             $all_tasks[] = $task;
             switch ($action) {
                 case 'complete':
                     if ($task->canEdit(logged_user())) {
                         $log_info = $task->completeTask($options);
                         $application_logs[] = array($task, ApplicationLogs::ACTION_CLOSE, false, false, true, substr($log_info, 0, -1));
                         // if task is repetitive, generate a complete instance of this task and modify repeat values
                         if ($task->isRepetitive()) {
                             $complete_last_task = false;
                             // calculate next repetition date
                             $opt_rep_day = array('saturday' => false, 'sunday' => false);
                             $new_dates = $this->getNextRepetitionDates($task, $opt_rep_day, $new_st_date, $new_due_date);
                             // if this is the last task of the repetetition, complete it, do not generate a new instance
                             if ($task->getRepeatNum() > 0) {
                                 $task->setRepeatNum($task->getRepeatNum() - 1);
                                 if ($task->getRepeatNum() == 0) {
                                     $complete_last_task = true;
                                 }
                             }
                             if (!$complete_last_task && $task->getRepeatEnd() instanceof DateTimeValue) {
                                 if ($task->getRepeatBy() == 'start_date' && array_var($new_dates, 'st') > $task->getRepeatEnd() || $task->getRepeatBy() == 'due_date' && array_var($new_dates, 'due') > $task->getRepeatEnd()) {
                                     $complete_last_task = true;
                                 }
                             }
                             if (!$complete_last_task) {
                                 // generate new pending task
                                 $new_task = $task->cloneTask(array_var($new_dates, 'st'), array_var($new_dates, 'due'));
                                 $reload_view = true;
                             }
                         }
                         foreach ($task->getAllSubTasks() as $sub) {
                             $tasksToReturn[] = $sub->getArrayInfo();
                         }
                         $tasksToReturn[] = $task->getArrayInfo();
                     }
                     break;
                 case 'delete':
                     if ($task->canDelete(logged_user())) {
                         $tasksToReturn[] = $task->getArrayInfo();
                         $task->trash();
                         $application_logs[] = array($task, ApplicationLogs::ACTION_TRASH);
                         if ($options == "news" || $options == "all") {
                             $tasksToReturn_related = $this->repetitive_tasks_related($task, "delete", $options);
                             foreach ($tasksToReturn_related as $tasksToReturn_rel) {
                                 $tasksToReturn[] = array('id' => $tasksToReturn_rel);
                             }
                         }
                     }
                     break;
                 case 'archive':
                     if ($task->canEdit(logged_user())) {
                         $tasksToReturn[] = $task->getArrayInfo();
                         $task->archive();
                         $application_logs[] = array($task, ApplicationLogs::ACTION_ARCHIVE);
                         if ($options == "news" || $options == "all") {
                             $tasksToReturn_related = $this->repetitive_tasks_related($task, "archive", $options);
                             foreach ($tasksToReturn_related as $tasksToReturn_rel) {
                                 $tasksToReturn[] = array('id' => $tasksToReturn_rel);
                             }
                         }
                     }
                     break;
                 case 'start_work':
                     if ($task->canAddTimeslot(logged_user())) {
                         $timeslot = $task->addTimeslot(logged_user());
                         $application_logs[] = array($timeslot, ApplicationLogs::ACTION_OPEN, false, true);
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'close_work':
                     if ($task->canAddTimeslot(logged_user())) {
                         $timeslot = $task->closeTimeslots(logged_user(), array_var($_POST, 'options'));
                         $application_logs[] = array($timeslot, ApplicationLogs::ACTION_CLOSE, false, true);
                         $showSuccessMessage = false;
                         $task->calculatePercentComplete();
                         $tasksToReturn[] = $task->getArrayInfo();
                     }
                     break;
                 case 'pause_work':
                     if ($task->canAddTimeslot(logged_user())) {
                         $task->pauseTimeslots(logged_user());
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'resume_work':
                     if ($task->canAddTimeslot(logged_user())) {
                         $task->resumeTimeslots(logged_user());
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'push_tasks_dates':
                     if ($task->canEdit(logged_user())) {
                         $time_push = 0;
                         $time = array_var($_POST, 'time');
                         if (isset($time["days"]) && (int) $time["days"] > 0) {
                             $time_push = (int) $time["days"] * 24;
                         }
                         if (config_option('use_time_in_task_dates')) {
                             if (isset($time["hours"]) && (int) $time["hours"] > 0) {
                                 $time_push += (int) $time["hours"];
                             }
                         }
                         if (user_config_option('pushUseWorkingDays') != isset($time["use_only_working_days"])) {
                             set_user_config_option('pushUseWorkingDays', $time["use_only_working_days"], logged_user()->getId());
                         }
                         if ($time_push > 0) {
                             $dd = $task->getDueDate() instanceof DateTimeValue ? $task->getDueDate() : null;
                             $sd = $task->getStartDate() instanceof DateTimeValue ? $task->getStartDate() : null;
                             if ($dd) {
                                 $time_push_dd = $time_push;
                                 Hook::fire('task_push_dates_calculation', array('date' => $dd, 'only_working_days' => $time["use_only_working_days"]), $time_push_dd);
                                 $task->setDueDate($dd->advance($time_push_dd * 3600, false));
                             }
                             if ($sd) {
                                 $time_push_sd = $time_push;
                                 Hook::fire('task_push_dates_calculation', array('date' => $sd, 'only_working_days' => $time["use_only_working_days"]), $time_push_sd);
                                 $task->setStartDate($sd->advance($time_push_sd * 3600, false));
                             }
                         }
                         $task->save();
                         $tasksToReturn[] = $task->getArrayInfo();
                         $showSuccessMessage = false;
                     }
                     break;
                 case 'markasread':
                     $task->setIsRead(logged_user()->getId(), true);
                     $tasksToReturn[] = $task->getArrayInfo();
                     $showSuccessMessage = false;
                     break;
                 case 'markasunread':
                     $task->setIsRead(logged_user()->getId(), false);
                     $tasksToReturn[] = $task->getArrayInfo();
                     $showSuccessMessage = false;
                     break;
                 default:
                     //DB::rollback();
                     flash_error(lang('invalid action'));
                     return;
             }
             // end switch
         }
         // end foreach
         $ignored = null;
         Hook::fire('after_multi_object_action', array('objects' => $all_tasks, 'action' => $action, 'options' => $options), $ignored);
         DB::commit();
         foreach ($application_logs as $log) {
             if (count($log) >= 2 && $log[0] instanceof ApplicationDataObject) {
                 call_user_func_array('ApplicationLogs::createLog', $log);
             }
         }
         if (count($tasksToReturn) < $count_tasks) {
             flash_error(lang('tasks updated') . '. ' . lang('some tasks could not be updated due to permission restrictions'));
         } else {
             if ($showSuccessMessage) {
                 flash_success(lang('tasks updated'));
             }
         }
         if (count($subt_info) > 0) {
             ajx_extra_data(array("tasks" => $tasksToReturn, 'subtasks' => $subt_info));
         } else {
             ajx_extra_data(array('tasks' => $tasksToReturn));
         }
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
     }
 }
 function getArrayInfo()
 {
     $tnum = ProjectTasks::count('milestone_id = ' . $this->getId() . " AND `trashed_on` = " . DB::escape(EMPTY_DATETIME));
     $tc = ProjectTasks::count('milestone_id = ' . $this->getId() . ' and completed_on > ' . DB::escape(EMPTY_DATETIME) . ' AND `trashed_on` = ' . DB::escape(EMPTY_DATETIME));
     $result = array('id' => $this->getId(), 't' => $this->getTitle(), 'wsid' => $this->getWorkspacesIdsCSV(), 'tnum' => $tnum, 'tc' => $tc, 'dd' => $this->getDueDate()->getTimestamp());
     $tags = $this->getTagNames();
     if ($tags) {
         $result['tags'] = $tags;
     }
     if ($this->getCompletedById() > 0) {
         $result['compId'] = $this->getCompletedById();
         $result['compOn'] = $this->getCompletedOn()->getTimestamp();
     }
     $result['is_urgent'] = $this->getIsUrgent();
     return $result;
 }