Ignore:
Timestamp:
Oct 23, 2004, 10:58:10 AM (20 years ago)
Author:
z0rglub
Message:
  • code refactoring
  • PHP warnings corrections
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/infos_images.php

    r509 r570  
    2626// +-----------------------------------------------------------------------+
    2727
    28 if( !defined("PHPWG_ROOT_PATH") )
     28if(!defined("PHPWG_ROOT_PATH"))
    2929{
    30         die ("Hacking attempt!");
     30  die ("Hacking attempt!");
    3131}
    32 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
    33 //-------------------------------------------------------------- initialization
    34 $page['nb_image_page'] = 5;
    35 
    36 check_cat_id( $_GET['cat_id'] );
    37 
     32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
     33// +-----------------------------------------------------------------------+
     34// |                             initialization                            |
     35// +-----------------------------------------------------------------------+
     36check_cat_id($_GET['cat_id']);
    3837$errors = array();
    3938
    40 if ( isset( $page['cat'] ) )
     39if (isset($page['cat']))
    4140{
    42 //--------------------------------------------------- update individual options
    43   if ( isset( $_POST['submit'] ) )
    44   {
    45     if ( isset( $_POST['associate'] ) and $_POST['associate'] != '' )
     41// +-----------------------------------------------------------------------+
     42// |                       update individual options                       |
     43// +-----------------------------------------------------------------------+
     44  if (isset($_POST['submit']))
     45  {
     46    if (isset($_POST['associate']) and $_POST['associate'] != '')
    4647    {
    4748      // does the uppercat id exists in the database ?
    48       if ( !is_numeric( $_POST['associate'] ) )
    49       {
    50         array_push( $errors, $lang['cat_unknown_id'] );
     49      if (!is_numeric($_POST['associate']))
     50      {
     51        array_push($errors, $lang['cat_unknown_id']);
    5152      }
    5253      else
     
    5556        $query.= ' WHERE id = '.$_POST['associate'];
    5657        $query.= ';';
    57         if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
    58           array_push( $errors, $lang['cat_unknown_id'] );
     58        if (mysql_num_rows(mysql_query($query)) == 0)
     59          array_push($errors, $lang['cat_unknown_id']);
    5960      }
    6061    }
     
    6667    $query.= ' WHERE category_id = '.$page['cat'];
    6768    $query.= ';';
    68     $result = mysql_query( $query );
    69     while ( $row = mysql_fetch_array( $result ) )
     69    $result = mysql_query($query);
     70    while ($row = mysql_fetch_array($result))
    7071    {
    7172      $name          = 'name-'.$row['id'];
     
    7475      $date_creation = 'date_creation-'.$row['id'];
    7576      $keywords      = 'keywords-'.$row['id'];
    76       if ( isset( $_POST[$name] ) )
     77      if (isset($_POST[$name]))
    7778      {
    7879        $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
    79         if ( $_POST[$name] == '' )
    80           $query.= 'NULL';
    81         else
    82           $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
     80        if ($_POST[$name] == '')
     81          $query.= 'NULL';
     82        else
     83          $query.= "'".htmlentities($_POST[$name], ENT_QUOTES)."'";
    8384
    8485        $query.= ', author = ';
    85         if ( $_POST[$author] == '' )
     86        if ($_POST[$author] == '')
    8687          $query.= 'NULL';
    8788        else
     
    8990
    9091        $query.= ', comment = ';
    91         if ( $_POST[$comment] == '' )
     92        if ($_POST[$comment] == '')
    9293          $query.= 'NULL';
    9394        else
     
    9596
    9697        $query.= ', date_creation = ';
    97         if ( check_date_format( $_POST[$date_creation] ) )
    98           $query.= "'".date_convert( $_POST[$date_creation] )."'";
    99         else if ( $_POST[$date_creation] == '' )
     98        if (check_date_format($_POST[$date_creation]))
     99          $query.= "'".date_convert($_POST[$date_creation])."'";
     100        else if ($_POST[$date_creation] == '')
    100101          $query.= 'NULL';
    101102
    102103        $query.= ', keywords = ';
    103104
    104         $keywords_array = get_keywords( $_POST[$keywords] );
    105         if ( count( $keywords_array ) == 0 ) $query.= 'NULL';
    106         else $query.= "'".implode( ',', $keywords_array )."'";
     105        $keywords_array = get_keywords($_POST[$keywords]);
     106        if (count($keywords_array) == 0) $query.= 'NULL';
     107        else $query.= "'".implode(',', $keywords_array)."'";
    107108
    108109        $query.= ' WHERE id = '.$row['id'];
    109110        $query.= ';';
    110         mysql_query( $query );
     111        mysql_query($query);
    111112      }
    112113      // add link to another category
    113       if ( isset( $_POST['check-'.$row['id']] ) and count( $errors ) == 0 )
     114      if (isset($_POST['check-'.$row['id']]) and count($errors) == 0)
    114115      {
    115116        $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
     
    117118        $query.= ' ('.$row['id'].','.$_POST['associate'].')';
    118119        $query.= ';';
    119         mysql_query( $query );
     120        mysql_query($query);
    120121        $associate = true;
    121122      }
    122123    }
    123     if ( isset( $_POST['associate'] )) update_category( $_POST['associate'] );
    124     if ( $associate ) synchronize_all_users();
    125 //------------------------------------------------------ update general options
    126     if ( isset( $_POST['use_common_author'] ) )
     124    if (isset($_POST['associate'])) update_category($_POST['associate']);
     125    if ($associate) synchronize_all_users();
     126// +-----------------------------------------------------------------------+
     127// |                        update general options                         |
     128// +-----------------------------------------------------------------------+
     129    if (isset($_POST['use_common_author']))
    127130    {
    128131      $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
    129132      $query.= ' WHERE category_id = '.$page['cat'];
    130       $result = mysql_query( $query );
    131       while ( $row = mysql_fetch_array( $result ) )
     133      $result = mysql_query($query);
     134      while ($row = mysql_fetch_array($result))
    132135      {
    133136        $query = 'UPDATE '.IMAGES_TABLE;
    134         if ( $_POST['author_cat'] == '' )
     137        if ($_POST['author_cat'] == '')
    135138        {
    136139          $query.= ' SET author = NULL';
     
    139142        {
    140143          $query.= ' SET author = ';
    141           $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
     144          $query.= "'".htmlentities($_POST['author_cat'], ENT_QUOTES)."'";
    142145        }
    143146        $query.= ' WHERE id = '.$row['image_id'];
    144147        $query.= ';';
    145         mysql_query( $query );
    146       }
    147     }
    148     if ( isset( $_POST['use_common_date_creation'] ) )
    149     {
    150       if ( check_date_format( $_POST['date_creation_cat'] ) )
    151       {
    152         $date = date_convert( $_POST['date_creation_cat'] );
     148        mysql_query($query);
     149      }
     150    }
     151    if (isset($_POST['use_common_date_creation']))
     152    {
     153      if (check_date_format($_POST['date_creation_cat']))
     154      {
     155        $date = date_convert($_POST['date_creation_cat']);
    153156        $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE;
    154157        $query.= ' WHERE category_id = '.$page['cat'];
    155         $result = mysql_query( $query );
    156         while ( $row = mysql_fetch_array( $result ) )
     158        $result = mysql_query($query);
     159        while ($row = mysql_fetch_array($result))
    157160        {
    158161          $query = 'UPDATE '.IMAGES_TABLE;
    159           if ( $_POST['date_creation_cat'] == '' )
     162          if ($_POST['date_creation_cat'] == '')
    160163          {
    161164            $query.= ' SET date_creation = NULL';
     
    167170          $query.= ' WHERE id = '.$row['image_id'];
    168171          $query.= ';';
    169           mysql_query( $query );
     172          mysql_query($query);
    170173        }
    171174      }
    172175      else
    173176      {
    174         array_push( $errors, $lang['err_date'] );
    175       }
    176     }
    177     if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' )
     177        array_push($errors, $lang['err_date']);
     178      }
     179    }
     180    if (isset($_POST['common_keywords']) and $_POST['keywords_cat'] != '')
    178181    {
    179182      $query = 'SELECT id,keywords FROM '.IMAGES_TABLE;
     
    181184      $query.= ' WHERE category_id = '.$page['cat'];
    182185      $query.= ';';
    183       $result = mysql_query( $query );
    184       while ( $row = mysql_fetch_array( $result ) )
    185       {
    186         if ( !isset( $row['keywords'] ) ) $specific_keywords = array();
    187         else $specific_keywords = explode( ',', $row['keywords'] );
     186      $result = mysql_query($query);
     187      while ($row = mysql_fetch_array($result))
     188      {
     189        if (!isset($row['keywords'])) $specific_keywords = array();
     190        else $specific_keywords = explode(',', $row['keywords']);
    188191       
    189         $common_keywords   = get_keywords( $_POST['keywords_cat'] );
     192        $common_keywords   = get_keywords($_POST['keywords_cat']);
    190193        // first possiblity : adding the given keywords to all the pictures
    191         if ( $_POST['common_keywords'] == 'add' )
    192         {
    193           $keywords = array_merge( $specific_keywords, $common_keywords );
    194           $keywords = array_unique( $keywords );
     194        if ($_POST['common_keywords'] == 'add')
     195        {
     196          $keywords = array_merge($specific_keywords, $common_keywords);
     197          $keywords = array_unique($keywords);
    195198        }
    196199        // second possiblity : removing the given keywords from all pictures
    197200        // (without deleting the other specific keywords
    198         if ( $_POST['common_keywords'] == 'remove' )
    199         {
    200           $keywords = array_diff( $specific_keywords, $common_keywords );
     201        if ($_POST['common_keywords'] == 'remove')
     202        {
     203          $keywords = array_diff($specific_keywords, $common_keywords);
    201204        }
    202205        // cleaning the keywords array, sometimes, an empty value still remain
    203         $keywords = array_remove( $keywords, '' );
     206        $keywords = array_remove($keywords, '');
    204207        // updating the picture with new keywords array
    205208        $query = 'UPDATE '.IMAGES_TABLE.' SET keywords = ';
    206         if ( count( $keywords ) == 0 )
     209        if (count($keywords) == 0)
    207210        {
    208211          $query.= 'NULL';
     
    212215          $query.= '"';
    213216          $i = 0;
    214           foreach ( $keywords as $keyword ) {
    215             if ( $i++ > 0 ) $query.= ',';
     217          foreach ($keywords as $keyword) {
     218            if ($i++ > 0) $query.= ',';
    216219            $query.= $keyword;
    217220          }
     
    220223        $query.= ' WHERE id = '.$row['id'];
    221224        $query.= ';';
    222         mysql_query( $query );
    223       }
    224     }
    225   }
    226 //--------------------------------------------------------- form initialization
    227   if( !isset( $_GET['start'] )
    228       || !is_numeric( $_GET['start'] )
    229       || ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
     225        mysql_query($query);
     226      }
     227    }
     228  }
     229// +-----------------------------------------------------------------------+
     230// |                           form initialization                         |
     231// +-----------------------------------------------------------------------+
     232  if (!isset($_GET['start'])
     233      or !is_numeric($_GET['start'])
     234      or (is_numeric($_GET['start']) and $_GET['start'] < 0))
    230235  {
    231236    $page['start'] = 0;
     
    236241  }
    237242
    238   if ( isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0 )
    239   {
    240     $page['start'] =
    241       floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page'];
     243  if (isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0)
     244  {
     245    $max = $conf['info_nb_elements_page'];
     246    $page['start'] = floor($_GET['num'] / $max) * $max;
    242247  }
    243248  // Navigation path
     
    247252 
    248253  $form_action = PHPWG_ROOT_PATH.'admin.php?page=infos_images&amp;cat_id='.$_GET['cat_id'];
    249   if( $page['start'])
     254  if($page['start'])
    250255  {
    251256    $form_action.= '&amp;start='.$_GET['start'];
    252257  }
    253258 
    254   $nav_bar = create_navigation_bar(
    255     $form_action, $current_category['nb_images'],$page['start'], $page['nb_image_page'], '' );
    256        
    257 //----------------------------------------------------- template initialization
    258 $template->set_filenames( array('infos_images'=>'admin/infos_images.tpl') );
    259 $template->assign_vars(array(
    260   'CATEGORY'=>$category_path,
    261   'NAV_BAR'=>$nav_bar,
     259  $nav_bar = create_navigation_bar($form_action,
     260                                   $current_category['nb_images'],
     261                                   $page['start'],
     262                                   $conf['info_nb_elements_page'],
     263                                   '');
     264// +-----------------------------------------------------------------------+
     265// |                         template initialization                       |
     266// +-----------------------------------------------------------------------+
     267  $template->set_filenames(array('infos_images'=>'admin/infos_images.tpl'));
     268  $template->assign_vars(
     269    array(
     270      'CATEGORY'=>$category_path,
     271      'NAV_BAR'=>$nav_bar,
     272     
     273      'L_INFOS_TITLE'=>$lang['infoimage_general'],
     274      'L_AUTHOR'=>$lang['author'],
     275      'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'],
     276      'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'],
     277      'L_KEYWORD'=>$lang['keywords'],
     278      'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'],
     279      'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'],
     280      'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'],
     281      'L_INFOS_DETAIL'=>$lang['infoimage_detailed'],
     282      'L_THUMBNAIL'=>$lang['thumbnail'],
     283      'L_INFOS_IMG'=>$lang['infoimage_title'],
     284      'L_INFOS_COMMENT'=>$lang['comment'],
     285      'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'],
     286      'L_SUBMIT'=>$lang['submit'],
     287     
     288      'F_ACTION'=>add_session_id($form_action)
     289      ));
     290// +-----------------------------------------------------------------------+
     291// |                            errors display                             |
     292// +-----------------------------------------------------------------------+
     293  if (count($errors) != 0)
     294  {
     295    $template->assign_block_vars('errors',array());
     296    foreach ($errors as $error)
     297    {
     298      $template->assign_block_vars('errors.error',array('ERROR'=>$error));
     299    }
     300  }
     301// +-----------------------------------------------------------------------+
     302// |                                 form                                  |
     303// +-----------------------------------------------------------------------+
     304  $array_cat_directories = array();
     305
     306  $pic_mod_base_url = PHPWG_ROOT_PATH.'admin.php';
     307  $pic_mod_base_url = '?page=picture_modify&amp;image_id=';
    262308 
    263   'L_INFOS_TITLE'=>$lang['infoimage_general'],
    264   'L_AUTHOR'=>$lang['author'],
    265   'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'],
    266   'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'],
    267   'L_KEYWORD'=>$lang['keywords'],
    268   'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'],
    269   'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'],
    270   'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'],
    271   'L_INFOS_DETAIL'=>$lang['infoimage_detailed'],
    272   'L_THUMBNAIL'=>$lang['thumbnail'],
    273   'L_INFOS_IMG'=>$lang['infoimage_title'],
    274   'L_INFOS_COMMENT'=>$lang['comment'],
    275   'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'],
    276   'L_SUBMIT'=>$lang['submit'],
    277  
    278   'F_ACTION'=>add_session_id($form_action)
    279   ));
    280  
    281 //-------------------------------------------------------------- errors display
    282 if ( sizeof( $errors ) != 0 )
    283 {
    284   $template->assign_block_vars('errors',array());
    285   for ( $i = 0; $i < sizeof( $errors ); $i++ )
    286   {
    287     $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
    288   }
    289 }
    290 //------------------------------------------------------------------------ form
    291 
    292   $array_cat_directories = array();
    293  
    294   $query = 'SELECT * FROM '.IMAGES_TABLE;
    295   $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
    296   $query.= ' WHERE category_id = '.$page['cat'];
    297   $query.= $conf['order_by'];
    298   $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
    299   $query.= ';';
    300   $result = mysql_query( $query );
    301   while ( $row = mysql_fetch_array( $result ) )
    302   {
    303         if ( !isset( $array_cat_directories[$row['storage_category_id']] ) )
     309  $query = '
     310SELECT *
     311  FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id
     312  WHERE category_id = '.$page['cat'].'
     313  '.$conf['order_by'].'
     314  LIMIT '.$page['start'].','.$conf['info_nb_elements_page'].'
     315;';
     316  $result = mysql_query($query);
     317  while ($row = mysql_fetch_array($result))
     318  {
     319    if (!isset($array_cat_directories[$row['storage_category_id']]))
    304320    {
    305321      $array_cat_directories[$row['storage_category_id']] =
    306         get_complete_dir( $row['storage_category_id'] );
     322        get_complete_dir($row['storage_category_id']);
    307323    }
    308324    $thumbnail_url = $array_cat_directories[$row['storage_category_id']];
    309325    $thumbnail_url.= 'thumbnail/';
    310     $thumbnail_url.= $conf['prefix_thumbnail'].get_filename_wo_extension( $row['file'] ).".".$row['tn_ext'];
    311        
    312     $template->assign_block_vars('picture' ,array(
    313           'ID_IMG'=>$row['id'],
    314           'URL_IMG'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=picture_modify&amp;image_id='.$row['id'] ),
    315           'TN_URL_IMG'=>$thumbnail_url,
    316           'FILENAME_IMG'=>$row['file'],
    317           'DEFAULTNAME_IMG'=>get_filename_wo_extension( $row['file'] ),
    318           'NAME_IMG'=>$row['name'],
    319           'AUTHOR_IMG'=>$row['author'],
    320           'DATE_IMG'=>date_convert_back( $row['date_creation'] ),
    321           'KEYWORDS_IMG'=>$row['keywords'],
    322           'COMMENT_IMG'=>$row['comment']
    323           ));
     326    $thumbnail_url.= $conf['prefix_thumbnail'];
     327    $thumbnail_url.= get_filename_wo_extension($row['file']);
     328    $thumbnail_url.= '.'.$row['tn_ext'];
     329
     330    // some fields are nullable in the images table
     331    $nullables = array('name','author','keywords','date_creation','comment');
     332    foreach ($nullables as $field)
     333    {
     334      if (isset($row[$field]))
     335      {
     336        $$field = $row[$field];
     337      }
     338      else
     339      {
     340        $$field = '';
     341      }
     342    }
     343
     344    $template->assign_block_vars(
     345      'picture',
     346      array(
     347        'ID_IMG'=>$row['id'],
     348        'URL_IMG'=>add_session_id($pic_mod_base_url.$row['id']),
     349        'TN_URL_IMG'=>$thumbnail_url,
     350        'FILENAME_IMG'=>$row['file'],
     351        'DEFAULTNAME_IMG'=>get_filename_wo_extension($row['file']),
     352        'NAME_IMG'=>$name,
     353        'DATE_IMG'=>date_convert_back($date_creation),
     354        'AUTHOR_IMG'=>$author,
     355        'KEYWORDS_IMG'=>$keywords,
     356        'COMMENT_IMG'=>$comment
     357       ));
    324358  }
    325359 
     
    330364  $query = 'SELECT COUNT(id) AS nb_total_categories';
    331365  $query.= ' FROM '.CATEGORIES_TABLE.';';
    332   $row = mysql_fetch_array( mysql_query( $query ) );
    333   if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
    334   {
    335     /*$vtp->addSession( $sub, 'associate_LOV' );
    336     $page['plain_structure'] = get_plain_structure( true );
    337     $structure = create_structure( '', array() );
    338     display_categories( $structure, '&nbsp;' );
    339     $vtp->closeSession( $sub, 'associate_LOV' );*/
     366  $row = mysql_fetch_array(mysql_query($query));
     367  if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
     368  {
     369    /*$vtp->addSession($sub, 'associate_LOV');
     370    $page['plain_structure'] = get_plain_structure(true);
     371    $structure = create_structure('', array());
     372    display_categories($structure, '&nbsp;');
     373    $vtp->closeSession($sub, 'associate_LOV');*/
    340374  }
    341375  // else, we only display a small text field, we suppose the administrator
     
    343377  else
    344378  {
    345     //$vtp->addSession( $sub, 'associate_text' );
    346     //$vtp->closeSession( $sub, 'associate_text' );
     379    //$vtp->addSession($sub, 'associate_text');
     380    //$vtp->closeSession($sub, 'associate_text');
    347381  }
    348382}
Note: See TracChangeset for help on using the changeset viewer.