Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • ArticleForumRightBottom
  • cApiClickableAction
  • cApiClickableQuestionAction
  • cGuiBackendHelpbox
  • cGuiFileOverview
  • cGuiFoldingRow
  • cGuiList
  • cGuiMenu
  • cGuiNavigation
  • cGuiNotification
  • cGuiObjectPager
  • cGuiPage
  • cGuiScrollList
  • cGuiSourceEditor
  • cGuiTableForm
  • cGuiTree
  • cPager
  • cTemplate
  • cTree
  • cTreeItem
  • NoteLink
  • NoteList
  • NoteListItem
  • NoteView
  • TODOBackendList
  • TODOLink
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the table form GUI class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GUI
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Mischa Holz
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Table form GUI class.
 20:  *
 21:  * @package Core
 22:  * @subpackage GUI
 23:  */
 24: class cGuiTableForm {
 25: 
 26:     /**
 27:      *
 28:      * @var array
 29:      */
 30:     public $items = array();
 31: 
 32:     /**
 33:      *
 34:      * @var array
 35:      */
 36:     public $captions = array();
 37: 
 38:     /**
 39:      *
 40:      * @var int
 41:      */
 42:     public $id = 0;
 43: 
 44:     /**
 45:      *
 46:      * @var array
 47:      */
 48:     public $rownames = array();
 49: 
 50:     /**
 51:      *
 52:      * @var  array
 53:      */
 54:     public $itemType = array();
 55: 
 56:     /**
 57:      *
 58:      * @var string
 59:      */
 60:     public $formname;
 61: 
 62:     /**
 63:      *
 64:      * @var string
 65:      */
 66:     public $formmethod;
 67: 
 68:     /**
 69:      *
 70:      * @var string
 71:      */
 72:     public $formaction;
 73: 
 74:     /**
 75:      *
 76:      * @var array
 77:      */
 78:     public $formvars = array();
 79: 
 80:     /**
 81:      *
 82:      * @var string
 83:      */
 84:     public $tableid = "";
 85: 
 86:     /**
 87:      *
 88:      * @var string
 89:      */
 90:     public $header;
 91: 
 92:     /**
 93:      *
 94:      * @var string
 95:      */
 96:     public $cancelLink;
 97: 
 98:     /**
 99:      *
100:      * @var string
101:      */
102:     public $submitjs;
103: 
104:     /**
105:      *
106:      * @var array
107:      */
108:     public $custom = array();
109: 
110:     /**
111:      * Creates a new cGuiTableForm with given name, action & method of form.
112:      *
113:      * @param string $name of form
114:      * @param string $action of form defaults to 'main.php'
115:      * @param string $method of form defaults to 'post'
116:      */
117:     public function __construct($name, $action = 'main.php', $method = 'post') {
118: 
119:         // action defaults to 'main.php'
120:         if ($action == '') {
121:             $action = 'main.php';
122:         }
123: 
124:         // set name, action & method
125:         $this->formname = $name;
126:         $this->formaction = $action;
127:         $this->formmethod = $method;
128: 
129:         $this->setActionButton('submit', cRegistry::getBackendUrl() . 'images/but_ok.gif', i18n('Save changes'), 's');
130:     }
131: 
132:     /**
133:      *
134:      * @param string $name
135:      * @param mixed $value
136:      */
137:     public function setVar($name, $value) {
138:         $this->formvars[$name] = $value;
139:     }
140: 
141:     /**
142:      * Adds a new caption, item and row name.
143:      *
144:      * @param string $caption
145:      * @param array|object|string $item
146:      * @param string $rowname
147:      */
148:     public function add($caption, $item, $rowname = "") {
149: 
150:         // handle item as array of items
151:         if (is_array($item)) {
152:             $temp = "";
153:             foreach ($item as $value) {
154:                 if (is_object($value) && method_exists($value, "render")) {
155:                     $temp .= $value->render();
156:                 } else {
157:                     $temp .= $value;
158:                 }
159:             }
160:             $item = $temp;
161:         }
162: 
163:         // handle item as object
164:         if (is_object($item) && method_exists($item, "render")) {
165:             $item = $item->render();
166:         }
167: 
168:         // increase ID
169:         $this->id++;
170: 
171:         // set defaults
172:         if ($caption == "") {
173:             $caption = "&nbsp;";
174:         }
175:         if ($item == "") {
176:             $item = "&nbsp;";
177:         }
178:         if ($rowname == "") {
179:             $rowname = $this->id;
180:         }
181: 
182:         $this->captions[$this->id] = $caption;
183:         $this->items[$this->id] = $item;
184:         $this->rownames[$this->id] = $rowname;
185:     }
186: 
187:     /**
188:      * Sets an URL as HREF of a cancel icon.
189:      *
190:      * @param string $link
191:      */
192:     public function addCancel($link) {
193:         $this->cancelLink = $link;
194:     }
195: 
196:     /**
197:      * Sets the header. The header is *set* not *added*!
198:      *
199:      * @param string $header
200:      * @todo rename addHeader() to setHeader()
201:      */
202:     public function addHeader($header) {
203:         $this->header = $header;
204:     }
205: 
206:     /**
207:      *
208:      * @param string $header
209:      */
210:     public function addSubHeader($header) {
211:         $this->id++;
212:         $this->items[$this->id] = '';
213:         $this->captions[$this->id] = $header;
214:         $this->itemType[$this->id] = 'subheader';
215:     }
216: 
217:     /**
218:      *
219:      * @param string $js
220:      */
221:     public function setSubmitJS($js) {
222:         $this->submitjs = $js;
223:     }
224: 
225:     /**
226:      *
227:      * @param unknown_type $id
228:      * @param unknown_type $event
229:      */
230:     public function setActionEvent($id, $event) {
231:         $this->custom[$id]["event"] = $event;
232:     }
233: 
234:     /**
235:      *
236:      * @param unknown_type $id
237:      * @param unknown_type $image
238:      * @param unknown_type $description
239:      * @param unknown_type $accesskey
240:      * @param unknown_type $action
241:      */
242:     public function setActionButton($id, $image, $description = "", $accesskey = false, $action = false) {
243:         $this->custom[$id]["image"] = $image;
244:         $this->custom[$id]["type"] = "actionsetter";
245:         $this->custom[$id]["action"] = $action;
246:         $this->custom[$id]["description"] = $description;
247:         $this->custom[$id]["accesskey"] = $accesskey;
248:         $this->custom[$id]["event"] = "";
249:     }
250: 
251:     /**
252:      *
253:      * @param unknown_type $id
254:      * @param unknown_type $title
255:      * @param unknown_type $description
256:      */
257:     public function setConfirm($id, $title, $description) {
258:         $this->custom[$id]["confirmtitle"] = $title;
259:         $this->custom[$id]["confirmdescription"] = $description;
260:     }
261: 
262:     /**
263:      *
264:      * @param string $tableid
265:      */
266:     public function setTableID($tableid) {
267:         $this->tableid = $tableid;
268:     }
269: 
270:     /**
271:      *
272:      * @param unknown_type $id
273:      */
274:     public function unsetActionButton($id) {
275:         unset($this->custom[$id]);
276:     }
277: 
278:     /**
279:      * Renders this cGuiTableForm and either returs ist markup or echoes it
280:      * immediately.
281:      *
282:      * @param bool $return if true then return markup, else echo immediately
283:      * @return Ambigous <string, mixed>
284:      */
285:     public function render($return = true) {
286:         global $sess, $cfg;
287: 
288:         $tpl = new cTemplate();
289: 
290:         if ($this->submitjs != "") {
291:             $tpl->set("s", "JSEXTRA", 'onsubmit="' . $this->submitjs . '"');
292:         } else {
293:             $tpl->set("s", "JSEXTRA", '');
294:         }
295: 
296:         $tpl->set("s", "FORMNAME", $this->formname);
297:         $tpl->set("s", "METHOD", $this->formmethod);
298:         $tpl->set("s", "ACTION", $this->formaction);
299: 
300:         $this->formvars[$sess->name] = $sess->id;
301: 
302:         $hidden = "";
303:         if (is_array($this->formvars)) {
304:             foreach ($this->formvars as $key => $value) {
305:                 $val = new cHTMLHiddenField($key, $value);
306:                 $hidden .= $val->render() . "\n";
307:             }
308:         }
309: 
310:         if (!array_key_exists("action", $this->formvars)) {
311:             $val = new cHTMLHiddenField("", "");
312:             $hidden .= $val->render() . "\n";
313:         }
314: 
315:         $tpl->set("s", "HIDDEN_VALUES", $hidden);
316: 
317:         $tpl->set('s', 'ID', $this->tableid);
318: 
319:         $header = "";
320:         if ($this->header != "") {
321:             $tablerow = new cHTMLTableRow();
322:             $tablehead = new cHTMLTableHead();
323:             $tablehead->setAttribute("colspan", "2");
324:             $tablehead->setAttribute("valign", "top");
325:             $tablehead->setContent($this->header);
326:             $tablerow->setContent($tablehead);
327:             $header = $tablerow->render();
328:         }
329: 
330:         $tpl->set('s', 'HEADER', $header);
331: 
332:         if (is_array($this->items)) {
333:             foreach ($this->items as $key => $value) {
334:                 if ($this->itemType[$key] == 'subheader') {
335:                     $tablerow = new cHTMLTableRow();
336:                     $tabledata = new cHTMLTableData();
337:                     $tabledata->setAttribute("colspan", "2");
338:                     $tabledata->setAttribute("valign", "top");
339:                     $tabledata->setContent($this->captions[$key]);
340:                     $tablerow->setContent($tablehead);
341: 
342:                     $tpl->set('d', 'SUBHEADER', $tablerow->render());
343:                 } else {
344:                     $tpl->set('d', 'SUBHEADER', '');
345:                     $tpl->set('d', 'CATNAME', $this->captions[$key]);
346:                     $tpl->set('d', 'CATFIELD', $value);
347:                     $tpl->set('d', 'ROWNAME', $this->rownames[$key]);
348: 
349:                     $tpl->next();
350:                 }
351:             }
352:         }
353: 
354:         if ($this->cancelLink != "") {
355:             $image = new cHTMLImage(cRegistry::getBackendUrl() . 'images/but_cancel.gif');
356:             $link = new cHTMLLink($this->cancelLink);
357:             $link->setContent($image);
358: 
359:             $tpl->set('s', 'CANCELLINK', $link->render());
360:         } else {
361:             $tpl->set('s', 'CANCELLINK', '');
362:         }
363: 
364:         $custombuttons = "";
365: 
366:         foreach ($this->custom as $key => $value) {
367:             if ($value["accesskey"] != "") {
368:                 $accesskey = $value["accesskey"];
369:             } else {
370:                 $accesskey = "";
371:             }
372: 
373:             $onclick = "";
374:             if ($value["action"] !== false) {
375: 
376:                 if ($value["confirmtitle"] != "") {
377:                     $action = 'document.forms["' . $this->formname . '"].elements["action"].value = "' . $value['action'] . '";';
378:                     $action .= 'document.forms["' . $this->formname . '"].submit()';
379: 
380:                     $onclick = 'Con.showConfirmation("' . $value['confirmdescription'] . '", function() { ' . $action . ' });return false;';
381:                 } else {
382:                     $onclick = 'document.forms["' . $this->formname . '"].elements["action"].value = "' . $value['action'] . '";';
383:                 }
384:             }
385: 
386:             if ($value["event"] != "") {
387:                 $onclick .= $value["event"];
388:             }
389: 
390:             $button = new cHTMLFormElement("submit", "", "", "", "", "image_button");
391:             $button->setAttribute("type", "image");
392:             $button->setAttribute("src", $value["image"]);
393:             $button->setAlt($value['description']);
394:             $button->setAttribute("accesskey", $accesskey);
395:             $button->setEvent("onclick", $onclick);
396:             $custombuttons .= $button->render();
397:         }
398: 
399:         $tpl->set('s', 'EXTRABUTTONS', $custombuttons);
400: 
401:         $tpl->set('s', 'ROWNAME', $this->id);
402: 
403:         $rendered = $tpl->generate(cRegistry::getBackendPath() . $cfg['path']['templates'] . $cfg['templates']['generic_table_form'], true);
404: 
405:         if ($return == true) {
406:             return $rendered;
407:         } else {
408:             echo $rendered;
409:         }
410:     }
411: }
412: 
CMS CONTENIDO 4.9.4 API documentation generated by ApiGen 2.8.0