XOOPS  2.6.0
categories.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
14 
24 include __DIR__ . '/header.php';
25 
26 // Call Header
27 $xoops->header('admin:images/images_admin_categories.tpl');
28 
29 $admin_page = new \Xoops\Module\Admin();
30 $admin_page->renderNavigation('categories.php');
31 
32 switch ($op) {
33  case 'save':
34  if (!$xoops->security()->check()) {
35  $xoops->redirect('categories.php', 3, implode('<br />', $xoops->security()->getErrors()));
36  }
37 
38  $imgcat_id = Request::getInt('imgcat_id', 0);
39  if (isset($imgcat_id) && $imgcat_id != 0) {
40  $obj = $helper->getHandlerCategories()->get($imgcat_id);
41  $isnew = false;
42  } else {
43  $obj = $helper->getHandlerCategories()->create();
44  $isnew = true;
45  }
46  $obj->setVar('imgcat_name', Request::getString('imgcat_name', ''));
47  $obj->setVar('imgcat_maxsize', Request::getInt('imgcat_maxsize', 100000));
48  $obj->setVar('imgcat_maxwidth', Request::getInt('imgcat_maxwidth', 128));
49  $obj->setVar('imgcat_maxheight', Request::getInt('imgcat_maxheight', 128));
50  $obj->setVar('imgcat_display', Request::getBool('imgcat_display', 1));
51  $obj->setVar('imgcat_weight', Request::getInt('imgcat_weight', 0));
52  $obj->setVar('imgcat_storetype', Request::getString('imgcat_storetype', 'file'));
53  $obj->setVar('imgcat_type', 'C');
54 
55  if ($imgcat_id = $helper->getHandlerCategories()->insert($obj)) {
56  // delete permissions
57  if (!$isnew) {
58  $criteria = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
59  $criteria->add(new Criteria('gperm_modid', $xoops->module->getVar('mid')));
60  $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
61  $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
62  $criteria->add($criteria2);
63  $xoops->getHandlerGroupperm()->deleteAll($criteria);
64  }
65  // Save permissions
66  $permissions = array('readgroup' => 'imgcat_read', 'writegroup' => 'imgcat_write');
67  foreach ($permissions as $k => $permission) {
68  $groups = Request::getArray($k, array(FixedGroups::ADMIN));
69  if (!in_array(FixedGroups::ADMIN, $groups)) {
70  array_push($groups, FixedGroups::ADMIN);
71  }
72  foreach ($groups as $group) {
73  $perm_obj = $xoops->getHandlerGroupperm()->create();
74  $perm_obj->setVar('gperm_groupid', $group);
75  $perm_obj->setVar('gperm_itemid', $imgcat_id);
76  $perm_obj->setVar('gperm_name', $permission);
77  $perm_obj->setVar('gperm_modid', $xoops->module->getVar('mid'));
78  $xoops->getHandlerGroupperm()->insert($perm_obj);
79  unset($perm_obj);
80  }
81  }
82  $xoops->redirect('categories.php', 2, _AM_IMAGES_CAT_SAVE);
83  }
84  $xoops->redirect('categories.php', 2, _AM_IMAGES_CAT_NOTSAVE . '<br />' . implode('<br />', $obj->getHtmlErrors()));
85  break;
86 
87  case 'add':
88  $obj = $helper->getHandlerCategories()->create();
89  $form = $helper->getForm($obj, 'category');
90  $xoops->tpl()->assign('form', $form->render());
91  break;
92 
93  case 'edit':
94  $imgcat_id = Request::getInt('imgcat_id', 0);
95  if ($imgcat_id > 0) {
96  $obj = $helper->getHandlerCategories()->get($imgcat_id);
97  $form = $helper->getForm($obj, 'category');
98  $xoops->tpl()->assign('form', $form->render());
99  }
100  break;
101 
102  case 'del':
103  $imgcat_id = Request::getInt('imgcat_id', 0);
104  if ($imgcat_id > 0) {
105  $ok = Request::getInt('ok', 0);
106  $obj = $helper->getHandlerCategories()->get($imgcat_id);
107 
108  if ($ok == 1) {
109  if (!$xoops->security()->check()) {
110  $xoops->redirect('categories.php', 3, implode(',', $xoops->security()->getErrors()));
111  }
112  if ($helper->getHandlerCategories()->delete($obj)) {
113  // Delete image datas and files
114  $images = $helper->getHandlerImages()->getByCategory($obj->getVar('imgcat_id'));
115  foreach ($images as $image) {
116  if ($helper->getHandlerImages()->delete($image)) {
117  if ($obj->getVar('imgcat_storetype') == 'db') {
118  $helper->getHandlerImagesBody()->delete($helper->getHandlerImagesBody()->get($image->getVar('image_id')));
119  } else {
120  unlink(\XoopsBaseConfig::get('uploads-path') . '/' . $image->getVar('image_name'));
121  }
122  }
123  }
124 
125  // Delete permissions
126  $criteria = new CriteriaCompo(new Criteria('gperm_itemid', $imgcat_id));
127  $criteria->add(new Criteria('gperm_modid', $xoops->module->getVar('mid')));
128  $criteria2 = new CriteriaCompo(new Criteria('gperm_name', 'imgcat_write'));
129  $criteria2->add(new Criteria('gperm_name', 'imgcat_read'), 'OR');
130  $criteria->add($criteria2);
131  $xoops->getHandlerGroupperm()->deleteAll($criteria);
132 
133  $xoops->redirect('categories.php', 2, XoopsLocale::S_DATABASE_UPDATED);
134  }
135  } else {
136  echo $xoops->confirm(
137  array('op' => 'del', 'ok' => 1, 'imgcat_id' => $imgcat_id),
138  XOOPS_URL . '/modules/images/admin/categories.php',
139  sprintf(_AM_IMAGES_CAT_DELETE, $obj->getVar('imgcat_name'))
140  );
141  }
142  }
143  break;
144 
145  case 'display':
146  $imgcat_id = Request::getInt('imgcat_id', 0);
147  if ($imgcat_id > 0) {
148  $imgcat = $helper->getHandlerCategories()->get($imgcat_id);
149  $old = $imgcat->getVar('imgcat_display');
150  $imgcat->setVar('imgcat_display', !$old);
151  if (!$helper->getHandlerCategories()->insert($imgcat)) {
152  $error = true;
153  }
154  }
155  break;
156 
157  case 'list':
158  default:
159  $admin_page->addItemButton(_AM_IMAGES_CAT_ADD, 'categories.php?op=add', 'add');
160  $admin_page->renderButton();
161 
162  $categories = $helper->getHandlerCategories()->getPermittedObjects();
163 
164  foreach (array_keys($categories) as $i) {
165  $imgcat_read = $gperm_handler->checkRight('imgcat_read', $categories[$i]->getVar('imgcat_id'), $groups, $xoops->module->mid());
166  $imgcat_write = $gperm_handler->checkRight('imgcat_write', $categories[$i]->getVar('imgcat_id'), $groups, $xoops->module->mid());
167  if ($imgcat_read || $imgcat_write) {
168  $count = $helper->getHandlerImages()->countByCategory($categories[$i]->getVar('imgcat_id'));
169  $cat_images = $categories[$i]->getValues();
170  $cat_images['imgcat_count'] = $count;
171  $xoops->tpl()->appendByRef('categories', $cat_images);
172  unset($cat_images);
173  }
174  }
175  break;
176 }
177 $xoops->footer();
if(empty($image_id)) $image
Definition: image.php:37
if(empty($settings['ROOT_PATH'])) elseif(empty($settings['DB_PARAMETERS'])) $error
$i
Definition: dialog.php:68
const _AM_IMAGES_CAT_SAVE
Definition: admin.php:35
$form
Definition: xoops_code.php:21
$gperm_handler
$xoops
Definition: admin.php:25
const _AM_IMAGES_CAT_ADD
Definition: admin.php:33
static get($name)
$criteria2
$groups
$imgcat_id
$helper
$criteria
$op
const _AM_IMAGES_CAT_NOTSAVE
Definition: admin.php:36
const _AM_IMAGES_CAT_DELETE
Definition: admin.php:37
const S_DATABASE_UPDATED
Definition: en_US.php:1024
$admin_page
Definition: categories.php:29