1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\XoopsObject;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24:
25: class UserrankRanksForm extends Xoops\Form\ThemeForm
26: {
27: 28: 29:
30: public function __construct(XoopsObject $obj)
31: {
32: $xoops = \Xoops::getInstance();
33: if ($obj->isNew()) {
34: $blank_img = 'blank.gif';
35: } else {
36: $blank_img = str_replace('ranks/', '', $obj->getVar('rank_image', 'e'));
37: }
38:
39: $title = $obj->isNew() ? sprintf(_AM_USERRANK_ADD) : sprintf(_AM_USERRANK_EDIT);
40:
41: parent::__construct($title, 'form', 'userrank.php', 'post', true);
42: $this->setExtra('enctype="multipart/form-data"');
43:
44: $this->addElement(new Xoops\Form\Text(_AM_USERRANK_TITLE, 'rank_title', 4, 50, $obj->getVar('rank_title')), true);
45: $min = new Xoops\Form\Text(_AM_USERRANK_MINPOST, 'rank_min', 1, 10, $obj->getVar('rank_min'));
46: $min->setPattern('^\d+$', _AM_USERRANK_ERROR_POST);
47: $this->addElement($min);
48: $max = new Xoops\Form\Text(_AM_USERRANK_MAXPOST, 'rank_max', 1, 10, $obj->getVar('rank_max'));
49: $max->setPattern('^\d+$', _AM_USERRANK_ERROR_POST);
50: $this->addElement($max);
51:
52: $imgtray_img = new Xoops\Form\ElementTray(_AM_USERRANK_IMAGE, '<br />');
53: $imgpath_img = sprintf(_AM_USERRANK_IMAGE_PATH, $xoops->path('uploads/ranks/'));
54: $imageselect_img = new Xoops\Form\Select($imgpath_img, 'rank_image', $blank_img);
55: $imageselect_img->addOption($blank_img, $blank_img);
56: \Xoops\Core\Lists\ImageFile::setOptionsArray($imageselect_img, $xoops->path('uploads/ranks'));
57: $imageselect_img->setExtra("onchange='showImgSelected(\"xo-ranks-img\", \"rank_image\", \"ranks\", \"\", \"" . \XoopsBaseConfig::get('uploads-url') . "\")'");
58: $imgtray_img->addElement($imageselect_img, false);
59: $imgtray_img->addElement(new Xoops\Form\Label('', "<br /><img src='" . \XoopsBaseConfig::get('uploads-url') . "/ranks/" . $blank_img . "' name='image_img' id='xo-ranks-img' alt='' />"));
60:
61: $fileseltray_img = new Xoops\Form\ElementTray('<br />', '<br /><br />');
62: $fileseltray_img->addElement(new Xoops\Form\File(_AM_USERRANK_UPLOAD, 'rank_image'), false);
63: $fileseltray_img->addElement(new Xoops\Form\Label(''), false);
64: $imgtray_img->addElement($fileseltray_img);
65: $this->addElement($imgtray_img);
66:
67: if (!$obj->isNew()) {
68: $rank_special = $obj->getVar('rank_special');
69: } else {
70: $rank_special = 0;
71: }
72:
73: $special_tray = new Xoops\Form\ElementTray(_AM_USERRANK_SPECIAL, '<br />');
74: $special_tray->setDescription(_AM_USERRANK_SPECIAL_CAN);
75: $special_tray->addElement(new Xoops\Form\RadioYesNo('', 'rank_special', $rank_special));
76: $this->addElement($special_tray);
77: if (!$obj->isNew()) {
78: $this->addElement(new Xoops\Form\Hidden('rank_id', $obj->getVar('rank_id')));
79: }
80: $this->addElement(new Xoops\Form\Hidden('op', 'userrank_save'));
81: $this->addElement(new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit'));
82: }
83: }
84: