<?php
 	/**
 * unit_copy_view.php - Unit Copy
 *
 * @author $Author: dtong $
 * @version $Id: unit_copy_view.php,v 1.11 2011/04/27 05:46:26 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

$imgadd     =  osa_imagepath() . 'forward.gif';
$imgdelete	=  osa_imagepath() . 'deletes.gif';
$imgdis     =  osa_imagepath() . 'dis_right.gif';

//$img_add   	= "<img src='$imgadd'    title='" . lang('unit_copy_addunit') . "'     border='0' />";
$img_del  	= "<img src='$imgdelete' title='" . lang('unit_copy_deleteunit') . "'  border='0' />";
$img_dis  	= "<img src='$imgdis'    title='" . lang('unit_copy_selectreminder') . "' border='0' />";

$href_save 	= base_url()."unit/unit/copy_save/$courseid/";
$href_add 	= base_url().'unit/copy/addunit/';
$href_del 	= base_url().'unit/copy/delunit/';
$href_reset = base_url().'unit/copy/refresh/'.$courseoldid;

$href_select  = base_url()."unit/unit/copy_index/$courseid/";
$href_refresh = base_url()."unit/unit/copy_refresh/$courseid/";
$formname = 'unitcopy_form';
?>
<form method="POST" name="<?php echo $formname; ?>" >
<div class="unitcopy_course_title" >
	<?php echo lang('unit_copy_titletext') . $courseoldname;  ?>
</div>
<input type="hidden"  value='<?php echo $unit_select;?>' name='txt_unitids' />
<center>
<div id='dhtmlwin_resource'>
<table width="96%" border="0">
<tr><td class="unitcopy_course_sourse"  valign="top" >
	<div class="unitcopy_sourse">
		<span class="user_course_title"><?php echo lang('unit_copy_select_course'); ?></span>
		<?php
		$href_course = $href_refresh;
		$button  = "change_button('img_button', '$imgdis', 'Disable');return false; ";
		$select  = "ajaxPostform('page_content','$href_course', '$formname', false);return false;";
		$jscript = "onChange=\"$select $button \"";
		if (isset($course) && $course!=FALSE && is_array($course)) {
			echo form_dropdown('courseid', $course, $from_courseid,"size='18' style='width:300px'\" $jscript " );
		}
		?>
	</div>
	<div style="margin-top:10px;"></div>
 	<div class="unitcopy_sourse">
		<span class="user_course_title"><?php echo lang('unit_copy_select_unit'); ?></span>
		<?php
			if (isset($unit)==FALSE || is_array($unit)==FALSE )
				$unit = array();
			$fieldname  = 'unitids[]';
			$button  = "change_button('img_button', '$imgadd', '" . lang('unit_copy_addunit') . "','$href_select','$formname');return false; ";
			$jscript = "onChange=\"$button \"";
			echo form_dropdown($fieldname, $unit,'',"size='10' style='width:300px' multiple='multiple'\" $jscript ");
		?>
	</div>
</td>
<td class="unitcopy_unit_sourse" valign="middle" align="center">
<?php
	$href_add = $href_add.$courseid;
	echo "<div style='margin-top:35px' id='img_button'>$img_dis</div>";
?>
</td>
<td class="unitcopy_unit_result" valign="middle" >
	<?php
	if (isset($unit_select)==FALSE || $unit_select == FALSE || $unit_select == '') {
		$unit_select = 0;
		$units 	     = '&nbsp;';
		$temp->id    = 0;
		$temp->course= '&nbsp;';
		$temp->type  = '&nbsp;';
		$temp->title = lang('unit_copy_emptylist_msg');
		$units_title = array($temp);
		$img_del 	 = '';
	}
		$units = explode(',',$unit_select);?>
		<div class="user_course_title" style="margin-bottom:15px;margin-left:15px"><?php echo lang('unit_copy_selectlist_title');?></div>
		<table class="unitcopy_table" style="width:100%;margin-right: auto; border:solid 1px;" >
		<tr>
		<td class="user_course_title" style="text-align: center;width:40%"><?php echo lang('unit_copy_col_course'); ?></td>
		<td class="user_course_title" style="text-align: center;width:60%"><?php echo lang('unit_copy_col_unit'); ?></td>
		</tr>
	<?php
		$class = 'table_body_row';
		$none  = false;
		$flag_undo = true;

		foreach ( $units as $row ) {
			$href_del = "{$href_select}{$from_courseid}/{$flag_undo}/{$row}";
			$onclick= "onclick=\"ajaxPostform('page_content','$href_del', '$formname', false);  return false;\"";
	 ?>
		<tr>
		<td class="<?php echo $class; ?>" width="40%"  ><?php echo $units_title[$row]->course; ?></td>
		<td class="<?php echo $class; ?>" width="50%" ><?php echo $units_title[$row]->title; ?></td>
		<td class="<?php echo $class; ?>" width="5%"  align="center"><a href='#' <?php echo $onclick; ?> ><?php echo $img_del; ?></a></td>
		</tr>
	<?php
			if ($none == false) {
				$none = true;
				$class = 'course_grade_table_body_row_none';
			} else {
				$none = false;
				$class = 'table_body_row';
			}
		}
   ?>
	</table>
	<div style="margin-bottom:15px;">&nbsp;</div>
</td>
</tr>
</table>
<br />
<div><?php echo lang('unit_copy_note');?></div>
<br />
<input type="button" value="<?php echo lang('unit_copy_button_save'); ?>"  <?php osa_btn()?>
<?php
	//$onclick= "onclick=\"ajaxPostform('page_content','$href_save', '$formname', false); refresh_unitnode('$courseid'); return false;\"";
	$after_save = lang('unit_copy_after_save');;
	$onclick= "onclick=\"updateUnit('$formname','$href_save', '$courseid'); alert('$after_save'); return false;\"";
	//$jscript_save = "onClick=\"javascript:refresh_unitcopy('$href_save','$courseoldid'); \"";
	echo $onclick
?> />
<span style="margin-left:30px">&nbsp;</span>
<input type="button" value="<?php echo lang('unit_copy_reset'); ?>"  <?php osa_btn()?>
<?php
	$jscript_reset = "onClick=\" if (confirm('" . lang('unit_copy_reset_msg') . "')) { ajaxGetpage('page_content','$href_select', false); return false; } \"";
	echo $jscript_reset
?>  />
</div>
</center>
</form>
