<main>
<div class="container-fluid">
<div class="row align-items-center justify-content-between pt-2">
<div class="col-12 text-end mb-2">
<?php
$sql1 = "select * from cp_sphp where del=0 and parent>0 order by parent,name";
$res1 = mysqli_query($db, $sql1);
while($r1 = mysqli_fetch_assoc($res1)) {
?>
<a href="?op=cp_sphp&op2=edit&id=<?=$r1['id'];?>" class="btn btn-xs cl-do7 mt-1"><?=$r1['name'];?></a>
<?php
}
?>
</div>
</div>
<?php
switch($op2) {
case "edit";
edit($_GET['id']);
break;
case "copy";
$sql4 = "select id from `cp_sphp` order by id desc limit 1";
$res4 = mysqli_query($db, $sql4);
$rw4 = mysqli_fetch_assoc($res4);
$id2=$rw4['id']+1;
$sql3 = "select * from `cp_sphp` where id=".$_GET['id'];
$res3 = mysqli_query($db, $sql3);
$r3 = mysqli_fetch_assoc($res3);
$idt=array(
'id'=>$id2,
'modul'=>trim($r3['modul']),
'name'=>$r3['name']."-",
'is'=>$r3['is'],
'level'=>$_GET['level'],
'parent'=>$_GET['parent'],
'update_at'=>time(),
//'body'=>gpc(trim($r3['body'])),
);
Insert($db,"cp_sphp",$idt,0);
edit($id2);
break;
case "edit2";
//echo "<pre>"; print_r($_POST); echo "</pre>";
$udt=array(
'modul'=>trim($_POST['modul']),
'parent'=>$_POST['parent'],
'name'=>$_POST['name'],
'is'=>$_POST['is'],
//'is_php'=>$_POST['is_php'],
//'is_html'=>$_POST['is_html'],
'level'=>$_POST['level'],
'body'=>gpc(trim($_POST['body'])),
'update_at'=>time(),
);
Update($db,"cp_sphp",$udt,"id=".$_POST['id'],0);
if($_POST['id']>2) {
file_save($_POST['parent']);
}
edit($_POST['id']);
break;
case "file_save";
file_save($_GET['id']);
edit($_GET['id2']);
break;
case "del";
Delete($db,"cp_sphp","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_5d" width="100%" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>modul</th>
<th>name</th>
<th>lev</th>
<th>parent</th>
<th>is</th>
<th>del</th>
<th>udate</th>
<th>Menu</th>
</tr>
</thead>
<tbody>
<?php
$sql = "select * from cp_sphp 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><a href="?op=cp_sphp&op2=list&col=modul&q=<?=$rw['modul'];?>"><?=$rw['modul'];?></a></td>
<td><?=$rw['name'];?></td>
<td><?=$rw['level'];?></td>
<td><?=$rw['parent'];?></td>
<td><?=$rw['is'];?></td>
<td><?=$rw['del'];?></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=cp_sphp&op2=edit&id=<?=$rw['id'];?>">edit</a>
<a href="#" onClick="uCol(<?=$rw['id'];?>,'del',1,'cp_sphp');" class="btn btn-xs btn-color-red">del</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br><?=$sql;?><br>
<?php
}
function edit($id) {
global $db,$ar;
$sql = "select * from `cp_sphp` where id=".$id;
$res = mysqli_query($db, $sql);
//echo $sql;
$rw = mysqli_fetch_assoc($res);
if($rw['is']=='js') { $jsc="checked"; } else { $jsc=""; }
if($rw['is']=='php') { $phpc="checked"; } else { $phpc=""; }
if($rw['is']=='html') { $htmlc="checked"; } else { $htmlc=""; }
$lev2=$rw['level']+1;
?>
<div class="row">
<div class="col-10">
<form action="index.php?op=cp_sphp&op2=edit2" method="post">
<input type="hidden" name="id" value="<?=$id;?>">
<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=cp_sphp&op2=copy&id=<?=$id;?>&level=<?=$rw['level'];?>&parent=<?=$rw['parent'];?>">Copy This</a>
<a class="btn btn-sm cl-dp5 mr-2" href="?op=cp_sphp&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="modul" class="label">modul</label>
<input type="text" class="form-control" name="modul" value="<?=$rw['modul'];?>">
<label for="name" class="label">name</label>
<input type="text" class="form-control" name="name" value="<?=$rw['name'];?>">
<label for="parent" class="label">parent</label>
<input type="text" class="form-control" name="parent" value="<?=$rw['parent'];?>">
<label for="level" class="label">level</label>
<input type="text" class="form-control" name="level" value="<?=$rw['level'];?>">
<br>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" <?=$jsc;?> name="is" id="inlineRadio1" value="js">
<label class="form-check-label" for="inlineRadio1">JS</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" <?=$phpc;?> name="is" id="inlineRadio2" value="php">
<label class="form-check-label" for="inlineRadio2">PHP</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" <?=$htmlc;?> name="is" id="inlineRadio3" value="html">
<label class="form-check-label" for="inlineRadio3">HTML</label>
</div>
</div>
<div class="col-5">
<textarea class="prism-live language-javascript line-numbers" rows="20" data-start="1" id="body" name="body" style="--max-height: 30em"><?=htmlspecialchars($rw['body']);?></textarea>
</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-2">
<a href="?op=cp_sphp&op2=edit&id=1">u9/v1/api</a><br>
<a href="?op=cp_sphp&op2=edit&id=2">u9/app</a><br>
<a href="?op=cp_sphp&op2=edit&id=3">u9/inc.com</a><br>
<?php
$sql3="SELECT * from cp_sphp where parent=".$rw['parent']." and id>3 and del=0 order by name";
$res3=mysqli_query($db,$sql3);
while($r=mysqli_fetch_assoc($res3)) {
if($rw['parent']==1) { $parent="u9/api/v1/api"; }
if($rw['parent']==2) { $parent="u9/app"; }
if($rw['parent']==3) { $parent="u9/inc.com"; }
?>
<a href="?op=cp_sphp&op2=edit&id=<?=$r['id'];?>"><?=$parent;?> - <?=$r['name'];?></a><br>
<?php
}
?>
<a href="?op=cp_sphp&op2=file_save&id=1&id2=<?=$id;?>" class="btn btn-sm cl-bl1">Save api</a>
<a href="?op=cp_sphp&op2=file_save&id=2&id2=<?=$id;?>" class="btn btn-sm cl-bl1">Save app</a>
<a href="?op=cp_sphp&op2=file_save&id=3&id2=<?=$id;?>" class="btn btn-sm cl-bl1">Save common</a>
</div>
</div>
<?php
//echo "<pre>"; print_r($rw); echo "</pre>";
}
function file_save($id) {
global $db,$ar;
if($id==1) { $file_name=$ar['app_path']."api/v1/api.common.function.php"; }
if($id==2) { $file_name=$ar['app_path']."app.function.php"; }
if($id==3) { $file_name=$ar['app_path']."inc.common.function.php"; }
unlink($file_name);
$text_content="<?php
";
$sql4 = "select body from `cp_sphp` where id=".$id;
$res4 = mysqli_query($db, $sql4);
$rw4 = mysqli_fetch_assoc($res4);
$text_content .= ugpc($rw4['body']);
$sql1 = "select body from cp_sphp where parent=".$id." and del=0 order by name";
$res1 = mysqli_query($db, $sql1);
while($r1 = mysqli_fetch_assoc($res1)) {
$text_content .= '
';
$text_content .= ugpc($r1['body']);
}
$text_content .="
?>";
file_put_contents($file_name, $text_content);
echo $file_name." saved<br>";
}
?>