Changeset 647


Ignore:
Timestamp:
Dec 18, 2004, 11:05:30 PM (19 years ago)
Author:
plg
Message:
  • bug fixed : in admin/cat_list, next_rank cant' be calculted and query to count sub-categories per sub-categories became false if no sub-categories
  • virtual association come back in admin/infos_images (not only in admin/picture_modify)
  • check_favorites function in admin section becomes check_user_favorites in public section : favorites are checked when user tries to display his favorites. Function was optimized.
  • in function update_category, wrap of long queries due to many categories to update at the same time
  • typo fixed in description of paginate_pages_around configuration parameter
  • bug fixed in new navigation bar : no separation pipe was displayed between next and last when the page displayed was the last
  • sessions.expiration changed of type from int to datetime (a lot easier to read)
  • sessions.ip removed : IP address is no longer used to verify session
  • typo fixed in language/en_UK.iso-8859-1/admin.lang.php on editcat_lock_info language item
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r642 r647  
    328328}
    329329
     330if (count($categories) > 0)
     331{
     332  $next_rank = max(array_keys($categories)) + 1;
     333}
     334else
     335{
     336  $next_rank = 1;
     337}
     338
    330339$template->assign_vars(array(
    331340  'CATEGORIES_NAV'=>$navigation,
    332   'NEXT_RANK'=>max(array_keys($categories))+1,
     341  'NEXT_RANK'=>$next_rank,
    333342  'F_ACTION'=>$form_action,
    334343 
     
    368377// +-----------------------------------------------------------------------+
    369378$ranks = array();
    370 foreach ($categories as $category)
    371 {
    372   $ranks[$category['id']] = $category['rank'];
    373 }
    374 
    375 $query = '
     379
     380if (count($categories) > 0)
     381{
     382  foreach ($categories as $category)
     383  {
     384    $ranks[$category['id']] = $category['rank'];
     385  }
     386
     387  $query = '
    376388SELECT id_uppercat, COUNT(*) AS nb_subcats
    377389  FROM '. CATEGORIES_TABLE.'
     
    379391  GROUP BY id_uppercat
    380392;';
    381 $result = pwg_query($query);
    382 while ($row = mysql_fetch_array($result))
    383 {
    384   $categories[$ranks[$row['id_uppercat']]]['nb_subcats'] = $row['nb_subcats'];
     393  $result = pwg_query($query);
     394  while ($row = mysql_fetch_array($result))
     395  {
     396    $categories[$ranks[$row['id_uppercat']]]['nb_subcats']
     397      = $row['nb_subcats'];
     398  }
    385399}
    386400
  • trunk/admin/include/functions.php

    r642 r647  
    392392}
    393393
    394 // The check_favorites function deletes all the favorites of a user if he is
    395 // not allowed to see them (the category or an upper category is restricted
    396 // or invisible)
    397 function check_favorites( $user_id )
    398 {
    399   $query = 'SELECT status,forbidden_categories';
    400   $query.= ' FROM '.USERS_TABLE;
    401   $query.= ' WHERE id = '.$user_id;
    402   $query.= ';';
    403   $row = mysql_fetch_array( pwg_query( $query ) );
    404   $status = $row['status'];
    405   // retrieving all the restricted categories for this user
    406   if ( isset( $row['forbidden_categories'] ) )
    407     $restricted_cat = explode( ',', $row['forbidden_categories'] );
    408   else
    409     $restricted_cat = array();
    410   // retrieving all the favorites for this user and comparing their
    411   // categories to the restricted categories
    412   $query = 'SELECT image_id FROM '.FAVORITES_TABLE;
    413   $query.= ' WHERE user_id = '.$user_id;
    414   $query.= ';';
    415   $result = pwg_query ( $query );
    416   while ( $row = mysql_fetch_array( $result ) )
    417   {
    418     // for each picture, we have to check all the categories it belongs
    419     // to. Indeed if a picture belongs to category_1 and category_2 and that
    420     // category_2 is not restricted to the user, he can have the picture as
    421     // favorite.
    422     $query = 'SELECT DISTINCT(category_id) as category_id';
    423     $query.= ' FROM '.PREFIX_TABLE.'image_category';
    424     $query.= ' WHERE image_id = '.$row['image_id'];
    425     $query.= ';';
    426     $picture_result = pwg_query( $query );
    427     $picture_cat = array();
    428     while ( $picture_row = mysql_fetch_array( $picture_result ) )
    429     {
    430       array_push( $picture_cat, $picture_row['category_id'] );
    431     }
    432     if ( count( array_diff( $picture_cat, $restricted_cat ) ) == 0 )
    433     {
    434       $query = 'DELETE FROM '.FAVORITES_TABLE;
    435       $query.= ' WHERE image_id = '.$row['image_id'];
    436       $query.= ' AND user_id = '.$user_id;
    437       $query.= ';';
    438       pwg_query( $query );
    439     }
    440   }
    441 }
    442 
    443394/**
    444395 * updates calculated informations about a set of categories : date_last and
     
    480431    {
    481432      $query.= '
    482   WHERE id IN ('.implode(',', $ids).')';
     433  WHERE id IN ('.wordwrap(implode(', ', $ids), 80, "\n").')';
    483434    }
    484435  }
     
    503454       MAX(date_available) AS date_last
    504455  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
    505   WHERE category_id IN ('.implode(',', $cat_ids).')
     456  WHERE category_id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    506457  GROUP BY category_id
    507458;';
     
    543494    ON id = category_id AND representative_picture_id = image_id
    544495  WHERE representative_picture_id IS NOT NULL
    545     AND id IN ('.implode(',', $cat_ids).')
     496    AND id IN ('.wordwrap(implode(', ', $cat_ids), 80, "\n").')
    546497    AND category_id IS NULL
    547498;';
  • trunk/admin/infos_images.php

    r642 r647  
    6161    }
    6262
    63     $associate = false;
    64    
    6563    $query = 'SELECT id,file FROM '.IMAGES_TABLE;
    6664    $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
     
    112110      }
    113111      // add link to another category
    114       if (isset($_POST['check-'.$row['id']]) and count($errors) == 0)
     112      if (isset($_POST['check-'.$row['id']])
     113          and isset($_POST['associate'])
     114          and $_POST['associate'] != '')
    115115      {
    116116        $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
     
    119119        $query.= ';';
    120120        pwg_query($query);
    121         $associate = true;
    122       }
    123     }
    124     if (isset($_POST['associate'])) update_category($_POST['associate']);
    125     if ($associate) synchronize_all_users();
     121      }
     122    }
     123    if (isset($_POST['associate']) and $_POST['associate'] != '')
     124    {
     125      update_category(array($_POST['associate']));
     126    }
    126127// +-----------------------------------------------------------------------+
    127128// |                        update general options                         |
     
    337338 
    338339  // Virtualy associate a picture to a category
    339   //
    340   // We only show a List Of Values if the number of categories is less than
    341   // $conf['max_LOV_categories']
    342   $query = 'SELECT COUNT(id) AS nb_total_categories';
    343   $query.= ' FROM '.CATEGORIES_TABLE.';';
    344   $row = mysql_fetch_array(pwg_query($query));
    345   if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
    346   {
    347     /*$vtp->addSession($sub, 'associate_LOV');
    348     $page['plain_structure'] = get_plain_structure(true);
    349     $structure = create_structure('', array());
    350     display_categories($structure, '&nbsp;');
    351     $vtp->closeSession($sub, 'associate_LOV');*/
    352   }
    353   // else, we only display a small text field, we suppose the administrator
    354   // knows the id of its category
    355   else
    356   {
    357     //$vtp->addSession($sub, 'associate_text');
    358     //$vtp->closeSession($sub, 'associate_text');
    359   }
     340  $query = '
     341SELECT id,name,uppercats,global_rank
     342  FROM '.CATEGORIES_TABLE.'
     343;';
     344  display_select_cat_wrapper($query,
     345                             array(),
     346                             'associate_option',
     347                             true);
    360348}
    361349//----------------------------------------------------------- sending html code
  • trunk/include/config.inc.php

    r643 r647  
    191191$conf['level_separator'] = ' / ';
    192192
    193 // paginate_pages_around : on paginate navigation bar, on many pages display
    194 // before and after the current page ?
     193// paginate_pages_around : on paginate navigation bar, how many pages
     194// display before and after the current page ?
    195195$conf['paginate_pages_around'] = 2;
    196196?>
  • trunk/include/functions_category.inc.php

    r642 r647  
    562562      else if ( $page['cat'] == 'fav' )
    563563      {
     564        check_user_favorites();
     565       
    564566        $page['title'] = $lang['favorites'];
    565567
  • trunk/include/functions_html.inc.php

    r645 r647  
    159159      $navbar.= $lang['next_page'];
    160160    }
     161   
     162    $navbar.= ' | ';
    161163    // link to last page ?
    162164    if ($cur_page != $maximum)
    163165    {
    164166      $temp_start = ($maximum - 1) * $nb_element_page;
    165       $navbar.= ' | ';
    166167      $navbar.= '<a href="';
    167168      $navbar.= add_session_id($url.'&amp;start='.$temp_start);
  • trunk/include/functions_session.inc.php

    r593 r647  
    8787  }
    8888  // 3. inserting session in database
    89   $expiration = $session_length + time();
    9089  $query = '
    9190INSERT INTO '.SESSIONS_TABLE.'
    92   (id,user_id,expiration,ip)
     91  (id,user_id,expiration)
    9392  VALUES
    94   (\''.$generated_id.'\','.$userid.','.$expiration.',
    95    \''.$_SERVER['REMOTE_ADDR'].'\')
     93  (\''.$generated_id.'\','.$userid.',
     94   ADDDATE(NOW(), INTERVAL '.$session_length.' SECOND))
    9695;';
    9796  pwg_query($query);
    9897
     98  $expiration = $session_length + time();
    9999  setcookie('id', $generated_id, $expiration, cookie_path());
    100100               
  • trunk/include/functions_user.inc.php

    r631 r647  
    238238  return ( $row = mysql_fetch_array($result) ) ? $row : false;
    239239}
     240
     241/*
     242 * deletes favorites of the current user if he's not allowed to see them
     243 *
     244 * @return void
     245 */
     246function check_user_favorites()
     247{
     248  global $user;
     249
     250  if ($user['forbidden_categories'] == '')
     251  {
     252    return;
     253  }
     254 
     255  $query = '
     256SELECT f.image_id
     257  FROM '.FAVORITES_TABLE.' AS f INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
     258    ON f.image_id = ic.image_id
     259  WHERE f.user_id = '.$user['id'].'
     260    AND ic.category_id IN ('.$user['forbidden_categories'].')
     261;';
     262  $result = pwg_query($query);
     263  $elements = array();
     264  while ($row = mysql_fetch_array($result))
     265  {
     266    array_push($elements, $row['image_id']);
     267  }
     268
     269  if (count($elements) > 0)
     270  {
     271    $query = '
     272DELETE FROM '.FAVORITES_TABLE.'
     273  WHERE image_id IN ('.implode(',', $elements).')
     274    AND user_id = '.$user['id'].'
     275;';
     276    pwg_query($query);
     277  }
     278}
    240279?>
  • trunk/include/user.inc.php

    r593 r647  
    6060  $page['session_id'] = $session_id;
    6161  $query = '
    62 SELECT user_id,expiration,ip
     62SELECT user_id,expiration,NOW() AS now
    6363  FROM '.SESSIONS_TABLE.'
    6464  WHERE id = \''.$page['session_id'].'\'
     
    6868  {
    6969    $row = mysql_fetch_array($result);
    70     if (!$user['has_cookie'])
     70    if (strnatcmp($row['expiration'], $row['now']) < 0)
    7171    {
    72       if ($row['expiration'] < time())
    73       {
    74         // deletion of the session from the database,
    75         // because it is out-of-date
    76         $delete_query = 'DELETE FROM '.SESSIONS_TABLE;
    77         $delete_query.= " WHERE id = '".$page['session_id']."'";
    78         $delete_query.= ';';
    79         pwg_query($delete_query);
    80       }
    81       else if ($_SERVER['REMOTE_ADDR'] == $row['ip'])
    82       {
    83         $query_user .= ' WHERE id = '.$row['user_id'];
    84         $query_done = true;
    85       }
     72      // deletion of the session from the database, because it is
     73      // out-of-date
     74      $delete_query = '
     75DELETE FROM '.SESSIONS_TABLE.'
     76  WHERE id = \''.$page['session_id'].'\'
     77;';
     78      pwg_query($delete_query);
    8679    }
    8780    else
  • trunk/install/dbscheme.txt

    r614 r647  
    7979column:id                        table:sessions       type:varchar                  nullable:N length:255 binary:Y
    8080column:user_id                   table:sessions       type:smallint                 nullable:N length:5   signed:N
    81 column:expiration                table:sessions       type:int                      nullable:N length:10  signed:N
    82 column:ip                        table:sessions       type:varchar                  nullable:N length:255 binary:N
     81column:expiration                table:sessions       type:datetime                 nullable:N
    8382column:id                        table:sites          type:tinyint                  nullable:N length:4   signed:Y
    8483column:galleries_url             table:sites          type:varchar                  nullable:N length:255 binary:N
     
    120119PK:group_access_pk   table:group_access   column:cat_id
    121120PK:groups_pk         table:groups         column:id
    122 PK:history_pk        table:history        column:date
    123121PK:image_category_pk table:image_category column:image_id
    124122PK:image_category_pk table:image_category column:category_id
     
    136134
    137135index:categories_i2     table:categories     column:id_uppercat
     136index:history_i1        table:history        column:date
    138137index:image_category_i1 table:image_category column:image_id
    139138index:image_category_i2 table:image_category column:category_id
  • trunk/install/phpwebgallery_structure.sql

    r616 r647  
    171171  id varchar(255) binary NOT NULL default '',
    172172  user_id smallint(5) unsigned NOT NULL default '0',
    173   expiration int(10) unsigned NOT NULL default '0',
    174   ip varchar(255) NOT NULL default '',
     173  expiration datetime NOT NULL default '0000-00-00 00:00:00',
    175174  PRIMARY KEY  (id)
    176175) TYPE=MyISAM;
  • trunk/language/en_UK.iso-8859-1/admin.lang.php

    r646 r647  
    8888// Categories
    8989$lang['cat_security'] = 'Public / Private';
     90$lang['cat_options'] = 'Category options';
    9091$lang['cat_add'] = 'Add a virtual category';
    9192$lang['cat_virtual'] = 'Virtual category';
     
    9697$lang['editcat_confirm'] = 'Category informations updated successfully.';
    9798$lang['editcat_perm'] = 'To set permissions for this category, click';
    98 $lang['editcat_lock_info'] = 'The category and its sub-categories will temporary been disabled for maintenance.'
     99$lang['editcat_lock_info'] = 'The category and its sub-categories will temporary been disabled for maintenance.';
    99100$lang['editcat_uploadable'] = 'Authorize upload';
    100101$lang['editcat_uploadable_info'] = 'Authorize users to upload files';
  • trunk/template/default/admin/infos_images.tpl

    r589 r647  
    7979    <tr>
    8080      <td colspan="7">
    81         <img src="./template/default/admin/images/arrow_select.gif" alt="&lt;" />
     81        <img src="./template/default/admin/images/arrow_select.gif" alt="&uarr;" />
    8282        {L_INFOS_ASSOCIATE}
    83         <!-- BEGIN associate_LOV -->
    84         <select name="associate">
    85           <!-- BEGIN associate_cat -->
    86           <option value="{#value}">{#content}</option>
    87           <!-- END associate_cat -->
     83        <select style="width:400px" name="associate" size="1">
     84          <!-- BEGIN associate_option -->
     85          <option {associate_option.SELECTED} value="{associate_option.VALUE}">{associate_option.OPTION}</option>
     86          <!-- END category_option -->
    8887        </select>
    89         <!-- END associate_LOV -->
    9088      </td>
    9189    </tr>
Note: See TracChangeset for help on using the changeset viewer.