<?php
 	/**
 * linkunit_view.php - View link unit.
 *
 * @author $Author: dtong $
 * @version $Id: linkunit_view.php,v 1.7 2011/04/05 15:26:01 dtong Exp $
 * @copyright Copyright (c) 2010, Tiller Software Co., Ltd.
*/
$href 			= osa_imagepath();
$imgdis     	= 'dis_right.gif';
$imgsave			= osa_imagepath() . 'forward.gif';
$imgclose		= 'close.gif';
$imgdelete		= 'deletes.gif';
$img_save   	= "<img src=". $href . "$imgdis  title='".lang('linkunit_disable')."' border='0' >";
$img_close   	= "<img src=". $href . "$imgclose  title='Close'        border='0' >";
$img_del  		= "<img src=". $href . "$imgdelete    title='Delete'    border='0' >";

$href_save 		= base_url().'template/linkunit/insert_linkunit/'.$extid;
$href_del 		= base_url().'template/linkunit/delete/'.$extid . '/';
$href_refresh  = base_url().'template/linkunit/select/'.$extid. '/' .$depid. '/' .$gradeid . '/';
$href_select  	= base_url().'template/linkunit/refresh/'.$extid. '/';
$href_goal = base_url().$templateid.'/'.$templateid .'/stage/0/'.CMS_ACTION_EDIT.'/'.$extid;
$refresh_goal =  "ajaxPostform('page_content', '{$href_goal}', '');";

$linkunit_col_user 	=lang('linkunit_col_user');
$linkunit_col_editor	=lang('linkunit_col_editor');
$linkunit_col_delete	=lang('linkunit_col_delete');
$linkunit_selected_unit		=lang('linkunit_selected_unit');
$linkunit_select_department=lang('linkunit_select_department');
$linkunit_select_grade		=lang('linkunit_select_grade');
$linkunit_select_unit		=lang('$bd_unit_select_unit');
$linkunit_deletemsg=lang('linkunit_deletemsg');
$massage = lang('linkunit_massage');
?>
<div id='linkunit'>
<form method="POST" name="linkunit_form" >
	<center>

			<input id='type' type='hidden' value='<?php echo $type; ?>'></input>
			<input id='department' type='hidden' value='<?php echo $depid; ?>'></input>
			<input id='grade' type='hidden' value='<?php echo $gradeid; ?>'></input>
			<div class="linkunit_title"><?php echo lang('linkunit_title_'.$type)?></div>
			<div class="linkunit_title"><?php echo $title?></div>
			<br />
			<table class="linkunit_table" border=0>
				<tr>
					<td width="40%" valign="top" >
						<div class="linkunit_head"><?php echo $linkunit_select_department; ?>
 						<?php
							if (isset($department) && is_array($department)) {
								$fieldname  = 'select_departmentid';
								//$jscript = "onChange=\"select_unit('$href_select','linkunit_form','unit_list','$massage');\" onkeyup=\"this.blur();this.focus();\"";
								$jscript = "onChange=\"select_unit('$href_select','linkunit_form','linkunit','$massage');\" onkeyup=\"this.blur();this.focus();\"";
								echo form_dropdown($fieldname, $department,$depid,$jscript);
							}
						?>
						&nbsp;&nbsp;&nbsp;
						<?php echo $linkunit_select_grade; ?>
						<?php
							if (isset($grade) && is_array($grade)) {
								$fieldname  = 'select_gradeid';
								//$jscript = "onChange=\"select_unit('$href_select','linkunit_form','unit_list','$massage');\" onkeyup=\"this.blur();this.focus();\"";
								$jscript = "onChange=\"select_unit('$href_select','linkunit_form','linkunit','$massage');\" onkeyup=\"this.blur();this.focus();\"";
								echo form_dropdown($fieldname, $grade,$gradeid, $jscript);
							}
						?>
						</div>
						<div id="unit_list"><div id="massage" class="linkunit_massage">&nbsp;</div>
						<?php
							if (isset($unit) && is_array($unit)) {
								$fieldname  = 'unitid[]';
								//$fieldname  = 'data_unit[]';
								//$button  = "change_button('img_button', '$imgsave', '" . lang('linkunit_assign') . "','','linkunit_form'); ";
								$button  = "change_button('img_button', '$imgsave', '" . lang('linkunit_assign_'.$type) . "','{$href_save}','linkunit_form','linkunit'); ";
								$jscript = "onChange=\"$button \"";
								echo form_dropdown($fieldname, $unit,'',"size='28'  multiple='multiple' style='width:450px' $jscript ");
							}
						?>
						</div>
					</td>
					<?php
						$jscript_add = "onClick=\"select_unit('$href_save','linkunit_form','linkunit','$massage');\"";
						//$jscript_add = "onClick=\"user_goal('$href_save','$href_refresh','$href_goal', 'linkunit_form','linkunit');\"";
					?>
					<td class="user_course_image"  valign="middle">
						<div id="img_add" >
							<!-- <a id="add" name="add" <?php echo $jscript_add ?> ><span id="img_button" ><?php echo $img_save ?></span></a>    -->
							<span id="img_button" ><?php echo $img_save ?></span>
						</div>
					</td>
					<td class="user_course_data"  valign=top>
						<div class="linkunit_head"><?php echo $linkunit_selected_unit; ?></div>
						<table class="linkunit_table" border=0 >
							<tr>
								<th class="user_course_table_header"><?php echo $linkunit_col_user ?></th>
								<th class="user_course_table_header"><?php echo $linkunit_col_delete ?></th>
							</tr>
							<?php
								// create row
								$swap='';
							  	if (isset($selectlistitem) && is_array($selectlistitem)) {
									foreach ($selectlistitem as $row) {
										if ($swap  == '') {
											$tr_class = "table_body_row";
											$swap = '_none';
										}
										else {
											$tr_class = "table_body_row_none";
											$swap = '';
										}
								// make link delete
								$href=$href_del.$row->groupid;
								//$jscript_del = "onClick=\"user_goal('$href','$href_refresh','$href_goal', 'linkunit_form','linkunit');\"";
								$jscript_del = "onClick=\"if(confirm('$linkunit_deletemsg')==true) { select_unit('$href','linkunit_form','linkunit','$massage'); } \"";
								$hide_unit = '';
								$class_unit_title = 'user_course_col_header_Name';
								if (isset($row->u_hidden) && $row->u_hidden !=FALSE ){
										$class_unit_title = 'linkunit_view_hide';
										$hide_unit = '<span class="linkunit_view_hide">('.lang('linkunit_hide').')</span>';
								}
							?>
							<tr class="<?php echo $tr_class; ?>">

								<td class="<?php echo $class_unit_title?>" ><?php echo $row->title ; ?>&nbsp;<?php echo $hide_unit ; ?></td>
								<td class="user_course_col_header_del" ><a <?php echo $jscript_del ?> ><?php echo $img_del ?></a></td>
							</tr>
							<?php
									} // foreach
								} // if
							?>
						</table>
						<div align="left" style="margin-top:10px">
							<input type="button" value="<?php echo lang('linkunit_button_done'); ?>" name="Done" <?php osa_btn()?>
							onClick="closeDhtmlWindow('linkunit');<?php echo $refresh_goal; ?> return false;" />
						</div>
					</td>
				</tr>
			</table>
			<table width="96%">
				<tr>
					<td>
						<div class="user_course_footer"><?php echo lang('linkunit_footer_'.$type); ?></div>
					</td>
				</tr>
			</table>

	</center>
</form>
</div>