/**
  * Quick add milestone
  *
  * @param void
  * @return null
  */
 function quick_add()
 {
     if (!Milestone::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;
     $milestone_data = $this->request->post('milestone');
     if (!is_array($milestone_data)) {
         $milestone_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     $this->smarty->assign(array('milestone_data' => $milestone_data, 'quick_add_url' => assemble_url('project_milestones_quick_add', array('project_id' => $this->active_project->getId()))));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_milestone = new Milestone();
         $this->active_milestone->setAttributes($milestone_data);
         if (!isset($milestone_data['priority'])) {
             $this->active_milestone->setPriority(PRIORITY_NORMAL);
         }
         // if
         $this->active_milestone->setProjectId($this->active_project->getId());
         $this->active_milestone->setCreatedBy($this->logged_user);
         $this->active_milestone->setState(STATE_VISIBLE);
         $this->active_milestone->setVisibility(VISIBILITY_NORMAL);
         $save = $this->active_milestone->save();
         if ($save && !is_error($save)) {
             $subscribers = array($this->logged_user->getId());
             if (is_foreachable(array_var($milestone_data['assignees'], 0))) {
                 $subscribers = array_merge($subscribers, array_var($milestone_data['assignees'], 0));
             } else {
                 $subscribers[] = $this->active_project->getLeaderId();
             }
             // if
             Subscriptions::subscribeUsers($subscribers, $this->active_milestone);
             db_commit();
             $this->active_milestone->ready();
             $this->smarty->assign(array('active_milestone' => $this->active_milestone, 'milestone_data' => array('visibility' => $this->active_project->getDefaultVisibility()), 'project_id' => $this->active_project->getId()));
             $this->skip_layout = true;
         } else {
             db_rollback();
             $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getErrorsAsString(), true, true);
         }
         // if
     }
     // if
 }
 function convertToMilestone(&$logged_user, &$error)
 {
     db_begin_work();
     $milestone = new Milestone();
     $milestone->setProjectId($this->getProjectId());
     $milestone->setName($this->getName());
     $milestone->setBody($this->getBody());
     $milestone->setState($this->getState());
     $milestone->setVisibility($this->getVisibility());
     $milestone->setPriority($this->getPriority());
     $milestone->setCommentsCount($this->getCommentsCount());
     $milestone->setIsLocked($this->getIsLocked());
     $milestone->setCreatedById($logged_user->getId());
     $milestone->setCreatedByName($logged_user->getName());
     $milestone->setCreatedByEmail($logged_user->getEmail());
     $save = $milestone->save();
     if ($save && !is_error($save)) {
         db_commit();
         $milestone->ready();
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "update healingcrystals_project_objects set parent_id='" . $milestone->getId() . "', parent_type='Milestone' where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type in ('Comment', 'Task')";
         mysql_query($query);
         $query = "update healingcrystals_project_objects set parent_id=null, parent_type=null where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type not in ('Comment', 'Task')";
         mysql_query($query);
         $query = "select * from healingcrystals_assignments where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert into healingcrystals_assignments (user_id, object_id, is_owner) values ('" . $entry['user_id'] . "', '" . $milestone->getId() . "', '" . $entry['is_owner'] . "')";
             mysql_query($query);
         }
         $query = "select * from healingcrystals_project_object_categories where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert ignore into healingcrystals_project_object_categories (object_id, category_id) values ('" . $milestone->getId() . "', '" . $entry['category_id'] . "')";
             mysql_query($query);
         }
         mysql_close($link);
         $this->moveToTrash();
         return $milestone->getId();
     } else {
         db_rollback();
         $error = $save;
         return '';
     }
 }