Code

239e76605c6376556af0cc56b989ac742c8b7ada
[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                      = "Managment ";
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;
49   
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     }
59   
60         }
62         /* Execute class and display something */
63         function execute()
64         {
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"]; 
72     
73     /* Start for New List Managment */
74     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
75       $s_action="open";
76       $s_entry = base64_decode($_GET['dep_id']);
77       $conferencefilter['depselect']= "".$this->config->departments[trim($s_entry)];
78     }
80     foreach($_POST as $key => $post){
81       if(preg_match("/.*new.*/i",$key)){
82         $s_action = "new";
83       // Post for delete
84       }elseif(preg_match("/conf_del.*/",$key)){
85         $s_action = "del";
86         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
87         $s_entry  = preg_replace("/_.*$/","",$s_entry);
88         // Post for edit
89       }elseif(preg_match("/conf_edit_.*/",$key)){
90         $s_action="edit";
91         $s_entry  = preg_replace("/conf_".$s_action."_/i","",$key);
92         $s_entry  = preg_replace("/_.*$/","",$s_entry);
93       }elseif(preg_match("/dep_back.*/i",$key)){
94         $s_action="back";
95       }elseif(preg_match("/dep_home.*/i",$key)){
96         $s_action="home";
97       }elseif(preg_match("/dep_root.*/i",$key)){
98         $s_action="root";
99       } 
100     }
102     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
103       $s_action = "edit";
104       $s_entry  = $_GET['id'];
105     }
107     /* Department changed? */
108     if(isset($_POST['depselect']) && $_POST['depselect']){
109       $conferencefilter['depselect']= $_POST['depselect'];
110     }
111  
112     /* Homebutton is posted */
113     if($s_action=="home"){
114       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
115       $conferencefilter['depselect']=(preg_replace("/^[^,]+,/","",$conferencefilter['depselect']));
116     }
118     if($s_action=="root"){
119       $conferencefilter['depselect']=($this->config->current['BASE']);
120     }
122     /* If Backbutton is Posted */
123     if($s_action=="back"){
124       $base_back          = preg_replace("/^[^,]+,/","",$conferencefilter['depselect']);
125       $base_back          = convert_department_dn($base_back);
127       if(isset($this->config->departments[trim($base_back)])){
128         $conferencefilter['depselect']= $this->config->departments[trim($base_back)];
129       }else{
130         $conferencefilter['depselect']= $this->config->departments["/"];
131       }
132     }
134     register_global("conferencefilter",$conferencefilter);
135     $this->reload();
137     /* Reset requested? */
138     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
139       if (isset($this->conftab)){
140         del_lock ($this->conftab->dn);
141         unset ($this->conftab);
142       }
143       $this->conftab= NULL;
144       $this->lognames= array();;
145       $this->cn= "";
146       unset ($_SESSION['objectinfo']);
147     }
149     /* Delete Entry if Posted action (s_action) == del
150      * The entry which will be deleted is defined in $s_entry
151      */
152     if ($s_action =="del"){
153       $this->dn= $this->conferences[$s_entry]['dn'];
155       /* Check locking */
156       if (($conf= get_lock($this->dn)) != ""){
157         $_SESSION['dn']= $this->dn;
158         return(gen_locked_message($conf, $this->dn));
159       } else {
160         add_lock ($this->dn, $this->ui->dn);
161         $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn));
162         $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE));
163         return ($display);
164       }
165     }
167     /* If department deletion is accepted ...
168      * Finally delete department
169      */
170     if (isset($_POST['delete_department_confirm'])){
171       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
172       $acl= get_module_permission($acl, "goFonConference", $this->dn);
173       if (chkacl($acl, "all") == ""){
174         $this->remove_from_parent();
175         gosa_log ("Department object'".$this->dn."' has been removed");
176         $this->reload ();
177       } else {
178         print_red (_("You have no permission to remove this department."));
179       }
180     }
182     /* Edit Entry if Posted action (s_action) == edit
183      * The entry which will be edited is defined in $s_entry
184      */
185     if ($s_action=="edit"){
187       $this->dn= $this->conferences[$s_entry]['dn'];
189       if (($conf= get_lock($this->dn)) != ""){
190         return(gen_locked_message ($conf, $this->dn));
191       }
193       /* Lock the current entry, so everyone will get the  above dialog */
194       add_lock ($this->dn, $this->ui->dn);
196       /* Set up the users ACL's for this 'dn' */
197       $this->acl= get_permissions ($this->dn, $this->ui->subtreeACL);
199       /* Register conftab to trigger edit dialog */
200       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
201       $this->conftab->set_acl(array(":all"));
202       $_SESSION['objectinfo']= $this->dn;
203     }
205     if($s_action == "new"){
206       $this->dn= "new";
207       $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn);
208       $this->conftab->set_acl(array(':all'));
209     }
211     if (isset($_POST['edit_finish'])){
213       /* Check tabs, will feed message array */
214       $this->conftab->last= $this->conftab->current;
215       $this->conftab->save_object();
216       $message= $this->conftab->check();
218       if (count($message) == 0){
219         if($this->conftab->save() == 1){
220           gosa_log ("goFonConference object '".$this->dn."' saving failed.");
221           return;
222         }
223         gosa_log ("goFonConference object '".$this->dn."' has been saved");
225         if ($this->dn != "new"){
226           del_lock ($this->dn);
227         }
229         $this->conftab->save ();
230         unset ($this->conftab);
231         $this->conftab= NULL;
232         unset ($_SESSION['objectinfo']);
233       } else {
234         show_errors($message);
235       }
236     }
237  
238     /* if edit or new, show dialog */
239                 if($this->conftab){
240       $display= $this->conftab->execute();
242       /* Don't show buttons if tab dialog requests this */
243       if (!$this->conftab->by_object[$this->conftab->current]->dialog){
244         $display.= "<p style=\"text-align:right\">\n";
245         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
246         $display.= "&nbsp;\n";
247         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
248         $display.= "</p>";
249       }
250       return ($display);
251     }
253     $this->reload();
254                 $listhead = "<div style='background:#F0F0F9;padding:5px;'>  
255                   <input type='image' align='middle' src='images/list_new_department.png' 
256                       align='middle' alt='"._("Create new department")."' name='dep_new'>&nbsp;
257                                   </div>";
261        $options= "";
262     foreach ($this->config->idepartments as $key => $value){
263       if ($conferencefilter['depselect'] == $key){
264         $options.= "<option selected value='$key'>$value</option>";
265       } else {
266         $options.= "<option value='$key'>$value</option>";
267       }
268     }
270         $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
271       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
272       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
273       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
274       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
275       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
276       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
277       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
278       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit").     "'>&nbsp;".
279       "</div>";
282     $actions = "<input type='image' src='images/edit.png'                alt='"._("edit")."'      name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
283                 $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'        name='conf_del_%KEY%'  title='"._("Delete this entry")."'>";
284                 $linkopen= "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
286     /* Set Header */
287                 $divlist  = new divlist("conferenceTabs");
288                 $divlist->SetSummary(_("This table displays all available conference rooms."));
289                 $divlist->SetEntriesPerPage(20);
290                 $divlist->SetHeader(array(
291           array("string" => "&nbsp;"),            
292                                         array("string" =>_("Name / nummer")),
293                                         array("string" =>_("Actions"), "attach" => "style='text-align:  right;border:none'")));
295        /* Insert departments in divlist*/
296     foreach($this->departments as $key=> $val){
298       if(!isset($this->config->departments[trim($key)])){
299         $this->config->departments[trim($key)]="";
300       }
302       $non_empty="";
303       $keys= str_replace("/","\/",$key);
304       foreach($this->config->departments as $keyd=>$vald ){
305         if(preg_match("/".$keys."\/.*/",$keyd)){
306           $non_empty="full";
307         }
308       }
310       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
311       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
312       $field3 = array("string" => "&nbsp;", "attach" => "style='border:none;width:60px;'");
315       $divlist->AddEntry(array($field1,$field2,$field3));
316     }
317     
318     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";
319     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
321     foreach($this->conferences as $conferencekey => $conference ){
322       $field1 = array("string"=>sprintf($userimg,_("Conference")));
323       $field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0]));
324       $field3 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions));
325       $divlist->AddEntry(array($field1,$field2,$field3));
326     }
328                 $smarty->assign("search_image",     get_template_path('images/search.png'));
329                 $smarty->assign("tree_image",       get_template_path('images/tree.png'));
330                 $smarty->assign("infoimage",        get_template_path('images/info.png'));
331                 $smarty->assign("launchimage",      get_template_path('images/launch.png'));
332     $smarty->assign("conferences",      $divlist->DrawList());
333     $smarty->assign("conferencehead",  $listhead);
334                 $smarty->assign("deplist",          $this->config->idepartments);
335                 $smarty->assign("apply",            apply_filter());
336                 $smarty->assign("alphabet",         generate_alphabet());
337                 $smarty->assign("hint",             print_sizelimit_warning());
339                 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
340                 return($display);
341         }
344         function reload()
345         {
346     $base = "dc=gonicus,dc=de";
347    
348     $conferencefilter = $_SESSION["conferencefilter"];
349     $base             = $conferencefilter['depselect'];
350     $regex            = $conferencefilter['regex'];
351      
352                 $this->conferences= get_list($this->ui->subtreeACL, "(objectClass=goFonConference)",TRUE, $base, array("*"), TRUE);
353     
354     /* NEW LIST MANAGMENT
355      * We also need to search for the departments
356      * So we are able to navigate like in konquerer
357      */
358     $base2 = preg_replace("/ou=people,/i","",$base);
360     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
361         TRUE, $base2, array("ou", "description"), TRUE);
363     $this->departments= array();
365     $tmp = array();
366     foreach ($res3 as $value){
367       $tmp[strtolower($value['dn']).$value['dn']]=$value;
368     }
369     ksort($tmp);
370     foreach($tmp as $value){
371       if($value["description"][0]!=".."){
372         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
373       }else{
374         $this->departments[$value['dn']]=$value["description"][0];
375       }
376     }
377     /* END NEW LIST MANAGMENT
378      */
381           
382   }
384         function remove_from_parent()
385         {
386                 $ldap= $this->config->get_ldap_link();
387                 $ldap->cd ($this->dn);
388                 $ldap->recursive_remove();
390                 /* Optionally execute a command after we're done */
391                 $this->postremove();
393                 /* Delete references to object groups */
394                 $ldap->cd ($this->config->current['BASE']);
395                 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
396                 while ($ldap->fetch()){
397                         $og= new conftab($this->config, $ldap->getDN());
398                         unset($og->member[$this->dn]);
399                         $og->save ();
400                 }
402         }
404         function remove_lock()
405         {
406                 if (isset($this->dn)){
407                         del_lock ($this->dn);
408                 }
409         }
412 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
413 ?>