Code

Added pre coded tasks
[gosa.git] / plugins / admin / fai / class_faiHookEntry.inc
1 <?php
3 class faiHookEntry 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_FAIscript","Object_FAItask");
13   var $objectclasses= array();
15   var $orig_cn              = "";
16   var $tasks                = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish",
17                                     "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt",
18                                     "savelog", "softupdate", "sysinfo"," updatebase");
19   var $Object_dn            = "";
20   var $Object_cn            = "";
21   var $Object_FAItask       = "";
22   var $Object_FAIscript     = "";
23   var $Object_description   = "";
24   var $Object_status        = "new";
25   
26   function faiHookEntry ($config, $dn= NULL,$object=false)
27   {
28     plugin::plugin ($config, $dn);
29     if($dn != "new"){
30       $this->orig_cn= $object['cn'];
31       $this->dn=$object['dn'];
32       foreach($object as $name=>$value){
33         $oname = "Object_".$name;
34         $this->$oname=$value;
35       }
36     }else{
37       $this->Object_status = "new";
38       $this->orig_cn       = false;
39     }
40   }
43   function execute()
44   {
45     /* Fill templating stuff */
46     $smarty     = get_smarty();
47     $display = "";
48         
49     if(isset($_POST['ImportUpload'])){
50       if(($_FILES['ImportFile']['error']!=0)){
51         print_red(_("Please select a valid file."));
52       }else
53       if(($_FILES['ImportFile']['size']==0)){
54         print_red(_("Selected file is empty."));
55       }else{
56         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
57         $this->Object_FAIscript = $str;
58       }
59     }
60     $smarty->assign("tasks", $this->tasks);
62      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
63      * If we post the escaped strings they will be escaped again
64      */
65     foreach($this->attributes as $attrs){
66       if(get_magic_quotes_gpc()){
67         $smarty->assign($attrs,stripslashes($this->$attrs));
68       }else{
69         $smarty->assign($attrs,($this->$attrs));
70       }
71     }
73     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
74     return($display);
75   }
77   /* Save data to object */
78   function save_object()
79   {
80     if(isset($_POST['SubObjectFormSubmitted'])){
81       foreach($this->attributes as $attrs){
82         if(isset($_POST[$attrs])){
83           $this->$attrs = $_POST[$attrs];
84         }else{
85           $this->$attrs = "";
86         }
87       }
88     }
89   }
91   /* Check supplied data */
92   function check()
93   {
94     $message= array();
95     if(empty($this->Object_FAIscript)) {
96       $message[]=_("Please enter a value for script.");
97     }
99     if(empty($this->Object_cn)){
100       $message[] = _("Please enter a name.");
101     }
103     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
104       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
105     }
106   
107     return ($message);
108   }
109  
110   function save()
111   {
112     $tmp=array();
113     foreach($this->attributes as $attrs){ 
114       $attr = preg_replace("/^Object_/","",$attrs);
115       $tmp[$attr] = $this->$attrs;
116     }
118     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
119       $tmp['remove']['from']  = $this->orig_cn;
120       $tmp['remove']['to']    = $tmp['cn'];
121     }
122   
123     $tmp['dn']      = $this->dn;  
124     $tmp['status']  = $this->Object_status;  
125     return($tmp);
126   }
128 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
129 ?>