d25af193635eb4537b436f683e190b6d1eebf2a0
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(file_get_contents($_FILES['ImportFile']['tmp_name']));
57 $this->FAIscript = $str;
58 }
59 }
62 foreach($this->attributes as $attrs){
63 if(get_magic_quotes_gpc()){
64 $smarty->assign($attrs,stripslashes($this->$attrs));
65 }else{
66 $smarty->assign($attrs,($this->$attrs));
67 }
68 }
70 for($i =0 ; $i < 100 ; $i++){
71 $FAIprioritys[$i]=$i;
72 }
73 $smarty->assign("FAIprioritys",$FAIprioritys);
74 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
75 return($display);
76 }
78 /* Save data to object */
79 function save_object()
80 {
81 if(isset($_POST['SubObjectFormSubmitted'])){
82 foreach($this->attributes as $attrs){
83 if(isset($_POST[$attrs])){
84 $this->$attrs = $_POST[$attrs];
85 }else{
86 $this->$attrs = "";
87 }
88 }
89 $this->FAIscript= recode("DOS..LATIN1", $this->FAIscript);
90 }
91 }
93 /* Check supplied data */
94 function check()
95 {
96 $message= array();
98 if(empty($this->cn)){
99 $message[] = _("Please enter a name.");
100 }
102 if(empty($this->FAIscript)){
103 $message[]=_("Please enter a script.");
104 }
106 return ($message);
107 }
109 function save()
110 {
111 $tmp=array();
112 foreach($this->attributes as $attrs){
113 $tmp[$attrs] = $this->$attrs;
114 }
116 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
117 $tmp['remove']['from'] = $this->orig_cn;
118 $tmp['remove']['to'] = $tmp['cn'];
119 }
121 $tmp['dn'] = $this->dn;
122 $tmp['status'] = $this->status;
123 return($tmp);
124 }
125 }
126 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
127 ?>