XOOPS  2.6.0
avatar_system.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 
13 
24 include __DIR__ . '/header.php';
25 // Get main instance
28 
31 
32 // Parameters
33 $nb_avatars = $helper->getConfig('avatars_pager');
34 $mimetypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
35 $upload_size = $helper->getConfig('avatars_imagefilesize');
36 $width = $helper->getConfig('avatars_imagewidth');
37 $height = $helper->getConfig('avatars_imageheight');
38 // Get Action type
39 $op = Request::getCmd('op', 'list');
40 // Get avatar handler
41 $avatar_Handler = $helper->getHandlerAvatar();
42 // Call Header
43 $xoops->header('admin:avatars/avatars_admin_system.tpl');
44 
45 $admin_page = new \Xoops\Module\Admin();
46 $admin_page->renderNavigation('avatar_system.php');
47 
48 $info_msg = array(
49  sprintf(AvatarsLocale::ALERT_INFO_MIMETYPES, implode(", ", $mimetypes)),
52 );
53 
54 switch ($op) {
55 
56  case 'list':
57  default:
58  // Add Scripts
59  $xoops->theme()->addScript('media/xoops/xoops.js');
60  // Define Stylesheet
61  $xoops->theme()->addStylesheet('modules/avatars/css/admin.css');
62 
64  $admin_page->addItemButton(XoopsLocale::A_ADD, 'avatar_system.php?op=new', 'add');
65  $admin_page->renderTips();
66  $admin_page->renderButton();
67  // Get start pager
68  $start = Request::getInt('start', 0);
69  // Filter avatars
70  $criteria = new Criteria('avatar_type', 'S');
71  $avatar_count = $avatar_Handler->getCount($criteria);
72  $xoops->tpl()->assign('avatar_count', $avatar_count);
73  // Get avatar list
74  $criteria->setStart($start);
75  $criteria->setLimit($nb_avatars);
76  $criteria->setSort("avatar_weight");
77  $criteria->setOrder("ASC");
78  $avatars_arr = $avatar_Handler->getObjects($criteria, true);
79  // Construct avatars array
80  $avatar_list = array();
81  $i = 0;
82  foreach (array_keys($avatars_arr) as $i) {
83  $avatar_list[$i] = $avatars_arr[$i]->getValues();
84  $avatar_list[$i]['count'] = count($avatar_Handler->getUser($avatars_arr[$i]));
85  }
86  $xoops->tpl()->assign('avatars_list', $avatar_list);
87  // Display Page Navigation
88  if ($avatar_count > $nb_avatars) {
89  $nav = new XoopsPageNav($avatar_count, $nb_avatars, $start, 'start', 'op=list');
90  $xoops->tpl()->assign('nav_menu', $nav->renderNav(4));
91  }
92  break;
93 
94  // New
95  case "new":
96  $admin_page->addItemButton(AvatarsLocale::LIST_OF_AVATARS, 'avatar_system.php', 'application-view-detail');
97  $admin_page->renderButton();
98  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, XoopsLocale::INFORMATION_FOR_UPLOADS));
99  // Create form
100  $obj = $avatar_Handler->create();
101  $form = $xoops->getModuleForm($obj, 'avatar');
102  // Assign form
103  $xoops->tpl()->assign('form', $form->render());
104  break;
105 
106  // Edit
107  case "edit":
108  $admin_page->addItemButton(AvatarsLocale::LIST_OF_AVATARS, 'avatar_system.php', 'application-view-detail');
109  $admin_page->renderButton();
110  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, XoopsLocale::INFORMATION_FOR_UPLOADS));
111  // Create form
112  $obj = $avatar_Handler->get(Request::getInt('avatar_id', 0));
113  $form = $xoops->getModuleForm($obj, 'avatar');
114  // Assign form
115  $xoops->tpl()->assign('form', $form->render());
116  break;
117 
118  // Save
119  case "save":
120  // Check security
121  if (!$xoops->security()->check()) {
122  $xoops->redirect('avatar_system.php', 3, implode('<br />', $xoops->security()->getErrors()));
123  }
124  $uploader_avatars_img =
126  // Get avatar id
127  $avatar_id = Request::getInt('avatar_id', 0);
128  if ($avatar_id > 0) {
129  $obj = $avatar_Handler->get($avatar_id);
130  } else {
131  $obj = $avatar_Handler->create();
132  }
133  $error_msg = '';
134  $obj->setVars($_POST);
135  if (preg_match('/^\d+$/', $_POST["avatar_weight"]) == false) {
136  $error_msg .= XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER . '<br />';
137  $obj->setVar("avatar_weight", 0);
138  } else {
139  $obj->setVar("avatar_weight", Request::getInt('avatar_weight', 0));
140  }
141  $obj->setVar('avatar_type', 's');
142  if ($uploader_avatars_img->fetchMedia('avatar_file')) {
143  $uploader_avatars_img->setPrefix('savt');
144  $uploader_avatars_img->fetchMedia('avatar_file');
145  if (!$uploader_avatars_img->upload()) {
146  $error_msg .= $uploader_avatars_img->getErrors();
147  $obj->setVar('avatar_file', 'avatars/blank.gif');
148  } else {
149  $obj->setVar('avatar_mimetype', $uploader_avatars_img->getMediaType());
150  $obj->setVar('avatar_file', 'avatars/' . $uploader_avatars_img->getSavedFileName());
151  }
152  } else {
153  $file = Request::getString('avatar_file', 'blank.gif');
154  $obj->setVar('avatar_file', 'avatars/' . $file);
155  }
156  if ($error_msg == '') {
157  if ($avatar_Handler->insert($obj)) {
158  $xoops->redirect('avatar_system.php', 2, XoopsLocale::S_ITEM_SAVED);
159  }
160  $error_msg .= $obj->getHtmlErrors();
161  }
162  $admin_page->addItemButton(AvatarsLocale::LIST_OF_AVATARS, 'avatar_system.php', 'application-view-detail');
163  $admin_page->renderButton();
164  $xoops->tpl()->assign('info_msg', $xoops->alert('info', $info_msg, XoopsLocale::INFORMATION_FOR_UPLOADS));
165  $xoops->tpl()->assign('error_msg', $xoops->alert('error', $error_msg, XoopsLocale::ERRORS));
166  $form = $xoops->getModuleForm($obj, 'avatar');
167  $xoops->tpl()->assign('form', $form->render());
168  break;
169 
170  //Delete
171  case "delete":
172  $avatar_id = Request::getInt('avatar_id', 0);
173  $obj = $avatar_Handler->get($avatar_id);
174  if (isset($_POST["ok"]) && $_POST["ok"] == 1) {
175  if (!$xoops->security()->check()) {
176  $xoops->redirect("avatar_system.php", 3, implode(",", $xoops->security()->getErrors()));
177  }
178  if ($avatar_Handler->delete($obj)) {
179  // Delete file
180  $file = $obj->getVar('avatar_file');
181  if ($file != 'avatars/blank.gif') {
182  $fullname = $xoops_upload_path . '/' . $file;
183  if (is_file($fullname)) {
184  chmod($fullname, 0777);
185  unlink($fullname);
186  }
187  }
188  // Update member profiles
189  $qb = $xoops->db()->createXoopsQueryBuilder();
190  $eb = $qb->expr();
191  $query = $qb->updatePrefix('users')
192  ->set('user_avatar', 'blank.gif')
193  ->where($eb->eq('user_avatar', ':file '))
194  ->setParameter(':file', $file);
195  $result = $query->execute();
196  $xoops->redirect("avatar_system.php", 2, XoopsLocale::S_ITEM_SAVED);
197  } else {
198  echo $xoops->alert('error', $obj->getHtmlErrors());
199  }
200  } else {
201  if ($avatar_id > 0) {
202  // Define Stylesheet
203  $xoops->theme()->addStylesheet('modules/system/css/admin.css');
204  $msg = '<div class="spacer"><img src="' . $xoops_upload_url . '/'
205  . $obj->getVar('avatar_file', 's')
206  . '" alt="" /></div><div class="txtcenter bold">'
207  . $obj->getVar('avatar_name', 's') . '</div>'
209  // Display message
210  echo $xoops->confirm(
211  array('ok' => 1, 'op' => 'delete', 'avatar_id' => $avatar_id),
212  'avatar_system.php',
213  $msg
214  );
215  } else {
216  $xoops->redirect('avatar_system.php', 1, XoopsLocale::E_DATABASE_NOT_UPDATED);
217  }
218  }
219  break;
220 
221  case "update_display":
222  $avatar_id = Request::getInt('avatar_id', 0);
223  if ($avatar_id > 0) {
224  $obj = $avatar_Handler->get($avatar_id);
225  $old = $obj->getVar('avatar_display');
226  $obj->setVar('avatar_display', !$old);
227  if ($avatar_Handler->insert($obj)) {
228  exit;
229  }
230  echo $obj->getHtmlErrors();
231  }
232  break;
233 }
234 $xoops->footer();
const E_YOU_NEED_A_POSITIVE_INTEGER
Definition: en_US.php:385
const A_ADD
Definition: en_US.php:77
const ERRORS
Definition: en_US.php:302
$i
Definition: dialog.php:68
$height
static getInstance()
Definition: Xoops.php:160
$width
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
const INFORMATION_FOR_UPLOADS
Definition: en_US.php:480
$xoops_upload_path
$query
Definition: index.php:37
const ALERT_INFO_MAXFILE
Definition: en_US.php:25
$result
Definition: pda.php:33
$info_msg
$mimetypes
$form
Definition: xoops_code.php:21
exit
Definition: browse.php:104
$xoops_upload_url
static get($name)
$nb_avatars
const ALERT_INFO_MIMETYPES
Definition: en_US.php:26
$avatar_Handler
const Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM
Definition: en_US.php:929
const ALERT_INFO_PIXELS
Definition: en_US.php:27
static getInstance()
Definition: helper.php:34
$upload_size
$xoops
$admin_page
$criteria
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
$helper
const S_ITEM_SAVED
Definition: en_US.php:1028
$start
const LIST_OF_AVATARS
Definition: en_US.php:39
const SYSTEM_TIPS
Definition: en_US.php:49
const E_DATABASE_NOT_UPDATED
Definition: en_US.php:320