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:  * @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:      * @return string
305:      */
306:     public function render($return = true) {
307:         global $sess, $cfg;
308: 
309:         $tpl = new cTemplate();
310: 
311:         if ($this->submitjs != "") {
312:             if (strlen($this->_acceptCharset) > 0) {
313:                 $tpl->set("s", "JSEXTRA", 'onsubmit="' . $this->submitjs
314:                         . '" accept-charset="' . $this->_acceptCharset . '"');
315:             } else {
316:                 $tpl->set("s", "JSEXTRA", 'onsubmit="' . $this->submitjs . '"');
317:             }
318:         } else {
319:             if (strlen($this->_acceptCharset) > 0) {
320:                 $tpl->set("s", "JSEXTRA", 'accept-charset="' . $this->_acceptCharset . '"');
321:             } else {
322:                 $tpl->set("s", "JSEXTRA", '');
323:             }
324:         }
325: 
326:         $tpl->set("s", "FORMNAME", $this->formname);
327:         $tpl->set("s", "METHOD", $this->formmethod);
328:         $tpl->set("s", "ACTION", $this->formaction);
329: 
330:         $this->formvars[$sess->name] = $sess->id;
331: 
332:         $hidden = "";
333:         if (is_array($this->formvars)) {
334:             foreach ($this->formvars as $key => $value) {
335:                 $val = new cHTMLHiddenField($key, $value);
336:                 $hidden .= $val->render() . "\n";
337:             }
338:         }
339: 
340:         if (!array_key_exists("action", $this->formvars)) {
341:             $val = new cHTMLHiddenField("", "");
342:             $hidden .= $val->render() . "\n";
343:         }
344: 
345:         $tpl->set("s", "HIDDEN_VALUES", $hidden);
346: 
347:         $tpl->set('s', 'ID', $this->tableid);
348: 
349:         $header = "";
350:         if ($this->header != "") {
351:             $tablerow = new cHTMLTableRow();
352:             $tablehead = new cHTMLTableHead();
353:             $tablehead->setAttribute("colspan", "2");
354:             $tablehead->setAttribute("valign", "top");
355:             $tablehead->setContent($this->header);
356:             $tablerow->setContent($tablehead);
357:             $header = $tablerow->render();
358:         }
359: 
360:         $tpl->set('s', 'HEADER', $header);
361: 
362:         if (is_array($this->items)) {
363:             foreach ($this->items as $key => $value) {
364:                 if ($this->itemType[$key] == 'subheader') {
365:                     $tablerow = new cHTMLTableRow();
366:                     $tabledata = new cHTMLTableData();
367:                     $tabledata->setAttribute("colspan", "2");
368:                     $tabledata->setAttribute("valign", "top");
369:                     $tabledata->setContent($this->captions[$key]);
370:                     $tablerow->setContent($tablehead);
371: 
372:                     $tpl->set('d', 'SUBHEADER', $tablerow->render());
373:                 } else {
374:                     $tpl->set('d', 'SUBHEADER', '');
375:                     $tpl->set('d', 'CATNAME', $this->captions[$key]);
376:                     $tpl->set('d', 'CATFIELD', $value);
377:                     $tpl->set('d', 'ROWNAME', $this->rownames[$key]);
378: 
379:                     $tpl->next();
380:                 }
381:             }
382:         }
383: 
384:         if ($this->cancelLink != "") {
385:             $image = new cHTMLImage(cRegistry::getBackendUrl() . 'images/but_cancel.gif');
386:             $link = new cHTMLLink($this->cancelLink);
387:             $link->setContent($image);
388: 
389:             $tpl->set('s', 'CANCELLINK', $link->render());
390:         } else {
391:             $tpl->set('s', 'CANCELLINK', '');
392:         }
393: 
394:         $custombuttons = "";
395: 
396:         foreach ($this->custom as $key => $value) {
397:             if ($value["accesskey"] != "") {
398:                 $accesskey = $value["accesskey"];
399:             } else {
400:                 $accesskey = "";
401:             }
402: 
403:             $onclick = "";
404:             if ($value["action"] !== false) {
405: 
406:                 if ($value["confirmtitle"] != "") {
407:                     $action = 'document.forms["' . $this->formname . '"].elements["action"].value = "' . $value['action'] . '";';
408:                     $action .= 'document.forms["' . $this->formname . '"].submit()';
409: 
410:                     $onclick = 'Con.showConfirmation("' . $value['confirmdescription'] . '", function() { ' . $action . ' });return false;';
411:                 } else {
412:                     $onclick = 'document.forms["' . $this->formname . '"].elements["action"].value = "' . $value['action'] . '";';
413:                 }
414:             }
415: 
416:             if ($value["event"] != "") {
417:                 $onclick .= $value["event"];
418:             }
419: 
420:             $button = new cHTMLFormElement("submit", "", "", "", "", "image_button");
421:             $button->setAttribute("type", "image");
422:             $button->setAttribute("src", $value["image"]);
423:             $button->setAlt($value['description']);
424:             $button->setAttribute("accesskey", $accesskey);
425:             $button->setEvent("onclick", $onclick);
426:             $custombuttons .= $button->render();
427:         }
428: 
429:         $tpl->set('s', 'EXTRABUTTONS', $custombuttons);
430: 
431:         $tpl->set('s', 'ROWNAME', $this->id);
432: 
433:         $rendered = $tpl->generate(cRegistry::getBackendPath() . $cfg['path']['templates'] . $cfg['templates']['generic_table_form'], true);
434: 
435:         if ($return == true) {
436:             return $rendered;
437:         } else {
438:             echo $rendered;
439:         }
440:     }
441: }
442: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0