Use mesage template for projlist errors
Use mesage template for projlist errors

<?php <?php
/* /*
* display.git_project_list.php * display.git_project_list.php
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Display - project list * Component: Display - project list
* *
* Copyright (C) 2008 Christopher Han <xiphux@gmail.com> * Copyright (C) 2008 Christopher Han <xiphux@gmail.com>
*/ */
   
require_once('util.projectcmp.php'); require_once('util.projectcmp.php');
require_once('util.descrcmp.php'); require_once('util.descrcmp.php');
require_once('util.ownercmp.php'); require_once('util.ownercmp.php');
require_once('util.agecmp.php'); require_once('util.agecmp.php');
require_once('gitutil.git_read_projects.php'); require_once('gitutil.git_read_projects.php');
   
function git_project_list($projectroot,$projectlist,$order = "project") function git_project_list($projectroot,$projectlist,$order = "project")
{ {
global $tpl,$git_projects; global $tpl,$git_projects;
$projects = git_read_projects($projectroot,$projectlist, TRUE); $projects = git_read_projects($projectroot,$projectlist, TRUE);
if (is_array($projects)) { if (is_array($projects)) {
if (count($projects) > 0) { if (count($projects) > 0) {
$tpl->clear_all_assign(); $tpl->clear_all_assign();
if ($order) if ($order)
$tpl->assign("order",$order); $tpl->assign("order",$order);
if (!isset($git_projects)) { if (!isset($git_projects)) {
switch ($order) { switch ($order) {
case "project": case "project":
usort($projects,"projectcmp"); usort($projects,"projectcmp");
break; break;
case "descr": case "descr":
usort($projects,"descrcmp"); usort($projects,"descrcmp");
break; break;
case "owner": case "owner":
usort($projects,"ownercmp"); usort($projects,"ownercmp");
break; break;
case "age": case "age":
usort($projects,"agecmp"); usort($projects,"agecmp");
break; break;
} }
$tpl->assign("projects",$projects); $tpl->assign("projects",$projects);
} else { } else {
foreach ($projects as $cat => $plist) { foreach ($projects as $cat => $plist) {
switch ($order) { switch ($order) {
case "project": case "project":
usort($projects[$cat],"projectcmp"); usort($projects[$cat],"projectcmp");
break; break;
case "descr": case "descr":
usort($projects[$cat],"descrcmp"); usort($projects[$cat],"descrcmp");
break; break;
case "owner": case "owner":
usort($projects[$cat],"ownercmp"); usort($projects[$cat],"ownercmp");
break; break;
case "age": case "age":
usort($projects[$cat],"agecmp"); usort($projects[$cat],"agecmp");
break; break;
} }
} }
$tpl->assign("categorizedprojects",$projects); $tpl->assign("categorizedprojects",$projects);
} }
} else } else {
$tpl->assign("errmsg","No projects found"); $tpl->assign("message","No projects found");
} else $tpl->assign("error",TRUE);
$tpl->assign("errmsg",$projects); }
  } else {
  $tpl->assign("message",$projects);
  $tpl->assign("error",TRUE);
  }
$tpl->display("projectlist.tpl"); $tpl->display("projectlist.tpl");
} }
   
?> ?>
   
{* {*
* error.tpl * message.tpl
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Error message template * Component: Warning/error message template
* *
* Copyright (C) 2009 Christopher Han <xiphux@gmail.com> * Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
*} *}
<div class="message {if $error}error{/if}">{$message}</div> <div class="message {if $error}error{/if}">{$message}</div>
   
{* {*
* projectlist.tpl * projectlist.tpl
* gitphp: A PHP git repository browser * gitphp: A PHP git repository browser
* Component: Project list template * Component: Project list template
* *
* Copyright (C) 2009 Christopher Han <xiphux@gmail.com> * Copyright (C) 2009 Christopher Han <xiphux@gmail.com>
*} *}
{if $errmsg} {if $message}
{* Something is wrong; display an error message instead of trying to list *} {* Something is wrong; display an error message instead of trying to list *}
{$errmsg} {include file='message.tpl'}
{else} {else}
<table cellspacing="0"> <table cellspacing="0">
{* Header *} {* Header *}
<tr> <tr>
{if $order == "project"} {if $order == "project"}
<th>Project</th> <th>Project</th>
{else} {else}
<th><a class="header" href="{$SCRIPT_NAME}?o=project">Project</a></th> <th><a class="header" href="{$SCRIPT_NAME}?o=project">Project</a></th>
{/if} {/if}
{if $order == "descr"} {if $order == "descr"}
<th>Description</th> <th>Description</th>
{else} {else}
<th><a class="header" href="{$SCRIPT_NAME}?o=descr">Description</a></th> <th><a class="header" href="{$SCRIPT_NAME}?o=descr">Description</a></th>
{/if} {/if}
{if $order == "owner"} {if $order == "owner"}
<th>Owner</th> <th>Owner</th>
{else} {else}
<th><a class="header" href="{$SCRIPT_NAME}?o=owner">Owner</a></th> <th><a class="header" href="{$SCRIPT_NAME}?o=owner">Owner</a></th>
{/if} {/if}
{if $order == "age"} {if $order == "age"}
<th>Last Change</th> <th>Last Change</th>
{else} {else}
<th><a class="header" href="{$SCRIPT_NAME}?o=age">Last Change</a></th> <th><a class="header" href="{$SCRIPT_NAME}?o=age">Last Change</a></th>
{/if} {/if}
<th>Actions</th> <th>Actions</th>
</tr> </tr>
   
