Code

Removed debug output
[gosa.git] / plugins / gofon / phoneaccount / class_phoneAccount.inc
index 20948dea2271d54ef6e39c49dcb6592049b985b7..ba00dbf23821050911858ca373af9de98e0efe5a 100644 (file)
@@ -31,12 +31,6 @@ class phoneAccount extends plugin
   var $init_HomeServer        = "0";            // Contains the dn of the server that manage this account 
   var $goFonHomeServers       = array();        // Contains all available server configurations 
     
-
-  /* CLI vars */
-  var $cli_summary            = "Manage users phone account";
-  var $cli_description        = "Some longer text\nfor help";
-  var $cli_parameters         = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* attribute list for save action */
   var $CopyPasteVars          = array("phoneNumbers","macroarray","macrostillavailable"/*"phoneNumbers" -Reset- */,
                                       "hardware_list","used_hardware");
@@ -79,16 +73,20 @@ class phoneAccount extends plugin
      *  and first server as default if necessary.
      * Check if connection is successfull for the selected server $this->goFonHomeServer
      */
+
+    /* Set available server */
+    if(isset($_SESSION['config']->data['SERVERS']['FON'])){
+      $this->goFonHomeServers = $_SESSION['config']->data['SERVERS']['FON'];
+    }
+
     $a_SETUP= array();
-    if(array_key_exists('config',$_SESSION) &&
+    if($this->is_account &&
+       array_key_exists('config',$_SESSION) &&
        array_key_exists('SERVERS',$_SESSION['config']->data) &&
        array_key_exists('FON',$_SESSION['config']->data['SERVERS']) &&
        is_callable("mysql_connect")
        ) {
 
-      /* Set available server */
-      $this->goFonHomeServers = $_SESSION['config']->data['SERVERS']['FON'];
-
       /* Servers defined? Watch here... */
       if (count($this->goFonHomeServers)){
 
@@ -111,13 +109,13 @@ class phoneAccount extends plugin
 
         $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']));
+#          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']));
+#         print_red(sprintf(_("Can't select database %s on %s."),$cur_cfg['DB'],$cur_cfg['SERVER']));
           gosa_log(mysql_error());
         }
 
@@ -251,11 +249,6 @@ class phoneAccount extends plugin
     ksort($this->hardware_list);
     $this->a_old_telenums = $this->phoneNumbers;
 
-    if($this->is_account){
-      $this->is_modified = true;
-    }
-
-
     /* Get voicemail PIN from MySQL DB 
      * Because every user can change his PIN directly from the phone
      *  without any update to the ldap
@@ -699,12 +692,15 @@ class phoneAccount extends plugin
      
       $i = 0; 
       $EXT = array();
-      $EXT[$i]['context'] = 'GOsa';
-      $EXT[$i]['exten']   = $this->uid;
-      $EXT[$i]['priority']= 1;
-      $EXT[$i]['app']     = "Goto";
-      $EXT[$i]['appdata'] = $newnums[$i_new_key]."|1";
-      $i ++;
+    
+      if(!is_numeric($this->uid)){
+        $EXT[$i]['context'] = 'GOsa';
+        $EXT[$i]['exten']   = $this->uid;
+        $EXT[$i]['priority']= 1;
+        $EXT[$i]['app']     = "Goto";
+        $EXT[$i]['appdata'] = $newnums[$i_new_key]."|1";
+        $i ++;
+      }
 
       // Entension entries  Hint / Dial / Goto
       foreach($newnums as $s_telenums){
@@ -1049,6 +1045,7 @@ class phoneAccount extends plugin
   function save_object()
   {
     if (isset($_POST["phoneTab"])){
+    
       plugin::save_object();
 
       /* Save checkbox */
@@ -1069,6 +1066,10 @@ class phoneAccount extends plugin
         $this->macrostillavailable=true;
       }
 
+      if(isset($_POST['macro']) && $_POST['macro'] != $this->macro){
+        $this->is_modified =true;
+      }
+
       if(is_array($this->phoneNumbers)){
         foreach($this->phoneNumbers as $telenumms) {
           $nummsinorder[]=$telenumms; 
@@ -1078,8 +1079,12 @@ class phoneAccount extends plugin
       }
 
       /* get all Postvars */
-      if(isset($this->macroarray[$this->macro])){ 
+      if(isset($this->macroarray[$this->macro])){
         foreach($this->macroarray[$this->macro] as $key => $paras){
+
+          $backup = $this->macroarray[$this->macro][$key];  
+
           if(isset($_POST[$paras['var']])){
             $this->macroarray[$this->macro][$key]['choosen'] = $_POST[$paras['var']];
           }
@@ -1097,6 +1102,9 @@ class phoneAccount extends plugin
               }
             }
           }
+          if(count(array_diff($this->macroarray[$this->macro][$key],$backup))){
+            $this->modified = TRUE;
+          }
         }
       }
     }
@@ -1131,8 +1139,10 @@ class phoneAccount extends plugin
       }
     }
 
-    if(!$this->generate_mysql_entension_entries()){
-      $message[] = $this->generate_error;
+    if ($this->initially_was_account != $this->is_account || $this->is_modified){
+      if(!$this->generate_mysql_entension_entries()){
+        $message[] = $this->generate_error;
+      }
     }
 
     /* We need at least one phone number */
@@ -1188,9 +1198,11 @@ class phoneAccount extends plugin
 
     $this->attrs['goFonForwarding']=array();
 
-    $str = $this->generate_mysql_entension_entries(true);
-    if(empty($str)){
-      print_red($str);
+    if ($this->initially_was_account != $this->is_account || $this->is_modified){
+      $str = $this->generate_mysql_entension_entries(true);
+      if(empty($str)){
+        print_red($str);
+      }
     }
 
     if($this->attrs['goFonMacro']==""){