~ubuntu-branches/ubuntu/vivid/gosa/vivid

« back to all changes in this revision

Viewing changes to gosa-core/include/smarty/plugins/block.render.php

Tags: 2.7.1-1
* New upstream release
* Updated packaging to not include smarty (Closes: #620489)
* Fixed case of POSIX (Closes: #620486)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
function smarty_block_render($params, $text, &$smarty)
 
4
{
 
5
        /* Skip closing tag </render> */        
 
6
        if(empty($text)) {
 
7
                return("");
 
8
        }
 
9
 
 
10
        /* Get acl parameter */
 
11
        $acl = "";
 
12
        if (isset($params['acl'])) {
 
13
                $acl = $params['acl'];
 
14
        }
 
15
 
 
16
        /* Debug output */
 
17
        if (session::is_set('debugLevel') && session::get('debugLevel') & DEBUG_ACL ){
 
18
                echo "<font color='blue' size='2'>&nbsp;".$acl."</font>";
 
19
        }
 
20
 
 
21
 
 
22
 
 
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']){
 
30
 
 
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);       
 
34
 
 
35
                /* Detect id */
 
36
                if(preg_match("/ id=(\"|')[^\"']*(\"|')/i",$text)){
 
37
                        $id = preg_replace('/^.* id[ ]*=[ ]*("|\')([^\"\' ]*).*$/i',"\\2",$use_text);   
 
38
                }else{
 
39
                        $id = "";
 
40
                }
 
41
                
 
42
                /* Is the box checked? */
 
43
                isset($params['checked'])&&$params['checked'] ? $check = " checked " : $check = "";
 
44
 
 
45
                /* If name isset, we have a html input field */ 
 
46
                if(!empty($name)){
 
47
 
 
48
                        /* Print checkbox */
 
49
                        echo "<input type='checkbox' name='use_".$name."' ".$check." 
 
50
                                        onClick=\"changeState('".$name."');\" class='center'>";
 
51
 
 
52
                        /* Disable current object, if checkbox isn't checked */
 
53
                        if($check == ""){
 
54
                                $text = preg_replace("/name=/i"," disabled name=",$text);
 
55
                        }
 
56
                        
 
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
        }
 
63
 
 
64
 
 
65
        /* Read / Write*/
 
66
        if(preg_match("/w/i",$acl)){
 
67
                return ($text);
 
68
        }
 
69
 
 
70
        $text = preg_replace ("/\n/","GOSA_LINE_BREAK",$text);
 
71
 
 
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))){
 
74
 
 
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'");
 
84
                                
 
85
                if(!preg_match("/ disabled /",$text)){
 
86
                        $from [] = "/name=/i" ;
 
87
                        $to   [] = "disabled name=";
 
88
                }
 
89
 
 
90
                $text   = preg_replace($from,$to,$text);
 
91
 
 
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
        }               
 
99
 
 
100
        /* Read only */
 
101
        if(preg_match("/r/i",$acl)){
 
102
                return(preg_replace("/GOSA_LINE_BREAK/","\n",$text));   
 
103
        }
 
104
 
 
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
        }
 
111
 
 
112
        /* Remove select options */
 
113
        $from   = array("#<option.*<\/option>#i",
 
114
                        "/(<textarea.*>).*(<\/textarea>)/i",
 
115
                        "/^(.*<input.*)checked(.*>.*)$/i");
 
116
 
 
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);
 
122
 
 
123
        return $text;
 
124
}
 
125
 
 
126
?>