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 // ------------------------------------------------------------------------- //
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_smilies', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
36 
37 // Parameters
38 $nb_smilies = xoops_getModuleOption('smilies_pager', 'system');
39 $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
40 $upload_size = 500000;
41 // Get Action type
42 $op = system_CleanVars ( $_REQUEST, 'op', 'list', 'string' );
43 // Get smilies handler
44 $smilies_Handler =& xoops_getModuleHandler("smilies", "system");
45 // Define main template
46 $xoopsOption['template_main'] = 'system_smilies.html';
47 // Call Header
49 
50 $xoBreadCrumb->addLink(_AM_SYSTEM_SMILIES_NAV_MANAGER, system_adminVersion('smilies', 'adminpath'));
51 
52 switch ($op) {
53 
54  case 'list': default:
55  // Define Stylesheet
56  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
57  $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
58  $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js');
59  $xoTheme->addScript('modules/system/js/admin.js');
60  // Define Breadcrumb and tips
62  $xoBreadCrumb->addHelp( system_adminVersion('smilies', 'help') );
63  $xoBreadCrumb->render();
64  // Get start pager
65  $start = system_CleanVars ( $_REQUEST, 'start', 0, 'int' );
66  // Criteria
67  $criteria = new CriteriaCompo();
68  $criteria->setSort("id");
69  $criteria->setOrder("ASC");
70  $criteria->setStart($start);
71  $criteria->setLimit($nb_smilies);
72  // Count smilies
73  $smilies_count = $smilies_Handler->getCount($criteria);
74  $smilies_arr = $smilies_Handler->getall($criteria);
75  // Assign Template variables
76  $xoopsTpl->assign( 'smilies_count', $smilies_count );
77  if ( $smilies_count > 0 ){
78  foreach (array_keys($smilies_arr) as $i){
79  $smilies_id = $smilies_arr[$i]->getVar("id");
80  $smilies['smilies_id'] = $smilies_id;
81  $smilies['code'] = $smilies_arr[$i]->getVar("code");
82  $smilies['emotion'] = $smilies_arr[$i]->getVar("emotion");
83  $smilies['display'] = $smilies_arr[$i]->getVar("display");
84  $smilies_img = ($smilies_arr[$i]->getVar("smile_url")) ? $smilies_arr[$i]->getVar("smile_url") : 'blank.gif';
85  $smilies['image'] = '<img src="' . XOOPS_UPLOAD_URL . '/' . $smilies_img . '" alt="" />';
86  $smilies['edit_delete'] = '<a href="admin.php?fct=smilies&amp;op=edit_smilie&amp;smilies_id=' . $smilies_id . '">
87  <img src="./images/icons/edit.png" border="0" alt="' . _AM_SYSTEM_SMILIES_EDIT . '" title="' . _AM_SYSTEM_SMILIES_EDIT . '"></a>
88  <a href="admin.php?fct=smilies&amp;op=smilies_delete&amp;smilies_id=' . $smilies_id . '">
89  <img src="./images/icons/delete.png" border="0" alt="' . _AM_SYSTEM_SMILIES_DELETE . '" title="' . _AM_SYSTEM_SMILIES_DELETE . '"></a>';
90  $xoopsTpl->append_by_ref( 'smilies', $smilies );
91  unset( $smilies );
92  }
93  }
94  // Display Page Navigation
95  if ($smilies_count > $nb_smilies) {
96  $nav = new XoopsPageNav($smilies_count, $nb_smilies, $start, 'start', 'fct=smilies&amp;op=list');
97  $xoopsTpl->assign('nav_menu', $nav->renderNav(4));
98  }
99  break;
100 
101  // New smilie
102  case "new_smilie":
103  // Define Stylesheet
104  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
105  // Define Breadcrumb and tips
107  $xoBreadCrumb->addHelp( system_adminVersion('smilies', 'help') . '#new' );
109  $xoBreadCrumb->render();
110  // Create form
111  $obj =& $smilies_Handler->create();
112  $form = $obj->getForm();
113  // Assign form
114  $xoopsTpl->assign('form', $form->render());
115  break;
116 
117  // Edit smilie
118  case "edit_smilie":
119  // Define Stylesheet
120  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
121  // Define Breadcrumb and tips
123  $xoBreadCrumb->addHelp( system_adminVersion('smilies', 'help') . '#edit' );
125  $xoBreadCrumb->render();
126  // Create form
127  $obj = $smilies_Handler->get(system_CleanVars($_REQUEST, 'smilies_id', 0, 'int'));
128  $form = $obj->getForm();
129  // Assign form
130  $xoopsTpl->assign('form', $form->render());
131  break;
132 
133  // Save smilie
134  case "save_smilie":
135  if (!$GLOBALS['xoopsSecurity']->check()) {
136  redirect_header('admin.php?fct=smilies', 3, implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()));
137  exit();
138  }
139  // Define Breadcrumb and tips
142  $xoBreadCrumb->render();
143 
144  if (isset($_POST["smilies_id"])) {
145  $obj =& $smilies_Handler->get(system_CleanVars($_POST, 'smilies_id', 0, 'int'));
146  } else {
147  $obj =& $smilies_Handler->create();
148  }
149  // erreur
150  $obj->setVar("code", $_POST["code"]);
151  $obj->setVar("emotion", $_POST["emotion"]);
152  $display = ($_POST["display"] == 1) ? "1" : "0";
153  $obj->setVar("display", $display);
154 
155  include_once XOOPS_ROOT_PATH . '/class/uploader.php';
156  $uploader_smilies_img = new XoopsMediaUploader( XOOPS_UPLOAD_PATH . '/smilies', $mimetypes, $upload_size, null, null);
157 
158  if ($uploader_smilies_img->fetchMedia("smile_url")) {
159  $uploader_smilies_img->setPrefix("smil") ;
160  $uploader_smilies_img->fetchMedia("smile_url");
161  if (!$uploader_smilies_img->upload()) {
162  $errors = $uploader_smilies_img->getErrors();
163  redirect_header("javascript:history.go(-1)",3, $errors);
164  } else {
165  $obj->setVar("smile_url", 'smilies/' . $uploader_smilies_img->getSavedFileName());
166  }
167  } else {
168  $obj->setVar("smile_url", 'smilies/' . $_POST["smile_url"]);
169  }
170  if ($smilies_Handler->insert($obj)) {
171  redirect_header("admin.php?fct=smilies", 2, _AM_SYSTEM_SMILIES_SAVE);
172  }
173  echo $obj->getHtmlErrors();
174  // Create form
175  $obj =& $smilies_Handler->create();
176  $form =& $obj->getForm();
177  // Assign form
178  $xoopsTpl->assign('form', $form->render());
179  break;
180 
181  //Del a smilie
182  case "smilies_delete":
183  $smilies_id = system_CleanVars($_REQUEST, 'smilies_id', 0, 'int');
184  $obj =& $smilies_Handler->get( $smilies_id );
185  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
186  if ( !$GLOBALS["xoopsSecurity"]->check() ) {
187  redirect_header("admin.php?fct=smilies", 3, implode(",", $GLOBALS["xoopsSecurity"]->getErrors()));
188  }
189  if ($smilies_Handler->delete($obj)) {
190  $urlfile = XOOPS_UPLOAD_PATH . '/' . $obj->getVar("smile_url");
191  if (is_file($urlfile)){
192  chmod($urlfile, 0777);
193  unlink($urlfile);
194  }
195  redirect_header("admin.php?fct=smilies", 2, _AM_SYSTEM_SMILIES_SAVE);
196  } else {
197  xoops_error( $obj->getHtmlErrors() );
198  }
199  } else {
200  // Define Stylesheet
201  $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css' );
202  // Define Breadcrumb and tips
204  $xoBreadCrumb->addHelp( system_adminVersion('smilies', 'help') . '#delete' );
205  $xoBreadCrumb->render();
206  $smilies_img = ($obj->getVar("smile_url")) ? $obj->getVar("smile_url") : 'blank.gif';
207  xoops_confirm(array("ok" => 1, "smilies_id" => $_REQUEST["smilies_id"], "op" => "smilies_delete"), $_SERVER["REQUEST_URI"], sprintf(_AM_SYSTEM_SMILIES_SUREDEL) . '<br ><img src="' . XOOPS_UPLOAD_URL . '/' . $smilies_img . '" alt="" /><br >');
208  }
209  break;
210 
211  case "smilies_update_display":
212  // Get smilies id
213  $smilies_id = system_CleanVars ( $_POST, 'smilies_id', 0, 'int' );
214  if ( $smilies_id > 0 ) {
215  $obj =& $smilies_Handler->get($smilies_id);
216  $old = $obj->getVar('display');
217  $obj->setVar('display', !$old);
218  if ($smilies_Handler->insert($obj)) {
219  exit;
220  }
221  echo $obj->getHtmlErrors();
222  }
223  break;
224 }
225 // Call Footer
227 ?>