Code

Fixed a couple of static/non-static error messages
[gosa.git] / plugins / admin / groups / class_groupApplication.inc
index edc3239b34d1a8465448bdaa888a90dc36caa1f2..12b80fab21da955b609519b1be3058b5c17b5132 100644 (file)
@@ -22,6 +22,7 @@ class appgroup extends plugin
   var $curbase                = "";
   var $curCatDir                  ;
   var $curCatDepth              =0;         //
+  var $Categories;
 
   /* attribute list for save action */
   var $attributes               = array("gosaMemberApplication","gosaApplicationParameter");
@@ -34,17 +35,17 @@ class appgroup extends plugin
 
   var $AllAppsForRelease        = array();
   var $AllAppsForReleaseParameter = array();
-
+  var $view_logged = FALSE;
   var $CopyPasteVars            = array("Categories");
   var $gosaApplicationParameter ;
   var $ui                       = NULL;
   var $no_release_acls          = false;
 
-  function appgroup ($config, $dn= NULL, $parent= NULL)
+  function appgroup (&$config, $dn= NULL, $parent= NULL)
   {
    
     /* Check if we have relase mangement enabled and prepare group application for release management */ 
-    $tmp = search_config($config->data,"faiManagement","CLASS");
+    $tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
     if(!empty($tmp)){
       $this->enableReleaseManagement = true;
       $this->objectclasses  [] = "FAIreleaseTag";
@@ -64,9 +65,11 @@ class appgroup extends plugin
   
       /* Release management is activated && this is a valid group app account,
           but no release class was found, so activate is_account flag  */
-      if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) && 
-         (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
-        $this->is_account =true;
+      if(isset($this->attrs['objectClass'])){
+        if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) && 
+            (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
+          $this->is_account =true;
+        }
       }
     }
     
@@ -156,6 +159,7 @@ class appgroup extends plugin
       $this->InitialFAIrelease  = $this->FAIrelease;
       $this->Releases           = $this->getReleases();
     }
+
   }
 
 
@@ -381,6 +385,12 @@ class appgroup extends plugin
     /* Call parent execute */
     plugin::execute();
 
+    /* Log view */
+    if($this->is_account && !$this->view_logged){
+      $this->view_logged = TRUE;
+      new log("view","groups/".get_class($this),$this->dn);
+    }
+
     /* Check if department was selected */ 
     if((isset($_GET['act']))&&($_GET['act']=="depopen")){
       $dep = base64_decode($_GET['depid']); 
@@ -388,7 +398,7 @@ class appgroup extends plugin
     }
 
     /* Check if category was selected */
-    if((isset($_GET['act']))&&($_GET['act']=="open") && isset($this->Categories[base64_decode($_GET['id'])])){
+    if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){
       $this->curCatDir = base64_decode($_GET['id']);
     }
 
@@ -402,7 +412,7 @@ class appgroup extends plugin
     }
 
     /* Do we represent a valid group? */
