summaryrefslogtreecommitdiff
blob: ff3dd3fdacf1de09961510a473d4bba4ee295666 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
function init_builds_task() {
	global $S, $request;
	if (!isset($S['user'])) return 'login';
	if (!(isset($S['builds_log']) && isset($request['task']) && is_numeric($request['task']))) return 'builds/log';
	$r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$request['task']);
	if ($r->rowCount()) {
		$S['builds_task']=new sql_task($r->fetch(PDO::FETCH_ASSOC));
	} else
		return '404';
}
function body_builds_task() {
	global $S, $request, $conf;
	$task=&$S['builds_task'];
	echo '<div style="font-size: 130%">'.$task->display().'</div>';
	echo '<a href="'.url("build/$task->build").'">Back</a><br/>';
	$page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1;
	$count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN);
	$pager='';
	if ($count > $conf['logview_max']) {
		$pager='<form action="'.url("build/$task->build/$task->order").'" method="post" onsubmit="window.location.href=\''.url("build/$task->build/$task->order").'/\'+this.page.value; return false">Page: ';
		if ($page > 1) {
			$pager.='<input type="button" value="&lt;&lt;" onclick="this.form.page.value='.($page-1).'; this.form.onsubmit()" /> '."\n";
		}
		$pager.='<select name="page">';
		for ($i=1; ($i-1)*$conf['logview_max']<$count; $i++) {
			$pager.="<option value=\"$i\"".($i==$page?'selected="selected"':'').">$i</option>\n";
		}
		$pager.='</select> <input type="submit" value="Go" />';
		if ($page*$conf['logview_max']<$count) {
			$pager.=' <input type="button" value="&gt;&gt;" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n";
		}
		$pager.='</form>';
		echo $pager;
	}
	$r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']);
	if ($r->rowCount()) {
		echo '<div style="font-family: monospace">';
		$ansi=new ansi_to_html();
		while ($entry=$r->fetch(PDO::FETCH_ASSOC)) {
			$entry=new sql_buildlog_entry($entry);
			echo '<'.($t=($entry->stream=='stderr'?'b':'span')).' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' '.date('D j M Y @ H:i:s T', $entry->timestamp).'">'.$ansi->process($entry->text)."</$t>";
		}
		echo $ansi->reset(); // Clear any leftover <span>s
		echo '</div>';
		echo $pager;
		echo '<a href="'.url("build/$task->build").'">Back</a><br/>';
	} else {
		if ($count) {
			echo print_error("There aren't $page pages.  Try an <a href=\"".url("build/$task->build/$task->order")."\">earlier page</a>.");
		} else {
			echo print_warning('No output');
		}
	}
}
?>