added extra function for filter plus update tpl class to version .16

This commit is contained in:
ceb 2003-04-26 01:19:45 +00:00
parent e7146dd451
commit 9cddaf2f6e
3 changed files with 154 additions and 139 deletions

View File

@ -1,18 +1,17 @@
<?php <?php
/**************************************************************************\ /**************************************************************************\
* phpGroupWare API - Template class * * phpGroupWare API - Template class *
* (C) Copyright 1999-2000 NetUSE GmbH Kristian Koehntopp * * (C) Copyright 1999-2000 NetUSE GmbH Kristian Koehntopp *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This is not part of phpGroupWare, but is used by phpGroupWare. * * This is not part of phpGroupWare, but is used by phpGroupWare. *
* http://www.phpgroupware.org/ * * http://www.phpgroupware.org/ *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This program is free software; you can redistribute it and/or modify it * * This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published * * under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation; either version 2.1 of the License, or * * by the Free Software Foundation; either version 2.1 of the License, or *
* any later version. * * any later version. *
\**************************************************************************/ \**************************************************************************/
/* $Id$ */
/* $Id$ */
class Template class Template
{ {
@ -26,7 +25,6 @@
/* relative filenames are relative to this pathname */ /* relative filenames are relative to this pathname */
var $root = ''; var $root = '';
var $oldroot = '';
/* $varkeys[key] = 'key'; $varvals[key] = 'value'; */ /* $varkeys[key] = 'key'; $varvals[key] = 'value'; */
var $varkeys = array(); var $varkeys = array();
@ -43,8 +41,7 @@
/* last error message is retained here */ /* last error message is retained here */
var $last_error = ''; var $last_error = '';
var $print = False;
/***************************************************************************/ /***************************************************************************/
/* public: Constructor. /* public: Constructor.
* root: template directory. * root: template directory.
@ -52,10 +49,6 @@
*/ */
function Template($root = '.', $unknowns = 'remove') function Template($root = '.', $unknowns = 'remove')
{ {
if(@isset($GLOBALS['phpgw_info']['flags']['printview']) && $GLOBALS['phpgw_info']['flags']['printview'] == True)
{
$this->print = True;
}
$this->set_root($root); $this->set_root($root);
$this->set_unknowns($unknowns); $this->set_unknowns($unknowns);
} }
@ -68,16 +61,10 @@
if (!is_dir($root)) if (!is_dir($root))
{ {
$this->halt("set_root: $root is not a directory."); $this->halt("set_root: $root is not a directory.");
return False; return false;
} }
$this->oldroot = $this->root;
$this->root = $root; $this->root = $root;
return True; return true;
}
function reset_root()
{
$this->root = $this->oldroot;
} }
/* public: set_unknowns(enum $unknowns) /* public: set_unknowns(enum $unknowns)
@ -103,7 +90,7 @@
if ($filename == '') if ($filename == '')
{ {
$this->halt("set_file: For handle $handle filename is empty."); $this->halt("set_file: For handle $handle filename is empty.");
return False; return false;
} }
$this->file[$handle] = $this->filename($filename); $this->file[$handle] = $this->filename($filename);
} }
@ -126,9 +113,8 @@
if (!$this->loadfile($parent)) if (!$this->loadfile($parent))
{ {
$this->halt("subst: unable to load $parent."); $this->halt("subst: unable to load $parent.");
return False; return false;
} }
if ($name == '') if ($name == '')
{ {
$name = $handle; $name = $handle;
@ -136,13 +122,9 @@
$str = $this->get_var($parent); $str = $this->get_var($parent);
$reg = "/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END $handle\s+-->/sm"; $reg = "/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END $handle\s+-->/sm";
preg_match_all($reg, $str, $m); preg_match_all($reg, $str, $m);
$this->set_var($name, $m[1][0]); $str = preg_replace($reg, '{' . "$name}", $str);
// ralfbecker: readded for compatibility with old way to set blocks $this->set_var($handle, $m[1][0]);
$this->set_var($parent,preg_replace($reg,'{'.$name.'}',$str)); $this->set_var($parent, $str);
if ($name != $handle)
{
$this->set_var($handle, $m[1][0]);
}
} }
/* public: set_var(array $values) /* public: set_var(array $values)
@ -152,7 +134,7 @@
* varname: name of a variable that is to be defined * varname: name of a variable that is to be defined
* value: value of that variable * value: value of that variable
*/ */
function set_var($varname, $value = '', $append=False) function set_var($varname, $value = '')
{ {
if ($varname == 'phpgw_body' && is_object($GLOBALS['phpgw']->xslttpl)) if ($varname == 'phpgw_body' && is_object($GLOBALS['phpgw']->xslttpl))
{ {
@ -169,15 +151,7 @@
print "scalar: set *$varname* to *$value*<br>\n"; print "scalar: set *$varname* to *$value*<br>\n";
} }
$this->varkeys[$varname] = $this->varname($varname); $this->varkeys[$varname] = $this->varname($varname);
$this->varvals[$varname] = $value;
if ($append)
{
$this->varvals[$varname] = $this->get_var($varname).$value;
}
else
{
$this->varvals[$varname] = $value;
}
} }
} }
else else
@ -192,16 +166,7 @@
print "array: set *$k* to *$v*<br>\n"; print "array: set *$k* to *$v*<br>\n";
} }
$this->varkeys[$k] = $this->varname($k); $this->varkeys[$k] = $this->varname($k);
$this->varvals[$k] = $v;
if ($append)
{
$this->varvals[$k] = $this->get_var($k).$v;
}
else
{
$this->varvals[$k] = $v;
}
} }
} }
} }
@ -215,7 +180,7 @@
if (!$this->loadfile($handle)) if (!$this->loadfile($handle))
{ {
$this->halt("subst: unable to load $handle."); $this->halt("subst: unable to load $handle.");
return False; return false;
} }
$str = $this->get_var($handle); $str = $this->get_var($handle);
@ -233,7 +198,7 @@
function psubst($handle) function psubst($handle)
{ {
print $this->subst($handle); print $this->subst($handle);
return False; return false;
} }
/* public: parse(string $target, string $handle, boolean append) /* public: parse(string $target, string $handle, boolean append)
@ -242,12 +207,19 @@
* handle: handle of template to substitute * handle: handle of template to substitute
* append: append to target handle * append: append to target handle
*/ */
function parse($target, $handle, $append = False) function parse($target, $handle, $append = false)
{ {
if (!is_array($handle)) if (!is_array($handle))
{ {
$str = $this->subst($handle); $str = $this->subst($handle);
$this->set_var($target, $str, $append); if ($append)
{
$this->set_var($target, $this->get_var($target) . $str);
}
else
{
$this->set_var($target, $str);
}
} }
else else
{ {
@ -261,10 +233,10 @@
return $str; return $str;
} }
function pparse($target, $handle, $append = False) function pparse($target, $handle, $append = false)
{ {
print $this->parse($target, $handle, $append); print $this->parse($target, $handle, $append);
return False; return false;
} }
/* This is short for finish parse */ /* This is short for finish parse */
@ -322,14 +294,14 @@
if (!$this->loadfile($handle)) if (!$this->loadfile($handle))
{ {
$this->halt("get_undefined: unable to load $handle."); $this->halt("get_undefined: unable to load $handle.");
return False; return false;
} }
preg_match_all("/\{([^}]+)\}/", $this->get_var($handle), $m); preg_match_all("/\{([^}]+)\}/", $this->get_var($handle), $m);
$m = $m[1]; $m = $m[1];
if (!is_array($m)) if (!is_array($m))
{ {
return False; return false;
} }
reset($m); reset($m);
while(list($k, $v) = each($m)) while(list($k, $v) = each($m))
@ -346,7 +318,7 @@
} }
else else
{ {
return False; return false;
} }
} }
@ -366,11 +338,7 @@
$str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template $handle: Variable \\1 undefined -->", $str); $str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template $handle: Variable \\1 undefined -->", $str);
break; break;
} }
/* If they want NOGIF policy, then I do a global replace */
if (@$GLOBALS['phpgw_info']['server']['image_type'] == 2)
{
$str = str_replace ('.gif','.png',$str);
}
return $str; return $str;
} }
@ -406,35 +374,16 @@
$new_filename = $filename; $new_filename = $filename;
} }
if ($this->print && $time!=2 && $time!=4)
{
$new_filename = $new_filename.'_print';
}
if (!file_exists($new_filename)) if (!file_exists($new_filename))
{ {
switch($time) if($time==2)
{ {
case 2: $this->halt("filename: file $new_filename does not exist.");
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root); }
$new_filename = $this->filename($filename,$new_root,3); else
break; {
case 3: $new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root);
$new_filename = $this->filename($filename,$root,4); $new_filename = $this->filename(str_replace($root.'/','',$new_filename),$new_root,2);
break;
case 4:
$this->halt("filename: file $new_filename does not exist.");
break;
default:
if (!$this->print)
{
$new_root = str_replace($GLOBALS['phpgw_info']['server']['template_set'],'default',$root);
$new_filename = $this->filename(str_replace($root.'/','',$new_filename),$new_root,4);
}
else
{
$new_filename = $this->filename($filename,$root,2);
}
} }
} }
return $new_filename; return $new_filename;
@ -455,12 +404,12 @@
{ {
if (isset($this->varkeys[$handle]) and !empty($this->varvals[$handle])) if (isset($this->varkeys[$handle]) and !empty($this->varvals[$handle]))
{ {
return True; return true;
} }
if (!isset($this->file[$handle])) if (!isset($this->file[$handle]))
{ {
$this->halt("loadfile: $handle is not a valid handle."); $this->halt("loadfile: $handle is not a valid handle.");
return False; return false;
} }
$filename = $this->file[$handle]; $filename = $this->file[$handle];
@ -468,7 +417,7 @@
if (empty($str)) if (empty($str))
{ {
$this->halt("loadfile: While loading $handle, $filename does not exist or is empty."); $this->halt("loadfile: While loading $handle, $filename does not exist or is empty.");
return False; return false;
} }
$this->set_var($handle, $str); $this->set_var($handle, $str);
@ -492,8 +441,6 @@
{ {
echo('<b>Halted.</b>'); echo('<b>Halted.</b>');
} }
$GLOBALS['phpgw_info']['flags']['nodisplay'] = True;
exit; exit;
} }

