Code

Updated templates
[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, NULL);
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       }
31     }else{
32       if(is_array($object)&&count($object)){
33         $this->orig_cn= $object['cn'];
34         $this->dn=$object['dn'];
35         foreach($object as $name=>$value){
36           $oname = $name;
37           $this->$oname=$value;
38         }
39       }else{
41         $this->status = "new";
42         $this->orig_cn       = false;
43       }
44     }
45   }
47   function execute()
48   {
49     /* Call parent execute */
50     plugin::execute();
52     /* Fill templating stuff */
53     $smarty     = get_smarty();
54     $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate));
55     $display = "";
56   
57     if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
58       if(($_FILES['ImportFile']['error']!=0)){
59         msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
60       }else
61       if(($_FILES['ImportFile']['size']==0)){
62         msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
63       }else{
64         $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
65         $this->FAIscript = $str;
66       }
67     }
68   
69      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
70      * If we post the escaped strings they will be escaped again
71      */
72     foreach($this->attributes as $attrs){
73       if(get_magic_quotes_gpc()){
74         $smarty->assign($attrs,(stripslashes($this->$attrs)));
75       }else{
76         $smarty->assign($attrs,($this->$attrs));
77       }
78     }
80     /* File download requested */
81     if(isset($_POST['download'])){
82       send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIscript");
83     }
85     /* Create download button*/
86     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
87       $smarty->assign("DownMe", image('images/save.png','download',_("Download")));
88     }else{
89       $smarty->assign("DownMe","");
90     }
92     for($i =0 ; $i < 100 ; $i++){
93       $FAIprioritys[$i]=$i;
94     }
96     $tmp = $this->plInfo();
97     foreach($tmp['plProvidedAcls'] as $name => $translated){
98       $acl = $this->getacl($name,preg_match("/freeze/i",$this->FAIstate));
99       $smarty->assign($name."ACL",$acl);
100     }
102     if(get_magic_quotes_gpc()){
103       $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
104     }else{
105       $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
106     }
107     $smarty->assign("FAIprioritys",$FAIprioritys);
108     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
109     return($display);
110   }
112   /* Save data to object */
113   function save_object()
114   {
115     if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
116       foreach($this->attributes as $attrs){
117         if($this->acl_is_writeable($attrs)){
118           if(isset($_POST[$attrs])){
119             $this->$attrs = $_POST[$attrs];
120           }else{
121             $this->$attrs = "";
122           }
123         }
124       }
125     }
126   }
128   /* Check supplied data */
129   function check()
130   {
131     /* Call common method to give check the hook */
132     $message= plugin::check();
133   
134     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
135       $message[] = msgPool::duplicated(_("Name"));
136     }
138     $c = trim($this->cn);
139     if($c == ""){
140       $message[] = msgPool::required(_("Name"));
141     }
142     if(preg_match("/[^a-z0-9_\-]/i",$c)){
143       $message[] = msgPool::invalid(_("Name"),$c,"/[a-z0-9_\-]/i");
144     }
146     $s = trim($this->FAIscript);
147     if($s == ""){
148       $message[]= msgPool::required(_("Script"));
149     }
151     return ($message);
152   }
153  
154   function save()
155   {
156     $tmp=array();
157     foreach($this->attributes as $attrs){ 
158       $tmp[$attrs] = $this->$attrs;
159     }
161     /* Strip out dos newlines */
162     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
164     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
165       $tmp['remove']['from']  = $this->orig_cn;
166       $tmp['remove']['to']    = $tmp['cn'];
167     }
168   
169     $tmp['dn']      = $this->dn;  
170     $tmp['status']  = $this->status; 
171     return($tmp);
172   }
174   
175   /* Return plugin informations for acl handling */
176   static function plInfo()
177   {
178     return (array(
179           "plShortName" => _("Script entry"),
180           "plDescription" => _("FAI script entry"),
181           "plSelfModify"  => FALSE,
182           "plDepends"     => array(),
183           "plPriority"    => 19,
184           "plSection"     => array("administration"),
185           "plCategory"    => array("fai"),
186           "plProvidedAcls" => array(
187             "cn"              => _("Name"),
188             "description"     => _("Description"),
189             "FAIscript"       => _("Script entry"),
190             "FAIpriority"     => _("Script Priority"))
191           ));
192   }
196 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
197 ?>