Changeset 881


Ignore:
Timestamp:
Oct 8, 2005, 12:04:53 AM (19 years ago)
Author:
plg
Message:
  • new: mass virtual categories movement manager in Administration>Categories>Move screen.
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin.php

    r862 r881  
    7474    'U_CONFIG_DISPLAY'=>add_session_id($conf_link.'default' ),
    7575    'U_CATEGORIES'=>add_session_id($link_start.'cat_list' ),
     76    'U_MOVE'=>add_session_id($link_start.'cat_move' ),
    7677    'U_CAT_UPLOAD'=>add_session_id($opt_link.'upload'),
    7778    'U_CAT_COMMENTS'=>add_session_id($opt_link.'comments'),
  • trunk/admin/cat_modify.php

    r862 r881  
    6868  if (isset($_POST['parent']))
    6969  {
    70     move_category($_GET['cat_id'], $_POST['parent']);
     70    move_categories(
     71      array($_GET['cat_id']),
     72      $_POST['parent']
     73      );
    7174  }
    7275
  • trunk/admin/include/functions.php

    r880 r881  
    13381338
    13391339/**
    1340  * change the parent category of the given category. The category is
     1340 * change the parent category of the given categories. The categories are
    13411341 * supposed virtual.
    13421342 *
    1343  * @param int category identifier
     1343 * @param array category identifiers
    13441344 * @param int parent category identifier
    13451345 * @return void
    13461346 */
    1347 function move_category($category_id, $new_parent = -1)
    1348 {
    1349   // verifies if the move is necessary
    1350   $query = '
    1351 SELECT id_uppercat, status
     1347function move_categories($category_ids, $new_parent = -1)
     1348{
     1349  global $page;
     1350
     1351  if (count($category_ids) == 0)
     1352  {
     1353    return;
     1354  }
     1355
     1356  $new_parent = $new_parent < 1 ? 'NULL' : $new_parent;
     1357
     1358  $categories = array();
     1359 
     1360  $query = '
     1361SELECT id, id_uppercat, status, uppercats
    13521362  FROM '.CATEGORIES_TABLE.'
    1353   WHERE id = '.$category_id.'
    1354 ;';
    1355   list($old_parent, $status) = mysql_fetch_row(pwg_query($query));
    1356 
    1357   $old_parent = empty($old_parent) ? 'NULL' : $old_parent;
    1358   $new_parent = $new_parent < 1 ? 'NULL' : $new_parent;
    1359 
    1360   if ($new_parent == $old_parent)
    1361   {
    1362     // no need to move !
    1363     return;
    1364   }
     1363  WHERE id IN ('.implode(',', $category_ids).')
     1364;';
     1365  $result = pwg_query($query);
     1366  while ($row = mysql_fetch_array($result))
     1367  {
     1368    $categories[$row['id']] =
     1369      array(
     1370        'parent' => empty($row['id_uppercat']) ? 'NULL' : $row['id_uppercat'],
     1371        'status' => $row['status'],
     1372        'uppercats' => $row['uppercats']
     1373        );
     1374  }
     1375 
     1376  // is the movement possible? The movement is impossible if you try to move
     1377  // a category in a sub-category or itself
     1378  if ('NULL' != $new_parent)
     1379  {
     1380    $query = '
     1381SELECT uppercats
     1382  FROM '.CATEGORIES_TABLE.'
     1383  WHERE id = '.$new_parent.'
     1384;';
     1385    list($new_parent_uppercats) = mysql_fetch_row(pwg_query($query));
     1386
     1387    foreach ($categories as $category)
     1388    {
     1389      // technically, you can't move a category with uppercats 12,125,13,14
     1390      // into a new parent category with uppercats 12,125,13,14,24
     1391      if (preg_match('/^'.$category['uppercats'].'/', $new_parent_uppercats))
     1392      {
     1393        array_push(
     1394          $page['errors'],
     1395          l10n('You cannot move a category in its own sub category')
     1396          );
     1397        return;
     1398      }
     1399    }
     1400  }
     1401 
     1402  $tables =
     1403    array(
     1404      USER_ACCESS_TABLE => 'user_id',
     1405      GROUP_ACCESS_TABLE => 'group_id'
     1406      );
    13651407 
    13661408  $query = '
    13671409UPDATE '.CATEGORIES_TABLE.'
    13681410  SET id_uppercat = '.$new_parent.'
    1369   WHERE id = '.$category_id.'
     1411  WHERE id IN ('.implode(',', $category_ids).')
    13701412;';
    13711413  pwg_query($query);
     
    13921434  if ('private' == $parent_status)
    13931435  {
    1394     switch ($status)
    1395     {
    1396       case 'public' :
    1397       {
    1398         set_cat_status(array($category_id), 'private');
    1399         break;
    1400       }
    1401       case 'private' :
    1402       {
    1403         $subcats = get_subcat_ids(array($category_id));
    1404 
    1405         $tables =
    1406           array(
    1407             USER_ACCESS_TABLE => 'user_id',
    1408             GROUP_ACCESS_TABLE => 'group_id'
    1409             );
     1436    foreach ($categories as $cat_id => $category)
     1437    {
     1438      switch ($category['status'])
     1439      {
     1440        case 'public' :
     1441        {
     1442          set_cat_status(array($cat_id), 'private');
     1443          break;
     1444        }
     1445        case 'private' :
     1446        {
     1447          $subcats = get_subcat_ids(array($cat_id));
    14101448       
    1411         foreach ($tables as $table => $field)
    1412         {
    1413           $query = '
     1449          foreach ($tables as $table => $field)
     1450          {
     1451            $query = '
    14141452SELECT '.$field.'
    14151453  FROM '.$table.'
    1416   WHERE category_id = '.$category_id.'
    1417 ;';
    1418           $category_access = array_from_query($query, $field);
    1419 
    1420           $query = '
     1454  WHERE cat_id = '.$cat_id.'
     1455;';
     1456            $category_access = array_from_query($query, $field);
     1457
     1458            $query = '
    14211459SELECT '.$field.'
    14221460  FROM '.$table.'
    1423   WHERE category_id = '.$new_parent.'
    1424 ;';
    1425           $parent_access = array_from_query($query, $field);
     1461  WHERE cat_id = '.$new_parent.'
     1462;';
     1463            $parent_access = array_from_query($query, $field);
    14261464         
    1427           $to_delete = array_diff($parent_access, $category_access);
     1465            $to_delete = array_diff($parent_access, $category_access);
    14281466         
    1429           if (count($to_delete) > 0)
    1430           {
    1431             $query = '
     1467            if (count($to_delete) > 0)
     1468            {
     1469              $query = '
    14321470DELETE FROM '.$table.'
    14331471  WHERE '.$field.' IN ('.implode(',', $to_delete).')
    1434     AND category_id IN ('.implode(',', $subcats).')
    1435 ;';
    1436             pwg_query($query);
     1472    AND cat_id IN ('.implode(',', $subcats).')
     1473;';
     1474              pwg_query($query);
     1475            }
    14371476          }
     1477          break;
    14381478        }
    1439         break;
    1440       }
    1441     }
    1442   }
     1479      }
     1480    }
     1481  }
     1482
     1483  array_push(
     1484    $page['infos'],
     1485    sprintf(
     1486      l10n('%d categories moved'),
     1487      count($categories)
     1488      )
     1489    );
    14431490}
    14441491?>
  • trunk/doc/ChangeLog

    r880 r881  
     12005-10-08 Pierrick LE GALL
     2
     3        * new: mass virtual categories movement manager in
     4        Administration>Categories>Move screen.
     5
    162005-10-05 Pierrick LE GALL
    27
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r876 r881  
    2727
    2828$lang['%d categories including %d physical and %d virtual'] = '%d categories including %d physical and %d virtual';
     29$lang['%d categories moved'] = '%d categories moved';
    2930$lang['%d comments'] = '%d comments';
    3031$lang['%d elements'] = '%d elements';
     
    8384$lang['Members'] = 'Members';
    8485$lang['Metadata synchronized from file'] = 'Metadata synchronized from file';
     86$lang['Move categories'] = 'Move categories';
    8587$lang['Move'] = 'Move';
    8688$lang['Name'] = 'Name';
     89$lang['New parent category'] = 'New parent category';
    8790$lang['No'] = 'No';
    8891$lang['Number of comments per page'] = 'Number of comments per page';
     
    130133$lang['Validate'] = 'Validate';
    131134$lang['Validation'] = 'Validation';
     135$lang['Virtual categories movement'] = 'Virtual categories movement';
     136$lang['Virtual categories to move'] = 'Virtual categories to move';
    132137$lang['Webmaster cannot be deleted'] = 'Webmaster cannot be deleted';
    133138$lang['Yes'] = 'Yes';
    134139$lang['You are running on development sources, no check possible.'] = 'You are running on development sources, no check possible.';
    135140$lang['You are running the latest version of PhpWebGallery.'] = 'You are running the latest version of PhpWebGallery.';
     141$lang['You cannot move a category in its own sub category'] = 'You cannot move a category in its own sub category';
    136142$lang['You need to confirm deletion'] = 'You need to confirm deletion';
    137143$lang['actions'] = 'actions';
  • trunk/language/fr_FR.iso-8859-1/admin.lang.php

    r876 r881  
    2727
    2828$lang['%d categories including %d physical and %d virtual'] = '%d catégories dont %d physiques et %d virtuelles';
     29$lang['%d categories moved'] = '%d catégories déplacées';
    2930$lang['%d comments'] = '%d commentaires utilisateur';
    3031$lang['%d elements'] = '%d éléments';
     
    8384$lang['Members'] = 'Membres';
    8485$lang['Metadata synchronized from file'] = 'Meta-données synchronisées à partir du fichier';
     86$lang['Move categories'] = 'Déplacer les catégories';
    8587$lang['Move'] = 'Déplacer';
    8688$lang['Name'] = 'Nom';
     89$lang['New parent category'] = 'Nouvelle catégorie parente';
    8790$lang['No'] = 'Non';
    8891$lang['Number of comments per page'] = 'Nombre de commentaires utilisateur par page';
     
    130133$lang['Validate'] = 'Valider';
    131134$lang['Validation'] = 'Validation';
     135$lang['Virtual categories movement'] = 'Déplacement de catégories virtuelles';
     136$lang['Virtual categories to move'] = 'Catégories virtuelles à déplacer';
    132137$lang['Webmaster cannot be deleted'] = 'Le webmestre ne peut pas être supprimé';
    133138$lang['Yes'] = 'Oui';
    134139$lang['You are running on development sources, no check possible.'] = 'Vous travaillez avec les sources de développement, impossible de vérifier la dernière version.';
    135140$lang['You are running the latest version of PhpWebGallery.'] = 'Vous utilisez la dernière version de PhpWebGallery.';
     141$lang['You cannot move a category in its own sub category'] = 'Vous ne pouvez pas déplacer une catégorie dans sa propre sous-catégorie';
    136142$lang['You need to confirm deletion'] = 'Vous devez confirmer la suppression';
    137143$lang['actions'] = 'actions';
  • trunk/template/yoga/admin.tpl

    r859 r881  
    3434      <ul>
    3535        <li><a href="{U_CATEGORIES}">{lang:manage}</a></li>
     36        <li><a href="{U_MOVE}">{lang:Move}</a></li>
    3637        <li><a href="{U_CAT_UPLOAD}">{lang:upload}</a></li>
    3738        <li><a href="{U_CAT_COMMENTS}">{lang:comments}</a></li>
Note: See TracChangeset for help on using the changeset viewer.