[ Index ]

PHP Cross Reference of Eventum

title

Body

[close]

/include/ -> class.filter.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */
   3  // +----------------------------------------------------------------------+
   4  // | Eventum - Issue Tracking System                                      |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB                  |
   7  // |                                                                      |
   8  // | This program is free software; you can redistribute it and/or modify |
   9  // | it under the terms of the GNU General Public License as published by |
  10  // | the Free Software Foundation; either version 2 of the License, or    |
  11  // | (at your option) any later version.                                  |
  12  // |                                                                      |
  13  // | This program is distributed in the hope that it will be useful,      |
  14  // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  15  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
  16  // | GNU General Public License for more details.                         |
  17  // |                                                                      |
  18  // | You should have received a copy of the GNU General Public License    |
  19  // | along with this program; if not, write to:                           |
  20  // |                                                                      |
  21  // | Free Software Foundation, Inc.                                       |
  22  // | 59 Temple Place - Suite 330                                          |
  23  // | Boston, MA 02111-1307, USA.                                          |
  24  // +----------------------------------------------------------------------+
  25  // | Authors: João Prado Maia <jpm@mysql.com>                             |
  26  // +----------------------------------------------------------------------+
  27  //
  28  // @(#) $Id: class.filter.php 3246 2007-02-09 09:10:12Z glen $
  29  //
  30  
  31  require_once (APP_INC_PATH . "class.error_handler.php");
  32  require_once (APP_INC_PATH . "class.misc.php");
  33  require_once (APP_INC_PATH . "class.auth.php");
  34  require_once (APP_INC_PATH . "class.date.php");
  35  
  36  /**
  37   * Class to handle the business logic related to the custom filters.
  38   *
  39   * @version 1.0
  40   * @author João Prado Maia <jpm@mysql.com>
  41   */
  42  
  43  class Filter
  44  {
  45      /**
  46       * Method used to check whether the given custom filter is a
  47       * global one or not.
  48       *
  49       * @access  public
  50       * @param   integer $cst_id The custom filter ID
  51       * @return  boolean
  52       */
  53      function isGlobal($cst_id)
  54      {
  55          $stmt = "SELECT
  56                      COUNT(*)
  57                   FROM
  58                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
  59                   WHERE
  60                      cst_id=" . Misc::escapeInteger($cst_id) . " AND
  61                      cst_is_global=1";
  62          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
  63          if (PEAR::isError($res)) {
  64              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  65              return false;
  66          } else {
  67              if ($res == 1) {
  68                  return true;
  69              } else {
  70                  return false;
  71              }
  72          }
  73      }
  74  
  75  
  76      /**
  77       * Method used to check whether the given user is the owner of the custom
  78       * filter ID.
  79       *
  80       * @access  public
  81       * @param   integer $cst_id The custom filter ID
  82       * @param   integer $usr_id The user ID
  83       * @return  boolean
  84       */
  85      function isOwner($cst_id, $usr_id)
  86      {
  87          $stmt = "SELECT
  88                      COUNT(*)
  89                   FROM
  90                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
  91                   WHERE
  92                      cst_id=" . Misc::escapeInteger($cst_id) . " AND
  93                      cst_usr_id=" . Misc::escapeInteger($usr_id);
  94          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
  95          if (PEAR::isError($res)) {
  96              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
  97              return false;
  98          } else {
  99              if ($res == 1) {
 100                  return true;
 101              } else {
 102                  return false;
 103              }
 104          }
 105      }
 106  
 107  
 108      /**
 109       * Method used to save the changes made to an existing custom
 110       * filter, or to create a new custom filter.
 111       *
 112       * @access  public
 113       * @return  integer 1 if the update worked properly, any other value otherwise
 114       */
 115      function save()
 116      {
 117          $cst_id = Filter::getFilterID($_POST["title"]);
 118          // loop through all available date fields and prepare the values for the sql query
 119          $date_fields = array(
 120              'created_date',
 121              'updated_date',
 122              'last_response_date',
 123              'first_response_date',
 124              'closed_date'
 125          );
 126          foreach ($date_fields as $field_name) {
 127              $date_var = $field_name;
 128              $filter_type_var = $field_name . '_filter_type';
 129              $date_end_var = $field_name . '_end';
 130              if (@$_POST['filter'][$field_name] == 'yes') {
 131                  $$date_var = "'" . Misc::escapeString($_POST[$field_name]["Year"] . "-" . $_POST[$field_name]["Month"] . "-" . $_POST[$field_name]["Day"]) . "'";
 132                  $$filter_type_var = "'" . $_POST[$field_name]['filter_type'] . "'";
 133                  if ($$filter_type_var == "'between'") {
 134                      $$date_end_var = "'" . Misc::escapeString($_POST[$date_end_var]["Year"] . "-" . $_POST[$date_end_var]["Month"] . "-" . $_POST[$date_end_var]["Day"]) . "'";
 135                  } elseif (($$filter_type_var == "'null'") || ($$filter_type_var == "'in_past'")) {
 136                      $$date_var = "NULL";
 137                      $$date_end_var = "NULL";
 138                  } else {
 139                      $$date_end_var = "NULL";
 140                  }
 141              } else {
 142                  $$date_var = 'NULL';
 143                  $$filter_type_var = "NULL";
 144                  $$date_end_var = 'NULL';
 145              }
 146          }
 147  
 148          // save custom fields to search
 149          if ((is_array($_POST['custom_field'])) && (count($_POST['custom_field']) > 0)) {
 150              foreach ($_POST['custom_field'] as $fld_id => $search_value) {
 151                  if (empty($search_value)) {
 152                      unset($_POST[$fld_id]);
 153                  }
 154              }
 155              $custom_field_string = serialize($_POST['custom_field']);
 156          } else {
 157              $custom_field_string = '';
 158          }
 159  
 160          if (empty($_POST['is_global'])) {
 161              $is_global_filter = 0;
 162          } else {
 163              $is_global_filter = $_POST['is_global'];
 164          }
 165          if ($cst_id != 0) {
 166              $stmt = "UPDATE
 167                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 168                       SET
 169                          cst_iss_pri_id='" . Misc::escapeInteger($_POST["priority"]) . "',
 170                          cst_keywords='" . Misc::escapeString($_POST["keywords"]) . "',
 171                          cst_users='" . Misc::escapeString($_POST["users"]) . "',
 172                          cst_reporter=" . Misc::escapeInteger($_POST["reporter"]) . ",
 173                          cst_iss_sta_id='" . Misc::escapeInteger($_POST["status"]) . "',
 174                          cst_iss_pre_id='" . Misc::escapeInteger(@$_POST["release"]) . "',
 175                          cst_iss_prc_id='" . Misc::escapeInteger(@$_POST["category"]) . "',
 176                          cst_rows='" . Misc::escapeString($_POST["rows"]) . "',
 177                          cst_sort_by='" . Misc::escapeString($_POST["sort_by"]) . "',
 178                          cst_sort_order='" . Misc::escapeString($_POST["sort_order"]) . "',
 179                          cst_hide_closed='" . Misc::escapeInteger(@$_POST["hide_closed"]) . "',
 180                          cst_show_authorized='" . Misc::escapeString(@$_POST["show_authorized_issues"]) . "',
 181                          cst_show_notification_list='" . Misc::escapeString(@$_POST["show_notification_list_issues"]) . "',
 182                          cst_created_date=$created_date,
 183                          cst_created_date_filter_type=$created_date_filter_type,
 184                          cst_created_date_time_period='" . @Misc::escapeInteger(@$_REQUEST['created_date']['time_period']) . "',
 185                          cst_created_date_end=$created_date_end,
 186                          cst_updated_date=$updated_date,
 187                          cst_updated_date_filter_type=$updated_date_filter_type,
 188                          cst_updated_date_time_period='" . @Misc::escapeInteger(@$_REQUEST['updated_date']['time_period']) . "',
 189                          cst_updated_date_end=$updated_date_end,
 190                          cst_last_response_date=$last_response_date,
 191                          cst_last_response_date_filter_type=$last_response_date_filter_type,
 192                          cst_last_response_date_time_period='" .@ Misc::escapeInteger(@$_REQUEST['last_response_date']['time_period']) . "',
 193                          cst_last_response_date_end=$last_response_date_end,
 194                          cst_first_response_date=$first_response_date,
 195                          cst_first_response_date_filter_type=$first_response_date_filter_type,
 196                          cst_first_response_date_time_period='" . @Misc::escapeInteger(@$_REQUEST['first_response_date']['time_period']) . "',
 197                          cst_first_response_date_end=$first_response_date_end,
 198                          cst_closed_date=$closed_date,
 199                          cst_closed_date_filter_type=$closed_date_filter_type,
 200                          cst_closed_date_time_period='" . @Misc::escapeInteger(@$_REQUEST['closed_date']['time_period']) . "',
 201                          cst_closed_date_end=" . Misc::escapeString($closed_date_end) . ",
 202                          cst_is_global=" . Misc::escapeInteger($is_global_filter) . ",
 203                          cst_search_type='" . Misc::escapeString($_POST['search_type']) . "',
 204                          cst_custom_field='" . Misc::escapeString($custom_field_string) . "'
 205                       WHERE
 206                          cst_id=$cst_id";
 207          } else {
 208              $stmt = "INSERT INTO
 209                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 210                       (
 211                          cst_usr_id,
 212                          cst_prj_id,
 213                          cst_title,
 214                          cst_iss_pri_id,
 215                          cst_keywords,
 216                          cst_users,
 217                          cst_reporter,
 218                          cst_iss_sta_id,
 219                          cst_iss_pre_id,
 220                          cst_iss_prc_id,
 221                          cst_rows,
 222                          cst_sort_by,
 223                          cst_sort_order,
 224                          cst_hide_closed,
 225                          cst_show_authorized,
 226                          cst_show_notification_list,
 227                          cst_created_date,
 228                          cst_created_date_filter_type,
 229                          cst_created_date_time_period,
 230                          cst_created_date_end,
 231                          cst_updated_date,
 232                          cst_updated_date_filter_type,
 233                          cst_updated_date_time_period,
 234                          cst_updated_date_end,
 235                          cst_last_response_date,
 236                          cst_last_response_date_filter_type,
 237                          cst_last_response_date_time_period,
 238                          cst_last_response_date_end,
 239                          cst_first_response_date,
 240                          cst_first_response_date_filter_type,
 241                          cst_first_response_date_time_period,
 242                          cst_first_response_date_end,
 243                          cst_closed_date,
 244                          cst_closed_date_filter_type,
 245                          cst_closed_date_time_period,
 246                          cst_closed_date_end,
 247                          cst_is_global,
 248                          cst_search_type,
 249                          cst_custom_field
 250                       ) VALUES (
 251                          " . Auth::getUserID() . ",
 252                          " . Auth::getCurrentProject() . ",
 253                          '" . Misc::escapeString($_POST["title"]) . "',
 254                          '" . Misc::escapeInteger($_POST["priority"]) . "',
 255                          '" . Misc::escapeString($_POST["keywords"]) . "',
 256                          '" . Misc::escapeString($_POST["users"]) . "',
 257                          '" . Misc::escapeInteger($_POST["reporter"]) . "',
 258                          '" . Misc::escapeInteger($_POST["status"]) . "',
 259                          '" . Misc::escapeInteger(@$_POST["release"]) . "',
 260                          '" . Misc::escapeInteger(@$_POST["category"]) . "',
 261                          '" . Misc::escapeString($_POST["rows"]) . "',
 262                          '" . Misc::escapeString($_POST["sort_by"]) . "',
 263                          '" . Misc::escapeString($_POST["sort_order"]) . "',
 264                          '" . Misc::escapeInteger(@$_POST["hide_closed"]) . "',
 265                          '" . Misc::escapeString(@$_POST["show_authorized_issues"]) . "',
 266                          '" . Misc::escapeString(@$_POST["show_notification_list_issues"]) . "',
 267                          $created_date,
 268                          $created_date_filter_type,
 269                          '" . @Misc::escapeInteger(@$_REQUEST['created_date']['time_period']) . "',
 270                          $created_date_end,
 271                          $updated_date,
 272                          $updated_date_filter_type,
 273                          '" . @Misc::escapeInteger(@$_REQUEST['updated_date']['time_period']) . "',
 274                          $updated_date_end,
 275                          $last_response_date,
 276                          $last_response_date_filter_type,
 277                          '" . @Misc::escapeInteger(@$_REQUEST['response_date']['time_period']) . "',
 278                          $last_response_date_end,
 279                          $first_response_date,
 280                          $first_response_date_filter_type,
 281                          '" . @Misc::escapeInteger(@$_REQUEST['first_response_date']['time_period']) . "',
 282                          $first_response_date_end,
 283                          $closed_date,
 284                          $closed_date_filter_type,
 285                          '" . @Misc::escapeInteger(@$_REQUEST['closed_date']['time_period']) . "',
 286                          $closed_date_end,
 287                          " . Misc::escapeInteger($is_global_filter) . ",
 288                          '" . Misc::escapeString($_POST['search_type']) . "',
 289                          '" . Misc::escapeString($custom_field_string) . "'
 290                       )";
 291          }
 292          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 293          if (PEAR::isError($res)) {
 294              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 295              return -1;
 296          } else {
 297              return 1;
 298          }
 299      }
 300  
 301  
 302      /**
 303       * Method used to get the filter ID associated with a specific
 304       * filter title.
 305       *
 306       * @access  public
 307       * @param   string $cst_title The custom filter title
 308       * @return  integer The custom filter ID
 309       */
 310      function getFilterID($cst_title)
 311      {
 312          $stmt = "SELECT
 313                      cst_id
 314                   FROM
 315                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 316                   WHERE
 317                      cst_usr_id=" . Auth::getUserID() . " AND
 318                      cst_prj_id=" . Auth::getCurrentProject() . " AND
 319                      cst_title='" . Misc::escapeString($cst_title) . "'";
 320          $res = $GLOBALS["db_api"]->dbh->getOne($stmt);
 321          if (PEAR::isError($res)) {
 322              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 323              return 0;
 324          } else {
 325              return $res;
 326          }
 327      }
 328  
 329  
 330      /**
 331       * Method used to get an associative array of the full list of
 332       * custom filters (filter id => filter title) associated with the
 333       * current user and the current 'active' project.
 334       *
 335       * @access  public
 336       * @return  array The full list of custom filters
 337       */
 338      function getAssocList()
 339      {
 340          $stmt = "SELECT
 341                      cst_id,
 342                      cst_title
 343                   FROM
 344                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 345                   WHERE
 346                      cst_prj_id=" . Auth::getCurrentProject() . " AND
 347                      (
 348                          cst_usr_id=" . Auth::getUserID() . " OR
 349                          cst_is_global=1
 350                      )
 351                   ORDER BY
 352                      cst_title";
 353          $res = $GLOBALS["db_api"]->dbh->getAssoc($stmt);
 354          if (PEAR::isError($res)) {
 355              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 356              return "";
 357          } else {
 358              return $res;
 359          }
 360      }
 361  
 362  
 363      /**
 364       * Method used to get an array of the full list of the custom
 365       * filters associated with the current user and the current
 366       * 'active' project.
 367       *
 368       * @access  public
 369       * @param   boolean $build_url If a URL for this filter should be constructed.
 370       * @return  array The full list of custom filters
 371       */
 372      function getListing($build_url = false)
 373      {
 374          $stmt = "SELECT
 375                      *
 376                   FROM
 377                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 378                   WHERE
 379                      cst_prj_id=" . Auth::getCurrentProject() . " AND
 380                      (
 381                          cst_usr_id=" . Auth::getUserID() . " OR
 382                          cst_is_global=1
 383                      )
 384                   ORDER BY
 385                      cst_title";
 386          $res = $GLOBALS["db_api"]->dbh->getAll($stmt, DB_FETCHMODE_ASSOC);
 387          if (PEAR::isError($res)) {
 388              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 389              return "";
 390          } else {
 391              if ((count($res) > 0) && ($build_url == true)) {
 392                  $filter_info = Filter::getFiltersInfo();
 393                  for ($i = 0; $i < count($res); $i++) {
 394                      $res[$i]['url'] = '';
 395                      foreach ($filter_info as $field => $filter) {
 396                          if (@$filter['is_date'] == true) {
 397                              $res[$i]['url'] .= $filter['param'] . '[filter_type]=' . $res[$i]['cst_' . $field . '_filter_type'] . '&';
 398                              if ($res[$i]['cst_' . $field . '_filter_type'] == 'in_past') {
 399                                  $res[$i]['url'] .= $filter['param'] . '[time_period]=' . $res[$i]['cst_' . $field . '_time_period'] . '&';
 400                              } else {
 401                                  $start_date = $res[$i]['cst_' . $field];
 402                                  if (!empty($start_date)) {
 403                                      $start_date_parts = explode("-", $start_date);
 404                                      $res[$i]['url'] .= $filter['param']  . '[Year]=' . $start_date_parts[0] . '&';
 405                                      $res[$i]['url'] .= $filter['param']  . '[Month]=' . $start_date_parts[1] . '&';
 406                                      $res[$i]['url'] .= $filter['param']  . '[Day]=' . $start_date_parts[2] . '&';
 407                                  }
 408                                  $end_date = $res[$i]['cst_' . $field . '_end'];
 409                                  if (!empty($end_date)) {
 410                                      $end_date_parts = explode("-", $end_date);
 411                                      $res[$i]['url'] .= $filter['param']  . '_end[Year]=' . $end_date_parts[0] . '&';
 412                                      $res[$i]['url'] .= $filter['param']  . '_end[Month]=' . $end_date_parts[1] . '&';
 413                                      $res[$i]['url'] .= $filter['param']  . '_end[Day]=' . $end_date_parts[2] . '&';
 414                                  }
 415                              }
 416                          } else {
 417                              if (@$filter['is_custom'] != 1) {
 418                                  $res[$i]['url'] .= $filter['param'] . '=' . urlencode($res[$i]['cst_' . $field]) . '&';
 419                              }
 420                          }
 421                      }
 422                      $res[$i]['url'] .= 'custom_field=' . urlencode($res[$i]['cst_custom_field']);
 423                  }
 424              }
 425  
 426              return $res;
 427          }
 428      }
 429  
 430  
 431      /**
 432       * Takes the saved search details and information about filters and returns an array of
 433       * of the saved search information.
 434       *
 435       * @access  private
 436       * @param   array $details An array of information about the saved search, usually the direct row from the database.
 437       * @param   array $info An array of information about filters
 438       * @return  array An array of information about the saved search.
 439       */
 440      function buildOptions($details, $info)
 441      {
 442          $options = array();
 443          foreach ($info as $field => $filter) {
 444              if (@$filter['is_date'] == true) {
 445                  $options[$filter['param']]['filter_type'] =  $details['cst_' . $field . '_filter_type'];
 446                  if ($details['cst_' . $field . '_filter_type'] == 'in_past') {
 447                      $options[$filter['param']]['time_period'] = $details['cst_' . $field . '_time_period'] . '&';
 448                  } else {
 449                      $start_date = $details['cst_' . $field];
 450                      if (!empty($start_date)) {
 451                          $start_date_parts = explode("-", $start_date);
 452                          $options[$filter['param']]['Year'] = $start_date_parts[0];
 453                          $options[$filter['param']]['Month'] = $start_date_parts[1];
 454                          $options[$filter['param']]['Day'] = $start_date_parts[2];
 455                      }
 456                      $end_date = $details['cst_' . $field . '_end'];
 457                      if (!empty($end_date)) {
 458                          $end_date_parts = explode("-", $end_date);
 459                          $options[$filter['param'] . '_end']['Year'] = $end_date_parts[0];
 460                          $options[$filter['param'] . '_end']['Month'] = $end_date_parts[1];
 461                          $options[$filter['param'] . '_end']['Day'] = $end_date_parts[2];
 462                      }
 463                  }
 464              } else {
 465                  if (@$filter['is_custom'] != 1) {
 466                      $options[$filter['param']] = $details['cst_' . $field];
 467                  }
 468              }
 469          }
 470          $options['custom_field'] = $details['cst_custom_field'];
 471          return $options;
 472      }
 473  
 474  
 475      /**
 476       * Method used to get an associative array of the full details of
 477       * a specific custom filter.
 478       *
 479       * @access  public
 480       * @param   integer $cst_id The custom filter ID
 481       * @param   boolean $check_perm Whether to check for the permissions or not
 482       * @return  array The custom filter details
 483       */
 484      function getDetails($cst_id, $check_perm = TRUE)
 485      {
 486          $stmt = "SELECT
 487                      *
 488                   FROM
 489                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 490                   WHERE";
 491          if ($check_perm) {
 492              $stmt .= "
 493                      cst_usr_id=" . Auth::getUserID() . " AND
 494                      cst_prj_id=" . Auth::getCurrentProject() . " AND ";
 495          }
 496          $stmt .= "
 497                      cst_id=$cst_id";
 498          $res = $GLOBALS["db_api"]->dbh->getRow($stmt, DB_FETCHMODE_ASSOC);
 499          if (PEAR::isError($res)) {
 500              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 501              return "";
 502          } else {
 503              if (is_string($res['cst_custom_field'])) {
 504                  $res['cst_custom_field'] = unserialize($res['cst_custom_field']);
 505              }
 506              return $res;
 507          }
 508      }
 509  
 510  
 511      /**
 512       * Method used to remove specific custom filters.
 513       *
 514       * @access  public
 515       * @return  integer 1 if the removals worked properly, any other value otherwise
 516       */
 517      function remove()
 518      {
 519          $items = implode(", ", Misc::escapeInteger($_POST["item"]));
 520          foreach ($_POST["item"] as $cst_id) {
 521              $stmt = "DELETE FROM
 522                          " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 523                       WHERE";
 524              if (Filter::isGlobal($cst_id)) {
 525                  if (Auth::getCurrentRole() >= User::getRoleID('Manager')) {
 526                      $stmt .= " cst_is_global=1 AND ";
 527                  } else {
 528                      $stmt .= "
 529                          cst_is_global=1 AND
 530                          cst_usr_id=" . Auth::getUserID() . " AND ";
 531                  }
 532              } else {
 533                  $stmt .= " cst_usr_id=" . Auth::getUserID() . " AND ";
 534              }
 535              $stmt .= "
 536                          cst_prj_id=" . Auth::getCurrentProject() . " AND
 537                          cst_id=$cst_id";
 538              $res = $GLOBALS["db_api"]->dbh->query($stmt);
 539              if (PEAR::isError($res)) {
 540                  Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 541                  return -1;
 542              }
 543          }
 544          return 1;
 545      }
 546  
 547  
 548      /**
 549       * Method used to remove all custom filters associated with some
 550       * specific projects.
 551       *
 552       * @access  public
 553       * @param   array $ids List of projects to remove from
 554       * @return  boolean Whether the removal worked properly or not
 555       */
 556      function removeByProjects($ids)
 557      {
 558          $items = implode(", ", Misc::escapeInteger($ids));
 559          $stmt = "DELETE FROM
 560                      " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_filter
 561                   WHERE
 562                      cst_prj_id IN ($items)";
 563          $res = $GLOBALS["db_api"]->dbh->query($stmt);
 564          if (PEAR::isError($res)) {
 565              Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 566              return false;
 567          } else {
 568              return true;
 569          }
 570      }
 571  
 572  
 573      /**
 574       * Returns an array of information about all the different filter fields.
 575       *
 576       * @access  public
 577       * @return  Array an array of information.
 578       */
 579      function getFiltersInfo()
 580      {
 581          // format is "name_of_db_field" => array(
 582          //      "title" => human readable title,
 583          //      "param" => name that appears in get, post or cookie
 584          $fields = array(
 585              'iss_pri_id'    =>  array(
 586                  'title' =>  ev_gettext("Priority"),
 587                  'param' =>  'priority',
 588                  'quickfilter'   =>  true
 589              ),
 590              'keywords'  =>  array(
 591                  'title' =>  ev_gettext("Keyword(s)"),
 592                  'param' =>  'keywords',
 593                  'quickfilter'   =>  true
 594              ),
 595              'users' =>  array(
 596                  'title' =>  ev_gettext("Assigned"),
 597                  'param' =>  'users',
 598                  'quickfilter'   =>  true
 599              ),
 600              'iss_prc_id'    =>  array(
 601                  'title' =>  ev_gettext("Category"),
 602                  'param' =>  'category',
 603                  'quickfilter'   =>  true
 604              ),
 605              'iss_sta_id'    =>  array(
 606                  'title' =>  ev_gettext("Status"),
 607                  'param' =>  'status',
 608                  'quickfilter'   =>  true
 609              ),
 610              'iss_pre_id'    =>  array(
 611                  'title' =>  ev_gettext("Release"),
 612                  'param' =>  'release'
 613              ),
 614              'created_date'  =>  array(
 615                  'title' =>  ev_gettext("Created Date"),
 616                  'param' =>  'created_date',
 617                  'is_date'   =>  true
 618              ),
 619              'updated_date'  =>  array(
 620                  'title' =>  ev_gettext("Updated Date"),
 621                  'param' =>  'updated_date',
 622                  'is_date'   =>  true
 623              ),
 624              'last_response_date'  =>  array(
 625                  'title' =>  ev_gettext("Last Response Date"),
 626                  'param' =>  'last_response_date',
 627                  'is_date'   =>  true
 628              ),
 629              'first_response_date'  =>  array(
 630                  'title' =>  ev_gettext("First Response Date"),
 631                  'param' =>  'first_response_date',
 632                  'is_date'   =>  true
 633              ),
 634              'closed_date'  =>  array(
 635                  'title' =>  ev_gettext("Closed Date"),
 636                  'param' =>  'closed_date',
 637                  'is_date'   =>  true
 638              ),
 639              'rows'  =>  array(
 640                  'title' =>  ev_gettext("Rows Per Page"),
 641                  'param' =>  'rows'
 642              ),
 643              'sort_by'   =>  array(
 644                  'title' =>  ev_gettext("Sort By"),
 645                  'param' =>  'sort_by'
 646              ),
 647              'sort_order'    =>  array(
 648                  'title' =>  ev_gettext("Sort Order"),
 649                  'param' =>  'sort_order',
 650              ),
 651              'hide_closed'   =>  array(
 652                  'title' =>  ev_gettext("Hide Closed Issues"),
 653                  'param' =>  'hide_closed'
 654              ),
 655              'show_authorized'   =>  array(
 656                  'title' =>  ev_gettext("Authorized to Send Emails"),
 657                  'param' =>  'show_authorized_issues'
 658              ),
 659              'show_notification_list'    =>  array(
 660                  'title' =>  ev_gettext("In Notification List"),
 661                  'param' =>  'show_notification_list_issues'
 662              ),
 663              'search_type'   =>  array(
 664                  'title' =>  ev_gettext("Search Type"),
 665                  'param' =>  'search_type'
 666              ),
 667              'reporter'  =>  array(
 668                  'title' =>  ev_gettext("Reporter"),
 669                  'param' =>  'reporter'
 670              )
 671          );
 672  
 673          // add custom fields
 674          $custom_fields = Custom_Field::getFieldsByProject(Auth::getCurrentProject());
 675          if (count($custom_fields) > 0) {
 676              foreach ($custom_fields as $fld_id) {
 677                  $field = Custom_Field::getDetails($fld_id);
 678                  $fields['custom_field_' . $fld_id] = array(
 679                      'title' =>  $field['fld_title'],
 680                      'is_custom' =>  1,
 681                      'fld_id'    =>  $fld_id,
 682                      'fld_type'  =>  $field['fld_type']
 683                  );
 684              }
 685          }
 686  
 687          return $fields;
 688      }
 689  }
 690  
 691  // benchmarking the included file (aka setup time)
 692  if (APP_BENCHMARK) {
 693      $GLOBALS['bench']->setMarker('Included Filter Class');
 694  }


Generated: Wed Dec 19 21:21:33 2007 Cross-referenced by PHPXref 0.7