index e9085b04525887bb11a099fd4befd6a4da8b6e75..c8861a82cd16581784fba1f67b1bec8dd1b0282f 100644 (file)
var $header= array();
var $colprops= array();
var $filters= array();
- static $objectTypes;
+ var $pid;
+ var $objectTypes;
function listing($filename)
}
// 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;
// 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];
}
}
$this->header= array();
if (isset($this->xmlData['table']['column'])){
foreach ($this->xmlData['table']['column'] as $index => $config) {
- if (isset($config['header'])) {
- $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">".xml::getLocalizedAttribute($config['header'], $GLOBALS['t_language'])."</td>";
+ if (isset($config['label'])) {
+ $this->header[$index]= "<td class='listheader' ".$this->colprops[$index].">"._($config['label'])."</td>";
} else {
$this->header[$index]= "<td class='listheader' ".$this->colprops[$index]."> </td>";
}
}
// 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;
function render()
{
-echo "Handle empty lists differently, alternating, sorting, post_id, bottom list info<br>";
+echo "filter for images, action menu, sorting, department browsing, filter base handling, bottom list info, copy'n paste handler, snapshot handler<br>";
// Initialize list
- $result= "<div class='contentboxb' id='listing_container' style='border-top:1px solid #B0B0B0;'>";
+ $result= "<input type='hidden' value='$this->pid' name='PID'>";
+ $result.= "<div class='contentboxb' id='listing_container' style='border-top:1px solid #B0B0B0;'>";
$result.= "<table summary='$this->headline' style='width:600px;height:450px;' cellspacing='0' id='t_scrolltable'>
<tr><td class='scrollhead'><table summary='' style='width:100%;' cellspacing='0' id='t_scrollhead'>";
$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.= "<tr><td colspan='$num_cols' class='scrollbody'><div style='width:600px;height:430px;' id='d_scrollbody' class='scrollbody'><table summary='' style='height:100%;width:581px;' cellspacing='0' id='t_scrollbody'>";
+ // No results? Just take an empty colspanned row
+ if (count($this->entries) == 0) {
+ $result.= "<tr class='rowxp0'><td class='list1nohighlight' colspan='$num_cols' style='height:100%;border-right:0px;width:100%;'> </td></tr>";
+ }
+
// Fill with contents
foreach ($this->entries as $row => $entry){
$result.="<tr class='rowxp".($row&1)."'>";
@@ -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.= "<tr>";
- for ($i= 0; $i<=$num_cols; $i++) {
+ for ($i= 0; $i<$num_cols; $i++) {
if ($i == 0) {
$result.= "<td class='list1nohighlight' style='height:100%;'> </td>";
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", "<img src='images/lists/seperator.png' alt='-' align='middle' height='16' width='1' class='center'>");
@@ -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= "<img class='center' title='$dn' src='".listing::$objectTypes[$objectClass]["image"]."'>";
+ if (isset($this->objectTypes[$objectClass])){
+ if (!isset($this->objectTypes[$objectClass]["priority"])){
+ $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$this->objectTypes[$objectClass]["image"]."'>";
return $result;
}
- if (listing::$objectTypes[$objectClass]["priority"] < $prio){
- $prio= listing::$objectTypes[$objectClass]["priority"];
- $result= "<img class='center' title='$dn' src='".listing::$objectTypes[$objectClass]["image"]."'>";
+ if ($this->objectTypes[$objectClass]["priority"] < $prio){
+ $prio= $this->objectTypes[$objectClass]["priority"];
+ $result= "<img class='center' title='".LDAP::fix($dn)."' src='".$this->objectTypes[$objectClass]["image"]."'>";
}
}
}
@@ -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("<a href='?plug=".$_GET['plug']."&post_id=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
+ return("<a href='?plug=".$_GET['plug']."&PID=$pid&act=listing_edit_$row' title='$dn'>$trans</a>");
}
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= "<ul class='level1' id='root'><li><a href='#'>Aktionen <img ".
+ "border=0 src='images/lists/sort-down.png'></a>";
+
+ // Build ul/li list
+ $result.= $this->recurseActions($actions);
+
+ return "<div id='pulldown'>".$result."</li></ul><div>";
+ }
+
+
+ function recurseActions($actions)
+ {
+ static $level= 2;
+ $result= "<ul class='level$level'>";
+ $separator= "";
+
+ foreach ($actions as $action) {
+
+ // Fill image if set
+ $img= "";
+ if (isset($action['image'])){
+ $img= "<img border=0 src='".$action['image']."'> ";
+ }
+
+ 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.= "<li$separator><a href='#'>$img"._($action['label'])." <img border='0' src='images/forward-arrow.png'></a>";
+ }
+ $result.= $this->recurseActions($action['action'])."</li>";
+ $level--;
+ $separator= "";
+ continue;
+ }
+
+ // Render entry elseways
+ if (isset($action['label'])){
+ $result.= "<li$separator><a href='#'>$img"._($action['label'])."</a></li>";
+ $separator= "";
+ }
+ }
+
+ $result.= "</ul>";
+ return $result;
}
+
+
}
?>