Code

Grey out, don't hide
[gosa.git] / plugins / 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       }
30       if(isset($this->attrs['FAIstate'][0])){
31         $this->FAIstate = $this->attrs['FAIstate'][0];
32       }
34     }else{
35       $this->status = "new";
36       $this->orig_cn       = false;
37     }
38   }
40   function execute()
41   {
42         /* Call parent execute */
43         plugin::execute();
45     /* Fill templating stuff */
46     $smarty     = get_smarty();
47     $display = "";
49      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
50      * If we post the escaped strings they will be escaped again
51      */
52     foreach($this->attributes as $attrs){
53       if(get_magic_quotes_gpc()){
54         $smarty->assign($attrs,htmlentities (stripslashes(utf8_decode($this->$attrs))));
55       }else{
56         $smarty->assign($attrs,htmlentities (utf8_decode($this->$attrs)));
57       }
58     }
60     foreach($this->attributes as $attr){
61       if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
62         $smarty->assign($attr."ACL"," disabled ");
63       }else{
64         $smarty->assign($attr."ACL","  ");
65       }
66     }
68     $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
69     return($display);
70   }
72   /* Save data to object */
73   function save_object()
74   {
75     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
76       foreach($this->attributes as $attrs){
77         if(isset($_POST[$attrs])){
78           $this->$attrs = $_POST[$attrs];
79         }else{
80           $this->$attrs = "";
81         }
82       }
83     }
84   }
86   /* Check supplied data */
87   function check()
88   {
89     /* Call common method to give check the hook */
90     $message= plugin::check();
92     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
93       $message[] =_("There is already a variable with the given name.");
94     }
95     
96     if(empty($this->FAIvariableContent)) {
97       $message[]=_("Please specify a value for the attribute 'content'."); 
98     }
99    
100     if(empty($this->cn)){
101       $message[] = _("Please enter a name.");
102     }
104     return ($message);
105   }
106  
107   function save()
108   {
109     $tmp=array();
110     foreach($this->attributes as $attrs){ 
111       $tmp[$attrs] = stripslashes( $this->$attrs);
112     }
114     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
115       $tmp['remove']['from']  = $this->orig_cn;
116       $tmp['remove']['to']    = $tmp['cn'];
117     }
118   
119     $tmp['dn']      = $this->dn;  
120     $tmp['status']  = $this->status;  
121     return($tmp);
122   }
124 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
125 ?>