Code

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