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 faiScriptEntry ($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(is_array($object)&&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 /* Create download button*/
81 if($this->dn != "new"){
82 $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."' target='_blank'>
83 <input type='button' value='"._("Download")."'>
84 </a>");
85 }else{
86 $smarty->assign("DownMe","");
87 }
89 for($i =0 ; $i < 100 ; $i++){
90 $FAIprioritys[$i]=$i;
91 }
92 $smarty->assign("FAIprioritys",$FAIprioritys);
93 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
94 return($display);
95 }
97 /* Save data to object */
98 function save_object()
99 {
100 if(isset($_POST['SubObjectFormSubmitted'])){
101 foreach($this->attributes as $attrs){
102 if(isset($_POST[$attrs])){
103 $this->$attrs = $_POST[$attrs];
104 }else{
105 $this->$attrs = "";
106 }
107 }
108 }
109 }
111 /* Check supplied data */
112 function check()
113 {
114 $message= array();
116 if(empty($this->cn)){
117 $message[] = _("Please enter a name.");
118 }
120 if(empty($this->FAIscript)){
121 $message[]=_("Please enter a script.");
122 }
124 return ($message);
125 }
127 function save()
128 {
129 $tmp=array();
130 foreach($this->attributes as $attrs){
131 $tmp[$attrs] = $this->$attrs;
132 }
134 /* Strip out dos newlines */
135 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
137 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
138 $tmp['remove']['from'] = $this->orig_cn;
139 $tmp['remove']['to'] = $tmp['cn'];
140 }
142 $tmp['dn'] = $this->dn;
143 $tmp['status'] = $this->status;
144 return($tmp);
145 }
146 }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>