5 * Copyright (c) 2002 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * This contains functions needed to generate html output.
15 var $tag, $text, $style, $class,
16 $id, $html_el = array(), $javascript, $xtr_prop;
18 function html($tag='', $text='', $style ='', $class='', $id='',
19 $xtr_prop = '', $javascript = '') {
22 $this->style
= $style;
23 $this->class = $class;
25 $this->xtr_prop
= $xtr_prop;
26 $this->javascript
= $javascript;
29 function htmlAdd($el, $last=true) {
31 $this->html_el
[] = $el;
33 $new_html_el = array();
35 foreach ($this->html_el
as $html_el) {
36 $new_html_el[] = $html_el;
38 $this->html_el
= $new_html_el;
42 function AddChild($tag='', $text='', $style ='', $class='', $id='',
43 $xtr_prop = '', $javascript = '') {
44 $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
48 function FindId($id) {
49 $cnt = count($this->html_el
);
52 for ($i = 0 ; $i < $cnt; $i++
) {
53 if ($this->html_el
[$i]->id
== $id) {
54 $ret = $this->html_el
[$i];
56 } else if (count($this->html_el
[$i]->html_el
)) {
57 $el = $this->html_el
[$i]->FindId($id);
65 function InsToId( $el, $id, $last=true) {
66 $html_el = &$this->FindId($id);
68 $html_el->htmlAdd($el, $last);
72 function scriptAdd($script) {
73 $s = "\n".'<!--'."\n".
76 $el = new html ('script',$s,'','','',array('language' => 'JavaScript',
77 'type' => 'text/javascript'));
81 function echoHtml( $usecss=false, $indent='x') {
83 $indent = ''; $indentmore = '';
85 $indentmore = $indent . ' ';
89 $class = $this->class;
91 $style = $this->style
;
92 $javascript = $this->javascript
;
93 $xtr_prop = $this->xtr_prop
;
96 foreach ($xtr_prop as $k => $v) {
98 $prop.=' '.$k.'="'.$v.'"';
106 foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
107 $js.=' '.$k.'="'.$v.'";';
111 echo $indent . '<' . $tag;
116 echo ' class="'.$class.'"';
119 echo ' id="'.$id.'"';
124 if ($style && !$usecss && !is_array($style)) {
125 /* last premisse is to prevent 'style="Array"' in the output */
126 echo ' style="'.$style.'"';
135 if ($style && !$usecss) {
136 foreach ($style as $k => $v) {
137 $openstyles .= '<'.$k.'>';
139 foreach ($style as $k => $v) {
140 /* if value of key value = true close the tag */
142 $closestyles .= '</'.$k.'>';
152 $cnt = count($this->html_el
);
155 for($i = 0;$i<$cnt;$i++
) {
156 $el = $this->html_el
[$i];
157 $el->echoHtml($usecss,$indentmore);
163 echo '</'.$tag.'>'."\n";