<?php
/**
 * target_view.php - Edit learning larget page
 *
 * @author $Author: dtong $
 * @version $Id: target_view.php,v 1.36 2011/05/09 11:27:45 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
	$width = '1000';
	$height = '750';
	$url_pdf  = base_url() . 'pdf/pdfgen/index/pdf_render_url_course-target-indexsess-' .
				   $course->id. '-PHPSESSIONID/LearningTargets';
	$jscript_pdf="onClick=\"return openBrowserWindow('$url_pdf')\"";
?>
<?php
if ($closebutton!=FALSE){
?>
<table width="100%" border="0">
	<tr>
		<td align="right">
			<input type="button" value="<?php echo lang('outcomes_course_lnk_button_close'); ?>" name="close" <?php osa_btn()?>
				onClick="closeDhtmlWindow('lt_form');" />
		</td>
	</tr>
</table>
<?php
}
?>
<table width="100%" border="0">
<tr>
<td align="left">
	<input type="button" value="<?php echo lang('target_button_pdf'); ?>" name="pdf" <?php osa_btn()?>
		<?php echo $jscript_pdf;?>  />
<?php
	if ( $btn_no_course_lt==FALSE ) {
		if ( $isedit ) {
?>
	<input name="btncourse_lnk" type="button" value="<?php echo lang('target_course_lnk_button_add'); ?>"
	       onclick="newDhtmlWindow('<?php echo base_url()."course/target/couse_lnk/"?>'+ '<?php echo $course->id;?>',
	           '<?php echo lang('outcomes_course_lnk_head');?>','600','460','course_input');"
	           <?php osa_btn();?> />
	           <br />
	<div class="course_lnk_link_title"><?php echo lang('target_course_lnk_title_link'); ?>:</div>
	<?php
			if ( is_array($course_lnk) ) {
		foreach ($course_lnk as $row){
	?>
	<div>
	<a id="<?php echo $row->lt_courseid; ?>" href="<?php echo base_url().'course/target/index_hist/'.$row->lt_courseid; ?>"
	onClick="newDhtmlWindow('<?php echo base_url()."course/target/index_hist/"?>'+ '<?php echo $row->lt_courseid;?>',
	       '<?php echo lang('outcomes_course_lnk_title_link');?>','1000','750','lt_form');return false;">
	       <span class="course_lnk_link"><?php echo $row->coursename; ?></span>
	</a>
	</div>
	<?php
	} //foreach
	?>
	<?php
			} //if (is_array($course_lnk))
			else {
				echo lang('target_course_lnk_course_none');
			}
		} //if ( $isedit )
	} //if ($btn_no_course_lt==FALSE)
	?>
</td>
</tr>
</table>
<div class="target_body">
<div class="target_title"><?php
	if ( $isedit ) {
		if ( !($tmp = osa_value($template, '_title_edit', FALSE)) ) {
			$tmp = lang('target_edit_page_title');
		}
		echo $tmp;
	}
	else {
		if ( !($tmp = osa_value($template, '_title_read', FALSE)) ) {
			$tmp = lang('target_read_page_title');
		}
		echo $tmp;
	}
	if ( !($course_title = osa_value($template, '_course', FALSE)) ) {
		$course_title = lang('target_course');
	}
?></div>
<div class="target_title"><?php echo "{$course_title}: ";
	osa_value($course, 'name')?></div><div style="padding-bottom:8px"></div>
<?php
	if ( $db_struct == FALSE ) {
		echo '<br /><br /><br /><div class="target_nodatamsg">';
		if ( !($tmp = osa_value($template, '_nodatamsg', FALSE)) ) {
			$tmp = lang('target_no_data_msg');
		}
		echo "{$tmp}</div>";
	}
	else {
?>
<?php
//This is the array containing the K ans S symbol based on index 1 or 2
	$selectvalue = osa_value($template, '_select1', FALSE);

	if ( !($strand_title=osa_value($template,'_strand',FALSE))) {
		$strand_title = lang('target_strand');
	}
	if ( !($standard_title=osa_value($template,'_standard',FALSE))) {
		$standard_title = lang('target_standard');
	}
	if ( !($benchmark_title=osa_value($template,'_benchmark',FALSE))) {
		$benchmark_title = lang('target_benchmark');
	}

	$edit_btn_alttext = '';
	$image_edit = '';
	$wintitle = osa_value($template, '_win_title', FALSE);
	$winwidth = osa_value($template, '_win_width', FALSE);
	$winheight = osa_value($template, '_win_height', FALSE);
	$winid = osa_value($template, '_win_id', FALSE);
	$divid = osa_value($template, '_body_divid', FALSE);
	$image_path = osa_imagepath();
	//$sortnone= "<img src=\"{$image_path}none.gif\" border=\"0\" />";
	$image_delete = osa_value($template, '_image_delete', FALSE);

	$button_none = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_NONE);
	$refresh_url = base_url() . "course/target/edit/{$course->id}/";

	if ( $isedit ) {
		if ( !($edit_btn_alttext=osa_value($template, '_image_edit_alttext', FALSE)) ) {
			$edit_btn_alttext = 'title="' . lang('target_edit_btn_alttext') . '"';
		}
		else {
			$edit_btn_alttext = 'title="' . $edit_btn_alttext . '"';
		}
		if ( !($image_edit=osa_value($template, '_image_edit', FALSE)) ) {
			$image_edit = $image_path . 'edit.gif';
		}
		else {
			$image_edit = $image_path . $image_edit;
		}
		if ( !$wintitle ) {
			$wintitle = lang('target_edit_win_title');
		}
		if ( !$winwidth ) {
			$winwidth = 900;
		}
		if ( !$winheight ) {
			$winheight = 700;
		}
		if ( !$winid ) {
			$winid = 'edit_lt';
		}
		if ( !$divid ) {
			$divid = 'page_content';
		}
		if ( !$image_delete ) {
			$image_delete = 'x.gif';
		}

		$alt_title_tmp = osa_value($template, '_image_delete_alttext', FALSE);
		if ( $alt_title_tmp ) {
			$alt_title_tmp = "title=\"$alt_title_tmp\"";
		}
		else {
			$alt_title_tmp = 'title="' . lang('target_delete_alttext') . '"';
		}
		$image_delete = "<img {$alt_title_tmp} src=\"" . osa_imagepath() . $image_delete . '" border="0" />';
/*
		$alt_title_tmp = 'title="' . lang('target_move_up_alttext') . '"';
		$image_sortup = "<img {$alt_title_tmp} src=\"{$image_path}moveup.gif\" border=\"0\" />";
		$alt_title_tmp = 'title="' . lang('target_move_down_alttext') . '"';
		$image_sortdown = "<img {$alt_title_tmp} src=\"{$image_path}movedown.gif\" border=\"0\" />";
*/
		$msg_delete = osa_value($template, '_delete_msg', FALSE);
		if ( !$msg_delete ) {
			$msg_delete = lang('target_delete_confirm_msg');
		}
	}
	foreach($db_struct as $strandid => $strand) {
		echo "<div class=\"target_strand\">{$strand_title}: {$strand[0]}</div>";
		foreach($strand as $stabdardid => $standard) {
			if ($stabdardid == 0) {
				continue;
			}
			if (!$this->config->item('cms_hide_benchmarks')){
				echo "<div class=\"target_standard\">{$standard_title}: {$standard[0]}</div>";
			}
			$standard_array = array();
			foreach($standard as $benchmarkid => $benchmark) {
				if ($benchmarkid == 0) continue;
				$link='';
				$tdwidth = 0;
				//Create the edit link if edit mode
				if ( $isedit ) {
					$image = osa_value($template, '_image_edit', FALSE);
					$image = "<img {$edit_btn_alttext} src=\"{$image_edit}\" border=\"0\" />";
					$url = base_url() . 'course/target/addt/' . $course->id . '/' . $benchmarkid . '/' . osa_value($template, '_typeid', FALSE);
					$jscript = "onClick=\"newDhtmlWindowTop('$url', '$wintitle', '$winwidth', '$winheight', '$winid');return false;\"";
					$link = "<a href=\"$url\" $jscript>$image</a>";
					$tdwidth = 50;
				}
				// Case Hidden benchmark
				if (!$this->config->item('cms_hide_benchmarks')){
					echo "<table  cellpadding='0' cellspacing='0' width='100%'><tr>".
					"<td class='target_bench' >{$benchmark_title}: {$benchmark[0]} </td>".
					"<td width='$tdwidth' valign='middle' align='right'>$link</td></tr></table>";
				}
				else{
					if (!in_array($standard[0],$standard_array)){
						$standard_array[] = $standard[0];
						echo "<table  cellpadding='0' cellspacing='0' width='100%'><tr>".
				  		"<td class='target_standard'>" .osa_value($template,'_standard',FALSE) . ": {$standard[0]} </td>";
						echo "<td width='$tdwidth' valign='middle' align='right'>$link</td></tr></table>";
					}
				}
				$colorflag = FALSE;
				$button_id  = '';
				$count_data = count($benchmark);
				if ($count_data > 2) {
					$button_lastid = $benchmark[$count_data-1]->id;
				}
				$button_sort = '';
				foreach($benchmark as $loop_index => $target) {
					if ($loop_index == 0 || is_null($target->data) ) continue;
					$delete = '';
					$kssymbol = '';
					if ( $isedit ) {
						$url = base_url() . 'course/target/delete/' . $target->id;
						$targettext = str_replace("'","\\'",$target->data);

						$msg = sprintf($msg_delete, $targettext);
						$jscript = "onClick=\"delTarget('$url', '$divid', '$msg'); return false;\"";
						$delete = "<a $jscript href=\"$url\">$image_delete</a>";
/*
						$url_sortup = base_url() . "course/target/sort/$course->id/$target->id/$lt_sort_type/$mode_up";
						$url_sortdown = base_url() . "course/target/sort/$course->id/$target->id/$lt_sort_type/$mode_down";
						$jscript_up   = "onClick=\"sortUnitItem('$url_sortup', '', '$divid'); return false;\"";
						$jscript_down = "onClick=\"sortUnitItem('$url_sortdown', '', '$divid'); return false;\"";

						$sortup = "<a $jscript_up href=\"$url_sortup\">$image_sortup</a>";
						$sortdown = "<a $jscript_down href=\"$url_sortdown\">$image_sortdown</a>";
						$button_sort = '';
						if ($count_data > 2) {
							if ($loop_index == 1)
								$button_sort = $sortnone.' '.$sortdown;
							elseif ($button_lastid != null && $target->id == $button_lastid)
								$button_sort = $sortup .' '.$sortnone;
							else
								$button_sort = $sortup .' '.$sortdown;
						} */
						$button_sort = '';
						if ($count_data > 2) {
							$button_down = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_DOWN,
				 							$divid, $target, $sort_type, $refresh_url);
				 			$button_up = $this->cms_btnsort->get_button(Cms_btnsort::BUTTON_UP,
				 							$divid, $target, $sort_type, $refresh_url);
				 			if ($loop_index == 1) {
								$button_sort = $button_none . ' ' . $button_down;
				 			}
							elseif ($button_lastid != null && $target->id == $button_lastid) {
								$button_sort = $button_up . ' '. $button_none;
							}
							else {
								$button_sort = $button_up .' '.$button_down;
							}
						}

					}
					if ( !is_null($target->select1) && array_key_exists($target->select1, $selectvalue)) {
						$kssymbol = $selectvalue[$target->select1];
					}
					$class = osa_colortrack($colorflag, 'target_target1', 'target_target2');

					echo "<table cellpadding='0' cellspacing='0' width='100%'><tr class=\"$class\">".
					"<td><div class=\"target_target\">{$target->data}</div></td>".
					"<td><div class=\"target_delete\"><nobr>$kssymbol &nbsp;$button_sort &nbsp; $delete</nobr></div></td></tr></table>";
				}
					echo "<table cellpadding='0' cellspacing='0' width='100%'>" .
				   	"<tr><td height='2' bgcolor='#F0F0F0' colspan='2'></td></tr></table>";

			}
		}
	}
?>
<?php }//if ( $db_struct == FALSE ) ?>
</div>
<?php
if ($closebutton!=FALSE){
?>
<table width="100%" border="0">
	<tr>
		<td align="right">
			<input type="button" value="<?php echo lang('outcomes_course_lnk_button_close'); ?>" name="close" <?php osa_btn()?>
				onClick="closeDhtmlWindow('lt_form');" />
		</td>
	</tr>
</table>
<?php
}
?>