XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 8066 2011-11-06 05:09:33Z beckmi $
3 // ------------------------------------------------------------------------ //
4 // XOOPS - PHP Content Management System //
5 // Copyright (c) 2000 XOOPS.org //
6 // <http://www.xoops.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
27 // Author: Kazumi Ono (AKA onokazu) //
28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29 // Project: The XOOPS Project //
30 // ------------------------------------------------------------------------- //
31 
32 // Check users rights
33 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
34 // Check is active
35 if ( !xoops_getModuleOption('active_avatars', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
36 // Get Action type
37 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
38 
39 switch ($op) {
40 
41  case 'list': default:
42  // Define main template
43  $xoopsOption['template_main'] = 'system_avatars.html';
44  // Call Header
46  // Define Stylesheet
47  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
48  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
49  $xoTheme->addScript('modules/system/js/admin.js');
50  // Define Breadcrumb and tips
51  $xoBreadCrumb->addLink( _AM_SYSTEM_AVATAR_MANAGER, system_adminVersion('avatars', 'adminpath') );
52  $xoBreadCrumb->addHelp( system_adminVersion('avatars', 'help') );
54  $xoBreadCrumb->render();
55  // Get avatar handler
56  $avt_handler =& xoops_getmodulehandler('avatar');
57  // Get User Config
58  $config_handler =& xoops_gethandler('config');
59  $xoopsConfigUser = $config_handler->getConfigsByCat( XOOPS_CONF_USER );
60  // User language
61  xoops_loadLanguage('user');
62  // Count avatars
63  $savatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'S'));
64  $cavatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'C'));
65  // Assign Template variables
66  $xoopsTpl->assign( 'view_cat', true );
67  $xoopsTpl->assign( 'count_system', $savatar_count );
68  $xoopsTpl->assign( 'count_custom', $cavatar_count );
69  // Create form
70  $avatar = $avt_handler->create();
71  $form = $avatar->getForm();
72  // Assign form
73  $xoopsTpl->assign('form', $form->render());
74  // Call Footer
76  break;
77 
78  case 'listavt':
79  // Get Avatar type
80  $type = system_CleanVars ( $_REQUEST, 'type', 'c', 'string' );
81  $start = system_CleanVars ( $_REQUEST, 'start', 0, 'int' );
82  // Define main template
83  $xoopsOption['template_main'] = 'system_avatars.html';
84  // Call Header
86  // Define Stylesheet
87  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
88  // Define scripts
89  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
90  $xoTheme->addScript('modules/system/js/admin.js');
91  // Define Breadcrumb and tips
92  $xoBreadCrumb->addLink( _AM_SYSTEM_AVATAR_MANAGER, system_adminVersion('avatars', 'adminpath') );
94  $xoBreadCrumb->addHelp( system_adminVersion('avatars', 'help') . '#' . $type );
96  $xoBreadCrumb->render();
97  // Get avatar handler
98  $avt_handler =& xoops_gethandler('avatar');
99  // Count avatars
100  $savatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'S'));
101  $cavatar_count = $avt_handler->getCount(new Criteria('avatar_type', 'C'));
102  // Assign Template variables
103  $xoopsTpl->assign( 'type', $type);
104  $xoopsTpl->assign( 'count_system', $savatar_count );
105  $xoopsTpl->assign( 'count_custom', $cavatar_count );
106  // Filter avatars
107  $criteria = new Criteria('avatar_type', $type);
108  $avtcount = $avt_handler->getCount($criteria);
109  // Get avatar list
110  $criteria->setStart($start);
111  $criteria->setLimit( xoops_getModuleOption('avatars_pager', 'system'));
112  $avatars = $avt_handler->getObjects($criteria, true);
113  // Construct avatars array
114  $avatar_list = array();
115  $i=0;
116  foreach (array_keys($avatars) as $i) {
117  $avatar_list[$i] = $avatars[$i]->toArray();
118  $avatar_list[$i]['type'] = $type;
119  $avatar_list[$i]['count'] = count($avt_handler->getUser($avatars[$i]));
120  if($type == 'c') {
121  $user = $avt_handler->getUser($avatars[$i]);
122  if(is_array($user) && isset($user[0])) $avatar_list[$i]['user'] = $user[0];
123  }
124  }
125  $xoopsTpl->assign('avatars_list', $avatar_list);
126  // Display Page Navigation
127  if ( $avtcount > xoops_getModuleOption('avatars_pager') ) {
128  $nav = new XoopsPageNav($avtcount, xoops_getModuleOption('avatars_pager', 'system'), $start, 'start', 'fct=avatars&amp;type=' . $type . '&amp;op=listavt');
129  $xoopsTpl->assign('nav_menu', $nav->renderImageNav());
130  }
131  // Call Footer
132  xoops_cp_footer();
133  break;
134 
135  case 'edit':
136  // Define main template
137  $xoopsOption['template_main'] = 'system_avatars.html';
138  // Call Header
139  xoops_cp_header();
140  // Define Stylesheet
141  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
142  // Define Breadcrumb and tips
143  $xoBreadCrumb->addLink( _AM_SYSTEM_AVATAR_MANAGER, system_adminVersion('avatars', 'adminpath') );
145  $xoBreadCrumb->addHelp( system_adminVersion('avatars', 'help') . '#edit' );
147  $xoBreadCrumb->render();
148  // User language
149  xoops_loadLanguage('user');
150  // Get avatar handler
151  $avt_handler =& xoops_getmodulehandler('avatar');
152  $avatar_id = system_CleanVars ( $_REQUEST, 'avatar_id', 0, 'int' );
153  if ( $avatar_id > 0 ) {
154  $avatar = $avt_handler->get( $avatar_id );
155  // Create form
156  $form = $avatar->getForm();
157  // Assign form
158  $xoopsTpl->assign('form', $form->render());
159  } else {
160  redirect_header('admin.php?fct=avatars', 1, _AM_SYSTEM_DBERROR);
161  }
162  // Call Footer
163  xoops_cp_footer();
164  break;
165 
166  case 'save':
167  // Check security
168  if ( !$GLOBALS['xoopsSecurity']->check() ) {
169  redirect_header( 'admin.php?fct=avatars', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors() ) );
170  exit();
171  }
172  $config_handler =& xoops_gethandler( 'config' );
173  $xoopsConfigUser = $config_handler->getConfigsByCat( XOOPS_CONF_USER );
174  // Upload class
175  include_once $GLOBALS['xoops']->path( '/class/uploader.php' );
176 
177  $uploader = new XoopsMediaUploader( XOOPS_UPLOAD_PATH . '/avatars', array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $xoopsConfigUser['avatar_maxsize'], $xoopsConfigUser['avatar_width'], $xoopsConfigUser['avatar_height']);
178  // Get avatar handler
179  $avt_handler =& xoops_gethandler('avatar');
180  // Get avatar id
181  $avatar_id = system_CleanVars ( $_POST, 'avatar_id', 0, 'int' );
182  if ( $avatar_id > 0 ) {
183  $avatar =& $avt_handler->get( $avatar_id );
184  } else {
185  $avatar =& $avt_handler->create();
186  }
187  $err = array();
188  if ($uploader->fetchMedia('avatar_file')) {
189  $uploader->setPrefix('savt');
190  if (!$uploader->upload()) {
191  $err[] = $uploader->getErrors();
192  } else {
193  $avatar->setVars( $_POST );
194  $avatar->setVar('avatar_file', 'avatars/' . $uploader->getSavedFileName() );
195  $avatar->setVar('avatar_mimetype', $uploader->getMediaType());
196  $avatar->setVar('avatar_type', 's');
197  if (!$avt_handler->insert($avatar)) {
198  $err[] = sprintf(_FAILSAVEIMG, $avatar->getVar('avatar_name') );
199  }
200  }
201  } else {
202  $file = system_CleanVars ( $_REQUEST, 'avatar_file', 'blank.gif', 'string' );
203  $avatar->setVars($_REQUEST);
204  $avatar->setVar('avatar_file', 'avatars/' . $file);
205  if (!$avt_handler->insert($avatar)) {
206  $err[] = sprintf(_FAILSAVEIMG, $avatar->getVar('avatar_name'));
207  }
208  }
209  if (count($err) > 0) {
210  // Define main template
211  $xoopsOption['template_main'] = 'system_header.html';
212  // Call header
213  xoops_cp_header();
214  // Define Stylesheet
215  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
216  // Define Breadcrumb and tips
217  $xoBreadCrumb->addLink( _AM_SYSTEM_AVATAR_MANAGER, system_adminVersion('avatars', 'adminpath') );
219  $xoBreadCrumb->render();
220  // Dsiplay errors
221  xoops_error( $err );
222  // Call Footer
223  xoops_cp_footer();
224  exit();
225  }
226  redirect_header( 'admin.php?fct=avatars', 2, _AM_SYSTEM_DBUPDATED );
227  break;
228 
229  case 'display':
230  // Get avatar handler
231  $avt_handler =& xoops_gethandler('avatar');
232  // Get avatar id
233  $avatar_id = system_CleanVars ( $_POST, 'avatar_id', 0, 'int' );
234  if ( $avatar_id > 0 ) {
235  // Get avatar
236  $avatar =& $avt_handler->get( $avatar_id );
237  $old = $avatar->getVar('avatar_display');
238  // Set value
239  $avatar->setVar('avatar_display', !$old );
240  if (!$avt_handler->insert($avatar)) {
241  $error=true;
242  }
243  }
244  break;
245 
246  case 'delfile':
247  // Define main template
248  $xoopsOption['template_main'] = 'system_avatars.html';
249  // Call Header
250  xoops_cp_header();
251  // Define Stylesheet
252  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
253  // Define Breadcrumb and tips
254  $xoBreadCrumb->addLink( _AM_SYSTEM_AVATAR_MANAGER, system_adminVersion('avatars', 'adminpath') );
256  $xoBreadCrumb->addHelp( system_adminVersion('avatars', 'help') . '#delete' );
257  $xoBreadCrumb->render();
258  // Get variables
259  $user_id = system_CleanVars ( $_REQUEST, 'user_id', 0, 'int' );
260  $avatar_id = system_CleanVars ( $_REQUEST, 'avatar_id', 0, 'int' );
261  // Get avatar handler
262  $avt_handler =& xoops_gethandler('avatar');
263  if ( $avatar_id > 0 ) {
264  $avatar = $avt_handler->get($avatar_id);
265  $msg = '<div class="spacer"><img src="' . XOOPS_UPLOAD_URL . '/' . $avatar->getVar('avatar_file','s') . '" alt="" /></div><div class="txtcenter bold">' . $avatar->getVar('avatar_name', 's') . '</div>' . _AM_SYSTEM_AVATAR_SUREDEL;
266  // Display message
267  xoops_confirm(array('op' => 'delfileok', 'avatar_id' => $avatar_id, 'fct' => 'avatars', 'user_id' => $user_id), 'admin.php', $msg );
268  } else {
269  redirect_header('admin.php?fct=avatars', 1, _AM_SYSTEM_DBERROR);
270  }
271  // Call footer
272  xoops_cp_footer();
273  break;
274 
275  case 'delfileok':
276  if (!$GLOBALS['xoopsSecurity']->check()) {
277  redirect_header('admin.php?fct=avatars',1, 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
278  }
279  $avatar_id = system_CleanVars ( $_POST, 'avatar_id', 0, 'int' );
280  if ($avatar_id <= 0) {
281  redirect_header('admin.php?fct=avatars', 1, _AM_SYSTEM_DBERROR);
282  }
283  $avt_handler = xoops_gethandler('avatar');
284  $avatar =& $avt_handler->get( $avatar_id );
285  if ( !is_object( $avatar ) ) {
286  redirect_header('admin.php?fct=avatars', 1, _AM_SYSTEM_DBERROR);
287  }
288  if (!$avt_handler->delete( $avatar )) {
289  // Call Header
290  xoops_cp_header();
291  // Display errors
292  xoops_error( sprintf( _AM_SYSTEM_AVATAR_FAILDEL, $avatar->getVar('avatar_id') ) );
293  // Call Footer
294  xoops_cp_footer();
295  exit();
296  }
297  $file = $avatar->getVar('avatar_file');
298  // Delete file
299  @unlink(XOOPS_UPLOAD_PATH.'/'.$file);
300  // Update member profil
301  if (isset($user_id) && $avatar->getVar('avatar_type') == 'C') {
302  $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE uid=".intval($user_id));
303  } else {
304  $xoopsDB->query("UPDATE ".$xoopsDB->prefix('users')." SET user_avatar='blank.gif' WHERE user_avatar='".$file."'");
305  }
306  redirect_header( 'admin.php?fct=avatars', 2, _AM_SYSTEM_DBUPDATED );
307  break;
308 }
309 
310 ?>