Code

Fixed proxy account (squid). Selection of worktime filtering wasn't working.
[gosa.git] / gosa-plugins / gofon / gofon / macro / class_gofonMacro.inc
index 07e10f0aa3f8110a559b87359a49b168bc8b8f80..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(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
+      return(msgPool::missingext("php-mysql"));
     }
 
     /********************
@@ -198,14 +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(_("The MySQL home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
-              $cfg_Current['SERVER'],$cfg_Current['LOGIN']));
+        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(_("Can't select database '%s' on home server '%s'."),$cfg_Current['DB'],$cfg_Current['SERVER']));
+        return ( msgPool::dbselect("GOfon",@mysql_error(),$cfg_Current['DB']));
       }
     }
   }
@@ -236,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(_("Removing macro from '%s' failed. Check GOsa log for mysql error."),$Server['SERVER']));
+          return ( msgPool::dbquery("GOfon",@mysql_error($r_current),$Server['SERVER']));
         }
         @mysql_close($r_current);
       }
@@ -298,24 +296,20 @@ 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));
+        return(sprintf(_("Not supported multiple brace in line %s!"),$i_linenum));
       }
       if(substr_count($s_linestr,")") >1 ){
-        return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum));
+        return(sprintf(_("Not supported multiple brace in 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));
+        return(sprintf(_("Application missing 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));
+        return(sprintf(_("Extension missing in line %s!"),$i_linenum));
       } 
 
       /* Create extension entry for current line 
@@ -345,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(_("Insert of new macro failed for server '%s'."),$cfg['SERVER']));
         }
         @mysql_close($r_con);
       }
@@ -405,7 +398,7 @@ class macro extends plugin
     $message= plugin::check();
 
     if(!count($this->goFonHomeServers)){
-      $message[] = _("There must be at least one server with an asterisk database to save this phone macro.");
+      $message[] = msgPool::noserver(_("GOfon"));
     }
 
     /* Check if insert/replace is possible and all servers are available */
@@ -419,17 +412,17 @@ class macro extends plugin
       $ldap = $this->config->get_ldap_link();
       $ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn"));
       if($ldap->count()>0){
-        $message[]=sprintf(_("The given cn '%s' already exists."),$this->cn);
+        $message[]= msgPool::duplicated(_("Name"));
       }
     }
   
     /* Check if display name is set */
     if(empty($this->displayName)){
-      $message[] = _("You must specify the 'Display Name' in order to save this macro");
+      $message[] = msgPool::required(_("Name"));
     }  
     /* CN is restricted to 20 chars */
     if(strlen("Makro-".$this->cn)>20 ){
-      $message[]=_("The given cn is too long, to create a Makro entry, maximum 20 chars.");
+      $message[]=_("Name can be 20 characters at maximum!");
     }
   
     /* If this macro is still in use we should not change the visible for user flag to invisible */
@@ -438,21 +431,24 @@ class macro extends plugin
       $res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro"));
       while ($val = $ldap->fetch()){
         if(strstr($val['goFonMacro'][0],$this->dn)){
-          $message[] = _("This macro is still in use. It is necessary to mark this macro as visible for users.");
+          $message[] = _("Macro is still in use!");
           return($message);
         }
       }
     }
 
-    /* Macro content must be smaller than 100 lines */
-    if(count(split("\n",$this->goFonMacroContent))>100){
-      $message[] = _("Makro length must be lower than 100 lines");
+    if(empty($this->goFonMacroContent)){
+      $message[] = _("Macro is empty!");
     }
 
-    /* Macro content must be smaller than 100 lines */
-    if(empty($this->goFonMacroContent)){
-      $message[] = _("You can't save an empty macro.");
+    /* 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;
   }
 
@@ -465,10 +461,10 @@ class macro extends plugin
     $ldap= $this->config->get_ldap_link();
 
     /* Skip remove if this macro is still in use */
-    $res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro"));
+    $res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro", "cn"));
     while ($val = $ldap->fetch()){ 
       if(strstr($val['goFonMacro'][0],$this->dn)){ 
-        print_red(_("This macro is still in use. To delete this Macro ensure that nobody has selected it."));
+        msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry because it is still in use by '%s'!"), $val['cn'][0]), ERROR_DIALOG);
         return false;
       }
     }
@@ -477,18 +473,20 @@ class macro extends plugin
     if(count($this->goFonHomeServers)){
       $str = $this->remove_from_database(true);
       if($str){ 
-        print_red($str);
+        msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
         return false;
       }
     }else{
-      print_red(_("Could not remove the macro entry from asterisk databases. Please check your asterisk database configurations."));
+      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']);
@@ -497,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()));
+      }
     }
   }
 
@@ -511,7 +511,7 @@ class macro extends plugin
     /* Try to add entries to databases */
     $str = $this->add_to_database(true);
     if($str){
-      print_red($str);
+      msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
     }else{
       /* Write back to ldap */
       $ldap= $this->config->get_ldap_link();
@@ -531,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){