XOOPS  2.6.0
avatar.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 
24 {
25  public function __construct(AvatarsAvatar $obj)
26  {
27  if ($obj->isNew()) {
28  $blank_img = 'blank.gif';
29  } else {
30  $blank_img = str_replace('avatars/', '', $obj->getVar('avatar_file', 'e'));
31  }
32  //$xoops = Xoops::getInstance();
33  // New and edit form
35 
36  $action = $_SERVER['REQUEST_URI'];
37  parent::__construct($title, 'avatar_form', $action, "post", true);
38  $this->setExtra('enctype="multipart/form-data"');
39  // Name
40  $this->addElement(new Xoops\Form\Text(XoopsLocale::NAME, 'avatar_name', 5, 255, $obj->getVar('avatar_name', 'e')), true);
41  // Upload part
42  $imgtray_img = new Xoops\Form\ElementTray(XoopsLocale::FILE, '<br />');
43  $avatars_path = \XoopsBaseConfig::get('uploads-path') . '/avatars';
44  $imageselect_img = new Xoops\Form\Select(sprintf(XoopsLocale::F_FILE_EXISTS_IN, $avatars_path . '/'), 'avatar_file', $blank_img);
45  $image_array_img = XoopsLists::getImgListAsArray($avatars_path);
46  $imageselect_img->addOption("$blank_img", $blank_img);
47  foreach ($image_array_img as $image_img) {
48  $imageselect_img->addOption("$image_img", $image_img);
49  }
51  $imageselect_img->setExtra("onchange='showImgSelected(\"xo-avatar-img\", \"avatar_file\", \"avatars\", \"\", \"" . $xoops_upload_url . "\")'");
52  $imgtray_img->addElement($imageselect_img, false);
53  $imgtray_img->addElement(new Xoops\Form\Label('', "<br /><img src='" . $xoops_upload_url . "/avatars/" . $blank_img . "' name='image_img' id='xo-avatar-img' alt='' />"));
54  $fileseltray_img = new Xoops\Form\ElementTray('<br />', '<br /><br />');
55  $fileseltray_img->addElement(new Xoops\Form\File(XoopsLocale::A_UPLOAD, 'avatar_file'), false);
56  // , $xoops->getModuleConfig('avatars_imagefilesize')
57  $imgtray_img->addElement($fileseltray_img);
58  $this->addElement($imgtray_img);
59  // Weight
60  $weight = new Xoops\Form\Text(XoopsLocale::DISPLAY_ORDER, 'avatar_weight', 1, 4, $obj->getVar('avatar_weight', 'e'), '');
62  $this->addElement($weight, true);
63  // Display
64  $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::DISPLAY_THIS_ITEM, 'avatar_display', $obj->getVar('avatar_display', 'e'), XoopsLocale::YES, XoopsLocale::NO));
65  // Hidden
66  if ($obj->isNew()) {
67  $this->addElement(new Xoops\Form\Hidden('avatar_type', 's'));
68  }
69  $this->addElement(new Xoops\Form\Hidden('op', 'save'));
70  $this->addElement(new Xoops\Form\Hidden('avatar_id', $obj->getVar('avatar_id', 'e')));
71  // Button
72  $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
73  }
74 }
const DISPLAY_ORDER
Definition: en_US.php:217
setExtra($extra)
Definition: Form.php:374
const A_SUBMIT
Definition: en_US.php:128
const E_YOU_NEED_A_POSITIVE_INTEGER
Definition: en_US.php:385
const A_ADD
Definition: en_US.php:77
const F_FILE_EXISTS_IN
Definition: en_US.php:411
$weight
Definition: admin_menu.php:38
addElement(Element $formElement, $required=false)
Definition: Form.php:206
$_SERVER['REQUEST_URI']
__construct(AvatarsAvatar $obj)
Definition: avatar.php:25
getVar($key, $format= 's')
$xoops_upload_url
Definition: misc.php:30
static get($name)
const DISPLAY_THIS_ITEM
Definition: en_US.php:221
const A_UPLOAD
Definition: en_US.php:133
const A_EDIT
Definition: en_US.php:93