Location: PHPKode > projects > BugIn and Ticketing System > bugin-0.65/inc/pre/list.pre.inc.php
<?php
$printPages = "";
if (!isset($_SESSION['userinfo'])) {
	header("Location: {$options['baseURL']}");
	exit;
}

// Frames target...
if ($userinfo['options'] & OPTION_FRAMES) {
	$listLinkTarget = ' target="list"';
	$meta .= "<base target=\"view\">\n";
}
else
	$listLinkTarget = "";

// Refresh if we do....
if ($userinfo['options'] & OPTION_REFRESH_LIST) {
	if ($_SERVER['QUERY_STRING'] != "")
		$meta .= "<META HTTP-EQUIV=\"refresh\" CONTENT=\"{$options['listRefresh']}, URL={$options['baseURL']}?{$_SERVER['QUERY_STRING']}\">\n";
	else
		$meta .= "<META HTTP-EQUIV=\"refresh\" CONTENT=\"{$options['listRefresh']}, URL={$options['baseURL']}?area=list\">\n";
}

if (isset($_REQUEST['view'])) {
	$_SESSION['view'] = basename($_REQUEST['view']);
}

if (isset($_REQUEST['sg'])) {
	if ($_REQUEST['sg'] != "search")
		$_SESSION['sg'] = intval($_REQUEST['sg']);
}

if (isset($_REQUEST['listCol'])) {
	if ($_REQUEST['listCol'] != "search")
		$_SESSION['listCol'] = intval($_REQUEST['listCol']);
}

if (isset($_REQUEST['project'])) {
	$_SESSION['project'] = intval($_REQUEST['project']);
}

if (isset($_REQUEST['listOrderBy'])) {
	$_SESSION['listOrderBy'] = basename($_REQUEST['listOrderBy']);
}

if (!isset($_SESSION['listOrderBy']))
	$listOrderBy = "id";
else 
	$listOrderBy = $_SESSION['listOrderBy'];

// Prints a single tickets.
function listTicketPrint($ticket) {
	global $options;
	global $bugDatabase;
	global $verbage;

	static $line = 1;

	// Line color selection
	if ($line == 0) {
		$line = 1;
		$bgColor = $options['colorTableBgAlt1'];
		$fontColor = $options['colorTableTextAlt1'];
	}
	else {
		$line = 0;
		$bgColor = $options['colorTableBgAlt2'];
		$fontColor = $options['colorTableTextAlt2'];
	}

	// Prints the ticket age too old gif...
	$ignoreStatusArray = explode(",", $ticket['status']);
	if ($options['errorTicketAge'] && ($ticket['age'] > $options['errorTicketAge']) && (!in_array($ticket['status'], explode(",", $options['closedNum'])) )) {
		$age = intval($ticket['age'] / 60);
		$err = "<img src=\"gfx/error.gif\" border=\"0\" alt=\"{$age}\">";
	}
	else {
		$err = "";
	}

	$desc = htmlentities($ticket['short_desc']);
	if ($ticket['owner']) {
		$owner = htmlentities($bugDatabase->lists['user'][$ticket['owner']]['name']);
	}
	else {
		$owner = "Unowned";
	}

	if (isset($bugDatabase->lists['user'][$ticket['creator']])) {
		$creator = htmlentities($bugDatabase->lists['user'][$ticket['creator']]['name']);
	}
	else {
		$creator = $verbage['unknown'];
	}

	if ($ticket['status']) {
		$status = htmlentities($bugDatabase->lists['status'][$ticket['status']]['name']);
	}
	else {
		$status = "Undefined";
	}

	if ($ticket['project']) {
		$showProject = htmlentities($bugDatabase->lists['project'][$ticket['project']]['name']);
	}
	else {
		$showProject = "Undefined";
	}

	echo <<<EOT
	<tr class="ticketList" bgcolor="{$bgColor}">
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}"><a href="?area=view&num={$ticket['id']}">{$ticket['id']}</a></font>{$err}</td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}"><a href="?area=view&num={$ticket['id']}">
EOT;
	if( $_SESSION['listOrderBy'] == "date_modified" )
		echo $ticket['modified'];
	else
		echo $ticket['added'];
