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