1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19:
20: class ImagesImageForm extends Xoops\Form\ThemeForm
21: {
22: 23: 24:
25: public function __construct(ImagesImage $obj)
26: {
27: $xoops = Xoops::getInstance();
28: $helper = Xoops\Module\Helper::getHelper('images');
29:
30: $groups = $xoops->getUserGroups();
31:
32: if ($obj->isNew()) {
33: $title = _AM_IMAGES_IMG_ADD;
34: } else {
35: $title = _AM_IMAGES_IMG_EDIT;
36: }
37:
38: parent::__construct('', 'image', $xoops->getEnv('PHP_SELF'), 'post', true);
39: $this->setExtra('enctype="multipart/form-data"');
40:
41: $tabTray = new Xoops\Form\TabTray('', 'uniqueid');
42: $tab1 = new Xoops\Form\Tab($title, 'tabid-1');
43:
44: $tab1->addElement(new Xoops\Form\Text(_AM_IMAGES_NAME, 'image_nicename', 50, 255, $obj->getVar('image_nicename')), true);
45:
46: if ($obj->isNew()) {
47: $categories = $helper->getHandlerCategories()->getListByPermission($groups, 'imgcat_write');
48: $select = new Xoops\Form\Select(_AM_IMAGES_CAT_SELECT, 'imgcat_id', $obj->getVar('imgcat_id'));
49: $select->addOption('', _AM_IMAGES_CAT_SELECT);
50: $select->addOptionArray($categories);
51: $tab1->addElement($select, true);
52: } else {
53: $tab1->addElement(new Xoops\Form\Label(_AM_IMAGES_CAT_SELECT, '<span class="red bold">' . $helper->getHandlerCategories()->get($obj->getVar('imgcat_id'))->getVar('imgcat_name') . '</span>'));
54: $this->addElement(new Xoops\Form\Hidden('imgcat_id', $obj->getVar('imgcat_id')));
55: }
56:
57:
58: $category = $helper->getHandlerCategories()->get($obj->getVar('imgcat_id'));
59: $upload_msg[] = _AM_IMAGES_CAT_SIZE . ' : ' . $category->getVar('imgcat_maxsize');
60: $upload_msg[] = _AM_IMAGES_CAT_WIDTH . ' : ' . $category->getVar('imgcat_maxwidth');
61: $upload_msg[] = _AM_IMAGES_CAT_HEIGHT . ' : ' . $category->getVar('imgcat_maxheight');
62:
63: $image_tray = new Xoops\Form\File(_AM_IMAGES_IMG_FILE, 'image_file');
64: $image_tray->setDescription(self::message($upload_msg, ''));
65: $tab1->addElement($image_tray);
66:
67: $tab1->addElement(new Xoops\Form\Text(_AM_IMAGES_WEIGHT, 'image_weight', 1, 4, $obj->getVar('image_weight')));
68:
69: $tab1->addElement(new Xoops\Form\RadioYesNo(_AM_IMAGES_DISPLAY, 'image_display', $obj->getVar('image_display')));
70:
71: $tabTray->addElement($tab1);
72: $this->addElement($tabTray);
73:
74: $this->addElement(new Xoops\Form\Hidden('image_name', $obj->getVar('image_name')));
75: $this->addElement(new Xoops\Form\Hidden('image_id', $obj->getVar('image_id')));
76:
77: 78: 79:
80: $buttonTray = new Xoops\Form\ElementTray('', '');
81: $buttonTray->addElement(new Xoops\Form\Hidden('op', 'save'));
82:
83: $buttonSubmit = new Xoops\Form\Button('', 'submit', XoopsLocale::A_SUBMIT, 'submit');
84: $buttonSubmit->setClass('btn btn-success');
85: $buttonTray->addElement($buttonSubmit);
86:
87: $buttonReset = new Xoops\Form\Button('', 'reset', XoopsLocale::A_RESET, 'reset');
88: $buttonReset->setClass('btn btn-warning');
89: $buttonTray->addElement($buttonReset);
90:
91: $buttonCancel = new Xoops\Form\Button('', 'cancel', XoopsLocale::A_CANCEL, 'button');
92: $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");
93: $buttonCancel->setClass('btn btn-danger');
94: $buttonTray->addElement($buttonCancel);
95:
96: $this->addElement($buttonTray);
97: }
98:
99: 100: 101:
102: public function message($msg, $title = '', $class = 'errorMsg')
103: {
104: $ret = "<div class='" . $class . "'>";
105: if ($title != '') {
106: $ret .= "<strong>" . $title . "</strong>";
107: }
108: if (is_array($msg) || is_object($msg)) {
109: $ret .= implode('<br />', $msg);
110: } else {
111: $ret .= $msg;
112: }
113: $ret .= "</div>";
114: return $ret;
115: }
116: }
117: