diff --git a/gosa-plugins/goto/admin/groups/apps/class_groupApplication.inc b/gosa-plugins/goto/admin/groups/apps/class_groupApplication.inc
index e10e4a69d7d1172687e77957cffaa0759875bfec..00f87bb5287539e360fb5c4c2979eb89c31834fb 100644 (file)
<?php
class appgroup extends plugin
{
- /* CLI vars */
- var $cli_summary= "Manage application groups";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
- /* Appgroup attributes */
- var $gosaMemberApplication= array();
-
- /* Helpers */
- var $departments = ""; // All departments within $this->curbase;
- var $apps = array(); // All available applications
- var $used_apps = array(); // Specifies which applications are currently assigned
-
- var $option_name = array();
- var $option_value = array();
- var $appoption = array();
-
- var $table = "";
- var $curbase = "";
- var $curCatDir ;
- var $curCatDepth =0; //
- var $Categories;
-
- /* attribute list for save action */
- var $attributes = array("gosaMemberApplication","gosaApplicationParameter");
- var $objectclasses = array("gosaApplicationGroup");
-
- var $FAIrelease = "/";
- var $InitialFAIrelease = "/";
- var $Releases = array();
- var $enableReleaseManagement = false;
-
- var $AllAppsForRelease = array();
- var $AllAppsForReleaseParameter = array();
- var $view_logged = FALSE;
- var $CopyPasteVars = array("Categories");
- var $gosaApplicationParameter ;
- var $ui = NULL;
- var $no_release_acls = false;
-
- var $multiple_support = TRUE;
-
- function appgroup (&$config, $dn= NULL, $parent= NULL)
- {
+ var $config;
+ var $curbase;
+
+ /* Contains the menu structure in an array.
+ */
+ var $a_Structure= array();
+ var $a_Structure_on_load = array();
+ var $Releases;
+ var $FAIrelease = 0;
+ var $apps = array();
+ var $_cache = array();
+
+ var $app_parameter = array();
+ var $edit_entry = array();
+ var $enableReleaseManagement = FALSE;
+
+ var $copied_release = "";
- /* Check if we have relase mangement enabled and prepare group application for release management */
+
+ public function __construct(&$config, $dn= NULL, $parent= NULL)
+ {
+ plugin::plugin($config,$dn,$parent);
+ $this->dn = $dn;
+ $this->_load_menu_structure();
+ $this->a_Structure_on_load = $this->a_Structure;
+
+ /* Check if we have relase mangement enabled and prepare group application for release management */
$tmp = $config->search("faiManagement", "CLASS",array('menu','tabs'));
if(!empty($tmp)){
$this->enableReleaseManagement = true;
- $this->objectclasses [] = "FAIreleaseTag";
- $this->attributes [] = "FAIrelease";
}
- plugin::plugin ($config, $dn, $parent);
+ $this->Releases = $this->getReleases();
+ $this->FAIrelease = "/";
+ $this->curbase = $this->config->current['BASE'];
+ $this->reload();
+
+ /* If we have at least one assigned application-
+ Enable this account.
+ */
+ $this->is_account = FALSE;
+ if(count($this->_get_all_entries()) > 1){
+ $this->is_account= TRUE;
+ }
+ $this->initially_was_account = $this->is_account;
+ }
- /* set userinfo object */
- $this->ui = get_userinfo();
- /* Compatibility check
- In some case of old applikations with old release tag saving,
- we must reassign is_account state.
- (Or if release management wasn't activated before creating this app) */
- if($this->enableReleaseManagement){
-
- /* Release management is activated && this is a valid group app account,
- but no release class was found, so activate is_account flag */
- if(isset($this->attrs['objectClass'])){
- if($dn != "new" && ( in_array("gosaApplicationGroup",$this->attrs['objectClass'])) &&
- (!in_array("FAIreleaseTag",$this->attrs['objectClass']))){
- $this->is_account =true;
- }
- }
- }
-
- /* Load member applications */
- if (isset ($this->attrs["gosaMemberApplication"][0])){
- $this->gosaMemberApplication = array();
- for ($i= 0; $i<$this->attrs["gosaMemberApplication"]["count"]; $i++){
- $this->gosaMemberApplication[]=
- $this->attrs["gosaMemberApplication"][$i];
- }
- }
+ /*! \brief Reload the list of applications for the currently selected release.
+ If necessary, maybe the list is already cached.
+ */
+ function reload()
+ {
+ $ret = array();
+ $release_info = $this->Releases[$this->FAIrelease];
- /* Load application options */
- if (isset($this->attrs['gosaApplicationParameter'])){
- for ($i= 0; $i<$this->attrs['gosaApplicationParameter']['count']; $i++){
- $option= preg_replace('/^[^:]+:/', '',
- $this->attrs['gosaApplicationParameter'][$i]);
- $name= preg_replace('/:.*$/', '',
- $this->attrs['gosaApplicationParameter'][$i]);
- $this->appoption[$name]= $option;
- }
- }
+ /* Check if the available application were already been fetched.
+ If not, build up a list of available applications.
+ */
+ if(!isset($this->_cache['ReleaseApps'][$release_info['suffix']])){
- /* Parse MemberApplication*/
- $tmp = array();
- $tmp2 = array();
- $prios = array();
- $cats = array();
+ /* First of all, get all application departments to search in.
+ */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->search("ou=apps",array("dn"));
+ $app_deps = array();
+ while($attrs = $ldap->fetch()){
+ $app_deps[] = $attrs['dn'];
+ }
- foreach($this->gosaMemberApplication as $memberApp){
- if(preg_match("/\|/i",$memberApp)){
-
- $tmp = split("\|",$memberApp);
-
- if(!empty($tmp[0])){
- $tmp2[$tmp[1]][$tmp[2]] = array("App"=>$tmp[0]);
- }
- if(!empty($tmp[1])){
- $n = split("/",$tmp[1]);
- $c = count($n);
- $cats [$tmp[1]] = $n[$c-1];
+ /* Search all release departments for the above fetched application departments
+ */
+ foreach($app_deps as $dep){
+ $ldap->cd($dep);
+ $ldap->search("objectClass=FAIbranch",array("dn"));
+ while($attrs = $ldap->fetch()){
+ $app_deps[] = $attrs['dn'];
}
- $prios[$tmp[1]][$tmp[2]] = $tmp[2];
- }else{
- $tmp2[]['App'] = $memberApp;
}
- }
- /* Assign collected category and application settings */
- $this->Categories = $cats;
- $this->gosaMemberApplication = $tmp2;
-
- /* Sort application by category */
- $cats[""]="";
- foreach($cats as $cat ){
- if((isset($prios[$cat]))&&(count($prios[$cat]))){
- $max = max($prios[$cat]);
- $min = 1;//min($prios[$cat]);
- $last = false;
- for($i = $min ; $i < $max ; $i++){
- if(!isset($prios[$cat][$i])){
- if($last == false){
- $this->gosaMemberApplication[$cat][$i]['App'] = "__SEPARATOR__".$i;
-
- $last = true;
- }
- }else{
- $last = false;
- }
+ /* Filter out those releases that match the currently selected release,
+ and fetch all applications from those departments.
+ */
+ foreach($app_deps as $dep){
+ if(preg_match("/^".normalizePreg($release_info['suffix'])."/",$dep)){
+ $ret = array_merge($ret,get_list("(objectClass=gosaApplication)","application",$dep,array("*"),GL_NONE));
}
}
- }
- /* Sort application by priority */
- $tmp = array();
- foreach($this->gosaMemberApplication as $key => $entries){
- ksort ($entries);
- foreach($entries as $entry){
- $tmp[$key][]= $entry;
+ /* Create a new array containing all fetch apps for the currently selected release,
+ sort it and store results in cache.
+ */
+ $tmp = array();
+ foreach($ret as $key => $app){
+ $tmp[$key] = $app['cn'][0];
}
- }
- $this->gosaMemberApplication = $tmp;
- $this->curbase = $this->config->current['BASE'];
-
- /* Get required release informations */
- if($this->enableReleaseManagement){
- $this->InitialFAIrelease = $this->FAIrelease;
- $this->Releases = $this->getReleases();
- }
-
- }
-
-
- /* Combine new array */
- function combineArrays($ar0,$ar1,$ar2)
- {
- $ret = array();
- if(is_array($ar0))
- foreach($ar0 as $ar => $a){
- $ret[$ar]=$a;
- }
- if(is_array($ar1))
- foreach($ar1 as $ar => $a){
- $ret[$ar]=$a;
- }
- if(is_array($ar2))
- foreach($ar2 as $ar => $a){
- $ret[$ar]=$a;
- }
- return($ret);
- }
-
- /* Returns element position within given array */
- function getpos($atr,$attrs)
- {
- $i = 0;
- foreach($attrs as $attr => $name) {
- $i++;
- if($attr == $atr){
- return($i);
+ natcasesort($tmp);
+ $res = array();
+ foreach($tmp as $key => $app){
+ $res[] = $ret[$key];
}
- }
- return(-1);
- }
+ $this->_cache['ReleaseApps'][$release_info['suffix']] = $res;
+ }
+ $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']];
+ }
- /* Check current combination of application && release
- Are all application available?, application parameter changed? ... */
- function diffAppsInReleases()
+
+
+ /*! \brief generate a list of available releases
+ @return return an array with all available releases.
+
+ e.g.
+
+ / "name" /
+ "found" 1
+ "parts" Array (empty)
+ "suffix" ou=apps,
+
+ halut "name" halut
+ "found" 1
+ "FAIstate"
+ "dn" ou=halut,ou=apps,ou=Direktorium,o=Landeshauptstadt München,c=de
+ "parts" 0 halut
+ "suffix" ou=halut,ou=apps,
+
+ This will be used as base for the application menu structure.
+ If there is a menu assigned for a release, this menu will be
+ appended with the index 'ENTRIES';
+ */
+ function getReleases()
{
- /* Only diff if it is required */
- $ret =array();
-
- /* If current release has changed */
- if($this->FAIrelease != $this->InitialFAIrelease){
-
- /* Walk through all apps which are currently displayed */
- if(isset($this->gosaMemberApplication[$this->curCatDir])){
-
- foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
+ $ret =array("/" => array("name" => "/", "found" => TRUE , "parts" => array(),"suffix" => get_ou('applicationou')));
+ if($this->enableReleaseManagement){
- /* If application is also available in new release, check if parameter differs */
- if(in_array($entry['App'],$this->AllAppsForRelease)){
+ /* Only display those releases that we are able to read
+ */
+ $dn = get_ou("applicationou").$this->config->current['BASE'];
+ $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
+ $res = get_sub_list($filter,array("application","fai"),
+ array(get_ou("applicationou"),get_ou("faiou")),$dn, array("ou","FAIstate"), GL_SUBSEARCH);
- $old = array(); // Old application parameter
- $new = array(); // New parameters
+ /* Go through all departments and check which department is a valid
+ department release.
+ */
+ foreach($res as $attrs){
+ if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
- /* There are possibly no parameters specified */
- if(isset($this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']])){
- $old = $this->AllAppsForReleaseParameter[$this->InitialFAIrelease][$entry['App']];
+ /* Parse all returned departments dns into a useable type.
+ (ou=1.0.0,ou=halut,ou=apps ==> halue/1.0.0)
+ */
+ $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
+ $parts = array_reverse(split("ou=",$bb));
+
+ $str ="";
+ foreach($parts as $key => $part){
+ if(empty($part)) {
+ unset($parts[$key]);
+ continue;
}
+ $part = str_replace(",","",$part);
+ $str .= $part."/";
+ $parts[$key] = $part;
+ }
+ $name = preg_replace("/\/$/","",$str);
+ if(empty($name)) {
+ $name ="/";
+ }
- if(isset($this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']])){
- $new = $this->AllAppsForReleaseParameter[$this->FAIrelease][$entry['App']];
- }
+ $FAIstate = "";
+ if(isset($attrs['FAIstate'])){
+ $FAIstate = $attrs['FAIstate'][0];
+ }
- /* Both (old & new) have no gosaApplicationParameter
- */
- if((!isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
- $ret[$entry['App']] = false;
-
- /* Both got gosaApplicationParameter */
- }elseif((isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
- if(array_differs($old['gosaApplicationParameter'],$new['gosaApplicationParameter'])){
- $ret[$entry['App']] = true;
- }else{
- $ret[$entry['App']] = false;
- }
+ /* Check if this department has a menu structure assigned
+ */
+ $all = $this->_get_all_entries();
+ $found = FALSE;
+ foreach($all as $entry){
+ if(isset($entry['DN']) && preg_match("/^".normalizePreg($bb)."/",$entry['DN'])){
+ $found =TRUE;
+ break;
}
- /* Initially had gosaApplicationParameter bot in new release not */
- }elseif((isset($old['gosaApplicationParameter'])) && (!isset($new['gosaApplicationParameter']))){
- $ret[$entry['App']] = true;
-
- /* Old release had no gosaApplicationParameter but new got some */
- }elseif((!isset($old['gosaApplicationParameter'])) && (isset($new['gosaApplicationParameter']))){
- $ret[$entry['App']] = true;
}
+
+ $ret[$name] = array("name" => $name,
+ "found" => $found,
+ "FAIstate" => $FAIstate,
+ "dn" => $attrs['dn'],
+ "parts" => $parts,"suffix" => $bb.get_ou('applicationou'));
}
}
}
- return($ret);
- }
-
- /* TRansports the geiven Arraykey one position up*/
- function ArrayUp($atr,$attrs)
- {
- $ret = $attrs;
- $pos = $this->getpos($atr,$attrs) ;
- $cn = count($attrs);
- if(!(($pos == -1)||($pos == 1))){
- $before = array_slice($attrs,0,($pos-2));
- $mitte = array_reverse(array_slice($attrs,($pos-2),2));
- $unten = array_slice($attrs,$pos);
- $ret = array();
- $ret = $this->combineArrays($before,$mitte,$unten);
- }
+ ksort($ret);
return($ret);
}
- /* TRansports the geiven Arraykey one position up*/
- function ArrayDown($atr,$attrs)
- {
- $ret = $attrs;
- $pos = $this->getpos($atr,$attrs) ;
- $cn = count($attrs);
- if(!(($pos == -1)||($pos == $cn))){
- $before = array_slice($attrs,0,($pos-1));
- $mitte = array_reverse(array_slice($attrs,($pos-1),2));
- $unten = array_slice($attrs,($pos+1));
- $ret = array();
- $ret = $this->combineArrays($before,$mitte,$unten);
- }
- return($ret);
- }
+ /*! \brief Load the menu structure from ldap and create a multi dimensional array.
-
- /* Sort category on position up */
- function catUp($id)
- {
- /* Get all cats depinding on current dir */
- $cats = $this->GetSubdirs($this->curCatDir);
- $newcats =$this->ArrayUp($id,$cats);
- foreach($newcats as $cat => $name){
- unset($this->Categories[$cat]);
- }
- foreach($newcats as $cat => $name){
- $this->Categories[$cat]=$name;
- }
- }
+ This will create a multidimensional array.
+ e.g.:
-
- /* Sort category on position down */
- function catDown($id)
- {
- /* Get all cats depinding on current dir */
- $cats = $this->GetSubdirs($this->curCatDir);
- $newcats =$this->ArrayDown($id,$cats);
- foreach($newcats as $cat => $name){
- unset($this->Categories[$cat]);
- }
- foreach($newcats as $cat => $name){
- $this->Categories[$cat]=$name;
- }
- }
-
-
- /* Increase application priority */
- function getOneUp($appl)
- {
- $cat = $this->curCatDir;
- $apps = $this->gosaMemberApplication[$cat];
- $appsA = array();
- foreach ($apps as $appkey => $name){
- $appsA[$name['App']] =$name['App'];
- }
- $result = $this->ArrayUp($appl,$appsA);
- $ret = array();
- foreach($result as $app){
- $ret[]=array("App"=>$app);
- }
- $this->gosaMemberApplication[$cat] = $ret;
- }
-
-
- /* Decrease application priority */
- function getOneDown($appl)
- {
- $cat = $this->curCatDir;
- $apps = $this->gosaMemberApplication[$cat];
- $appsA = array();
- foreach ($apps as $appkey => $name){
- $appsA[$name['App']] =$name['App'];
- }
- $result = $this->ArrayDown($appl,$appsA);
- $ret = array();
- foreach($result as $app){
- $ret[]=array("App"=>$app);
- }
- $this->gosaMemberApplication[$cat] = $ret;
- }
-
-
- /* Add seperator to application list */
- function AddSeperator($id)
- {
- $found = false;
- $cat = "";
- $tmp = array();
- foreach($this->gosaMemberApplication[$this->curCatDir] as $appID => $app){
- $tmp[] = $app;
- if(($app['App'] == $id)&&(!$found)){
- $cnt = count($this->gosaMemberApplication[$this->curCatDir]);
- $tmp[] = array("App" => "__SEPARATOR__".($cnt+1));
- $found = true;
- }
- }
- if($found){
- $this->gosaMemberApplication[$this->curCatDir]=$tmp;
- }
- }
-
-
- /* Check if application acls are readable */
- function check_acls()
- {
- return(count($this->ui->get_module_departments("application")));
- }
-
-
- function execute()
- {
- /* Call parent execute */
- plugin::execute();
- $display = "";
-
- /* Log view */
- if($this->is_account && !$this->view_logged){
- $this->view_logged = TRUE;
- new log("view","groups/".get_class($this),$this->dn);
- }
-
- /* Account state settings - Skip if we are editing multiple entries */
- if(!$this->multiple_support_active){
-
- /* Do we need to flip is_account state? */
- if(isset($_POST['modify_state'])){
- if($this->is_account && $this->acl_is_removeable()){
- $this->is_account= FALSE;
- }elseif(!$this->is_account && $this->acl_is_createable()){
- $this->is_account= TRUE;
- }
- }
-
- /* Do we represent a valid group? */
- if (!$this->is_account && $this->parent === NULL){
- $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
- _("This 'dn' is no appgroup.")."</b>";
- return ($display);
- }
-
- /* Show tab dialog headers */
- $display= "";
- 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."));
- } else {
- $display.= $this->show_enable_header(_("Create applications"),
- _("This group has application features disabled. You can enable them by clicking below."));
- return ($display);
- }
- }
- }
+ $this->a_Structure =
- /* Check acl, applications must be readable */
- if(!$this->check_acls()){
- $display .= "<img src='images/button_cancel.png' alt='"._("ACL")."' class='center'>
- <b>"._("Insufficient permissions")."</b>
- <p>".
- _("You do not have permission to query application entries. All your changes will not be saved.").
- "</p><p class='seperator'> </p>";
- $this->no_release_acls = true;
- }
- /* Check if department was selected */
- if((isset($_GET['act']))&&($_GET['act']=="depopen")){
- $dep = base64_decode($_GET['depid']);
- $this->curbase =$dep;
- }
-
- /* Check if category was selected */
- if((isset($_GET['act']))&&($_GET['act']=="open") && (empty($_GET['id']) || isset($this->Categories[base64_decode($_GET['id'])]))){
- $this->curCatDir = base64_decode($_GET['id']);
- }
-
-
+ [0]['TYPE'] = "BASE"
+ [0]['ENTRIES'] [0]['TYPE'] = "RELEASE"
+ [0]['NAME'] = "halut"
+ [0]['ENTRIES']= array()
+ ...
+ [0]['ENTRIES'] [1]['TYPE'] = "RELEASE"
+ [1]['NAME'] = "halut/1.0.0"
+ [1]['ENTRIES'] [0]['TYPE'] = "TYPE"
+ [0]['NAME'] = "Programme"
+ [0]['ENTRIES'][0]['TYPE'] = "ENTRY"
+ [0]['NAME'] = "konqueror"
+ [1]['TYPE'] = "ENTRY"
+ [1]['NAME'] = "firefox"
+ */
+ function _load_menu_structure()
+ {
+ /* Create the base object
+ */
+ $base = array();
+ $base['UNIQID'] = uniqid();
+ $base['PARENT'] = 0;
+ $base['NAME'] = "";
+ $base['TYPE'] = "BASE";
+ $base['ENTRIES']= array();
+ $base['STATUS'] = "LOADED";
+ $this->a_Structure = array();
+ $this->a_Structure[0] = $base;
- /* Add Categorie */
- if((isset($_POST['AddCat']))&&(isset($_POST['CatName']))&&(!empty($_POST['CatName']))){
-
- /* Only allow adding a category, if it is allowed */
- if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
-
- if(preg_match("/[\\\\\/]/i",$_POST['CatName'])){
- print_red(_("Invalid character in category name."));
- }elseif(!in_array($_POST['CatName'],$this->Categories)){
- if(empty($this->curCatDir)){
- $this->Categories[$_POST['CatName']]=$_POST['CatName'];
- }else{
- $this->Categories[$this->curCatDir."/".$_POST['CatName']]=$_POST['CatName'];
+ /* Search for all Releases/Menu Folders and Menu Entries,
+ to append them to our structure array.
+ */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dn);
+ $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*"));
+ while($attrs = $ldap->fetch()){
+
+ /* Find the correct position where to add this entry.
+ e.g. If we have cn=firefox,cn=Programme,ou=halut...
+
+ 1. get a pointer to the halut array ($this->a_Structure['0'][ENTRIES''][]['halut'])
+ 2. then get a pointer to the halut['ENTRIES'][]['Programme'] array.
+ 3. append 'firefox' to the 'ENTRIES' of our "Programme" pointer.
+ */
+ $cur = &$this->a_Structure[0]['ENTRIES'];
+ $parent_id = $base['UNIQID'];
+ $sub_dn = preg_replace("/,".normalizePreg($this->dn)."$/","",$attrs['dn']);
+ $sub_dn_array = split("\,",$sub_dn);
+
+ /* Walk through our menu structure array while we have found
+ the correct position where to add this object.
+ */
+ $found = true;
+ for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){
+ $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]);
+
+ /* We haven't found the end node where this object has to be added
+ */
+ if($i > 0){
+ $found =FALSE;
+ foreach($cur as $key => $entry){
+ if($entry['NAME'] == $name){
+ $cur = &$cur[$key]['ENTRIES'];
+ $parent_id = $entry['UNIQID'];
+ $found =true;
+ break;
+ }
}
}else{
- print_red(_("The specified category already exists."));
- }
- }
- }
-
-
- $this->reload();
- $this->diffAppsInReleases();
-
- /* Check POST variables for commands
- to add/remove some applications */
- $only_once = false;
- if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
-
- /* Walk through posts */
- foreach($_POST as $name => $value){
-
- /* Add a seperator to current category */
- if((preg_match("/AddSep_/",$name))&&(!$only_once)){
- $only_once = true;
- $n = preg_replace("/AddSep_/","",$name);
- $val= preg_replace("/_.*$/","",$n);
- $this->AddSeperator($val);
- }
-
- /* Delete application | seperator entry */
- if((preg_match("/DelApp_/",$name))&&(!$only_once)){
- $only_once = true;
-
- if(preg_match("/DelApp___SEPARATOR__/",$name)) {
- $n= preg_replace("/DelApp___SEPARATOR__/","",$name);
- $val= "__SEPARATOR__".preg_replace("/_.*$/","",$n);
- }else{
- $n = preg_replace("/DelApp_/","",$name);
- $val= preg_replace("/_.*$/","",$n);
+
+ if(!$found){
+ break;
}
- foreach($this->gosaMemberApplication as $key => $cat){
- foreach($cat as $key2 => $app){
- if($app['App'] == $val){
- unset($this->gosaMemberApplication[$key][$key2]);
- if(isset($this->used_apps[$val])){
- foreach($this->getParameters($val) as $para){
- if(isset($this->appoption[$para])){
- unset($this->appoption[$para]);
- }
- }
- unset($this->used_apps[$val]);
- }
- }
- }
- }
- }
-
- 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]);
- }
+ /* Get application priority.
+ And ensure that each priority exists once.
+ */
+ $priority = 1;
+ if(isset($attrs['gosaApplicationPriority'])){
+ $priority= $attrs['gosaApplicationPriority'][0];
}
- foreach($free_apps as $app){
- if(isset($this->used_apps[$app])){
- unset($this->used_apps[$app]);
- }
+ while(isset($cur[$priority])){
+ $priority ++;
}
- }
-
- /* Edit application parameter */
- if((preg_match("/EdiApp_/",$name))&&(!$only_once)){
- $only_once = true;
- $appname = $value;
- $appname = preg_replace("/EdiApp_/","",$name);
- $appname = preg_replace("/_.*$/","",$appname);
-
- /* We've got the appname, get parameters from ldap */
- $ldap= $this->config->get_ldap_link();
-
- /* Check if we have release management enabled */
- $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
- if(!empty($tmp)){
+ /* Create the data object that should be added
+ * Folder
+ * Entry
+ * Release
+ */
+ $data = array();
- /* Get application parameter from ldap */
- $tmp = array_flip($this->Releases);
- $base = $tmp[$this->FAIrelease];
- $ldap->cd($base);
- $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
- $found = "";
- while($attrs = $ldap->fetch()) {
- if(preg_match("/cn=".$appname.",".$base."/",$attrs['dn'])){
- $found = $attrs['dn'];
- }
- }
- $ldap->cat($found, array("gosaApplicationParameter"));
- }else{
+ /* Add a menu folder
+ */
+ if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){
+ $type = "FOLDER";
- /* Get application parameter from ldap */
- $ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=gosaApplication)(cn=$appname))",array("gosaApplicationParameter"));
- }
+ $data['ICON'] = "";
+ if(isset($attrs['gosaApplicationIcon'])){
+ $data['ICON'] = $ldap->get_attribute($attrs['dn'],"gosaApplicationIcon");
+ }
- /* Check if this application is unique */
- if ($ldap->count() != 1){
- print_red (_("The selected application name is not uniq. Please check your LDAP."));
- } else {
+ /* Add a menu entry
+ */
+ }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){
- /* Get parameter */
- $attrs= $ldap->fetch();
+ $type = "ENTRY";
+ $data['INFO'] = "";
+ $data['PARAMETER'] = array();
if(isset($attrs['gosaApplicationParameter'])){
- $this->dialog= TRUE;
-
- /* Fill name and value arrays */
- for ($i= 0; $i<$attrs['gosaApplicationParameter']['count']; $i++){
- $option= preg_replace('/^[^:]+:/', '',
- $attrs['gosaApplicationParameter'][$i]);
- $name= preg_replace('/:.*$/', '',
- $attrs['gosaApplicationParameter'][$i]);
- $this->option_name[$i]= $name;
-
- /* Fill with values from application, default should be
- loaded by the external scripts */
- if (isset($this->appoption[$name])){
- $this->option_value[$i]= $this->appoption[$name];
+ for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){
+ if(preg_match("/:/",$attrs['gosaApplicationParameter'][$p])){
+ $tmp = split(":",$attrs['gosaApplicationParameter'][$p]);
+ $data['PARAMETER'][$tmp[0]] = $tmp[1];
+ }elseif($attrs['gosaApplicationParameter'][$p] == "*separator*"){
+ $type = "SEPERATOR";
+ $data['PARAMETER'] = array();
+ break;
}
}
+ }
- /* Create edit field */
- $table= "<table summary=\"\">";
- for ($i= 0; $i < count($this->option_name); $i++){
- if (isset($this->option_value[$i])){
- $value= $this->option_value[$i];
- } else {
- $value= "";
- }
- $table.="<tr><td>".$this->option_name[$i]."</td><td>".
- "<input name=\"value$i\" size=60 maxlength=250 ".
- "value=\"".$value."\"><br></td></tr>";
- }
- $table.= "</table>";
- $this->table= $table;
- } else {
- print_red (_("The selected application has no options."));
+ /* Add a release
+ */
+ }elseif(in_array("FAIbranch",$attrs['objectClass'])){
+ $type = "RELEASE";
+ if(isset($attrs['FAIstate'][0])){
+ $data['FAIstate'] = $attrs['FAIstate'][0];
+ }else{
+ $data['FAIstate'] = "";
}
}
- }
- }
- }
- /* Add multiple */
- if(isset($_POST['AddApps'])){
- foreach($_POST as $name => $value){
- if(preg_match("/AddApp_/",$name)){
- $app = preg_replace("/AddApp_/","",$name);
- $this->addApp($app);
+ /* Create object and append it to the current structure pointer
+ */
+ $data['LDAP_ATTRS'] = $attrs;
+ $data['DN'] = $attrs['dn'];
+ $data['NAME'] = $name;
+ $data['TYPE'] = $type;
+ $data['PRIORITY'] = $priority;
+ $data['ENTRIES'] = array();
+ $data['UNIQID'] = uniqid();
+ $data['PARENT'] = $parent_id;
+ $data['STATUS'] = "LOADED";
+ $cur[$priority] = $data;
+ ksort($cur);
}
}
}
+ }
+
+
+ function execute()
+ {
+ /* Call parent execute */
+ plugin::execute();
- /* Add application with post */
- if((isset($_GET['act']))&&($_GET['act']=="add")){
- $this->used_apps[$_GET['id']]= $_GET['id'];
- asort($this->used_apps);
- $this->addApp($_GET['id']);
+ if(isset($_GET['r'])) $this->__construct($this->config,$this->dn);
+
+ if (isset($_POST['modify_state'])){
+ $this->is_account = !$this->is_account;
}
- /* Cancel edit options? */
- if (isset($_POST['edit_options_cancel'])){
- $this->dialog= FALSE;
+ /* Do we represent a valid account? */
+ if (!$this->is_account){
+ $display= $this->show_disable_header(msgPool::addFeaturesButton(_("Menu")), msgPool::featuresDisabled(_("Menu")));
+ return ($display);
}
- /* Finish edit options? */
- if (isset($_POST['edit_options_finish'])){
- $this->dialog= FALSE;
+ $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Menu")), msgPool::featuresEnabled(_("Menu")));
- /* Save informations passed by the user */
- $this->option_value= array();
- for ($i= 0; $i<count($this->option_name); $i++){
- $this->appoption[$this->option_name[$i]]= $_POST["value$i"];
- $this->is_modified= TRUE;
+ if(isset($_GET['send'])){
+ $id = $_GET['send'];
+ $all = $this->_get_all_entries();
+ if(isset($all[$id])){
+ send_binary_content($all[$id]['ICON'],$id.".jpg","image/jpeg");
+ exit;
}
}
- /* Prepare templating stuff */
- $smarty= get_smarty();
- $smarty->assign("used_apps", $this->used_apps);
- $apps= array();
- foreach ($this->apps as $key => $value){
- if (!array_key_exists($key, $this->used_apps)){
- $apps["$key"]= "$value";
+ if(isset($_GET['r']))
+ $this->__construct($this->config,$this->dn);
+
+ if(count($this->edit_entry)){
+ if($this->edit_entry['TYPE'] == "ENTRY"){
+ $smarty = get_smarty();
+ $smarty->assign("type", "ENTRY");
+ $smarty->assign("entry",$this->edit_entry);
+ $smarty->assign("paras",$this->app_parameter);
+ $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
+ return($display);
+ }
+ if($this->edit_entry['TYPE'] == "FOLDER"){
+ $smarty = get_smarty();
+
+ session::set("binarytype" , "image/jpeg");
+ session::set("binary" , $this->edit_entry['ICON']);
+
+ $smarty->assign("rand", microtime(TRUE));
+ $smarty->assign("image_set" , strlen($this->edit_entry['ICON']) > 0);
+ $smarty->assign("type", "FOLDER");
+ $smarty->assign("entry",$this->edit_entry);
+ $display= $smarty->fetch (get_template_path('edit_entry.tpl', TRUE, dirname(__FILE__)));
+ return($display);
}
}
+ $smarty = get_smarty();
+ $smarty->assign("plug_id" , $_GET['plug']);
/* 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);
}
}
- /* Create 'open' and 'add' links */
- if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
- $linkadd = "<a href='?plug=".$_GET['plug']."&act=add&id=%s'>%s</a>";
- }else{
- $linkadd = "%s";
- }
$linkopen = "<a href='?plug=".$_GET['plug']."&act=depopen&depid=%s'>%s</a>";
/* Create base back entry */
/* Append departments for current base */
foreach($departments as $key => $app){
$div->AddEntry(array(
- array("string"=>"<img class='center' src='images/folder.png' alt='"._("department")."'> ".sprintf($linkopen,base64_encode($key),$app),
+ array("string"=>"<img class='center' src='images/lists/folder.png' alt='"._("department")."'> ".sprintf($linkopen,
+ base64_encode($key),$app),
"attach"=>"style='border:0px;'")
));
}
+
/* Add applications found on this base */
- foreach($apps as $key => $app){
+ $used_apps = $this->_get_used_entry_name();
+ foreach($this->apps as $key => $app){
+ if(in_array($app['cn'][0],$used_apps)){
+ continue;
+ }
+ if(!preg_match("/".get_ou('applicationou').normalizePreg($this->curbase)."$/",$app['dn'])){
+ continue;
+ }
+
+ $name = $app['cn'][0];
+ if(isset($app['description'])){
+ $name .= " [".$app['description'][0]."]";
+ }
$div->AddEntry(array(
array("string"=>sprintf("<input class='center' type='checkbox' value='1' name='AddApp_%s'>",$key).
- "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".sprintf($linkadd,$key,$app),
+ "<img class='center' src='images/select_application.png' alt='"._("application")."'> ".$name,
"attach"=>"style='border:0px;'")
));
}
- /* Create list of used/assigned applications */
- $div2 = new divSelectBox("appgroup");
- $div2->SetHeight(300);
-
- /* Check acls to create "edit/remove" category links */
- if(!$this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
- $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
- $catremove = " <img src='images/empty.png' alt=' '>";
- $catupdown = "";
+ /* Assign copy / paste values
+ */
+ if(!empty($this->copied_release)){
+ $smarty->assign("copied", TRUE);
+ $smarty->assign("copy_source", $this->copied_release);
}else{
- $linkopen = "<img class='center' src='images/folder.png' alt=\"\"> <a href='?plug=".$_GET['plug']."&act=open&id=%s'>%s</a>";
- $catremove = " <input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelCat_%s' value='%s'>";
- $catupdown = "<a href='?plug=".$_GET['plug']."&act=cat_up&id=%s'>".
- "<img align='top' alt=\"\" src='images/sort_up.png' border=0 title='"._("Move up")."'>".
- "</a> ".
- "<a href='?plug=".$_GET['plug']."&act=cat_down&id=%s'>".
- "<img alt=\"\" src='images/sort_down.png' title='"._("Move down")."' border=0>".
- "</a>";
+ $smarty->assign("copied", FALSE);
}
+ $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
+ $smarty->assign("FAIrelease",$this->FAIrelease);
+ $smarty->assign("app_list",$div->DrawList());
+ $smarty->assign("i",0);
+ $smarty->assign("releases",$this->Releases);
+ $smarty->assign("folders" , $this->_get_folder_names());
+ $entries = $this->_get_entries_for_release($this->FAIrelease);
+ $smarty->assign("entries",$entries);
+ $display.= $smarty->fetch (get_template_path('app_list.tpl', TRUE, dirname(__FILE__)));
+ return($display);
+ }
- /* Add back category for current category */
- if(empty($this->curCatDir)){
- $cnt =0;
- }else{
- $cnt = count(split("/",$this->curCatDir));
- $tmp = split("/",$this->curCatDir);
- $bbk = "";
- for($i = 0 ; $i < ($cnt -1 ) ; $i++){
- $bbk .= $tmp[$i]."/";
+
+ /*! \brief Returns all used folder names
+ @return Array All used folder names.
+ */
+ function _get_folder_names()
+ {
+ $data = $this->_get_entries_for_release($this->FAIrelease);
+ $all = $this->_get_all_entries();
+ $ret = array("BASE" => ".");
+ foreach($data as $entry){
+
+ if($entry['TYPE'] == "FOLDER"){
+ $str = $entry['NAME'];
+ $parent = $entry['PARENT'];
+ $i = 10;
+ while(isset($all[$parent]) && $i){
+ $i --;
+ $parent_o = $all[$parent];
+ $str = $parent_o['NAME']."/".$str;
+ $parent = $all[$parent_o['UNIQID']]['PARENT'];
+ }
+ $ret[$entry['UNIQID']] = $str;
}
- $bbk = preg_replace("/\/$/","",$bbk);
- $div2 ->AddEntry(array(array("string"=>sprintf($linkopen,base64_encode($bbk),".. ["._("Back")."]")),array("string"=>" ","attach"=>"style='border-right:0px;'")));
}
+ return($ret);
+ }
- /* Add sub categories */
- $this->GetSubdirs($this->curCatDir);
- foreach($this->GetSubdirs($this->curCatDir) as $path => $name){
- $div2 ->AddEntry(array(
- array("string"=>sprintf($linkopen,base64_encode($path),$name)),
- array("string"=>preg_replace("/%s/",base64_encode($path),$catupdown.$catremove),
- "attach"=>"align='right' style='width:80px;border-right:0px;'")));
- }
- /* Create priority & seperator links */
- $separator ="<hr size=1>";
- if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){
- $sep = "<input type='image' src='images/back.png' title='"._("Insert seperator")."' value='%s' name='AddSep_%s'>";
- $upudown = "<a href='?plug=".$_GET['plug']."&act=one_up&id=%s'>".
- " <img alt='{t}sort{/t}' align='top' src='images/sort_up.png' title='"._("Move up")."' border=0>".
- "</a> ".
- "<a href='?plug=".$_GET['plug']."&act=one_down&id=%s'>".
- " <img alt='{t}sort{/t}' src='images/sort_down.png' title='"._("Move down")."' border=0>".
- "</a> ".
- "<input type='image' src='images/edittrash.png' title='"._("Delete entry")."' name='DelApp_%s' value='%s' alt='{t}delete{/t}' >";
- }else{
- $sep = "";
- $upudown = "";
- }
-
- /* Create edit link */
- if($this->acl_is_writeable("gosaApplicationParameter",$this->no_release_acls)){
- $edit= " <input type='image' src='images/edit.png' title='"._("Edit entry")."' name='EdiApp_%s' value='%s' alt='{t}edit{/t}' >";
- }else{
- $edit= "";
+ /*! \brief return all used applications
+ @return Array All used applications.
+ */
+ function _get_used_entry_name()
+ {
+ $data = $this->_get_entries_for_release($this->FAIrelease);
+ $ret = array();
+ foreach($data as $entry){
+ if($entry['TYPE'] == "ENTRY"){
+ $ret[] = $entry['NAME'];
+ }
}
+ return($ret);
+ }
- /* Get differences to mark those entries that have changed from last edit. */
- $Differences = $this->diffAppsInReleases();
- /* Walk through entries an append them to list */
- if(isset($this->gosaMemberApplication[$this->curCatDir])){
- foreach($this->gosaMemberApplication[$this->curCatDir] as $cat => $entry){
+ /*! \brief Returns all folder an entries for the selected release
+ @return Array Returns the complete menu structure for the given array.
+ */
+ function _get_entries_for_release($release,$cur = NULL)
+ {
+ $all = $this->_get_all_entries();
+ $key = $this->_get_release_key($release);
+ if(isset($all[$key]) && count($all[$key]['ENTRIES'])){
+ $res = $this->_get_all_entries(TRUE,TRUE,$all[$key]['ENTRIES']);
+ return($res);
+ }
+ return(array());
+ }
- /* Add seperator */
- if(preg_match("/__SEPARATOR__/",$entry['App'])){
- $div2 ->AddEntry(array(array("string"=>$separator),
- array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$upudown),"attach"=>"align='right' style='border-right:0px;'")));
- }else{
- /* Add application */
+ /*! \brief Save the currently edited entry
+ */
+ function _save_entry_edit()
+ {
+ $all = $this->_get_all_entries();
+ $entry = $this->edit_entry;
+ $r_entry= &$all[$entry['UNIQID']];
- $image = "";
- /* Check if application was available within selected release
- * or application list if release management is not active
- */
- if(!in_array($entry['App'],$this->AllAppsForRelease)){
+ if($entry['TYPE'] == "ENTRY"){
+ $r_entry['PARAMETER'] = $this->app_parameter;
+ $r_entry['STATUS'] = "EDITED";
+ }
+ if($entry['TYPE'] == "FOLDER"){
+ $r_entry['ICON'] = $this->edit_entry['ICON'];
+ $r_entry['STATUS'] = "EDITED";
+ }
+ $this->dialog = FALSE;
+ $this->edit_entry = array();
+ }
- /* release managent is active
- */
- if(!$this->enableReleaseManagement){
- $image = "<img class='center' alt='R' src='images/select_invalid_application.png'
- title='"._("This application is no longer available.")."'> ";
- }else{
- $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)."\"> ";
- }
+
+ /*! \brief prepare the entry with the given ID, to be edited.
+ Read application Parameter from ldap.
+ */
+ function _edit_entry_edit($id)
+ {
+ $all = $this->_get_all_entries();
+ $entry = $all[$id];
+
+ $this->app_parameter = array();
+ if($entry['TYPE'] == "ENTRY"){
+ $found = FALSE;
+ foreach($this->apps as $id => $app){
+
+ if($app['cn'][0] == $entry['NAME']){
+ $found = TRUE;
+ break;
+ }
+ }
+ if($found){
- }elseif(isset($Differences[$entry['App']]) && ($Differences[$entry['App']] == true)) {
- $entry['App'].=" <i>["._("Check parameter")."]</i>";
- $image = "<img class='center' src='images/select_invalid_application.png'
- title='"._("This application has changed parameters.")."'> ";
- }else{
- $image = "<img class='center' src='images/select_application.png' alt=\"\"> ";
+ /* Create a list of editable parameter */
+ if(isset($app['gosaApplicationParameter'])){
+ for($i = 0 ; $i < $app['gosaApplicationParameter']['count'] ; $i++) {
+ $para = $app['gosaApplicationParameter'][$i];
+ $tmp = split(":",$para);
+ $this->app_parameter[$tmp[0]] = $tmp[1];
}
-
- $div2->AddEntry(array(array("string"=>sprintf($image."%s",$entry['App'])),
- array("string"=>preg_replace("/\%s/",htmlentities($entry['App']),$sep.$edit.$upudown),
- "attach"=>"align='right' style='width:100px;border-right:0px;'")));
}
+
+ /* Overwrite parameters with entry parameters */
+ foreach($entry['PARAMETER'] as $name => $value){
+ $this->app_parameter[$name] = $value;
+ }
+
+ $this->dialog = TRUE;
+ $this->edit_entry = $entry;
}
}
- /* Assign created div lists to template */
- $smarty->assign("UsedApps", $div2->DrawList());
- $smarty->assign("List", $div->DrawList());
- $smarty->assign("apps", $apps);
-
- $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement);
+ if($entry['TYPE'] == "FOLDER"){
+ $this->dialog = TRUE;
+ $this->edit_entry = $entry;
+ }
+ }
- $smarty->assign("ReleaseSelectAble", false);
- $smarty->assign("Release", $this->FAIrelease);
-
- if($this->enableReleaseManagement){
- $smarty->assign("FAIrelease", $this->FAIrelease);
- $smarty->assign("Releases", $this->Releases);
- if(!$this->no_release_acls && count($this->Releases)){
- $smarty->assign("ReleaseSelectAble", true);
+ /*! \brief Removes the menu structure from ldap
+ */
+ function remove_from_parent()
+ {
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->dn);
+ $ldap->ls("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",$this->dn,array("*"));
+ $a_remove = array();
+ while($attrs = $ldap->fetch()){
+ $a_remove[] = $attrs['dn'];
+ }
+ foreach($a_remove as $remove){
+ $ldap->rmdir_recursive($remove);
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
}
}
-
- /* Set acls to template */
- $tmp = $this->plInfo();
- foreach($tmp['plProvidedAcls'] as $acl => $translation){
- $smarty->assign($acl."ACL",$this->getacl($acl,$this->no_release_acls));
- }
+ $this->_load_menu_structure();
+ }
- /* Assign multiple edit values */
- foreach(array("apps") as $attr){
- if(in_array($attr,$this->multi_boxes)){
- $smarty->assign("use_".$attr,TRUE);
- }else{
- $smarty->assign("use_".$attr,FALSE);
- }
- }
- $smarty->assign("multiple_support",$this->multiple_support_active);
-
- /* Show main page */
- if (($this->dialog)){
- $smarty->assign("table", $this->table);
- $display.= $smarty->fetch (get_template_path('application_options.tpl', TRUE,dirname(__FILE__)));
- } else {
- $display.= $smarty->fetch (get_template_path('application.tpl', TRUE,dirname(__FILE__)));
- }
- return ($display);
+
+ function check()
+ {
+ $message = plugin::check();
+ return($message);
}
- function getReleases()
+ /*! \brief Create missing releases, if there is a release selected \
+ that is currently not part of the menu structure \
+ then create this entry
+ */
+ function _check_missing_release($release)
{
- /* Only display those releases that we are able to read */
- $dn = $this->config->current['BASE'];
- $filter = "(&(objectClass=organizationalUnit)(objectClass=FAIbranch))";
- $res = get_list($filter,"application", $dn, array("ou"), GL_SUBSEARCH);
-
- $ret =array();
- foreach($res as $attrs){
- if(preg_match("/".get_ou('applicationou')."/",$attrs['dn'])){
- $bb = preg_replace("/".get_ou('applicationou').".*/","",$attrs['dn']);
- $parts = array_reverse(split("ou=",$bb));
-
- $str ="";
- foreach($parts as $part){
- if(empty($part)) {
- continue;
- }
- $str .= str_replace(",","",$part)."/";
- }
- $name = preg_replace("/\/$/","",$str);
- if(empty($name)) {
- $name ="/";
+ $release_info = $this->Releases[$release];
+
+ $parent_id = $this->a_Structure[0]['UNIQID'];
+ $cur = &$this->a_Structure[0]['ENTRIES'];
+ for($i = 0 ; $i < count($release_info['parts']) ; $i ++){
+ $part = $release_info['parts'][$i];
+ $found = FALSE;
+ foreach($cur as $key => $name){
+ if($name['NAME'] == $part){
+ $parent_id = $cur[$key]['UNIQID'];
+ $cur = &$cur[$key]['ENTRIES'];
+
+ $found =TRUE;
+ break;
}
- $ret[$attrs['dn']] = $name;
+ }
+ if(!$found){
+ $release = array();
+ $release['UNIQID'] = uniqid();
+ $release['PARENT'] = $parent_id;
+ $release['NAME'] = $part;
+ $release['TYPE'] = "RELEASE";
+ $release['ENTRIES']= array();
+ $release['STATUS'] = "ADDED";
+ $release['FAIstate'] = $release_info['FAIstate'];
+ $cur[] = $release;
+ $i --;
}
}
- natcasesort($ret);
- return($ret);
}
- function save_object()
+
+
+ /*! \brief Moves a given object ($id) in a specified direction ($dir).
+ @param String The object ID of the object we want to move
+ @dir String Move "up" or "down"
+ */
+ function _move_entry($id,$dir)
{
+ $all = $this->_get_all_entries();
+ if($dir == "down"){
+ $to = $this->_get_next($id);
+ }
+ if($dir == "up"){
+ $to = $this->_get_last($id);
+ }
- /* Move category one position up or down */
- if((isset($_GET['act']))&&(($_GET['act'] == "cat_up")||($_GET['act']=="cat_down"))){
- if($_GET['act']=="cat_up"){
- $this->catUp(base64_decode($_GET['id']));
- }
- if($_GET['act']=="cat_down"){
- $this->catDown(base64_decode($_GET['id']));
- }
+ if(!$to){
+ return;
}
- /* Move application one position up or down */
- if((isset($_GET['act']))&&(($_GET['act'] == "one_up")||($_GET['act']=="one_down"))){
- if(isset($_GET['id'])){
- $id = $_GET['id'];
- $act = $_GET['act'];
+ $o_to = $all[$to];
+ $o_from = $all[$id];
- if($act == "one_up"){
- $this->getOneUp($id);
- }elseif($act == "one_down") {
- $this->getOneDown($id);
+ if($o_to['PARENT'] == $o_from['UNIQID'] && $dir == "down"){
+ $to = $this->_get_next($to,$o_from['PARENT']);
+ $o_to = $all[$to];
+ }
+
+ /* Target is ENTRY && same BASE, just switch */
+ if($o_to['PARENT'] == $o_from['PARENT'] ){
+ $parent = $all[$o_to['PARENT']];
+ $pos = 0;
+ foreach($parent['ENTRIES'] as $entry){
+ $pos ++;
+ if($entry['UNIQID'] == $to){
+ break;
}
}
+ if($dir == "up" && $pos > 0){
+ $pos --;
+ }
+ $this->_add_entry($parent['UNIQID'],$o_from,$pos);
+ $this->_remove_entry_id($id);
+ return(TRUE);
}
-
-
- plugin::save_object();
+ return(FALSE);
}
-
- function remove_from_parent()
+
+
+ /*! \brief Returns the railing object ID of the given object.
+ @return String The id of the trailing object.
+ */
+ function _get_last($id)
{
- if(!$this->initially_was_account){
- return;
+ $all_l = array_reverse($this->_get_entries_for_release($this->FAIrelease));
+ for($i = 0 ; $i < count($all_l) ; $i ++){
+ if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
+ $i++;
+ break;
+ }
+ }
+ while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER","CLOSE","OPEN")) && $i < count($all_l)){
+ $i++;
}
- plugin::remove_from_parent();
+ if(!isset($all_l[$i])){
+ return(FALSE);
+ }
- $ldap= $this->config->get_ldap_link();
- $ldap->cd($this->dn);
- $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));
+ if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
+ return($all_l[$i]['PARENT']);
+ }
- /* Optionally execute a command after we're done */
- $this->handle_post_events("remove");
+ return($all_l[$i]['UNIQID']);
}
- /* Save to LDAP */
- function save()
+ /*! \brief Returns the following object ID of the given object.
+ @return String The id of the following object.
+ */
+ function _get_next($id,$parent = 0)
{
- /* Skip saving application settings, if we do not have release acls */
- if($this->no_release_acls && $this->enableReleaseManagement){
- new log("security","groups/".get_class($this),$this->dn,array(),"Skip saving group application extension. Caused by insufficient acls");
-
- return;
+ $all_l = $this->_get_entries_for_release($this->FAIrelease);
+ for($i = 0 ; $i < count($all_l) ; $i ++){
+ if(isset($all_l[$i]['UNIQID']) && $all_l[$i]['UNIQID'] == $id){
+ $i++;
+ break;
+ }
}
+ if($parent != 0){
+ while(isset($all_l[$i]) && $all_l[$i]['PARENT'] != $parent){
+ $i++;
+ }
+ }else{
+ while(isset($all_l[$i]) && !in_array($all_l[$i]['TYPE'],array("ENTRY","FOLDER")) && $i < count($all_l)){
+ $i++;
+ }
+ }
+ if(!isset($all_l[$i])){
+ return(FALSE);
+ }
+ if(in_array($all_l[$i]['TYPE'],array("CLOSE","OPEN"))){
+ return($all_l[$i]['PARENT']);
+ }
+ return($all_l[$i]['UNIQID']);
+ }
- plugin::save();
-
- /* Copy members */
- $tmp = array("" => "");
- $tmp = array_merge($tmp,$this->Categories);
-
- $this->attrs["gosaMemberApplication"]= array();
- $this->attrs["gosaApplicationParameter"]= array();
- $cat_id= 0 ;
- foreach($tmp 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 ++;
+
+
+
+ /* !\brief Handle ui POSTS, like sort up/down/delete
+ */
+ function save_object()
+ {
+ foreach($_POST as $name => $value){
+
+ if(preg_match("/^menu_copy_/",$name)){
+ $this->copied_release = $this->FAIrelease;
+ break;
+ }
+ if(preg_match("/^menu_paste_/",$name)){
+ $source_rel = $this->_get_release_key($this->copied_release);
+ $current_rel = $this->_get_release_key($this->FAIrelease);
+
+ $all = $this->_get_all_entries();
+ $menu = $all[$source_rel]['ENTRIES'];
+
+ foreach($menu as $entry){
+ if(in_array($entry['TYPE'],array("FOLDER","ENTRY","SEPERATOR"))){
+ $this->_add_entry($current_rel,$entry,-1);
}
}
+ break;
+ }
+
+ if(preg_match("/del_/",$name)){
+ $id = preg_replace("/^del_/","",$name);
+ $id = preg_replace("/_(x|y)$/","",$id);
+ $this->_remove_entry_id($id);
+ break;
+ }
+ if(preg_match("/app_entry_edit/",$name)){
+ $id = preg_replace("/^app_entry_edit/","",$name);
+ $id = preg_replace("/_(x|y)$/","",$id);
+ $this->_edit_entry_edit($id);
+ break;
}
- if(($i==0)&&(!empty($name))){
- $this->attrs["gosaMemberApplication"][]= "|".$name."|".$cat_id;
+ if(preg_match("/up_/",$name)){
+ $id = preg_replace("/^up_/","",$name);
+ $id = preg_replace("/_(x|y)$/","",$id);
+ $this->_move_entry($id,"up");
+ break;
+ }
+ if(preg_match("/down_/",$name)){
+ $id = preg_replace("/^down_/","",$name);
+ $id = preg_replace("/_(x|y)$/","",$id);
+ $this->_move_entry($id,"down");
+ break;
+ }
+ if(preg_match("/^parameter_/",$name) &&
+ count($this->edit_entry) && $this->edit_entry['TYPE'] == "ENTRY"){
+ $name = preg_replace("/^parameter_/","",$name);
+ $this->app_parameter[$name] = $value;
+ }
+ }
+ if(isset($_POST['FAIrelease'])){
+ $this->FAIrelease = $_POST['FAIrelease'];
+ $this->_check_missing_release($this->FAIrelease);
+ }
+ if(isset($_GET['act']) && $_GET['act'] == 'depopen'){
+ $this->curbase = base64_decode($_GET['depid']);
+ }
+ if(isset($_POST['add_to_folder']) && isset($_POST['folder'])){
+ $folder = $_POST['folder'];
+ foreach($_POST as $name => $value){
+ if(preg_match("/^AddApp_[0-9]*$/",$name)){
+ $this->_add_app_id($folder,preg_replace("/^AddApp_/","",$name));
+ }
}
- $cat_id++;
}
+ /* Add seperator */
+ if(isset($_POST['add_seperator']) && isset($_POST['menu_folder'])){
+ $folder = $_POST['menu_folder'];
+ $this->_add_seperator($folder);
+ }
-
- /* Are there application parameters to be saved */
- $this->attrs['gosaApplicationParameter']= array();
- foreach($this->appoption as $name => $value){
- if ($value != ""){
- $this->attrs['gosaApplicationParameter'][]= "$name:$value";
+ if(isset($_POST['add_menu_to_folder']) && isset($_POST['menu_folder'])){
+ $folder = $_POST['menu_folder'];
+ $name = $_POST['menu_folder_name'];
+ if(strlen($name) > 0 && preg_match("/[a-z ]/i",$name)){
+ $this->_add_sub_folder($folder,$name);
}
}
+ if(isset($_POST['app_entry_save'])){
+ $this->_save_entry_edit();
+ }
- /* Write back to LDAP */
- $ldap= $this->config->get_ldap_link();
- $ldap->cd($this->dn);
- $this->cleanup();
- $ldap->modify ($this->attrs);
+ if(isset($_FILES['folder_image']) && isset($_POST['folder_image_upload'])){
+ if($_FILES['folder_image']['error'] == 0 && $_FILES['folder_image']['size'] > 0){
+ $this->edit_entry['ICON'] = file_get_contents($_FILES['folder_image']['tmp_name']);
+ }
+ }
- 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());
- }
+ if(isset($_POST['edit_reset_image'])){
+ $this->edit_entry['ICON'] = "";
+ }
- show_ldap_error($ldap->get_error(), sprintf(_("Saving of groups/applications with dn '%s' failed."),$this->dn));
+ if(isset($_POST['app_entry_cancel'])){
+ $this->edit_entry = array();
+ $this->dialog = FALSE;
+ }
+ $this->reload();
+ }
- /* Optionally execute a command after we're done */
- if ($this->initially_was_account == $this->is_account){
- if ($this->is_modified){
- $this->handle_post_events("modify");
+
+ /*! \brief Returns the UNIQID of the currently selected release
+ */
+ function _get_release_key($release,$add_if_missing = FALSE)
+ {
+ $release_info = $this->Releases[$release];
+
+ if($release_info['name'] == "/"){
+ return($this->a_Structure['0']['UNIQID']);
+ }
+
+ $cur = &$this->a_Structure[0]['ENTRIES'];
+ $s_key = "";
+ $found = FALSE;
+ foreach($release_info['parts'] as $name){
+ foreach($cur as $key => $obj){
+ if($obj['TYPE'] == "RELEASE" && $obj['NAME'] == $name){
+ $s_key = $cur[$key]['UNIQID'];
+ $cur = &$cur[$key]['ENTRIES'];
+ $found = TRUE;
+ break;
+ }
+ $found = FALSE;
}
- } else {
- $this->handle_post_events("add");
}
-
+ if($found){
+ return($s_key);
+ }
+ return(FALSE);
}
- function check()
+
+ /*! \brief Add a new folder folder to the specified folder id
+ @param String $folder The folder id in where we want to add the new folder.
+ @param String $name The name of the new folder.
+ */
+ function _add_sub_folder($folder,$name)
{
- /* Call common method to give check the hook */
- $message= plugin::check();
-
- return ($message);
+ $all = $this->_get_all_entries();
+ if($folder == "BASE"){
+ $folder = $this->_get_release_key($this->FAIrelease,TRUE);
+ }
+
+ if(isset($all[$folder])){
+ $a_folder = array();
+ $a_folder['STATUS'] = "ADDED";
+ $a_folder['NAME'] = $name;
+ $a_folder['UNIQID'] = uniqid();
+ $a_folder['ENTRIES']= array();
+ $a_folder['PARENT'] = $folder;
+ $a_folder['TYPE'] = "FOLDER";
+ $a_folder['ICON'] = "";
+ $all[$folder]['ENTRIES'][] = $a_folder;
+ }
}
- function reload()
+ /* !\brief Remove the given id from the menu structure.
+ @param String ID to of the entry we want to remove.
+ @return Boolean TRUE on success
+ */
+ function _remove_entry_id($id)
{
- /* Generate applist */
- $this->apps= array();
-
- /* Special handling for release managed apps */
- $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
- if(!empty($tmp) && count($this->Releases)){
- $this->enableReleaseManagement = true;
-
- /* Check if release is available */
- $tmp = array_flip($this->Releases);
- if(isset($tmp[$this->FAIrelease])){
- $base = $tmp[$this->FAIrelease];
- }else{
-
- /* Release is not available, check if there is an alternative */
- $old_r = $this->FAIrelease;
- $k = key($tmp);
+ $all = $this->_get_all_entries();
+ if(isset($all[$id])){
+ $all[$id]['STATUS'] = "REMOVED";
+ $all[$id]['ENTRIES'] = array();
+ return(TRUE);
+ }
+ return(FALSE);
+ }
- if(isset($tmp[$k])){
-
- /* We have found an alternative release name */
- $r = $tmp[$k];
- $this->FAIrelease = $k;
- $base = $r;
-
- /* Display msg */
- if(!(!$this->initially_was_account && $old_r =="/")){
- print_red(sprintf(_("Can't resolve the release name '%s', setting release name to '%s'. Possibly the objects base has changed."),$old_r,$k));
- }
- }else{
-
- /* There are no releases available ... */
- print_red(_("There are no releases available. You will not be able to select another release."));
- return;
- }
- }
+
+ /* !\brief Adds an object to a given folder.
+ @param String The folder where we should add the entry
+ @param Array The entry we want to add.
+ @param Array The position in the destination entry array.
+ */
+ function _add_entry($folder_id,$entry,$pos = 0)
+ {
+ $all = $this->_get_all_entries();
- /* Get applications for this release */
- $base = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou').$this->curbase,$base);
- $res = get_list("(objectClass=gosaApplication)","application",$base,array("*"));
- }else{
-
- /* Get applications for this base */
- $res = get_list("(objectClass=gosaApplication)","application",get_ou('applicationou').$this->curbase,array("*"));
- }
-
- /* Append applications */
- foreach($res as $attrs){
- if (isset($attrs["description"][0])){
- $this->apps[$attrs["cn"][0]]=
- $attrs["cn"][0]." (".
- $attrs["description"][0].")";
- } else {
- $this->apps[$attrs["cn"][0]]=
- $attrs["cn"][0];
- }
+ /* Do not add removed */
+ if($entry['STATUS'] == "REMOVED"){
+ return;
}
- /* Get all apps ... */
- $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);
- foreach($res as $attrs){
-
- $testdn = preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$attrs['dn']);
- $testdn = preg_replace("/^[^,]+/","",$testdn);
- $testdn = preg_replace("/^,/","",$testdn);
+ /* Check if the folder exists
+ */
+ if(isset($all[$folder_id])){
- if($testdn == preg_replace("/".get_ou('applicationou').".*$/",get_ou('applicationou'),$tmp[$this->FAIrelease])){
- $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
- $this->AllAppsForReleaseParameter[$this->FAIrelease][$attrs['cn'][0]] = $attrs;
+ /* Check if the entry we want to add,
+ contains su objects.
+ */
+ if(!isset($entry['ENTRIES'])){
+ $entries = array();
+ }else{
+ $entries = $entry['ENTRIES'];
+ }
+ $folder = &$all[$folder_id];
+
+ /* Prepare the entry to be added.
+ */
+ $entry['UNIQID'] = uniqid();
+ $entry['PARENT'] = $folder_id;
+ $entry['ENTRIES']= array();
+ $entry['STATUS'] = "ADDED";
+
+ /* Append the ebtry to the given folder
+ and to the given position \$pos
+ */
+ $cnt = 0;
+ $new = array();
+ $added =FALSE;
+ foreach($folder['ENTRIES'] as $key => $obj){
+ if($obj['STATUS'] == "LOADED"){
+ $obj['STATUS'] = "EDITED";
}
+ if($pos == $cnt){
+ $new[] = $entry;
+ $added = TRUE;
+ }
+ $cnt ++;
+ $new[] = $obj;
}
- }else{
- foreach($res as $attrs){
- $this->AllAppsForRelease[$attrs['dn']] = $attrs['cn'][0];
+ if(!$added){
+ $new[] = $entry;
}
- }
-
- natcasesort ($this->apps);
- reset ($this->apps);
-
- if(is_array($this->gosaMemberApplication))
- foreach ($this->gosaMemberApplication as $cat){
- if(is_array($cat))
- foreach($cat as $entry){
- $this->used_apps[$entry['App']]= $entry['App'];
- }
+ $all[$folder_id]['ENTRIES'] = &$new;
+
+ /* Add sub entries too.
+ */
+ foreach($entries as $sub){
+ $this->_add_entry($entry['UNIQID'],$sub,-1);
}
+ return(TRUE);
+ }
+ return(FALSE);
}
-
- function addApp($cn)
+
+ /*! \brief Add the application identified by $app_id to folder $folder_id
+ @param String folder_id The UNIQID of the folder where we want to add the new folder.
+ @param Integer app_id The ID of the application which should be added.
+ */
+ function _add_app_id($folder_id,$app_id)
{
- if((isset($this->gosaMemberApplication[$this->curCatDir]))&&(is_array($this->gosaMemberApplication[$this->curCatDir]))){
- foreach($this->gosaMemberApplication[$this->curCatDir] as $entry){
- if($entry['App'] == $cn) return;
+ $all = $this->_get_all_entries();
+ if($folder_id == "BASE"){
+ $folder_id = $this->_get_release_key($this->FAIrelease);
+ }
+ if(isset($all[$folder_id]) && isset($this->apps[$app_id])){
+
+ $new = array();
+ $new['TYPE'] = "ENTRY";
+ $new['NAME'] = $this->apps[$app_id]['cn'][0];
+ $new['UNIQID']= uniqid();
+ $new['PARENT']= $folder_id;
+ $new['PARAMETER']= array();
+ if(isset($this->apps[$app_id]['description'][0])){
+ $new['INFO'] = $this->apps[$app_id]['description'][0];
+ }else{
+ $new['INFO'] = "";
}
+ $new['STATUS']= "ADDED";
+ $all[$folder_id]['ENTRIES'][] = $new;
}
- $this->gosaMemberApplication[$this->curCatDir][]= array("App"=>$cn);
- $this->used_apps[$cn]=$cn;
- $this->is_modified= TRUE;
}
- function removeApp($cn)
+ /*! \brief Add the application identified by $app_id to folder $folder_id
+ @param String folder_id The UNIQID of the folder where we want to add the new folder.
+ @param Integer app_id The ID of the application which should be added.
+ */
+ function _add_seperator($folder_id)
{
- $temp= array();
- foreach ($this->gosaMemberApplication as $value){
- if ($value != $cn){
- $temp[]= $value;
- }
+ $all = $this->_get_all_entries();
+ if($folder_id == "BASE"){
+ $folder_id = $this->_get_release_key($this->FAIrelease);
+ }
+
+ if(isset($all[$folder_id])){
+ $new = array();
+ $new['TYPE'] = "SEPERATOR";
+ $new['NAME'] = "SEPERATOR";
+ $new['UNIQID']= uniqid();
+ $new['PARENT']= $folder_id;
+ $new['PARAMETER']= array();
+ $new['STATUS']= "ADDED";
+ $all[$folder_id]['ENTRIES'][] = $new;
}
- $this->gosaMemberApplication= $temp;
- $this->is_modified= TRUE;
}
- function getParameters($app)
+
+ /*! \brief Return all entries linear. ($this->a_Structure is a multidimensional array)
+ @param Boolean $add_tags If TRUE, OPEN/CLOSE Tags will be appended.
+ Used in the smarty template to display logical sperations.
+ @param &Array Start here, Pointer to an array.
+ */
+ function _get_all_entries($add_tags = FALSE, $skip_release = FALSE, &$cur = NULL)
{
- $tmp = $this->getReleases();
$ret = array();
- if(in_array($this->FAIrelease,$tmp)){
- $tmp2 = array_flip($tmp);
- $base = $tmp2[$this->FAIrelease];
- $ldap = $this->config->get_ldap_link();
- $ldap->cd($this->config->current['BASE']);
- $ldap->search("(&(objectClass=gosaApplication)(cn=".$app.")(gosaApplicationParameter=*))",array("gosaApplicationParameter"));
- if($ldap->count()){
- $attrs = $ldap->fetch();
- for($i = 0 ; $i < $attrs['gosaApplicationParameter']['count'] ; $i ++ ){
- $name = preg_replace("/:.*$/","",$attrs['gosaApplicationParameter'][$i]);
- $ret[$name] = $name;
+ if($cur == NULL){
+ $cur = &$this->a_Structure;
+ }
+
+ /* Walk through all entries and append them to our return array
+ */
+ foreach($cur as $key => $entry){
+ if($skip_release && $entry['TYPE'] == "RELEASE"){
+ continue;
+ }
+ if($entry['TYPE'] == "ENTRY"){
+ $found = FALSE;
+ foreach($this->apps as $app){
+ if($app['cn'][0] == $entry['NAME']){
+ $found = TRUE;
+ if(isset($app['description'][0])){
+ $entry['INFO'] = "[".$app['description'][0]."]";
+ }
+ break;
+ }
}
+ if(!$found){
+ $entry['INFO'] = "<font color='red'>"._("Not available in release.")."</font>";
+ }
+ }
+
+ $tmp = $entry;
+
+ /* Recursive resolution of the subentries
+ There are two methods.
+ - Just add sub entries
+ - Add sub entries and additionaly add OPEN / CLOSE tags to be able
+ to display logical seperators in the smarty template.
+ */
+ if(!$add_tags){
+ $ret[$tmp['UNIQID']] = &$cur[$key];
+ if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
+ $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
+ }
+ }else{
+
+ if(isset($tmp['ENTRIES'])){
+ unset($tmp['ENTRIES']);
+ }
+ if($tmp['STATUS'] != "REMOVED"){
+ $ret[] = $tmp;
+ if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){
+ $add = false;
+ foreach($entry['ENTRIES'] as $entry){
+ if($entry['STATUS'] != "REMOVED"){
+ $add = TRUE;
+ break;
+ }
+ }
+
+ if($add){
+ $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['PARENT']);
+ $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,$cur[$key]['ENTRIES']));
+ $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['PARENT']);
+ }
+ }
+ }
}
}
return($ret);
}
- function GetSubdirs($dir)
+
+ /*! \brief Save this plugin data to ldap.
+ Save the current menu structure to ldap.
+ */
+ function save()
{
- $ret = array();
- $tmp1 = split("/",$this->curCatDir);
+ $ldap = $this->config->get_ldap_link();
+ $all = $this->_get_all_entries();
+ $prio = 0;
+ $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array());
+
+
+ /* Walk through the menu structure and build up the ldap data object,
+ the entry dn and the entry priority.
+ */
+ $sep_id = 0;
+ foreach($all as $entry){
+ $prio ++;
+ $cur = $entry;
+ $dn = "";
+
+ /* Build entry dn
+ */
+ do{
+ if($cur['TYPE'] == "SEPERATOR"){
+ $sep_id ++;
+ $dn.= "cn=seperator_".$sep_id.",";
+ }elseif($cur['TYPE'] == "ENTRY"){
+ $dn.= "cn=".$cur['NAME'].",";
+ }elseif($cur['TYPE'] == "FOLDER"){
+ $dn.= "cn=".$cur['NAME'].",";
+ }elseif($cur['TYPE'] == "RELEASE"){
+ $dn.= "ou=".$cur['NAME'].",";
+ }elseif($cur['TYPE'] == "BASE"){
+ }
+ if(!isset($all[$cur['PARENT']])){
+ $cur = NULL;
+ }else{
+ $cur = $all[$cur['PARENT']];
+ }
+ }while(is_array($cur));
+
+ $cur_dn = $dn.$this->dn;
+ $attrs = array();
+
+ /* Build entry data object.
+ */
+ switch($entry['TYPE']){
+ case "SEPERATOR" :
+ {
+ $attrs['objectClass'] = array("gotoMenuEntry");
+ $attrs['cn'] = "seperator_".$sep_id;
+ $attrs['gosaApplicationPriority'] = $prio;
+ $attrs['gosaApplicationParameter'] = "*separator*";
+ }
+ break;
+ case "ENTRY" :
+ {
+ $attrs['objectClass'] = array("gotoMenuEntry");
+ $attrs['cn'] = $entry['NAME'];
+ $attrs['gosaApplicationPriority'] = $prio;
+ $attrs['gosaApplicationParameter'] = array();
+
+ foreach($entry['PARAMETER'] as $name => $value){
+ $attrs['gosaApplicationParameter'][] = $name.":".$value;
+ }
+ if($entry['STATUS'] == "ADDED" && !count($attrs['gosaApplicationParameter'])){
+ unset($attrs['gosaApplicationParameter']);
+ }
+ }
+ break;
+ case "FOLDER" :
+ {
+ $attrs['objectClass'] = array("gotoSubmenuEntry");
+ $attrs['cn'] = $entry['NAME'];
+ $attrs['gosaApplicationPriority'] = $prio;
+ if($entry['STATUS'] != "ADDED"){
+ $attrs['gosaApplicationIcon'] = array();
+ }
+
+ if(!empty($entry['ICON'])){
+ $attrs['gosaApplicationIcon'] = $entry['ICON'];
+ }
+ }
+ break;
+ case "RELEASE" :
+ {
+ $attrs['ou'] = $entry['NAME'];
+ $attrs['objectClass'] = array();
+ $attrs['objectClass'][] = "top";
+ $attrs['objectClass'][] = "organizationalUnit";
+ $attrs['objectClass'][] = "FAIbranch";
+ if(!empty($entry['FAIstate'])){
+ $attrs['FAIstate'] = $entry['FAIstate'];
+ }
+ }
+ break;
+ }
- foreach($this->Categories as $path=>$cat){
- $tmp2 = split("/",$path);
-
- if((empty($this->curCatDir))&&(!preg_match("/\//",$path))){
- $abort = false;
- }elseif(((count($tmp1))+1) == (count($tmp2))){
- $abort = false;
- for($i = 0 ; $i < count($tmp1) ; $i++){
- if($tmp1[$i] != $tmp2[$i]){
- $abort = true;
+ /* Append missing ObjectClasses, ... Tagging
+ */
+ if(isset($entry['LDAP_ATTRS'])){
+ for($i = 0 ; $i < $entry['LDAP_ATTRS']['objectClass']['count']; $i ++){
+ $oc = $entry['LDAP_ATTRS']['objectClass'][$i];
+ if(!in_array($oc,$attrs['objectClass'])){
+ $attrs['objectClass'][] = $oc;
}
}
- }else{
- $abort= true;
}
- if(!$abort){
- $ret[$path]=$cat;
- }
+
+ /* Create an array containing all operations sorted by type. (add,remove...)
+ */
+ if($entry['STATUS'] == "LOADED"){
+ continue;
+ }
+ if($entry['STATUS'] == "REMOVED"){
+ if(isset($entry['DN'])){
+ $Actions['Remove'][$entry['DN']] = $entry['DN'];
+ }else{
+ $Actions['Remove'][$cur_dn] = $cur_dn;
+ }
+ }
+ if($entry['STATUS'] == "EDITED"){
+ $Actions['Edit'][$cur_dn] = $attrs;
+ }
+ if($entry['STATUS'] == "ADDED"){
+ $Actions['Add'][$cur_dn] = $attrs;
+ }
}
- return($ret);
- }
+ /* First remove entries
+ */
+ $ldap = $this->config->get_ldap_link();
+ $ldap->cd($this->config->current['BASE']);
+ foreach($Actions['Remove'] as $dn){
+ $ldap->cd($dn);
+ $ldap->cat($dn);
+ if($ldap->count()){
+ $ldap->rmdir_recursive($dn);
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+ }
+ }
+ }
+
+ /* Add new entries
+ */
+ foreach($Actions['Add'] as $dn => $data){
+ $ldap->cd($dn);
+ $ldap->cat($dn);
+ if(!$ldap->count()){
+ $ldap->add($data);
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+ }
+ }
+ }
- 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;
+ /* Modify entries
+ */
+ foreach($Actions['Edit'] as $dn => $data){
+ $ldap->cd($dn);
+ $ldap->cat($dn);
+ if($ldap->count()){
+ $ldap->modify($data);
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()));
+ }
+ }
+ }
+
+ $this->_load_menu_structure();
}
- /* Return plugin informations for acl handling */
+ /*! \brief Return plugin informations for acl handling
+ @return Array containing all plugin ACL informations
+ */
static function plInfo()
{
return (array(
}
+ /* \brief Prepare this plugin to be copied.
+ Adapt all required attributes from the source object.
+ In this case, update the menu structure too, mark all elements
+ as newly added, so they will be saved in save();
+ */
+ function PrepareForCopyPaste($source)
+ {
+ plugin::PrepareForCopyPaste($source);
+
+ $tmp = new appgroup($this->config,$source['dn']);
+ $this->is_account = TRUE;
+ $this->a_Structure = $tmp->a_Structure;
+ $all = $this->_get_all_entries();
+ foreach($all as &$entry){
+ if(isset($entry['STATUS'])){
+ $entry['STATUS'] = "ADDED";
+ }
+ }
+ }
+
+
+ /*! \brief Save HTML posts in multiple edit mode
+ */
function multiple_save_object()
{
if(isset($_POST['group_apps_multi'])){
}
}
- function multiple_execute()
- {
- return($this->execute());
- }
-
- function init_multiple_support($attrs,$all)
- {
- // Do nothing here
- }
+ /*! \brief Return values used in multiple edit mode.
+ Some values can be modified for multiple
+ groups at the same time.
+ @return Array All values that support multiple edit.
+ */
function get_multi_edit_values()
{
$ret = plugin::get_multi_edit_values();