add checks for Messge Disposition Notifications.
[squirrelmail.git] / class / html.class.php
CommitLineData
53ef1f99 1<?php
2/**
978d53dc 3 * html.class.php
53ef1f99 4 *
76911253 5 * Copyright (c) 2003 The SquirrelMail Project Team
53ef1f99 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
53ef1f99 8 * This contains functions needed to generate html output.
9 *
10 * $Id$
11 */
12
53ef1f99 13class html {
14 var $tag, $text, $style, $class,
15 $id, $html_el = array(), $javascript, $xtr_prop;
16
17 function html($tag='', $text='', $style ='', $class='', $id='',
18 $xtr_prop = '', $javascript = '') {
19 $this->tag = $tag;
20 $this->text = $text;
21 $this->style = $style;
22 $this->class = $class;
23 $this->id = $id;
24 $this->xtr_prop = $xtr_prop;
25 $this->javascript = $javascript;
26 }
27
6789a914 28 function htmlAdd($el, $last=true) {
29 if ($last) {
30 $this->html_el[] = $el;
31 } else {
6789a914 32 $new_html_el = array();
33 $new_html_el[] = $el;
34 foreach ($this->html_el as $html_el) {
35 $new_html_el[] = $html_el;
36 }
37 $this->html_el = $new_html_el;
38 }
53ef1f99 39 }
40
6789a914 41 function AddChild($tag='', $text='', $style ='', $class='', $id='',
42 $xtr_prop = '', $javascript = '') {
43 $el = new html ($tag, $text, $style, $class, $id, $xtr_prop, $javascript);
44 $this->htmlAdd($el);
45 }
46
47 function FindId($id) {
48 $cnt = count($this->html_el);
49 $el = false;
50 if ($cnt) {
51 for ($i = 0 ; $i < $cnt; $i++) {
52 if ($this->html_el[$i]->id == $id) {
53 $ret = $this->html_el[$i];
54 return $ret;
55 } else if (count($this->html_el[$i]->html_el)) {
56 $el = $this->html_el[$i]->FindId($id);
57 }
58 if ($el) return $el;
59 }
60 }
61 return $el;
62 }
63
64 function InsToId( $el, $id, $last=true) {
65 $html_el = &$this->FindId($id);
66 if ($html_el) {
67 $html_el->htmlAdd($el, $last);
68 }
69 }
70
71 function scriptAdd($script) {
72 $s = "\n".'<!--'."\n".
73 $script .
74 "\n".'// -->'."\n";
2bfc4fbf 75 $el = new html ('script',$s,'','','',array('language' => 'JavaScript',
6789a914 76 'type' => 'text/javascript'));
77 $this->htmlAdd($el);
78 }
53ef1f99 79
84d46e4e 80 function echoHtml( $usecss=false, $indent='x') {
81 if ($indent == 'x') {
82 $indent = ''; $indentmore = '';
83 } else {
84 $indentmore = $indent . ' ';
85 }
53ef1f99 86 $tag = $this->tag;
87 $text = $this->text;
88 $class = $this->class;
89 $id = $this->id;
90 $style = $this->style;
91 $javascript = $this->javascript;
92 $xtr_prop = $this->xtr_prop;
93 if ($xtr_prop) {
94 $prop = '';
95 foreach ($xtr_prop as $k => $v) {
96 if (is_string($k)) {
97 $prop.=' '.$k.'="'.$v.'"';
98 } else {
99 $prop.=' '.$v;
100 }
101 }
102 }
103 if ($javascript) {
104 $js = '';
105 foreach ($javascript as $k => $v) { /* here we put the onclick, onmouseover etc entries */
106 $js.=' '.$k.'="'.$v.'";';
107 }
108 }
6789a914 109 if ($tag) {
110 echo $indent . '<' . $tag;
111 } else {
112 echo $indent;
113 }
53ef1f99 114 if ($class) {
115 echo ' class="'.$class.'"';
116 }
117 if ($id) {
118 echo ' id="'.$id.'"';
119 }
120 if ($xtr_prop) {
121 echo ' '.$prop;
122 }
4a177858 123 if ($style && !$usecss && !is_array($style)) {
124 /* last premisse is to prevent 'style="Array"' in the output */
53ef1f99 125 echo ' style="'.$style.'"';
126 }
127 if ($javascript) {
128 echo ' '.$js;
129 }
6789a914 130 if ($tag) echo '>';
c6bed723 131
132 $openstyles = '';
133 $closestyles = '';
134 if ($style && !$usecss) {
135 foreach ($style as $k => $v) {
136 $openstyles .= '<'.$k.'>';
53ef1f99 137 }
c6bed723 138 foreach ($style as $k => $v) {
139 /* if value of key value = true close the tag */
140 if ($v) {
141 $closestyles .= '</'.$k.'>';
142 }
143 }
144 }
145 echo $openstyles;
146
147 if ($text) {
148 echo $text;
53ef1f99 149 }
c6bed723 150
53ef1f99 151 $cnt = count($this->html_el);
152 if ($cnt) {
153 echo "\n";
53ef1f99 154 for($i = 0;$i<$cnt;$i++) {
155 $el = $this->html_el[$i];
4a177858 156 $el->echoHtml($usecss,$indentmore);
53ef1f99 157 }
c6bed723 158 echo $indent;
6789a914 159 }
c6bed723 160 echo $closestyles;
6789a914 161 if ($tag) {
c6bed723 162 echo '</'.$tag.'>'."\n";
6789a914 163 } else {
164 echo "\n";
53ef1f99 165 }
53ef1f99 166 }
167}
168
169
170?>