X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_listing.inc;h=c8861a82cd16581784fba1f67b1bec8dd1b0282f;hb=2a19cca5bf48999ebf32a2482faf6555187e6090;hp=f4b6913ac8b48fb370a254068ce290dcf20f7593;hpb=4e0898b471ddafacb43f437f06a596bd3559c28d;p=gosa.git diff --git a/gosa-core/include/class_listing.inc b/gosa-core/include/class_listing.inc index f4b6913ac..c8861a82c 100644 --- a/gosa-core/include/class_listing.inc +++ b/gosa-core/include/class_listing.inc @@ -8,11 +8,13 @@ class listing { var $departmentRootVisible= false; var $multiSelect= false; var $template; - var $summary; + var $headline; + var $module; var $header= array(); var $colprops= array(); var $filters= array(); - static $objectTypes; + var $pid; + var $objectTypes; function listing($filename) @@ -22,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; @@ -61,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]; } } @@ -72,32 +77,37 @@ 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]."> "; } } } + // Assign headline/module + $this->headline= _($this->xmlData['definition']['label']); + $this->module= $this->xmlData['definition']['module']; + return true; } function render() { -echo "Fill summary, handle empty lists differently, alternating, sorting, post_id
"; - $summary= "empty"; +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); // Build list header $result.= ""; if ($this->multiSelect) { - $result.= ""; + $result.= ""; } foreach ($this->header as $header) { $result.= $header; @@ -109,13 +119,18 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i // 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.=""; // Render multi select if needed if ($this->multiSelect) { - $result.=""; + $result.=""; } foreach ($this->xmlData['table']['column'] as $index => $config) { @@ -127,7 +142,7 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i // 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; @@ -141,15 +156,47 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i $result.= ""; } - $result.= "
 
 
 
"; + $result.= "
"; - return $result; + $smarty= get_smarty(); + $smarty->assign("FILTER", $this->filter->render()); + $smarty->assign("LIST", $result); + + // Assign navigation elements + $nav= $this->renderNavigation(); + foreach ($nav as $key => $html) { + $smarty->assign($key, $html); + } + + // Assign action menu + $smarty->assign("ACTIONS", $this->renderActionMenu()); + + // Assign separator + $smarty->assign("SEPARATOR", "-"); + + // Assign summary + $smarty->assign("HEADLINE", $this->headline); + + return ($smarty->fetch(get_template_path($this->xmlData['definition']['template'], true))); + } + + + function setFilter($filter) + { + $this->filter= &$filter; + $this->entries= $this->filter->query(); } - function setEntries($entries) + function update() { - $this->entries= &$entries; + // 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(); } @@ -207,6 +254,14 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i } // 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) { @@ -226,10 +281,9 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i $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 @@ -250,33 +304,39 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i // 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= ""; } } } @@ -285,13 +345,19 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i } - 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 @@ -307,17 +373,185 @@ echo "Fill summary, handle empty lists differently, alternating, sorting, post_i $result= " "; $trans= call_user_func_array("sprintf", $params); if ($trans != "") { - return("$trans"); + return("$trans"); } return $result; } - static function filterActions() + function renderNavigation() { - return "TBD"; + $result= array(); + $enableBack = true; + $enableRoot = true; + $enableHome = true; + + $ui = get_userinfo(); + + /* Check if base = first available base */ + $deps = $ui->get_module_departments($this->module); + + if(!count($deps) || $deps[0] == $this->filter->base){ + $enableBack = false; + $enableRoot = false; + } + + $listhead =""; + + /* Check if we are in users home department */ + if(!count($deps) ||$this->filter->base == get_base_from_people($ui->dn)){ + $enableHome = false; + } + + /* Draw root button */ + if($enableRoot){ + $result["ROOT"]= ""; + }else{ + $result["ROOT"]= ""._("Root").""; + } + + /* Draw back button */ + if($enableBack){ + $result["BACK"]= ""; + }else{ + $result["BACK"]= ""._("Up").""; + } + + /* Draw home button */ + if($enableHome){ + $result["HOME"]= ""; + }else{ + $result["HOME"]= ""._("Home").""; + } + + /* Draw reload button, this button is enabled everytime */ + $result["RELOAD"]= ""; + + return ($result); } + + + function getAction() + { + // 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= "
"; + } + + + function recurseActions($actions) + { + static $level= 2; + $result= ""; + return $result; + } + + } ?>