Code

Added execute methods
[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("cn","description","FAIscript","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 $dn            = "";
20   var $cn            = "";
21   var $FAItask       = "";
22   var $FAIscript     = "";
23   var $description   = "";
24   var $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 = $name;
34         $this->$oname=$value;
35       }
36     }else{
37       $this->status = "new";
38       $this->orig_cn       = false;
39     }
40   }
43   function execute()
44   {
45         /* Call parent execute */
46         plugin::execute();
47     /* Fill templating stuff */
48     $smarty     = get_smarty();
49     $display = "";
50         
51     if(isset($_POST['ImportUpload'])){
52       if(($_FILES['ImportFile']['error']!=0)){
53         print_red(_("Please select a valid file."));
54       }else
55       if(($_FILES['ImportFile']['size']==0)){
56         print_red(_("Selected file is empty."));
57       }else{
58         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
59         $this->FAIscript = $str;
60       }
61     }
62     $smarty->assign("tasks", $this->tasks);
64      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
65      * If we post the escaped strings they will be escaped again
66      */
67     foreach($this->attributes as $attrs){
68       if(get_magic_quotes_gpc()){
69         $smarty->assign($attrs,stripslashes($this->$attrs));
70       }else{
71         $smarty->assign($attrs,($this->$attrs));
72       }
73     }
75     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
76     return($display);
77   }
79   /* Save data to object */
80   function save_object()
81   {
82     if(isset($_POST['SubObjectFormSubmitted'])){
83       foreach($this->attributes as $attrs){
84         if(isset($_POST[$attrs])){
85           $this->$attrs = $_POST[$attrs];
86         }else{
87           $this->$attrs = "";
88         }
89       }
90       $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
91     }
92   }
94   /* Check supplied data */
95   function check()
96   {
97     $message= array();
98     if(empty($this->FAIscript)) {
99       $message[]=_("Please enter a value for script.");
100     }
102     if(empty($this->cn)){
103       $message[] = _("Please enter a name.");
104     }
106     return ($message);
107   }
108  
109   function save()
110   {
111     $tmp=array();
112     foreach($this->attributes as $attrs){ 
113       $tmp[$attrs] = $this->$attrs;
114     }
116     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
117       $tmp['remove']['from']  = $this->orig_cn;
118       $tmp['remove']['to']    = $tmp['cn'];
119     }
120   
121     $tmp['dn']      = $this->dn;  
122     $tmp['status']  = $this->status;  
123     return($tmp);
124   }
126 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
127 ?>