/**
  * View the discussion
  *
  */
 function view()
 {
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     ProjectObjectViews::log($this->active_milestone, $this->logged_user);
     $total_objects = 0;
     $objects = $this->active_milestone->getObjects($this->logged_user);
     if (is_foreachable($objects)) {
         foreach ($objects as $objects_by_module) {
             $total_objects += count($objects_by_module);
         }
         // foreach
     }
     // if
     $this->smarty->assign(array('objects' => $objects, 'total_objects' => $total_objects, 'page_back_url' => assemble_url('mobile_access_view_milestones', array('project_id' => $this->active_project->getId()))));
     $this->addBreadcrumb(str_excerpt(clean($this->active_milestone->getName()), 10), mobile_access_module_get_view_url($this->active_milestone));
     $this->addBreadcrumb(lang('View'));
 }
 /**
  * Reschedule selected milestone
  *
  * @param void
  * @return null
  */
 function reschedule()
 {
     if ($this->active_milestone->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_milestone->canEdit($this->logged_user)) {
         $this->httpError($this->logged_user);
     }
     // if
     $milestone_data = $this->request->post('milestone');
     if (!is_array($milestone_data)) {
         $milestone_data = array('start_on' => $this->active_milestone->getStartOn(), 'due_on' => $this->active_milestone->getDueOn(), 'reschedule_milstone_objects' => false);
     }
     // if
     $this->smarty->assign('milestone_data', $milestone_data);
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $old_due_on = new DateValue($this->active_milestone->getDueOn());
         $new_start_on = new DateValue(array_var($milestone_data, 'start_on'));
         $new_due_on = new DateValue(array_var($milestone_data, 'due_on'));
         $reschedule_tasks = (bool) array_var($milestone_data, 'reschedule_milstone_objects');
         $successive_milestones = Milestones::findSuccessiveByMilestone($this->active_milestone, STATE_VISIBLE, $this->logged_user->getVisibility());
         // before we update timestamp
         $reschedule = $this->active_milestone->reschedule($new_start_on, $new_due_on, $reschedule_tasks);
         if ($reschedule && !is_error($reschedule)) {
             //if (instance_of($new_due_on, 'DateValue')){
             if ($new_due_on->getTimestamp() != $old_due_on->getTimestamp()) {
                 $with_successive = array_var($milestone_data, 'with_sucessive');
                 $to_move = null;
                 switch (array_var($with_successive, 'action')) {
                     case 'move_all':
                         $to_move = $successive_milestones;
                         break;
                     case 'move_selected':
                         $selected_milestones = array_var($with_successive, 'milestones');
                         if (is_foreachable($selected_milestones)) {
                             $to_move = Milestones::findByIds($selected_milestones, STATE_VISIBLE, $this->logged_user->getVisibility());
                         }
                         // if
                         break;
                 }
                 // switch
                 if (is_foreachable($to_move)) {
                     $diff = $new_due_on->getTimestamp() - $old_due_on->getTimestamp();
                     foreach ($to_move as $to_move_milestone) {
                         $milestone_start_on = $to_move_milestone->getStartOn();
                         $milestone_due_on = $to_move_milestone->getDueOn();
                         $new_milestone_start_on = $milestone_start_on->advance($diff, false);
                         $new_milestone_due_on = $milestone_due_on->advance($diff, false);
                         $to_move_milestone->reschedule($new_milestone_start_on, $new_milestone_due_on, $reschedule_tasks);
                     }
                     // foreach
                 }
                 // if
             }
             // if
             db_commit();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 //flash_success('Milestone ":name" has been updated', array('name' => $this->active_milestone->getName()), false, true);
                 flash_success('Project ":name" has been updated', array('name' => $this->active_milestone->getName()), false, true);
                 $this->redirectToUrl($this->active_milestone->getViewUrl());
             } else {
                 $this->serveData($this->active_milestone);
             }
             // if
             //}
         } else {
             db_rollback();
             if ($this->request->getFormat() == FORMAT_HTML) {
                 $this->smarty->assign('errors', $reschedule);
             } else {
                 $this->serveData($save);
             }
             // if
         }
         // if
     }
     // if
 }