File: gui.toolkit.inc.php

package info (click to toggle)
jffnms 0.8.3dfsg.1-2.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 4,924 kB
  • ctags: 5,050
  • sloc: php: 19,981; sh: 215; makefile: 91; perl: 52
file content (285 lines) | stat: -rw-r--r-- 8,380 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?
/* This file is part of JFFNMS
 * Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
 * This program is licensed under the GNU GPL, full terms in the LICENSE file
 */
    /* Basic HTML Structures */

    function tag ($name, $id = "", $class = "", $others = "", $indent = true, $keep_lines = false) {
	return  
	    html_indenter().
	    "<".$name.
	    (!empty($id)?" id='".$id."'":"").
	    (!empty($class)?" class='".$class."'":"").
	    (!empty($others)?" ".trim($others):"").
	    ">".
	    (($keep_lines)?"":"\n").
	    (($indent)?html_indent_more():"");
    }

    function tag_close($name, $indent = true, $indent_after = true) {
	return 
	    (($indent)?html_indent_less():"").
	    (($indent_after)?html_indenter():"").
	    "</".$name.">\n";
    }

    function html ($name, $content, $id = "", $class = "", $others = "", $indent = true, $keep_lines = false)  {
	return
	    tag ($name, $id, $class, $others, $indent, $keep_lines).
	    (!empty($content)
		?re_indent($content,$keep_lines)
		:"").
	    tag_close($name, $indent, $indent);
    }

    function re_indent($text, $keep_lines = false) {

	if ($keep_lines) return $text;

	$ind = html_indenter();

        $lines = explode("\n",$text);
    
	foreach ($lines as $line)
	    if ($line!=="") {
		$line = rtrim($line);
		if (++$i==1) $cant = @substr_count("\t",$line);
	    
		$line = substr($line,$count);
	        $result .= $ind.$line."\n";
	    }

	return rtrim($result)."\n";
    }

    /* Complex HTML Structures */

    function table ($id="", $class = "") {
	return tag("table", $id, $class, "", false);
    }
    
    function table_close() {
	return tag_close ("table", false);
    }

    function tr_open($id = "", $class = "", $bgcolor = "", $rowspan = "", $style = "") {
	return
	    tag("tr", $id, $class, 
		(!empty($bgcolor)?" bgcolor='$bgcolor'":"").
		(!empty($rowspan)?" rowspan=$rowspan":"").
		(!empty($style)?" style='$style'":""));
    } 

    function td ($content="", $class = "", $id = "", $colspan = "", $rowspan = "", $keep_lines = false) {
	return
	    html ("td", $content, $id, $class, 
		(is_numeric($colspan)?" colspan='$colspan'":"").
		(is_numeric($rowspan)?" rowspan='$rowspan'":""), true, $keep_lines);
    }

    function table_row($text = "", $class = "", $colspan="", $rowspan="", $echo = true) {
    
	$result = 
	    tr_open("", "", "", $rowspan).
	    td($text, $class, "", $colspan).
	    tag_close("tr");
    
	if ($echo) 
	    echo $result;

	return $result;
    }

    function tr ($tds = "", $classes = "", $colspans="", $rowspan="") {
	
	$tds = !is_array($tds)?array($tds):$tds;
	$classes = !is_array($classes)?array($classes):$classes;
	$colspans = !is_array($colspans)?array($colspans):$colspans;

	$result = tr_open("", "", "", $rowspan);
	
	foreach ($tds as $key=>$td_content) 
	    $result .= td ($td_content, 
		(isset($classes[$key])?$classes[$key]:current($classes)), "", 
		(isset($colspans[$key])?$colspans[$key]:current($colspans)));

	$result .= tag_close("tr");
    
	return $result;
    }

    function script ($content) {
	return 
	    tag ("script","","","type='text/javascript'").
	    re_indent($content,true)."\n".
	    tag_close("script");
    }

    function br() {
	return tag ("br","","","",false);
    }

    function memobox($name,$rows,$cols,$value) {
        return 
	    html ("textarea", $value, "", "", "rows='$rows' cols='$cols' name='$name'", false, true);
    }

    function checkbox($name, $var, $form = true) {
	return checkbox_value($name,1,$var,$form);
    }

    function checkbox_value($name,$value, $check = false, $form = true, $onclick="") {
	if ($form==false) {
	    $name = "checkbox_".rand(1000,9999);
	    $disabled = " disabled";
	}
    
	if ($check==true) $checked=" checked";
        if (!empty($onclick)) $js = " onClick=\"$onclick\"";
    
	return 
	    tag("input", $name, "", 
	    "type='checkbox' name='$name' value='$value'".$checked.$js.$disabled, false);
    }

    function textbox($name, $var, $len = 0, $maxsize = 0, $disabled = 0) {
	return tag("input", $name, "", 
	    "type='text' name='$name' value='$var' size='".(($len==0)?strlen($var):$len)."'".
	    (($maxsize>0)?" maxsize='$maxsize'":"").
	    (($disabled==1)?" disabled":""), false);
    }

    function form ($id = "", $action = "", $method = "POST", $target = "_self", $class = "") {
	return	
        tag ("form", $id, $class,
		(!empty($action)?" action='".$action."'":"").
		(!empty($method)?" method='".$method."'":"").
		(!empty($target)?" target='".$target."'":"")
	    ,false);
    }

    function adm_form_submit($value = "Submit", $name = "") {
	return 
	    tag ("input", "" ,"", 
	    (!empty($name)?"name='$name'":""). 
	    " type='submit' value='$value'", false);
    }
    
    function form_close() {
	return tag_close("form", false);
    }

    function image($src, $w = "", $h = "", $title = "", $class="", $id = "", $onclick="", $others = "") {
	
	if (!empty($src) && (strpos($src,"/")===false)) { //when we were given a file without a path
	    if (($w==="") && ($h==="")) //only when w and h are not set, but if you use NULL you will avoid the w/h fields
		list($w, $h) = getimagesize($GLOBALS["jffnms_real_path"]."/htdocs/images/".$src);

	    $src = $GLOBALS["jffnms_rel_path"]."/images/".$src;	//add default path
	}
	
	return 
	    tag ("img", $id, $class, 
	        "src='".$src."'".
		" title='".$title."' alt='".$title."'".
		(!empty($w)?" width='".$w."'":"").
		(!empty($h)?" height='".$h."'":"").
		(!empty($onclick)?" OnClick='javascript: ".$onclick."'":"").
		(!empty($others)?" ".$others:"")
		, false);
    }

    function linktext ($text, $url, $target="" ,$class = "", $on_click = "", $id = "", $style = "") {
	return
	    html ("a", $text, $id, $class, 
		(!empty($target)?" target='".$target."'":"").
	        (!empty($url)?" href=\"".htmlspecialchars($url)."\"":"").
		(!empty($on_click)?" onClick=\"".$on_click."\"":"").
		(!empty($style)?" style='".$style."'":"")
	    );
    }

    function radiobutton($name, $selected, $value) {
	return tag ("input", $name, ""," type='radio' name='".$name."' value='".$value."'".
	    (($selected==1)?" checked":""), false);
    }

    function hidden($name,$value) { 
	return tag ("input","","","type='hidden' name='".$name."' value='".$value."'", false);
    }

    function select_custom ($control_name,$options,$mark_values,$onclick="", $size = 1, $echo = false, $class = "", $ondblclick = "") {

	if ($size > 1) {
	    $multi = "multiple size='".$size."'";
	    $control_name.="[]";
	}  

	if (!is_array($mark_values)) $mark_values=explode(",",$mark_values);
    
	$result .= tag ("select", $control_name, $class, "name='".$control_name."'".
	    (($onclick)?" onChange=\"".$onclick."\"":"").
	    (($ondblclick)?" onDblClick=\"".$ondblclick."\"":"").
	    (!empty($multi)?" ".$multi:""));

        foreach ($options as $key=>$value){
	    //debug ($key." - ".in_array($key,$mark_values)." - ".$mark_values[0]." - ".($mark_values[0]==="SELECT_ALL"));
	
	    $encoded_key = ((strpos($key,"=")===false) && (strlen($key) > 3))?urlencode($key):$key;

	    $result .= html("option",$value,"","","value='".$encoded_key."'".
		((in_array($key,$mark_values) or ($mark_values[0]==="SELECT_ALL"))?" selected":"")
		, false, true);
	}

	$result .= tag_close("select");

	if ($echo) 
	    echo $result;
	return $result;
    }

    /* HTML Automatic Indenting Functions */

    function html_indent_none() {
	html_indent_init();
	$GLOBALS["html_indents"][$GLOBALS["html_indent"]]=0;
    }

    function html_indent_more () {
	$GLOBALS["html_indent"]++;
	return html_indent_none();
    }

    function html_indent_less () {
	$GLOBALS["html_indent"]--;
	return html_indent_none();
    }

    function html_indent_init () {
	if (!isset($GLOBALS["html_indent"]) || !isset($GLOBALS["html_indents"])) {
	    $GLOBALS["html_indent"] = 0;
	    $GLOBALS["html_indents"] = array($GLOBALS["html_indent"]=>0);
	}
    }

    function html_indent_already() {
	html_indent_init();
	return $GLOBALS["html_indents"][$GLOBALS["html_indent"]];
    }

    function html_indenter ($verify = 0, $count = 1) {
	if ((html_indent_already()==0) || (!$verify)) {

	    $result = "";
	    for ($i = 0; $i < $GLOBALS["html_indent"]; $i++) $result .= "\t";

	    if ($count) $GLOBALS["html_indents"][$GLOBALS["html_indent"]]=1;

	    return $result;
	} else 
	    echo "!";
    }

?>