$action = isset($_GET['action']) ? $_GET['action'] : $action; switch ($action) { case "modCat": modifyCategory($_POST); break; case "modCatS": modifyCategoryS($_POST); break; case "modCatall": modifyCategoryAll(); break; case "addCat": addCategory($_POST); break; case "delCat": delCategory($_POST, $_GET); break; default: catManager(); break; } /* if (isset($_POST)) { foreach ($_POST as $k => $v) { ${$k} = $v; } } if (isset($_GET['action'])) { $action = $_GET['action']; }
// Default Action if (isset($_GET[ACTION_TYPE]) && $_GET[ACTION_TYPE] != NULL) { switch ($_GET[ACTION_TYPE]) { case ACTION_EDIT: $actionType = ACTION_EDIT; checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[CATEGORY_ID]); checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[CATEGORY_NAME]); checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[SECTION_ID]); checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[PARENT_CATEGORY_ID]); editCategory(); exit; break; case ACTION_DEL: $actionType = ACTION_DEL; checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[CATEGORY_ID]); delCategory(); exit; break; case ACTION_ADD: default: break; } } checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[CATEGORY_NAME]); checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[SECTION_ID]); checkNullwithRedirect(ADD_CATEGORY_PAGE, $_GET[PARENT_CATEGORY_ID]); addCategory(); function addCategory() { // TODO : Escape String for SQL Statement $categoryName = $_GET[CATEGORY_NAME];
function delCategory($catNo) { $query = 'SELECT * FROM Category ' . 'WHERE ' . catParent . " = '{$catNo}'"; $result = DB::query($query, false); if ($result == null) { $query = 'DELETE FROM Category WHERE ' . catNo . " = '{$catNo}'"; return DB::query($query); } //del all subcat first while ($row = $result->fetch_assoc()) { if (delCategory($row[catNo]) == false) { return false; } } }