/**
  * Quick add checklist
  *
  * @param void
  * @return null
  */
 function quick_add()
 {
     if (!Checklist::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;
     $checklist_data = $this->request->post('checklist');
     if (!is_array($checklist_data)) {
         $checklist_data = array('visibility' => $this->active_project->getDefaultVisibility());
     }
     //if
     $this->smarty->assign(array('checklist_data' => $checklist_data, 'quick_add_url' => assemble_url('project_checklists_quick_add', array('project_id' => $this->active_project->getId()))));
     if ($this->request->isSubmitted()) {
         db_begin_work();
         $this->active_checklist = new Checklist();
         $this->active_checklist->setAttributes($checklist_data);
         $this->active_checklist->setProjectId($this->active_project->getId());
         $this->active_checklist->setCreatedBy($this->logged_user);
         $this->active_checklist->setState(STATE_VISIBLE);
         $subscribers = array($this->logged_user->getId());
         if (is_foreachable(array_var($checklist_data['assignees'], 0))) {
             $subscribers = array_merge($subscribers, array_var($checklist_data['assignees'], 0));
         } else {
             $subscribers[] = $this->active_project->getLeaderId();
         }
         // if
         Subscriptions::subscribeUsers($subscribers, $this->active_checklist);
         $this->active_checklist->ready();
         // ready
         $save = $this->active_checklist->save();
         if ($save && !is_error($save)) {
             if (isset($checklist_data['tasks']) && is_foreachable($checklist_data['tasks'])) {
                 foreach ($checklist_data['tasks'] as $task_text) {
                     $task_text = trim($task_text);
                     if ($task_text != '') {
                         $task = new Task();
                         $task->setBody($task_text);
                         $task->setPriority(PRIORITY_NORMAL);
                         $task->setProjectId($this->active_project->getId());
                         $task->setParent($this->active_checklist);
                         $task->setCreatedBy($this->logged_user);
                         $task->setState(STATE_VISIBLE);
                         $task->setVisibility(VISIBILITY_NORMAL);
                         $task->new_assignees = $checklist_data['assignees'];
                         $task->save();
                         Subscriptions::subscribeUsers($subscribers, $task);
                         $task->ready();
                     }
                     // if
                 }
                 // if
             }
             // if
             db_commit();
             $this->smarty->assign(array('active_checklist' => $this->active_checklist, 'checklist_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
 }