<?php
// Thanks to Joerg Napp for some serious bugfixes in this plugin.
function smarty_function_pagesetter_listScat($args, &$smarty)
{
//$smarty->caching = 0; // Nice for debugging ...
if (!isset($args['field']))
return "Missing 'field' argument in Smarty plugin 'pagesetter_listScat'";
$field = $args['field'];
$listClass = $args['listClass'];
$level = (empty($args['level']) ? 1000 : $args['level']);
$topValue = $args['topValue'];
$currentValue = (isset($args['currentValue']) ? $args['currentValue'] : pnVarCleanFromInput('cv'));
$template = $args['tpl'];
if (isset($args['tid']))
{
$tid = $args['tid'];
}
else
{
$core = $smarty->get_template_vars('core');
$tid = $core['tid'];
}
if (!pnModAPILoad('pagesetter', 'admin'))
return pagesetterErrorPage(__FILE__, __LINE__, 'Failed to load Pagesetter admin API');
$listID = pnModAPIFunc( 'pagesetter',
'admin',
'getListIDByFieldName',
array('tid' => $tid,
'field' => $field) );
if ($listID === false)
return pagesetterErrorAPIGet();
$listInfo = pnModAPIFunc( 'pagesetter',
'admin',
'getList',
array('lid' => $listID,
'topListValueID' => $topValue) );
if ($listInfo === false)
return pagesetterErrorAPIGet();
// build the parameters for the URL.
// these are the same for every item.
$url_parameters = array();
$url_parameters['tid'] = $tid;
if (!empty($template)) {
$url_parameters['tpl'] = $template;
}
$items = $listInfo['items'];
$indent = $items[0]['indent'];
$i = 0;
$setup = array('currentValue' => $currentValue,
'listClass' => $listClass,
'field' => $field);
$html = pagesetter_listScat_rec($items, $i, $indent, count($items), $url_parameters, $setup);
return $html;
}
function pagesetter_listScat_rec(&$items, &$i, $indent, $size, &$url_parameters, &$setup)
{
if (isset($setup['listClass']) && $i == 0)
$html = "\n";
else
$html = "\n";
while ($i < $size)
{
$item = $items[$i];
if ($item['indent'] < $indent)
break;
$url_parameters['filter'] = "$setup[field]^sub^$item[id]";
$url_parameters['cv'] = $item['id'] ;
$parent = $item['parentID'] ;
$current = $setup['currentValue'];
echo $parent;
$url = pnModUrl('pagesetter', 'user', '', $url_parameters);
if ( ($indent != "0") && ($current == $parent)) //its a sub-category
$html .= "<tr><td width=20px> </td><td><a href=\"$url"."&orderby=title\">- $item[title]</a></td></tr>\n";
++$i;
if ($items[$i]['indent'] > $indent)
{
$html .= pagesetter_listScat_rec($items, $i, $indent+1, $size, $url_parameters, $setup);
}
$html .= "\n";
}
$html .= "\n";
return $html;
}
?><div class="pn-title" align="center">Library</div>
<br>
<table width="100%">
<tr>
<td width=30% valign="top" align="left" class="pn-title">
<table valign="top">
<tr><td colspan="2" class="pn-title">Categories<br><br></td></tr>
<!--[pagesetter_listBrowser field="category"]-->
</table></td>
<td width=30% valign="top" align="left" class="pn-title">
<table valign="top">
<tr><td colspan="2" class="pn-title">Subcategories<br><br></td></tr>
<!--[pagesetter_listScat field="category"]-->
</table></td>
<!--[ pnvarcleanfrominput name=cv assign=cv ]-->
<!--[pagesetter_createFilter filter="category:eq:`$cv`" assign=listFilter]-->
<td width=30% valign="top">
<div class="pn-title" >Articles<br></div>
<br>
<!--[pagesetter_inlinePubList tid=6 filter=$listFilter orderby=title pubcnt=400]-->
<br />Template courtesy of Designs By Darren.