-    if (!$this->is_account && $this->parent == NULL){
+    if (!$this->is_account && $this->parent === NULL){
       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
         _("This 'dn' is no appgroup.")."</b>";
       return ($display);
@@ -410,7 +420,7 @@ class appgroup extends plugin
 
     /* Show tab dialog headers */
     $display= "";
-    if ($this->parent != NULL){
+    if ($this->parent !== NULL){
       if ($this->is_account){
         $display= $this->show_disable_header(_("Remove applications"),
             _("This group has application features enabled. You can disable them by clicking below."));
@@ -501,20 +511,34 @@ class appgroup extends plugin
           }
         }
 
-        /* Remove category entry */
-        if(preg_match("/DelCat_/",$name)){
-          $n = preg_replace("/DelCat_/","",$name);
-          $app = base64_decode( preg_replace("/_.*$/","",$n));
-          foreach($this->Categories as $key =>  $cat){
-            if($cat == $app){
-              foreach($this->Categories as $p => $n){
-                if(preg_match("/^".$key."\/.*/",$p)){
-                  unset($this->Categories[$p]);    
-                }
+        if(preg_match("/DelCat_/",$name) && !$only_once){
+          $only_once =TRUE;
+          $cat = preg_replace("/DelCat_/","",$name);
+          $cat = trim(base64_decode( preg_replace("/_.*$/","",$cat)));
+
+          $free_apps = array();
+
+          if(isset($this->gosaMemberApplication[$cat]) && is_array($this->gosaMemberApplication[$cat])){
+            foreach($this->gosaMemberApplication[$cat] as $app){
+              $free_apps[] = $app['App'];
+            }
+            unset($this->gosaMemberApplication[$cat]);
+            unset($this->Categories[$cat]);
+          }
+          foreach($this->Categories as $key => $name){
+            if(preg_match("/^".normalizePreg($cat)."\/.*/",$key)){
+              foreach($this->gosaMemberApplication[$key] as $app){
+                $free_apps[] = $app['App'];
               }
+              unset($this->gosaMemberApplication[$key]);
               unset($this->Categories[$key]);
             }
           }
+          foreach($free_apps as $app){
+            if(isset($this->used_apps[$app])){
+              unset($this->used_apps[$app]);
+            }
+          }
         }
 
         /* Edit application parameter */
@@ -529,7 +553,7 @@ class appgroup extends plugin
           $ldap= $this->config->get_ldap_link();
 
           /* Check if we have release management enabled */
-          $tmp = search_config($this->config->data,"faiManagement","CLASS");
+          $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
           if(!empty($tmp)){
     
             /* Get application parameter from ldap */
@@ -598,6 +622,16 @@ class appgroup extends plugin
       }
     }
 
+    /* Add multiple */
+    if(isset($_POST['AddApps'])){
+      foreach($_POST as $name => $value){
+        if(preg_match("/AddApp_/",$name)){
+          $app = preg_replace("/AddApp_/","",$name);
+          $this->addApp($app);
+        }
+      }
+    }
+
     /* Add application with post */
     if((isset($_GET['act']))&&($_GET['act']=="add")){
       $this->used_apps[$_GET['id']]= $_GET['id'];
@@ -634,16 +668,18 @@ class appgroup extends plugin
 
 
     /* Create application list */
-    $div = new DivSelectBox("appgroup");    
+    $div = new divSelectBox("appgroup");    
     $div->SetHeight(300);
     $departments = array();
     $res = get_list("(objectClass=gosaDepartment)", "application", $this->curbase,array("description","cn","ou"),GL_SIZELIMIT);
     foreach($res as $value){
-      $fdn= @LDAP::fix(str_replace($this->curbase,"",$value['dn']));
+      $fdn = $value['dn'];
+      $fdn = preg_replace("/".normalizePreg($this->curbase)."/","",$fdn);
+      $fdn= @LDAP::fix($fdn);
       if($value["description"][0]!=".."){
         $departments[$value['dn']]= convert_department_dn($fdn)." - [".$value["description"][0]."]";
       }else{
-        $departments[$value['dn']]=convert_department_dn($fdn);
+        $departments[$value['dn']]=convert_department_dn($fdn)." ["._("Back")."]";
       }
     }
 
@@ -682,7 +718,7 @@ class appgroup extends plugin
     }
 
     /* Create list of used/assigned applications */
-    $div2 = new DivSelectBox("appgroup");
+    $div2 = new divSelectBox("appgroup");
     $div2->SetHeight(300);
 
     /* Check acls to create "edit/remove" category links */
@@ -709,9 +745,10 @@ class appgroup extends plugin
       $tmp = split("/",$this->curCatDir);
       $bbk = "";
       for($i = 0 ; $i < ($cnt -1 ) ; $i++){
-        $bbk .= $tmp[$i];
+        $bbk .= $tmp[$i]."/";
       }
-      $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),"..")),array("string"=>"&nbsp;","attach"=>"style='border-right:0px;'")));
+      $bbk = preg_replace("/\/$/","",$bbk);
+      $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>"&nbsp;","attach"=>"style='border-right:0px;'")));
     }
 
     /* Add sub categories */ 
@@ -770,11 +807,11 @@ class appgroup extends plugin
             /*  release managent is active
              */
             if(!$this->enableReleaseManagement){
-              $image = "<img class='center' src='images/select_invalid_application.png' 
+              $image = "<img class='center' alt='R' src='images/select_invalid_application.png' 
                           title='"._("This application is no longer available.")."'>&nbsp;";
             }else{
-              $image = "<img class='center' src='images/select_invalid_application.png' 
-                          title='".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."'>&nbsp;";
+              $image = "<img class='center' alt='F' src='images/select_invalid_application.png' 
+                          title=\"".sprintf(_("This application is not available in any release named %s."),$this->FAIrelease)."\">&nbsp;";
             }
       
           }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
@@ -818,11 +855,11 @@ class appgroup extends plugin
     }
 
     /* Show main page */
-    if ($this->dialog){
+    if (is_object($this->dialog)){
       $smarty->assign("table", $this->table);
-      $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE));
+      $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__)));
     } else {
-      $display.= $smarty->fetch (get_template_path('application.tpl', TRUE));
+      $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__)));
     }
     
     return ($display);
@@ -893,6 +930,10 @@ class appgroup extends plugin
 
   function remove_from_parent()
   {
+    if(!$this->initially_was_account){
+      return;
+    }
+
     plugin::remove_from_parent();
 
     $ldap= $this->config->get_ldap_link();
@@ -900,7 +941,7 @@ class appgroup extends plugin
     $this->cleanup();
     
     $ldap->modify ($this->attrs); 
-
+    new log("remove","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of groups/applications with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
@@ -913,7 +954,8 @@ class appgroup extends plugin
   {
     /* Skip saving application settings, if we do not have release acls */
     if($this->no_release_acls){
-      gosa_log("Skip saving group application extension. Caused by insufficient acls");
+      new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls");
+      
       return;
     }
 
@@ -925,21 +967,25 @@ class appgroup extends plugin
     $this->Categories[""]=""; 
     $this->attrs["gosaMemberApplication"]= array();
     $this->attrs["gosaApplicationParameter"]= array();
+    $cat_id= 0 ;
     foreach($this->Categories as $name => $cats){
       $i =0;
       if(isset($this->gosaMemberApplication[$name])){
         foreach($this->gosaMemberApplication[$name] as $entry){
           if(!preg_match("/__SEPARATOR__/",$entry['App'])){
             $this->attrs["gosaMemberApplication"][]= $entry['App']."|".$name."|".$i;
+            $i ++;
           }
-          $i ++;
         }
       }
       if(($i==0)&&(!empty($name))){
-        $this->attrs["gosaMemberApplication"][]= "|".$name."|".$i;
+        $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cat_id;
       }
+      $cat_id++;
     }
 
+
+
     /* Are there application parameters to be saved */
     $this->attrs['gosaApplicationParameter']= array();
     foreach($this->appoption as $name => $value){
@@ -954,6 +1000,12 @@ class appgroup extends plugin
     $this->cleanup();
     $ldap->modify ($this->attrs); 
 
+    if($this->initially_was_account){
+      new log("modify","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
+    }else{
+      new log("create","group/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); 
+    }   
+
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
 
     /* Optionally execute a command after we're done */
@@ -982,8 +1034,8 @@ class appgroup extends plugin
     $this->apps= array();
 
     /* Special handling for release managed apps */
-    $tmp = search_config($this->config->data,"faiManagement","CLASS");
-    if(!empty($tmp)){
+    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
+    if(!empty($tmp) && count($this->Releases)){
       $this->enableReleaseManagement = true;
 
       /* Check if release is available */
@@ -1037,8 +1089,8 @@ class appgroup extends plugin
     }
 
     /* Get all apps ... */
-    $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn")); 
-    $tmp = search_config($this->config->data,"faiManagement","CLASS");
+    $res = get_list("objectClass=gosaApplication","application",$this->config->current['BASE'],array("gosaApplicationParameter","cn"),GL_SUBSEARCH); 
+    $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
     $this->AllAppsForRelease = array();
     if(!empty($tmp)){
       $tmp = array_flip($this->Releases);
@@ -1146,8 +1198,18 @@ class appgroup extends plugin
   }
 
 
+  function PrepareForCopyPaste($source)
+  {
+    $s = new appgroup($this->config,$source['dn']);
+    $this->FAIrelease = $this->InitialFAIrelease = $s->FAIrelease;
+    $this->gosaMemberApplication = $s->gosaMemberApplication;
+    $this->appoption = $s->appoption;
+    $this->Categories = $s->Categories;
+  }
+
+
   /* Return plugin informations for acl handling  */ 
-  function plInfo()
+  static function plInfo()
   {
     return (array(
           "plShortName"   => _("Applications"),