<!-- job/terminated.phtml -->

 <?php if ( $this->result ): ?>

<table id="box-table">
<caption><?php echo $this->escape($this->title); ?></caption>
<thead>
<tr>
     <th scope="col">&nbsp;</th>
     <th scope="col">&nbsp;</th>
     <th scope="col"> <?php print $this->translate->_("Job Id"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Job Name"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Status"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Level"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Files"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Bytes"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Errors"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Client"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Pool"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Start Time"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("End Time"); ?> </th>
     <th scope="col"> <?php print $this->translate->_("Duration"); ?> <br /> <?php print $this->translate->_("hh-mm-ss"); ?> </th>
     <th scope="col">&nbsp;</th>
</tr>
</thead>
<tbody>
<?php foreach($this->result as $line) : ?>
<tr>
    <td style="padding: 0px;">
        <?php
            if ( isset($line['poolid'], $line['poolname']) )    {
                // restore button
                echo '<a href="';
                echo $this->baseUrl, '/restorejob/main-form/jobid/', $this->escape($line['jobid']);
                echo '" title="', $this->translate->_("Restore Job"), '">';
                echo '<img src="', $this->baseUrl, '/images/restore.png" alt="', $this->translate->_("Restore Job"), '" border="0" hspace="2">';
                echo '</a>';
            }
        ?>
    </td>
    <td style="padding: 0px;">
        <?php
            if ( isset($line['jobname']) && ($line['type'] != 'R') )    {
                // re-run button
                echo '<a href="';
                echo $this->baseUrl, '/job/run-job/jobname/', $this->escape($line['jobname']);
                echo '" title="', $this->translate->_("Re-run Job"), '">';
                echo '<img src="', $this->baseUrl, '/images/re-run-job.png" alt="', $this->translate->_("Re-run Job"), '" border="0" hspace="2">';
                echo '</a>';
            }
        ?>
    </td>
    <td>
        <a href="<?php echo $this->baseUrl, '/job/detail/jobid/', $this->escape($line['jobid']); ?>"
            title="<?php echo $this->translate->_("Detail Job"); ?>">
            <?php echo $line['jobid']; ?>
        </a>
    </td>

    <!-- Job.Name -->
    <td><?php  echo $this->escape($line['jobname']);?>  </td>

	<!-- Status -->
	<?php
		$class_td = '';
		if ( $line['joberrors'] != 0 )	{
		    if ( $line['jobstatus'] == 'T' )	{
		        $class_td = 'class="warn"';
		    } else {
		        // 100% что была какая-то ошибка
		        $class_td = 'class="err"';
		    }
			echo '<td ', $class_td, ' align="center"> ',
			     $this->translate->_( $this->escape($line['jobstatuslong']) ), ' </td>';
		}
		elseif	( $line['jobstatus'] == 'T' )	{
			echo '<td align="center">OK</td>';
		} else {
		    // ошибок вроде нет, но что-то не в порядке
		    if ( ($line['jobstatus'] == 'f') OR ($line['jobstatus'] == 'E') )	{
		        // fatal error
                $class_td = 'class="err"';
		    } else {
		        $class_td = 'class="warn"';
		    }
			echo '<td ', $class_td, ' align="center">',
			     $this->translate->_( $this->escape($line['jobstatuslong']) ), '</td>';
		}
	?>

	<td align="center"><?php echo $this->escape($line['level']);?></td>

	<?php
		if ( ($line['jobfiles'] == 0) && ($line['type'] != 'D') ) {
			$class = 'class="warn"';
		} else {
			$class = '';
		}
		echo '<td ', $class, ' align="right">', number_format($line['jobfiles']), '</td>';
	?>

	<?php
		if ( ($line['jobbytes'] == 0) && ($line['type'] != 'D') ) {
			$class = 'class="warn"';
		} else {
			$class = '';
		}
		echo '<td ', $class, ' align="right">', $this->convBytes($line['jobbytes']), '</td>';
	?>

<!-- Errors -->
<?php
    if ( $line['joberrors'] == 0 )
        echo '<td align="center">-</td>';
    else  {
        if ( $line['reviewed'] > 0 )  {
            // reviewed icon
            echo '<td align="right">';
            echo '<img src="', $this->baseUrl, '/images/dialog-ok-apply.png" align="absmiddle" ',
                ' alt="', $this->translate->_("Bacula Job Reviewed"),'"',
                ' title="', $this->translate->_("Bacula Job Reviewed"),'"',
                ' border="0" hspace="4">';
        } else
            echo '<td class="err" align="right">';
        echo '<a href="',
            $this->baseUrl, '/log/view-log-id/jobid/', $this->escape($line['jobid']), '" title="',
            $this->translate->_("View Messages"), '"';
        if ( $line['reviewed'] == 0 )
            echo ' class="linkerr" ';
        echo '>', $this->escape($line['joberrors']), '</a></td>';
    }
?>

	<td><?php echo $line['clientname'];?></td>

	<td>
		<?php
			if ( isset($line['poolid']) && isset($line['poolname']) )	{
				echo '<a href="';
				echo $this->baseUrl, "/volume/find-pool-id/id/", $this->escape($line['poolid']),
				"/name/", $this->escape($line['poolname']);
				echo '" title="', $this->translate->_("Detail Pool"), '">';
			}	else 	{
				echo "&nbsp;";
			}

			if ( isset($line['poolid']) && isset($line['poolname']) )	{
				echo $this->escape($line['poolname']);
				echo '</a>';
			}	else {
				echo '&nbsp;';
			}
		?>
	</td>

	<td>&nbsp;<?php echo $this->escape($line['starttime']);?>&nbsp;</td>
	<td>&nbsp;<?php echo $this->escape($line['endtime']);?>&nbsp;</td>
	<td align="right">&nbsp;<?php echo $this->escape($line['durationtime']);?>&nbsp;</td>

    <!-- add to logbook button -->
    <td style="padding: 0px; width:16px;"><?php
        if ( isset($line['poolid'], $line['poolname']) )    {
                echo '<a href="';
                echo $this->baseUrl, '/wblogbook/writelogbook/name_job/', $this->escape($line['jobname']),
                    '/endtime/', $this->escape($line['endtime']),
                    '/jobid/', $this->escape($line['jobid']),
                    '/joberrors/', $this->escape($line['joberrors']);
                echo '" title="', $this->translate->_("Written in Logbook"), '">';
                echo '<img src="', $this->baseUrl, '/images/bookmark-new.png" alt="', $this->translate->_("Written in Logbook"), '" border="0" hspace="2">';
                echo '</a>';
        }
        ?>
    </td>

	</tr>
<?php endforeach; ?>
</tbody>
</table>

<?php else: ?>
<div class="ui-widget" style="float: left;">
	<div class="ui-state-highlight ui-corner-all" style="padding: 0pt 0.7em; margin-top: 20px;">
		<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: 0.3em;"></span>
		<strong><?php print $this->translate->_("No Jobs found."); ?></strong></p>
		<p><a href="<?php echo $this->baseUrl, '/job/list-last-jobs-run/numjob/20'; ?>">
		<?php print $this->translate->_("See List last 20 Jobs run"); ?></a></p>
	</div>
</div>
<div style="clear: both;"><!--  --></div>
<?php endif; ?>