1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_macros.inc";
22 class gofonMacro extends plugin
23 {
24 /* Definitions */
25 var $plHeadline = "Phone macros";
26 var $plDescription = "This does something";
28 /* Dialog attributes */
29 var $macrotabs = NULL;
30 var $macros = array();
31 var $ui = NULL;
32 var $acl = "";
33 var $DivListMacro = NULL;
35 function gofonMacro($config, $ui)
36 {
37 /* Save configuration for internal use */
38 $this->config= $config;
39 $this->ui= $ui;
41 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
42 $this->acl= get_module_permission($acl, "goFonMacro", $ui->dn);
44 $this->DivListMacro = new divListMacro($this->config,$this);
45 }
47 function execute()
48 {
49 /* Call parent execute */
50 plugin::execute();
52 /*****************
53 Variable initialisation
54 *****************/
56 $s_action = ""; // Contains the action to proceed
57 $s_entry = ""; // The value for s_action
58 $base_back = ""; // The Link for Backbutton
59 $smarty= get_smarty();
62 /*****************
63 Check Posts
64 *****************/
66 /* Test Posts */
67 foreach($_POST as $key => $val){
68 // Post for delete
69 if(preg_match("/user_del.*/",$key)){
70 $s_action = "del";
71 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
72 // Post for edit
73 }elseif(preg_match("/user_edit_.*/",$key)){
74 $s_action="edit";
75 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
76 // Post for new
77 }elseif(preg_match("/user_new.*/",$key)){
78 $s_action="new";
79 }elseif(preg_match("/user_chgpw.*/i",$key)){
80 $s_action="change_pw";
81 $s_entry = preg_replace("/user_chgpw_/i","",$key);
82 }
83 }
84 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
85 $s_action ="edit";
86 $s_entry = $_GET['id'];
87 }
88 $s_entry = preg_replace("/_.$/","",$s_entry);
91 /*****************
92 Create a new Macro
93 *****************/
95 /* New macro? */
96 if ($s_action=="new"){
98 /* By default we set 'dn' to 'new', all relevant plugins will
99 react on this. */
100 $this->dn= "new";
102 /* Create new usertab object */
103 $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
104 }
107 /*****************
108 Edit || Password canceled
109 *****************/
111 /* Cancel dialogs */
112 if (isset($_POST['edit_cancel']) || isset($_POST['delete_cancel'])){
113 del_lock ($this->macrotabs->dn);
114 unset ($this->macrotabs);
115 $this->macrotabs= NULL;
116 unset ($_SESSION['objectinfo']);
117 }
120 /*****************
121 Edit finised
122 *****************/
124 /* Finish mac edit is triggered by the tabulator dialog, so
125 the user wants to save edited data. Check and save at this
126 point. */
127 if ((isset($_POST['edit_finish'])) && (isset($this->macrotabs->config))){
129 /* Check tabs, will feed message array */
130 $this->macrotabs->last= $this->macrotabs->current;
131 $this->macrotabs->save_object();
132 $message= $this->macrotabs->check();
134 /* Save, or display error message? */
135 if (count($message) == 0){
137 /* Save data data to ldap */
138 $this->macrotabs->save();
139 gosa_log ("Macro object'".$this->dn."' has been saved");
141 /* macro has been saved successfully, remove lock from
142 LDAP. */
143 if ($this->dn != "new"){
144 del_lock ($this->dn);
145 }
147 unset ($this->macrotabs);
148 $this->macrotabs= NULL;
149 unset ($_SESSION['objectinfo']);
150 } else {
151 /* Ok. There seem to be errors regarding to the tab data,
152 show message and continue as usual. */
153 show_errors($message);
154 }
155 }
158 /*****************
159 Edit macro
160 *****************/
162 /* User wants to edit data */
163 if (($s_action=="edit") && (!isset($this->macrotabs->config))){
165 /* Get 'dn' from posted 'macrolists', must be unique */
166 $this->dn= $this->macros[$s_entry]['dn'];
168 /* Check locking, save current plugin in 'back_plugin', so
169 the dialog knows where to return. */
170 if (($user= get_lock($this->dn)) != ""){
171 return(gen_locked_message ($user, $this->dn));
172 }
174 /* Lock the current entry, so everyone will get the
175 above dialog */
176 add_lock ($this->dn, $this->ui->dn);
177 /* Register macrotabs to trigger edit dialog */
178 $this->macrotabs= new macrotabs($this->config,
179 $this->config->data['TABS']['MACROTABS'], $this->dn);
180 $_SESSION['objectinfo']= $this->dn;
181 }
184 /*****************
185 Remove marco
186 *****************/
188 /* Remove user was requested */
189 if ($s_action=="del"){
191 /* Get 'dn' from posted 'uid' */
192 $this->dn= $this->macros[$s_entry]['dn'];
194 /* Load permissions for selected 'dn' and check if
195 we're allowed to remove this 'dn' */
196 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
197 $this->acl= get_module_permission($acl, "goFonMacro", $this->dn);
198 if (chkacl($this->acl, "delete") == ""){
200 /* Check locking, save current plugin in 'back_plugin', so
201 the dialog knows where to return. */
202 if (($user= get_lock($this->dn)) != ""){
203 return (gen_locked_message ($user, $this->dn));
204 }
206 /* Lock the current entry, so nobody will edit it during deletion */
207 add_lock ($this->dn, $this->ui->dn);
208 $smarty= get_smarty();
209 $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn));
210 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
211 } else {
213 /* Obviously the user isn't allowed to delete. Show message and
214 clean session. */
215 print_red (_("You are not allowed to delete this macro!"));
216 }
217 }
220 /*****************
221 Remove macro
222 *****************/
224 /* Confirmation for deletion has been passed. Macro should be deleted. */
225 if (isset($_POST['delete_macro_confirm'])){
227 /* Some nice guy may send this as POST, so we've to check
228 for the permissions again. */
229 if (chkacl($this->acl, "delete") == ""){
231 /* Delete request is permitted, perform LDAP action */
232 $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
233 $this->macrotabs->set_acl(array($this->acl));
235 $this->macrotabs->delete ();
236 gosa_log ("macro object'".$this->dn."' has been removed");
237 unset ($this->macrotabs);
238 $this->macrotabs= NULL;
239 } else {
240 /* Normally this shouldn't be reached, send some extra
241 logs to notify the administrator */
242 print_red (_("You are not allowed to delete this macro!"));
243 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
244 }
245 /* Remove lock file after successfull deletion */
246 del_lock ($this->dn);
247 }
250 /*****************
251 Display open dialogs
252 *****************/
254 /* Show tab dialog if object is present */
255 if (($this->macrotabs) && (isset($this->macrotabs->config))){
256 $display= $this->macrotabs->execute();
258 /* Don't show buttons if tab dialog requests this */
259 if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){
260 $display.= "<p style=\"text-align:right\">\n";
261 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Save")."\">\n";
262 $display.= " \n";
263 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
264 $display.= "</p>";
265 }
266 return ($display);
267 }
270 /*****************
271 Display entry list
272 *****************/
274 /* Return rendered main page */
275 /* Display dialog with system list */
276 $this->DivListMacro->execute();
278 /* Add departments if subsearch is disabled */
279 if(!$this->DivListMacro->SubSearch){
280 $this->DivListMacro->AddDepartments($this->DivListMacro->selectedBase,4);
281 }
282 $this->reload();
283 $this->DivListMacro->setEntries($this->macros);
284 return($this->DivListMacro->Draw());
285 }
288 function reload()
289 {
290 /* Set base for all searches */
291 $base = $this->DivListMacro->selectedBase;
292 $SubSearch = $this->DivListMacro->SubSearch;
293 $Regex = $this->DivListMacro->Regex;
294 $Filter = "(&(cn=".$Regex.")(objectClass=goFonMacro))";
295 $Flags = GL_SIZELIMIT;
296 $Attrs = array("cn","description","displayName");
298 /* Prepare for ls or search*/
299 if($SubSearch){
300 $Flags |= GL_SUBSEARCH;
301 }else{
302 $base = "ou=macros,ou=asterisk,ou=configs,ou=systems,".$base;
303 }
305 /* Generate macro list */
306 $res= get_list($Filter, $this->ui->subtreeACL,$base, $Attrs, $Flags);
308 $tmp=array();
309 foreach($res as $tkey => $val ){
310 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
311 }
312 ksort($tmp);
313 $this->macros=array();
314 foreach($tmp as $val){
315 $this->macros[]=$val;
316 }
318 reset ($this->macros);
319 }
322 /* Save data to object */
323 function save_object()
324 {
325 $this->DivListMacro->save_object();
326 }
329 function adapt_from_template($dn) { }
330 function check() { }
331 }
332 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
333 ?>