<?php

#
# XiVO Web-Interface
# Copyright (C) 2006-2014  Avencall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

$url = &$this->get_module('url');
$form = &$this->get_module('form');
$dhtml = &$this->get_module('dhtml');

$pager = $this->get_var('pager');
$act = $this->get_var('act');
$list = $this->get_var('list');

$page = $url->pager($pager['pages'],
		    $pager['page'],
		    $pager['prev'],
		    $pager['next'],
		    'xivo/configuration/provisioning/plugin',
		    array('act' => $act));
?>
<div class="b-list">
<?php
	if($page !== ''):
		echo '<div class="b-page">',$page,'</div>';
	endif;
?>
<form action="#" name="fm-plugin-list" method="post" accept-charset="utf-8">
<?=$form->hidden(array('name' => DWHO_SESS_NAME,'value'	=> DWHO_SESS_ID));?>
<?=$form->hidden(array('name' => 'act','value'	=> $act));?>
<?=$form->hidden(array('name' => 'page','value' => $pager['page']));?>

<div id="box_installer" class="bi_bg">
	<div class="bi_message">
	<div class="bi_loading"><?=$url->img_html('img/site/loading.gif', $this->bbf('img_loading'), 'height="75" width="75" border="0"')?></div>
	</div>
</div>

<table class="table table-condensed table-striped table-hover table-bordered" id="table-main-listing">
	<tr class="sb-top">
		<th class="th-left xspan"><span class="span-left">&nbsp;</span></th>
		<th class="th-center"><?=$this->bbf('col_name');?></th>
		<th class="th-center"><?=$this->bbf('col_description');?></th>
		<th class="th-center"><?=$this->bbf('col_version');?></th>
		<th class="th-center"><?=$this->bbf('col_size');?></th>
		<th class="th-center col-action"><?=$this->bbf('col_action');?></th>
		<th class="th-right xspan"><span class="span-right">&nbsp;</span></th>
	</tr>
<?php
	if(($list === false) || ($nb = count($list)) === 0):
?>
	<tr class="sb-content">
		<td colspan="7" class="td-single"><?=$this->bbf('no_plugin');?></td>
	</tr>
<?php
	else:
		for($i = 0;$i < $nb;$i++):
			$ref = &$list[$i];

			$upgrade = false;
			if (isset($ref['version-installable']) === true):
				if($ref['version'] !== $ref['version-installable']):
					$upgrade = true;
					$version = '<b>'.$ref['version'].' / '.$ref['version-installable'].'</b>';
				else:
					$version = $ref['version'];
				endif;
			else:
				$version = $ref['version'];
			endif;

			$plugin_size = '-';
			if (isset($ref['dsize']) === true):
				$iec_size = dwho_size_iec($ref['dsize']);
				$plugin_size = $this->bbf('size_iec_'.$iec_size[1],$iec_size[0]);
			endif;
?>
	<tr onmouseover="this.tmp = this.className; this.className = 'sb-content l-infos-over';"
	    onmouseout="this.className = this.tmp;"
	    class="sb-content l-infos-<?=(($i % 2) + 1)?>on2">
		<td class="td-left">
			&nbsp;
		</td>
		<td class="txt-left" title="<?=dwho_alttitle($ref['name']);?>">
			<?=dwho_htmlen(dwho_trunc($ref['name'],25,'...',false));?>
		</td>
		<td class="txt-left" title="<?=dwho_alttitle($ref['description']);?>">
			<?=dwho_htmlen(dwho_trunc($ref['description'],65,'...',false));?>
		</td>
		<td>
			<?=$version?>
<?php
		if ($upgrade === true):
			echo	$url->href_html($url->img_html('img/site/utils/updating.png',
							       $this->bbf('opt_upgrade'),
							       'border="0"'),
						'xivo/configuration/provisioning/plugin',
						array('act'	=> 'upgrade',
						      'id'	=> $ref['name']),
						'style="margin-left:4px"',
						$this->bbf('opt_upgrade')),"\n";
		endif;
?>
		</td>
		<td><?=$plugin_size?></td>
		<td class="td-right" colspan="2">
<?php
		if ($ref['type'] === 'installable'):
			echo	$url->href_html($url->img_html('img/site/button/add.png',
							       $this->bbf('opt_install'),
							       'border="0"'),
						'#',
						null,
						'onclick="init_install_plugin(\''.$ref['name'].'\');return(false);"',
						$this->bbf('opt_install')),"\n";
		elseif ($ref['type'] === 'installed'):
			echo	$url->href_html($url->img_html('img/site/button/edit.png',
							       $this->bbf('opt_modify'),
							       'border="0"'),
						'xivo/configuration/provisioning/plugin',
						array('act'	=> 'edit',
						      'id'	=> $ref['name']),
						$this->bbf('opt_modify')),"\n";
			echo	$url->href_html($url->img_html('img/site/button/delete.png',
							       $this->bbf('opt_uninstall'),
							       'border="0"'),
						'xivo/configuration/provisioning/plugin',
						array('act'	=> 'uninstall',
						      'id'	=> $ref['name']),
						'onclick="return(confirm(\''.$dhtml->escape($this->bbf('opt_uninstall_confirm')).'\'));"',
						$this->bbf('opt_uninstall'));
		endif;
?>
		</td>
	</tr>
<?php
		endfor;
	endif;
?>
</table>
</form>
<?php
	if($page !== ''):
		echo '<div class="b-page">',$page,'</div>';
	endif;
?>
</div>