{if $categorizedprojects} {if $categorizedprojects}
{* Show categorized; categorized project lists nested associatively in the project {* Show categorized; categorized project lists nested associatively in the project
list by category key *} list by category key *}
{foreach from=$categorizedprojects key=categ item=plist} {foreach from=$categorizedprojects key=categ item=plist}
{if $categ != "none"} {if $categ != "none"}
<tr> <tr>
<th>{$categ}</th> <th>{$categ}</th>
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
</tr> </tr>
{/if} {/if}
{section name=proj loop=$plist} {section name=proj loop=$plist}
<tr class="{cycle values="light,dark"}"> <tr class="{cycle values="light,dark"}">
<td> <td>
<a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=summary" class="list {if $categ != "none"}indent{/if}">{$plist[proj].project}</a> <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=summary" class="list {if $categ != "none"}indent{/if}">{$plist[proj].project}</a>
</td> </td>
<td>{$plist[proj].descr}</td> <td>{$plist[proj].descr}</td>
<td><i>{$plist[proj].owner}</i></td> <td><i>{$plist[proj].owner}</i></td>
<td> <td>
{if $plist[proj].age < 7200} {* 60*60*2, or 2 hours *} {if $plist[proj].age < 7200} {* 60*60*2, or 2 hours *}
<span class="agehighlight"><b><i>{$plist[proj].age_string}</i></b></span> <span class="agehighlight"><b><i>{$plist[proj].age_string}</i></b></span>
{elseif $plist[proj].age < 172800} {* 60*60*24*2, or 2 days *} {elseif $plist[proj].age < 172800} {* 60*60*24*2, or 2 days *}
<span class="agehighlight"><i>{$plist[proj].age_string}</i></span> <span class="agehighlight"><i>{$plist[proj].age_string}</i></span>
{else} {else}
<i>{$plist[proj].age_string}</i> <i>{$plist[proj].age_string}</i>
{/if} {/if}
</td> </td>
<td class="link"><a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=tree">tree</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=snapshot&h=HEAD">snapshot</a></td> <td class="link"><a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=tree">tree</a> | <a href="{$SCRIPT_NAME}?p={$plist[proj].project}&a=snapshot&h=HEAD">snapshot</a></td>
</tr> </tr>
{/section} {/section}
{/foreach} {/foreach}
   
{else} {else}
{* Show flat uncategorized project array *} {* Show flat uncategorized project array *}
{section name=proj loop=$projects} {section name=proj loop=$projects}
<tr class="{cycle values="light,dark"}"> <tr class="{cycle values="light,dark"}">
<td> <td>
<a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=summary" class="list">{$projects[proj].project}</a> <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=summary" class="list">{$projects[proj].project}</a>
</td> </td>
<td>{$projects[proj].descr}</td> <td>{$projects[proj].descr}</td>
<td><i>{$projects[proj].owner}</i></td> <td><i>{$projects[proj].owner}</i></td>
<td> <td>
{if $projects[proj].age < 7200} {* 60*60*2, or 2 hours *} {if $projects[proj].age < 7200} {* 60*60*2, or 2 hours *}
<span class="agehighlight"><b><i>{$projects[proj].age_string}</i></b></span> <span class="agehighlight"><b><i>{$projects[proj].age_string}</i></b></span>
{elseif $projects[proj].age < 172800} {* 60*60*24*2, or 2 days *} {elseif $projects[proj].age < 172800} {* 60*60*24*2, or 2 days *}
<span class="agehighlight"><i>{$projects[proj].age_string}</i></span> <span class="agehighlight"><i>{$projects[proj].age_string}</i></span>
{else} {else}
<i>{$projects[proj].age_string}</i> <i>{$projects[proj].age_string}</i>
{/if} {/if}
</td> </td>
<td class="link"><a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=tree">tree</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=snapshot&h=HEAD">snapshot</a></td> <td class="link"><a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=summary">summary</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=shortlog">shortlog</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=log">log</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=tree">tree</a> | <a href="{$SCRIPT_NAME}?p={$projects[proj].project}&a=snapshot&h=HEAD">snapshot</a></td>
</tr> </tr>
{/section} {/section}
   
{/if} {/if}
   
</table> </table>
{/if} {/if}
   
comments