/** * function actionEdit: * processes subaction and calls getQuizEditForm function which renders edit interface */ public function actionEdit() { // dataSource: the $dataSource argument to get*Form() functions specifies where to persist data for the form from. // if a submit was in progress, and the submit was successful, we set dataSource to db. // else, we set dataSource to POST, because we need to present the user's entered values, rather than existing values // so that he/she may make changes and submit again, with least hassle. if (isset($_GET['subaction'])) { switch ($_GET['subaction']) { case 'addsections': if (!$this->isValidId($_POST['txtSectionCount'])) { displayerror('Error. No count specified.'); } else { $count = escape($_POST['txtSectionCount']); if (addSections($this->moduleComponentId, $count) !== false) { displayinfo('Section(s) added successfully.'); } } break; case 'editsection': $dataSource = 'db'; if (!$this->isValidId($_GET['sectionid'])) { displayerror('Error. Invalid section id specified.'); } elseif (isset($_POST['btnSubmit'])) { $dataSource = 'POST'; if (submitSectionEditForm($this->moduleComponentId, intval($_GET['sectionid']))) { displayinfo('Section properties saved successfully.'); $dataSource = 'db'; } } return getSectionEditForm($this->moduleComponentId, intval($_GET['sectionid']), $dataSource); break; case 'deletesection': if (!$this->isValidId($_POST['hdnSectionId'])) { displayerror('Error. Invalid section id specified.'); } elseif (deleteSection($this->moduleComponentId, intval($_POST['hdnSectionId']))) { displayinfo('The specified section was successfully deleted.'); } break; case 'movesection': if (!$this->isValidId($_GET['sectionid'])) { displayerror('Error. Invalid section id specified.'); } elseif (!isset($_GET['direction']) || $_GET['direction'] != 'up' && $_GET['direction'] != 'down') { displayerror('Error. No or invalid direction specified. Could not move section.'); } elseif (moveSection($this->moduleComponentId, intval($_GET['sectionid']))) { displayinfo('The specified section was successfully moved.'); } break; case 'addquestions': if (!$this->isValidId($_GET['sectionid'])) { displayerror('Error. No or invalid section id specified. Could not add question.'); } elseif (!$this->isValidId($_POST['txtQuestionCount'])) { displayerror('Error. No or invalid count specified. Could not add question.'); } else { $count = intval($_POST['txtQuestionCount']); $insertIds = addQuestions($this->moduleComponentId, intval($_GET['sectionid']), $count); if ($insertIds !== false) { displayinfo('New question(s) added successfully.'); } } break; case 'editquestion': $dataSource = 'db'; if (!$this->isValidId($_GET['sectionid']) || !$this->isValidId($_GET['questionid'])) { displayerror('Error. Invalid section or question specified.'); } elseif (isset($_POST['btnSubmit'])) { $dataSource = 'POST'; if (submitQuestionEditForm($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']))) { displayinfo('Question properties saved successfully.'); $dataSource = 'db'; } } return getQuestionEditForm($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']), $dataSource); break; case 'deletequestion': if (!$this->isValidId($_POST['hdnSectionId']) || !$this->isValidId($_POST['hdnQuestionId'])) { displayerror('Error. Invalid section or question specified.'); } elseif (deleteQuestion($this->moduleComponentId, intval($_POST['hdnSectionId']), intval($_POST['hdnQuestionId']))) { displayinfo('Question successfully deleted.'); } break; case 'movequestion': if (!$this->isValidId($_GET['sectionid'])) { displayerror('Error. Invalid section id specified.'); } elseif (!$this->isValidId($_GET['questionid'])) { displayerror('Error. Invalid question id specified.'); } elseif (!isset($_GET['direction']) || $_GET['direction'] != 'up' && $_GET['direction'] != 'down') { displayerror('Error. No or invalid direction specified. Could not move section.'); } elseif (moveQuestion($this->moduleComponentId, intval($_GET['sectionid']), intval($_GET['questionid']), $_GET['direction'])) { displayinfo('The specified question was successfully moved.'); } break; } } if (isset($_POST['btnSetWeightMarks'])) { if (setWeightMark(intval($_POST['quizId']), intval($_POST['weight']), intval($_POST['pos']), intval($_POST['neg']))) { displayinfo('Weight - Marks saved.'); } else { displayerror('Error in changing weight mark'); } } $dataSource = 'db'; if (isset($_POST['btnSubmit'])) { $dataSource = 'POST'; if (submitQuizEditForm($this->moduleComponentId)) { $dataSource = 'db'; } } return getQuizEditForm($this->moduleComponentId, $dataSource); }
if (isset($_POST['yearInput'])) { createYear($_POST['yearInput']); header("location: index?year=" . $_POST['yearInput']); } if (isset($_POST['deletevideoid'])) { deleteVideo($_POST['deletevideoid']); } if (isset($_POST['deleteyearid'])) { deleteYear($_POST['deleteyearid']); } if (isset($_POST['updatesectionInput']) && isset($_POST['updatesectionold']) && isset($_POST['sectionsid']) && isset($_POST['updatesectionyear'])) { if ($_POST['updatesectionInput'] != "") { updateSection($_POST['updatesectionold'], $_POST['updatesectionInput'], $_POST['sectionsid'], $_POST['updatesectionyear']); header("location: index?year=" . $_POST['updatesectionyear'] . "§ion=" . $_POST['updatesectionInput']); } else { deleteSection($_POST['updatesectionold'], $_POST['updatesectionyear']); header("location: index?year=" . $_POST['updatesectionyear'] . "§ion=" . $_POST['updatesectionold']); } } ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Aikido Yoshinkai Canada</title> <link href="bootstrap/bootstrap.min.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet">
require "../includes/include.php"; if (is_numeric($_POST["id"]) && intval($_POST["id"]) > 0) { $sqlite = new SQLite3($db_str, SQLITE3_OPEN_READWRITE); $id = intval($_POST["id"]); $section = findSectionById($id); $container = null; if ($section !== false) { $container = $section["container"]; } $changes = 0; $success = false; if ($sqlite->exec("pragma foreign_keys = on")) { $delete = $sqlite->prepare("delete from sections where s_id=:id"); $delete->bindValue("id", $id, SQLITE3_INTEGER); $success = $delete->execute() !== false; $changes = $sqlite->changes(); } else { $success = deleteSection($id); } if ($success) { sortSection($container); $message = date("Y-m-d H:i:s"); } else { $message = "Unable to delete some links or sections"; } $result = ["delete" => $section, "success" => $success, "message" => $message, "changes" => $changes, "anchor" => "s" . ($container != null ? $container : "null")]; $sqlite->close(); } else { $result = ["delete" => $_POST["id"], "success" => false, "message" => "Bad request", "changes" => 0]; } print json_encode($result);
function deleteSection($id) { global $sqlite; global $changes; $rv = true; $search = $sqlite->prepare("select s_id from sections where s_container=:id"); $search->bindValue("id", $id, SQLITE3_INTEGER); $sections = $search->execute(); while ($section = $sections->fetchArray(SQLITE3_ASSOC)) { $rv &= deleteSection(intval($section["s_id"])); if (!$rv) { break; } } $sections->finalize(); $search->close(); $links = $sqlite->prepare("delete from links where l_section=:id"); $links->bindValue("id", $id, SQLITE3_INTEGER); $section = $sqlite->prepare("delete from sections where s_id=:id"); $section->bindValue("id", $id, SQLITE3_INTEGER); if ($rv && $links->execute() !== false) { $changes += $sqlite->changes(); } else { $rv = false; } if ($rv && $section->execute() !== false) { $changes++; } else { $rv = false; } $links->close(); $section->close(); return $rv; }