source: tags/release-1_3RC1/admin/comments.php @ 27109

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

In comments validation section, shows only unvalidated comments, not all
comments of picture which have unvalidated comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 KB
Line 
1<?php
2/***************************************************************************
3 *                               comments.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: comments.php 79 2003-09-07 21:39:24Z 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$page['plain_structure'] = get_plain_structure();
21//------------------------------------------------------------------- functions
22function display_pictures( $mysql_result, $maxtime, $validation_box = false )
23{
24  global $vtp,$sub,$lang,$conf,
25    $array_cat_directories,$array_cat_site_id,$array_cat_names;
26
27  while ( $row = mysql_fetch_array( $mysql_result ) )
28  {
29    $vtp->addSession( $sub, 'picture' );
30    // 2. for each picture, getting informations for displaying thumbnail and
31    //    link to the full size picture
32    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
33    $query.= ' FROM '.PREFIX_TABLE.'images';
34    $query.= ' WHERE id = '.$row['image_id'];
35    $query.= ';';
36    $subresult = mysql_query( $query );
37    $subrow = mysql_fetch_array( $subresult );
38
39    if ( $array_cat_directories[$subrow['cat_id']] == '' )
40    {
41      $array_cat_directories[$subrow['cat_id']] =
42        get_complete_dir( $subrow['cat_id'] );
43      $cat_result = get_cat_info( $subrow['cat_id'] );
44      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
45      $array_cat_names[$subrow['cat_id']] =
46        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
47    }
48    $cat_directory = $array_cat_directories[$row['cat_id']];
49    $file = get_filename_wo_extension( $subrow['file'] );
50    // name of the picture
51    $name = $array_cat_names[$subrow['cat_id']].' &gt; ';
52    if ( $subrow['name'] != '' )
53    {
54      $name.= $subrow['name'];
55    }
56    else
57    {
58      $name.= str_replace( '_', ' ', $file );
59    }
60    $name.= ' [ '.$subrow['file'].' ]';
61    $vtp->setVar( $sub, 'picture.title', $name );
62    // source of the thumbnail picture
63    $src = '';
64    if ( $array_cat_site_id[$subrow['cat_id']] == 1 )
65    {
66      $src.= '.';
67    }
68    $src.= $array_cat_directories[$subrow['cat_id']];
69    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
70    $src.= $file.'.'.$subrow['tn_ext'];
71    $vtp->setVar( $sub, 'picture.thumb_src', $src );
72    // link to the full size picture
73    $url = '../picture.php?cat='.$subrow['cat_id'];
74    $url.= '&amp;image_id='.$row['image_id'];
75    $vtp->setVar( $sub, 'picture.thumb_url', add_session_id( $url ) );
76    // 3. for each picture, retrieving all comments
77    $query = 'SELECT id,date,author,content';
78    $query.= ' FROM '.PREFIX_TABLE.'comments';
79    $query.= ' WHERE image_id = '.$row['image_id'];
80    $query.= ' AND date > '.$maxtime;
81    if ( $validation_box ) $query.= " AND validated = 'false'";
82    $query.= ' ORDER BY date DESC';
83    $query.= ';';
84    $subresult = mysql_query( $query );
85    while ( $subrow = mysql_fetch_array( $subresult ) )
86    {
87      $vtp->addSession( $sub, 'comment' );
88      $author = $subrow['author'];
89      if ( $subrow['author'] == '' ) $author = $lang['guest'];
90      $vtp->setVar( $sub, 'comment.author', $author );
91      $displayed_date = format_date( $subrow['date'], 'unix', true );
92      $vtp->setVar( $sub, 'comment.date', $displayed_date );
93      $vtp->setVar( $sub, 'comment.content', nl2br( $subrow['content'] ) );
94      $vtp->addSession( $sub, 'delete' );
95      $url = './admin.php?page=comments';
96      if ( isset( $_GET['last_days'] ) ) $url.= '&amp;last_days='.MAX_DAYS;
97      if ( isset( $_GET['show_unvalidated'] ) )
98        $url.= '&amp;show_unvalidated=true';
99      $url.= '&amp;del='.$subrow['id'];
100      $vtp->setVar( $sub, 'delete.link', add_session_id( $url ) );
101      $vtp->closeSession( $sub, 'delete' );
102      // if the comment has to be validated, we display a checkbox
103      if ( $validation_box )
104      {
105        $vtp->addSession( $sub, 'validation' );
106        $vtp->setVar( $sub, 'validation.id', $subrow['id'] );
107        $vtp->closeSession( $sub, 'validation' );
108      }
109      $vtp->closeSession( $sub, 'comment' );
110    }
111    $vtp->closeSession( $sub, 'picture' );
112  }
113}
114//------------------------------------------------------------ comment deletion
115if ( isset( $_GET['del'] ) and is_numeric( $_GET['del'] ) )
116{
117  $query = 'DELETE FROM '.PREFIX_TABLE.'comments';
118  $query.= ' WHERE id = '.$_GET['del'];
119  $query.= ';';
120  mysql_query( $query );
121}
122//--------------------------------------------------------- comments validation
123if ( isset( $_POST['submit'] ) )
124{
125  $query = 'SELECT id';
126  $query.= ' FROM '.PREFIX_TABLE.'comments';
127  $query.= " WHERE validated = 'false'";
128  $query.= ';';
129  $result = mysql_query( $query );
130  while ( $row = mysql_fetch_array( $result ) )
131  {
132    if ( $_POST['validate-'.$row['id']] == 'true' )
133    {
134      $query = 'UPDATE '.PREFIX_TABLE.'comments';
135      $query.= " SET validated = 'true'";
136      $query.= ' WHERE id = '.$row['id'];
137      $query.= ';';
138      mysql_query( $query );
139    }
140  }
141}
142//----------------------------------------------------- template initialization
143$sub = $vtp->Open( '../template/'.$user['template'].'/admin/comments.vtp' );
144$tpl = array( 'stats_last_days','delete','close','submit','open' );
145templatize_array( $tpl, 'lang', $sub );
146$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
147//--------------------------------------------------- number of days to display
148if ( isset( $_GET['last_days'] ) ) define( MAX_DAYS, $_GET['last_days'] );
149else                               define( MAX_DAYS, 0 );
150//----------------------------------------- non specific section initialization
151$array_cat_directories = array();
152$array_cat_names       = array();
153$array_cat_site_id     = array();
154//------------------------------------------------------- last comments display
155$vtp->addSession( $sub, 'section' );
156$vtp->setVar( $sub, 'section.title', $lang['comments_last_title'] );
157$vtp->addSession( $sub, 'last_days' );
158foreach ( $conf['last_days'] as $option ) {
159  $vtp->addSession( $sub, 'last_day_option' );
160  $vtp->setVar( $sub, 'last_day_option.option', $option );
161  $url = './admin.php?page=comments';
162  $url.= '&amp;last_days='.($option - 1);
163  $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) );
164  if ( $option == MAX_DAYS + 1 )
165  {
166    $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;');
167  }
168  $vtp->closeSession( $sub, 'last_day_option' );
169}
170$vtp->closeSession( $sub, 'last_days' );
171if ( isset( $_GET['last_days'] ) )
172{
173  $vtp->addSession( $sub, 'close' );
174  $url = './admin.php?page=comments';
175  if ( isset( $_GET['show_unvalidated'] ) )
176  {
177    $url.= '&amp;show_unvalidated='.$_GET['show_unvalidated'];
178  }
179  $vtp->setVar( $sub, 'close.url', add_session_id( $url ) );
180  $vtp->closeSession( $sub, 'close' );
181  // 1. retrieving picture ids which have comments recently added
182  $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
183  list($year,$month,$day) = explode( '-', $date);
184  $maxtime = mktime( 0,0,0,$month,$day,$year );
185  $query = 'SELECT DISTINCT(image_id) as image_id';
186  $query.= ' FROM '.PREFIX_TABLE.'comments';
187  $query.=     ', '.PREFIX_TABLE.'images as images';
188  $query.= ' WHERE image_id = images.id';
189  $query.= ' AND date > '.$maxtime;
190  $query.= ' ORDER BY date_available DESC';
191  $query.= ';';
192  $result = mysql_query( $query );
193  display_pictures( $result, $maxtime );
194}
195$vtp->closeSession( $sub, 'section' );
196//---------------------------------------------- non validated comments display
197$vtp->addSession( $sub, 'section' );
198$vtp->setVar( $sub, 'section.title', $lang['comments_non_validated_title'] );
199if ( isset( $_GET['show_unvalidated'] ) )
200{
201  // form starts
202  $vtp->addSession( $sub, 'start_form' );
203  $action = './admin.php?page=comments';
204  if ( isset( $_GET['last_days'] ) )
205  {
206    $action.= '&amp;last_days='.$_GET['last_days'];
207  }
208  $action.= '&amp;show_unvalidated=true';
209  $vtp->setVar( $sub, 'start_form.action', add_session_id( $action ) );
210  $vtp->closeSession( $sub, 'start_form' );
211  // close this section ?
212  $vtp->addSession( $sub, 'close' );
213  $url = './admin.php?page=comments';
214  if ( isset( $_GET['last_days'] ) )
215  {
216    $url.= '&amp;last_days='.$_GET['last_days'];
217  }
218  $vtp->setVar( $sub, 'close.url', add_session_id( $url ) );
219  $vtp->closeSession( $sub, 'close' );
220  // retrieving all picture ids which have unvalidated comments
221  $query = 'SELECT DISTINCT(image_id) as image_id';
222  $query.= ' FROM '.PREFIX_TABLE.'comments as comments';
223  $query.=     ', '.PREFIX_TABLE.'images as images';
224  $query.= ' WHERE image_id = images.id';
225  $query.= " AND comments.validated = 'false'";
226  $query.= ' ORDER BY date_available DESC';
227  $query.= ';';
228  $result = mysql_query( $query );
229  display_pictures( $result, 0, true );
230  $vtp->addSession( $sub, 'submit' );
231  $vtp->closeSession( $sub, 'submit' );
232  // form ends
233  $vtp->addSession( $sub, 'end_form' );
234  $vtp->closeSession( $sub, 'end_form' );
235}
236else
237{
238  $vtp->addSession( $sub, 'open' );
239  $url = './admin.php?page=comments';
240  if ( isset( $_GET['last_days'] ) )
241  {
242    $url.= '&amp;last_days='.$_GET['last_days'];
243  }
244  $url.= '&amp;show_unvalidated=true';
245  $vtp->setVar( $sub, 'open.url', add_session_id( $url ) );
246  $vtp->closeSession( $sub, 'open' );
247}
248$vtp->closeSession( $sub, 'section' );
249//----------------------------------------------------------- sending html code
250$vtp->Parse( $handle, 'sub', $sub );
251?>
Note: See TracBrowser for help on using the repository browser.