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 lists */
76 $from = array("/class=['\"]list1nohighlight['\"]/i",
77 "/class=['\"]list0['\"]/i",
78 "/class=['\"]list1['\"]/i",
79 "/class=['\"]sortableListItem[^'\"]*['\"]/i");
80 $to = array("class='list1nohighlightdisabled'",
81 "class='list1nohighlightdisabled'",
82 "class='list1nohighlightdisabled'",
83 "class='sortableListItemDisabled'");
85 if(!preg_match("/ disabled /",$text)){
86 $from [] = "/name=/i" ;
87 $to [] = "disabled name=";
88 }
90 $text = preg_replace($from,$to,$text);
92 /* Replace picture if object is disabled */
93 if(isset($params['disable_picture'])){
94 $syn = "/src=['\"][^\"']*['\"]/i";
95 $new = "src=\"".$params['disable_picture']."\"";
96 $text = preg_replace($syn,$new,$text);
97 }
98 }
100 /* Read only */
101 if(preg_match("/r/i",$acl)){
102 return(preg_replace("/GOSA_LINE_BREAK/","\n",$text));
103 }
105 /* No acls */
106 if(preg_match("/type['\"= ].*submit/",$text)){
107 $text = preg_replace("/submit/","button",$text);
108 }else{
109 $text = preg_replace("/value=['\"][^\"']*['\"]/","",$text);
110 }
112 /* Remove select options */
113 $from = array("#<option.*<\/option>#i",
114 "/(<textarea.*>).*(<\/textarea>)/i",
115 "/^(.*<input.*)checked(.*>.*)$/i");
117 $to = array(" ",
118 "\\1\\2",
119 "\\1 \\2");
120 $text = preg_replace($from,$to,$text);
121 $text = preg_replace("/GOSA_LINE_BREAK/","\n",$text);
123 return $text;
124 }
126 ?>