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; }
- 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; }
} $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) */ $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;