Code

d36d79d607558fcb4e3df9587cc73e0390f2dcfc
[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 conference";
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(array(":all"));
216       $_SESSION['objectinfo']= $this->dn;
217     }
219     /* Insert new entry*/    
220     if($s_action == "new"){
221       $this->dn= "new";
222       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
223       $this->conftab->set_acl(array(':all'));
224     }
226     /* Edit finished, check and save changes */
227     if (isset($_POST['edit_finish'])){
228       /* Check tabs, will feed message array */
229       $this->conftab->last= $this->conftab->current;
230       $this->conftab->save_object();
231       $message= $this->conftab->check();
233       if (count($message) == 0){
234         if($this->conftab->save() == 1){
235           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
236           return;
237         }
238         gosa_log ("goFonConference object '".$this->dn."' has been saved");
240         if ($this->dn != "new"){
241           del_lock ($this->dn);
242         }
244         $this->conftab->save ();
245         unset ($this->conftab);
246         $this->conftab= NULL;
247         unset ($_SESSION['objectinfo']);
248       } else {
249         show_errors($message);
250       }
251     }
253     /* if edit or new, show dialog */
254     if($this->conftab){
255       $display= $this->conftab->execute();
257       /* Don't show buttons if tab dialog requests this */
258       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
259         $display.= "<p style=\"text-align:right\">\n";
260         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
261         $display.= "&nbsp;\n";
262         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
263         $display.= "</p>";
264       }
265       return ($display);
266     }
268     /* Header + Departmentlist*/
269     $options= "";
270     foreach ($this->config->idepartments as $key => $value){
271       if ($conferencefilter['depselect'] == $key){
272         $options.= "<option selected value='$key'>$value</option>";
273       } else {
274         $options.= "<option value='$key'>$value</option>";
275       }
276     }
278     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
279       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
280       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
281       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
282       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
283       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
284       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
285       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
286       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").     "'>&nbsp;".
287       "</div>";
289     /* Images for delete / edit */
290     $actions = "<input type='image' src='images/edit.png'                alt='"._("edit")."'      name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
291     $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'    name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
293     /* open an entry */
294     $linkopen= "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
296     /* Set Header */
297     $divlist  = new divlist("conferenceTabs");
298     $divlist->SetSummary(_("This table displays all available conference rooms."));
299     $divlist->SetEntriesPerPage(20);
300     $divlist->SetHeader(array(
301           array("string" => "&nbsp;"),            
302           array("string" =>_("Name / nummer")),
303           array("string" =>_("Actions"), "attach" => "style='text-align:  right;border:none'")));
305     /* Insert departments in divlist*/
306     foreach($this->departments as $key=> $val){
307       if(!isset($this->config->departments[trim($key)])){
308         $this->config->departments[trim($key)]="";
309       }
311       $non_empty="";
312       $keys= str_replace("/","\/",$key);
313       foreach($this->config->departments as $keyd=>$vald ){
314         if(preg_match("/".$keys."\/.*/",$keyd)){
315           $non_empty="full";
316         }
317       }
319       /* Prepare and insert fields*/
320       $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
321       $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
322       $a_field3 = array("string" => "&nbsp;", "attach" => "style='border:none;width:60px;'");
324       /* Add entries */
325       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3));
326     }
328     /* Image shown in divlist */
329     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";
331     /* Edit entry link*/
332     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
334     /* Insert conferneces*/
335     foreach($this->conferences as $conferencekey => $conference ){
336       $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
337       $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0]));
338       $a_field3 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions));
339       $divlist->AddEntry(array($a_field1,$a_field2,$a_field3));
340     }
342     $smarty->assign("search_image",     get_template_path('images/search.png'));
343     $smarty->assign("tree_image",       get_template_path('images/tree.png'));
344     $smarty->assign("infoimage",        get_template_path('images/info.png'));
345     $smarty->assign("launchimage",      get_template_path('images/launch.png'));
346     $smarty->assign("conferences",      $divlist->DrawList());
347     $smarty->assign("conferencehead",  $listhead);
348     $smarty->assign("deplist",          $this->config->idepartments);
349     $smarty->assign("apply",            apply_filter());
350     $smarty->assign("alphabet",         generate_alphabet());
351     $smarty->assign("hint",             print_sizelimit_warning());
353     $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
354     return($display);
355   }
358   /* Reload entries for divlist.
359    * First, reload all conferences for the current base, with the given regex
360    * Second, get all departments for the given base and regex
361    * Convert departments dn
362    */
363   function reload()
364   {
365     $conferencefilter = $_SESSION["conferencefilter"];
366     $base             = $conferencefilter['depselect'];
367     $regex            = $conferencefilter['regex'];
369     $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
370     $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
372     $this->departments= array();
374     $tmp = array();
375     foreach ($res3 as $value){
376       $tmp[strtolower($value['dn']).$value['dn']]=$value;
377     }
378     ksort($tmp);
379     foreach($tmp as $value){
380       if($value["description"][0]!=".."){
381         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
382       }else{
383         $this->departments[$value['dn']]=$value["description"][0];
384       }
385     }
386   }
388   function remove_from_parent()
389   {
390     $ldap= $this->config->get_ldap_link();
391     $ldap->cd ($this->dn);
392     $ldap->recursive_remove();
394     /* Optionally execute a command after we're done */
395     $this->postremove();
397     /* Delete references to object groups */
398     $ldap->cd ($this->config->current['BASE']);
399     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
400     while ($ldap->fetch()){
401       $og= new conftab($this->config, $ldap->getDN());
402       unset($og->member[$this->dn]);
403       $og->save ();
404     }
406   }
408   function remove_lock()
409   {
410     if (isset($this->dn)){
411       del_lock ($this->dn);
412     }
413   }
416 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
417 ?>