Code

Updated copy & paste
[gosa.git] / 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       }
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     $tmp = $this->plInfo();
61     foreach($tmp['plProvidedAcls'] as $name => $translated){
62       $acl = $this->getacl($name);
63       if($this->FAIstate == "freezed"){
64         $acl = preg_replace("/w/","",$acl);
65       }
66       $smarty->assign($name."ACL",$acl);
67     }
71     $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
72     return($display);
73   }
75   /* Save data to object */
76   function save_object()
77   {
78      if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
79       foreach($this->attributes as $attrs){
80         if($this->acl_is_writeable($attrs)){
81           if(isset($_POST[$attrs])){
82             $this->$attrs = $_POST[$attrs];
83           }else{
84             $this->$attrs = "";
85           }
86         }
87       }
88     }
89   }
91   /* Check supplied data */
92   function check()
93   {
94     /* Call common method to give check the hook */
95     $message= plugin::check();
97     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
98       $message[] =_("There is already a variable with the given name.");
99     }
100     
101     if(empty($this->FAIvariableContent)) {
102       $message[]=_("Please specify a value for the attribute 'content'."); 
103     }
104    
105     if(empty($this->cn)){
106       $message[] = _("Please enter a name.");
107     }
109     return ($message);
110   }
111  
112   function save()
113   {
114     $tmp=array();
115     foreach($this->attributes as $attrs){ 
116       $tmp[$attrs] = stripslashes( $this->$attrs);
117     }
119     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
120       $tmp['remove']['from']  = $this->orig_cn;
121       $tmp['remove']['to']    = $tmp['cn'];
122     }
123   
124     $tmp['dn']      = $this->dn;  
125     $tmp['status']  = $this->status;  
126     return($tmp);
127   }
129   /* Return plugin informations for acl handling */
130   static function plInfo()
131   {
132     return (array(
133           "plShortName" => _("Variable entry"),
134           "plDescription" => _("FAI variable entry "),
135           "plSelfModify"  => FALSE,
136           "plDepends"     => array(),
137           "plPriority"    => 23,
138           "plSection"     => array("administration"),
139           "plCategory"    => array("fai"),
140           "plProvidedAcls" => array(
141             "cn"                => _("Name"),
142             "description"       => _("Description"),
143             "FAIvariableContent"=> _("Variable content") )
144           ));
145   }
149 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
150 ?>