View File

@ -463,17 +463,23 @@
$_query = stripslashes($GLOBALS['query']); $_query = stripslashes($GLOBALS['query']);
} }
// If the place a in there search, it will mess everything up // If the place a '"' in there search, it will mess everything up
// Our only option is to remove it // Our only option is to remove it
if(ereg('"',$_query)) if(ereg('"',$_query))
{ {
$_query = ereg_replace('"','',$_query); $_query = ereg_replace('"','',$_query);
} }
$var = array( $var = array
(
'query_value' => stripslashes($_query), 'query_value' => stripslashes($_query),
'searchby' => $this->searchby($search_obj),
'lang_search' => lang('Search') 'lang_search' => lang('Search')
); );
if (is_array($search_obj))
{
$var['searchby'] = $this->searchby($search_obj);
}
$this->template->set_var($var); $this->template->set_var($var);
return $this->template->fp('out','search'); return $this->template->fp('out','search');
} /* search() */ } /* search() */
@ -597,50 +603,109 @@
return $this->template->fp('out','filter'); return $this->template->fp('out','filter');
} /* filter() */ } /* filter() */
/* replacement for function filter */
function new_filter($data=0)
{
if(is_array($data))
{
$filter = (isset($data['filter'])?$data['filter']:'');
$format = (isset($data['format'])?$data['format']:'all');
}
else
{
//$filter = get_var('filter',Array('GET','POST'));
$filter = $data;
$format = 'all';
}
switch($format)
{
case 'yours':
$filter_obj = array
(
array('none',lang('show all')),
array('yours',lang('only yours'))
);
break;
case 'private':
$filter_obj = array
(
array('none',lang('show all')),
array('private',lang('only private'))
);
break;
default:
$filter_obj = array
(
array('none',lang('show all')),
array('yours',lang('only yours')),
array('private',lang('only private'))
);
}
$str = '';
$indexlimit = count($filter_obj);
for($index=0; $index<$indexlimit; $index++)
{
if($filter == '')
{
$filter = $filter_obj[$index][0];
}
$str .= ' <option value="' . $filter_obj[$index][0] . '"'.($filter == $filter_obj[$index][0]?' selected':'') . '>' . $filter_obj[$index][1] . '</option>'."\n";
}
$str = ' <select name="filter" onChange="this.form.submit()">'."\n" . $str . ' </select>';
$this->template->set_var('select',$str);
$this->template->set_var('lang_filter',lang('Filter'));
return $this->template->fp('out','filter');
} /* filter() */
function xslt_filter($data=0) function xslt_filter($data=0)
{ {
if(is_array($data)) if(is_array($data))
{ {
$filter = (isset($data['filter'])?$data['filter']:''); $filter = (isset($data['filter'])?$data['filter']:'');
$yours = (isset($data['yours'])?$data['yours']:''); $format = (isset($data['format'])?$data['format']:'all');
} }
else else
{ {
$filter = get_var('filter',Array('GET','POST')); //$filter = get_var('filter',Array('GET','POST'));
$filter = $data;
$format = 'all';
} }
$filter_obj = array switch($format)
(
array
(
'key' => 'none',
'lang' => lang('show all')
),
array
(
'key' => 'yours',
'lang' => lang('only yours')
),
array
(
'key' => 'private',
'lang' => lang('only private')
)
);
if(is_array($filter_obj))
{ {
for($i=0;$i<count($filter_obj);$i++) case 'yours':
$filter_obj = array
(
array('key' => 'none','lang' => lang('show all')),
array('key' => 'yours','lang' => lang('only yours'))
);
break;
case 'private':
$filter_obj = array
(
array('key' => 'none','lang' => lang('show all')),
array('key' => 'private','lang' => lang('only private'))
);
break;
default:
$filter_obj = array
(
array('key' => 'none','lang' => lang('show all')),
array('key' => 'yours','lang' => lang('only yours')),
array('key' => 'private','lang' => lang('only private'))
);
}
for($i=0;$i<count($filter_obj);$i++)
{
if($filter_obj[$i]['key'] == $filter)
{ {
if($filter_obj[$i]['key'] == $filter) $filter_obj[$i]['selected'] = 'yes';
{
$filter_obj[$i]['selected'] = 'yes';
}
if (!$yours && $filter_obj[$i]['key'] == 'yours')
{
unset($filter_obj[$i]);
}
} }
} }
return $filter_obj; return $filter_obj;

View File

@ -139,6 +139,9 @@
<xsl:when test="$app_tpl = 'delete'"> <xsl:when test="$app_tpl = 'delete'">
<xsl:call-template name="app_delete"/> <xsl:call-template name="app_delete"/>
</xsl:when> </xsl:when>
<xsl:when test="$app_tpl = 'config'">
<xsl:call-template name="app_config"/>
</xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:call-template name="app_data"/> <xsl:call-template name="app_data"/>
</xsl:otherwise> </xsl:otherwise>