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";
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(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->Object_description)){
86 $message[] = _("Invalid character in description. Please enter a valid description.");
87 }
89 if(empty($this->Object_cn)){
90 $message[] = _("Please enter a name.");
91 }
93 if(preg_match("/[^0-9a-z]/i",$this->Object_cn)){
94 $message[] = _("Please enter a valid name. Only a-Z 0-9 are allowed.");
95 }
97 return ($message);
98 }
100 function save()
101 {
102 $tmp=array();
103 foreach($this->attributes as $attrs){
104 $attr = preg_replace("/^Object_/","",$attrs);
105 $tmp[$attr] = $this->$attrs;
106 }
108 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
109 $tmp['remove']['from'] = $this->orig_cn;
110 $tmp['remove']['to'] = $tmp['cn'];
111 }
113 $tmp['dn'] = $this->dn;
114 $tmp['status'] = $this->Object_status;
115 return($tmp);
116 }
117 }
118 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
119 ?>