Ignore:
Timestamp:
Sep 1, 2004, 1:05:19 AM (20 years ago)
Author:
gweltas
Message:

Template migration : picture_modify.php

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/picture_modify.php

    r362 r509  
    2626// +-----------------------------------------------------------------------+
    2727
    28 include_once( './admin/include/isadmin.inc.php' );
     28if( !defined("PHPWG_ROOT_PATH") )
     29{
     30        die ("Hacking attempt!");
     31}
     32include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
     33
    2934//--------------------------------------------------------- update informations
    3035$errors = array();
    3136// first, we verify whether there is a mistake on the given creation date
    32 if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' )
    33 {
    34   if ( !check_date_format( $_POST['creation_date'] ) )
     37if ( isset( $_POST['date_creation'] ) and !empty($_POST['date_creation']))
     38{
     39  if ( !check_date_format( $_POST['date_creation'] ) )
    3540    array_push( $errors, $lang['err_date'] );
    3641}
    3742if ( isset( $_POST['submit'] ) )
    3843{
    39   $query = 'UPDATE '.PREFIX_TABLE.'images';
    40  
    41   $query.= ' SET name = ';
     44  $query = 'UPDATE '.IMAGES_TABLE.' SET name = ';
    4245  if ( $_POST['name'] == '' )
    4346    $query.= 'NULL';
     
    5861
    5962  $query.= ', date_creation = ';
    60   if ( check_date_format( $_POST['creation_date'] ) )
    61     $query.= "'".date_convert( $_POST['creation_date'] )."'";
    62   else if ( $_POST['creation_date'] == '' )
     63  if ( check_date_format( $_POST['date_creation'] ) )
     64    $query.= "'".date_convert( $_POST['date_creation'] )."'";
     65  else if ( $_POST['date_creation'] == '' )
    6366    $query.= 'NULL';
    6467
     
    8386  $query = 'SELECT DISTINCT(category_id) as category_id';
    8487  $query.= ',representative_picture_id';
    85   $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic';
    86   $query.= ', '.PREFIX_TABLE.'categories AS c';
     88  $query.= ' FROM '.IMAGE_CATEGORY_TABLE.' AS ic';
     89  $query.= ', '.CATEGORIES_TABLE.' AS c';
    8790  $query.= ' WHERE c.id = ic.category_id';
    8891  $query.= ' AND image_id = '.$_GET['image_id'];
     
    9699    if ( isset($_POST['representative-'.$row['category_id']]) )
    97100    {
    98       $query = 'UPDATE '.PREFIX_TABLE.'categories';
     101      $query = 'UPDATE '.CATEGORIES_TABLE;
    99102      $query.= ' SET representative_picture_id = '.$_GET['image_id'];
    100103      $query.= ' WHERE id = '.$row['category_id'];
     
    107110              and $row['representative_picture_id'] == $_GET['image_id'] )
    108111    {
    109       $query = 'UPDATE '.PREFIX_TABLE.'categories';
     112      $query = 'UPDATE '.CATEGORIES_TABLE;
    110113      $query.= ' SET representative_picture_id = NULL';
    111114      $query.= ' WHERE id = '.$row['category_id'];
     
    125128    else
    126129    {
    127       $query = 'SELECT id';
    128       $query.= ' FROM '.PREFIX_TABLE.'categories';
     130      $query = 'SELECT id FROM '.CATEGORIES_TABLE;
    129131      $query.= ' WHERE id = '.$_POST['associate'];
    130132      $query.= ';';
     
    137139       and count( $errors ) == 0 )
    138140  {
    139     $query = 'INSERT INTO '.PREFIX_TABLE.'image_category';
     141    $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE;
    140142    $query.= ' (category_id,image_id) VALUES ';
    141143    $query.= '('.$_POST['associate'].','.$_GET['image_id'].')';
     
    147149  // dissociate any category ?
    148150  // retrieving all the linked categories
    149   $query = 'SELECT DISTINCT(category_id) as category_id';
    150   $query.= ' FROM '.PREFIX_TABLE.'image_category';
     151  $query = 'SELECT DISTINCT(category_id) as category_id FROM '.IMAGE_CATEGORY_TABLE;
    151152  $query.= ' WHERE image_id = '.$_GET['image_id'];
    152153  $query.= ';';
     
    156157    if ( isset($_POST['dissociate-'.$row['category_id']]) )
    157158    {
    158       $query = 'DELETE FROM '.PREFIX_TABLE.'image_category';
     159      $query = 'DELETE FROM '.IMAGE_CATEGORY_TABLE;
    159160      $query.= ' WHERE image_id = '.$_GET['image_id'];
    160161      $query.= ' AND category_id = '.$row['category_id'];
     
    170171  }
    171172}
    172 //----------------------------------------------------- template initialization
    173 $sub = $vtp->Open(
    174   './template/'.$user['template'].'/admin/picture_modify.vtp' );
    175 
    176 $tpl = array( 'submit','errors_title','picmod_update','picmod_back',
    177               'default','file','size','filesize','registration_date',
    178               'author','creation_date','keywords','comment', 'upload_name',
    179               'dissociate','categories','infoimage_associate',
    180               'cat_image_info','category_representative' );
    181 templatize_array( $tpl, 'lang', $sub );
    182 $vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
    183 //-------------------------------------------------------------- errors display
    184 if ( count( $errors ) != 0 )
    185 {
    186   $vtp->addSession( $sub, 'errors' );
    187   foreach ( $errors as $error ) {
    188     $vtp->addSession( $sub, 'li' );
    189     $vtp->setVar( $sub, 'li.content', $error );
    190     $vtp->closeSession( $sub, 'li' );
    191   }
    192   $vtp->closeSession( $sub, 'errors' );
    193 }
    194 //-------------------------------------------- displaying informations and form
    195 $action = './admin.php?'.$_SERVER['QUERY_STRING'];
    196 $vtp->setVar( $sub, 'form_action', $action );
     173
    197174// retrieving direct information about picture
    198 $infos = array( 'file','date_available','date_creation','tn_ext','name'
    199                 ,'filesize','width','height','author','comment','keywords'
    200                 ,'storage_category_id' );
    201 $query = 'SELECT '. implode( ',', $infos );
    202 $query.= ' FROM '.PREFIX_TABLE.'images';
     175$query = 'SELECT * FROM '.IMAGES_TABLE;
    203176$query.= ' WHERE id = '.$_GET['image_id'];
    204177$query.= ';';
    205178$row = mysql_fetch_array( mysql_query( $query ) );
    206179
    207 foreach ( $infos as $info ) {
    208   if ( !isset( $row[$info] ) ) $row[$info] = '';
    209 }
    210 
    211 // picture title
    212 if ( $row['name'] == '' )
    213 {
    214   $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
    215 }
    216 else
    217 {
    218   $title = $row['name'];
    219 }
    220 $vtp->setVar( $sub, 'title', $title );
    221 $vtp->setVar( $sub, 'f_file', $row['file'] );
    222 $vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] );
    223 $vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' );
    224 $vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available']));
    225 $default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) );
    226 $vtp->setVar( $sub, 'default_name', $default_name );
    227 // if this form is displayed after an unsucceeded submit, we have to display
    228 // the values filled by the user (wright or wrong).
    229 if ( count( $errors ) > 0 )
    230 {
    231   $name            = $_POST['name'];
    232   $author          = $_POST['author'];
    233   $creation_date   = $_POST['creation_date'];
    234   $keywords        = $_POST['keywords'];
    235   $comment         = $_POST['comment'];
    236 }
    237 else
    238 {
    239   $name            = $row['name'];
    240   $author          = $row['author'];
    241   $creation_date   = date_convert_back( $row['date_creation'] );
    242   $keywords        = $row['keywords'];
    243   $comment         = $row['comment'];
    244 }
    245 $vtp->setVar( $sub, 'f_name',            $name );
    246 $vtp->setVar( $sub, 'f_author',          $author );
    247 $vtp->setVar( $sub, 'f_creation_date',   $creation_date );
    248 $vtp->setVar( $sub, 'f_keywords',        $keywords );
    249 $vtp->setVar( $sub, 'f_comment',         $comment );
    250 // retrieving directory where picture is stored (for displaying the
    251 // thumbnail)
     180$title = empty($row['name'])?str_replace( '_',' ',get_filename_wo_extension($row['file']) ):$row['name'];
     181// Navigation path
     182$current_category = get_cat_info($row['storage_category_id']);
     183$dir_path = get_cat_display_name($current_category['name'], '->', '');
     184
    252185$thumbnail_url = get_complete_dir( $row['storage_category_id'] );
    253 $result = get_cat_info( $row['storage_category_id'] );
    254 $cat_name = get_cat_display_name( $result['name'], ' > ', '' );
    255 $vtp->setVar( $sub, 'dir', $cat_name );
    256 if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url;
    257186$file_wo_ext = get_filename_wo_extension( $row['file'] );
    258187$thumbnail_url.= '/thumbnail/';
    259188$thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext'];
    260 $vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url );
    261 // storage category is linked by default
    262 $vtp->addSession( $sub, 'linked_category' );
    263 $vtp->setVar( $sub, 'linked_category.name', $cat_name );
    264 $url = '../picture.php?image_id='.$_GET['image_id'];
    265 $url.= '&cat='.$row['storage_category_id'];
    266 $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
    267 $url = './admin.php?page=infos_images&cat_id='.$row['storage_category_id'];
    268 $vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url));
    269 if ( $result['status'] == 'private' )
    270 {
    271   $private_string = '<span style="color:red;font-weight:bold;">';
    272   $private_string.= $lang['private'].'</span>';
    273   $vtp->setVar( $sub, 'linked_category.private', $private_string );
    274 }
    275 if ( !$result['visible'] )
    276 {
    277   $invisible_string = '<span style="color:red;">';
    278   $invisible_string.= $lang['cat_invisible'].'</span>';
    279   $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
    280 }
    281 $vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] );
    282 if ( $result['representative_picture_id'] == $_GET['image_id'] )
    283 {
    284   $vtp->setVar( $sub, 'linked_category.representative_checked',
    285                 ' checked="checked"' );
    286 }
    287 $vtp->closeSession( $sub, 'linked_category' );
     189$url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
     190$url_img .= '&amp;cat='.$row['storage_category_id'];
     191$date = isset($_POST['date_creation']) && empty($errors)
     192          ?$_POST['date_creation']:date_convert_back($row['date_creation']);
     193
    288194// retrieving all the linked categories
    289195$query = 'SELECT DISTINCT(category_id) as category_id,status,visible';
    290196$query.= ',representative_picture_id';
    291 $query.= ' FROM '.PREFIX_TABLE.'image_category';
    292 $query.= ','.PREFIX_TABLE.'categories';
     197$query.= ' FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE;
    293198$query.= ' WHERE image_id = '.$_GET['image_id'];
    294 $query.= ' AND category_id != '.$row['storage_category_id'];
    295 $query.= ' AND category_id = id';
    296 $query.= ';';
     199$query.= ' AND category_id = id;';
    297200$result = mysql_query( $query );
    298 while ( $row = mysql_fetch_array( $result ) )
    299 {
    300   $vtp->addSession( $sub, 'linked_category' );
    301   $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] );
    302 
    303   $vtp->addSession( $sub, 'checkbox' );
    304   $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] );
    305   $vtp->closeSession( $sub, 'checkbox' );
    306 
    307   $cat_infos = get_cat_info( $row['category_id'] );
     201$categories = '';
     202while ( $cat_row = mysql_fetch_array( $result ) )
     203{
     204  $cat_infos = get_cat_info( $cat_row['category_id'] );
    308205  $cat_name = get_cat_display_name( $cat_infos['name'], ' &gt; ', '' );
    309   $vtp->setVar( $sub, 'linked_category.name', $cat_name );
    310 
    311   $url = '../picture.php?image_id='.$_GET['image_id'];
    312   $url.= '&amp;cat='.$row['category_id'];
    313   $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url));
    314 
    315   $url = './admin.php?page=infos_images&amp;cat_id='.$row['category_id'];
    316   $vtp->setVar( $sub, 'linked_category.infos_images_link',
    317                 add_session_id( $url));
    318 
    319   if ( $row['status'] == 'private' )
    320   {
    321     $private_string = '<span style="color:red;font-weight:bold;">';
    322     $private_string.= $lang['private'].'</span>';
    323     $vtp->setVar( $sub, 'linked_category.private', $private_string );
    324   }
    325 
    326   if ( !get_boolean( $row['visible'] ) )
    327   {
    328     $invisible_string = '<span style="color:red;">';
    329     $invisible_string.= $lang['cat_invisible'].'</span>';
    330     $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string );
    331   }
    332 
    333   if ( isset( $row['representative_picture_id'] )
    334        and $row['representative_picture_id'] == $_GET['image_id'] )
    335   {
    336     $vtp->setVar( $sub, 'linked_category.representative_checked',
    337                   ' checked="checked"' );
    338   }
    339  
    340   $vtp->closeSession( $sub, 'linked_category' );
    341 }
     206  $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>';
     207}
     208
     209//----------------------------------------------------- template initialization
     210$template->set_filenames( array('picture_modify'=>'admin/picture_modify.tpl') );
     211$template->assign_vars(array(
     212  'TITLE_IMG'=>$title,
     213  'DIR_IMG'=>$dir_path,
     214  'FILE_IMG'=>$row['file'],
     215  'TN_URL_IMG'=>$thumbnail_url,
     216  'URL_IMG'=>add_session_id( $url_img ),
     217  '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'],
     220  'SIZE_IMG'=>$row['width'].' * '.$row['height'],
     221  'FILESIZE_IMG'=>$row['filesize'].' KB',
     222  'REGISTRATION_DATE_IMG'=> format_date($row['date_available']),
     223  'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'],
     224  'CREATION_DATE_IMG'=>$date,
     225  'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'],
     226  'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'],
     227  'ASSOCIATED_CATEGORIES'=>$categories,
     228 
     229  'L_UPLOAD_NAME'=>$lang['upload_name'],
     230  'L_DEFAULT'=>$lang['default'],
     231  'L_FILE'=>$lang['file'],
     232  'L_SIZE'=>$lang['size'],
     233  'L_FILESIZE'=>$lang['filesize'],
     234  'L_REGISTRATION_DATE'=>$lang['registration_date'],
     235  'L_AUTHOR'=>$lang['author'],
     236  'L_CREATION_DATE'=>$lang['creation_date'],
     237  'L_KEYWORDS'=>$lang['keywords'],
     238  'L_COMMENT'=>$lang['comment'],
     239  'L_CATEGORIES'=>$lang['categories'],
     240  'L_DISSOCIATE'=>$lang['dissociate'],
     241  'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'],
     242  'L_SUBMIT'=>$lang['submit'],
     243 
     244  'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING'])
     245  ));
     246 
     247//-------------------------------------------------------------- errors display
     248if ( sizeof( $errors ) != 0 )
     249{
     250  $template->assign_block_vars('errors',array());
     251  for ( $i = 0; $i < sizeof( $errors ); $i++ )
     252  {
     253    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
     254  }
     255}
     256
    342257// if there are linked category other than the storage category, we show
    343258// propose the dissociate text
    344259if ( mysql_num_rows( $result ) > 0 )
    345260{
    346   $vtp->addSession( $sub, 'dissociate' );
    347   $vtp->closeSession( $sub, 'dissociate' );
     261  //$vtp->addSession( $sub, 'dissociate' );
     262  //$vtp->closeSession( $sub, 'dissociate' );
    348263}
    349264// associate to another category ?
     
    352267// $conf['max_LOV_categories']
    353268$query = 'SELECT COUNT(id) AS nb_total_categories';
    354 $query.= ' FROM '.PREFIX_TABLE.'categories';
    355 $query.= ';';
     269$query.= ' FROM '.CATEGORIES_TABLE.';';
    356270$row = mysql_fetch_array( mysql_query( $query ) );
    357271if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] )
    358272{
    359   $vtp->addSession( $sub, 'associate_LOV' );
     273  $template->assign_block_vars('associate_LOV',array());
     274  $template->assign_block_vars('associate_LOV.associate_cat',array(
     275        ));
     276  /*$vtp->addSession( $sub, 'associate_LOV' );
    360277  $vtp->addSession( $sub, 'associate_cat' );
    361278  $vtp->setVar( $sub, 'associate_cat.value', '-1' );
     
    365282  $structure = create_structure( '', array() );
    366283  display_categories( $structure, '&nbsp;' );
    367   $vtp->closeSession( $sub, 'associate_LOV' );
    368 }
    369 // else, we only display a small text field, we suppose the administrator
    370 // knows the id of its category
    371 else
    372 {
    373   $vtp->addSession( $sub, 'associate_text' );
    374   $vtp->closeSession( $sub, 'associate_text' );
    375 }
     284  $vtp->closeSession( $sub, 'associate_LOV' );*/
     285}
     286
    376287//----------------------------------------------------------- sending html code
    377 $vtp->Parse( $handle , 'sub', $sub );
     288$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify');
    378289?>
Note: See TracChangeset for help on using the changeset viewer.