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 }
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 $this->reload();
252 }
254 /* if edit or new, show dialog */
255 if($this->conftab){
256 $display= $this->conftab->execute();
258 /* Don't show buttons if tab dialog requests this */
259 if (!$this->conftab->by_object[$this->conftab->current]->dialog){
260 $display.= "<p style=\"text-align:right\">\n";
261 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
262 $display.= " \n";
263 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
264 $display.= "</p>";
265 }
266 return ($display);
267 }
269 /* Header + Departmentlist*/
270 $options= "";
271 foreach ($this->config->idepartments as $key => $value){
272 if ($conferencefilter['depselect'] == $key){
273 $options.= "<option selected value='$key'>$value</option>";
274 } else {
275 $options.= "<option value='$key'>$value</option>";
276 }
277 }
279 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
280 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
281 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
282 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
283 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
284 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
285 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
286 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
287 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit"). "'> ".
288 "</div>";
290 /* Images for delete / edit */
291 $actions = "<input type='image' src='images/edit.png' alt='"._("edit")."' name='conf_edit_%KEY%' title='"._("Edit this entry")."'>";
292 $actions.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
294 $actions2= "<input type='image' src='images/edittrash.png' alt='"._("delete")."' name='conf_del_%KEY%' title='"._("Delete this entry")."'>";
295 /* open an entry */
296 $linkopen= "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
298 /* Set Header */
299 $divlist = new divlist("conferenceTabs");
300 $divlist->SetSummary(_("This table displays all available conference rooms."));
301 $divlist->SetEntriesPerPage(20);
302 $divlist->SetHeader(array(
303 array("string" => " "),
304 array("string" =>_("Name / nummer")),
305 array("string" => _("Owner")),
306 array("string" => _("PIN")),
307 array("string" =>_("Actions"), "attach" => "style='text-align: right;border:none'")));
309 /* Insert departments in divlist*/
310 foreach($this->departments as $key=> $val){
311 if(!isset($this->config->departments[trim($key)])){
312 $this->config->departments[trim($key)]="";
313 }
315 $non_empty="";
316 $keys= str_replace("/","\/",$key);
317 foreach($this->config->departments as $keyd=>$vald ){
318 if(preg_match("/".$keys."\/.*/",$keyd)){
319 $non_empty="full";
320 }
321 }
323 /* Prepare and insert fields*/
324 $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
325 $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
326 $a_field3 = array("string" => " ");
327 $a_field4 = array("string" => " ");
328 $a_field5 = array("string" => " ", "attach" => "style='text-align: right;border:none'");
330 /* Add entries */
331 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
332 }
334 /* Image shown in divlist */
335 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
337 /* Edit entry link*/
338 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
340 /* Insert conferneces*/
341 foreach($this->conferences as $conferencekey => $conference ){
343 if((isset($conference['goFonPIN'][0]))&&($this->ui->dn==$conference['goFonConferenceOwner'][0])){
344 $pin = "<img src='images/list_password.png' title='PIN : ".$conference['goFonPIN'][0]."' alt='PIN'>";
345 }else{
346 $pin = " ";
347 }
349 if(isset($conference['telephoneNumber'][0])){
350 $number = " - ".$conference['telephoneNumber'][0];
351 }else{
352 $number = " - ?";
353 }
355 $ldap= $this->config->get_ldap_link();
356 $ldap->cd ($conference['goFonConferenceOwner'][0]);
357 $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
358 $cn = $data['cn'][0];
360 $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
362 $acl= get_permissions ($conference['dn'], $this->ui->subtreeACL);
363 $this->acl = get_module_permission($acl, "goFonConference", $conference['dn']);
365 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
366 $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0].$number));
367 }else{
368 $a_field2 = array("string"=>$conference['cn'][0].$number);
369 }
370 $a_field3 = array("string"=> $cn);
371 $a_field4 = array("string"=> $pin);
373 if(($this->ui->dn==$conference['goFonConferenceOwner'][0])&&(chkacl($this->acl,"goFonConferenceOwner")=="")){
374 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions), "attach" => "style='text-align: right;border:none'");
375 }elseif(chkacl($this->acl,"goFonConferenceOwner")==""){
376 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions2), "attach" => "style='text-align: right;border:none'");
377 }else{
378 $a_field5 = array("string"=>" ", "attach" => "style='text-align: right;border:none'");
379 }
381 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
382 }
384 $smarty->assign("search_image", get_template_path('images/search.png'));
385 $smarty->assign("tree_image", get_template_path('images/tree.png'));
386 $smarty->assign("infoimage", get_template_path('images/info.png'));
387 $smarty->assign("launchimage", get_template_path('images/launch.png'));
388 $smarty->assign("conferences", $divlist->DrawList());
389 $smarty->assign("conferencehead", $listhead);
390 $smarty->assign("deplist", $this->config->idepartments);
391 $smarty->assign("apply", apply_filter());
392 $smarty->assign("alphabet", generate_alphabet());
393 $smarty->assign("hint", print_sizelimit_warning());
395 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
396 return($display);
397 }
400 /* Reload entries for divlist.
401 * First, reload all conferences for the current base, with the given regex
402 * Second, get all departments for the given base and regex
403 * Convert departments dn
404 */
405 function reload()
406 {
407 $conferencefilter = $_SESSION["conferencefilter"];
408 $base = $conferencefilter['depselect'];
409 $regex = $conferencefilter['regex'];
411 $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
412 $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
414 $this->departments= array();
416 $tmp = array();
417 foreach ($res3 as $value){
418 $tmp[strtolower($value['dn']).$value['dn']]=$value;
419 }
420 ksort($tmp);
421 foreach($tmp as $value){
422 if($value["description"][0]!=".."){
423 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
424 }else{
425 $this->departments[$value['dn']]=$value["description"][0];
426 }
427 }
428 }
430 function remove_from_parent()
431 {
432 $ldap= $this->config->get_ldap_link();
433 $ldap->cd ($this->dn);
434 $ldap->recursive_remove();
436 /* Optionally execute a command after we're done */
437 $this->postremove();
439 /* Delete references to object groups */
440 $ldap->cd ($this->config->current['BASE']);
441 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
442 while ($ldap->fetch()){
443 $og= new conftab($this->config, $ldap->getDN());
444 unset($og->member[$this->dn]);
445 $og->save ();
446 }
448 }
450 function remove_lock()
451 {
452 if (isset($this->dn)){
453 del_lock ($this->dn);
454 }
455 }
457 }
458 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
459 ?>