//		<td><font color="{$fontColor}"><a href="?area=view&num={$ticket['id']}">{$ticket['added']}
	echo <<<EOT
		</a></font></td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}"><a href="?area=view&num={$ticket['id']}">{$desc}</a></font></td>
		<td bgcolor="#{$bugDatabase->lists['priority'][$ticket['priority']]['color']}"><font color="{$fontColor}" class="viewData">{$bugDatabase->lists['priority'][$ticket['priority']]['name']}</font></td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}">{$status}</font></td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}">{$creator}</font></td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}">{$owner}</font></td>
		<td class="viewData" bgcolor="{$bgColor}"><font color="{$fontColor}">{$showProject}</font></td>
	</tr>

EOT;
}

// Get project list and whatnot.
if (!isset($_SESSION['project'])) {
	$_SESSION['project'] = 0;
}

if ($_SESSION['project']) {
	$restrict = "({$bugDatabase->tablePrefix}_tickets.project = {$_SESSION['project']}) AND ";
}

$projects = "<option value=\"0\">{$verbage['lst_all_projects']}</option>\n";
$projects .= generateOptionList($bugDatabase->lists['project'], "id", $_SESSION['project']);

// Now we try and find the actual fixed and closed numbers.
$hideSQL = "";
$closedIDs = explode(",", $options['closedNum']);
while (list($key, $value) = each($closedIDs)) {
	sqlAdd($hideSQL, "{$bugDatabase->tablePrefix}_tickets.status != '{$value['id']}'", "AND");
}
sqlAdd($hideSQL, "", "AND", 1);

@$groups = implode(",", $userinfo['user_projects']);

// Set up the SQL Query
if (!isset($_SESSION['view'])) {
	buginError("Using Default View", MESSAGE_DEBUG);
	if ((count($userinfo['user_group']) > 1) || (!$userinfo['isAdmin'] && count($userinfo['user_group'])) ) {
		$things = split(",", $options['defProjView']);
	}
	else {
		$things = split(",", $options['defUserView']);
	}
	$_SESSION['view'] = $things[0];
	$_SESSION['sg'] = $things[1];
	$_SESSION['listCol'] = $things[2];
}

// Set up head line....

if (isset($_SESSION['sg']) &&
	isset($_SESSION['listCol']) &&
	isset($ticketList[$_SESSION['sg']][$_SESSION['listCol']][0]['name']))
	$listViewName = $ticketList[$_SESSION['sg']][$_SESSION['listCol']][0]['name'];
elseif ($_SESSION['listCol'] == "search")
	$listViewName = "Search Results";
else
	$listViewName = "";

$titleMatch['list'] = "List {$options['ticketName']}s ({$listViewName})";

$excludeSQL = "";

// If we're searching, remember the last search...
if ($area == "list" && (isset($_SESSION['sg']) && $_SESSION['sg'] == "search"))
	$ticketList['search']['search'] = $_SESSION['lastSearch'];


