Changeset 345


Ignore:
Timestamp:
Feb 2, 2004, 1:55:18 AM (20 years ago)
Author:
gweltas
Message:

Merge of the 1.3.1 release
Creation of an unique include file (common.php)
Creation of an unique define file (include/constants.php)
Modification of the installation procedure

Location:
trunk
Files:
16 added
4 deleted
59 edited

Legend:

Unmodified
Added
Removed
  • trunk/about.php

    r57 r345  
    1818 ***************************************************************************/
    1919
    20 //----------------------------------------------------------- personnal include
    21 include_once( './include/init.inc.php' );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    2223//----------------------------------------------------- template initialization
    23 $vtp = new VTemplate;
     24//
     25// Start output of page
     26//
     27$title= $lang['about_page_title'];
     28include('include/page_header.php');
     29
    2430$handle = $vtp->Open( './template/'.$user['template'].'/about.vtp' );
    2531initialize_template();
    2632
    27 $tpl = array('about_page_title','about_title','about_message','about_return');
     33$tpl = array('about_title','about_message','about_return');
    2834templatize_array( $tpl, 'lang', $handle );
    2935$vtp->setVar( $handle, 'user_template', $user['template'] );
     
    3440$code = $vtp->Display( $handle, 0 );
    3541echo $code;
     42include('include/page_tail.php');
    3643?>
  • trunk/admin.php

    r228 r345  
    1818 ***************************************************************************/
    1919
    20 //----------------------------------------------------------- personnal include
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    2123include_once( './admin/include/isadmin.inc.php' );
    2224//----------------------------------------------------- template initialization
     
    3537$page_valide = false;
    3638$title = '';
     39if (isset( $_GET['page'] ))
    3740switch ( $_GET['page'] )
    3841{
  • trunk/admin/cat_list.php

    r226 r345  
    1919 ***************************************************************************/
    2020include_once( './admin/include/isadmin.inc.php' );
     21
    2122//----------------------------------------------------- template initialization
    2223$sub = $vtp->Open( './template/'.$user['template'].'/admin/cat_list.vtp' );
    2324$tpl = array( 'cat_edit','cat_up','cat_down','cat_image_info',
    2425              'cat_permission','cat_update','cat_add','cat_parent','submit',
    25               'cat_virtual','delete','cat_first','cat_last' );
     26              'cat_virtual','delete','cat_first','cat_last','errors_title' );
    2627templatize_array( $tpl, 'lang', $sub );
    2728$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
     
    3031if ( isset( $_POST['submit'] ) )
    3132{
    32   if ( !preg_match( '/^\s*$/', $_POST['virtual_name'] ) )
     33  // is the given category name only containing blank spaces ?
     34  if ( preg_match( '/^\s*$/', $_POST['virtual_name'] ) )
     35    array_push( $errors, $lang['cat_error_name'] );
     36  // does the uppercat id exists in the database ?
     37  if ( $_POST['associate'] == '' )
     38  {
     39    $_POST['associate'] = -1;
     40  }
     41  else if ( !is_numeric( $_POST['associate'] ) )
     42  {
     43    array_push( $errors, $lang['cat_unknown_id'] );
     44  }
     45  else
     46  {
     47    $query = 'SELECT id';
     48    $query.= ' FROM '.PREFIX_TABLE.'categories';
     49    $query.= ' WHERE id = '.$_POST['associate'];
     50    $query.= ';';
     51    if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
     52      array_push( $errors, $lang['cat_unknown_id'] );
     53  }
     54 
     55  if ( count( $errors ) == 0 )
    3356  {
    3457    // we have then to add the virtual category
     
    4265    $query.= ';';
    4366    mysql_query( $query );
    44   }
    45   else
    46   {
    47     array_push( $errors, $lang['cat_error_name'] );
     67    synchronize_all_users();
    4868  }
    4969}
     
    172192{
    173193  delete_category( $_GET['delete'] );
     194  synchronize_all_users();
    174195}
    175196//------------------------------------------------------------------ reordering
     
    234255  $result = mysql_query( $query );
    235256  $row    = mysql_fetch_array( $result );
     257  if ( !isset( $row['min'] ) ) $row['min'] = 0;
     258  if ( !isset( $row['max'] ) ) $row['max'] = 0;
    236259  $min_rank = $row['min'];
    237260  $max_rank = $row['max'];
     
    259282  {
    260283    $subcat_visible = true;
     284    if ( !isset( $row['dir'] ) ) $row['dir'] = '';
    261285
    262286    $vtp->addSession( $sub, 'cat' );
     287    // is the category expanded or not ?
     288    if ( isset($page['expand']) && $page['expand'] == 'all' )
     289    {
     290      $vtp->addSession( $sub, 'bullet_wo_link' );
     291      $vtp->closeSession( $sub, 'bullet_wo_link' );
     292    }
     293    else if ( isset($page['tab_expand']) && in_array( $row['id'], $page['tab_expand'] ) )
     294    {
     295      $vtp->addSession( $sub, 'bullet_expanded' );
     296      $tab_expand = array_diff( $page['tab_expand'], array( $row['id'] ) );
     297      $expand = implode( ',', $tab_expand );
     298      $url = './admin.php?page=cat_list&expand='.$expand;
     299      $vtp->setVar( $sub, 'bullet_expanded.link', add_session_id( $url ) );
     300      $vtp->closeSession( $sub, 'bullet_expanded' );
     301    }
     302    else
     303    {
     304      $vtp->addSession( $sub, 'bullet_collapsed' );
     305      $tab_expand = array_merge( $page['tab_expand'], array( $row['id'] ) );
     306      $expand = implode( ',', $tab_expand );
     307      $url = './admin.php?page=cat_list&expand='.$expand;
     308      $vtp->setVar( $sub, 'bullet_collapsed.link', add_session_id( $url ) );
     309      $vtp->closeSession( $sub, 'bullet_collapsed' );
     310    }
     311   
    263312    $vtp->setVar( $sub, 'cat.td', $td );
    264313    $vtp->setVar( $sub, 'cat.class', $class );
    265314    $vtp->setVar( $sub, 'cat.indent', $indent );
    266315    $vtp->setVar( $sub, 'cat.name', $row['name'] );
    267     $vtp->setVar( $sub, 'cat.id', $row['id'] );
     316
    268317    if ( $row['dir'] != '' )
    269318    {
     
    281330      // category can be deleted
    282331      $vtp->addSession( $sub, 'delete' );
    283       $url = './admin.php?page=cat_list&delete='.$row['id'];
     332      $url = './admin.php?page=cat_list&expand='.$page['expand'];
     333      $url.= '&delete='.$row['id'];
    284334      $vtp->setVar( $sub, 'delete.delete_url', add_session_id( $url ) );
    285335      $vtp->closeSession( $sub, 'delete' );
     
    300350    {
    301351      $vtp->addSession( $sub, 'up' );
    302       $vtp->setVar( $sub, 'up.id', $row['id'] );
    303       $url = add_session_id( './admin.php?page=cat_list&up='.$row['id'] );
    304       $vtp->setVar( $sub, 'up.up_url', $url );
     352      $url = './admin.php?page=cat_list&expand='.$page['expand'];
     353      $url.= '&up='.$row['id'];
     354      $vtp->setVar( $sub, 'up.up_url', add_session_id( $url ) );
    305355      $vtp->closeSession( $sub, 'up' );
    306356    }
     
    308358    {
    309359      $vtp->addSession( $sub, 'no_up' );
    310       $vtp->setVar( $sub, 'no_up.id', $row['id'] );
    311       $url = add_session_id( './admin.php?page=cat_list&last='.$row['id']);
    312       $vtp->setVar( $sub, 'no_up.last_url', $url );
     360      $url = './admin.php?page=cat_list&expand='.$page['expand'];
     361      $url.= '&last='.$row['id'];
     362      $vtp->setVar( $sub, 'no_up.last_url', add_session_id( $url ) );
    313363      $vtp->closeSession( $sub, 'no_up' );
    314364    }
     
    316366    {
    317367      $vtp->addSession( $sub, 'down' );
    318       $vtp->setVar( $sub, 'down.id', $row['id'] );
    319       $url = add_session_id( './admin.php?page=cat_list&down='.$row['id']);
    320       $vtp->setVar( $sub, 'down.down_url', $url );
     368      $url = './admin.php?page=cat_list&expand='.$page['expand'];
     369      $url.= '&down='.$row['id'];
     370      $vtp->setVar( $sub, 'down.down_url', add_session_id( $url ) );
    321371      $vtp->closeSession( $sub, 'down' );
    322372    }
     
    324374    {
    325375      $vtp->addSession( $sub, 'no_down' );
    326       $vtp->setVar( $sub, 'no_down.id', $row['id'] );
    327       $url = add_session_id('./admin.php?page=cat_list&first='.$row['id']);
    328       $vtp->setVar( $sub, 'no_down.first_url', $url );
     376      $url = './admin.php?page=cat_list&expand='.$page['expand'];
     377      $url.= '&first='.$row['id'];
     378      $vtp->setVar( $sub, 'no_down.first_url', add_session_id( $url ) );
    329379      $vtp->closeSession( $sub, 'no_down' );
    330380    }
     
    332382    {
    333383      $vtp->addSession( $sub, 'image_info' );
    334       $url = add_session_id( './admin.php?page=infos_images&cat_id='
    335                              .$row['id'] );
    336       $vtp->setVar( $sub, 'image_info.image_info_url', $url );
     384      $url = './admin.php?page=infos_images&cat_id='.$row['id'];
     385      $vtp->setVar( $sub, 'image_info.image_info_url', add_session_id($url) );
    337386      $vtp->closeSession( $sub, 'image_info' );
    338387    }
     
    372421    $vtp->closeSession( $sub, 'cat' );
    373422
    374     display_cat_manager( $row['id'], $indent.str_repeat( '&nbsp', 4 ),
    375                          $subcat_visible, $level + 1 );
     423    if ( in_array( $row['id'], $page['tab_expand'] )
     424         or $page['expand'] == 'all')
     425      display_cat_manager( $row['id'], $indent.str_repeat( '&nbsp', 4 ),
     426                           $subcat_visible, $level + 1 );
    376427  }
    377428}
    378429display_cat_manager( 'NULL', str_repeat( '&nbsp', 4 ), true, 0 );
    379430// add a virtual category ?
    380 $vtp->addSession( $sub, 'associate_cat' );
    381 $vtp->setVar( $sub, 'associate_cat.value', '-1' );
    382 $vtp->setVar( $sub, 'associate_cat.content', '' );
    383 $vtp->closeSession( $sub, 'associate_cat' );
    384 $page['plain_structure'] = get_plain_structure();
    385 $structure = create_structure( '', array() );
    386 display_categories( $structure, ' ' );
     431// We only show a List Of Values if the number of categories is less than
     432// $conf['max_LOV_categories']
     433$query = 'SELECT COUNT(id) AS nb_total_categories';
     434$query.= ' FROM '.PREFIX_TABLE.'categories';
     435$query.= ';';
     436$row = mysql_fetch_array( mysql_query( $query ) );
     437if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     438{
     439  $vtp->addSession( $sub, 'associate_LOV' );
     440  $vtp->addSession( $sub, 'associate_cat' );
     441  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     442  $vtp->setVar( $sub, 'associate_cat.content', '' );
     443  $vtp->closeSession( $sub, 'associate_cat' );
     444  $page['plain_structure'] = get_plain_structure( true );
     445  $structure = create_structure( '', array() );
     446  display_categories( $structure, '&nbsp;' );
     447  $vtp->closeSession( $sub, 'associate_LOV' );
     448}
     449// else, we only display a small text field, we suppose the administrator
     450// knows the id of its category
     451else
     452{
     453  $vtp->addSession( $sub, 'associate_text' );
     454  $vtp->closeSession( $sub, 'associate_text' );
     455}
    387456//----------------------------------------------------------- sending html code
    388457$vtp->Parse( $handle , 'sub', $sub );
  • trunk/admin/cat_modify.php

    r226 r345  
    4141  $query.= ';';
    4242  $row = mysql_fetch_array( mysql_query( $query ) );
     43 
     44  $query = 'UPDATE '.PREFIX_TABLE.'categories';
     45
     46  $query.= ' SET name = ';
     47  if ( $_POST['name'] == '' )
     48    $query.= 'NULL';
     49  else
     50    $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";
     51
     52  $query.= ', comment = ';
     53  if ( $_POST['comment'] == '' )
     54    $query.= 'NULL';
     55  else
     56    $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
     57
     58  $query.= ", status = '".$_POST['status']."'";
     59  $query.= ", visible = '".$_POST['visible']."'";
     60
     61  if ( isset( $_POST['uploadable'] ) )
     62    $query.= ", uploadable = '".$_POST['uploadable']."'";
     63
     64  if ( isset( $_POST['associate'] ) )
     65  {
     66    $query.= ', id_uppercat = ';
     67    if ( $_POST['associate'] == -1 or $_POST['associate'] == '' )
     68      $query.= 'NULL';
     69    else
     70      $query.= $_POST['associate'];
     71  }
     72  $query.= ' WHERE id = '.$_GET['cat'];
     73  $query.= ';';
     74  mysql_query( $query );
    4375
    4476  if ( $_POST['status'] != $row['status'] )
     
    5486    $query.= ' WHERE cat_id = '.$_GET['cat'];
    5587    mysql_query( $query );
    56   }
    57  
    58   $query = 'UPDATE '.PREFIX_TABLE.'categories';
    59 
    60   $query.= ' SET name = ';
    61   if ( $_POST['name'] == '' )
    62     $query.= 'NULL';
    63   else
    64     $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES)."'";
    65 
    66   $query.= ', comment = ';
    67   if ( $_POST['comment'] == '' )
    68     $query.= 'NULL';
    69   else
    70     $query.= "'".htmlentities( $_POST['comment'], ENT_QUOTES )."'";
    71 
    72   $query.= ", status = '".$_POST['status']."'";
    73   $query.= ", visible = '".$_POST['visible']."'";
    74 
    75   if ( isset( $_POST['uploadable'] ) )
    76     $query.= ", uploadable = '".$_POST['uploadable']."'";
    77 
    78   if ( isset( $_POST['associate'] ) )
    79   {
    80     $query.= ', id_uppercat = ';
    81     if ( $_POST['associate'] == -1 ) $query.= 'NULL';
    82     else                             $query.= $_POST['associate'];
    83   }
    84   $query.= ' WHERE id = '.$_GET['cat'];
    85   $query.= ';';
    86   mysql_query( $query );
     88    // resynchronize all users
     89    synchronize_all_users();
     90  }
    8791
    8892  // checking users favorites
     
    112116$query.= ';';
    113117$row = mysql_fetch_array( mysql_query( $query ) );
     118
     119if ( !isset( $row['dir'] ) ) $row['dir'] = '';
     120if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
     121
    114122$result = get_cat_info( $row['id'] );
    115123// cat name
     
    136144}
    137145$vtp->setVar( $sub, 'name',    $row['name'] );
     146if ( !isset( $row['comment'] ) ) $row['comment'] = '';
    138147$vtp->setVar( $sub, 'comment', $row['comment'] );
    139148// status : public, private...
     
    204213{
    205214  $vtp->addSession( $sub, 'parent' );
    206   $vtp->addSession( $sub, 'associate_cat' );
    207   $vtp->setVar( $sub, 'associate_cat.value', '-1' );
    208   $vtp->setVar( $sub, 'associate_cat.content', '' );
    209   $vtp->closeSession( $sub, 'associate_cat' );
    210   $structure = create_structure( '', array() );
    211   display_categories( $structure, '&nbsp;', $row['id_uppercat'], $row['id'] );
     215  // We only show a List Of Values if the number of categories is less than
     216  // $conf['max_LOV_categories']
     217  $query = 'SELECT COUNT(id) AS nb_total_categories';
     218  $query.= ' FROM '.PREFIX_TABLE.'categories';
     219  $query.= ';';
     220  $countrow = mysql_fetch_array( mysql_query( $query ) );
     221  if ( $countrow['nb_total_categories'] < $conf['max_LOV_categories'] )
     222  {
     223    $vtp->addSession( $sub, 'associate_LOV' );
     224    $vtp->addSession( $sub, 'associate_cat' );
     225    $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     226    $vtp->setVar( $sub, 'associate_cat.content', '' );
     227    $vtp->closeSession( $sub, 'associate_cat' );
     228    $page['plain_structure'] = get_plain_structure( true );
     229    $structure = create_structure( '', array() );
     230    display_categories( $structure, '&nbsp;', $row['id_uppercat'],$row['id'] );
     231    $vtp->closeSession( $sub, 'associate_LOV' );
     232  }
     233  // else, we only display a small text field, we suppose the administrator
     234  // knows the id of its category
     235  else
     236  {
     237    $vtp->addSession( $sub, 'associate_text' );
     238    $vtp->setVar( $sub, 'associate_text.value', $row['id_uppercat'] );
     239    $vtp->closeSession( $sub, 'associate_text' );
     240  }
    212241  $vtp->closeSession( $sub, 'parent' );
    213242}
  • trunk/admin/cat_perm.php

    r226 r345  
    8484    check_favorites( $row['id'] );
    8585  }
     86  // resynchronize all users
     87  synchronize_all_users();
    8688}
    8789//---------------------------------------------------------------------- groups
     
    150152  // for color of user : (red means access forbidden, green authorized) we
    151153  // ask all forbidden categories, including the groups rights
    152   $restrictions = get_restrictions( $row['id'], $row['status'], false );
     154  $restrictions = get_user_restrictions( $row['id'], $row['status'], false );
    153155  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
    154156  if ( $is_user_allowed == 0 )
     
    162164  // for permission update button, we only ask forbidden categories for the
    163165  // user, not taking into account the groups the user belongs to
    164   $restrictions = get_restrictions( $row['id'], $row['status'], false, false );
     166  $restrictions = get_user_restrictions($row['id'],$row['status'],false,false);
    165167  $is_user_allowed = is_user_allowed( $page['cat'], $restrictions );
    166168  if ( $is_user_allowed == 2 )
  • trunk/admin/comments.php

    r231 r345  
    3737    $subrow = mysql_fetch_array( $subresult );
    3838
    39     if ( $array_cat_directories[$subrow['cat_id']] == '' )
     39    if ( !isset( $array_cat_directories[$subrow['cat_id']] ) )
    4040    {
    4141      $array_cat_directories[$subrow['cat_id']] =
     
    5050    // name of the picture
    5151    $name = $array_cat_names[$subrow['cat_id']].' &gt; ';
    52     if ( $subrow['name'] != '' )
     52    if ( isset( $subrow['name'] ) and $subrow['name'] != '' )
    5353    {
    5454      $name.= $subrow['name'];
     
    160160$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
    161161//--------------------------------------------------- number of days to display
    162 if ( isset( $_GET['last_days'] ) ) define( "MAX_DAYS", $_GET['last_days'] );
    163 else                               define( "MAX_DAYS", 0 );
     162if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
     163else                               define( 'MAX_DAYS', 0 );
    164164//----------------------------------------- non specific section initialization
    165165$array_cat_directories = array();
  • trunk/admin/configuration.php

    r228 r345  
    6161  }
    6262  // deletion of site as asked
     63  $site_deleted = false;
    6364  $query = 'SELECT id';
    6465  $query.= ' FROM '.PREFIX_TABLE.'sites';
     
    7172    {
    7273      delete_site( $row['id'] );
    73       // if any picture of this site were linked to another categories, we
    74       // have to update the informations of those categories. To make it
    75       // simple, we just update all the categories
    76       update_category( 'all' );
     74      $site_deleted = true;
    7775    }
     76  }
     77  // if any picture of this site were linked to another categories, we have
     78  // to update the informations of those categories. To make it simple, we
     79  // just update all the categories
     80  if ( $site_deleted )
     81  {
     82    update_category( 'all' );
     83    synchronize_all_users();
    7884  }
    7985  // thumbnail prefix must not contain accentuated characters
     
    235241{
    236242//--------------------------------------------------------- data initialization
    237   $query  = 'SELECT';
    238   foreach ( $conf_infos as $i => $conf_info ) {
    239     if ( $i > 0 ) $query.= ',';
    240     else          $query.= ' ';
    241     $query.= $conf_info;
    242   }
     243  $query  = 'SELECT '.implode( ',', $conf_infos );
    243244  $query .= ' FROM '.PREFIX_TABLE.'config;';
    244245  $row = mysql_fetch_array( mysql_query( $query ) );
    245   foreach ( $conf_infos as $conf_info ) {
    246     $$conf_info = $row[$conf_info];
    247   }
    248 
    249   $query  = 'SELECT';
    250   foreach ( $default_user_infos as $i => $default_user_info ) {
    251     if ( $i > 0 ) $query.= ',';
    252     else          $query.= ' ';
    253     $query.= $default_user_info;
    254   }
     246  foreach ( $conf_infos as $info ) {
     247    if ( isset( $row[$info] ) ) $$info = $row[$info];
     248    else                        $$info = '';
     249  }
     250
     251  $query  = 'SELECT '.implode( ',', $default_user_infos );
    255252  $query.= ' FROM '.PREFIX_TABLE.'users';
    256253  $query.= " WHERE username = 'guest'";
    257254  $query.= ';';
    258255  $row = mysql_fetch_array( mysql_query( $query ) );
    259   foreach ( $default_user_infos as $default_user_info ) {
    260     $$default_user_info = $row[$default_user_info];
     256  foreach ( $default_user_infos as $info ) {
     257    if ( isset( $row[$info] ) ) $$info = $row[$info];
     258    else                        $$info = '';
    261259  }
    262260}
     
    654652$vtp->setVar( $sub, 'select.name', 'template' );
    655653$option = get_dirs( './template/' );
     654
    656655for ( $i = 0; $i < sizeof( $option ); $i++ )
    657656{
  • trunk/admin/create_listing_file.php

    r161 r345  
    1010 ***************************************************************************/
    1111
    12 $prefix_thumbnail = 'TN-';
    13        
     12$conf['prefix_thumbnail'] = 'TN-';
    1413$conf['picture_ext'] = array ( 'jpg', 'gif', 'png', 'JPG', 'GIF', 'PNG' );
    1514
     
    2120
    2221$listing.= '<url>'.$url.'</url>';
    23        
     22
     23/**
     24 * returns an array with all picture files according to $conf['picture_ext']
     25 *
     26 * @param string $dir
     27 * @return array
     28 */
     29function get_picture_files( $dir )
     30{
     31  global $conf;
     32
     33  $pictures = array();
     34  if ( $opendir = opendir( $dir ) )
     35  {
     36    while ( $file = readdir( $opendir ) )
     37    {
     38      if ( in_array( get_extension( $file ), $conf['picture_ext'] ) )
     39      {
     40        array_push( $pictures, $file );
     41      }
     42    }
     43  }
     44  return $pictures;
     45}
     46
     47/**
     48 * returns an array with all thumbnails according to $conf['picture_ext']
     49 * and $conf['prefix_thumbnail']
     50 *
     51 * @param string $dir
     52 * @return array
     53 */
     54function get_thumb_files( $dir )
     55{
     56  global $conf;
     57
     58  $prefix_length = strlen( $conf['prefix_thumbnail'] );
     59 
     60  $thumbnails = array();
     61  if ( $opendir = @opendir( $dir ) )
     62  {
     63    while ( $file = readdir( $opendir ) )
     64    {
     65      if ( in_array( get_extension( $file ), $conf['picture_ext'] )
     66           and substr($file,0,$prefix_length) == $conf['prefix_thumbnail'] )
     67      {
     68        array_push( $thumbnails, $file );
     69      }
     70    }
     71  }
     72  return $thumbnails;
     73}
     74
    2475// get_dirs retourne un tableau contenant tous les sous-répertoires d'un
    2576// répertoire
    26 function get_dirs( $rep, $indent, $level )
     77function get_dirs( $basedir, $indent, $level )
    2778{
    28   $sub_rep = array();
    29   $i = 0;
     79  $fs_dirs = array();
    3080  $dirs = "";
    31   if ( $opendir = opendir ( $rep ) )
     81
     82  if ( $opendir = opendir( $basedir ) )
    3283  {
    33     while ( $file = readdir ( $opendir ) )
     84    while ( $file = readdir( $opendir ) )
    3485    {
    35       if ( $file != "."
    36            and $file != ".."
    37            and is_dir ( $rep."/".$file )
    38            and $file != "thumbnail" )
     86      if ( $file != '.'
     87           and $file != '..'
     88           and is_dir ( $basedir.'/'.$file )
     89           and $file != 'thumbnail' )
    3990      {
    40         $sub_rep[$i++] = $file;
     91        array_push( $fs_dirs, $file );
    4192        if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
    4293        {
     
    50101  }
    51102  // write of the dirs
    52   for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
    53   {
    54     $dirs.= "\n".$indent.'<dir'.$level.' name="'.$sub_rep[$i].'">';
    55     $dirs.= get_pictures( $rep.'/'.$sub_rep[$i], $indent.'  ' );
    56     $dirs.= get_dirs( $rep.'/'.$sub_rep[$i], $indent.'  ', $level + 1 );
     103  foreach ( $fs_dirs as $fs_dir ) {
     104    $dirs.= "\n".$indent.'<dir'.$level.' name="'.$fs_dir.'">';
     105    $dirs.= get_pictures( $basedir.'/'.$fs_dir, $indent.'  ' );
     106    $dirs.= get_dirs( $basedir.'/'.$fs_dir, $indent.'  ', $level + 1 );
    57107    $dirs.= "\n".$indent.'</dir'.$level.'>';
    58108  }
     
    74124}
    75125
    76 function is_image( $filename )
     126function get_pictures( $dir, $indent )
    77127{
    78128  global $conf;
     129 
     130  // fs means filesystem : $fs_pictures contains pictures in the filesystem
     131  // found in $dir, $fs_thumbnails contains thumbnails...
     132  $fs_pictures   = get_picture_files( $dir );
     133  $fs_thumbnails = get_thumb_files( $dir.'/thumbnail' );
    79134
    80   if ( !is_dir( $filename )
    81        and in_array( get_extension( $filename ), $conf['picture_ext'] ) )
    82   {
    83     return true;
    84   }
    85   return false;
    86 }
     135  $root = "\n".$indent.'<root>';
    87136
    88 function TN_exists( $dir, $file )
    89 {
    90   global $conf, $prefix_thumbnail;
     137  foreach ( $fs_pictures as $fs_picture ) {
     138    $file_wo_ext = get_filename_wo_extension( $fs_picture );
     139    $tn_ext = '';
     140    foreach ( $conf['picture_ext'] as $ext ) {
     141      $test = $conf['prefix_thumbnail'].$file_wo_ext.'.'.$ext;
     142      if ( !in_array( $test, $fs_thumbnails ) ) continue;
     143      else { $tn_ext = $ext; break; }
     144    }
     145    // if we found a thumnbnail corresponding to our picture...
     146    if ( $tn_ext != '' )
     147    {
     148      list( $width,$height ) = @getimagesize( $dir.'/'.$fs_picture );
    91149
    92   $titre = get_filename_wo_extension( $file );
    93 
    94   for ( $i = 0; $i < sizeof ( $conf['picture_ext'] ); $i++ )
    95   {
    96     $base_tn_name = $dir.'/thumbnail/'.$prefix_thumbnail.$titre.'.';
    97     $ext = $conf['picture_ext'][$i];
    98     if ( is_file( $base_tn_name.$ext ) )
     150      $root.= "\n".$indent.'  ';
     151      $root.= '<picture';
     152      $root.= ' file="'.    $fs_picture.'"';
     153      $root.= ' tn_ext="'.  $tn_ext.'"';
     154      $root.= ' filesize="'.floor(filesize($dir.'/'.$fs_picture)/1024).'"';
     155      $root.= ' width="'.   $width.'"';
     156      $root.= ' height="'.  $height.'"';
     157      $root.= ' />';
     158     
     159      if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $fs_picture ) )
     160      {
     161        echo '<span style="color:red;">"'.$fs_picture.'" : ';
     162        echo 'The name of the picture should be composed of ';
     163        echo 'letters, figures, "-", "_" or "." ONLY';
     164        echo '</span><br />';
     165      }
     166    }
     167    else
    99168    {
    100       return $ext;
     169      echo 'The thumbnail is missing for '.$dir.'/'.$fs_picture;
     170      echo '-> '.$dir.'/thumbnail/';
     171      echo $conf['prefix_thumbnail'].$file_wo_ext.'.xxx';
     172      echo ' ("xxx" can be : ';
     173      echo implode( ', ', $conf['picture_ext'] );
     174      echo ')<br />';
    101175    }
    102176  }
    103   echo 'The thumbnail is missing for '.$dir.'/'.$file;
    104   echo '-> '.$dir.'/thumbnail/'.$prefix_thumbnail.$titre.'.xxx';
    105   echo ' ("xxx" can be : ';
    106   for ( $i = 0; $i < sizeof ( $conf['picture_ext'] ); $i++ )
    107   {
    108     if ( $i > 0 )
    109     {
    110       echo ', ';
    111     }
    112     echo '"'.$conf['picture_ext'][$i].'"';
    113   }
    114   echo ')<br />';
    115   return false;
    116 }
    117177
    118 function get_pictures( $rep, $indent )
    119 {
    120   $pictures = array();         
     178  $root.= "\n".$indent.'</root>';
    121179
    122   $tn_ext = '';
    123   $root = '';
    124   if ( $opendir = opendir ( $rep ) )
    125   {
    126     while ( $file = readdir ( $opendir ) )
    127     {
    128       if ( is_image( $file ) and $tn_ext = TN_exists( $rep, $file ) )
    129       {
    130         $picture = array();
    131 
    132         $picture['file']     = $file;
    133         $picture['tn_ext']   = $tn_ext;
    134         $picture['date']     = date('Y-m-d',filemtime( $rep.'/'.$file ) );
    135         $picture['filesize'] = floor( filesize( $rep."/".$file ) / 1024 );
    136         $image_size = @getimagesize( $rep."/".$file );
    137         $picture['width']    = $image_size[0];
    138         $picture['height']   = $image_size[1];
    139 
    140         array_push( $pictures, $picture );
    141 
    142         if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
    143         {
    144           echo '<span style="color:red;">"'.$file.'" : ';
    145           echo 'The name of the picture should be composed of ';
    146           echo 'letters, figures, "-", "_" or "." ONLY';
    147           echo '</span><br />';
    148         }
    149       }
    150     }
    151   }
    152   // write of the node <root> with all the pictures at the root of the
    153   // directory
    154   $root.= "\n".$indent."<root>";
    155   if ( sizeof( $pictures ) > 0 )
    156   {
    157     for( $i = 0; $i < sizeof( $pictures ); $i++ )
    158     {
    159       $root.= "\n".$indent.'  ';
    160       $root.= '<picture';
    161       $root.= ' file="'.     $pictures[$i]['file'].     '"';
    162       $root.= ' tn_ext="'.   $pictures[$i]['tn_ext'].   '"';
    163       $root.= ' date="'.     $pictures[$i]['date'].     '"';
    164       $root.= ' filesize="'. $pictures[$i]['filesize']. '"';
    165       $root.= ' width="'.    $pictures[$i]['width'].    '"';
    166       $root.= ' height="'.   $pictures[$i]['height'].   '"';
    167       $root.= ' />';
    168     }
    169   }
    170   $root.= "\n".$indent.'</root>';
    171180  return $root;
    172181}
     
    178187  fwrite( $fp, $listing );
    179188  fclose( $fp );
     189  echo "listing.xml created";
    180190}
    181191else
     
    183193  echo "I can't write the file listing.xml";
    184194}
    185 
    186 echo "listing.xml created";
    187195?>
  • trunk/admin/group_list.php

    r226 r345  
    3434  $row = mysql_fetch_array( mysql_query( $query ) );
    3535  // confirm group deletion ?
    36   if ( $_GET['confirm'] != 1 )
     36  if ( !isset( $_GET['confirm'] ) or $_GET['confirm'] != 1 )
    3737  {
    3838    $vtp->addSession( $sub, 'deletion' );
  • trunk/admin/group_perm.php

    r226 r345  
    6161    check_favorites( $row['id'] );
    6262  }
     63  // synchronization of calculated data
     64  synchronize_group( $_GET['group_id'] );
    6365  // confirmation display
    6466  $vtp->addSession( $sub, 'confirmation' );
  • trunk/admin/include/functions.php

    r196 r345  
    5454  return false;
    5555}
    56        
     56
     57/**
     58 * returns an array with all picture files according to $conf['picture_ext']
     59 *
     60 * @param string $dir
     61 * @return array
     62 */
     63function get_picture_files( $dir )
     64{
     65  global $conf;
     66
     67  $pictures = array();
     68  if ( $opendir = opendir( $dir ) )
     69  {
     70    while ( $file = readdir( $opendir ) )
     71    {
     72      if ( in_array( get_extension( $file ), $conf['picture_ext'] ) )
     73      {
     74        array_push( $pictures, $file );
     75      }
     76    }
     77  }
     78  return $pictures;
     79}
     80
     81/**
     82 * returns an array with all thumbnails according to $conf['picture_ext']
     83 * and $conf['prefix_thumbnail']
     84 *
     85 * @param string $dir
     86 * @return array
     87 */
     88function get_thumb_files( $dir )
     89{
     90  global $conf;
     91
     92  $prefix_length = strlen( $conf['prefix_thumbnail'] );
     93 
     94  $thumbnails = array();
     95  if ( $opendir = @opendir( $dir ) )
     96  {
     97    while ( $file = readdir( $opendir ) )
     98    {
     99      if ( in_array( get_extension( $file ), $conf['picture_ext'] )
     100           and substr($file,0,$prefix_length) == $conf['prefix_thumbnail'] )
     101      {
     102        array_push( $thumbnails, $file );
     103      }
     104    }
     105  }
     106  return $thumbnails;
     107}
     108
    57109function TN_exists( $dir, $file )
    58110{
     
    68120  }
    69121  return false;
    70 }       
     122}
    71123       
     124
    72125// The function delete_site deletes a site
    73126// and call the function delete_category for each primary category of the site
     
    92145}
    93146       
     147
    94148// The function delete_category deletes the category identified by the $id
    95149// It also deletes (in the database) :
     
    145199}
    146200       
     201
    147202// The function delete_image deletes the image identified by the $id
    148203// It also deletes (in the database) :
     
    179234  $count_deleted++;
    180235}
    181        
     236
    182237// The delete_user function delete a user identified by the $user_id
    183238// It also deletes :
     
    186241//     - all the favorites linked to this user
    187242//     - all sessions linked to this user
     243//     - all categories informations linked to this user
    188244function delete_user( $user_id )
    189245{
     
    211267  $query.= ';';
    212268  mysql_query( $query );
    213                
     269
     270  // destruction of the categories informations linked with the user
     271  $query = 'DELETE FROM '.PREFIX_TABLE.'user_category';
     272  $query.= ' WHERE user_id = '.$user_id;
     273  $query.= ';';
     274  mysql_query( $query );
     275
    214276  // destruction of the user
    215277  $query = 'DELETE FROM '.PREFIX_TABLE.'users';
     
    231293  mysql_query( $query );
    232294
    233   // destruction of the group links for this group
     295  // synchronize all users linked to the group
     296  synchronize_group( $group_id );
     297
     298  // destruction of the users links for this group
    234299  $query = 'DELETE FROM '.PREFIX_TABLE.'user_group';
    235300  $query.= ' WHERE group_id = '.$group_id;
     
    249314function check_favorites( $user_id )
    250315{
    251   $query = 'SELECT status';
     316  $query = 'SELECT status,forbidden_categories';
    252317  $query.= ' FROM '.PREFIX_TABLE.'users';
    253318  $query.= ' WHERE id = '.$user_id;
     
    256321  $status = $row['status'];
    257322  // retrieving all the restricted categories for this user
    258   $restricted_cat = get_all_restrictions( $user_id, $status );
     323  if ( isset( $row['forbidden_categories'] ) )
     324    $restricted_cat = explode( ',', $row['forbidden_categories'] );
     325  else
     326    $restricted_cat = array();
    259327  // retrieving all the favorites for this user and comparing their
    260328  // categories to the restricted categories
     
    315383    $query.= ' WHERE category_id = '.$id;
    316384    $query.= ';';
    317     $row = mysql_fetch_array( mysql_query( $query ) );
     385    list( $nb_images ) = mysql_fetch_array( mysql_query( $query ) );
     386    // updating the date_last
     387    $query = 'SELECT MAX(date_available) AS date_available';
     388    $query.= ' FROM '.PREFIX_TABLE.'images';
     389    $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     390    $query.= ' WHERE category_id = '.$id;
     391    $query.= ';';
     392    list( $date_available ) = mysql_fetch_array( mysql_query( $query ) );
     393   
    318394    $query = 'UPDATE '.PREFIX_TABLE.'categories';
    319     $query.= ' SET nb_images = '.$row['nb_images'];
     395    $query.= " SET date_last = '".$date_available."'";
     396    $query.= ', nb_images = '.$nb_images;
    320397    $query.= ' WHERE id = '.$id;
    321398    $query.= ';';
    322399    mysql_query( $query );
    323     // updating the date_last
    324     $query = 'SELECT date_available';
    325     $query.= ' FROM '.PREFIX_TABLE.'images';
    326     $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    327     $query.= ' WHERE category_id = '.$id;
    328     $query.= ' ORDER BY date_available DESC';
    329     $query.= ' LIMIT 0,1';
    330     $query.= ';';
    331     $row = mysql_fetch_array( mysql_query( $query ) );
    332     $query = 'UPDATE '.PREFIX_TABLE.'categories';
    333     $query.= " SET date_last = '".$row['date_available']."'";
    334     $query.= ' WHERE id = '.$id;
    335     $query.= ';';
    336     mysql_query( $query );
     400
    337401    // updating the representative_picture_id : if the representative
    338402    // picture of the category is not any more linked to the category, we
     
    344408    // if the category has no representative picture (ie
    345409    // representative_picture_id == NULL) we don't update anything
    346     if ( $row['representative_picture_id'] != '' )
     410    if ( isset( $row['representative_picture_id'] ) )
    347411    {
    348412      $query = 'SELECT image_id';
     
    367431{
    368432  // date arrives at this format : DD/MM/YYYY
    369   list($day,$month,$year) = explode( '/', $date );
     433  @list($day,$month,$year) = explode( '/', $date );
    370434  return @checkdate( $month, $day, $year );
    371435}
     
    433497  }
    434498}
     499
     500/**
     501 * Complete plain structure of the gallery
     502 *
     503 * Returns the plain structure (one level array) of the gallery. In the
     504 * returned array, each element is an array with jeys 'id' and
     505 * 'id_uppercat'. The function also fills the array $page['subcats'] which
     506 * associate (category_id => array of sub-categories id).
     507 *
     508 * @param bool $use_name
     509 * @return array
     510 */
     511function get_plain_structure( $use_name = false )
     512{
     513  global $page;
     514
     515  $plain_structure = array();
     516
     517  $query = 'SELECT id,id_uppercat';
     518  if ( $use_name ) $query.= ',name';
     519  $query.= ' FROM '.PREFIX_TABLE.'categories';
     520  $query.= ' ORDER BY id_uppercat ASC, rank ASC';
     521  $query.= ';';
     522
     523  $subcats = array();
     524  $id_uppercat = 'NULL';
     525
     526  $result = mysql_query( $query );
     527  while ( $row = mysql_fetch_array( $result ) )
     528  {
     529    $plain_structure[$row['id']]['id'] = $row['id'];
     530    if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = 'NULL';
     531    $plain_structure[$row['id']]['id_uppercat'] = $row['id_uppercat'];
     532    if ( $use_name ) $plain_structure[$row['id']]['name'] = $row['name'];
     533    // subcats list
     534    if ( $row['id_uppercat'] != $id_uppercat )
     535    {
     536      $page['subcats'][$id_uppercat] = $subcats;
     537
     538      $subcats = array();
     539      $id_uppercat = $row['id_uppercat'];
     540    }
     541    array_push( $subcats, $row['id'] );
     542  }
     543  mysql_free_result( $result );
     544 
     545  $page['subcats'][$id_uppercat] = $subcats;
     546
     547  return $plain_structure;
     548}
     549
     550/**
     551 * get N levels array representing structure under the given category
     552 *
     553 * create_structure returns the N levels array representing structure under
     554 * the given gategory id. It also updates the
     555 * $page['plain_structure'][id]['all_subcats_id'] and
     556 * $page['plain_structure'][id]['direct_subcats_ids'] for each sub category.
     557 *
     558 * @param int $id_uppercat
     559 * @return array
     560 */
     561function create_structure( $id_uppercat )
     562{
     563  global $page;
     564
     565  $structure = array();
     566  $ids = get_subcats_ids( $id_uppercat );
     567  foreach ( $ids as $id ) {
     568    $category = $page['plain_structure'][$id];
     569
     570    $category['subcats'] = create_structure( $id );
     571
     572    $page['plain_structure'][$id]['all_subcats_ids'] =
     573      get_all_subcats_ids( $id );
     574
     575    $page['plain_structure'][$id]['direct_subcats_ids'] =
     576      get_subcats_ids( $id );
     577
     578    array_push( $structure, $category );
     579  }
     580  return $structure;
     581}
     582
     583/**
     584 * returns direct sub-categories ids
     585 *
     586 * Returns an array containing all the direct sub-categories ids of the
     587 * given category. It uses the $page['subcats'] global array.
     588 *
     589 * @param int $id_uppercat
     590 * @return array
     591 */
     592function get_subcats_ids( $id_uppercat )
     593{
     594  global $page;
     595
     596  if ( $id_uppercat == '' ) $id_uppercat = 'NULL';
     597
     598  if ( isset( $page['subcats'][$id_uppercat] ) )
     599    return $page['subcats'][$id_uppercat];
     600  else
     601    return array();
     602}
     603
     604/**
     605 * returns all sub-categories ids, not only direct ones
     606 *
     607 * Returns an array containing all the sub-categories ids of the given
     608 * category, not only direct ones. This function is recursive.
     609 *
     610 * @param int $category_id
     611 * @return array
     612 */
     613function get_all_subcats_ids( $category_id )
     614{
     615  $ids = array();
     616 
     617  $subcats = get_subcats_ids( $category_id );
     618  $ids = array_merge( $ids, $subcats );
     619  foreach ( $subcats as $subcat ) {
     620    // recursive call
     621    $sub_subcats = get_all_subcats_ids( $subcat );
     622    $ids = array_merge( $ids, $sub_subcats );
     623  }
     624  return array_unique( $ids );
     625}
     626
     627/**
     628 * prepares the query to update the table user_category
     629 *
     630 * Prepares the query (global variable $values) to update table
     631 * user_category : for a couple (user,category) the number of sub-categories
     632 * and the last date of the category (all sub-categories taken into
     633 * account). It also calls function update_uppercats for each category. The
     634 * function is recursive.
     635 *
     636 * @param array $categories
     637 * @return void
     638 */
     639function update_user_category( $categories )
     640{
     641  global $page,$user_restrictions,$value_num,$values;
     642
     643  foreach ( $categories as $category ) {
     644    // recursive call
     645    update_user_category( $category['subcats'] );
     646    // 1. update the table user_category
     647    foreach ( $user_restrictions as $user_id => $restrictions ) {
     648      // if the category is forbidden to this user, go to next user
     649      if ( in_array( $category['id'], $restrictions ) ) continue;
     650
     651      // how many sub_categories for this user ?
     652      $user_subcats = array_diff(
     653        $page['plain_structure'][$category['id']]['direct_subcats_ids'],
     654        $restrictions );
     655      $user_nb_subcats = count( array_unique( $user_subcats ) );
     656      // last date of the category
     657      $user_all_subcats = array_unique( array_diff(
     658        $page['plain_structure'][$category['id']]['all_subcats_ids'],
     659        $restrictions ) );
     660           
     661      $query = 'SELECT MAX(date_last) AS last_date';
     662      $query.= ' FROM '.PREFIX_TABLE.'categories';
     663      $query.= ' WHERE id IN ('.$category['id'];
     664      if ( count( $user_all_subcats ) > 0 )
     665        $query.= ','.implode( ',', $user_all_subcats );
     666      $query.= ')';
     667      $query.= ';';
     668      $row = mysql_fetch_array( mysql_query( $query ) );
     669
     670      // insert a new line in database
     671      if ( $value_num++ > 0 ) $values.= ', ';
     672      else                    $values.= ' ';
     673      $values.= '('.$user_id.",".$category['id'];
     674      if ( isset( $row['last_date'] ) ) $values.= ",'".$row['last_date']."'";
     675      else                              $values.= ',NULL';
     676      $values.= ','.$user_nb_subcats.')';
     677    }
     678    update_uppercats( $category['id'] );
     679  }
     680}
     681
     682/**
     683 * updates the column categories.uppercats
     684 *
     685 * @param int $category_id
     686 * @return void
     687 */
     688function update_uppercats( $category_id )
     689{
     690  global $page;
     691
     692  $final_id = $category_id;
     693  $uppercats = array();
     694
     695  array_push( $uppercats, $category_id );
     696  $uppercat = $page['plain_structure'][$category_id]['id_uppercat'];
     697
     698  while ( $uppercat != 'NULL' )
     699  {
     700    array_push( $uppercats, $uppercat );
     701    $category_id = $page['plain_structure'][$category_id]['id_uppercat'];
     702    $uppercat = $page['plain_structure'][$category_id]['id_uppercat'];
     703  }
     704
     705  $string_uppercats = implode( ',', array_reverse( $uppercats ) );
     706  $query = 'UPDATE '.PREFIX_TABLE.'categories';
     707  $query.= ' SET uppercats = '."'".$string_uppercats."'";
     708  $query.= ' WHERE id = '.$final_id;
     709  $query.= ';';
     710  mysql_query( $query );
     711}
     712
     713/**
     714 * returns an array with the ids of the restricted categories for the user
     715 *
     716 * Returns an array with the ids of the restricted categories for the
     717 * user. If the $check_invisible parameter is set to true, invisible
     718 * categorie are added to the restricted one in the array.
     719 *
     720 * @param int $user_id
     721 * @param string $user_status
     722 * @param bool $check_invisible
     723 * @param bool $use_groups
     724 * @return array
     725 */
     726function get_user_restrictions( $user_id, $user_status,
     727                                $check_invisible, $use_groups = true )
     728{
     729  // 1. retrieving ids of private categories
     730  $query = 'SELECT id';
     731  $query.= ' FROM '.PREFIX_TABLE.'categories';
     732  $query.= " WHERE status = 'private'";
     733  $query.= ';';
     734  $result = mysql_query( $query );
     735  $privates = array();
     736  while ( $row = mysql_fetch_array( $result ) )
     737  {
     738    array_push( $privates, $row['id'] );
     739  }
     740  // 2. retrieving all authorized categories for the user
     741  $authorized = array();
     742  // 2.1. retrieving authorized categories thanks to personnal user
     743  //      authorization
     744  $query = 'SELECT cat_id';
     745  $query.= ' FROM '.PREFIX_TABLE.'user_access';
     746  $query.= ' WHERE user_id = '.$user_id;
     747  $query.= ';';
     748  $result = mysql_query( $query );
     749  while ( $row = mysql_fetch_array( $result ) )
     750  {
     751    array_push( $authorized, $row['cat_id'] );
     752  }
     753  // 2.2. retrieving authorized categories thanks to group authorization to
     754  //      which the user is a member
     755  if ( $use_groups )
     756  {
     757    $query = 'SELECT ga.cat_id';
     758    $query.= ' FROM '.PREFIX_TABLE.'user_group as ug';
     759    $query.= ', '.PREFIX_TABLE.'group_access as ga';
     760    $query.= ' WHERE ug.group_id = ga.group_id';
     761    $query.= ' AND ug.user_id = '.$user_id;
     762    $query.= ';';
     763    $result = mysql_query( $query );
     764    while ( $row = mysql_fetch_array( $result ) )
     765    {
     766      array_push( $authorized, $row['cat_id'] );
     767    }
     768    $authorized = array_unique( $authorized );
     769  }
     770
     771  $forbidden = array();
     772  foreach ( $privates as $private ) {
     773    if ( !in_array( $private, $authorized ) )
     774    {
     775      array_push( $forbidden, $private );
     776    }
     777  }
     778
     779  if ( $check_invisible )
     780  {
     781    // 3. adding to the restricted categories, the invisible ones
     782    if ( $user_status != 'admin' )
     783    {
     784      $query = 'SELECT id';
     785      $query.= ' FROM '.PREFIX_TABLE.'categories';
     786      $query.= " WHERE visible = 'false';";
     787      $result = mysql_query( $query );
     788      while ( $row = mysql_fetch_array( $result ) )
     789      {
     790        array_push( $forbidden, $row['id'] );
     791      }
     792    }
     793  }
     794  return array_unique( $forbidden );
     795}
     796
     797/**
     798 * finalizes operation for user_category table update
     799 *
     800 * This function is called by synchronization_*. It creates the
     801 * $page['plain_structure'] and $page['structure'], get the SQL query to
     802 * update user_category, clean user_category, and finally update the
     803 * table. The users updates depends on the global array $user_restrictions.
     804 *
     805 * @return void
     806 */
     807function synchronize()
     808{
     809  global $user_restrictions,$page,$values;
     810
     811  update_user_category( $page['structure'] );
     812
     813  // cleaning user_category table for users to update
     814  foreach( $user_restrictions as $user_id => $restrictions ) {
     815    $query = 'DELETE';
     816    $query.= ' FROM '.PREFIX_TABLE.'user_category';
     817    $query.= ' WHERE user_id = '.$user_id;
     818    $query.= ';';
     819    mysql_query( $query );
     820  }
     821
     822  $query = 'INSERT INTO '.PREFIX_TABLE.'user_category';
     823  $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES ';
     824  $query.= $values;
     825  $query.= ';';
     826  mysql_query( $query );
     827}
     828
     829/**
     830 * synchronizes all users calculated informations
     831 *
     832 * fills global array $user_restrictions with all users and related
     833 * restrictions before calling synchronize.
     834 *
     835 * @return void
     836 */
     837function synchronize_all_users()
     838{
     839  global $user_restrictions,$page;
     840
     841  $page['plain_structure'] = get_plain_structure();
     842  $page['structure']       = create_structure( '' );
     843 
     844  $user_restrictions = array();
     845 
     846  $query = 'SELECT id';
     847  $query.= ' FROM '.PREFIX_TABLE.'users';
     848  $query.= ';';
     849  $result = mysql_query( $query );
     850  while ( $row = mysql_fetch_array( $result ) )
     851  {
     852    $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
     853  }
     854  synchronize();
     855}
     856
     857/**
     858 * synchronizes 1 user calculated informations
     859 *
     860 * fills global array $user_restrictions with the user id and its related
     861 * restrictions before calling synchronize.
     862 *
     863 * @param int $user_id
     864 * @return void
     865 */
     866function synchronize_user( $user_id )
     867{
     868  global $user_restrictions,$page;
     869
     870  $page['plain_structure'] = get_plain_structure();
     871  $page['structure']       = create_structure( '' );
     872 
     873  $user_restrictions = array();
     874  $user_restrictions[$user_id] = update_user_restrictions( $user_id );
     875  synchronize();
     876}
     877
     878/**
     879 * synchronizes all users (belonging to the group) calculated informations
     880 *
     881 * fills global array $user_restrictions with all users and related
     882 * restrictions before calling synchronize.
     883 *
     884 * @return void
     885 */
     886function synchronize_group( $group_id )
     887{
     888  global $user_restrictions,$page;
     889
     890  $page['plain_structure'] = get_plain_structure();
     891  $page['structure']       = create_structure( '' );
     892 
     893  $user_restrictions = array();
     894 
     895  $query = 'SELECT id';
     896  $query.= ' FROM '.PREFIX_TABLE.'users';
     897  $query.= ', '.PREFIX_TABLE.'user_group';
     898  $query.= ' WHERE group_id = '.$group_id;
     899  $query.= ' AND id = user_id';
     900  $query.= ';';
     901  $result = mysql_query( $query );
     902  while ( $row = mysql_fetch_array( $result ) )
     903  {
     904    $user_restrictions[$row['id']] = update_user_restrictions( $row['id'] );
     905  }
     906  synchronize();
     907}
     908
     909/**
     910 * updates the calculated data users.forbidden_categories, it includes
     911 * sub-categories of the direct forbidden categories
     912 *
     913 * @param nt $user_id
     914 * @return array
     915 */
     916function update_user_restrictions( $user_id )
     917{
     918  $restrictions = get_user_all_restrictions( $user_id );
     919
     920  // update the users.forbidden_categories in database
     921  $query = 'UPDATE '.PREFIX_TABLE.'users';
     922  $query.= ' SET forbidden_categories = ';
     923  if ( count( $restrictions ) > 0 )
     924    $query.= "'".implode( ',', $restrictions )."'";
     925  else
     926    $query.= 'NULL';
     927  $query .= ' WHERE id = '.$user_id;
     928  $query.= ';';
     929  mysql_query( $query );
     930
     931  return $restrictions;
     932}
     933
     934/**
     935 * returns all the restricted categories ids including sub-categories
     936 *
     937 * @param int $user_id
     938 * @return array
     939 */
     940function get_user_all_restrictions( $user_id )
     941{
     942  global $page;
     943 
     944  $query = 'SELECT status';
     945  $query.= ' FROM '.PREFIX_TABLE.'users';
     946  $query.= ' WHERE id = '.$user_id;
     947  $query.= ';';
     948  $row = mysql_fetch_array( mysql_query( $query ) );
     949 
     950  $base_restrictions=get_user_restrictions($user_id,$row['status'],true,true);
     951
     952  $restrictions = $base_restrictions;
     953  foreach ( $base_restrictions as $category_id ) {
     954    echo $category_id.' is forbidden to user '.$user_id.'<br />';
     955    $restrictions =
     956      array_merge( $restrictions,
     957                   $page['plain_structure'][$category_id]['all_subcats_ids'] );
     958  }
     959
     960  return array_unique( $restrictions );
     961}
     962
     963// The function is_user_allowed returns :
     964//      - 0 : if the category is allowed with this $restrictions array
     965//      - 1 : if this category is not allowed
     966//      - 2 : if an uppercat category is not allowed
     967// Note : the restrictions array must represent ONLY direct forbidden
     968// categories, not all forbidden categories
     969function is_user_allowed( $category_id, $restrictions )
     970{
     971  if ( in_array( $category_id, $restrictions ) ) return 1;
     972
     973  $query = 'SELECT uppercats';
     974  $query.= ' FROM '.PREFIX_TABLE.'categories';
     975  $query.= ' WHERE id = '.$category_id;
     976  $query.= ';';
     977  $row = mysql_fetch_array( mysql_query( $query ) );
     978  $uppercats = explode( ',', $row['uppercats'] );
     979  foreach ( $uppercats as $category_id ) {
     980    if ( in_array( $category_id, $restrictions ) ) return 2;
     981  }
     982
     983  // no restriction found : the user is allowed to access this category
     984  return 0;
     985}
     986
     987/**
     988 * returns an array containing sub-directories which can be a category
     989 *
     990 * directories nammed "thumbnail" are omitted
     991 *
     992 * @param string $basedir
     993 * @return array
     994 */
     995function get_category_directories( $basedir )
     996{
     997  $sub_dirs = array();
     998
     999  if ( $opendir = opendir( $basedir ) )
     1000  {
     1001    while ( $file = readdir( $opendir ) )
     1002    {
     1003      if ( $file != '.' and $file != '..'
     1004           and is_dir( $basedir.'/'.$file )
     1005           and $file != 'thumbnail' )
     1006      {
     1007        array_push( $sub_dirs, $file );
     1008      }
     1009    }
     1010  }
     1011  return $sub_dirs;
     1012}
    4351013?>
  • trunk/admin/include/isadmin.inc.php

    r231 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
    19 define( "PREFIX_INCLUDE", '' );
    2019
    21 include_once( './include/config.inc.php' );
    22 include_once( './include/user.inc.php' );
    2320include( './admin/include/functions.php' );
    2421
  • trunk/admin/infos_images.php

    r228 r345  
    2121include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' );
    2222//-------------------------------------------------------------- initialization
     23$page['nb_image_page'] = 5;
     24
    2325check_cat_id( $_GET['cat_id'] );
     26
     27$errors = array();
     28
    2429if ( isset( $page['cat'] ) )
    2530{
    2631//--------------------------------------------------- update individual options
    27   $query = 'SELECT id,file';
    28   $query.= ' FROM '.PREFIX_TABLE.'images';
    29   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    30   $query.= ' WHERE category_id = '.$page['cat'];
    31   $query.= ';';
    32   $result = mysql_query( $query );
    33   $i = 1;
    34   while ( $row = mysql_fetch_array( $result ) )
    35   {
    36     $name          = 'name-'.$row['id'];
    37     $author        = 'author-'.$row['id'];
    38     $comment       = 'comment-'.$row['id'];
    39     $date_creation = 'date_creation-'.$row['id'];
    40     $keywords      = 'keywords-'.$row['id'];
    41     if ( isset( $_POST[$name] ) )
    42     {
    43       $query = 'UPDATE '.PREFIX_TABLE.'images';
    44 
    45       $query.= ' SET name = ';
    46       if ( $_POST[$name] == '' )
    47         $query.= 'NULL';
     32  if ( isset( $_POST['submit'] ) )
     33  {
     34    if ( isset( $_POST['associate'] ) and $_POST['associate'] != '' )
     35    {
     36      // does the uppercat id exists in the database ?
     37      if ( !is_numeric( $_POST['associate'] ) )
     38      {
     39        array_push( $errors, $lang['cat_unknown_id'] );
     40      }
    4841      else
    49         $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
    50 
    51       $query.= ', author = ';
    52       if ( $_POST[$author] == '' )
    53         $query.= 'NULL';
    54       else
    55         $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
    56 
    57       $query.= ', comment = ';
    58       if ( $_POST[$comment] == '' )
    59         $query.= 'NULL';
    60       else
    61         $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
    62 
    63       $query.= ', date_creation = ';
    64       if ( check_date_format( $_POST[$date_creation] ) )
    65         $query.= "'".date_convert( $_POST[$date_creation] )."'";
    66       else if ( $_POST[$date_creation] == '' )
    67         $query.= 'NULL';
    68 
    69       $query.= ', keywords = ';
    70       $keywords_array = get_keywords( $_POST[$keywords] );
    71       if ( count( $keywords_array ) == 0 )
    72         $query.= 'NULL';
    73       else
    74       {
    75         $query.= "'";
    76         foreach ( $keywords_array as $i => $keyword ) {
    77           if ( $i > 0 ) $query.= ',';
    78           $query.= $keyword;
    79         }
    80         $query.= "'";
    81       }
    82 
    83       $query.= ' WHERE id = '.$row['id'];
    84       $query.= ';';
    85       mysql_query( $query );
    86     }
    87     // add link to another category
    88     if ( $_POST['check-'.$row['id']] == 1 )
    89     {
    90       $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
    91       $query.= ' (image_id,category_id) VALUES';
    92       $query.= ' ('.$row['id'].','.$_POST['associate'].')';
    93       $query.= ';';
    94       mysql_query( $query );
    95     }
    96   }
    97   update_category( $_POST['associate'] );
    98 //------------------------------------------------------ update general options
    99   if ( $_POST['use_common_author'] == 1 )
    100   {
    101     $query = 'SELECT image_id';
    102     $query.= ' FROM '.PREFIX_TABLE.'image_category';
     42      {
     43        $query = 'SELECT id';
     44        $query.= ' FROM '.PREFIX_TABLE.'categories';
     45        $query.= ' WHERE id = '.$_POST['associate'];
     46        $query.= ';';
     47        if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
     48          array_push( $errors, $lang['cat_unknown_id'] );
     49      }
     50    }
     51
     52    $associate = false;
     53   
     54    $query = 'SELECT id,file';
     55    $query.= ' FROM '.PREFIX_TABLE.'images';
     56    $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    10357    $query.= ' WHERE category_id = '.$page['cat'];
     58    $query.= ';';
    10459    $result = mysql_query( $query );
    10560    while ( $row = mysql_fetch_array( $result ) )
    10661    {
    107       $query = 'UPDATE '.PREFIX_TABLE.'images';
    108       if ( $_POST['author_cat'] == '' )
    109       {
    110         $query.= ' SET author = NULL';
    111       }
    112       else
    113       {
    114         $query.= ' SET author = ';
    115         $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
    116       }
    117       $query.= ' WHERE id = '.$row['image_id'];
    118       $query.= ';';
    119       mysql_query( $query );
    120     }
    121   }
    122   if ( $_POST['use_common_date_creation'] == 1 )
    123   {
    124     if ( check_date_format( $_POST['date_creation_cat'] ) )
    125     {
    126       $date = date_convert( $_POST['date_creation_cat'] );
     62      $name          = 'name-'.$row['id'];
     63      $author        = 'author-'.$row['id'];
     64      $comment       = 'comment-'.$row['id'];
     65      $date_creation = 'date_creation-'.$row['id'];
     66      $keywords      = 'keywords-'.$row['id'];
     67      if ( isset( $_POST[$name] ) )
     68      {
     69        $query = 'UPDATE '.PREFIX_TABLE.'images';
     70
     71        $query.= ' SET name = ';
     72        if ( $_POST[$name] == '' )
     73          $query.= 'NULL';
     74        else
     75          $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
     76
     77        $query.= ', author = ';
     78        if ( $_POST[$author] == '' )
     79          $query.= 'NULL';
     80        else
     81          $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
     82
     83        $query.= ', comment = ';
     84        if ( $_POST[$comment] == '' )
     85          $query.= 'NULL';
     86        else
     87          $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
     88
     89        $query.= ', date_creation = ';
     90        if ( check_date_format( $_POST[$date_creation] ) )
     91          $query.= "'".date_convert( $_POST[$date_creation] )."'";
     92        else if ( $_POST[$date_creation] == '' )
     93          $query.= 'NULL';
     94
     95        $query.= ', keywords = ';
     96
     97        $keywords_array = get_keywords( $_POST[$keywords] );
     98        if ( count( $keywords_array ) == 0 ) $query.= 'NULL';
     99        else $query.= "'".implode( ',', $keywords_array )."'";
     100
     101        $query.= ' WHERE id = '.$row['id'];
     102        $query.= ';';
     103        mysql_query( $query );
     104      }
     105      // add link to another category
     106      if ( isset( $_POST['check-'.$row['id']] ) and count( $errors ) == 0 )
     107      {
     108        $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     109        $query.= ' (image_id,category_id) VALUES';
     110        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
     111        $query.= ';';
     112        mysql_query( $query );
     113        $associate = true;
     114      }
     115    }
     116    update_category( $_POST['associate'] );
     117    if ( $associate ) synchronize_all_users();
     118//------------------------------------------------------ update general options
     119    if ( isset( $_POST['use_common_author'] ) )
     120    {
    127121      $query = 'SELECT image_id';
    128122      $query.= ' FROM '.PREFIX_TABLE.'image_category';
     
    132126      {
    133127        $query = 'UPDATE '.PREFIX_TABLE.'images';
    134         if ( $_POST['date_creation_cat'] == '' )
    135         {
    136           $query.= ' SET date_creation = NULL';
    137         }
    138         else
    139         {
    140           $query.= " SET date_creation = '".$date."'";
     128        if ( $_POST['author_cat'] == '' )
     129        {
     130          $query.= ' SET author = NULL';
     131        }
     132        else
     133        {
     134          $query.= ' SET author = ';
     135          $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
    141136        }
    142137        $query.= ' WHERE id = '.$row['image_id'];
     
    145140      }
    146141    }
    147     else
    148     {
    149       echo $lang['err_date'];
    150     }
    151   }
    152   if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
    153   {
    154     $query = 'SELECT id,keywords';
    155     $query.= ' FROM '.PREFIX_TABLE.'images';
    156     $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    157     $query.= ' WHERE category_id = '.$page['cat'];
    158     $query.= ';';
    159     $result = mysql_query( $query );
    160     while ( $row = mysql_fetch_array( $result ) )
    161     {
    162       $specific_keywords = explode( ',', $row['keywords'] );
    163       $common_keywords   = get_keywords( $_POST['keywords_cat'] );
    164       // first possiblity : adding the given keywords to all the pictures
    165       if ( $_POST['common_keywords'] == 'add' )
    166       {
    167         $keywords = array_merge( $specific_keywords, $common_keywords );
    168         $keywords = array_unique( $keywords );
    169       }
    170       // second possiblity : removing the given keywords from all pictures
    171       // (without deleting the other specific keywords
    172       if ( $_POST['common_keywords'] == 'remove' )
    173       {
    174         $keywords = array_diff( $specific_keywords, $common_keywords );
    175       }
    176       // cleaning the keywords array, sometimes, an empty value still remain
    177       $keywords = array_remove( $keywords, '' );
    178       // updating the picture with new keywords array
    179       $query = 'UPDATE '.PREFIX_TABLE.'images';
    180       $query.= ' SET keywords = ';
    181       if ( count( $keywords ) == 0 )
    182       {
    183         $query.= 'NULL';
     142    if ( isset( $_POST['use_common_date_creation'] ) )
     143    {
     144      if ( check_date_format( $_POST['date_creation_cat'] ) )
     145      {
     146        $date = date_convert( $_POST['date_creation_cat'] );
     147        $query = 'SELECT image_id';
     148        $query.= ' FROM '.PREFIX_TABLE.'image_category';
     149        $query.= ' WHERE category_id = '.$page['cat'];
     150        $result = mysql_query( $query );
     151        while ( $row = mysql_fetch_array( $result ) )
     152        {
     153          $query = 'UPDATE '.PREFIX_TABLE.'images';
     154          if ( $_POST['date_creation_cat'] == '' )
     155          {
     156            $query.= ' SET date_creation = NULL';
     157          }
     158          else
     159          {
     160            $query.= " SET date_creation = '".$date."'";
     161          }
     162          $query.= ' WHERE id = '.$row['image_id'];
     163          $query.= ';';
     164          mysql_query( $query );
     165        }
    184166      }
    185167      else
    186168      {
    187         $query.= '"';
    188         $i = 0;
    189         foreach ( $keywords as $keyword ) {
    190           if ( $i++ > 0 ) $query.= ',';
    191           $query.= $keyword;
    192         }
    193         $query.= '"';
    194       }
    195       $query.= ' WHERE id = '.$row['id'];
     169        array_push( $errors, $lang['err_date'] );
     170      }
     171    }
     172    if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
     173    {
     174      $query = 'SELECT id,keywords';
     175      $query.= ' FROM '.PREFIX_TABLE.'images';
     176      $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     177      $query.= ' WHERE category_id = '.$page['cat'];
    196178      $query.= ';';
    197       mysql_query( $query );
     179      $result = mysql_query( $query );
     180      while ( $row = mysql_fetch_array( $result ) )
     181      {
     182        if ( !isset( $row['keywords'] ) ) $specific_keywords = array();
     183        else $specific_keywords = explode( ',', $row['keywords'] );
     184       
     185        $common_keywords   = get_keywords( $_POST['keywords_cat'] );
     186        // first possiblity : adding the given keywords to all the pictures
     187        if ( $_POST['common_keywords'] == 'add' )
     188        {
     189          $keywords = array_merge( $specific_keywords, $common_keywords );
     190          $keywords = array_unique( $keywords );
     191        }
     192        // second possiblity : removing the given keywords from all pictures
     193        // (without deleting the other specific keywords
     194        if ( $_POST['common_keywords'] == 'remove' )
     195        {
     196          $keywords = array_diff( $specific_keywords, $common_keywords );
     197        }
     198        // cleaning the keywords array, sometimes, an empty value still remain
     199        $keywords = array_remove( $keywords, '' );
     200        // updating the picture with new keywords array
     201        $query = 'UPDATE '.PREFIX_TABLE.'images';
     202        $query.= ' SET keywords = ';
     203        if ( count( $keywords ) == 0 )
     204        {
     205          $query.= 'NULL';
     206        }
     207        else
     208        {
     209          $query.= '"';
     210          $i = 0;
     211          foreach ( $keywords as $keyword ) {
     212            if ( $i++ > 0 ) $query.= ',';
     213            $query.= $keyword;
     214          }
     215          $query.= '"';
     216        }
     217        $query.= ' WHERE id = '.$row['id'];
     218        $query.= ';';
     219        mysql_query( $query );
     220      }
    198221    }
    199222  }
    200223//--------------------------------------------------------- form initialization
    201   $page['nb_image_page'] = 5;
    202 
    203224  if( !isset( $_GET['start'] )
    204225      or !is_numeric( $_GET['start'] )
     
    212233  }
    213234
    214   if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
     235  if ( isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0 )
    215236  {
    216237    $page['start'] =
     
    218239  }
    219240  // retrieving category information
    220   $page['plain_structure'] = get_plain_structure();
    221241  $result = get_cat_info( $page['cat'] );
    222242  $cat['name'] = $result['name'];
     
    229249                'infoimage_creation_date','keywords',
    230250                'infoimage_addtoall','infoimage_removefromall',
    231                 'infoimage_keyword_separation','infoimage_associate' );
     251                'infoimage_keyword_separation','infoimage_associate',
     252                'errors_title' );
    232253  templatize_array( $tpl, 'lang', $sub );
    233254  $vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
     255//-------------------------------------------------------------- errors display
     256if ( count( $errors ) != 0 )
     257{
     258  $vtp->addSession( $sub, 'errors' );
     259  foreach ( $errors as $error ) {
     260    $vtp->addSession( $sub, 'li' );
     261    $vtp->setVar( $sub, 'li.content', $error );
     262    $vtp->closeSession( $sub, 'li' );
     263  }
     264  $vtp->closeSession( $sub, 'errors' );
     265}
    234266//------------------------------------------------------------------------ form
    235267  $url = './admin.php?page=infos_images&amp;cat_id='.$page['cat'];
     
    244276  $array_cat_directories = array();
    245277
    246   $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords';
    247   $query.= ',storage_category_id,category_id';
     278  $infos = array( 'id','file','comment','author','tn_ext','name'
     279                  ,'date_creation','keywords','storage_category_id'
     280                  ,'category_id' );
     281 
     282  $query = 'SELECT '.implode( ',', $infos );
    248283  $query.= ' FROM '.PREFIX_TABLE.'images';
    249   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     284  $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
    250285  $query.= ' WHERE category_id = '.$page['cat'];
    251286  $query.= $conf['order_by'];
     
    255290  while ( $row = mysql_fetch_array( $result ) )
    256291  {
     292    foreach ($infos as $info) { if (!isset($row[$info])) $row[$info] = ''; }
     293   
    257294    $vtp->addSession( $sub, 'picture' );
    258295    $vtp->setVar( $sub, 'picture.id', $row['id'] );
     
    267304    $vtp->setVar( $sub, 'picture.default_name', $file );
    268305    // creating url to thumbnail
    269     if ( $array_cat_directories[$row['storage_category_id']] == '' )
     306    if ( !isset( $array_cat_directories[$row['storage_category_id']] ) )
    270307    {
    271308      $array_cat_directories[$row['storage_category_id']] =
     
    280317    $vtp->closeSession( $sub, 'picture' );
    281318  }
    282   $structure = create_structure( '', array() );
    283   display_categories( $structure, '&nbsp;' );
     319  // Virtualy associate a picture to a category
     320  //
     321  // We only show a List Of Values if the number of categories is less than
     322  // $conf['max_LOV_categories']
     323  $query = 'SELECT COUNT(id) AS nb_total_categories';
     324  $query.= ' FROM '.PREFIX_TABLE.'categories';
     325  $query.= ';';
     326  $row = mysql_fetch_array( mysql_query( $query ) );
     327  if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     328  {
     329    $vtp->addSession( $sub, 'associate_LOV' );
     330    $page['plain_structure'] = get_plain_structure( true );
     331    $structure = create_structure( '', array() );
     332    display_categories( $structure, '&nbsp;' );
     333    $vtp->closeSession( $sub, 'associate_LOV' );
     334  }
     335  // else, we only display a small text field, we suppose the administrator
     336  // knows the id of its category
     337  else
     338  {
     339    $vtp->addSession( $sub, 'associate_text' );
     340    $vtp->closeSession( $sub, 'associate_text' );
     341  }
    284342}
    285343//----------------------------------------------------------- sending html code
  • trunk/admin/phpwebgallery_structure.sql

    r266 r345  
    11-- MySQL dump 8.21
    22--
    3 -- Host: localhost    Database: devel
     3-- Host: localhost    Database: perfs_test
    44---------------------------------------------------------
    55-- Server version       3.23.49-log
     
    2424  uploadable enum('true','false') NOT NULL default 'false',
    2525  representative_picture_id mediumint(8) unsigned default NULL,
    26   PRIMARY KEY  (id)
     26  uppercats varchar(255) NOT NULL default '',
     27  PRIMARY KEY  (id),
     28  KEY id (id),
     29  KEY id_uppercat (id_uppercat)
    2730) TYPE=MyISAM;
    2831
     
    126129  image_id mediumint(8) unsigned NOT NULL default '0',
    127130  category_id smallint(5) unsigned NOT NULL default '0',
    128   PRIMARY KEY  (image_id,category_id)
     131  PRIMARY KEY  (image_id,category_id),
     132  KEY category_id (category_id),
     133  KEY image_id (image_id)
    129134) TYPE=MyISAM;
    130135
     
    187192  cat_id smallint(5) unsigned NOT NULL default '0',
    188193  PRIMARY KEY  (user_id,cat_id)
     194) TYPE=MyISAM;
     195
     196--
     197-- Table structure for table 'phpwebgallery_user_category'
     198--
     199
     200DROP TABLE IF EXISTS phpwebgallery_user_category;
     201CREATE TABLE phpwebgallery_user_category (
     202  user_id smallint(5) unsigned NOT NULL default '0',
     203  category_id smallint(5) unsigned NOT NULL default '0',
     204  date_last date default NULL,
     205  nb_sub_categories smallint(5) unsigned NOT NULL default '0',
     206  PRIMARY KEY  (user_id,category_id)
    189207) TYPE=MyISAM;
    190208
     
    221239  long_period tinyint(3) unsigned NOT NULL default '14',
    222240  template varchar(255) NOT NULL default 'default',
     241  forbidden_categories text,
    223242  PRIMARY KEY  (id),
    224243  UNIQUE KEY username (username)
  • trunk/admin/picture_modify.php

    r226 r345  
    1919
    2020include_once( './admin/include/isadmin.inc.php' );
    21 //----------------------------------------- categories structure initialization
    22 $page['plain_structure'] = get_plain_structure();
    2321//--------------------------------------------------------- update informations
    2422$errors = array();
     
    8886    // category, the category is updated in the database (without wondering
    8987    // if this picture was already the representative one)
    90     if ( $_POST['representative-'.$row['category_id']] == 1 )
     88    if ( isset($_POST['representative-'.$row['category_id']]) )
    9189    {
    9290      $query = 'UPDATE '.PREFIX_TABLE.'categories';
     
    9896    // if the user ask this picture to be not any more the representative,
    9997    // we have to set the representative_picture_id of this category to NULL
    100     else if ( $row['representative_picture_id'] == $_GET['image_id'] )
     98    else if ( isset( $row['representative_picture_id'] )
     99              and $row['representative_picture_id'] == $_GET['image_id'] )
    101100    {
    102101      $query = 'UPDATE '.PREFIX_TABLE.'categories';
     
    107106    }
    108107  }
     108  $associate_or_dissociate = false;
    109109  // associate with a new category ?
    110   if ( $_POST['associate'] != '-1' )
     110  if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' )
     111  {
     112    // does the uppercat id exists in the database ?
     113    if ( !is_numeric( $_POST['associate'] ) )
     114    {
     115      array_push( $errors, $lang['cat_unknown_id'] );
     116    }
     117    else
     118    {
     119      $query = 'SELECT id';
     120      $query.= ' FROM '.PREFIX_TABLE.'categories';
     121      $query.= ' WHERE id = '.$_POST['associate'];
     122      $query.= ';';
     123      if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
     124        array_push( $errors, $lang['cat_unknown_id'] );
     125    }
     126  }
     127  if ( $_POST['associate'] != '-1'
     128       and $_POST['associate'] != ''
     129       and count( $errors ) == 0 )
    111130  {
    112131    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     
    115134    $query.= ';';
    116135    mysql_query( $query);
     136    $associate_or_dissociate = true;
    117137    update_category( $_POST['associate'] );
    118138  }
     
    126146  while ( $row = mysql_fetch_array( $result ) )
    127147  {
    128     if ( $_POST['dissociate-'.$row['category_id']] == 1 )
     148    if ( isset($_POST['dissociate-'.$row['category_id']]) )
    129149    {
    130150      $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
     
    133153      $query.= ';';
    134154      mysql_query( $query );
     155      $associate_or_dissociate = true;
    135156      update_category( $row['category_id'] );
    136157    }
     158  }
     159  if ( $associate_or_dissociate )
     160  {
     161    synchronize_all_users();
    137162  }
    138163}
     
    163188$vtp->setVar( $sub, 'form_action', $action );
    164189// retrieving direct information about picture
    165 $query = 'SELECT file,date_available,date_creation,tn_ext,name,filesize';
    166 $query.= ',width,height,author,comment,keywords,storage_category_id';
     190$infos = array( 'file','date_available','date_creation','tn_ext','name'
     191                ,'filesize','width','height','author','comment','keywords'
     192                ,'storage_category_id' );
     193$query = 'SELECT '. implode( ',', $infos );
    167194$query.= ' FROM '.PREFIX_TABLE.'images';
    168195$query.= ' WHERE id = '.$_GET['image_id'];
    169196$query.= ';';
    170197$row = mysql_fetch_array( mysql_query( $query ) );
     198
     199foreach ( $infos as $info ) {
     200  if ( !isset( $row[$info] ) ) $row[$info] = '';
     201}
     202
    171203// picture title
    172204if ( $row['name'] == '' )
     
    291323  }
    292324
    293   if ( $row['representative_picture_id'] == $_GET['image_id'] )
     325  if ( isset( $row['representative_picture_id'] )
     326       and $row['representative_picture_id'] == $_GET['image_id'] )
    294327  {
    295328    $vtp->setVar( $sub, 'linked_category.representative_checked',
     
    307340}
    308341// associate to another category ?
    309 $vtp->addSession( $sub, 'associate_cat' );
    310 $vtp->setVar( $sub, 'associate_cat.value', '-1' );
    311 $vtp->setVar( $sub, 'associate_cat.content', '' );
    312 $vtp->closeSession( $sub, 'associate_cat' );
    313 $structure = create_structure( '', array() );
    314 display_categories( $structure, '&nbsp;' );
     342//
     343// We only show a List Of Values if the number of categories is less than
     344// $conf['max_LOV_categories']
     345$query = 'SELECT COUNT(id) AS nb_total_categories';
     346$query.= ' FROM '.PREFIX_TABLE.'categories';
     347$query.= ';';
     348$row = mysql_fetch_array( mysql_query( $query ) );
     349if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     350{
     351  $vtp->addSession( $sub, 'associate_LOV' );
     352  $vtp->addSession( $sub, 'associate_cat' );
     353  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     354  $vtp->setVar( $sub, 'associate_cat.content', '' );
     355  $vtp->closeSession( $sub, 'associate_cat' );
     356  $page['plain_structure'] = get_plain_structure( true );
     357  $structure = create_structure( '', array() );
     358  display_categories( $structure, '&nbsp;' );
     359  $vtp->closeSession( $sub, 'associate_LOV' );
     360}
     361// else, we only display a small text field, we suppose the administrator
     362// knows the id of its category
     363else
     364{
     365  $vtp->addSession( $sub, 'associate_text' );
     366  $vtp->closeSession( $sub, 'associate_text' );
     367}
    315368//----------------------------------------------------------- sending html code
    316369$vtp->Parse( $handle , 'sub', $sub );
  • trunk/admin/stats.php

    r231 r345  
    4343$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
    4444//--------------------------------------------------- number of days to display
    45 if ( isset( $_GET['last_days'] ) ) define( "MAX_DAYS", $_GET['last_days'] );
    46 else                               define( "MAX_DAYS", 0 );
     45if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
     46else                               define( 'MAX_DAYS', 0 );
    4747
    4848foreach ( $conf['last_days'] as $option ) {
    4949  $vtp->addSession( $sub, 'last_day_option' );
    5050  $vtp->setVar( $sub, 'last_day_option.option', $option );
    51   $url = './admin.php?page=stats&amp;expand='.$_GET['expand'];
     51  $url = './admin.php?page=stats';
     52  if (isset($_GET['expand']))
     53          $url .='&amp;expand='.$_GET['expand'];
    5254  $url.= '&amp;last_days='.($option - 1);
    5355  $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) );
     
    6062//---------------------------------------------------------------- log  history
    6163// empty link
    62 $url = './admin.php?page=stats&amp;last_days='.$_GET['last_days'];
    63 $url.= '&amp;expand='.$_GET['expand'];
     64$url = './admin.php?page=stats';
     65if (isset($_GET['last_days']))
     66        $url .='&amp;last_days='.$_GET['last_days'];
     67// expand array management
     68$expand_days = array();
     69if (isset($_GET['expand']))
     70{
     71        $url.= '&amp;expand='.$_GET['expand'];
     72        $expand_days = explode( ',', $_GET['expand'] );
     73}
    6474$url.= '&amp;act=empty';
    6575$vtp->setVar( $sub, 'emply_url', add_session_id( $url ) );
    66 // expand array management
    67 $expand_days = explode( ',', $_GET['expand'] );
    6876$page['expand_days'] = array();
    6977foreach ( $expand_days as $expand_day ) {
     
    100108    array_push( $local_expand, $i );
    101109  }
    102   $url = './admin.php?page=stats&amp;last_days='.$_GET['last_days'];
     110  $url = './admin.php?page=stats';
     111  if (isset($_GET['last_days']))
     112        $url.= '&amp;last_days='.$_GET['last_days'];
    103113  $url.= '&amp;expand='.implode( ',', $local_expand );
    104114  $vtp->setVar( $sub, 'day.url', add_session_id( $url ) );
  • trunk/admin/thumbnail.php

    r228 r345  
    254254    $vtp->closeSession( $sub, 'dir' );
    255255    // recursive call
    256     $dirs.= get_displayed_dirs( $dir.'/'.$sub_dir,
    257                                 $indent+30 );
    258    
     256    get_displayed_dirs( $dir.'/'.$sub_dir,
     257                                $indent+30 );   
    259258  }
    260259}
     
    360359    $vtp->setVar( $sub, 'params.action', add_session_id( $url ) );
    361360    // GD version selected...
    362     if ( $_POST['gd'] == 1 )
     361    if ( isset( $_POST['gd'] ) and $_POST['gd'] == 1 )
    363362    {
    364363      $vtp->setVar( $sub, 'params.gd1_checked', ' checked="checked"' );
     
    388387    // options for the number of picture to miniaturize : "n"
    389388    $options = array( 5,10,20,40 );
     389    if ( isset( $_POST['n'] ) ) $n = $_POST['n'];
     390    else                        $n = 5;
    390391    foreach ( $options as $option ) {
    391392      $vtp->addSession( $sub, 'n_option' );
    392393      $vtp->setVar( $sub, 'n_option.option', $option );
    393       if ( $option == $_POST['n'] )
     394      if ( $option == $n )
    394395      {
    395396        $vtp->setVar( $sub, 'n_option.selected', ' selected="selected"' );
  • trunk/admin/update.php

    r228 r345  
    33 *                                update.php                               *
    44 *                            ------------------                           *
    5  *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
     5 *   application   : PhpWebGallery 1.4 <http://phpwebgallery.net>          *
    66 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
    77 *                                                                         *
     
    2020include_once( './admin/include/isadmin.inc.php' );
    2121//------------------------------------------------------------------- functions
    22 function insert_local_category( $cat_id )
     22function insert_local_category( $id_uppercat )
    2323{
    2424  global $conf, $page, $user, $lang;
    25 
    26   $site_id = 1;
     25 
     26  $uppercats = '';
     27  $output = '';
    2728
    2829  // 0. retrieving informations on the category to display
    2930  $cat_directory = './galleries';
    30 
    31   if ( is_numeric( $cat_id ) )
    32   {
    33     $cat_directory.= '/'.get_local_dir( $cat_id );
    34     $result = get_cat_info( $cat_id );
     31  if ( is_numeric( $id_uppercat ) )
     32  {
     33    $query = 'SELECT name,uppercats,dir';
     34    $query.= ' FROM '.PREFIX_TABLE.'categories';
     35    $query.= ' WHERE id = '.$id_uppercat;
     36    $query.= ';';
     37    $row = mysql_fetch_array( mysql_query( $query ) );
     38    $uppercats = $row['uppercats'];
     39    $name      = $row['name'];
     40    $dir       = $row['dir'];
     41
     42    $upper_array = explode( ',', $uppercats );
     43
     44    $local_dir = '';
     45
     46    $database_dirs = array();
     47    $query = 'SELECT id,dir';
     48    $query.= ' FROM '.PREFIX_TABLE.'categories';
     49    $query.= ' WHERE id IN ('.$uppercats.')';
     50    $query.= ';';
     51    $result = mysql_query( $query );
     52    while( $row = mysql_fetch_array( $result ) )
     53    {
     54      $database_dirs[$row['id']] = $row['dir'];
     55    }
     56    foreach ( $upper_array as $id ) {
     57      $local_dir.= $database_dirs[$id].'/';
     58    }
     59
     60    $cat_directory.= '/'.$local_dir;
     61
    3562    // 1. display the category name to update
    3663    $src = './template/'.$user['template'].'/admin/images/puce.gif';
    3764    $output = '<img src="'.$src.'" alt="&gt;" />';
    38     $output.= '<span style="font-weight:bold;">'.$result['name'][0].'</span>';
    39     $output.= ' [ '.$result['dir'].' ]';
     65    $output.= '<span style="font-weight:bold;">'.$name.'</span>';
     66    $output.= ' [ '.$dir.' ]';
    4067    $output.= '<div class="retrait">';
    4168
     
    4471    if ( isset( $page['cat'] ) or $_GET['update'] == 'all' )
    4572    {
    46       $output.= insert_local_image( $cat_directory, $cat_id );
    47     }
    48   }
    49 
     73      $output.= insert_local_image( $cat_directory, $id_uppercat );
     74    }
     75  }
     76
     77  $sub_dirs = get_category_directories( $cat_directory );
     78
     79  $sub_category_dirs = array();
     80  $query = 'SELECT id,dir';
     81  $query.= ' FROM '.PREFIX_TABLE.'categories';
     82  $query.= ' WHERE site_id = 1';
     83  if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL';
     84  else                           $query.= ' AND id_uppercat = '.$id_uppercat;
     85  $query.= ' AND dir IS NOT NULL'; // virtual categories not taken
     86  $query.= ';';
     87  $result = mysql_query( $query );
     88  while ( $row = mysql_fetch_array( $result ) )
     89  {
     90    $sub_category_dirs[$row['id']] = $row['dir'];
     91  }
     92 
    5093  // 3. we have to remove the categories of the database not present anymore
     94  foreach ( $sub_category_dirs as $id => $dir ) {
     95    if ( !in_array( $dir, $sub_dirs ) ) delete_category( $id );
     96  }
     97
     98  // array of new categories to insert
     99  $inserts = array();
     100 
     101  foreach ( $sub_dirs as $sub_dir ) {
     102    // 5. Is the category already existing ? we create a subcat if not
     103    //    existing
     104    $category_id = array_search( $sub_dir, $sub_category_dirs );
     105    if ( !is_numeric( $category_id ) )
     106    {
     107      if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $sub_dir ) )
     108      {
     109        $name = str_replace( '_', ' ', $sub_dir );
     110
     111        $value = "('".$sub_dir."','".$name."',1";
     112        if ( !is_numeric( $id_uppercat ) ) $value.= ',NULL';
     113        else                               $value.= ','.$id_uppercat;
     114        $value.= ",'undef'";
     115        $value.= ')';
     116        array_push( $inserts, $value );
     117      }
     118      else
     119      {
     120        $output.= '<span style="color:red;">"'.$sub_dir.'" : ';
     121        $output.= $lang['update_wrong_dirname'].'</span><br />';
     122      }
     123    }
     124  }
     125
     126  // we have to create the category
     127  if ( count( $inserts ) > 0 )
     128  {
     129    $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
     130    $query.= ' (dir,name,site_id,id_uppercat,uppercats) VALUES ';
     131    $query.= implode( ',', $inserts );
     132    $query.= ';';
     133    mysql_query( $query );
     134    // updating uppercats field
     135    $query = 'UPDATE '.PREFIX_TABLE.'categories';
     136    $query.= ' SET uppercats = ';
     137    if ( $uppercats != '' ) $query.= "CONCAT('".$uppercats."',',',id)";
     138    else                    $query.= 'id';
     139    $query.= ' WHERE id_uppercat ';
     140    if (!is_numeric($id_uppercat)) $query.= 'IS NULL';
     141    else                           $query.= '= '.$id_uppercat;
     142    $query.= ';';
     143    mysql_query( $query );
     144  }
     145
     146  // Recursive call on the sub-categories (not virtual ones)
    51147  $query = 'SELECT id';
    52148  $query.= ' FROM '.PREFIX_TABLE.'categories';
    53   $query.= ' WHERE site_id = '.$site_id;
    54   if ( !is_numeric( $cat_id ) )
    55   {
    56     $query.= ' AND id_uppercat IS NULL';
    57   }
    58   else
    59   {
    60     $query.= ' AND id_uppercat = '.$cat_id;
    61   }
    62   $query.= ';';
    63   $result = mysql_query( $query );
    64   while ( $row = mysql_fetch_array( $result ) )
    65   {
    66     // retrieving the directory
    67     $rep = './galleries/'.get_local_dir( $row['id'] );
    68     // is the directory present ?
    69     if ( !is_dir( $rep ) ) delete_category( $row['id'] );
    70   }
    71   // 4. retrieving the sub-directories
    72   $subdirs = array();
    73   $dirs = '';
    74   if ( $opendir = opendir( $cat_directory ) )
    75   {
    76     while ( $file = readdir( $opendir ) )
    77     {
    78       if ( $file != '.'
    79            and $file != '..'
    80            and is_dir ( $cat_directory.'/'.$file )
    81            and $file != 'thumbnail' )
    82       {
    83         if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
    84           array_push( $subdirs, $file );
    85         else
    86         {
    87           $output.= '<span style="color:red;">"'.$file.'" : ';
    88           $output.= $lang['update_wrong_dirname'].'</span><br />';
    89           // if the category even exists (from a previous release of
    90           // PhpWebGallery), we keep it in our $subdirs array
    91           $query = 'SELECT id';
    92           $query.= ' FROM '.PREFIX_TABLE.'categories';
    93           $query.= ' WHERE site_id = '.$site_id;
    94           $query.= " AND dir = '".$file."'";
    95           $query.= ' AND id_uppercat';
    96           if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL';
    97           else                          $query.= ' = '.$cat_id;
    98           $query.= ';';
    99           $result = mysql_query( $query );
    100           if ( mysql_num_rows( $result ) != 0 )
    101           {
    102             array_push( $subdirs, $file );
    103           }
    104         }
    105       }
    106     }
    107   }
    108   foreach ( $subdirs as $subdir ) {
    109     // 5. Is the category already existing ? we create a subcat if not
    110     //    existing
    111     $category_id = '';
    112     $query = 'SELECT id';
    113     $query.= ' FROM '.PREFIX_TABLE.'categories';
    114     $query.= ' WHERE site_id = '.$site_id;
    115     $query.= " AND dir = '".$subdir."'";
    116     $query.= ' AND id_uppercat';
    117     if ( !is_numeric( $cat_id ) ) $query.= ' IS NULL';
    118     else                          $query.= ' = '.$cat_id;
    119     $query.= ';';
    120     $result = mysql_query( $query );
    121     if ( mysql_num_rows( $result ) == 0 )
    122     {
    123       $name = str_replace( '_', ' ', $subdir );
    124       // we have to create the category
    125       $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
    126       $query.= ' (dir,name,site_id,id_uppercat) VALUES';
    127       $query.= " ('".$subdir."','".$name."','".$site_id."'";
    128       if ( !is_numeric( $cat_id ) ) $query.= ',NULL';
    129       else                          $query.= ",'".$cat_id."'";
    130       $query.= ');';
    131       mysql_query( $query );
    132       $category_id = mysql_insert_id();
    133       // regeneration of the plain_structure to integrate the new category
    134       $page['plain_structure'] = get_plain_structure();
    135     }
    136     else
    137     {
    138       // we get the already registered id
    139       $row = mysql_fetch_array( $result );
    140       $category_id = $row['id'];
    141     }
    142     // 6. recursive call
    143     $output.= insert_local_category( $category_id );
    144   }
    145                
    146   if ( is_numeric( $cat_id ) )
     149  $query.= ' WHERE site_id = 1';
     150  if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL';
     151  else                           $query.= ' AND id_uppercat = '.$id_uppercat;
     152  $query.= ' AND dir IS NOT NULL'; // virtual categories not taken
     153  $query.= ';';
     154  $result = mysql_query( $query );
     155  while ( $row = mysql_fetch_array( $result ) )
     156  {
     157    $output.= insert_local_category( $row['id'] );
     158  }
     159
     160  if ( is_numeric( $id_uppercat ) )
    147161  {
    148162    $output.= '</div>';
     
    150164  return $output;
    151165}
    152        
    153 function insert_local_image( $rep, $category_id )
     166
     167function insert_local_image( $dir, $category_id )
    154168{
    155169  global $lang,$conf,$count_new;
    156170
    157171  $output = '';
     172
     173  // fs means filesystem : $fs_pictures contains pictures in the filesystem
     174  // found in $dir, $fs_thumbnails contains thumbnails...
     175  $fs_pictures   = get_picture_files( $dir );
     176  $fs_thumbnails = get_thumb_files( $dir.'thumbnail' );
     177
    158178  // we have to delete all the images from the database that :
    159179  //     - are not in the directory anymore
     
    166186  while ( $row = mysql_fetch_array( $result ) )
    167187  {
    168     $lien_image = $rep.'/'.$row['file'];
    169     $lien_thumbnail = $rep.'/thumbnail/'.$conf['prefix_thumbnail'];
    170     $lien_thumbnail.= get_filename_wo_extension( $row['file'] );
    171     $lien_thumbnail.= '.'.$row['tn_ext'];
    172                
    173     if ( !is_file ( $lien_image ) or !is_file ( $lien_thumbnail ) )
    174     {
    175       if ( !is_file ( $lien_image ) )
     188    $pic_to_delete = false;
     189    if ( !in_array( $row['file'], $fs_pictures ) )
     190    {
     191      $output.= $row['file'];
     192      $output.= ' <span style="font-weight:bold;">';
     193      $output.= $lang['update_disappeared'].'</span><br />';
     194      $pic_to_delete = true;
     195    }
     196
     197    $thumbnail = $conf['prefix_thumbnail'];
     198    $thumbnail.= get_filename_wo_extension( $row['file'] );
     199    $thumbnail.= '.'.$row['tn_ext'];
     200    if ( !in_array( $thumbnail, $fs_thumbnails ) )
     201    {
     202      $output.= $row['file'];
     203      $output.= ' : <span style="font-weight:bold;">';
     204      $output.= $lang['update_disappeared_tn'].'</span><br />';
     205      $pic_to_delete = true;
     206    }
     207
     208    if ( $pic_to_delete ) delete_image( $row['id'] );
     209  }
     210
     211  $registered_pictures = array();
     212  $query = 'SELECT file';
     213  $query.= ' FROM '.PREFIX_TABLE.'images';
     214  $query.= ' WHERE storage_category_id = '.$category_id;
     215  $query.= ';';
     216  $result = mysql_query( $query );
     217  while ( $row = mysql_fetch_array( $result ) )
     218  {
     219    array_push( $registered_pictures, $row['file'] );
     220  }
     221
     222  // validated pictures are picture uploaded by users, validated by an admin
     223  // and not registered (visible) yet
     224  $validated_pictures    = array();
     225  $unvalidated_pictures  = array();
     226 
     227  $query = 'SELECT file,infos,validated';
     228  $query.= ' FROM '.PREFIX_TABLE.'waiting';
     229  $query.= ' WHERE storage_category_id = '.$category_id;
     230  $query.= ';';
     231  $result = mysql_query( $query );
     232  while ( $row = mysql_fetch_array( $result ) )
     233  {
     234    if ( $row['validated'] == 'true' )
     235      $validated_pictures[$row['file']] = $row['infos'];
     236    else
     237      array_push( $unvalidated_pictures, $row['file'] );
     238  }
     239
     240  // we only search among the picture present in the filesystem and not
     241  // present in the database yet. If we know that this picture is known as
     242  // an uploaded one but not validated, it's not tested neither
     243  $unregistered_pictures = array_diff( $fs_pictures
     244                                       ,$registered_pictures
     245                                       ,$unvalidated_pictures );
     246
     247  $inserts = array();
     248 
     249  foreach ( $unregistered_pictures as $unregistered_picture ) {
     250    if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $unregistered_picture ) )
     251    {
     252      $file_wo_ext = get_filename_wo_extension( $unregistered_picture );
     253      $tn_ext = '';
     254      foreach ( $conf['picture_ext'] as $ext ) {
     255        $test = $conf['prefix_thumbnail'].$file_wo_ext.'.'.$ext;
     256        if ( !in_array( $test, $fs_thumbnails ) ) continue;
     257        else { $tn_ext = $ext; break; }
     258      }
     259      // if we found a thumnbnail corresponding to our picture...
     260      if ( $tn_ext != '' )
    176261      {
    177         $output.= $row['file'];
     262        $image_size = @getimagesize( $dir.$unregistered_picture );
     263        // (file, storage_category_id, date_available, tn_ext, filesize,
     264        // width, height, name, author, comment, date_creation)'
     265        $value = '(';
     266        $value.= "'".$unregistered_picture."'";
     267        $value.= ','.$category_id;
     268        $value.= ",'".date( 'Y-m-d' )."'";
     269        $value.= ",'".$tn_ext."'";
     270        $value.= ','.floor( filesize( $dir.$unregistered_picture) / 1024 );
     271        $value.= ','.$image_size[0];
     272        $value.= ','.$image_size[1];
     273        if ( isset( $validated_pictures[$unregistered_picture] ) )
     274        {
     275          // retrieving infos from the XML description from waiting table
     276          $infos = nl2br( $validated_pictures[$unregistered_picture] );
     277
     278          $unixtime = getAttribute( $infos, 'date_creation' );
     279          if ($unixtime != '') $date_creation ="'".date('Y-m-d',$unixtime)."'";
     280          else                 $date_creation = 'NULL';
     281         
     282          $value.= ",'".getAttribute( $infos, 'name' )."'";
     283          $value.= ",'".getAttribute( $infos, 'author' )."'";
     284          $value.= ",'".getAttribute( $infos, 'comment')."'";
     285          $value.= ','.$date_creation;
     286
     287          // deleting the waiting element
     288          $query = 'DELETE FROM '.PREFIX_TABLE.'waiting';
     289          $query.= " WHERE file = '".$unregistered_picture."'";
     290          $query.= ' AND storage_category_id = '.$category_id;
     291          $query.= ';';
     292          mysql_query( $query );
     293        }
     294        else
     295        {
     296          $value.= ",'','','',NULL";
     297        }
     298        $value.= ')';
     299       
     300        $count_new++;
     301        $output.= $unregistered_picture;
    178302        $output.= ' <span style="font-weight:bold;">';
    179         $output.= $lang['update_disappeared'].'</span><br />';
     303        $output.= $lang['update_research_added'].'</span>';
     304        $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')';
     305        $output.= '<br />';
     306        array_push( $inserts, $value );
    180307      }
    181       if ( !is_file ( $lien_thumbnail ) )
     308      else
    182309      {
    183         $output.= $row['file'];
    184         $output.= ' : <span style="font-weight:bold;">';
    185         $output.= $lang['update_disappeared_tn'].'</span><br />';
     310        $output.= '<span style="color:red;">';
     311        $output.= $lang['update_missing_tn'].' : '.$unregistered_picture;
     312        $output.= ' (<span style="font-weight:bold;">';
     313        $output.= $conf['prefix_thumbnail'];
     314        $output.= get_filename_wo_extension( $unregistered_picture );
     315        $output.= '.XXX</span>';
     316        $output.= ', XXX = ';
     317        $output.= implode( ', ', $conf['picture_ext'] );
     318        $output.= ')</span><br />';
    186319      }
    187       // suppression de la base :
    188       delete_image( $row['id'] );
    189     }
    190   }
    191                
    192   // searching the new images in the directory
    193   $pictures = array();         
    194   $tn_ext = '';
    195   if ( $opendir = opendir( $rep ) )
    196   {
    197     while ( $file = readdir( $opendir ) )
    198     {
    199       if ( is_file( $rep.'/'.$file ) and is_image( $rep.'/'.$file ) )
    200       {
    201         // is the picture waiting for validation by an administrator ?
    202         $query = 'SELECT id,validated,infos';
    203         $query.= ' FROM '.PREFIX_TABLE.'waiting';
    204         $query.= ' WHERE storage_category_id = '.$category_id;
    205         $query.= " AND file = '".$file."'";
    206         $query.= ';';
    207         $result = mysql_query( $query );
    208         $waiting = mysql_fetch_array( $result );
    209         if (mysql_num_rows( $result ) == 0 or $waiting['validated'] == 'true')
    210         {
    211           if ( $tn_ext = TN_exists( $rep, $file ) )
    212           {
    213             // is the picture already in the database ?
    214             $query = 'SELECT id';
    215             $query.= ' FROM '.PREFIX_TABLE.'images';
    216             $query.= ' WHERE storage_category_id = '.$category_id;
    217             $query.= " AND file = '".$file."'";
    218             $query.= ';';
    219             $result = mysql_query( $query );
    220             if ( mysql_num_rows( $result ) == 0 )
    221             {
    222               // the name of the file must not use acentuated characters or
    223               // blank space..
    224               if ( preg_match( '/^[a-zA-Z0-9-_.]+$/', $file ) )
    225               {
    226                 $picture = array();
    227                 $picture['file']     = $file;
    228                 $picture['tn_ext']   = $tn_ext;
    229                 $picture['date'] = date( 'Y-m-d', filemtime($rep.'/'.$file) );
    230                 $picture['filesize'] = floor( filesize($rep.'/'.$file) / 1024);
    231                 $image_size = @getimagesize( $rep.'/'.$file );
    232                 $picture['width']    = $image_size[0];
    233                 $picture['height']   = $image_size[1];
    234                 if ( $waiting['validated'] == 'true' )
    235                 {
    236                   // retrieving infos from the XML description of
    237                   // $waiting['infos']
    238                   $infos = nl2br( $waiting['infos'] );
    239                   $picture['author']        = getAttribute( $infos, 'author' );
    240                   $picture['comment']       = getAttribute( $infos, 'comment');
    241                   $unixtime = getAttribute( $infos, 'date_creation' );
    242                   $picture['date_creation'] = '';
    243                   if ( $unixtime != '' )
    244                     $picture['date_creation'] = date( 'Y-m-d', $unixtime );
    245                   $picture['name']          = getAttribute( $infos, 'name' );
    246                   // deleting the waiting element
    247                   $query = 'DELETE FROM '.PREFIX_TABLE.'waiting';
    248                   $query.= ' WHERE id = '.$waiting['id'];
    249                   $query.= ';';
    250                   mysql_query( $query );
    251                 }
    252                 array_push( $pictures, $picture );
    253               }
    254               else
    255               {
    256                 $output.= '<span style="color:red;">"'.$file.'" : ';
    257                 $output.= $lang['update_wrong_dirname'].'</span><br />';
    258               }
    259 
    260             }
    261           }
    262           else
    263           {
    264             $output.= '<span style="color:red;">';
    265             $output.= $lang['update_missing_tn'].' : '.$file;
    266             $output.= ' (<span style="font-weight:bold;">';
    267             $output.= $conf['prefix_thumbnail'];
    268             $output.= get_filename_wo_extension( $file ).'.XXX</span>';
    269             $output.= ', XXX = ';
    270             $output.= implode( ', ', $conf['picture_ext'] );
    271             $output.= ')</span><br />';
    272           }
    273         }
    274       }
    275     }
    276   }
    277   // inserting the pictures found in the directory
    278   foreach ( $pictures as $picture ) {
     320    }
     321    else
     322    {
     323      $output.= '<span style="color:red;">"'.$unregistered_picture.'" : ';
     324      $output.= $lang['update_wrong_dirname'].'</span><br />';
     325    }
     326  }
     327
     328  if ( count( $inserts ) > 0 )
     329  {
     330    // inserts all found pictures
    279331    $query = 'INSERT INTO '.PREFIX_TABLE.'images';
    280332    $query.= ' (file,storage_category_id,date_available,tn_ext';
     
    282334    $query.= ',name,author,comment,date_creation)';
    283335    $query.= ' VALUES ';
    284     $query.= "('".$picture['file']."','".$category_id."'";
    285     $query.= ",'".$picture['date']."','".$picture['tn_ext']."'";
    286     $query.= ",'".$picture['filesize']."','".$picture['width']."'";
    287     $query.= ",'".$picture['height']."','".$picture['name']."'";
    288     $query.= ",'".$picture['author']."','".$picture['comment']."'";
    289     if ( $picture['date_creation'] != '' )
    290     {
    291       $query.= ",'".$picture['date_creation']."'";
    292     }
    293     else
    294     {
    295       $query.= ',NULL';
    296     }
    297     $query.= ');';
    298     mysql_query( $query );
    299     $count_new++;
    300     // retrieving the id of newly inserted picture
     336    $query.= implode( ',', $inserts );
     337    $query.= ';';
     338    mysql_query( $query );
     339
     340    // what are the ids of the pictures in the $category_id ?
     341    $ids = array();
     342
    301343    $query = 'SELECT id';
    302344    $query.= ' FROM '.PREFIX_TABLE.'images';
    303345    $query.= ' WHERE storage_category_id = '.$category_id;
    304     $query.= " AND file = '".$picture['file']."'";
    305     $query.= ';';
    306     list( $image_id ) = mysql_fetch_array( mysql_query( $query ) );
    307     // adding the link between this picture and its storage category
     346    $query.= ';';
     347    $result = mysql_query( $query );
     348    while ( $row = mysql_fetch_array( $result ) )
     349    {
     350      array_push( $ids, $row['id'] );
     351    }
     352
     353    // recreation of the links between this storage category pictures and
     354    // its storage category
     355    $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
     356    $query.= ' WHERE category_id = '.$category_id;
     357    $query.= ' AND image_id IN ('.implode( ',', $ids ).')';
     358    $query.= ';';
     359    mysql_query( $query );
     360
    308361    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
    309     $query.= ' (image_id,category_id) VALUES ';
    310     $query.= ' ('.$image_id.','.$category_id.')';
    311     $query.= ';';
    312     mysql_query( $query );
    313 
    314     $output.= $picture['file'];
    315     $output.= ' <span style="font-weight:bold;">';
    316     $output.= $lang['update_research_added'].'</span>';
    317     $output.= ' ('.$lang['update_research_tn_ext'].' '.$picture['tn_ext'].')';
    318     $output.= '<br />';
     362    $query.= '(category_id,image_id) VALUES ';
     363    foreach ( $ids as $num => $image_id ) {
     364      if ( $num > 0 ) $query.= ',';
     365      $query.= '('.$category_id.','.$image_id.')';
     366    }
     367    $query.= ';';
     368    mysql_query( $query );
    319369  }
    320370  return $output;
     
    368418// function also deletes the categories that are in the database and not in
    369419// the xml_file.
    370 function insert_remote_category( $xml_dir, $site_id, $id_uppercat, $level )
    371 {
    372   global $conf,$user;
    373 
     420function insert_remote_category( $xml_content, $site_id, $id_uppercat, $level )
     421{
     422  global $conf, $page, $user, $lang;
     423 
     424  $uppercats = '';
    374425  $output = '';
    375   $categories = array();
    376   $list_dirs = getChildren( $xml_dir, 'dir'.$level );
    377   for ( $i = 0; $i < sizeof( $list_dirs ); $i++ )
    378   {
    379     // is the category already existing ?
    380     $category_id = '';
    381     $dir = getAttribute( $list_dirs[$i], 'name' );
    382     $categories[$i] = $dir;
    383 
     426  // 0. retrieving informations on the category to display
     427  $cat_directory = '../galleries';
     428               
     429  if ( is_numeric( $id_uppercat ) )
     430  {
     431    $query = 'SELECT name,uppercats,dir';
     432    $query.= ' FROM '.PREFIX_TABLE.'categories';
     433    $query.= ' WHERE id = '.$id_uppercat;
     434    $query.= ';';
     435    $row = mysql_fetch_array( mysql_query( $query ) );
     436    $uppercats = $row['uppercats'];
     437    $name      = $row['name'];
     438
     439    // 1. display the category name to update
    384440    $src = './template/'.$user['template'].'/admin/images/puce.gif';
    385     $output.= '<img src="'.$src.'" alt="&gt;" />';
    386     $output.= '<span style="font-weight:bold;">'.$dir.'</span>';
     441    $output = '<img src="'.$src.'" alt="&gt;" />';
     442    $output.= '<span style="font-weight:bold;">'.$name.'</span>';
     443    $output.= ' [ '.$row['dir'].' ]';
    387444    $output.= '<div class="retrait">';
    388445
    389     $query = 'SELECT id';
    390     $query.= ' FROM '.PREFIX_TABLE.'categories';
    391     $query.= ' WHERE site_id = '.$site_id;
    392     $query.= " AND dir = '".$dir."'";
    393     if ( $id_uppercat == 'NULL' )
    394     {
    395       $query.= ' AND id_uppercat IS NULL';
    396     }
    397     else
    398     {
    399       $query.= ' AND id_uppercat = '.$id_uppercat;
    400     }
    401     $query.= ';';
    402     $result = mysql_query( $query );
    403     if ( mysql_num_rows( $result ) == 0 )
    404     {
    405       $name = str_replace( '_', ' ', $dir );
    406       // we have to create the category
    407       $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
    408       $query.= ' (name,dir,site_id,id_uppercat) VALUES ';
    409       $query.= "('".$name."','".$dir."',".$site_id;
    410       if ( !is_numeric( $id_uppercat ) )
    411       {
    412         $query.= ',NULL';
    413       }
    414       else
    415       {
    416         $query.= ','.$id_uppercat;
    417       }
    418       $query.= ');';
    419       mysql_query( $query );
    420       $category_id = mysql_insert_id();
    421     }
    422     else
    423     {
    424       // we get the already registered id
    425       $row = mysql_fetch_array( $result );
    426       $category_id = $row['id'];
    427     }
    428     $output.= insert_remote_image( $list_dirs[$i], $category_id );
    429     $output.= insert_remote_category( $list_dirs[$i], $site_id,
    430                                       $category_id, $level+1 );
    431     $output.= '</div>';
    432   }
    433   // we have to remove the categories of the database not present in the xml
    434   // file (ie deleted from the picture storage server)
    435   $query = 'SELECT dir,id';
     446    // 2. we search pictures of the category only if the update is for all
     447    //    or a cat_id is specified
     448    $output.= insert_remote_image( $xml_content, $id_uppercat );
     449  }
     450
     451  // $xml_dirs contains dir names contained in the xml file for this
     452  // id_uppercat
     453  $xml_dirs = array();
     454  $temp_dirs = getChildren( $xml_content, 'dir'.$level );
     455  foreach ( $temp_dirs as $temp_dir ) {
     456    array_push( $xml_dirs, getAttribute( $temp_dir, 'name' ) );
     457  }
     458
     459  // $database_dirs contains dir names contained in the database for this
     460  // id_uppercat and site_id
     461  $database_dirs = array();
     462  $query = 'SELECT id,dir';
    436463  $query.= ' FROM '.PREFIX_TABLE.'categories';
    437464  $query.= ' WHERE site_id = '.$site_id;
    438   if ( !is_numeric( $id_uppercat ) )
    439   {
    440     $query.= ' AND id_uppercat IS NULL';
    441   }
    442   else
    443   {
    444     $query.= ' AND id_uppercat = '.$id_uppercat;
    445   }
    446   $query.= ';';
    447   $result = mysql_query( $query );
    448   while ( $row = mysql_fetch_array( $result ) )
    449   {
    450     // is the category in the xml file ?
    451     if ( !in_array( $row['dir'], $categories ) )
    452     {
    453       delete_category( $row['id'] );
    454     }
    455   }
     465  if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL';
     466  else                           $query.= ' AND id_uppercat = '.$id_uppercat;
     467  $query.= ' AND dir IS NOT NULL'; // virtual categories not taken
     468  $query.= ';';
     469  $result = mysql_query( $query );
     470  while ( $row = mysql_fetch_array( $result ) )
     471  {
     472    $database_dirs[$row['id']] = $row['dir'];
     473  }
     474 
     475  // 3. we have to remove the categories of the database not present anymore
     476  foreach ( $database_dirs as $id => $dir ) {
     477    if ( !in_array( $dir, $xml_dirs ) ) delete_category( $id );
     478  }
     479
     480  // array of new categories to insert
     481  $inserts = array();
     482 
     483  foreach ( $xml_dirs as $xml_dir ) {
     484    // 5. Is the category already existing ? we create a subcat if not
     485    //    existing
     486    $category_id = array_search( $xml_dir, $database_dirs );
     487    if ( !is_numeric( $category_id ) )
     488    {
     489      $name = str_replace( '_', ' ', $xml_dir );
     490
     491      $value = "('".$xml_dir."','".$name."',".$site_id;
     492      if ( !is_numeric( $id_uppercat ) ) $value.= ',NULL';
     493      else                               $value.= ','.$id_uppercat;
     494      $value.= ",'undef'";
     495      $value.= ')';
     496      array_push( $inserts, $value );
     497    }
     498  }
     499
     500  // we have to create the category
     501  if ( count( $inserts ) > 0 )
     502  {
     503    $query = 'INSERT INTO '.PREFIX_TABLE.'categories';
     504    $query.= ' (dir,name,site_id,id_uppercat,uppercats) VALUES ';
     505    $query.= implode( ',', $inserts );
     506    $query.= ';';
     507    mysql_query( $query );
     508    // updating uppercats field
     509    $query = 'UPDATE '.PREFIX_TABLE.'categories';
     510    $query.= ' SET uppercats = ';
     511    if ( $uppercats != '' ) $query.= "CONCAT('".$uppercats."',',',id)";
     512    else                    $query.= 'id';
     513    $query.= ' WHERE id_uppercat ';
     514    if (!is_numeric($id_uppercat)) $query.= 'IS NULL';
     515    else                           $query.= '= '.$id_uppercat;
     516    $query.= ';';
     517    mysql_query( $query );
     518  }
     519
     520  // Recursive call on the sub-categories (not virtual ones)
     521  $query = 'SELECT id,dir';
     522  $query.= ' FROM '.PREFIX_TABLE.'categories';
     523  $query.= ' WHERE site_id = '.$site_id;
     524  if (!is_numeric($id_uppercat)) $query.= ' AND id_uppercat IS NULL';
     525  else                           $query.= ' AND id_uppercat = '.$id_uppercat;
     526  $query.= ' AND dir IS NOT NULL'; // virtual categories not taken
     527  $query.= ';';
     528  $result = mysql_query( $query );
     529  while ( $row = mysql_fetch_array( $result ) )
     530  {
     531    $database_dirs[$row['dir']] = $row['id'];
     532  }
     533  foreach ( $temp_dirs as $temp_dir ) {
     534    $dir = getAttribute( $temp_dir, 'name' );
     535    $id_uppercat = $database_dirs[$dir];
     536    $output.= insert_remote_category( $temp_dir, $site_id,
     537                                      $id_uppercat,$level+1 );
     538  }
     539
     540  if ( is_numeric( $id_uppercat ) ) $output.= '</div>';
    456541
    457542  return $output;
    458543}
    459        
     544
    460545// insert_remote_image searchs the "root" node of the xml_dir given and
    461546// insert the contained pictures if the are not in the database yet.
     
    466551  $output = '';
    467552  $root = getChild( $xml_dir, 'root' );
    468   $pictures = array();
     553
     554  $fs_pictures = array();
    469555  $xml_pictures = getChildren( $root, 'picture' );
    470   for ( $j = 0; $j < sizeof( $xml_pictures ); $j++ )
    471   {
    472     //<picture file="albatros.jpg" tn_ext="png" date="2002-04-14"
    473     //  filesize="35" width="640" height="480" />
    474     $file     = getAttribute( $xml_pictures[$j], 'file' );
    475     $tn_ext   = getAttribute( $xml_pictures[$j], 'tn_ext' );
    476     $date     = getAttribute( $xml_pictures[$j], 'date' );
    477     $filesize = getAttribute( $xml_pictures[$j], 'filesize' );
    478     $width    = getAttribute( $xml_pictures[$j], 'width' );
    479     $height   = getAttribute( $xml_pictures[$j], 'height' );
    480                        
    481     $pictures[$j] = $file;
    482                        
     556  foreach ( $xml_pictures as $xml_picture ) {
     557    array_push( $fs_pictures, getAttribute( $xml_picture, 'file' ) );
     558  }
     559 
     560  // we have to delete all the images from the database that are not in the
     561  // directory anymore (not in the XML anymore)
     562  $query = 'SELECT id,file';
     563  $query.= ' FROM '.PREFIX_TABLE.'images';
     564  $query.= ' WHERE storage_category_id = '.$category_id;
     565  $query.= ';';
     566  $result = mysql_query( $query );
     567  while ( $row = mysql_fetch_array( $result ) )
     568  {
     569    if ( !in_array( $row['file'], $fs_pictures ) )
     570    {
     571      $output.= $row['file'];
     572      $output.= ' <span style="font-weight:bold;">';
     573      $output.= $lang['update_disappeared'].'</span><br />';
     574      delete_image( $row['id'] );
     575    }
     576  }
     577
     578  $database_pictures = array();
     579  $query = 'SELECT file';
     580  $query.= ' FROM '.PREFIX_TABLE.'images';
     581  $query.= ' WHERE storage_category_id = '.$category_id;
     582  $query.= ';';
     583  $result = mysql_query( $query );
     584  while ( $row = mysql_fetch_array( $result ) )
     585  {
     586    array_push( $database_pictures, $row['file'] );
     587  }
     588
     589  $inserts = array();
     590  $xml_pictures = getChildren( $root, 'picture' );
     591  foreach ( $xml_pictures as $xml_picture ) {
     592    // <picture file="albatros.jpg" tn_ext="png" filesize="35" width="640"
     593    // height="480" />
     594    $file = getAttribute( $xml_picture, 'file' );
     595
    483596    // is the picture already existing in the database ?
    484     $query = 'SELECT id,tn_ext';
    485     $query.= ' FROM '.PREFIX_TABLE.'images';
    486     $query.= ' WHERE storage_category_id = '.$category_id;
    487     $query.= " AND file = '".$file."'";
    488     $query.= ';';
    489     $result = mysql_query( $query );
    490     $query = '';
    491     if ( mysql_num_rows( $result ) == 0 )
    492     {
    493       $query = 'INSERT INTO '.PREFIX_TABLE.'images';
    494       $query.= ' (file,storage_category_id,date_available,tn_ext';
    495       $query.= ',filesize,width,height)';
    496       $query.= ' VALUES (';
    497       $query.= "'".$file."'";
    498       $query.= ",'".$category_id."'";
    499       $query.= ",'".$date."'";
    500       $query.= ",'".$tn_ext."'";
    501       $query.= ",'".$filesize."'";
    502       $query.= ",'".$width."'";
    503       $query.= ",'".$height."'";
    504       $query.= ')';
    505       $query.= ';';
    506       mysql_query( $query );
    507       // retrieving the id of newly inserted picture
    508       $query = 'SELECT id';
    509       $query.= ' FROM '.PREFIX_TABLE.'images';
    510       $query.= ' WHERE storage_category_id = '.$category_id;
    511       $query.= " AND file = '".$file."'";
    512       $query.= ';';
    513       list( $image_id ) = mysql_fetch_array( mysql_query( $query ) );
    514       // adding the link between this picture and its storage category
    515       $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
    516       $query.= ' (image_id,category_id) VALUES ';
    517       $query.= ' ('.$image_id.','.$category_id.')';
    518       $query.= ';';
    519       mysql_query( $query );
    520 
     597    if ( !in_array( $file, $database_pictures ) )
     598    {
     599      $tn_ext = getAttribute( $xml_picture, 'tn_ext' );
     600      // (file, storage_category_id, date_available, tn_ext, filesize,
     601      // width, height)
     602      $value = '(';
     603      $value.= "'".$file."'";
     604      $value.= ','.$category_id;
     605      $value.= ",'".date( 'Y-m-d' )."'";
     606      $value.= ",'".$tn_ext."'";
     607      $value.= ','.getAttribute( $xml_picture, 'filesize' );
     608      $value.= ','.getAttribute( $xml_picture, 'width' );
     609      $value.= ','.getAttribute( $xml_picture, 'height' );
     610      $value.= ')';
     611
     612      $count_new++;
    521613      $output.= $file;
    522614      $output.= ' <span style="font-weight:bold;">';
    523615      $output.= $lang['update_research_added'].'</span>';
    524       $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')<br />';
    525 
    526       $count_new++;
    527     }
    528     else
    529     {
    530       // is the tn_ext the same in the xml file and in the database ?
    531       $row = mysql_fetch_array( $result );
    532       if ( $row['tn_ext'] != $tn_ext )
    533       {
    534         $query = 'UPDATE '.PREFIX_TABLE.'images';
    535         $query.= ' SET';
    536         $query.= " tn_ext = '".$tn_ext."'";
    537         $query.= ' WHERE storage_category_id = '.$category_id;
    538         $query.= " AND file = '".$file."'";
    539         $query.= ';';
    540       }
    541     }
    542     // execution of the query
    543     if ( $query != '' )
    544     {
    545       mysql_query( $query );
    546     }
    547   }
    548   // we have to remove the pictures of the database not present in the xml file
    549   // (ie deleted from the picture storage server)
    550   $query = 'SELECT id,file';
    551   $query.= ' FROM '.PREFIX_TABLE.'images';
    552   $query.= ' WHERE storage_category_id = '.$category_id;
    553   $query.= ';';
    554   $result = mysql_query( $query );
    555   while ( $row = mysql_fetch_array( $result ) )
    556   {
    557     // is the file in the xml file ?
    558     if ( !in_array( $row['file'], $pictures ) )
    559     {
    560       delete_image( $row['id'] );
    561     }
    562   }
     616      $output.= ' ('.$lang['update_research_tn_ext'].' '.$tn_ext.')';
     617      $output.= '<br />';
     618      array_push( $inserts, $value );
     619    }
     620  }
     621
     622  if ( count( $inserts ) > 0 )
     623  {
     624    // inserts all found pictures
     625    $query = 'INSERT INTO '.PREFIX_TABLE.'images';
     626    $query.= ' (file,storage_category_id,date_available,tn_ext';
     627    $query.= ',filesize,width,height)';
     628    $query.= ' VALUES ';
     629    $query.= implode( ',', $inserts );
     630    $query.= ';';
     631    mysql_query( $query );
     632
     633    // what are the ids of the pictures in the $category_id ?
     634    $ids = array();
     635
     636    $query = 'SELECT id';
     637    $query.= ' FROM '.PREFIX_TABLE.'images';
     638    $query.= ' WHERE storage_category_id = '.$category_id;
     639    $query.= ';';
     640    $result = mysql_query( $query );
     641    while ( $row = mysql_fetch_array( $result ) )
     642    {
     643      array_push( $ids, $row['id'] );
     644    }
     645
     646    // recreation of the links between this storage category pictures and
     647    // its storage category
     648    $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
     649    $query.= ' WHERE category_id = '.$category_id;
     650    $query.= ' AND image_id IN ('.implode( ',', $ids ).')';
     651    $query.= ';';
     652    mysql_query( $query );
     653
     654    $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     655    $query.= '(category_id,image_id) VALUES ';
     656    foreach ( $ids as $num => $image_id ) {
     657      if ( $num > 0 ) $query.= ',';
     658      $query.= '('.$category_id.','.$image_id.')';
     659    }
     660    $query.= ';';
     661    mysql_query( $query );
     662  }
     663
    563664  return $output;
    564665}
     
    570671templatize_array( $tpl, 'lang', $sub );
    571672$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
    572 //-------------------------------------------------------- categories structure
    573 $page['plain_structure'] = get_plain_structure();
    574673//-------------------------------------------- introduction : choices of update
    575674// Display choice if "update" var is not specified
    576 check_cat_id( $_GET['update'] );
    577 if ( !isset( $_GET['update'] )
    578      and !( isset( $page['cat'] )
    579             or $_GET['update'] == 'cats'
    580             or $_GET['update'] == 'all' ) )
     675if (!isset( $_GET['update'] ))
    581676{
    582677  $vtp->addSession( $sub, 'introduction' );
     
    592687else
    593688{
     689  check_cat_id( $_GET['update'] );
     690  $start = get_moment();
    594691  $count_new = 0;
    595692  $count_deleted = 0;
     
    603700    $categories = insert_local_category( 'NULL' );
    604701  }
     702  $end = get_moment();
     703  echo get_elapsed_time( $start, $end ).' for update <br />';
    605704  $vtp->setVar( $sub, 'local_update.categories', $categories );
    606705  $vtp->setVar( $sub, 'local_update.count_new', $count_new );
     
    614713  $count_deleted = 0;
    615714  $vtp->addSession( $sub, 'remote_update' );
    616 
     715 
     716  $start = get_moment();
    617717  remote_images();
     718  $end = get_moment();
     719  echo get_elapsed_time( $start, $end ).' for remote_images<br />';
     720 
    618721  $vtp->setVar( $sub, 'remote_update.count_new', $count_new );
    619722  $vtp->setVar( $sub, 'remote_update.count_deleted', $count_deleted );
     
    622725}
    623726//---------------------------------------- update informations about categories
    624 update_category( 'all' );
     727if ( isset( $_GET['update'] )
     728     or isset( $page['cat'] )
     729     or @is_file( './listing.xml' ) )
     730{
     731  $start = get_moment();
     732  update_category( 'all' );
     733  $end = get_moment();
     734  echo get_elapsed_time( $start, $end ).' for update_category( all )<br />';
     735
     736  $start = get_moment();
     737  synchronize_all_users();
     738  $end = get_moment();
     739  echo get_elapsed_time( $start, $end ).' for synchronize_all_users<br />';
     740}
    625741//----------------------------------------------------------- sending html code
    626742$vtp->Parse( $handle , 'sub', $sub );
  • trunk/admin/user_list.php

    r226 r345  
    5959  $row = mysql_fetch_array( mysql_query( $query ) );
    6060  // confirm user deletion ?
    61   if ( $_GET['confirm'] != 1 )
     61  if ( !isset( $_GET['confirm'] ) )
    6262  {
    6363    $vtp->addSession( $sub, 'deletion' );
     
    110110  $action = './admin.php?'.$_SERVER['QUERY_STRING'];
    111111  $vtp->setVar( $sub, 'add_user.form_action', $action );
    112   $vtp->setVar( $sub, 'add_user.f_username', $_POST['username'] );
     112  if (isset( $_POST['username']))
     113          $vtp->setVar( $sub, 'add_user.f_username', $_POST['username'] );
    113114  $vtp->closeSession( $sub, 'add_user' );
    114115 
     
    150151    $vtp->addSession( $sub, 'user' );
    151152    // checkbox for mail management if the user has a mail address
    152     if ( $row['mail_address'] != '' and $row['username'] != 'guest' )
     153    if ( isset( $row['mail_address'] ) and $row['username'] != 'guest' )
    153154    {
    154155      $vtp->addSession( $sub, 'checkbox' );
     
    230231    while ( $row = mysql_fetch_array( $result ) )
    231232    {
    232       if ( $_POST['mail-'.$row['id']] == 1 )
     233      if ( isset( $_POST['mail-'.$row['id']] ) )
    233234        array_push( $mails, $row['mail_address'] );
    234235    }
  • trunk/admin/user_modify.php

    r226 r345  
    4040$page['username'] = $row['username'];
    4141$page['status'] = $row['status'];
     42if ( !isset( $row['mail_address'] ) ) $row['mail_address'] = '';
    4243$page['mail_address'] = $row['mail_address'];
    4344// user is not modifiable if :
     
    6364  // shall we use a new password and overwrite the old one ?
    6465  $use_new_password = false;
    65   if ( $_POST['use_new_pwd'] == 1)
    66   {
    67     $use_new_password = true;
    68   }
     66  if ( isset( $_POST['use_new_pwd'] ) ) $use_new_password = true;
    6967  // if we try to update the webmaster infos, we have to set the status to
    7068  // 'admin'
     
    8987  {
    9088    $dissociate = 'dissociate-'.$row['id'];
    91     if ( $_POST[$dissociate] == 1 )
     89    if ( isset( $_POST[$dissociate] ) )
    9290    {
    9391      $query = 'DELETE FROM '.PREFIX_TABLE.'user_group';
     
    104102  $query.= ';';
    105103  mysql_query( $query );
     104  // synchronize category informations for this user
     105  synchronize_user( $_GET['user_id'] );
    106106}
    107107//-------------------------------------------------------------- errors display
     
    125125  $vtp->setVar( $sub, 'confirmation.url', $url );
    126126  $vtp->closeSession( $sub, 'confirmation' );
    127   if ( $use_new_pwd )
     127  if ( $use_new_password )
    128128  {
    129129    $vtp->addSession( $sub, 'password_updated' );
  • trunk/admin/user_perm.php

    r226 r345  
    5353  }
    5454  check_favorites( $_GET['user_id'] );
     55  synchronize_user( $_GET['user_id'] );
    5556  $vtp->addSession( $sub, 'confirmation' );
    5657  $url = './admin.php?page=user_list';
     
    5960}
    6061//---------------------------------------------------------------- form display
    61 $restrictions = get_restrictions( $_GET['user_id'], $page['user_status'],
     62$restrictions = get_user_restrictions( $_GET['user_id'], $page['user_status'],
    6263                                  false, false );
    6364$action = './admin.php?page=user_perm&amp;user_id='.$_GET['user_id'];
  • trunk/admin/waiting.php

    r226 r345  
    117117  $vtp->setVar( $sub, 'picture.file', $row['file'] );
    118118  // is there an existing associated thumnail ?
    119   if ( $row['tn_ext'] != '' )
     119  if ( isset( $row['tn_ext'] ) and $row['tn_ext'] != '' )
    120120  {
    121121    $vtp->addSession( $sub, 'thumbnail' );
  • trunk/category.php

    r228 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
    19 // determine the initial instant to indicate the generation time of this page
    20 $t1 = explode( ' ', microtime() );
    21 $t2 = explode( '.', $t1[0] );
    22 $t2 = $t1[1].'.'.$t2[1];
    23 //----------------------------------------------------------- personnal include
    24 include_once( './include/init.inc.php' );
     19//----------------------------------------------------------- include
     20$phpwg_root_path = './';
     21include_once( $phpwg_root_path.'common.php' );
    2522//---------------------------------------------------------------------- logout
    26 if ( $_GET['act'] == 'logout' and isset( $_COOKIE['id'] ) )
     23if ( isset( $_GET['act'] )
     24     and $_GET['act'] == 'logout'
     25     and isset( $_COOKIE['id'] ) )
    2726{
    2827  // cookie deletion if exists
     
    3534}
    3635//-------------------------------------------------- access authorization check
    37 // creating the plain structure : array of all the available categories and
    38 // their relative informations, see the definition of the function
    39 // get_plain_structure for further details.
    40 $page['plain_structure'] = get_plain_structure();
    41 
    42 check_cat_id( $_GET['cat'] );
     36if ( isset( $_GET['cat'] ) ) check_cat_id( $_GET['cat'] );
    4337check_login_authorization();
    4438if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
     
    4741}
    4842//-------------------------------------------------------------- initialization
     43// detection of the start picture to display
     44if ( !isset( $_GET['start'] )
     45     or !is_numeric( $_GET['start'] )
     46     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
     47  $page['start'] = 0;
     48else
     49  $page['start'] = $_GET['start'];
     50
     51initialize_category();
     52
    4953// creation of the array containing the cat ids to expand in the menu
    5054// $page['tab_expand'] contains an array with the category ids
     
    5761    if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
    5862  }
    59   if ( is_numeric( $page['cat'] ) )
    60   {
    61     // the category displayed (in the URL cat=23) must be seen in the menu ->
    62     // parent categories must be expanded
    63     $parent = $page['plain_structure'][$page['cat']]['id_uppercat'];
    64     while ( $parent != '' )
    65     {
    66       array_push( $page['tab_expand'], $parent );
    67       $parent = $page['plain_structure'][$parent]['id_uppercat'];
    68     }
    69   }
    70   $page['expand'] = implode( ',', $page['tab_expand'] );
    71 }
     63}
     64if ( isset($page['cat']) && is_numeric( $page['cat'] ) )
     65{
     66  // the category displayed (in the URL cat=23) must be seen in the menu ->
     67  // parent categories must be expanded
     68  $uppercats = explode( ',', $page['uppercats'] );
     69  foreach ( $uppercats as $uppercat ) {
     70    array_push( $page['tab_expand'], $uppercat );
     71  }
     72}
     73$page['tab_expand'] = array_unique( $page['tab_expand'] );
     74$page['expand'] = implode( ',', $page['tab_expand'] );
    7275// in case of expanding all authorized cats
    7376// The $page['expand'] equals 'all' and
    7477// $page['tab_expand'] contains all the authorized cat ids
    75 if ( $user['expand'] or $_GET['expand'] == 'all' )
     78if ( $user['expand']
     79     or ( isset( $_GET['expand'] ) and $_GET['expand'] == 'all' ) )
    7680{
    7781  $page['tab_expand'] = array();
    7882  $page['expand'] = 'all';
    79 }
    80 // detection of the start picture to display
    81 if ( !isset( $_GET['start'] )
    82      or !is_numeric( $_GET['start'] )
    83      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
    84 {
    85   $page['start'] = 0;
    86 }
    87 else
    88 {
    89   $page['start'] = $_GET['start'];
    9083}
    9184// Sometimes, a "num" is provided in the URL. It is the number
     
    9386// We have to find the right $page['start'] that show the num picture
    9487// in this category
    95 if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
     88if ( isset( $_GET['num'] )
     89     and is_numeric( $_GET['num'] )
     90     and $_GET['num'] >= 0 )
    9691{
    9792  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
     
    9994}
    10095// creating the structure of the categories (useful for displaying the menu)
    101 $page['structure'] = create_structure( '', $user['restrictions'] );
     96// creating the plain structure : array of all the available categories and
     97// their relative informations, see the definition of the function
     98// get_user_plain_structure for further details.
     99$page['plain_structure'] = get_user_plain_structure();
     100$page['structure'] = create_user_structure( '' );
    102101$page['structure'] = update_structure( $page['structure'] );
    103 initialize_category();
     102
    104103//----------------------------------------------------- template initialization
    105 $vtp = new VTemplate;
     104
     105//
     106// Start output of page
     107//
     108$title = $page['title'];
     109include('include/page_header.php');
     110
    106111$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
    107112initialize_template();
     
    109114  'categories','hint_category','sub-cat','images_available','total',
    110115  'title_menu','nb_image_category','send_mail','title_send_mail',
    111   'generation_time','connected_user','recent_image','days','generation_time',
     116  'connected_user','recent_image','days',
    112117  'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint',
    113118  'most_visited_cat','recent_cat','recent_cat_hint','upload_picture',
     
    115120templatize_array( $tpl, 'lang', $handle );
    116121
    117 $tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
     122$tpl = array( 'mail_webmaster','webmaster','top_number');
    118123templatize_array( $tpl, 'conf', $handle );
    119124
     
    121126templatize_array( $tpl, 'user', $handle );
    122127
    123 $tpl = array( 'title','navigation_bar','cat_comment','cat_nb_images' );
     128$tpl = array( 'navigation_bar','cat_comment','cat_nb_images' );
    124129templatize_array( $tpl, 'page', $handle );
    125130
     
    128133$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
    129134$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
    130 $nb_total_pictures = count_images( $page['structure'] );
     135$nb_total_pictures = count_user_total_images();
    131136$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
     137
    132138//------------------------------------------------------------- categories menu
     139$vtp->setVar( $handle, 'home_url', add_session_id( 'category.php' ) );
    133140// normal categories
    134141foreach ( $page['structure'] as $category ) {
     
    144151  // searching the number of favorite picture
    145152  $query = 'SELECT COUNT(*) AS count';
    146   $query.= ' FROM '.PREFIX_TABLE.'favorites';
     153  $query.= ' FROM '.FAVORITES_TABLE;
    147154  $query.= ' WHERE user_id = '.$user['id'].';';
    148155  $result = mysql_query( $query );
     
    182189  // customization link
    183190  $vtp->addSession( $handle, 'summary' );
    184   $url = './profile.php?cat='.$page['cat'];
    185   $url.= '&amp;expand='.$page['expand'];
    186   if ( $page['cat'] == 'search' )
     191  $url = './profile.php';
     192  if (isset($page['cat']) && isset($page['expand']))
     193        $url.='?cat='.$page['cat'].'&amp;expand='.$page['expand'];
     194  if ( isset($page['cat']) && $page['cat'] == 'search' )
    187195  {
    188196    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
     
    254262  $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
    255263  $query.= ',storage_category_id';
    256   $query.= ' FROM '.PREFIX_TABLE.'images AS i';
    257   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
     264  $query.= ' FROM '.IMAGES_TABLE.' AS i';
     265  $query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id';
    258266  $query.= $page['where'];
    259267  $query.= $conf['order_by'];
     
    271279  {
    272280    // retrieving the storage dir of the picture
    273     if ( $array_cat_directories[$row['storage_category_id']] == '' )
     281    if ( !isset($array_cat_directories[$row['storage_category_id']]))
    274282    {
    275283      $array_cat_directories[$row['storage_category_id']] =
     
    280288    $file = get_filename_wo_extension( $row['file'] );
    281289    // name of the picture
    282     if ( $row['name'] != '' ) $name = $row['name'];
    283     else                      $name = str_replace( '_', ' ', $file );
     290    if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name'];
     291    else $name = str_replace( '_', ' ', $file );
    284292
    285293    if ( $page['cat'] == 'search' )
     
    321329      $vtp->addSession( $handle, 'nb_comments' );
    322330      $query = 'SELECT COUNT(*) AS nb_comments';
    323       $query.= ' FROM '.PREFIX_TABLE.'comments';
    324       $query.= ' WHERE image_id = '.$row['id'];
     331      $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id'];
    325332      $query.= " AND validated = 'true'";
    326333      $query.= ';';
     
    351358elseif ( ( isset( $page['cat'] )
    352359           and is_numeric( $page['cat'] )
    353            and $page['cat_nb_images'] == 0 )
    354          or $_GET['cat'] == '' )
     360           and $page['cat_nb_images'] == 0
     361           and $page['plain_structure'][$page['cat']]['nb_sub_categories'] > 0)
     362         or (!isset($_GET['cat'])))
    355363{
    356364  $vtp->addSession( $handle, 'thumbnails' );
    357365  $vtp->addSession( $handle, 'line' );
    358366
    359   $subcats = get_non_empty_subcat_ids( $page['cat'] );
     367  $subcats=array();
     368  if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] );
     369  else                     $subcats = get_non_empty_subcat_ids( '' );
    360370  $cell_number = 1;
    361371  $i = 0;
     
    369379    // searching the representative picture of the category
    370380    $query = 'SELECT representative_picture_id';
    371     $query.= ' FROM '.PREFIX_TABLE.'categories';
    372     $query.= ' WHERE id = '.$non_empty_id;
     381    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id;
     382    $query.= ';';
    373383    $row = mysql_fetch_array( mysql_query( $query ) );
    374384   
    375385    $query = 'SELECT file,tn_ext,storage_category_id';
    376     $query.= ' FROM '.PREFIX_TABLE.'images';
    377     $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
     386    $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
    378387    $query.= ' WHERE category_id = '.$non_empty_id;
     388    $query.= ' AND id = image_id';
    379389    // if the category has a representative picture, this is its thumbnail
    380     // tha will be displayed !
    381     if ( $row['representative_picture_id'] != '' )
     390    // that will be displayed !
     391    if ( isset( $row['representative_picture_id'] ) )
    382392      $query.= ' AND id = '.$row['representative_picture_id'];
    383393    else
     
    398408
    399409    $url_link = './category.php?cat='.$subcat_id;
    400     if ( !in_array( $page['cat'], $page['tab_expand'] ) )
     410    if ( isset($page['cat'])&& !in_array( $page['cat'], $page['tab_expand'] ) )
    401411    {
    402412      array_push( $page['tab_expand'], $page['cat'] );
     
    460470                  get_cat_display_name( $page['cat_name'], ' - ',
    461471                                        'font-style:italic;' ) );
     472    // upload a picture in the category
     473    if ( $page['cat_site_id'] == 1
     474         and $conf['upload_available']
     475         and $page['cat_uploadable'] )
     476    {
     477      $vtp->addSession( $handle, 'upload' );
     478      $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
     479      $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
     480      $vtp->closeSession( $handle, 'upload' );
     481    }
    462482  }
    463483  else
     
    465485    $vtp->setVar( $handle, 'cat_infos.cat_name', $page['title'] );
    466486  }
    467   // upload a picture in the category
    468   if ( $page['cat_site_id'] == 1
    469        and $conf['upload_available']
    470        and $page['cat_uploadable'] )
    471   {
    472     $vtp->addSession( $handle, 'upload' );
    473     $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
    474     $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
    475     $vtp->closeSession( $handle, 'upload' );
    476   }
     487 
    477488  $vtp->closeSession( $handle, 'cat_infos' );
    478489}
     
    480491pwg_log( 'category', $page['title'] );
    481492mysql_close();
    482 //------------------------------------------------------------- generation time
    483 $time = get_elapsed_time( $t2, get_moment() );
    484 $vtp->setGlobalVar( $handle, 'time', $time );
    485493//----------------------------------------------------------- html code display
    486494$code = $vtp->Display( $handle, 0 );
    487495echo $code;
     496
     497include('include/page_tail.php');
    488498?>
  • trunk/comments.php

    r231 r345  
    1818 ***************************************************************************/
    1919
    20 include_once( './include/init.inc.php' );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
     23
    2124//------------------------------------------------------------------- functions
    2225function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
     
    4750    $category_id = $subrow['category_id'];
    4851
    49     if ( $array_cat_directories[$category_id] == '' )
     52    if ( !isset($array_cat_directories[$category_id]))
    5053    {
    5154      $array_cat_directories[$category_id] =
     
    134137}
    135138//----------------------------------------------------- template initialization
    136 $vtp = new VTemplate;
     139//
     140// Start output of page
     141//
     142$title= $lang['title_comments'];
     143include('include/page_header.php');
     144
    137145$handle = $vtp->Open( './template/'.$user['template'].'/comments.vtp' );
    138146initialize_template();
    139147$tpl = array( 'title_comments','stats_last_days','search_return_main_page' );
    140148templatize_array( $tpl, 'lang', $handle );
    141 $vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] );
    142149//--------------------------------------------------- number of days to display
    143 if ( isset( $_GET['last_days'] ) ) define( "MAX_DAYS", $_GET['last_days'] );
    144 else                               define( "MAX_DAYS", 0 );
     150if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
     151else                               define( 'MAX_DAYS', 0 );
    145152//----------------------------------------- non specific section initialization
    146153$array_cat_directories = array();
     
    169176$query.= ' WHERE c.image_id = ic.image_id';
    170177$query.= ' AND date > '.$maxtime;
     178$query.= " AND validated = 'true'";
    171179// we must not show pictures of a forbidden category
    172 $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    173 if ( count( $restricted_cats ) > 0 )
     180if ( $user['forbidden_categories'] != '' )
    174181{
    175   $query.= ' AND category_id NOT IN (';
    176   foreach ( $restricted_cats as $i => $restricted_cat ) {
    177     if ( $i > 0 ) $query.= ',';
    178     $query.= $restricted_cat;
    179   }
    180   $query.= ')';
     182  $query.= ' AND category_id NOT IN ';
     183  $query.= '('.$user['forbidden_categories'].')';
    181184}
    182185$query.= ' ORDER BY ic.image_id DESC';
    183186$query.= ';';
    184187$result = mysql_query( $query );
    185 display_pictures( $result, $maxtime, $restricted_cats );
     188display_pictures( $result, $maxtime, $user['restrictions'] );
    186189//----------------------------------------------------------- html code display
    187190$code = $vtp->Display( $handle, 0 );
    188191echo $code;
     192include('include/page_tail.php');
    189193?>
  • trunk/identification.php

    r104 r345  
    1818 ***************************************************************************/
    1919
    20 //----------------------------------------------------------- personnal include
    21 include_once( "./include/init.inc.php" );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
     23
    2224//-------------------------------------------------------------- identification
    2325$errors = array();
     
    2628  // retrieving the encrypted password of the login submitted
    2729  $query = 'SELECT password';
    28   $query.= ' FROM '.PREFIX_TABLE.'users';
     30  $query.= ' FROM '.USERS_TABLE;
    2931  $query.= " WHERE username = '".$_POST['login']."';";
    3032  $row = mysql_fetch_array( mysql_query( $query ) );
     
    4446}
    4547//----------------------------------------------------- template initialization
    46 $vtp = new VTemplate;
     48//
     49// Start output of page
     50//
     51$title = $lang['ident_page_title'];
     52include('include/page_header.php');
     53
    4754$handle = $vtp->Open( './template/default/identification.vtp' );
    4855// language
    49 $vtp->setGlobalVar( $handle, 'ident_page_title', $lang['ident_page_title'] );
    5056$vtp->setGlobalVar( $handle, 'ident_title',      $lang['ident_title'] );
    5157$vtp->setGlobalVar( $handle, 'login',            $lang['login'] );
     
    7480//------------------------------------------------------------------ users list
    7581// retrieving all the users login
    76 $query = 'select username from '.PREFIX_TABLE.'users;';
     82$query = 'select username from '.USERS_TABLE.';';
    7783$result = mysql_query( $query );
    7884if ( mysql_num_rows ( $result ) < $conf['max_user_listbox'] )
     
    110116$code = $vtp->Display( $handle, 0 );
    111117echo $code;
     118include('include/page_tail.php');
    112119?>
  • trunk/include/config.inc.php

    r215 r345  
    33 *                              config.inc.php                             *
    44 *                            -------------------                          *
    5  *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
     5 *   application   : PhpWebGallery 1.4 <http://phpwebgallery.net>          *
    66 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
    77 *                                                                         *
     
    1717 *                                                                         *
    1818 ***************************************************************************/
    19 unset( $conf, $page, $user, $lang );
    20 $conf = array();
    21 $page = array();
    22 $user = array();
    23 $lang = array();
    24 
    25 include_once( PREFIX_INCLUDE.'./include/functions.inc.php' );
    26 include_once( PREFIX_INCLUDE.'./include/vtemplate.class.php' );
    2719// How to change the order of display for images in a category ?
    2820//
     
    4537$conf['slideshow_period']   = array(2,5,10);
    4638$conf['last_days']          = array(1,2,3,10,30,365);
    47 $conf['version']            = 'devel';
     39$conf['version']            = '1.4 - devel';
    4840$conf['site_url']           = 'http://www.phpwebgallery.net';
    4941$conf['forum_url']          = 'http://forum.phpwebgallery.net';
     
    5244$conf['top_number']         = 10;
    5345$conf['anti-flood_time']    = 60; // seconds between 2 comments : 0 to disable
     46$conf['max_LOV_categories'] = 50;
    5447
    55 database_connection();
    56 // rertieving the configuration informations for site
    57 // $infos array is used to know the fields to retrieve in the table "config"
    58 // Each field becomes an information of the array $conf.
    59 // Example :
    60 //            prefix_thumbnail --> $conf['prefix_thumbnail']
    61 $infos = array( 'prefix_thumbnail', 'webmaster', 'mail_webmaster', 'access',
    62                 'session_id_size', 'session_keyword', 'session_time',
    63                 'max_user_listbox', 'show_comments', 'nb_comment_page',
    64                 'upload_available', 'upload_maxfilesize', 'upload_maxwidth',
    65                 'upload_maxheight', 'upload_maxwidth_thumbnail',
    66                 'upload_maxheight_thumbnail','log','comments_validation',
    67                 'comments_forall','authorize_cookies','mail_notification' );
    68 
    69 $query  = 'SELECT ';
    70 foreach ( $infos as $i => $info ) {
    71   if ( $i > 0 ) $query.= ',';
    72   $query.= $info;
    73 }
    74 $query.= ' FROM '.PREFIX_TABLE.'config;';
    75 
    76 $row = mysql_fetch_array( mysql_query( $query ) );
    77 
    78 // affectation of each field of the table "config" to an information of the
    79 // array $conf.
    80 foreach ( $infos as $info ) {
    81   $conf[$info] = $row[$info];
    82   // If the field is true or false, the variable is transformed into a boolean
    83   // value.
    84   if ( $row[$info] == 'true' or $row[$info] == 'false' )
    85   {
    86     $conf[$info] = get_boolean( $row[$info] );
    87   }
    88 }
    8948?>
  • trunk/include/functions.inc.php

    r235 r345  
    11<?php
    2 // +-----------------------------------------------------------------------+
    3 // |                           functions.inc.php                           |
    4 // +-----------------------------------------------------------------------+
    5 // | application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          |
    6 // | author        : Pierrick LE GALL <pierrick@z0rglub.com>               |
    7 // +-----------------------------------------------------------------------+
    8 // | file          : $RCSfile$
    9 // | tag           : $Name$
    10 // | last update   : $Date$
    11 // | revision      : $Revision$
    12 // +-----------------------------------------------------------------------+
    13 // | This program is free software; you can redistribute it and/or modify  |
    14 // | it under the terms of the GNU General Public License as published by  |
    15 // | the Free Software Foundation;                                         |
    16 // +-----------------------------------------------------------------------+
    17 
     2/***************************************************************************
     3 *                             functions.inc.php                           *
     4 *                            -------------------                          *
     5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
     6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
     7 *                                                                         *
     8 *   $Id$
     9 *                                                                         *
     10 ***************************************************************************
     11
     12 ***************************************************************************
     13 *                                                                         *
     14 *   This program is free software; you can redistribute it and/or modify  *
     15 *   it under the terms of the GNU General Public License as published by  *
     16 *   the Free Software Foundation;                                         *
     17 *                                                                         *
     18 ***************************************************************************/
    1819include( PREFIX_INCLUDE.'./include/functions_user.inc.php' );
    1920include( PREFIX_INCLUDE.'./include/functions_session.inc.php' );
     
    167168}
    168169
    169 // get_dirs retourne un tableau contenant tous les sous-répertoires d'un
    170 // répertoire
    171 function get_dirs( $rep )
    172 {
    173   $sub_rep = array();
    174 
    175   if ( $opendir = opendir ( $rep ) )
     170/**
     171 * returns an array contening sub-directories
     172 *
     173 * @param string $dir
     174 * @return array
     175 */
     176function get_dirs( $directory )
     177{
     178  $sub_dirs = array();
     179
     180  if ( $opendir = opendir( $directory ) )
    176181  {
    177182    while ( $file = readdir ( $opendir ) )
    178183    {
    179       if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) )
     184      if ( $file != '.' and $file != '..' and is_dir ( $directory.'/'.$file ) )
    180185      {
    181         array_push( $sub_rep, $file );
     186        array_push( $sub_dirs, $file );
    182187      }
    183188    }
    184189  }
    185   return $sub_rep;
     190  return $sub_dirs;
    186191}
    187192
     
    266271}
    267272
    268 // get_themes retourne un tableau contenant tous les "template - couleur"
    269 function get_themes( $theme_dir )
    270 {
    271   $themes = array();
    272   $main_themes = get_dirs( $theme_dir );
    273   for ( $i = 0; $i < sizeof( $main_themes ); $i++ )
    274   {
    275     $colors = get_dirs( $theme_dir.$main_themes[$i].'/' );
    276     for ( $j = 0; $j < sizeof( $colors ); $j++ )
    277     {
    278       array_push( $themes, $main_themes[$i].' - '.$colors[$j] );
    279     }
    280   }
    281   return $themes;
    282 }
    283 
    284273// - add_style replaces the
    285274//         $search  into <span style="$style">$search</span>
     
    325314}
    326315
    327 function database_connection()
    328 {
    329   include( PREFIX_INCLUDE.'./include/mysql.inc.php' );
    330   define( "PREFIX_TABLE", $prefixeTable );
    331 
    332   @mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
    333     or die ( "Could not connect to server" );
    334   @mysql_select_db( $cfgBase )
    335     or die ( "Could not connect to database" );
    336 }
    337 
    338316function pwg_log( $file, $category, $picture = '' )
    339317{
     
    356334
    357335  foreach ( $array as $value ) {
     336  if (isset(${$global_array_name}[$value]))
    358337    $vtp->setGlobalVar( $handle, $value, ${$global_array_name}[$value] );
    359338  }
     
    433412  }
    434413}
     414
     415function pwg_write_debug()
     416{
     417  global $debug;
     418 
     419  $fp = @fopen( './log/debug.log', 'a+' );
     420  fwrite( $fp, "\n\n" );
     421  fwrite( $fp, $debug );
     422  fclose( $fp );
     423}
     424
     425function pwg_query( $query )
     426{
     427  global $count_queries,$queries_time;
     428
     429  $start = get_moment();
     430  $output = '';
     431 
     432  $count_queries++;
     433  $output.= '<br /><br />['.$count_queries.'] '.$query;
     434  $result = mysql_query( $query );
     435  $time = get_moment() - $start;
     436  $queries_time+= $time;
     437  $output.= '<b>('.number_format( $time, 3, '.', ' ').' s)</b>';
     438  $output.= '('.number_format( $queries_time, 3, '.', ' ').' s)';
     439
     440  // echo $output;
     441 
     442  return $result;
     443}
     444
     445function pwg_debug( $string )
     446{
     447  global $debug,$t2,$count_queries;
     448
     449  $now = explode( ' ', microtime() );
     450  $now2 = explode( '.', $now[0] );
     451  $now2 = $now[1].'.'.$now2[1];
     452  $time = number_format( $now2 - $t2, 3, '.', ' ').' s';
     453  $debug.= '['.$time.', ';
     454  $debug.= $count_queries.' queries] : '.$string;
     455  $debug.= "\n";
     456}
    435457?>
  • trunk/include/functions_category.inc.php

    r133 r345  
    1818 ***************************************************************************/
    1919
    20 function get_subcats_id( $cat_id )
    21 {
    22   $restricted_cats = array();
    23                
    24   $query = 'SELECT id';
    25   $query.= ' FROM '.PREFIX_TABLE.'categories';
    26   $query.= ' WHERE id_uppercat = '.$cat_id;
    27   $query.= ';';
    28   $result = mysql_query( $query );
    29   while ( $row = mysql_fetch_array( $result ) )
    30   {
    31     array_push( $restricted_cats, $row['id'] );
    32     $sub_restricted_cats = get_subcats_id( $row['id'] );
    33     foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
    34       array_push( $restricted_cats, $sub_restricted_cat );
    35     }
    36   }
    37   return $restricted_cats;
    38 }
    39 
    4020function check_restrictions( $category_id )
    4121{
    4222  global $user,$lang;
    4323
    44   if ( is_user_allowed( $category_id, $user['restrictions'] ) > 0 )
     24  if ( in_array( $category_id, $user['restrictions'] ) )
    4525  {
    4626    echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
     
    5030  }
    5131}
    52        
     32
    5333// the check_cat_id function check whether the $cat is a right parameter :
    5434//  - $cat is numeric and corresponds to a category in the database
     
    6242  if ( isset( $cat ) )
    6343  {
    64     if ( isset( $page['plain_structure'] ) )
    65     {
    66       if ( isset( $page['plain_structure'][$cat] ) )
    67       {
    68         $page['cat'] = $cat;
    69       }
     44    if ( isset( $page['plain_structure'][$cat] ) )
     45    {
     46      $page['cat'] = $cat;
    7047    }
    7148    else if ( is_numeric( $cat ) )
    7249    {
    7350      $query = 'SELECT id';
    74       $query.= ' FROM '.PREFIX_TABLE.'categories';
    75       $query.= ' WHERE id = '.$cat;
    76       $query. ';';
     51      $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';';
    7752      $result = mysql_query( $query );
    7853      if ( mysql_num_rows( $result ) != 0 )
     
    9267}
    9368
    94 function get_plain_structure()
    95 {
    96   $infos = array( 'name','id','date_last','nb_images','dir','id_uppercat',
    97                   'rank','site_id');
     69function get_user_plain_structure()
     70{
     71  global $page,$user;
    9872 
    99   $query = 'SELECT ';
    100   foreach ( $infos as $i => $info ) {
    101     if ( $i > 0 ) $query.= ',';
    102     $query.= $info;
    103   }
    104   $query.= ' FROM '.PREFIX_TABLE.'categories';
     73  $infos = array( 'name','id','uc.date_last','nb_images','dir','id_uppercat',
     74                  'rank','site_id','nb_sub_categories','uppercats');
     75 
     76  $query = 'SELECT '.implode( ',', $infos );
     77  $query.= ' FROM '.CATEGORIES_TABLE.' AS c';
     78//  $query.= ' ,'.PREFIX_TABLE.'user_category AS uc';
     79  $query.= ' INNER JOIN '.USER_CATEGORY_TABLE.' AS uc';
     80  $query.= ' ON c.id = uc.category_id';
     81  $query.= ' WHERE user_id = '.$user['id'];
     82  if ( $page['expand'] != 'all' )
     83  {
     84    $query.= ' AND (id_uppercat is NULL';
     85    if ( count( $page['tab_expand'] ) > 0 )
     86    {
     87      $query.= ' OR id_uppercat IN ('.$page['expand'].')';
     88    }
     89    $query.= ')';
     90  }
     91  if ( $user['forbidden_categories'] != '' )
     92  {
     93    $query.= ' AND id NOT IN ';
     94    $query.= '('.$user['forbidden_categories'].')';
     95  }
     96//  $query.= ' AND c.id = uc.category_id';
    10597  $query.= ' ORDER BY id_uppercat ASC, rank ASC';
    10698  $query.= ';';
     
    112104    $category = array();
    113105    foreach ( $infos as $info ) {
    114       $category[$info] = $row[$info];
    115       if ( $info == 'date_last' )
    116       {
    117         list($year,$month,$day) = explode( '-', $row[$info] );
    118         $category[$info] = mktime(0,0,0,$month,$day,$year);
    119       }
     106      if ( $info == 'uc.date_last' )
     107      {
     108        list($year,$month,$day) = explode( '-', $row['date_last'] );
     109        $category['date_last'] = mktime(0,0,0,$month,$day,$year);
     110      }
     111      else if ( isset( $row[$info] ) ) $category[$info] = $row[$info];
     112      else                             $category[$info] = '';
    120113    }
    121114    $plain_structure[$row['id']] = $category;
     
    125118}
    126119
    127 function create_structure( $id_uppercat, $restrictions )
     120function create_user_structure( $id_uppercat )
    128121{
    129122  global $page;
    130123
    131124  if ( !isset( $page['plain_structure'] ) )
    132     $page['plain_structure'] = get_plain_structure();
     125    $page['plain_structure'] = get_user_plain_structure();
    133126
    134127  $structure = array();
    135   $ids = get_subcat_ids( $id_uppercat );
     128  $ids = get_user_subcat_ids( $id_uppercat );
    136129  foreach ( $ids as $id ) {
    137     if ( !in_array( $id, $restrictions ) )
    138     {
    139       $category = $page['plain_structure'][$id];
    140       $category['subcats'] = create_structure( $id, $restrictions );
    141       array_push( $structure, $category );
    142     }
     130    $category = $page['plain_structure'][$id];
     131    $category['subcats'] = create_user_structure( $id );
     132    array_push( $structure, $category );
    143133  }
    144134  return $structure;
    145135}
    146136
    147 function get_subcat_ids( $id_uppercat )
     137function get_user_subcat_ids( $id_uppercat )
    148138{
    149139  global $page;
     
    158148
    159149// update_structure updates or add informations about each node of the
    160 // structure : the last date, should the category be expanded in the menu ?,
    161 // the associated expand string "48,14,54"
     150// structure :
    162151//
    163 // 1. last date
    164 // for each category of the structure, we have to find the most recent
    165 // subcat so that the parent cat has the same last_date info.
    166 // For example : we have :
    167 // > pets       (2003.02.15)
    168 //    > dogs    (2003.06.14)
    169 //       > rex  (2003.06.18)
    170 //       > toby (2003.06.13)
    171 //    > kitten  (2003.07.05)
    172 // We finally want to have :
    173 // > pets       (2003.07.05) <- changed to pets > kitten last date
    174 //    > dogs    (2003.06.18) <- changed to pets > dogs > rex last date
    175 //       > rex  (2003.06.18)
    176 //       > toby (2003.06.13)
    177 //    > kitten  (2003.07.05)
    178 //
    179 // 2. should the category be expanded in the menu ?
     152// 1. should the category be expanded in the menu ?
    180153// If the category has to be expanded (ie its id is in the
    181154// $page['tab_expand'] or all the categories must be expanded by default),
    182155// $category['expanded'] is set to true.
    183156//
    184 // 3. associated expand string
     157// 2. associated expand string
    185158// in the menu, there is a expand string (used in the URL) to tell which
    186159// categories must be expanded in the menu if this category is chosen
     
    192165
    193166  foreach ( $categories as $category ) {
    194     // update the last date of the category
    195     $last_date = search_last_date( $category );
    196     $category['date_last'] = $last_date;
    197167    // update the "expanded" key
    198168    if ( $user['expand']
     
    206176      $category['expanded'] = false;
    207177    }
    208     // update the  "expand_string" key
     178    // update the "expand_string" key
    209179    if ( $page['expand'] == 'all' )
    210180    {
     
    220190        $tab_expand = array_diff( $page['tab_expand'],array($category['id']) );
    221191      }
    222       else if ( count( $category['subcats'] ) > 0 )
     192      else if ( $category['nb_sub_categories'] > 0 )
    223193      {
    224194        // we have this time to add the $category['id']...
     
    234204
    235205  return $updated_categories;
    236 }
    237 
    238 // search_last_date searchs the last date for a given category. If we take
    239 // back the example given for update_last_dates, we should have :
    240 // search_last_date( pets )        --> 2003.07.05
    241 // search_last_date( pets > dogs ) --> 2003.06.18
    242 // and so on
    243 function search_last_date( $category )
    244 {
    245   $date_last = $category['date_last'];
    246   foreach ( $category['subcats'] as $subcat ) {
    247     $subcat_date_last = search_last_date( $subcat );
    248     if ( $subcat_date_last > $date_last )
    249     {
    250       $date_last = $subcat_date_last;
    251     }
    252   }
    253   return $date_last;
    254206}
    255207
     
    263215function count_images( $categories )
    264216{
     217  return count_user_total_images();
    265218  $total = 0;
    266219  foreach ( $categories as $category ) {
     
    269222  }
    270223  return $total;
     224}
     225
     226function count_user_total_images()
     227{
     228  global $user;
     229
     230  $query = 'SELECT SUM(nb_images) AS total';
     231  $query.= ' FROM '.CATEGORIES_TABLE;
     232  if ( count( $user['restrictions'] ) > 0 )
     233    $query.= ' WHERE id NOT IN ('.$user['forbidden_categories'].')';
     234  $query.= ';';
     235 
     236  $row = mysql_fetch_array( mysql_query( $query ) );
     237
     238  if ( !isset( $row['total'] ) ) $row['total'] = 0;
     239
     240  return $row['total'];
    271241}
    272242
     
    286256  global $page;
    287257
     258  $infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url'
     259                  ,'dir','date_last','uploadable','status','visible'
     260                  ,'representative_picture_id','uppercats' );
     261
     262  $query = 'SELECT '.implode( ',', $infos );
     263  $query.= ' FROM '.CATEGORIES_TABLE.' AS a';
     264  $query.= ', '.SITES_TABLE.' AS b';
     265  $query.= ' WHERE a.id = '.$id;
     266  $query.= ' AND a.site_id = b.id';
     267  $query.= ';';
     268  $row = mysql_fetch_array( mysql_query( $query ) );
     269
    288270  $cat = array();
    289                
    290   $query = 'SELECT nb_images,id_uppercat,comment,site_id,galleries_url,dir';
    291   $query.= ',date_last,uploadable,status,visible,representative_picture_id';
    292   $query.= ' FROM '.PREFIX_TABLE.'categories AS a';
    293   $query.= ', '.PREFIX_TABLE.'sites AS b';
    294   $query.= ' WHERE a.id = '.$id;
    295   $query.= ' AND a.site_id = b.id;';
    296   $row = mysql_fetch_array( mysql_query( $query ) );
    297   $cat['site_id']     = $row['site_id'];
    298   $cat['id_uppercat'] = $row['id_uppercat'];
    299   $cat['comment']     = nl2br( $row['comment'] );
    300   $cat['nb_images']   = $row['nb_images'];
    301   $cat['dir']         = $row['dir'];
    302   $cat['date_last']   = $row['date_last'];
    303   $cat['uploadable']  = get_boolean( $row['uploadable'] );
    304   $cat['status']      = $row['status'];
    305   $cat['visible']     = get_boolean( $row['visible'] );
    306   $cat['representative_picture_id'] = $row['representative_picture_id'];
     271  // affectation of each field of the table "config" to an information of the
     272  // array $cat.
     273  foreach ( $infos as $info ) {
     274    if ( isset( $row[$info] ) ) $cat[$info] = $row[$info];
     275    else                        $cat[$info] = '';
     276    // If the field is true or false, the variable is transformed into a
     277    // boolean value.
     278    if ( $cat[$info] == 'true' or $cat[$info] == 'false' )
     279    {
     280      $cat[$info] = get_boolean( $cat[$info] );
     281    }
     282  }
     283  $cat['comment'] = nl2br( $cat['comment'] );
    307284
    308285  $cat['name'] = array();
    309286
    310   if ( !isset( $page['plain_structure'] ) )
    311     $page['plain_structure'] = get_plain_structure();
    312 
    313   array_push( $cat['name'], $page['plain_structure'][$id]['name'] );
    314   while ( $page['plain_structure'][$id]['id_uppercat'] != '' )
    315   {
    316     $id = $page['plain_structure'][$id]['id_uppercat'];
    317     array_push( $cat['name'], $page['plain_structure'][$id]['name'] );
    318   }
     287  $query = 'SELECT name FROM '.CATEGORIES_TABLE;
     288  $query.= ' WHERE id IN ('.$cat['uppercats'].')';
     289  $query.= ' ORDER BY id ASC';
     290  $query.= ';';
     291  $result = mysql_query( $query );
     292  while( $row = mysql_fetch_array( $result ) )
     293  {
     294    array_push( $cat['name'], $row['name'] );
     295  }
     296 
    319297  return $cat;
    320298}
     
    338316  global $page;
    339317
    340   if ( !isset( $page['plain_structure'] ) )
    341     $page['plain_structure'] = get_plain_structure();
    342  
    343   // creating the local path : "root_cat/sub_cat/sub_sub_cat/"
    344   $dir = $page['plain_structure'][$category_id]['dir'].'/';
    345   while ( $page['plain_structure'][$category_id]['id_uppercat'] != '' )
    346   {
    347     $category_id = $page['plain_structure'][$category_id]['id_uppercat'];
    348     $dir = $page['plain_structure'][$category_id]['dir'].'/'.$dir;
    349   }
    350   return $dir;
     318  $uppercats = '';
     319  $local_dir = '';
     320
     321  if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
     322  {
     323    $uppercats = $page['plain_structure'][$category_id]['uppercats'];
     324  }
     325  else
     326  {
     327    $query = 'SELECT uppercats';
     328    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
     329    $query.= ';';
     330    $row = mysql_fetch_array( mysql_query( $query ) );
     331    $uppercats = $row['uppercats'];
     332  }
     333
     334  $upper_array = explode( ',', $uppercats );
     335
     336  $database_dirs = array();
     337  $query = 'SELECT id,dir';
     338  $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
     339  $query.= ';';
     340  $result = mysql_query( $query );
     341  while( $row = mysql_fetch_array( $result ) )
     342  {
     343    $database_dirs[$row['id']] = $row['dir'];
     344  }
     345  foreach ( $upper_array as $id ) {
     346    $local_dir.= $database_dirs[$id].'/';
     347  }
     348
     349  return $local_dir;
    351350}
    352351
     
    357356  global $page;
    358357
    359   if ( !isset( $page['plain_structure'] ) )
    360     $page['plain_structure'] = get_plain_structure();
    361 
    362358  $query = 'SELECT galleries_url';
    363   $query.= ' FROM '.PREFIX_TABLE.'sites';
    364   $query.= ' WHERE id = '.$page['plain_structure'][$category_id]['site_id'];
     359  $query.= ' FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c';
     360  $query.= ' WHERE s.id = c.site_id';
     361  $query.= ' AND c.id = '.$category_id;
    365362  $query.= ';';
    366363  $row = mysql_fetch_array( mysql_query( $query ) );
     
    375372//   - $style : the style of the span tag for the lowest category,
    376373//     "font-style:italic;" for example
    377 function get_cat_display_name( $array_cat_names, $separation, $style )
    378 {
    379   $output = "";
    380   for ( $i = sizeof( $array_cat_names ) - 1; $i >= 0; $i-- )
    381   {
    382     if ( $i != sizeof( $array_cat_names ) - 1 )
    383     {
    384       $output.= $separation;
    385     }
    386     if ( $i != 0 )
    387     {
    388       $output.= $array_cat_names[$i];
    389     }
     374function get_cat_display_name( $array_cat_names, $separation,
     375                               $style, $replace_space = true )
     376{
     377  $output = '';
     378  foreach ( $array_cat_names as $i => $name ) {
     379    if ( $i > 0 ) $output.= $separation;
     380    if ( $i < count( $array_cat_names ) - 1 or $style == '')
     381      $output.= $name;
    390382    else
    391     {
    392       if ( $style != "" )
    393       {
    394         $output.= '<span style="'.$style.'">';
    395       }
    396       $output.= $array_cat_names[$i];
    397       if ( $style != "" )
    398       {
    399         $output.= "</span>";
    400       }
    401     }
    402   }
    403   return replace_space( $output );
     383      $output.= '<span style="'.$style.'">'.$name.'</span>';
     384  }
     385  if ( $replace_space ) return replace_space( $output );
     386  else                  return $output;
    404387}
    405388
     
    419402function initialize_category( $calling_page = 'category' )
    420403{
     404  pwg_debug( 'start initialize_category' );
    421405  global $page,$lang,$user,$conf;
    422406
     
    427411    $page['nb_image_page'] = $user['nb_image_page'];
    428412    // $url is used to create the navigation bar
    429     $url = './category.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
     413    $url = './category.php?cat='.$page['cat'];
     414    if ( isset($page['expand']) ) $url.= '&amp;expand='.$page['expand'];
    430415    // simple category
    431416    if ( is_numeric( $page['cat'] ) )
     
    438423      $page['cat_site_id']    = $result['site_id'];
    439424      $page['cat_uploadable'] = $result['uploadable'];
    440       $page['title'] = get_cat_display_name( $page['cat_name'], ' - ', '' );
     425      $page['uppercats']      = $result['uppercats'];
     426      $page['title'] = get_cat_display_name( $page['cat_name'],' - ','',false);
    441427      $page['where'] = ' WHERE category_id = '.$page['cat'];
    442428    }
     
    447433      {
    448434        // we must not show pictures of a forbidden category
    449         $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    450         if ( count( $restricted_cats ) > 0 )
     435        if ( $user['forbidden_categories'] != '' )
    451436        {
    452           $where_append.= ' AND category_id NOT IN (';
    453           foreach ( $restricted_cats as $i => $restricted_cat ) {
    454             if ( $i > 0 ) $where_append.= ',';
    455             $where_append.= $restricted_cat;
    456           }
    457           $where_append.= ')';
     437          $forbidden = ' category_id NOT IN ';
     438          $forbidden.= '('.$user['forbidden_categories'].')';
    458439        }
    459440      }
     
    500481        }
    501482        $page['where'].= ' )';
    502         $page['where'].= $where_append;
     483        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
    503484
    504485        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
    505         $query.= ' FROM '.PREFIX_TABLE.'images';
    506         $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
     486        $query.= ' FROM '.IMAGES_TABLE;
     487        $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
    507488        $query.= ' ON id = ic.image_id';
    508489        $query.= $page['where'];
     
    516497        $page['title'] = $lang['favorites'];
    517498
    518         $page['where'] = ', '.PREFIX_TABLE.'favorites AS fav';
     499        $page['where'] = ', '.FAVORITES_TABLE.' AS fav';
    519500        $page['where'].= ' WHERE user_id = '.$user['id'];
    520501        $page['where'].= ' AND fav.image_id = id';
    521502     
    522503        $query = 'SELECT COUNT(*) AS nb_total_images';
    523         $query.= ' FROM '.PREFIX_TABLE.'favorites';
     504        $query.= ' FROM '.FAVORITES_TABLE;
    524505        $query.= ' WHERE user_id = '.$user['id'];
    525506        $query.= ';';
     
    534515        $page['where'] = " WHERE date_available > '";
    535516        $page['where'].= date( 'Y-m-d', $date )."'";
    536         $page['where'].= $where_append;
     517        if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
    537518
    538519        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
    539         $query.= ' FROM '.PREFIX_TABLE.'images';
    540         $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
     520        $query.= ' FROM '.IMAGES_TABLE;
     521        $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category AS ic';
    541522        $query.= ' ON id = ic.image_id';
    542523        $query.= $page['where'];
     
    547528      {
    548529        $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
    549         $page['where'] = ' WHERE category_id != -1'.$where_append;
     530       
     531        if ( isset( $forbidden ) ) $page['where'] = ' WHERE '.$forbidden;
     532        else                       $page['where'] = '';
    550533        $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
    551534        $page['cat_nb_images'] = $conf['top_number'];
    552         if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
     535        if ( isset( $page['start'] )
     536             and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
    553537        {
    554538          $page['nb_image_page'] = $conf['top_number'] - $page['start'];
     
    556540      }
    557541
    558       if ( $query != '' )
     542      if ( isset($query))
    559543      {
    560544        $result = mysql_query( $query );
     
    574558    $page['title'] = $lang['diapo_default_page_title'];
    575559  }
     560  pwg_debug( 'end initialize_category' );
    576561}
    577562
     
    600585
    601586  $query = 'SELECT id,nb_images';
    602   $query.= ' FROM '.PREFIX_TABLE.'categories';
     587  $query.= ' FROM '.CATEGORIES_TABLE;
    603588  $query.= ' WHERE id_uppercat ';
    604589  if ( !is_numeric( $id_uppercat ) ) $query.= 'is NULL';
    605590  else                               $query.= '= '.$id_uppercat;
    606591  // we must not show pictures of a forbidden category
    607   foreach ( $user['restrictions'] as $restricted_cat ) {
    608     $query.= ' AND id != '.$restricted_cat;
     592  if ( $user['forbidden_categories'] != '' )
     593  {
     594    $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
    609595  }
    610596  $query.= ' ORDER BY rank';
     
    633619
    634620  $query = 'SELECT id,nb_images';
    635   $query.= ' FROM '.PREFIX_TABLE.'categories';
     621  $query.= ' FROM '.CATEGORIES_TABLE;
    636622  $query.= ' WHERE id_uppercat = '.$id_uppercat;
    637623  // we must not show pictures of a forbidden category
    638   foreach ( $user['restrictions'] as $restricted_cat ) {
    639     $query.= ' AND id != '.$restricted_cat;
     624  if ( $user['forbidden_categories'] != '' )
     625  {
     626    $query.= ' AND id NOT IN ('.$user['forbidden_categories'].')';
    640627  }
    641628  $query.= ' ORDER BY RAND()';
  • trunk/include/functions_group.inc.php

    r57 r345  
    8686    $query.= ';';
    8787    $row = mysql_fetch_array( mysql_query( $query ) );
    88     if ( $row['id_uppercat'] == '' )
    89     {
    90       $is_root = true;
    91     }
     88    if ( !isset( $row['id_uppercat'] ) ) $row['id_uppercat'] = '';
     89    if ( $row['id_uppercat'] == '' ) $is_root = true;
    9290    $category_id = $row['id_uppercat'];
    9391  }
  • trunk/include/functions_user.inc.php

    r99 r345  
    3838}
    3939
    40 function register_user(
    41   $login, $password, $password_conf, $mail_address, $status = 'guest' )
     40function register_user( $login, $password, $password_conf,
     41                        $mail_address, $status = 'guest' )
    4242{
    4343  global $lang;
     
    5050  //      3. include ' or " characters
    5151  //      4. be already used
    52   if ( $login == '' )
    53   {
    54     $error[$i++] = $lang['reg_err_login1'];
    55   }
    56   if ( ereg( "^.* $", $login) )
    57   {
    58     $error[$i++] = $lang['reg_err_login2'];
    59   }
    60   if ( ereg( "^ .*$", $login ) )
    61   {
    62     $error[$i++] = $lang['reg_err_login3'];
    63   }
     52  if ( $login == '' )            $error[$i++] = $lang['reg_err_login1'];
     53  if ( ereg( "^.* $", $login) )  $error[$i++] = $lang['reg_err_login2'];
     54  if ( ereg( "^ .*$", $login ) ) $error[$i++] = $lang['reg_err_login3'];
     55
    6456  if ( ereg( "'", $login ) or ereg( "\"", $login ) )
    65   {
    6657    $error[$i++] = $lang['reg_err_login4'];
    67   }
    6858  else
    6959  {
    70     $query = 'select id';
    71     $query.= ' from '.PREFIX_TABLE.'users';
    72     $query.= " where username = '".$login."';";
    73     $result = mysql_query( $query );
    74     if ( mysql_num_rows( $result ) > 0 )
    75     {
    76       $error[$i++] = $lang['reg_err_login5'];
    77     }
     60    $query = 'SELECT id';
     61    $query.= ' FROM '.PREFIX_TABLE.'users';
     62    $query.= " WHERE username = '".$login."'";
     63    $query.= ';';
     64    $result = mysql_query( $query );
     65    if ( mysql_num_rows($result) > 0 ) $error[$i++] = $lang['reg_err_login5'];
    7866  }
    7967  // given password must be the same as the confirmation
    80   if ( $password != $password_conf )
    81   {
    82     $error[$i++] = $lang['reg_err_pass'];
    83   }
     68  if ( $password != $password_conf ) $error[$i++] = $lang['reg_err_pass'];
    8469
    8570  $error_mail_address = validate_mail_address( $mail_address );
    86   if ( $error_mail_address != '' )
    87   {
    88     $error[$i++] = $error_mail_address;
    89   }
     71  if ( $error_mail_address != '' ) $error[$i++] = $error_mail_address;
    9072
    9173  // if no error until here, registration of the user
     
    9577    $infos = array( 'nb_image_line', 'nb_line_page', 'language',
    9678                    'maxwidth', 'maxheight', 'expand', 'show_nb_comments',
    97                     'short_period', 'long_period', 'template' );
    98     $query = 'select';
     79                    'short_period', 'long_period', 'template',
     80                    'forbidden_categories' );
     81    $query = 'SELECT ';
    9982    for ( $i = 0; $i < sizeof( $infos ); $i++ )
    10083    {
    101       if ( $i > 0 )
    102       {
    103         $query.= ',';
    104       }
    105       else
    106       {
    107         $query.= ' ';
    108       }
     84      if ( $i > 0 ) $query.= ',';
    10985      $query.= $infos[$i];
    11086    }
    111     $query.= ' from '.PREFIX_TABLE.'users';
    112     $query.= " where username = 'guest';";
     87    $query.= ' FROM '.PREFIX_TABLE.'users';
     88    $query.= " WHERE username = 'guest'";
     89    $query.= ';';
    11390    $row = mysql_fetch_array( mysql_query( $query ) );
    11491    // 2. adding new user
    115     $query = 'insert into '.PREFIX_TABLE.'users';
     92    $query = 'INSERT INTO '.PREFIX_TABLE.'users';
    11693    $query.= ' (';
    11794    $query.= ' username,password,mail_address,status';
     
    123100    $query.= " '".$login."'";
    124101    $query.= ",'".md5( $password )."'";
    125     if ( $mail_address != '' )
    126     {
    127       $query.= ",'".$mail_address."'";
    128     }
    129     else
    130     {
    131       $query.= ',NULL';
    132     }
     102    if ( $mail_address != '' ) $query.= ",'".$mail_address."'";
     103    else                       $query.= ',NULL';
    133104    $query.= ",'".$status."'";
    134     for ( $i = 0; $i < sizeof( $infos ); $i++ )
    135     {
     105    foreach ( $infos as $info ) {
    136106      $query.= ',';
    137       if ( $row[$infos[$i]] == '' )
    138       {
    139         $query.= 'NULL';
    140       }
    141       else
    142       {
    143         $query.= "'".$row[$infos[$i]]."'";
    144       }
     107      if ( !isset( $row[$info] ) ) $query.= 'NULL';
     108      else                         $query.= "'".$row[$info]."'";
    145109    }
    146110    $query.= ');';
     
    166130      mysql_query ( $query );
    167131    }
     132    // 5. associate new user to the same groups that the guest
     133    $query = 'SELECT group_id';
     134    $query.= ' FROM '.PREFIX_TABLE.'user_group AS ug';
     135    $query.= ',     '.PREFIX_TABLE.'users      AS u';
     136    $query.= " WHERE u.username = 'guest'";
     137    $query.= ' AND ug.user_id = u.id';
     138    $query.= ';';
     139    $result = mysql_query( $query );
     140    while( $row = mysql_fetch_array( $result ) )
     141    {
     142      $query = 'INSERT INTO '.PREFIX_TABLE.'user_group';
     143      $query.= ' (user_id,group_id) VALUES';
     144      $query.= ' ('.$user_id.','.$row['group_id'].')';
     145      $query.= ';';
     146      mysql_query ( $query );
     147    }
     148    // 6. has the same categories informations than guest
     149    $query = 'SELECT category_id,date_last,nb_sub_categories';
     150    $query.= ' FROM '.PREFIX_TABLE.'user_category AS uc';
     151    $query.= ',     '.PREFIX_TABLE.'users         AS u';
     152    $query.= " WHERE u.username = 'guest'";
     153    $query.= ' AND uc.user_id = u.id';
     154    $query.= ';';
     155    $result = mysql_query( $query );
     156    while( $row = mysql_fetch_array( $result ) )
     157    {
     158      $query = 'INSERT INTO '.PREFIX_TABLE.'user_category';
     159      $query.= ' (user_id,category_id,date_last,nb_sub_categories) VALUES';
     160      $query.= ' ('.$user_id.','.$row['category_id'];
     161      $query.= ",'".$row['date_last']."',".$row['nb_sub_categories'].')';
     162      $query.= ';';
     163      mysql_query ( $query );
     164    }
    168165  }
    169166  return $error;
     
    210207  global $user,$lang,$conf,$page;
    211208
    212   if ( $user['is_the_guest']
    213        and ( $conf['access'] == 'restricted' or $page['cat'] == 'fav' ) )
     209  if ( $user['is_the_guest'])
     210  {
     211  if ( $conf['access'] == 'restricted' || (isset($page['cat']) && $page['cat'] == 'fav' ) )
    214212  {
    215213    echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
     
    217215    exit();
    218216  }
    219 }
    220        
    221 // The function get_restrictions returns an array with the ids of the
    222 // restricted categories for the user.
    223 // If the $check_invisible parameter is set to true, invisible categories
    224 // are added to the restricted one in the array.
    225 function get_restrictions( $user_id, $user_status,
    226                            $check_invisible, $use_groups = true )
    227 {
    228   // 1. retrieving ids of private categories
    229   $query = 'SELECT id';
    230   $query.= ' FROM '.PREFIX_TABLE.'categories';
    231   $query.= " WHERE status = 'private'";
    232   $query.= ';';
    233   $result = mysql_query( $query );
    234   $privates = array();
    235   while ( $row = mysql_fetch_array( $result ) )
    236   {
    237     array_push( $privates, $row['id'] );
    238   }
    239   // 2. retrieving all authorized categories for the user
    240   $authorized = array();
    241   // 2.1. retrieving authorized categories thanks to personnal user
    242   //      authorization
    243   $query = 'SELECT cat_id';
    244   $query.= ' FROM '.PREFIX_TABLE.'user_access';
    245   $query.= ' WHERE user_id = '.$user_id;
    246   $query.= ';';
    247   $result = mysql_query( $query );
    248   while ( $row = mysql_fetch_array( $result ) )
    249   {
    250     array_push( $authorized, $row['cat_id'] );
    251   }
    252   // 2.2. retrieving authorized categories thanks to group authorization to
    253   //      which the user is a member
    254   if ( $use_groups )
    255   {
    256     $query = 'SELECT ga.cat_id';
    257     $query.= ' FROM '.PREFIX_TABLE.'user_group as ug';
    258     $query.= ', '.PREFIX_TABLE.'group_access as ga';
    259     $query.= ' WHERE ug.group_id = ga.group_id';
    260     $query.= ' AND ug.user_id = '.$user_id;
    261     $query.= ';';
    262     $result = mysql_query( $query );
    263     while ( $row = mysql_fetch_array( $result ) )
    264     {
    265       array_push( $authorized, $row['cat_id'] );
    266     }
    267     $authorized = array_unique( $authorized );
    268   }
    269 
    270   $forbidden = array();
    271   foreach ( $privates as $private ) {
    272     if ( !in_array( $private, $authorized ) )
    273     {
    274       array_push( $forbidden, $private );
    275     }
    276   }
    277 
    278   if ( $check_invisible )
    279   {
    280     // 3. adding to the restricted categories, the invisible ones
    281     if ( $user_status != 'admin' )
    282     {
    283       $query = 'SELECT id';
    284       $query.= ' FROM '.PREFIX_TABLE.'categories';
    285       $query.= " WHERE visible = 'false';";
    286       $result = mysql_query( $query );
    287       while ( $row = mysql_fetch_array( $result ) )
    288       {
    289         array_push( $forbidden, $row['id'] );
    290       }
    291     }
    292   }
    293   return array_unique( $forbidden );
    294 }
    295 
    296 // The get_all_restrictions function returns an array with all the
    297 // categories id which are restricted for the user. Including the
    298 // sub-categories and invisible categories
    299 function get_all_restrictions( $user_id, $user_status )
    300 {
    301   $restricted_cats = get_restrictions( $user_id, $user_status, true );
    302   foreach ( $restricted_cats as $restricted_cat ) {
    303     $sub_restricted_cats = get_subcats_id( $restricted_cat );
    304     foreach ( $sub_restricted_cats as $sub_restricted_cat ) {
    305       array_push( $restricted_cats, $sub_restricted_cat );
    306     }
    307   }
    308   return $restricted_cats;
    309 }
    310 
    311 // The function is_user_allowed returns :
    312 //      - 0 : if the category is allowed with this $restrictions array
    313 //      - 1 : if this category is not allowed
    314 //      - 2 : if an uppercat category is not allowed
    315 function is_user_allowed( $category_id, $restrictions )
    316 {
    317   $lowest_category_id = $category_id;
    318 
    319   $is_root = false;
    320   while ( !$is_root and !in_array( $category_id, $restrictions ) )
    321   {
    322     $query = 'SELECT id_uppercat';
    323     $query.= ' FROM '.PREFIX_TABLE.'categories';
    324     $query.= ' WHERE id = '.$category_id;
    325     $query.= ';';
    326     $row = mysql_fetch_array( mysql_query( $query ) );
    327     if ( $row['id_uppercat'] == '' ) $is_root = true;
    328     $category_id = $row['id_uppercat'];
    329   }
    330 
    331   if ( in_array( $lowest_category_id, $restrictions ) ) return 1;
    332   if ( in_array( $category_id,        $restrictions ) ) return 2;
    333   // this user is allowed to go in this category
    334   return 0;
     217  }
    335218}
    336219?>
  • trunk/include/functions_xml.inc.php

    r231 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
    19 
    20 //------------------------------------------------------------------ constantes
    21 define( "ATT_REG", '\w+' );
    22 define( "VAL_REG", '[^"]*' );
    2319//------------------------------------------------------------------- functions
    2420// getContent returns the content of a tag
  • trunk/include/user.inc.php

    r90 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
     19
    1920// retrieving user informations
    2021// $infos array is used to know the fields to retrieve in the table "users"
     
    2526                'nb_line_page', 'status', 'language', 'maxwidth',
    2627                'maxheight', 'expand', 'show_nb_comments', 'short_period',
    27                 'long_period', 'template' );
     28                'long_period', 'template', 'forbidden_categories' );
    2829
    29 $query_user  = 'SELECT ';
    30 foreach ( $infos as $i => $info ) {
    31   if ( $i > 0 ) $query_user.= ',';
    32   $query_user.= $info;
    33 }
    34 $query_user.= ' FROM '.PREFIX_TABLE.'users';
     30$query_user = 'SELECT '.implode( ',', $infos );
     31$query_user.= ' FROM '.USERS_TABLE;
    3532$query_done = false;
    3633$user['is_the_guest'] = false;
     
    6057  $page['session_id'] = $session_id;
    6158  $query = 'SELECT user_id,expiration,ip';
    62   $query.= ' FROM '.PREFIX_TABLE.'sessions';
     59  $query.= ' FROM '.SESSIONS_TABLE;
    6360  $query.= " WHERE id = '".$page['session_id']."'";
    6461  $query.= ';';
     
    7370        // deletion of the session from the database,
    7471        // because it is out-of-date
    75         $delete_query = 'DELETE FROM '.PREFIX_TABLE.'sessions';
     72        $delete_query = 'DELETE FROM '.SESSIONS_TABLE;
    7673        $delete_query.= " WHERE id = '".$page['session_id']."'";
    7774        $delete_query.= ';';
     
    9794}
    9895$query_user .= ';';
    99 
    10096$row = mysql_fetch_array( mysql_query( $query_user ) );
    10197
     
    10399// of the array $user.
    104100foreach ( $infos as $info ) {
    105   $user[$info] = $row[$info];
    106   // If the field is true or false, the variable is transformed into a
    107   // boolean value.
    108   if ( $row[$info] == 'true' or $row[$info] == 'false' )
     101  if ( isset( $row[$info] ) )
    109102  {
    110     $user[$info] = get_boolean( $row[$info] );
     103    // If the field is true or false, the variable is transformed into a
     104    // boolean value.
     105    if ( $row[$info] == 'true' or $row[$info] == 'false' )
     106      $user[$info] = get_boolean( $row[$info] );
     107    else
     108      $user[$info] = $row[$info];   
     109  }
     110  else
     111  {
     112    $user[$info] = '';
    111113  }
    112114}
     115
     116// special for $user['restrictions'] array
     117$user['restrictions'] = explode( ',', $user['forbidden_categories'] );
     118if ( $user['restrictions'][0] == '' ) $user['restrictions'] = array();
    113119?>
  • trunk/include/vtemplate.class.php

    r153 r345  
    1616 *                       
    1717 *****************************************************************/
    18 
    1918// to make it work on nexen.net
    2019set_magic_quotes_runtime(0);
  • trunk/index.php

    r231 r345  
    1818 ***************************************************************************/
    1919
    20 define( "PREFIX_INCLUDE", '' );
    21 include_once( './include/functions.inc.php' );
    22 database_connection();
    23 // retrieving configuration informations
    24 $query = 'SELECT access';
    25 $query.= ' FROM '.PREFIX_TABLE.'config;';
    26 $row = mysql_fetch_array( mysql_query( $query ) );
    27 if ( $row['access'] == 'restricted' )
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
     23if ( $conf['access'] == 'restricted' )
    2824{
    2925  if ( isset( $_COOKIE['id'] ) ) $url = 'category';
  • trunk/install.php

    r230 r345  
    1919
    2020//-------------------------------------------------------------------- includes
    21 define( "PREFIX_INCLUDE", '' );
     21define( 'PREFIX_INCLUDE', '' );
    2222include( './include/vtemplate.class.php' );
    2323include( './include/functions.inc.php' );
     24
     25$config_file = './config.php';
    2426//----------------------------------------------------- template initialization
    2527$vtp = new VTemplate;
    2628$handle = $vtp->Open( './template/default/install.vtp' );
    27 $vtp->setGlobalVar( $handle, 'release', '1.3' );
     29$vtp->setGlobalVar( $handle, 'release', '1.4' );
    2830//-------------------------------------------------------------------- language
    2931if ( isset( $_GET['language'] ) )
     
    4648}
    4749//---------------------- Step 1 : connection informations, write of config file
    48 if ( $_GET['step'] == 1 )
     50if ( isset($_GET['step']) && $_GET['step'] == 1 )
    4951{
    5052  $errors = array();
     
    7476      array_push( $errors, $lang['step1_err_server'] );
    7577    }
    76                        
     78       
    7779    if ( count( $errors ) == 0 )
    7880    {
     
    8284      $file_content.= "\n\$cfgPassword = '". $_POST['cfgPassword']."';";
    8385      $file_content.= "\n\$cfgHote = '".     $_POST['cfgHote']."';";
    84       $file_content.= "\n\$prefixeTable = '".$_POST['prefixeTable']."';";
     86          $file_content.= "\n";
     87      $file_content.= "\n\$table_prefix = '".$_POST['prefixeTable']."';";
     88          $file_content.= "\n";
     89          $file_content.= "\ndefine('PHPWG_INSTALLED', true);";
    8590      $file_content.= "\n?>";
    8691      // writting the configuration file
    87       if ( $fp = @fopen( './include/mysql.inc.php', 'a+' ) )
    88       {
     92      if ( $fp = @fopen( $config_file, 'a+' ) )
     93      {
     94                ftruncate($fp, 0);
    8995        fwrite( $fp, $file_content );
    9096        fclose( $fp );
     
    94100      $cfgPassword = '';
    95101      $cfgBase     = '';
    96       include( './include/mysql.inc.php' );
     102      if ( is_file( $config_file ) ) include( $config_file );
    97103      $file_OK = false;
    98104      if ( @mysql_connect( $cfgHote, $cfgUser, $cfgPassword ) )
     
    151157      $vtp->setVar( $handle, 'step1.f_host', $_POST['cfgHote'] );
    152158    // user
    153     $vtp->setVar( $handle, 'step1.f_user', $_POST['cfgUser'] );
     159        if ( isset( $_POST['cfgUser'] ) )
     160            $vtp->setVar( $handle, 'step1.f_user', $_POST['cfgUser'] );
    154161    // base
    155     $vtp->setVar( $handle, 'step1.f_base', $_POST['cfgBase'] );
     162        if ( isset( $_POST['cfgBase'] ) )
     163            $vtp->setVar( $handle, 'step1.f_base', $_POST['cfgBase'] );
    156164    // prefixeTable
    157165    if ( !isset( $_POST['prefixeTable'] ) )
     
    164172}
    165173//------------------------------------- Step 2 : creation of tables in database
    166 else if ( $_GET['step'] == 2 )
     174else if (  isset($_GET['step']) && $_GET['step'] == 2 )
    167175{
    168176  $errors = array();
    169177  $infos  = array();
    170178
    171   include( './include/mysql.inc.php' );
     179  include( $config_file );
    172180  mysql_connect( $cfgHote, $cfgUser, $cfgPassword )
    173181    or die ( "Can't connect to database host" );
     
    189197      {
    190198        $query = trim( $query );
    191         $query = str_replace( 'phpwebgallery_', $prefixeTable, $query );
     199        $query = str_replace( 'phpwebgallery_', $table_prefix, $query );
    192200        // we don't execute "DROP TABLE" queries
    193201        if ( !preg_match( '/^DROP TABLE/i', $query ) )
     
    222230    if ( count( $errors ) == 0 )
    223231    {
    224       $query = 'DELETE FROM '.$prefixeTable.'config';
     232      $query = 'DELETE FROM '.$table_prefix.'config';
    225233      mysql_query( $query );
    226234
    227       $query = 'INSERT INTO '.$prefixeTable.'config';
     235      $query = 'INSERT INTO '.$table_prefix.'config';
    228236      $query.= ' (webmaster,mail_webmaster) VALUES ';
    229237      $query.= " ('".$webmaster."','".$_POST['mail_webmaster']."')";
     
    231239      mysql_query( $query );
    232240
    233       $query = 'INSERT INTO '.$prefixeTable.'sites';
     241      $query = 'INSERT INTO '.$table_prefix.'sites';
    234242      $query.= " (id,galleries_url) VALUES (1, './galleries/')";
    235243      $query.= ';';
     
    237245
    238246      // webmaster admin user
    239       $query = 'INSERT INTO '.$prefixeTable.'users';
    240       $query.= ' (id,username,password,status,language) VALUES ';
     247      $query = 'INSERT INTO '.$table_prefix.'users';
     248      $query.= ' (id,username,password,status,language,mail_address) VALUES ';
    241249      $query.= "(1,'".$webmaster."','".md5( $_POST['pwdWebmaster'] )."'";
    242       $query.= ",'admin','".$_GET['language']."')";
     250      $query.= ",'admin','".$_GET['language']."'";
     251      $query.= ",'".$_POST['mail_webmaster']."')";
    243252      $query.= ';';
    244253      mysql_query($query);
    245254
    246255      // guest user
    247       $query = 'INSERT INTO '.$prefixeTable.'users';
     256      $query = 'INSERT INTO '.$table_prefix.'users';
    248257      $query.= '(id,username,password,status,language) VALUES ';
    249258      $query.= "(2,'guest','','guest','".$_GET['language']."')";
     
    268277  {
    269278    $vtp->addSession( $handle, 'step2' );
     279        if ( isset( $_POST['webmaster'] ))
    270280    $vtp->setVar( $handle, 'step2.f_webmaster', $_POST['webmaster'] );
     281        if ( isset( $_POST['mail_webmaster'] ))
    271282    $vtp->setVar( $handle, 'step2.f_mail_webmaster', $_POST['mail_webmaster']);
    272283    $vtp->closeSession( $handle, 'step2' );
  • trunk/language/english.php

    r229 r345  
    156156$lang['upload_successful'] = 'Picture uploaded with success, an administrator will validate it as soon as possible';
    157157// new or modified in release 1.3
    158 $lang['charset'] = 'ISO_8859-1';
     158$lang['charset'] = 'iso-8859-1';
    159159$lang['no'] = 'no';
    160160$lang['yes'] = 'yes';
     
    536536  $lang['conf_upload_available_info'] = 'Authorizing the upload of pictures by users on the categories of the website (not on a remote server). This is general parameter, it is needed to authorize upload category by category, by default, no category is "uploadable".';
    537537  $lang['install_help'] = 'Need help ? Ask your question on <a href="http://forum.phpwebgallery.net">PhpWebGallery message board</a>.';
     538  // new or modified in release 1.3.1
     539  $lang['cat_unknown_id'] = 'This category is unknown in the database';
     540}
     541
    538542  // new or modified in release 1.4
    539543  $lang['install_end_message'] = 'The configuration of PhpWebGallery is finished, here is the next step<br /><br />
     
    545549</ul>';
    546550  $lang['install_warning'] = 'The file "install.php" is still present. Please remove it from your server. It is not secure to keep it.';
    547 }
     551
    548552?>
  • trunk/language/francais.php

    r229 r345  
    33 *                                francais.php                             *
    44 *                            -------------------                          *
    5  *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
     5 *   application   : PhpWebGallery 1.4 <http://phpwebgallery.net>          *
    66 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
    77 *                                                                         *
     
    148148$lang['upload_successful'] = 'Image uploadée avec succès, un administrateur validera celle-ci dès que possible.';
    149149// new or modified in release 1.3
    150 $lang['charset'] = 'ISO_8859-1';
     150$lang['charset'] = 'iso-8859-1';
    151151$lang['no'] = 'non';
    152152$lang['yes'] = 'oui';
     
    216216$lang['mail_new_comment_subject'] = 'Nouveau commentaire sur le site';
    217217$lang['mail_new_comment_content'] = 'Un nouveau commentaire a été posté sur la galerie. Si vous avez activé la validation des commentaires, il faut d\'abord valider le commentaire dans la zone d\'administration pour le voir apparaître.'."\n\n".'Vous avez accès aux derniers commentaires dans la zone d\'administration.';
     218if (isset($conf))
    218219$lang['about_message'] = '<div style="text-align:center;font-weigh:bold;">Informations sur le PhpWebGallery</div>
    219220<ul>
     
    532533  $lang['help_access'][2] = '2. Sur les pages des permissions (d\'un groupe, d\'utilisateur) la catégorie apparaîtra et vous pourrez autoriser l\'accès ou non.';
    533534  $lang['help_infos'][2] = 'Pour n\'importe quelle question, n\'hésitez pas à consulter le forum ou à y poser une question, sur le site';
     535if (isset($conf))
    534536  $lang['help_infos'][2] = 'Pour n\'importe quelle question, n\'hésitez pas à consulter le <a href="'.$conf['forum_url'].'" style="text-decoration:underline">forum</a> ou à y poser une question, sur le site';
    535537  $lang['step1_err_copy'] = 'Copiez le texte en bleu entre les tirets et collez-le dans le fichier mysql.inc.php qui se trouve dans le répertoire "include" à la base de l\'endroit où vous avez installé PhpWebGallery (le fichier mysql.inc.php ne doit comporter QUE ce qui est en bleu entre les tirets, aucun retour à la ligne ou espace n\'est autorisé)';
    536538  $lang['conf_upload_available_info'] = 'Autoriser l\'ajout d\'image par les utilisateurs dans les catégories du site (pas sur un site distant). Ceci est un paramètre général, il est nécessaire pour autoriser l\'upload catégorie par catégorie.';
    537539  $lang['install_help'] = 'Besoin d\'aide ? Posez votre question sur le <a href="http://forum.phpwebgallery.net">forum de PhpWebGallery</a>.';
    538   // new or modified in release 1.4
     540   // new or modified in release 1.3.1
     541  $lang['cat_unknown_id'] = 'Cette catégorie n\'existe pas dans la base de données';
     542  }
     543 
     544
     545// new or modified in release 1.4
    539546  $lang['install_end_message'] = 'La configuration de l\'application s\'est correctement déroulée, place à la prochaine étape<br /><br />
    540547Par mesure de sécurité, merci de supprimer le fichier "install.php"<br />
    541548Un fois ce fichier supprimé, veuillez suivre ces indications :
    542549<ul>
    543   <li>allez sur la page d\'identification : [ <a href="../identification.php">identification</a> ] et connectez-vous avec le pseudo donné pour le webmaster</li>
     550  <li>allez sur la page d\'identification : [ <a href="./identification.php">identification</a> ] et connectez-vous avec le pseudo donné pour le webmaster</li>
    544551  <li>celui-ci vous permet d\'accéder à la partie administration et aux instructions pour placer les images dans les répertoires.</li>
    545552</ul>';
    546553  $lang['install_warning'] = 'Le fichier "install.php" est encore présent sur votre serveur. Merci de le supprimer. Il pourrait être utilisé par un tiers à des fins malveillantes.';
    547 }
     554
     555
    548556?>
  • trunk/picture.php

    r183 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
    19 
    2019// this page shows the image full size
    21 //----------------------------------------------------------- personnal include
    22 include_once( './include/init.inc.php' );       
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );   
    2323//-------------------------------------------------- access authorization check
    2424check_cat_id( $_GET['cat'] );
    2525check_login_authorization();
    26 $page['plain_structure'] = get_plain_structure();
    2726if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
    2827{
     
    3029}
    3130//---------------------------------------- incrementation of the number of hits
    32 $query = 'UPDATE '.PREFIX_TABLE.'images';
    33 $query.= ' SET hit=hit+1';
     31$query = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1';
    3432$query.= ' WHERE id='.$_GET['image_id'];
    3533$query.= ';';
     
    3836initialize_category( 'picture' );
    3937//------------------------------------- main picture information initialization
    40 $query = 'SELECT id,date_available,comment,hit,keywords';
    41 $query.= ',author,name,file,date_creation,filesize,width,height';
    42 $query.= ',storage_category_id';
    43 if ( is_numeric( $page['cat'] ) )
    44 {
    45   $query.= ',category_id';
    46 }
    47 $query.= ' FROM '.PREFIX_TABLE.'images';
    48 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id';
     38$infos = array( 'id','date_available','comment','hit','keywords','author'
     39                ,'name','file','date_creation','filesize','width','height'
     40                ,'storage_category_id' );
     41
     42$query = 'SELECT '.implode( ',', $infos );
     43if ( is_numeric( $page['cat'] ) ) $query.= ',category_id';
     44$query.= ' FROM '.IMAGES_TABLE;
     45$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
     46$query.= ' ON id = ic.image_id';
    4947$query.= $page['where'];
    5048$query.= ' AND id = '.$_GET['image_id'];
     
    6260}
    6361$row = mysql_fetch_array( $result );
    64 $page['id']             = $row['id'];
    65 $page['file']           = $row['file'];
    66 $page['name']           = $row['name'];
    67 $page['date_available'] = $row['date_available'];
    68 $page['comment']        = $row['comment'];
    69 $page['hit']            = $row['hit'];
    70 $page['author']         = $row['author'];
    71 $page['date_creation']  = $row['date_creation'];
    72 $page['filesize']       = $row['filesize'];
    73 $page['width']          = $row['width'];
    74 $page['height']         = $row['height'];
    75 $page['category_id']    = $row['category_id'];
    76 $page['keywords']       = $row['keywords'];
    77 $page['storage_category_id'] = $row['storage_category_id'];
     62
     63foreach ( $infos as $info ) {
     64  if ( isset( $row[$info] ) ) $page[$info] = $row[$info];
     65  else                        $page[$info] = '';
     66}
     67if ( is_numeric( $page['cat'] ) ) $page['category_id'] = $row['category_id'];
    7868// retrieving the number of the picture in its category (in order)
    7969$query = 'SELECT DISTINCT(id)';
    80 $query.= ' FROM '.PREFIX_TABLE.'images';
    81 $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id';
     70$query.= ' FROM '.IMAGES_TABLE;
     71$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
     72$query.= ' ON id = ic.image_id';
    8273$query.= $page['where'];
    8374$query.= $conf['order_by'];
     
    9889    // verify if the picture is already in the favorite of the user
    9990    $query = 'SELECT COUNT(*) AS nb_fav';
    100     $query.= ' FROM '.PREFIX_TABLE.'favorites';
    101     $query.= ' WHERE image_id = '.$page['id'];
     91    $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$page['id'];
    10292    $query.= ' AND user_id = '.$user['id'];
    10393    $query.= ';';
     
    10696    if ( $row['nb_fav'] == 0 )
    10797    {
    108       $query = 'INSERT INTO '.PREFIX_TABLE.'favorites';
    109       $query.= ' (image_id,user_id) VALUES';
     98      $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES';
    11099      $query.= ' ('.$page['id'].','.$user['id'].')';
    111100      $query.= ';';
     
    115104  if ( $_GET['add_fav'] == 0 )
    116105  {
    117     $query = 'DELETE FROM '.PREFIX_TABLE.'favorites';
    118     $query.= ' WHERE user_id = '.$user['id'];
     106    $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'];
    119107    $query.= ' AND image_id = '.$page['id'];
    120108    $query.= ';';
     
    140128    }
    141129    $query = 'SELECT id';
    142     $query.= ' FROM '.PREFIX_TABLE.'images';
    143     $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
     130        $query.= ' FROM '.IMAGES_TABLE;
     131        $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
    144132    $query.= ' ON id = ic.image_id';
    145133    $query.= $page['where'];
     
    162150  }
    163151}
     152
     153//---------------------------------------------- next picture thumbnail display
     154$next = 0;
     155if ( $page['num'] < $page['cat_nb_images']-1 )
     156{
     157  $next = $page['num'] + 1;
     158  $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id';
     159  $query.= ' FROM '.IMAGES_TABLE;
     160  $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
     161  $query.= ' ON id=ic.image_id';
     162  $query.= $page['where'];
     163  $query.= $conf['order_by'];
     164  $query.= ' LIMIT '.$next.',1';
     165  $query.= ';';
     166  $result = mysql_query( $query );
     167  $row = mysql_fetch_array( $result );
     168
     169  if ( !isset($array_cat_directories[$row['storage_category_id']]))
     170  {
     171    $array_cat_directories[$row['storage_category_id']] =
     172      get_complete_dir( $row['storage_category_id'] );
     173  }
     174  $cat_directory = $array_cat_directories[$row['storage_category_id']];
     175
     176  $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
     177  $next_lien_thumbnail = $cat_directory.'thumbnail/';
     178  $next_lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
     179 
     180  if ( isset( $row['name'] ) and $row['name'] != '' )
     181  {
     182    $next_alt_thumbnail = $row['name'];
     183  }
     184  else
     185  {
     186    $next_alt_thumbnail = $file;
     187  }
     188  $next_title = $lang['next_image']." : ".$next_alt_thumbnail;
     189
     190  $next_url_link = './picture.php?image_id='.$row['id'];
     191  $next_url_link.= '&amp;cat='.$page['cat'];
     192  if ( isset( $_GET['expand'] ) )
     193    $next_url_link.= '&amp;expand='.$_GET['expand'];
     194  if ( $page['cat'] == 'search' )
     195  {
     196    $next_url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
     197  }
     198}
    164199//----------------------------------------------------- template initialization
    165 $vtp = new VTemplate;
     200//
     201// Start output of page
     202//
     203//------------------------------------------------------------------ page title
     204$title = $page['name'];
     205if ( $title == '')
     206{
     207  $title = str_replace("_"," ",get_filename_wo_extension($page['file']));
     208}
     209$refresh = 0;
     210if ( isset( $_GET['slideshow'] ) && isset($next_url_link))
     211{
     212        $refresh= $_GET['slideshow'];
     213        $url_link = $next_url_link;
     214}
     215include('include/page_header.php');
     216
    166217$handle = $vtp->Open( './template/'.$user['template'].'/picture.vtp' );
    167218initialize_template();
     
    171222              'period_seconds' );
    172223templatize_array( $tpl, 'lang', $handle );
    173 $vtp->setGlobalVar( $handle, 'user_template', $user['template'] );
    174 $vtp->setGlobalVar( $handle, 'text_color', $user['couleur_text'] );
    175224//-------------------------------------------------------- slideshow management
    176225if ( isset( $_GET['slideshow'] ) )
     
    200249    $url.= '?image_id='.$page['id'];
    201250    $url.= '&amp;cat='.$page['cat'];
    202     $url.= '&amp;expand='.$_GET['expand'];
     251        if (isset($_GET['expand']))
     252            $url.= '&amp;expand='.$_GET['expand'];
    203253    if ( $page['cat'] == 'search' )
    204254    {
     
    212262  $vtp->closeSession( $handle, 'start_slideshow' );
    213263}
    214 //------------------------------------------------------------------ page title
    215 if ( $page['name'] != '' )
    216 {
    217   $vtp->setGlobalVar( $handle, 'page_title', $page['name'] );
    218 }
    219 else
    220 {
    221   $page_title = str_replace("_"," ",get_filename_wo_extension($page['file']));
    222   $vtp->setGlobalVar( $handle, 'page_title', $page_title );
    223 }
     264
    224265//-------------------------------------------------- previous picture thumbnail
    225266if ( $page['num'] >= 1 )
     
    227268  $prev = $page['num'] - 1;
    228269  $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id';
    229   $query.= ' FROM '.PREFIX_TABLE.'images';
    230   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
     270  $query.= ' FROM '.IMAGES_TABLE;
     271  $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
     272  $query.= ' ON id=ic.image_id';
    231273  $query.= $page['where'];
    232274  $query.= $conf['order_by'];
     
    236278  $row = mysql_fetch_array( $result );
    237279
    238   if ( $array_cat_directories[$row['storage_category_id']] == '' )
     280  if ( !isset($array_cat_directories[$row['storage_category_id']]) )
    239281  {
    240282    $array_cat_directories[$row['storage_category_id']] =
     
    244286
    245287  $file = substr( $row['file'], 0, strrpos ( $row['file'], '.' ) );
    246   $lien_thumbnail = $cat_directory.'/thumbnail/';
     288  $lien_thumbnail = $cat_directory.'thumbnail/';
    247289  $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
    248290
    249291  $prev_title = $lang['previous_image'].' : ';
    250   $alt_thumbnaill = '';
    251   if ( $row['name'] != '' ) $alt_thumbnail = $row['name'];
    252   else                      $alt_thumbnail = $file;
     292
     293  if ( isset( $row['name'] ) and $row['name'] != '' )
     294    $alt_thumbnail = $row['name'];
     295  else
     296    $alt_thumbnail = $file;
     297
    253298  $prev_title.= $alt_thumbnail;
    254299 
    255300  $url_link = './picture.php?image_id='.$row['id'].'&amp;cat='.$page['cat'];
    256   $url_link.= '&amp;expand='.$_GET['expand'];
     301  if ( isset( $_GET['expand'] ) ) $url_link.= '&amp;expand='.$_GET['expand'];
    257302  if ( $page['cat'] == 'search' )
    258303  {
     
    283328}
    284329
    285 if ( $array_cat_directories[$page['storage_category_id']] == '' )
     330if ( !isset($array_cat_directories[$page['storage_category_id']]) )
    286331{
    287332  $array_cat_directories[$page['storage_category_id']] =
     
    291336
    292337$n = $page['num'] + 1;
    293 $intitule_titre = replace_space( $intitule_cat." - " ).$n.'/'.
     338$intitule_titre = replace_space( $intitule_cat." - " ).$n.'/';
    294339$intitule_titre.= $page['cat_nb_images']."<br />";
    295340if ( $page['name'] != "" )
     
    330375       
    331376$url_link = './category.php?cat='.$page['cat'].'&amp;';
    332 $url_link.= 'num='.$page['num'].'&amp;expand='.$_GET['expand'];
     377$url_link.= 'num='.$page['num'];
     378if (isset($_GET['expand']))
     379        $url_link.='&amp;expand='.$_GET['expand'];
    333380if ( $page['cat'] == 'search' )
    334381{
     
    338385$vtp->setGlobalVar( $handle, 'picture_width', $final_width );
    339386$vtp->setGlobalVar( $handle, 'picture_height', $final_height );
    340 $vtp->setGlobalVar( $handle, 'picture_border_color', $user['couleur_text'] );
    341387$vtp->setGlobalVar( $handle, 'picture_src', $lien_image );
    342388$vtp->setGlobalVar( $handle, 'picture_alt', $page['file'] );
     
    427473  $keywords = explode( ',', $page['keywords'] );
    428474  $content = '';
    429   $url = './category.php?cat=search&amp;expand='.$_GET['expand'];
     475  $url = './category.php?cat=search';
     476  if ( isset( $_GET['expand'] ) ) $url.= '&amp;expand='.$_GET['expand'];
    430477  $url.= '&amp;mode=OR&amp;search=';
    431478  foreach ( $keywords as $i => $keyword ) {
     
    443490$vtp->closeSession( $handle, 'info_line' );
    444491//------------------------------------------------------- favorite manipulation
    445 if ( $page['cat'] != 'fav' and !$user['is_the_guest'] )
    446 {
    447   $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
    448   $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=1';
    449   if ( $page['cat'] == 'search' )
    450   {
    451     $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    452   }
    453   $vtp->addSession( $handle, 'favorite' );
    454   $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
    455   $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] );
    456   $vtp->setVar( $handle, 'favorite.src',
    457                 './template/'.$user['template'].'/theme/favorite.gif' );
    458   $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['add_favorites_alt'].' ]' );
    459   $vtp->closeSession( $handle, 'favorite' );
    460 }
    461 if ( $page['cat'] == 'fav' )
    462 {
    463   $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
    464   $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=0';
    465   $vtp->addSession( $handle, 'favorite' );
    466   $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
    467   $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] );
    468   $vtp->setVar( $handle, 'favorite.src',
    469                 './template/'.$user['template'].'/theme/del_favorite.gif' );
    470   $vtp->setVar( $handle, 'favorite.alt','[ '.$lang['del_favorites_alt'].' ]' );
    471   $vtp->closeSession( $handle, 'favorite' );
     492if ( !$user['is_the_guest'] )
     493{
     494  // verify if the picture is already in the favorite of the user
     495  $query = 'SELECT COUNT(*) AS nb_fav';
     496  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$page['id'];
     497  $query.= ' AND user_id = '.$user['id'].';';
     498  $result = mysql_query( $query );
     499  $row = mysql_fetch_array( $result );
     500  if (!$row['nb_fav'])
     501  {
     502    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
     503    if (isset($_GET['expand']))
     504      $url.= '&amp;expand='.$_GET['expand'];
     505    $url.='&amp;add_fav=1';
     506    if ( $page['cat'] == 'search' )
     507    {
     508      $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
     509    }
     510    $vtp->addSession( $handle, 'favorite' );
     511    $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
     512    $vtp->setVar( $handle, 'favorite.title', $lang['add_favorites_hint'] );
     513    $vtp->setVar( $handle, 'favorite.src',
     514                  './template/'.$user['template'].'/theme/favorite.gif' );
     515    $vtp->setVar($handle,'favorite.alt','[ '.$lang['add_favorites_alt'].' ]');
     516    $vtp->closeSession( $handle, 'favorite' );
     517  }
     518  else
     519  {
     520    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
     521    $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=0';
     522    $vtp->addSession( $handle, 'favorite' );
     523    $vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
     524    $vtp->setVar( $handle, 'favorite.title', $lang['del_favorites_hint'] );
     525    $vtp->setVar( $handle, 'favorite.src',
     526                  './template/'.$user['template'].'/theme/del_favorite.gif' );
     527    $vtp->setVar($handle,'favorite.alt','[ '.$lang['del_favorites_alt'].' ]');
     528    $vtp->closeSession( $handle, 'favorite' );
     529  }
    472530}
    473531//------------------------------------ admin link for information modifications
     
    480538  $vtp->setVar( $handle, 'modification.name', $lang['link_info_image'] );
    481539}
    482 //---------------------------------------------- next picture thumbnail display
    483 if ( $page['num'] < $page['cat_nb_images']-1 )
    484 {
    485   $next = $page['num'] + 1;
    486   $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id';
    487   $query.= ' FROM '.PREFIX_TABLE.'images';
    488   $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
    489   $query.= $page['where'];
    490   $query.= $conf['order_by'];
    491   $query.= ' LIMIT '.$next.',1';
    492   $query.= ';';
    493   $result = mysql_query( $query );
    494   $row = mysql_fetch_array( $result );
    495 
    496   if ( $array_cat_directories[$row['storage_category_id']] == '' )
    497   {
    498     $array_cat_directories[$row['storage_category_id']] =
    499       get_complete_dir( $row['storage_category_id'] );
    500   }
    501   $cat_directory = $array_cat_directories[$row['storage_category_id']];
    502 
    503   $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
    504   $lien_thumbnail = $cat_directory.'thumbnail/';
    505   $lien_thumbnail.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
    506  
    507   if ( $row['name'] != "" )
    508   {
    509     $alt_thumbnail = $row['name'];
    510   }
    511   else
    512   {
    513     $alt_thumbnail = $file;
    514   }
    515   $next_title = $lang['next_image']." : ".$alt_thumbnail;
    516 
    517   $url_link = './picture.php?image_id='.$row['id'].'&amp;cat='.$page['cat'];
    518   $url_link.= '&amp;expand='.$_GET['expand'];
    519   if ( $page['cat'] == 'search' )
    520   {
    521     $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
    522   }
     540
     541if ( $next )
     542{
    523543  // sending vars for display
    524544  $vtp->addSession( $handle,   'next' );
    525   $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $url_link ) );
     545  $vtp->setGlobalVar( $handle, 'next.url', add_session_id( $next_url_link ) );
    526546  $vtp->setGlobalVar( $handle, 'next.title', $next_title );
    527   $vtp->setGlobalVar( $handle, 'next.src', $lien_thumbnail );
    528   $vtp->setGlobalVar( $handle, 'next.alt', $alt_thumbnail );
     547  $vtp->setGlobalVar( $handle, 'next.src', $next_lien_thumbnail );
     548  $vtp->setGlobalVar( $handle, 'next.alt', $next_alt_thumbnail );
    529549  $vtp->closeSession( $handle, 'next' );
    530   // slideshow
    531   if ( isset( $_GET['slideshow'] ) )
    532   {
    533     $vtp->addSession( $handle, 'refresh' );
    534     $vtp->setVar( $handle, 'refresh.time', $_GET['slideshow'] );
    535     $url = $url_link.'&amp;slideshow='.$_GET['slideshow'];
    536     $vtp->setVar( $handle, 'refresh.url', add_session_id( $url ) );
    537     $vtp->closeSession( $handle, 'refresh' );
    538   }
    539 }
    540 else
    541 {
    542   $vtp->addSession( $handle, 'previous_empty' );
    543   $vtp->closeSession( $handle, 'previous_empty' );
     550}
     551else
     552{
     553  $vtp->addSession( $handle, 'next_empty' );
     554  $vtp->closeSession( $handle, 'next_empty' );
    544555}
    545556//---------------------------------------------------- users's comments display
     
    577588      // anti-flood system
    578589      $reference_date = time() - $conf['anti-flood_time'];
    579       $query = 'SELECT id';
    580       $query.= ' FROM '.PREFIX_TABLE.'comments';
     590      $query = 'SELECT id FROM '.COMMENTS_TABLE;
    581591      $query.= ' WHERE date > '.$reference_date;
    582592      $query.= " AND author = '".$author."'";
     
    585595           or $conf['anti-flood_time'] == 0 )
    586596      {
    587         $query = 'INSERT INTO '.PREFIX_TABLE.'comments';
     597        $query = 'INSERT INTO '.COMMENTS_TABLE;
    588598        $query.= ' (author,date,image_id,content,validated) VALUES';
    589599        $query.= ' (';
     
    632642       and $user['status'] == 'admin' )
    633643  {
    634     $query = 'DELETE FROM '.PREFIX_TABLE.'comments';
    635     $query.= ' WHERE id = '.$_GET['del'].';';
     644    $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';';
    636645    mysql_query( $query );
    637646  }
    638647  // number of comment for this picture
    639648  $query = 'SELECT COUNT(*) AS nb_comments';
    640   $query.= ' FROM '.PREFIX_TABLE.'comments';
    641   $query.= ' WHERE image_id = '.$page['id'];
     649  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['id'];
    642650  $query.= " AND validated = 'true'";
    643651  $query.= ';';
     
    646654  // navigation bar creation
    647655  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$page['id'];
    648   $url.= '&amp;expand='.$_GET['expand'];
     656  if (isset($_GET['expand']))
     657        $url.= '&amp;expand='.$_GET['expand'];
    649658  if ( $page['cat'] == 'search' )
    650659  {
     
    670679
    671680  $query = 'SELECT id,author,date,image_id,content';
    672   $query.= ' FROM '.PREFIX_TABLE.'comments';
    673   $query.= ' WHERE image_id = '.$page['id'];
     681  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['id'];
    674682  $query.= " AND validated = 'true'";
    675683  $query.= ' ORDER BY date ASC';
     
    724732    {
    725733      $vtp->addSession( $handle, 'author_known' );
    726       $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] );
     734          if (isset($user['pseudo']))
     735              $vtp->setVar( $handle, 'author_known.value', $user['pseudo'] );
    727736      $vtp->closeSession( $handle, 'author_known' );
    728737    }
     
    742751$code = $vtp->Display( $handle, 0 );
    743752echo $code;
     753
     754include('include/page_tail.php');
    744755?>
  • trunk/profile.php

    r60 r345  
    1818 ***************************************************************************/
    1919// customize appearance of the site for a user
    20 //----------------------------------------------------------- personnal include
    21 include_once( './include/init.inc.php' );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    2223//-------------------------------------------------- access authorization check
    2324check_login_authorization();
     
    2829  exit();
    2930}
    30 //-------------------------------------------------------------- initialization
    31 check_cat_id( $_GET['cat'] );
    3231//------------------------------------------------------ update & customization
    3332$infos = array( 'nb_image_line', 'nb_line_page', 'language',
     
    7069  }
    7170  $mail_error = validate_mail_address( $_POST['mail_address'] );
    72   if ( $mail_error != '' )
    73   {
    74     array_push( $errors, $mail_error );
    75   }
    76   if ( $_POST['use_new_pwd'] == 1 )
    77   {
    78     // password must be the same as its confirmation
    79     if ( $_POST['password'] != $_POST['passwordConf'] )
    80     {
    81       array_push( $errors, $lang['reg_err_pass'] );
    82     }
    83   }
    84 
     71  if ( $mail_error != '' ) array_push( $errors, $mail_error );
     72  // password must be the same as its confirmation
     73  if ( isset( $_POST['use_new_pwd'] )
     74       and $_POST['password'] != $_POST['passwordConf'] )
     75    array_push( $errors, $lang['reg_err_pass'] );
     76 
    8577  if ( count( $errors ) == 0 )
    8678  {
     
    9890    mysql_query( $query );
    9991
    100     if ( $_POST['use_new_pwd'] == 1 )
     92    if ( isset( $_POST['use_new_pwd'] ) )
    10193    {
    10294      $query = 'UPDATE '.PREFIX_TABLE.'users';
     
    10698      mysql_query( $query );
    10799    }
    108     if ( $_POST['create_cookie'] == 1 )
     100    if ( isset( $_POST['create_cookie'] ) )
    109101    {
    110102      setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'],
     
    118110    }
    119111    // redirection
    120     $url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand'];
    121     if ( $page['cat'] == 'search' )
    122     {
    123       $url.= '&search='.$_GET['search'].'&mode='.$_GET['mode'];
    124     }
    125     if ( $_POST['create_cookie'] != 1 ) $url = add_session_id( $url, true );
     112    $url = 'category.php';
     113    if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true );
    126114    header( 'Request-URI: '.$url ); 
    127115    header( 'Content-Location: '.$url ); 
     
    131119}
    132120//----------------------------------------------------- template initialization
    133 $vtp = new VTemplate;
     121//
     122// Start output of page
     123//
     124$title = $lang['customize_page_title'];
     125include('include/page_header.php');
     126
    134127$handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' );
    135128initialize_template();
    136 $tpl = array( 'customize_page_title','customize_title','password','new',
     129$tpl = array( 'customize_title','password','new',
    137130              'reg_confirm','submit','create_cookie' );
    138131templatize_array( $tpl, 'lang', $handle );
    139132//----------------------------------------------------------------- form action
    140 $url = './profile.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
    141 if ( $page['cat'] == 'search' )
    142 {
    143   $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    144 }
     133$url = './profile.php';
    145134$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
    146135//-------------------------------------------------------------- errors display
     
    202191  $vtp->addSession( $handle, 'select' );
    203192  $vtp->setVar( $handle, 'select.name', 'template' );
    204   $option = get_dirs( './template/' );
     193  $option = get_dirs( './template' );
    205194  for ( $i = 0; $i < sizeof( $option ); $i++ )
    206195  {
     
    379368$code = $vtp->Display( $handle, 0 );
    380369echo $code;
     370include('include/page_tail.php');
    381371?>
  • trunk/register.php

    r105 r345  
    1818 ***************************************************************************/
    1919
    20 //----------------------------------------------------------- personnal include
    21 include_once( './include/init.inc.php' );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    2223//-------------------------------------------------- access authorization check
    2324if ( $conf['access'] == "restricted" )
     
    4344}
    4445//----------------------------------------------------- template initialization
    45 $vtp = new VTemplate;
     46//
     47// Start output of page
     48//
     49$title= $lang['register_page_title'];
     50include('include/page_header.php');
     51
    4652$handle = $vtp->Open( './template/'.$user['template'].'/register.vtp' );
    4753// language
    48 $vtp->setGlobalVar( $handle, 'register_page_title',
    49                     $lang['register_page_title'] );
    5054$vtp->setGlobalVar( $handle, 'register_title',   $lang['register_title'] );
    5155$vtp->setGlobalVar( $handle, 'ident_guest_visit',$lang['ident_guest_visit'] );
     
    7175$vtp->addSession( $handle, 'text' );
    7276$vtp->setVar( $handle, 'text.name', 'login' );
    73 $vtp->setVar( $handle, 'text.value', $_POST['login'] );
     77if (isset( $_POST['login']))
     78        $vtp->setVar( $handle, 'text.value', $_POST['login'] );
    7479$vtp->closeSession( $handle, 'text' );
    7580$vtp->closeSession( $handle, 'line' );
     
    95100$vtp->addSession( $handle, 'text' );
    96101$vtp->setVar( $handle, 'text.name', 'mail_address' );
    97 $vtp->setVar( $handle, 'text.value', $_POST['mail_address'] );
     102if (isset( $_POST['mail_address']))
     103        $vtp->setVar( $handle, 'text.value', $_POST['mail_address'] );
    98104$vtp->closeSession( $handle, 'text' );
    99105$vtp->closeSession( $handle, 'line' );
     
    101107$code = $vtp->Display( $handle, 0 );
    102108echo $code;
     109include('include/page_tail.php');
    103110?>
  • trunk/search.php

    r57 r345  
    1818 ***************************************************************************/
    1919
    20 //----------------------------------------------------------- personnal include
    21 include_once( './include/init.inc.php' );
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    2223//-------------------------------------------------- access authorization check
    2324check_login_authorization();
     
    5455}
    5556//----------------------------------------------------- template initialization
    56 $vtp = new VTemplate;
     57//
     58// Start output of page
     59//
     60$title= $lang['search_title'];
     61include('include/page_header.php');
     62
    5763$handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' );
    5864initialize_template();
    59 
    6065$tpl = array( 'search_title','search_return_main_page','submit',
    6166              'search_comments' );
     
    8287$vtp->setVar( $handle, 'text.size', '40' );
    8388$vtp->setVar( $handle, 'text.name', 'search' );
     89if (isset($_POST['search']))
    8490$vtp->setVar( $handle, 'text.value', $_POST['search'] );
    8591$vtp->closeSession( $handle, 'text' );
     
    9399$vtp->setVar( $handle, 'radio.value', 'OR' );
    94100$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
    95 if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
     101if (!isset($_POST['mode']) || $_POST['mode'] == 'OR' )
    96102{
    97103  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     
    103109$vtp->setVar( $handle, 'radio.value', 'AND' );
    104110$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
    105 if ( $_POST['mode'] == 'AND' )
     111if ( isset($_POST['mode']) && $_POST['mode'] == 'AND' )
    106112{
    107113  $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
     
    117123echo $code;
    118124//------------------------------------------------------------ log informations
    119 pwg_log( 'search', $page['title'] );
     125pwg_log( 'search', $title );
    120126mysql_close();
     127include('include/page_tail.php');
    121128?>
  • trunk/template/default/about.vtp

    r28 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#about_page_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; charset={#charset}" />
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    2820      </tr>
    2921    </table>
    30     {#footer}
    31   </body>
    32 </html>
  • trunk/template/default/admin/cat_list.vtp

    r227 r345  
    99</div>
    1010<!--/VTP_errors-->
    11 <table style="width:100%;">
    12 <tr>
    13   <td colspan="8" style="text-align:center;padding-top:10px;padding-bottom:10px;">
     11<div style="text-align:center;padding-top:10px;padding-bottom:5px;">
    1412  <form action="" method="post">
    1513    {#cat_add} <input type="text" name="virtual_name" />
    1614    {#cat_parent}
     15    <!--VTP_associate_LOV-->
    1716    <select name="associate">
    1817      <!--VTP_associate_cat-->
     
    2019      <!--/VTP_associate_cat-->
    2120    </select>
     21    <!--/VTP_associate_LOV-->
     22    <!--VTP_associate_text-->
     23      <input type="text" name="associate" />
     24    <!--/VTP_associate_text-->
    2225   <input type="submit" value="{#submit}" name="submit" />
    2326  </form>
    24   </td>
    25 </tr>
     27</div>
     28<table style="width:100%;">
    2629<!--VTP_cat-->
    2730<tr>
    2831  <{#td} style="width:50%;text-align:left;">
    2932    <a name="{#id}"></a>
    30     {#indent}<img src="./template/{#user_template}/admin/images/puce.gif" alt="&gt;" />
     33    {#indent}
     34    <!--VTP_bullet_collapsed--><a href="{#link}"><img src="../template/{#user_template}/admin/images/collapsed.gif" style="border:none;" alt="&gt;" /></a><!--/VTP_bullet_collapsed-->
     35    <!--VTP_bullet_expanded--><a href="{#link}"><img src="../template/{#user_template}/admin/images/expanded.gif" style="border:none;" alt="&gt;" /></a><!--/VTP_bullet_expanded-->
     36    <!--VTP_bullet_wo_link--><img src="../template/{#user_template}/admin/images/collapsed.gif" style="border:none;" alt="&gt;" /><!--/VTP_bullet_wo_link-->
    3137    &nbsp;{#name} [
    3238    <!--VTP_storage-->
  • trunk/template/default/admin/cat_modify.vtp

    r68 r345  
    6565      <td>{#cat_parent}</td>
    6666      <td class="row2">
     67        <!--VTP_associate_LOV-->
    6768        <select name="associate">
    6869          <!--VTP_associate_cat-->
    69           <option value="{#value}"{#selected}>{#content}</option>
     70          <option value="{#value}">{#content}</option>
    7071          <!--/VTP_associate_cat-->
    7172        </select>
     73        <!--/VTP_associate_LOV-->
     74        <!--VTP_associate_text-->
     75        <input type="text" name="associate" value="{#value}" />
     76        <!--/VTP_associate_text-->
    7277      </td>
    7378    </tr>
  • trunk/template/default/admin/comments.vtp

    r227 r345  
    2525<!--/VTP_start_form-->
    2626<!--VTP_picture-->
    27 <div style="border:2px solid #D3DCE3;margin:2px;">
     27<div style="border:2px solid #D3DCE3;margin:3px;">
    2828  <table style="width:100%;">
    2929    <tr>
  • trunk/template/default/admin/configuration.vtp

    r61 r345  
    4848    <!--VTP_title_line-->
    4949    <tr>
    50       <th colspan="3" align="center">{#title}</th>
     50      <th colspan="3">{#title}</th>
    5151    </tr>
    5252    <!--/VTP_title_line-->
  • trunk/template/default/admin/infos_image.vtp

    r227 r345  
     1<!--VTP_errors-->
     2<div class="errors">
     3  <div class="errors_title">{#errors_title}</div>
     4  <ul>
     5    <!--VTP_li-->
     6    <li>{#content}</li>
     7    <!--/VTP_li-->
     8  </ul>
     9</div>
     10<!--/VTP_errors-->
    111<form method="post" action="{#form_action}">
    212  <table width="100%">
     
    7686        <img src="./template/{#user_template}/admin/images/arrow_select.gif" alt="&lt;" />
    7787        {#infoimage_associate}
     88        <!--VTP_associate_LOV-->
    7889        <select name="associate">
    7990          <!--VTP_associate_cat-->
     
    8192          <!--/VTP_associate_cat-->
    8293        </select>
    83     </td>
    84   </tr>
     94        <!--/VTP_associate_LOV-->
     95        <!--VTP_associate_text-->
     96        <input type="text" name="associate" />
     97        <!--/VTP_associate_text-->
     98      </td>
     99    </tr>
    85100    <tr>
    86101      <td colspan="6" style="text-align:center;">
  • trunk/template/default/admin/picture_modify.vtp

    r227 r345  
    7777                <tr>
    7878                  <td>{#infoimage_associate}
     79                    <!--VTP_associate_LOV-->
    7980                    <select name="associate">
    8081                      <!--VTP_associate_cat-->
    8182                      <option value="{#value}">{#content}</option>
    8283                      <!--/VTP_associate_cat-->
     84                    </select>
     85                    <!--/VTP_associate_LOV-->
     86                    <!--VTP_associate_text-->
     87                    <input type="text" name="associate" />
     88                    <!--/VTP_associate_text-->
    8389                    </select>
    8490                  </td>
  • trunk/template/default/admin/stats.vtp

    r227 r345  
    1 <style>
    2       .commentsAuthor,.commentsTitle,.commentsInfos,.commentsContent,.commentsNavigationBar {
    3         color:{#text_color};
    4         font-family:arial,sans-Serif;
    5         font-size:12px;
    6       }
    7       .commentsTitle,.commentsAuthor {
    8         text-align:center;
    9         font-weight:bold;
    10       }
    11       .commentsInfos {
    12         text-align:right;
    13         margin:3px 3px 3px 10px;
    14         font-size:11px;
    15       }
    16       .commentsContent {
    17         margin:10px;
    18       }
    19       .commentsTitle {
    20         margin-top:15px;
    21       }
    22       .commentsAuthor {
    23         margin:5px;
    24       }
    25       .commentsNavigationBar {
    26         margin:10px;
    27       }
    28       .tableComment {
    29         width:100%;
    30         border:2px solid #006699;
    31         margin:10px;
    32       }
    33       .cellAuthor {
    34         border-right:1px solid #006699;
    35         width:100px;
    36       }
    37       .cellInfo {
    38         border-bottom:1px solid #006699;
    39       }
    40       .imgLink {
    41         border:1px solid black;
    42       }
    43 </style>
    441<div style="text-align:center;margin-top:5px;">
    452  <!--VTP_last_day_option-->
  • trunk/template/default/category.vtp

    r128 r345  
    1 <html>
    2   <head>
    3     <meta http-equiv="Content-Type" content="text/html; charset={#charset}" />
    4     {#style}
    5     <title>{#title}</title>
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;">
    102      <tr>
    113        <td valign="top" style="width:1%;padding:10px;">
    124          {#frame_start}100%{#frame_begin}
    13             <div class="titreMenu">{#categories}</div>
     5            <div class="titreMenu">
     6              <a href="{#home_url}">{#categories}</a>
     7            </div>
    148            <div class="menu">
    159              <!--VTP_category-->{#indent}<!--VTP_bullet_w_link--><a href="{#bullet_link}"><img src="{#bullet_url}" style="border:none;" alt="&gt;" /></a><!--/VTP_bullet_w_link--><!--VTP_bullet_wo_link--><img src="{#bullet_url}" style="border:none;" alt="&gt;" /><!--/VTP_bullet_wo_link-->&nbsp;<a href="{#link_url}"><span title="{#hint_category}" style="{#name_style}">{#link_name}</span>&nbsp;<span class="menuInfoCat">[&nbsp;<!--VTP_subcat--><span title="{#nb_subcats} {#sub-cat}">{#nb_subcats}</span>&nbsp;-&nbsp;<!--/VTP_subcat--><span title="{#total_cat} {#images_available}">{#total_cat}</span>&nbsp;]</span></a>{#cat_icon}<br />
     
    1711              <div class="totalImages">[&nbsp;{#nb_total_pictures}&nbsp;{#total}&nbsp;]</div>
    1812              <!--VTP_favorites-->
    19               <br />&nbsp;<img src="{#lien_collapsed}" al="&gt;" />&nbsp;<a href="{#url}"><span title="{#favorite_cat_hint}" style="font-weight:bold;">{#favorite_cat}</span></a>&nbsp;<span class="menuInfoCat">[&nbsp;{#nb_favorites}&nbsp;]</span>
     13              <br />&nbsp;<img src="{#lien_collapsed}" alt="&gt;" />&nbsp;<a href="{#url}"><span title="{#favorite_cat_hint}" style="font-weight:bold;">{#favorite_cat}</span></a>&nbsp;<span class="menuInfoCat">[&nbsp;{#nb_favorites}&nbsp;]</span>
    2014              <!--/VTP_favorites-->
    21               <br />&nbsp;<img src="{#lien_collapsed}" al="&gt;" />&nbsp;<span style="font-weight:bold;">{#stats}</span></a>
    22               <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="{#lien_collapsed}" al="&gt;" />&nbsp;<a href="{#most_visited_url}"><span title="{#most_visited_cat_hint}" style="font-weight:bold;">{#top_number}&nbsp;{#most_visited_cat}</span></a>
    23               <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="{#lien_collapsed}" al="&gt;" />&nbsp;<a href="{#recent_url}"><span title="{#recent_cat_hint}" style="font-weight:bold;">{#recent_cat}</span></a> {#icon_short}
     15              <br />&nbsp;<img src="{#lien_collapsed}" alt="&gt;" />&nbsp;<span style="font-weight:bold;">{#stats}</span>
     16              <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="{#lien_collapsed}" alt="&gt;" />&nbsp;<a href="{#most_visited_url}"><span title="{#most_visited_cat_hint}" style="font-weight:bold;">{#top_number}&nbsp;{#most_visited_cat}</span></a>
     17              <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="{#lien_collapsed}" alt="&gt;" />&nbsp;<a href="{#recent_url}"><span title="{#recent_cat_hint}" style="font-weight:bold;">{#recent_cat}</span></a> {#icon_short}
    2418            </div>
    2519          {#frame_end}
     
    3226              <!--/VTP_summary-->
    3327              <!--VTP_upload-->
    34               <br />&nbsp;<img src="{#lien_collapsed}" alt="&gt;"/>&nbsp;<a href="{#url}" class="back">{#upload_picture}</a>
     28              <br />&nbsp;<img src="{#lien_collapsed}" alt="&gt;"/>&nbsp;<a href="{#url}">{#upload_picture}</a>
    3529              <!--/VTP_upload-->
    3630            </div>
     
    5549                           alt="{#alt}"
    5650                           title="{#title}"
    57                            class="imgLink"/><br />
    58                       {#name}
    59                       </a>
     51                           class="imgLink"/></a>
     52                      <br />
     53                      <a href="{#url}" class="back">{#name}</a>
    6054                      {#icon}
    6155                      <!--VTP_nb_comments-->
     
    10397      </tr>
    10498    </table>
    105     <div class="copyright">{#generation_time} {#time}</div>
    106     <!-- Please, do not remove this copyright. If you really want to,
    107          contact me pierrick@z0rglub.com to find a solution on how
    108          to show the origin of the script...-->
    109     <div class="copyright">Powered by <a href="{#site_url}" class="back">PhpWebGallery</a> {#version}</div>
    110     {#footer}
    111   </body>
    112 </html>
  • trunk/template/default/comments.vtp

    r166 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#title_comments}</title>
    5     <meta http-equiv="Content-Type" content="text/html; {#charset}">
    6     <!-- Specific style to comments.php-->
    7     <style type="text/css">
    8       .commentsAuthor,.commentsTitle,.commentsInfos,.commentsContent,.commentsNavigationBar {
    9         color:{#text_color};
    10         font-family:arial,sans-Serif;
    11         font-size:12px;
    12       }
    13       .commentsTitle,.commentsAuthor {
    14         text-align:center;
    15         font-weight:bold;
    16       }
    17       .commentsInfos {
    18         margin:3px 3px 3px 10px;
    19         font-size:11px;
    20         text-align:right;
    21       }
    22       .commentsContent {
    23         margin:10px;
    24       }
    25       .commentsTitle {
    26         margin-top:15px;
    27       }
    28       .commentsAuthor {
    29         margin:5px;
    30       }
    31       .commentsNavigationBar {
    32         margin:10px;
    33       }
    34       .tableComment {
    35         width:100%;
    36         border:2px solid {#text_color};
    37         margin:10px;
    38       }
    39       .cellAuthor {
    40         border-right:1px solid {#text_color};
    41         width:100px;
    42       }
    43       .cellInfo {
    44         border-bottom:1px solid {#text_color};
    45       }
    46     </style>
    47   </head>
    48   <body>
    49     {#header}
    501    <table style="width:100%;">
    512      <tr align="center" valign="middle">
     
    7324  <table style="width:100%;">
    7425    <tr>
    75      <td valign="top" width="1px">
     26     <td valign="top" style="width:15%;">
    7627       <!-- the thumbnail of the picture, linked to the full size page -->
    7728       <a href="{#thumb_url}" title="{#thumb_title}">
     
    7930       </a>
    8031     </td>
    81      <td style="padding:2px;">
    82        <div style="font-weight:bold;padding-left:10px;">{#title}</div>
     32     <td style="padding:10px;width:85%;">
     33       <div style="font-weight:bold;padding-left:10px;text-align:left;">{#title}</div>
    8334       <!--VTP_comment-->
    84        <table style="width:100%;">
    85          <tr>
    86            <td>
    8735             <table class="tableComment">
    8836               <tr>
     
    10250               </tr>
    10351             </table>
    104            </td>
    105          </tr>
    106        </table>
    10752       <!--/VTP_comment-->
    10853     </td>
     
    11560      </tr>
    11661    </table>
    117     {#footer}
    118   </body>
    119 </html>
  • trunk/template/default/htmlfunctions.inc.php

    r57 r345  
    1818 ***************************************************************************/
    1919
    20 include( PREFIX_INCLUDE.'./template/'.$user['template'].'/theme/conf.php' );
     20//include( PREFIX_INCLUDE.'./template/'.$user['template'].'/theme/conf.php' );
    2121$user['lien_expanded']='./template/'.$user['template'].'/theme/expanded.gif';
    2222$user['lien_collapsed']='./template/'.$user['template'].'/theme/collapsed.gif';
    23 include_once( PREFIX_INCLUDE.'./template/'.$user['template'].'/style.inc.php');
     23//include_once( PREFIX_INCLUDE.'./template/'.$user['template'].'/style.inc.php');
    2424
    2525function get_icon( $date_comparaison )
     
    161161  global $vtp, $handle, $user, $lang;
    162162
    163   $vtp->setGlobalVar( $handle, 'charset', $lang['charset'] );
    164   $vtp->setGlobalVar( $handle, 'style', $user['style'] );
     163 // $vtp->setGlobalVar( $handle, 'charset', $lang['charset'] );
     164  //$vtp->setGlobalVar( $handle, 'style', $user['style'] );
    165165  $vtp->setGlobalVar( $handle, 'frame_start', get_frame_start() );
    166166  $vtp->setGlobalVar( $handle, 'frame_begin', get_frame_begin() );
    167167  $vtp->setGlobalVar( $handle, 'frame_end',   get_frame_end() );
    168   $vtp->setVarF( $handle, 'header',
    169                  './template/'.$user['template'].'/header.htm' );
    170   $vtp->setVarF( $handle, 'footer',
    171                  './template/'.$user['template'].'/footer.htm' );
     168 //$vtp->setVarF( $handle, 'header',
     169 //                './template/'.$user['template'].'/header.htm' );
     170  //$vtp->setVarF( $handle, 'footer',
     171   //              './template/'.$user['template'].'/footer.htm' );
    172172}
    173173
     
    178178  $vtp->addSession( $handle, 'category' );
    179179  $vtp->setVar( $handle, 'category.indent', $indent );
    180 
    181   if ( $user['expand'] or count( $category['subcats'] ) == 0 )
     180  if ( $user['expand'] or $category['nb_sub_categories'] == 0 )
    182181  {
    183182    $vtp->addSession( $handle, 'bullet_wo_link' );
     
    189188  {
    190189    $vtp->addSession( $handle, 'bullet_w_link' );
    191     $url = './category.php?cat='.$page['cat'];
     190    $url = './category.php';
     191        if (isset($page['cat']))
     192        {
     193        $url .='?cat='.$page['cat'];
    192194    $url.= '&amp;expand='.$category['expand_string'];
    193     if ( $page['cat'] == 'search' )
    194     {
    195       $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
    196     }
     195        }
     196        else if ($category['expand_string']<>'')
     197        {
     198                $url.= '?expand='.$category['expand_string'];
     199        }
    197200    $vtp->setVar( $handle, 'bullet_w_link.bullet_link', add_session_id($url) );
    198201    if ( $category['expanded'] )
     
    221224    $vtp->setVar( $handle, 'category.name_style', 'font-weight:bold;' );
    222225  }
    223   if ( count( $category['subcats'] ) > 0 )
     226  if ( $category['nb_sub_categories'] > 0 )
    224227  {
    225228    $vtp->addSession( $handle, 'subcat' );
    226     $vtp->setVar( $handle, 'subcat.nb_subcats', count($category['subcats']) );
     229    $vtp->setVar( $handle,'subcat.nb_subcats',$category['nb_sub_categories'] );
    227230    $vtp->closeSession( $handle, 'subcat' );
    228231  }
  • trunk/template/default/identification.vtp

    r25 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#ident_page_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; charset={#charset}" />
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    7466      </tr>
    7567    </table>
    76     {#footer}
    77   </body>
    78 </html>
  • trunk/template/default/picture.vtp

    r50 r345  
    1 <html>
    2   <head>
    3     <!--VTP_refresh-->
    4     <meta http-equiv="refresh" content="{#time};url={#url}">
    5     <!--/VTP_refresh-->
    6     <meta http-equiv="Content-Type" content="text/html;charset={#charset}">
    7     {#style}
    8     <!-- Specific style to picture.php-->
    9     <style type="text/css">
    10       .commentsAuthor,.commentsTitle,.commentsInfos,.commentsContent,.commentsNavigationBar {
    11         color:{#text_color};
    12         font-family:arial,sans-Serif;
    13         font-size:12px;
    14       }
    15       .commentsTitle,.commentsAuthor {
    16         text-align:center;
    17         font-weight:bold;
    18       }
    19       .commentsInfos {
    20         margin:3px 3px 3px 10px;
    21         font-size:11px;
    22       }
    23       .commentsContent {
    24         margin:10px;
    25       }
    26       .commentsTitle {
    27         margin-top:15px;
    28       }
    29       .commentsAuthor {
    30         margin:5px;
    31       }
    32       .commentsNavigationBar {
    33         margin:10px;
    34       }
    35       .tableComment {
    36         width:90%;
    37         border:2px solid {#text_color};
    38         margin:10px;
    39       }
    40       .cellAuthor {
    41         border-right:1px solid {#text_color};
    42         width:100px;
    43       }
    44       .cellInfo {
    45         border-bottom:1px solid {#text_color};
    46       }
    47     </style>
    48     <title>{#page_title}</title>
    49   </head>
    50   <body>
    51     {#header}
    521    <!--VTP_information-->
    532    <div class="information">{#content}</div>
     
    8635          {#frame_start}1%{#frame_begin}
    8736          <a href="{#picture_link}">
    88             <img style="margin:10px;width:{#picture_width}px;height:{#picture_height}px;border:1px solid {#picture_border_color}" src="{#picture_src}" alt="{#picture_alt}"/>
     37            <img class="imgLink" style="margin:10px;width:{#picture_width}px;height:{#picture_height}px;border:1px solid" src="{#picture_src}" alt="{#picture_alt}"/>
    8938          </a>
    9039          <div class="commentImage">{#picture_comment}</div>
     
    186135      <!--/VTP_comments-->
    187136    </table>
    188     {#footer}
    189   </body>
    190 </html>
  • trunk/template/default/profile.vtp

    r45 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#customize_page_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; {#charset}">
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    9890      </tr>
    9991    </table>
    100     {#footer}
    101   </body>
    102 </html>
  • trunk/template/default/register.vtp

    r107 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#register_page_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; charset={#charset}">
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    7062      </tr>
    7163    </table>
    72     {#footer}
    73   </body>
    74 </html>
  • trunk/template/default/search.vtp

    r107 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#search_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; charset={#charset}">
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    8072      </tr>
    8173    </table>
    82     {#footer}
    83   </body>
    84 </html>
  • trunk/template/default/upload.vtp

    r122 r345  
    1 <html>
    2   <head>
    3     {#style}
    4     <title>{#upload_title}</title>
    5     <meta http-equiv="Content-Type" content="text/html; charset={#charset}">
    6   </head>
    7   <body>
    8     {#header}
    91    <table style="width:100%;height:100%">
    102      <tr align="center" valign="middle">
     
    111103      </tr>
    112104    </table>
    113     {#footer}
    114   </body>
    115 </html>
  • trunk/upload.php

    r150 r345  
    1717 *                                                                         *
    1818 ***************************************************************************/
     19
     20//----------------------------------------------------------- include
     21$phpwg_root_path = './';
     22include_once( $phpwg_root_path.'common.php' );
    1923
    2024//------------------------------------------------------------------- functions
     
    9599    @unlink( $temp_name );
    96100  }
     101  else
     102  {
     103        @chmod( $temp_name, 0644);
     104  }
    97105  return $result;
    98106}       
    99 //----------------------------------------------------------- personnal include
    100 include_once( './include/init.inc.php' );
     107
    101108//-------------------------------------------------- access authorization check
    102109check_login_authorization();
     
    110117  $page['cat_name']       = $result['name'];
    111118  $page['cat_uploadable'] = $result['uploadable'];
    112 }
    113 else
    114 {
    115   $access_forbidden = true;
    116 }
    117 if ( $access_forbidden == true
    118      or $page['cat_site_id'] != 1
     119if ( $page['cat_site_id'] != 1
    119120     or !$conf['upload_available']
    120121     or !$page['cat_uploadable'] )
     
    125126  exit();
    126127}
     128}
    127129//----------------------------------------------------- template initialization
    128 $vtp = new VTemplate;
     130//
     131// Start output of page
     132//
     133$title= $lang['upload_title'];
     134include('include/page_header.php');
    129135$handle = $vtp->Open( './template/'.$user['template'].'/upload.vtp' );
    130136initialize_template();
     
    165171    array_push( $error, $lang['upload_err_username'] );
    166172  }
    167 
     173 
     174  $date_creation = '';
    168175  if ( $_POST['date_creation'] != '' )
    169176  {
     
    190197  $xml_infos.= ' name="'.htmlspecialchars( $_POST['name'], ENT_QUOTES).'"';
    191198  $xml_infos.= ' />';
     199
     200  if ( !preg_match( '/^[a-zA-Z0-9-_.]+$/', $_FILES['picture']['name'] ) )
     201  {
     202    // reload language file with administration labels
     203    $isadmin = true;
     204    include( './language/'.$user['language'].'.php' );
     205    array_push( $error, $lang['update_wrong_dirname'] );
     206  }
    192207 
    193208  if ( sizeof( $error ) == 0 )
     
    196211                               $conf['upload_maxwidth'],
    197212                               $conf['upload_maxheight']  );
    198     $upload_type = $result['type'];
    199213    for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
    200214    {
     
    238252                             $conf['upload_maxwidth_thumbnail'],
    239253                             $conf['upload_maxheight_thumbnail']  );
    240   $upload_type = $result['type'];
    241254  for ( $j = 0; $j < sizeof( $result['error'] ); $j++ )
    242255  {
     
    348361    $vtp->setGlobalVar( $handle, 'user_mail_address',$user['mail_address'] );
    349362    // name of the picture
     363        if (isset($_POST['name']))
    350364    $vtp->setVar( $handle, 'fields.name', $_POST['name'] );
    351365    // author
     366        if (isset($_POST['author']))
    352367    $vtp->setVar( $handle, 'fields.author', $_POST['author'] );
    353368    // date of creation
     369        if (isset($_POST['date_creation']))
    354370    $vtp->setVar( $handle, 'fields.date_creation', $_POST['date_creation'] );
    355371    // comment
     372        if (isset($_POST['comment']))
    356373    $vtp->setVar( $handle, 'fields.comment', $_POST['comment'] );
    357374
     
    374391$code = $vtp->Display( $handle, 0 );
    375392echo $code;
     393include('include/page_tail.php');
    376394?>
Note: See TracChangeset for help on using the changeset viewer.