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, NULL);
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 }
31 }else{
32 if(is_array($object)&&count($object)){
33 $this->orig_cn= $object['cn'];
34 $this->dn=$object['dn'];
35 foreach($object as $name=>$value){
36 $oname = $name;
37 $this->$oname=$value;
38 }
39 }else{
41 $this->status = "new";
42 $this->orig_cn = false;
43 }
44 }
45 }
47 function execute()
48 {
49 /* Call parent execute */
50 plugin::execute();
52 /* Fill templating stuff */
53 $smarty = get_smarty();
54 $smarty->assign("freeze", preg_match("/freeze/i",$this->FAIstate));
55 $display = "";
57 if(isset($_POST['ImportUpload']) && $this->acl_is_writeable("FAIscript")){
58 if(($_FILES['ImportFile']['error']!=0)){
59 msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
60 }else
61 if(($_FILES['ImportFile']['size']==0)){
62 msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("file is empty")), ERROR_DIALOG);
63 }else{
64 $str = utf8_encode(addslashes(file_get_contents($_FILES['ImportFile']['tmp_name'])));
65 $this->FAIscript = $str;
66 }
67 }
69 /* Magic quotes GPC, escapes every ' " \, to solve some security risks
70 * If we post the escaped strings they will be escaped again
71 */
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 /* File download requested */
81 if(isset($_GET['getFAIScript'])){
82 send_binary_content(stripslashes($this->FAIscript),$this->cn.".FAIscript");
83 }
85 /* Create download button*/
86 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
87 $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIScript'>
88 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
89 </a>");
90 }else{
91 $smarty->assign("DownMe","");
92 }
94 for($i =0 ; $i < 100 ; $i++){
95 $FAIprioritys[$i]=$i;
96 }
98 $tmp = $this->plInfo();
99 foreach($tmp['plProvidedAcls'] as $name => $translated){
100 $acl = $this->getacl($name,preg_match("/freeze/i",$this->FAIstate));
101 $smarty->assign($name."ACL",$acl);
102 }
104 if(get_magic_quotes_gpc()){
105 $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
106 }else{
107 $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
108 }
109 $smarty->assign("FAIprioritys",$FAIprioritys);
110 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
111 return($display);
112 }
114 /* Save data to object */
115 function save_object()
116 {
117 if((isset($_POST['SubObjectFormSubmitted'])) && !preg_match("/freeze/", $this->FAIstate)){
118 foreach($this->attributes as $attrs){
119 if($this->acl_is_writeable($attrs)){
120 if(isset($_POST[$attrs])){
121 $this->$attrs = $_POST[$attrs];
122 }else{
123 $this->$attrs = "";
124 }
125 }
126 }
127 }
128 }
130 /* Check supplied data */
131 function check()
132 {
133 /* Call common method to give check the hook */
134 $message= plugin::check();
136 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
137 $message[] = msgPool::duplicated(_("Name"));
138 }
140 $c = trim($this->cn);
141 if($c == ""){
142 $message[] = msgPool::required(_("Name"));
143 }
144 if(preg_match("/[^a-z0-9_\-]/i",$c)){
145 $message[] = msgPool::invalid(_("Name"),$c,"/[a-z0-9_\-]/i");
146 }
148 $s = trim($this->FAIscript);
149 if($s == ""){
150 $message[]= msgPool::required(_("Script"));
151 }
153 return ($message);
154 }
156 function save()
157 {
158 $tmp=array();
159 foreach($this->attributes as $attrs){
160 $tmp[$attrs] = $this->$attrs;
161 }
163 /* Strip out dos newlines */
164 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
166 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
167 $tmp['remove']['from'] = $this->orig_cn;
168 $tmp['remove']['to'] = $tmp['cn'];
169 }
171 $tmp['dn'] = $this->dn;
172 $tmp['status'] = $this->status;
173 return($tmp);
174 }
177 /* Return plugin informations for acl handling */
178 static function plInfo()
179 {
180 return (array(
181 "plShortName" => _("Script entry"),
182 "plDescription" => _("FAI script entry"),
183 "plSelfModify" => FALSE,
184 "plDepends" => array(),
185 "plPriority" => 19,
186 "plSection" => array("administration"),
187 "plCategory" => array("fai"),
188 "plProvidedAcls" => array(
189 "cn" => _("Name"),
190 "description" => _("Description"),
191 "FAIscript" => _("Script entry"),
192 "FAIpriority" => _("Script Priority"))
193 ));
194 }
197 }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>