function change_priority_tasks()
 {
     if ($this->request->post('priority') == '0') {
         $query = "update " . TABLE_PREFIX . "project_objects set priority='0', updated_on='" . new DateTimeValue() . "', updated_by_id='" . $this->logged_user->getId() . "' where id='" . $this->active_task->getId() . "'";
         db_execute($query);
     } else {
         $this->active_task->setPriority($this->request->post('priority'));
         $save = $this->active_task->save();
     }
 }
Exemplo n.º 2
0
 public function executeAddTask()
 {
     $project = ProjectPeer::retrieveByUuid($this->getRequestParameter('slug'));
     // TODO: make sure user is a member of project
     $this->forward404Unless($project, 'Project not found, or user is not member, unable to add task');
     $this->forward404Unless($user = sfGuardUserProfilePeer::retrieveByUuid($this->getRequestParameter('task_user'), 'Unable to retrieve user'));
     // TODO: add validation for task input
     $task = new Task();
     $task->setProjectId($project->getId());
     $task->setOwnerId($this->getUser()->getProfile()->getUserID());
     $task->setName($this->getRequestParameter('name', 'Task Name'));
     $task->setDescription($this->getRequestParameter('description', 'Task Description'));
     if ($this->getRequestParameter('begin')) {
         list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('begin'), $this->getUser()->getCulture());
         $task->setBegin("{$y}-{$m}-{$d}");
     }
     if ($this->getRequestParameter('finish')) {
         list($d, $m, $y) = sfI18N::getDateForCulture($this->getRequestParameter('finish'), $this->getUser()->getCulture());
         $task->setFinish("{$y}-{$m}-{$d}");
     }
     $task->setStatus(sfConfig::get('app_task_status_open'));
     $task->setPriority($this->getRequestParameter('priority'));
     $task->save();
     //if ($user != null) $task->addUser($user->getUserId());
     $task->addUser($user->getUserId());
     $this->redirect('@show_project_tasks?tab=tasks&project=' . $project->getSlug());
 }
 /**
  * Mark this object as completed
  *
  * @param User $by
  * @param string $comment
  * @return boolean
  */
 function complete($by, $comment = null)
 {
     if ($this->isCompleted()) {
         return true;
         // already completed
     }
     // if
     if (!instance_of($by, 'User') && !instance_of($by, 'AnonymousUser')) {
         return new InvalidParamError('by', $by, '$by is expected to be an User or AnonymousUser instance', true);
     }
     // if
     if (instance_of($this, 'Ticket')) {
         $recurring_flag = false;
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "select recurring_period, recurring_period_type from healingcrystals_project_object_misc where object_id='" . $this->getId() . "'";
         $result = mysql_query($query, $link);
         if (mysql_num_rows($result)) {
             $info = mysql_fetch_assoc($result);
             $recurring_period = $info['recurring_period'];
             $recurring_period_type = $info['recurring_period_type'];
             switch ($recurring_period_type) {
                 case 'D':
                     $recurring_period_type = 'day' . ($recurring_period == 1 ? '' : 's');
                     break;
                 case 'W':
                     $recurring_period_type = 'week' . ($recurring_period == 1 ? '' : 's');
                     break;
                 case 'M':
                     $recurring_period_type = 'month' . ($recurring_period == 1 ? '' : 's');
                     break;
                 case 'Y':
                     $recurring_period_type = 'year' . ($recurring_period == 1 ? '' : 's');
                     break;
             }
             if (!empty($recurring_period) && !empty($recurring_period_type)) {
                 $recurring_flag = true;
             }
         }
         mysql_close();
     }
     if (instance_of($this, 'Ticket') && $recurring_flag) {
         $datetime = new DateTime();
         $datetime->modify('+' . $recurring_period . ' ' . $recurring_period_type);
         $this->setDueOn($datetime->format('Y-m-d'));
         $save = $this->save();
         if ($save && !is_error($save)) {
             $activity_log = new TaskCompletedActivityLog();
             $activity_log->log($this, $by);
         }
         // if
         return $save;
     } else {
         $this->setCompletedBy($by);
         $this->setCompletedOn(new DateTimeValue());
         $save = $this->save();
         if ($save && !is_error($save)) {
             event_trigger('on_project_object_completed', array(&$this, &$by, $comment));
             $activity_log = new TaskCompletedActivityLog();
             $activity_log->log($this, $by);
             if (instance_of($this, 'Task')) {
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME);
                 $query = "select * from healingcrystals_project_object_misc where object_id='" . $this->getId() . "'";
                 $result = mysql_query($query, $link);
                 $flag_continue = true;
                 if (mysql_num_rows($result)) {
                     $info = mysql_fetch_assoc($result);
                     if (empty($info['recurring_period'])) {
                         $flag_continue = false;
                     }
                     if ($flag_continue) {
                         $recurring_period = $info['recurring_period'];
                         $recurring_period_type = $info['recurring_period_type'];
                         $recurring_period_condition = $info['recurring_period_condition'];
                         $recurring_end_date = $info['recurring_end_date'];
                         $auto_email_status = $info['auto_email_status'];
                         $email_reminder_period = $info['email_reminder_period'];
                         $email_reminder_unit = $info['email_reminder_unit'];
                         $email_reminder_time = $info['email_reminder_time'];
                         if ($recurring_period_condition == 'after_due_date') {
                             $due_date = new DateTime($this->getDueOn());
                         } else {
                             $due_date = new DateTime();
                         }
                         switch ($recurring_period_type) {
                             case 'D':
                                 $recurring_period_type = 'day' . ($recurring_period == 1 ? '' : 's');
                                 break;
                             case 'W':
                                 $recurring_period_type = 'week' . ($recurring_period == 1 ? '' : 's');
                                 break;
                             case 'M':
                                 $recurring_period_type = 'month' . ($recurring_period == 1 ? '' : 's');
                                 break;
                         }
                         $due_date->modify('+' . $recurring_period . ' ' . $recurring_period_type);
                         if (!empty($recurring_end_date) && $recurring_end_date != '0000-00-00') {
                             if (strtotime($due_date->format('Y-m-d')) - strtotime($recurring_end_date) > 0) {
                                 $flag_continue = false;
                             }
                         }
                     }
                     if ($flag_continue) {
                         $new_task = new Task();
                         $new_task->setSource($this->getSource());
                         $new_task->setType($this->getType());
                         $new_task->setModule('resources');
                         $new_task->setProjectId($this->getProjectId());
                         $new_task->setMilestoneId($this->getMilestoneId());
                         $new_task->setParentId($this->getParentId());
                         $new_task->setParentType($this->getParentType());
                         //$new_task->setName($this->getName());
                         $new_task->setBody($this->getBody());
                         $new_task->setState($this->getState());
                         $new_task->setVisibility($this->getVisibility());
                         $new_task->setPriority($this->getPriority());
                         $new_task->setCreatedOn(date('Y-m-d H:i:s'));
                         $new_task->setCreatedById($this->getCreatedById());
                         $new_task->setCreatedByName($this->getCreatedByName());
                         $new_task->setCreatedByEmail($this->getCreatedByEmail());
                         $new_task->setDueOn($due_date->format('Y-m-d'));
                         $query02 = "insert into healingcrystals_project_objects (source, type, module, project_id, milestone_id, parent_id, parent_type, body, state, visibility, priority, created_on, created_by_id, created_by_name, created_by_email, due_on) values ('{$new_task->getSource()}' , '{$new_task->getType()}', '{$new_task->getModule()}', '{$new_task->getProjectId()}', '{$new_task->getMilestoneId()}', '{$new_task->getParentId()}', '{$new_task->getParentType()}', '" . mysql_real_escape_string($new_task->getBody()) . "', '{$new_task->getState()}', '{$new_task->getVisibility()}', '{$new_task->getPriority()}', '{$new_task->getCreatedOn()}', '{$new_task->getCreatedById()}', '{$new_task->getCreatedByName()}', '{$new_task->getCreatedByEmail()}',  '{$new_task->getDueOn()}')";
                         mysql_query($query02);
                         $new_task_id = mysql_insert_id($link);
                         if ($new_task_id) {
                             $_SESSION['new_recurring_task_id'] = $new_task_id;
                             $query02 = "select * from healingcrystals_assignments where object_id='" . $this->getId() . "'";
                             $result02 = mysql_query($query02, $link);
                             if (mysql_num_rows($result02)) {
                                 $query03 = "insert into healingcrystals_assignments \n\t\t\t\t\t\t\t\t\t\t\tselect user_id, '{$new_task_id}', is_owner from healingcrystals_assignments where object_id='" . $this->getId() . "'";
                                 mysql_query($query03);
                             }
                             $query02 = "insert into healingcrystals_project_object_misc \n\t\t\t\t\t\t\t\t\t\tselect '{$new_task_id}', reminder_date, recurring_period, recurring_period_type, recurring_period_condition, recurring_end_date, now(), null, auto_email_status, email_reminder_period, email_reminder_unit, email_reminder_time, null from healingcrystals_project_object_misc where object_id='" . $this->getId() . "'";
                             mysql_query($query02);
                         }
                     }
                 }
                 $query = "select comment_id, user_id from actionrequests_to_tasklist where object_id='" . $this->getId() . "'";
                 $result = mysql_query($query);
                 if (mysql_num_rows($result)) {
                     $info = mysql_fetch_assoc($result);
                     $query = "update healingcrystals_assignments_action_request set is_action_request='-1', last_modified=now() where is_action_request='1' and user_id='" . $info['user_id'] . "' and comment_id='" . $info['comment_id'] . "'";
                     mysql_query($query);
                 }
                 //mysql_close();
             }
         }
         // if
         return $save;
     }
 }
 /**
  * Quick add checklist
  *
  * @param void
  * @return null
  */
 function quick_add()
 {
     if (!Checklist::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, lang("You don't have permission for this action"), true, true);
     }
     // if
     $this->skip_layout = true;
     $checklist_data = $this->request->post('checklist');
     if (!is_array($checklist_data)) {
         $checklist_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     //if
     $this->smarty->assign(array('checklist_data' => $checklist_data, 'quick_add_url' => assemble_url('project_checklists_quick_add', array('project_id' => $this->active_project->getId()))));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_checklist = new Checklist();
         $this->active_checklist->setAttributes($checklist_data);
         $this->active_checklist->setProjectId($this->active_project->getId());
         $this->active_checklist->setCreatedBy($this->logged_user);
         $this->active_checklist->setState(STATE_VISIBLE);
         $subscribers = array($this->logged_user->getId());
         if (is_foreachable(array_var($checklist_data['assignees'], 0))) {
             $subscribers = array_merge($subscribers, array_var($checklist_data['assignees'], 0));
         } else {
             $subscribers[] = $this->active_project->getLeaderId();
         }
         // if
         Subscriptions::subscribeUsers($subscribers, $this->active_checklist);
         $this->active_checklist->ready();
         // ready
         $save = $this->active_checklist->save();
         if ($save && !is_error($save)) {
             if (isset($checklist_data['tasks']) && is_foreachable($checklist_data['tasks'])) {
                 foreach ($checklist_data['tasks'] as $task_text) {
                     $task_text = trim($task_text);
                     if ($task_text != '') {
                         $task = new Task();
                         $task->setBody($task_text);
                         $task->setPriority(PRIORITY_NORMAL);
                         $task->setProjectId($this->active_project->getId());
                         $task->setParent($this->active_checklist);
                         $task->setCreatedBy($this->logged_user);
                         $task->setState(STATE_VISIBLE);
                         $task->setVisibility(VISIBILITY_NORMAL);
                         $task->new_assignees = $checklist_data['assignees'];
                         $task->save();
                         Subscriptions::subscribeUsers($subscribers, $task);
                         $task->ready();
                     }
                     // if
                 }
                 // if
             }
             // if
             db_commit();
             $this->smarty->assign(array('active_checklist' => $this->active_checklist, 'checklist_data' => array('visibility' => $this->active_project->getDefaultVisibility()), 'project_id' => $this->active_project->getId()));
         } else {
             db_rollback();
             $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getErrorsAsString(), true, true);
         }
         // if
     }
     // if
 }
 function importPendingEmailToTaskList(&$incoming_mail, &$project, &$user, $page_id, $comment)
 {
     //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     //mysql_select_db(DB_NAME, $link);
     //mysql_query("insert into testing (date_added, content) values (now(), 'in task list adde func:Page " . $page_id . " / comment: " . $comment->getId() . "')");
     //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($incoming_mail->getSubject()) . "')");
     //EOF:mod 20120820
     list($user_name, $priority) = explode('-', $incoming_mail->getSubject());
     $user_name = trim($user_name);
     $priority = trim($priority);
     $name_parts = explode(' ', $user_name);
     list($first_name, $last_name) = $name_parts;
     //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($priority) . "')");
     //BOF:mod 20120820
     /*
     //EOF:mod 20120820
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $query = "select id from healingcrystals_users where first_name='" . mysql_real_escape_string($first_name) . "' " . (!empty($last_name) ? " and last_name='" . mysql_real_escape_string($last_name) . "' " : "");
     $result = mysql_query($query, $link);
     if (mysql_num_rows($result)){
     		$info = mysql_fetch_assoc($result);
     		$user_id = $info['id'];
     		$task_meant_for_user = Users::findById($user_id);
     		$page_title = $task_meant_for_user->getName() . ' - Task List';
     		//echo $page_title . '<br/>';
     		$query2 = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'";
     		//echo $query2 . '<br/>';
     		$result2 = mysql_query($query2,$link);
     		if (mysql_num_rows($result2)){
     			$info2 = mysql_fetch_assoc($result2);
     			$page_id = $info2['id'];
     		} else {
     			$query3 = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'";
     			//echo $query3 . '<br/>';
     			$page_category = mysql_query($query3, $link);
     			$page_category_info = mysql_fetch_assoc($page_category);
     			$category_id = $page_category_info['id'];
     			//echo $category_id . '<br/>';
     
     			$page_data = array(
     				'type' => 'Page',
     				'module' => 'pages',
     				'visibility' => VISIBILITY_NORMAL,
     				'name' => $page_title,
     				'body' => 'Auto-generated Task List Page',
     				'integer_field_1' => '1',
     			);
     			//print_r($page_data);
     			//db_begin_work();
     			$page = new Page();
     			$page->setAttributes($page_data);
     			$page->setProjectId(TASK_LIST_PROJECT_ID);
     			$page->setCreatedBy($user);
     			$page->setState(STATE_VISIBLE);
     			$page->setParentId($category_id);
     			$page->save();
     			$page->ready();
     			$page_id = $page->getId();
     		}
     }
     mysql_close($link);
     //BOF:mod 20120820
     */
     //EOF:mod 20120820
     $task = new Task();
     $task->setProjectId($project->getId());
     $task->setParentId($page_id);
     $task->setParentType('Page');
     $task->setCreatedBy($user);
     $task->setCreatedOn($incoming_mail->getCreatedOn());
     $task->setVisibility(VISIBILITY_NORMAL);
     $task->setState(STATE_VISIBLE);
     $task->setSource(OBJECT_SOURCE_EMAIL);
     if (!empty($priority)) {
         $constant_name = 'PRIORITY_' . strtoupper(str_replace(' ', '', $priority));
         $priority_val = '';
         $priority_val_set = false;
         if (defined($constant_name)) {
             switch ($constant_name) {
                 case 'PRIORITY_HOLD':
                     $priority_val = '-4';
                     $priority_val_set = true;
                     break;
                     //BOF:mod 20121107
                     /*
                     //EOF:mod 20121107
                     case 'PRIORITY_ONGOING':
                     	$priority_val = '-3';
                     	$priority_val_set = true;
                     	break;
                     //BOF:mod 20121107
                     */
                     //EOF:mod 20121107
                 //BOF:mod 20121107
                 /*
                 //EOF:mod 20121107
                 case 'PRIORITY_ONGOING':
                 	$priority_val = '-3';
                 	$priority_val_set = true;
                 	break;
                 //BOF:mod 20121107
                 */
                 //EOF:mod 20121107
                 case 'PRIORITY_LOWEST':
                     $priority_val = '-2';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_LOW':
                     $priority_val = '-1';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_NORMAL':
                     $priority_val = '0';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_HIGH':
                     $priority_val = '1';
                     $priority_val_set = true;
                     break;
                 case 'PRIORITY_HIGHEST':
                     $priority_val = '2';
                     $priority_val_set = true;
                     break;
                     //BOF:mod 20121107
                 //BOF:mod 20121107
                 case 'PRIORITY_URGENT':
                     $priority_val = '3';
                     $priority_val_set = true;
                     break;
                     //EOF:mod 20121107
             }
             if ($priority_val_set) {
                 $task->setPriority($priority_val);
             }
         }
     }
     $task->setName($incoming_mail->getSubject());
     $amended_body = '';
     //BOF:mod 20120820
     if (empty($comment)) {
         if (strpos($incoming_mail->getSubject(), '{') !== false) {
             $amended_body .= substr($incoming_mail->getSubject(), 0, strrpos($incoming_mail->getSubject(), '{'));
         } else {
             $amended_body .= $incoming_mail->getBody();
         }
     } else {
         if (strpos($incoming_mail->getSubject(), '{') !== false) {
             $parent = $comment->getParent();
             $url = $parent->getViewUrl() . '#comment' . $comment->getId();
             $amended_body .= substr($incoming_mail->getSubject(), 0, strrpos($incoming_mail->getSubject(), '{')) . '<br/><a href="' . $url . '">View Task in Full</a>';
         } else {
             $temp_body = strip_tags($incoming_mail->getBody());
             $chars_len = strlen($temp_body);
             //if ($chars_len > 150){
             if ($chars_len > 525) {
                 //mysql_query("insert into testing (date_added, content) values (now(), 'greater than 150 block')");
                 //$url = $comment->getRealViewUrl();
                 $parent = $comment->getParent();
                 $url = $parent->getViewUrl() . '#comment' . $comment->getId();
                 //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($url) . "')");
                 //$amended_body .= substr($temp_body, 0, 150) . '.. <br/><a href="' . $url . '">View Task in Full</a>';
                 $amended_body .= substr($temp_body, 0, 525) . '.. <br/><a href="' . $url . '">View Task in Full</a>';
             } else {
                 $amended_body .= $incoming_mail->getBody();
             }
         }
         //mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($amended_body) . "')");
         $attachments = $comment->getAttachments();
         if (is_foreachable($attachments)) {
             $amended_body .= '<br/>Attachments:<br/>';
             foreach ($attachments as $attachment) {
                 $amended_body .= '<a href="' . $attachment->getViewUrl() . '">' . $attachment->getName() . '</a><br/>';
             }
         }
     }
     $task->setBody($amended_body);
     //IncomingMailImporter::attachFilesToProjectObject($incoming_mail, $task);
     $save = $task->save();
     if ($save && !is_error($save)) {
         //$subscibed_users = array($project->getLeaderId());
         //if (instance_of($user, 'User')) {
         // $subscibed_users[] = $user->getId();
         //} // if
         //Subscriptions::subscribeUsers($subscibed_users, $ticket);
         $task->ready();
         //mysql_query("insert into testing (date_added, content) values (now(), 'in task list adde func end: " . $task->getId() . "')");
         return $task;
     }
     // if
     return $save;
     //mysql_close($link);
 }