/** * Show and process edit page form. Also, handle all other page update * requests * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->active_page->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_page->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if //BOF:mod 20110615 $subscribers = $this->active_page->getSubscribers(); $notify_users = array(array(), null); foreach ($subscribers as $subscriber) { $notify_users[0][] = $subscriber->getId(); } $this->smarty->assign('notify_users', $notify_users); //EOF:mod 20110615 $page_data = $this->request->post('page'); if (!is_array($page_data)) { $page_data = array('name' => $this->active_page->getName(), 'body' => $this->active_page->getBody(), 'visibility' => $this->active_page->getVisibility(), 'parent_id' => $this->active_page->getParentId(), 'milestone_id' => $this->active_page->getMilestoneId(), 'tags' => $this->active_page->getTags()); } // if //BOF:mod 20110519 //$subscribers = $this->active_page->getSubscribers(); //$page_data['subscribers'] = $subscribers; //EOF:mod 20110519 //BOF:mod 20121116 $options = array(); $options[] = array('url' => 'javascript:convert_object_to_milestone(\'' . $this->active_page->getProjectId() . '\', \'' . $this->active_page->getId() . '\', \'' . $this->active_page->getType() . '\');', 'text' => 'Milestone'); $options[] = array('url' => 'javascript:convert_object_to_ticket(\'' . $this->active_page->getProjectId() . '\', \'' . $this->active_page->getId() . '\', \'' . $this->active_page->getType() . '\');', 'text' => 'Ticket'); $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options); //EOF:mod 20121116 $this->smarty->assign(array('page_data' => $page_data)); if ($this->request->isSubmitted()) { db_begin_work(); $old_page_name = $this->active_page->getName(); $old_page_body = $this->active_page->getBody(); $this->active_page->setAttributes($page_data); $new_version = null; $error = null; // Create a new version if (!array_var($page_data, 'is_minor_revision', false) && ($this->active_page->getName() != $old_page_name || $this->active_page->getBody() != $old_page_body)) { $new_version = $this->active_page->createVersion($this->logged_user); if (is_error($new_version)) { $error = $new_version; } // if } // if // Update page properties if we don't have an error already if (!is_error($error)) { //BOF:mod 20121122 if (!empty($page_data['new_team_id']) && $page_data['new_team_id'] != $this->active_project->getId()) { $this->active_page->setProjectId($page_data['new_team_id']); } //EOF:mod 20121122 $save = $this->active_page->save(); if (is_error($save)) { $error = $save; } // if } // if if (!is_error($error)) { if ($new_version) { //BOF:mod 20010519 /* //EOF:mod 20010519 event_trigger('on_new_revision', array(&$this->active_page, &$new_version, &$this->logged_user)); //BOF:mod 20010519 */ /*if ($page_data['subscribers_to_notify']){ $link = mysql_connect(DB_HOST, DB_USER, DB_PASS); mysql_select_db(DB_NAME); foreach($page_data['subscribers_to_notify'] as $fyi_user_id){ $query = "insert into healingcrystals_project_objects_to_fyi_users (fyi_user_id, selected_by_user_id, object_id) values ('" . $fyi_user_id . "', '" . $this->logged_user->getId() . "', '" . $this->active_page->getId() . "')"; mysql_query($query); } mysql_close($link); }*/ //EOF:mod 20010519 $activity_log = new NewPageVersionActivityLog(); $activity_log->log($this->active_page, $this->logged_user); } // if //BOF:mod 20110614 $subscribers = $this->request->post('notify_users'); if (!in_array($this->active_project->getLeaderId(), $subscribers)) { $subscribers[] = $this->active_project->getLeaderId(); } // if Subscriptions::subscribeUsers($subscribers, $this->active_page); //EOF:mod 20110614 //Subscriptions::subscribe($this->logged_user, $this->active_page); db_commit(); //BOF: mod $this->active_page->register_departments(!empty($page_data['departments']) ? $page_data['departments'] : array()); //EOF: mod //BOF:mod 20110614 $assignees_flag_data = $this->request->post('assignee'); $this->active_page->register_assignees_flag($assignees_flag_data); //EOF:mod 20110614 if ($this->request->getFormat() == FORMAT_HTML) { flash_success('Page ":name" has been updated', array('name' => $old_page_name)); $this->redirectToUrl($this->active_page->getViewUrl()); } else { $this->serveData($this->active_page, 'page'); } // if } else { db_rollback(); if ($this->request->getFormat() == FORMAT_HTML) { $this->smarty->assign('errors', $error); } else { $this->serveData($error); } // if } // if } // if }