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";
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 = $name;
32 $this->$oname=$value;
33 }
34 }else{
35 $this->status = "new";
36 $this->orig_cn = false;
37 }
38 }
40 function execute()
41 {
42 /* Call parent execute */
43 plugin::execute();
45 /* Fill templating stuff */
46 $smarty = get_smarty();
47 $display = "";
49 if(isset($_POST['ImportUpload'])){
50 if(($_FILES['ImportFile']['error']!=0)){
51 print_red(_("Please select a valid file."));
52 }else
53 if(($_FILES['ImportFile']['size']==0)){
54 print_red(_("Selected file is empty."));
55 }else{
56 $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
57 $this->FAIscript = $str;
58 }
59 }
61 foreach($this->attributes as $attrs){
62 if(get_magic_quotes_gpc()){
63 $smarty->assign($attrs,stripslashes($this->$attrs));
64 }else{
65 $smarty->assign($attrs,($this->$attrs));
66 }
67 }
69 for($i =0 ; $i < 100 ; $i++){
70 $FAIprioritys[$i]=$i;
71 }
72 $smarty->assign("FAIprioritys",$FAIprioritys);
73 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
74 return($display);
75 }
77 /* Save data to object */
78 function save_object()
79 {
80 if(isset($_POST['SubObjectFormSubmitted'])){
81 foreach($this->attributes as $attrs){
82 if(isset($_POST[$attrs])){
83 $this->$attrs = $_POST[$attrs];
84 }else{
85 $this->$attrs = "";
86 }
87 }
88 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
89 }
90 }
92 /* Check supplied data */
93 function check()
94 {
95 $message= array();
97 if(empty($this->cn)){
98 $message[] = _("Please enter a name.");
99 }
101 if(empty($this->FAIscript)){
102 $message[]=_("Please enter a script.");
103 }
105 return ($message);
106 }
108 function save()
109 {
110 $tmp=array();
111 foreach($this->attributes as $attrs){
112 $tmp[$attrs] = $this->$attrs;
113 }
115 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
116 $tmp['remove']['from'] = $this->orig_cn;
117 $tmp['remove']['to'] = $tmp['cn'];
118 }
120 $tmp['dn'] = $this->dn;
121 $tmp['status'] = $this->status;
122 return($tmp);
123 }
124 }
125 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
126 ?>