[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> project_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: project_api.php,v 1.77.2.1 2007-10-13 22:35:40 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  25  
  26      require_once ( $t_core_dir . 'category_api.php' );
  27      require_once ( $t_core_dir . 'version_api.php' );
  28      require_once ( $t_core_dir . 'bug_api.php' );
  29      require_once ( $t_core_dir . 'file_api.php' );
  30      require_once ( $t_core_dir . 'news_api.php' );
  31  
  32      ### Project API ###
  33  
  34      #===================================
  35      # Caching
  36      #===================================
  37  
  38      #########################################
  39      # SECURITY NOTE: cache globals are initialized here to prevent them
  40      #   being spoofed if register_globals is turned on
  41  
  42      $g_cache_project = array();
  43      $g_cache_project_missing = array();
  44      $g_cache_project_all = false;
  45  
  46      # --------------------
  47      # Cache a project row if necessary and return the cached copy
  48      #  If the second parameter is true (default), trigger an error
  49      #  if the project can't be found.  If the second parameter is
  50      #  false, return false if the project can't be found.
  51  	function project_cache_row( $p_project_id, $p_trigger_errors=true ) {
  52          global $g_cache_project, $g_cache_project_missing;
  53  
  54          if ( isset ( $g_cache_project[(int)$p_project_id] ) ) {
  55              return $g_cache_project[(int)$p_project_id];
  56          } else if ( isset( $g_cache_project_missing[(int)$p_project_id] ) ) {
  57              return false;
  58          }
  59  
  60          $c_project_id = db_prepare_int( $p_project_id );
  61          $t_project_table = config_get( 'mantis_project_table' );
  62  
  63          $query = "SELECT *
  64                    FROM $t_project_table
  65                    WHERE id='$c_project_id'";
  66          $result = db_query( $query );
  67  
  68          if ( 0 == db_num_rows( $result ) ) {
  69              $g_cache_project_missing[(int)$p_project_id] = true;
  70  
  71              if ( $p_trigger_errors ) {
  72                  trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
  73              } else {
  74                  return false;
  75              }
  76          }
  77  
  78          $row = db_fetch_array( $result );
  79  
  80          $g_cache_project[(int)$p_project_id] = $row;
  81  
  82          return $row;
  83      }
  84  
  85      # --------------------
  86      # Cache all project rows and return an array of them
  87  	function project_cache_all() {
  88          global $g_cache_project, $g_cache_project_all;
  89  
  90          if ( !$g_cache_project_all ) {
  91              $t_project_table = config_get( 'mantis_project_table' );
  92  
  93              $query = "SELECT *
  94                        FROM $t_project_table";
  95              $result = db_query( $query );
  96              $count = db_num_rows( $result );
  97              for ( $i = 0 ; $i < $count ; $i++ ) {
  98                  $row = db_fetch_array( $result );
  99  
 100                  $g_cache_project[(int)$row['id']] = $row;
 101              }
 102  
 103              $g_cache_project_all = true;
 104          }
 105  
 106          return $g_cache_project;
 107      }
 108  
 109      # --------------------
 110      # Clear the project cache (or just the given id if specified)
 111  	function project_clear_cache( $p_project_id = null ) {
 112          global $g_cache_project, $g_cache_project_missing, $g_cache_project_all;
 113  
 114          if ( null === $p_project_id ) {
 115              $g_cache_project = array();
 116              $g_cache_project_missing = array();
 117              $g_cache_project_all = false;
 118          } else {
 119              unset( $g_cache_project[(int)$p_project_id] );
 120              unset( $g_cache_project_missing[(int)$p_project_id] );
 121              $g_cache_project_all = false;
 122          }
 123  
 124          return true;
 125      }
 126  
 127      #===================================
 128      # Boolean queries and ensures
 129      #===================================
 130  
 131      # --------------------
 132      # check to see if project exists by id
 133      # return true if it does, false otherwise
 134  	function project_exists( $p_project_id ) {
 135          # we're making use of the caching function here.  If we
 136          #  succeed in caching the project then it exists and is
 137          #  now cached for use by later function calls.  If we can't
 138          #  cache it we return false.
 139          if ( false == project_cache_row( $p_project_id, false ) ) {
 140              return false;
 141          } else {
 142              return true;
 143          }
 144      }
 145  
 146      # --------------------
 147      # check to see if project exists by id
 148      # if it doesn't exist then error
 149      #  otherwise let execution continue undisturbed
 150  	function project_ensure_exists( $p_project_id ) {
 151          if ( !project_exists( $p_project_id ) ) {
 152              trigger_error( ERROR_PROJECT_NOT_FOUND, ERROR );
 153          }
 154      }
 155  
 156      # --------------------
 157      # check to see if project exists by name
 158  	function project_is_name_unique( $p_name ) {
 159          $c_name = db_prepare_string( $p_name );
 160  
 161          $t_project_table = config_get( 'mantis_project_table' );
 162  
 163          $query ="SELECT COUNT(*)
 164                   FROM $t_project_table
 165                   WHERE name='$c_name'";
 166          $result = db_query( $query );
 167  
 168          if ( 0 == db_result( $result ) ) {
 169              return true;
 170          } else {
 171              return false;
 172          }
 173      }
 174  
 175      # --------------------
 176      # check to see if project exists by id
 177      # if it doesn't exist then error
 178      #  otherwise let execution continue undisturbed
 179  	function project_ensure_name_unique( $p_name ) {
 180          if ( !project_is_name_unique( $p_name ) ) {
 181              trigger_error( ERROR_PROJECT_NAME_NOT_UNIQUE, ERROR );
 182          }
 183      }
 184  
 185      # --------------------
 186      # check to see if the user/project combo already exists
 187      # returns true is duplicate is found, otherwise false
 188  	function project_includes_user( $p_project_id, $p_user_id ) {
 189          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 190  
 191          $c_project_id    = db_prepare_int( $p_project_id );
 192          $c_user_id        = db_prepare_int( $p_user_id );
 193  
 194          $query = "SELECT COUNT(*)
 195                    FROM $t_project_user_list_table
 196                    WHERE project_id='$c_project_id' AND
 197                          user_id='$c_user_id'";
 198          $result = db_query( $query );
 199  
 200          if ( 0 == db_result( $result ) ) {
 201              return false;
 202          } else {
 203              return true;
 204          }
 205      }
 206  
 207      #=======================================
 208      # Creation / Deletion / Updating / Copy
 209      #=======================================
 210  
 211      # --------------------
 212      # Create a new project
 213  	function project_create( $p_name, $p_description, $p_status, $p_view_state = VS_PUBLIC, $p_file_path = '', $p_enabled = true ) {
 214          # Make sure file path has trailing slash
 215          $p_file_path = terminate_directory_path( $p_file_path );
 216  
 217          $c_name         = db_prepare_string( $p_name );
 218          $c_description     = db_prepare_string( $p_description );
 219          $c_status        = db_prepare_int( $p_status );
 220          $c_view_state    = db_prepare_int( $p_view_state );
 221          $c_file_path    = db_prepare_string( $p_file_path );
 222          $c_enabled        = db_prepare_bool( $p_enabled );
 223  
 224          if ( is_blank( $p_name ) ) {
 225              trigger_error( ERROR_PROJECT_NAME_INVALID, ERROR );
 226          }
 227  
 228          project_ensure_name_unique( $p_name );
 229  
 230          if ( !is_blank( $p_file_path ) ) {
 231              file_ensure_valid_upload_path( $p_file_path );
 232          }
 233  
 234          $t_project_table = config_get( 'mantis_project_table' );
 235  
 236          $query = "INSERT INTO $t_project_table
 237                      ( name, status, enabled, view_state, file_path, description )
 238                    VALUES
 239                      ( '$c_name', '$c_status', '$c_enabled', '$c_view_state', '$c_file_path', '$c_description' )";
 240  
 241          db_query( $query );
 242  
 243          # return the id of the new project
 244          return db_insert_id($t_project_table);
 245      }
 246  
 247      # --------------------
 248      # Delete a project
 249  	function project_delete( $p_project_id ) {
 250          $t_email_notifications = config_get( 'enable_email_notification' );
 251          # temporarily disable all notifications
 252          config_set_cache( 'enable_email_notification', OFF );
 253  
 254          $c_project_id = db_prepare_int( $p_project_id );
 255  
 256          $t_project_table = config_get( 'mantis_project_table' );
 257  
 258          # Delete the bugs
 259          bug_delete_all( $p_project_id );
 260  
 261          # Delete associations with custom field definitions.
 262          custom_field_unlink_all( $p_project_id );
 263  
 264          # Delete the project categories
 265          category_remove_all( $p_project_id );
 266  
 267          # Delete the project versions
 268          version_remove_all( $p_project_id );
 269  
 270          # Delete relations to other projects
 271          project_hierarchy_remove_all( $p_project_id );
 272  
 273          # Delete the project files
 274          project_delete_all_files( $p_project_id );
 275  
 276          # Delete the records assigning users to this project
 277          project_remove_all_users( $p_project_id );
 278  
 279          # Delete all news entries associated with the project being deleted
 280          news_delete_all( $p_project_id );
 281          
 282          # Delete project specific configurations
 283          config_delete_project( $p_project_id );
 284          
 285          # Delete any user prefs that are project specific
 286          user_pref_delete_project( $p_project_id );
 287  
 288          # Delete the project entry
 289          $query = "DELETE FROM $t_project_table
 290                    WHERE id='$c_project_id'";
 291  
 292          db_query( $query );
 293  
 294          config_set_cache( 'enable_email_notification', $t_email_notifications );
 295  
 296          project_clear_cache( $p_project_id );
 297  
 298          # db_query() errors on failure so:
 299          return true;
 300      }
 301  
 302      # --------------------
 303      # Update a project
 304  	function project_update( $p_project_id, $p_name, $p_description, $p_status, $p_view_state, $p_file_path, $p_enabled ) {
 305          # Make sure file path has trailing slash
 306          $p_file_path    = terminate_directory_path( $p_file_path );
 307  
 308          $c_project_id    = db_prepare_int( $p_project_id );
 309          $c_name         = db_prepare_string( $p_name );
 310          $c_description     = db_prepare_string( $p_description );
 311          $c_status        = db_prepare_int( $p_status );
 312          $c_view_state    = db_prepare_int( $p_view_state );
 313          $c_file_path    = db_prepare_string( $p_file_path );
 314          $c_enabled        = db_prepare_bool( $p_enabled );
 315  
 316          if ( is_blank( $p_name ) ) {
 317              trigger_error( ERROR_PROJECT_NAME_INVALID, ERROR );
 318          }
 319  
 320          $t_old_name = project_get_field( $p_project_id, 'name' );
 321  
 322          if ( strcasecmp( $p_name, $t_old_name ) != 0 ) {
 323              project_ensure_name_unique( $p_name );
 324          }
 325  
 326          if ( !is_blank( $p_file_path ) ) {
 327              file_ensure_valid_upload_path( $p_file_path );
 328          }
 329  
 330          $t_project_table = config_get( 'mantis_project_table' );
 331  
 332          $query = "UPDATE $t_project_table
 333                    SET name='$c_name',
 334                      status='$c_status',
 335                      enabled='$c_enabled',
 336                      view_state='$c_view_state',
 337                      file_path='$c_file_path',
 338                      description='$c_description'
 339                    WHERE id='$c_project_id'";
 340          db_query( $query );
 341  
 342          project_clear_cache( $p_project_id );
 343  
 344          # db_query errors on failure so:
 345          return true;
 346      }
 347  
 348      #--------------------
 349      # Copy custom fields
 350  	function project_copy_custom_fields( $p_destination_id, $p_source_id ) {
 351          $t_custom_field_ids = custom_field_get_linked_ids( $p_source_id );
 352           foreach ( $t_custom_field_ids as $t_custom_field_id ) {
 353              if( !custom_field_is_linked( $t_custom_field_id, $p_destination_id ) ){
 354                   custom_field_link( $t_custom_field_id, $p_destination_id );
 355                   $t_sequence = custom_field_get_sequence( $t_custom_field_id, $p_source_id );
 356                   custom_field_set_sequence( $t_custom_field_id, $p_destination_id, $t_sequence );
 357              }
 358           }
 359      }
 360  
 361      #===================================
 362      # Data Access
 363      #===================================
 364  
 365      # --------------------
 366      # Get the id of the project with the specified name
 367  	function project_get_id_by_name( $p_project_name ) {
 368          $c_project_name = db_prepare_string( $p_project_name );
 369  
 370          $t_project_table = config_get( 'mantis_project_table' );
 371  
 372          $query = "SELECT id FROM $t_project_table WHERE name = '$c_project_name'";
 373          $t_result = db_query( $query, 1 );
 374  
 375          if ( db_num_rows( $t_result ) == 0 ) {
 376              return 0;
 377          } else {
 378              return db_result( $t_result );
 379          }
 380      }
 381  
 382      # --------------------
 383      # Return the row describing the given project
 384  	function project_get_row( $p_project_id ) {
 385          return project_cache_row( $p_project_id );
 386      }
 387  
 388      # --------------------
 389      # Return all rows describing all projects
 390  	function project_get_all_rows() {
 391          return project_cache_all();
 392      }
 393  
 394      # --------------------
 395      # Return the specified field of the specified project
 396  	function project_get_field( $p_project_id, $p_field_name ) {
 397          $row = project_get_row( $p_project_id );
 398  
 399          if ( isset( $row[$p_field_name] ) ) {
 400              return $row[$p_field_name];
 401          } else {
 402              error_parameters( $p_field_name );
 403              trigger_error( ERROR_DB_FIELD_NOT_FOUND, WARNING );
 404              return '';
 405          }
 406      }
 407  
 408      # --------------------
 409      # Return the name of the project
 410      # Handles ALL_PROJECTS by returning the internationalized string for All Projects
 411  	function project_get_name( $p_project_id ) {
 412          if ( ALL_PROJECTS == $p_project_id ) {
 413              return lang_get( 'all_projects' );
 414          } else {
 415              return project_get_field( $p_project_id, 'name' );
 416          }
 417      }
 418  
 419      # --------------------
 420      # Return the user's local (overridden) access level on the project or false
 421      #  if the user is not listed on the project
 422  	function project_get_local_user_access_level( $p_project_id, $p_user_id ) {
 423          $c_project_id    = db_prepare_int( $p_project_id );
 424          $c_user_id        = db_prepare_int( $p_user_id );
 425  
 426          if ( ALL_PROJECTS == $c_project_id ) {
 427              return false;
 428          }
 429  
 430          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 431  
 432          $query = "SELECT access_level
 433                    FROM $t_project_user_list_table
 434                    WHERE user_id='$c_user_id' AND project_id='$c_project_id'";
 435          $result = db_query( $query );
 436  
 437          if ( db_num_rows( $result ) > 0 ) {
 438              return db_result( $result );
 439          } else {
 440              return false;
 441          }
 442      }
 443  
 444      # --------------------
 445      # return the descriptor holding all the info from the project user list
 446      # for the specified project
 447  	function project_get_local_user_rows( $p_project_id ) {
 448          $c_project_id    = db_prepare_int( $p_project_id );
 449  
 450          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 451  
 452          $query = "SELECT *
 453                  FROM $t_project_user_list_table
 454                  WHERE project_id='$c_project_id'";
 455  
 456          $result = db_query( $query );
 457  
 458          $t_user_rows = array();
 459          $t_row_count = db_num_rows( $result );
 460  
 461          for ( $i=0 ; $i < $t_row_count ; $i++ ) {
 462              array_push( $t_user_rows, db_fetch_array( $result ) );
 463          }
 464  
 465          return $t_user_rows;
 466      }
 467  
 468      # --------------------
 469      # Return an array of info about users who have access to the the given project
 470      # For each user we have 'id', 'username', and 'access_level' (overall access level)
 471      # If the second parameter is given, return only users with an access level
 472      #  higher than the given value.
 473      # if the first parameter is given as 'ALL_PROJECTS', return the global access level (without
 474      # any reference to the specific project
 475  	function project_get_all_user_rows( $p_project_id = ALL_PROJECTS, $p_access_level = ANYBODY ) {
 476          $c_project_id    = db_prepare_int( $p_project_id );
 477  
 478          # Optimization when access_level is NOBODY
 479          if ( NOBODY == $p_access_level ) {
 480              return array();
 481          }
 482  
 483          $t_user_table = config_get( 'mantis_user_table' );
 484          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 485          $t_project_table = config_get( 'mantis_project_table' );
 486          
 487          $t_global_access_level = $p_access_level;
 488  
 489          if ( $c_project_id != ALL_PROJECTS ) {
 490              # looking for specific project
 491              if ( VS_PRIVATE == project_get_field( $p_project_id, 'view_state' ) ) {
 492                  # @@@ (thraxisp) this is probably more complex than it needs to be
 493                  # When a new project is created, those who meet 'private_project_threshold' are added
 494                  #  automatically, but don't have an entry in project_user_list_table.
 495                  #  if they did, you would not have to add global levels.
 496                  
 497                  $t_private_project_threshold = config_get( 'private_project_threshold' );
 498                  if ( is_array( $t_private_project_threshold ) ) {
 499                      if ( is_array( $p_access_level ) ) {
 500                          # both private threshold and request are arrays, use intersection
 501                          $t_global_access_level = array_intersect( $p_access_level, $t_private_project_threshold );
 502                      } else {
 503                          # private threshold is an array, but request is a number, use values in threshold higher than request
 504                          $t_global_access_level = array();
 505                          foreach ( $t_private_project_threshold as $t_threshold ) {
 506                              if ( $p_access_level <= $t_threshold ) {
 507                                  $t_global_access_level[] = $t_threshold;
 508                              }
 509                          }
 510                      }
 511                  } else {
 512                      if ( is_array( $p_access_level ) ) {
 513                          # private threshold is a number, but request is an array, use values in request higher than threshold
 514                          $t_global_access_level = array();
 515                          foreach ( $p_access_level as $t_threshold ) {
 516                              if ( $t_threshold >= $t_private_project_threshold ) {
 517                                  $t_global_access_level[] = $t_threshold;
 518                              }
 519                          }
 520                      } else {
 521                          # both private threshold and request are numbers, use maximum
 522                          $t_global_access_level = max( $p_access_level, $t_private_project_threshold );
 523                      }
 524                  }
 525              }
 526          }
 527                  
 528          $t_project_clause = ( $c_project_id != ALL_PROJECTS ) ? ' AND p.id = ' . $c_project_id : '';
 529          if ( is_array( $t_global_access_level ) ) {
 530              if ( 0 == count( $t_global_access_level ) ) {
 531                  $t_global_access_clause = ">= " . NOBODY . " ";
 532              } else if ( 1 == count( $t_global_access_level ) ) {
 533                  $t_global_access_clause = "= " . array_shift( $t_global_access_level ) . " ";
 534              } else {
 535                  $t_global_access_clause = "IN (" . implode( ',', $t_global_access_level ) . ")";
 536              }
 537          } else {
 538              $t_global_access_clause = ">= $t_global_access_level ";
 539          }            
 540  
 541          $t_on = ON;
 542          $t_adm = ADMINISTRATOR;
 543          $t_users = array();
 544  
 545          $query = "SELECT id, username, realname, access_level
 546                  FROM $t_user_table
 547                  WHERE enabled = $t_on
 548                      AND access_level $t_global_access_clause";
 549  
 550          $result = db_query( $query );
 551          $t_row_count = db_num_rows( $result );
 552          for ( $i=0 ; $i < $t_row_count ; $i++ ) {
 553              $row = db_fetch_array( $result );
 554              $t_users[$row['id']] = $row;
 555          }
 556  
 557          if( $c_project_id != ALL_PROJECTS ) {
 558              # Get the project overrides
 559              $query = "SELECT u.id, u.username, u.realname, l.access_level
 560                  FROM $t_project_user_list_table l, $t_user_table u
 561                  WHERE l.user_id = u.id
 562                  AND u.enabled = $t_on
 563                  AND l.project_id = $c_project_id";
 564  
 565              $result = db_query( $query );
 566              $t_row_count = db_num_rows( $result );
 567              for ( $i=0 ; $i < $t_row_count ; $i++ ) {
 568                  $row = db_fetch_array( $result );
 569                  if ( is_array( $p_access_level ) ) {
 570                      $t_keep = in_array( $row['access_level'], $p_access_level );
 571                  } else {
 572                      $t_keep = $row['access_level'] >= $p_access_level;
 573                  }
 574  
 575                  if ( $t_keep ) {
 576                      $t_users[$row['id']] = $row;
 577                  } else {
 578                      # If user's overridden level is lower than required, so remove
 579                      #  them from the list if they were previously there
 580                      unset( $t_users[$row['id']] );
 581                  }
 582              }
 583          }
 584  
 585          return array_values( $t_users );
 586      }
 587  
 588  
 589      #===================================
 590      # Data Modification
 591      #===================================
 592  
 593      # --------------------
 594      # add user with the specified access level to a project
 595  	function project_add_user( $p_project_id, $p_user_id, $p_access_level ) {
 596          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 597  
 598          $c_project_id    = db_prepare_int( $p_project_id );
 599          $c_user_id        = db_prepare_int( $p_user_id );
 600          $c_access_level    = db_prepare_int( $p_access_level );
 601  
 602          if ( DEFAULT_ACCESS_LEVEL == $p_access_level ) {
 603              # Default access level for this user
 604              $c_access_level = db_prepare_int( user_get_access_level ( $p_user_id ) );
 605          }
 606  
 607          $query = "INSERT
 608                    INTO $t_project_user_list_table
 609                      ( project_id, user_id, access_level )
 610                    VALUES
 611                      ( '$c_project_id', '$c_user_id', '$c_access_level')";
 612  
 613          db_query( $query );
 614  
 615          # db_query errors on failure so:
 616          return true;
 617      }
 618  
 619      # --------------------
 620      # update entry
 621      # must make sure entry exists beforehand
 622  	function project_update_user_access( $p_project_id, $p_user_id, $p_access_level ) {
 623          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 624  
 625          $c_project_id    = db_prepare_int( $p_project_id );
 626          $c_user_id        = db_prepare_int( $p_user_id );
 627          $c_access_level    = db_prepare_int( $p_access_level );
 628  
 629          $query = "UPDATE $t_project_user_list_table
 630                    SET access_level='$c_access_level'
 631                    WHERE    project_id='$c_project_id' AND
 632                          user_id='$c_user_id'";
 633  
 634          db_query( $query );
 635  
 636          # db_query errors on failure so:
 637          return true;
 638      }
 639  
 640      # --------------------
 641      # update or add the entry as appropriate
 642      #  This function involves one more db query than project_update_user_acces()
 643      #  or project_add_user()
 644  	function project_set_user_access( $p_project_id, $p_user_id, $p_access_level ) {
 645          if ( project_includes_user( $p_project_id, $p_user_id ) ) {
 646              return project_update_user_access( $p_project_id, $p_user_id, $p_access_level );
 647          } else {
 648              return project_add_user( $p_project_id, $p_user_id, $p_access_level );
 649          }
 650      }
 651  
 652      # --------------------
 653      # remove user from project
 654  	function project_remove_user( $p_project_id, $p_user_id ) {
 655          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 656  
 657          $c_project_id    = db_prepare_int( $p_project_id );
 658          $c_user_id        = db_prepare_int( $p_user_id );
 659  
 660          $query = "DELETE FROM $t_project_user_list_table
 661                    WHERE project_id='$c_project_id' AND
 662                          user_id='$c_user_id'";
 663  
 664          db_query( $query );
 665  
 666          # db_query errors on failure so:
 667          return true;
 668      }
 669  
 670      # --------------------
 671      # delete all users from the project user list for a given project
 672      # this is useful when deleting or closing a project
 673  	function project_remove_all_users( $p_project_id ) {
 674          $t_project_user_list_table = config_get( 'mantis_project_user_list_table' );
 675  
 676          $c_project_id    = db_prepare_int( $p_project_id );
 677  
 678          $query = "DELETE FROM $t_project_user_list_table
 679                  WHERE project_id='$c_project_id'";
 680  
 681          db_query( $query );
 682  
 683          # db_query errors on failure so:
 684          return true;
 685      }
 686  
 687      # --------------------
 688      # Copy all users and their permissions from the source project to the
 689      #  destination project
 690  	function project_copy_users( $p_destination_id, $p_source_id ) {
 691          # Copy all users from current project over to another project
 692          $rows = project_get_local_user_rows( $p_source_id );
 693  
 694          for ( $i = 0 ; $i < sizeof( $rows ) ; $i++ ) {
 695              extract( $rows[$i], EXTR_PREFIX_ALL, 'v' );
 696  
 697              # if there is no duplicate then add a new entry
 698              # otherwise just update the access level for the existing entry
 699              if ( project_includes_user( $p_destination_id, $v_user_id ) ) {
 700                  project_update_user_access( $p_destination_id, $v_user_id, $v_access_level );
 701              } else {
 702                  project_add_user( $p_destination_id, $v_user_id, $v_access_level );
 703              }
 704          }
 705      }
 706  
 707      # --------------------
 708      # Delete all files associated with a project
 709  	function project_delete_all_files( $p_project_id ) {
 710          file_delete_project_files( $p_project_id );
 711      }
 712  
 713      #===================================
 714      # Other
 715      #===================================
 716  
 717      # --------------------
 718      # Pads the project id with the appropriate number of zeros.
 719  	function project_format_id( $p_project_id ) {
 720          $t_padding = config_get( 'display_project_padding' );
 721          return( str_pad( $p_project_id, $t_padding, '0', STR_PAD_LEFT ) );
 722      }
 723  
 724          # --------------------
 725      # Return true if the file name identifier is unique, false otherwise
 726  	function project_file_is_name_unique( $p_name ) {
 727          $t_file_table = config_get( 'mantis_project_file_table' );
 728  
 729          $c_name = db_prepare_string( $p_name );
 730  
 731          $query = "SELECT COUNT(*)
 732                    FROM $t_file_table
 733                    WHERE filename='$c_name'";
 734          $result = db_query( $query );
 735          $t_count = db_result( $result );
 736  
 737          if ( $t_count > 0 ) {
 738              return false;
 739          } else {
 740              return true;
 741          }
 742      }
 743  
 744  
 745  ?>


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