1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_ROOT_PATH . "/core/XCube_ActionForm.class.php";
14: require_once XOOPS_MODULE_PATH . "/legacy/class/Legacy_Validator.class.php";
15:
16: class Legacy_BlockEditForm extends XCube_ActionForm
17: {
18: function getTokenName()
19: {
20: return "module.legacy.BlockEditForm.TOKEN" . $this->get('bid');
21: }
22:
23: function prepare()
24: {
25:
26:
27:
28: $this->mFormProperties['bid'] =new XCube_IntProperty('bid');
29: $this->mFormProperties['options'] =new XCube_StringArrayProperty('options');
30: $this->mFormProperties['title'] =new XCube_StringProperty('title');
31: $this->mFormProperties['side'] =new XCube_IntProperty('side');
32: $this->mFormProperties['weight'] =new XCube_IntProperty('weight');
33: $this->mFormProperties['bcachetime'] =new XCube_IntProperty('bcachetime');
34: $this->mFormProperties['bmodule'] =new XCube_IntArrayProperty('bmodule');
35: $this->mFormProperties['groupid'] =new XCube_IntArrayProperty('groupid');
36:
37:
38:
39:
40: $this->mFieldProperties['bid'] =new XCube_FieldProperty($this);
41: $this->mFieldProperties['bid']->setDependsByArray(array('required'));
42: $this->mFieldProperties['bid']->addMessage('required', _MD_LEGACY_ERROR_REQUIRED, _AD_LEGACY_LANG_BID);
43:
44: $this->mFieldProperties['title'] =new XCube_FieldProperty($this);
45: $this->mFieldProperties['title']->setDependsByArray(array('required','maxlength'));
46: $this->mFieldProperties['title']->addMessage('required', _MD_LEGACY_ERROR_REQUIRED, _AD_LEGACY_LANG_TITLE, '255');
47: $this->mFieldProperties['title']->addMessage('maxlength', _MD_LEGACY_ERROR_MAXLENGTH, _AD_LEGACY_LANG_TITLE, '255');
48: $this->mFieldProperties['title']->addVar('maxlength', '255');
49:
50: $this->mFieldProperties['side'] =new XCube_FieldProperty($this);
51: $this->mFieldProperties['side']->setDependsByArray(array('required', 'objectExist'));
52: $this->mFieldProperties['side']->addMessage('required', _MD_LEGACY_ERROR_REQUIRED, _AD_LEGACY_LANG_SIDE);
53: $this->mFieldProperties['side']->addMessage('objectExist', _AD_LEGACY_ERROR_OBJECTEXIST, _AD_LEGACY_LANG_SIDE);
54: $this->mFieldProperties['side']->addVar('handler', 'columnside');
55: $this->mFieldProperties['side']->addVar('module', 'legacy');
56:
57: $this->mFieldProperties['weight'] =new XCube_FieldProperty($this);
58: $this->mFieldProperties['weight']->setDependsByArray(array('required', 'intRange'));
59: $this->mFieldProperties['weight']->addMessage('required', _MD_LEGACY_ERROR_REQUIRED, _AD_LEGACY_LANG_WEIGHT);
60: $this->mFieldProperties['weight']->addMessage('intRange', _AD_LEGACY_ERROR_INTRANGE, _AD_LEGACY_LANG_WEIGHT);
61: $this->mFieldProperties['weight']->addVar('min', '0');
62: $this->mFieldProperties['weight']->addVar('max', '65535');
63:
64: $this->mFieldProperties['bcachetime'] =new XCube_FieldProperty($this);
65: $this->mFieldProperties['bcachetime']->setDependsByArray(array('required', 'objectExist'));
66: $this->mFieldProperties['bcachetime']->addMessage('required', _MD_LEGACY_ERROR_REQUIRED, _AD_LEGACY_LANG_BCACHETIME);
67: $this->mFieldProperties['bcachetime']->addMessage('objectExist', _AD_LEGACY_ERROR_OBJECTEXIST, _AD_LEGACY_LANG_BCACHETIME);
68: $this->mFieldProperties['bcachetime']->addVar('handler', 'cachetime');
69:
70: $this->mFieldProperties['groupid'] =new XCube_FieldProperty($this);
71: $this->mFieldProperties['groupid']->setDependsByArray(array('objectExist'));
72: $this->mFieldProperties['groupid']->addMessage('objectExist', _AD_LEGACY_ERROR_OBJECTEXIST, _AD_LEGACY_LANG_GROUPID);
73: $this->mFieldProperties['groupid']->addVar('handler', 'group');
74: }
75:
76: function validateBmodule()
77: {
78: $bmodule = $this->get('bmodule');
79: if (!(count($bmodule))) {
80: $this->addErrorMessage(_AD_LEGACY_ERROR_BMODULE);
81: }
82: else {
83: $handler =& xoops_gethandler('module');
84: foreach ($this->get('bmodule') as $mid) {
85: $module =& $handler->get($mid);
86: if ($mid != -1 && $mid != 0 && !is_object($module)) {
87: $this->addErrorMessage(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_OBJECTEXIST, _AD_LEGACY_LANG_BMODULE));
88: }
89: }
90: }
91: }
92:
93: function validateGroupid()
94: {
95: $groupid = $this->get('groupid');
96: if (!(count($groupid))) {
97: $this->addErrorMessage(_AD_LEGACY_ERROR_GROUPID);
98: }
99: }
100:
101: function load(&$obj)
102: {
103: $this->set('bid', $obj->get('bid'));
104: $this->set('title', $obj->get('title'));
105: $this->set('side', $obj->get('side'));
106: $this->set('weight', $obj->get('weight'));
107: $this->set('bcachetime', $obj->get('bcachetime'));
108:
109: $i = 0;
110: foreach ($obj->mBmodule as $module) {
111: if (is_object($module)) {
112: $this->set('bmodule', $i++, $module->get('module_id'));
113: }
114: }
115:
116: $i = 0;
117: foreach ($obj->mGroup as $group) {
118: if (is_object($group)) {
119: $this->set('groupid', $i++, $group->get('groupid'));
120: }
121: }
122: }
123:
124: function update(&$obj)
125: {
126: $obj->set('bid', $this->get('bid'));
127: $obj->set('title', $this->get('title'));
128: $obj->set('side', $this->get('side'));
129: $obj->set('weight', $this->get('weight'));
130: $obj->set('bcachetime', $this->get('bcachetime'));
131:
132: $obj->set('last_modified', time());
133:
134:
135:
136:
137: $optionArr = $this->get('options');
138: for ($i = 0; $i < count($optionArr); $i++) {
139: if (is_array($optionArr[$i])) {
140: $optionArr[$i] = implode(',', $optionArr[$i]);
141: }
142: }
143:
144: $obj->set('options', implode('|', $optionArr));
145:
146: $obj->mBmodule = array();
147: $handler =& xoops_getmodulehandler('block_module_link', 'legacy');
148: foreach ($this->get('bmodule') as $mid) {
149: $t_obj =& $handler->create();
150: $t_obj->set('block_id', $this->get('bid'));
151: $t_obj->set('module_id', $mid);
152: $obj->mBmodule[] =& $t_obj;
153: unset($t_obj);
154: }
155:
156: $obj->mGroup = array();
157: $handler =& xoops_gethandler('group');
158: foreach ($this->get('groupid') as $groupid) {
159: $obj->mGroup[] =& $handler->get($groupid);
160: }
161: }
162: }
163:
164: ?>
165: