Code

Added repository service
[gosa.git] / plugins / admin / systems / class_servRepositorySetup.inc
index b83b68fd98c8272a19bed7bd1c99962130c85d3a..8fec23baad07671634fe52e988f494a63209d1a5 100644 (file)
@@ -9,16 +9,17 @@ class servRepositorySetup  extends plugin
 
   /* attribute list for save action */
   var $ignore_account   = TRUE;
-  var $attributes       = array("Release","ParentServer","Url");
+  var $attributes       = array("Release","ParentServer","Url","cn");
   var $objectclasses    = array("whatever");
 
   /* Attributes */
-  var $Release          ="";
-  var $ParentServer     ="";
-  var $Url              ="";   
-  var $Sections         =array();
-  var $ParentServers    ="";
-  var $initialy_was=false;
+  var $Release          = "";
+  var $ParentServer     = "";
+  var $Url              = "";   
+  var $Sections         = array();
+  var $ParentServers    = "";
+  var $initialy_was     = false;
+  var $cn               = "";
 
   function servRepositorySetup ($config, $dn= NULL,$data = false)
   {
@@ -93,9 +94,10 @@ class servRepositorySetup  extends plugin
       $smarty->assign($attr       ,$this->$attr);
       $smarty->assign($attr."ACL" ,chkacl($this->acl,$attr));
     }
-
-    $smarty->assign("ParentServers"   ,$this->getParentServers());
-    $smarty->assign("ParentServerKeys",array_flip($this->getParentServers()));
+  
+    $tmp = $this->getParentServers();
+    $smarty->assign("ParentServers"   ,$tmp);
+    $smarty->assign("ParentServerKeys",array_flip($tmp));
 
     return($smarty->fetch(get_template_path('servRepositorySetup.tpl', TRUE)));
   }
@@ -110,7 +112,8 @@ class servRepositorySetup  extends plugin
   /* Check supplied data */
   function check()
   {
-    $message= array();
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     if(empty($this->Release)){
       $message[]=_("Please enter a value for 'release'.");
@@ -142,9 +145,46 @@ class servRepositorySetup  extends plugin
     $ldap->cd($this->config->current['BASE']);
     $ldap->search("(objectClass=FAIrepositoryServer)",array("*"));
     while($attr = $ldap->fetch()){
+      if($attr['cn'][0] == $this->cn) continue;
       $ret[$attr['cn'][0]]= $attr['cn'][0];   
     }
+
+    $ret = array_merge($ret,$this->GetHookElements());
+    
     $ret['none']= " ";
+    asort($ret);
+    return($ret);
+  }
+
+  /* this funtions calls a defined hook 
+      and parses all additional serverdata 
+   */
+  function GetHookElements()
+  {
+    $ret = array();
+    $cmd= search_config($this->config->data['TABS'], "servrepository", "REPOSITORY_HOOK");
+    if(!empty($cmd)){
+      $res = shell_exec($cmd);
+      $res2 = trim($res);
+      if(!$res){
+        print_red(sprintf(_("Can't execute specified REPOSITORY_HOOK '%s'. Please check your gosa.conf."),$cmd));
+      }elseif(empty($res2)){
+        print_red(sprintf(_("The specified REPOSITORY_HOOK '%s', specified in your gosa.conf, returns an empty string."),$cmd));
+      }else{  
+        $tmp = split("\n",$res);
+        foreach($tmp as $hook){
+          /* skip empty */
+          if(empty($hook)) continue;
+
+          if(preg_match("/;/",$hook)){ 
+            $hookinfo = split(";",$hook);
+            $ret[$hookinfo[0]] = $hookinfo[0];
+          }else{
+            $ret[$hook] = $hook;
+          }
+        }
+      }
+    }
     return($ret);
   }