Code

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@1522 594d385d-05f5-0310...
[gosa.git] / plugins / admin / fai / class_faiHookEntry.inc
1 <?php
3 class faiHookEntry 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_FAIscript","Object_FAItask");
13   var $objectclasses= array();
15   var $orig_cn              = "";
17   var $Object_dn            = "";
18   var $Object_cn            = "";
19   var $Object_FAItask       = "";
20   var $Object_FAIscript     = "";
21   var $Object_description   = "";
22   var $Object_status        = "new";
23   
24   function faiHookEntry ($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   }
41   function execute()
42   {
43     /* Fill templating stuff */
44     $smarty     = get_smarty();
45     $display = "";
46         
47     if(isset($_POST['ImportUpload'])){
48       if(($_FILES['ImportFile']['error']!=0)){
49         print_red(_("Please select a valid file."));
50       }else
51       if(($_FILES['ImportFile']['size']==0)){
52         print_red(_("Selected file is empty."));
53       }else{
54         $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
55         $this->Object_FAIscript = $str;
56       }
57     }
59      /* Magic quotes GPC, escapes every ' " \, to solve some security risks
60      * If we post the escaped strings they will be escaped again
61      */
62     foreach($this->attributes as $attrs){
63       if(get_magic_quotes_gpc()){
64         $smarty->assign($attrs,stripslashes($this->$attrs));
65       }else{
66         $smarty->assign($attrs,($this->$attrs));
67       }
68     }
71     for($i =1 ; $i <= 100 ; $i++){
72       $Object_FAIprioritys[$i]=$i;
73     }
74     $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
75     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
76     return($display);
77   }
79   /* Save data to object */
80   function save_object()
81   {
82     if(isset($_POST['SubObjectFormSubmitted'])){
83       foreach($this->attributes as $attrs){
84         if(isset($_POST[$attrs])){
85           $this->$attrs = $_POST[$attrs];
86         }else{
87           $this->$attrs = "";
88         }
89       }
90     }
91   }
93   /* Check supplied data */
94   function check()
95   {
96     $message= array();
97     if(empty($this->Object_FAItask)) {
98       $message[]=_("Please enter a value for task.");
99     }
100     if(empty($this->Object_FAIscript)) {
101       $message[]=_("Please enter a value for script.");
102     }
104     if(empty($this->Object_cn)){
105       $message[] = _("Please enter a name.");
106     }
108     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
109       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
110     }
111   
112     return ($message);
113   }
114  
115   function save()
116   {
117     $tmp=array();
118     foreach($this->attributes as $attrs){ 
119       $attr = preg_replace("/^Object_/","",$attrs);
120       $tmp[$attr] = $this->$attrs;
121     }
123     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
124       $tmp['remove']['from']  = $this->orig_cn;
125       $tmp['remove']['to']    = $tmp['cn'];
126     }
127   
128     $tmp['dn']      = $this->dn;  
129     $tmp['status']  = $this->Object_status;  
130     return($tmp);
131   }
133 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
134 ?>