<?php
/**
 * outcomes_skills_read_view.php - outcomes and skills
 *
 * @author $Author: dtong $
 * @version $Id: outcomes_skills_read_view.php,v 1.22 2011/05/09 04:48:52 dtong Exp $
 * @copyright Copyright (c) 2010, Tiller Software Co., Ltd.
*/
?>
<?php
	$lang_outcomes   = lang('outcomes_column_outcomes');
	$lang_skills     = lang('outcomes_column_skills');
	$lang_add_button = lang('outcomes_button_add');
	$lang_confirm_del= lang('outcomes_confirm_delete');
	$lang_add_course_lnk_button = lang('outcomes_course_lnk_button_add');
	$lang_title_course_lnk = lang('outcomes_course_lnk_head');

	$lang_alt_add    = lang('outcomes_alt_add');
	$lang_alt_del	 = lang('outcomes_alt_del');

	$last_outcomes	 = '';

	$add_link = base_url() . $edit_link  ;
	$del_link = base_url() . $delete_link;

	$add_img  = osa_imagepath() . 'edit.gif';
	$del_img  = osa_imagepath() . 'x.gif';

	$class_div 	     = 'outcomes_skills_normal';
	$class_bg        = '';
	$length          = 0;
	$outcomes_line   = 0;
	//$skils_line      = 0;

?>

<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);?>">
<div class="target_body">

<div class="target_title"><?php echo lang('outcomes_skills'); ?> - <?php echo $coursename; ?></div>
<?php
	if (isset($show_close_btn) && $show_close_btn){
?>
		<div align="right">
		<input type="button" value="<?php echo lang('outcomes_course_lnk_button_close'); ?>" id="B1" <?php osa_btn();?>
		           onClick="closeDhtmlWindow('outcomes_form');" />
		</div>
<?php
	}
?>

</div>
<?php if ( $isedit ) { ?>
<div class="outcomes_skills_button_add" >
<input type="button" value="<?php echo $lang_add_button; ?>" id="B1" <?php osa_btn();?>
	onClick="ajaxPostform('page_content', '<?php echo base_url().$edit_link.$courseid; ?>', 'form_outcomes_skills', false); return false;" />
<?php if ( isset($btn_no_course_lt) && $btn_no_course_lt == FALSE ) {?>
<input name="btncourse_lnk" type="button" value="<?php echo $lang_add_course_lnk_button; ?>"
	onclick="newDhtmlWindow('<?php echo base_url()."course/outcomes/couse_lnk/"?>'+ '<?php echo $courseid;?>',
				'<?php echo $lang_title_course_lnk;?>','600','500','course_input');" <?php osa_btn();?> />
<br />
<?php
if (isset($course_lnk) && is_array($course_lnk)){
?>
	<br />
	<div class="course_lnk_link_title"><?php echo lang('outcomes_course_lnk_title_link'); ?>:</div>
<?php
	foreach ($course_lnk as $row){
?>
		<a id="<?php echo $row->lt_courseid; ?>" href="<?php echo base_url().'course/outcomes/popup/'.$row->lt_courseid; ?>"
			onClick="newDhtmlWindow('<?php echo base_url()."course/outcomes/popup/"?>'+ '<?php echo $row->lt_courseid;?>',
       		'<?php echo lang('outcomes_course_lnk_title_link');?>','1000','750','outcomes_form');return false;">
       		<span class="course_lnk_link"><?php echo $row->coursename; ?></span>
		</a>
		<br />
<?php
	} //foreach
?>
	<br />
<?php
} // (isset($course_lnk) && is_array($course_lnk))
} // ( $btn_no_course_lt )
?>
</div>

