Code

a3096f17339dda451121671f50826e482b45b652
[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     foreach($this->attributes as $attrs){
60       $smarty->assign($attrs,stripslashes($this->$attrs));
61     }
63     $smarty->assign("Object_FAItemplateFile","");
64   
65     for($i =1 ; $i <= 100 ; $i++){
66       $Object_FAIprioritys[$i]=$i;
67     }
68     $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
69     $display.= $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
70     return($display);
71   }
73   /* Save data to object */
74   function save_object()
75   {
76     if(isset($_POST['SubObjectFormSubmitted'])){
77       foreach($this->attributes as $attrs){
78         if($attrs == "Object_FAItemplateFile") continue;
79         if(isset($_POST[$attrs])){
80           $this->$attrs = $_POST[$attrs];
81         }else{
82           $this->$attrs = "";
83         }
84       }
85     }
86   }
88   /* Check supplied data */
89   function check()
90   {
91     $message= array();
92     if(empty($this->Object_FAItemplateFile)){
93       $message[]=_("Please specify a value for attribute 'file'.");
94     } 
96     if(empty($this->Object_FAItemplatePath)){
97       $message[]=_("Please specify a value for attribute 'path'.");
98     } 
99   
100     $str = utf8_encode("üöä");
102     if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
103       $message[] = _("Invalid character in description. Please enter a valid description.");
104     }
106     if(empty($this->Object_cn)){
107       $message[] = _("Please enter a name.");
108     }
110     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
111       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
112     }
113     return ($message);
114   }
115  
116   function save()
117   {
118     $tmp=array();
119     foreach($this->attributes as $attrs){ 
120       $attr = preg_replace("/^Object_/","",$attrs);
121       $tmp[$attr] = $this->$attrs;
122     }
124     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
125       $tmp['remove']['from']  = $this->orig_cn;
126       $tmp['remove']['to']    = $tmp['cn'];
127     }
128   
129     $tmp['dn']      = $this->dn;  
130     $tmp['status']  = $this->Object_status;  
132     return($tmp);
133   }
135 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
136 ?>