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.
14 var $tag, $text, $style, $class,
15 $id, $html_el = array(), $javascript, $xtr_prop;
17 function html($tag='', $text='', $style ='', $class='', $id='',
18 $xtr_prop = '', $javascript = '') {
21 $this->style
= $style;
22 $this->class = $class;
24 $this->xtr_prop
= $xtr_prop;
25 $this->javascript
= $javascript;
28 function htmlAdd($el, $last=true) {
30 $this->html_el
[] = $el;
32 $new_html_el = array();
34 foreach ($this->html_el
as $html_el) {
35 $new_html_el[] = $html_el;
37 $this->html_el
= $new_html_el;
41 function AddChild($tag='', $text='', $style ='', $class='', $id='',
42 $xtr_prop = '', $javascript = '') {
43 $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
47 function FindId($id) {
48 $cnt = count($this->html_el
);
51 for ($i = 0 ; $i < $cnt; $i++
) {
52 if ($this->html_el
[$i]->id
== $id) {
53 $ret = $this->html_el
[$i];
55 } else if (count($this->html_el
[$i]->html_el
)) {
56 $el = $this->html_el
[$i]->FindId($id);
64 function InsToId( $el, $id, $last=true) {
65 $html_el = &$this->FindId($id);
67 $html_el->htmlAdd($el, $last);
71 function scriptAdd($script) {
72 $s = "\n".'<!--'."\n".
75 $el = new html ('script',$s,'','','',array('language' => 'JavaScript',
76 'type' => 'text/javascript'));
80 function echoHtml( $usecss=false, $indent='x') {
82 $indent = ''; $indentmore = '';
84 $indentmore = $indent . ' ';
88 $class = $this->class;
90 $style = $this->style
;
91 $javascript = $this->javascript
;
92 $xtr_prop = $this->xtr_prop
;
95 foreach ($xtr_prop as $k => $v) {
97 $prop.=' '.$k.'="'.$v.'"';
105 foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
106 $js.=' '.$k.'="'.$v.'";';
110 echo $indent . '<' . $tag;
115 echo ' class="'.$class.'"';
118 echo ' id="'.$id.'"';
123 if ($style && !$usecss && !is_array($style)) {
124 /* last premisse is to prevent 'style="Array"' in the output */
125 echo ' style="'.$style.'"';
134 if ($style && !$usecss) {
135 foreach ($style as $k => $v) {
136 $openstyles .= '<'.$k.'>';
138 foreach ($style as $k => $v) {
139 /* if value of key value = true close the tag */
141 $closestyles .= '</'.$k.'>';
151 $cnt = count($this->html_el
);
154 for($i = 0;$i<$cnt;$i++
) {
155 $el = $this->html_el
[$i];
156 $el->echoHtml($usecss,$indentmore);
162 echo '</'.$tag.'>'."\n";