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