source: trunk/admin/waiting.php @ 177

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

Display a message to update the database after validating uploaded pictures

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 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 177 2003-10-05 13:10:54Z 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','waiting_update' );
72templatize_array( $tpl, 'lang', $sub );
73//-------------------------------------------------------- confirmation message
74if ( isset( $_POST['submit'] ) )
75{
76  $vtp->addSession( $sub, 'confirmation' );
77  $vtp->closeSession( $sub, 'confirmation' );
78}
79//---------------------------------------------------------------- form display
80$cat_names = array();
81$query = 'SELECT id,storage_category_id,file,username,mail_address';
82$query.= ',date,tn_ext';
83$query.= ' FROM '.PREFIX_TABLE.'waiting';
84$query.= " WHERE validated = 'false'";
85$query.= ' ORDER BY storage_category_id';
86$query.= ';';
87$result = mysql_query( $query );
88$i = 0;
89while ( $row = mysql_fetch_array( $result ) )
90{
91  $vtp->addSession( $sub, 'picture' );
92  $vtp->setVar( $sub, 'picture.id', $row['id'] );
93  if ( $i++ % 2 == 0 )
94  {
95    $vtp->setVar( $sub, 'picture.class', 'row2' );
96  }
97  if ( !isset( $cat_names[$row['storage_category_id']] ) )
98  {
99    $cat = get_cat_info( $row['storage_category_id'] );
100    $cat_names[$row['storage_category_id']] = array();
101    $cat_names[$row['storage_category_id']]['dir'] =
102      '.'.get_complete_dir( $row['storage_category_id'] );
103    $cat_names[$row['storage_category_id']]['display_name'] =
104      get_cat_display_name( $cat['name'], ' &gt; ', 'font-weight:bold;' );
105  }
106  // category name
107  $vtp->setVar( $sub, 'picture.cat_name',
108                $cat_names[$row['storage_category_id']]['display_name'] );
109  // date displayed like this (in English ) :
110  //                     Sunday 15 June 2003 21:29
111  $date = format_date( $row['date'], 'unix', true );
112  $vtp->setVar( $sub, 'picture.date', $date );
113  // file preview link
114  $url = $cat_names[$row['storage_category_id']]['dir'].$row['file'];
115  $vtp->setVar( $sub, 'picture.preview_url', $url );
116  // file name
117  $vtp->setVar( $sub, 'picture.file', $row['file'] );
118  // is there an existing associated thumnail ?
119  if ( $row['tn_ext'] != '' )
120  {
121    $vtp->addSession( $sub, 'thumbnail' );
122    $thumbnail = $conf['prefix_thumbnail'];
123    $thumbnail.= get_filename_wo_extension( $row['file'] );
124    $thumbnail.= '.'.$row['tn_ext'];
125    $url = $cat_names[$row['storage_category_id']]['dir'];
126    $url.= 'thumbnail/'.$thumbnail;
127    $vtp->setVar( $sub, 'thumbnail.preview_url', $url );
128    $vtp->setVar( $sub, 'thumbnail.file', $thumbnail );
129    $vtp->closeSession( $sub, 'thumbnail' );
130  }
131  else
132  {
133    $vtp->addSession( $sub, 'no_thumbnail' );
134    $vtp->closeSession( $sub, 'no_thumbnail' );
135  }
136  // username and associated mail address
137  $vtp->setVar( $sub, 'picture.mail_address', $row['mail_address'] );
138  $vtp->setVar( $sub, 'picture.username', $row['username'] );
139
140  $vtp->closeSession( $sub, 'picture' );
141}
142//----------------------------------------------------------- sending html code
143$vtp->Parse( $handle , 'sub', $sub );
144?>
Note: See TracBrowser for help on using the repository browser.