Code

Added empty package configuration dialog
[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     /* Reload departments */
64     $this->config->departments  = get_departments();
65     $smarty                                                       = get_smarty();
66     $display                                              = "";
67     $s_action                                           = "";  // Will contain an action, like del or edit
68     $s_entry                                            = "";  // The entry name for edit delete -...
69     $conferencefilter           = $_SESSION["conferencefilter"]; 
71     if(isset($_POST['regexit'])){
72       $conferencefilter['regex']=$_POST['regexit'];
73     }
75     if(isset($_GET['search'])){
76       if($_GET['search']=="*"){
77         $conferencefilter['regex']=$_GET['search'];
78       }else{
79         $conferencefilter['regex']=$_GET['search']."*";
80       }
81     }
83     $smarty->assign("regex",$conferencefilter['regex']); 
85     /* Start for New List Managment */
86     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
87       $s_action="open";
88       $s_entry = base64_decode($_GET['dep_id']);
89       $conferencefilter['depselect']= "".$this->config->departments[trim($s_entry)];
90     }
92     foreach($_POST as $key => $post){
93       if(preg_match("/.*new.*/i",$key)){
94         $s_action = "new";
95         // Post for delete
96       }elseif(preg_match("/conf_del.*/",$key)){
97         $s_action = "del";
98         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
99         $s_entry  = preg_replace("/_.*$/","",$s_entry);
100         // Post for edit
101       }elseif(preg_match("/conf_edit_.*/",$key)){
102         $s_action="edit";
103         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
104         $s_entry  = preg_replace("/_.*$/","",$s_entry);
105       }elseif(preg_match("/dep_back.*/i",$key)){
106         $s_action="back";
107       }elseif(preg_match("/dep_home.*/i",$key)){
108         $s_action="home";
109       }elseif(preg_match("/dep_root.*/i",$key)){
110         $s_action="root";
111       } 
112     }
114     /* Edit Entry */
115     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
116       $s_action = "edit";
117       $s_entry  = $_GET['id'];
118     }
120     /* Department changed? */
121     if(isset($_POST['depselect']) && $_POST['depselect']){
122       $conferencefilter['depselect']= $_POST['depselect'];
123     }
125     /* Homebutton is posted */
126     if($s_action=="home"){
127       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
128       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$conferencefilter['depselect']));
129     }
130     
131     /* back to root */
132     if($s_action=="root"){
133       $conferencefilter['depselect']=($this->config->current['BASE']);
134     }
136     /* If Backbutton is Posted */
137     if($s_action=="back"){
138       $base_back          = preg_replace("/^[^,]+,/","",$conferencefilter['depselect']);
139       $base_back          = convert_department_dn($base_back);
141       if(isset($this->config->departments[trim($base_back)])){
142         $conferencefilter['depselect']= $this->config->departments[trim($base_back)];
143       }else{
144         $conferencefilter['depselect']= $this->config->departments["/"];
145       }
146     }
148     register_global("conferencefilter",$conferencefilter);
149     $this->reload();
151     /* Reset requested? */
152     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
153       if (isset($this->conftab)){
154         del_lock ($this->conftab->dn);
155         unset ($this->conftab);
156       }
157       $this->conftab= NULL;
158       $this->lognames= array();;
159       $this->cn= "";
160       unset ($_SESSION['objectinfo']);
161     }
163     /* Delete Entry if Posted action (s_action) == del
164      * The entry which will be deleted is defined in $s_entry
165      */
166     if ($s_action =="del"){
167       $this->dn= $this->conferences[$s_entry]['dn'];
169       /* Check locking */
170       if (($conf= get_lock($this->dn)) != ""){
171         $_SESSION['dn']= $this->dn;
172         return(gen_locked_message($conf, $this->dn));
173       } else {
174         add_lock ($this->dn, $this->ui->dn);
175         $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
176         $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
177         return ($display);
178       }
179     }
181     /* If department deletion is accepted ...
182      * Finally delete department
183      */
184     if (isset($_POST['delete_department_confirm'])){
185       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
186       $acl= get_module_permission($acl, "goFonConference", $this->dn);
187       if (chkacl($acl, "all") == ""){
188         $this->remove_from_parent();
189         gosa_log ("Department object'".$this->dn."' has been removed");
190         $this->reload ();
191       } else {
192         print_red (_("You have no permission to remove this department."));
193       }
194     }
196     /* Edit Entry if Posted action (s_action) == edit
197      * The entry which will be edited is defined in $s_entry
198      */
199     if ($s_action=="edit"){
201       $this->dn= $this->conferences[$s_entry]['dn'];
203       if (($conf= get_lock($this->dn)) != ""){
204         return(gen_locked_message ($conf, $this->dn));
205       }
207       /* Lock the current entry, so everyone will get the  above dialog */
208       add_lock ($this->dn, $this->ui->dn);
210       /* Set up the users ACL's for this 'dn' */
211       $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
213       /* Register conftab to trigger edit dialog */
214       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
215       $this->conftab->set_acl($this->acl);
216       $_SESSION['objectinfo']= $this->dn;
217     }
219     /* Insert new entry*/    
220     if($s_action == "new"){
221       $this->dn= "new";
222       /* Set up the users ACL's for this 'dn' */
223       $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
224       $this->dn= "new";
225       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
226       $this->acl= get_permissions ($this->conftab->dn, $this->ui->subtreeACL);
227       $this->conftab->set_acl($this->acl);
228       $this->conftab->set_acl(array(':all'));
229       $_SESSION['objectinfo']= $this->dn;
230     }
232     /* Edit finished, check and save changes */
233     if (isset($_POST['edit_finish'])){
234       /* Check tabs, will feed message array */
235       $this->conftab->last= $this->conftab->current;
236       $this->conftab->save_object();
237       $message= $this->conftab->check();
239       if (count($message) == 0){
240         if($this->conftab->save() == 1){
241           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
242           return;
243         }
244         gosa_log ("goFonConference object '".$this->dn."' has been saved");
246         if ($this->dn != "new"){
247           del_lock ($this->dn);
248         }
250         $this->conftab->save ();
251         del_lock ($this->conftab->dn);;
252         unset ($this->conftab);
253         $this->conftab= NULL;
254         unset ($_SESSION['objectinfo']);
255       } else {
256         show_errors($message);
257       }
258       
259       $this->reload();
260     }
262     /* if edit or new, show dialog */
263     if($this->conftab){
264       $display= $this->conftab->execute();
266       /* Don't show buttons if tab dialog requests this */
267       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
268         $display.= "<p style=\"text-align:right\">\n";
269         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
270         $display.= "&nbsp;\n";
271         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
272         $display.= "</p>";
273       }
274       return ($display);
275     }
277     /* Header + Departmentlist*/
278     $options= "";
279     foreach ($this->config->idepartments as $key => $value){
280       if ($conferencefilter['depselect'] == $key){
281         $options.= "<option selected value='$key'>$value</option>";
282       } else {
283         $options.= "<option value='$key'>$value</option>";
284       }
285     }
287     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
288       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
289       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
290       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
291       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
292       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new conference")."' alt='"._("New conference")."' name='user_new'>&nbsp;".
293       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
294       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
295       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").     "'>&nbsp;".
296       "</div>";
298     /* Images for delete / edit */
299     $actions = "<input type='image' src='images/edit.png'                alt='"._("edit")."'      name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
300     $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'    name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
301     
302     $actions2= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'    name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
303     /* open an entry */
304     $linkopen= "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
306     /* Set Header */
307     $divlist  = new divlist("conferenceTabs");
308     $divlist->SetSummary(_("This table displays all available conference rooms."));
309     $divlist->SetEntriesPerPage(20);
310     $divlist->SetHeader(array(
311           array("string" => "&nbsp;"),            
312           array("string" =>_("Name - Number")),
313           array("string" => _("Owner")),
314           array("string" => _("PIN")),
315           array("string" =>_("Actions"), "attach" => "style='text-align:  right;border:none'")));
317     /* Insert departments in divlist*/
318     foreach($this->departments as $key=> $val){
319       if(!isset($this->config->departments[trim($key)])){
320         $this->config->departments[trim($key)]="";
321       }
323       $non_empty="";
324       $keys= str_replace("/","\/",$key);
325       foreach($this->config->departments as $keyd=>$vald ){
326         if(preg_match("/".$keys."\/.*/",$keyd)){
327           $non_empty="full";
328         }
329       }
331       /* Prepare and insert fields*/
332       $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
333       $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
334       $a_field3 = array("string" => "&nbsp;");
335       $a_field4 = array("string" => "&nbsp;");
336       $a_field5 = array("string" => "&nbsp;",  "attach" => "style='text-align:  right;border:none'");
338       /* Add entries */
339       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
340     }
342     /* Image shown in divlist */
343     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";
345     /* Edit entry link*/
346     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
348     /* Insert conferneces*/
349     foreach($this->conferences as $conferencekey => $conference ){
350   
351       if((isset($conference['goFonPIN'][0]))&&($this->ui->dn==$conference['goFonConferenceOwner'][0])){
352         $pin = "<img src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
353       }else{
354         $pin = "&nbsp;";
355       }
357       if(isset($conference['telephoneNumber'][0])){
358         $number = " - ".$conference['telephoneNumber'][0];
359       }else{
360         $number = "&nbsp; - ?";
361       }
363       $ldap= $this->config->get_ldap_link();
364       $ldap->cd ($conference['goFonConferenceOwner'][0]);
365       $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
366       $cn = $data['cn'][0];
367  
368       $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
370       $acl= get_permissions ($conference['dn'], $this->ui->subtreeACL);
371       $this->acl =  get_module_permission($acl, "goFonConference", $conference['dn']);
373       if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
374         $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number));
375       }else{  
376         $a_field2 = array("string"=>$conference['cn'][0].$number);
377       }
378       $a_field3 = array("string"=> $cn);
379       $a_field4 = array("string"=> $pin);
381       if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
382         $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='text-align:  right;border:none'");
383       }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
384         $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='text-align:  right;border:none'");
385       }else{
386         $a_field5 = array("string"=>"&nbsp;", "attach" => "style='text-align:  right;border:none'");
387       }
389       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
390     }
392     $smarty->assign("search_image",     get_template_path('images/search.png'));
393     $smarty->assign("tree_image",       get_template_path('images/tree.png'));
394     $smarty->assign("infoimage",        get_template_path('images/info.png'));
395     $smarty->assign("launchimage",      get_template_path('images/launch.png'));
396     $smarty->assign("conferences",      $divlist->DrawList());
397     $smarty->assign("conferencehead",  $listhead);
398     $smarty->assign("deplist",          $this->config->idepartments);
399     $smarty->assign("apply",            apply_filter());
400     $smarty->assign("alphabet",         generate_alphabet());
401     $smarty->assign("hint",             print_sizelimit_warning());
403     $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
404     return($display);
405   }
408   /* Reload entries for divlist.
409    * First, reload all conferences for the current base, with the given regex
410    * Second, get all departments for the given base and regex
411    * Convert departments dn
412    */
413   function reload()
414   {
415     $conferencefilter = $_SESSION["conferencefilter"];
416     $base             = $conferencefilter['depselect'];
417     $regex            = $conferencefilter['regex'];
419     $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
420     $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
422     $this->departments= array();
424     $tmp = array();
425     foreach ($res3 as $value){
426       $tmp[strtolower($value['dn']).$value['dn']]=$value;
427     }
428     ksort($tmp);
429     foreach($tmp as $value){
430       if($value["description"][0]!=".."){
431         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
432       }else{
433         $this->departments[$value['dn']]=$value["description"][0];
434       }
435     }
436   }
438   function remove_from_parent()
439   {
440     $cfg = new conference($this->config, $this->dn);
441     $cfg->remove_from_parent();
442     $ldap= $this->config->get_ldap_link();
443     $ldap->cd ($this->dn);
444     $ldap->recursive_remove();
446     /* Optionally execute a command after we're done */
447     $this->postremove();
449     /* Delete references to object groups */
450     $ldap->cd ($this->config->current['BASE']);
451     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
452     while ($ldap->fetch()){
453       $og= new conftab($this->config, $ldap->getDN());
454       unset($og->member[$this->dn]);
455       $og->save ();
456     }
458   }
460   function remove_lock()
461   {
462     if (isset($this->dn)){
463       del_lock ($this->dn);
464     }
465   }
468 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
469 ?>