Code

Apply fix for #3750
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_faiVariableEntry.inc
1 <?php
3 class faiVariableEntry extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes   = array("cn","description","FAIvariableContent");
8   var $objectclasses= array();
10   var $orig_cn              = "";
11   var $dn            = "";
12   var $cn            = "";
13   var $FAIvariableContent   = "";
14   var $description   = "";
15   var $status        = "new";
16   var $parent        = NULL;
17   var $FAIstate      = "";
18   
19   function faiVariableEntry (&$config, $dn= NULL,$object=false)
20   {
21     plugin::plugin ($config, $dn);
22     if((isset($object['cn'])) && (!empty($object['cn']))){
23       $this->orig_cn= $object['cn'];
24       $this->dn=$object['dn'];
25       foreach($object as $name=>$value){
26         $oname = $name;
27         $this->$oname=addslashes($value);
28       }
29     }else{
30       $this->status = "new";
31       $this->orig_cn       = false;
32     }
33   }
35   function execute()
36   {
37         /* Call parent execute */
38         plugin::execute();
40     /* Fill templating stuff */
41     $smarty     = get_smarty();
42     $display = "";
44      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
45      * If we post the escaped strings they will be escaped again
46      */
47     foreach($this->attributes as $attrs){
48       if(get_magic_quotes_gpc()){
49         $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs))));
50       }else{
51         $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs)));
52       }
53     }
55     $tmp = $this->plInfo();
56     foreach($tmp['plProvidedAcls'] as $name => $translated){
57       $acl = $this->getacl($name, preg_match("/freeze/",$this->FAIstate));
58       $smarty->assign($name."ACL",$acl);
59     }
61     $smarty->assign("freeze",preg_match("/freeze/",$this->FAIstate));
62     $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
63     return($display);
64   }
67   /* Save data to object */
68   function save_object()
69   {
70      if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
71       foreach($this->attributes as $attrs){
72         if($this->acl_is_writeable($attrs)){
73           if(isset($_POST[$attrs])){
74             $this->$attrs = $_POST[$attrs];
75           }else{
76             $this->$attrs = "";
77           }
78         }
79       }
80     }
81   }
83   /* Check supplied data */
84   function check()
85   {
86     /* Call common method to give check the hook */
87     $message= plugin::check();
89     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
90       $message[] = msgPool::duplicated(_("Name"));
91     }
92     
93     if($this->FAIvariableContent == "") {
94       $message[]= msgPool::required(_("Content")); 
95     }
96   
97     $c = trim($this->cn);
98     if($c == ""){
99       $message[] = msgPool::required(_("Name"));
100     }
101     if(preg_match("/[^a-z0-9_\-]/i",$c)){
102       $message[] = msgPool::invalid(_("Name"),$c,"/[a-z0-9_\-]/i");
103     }
105     return ($message);
106   }
107  
108   function save()
109   {
110     $tmp=array();
111     foreach($this->attributes as $attrs){ 
112       $tmp[$attrs] = stripslashes( $this->$attrs);
113     }
115     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
116       $tmp['remove']['from']  = $this->orig_cn;
117       $tmp['remove']['to']    = $tmp['cn'];
118     }
119   
120     $tmp['dn']      = $this->dn;  
121     $tmp['status']  = $this->status;  
122     return($tmp);
123   }
125   /* Return plugin informations for acl handling */
126   static function plInfo()
127   {
128     return (array(
129           "plShortName" => _("Variable entry"),
130           "plDescription" => _("FAI variable entry "),
131           "plSelfModify"  => FALSE,
132           "plDepends"     => array(),
133           "plPriority"    => 23,
134           "plSection"     => array("administration"),
135           "plCategory"    => array("fai"),
136           "plProvidedAcls" => array(
137             "cn"                => _("Name"),
138             "description"       => _("Description"),
139             "FAIvariableContent"=> _("Variable content") )
140           ));
141   }
145 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
146 ?>