Code

Adapted path and image
[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   }
40   function execute()
41   {
42     /* Fill templating stuff */
43     $smarty     = get_smarty();
44     $display = "";
46     foreach($this->attributes as $attrs){
47       $smarty->assign($attrs,stripslashes($this->$attrs));
48     }
50     for($i =1 ; $i <= 100 ; $i++){
51       $Object_FAIprioritys[$i]=$i;
52     }
53     $smarty->assign("Object_FAIprioritys",$Object_FAIprioritys);
54     $display.= $smarty->fetch(get_template_path('faiHookEntry.tpl', TRUE));
55     return($display);
56   }
58   /* Save data to object */
59   function save_object()
60   {
61     if(isset($_POST['SubObjectFormSubmitted'])){
62       foreach($this->attributes as $attrs){
63         if(isset($_POST[$attrs])){
64           $this->$attrs = $_POST[$attrs];
65         }else{
66           $this->$attrs = "";
67         }
68       }
69     }
70   }
72   /* Check supplied data */
73   function check()
74   {
75     $message= array();
76     if(empty($this->Object_FAItask)) {
77       $message[]=_("Please enter a value for task.");
78     }
79     if(empty($this->Object_FAIscript)) {
80       $message[]=_("Please enter a value for script.");
81     }
83     $str = utf8_encode("üöä");
85     if(empty($this->Object_description)){
86       $message[] = _("Please enter a description.");
87     }
89     if(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
90       $message[] = _("Invalid character in description. Please enter a valid description.");
91     }
93     if(empty($this->Object_cn)){
94       $message[] = _("Please enter a name.");
95     }
97     if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
98       $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
99     }
100   
101     return ($message);
102   }
103  
104   function save()
105   {
106     $tmp=array();
107     foreach($this->attributes as $attrs){ 
108       $attr = preg_replace("/^Object_/","",$attrs);
109       $tmp[$attr] = $this->$attrs;
110     }
112     if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
113       $tmp['remove']['from']  = $this->orig_cn;
114       $tmp['remove']['to']    = $tmp['cn'];
115     }
116   
117     $tmp['dn']      = $this->dn;  
118     $tmp['status']  = $this->Object_status;  
119     return($tmp);
120   }
122 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
123 ?>