<?php $this->load->view("main/drs/header"); ?>
<?php
 if($this->session->userdata("per") == 1){
  $value_of_text = "مشتری";
   $bimeh_value = "تخفیف ها";
 }else{
  $value_of_text = "بیمار";
  $bimeh_value = "بیمه";
 }
?>
			  <style>
				.add_pationt,.setting,.send_message{
	   width: 100%;
	   height: 100%;
	   position: fixed;
	   top: 0;
	   left: 0;
	   z-index: 3000;
	   background: rgba(0,0,0,0.5);
}
textarea{
  resize: none;
  height: 100px !important;
}
.icon-pause,.icon-minus-sign,.icon-play{
 
  cursor: pointer;
}
.icon-pause:hover{
  color: #f00 !important;
}
			  </style>
			  <!-- for edit clender -->
			  	<div class="add_pationt" style="display: none;">
	   <div class="modal-dialog">
		<input type="hidden" id="ajaxupdater" value="" >
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                <h4 class="modal-title">ثبت نوبت</h4>
                                            </div>
                                            <div class="modal-body">
												 <input type="hidden" id="hidden_path" name="path" value="" />
												
												
												
                                            
										   <div id="folder">
                                                    <div class="form-group">
                                                        <label for="exampleInputEmail1">نام <?php echo $value_of_text; ?></label>
                                                        <input type="text" name="foldername" class="form-control" id="exampleInputEmail1">
                                                    </div>
													 <div class="form-group">
                                                        <label for="exampleInputEmail1">ساعت مراجعه</label>
                                                         <input type="text" name="foldername" class="form-control" id="exampleInputEmail2">
                                                    </div>
													 
													
													
                                                   </div>
										  
                                                    <button type="submit" class="btn btn-info set_calender" id="button_creator">ثبت</button>
                                            </div>
                                        </div>
                                    </div>
</div>
              	<div class="send_message" style="display:none;">
	   <div class="modal-dialog">
		
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                <h4 class="modal-title">فرستادن پیغام</h4>
                                            </div>
                                            <div class="modal-body">

                                               
												 <input type="hidden" id="tellid" name="path" value="" />
												
												 
												
										  
										   <div id="piture" >
                                                    <div class="form-group">
                                                        <div class="col-lg-12 row"><label for="exampleInputFile">نام:</label><span class="nameho"></span></div>
														<div class="col-lg-12 row"><label for="exampleInputFile">متن پیغام:</label><p class="textho"></p></div>
                                                         <div class="col-lg-12 row"><textarea class="form-control message" placeholder="پاسخ"></textarea></div>
                                                    </div>
                                            </div>       
                                                    <button type="submit" class="btn btn-default send_mess">فرستادن پیغام</button>
                                                
                                            </div>
                                        </div>
										<div class="alert alert-success fade in succmessage" style="margin-top:10px;display:none">
                                  
                                    پیام شما با موفقیت فرستاده شد.                             
                                </div>
                                    </div>
