Code

Updated list summary, using images instead of object names
[gosa.git] / plugins / admin / fai / class_faiHookEntry.inc
1 <?php
3 class faiHookEntry extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes   = array("cn","description","FAIscript","FAItask");
8   var $objectclasses= array();
10   var $orig_cn              = "";
11   var $tasks                = array("chboot", "configure", "debconf", "extrbase", "faiend", "finish",
12                                     "install", "instsoft", "mirror", "mountdisks", "partition", "prepareapt",
13                                     "savelog", "softupdate", "sysinfo","updatebase");
14   var $dn            = "";
15   var $cn            = "";
16   var $FAItask       = "";
17   var $FAIscript     = "";
18   var $description   = "";
19   var $status        = "new";
20   var $parent        = NULL;
21   var $FAIstate      = "";
22   
23   function faiHookEntry ($config, $dn= NULL,$object=false)
24   {
25     plugin::plugin ($config, $dn);
26     if($dn != "new"){
27       $this->orig_cn= $object['cn'];
28       $this->dn=$object['dn'];
29       foreach($object as $name=>$value){
30         $oname = $name;
31         $this->$oname=$value;
32       }
34       if(isset($this->attrs['FAIstate'][0])){
35         $this->FAIstate = $this->attrs['FAIstate'][0];
36       }
38     }elseif(is_array($object)){
39       if(count($object)){
40         $this->orig_cn= $object['cn'];
41         $this->dn=$object['dn'];
42         foreach($object as $name=>$value){
43           $oname = $name;
44           $this->$oname=$value;
45         }
46       }else{
48         $this->status = "new";
49         $this->orig_cn       = false;
50       }
51     }
52   }
55   function execute()
56   {
57         /* Call parent execute */
58         plugin::execute();
60     /* Fill templating stuff */
61     $smarty     = get_smarty();
62     $display = "";
63         
64     if(isset($_POST['ImportUpload'])){
65       if(($_FILES['ImportFile']['error']!=0)){
66         print_red(_("Please select a valid file."));
67       }else
68       if(($_FILES['ImportFile']['size']==0)){
69         print_red(_("Selected file is empty."));
70       }else{
71         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
72         $this->FAIscript = $str;
73       }
74     }
76     /* Create download button*/
77     if($this->dn != "new"){
78       $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
79         <input type='button' value='"._("Download")."'>
80         </a>");
81     }else{
82       $smarty->assign("DownMe","");  
83     }
85     $used_tasks = $this->parent->getUsedFAItask($this->cn);
86     $tasks = $this->tasks;
87     foreach($this->tasks as $id => $task){
88       if(in_array($task,$used_tasks)){
89         unset($tasks[$id]);
90       }
91     }
92     $smarty->assign("tasks", $tasks);
94      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
95      * If we post the escaped strings they will be escaped again
96      */
97     foreach($this->attributes as $attrs){
98       if(get_magic_quotes_gpc()){
99         $smarty->assign($attrs,stripslashes($this->$attrs));
100       }else{
101         $smarty->assign($attrs,$this->$attrs);
102       }
103     }
105     foreach($this->attributes as $attr){
106       if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
107         $smarty->assign($attr."ACL"," disabled ");
108       }else{
109         $smarty->assign($attr."ACL","  ");
110       }
111     }
113     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
114     return($display);
115   }
117   /* Save data to object */
118   function save_object()
119   {
120     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
121       foreach($this->attributes as $attrs){
122         if(isset($_POST[$attrs])){
123           $this->$attrs = $_POST[$attrs];
124         }else{
125           $this->$attrs = "";
126         }
127       }
128     }
129   }
131   /* Check supplied data */
132   function check()
133   {
134     /* Call common method to give check the hook */
135     $message= plugin::check();
137     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
138       $message[] =_("There is already a hook with the given name.");
139     }
141     if(empty($this->FAIscript)) {
142       $message[]=_("Please enter a value for script.");
143     }
145     if(empty($this->cn)){
146       $message[] = _("Please enter a name.");
147     }
149     return ($message);
150   }
151  
152   function save()
153   {
154     $tmp=array();
155     foreach($this->attributes as $attrs){ 
156       $tmp[$attrs] = $this->$attrs;
157     }
159     /* Strip out dos newlines */
160     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
162     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
163       $tmp['remove']['from']  = $this->orig_cn;
164       $tmp['remove']['to']    = $tmp['cn'];
165     }
166   
167     $tmp['dn']      = $this->dn;  
168     $tmp['status']  = $this->status;  
169     return($tmp);
170   }
172 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
173 ?>