<main>
<div class="container-fluid mt-3">
<div class="row">
<div class="col-11">
<?php
switch($op2) {
case "gen_menu";
gen_list_child($_GET['id']);
list_scriptext($q,$col,$q2,$col2,$q3,$col3);
break;
case "tree";
tree();
break;
case "gen_route";
gen_route();
list_scriptext($q,$col,$q2,$col2,$q3,$col3);
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_page` 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_page` where id=".$_GET['id'];
$res3 = mysqli_query($db, $sql3);
$r3 = mysqli_fetch_assoc($res3);
$idt=array(
'id'=>$id2,
'path'=>$r3['path']."-",
'path_right'=>$r3['path_right'],
'title_right'=>$r3['title_right'],
'name'=>$r3['name']."-",
'title'=>$r3['title'],
'page_type'=>$r3['page_type'],
'url_type'=>$r3['url_type'],
'icon'=>$r3['icon'],
'parent'=>$r3['parent'],
'content_id'=>$r3['content_id'],
'level'=>$r3['level'],
'custom'=>'',
'update_at'=>time(),
);
$idt['parent']=$_GET['parent'];
$idt['level']=$_GET['level'];
Insert($db,"rs4_h_page",$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
));
//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'],
'page_type'=>$_POST['page_type'],
//'url_type'=>$_POST['url_type'],
'icon'=>$_POST['icon'],
'level'=>$_POST['level'],
//'view_title'=>$_POST['view_title'],
'custom'=>gpc($beautify->beautify(trim($_POST['custom']))),
'bottom'=>gpc($beautify->beautify(trim($_POST['bottom']))),
'update_at'=>time(),
);
if(isset($_POST['content_id'])) {
$udt['content_id']=$_POST['content_id'];
} else {
$udt['content_id']=0;
}
if(isset($_POST['view_back'])) {
$udt['view_back']=$_POST['view_back'];
} else {
$udt['view_back']=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_toolbar'])) {
$udt['view_toolbar']=$_POST['view_toolbar'];
} else {
$udt['view_toolbar']=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;
}
if(isset($_POST['page_type']) && $_POST['page_type']==1) {
$udt['page_type']=$_POST['page_type'];
$udt['url_type']='url';
} else {
$udt['page_type']=2;
$udt['url_type']='componentUrl';
}
Update($db,"rs4_h_page",$udt,"id=".$_POST['id'],0);
$_POST['path_parent']=getPerent($_POST['parent']);
file_save($_POST);
edit($_POST['id']);
break;
case "file_save";
file_save($_GET['id']);
edit($_GET['id2']);
break;
case "del";
Delete($db,"rs4_h_page","id=".$_GET['id'],0);
//edit($_GET['id']);
case "list";
list_scriptext($q,$col,$q2,$col2,$q3,$col3);
default;
}
?>
</div>
<div class="col-1 small">
<a href="?op=rs4_h_page&op2=gen_route" class="btn btn-xs btn-color-pink mt-1">gen route</a><br>
<?php
tree();
?>
</div>
</div>
</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>cat</th>
<th>tabber</th>
<th>lev</th>
<th>type</th>
<th>parent</th>
<th>toolbar</th>
<th>r_link</th>
<th>r_ico</th>
<th>uType</th>
<th>pType</th>
<th>parent</th>
<th>udate</th>
<th>del</th>
<th>Menu</th>
</tr>
</thead>
<tbody>
<?php
$sql = "select * from rs4_h_page where id>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)) {
if($rw['del']==0) {
$mdel='<a href="#" onClick="uCol('.$rw['id'].',\'del\',1,\'rs4_h_page\');" class="btn btn-xs btn-color-red">del</a>';
} else {
$mdel='<a href="#" onClick="uCol('.$rw['id'].',\'del\',0,\'rs4_h_page\');" class="btn btn-xs btn-color-blue">undel</a>';
}
?>
<tr>
<td><?=$rw['id'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'path','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['path'];?></td>
<td><?=$rw['name'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'icon','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['icon'];?></td>
<td><?=$rw['title'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'page_cat','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['page_cat'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'view_tabber','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['view_tabber'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'level','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['level'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'page_type','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['page_type'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'parent','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['parent'];?></td>
<td contenteditable="true" onBlur="colUpdate(this,'view_toolbar','<?=$rw['id'];?>','rs4_h_page')" onClick="editRow(this);"><?=$rw['view_toolbar'];?></td>
<td><?=$rw['path_right'];?></td>
<td><?=$rw['icon_right'];?></td>
<td><?=$rw['url_type'];?></td>
<td><a href="?op=rs4_h_page&op2=list&col=page_type&q=<?=$rw['page_type'];?>"><?=$rw['page_type'];?></a></td>
<td><a href="?op=rs4_h_page&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><?=$rw['del'];?></td>
<td>
<a class="btn btn-xs btn-danger" href="?op=rs4_h_page&op2=del&id=<?=$rw['id'];?>">delete</a>
<a class="btn btn-xs btn-primary" href="?op=rs4_h_page&op2=edit&id=<?=$rw['id'];?>">edit</a>
<?=$mdel;?>
<a class="btn btn-xs btn-primary" href="?op=rs4_h_page&op2=gen_menu&id=<?=$rw['id'];?>">menu</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br><?=$sql;?><br>
<?php
}
function gen_list_child($id) {
global $db,$ar;
include_once $ar['path_core']."nibrasfincp/inc.ar.f7icon.php";
$sql="SELECT `path`,`name`,`icon`,`title` from rs4_h_page where del=0 and parent=".$id." order by name";
$res=mysqli_query($db,$sql);
$text='<div class="list links-list colored-icons-list list-outline list-dividers full-width">
<ul>';
while($r1=mysqli_fetch_assoc($res)) {
if($r1['icon']=='') {
$l_icon=$ar['f7_icon'][array_rand($ar['f7_icon'], 1)];
} else {
$l_icon=$rw['icon'];
}
$text .='
<li>
<a href="/'.$r1['path'].'">
<div class="colored-icon green">
<i class="icon f7-icons">'.$l_icon.'</i>
</div>'.$r1['title'].'</a>
</li>';
}
$text .='</ul></div>';
echo '<textarea class="form-control" rows="5">'.$text.'</textarea>';
}
function getPerent($id) {
global $db,$ar;
$sql="SELECT `path`,`name` from rs4_h_page 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_page where parent=0 order by page_type,name";
$res=mysqli_query($db,$sql);
while($r1=mysqli_fetch_assoc($res)) {
?>
<a href="?op=rs4_h_page&op2=edit&id=<?=$r1['id'];?>"><?=$r1['name'];?></a><br>
<?php
$sql2="SELECT * from rs4_h_page where parent=".$r1['id']." order by name";
$res2=mysqli_query($db,$sql2);
while($r2=mysqli_fetch_assoc($res2)) {
?>
- <a href="?op=rs4_h_page&op2=edit&id=<?=$r2['id'];?>"><?=$r2['name'];?></a><br>
<?php
$sql3="SELECT * from rs4_h_page where parent=".$r2['id']." order by name";
$res3=mysqli_query($db,$sql3);
while($r3=mysqli_fetch_assoc($res3)) {
?>
- - <a href="?op=rs4_h_page&op2=edit&id=<?=$r3['id'];?>"><?=$r3['name'];?></a><br>
<?php
$sql4="SELECT * from rs4_h_page where parent=".$r3['id']." order by name";
$res4=mysqli_query($db,$sql4);
while($r4=mysqli_fetch_assoc($res4)) {
?>
- - - <a href="?op=rs4_h_page&op2=edit&id=<?=$r4['id'];?>"><?=$r4['name'];?></a><br>
<?php
}
}
}
}
}
function edit($id) {
global $db,$ar;
$sql = "select * from `rs4_h_page` 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=htmlspecialchars(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['page_type']==1) { $jsc="checked"; } else { $jsc=""; }
if($rw['page_type']==2) { $phpc="checked"; } else { $phpc=""; }
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=""; }
if($rw['view_back']==1) { $vb="checked"; } else { $vb=""; }
$lev2=$rw['level']+1;
$parent=getPerent($rw['parent']);
$php_file=$ar['path_core'].'rs4/pages/'.$rw['name'].'.html';
include_once $ar['path_core']."nibrasfincp/inc.ar.f7icon.php";
if($rw['icon']=='') {
$p_icon=$ar['f7_icon'][array_rand($ar['f7_icon'], 1)];
} else {
$p_icon=$rw['icon'];
}
?>
<div class="row">
<div class="col-8">
<form action="index.php?op=rs4_h_page&op2=edit2" method="post">
<input type="hidden" name="id" value="<?=$id;?>">
<input type="hidden" name="icon" value="<?=$ip_icon;?>">
<input type="hidden" name="parent" value="<?=$rw['parent'];?>">
<input type="hidden" name="page_cat" value="<?=$rw['page_cat'];?>">
<input type="hidden" name="view_tabber" value="<?=$rw['view_tabber'];?>">
<input type="hidden" name="view_toolbar" value="<?=$rw['view_toolbar'];?>">
<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_page&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_page&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 class="form-check form-check-inline">
<input class="form-check-input" type="radio" <?=$jsc;?> name="page_type" id="inlineRadio1" value="1">
<label class="form-check-label" for="inlineRadio1">url</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" <?=$phpc;?> name="page_type" id="inlineRadio2" value="2">
<label class="form-check-label" for="inlineRadio2">template</label>
</div>
</div>
<div class="col-5">
<textarea class="prism-live language-javascript line-numbers" rows="20" data-start="1" name="custom" style="--max-height: 20em"><?=$htm_custom;?></textarea>
<br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" <?=$vb;?> name="view_back" id="view_back" value="1">
<label class="form-check-label" for="view_back">view_back</label>
</div>
<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">
<pre class="line-numbers" data-start="1" style="white-space:pre-wrap;"><code contenteditable class="language-javascript"><?=htmlspecialchars($rw['body']);?></code></pre>
</div>
</div>
</form>
</div>
<div class="col-4">
<div class="card">
<div class="card-body">
<?=$php_file;?>
<h5 class="card-title">pages/<?=$rw['name'];?>.html</h5>
<form method="post" action="index.php?op=rs4_h_page&op2=php_save">
<input type="hidden" name="file_name" value="<?=$php_file;?>">
<input type="hidden" name="id" value="<?=$rw['id'];?>">
<textarea class="prism-live language-javascript line-numbers" rows="20" data-start="1" name="content" style="--max-height: 20em"><?=$filecontent;?></textarea>
<input type="submit" name="submit" class="btn btn-success mt-2">
</form>
</div>
</div>
</div>
</div>
<?php
//echo "<pre>"; print_r($rw); echo "</pre>";
}
function file_save($p) {
global $db,$ar;
if($p['view_toolbar']==0) {
$tlbar = ' no-toolbar';
} else {
$tlbar ="";
}
if($p['page_type']==1) {
$start ='<div class="page page-'.$p['name'].''.$tlbar.'" data-name="'.$p['name'].'">';
$end ='
</div>
</div>';
} else {
$start ='<template>
<div class="page page-'.$p['name'].''.$tlbar.'" data-name="'.$p['name'].'">';
$end ='
</div>
</div>
</template>';
}
$text_content =$start;
if($p['view_navbar']==1) {
$text_content .= '
<div class="navbar navbar-large">
<div class="navbar-bg"></div>
<div class="navbar-inner">';
if($p['view_back']==1) {
$text_content .= '
<div class="left">
<a href="#" class="link back">
<i class="icon f7-icons arrow-back">arrow_left</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>';
}
if($p['searchbar']==1) {
$text_content .='
<div class="subnavbar">
<form data-search-container=".search-list_'.$p['name'].'" data-search-in=".item-title" class="searchbar searchbar-init">
<div class="searchbar-inner">
<div class="searchbar-input-wrap">
<input type="search" placeholder="Search" />
<i class="searchbar-icon"></i>
<span class="input-clear-button"></span>
</div>
<span class="searchbar-disable-button">Cancel</span>
</div>
</form>
</div>';
}
if($p['path_right']!='') {
$text_content .= '
<div class="right">
<a href="/'.$p['path_right'].'/" class="link">
<i class="icon material-icons">'.$p['icons_right'].'</i> '.$p['title_right'].'
</a>
</div>';
} else {
$text_content .= '
<div class="right">
</div>';
}
$text_content .= '
</div>
</div>';
}
if($p['content_id']==1) {
$text_content .= '
<div class="page-content" id="'.$p['name'].'_content">';
} else {
$text_content .= '
<div class="page-content">';
}
$text_content .='
'.$p['custom'];
$text_content .=$end;
$php_file=$ar['path_core'].'rs4/pages/'.$p['name'].'.html';
file_put_contents($php_file, $text_content);
//echo $text_content."<hr>";
echo $php_file." saved<br>";
$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
));
$udt=array(
'body'=>$beautify->beautify($text_content),
);
Update($db,"rs4_h_page",$udt,"id=".$p['id'],0);
}
function gen_route() {
global $ar,$db;
$sql = "select * from `rs4_h_page` where del=0 order by name";
$res = mysqli_query($db, $sql);
//echo $sql;
$text="\rvar routes = [
{ path: '/', url: './index.html', name: 'start'},";
while($r1 = mysqli_fetch_assoc($res)) {
$text .= "
{ path: '/".$r1['path']."', ".$r1['url_type'].": './pages/".$r1['name'].".html', name: '".$r1['name']."'},";
}
$text .= "
{ path: '(.*)', url: './pages/blank.html'}];";
?>
<textarea class="form-control" rows="10"><?=$text;?></textarea>
<?php
$file_name=$ar['path_core']."rs4/js/routes.js";
file_put_contents($file_name, $text);
//echo "<pre>"; print_r($text); echo "</pre>";
}
?>