<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=rs4_h_tab&op2=tree" class="btn btn-xs btn-color-red mt-1">tree</a>
<a href="?op=rs4_h_tab&op2=save_html" class="btn btn-xs btn-color-pink mt-1">save html</a>
<?php
$sql1 = "select * from rs4_h_tab where del=0 order by page_type,name";
$res1 = mysqli_query($db, $sql1);
while($r1 = mysqli_fetch_assoc($res1)) {
?>
<a href="?op=rs4_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 `rs4_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 `rs4_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,"rs4_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'],
'seq'=>$_POST['seq'],
'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,"rs4_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,"rs4_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 rs4_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'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['path'];?></td>
<td><?=$rw['name'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'icon','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['icon'];?></td>
<td><?=$rw['title'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'level','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['level'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'page_type','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['page_type'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'parent','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['parent'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'seq','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['seq'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'is_active','<?=$rw['id'];?>','rs4_h_tab')" onClick="editRow(this);"><?=$rw['is_active'];?></td>
<td><?=$rw['path_right'];?></td>
<td><?=$rw['icon_right'];?></td>
<td><a href="?op=rs4_h_tab&op2=list&col=page_type&q=<?=$rw['page_type'];?>"><?=$rw['page_type'];?></a></td>
<td><a href="?op=rs4_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=rs4_h_tab&op2=edit&id=<?=$rw['id'];?>">edit</a>
<a href="#" onClick="uCol(<?=$rw['id'];?>,'del',1,'rs4_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 rs4_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 rs4_h_tab where parent=1 order by page_type,name";
$res=mysqli_query($db,$sql);
while($r1=mysqli_fetch_assoc($res)) {
?>
<a href="?op=rs4_h_tab&op2=edit&id=<?=$r1['id'];?>"><?=$r1['name'];?></a><br>
<?php
$sql2="SELECT * from rs4_h_tab where parent=".$r1['id']." order by name";
$res2=mysqli_query($db,$sql2);
while($r2=mysqli_fetch_assoc($res2)) {
?>
---- <a href="?op=rs4_h_tab&op2=edit&id=<?=$r2['id'];?>"><?=$r2['name'];?></a><br>
<?php
$sql3="SELECT * from rs4_h_tab where parent=".$r2['id']." order by name";
$res3=mysqli_query($db,$sql3);
while($r3=mysqli_fetch_assoc($res3)) {
?>
---- ---- <a href="?op=rs4_h_tab&op2=edit&id=<?=$r3['id'];?>"><?=$r3['name'];?></a><br>
<?php
$sql4="SELECT * from rs4_h_tab where parent=".$r3['id']." order by name";
$res4=mysqli_query($db,$sql4);
while($r4=mysqli_fetch_assoc($res4)) {
?>
---- ---- ---- <a href="?op=rs4_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 d-none 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,"rs4_h_tab",$udt,"id=".$p['id'],0);
}
if($p['page_type']==1) {
$udt['body']=gpc($beautify->beautify($text_content));
Update($db,"rs4_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 `rs4_h_tab` where id=".$id;
$res = mysqli_query($db, $sql);
//echo $sql;
$rw = mysqli_fetch_assoc($res);
$php_file=$ar['path_core'].'rs4/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=rs4_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=rs4_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=rs4_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="seq" class="label">seq</label>
<input type="text" class="form-control" name="seq" value="<?=$rw['seq'];?>">
<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 `rs4_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']."rs4/index.html";
unlink($file_name);
file_put_contents($file_name, $text2);
}
?>