<?php
require_javascript("og/modules/addTaskForm.js");
$task_list = $object;
$genid = gen_id();
$description = "";

$tz_offset = Timezones::getTimezoneOffsetToApply($task_list);
$tz_offset = $tz_offset/3600;

?>
<script>
  if(App.modules.addTaskForm) {
    App.modules.addTaskForm.task_lists[<?php echo $task_list->getId() ?>] = {
      id               : <?php echo $task_list->getId() ?>,
	  can_add_task     : <?php echo ($task_list->canAddSubTask(logged_user()) && !$task_list->isTrashed()) ? 'true' : 'false' ?>,
      add_task_link_id : 'addTaskForm<?php echo $task_list->getId() ?>ShowLink',
      task_form_id     : 'addTaskForm<?php echo $task_list->getId() ?>',
      text_id          : 'addTaskText<?php echo $task_list->getId() ?>',
      assign_to_id     : 'addTaskAssignTo<?php echo $task_list->getId() ?>',
      submit_id        : 'addTaskSubmit<?php echo $task_list->getId() ?>'
    };
  } // if
</script>

		
<?php if ($task_list->getObjectSubtype() > 0) {
		$subType = ProjectCoTypes::instance()->findById($task_list->getObjectSubtype());
		if ($subType instanceOf ProjectCoType ) {
			echo "<div><span class='bold'>" . lang('object type') . ":</span> " . $subType->getName() . "</div>";
		}
	  }
?>



<?php if($task_list->getText()) { ?>
  
	<div class="wysiwyg-description"><?php
		if($task_list->getTypeContent() == "text"){
			echo escape_html_whitespace(convert_to_links(clean($task_list->getText())));
		}else{
			echo convert_to_links(purify_html(nl2br($task_list->getText())));
		}
	?></div>
  
<?php } // if ?>

<?php
/**
 * This section displays the most important information of the task. 
 */
?>
<?php 
if($task_list->getAssignedTo()){
	if (logged_user()->getId() == $task_list->getAssignedTo()->getId()){
		$username = lang('me');
	}else{
		$username = clean($task_list->getAssignedToName());
	}
 	$description .= '<span style="font-weight:bold">' . lang("assigned to") . ': </span><a class=\'internalLink\' href=\''
	. $task_list->getAssignedTo()->getCardUserUrl() . '\' title=\'' . escape_single_quotes(lang('user card of', clean($task_list->getAssignedToName()))). '\'>'
	. $username . '</a>';
} 
 ?>
<div>
	<?php if ($description != "" || $priority != "") { ?>
	<div style="width:50%; float: left;">
		<div class="member-path-dim-block" style="font-weight:bold;"><?php echo $description;?></div>
		<div class="member-path-dim-block" style="font-weight:bold;"><?php if (isset($priority)){echo $priority;} ?></div>
	</div>
	<?php } ?>
	
	<?php if (($task_list->getDueDate() instanceof DateTimeValue) || ($task_list->getStartDate() instanceof DateTimeValue) || isset($status)) { ?>
	<div style="width:50%; float: left;">
	<?php if ($task_list->getDueDate() instanceof DateTimeValue) {
	 		if ($task_list->getDueDate()->getYear() > DateTimeValueLib::now()->getYear()) { ?> 
			<div class="member-path-dim-block dueDate"><span class="bold"><?php echo lang('due date') ?>: </span><?php echo format_datetime($task_list->getDueDate(), null, $tz_offset) ?></div>
	  <?php } else { ?> 
	 		<div class="member-path-dim-block dueDate"><span class="bold"><?php echo lang('due date') ?>: </span><?php
	 		
	 		$tm = null;
	 		if(!$task_list->getUseDueTime()){
	 			$tm = 0;
	 		}	 		
	 	  	echo format_descriptive_date($task_list->getDueDate(),$tm);
	 	  	if ($task_list->getUseDueTime()) {
	 	  		echo " ".lang('by time')." " . format_time($task_list->getDueDate(), user_config_option('time_format_use_24') ? 'G:i' : 'g:i A', $tz_offset);
	 	  	}
	 	  	
	 	  ?></div>
	  <?php }
		} ?>
		
	<?php if ($task_list->getStartDate() instanceof DateTimeValue) {
	 		if ($task_list->getStartDate()->getYear() > DateTimeValueLib::now()->getYear()) { ?> 
			<div class="member-path-dim-block startDate"><span class="bold"><?php echo lang('start date') ?>: </span><?php echo format_datetime($task_list->getStartDate(), null, 0) ?></div>
	  <?php } else { ?> 
	 		<div class="member-path-dim-block startDate"><span class="bold"><?php echo lang('start date') ?>: </span><?php
	 		 
	 		$tm = null;
	 		if(!$task_list->getUseDueTime()){
	 			$tm = 0;
	 		}
	 	  	echo format_descriptive_date($task_list->getStartDate(),$tm);
	 	  	if ($task_list->getUseDueTime()) {
	 	  		echo " ".lang('by time')." " . format_time($task_list->getStartDate(), user_config_option('time_format_use_24') ? 'G:i' : 'g:i A', $tz_offset);
	 	  	}
	 	  	
	 	  ?></div>
	  <?php }
		} ?>
		 
		 <div class="member-path-dim-block" style="font-weight:bold"><?php if (isset($status)){echo $status;} ?></div>
		 <div class="member-path-dim-block" style="font-weight:bold"><?php echo lang('mark as started this task') .": "; echo ($task_list->getMarkAsStarted()) ? lang('yes') : lang('no'); ?></div>
		 <?php $null=null; Hook::fire('view_task_render_more_properties', $task_list, $null)?>
	</div>
	<?php } ?>
	
</div> 
<div class="clear"></div>





<?php if ($last_task_of_repetition instanceof ProjectTask && $last_task_of_repetition->isRepetitive()) { ?>
	<div style="font-weight:bold">
	<?php 
		echo '<br>' . lang('this task repeats'). '&nbsp;';
		if ($last_task_of_repetition->getRepeatForever()) echo lang('forever');
		else if ($last_task_of_repetition->getRepeatNum()) echo lang('n times', $last_task_of_repetition->getRepeatNum());
		else if ($last_task_of_repetition->getRepeatEnd()) echo lang('until x', format_date($last_task_of_repetition->getRepeatEnd()));
		echo ", " . lang ('every') . " ";
		if ($last_task_of_repetition->getRepeatD() > 0) echo lang('n days', $last_task_of_repetition->getRepeatD()) . ".";
		else if ($last_task_of_repetition->getRepeatM() > 0) echo lang('n months', $last_task_of_repetition->getRepeatM()) . ".";
		else if ($last_task_of_repetition->getRepeatY() > 0) echo lang('n years', $last_task_of_repetition->getRepeatY()) . ".";
	?>
	</div>
<?php }
?>