</div>
				<div class="setting" style="display: none;">
				<div class="modal-dialog">
		<input type="hidden" id="ajaxupdater" value="" >
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                                                <h4 class="modal-title">مدیریت نوبت تلگرام</h4>
                                            </div>
                                            <div class="modal-body">
												 <input type="hidden"  id="hidden_date" name="date" value="" />
												<input type="hidden"  id="hidden_id" name="id" value="" />
												
												
                                            
										   <div id="folder">
											<div class="form-group">
                                                        <label for="exampleInputEmail1">وضعیت</label>
                                                         <select type="text" name="foldername" class="form-control" id="exampleInputEmail2">
														  <option value="3">پذیرفتن</option>
														  <option value="4">رد</option>
														 </select>
                                                    </div>
													 <div class="form-group">
                                                        <label for="exampleInputEmail1">ساعت مراجعه</label>
                                                         <input type="text" name="foldername" class="form-control" id="exampleInputEmail2">
                                                    </div>
													 <div class="form-group">
                                                        <label for="exampleInputEmail1">پیام فرستادن به <?php echo $value_of_text; ?></label>
                                                         <textarea type="text" name="foldername" class="form-control" id="exampleInputEmail2"></textarea>
                                                    </div>
													 
													
													
                                                   </div>
										  
                                                    <button type="submit" class="btn btn-info set_fromtelegram" id="button_creator">ثبت</button>
                                            </div>
                                        </div>
                                    </div>
				  
				</div>
			  <!--end for -->
              <div class="row state-overview">
				<div class="col-lg-1 col-sm-6 ltr">
                      <section class="panel">
						<a href="<?php echo base_url(); ?>panel/galery">
                          <div class="symbol blue">
                              <img src="<?php echo base_url(); ?>assets/main/img/Gallery.png">
							  <span>گالری تصاویر</span>
                          </div>
						  </a>
                      </section>
                  </div>
				<a href="<?php echo base_url(); ?>panel/list_articles">
                  <div class="col-lg-1 col-sm-6 ltr">
                      <section class="panel">
						<div class="symbol yellow">
                          <img src="<?php echo base_url(); ?>assets/main/img/Articles.png">
							  <span>مقالات</span>
                          </div>
                      </section>
                  </div>
				  </a>
				  <a href="<?php echo base_url(); ?>panel/set_insure">
                  <div class="col-lg-1 col-sm-6 ltr">
                      <section class="panel">
                          <div class="symbol green">
                            <img src="<?php echo base_url(); ?>assets/main/img/Insurance.png">
							  <span><?php echo $bimeh_value ?></span>
                          </div>
                      </section>
                  </div>
				  </a>
				  <a href="<?php echo base_url(); ?>panel/contact">
                  <div class="col-lg-1 col-sm-6 ltr">
                      <section class="panel">
                          <div class="symbol red">
                            <img src="<?php echo base_url(); ?>assets/main/img/Service.png">
							  <span>تماس با ما</span>
                          </div>
                      </section>
                  </div>
				  </a>
				  <a href="<?php echo base_url(); ?>panel/list_Patient">
                  <div class="col-lg-1 col-sm-6 ltr">
                      <section class="panel">
                          <div class="symbol purple">
                              <img src="<?php echo base_url(); ?>assets/main/img/List.png">
							  <span>لیست <?php echo $value_of_text;  ?>ان</span>
                          </div>
                      </section>
                  </div>
				  </a>
				  <div class="col-lg-6 col-sm-6 rtl">
                    <div class="search_holder">
                                                <button class="col-lg-3"><i class="icon-search icon-flip-horizontal" aria-hidden="true"></i> جستجو</button>
                                                <div style="float: left;width: 60%;">
												<input class="form-control" type="text" placeholder="جستجو بر اساس نام <?php echo $value_of_text; ?>">
												</div>
                                            </div>  
                  </div>
              </div>
              <!--state overview end-->

              <div class="row">
                  <div class="col-lg-8">
                      <!--custom chart start-->
                      <div class="border-head">
						<?php if($this->session->userdata("per") == 1){ ?>
                          <h3>تعداد مشتری های پذیرفته شده</h3>
						<?php }else{ ?>
						<h3>تعداد بیماران ویزیت شده</h3>
						<?php } ?>
                      </div>
                      <div class="custom-bar-chart">
                          <div class="bar">
                              <div class="title">فروردین</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[0] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[0]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">اردیبهشت</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[1] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[1]; ?></div>
                          </div>
                          <div class="bar ">
                              <div class="title">خرداد</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[2] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[2]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">تیر</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[3] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[3]; ?></div>
                          </div>
                          <div class="bar">
                              <div class="title">مرداد</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[4] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[4]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">شهریور</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[5] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[5]; ?></div>
                          </div>
                          <div class="bar">
                              <div class="title">مهر</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[6] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[6]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">آبان</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[7] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[7]; ?></div>
                          </div>
                          <div class="bar ">
                              <div class="title">آذر</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[8] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[8]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">دی</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[9] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[9]; ?></div>
                          </div>
                          <div class="bar ">
                              <div class="title">بهمن</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[10] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[10]; ?></div>
                          </div>
                          <div class="bar doted">
                              <div class="title">اسفند</div>
                              <div class="value tooltips" data-original-title="<?php echo $count_of_customers[11] . "نفر"; ?>" data-toggle="tooltip" data-placement="top"><?php echo $count_of_customers[11]; ?></div>
                          </div>
                      </div>
                      <!--custom chart end-->
                  </div>
                  <div class="col-lg-4">
                      <!--new earning start-->
                      <div class="panel terques-chart">
                          <div class="panel-body chart-texture">
                              <div class="chart">
                                  <div class="heading">
                                      <span>جمعه</span>
                                      <strong>ريال 570000 | 15%</strong>
                                  </div>
                                  <div class="sparkline" data-type="line" data-resize="true" data-height="75" data-width="90%" data-line-width="1" data-line-color="#fff" data-spot-color="#fff" data-fill-color="" data-highlight-line-color="#fff" data-spot-radius="4" data-data="[200,135,667,333,526,996,564,123,890,564,455]"></div>
                              </div>
                          </div>
                          <div class="chart-tittle">
                              <span class="title">ورودی ها</span>
                              <span class="value">
                                  <a href="#" class="active">فروش</a>
                                  |
                                  <a href="#">بازگشتی</a>
                                  |
                                  <a href="#">آنلاین</a>
                              </span>
                          </div>
                      </div>
                      <!--new earning end-->

                      <!--total earning start-->
                      <div class="panel green-chart">
                          <div class="panel-body">
                              <div class="chart">
                                  <div class="heading">
                                      <span>مهر</span>
                                      <strong>23 روز | 65%</strong>
                                  </div>
                                  <div id="barchart"></div>
                              </div>
                          </div>
                          <div class="chart-tittle">
                              <span class="title">درآمد کل</span>
                              <span class="value">ريال, 76،54،678</span>
                          </div>
                      </div>
                      <!--total earning end-->
                  </div>
              </div>
              <div class="row">
                  <div class="col-lg-8">
                      <!--work progress start-->
                      <section class="panel">
                          <div class="panel-body progress-panel">
                              <div class="task-progress">
                                  <h1>کنترل مدیریت نوبت</h1>
                              </div>
                              <div class="task-option">
                              </div>
                          </div>
                          <table class="table table-hover  nobats">
                              <tbody>
								<?php $count = 2;$counter=1; ?>
								<?php $html ="";	?>
								<?php foreach($lastsnobats as $value){ ?>
								<?php if($value->visit_status != 3){ ?>
								  <?php if($value->visit_status == 0 && $counter == 1){
								
								  ?>
								<?php
								$htmlf = '<tr class="first" data_id="'.$value->id . '"><td>'. $counter.'</td>';
                                $htmlf .= '<td>'.$value->po_name.'</td><td><i class="icon-ok-sign" aria-hidden="true"></i></td>';
                                if($value->isdoc){
								$htmlf .= '<td><span><a href='.$value->docurl.' target="_blank" ><img src="'.base_url().'assets/main/img/Folder.png"></a></span>';
								}else{
								$htmlf .= '<td><a href='.$value->docurl.' target="_blank"><span><img src="'.base_url().'assets/main/img/List01.png"></span></a>';
								}
								$htmlf .= '</td></tr>';
								?>
								
							  <?php $counter++; ?>
								<?php }elseif($value->visit_status == 1){ ?>
								 <?php
								 $html .= '<tr style="background:#eee;" data_id="'. $value->id .'">';
								$html .= '<td>'. $count."</td>";
								$html .= '<td>'.$value->po_name."</td>";
                                $html .= '<td><i class="icon-minus-sign" aria-hidden="true"></i>';
                                $html .=  ' <span class="iconpause" data_type="play" ><i class="icon-play" style="color: #999 !important;"  aria-hidden="true"></i></span></td>';
                                  if($value->isdoc){
								$html .= '<td><a href='.$value->docurl.' target="_blank" ><img src="'. base_url().'assets/main/img/Folder.png"></a>';
								  }else{
								$html .= '<td><a href='.$value->docurl.' target="_blank" ><img src="'.base_url().'assets/main/img/List01.png"></a>';   
								  }
								$html .= "</td></tr>";
								$count++;
								  ?>
								<?php }elseif($value->visit_status == 0){ ?>
								<?php
								$html .= '<tr data_id="'. $value->id .'">';
								$html .= '<td>'.$count.'</td>';
								$html .= '<td>'. $value->po_name.'</td>';
								$html .= '<td><i class="icon-minus-sign" aria-hidden="true"></i>';
                                $html .= ' <span class="iconpause" data_type="pause" ><i class="icon-pause" style="color: #999 !important;"  aria-hidden="true"></i></span></td>';
                                if($value->isdoc){
								$html .= '<td><a href="'.$value->docurl.'" target="_blank"  ><img src="'. base_url().'assets/main/img/Folder.png"></a>';
								}else{
								$html .= '<td><a href="'.$value->docurl.'" target="_blank"  ><img src="'.base_url().'assets/main/img/List01.png"></a>';
								}
                                $html .=  '</td></tr>';
								  $count++;
								?>
								
                                  
                                  
                                  
                                  
                              
								<?php }  ?>
								<?php } } ?>
                             <?php echo @$htmlf.$html; ?>
                              </tbody>
                          </table>
                      </section>
                      <!--work progress end-->
                  </div>
				                    <div class="col-lg-4">
                      <!--user info table start-->
                      <section class="panel">
                          <div class="panel-body">
                              <a href="#" class="task-thumb">
                                  <img src="<?php echo base_url(); ?>assets/main/img/avatar1.jpg" alt="">
                              </a>
                              <div class="task-thumb-details">
                                  <?php if($this->session->userdata("per") == 1){ ?>
                         <h1><a href="#">پیام کاربران</a></h1>
						<?php }else{ ?>
						 <h1><a href="#">مشاور پزشکی</a></h1>
						<?php } ?>
								 
                                  
								  <p><?php echo $fullname; ?></p>
                              </div>
                          </div>
                          <table class="table table-hover personal-task">
                              <tbody>
								<?php foreach($telegram_message as $value){ ?>
                                <tr data_tellid="<?php echo $value->tellid; ?>" >
                                    <td>
                                        <i class=" icon-bell-alt"></i>
                                    </td>
                                    <td><?php echo $value->fullname; ?></td>
                                    <td><?php echo mb_substr($value->message,0,25)."..."; ?> <input type="hidden" value="<?php echo $value->message; ?>" ></td>
                                </tr>
								<?php } ?>
                              
                              </tbody>
                          </table>
                      </section>
                      <!--user info table end-->
                  </div>
              </div>
              <div class="row">
			  <!-- for calculator -->
			  <div class="col-lg-8">
			  <?php //$this->load->view("plugins/calendar"); ?>
			   <?php $this->load->view("plugins/persian_calender"); ?>
			  </div>
			  <div class="col-lg-4">
			  <?php $this->load->view("plugins/normal_calender"); ?>
			  </div>
			  <div class="col-lg-4" style="float: left;margin-top:20px;">
				<div class="clock">
				  <b class="ho">22</b><b>:</b><b class="min">22</b><b>:</b><b class="sec">22</b>
				</div>
				</div>
			  <!--end calculator -->
              </div>
              <div class="row">
                
              </div>

          </section>
      <?php $this->load->view("main/drs/footer"); ?>

	  <script>
		$(document).on('click', '.icon-ok-sign', function(){
     $data_id = $(this).parent().parent().attr("data_id");
		  $.post("<?php echo base_url(); ?>panel/nobatdehi_status_controls",{id:$data_id,type:"done"},function(e){
			 var $array = JSON.parse(e);
			 $count = 2;
			 $html = "";
			 $htmlf = ""
			 $counter = 1;
			for(i=0;i<$array.length;i++){
			  if ($array[i]["visit_status"] != 3) {
				if($array[i]["visit_status"] == 0 && $counter == 1) {
					$htmlf += '<tr class="first" data_id="'+$array[i]["id"] +'">'
                    $htmlf += '<td>'+$counter +'</td>';
                    $htmlf += '<td>'+ $array[i]["po_name"] +'</td>';
                    $htmlf +=  '<td><i class="icon-ok-sign" aria-hidden="true"></i></td>';
                    $htmlf +=  '<td><span><img src="<?php echo base_url(); ?>assets/main/img/Folder.png"></span><span><img src="<?php echo base_url(); ?>assets/main/img/List01.png"></span>';
                    $htmlf +=  '</td></tr>';
					$counter++;
				}else if($array[i]["visit_status"] == 1){
				   $html += '<tr style="background:#eee;" data_id="'+ $array[i]["id"] +'" >';
                   $html +=  '<td>'+$count+'</td>';
                   $html +=  '<td>' + $array[i]["po_name"] + '</td>';
                   $html +=   '<td><i class="icon-minus-sign" aria-hidden="true"></i>';
				   $html +=	 ' <span class="iconpause" data_type="play" ><i class="icon-play" style="color: #999 !important;"  aria-hidden="true"></i></span>'
                   $html +=   '</td><td><img src="<?php echo base_url(); ?>assets/main/img/Folder.png"><img src="<?php echo base_url(); ?>assets/main/img/List01.png">'
                   $html +=    '</td></tr>';
				   $count++;
				}else if($array[i]["visit_status"] == 0){
				  $html += '<tr data_id="'+$array[i]["id"]+'">';
                  $html +=  '<td>'+ $count +'</td>';
                  $html +=   '<td>'+ $array[i]["po_name"] +'</td>';
                  $html +=   '<td><i class="icon-minus-sign" aria-hidden="true"></i>';
				  $html +=	 ' <span class="iconpause" data_type="pause" ><i class="icon-pause" style="color: #999 !important;"  aria-hidden="true"></i></span>';
                  $html +=   '</td><td><img src="<?php echo base_url(); ?>assets/main/img/Folder.png"><img src="<?php echo base_url(); ?>assets/main/img/List01.png">';
                  $html +=   '</td></tr>';
				  $count++;
				}
				
			  }
			}
			$html = $htmlf + $html;
			$(".nobats tbody").html($html);
			});
});
		
		$(".personal-task tr").click(function(){
		  var $tellid = $(this).attr("data_tellid");
		  var $name = $(this).find("td").eq(1).text();
		  var $text = $(this).find("input").val();
		  $("#tellid").val($tellid);
		  $(".nameho").text($name);
		  $(".textho").text($text);
		  $(".send_message").css({"display":"block"});
		  });
		 $(".send_mess").click(function(){
		  $message = $(".message").val();
		  $tellid = $("#tellid").val();
		  $.post("<?php echo base_url(); ?>/panel/send_message",{message:$message,tellid:$tellid},function(e){
			if (e == "done") {
				
				 $(".succmessage").css({"display":"block"});
				 $(".message").val("");
			}
			});
		  });
		$(".close").click(function(){
			  $(".add_pationt").css({"display":"none"});
			  $(".setting").css({"display":"none"});
			  $(".send_message").css({"display":"none"});
			  });
		$(document).ready(function(){

		$(".set_calender").click(function(){
		  $date = $(".add_pationt").attr("data_date");
		  $name = $("#exampleInputEmail1").val();
		  $time = $("#exampleInputEmail2").val();
		  
		 $.post("<?php echo base_url(); ?>panel/set_appointment_control_ajax",{date:$date,time:$time,name:$name},function(e){
			if (e == "done") {
				$(".add_pationt").css({"display":"none"});
				$("#exampleInputEmail1").val("");
				$("#exampleInputEmail2").val("");
				 location.reload();
			}
			
			});
		  });
		$("#ajaxupdate").click(function(){
		  
		  });
		$(".set_fromtelegram").click(function(){
		  $message = $(".setting textarea").val();
		  $time = $(".setting input").val();
		  $date = $("#hidden_date").val();
		  $status = $(".setting select").val();
		  $id = $("#hidden_id").val();
		  $.post("<?php echo base_url(); ?>panel/control_robat_program" ,{id:$id,message:$message,time:$time,date:$date,status:$status},function(e){
			if (e == "done") {
				$(".setting").css({"display":"none"});
			}
			});
		  });
		$(document).on("click",".iconpause",function(){
		  if ($(this).attr("data_type") == "pause") {
		$(this).parent().parent().find(".iconpause i").removeClass("icon-pause");
		 $(this).parent().parent().find(".iconpause i").addClass("icon-play");
		 $(".iconpause i").css({"background":"#0f0 !important"});
		 $(this).attr({"data_type":"play"});
		 $(this).parent().parent().css({"background":"#eee"});
		 $type = "resume";
		  }else{
			$(this).parent().parent().find(".iconpause i").addClass("icon-pause");
		 $(this).parent().parent().find(".iconpause i").removeClass("icon-play");
		 $(this).attr({"data_type":"pause"});
		 $(this).parent().parent().css({"background":"#fff"});
		 $type="play";
		  }
		  $id = $(this).parent().parent().attr("data_id");
		 
		$.post("<?php echo base_url(); ?>panel/nobatdehi_status_controls",{id:$id,type:$type},function(e){
		  });
		  });
		  });
		
		
	  
	  </script>
	  <script>
		window.onload = function() {
		$(".search_holder button").click(function(){
			var $value = $(this).parent().find("input").val();
			window.location = "<?php echo base_url(); ?>panel/list_Patient?search="+$value;
			});
		$(".search_holder input").keypress(function(e){
			if(e.keyCode == 13){
				$(".search_holder button").click();
			}
			});
		 
		  setInterval(function(){ 
	  $.post("<?php echo base_url(); ?>panel/checkajaxnobat",{"nobat_count":"<?php echo $nobat_count; ?>"},function(e){
		if (e == "update") {
			location.reload();
		}
		  }); 
		  },25000);
		}
			
	  </script>
