feat: 本機新增頁面與導覽調整
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
session_start();
|
||||
date_default_timezone_set("Asia/Taipei");
|
||||
|
||||
class DB
|
||||
{
|
||||
protected $dsn = "mysql:host=localhost;charset=utf8;dbname=vedio_list";
|
||||
protected $pdo;
|
||||
protected $table;
|
||||
|
||||
function __construct($table)
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->pdo = new PDO($this->dsn, 'root', '');
|
||||
}
|
||||
|
||||
function all(...$arg)
|
||||
{
|
||||
$sql = "SELECT * FROM `$this->table` ";
|
||||
if (isset($arg[0])) {
|
||||
if (is_array($arg[0])) {
|
||||
$tmp = $this->a2s($arg[0]);
|
||||
$sql .= " WHERE " . join(" AND ", $tmp);
|
||||
} else {
|
||||
$sql .= $arg[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arg[1])) {
|
||||
$sql .= $arg[1];
|
||||
}
|
||||
|
||||
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
function count(...$arg)
|
||||
{
|
||||
$sql = "SELECT count(*) FROM `$this->table`";
|
||||
if (isset($arg[0])) {
|
||||
if (is_array($arg[0])) {
|
||||
$tmp = $this->a2s($arg[0]);
|
||||
$sql .= " WHERE " . join(" AND ", $tmp);
|
||||
} else {
|
||||
$sql .= $arg[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arg[1])) {
|
||||
$sql .= $arg[1];
|
||||
}
|
||||
|
||||
return $this->pdo->query($sql)->fetchColumn();
|
||||
}
|
||||
|
||||
function find($arg)
|
||||
{
|
||||
$sql = "SELECT * FROM `$this->table` ";
|
||||
|
||||
if (is_array($arg)) {
|
||||
$tmp = $this->a2s($arg);
|
||||
$sql .= " WHERE " . join(" AND ", $tmp);
|
||||
} else {
|
||||
$sql .= " WHERE `id`='$arg'";
|
||||
}
|
||||
|
||||
return $this->pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
function save($arg)
|
||||
{
|
||||
if (isset($arg['id'])) {
|
||||
$tmp = $this->a2s($arg);
|
||||
$sql = "UPDATE `$this->table` SET " . join(" , ", $tmp);
|
||||
$sql .= " WHERE `id`='{$arg['id']}'";
|
||||
} else {
|
||||
$keys = array_keys($arg);
|
||||
$sql = "INSERT INTO `$this->table` (`" . join("`,`", $keys) . "`) VALUES('" . join("','", $arg) . "');";
|
||||
}
|
||||
|
||||
return $this->pdo->exec($sql);
|
||||
}
|
||||
|
||||
function del($arg)
|
||||
{
|
||||
$sql = "DELETE FROM `$this->table` ";
|
||||
|
||||
if (is_array($arg)) {
|
||||
$tmp = $this->a2s($arg);
|
||||
$sql .= " WHERE " . join(" AND ", $tmp);
|
||||
} else {
|
||||
$sql .= " WHERE `id`='$arg'";
|
||||
}
|
||||
|
||||
return $this->pdo->exec($sql);
|
||||
}
|
||||
|
||||
protected function a2s($array)
|
||||
{
|
||||
$tmp = [];
|
||||
foreach ($array as $key => $val) {
|
||||
$tmp[] = "`$key`='$val'";
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
function q($sql)
|
||||
{
|
||||
return $this->pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
function dd($array)
|
||||
{
|
||||
echo "<pre>";
|
||||
print_r($array);
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
function to($url)
|
||||
{
|
||||
header("location:$url");
|
||||
}
|
||||
|
||||
$Drama = new DB('dramas');
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
include_once "db.php";
|
||||
|
||||
$table = ${$_POST['table']};
|
||||
$table->del($_POST['id']);
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
include_once "db.php";
|
||||
|
||||
$row = $Drama->find($_POST['id']);
|
||||
$row['sh'] = ((int)$row['sh'] + 1) % 2;
|
||||
$Drama->save($row);
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
include_once "db.php";
|
||||
|
||||
$table = ${$_POST['table']};
|
||||
$row1 = $table->find($_POST['ids'][0]);
|
||||
$row2 = $table->find($_POST['ids'][1]);
|
||||
|
||||
$tmp = $row1['rank'];
|
||||
$row1['rank'] = $row2['rank'];
|
||||
$row2['rank'] = $tmp;
|
||||
|
||||
$table->save($row1);
|
||||
$table->save($row2);
|
||||
Reference in New Issue
Block a user