/**
  * Edit specific milestone
  *
  * @param void
  * @return null
  */
 function edit()
 {
     $this->wireframe->print_button = false;
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     //$this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this milestone', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $this->wireframe->addPageMessage(lang('<a href=":url">Click here</a> if you wish to reschedule this project', array('url' => $this->active_milestone->getRescheduleUrl())), 'info');
     $milestone_data = $this->request->post('milestone');
     if (!is_array($milestone_data)) {
         $milestone_data = array('name' => $this->active_milestone->getName(), 'body' => $this->active_milestone->getBody(), 'start_on' => $this->active_milestone->getStartOn(), 'due_on' => $this->active_milestone->getDueOn(), 'priority' => $this->active_milestone->getPriority(), 'assignees' => Assignments::findAssignmentDataByObject($this->active_milestone), 'tags' => $this->active_milestone->getTags(), 'project_id' => $this->active_milestone->getProjectId(), 'visibility' => $this->active_milestone->getVisibility());
     }
     // if
     //BOF:mod 20121116
     $options = array();
     $options[] = array('url' => 'javascript:convert_object_to_ticket(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Ticket');
     $options[] = array('url' => 'javascript:convert_object_to_page(\'' . $this->active_milestone->getProjectId() . '\', \'' . $this->active_milestone->getId() . '\', \'' . $this->active_milestone->getType() . '\');', 'text' => 'Page');
     $this->wireframe->addPageAction(lang('Convert To'), 'javascript://', $options);
     //EOF:mod 20121116
     $this->smarty->assign('milestone_data', $milestone_data);
     //BOF: task 07 | AD
     $this->smarty->assign('is_edit_mode', '1');
     //EOF: task 07 | AD
     if ($this->request->isSubmitted()) {
         if (!isset($milestone_data['assignees'])) {
             $milestone_data['assignees'] = array(array(), 0);
         }
         // if
         db_begin_work();
         $old_name = $this->active_milestone->getName();
         //BOF: task 07 | AD
         $old_project_id = $this->active_milestone->getProjectId();
         //EOF: task 07 | AD
         $this->active_milestone->setAttributes($milestone_data);
         $save = $this->active_milestone->save();
         if ($save && !is_error($save)) {
             db_commit();
             //BOF: task 07 | AD
             //BOF: mod
             $this->active_milestone->register_departments(!empty($milestone_data['departments']) ? $milestone_data['departments'] : array(), implode(',', $milestone_data['departments']));
             //EOF: mod
             //BOF:mod 20110614
             $assignees_flag_data = $this->request->post('assignee');
             $this->active_milestone->register_assignees_flag($assignees_flag_data);
             //EOF:mod 20110614
             if ($old_project_id != $this->active_milestone->getProjectId()) {
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME, $link);
                 $query = "select id, integer_field_1 \n\t\t\t\t\t\t\tfrom healingcrystals_project_objects where \n\t\t\t\t\t\t\tmilestone_id ='" . $this->active_milestone->getId() . "' and \n\t\t\t\t\t\t\tproject_id='" . $old_project_id . "' and type='Ticket' and integer_field_1 is not null";
                 $result = mysql_query($query);
                 $next_id = Tickets::findNextTicketIdByProject($this->active_milestone->getProjectId());
                 while ($ticket = mysql_fetch_assoc($result)) {
                     mysql_query("update healingcrystals_project_objects \n\t\t\t\t\t\t\t\t\tset integer_field_1='" . $next_id . "'  \n\t\t\t\t\t\t\t\t\twhere id='" . $ticket['id'] . "'");
                     $next_id++;
                 }
                 $query = "select updated_on, updated_by_id, updated_by_name, integer_field_1 from healingcrystals_project_objects where id='" . $this->active_milestone->getId() . "'";
                 $result = mysql_query($query, $link);
                 $info = mysql_fetch_assoc($result);
                 $query = "update healingcrystals_project_objects set \n\t\t\t\t\t\t\tproject_id ='" . $this->active_milestone->getProjectId() . "', \n\t\t\t\t\t\t\tupdated_on =" . (empty($info['updated_on']) ? "null" : "'" . $info['updated_on'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_id =" . (empty($info['updated_by_id']) ? "null" : "'" . $info['updated_by_id'] . "'") . ", \n\t\t\t\t\t\t\tupdated_by_name =" . (empty($info['updated_by_name']) ? "null" : "'" . mysql_real_escape_string($info['updated_by_name']) . "'") . ", \n\t\t\t\t\t\t\tupdated_by_email =" . (empty($info['updated_by_email']) ? "null" : "'" . $info['updated_by_email'] . "'") . " \n\t\t\t\t\t\t\twhere milestone_id ='" . $this->active_milestone->getId() . "' and project_id='" . $old_project_id . "'";
                 mysql_query($query);
                 $query = "update healingcrystals_project_objects set category_id=null where id='" . $this->active_milestone->getId() . "'";
                 mysql_query($query);
                 mysql_close($link);
             }
             //EOF: task 07 | AD
             if ($this->request->getFormat() == FORMAT_HTML) {
                 //flash_success('Milestone ":name" has been updated', array('name' => $old_name), false, true);
                 flash_success('Project ":name" has been updated', array('name' => $old_name), false, true);
                 $this->redirectToUrl($this->active_milestone->getViewUrl());
             } else {
                 $this->serveData($this->active_milestone, 'milestone');
             }
             // if
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 $this->smarty->assign('errors', $save);
             } else {
                 $this->serveData($save);
             }
             // if
         }
         // if
     }
     // if
 }