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 /* Fill templating stuff */
43 $smarty = get_smarty();
44 $display = "";
46 if(isset($_POST['ImportUpload'])){
47 if(($_FILES['ImportFile']['error']!=0)){
48 print_red(_("Please select a valid file."));
49 }else
50 if(($_FILES['ImportFile']['size']==0)){
51 print_red(_("Selected file is empty."));
52 }else{
53 $str = utf8_encode(file_get_contents($_FILES['ImportFile']['tmp_name']));
54 $this->FAIscript = $str;
55 }
56 }
59 foreach($this->attributes as $attrs){
60 if(get_magic_quotes_gpc()){
61 $smarty->assign($attrs,stripslashes($this->$attrs));
62 }else{
63 $smarty->assign($attrs,($this->$attrs));
64 }
65 }
67 for($i =0 ; $i < 100 ; $i++){
68 $FAIprioritys[$i]=$i;
69 }
70 $smarty->assign("FAIprioritys",$FAIprioritys);
71 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
72 return($display);
73 }
75 /* Save data to object */
76 function save_object()
77 {
78 if(isset($_POST['SubObjectFormSubmitted'])){
79 foreach($this->attributes as $attrs){
80 if(isset($_POST[$attrs])){
81 $this->$attrs = $_POST[$attrs];
82 }else{
83 $this->$attrs = "";
84 }
85 }
86 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
87 }
88 }
90 /* Check supplied data */
91 function check()
92 {
93 $message= array();
95 if(empty($this->cn)){
96 $message[] = _("Please enter a name.");
97 }
99 if(empty($this->FAIscript)){
100 $message[]=_("Please enter a script.");
101 }
103 return ($message);
104 }
106 function save()
107 {
108 $tmp=array();
109 foreach($this->attributes as $attrs){
110 $tmp[$attrs] = $this->$attrs;
111 }
113 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
114 $tmp['remove']['from'] = $this->orig_cn;
115 $tmp['remove']['to'] = $tmp['cn'];
116 }
118 $tmp['dn'] = $this->dn;
119 $tmp['status'] = $this->status;
120 return($tmp);
121 }
122 }
123 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
124 ?>