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 */
21 class conference extends plugin
22 {
23 /* department attributes */
24 var $cn = "";
25 var $description = "";
26 var $base = "";
27 var $ou = "";
28 var $goFonPIN = "";
30 var $goFonConferenceOption = "";
31 var $goFonConferenceOption_P = ""; // Set PIN
32 var $goFonConferenceOption_r = ""; // record Conference
33 var $goFonConferenceOption_M = ""; // Play Music opn hold
34 var $goFonConferenceOption_s = ""; // activate menu
35 var $goFonConferenceOption_i = ""; // announce new and leaving user
36 var $goFonConferenceOption_c = ""; // Count User
37 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
39 var $goFonConferenceOptionFormat = "";
40 var $goFonConferenceOptionLifetime = "";
41 var $telephoneNumber = "";
43 var $old_tele_number = false;
44 var $generate_error = "";
46 var $old_dn;
48 /* Headpage attributes */
49 var $last_dep_sorting= "invalid";
50 var $departments= array();
52 /* attribute list for save action */
53 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
54 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
55 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber");
57 var $objectclasses= array("top", "goFonConference");
59 function conference ($config, $dn)
60 {
61 plugin::plugin($config, $dn);
62 $this->is_account = TRUE;
63 $this->ui = get_userinfo();
64 $this->dn = $dn;
65 $this->orig_dn = $dn;
66 $this->config = $config;
68 /* Set base */
69 if ($this->dn == "new"){
70 $ui= get_userinfo();
71 if(isset($_SESSION['conferencefilter']['depselect'])){
72 $this->base = $_SESSION['conferencefilter']['depselect'];
73 }else{
74 $this->base= dn2base($ui->dn);
75 }
76 } else {
77 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
78 }
81 /* Parse Options ...
82 * Parameter|Lifetime|number
83 */
84 if($this->dn!="new"){
85 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
87 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
88 $varname = "goFonConferenceOption_".$tmp1[0][$i];
89 if($tmp1[0][$i]=="d"){
90 $this->goFonConferenceOption_D = $tmp1[0][$i];
91 }else{
92 $this->$varname = $tmp1[0][$i];
93 }
94 }
96 $this->goFonConferenceOptionLifetime = $tmp1[1];
97 $this->old_tele_number = $this->telephoneNumber;
98 }
99 $this->old_dn = $this->dn;
100 }
102 function execute()
103 {
104 $this->config->departments = get_departments($this->dn);
105 $this->config->make_idepartments();
106 $smarty= get_smarty();
108 $smarty->assign("bases" ,array_flip($this->config->departments));
109 $smarty->assign("base" ,$this->base);
111 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
112 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
113 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
115 foreach ($this->attributes as $val){
116 $smarty->assign("$val", $this->$val);
117 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
118 if(!$this->$val){
119 $smarty->assign($val."CHK", "");
120 }else{
121 $smarty->assign($val."CHK", " checked ");
122 }
123 }
124 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
125 }
127 function remove_from_parent()
128 {
129 $ldap= $this->config->get_ldap_link();
130 $ldap->cd ($this->dn);
131 $ldap->recursive_remove();
133 /* Optionally execute a command after we're done */
134 $this->handle_post_events('remove');
135 }
138 /* Save data to object */
139 function save_object()
140 {
141 plugin::save_object();
142 if(isset($_POST['cn'])){
143 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
144 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
145 if(isset($_POST[$attrs])){
146 $this->$attrs = $_POST[$attrs];
147 }else{
148 $this->$attrs = false;
149 }
150 }
151 }
152 }
155 /* Check values */
156 function check()
157 {
158 $message= array();
160 if($this->is_number_used()){
161 $message[] = $this->is_number_used();
162 }
164 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
165 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
166 }
168 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
169 $message[]= _("Please enter a PIN.");
170 }
172 if(empty($this->cn)){
173 $message[] =_("Please enter a name for the conference.");
174 }
176 if(!is_numeric($this->telephoneNumber)){
177 $message[] =_("Only numeric chars are allowed in Number field.");
178 }
180 if(!is_numeric($this->goFonConferenceOptionLifetime)){
181 $message[] =_("Only numbers are allowed in Lifetime.");
182 }
184 $this->SQL_remove_me(false);
185 $this->SQL_add_me(false);
187 if(!empty($this->generate_error)){
188 $message[]=$this->generate_error;
189 $this->generate_error="";
190 }
192 return $message;
193 }
196 function SQL_add_me($save){
197 // Get Configuration for Mysql database Server
198 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
200 // Connect to DB server
201 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
203 // Check if we are connected correctly
204 if(!$r_con){
205 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
206 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
207 gosa_log(mysql_error());
208 return false;
209 }
211 // Select database for Extensions
212 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
214 // Test if we have the database selected correctly
215 if(!$db){
216 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
217 gosa_log(mysql_error());
218 return false;
219 }
221 if((!empty($this->telephoneNumber))&&($save==true)){
223 $EXT=array();
225 $parameter ="";
226 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
227 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
228 $parameter .= $this->$attrs;
229 }
231 $i=1;
232 $context="GOsa";
233 // Set Language to German
234 $EXT[$i]['exten'] =$this->telephoneNumber;
235 $EXT[$i]['context'] = $context;
236 $EXT[$i]['priority']= $i;
237 $EXT[$i]['app'] ="SetLanguage";
238 $EXT[$i]['appdata'] ="de";
239 $i++;
241 if($this->goFonConferenceOption_r == "r"){
243 // Recordingformat for conference
244 $EXT[$i]['exten'] =$this->telephoneNumber;
245 $EXT[$i]['context'] =$context;
246 $EXT[$i]['priority']= $i;
247 $EXT[$i]['app'] ="Setvar";
248 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
249 $i++;
251 }
253 // Answer Call
254 $EXT[$i]['exten'] =$this->telephoneNumber;
255 $EXT[$i]['context'] =$context;
256 $EXT[$i]['priority']=$i;
257 $EXT[$i]['app'] ="answer";
258 $EXT[$i]['appdata'] ="";
259 $i++;
261 // Start Conference
262 $EXT[$i]['exten'] =$this->telephoneNumber;
263 $EXT[$i]['context'] =$context;
264 $EXT[$i]['priority']=$i;
265 $EXT[$i]['app'] ="MeetMe";
267 if(empty($this->goFonPIN)) {
268 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
269 }else{
270 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
271 }
272 $i++;
274 // Start Conference
275 $EXT[$i]['exten'] =$this->cn;
276 $EXT[$i]['context'] =$context;
277 $EXT[$i]['priority']=1;
278 $EXT[$i]['app'] ="Goto";
279 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
280 $SQL=array();
282 foreach($EXT as $keytop => $valtop){
283 $s_keys = "";
284 $s_values = "";
285 foreach($valtop as $key=>$val){
286 $s_keys .="`".$key."`,";
287 $s_values .="'".$val."',";
288 }
289 $s_keys =preg_replace("/\,$/","",$s_keys);
290 $s_values =preg_replace("/\,$/","",$s_values);
291 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
292 }
293 foreach($SQL as $sqlsyn){
294 mysql_query($sqlsyn);
295 }
296 }
300 return(true);
301 }
303 function SQL_remove_me($save){
305 if($this->old_tele_number){
306 // Get Configuration for Mysql database Server
307 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
309 // Connect to DB server
310 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
312 // Check if we are connected correctly
313 if(!$r_con){
314 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
315 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
316 gosa_log(mysql_error());
317 return false;
318 }
320 // Select database for Extensions
321 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
323 // Test if we have the database selected correctly
324 if(!$db){
325 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
326 gosa_log(mysql_error());
327 return false;
328 }
330 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."')
331 OR (exten='".$this->telephoneNumber."')
332 OR (exten='".$this->cn."')";
334 if($save){
335 @mysql_query($SQL);
336 }
338 }//ENDE old num availiable ...
339 return(true);
340 }
344 /* This function checks if the given phonenumbers are available or already in use*/
345 function is_number_used()
346 {
347 $ldap= $this->config->get_ldap_link();
348 $ldap->cd($this->config->current['BASE']);
349 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
350 while($attrs = $ldap->fetch()) {
351 unset($attrs['telephoneNumber']['count']);
352 foreach($attrs['telephoneNumber'] as $tele){
353 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
354 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
355 $numbers[$tele]=$attrs;
356 }
357 }
359 $num = $this->telephoneNumber;
360 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->cn))){
361 if(isset($numbers[$num]['uid'][0])){
362 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
363 }else{
364 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
365 }
366 }
367 }
373 /* Save to LDAP */
374 function save()
375 {
376 plugin::save();
378 $this->SQL_remove_me(true);
379 $this->SQL_add_me(true);
381 $this->attrs['goFonConferenceOption']="";
382 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
383 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
384 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
385 unset($this->attrs[$attrs]);
386 }
388 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
389 unset($this->attrs['goFonConferenceOptionLifetime']);
391 /* Write back to ldap */
393 unset($this->attrs['base']);
395 $ldap= $this->config->get_ldap_link();
397 $ldap->cat($this->dn);
398 $a= $ldap->fetch();
399 $ldap->cd($this->dn);
400 if (count($a)){
401 $ldap->modify($this->attrs);
402 $this->handle_post_events('modify');
403 } else {
404 $ldap->add($this->attrs);
405 $this->handle_post_events('add');
406 }
407 show_ldap_error($ldap->get_error());
409 /* Optionally execute a command after we're done */
410 $this->postcreate();
411 }
413 }
415 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
416 ?>