<?php }   ?>
<?php if ( (isset($nodatamsg) && $nodatamsg != '') && ( !isset($course_lnk) || $course_lnk === FALSE)) {
	echo "<div class='outcomes_skills_button_add'>";
	echo "<br /><div class='target_nodatamsg'>$nodatamsg</div></div>";
	echo "<div/>";
	//return;
} ?>
<?php
	if (isset($outcomes) && is_array($outcomes) ) {
	    $button_sort   = '';
	    $coursename = '';
	    $url_id = '';
		$divid = osa_value($template, '_body_divid', FALSE);
		$refresh_url = base_url() . "course/outcomes/edit/{$courseid}";
		$button_none = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_NONE);
		foreach ($outcomes as $outcomeid => $skills) {

			$count_data = count($skills);
			if ($last_outcomes != $outcomeid) {
	 		 	$last_outcomes  = $outcomeid;

	 		 	$url_id		= $courseid.'/'.$outcomeid;
	 		 	$edit_url 	= base_url() . 'course/outcomes/edit/' . $courseid;
				$add_url 	= $add_link.$url_id;
				$add_click  = "onClick=\"ajaxPostform('page_content', '$add_url', 'form_outcomes_skills'); return false;\"";
				$add_html   = "<a href='$add_url' $add_click><img src='$add_img' class='outcomes_button_image' title='Edit' /></a>" ;
				$outcomes   = htmlspecialchars($skills[0]);

				echo "<table class='unit_outcomes_table' cellspacing='0px;' >";
				echo "<tr><td valign='top' width='3%'><div class='outcomes_skills_header'>$lang_outcomes:</div></td>";
				echo "<td width='80%'><div >$outcomes</div></td>";
				echo "<td width='10%'>&nbsp;</td>";
				if ( $isedit ) {
					echo "<td width='2%'><div class='outcomes_skills_img1'>". $add_html ."</div></td>";
				}
			 	echo "</tr>";
			 	echo "</table>";
				$outcomes_line += 1;
			}
			$last_skillid = '';
			$sort_skills = & $skills[1];
			//We need to sort each skill segment separately
			osa_array_natsort($sort_skills, Cms_btnsort::INDEX_SORTKEY);
			$skills_count = count($sort_skills);
			$tmp_counter = 0;
			foreach ($sort_skills as $row) {
				$button_sort   = '';
				if ( $skills_count > 1 ) {
					$button_down = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_DOWN,
			 							$divid, $row, $sort_type, $refresh_url);
			 		$button_up = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_UP,
			 							$divid, $row, $sort_type, $refresh_url);
					if ( $tmp_counter == 0 ) {
						$button_sort = "{$button_none}&nbsp;&nbsp;{$button_down}";
					}
					elseif ( $tmp_counter == $skills_count-1) {
						$button_sort = "{$button_up}&nbsp;&nbsp;{$button_none}";
					}
					else {
						$button_sort = "{$button_up}&nbsp;&nbsp;{$button_down}";
					}
			 	}

				$del_url 	 = $del_link.$url_id.'/'.$row->skillsid;
				$del_click   = "onClick=\"return delTarget('$del_url','page_content','$lang_confirm_del');\"";
				$del_html    = "<a href='$del_url' $del_click><img src='$del_img' class='outcomes_button_image' title='Delete' /></a>" ;

				echo "<table class='unit_skills_table' cellspacing='0px;' >";
				if ($class_bg != '_none')
					$class_bg  = '_none';
				else
					$class_bg  = '_color';

				if ($row->skills != '') {
					$skills = htmlspecialchars($row->skills);
					echo "<tr >";

				 	echo "<td width='80%' class='outcomes_skills_bg1$class_bg'><div class='outcomes_skills_normal'>$skills</div></td>";
					//echo "<td><div class=\"target_delete\"><nobr>&nbsp;&nbsp;&nbsp; $del_html &nbsp;</nobr></div></td>";
					echo "<td width='10%' class='outcomes_skills_bg2$class_bg'><nobr>". $button_sort ." &nbsp; </nobr></td>";

					if ( $isedit ) {

						echo "<td width='10%' class='outcomes_skills_bg2$class_bg'><div class='outcomes_skills_img2'>".$del_html."</div></td>";
					}
				 	echo "</tr>";
				}
				echo "</table>";
				$tmp_counter++;
				//$skils_line += 1;
			}
		}
	}
	//if ($outcomes_line > 1)
	echo "<table  class='unit_outcomes_table' cellspacing='0px;' ><tr><td></td></tr></table>";

	//if ($outcomes_line + $skils_line > $max_rows) {
		if ( $isedit ) {
?>
		<div class="outcomes_skills_button_add" >
		<input type="button" value="<?php echo $lang_add_button; ?>" id="B1" <?php osa_btn();?>
			onClick="ajaxPostform('page_content','<?php
				echo base_url() . "{$edit_link}{$courseid}"?>','form_outcomes_skills', false); return false;" />
		</div>
<?php
		}
	//}
?>

<?php
	if (isset($show_close_btn) && $show_close_btn){
?>
		<div class="target_body" align="right">
		<input type="button" value="<?php echo lang('outcomes_course_lnk_button_close'); ?>" id="B1" <?php osa_btn();?>
		           onClick="closeDhtmlWindow('outcomes_form');" />
		</div>
<?php
	}
?>

</form>