Code

this should do it.
[gosa.git] / plugins / admin / fai / class_faiVariableEntry.inc
1 <?php
3 class faiVariableEntry extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage server basic objects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   /* attribute list for save action */
11   var $ignore_account= TRUE;
12   var $attributes   = array("cn","description","FAIvariableContent");
13   var $objectclasses= array();
15   var $orig_cn              = "";
16   var $dn            = "";
17   var $cn            = "";
18   var $FAIvariableContent   = "";
19   var $description   = "";
20   var $status        = "new";
21   
22   function faiVariableEntry ($config, $dn= NULL,$object=false)
23   {
24     plugin::plugin ($config, $dn);
25     if($dn != "new"){
26       $this->orig_cn= $object['cn'];
27       $this->dn=$object['dn'];
28       foreach($object as $name=>$value){
29         $oname = $name;
30         $this->$oname=addslashes($value);
31       }
32     }else{
33       $this->status = "new";
34       $this->orig_cn       = false;
35     }
36   }
38   function execute()
39   {
40         /* Call parent execute */
41         plugin::execute();
43     /* Fill templating stuff */
44     $smarty     = get_smarty();
45     $display = "";
47      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
48      * If we post the escaped strings they will be escaped again
49      */
50     foreach($this->attributes as $attrs){
51       if(get_magic_quotes_gpc()){
52         $smarty->assign($attrs,htmlentities (stripslashes($this->$attrs)));
53       }else{
54         $smarty->assign($attrs,htmlentities (($this->$attrs)));
55       }
56     }
58     $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
59     return($display);
60   }
62   /* Save data to object */
63   function save_object()
64   {
65     if(isset($_POST['SubObjectFormSubmitted'])){
66       foreach($this->attributes as $attrs){
67         if(isset($_POST[$attrs])){
68           $this->$attrs = $_POST[$attrs];
69         }else{
70           $this->$attrs = "";
71         }
72       }
73     }
74   }
76   /* Check supplied data */
77   function check()
78   {
79     $message= array();
80     
81     if(empty($this->FAIvariableContent)) {
82       $message[]=_("Please specify a value for the attribute 'content'."); 
83     }
84    
85     if(empty($this->cn)){
86       $message[] = _("Please enter a name.");
87     }
89     return ($message);
90   }
91  
92   function save()
93   {
94     $tmp=array();
95     foreach($this->attributes as $attrs){ 
96       $tmp[$attrs] = stripslashes( $this->$attrs);
97     }
99     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
100       $tmp['remove']['from']  = $this->orig_cn;
101       $tmp['remove']['to']    = $tmp['cn'];
102     }
103   
104     $tmp['dn']      = $this->dn;  
105     $tmp['status']  = $this->status;  
106     return($tmp);
107   }
109 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
110 ?>