6ea4e3649796721e42d60793da3b01dbd0269fb0
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 = "";
34 function gofonMacro($config, $ui)
35 {
36 /* Save configuration for internal use */
37 $this->config= $config;
38 $this->ui= $ui;
40 /* Get global filter config */
41 if (!is_global("macrofilter")){
42 $base= get_base_from_people($ui->dn);
43 $macrofilter= array("regex" => "*");
44 register_global("macrofilter", $macrofilter);
45 }
47 if(!isset($_SESSION['CurrentMainBase'])){
48 $_SESSION['CurrentMainBase'] = $base= get_base_from_people($ui->dn);
49 }
51 $acl= get_permissions ($ui->dn, $ui->subtreeACL);
52 $this->acl= get_module_permission($acl, "goFonMacro", $ui->dn);
53 }
55 function execute()
56 {
57 /* Call parent execute */
58 plugin::execute();
60 /* Save data */
61 $macrofilter= get_global("macrofilter");
62 foreach( array("regex") as $type){
63 if (isset($_POST[$type])){
64 $macrofilter[$type]= $_POST[$type];
65 }
66 }
67 if (isset($_GET['search'])){
68 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
69 if ($s == "**"){
70 $s= "*";
71 }
72 $macrofilter['regex']= $s;
73 }
75 $s_action = ""; // Contains the action to proceed
76 $s_entry = ""; // The value for s_action
77 $base_back = ""; // The Link for Backbutton
79 /* Start for New List Managment */
80 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
81 $s_action="open";
82 $s_entry = base64_decode($_GET['dep_id']);
83 $_SESSION['CurrentMainBase'] = $this->config->departments[trim($s_entry)];
85 }
87 /* Test Posts */
88 foreach($_POST as $key => $val){
89 // Post for delete
90 if(preg_match("/user_del.*/",$key)){
91 $s_action = "del";
92 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
93 // Post for edit
94 }elseif(preg_match("/user_edit_.*/",$key)){
95 $s_action="edit";
96 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
97 // Post for new
98 }elseif(preg_match("/dep_back.*/i",$key)){
99 $s_action="back";
100 }elseif(preg_match("/user_new.*/",$key)){
101 $s_action="new";
102 }elseif(preg_match("/dep_home.*/i",$key)){
103 $s_action="home";
104 }elseif(preg_match("/user_chgpw.*/i",$key)){
105 $s_action="change_pw";
106 $s_entry = preg_replace("/user_chgpw_/i","",$key);
107 }elseif(preg_match("/dep_root.*/i",$key)){
108 $s_action="root";
109 }
110 }
111 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
112 $s_action ="edit";
113 $s_entry = $_GET['id'];
114 }
116 $s_entry = preg_replace("/_.$/","",$s_entry);
118 /* Department changed? */
119 if(isset($_POST['CurrentMainBase']) && $_POST['CurrentMainBase']){
120 $_SESSION['CurrentMainBase']= $_POST['CurrentMainBase'];
121 }
123 /* Homebutton is posted */
124 if($s_action=="home"){
125 $_SESSION['CurrentMainBase'] = preg_replace("/^[^,]+,/","",$this->ui->dn);
126 $_SESSION['CurrentMainBase'] = preg_replace("/^[^,]+,/","", $_SESSION['CurrentMainBase']);
127 }
129 if($s_action=="root"){
130 $_SESSION['CurrentMainBase'] = $this->config->current['BASE'] ;
131 }
134 /* If Backbutton is Posted */
135 if($s_action=="back"){
136 $base_back = preg_replace("/^[^,]+,/","", $_SESSION['CurrentMainBase']);
137 $base_back = convert_department_dn($base_back);
139 if(isset($this->config->departments[trim($base_back)])){
140 $_SESSION['CurrentMainBase'] = $this->config->departments[trim($base_back)];
141 }else{
142 $_SESSION['CurrentMainBase'] = $this->config->departments["/"];
143 }
144 }
146 register_global("macrofilter", $macrofilter);
147 $this->reload();
149 $smarty= get_smarty();
151 /* Check for exeeded sizelimit */
152 if (($message= check_sizelimit()) != ""){
153 return($message);
154 }
156 /* New macro? */
157 if ($s_action=="new"){
159 /* By default we set 'dn' to 'new', all relevant plugins will
160 react on this. */
161 $this->dn= "new";
163 /* Create new usertab object */
164 $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
165 }
167 /* Cancel dialogs */
168 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
169 del_lock ($this->macrotabs->dn);
170 unset ($this->macrotabs);
171 $this->macrotabs= NULL;
172 unset ($_SESSION['objectinfo']);
173 }
175 /* Finish mac edit is triggered by the tabulator dialog, so
176 the user wants to save edited data. Check and save at this
177 point. */
178 if ((isset($_POST['edit_finish'])) && (isset($this->macrotabs->config))){
180 /* Check tabs, will feed message array */
181 $this->macrotabs->last= $this->macrotabs->current;
182 $this->macrotabs->save_object();
183 $message= $this->macrotabs->check();
185 /* Save, or display error message? */
186 if (count($message) == 0){
188 /* Save data data to ldap */
189 $this->macrotabs->save();
190 gosa_log ("Macro object'".$this->dn."' has been saved");
192 /* macro has been saved successfully, remove lock from
193 LDAP. */
194 if ($this->dn != "new"){
195 del_lock ($this->dn);
196 }
198 /* There's no page reload so we have to read new mac at
199 this point. */
200 $this->reload ();
201 unset ($this->macrotabs);
202 $this->macrotabs= NULL;
203 unset ($_SESSION['objectinfo']);
204 } else {
205 /* Ok. There seem to be errors regarding to the tab data,
206 show message and continue as usual. */
207 show_errors($message);
208 }
209 }
211 /* User wants to edit data? */
212 if (($s_action=="edit") && (!isset($this->macrotabs->config))){
214 /* Get 'dn' from posted 'macrolists', must be unique */
215 $this->dn= $this->macros[$s_entry]['dn'];
217 /* Check locking, save current plugin in 'back_plugin', so
218 the dialog knows where to return. */
219 if (($user= get_lock($this->dn)) != ""){
220 return(gen_locked_message ($user, $this->dn));
221 }
223 /* Lock the current entry, so everyone will get the
224 above dialog */
225 add_lock ($this->dn, $this->ui->dn);
226 /* Register macrotabs to trigger edit dialog */
227 $this->macrotabs= new macrotabs($this->config,
228 $this->config->data['TABS']['MACROTABS'], $this->dn);
229 $_SESSION['objectinfo']= $this->dn;
230 }
232 /* Remove user was requested */
233 if ($s_action=="del"){
235 /* Get 'dn' from posted 'uid' */
236 $this->dn= $this->macros[$s_entry]['dn'];
238 /* Load permissions for selected 'dn' and check if
239 we're allowed to remove this 'dn' */
240 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
241 $this->acl= get_module_permission($acl, "goFonMacro", $this->dn);
242 if (chkacl($this->acl, "delete") == ""){
244 /* Check locking, save current plugin in 'back_plugin', so
245 the dialog knows where to return. */
246 if (($user= get_lock($this->dn)) != ""){
247 return (gen_locked_message ($user, $this->dn));
248 }
250 /* Lock the current entry, so nobody will edit it during deletion */
251 add_lock ($this->dn, $this->ui->dn);
252 $smarty= get_smarty();
253 $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn));
254 return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
255 } else {
257 /* Obviously the user isn't allowed to delete. Show message and
258 clean session. */
259 print_red (_("You are not allowed to delete this macro!"));
260 }
261 }
263 /* Confirmation for deletion has been passed. Group should be deleted. */
264 if (isset($_POST['delete_macro_confirm'])){
266 /* Some nice guy may send this as POST, so we've to check
267 for the permissions again. */
268 if (chkacl($this->acl, "delete") == ""){
270 /* Delete request is permitted, perform LDAP action */
271 $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn);
272 $this->macrotabs->set_acl(array($this->acl));
274 $this->macrotabs->delete ();
275 gosa_log ("macro object'".$this->dn."' has been removed");
276 unset ($this->macrotabs);
277 $this->macrotabs= NULL;
279 /* Group list has changed, reload it. */
280 $this->reload ();
281 } else {
282 /* Normally this shouldn't be reached, send some extra
283 logs to notify the administrator */
284 print_red (_("You are not allowed to delete this macro!"));
285 gosa_log ("Warning: '".$this->ui->uid."' tried to trick group deletion.");
286 }
287 /* Remove lock file after successfull deletion */
288 del_lock ($this->dn);
289 }
292 /* Delete macro canceled? */
293 if (isset($_POST['delete_cancel'])){
294 del_lock ($this->dn);
295 unset($_SESSION['objectinfo']);
296 }
298 /* Show tab dialog if object is present */
299 if (($this->macrotabs) && (isset($this->macrotabs->config))){
300 $display= $this->macrotabs->execute();
302 /* Don't show buttons if tab dialog requests this */
303 if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){
304 $display.= "<p style=\"text-align:right\">\n";
305 $display.= "<input type=\"submit\" name=\"edit_finish\" value=\""._("Finish")."\">\n";
306 $display.= " \n";
307 $display.= "<input type=\"submit\" name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
308 $display.= "</p>";
309 }
310 return ($display);
311 }
316 /* Prepare departments */
317 $options= "";
318 foreach ($this->config->idepartments as $key => $value){
319 if ($_SESSION['CurrentMainBase'] == $key){
320 $options.= "<option selected='selected' value='$key'>$value</option>";
321 } else {
322 $options.= "<option value='$key'>$value</option>";
323 }
324 }
327 /* NEW LIST MANAGMENT */
328 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
329 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root"). "'> ".
330 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
331 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
332 " <input class='center' type='image' src='images/list_reload.png' align='middle' title='"._("Reload list")."' name='submit_department' alt='"._("Submit")."'> ".
333 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
334 " <input class='center' type='image' align='middle' src='images/list_new_macro.png' title='"._("Create new phone macro")."' alt='"._("New")."' name='user_new'> ".
335 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
336 _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
337 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
338 "</div>";
341 /* Options */
342 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
343 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
345 $divlist = new divlist("macrotabs");
346 $divlist->SetHeader(array(
347 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
348 array("string" => _("Username")." / "._("Department"), "attach" => "style=''"),
349 array("string" => _("Visible"), "attach" => "style='width:50px;'"),
350 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'" )));
353 $divlist->SetSummary(_("This table displays all phone macros, in the selected tree."));
354 $divlist->SetEntriesPerPage(0);
356 // Defining Links
357 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
359 foreach($this->departments as $key=> $val){
361 if(!isset($this->config->departments[trim($key)])){
362 $this->config->departments[trim($key)]="";
363 }
365 $non_empty="";
366 $keys= str_replace("/","\/",$key);
367 foreach($this->config->departments as $keyd=>$vald ){
368 if(preg_match("/".$keys."\/.*/",$keyd)){
369 $non_empty="full";
370 }
371 }
373 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
374 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
375 $field3 = array("string" => " ", "attach" => "style='width:50px;'");
376 $field4 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
377 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
378 }
380 // Pictures for Extensions
381 $empty = "<img class='center' src='images/nothing.png' style='width:16px;height:16px;' alt=''>";
383 // User and Template Images
384 $macroimg = "<img class='center' src='images/list_macro.png' alt='"._("Macro")."' title='%s'>";
385 $visible = "<img class='center' src='images/true.png' alt='"._("yes")."' title='"._("visible")."'>";
386 $invisible = "<img class='center' src='images/false.png' alt='"._("no")."'title='"._("invisible")."'>";
388 // Link for edit
389 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
391 // Test Every Entry and generate divlist Array
392 foreach($this->macros as $key => $val){
393 // Generate Array to Add
394 $display= $val["displayName"][0];
397 if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){
398 $pic1 = $visible;
399 }else{
400 $pic1 = $invisible;
401 }
403 $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
404 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".$val['dn']."'");
405 $field3 = array("string" => $pic1, "attach" => "style='width:50px;'");
406 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:60px;border-right:0px;text-align:right;'");
408 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
409 }
411 /* Show main page */
412 $smarty->assign("macroshead", $listhead);
413 $smarty->assign("macros", $divlist->DrawList());
414 $smarty->assign("search_image", get_template_path('images/search.png'));
415 $smarty->assign("tree_image", get_template_path('images/tree.png'));
416 $smarty->assign("infoimage", get_template_path('images/info.png'));
417 $smarty->assign("launchimage", get_template_path('images/launch.png'));
418 $smarty->assign("deplist", $this->config->idepartments);
419 foreach( array("regex") as $type){
420 $smarty->assign("$type", $macrofilter[$type]);
421 }
423 $smarty->assign("CurrentMainBase" , $_SESSION['CurrentMainBase']);
425 /* Extend if we are not using javascript */
426 $smarty->assign("apply", apply_filter());
427 $smarty->assign("alphabet", generate_alphabet());
428 $smarty->assign("hint", print_sizelimit_warning());
430 return($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
431 }
434 function reload()
435 {
436 /* Get config */
437 $macrofilter= get_global('macrofilter');
439 /* Set base for all searches */
440 $base= $_SESSION['CurrentMainBase'];
442 /* Regex filter? */
443 if ($macrofilter['regex'] != ""){
444 $regex= $macrofilter['regex'];
445 } else {
446 $regex= "*";
447 }
449 /* Generate macro list */
450 $res= get_list($this->ui->subtreeACL, "(&(cn=$regex)(objectClass=goFonMacro))", FALSE, "ou=macros,ou=asterisk,ou=configs,ou=systems,".$base, array("*"), TRUE);
451 $this->macros= $res;
453 /* NEW LIST MANAGMENT
454 * We also need to search for the departments
455 * So we are able to navigate like in konquerer
456 */
457 $peopleOU = get_people_ou();
459 if(empty($peopleOU)){
460 $base2 = $base;
461 }else{
462 $base2 = preg_replace("/".$peopleOU."/i","",$base);
463 }
465 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
466 TRUE, $base2, array("ou", "description"), TRUE);
468 $this->departments= array();
469 $tmp = array();
470 foreach ($res3 as $value){
471 $tmp[strtolower($value['dn']).$value['dn']]=$value;
472 }
473 ksort($tmp);
474 foreach($tmp as $value){
475 if(isset($value["description"][0])){
476 $this->departments[$value['dn']]= convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
477 }else{
478 $this->departments[$value['dn']]= convert_department_dn2($value['dn']);//$value["description"][0];
479 }
480 }
482 /* END NEW LIST MANAGMENT
483 */
485 $tmp=array();
486 foreach($this->macros as $tkey => $val ){
487 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
488 }
489 ksort($tmp);
490 $this->macros=array();
491 foreach($tmp as $val){
492 $this->macros[]=$val;
493 }
495 reset ($this->macros);
496 }
498 function remove_from_parent()
499 {
500 /* Optionally execute a command after we're done */
501 $this->postremove();
502 }
505 /* Save data to object */
506 function save_object()
507 {
508 }
511 /* Check values */
512 function check()
513 {
514 }
517 /* Save to LDAP */
518 function save()
519 {
520 /* Optionally execute a command after we're done */
521 $this->postcreate();
522 }
524 function adapt_from_template($dn)
525 {
526 }
528 function password_change_needed()
529 {
530 }
532 function show_header($button_text, $text, $disabled= FALSE)
533 {
534 }
536 function remove_lock()
537 {
538 if (isset($this->macrotabs->dn)){
539 del_lock ($this->macrotabs->dn);
540 }
541 }
543 }
544 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
545 ?>