📄 sqladmin.php
字号:
<?php
class CSQLAdmin extends CLibrary {
/**
* description
*
* @var type
*
* @access type
*/
var $form;
/**
* description
*
* @var type
*
* @access type
*/
var $functions;
/**
* description functions list which will be executed in variouse points of sqladmin
*
* @var type
*
* @access type
*/
var $functions;
function CSQLAdmin($section , $templates , $db , $tables , $extra = "") {
global $_CONF;
if (!$_GET["page"])
$_GET["page"] = 1;
parent::CLibrary("SQLAdmin");
//checking if the templates are orblects or path to a template file
if (!is_array($templates))
//if path the load the tempmate form that file
$this->templates = array("generic_form" => new CTemplate($templates));
else
$this->templates = $templates;
$this->db = $db;
$this->tables = $tables;
//extra variables to be passed to cform
$this->extra = $extra;
//loading the forms , changed the varialbes locations, but still keeping the compatibility
$path = ($_CONF["forms"]["adminpath"] ? $_CONF["forms"]["adminpath"] : $_CONF["formspath"] );
if (dirname($section)) {
$path .= dirname($section) . "/" ;
$section = basename($section);
}
//debuging part
// if (defined("PB_DEBUG") && PB_DEBUG == "1")
// echo "<br>FILE:SQLADMIN:MAIN:{$path}{$section}.xml";
$conf = new CConfig( $path . $section . ".xml");
$this->forms = $conf->vars["form"];
//loading the edit/add forms
if (is_array($this->forms["forms"])) {
foreach ($this->forms["forms"] as $key => $val) {
unset($conf);
//debuging part
// if (defined("PB_DEBUG") && PB_DEBUG == "1")
// echo "<br>FILE:SQLADMIN:SECTION:{$path}{$section}.xml";
$conf = new CConfig($path . $val );
$this->forms["forms"][$key] = $conf->vars["form"];
//adding the tables
$this->forms["forms"][$key]["table"] = $this->forms["table"];
$this->forms["forms"][$key]["table_uid"] = $this->forms["table_uid"];
$this->forms["forms"][$key]["xmlfile"] = $path . $val ;
}
}
$this->form = new CForm($this->templates["generic_form"], &$db , &$tables);
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function FormList($items = "") {
global $base;
//checking if hte values weren't inputed ion the main object
if (is_array($this->items)) {
$items = $this->items;
}
//crap, preexecute a function, which is suposed in some times to preload the items too
if (is_array($this->functions["list"]["pre"]))
call_user_func($this->functions["list"]["pre"], &$items , &$items_count);
//if i got no elements from preloader functions, then i load it manualy
if (!is_array($items)) {
//cheking if is a normal browse or a search method
if (isset($this->forms["uridata"]["search"]) && ($_GET[$this->forms["uridata"]["action"]] == $this->forms["uridata"]["search"])) {
$items = $this->db->QuerySelectLimit($this->tables[$this->forms["forms"]["list"]["table"]],"*", "`" . $_GET["what"] . "` " . ( $_GET["type"] == "int" ? "='" . $_GET["search"] . "'" : "LIKE '%" . $_GET["search"] . "%'"),(int) $_GET["page"],$this->forms["forms"]["list"]["items"]);
$count = $this->db->RowCount($this->tables[$this->forms["forms"]["list"]["table"]] , " WHERE `" . $_GET["what"] . "` " . ( $_GET["type"] == "int" ? "='" . $_GET["search"] . "'" : "LIKE '%" . $_GET["search"] . "%'"));
} else {
$items = $this->db->QuerySelectLimit($this->tables[$this->forms["forms"]["list"]["table"]],"*","",(int) $_GET["page"],$this->forms["forms"]["list"]["items"]);
$count = $this->db->RowCount($this->tables[$this->forms["forms"]["list"]["table"]]);
}
}
$_GET["page"] = $_GET["page"] ? $_GET["page"] : 1;
//auto index the element
$start = $this->forms["forms"]["list"]["items"] * ($_GET["page"] - 1 );
if (is_array($items)) {
foreach ($items as $key => $val) {
$items[$key]["_count"] = ++$start;
}
}
//$data = new CForm($this->templates["generic_form"], &$this->db , &$this->tables);
return $this->form->SimpleList($this->forms["forms"]["list"] , $items , $count , $this->extra["list"]);
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function SetFunction( $form , $event , $function) {
$this->functions[$form][$event] = $function;
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function ListProcess($pre = "" , $after = "" ) {
$this->functions["list"]["pre"] = $pre;
$this->functions["list"]["after"] = $after;
}
/**
* description
*
* @param
*
* @return
*
* @access
*/
function StoreRecord($redirect = true) {
global $base, $_CONF;
//validating the input data
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//doing a autodetect for storing type , edit or add
//if $_GET["type"] is set is simple, else detecting after the id form
if (!isset($_GET["type"])) {
if ($_POST[$this->forms["table_uid"]])
$_GET["type"] = "edit";
else
$_GET["type"] = "add";
}
//if validation succeeds then i move the files from /tmp to their directory, else i will proceed to add
//precheck for uploaded files, like temporary images, etc.
$form = $this->forms["forms"][$_GET["type"]];
if (is_array($form["fields"])) {
foreach ($form["fields"] as $key => $val) {
switch ($val["type"]) {
case "date":
$_POST[$key] = mktime ( $_POST[$key . "_hour"] , $_POST[$key . "_minute"] , $_POST[$key . "_second"] , $_POST[$key. "_month"] , $_POST[$key. "_day"] , $_POST[$key. "_year"]);
break;
case "droplist":
if ($val["subtype"] == "multiple") {
//detect the fields which should be available for this field
if (is_array($_POST)) {
foreach ($_POST as $k => $v) {
if (strstr($k , $key . "_option_")) {
$option[] = $v;
}
}
//ok, now build the result
if (is_array($option)) {
$_POST[$key] = implode($val["tree"]["db_separator"],$option);
} else {
$_POST[$key] = "";
}
} else {
}
}
break;
case "upload":
$file = true;
case "image":
unset($_POST[$key]);
//checking how choosed the client to set the image
switch ($_POST[$key . "_radio_type"]) {
case 0:
//checking if the client specified any image type
if (is_array($_FILES[$key . "_upload_client"]) && is_uploaded_file($_FILES[$key . "_upload_client"]["tmp_name"])) {
$img = &$_FILES[$key . "_upload_client"];
//temporary upload the file in images/upload/tmp/
$name = $_POST[$key . "_temp"] != "" ? $_POST[$key . "_temp"] : $val["file"]["default"] . time() . $val["file"]["ext"];
move_uploaded_file($img["tmp_name"] , $_CONF["path"] . $_CONF["upload"] . "tmp/" . $name );
// generate the tn image
if ($val["tn"]["generate"] == "true") {
$base->image->Resize(
$_CONF["path"] . $_CONF["upload"] . "tmp/" . $name ,
$_CONF["path"] . $_CONF["upload"] . "tmp/" . $val["tn"]["preffix"] . $name ,
$val["tn"]["width"]
);
$_POST["tn_" . $key] = "1";
}
//setting read/delete/save permission for all users, usefull if the httpd is working as normal user ( most cases )
chmod ($_CONF["path"] . $_CONF["upload"] . "tmp/" . $name , 0777);
// die;
//setting the temp variable
$_fields["values"][$key . "_temp"] = $name;
$_POST[$key . "_temp"] = $name;
$_POST[$key . "_file"] = $_FILES[$key . "_upload_client"]["name"];
$_POST[$key] = "1";
}
break;
case "1":
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -