function get_analysis($pid, $depth) { $q = "\n\t\t\tselect\t\tA.id\n\t\t\t,\t\t\tA.pid\n\t\t\t,\t\t\tA.name\n\t\t\t,\t\t\tA.name\t\tas label\n\t\t\t,\t\t\tA.base\n\t\t\t,\t\t\tA.var_independent\n\t\t\t,\t\t\tA.var_dependent\n\t\t\t,\t\t\tA.var_intervening\n\t\t\t,\t\t\tA.var_mediation\n\t\t\t,\t\t\tA.var_moderation\n\t\t\t,\t\t\tA.channel\n\t\t\t,\t\t\tA.phase\n\t\t\t,\t\t\tA.segmentation\n\t\t\t,\t\t\tA.attribute\n\t\t\t,\t\t\tA.hierarchy\n\t\t\tfrom\t\tanalysis_price\tA\n\t\t\twhere\t\tA.pid\t\t\t= {$pid}\n\t\t\torder by\tA.id\n\t\t"; $rs = Jaring::db_execute($q, null, true); $index = 0; foreach ($rs as &$m) { $id = $m["id"]; if ($index === 0) { $m["isFirst"] = true; } else { $m["isFirst"] = false; } $m["iconCls"] = "group"; $m["index"] = $index++; $m["depth"] = $depth; $c = get_analysis($id, $depth + 1); if (count($c) <= 0) { $m["leaf"] = true; } else { $m["children"] = $c; $m["expandable"] = true; $m["expanded"] = true; $m["loaded"] = true; } } return $rs; }
function get_analysis($pid, $depth) { $q = "\n\t\t\tselect\t\tA.id\n\t\t\t,\t\t\tA.pid\n\t\t\t,\t\t\tA.name\n\t\t\t,\t\t\tA.name\t\tas text\n\t\t\tfrom\t\tanalysis_price\tA\n\t\t\twhere\t\tA.pid\t\t\t= {$pid}\n\t\t\torder by\tA.id\n\t\t"; $rs = Jaring::db_execute($q, null, true); $index = 0; foreach ($rs as &$m) { $id = $m["id"]; if ($index === 0) { $m["isFirst"] = true; } else { $m["isFirst"] = false; } $m["iconCls"] = ""; $m["index"] = $index++; $m["depth"] = $depth; $c = get_analysis($id, $depth + 1); if (count($c) <= 0) { $m["leaf"] = true; } else { $m["children"] = $c; $m["expandable"] = true; $m["expanded"] = true; $m["loaded"] = true; } } return $rs; }
function delete_child_recursive($id) { $q = " select id from analysis_price where pid = {$id} "; $rs = Jaring::db_execute($q, null, true); foreach ($rs as $row) { delete_child_recursive($row["id"]); } $q = " delete from analysis_price where id = {$id} "; Jaring::db_execute($q, null, false); }
function request_delete_before($data) { // do not delete user admin of profile. foreach ($data as $d) { $ug_id = $d["id"]; $q = "\n\t\t\tselect\tcount(PA._user_id) as n\n\t\t\tfrom\t_profile_admin\tPA\n\t\t\t,\t\t_user_group\t\tUG\n\t\t\twhere\tPA._user_id\t\t= UG._user_id\n\t\t\tand\t\tUG.id\t\t\t= {$ug_id}\n\t\t\t"; $rs = Jaring::db_execute($q, null); if ((int) $rs[0]["n"] > 0) { throw new Exception(Jaring::$MSG_ADMIN_PROFILE); } } }
function request_delete_before($data) { foreach ($data as $d) { $user_id = $d["id"]; if ($user_id === 1 || $user_id === "1") { throw new Exception(Jaring::$MSG_DATA_LOCK); } $q = "\n\t\t\tselect\tcount(_user_id) as n\n\t\t\tfrom\t_profile_admin\n\t\t\twhere\t_user_id = {$user_id}\n\t\t\t"; $rs = Jaring::db_execute($q, null); if ((int) $rs[0]["n"] > 0) { throw new Exception(Jaring::$MSG_ADMIN_PROFILE); } } return true; }
function request_delete_before($data) { foreach ($data as $d) { // delete file $q = "\tselect path\n\t\t\t\tfrom " . Jaring::$_mod["db_table"]["name"] . "\n\t\t\t\twhere id = " . $d["id"]; $rs = Jaring::db_execute($q); if (count($rs) > 0) { $f = APP_PATH . $rs[0]["path"]; if (file_exists($f)) { unlink($f); } } // delete link to media table. $q = "delete from _media_table where _media_id = " . $d["id"]; Jaring::db_execute($q, null, false); } return true; }
/* Copyright 2014 - Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ // insert into media table $table = "_media"; $fields = ["id", "name", "extension", "size", "mime", "path"]; $fupath = Jaring::$_media_dir . sha1_file($_FILES["content"]["tmp_name"]); Jaring::db_prepare_insert($table, $fields); $pi = pathinfo($_FILES["content"]["name"]); $bindv = []; $bindv[] = Jaring::db_generate_id(); $bindv[] = $pi["filename"]; $bindv[] = $pi["extension"]; $bindv[] = $_FILES["content"]["size"]; $bindv[] = $_FILES["content"]["type"]; $bindv[] = $fupath; Jaring::$_db_ps->execute($bindv); Jaring::$_db_ps->closeCursor(); move_uploaded_file($_FILES["content"]["tmp_name"], APP_PATH . "/" . $fupath); // link media id into table _media_table $id = $bindv[0]; $table = "_media_table"; $fields = ["table_id", "_media_id"]; $bindv = [$_POST["table_id"], $id]; Jaring::db_prepare_insert($table, $fields); Jaring::$_db_ps->execute($bindv); Jaring::$_db_ps->closeCursor(); Jaring::$_out["success"] = true; Jaring::$_out["data"] = Jaring::$MSG_SUCCESS_CREATE;
- mhd.sulhan (m.shulhan@gmail.com) */ foreach ($data as $d) { //{{{ delete all file $q = "\tselect\tM.path\n\t\t\tfrom\t_media\t\t\tM\n\t\t\t,\t\t_media_table\tMT\n\t\t\twhere\tM.id\t\t= MT._media_id\n\t\t\tand\t\tMT.table_id\t= '" . $d["table_id"] . "'"; $rs = Jaring::db_execute($q); foreach ($rs as $k => $v) { $f = APP_PATH . $v["path"]; if (file_exists($f)) { unlink($f); } } //}}} //{{{ delete data from _media_table $media_id = $d["_media_id"]; $bindv = []; $bindv[] = $d["table_id"]; $bindv[] = $media_id; $table = "_media_table"; $fids = ["table_id", "_media_id"]; Jaring::db_prepare_delete($table, $fids); Jaring::$_db_ps->execute($bindv); Jaring::$_db_ps->closeCursor(); //}}} //{{{ delete data from media $q = " delete from _media where id = " . $media_id; Jaring::db_execute($q); //}}} } Jaring::$_out['success'] = true; Jaring::$_out['data'] = Jaring::$MSG_SUCCESS_DESTROY;
function request_delete_before($data) { foreach ($data as $d) { $user_id = $d["_user_id"]; $profile_id = $d["id"]; if ($profile_id === 1) { throw new Exception(Jaring::$MSG_DATA_LOCK); } // delete menu access. $q = "\n\t\t\tdelete from _group_menu where _group_id in (\n\t\t\t\tselect\tid\n\t\t\t\tfrom\t_group\n\t\t\t\twhere\t_profile_id = {$profile_id}\n\t\t\t)\n\t\t\t"; Jaring::db_execute($q, null, false); // delete group of user. $q = " delete from _user_group where _profile_id = {$profile_id}"; Jaring::db_execute($q, null, false); // delete group. $q = " delete from _group where _profile_id = {$profile_id}"; Jaring::db_execute($q, null, false); // set admin of profile back to be owned by super admin. $q = "\n\t\t\tupdate\t_user\n\t\t\tset\t\t_profile_id = 1\n\t\t\twhere\tid\t\t\t= (\n\t\t\t\tselect\t_user_id\n\t\t\t\tfrom\t_profile_admin\n\t\t\t\twhere\t_profile_id = {$profile_id}\n\t\t\t)\n\t\t\t"; Jaring::db_execute($q, null, false); // delete users. $q = " delete from _user where _profile_id = {$profile_id}"; Jaring::db_execute($q, null, false); // delete profile admin $q = " delete from _profile_admin where _profile_id = {$profile_id} "; Jaring::db_execute($q, null, false); } return true; }
<?php /* Copyright 2014 Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ $no_cookies = true; require_once "../../../init.php"; Jaring::db_init(); $q = "select logo_type, logo from _profile where id = ?"; Jaring::$_db_ps = Jaring::$_db->prepare($q); Jaring::$_db_ps->execute(array($_GET["_profile_id"])); Jaring::$_db_ps->bindColumn(1, $type, PDO::PARAM_STR); Jaring::$_db_ps->bindColumn(2, $lob, PDO::PARAM_LOB); Jaring::$_db_ps->fetch(PDO::FETCH_BOUND); header("Content-Type: {$type}"); echo $lob;
<?php /* Copyright 2014 - Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ Jaring::db_prepare_insert(Jaring::$_mod["db_table"]["name"], Jaring::$_mod["db_table"]["create"]); $pi = pathinfo($_FILES["content"]["name"]); $fupath = Jaring::$_media_dir . sha1_file($_FILES["content"]["tmp_name"]); $bindv = []; $bindv[] = Jaring::$_c_profile_id; $bindv[] = Jaring::db_generate_id(); $bindv[] = "" === $_POST["name"] ? $pi["filename"] : $_POST["name"]; $bindv[] = $pi["extension"]; $bindv[] = $_FILES["content"]["size"]; $bindv[] = $_FILES["content"]["type"]; $bindv[] = $_POST["description"]; $bindv[] = $fupath; Jaring::$_db_ps->execute($bindv); Jaring::$_db_ps->closeCursor(); move_uploaded_file($_FILES["content"]["tmp_name"], APP_PATH . "/" . $fupath); Jaring::$_out["success"] = true; Jaring::$_out["data"] = Jaring::$MSG_SUCCESS_CREATE;
<?php /* Copyright 2014 Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ require_once "init.php"; $i = 1; $q = ""; $t = 0; $r = array('success' => false, 'data' => '', 'total' => 0); try { Jaring::db_init(); } catch (Exception $e) { $r['data'] = $e->getMessage(); echo json_encode($r); die; }
$fields[] = "name"; $bindv[] = $_POST["name"]; } $fields[] = "description"; $bindv[] = $_POST["description"]; $bindv[] = $_POST["id"]; } else { $fields = Jaring::$_mod["db_table"]["update"]; // delete old file content $q = " select path from _media where id = " . $_POST["id"]; $rs = Jaring::db_execute($q); if (count($rs) > 0) { unlink(APP_PATH . "/" . $rs[0]["path"]); } // update data $pi = pathinfo($_FILES["content"]["name"]); $bindv[0] = "" === $_POST["name"] ? $pi["filename"] : $_POST["name"]; $bindv[1] = $pi["extension"]; $bindv[2] = $_FILES["content"]["size"]; $bindv[3] = $_FILES["content"]["type"]; $bindv[4] = $_POST["description"]; $bindv[5] = Jaring::$_media_dir . $sha1; } Jaring::db_prepare_update($table, $fields, $ids); Jaring::$_db_ps->execute($bindv); Jaring::$_db_ps->closeCursor(); if ($_FILES["content"]["error"] === UPLOAD_ERR_OK) { move_uploaded_file($_FILES["content"]["tmp_name"], APP_PATH . "/" . $bindv[5]); } Jaring::$_out["success"] = true; Jaring::$_out["data"] = Jaring::$MSG_SUCCESS_UPDATE;
} $qwhere .= " and " . $v[0] . " = " . $v[1]; } // find GET parameter that match with table fields // and use it's value to filter data foreach ($fread as $v) { $f = explode(".", $v)[1]; if (array_key_exists($f, $_GET)) { $x = $_GET[$f]; if (!is_numeric($x)) { $x = "'" . $x . "'"; } $qwhere .= " and " . $v . " = " . $x; } } // generate filter $qwhere .= " and ( "; foreach (Jaring::$_mod["db_table"]["search"] as $k => $v) { if ($k > 0) { $qwhere .= " or "; } $qwhere .= $v . " like " . $query; } $qwhere .= " ) "; // Get total rows $qtotal = " select COUNT(" . Jaring::$_mod["db_table"]["id"][0] . ") as total " . $qfrom . $qwhere; // Get data $qread = $qselect . $qfrom . $qwhere . $qorder . $qlimit; Jaring::$_out["total"] = (int) Jaring::db_execute($qtotal)[0]["total"]; Jaring::$_out["data"] = Jaring::db_execute($qread); Jaring::$_out["success"] = true;
<?php /* Copyright 2014 Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ define("APP_PATH", realpath(dirname(__FILE__) . "/../") . "/"); function __autoload($class_name) { require_once APP_PATH . "/lib/" . $class_name . ".php"; } Jaring::init(); if (!isset($no_cookies)) { Jaring::cookies_check(); }
<?php /* Copyright 2014 Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ define("APP_PATH", realpath(dirname(__FILE__))); function __autoload($class_name) { include APP_PATH . "/lib/" . $class_name . ".php"; } Jaring::init(); if (Jaring::$_c_uid != 0) { header("Location:" . Jaring::$_mod_main); } else { header("Location:" . Jaring::$_mod_home); }
<?php /* Copyright 2014 - Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ require_once "../../../init.php"; $fields = ["MT.table_id", "MT._media_id", "M.name", "M.extension", "M.size", "M.mime", "M.description", "M.path"]; Jaring::$_mod["db_table"]["name"] = ["_media M", "_media_table MT"]; Jaring::$_mod["db_table"]["id"] = array_slice($fields, 0, 2); Jaring::$_mod["db_table"]["read"] = $fields; Jaring::$_mod["db_table"]["relation"] = [["M.id", "MT._media_id"]]; Jaring::$_mod["db_table"]["search"] = ["M.name", "M.extension", "M.mime", "M.description"]; Jaring::$_mod["db_table"]["order"] = ["MT._media_id"]; Jaring::$_mod["db_table"]["create"] = array_slice($fields, 0, 2); Jaring::$_mod["db_table"]["update"] = $fields; Jaring::$_mod["db_table"]["generate_id"] = "id"; Jaring::request_handle("action");
public static function db_prepare_delete($table, $fields) { $qdelete = " delete from {$table}"; $qwhere = " where " . self::db_prepare_fields($fields); self::$_db_ps = self::$_db->prepare($qdelete . $qwhere); }
<?php /* Copyright 2014 Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ require_once "../../init.php"; Jaring::$_mod["db_table"]["name"] = "_group"; Jaring::$_mod["db_table"]["create"] = ["_profile_id", "id", "pid", "name"]; Jaring::$_mod["db_table"]["update"] = ["pid", "name"]; function request_delete_before($data) { // Disallow user to delete group super admin foreach ($data as $d) { if ($d["id"] === "1") { throw new Exception(Jaring::$MSG_DATA_LOCK); } } // Delete group menu access $q = "delete from _group_menu where _group_id = ?"; foreach ($data as $d) { $ps = Jaring::$_db->prepare($q); $ps->execute(array($d["id"])); $ps->closeCursor(); } return true; } Jaring::request_handle("crud");
<?php /* Copyright 2014 - Mhd Sulhan Authors: - mhd.sulhan (m.shulhan@gmail.com) */ $query = "%" . $_GET["query"] . "%"; $start = (int) $_GET["start"]; $limit = (int) $_GET["limit"]; $gid = $_GET['_group_id']; if ($gid <= 0) { throw new Exception("Invalid group ID (" . $gid . ") !"); } $qfrom = " from _user "; $qwhere = "\n\t\twhere\t\tid not in (\n\t\t\t select\t_user_id\n\t\t\t from\t_user_group\n\t\t\t where\t_group_id = ?\n\t\t)\n\t\tand\t\t\t(\n\t\t\t\tname\t\tlike ?\n\t\t\tor\trealname\tlike ?\n\t\t)"; $qorder = " order by realname "; $qlimit = " limit {$start} , {$limit} "; $qbind = array($gid, $query, $query); if (Jaring::$_c_profile_id !== 1) { $qwhere .= " and _profile_id = " . Jaring::$_c_profile_id; } // Query total. $qtotal = " select\tCOUNT(id) as total " . $qfrom . $qwhere; // Query data. $q = "\n\tselect\t\tid\t\t\tas _user_id\n\t,\t\t\trealname\tas _user_realname" . $qfrom . $qwhere . $qorder . $qlimit; Jaring::$_out['total'] = Jaring::db_execute($qtotal, $qbind)[0]["total"]; Jaring::$_out['data'] = Jaring::db_execute($q, $qbind); Jaring::$_out['success'] = true;