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 9184 2012-03-24 18:26:23Z mageg $
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 
35 // Check is active
36 if ( !xoops_getModuleOption('active_images', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
37 
38 if (isset($_POST)) {
39  foreach ( $_POST as $k => $v ) {
40  ${$k} = $v;
41  }
42 }
43 
44 // Get Action type
45 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
46 if (isset($_GET['op'])) {
47  $op = trim($_GET['op']);
48 }
49 if (isset($_GET['image_id'])) {
50  $image_id = intval($_GET['image_id']);
51 }
52 if (isset($_GET['imgcat_id'])) {
53  $imgcat_id = intval($_GET['imgcat_id']);
54 }
55 
57 $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
58 
59 // check READ right by category before continue
60 if ( isset($imgcat_id) && $op == 'listimg' ) {
61  $imgcat_read = $gperm_handler->checkRight( 'imgcat_read', $imgcat_id, $groups, $xoopsModule->mid() );
62  $imgcat_write = $gperm_handler->checkRight( 'imgcat_write', $imgcat_id, $groups, $xoopsModule->mid() );
63  if (!$imgcat_read && !$imgcat_write) {
64  redirect_header('admin.php?fct=images',1);
65  }
66 }
67 
68 // check WRITE right by category before continue
69 if ( isset($imgcat_id) && ($op == 'addfile' || $op == 'editcat' || $op == 'updatecat' || $op == 'delcatok' || $op == 'delcat') ) {
70  $imgcat_write = $gperm_handler->checkRight( 'imgcat_write', $imgcat_id, $groups, $xoopsModule->mid() );
71  if (!$imgcat_write) {
72  redirect_header('admin.php?fct=images',1);
73  }
74 }
75 
76 // Only website administator can delete categories or images
77 
78 
79 if ( !$xoopsUser->isAdmin($xoopsModule->mid()) && ($op == 'delfile' || $op == 'delfileok' || $op == 'delcatok' || $op == 'delcat') ) {
80  redirect_header('admin.php?fct=images',1);
81 }
82 
83 switch ( $op ) {
84 
85  case 'list':
86  // Define main template
87  $xoopsOption['template_main'] = 'system_images.html';
88  // Call Header
90  // Define Stylesheet
91  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
92  // Define scripts
93  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
94  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
95  $xoTheme->addScript('modules/system/js/admin.js');
96  // Define Breadcrumb and tips
97  $xoBreadCrumb->addLink( _AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath') );
98  $xoBreadCrumb->addHelp( system_adminVersion('images', 'help') );
100  $xoBreadCrumb->render();
101 
102  $imgcat_handler = xoops_gethandler('imagecategory');
103  $imagecategorys = $imgcat_handler->getObjects();
104 
105  $catcount = count($imagecategorys);
106  $image_handler =& xoops_gethandler('image');
107 
108  foreach (array_keys($imagecategorys) as $i) {
109  $imgcat_read = $gperm_handler->checkRight( 'imgcat_read', $imagecategorys[$i]->getVar('imgcat_id'), $groups, $xoopsModule->mid() );
110  $imgcat_write = $gperm_handler->checkRight( 'imgcat_write', $imagecategorys[$i]->getVar('imgcat_id'), $groups, $xoopsModule->mid() );
111  if ( $imgcat_read || $imgcat_write ) {
112  $count = $image_handler->getCount(new Criteria('imgcat_id', $imagecategorys[$i]->getVar('imgcat_id')));
113 
114  $cat_images['id'] = $imagecategorys[$i]->getVar('imgcat_id');
115  $cat_images['name'] = $imagecategorys[$i]->getVar('imgcat_name');
116  $cat_images['count'] = $count;
117  $cat_images['size'] = $count;
118  $cat_images['maxsize'] = $imagecategorys[$i]->getVar('imgcat_maxsize');
119  $cat_images['maxwidth'] = $imagecategorys[$i]->getVar('imgcat_maxwidth');
120  $cat_images['maxheight'] = $imagecategorys[$i]->getVar('imgcat_maxheight');
121  $cat_images['display'] = $imagecategorys[$i]->getVar('imgcat_display');
122  $cat_images['weight'] = $imagecategorys[$i]->getVar('imgcat_weight');
123  $cat_images['type'] = $imagecategorys[$i]->getVar('imgcat_type');
124  $cat_images['store'] = $imagecategorys[$i]->getVar('imgcat_storetype');
125 
126  $xoopsTpl->append_by_ref('cat_img', $cat_images);
127  unset($cat_images);
128  }
129  }
130  // Image Form
131  if (!empty($catcount)) {
132  $form = new XoopsThemeForm( _ADDIMAGE, 'image_form', 'admin.php', 'post', true );
133  $form->setExtra('enctype="multipart/form-data"');
134  $form->addElement(new XoopsFormText( _IMAGENAME, 'image_nicename', 50, 255), true );
135  $select = new XoopsFormSelect( _IMAGECAT, 'imgcat_id' );
136  $select->addOptionArray($imgcat_handler->getList($groups, 'imgcat_write') );
137  $form->addElement($select, true);
138  $form->addElement(new XoopsFormFile( _IMAGEFILE, 'image_file', 5000000) );
139  $form->addElement(new XoopsFormText( _IMGWEIGHT, 'image_weight', 3, 4, 0) );
140  $form->addElement(new XoopsFormRadioYN( _IMGDISPLAY, 'image_display', 1, _YES, _NO) );
141  $form->addElement(new XoopsFormHidden( 'op', 'addfile'));
142  $form->addElement(new XoopsFormHidden( 'fct', 'images'));
143  $form->addElement(new XoopsFormButton( '', 'img_button', _SUBMIT, 'submit') );
144  $form->assign($xoopsTpl);
145  }
146  // Category Form
147  if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
148  $form = new XoopsThemeForm( _AM_SYSTEM_IMAGES_ADDCAT, 'imagecat_form', 'admin.php', 'post', true);
149  $form->addElement( new XoopsFormText( _AM_SYSTEM_IMAGES_IMGCATNAME, 'imgcat_name', 50, 255 ), true);
150  $form->addElement( new XoopsFormSelectGroup( _AM_SYSTEM_IMAGES_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true ));
151  $form->addElement( new XoopsFormSelectGroup( _AM_SYSTEM_IMAGES_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true ));
152  $form->addElement( new XoopsFormText( _IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000 ));
153  $form->addElement( new XoopsFormText( _IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120 ));
154  $form->addElement( new XoopsFormText( _IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120 ));
155  $form->addElement( new XoopsFormText( _AM_SYSTEM_IMAGES_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0 ));
156  $form->addElement( new XoopsFormRadioYN( _AM_SYSTEM_IMAGES_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO ));
157 
158  $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE.'<br /><span style="color:#ff0000;">'._MD_STRTYOPENG.'</span>', 'imgcat_storetype', 'file');
159  $storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB));
160  $form->addElement($storetype);
161 
162  //$form->addElement(new XoopsFormHidden('imgcat_storetype', 'file'));
163  $form->addElement(new XoopsFormHidden('op', 'addcat'));
164  $form->addElement(new XoopsFormHidden('fct', 'images'));
165  $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
166  $form->assign($xoopsTpl);
167  }
168  // Call Footer
169  xoops_cp_footer();
170  break;
171 
172  case 'display_cat':
173  // Get Image Category handler
174  $imgcat_handler = xoops_gethandler('imagecategory');
175  // Get category id
176  $imgcat_id = system_CleanVars ( $_POST, 'imgcat_id', 0, 'int' );
177  if ( $imgcat_id > 0 ) {
178  $imgcat = $imgcat_handler->get($imgcat_id);
179  $old = $imgcat->getVar('imgcat_display');
180  $imgcat->setVar('imgcat_display', !$old );
181  if (!$imgcat_handler->insert($imgcat)) {
182  $error=true;
183  }
184  }
185  break;
186 
187  case 'listimg':
188  // Get category id
189  $imgcat_id = system_CleanVars ( $_REQUEST, 'imgcat_id', 0, 'int' );
190  if ($imgcat_id <= 0) {
191  redirect_header('admin.php?fct=images', 1);
192  }
193  // Get rights
194  $imgcat_write = $gperm_handler->checkRight( 'imgcat_write', $imgcat_id, $groups, $xoopsModule->mid() );
195  // Get category handler
196  $imgcat_handler = xoops_gethandler('imagecategory');
197 
198  $imagecategory =& $imgcat_handler->get($imgcat_id);
199  if (!is_object($imagecategory)) {
200  redirect_header('admin.php?fct=images', 1);
201  }
202  // Get image handler
203  $image_handler = xoops_gethandler('image');
204  // Define main template
205  $xoopsOption['template_main'] = 'system_images.html';
206  // Call header
207  xoops_cp_header();
208  // Define Stylesheet
209  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
210  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
211  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/lightbox.css' );
212  // Define scripts
213  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
214  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
215  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.lightbox.js');
216  $xoTheme->addScript('modules/system/js/admin.js');
217 
218  // Define Breadcrumb and tips
219  $xoBreadCrumb->addLink( _AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath') );
220  $xoBreadCrumb->addLink( $imagecategory->getVar('imgcat_name') );
221  $xoBreadCrumb->addHelp( system_adminVersion('images', 'help') . '#cat' );
223  $xoBreadCrumb->render();
224 
225  $criteria = new CriteriaCompo(new Criteria('imgcat_id', $imgcat_id));
226  $criteria->setSort('image_weight ASC, image_id');
227  $criteria->setOrder('DESC');
228  $imgcount = $image_handler->getCount($criteria);
229  $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
230  $criteria->setStart($start);
231  $criteria->setLimit(xoops_getModuleOption('images_pager', 'system'));
232  $images = $image_handler->getObjects($criteria, true, false);
233 
234  if ($imagecategory->getVar('imgcat_storetype') == 'db') {
235  $xoopsTpl->assign('db_store', 1 );
236  }
237 
238  foreach (array_keys($images) as $i) {
239  $xoopsTpl->append_by_ref('images', $images[$i]->toArray() );
240  }
241  if ($imgcount > 0) {
242  if ($imgcount > xoops_getModuleOption('images_pager', 'system')) {
243  //include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
244  $nav = new XoopsPageNav($imgcount, xoops_getModuleOption('images_pager', 'system'), $start, 'start', 'fct=images&amp;op=listimg&amp;imgcat_id='.$imgcat_id);
245  $xoopsTpl->assign('nav_menu', $nav->renderImageNav() );
246  }
247  }
248 
249  if ( file_exists( XOOPS_ROOT_PATH . '/modules/system/language/' . $GLOBALS['xoopsConfig']['language'] . '/images/lightbox-btn-close.gif' ) ) {
250  $xoopsTpl->assign('xoops_language', $GLOBALS['xoopsConfig']['language'] );
251  } else {
252  $xoopsTpl->assign('xoops_language', 'english' );
253  }
254  $xoopsTpl->assign('listimg', true);
255 
256  // Image Form
257  $form = new XoopsThemeForm( _ADDIMAGE, 'image_form', 'admin.php', 'post', true );
258  $form->setExtra('enctype="multipart/form-data"');
259  $form->addElement(new XoopsFormText( _IMAGENAME, 'image_nicename', 50, 255), true );
260  $select = new XoopsFormSelect( _IMAGECAT, 'imgcat_id', $imgcat_id);
261  $select->addOptionArray($imgcat_handler->getList($groups, 'imgcat_write') );
262  $form->addElement($select, true);
263  $form->addElement(new XoopsFormFile( _IMAGEFILE, 'image_file', 5000000) );
264  $form->addElement(new XoopsFormText( _IMGWEIGHT, 'image_weight', 3, 4, 0) );
265  $form->addElement(new XoopsFormRadioYN( _IMGDISPLAY, 'image_display', 1, _YES, _NO) );
266  $form->addElement(new XoopsFormHidden( 'op', 'addfile'));
267  $form->addElement(new XoopsFormHidden( 'fct', 'images'));
268  $form->addElement(new XoopsFormButton( '', 'img_button', _SUBMIT, 'submit') );
269  $form->assign($xoopsTpl);
270 
271  // Call Footer
272  xoops_cp_footer();
273  break;
274 
275  case 'display_img':
276  // Get image handler
277  $image_handler = xoops_gethandler('image');
278  // Get image id
279  $image_id = system_CleanVars ( $_POST, 'image_id', 0, 'int' );
280  if ( $image_id > 0 ) {
281  $img = $image_handler->get($image_id);
282  $old = $img->getVar('image_display');
283  $img->setVar('image_display', !$old );
284  if (!$image_handler->insert($img)) {
285  $error=true;
286  }
287  }
288  break;
289 
290  case 'editimg':
291  // Define main template
292  $xoopsOption['template_main'] = 'system_images.html';
293  // Call Header
294  xoops_cp_header();
295  // Define Stylesheet
296  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
297  // Define scripts
298  $xoTheme->addScript('modules/system/js/admin.js');
299  // Get image handler
300  $image_handler = xoops_gethandler('image');
301  $imgcat_handler = xoops_gethandler('imagecategory');
302  // Get image id
303  $image_id = system_CleanVars ( $_REQUEST, 'image_id', 0, 'int' );
304  if ( $image_id > 0 ) {
306  $image_cat =& $imgcat_handler->get($image->getVar('imgcat_id'));
307  // Define Breadcrumb and tips
308  $xoBreadCrumb->addLink( _AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath') );
309  $xoBreadCrumb->addLink( $image_cat->getVar('imgcat_name'), system_adminVersion('images', 'adminpath') . '&amp;op=listimg&amp;imgcat_id=' .$image->getVar('imgcat_id') );
311  $xoBreadCrumb->render();
312  if ($image_cat->getVar('imgcat_storetype') == 'db') {
313  $msg = '<div class="txtcenter"><img class="tooltip" src="' . XOOPS_URL . '/image.php?id=' . $image->getVar('image_id') . '" alt="' . $image->getVar('image_nicename') . '" title="' . $image->getVar('image_nicename') . '" style="max-width:120px; max-height:120px;"/></div>';
314  } else {
315  $msg = '<div class="txtcenter"><img src="./class/thumbs/phpThumb.php?src=' . XOOPS_UPLOAD_PATH . '/' . $image->getVar('image_name') . '&amp;h=120" alt="" /></div>';
316  }
317 
318  $xoopsTpl->assign('edit_thumbs', $msg );
319 
320  $form = new XoopsThemeForm( _AM_SYSTEM_IMAGES_EDITIMG, 'edit_form', 'admin.php', 'post', true );
321  $form->setExtra('enctype="multipart/form-data"');
322  $form->addElement(new XoopsFormText( _IMAGENAME, 'image_nicename', 50, 255, $image->getVar('image_nicename')), true );
323  $select = new XoopsFormSelect( _IMAGECAT, 'imgcat_id', $image->getVar('imgcat_id'));
324  $select->addOptionArray( $imgcat_handler->getList($groups, 'imgcat_write', $image->getVar('imgcat_write')) );
325  $form->addElement($select, true);
326  //$form->addElement(new XoopsFormFile( _IMAGEFILE, 'image_file', 5000000) );
327  $form->addElement(new XoopsFormText( _IMGWEIGHT, 'image_weight', 3, 4, $image->getVar('image_weight') ) );
328  $form->addElement(new XoopsFormRadioYN( _IMGDISPLAY, 'image_display', $image->getVar('image_display'), _YES, _NO) );
329  $form->addElement(new XoopsFormHidden( 'image_id', $image_id ));
330  $form->addElement(new XoopsFormHidden( 'op', 'save' ));
331  $form->addElement(new XoopsFormHidden( 'fct', 'images' ));
332  $form->addElement(new XoopsFormButton( '', 'img_button', _SUBMIT, 'submit' ) );
333  $form->assign($xoopsTpl);
334 
335  } else {
336  redirect_header('admin.php?fct=images', 1, _AM_SYSTEM_DBERROR);
337  }
338  // Call Footer
339  xoops_cp_footer();
340  break;
341 
342  case 'delfile':
343  // Get image handler
344  $image_handler = xoops_gethandler('image');
345  $imgcat_handler = xoops_gethandler('imagecategory');
346  // Call Header
347  xoops_cp_header();
348  // Define Stylesheet
349  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
350  $xoTheme->addStylesheet( 'browse.php?Frameworks/jquery/css/thumbs/thumbs.css' );
351  // Define scripts
352  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
353  $xoTheme->addScript('modules/system/js/thumbs.js');
354  // Get image id
355  $image_id = system_CleanVars ( $_REQUEST, 'image_id', 0, 'int' );
356  if ( $image_id > 0 ) {
358  $image_cat =& $imgcat_handler->get($image->getVar('imgcat_id'));
359  if ($image_cat->getVar('imgcat_storetype') == 'db') {
360  $msg = '<div style="width: 180px;margin:0 auto;"><img class="thumb" src="' . XOOPS_URL . '/image.php?id=' . $image->getVar('image_id') . '" alt="" title="" style="max-width:120px; max-height:120px;"/></div>';
361  } else {
362  $msg = '<div style="width: 180px;margin:0 auto;"><img class="thumb" src="' . XOOPS_UPLOAD_URL . '/' . $image->getVar('image_name') . '" alt="" /></div>';
363  }
364  $msg .= '<div class="spacer">' . $image->getVar('image_nicename') . '</div>';
365  $msg .= '<div class="spacer">' . _AM_SYSTEM_IMAGES_RUDELIMG . '</div>';
366  xoops_confirm( array('op' => 'delfileok', 'image_id' => $image_id, 'fct' => 'images'), 'admin.php', $msg );
367 
368  } else {
369  redirect_header('admin.php?fct=images', 1, _AM_SYSTEM_DBERROR);
370  }
371  // Call Footer
372  xoops_cp_footer();
373  break;
374 
375  case 'delfileok':
376  if (!$GLOBALS['xoopsSecurity']->check()) {
377  redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
378  }
379  // Get image id
380  $image_id = system_CleanVars ( $_POST, 'image_id', 0, 'int' );
381  if ($image_id <= 0) {
382  redirect_header('admin.php?fct=images',1);
383  }
384  $image_handler =& xoops_gethandler('image');
386  if (!is_object($image)) {
387  redirect_header('admin.php?fct=images',1);
388  }
389  if (!$image_handler->delete($image)) {
390  xoops_cp_header();
391  xoops_error( sprintf( _AM_SYSTEM_IMAGES_FAILDEL, $image->getVar('image_id') ) );
392  xoops_cp_footer();
393  exit();
394  }
395  @unlink(XOOPS_UPLOAD_PATH.'/'.$image->getVar('image_name'));
396  redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
397  break;
398 
399  case 'save':
400  if (!$GLOBALS['xoopsSecurity']->check()) {
401  redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
402  exit();
403  }
404  // Get image handler
405  $image_handler = xoops_gethandler('image');
406  // Call Header
407  xoops_cp_header();
408  // Define Stylesheet
409  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
410  // Get image id
411  $image_id = system_CleanVars ( $_POST, 'image_id', 0, 'int' );
412  if ( $image_id > 0 ) {
414  $image->setVars($_POST);
415  if (!$image_handler->insert($image)) {
416  echo sprintf( _AM_SYSTEM_IMAGES_FAILSAVE, $avatar->getVar('avatar_name'));
417  xoops_cp_footer();
418  exit;
419  }
420  redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
421  }
422 
423  // Call Footer
424  xoops_cp_footer();
425  break;
426 
427  case 'addfile':
428  if (!$GLOBALS['xoopsSecurity']->check()) {
429  redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
430  }
431  $imgcat_handler =& xoops_gethandler('imagecategory');
432  $imagecategory =& $imgcat_handler->get(intval($imgcat_id));
433  if (!is_object($imagecategory)) {
434  redirect_header('admin.php?fct=images',1);
435  }
436  xoops_load('xoopsmediauploader');
437  $uploader = new XoopsMediaUploader( XOOPS_UPLOAD_PATH . '/images', array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png', 'image/bmp'), $imagecategory->getVar('imgcat_maxsize'), $imagecategory->getVar('imgcat_maxwidth'), $imagecategory->getVar('imgcat_maxheight'));
438  $uploader->setPrefix('img');
439  $err = array();
440  $ucount = count($_POST['xoops_upload_file']);
441  for ($i = 0; $i < $ucount; $i++) {
442  if ($uploader->fetchMedia($_POST['xoops_upload_file'][$i])) {
443  if (!$uploader->upload()) {
444  $err[] = $uploader->getErrors();
445  } else {
446  $image_handler =& xoops_gethandler('image');
447  $image =& $image_handler->create();
448  $image->setVar('image_name', 'images/' . $uploader->getSavedFileName());
449  $image->setVar('image_nicename', $image_nicename);
450  $image->setVar('image_mimetype', $uploader->getMediaType());
451  $image->setVar('image_created', time());
452  $image_display = empty($image_display) ? 0 : 1;
453  $image->setVar('image_display', $image_display);
454  $image->setVar('image_weight', $image_weight);
455  $image->setVar('imgcat_id', $imgcat_id);
456  if ($imagecategory->getVar('imgcat_storetype') == 'db') {
457  $fp = @fopen($uploader->getSavedDestination(), 'rb');
458  $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
459  @fclose($fp);
460  $image->setVar('image_body', $fbinary, true);
461  @unlink($uploader->getSavedDestination());
462  }
463  if (!$image_handler->insert($image)) {
464  $err[] = sprintf(_FAILSAVEIMG, $image->getVar('image_nicename'));
465  }
466  }
467  } else {
468  $err[] = sprintf(_FAILFETCHIMG, $i);
469  $err = array_merge($err, $uploader->getErrors(false));
470  }
471  }
472  if (count($err) > 0) {
473  xoops_cp_header();
474  xoops_error($err);
475  xoops_cp_footer();
476  exit();
477  }
478  redirect_header('admin.php?fct=images&op=listimg&imgcat_id=' . $image->getVar('imgcat_id'), 2, _AM_SYSTEM_DBUPDATED);
479  break;
480 
481  case 'addcat':
482  if (!$GLOBALS['xoopsSecurity']->check()) {
483  redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
484  }
485  $imgcat_handler =& xoops_gethandler('imagecategory');
486  $imagecategory =& $imgcat_handler->create();
487  $imagecategory->setVar('imgcat_name', $imgcat_name);
488  $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
489  $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
490  $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
491  $imgcat_display = empty($imgcat_display) ? 0 : 1;
492  $imagecategory->setVar('imgcat_display', $imgcat_display);
493  $imagecategory->setVar('imgcat_weight', $imgcat_weight);
494  $imagecategory->setVar('imgcat_storetype', $imgcat_storetype);
495  $imagecategory->setVar('imgcat_type', 'C');
496  if (!$imgcat_handler->insert($imagecategory)) {
497  exit();
498  }
499  $newid = $imagecategory->getVar('imgcat_id');
500  $imagecategoryperm_handler =& xoops_gethandler('groupperm');
501  if (!isset($readgroup)) {
502  $readgroup = array();
503  }
504  if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
505  array_push($readgroup, XOOPS_GROUP_ADMIN);
506  }
507  foreach ($readgroup as $rgroup) {
508  $imagecategoryperm =& $imagecategoryperm_handler->create();
509  $imagecategoryperm->setVar('gperm_groupid', $rgroup);
510  $imagecategoryperm->setVar('gperm_itemid', $newid);
511  $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
512  $imagecategoryperm->setVar('gperm_modid', 1);
513  $imagecategoryperm_handler->insert($imagecategoryperm);
514  unset($imagecategoryperm);
515  }
516  if (!isset($writegroup)) {
517  $writegroup = array();
518  }
519  if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
520  array_push($writegroup, XOOPS_GROUP_ADMIN);
521  }
522  foreach ($writegroup as $wgroup) {
523  $imagecategoryperm =& $imagecategoryperm_handler->create();
524  $imagecategoryperm->setVar('gperm_groupid', $wgroup);
525  $imagecategoryperm->setVar('gperm_itemid', $newid);
526  $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
527  $imagecategoryperm->setVar('gperm_modid', 1);
528  $imagecategoryperm_handler->insert($imagecategoryperm);
529  unset($imagecategoryperm);
530  }
531 
532  redirect_header('admin.php?fct=images',2,_AM_SYSTEM_DBUPDATED);
533  break;
534 
535  case 'editcat':
536  if ($imgcat_id <= 0) {
537  redirect_header('admin.php?fct=images',1);
538  }
539  $imgcat_handler = xoops_gethandler('imagecategory');
540  $imagecategory =& $imgcat_handler->get($imgcat_id);
541  if (!is_object($imagecategory)) {
542  redirect_header('admin.php?fct=images',1);
543  }
544 
545  $imagecategoryperm_handler =& xoops_gethandler('groupperm');
546  $form = new XoopsThemeForm( _AM_SYSTEM_IMAGES_EDITIMG, 'imagecat_form', 'admin.php', 'post', true );
547  $form->addElement(new XoopsFormText( _AM_SYSTEM_IMAGES_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true);
548  $form->addElement(new XoopsFormSelectGroup( _AM_SYSTEM_IMAGES_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true));
549  $form->addElement(new XoopsFormSelectGroup( _AM_SYSTEM_IMAGES_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true));
550  $form->addElement(new XoopsFormText( _IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize')));
551  $form->addElement(new XoopsFormText( _IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth')));
552  $form->addElement(new XoopsFormText( _IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight')));
553  $form->addElement(new XoopsFormText( _AM_SYSTEM_IMAGES_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight')));
554  $form->addElement(new XoopsFormRadioYN( _AM_SYSTEM_IMAGES_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO));
555  $storetype = array( 'db' => _AM_SYSTEM_IMAGES_INDB, 'file' => _AM_SYSTEM_IMAGES_ASFILE );
556  $form->addElement(new XoopsFormLabel( _AM_SYSTEM_IMAGES_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')]));
557  $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
558  $form->addElement(new XoopsFormHidden('op', 'updatecat'));
559  $form->addElement(new XoopsFormHidden('fct', 'images'));
560  $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
561  // Define main template
562  $xoopsOption['template_main'] = 'system_header.html';
563  // Call Header
564  xoops_cp_header();
565  // Define Stylesheet
566  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
567  $xoTheme->addStylesheet( 'browse.php?Frameworks/jquery/css/thumbs/thumbs.css' );
568  $xoTheme->addStylesheet( 'browse.php?Frameworks/jquery/css/lightbox/lightbox.css' );
569  // Define scripts
570  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
571  $xoTheme->addScript('modules/system/js/admin.js');
572  $xoTheme->addScript('modules/system/js/thumbs.js');
573  // Define Breadcrumb and tips
574  $xoBreadCrumb->addLink( _AM_SYSTEM_IMAGES_MANAGER, system_adminVersion('images', 'adminpath') );
575  $xoBreadCrumb->addLink( $imagecategory->getVar('imgcat_name'), '' );
576  $xoBreadCrumb->render();
577  echo "<br />";
578  $form->display();
579  // Call Footer
580  xoops_cp_footer();
581  exit();
582 
583  case 'updatecat':
584  if (!$GLOBALS['xoopsSecurity']->check() || $imgcat_id <= 0) {
585  redirect_header('admin.php?fct=images',1, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
586  }
587  $imgcat_handler = xoops_gethandler('imagecategory');
588  $imagecategory =& $imgcat_handler->get($imgcat_id);
589  if (!is_object($imagecategory)) {
590  redirect_header('admin.php?fct=images',1);
591  }
592  $imagecategory->setVar('imgcat_name', $imgcat_name);
593  $imgcat_display = empty($imgcat_display) ? 0 : 1;
594  $imagecategory->setVar('imgcat_display', $imgcat_display);
595  $imagecategory->setVar('imgcat_maxsize', $imgcat_maxsize);
596  $imagecategory->setVar('imgcat_maxwidth', $imgcat_maxwidth);
597  $imagecategory->setVar('imgcat_maxheight', $imgcat_maxheight);
598  $imagecategory->setVar('imgcat_weight', $imgcat_weight);
599  if (!$imgcat_handler->insert($imagecategory)) {
600  exit();
601  }
602  $imagecategoryperm_handler =& xoops_gethandler('groupperm');
603  $criteria = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
604  $criteria->add(new Criteria('gperm_modid', 1));
605  $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
606  $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
607  $criteria->add($criteria2);
608  $imagecategoryperm_handler->deleteAll($criteria);
609  if (!isset($readgroup)) {
610  $readgroup = array();
611  }
612  if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
613  array_push($readgroup, XOOPS_GROUP_ADMIN);
614  }
615  foreach ($readgroup as $rgroup) {
616  $imagecategoryperm =& $imagecategoryperm_handler->create();
617  $imagecategoryperm->setVar('gperm_groupid', $rgroup);
618  $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
619  $imagecategoryperm->setVar('gperm_name', 'imgcat_read');
620  $imagecategoryperm->setVar('gperm_modid', 1);
621  $imagecategoryperm_handler->insert($imagecategoryperm);
622  unset($imagecategoryperm);
623  }
624  if (!isset($writegroup)) {
625  $writegroup = array();
626  }
627  if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
628  array_push($writegroup, XOOPS_GROUP_ADMIN);
629  }
630  foreach ($writegroup as $wgroup) {
631  $imagecategoryperm =& $imagecategoryperm_handler->create();
632  $imagecategoryperm->setVar('gperm_groupid', $wgroup);
633  $imagecategoryperm->setVar('gperm_itemid', $imgcat_id);
634  $imagecategoryperm->setVar('gperm_name', 'imgcat_write');
635  $imagecategoryperm->setVar('gperm_modid', 1);
636  $imagecategoryperm_handler->insert($imagecategoryperm);
637  unset($imagecategoryperm);
638  }
639  redirect_header('admin.php?fct=images',2,_AM_SYSTEM_DBUPDATED);
640  break;
641 
642  case 'delcat':
643  // Call Header
644  xoops_cp_header();
645  // Display message
646  xoops_confirm( array('op' => 'delcatok', 'imgcat_id' => $imgcat_id, 'fct' => 'images'), 'admin.php', _AM_SYSTEM_IMAGES_RUDELIMGCAT);
647  // Call Footer
648  xoops_cp_footer();
649  break;
650 
651  case 'delcatok':
652  if (!$GLOBALS['xoopsSecurity']->check()) {
653  redirect_header('admin.php?fct=images', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
654  }
655  $imgcat_id = intval($imgcat_id);
656  if ($imgcat_id <= 0) {
657  redirect_header('admin.php?fct=images',1);
658  }
659  $imgcat_handler = xoops_gethandler('imagecategory');
660  $imagecategory =& $imgcat_handler->get($imgcat_id);
661  if (!is_object($imagecategory)) {
662  redirect_header('admin.php?fct=images',1);
663  }
664  if ($imagecategory->getVar('imgcat_type') != 'C') {
665  xoops_cp_header();
666  xoops_error(_MD_SCATDELNG);
667  xoops_cp_footer();
668  exit();
669  }
670  $image_handler =& xoops_gethandler('image');
671  $images = $image_handler->getObjects(new Criteria('imgcat_id', $imgcat_id), true, false);
672  $errors = array();
673  foreach (array_keys($images) as $i) {
674  if (!$image_handler->delete($images[$i])) {
675  $errors[] = sprintf( _AM_SYSTEM_IMAGES_FAILDEL, $i);
676  } else {
677  if (file_exists(XOOPS_UPLOAD_PATH .'/' . $images[$i]->getVar('image_name')) && !unlink(XOOPS_UPLOAD_PATH.'/'.$images[$i]->getVar('image_name'))) {
678  $errors[] = sprintf( _AM_SYSTEM_IMAGES_FAILUNLINK, $i );
679  }
680  }
681  }
682  if (!$imgcat_handler->delete($imagecategory)) {
683  $errors[] = sprintf( _AM_SYSTEM_IMAGES_FAILDELCAT, $imagecategory->getVar('imgcat_name'));
684  }
685  if (count($errors) > 0) {
686  xoops_cp_header();
688  xoops_cp_footer();
689  exit();
690  }
691  redirect_header('admin.php?fct=images', 2, _AM_SYSTEM_DBUPDATED);
692  break;
693 }
694 
695 ?>