X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_listing.inc;h=c8861a82cd16581784fba1f67b1bec8dd1b0282f;hb=2a19cca5bf48999ebf32a2482faf6555187e6090;hp=e9085b04525887bb11a099fd4befd6a4da8b6e75;hpb=ce382410d752f2aa4abb3855016f9cc00de17a8c;p=gosa.git diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index e9085b045..c8861a82c 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -13,7 +13,8 @@ class listing { var $header= array(); var $colprops= array(); var $filters= array(); - static $objectTypes; + var $pid; + var $objectTypes; function listing($filename) @@ -23,13 +24,16 @@ class listing { } // Register build in filters - $this->registerFilter("objectType", "listing::filterObjectType"); - $this->registerFilter("link", "listing::filterLink"); - $this->registerFilter("actions", "listing::filterActions"); + $this->registerElementFilter("objectType", "listing::filterObjectType"); + $this->registerElementFilter("link", "listing::filterLink"); + $this->registerElementFilter("actions", "listing::filterActions"); + + // Initialize pid + $this->pid= preg_replace("/[^0-9]/", "", microtime(TRUE)); } - function registerFilter($name, $call) + function registerElementFilter($name, $call) { if (!isset($this->filters[$name])) { $this->filters[$name]= $call; @@ -62,7 +66,7 @@ class listing { // Fill objectTypes if (isset($this->xmlData['definition']['objectType'])) { foreach ($this->xmlData['definition']['objectType'] as $index => $otype) { - listing::$objectTypes[$otype['objectClass']]= $this->xmlData['definition']['objectType'][$index]; + $this->objectTypes[$otype['objectClass']]= $this->xmlData['definition']['objectType'][$index]; } } @@ -73,8 +77,8 @@ class listing { $this->header= array(); if (isset($this->xmlData['table']['column'])){ foreach ($this->xmlData['table']['column'] as $index => $config) { - if (isset($config['header'])) { - $this->header[$index]= "colprops[$index].">".xml::getLocalizedAttribute($config['header'], $GLOBALS['t_language']).""; + if (isset($config['label'])) { + $this->header[$index]= "colprops[$index].">"._($config['label']).""; } else { $this->header[$index]= "colprops[$index]."> "; } @@ -82,7 +86,7 @@ class listing { } // Assign headline/module - $this->headline= xml::getLocalizedAttribute($this->xmlData['definition']['headline'], $GLOBALS['t_language']); + $this->headline= _($this->xmlData['definition']['label']); $this->module= $this->xmlData['definition']['module']; return true; @@ -91,10 +95,11 @@ class listing { function render() { -echo "Handle empty lists differently, alternating, sorting, post_id, bottom list info
"; +echo "filter for images, action menu, sorting, department browsing, filter base handling, bottom list info, copy'n paste handler, snapshot handler
"; // Initialize list - $result= "
"; + $result= ""; + $result.= "
"; $result.= "
"; $num_cols= count($this->colprops) + ($this->multiSelect?1:0); @@ -114,6 +119,11 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list // New table for the real list contents $result.= "
"; + // No results? Just take an empty colspanned row + if (count($this->entries) == 0) { + $result.= ""; + } + // Fill with contents foreach ($this->entries as $row => $entry){ $result.=""; @@ -132,7 +142,7 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list // Need to fill the list if it's not full (nobody knows why this is 22 ;-)) if (count($this->entries) < 22) { $result.= ""; - for ($i= 0; $i<=$num_cols; $i++) { + for ($i= 0; $i<$num_cols; $i++) { if ($i == 0) { $result.= ""; continue; @@ -159,7 +169,7 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list } // Assign action menu - $smarty->assign("ACTIONS", "TBD"); + $smarty->assign("ACTIONS", $this->renderActionMenu()); // Assign separator $smarty->assign("SEPARATOR", "-"); @@ -174,11 +184,18 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list function setFilter($filter) { $this->filter= &$filter; + $this->entries= $this->filter->query(); } function update() { + // Do not do anything if this is not our PID + # DISABLED because the object is not in the session + #if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) { + # return; + #} + $this->entries= $this->filter->query(); } @@ -237,6 +254,14 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list } // Watch out for filters and prepare to execute them + $data= $this->processElementFilter($data, $config, $row); + + return $data; + } + + + function processElementFilter($data, $config, $row) + { preg_match_all("/%\{filter:([^(]+)\((.*)\)\}/", $data, $matches, PREG_SET_ORDER); foreach ($matches as $match) { @@ -256,10 +281,9 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list $params[]= $row; } - // pid is replaced by the current post_id + // pid is replaced by the current PID if ($param == "pid") { - #TODO: get post_id - $params[]= "99"; + $params[]= $this->pid; } // Fixie with "" is passed directly @@ -280,33 +304,39 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list // Move dn if needed if ($param == "dn") { - $params[]= $config["dn"]; + $params[]= LDAP::fix($config["dn"]); } } // Replace information - $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data); + if ($cl == "listing") { + // Non static call - seems to result in errors + $data= @preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($this, "$method"), $params), $data); + } else { + // Static call + $data= preg_replace('/'.preg_quote($match[0]).'/', call_user_func_array(array($cl, $method), $params), $data); + } } return $data; } - static function filterObjectType($dn, $classes) + function filterObjectType($dn, $classes) { // Walk thru classes and return on first match $result= " "; $prio= 99; foreach ($classes as $objectClass) { - if (isset(listing::$objectTypes[$objectClass])){ - if (!isset(listing::$objectTypes[$objectClass]["priority"])){ - $result= ""; + if (isset($this->objectTypes[$objectClass])){ + if (!isset($this->objectTypes[$objectClass]["priority"])){ + $result= ""; return $result; } - if (listing::$objectTypes[$objectClass]["priority"] < $prio){ - $prio= listing::$objectTypes[$objectClass]["priority"]; - $result= ""; + if ($this->objectTypes[$objectClass]["priority"] < $prio){ + $prio= $this->objectTypes[$objectClass]["priority"]; + $result= ""; } } } @@ -315,13 +345,19 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list } - static function filterLink() + function filterActions() + { + return "TBD"; + } + + + function filterLink() { $result= " "; $row= func_get_arg(0); $pid= func_get_arg(1); - $dn= func_get_arg(2); + $dn= LDAP::fix(func_get_arg(2)); $params= array(func_get_arg(3)); // Collect sprintf params @@ -337,7 +373,7 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list $result= " "; $trans= call_user_func_array("sprintf", $params); if ($trans != "") { - return("$trans"); + return("$trans"); } return $result; @@ -400,10 +436,122 @@ echo "Handle empty lists differently, alternating, sorting, post_id, bottom list } - static function filterActions() + function getAction() { - return "TBD"; + // Do not do anything if this is not our PID + # DISABLED because the object is not in the session + #if(isset($_REQUEST['PID']) && $_REQUEST['PID'] != $this->pid) { + # return; + #} + + $result= array("targets" => array(), "action" => ""); + + // Filter GET with "act" attributes + if (isset($_GET['act'])) { + $key= validate($_GET['act']); + $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)$/', '$1', $key); + if (isset($this->entries[$target]['dn'])) { + $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+$/', '$1', $key); + $result['targets'][]= $this->entries[$target]['dn']; + } + return $result; + } + + // Filter POST with "listing_" attributes + foreach ($_POST as $key => $prop) { + + // Capture selections + if (preg_match('/^listing_selected_[0-9]+$/', $key)) { + $target= preg_replace('/^listing_selected_([0-9]+)$/', '$1', $key); + if (isset($this->entries[$target]['dn'])) { + $result['targets'][]= $this->entries[$target]['dn']; + } + continue; + } + + // Capture action with target - this is a one shot + if (preg_match('/^listing_[a-zA-Z_]+_[0-9]+(|_x)$/', $key)) { + $target= preg_replace('/^listing_[a-zA-Z_]+_([0-9]+)(|_x)$/', '$1', $key); + if (isset($this->entries[$target]['dn'])) { + $result['action']= preg_replace('/^listing_([a-zA-Z_]+)_[0-9]+(|_x)$/', '$1', $key); + $result['targets']= array($this->entries[$target]['dn']); + } + break; + } + + // Capture action without target + if (preg_match('/^listing_[a-zA-Z_]+(|_x)$/', $key)) { + $result['action']= preg_replace('/^listing_([a-zA-Z_]+)(|_x)$/', '$1', $key); + continue; + } + } + + return $result; + } + + + function renderActionMenu() + { + // Don't send anything if the menu is not defined + if (!isset($this->xmlData['actionmenu']['action'])){ + return ""; + } + + // Load shortcut + $actions= &$this->xmlData['actionmenu']['action']; + $result= "
  • Aktionen "; + + // Build ul/li list + $result.= $this->recurseActions($actions); + + return "
    ".$result."
"; + } + + + function recurseActions($actions) + { + static $level= 2; + $result= "
    "; + $separator= ""; + + foreach ($actions as $action) { + + // Fill image if set + $img= ""; + if (isset($action['image'])){ + $img= " "; + } + + if ($action['type'] == "separator"){ + $separator= " style='border-top:1px solid #AAA' "; + continue; + } + + // Dive into subs + if ($action['type'] == "sub" && isset($action['action'])) { + $level++; + if (isset($action['label'])){ + $result.= "$img"._($action['label'])." "; + } + $result.= $this->recurseActions($action['action']).""; + $level--; + $separator= ""; + continue; + } + + // Render entry elseways + if (isset($action['label'])){ + $result.= "$img"._($action['label']).""; + $separator= ""; + } + } + + $result.= "
"; + return $result; } + + } ?>