Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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

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