diff options
author | Jayaram Pai | 2014-04-26 14:54:09 +0530 |
---|---|---|
committer | Jayaram Pai | 2014-04-26 14:54:09 +0530 |
commit | 430133242f89015f4ffc500fb34eedf2324ec3a1 (patch) | |
tree | c1a3dadd857a61576176876e2a045b38559b282f | |
download | textbook_companion_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.tar.gz textbook_companion_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.tar.bz2 textbook_companion_fixer-430133242f89015f4ffc500fb34eedf2324ec3a1.zip |
initial commit
-rw-r--r-- | css/scilab_fixer.css | 29 | ||||
-rw-r--r-- | js/scilab_fixer.js | 117 | ||||
-rwxr-xr-x | scilab_fixer.info | 3 | ||||
-rwxr-xr-x | scilab_fixer.module | 166 |
4 files changed, 315 insertions, 0 deletions
diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css new file mode 100644 index 0000000..c001482 --- /dev/null +++ b/css/scilab_fixer.css @@ -0,0 +1,29 @@ +#fix-caption-form #edit-caption { + width: 99% !important; +} +#fix-caption-form .well { + margin-top: 25px; +} +#fix-caption-page #updating, +#fix-caption-page #done { + display: none; + position: fixed; + z-index: 2000; + left: 55%; + top: 45%; + padding: 5px 10px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + -o-border-radius: 5px; + border-radius: 5px; + -webkit-box-shadow: 0px 0px 10px #cccccc; + -moz-box-shadow: 0px 0px 10px #cccccc; + -obox-shadow: 0px 0px 10px #cccccc; + box-shadow: 0px 0px 10px #cccccc; +} +#fix-caption-page #updating { + background: #FF851B; +} +#fix-caption-page #done { + background: #2ECC40; +} diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js new file mode 100644 index 0000000..43450f3 --- /dev/null +++ b/js/scilab_fixer.js @@ -0,0 +1,117 @@ +$(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "fix/"; + + $category = $("#fix-caption-form #edit-category"); + $book = $("#fix-caption-form #edit-book"); + $chapter = $("#fix-caption-form #edit-chapter"); + $example = $("#fix-caption-form #edit-example"); + $caption = $("#fix-caption-form #edit-caption"); + $code = $("#fix-caption-form #fix-caption-code"); + $form = $("#scilab-fixer-caption-form"); + $updating = $("#fix-caption-page #updating"); + $done = $("#fix-caption-page #done"); + + function reset() { + for (var i = 0, l = arguments.length; i < l; i ++) { + switch(arguments[i]) { + case "book": + $book.html("<option value='0'>Please select a book</option>"); + break; + + case "chapter": + $chapter.html("<option value='0'>Please select a chapter</option>"); + break; + + case "example": + $example.html("<option value='0'>Please select a example</option>"); + break; + + } + } + } + + $category.change(function() { + reset("book", "chapter", "example"); + var category_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/category/" + category_id, + type: "POST", + dataType: "html", + success: function(data) { + $book.html(data); + } + }); + }); + + $book.change(function() { + reset("chapter", "example"); + var book_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/book/" + book_id, + type: "POST", + dataType: "html", + success: function(data) { + $chapter.html(data); + } + }); + }); + + $chapter.change(function() { + reset("example"); + var chapter_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/chapter/" + chapter_id, + type: "POST", + dataType: "html", + success: function(data) { + $example.html(data); + } + }); + }); + + $example.change(function() { + var example_id = $(this).val(); + + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + $code.html(code); + var caption = $(data).filter("#caption").html(); + $caption.val(caption); + } + }); + }); + + $form.submit(function(e) { + var example_id = $example.val(); + if(example_id != "0") { + var caption = $caption.val(); + $updating.show(); + $.ajax({ + url: modPath + "ajax/update/", + type: "POST", + data: { + example_id: example_id, + caption: caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); +}); diff --git a/scilab_fixer.info b/scilab_fixer.info new file mode 100755 index 0000000..b8707ea --- /dev/null +++ b/scilab_fixer.info @@ -0,0 +1,3 @@ +name = Scilab fixer +description = Module to fix scilab bugs +core = 6.x diff --git a/scilab_fixer.module b/scilab_fixer.module new file mode 100755 index 0000000..4cfd892 --- /dev/null +++ b/scilab_fixer.module @@ -0,0 +1,166 @@ +<?php + function scilab_fixer_menu() { + $items = array(); + $items["fix/caption"] = array( + "title" => "Fix TBC captions", + "page callback" => "scilab_fixer_caption_all", + "access arguments" => array("fix scilab"), + "type" => MENU_NORMAL_ITEM + ); + $items["fix/ajax"] = array( + "page callback" => "scilab_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + return $items; + } + + function scilab_fixer_perm() { + return array( + "fix scilab", + ); + } + + function scilab_fixer_caption_form($form_state) { + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title"=> "Caption change form", + "#prefix" => "<div id='fix-caption-form'>", + "#suffix" => "</div>", + ); + $form["wrapper"]["category"] = array( + "#type" => "select", + "#title" => t("Please select the category"), + '#options' => array( + 0 => 'Please select a category', + 1 => 'Fluid Mechanics', + 2 => 'Control Theory & Control Systems', + 3 => 'Chemical Engineering', + 4 => 'Thermodynamics', + 5 => 'Mechanical Engineering', + 6 => 'Signal Processing', + 7 => 'Digital Communications', + 8 => 'Electrical Technology', + 9 => 'Mathematics & Pure Science', + 10 => 'Analog Electronics', + 11 => 'Digital Electronics', + 12 => 'Computer Programming', + 13 => 'Others' + ), + ); + $form["wrapper"]["book"] = array( + "#type" => "select", + "#title" => t("Please select the book."), + "#options" => array( + 0 => "Please select a book" + ) + ); + $form["wrapper"]["chapter"] = array( + "#type" => "select", + "#title" => t("Please select the chapter"), + "#options" => array( + 0 => "Please select a chapter" + ) + ); + $form["wrapper"]["example"] = array( + "#type" => "select", + "#title" => t("Please select the example"), + "#options" => array( + 0 => "Please select a example" + ) + ); + $form["wrapper"]["caption"] = array( + "#type" => "textfield", + "#title" => t("Enter new caption"), + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update" + ); + $form["wrapper"]["code"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#prefix" => "<div class='well'><pre id='fix-caption-code'>", + "#suffix" => "</pre></div>", + ); + return $form; + } + + function scilab_fixer_caption_all() { + $page_content = ""; + $page_content .= "<div id='fix-caption-page'>"; + $page_content .= "<center><span id='updating'>Updating...</span></center>"; + $page_content .= "<span id='done'>Done.</span>"; + $page_content .= drupal_get_form("scilab_fixer_caption_form"); + $page_content .= "</div>"; + return $page_content; + } + + function scilab_fixer_ajax($item, $key) { + $data = ""; + if($item == "category" && $key) { + $query = " + SELECT pre.id AS id, pre.book, pre.author FROM textbook_companion_preference pre + LEFT JOIN textbook_companion_proposal pro ON pro.id = pre.proposal_id + WHERE pro.proposal_status = 3 AND pre.approval_status = 1 AND pre.category = %d + ORDER BY pre.book ASC + "; + $result = db_query($query, $key); + + $data .= "<option value='0'>Please select the book.</option>"; + while($row = db_fetch_object($result)) { + $data .= "<option value='{$row->id}'>{$row->book}</option>"; + } + } else if($item == "book" && $key) { + $query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key); + + $data .= "<option value='0'>Please select the chapter.</option>"; + while($row = db_fetch_object($result)) { + $data .= "<option value='{$row->id}'>{$row->number} {$row->name}</option>"; + } + } else if($item == "chapter" && $key) { + $query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key); + + $data .= "<option value='0'>Please select the example.</option>"; + while($row = db_fetch_object($result)) { + $data .= "<option value='{$row->id}'>{$row->number} {$row->caption}</option>"; + } + } else if($item == "example" && $key) { + $query = " + SELECT * FROM textbook_companion_example_files fil + LEFT JOIN textbook_companion_example exa ON exa.id = fil.example_id + WHERE example_id = %d + "; + $result = db_query($query, $key); + $row = db_fetch_object($result); + /* fetching example file data */ + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + $example = file_get_contents($example_path); + $data .= "<div id='caption'>{$row->caption}</div>"; + $data .= "<div id='code'>{$example}</div>"; + } else if($item == "update") { + $example_id = $_POST["example_id"]; + $caption = $_POST["caption"]; + $query = " + UPDATE textbook_companion_example + SET caption = '%s' + WHERE id = %d + "; + $result = db_query($query, $caption, $example_id); + $data .= "Updated"; + } else { + $data = "Nothing to display."; + } + echo $data; + exit(); + } + + function scilab_fixer_init() { + drupal_add_css(drupal_get_path("module", "scilab_fixer") . "/css/scilab_fixer.css"); + drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/scilab_fixer.js"); + } +?> |