Code

Fixed proxy account (squid). Selection of worktime filtering wasn't working.
[gosa.git] / gosa-plugins / gofon / gofon / macro / class_gofonMacro.inc
index c4d22b417569826a358cc8b80ab65bc38ae5c45e..640665faf7fb983a6fbf523228bd8d02196223bf 100644 (file)
@@ -9,12 +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= "";
@@ -44,6 +38,8 @@ class macro extends plugin
   var $attributes     = array("cn","base", "description","displayName","goFonMacroContent","goFonMacroVisible");
   var $view_logged = FALSE;
   var $orig_cn = ""; 
+  var $orig_base = ""; 
+  var $orig_dn = ""; 
   /*! Objectclasses that this calls handles */
   var $objectclasses  = array("top", "goFonMacro");
 
@@ -68,7 +64,7 @@ class macro extends plugin
       }
     } else {
       $this->orig_cn=$this->cn;
-      $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_ou("macroou"))."/i", "", $this->dn);
     }
 
     /* Check server configurations
@@ -85,6 +81,9 @@ class macro extends plugin
         unset($this->goFonHomeServers[0]);  
       }
     }
+    
+    $this->orig_base = $this->base;
+    $this->orig_dn = $this->dn;
   }
 
 
@@ -188,7 +187,7 @@ class macro extends plugin
   {
     /* Check if mysql extension is available */
     if(!is_callable("mysql_pconnect")){
-      return(sprintf(_("Missing %s PHP extension!"), "mysql"));
+      return(msgPool::missingext("php-mysql"));
     }
 
     /********************
@@ -198,13 +197,13 @@ class macro extends plugin
       $r_current    =  @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
       if(!$r_current){
         new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
-        return (sprintf(_("Cannot connect to %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
+        return ( msgPool::dbconnect("GOfon",@mysql_error(),$cfg_Current['SERVER']));
       }
       $db_current  =  @mysql_select_db($cfg_Current['DB'],$r_current);
       if(!$db_current){
         new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
         mysql_close($r_current);
-        return (sprintf(_("Cannot select %s database on server '%s'!"), "GOfon", $cfg_Current['SERVER']));
+        return ( msgPool::dbselect("GOfon",@mysql_error(),$cfg_Current['DB']));
       }
     }
   }
@@ -235,7 +234,7 @@ class macro extends plugin
         @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current));
-          return(sprintf(_("Cannot remove macro from '%s'!"),$Server['SERVER']));
+          return ( msgPool::dbquery("GOfon",@mysql_error($r_current),$Server['SERVER']));
         }
         @mysql_close($r_current);
       }
@@ -297,10 +296,6 @@ 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(_("Not supported multiple brace in line %s!"),$i_linenum));
@@ -344,7 +339,6 @@ class macro extends plugin
         @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
         if(!$res){
           new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_con));
-          return(sprintf(_("Cannot insert new macro on server '%s'!"),$cfg['SERVER']));
         }
         @mysql_close($r_con);
       }
@@ -404,7 +398,7 @@ class macro extends plugin
     $message= plugin::check();
 
     if(!count($this->goFonHomeServers)){
-      $message[] = _("There is currently no asterisk server defined!");
+      $message[] = msgPool::noserver(_("GOfon"));
     }
 
     /* Check if insert/replace is possible and all servers are available */
@@ -418,13 +412,13 @@ class macro extends plugin
       $ldap = $this->config->get_ldap_link();
       $ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn"));
       if($ldap->count()>0){
-        $message[]= _("Name is already in use!");
+        $message[]= msgPool::duplicated(_("Name"));
       }
     }
   
     /* Check if display name is set */
     if(empty($this->displayName)){
-      $message[] = _("Display name is not set!");
+      $message[] = msgPool::required(_("Name"));
     }  
     /* CN is restricted to 20 chars */
     if(strlen("Makro-".$this->cn)>20 ){
@@ -446,6 +440,15 @@ class macro extends plugin
     if(empty($this->goFonMacroContent)){
       $message[] = _("Macro is empty!");
     }
+
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return $message;
   }
 
@@ -474,14 +477,16 @@ class macro extends plugin
         return false;
       }
     }else{
-      msg_dialog::display(_("Configuration error"), _("There is currently no asterisk server defined!"), WARNING_DIALOG);
+      msg_dialog::display(_("Configuration error"), msgPool::noserver(_("GOfon")), WARNING_DIALOG);
       return false;
     }
 
     /* Remove phone macro */ 
     $ldap->rmDir($this->dn);
     new log("remove","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed!"),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+    }
 
     /* Delete references to object groups */
     $ldap->cd ($this->config->current['BASE']);
@@ -490,7 +495,9 @@ class macro extends plugin
       $og= new ogroup($this->config, $ldap->getDN());
       unset($og->member[$this->dn]);
       $og->save ();
-      show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed!"),$this->dn));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+      }
     }
   }
 
@@ -524,7 +531,9 @@ class macro extends plugin
         $ldap->add($this->attrs);
         $this->handle_post_events("add");
       }
-      show_ldap_error($ldap->get_error(), sprintf(_("Saving of goFonMacro/generic account with dn '%s' failed."),$this->dn));
+      if (!$ldap->success()){
+        msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+      }
 
       /* Log last action */
       if($this->initially_was_account){