1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: class cApiClickableAction extends cApiAction {
30:
31: 32: 33: 34: 35:
36: private $_helpText;
37:
38: 39: 40: 41: 42:
43: protected $_link;
44:
45: 46: 47: 48: 49:
50: private $_img;
51:
52: 53: 54: 55:
56: const QUESTIONACTION_PROMPT = 'prompt';
57:
58: 59: 60: 61:
62: const QUESTIONACTION_YESNO = 'yesno';
63:
64: 65:
66: public function __construct() {
67: global $area;
68:
69: parent::__construct();
70:
71: $this->_area = $area;
72: $this->_frame = 4;
73: $this->_target = "right_bottom";
74:
75: $this->_link = new cHTMLLink();
76: $this->_img = new cHTMLImage();
77: $this->_img->setBorder(0);
78: $this->_img->setStyle("padding-left: 1px; padding-right: 1px;");
79:
80: $this->_parameters = array();
81:
82: $this->setEnabled();
83: }
84:
85: 86: 87: 88: 89: 90: 91:
92: public function setIcon($icon) {
93: $this->_img->setSrc($icon);
94: }
95:
96: 97: 98: 99:
100: public function getIcon() {
101: return $this->_img;
102: }
103:
104: 105: 106: 107: 108: 109: 110: 111:
112: public function setNamedAction($actionName) {
113: if ($this->loadBy("name", $actionName) !== false) {
114: $a = new cApiArea();
115: $a->loadByPrimaryKey($this->get("idarea"));
116:
117: $this->_namedAction = $actionName;
118: $this->_area = $a->get("name");
119:
120: $this->_parameters = array();
121: $this->_wantParameters = array();
122: }
123: }
124:
125: 126:
127: public function setDisabled() {
128: $this->_enabled = false;
129: $this->_onDisable();
130: }
131:
132: 133:
134: public function setEnabled() {
135: $this->_enabled = true;
136: $this->_onEnable();
137: }
138:
139: 140:
141: protected function _onDisable() {
142: }
143:
144: 145:
146: protected function _onEnable() {
147: }
148:
149: 150: 151:
152: public function changeArea($sArea) {
153: $this->_area = $sArea;
154: }
155:
156: 157: 158: 159:
160: public function wantParameter($parameter) {
161: $this->_wantParameters[] = $parameter;
162:
163: $this->_wantParameters = array_unique($this->_wantParameters);
164: }
165:
166: 167: 168: 169: 170: 171:
172: public function setHelpText($helptext) {
173: $this->_helpText = $helptext;
174: }
175:
176: 177:
178: public function getHelpText() {
179: return $this->_helpText;
180: }
181:
182: 183: 184: 185: 186:
187: public function setParameter($name, $value) {
188: $this->_parameters[$name] = $value;
189: }
190:
191: 192: 193: 194: 195:
196: public function process($parameters) {
197: echo "Process should be overridden";
198: return false;
199: }
200:
201: 202: 203: 204:
205: public function render() {
206: $this->_img->setAlt($this->_helpText);
207:
208: foreach ($this->_parameters as $name => $value) {
209: $this->_link->setCustom($name, $value);
210: }
211:
212: $this->_link->setAlt($this->_helpText);
213: $this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
214: $this->_link->setTargetFrame($this->_target);
215: $this->_link->setContent($this->_img);
216:
217: if ($this->_enabled == true) {
218: return ($this->_link->render());
219: } else {
220: return ($this->_img->render());
221: }
222: }
223:
224: 225: 226: 227:
228: public function renderText() {
229: foreach ($this->_parameters as $name => $value) {
230: $this->_link->setCustom($name, $value);
231: }
232:
233: $this->_link->setAlt($this->_helpText);
234: $this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
235: $this->_link->setTargetFrame($this->_target);
236: $this->_link->setContent($this->_helpText);
237:
238: if ($this->_enabled == true) {
239: return ($this->_link->render());
240: } else {
241: return ($this->_helpText);
242: }
243: }
244: }
245:
246: 247: 248: 249: 250: 251:
252: class cApiClickableQuestionAction extends cApiClickableAction {
253:
254: 255:
256: public function __construct() {
257: parent::__construct();
258: }
259:
260: 261: 262: 263:
264: public function setQuestionMode($mode) {
265: $this->_mode = $mode;
266: }
267:
268: 269: 270: 271:
272: public function setQuestion($question) {
273: $this->_question = $question;
274: }
275:
276: 277: 278: 279:
280: public function setResultVar($var) {
281: $this->_resultVar = $var;
282: }
283:
284: 285: 286: 287: 288:
289: public function render() {
290: switch ($this->_mode) {
291: case self::QUESTIONACTION_PROMPT:
292: $this->_link->attachEventDefinition("_" . get_class($this) . rand(), "onclick", 'var answer = prompt("' . conHtmlSpecialChars($this->_question) . '");if (answer == null) {return false;} else { this.href = this.href + "&' . $this->_resultVar . '="+answer; return true;}');
293: break;
294: case self::QUESTIONACTION_YESNO:
295: default:
296: $this->_link->attachEventDefinition("_" . get_class($this) . rand(), "onclick", 'var answer = confirm("' . conHtmlSpecialChars($this->_question) . '");if (answer == false) {return false;} else { return true;}');
297: break;
298: }
299:
300: return parent::render();
301: }
302: }
303: