Code

Updated gofoMacro.
[gosa.git] / plugins / gofon / macro / class_gofonMacro.inc
old mode 100755 (executable)
new mode 100644 (file)
index ae3872a..9ea248a
@@ -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{
@@ -221,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);
       }
@@ -269,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;
       }
@@ -328,6 +326,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']));
@@ -345,7 +344,7 @@ 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;
       }
 
@@ -411,12 +410,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;
   }
 
@@ -455,7 +448,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]);
@@ -468,9 +461,6 @@ class macro extends plugin
   /*! Save to LDAP */
   function save()
   {
-    /* Post checks */
-    $this->execute();
-
     plugin::save();
     unset($this->attrs['base']);