X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Fgoto%2Fadmin%2Fgroups%2Fapps%2Fclass_groupApplication2.inc;h=fa4f90afc586e6a63152d6ac4eaeb8fa558e572f;hb=88b696f472d82c177f49a2f9e33184bba7cfc82e;hp=f3476f02bfcda98442aab7e6c2ecc9c93c9b0e72;hpb=9687c6c6a978ebe746859650e74602a8ae728a69;p=gosa.git diff --git a/gosa-plugins/goto/admin/groups/apps/class_groupApplication2.inc b/gosa-plugins/goto/admin/groups/apps/class_groupApplication2.inc index f3476f02b..fa4f90afc 100644 --- a/gosa-plugins/goto/admin/groups/apps/class_groupApplication2.inc +++ b/gosa-plugins/goto/admin/groups/apps/class_groupApplication2.inc @@ -19,6 +19,10 @@ class appgroup2 extends plugin var $apps = array(); var $_cache = array(); + var $app_parameter = array(); + var $edit_entry = array(); + var $enableReleaseManagement = FALSE; + public function __construct(&$config, $dn= NULL, $parent= NULL) { plugin::plugin($config,$dn,$parent); @@ -32,25 +36,24 @@ class appgroup2 extends plugin $this->enableReleaseManagement = true; } - /* Get required release informations */ - if($this->enableReleaseManagement){ - $this->Releases = $this->getReleases(); -# $this->FAIrelease = 0; - } -# $this->curbase = $this->config->current['BASE']; + $this->FAIrelease = 0; + $this->Releases = $this->getReleases(); + $this->curbase = $this->config->current['BASE']; $this->reload(); } + /*! \brief Reload the list of applications for the currently selected release + */ function reload() { $ret = array(); $release_info = $this->Releases[$this->FAIrelease]; - if(1 | !isset($this->_cache['ReleaseApps'][$release_info['suffix']])){ + if(!isset($this->_cache['ReleaseApps'][$release_info['suffix']])){ $ldap = $this->config->get_ldap_link(); - $ldap->cd($this->curbase); + $ldap->cd($this->config->current['BASE']); $ldap->search("ou=apps",array("dn")); $app_deps = array(); while($attrs = $ldap->fetch()){ @@ -75,55 +78,87 @@ class appgroup2 extends plugin $this->apps = $this->_cache['ReleaseApps'][$release_info['suffix']]; } - + + + + /*! \brief generate a list of available releases + @return return an array with all available releases. + */ function getReleases() { - /* 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(array("name" => "/" , "parts" => array(),"suffix" => get_ou('applicationou'))); - 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 $key => $part){ - if(empty($part)) { - unset($parts[$key]); - continue; + if($this->enableReleaseManagement){ + + /* 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","FAIstate"), GL_SUBSEARCH); + + 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 $key => $part){ + if(empty($part)) { + unset($parts[$key]); + continue; + } + $part = str_replace(",","",$part); + $str .= $part."/"; + $parts[$key] = $part; } - $part = str_replace(",","",$part); - $str .= $part."/"; - $parts[$key] = $part; - } - $name = preg_replace("/\/$/","",$str); - if(empty($name)) { - $name ="/"; + $name = preg_replace("/\/$/","",$str); + if(empty($name)) { + $name ="/"; + } + $FAIstate = ""; + if(isset($attrs['FAIstate'])){ + $FAIstate = $attrs['FAIstate'][0]; + } + + $ret[$name] = array("name" => $name, + "FAIstate" => $FAIstate, + "dn" => $attrs['dn'], + "parts" => $parts,"suffix" => $bb.get_ou('applicationou')); } - $ret[] = array("name" => $name , "dn" => $attrs['dn'], "parts" => $parts,"suffix" => $bb.get_ou('applicationou')); } } + ksort($ret); return($ret); } + /*! \brief Load the menu structure from ldap and create a multi dimensional array + */ function _load_menu_structure() { $this->a_Structure = array(); $ldap = $this->config->get_ldap_link(); $ldap->cd($this->dn); $ldap->search("(|(objectClass=gotoSubmenuEntry)(objectClass=FAIbranch)(objectClass=gotoMenuEntry))",array("*")); - $parent_id = 0; + + $base = array(); + $base['UNIQID'] = uniqid(); + $base['PARENT'] = 0; + $base['NAME'] = ""; + $base['TYPE'] = "BASE"; + $base['ENTRIES']= array(); + $base['STATUS'] = "LOADED"; + + $this->a_Structure[0] = $base; + while($attrs = $ldap->fetch()){ - $cur = &$this->a_Structure; + $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); + + for($i = (count($sub_dn_array)-1) ; $i >= 0 ; $i--){ $name = preg_replace("/^[^=]*+=/","",$sub_dn_array[$i]); - if($i != 0){ + if($i > 0){ foreach($cur as $key => $entry){ if($entry['NAME'] == $name){ $cur = &$cur[$key]['ENTRIES']; @@ -143,11 +178,29 @@ class appgroup2 extends plugin $data = array(); if(in_array("gotoSubmenuEntry",$attrs['objectClass'])){ $type = "FOLDER"; + + $data['ICON'] = ""; + if(isset($attrs['gosaApplicationIcon'])){ + $data['ICON'] = $ldap->get_attribute($attrs['dn'],"gosaApplicationIcon"); + } + }elseif(in_array("gotoMenuEntry",$attrs['objectClass'])){ $type = "ENTRY"; + $data['PARAMETER'] = array(); + if(isset($attrs['gosaApplicationParameter'])){ + for($p = 0 ; $p < $attrs['gosaApplicationParameter']['count'] ; $p ++){ + $tmp = split(":",$attrs['gosaApplicationParameter'][$p]); + $data['PARAMETER'][$tmp[0]] = $tmp[1]; + } + } }elseif(in_array("FAIbranch",$attrs['objectClass'])){ + $type = "RELEASE"; - $data['FAIstate'] = $attrs['FAIstate'][0]; + if(isset($attrs['FAIstate'][0])){ + $data['FAIstate'] = $attrs['FAIstate'][0]; + }else{ + $data['FAIstate'] = ""; + } } $data['DN'] = $attrs['dn']; @@ -171,10 +224,44 @@ class appgroup2 extends plugin /* Call parent execute */ plugin::execute(); + 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; + } + } + 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"); @@ -192,12 +279,6 @@ class appgroup2 extends plugin } } - /* Create 'open' and 'add' links */ -# if($this->acl_is_writeable("gosaMemberApplication",$this->no_release_acls)){ - $linkadd = "%s"; - # }else{ - # $linkadd = "%s"; - # } $linkopen = "%s"; /* Create base back entry */ @@ -235,12 +316,13 @@ class appgroup2 extends plugin } $div->AddEntry(array( array("string"=>sprintf("",$key). - ""._("application")." ".sprintf($linkadd,$key,$name), + ""._("application")." ".$name, "attach"=>"style='border:0px;'") )); } + $smarty->assign("enableReleaseManagement",$this->enableReleaseManagement); $smarty->assign("FAIrelease",$this->FAIrelease); $smarty->assign("app_list",$div->DrawList()); $smarty->assign("releases",$this->Releases); @@ -251,7 +333,10 @@ class appgroup2 extends plugin return($display); } - + + /*! \brief Returns all used folder names + @return Array All used folder names. + */ function _get_folder_names() { $data = $this->_get_entries_for_release($this->FAIrelease); @@ -264,7 +349,10 @@ class appgroup2 extends plugin return($ret); } - + + /*! \brief return all used applications + @return Array All used applications. + */ function _get_used_entry_name() { $data = $this->_get_entries_for_release($this->FAIrelease); @@ -277,116 +365,135 @@ class appgroup2 extends plugin return($ret); } - + + /*! \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])){ - return($this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES'])); + if(isset($all[$key]) && count($all[$key]['ENTRIES'])){ + $res = $this->_get_all_entries(TRUE,TRUE,&$all[$key]['ENTRIES']); + return($res); } return(array()); } - function _edit_entry_edit($id) + /*! \brief Save the currently edited entry */ + function _save_entry_edit() { - } - + $all = $this->_get_all_entries(); + $entry = $this->edit_entry; + $r_entry= &$all[$entry['UNIQID']]; - function remove_from_parent() - { + 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(); } - function save() + /*! \brief prepare the entry with the given ID, to be edited. + */ + function _edit_entry_edit($id) { - $ldap = $this->config->get_ldap_link(); - $all = $this->_get_all_entries(); - $prio = 0; - foreach($all as $entry){ - $prio ++; - $cur = $entry; - $dn = ""; + $all = $this->_get_all_entries(); + $entry = $all[$id]; - do{ - if($cur['TYPE'] == "ENTRY"){ - $dn.= "cn=".$cur['NAME'].","; - }elseif($cur['TYPE'] == "FOLDER"){ - $dn.= "cn=".$cur['NAME'].","; - }elseif($cur['TYPE'] == "RELEASE"){ - $dn.= "ou=".$cur['NAME'].","; - } - $cur = $all[$cur['PARENT']]; - if(!isset($cur['PARENT'])){ - $cur = NULL; - } - }while(is_array($cur)); - $cur_dn = $dn.$this->dn; + $this->app_parameter = array(); + if($entry['TYPE'] == "ENTRY"){ + $found = FALSE; + foreach($this->apps as $id => $app){ - $attrs = array(); - switch($entry['TYPE']){ - case "ENTRY" : - { - $attrs['objectClass'] = "gotoMenuEntry"; - $attrs['cn'] = $entry['NAME']; - $attrs['gosaApplicationPriority'] = $prio; + if($app['cn'][0] == $entry['NAME']){ + $found = TRUE; + break; } - break; - case "FOLDER" : - { - $attrs['objectClass'] = "gotoSubmenuEntry"; - $attrs['cn'] = $entry['NAME']; - $attrs['gosaApplicationPriority'] = $prio; + } + if($found){ + + /* 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]; + } } - break; - case "RELEASE" : - { - $attrs['ou'] = $entry['NAME']; - $attrs['objectClass'] = array(); - $attrs['objectClass'][] = "top"; - $attrs['objectClass'][] = "organizationalUnit"; - $attrs['objectClass'][] = "FAIbranch"; - $attrs['FAIstate'] = $entry['FAIstate']; + + /* Overwrite parameters with entry parameters */ + foreach($entry['PARAMETER'] as $name => $value){ + $this->app_parameter[$name] = $value; } - break; - } - - echo $entry['STATUS']." ---> ".$cur_dn."
"; - if($entry['STATUS'] == "LOADED"){ - continue; - } - if($entry['STATUS'] == "REMOVED"){ - echo "REMOVE
"; - $ldap->rmdir_recursive($cur_dn); - echo $ldap->get_error(); - } - if($entry['STATUS'] == "EDITED"){ - echo "EDITED
"; - $ldap->cd($cur_dn); - $ldap->modify($attrs); - echo $ldap->get_error(); - print_a($attrs); - } - if($entry['STATUS'] == "ADDED"){ - echo "ADDED
"; - $ldap->cd($cur_dn); - $ldap->add($attrs); - echo $ldap->get_error(); - print_a($attrs); + + $this->dialog = TRUE; + $this->edit_entry = $entry; } } - print_a($this->a_Structure); - exit(); + if($entry['TYPE'] == "FOLDER"){ + $this->dialog = TRUE; + $this->edit_entry = $entry; + } + } + + + function remove_from_parent() + { } + function check() { } + /*! \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) + { + $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; + } + } + 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 --; + } + } + } + /* !\brief Handle ui POSTS, like sort up/down/delete */ @@ -399,8 +506,8 @@ class appgroup2 extends plugin $this->_remove_entry_id($id); break; } - if(preg_match("/edit_/",$name)){ - $id = preg_replace("/^edit_/","",$name); + 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; @@ -417,9 +524,15 @@ class appgroup2 extends plugin $this->_move_entry_down($id); 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']); @@ -439,14 +552,39 @@ class appgroup2 extends plugin $this->_add_sub_folder($folder,$name); } } + if(isset($_POST['app_entry_save'])){ + $this->_save_entry_edit(); + } + + 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(isset($_POST['edit_reset_image'])){ + $this->edit_entry['ICON'] = ""; + } + + if(isset($_POST['app_entry_cancel'])){ + $this->edit_entry = array(); + $this->dialog = FALSE; + } $this->reload(); } - - function _get_release_key($release) + + /*! \brief Returns the UNIQID of the currently selected release + */ + function _get_release_key($release,$add_if_missing = FALSE) { $release_info = $this->Releases[$release]; - $cur = &$this->a_Structure; + + 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){ @@ -466,12 +604,16 @@ class appgroup2 extends plugin return(FALSE); } - + + /*! \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) { $all = $this->_get_all_entries(); if($folder == "BASE"){ - $folder = $this->_get_release_key($this->FAIrelease); + $folder = $this->_get_release_key($this->FAIrelease,TRUE); } if(isset($all[$folder])){ @@ -542,7 +684,11 @@ class appgroup2 extends plugin return(FALSE); } - + + /*! \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) { $all = $this->_get_all_entries(); @@ -657,13 +803,22 @@ class appgroup2 extends plugin if(isset($tmp['ENTRIES'])){ unset($tmp['ENTRIES']); } - if($tmp['STATUS'] != "REMOVED"){ $ret[] = $tmp; if(isset($entry['ENTRIES']) && count($entry['ENTRIES'])){ - $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']); - $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES'])); - $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']); + $add = false; + foreach($entry['ENTRIES'] as $entry){ + if($entry['STATUS'] != "REMOVED"){ + $add = TRUE; + break; + } + } + + if($add){ + $ret[] = array("TYPE" => "OPEN", "PARENT" => $entry['UNIQID']); + $ret = array_merge($ret,$this->_get_all_entries($add_tags,$skip_release,&$cur[$key]['ENTRIES'])); + $ret[] = array("TYPE" => "CLOSE" , "PARENT" => $entry['UNIQID']); + } } } } @@ -685,6 +840,8 @@ class appgroup2 extends plugin $o_to = &$all[$to]; $o_from = &$all[$from]; + print_a($o_to,$o_from); + /*********************** * Source == Destination * Move into next parent. @@ -776,6 +933,112 @@ class appgroup2 extends plugin } + function save() + { + $ldap = $this->config->get_ldap_link(); + $all = $this->_get_all_entries(); + $prio = 0; + $Actions = array("Remove" => array(),"Edit" => array() , "Add" => array()); + + foreach($all as $entry){ + $prio ++; + $cur = $entry; + $dn = ""; + + do{ + if($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(); + switch($entry['TYPE']){ + case "ENTRY" : + { + $attrs['objectClass'] = "gotoMenuEntry"; + $attrs['cn'] = $entry['NAME']; + $attrs['gosaApplicationPriority'] = $prio; + $attrs['gosaApplicationParameter'] = array(); + + foreach($entry['PARAMETER'] as $name => $value){ + $attrs['gosaApplicationParameter'][] = $name.":".$value; + } + } + break; + case "FOLDER" : + { + $attrs['objectClass'] = "gotoSubmenuEntry"; + $attrs['cn'] = $entry['NAME']; + $attrs['gosaApplicationPriority'] = $prio; + $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; + } + + if($entry['STATUS'] == "LOADED"){ + continue; + } + if($entry['STATUS'] == "REMOVED"){ + $Actions['Remove'][$cur_dn] = $cur_dn; + } + if($entry['STATUS'] == "EDITED"){ + $Actions['Edit'][$cur_dn] = $attrs; + } + if($entry['STATUS'] == "ADDED"){ + $Actions['Add'][$cur_dn] = $attrs; + } + } + + $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); + } + } + foreach($Actions['Add'] as $dn => $data){ + $ldap->cd($dn); + $ldap->cat($dn); + if(!$ldap->count()){ + $ldap->add($data); + } + } + foreach($Actions['Edit'] as $dn => $data){ + $ldap->cd($dn); + $ldap->cat($dn); + if($ldap->count()){ + $ldap->modify($data); + } + } + } + + /* Return plugin informations for acl handling */ static function plInfo() {