Code

Fixed DOS newline handling
[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       if(count($object)){
38         $this->orig_cn= $object['cn'];
39         $this->dn=$object['dn'];
40         foreach($object as $name=>$value){
41           $oname = $name;
42           $this->$oname=$value;
43         }
44       }else{
46         $this->status = "new";
47         $this->orig_cn       = false;
48       }
49     }
50   }
53   function execute()
54   {
55         /* Call parent execute */
56         plugin::execute();
58     /* Fill templating stuff */
59     $smarty     = get_smarty();
60     $display = "";
61         
62     if(isset($_POST['ImportUpload'])){
63       if(($_FILES['ImportFile']['error']!=0)){
64         print_red(_("Please select a valid file."));
65       }else
66       if(($_FILES['ImportFile']['size']==0)){
67         print_red(_("Selected file is empty."));
68       }else{
69         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
70         $this->FAIscript = $str;
71       }
72     }
74     $used_tasks = $this->parent->getUsedFAItask($this->cn);
75     $tasks = $this->tasks;
76     foreach($this->tasks as $id => $task){
77       if(in_array($task,$used_tasks)){
78         unset($tasks[$id]);
79       }
80     }
81     $smarty->assign("tasks", $tasks);
83      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
84      * If we post the escaped strings they will be escaped again
85      */
86     foreach($this->attributes as $attrs){
87       if(get_magic_quotes_gpc()){
88         $smarty->assign($attrs,htmlentities(stripslashes($this->$attrs)));
89       }else{
90         $smarty->assign($attrs,htmlentities($this->$attrs));
91       }
92     }
94     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
95     return($display);
96   }
98   /* Save data to object */
99   function save_object()
100   {
101     if(isset($_POST['SubObjectFormSubmitted'])){
102       foreach($this->attributes as $attrs){
103         if(isset($_POST[$attrs])){
104           $this->$attrs = $_POST[$attrs];
105         }else{
106           $this->$attrs = "";
107         }
108       }
109     }
110   }
112   /* Check supplied data */
113   function check()
114   {
115     $message= array();
116     if(empty($this->FAIscript)) {
117       $message[]=_("Please enter a value for script.");
118     }
120     if(empty($this->cn)){
121       $message[] = _("Please enter a name.");
122     }
124     return ($message);
125   }
126  
127   function save()
128   {
129     $tmp=array();
130     foreach($this->attributes as $attrs){ 
131       $tmp[$attrs] = $this->$attrs;
132     }
134     /* Strip out dos newlines */
135     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
137     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
138       $tmp['remove']['from']  = $this->orig_cn;
139       $tmp['remove']['to']    = $tmp['cn'];
140     }
141   
142     $tmp['dn']      = $this->dn;  
143     $tmp['status']  = $this->status;  
144     return($tmp);
145   }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>