1: <?php
2: /**
3: * User ranks class manager
4: *
5: * You may not change or alter any portion of this comment or credits
6: * of supporting developers from this source code or any supporting source code
7: * which is considered copyrighted (c) material of the original comment or credit authors.
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
13: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14: * @author Gregory Mage (AKA Mage)
15: * @package system
16: */
17:
18: // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
19:
20: /**
21: * System User ranks
22: *
23: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
24: * @package system
25: */
26: class SystemUserrank extends XoopsObject
27: {
28: //PHP 8.2 Dynamic properties deprecated
29: public $rank_id;
30: public $rank_title;
31: public $rank_min;
32: public $rank_max;
33: public $rank_special;
34: public $rank_image;
35:
36: /**
37: *
38: */
39: public function __construct()
40: {
41: parent::__construct();
42: $this->initVar('rank_id', XOBJ_DTYPE_INT, null, false, 5);
43: $this->initVar('rank_title', XOBJ_DTYPE_TXTBOX, null, false);
44: $this->initVar('rank_min', XOBJ_DTYPE_INT, null, false, 8);
45: $this->initVar('rank_max', XOBJ_DTYPE_INT, null, false, 8);
46: $this->initVar('rank_special', XOBJ_DTYPE_INT, null, false, 1);
47: $this->initVar('rank_image', XOBJ_DTYPE_TXTBOX, null, false);
48: }
49:
50: /**
51: * @param bool $action
52: *
53: * @return XoopsThemeForm
54: */
55: public function getForm($action = false)
56: {
57: if ($this->isNew()) {
58: $blank_img = 'blank.gif';
59: } else {
60: $blank_img = str_replace('ranks/', '', $this->getVar('rank_image', 'e'));
61: }
62: if ($action === false) {
63: $action = $_SERVER['REQUEST_URI'];
64: }
65:
66: $title = $this->isNew() ? sprintf(_AM_SYSTEM_USERRANK_ADD) : sprintf(_AM_SYSTEM_USERRANK_EDIT);
67:
68: $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
69: $form->setExtra('enctype="multipart/form-data"');
70:
71: $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_TITLE, 'rank_title', 50, 50, $this->getVar('rank_title'), true));
72: $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_MINPOST, 'rank_min', 10, 10, $this->getVar('rank_min')));
73: $form->addElement(new XoopsFormText(_AM_SYSTEM_USERRANK_MAXPOST, 'rank_max', 10, 10, $this->getVar('rank_max')));
74:
75: $imgtray_img = new XoopsFormElementTray(_AM_SYSTEM_USERRANK_IMAGE, '<br>');
76: $imgpath_img = sprintf(_AM_SYSTEM_USERRANK_IMAGE_PATH, XOOPS_UPLOAD_PATH . '/ranks/');
77: $imageselect_img = new XoopsFormSelect($imgpath_img, 'rank_image', $blank_img);
78: $image_array_img = XoopsLists::getImgListAsArray(XOOPS_UPLOAD_PATH . '/ranks');
79: $imageselect_img->addOption("$blank_img", $blank_img);
80: foreach ($image_array_img as $image_img) {
81: $imageselect_img->addOption("$image_img", $image_img);
82: }
83: $imageselect_img->setExtra("onchange='showImgSelected(\"xo-ranks-img\", \"rank_image\", \"ranks\", \"\", \"" . XOOPS_UPLOAD_URL . "\")'");
84: $imgtray_img->addElement($imageselect_img, false);
85: $imgtray_img->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/ranks/' . $blank_img . "' name='image_img' id='xo-ranks-img' alt='' />"));
86:
87: $fileseltray_img = new XoopsFormElementTray('<br>', '<br><br>');
88: $fileseltray_img->addElement(new XoopsFormFile(_AM_SYSTEM_USERRANK_UPLOAD, 'rank_image', 500000), false);
89: $fileseltray_img->addElement(new XoopsFormLabel(''), false);
90: $imgtray_img->addElement($fileseltray_img);
91: $form->addElement($imgtray_img);
92:
93: $rank_special = 0;
94: if (!$this->isNew()) {
95: $rank_special = $this->getVar('rank_special');
96: }
97:
98: $special_tray = new XoopsFormElementTray(_AM_SYSTEM_USERRANK_SPECIAL, '<br>');
99: $special_tray->setDescription(_AM_SYSTEM_USERRANK_SPECIAL_CAN);
100: $special_tray->addElement(new XoopsFormRadioYN('', 'rank_special', $rank_special));
101: $form->addElement($special_tray);
102: if (!$this->isNew()) {
103: $form->addElement(new XoopsFormHidden('rank_id', $this->getVar('rank_id')));
104: }
105: $form->addElement(new XoopsFormHidden('op', 'userrank_save'));
106: $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
107:
108: return $form;
109: }
110: }
111:
112: /**
113: * System user ranks handler class. (Singelton)
114: *
115: * This class is responsible for providing data access mechanisms to the data source
116: * of XOOPS block class objects.
117: *
118: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
119: * @package system
120: * @subpackage avatar
121: */
122: class SystemuserrankHandler extends XoopsPersistableObjectHandler
123: {
124: /**
125: * @param null|XoopsDatabase $db
126: */
127: public function __construct(XoopsDatabase $db)
128: {
129: parent::__construct($db, 'ranks', 'SystemUserrank', 'rank_id', 'rank_title');
130: }
131: }
132: