Code

644716d7476e6e9cec072e3085fcef1e63e42e95
[gosa.git] / plugins / gofon / conference / class_phoneConferenceManagment.inc
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_conference.inc";
22 class phoneConferenceManagment extends plugin
23 {
24   /* Definitions */
25   var $plHeadline                                 = "Phone conferences";
26   var $plDescription                    = "Management";
28   /* CLI vars */
29   var $cli_summary                        = "Handling of LDAP subtrees";
30   var $cli_description          = "Some longer text\nfor help";
31   var $cli_parameters                   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33   /* Headpage attributes */
34   var $conferences                        = array();
36   /* attribute list for save action */
37   var $attributes                                 = array();
38   var $objectclasses                    = array();
39   var $conftab            = false;
41   var $departments  =array();
43   /* Initialise Class */
44   function phoneConferenceManagment ($config, $ui)
45   {
46     $this->ui                   = $ui;
47     $this->dn                   = "";
48     $this->config               = $config;
50     /* Get global filter config */
51     if (!isset($_SESSION["conferencefilter"])){
52       $base= get_base_from_people($ui->dn);
53       $conferencefilter= array(
54           "depselect"       => $base,
55           "regex"           => "*");
56       $_SESSION["conferencefilter"] = $conferencefilter;
57     }
58   }
60   /* Execute class and display something */
61   function execute()
62   {
63         /* Call parent execute */
64         plugin::execute();
65     /* Reload departments */
66     $this->config->departments  = get_departments();
67     $smarty                                                       = get_smarty();
68     $display                                              = "";
69     $s_action                                           = "";  // Will contain an action, like del or edit
70     $s_entry                                            = "";  // The entry name for edit delete -...
71     $conferencefilter           = $_SESSION["conferencefilter"]; 
73     if(isset($_POST['regexit'])){
74       $conferencefilter['regex']=$_POST['regexit'];
75     }
77     if(isset($_GET['search'])){
78       if($_GET['search']=="*"){
79         $conferencefilter['regex']=$_GET['search'];
80       }else{
81         $conferencefilter['regex']=$_GET['search']."*";
82       }
83     }
85     $smarty->assign("regex",$conferencefilter['regex']); 
87     /* Start for New List Managment */
88     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
89       $s_action="open";
90       $s_entry = base64_decode($_GET['dep_id']);
91       $conferencefilter['depselect']= "".$this->config->departments[trim($s_entry)];
92     }
94     foreach($_POST as $key => $post){
95       if(preg_match("/.*new.*/i",$key)){
96         $s_action = "new";
97         // Post for delete
98       }elseif(preg_match("/conf_del.*/",$key)){
99         $s_action = "del";
100         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
101         $s_entry  = preg_replace("/_.*$/","",$s_entry);
102         // Post for edit
103       }elseif(preg_match("/conf_edit_.*/",$key)){
104         $s_action="edit";
105         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
106         $s_entry  = preg_replace("/_.*$/","",$s_entry);
107       }elseif(preg_match("/dep_back.*/i",$key)){
108         $s_action="back";
109       }elseif(preg_match("/dep_home.*/i",$key)){
110         $s_action="home";
111       }elseif(preg_match("/dep_root.*/i",$key)){
112         $s_action="root";
113       } 
114     }
116     /* Edit Entry */
117     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
118       $s_action = "edit";
119       $s_entry  = $_GET['id'];
120     }
122     /* Department changed? */
123     if(isset($_POST['depselect']) && $_POST['depselect']){
124       $conferencefilter['depselect']= $_POST['depselect'];
125     }
127     /* Homebutton is posted */
128     if($s_action=="home"){
129       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
130       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$conferencefilter['depselect']));
131     }
132     
133     /* back to root */
134     if($s_action=="root"){
135       $conferencefilter['depselect']=($this->config->current['BASE']);
136     }
138     /* If Backbutton is Posted */
139     if($s_action=="back"){
140       $base_back          = preg_replace("/^[^,]+,/","",$conferencefilter['depselect']);
141       $base_back          = convert_department_dn($base_back);
143       if(isset($this->config->departments[trim($base_back)])){
144         $conferencefilter['depselect']= $this->config->departments[trim($base_back)];
145       }else{
146         $conferencefilter['depselect']= $this->config->departments["/"];
147       }
148     }
150     register_global("conferencefilter",$conferencefilter);
151     $this->reload();
153     /* Reset requested? */
154     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
155       if (isset($this->conftab)){
156         del_lock ($this->conftab->dn);
157         unset ($this->conftab);
158       }
159       $this->conftab= NULL;
160       $this->lognames= array();;
161       $this->cn= "";
162       unset ($_SESSION['objectinfo']);
163     }
165     /* Delete Entry if Posted action (s_action) == del
166      * The entry which will be deleted is defined in $s_entry
167      */
168     if ($s_action =="del"){
169       $this->dn= $this->conferences[$s_entry]['dn'];
171       /* Check locking */
172       if (($conf= get_lock($this->dn)) != ""){
173         $_SESSION['dn']= $this->dn;
174         return(gen_locked_message($conf, $this->dn));
175       } else {
176         add_lock ($this->dn, $this->ui->dn);
177         $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
178         $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
179         return ($display);
180       }
181     }
183     /* If department deletion is accepted ...
184      * Finally delete department
185      */
186     if (isset($_POST['delete_department_confirm'])){
187       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
188       $acl= get_module_permission($acl, "goFonConference", $this->dn);
189       if (chkacl($acl, "all") == ""){
190         $this->remove_from_parent();
191         gosa_log ("Department object'".$this->dn."' has been removed");
192         $this->reload ();
193       } else {
194         print_red (_("You have no permission to remove this department."));
195       }
196     }
198     /* Edit Entry if Posted action (s_action) == edit
199      * The entry which will be edited is defined in $s_entry
200      */
201     if ($s_action=="edit"){
203       $this->dn= $this->conferences[$s_entry]['dn'];
205       if (($conf= get_lock($this->dn)) != ""){
206         return(gen_locked_message ($conf, $this->dn));
207       }
209       /* Lock the current entry, so everyone will get the  above dialog */
210       add_lock ($this->dn, $this->ui->dn);
212       /* Set up the users ACL's for this 'dn' */
213       $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
215       /* Register conftab to trigger edit dialog */
216       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
217       $this->conftab->set_acl($this->acl);
218       $_SESSION['objectinfo']= $this->dn;
219     }
221     /* Insert new entry*/    
222     if($s_action == "new"){
223       $this->dn= "new";
224       /* Set up the users ACL's for this 'dn' */
225       $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
226       $this->dn= "new";
227       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
228       $this->acl= get_permissions ($this->conftab->dn, $this->ui->subtreeACL);
229       $this->conftab->set_acl($this->acl);
230       $this->conftab->set_acl(array(':all'));
231       $_SESSION['objectinfo']= $this->dn;
232     }
234     /* Edit finished, check and save changes */
235     if (isset($_POST['edit_finish'])){
236       /* Check tabs, will feed message array */
237       $this->conftab->last= $this->conftab->current;
238       $this->conftab->save_object();
239       $message= $this->conftab->check();
241       if (count($message) == 0){
242         if($this->conftab->save() == 1){
243           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
244           return;
245         }
246         gosa_log ("goFonConference object '".$this->dn."' has been saved");
248         if ($this->dn != "new"){
249           del_lock ($this->dn);
250         }
252         $this->conftab->save ();
253         del_lock ($this->conftab->dn);;
254         unset ($this->conftab);
255         $this->conftab= NULL;
256         unset ($_SESSION['objectinfo']);
257       } else {
258         show_errors($message);
259       }
260       
261       $this->reload();
262     }
264     /* if edit or new, show dialog */
265     if($this->conftab){
266       $display= $this->conftab->execute();
268       /* Don't show buttons if tab dialog requests this */
269       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
270         $display.= "<p style=\"text-align:right\">\n";
271         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
272         $display.= "&nbsp;\n";
273         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
274         $display.= "</p>";
275       }
276       return ($display);
277     }
279     /* Header + Departmentlist*/
280     $options= "";
281     foreach ($this->config->idepartments as $key => $value){
282       if ($conferencefilter['depselect'] == $key){
283         $options.= "<option selected value='$key'>$value</option>";
284       } else {
285         $options.= "<option value='$key'>$value</option>";
286       }
287     }
289     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
290       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
291       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
292       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
293       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
294       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new conference")."' alt='"._("New conference")."' name='user_new'>&nbsp;".
295       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
296       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
297       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").     "'>&nbsp;".
298       "</div>";
300     /* Images for delete / edit */
301     $actions = "<input type='image' src='images/edit.png'                alt='"._("edit")."'      name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
302     $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'    name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
303     
304     $actions2= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'    name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
305     /* open an entry */
306     $linkopen= "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
308     /* Set Header */
309     $divlist  = new divlist("conferenceTabs");
310     $divlist->SetSummary(_("This table displays all available conference rooms."));
311     $divlist->SetEntriesPerPage(0);
312     $divlist->SetHeader(array(
313           array("string" => "&nbsp;"),            
314           array("string" =>_("Name - Number")),
315           array("string" => _("Owner")),
316           array("string" => _("PIN")),
317           array("string" =>_("Actions"), "attach" => "style='text-align:  right;border:none'")));
319     /* Insert departments in divlist*/
320     foreach($this->departments as $key=> $val){
321       if(!isset($this->config->departments[trim($key)])){
322         $this->config->departments[trim($key)]="";
323       }
325       $non_empty="";
326       $keys= str_replace("/","\/",$key);
327       foreach($this->config->departments as $keyd=>$vald ){
328         if(preg_match("/".$keys."\/.*/",$keyd)){
329           $non_empty="full";
330         }
331       }
333       /* Prepare and insert fields*/
334       $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
335       $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
336       $a_field3 = array("string" => "&nbsp;");
337       $a_field4 = array("string" => "&nbsp;");
338       $a_field5 = array("string" => "&nbsp;",  "attach" => "style='text-align:  right;border:none'");
340       /* Add entries */
341       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
342     }
344     /* Image shown in divlist */
345     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";
347     /* Edit entry link*/
348     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
350     /* Insert conferneces*/
351     foreach($this->conferences as $conferencekey => $conference ){
352   
353       if((isset($conference['goFonPIN'][0]))&&($this->ui->dn==$conference['goFonConferenceOwner'][0])){
354         $pin = "<img src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
355       }else{
356         $pin = "&nbsp;";
357       }
359       if(isset($conference['telephoneNumber'][0])){
360         $number = " - ".$conference['telephoneNumber'][0];
361       }else{
362         $number = "&nbsp; - ?";
363       }
365       $ldap= $this->config->get_ldap_link();
366       $ldap->cd ($conference['goFonConferenceOwner'][0]);
367       $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
368       $cn = $data['cn'][0];
369  
370       $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
372       $acl= get_permissions ($conference['dn'], $this->ui->subtreeACL);
373       $this->acl =  get_module_permission($acl, "goFonConference", $conference['dn']);
375       if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
376         $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number));
377       }else{  
378         $a_field2 = array("string"=>$conference['cn'][0].$number);
379       }
380       $a_field3 = array("string"=> $cn);
381       $a_field4 = array("string"=> $pin);
383       if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
384         $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='text-align:  right;border:none'");
385       }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
386         $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='text-align:  right;border:none'");
387       }else{
388         $a_field5 = array("string"=>"&nbsp;", "attach" => "style='text-align:  right;border:none'");
389       }
391       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
392     }
394     $smarty->assign("search_image",     get_template_path('images/search.png'));
395     $smarty->assign("tree_image",       get_template_path('images/tree.png'));
396     $smarty->assign("infoimage",        get_template_path('images/info.png'));
397     $smarty->assign("launchimage",      get_template_path('images/launch.png'));
398     $smarty->assign("conferences",      $divlist->DrawList());
399     $smarty->assign("conferencehead",  $listhead);
400     $smarty->assign("deplist",          $this->config->idepartments);
401     $smarty->assign("apply",            apply_filter());
402     $smarty->assign("alphabet",         generate_alphabet());
403     $smarty->assign("hint",             print_sizelimit_warning());
405     $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
406     return($display);
407   }
410   /* Reload entries for divlist.
411    * First, reload all conferences for the current base, with the given regex
412    * Second, get all departments for the given base and regex
413    * Convert departments dn
414    */
415   function reload()
416   {
417     $conferencefilter = $_SESSION["conferencefilter"];
418     $base             = $conferencefilter['depselect'];
419     $regex            = $conferencefilter['regex'];
421     $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
422     $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
424     $this->departments= array();
426     $tmp = array();
427     foreach ($res3 as $value){
428       $tmp[strtolower($value['dn']).$value['dn']]=$value;
429     }
430     ksort($tmp);
431     foreach($tmp as $value){
432       if($value["description"][0]!=".."){
433         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
434       }else{
435         $this->departments[$value['dn']]=$value["description"][0];
436       }
437     }
438   }
440   function remove_from_parent()
441   {
442     $cfg = new conference($this->config, $this->dn);
443     $cfg->remove_from_parent();
444     $ldap= $this->config->get_ldap_link();
445     $ldap->cd ($this->dn);
446     $ldap->recursive_remove();
448     /* Optionally execute a command after we're done */
449     $this->postremove();
451     /* Delete references to object groups */
452     $ldap->cd ($this->config->current['BASE']);
453     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
454     while ($ldap->fetch()){
455       $og= new conftab($this->config, $ldap->getDN());
456       unset($og->member[$this->dn]);
457       $og->save ();
458     }
460   }
462   function remove_lock()
463   {
464     if (isset($this->dn)){
465       del_lock ($this->dn);
466     }
467   }
470 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
471 ?>