Code

Fixed problem with not clickable buttons in fai package error msgs
[gosa.git] / plugins / admin / fai / class_faiTemplateEntry.inc
1 <?php
3 class faiTemplateEntry 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","FAItemplateFile","FAItemplatePath","FAImode","user","group","binary","FAIowner");
13   var $objectclasses= array();
15   var $orig_cn              = "";
17   var $dn            = "";
18   var $cn            = "";
19   var $FAItemplateFile   = "";
20   var $FAItemplatePath   = "";
21   var $description   = "";
22   var $status        = "new";
23   var $FAImode       = "0640";
24   var $FAIowner      = "root.root";
25   var $user          = "root";
26   var $group         = "root";
27   var $binary        = false;
28   var $parent        = NULL;
29   var $FAIstate      = "";
30   
31   function faiTemplateEntry ($config, $dn= NULL,$object=false)
32   {
33     plugin::plugin ($config, $dn);
35     if((isset($object['cn'])) && (!empty($object['cn']))){
36       $this->orig_cn= $object['cn'];
37       $this->dn=$object['dn'];
38       foreach($object as $name=>$value){
39         $oname = $name;
40         $this->$oname=$value;
41       }
43       if(isset($this->attrs['FAIstate'][0])){
44         $this->FAIstate = $this->attrs['FAIstate'][0];
45       }
47     }else{
48       $this->status = "new";
49       $this->orig_cn= false;
50     }
52     $this->user = explode( '.', $this->FAIowner );
53     $this->group = $this->user[1];
54     $this->user = $this->user[0];
56     $_SESSION['binary'] = $this->FAItemplateFile;
57     $_SESSION['binarytype'] = 'octet-stream';
58     $_SESSION['binaryfile'] = basename( $this->FAItemplatePath );
60     if(!empty($this->dn) && $this->dn != "new"){
61       $ldap = $this->config->get_ldap_link();
62       $_SESSION['binary'] =$ldap->get_attribute($this->dn,"FAItemplateFile");
63       $this->FAItemplateFile = $_SESSION['binary'];
64     }
65     
66     $this->FAImode= sprintf("%0.4s", $this->FAImode)." ";
67   }
70   function execute()
71   {
72     /* Call parent execute */
73     plugin::execute();
75     /* Fill templating stuff */
76     $smarty     = get_smarty();
77     $smarty->assign("rand", rand(0, 10000));
78     $display = "";
80     if(isset($_POST['TmpFileUpload']) && $this->acl_is_writeable("FAItemplateFile")){
81       if($str=file_get_contents($_FILES['FAItemplateFile']['tmp_name'])){
82         $this->FAItemplateFile = $str;
84         /* If we don't have a filename set it from upload filename. */
85         if( 0 == strlen( $this->FAItemplatePath )){
86           $this->FAItemplatePath = $_FILES['FAItemplateFile']['name'];
87         }
89         $_SESSION['binary']     = $this->FAItemplateFile;
90         $_SESSION['binarytype'] = 'octet-stream';
91         $_SESSION['binaryfile'] = basename( $this->FAItemplatePath );
92       }
93     }
94     
95     $status= _("no file uploaded yet");
97     $bStatus = false; // Hide download icon on default 
98     
99     if(strlen($this->FAItemplateFile)){
101       $status= sprintf(_("exists in database (size: %s bytes)"),strlen($this->FAItemplateFile));
102       $bStatus = true;  // Display download icon 
103     }
104     $smarty->assign("status",$status);
105     $smarty->assign("bStatus",$bStatus);
107     /* Magic quotes GPC, escapes every ' " \, to solve some security risks 
108      * If we post the escaped strings they will be escaped again
109      */
110     foreach($this->attributes as $attrs){
111       if(get_magic_quotes_gpc()){
112         $smarty->assign($attrs,stripslashes($this->$attrs));
113       }else{
114         $smarty->assign($attrs,($this->$attrs));
115       }
116     }
118     /* Assign file modes */
119     $tmode= "$this->FAImode ";
120     foreach (array("s", "u", "g", "o") as $type){
121       $current= substr($tmode, 0, 1);
122       $tmode=   preg_replace("/^./", "", $tmode);
123       $nr= 1;
124       while ($nr < 5){
125         if ($current & $nr){
126           $smarty->assign($type.$nr, "checked");
127         } else {
128           $smarty->assign($type.$nr, "");
129         }
130         $nr+= $nr;
131       }
132     }
134     $smarty->assign("FAItemplateFile","");
136     foreach($this->attributes as $attr){
137       $smarty->assign($attr."ACL",$this->getacl($attr,preg_match("/freeze/",$this->FAIstate)));
138     }
140     $display.=  $smarty->fetch(get_template_path('faiTemplateEntry.tpl', TRUE));
141     return($display);
142   }
144   /* Save data to object */
145   function save_object()
146   {
147     /* Check if form is posted and we are not freezed */
148     if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
150       plugin::save_object();
152       /* Set user.group (FAIowner) attribute */  
153       if(isset($_POST['group']) && isset($_POST["user"]) && $this->acl_is_writeable("FAIowner")){
154         $this->FAIowner = $_POST["user"].'.'.$_POST["group"];
155         $this->user = $_POST['user'];
156         $this->group= $_POST['group'];
157       }
159       /* Check if permissions have changed */
160       if($this->acl_is_writeable("FAImode")){
162         /* Save mode */
163         $tmode= "";
164         foreach (array("s", "u", "g", "o") as $type){
165           $nr= 1;
166           $dest= 0;
167           while ($nr < 5){
168             if (isset($_POST["$type$nr"])){
169               $dest+= $nr;
170             }
171             $nr+= $nr;
172           }
173           $tmode= $tmode.$dest;
174         }
175         $this->FAImode= $tmode;
176       }
177     }
178   }
181   /* Check supplied data */
182   function check()
183   {
184     /* Call common method to give check the hook */
185     $message= plugin::check();
187     if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
188       $message[] =_("There is already a template with the given name.");
189     }
191     if(empty($this->FAItemplateFile)){
192       $message[]=_("Please specify a value for attribute 'file'.");
193     } 
195     if(empty($this->FAItemplatePath)){
196       $message[]=_("Please specify a value for attribute 'path'.");
197     } 
198   
199     if(empty($this->cn)){
200       $message[] = _("Please enter a name.");
201     }
203     if(empty($this->user)){
204       $message[] = _("Please enter a user.");
205     }
206     elseif(preg_match("/[^0-9a-z]/i",$this->user)){
207       $message[] = _("Please enter a valid user. Only a-z/0-9 are allowed.");
208     }
210     if(empty($this->group)){
211       $message[] = _("Please enter a group.");
212     }
213     elseif(preg_match("/[^0-9a-z]/i",$this->group)){
214       $message[] = _("Please enter a valid group. Only a-z/0-9 are allowed.");
215     }
217     return ($message);
218   }
219  
220   function save()
221   {
222     $tmp=array();
223     foreach($this->attributes as $attrs){ 
224       $tmp[$attrs] = $this->$attrs;
225     }
227     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
228       $tmp['remove']['from']  = $this->orig_cn;
229       $tmp['remove']['to']    = $tmp['cn'];
230     }
231   
232     $tmp['dn']      = $this->dn;  
233     $tmp['status']  = $this->status;  
235     return($tmp);
236   }
238   
239   /* Return plugin informations for acl handling */
240   function plInfo()
241   {
242     return (array(
243           "plShortName" => _("Template entry"),
244           "plDescription" => _("FAI template entry"),
245           "plSelfModify"  => FALSE,
246           "plDepends"     => array(),
247           "plPriority"    => 25,
248           "plSection"     => array("administration"),
249           "plCategory"    => array("fai"),
250           "plProvidedAcls" => array(
251             "cn"                => _("Name"),
252             "description"       => _("Description"),
253             "FAItemplateFile"   => _("Template file"),
254             "FAItemplatePath"   => _("Template path"),
255             "FAIowner"          => _("File owner"),
256             "FAImode"           => _("File permissions"))
257           ));
258   }
261 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
262 ?>