/**
  * Quick add checklist
  *
  * @param void
  * @return null
  */
 function quick_add()
 {
     if (!Discussion::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;
     $discussion_data = $this->request->post('discussion');
     if (!is_array($discussion_data)) {
         $discussion_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     $this->smarty->assign(array('discussion_data' => $discussion_data, 'quick_add_url' => assemble_url('project_discussions_quick_add', array('project_id' => $this->active_project->getId()))));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_discussion = new Discussion();
         if (count($_FILES > 0)) {
             attach_from_files($this->active_discussion, $this->logged_user);
         }
         // if
         $this->active_discussion->setAttributes($discussion_data);
         $this->active_discussion->setBody(clean(array_var($discussion_data, 'body', null)));
         $this->active_discussion->setProjectId($this->active_project->getId());
         $this->active_discussion->setCreatedBy($this->logged_user);
         $this->active_discussion->setState(STATE_VISIBLE);
         $save = $this->active_discussion->save();
         if ($save && !is_error($save)) {
             $subscribers = array($this->logged_user->getId());
             if (is_foreachable($this->request->post('notify_users'))) {
                 $subscribers = array_merge($subscribers, $this->request->post('notify_users'));
             } else {
                 $subscribers[] = $this->active_project->getLeaderId();
             }
             // if
             if (!in_array($this->active_project->getLeaderId(), $subscribers)) {
                 $subscribers[] = $this->active_project->getLeaderId();
             }
             // if
             Subscriptions::subscribeUsers($subscribers, $this->active_discussion);
             db_commit();
             $this->active_discussion->ready();
             $this->smarty->assign(array('active_discussion' => $this->active_discussion, 'discussion_data' => array('visibility' => $this->active_project->getDefaultVisibility()), 'project_id' => $this->active_project->getId()));
         } else {
             db_rollback();
             $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getErrorsAsString(), true, true);
         }
         // if
     }
     // if
 }
 /**
  * Import pending email as discussion
  *
  * @param IncomingMail $incoming_mail
  * @param Project $project
  * @param User $user
  * @return Discussion
  */
 function importPendingEmailAsDiscussion(&$incoming_mail, &$project, &$user)
 {
     $discussion = new Discussion();
     $discussion->setProjectId($project->getId());
     $discussion->setCreatedBy($user);
     $discussion->setCreatedOn($incoming_mail->getCreatedOn());
     $discussion->setVisibility(VISIBILITY_NORMAL);
     $discussion->setState(STATE_VISIBLE);
     $discussion->setSource(OBJECT_SOURCE_EMAIL);
     $discussion->setName($incoming_mail->getSubject());
     $discussion->setBody($incoming_mail->getBody());
     IncomingMailImporter::attachFilesToProjectObject($incoming_mail, $discussion);
     $save = $discussion->save();
     if ($save && !is_error($save)) {
         $subscibed_users = array($project->getLeaderId());
         if (instance_of($user, 'User')) {
             $subscibed_users[] = $user->getId();
         }
         // if
         Subscriptions::subscribeUsers($subscibed_users, $discussion);
         $discussion->ready();
         return $discussion;
     }
     // if
     return $save;
 }