Code

903230055977e3de746c576b549f0be8bc5e72ca
[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("Object_cn","Object_description","Object_FAIpriority","Object_FAIscript");
13   var $objectclasses= array();
15   var $orig_cn              = "";
17   var $Object_dn            = "";
18   var $Object_cn            = "";
19   var $Object_FAIpriority   = "";
20   var $Object_FAIscript     = "";
21   var $Object_description   = "";
22   var $Object_status        = "new";
23   
24   function faiScriptEntry ($config, $dn= NULL,$object=false)
25   {
26     plugin::plugin ($config, $dn);
27     if($dn != "new"){
28       $this->orig_cn= $object['cn'];
29       $this->dn=$object['dn'];
30       foreach($object as $name=>$value){
31         $oname = "Object_".$name;
32         $this->$oname=$value;
33       }
34     }else{
35       $this->Object_status = "new";
36       $this->orig_cn       = false;
37     }
38   }
40   function execute()
41   {
42     /* Fill templating stuff */
43     $smarty     = get_smarty();
44     $display = "";
45   
46     if(isset($_POST['ImportUpload'])){
47       if(($_FILES['ImportFile']['error']!=0)){
48         print_red(_("Please select a valid file."));
49       }else
50       if(($_FILES['ImportFile']['size']==0)){
51         print_red(_("Selected file is empty."));
52       }else{
53         $str = file_get_contents($_FILES['ImportFile']['tmp_name']);
54         $this->Object_FAIscript = $str;
55       }
56     }
58   
60     foreach($this->attributes as $attrs){
61       $smarty->assign($attrs,stripslashes($this->$attrs));
62     }
64     for($i =1 ; $i <= 100 ; $i++){
65       $Object_FAIprioritys[$i]=$i;
66     }
67     $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
68     $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
69     return($display);
70   }
72   /* Save data to object */
73   function save_object()
74   {
75     if(isset($_POST['SubObjectFormSubmitted'])){
76       foreach($this->attributes as $attrs){
77         if(isset($_POST[$attrs])){
78           $this->$attrs = $_POST[$attrs];
79         }else{
80           $this->$attrs = "";
81         }
82       }
83     }
84   }
86   /* Check supplied data */
87   function check()
88   {
89     $message= array();
90   
91     $str = utf8_encode("üöä");
93     if(empty($this->Object_FAIscript)){
94       $message[]=_("Please specify a script.");
95     }
96     
97     if(empty($this->Object_description)){
98       $message[] = _("Please enter a description.");
99     }
101     if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
102       $message[] = _("Invalid character in description. Please enter a valid description.");
103     }
105     if(empty($this->Object_cn)){
106       $message[] = _("Please enter a name.");
107     }
109     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
110       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
111     }
112  
113     return ($message);
114   }
115  
116   function save()
117   {
118     $tmp=array();
119     foreach($this->attributes as $attrs){ 
120       $attr = preg_replace("/^Object_/","",$attrs);
121       $tmp[$attr] = $this->$attrs;
122     }
124     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
125       $tmp['remove']['from']  = $this->orig_cn;
126       $tmp['remove']['to']    = $tmp['cn'];
127     }
128   
129     $tmp['dn']      = $this->dn;  
130     $tmp['status']  = $this->Object_status; 
131     return($tmp);
132   }
134 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
135 ?>