[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/api/soap/ -> mc_project_api.php (source)

   1  <?php
   2  # MantisConnect - A webservice interface to Mantis Bug Tracker
   3  # Copyright (C) 2004-2011  Victor Boctor - vboctor@users.sourceforge.net
   4  # This program is distributed under dual licensing.  These include
   5  # GPL and a commercial licenses.  Victor Boctor reserves the right to
   6  # change the license of future releases.
   7  # See docs/ folder for more details
   8  
   9  function mc_project_get_issues( $p_username, $p_password, $p_project_id, $p_page_number, $p_per_page ) {
  10      $t_user_id = mci_check_login( $p_username, $p_password );
  11      if( $t_user_id === false ) {
  12          return mci_soap_fault_login_failed();
  13      }
  14  
  15      $t_lang = mci_get_user_lang( $t_user_id );
  16  
  17      if( !project_exists( $p_project_id ) ) {
  18          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
  19      }
  20  
  21      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
  22          return mci_soap_fault_access_denied( $t_user_id );
  23      }
  24  
  25      $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
  26      $t_page_count = 0;
  27      $t_bug_count = 0;
  28  
  29      $t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );
  30      
  31      $t_result = array();
  32      
  33      // the page number was moved back, so we have exceeded the actual page number, see bug #12991
  34      if ( $t_orig_page_number > $p_page_number )
  35          return $t_result;    
  36  
  37      foreach( $t_rows as $t_issue_data ) {
  38          $t_result[] = mci_issue_data_as_array( $t_issue_data, $t_user_id, $t_lang );
  39      }
  40  
  41      return $t_result;
  42  }
  43  
  44  /**
  45   * Get all projects accessible by the given user.
  46   *
  47   * @param string $p_username  The name of the user trying to access the project list.
  48   * @param string $p_password  The password of the user.
  49   * @return Array  suitable to be converted into a ProjectDataArray
  50   */
  51  function mc_projects_get_user_accessible( $p_username, $p_password ) {
  52      $t_user_id = mci_check_login( $p_username, $p_password );
  53      if( $t_user_id === false ) {
  54          return mci_soap_fault_login_failed();
  55      }
  56  
  57      if( !mci_has_readonly_access( $t_user_id ) ) {
  58          return mci_soap_fault_access_denied( $t_user_id );
  59      }
  60  
  61      $t_lang = mci_get_user_lang( $t_user_id );
  62  
  63      $t_result = array();
  64      foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) {
  65          $t_project_row = project_cache_row( $t_project_id );
  66          $t_project = array();
  67          $t_project['id'] = $t_project_id;
  68          $t_project['name'] = $t_project_row['name'];
  69          $t_project['status'] = mci_enum_get_array_by_id( $t_project_row['status'], 'project_status', $t_lang );
  70          $t_project['enabled'] = $t_project_row['enabled'];
  71          $t_project['view_state'] = mci_enum_get_array_by_id( $t_project_row['view_state'], 'project_view_state', $t_lang );
  72          $t_project['access_min'] = mci_enum_get_array_by_id( $t_project_row['access_min'], 'access_levels', $t_lang );
  73          $t_project['file_path'] = array_key_exists( 'file_path', $t_project_row ) ? $t_project_row['file_path'] : "";
  74          $t_project['description'] = array_key_exists( 'description', $t_project_row ) ? $t_project_row['description'] : "";
  75          $t_project['subprojects'] = mci_user_get_accessible_subprojects( $t_user_id, $t_project_id, $t_lang );
  76          $t_result[] = $t_project;
  77      }
  78  
  79      return $t_result;
  80  }
  81  
  82  /**
  83   * Get all categories of a project.
  84   *
  85   * @param string $p_username  The name of the user trying to access the categories.
  86   * @param string $p_password  The password of the user.
  87   * @param integer $p_project_id  The id of the project to retrieve the categories for.
  88   * @return Array  of categorie names
  89   */
  90  function mc_project_get_categories( $p_username, $p_password, $p_project_id ) {
  91      $t_user_id = mci_check_login( $p_username, $p_password );
  92  
  93      if( $t_user_id === false ) {
  94          return mci_soap_fault_login_failed();
  95      }
  96  
  97      if( !project_exists( $p_project_id ) ) {
  98          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
  99      }
 100  
 101      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 102          return mci_soap_fault_access_denied( $t_user_id );
 103      }
 104  
 105      $t_result = array();
 106      $t_cat_array = category_get_all_rows( $p_project_id );
 107      foreach( $t_cat_array as $t_category_row ) {
 108          $t_result[] = $t_category_row['name'];
 109      }
 110      return $t_result;
 111  }
 112  
 113  /**
 114   * Add a new category to a project
 115   * @param string $p_username  The name of the user trying to access the categories.
 116   * @param string $p_password  The password of the user.
 117   * @param integer $p_project_id  The id of the project to retrieve the categories for.
 118   * @param string $p_category_name The name of the new category to add
 119   * @return integer id of the new category
 120   */
 121  
 122  function mc_project_add_category($p_username, $p_password, $p_project_id, $p_category_name ) {
 123          $t_user_id = mci_check_login( $p_username, $p_password );
 124  
 125          if( $t_user_id === false ) {
 126                  return new soap_fault( 'Client', '', 'Access Denied' );
 127          }
 128  
 129          if( !project_exists( $p_project_id ) ) {
 130                  return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 131          }
 132  
 133          if( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $p_project_id ) ) {
 134                  return new soap_fault( 'Client', '', 'Access Denied' );
 135          }
 136  
 137          return category_add( $p_project_id, $p_category_name );
 138  }
 139  
 140  /**
 141   * Delete a category of a project
 142   * @param string $p_username  The name of the user trying to access the categories.
 143   * @param string $p_password  The password of the user.
 144   * @param integer $p_project_id  The id of the project to retrieve the categories for.
 145   * @param string $p_category_name The name of the category to delete
 146   * @return bool returns true or false depending on the success of the delete action
 147   */
 148  
 149  function mc_project_delete_category ($p_username, $p_password, $p_project_id, $p_category_name) {
 150          $t_user_id = mci_check_login( $p_username, $p_password );
 151  
 152          if( $t_user_id === false ) {
 153                  return new soap_fault( 'Client', '', 'Access Denied' );
 154          }
 155  
 156          if( !project_exists( $p_project_id ) ) {
 157                  return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 158          }
 159  
 160          if( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $p_project_id ) ) {
 161                  return new soap_fault( 'Client', '', 'Access Denied' );
 162          }
 163  
 164          // find the id of the category
 165          $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id );
 166  
 167          // delete the category and link all the issue to the general category by default
 168          return category_remove( $p_category_id, 1 );
 169  }
 170  
 171  /**
 172   * Update a category of a project
 173   * @param string $p_username  The name of the user trying to access the categories.
 174   * @param string $p_password  The password of the user.
 175   * @param integer $p_project_id  The id of the project to retrieve the categories for.
 176   * @param string $p_category_name The name of the category to rename
 177   * @param string $p_category_name_new The new name of the category to rename
 178   * @param int $p_assigned_to User ID that category is assigned to
 179   * @return bool returns true or false depending on the success of the update action
 180   */
 181  
 182  function mc_project_rename_category_by_name( $p_username, $p_password, $p_project_id, $p_category_name, $p_category_name_new, $p_assigned_to ) {
 183          $t_user_id = mci_check_login( $p_username, $p_password );
 184  
 185          if ( null === $p_assigned_to ) {
 186                  return new soap_fault( 'Client', '', 'p_assigned_to needed' );
 187          }
 188  
 189          if( $t_user_id === false ) {
 190                  return new soap_fault( 'Client', '', 'Access Denied' );
 191          }
 192  
 193          if( !project_exists( $p_project_id ) ) {
 194                  return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 195          }
 196  
 197          if( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $p_project_id ) ) {
 198                  return new soap_fault( 'Client', '', 'Access Denied' );
 199          }
 200  
 201          // find the id of the category
 202          $p_category_id = category_get_id_by_name( $p_category_name, $p_project_id );
 203  
 204          // update the category
 205          return category_update( $p_category_id, $p_category_name_new, $p_assigned_to );
 206  }
 207  
 208  /**
 209   * Get all versions of a project.
 210   *
 211   * @param string $p_username  The name of the user trying to access the versions.
 212   * @param string $p_password  The password of the user.
 213   * @param integer $p_project_id  The id of the project to retrieve the versions for.
 214   * @return Array  representing a ProjectVersionDataArray structure.
 215   */
 216  function mc_project_get_versions( $p_username, $p_password, $p_project_id ) {
 217      $t_user_id = mci_check_login( $p_username, $p_password );
 218  
 219      if( $t_user_id === false ) {
 220          return mci_soap_fault_login_failed();
 221      }
 222  
 223      if( !project_exists( $p_project_id ) ) {
 224          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 225      }
 226  
 227      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 228          return mci_soap_fault_access_denied( $t_user_id );
 229      }
 230      
 231      $t_result = array();
 232      foreach( version_get_all_rows( $p_project_id, VERSION_ALL ) as $t_version ) {
 233          $t_result[] = mci_project_version_as_array ( $t_version );
 234      }
 235  
 236      return $t_result;
 237  }
 238  
 239  /**
 240   * Get all released versions of a project.
 241   *
 242   * @param string $p_username  The name of the user trying to access the versions.
 243   * @param string $p_password  The password of the user.
 244   * @param integer $p_project_id  The id of the project to retrieve the versions for.
 245   * @return Array  representing a ProjectVersionDataArray structure.
 246   */
 247  function mc_project_get_released_versions( $p_username, $p_password, $p_project_id ) {
 248      $t_user_id = mci_check_login( $p_username, $p_password );
 249  
 250      if( $t_user_id === false ) {
 251          return mci_soap_fault_login_failed();
 252      }
 253  
 254      if( !project_exists( $p_project_id ) ) {
 255          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 256      }
 257  
 258      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 259          return mci_soap_fault_access_denied( $t_user_id );
 260      }
 261  
 262      $t_result = array();
 263  
 264      foreach( version_get_all_rows( $p_project_id, VERSION_RELEASED ) as $t_version ) {
 265          $t_result[] = mci_project_version_as_array ( $t_version );
 266      }
 267  
 268      return $t_result;
 269  }
 270  
 271  /**
 272   * Get all unreleased (a.k.a. future) versions of a project.
 273   *
 274   * @param string $p_username  The name of the user trying to access the versions.
 275   * @param string $p_password  The password of the user.
 276   * @param integer $p_project_id  The id of the project to retrieve the versions for.
 277   * @return Array  representing a ProjectVersionDataArray structure.
 278   */
 279  function mc_project_get_unreleased_versions( $p_username, $p_password, $p_project_id ) {
 280      $t_user_id = mci_check_login( $p_username, $p_password );
 281  
 282      if( $t_user_id === false ) {
 283          return mci_soap_fault_login_failed();
 284      }
 285  
 286      if( !project_exists( $p_project_id ) ) {
 287          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 288      }
 289  
 290      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 291          return mci_soap_fault_access_denied( $t_user_id );
 292      }
 293  
 294      $t_result = array();
 295  
 296      foreach( version_get_all_rows( $p_project_id, VERSION_FUTURE ) as $t_version )
 297          $t_result[] = mci_project_version_as_array ( $t_version );
 298  
 299      return $t_result;
 300  }
 301  
 302  /**
 303   * Submit the specified version details.
 304   *
 305   * @param string $p_username  The name of the user trying to add the issue.
 306   * @param string $p_password  The password of the user.
 307   * @param Array $p_version  A ProjectVersionData structure containing information about the new verison.
 308   * @return integer  The id of the created version.
 309   */
 310  function mc_project_version_add( $p_username, $p_password, $p_version ) {
 311      $t_user_id = mci_check_login( $p_username, $p_password );
 312  
 313      if( $t_user_id === false ) {
 314          return mci_soap_fault_login_failed();
 315      }
 316  
 317      $t_project_id = $p_version['project_id'];
 318      $t_name = $p_version['name'];
 319      $t_released = $p_version['released'];
 320      $t_description = $p_version['description'];
 321      $t_date_order =  $p_version['date_order'];
 322      if ( is_blank( $t_date_order ) ) 
 323          $t_date_order = null;
 324      else 
 325          $t_date_order = date( "Y-m-d H:i:s", strtotime( $t_date_order ) );
 326      
 327      $t_obsolete = isset ( $p_version['obsolete'] ) ? $p_version['obsolete'] : false;
 328      
 329      if ( is_blank( $t_project_id ) ) {
 330          return new soap_fault( 'Client', '', 'Mandatory field "project_id" was missing' );
 331      }
 332  
 333      if ( !project_exists( $t_project_id ) ) {
 334          return new soap_fault( 'Client', '', "Project '$t_project_id' does not exist." );
 335      }
 336  
 337      if ( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
 338          return mci_soap_fault_access_denied( $t_user_id );
 339      }
 340  
 341      if ( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $t_project_id ) ) {
 342          return mci_soap_fault_access_denied( $t_user_id );
 343      }
 344  
 345      if ( is_blank( $t_name ) ) {
 346          return new soap_fault( 'Client', '', 'Mandatory field "name" was missing' );
 347      }
 348  
 349      if ( !version_is_unique( $t_name, $t_project_id ) ) {
 350          return new soap_fault( 'Client', '', 'Version exists for project', 'The version you attempted to add already exists for this project' );
 351      }
 352  
 353      if ( $t_released === false ) {
 354          $t_released = VERSION_FUTURE;
 355      } else {
 356          $t_released = VERSION_RELEASED;
 357      }
 358      
 359      if ( version_add( $t_project_id, $t_name, $t_released, $t_description, $t_date_order, $t_obsolete ) )
 360          return version_get_id( $t_name, $t_project_id );
 361  
 362      return null;
 363  }
 364  
 365  /**
 366   * Submit the specified version details.
 367   *
 368   * @param string $p_username  The name of the user trying to update the issue.
 369   * @param string $p_password  The password of the user.
 370   * @param integer $p_version_id A version's id
 371   * @param Array $p_version  A ProjectVersionData structure containing information about the new verison.
 372   * @return bool returns true or false depending on the success of the update action
 373   */
 374  function mc_project_version_update( $p_username, $p_password, $p_version_id, $p_version ) {
 375      $t_user_id = mci_check_login( $p_username, $p_password );
 376  
 377      if( $t_user_id === false ) {
 378          return mci_soap_fault_login_failed();
 379      }
 380  
 381      if( is_blank( $p_version_id ) ) {
 382          return new soap_fault( 'Client', '', 'Mandatory field "version_id" was missing' );
 383      }
 384  
 385      if( !version_exists( $p_version_id ) ) {
 386          return new soap_fault( 'Client', '', "Version '$p_version_id' does not exist." );
 387      }
 388  
 389      $t_project_id = $p_version['project_id'];
 390      $t_name = $p_version['name'];
 391      $t_released = $p_version['released'];
 392      $t_description = $p_version['description'];
 393      $t_date_order = $p_version['date_order'];
 394      $t_obsolete = isset ( $p_version['obsolete'] ) ? $p_version['obsolete'] : false;
 395  
 396      if ( is_blank( $t_project_id ) ) {
 397          return new soap_fault( 'Client', '', 'Mandatory field "project_id" was missing' );
 398      }
 399  
 400      if ( !project_exists( $t_project_id ) ) {
 401          return new soap_fault( 'Client', '', "Project '$t_project_id' does not exist." );
 402      }
 403  
 404      if ( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
 405          return mci_soap_fault_access_denied( $t_user_id );
 406      }
 407  
 408      if ( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $t_project_id ) ) {
 409          return mci_soap_fault_access_denied( $t_user_id );
 410      }
 411  
 412      if ( is_blank( $t_name ) ) {
 413          return new soap_fault( 'Client', '', 'Mandatory field "name" was missing' );
 414      }
 415  
 416      # check for duplicates
 417      $t_old_version_name = version_get_field( $p_version_id, 'version' );
 418      if ( ( strtolower( $t_old_version_name ) != strtolower( $t_name ) ) && !version_is_unique( $t_name, $t_project_id ) ) {
 419          return new soap_fault( 'Client', '', 'Version exists for project', 'The version you attempted to update already exists for this project' );
 420      }
 421  
 422      if ( $t_released === false ) {
 423          $t_released = VERSION_FUTURE;
 424      } else {
 425          $t_released = VERSION_RELEASED;
 426      }
 427  
 428      $t_version_data = new VersionData();
 429      $t_version_data->id = $p_version_id;
 430      $t_version_data->project_id = $t_project_id;
 431      $t_version_data->version = $t_name;
 432      $t_version_data->description = $t_description;
 433      $t_version_data->released = $t_released;
 434      $t_version_data->date_order = date( "Y-m-d H:i:s", strtotime( $t_date_order ) );
 435      $t_version_data->obsolete = $t_obsolete;
 436  
 437      return version_update( $t_version_data );
 438  }
 439  
 440  /**
 441   * Delete a version.
 442   *
 443   * @param string $p_username  The name of the user trying to delete the version.
 444   * @param string $p_password  The password of the user.
 445   * @param integer $p_version_id A version's id
 446   * @return bool returns true or false depending on the success of the delete action
 447   */
 448  function mc_project_version_delete( $p_username, $p_password, $p_version_id ) {
 449      $t_user_id = mci_check_login( $p_username, $p_password );
 450  
 451      if( $t_user_id === false ) {
 452          return mci_soap_fault_login_failed();
 453      }
 454  
 455      if( is_blank( $p_version_id ) ) {
 456          return new soap_fault( 'Client', '', 'Mandatory field "version_id" was missing' );
 457      }
 458  
 459      if( !version_exists( $p_version_id ) ) {
 460          return new soap_fault( 'Client', '', "Version '$p_version_id' does not exist." );
 461      }
 462  
 463      $t_project_id = version_get_field( $p_version_id, 'project_id' );
 464  
 465      if( !mci_has_readwrite_access( $t_user_id, $t_project_id ) ) {
 466          return mci_soap_fault_access_denied( $t_user_id );
 467      }
 468  
 469      if( !mci_has_access( config_get( 'manage_project_threshold' ), $t_user_id, $t_project_id ) ) {
 470          return mci_soap_fault_access_denied( $t_user_id );
 471      }
 472  
 473      return version_remove( $p_version_id );
 474  }
 475  
 476  /**
 477   * Get the custom fields that belong to the specified project.
 478   *
 479   * @param string $p_username  The name of the user trying to access the versions.
 480   * @param string $p_password  The password of the user.
 481   * @param integer $p_project_id  The id of the project to retrieve the custom fields for.
 482   * @return Array  representing a CustomFieldDefinitionDataArray structure.
 483   */
 484  function mc_project_get_custom_fields( $p_username, $p_password, $p_project_id ) {
 485      $t_user_id = mci_check_login( $p_username, $p_password );
 486  
 487      if( $t_user_id === false ) {
 488          return mci_soap_fault_login_failed();
 489      }
 490  
 491      if( !project_exists( $p_project_id ) ) {
 492          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 493      }
 494  
 495      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 496          return mci_soap_fault_access_denied( $t_user_id );
 497      }
 498  
 499      $t_result = array();
 500      $t_related_custom_field_ids = custom_field_get_linked_ids( $p_project_id );
 501  
 502      foreach( custom_field_get_linked_ids( $p_project_id ) as $t_id ) {
 503          $t_def = custom_field_get_definition( $t_id );
 504          if( access_has_project_level( $t_def['access_level_r'], $p_project_id ) ) {
 505              $t_result[] = array(
 506                  'field' => array(
 507                      'id' => $t_def['id'],
 508                      'name' => $t_def['name'],
 509                  ),
 510                  'type' => $t_def['type'],
 511                  'default_value' => $t_def['default_value'],
 512                  'possible_values' => $t_def['possible_values'],
 513                  'valid_regexp' => $t_def['valid_regexp'],
 514                  'access_level_r' => $t_def['access_level_r'],
 515                  'access_level_rw' => $t_def['access_level_rw'],
 516                  'length_min' => $t_def['length_min'],
 517                  'length_max' => $t_def['length_max'],
 518                  'display_report' => $t_def['display_report'],
 519                  'display_update' => $t_def['display_update'],
 520                  'display_resolved' => $t_def['display_resolved'],
 521                  'display_closed' => $t_def['display_closed'],
 522                  'require_report' => $t_def['require_report'],
 523                  'require_update' => $t_def['require_update'],
 524                  'require_resolved' => $t_def['require_resolved'],
 525                  'require_closed' => $t_def['require_closed'],
 526              );
 527          }
 528      }
 529  
 530      return $t_result;
 531  }
 532  
 533  /**
 534   * Get the attachments that belong to the specified project.
 535   *
 536   * @param string $p_username  The name of the user trying to access the versions.
 537   * @param string $p_password  The password of the user.
 538   * @param integer $p_project_id  The id of the project to retrieve the attachments for.
 539   * @return Array  representing a ProjectAttachmentDataArray structure.
 540   */
 541  function mc_project_get_attachments( $p_username, $p_password, $p_project_id ) {
 542      $t_user_id = mci_check_login( $p_username, $p_password );
 543      if( $t_user_id === false ) {
 544          return mci_soap_fault_login_failed();
 545      }
 546  
 547      # Check if project documentation feature is enabled.
 548      if( OFF == config_get( 'enable_project_documentation' ) || !file_is_uploading_enabled() ) {
 549          return mci_soap_fault_access_denied( $t_user_id );
 550      }
 551  
 552      if( !project_exists( $p_project_id ) ) {
 553          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 554      }
 555  
 556      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 557          return mci_soap_fault_access_denied( $t_user_id );
 558      }
 559  
 560      $t_project_file_table = db_get_table( 'project_file' );
 561      $t_project_table = db_get_table( 'project' );
 562      $t_project_user_list_table = db_get_table( 'project_user_list' );
 563      $t_user_table = db_get_table( 'user' );
 564      $t_pub = VS_PUBLIC;
 565      $t_priv = VS_PRIVATE;
 566      $t_admin = config_get_global( 'admin_site_threshold' );
 567  
 568      if( $p_project_id == ALL_PROJECTS ) {
 569          # Select all the projects that the user has access to
 570          $t_projects = user_get_accessible_projects( $t_user_id );
 571      } else {
 572          # Select the specific project
 573          $t_projects = array(
 574              $p_project_id,
 575          );
 576      }
 577  
 578      $t_projects[] = ALL_PROJECTS; # add ALL_PROJECTS to the list of projects to fetch
 579  
 580  
 581      $t_reqd_access = config_get( 'view_proj_doc_threshold' );
 582      if( is_array( $t_reqd_access ) ) {
 583          if( 1 == count( $t_reqd_access ) ) {
 584              $t_access_clause = "= " . array_shift( $t_reqd_access ) . " ";
 585          } else {
 586              $t_access_clause = "IN (" . implode( ',', $t_reqd_access ) . ")";
 587          }
 588      } else {
 589          $t_access_clause = ">= $t_reqd_access ";
 590      }
 591  
 592      $query = "SELECT pft.id, pft.project_id, pft.filename, pft.file_type, pft.filesize, pft.title, pft.description, pft.date_added, pft.user_id
 593          FROM $t_project_file_table pft
 594          LEFT JOIN $t_project_table pt ON pft.project_id = pt.id
 595          LEFT JOIN $t_project_user_list_table pult
 596          ON pft.project_id = pult.project_id AND pult.user_id = $t_user_id
 597          LEFT JOIN $t_user_table ut ON ut.id = $t_user_id
 598          WHERE pft.project_id in (" . implode( ',', $t_projects ) . ") AND
 599          ( ( ( pt.view_state = $t_pub OR pt.view_state is null ) AND pult.user_id is null AND ut.access_level $t_access_clause ) OR
 600          ( ( pult.user_id = $t_user_id ) AND ( pult.access_level $t_access_clause ) ) OR
 601          ( ut.access_level = $t_admin ) )
 602          ORDER BY pt.name ASC, pft.title ASC";
 603      $result = db_query( $query );
 604      $num_files = db_num_rows( $result );
 605  
 606      $t_result = array();
 607      for( $i = 0;$i < $num_files;$i++ ) {
 608          $row = db_fetch_array( $result );
 609  
 610          $t_attachment = array();
 611          $t_attachment['id'] = $row['id'];
 612          $t_attachment['filename'] = $row['filename'];
 613          $t_attachment['title'] = $row['title'];
 614          $t_attachment['description'] = $row['description'];
 615          $t_attachment['size'] = $row['filesize'];
 616          $t_attachment['content_type'] = $row['file_type'];
 617          $t_attachment['date_submitted'] = timestamp_to_iso8601( $row['date_added'] );
 618          $t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $row['id'] . '&amp;type=doc';
 619          $t_attachment['user_id'] = $row['user_id'];
 620          $t_result[] = $t_attachment;
 621      }
 622  
 623      return $t_result;
 624  }
 625  
 626  function mc_project_get_all_subprojects( $p_username, $p_password, $p_project_id ) {
 627      $t_user_id = mci_check_login( $p_username, $p_password );
 628  
 629      if( $t_user_id === false ) {
 630          return new soap_fault( 'Client', '', 'Access Denied' );
 631      }
 632  
 633      if( !project_exists( $p_project_id ) ) {
 634          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 635      }
 636  
 637      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 638          return mci_soap_fault_access_denied( $t_user_id );
 639      }
 640  
 641      return user_get_all_accessible_subprojects( $t_user_id, $p_project_id );
 642  }
 643  
 644  /**
 645   * Get a project definition.
 646   *
 647   * @param integer $p_project_id  The id of the project to retrieve.
 648   * @return Array an Array containing the id and the name of the project.
 649   */
 650  function mci_project_as_array_by_id( $p_project_id ) {
 651      $t_result = array();
 652      $t_result['id'] = $p_project_id;
 653      $t_result['name'] = project_get_name( $p_project_id );
 654      return $t_result;
 655  }
 656  
 657  /**
 658   * Get the id of a project via the project's name.
 659   *
 660   * @param string $p_username  The name of the user trying to access the versions.
 661   * @param string $p_password  The password of the user.
 662   * @param string $p_project_name  The name of the project to retrieve.
 663   * @return integer  The id of the project with the given name, -1 if there is no such project.
 664   */
 665  function mc_project_get_id_from_name( $p_username, $p_password, $p_project_name ) {
 666          $t_user_id = mci_check_login( $p_username, $p_password );
 667          if( $t_user_id === false ) {
 668                  return mci_soap_fault_login_failed();
 669          }
 670          
 671          return project_get_id_by_name ( $p_project_name );
 672  }
 673  
 674  
 675  ### MantisConnect Administrative Webservices ###
 676  
 677  /**
 678   * Add a new project.
 679   *
 680   * @param string $p_username  The name of the user trying to access the versions.
 681   * @param string $p_password  The password of the user.
 682   * @param Array $p_project A new ProjectData structure
 683   * @return integer the new project's project_id
 684   */
 685  function mc_project_add( $p_username, $p_password, $p_project ) {
 686      $t_user_id = mci_check_login( $p_username, $p_password );
 687      if( $t_user_id === false ) {
 688          return mci_soap_fault_login_failed();
 689      }
 690  
 691      if( !mci_has_administrator_access( $t_user_id ) ) {
 692          return mci_soap_fault_access_denied( $t_user_id );
 693      }
 694  
 695      if ( !isset( $p_project['name'] ) ) {
 696          return new soap_fault( 'Client', '', 'Missing Field', 'Required Field Missing' );
 697      } else {
 698          $t_name = $p_project['name'];
 699      }
 700  
 701      if( isset( $p_project['status'] ) ) {
 702          $t_status = $p_project['status'];
 703      } else {
 704          $t_status = array( 'name' => 'development' ); // development
 705      }
 706  
 707      if( isset( $p_project['view_state'] ) ) {
 708          $t_view_state = $p_project['view_state'];
 709      } else {
 710          $t_view_state = array( 'id' => VS_PUBLIC );
 711      }
 712  
 713      if ( isset( $p_project['enabled'] ) ) {
 714          $t_enabled = $p_project['enabled'];
 715      } else {
 716          $t_enabled = true;
 717      }
 718  
 719      if ( isset( $p_project['description'] ) ) {
 720          $t_description = $p_project['description'];
 721      } else {
 722          $t_description = '';
 723      }
 724  
 725      if ( isset( $p_project['file_path'] ) ) {
 726          $t_file_path = $p_project['file_path'];
 727      } else {
 728          $t_file_path = '';
 729      }
 730  
 731      if ( isset( $p_project['inherit_global'] ) ) {
 732          $t_inherit_global = $p_project['inherit_global'];
 733      } else {
 734          $t_inherit_global = true;
 735      }
 736  
 737      // check to make sure project doesn't already exist
 738      if( !project_is_name_unique( $t_name ) ) {
 739          return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' );
 740      }
 741  
 742      $t_project_status = mci_get_project_status_id( $t_status );
 743      $t_project_view_state = mci_get_project_view_state_id( $t_view_state );
 744  
 745      // project_create returns the new project's id, spit that out to webservice caller
 746      return project_create( $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global );
 747  }
 748  
 749  /**
 750   * Update a project
 751   *
 752   * @param string $p_username  The name of the user
 753   * @param string $p_password  The password of the user
 754   * @param integer $p_project_id A project's id
 755   * @param Array $p_project A new ProjectData structure
 756   * @return bool returns true or false depending on the success of the update action
 757   */
 758  function mc_project_update( $p_username, $p_password, $p_project_id, $p_project ) {
 759      $t_user_id = mci_check_login( $p_username, $p_password );
 760      if( $t_user_id === false ) {
 761          return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect' );
 762      }
 763  
 764      if( !mci_has_administrator_access( $t_user_id, $p_project_id ) ) {
 765          return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access' );
 766      }
 767  
 768      if( !project_exists( $p_project_id ) ) {
 769          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 770      }
 771  
 772      if ( !isset( $p_project['name'] ) ) {
 773          return new soap_fault( 'Client', '', 'Missing Field', 'Required Field Missing' );
 774      } else {
 775          $t_name = $p_project['name'];
 776      }
 777  
 778      // check to make sure project doesn't already exist
 779      if ( $t_name != project_get_name( $p_project_id ) ) {
 780          if( !project_is_name_unique( $t_name ) ) {
 781              return new soap_fault( 'Client', '', 'Project name exists', 'The project name you attempted to add exists already' );
 782          }
 783      }
 784  
 785      if ( !isset( $p_project['description'] ) ) {
 786          $t_description = project_get_field( $p_project_id, 'description' );
 787      } else {
 788          $t_description = $p_project['description'];
 789      }
 790  
 791      if ( !isset( $p_project['status'] ) ) {
 792          $t_status = project_get_field( $p_project_id, 'status' );
 793      } else {
 794          $t_status = $p_project['status'];
 795      }
 796  
 797      if ( !isset( $p_project['view_state'] ) ) {
 798          $t_view_state = project_get_field( $p_project_id, 'view_state' );
 799      } else {
 800          $t_view_state = $p_project['view_state'];
 801      }
 802  
 803      if ( !isset( $p_project['file_path'] ) ) {
 804          $t_file_path = project_get_field( $p_project_id, 'file_path' );
 805      } else {
 806          $t_file_path = $p_project['file_path'];
 807      }
 808  
 809      if ( !isset( $p_project['enabled'] ) ) {
 810          $t_enabled = project_get_field( $p_project_id, 'enabled' );
 811      } else {
 812          $t_enabled = $p_project['enabled'];
 813      }
 814  
 815      if ( !isset( $p_project['inherit_global'] ) ) {
 816          $t_inherit_global = project_get_field( $p_project_id, 'inherit_global' );
 817      } else {
 818          $t_inherit_global = $p_project['inherit_global'];
 819      }
 820  
 821      $t_project_status = mci_get_project_status_id( $t_status );
 822      $t_project_view_state = mci_get_project_view_state_id( $t_view_state );
 823  
 824      return project_update( $p_project_id, $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global );
 825  }
 826  
 827  /**
 828   * Delete a project.
 829   *
 830   * @param string $p_username  The name of the user trying to access the versions.
 831   * @param string $p_password  The password of the user.
 832   * @param integer $p_project_id A project's id
 833   * @return bool returns true or false depending on the success of the delete action
 834   */
 835  function mc_project_delete( $p_username, $p_password, $p_project_id ) {
 836      $t_user_id = mci_check_login( $p_username, $p_password );
 837      if( $t_user_id === false ) {
 838          return mci_soap_fault_login_failed();
 839      }
 840  
 841      if( !project_exists( $p_project_id ) ) {
 842          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 843      }
 844  
 845      if( !mci_has_administrator_access( $t_user_id, $p_project_id ) ) {
 846          return mci_soap_fault_access_denied( $t_user_id );
 847      }
 848  
 849      return project_delete( $p_project_id );
 850  }
 851  
 852  function mc_project_get_issue_headers( $p_username, $p_password, $p_project_id, $p_page_number, $p_per_page ) {
 853      $t_user_id = mci_check_login( $p_username, $p_password );
 854      if( $t_user_id === false ) {
 855          return mci_soap_fault_login_failed();
 856      }
 857      if( !project_exists( $p_project_id ) ) {
 858          return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 859      }
 860  
 861      if( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 862          return mci_soap_fault_access_denied( $t_user_id );
 863      }
 864      
 865      $t_orig_page_number = $p_page_number < 1 ? 1 : $p_page_number;
 866      $t_page_count = 0;
 867      $t_bug_count = 0;
 868  
 869      $t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );
 870      $t_result = array();
 871      
 872      // the page number was moved back, so we have exceeded the actual page number, see bug #12991
 873      if ( $t_orig_page_number > $p_page_number )
 874          return $t_result;
 875  
 876      foreach( $t_rows as $t_issue_data ) {
 877          $t_id = $t_issue_data->id;
 878  
 879          $t_issue = array();
 880  
 881          $t_issue['id'] = $t_id;
 882          $t_issue['view_state'] = $t_issue_data->view_state;
 883          $t_issue['last_updated'] = timestamp_to_iso8601( $t_issue_data->last_updated );
 884  
 885          $t_issue['project'] = $t_issue_data->project_id;
 886          $t_issue['category'] = mci_get_category( $t_issue_data->category_id );
 887          $t_issue['priority'] = $t_issue_data->priority;
 888          $t_issue['severity'] = $t_issue_data->severity;
 889          $t_issue['status'] = $t_issue_data->status;
 890  
 891          $t_issue['reporter'] = $t_issue_data->reporter_id;
 892          $t_issue['summary'] = $t_issue_data->summary;
 893          if( !empty( $t_issue_data->handler_id ) ) {
 894              $t_issue['handler'] = $t_issue_data->handler_id;
 895          }
 896          $t_issue['resolution'] = $t_issue_data->resolution;
 897  
 898          $t_issue['attachments_count'] = count( mci_issue_get_attachments( $t_issue_data->id ) );
 899          $t_issue['notes_count'] = count( mci_issue_get_notes( $t_issue_data->id ) );
 900  
 901          $t_result[] = $t_issue;
 902      }
 903  
 904      return $t_result;
 905  }
 906  
 907  /**
 908   * Get appropriate users assigned to a project by access level.
 909   *
 910   * @param string $p_username  The name of the user trying to access the versions.
 911   * @param string $p_password  The password of the user.
 912   * @param integer $p_project_id  The id of the project to retrieve the users for.
 913   * @param integer $p_access Minimum access level.
 914   * @return Array  representing a ProjectAttachmentDataArray structure.
 915   */
 916  function mc_project_get_users( $p_username, $p_password, $p_project_id, $p_access ) {
 917      $t_user_id = mci_check_login( $p_username, $p_password );
 918  
 919      if( $t_user_id === false ) {
 920          return mci_soap_fault_login_failed();
 921      }
 922  
 923      $t_users = array();
 924  
 925      $t_users = project_get_all_user_rows( $p_project_id, $p_access ); # handles ALL_PROJECTS case
 926  
 927      $t_display = array();
 928      $t_sort = array();
 929      $t_show_realname = ( ON == config_get( 'show_realname' ) );
 930      $t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
 931      foreach( $t_users as $t_user ) {
 932          $t_user_name = string_attribute( $t_user['username'] );
 933          $t_sort_name = strtolower( $t_user_name );
 934          if( $t_show_realname && ( $t_user['realname'] <> "" ) ) {
 935              $t_user_name = string_attribute( $t_user['realname'] );
 936              if( $t_sort_by_last_name ) {
 937                  $t_sort_name_bits = explode( ' ', strtolower( $t_user_name ), 2 );
 938                  $t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
 939              } else {
 940                  $t_sort_name = strtolower( $t_user_name );
 941              }
 942          }
 943          $t_display[] = $t_user_name;
 944          $t_sort[] = $t_sort_name;
 945      }
 946      array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
 947  
 948      $t_result = array();
 949      for( $i = 0;$i < count( $t_sort );$i++ ) {
 950          $t_row = $t_users[$i];
 951  
 952          // This is not very performant - But we have to assure that the data returned is exactly
 953          // the same as the data that comes with an issue (test for equality - $t_row[] does not
 954          // contain email fields).
 955          $t_result[] = mci_account_get_array_by_id( $t_row['id'] );
 956      }
 957      return $t_result;
 958  }


Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7