1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22:
23: class AvatarsAvatarForm extends Xoops\Form\ThemeForm
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:
33:
34: $title = $obj->isNew() ? XoopsLocale::A_ADD : XoopsLocale::A_EDIT;
35:
36: $action = $_SERVER['REQUEST_URI'];
37: parent::__construct($title, 'avatar_form', $action, "post", true);
38: $this->setExtra('enctype="multipart/form-data"');
39:
40: $this->addElement(new Xoops\Form\Text(XoopsLocale::NAME, 'avatar_name', 5, 255, $obj->getVar('avatar_name', 'e')), true);
41:
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: $imageselect_img->addOption($blank_img, $blank_img);
46: \Xoops\Core\Lists\ImageFile::setOptionsArray($imageselect_img, $avatars_path);
47: $xoops_upload_url = \XoopsBaseConfig::get('uploads-url');
48: $imageselect_img->setExtra("onchange='showImgSelected(\"xo-avatar-img\", \"avatar_file\", \"avatars\", \"\", \"" . $xoops_upload_url . "\")'");
49: $imgtray_img->addElement($imageselect_img, false);
50: $imgtray_img->addElement(new Xoops\Form\Label('', "<br /><img src='" . $xoops_upload_url . "/avatars/" . $blank_img . "' name='image_img' id='xo-avatar-img' alt='' />"));
51: $fileseltray_img = new Xoops\Form\ElementTray('<br />', '<br /><br />');
52: $fileseltray_img->addElement(new Xoops\Form\File(XoopsLocale::A_UPLOAD, 'avatar_file'), false);
53:
54: $imgtray_img->addElement($fileseltray_img);
55: $this->addElement($imgtray_img);
56:
57: $weight = new Xoops\Form\Text(XoopsLocale::DISPLAY_ORDER, 'avatar_weight', 1, 4, $obj->getVar('avatar_weight', 'e'), '');
58: $weight->setPattern('^\d+$', XoopsLocale::E_YOU_NEED_A_POSITIVE_INTEGER);
59: $this->addElement($weight, true);
60:
61: $this->addElement(new Xoops\Form\RadioYesNo(XoopsLocale::DISPLAY_THIS_ITEM, 'avatar_display', $obj->getVar('avatar_display', 'e'), XoopsLocale::YES, XoopsLocale::NO));
62:
63: if ($obj->isNew()) {
64: $this->addElement(new Xoops\Form\Hidden('avatar_type', 's'));
65: }
66: $this->addElement(new Xoops\Form\Hidden('op', 'save'));
67: $this->addElement(new Xoops\Form\Hidden('avatar_id', $obj->getVar('avatar_id', 'e')));
68:
69: $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
70: }
71: }
72: