<main>
  <div class="container-fluid">
<div class="row align-items-center justify-content-between pt-2">
        <div class="col-12 text-end mb-2">
          <a href="?op=t1_h_tab&op2=tree" class="btn btn-xs btn-color-red mt-1">tree</a> 
          <a href="?op=t1_h_tab&op2=save_html" class="btn btn-xs btn-color-pink mt-1">save html</a>
          <?php 
          $sql1 = "select * from t1_h_tab where del=0 order by page_type,name";
          $res1 = mysqli_query($db, $sql1);
          while($r1 = mysqli_fetch_assoc($res1)) {
            ?>
            <a href="?op=t1_h_tab&op2=edit&id=<?=$r1['id'];?>" class="btn btn-xs cl-do7 mt-1"><?=$r1['name'];?></a>
            <?php
          }  
          ?>
        </div>
    </div>
  <?php
  switch($op2) {

      case "tree";
          tree();
        break;
      case "save_html";
          save_html();
        break;

      case "php_save";          
        file_put_contents($_POST['file_name'], $_POST['content']);
        edit($_POST['id']);
        break;

      case "edit";
        edit($_GET['id']);
        break;
      case "copy";
        $sql4 = "select id from `t1_h_tab` order by id desc limit 1";
        $res4 = mysqli_query($db, $sql4);
        $rw4 = mysqli_fetch_assoc($res4);
        $id2=$rw4['id']+1;

        $sql3 = "select * from `t1_h_tab` where id=".$_GET['id'];
        $res3 = mysqli_query($db, $sql3);
        $r3 = mysqli_fetch_assoc($res3);
        $idt=array(
          'id'=>$id2,
          'path'=>$r3['path'],
          'page_type'=>$r3['page_type'],
          'path_right'=>$r3['path_right'],
          'title_right'=>$r3['title_right'],
          'name'=>$r3['name']."-",
          'title'=>$r3['title'],
          'seq'=>$id2,
          'icon'=>$r3['icon'],
          'content_id'=>$r3['content_id'],
          'level'=>$r3['level'],
          'parent'=>$r3['parent'],
          'update_at'=>time(),
        );
        Insert($db,"t1_h_tab",$idt,0);
        edit($id2);
        break;
      case "edit2";
        $beautify = new Beautify_Html(array(
          'indent_inner_html' => false,
          'indent_char' => " ",
          'indent_size' => 2,
          'wrap_line_length' => 32786,
          'unformatted' => ['code', 'pre'],
          'preserve_newlines' => false,
          'max_preserve_newlines' => 32786,
          'indent_scripts'  => 'normal', // keep|separate|normal
        ));
        //$text2=$beautify->beautify($text);


        //echo "<pre>"; print_r($_POST); echo "</pre>";
        $udt=array(
          'path'=>trim($_POST['path']),
          'path_right'=>$_POST['path_right'],
          'title_right'=>$_POST['title_right'],
          'icon_right'=>$_POST['icon_right'],
          'name'=>$_POST['name'],
          'title'=>$_POST['title'],
          'icon'=>$_POST['icon'],
          'level'=>$_POST['level'],
          'is_active'=>$_POST['is_active'],
          'custom'=>gpc(trim($beautify->beautify($_POST['custom']))),
          //'body'=>gpc(trim($_POST['body'])),
          'update_at'=>time(),
        );
        if(isset($_POST['content_id'])) {
          $udt['content_id']=$_POST['content_id'];
        } else {
          $udt['content_id']=0;          
        }
        if(isset($_POST['view_title'])) {
          $udt['view_title']=$_POST['view_title'];
        } else {
          $udt['view_title']=0;          
        }
        if(isset($_POST['view_navbar'])) {
          $udt['view_navbar']=$_POST['view_navbar'];
        } else {
          $udt['view_navbar']=0;          
        }
        if(isset($_POST['view_left_panel'])) {
          $udt['view_left_panel']=$_POST['view_left_panel'];
        } else {
          $udt['view_left_panel']=0;          
        }
        if(isset($_POST['searchbar'])) {
          $udt['searchbar']=$_POST['searchbar'];
        } else {
          $udt['searchbar']=0;          
        }
        Update($db,"t1_h_tab",$udt,"id=".$_POST['id'],0);

        $_POST['path_parent']=getPerent($_POST['parent']);
        gen_htm_page($_POST);
        edit($_POST['id']);
        save_html();
        break;
       case "del";
        Delete($db,"t1_h_tab","id=".$_GET['id'],0);
        //edit($_GET['id']);
  
      case "list";
        list_scriptext($q,$col,$q2,$col2,$q3,$col3);
      default;
    }                    
  ?>          
  </div>
</main>
<?php
function list_scriptext($q,$col,$q2,$col2,$q3,$col3) {
  global $db,$ar;
  //print_r($ar);
  ?>  
  <table class="table table-bordered" id="dataTable_13d" width="100%" cellspacing="0">
      <thead>
          <tr>
              <th>ID</th>
              <th>path</th>
              <th>name</th>
              <th>icon</th>
              <th>title</th>
              <th>lev</th>
              <th>type</th>
              <th>parent</th>
              <th>seq</th>
              <th>active</th>
              <th>r_link</th>
              <th>r_ico</th>
              <th>pType</th>
              <th>parent</th>
              <th>udate</th>
              <th>Menu</th>
          </tr>
      </thead>

      <tbody>
      <?php
      $sql = "select * from t1_h_tab where del=0 ";

      if($col!='') {
        $sql .= " and ".$col."='".$q."' ";
      }
      
      if($col2!='') {
        $sql .= " and ".$col2."='".$q2."' ";
      }

      if($col3!='') {
        $sql .= " and ".$col3."='".$q3."' ";
      }      
      
      //$sql .= " and st=1";
      $res = mysqli_query($db, $sql);
      //echo $sql;

      while($rw = mysqli_fetch_assoc($res)) {  
      ?>
      
          <tr>
              <td><?=$rw['id'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'path','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['path'];?></td>
              <td><?=$rw['name'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'icon','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['icon'];?></td>
              <td><?=$rw['title'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'level','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['level'];?></td>              
              <td contenteditable="true" onBlur="colUpdate(this,'page_type','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['page_type'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'parent','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['parent'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'seq','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['seq'];?></td>
              <td contenteditable="true" onBlur="colUpdate(this,'is_active','<?=$rw['id'];?>','t1_h_tab')" onClick="editRow(this);"><?=$rw['is_active'];?></td>               
              <td><?=$rw['path_right'];?></td>
              <td><?=$rw['icon_right'];?></td>
              <td><a href="?op=t1_h_tab&op2=list&col=page_type&q=<?=$rw['page_type'];?>"><?=$rw['page_type'];?></a></td>              
              <td><a href="?op=t1_h_tab&op2=list&col=parent&q=<?=$rw['parent'];?>"><?=$rw['parent'];?></a></td>              
              <td class="text-right"><?=date("Y-m-d H:i",$rw['update_at']);?></td>
              <td>
                <a class="btn btn-xs btn-primary" href="?op=t1_h_tab&op2=edit&id=<?=$rw['id'];?>">edit</a> 
                <a href="#" onClick="uCol(<?=$rw['id'];?>,'del',1,'t1_h_tab');" class="btn btn-xs btn-color-red">del</a>                               
              </td>
          </tr>
        <?php
        }
        ?>  
          
      </tbody>
  </table>
  <br><?=$sql;?><br>
  <?php   
}

function getPerent($id) {
  global $db,$ar;
  $sql="SELECT `path`,`name` from t1_h_tab where id=".$id;
  $res=mysqli_query($db,$sql);
  $r1=mysqli_fetch_assoc($res);
  return $r1['path'];
}

function tree() {
  global $ar,$db;
  $sql="SELECT * from t1_h_tab where parent=1 order by page_type,name";
  $res=mysqli_query($db,$sql);
  while($r1=mysqli_fetch_assoc($res)) {
    ?>
    <a href="?op=t1_h_tab&op2=edit&id=<?=$r1['id'];?>"><?=$r1['name'];?></a><br>
    <?php

    $sql2="SELECT * from t1_h_tab where parent=".$r1['id']." order by name";
    $res2=mysqli_query($db,$sql2);
    while($r2=mysqli_fetch_assoc($res2)) {
      ?>
      ---- <a href="?op=t1_h_tab&op2=edit&id=<?=$r2['id'];?>"><?=$r2['name'];?></a><br>
      <?php
        $sql3="SELECT * from t1_h_tab where parent=".$r2['id']." order by name";
        $res3=mysqli_query($db,$sql3);
        while($r3=mysqli_fetch_assoc($res3)) {
          ?>
          ---- ---- <a href="?op=t1_h_tab&op2=edit&id=<?=$r3['id'];?>"><?=$r3['name'];?></a><br>
          <?php
          $sql4="SELECT * from t1_h_tab where parent=".$r3['id']." order by name";
          $res4=mysqli_query($db,$sql4);
          while($r4=mysqli_fetch_assoc($res4)) {
            ?>
            ---- ---- ---- <a href="?op=t1_h_tab&op2=edit&id=<?=$r4['id'];?>"><?=$r4['name'];?></a><br>
            <?php
            
          }      
        }      
    }
  }
}

/*
type 1/level 1
ada left panel
ada navbar
ada menu bawah

type 2/level 2 atau lebih
tanpa menu bawah
ada navbar
ada link back
ada/tanpa right_link

type 3/halaman lepas
- login,register,lupa password,intro
- tanpa menu bawah
- ada right_link
- tanpa menu bawah
- tak ada left panel
- tanpa link back
*/

/*
      if($p['path_right']!='') {
        $text_content .= '
        <div class="right">
          <a href="/'.$p['path_right'].'/" class="link">
          <i class="icon material-symbols-outlined">'.$p['icon_right'].'</i> '.$p['title_right'].'
          </a>
        </div>';
      }

*/

function gen_htm_page($p) {
  global $db,$ar;

  if($p['is_active']==1) {
    $text_content='
    <div id="tab-'.$p['name'].'" class="tab tab-'.$p['name'].' view view-init view-main tab-active">
      <div class="page page-tab_'.$p['name'].'" data-name="tab_'.$p['name'].'">';
  } else {
    $text_content='
    <div id="tab-'.$p['name'].'" class="tab tab-'.$p['name'].' view view-init">
      <div class="page page-tab_'.$p['name'].'" data-name="tab_'.$p['name'].'">';
  }
  if($p['view_navbar']) {
    $text_content.='
  <div class="navbar navbar-large">
      <div class="navbar-bg">
      </div>
      <div class="navbar-inner">
        <div class="left">
          <a href="#" class="link icon-only switch-theme">
            <i class="icon f7-icons">moon_stars</i>
          </a>
        </div>';

    if($p['view_title']==1) {
      $text_content .= '<div class="title">'.$p['title'].'</div>
        <div class="title-large">
          <div class="title-large-text">'.$p['title'].'</div>
        </div>';
    }

    $text_content .='<div class="right">
          <a href="#" class="link icon-only reload_data">
            <i class="icon f7-icons">arrow_2_circlepath_circle_fill</i>
          </a>          
          <a id="signout" class="link icon-only text-color-red logout">
            <i class="icon f7-icons">square_arrow_right
              
            </i>
          </a>
        </div>
      </div>
    </div>';
  }

  if($p['content_id']>0) {      
    $text_content .='<div class="page-content" id="'.$p['name'].'_tab_content">';
  } else {
    $text_content .='<div class="page-content">';
  }

  if($p['custom']!='') {
    $text_content .=$p['custom'];
  }

  $text_content.='</div></div></div>';
  

  $beautify = new Beautify_Html(array(
    'indent_inner_html' => false,
    'indent_char' => " ",
    'indent_size' => 2,
    'wrap_line_length' => 32786,
    'unformatted' => ['code', 'pre'],
    'preserve_newlines' => false,
    'max_preserve_newlines' => 32786,
    'indent_scripts'  => 'normal', // keep|separate|normal
  ));

  if($p['page_type']==2) {
    $udt['body']=gpc($beautify->beautify($p['custom']));
    Update($db,"t1_h_tab",$udt,"id=".$p['id'],0);
  } 

  if($p['page_type']==1) {
    $udt['body']=gpc($beautify->beautify($text_content));
    Update($db,"t1_h_tab",$udt,"id=".$p['id'],0);
  }

  //file_put_contents($file_name, $text_content);
  //echo $file_name." saved<br>";
}


function edit($id) {
   global $db,$ar;    
  $sql = "select * from `t1_h_tab` where id=".$id;
  $res = mysqli_query($db, $sql);
  //echo $sql;
  $rw = mysqli_fetch_assoc($res);
  $php_file=$ar['path_core'].'f1/pages/'.$rw['name'].'.html';
  if (file_exists($php_file)) {
    $filecontent=file_get_contents($php_file);
  } else {
    $filecontent="";      
  }
  if($rw['menu']!='') {
    $htm_menu=htmlspecialchars($rw['menu']);
  } else {
    $htm_menu="";
  }
  if($rw['custom']!='') {
    $htm_custom=htmlspecialchars($rw['custom']);
  } else {
    $htm_custom="";
  }

  if($rw['body']!='') {
    $htm_body=htmlspecialchars($rw['body']);
  } else {
    $htm_body="";
  }

  if($rw['page_type']==1)  { $jsc="checked"; } else { $jsc=""; }
  if($rw['page_type']==2)  { $phpc="checked"; } else { $phpc=""; }
  if($rw['page_type']==3)  { $p3="checked"; } else { $p3=""; }
  if($rw['content_id']==1)  { $ci1="checked"; } else { $ci1=""; }
  if($rw['view_title']==1)  { $vt="checked"; } else { $vt=""; }
  if($rw['view_navbar']==1)  { $vn="checked"; } else { $vn=""; }
  if($rw['view_left_panel']==1)  { $lp="checked"; } else { $lp=""; }
  if($rw['searchbar']==1)  { $sb="checked"; } else { $sb=""; }
  $lev2=$rw['level']+1;
  $parent=getPerent($rw['parent']);
  ?>
<div class="row">
  <div class="col-8">
  <form action="index.php?op=t1_h_tab&op2=edit2" method="post">
    <input type="hidden" name="id" value="<?=$id;?>">
    <input type="hidden" name="parent" value="<?=$rw['parent'];?>">
    <input type="hidden" name="is_active" value="<?=$rw['is_active'];?>">
    <input type="hidden" name="page_type" value="<?=$rw['page_type'];?>">
    <div class="row">
      <div class="col-6">        
      </div>
      <div class="col-6 text-end">
        <a class="btn btn-sm cl-dp5 mr-2" href="?op=t1_h_tab&op2=copy&id=<?=$id;?>&level=<?=$rw['level'];?>&parent=<?=$rw['parent'];?>">Copy This</a>
        <a class="btn btn-sm cl-dp5 mr-2" href="?op=t1_h_tab&op2=copy&id=<?=$id;?>&level=<?=$lev2;?>&parent=<?=$rw['id'];?>">AddChild</a>
        <button type="submit" name="submit" class="btn btn-sm btn-primary">Save</button>
        
      </div>
    </div>

    <div class="row">
      <div class="col-2">
        <label for="path" class="label">path</label>
        <input type="text" class="form-control" name="path" value="<?=$rw['path'];?>">
        <label for="name" class="label">name</label>
        <input type="text" class="form-control" name="name" value="<?=$rw['name'];?>">
        <label for="title" class="label">title</label>
        <input type="text" class="form-control" name="title" value="<?=$rw['title'];?>">
        <label for="level" class="label">level</label>
        <input type="text" class="form-control" name="level" value="<?=$rw['level'];?>">
        <label for="path_right" class="label">path_right</label>
        <input type="text" class="form-control" name="path_right" value="<?=$rw['path_right'];?>">
        <label for="title_right" class="label">title_right</label>
        <input type="text" class="form-control" name="title_right" value="<?=$rw['title_right'];?>">
        <label for="icon_right" class="label">icon_right</label>
        <input type="text" class="form-control" name="icon_right" value="<?=$rw['icon_right'];?>">
        <br>

      </div>
      <div class="col-5">        
          
        <textarea class="prism-live language-javascript line-numbers" rows="30" data-start="1" name="custom" style="--max-height: 30em"><?=$htm_custom;?></textarea>
        <br>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="checkbox" <?=$ci1;?> name="content_id" id="inlineRadio2" value="1">
          <label class="form-check-label" for="inlineRadio2">content_id</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="checkbox" <?=$vt;?> name="view_title" id="view_title" value="1">
          <label class="form-check-label" for="view_title">view_title</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="checkbox" <?=$vn;?> name="view_navbar" id="view_navbar" value="1">
          <label class="form-check-label" for="view_navbar">view_navbar</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="checkbox" <?=$lp;?> name="view_left_panel" id="view_left_panel" value="1">
          <label class="form-check-label" for="view_left_panel">view_left_panel</label>
        </div>
        <div class="form-check form-check-inline">
          <input class="form-check-input" type="checkbox" <?=$sb;?> name="searchbar" id="searchbar" value="1">
          <label class="form-check-label" for="view_left_panel">searchbar</label>
        </div>
        <?php 
        echo "<pre>"; print_r($parent); echo "</pre>";
        //echo "<pre>"; print_r($rw); echo "</pre>";
        ?>
      </div>
      <div class="col-5">
<textarea class="prism-live language-javascript line-numbers" rows="20" data-start="1" name="body" style="--max-height: 20em"><?=$htm_body;?></textarea>
      </div>
    </div>
  </form>
  </div>
  <div class="col-4">

  </div>
</div>
  <?php
  //echo "<pre>"; print_r($rw); echo "</pre>";
}


function save_html() {
  global $ar,$db;
  $sql = "select body from `t1_h_tab` where del=0 order by seq";
  $res = mysqli_query($db, $sql);
  //echo $sql;
  $text='';
  while($r1 = mysqli_fetch_assoc($res)) {
    $text .= ugpc($r1['body']);
  }
  $text .= '';

  $beautify = new Beautify_Html(array(
    'indent_inner_html' => false,
    'indent_char' => " ",
    'indent_size' => 2,
    'wrap_line_length' => 32786,
    'unformatted' => ['code', 'pre'],
    'preserve_newlines' => false,
    'max_preserve_newlines' => 32786,
    'indent_scripts'  => 'normal', // keep|separate|normal
  ));
  $text2=$beautify->beautify($text);
  $file_name=$ar['path_core']."f1/index.html";
  unlink($file_name);
  file_put_contents($file_name, $text2);
}
?>

/home/u902783705/domains/azkapersada.com/public_html/sub/
rs2/inc/inc.t1_h_tab.php
si/common.function
si/dom/get.img
si/api/post_location
si/api/post_loc_v3
si/api/post_tag_v2
si/api/post_tag_v3
common.function
common.function-
footer
header
inc.app.function
inc.ar.app
index
tes_curl
ucol
api/v2/api.function
api/v2/inc.mail
api/v2/index
api/v2/php/agen
api/v2/php/armada_jalan_byday
api/v2/php/armada_perpal_byday
api/v2/php/armada_perpal_byday-
api/v2/php/beda_byday
api/v2/php/cek_rute_baru
api/v2/php/cek_rute_time
api/v2/php/cek_rute_time_v1
api/v2/php/cek_rute_time_v2
api/v2/php/city
api/v2/php/dr_time_byday
api/v2/php/dr_time_jalan_byday
api/v2/php/email_cek
api/v2/php/get_nl_byday
api/v2/php/get_nl_kelas_armada
api/v2/php/js_armada_tax_expire
api/v2/php/js_blue_armada
api/v2/php/js_blue_expire
api/v2/php/js_car_srut_blank
api/v2/php/js_img_todl
api/v2/php/js_jalurnew
api/v2/php/js_kebid
api/v2/php/js_nl_latest
api/v2/php/js_nl_min
api/v2/php/js_noken
api/v2/php/js_noken_mesin_blank
api/v2/php/js_noken_no_lambung
api/v2/php/js_noken_spionam_cek
api/v2/php/js_noken_tax_cek
api/v2/php/js_rute
api/v2/php/js_rute_bycity
api/v2/php/js_rute_min
api/v2/php/js_spionam_id
api/v2/php/js_spionam_kps
api/v2/php/kd_armada
api/v2/php/kd_armada_dr_time
api/v2/php/kd_armada_to_time
api/v2/php/naik_byday
api/v2/php/nk_pilih
api/v2/php/nl_noken_bytgl
api/v2/php/nl_pilih
api/v2/php/nl_reset
api/v2/php/noken_koreksi
api/v2/php/otw
api/v2/php/otw_not_full
api/v2/php/password_forgot
api/v2/php/post_1naik
api/v2/php/post_1turun
api/v2/php/post_blue
api/v2/php/post_dr_time_byday_local
api/v2/php/post_kebid_byday
api/v2/php/post_noken_mesin
api/v2/php/post_noken_no_lambung
api/v2/php/post_sakpol
api/v2/php/post_spionam
api/v2/php/post_spionam_cek
api/v2/php/post_spionam_update
api/v2/php/post_spnm_noken
api/v2/php/ricar
api/v2/php/rute_price
api/v2/php/selisih_bagasi
api/v2/php/signin
api/v2/php/tool
api/v2/php/tool_armada
api/v2/php/tool_lambung
api/v2/php/tool_noken
api/v2/php/turun_byday
api/v2/php/ucol
api/v2/php/uji_no
api/v2/php/update_agen
api/v2/php/update_armada_byday
api/v2/php/update_armada_v2_byday
api/v2/php/update_bagasi_byday
api/v2/php/update_bagasi_city
api/v2/php/update_jalan_byday
api/v2/php/update_penumpang_byday
api/v2/php/update_trayek_dr_time
api/v2/php/update_trayek_to_time
daily/10_tool_seq
daily/14_update_kd_armada
daily/15_update_rute_dr_to_ccd
daily/16_kdagen_to_id
daily/16_kdagen_to_id-
daily/17_update_dr_to_time
inc/inc.cp_sphp
inc/inc.filephp
inc/inc.job_kebid
inc/inc.js_pergi
inc/inc.rs4_css
inc/inc.rs4_html
inc/inc.rs4_h_page
inc/inc.rs4_h_tab
inc/inc.rs4_js
inc/inc.rs4_jsf
inc/inc.t1_css
inc/inc.t1_html
inc/inc.t1_h_page
inc/inc.t1_h_tab
inc/inc.t1_js
inc/inc.t1_jsf
xhr/inc.xhr