source: trunk/admin/comments.php @ 34

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

template as user_template for displaying pictures in the template

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