<?
$this->title->elem('a');
$this->title->name($this->Language('Add banner'));
$this->title->cssClass('slideDown');
$this->title->create($this->Language('Banners')); 

$form = $this->Form;
?>

<form method="post" enctype="multipart/form-data" class="slideDownBox">
<table class="header">
<?
while($row = $this->clients->Assoc()){

	$form->option('company', $row['id'], $row['company']);
}

foreach($this->position->get_position() as $row2){

	if(preg_match('/public/i', $row2['position'])){

		if($row2['name']){

			$form->option('position', $row2['value'], $row2['name']);
		}
	}
}

$columns = array('company', 'file', 'url', 'target', 'position', 'date_at', 'date_to', 'never_expires', 'is_active');

$form->option('target', '_blank', '_blank');
$form->option('target', '_self', '_self');

$form->input($columns);
$form->select(array('target', 'company', 'position'));

$form->file('type="file"');
$form->never_expires(array('type="checkbox"', 'value=1'));
$form->is_active(array('type="checkbox"', 'value="1"', 'checked="chekced"'));
					
$form->trHeaderList($columns);
?>
<tr>
	<th></th>
	<td><input type="submit" name="insert_banner" value="<?=$this->Language('Add banner');?>"/> <a href="<?=$this->Link();?>"><?=$this->Language('Cancel');?></a></td>
</tr>
</table>
</form>


<form method="post" enctype="multipart/form-data">
<table class="content">
<?
/*
$columns = array('company', 'image', 'file', 'url', 'target', 'position', 'date_at_str', 'date_to_str', 'viewed', 'clicked', 
'never_expires' => array(0 => $this->Language('No'), 1 => $this->Language('Yes')), 
'is_active' => array(0 => $this->Language('No'), 1 => $this->Language('Yes')), 
'delete');
*/
$columns = array('company', 'file', 'url', 'target', 'position', 'date_at', 'date_to', 'never_expires', 'is_active', 'update,cancel' => '');
$form->trHeader($columns);
while($row = $this->banners->Each()){

	$this->pre($row);

	$image = $row['image'];

	if($_GET['action'] == 'edit' && $_GET['id'] == $row['id']){

		$form->input($columns);
		$form->select(array('target', 'company', 'position'));
		$form->a('cancel');

		$form->file('type="file"');
		$form->never_expires(array('type="checkbox"', 'value=1', ($row['never_expires'] == 1 ? 'checked="chekced"' : '')));
		$form->is_active(array('type="checkbox"', 'value="1"', ($row['is_active'] == 1 ? 'checked="chekced"' : '')));
		$form->update(array('type=submit', 'value='.$this->Language('Update')));
		$form->cancel(array('href="./"', 'value="'.$this->Language('Cancel').'"'));

		//$form->toElem('company_option_'.$row['client_id'], 'checked="checked"');
		//$form->toElem('position_option_'.strtolower($row['position']), 'checked="checked"');

		//$form->select('company')->selected();

		$row['image'] = $image;
		$form->tr($columns, $row);
	}
	else{

		$row['image'] = '<a href="../files/banners/'.$row['image'].'" class="ajax_images">'.($row['image'] ? '<img src="../files/banners/'.$row['image'].'" class="thmb_image" alt="banner"/>' : $this->Language('no image')).'</a>';
		$row['company'] = '<a href="'.$this->Link('?action=edit&id='.$row['id']).'" id="strutctur_row_'.$row['id'].'">'.($row['company'] ? $row['company'] : $this->Language('no company')).'</a>';
		$row['delete'] = '<a href="'.$this->Link('?action=delete&id='.$row['id']).'" class="delete">'.$this->Language('Delete').'</a>';

		$form->exception('never_expires', array($this->Language('No'), $this->Language('Yes')));
		$form->exception('is_active', array($this->Language('No'), $this->Language('Yes')));

		$form->tr($columns, $row);
	}
}
?>
</table>
</form>