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 10936 2013-01-27 23:53:28Z 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 // ------------------------------------------------------------------------- //
37 // Check users rights
38 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) exit( _NOPERM );
39 // Check is active
40 if ( !xoops_getModuleOption('active_userrank', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
41 
42 // Parameters
43 $nb_rank = xoops_getModuleOption('userranks_pager', 'system');
44 $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
45 $upload_size = 500000;
46 // Get Action type
47 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
48 // Get userrank handler
49 $userrank_Handler =& xoops_getModuleHandler("userrank", "system");
50 // Define main template
51 $xoopsOption['template_main'] = 'system_userrank.html';
52 // Call Header
54 
55 switch ($op) {
56 
57  case 'list': default:
58  // Define Stylesheet
59  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
60  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
61  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js');
62  $xoTheme->addScript('modules/system/js/admin.js');
63  // Define Breadcrumb and tips
64  $xoBreadCrumb->addLink(_AM_SYSTEM_USERRANK_NAV_MANAGER, system_adminVersion('userrank', 'adminpath'));
65  $xoBreadCrumb->addHelp( system_adminVersion('userrank', 'help') );
67  $xoBreadCrumb->render();
68  // Get start pager
69  $start = system_CleanVars ( $_REQUEST, 'start', 0, 'int' );
70  // Criteria
71  $criteria = new CriteriaCompo();
72  $criteria->setSort("rank_id");
73  $criteria->setOrder("ASC");
74  $criteria->setStart($start);
75  $criteria->setLimit($nb_rank);
76  // Count rank
77  $userrank_count = $userrank_Handler->getCount($criteria);
78  $userrank_arr = $userrank_Handler->getall($criteria);
79  // Assign Template variables
80  $xoopsTpl->assign( 'userrank_count', $userrank_count );
81  if ( $userrank_count > 0 ){
82  foreach (array_keys($userrank_arr) as $i){
83  $rank_id = $userrank_arr[$i]->getVar("rank_id");
84  $userrank['rank_id'] = $rank_id;
85  $userrank['rank_title'] = $userrank_arr[$i]->getVar("rank_title");
86  $userrank['rank_min'] = $userrank_arr[$i]->getVar("rank_min");
87  $userrank['rank_max'] = $userrank_arr[$i]->getVar("rank_max");
88  $userrank['rank_special'] = $userrank_arr[$i]->getVar("rank_special");
89  $rank_img = ($userrank_arr[$i]->getVar("rank_image")) ? $userrank_arr[$i]->getVar("rank_image") : 'blank.gif';
90  $userrank['rank_image'] = '<img src="'.XOOPS_UPLOAD_URL.'/'.$rank_img.'" alt="" />';
91  $xoopsTpl->append_by_ref( 'userrank', $userrank );
92  unset( $userrank );
93  }
94  }
95  // Display Page Navigation
96  if ($userrank_count > $nb_rank) {
97  $nav = new XoopsPageNav($userrank_count, $nb_rank, $start, 'start', 'fct=userrank&amp;op=list');
98  $xoopsTpl->assign('nav_menu', $nav->renderNav(4));
99  }
100  break;
101 
102  // New userrank
103  case 'userrank_new':
104  // Define Stylesheet
105  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
106  // Define Breadcrumb and tips
107  $xoBreadCrumb->addLink(_AM_SYSTEM_USERRANK_NAV_MANAGER, system_adminVersion('userrank', 'adminpath'));
109  $xoBreadCrumb->addHelp( system_adminVersion('userrank', 'help') . '#new' );
111  $xoBreadCrumb->render();
112  // Create form
113  $obj =& $userrank_Handler->create();
114  $form = $obj->getForm();
115  // Assign form
116  $xoopsTpl->assign('form', $form->render());
117  break;
118 
119  // Edit userrank
120  case 'userrank_edit':
121  // Define Stylesheet
122  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
123  // Define Breadcrumb and tips
124  $xoBreadCrumb->addLink(_AM_SYSTEM_USERRANK_NAV_MANAGER, system_adminVersion('userrank', 'adminpath'));
126  $xoBreadCrumb->addHelp( system_adminVersion('userrank', 'help') . '#edit' );
128  $xoBreadCrumb->render();
129  // Create form
130  $obj = $userrank_Handler->get(system_CleanVars($_REQUEST, 'rank_id', 0, 'int'));
131  $form = $obj->getForm();
132  // Assign form
133  $xoopsTpl->assign('form', $form->render());
134  break;
135 
136  // Save rank
137  case 'userrank_save':
138  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
139  redirect_header("admin.php?fct=userrank", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
140  }
141  if (isset($_POST["rank_id"])) {
142  $obj =& $userrank_Handler->get($_POST["rank_id"]);
143  } else {
144  $obj =& $userrank_Handler->create();
145  }
146 
147  $obj->setVar("rank_title", $_POST["rank_title"]);
148  $obj->setVar("rank_min", $_POST["rank_min"]);
149  $obj->setVar("rank_max", $_POST["rank_max"]);
150  $verif_rank_special = ($_POST["rank_special"] == 1) ? "1" : "0";
151  $obj->setVar("rank_special", $verif_rank_special);
152 
153  include_once XOOPS_ROOT_PATH . '/class/uploader.php';
154  $uploader_rank_img = new XoopsMediaUploader( XOOPS_UPLOAD_PATH . '/ranks', $mimetypes, $upload_size, null, null);
155 
156  if ($uploader_rank_img->fetchMedia("rank_image")) {
157  $uploader_rank_img->setPrefix("rank") ;
158  $uploader_rank_img->fetchMedia("rank_image");
159  if (!$uploader_rank_img->upload()) {
160  $errors = $uploader_rank_img->getErrors();
161  redirect_header("javascript:history.go(-1)",3, $errors);
162  } else {
163  $obj->setVar("rank_image", 'ranks/' . $uploader_rank_img->getSavedFileName());
164  }
165  } else {
166  $obj->setVar("rank_image", 'ranks/' . $_POST["rank_image"]);
167  }
168 
169  if ($userrank_Handler->insert($obj)) {
170  redirect_header("admin.php?fct=userrank", 2, _AM_SYSTEM_USERRANK_SAVE);
171  }
172  break;
173 
174  // Delete userrank
175  case 'userrank_delete':
176  $rank_id = system_CleanVars($_REQUEST, 'rank_id', 0, 'int');
177  $obj =& $userrank_Handler->get( $rank_id );
178  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
179  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
180  redirect_header("admin.php?fct=userrank", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
181  }
182  if ($userrank_Handler->delete($obj)) {
183  $urlfile = XOOPS_UPLOAD_PATH . '/' . $obj->getVar("rank_image");
184  if (is_file($urlfile)){
185  chmod($urlfile, 0777);
186  unlink($urlfile);
187  }
188  redirect_header("admin.php?fct=userrank", 2, _AM_SYSTEM_USERRANK_SAVE);
189  } else {
190  xoops_error( $obj->getHtmlErrors() );
191  }
192  } else {
193  // Define Stylesheet
194  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
195  // Define Breadcrumb and tips
196  $xoBreadCrumb->addLink(_AM_SYSTEM_USERRANK_NAV_MANAGER, system_adminVersion('userrank', 'adminpath'));
198  $xoBreadCrumb->addHelp( system_adminVersion('userrank', 'help') . '#delete' );
199  $xoBreadCrumb->render();
200  $rank_img = ($obj->getVar("rank_image")) ? $obj->getVar("rank_image") : 'blank.gif';
201  xoops_confirm(array("ok" => 1, "rank_id" => $_REQUEST["rank_id"], "op" => "userrank_delete"), $_SERVER["REQUEST_URI"], sprintf(_AM_SYSTEM_USERRANK_SUREDEL) . '<br ><img src="' . XOOPS_UPLOAD_URL . '/' . $rank_img . '" alt="" /><br >');
202  }
203  break;
204 
205  // Update userrank status
206  case 'userrank_update_special':
207  // Get rank id
208  $rank_id = system_CleanVars ( $_POST, 'rank_id', 0, 'int' );
209  if ( $rank_id > 0 ) {
210  $obj =& $userrank_Handler->get($rank_id);
211  $old = $obj->getVar('rank_special');
212  $obj->setVar('rank_special', !$old );
213  if ($userrank_Handler->insert($obj)) {
214  exit;
215  }
216  echo $obj->getHtmlErrors();
217  }
218  break;
219 
220 }
221 // Call Footer
223 
224 ?>