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";
25 function faiHookEntry ($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 = "";
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 }
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 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
100 }
101 }
103 /* Check supplied data */
104 function check()
105 {
106 $message= array();
108 if(empty($this->cn)){
109 $message[] = _("Please enter a name.");
110 }
112 if(empty($this->FAIscript)){
113 $message[]=_("Please enter a script.");
114 }
116 return ($message);
117 }
119 function save()
120 {
121 $tmp=array();
122 foreach($this->attributes as $attrs){
123 $tmp[$attrs] = $this->$attrs;
124 }
126 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
127 $tmp['remove']['from'] = $this->orig_cn;
128 $tmp['remove']['to'] = $tmp['cn'];
129 }
131 $tmp['dn'] = $this->dn;
132 $tmp['status'] = $this->status;
133 return($tmp);
134 }
135 }
136 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
137 ?>