Changeset 17669 for trunk/admin


Ignore:
Timestamp:
Aug 30, 2012, 2:54:29 PM (12 years ago)
Author:
plg
Message:

merge r17668 from branch 2.4 to trunk

bug 2733 fixed: when creating a sub-album in a private album with
pwg.categories.add, it is automatically private too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r17424 r17669  
    11971197 * @return array with ('info' and 'id') or ('error') key
    11981198 */
    1199 function create_virtual_category($category_name, $parent_id=null)
     1199function create_virtual_category($category_name, $parent_id=null, $options=array())
    12001200{
    12011201  global $conf, $user;
     
    12061206    return array('error' => l10n('The name of an album must not be empty'));
    12071207  }
    1208 
    1209   $parent_id = !empty($parent_id) ? $parent_id : 'NULL';
    1210 
     1208   
    12111209  $insert = array(
    12121210    'name' => $category_name,
    12131211    'rank' => 0,
    1214     'commentable' => boolean_to_string($conf['newcat_default_commentable']),
     1212    'global_rank' => 0,
    12151213    );
    12161214
    1217   if ($parent_id != 'NULL')
     1215  // is the album commentable?
     1216  if (isset($options['commentable']) and is_bool($options['commentable']))
     1217  {
     1218    $insert['commentable'] = $options['commentable'];
     1219  }
     1220  else
     1221  {
     1222    $insert['commentable'] = $conf['newcat_default_commentable'];
     1223  }
     1224  $insert['commentable'] = boolean_to_string($insert['commentable']);
     1225
     1226  // is the album temporarily locked? (only visible by administrators,
     1227  // whatever permissions) (may be overwritten if parent album is not
     1228  // visible)
     1229  if (isset($options['visible']) and is_bool($options['visible']))
     1230  {
     1231    $insert['visible'] = $options['visible'];
     1232  }
     1233  else
     1234  {
     1235    $insert['visible'] = $conf['newcat_default_visible'];
     1236  }
     1237  $insert['visible'] = boolean_to_string($insert['visible']);
     1238
     1239  // is the album private? (may be overwritten if parent album is private)
     1240  if (isset($options['status']) and 'private' == $options['status'])
     1241  {
     1242    $insert['status'] = 'private';
     1243  }
     1244  else
     1245  {
     1246    $insert['status'] = $conf['newcat_default_status'];
     1247  }
     1248
     1249  // any description for this album?
     1250  if (isset($options['comment']))
     1251  {
     1252    $insert['comment'] = strip_tags($options['comment']);
     1253  }
     1254
     1255  if (!empty($parent_id) and is_numeric($parent_id))
    12181256  {
    12191257    $query = '
     
    12341272      $insert['visible'] = 'false';
    12351273    }
    1236     else
    1237     {
    1238       $insert['visible'] = boolean_to_string($conf['newcat_default_visible']);
    1239     }
    12401274
    12411275    // at creation, must a category be public or private ? Warning : if the
     
    12461280      $insert['status'] = 'private';
    12471281    }
    1248     else
    1249     {
    1250       $insert['status'] = $conf['newcat_default_status'];
    1251     }
     1282
     1283    $uppercats_prefix = $parent['uppercats'].',';
    12521284  }
    12531285  else
    12541286  {
    1255     $insert['visible'] = boolean_to_string($conf['newcat_default_visible']);
    1256     $insert['status'] = $conf['newcat_default_status'];
    1257     $insert['global_rank'] = $insert['rank'];
     1287    $uppercats_prefix = '';
    12581288  }
    12591289
    12601290  // we have then to add the virtual category
    1261   mass_inserts(
     1291  single_insert(CATEGORIES_TABLE, $insert);
     1292  $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
     1293
     1294  single_update(
    12621295    CATEGORIES_TABLE,
    1263     array(
    1264       'site_id', 'name', 'id_uppercat', 'rank', 'commentable',
    1265       'visible', 'status', 'global_rank',
    1266       ),
    1267     array($insert)
     1296    array('uppercats' => $uppercats_prefix.$inserted_id),
     1297    array('id' => $inserted_id)
    12681298    );
    1269 
    1270   $inserted_id = pwg_db_insert_id(CATEGORIES_TABLE);
    1271 
    1272   $query = '
    1273 UPDATE
    1274   '.CATEGORIES_TABLE.'
    1275   SET uppercats = \''.
    1276     (isset($parent) ? $parent{'uppercats'}.',' : '').
    1277     $inserted_id.
    1278     '\'
    1279   WHERE id = '.$inserted_id.'
    1280 ;';
    1281   pwg_query($query);
    12821299
    12831300  update_global_rank();
Note: See TracChangeset for help on using the changeset viewer.