Code

Added anyway edit to fai class
[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";
24   
25   function faiScriptEntry ($config, $dn= NULL,$object=false)
26   {
27     plugin::plugin ($config, $dn);
28     if($dn != "new"){
29       $this->orig_cn= $object['cn'];
30       $this->dn=$object['dn'];
31       foreach($object as $name=>$value){
32         $oname = $name;
33         $this->$oname=$value;
34       }
35     }else{
36       if(count($object)){
37         $this->orig_cn= $object['cn'];
38         $this->dn=$object['dn'];
39         foreach($object as $name=>$value){
40           $oname = $name;
41           $this->$oname=$value;
42         }
43       }else{
45         $this->status = "new";
46         $this->orig_cn       = false;
47       }
48     }
49   }
51   function execute()
52   {
53         /* Call parent execute */
54         plugin::execute();
56     /* Fill templating stuff */
57     $smarty     = get_smarty();
58     $display = "";
59   
60     if(isset($_POST['ImportUpload'])){
61       if(($_FILES['ImportFile']['error']!=0)){
62         print_red(_("Please select a valid file."));
63       }else
64       if(($_FILES['ImportFile']['size']==0)){
65         print_red(_("Selected file is empty."));
66       }else{
67         $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
68         $this->FAIscript = $str;
69       }
70     }
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     for($i =0 ; $i < 100 ; $i++){
81       $FAIprioritys[$i]=$i;
82     }
83     $smarty->assign("FAIprioritys",$FAIprioritys);
84     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
85     return($display);
86   }
88   /* Save data to object */
89   function save_object()
90   {
91     if(isset($_POST['SubObjectFormSubmitted'])){
92       foreach($this->attributes as $attrs){
93         if(isset($_POST[$attrs])){
94           $this->$attrs = $_POST[$attrs];
95         }else{
96           $this->$attrs = "";
97         }
98       }
99     }
100   }
102   /* Check supplied data */
103   function check()
104   {
105     $message= array();
106   
107     if(empty($this->cn)){
108       $message[] = _("Please enter a name.");
109     }
111     if(empty($this->FAIscript)){
112       $message[]=_("Please enter a script.");
113     }
115     return ($message);
116   }
117  
118   function save()
119   {
120     $tmp=array();
121     foreach($this->attributes as $attrs){ 
122       $tmp[$attrs] = $this->$attrs;
123     }
125     /* Strip out dos newlines */
126     $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
128     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
129       $tmp['remove']['from']  = $this->orig_cn;
130       $tmp['remove']['to']    = $tmp['cn'];
131     }
132   
133     $tmp['dn']      = $this->dn;  
134     $tmp['status']  = $this->status; 
135     return($tmp);
136   }
138 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
139 ?>