Code

4f5cf2990f647fff755bbdeee24b3c1f3a999d13
[gosa.git] / plugins / admin / fai / class_faiScriptEntry.inc
1 <?php
3 class faiScriptEntry 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","FAIpriority","FAIscript");
13   var $objectclasses= array();
15   var $orig_cn              = "";
17   var $dn            = "";
18   var $cn            = "";
19   var $FAIpriority   = "0";
20   var $FAIscript     = "";
21   var $description   = "";
22   var $status        = "new";
23   var $parent        = NULL;
24   var $FAIstate      = "";
25   
26   function faiScriptEntry ($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       }
37       if(isset($this->attrs['FAIstate'][0])){
38         $this->FAIstate = $this->attrs['FAIstate'][0];
39       }
41     }else{
42       if(is_array($object)&&count($object)){
43         $this->orig_cn= $object['cn'];
44         $this->dn=$object['dn'];
45         foreach($object as $name=>$value){
46           $oname = $name;
47           $this->$oname=$value;
48         }
49       }else{
51         $this->status = "new";
52         $this->orig_cn       = false;
53       }
54     }
55   }
57   function execute()
58   {
59         /* Call parent execute */
60         plugin::execute();
62     /* Fill templating stuff */
63     $smarty     = get_smarty();
64     $display = "";
65   
66     if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
67       if(($_FILES['ImportFile']['error']!=0)){
68         print_red(_("Please select a valid file."));
69       }else
70       if(($_FILES['ImportFile']['size']==0)){
71         print_red(_("Selected file is empty."));
72       }else{
73         $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
74         $this->FAIscript = $str;
75       }
76     }
77   
78     foreach($this->attributes as $attrs){
79       if(get_magic_quotes_gpc()){
80        $smarty->assign($attrs,stripslashes($this->$attrs));
81       }else{
82        $smarty->assign($attrs,($this->$attrs));
83       } 
84     }
86      /* Create download button*/
87     if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
88       $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
89         <input type='button' value='"._("Download")."'>
90         </a>");
91     }else{
92       $smarty->assign("DownMe","");
93     }
95     for($i =0 ; $i < 100 ; $i++){
96       $FAIprioritys[$i]=$i;
97     }
99     $tmp = $this->plInfo();
100     foreach($tmp['plProvidedAcls'] as $name => $translated){
101       $acl = $this->getacl($name);
102       if($this->FAIstate == "freezed"){
103         $acl = preg_replace("/w/","",$acl);
104       }
105       $smarty->assign($name."ACL",$acl);
106     }
108     $smarty->assign("FAIprioritys",$FAIprioritys);
109     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
110     return($display);
111   }
113   /* Save data to object */
114   function save_object()
115   {
116     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
117       foreach($this->attributes as $attrs){
118         if($this->acl_is_writeable($attrs)){
119           if(isset($_POST[$attrs])){
120             $this->$attrs = $_POST[$attrs];
121           }else{
122             $this->$attrs = "";
123           }
124         }
125       }
126     }
127   }
129   /* Check supplied data */
130   function check()
131   {
132     /* Call common method to give check the hook */
133     $message= plugin::check();
134   
135     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
136       $message[] =_("There is already a script with the given name.");
137     }
139     if(empty($this->cn)){
140       $message[] = _("Please enter a name.");
141     }
143     if(empty($this->FAIscript)){
144       $message[]=_("Please enter a script.");
145     }
147     return ($message);
148   }
149  
150   function save()
151   {
152     $tmp=array();
153     foreach($this->attributes as $attrs){ 
154       $tmp[$attrs] = $this->$attrs;
155     }
157     /* Strip out dos newlines */
158     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
160     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
161       $tmp['remove']['from']  = $this->orig_cn;
162       $tmp['remove']['to']    = $tmp['cn'];
163     }
164   
165     $tmp['dn']      = $this->dn;  
166     $tmp['status']  = $this->status; 
167     return($tmp);
168   }
170   
171   /* Return plugin informations for acl handling */
172   function plInfo()
173   {
174     return (array(
175           "plShortName" => _("Script entry"),
176           "plDescription" => _("FAI script entry"),
177           "plSelfModify"  => FALSE,
178           "plDepends"     => array(),
179           "plPriority"    => 19,
180           "plSection"     => array("administration"),
181           "plCategory"    => array("fai"),
182           "plProvidedAcls" => array(
183             "cn"              => _("Name"),
184             "description"     => _("Description"),
185             "FAIscript"       => _("Script entry"),
186             "FAIpriority"     => _("Script Priority"))
187           ));
188   }
192 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
193 ?>