<?php echo $this->Html->script('site_js/common')?>
<?php //pr($ses_datainfo[0]['Courserole']['role']);?>
<?php 
if($ses_datainfo[0]['Courserole']['role'] != array_search('Teacher',$course_user_role)):
?>
	<div>
		<h4><?php echo $datas[0]['Classcontent']['title']?></h4>
		<div><?php echo $this->Html->image('upload/contents/medium/'.$datas[0]['Classcontent']['id'].'.png');?></div>
		<p><?php echo $datas[0]['Classcontent']['content']?></p>
		<?php if(!empty($datas[0]['Classcontent']['ext'])):?>
		<div> <a href="<?php echo $this->webroot.'img/upload/contents/atched/'.$datas[0]['Classcontent']['id'].$datas[0]['Classcontent']['ext'];?>" > Download Attached File</a> </div>
		<?php endif;endif;?>
	</div>
	<?php 
	if($datas[0]['Classcontent']['status'] != SAVE):
		?>
		<br/>
		<?php 
		if($ses_datainfo[0]['Courserole']['role'] != array_search('Teacher',$course_user_role)):
			?>
			<?php echo $this->Form->create('Classcontentcomment',array('action'=>'add'.'/'.$this->params['pass'][0])); ?>
			<fieldset>
				<?php echo $this->Form->input('comment',array('placeholder'=>'Write your comment here','label'=>false)); ?>
				<?php echo $this->Form->hidden('classcontent_id',array('value'=>$this->params['pass'][0])); ?>
				<?php echo $this->Form->hidden('assignment_id',array('value'=>$this->params['pass'][1])); ?>
			</fieldset>
			<?php echo $this->Form->end(__('Submit')); ?>
		<?php 
		endif; 
		$arr_comments = array_reverse($comments);
		foreach ($arr_comments as $comment):
			static $i = 1;
			if($comment['Classcontentcomment']['profile_id'] == $loggedUser['User']['profile_id']):
				$del = 'Delete';
			elseif ($ses_datainfo[0]['Courserole']['profile_id'] == $loggedUser['User']['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_id';
		else :
			foreach ($comment['Classcontentcommentlike'] as $like):
			
				if($like['profile_id']== $loggedUser['User']['profile_id']):
					$lun = 'Liked';
					$fun_n = 'unlike_by_wall_id';
					break;
				else:
					$lun = 'Like';
					$fun_n = 'like_by_wall_id';
				endif;
			endforeach;
		endif;
				
	?>		
	<div id="data_<?php echo $comment_id;?>">
		
		<div class="ccComment">
			<?php echo $this->Html->image('/img/upload/profiles/'.$comment['Classcontentcomment']['profile_id'].'.png',array('width'=>'100%'));?>
			<?php echo $comment['Prof']['fname'].": " .$comment['Classcontentcomment']['comment'];?>
			<div class="cccdButton" onclick="dd('../classcontentcomments','delete','<?php //echo $comment_id; ?>','');"><?php //echo $del;?></div>
			<?php $total_like = sizeof($comment['Classcontentcommentlike']) ?>
			<!--
			<div class="fr">
				<div class="sButton" 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 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['User']['profile_id']):
				$delete = 'Delete';
			elseif ($ses_datainfo[0]['Courserole']['profile_id'] == $loggedUser['User']['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('/img/upload/profiles/'.$children['Classcontentcomment']['user_id'].'.png',array('width'=>'100%'));?>
				<?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 endforeach; ?>
<?php endif;?>
