<?php
/**
 * unit_seladd_view.php - Selection template view. All the template views have a lot code
 *
 * @author $Author: sathaporn $
 * @version $Id: unit_seladd_view.php,v 1.6 2010/06/28 12:43:23 sathaporn Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
//var_dump($selobj);

?>
<div class="selwin_body">

<?php if ($template->getval('_title') !== FALSE ) { ?>
<div class="selwin_title"><?php echo $template->getval('_title') ?></div>
<?php }?>
<?php if ($template->getval('_subtitle') !== FALSE ) { ?>
<div class="selwin_subtitle"><?php echo $subtitle ?></div>
<?php }?>
<form name="selection_form">
<table width="100%" cellpadding="0" cellspacing="0">
<?php
	$last_deptname = '';
	$template->color_track_reset();
	foreach ($selobj as $select) {
		if (is_array($deptobj) && array_key_exists($select->departmentid, $deptobj) ) {
			$deptname = $deptobj[$select->departmentid]->name;
			if ($depdisplay && isset($deptobj[$select->departmentid]->department_display) && $deptobj[$select->departmentid]->department_display != '' )
				$deptname .= '/'.$deptobj[$select->departmentid]->department_display;
			
			if ( $last_deptname =='' || $last_deptname != $deptname ) {
				$last_deptname = $deptname;
				echo '<tr><td colspan="2" ><div class="selwin_dept">'. $last_deptname .'</div></td></tr>';
			}
		}
		$color = $template->color_track('selwin_item1', 'selwin_item2');
		$checked='';
		if ( !is_null($select->checked) && is_numeric($select->checked) )
			$checked = 'checked="checked"';
		echo "<tr class=\"$color\">";
		if ( $template->getval('_cattext_flag1') !== FALSE ) {
			echo "<td class=\"selwin_text\">{$select->cattext}</td>";
		}
		echo '<td class="selwin_box">';
		echo "<input type=\"checkbox\" name=\"catid_{$select->catid}\" value=\"{$select->catid}\" $checked />";
		echo '</td>';
		echo "</tr>";
	}
?>
</table>
<div style="padding:20px"></div>
	<input type="button" value="<?php echo $template->getval('_cancel_text');?>"
		name="close" <?php osa_btn()?>
			onClick="cancelDhtml('<?php echo $template->getval('_divid') ?>');" />
	<span style="padding:20px">&nbsp;</span>
	<input type="button" value="<?php echo $template->getval('_save_text');?>"
		name="save" <?php osa_btn()?>
		onClick="submitDhtml('<?php echo base_url() . "/unit/select/update/$unitid/$type"?>',
			'selection_form',
			'<?php echo base_url() . "/unit/unit/stage/{$stagenum}/" . CMS_ACTION_EDIT . "/{$unitid}"?>',
			'<?php echo $divid ?>');" />
</form>
</div>