Ignore:
Timestamp:
Oct 23, 2004, 11:58:28 AM (20 years ago)
Author:
z0rglub
Message:
  • refactoring
  • PHP Warnings correction
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r509 r575  
    2626// +-----------------------------------------------------------------------+
    2727
    28 if( !defined("PHPWG_ROOT_PATH") )
    29 {
    30         die ("Hacking attempt!");
    31 }
    32 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
    33 
     28if(!defined("PHPWG_ROOT_PATH"))
     29{
     30  die ("Hacking attempt!");
     31}
     32include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
    3433//--------------------------------------------------------- update informations
    3534$errors = array();
    3635// first, we verify whether there is a mistake on the given creation date
    37 if ( isset( $_POST['date_creation'] ) and !empty($_POST['date_creation']))
    38 {
    39   if ( !check_date_format( $_POST['date_creation'] ) )
    40     array_push( $errors, $lang['err_date'] );
    41 }
    42 if ( isset( $_POST['submit'] ) )
     36if (isset($_POST['date_creation']) and !empty($_POST['date_creation']))
     37{
     38  if (!check_date_format($_POST['date_creation']))
     39  {
     40    array_push($errors, $lang['err_date']);
     41  }
     42}
     43if (isset($_POST['submit']))
    4344{
    4445  $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
    45   if ( $_POST['name'] == '' )
     46  if ($_POST['name'] == '')
    4647    $query.= 'NULL';
    4748  else
    48     $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'";
     49    $query.= "'".htmlentities($_POST['name'], ENT_QUOTES)."'";
    4950 
    5051  $query.= ', author = ';
    51   if ( $_POST['author'] == '' )
     52  if ($_POST['author'] == '')
    5253    $query.= 'NULL';
    5354  else
     
    5556
    5657  $query.= ', comment = ';
    57   if ( $_POST['comment'] == '' )
     58  if ($_POST['comment'] == '')
    5859    $query.= 'NULL';
    5960  else
     
    6162
    6263  $query.= ', date_creation = ';
    63   if ( check_date_format( $_POST['date_creation'] ) )
    64     $query.= "'".date_convert( $_POST['date_creation'] )."'";
    65   else if ( $_POST['date_creation'] == '' )
     64  if (check_date_format($_POST['date_creation']))
     65    $query.= "'".date_convert($_POST['date_creation'])."'";
     66  else if ($_POST['date_creation'] == '')
    6667    $query.= 'NULL';
    6768
    6869  $query.= ', keywords = ';
    69   $keywords_array = get_keywords( $_POST['keywords'] );
    70   if ( count( $keywords_array ) == 0 )
     70  $keywords_array = get_keywords($_POST['keywords']);
     71  if (count($keywords_array) == 0)
    7172    $query.= 'NULL';
    7273  else
    7374  {
    7475    $query.= "'";
    75     foreach ( $keywords_array as $i => $keyword ) {
    76       if ( $i > 0 ) $query.= ',';
     76    foreach ($keywords_array as $i => $keyword) {
     77      if ($i > 0) $query.= ',';
    7778      $query.= $keyword;
    7879    }
     
    8283  $query.= ' WHERE id = '.$_GET['image_id'];
    8384  $query.= ';';
    84   mysql_query( $query );
     85  mysql_query($query);
    8586  // make the picture representative of a category ?
    86   $query = 'SELECT DISTINCT(category_id) as category_id';
    87   $query.= ',representative_picture_id';
    88   $query.= ' FROM '.IMAGE_CATEGORY_TABLE.' AS ic';
    89   $query.= ', '.CATEGORIES_TABLE.' AS c';
    90   $query.= ' WHERE c.id = ic.category_id';
    91   $query.= ' AND image_id = '.$_GET['image_id'];
    92   $query.= ';';
    93   $result = mysql_query( $query );
    94   while ( $row = mysql_fetch_array( $result ) )
     87  $query = '
     88SELECT DISTINCT(category_id) as category_id,representative_picture_id
     89  FROM '.IMAGE_CATEGORY_TABLE.' AS ic, '.CATEGORIES_TABLE.' AS c
     90  WHERE c.id = ic.category_id
     91    AND image_id = '.$_GET['image_id'].'
     92;';
     93  $result = mysql_query($query);
     94  while ($row = mysql_fetch_array($result))
    9595  {
    9696    // if the user ask the picture to be the representative picture of its
    9797    // category, the category is updated in the database (without wondering
    9898    // if this picture was already the representative one)
    99     if ( isset($_POST['representative-'.$row['category_id']]) )
     99    if (isset($_POST['representative-'.$row['category_id']]))
    100100    {
    101101      $query = 'UPDATE '.CATEGORIES_TABLE;
     
    103103      $query.= ' WHERE id = '.$row['category_id'];
    104104      $query.= ';';
    105       mysql_query( $query );
     105      mysql_query($query);
    106106    }
    107107    // if the user ask this picture to be not any more the representative,
    108108    // we have to set the representative_picture_id of this category to NULL
    109     else if ( isset( $row['representative_picture_id'] )
    110               and $row['representative_picture_id'] == $_GET['image_id'] )
    111     {
    112       $query = 'UPDATE '.CATEGORIES_TABLE;
    113       $query.= ' SET representative_picture_id = NULL';
    114       $query.= ' WHERE id = '.$row['category_id'];
    115       $query.= ';';
    116       mysql_query( $query );
     109    else if (isset($row['representative_picture_id'])
     110             and $row['representative_picture_id'] == $_GET['image_id'])
     111    {
     112      $query = '
     113UPDATE '.CATEGORIES_TABLE.'
     114  SET representative_picture_id = NULL
     115  WHERE id = '.$row['category_id'].'
     116;';
     117      mysql_query($query);
    117118    }
    118119  }
    119120  $associate_or_dissociate = false;
    120121  // associate with a new category ?
    121   if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' )
     122  if ($_POST['associate'] != '-1' and $_POST['associate'] != '')
    122123  {
    123124    // does the uppercat id exists in the database ?
    124     if ( !is_numeric( $_POST['associate'] ) )
    125     {
    126       array_push( $errors, $lang['cat_unknown_id'] );
     125    if (!is_numeric($_POST['associate']))
     126    {
     127      array_push($errors, $lang['cat_unknown_id']);
    127128    }
    128129    else
    129130    {
    130       $query = 'SELECT id FROM '.CATEGORIES_TABLE;
    131       $query.= ' WHERE id = '.$_POST['associate'];
    132       $query.= ';';
    133       if ( mysql_num_rows( mysql_query( $query ) ) == 0 )
    134         array_push( $errors, $lang['cat_unknown_id'] );
    135     }
    136   }
    137   if ( $_POST['associate'] != '-1'
     131      $query = '
     132SELECT id
     133  FROM '.CATEGORIES_TABLE.'
     134  WHERE id = '.$_POST['associate'].'
     135;';
     136      if (mysql_num_rows(mysql_query($query)) == 0)
     137        array_push($errors, $lang['cat_unknown_id']);
     138    }
     139  }
     140  if ($_POST['associate'] != '-1'
    138141       and $_POST['associate'] != ''
    139        and count( $errors ) == 0 )
    140   {
    141     $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
    142     $query.= ' (category_id,image_id) VALUES ';
    143     $query.= '('.$_POST['associate'].','.$_GET['image_id'].')';
    144     $query.= ';';
    145     mysql_query( $query);
     142       and count($errors) == 0)
     143  {
     144    $query = '
     145INSERT INTO '.IMAGE_CATEGORY_TABLE.'
     146  (category_id,image_id)
     147  VALUES
     148  ('.$_POST['associate'].','.$_GET['image_id'].')
     149;';
     150    mysql_query($query);
    146151    $associate_or_dissociate = true;
    147     update_category( $_POST['associate'] );
     152    update_category($_POST['associate']);
    148153  }
    149154  // dissociate any category ?
    150155  // retrieving all the linked categories
    151   $query = 'SELECT DISTINCT(category_id) as category_id FROM '.IMAGE_CATEGORY_TABLE;
    152   $query.= ' WHERE image_id = '.$_GET['image_id'];
    153   $query.= ';';
    154   $result = mysql_query( $query );
    155   while ( $row = mysql_fetch_array( $result ) )
    156   {
    157     if ( isset($_POST['dissociate-'.$row['category_id']]) )
    158     {
    159       $query = 'DELETE FROM '.IMAGE_CATEGORY_TABLE;
    160       $query.= ' WHERE image_id = '.$_GET['image_id'];
    161       $query.= ' AND category_id = '.$row['category_id'];
    162       $query.= ';';
    163       mysql_query( $query );
     156  $query = '
     157SELECT DISTINCT(category_id) as category_id
     158  FROM '.IMAGE_CATEGORY_TABLE.'
     159  WHERE image_id = '.$_GET['image_id'].'
     160;';
     161  $result = mysql_query($query);
     162  while ($row = mysql_fetch_array($result))
     163  {
     164    if (isset($_POST['dissociate-'.$row['category_id']]))
     165    {
     166      $query = '
     167DELETE FROM '.IMAGE_CATEGORY_TABLE.'
     168  WHERE image_id = '.$_GET['image_id'].'
     169  AND category_id = '.$row['category_id'].'
     170;';
     171      mysql_query($query);
    164172      $associate_or_dissociate = true;
    165       update_category( $row['category_id'] );
    166     }
    167   }
    168   if ( $associate_or_dissociate )
     173      update_category($row['category_id']);
     174    }
     175  }
     176  if ($associate_or_dissociate)
    169177  {
    170178    synchronize_all_users();
     
    173181
    174182// retrieving direct information about picture
    175 $query = 'SELECT * FROM '.IMAGES_TABLE;
    176 $query.= ' WHERE id = '.$_GET['image_id'];
    177 $query.= ';';
    178 $row = mysql_fetch_array( mysql_query( $query ) );
    179 
    180 $title = empty($row['name'])?str_replace( '_',' ',get_filename_wo_extension($row['file']) ):$row['name'];
     183$query = '
     184SELECT *
     185  FROM '.IMAGES_TABLE.'
     186  WHERE id = '.$_GET['image_id'].'
     187;';
     188$row = mysql_fetch_array(mysql_query($query));
     189
     190// some fields are nullable in the images table
     191$nullables = array('name','author','keywords','date_creation','comment');
     192foreach ($nullables as $field)
     193{
     194  if (!isset($row[$field]))
     195  {
     196    $row[$field] = '';
     197  }
     198}
     199
     200if (empty($row['name']))
     201{
     202  $title = str_replace('_', ' ',get_filename_wo_extension($row['file']));
     203}
     204else
     205{
     206  $title = $row['name'];
     207}
    181208// Navigation path
    182209$current_category = get_cat_info($row['storage_category_id']);
    183210$dir_path = get_cat_display_name($current_category['name'], '->', '');
    184211
    185 $thumbnail_url = get_complete_dir( $row['storage_category_id'] );
    186 $file_wo_ext = get_filename_wo_extension( $row['file'] );
     212$thumbnail_url = get_complete_dir($row['storage_category_id']);
     213$file_wo_ext = get_filename_wo_extension($row['file']);
    187214$thumbnail_url.= '/thumbnail/';
    188215$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
     
    193220
    194221// retrieving all the linked categories
    195 $query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
    196 $query.= ',representative_picture_id';
    197 $query.= ' FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE;
    198 $query.= ' WHERE image_id = '.$_GET['image_id'];
    199 $query.= ' AND category_id = id;';
    200 $result = mysql_query( $query );
     222$query = '
     223SELECT DISTINCT(category_id) AS category_id,status,visible
     224       ,representative_picture_id
     225  FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE.'
     226  WHERE image_id = '.$_GET['image_id'].'
     227    AND category_id = id
     228;';
     229$result = mysql_query($query);
    201230$categories = '';
    202 while ( $cat_row = mysql_fetch_array( $result ) )
    203 {
    204   $cat_infos = get_cat_info( $cat_row['category_id'] );
    205   $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '' );
     231while ($cat_row = mysql_fetch_array($result))
     232{
     233  $cat_infos = get_cat_info($cat_row['category_id']);
     234  $cat_name = get_cat_display_name($cat_infos['name'], ' > ', '');
    206235  $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>';
    207236}
    208237
    209238//----------------------------------------------------- template initialization
    210 $template->set_filenames( array('picture_modify'=>'admin/picture_modify.tpl') );
     239$template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl'));
    211240$template->assign_vars(array(
    212241  'TITLE_IMG'=>$title,
     
    214243  'FILE_IMG'=>$row['file'],
    215244  'TN_URL_IMG'=>$thumbnail_url,
    216   'URL_IMG'=>add_session_id( $url_img ),
     245  'URL_IMG'=>add_session_id($url_img),
     246  'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])),
     247  'FILE_IMG'=>$row['file'],
    217248  'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'],
    218   'DEFAULT_NAME_IMG'=>str_replace( '_',' ',get_filename_wo_extension($row['file']) ),
    219   'FILE_IMG'=>$row['file'],
    220249  'SIZE_IMG'=>$row['width'].' * '.$row['height'],
    221250  'FILESIZE_IMG'=>$row['filesize'].' KB',
     
    243272 
    244273  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
    245   ));
     274 ));
    246275 
    247276//-------------------------------------------------------------- errors display
    248 if ( sizeof( $errors ) != 0 )
     277if (sizeof($errors) != 0)
    249278{
    250279  $template->assign_block_vars('errors',array());
    251   for ( $i = 0; $i < sizeof( $errors ); $i++ )
     280  for ($i = 0; $i < sizeof($errors); $i++)
    252281  {
    253282    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
     
    257286// if there are linked category other than the storage category, we show
    258287// propose the dissociate text
    259 if ( mysql_num_rows( $result ) > 0 )
    260 {
    261   //$vtp->addSession( $sub, 'dissociate' );
    262   //$vtp->closeSession( $sub, 'dissociate' );
     288if (mysql_num_rows($result) > 0)
     289{
     290  //$vtp->addSession($sub, 'dissociate');
     291  //$vtp->closeSession($sub, 'dissociate');
    263292}
    264293// associate to another category ?
     
    268297$query = 'SELECT COUNT(id) AS nb_total_categories';
    269298$query.= ' FROM '.CATEGORIES_TABLE.';';
    270 $row = mysql_fetch_array( mysql_query( $query ) );
    271 if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
     299$row = mysql_fetch_array(mysql_query($query));
     300if ($row['nb_total_categories'] < $conf['max_LOV_categories'])
    272301{
    273302  $template->assign_block_vars('associate_LOV',array());
    274303  $template->assign_block_vars('associate_LOV.associate_cat',array(
    275304        ));
    276   /*$vtp->addSession( $sub, 'associate_LOV' );
    277   $vtp->addSession( $sub, 'associate_cat' );
    278   $vtp->setVar( $sub, 'associate_cat.value', '-1' );
    279   $vtp->setVar( $sub, 'associate_cat.content', '' );
    280   $vtp->closeSession( $sub, 'associate_cat' );
    281   $page['plain_structure'] = get_plain_structure( true );
    282   $structure = create_structure( '', array() );
    283   display_categories( $structure, '&nbsp;' );
    284   $vtp->closeSession( $sub, 'associate_LOV' );*/
     305  /*$vtp->addSession($sub, 'associate_LOV');
     306  $vtp->addSession($sub, 'associate_cat');
     307  $vtp->setVar($sub, 'associate_cat.value', '-1');
     308  $vtp->setVar($sub, 'associate_cat.content', '');
     309  $vtp->closeSession($sub, 'associate_cat');
     310  $page['plain_structure'] = get_plain_structure(true);
     311  $structure = create_structure('', array());
     312  display_categories($structure, '&nbsp;');
     313  $vtp->closeSession($sub, 'associate_LOV');*/
    285314}
    286315
Note: See TracChangeset for help on using the changeset viewer.