1: <?php
2: /**
3: * A class to render helpful information next to a form element
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: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: /**
18: * Class cGuilBackendHelpbox.
19: * Renders a little helpbox to display information next to a form element
20: *
21: * @package Core
22: * @subpackage GUI
23: */
24: class cGuiBackendHelpbox {
25:
26: /**
27: * the text that will appear in the tooltip
28: *
29: * @var string
30: */
31: protected $helpText;
32:
33: protected $imageURL;
34:
35: /**
36: * Basic constructor.
37: * Assigns a help text
38: *
39: * @param string $helpText the text that will appear in the tooltip
40: * @param string $imageURL This image will be used for the tooltip
41: */
42: public function __construct($helpText, $imageURL = '') {
43: $this->setHelpText($helpText);
44: $this->setImageURL($imageURL);
45: }
46:
47: /**
48: * Set the help text to a new value
49: *
50: * @param string $helpText the text that will appear in the tooltip
51: */
52: public function setHelpText($helpText) {
53: $this->helpText = $helpText;
54: }
55:
56: /**
57: * Set the image for the tooltip
58: *
59: * @param string $imageURL the image file
60: */
61: public function setImageURL($imageURL) {
62: $this->imageURL = $imageURL;
63: }
64:
65: /**
66: * Render the helpbox.
67: * Please make sure that the atooltip.jquery.js and the
68: * atooltip.css are embedded on the site
69: *
70: * @param string $returnAsString if true the rendered button will be
71: * returned. Otherwise it will be echoed
72: * @return string|NULL rendered button or nothing if it's been printed
73: */
74: public function render($returnAsString = true) {
75: $id = md5(rand()) . "-Info";
76:
77: $style = '';
78: if ($this->imageURL != '') {
79: $style = 'style="background: transparent url(' . $this->imageURL . ') no-repeat;"';
80: }
81:
82: $ret = "<a " . $style . " href='javascript://' id='" . $id . "-link' title='" . i18n("More information") . "' class='i-link infoButton'></a>";
83: $ret .= "<div id='" . $id . "' style='display: none;'>" . $this->helpText . "</div>";
84:
85: if ($returnAsString) {
86: return $ret;
87: } else {
88: echo ($ret);
89: return NULL;
90: }
91: }
92: }
93:
94: ?>