[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

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

   1  <?php
   2      # MantisConnect - A webservice interface to Mantis Bug Tracker
   3      # Copyright (C) 2004-2007  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      # --------------------------------------------------------
  10      # $Id: mc_project_api.php,v 1.1 2007-07-18 06:52:56 vboctor Exp $
  11      # --------------------------------------------------------
  12      
  13  	function mc_project_get_issues( $p_username, $p_password, $p_project_id , $p_page_number, $p_per_page ) {
  14          $t_user_id = mci_check_login( $p_username, $p_password );
  15          $t_lang = mci_get_user_lang( $t_user_id );
  16          if ( $t_user_id === false ) {
  17              return new soap_fault( 'Client', '', 'Access Denied' );
  18          }
  19          if ( !project_exists( $p_project_id ) ) {
  20              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
  21          }
  22  
  23          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
  24              return new soap_fault( 'Client', '', 'Access Denied' );
  25          }
  26  
  27          $t_page_count = 0;
  28          $t_bug_count = 0;    
  29  
  30          $t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );
  31          $t_result = array();
  32  
  33          foreach( $t_rows as $t_issue_data ) {
  34              $t_id = $t_issue_data['id'];
  35  
  36              $t_issue = array();
  37              $t_issue['id'] = $t_id;
  38              $t_issue['view_state'] = mci_enum_get_array_by_id( $t_issue_data['view_state'], 'view_state', $t_lang );
  39              $t_issue['last_updated'] = timestamp_to_iso8601( $t_issue_data['last_updated'] );
  40  
  41              $t_issue['project'] = mci_project_as_array_by_id( $t_issue_data['project_id'] );
  42              $t_issue['category'] = mci_null_if_empty( $t_issue_data['category'] );
  43              $t_issue['priority'] = mci_enum_get_array_by_id( $t_issue_data['priority'], 'priority', $t_lang );
  44              $t_issue['severity'] = mci_enum_get_array_by_id( $t_issue_data['severity'], 'severity', $t_lang );
  45              $t_issue['status'] = mci_enum_get_array_by_id( $t_issue_data['status'], 'status', $t_lang );
  46  
  47              $t_issue['reporter'] = mci_account_get_array_by_id( $t_issue_data['reporter_id'] );
  48              $t_issue['summary'] = $t_issue_data['summary'];
  49              $t_issue['version'] = mci_null_if_empty( $t_issue_data['version'] );
  50              $t_issue['build'] = mci_null_if_empty( $t_issue_data['build'] );
  51              $t_issue['platform'] = mci_null_if_empty( $t_issue_data['platform'] );
  52              $t_issue['os'] = mci_null_if_empty( $t_issue_data['os'] );
  53              $t_issue['os_build'] = mci_null_if_empty( $t_issue_data['os_build'] );
  54              $t_issue['reproducibility'] = mci_enum_get_array_by_id( $t_issue_data['reproducibility'], 'reproducibility', $t_lang );
  55              $t_issue['date_submitted'] = timestamp_to_iso8601( $t_issue_data['date_submitted'] );
  56              $t_issue['sponsorship_total'] = $t_issue_data['sponsorship_total'];
  57  
  58              if( !empty( $t_issue_data['handler_id'] ) ) {
  59                  $t_issue['handler'] = mci_account_get_array_by_id( $t_issue_data['handler_id'] );
  60              }
  61              $t_issue['projection'] = mci_enum_get_array_by_id( $t_issue_data['projection'], 'projection', $t_lang );
  62              $t_issue['eta'] = mci_enum_get_array_by_id( $t_issue_data['eta'], 'eta', $t_lang );
  63  
  64              $t_issue['resolution'] = mci_enum_get_array_by_id( $t_issue_data['resolution'], 'resolution', $t_lang );
  65              $t_issue['fixed_in_version'] = mci_null_if_empty( $t_issue_data['fixed_in_version'] );
  66  
  67              $t_issue['description'] = bug_get_text_field( $t_id, 'description' );
  68              $t_issue['steps_to_reproduce'] = mci_null_if_empty( bug_get_text_field( $t_id, 'steps_to_reproduce' ) );
  69              $t_issue['additional_information'] = mci_null_if_empty( bug_get_text_field( $t_id, 'additional_information' ) );
  70  
  71              $t_issue['attachments'] = mci_issue_get_attachments( $t_issue_data['id'] );
  72              $t_issue['relationships'] = mci_issue_get_relationships( $t_issue_data['id'], $t_user_id );
  73              $t_issue['notes'] = mci_issue_get_notes( $t_issue_data['id'] );
  74              $t_issue['custom_fields'] = mci_issue_get_custom_fields( $t_issue_data['id'] );
  75  
  76              $t_result[] = $t_issue;
  77          }
  78          
  79          return $t_result;
  80      }
  81  
  82  
  83      /**
  84       * Get all projects accessible by the given user.
  85       *
  86       * @param string $p_username  The name of the user trying to access the project list.
  87       * @param string $p_password  The password of the user.
  88       * @return Array  suitable to be converted into a ProjectDataArray
  89       */
  90  	function mc_projects_get_user_accessible( $p_username, $p_password ) {
  91          $t_user_id = mci_check_login( $p_username, $p_password );
  92          $t_lang = mci_get_user_lang( $t_user_id );
  93          if ( $t_user_id === false ) {
  94              return new soap_fault( 'Client', '', 'Access Denied' );
  95          }
  96  
  97          if ( !mci_has_readonly_access( $t_user_id ) ) {
  98              return new soap_fault( 'Client', '', 'Access Denied' );
  99          }
 100  
 101          $t_result = array();
 102          foreach( user_get_accessible_projects( $t_user_id ) as $t_project_id ) {
 103              $t_project_row = project_cache_row( $t_project_id );
 104              $t_project = array();
 105              $t_project['id'] = $t_project_id;
 106              $t_project['name'] = $t_project_row['name'];
 107              $t_project['status'] = mci_enum_get_array_by_id( $t_project_row['status'], 'project_status', $t_lang );
 108              $t_project['enabled'] = $t_project_row['enabled'];
 109              $t_project['view_state'] = mci_enum_get_array_by_id( $t_project_row['view_state'], 'project_view_state', $t_lang );
 110              $t_project['access_min'] = mci_enum_get_array_by_id( $t_project_row['access_min'], 'access_levels', $t_lang );
 111              $t_project['file_path'] =
 112                  array_key_exists( 'file_path', $t_project_row ) ? $t_project_row['file_path'] : "";
 113              $t_project['description'] =
 114                  array_key_exists( 'description', $t_project_row ) ? $t_project_row['description'] : "";
 115              $t_project['subprojects'] = mci_user_get_accessible_subprojects( $t_user_id, $t_project_id );
 116              $t_result[] = $t_project;
 117          }
 118          return $t_result;
 119      }
 120  
 121      /**
 122       * Get all categories of a project.
 123       *
 124       * @param string $p_username  The name of the user trying to access the categories.
 125       * @param string $p_password  The password of the user.
 126       * @param integer $p_project_id  The id of the project to retrieve the categories for.
 127       * @return Array  of categorie names
 128       */
 129  	function mc_project_get_categories( $p_username, $p_password, $p_project_id ) {
 130          $t_user_id = mci_check_login( $p_username, $p_password );
 131  
 132          if ( $t_user_id === false ) {
 133              return new soap_fault( 'Client', '', 'Access Denied' );
 134          }
 135  
 136          if ( !project_exists( $p_project_id ) ) {
 137              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 138          }
 139  
 140          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 141              return new soap_fault( 'Client', '', 'Access Denied' );
 142          }
 143          
 144          return mci_category_get_all_rows( $p_project_id, $t_user_id );
 145      }
 146  
 147      /**
 148       * Get all versions of a project.
 149       *
 150       * @param string $p_username  The name of the user trying to access the versions.
 151       * @param string $p_password  The password of the user.
 152       * @param integer $p_project_id  The id of the project to retrieve the versions for.
 153       * @return Array  representing a ProjectVersionDataArray structure.
 154       */
 155  	function mc_project_get_versions( $p_username, $p_password, $p_project_id ) {
 156          $t_user_id = mci_check_login( $p_username, $p_password );
 157  
 158          if ( $t_user_id === false ) {
 159              return new soap_fault( 'Client', '', 'Access Denied' );
 160          }
 161  
 162          if ( !project_exists( $p_project_id ) ) {
 163              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 164          }
 165  
 166          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 167              return new soap_fault( 'Client', '', 'Access Denied' );
 168          }
 169  
 170          $t_result = array();
 171          foreach( version_get_all_rows( $p_project_id, VERSION_ALL ) as $t_version) {
 172              $t_result[] = array(
 173                  'id'            => $t_version['id'],
 174                  'name'            => $t_version['version'],
 175                  'project_id'    => $p_project_id,
 176                  'date_order'    => timestamp_to_iso8601( $t_version['date_order'] ),
 177                  'description'    => mci_null_if_empty( $t_version['description'] ),
 178                  'released'        => $t_version['released'],
 179              );
 180          }
 181  
 182          return $t_result;
 183      }
 184  
 185      /**
 186       * Get all released versions of a project.
 187       *
 188       * @param string $p_username  The name of the user trying to access the versions.
 189       * @param string $p_password  The password of the user.
 190       * @param integer $p_project_id  The id of the project to retrieve the versions for.
 191       * @return Array  representing a ProjectVersionDataArray structure.
 192       */
 193  	function mc_project_get_released_versions( $p_username, $p_password, $p_project_id ) {
 194          $t_user_id = mci_check_login( $p_username, $p_password );
 195  
 196          if ( $t_user_id === false ) {
 197              return new soap_fault( 'Client', '', 'Access Denied' );
 198          }
 199  
 200          if ( !project_exists( $p_project_id ) ) {
 201              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 202          }
 203  
 204          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 205              return new soap_fault( 'Client', '', 'Access Denied' );
 206          }
 207  
 208          $t_result = array();
 209  
 210          foreach( version_get_all_rows( $p_project_id, VERSION_RELEASED ) as $t_version) {
 211              $t_result[] = array(
 212                  'id'            => $t_version['id'],
 213                  'name'            => $t_version['version'],
 214                  'project_id'    => $p_project_id,
 215                  'date_order'    => timestamp_to_iso8601( db_unixtimestamp( $t_version['date_order'] ) ),
 216                  'description'    => mci_null_if_empty( $t_version['description'] ),
 217                  'released'        => $t_version['released'],
 218              );
 219          }
 220  
 221          return $t_result;
 222      }
 223  
 224      /**
 225       * Get all unreleased (a.k.a. future) versions of a project.
 226       *
 227       * @param string $p_username  The name of the user trying to access the versions.
 228       * @param string $p_password  The password of the user.
 229       * @param integer $p_project_id  The id of the project to retrieve the versions for.
 230       * @return Array  representing a ProjectVersionDataArray structure.
 231       */
 232  	function mc_project_get_unreleased_versions( $p_username, $p_password, $p_project_id ) {
 233          $t_user_id = mci_check_login( $p_username, $p_password );
 234  
 235          if ( $t_user_id === false ) {
 236              return new soap_fault( 'Client', '', 'Access Denied' );
 237          }
 238  
 239          if ( !project_exists( $p_project_id ) ) {
 240              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 241          }
 242  
 243          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 244              return new soap_fault( 'Client', '', 'Access Denied' );
 245          }
 246  
 247          $t_result = array();
 248  
 249          foreach( version_get_all_rows( $p_project_id, VERSION_FUTURE ) as $t_version) {
 250              $t_result[] = array(
 251                  'id'            => $t_version['id'],
 252                  'name'            => $t_version['version'],
 253                  'project_id'    => $p_project_id,
 254                  'date_order'    => timestamp_to_iso8601( $t_version['date_order'] ),
 255                  'description'    => mci_null_if_empty( $t_version['description'] ),
 256                  'released'        => $t_version['released'],
 257              );
 258          }
 259  
 260          return $t_result;
 261      }
 262      
 263      /**
 264       * Submit the specified version details.
 265       *
 266       * @param string $p_username  The name of the user trying to add the issue.
 267       * @param string $p_password  The password of the user.
 268       * @param Array $p_version  A ProjectVersionData structure containing information about the new verison.
 269       * @return integer  The id of the created version.
 270       */     
 271  	function mc_project_version_add( $p_username, $p_password, $p_version ) {
 272          $t_user_id = mci_check_login( $p_username, $p_password );        
 273          if ( $t_user_id === false ) {
 274              return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect');
 275          }
 276          if ( !mci_has_administrator_access( $t_user_id ) ) {
 277              return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access');
 278          }
 279          extract( $p_version, EXTR_PREFIX_ALL, 'v');
 280          if ( is_blank( $v_project_id ) ) {
 281              return new soap_fault('Client', '', 'Mandatory field "project_id" was missing');
 282          }
 283          if ( is_blank( $v_name ) ) {
 284              return new soap_fault('Client', '', 'Mandatory field "name" was missing');
 285          }
 286          if ( !version_is_unique( $v_name, $v_project_id ) ) {
 287              return new soap_fault( 'Client', '', 'Version exists for project', 'The version you attempted to add already exists for this project');
 288          }
 289          if ( $v_released === false ) {
 290              $v_released = VERSION_FUTURE;
 291          } else {
 292              $v_released = VERSION_RELEASED;
 293          }
 294          if ( version_add( $v_project_id, $v_name, $v_released, $v_description ) ) {
 295              $t_version_id = version_get_id( $v_name, $v_project_id );
 296              if ( !is_blank( $v_date_order ) ) {
 297                  $t_version = version_get( $t_version_id );
 298                  $t_version->date_order = $v_date_order;
 299                  version_update( $t_version );
 300              }
 301              return $t_version_id;
 302          } else {
 303              return null;
 304          }
 305      }
 306      
 307      /**
 308       * Submit the specified version details.
 309       *
 310       * @param string $p_username  The name of the user trying to update the issue.
 311       * @param string $p_password  The password of the user.
 312       * @param integer $p_version_id A version's id
 313       * @param Array $p_version  A ProjectVersionData structure containing information about the new verison.
 314       * @return bool returns true or false depending on the success of the update action
 315       */     
 316  	function mc_project_version_update( $p_username, $p_password, $p_version_id, $p_version ) {
 317          $t_user_id = mci_check_login( $p_username, $p_password );        
 318          if ( $t_user_id === false ) {
 319              return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect');
 320          }
 321          if ( !mci_has_administrator_access( $t_user_id ) ) {
 322              return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access');
 323          }
 324          if ( is_blank( $p_version_id ) ) {
 325              return new soap_fault('Client', '', 'Mandatory field "version_id" was missing');
 326          }
 327          if ( !version_exists( $p_version_id ) ) {
 328              return new soap_fault( 'Client', '', "Version '$p_version_id' does not exist." );
 329          }
 330          extract( $p_version, EXTR_PREFIX_ALL, 'v');
 331          if ( is_blank( $v_project_id ) ) {
 332              return new soap_fault('Client', '', 'Mandatory field "project_id" was missing');
 333          }
 334          if ( !project_exists( $v_project_id ) ) {
 335              return new soap_fault( 'Client', '', "Version '$v_project_id' does not exist." );
 336          }
 337          if ( is_blank( $v_name ) ) {
 338              return new soap_fault('Client', '', 'Mandatory field "name" was missing');
 339          }
 340          # check for duplicates
 341          $t_old_version_name = version_get_field( $p_version_id, 'version' );
 342          if ( ( strtolower( $t_old_version_name ) != strtolower( $v_name ) ) && !version_is_unique( $v_name, $v_project_id ) ) {
 343              return new soap_fault( 'Client', '', 'Version exists for project', 'The version you attempted to update already exists for this project');
 344          }
 345          if ( $v_released === false ) {
 346              $v_released = VERSION_FUTURE;
 347          } else {
 348              $v_released = VERSION_RELEASED;
 349          }
 350          $t_version_data = new VersionData();
 351          $t_version_data->id = $p_version_id;
 352          $t_version_data->project_id = $v_project_id;
 353          $t_version_data->version = $v_name;
 354          $t_version_data->description = $v_description;
 355          $t_version_data->released = $v_released;
 356          $t_version_data->date_order = $v_date_order;
 357          return version_update( $t_version_data );
 358      }
 359      
 360      /** 
 361       * Delete a version.
 362       *
 363       * @param string $p_username  The name of the user trying to delete the version.
 364       * @param string $p_password  The password of the user.
 365       * @param integer $p_version_id A version's id
 366       * @return bool returns true or false depending on the success of the delete action
 367       */
 368  	function mc_project_version_delete( $p_username, $p_password, $p_version_id ) {
 369          $t_user_id = mci_check_login( $p_username, $p_password );        
 370          if ( $t_user_id === false ) {
 371              return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect');
 372          }
 373          if ( !mci_has_administrator_access( $t_user_id ) ) {
 374              return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access');
 375          }
 376          if ( is_blank( $p_version_id ) ) {
 377              return new soap_fault('Client', '', 'Mandatory field "version_id" was missing');
 378          }
 379          if ( !version_exists( $p_version_id ) ) {
 380              return new soap_fault( 'Client', '', "Version '$p_version_id' does not exist." );
 381          }
 382          return version_remove( $p_version_id );
 383      }
 384      
 385      /**
 386       * Get the custom fields that belong to the specified project.
 387       *
 388       * @param string $p_username  The name of the user trying to access the versions.
 389       * @param string $p_password  The password of the user.
 390       * @param integer $p_project_id  The id of the project to retrieve the custom fields for.
 391       * @return Array  representing a CustomFieldDefinitionDataArray structure.
 392       */
 393  	function mc_project_get_custom_fields( $p_username, $p_password, $p_project_id ) {
 394          $t_user_id = mci_check_login( $p_username, $p_password );
 395  
 396          if ( $t_user_id === false ) {
 397              return new soap_fault( 'Client', '', 'Access Denied' );
 398          }
 399  
 400          if ( !project_exists( $p_project_id ) ) {
 401              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 402          }
 403  
 404          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 405              return new soap_fault( 'Client', '', 'Access Denied' );
 406          }
 407  
 408          $t_result = array();
 409          
 410          $t_related_custom_field_ids = custom_field_get_linked_ids( $p_project_id );
 411          
 412  
 413          foreach( custom_field_get_linked_ids( $p_project_id ) as $t_id ) {
 414              $t_def = custom_field_get_definition( $t_id );
 415              if ( access_has_project_level( $t_def['access_level_r'], $p_project_id ) ) {
 416                  $t_result[] = array(
 417                      'field'                => array( 'id' => $t_def['id'], 'name' => $t_def['name'] ),
 418                      'type'                => $t_def['type'],
 419                      'default_value'        => $t_def['default_value'],
 420                      'possible_values'    => $t_def['possible_values'],
 421                      'valid_regexp'        => $t_def['valid_regexp'],
 422                      'access_level_r'    => $t_def['access_level_r'],
 423                      'access_level_rw'    => $t_def['access_level_rw'],
 424                      'length_min'        => $t_def['length_min'],
 425                      'length_max'        => $t_def['length_max'],
 426                      'advanced'            => $t_def['advanced'],
 427                      'display_report'    => $t_def['display_report'],
 428                      'display_update'    => $t_def['display_update'],
 429                      'display_resolved'    => $t_def['display_resolved'],
 430                      'display_closed'    => $t_def['display_closed'],
 431                      'require_report'    => $t_def['require_report'],
 432                      'require_update'    => $t_def['require_update'],
 433                      'require_resolved'    => $t_def['require_resolved'],
 434                      'require_closed'    => $t_def['require_closed'],
 435                  );
 436              }
 437          }
 438  
 439          return $t_result;
 440      }
 441  
 442      /**
 443       * Get the attachments that belong to the specified project.
 444       *
 445       * @param string $p_username  The name of the user trying to access the versions.
 446       * @param string $p_password  The password of the user.
 447       * @param integer $p_project_id  The id of the project to retrieve the attachments for.
 448       * @return Array  representing a ProjectAttachmentDataArray structure.
 449       */
 450  	function mc_project_get_attachments( $p_username, $p_password, $p_project_id ) {
 451          $t_user_id = mci_check_login( $p_username, $p_password );
 452          if ( $t_user_id === false ) {
 453              return new soap_fault( 'Client', '', 'Access Denied' );
 454          }
 455  
 456          # Check if project documentation feature is enabled.
 457          if ( OFF == config_get( 'enable_project_documentation' ) || !file_is_uploading_enabled() ) {
 458              return new soap_fault( 'Client', '', 'Access Denied' );
 459          }
 460      
 461          if ( !project_exists( $p_project_id ) ) {
 462              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 463          }
 464  
 465          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 466              return new soap_fault( 'Client', '', 'Access Denied' );
 467          }
 468  
 469          $t_project_file_table = config_get( 'mantis_project_file_table' );
 470          $t_project_table = config_get( 'mantis_project_table' );
 471          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 472          $t_user_table = config_get( 'mantis_user_table' );
 473          $t_pub = VS_PUBLIC;
 474          $t_priv = VS_PRIVATE;
 475          $t_admin = ADMINISTRATOR;
 476      
 477          if ( $t_project_id == ALL_PROJECTS ) {
 478              # Select all the projects that the user has access to
 479              $t_projects = user_get_accessible_projects( $t_user_id );
 480          } else {
 481              # Select the specific project 
 482              $t_projects = array( $t_project_id );
 483          }
 484              
 485          $t_projects[] = ALL_PROJECTS; # add ALL_PROJECTS to the list of projects to fetch
 486          
 487          $t_reqd_access = config_get( 'view_proj_doc_threshold' );
 488          if ( is_array( $t_reqd_access ) ) {
 489              if ( 1 == count( $t_reqd_access ) ) {
 490                  $t_access_clause = "= " . array_shift( $t_reqd_access ) . " ";
 491              } else {
 492                  $t_access_clause = "IN (" . implode( ',', $t_reqd_access ) . ")";
 493              }
 494          } else {
 495              $t_access_clause = ">= $t_reqd_access ";
 496          }            
 497      
 498          $query = "SELECT pft.id, pft.project_id, pft.filename, pft.file_type, pft.filesize, pft.title, pft.description, pft.date_added
 499                      FROM $t_project_file_table pft
 500                          LEFT JOIN $t_project_table pt ON pft.project_id = pt.id
 501                          LEFT JOIN $t_project_user_list_table pult 
 502                              ON pft.project_id = pult.project_id AND pult.user_id = $t_user_id
 503                          LEFT JOIN $t_user_table ut ON ut.id = $t_user_id
 504                      WHERE pft.project_id in (" . implode( ',', $t_projects ) . ") AND
 505                          ( ( ( 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
 506                              ( ( pult.user_id = $t_user_id ) AND ( pult.access_level $t_access_clause ) ) OR
 507                              ( ut.access_level = $t_admin ) )
 508                      ORDER BY pt.name ASC, pft.title ASC";
 509          $result = db_query( $query );
 510          $num_files = db_num_rows( $result );
 511          
 512          $t_result = array();
 513          for ($i=0;$i<$num_files;$i++) {
 514              $row = db_fetch_array( $result );
 515              extract( $row, EXTR_PREFIX_ALL, 'v' );
 516              $t_attachment = array();
 517              $t_attachment['id'] = $v_id;
 518              $t_attachment['filename'] = $v_filename;
 519              $t_attachment['title'] = $v_title;
 520              $t_attachment['description'] = $v_description;
 521              $t_attachment['size'] = $v_filesize;
 522              $t_attachment['content_type'] = $v_file_type;
 523              $t_attachment['date_submitted'] = timestamp_to_iso8601( db_unixtimestamp( $v_date_added ) );
 524              $t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $v_id . '&amp;type=doc';
 525              $t_result[] = $t_attachment;
 526          }
 527  
 528          return $t_result;
 529      }
 530  
 531      /**
 532       * Get a project definition.
 533       *
 534       * @param integer $p_project_id  The id of the project to retrieve.
 535       * @return Array an Array containing the id and the name of the project.
 536       */
 537  	function mci_project_as_array_by_id( $p_project_id ) {
 538          $t_result = array();
 539          $t_result['id'] = $p_project_id;
 540          $t_result['name'] = project_get_name( $p_project_id );
 541          return $t_result;
 542      }
 543  
 544      ### MantisConnect Administrative Webservices ###
 545      
 546      /** 
 547       * Add a new project.
 548       *
 549       * @param string $p_username  The name of the user trying to access the versions.
 550       * @param string $p_password  The password of the user.
 551       * @param Array $p_project A new ProjectData structure
 552       * @return integer the new project's project_id
 553       */
 554  	function mc_project_add( $p_username, $p_password, $p_project ) {
 555          $t_user_id = mci_check_login( $p_username, $p_password );        
 556          if ( $t_user_id === false ) {
 557              return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect');
 558          }
 559  
 560          if ( !mci_has_administrator_access( $t_user_id ) ) {
 561              return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access');
 562          }
 563  
 564          extract( $p_project, EXTR_PREFIX_ALL, 'v');
 565  
 566      /*    if ( is_blank($v_name) )
 567              return new soap_fault('Client', '', 'Mandatory field "name" was missing');
 568      */    
 569          // check to make sure project doesn't already exist
 570          if ( !project_is_name_unique( $v_name ) ) {
 571              return new soap_fault( 'Client', '', 'Project name exists', 
 572                      'The project name you attempted to add exists already');
 573          }
 574  
 575          if ( is_blank( $v_status ) ) {
 576              $v_status = array( 'name' => 'development' ); // development
 577          }
 578  
 579          if ( is_blank( $v_view_state ) ) {
 580              $v_view_state = array( 'id' => VS_PUBLIC );
 581          }
 582  
 583          if ( is_blank( $v_enabled ) ) {
 584              $v_enabled = true;
 585          }
 586  
 587          $t_project_status = mci_get_project_status_id( $v_status );
 588          $t_project_view_state = mci_get_project_view_state_id( $v_view_state );
 589  
 590          // project_create returns the new project's id, spit that out to webservice caller
 591          return project_create($v_name, $v_description, $t_project_status, $t_project_view_state, $v_file_path, $v_enabled);
 592      }
 593      
 594      /** 
 595       * Delete a project.
 596       *
 597       * @param string $p_username  The name of the user trying to access the versions.
 598       * @param string $p_password  The password of the user.
 599       * @param integer $p_project_id A project's id
 600       * @return bool returns true or false depending on the success of the delete action
 601       */
 602  	function mc_project_delete( $p_username, $p_password, $p_project_id ) {
 603          $t_user_id = mci_check_login( $p_username, $p_password );
 604          if ( $t_user_id === false ) {
 605              return new soap_fault( 'Client', '', 'Access Denied', 'Username/password combination was incorrect');
 606          }
 607  
 608          if ( !project_exists( $p_project_id ) ) {
 609              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 610          }
 611  
 612          if ( !mci_has_administrator_access( $t_user_id, $p_project_id ) ) {
 613              return new soap_fault( 'Client', '', 'Access Denied', 'User does not have administrator access');
 614          }
 615  
 616          return project_delete( $p_project_id );
 617      }
 618      
 619  	function mc_project_get_issue_headers( $p_username, $p_password, $p_project_id , $p_page_number, $p_per_page ) {
 620          $t_user_id = mci_check_login( $p_username, $p_password );
 621          if ( $t_user_id === false ) {
 622              return new soap_fault( 'Client', '', 'Access Denied' );
 623          }
 624          if ( !project_exists( $p_project_id ) ) {
 625              return new soap_fault( 'Client', '', "Project '$p_project_id' does not exist." );
 626          }        
 627          
 628          if ( !mci_has_readonly_access( $t_user_id, $p_project_id ) ) {
 629              return new soap_fault( 'Client', '', 'Access Denied' );
 630          }
 631  
 632          $t_page_count = 0;
 633          $t_bug_count = 0;    
 634  
 635          
 636          $t_rows = filter_get_bug_rows( $p_page_number, $p_per_page, $t_page_count, $t_bug_count, null, $p_project_id );
 637          $t_result = array();
 638  
 639          foreach( $t_rows as $t_issue_data ) {
 640              $t_id = $t_issue_data['id'];
 641              
 642              $t_issue = array();
 643              
 644              $t_issue['id'] = $t_id;
 645              $t_issue['view_state'] = $t_issue_data['view_state'];
 646              $t_issue['last_updated'] = timestamp_to_iso8601( $t_issue_data['last_updated'] );
 647  
 648              $t_issue['project'] = $t_issue_data['project_id'];
 649              $t_issue['category'] = mci_null_if_empty( $t_issue_data['category'] );
 650              $t_issue['priority'] = $t_issue_data['priority'];
 651              $t_issue['severity'] = $t_issue_data['severity'];
 652              $t_issue['status'] = $t_issue_data['status'];
 653  
 654              $t_issue['reporter'] = $t_issue_data['reporter_id'];
 655              $t_issue['summary'] = $t_issue_data['summary'];
 656              if( !empty( $t_issue_data['handler_id'] ) ) {
 657                  $t_issue['handler'] = $t_issue_data['handler_id'];
 658              }
 659              $t_issue['resolution'] = $t_issue_data['resolution'];
 660              
 661              $t_issue['attachments_count'] = count( mci_issue_get_attachments( $t_issue_data['id'] ) );
 662              $t_issue['notes_count'] = count( mci_issue_get_notes( $t_issue_data['id'] ) );
 663  
 664              $t_result[] = $t_issue;
 665          }
 666          
 667          return $t_result;
 668      }
 669      
 670      /**
 671       * Get appropriate users assigned to a project by access level.
 672       *
 673       * @param string $p_username  The name of the user trying to access the versions.
 674       * @param string $p_password  The password of the user.
 675       * @param integer $p_project_id  The id of the project to retrieve the users for.
 676       * @param integer $p_access Minimum access level.
 677       * @return Array  representing a ProjectAttachmentDataArray structure.
 678       */
 679  	function mc_project_get_users( $p_username, $p_password, $p_project_id, $p_access ) {
 680          $t_user_id = mci_check_login( $p_username, $p_password );
 681  
 682          if ( $t_user_id === false ) {
 683              return new soap_fault( 'Client', '', 'Access Denied' );
 684          }
 685          
 686          $t_users = array();
 687  
 688          $t_users = project_get_all_user_rows( $p_project_id, $p_access ); # handles ALL_PROJECTS case
 689          
 690          $t_display = array();
 691          $t_sort = array();
 692          $t_show_realname = ( ON == config_get( 'show_realname' ) );
 693          $t_sort_by_last_name = ( ON == config_get( 'sort_by_last_name' ) );
 694          foreach ( $t_users as $t_user ) {
 695              $t_user_name = string_attribute( $t_user['username'] );
 696              $t_sort_name = strtolower( $t_user_name );
 697              if ( $t_show_realname && ( $t_user['realname'] <> "" ) ){
 698                  $t_user_name = string_attribute( $t_user['realname'] );
 699                  if ( $t_sort_by_last_name ) {
 700                      $t_sort_name_bits = split( ' ', strtolower( $t_user_name ), 2 );
 701                      $t_sort_name = ( isset( $t_sort_name_bits[1] ) ? $t_sort_name_bits[1] . ', ' : '' ) . $t_sort_name_bits[0];
 702                  } else {
 703                      $t_sort_name = strtolower( $t_user_name );
 704                  }
 705              }
 706              $t_display[] = $t_user_name;
 707              $t_sort[] = $t_sort_name;
 708          }
 709          array_multisort( $t_sort, SORT_ASC, SORT_STRING, $t_users, $t_display );
 710          
 711          $t_result = array();
 712          for ($i = 0; $i < count( $t_sort ); $i++ ) {
 713              $t_row = $t_users[$i];
 714              // This is not very performant - But we have to assure that the data returned is exactly
 715              // the same as the data that comes with an issue (test for equality - $t_row[] does not
 716              // contain email fields).
 717              $t_result[] = mci_account_get_array_by_id( $t_row['id'] );
 718          }
 719          return $t_result;
 720      }
 721  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics