Changeset 809


Ignore:
Timestamp:
Aug 14, 2005, 1:09:54 AM (19 years ago)
Author:
plg
Message:
  • new : maintenance screen in administration. There you can update categories informations (number of images, date of the last added element), update images informations (path, average rate), purge obsolete sessions, purge history.
  • new : ability to have random representative for categories. This configuration parameter is set to false by default.
  • new : ability to set an element as representative of a category without belonging to the category. Thus, administrator can choose representative even for empty categories.
  • improvement : semantically superior design for category edition screen by regrouping fields in fieldsets. The improved screen contains action buttons as in category list screen.
  • new : ability to move a virtual category (ie change its parent category).
  • bug fixed : the sync_users function checks all user children tables (access, cache, group association).
Location:
trunk
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin.php

    r808 r809  
    166166 {
    167167   $title = 'batch management';
     168   $page_valide = true;
     169   break;
     170 }
     171 case 'maintenance' :
     172 {
     173   $title = l10n('Maintenance');
     174   $page_valide = true;
     175   break;
     176 }
     177 case 'representative' :
     178 {
     179   $title = l10n('Representative');
    168180   $page_valide = true;
    169181   break;
     
    245257  'U_SITES'=>add_session_id($link_start.'remote_site'),
    246258  'U_PHPINFO'=>add_session_id($link_start.'admin_phpinfo' ),
     259  'U_MAINTENANCE'=>add_session_id($link_start.'maintenance'),
    247260  'U_CONFIG_GENERAL'=>add_session_id($conf_link.'general' ),
    248261  'U_CONFIG_COMMENTS'=>add_session_id($conf_link.'comments' ),
     
    270283  ));
    271284
     285if ($conf['allow_random_representative'])
     286{
     287  $template->assign_block_vars(
     288    'representative',
     289    array(
     290      'URL' => add_session_id($opt_link.'representative')
     291      )
     292    );
     293}
     294 
    272295//--------------------------------------------------------------------- summary
    273296$link_start = PHPWG_ROOT_PATH.'admin.php?page=';
  • trunk/admin/cat_modify.php

    r792 r809  
    4242if ( isset( $_POST['submit'] ) )
    4343{
    44   $query = 'SELECT status';
    45   $query.= ' FROM '.CATEGORIES_TABLE;
    46   $query.= ' WHERE id = '.$_GET['cat_id'];
    47   $query.= ';';
    48   $row = mysql_fetch_array( pwg_query( $query ) );
    49  
    5044  $query = 'UPDATE '.CATEGORIES_TABLE;
    5145  $query.= ' SET name = ';
     
    8276  set_cat_status(array($_GET['cat_id']), $_POST['status']);
    8377
    84   array_push($infos, $lang['editcat_confirm']);
     78  if (isset($_POST['parent']))
     79  {
     80    move_category($_GET['cat_id'], $_POST['parent']);
     81  }
     82
     83  array_push($page['infos'], $lang['editcat_confirm']);
    8584}
    8685else if (isset($_POST['set_random_representant']))
    8786{
    8887  set_random_representant(array($_GET['cat_id']));
     88}
     89else if (isset($_POST['delete_representant']))
     90{
     91  $query = '
     92UPDATE '.CATEGORIES_TABLE.'
     93  SET representative_picture_id = NULL
     94  WHERE id = '.$_GET['cat_id'].'
     95;';
     96  pwg_query($query);
    8997}
    9098
     
    96104$category = mysql_fetch_array( pwg_query( $query ) );
    97105// nullable fields
    98 foreach (array('comment','dir','site_id') as $nullable)
     106foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable)
    99107{
    100108  if (!isset($category[$nullable]))
     
    103111  }
    104112}
     113
     114$category['is_virtual'] = empty($category['dir']) ? true : false;
    105115
    106116// Navigation path
     
    135145
    136146//----------------------------------------------------- template initialization
     147
     148$base_url = PHPWG_ROOT_PATH.'admin.php?page=';
     149$cat_list_url = $base_url.'cat_list';
     150 
     151$self_url = $cat_list_url;
     152if (!empty($category['id_uppercat']))
     153{
     154  $self_url.= '&parent_id='.$category['id_uppercat'];
     155}
     156
    137157$template->assign_vars(array(
    138158  'CATEGORIES_NAV'=>$navigation,
     
    164184  'L_SUBMIT'=>$lang['submit'],
    165185  'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
     186
     187  'U_JUMPTO'=>
     188    add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']),
     189  'U_CHILDREN'=>
     190    add_session_id($cat_list_url.'&parent_id='.$category['id']),
    166191   
    167192  'F_ACTION'=>add_session_id($form_action)
    168193  ));
    169194
     195
     196if ('private' == $category['status'])
     197{
     198  $template->assign_block_vars(
     199    'permissions',
     200    array(
     201      'URL'=>add_session_id($base_url.'cat_perm&cat='.$category['id'])
     202        )
     203    );
     204}
     205
     206// manage category elements link
    170207if ($category['nb_images'] > 0)
    171208{
    172   $query = '
     209  $template->assign_block_vars(
     210    'elements',
     211    array(
     212      'URL'=>add_session_id($base_url.'element_set&cat='.$category['id'])
     213      )
     214    );
     215}
     216
     217// representant management
     218if ($category['nb_images'] > 0
     219    or !empty($category['representative_picture_id']))
     220{
     221  $template->assign_block_vars('representant', array());
     222
     223  // picture to display : the identified representant or the generic random
     224  // representant ?
     225  if (!empty($category['representative_picture_id']))
     226  {
     227    $query = '
    173228SELECT tn_ext,path
    174229  FROM '.IMAGES_TABLE.'
    175230  WHERE id = '.$category['representative_picture_id'].'
    176231;';
    177   $row = mysql_fetch_array(pwg_query($query));
    178   $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    179   $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
    180   $url.= '&image_id='.$category['representative_picture_id'];
    181   $template->assign_block_vars('representant',
    182                                array('SRC' => $src,
    183                                      'URL' => $url));
    184 }
    185 
    186 if (!empty($category['dir']))
     232    $row = mysql_fetch_array(pwg_query($query));
     233    $src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     234    $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify';
     235    $url.= '&image_id='.$category['representative_picture_id'];
     236 
     237    $template->assign_block_vars(
     238      'representant.picture',
     239      array(
     240        'SRC' => $src,
     241        'URL' => $url
     242        )
     243      );
     244  }
     245  else // $category['nb_images'] > 0
     246  {
     247    $template->assign_block_vars('representant.random', array());
     248  }
     249
     250  // can the admin choose to set a new random representant ?
     251  if ($category['nb_images'] > 0)
     252  {
     253    $template->assign_block_vars('representant.set_random', array());
     254  }
     255
     256  // can the admin delete the current representant ?
     257  if (
     258    ($category['nb_images'] > 0
     259     and $conf['allow_random_representative'])
     260    or
     261    ($category['nb_images'] == 0
     262     and !empty($category['representative_picture_id'])))
     263  {
     264    $template->assign_block_vars('representant.delete_representant', array());
     265  }
     266}
     267
     268if (!$category['is_virtual']) //!empty($category['dir']))
    187269{
    188270  $template->assign_block_vars(
     
    193275  $template->assign_block_vars('upload' ,array());
    194276}
     277else
     278{
     279  $template->assign_block_vars(
     280    'delete',
     281    array(
     282      'URL'=>add_session_id($self_url.'&delete='.$category['id'])
     283      )
     284    );
     285
     286  $template->assign_block_vars('move', array());
     287
     288  // the category can be moved in any category but in itself, in any
     289  // sub-category
     290  $unmovables = get_subcat_ids(array($category['id']));
     291 
     292  $blockname = 'move.parent_option';
     293
     294  $template->assign_block_vars(
     295    $blockname,
     296    array(
     297      'SELECTED'
     298        => empty($category['id_uppercat']) ? 'selected="selected"' : '',
     299      'VALUE'=> 0,
     300      'OPTION' => '------------'
     301      )
     302    );
     303 
     304  $query = '
     305SELECT id,name,uppercats,global_rank
     306  FROM '.CATEGORIES_TABLE.'
     307  WHERE id NOT IN ('.implode(',', $unmovables).')
     308;';
     309 
     310  display_select_cat_wrapper(
     311    $query,
     312    empty($category['id_uppercat']) ? array() : array($category['id_uppercat']),
     313    $blockname
     314    );
     315}
    195316
    196317if (is_numeric($category['site_id']) and $category['site_id'] != 1)
  • trunk/admin/cat_options.php

    r675 r809  
    7373      break;
    7474    }
     75    case 'representative' :
     76    {
     77      $query = '
     78UPDATE '.CATEGORIES_TABLE.'
     79  SET representative_picture_id = NULL
     80  WHERE id IN ('.implode(',', $_POST['cat_true']).')
     81;';
     82      pwg_query($query);
     83      break;
     84    }
    7585  }
    7686}
     
    109119    {
    110120      set_cat_status($_POST['cat_false'], 'public');
     121      break;
     122    }
     123    case 'representative' :
     124    {
     125      // theoretically, all categories in $_POST['cat_false'] contain at
     126      // least one element, so PhpWebGallery can find a representant.
     127      set_random_representant($_POST['cat_false']);
    111128      break;
    112129    }
     
    179196        )
    180197      );
    181     $template->assign_block_vars('upload', array());
    182198    break;
    183199  }
     
    202218        )
    203219      );
    204     $template->assign_block_vars('comments', array());
    205220    break;
    206221  }
     
    225240        )
    226241      );
    227     $template->assign_block_vars('visible', array());
    228242    break;
    229243  }
     
    248262        )
    249263      );
    250     $template->assign_block_vars('status', array());
     264    break;
     265  }
     266  case 'representative' :
     267  {
     268    $query_true = '
     269SELECT id,name,uppercats,global_rank
     270  FROM '.CATEGORIES_TABLE.'
     271  WHERE representative_picture_id IS NOT NULL
     272;';
     273    $query_false = '
     274SELECT id,name,uppercats,global_rank
     275  FROM '.CATEGORIES_TABLE.'
     276  WHERE nb_images != 0
     277    AND representative_picture_id IS NULL
     278;';
     279    $template->assign_vars(
     280      array(
     281        'L_CAT_TITLE' => l10n('Representative'),
     282        'L_CAT_OPTIONS_TRUE' => l10n('singly represented'),
     283        'L_CAT_OPTIONS_FALSE' => l10n('randomly represented'),
     284        'L_CAT_OPTIONS_INFO' => l10n('')
     285        )
     286      );
    251287    break;
    252288  }
  • trunk/admin/include/functions.php

    r808 r809  
    396396function update_category($ids = 'all', $recursive = false)
    397397{
     398  global $conf;
     399 
    398400  // retrieving all categories to update
    399401  $cat_ids = array();
     
    429431  $query.= '
    430432;';
    431   $result = pwg_query( $query );
    432   while ( $row = mysql_fetch_array( $result ) )
    433   {
    434     array_push($cat_ids, $row['id']);
    435   }
    436   $cat_ids = array_unique($cat_ids);
     433  $cat_ids = array_unique(array_from_query($query, 'id'));
    437434
    438435  if (count($cat_ids) == 0)
     
    471468  mass_updates(CATEGORIES_TABLE, $fields, $datas);
    472469
    473   $query = '
     470  // representative pictures
     471  if (count($cat_ids) > 0)
     472  {
     473    // find all categories where the setted representative is not possible :
     474    // the picture does not exist
     475    $query = '
     476SELECT c.id
     477  FROM '.CATEGORIES_TABLE.' AS c LEFT JOIN '.IMAGES_TABLE.' AS i
     478    ON c.representative_picture_id = i.id
     479  WHERE representative_picture_id IS NOT NULL
     480    AND c.id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
     481    AND i.id IS NULL
     482;';
     483    $wrong_representant = array_from_query($query, 'id');
     484
     485    if ($conf['allow_random_representative'])
     486    {
     487      if (count($wrong_representant) > 0)
     488      {
     489        $query = '
    474490UPDATE '.CATEGORIES_TABLE.'
    475491  SET representative_picture_id = NULL
    476   WHERE nb_images = 0
    477 ;';
    478   pwg_query($query);
    479  
    480   if (count($cat_ids) > 0)
    481   {
    482     $categories = array();
    483     // find all categories where the setted representative is not possible
    484     $query = '
     492  WHERE id IN ('.wordwrap(implode(', ', $wrong_representant), 80, "\n").')
     493;';
     494        pwg_query($query);
     495      }
     496    }
     497    else
     498    {
     499      $to_null = array();
     500      $to_rand = array();
     501
     502      if (count($wrong_representant) > 0)
     503      {
     504        // among the categories with an unknown representant, we dissociate
     505        // categories containing pictures and categories containing no
     506        // pictures. Indeed, the representant must set to NULL if no picture
     507        // in the category and set to a random picture otherwise.
     508        $query = '
    485509SELECT id
    486   FROM '.CATEGORIES_TABLE.' LEFT JOIN '.IMAGE_CATEGORY_TABLE.'
    487     ON id = category_id AND representative_picture_id = image_id
    488   WHERE representative_picture_id IS NOT NULL
    489     AND id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    490     AND category_id IS NULL
    491 ;';
    492     $result = pwg_query($query);
    493     while ($row = mysql_fetch_array($result))
    494     {
    495       array_push($categories, $row['id']);
    496     }
    497     // find categories with elements and with no representant
    498     $query = '
     510  FROM '.CATEGORIES_TABLE.'
     511  WHERE id IN ('.wordwrap(implode(', ', $wrong_representant), 80, "\n").')
     512    AND nb_images = 0
     513;';
     514        $to_null = array_from_query($query, 'id');
     515        $to_rand = array_diff($wrong_representant, $to_null);
     516      }
     517     
     518      if (count($to_null) > 0)
     519      {
     520        $query = '
     521UPDATE '.CATEGORIES_TABLE.'
     522  SET representative_picture_id = NULL
     523  WHERE id IN ('.wordwrap(implode(', ', $to_null), 80, "\n").')
     524;';
     525        pwg_query($query);
     526      }
     527     
     528      // If the random representant is not allowed, we need to find
     529      // categories with elements and with no representant. Those categories
     530      // must be added to the list of categories to set to a random
     531      // representant.
     532      $query = '
    499533SELECT id
    500534  FROM '.CATEGORIES_TABLE.'
    501535  WHERE representative_picture_id IS NULL
    502536    AND nb_images != 0
    503 ;';
    504     $result = pwg_query($query);
    505     while ($row = mysql_fetch_array($result))
    506     {
    507       array_push($categories, $row['id']);
    508     }
    509 
    510     $categories = array_unique($categories);
    511     set_random_representant($categories);
     537    AND id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
     538;';
     539      $to_rand =
     540        array_unique(
     541          array_merge(
     542            $to_rand,
     543            array_from_query($query, 'id')
     544            )
     545          );
     546     
     547      if (count($to_rand) > 0)
     548      {
     549        set_random_representant($to_rand);
     550      }
     551    }
    512552  }
    513553}
     
    11871227
    11881228/**
    1189  * compares and synchronizes USERS_TABLE and USER_INFOS_TABLE : each user in
    1190  * USERS_TABLE must be present in USER_INFOS_TABLE.
     1229 * synchronize base users list and related users list
     1230 *
     1231 * compares and synchronizes base users table (USERS_TABLE) with its child
     1232 * tables (USER_INFOS_TABLE, USER_ACCESS, USER_CACHE, USER_GROUP) : each
     1233 * base user must be present in child tables, users in child tables not
     1234 * present in base table must be deleted.
     1235 *
     1236 * @return void
    11911237 */
    11921238function sync_users()
     
    12411287  }
    12421288
    1243   // users present in $infos_users and not in $base_users must be deleted
    1244   $to_delete = array_diff($infos_users, $base_users);
    1245 
    1246   if (count($to_delete) > 0)
     1289  // users present in user related tables must be present in the base user
     1290  // table
     1291  $tables =
     1292    array(
     1293      USER_INFOS_TABLE,
     1294      USER_ACCESS_TABLE,
     1295      USER_CACHE_TABLE,
     1296      USER_GROUP_TABLE
     1297      );
     1298  foreach ($tables as $table)
    12471299  {
    12481300    $query = '
     1301SELECT user_id
     1302  FROM '.$table.'
     1303;';
     1304    $to_delete =
     1305      array_diff(
     1306        array_from_query($query, 'user_id'),
     1307        $base_users
     1308        );
     1309   
     1310    if (count($to_delete) > 0)
     1311    {
     1312      $query = '
    12491313DELETE
    1250   FROM '.USER_INFOS_TABLE.'
     1314  FROM '.$table.'
    12511315  WHERE user_id in ('.implode(',', $to_delete).')
    12521316;';
     1317      pwg_query($query);
     1318    }
     1319  }
     1320}
     1321
     1322/**
     1323 * updates categories.uppercats field based on categories.id +
     1324 * categories.id_uppercat
     1325 *
     1326 * @return void
     1327 */
     1328function update_uppercats()
     1329{
     1330  $uppercat_ids = array();
     1331 
     1332  $query = '
     1333SELECT id, id_uppercat
     1334  FROM '.CATEGORIES_TABLE.'
     1335;';
     1336  $result = pwg_query($query);
     1337  while ($row = mysql_fetch_array($result))
     1338  {
     1339    $uppercat_ids[$row['id']] =
     1340      !empty($row['id_uppercat']) ? $row['id_uppercat'] : 'NULL';
     1341  }
     1342 
     1343  // uppercats array associates a category id to the list of uppercats id.
     1344  $uppercats = array();
     1345 
     1346  foreach (array_keys($uppercat_ids) as $id)
     1347  {
     1348    $uppercats[$id] = array();
     1349
     1350    $uppercat = $id;
     1351
     1352    while ($uppercat != 'NULL')
     1353    {
     1354      array_push($uppercats[$id], $uppercat);
     1355      $uppercat = $uppercat_ids[$uppercat];
     1356    }
     1357  }
     1358
     1359  $datas = array();
     1360
     1361  foreach ($uppercats as $id => $list)
     1362  {
     1363    array_push(
     1364      $datas,
     1365      array(
     1366        'id' => $id,
     1367        'uppercats' => implode(',', array_reverse($list))
     1368        )
     1369      );
     1370  }
     1371
     1372  $fields = array('primary' => array('id'), 'update' => array('uppercats'));
     1373  mass_updates(CATEGORIES_TABLE, $fields, $datas);
     1374}
     1375
     1376/**
     1377 * update images.path field
     1378 *
     1379 * @return void
     1380 */
     1381function update_path()
     1382{
     1383  $query = '
     1384SELECT DISTINCT(storage_category_id)
     1385  FROM '.IMAGES_TABLE.'
     1386;';
     1387  $cat_ids = array_from_query($query, 'storage_category_id');
     1388  $fulldirs = get_fulldirs($cat_ids);
     1389 
     1390  foreach ($cat_ids as $cat_id)
     1391  {
     1392    $query = '
     1393UPDATE '.IMAGES_TABLE.'
     1394  SET path = CONCAT(\''.$fulldirs[$cat_id].'\',\'/\',file)
     1395  WHERE storage_category_id = '.$cat_id.'
     1396;';
    12531397    pwg_query($query);
    1254   }
     1398  }
     1399}
     1400
     1401/**
     1402 * update images.average_rate field
     1403 *
     1404 * @return void
     1405 */
     1406function update_average_rate()
     1407{
     1408  $average_rates = array();
     1409 
     1410  $query = '
     1411SELECT element_id,
     1412       ROUND(AVG(rate),2) AS average_rate
     1413  FROM '.RATE_TABLE.'
     1414  GROUP BY element_id
     1415;';
     1416  $result = pwg_query($query);
     1417  while ($row = mysql_fetch_array($result))
     1418  {
     1419    array_push($average_rates, $row);
     1420  }
     1421
     1422  $datas = array();
     1423  foreach ($average_rates as $item)
     1424  {
     1425    array_push(
     1426      $datas,
     1427      array(
     1428        'id' => $item['element_id'],
     1429        'average_rate' => $item['average_rate']
     1430        )
     1431      );
     1432  }
     1433  $fields = array('primary' => array('id'), 'update' => array('average_rate'));
     1434  mass_updates(IMAGES_TABLE, $fields, $datas);
     1435}
     1436
     1437/**
     1438 * change the parent category of the given category. The category is
     1439 * supposed virtual.
     1440 *
     1441 * @param int category identifier
     1442 * @param int parent category identifier
     1443 * @return void
     1444 */
     1445function move_category($category_id, $new_parent = -1)
     1446{
     1447  // verifies if the move is necessary
     1448  $query = '
     1449SELECT id_uppercat, status
     1450  FROM '.CATEGORIES_TABLE.'
     1451  WHERE id = '.$category_id.'
     1452;';
     1453  list($old_parent, $status) = mysql_fetch_row(pwg_query($query));
     1454
     1455  $old_parent = empty($old_parent) ? 'NULL' : $old_parent;
     1456  $new_parent = $new_parent < 1 ? 'NULL' : $new_parent;
     1457
     1458  if ($new_parent == $old_parent)
     1459  {
     1460    // no need to move !
     1461    return;
     1462  }
     1463 
     1464  $query = '
     1465UPDATE '.CATEGORIES_TABLE.'
     1466  SET id_uppercat = '.$new_parent.'
     1467  WHERE id = '.$category_id.'
     1468;';
     1469  pwg_query($query);
     1470
     1471  update_uppercats();
     1472  ordering();
     1473  update_global_rank();
     1474
     1475  // status and related permissions management
     1476  if ('NULL' == $new_parent)
     1477  {
     1478    $parent_status = 'public';
     1479  }
     1480  else
     1481  {
     1482    $query = '
     1483SELECT status
     1484  FROM '.CATEGORIES_TABLE.'
     1485  WHERE id = '.$new_parent.'
     1486;';
     1487    list($parent_status) = mysql_fetch_row(pwg_query($query));
     1488  }
     1489
     1490  if ('private' == $parent_status)
     1491  {
     1492    switch ($status)
     1493    {
     1494      case 'public' :
     1495      {
     1496        set_cat_status(array($category_id), 'private');
     1497        break;
     1498      }
     1499      case 'private' :
     1500      {
     1501        $subcats = get_subcat_ids(array($category_id));
     1502
     1503        $tables =
     1504          array(
     1505            USER_ACCESS_TABLE => 'user_id',
     1506            GROUP_ACCESS_TABLE => 'group_id'
     1507            );
     1508       
     1509        foreach ($tables as $table => $field)
     1510        {
     1511          $query = '
     1512SELECT '.$field.'
     1513  FROM '.$table.'
     1514  WHERE category_id = '.$category_id.'
     1515;';
     1516          $category_access = array_from_query($query, $field);
     1517
     1518          $query = '
     1519SELECT '.$field.'
     1520  FROM '.$table.'
     1521  WHERE category_id = '.$new_parent.'
     1522;';
     1523          $parent_access = array_from_query($query, $field);
     1524         
     1525          $to_delete = array_diff($parent_access, $category_access);
     1526         
     1527          if (count($to_delete) > 0)
     1528          {
     1529            $query = '
     1530DELETE FROM '.$table.'
     1531  WHERE '.$field.' IN ('.implode(',', $to_delete).')
     1532    AND category_id IN ('.implode(',', $subcats).')
     1533;';
     1534            pwg_query($query);
     1535          }
     1536        }
     1537        break;
     1538      }
     1539    }
     1540  }
    12551541}
    12561542?>
  • trunk/admin/picture_modify.php

    r801 r809  
    235235;';
    236236display_select_cat_wrapper($query,array(),'dissociated_option');
     237
    237238// representing
    238239$query = '
     
    246247SELECT id,name,uppercats,global_rank
    247248  FROM '.CATEGORIES_TABLE.'
    248   WHERE id IN ('.implode(',', $associateds).')
    249     AND representative_picture_id != '.$_GET['image_id'].'
     249  WHERE representative_picture_id != '.$_GET['image_id'].'
     250    OR representative_picture_id IS NULL
    250251;';
    251252display_select_cat_wrapper($query,array(),'dismissed_option');
  • trunk/doc/ChangeLog

    r808 r809  
     12005-09-13 Pierrick LE GALL
     2
     3        * new : maintenance screen in administration. There you can update
     4        categories informations (number of images, date of the last added
     5        element), update images informations (path, average rate), purge
     6        obsolete sessions, purge history.
     7
     8        * new : ability to have random representative for categories. This
     9        configuration parameter is set to false by default.
     10
     11        * new : ability to set an element as representative of a category
     12        without belonging to the category. Thus, administrator can choose
     13        representative even for empty categories.
     14
     15        * improvement : semantically superior design for category edition
     16        screen by regrouping fields in fieldsets. The improved screen
     17        contains action buttons as in category list screen.
     18
     19        * new : ability to move a virtual category (ie change its parent
     20        category).
     21
     22        * bug fixed : the sync_users function checks all user children
     23        tables (access, cache, group association).
     24
    1252005-08-08 Pierrick LE GALL
    226
  • trunk/include/category_subcats.inc.php

    r760 r809  
    3333
    3434$query = '
    35 SELECT id, name, date_last
     35SELECT id, name, date_last, representative_picture_id
    3636  FROM '.CATEGORIES_TABLE.'
    3737  WHERE id_uppercat ';
     
    4444  $query.= '= '.$page['cat'];
    4545}
    46 // we must not show pictures of a forbidden category
    47 if ($user['forbidden_categories'] != '')
    48 {
    49   $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
    50 }
    51 $query.= '
     46  $query.= '
     47    AND id NOT IN ('.$user['forbidden_categories'].')
    5248  ORDER BY rank
    5349;';
    5450$result = pwg_query($query);
    5551
    56 // template thumbnail initialization
    57 if (mysql_num_rows($result) > 0)
     52// $conf['allow_random_representative']
     53
     54$cat_thumbnails = array();
     55
     56while ($row = mysql_fetch_array($result))
    5857{
     58  if (isset($row['representative_picture_id'])
     59      and is_numeric($row['representative_picture_id']))
     60  {
     61    // if a representative picture is set, it has priority
     62    $image_id = $row['representative_picture_id'];
     63  }
     64  else if ($conf['allow_random_representative'])
     65  {
     66    // searching a random representant among elements in sub-categories
     67    $query = '
     68SELECT image_id
     69  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
     70    ON ic.category_id = c.id
     71  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
     72    AND c.id NOT IN ('.$user['forbidden_categories'].')
     73  ORDER BY RAND()
     74  LIMIT 0,1
     75;';
     76    $subresult = pwg_query($query);
     77    if (mysql_num_rows($result) > 0)
     78    {
     79      list($image_id) = mysql_fetch_row($subresult);
     80    }
     81  }
     82  else
     83  {
     84    // searching a random representant among representant of sub-categories
     85    $query = '
     86SELECT representative_picture_id
     87  FROM '.CATEGORIES_TABLE.'
     88  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
     89    AND id NOT IN ('.$user['forbidden_categories'].')
     90    AND representative_picture_id IS NOT NULL
     91  ORDER BY RAND()
     92  LIMIT 0,1
     93;';
     94    $subresult = pwg_query($query);
     95    if (mysql_num_rows($subresult) > 0)
     96    {
     97      list($image_id) = mysql_fetch_row($subresult);
     98    }
     99  }
     100
     101  if (isset($image_id))
     102  {
     103    array_push(
     104      $cat_thumbnails,
     105      array(
     106        'category' => $row['id'],
     107        'picture' => $image_id,
     108        'name' => $row['name'],
     109        'date_last' => @$row['date_last']
     110        )
     111      );
     112  }
     113
     114  unset($image_id);
     115}
     116
     117if (count($cat_thumbnails) > 0)
     118{
     119  $images = array();
     120 
     121  foreach ($cat_thumbnails as $item)
     122  {
     123    $images[$item['picture']] = '';
     124  }
     125
     126  $query = '
     127SELECT id, path, tn_ext
     128  FROM '.IMAGES_TABLE.'
     129  WHERE id IN ('.implode(',', array_keys($images)).')
     130;';
     131  $result = pwg_query($query);
     132  while ($row = mysql_fetch_array($result))
     133  {
     134    $images[$row['id']] = get_thumbnail_src($row['path'], @$row['tn_ext']);
     135  }
     136
    59137  $template->assign_block_vars('thumbnails', array());
    60138  // first line
     
    62140  // current row displayed
    63141  $row_number = 0;
    64 }
     142 
     143  foreach ($cat_thumbnails as $item)
     144  {
     145    $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id'];
    65146
    66 while ($row = mysql_fetch_array($result))
    67 {
    68   $query = '
    69 SELECT path, tn_ext
    70   FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGES_TABLE.' AS i
    71     ON i.id = c.representative_picture_id
    72   WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'';
    73   // we must not show pictures of a forbidden category
    74   if ($user['forbidden_categories'] != '')
    75   {
    76     $query.= '
    77     AND c.id NOT IN ('.$user['forbidden_categories'].')';
    78   }
    79   $query.= '
    80   ORDER BY RAND()
    81   LIMIT 0,1
    82 ;';
    83   $element_result = pwg_query($query);
    84   if (mysql_num_rows($element_result) == 0)
    85   {
    86     continue;
    87   }
    88   $element_row = mysql_fetch_array($element_result);
    89 
    90   $thumbnail_link = get_thumbnail_src($element_row['path'],
    91                                       @$element_row['tn_ext']);
    92 
    93   $thumbnail_title = $lang['hint_category'];
    94 
    95   $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id'];
    96 
    97   $template->assign_block_vars(
    98     'thumbnails.line.thumbnail',
    99     array(
    100       'IMAGE'                 => $thumbnail_link,
    101       'IMAGE_ALT'             => $row['name'],
    102       'IMAGE_TITLE'           => $thumbnail_title,
    103       'IMAGE_TS'              => get_icon(@$row['date_last']),
    104        
    105       'U_IMG_LINK'            => add_session_id($url_link)
    106      )
    107    );
    108 
    109   $template->assign_block_vars(
    110     'thumbnails.line.thumbnail.category_name',
    111     array(
    112       'NAME' => $row['name']
    113       )
    114     );
    115 
    116   // create a new line ?
    117   if (++$row_number == $user['nb_image_line'])
    118   {
    119     $template->assign_block_vars('thumbnails.line', array());
    120     $row_number = 0;
     147    $template->assign_block_vars(
     148      'thumbnails.line.thumbnail',
     149      array(
     150        'IMAGE' => $images[$item['picture']],
     151        'IMAGE_ALT' => $item['name'],
     152        'IMAGE_TITLE' => $lang['hint_category'],
     153        'IMAGE_TS' => get_icon(@$item['date_last']),
     154        'U_IMG_LINK' =>
     155          add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$item['category'])
     156        )
     157      );
     158   
     159    $template->assign_block_vars(
     160      'thumbnails.line.thumbnail.category_name',
     161      array(
     162        'NAME' => $item['name']
     163        )
     164      );
     165   
     166    // create a new line ?
     167    if (++$row_number == $user['nb_image_line'])
     168    {
     169      $template->assign_block_vars('thumbnails.line', array());
     170      $row_number = 0;
     171    }
    121172  }
    122173}
  • trunk/include/config_default.inc.php

    r808 r809  
    253253// guest_id : id of the anonymous user
    254254$conf['guest_id'] = 2;
     255
     256// allow_random_representative : do you wish PhpWebGallery to search among
     257// categories elements a new representative at each reload ?
     258//
     259// If false, an element is randomly or manually chosen to represent its
     260// category and remains the representative as long as an admin does not
     261// change it.
     262//
     263// Warning : setting this parameter to true is CPU consuming. Each time you
     264// change the value of this parameter from false to true, an administrator
     265// must update categories informations in screen [Admin > General >
     266// Maintenance].
     267$conf['allow_random_representative'] = false;
    255268?>
  • trunk/template/default/admin.tpl

    r792 r809  
    2121  <li><a class="adminMenu" href="{U_HISTORY}">{L_HISTORY}</a></li>
    2222  <li><a class="adminMenu" href="{U_CAT_UPDATE}">{L_UPDATE}</a></li>
     23  <li><a class="adminMenu" href="{U_MAINTENANCE}">{lang:Maintenance}</a></li>
    2324</ul>
    2425</div>
     
    4243  <li><a class="adminMenu" href="{U_CAT_VISIBLE}">{L_CAT_VISIBLE}</a></li>
    4344  <li><a class="adminMenu" href="{U_CAT_STATUS}">{L_CAT_STATUS}</a></li>
     45  <!-- BEGIN representative -->
     46  <li><a class="adminMenu" href="{representative.URL}">{lang:Representatve}</a></li>
     47  <!-- END representative -->
    4448</ul>
    4549</div>
     
    9296  </div>
    9397  <!-- END infos -->
    94 
    95   <div align="center">{ADMIN_CONTENT}{ADMIN_CONTENT_2}</div>
     98  <div id="adminMain">
     99    {ADMIN_CONTENT}{ADMIN_CONTENT_2}
     100  </div>
    96101</div>
    97102        </td>
  • trunk/template/default/admin/cat_modify.tpl

    r792 r809  
    1 <div class="admin">{CATEGORIES_NAV}</div>
     1<h2>{CATEGORIES_NAV}</h2>
     2
     3<ul class="categoryActions">
     4  <li><a href="{U_JUMPTO}" title="{lang:jump to category}"><img src="./template/default/theme/category_jump-to.png" alt="{lang:jump to}" /></a></li>
     5  <!-- BEGIN elements -->
     6  <li><a href="{elements.URL}" title="{lang:manage category elements}"><img src="./template/default/theme/category_elements.png" alt="{lang:elements}" /></a></li>
     7  <!-- END elements -->
     8  <li><a href="{U_CHILDREN}" title="{lang:manage sub-categories}"><img src="./template/default/theme/category_children.png" alt="{lang:sub-categories}" /></a></li>
     9  <!-- BEGIN permissions -->
     10  <li><a href="{permissions.URL}" title="{lang:edit category permissions}" ><img src="./template/default/theme/category_permissions.png" alt="{lang:permissions}" /></a></li>
     11  <!-- END permissions -->
     12  <!-- BEGIN delete -->
     13  <li><a href="{delete.URL}" title="{lang:delete category}"><img src="./template/default/theme/category_delete.png" alt="{lang:delete}" /></a></li>
     14  <!-- END delete -->
     15</ul>
     16
    217<form action="{F_ACTION}" method="POST">
    3 <table style="width:100%;">
    4     <!-- BEGIN representant -->
    5     <tr>
    6       <td style="width:50%;" align="center">
    7         <a href="{representant.URL}"><img src="{representant.SRC}" alt="" class="miniature" /></a>
    8       </td>
    9       <td class="row1"><input type="submit" name="set_random_representant" value="{L_SET_RANDOM_REPRESENTANT}" class="bouton" /></td>
    10     </tr>
    11     <!-- END representant -->
    12   </table>
    13 </form>
    14 <form action="{F_ACTION}" method="POST">
    15 <table style="width:100%;">
     18
     19<fieldset>
     20  <legend>{lang:Informations}</legend>
     21  <table>
    1622    <!-- BEGIN server -->
    1723    <tr>
    18       <td style="width:50%;"><strong>{L_REMOTE_SITE}</strong></td>
    19       <td class="row1">{server.SITE_URL}</td>
     24      <td><strong>{L_REMOTE_SITE}</strong></td>
     25      <td>{server.SITE_URL}</td>
    2026    </tr>
    2127    <!-- END server -->
     28    <!-- BEGIN storage -->
    2229    <tr>
    23       <td style="width:50%;"><strong>{L_EDIT_NAME}</strong></td>
    24       <td class="row1">
     30      <td><strong>{L_STORAGE}</strong></td>
     31      <td class="row1">{storage.CATEGORY_DIR}</td>
     32    </tr>
     33    <!-- END storage -->
     34    <tr>
     35      <td><strong>{L_EDIT_NAME}</strong></td>
     36      <td>
    2537        <input type="text" name="name" value="{CAT_NAME}" maxlength="60"/>
    2638      </td>
    2739    </tr>
    28         <!-- BEGIN storage -->
    29         <tr>
    30       <td><strong>{L_STORAGE}</strong></td>
    31       <td class="row1">{storage.CATEGORY_DIR}</td>
    32     </tr>
    33         <!-- END storage -->
    3440    <tr>
    3541      <td><strong>{L_EDIT_COMMENT}</strong></td>
    36       <td class="row1">
     42      <td>
    3743        <textarea name="comment" rows="3" cols="50" >{CAT_COMMENT}</textarea>
    3844      </td>
    3945    </tr>
    40         <tr class="admin">
    41           <th colspan="2">{L_EDIT_CAT_OPTIONS}</th>
    42         </tr>
     46  </table>
     47</fieldset>
     48
     49<!-- BEGIN move -->
     50<fieldset>
     51  <legend>{lang:Move}</legend>
     52  {lang:Parent category}
     53  <select name="parent">
     54    <!-- BEGIN parent_option -->
     55    <option class="{move.parent_option.CLASS}" {move.parent_option.SELECTED} value="{move.parent_option.VALUE}">{move.parent_option.OPTION}</option>
     56    <!-- END parent_option -->
     57  </select> 
     58</fieldset>
     59<!-- END move -->
     60
     61<fieldset>
     62  <legend>{lang:Options}</legend>
     63  <table>
    4364    <tr>
    44       <td><strong>{L_EDIT_STATUS}&nbsp;:</strong><br /><span class="small">{L_EDIT_STATUS_INFO}</span></td>
    45       <td class="row1">
    46           <input type="radio" class="radio" name="status" value="public" {STATUS_PUBLIC} />{L_STATUS_PUBLIC}&nbsp;&nbsp;
    47           <input type="radio" class="radio" name="status" value="private" {STATUS_PRIVATE} />{L_STATUS_PRIVATE}
     65      <td><strong>{L_EDIT_STATUS}</strong><br /><span class="small">{L_EDIT_STATUS_INFO}</span></td>
     66      <td>
     67          <input type="radio" name="status" value="public" {STATUS_PUBLIC} />{L_STATUS_PUBLIC}
     68          <input type="radio" name="status" value="private" {STATUS_PRIVATE} />{L_STATUS_PRIVATE}
    4869      </td>
    4970    </tr>
    5071    <tr>
    51       <td><strong>{L_EDIT_LOCK}&nbsp;:</strong><br /><span class="small">{L_EDIT_LOCK_INFO}</span></td>
    52       <td class="row1">
    53           <input type="radio" class="radio" name="visible" value="false" {LOCKED} />{L_YES}&nbsp;&nbsp;
    54           <input type="radio" class="radio" name="visible" value="true" {UNLOCKED} />{L_NO}
     72      <td><strong>{L_EDIT_LOCK}</strong><br /><span class="small">{L_EDIT_LOCK_INFO}</span></td>
     73      <td>
     74          <input type="radio" name="visible" value="false" {LOCKED} />{L_YES}
     75          <input type="radio" name="visible" value="true" {UNLOCKED} />{L_NO}
    5576      </td>
    5677    </tr>
    5778    <tr>
    58       <td><strong>{L_EDIT_COMMENTABLE}&nbsp;:</strong><br /><span class="small">{L_EDIT_COMMENTABLE_INFO}</span></td>
    59       <td class="row1">
    60           <input type="radio" class="radio" name="commentable" value="true" {COMMENTABLE_TRUE} />{L_YES}&nbsp;&nbsp;
    61           <input type="radio" class="radio" name="commentable" value="false" {COMMENTABLE_FALSE} />{L_NO}
     79      <td><strong>{L_EDIT_COMMENTABLE}</strong><br /><span class="small">{L_EDIT_COMMENTABLE_INFO}</span></td>
     80      <td>
     81          <input type="radio" name="commentable" value="true" {COMMENTABLE_TRUE} />{L_YES}
     82          <input type="radio" name="commentable" value="false" {COMMENTABLE_FALSE} />{L_NO}
    6283      </td>
    6384    </tr>
    6485    <!-- BEGIN upload -->
    6586    <tr>
    66       <td><strong>{L_EDIT_UPLOADABLE}&nbsp;:</strong><br /><span class="small">{L_EDIT_UPLOADABLE_INFO}</span></td>
    67       <td class="row1">
    68           <input type="radio" class="radio" name="uploadable" value="true" {UPLOADABLE_TRUE} />{L_YES}&nbsp;&nbsp;
    69           <input type="radio" class="radio" name="uploadable" value="false" {UPLOADABLE_FALSE} />{L_NO}
     87      <td><strong>{L_EDIT_UPLOADABLE}</strong><br /><span class="small">{L_EDIT_UPLOADABLE_INFO}</span></td>
     88      <td>
     89          <input type="radio" name="uploadable" value="true" {UPLOADABLE_TRUE} />{L_YES}
     90          <input type="radio" name="uploadable" value="false" {UPLOADABLE_FALSE} />{L_NO}
    7091      </td>
    7192    </tr>
    7293    <!-- END upload -->
     94  </table>
     95</fieldset>
     96
     97<p style="text-align:center;">
     98  <input type="submit" value="{L_SUBMIT}" name="submit" />
     99  <input type="reset" value="{lang:Reset}" name="reset" />
     100</p>
     101
     102<!-- BEGIN representant -->
     103<fieldset>
     104  <legend>{lang:Representant}</legend>
     105  <table>
    73106    <tr>
    74       <td colspan="2">&nbsp;</td>
    75     </tr>
    76     <tr>
    77       <td colspan="2" align="center">
    78         <input type="submit" name="submit" value="{L_SUBMIT}" class="bouton" />
     107      <td align="center">
     108        <!-- BEGIN picture -->
     109        <a href="{representant.picture.URL}"><img src="{representant.picture.SRC}" alt="" class="miniature" /></a>
     110        <!-- END picture -->
     111
     112        <!-- BEGIN random -->
     113        <img src="./template/default/theme/category_representant_random.png" alt="{lang:Random picture}" class="miniature" />
     114        <!-- END random -->
     115      </td>
     116      <td>
     117        <!-- BEGIN set_random -->
     118        <p><input type="submit" name="set_random_representant" value="{L_SET_RANDOM_REPRESENTANT}" /></p>
     119        <!-- END set_random -->
     120
     121        <!-- BEGIN delete_representant -->
     122        <p><input type="submit" name="delete_representant" value="{lang:Delete Representant}" /></p>
     123        <!-- END delete_representant -->
    79124      </td>
    80125    </tr>
    81126  </table>
     127</fieldset>
     128<!-- END representant -->
     129
    82130</form>
  • trunk/template/default/default.css

    r803 r809  
    4848        line-height:    120%;
    4949        font-size:18px;
    50         font-weight: bold;
    51 }
    52 
    53 h2 /* H2 tag style (admin side only) */
    54 {
    55         font-family: Arial, Helvetica, sans-serif;
    56         text-decoration:none;
    57         line-height:    120%;
    58         font-size:12px;
    5950        font-weight: bold;
    6051}
     
    366357}
    367358
     359div#adminMain {
     360  text-align: left;
     361}
     362
     363div#adminMain h2 {
     364  background-color: #3f3f3f;
     365  text-align: center;
     366  font-size: 120%;
     367}
     368
    368369div.adminMenu{ margin:10px 50px 10px 50px; }
    369370
     
    412413  float: right;
    413414  margin-top: 5px;
     415}
     416
     417div#adminMain>ul.categoryActions {
     418  text-align: center;
    414419}
    415420
     
    491496  white-space: nowrap;
    492497}
     498
     499fieldset {
     500  border: 1px solid gray;
     501}
     502
     503fieldset>legend {
     504  margin: 5px;
     505}
Note: See TracChangeset for help on using the changeset viewer.