<?php
/**
 * unit_osadd_view.php - View file for add/edit outcome(s) and skill(s)
 *
 * @author $Author: dtong $
 * @version $Id: unit_osadd_view.php,v 1.5 2011/02/02 11:32:18 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
$lang_save_button   = lang('unit_outcomes_button_save');
$lang_cancel_button = lang('unit_outcomes_button_cancel');

$lang_outcomes      = lang('unit_outcomes_column_outcomes');
$lang_skills        = lang('unit_outcomes_column_skills');
//$lang_add_button = lang('outcomes_button_add');
//$lang_save_button = lang('unit_outcomes_button_save');

$del_img_src = osa_imagepath() . 'x.gif';
$img_link = base_url() . $savelink;//"course/target/add_zms";
$img_src = base_url(). osa_imagepath() . 'edit.gif';
$onClick = "onClick=\"updateUnit('form_outcomes_skills','$img_link/outcomesid','$courseid'); return false;\"";
$img_html= "<a href='$img_link/outcomesid/$courseid' $onClick><img src='$img_src' class='outcomes_button_image' alt='Angry face' /></a>" ;

$del_img_html= "<a href='$img_link/outcomesid/$courseid' $onClick><img src='$del_img_src' class='outcomes_button_image' alt='Angry face' /></a>" ;

if (!isset($add_js))
	$add_js='';
if ((!isset($outcomes) && !isset($outcomes_dep)) || (empty($outcomes) && empty($outcomes_dep )) ) {
	echo '<center><div class="center_screen"><div class="unit_outcome_error">'.lang('unit_outcomes_nodata_error').'</div><div>&nbsp</div>';
?>
	<input type="button"
		value="<?php echo lang('unit_outcomes_nodata_close');?>"
		onclick="closeDhtmlWindow('outcomesskills');
		<?php echo $add_js;?>" <?php osa_btn();?> />
<?php
	echo '</div></center>';
	return false;
}
?>
<div class="outcomes_skills_title" ><?php echo lang('unit_outcomes_skills'); ?></div>
<form name='form_outcomes_skills' method="post">

<input type="hidden" name="courseid" value="<?php @osa_echo($courseid);?>">
<input type="hidden" name="descid" value="<?php @osa_echo($descobj->id);?>">
<input type="hidden" name="editorid" value="<?php @osa_echo($editorids);?>">

<table class='unit_outcomes_skills_table' cellspacing='0px;' border="0" >
<tr><td colspan='2'><hr class='unit_outcomes_skills_hr' /></td></tr>
<?php
	$class_td = '';
	$course = array();
	$courseid = '';
	$coursename = '';
	$last_outcomes = '';

	if ($outcomes) {
		foreach ($outcomes as $row) {
			if ($last_outcomes != $row->outcomesid && isset($row->skillsid) && $row->skillsid !== FALSE) {
				$last_outcomes  = $row->outcomesid;
				$courseid = $row->courseid;
				$coursename = $row->coursename;
				if (!in_array($courseid, $course )){
					$course[]=$courseid;
					echo "<tr><td colspan='2'><div class='itwin_dept'>$coursename</div></td></tr>";
				}
				echo "<tr><td colspan='2'><div class='outcomes_skills_header'>$lang_outcomes: $row->outcomes</div></td></tr>";
			}
			if ($class_td != '_color' )
				$class_td  = '_color';
			else
				$class_td  = '_none';

		    $checked = '';

		    if (isset($selected) && $selected != FALSE) {
			    if (array_key_exists($row->skillsid , $selected))
			   		$checked = "checked='checked'";
		    }
		    if (isset($row->skillsid) && $row->skillsid != FALSE) {
				$value = "os_$row->skillsid".'_'."$row->outcomesid";
				$checkbox="<input type='checkbox' name='os_$row->skillsid' value='$value' $checked  />";
				//<input type='textbox' value='os_$row->skillsid' />
				echo "<tr><td class='outcomes_skills_bg1$class_td' ><div class='outcomes_skills_normal'>$row->skills</div></td>";
				echo "<td class='outcomes_skills_bg2$class_td'>".$checkbox."</td></tr>";
		    }
		}
	}
	$department = array();
	$standard = array();
	$outcome = array();
	// outcomes by department
	$last_outcomes = '';
	if ($outcomes_dep) {
		foreach ($outcomes_dep as $row) {
			if ($class_td != '_color' )
				$class_td  = '_color';
			else
				$class_td  = '_none';

			if (!in_array($row->depid, $department )){
				$department[] = $row->depid;
				echo "<tr><td colspan='2'><div class='itwin_dept'>{$row->department}</div></td></tr>";
			}

			if (!in_array($row->standardid, $standard )){
				$standard[] = $row->standardid;
				echo "<tr><td colspan='2' class='itwin_standard_bg'><div class='itwin_standard'>{$row->standard}<div></td></tr>";
			}

			if (!in_array($row->outcomesid, $outcome )){
				$outcome[] = $row->outcomesid;
				echo "<tr><td colspan='2'><div class='outcomes_skills_header'>{$lang_outcomes}: {$row->outcomes}</div></td></tr>";
			}

			$checked = '';

			if (isset($selected_dep) && $selected_dep != FALSE) {
			if (array_key_exists($row->skillsid , $selected_dep))
				$checked = "checked='checked'";
			}

			if (isset($row->skillsid) && $row->skillsid != FALSE) {
				$value = "os_$row->skillsid".'_'."$row->outcomesid";
				$checkbox="<input type='checkbox' name='os_$row->skillsid' value='$value' $checked  />";
				//<input type='textbox' value='os_$row->skillsid' />
				echo "<tr><td class='outcomes_skills_bg1$class_td' ><div class='outcomes_skills_normal'>$row->skills</div></td>";
				echo "<td class='outcomes_skills_bg2$class_td'>".$checkbox."</td></tr>";
		    }
		}
	}
?>
</table>
<div class="outcomes_skills_center">
    <div class="outcomes_skills_button_padding" ></div>

    <input type="button" value="<?php echo $lang_cancel_button ?>" name="close"  <?php osa_btn(); ?>
		   onClick="cancelDhtml('<?php echo $template->getval('_divid') ?>');" />

	<span class="outcomes_skills_button_span" ></span>

    <input type="button" value="<?php echo $lang_save_button ?>" name="save" <?php osa_btn()?>
		onClick="submitDhtml('<?php echo base_url() .$savelink . $template->unitid(). "/" .$type; ?> ', 'form_outcomes_skills',
		'<?php echo base_url() . "unit/unit/stage/" . $template->getval('_stage_num') . "/" .CMS_ACTION_EDIT . "/" . $template->unitid() ?>',
		'<?php echo $template->getval('_stage_div') ?>', '<?php echo $template->getval('_divid') ?>');" />
</div>
</form>