<?php
/**
 * unit_add_view.php - Unit view file
 *
 * @author $Author: dtong $
 * @version $Id: unit_add_view.php,v 1.30 2011/05/20 05:55:13 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

	$div_style = 'style="visibility:hidden; "';
	$span_course_lang =  '';
	$checked1='';
	$checked2='';
	$checked3='';
	$checked4='';
	if (isset($unittype) && $unittype != '') {
		switch ($unittype) {
		case $template->TYPE_NORMAL:
			$checked1='checked="checked"';
			break;
		case $template->TYPE_META:
			$checked2='checked="checked"';
			break;
	  case $template->TYPE_INT_PARENT:
			 $checked3='checked="checked"';
			 $div_style = 'style="visibility:visible;margin:10px;"';
			 $span_course_lang = "<font color=\"red\">" . lang('unit_intcourses') . ":</font>";
			 break;
	  case $template->TYPE_UNI_PARENT:
			 $checked4='checked="checked"';
			 $div_style = 'style="visibility:visible;margin:10px;"';
			 $span_course_lang = lang('unit_unicourses') . ": ";
			 break;
	   }
	}
	else { // default
		$checked1='checked="checked"';
	}

	if ( !isset($unit) ) {
		$unit = new stdClass();
		$unit->title = '';
		$unit->description = '';
		$unit->startdate = '';
		$unit->enddate = '';
	}

	if (isset($unit_title) && $unit_title != '') {
		@$unit->title = $unit_title;
	}
	if (isset($description) && $description != '') {
		@$unit->description = $description;
	}
	if (isset($startdate) && $startdate != '') {
		@$unit->startdate = $startdate;
	}
	if (isset($enddate) && $enddate != '') {
		@$unit->enddate = $enddate;
	}
?>
<div style="margin-top:15px;margin-left:10px">
	<div style="font-size:14px;font-weight:bold;margin-bottom:15px;">
	<?php echo sprintf(lang('unit_add_title'),osa_unittype_translate($unit_template,1)); ?></div>
	<div style="font-weight:bold;margin-bottom:15px;"><?php echo $coursename; ?></div>
	<form name='form_unit' method="post">
	<input type="hidden" id="courseid"    name="courseid"    value='<?php echo $courseid ?>' />
	<input type="hidden" id="courseids"   name="courseids"   value='<?php echo $courseids ?>' />

<?php
	if ($this->config->item('cms_use_all_unit_types')==FALSE &&
		$this->config->item('cms_use_unit_meta')==FALSE &&
		$this->config->item('cms_use_unit_integrated')==FALSE &&
		$this->config->item('cms_use_unit_unified')==FALSE ) {
			echo "<input type='hidden' name='unittype' value='{$template->TYPE_NORMAL}' />";
			$div_style = 'style="visibility:hidden; display:none;"';
	} else {
		if ($this->config->item('cms_use_all_unit_types') ||
			$this->config->item('cms_use_unit_meta') ||
			$this->config->item('cms_use_unit_integrated') ||
			$this->config->item('cms_use_unit_unified') ) {

			echo lang('unit_ask_unit_type');  ?>:
			<div style="margin:3px"></div>&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="radio" name="unittype" value="<?php echo $template->TYPE_NORMAL;?>"
			onclick="JavaScript:shrinkDiv('Course_Int','12px');" <?php echo $checked1; ?> />
			<?php echo lang('unit_normal'); ?>&nbsp;&nbsp;
<?php 	} ?>

<?php 	if ($unit_template == CMS_UBD_TEMPLATE && ($this->config->item('cms_use_all_unit_types') || $this->config->item('cms_use_unit_meta'))) { ?>
       		<input type="radio" name="unittype" value="<?php echo $template->TYPE_META;?>"
       		onclick="JavaScript:shrinkDiv('Course_Int','12px');" <?php echo $checked2; ?> />
       		<?php echo lang('unit_metaunit'); ?>&nbsp;&nbsp;
<?php 	} ?>

<?php 	if ($unit_template == CMS_UBD_TEMPLATE && ($this->config->item('cms_use_all_unit_types') || $this->config->item('cms_use_unit_integrated'))) { ?>
       		<input type="radio" name="unittype" value="<?php echo $template->TYPE_INT_PARENT;?>"
       		onclick="JavaScript:expandDiv('Course_Int','10px'); writeSpan('course_lang',
       		'<?php echo "<font color=red>" . lang('unit_intcourses') . ":</font>"; ?>'); " <?php echo $checked3; ?> />
       		<?php echo lang('unit_integratedunit'); ?>&nbsp;&nbsp;
<?php 	} ?>

<?php 	if ( $this->config->item('cms_use_all_unit_types') || $this->config->item('cms_use_unit_unified') ) { ?>
       		<input type="radio" name="unittype" value="<?php echo $template->TYPE_UNI_PARENT;?>"
       		onclick="JavaScript:expandDiv('Course_Int','10px'); writeSpan('course_lang',
       		'<?php echo lang('unit_unicourses') . ": "; ?>'); " <?php echo $checked4; ?> />
			<?php echo lang('unit_unifiedunit');?>
<?php	}
	}
?>

<?php
	//update course button
	$sel_url = base_url()."unit/unit/selcourse_add/FALSE/".$unit_template;
	$title = lang('unit_button_add_course');
	$width = 700;
	$height = 700;
	$divid = 'changeunit_div';
	$formname = 'form_unit';
	$ajaxPostWindow = "JavaScript:ajaxPostWindow ('$sel_url','$title',$width,$height,'$divid','$formname');";
?>
       <div id="Course_Int" <?php echo $div_style; ?> ><span id="course_lang"><?php echo $span_course_lang; ?></span>
       <input name="unitbutton" type="button" value="<?php echo lang('unit_button_add_course');?>"
	       	       onclick="<?php echo $ajaxPostWindow; ?>" <?php osa_btn()?>
	               style="margin-left:10px;vertical-align:middle;" />

       <div id='coursenames_div' style="display:inline;vertical-align:middle;"  >
       <?php if (isset($sel_coursenames) && count($sel_coursenames) > 0) {
				   echo '<div style="width:550px;margin-left:20px;margin:10px">';
				   $sep='';
				   foreach ($sel_coursenames as $coursenames) {
				   	echo $sep . "<nobr>$coursenames</nobr><br />";
				   	//$sep = ', ';
				   }
				   echo '</div>';
       		} //if
       ?>
       </div>
       <?php
       		//if ( !isset($units_sel) || !is_array($units_sel)) { $units_sel = array(); }
       ?>
       </div>
 <?php //} // if ( $this->config->item('cms_use_all_unit_types') )
 		// else {
 		// 	echo "<input type='hidden' name='unittype' value='{$template->TYPE_NORMAL}' />";
 		// }
 ?>
       <?php echo lang('unit_ask_title_desc'); ?>:<br /><br />

       <table border="0" cellspacing="0" width="600" cellpadding="3">
          <tr>
            <td width="147" valign="top" class="required"><?php echo lang('unit_title');?>:</td>
            <td width="445" valign="top"><input type="text" name="title" id="title" size="81" value="<?php echo @$unit->title;?>" /></td>
          </tr>
          <tr>
            <td width="147" valign="top" class="required"><?php echo lang('unit_description');?>:</td>
            <td width="445" valign="top"><textarea rows="6" name="description" id="description" cols="80"><?php
            	echo @$unit->description;
            ?></textarea></td>
          </tr>
          <tr>
            <td width="147" valign="top" class="required"><?php echo lang('unit_startdate');?></td>
            <td width="445" valign="top">
            	<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" class="required"><?php echo lang('unit_enddate');?></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_startdate')?>" /> <?php echo lang('unit_use_calendar_msg');?>
            </td>
          </tr>
          <tr>
            <td width="592" colspan="2"><img border="0" src="<?php echo osa_imagepath(); ?>10x10.gif"></td>
          </tr>

          <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/add/' . $courseid . "/$unit_template" ?>');" />
             	<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/addunit/<?php echo $unit_template?>','<?php echo $courseid?>'); return false;" /></td>
          </tr>
        </table>
        </form>
</div>
<?php if (isset($unitbody)) echo $unitbody;?>