<?php
/*----------------------------------------------------------------------------------|  www.vdm.io  |----/
				fdsh 
/-------------------------------------------------------------------------------------------------------/

	@version		1.0.39
	@build			4th April, 2023
	@created		17th December, 2020
	@package		Reservation
	@subpackage		default.php
	@author			farhad shahbazi <http://farhad.com>	
	@copyright		Copyright (C) 2015. All Rights Reserved
	@license		GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
  ____  _____  _____  __  __  __      __       ___  _____  __  __  ____  _____  _  _  ____  _  _  ____ 
 (_  _)(  _  )(  _  )(  \/  )(  )    /__\     / __)(  _  )(  \/  )(  _ \(  _  )( \( )( ___)( \( )(_  _)
.-_)(   )(_)(  )(_)(  )    (  )(__  /(__)\   ( (__  )(_)(  )    (  )___/ )(_)(  )  (  )__)  )  (   )(  
\____) (_____)(_____)(_/\/\_)(____)(__)(__)   \___)(_____)(_/\/\_)(__)  (_____)(_)\_)(____)(_)\_) (__) 

/------------------------------------------------------------------------------------------------------*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');


?>
<?php echo $this->toolbar->render(); ?>

<!--[JCBGUI.site_view.default.26.$$$$]-->
<?php
$clip='<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="25px" height="25px" viewBox="0 0 400.000000 448.000000" preserveAspectRatio="xMidYMid meet" style="&#10;    fill: #a5a5a5"><g transform="translate(0.000000,448.000000) scale(0.100000,-0.100000)" fill="inherit" stroke="none"><path d="M2620 4465 c-179 -30 -330 -90 -477 -188 -87 -58 -206 -174 -1037 -1006 l-940 -940 -3 -58 c-5 -68 16 -111 69 -143 37 -22 107 -27 141 -9 12 6 434 422 937 924 556 554 941 930 981 958 164 115 328 169 514 169 147 -1 241 -22 370 -86 332 -163 529 -488 512 -841 -8 -164 -52 -291 -155 -450 -64 -100 -2284 -2324 -2390 -2395 -220 -148 -495 -113 -683 87 -174 187 -195 439 -53 653 30 45 385 407 1171 1192 1193 1192 1146 1148 1234 1148 45 0 122 -46 152 -92 29 -46 37 -121 16 -175 -5 -16 -410 -428 -919 -938 -992 -993 -944 -940 -919 -1030 14 -51 65 -102 112 -110 94 -18 34 -71 1010 903 494 493 919 926 944 961 150 207 128 458 -57 641 -164 163 -375 195 -585 87 -51 -26 -224 -195 -1217 -1186 -1209 -1208 -1208 -1207 -1274 -1358 -92 -207 -89 -487 5 -690 43 -91 100 -170 177 -244 117 -111 236 -179 389 -220 118 -32 319 -32 430 -1 94 27 198 78 275 134 80 59 2347 2330 2409 2413 75 101 166 290 196 409 110 436 -16 869 -342 1176 -263 248 -643 365 -993 305z"/></g></svg>';
$send='<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="25px" height="25px" viewBox="0 0 448.000000 396.000000" preserveAspectRatio="xMidYMid meet" style=" fill: #238ff3; "> <g transform="translate(0.000000,396.000000) scale(0.100000,-0.100000)" fill="inherit" stroke="none"> <path d="M285 3946 c-110 -27 -202 -105 -252 -211 l-28 -60 0 -585 0 -585 27 -57 c47 -101 137 -178 243 -207 22 -6 436 -63 920 -126 484 -64 893 -119 909 -123 19 -5 -251 -43 -815 -116 -464 -59 -886 -114 -937 -122 -157 -23 -261 -95 -320 -222 l-27 -57 0 -595 0 -595 27 -57 c73 -156 239 -247 399 -218 43 8 567 229 1708 722 905 390 1756 758 1891 815 135 58 265 120 290 138 100 70 155 180 154 305 -2 109 -31 179 -108 256 l-61 60 -1900 814 c-1045 447 -1925 819 -1955 826 -66 16 -99 16 -165 0z"></path> </g> </svg>';
$recorder='<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="25px" height="25px" viewBox="0 0 352.000000 512.000000" preserveAspectRatio="xMidYMid meet" style="&#10;    fill: #a5a5a5;&#10;"> <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)" fill="inherit" stroke="none"> <path d="M1580 5105 c-293 -47 -576 -227 -747 -476 -83 -121 -153 -299 -178 -454 -22 -131 -22 -1565 0 -1705 45 -302 223 -583 476 -757 124 -85 303 -155 459 -178 612 -93 1183 326 1275 935 22 139 22 1561 0 1700 -43 285 -199 549 -427 721 -246 185 -554 262 -858 214z m370 -328 c209 -57 368 -171 480 -344 50 -76 79 -142 108 -248 15 -54 17 -144 17 -865 0 -721 -2 -811 -17 -865 -29 -106 -58 -172 -108 -248 -238 -366 -718 -474 -1087 -247 -180 111 -294 265 -361 490 -15 49 -17 145 -20 825 -2 557 0 791 8 845 53 337 300 594 640 666 80 17 262 12 340 -9z"/> <path d="M95 3666 c-41 -18 -83 -69 -90 -109 -4 -18 -5 -278 -3 -577 4 -512 6 -552 26 -658 71 -361 231 -661 492 -922 278 -279 611 -447 987 -501 l92 -13 3 -392 c3 -379 4 -394 24 -420 39 -53 71 -69 134 -69 63 0 95 16 134 69 20 26 21 41 24 420 l3 393 62 7 c34 4 101 16 148 26 353 78 645 242 895 503 278 289 443 646 484 1047 7 65 10 296 8 607 -3 488 -4 502 -24 529 -39 53 -71 69 -134 69 -63 0 -95 -16 -134 -69 -20 -27 -21 -42 -27 -594 -6 -528 -7 -573 -27 -659 -68 -297 -191 -523 -397 -728 -207 -208 -437 -332 -733 -397 -140 -31 -424 -31 -564 0 -295 65 -527 190 -733 397 -205 204 -331 435 -398 730 -19 83 -21 135 -26 657 -6 552 -7 567 -27 594 -11 15 -32 37 -46 47 -33 25 -113 32 -153 13z"/> </g> </svg>';
?>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>

<div id="context-menu" style="width: 150px; position: absolute; display: none">
  <div class="css-1obmwoi ezvb10p0"></div>
  <div origin="right top" class="css-m4s3q2 ezvb10p1">
    <ul class="css-1wjqtxb ehfgrij0">
      <li class="Menu_MenuItemWrapper__NyeOc" id="editctxbtn" data-cmd="edit" style="display: none" >
        <img class="Menu_MenuIcon__tFRZQ css-v6ppy3 e13l1lra1" src="/components/com_reservation/assets/images/edit_icon.svg" alt="ویرایش">
        <p class="Menu_Title__jDLFR">ویرایش</p>
      </li>
      <li class="Menu_MenuItemWrapper__NyeOc" data-cmd="reply">
        <img class="Menu_MenuIcon__tFRZQ css-v6ppy3 e13l1lra1" src="/components/com_reservation/assets/images/reply_icon.svg" alt="پاسخ">
        <p class="Menu_Title__jDLFR">پاسخ</p>
      </li>
      <li class="Menu_MenuItemWrapper__NyeOc" data-cmd="copy">
        <img class="Menu_MenuIcon__tFRZQ css-v6ppy3 e13l1lra1" src="/components/com_reservation/assets/images/copy_icon.svg" alt="رونوشت">
        <p class="Menu_Title__jDLFR">رونوشت</p>
      </li>
      <li class="Menu_MenuItemWrapper__NyeOc" id="delctxbtn" data-cmd="del" data-toggle="modal" data-target="#confirm-delete">
        <img class="Menu_MenuIcon__tFRZQ css-v6ppy3 e13l1lra1" src="/components/com_reservation/assets/images/delete_icon.svg" alt="حذف">
        <p class="Menu_Title__jDLFR">حذف</p>
      </li>
      
    </ul>
  </div>
</div>
<!-- <p id='copy-toast'>رونوشت پیام انجام شد.<img  src="/components/com_reservation/assets/images/copy_icon.svg" alt="رونوشت"></p> -->
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="height: auto;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                حذف پیام
            </div>
            <div class="modal-body">
                آیا برای حذف این پیام مطمئن هستید؟
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">لغو</button>
                <a id="submit-delete" data-dismiss="modal" class="btn btn-success success">تایید</a>
            </div>
        </div>
    </div>
</div>

<div class="chat">
  <div class="row justify-content-center">
    <div class="col-md-8">
      <div class="card card-cahtt">
        <div class="card-header header-chats">
          <?php
            if ( ( ! file_exists( JPATH_SITE . '/libraries/CBLib/CBLib/Core/CBLib.php' ) ) || ( ! file_exists( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' ) ) ) {
              // echo 'CB not installed';
              $imgurl = '';
            }
            else
            {
              include_once( JPATH_ADMINISTRATOR . '/components/com_comprofiler/plugin.foundation.php' );
              
              cbimport( 'cb.html' );
              $joomlaid = $id;
              global $_CB_framework, $_PLUGINS, $ueConfig;

              $cbUser =& CBuser::getInstance( (int) JFactory::getApplication()->input->get('uid') );
              $user = $cbUser->getUserData();
              $imgurl = '/images/comprofiler/' . $user->avatar;
              // dump($user, 'user');
            }
          ?>
          <a id="profile-user" class="img" href="#">
            <img src="<?php echo $imgurl;?>" alt="">
          </a>
          <p id="user-name"><?php echo $this->item->users_name; ?></p>
          <div id="chat-status">
          <?php if($this->item->session->finish==0):?>
            <p id="notice">گفتگو در حال انجام است</p>
          <?php else:?>
            <p id="notice">گفتگو خاتمه یافت</p>
          <?php endif; ?>
          <?php if(empty($this->item->msn)):?>
            <?php if($this->item->session->finish==0):?>
              <button id="conversation" class="btn btn-sm btn-danger">پایان گفتگو
                <div id="loading" class="spinner-grow text-warning" role="status">
                  <span class="sr-only">Loading...</span>
                </div>
              </button>
            <?php else:?>
              <button id="conversation" class="btn btn-sm btn-success">ادامه گفتگو
                <div id="loading" class="spinner-grow text-warning" role="status">
                  <span class="sr-only">Loading...</span>
                </div>
              </button>
            <?php endif; ?>
            <button id="video_session" class="btn btn-sm btn-info">شروع جلسه آنلاین
              <div id="loading" class="spinner-grow text-warning" role="status">
                <span class="sr-only">Loading...</span>
              </div>
            </button>
          <?php endif;?>
          </div>
        </div>
        <div class="card-body" id="chat-body">
        <?php //dump($this, 'this');?>
        
        <?php foreach($this->item->messages as $message):?>
          <?php
            // dump($message, 'message');
            $tsmsg = trim(strip_tags($message->message));
            $reply = "";
            if($message->reply)
            {
              $reply_pm = $this->item->messages[$message->reply];
              $reply = $reply_pm->message;
              // dump($reply_pm, 'reply_pm');
              if($reply_pm->from == $this->item->users_id)
                $reply_user = $this->item->users_name;
              else
                $reply_user = $this->user->name;
                
              $reply = '<div id="rep-'.$message->reply.'" class="text reply"><div class="Preview_preview__7RTlb" data-prevent-context-menu-mobile="true" style="border-right: 3px solid rgb(19, 194, 194);"><div class="Preview_details__kki9K"><span class="Preview_sender__RUCFl" style="color: rgb(19, 194, 194);">'.$reply_user.'</span><div class="Text_text__0QjN9 TextPreview_text_preview__7vRSt"><span>'.$reply.'</span></div></div></div></div>';
            }
            // $date = new DateTime($message->created, new DateTimeZone('UTC'));
            // $date->setTimezone(new DateTimeZone('Asia/tehran'));
          ?>
          <?php if($tsmsg || substr($message->message, 0, 4) == '<img'): ?>
            <div class="pm <?= ($message->from != $this->item->users_id)? 'me': '';?>" id="pm-<?php echo $message->id?>">
              <?php if($reply && $message->from != $this->item->users_id):?>
                <?php echo $reply; ?>
              <?php endif;?>
              <div class="text">
                <span class="massage">
                  <?= $message->message;?>
                </span>
                <div class="info-message">
                  <span class='readtick <?php echo $message->read ? 'read' : 'unread';?>' style="<?= ($message->from==$this->item->users_id)? 'display:none;': '';?>">  </span>
                  <!--<span class="time"><?php //echo $date->format('Y/m/d H:i'); ?></span> -->
                  <!--<span class="time"><?php //echo JHtml::_('date', $message->created, 'l, d M Y G:i'); ?></span>-->
                  <span class="time"><?php echo JHtml::_('date', $message->created, 'Y/m/d G:i'); ?></span>
                </div>
              </div>
              <?php if($reply && $message->from == $this->item->users_id):?>
                <?php echo $reply; ?>
              <?php endif;?>
            </div>
          <?php endif;?>
        <?php endforeach;?>
        </div>
        <div class="">
          <form id='sending-form' action="#" method="post" class="form-inline" enctype="multipart/form-data">
          
            <div id="reply-header" class="css-go2n58 e27v5ni5" style="display: none;">
              <div class="css-1ber1nl e27v5ni2">
                <div class="Preview_preview__7RTlb css-5a4ol0" data-prevent-context-menu-mobile="true" style="border-right: 3px solid rgb(19, 194, 194);">
                  <div class="Preview_details__kki9K">
                    <span id="reply-user" class="Preview_sender__RUCFl" style="color: rgb(19, 194, 194);">ArMaN</span>
                    <div class="Text_text__0QjN9 TextPreview_text_preview__7vRSt">
                      <span id="reply-text">replytext</span>
                      <input type="hidden" value="0" name="replyid" id="reply-id">
                    </div>
                  </div>
                </div>
              </div>
              <div id="reply-close" class="e27v5ni1 css-1fgag0w eryqwb30">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><g transform="translate(-1024 -240)"><g transform="translate(1024 240)"><rect fill="none" width="16" height="16"></rect><path fill="#5e6c84" d="M14.857,9.143H9.143v5.714a1.143,1.143,0,1,1-2.286,0V9.143H1.143a1.143,1.143,0,1,1,0-2.286H6.857V1.143a1.143,1.143,0,1,1,2.286,0V6.857h5.714a1.143,1.143,0,1,1,0,2.286Z" transform="translate(12 0.686) rotate(45)"></path></g></g></svg>
              </div>
            </div>
            <div style="position: relative;">
              <button type="submit" name="chatSendBtn" id="chatSendBtn" class="btn btn-primary"
                style="cursor:<?= $this->item->session->finish==1?'no-drop':'pointer';?>"
                <?= $this->item->session->finish==1?'disabled':'';?> >
                <?php echo $send; ?>
                <div id="loading" class="spinner-grow text-warning" role="status">
                  <span class="sr-only">Loading...</span>
                </div>
              </button>
              <!-- <input title="در این قسمت میتوانید پیام خود را وارد کنید" type="text" style="flex-grow: 2" class="form-control mr-1" name="chatMessage" id="chatMessage" required placeholder="پیام خود را وارد کنید ..."> -->
              <textarea title="در این قسمت میتوانید پیام خود را وارد کنید" id="chatMessage" style="height: 51px;" name="chatMessage" cols="100%" required placeholder="پیام خود را وارد کنید ..."></textarea>
              <label id="upload_file" for="atachedfile">
                <?php echo $clip; ?>
              </label>
              <label id="upload_voise" for="atachedfile">
                <?php echo $recorder; ?>
              </label>
            </div>
            <input name="atachedfile" id='atachedfile' type="file" />
            <progress style="display: none;"></progress>
            <input type="hidden" name="pmid" id="pmid" value="0">
          </form>

        </div>
      </div>
    </div>
  </div>
  <div id="myModal" class="modalimg">
    <span class="closeimg">&times;</span>
    <img class="modalimg-content" id="img01">
    <div id="caption"></div>
  </div>
	<script>
	</script>
  <input type="hidden" name="<?= JSession::getFormToken();?>" id="token">
	
</div><!--[/JCBGUI$$$$]-->

