1 <?php
3 function smarty_block_render($params, $text, &$smarty)
4 {
5 /* Skip closing tag </render> */
6 if(empty($text)) {
7 return("");
8 }
10 /* Get acl parameter */
11 $acl = "";
12 if (isset($params['acl'])) {
13 $acl = $params['acl'];
14 }
16 /* Debug output */
17 if (session::is_set('DEBUGLEVEL') && session::get('DEBUGLEVEL') & DEBUG_ACL ){
18 echo "<font color='blue' size='2'> ".$acl."</font>";
19 }
23 /* Parameter : checkbox, checked
24 * If the parameter 'checkbox' is given, we create a html checkbox in front
25 * of the current object.
26 * The parameter 'checked' specifies whether the box is checked or not.
27 * The checkbox disables or enables the current object.
28 */
29 if(isset($params['checkbox']) && $params['checkbox']){
31 /* Detect name and id of the current object */
32 $use_text = preg_replace("/\n/"," ",$text);
33 $name = preg_replace('/^.* name[ ]*=[ ]*("|\')([^\"\' ]*).*$/i',"\\2",$use_text);
35 /* Detect id */
36 if(preg_match("/ id=(\"|')[^\"']*(\"|')/i",$text)){
37 $id = preg_replace('/^.* id[ ]*=[ ]*("|\')([^\"\' ]*).*$/i',"\\2",$use_text);
38 }else{
39 $id = "";
40 }
42 /* Is the box checked? */
43 isset($params['checked'])&&$params['checked'] ? $check = " checked " : $check = "";
45 /* If name isset, we have a html input field */
46 if(!empty($name)){
48 /* Print checkbox */
49 echo "<input type='checkbox' name='use_".$name."' ".$check."
50 onClick=\"changeState('".$name."');\" class='center'>";
52 /* Disable current object, if checkbox isn't checked */
53 if($check == ""){
54 $text = preg_replace("/name=/i"," disabled name=",$text);
55 }
57 /* Add id to current entry, if it is missing */
58 if($id == ""){
59 $text = preg_replace("/name=/i"," id=\"".$name."\" name=",$text);
60 }
61 }
62 }
65 /* Read / Write*/
66 if(preg_match("/w/i",$acl)){
67 return ($text);
68 }
70 $text = preg_replace ("/\n/","GOSA_LINE_BREAK",$text);
72 /* Disable objects, but keep those active that have mode=read_active */
73 if(!(isset($params['mode']) && ($params['mode']=='read_active') && preg_match("/(r|w)/",$acl))){
75 /* Disable options && greyout divlists */
76 $from = array("/class=['\"]list1nohighlight['\"]/i",
77 "/class=['\"]list0['\"]/i",
78 "/class=['\"]list1['\"]/i");
79 $to = array("class='list1nohighlightdisabled'",
80 "class='list1nohighlightdisabled'",
81 "class='list1nohighlightdisabled'");
83 if(!preg_match("/ disabled /",$text)){
84 $from [] = "/name=/i" ;
85 $to [] = "disabled name=";
86 }
88 $text = preg_replace($from,$to,$text);
90 /* Replace picture if object is disabled */
91 if(isset($params['disable_picture'])){
92 $syn = "/src=['\"][^\"']*['\"]/i";
93 $new = "src=\"".$params['disable_picture']."\"";
94 $text = preg_replace($syn,$new,$text);
95 }
96 }
98 /* Read only */
99 if(preg_match("/r/i",$acl)){
100 return(preg_replace("/GOSA_LINE_BREAK/","\n",$text));
101 }
103 /* No acls */
104 if(preg_match("/type['\"= ].*submit/",$text)){
105 $text = preg_replace("/submit/","button",$text);
106 }else{
107 $text = preg_replace("/value=['\"][^\"']*['\"]/","",$text);
108 }
110 /* Remove select options */
111 $from = array("#<option.*<\/option>#i",
112 "/(<textarea.*>).*(<\/textarea>)/i",
113 "/^(.*<input.*)checked(.*>.*)$/i");
115 $to = array(" ",
116 "\\1\\2",
117 "\\1 \\2");
118 $text = preg_replace($from,$to,$text);
119 $text = preg_replace("/GOSA_LINE_BREAK/","\n",$text);
121 return $text;
122 }
124 ?>