<?php
/**
 * unit_edit_view.php - Unit view file
 *
 * @author $Author: dtong $
 * @version $Id: unit_edit_view.php,v 1.77 2011/04/27 05:46:26 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/
	if ( isset($parentinfo) && is_object($parentinfo) ) {
		$parent_uniturl = base_url() . "unit/unit/index_paging/{$parentinfo->id}";
		$parent_unithtml = "<a class=\"cmslink\" href=\"$parent_uniturl\" onclick=\"newDhtmlWindow('$parent_uniturl','" . lang('unit_parentunit') .
						"',900,800,'unitread');return false;\">{$parentinfo->title}</a>";
		if ( isset($valid_parent_unit) && !$valid_parent_unit ) {
			$parent_unithtml = $parentinfo->title;
		}
	}
	//Set up PDF Jscript
	$url_pdf  = base_url() . 'pdf/pdfgen/index/' . 'pdf_render_' . 'urljs_unit-unit-indexsess-'.
					$unit->id . '-PHPSESSIONID/unit';
	$jscript_pdf="onClick=\"return openBrowserWindow('$url_pdf')\"";
	//Set Jscript for history
	if (isset($unit->id))
		 $href = base_url().'unit/compare/version/'.$unit->id;

	if (isset($unit->currentunitid))
		 $href .= '/' . $unit->currentunitid;
	else
		$href .= '/' . $unit->id;
	$div = 'unit_history_form';
	//$title=lang('unit_history_title');
	$title = lang('unit_compare_title');
	$click_history="onClick=\"newDhtmlWindow('$href','$title', '1000','800', '$div');return false;\"";

	//Set Jscript for ICT Lib
	$unitid = $unit->id;
	if (isset($unit->parentid))
		$unitid = $unit->parentid;

	$url_itstd = base_url().'unit/itstd/readict/';
	//Onclick ict button unit page.
	$div = 'itstandards_popup';
	$title = lang('unit_title_ict');
	$href = $url_itstd . CMS_ITSTANDARDS_TYPE .'/'. CMS_ITSTANDARDS_RESOURCE_TYPE .'/'. $unitid;
	$click_ict="onClick=\"newDhtmlWindow('$href','$title', '900', '750', '$div');return false;\"";

	//Onclick gc button unit page.
	$div = 'gc_popup';
	$title = lang('unit_title_gc');
	$href = $url_itstd . CMS_GLOBAL_CITIZEN_TYPE .'/'. CMS_GLOBAL_CITIZEN_UPLOAD_TYPE .'/'. $unitid;
	$click_gc = "onClick=\"newDhtmlWindow('$href','$title', '900', '750', '$div');return false;\"";

	//Onclick tail button unit page.
	$div = 'tail_popup';
	$title = lang('unit_title_tail');
	$href = $url_itstd . CMS_TAIL_TYPE .'/'. CMS_TAIL_UPLOAD_TYPE .'/'. $unitid;
	$click_tail = "onClick=\"newDhtmlWindow('$href','$title', '900', '750', '$div');return false;\"";

	if (isset($disable_compare_button) && $disable_compare_button )
		$disable_compare_button = ' disabled="disabled" style="color:grey" '; //firefox needs grey
	else
		$disable_compare_button = '';

	$privateres_link = base_url() . 'unit/unit/privateres/';

	if (isset($unitpage))
		echo $unitpage;
?>
<table class="unitbody"><tr><td style="margin:0px;padding:0px">
		<span style="font-weight:bold;font-size:120%;margin-right:15px"><?php echo $coursename; ?></span>
		<span style="vertical-align:middle;margin-left:50px">
			<input <?php echo $disable_compare_button ; ?> type="button" value="<?php echo lang('unit_history_btncompare');?>" <?php osa_btn();?>
					<?php echo $click_history ; ?> />

			<?php if( isset($use_button_ict) && $use_button_ict ){?>
				<input type="button" value="<?php echo lang('unit_button_ict');?>" <?php osa_btn();?><?php echo $click_ict ; ?> />
			<?php }?>

			<?php if( isset($use_button_gc) && $use_button_gc ){?>
				<input type="button" value="<?php echo lang('unit_button_gc');?>" <?php osa_btn();?><?php echo $click_gc ; ?> />
			<?php }?>

			<?php if( isset($use_button_tail) && $use_button_tail){?>
				<input type="button" value="<?php echo lang('unit_button_tail');?>" <?php osa_btn();?><?php echo $click_tail ; ?> />
			<?php }?>

			<span style="margin-left:15px">&nbsp;</span>
			<input type="button" value="<?php echo lang('unit_button_pdf'); ?>" name="pdf"
					<?php osa_btn(); echo $jscript_pdf;?> />
		<?php if (isset($show_pdf_private_resource_select) && $show_pdf_private_resource_select) { ?>
			<input type="checkbox" <?php echo $checked_privateres?>
				onClick="ajaxGetpage('','<?php echo $privateres_link?>'+this.checked,true);return true" />
			<?php echo lang('unit_no_private_resource_pdf')?>
		<?php } ?>
		</span>

<?php  if ($current_page == '' || $current_page == 1) { ?>
		<form name='form_unit' style="margin:0px" method="post" >
		<input type="hidden" id="courseid"  name="courseid"  value='<?php @osa_echo($master_courseid);?>' />
		<input type="hidden" id="courseids" name="courseids" value='<?php @osa_echo($child_courseids);?>' />
       	<input type="hidden" id="unitid"    name="unitid"    value="<?php echo $publish_id; ?>" />
        <table border="0" cellspacing="0" width="45%" cellpadding="3">
          <tr>
            <td width="147" valign="top"><nobr><?php echo lang('unit_title');?>:</nobr></td>
            <td width="445" valign="top"><input type="text" name="title" id="title" size="81" value="<?php echo @$unit->title;?>" /></td>
          </tr>
          <?php if ( isset($parent_unithtml) ) { ?>
          	<tr>
            	<td width="147" valign="top"><nobr><?php echo lang('unit_parentunit');?>:</nobr></td>
            	<td width="445" valign="top">
            		<?php echo lang('unit_fromcourse')?>: <?php echo $parentinfo->coursename;?><br />
            		<?php echo lang('unit_title') . ": $parent_unithtml";?>
            	</td>
          </tr>
          <?php } ?>
          <tr>
            <td width="147" valign="top"><nobr><?php echo lang('unit_description');?>:</nobr></td>
            <td width="445" valign="top"><textarea rows="6" name="description" id="description" cols="100"><?php
            	echo @$unit->description;
            ?></textarea></td>
          </tr>
          <?php if ($displaytype==TRUE) {
					$sel_url = base_url()."unit/unit/changetype/".$unit->id."/".$unit->courseid."/".$unit_template;
					$title = lang('unit_change_type_title');
					$width = 500;
					$height = 300;
					$divid = 'changetype_div';
					$formname = 'form_unit';
					$ajaxChangeType = "JavaScript:ajaxPostWindow('$sel_url','$title',$width,$height,'$divid');";

					$sel_url = base_url()."unit/unit/selcourse_edit/".$unit->id."/".$unit->courseid.'/'.$unit_template;
					$title = lang('unit_selectcourses');
              		$width = 620;
              		$height = 650;
          			$divid = 'changeunit_div';
					$formname = 'form_unit';
					$ajaxPostWindow = "JavaScript:ajaxPostWindow('$sel_url','$title',$width,$height,'$divid');";
            	?>
          <tr>
            <td valign="middle" width="20%"><nobr><?php echo lang('unit_type');?>:</nobr></td>
            <td valign="middle" width="70%">
            <div style="vertical-align:middle;"><?php echo $unittypename;?>
	            <?php if ( !isset($parent_unithtml ) && ($integrated_flag == TRUE || $unified_flag == TRUE) ) { ?>
	            <input name="unitbutton" type="button" value="<?php echo lang('unit_button_update_course');?>" <?php osa_btn()?>
		       	       onclick="<?php echo $ajaxPostWindow; ?>" style="margin-left:10px;vertical-align:middle;" />
				<?php } ?>
				<?php if ( !isset($parent_unithtml ) && $change_flag == TRUE ) { ?>
	            <input name="unitbutton" type="button" value="<?php echo lang('unit_change_type_button');?>"
		       	       onclick="<?php echo $ajaxChangeType; ?>" <?php osa_btn()?>
		               style="margin-left:10px;vertical-align:middle;" />
				<?php } ?>

		        <div id='editornames' style="display:none;vertical-align:middle;">
	       		</div>
			</div>
            </td>
          </tr>
          <?php } ?>

          <?php if (isset($tearchers) && $template == CMS_MYP_TEMPLATE ){?>
	          <tr>
	            <td width="147" valign="top"><nobr><?php echo lang('unit_teacher');?>:</nobr></td>
	            <td width="445" valign="top"><?php echo $tearchers;?></td>
	          </tr>
          <?php }?>
           <?php if (isset($grade_level) && $template == CMS_MYP_TEMPLATE ){?>
	          <tr>
	            <td width="147" valign="top"><nobr><?php echo lang('unit_grade_level');?>:</nobr></td>
	            <td width="445" valign="top"><?php echo $grade_level;?></td>
	          </tr>
           <?php }?>

          <tr>
            <td width="147" valign="middle"><nobr><?php echo lang('unit_startdate');?>:</nobr></td>
            <td width="445" valign="middle">
            	<input type="text" id="startdate" name="startdate" size="20" onClick="this.blur();"
            		value="<?php echo osa_date_format(@$unit->startdate);?>" />
               <input type="image" src="<?php echo osa_imagepath().'calen.gif'?>" name="startdatebutton" id="startdatebutton"
               	alt="<?php echo lang('unit_startdate')?>" />
               <?php echo lang('unit_use_calendar_msg');?>
            </td>
          </tr>
          <tr>

            <td width="147" valign="top"><nobr><?php echo lang('unit_enddate');?>:</nobr></td>
            <td width="445" valign="top">
            	<input type="text" id="enddate" name="enddate" size="20" onClick="this.blur();"
            		value="<?php echo osa_date_format(@$unit->enddate);?>" />
              <input type="image" src="<?php echo osa_imagepath().'calen.gif'?>" name="enddatebutton" id="enddatebutton"
               alt="<?php echo lang('unit_enddate')?>" /> <?php echo lang('unit_use_calendar_msg');?>
            </td>
          </tr>
        <?php if( $this->config->item('cms_notuse_hide_unit_feature')===FALSE) { ?>
        <tr>
	        <td valign="middle" width="147"><nobr><?php echo lang('unit_hidden');?>:</nobr></td>
	        <td valign="middle" width="445">
				<?php echo $hidden;?>
			  </td>
		  </tr>
		  <?php } ?>
		  <?php if (isset($unit_editor_name) && !empty($unit_editor_name) ) {?>
				<tr>
	            <td valign="middle" width="5%"><nobr><?php echo lang('unit_uniteditor_name');?>:</nobr></td>
	            <td valign="middle" width="93%"><div style="float:left;margin-top:5px"><b><?php echo $unit_editor_name?></b></div>
	            	<?php
	            		if ( isset($show_finishediting_button) && $show_finishediting_button ) { ?>
	            			<div style="float:left;margin:0px;padding:0px;margin-left:7px">
	            			<input type=button value="<?php echo lang('unit_btn_unlock')?>" <?php osa_btn();?>
             					onClick="updateDivConfirm('page_content', '<?php echo base_url() .
	            					'unit/unit/unlock/' . $unit->id ?>', '<?php echo lang('unit_confirm_unlock')?>');
	            					refresh_unitnode('<?php echo $unit->courseid; ?>');return false" />
             			   </div>
	            	<?php } ?>
	            </td>
         	 </tr>
			<?php } ?>

			<?php if (isset($timelimit_msg) && !empty($timelimit_msg) ) {?>
				<tr>
	            <td valign="top" width="5%"><nobr><?php echo lang('unit_timelimit_title');?>:</nobr></td>
	            <td valign="top" width="93%">
	            	<span style="font-size:90%"><?php echo $timelimit_msg?></span>
	            </td>
         	 </tr>
			<?php } ?>

          <tr>
             <td width="147">&nbsp;</td>
             <td><span style="margin-right:100px">&nbsp;</span>
              <input type=button value="<?php echo lang('unit_cancel')?>" <?php osa_btn();?>
             	onClick="return cancelInput('page_content', '<?php echo base_url() . 'unit/unit/canceledit/' . $unit->id ?>');" />
             	<span style="margin-left:30px"></span>
               <input type="button" value="<?php echo lang('unit_save');?>" id="B1" <?php osa_btn();?>
              	 onClick="updateUnit('form_unit','<?php echo base_url()?>/unit/unit/update','<?php echo $unit->courseid;?>'); return false;" /></td>
          </tr>
        </table>
        </form>
<?php } ?>
<?php if (isset($unitbody)) echo $unitbody;?>
<center>
<div style="padding:0px;margin:0px;padding-top:15px"><nobr>
	<span style="vertical-align: middle;">
			<input name="editmodebutton" type="button" value="<?php echo lang('unit_undoeditingunit');?>" <?php osa_btn();?>
				onClick="undoUnitEdit('<?php echo base_url()?>unit/unit/undo/<?php @osa_echo($unit->id); ?>',
							'<?php @osa_echo($unit->courseid); ?>', '<?php echo lang('unit_undoconfirmmsg');?>');return false;" />
	</span>

	<?php
	if ( isset($distribute) && $distribute==TRUE ) {
	$multi_courseids = $unit->courseid.' '.$child_courseids;
	//echo $multi_courseids;
	?>
	<span style="vertical-align: middle; margin-left:50px;">
			<input name="editmodebutton" type="button" value="<?php echo lang('unit_savedistribute');?>" <?php osa_btn();?>
				onClick="confirmUnits('<?php echo base_url()?>unit/unit/distribute/<?php @osa_echo($unit->id); ?>',
							'<?php echo $multi_courseids; ?>','<?php echo lang('unit_distributemsg');?>');return false;" />
	</span>
	<?php
		echo '<div style="margin-top:10px;font-size:10px">'.lang('unit_int_stage1only').'</div>';
		} else { //echo "</nobr>"; }
	?>
	<span style="vertical-align: middle; margin-left:50px;">
			<input name="editmodebutton" type="button" value="<?php echo lang('unit_saveconfirm');?>" <?php osa_btn();?>
				onClick="confirmUnit('<?php echo base_url()?>unit/unit/confirm/<?php @osa_echo($unit->id); ?>',
							'<?php @osa_echo($unit->courseid); ?>','<?php echo lang('unit_confirmmsg');?>');return false;" />
	</span>
	<?php
		}
	?>
	</nobr>
</div>
<?php
	if (isset($unitpage))
		echo $unitpage;
?>
</center>
</td></tr></table>