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;
34 $new_html_el = array();
36 foreach ($this->html_el as $html_el) {
37 $new_html_el[] = $html_el;
39 $this->html_el = $new_html_el;
43 function AddChild($tag='', $text='', $style ='', $class='', $id='',
44 $xtr_prop = '', $javascript = '') {
45 $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
49 function FindId($id) {
50 $cnt = count($this->html_el);
53 for ($i = 0 ; $i < $cnt; $i++) {
54 if ($this->html_el[$i]->id == $id) {
55 $ret = $this->html_el[$i];
57 } else if (count($this->html_el[$i]->html_el)) {
58 $el = $this->html_el[$i]->FindId($id);
66 function InsToId( $el, $id, $last=true) {
67 $html_el = &$this->FindId($id);
69 $html_el->htmlAdd($el, $last);
73 function scriptAdd($script) {
74 $s = "\n".'<!--'."\n".
77 $el = new html ('script',$s,''.''.''.array('language' => 'JavaScript',
78 'type' => 'text/javascript'));
82 function echoHtml( $usecss=false, $indent='x') {
84 $indent = ''; $indentmore = '';
86 $indentmore = $indent . ' ';
90 $class = $this->class;
92 $style = $this->style;
93 $javascript = $this->javascript;
94 $xtr_prop = $this->xtr_prop;
97 foreach ($xtr_prop as $k => $v) {
99 $prop.=' '.$k.'="'.$v.'"';
107 foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
108 $js.=' '.$k.'="'.$v.'";';
112 echo $indent . '<' . $tag;
117 echo ' class="'.$class.'"';
120 echo ' id="'.$id.'"';
125 if ($style && !$usecss && !is_array($style)) {
126 /* last premisse is to prevent 'style="Array"' in the output */
127 echo ' style="'.$style.'"';
136 if ($style && !$usecss) {
137 foreach ($style as $k => $v) {
138 $openstyles .= '<'.$k.'>';
140 foreach ($style as $k => $v) {
141 /* if value of key value = true close the tag */
143 $closestyles .= '</'.$k.'>';
153 $cnt = count($this->html_el);
156 for($i = 0;$i<$cnt;$i++) {
157 $el = $this->html_el[$i];
158 $el->echoHtml($usecss,$indentmore);
164 echo '</'.$tag.'>'."\n";