Code

If we use stripslashes to display, we should use addslahes at construction.
[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("Object_cn","Object_description","Object_FAIvariableContent");
13   var $objectclasses= array();
15   var $orig_cn              = "";
16   var $Object_dn            = "";
17   var $Object_cn            = "";
18   var $Object_FAIvariableContent   = "";
19   var $Object_description   = "";
20   var $Object_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 = "Object_".$name;
30         $this->$oname=addslashes($value);
31       }
32     }else{
33       $this->Object_status = "new";
34       $this->orig_cn       = false;
35     }
36   }
38   function execute()
39   {
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($this->$attrs)));
50       }else{
51         $smarty->assign($attrs,htmlentities (($this->$attrs)));
52       }
53     }
55     $display.= $smarty->fetch(get_template_path('faiVariableEntry.tpl', TRUE));
56     return($display);
57   }
59   /* Save data to object */
60   function save_object()
61   {
62     if(isset($_POST['SubObjectFormSubmitted'])){
63       foreach($this->attributes as $attrs){
64         if(isset($_POST[$attrs])){
65           $this->$attrs = $_POST[$attrs];
66         }else{
67           $this->$attrs = "";
68         }
69       }
70     }
71   }
73   /* Check supplied data */
74   function check()
75   {
76     $message= array();
77     
78     if(empty($this->Object_FAIvariableContent)) {
79       $message[]=_("Please specify a value for the attribute 'content'."); 
80     }
81    
82     if(empty($this->Object_cn)){
83       $message[] = _("Please enter a name.");
84     }
86     if(preg_match("/[^0-9a-z_]/i",$this->Object_cn)){
87       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
88     }
89  
90     return ($message);
91   }
92  
93   function save()
94   {
95     $tmp=array();
96     foreach($this->attributes as $attrs){ 
97       $attr = preg_replace("/^Object_/","",$attrs);
98       $tmp[$attr] = stripslashes( $this->$attrs);
99     }
101     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
102       $tmp['remove']['from']  = $this->orig_cn;
103       $tmp['remove']['to']    = $tmp['cn'];
104     }
105   
106     $tmp['dn']      = $this->dn;  
107     $tmp['status']  = $this->Object_status;  
108     return($tmp);
109   }
111 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
112 ?>