<style>
    .w98p {
  width: 100%;
  resize: vertical;
}
</style>
<?php echo $this->Html->script('site_js/common')?>
<?php 
//pr($ses_datainfo[0]['Courserole']['role']);
//pr($this->params);die();
if(empty($this->params['pass'][2])){
	//$blocktitle = 'Discussion';
	$blocktitle = 'Assignment - Discussion';
	
}else{
	$blocktitle = 'Assignment - Discussion - Feedback';
}

?>
<div class="blocktitle"><?php echo $blocktitle;?></div>
<div class="tar borb">
	<?php echo $this->Html->link('Back',array('controller'=>'assignmentfeedbacks','action'=>'add',$this->params['pass'][1]),array('class'=>'btn btn-mini'))?>
</div>
<br/>
<div class="w97p pdl10">
<?php 
//pr($datas);die();
//if($ses_datainfo[0]['Courserole']['role'] != array_search('Teacher',$course_user_role)){

//hide this when redirected from open button of action as a teacher
	if(empty($this->params['pass'][2])){
	?>
	<div>
		<?php 
		if($ses_datainfo[0]['Courserole']['role'] != array_search('Teacher',$course_user_role)){
			echo "Comment(s) posted here will be sent as response(s) to this assignment.";
			echo '<div class="divline"></div>';
		}
                
		?>
		<h4><?php echo $datas[0]['Classcontent']['title']?></h4>
		<div class="fnt80"><?php echo 'By '.$datas[0]['Prof']['fname'].' '.$datas[0]['Prof']['lname'].', '.date('d-M, Y',strtotime($datas[0]['Classcontent']['created']));?></div>
		<div class="divline"></div>
		<div>
			<?php 
			$img = "img/upload/contents/medium/".$datas[0]['Classcontent']['id'].".png" ;
			if(is_file($img)){
				echo '<div class="ih300 tac borb mrb5 pdb5">'.$this->Html->image('upload/contents/medium/'.$datas[0]['Classcontent']['id'].'.png').'</div>';
			}
			?>
			<div><?php echo $datas[0]['Classcontent']['content'];?></div>
		</div>
		<?php 
		if(!empty($datas[0]['Classcontent']['ext'])):
			$file_name = 'Attachment';
			if(!empty($datas[0]['Classcontent']['filename'])){
				$file_name = $datas[0]['Classcontent']['filename'];
			}
			?>
			<div class="bort mrt5 pdt5 fnt80"><a class="cblue" href="<?php echo $this->webroot.'img/upload/contents/atched/'.$datas[0]['Classcontent']['id'].$datas[0]['Classcontent']['ext'];?>" ><?php echo $file_name;?></a> </div>
			<?php 
		endif;
		?>
	</div>
	<?php
	}
	//}
	?>
			
		
		<?php 
		if($datas[0]['Classcontent']['status'] != SAVE):
			?>
			<?php 
			//hide this when redirected from open button of action as a teacher
			if(empty($this->params['pass'][2])){
				?>
				<div class="divline2"></div>
				<div class="bold mrb10 font120">
					<div class="fl">Leave a replay</div>
					<div class="fr tar"><?php echo sizeof($comments);?> comment(s)</div>
					<div class="cl"></div>
				</div>
				<?php 
				//if($ses_datainfo[0]['Courserole']['role'] != array_search('Teacher',$course_user_role)):
					?>
					<?php echo $this->Form->create('Classcontentcomment',array('action'=>'add'.'/'.base64_decode($this->params['pass'][0]))); ?>
					<fieldset>
						<?php echo $this->Form->input('comment',array('placeholder'=>'Write your comment here','label'=>false,'class'=>'w98p')); ?>
						<?php echo $this->Form->hidden('classcontent_id',array('value'=>base64_decode($this->params['pass'][0]))); ?>
						<?php echo $this->Form->hidden('assignment_id',array('value'=>base64_decode($this->params['pass'][1]))); ?>
						<div class="tar"><?php echo $this->Form->input('Post',array('type'=>'submit','label'=>false,'div'=>false));?></div>
					</fieldset>
					<?php 
					echo $this->Form->end();
				//endif; 
				?>
				<div class="divline"></div>
				<?php
			}
			?>
			
			<?php 
			//hide from all without action-open
			if(!empty($this->params['pass'][2])){
				//pr($comments);die();
				?>
				<div class="row-fluid">
					<div class="span9 bold"><?php echo $datas[0]['Classcontent']['title'];?></div>
					<div class="span3 tar">
						<b>Assignment Submitted</b> 
						<div class="fnt80 ">
							<?php 
							echo "By ".$comments[0]['Prof']['fname']." ".$comments[0]['Prof']['lname'];
							?>
							
						</div>
					</div>
				</div>
				<?php
				
			}
			?>
			
			<?php 
			$arr_comments = array_reverse($comments);
			foreach ($arr_comments as $comment):
				static $i = 1;
				if($comment['Classcontentcomment']['profile_id'] == $loggedUser['profile_id']):
					$del = 'Delete';
				elseif ($ses_datainfo[0]['Courserole']['profile_id'] == $loggedUser['profile_id']):
					$del = 'Delete';
				else:
					$del = '';
				endif;
				$comment_id = $comment['Classcontentcomment']['id'];
			
				// logic of  like/ullike
				if(empty($comment['Classcontentcommentlike'])):
					$lun = 'Like';
					$fun_n = 'like_by_wall_id2';
				else :
					foreach ($comment['Classcontentcommentlike'] as $like):
						if($like['user_id']== $loggedUser['id']):
							$lun = 'Liked';
							$fun_n = 'unlike_by_wall_id2';
							break;
						else:
							$lun = 'Like';
							$fun_n = 'like_by_wall_id2';
						endif;
					endforeach;
				endif;
				?>
				<?php 
				//hide this when redirected from open button of action as a teacher
				if(empty($this->params['pass'][2])){
					?>
					<div id="data_<?php echo $comment_id;?>" class="fnt80">
						<div class="ccComment brd shdw mrb10 pd10">
							<?php 
                                                        $profileimg=$comment['Prof']['link1'];
                                                        ?>
							<div class="row-fluid">
								<div class="span1"><?php 
                                                                if(!empty($profileimg)){
                                                                    echo $this->Html->image($profileimg);
                                                                }else{
                                                                    echo $this->Html->image('profile.jpg');
                                                                }
                                                                ?></div>
								<div class="span11">
									<div class="w98p"><?php echo '<span class="profile-name">'.$comment['Prof']['fname']." ".$comment['Prof']['lname'].":</span> " .$comment['Classcontentcomment']['comment'];?></div>
									<div class="divline mrbt5"></div>
									<?php 
										$total_like = sizeof($comment['Classcontentcommentlike']);
										$pth = "http://$_SERVER[HTTP_HOST]/classcontentcommentlikes"; 
									?>
									<div class="tar">
										<div onclick="<?php echo $fun_n?>('<?php echo $pth;?>','<?php echo $comment['Classcontentcomment']['id']?>',<?php echo $total_like;?>);"id="<?php echo 'lkunl'.$comment['Classcontentcomment']['id'] ?>" ><?php echo $lun . '('.$total_like.')'?></div>
									</div>
								</div>
							</div>
						</div>
					
						<div id="commentForm<?php //echo $comment_id;?>"></div>
						 <?php 
							if($comment['children']):
							$childrens = array_reverse($comment['children']);
							foreach ($childrens as $children):
							$comments_id = $children['Classcontentcomment']['id'];
							
							
							if($children['Classcontentcomment']['profile_id'] == $loggedUser['profile_id']):
								$delete = 'Delete';
							elseif ($ses_datainfo[0]['Courserole']['profile_id'] == $loggedUser['profile_id']):
								$delete = 'Delete';
							else:
								$delete = '';
							endif;
							
							?>
							<div class="ccComment"  style="margin-left: 30px;" id="data_<?php echo $comments_id ?>">
								<?php echo $this->Html->image('http://lms1.pnsreviews.com/img/upload/profiles/'.$children['Classcontentcomment']['profile_id'].'.png');?>
								<?php echo $children['Profile']['fname'].": " . $children['Classcontentcomment']['comment'];?>
								<div class="cccdButton" onclick="dd('../classcontentcomments','delete','<?php echo $comments_id; ?>','<?php echo $children['User']['username']?>');"><?php echo $delete;?></div>
							</div>
						<?php endforeach; endif;?>
					</div>
					<?php
				
				//show this when clicked from action-open
				}else{
					?>
					<div id="data_<?php echo $comment_id;?>">
						<div class="ccComment">
							
							<div class="">
								<div class="">
									<div class="divline"></div>
									<div class="fnt80 mrb5"><b>Posted:</b> <?php echo date('d-M, Y ',strtotime($comment['Classcontentcomment']['created'])).' <span class="pdl5">'.date(' h:i:s A',strtotime($comment['Classcontentcomment']['created'])).'</span>';?></div>
									<?php 
									echo $comment['Classcontentcomment']['comment'];
									?>
									<!--
									<div class="divline mrb5"></div>
									<?php $total_like = sizeof($comment['Classcontentcommentlike']); ?>
									<div class="tar">
										<div onclick="<?php echo $fun_n?>('../classcontentcommentlikes','<?php echo $comment['Classcontentcomment']['id']?>');"id="<?php echo 'lun'.$comment['Classcontentcomment']['id'] ?>" ><?php echo $lun . '('.$total_like.')'?></div>
									</div>
								-->
								</div>
							</div>
						</div>
					
						<div id="commentForm<?php //echo $comment_id;?>"></div>
						 <?php 
							if($comment['children']):
							$childrens = array_reverse($comment['children']);
							foreach ($childrens as $children):
							$comments_id = $children['Classcontentcomment']['id'];
							
							
							if($children['Classcontentcomment']['profile_id'] == $loggedUser['profile_id']):
								$delete = 'Delete';
							elseif ($ses_datainfo[0]['Courserole']['profile_id'] == $loggedUser['profile_id']):
								$delete = 'Delete';
							else:
								$delete = '';
							endif;
							
							?>
							<div class="ccComment"  style="margin-left: 30px;" id="data_<?php echo $comments_id ?>">
								<?php echo $this->Html->image('http://lms1.pnsreviews.com/img/upload/profiles/'.$children['Classcontentcomment']['profile_id'].'.png');?>
								<?php echo $children['Profile']['fname'].": " . $children['Classcontentcomment']['comment'];?>
								<div class="cccdButton" onclick="dd('../classcontentcomments','delete','<?php echo $comments_id; ?>','<?php echo $children['User']['username']?>');"><?php echo $delete;?></div>
							</div>
						<?php endforeach; endif;?>
					</div>
					<?php
				}
				?>
				
		<?php endforeach; ?>
	
<?php endif;?>
</div>
