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_D = ""; // 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_P = ""; // Conference Type, no PIN/PIN
39 var $goFonConferenceOptionFormat = "";
40 var $goFonConferenceOptionLifetime = "";
41 var $goFonConferenceOptionNumber = "";
43 var $old_tele_number = false;
44 var $generate_error = "";
46 /* Headpage attributes */
47 var $last_dep_sorting= "invalid";
48 var $departments= array();
50 /* attribute list for save action */
51 var $attributes= array("cn", "description", "goFonPIN","goFonConferenceOption_D","goFonConferenceOption_r",
52 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
53 "goFonConferenceOption_P","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","goFonConferenceOptionNumber");
55 var $objectclasses= array("top", "goFonConference");
57 function conference ($config, $dn)
58 {
59 plugin::plugin($config, $dn);
60 $this->is_account = TRUE;
61 $this->ui = get_userinfo();
62 $this->dn = $dn;
63 $this->orig_dn = $dn;
64 $this->config = $config;
66 /* Set base */
67 if ($this->dn == "new"){
68 $ui= get_userinfo();
69 if(isset($_SESSION['conferencefilter']['depselect'])){
70 $this->base = $_SESSION['conferencefilter']['depselect'];
71 }else{
72 $this->base= dn2base($ui->dn);
73 }
74 } else {
75 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
76 }
79 /* Parse Options ...
80 * Parameter|Lifetime|number
81 */
82 if($this->dn!="new"){
83 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
85 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
86 $varname = "goFonConferenceOption_".$tmp1[0][$i];
87 $this->$varname = $tmp1[0][$i];
88 }
90 $this->goFonConferenceOptionLifetime = $tmp1[1];
91 $this->goFonConferenceOptionNumber = $tmp1[2];
92 $this->old_tele_number = $tmp1[2];
93 }
94 }
96 function execute()
97 {
98 $this->config->departments = get_departments($this->dn);
99 $this->config->make_idepartments();
100 $smarty= get_smarty();
102 $smarty->assign("goFonConferenceOptions", array("P"=>"Conference ",""=>"Conference without PIN"));
103 $smarty->assign("goFonConferenceOptionFormats", array("wav"=>"Wave","gsm"=>"GSM","wav49"=>"Wave49"));
104 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_P);
106 foreach ($this->attributes as $val){
107 $smarty->assign("$val", $this->$val);
108 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
109 if(!$this->$val){
110 $smarty->assign($val."CHK", "");
111 }else{
112 $smarty->assign($val."CHK", " checked ");
113 }
114 }
115 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
116 }
118 function remove_from_parent()
119 {
120 $ldap= $this->config->get_ldap_link();
121 $ldap->cd ($this->dn);
122 $ldap->recursive_remove();
124 /* Optionally execute a command after we're done */
125 $this->handle_post_events('remove');
126 }
129 /* Save data to object */
130 function save_object()
131 {
132 plugin::save_object();
133 if(isset($_POST['cn'])){
134 foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
135 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P") as $attrs){
136 if(isset($_POST[$attrs])){
137 $this->$attrs = $_POST[$attrs];
138 }else{
139 $this->$attrs = false;
140 }
141 }
142 }
143 }
146 /* Check values */
147 function check()
148 {
149 $message= array();
151 if(empty($this->cn)){
152 $message[] =_("Please enter a name for the conference.");
153 }
155 if(!is_numeric($this->goFonConferenceOptionNumber)){
156 $message[] =_("Only numeric chars are allowed in Number field.");
157 }
159 if(!is_numeric($this->goFonConferenceOptionLifetime)){
160 $message[] =_("Only numbers are allowed in Lifetime.");
161 }
163 $this->SQL_remove_me(false);
164 $this->SQL_add_me(false);
166 if(!empty($this->generate_error)){
167 $message[]=$this->generate_error;
168 $this->generate_error="";
169 }
171 return $message;
172 }
175 function SQL_add_me($save){
176 // Get Configuration for Mysql database Server
177 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
179 // Connect to DB server
180 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
182 // Check if we are connected correctly
183 if(!$r_con){
184 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
185 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
186 gosa_log(mysql_error());
187 return false;
188 }
190 // Select database for Extensions
191 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
193 // Test if we have the database selected correctly
194 if(!$db){
195 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
196 gosa_log(mysql_error());
197 return false;
198 }
200 if((!empty($this->goFonConferenceOptionNumber))&&($save==true)){
202 $EXT=array();
204 $parameter ="";
205 foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
206 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P") as $attrs){
207 $parameter .= $this->$attrs;
208 }
210 $i=1;
211 $context="GOsa";
212 // Set Language to German
213 $EXT[$i]['exten'] =$this->goFonConferenceOptionNumber;
214 $EXT[$i]['context'] = $context;
215 $EXT[$i]['priority']= $i;
216 $EXT[$i]['app'] ="SetLanguage";
217 $EXT[$i]['appdata'] ="de";
218 $i++;
220 if($this->goFonConferenceOption_r == "r"){
222 // Recordingformat for conference
223 $EXT[$i]['exten'] =$this->goFonConferenceOptionNumber;
224 $EXT[$i]['context'] =$context;
225 $EXT[$i]['priority']= $i;
226 $EXT[$i]['app'] ="Setvar";
227 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
228 $i++;
230 }
232 // Answer Call
233 $EXT[$i]['exten'] =$this->goFonConferenceOptionNumber;
234 $EXT[$i]['context'] =$context;
235 $EXT[$i]['priority']=$i;
236 $EXT[$i]['app'] ="answer";
237 $EXT[$i]['appdata'] ="";
238 $i++;
240 // Start Conference
241 $EXT[$i]['exten'] =$this->goFonConferenceOptionNumber;
242 $EXT[$i]['context'] =$context;
243 $EXT[$i]['priority']=$i;
244 $EXT[$i]['app'] ="MeetMe";
245 $EXT[$i]['appdata'] =$this->goFonConferenceOptionNumber."|".$parameter."|".$this->goFonPIN;
247 $SQL=array();
249 foreach($EXT as $keytop => $valtop){
250 $s_keys = "";
251 $s_values = "";
252 foreach($valtop as $key=>$val){
253 $s_keys .="`".$key."`,";
254 $s_values .="'".$val."',";
255 }
256 $s_keys =preg_replace("/\,$/","",$s_keys);
257 $s_values =preg_replace("/\,$/","",$s_values);
258 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
259 }
260 foreach($SQL as $sqlsyn){
261 mysql_query($sqlsyn);
262 }
263 }
267 return(true);
268 }
270 function SQL_remove_me($save){
272 if($this->old_tele_number){
273 // Get Configuration for Mysql database Server
274 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
276 // Connect to DB server
277 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
279 // Check if we are connected correctly
280 if(!$r_con){
281 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
282 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
283 gosa_log(mysql_error());
284 return false;
285 }
287 // Select database for Extensions
288 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
290 // Test if we have the database selected correctly
291 if(!$db){
292 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
293 gosa_log(mysql_error());
294 return false;
295 }
297 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."') OR (exten='".$this->goFonConferenceOptionNumber."')";
299 if($save){
300 @mysql_query($SQL);
301 }
303 }//ENDE old num availiable ...
304 return(true);
305 }
308 /* Save to LDAP */
309 function save()
310 {
311 plugin::save();
313 $this->SQL_remove_me(true);
314 $this->SQL_add_me(true);
316 $this->attrs['goFonConferenceOption']="";
317 foreach(array("goFonConferenceOption_D","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
318 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_P","goFonConferenceOptionFormat") as $attrs){
319 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
320 unset($this->attrs[$attrs]);
321 }
323 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
324 unset($this->attrs['goFonConferenceOptionLifetime']);
326 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionNumber;
327 unset($this->attrs['goFonConferenceOptionNumber']);
330 /* Write back to ldap */
331 $ldap= $this->config->get_ldap_link();
332 $ldap->cat($this->dn);
333 $a= $ldap->fetch();
334 $ldap->cd($this->dn);
335 if (count($a)){
336 $ldap->modify($this->attrs);
337 $this->handle_post_events('modify');
338 } else {
339 $ldap->add($this->attrs);
340 $this->handle_post_events('add');
341 }
342 show_ldap_error($ldap->get_error());
344 /* Optionally execute a command after we're done */
345 $this->postcreate();
346 }
348 }
350 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
351 ?>