1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: class cApiClickableAction extends cApiAction {
30:
31: 32: 33:
34:
35: 36: 37: 38: 39:
40: private $_helpText;
41:
42: 43: 44: 45: 46:
47: protected $_link;
48:
49: 50: 51: 52: 53:
54: private $_img;
55:
56: const QUESTIONACTION_PROMPT = 'prompt';
57:
58: const QUESTIONACTION_YESNO = 'yesno';
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:
79: 80: 81: 82: 83: 84: 85:
86: public function setIcon($icon) {
87: $this->_img->setSrc($icon);
88: }
89:
90: public function getIcon() {
91: return $this->_img;
92: }
93:
94: 95: 96: 97: 98: 99: 100: 101:
102: public function setNamedAction($actionName) {
103: if ($this->loadBy("name", $actionName) !== false) {
104: $a = new cApiArea();
105: $a->loadByPrimaryKey($this->get("idarea"));
106:
107: $this->_namedAction = $actionName;
108: $this->_area = $a->get("name");
109:
110: $this->_parameters = array();
111: $this->_wantParameters = array();
112: }
113: }
114:
115: public function setDisabled() {
116: $this->_enabled = false;
117: $this->_onDisable();
118: }
119:
120: public function setEnabled() {
121: $this->_enabled = true;
122: $this->_onEnable();
123: }
124:
125: protected function _onDisable() {
126: }
127:
128: protected function _onEnable() {
129: }
130:
131: 132: 133:
134: public function changeArea($sArea) {
135: $this->_area = $sArea;
136: }
137:
138: public function wantParameter($parameter) {
139: $this->_wantParameters[] = $parameter;
140:
141: $this->_wantParameters = array_unique($this->_wantParameters);
142: }
143:
144: 145: 146: 147: 148: 149:
150: public function setHelpText($helptext) {
151: $this->_helpText = $helptext;
152: }
153:
154: public function getHelpText() {
155: return $this->_helpText;
156: }
157:
158: public function setParameter($name, $value) {
159: $this->_parameters[$name] = $value;
160: }
161:
162: public function process($parameters) {
163: echo "Process should be overridden";
164: return false;
165: }
166:
167: public function render() {
168: $this->_img->setAlt($this->_helpText);
169:
170: foreach ($this->_parameters as $name => $value) {
171: $this->_link->setCustom($name, $value);
172: }
173:
174: $this->_link->setAlt($this->_helpText);
175: $this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
176: $this->_link->setTargetFrame($this->_target);
177: $this->_link->setContent($this->_img);
178:
179: if ($this->_enabled == true) {
180: return ($this->_link->render());
181: } else {
182: return ($this->_img->render());
183: }
184: }
185:
186: public function renderText() {
187: foreach ($this->_parameters as $name => $value) {
188: $this->_link->setCustom($name, $value);
189: }
190:
191: $this->_link->setAlt($this->_helpText);
192: $this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
193: $this->_link->setTargetFrame($this->_target);
194: $this->_link->setContent($this->_helpText);
195:
196: if ($this->_enabled == true) {
197: return ($this->_link->render());
198: } else {
199: return ($this->_helpText);
200: }
201: }
202:
203: }
204:
205: 206: 207: 208: 209: 210:
211: class cApiClickableQuestionAction extends cApiClickableAction {
212:
213: public function __construct() {
214: parent::__construct();
215: }
216:
217: public function setQuestionMode($mode) {
218: $this->_mode = $mode;
219: }
220:
221: public function setQuestion($question) {
222: $this->_question = $question;
223: }
224:
225: public function setResultVar($var) {
226: $this->_resultVar = $var;
227: }
228:
229: public function render() {
230: switch ($this->_mode) {
231: case self::QUESTIONACTION_PROMPT:
232: $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;}');
233: break;
234: case self::QUESTIONACTION_YESNO:
235: default:
236: $this->_link->attachEventDefinition("_" . get_class($this) . rand(), "onclick", 'var answer = confirm("' . conHtmlSpecialChars($this->_question) . '");if (answer == false) {return false;} else { return true;}');
237: break;
238: }
239:
240: return parent::render();
241: }
242:
243: }
244: