0c78457f10fb967a8fba9c0f115ebd65e9ee757d
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 }
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 /* open an entry */
295 $linkopen= "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
297 /* Set Header */
298 $divlist = new divlist("conferenceTabs");
299 $divlist->SetSummary(_("This table displays all available conference rooms."));
300 $divlist->SetEntriesPerPage(20);
301 $divlist->SetHeader(array(
302 array("string" => " "),
303 array("string" =>_("Name / nummer")),
304 array("string" => _("Owner")),
305 array("string" => _("PIN")),
306 array("string" =>_("Actions"), "attach" => "style='text-align: right;border:none'")));
308 /* Insert departments in divlist*/
309 foreach($this->departments as $key=> $val){
310 if(!isset($this->config->departments[trim($key)])){
311 $this->config->departments[trim($key)]="";
312 }
314 $non_empty="";
315 $keys= str_replace("/","\/",$key);
316 foreach($this->config->departments as $keyd=>$vald ){
317 if(preg_match("/".$keys."\/.*/",$keyd)){
318 $non_empty="full";
319 }
320 }
322 /* Prepare and insert fields*/
323 $a_field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>","attach"=>"style='width:22px;'");
324 $a_field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
325 $a_field3 = array("string" => " ");
326 $a_field4 = array("string" => " ");
327 $a_field5 = array("string" => " ", "attach" => "style='border:none;width:60px;'");
329 /* Add entries */
330 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
331 }
333 /* Image shown in divlist */
334 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
336 /* Edit entry link*/
337 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
339 /* Insert conferneces*/
340 foreach($this->conferences as $conferencekey => $conference ){
342 if(isset($conference['goFonPIN'][0])){
343 $pin = $conference['goFonPIN'][0];
344 }else{
345 $pin = " ";
346 }
347 $ldap= $this->config->get_ldap_link();
348 $ldap->cd ($conference['goFonConferenceOwner'][0]);
349 $data = $ldap->fetch($ldap->cat($conference['goFonConferenceOwner'][0]));
350 $cn = $data['cn'][0];
352 $a_field1 = array("string"=>sprintf($userimg,_("Conference")));
353 $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$conference['cn'][0]));
354 $a_field3 = array("string"=> $cn);
355 $a_field4 = array("string"=> $pin);
356 $a_field5 = array("string"=>preg_replace("/%KEY%/",$conferencekey,$actions));
357 $divlist->AddEntry(array($a_field1,$a_field2,$a_field3,$a_field4,$a_field5));
358 }
360 $smarty->assign("search_image", get_template_path('images/search.png'));
361 $smarty->assign("tree_image", get_template_path('images/tree.png'));
362 $smarty->assign("infoimage", get_template_path('images/info.png'));
363 $smarty->assign("launchimage", get_template_path('images/launch.png'));
364 $smarty->assign("conferences", $divlist->DrawList());
365 $smarty->assign("conferencehead", $listhead);
366 $smarty->assign("deplist", $this->config->idepartments);
367 $smarty->assign("apply", apply_filter());
368 $smarty->assign("alphabet", generate_alphabet());
369 $smarty->assign("hint", print_sizelimit_warning());
371 $display= $smarty->fetch(get_template_path('headpage.tpl', TRUE));
372 return($display);
373 }
376 /* Reload entries for divlist.
377 * First, reload all conferences for the current base, with the given regex
378 * Second, get all departments for the given base and regex
379 * Convert departments dn
380 */
381 function reload()
382 {
383 $conferencefilter = $_SESSION["conferencefilter"];
384 $base = $conferencefilter['depselect'];
385 $regex = $conferencefilter['regex'];
387 $this->conferences=get_list($this->ui->subtreeACL, "(&(|(cn=$regex)(description=$regex))(objectClass=goFonConference))",FALSE, $base, array("*"), TRUE);
388 $res3=get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",TRUE, $base, array("ou", "description"), TRUE);
390 $this->departments= array();
392 $tmp = array();
393 foreach ($res3 as $value){
394 $tmp[strtolower($value['dn']).$value['dn']]=$value;
395 }
396 ksort($tmp);
397 foreach($tmp as $value){
398 if($value["description"][0]!=".."){
399 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
400 }else{
401 $this->departments[$value['dn']]=$value["description"][0];
402 }
403 }
404 }
406 function remove_from_parent()
407 {
408 $ldap= $this->config->get_ldap_link();
409 $ldap->cd ($this->dn);
410 $ldap->recursive_remove();
412 /* Optionally execute a command after we're done */
413 $this->postremove();
415 /* Delete references to object groups */
416 $ldap->cd ($this->config->current['BASE']);
417 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
418 while ($ldap->fetch()){
419 $og= new conftab($this->config, $ldap->getDN());
420 unset($og->member[$this->dn]);
421 $og->save ();
422 }
424 }
426 function remove_lock()
427 {
428 if (isset($this->dn)){
429 del_lock ($this->dn);
430 }
431 }
433 }
434 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
435 ?>