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