Exemple #1
0
 public function update($args = NULL, $update_modifier = true, $log_changes = true)
 {
     global $auth;
     global $g_item_fields;
     $dbh = new DB_Mysql();
     $update_fields = NULL;
     ### build hash to fast access ##
     if ($args) {
         $update_fields = array();
         foreach ($args as $a) {
             $update_fields[$a] = true;
         }
     }
     if (!$this->id) {
         trigger_error("User object without id can't be updated", E_USER_WARNING);
     }
     if (!sizeof($this->field_states)) {
         trigger_error("need members to update to database. e.g. 'firstname,lastname,data'", E_USER_WARNING);
     }
     /**
      * @@@ WE NEED AN AUTHORISATION-CHECK HERE @@@
      *
      * we also should lock those to into ONE transaction
      *
      *
      */
     if ($update_modifier && $auth->cur_user) {
         $this->modified_by = $auth->cur_user->id;
         $this->modified = getGMTString();
         if ($update_fields) {
             $update_fields['modified_by'] = true;
             $update_fields['modified'] = true;
         }
     }
     $log_changed_fields = array();
     $t_pairs = array();
     foreach ($g_item_fields as $f) {
         $name = $f->name;
         if ($update_fields && !isset($update_fields[$name])) {
             continue;
         }
         if (isset($this->_values_org[$name])) {
             if (!isset($this->{$name}) && $this->{$name} != NULL) {
                 trigger_error("{$name} is not a member of {$this} and can't be passed to db", E_USER_WARNING);
             }
             if ($this->_values_org[$name] == $this->{$name}) {
                 continue;
             } else {
                 if ($this->fields[$name]->log_changes) {
                     $log_changed_fields[] = $name;
                 }
             }
         }
         $t_pairs[] = $name . "='" . asSecureString($this->{$name}) . "'";
     }
     $prefix = confGet('DB_TABLE_PREFIX');
     if (count($t_pairs)) {
         $str_query = 'UPDATE ' . $prefix . 'item ' . 'SET ' . join(', ', $t_pairs) . ' WHERE id=' . $this->id;
         $dbh = new DB_Mysql();
         $sth = $dbh->prepare($str_query);
         $sth->execute("", 1);
     }
     #--- now write non item-fields ---
     #
     #--- build query-string like "update users SET firstname=:1, lastname=:2 where id=:3" --
     #
     if ($this->_type && $this->_type != 'dbprojectitem') {
         $t_pairs = array();
         # the 'id' field is skipped later, because it's defined as project-item-field. so we have to add it here
         foreach ($this->fields as $f) {
             $name = $f->name;
             ### selective updates ###
             if ($update_fields && !isset($update_fields[$name])) {
                 continue;
             }
             ### skip project-item fields ###
             if (isset($this->fields[$name]) && isset($this->fields[$name]->in_db_object) || !isset($g_item_fields[$name])) {
                 if (!isset($this->{$name}) && $this->{$name} != NULL) {
                     trigger_error("{$name} is not a member of {$this} and can't be passed to db", E_USER_WARNING);
                     continue;
                 }
                 if (isset($this->_values_org[$name])) {
                     if ($this->_values_org[$name] == $this->{$name}) {
                         continue;
                     } else {
                         if ($this->fields[$name]->log_changes) {
                             $log_changed_fields[] = $name;
                         }
                     }
                 }
                 global $sql_obj;
                 $t_pairs[] = $name . '=' . "'" . asSecureString($this->{$name}) . "'";
             }
         }
         if (count($t_pairs)) {
             $str_query = 'UPDATE ' . $prefix . $this->_type . ' SET ' . join(', ', $t_pairs) . ' WHERE id=' . $this->id;
             $sth = $dbh->prepare($str_query);
             $sth->execute("", 1);
         }
         if ($log_changes && $log_changed_fields) {
             require_once confGet('DIR_STREBER') . "db/db_itemchange.inc.php";
             foreach ($log_changed_fields as $name) {
                 /**
                  * keep changes in itemchange table
                  */
                 $c = new ItemChange(array('item' => $this->id, 'field' => $name, 'value_old' => $this->_values_org[$name]));
                 $c->insert();
             }
         }
     }
     return true;
 }
 /**
  * return tasks of project
  *
  *
  *
  * @params
  *   show_folders=true,
  *   order_by=NULL,
  *   status_min=2,
  *   status_max=4,
  *   visible_only=true,
  *   alive_only=true,
  *   parent_task=NULL)  # if NULL parent-task is ignored
  */
 static function getAll($args = NULL)
 {
     global $auth;
     $prefix = confGet('DB_TABLE_PREFIX');
     ### default params ###
     $project = NULL;
     $show_folders = true;
     $order_by = "is_folder DESC, parent_task, prio ASC,project,name";
     $status_min = STATUS_NEW;
     $status_max = STATUS_BLOCKED;
     $visible_only = NULL;
     # use project rights settings
     $alive_only = true;
     # ignore deleted
     $parent_task = NULL;
     #
     $sort_hierarchical = false;
     $use_collapsed = false;
     # by default ignore collapsed folders
     $issues_only = false;
     $folders_only = false;
     $level = 0;
     # hierarchical depth in trees
     $assigned_to_person = 0;
     # skip by default
     $search = NULL;
     $name = NULL;
     $is_milestone = NULL;
     $for_milestone = NULL;
     $resolved_version = NULL;
     $is_released_min = NULL;
     $is_released_max = NULL;
     $id = NULL;
     $modified_by = NULL;
     $not_modified_by = NULL;
     $resolve_reason_min = NULL;
     $category = NULL;
     $category_in = NULL;
     $label = NULL;
     $person = 0;
     $is_news = NULL;
     ### filter params ###
     if ($args) {
         foreach ($args as $key => $value) {
             if (!isset(${$key}) && !is_null(${$key}) && !${$key} === "") {
                 trigger_error("unknown parameter", E_USER_NOTICE);
             } else {
                 ${$key} = $value;
             }
         }
     }
     if ($sort_hierarchical && is_null($parent_task)) {
         $parent_task = 0;
     }
     $str_project = $project ? 'AND upp.project=' . intval($project) : '';
     $str_project2 = $project ? 'AND i.project=' . intval($project) : '';
     $str_is_alive = $alive_only ? 'AND i.state=' . ITEM_STATE_OK : '';
     $str_is_issue = $issues_only ? 'AND t.issue_report!=0' : '';
     $str_is_folder = $show_folders ? '' : 'AND t.is_folder=0';
     $str_modified_by = $modified_by ? 'AND i.modified_by =' . intval($modified_by) : '';
     $str_not_modified_by = $not_modified_by ? 'AND i.modified_by !=' . intval($not_modified_by) : '';
     $str_id = $id ? 'AND t.id=' . intval($id) : '';
     if (!is_null($label)) {
         $str_label = 'AND t.label=' . intval($label);
     } else {
         $str_label = '';
     }
     if (!is_null($is_milestone)) {
         $str_is_milestone = $is_milestone ? 'AND t.is_milestone=1' : 'AND t.is_milestone=0';
     } else {
         $str_is_milestone = '';
     }
     if (!is_null($category)) {
         $str_category = 'AND t.category=' . intval($category);
     } else {
         $str_category = '';
     }
     if (!is_null($category_in)) {
         $clean_array = array();
         foreach ($category_in as $c) {
             $clean_array[] = intval($c);
         }
         $str_category_in = 'AND t.category IN(' . join(",", $clean_array) . ')';
     } else {
         $str_category_in = '';
     }
     if (!is_null($is_news)) {
         $str_is_news = 'AND t.is_news=' . intval($is_news);
     } else {
         $str_is_news = '';
     }
     $str_is_released_min = $is_released_min ? 'AND t.is_released >= ' . intval($is_released_min) : '';
     if ($resolve_reason_min !== NULL) {
         $str_resolve_reason_min = $resolve_reason_min ? 'AND t.resovle_reason >= ' . intval($resolve_reason_min) : '';
     } else {
         $str_reasolve_reason_min = '';
     }
     $str_is_released_max = $is_released_max ? 'AND t.is_released <= ' . intval($is_released_max) : '';
     $str_has_name = $name ? "AND (t.name='" . asSecureString($name) . "' or t.short='" . asSecureString($name) . "')" : "";
     if (!is_null($for_milestone)) {
         $str_for_milestone = 'AND t.for_milestone=' . intval($for_milestone);
     } else {
         $str_for_milestone = '';
     }
     if (!is_null($resolved_version)) {
         $str_resolved_version = 'AND t.resolved_version=' . intval($resolved_version);
     } else {
         $str_resolved_version = '';
     }
     if ($folders_only) {
         $str_is_folder = 'AND t.is_folder=1';
     }
     $str_parent_task = !is_null($parent_task) ? 'AND t.parent_task=' . intval($parent_task) : '';
     $str_match = $search ? "AND MATCH (t.name,t.short,t.description) AGAINST ('" . asMatchString($search) . "*' IN BOOLEAN MODE)" : '';
     $str_person = $person ? $person : $auth->cur_user->id;
     if (is_null($visible_only)) {
         $visible_only = $auth->cur_user && $auth->cur_user->user_rights & RIGHT_VIEWALL ? false : true;
     }
     if ($visible_only) {
         ### only filter assigned to person ###
         if ($assigned_to_person) {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}taskperson tp, {$prefix}projectperson upp, {$prefix}item itp\r\n                WHERE\r\n\r\n                    upp.person = {$auth->cur_user->id}\r\n\t\t\t\t\t/*upp.person = {$str_person}*/\r\n                    {$str_project}\r\n                    AND i.type = '" . ITEM_TASK . "'\r\n                    AND i.project=upp.project\r\n                    {$str_is_alive}\r\n                    {$str_project2}\r\n                    {$str_modified_by}\r\n                    {$str_not_modified_by}\r\n\r\n                    {$str_is_issue}\r\n\r\n                    AND ( i.pub_level >= upp.level_view\r\n                          OR\r\n                          /*i.created_by = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\t  i.created_by = {$str_person}\r\n                    )\r\n\r\n                    AND t.id = i.id\r\n                    {$str_id}\r\n                    {$str_category}\r\n                    {$str_category_in}\r\n                    {$str_is_folder}\r\n                    {$str_is_issue}\r\n                    {$str_label}\r\n                    {$str_parent_task}\r\n                    {$str_has_name}\r\n                    {$str_is_milestone}\r\n                    {$str_is_released_min}\r\n                    {$str_is_released_max}\r\n                    {$str_for_milestone}\r\n                    {$str_resolved_version}\r\n                    {$str_is_news}\r\n                    AND t.status >= " . intval($status_min) . "\r\n                    AND t.status <= " . intval($status_max) . "\r\n\r\n                    AND i.id = tp.task\r\n                           AND tp.person = " . intval($assigned_to_person) . "\r\n                           AND itp.id = tp.id\r\n                           AND itp.state = 1\r\n                           " . "\r\n                    {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         } else {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}projectperson upp\r\n                WHERE\r\n                        /*upp.person = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\tupp.person = {$str_person}\r\n                    {$str_project}\r\n                    AND i.type = '" . ITEM_TASK . "'\r\n                    AND i.project = upp.project\r\n                    {$str_is_alive}\r\n                    {$str_project2}\r\n                    {$str_category}\r\n                    {$str_category_in}\r\n                    {$str_modified_by}\r\n                    {$str_not_modified_by}\r\n                    {$str_is_issue}\r\n                    {$str_is_milestone}\r\n                    {$str_is_released_min}\r\n                    {$str_is_released_max}\r\n                    {$str_for_milestone}\r\n                    {$str_label}\r\n                    {$str_resolved_version}\r\n                    {$str_is_news}\r\n                    AND ( i.pub_level >= upp.level_view\r\n                          OR\r\n                          /*i.created_by = {$auth->cur_user->id}*/\r\n\t\t\t\t\t\t  i.created_by = {$str_person}\r\n                    )\r\n\r\n                    AND t.id = i.id\r\n                    {$str_is_folder}\r\n                    {$str_is_issue}\r\n                    {$str_parent_task}\r\n                    {$str_has_name}\r\n                    {$str_id}\r\n                    AND t.status >= " . intval($status_min) . "\r\n                    AND t.status <= " . intval($status_max) . "\r\n                    {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         }
     } else {
         if ($assigned_to_person) {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t, {$prefix}taskperson tp ,{$prefix}item itp\r\n                WHERE\r\n                    i.type = '" . ITEM_TASK . "'\r\n                {$str_project2}\r\n                {$str_is_alive}\r\n                {$str_modified_by}\r\n                {$str_not_modified_by}\r\n\r\n                AND t.id = i.id\r\n                {$str_id}\r\n                {$str_is_folder}\r\n                {$str_is_issue}\r\n                {$str_category}\r\n                {$str_category_in}\r\n                {$str_parent_task}\r\n                {$str_has_name}\r\n                {$str_label}\r\n                {$str_is_milestone}\r\n                {$str_is_released_min}\r\n                {$str_is_released_max}\r\n                {$str_for_milestone}\r\n                {$str_is_news}\r\n                {$str_resolved_version}\r\n                AND t.status >= " . intval($status_min) . "\r\n                AND t.status <= " . intval($status_max) . "\r\n                {$str_match}\r\n                AND i.id = tp.task\r\n                AND tp.person = " . intval($assigned_to_person) . "\r\n                       AND tp.id = itp.id\r\n                       AND itp.state = 1\r\n                " . getOrderByString($order_by);
         } else {
             $str_query = "SELECT i.*, t.* from {$prefix}item i, {$prefix}task t\r\n                WHERE\r\n                    i.type = '" . ITEM_TASK . "'\r\n                {$str_project2}\r\n                {$str_is_alive}\r\n                {$str_modified_by}\r\n                {$str_not_modified_by}\r\n\r\n                AND t.id = i.id\r\n                {$str_category}\r\n                {$str_category_in}\r\n                {$str_id}\r\n                {$str_is_folder}\r\n                {$str_is_issue}\r\n                {$str_is_milestone}\r\n                {$str_for_milestone}\r\n                {$str_label}\r\n                {$str_resolved_version}\r\n                {$str_is_news}\r\n\r\n                {$str_is_released_min}\r\n                {$str_is_released_max}\r\n                {$str_parent_task}\r\n                {$str_has_name}\r\n                AND t.status >= " . intval($status_min) . "\r\n                AND t.status <= " . intval($status_max) . "\r\n                {$str_match}\r\n\r\n                " . getOrderByString($order_by);
         }
     }
     $dbh = new DB_Mysql();
     $sth = $dbh->prepare($str_query);
     $sth->execute("", 1);
     $tmp = $sth->fetchall_assoc();
     $tasks = array();
     foreach ($tmp as $t) {
         $task = new Task($t);
         $task->level = $level;
         $tasks[] = $task;
         ### hierarchical / recursive sorting ###
         if ($sort_hierarchical && $task->is_folder && (!$use_collapsed || !$task->view_collapsed)) {
             if ($sub_tasks = Task::getAll(array('sort_hierarchical' => true, 'use_collapsed' => $use_collapsed, 'parent_task' => $task->id, 'order_by' => $order_by, 'visible_only' => $visible_only, 'alive_only' => $alive_only, 'issues_only' => $issues_only, 'status_min' => $status_min, 'status_max' => $status_max, 'level' => $level + 1, 'folders_only' => $folders_only, 'project' => $project))) {
                 foreach ($sub_tasks as &$st) {
                     $tasks[] = $st;
                 }
             }
         }
     }
     return $tasks;
 }
 public function update($args = NULL, $update_modifier = true)
 {
     global $auth;
     $dbh = new DB_Mysql();
     $prefix = confGet('DB_TABLE_PREFIX');
     $update_fields = NULL;
     ### build hash to fast access ##
     if ($args) {
         $update_fields = array();
         foreach ($args as $a) {
             $update_fields[$a] = true;
         }
     }
     if (!$this->id) {
         trigger_error("User object without id can't be updated", E_USER_WARNING);
     }
     if (!sizeof($this->field_states)) {
         trigger_error("need members to update to database. e.g. 'firstname,lastname,data'", E_USER_WARNING);
     }
     $t_pairs = array();
     # the 'id' field is skipped later, because it's defined as project-item-field. so we have to add it here
     foreach ($this->fields as $f) {
         $name = $f->name;
         ### selective updates ###
         if ($update_fields && !isset($update_fields[$name])) {
             continue;
         }
         ### skip project-item fields ###
         if (isset($this->fields[$name]) && isset($this->fields[$name]->in_db_object) || !isset($g_item_fields[$name])) {
             if (!isset($this->{$name}) && $this->{$name} != NULL) {
                 trigger_error("{$name} is not a member of {$this} and can't be passed to db", E_USER_WARNING);
                 continue;
             }
             if (isset($this->_values_org[$name])) {
                 if ($this->_values_org[$name] == stripslashes($this->{$name})) {
                     continue;
                 } else {
                     if ($this->fields[$name]->log_changes) {
                         $log_changed_fields[] = $name;
                     }
                 }
             }
             global $sql_obj;
             $t_pairs[] = $name . '=' . "'" . asSecureString($this->{$name}) . "'";
         }
     }
     if (count($t_pairs)) {
         $str_query = 'UPDATE ' . $prefix . $this->_type . ' SET ' . join(', ', $t_pairs) . ' WHERE id=' . $this->id;
         $sth = $dbh->prepare($str_query);
         $sth->execute("", 1);
     }
 }