diff --git a/plugins/gofon/phoneaccount/class_phoneAccount.inc b/plugins/gofon/phoneaccount/class_phoneAccount.inc
index 099a16f5ec8137be403f917f49bd28c2db295699..56347c7032c1533f3b9b7ec08f93b2cda2585ab3 100644 (file)
/* Set available server */
$this->goFonHomeServers = $_SESSION['config']->data['SERVERS']['FON'];
- /* Set default server */
- if($this->dn == "new"){
- $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
- }
+ /* Servers defined? Watch here... */
+ if (count($this->goFonHomeServers)){
- /* Remember inital home server, to be able to remove old entries */
- $this->init_HomeServer = $this->goFonHomeServer;
+ /* Set default server */
+ if(empty($this->goFonHomeServer) || $this->goFonHomeServer == "0"){
+ $this->goFonHomeServer= $this->goFonHomeServers[0]['DN'];
+ }
- /* get config */
- $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
+ /* Remember inital home server, to be able to remove old entries */
+ $this->init_HomeServer = $this->goFonHomeServer;
- $r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
- if(!$r_con){
- $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
- $cur_cfg['SERVER'],$cur_cfg['LOGIN']);
- gosa_log(mysql_error());
- return false;
- }
- $db = @mysql_select_db($cur_cfg['DB'],$r_con);
- if(!$db){
- $this->generate_error = sprintf(_("Can't select database %s on %s."),$cur_cfg['DB'],$cur_cfg['SERVER']);
- gosa_log(mysql_error());
- return false;
- }
-
- $first = false;
- foreach($this->phoneNumbers as $key => $val){
- if(!$first){
- $first = $key;
+ /* Get config */
+ if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
+ print_red(sprintf(_("The specified goFonHomeServer '%s' is not available in GOsa server configuration. Saving this account will create a new entry on the server '%s'. Use cancel if you do not want to create a new entry ignoring old accounts."),$this->goFonHomeServer, $this->goFonHomeServers[0]['DN']));
+
+ $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
+ $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
+ }
+ $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
+
+ $r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']);
+ if(!$r_con){
+ print_red( sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
+ $cur_cfg['SERVER'],$cur_cfg['LOGIN']));
+ gosa_log(mysql_error());
+ }
+ $db = @mysql_select_db($cur_cfg['DB'],$r_con);
+ if(!$db){
+ print_red(sprintf(_("Can't select database %s on %s."),$cur_cfg['DB'],$cur_cfg['SERVER']));
+ gosa_log(mysql_error());
+ }
+
+ $first = false;
+ foreach($this->phoneNumbers as $key => $val){
+ if(!$first){
+ $first = $key;
+ }
}
}
}
-
/* Get available phone hardware
* Search for all available phone hardware
*/
* Search for all Marcos that are visible and create
* an array with name and parameters
*/
- $ldap->search("((objectClass=goFonMacro)(goFonMacroVisible=1))", array("*"));
+ $ldap->search("(&(objectClass=goFonMacro)(goFonMacroVisible=1))", array("*"));
/* Add none for no macro*/
$this->macros['none']=_("no macro");
unset($tmp[0]);
/* Check if makro has been removed */
- if(!isset($this->macroarray[$this->macro])){
+ if(!isset($this->macros[$this->macro])){
$this->macrostillavailable = false;
}else{
$this->macrostillavailable = true;
$this->generate_error = sprintf(
_("The MySQL Server '%s' isn't reachable as user '%s'. Abort saving entries to keep the database consistent, check GOsa log for mysql error."),
$a_New['SERVER'],$a_New['LOGIN']);
- gosa_log(mysql_error($new_connection));
+ gosa_log(@mysql_error($new_connection));
return false;
}
$new_database = @mysql_select_db($a_New['DB'],$new_connection);
$this->generate_error = sprintf(
_("Can't select database %s on %s. Abort saving entries to keep the database consistent, check GOsa log for mysql error."),
$a_New['DB'],$a_New['SERVER']);
- gosa_log(mysql_error($new_connection));
+ gosa_log( @mysql_error($new_connection));
return false;
}
$this->generate_error = sprintf(
_("The old MySQL home server '%s' isn't reachable as user '%s'. Abort saving entries to keep the database consistent, check GOsa log for mysql error."),
$a_Remove['SERVER'],$a_Remove['LOGIN']);
- gosa_log(mysql_error($old_connection));
+ gosa_log(@mysql_error($old_connection));
return false;
}
$old_database = @mysql_select_db($a_Remove['DB'],$old_connection);
$this->generate_error = sprintf(
_("Can't select database %s on %s. Abort saving entries to keep the database consistent, check GOsa log for mysql error."),
$a_Remove['DB'],$a_Remove['SERVER']);
- gosa_log(mysql_error($old_connection));
+ gosa_log(@mysql_error($old_connection));
return false;
}
}
$sip_data_array['host'] = $s_host;
$sip_data_array['insecure'] = NULL;
$sip_data_array['language'] = NULL;
- $sip_data_array['mailbox'] = "asterisk";
+ $sip_data_array['mailbox'] = $newnums[$i_new_key];
$sip_data_array['md5secret'] = NULL;
$sip_data_array['nat'] = "no";
$sip_data_array['permit'] = NULL;
$EXT[$i]['exten'] = $s_telenums;
$EXT[$i]['priority']= "Hint";
$EXT[$i]['app'] = 'SIP/'.$this->uid;
- $EXT[$i]['appdata'] = '';
$i ++;
/* SetCID */
//$EXT[$i]['context'] = 'GOsa';
}
// Perform queries ...
- foreach($SQL_query_array as $query){
- if(!@mysql_query($query,$new_connection)){
- print_red(_("Error while performing query:")." ".mysql_error());
- return false;
+ if($this->goFonHardware != "automatic"){
+ foreach($SQL_query_array as $query){
+ if(!@mysql_query($query,$new_connection)){
+ print_red(_("Error while performing query:")." ".mysql_error());
+ return false;
+ }
}
}
}
/* Call common method to give check the hook */
$message= plugin::check();
+ if(!count($this->goFonHomeServers)){
+ $message[] = _("There must be at least one server with an asterisk database to create a phone account.");
+ }
+
+ if(empty($this->goFonHomeServer)){
+ $message[] = _("Please select a valid goFonHomeServer.");
+ }
+
if((strlen($this->goFonVoicemailPIN)==0)||(strlen($this->goFonVoicemailPIN)>4)){
$message[]=(_("Voicemail PIN must be between 1-4 characters."));
}else{
{
plugin::save();
+ /* Force saving macro again
+ * This ensures that
+ * - the macro is available on the destiantion server.
+ * - the macro saved is up to date on the destination server.
+ */
+ if(!empty($this->macro) && $this->macro != "none") {
+ $macro_tab = new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->macro);
+ $macro_tab -> save();
+ }
+
/* Save arrays */
$tmp_numbers = array();
foreach ($this->phoneNumbers as $number){
$this->attrs['goFonForwarding']=array();
- $this->generate_mysql_entension_entries(true);
+ $str = $this->generate_mysql_entension_entries(true);
+ if(empty($str)){
+ print_red($str);
+ }
if($this->attrs['goFonMacro']==""){
$this->attrs['goFonMacro']=array();
$this->goFonPIN = $_POST['goFonPIN'];
}
}
+
+
+ function allow_remove()
+ {
+ /* Check if previously selected server is still available */
+ if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
+ return sprintf(_("The previously selected asterisk home server (%s) is no longer available. Remove aborted."),preg_replace("/,/",", ",$this->goFonHomeServer));
+ }
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: