/** * Update an existing comment * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->active_comment->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_comment->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $parent = $this->active_comment->getParent(); if (!instance_of($parent, 'ProjectObject')) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if $parent->prepareProjectSectionBreadcrumb($this->wireframe); $this->wireframe->addBreadCrumb($parent->getName(), $parent->getViewUrl()); $comment_data = $this->request->post('comment'); if (!is_array($comment_data)) { $comment_data = array('body' => $this->active_comment->getBody()); } // if $this->smarty->assign('comment_data', $comment_data); //BOF:task_1260 $active_object = ProjectObjects::findById($this->active_comment->getParentId()); $this->smarty->assign('subscribers', $active_object->getSubscribers()); $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); //$query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "'"; $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "'"; $request = mysql_query($query); $fyi_users = array(); $action_request_users = array(); while ($entry = mysql_fetch_array($request)) { //BOF:mod 20130429 /* //EOF:mod 20130429 if ($entry['is_action_request']=='1'){ //BOF:mod 20130429 */ if (!empty($entry['is_action_request'])) { //EOF:mod 20130429 $action_request_users[] = $entry['user_id']; } //BOF:mod 20130429 /* //EOF:mod 20130429 if ($entry['is_fyi']=='1'){ $fyi_users[] = $entry['user_id']; } //BOF:mod 20130429 */ //EOF:mod 20130429 } $this->smarty->assign('fyi_users', $fyi_users); $this->smarty->assign('action_request_users', $action_request_users); $this->smarty->assign('logged_user', $this->logged_user); //EOF:task_1260 if ($this->request->isSubmitted()) { $this->active_comment->setAttributes($comment_data); $save = $this->active_comment->save(); if ($save && !is_error($save)) { //BOF:task_1260 //$subscribers_to_notify = array_var($comment_data, 'subscribers_to_notify'); $action_request_user_id = array_var($comment_data, 'action_request'); //mysql_query("update healingcrystals_assignments_action_request set is_action_request='0', is_fyi='0' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and is_action_request<>'-1' and is_fyi<>'-1'"); //mysql_query("update healingcrystals_assignments_action_request set is_action_request='0', is_fyi='0' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and is_action_request<>'-1' and is_fyi<>'-1'"); /*if (!empty($subscribers_to_notify)){ foreach ($subscribers_to_notify as $id){ $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query); if (mysql_num_rows($result)){ $query = "update healingcrystals_assignments_action_request set is_fyi='1' where comment_id='" . $this->active_comment->getId() . "' and selected_by_user_id='" . $this->logged_user->getId() . "' and user_id='" . $id . "'"; mysql_query($query); } else { $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '0', '1', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())"; mysql_query($query); } } }*/ $existing_ar_users = array(); $new_ar_users = array(); if (!empty($action_request_user_id)) { foreach ($action_request_user_id as $id) { $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $info = mysql_fetch_assoc($result); if ($info['is_action_request'] == '1') { $existing_ar_users[] = $id; } else { $query = "update healingcrystals_assignments_action_request set is_action_request='1' where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "'"; mysql_query($query); $new_ar_users[] = $id; } } else { $query = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added) values ('" . $id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now())"; mysql_query($query); $new_ar_users[] = $id; } } $query = "update healingcrystals_assignments_action_request set is_action_request='0' where comment_id='" . $this->active_comment->getId() . "' and user_id not in (" . implode(', ', $action_request_user_id) . ")"; mysql_query($query); } else { $query = "update healingcrystals_assignments_action_request set is_action_request='0' where comment_id='" . $this->active_comment->getId() . "'"; mysql_query($query); } mysql_query("delete from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and is_action_request='0' and is_fyi='0' and marked_for_email='0'"); //EOF:task_1260 foreach ($action_request_users as $id) { if (!in_array($id, $existing_ar_users)) { //unassign $query = "select object_id from actionrequests_to_tasklist where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "' and type='Task'"; $result = mysql_query($query); if (mysql_num_rows($result)) { $info = mysql_fetch_assoc($result); $task = new Task($info['object_id']); $task->delete(); mysql_query("delete from actionrequests_to_tasklist where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "' and type='Task'"); } } } foreach ($new_ar_users as $id) { //assign //BOF:mod 20130429 /* //EOF:mod 20130429 $priority = '0'; $query = "select * from healingcrystals_assignments_action_request where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "'"; $result = mysql_query($query, $link); if (mysql_num_rows($result)){ $query1 = "update healingcrystals_assignments_action_request set is_action_request='1', priority_actionrequest='" . $priority . "' where comment_id='" . $this->active_comment->getId() . "' and user_id='" . $id . "'"; mysql_query($query1, $link); } else { $query1 = "insert into healingcrystals_assignments_action_request (user_id, is_action_request, is_fyi, selected_by_user_id, comment_id, date_added, priority_actionrequest) values ('" . $id . "', '1', '0', '" . $this->logged_user->getId() . "', '" . $this->active_comment->getId() . "', now(), '" . $priority . "')"; mysql_query($query1, $link); } //BOF:mod 20130429 */ //EOF:mod 20130429 $task = new Task(); $task->setProjectId(TASK_LIST_PROJECT_ID); $task->setParentId(Page::getTaskPageIdForUser($id)); $task->setParentType('Page'); $task->setCreatedBy($this->logged_user); $task->setVisibility(VISIBILITY_NORMAL); $task->setState(STATE_VISIBLE); $task_body = ''; $parent = $this->active_comment->getParent(); $url = $parent->getViewUrl() . '#comment' . $this->active_comment->getId(); $comment_body = $this->active_comment->getBody(); $comment_body = strip_tags($comment_body); if (strlen($comment_body) > 525) { $task_body .= substr($comment_body, 0, 525) . '..'; } else { $task_body .= $comment_body; } $task_body .= '<br/><a href="' . $url . '">View Task in Full</a>'; $attachments = $this->active_comment->getAttachments(); if (is_foreachable($attachments)) { $task_body .= '<br/>Attachments:<br/>'; foreach ($attachments as $attachment) { $task_body .= '<a href="' . $attachment->getViewUrl() . '">' . $attachment->getName() . '</a><br/>'; } } $task->setBody($task_body); $savetask = $task->save(); if ($savetask && !is_error($savetask)) { $task->ready(); mysql_query("insert into actionrequests_to_tasklist (comment_id, user_id, type, object_id) values ('" . $this->active_comment->getId() . "', '" . $id . "', 'Task', '" . $task->getId() . "')"); } } if ($this->request->getFormat() == FORMAT_HTML) { flash_success('Comment has been updated'); $this->redirectToUrl($this->active_comment->getRealViewUrl()); } else { $this->serveData($this->active_comment, 'comment'); } // if } else { if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $save); } else { $this->serveData($save); } // if } // if } // if //BOF:task_1260 //mysql_close($link); //EOF:task_1260 }
function getTaskPageUrlForUser() { $user_id = $this->getId(); $task_page_id = Page::getTaskPageIdForUser($user_id); $page = new Page($task_page_id); return $page->getViewUrl(); }