// Now we assemble the SQL...
switch ($_SESSION['view']) {
	case "unowned":
		$endmod = "{$bugDatabase->tablePrefix}_tickets.owner = '0' $hideSQL";
		break;
	case "group":
		$endmod = "{$bugDatabase->tablePrefix}_tickets.project IN ({$groups}) AND ({$bugDatabase->tablePrefix}_tickets.owner > '0') $hideSQL";
		break;
	case "custom":
		$count = 0;

		while (list($listKey, $tl) = @each($ticketList[$_SESSION['sg']][$_SESSION['listCol']])) {
			if (isset($tl['include'])) {
				while (list($key, $value) = each($tl['include'])) {
					sqlAdd($genSQL[$count], "{$value['name']} = '{$value['value']}'", "OR");
					buginError("genSQL[{$count}] added {$value['name']} = '{$value['value']}'", 1);
					if (isset($value['break'])) {
						 sqlAdd($genSQL[$count], "", "OR", 1);
						 $count ++;
					}
				}
				if (!$value['break']) {
					sqlAdd($genSQL[$count], "", "OR", 1);
					$count ++;
				}
			}

			if (isset($tl['exclude'])) {
				while (list($key, $value) = each($tl['exclude'])) {
					sqlAdd($genSQL[$count], "{$value['name']} != '{$value['value']}'", "AND");
					buginError("genSQL[{$count}] added {$value['name']} != '{$value['value']}'", 1);
					if (isset($value['break'])) {
						sqlAdd($genSQL[$count], "", "OR", 1);
						$count ++;
					}
				}
				if (!$value['break']) {
					sqlAdd($genSQL[$count], "", "OR", 1);
					$count ++;
				}
			}
			if (isset($tl['lessthen'])) {
				while (list($key, $value) = each($tl['lessthen'])) {
					sqlAdd($genSQL[$count], "{$value['name']} < '{$value['value']}'", "AND");
					buginError("genSQL[{$count}] added {$value['name']} < '%{$value['value']}%'", 1);
					if ($value["break"]) {
						sqlAdd($genSQL[$count], "", "OR", 1);
						$count ++;
					}
				}
				if (!$value['break']) {
					sqlAdd($genSQL[$count], "", "OR", 1);
					$count ++;
				}
			}
			if (isset($tl['greaterthen'])) {
				while (list($key, $value) = each($tl['greaterthen'])) {
					sqlAdd($genSQL[$count], "{$value['name']} > '{$value['value']}'", "AND");
					buginError("genSQL[{$count}] added {$value['name']} > '%{$value['value']}%'", 1);
					if ($value["break"]) {
						sqlAdd($genSQL[$count], "", "OR", 1);
						$count ++;
					}
				}
				if (!$value['break']) {
					sqlAdd($genSQL[$count], "", "OR", 1);
					$count ++;
				}
			}
			if (isset($tl['like'])) {
				while (list($key, $value) = each($tl["like"])) {
					sqlAdd($genSQL[$count], "{$value['name']} LIKE '%{$value['value']}%'", "AND");
					buginError("genSQL[{$count}] added {$value['name']} LIKE '%{$value['value']}%'", 1);
					if (isset($value['break']) && $value['break']) {
						sqlAdd($genSQL[$count], "", "OR", 1);
						$count ++;
					}
				}
				if (!$value['break']) {
					sqlAdd($genSQL[$count], "", "OR", 1);
					$count ++;
				}
			}
		}
		$includeSQL = @implode(" ", $genSQL);

		$endmod = "$includeSQL $excludeSQL";
		break;
	case "my.tickets":
		$endmod = " owner = '{$userinfo['uid']}' $hideSQL";
		break;
	case "my.closed":
		$endmod = " creator = '{$userinfo['uid']}' $hideSQL";
		break;
	default:
		$endmod = " owner = '{$userinfo['uid']}' $hideSQL";
}

$lob = array('id'=>"", 'priority'=>"", 'status'=>"", 'category'=>"", 'owner'=>"", 'creator'=>"",
       'project'=>"", 'date_modified'=>"", 'date_added'=>"");
$lob[$listOrderBy] = " SELECTED";

$i = 0;

if (isset($_REQUEST['page'])) {
	$page = intval($_REQUEST['page']);
	$limit = ($page - 1) * $options['listNumShow'];
}
else {
	$limit = 0;
	$page = 1;
}

if (!isset($restrict)) {
	$restrict = "";
}

if ($_GET['page'] == 'all' || ($userinfo['options'] & OPTION_NO_PAGING))
	$listLimit = 0;
else
	$listLimit = array($options['listNumShow'],$limit);


$endmod = ereg_replace("^(OR|AND)", "", $restrict.$endmod);
$endmod = ereg_replace("AND AND", "AND", $endmod);

$tickets = $bugDatabase->getTicketList($endmod, "", $listOrderBy, $listLimit);

if (count($tickets) < $bugDatabase->totalRecords['count(*)']) {
	$pages = intval(($bugDatabase->totalRecords['count(*)'] / $options['listNumShow']));
	if (($pages * $options['listNumShow']) < $bugDatabase->totalRecords['count(*)'])
		$pages ++; // Handle the rounding error
	for ($i = 1; $i <= $pages; $i ++) {
		if ($i == $page) {
			$printPages[$i] = $i;
		}
		else {
			$printPages[$i] = "<a href=\"?area=list&sg={$_SESSION['sg']}&listCol={$_SESSION['listCol']}&view={$_SESSION['view']}&page={$i}\"{$listLinkTarget}>{$i}</a>";
		}
	}
	$printPages = ",Pages: ".implode(" ", $printPages)." <a href=\"?area=list&sg={$_SESSION['sg']}&listCol={$_SESSION['listCol']}&view={$_SESSION['view']}&page=all\">[All]</a>";

}
if (!isset($_GET['reverse_sort'])) {
	if (!isset($_SESSION['reverse_sort'])) 
		$_SESSION['reverse_sort'] = 0;
}
else {
	$_SESSION['reverse_sort'] = intval($_GET['reverse_sort']);
}

$reverse_sort = ($_SESSION['reverse_sort'] ? " CHECKED" : "");

?>
Return current item: BugIn and Ticketing System