source: trunk/admin/waiting.php @ 156

Last change on this file since 156 was 61, checked in by z0rglub, 21 years ago

Multi categories for the same picture

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1<?php
2/***************************************************************************
3 *                                waiting.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: waiting.php 61 2003-08-30 15:54:37Z z0rglub $
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 ***************************************************************************/
19include_once( './include/isadmin.inc.php' );
20//--------------------------------------------------------------------- updates
21if ( isset( $_POST['submit'] ) )
22{
23  $query = 'SELECT id,storage_category_id,file,tn_ext';
24  $query.= ' FROM '.PREFIX_TABLE.'waiting';
25  $query.= " WHERE validated = 'false'";
26  $query.= ';';
27  $result = mysql_query( $query );
28  while ( $row = mysql_fetch_array( $result ) )
29  {
30    $key = 'validate-'.$row['id'];
31    if ( isset( $_POST[$key] ) )
32    {
33      if ( $_POST[$key] == 'true' )
34      {
35        // The uploaded element was validated, we have to set the
36        // "validated" field to "true"
37        $query = 'UPDATE '.PREFIX_TABLE.'waiting';
38        $query.= " SET validated = 'true'";
39        $query.= ' WHERE id = '.$row['id'];
40        $query.= ';';
41        mysql_query( $query );
42        // linking logically the picture to its storage category
43        $query = 'INSERT INTO';
44      }
45      else
46      {
47        // The uploaded element was refused, we have to delete its reference
48        // in the database and to delete the element as well.
49        $query = 'DELETE FROM '.PREFIX_TABLE.'waiting';
50        $query.= ' WHERE id = '.$row['id'];
51        $query.= ';';
52        mysql_query( $query );
53        // deletion of the associated files
54        $dir = get_complete_dir( $row['storage_category_id'] );
55        unlink( '.'.$dir.$row['file'] );
56        if ( $row['tn_ext'] != '' )
57        {
58          $thumbnail = $conf['prefix_thumbnail'];
59          $thumbnail.= get_filename_wo_extension( $row['file'] );
60          $thumbnail.= '.'.$row['tn_ext'];
61          $url = '.'.$dir.'thumbnail/'.$thumbnail;
62          unlink( $url );
63        }
64      }
65    }
66  }
67}
68//----------------------------------------------------- template initialization
69$sub = $vtp->Open( '../template/'.$user['template'].'/admin/waiting.vtp' );
70$tpl = array( 'category','date','author','thumbnail','file','delete',
71              'submit' );
72templatize_array( $tpl, 'lang', $sub );
73//---------------------------------------------------------------- form display
74$cat_names = array();
75$query = 'SELECT id,storage_category_id,file,username,mail_address';
76$query.= ',date,tn_ext';
77$query.= ' FROM '.PREFIX_TABLE.'waiting';
78$query.= " WHERE validated = 'false'";
79$query.= ' ORDER BY storage_category_id';
80$query.= ';';
81$result = mysql_query( $query );
82$i = 0;
83while ( $row = mysql_fetch_array( $result ) )
84{
85  $vtp->addSession( $sub, 'picture' );
86  $vtp->setVar( $sub, 'picture.id', $row['id'] );
87  if ( $i++ % 2 == 0 )
88  {
89    $vtp->setVar( $sub, 'picture.class', 'row2' );
90  }
91  if ( !isset( $cat_names[$row['storage_category_id']] ) )
92  {
93    $cat = get_cat_info( $row['storage_category_id'] );
94    $cat_names[$row['storage_category_id']] = array();
95    $cat_names[$row['storage_category_id']]['dir'] =
96      '.'.get_complete_dir( $row['storage_category_id'] );
97    $cat_names[$row['storage_category_id']]['display_name'] =
98      get_cat_display_name( $cat['name'], ' &gt; ', 'font-weight:bold;' );
99  }
100  // category name
101  $vtp->setVar( $sub, 'picture.cat_name',
102                $cat_names[$row['storage_category_id']]['display_name'] );
103  // date displayed like this (in English ) :
104  //                     Sunday 15 June 2003 21:29
105  $date = format_date( $row['date'], 'unix', true );
106  $vtp->setVar( $sub, 'picture.date', $date );
107  // file preview link
108  $url = $cat_names[$row['storage_category_id']]['dir'].$row['file'];
109  $vtp->setVar( $sub, 'picture.preview_url', $url );
110  // file name
111  $vtp->setVar( $sub, 'picture.file', $row['file'] );
112  // is there an existing associated thumnail ?
113  if ( $row['tn_ext'] != '' )
114  {
115    $vtp->addSession( $sub, 'thumbnail' );
116    $thumbnail = $conf['prefix_thumbnail'];
117    $thumbnail.= get_filename_wo_extension( $row['file'] );
118    $thumbnail.= '.'.$row['tn_ext'];
119    $url = $cat_names[$row['storage_category_id']]['dir'];
120    $url.= 'thumbnail/'.$thumbnail;
121    $vtp->setVar( $sub, 'thumbnail.preview_url', $url );
122    $vtp->setVar( $sub, 'thumbnail.file', $thumbnail );
123    $vtp->closeSession( $sub, 'thumbnail' );
124  }
125  else
126  {
127    $vtp->addSession( $sub, 'no_thumbnail' );
128    $vtp->closeSession( $sub, 'no_thumbnail' );
129  }
130  // username and associated mail address
131  $vtp->setVar( $sub, 'picture.mail_address', $row['mail_address'] );
132  $vtp->setVar( $sub, 'picture.username', $row['username'] );
133
134  $vtp->closeSession( $sub, 'picture' );
135}
136//----------------------------------------------------------- sending html code
137$vtp->Parse( $handle , 'sub', $sub );
138?>
Note: See TracBrowser for help on using the repository browser.