Code

Added a first set of reference changes - nearly untested
[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       = "chboot";
22   var $FAIscript     = "";
23   var $description   = "";
24   var $status        = "new";
25   var $parent        = NULL;
26   var $FAIstate      = "";
27   
28   function faiHookEntry (&$config, $dn= NULL,$object=false)
29   {
30     plugin::plugin ($config, $dn);
31     if($dn != "new"){
32       $this->orig_cn= $object['cn'];
33       $this->dn=$object['dn'];
34       foreach($object as $name=>$value){
35         $oname = $name;
36         $this->$oname=$value;
37       }
39       if(isset($this->attrs['FAIstate'][0])){
40         $this->FAIstate = $this->attrs['FAIstate'][0];
41       }
43     }elseif(is_array($object)){
44       if(count($object)){
45         $this->orig_cn= $object['cn'];
46         $this->dn=$object['dn'];
47         foreach($object as $name=>$value){
48           $oname = $name;
49           $this->$oname=$value;
50         }
51       }else{
53         $this->status = "new";
54         $this->orig_cn       = false;
55       }
56     }
57   }
60   function execute()
61   {
62         /* Call parent execute */
63         plugin::execute();
65     /* Fill templating stuff */
66     $smarty     = get_smarty();
67     $display = "";
68         
69     if(isset($_POST['ImportUpload'])){
70       if(($_FILES['ImportFile']['error']!=0)){
71         print_red(_("Please select a valid file."));
72       }else
73       if(($_FILES['ImportFile']['size']==0)){
74         print_red(_("Selected file is empty."));
75       }else{
76         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
77         $this->FAIscript = $str;
78       }
79     }
81     /* Create download button*/
82     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
83       $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
84           <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
85         </a>");
86     }else{
87       $smarty->assign("DownMe","");  
88     }
90     $used_tasks = $this->parent->getUsedFAItask($this->cn);
91     $tasks = $this->tasks;
92     foreach($this->tasks as $id => $task){
93       if(in_array($task,$used_tasks)){
94         unset($tasks[$id]);
95       }
96     }
97     $smarty->assign("tasks", $tasks);
99      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
100      * If we post the escaped strings they will be escaped again
101      */
102     foreach($this->attributes as $attrs){
103       if(get_magic_quotes_gpc()){
104         $smarty->assign($attrs,(stripslashes($this->$attrs)));
105       }else{
106         $smarty->assign($attrs,($this->$attrs));
107       }
108     }
110     $tmp = $this->plInfo();
111     foreach($tmp['plProvidedAcls'] as $name => $translated){
112       $acl = $this->getacl($name);
113       if($this->FAIstate == "freezed"){
114         $acl = preg_replace("/w/","",$acl);
115       }
116       $smarty->assign($name."ACL",$acl);
117     }
119     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
120     return($display);
121   }
123   /* Save data to object */
124   function save_object()
125   {
126     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
127       foreach($this->attributes as $attrs){
128         if($this->acl_is_writeable($attrs)){
129           if(isset($_POST[$attrs])){
130             $this->$attrs = $_POST[$attrs];
131           }else{
132             $this->$attrs = "";
133           }
134         }
135       }
136     }
137   }
139   /* Check supplied data */
140   function check()
141   {
142     /* Call common method to give check the hook */
143     $message= plugin::check();
145     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
146       $message[] =_("There is already a hook with the given name.");
147     }
149     if(empty($this->FAIscript)) {
150       $message[]=_("Please enter a value for script.");
151     }
153     if(empty($this->cn)){
154       $message[] = _("Please enter a name.");
155     }
157     return ($message);
158   }
159  
160   function save()
161   {
162     $tmp=array();
163     foreach($this->attributes as $attrs){ 
164       $tmp[$attrs] = $this->$attrs;
165     }
167     /* Strip out dos newlines */
168     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
170     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
171       $tmp['remove']['from']  = $this->orig_cn;
172       $tmp['remove']['to']    = $tmp['cn'];
173     }
174   
175     $tmp['dn']      = $this->dn;  
176     $tmp['status']  = $this->status;  
177     return($tmp);
178   }
180     /* Return plugin informations for acl handling */
181   function plInfo()
182   {
183     return (array(
184           "plShortName" => _("Hook entry"),
185           "plDescription" => _("FAI hook entry"),
186           "plSelfModify"  => FALSE,
187           "plDepends"     => array(),
188           "plPriority"    => 21,
189           "plSection"     => array("administration"),
190           "plCategory"    => array("fai"),
191           "plProvidedAcls" => array(
192             "cn"                => _("Name"),
193             "description"       => _("Description"),
194             "FAItask"           => _("Task"),
195             "FAIscript"         => _("FAI script"))
196           ));
197   }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>