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']) && $this->acl_is_writeable("FAIscript")){
62 if(($_FILES['ImportFile']['error']!=0)){
63 msg_dialog::display(_("Error"), _("Upload failed!"), ERROR_DIALOG);
64 }else
65 if(($_FILES['ImportFile']['size']==0)){
66 msg_dialog::display(_("Error"), _("Uploaded file is empty!"), ERROR_DIALOG);
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 /* File download requested */
82 if(isset($_GET['getFAIScript'])){
83 send_binary_content($this->FAIscript,$this->cn.".FAIscript");
84 }
86 /* Create download button*/
87 if($this->dn != "new" && $this->acl_is_readable("FAIscript")){
88 $smarty->assign("DownMe","<a href='?plug=".$_GET['plug']."&getFAIScript'>
89 <img src='images/save.png' alt='"._("Download")."' title='"._("Download")."' border=0 class='center'>
90 </a>");
91 }else{
92 $smarty->assign("DownMe","");
93 }
95 for($i =0 ; $i < 100 ; $i++){
96 $FAIprioritys[$i]=$i;
97 }
99 $tmp = $this->plInfo();
100 foreach($tmp['plProvidedAcls'] as $name => $translated){
101 $acl = $this->getacl($name);
102 if($this->FAIstate == "freezed"){
103 $acl = preg_replace("/w/","",$acl);
104 }
105 $smarty->assign($name."ACL",$acl);
106 }
108 $smarty->assign("FAIprioritys",$FAIprioritys);
109 if(get_magic_quotes_gpc()){
110 $smarty->assign("FAIscript" , htmlentities(stripslashes($this->FAIscript)));
111 }else{
112 $smarty->assign("FAIscript" , htmlentities($this->FAIscript));
113 }
114 $display.= $smarty->fetch(get_template_path('faiScriptEntry.tpl', TRUE));
115 return($display);
116 }
118 /* Save data to object */
119 function save_object()
120 {
121 if((isset($_POST['SubObjectFormSubmitted'])) && ($this->FAIstate != "freeze")){
122 foreach($this->attributes as $attrs){
123 if($this->acl_is_writeable($attrs)){
124 if(isset($_POST[$attrs])){
125 $this->$attrs = $_POST[$attrs];
126 }else{
127 $this->$attrs = "";
128 }
129 }
130 }
131 }
132 }
134 /* Check supplied data */
135 function check()
136 {
137 /* Call common method to give check the hook */
138 $message= plugin::check();
140 if(isset($this->parent->SubObjects[$this->cn]) && $this->cn != $this->orig_cn){
141 $message[] =_("Name is already in use!");
142 }
144 if(empty($this->cn)){
145 $message[] = _("Name is empty!");
146 }
148 if(empty($this->FAIscript)){
149 $message[]=_("Please enter a script!");
150 }
152 return ($message);
153 }
155 function save()
156 {
157 $tmp=array();
158 foreach($this->attributes as $attrs){
159 $tmp[$attrs] = $this->$attrs;
160 }
162 /* Strip out dos newlines */
163 $tmp['FAIscript']= strtr($this->FAIscript, array("\x0D" => ""));
165 if(($this->orig_cn)&&($tmp['cn']!=$this->orig_cn)){
166 $tmp['remove']['from'] = $this->orig_cn;
167 $tmp['remove']['to'] = $tmp['cn'];
168 }
170 $tmp['dn'] = $this->dn;
171 $tmp['status'] = $this->status;
172 return($tmp);
173 }
176 /* Return plugin informations for acl handling */
177 static function plInfo()
178 {
179 return (array(
180 "plShortName" => _("Script entry"),
181 "plDescription" => _("FAI script entry"),
182 "plSelfModify" => FALSE,
183 "plDepends" => array(),
184 "plPriority" => 19,
185 "plSection" => array("administration"),
186 "plCategory" => array("fai"),
187 "plProvidedAcls" => array(
188 "cn" => _("Name"),
189 "description" => _("Description"),
190 "FAIscript" => _("Script entry"),
191 "FAIpriority" => _("Script Priority"))
192 ));
193 }
196 }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>