diff --git a/index.php b/index.php index 43f1da5..539ed42 100644 --- a/index.php +++ b/index.php @@ -8,12 +8,13 @@ $dictionary_to_load = (isset($_GET['dict'])) ? intval($_GET['dict']) : 0; $the_public_dictionary = '"That dictionary doesn\'t exist."'; $dictionary_name = 'ERROR'; $dictionary_creator = 'nobody'; -$is_viewing = $dictionary_to_load > 0; $word_to_load = (isset($_GET['word'])) ? intval($_GET['word']) : 0; $the_public_word = '"That word doesn\'t exist."'; $word_name = 'ERROR'; +$display_mode = ($dictionary_to_load > 0) ? (($word_to_load > 0) ? "word" : "view") : "build"; + $announcement = get_include_contents(SITE_LOCATION . '/announcement.php'); $notificationMessage = ""; @@ -27,35 +28,66 @@ if ($current_user > 0 || !isset($_SESSION['loginfailures']) || (isset($_SESSION[ require_once(SITE_LOCATION . '/php/notificationconditiontree.php'); -if ($is_viewing) { - $query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`words`, `d`.`parts_of_speech`, `d`.`is_complete` "; - $query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` WHERE `d`.`is_public`=1 AND `d`.`id`=" . $dictionary_to_load . ";"; - +if ($display_mode != "build") { $dbconnection = new PDO('mysql:host=' . DATABASE_SERVERNAME . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD); $dbconnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbconnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $dbconnection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); - try { - $queryResults = $dbconnection->prepare($query); - $queryResults->execute(); - if ($queryResults) { - if (num_rows($queryResults) === 1) { - while ($dict = fetch($queryResults)) { - $dictionary_name = $dict['name']; - $dictionary_creator = $dict['public_name']; - $the_public_dictionary = '{"name":"' . $dict['name'] . '",'; - $the_public_dictionary .= '"description":"' . $dict['description'] . '",'; - $the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",'; - $the_public_dictionary .= '"words":' . $dict['words'] . ','; - $the_public_dictionary .= '"settings":{'; - $the_public_dictionary .= '"partsOfSpeech":"' . $dict['parts_of_speech'] . '",'; - $the_public_dictionary .= '"isComplete":' . (($dict['is_complete'] == 1) ? 'true' : 'false') . '},'; - $the_public_dictionary .= '}'; + + if ($display_mode == "word") { + // only query for specific word. + $query = "SELECT `d`.`name` AS `dname`, `u`.`public_name`, `w`.`word_id`, `w`.`name`, `w`.`pronunciation`, `w`.`part_of_speech`, `w`.`simple_definition`, `w`.`long_definition` "; + $query .= "FROM `words` AS `w` LEFT JOIN `dictionaries` AS `d` ON `w`.`dictionary`=`d`.`id` "; + $query .= "LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` "; + $query .= "WHERE `d`.`is_public`=1 AND `w`.`dictionary`=" . $dictionary_to_load . " AND `w`.`word_id`=" . $dictionary_to_load . ";"; + + try { + $queryResults = $dbconnection->prepare($query); + $queryResults->execute(); + if ($queryResults) { + if (num_rows($queryResults) === 1) { + while ($word = fetch($queryResults)) { + $dictionary_name = $word['dname']; + $dictionary_creator = $word['public_name']; + $the_public_word = '{"name":"' . $word['name'] . '",'; + $the_public_word .= '"pronunciation":"' . $word['pronunciation'] . '",'; + $the_public_word .= '"partOfSpeech":"' . $word['part_of_speech'] . '",'; + $the_public_word .= '"simpleDefinition":"' . $word['simple_definition'] . '",'; + $the_public_word .= '"longDefinition":"' . $word['long_definition'] . '",'; + $the_public_word .= '"wordId":"' . $word['word_id'] . '"'; + $the_public_word .= '}'; + } } } } + catch (PDOException $ex) {} + } else { + // Otherwise, grab everything. + $query = "SELECT `d`.`id`, `d`.`name`, `d`.`description`, `u`.`public_name`, `d`.`parts_of_speech`, `d`.`is_complete` "; + $query .= "FROM `dictionaries` AS `d` LEFT JOIN `users` AS `u` ON `d`.`user`=`u`.`id` WHERE `d`.`is_public`=1 AND `d`.`id`=" . $dictionary_to_load . ";"; + + try { + $queryResults = $dbconnection->prepare($query); + $queryResults->execute(); + if ($queryResults) { + if (num_rows($queryResults) === 1) { + while ($dict = fetch($queryResults)) { + $dictionary_name = $dict['name']; + $dictionary_creator = $dict['public_name']; + $the_public_dictionary = '{"name":"' . $dict['name'] . '",'; + $the_public_dictionary .= '"description":"' . $dict['description'] . '",'; + $the_public_dictionary .= '"createdBy":"' . $dict['public_name'] . '",'; + $the_public_dictionary .= '"words":' . Get_Dictionary_Words($dictionary_to_load) . ','; + $the_public_dictionary .= '"settings":{'; + $the_public_dictionary .= '"partsOfSpeech":"' . $dict['parts_of_speech'] . '",'; + $the_public_dictionary .= '"isComplete":' . (($dict['is_complete'] == 1) ? 'true' : 'false') . '},'; + $the_public_dictionary .= '}'; + } + } + } + } + catch (PDOException $ex) {} } - catch (PDOException $ex) {} } ?> @@ -65,20 +97,29 @@ if ($is_viewing) { - - <?php echo $dictionary_name; ?> Dictionary on Lexiconga - + + <?php echo (($display_mode == "word") ? ($word_name . " | ") : "") . $dictionary_name; ?> Dictionary on Lexiconga + " /> - + Dictionary" /> - - + + + + + Lexiconga Dictionary Builder + + + + + - - + +
@@ -99,7 +140,7 @@ if ($is_viewing) {
- +
;margin-bottom:10px;"> Close
@@ -142,35 +183,36 @@ if ($is_viewing) {
- + Settings

- +

- HideShow Description -
+ HideShow Description +
blocknone;">
- Hide Search/Filter Options -
+ + Hide Search/Filter Options +
blocknone;">
@@ -178,25 +220,28 @@ if ($is_viewing) {
- + ;"> Check All   - + ;"> Uncheck All
+ -
+
+ document.write(DictionaryEntryTemplate(" . $the_public_word . "));"; } ?> +
- +