/**
  * Create a new checklist
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->wireframe->print_button = false;
     if ($this->request->isApiCall() && !$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
     if (!Checklist::canAdd($this->logged_user, $this->active_project)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $checklist_data = $this->request->post('checklist');
     if (!is_array($checklist_data)) {
         $checklist_data = array('milestone_id' => $this->request->get('milestone_id'), 'visibility' => $this->active_project->getDefaultVisibility());
     }
     // if
     $this->smarty->assign('checklist_data', $checklist_data);
     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());
         if (trim($this->active_checklist->getCreatedByName()) == '' || trim($this->active_checklist->getCreatedByEmail()) == '') {
             $this->active_checklist->setCreatedBy($this->logged_user);
         }
         // if
         $this->active_checklist->setState(STATE_VISIBLE);
         $save = $this->active_checklist->save();
         if ($save && !is_error($save)) {
             db_commit();
             $this->active_checklist->ready();
             // ready
             //BOF: mod
             $this->active_checklist->register_departments(!empty($checklist_data['departments']) ? $checklist_data['departments'] : array());
             //EOF: mod
             //BOF:mod 20110615
             $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_checklist);
             $assignees_flag_data = $this->request->post('assignee');
             $this->active_checklist->register_assignees_flag($assignees_flag_data);
             //EOF:mod 20110615
             if ($this->request->isApiCall()) {
                 $this->serveData($this->active_checklist, 'checklist');
             } else {
                 flash_success('Checklist :name has been added', array('name' => $this->active_checklist->getName()));
                 $this->redirectToUrl($this->active_checklist->getViewUrl());
             }
             // if
         } else {
             db_rollback();
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 $this->smarty->assign('errors', $save);
             }
             // if
         }
         // if
     }
     // if
 }