<? _title($this, $this->Language('Plugins')); ?>

<form method="post" name="model" action="<?=$this->Link('?update_id='.$_GET['id']);?>">
<input type="hidden" name="type" value="PLUGIN">
<table class="content" border=0>
<tr>
	<th><?=$this->Language('plugin');?></th>
	<th><?=$this->Language('roles');?></th>
	<th colspan="2"></th>
</tr>
<tr>
	<td><input type="text" name="name"></td>
	<td>
		<select multiple="" name="roles[]">
			<?
			while($row = $this->roles->Assoc()){

				//NB! do not add selected param
			?>
				<option value="<?=$row['id']?>"><?=$row['name']?></option>
			<?
			}
			?>
		</select>
	</td>
	<td colspan="2"><input type="submit" name="add" value="<?=$this->Language('Add');?>" onclick="$('[name=model]').attr('action', '<?=$this->Link();?>'); "></td>
</tr>

<?PHP
while($row = $this->templates->Assoc()){

		IF($_GET['action']=='edit' && $_GET['id'] == $row['id']){
		?>
			<tr id="pos_<?=$row["id"];?>">
				<td><input type="hidden" name="id" value="<?=$row['id'];?>"><input type="text" name="name" value="<?=$row['name'];?>"></td>
				<td>
					<select multiple="" name="roles[]">
						<?
						while($row2 = $this->roles->Assoc()){

							$selected = '';
							foreach($this->permissions->Rows as $row3){

								if($row2['id'] == $row3['role_id']){

									$selected = 'selected="selected"';
									break;
								}
							}
							?>
								<option value="<?=$row2['id']?>" <?=$selected;?>><?=$row2['name']?></option>
							<?
						}
						?>
					</select>
				</td>
				<td colspan="2"><input type="submit" name="update" value="<?=$this->Language('Update');?>"> <a href="<?=$this->Link('?cancel_id='.$_GET['id']);?>"><?=$this->Language('Cancel');?></a></td>
			</tr>

		<? }else{ ?>
			<tr id="pos_<?=$row["id"];?>">
				<td><a href="<?=$this->Link('?action=edit&id='.$row['id']);?>"><?=$row['name'];?></a></td>
				<td><?=$row['roles'];?></td>
				<td style="background:<?=($row['is_active'] == 1 ? '#336600' : '#CC0000');?>;"><a href="<?=$this->Link('?action=activate&id='.$row['id']);?>&is_active=<?=$row['is_active'];?>"><?=$this->Language('Activate');?></a></td>
				<td ><a href="<?=$this->Link('?action=delete&id='.$row['id']);?>" onclick="return $.confirm();"><?=$this->Language('Delete');?></a></td>
			</tr>
		<? } ?>
<? } ?>
</table>
</form>

<script>
$('#pos_<?=$_GET["id"];?>').scrollTo();
$('#pos_<?=$_GET["update_id"];?>').scrollTo();
</script>