Example #1
0
 /**
  * Method used to add a new project to the system.
  *
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 public static function insert()
 {
     if (Validation::isWhitespace($_POST['title'])) {
         return -2;
     }
     $stmt = 'INSERT INTO
                 {{%project}}
              (
                 prj_created_date,
                 prj_title,
                 prj_status,
                 prj_lead_usr_id,
                 prj_initial_sta_id,
                 prj_outgoing_sender_name,
                 prj_outgoing_sender_email,
                 prj_mail_aliases,
                 prj_remote_invocation,
                 prj_customer_backend,
                 prj_workflow_backend
              ) VALUES (
                  ?, ?, ?, ?, ?,
                  ?, ?, ?, ?, ?, ?
              )';
     try {
         DB_Helper::getInstance()->query($stmt, array(Date_Helper::getCurrentDateGMT(), $_POST['title'], $_POST['status'], $_POST['lead_usr_id'], $_POST['initial_status'], $_POST['outgoing_sender_name'], $_POST['outgoing_sender_email'], $_POST['mail_aliases'], $_POST['remote_invocation'], $_POST['customer_backend'], $_POST['workflow_backend']));
     } catch (DbException $e) {
         return -1;
     }
     $new_prj_id = DB_Helper::get_last_insert_id();
     foreach ($_POST['users'] as $user) {
         if ($user == $_POST['lead_usr_id']) {
             $role_id = User::getRoleID('Manager');
         } else {
             $role_id = User::getRoleID('Standard User');
         }
         self::associateUser($new_prj_id, $user, $role_id);
     }
     foreach ($_POST['statuses'] as $sta_id) {
         Status::addProjectAssociation($sta_id, $new_prj_id);
     }
     Display_Column::setupNewProject($new_prj_id);
     // insert default timetracking categories
     Time_Tracking::addProjectDefaults($new_prj_id);
     return 1;
 }
Example #2
0
 /**
  * Method used to add a new project to the system.
  *
  * @access  public
  * @return  integer 1 if the update worked, -1 or -2 otherwise
  */
 function insert()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     $stmt = "INSERT INTO\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "project\n                 (\n                    prj_created_date,\n                    prj_title,\n                    prj_status,\n                    prj_lead_usr_id,\n                    prj_initial_sta_id,\n                    prj_outgoing_sender_name,\n                    prj_outgoing_sender_email,\n                    prj_remote_invocation,\n                    prj_customer_backend,\n                    prj_workflow_backend\n                 ) VALUES (\n                    '" . Date_API::getCurrentDateGMT() . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["status"]) . "',\n                    " . Misc::escapeInteger($HTTP_POST_VARS["lead_usr_id"]) . ",\n                    " . Misc::escapeInteger($HTTP_POST_VARS["initial_status"]) . ",\n                    '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_name"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["outgoing_sender_email"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["remote_invocation"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["customer_backend"]) . "',\n                    '" . Misc::escapeString($HTTP_POST_VARS["workflow_backend"]) . "'\n                 )";
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         $new_prj_id = $GLOBALS["db_api"]->get_last_insert_id();
         for ($i = 0; $i < count($HTTP_POST_VARS["users"]); $i++) {
             if ($HTTP_POST_VARS["users"][$i] == $HTTP_POST_VARS["lead_usr_id"]) {
                 $role_id = User::getRoleID("Manager");
             } else {
                 $role_id = User::getRoleID("Standard User");
             }
             Project::associateUser($new_prj_id, $HTTP_POST_VARS["users"][$i], $role_id);
         }
         foreach ($HTTP_POST_VARS['statuses'] as $sta_id) {
             Status::addProjectAssociation($sta_id, $new_prj_id);
         }
         Display_Column::setupNewProject($new_prj_id);
         return 1;
     }
 }
Example #3
0
 /**
  * Method used to update the details of a given custom status.
  *
  * @access  public
  * @return  integer 1 if the update worked properly, any other value otherwise
  */
 function update()
 {
     global $HTTP_POST_VARS;
     if (Validation::isWhitespace($HTTP_POST_VARS["title"])) {
         return -2;
     }
     $stmt = "UPDATE\n                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "status\n                 SET\n                    sta_title='" . Misc::escapeString($HTTP_POST_VARS["title"]) . "',\n                    sta_abbreviation='" . Misc::escapeString($HTTP_POST_VARS["abbreviation"]) . "',\n                    sta_rank=" . Misc::escapeInteger($HTTP_POST_VARS['rank']) . ",\n                    sta_color='" . Misc::escapeString($HTTP_POST_VARS["color"]) . "',\n                    sta_is_closed=" . Misc::escapeInteger($HTTP_POST_VARS['is_closed']) . "\n                 WHERE\n                    sta_id=" . Misc::escapeInteger($HTTP_POST_VARS["id"]);
     $res = $GLOBALS["db_api"]->dbh->query($stmt);
     if (PEAR::isError($res)) {
         Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         return -1;
     } else {
         $projects = Status::getAssociatedProjects($HTTP_POST_VARS['id']);
         $current_projects = array_keys($projects);
         // remove all of the associations with projects, then add them all again
         Status::removeProjectAssociations($HTTP_POST_VARS['id']);
         foreach ($HTTP_POST_VARS['projects'] as $prj_id) {
             Status::addProjectAssociation($HTTP_POST_VARS['id'], $prj_id);
         }
         // need to update all issues that are not supposed to have the changed sta_id to '0'
         $removed_projects = array();
         foreach ($current_projects as $project_id) {
             if (!in_array($project_id, $HTTP_POST_VARS['projects'])) {
                 $removed_projects[] = $project_id;
             }
         }
         if (count($removed_projects) > 0) {
             $stmt = "UPDATE\n                            " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue\n                         SET\n                            iss_sta_id=0\n                         WHERE\n                            iss_sta_id=" . Misc::escapeInteger($HTTP_POST_VARS['id']) . " AND\n                            iss_prj_id IN (" . implode(', ', $removed_projects) . ")";
             $res = $GLOBALS["db_api"]->dbh->query($stmt);
             if (PEAR::isError($res)) {
                 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
             }
         }
         return 1;
     }
 }