From 7e9c14a7c2cb09f6fd585646246a9ac54a0d2021 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Mon, 13 Jun 2016 21:26:05 -0700 Subject: [PATCH] Updated database to store and read current dictionary in `users` table. --- php/ajax_dictionarymanagement.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/php/ajax_dictionarymanagement.php b/php/ajax_dictionarymanagement.php index f56e105..d038900 100644 --- a/php/ajax_dictionarymanagement.php +++ b/php/ajax_dictionarymanagement.php @@ -57,7 +57,7 @@ function Get_Dictionaries($return_list = true) { function Load_Current_Dictionary() { if ($_SESSION['user'] > 0) { $query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`words`, `d`.`next_word_id`, `d`.`allow_duplicates`, `d`.`case_sensitive`, `d`.`parts_of_speech`, `d`.`sort_by_equivalent`, `d`.`is_complete`, `d`.`is_public` "; - $query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `user`=`u`.`id` WHERE `is_current`=1 AND `user`=" . $_SESSION['user'] . ";"; + $query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `user`=`u`.`id` WHERE `d`.`id`=`u`.`current_dictionary` AND `user`=" . $_SESSION['user'] . ";"; $dictionary = query($query); if ($dictionary) { @@ -103,8 +103,8 @@ function Save_Current_DictionaryAsNew() { $dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); - $query = "INSERT INTO `dictionaries`(`user`, `is_current`, `name`, `description`, `words`, `next_word_id`, `allow_duplicates`, `case_sensitive`, `parts_of_speech`, `sort_by_equivalent`, `is_complete`, `is_public`) "; - $query .= "VALUES (" . $_SESSION['user'] . ",0,'" . $_POST['name'] . "','" . $_POST['description'] . "','" . $_POST['words'] . "'," . $_POST['nextwordid'] . "," . $_POST['allowduplicates'] . "," . $_POST['casesensitive'] . ",'" . $_POST['partsofspeech'] . "'," . $_POST['sortbyequivalent'] . "," . $_POST['iscomplete'] . "," . $_POST['ispublic'] . ")"; + $query = "INSERT INTO `dictionaries`(`user`, `name`, `description`, `words`, `next_word_id`, `allow_duplicates`, `case_sensitive`, `parts_of_speech`, `sort_by_equivalent`, `is_complete`, `is_public`) "; + $query .= "VALUES (" . $_SESSION['user'] . ",'" . $_POST['name'] . "','" . $_POST['description'] . "','" . $_POST['words'] . "'," . $_POST['nextwordid'] . "," . $_POST['allowduplicates'] . "," . $_POST['casesensitive'] . ",'" . $_POST['partsofspeech'] . "'," . $_POST['sortbyequivalent'] . "," . $_POST['iscomplete'] . "," . $_POST['ispublic'] . ")"; try { $update = $dbconnection->prepare($query); @@ -185,8 +185,7 @@ function Switch_Current_Dictionary($newdictionaryid, $returndictionary = true) { if (isset($newdictionaryid)) { if (in_array($newdictionaryid, $_SESSION['dictionaries'])) { //Clear is_current from all user's dictionaries and then update the one they chose, only if the chosen dictionary is valid. - $query = "UPDATE `dictionaries` SET `is_current`=0 WHERE `user`=" . $_SESSION['user'] . ";"; - $query .= "UPDATE `dictionaries` SET `is_current`=1 WHERE `id`=" . $newdictionaryid . " AND `user`=" . $_SESSION['user'] . ";"; + $query .= "UPDATE `users` SET `current_dictionary`=" . $newdictionaryid . " WHERE `id`=" . $_SESSION['user'] . ";"; $update = query($query); if ($update) {