<?php 
session_start();
include("header.php");
include("conn.php");
error_reporting(0);
function curPageName() 
{
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
?>


    </div><!--/breadcrumbs-->
    <div class="purchase">
        <div class="container">
            <div class="row">
              <div class="col-md-9 animated fadeInLeft">
                    
                    <form name="current_reviews" action="" method="get">
               
                <div class="row">
 <p style="color: #00F;font-family: Calibri,Geneva,sans-serif;font-size: 16px;width: 290px;text-align: center;margin-left: auto;margin-right: auto;"><?php if(isset($_SESSION['msg']))
 {
echo $_SESSION['msg'];
 }?></p>
                        <div class="col-sm-6">
                        
                     <label><a href="#" onclick="window.location='child-center-reviews.php'" style="color:#00F;"><button class="btn-u"  <?php if(curPageName()!="child-center-reviews.php")
 {?> style="margin-top:26px;background:#CCC !important;"<?php } else {?> style="background:#72c02c !important;margin-top:26px;" <?php }?> type="button" name="search_form" id="search_form">Read Reviews</button></a></label>
                     <label><a href="#" onclick="window.location='write-center-reviews.php'"  style="color:#00F;"><button class="btn-u" <?php if(curPageName()!="write-center-reviews.php")
 {?> style="margin-top:26px;background:#CCC !important;"<?php } else {?> style="background:#72c02c !important;margin-top:26px;" <?php }?>  type="button" name="search_form" id="search_form">Write Reviews</button></a></label>
<input type="text"   name="tag"   id="tag" Placeholder="Search for center you'd like to review" style="width: 368px;
margin-top: 8px;" class="form-control margin-bottom-20" >
</div>
                  
                        <div class="col-sm-6">
                    
<input type="text"   name="zipcode"  id="zipcode" Placeholder="Zipcode"  style="width: 126px;margin-top: 73px;margin-left: -57px;" class="form-control margin-bottom-20"  />
                       
                    <!-- <select name="zipcode" id="zipcode" style="width: 126px;
margin-top: 74px;
margin-left: -57px;" class="form-control margin-bottom-20" >
                        <?php
						$sel_zipcode=mysql_query("select DISTINCT ZipCode from information");
						while($fetch_zipcode=mysql_fetch_array($sel_zipcode))
						{
						?>
                    <option value="<?php echo $fetch_zipcode['ZipCode'];?>" <?php if($_GET['zipcode']==$fetch_zipcode['ZipCode']) {?> selected="selected" <?php }?>><?php echo $fetch_zipcode['ZipCode'];?></option>
                    <?php }?>
                    </select>-->
                    </div>
                    <button class="btn-u"  style="margin-top: -54px;margin-left: 535px;float: left;" type="submit" name="search_form" id="search_form">Search</button>
                    
                     <div class="col-sm-6">
                     
                    <span style="font-size: 12px;width: 10%;float: right;margin-bottom: -32px;margin-right: -57px;"> Sort By</span> <select name="sortby" id="sortby" style="width: 35%;
margin-left: 474px;height: 27px;font-size: 11px;" onchange="this.form.submit()" class="form-control margin-bottom-20" >
                     
                   <option value="Newest to Oldest" <?php if($_GET['sortby']=='Newest to Oldest') {?> selected="selected" <?php }?>>Newest to Oldest</option>
                   <option value="Oldest to Newest" <?php if($_GET['sortby']=='Oldest to Newest') {?> selected="selected" <?php }?>>Oldest to Newes</option>
                   <option value="Highest to Lowest" <?php if($_GET['sortby']=='Highest to Lowest') {?> selected="selected" <?php }?> >Highest to Lowest</option>
                   <option value="Lowest to Highest" <?php if($_GET['sortby']=='Lowest to Highest') {?> selected="selected" <?php }?>>Lowest to Highest</option>
                    </select>
                  
                             
                    </div>
                    
                  
                  </div>
                  
                  </form>
                   <table width="622">
 <?php
//search code by name and by zipcode
$orderby='Count Desc';
if($_GET['sortby']=='Newest to Oldest')
{
$orderby='date Desc';	
}
if($_GET['sortby']=='Newest to Oldest')
{
$orderby='date Asc';	
}
if($_GET['sortby']=='Highest to Lowest')
{
$orderby='Count Desc';	
}
if($_GET['sortby']=='Lowest to Highest')
{
$orderby='Count Asc';	
}

 if(isset($_GET['search_form'])!='' && $_GET['tag']!='')
 {

$sql = "SELECT count(id) FROM information where Name LIKE '%".$_GET['tag']."%' ORDER BY $orderby";  
 }
 else if(isset($_GET['search_form'])!='' && $_GET['zipcode']!='')
 {	
$sql = "SELECT count(id) FROM information where Zipcode='".$_GET['zipcode']."' ORDER BY $orderby";  
 }
 
 else
 {
$sql = "SELECT count(id) FROM information"; 
 }
$rec_limit =20;
$retval = mysql_query($sql);
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
//code to reterive information
 if(isset($_GET['search_form'])!='' && $_GET['tag']!='')
 {
 $query1="select * from information  where Name LIKE '%".$_GET['tag']."%' ORDER BY $orderby LIMIT $offset, $rec_limit ";
 }
 elseif(isset($_GET['search_form'])!='' && $_GET['zipcode']!='')
 {
	  $query1="select * from information  where Zipcode ='".$_GET['zipcode']."' ORDER BY $orderby LIMIT $offset, $rec_limit ";
 }
 else
 {
 //$query1="select * from information  where Name LIKE '%".$_GET['tag']."%' OR ZipCode='".$_GET['zipcode']."' ORDER BY $orderby LIMIT $offset, $rec_limit ";
  $query1="select * from information ORDER BY $orderby LIMIT $offset, $rec_limit"; 
 }
					 $get_reviews=mysql_query($query1);
					 while($fech_reviews=mysql_fetch_array($get_reviews))
					 {?>
                     <tr style="border-bottom:1px solid gray;">
                       <?php
if($fech_reviews['image']!='' &&  $fech_reviews['video']=='')
{?>
<td width="114" height="93"><a id="dialog-link" class="fancybox ui-state-default ui-corner-all"  href="#inline1"><img src="<?php echo $fech_reviews['image'];?>" style="width: 100px;
height: 80px;;"></a></td>
<div id="inline1" class="box" style="display:none;">
<img src="<?php echo $fech_reviews['image'];?>" >
</div>
<?php }?>

<?php
if($fech_reviews['image']=='' &&  $fech_reviews['video']!='')
{?>
<td width="114" height="93"><a  class="fancybox ui-state-default ui-corner-all"  href="#inline2"><img src="<?php echo $fech_reviews['video_thumbil'];?>" style="width: 100px;
height: 80px;;"></a></td>
             <div id="inline2" class="box" style="display:none;">
<iframe src="<?php echo $fech_reviews['video'];?>" width="530" height="300" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> 
</div>
<?php }?>


<?php
if($fech_reviews['image']!='' &&  $fech_reviews['video']!='')
{?>
<td width="114" height="93"><a class="fancybox ui-state-default ui-corner-all"  href="#inline3"><img src="<?php echo $fech_reviews['image'];?>" style="width: 100px;height: 80px;;"></a>

<div id="inline3" class="box" style="display:none;">
<img src="<?php echo $fech_reviews['image'];?>" >
<iframe src="<?php echo $fech_reviews['video'];?>" width="530" height="300" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> 
</div>
</td>
<?php }?>
<?php
if($fech_reviews['image']=='' &&  $fech_reviews['video']=='')
{?>
<td width="114" height="93"><img src="assets/img/nomedia.jpg" style="width: 100px;height: 80px;;"></td>
<?php }?>
                       <td width="234"><?php echo $fech_reviews['Name'].'<br>'.$fech_reviews['Address1'].'<br>';?>
                     
                      <a class="fancybox fancybox.iframe" href="viewschool.php?&id=<?php  echo $fech_reviews['id'];?>">More info</a>  
                       </td>
                       <td width="58">
                       
					   <?php
					    $query_sql_count_reviews_grade="select * from reviews where school_id='".$fech_reviews['id']."' AND status='1'";
					   $query_grade=mysql_query($query_sql_count_reviews_grade);
					   if(mysql_num_rows($query_grade)==100)
					   {
						echo "A";   
					   }
					   if(mysql_num_rows($query_grade)==80)
					   {
						echo "B";   
					   }
					   if(mysql_num_rows($query_grade)==60)
					   {
						echo "c";   
					   }
					   if(mysql_num_rows($query_grade)==40)
					   {
						echo "D";   
					   }
					   if(mysql_num_rows($query_grade)==20)
					   {
						echo "E";   
					   }
					   if(mysql_num_rows($query_grade)==0 || mysql_num_rows($query_grade)==10 || mysql_num_rows($query_grade)< 10)
					   {
						echo "F";   
					   }
					   ?>
                       </br> GRADE
                       </td>
                       <td width="81"><a href="reviews-list.php?&school_id=<?php  echo $fech_reviews['id'];?>"> <?php 
					   //code for count reviews
					   $query_sql_count_reviews="select * from reviews where school_id='".$fech_reviews['id']."' AND status='1'";
					   $query_sql=mysql_query($query_sql_count_reviews);
					   echo  mysql_num_rows($query_sql);
					   ?></br>REVIEW</a></td>
                       <td width="111"><button class="btn-u" onclick="window.location='reviews-list.php?&school_id=<?php  echo $fech_reviews['id'];?>'"  type="button" name="signup_form" id="signup_form">Read a review</button></td>
                     </tr>
                     <tr>
                     <?php }?>
                       <td height="28">&nbsp;</td>
                       <td><?php
		 
		  
		   if($page > 0)
{
   $last = $page - 2;
   echo "<a  href=\"child-center-reviews.php?page=$last\" style='font-family:Verdana, Geneva, sans-serif;font-weight:bold;color:#000;'>Last</a> | ";
   echo "<a href=\"child-center-reviews.php?page=$page\"  style='font-family:Verdana, Geneva, sans-serif;font-weight:bold;color:#000;'>Next</a> Page $page of $rec_limit";
}
else if($rec_count<$rec_limit)
{
echo 'Number Of Records:'.' '.$left_rec	;
}
else if($page == 0)
{
   echo "<a href=\"child-center-reviews.php?page=$page\"  style='font-family:Verdana, Geneva, sans-serif;font-weight:bold;color:#000'>Next</a> Page $page of $rec_limit";
}
else if( $left_rec < $rec_limit)
{
   $last = $page - 2;
   echo "<a href=\"child-center-reviews.php?page=$last\"  style='font-family:Verdana, Geneva, sans-serif;font-weight:bold;color:#000'>Last</a> Page $page of $rec_limit";

}
?></td>
                       <td>&nbsp;</td>
                       <td>&nbsp;</td>
                       <td>&nbsp;</td>
                     </tr>
                    
                   </table>
      
                   
                   <p>&nbsp;</p>
              </div>           
                
                <?php
				include("leftbar.php");
				?>
            </div>
        </div>
    </div>
        
    <!--=== End Content Part ===-->

    <!--=== Parallax About Block ===-->
          
    <!--=== End Parallax About Block ===-->

    <!--=== Container Part ===-->
    <!--/container-->
    <!--=== Container Part ===-->

    <!--=== Meet Our Team ===-->
        
    <!--=== End Meet Our Team ===-->

    <!--=== Contact Us ===-->
    
    <!--=== Contact Us ===-->

    <!--=== Footer ===-->
    <!--/footer-->
    <!--=== End Footer ===-->

    <!--=== Copyright ===-->
    <?php
	include("footer.php");
		unset($_SESSION['msg']);
	?>
    
    <!--/copyright--> 
    <!--=== End Copyright ===-->
</div><!--/End Wrapepr-->

<!-- JS Global Compulsory -->           
<script type="text/javascript" src="assets/plugins/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script> 
<!-- JS Implementing Plugins -->
<script type="text/javascript" src="assets/plugins/back-to-top.js"></script>
<script type="text/javascript" src="assets/plugins/jquery.parallax.js"></script>
<script type="text/javascript" src="assets/plugins/owl-carousel/owl-carousel/owl.carousel.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="assets/plugins/gmap/gmap.js"></script>
<!-- JS Page Level -->           
<script type="text/javascript" src="assets/js/app.js"></script>
<script type="text/javascript" src="assets/js/pages/page_contacts.js"></script>
<script type="text/javascript" src="assets/js/plugins/owl-carousel.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {
        App.init();
        App.initParallaxBg();
        ContactPage.initMap();        
        OwlCarousel.initOwlCarousel();                              
    });
</script>
<!--[if lt IE 9]>
    <script src="assets/plugins/respond.js"></script>
    <script src="assets/plugins/html5shiv.js"></script>
<![endif]-->

</body>
</html> 