<?php 
$this->load->view('site/templates/header');
$this->load->model('product_model');
$this->load->model('user_model');
?>
	<section>
    	<div class="main">
        	<ul class="bread_crumbs">
            	<li><a href="<?php echo base_url(); ?>">Home</a></li>
                <span>›</span>
                <li><a href="view-profile/<?php echo $this->session->userdata['shopsy_session_user_name']; ?>">Profile</a></li>
                <span>›</span>
                <li><a >Conversation</a></li>
            </ul>
            <div class="convers">   
            	
                <div class="conversation_container">
                    <div class="conversation_container_left">
                        <div class="side_bar">
                            <ul>
                                <li <?php if($viewfolder=='inbox'){ echo 'class="active"'; }?>>
                                    <a href="people/<?php echo $this->session->userdata['shopsy_session_user_name'];?>/conversations?qv=inbox">Inbox</a>
                                </li>
                                <li <?php if($viewfolder=='sent'){ echo 'class="active"'; }?>>
                                    <a href="people/<?php echo $this->session->userdata['shopsy_session_user_name'];?>/conversations?qv=sent">Sent</a>
                                </li>
                                <li <?php if($viewfolder=='all'){ echo 'class="active"'; }?>>
                                    <a href="people/<?php echo $this->session->userdata['shopsy_session_user_name'];?>/conversations?qv=all">All</a>
                                </li>
                                <li <?php if($viewfolder=='trash'){ echo 'class="active"'; }?>>
                                    <a href="people/<?php echo $this->session->userdata['shopsy_session_user_name'];?>/conversations?qv=trash">Trash</a>
                                </li>
                            </ul>
                        </div>
                    </div>                    
                    <div class="conversation_container_right">      
                        <div>
                            <center><img id="MessageStatus" src="images/ajax-loader/ajax-loader(6).gif" alt="Loading" style="display:none;" /></center>
                        </div>  
                        <?php if ($conversations->num_rows() > 0){ ?> 
                        <ul class="message-box">
           					<li style=" border-right: 1px solid #D9D9D9;">
                            	<input id="checkbox-id" type="checkbox" class="select-all-msg">
                            </li>  
                            <?php if($viewfolder!='trash'){?>         					
              				<li style=" border-right: 1px solid #D9D9D9;">
                            	<a href="javascript:void(0);" onclick="javascript:confirmTrashMsg('<?php echo $this->session->userdata['shopsy_session_user_id'];?>','<?php echo $viewfolder; ?>','Delete');">Archive</a>
                            </li>
                            <?php }else{ ?>
                            <li style=" border-right: 1px solid #D9D9D9;">
                            	<a href="javascript:void(0);" onclick="javascript:confirmTrashMsg('<?php echo $this->session->userdata['shopsy_session_user_id'];?>','<?php echo $viewfolder; ?>','Read');">Restore</a>
                            </li>
                            <?php } ?>
                            <?php if($viewfolder!='trash'){ ?>
                			<li style=" border-right: 1px solid #D9D9D9;">
                            	<a href="javascript:void(0);" onclick="javascript:markmessage('read');">Mark as Read</a>
                            </li>
                  			<li style=" border-right: 1px solid #D9D9D9;">
                            	<a href="javascript:void(0);" onclick="javascript:markmessage('unread');">Mark as Unread</a>
                            </li>
                            <?php } ?>
                       		<li class="lastli" >
                            <?php if($viewfolder=='trash'){?>
                            <a href="javascript:void(0);" onclick="javascript:confirmTrashMsg('<?php echo $this->session->userdata['shopsy_session_user_id'];?>','<?php echo $viewfolder; ?>','Delete');" >Delete Forever</a>
                            <?php }else{ ?>
                            <a href="javascript:void(0);" onclick="javascript:confirmTrashMsg('<?php echo $this->session->userdata['shopsy_session_user_id'];?>','<?php echo $viewfolder; ?>','Trash');" >Delete</a>
                            <?php } ?>
                            </li>
           				</ul>
                        
                        <?php foreach ($conversations->result() as $row){ ?> 
                        	<?php 
								$label='';
								if($viewfolder=='inbox'){
									if($row->senderthumbnail!=''){ $profile_pic='users/thumb/'.$row->senderthumbnail; } else { $profile_pic='default_avat.png';}
									$shopname=$row->sendershopname;
									$shopurl=$row->sendershopurl;
									$username=$row->sender_name;
									$status='receiver_status';
								}else if($viewfolder=='sent'){
									if($row->thumbnail!=''){ $profile_pic='users/thumb/'.$row->thumbnail; } else { $profile_pic='default_avat.png';}
									$shopname=$row->shopname;
									$shopurl=$row->shopurl;
									$username=$row->user_name;
									$status='sender_status';
								}else  if($viewfolder=='all' || $viewfolder=='trash'){
									if($this->session->userdata['shopsy_session_user_id']==$row->receiver_id){
										if($row->thumbnail!=''){ $profile_pic='users/thumb/'.$row->thumbnail; } else { $profile_pic='default_avat.png';}										
										$username=$row->user_name;
										$shopname=$row->shopname;
										$shopurl=$row->shopurl;
										$label='Inbox';
										$status='receiver_status';
									}else if($this->session->userdata['shopsy_session_user_id']==$row->sender_id){
										if($row->thumbnail!=''){ $profile_pic='users/thumb/'.$row->thumbnail; } else { $profile_pic='default_avat.png';}
										$username=$row->user_name;
										$shopname=$row->sendershopname;
										$shopurl=$row->sendershopurl;
										$label='Sent';
										$status='sender_status';
									}
								}
							?>
                        <ul <?php if($row->$status!='Read'){ echo 'style="background:#EBF6F9"'; } ?> class="message-box" id="Msg_<?php echo $row->id;?>">
                        	<li style=" border-right: 1px solid #D9D9D9;">
                            	<input id="checkbox-id" type="checkbox" class="chkMsg" value="<?php echo $row->id;?>" <?php if($row->$status!='Read'){ echo 'data-mode="unread"'; }else { echo 'data-mode="read"';} ?> >
                            </li>
                            <li>
                                <div class="avatar_view">                                
                                    <img width="40px" src="images/<?php echo $profile_pic;?>">
                                </div>
                                <div class="avater_split">
                                    <span>                        
                                    	<a href="view-profile/<?php echo $username; ?>">            
                                        	<label class="sort_link_1"><?php echo $username; ?></label>
                                        </a>
                                    </span>
                                    <?php if($shopname!=''){ ?>
                                    <div class="sub_cut">
                                        <a href="shop-section/<?php echo $shopurl;?>">
                                            <p>
                                                <img src="images/flow.png">
                                                <label class="sort_link_1"><?php echo $shopname; ?> </label>
                                            </p>
                                        </a>
                                    </div>
                                    <?php } ?>
                                </div>
                            </li>
                            <li>
                                <span class="re-order">
                                    <!--<strong class="new-buton">NEW</strong>-->
                                    <a href="people/<?php echo $this->session->userdata['shopsy_session_user_name'];?>/conversations/<?php echo $viewfolder; ?>/<?php echo $row->id;?>"><?php echo $row->subject;?></a>
                                </span>
                                <br />
                                <label class="text_lines"><?php echo $row->message;?></label>
                            </li>
                            <li style="float:right">
                                <span>
								<?php 
									$datediff = time()-strtotime($row->dataAdded); 
									$diffdate=floor($datediff/(60*60*24));
									if($diffdate!=0){
										if($diffdate<4){
											echo $diffdate.' days ago';
										}else{
											echo date('m/d/y',strtotime($row->dataAdded));
										}
									}else{
										if(floor($datediff/(60*60))<1){
											if(floor($datediff/(60))>0){
												echo floor($datediff/(60)).' mins ago';
											}else{
												echo 'just now';
											}
										}else{
											echo floor($datediff/(60*60)).' hours ago';
										}
									}
								?>
                                </span>
                                <?php if($label!=''){ ?>
                                <strong class="new-buton"><?php echo $label; ?></strong>
                                <?php } ?>
                            </li>
                        </ul>
                        <?php } }else{ ?>
                        	No Conversation Found
                        <?php } ?>
           			</div>
                </div>
			</div>
		</div>
	</section>


<?php $this->load->view('site/templates/footer'); ?>
