Code

Updated fai Packages
[gosa.git] / gosa-plugins / fai / admin / fai / class_faiScriptEntry.inc
1 <?php
3 class faiScriptEntry extends plugin
4 {
5   /* attribute list for save action */
6   var $ignore_account= TRUE;
7   var $attributes   = array("cn","description","FAIpriority","FAIscript");
8   var $objectclasses= array();
10   var $orig_cn              = "";
12   var $dn            = "";
13   var $cn            = "";
14   var $FAIpriority   = "0";
15   var $FAIscript     = "";
16   var $description   = "";
17   var $status        = "new";
18   var $parent        = NULL;
19   var $FAIstate      = "";
20   
21   function faiScriptEntry (&$config, $dn= NULL,$object=false)
22   {
23     plugin::plugin ($config, $dn);
24     if($dn != "new"){
25       $this->orig_cn= $object['cn'];
26       $this->dn=$object['dn'];
27       foreach($object as $name=>$value){
28         $oname = $name;
29         $this->$oname=$value;
30       }
32       if(isset($this->attrs['FAIstate'][0])){
33         $this->FAIstate = $this->attrs['FAIstate'][0];
34       }
36     }else{
37       if(is_array($object)&&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   }
52   function execute()
53   {
54     /* Call parent execute */
55     plugin::execute();
57     /* Fill templating stuff */
58     $smarty     = get_smarty();
59     $display = "";
60   
61     if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
62       if(($_FILES['ImportFile']['error']!=0)){
63         msg_dialog::display(_("Error"), _("Upload failed!"), ERROR_DIALOG);
64       }else
65       if(($_FILES['ImportFile']['size']==0)){
66         msg_dialog::display(_("Error"), _("Uploaded file is empty!"), ERROR_DIALOG);
67       }else{
68         $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
69         $this->FAIscript = $str;
70       }
71     }
72   
73      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
74      * If we post the escaped strings they will be escaped again
75      */
76     foreach($this->attributes as $attrs){
77       if(get_magic_quotes_gpc()){
78         $smarty->assign($attrs,(stripslashes($this->$attrs)));
79       }else{
80         $smarty->assign($attrs,($this->$attrs));
81       }
82     }
84     /* File download requested */
85     if(isset($_GET['getFAIScript'])){
86       send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIscript");
87     }
89     /* Create download button*/
90     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
91       $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIScript'>
92         <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
93         </a>");
94     }else{
95       $smarty->assign("DownMe","");
96     }
98     for($i =0 ; $i < 100 ; $i++){
99       $FAIprioritys[$i]=$i;
100     }
102     $tmp = $this->plInfo();
103     foreach($tmp['plProvidedAcls'] as $name => $translated){
104       $acl = $this->getacl($name);
105       if($this->FAIstate == "freezed"){
106         $acl = preg_replace("/w/","",$acl);
107       }
108       $smarty->assign($name."ACL",$acl);
109     }
111     if(get_magic_quotes_gpc()){
112       $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
113     }else{
114       $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
115     }
116     $smarty->assign("FAIprioritys",$FAIprioritys);
117     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
118     return($display);
119   }
121   /* Save data to object */
122   function save_object()
123   {
124     if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
125       foreach($this->attributes as $attrs){
126         if($this->acl_is_writeable($attrs)){
127           if(isset($_POST[$attrs])){
128             $this->$attrs = $_POST[$attrs];
129           }else{
130             $this->$attrs = "";
131           }
132         }
133       }
134     }
135   }
137   /* Check supplied data */
138   function check()
139   {
140     /* Call common method to give check the hook */
141     $message= plugin::check();
142   
143     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
144       $message[] = msgPool::duplicated(_("Name"));
145     }
147     if(empty($this->cn)){
148       $message[] = msgPool::required(_("Name"));
149     }
151     if(empty($this->FAIscript)){
152       $message[]= msgPool::required(_("Script"));
153     }
155     return ($message);
156   }
157  
158   function save()
159   {
160     $tmp=array();
161     foreach($this->attributes as $attrs){ 
162       $tmp[$attrs] = $this->$attrs;
163     }
165     /* Strip out dos newlines */
166     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
168     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
169       $tmp['remove']['from']  = $this->orig_cn;
170       $tmp['remove']['to']    = $tmp['cn'];
171     }
172   
173     $tmp['dn']      = $this->dn;  
174     $tmp['status']  = $this->status; 
175     return($tmp);
176   }
178   
179   /* Return plugin informations for acl handling */
180   static function plInfo()
181   {
182     return (array(
183           "plShortName" => _("Script entry"),
184           "plDescription" => _("FAI script entry"),
185           "plSelfModify"  => FALSE,
186           "plDepends"     => array(),
187           "plPriority"    => 19,
188           "plSection"     => array("administration"),
189           "plCategory"    => array("fai"),
190           "plProvidedAcls" => array(
191             "cn"              => _("Name"),
192             "description"     => _("Description"),
193             "FAIscript"       => _("Script entry"),
194             "FAIpriority"     => _("Script Priority"))
195           ));
196   }
200 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
201 ?>