1 <?php
3 class faiScriptEntry extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account= TRUE;
7 var $attributes = array("cn","description","FAIpriority","FAIscript");
8 var $objectclasses= array();
10 var $orig_cn = "";
12 var $dn = "";
13 var $cn = "";
14 var $FAIpriority = "0";
15 var $FAIscript = "";
16 var $description = "";
17 var $status = "new";
18 var $parent = NULL;
19 var $FAIstate = "";
21 function faiScriptEntry ($config, $dn= NULL,$object=false)
22 {
23 plugin::plugin ($config, $dn);
24 if($dn != "new"){
25 $this->orig_cn= $object['cn'];
26 $this->dn=$object['dn'];
27 foreach($object as $name=>$value){
28 $oname = $name;
29 $this->$oname=$value;
30 }
32 if(isset($this->attrs['FAIstate'][0])){
33 $this->FAIstate = $this->attrs['FAIstate'][0];
34 }
36 }else{
37 if(is_array($object)&&count($object)){
38 $this->orig_cn= $object['cn'];
39 $this->dn=$object['dn'];
40 foreach($object as $name=>$value){
41 $oname = $name;
42 $this->$oname=$value;
43 }
44 }else{
46 $this->status = "new";
47 $this->orig_cn = false;
48 }
49 }
50 }
52 function execute()
53 {
54 /* Call parent execute */
55 plugin::execute();
57 /* Fill templating stuff */
58 $smarty = get_smarty();
59 $display = "";
61 if(isset($_POST['ImportUpload'])){
62 if(($_FILES['ImportFile']['error']!=0)){
63 print_red(_("Please select a valid file."));
64 }else
65 if(($_FILES['ImportFile']['size']==0)){
66 print_red(_("Selected file is empty."));
67 }else{
68 $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
69 $this->FAIscript = $str;
70 }
71 }
73 foreach($this->attributes as $attrs){
74 if(get_magic_quotes_gpc()){
75 $smarty->assign($attrs,stripslashes($this->$attrs));
76 }else{
77 $smarty->assign($attrs,($this->$attrs));
78 }
79 }
81 /* Create download button*/
82 if($this->dn != "new"){
83 $smarty->assign("DownMe","<a href='getFAIscript.php?id=".base64_encode($this->dn)."'>
84 <input type='button' value='"._("Download")."'>
85 </a>");
86 }else{
87 $smarty->assign("DownMe","");
88 }
90 for($i =0 ; $i < 100 ; $i++){
91 $FAIprioritys[$i]=$i;
92 }
94 foreach($this->attributes as $attr){
95 if(($this->FAIstate == "freeze") || (chkacl($this->acl,$attr)!= "")){
96 $smarty->assign($attr."ACL"," disabled ");
97 }else{
98 $smarty->assign($attr."ACL"," ");
99 }
100 }
102 $smarty->assign("FAIprioritys",$FAIprioritys);
103 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
104 return($display);
105 }
107 /* Save data to object */
108 function save_object()
109 {
110 if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
111 foreach($this->attributes as $attrs){
112 if(isset($_POST[$attrs])){
113 $this->$attrs = $_POST[$attrs];
114 }else{
115 $this->$attrs = "";
116 }
117 }
118 }
119 }
121 /* Check supplied data */
122 function check()
123 {
124 /* Call common method to give check the hook */
125 $message= plugin::check();
127 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
128 $message[] =_("There is already a script with the given name.");
129 }
131 if(empty($this->cn)){
132 $message[] = _("Please enter a name.");
133 }
135 if(empty($this->FAIscript)){
136 $message[]=_("Please enter a script.");
137 }
139 return ($message);
140 }
142 function save()
143 {
144 $tmp=array();
145 foreach($this->attributes as $attrs){
146 $tmp[$attrs] = $this->$attrs;
147 }
149 /* Strip out dos newlines */
150 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
152 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
153 $tmp['remove']['from'] = $this->orig_cn;
154 $tmp['remove']['to'] = $tmp['cn'];
155 }
157 $tmp['dn'] = $this->dn;
158 $tmp['status'] = $this->status;
159 return($tmp);
160 }
161 }
162 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
163 ?>