Changeset 12597


Ignore:
Timestamp:
11/11/11 11:21:58 (8 years ago)
Author:
mistic100
Message:

merge r12596 from trunk: feature 2500: make 'validate_user_comment' and 'delete_user_comment' working with array

Location:
branches/2.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.3/admin/comments.php

    r8728 r12597  
    4949  else 
    5050  { 
     51    include_once( PHPWG_ROOT_PATH .'include/functions_comment.inc.php' ); 
    5152    check_input_parameter('comments', $_POST, true, PATTERN_ID); 
    5253     
    5354    if (isset($_POST['validate'])) 
    5455    { 
    55       $query = ' 
    56 UPDATE '.COMMENTS_TABLE.' 
    57   SET validated = \'true\' 
    58     , validation_date = NOW() 
    59   WHERE id IN ('.implode(',', $_POST['comments']).') 
    60 ;'; 
    61     pwg_query($query); 
     56      validate_user_comment($_POST['comments']); 
    6257 
    63     array_push( 
    64       $page['infos'], 
    65       l10n_dec( 
    66         '%d user comment validated', '%d user comments validated', 
    67         count($_POST['comments']) 
    68         ) 
    69       ); 
     58      array_push( 
     59        $page['infos'], 
     60        l10n_dec( 
     61          '%d user comment validated', '%d user comments validated', 
     62          count($_POST['comments']) 
     63          ) 
     64        ); 
    7065    } 
    7166 
    7267    if (isset($_POST['reject'])) 
    7368    { 
    74       $query = ' 
    75 DELETE 
    76   FROM '.COMMENTS_TABLE.' 
    77   WHERE id IN ('.implode(',', $_POST['comments']).') 
    78 ;'; 
    79       pwg_query($query); 
     69      delete_user_comment($_POST['comments']); 
    8070 
    8171      array_push( 
  • branches/2.3/include/functions_comment.inc.php

    r12557 r12597  
    203203 * so to avoid a new sql request we add author in where clause 
    204204 * 
    205  * @param comment_id 
     205 * @param int or array of int comment_id 
    206206 */ 
    207 function delete_user_comment($comment_id) { 
     207function delete_user_comment($comment_id) 
     208{ 
    208209  $user_where_clause = ''; 
    209210  if (!is_admin()) 
     
    211212    $user_where_clause = '   AND author_id = \''.$GLOBALS['user']['id'].'\''; 
    212213  } 
     214   
     215  if (is_array($comment_id)) 
     216    $where_clause = 'id IN('.implode(',', $comment_id).')'; 
     217  else 
     218    $where_clause = 'id = '.$comment_id; 
     219     
    213220  $query = ' 
    214221DELETE FROM '.COMMENTS_TABLE.' 
    215   WHERE id = '.$comment_id. 
     222  WHERE '.$where_clause. 
    216223$user_where_clause.' 
    217224;'; 
    218225  $result = pwg_query($query); 
    219   if ($result) { 
     226   
     227  if ($result)  
     228  { 
    220229    email_admin('delete',  
    221230                array('author' => $GLOBALS['user']['username'], 
     
    378387} 
    379388 
     389/** 
     390 * Tries to validate a user comment in the database 
     391 * @param int or array of int comment_id 
     392 */ 
    380393function validate_user_comment($comment_id) 
    381394{ 
     395  if (is_array($comment_id)) 
     396    $where_clause = 'id IN('.implode(',', $comment_id).')'; 
     397  else 
     398    $where_clause = 'id = '.$comment_id; 
     399     
    382400  $query = ' 
    383401UPDATE '.COMMENTS_TABLE.' 
    384402  SET validated = \'true\' 
    385403    , validation_date = NOW() 
    386   WHERE id = '.$comment_id.' 
     404  WHERE '.$where_clause.' 
    387405;'; 
    388406  pwg_query($query); 
Note: See TracChangeset for help on using the changeset viewer.