XOOPS  2.6.0
userrank.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 
22 include __DIR__ . '/header.php';
23 
24 // Get main instance
27 
28 // Parameters
29 $nb_rank = $xoops->getModuleConfig('admin:userrank/userrank_pager');
30 $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
31 $upload_size = 500000;
32 // Get Action type
33 $op = $system->cleanVars($_REQUEST, 'op', 'list', 'string');
34 // Get userrank handler
35 $userrank_Handler = $xoops->getHandler("ranks");
36 // Call Header
37 $xoops->header('admin:userrank/userrank.tpl');
38 
39 $admin_page = new \Xoops\Module\Admin();
40 $admin_page->renderNavigation('userrank.php');
41 
42 switch ($op) {
43 
44  case 'list':
45  default:
46  // Add Scripts
47  $xoops->theme()->addScript('media/xoops/xoops.js');
48 
50  $admin_page->addItemButton(_AM_USERRANK_ADD, './userrank.php?op=userrank_new', 'add');
51  $admin_page->renderTips();
52  $admin_page->renderButton();
53 
54  // Get start pager
55  $start = $system->cleanVars($_REQUEST, 'start', 0, 'int');
56  // Criteria
57  $criteria = new CriteriaCompo();
58  $criteria->setSort("rank_id");
59  $criteria->setOrder("ASC");
60  $criteria->setStart($start);
61  $criteria->setLimit($nb_rank);
62  // Count rank
63  $userrank_count = $userrank_Handler->getCount($criteria);
64  $userrank_arr = $userrank_Handler->getall($criteria);
65  // Assign Template variables
66  $xoops->tpl()->assign('userrank_count', $userrank_count);
67  if ($userrank_count > 0) {
68  foreach (array_keys($userrank_arr) as $i) {
69  $rank_id = $userrank_arr[$i]->getVar("rank_id");
70  $userrank['rank_id'] = $rank_id;
71  $userrank['rank_title'] = $userrank_arr[$i]->getVar("rank_title");
72  $userrank['rank_min'] = $userrank_arr[$i]->getVar("rank_min");
73  $userrank['rank_max'] = $userrank_arr[$i]->getVar("rank_max");
74  $userrank['rank_special'] = $userrank_arr[$i]->getVar("rank_special");
75  $rank_img = ($userrank_arr[$i]->getVar("rank_image")) ? $userrank_arr[$i]->getVar("rank_image") : 'blank.gif';
76  $userrank['rank_image'] = '<img src="' . \XoopsBaseConfig::get('uploads-url') . '/' . $rank_img . '" alt="" />';
77  $xoops->tpl()->appendByRef('userrank', $userrank);
78  unset($userrank);
79  }
80  }
81  // Display Page Navigation
82  if ($userrank_count > $nb_rank) {
83  $nav = new XoopsPageNav($userrank_count, $nb_rank, $start, 'start', 'userrank.php');
84  $xoops->tpl()->assign('nav_menu', $nav->renderNav(4));
85  }
86  break;
87 
88  // New userrank
89  case 'userrank_new':
90  $admin_page->addTips(sprintf(_AM_USERRANK_TIPS_FORM1, implode(', ', $mimetypes)) . sprintf(_AM_USERRANK_TIPS_FORM2, $upload_size / 1000));
91  $admin_page->addItemButton(_AM_USERRANK_LIST, './userrank.php', 'application-view-detail');
92  $admin_page->renderTips();
93  $admin_page->renderButton();
94  // Create form
95  $obj = $userrank_Handler->create();
96  $form = $xoops->getModuleForm($obj, 'ranks');
97  $xoops->tpl()->assign('form', $form->render());
98  break;
99 
100  // Edit userrank
101  case 'userrank_edit':
102  $admin_page->addTips(sprintf(_AM_USERRANK_TIPS_FORM1, implode(', ', $mimetypes)) . sprintf(_AM_USERRANK_TIPS_FORM2, $upload_size / 1000));
103  $admin_page->addItemButton(_AM_USERRANK_ADD, './userrank.php?op=userrank_new', 'add');
104  $admin_page->addItemButton(_AM_USERRANK_LIST, './userrank.php', 'application-view-detail');
105  $admin_page->renderTips();
106  $admin_page->renderButton();
107  // Create form
108  $obj = $userrank_Handler->get($system->cleanVars($_REQUEST, 'rank_id', 0, 'int'));
109  $form = $xoops->getModuleForm($obj, 'ranks');
110  $xoops->tpl()->assign('form', $form->render());
111  break;
112 
113  // Save rank
114  case 'userrank_save':
115  if (!$xoops->security()->check()) {
116  $xoops->redirect("userrank.php", 3, implode(",", $xoops->security()->getErrors()));
117  }
118  if (isset($_POST["rank_id"])) {
119  $obj = $userrank_Handler->get($_POST["rank_id"]);
120  } else {
121  $obj = $userrank_Handler->create();
122  }
123 
124  $obj->setVar("rank_title", $_POST["rank_title"]);
125  $obj->setVar("rank_min", $_POST["rank_min"]);
126  $obj->setVar("rank_max", $_POST["rank_max"]);
127  $verif_rank_special = ($_POST["rank_special"] == 1) ? "1" : "0";
128  $obj->setVar("rank_special", $verif_rank_special);
129 
130  $uploader_rank_img = new XoopsMediaUploader(\XoopsBaseConfig::get('uploads-url') . '/ranks', $mimetypes, $upload_size, null, null);
131 
132  if ($uploader_rank_img->fetchMedia("rank_image")) {
133  $uploader_rank_img->setPrefix("rank");
134  $uploader_rank_img->fetchMedia("rank_image");
135  if (!$uploader_rank_img->upload()) {
136  $errors = $uploader_rank_img->getErrors();
137  $xoops->redirect("javascript:history.go(-1)", 3, $errors);
138  } else {
139  $obj->setVar("rank_image", 'ranks/' . $uploader_rank_img->getSavedFileName());
140  }
141  } else {
142  $obj->setVar("rank_image", 'ranks/' . $_POST["rank_image"]);
143  }
144 
145  if ($userrank_Handler->insert($obj)) {
146  $xoops->redirect("userrank.php", 2, _AM_USERRANK_SAVE);
147  }
148  break;
149 
150  // Delete userrank
151  case 'userrank_delete':
152  $admin_page->addItemButton(_AM_USERRANK_ADD, './userrank.php?op=userrank_new', 'add');
153  $admin_page->addItemButton(_AM_USERRANK_LIST, './userrank.php', 'list');
154  $admin_page->renderButton();
155  $rank_id = $system->cleanVars($_REQUEST, 'rank_id', 0, 'int');
156  $obj = $userrank_Handler->get($rank_id);
157  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
158  if (!$xoops->security()->check()) {
159  $xoops->redirect("userrank.php", 3, implode(",", $xoops->security()->getErrors()));
160  }
161  if ($userrank_Handler->delete($obj)) {
162  $urlfile = \XoopsBaseConfig::get('uploads-url') . '/' . $obj->getVar("rank_image");
163  if (is_file($urlfile)) {
164  chmod($urlfile, 0777);
165  unlink($urlfile);
166  }
167  $xoops->redirect("userrank.php", 2, _AM_USERRANK_SAVE);
168  } else {
169  echo $xoops->alert('error', $obj->getHtmlErrors());
170  }
171  } else {
172  $rank_img = ($obj->getVar("rank_image")) ? $obj->getVar("rank_image") : 'blank.gif';
173  echo $xoops->confirm(array(
174  "ok" => 1, "rank_id" => $_REQUEST["rank_id"], "op" => "userrank_delete"
175  ), $_SERVER["REQUEST_URI"], sprintf(_AM_USERRANK_SUREDEL) . '<br ><img src="' . \XoopsBaseConfig::get('uploads-url') . '/' . $rank_img . '" alt="" /><br >');
176  }
177  break;
178 
179  // Update userrank status
180  case 'userrank_update_special':
181  // Get rank id
182  $rank_id = $system->cleanVars($_POST, 'rank_id', 0, 'int');
183  if ($rank_id > 0) {
184  $obj = $userrank_Handler->get($rank_id);
185  $old = $obj->getVar('rank_special');
186  $obj->setVar('rank_special', !$old);
187  if ($userrank_Handler->insert($obj)) {
188  exit;
189  }
190  echo $obj->getHtmlErrors();
191  }
192  break;
193 
194 }
195 // Call Footer
196 $xoops->footer();
$i
Definition: dialog.php:68
const _AM_USERRANK_ADD
Definition: admin.php:23
static getInstance()
Definition: system.php:46
$admin_page
Definition: userrank.php:39
static getInstance()
Definition: Xoops.php:160
const _AM_USERRANK_TIPS_FORM2
Definition: admin.php:47
$_SERVER['REQUEST_URI']
const _AM_USERRANK_SAVE
Definition: admin.php:33
$form
Definition: xoops_code.php:21
exit
Definition: browse.php:104
$mimetypes
Definition: userrank.php:30
$upload_size
Definition: userrank.php:31
$system
Definition: userrank.php:25
const _AM_USERRANK_SUREDEL
Definition: admin.php:36
$userrank_Handler
Definition: userrank.php:35
static get($name)
$op
Definition: userrank.php:33
$criteria
const _AM_USERRANK_TIPS_FORM1
Definition: admin.php:46
const _AM_USERRANK_LIST
Definition: admin.php:28
$start
$nb_rank
Definition: userrank.php:29
$xoops
Definition: userrank.php:26
const _AM_USERRANK_TIPS
Definition: admin.php:45