Code

Updated macro checks
[gosa.git] / plugins / gofon / macro / class_gofonMacro.inc
old mode 100755 (executable)
new mode 100644 (file)
index 93c0859..6043a63
@@ -9,13 +9,6 @@
 */
 class macro extends plugin
 {
-  /*! CLI vars */
-  var $cli_summary= "Handling of GOsa's macro object";
-  /*! CLI vars */
-  var $cli_description= "Some longer text\nfor help";
-  /*! CLI vars */
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /*! Macro attributes,  */
   var $generate_error= "";
   
@@ -49,6 +42,8 @@ class macro extends plugin
 
   var $goFonHomeServers = array(); // Contains all available asterisk database server 
 
+  var $is_new = FALSE;
+
   //! The Konstructor   
   /*!  Konstructor, load class with  attributes of the given dn*/
   function macro ($config, $dn= NULL, $parent= NULL)
@@ -60,6 +55,7 @@ class macro extends plugin
 
     /* Edit or new one ?*/
     if ($this->dn == "new"){
+      $this->is_new = TRUE;
       if(isset($_SESSION['CurrentMainBase'])){
         $this->base = $_SESSION['CurrentMainBase'];
       }else{
@@ -151,16 +147,6 @@ class macro extends plugin
       $smarty->assign("goFonMacroVisibleChecked","");
     }
 
-    if(isset($_POST['goFonMacroVisible'])) {
-      $this->goFonMacroVisible= 1 ;
-      $smarty->assign("goFonMacroVisibleChecked"," checked ");
-    }else  {
-      if(isset($_POST['displayName'])){
-        $this->goFonMacroVisible= 0 ;
-        $smarty->assign("goFonMacroVisibleChecked","");
-      }
-    }
-    
     if($this->dn != "new"){
       $smarty->assign("disable_cn"," disabled ");
     }else{
@@ -231,9 +217,10 @@ class macro extends plugin
         $r_current  =  @mysql_pconnect($Server['SERVER'],$Server['LOGIN'],$Server['PASSWORD']);
         $db_current =  @mysql_select_db($Server['DB'],$r_current);
         $res = @mysql_query($query,$r_current);
+        @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           gosa_log(@mysql_error($r_current));
-          return(sprintf(_("Removing marco from '%s' failed. Check GOsa log for mysql error."),$Server['SERVER']));
+          return(sprintf(_("Removing macro from '%s' failed. Check GOsa log for mysql error."),$Server['SERVER']));
         }
         @mysql_close($r_current);
       }
@@ -279,9 +266,10 @@ class macro extends plugin
        * Remove comments introduced by ;
        * Skip empty lines 
        */ 
-      $s_linestr = preg_replace ("/^.*=\> /","",$s_linestr);
-      $s_linestr = preg_replace("/;.*$/","",$s_linestr) ;
       $s_linestr = trim($s_linestr);
+      $s_linestr = preg_replace("/;.*$/","",$s_linestr) ;
+      $s_linestr = preg_replace ("/^.*=\> /","",$s_linestr);
+
       if(empty($s_linestr)){
         continue;
       }
@@ -295,24 +283,26 @@ class macro extends plugin
       $tmp  = split(",", $s_linestr,3);
 
       /* Check if there are exactly 2 , */ 
-      if(substr_count($s_linestr,",") !=2){
-        return(sprintf(_("More than two ',' given in line : '%s'. Remember that parameters are seperated by '|'."),$i_linenum));
-      }
-      /* Multiple () are not supproted currently ... */  
-      if(substr_count($s_linestr,"(") >1 ){
-        return(sprintf(_("More than one '(' is currently not supported. Line : '%s'."),$i_linenum));
-      }
-      if(substr_count($s_linestr,")") >1 ){
-        return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum));
-      }
+#      if(substr_count($s_linestr,",") !=2){
+#        return(sprintf(_("More than two ',' given in line : '%s'. Remember that parameters are seperated by '|'."),$i_linenum));
+#      }
+
+#     /* Multiple () are not supproted currently ... */  
+#     if(substr_count($s_linestr,"(") >1 ){
+#       return(sprintf(_("More than one '(' is currently not supported. Line : '%s'."),$i_linenum));
+#     }
+#     if(substr_count($s_linestr,")") >1 ){
+#       return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum));
+#     }
+
       /* Check if there is an application given */
       if(empty($tmp[1])){
         return(sprintf(_("There is no application given in line : '%s'."),$i_linenum));
-      } 
+      }
       /* Check if there is an extension given */
       if(empty($tmp[0])){
         return(sprintf(_("There is no extension type given in line : '%s'."),$i_linenum));
-      } 
+      }
 
       /* Create extension entry for current line 
        *  and add this line to an array that will be inserted 
@@ -321,8 +311,7 @@ class macro extends plugin
       $exten  = addslashes($tmp[0]);
       $prio   = addslashes($tmp[1]);
       $app    = addslashes(preg_replace("/\(.*\).*$/","",$tmp[2]));
-      $para   = addslashes(preg_replace("/^.*\(/","",$tmp[2]));
-      $para   = preg_replace("/\).*$/","",$para);
+      $para   = addslashes(preg_replace("/^[^(]*\((.*)\)[^)]*$/", "$1", $tmp[2]));
       $sql.= " ('".$context."','".$exten."','".$prio."','".$app."','".$para."'),";
     }
     
@@ -338,6 +327,7 @@ class macro extends plugin
         $db     = @mysql_select_db($cfg['DB'],$r_con);
         $query  = preg_replace("/%TABLENAME%/",$cfg['EXT_TABLE'],$sql);
         $res    = @mysql_query($query,$r_con);
+        @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           gosa_log(@mysql_error($r_con));
           return(sprintf(_("Insert of new macro failed for server '%s'."),$cfg['SERVER']));
@@ -355,9 +345,15 @@ class macro extends plugin
       plugin::save_object();
 
       /* The cn can't be changed if this entry is not new */
-      if($this->dn!= "new"){
+      if(!$this->is_new){
         $this->cn = $this->orig_cn;
       }
+
+      if(isset($_POST['goFonMacroVisible'])) {
+        $this->goFonMacroVisible= 1 ;
+      }else  {
+        $this->goFonMacroVisible= 0 ;
+      }
     }
   }
 
@@ -415,12 +411,6 @@ class macro extends plugin
         }
       }
     }
-
-    /* Macro content must be smaller than 100 lines */
-    if(count(split("\n",$this->goFonMacroContent))>100){
-      $message[] = _("Makro length must be lower than 100 lines");
-    }
-
     return $message;
   }
 
@@ -446,9 +436,11 @@ class macro extends plugin
       $str = $this->remove_from_database(true);
       if($str){ 
         print_red($str);
+        return false;
       }
     }else{
-      print_red(_("Could not remove the macro entry from asterisk databases. Please check your asterisk database configurations and remove this entry from database manually, if necessary."));
+      print_red(_("Could not remove the macro entry from asterisk databases. Please check your asterisk database configurations."));
+      return false;
     }
 
     /* Remove phone macro */ 
@@ -457,7 +449,7 @@ class macro extends plugin
 
     /* Delete references to object groups */
     $ldap->cd ($this->config->current['BASE']);
-    $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+    $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".@LDAP::prepare4filter($this->dn)."))", array("cn"));
     while ($ldap->fetch()){
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);
@@ -470,9 +462,6 @@ class macro extends plugin
   /*! Save to LDAP */
   function save()
   {
-    /* Post checks */
-    $this->execute();
-
     plugin::save();
     unset($this->attrs['base']);