

<?php 

  
  //added id
    //for display blog

      $id="";
      if(isset($_GET['blogid'])){
        $id=$_GET['blogid'];
        include('module/blog.php');
      }
    //if not get id, show blog category
    //else show blog detail
  if(!isset($_GET['blogid'])){

     //ended id
    //cat id
      $hcat_id="";
      if(isset($_GET['hcat_id'])){
        $hcat_id=$_GET['hcat_id'];
      }
     //ended catid
      $uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
      $request_uri = $uri_parts[0];


$alignedId=array(10=>"massage",21=>"ganbanyoku" ,32=>"massage-shatin", 11=>"skin-care", 26=>"ear-candling",27=>"eye-treatment",28=>"organic",29=>"skin-treatment",30=>"detoxification",31=>"hot-stone",33=>"skin-scraping",34=>"skin-massage",35=>"facial",14=>"ganbanyoku-spa",36=>"ganbanyoku-review",39=>"skin-doctor",23=>"amigo-ganbanyoku",12=>"lai-chi-kok",13=>"ganbanyoku-contact", 41=>"ganbanyoku-shatin", 44=>"tsim-sha-tsui", 1=>"About-us");


// $sql_submenu = mysql_query('SELECT * FROM `album` WHERE `ep_web` = '.$sect_id.' AND `show` = 1  ORDER BY `rank` ASC')or die(mysql_error());
$sql_submenu = mysql_query('SELECT * FROM `nchmcblog_cat` WHERE `show` = 1  ORDER BY `rank` ASC')or die(mysql_error());
// $sql_submenu = mysql_query('SELECT * FROM `album` WHERE `ep_web` = '.$sect_id.' AND `show` = 1  ORDER BY `rank` DESC')or die(mysql_error());
// $row_submenu = mysql_fetch_assoc($sql_submenu);
$num_row = mysql_num_rows($sql_submenu);

if ($id){
  $sql_content = mysql_query('SELECT * FROM `album` WHERE `ep_id` = '.$id.' AND `show` = 1') or die(mysql_error());
} else {
  $sql_content = mysql_query('SELECT * FROM `album` WHERE `ep_web` = '.$sect_id.' AND `show` = 1 ORDER BY `rank` ASC LIMIT 0, 1 ') or die(mysql_error());
}
// $row_content = mysql_fetch_assoc($sql_content);

//added to add photo list
$countcat=0;
$cateList=array();
while ($row_submenu = mysql_fetch_assoc($sql_submenu)){
  $cat=$row_submenu['cat_id'];
  array_push($cateList, $cat);
  $countcat=$countcat+1;
}

//end added to add photo list

//category name added at 2019-10-10
function categoryName($id){
  global $global_lang;
  $sql = mysql_query('SELECT * FROM `nchmcblog_cat` WHERE `cat_id` = '.$id);
  $row = mysql_fetch_assoc($sql);
  if($global_lang=="tc"){
    return $row['cp_cat_name'];
  }

   if($global_lang=="sc"){
  return $row['sp_cat_name'];
  }
}
//end category name
?>


  <!-- Masthead -->
  <header style="position: relative;
    background-color: #343a40;
    background: url(../img/nchmcbanner.png) no-repeat center center;
    background-size: cover;">
    <div style="height: 320px">
    </div>
  </header>
   


  <!-- new content row -->
  <div class="container ">
  <div class="row">
     <?php

      if($countcat!=1){
            //for more category
     ?> 
     <div class="col-md-3 " style="padding-left: 0px!important;padding-right: 0px!important;text-align: left;" >  
         <style>
          /*#link_bar li:hover a { color: red }*/
          /*#link_bar li:hover  a p b { color: #a03d49; }*/
          .sidemenu2:hover  { background-color: #bd6974!important; }
          /*#link_bar li:hover  { border-top:2px solid #a03d49; }*/

           /*#link_bar li { border-top:2px solid transparent;cursor: pointer; }*/
 /*          #link_bar li { border-top:2px solid transparent; }
          #link_bar li:hover  { border-top:2px solid #a03d49; }*/

         
      </style>
      <?php

        foreach ($cateList as  $catid) {

          if(empty($hcat_id)){
                //set the first catid
                $hcat_id=$catid;
          }
      ?>

        <a href="<?php echo $request_uri."?section=Knowledge"."&hcat_id=".$catid;?>"  style="text-decoration: none"> 
        <!-- <a href="<?php echo $current_path."&hcat_id=".$catid;?>"  style="text-decoration: none">  -->
            <div style="width: 250px;height: 50px;background-color: #<?php if($hcat_id == $catid || empty($hcat_id)){ echo 'bd6974';}else{ echo 'a73745';}?>;margin-bottom: 1px;text-align: center;vertical-align: middle;display: block; " class="sidemenu2"> 
               <p style="line-height: 50px;color: #ffffff;"><b>
                <?php echo categoryName($catid);?>
                </b></p>
            </div>
        </a>
      <?php
        }//foreach ($cateList as  $catid) {
      ?>
     </div> 
     <?php 
           }//if($countcat!=1){
     ?>  

      <?php

      if($countcat!=1){
                //for more category
     ?> 
    <div class="col-md-9 " style="padding-left: 0px!important;padding-right: 0px!important;text-align: center;" > 

      <?php

       }

       ?>
       <?php

      if($countcat==1){
            //for only one category

        foreach ($cateList as  $catid) {

          if(empty($hcat_id)){
                //set the first catid
                $hcat_id=$catid;
          }
        }
     ?> 
        <div class="col-md-12 " style="padding-left: 0px!important;padding-right: 0px!important;text-align: center;" > 

      <?php

       }

       ?>
      <!-- content -->
          <div style="display: block;width: 100%;text-align: left;">
              <!-- <p><span style="color:#2c2c2c;">首頁 > </span><span style="color:#a73745; ">診所環境</span></p> -->
              <?php 
              if($global_lang=="tc"){
               ?>
                    <p><span style="color:#2c2c2c;">首頁 > </span><span style="color:#a73745; ">兒科知識</span></p>
              <?php     
                  }
              ?>
               <?php 
                  if($global_lang=="sc"){
               ?>
                    <p><span style="color:#2c2c2c;">首页 > </span><span style="color:#a73745; ">儿科知识</span></p>
              <?php     
                  }
              ?>
          </div>
         
          
          <!-- list first category -->
          <?php 
          // foreach ($cateList as  $catid) {
            echo '<h4 style="color:#a73745; ">'.categoryName($hcat_id).'</h4>';
          ?>


             

       
            <!-- get blog detail -->
            <?php
            // $sql = mysql_query('SELECT * FROM `nchmcblog_cat` WHERE `cat_id` = '.$id);
              $sql = mysql_query('SELECT * FROM `nchmcblog` WHERE `ep_web` = '.$hcat_id.' ORDER BY `ep_date` DESC, `last_update` DESC');

              //for count number of item
              $itemTotal=mysql_num_rows($sql);
               $currentPage = $_GET["page"];
              if(!isset($_GET["page"])){
                      $currentPage =0;
              }
              $itemsPerPage = 2;
              $lastPage = ceil($itemTotal/$itemsPerPage); //+1, because you round up to whole pages
              $startItem = $currentPage * $itemsPerPage;

              //end for count number of item

              // $row = mysql_fetch_assoc($sql);
              $countProduct=0;

              // echo "countProduct";
              // echo $countProduct;
              // echo "startItem";
              // echo $startItem;
              // echo "itemsPerPage";
              // echo $itemsPerPage;

              $printedProduct=1;
              while ($row = mysql_fetch_assoc($sql)){

                if($countProduct>=$startItem && $printedProduct<=$itemsPerPage){
                    $printedProduct=$printedProduct+1;
                  
              if($global_lang=="tc"){
                $id=$row['news_id'];
                $subject=$row['cp_subject'];
                $pic=$row['ep_pic'];
                $brief=$row['cp_brief'];
              }
              if($global_lang=="sc"){
                $id=$row['news_id'];
                $subject=$row['sp_subject'];
                $pic=$row['ep_pic'];
                $brief=$row['sp_brief'];
              }

            ?>

              <div style="height: 60px ;position: relative;width:100%">
          <!-- place horizontal line -->
     <!--      <span style="width:10000px;height: 1px;background: #dddddd;position: absolute;display: inline-block;left: 50%;margin-left: -190px;top: 0px;margin-top: 30px;" ></span> -->
        <span style="width:100%;height: 1px;background: #dddddd;display: inline-block;top: 0px;margin-top: 30px;" ></span>
        </div>  


             <div class="container ">
              <a href="<?php  echo $request_uri.'?section=Knowledge'.'&hcat_id='.$hcat_id.'&page='.$currentPage.'&blogid='.$id;?>" style="text-decoration: none;display: inline-block;width: 100%;height: 100%;color: #000000!important;">
              <div class="row" style="cursor: pointer;">
              
              <div class="col-md-3 " style="padding-left: 0px!important;padding-right: 0px!important;text-align: center;" >
              <!-- <a href="<?php echo $current_path."&id=".$id;?>">  -->
              <!-- photo -->
              <img class="img-responsive" src="..\upload\blog_images\<?php echo $pic;?>" style="width: auto;
height: auto;
max-width: 100%;
max-height: 100%;" >
              <!-- end photo -->
               <!-- </a> -->
            </div>
            <div class="col-md-9 " style="padding-left: 35px!important;padding-right: 35px!important;padding-top:25px;text-align: left;background-color: #f5f5f5;" >
               
              <!-- <a href="<?php echo $current_path.'&id='.$id;?>" style="text-decoration: none;display: inline-block;width: 100%;height: 100%;color: #000000!important;">  -->
                <h5 style="color:#a73745; "><?php echo $subject;?></h5>
                <p style="margin-top: 20px;text-decoration: none;"><?php echo $brief;?>...<span style="color:#a73745; ">( 閱讀更多 )</span></p>
              
             </div> 
            
             </div>
             </a> 
            </div>  
            <?php
                }//if($countProduct>=$startItem){
                $countProduct=$countProduct+1;
              }//while ($row = mysql_fetch_assoc($sql)){
            ?>
            <!-- end  get blog detail -->
              
        <?php 
          // }//foreach ($cateList as  $catid) {

          ?>
          <!-- end list first category -->
           
           <!-- page control -->
           <div style="display: inline-block;text-align: center;width: 100%;">
                <style>
                  .pagebutton {
                    text-decoration: none;
                    display: inline-block;
                    padding: 8px 16px;
                  }

                  /*.pagebutton:hover {
                    background-color: #ddd!important;
                    color: black!important;
                  }*/

                  .previous {
                    background-color: #f1f1f1!important;
                    color: black!important;
                  }

                  .next {
                    /*background-color: #4CAF50!important;*/
                    /*background-color: #5dab81!important;*/
                    background-color: #a73745!important;
                    color: white!important;
                  }

                  .round {
                    border-radius: 50%;
                  }

          /*#link_bar li:hover a { color: red }*/
          /*#link_bar li:hover  a p b { color: #a03d49; }*/
          .next:hover  { background-color: #bd6974!important; }
          /*#link_bar li:hover  { border-top:2px solid #a03d49; }*/

           /*#link_bar li { border-top:2px solid transparent;cursor: pointer; }*/
 /*          #link_bar li { border-top:2px solid transparent; }
          #link_bar li:hover  { border-top:2px solid #a03d49; }*/

         
      
                  </style>
                  <!-- page control -->
                  <div style="text-align: center;width: 100%;margin-top:20px;">
                    <!-- <a href='<?php echo $current_path."&page=0";?>' style="" class="pagebutton next">&lt;</a> -->

                    <a href='<?php echo $request_uri."?section=Knowledge"."&hcat_id=".$hcat_id."&page=0";?>' style="text-decoration: none" class="pagebutton next">&lt;</a>
                   <?php 
                   // echo $lastPage;
                   for ($i=0; $i <=$lastPage-1 ; $i++) { 
                     # code...
                    
                    ?>  

                    <!-- <a href='./listgrid.php?cat=<{$selectedCat}>&page=<{$foo}>&orderby=<{$orderby}>' class="pagebutton next"> <?php echo $i+1; ?></a> -->
                    <!-- <a href='<?php echo $current_path."&page=".($i);?>' class="pagebutton next"> <?php echo $i+1; ?></a> -->
                    <a href='<?php echo $request_uri."?section=Knowledge"."&hcat_id=".$hcat_id."&page=".($i);?>' class="pagebutton next" style="text-decoration: none"> <?php echo $i+1; ?></a>
                    <?php

                      }//for ($i=0; $i <$lastPage-1 ; $i++) {
                    ?>
                    <!-- <a href='./listgrid.php?cat=<{$selectedCat}>&page=<{$lastPage-1}>&orderby=<{$orderby}>' class="pagebutton next">&gt;</a> -->
                    <!-- <a href='<?php echo $current_path."&page=".($lastPage-1);?>' class="pagebutton next">&gt;</a> -->
                    <a href='<?php echo $request_uri."?section=Knowledge"."&hcat_id=".$hcat_id."&page=".($lastPage-1);?>' class="pagebutton next" style="text-decoration: none">&gt;</a>
                  </div>

            </div> 
           <!-- end page control -->

 


        <!--    <div style="height: 60px ;position: relative;width:100%" onclick="myFunction('row1')">
          <p>1</p>
        </div> -->
     <!--    <div id="row1">
          This is my DIV element.
        </div> -->
      <!-- end content -->
    </div>
  </div>
</div>

<?php
   }//if(!isset($_GET['id'])){
?>
  <!-- end new content row -->



  
  

  
