Code

Fixed magic_quotes_gpc escaping in faiTemplate faiTemplateEntry faiScript faiScriptEntry
[gosa.git] / plugins / admin / fai / class_faiTemplateEntry.inc
1 <?php
3 class faiTemplateEntry 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_FAItemplateFile","Object_FAItemplatePath");
13   var $objectclasses= array();
15   var $orig_cn              = "";
17   var $Object_dn            = "";
18   var $Object_cn            = "";
19   var $Object_FAItemplateFile   = "";
20   var $Object_FAItemplatePath   = "";
21   var $Object_description   = "";
22   var $Object_status        = "new";
23   
24   function faiTemplateEntry ($config, $dn= NULL,$object=false)
25   {
26     plugin::plugin ($config, $dn);
27     if($dn != "new"){
28       $this->orig_cn= $object['cn'];
29       $this->dn=$object['dn'];
30       foreach($object as $name=>$value){
31         $oname = "Object_".$name;
32         $this->$oname=$value;
33       }
34     }else{
35       $this->Object_status = "new";
36       $this->orig_cn       = false;
37     }
38   }
40   function execute()
41   {
42     /* Fill templating stuff */
43     $smarty     = get_smarty();
44     $display = "";
46     if(isset($_POST['TmpFileUpload'])){
47       if($str=file_get_contents($_FILES['FAItemplateFile']['tmp_name'])){
48         $this->Object_FAItemplateFile = $str;
49       }
50     
51     }
52     
53     $status="<br>"._("No file uploaded");
54     if(strlen($this->Object_FAItemplateFile)){
55       $status="<br>".sprintf(_("File uploaded, size : %s byte"),strlen($this->Object_FAItemplateFile));
56     }
57     $smarty->assign("status",$status);
59     /* Magic quotes GPC, escapes every ' " \, to solve some security risks 
60      * If we post the escaped strings they will be escaped again
61      */
62     foreach($this->attributes as $attrs){
63       if(get_magic_quotes_gpc()){
64         $smarty->assign($attrs,stripslashes($this->$attrs));
65       }else{
66         $smarty->assign($attrs,($this->$attrs));
67       }
68     }
70     $smarty->assign("Object_FAItemplateFile","");
72     for($i =1 ; $i <= 100 ; $i++){
73       $Object_FAIprioritys[$i]=$i;
74     }
75     $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
76     $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
77     return($display);
78   }
80   /* Save data to object */
81   function save_object()
82   {
83     if(isset($_POST['SubObjectFormSubmitted'])){
84       foreach($this->attributes as $attrs){
85         if($attrs == "Object_FAItemplateFile") continue;
86         if(isset($_POST[$attrs])){
87           $this->$attrs = $_POST[$attrs];
88         }else{
89           $this->$attrs = "";
90         }
91       }
92     }
93   }
95   /* Check supplied data */
96   function check()
97   {
98     $message= array();
99     if(empty($this->Object_FAItemplateFile)){
100       $message[]=_("Please specify a value for attribute 'file'.");
101     } 
103     if(empty($this->Object_FAItemplatePath)){
104       $message[]=_("Please specify a value for attribute 'path'.");
105     } 
106   
107     if(empty($this->Object_cn)){
108       $message[] = _("Please enter a name.");
109     }
111     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
112       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
113     }
114     return ($message);
115   }
116  
117   function save()
118   {
119     $tmp=array();
120     foreach($this->attributes as $attrs){ 
121       $attr = preg_replace("/^Object_/","",$attrs);
122       $tmp[$attr] = $this->$attrs;
123     }
125     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
126       $tmp['remove']['from']  = $this->orig_cn;
127       $tmp['remove']['to']    = $tmp['cn'];
128     }
129   
130     $tmp['dn']      = $this->dn;  
131     $tmp['status']  = $this->Object_status;  
133     return($tmp);
134   }
136 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
137 ?>