From 8fc6df7a0121ac49750b598de10f0e2d2a323ca3 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Sat, 26 Apr 2014 14:54:09 +0530 Subject: initial commit --- css/scilab_fixer.css | 29 +++++++++ js/scilab_fixer.js | 117 ++++++++++++++++++++++++++++++++++++ scilab_fixer.info | 3 + scilab_fixer.module | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 315 insertions(+) create mode 100644 css/scilab_fixer.css create mode 100644 js/scilab_fixer.js create mode 100755 scilab_fixer.info create mode 100755 scilab_fixer.module 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(""); + break; + + case "chapter": + $chapter.html(""); + break; + + case "example": + $example.html(""); + 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 @@ + "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" => "
", + "#suffix" => "
", + ); + $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" => "
",
+            "#suffix" => "
", + ); + return $form; + } + + function scilab_fixer_caption_all() { + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + $page_content .= drupal_get_form("scilab_fixer_caption_form"); + $page_content .= "
"; + 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 .= ""; + while($row = db_fetch_object($result)) { + $data .= ""; + } + } else if($item == "book" && $key) { + $query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key); + + $data .= ""; + while($row = db_fetch_object($result)) { + $data .= ""; + } + } else if($item == "chapter" && $key) { + $query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key); + + $data .= ""; + while($row = db_fetch_object($result)) { + $data .= ""; + } + } 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 .= "
{$row->caption}
"; + $data .= "
{$example}
"; + } 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"); + } +?> -- cgit From 82d8e9a665e5f1f64a03b4d8e33688d275a74daa Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Sat, 26 Apr 2014 16:27:44 +0530 Subject: added caption reset on example change --- css/scilab_fixer.css | 2 ++ js/scilab_fixer.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css index c001482..37097a0 100644 --- a/css/scilab_fixer.css +++ b/css/scilab_fixer.css @@ -3,6 +3,8 @@ } #fix-caption-form .well { margin-top: 25px; + width: 620px; + overflow-x: auto; } #fix-caption-page #updating, #fix-caption-page #done { diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js index 43450f3..ef05611 100644 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -27,12 +27,16 @@ $(document).ready(function() { $example.html(""); break; + case "caption": + $caption.val(""); + break; + } } } $category.change(function() { - reset("book", "chapter", "example"); + reset("book", "chapter", "example", "caption"); var category_id = $(this).val(); $.ajax({ @@ -46,7 +50,7 @@ $(document).ready(function() { }); $book.change(function() { - reset("chapter", "example"); + reset("chapter", "example", "caption"); var book_id = $(this).val(); $.ajax({ @@ -60,7 +64,7 @@ $(document).ready(function() { }); $chapter.change(function() { - reset("example"); + reset("example", "caption"); var chapter_id = $(this).val(); $.ajax({ @@ -75,6 +79,7 @@ $(document).ready(function() { $example.change(function() { var example_id = $(this).val(); + reset("caption"); $.ajax({ url: modPath + "ajax/example/" + example_id, -- cgit From cc8d9b610e9bba5bc1c3c837434e7505dcbb4712 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Tue, 29 Apr 2014 04:58:16 +0530 Subject: added author display to select:book --- scilab_fixer.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scilab_fixer.module b/scilab_fixer.module index 4cfd892..ce214cf 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -110,7 +110,7 @@ $data .= ""; while($row = db_fetch_object($result)) { - $data .= ""; + $data .= ""; } } else if($item == "book" && $key) { $query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; -- cgit From 3c2681e374383438a84009edbe96b9501c67b25f Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Tue, 29 Apr 2014 08:38:53 +0530 Subject: added feature to auto populate caption on select code text --- js/scilab_fixer.js | 1 + js/selection.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 js/selection.js diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js index ef05611..8236099 100644 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -11,6 +11,7 @@ $(document).ready(function() { $form = $("#scilab-fixer-caption-form"); $updating = $("#fix-caption-page #updating"); $done = $("#fix-caption-page #done"); + $example.attr("multiple", "enabled"); function reset() { for (var i = 0, l = arguments.length; i < l; i ++) { diff --git a/js/selection.js b/js/selection.js new file mode 100644 index 0000000..fcb738b --- /dev/null +++ b/js/selection.js @@ -0,0 +1,26 @@ +function getSelectionText(divID) { + var selectedText = ""; + if (window.getSelection) { + var sel = window.getSelection(); + var div = document.getElementById(divID); + + if (sel.rangeCount) { + // Get the selected range + var range = sel.getRangeAt(0); + // Check that the selection is wholly contained within the div text + // if (range.commonAncestorContainer == div.firstChild) { + var selectedText = range.toString(); + // } + } + } + return selectedText; +} +$(document).ready(function() { + $("#fix-caption-code").mousedown(function() { + $("#edit-caption").val(""); + }); + $("#fix-caption-code").mouseup(function() { + quotedText = getSelectionText("#fix-caption-code"); + $("#edit-caption").val(quotedText); + }); +}); -- cgit From aed2bf0e36a43aa936233e218c23c82bddd981ec Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Tue, 29 Apr 2014 08:46:18 +0530 Subject: updated uncommitted files --- css/scilab_fixer.css | 3 +++ scilab_fixer.module | 2 ++ 2 files changed, 5 insertions(+) diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css index 37097a0..2468fb4 100644 --- a/css/scilab_fixer.css +++ b/css/scilab_fixer.css @@ -6,6 +6,9 @@ width: 620px; overflow-x: auto; } +#fix-caption-form #edit-example { + height: 250px; +} #fix-caption-page #updating, #fix-caption-page #done { display: none; diff --git a/scilab_fixer.module b/scilab_fixer.module index ce214cf..fb1a831 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -94,6 +94,7 @@ $page_content .= "Done."; $page_content .= drupal_get_form("scilab_fixer_caption_form"); $page_content .= ""; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; return $page_content; } @@ -162,5 +163,6 @@ 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"); + drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/selection.js"); } ?> -- cgit From 0d8e9f1dfead4388e3842dddcfffd19d89ecc042 Mon Sep 17 00:00:00 2001 From: Jayaram R Pai Date: Thu, 26 Jun 2014 12:19:37 +0530 Subject: added interface to add aicte books --- scilab_fixer.module | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/scilab_fixer.module b/scilab_fixer.module index fb1a831..8955255 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -7,6 +7,28 @@ "access arguments" => array("fix scilab"), "type" => MENU_NORMAL_ITEM ); + $items["fix/aicte"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array("fix scilab"), + "access arguments" => array("fix scilab"), + "weight" => 30, + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte/new"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array("fix scilab"), + "weight" => 1, + "type" => MENU_DEFAULT_LOCAL_TASK + ); + $items["fix/aicte/edit"] = array( + "title" => "Edit AICTE books", + "page callback" => "scilab_fixer_aicte_edit_all", + "access arguments" => array("fix scilab"), + "weight" => 2, + "type" => MENU_LOCAL_TASK + ); $items["fix/ajax"] = array( "page callback" => "scilab_fixer_ajax", "access callback" => TRUE, @@ -160,6 +182,161 @@ exit(); } + function scilab_fixer_aicte_form($form_state, $aicte_id) { + $query = " + SELECT * FROM textbook_companion_aicte + WHERE id = {$aicte_id} + "; + $result = db_query($query); + $row = db_fetch_object($result); + + $form = array(); + $form["book"] = array( + "#type" => "textfield", + "#title" => "Book Name", + "#default_value" => $row->book, + "#required" => TRUE + ); + $form["author"] = array( + "#type" => "textfield", + "#title" => "Author", + "#default_value" => $row->author, + "#required" => TRUE + ); + $form["category"] = array( + "#type" => "select", + "#title" => "Book 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' + ), + "#default_value" => $row->category, + "#required" => TRUE + ); + $form["isbn"] = array( + "#type" => "textfield", + "#title" => "ISBN", + "#default_value" => $row->isbn, + "#required" => FALSE + ); + $form["publisher"] = array( + "#type" => "textfield", + "#title" => "Publisher", + "#default_value" => $row->publisher, + "#required" => TRUE + ); + $form["edition"] = array( + "#type" => "textfield", + "#title" => "Edition", + "#default_value" => $row->edition, + "#required" => TRUE + ); + $form["year"] = array( + "#type" => "textfield", + "#title" => "Year of publication", + "#default_value" => $row->year, + "#required" => TRUE + ); + $form["aicte_id"] = array( + "#type" => "hidden", + "#value" => $row->id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; + } + + function scilab_fixer_aicte_form_validate($form, &$form_state) { + if(!$form_state["values"]["category"]) { + form_set_error("category", "Please select a category."); + } + if(!is_numeric($form_state["values"]["edition"])) { + form_set_error("edition", "Only digits are allowed."); + } + if(!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { + form_set_error("year", "Please enter a valid year. eg: 2011."); + } + } + + function scilab_fixer_aicte_form_submit($form, &$form_state) { + $v = $form_state["values"]; + if($v["aicte_id"]) { + $query = " + UPDATE textbook_companion_aicte + SET book = '%s', author = '%s', category = %d, + isbn = '%s', publisher = '%s', edition = %d, + year = %d + WHERE id = %d + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] + ); + drupal_set_message("Book updated successfully", "status"); + } else { + $query = " + INSERT INTO textbook_companion_aicte + (book, author, category, isbn, publisher, edition, year) + VALUES + ('%s', '%s', %d, '%s', '%s', %d, %d) + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"] + ); + drupal_set_message("Book added successfully", "status"); + } + } + + function scilab_fixer_aicte_all() { + $page_content = ""; + $page_content .= drupal_get_form("scilab_fixer_aicte_form"); + return $page_content; + } + + function scilab_fixer_aicte_edit_all($aicte_id=0) { + $page_content = ""; + if($aicte_id) { + $page_content .= drupal_get_form("scilab_fixer_aicte_form", $aicte_id); + } else { + $query = " + SELECT * FROM textbook_companion_aicte + ORDER BY time DESC + "; + $result = db_query($query); + $headers = array( + "Book", "Author", + "Edition", "Action", + ); + $rows = array(); + while($row = db_fetch_object($result)) { + $item = array( + "{$row->book}", + "{$row->author}", + "{$row->edition}", + l(t("Edit"), "fix/aicte/edit/{$row->id}") + ); + array_push($rows, $item); + } + $page_content .= theme("table", $headers, $rows); + } + return $page_content; + } + 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"); -- cgit From b05847459755de88ad638973d4f351883fd00d51 Mon Sep 17 00:00:00 2001 From: Jayaram R Pai Date: Mon, 4 Aug 2014 16:16:18 +0530 Subject: added page to edit example code --- css/scilab_fixer.css | 18 ++++++---- js/scilab_fixer.js | 62 +++++++++++++++++++++++++-------- js/selection.js | 4 +-- scilab_fixer.module | 97 +++++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 154 insertions(+), 27 deletions(-) diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css index 2468fb4..964317f 100644 --- a/css/scilab_fixer.css +++ b/css/scilab_fixer.css @@ -1,16 +1,16 @@ -#fix-caption-form #edit-caption { +#fix-tbc-form #edit-caption { width: 99% !important; } -#fix-caption-form .well { +#fix-tbc-form .well { margin-top: 25px; width: 620px; overflow-x: auto; } -#fix-caption-form #edit-example { +#fix-tbc-form #edit-example { height: 250px; } -#fix-caption-page #updating, -#fix-caption-page #done { +#fix-tbc-page #updating, +#fix-tbc-page #done { display: none; position: fixed; z-index: 2000; @@ -26,9 +26,13 @@ -obox-shadow: 0px 0px 10px #cccccc; box-shadow: 0px 0px 10px #cccccc; } -#fix-caption-page #updating { +#fix-tbc-page #updating { background: #FF851B; } -#fix-caption-page #done { +#fix-tbc-page #done { background: #2ECC40; } +textarea#edit-code { + height: 300px; + width: 650px; +} diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js index 8236099..9148603 100644 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -2,15 +2,16 @@ $(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"); + $category = $("#fix-tbc-form #edit-category"); + $book = $("#fix-tbc-form #edit-book"); + $chapter = $("#fix-tbc-form #edit-chapter"); + $example = $("#fix-tbc-form #edit-example"); + $caption = $("#fix-tbc-form #edit-caption"); + $code = $("#fix-tbc-form #edit-code"); + $caption_form = $("#scilab-fixer-caption-form"); + $code_form = $("#scilab-fixer-code-form"); + $updating = $("#fix-tbc-page #updating"); + $done = $("#fix-tbc-page #done"); $example.attr("multiple", "enabled"); function reset() { @@ -81,21 +82,30 @@ $(document).ready(function() { $example.change(function() { var example_id = $(this).val(); reset("caption"); - + console.log("########" + example_id); $.ajax({ url: modPath + "ajax/example/" + example_id, type: "POST", dataType: "html", success: function(data) { var code = $(data).filter("#code").html(); - $code.html(code); + /* checking whether it is for .well or textarea */ + if($code.hasClass("fix-caption-code")) { + $code.html(code); + } else { + $code.val(code); + } var caption = $(data).filter("#caption").html(); - $caption.val(caption); + try { + $caption.val(caption); + } catch(e) { + return; + } } }); }); - $form.submit(function(e) { + $caption_form.submit(function(e) { var example_id = $example.val(); if(example_id != "0") { var caption = $caption.val(); @@ -105,7 +115,31 @@ $(document).ready(function() { type: "POST", data: { example_id: example_id, - caption: caption + caption: caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); + + $code_form.submit(function(e) { + var example_id = $example.val(); + if(example_id != "0") { + var code = $code.val(); + $.ajax({ + url: modPath + "ajax/code/" + example_id, + type: "POST", + data: { + code: code }, dataType: "html", success: function(data) { diff --git a/js/selection.js b/js/selection.js index fcb738b..6834aca 100644 --- a/js/selection.js +++ b/js/selection.js @@ -16,10 +16,10 @@ function getSelectionText(divID) { return selectedText; } $(document).ready(function() { - $("#fix-caption-code").mousedown(function() { + $(".fix-caption-code").mousedown(function() { $("#edit-caption").val(""); }); - $("#fix-caption-code").mouseup(function() { + $(".fix-caption-code").mouseup(function() { quotedText = getSelectionText("#fix-caption-code"); $("#edit-caption").val(quotedText); }); diff --git a/scilab_fixer.module b/scilab_fixer.module index 8955255..27bb6d5 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -29,6 +29,13 @@ "weight" => 2, "type" => MENU_LOCAL_TASK ); + $items["fix/code"] = array( + "title" => "Edit TBC code", + "page callback" => "scilab_fixer_code_all", + "access arguments" => array("fix scilab"), + "access arguments" => array("fix scilab"), + "type" => MENU_CALLBACK + ); $items["fix/ajax"] = array( "page callback" => "scilab_fixer_ajax", "access callback" => TRUE, @@ -48,7 +55,7 @@ $form["wrapper"] = array( "#type" => "fieldset", "#title"=> "Caption change form", - "#prefix" => "
", + "#prefix" => "
", "#suffix" => "
", ); $form["wrapper"]["category"] = array( @@ -100,10 +107,10 @@ "#type" => "submit", "#value" => "Update" ); - $form["wrapper"]["code"] = array( + $form["wrapper"]["code_wrapper"] = array( "#type" => "fieldset", "#description" => t("No code to display"), - "#prefix" => "
",
+            "#prefix" => "
",
             "#suffix" => "
", ); return $form; @@ -111,7 +118,7 @@ function scilab_fixer_caption_all() { $page_content = ""; - $page_content .= "
"; + $page_content .= "
"; $page_content .= "
Updating...
"; $page_content .= "Done."; $page_content .= drupal_get_form("scilab_fixer_caption_form"); @@ -175,6 +182,18 @@ "; $result = db_query($query, $caption, $example_id); $data .= "Updated"; + } else if($item == "code" && $key) { + $code = $_POST["code"]; + $query = " + SELECT * FROM textbook_companion_example_files + WHERE example_id = %d AND filetype = 'S' + "; + $result = db_query($query, $key); + $row = db_fetch_object($result); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; } else { $data = "Nothing to display."; } @@ -337,6 +356,76 @@ return $page_content; } + function scilab_fixer_code_form($form_state) { + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title"=> "Code edit form", + "#prefix" => "
", + "#suffix" => "
", + ); + $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"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor"), + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update" + ); + return $form; + } + + function scilab_fixer_code_all() { + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + $page_content .= drupal_get_form("scilab_fixer_code_form"); + $page_content .= "
"; + return $page_content; + } + 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"); -- cgit From 6ea7167991f5c9a8c87fffbda8a8513e965f15b0 Mon Sep 17 00:00:00 2001 From: Jayaram R Pai Date: Tue, 12 Aug 2014 12:27:33 +0530 Subject: added page to mark indian edition aicte books --- css/scilab_fixer.css | 3 +++ js/scilab_fixer.js | 26 +++++++++++++++++++++++++ scilab_fixer.module | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css index 964317f..4047749 100644 --- a/css/scilab_fixer.css +++ b/css/scilab_fixer.css @@ -36,3 +36,6 @@ textarea#edit-code { height: 300px; width: 650px; } +.orange { + background: #FF9933 !important; +} diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js index 9148603..b48832e 100644 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -154,4 +154,30 @@ $(document).ready(function() { } e.preventDefault(); }); + + /* toggle in edition */ + $ind_ed = $(".ind-ed"); + + $ind_ed.click(function(e) { + var aicte_id = $(this).attr("data-aicte"); + $t = $(this); + $.ajax({ + url: modPath + "ajax/ind-ed/" + aicte_id, + type: "GET", + dataType: "html", + success: function(data) { + $tr = $t.parents("tr:first"); + if($tr.hasClass("orange")) { + $t.parents("tr:first").removeClass("orange"); + $t.html("Mark"); + } else { + $t.parents("tr:first").addClass("orange"); + $t.html("Unmark"); + } + console.log(data); + }, + }); + e.preventDefault(); + }); + }); diff --git a/scilab_fixer.module b/scilab_fixer.module index 27bb6d5..5e210f4 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -29,6 +29,12 @@ "weight" => 2, "type" => MENU_LOCAL_TASK ); + $items["fix/aicte/in"] = array( + "title" => "Mark Indian edition books", + "page callback" => "scilab_fixer_aicte_in_all", + "access arguments" => array("fix scilab"), + "type" => MENU_CALLBACK + ); $items["fix/code"] = array( "title" => "Edit TBC code", "page callback" => "scilab_fixer_code_all", @@ -194,6 +200,14 @@ $example_path = $uploads_dir . $row->filepath; file_put_contents($example_path, $code); $data .= "updated"; + } else if($item == "ind-ed" && $key) { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = %d + "; + db_query($query, $key); + $data .= "updated"; } else { $data = "Nothing to display."; } @@ -356,6 +370,47 @@ return $page_content; } + function scilab_fixer_aicte_in_all(){ + $page_content = ""; + $query = " + SELECT * FROM textbook_companion_aicte + "; + $result = db_query($query); + $headers = array( + "Book", "Publisher", "Action" + ); + $rows = array(); + while($row = db_fetch_object($result)) { + $item = array( + "data" => array( + "{$row->book}
by{$row->author}", + $row->publisher, + ), + ); + $ind_options = array( + /* # linking in drupal l() */ + "fragment" => " ", + "external" => TRUE, + "attributes" => array( + "class" => "ind-ed", + "data-aicte" => "{$row->id}", + ) + ); + /* ind-ed link */ + if($row->ind) { + array_push($item["data"], l("Unmark", "", $ind_options)); + } else { + array_push($item["data"], l("Mark", "", $ind_options)); + } + if($row->ind) { + $item["class"] .= " orange"; + } + array_push($rows, $item); + } + $page_content .= theme("table", $headers, $rows); + return $page_content; + } + function scilab_fixer_code_form($form_state) { $form = array(); $form["wrapper"] = array( -- cgit From 3b4dd560d5b3a763921724ee091382ca2bbaf8ab Mon Sep 17 00:00:00 2001 From: prashant Date: Thu, 25 Sep 2014 15:14:21 +0530 Subject: added aicte book disable eanble functionaty --- css/scilab_fixer.css | 6 ++++++ js/scilab_fixer.js | 17 +++++++++++++++++ js/selection.js | 0 scilab_fixer.module | 45 +++++++++++++++++++++++++++++++++++---------- 4 files changed, 58 insertions(+), 10 deletions(-) mode change 100644 => 100755 css/scilab_fixer.css mode change 100644 => 100755 js/scilab_fixer.js mode change 100644 => 100755 js/selection.js diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css old mode 100644 new mode 100755 index 4047749..5634290 --- a/css/scilab_fixer.css +++ b/css/scilab_fixer.css @@ -39,3 +39,9 @@ textarea#edit-code { .orange { background: #FF9933 !important; } +.sync-msg { + font-size: .8em; +} +.messages.success { + background: lightgreen; +} diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js old mode 100644 new mode 100755 index b48832e..657cb61 --- a/js/scilab_fixer.js +++ b/js/scilab_fixer.js @@ -1,6 +1,9 @@ $(document).ready(function() { var basePath = Drupal.settings.basePath; var modPath = basePath + "fix/"; + var modPath1 = basePath + "fix/aicte/book/"; + + $category = $("#fix-tbc-form #edit-category"); $book = $("#fix-tbc-form #edit-book"); @@ -155,6 +158,20 @@ $(document).ready(function() { e.preventDefault(); }); +$Selected = $(".selected"); + $Selected.click(function (e) { + $(".sync-msg").remove(); + $(this).after("Saving..."); + $.ajax({ + url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), + success: function() { + $(".sync-msg").remove(); + console.log ("success"); + } + }); + + }); + /* toggle in edition */ $ind_ed = $(".ind-ed"); diff --git a/js/selection.js b/js/selection.js old mode 100644 new mode 100755 diff --git a/scilab_fixer.module b/scilab_fixer.module index 5e210f4..33235e1 100755 --- a/scilab_fixer.module +++ b/scilab_fixer.module @@ -11,7 +11,6 @@ "title" => "Add AICTE books", "page callback" => "scilab_fixer_aicte_all", "access arguments" => array("fix scilab"), - "access arguments" => array("fix scilab"), "weight" => 30, "type" => MENU_NORMAL_ITEM ); @@ -28,7 +27,7 @@ "access arguments" => array("fix scilab"), "weight" => 2, "type" => MENU_LOCAL_TASK - ); + ); $items["fix/aicte/in"] = array( "title" => "Mark Indian edition books", "page callback" => "scilab_fixer_aicte_in_all", @@ -37,8 +36,7 @@ ); $items["fix/code"] = array( "title" => "Edit TBC code", - "page callback" => "scilab_fixer_code_all", - "access arguments" => array("fix scilab"), + "page callback" => "scilab_fixer_code_all", "access arguments" => array("fix scilab"), "type" => MENU_CALLBACK ); @@ -47,6 +45,11 @@ "access callback" => TRUE, "type" => MENU_CALLBACK ); + $items["fix/aicte/book/ajax"] = array( + "page callback" => "scilab_fixer_aicte_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); return $items; } @@ -208,12 +211,27 @@ "; db_query($query, $key); $data .= "updated"; - } else { + }else { $data = "Nothing to display."; } echo $data; exit(); } + function scilab_fixer_aicte_ajax($item="", $key="") { + $data = ""; + if($item == "selected") { + $query = " + UPDATE textbook_companion_aicte + SET selected = !selected + WHERE id = {$key} + "; + db_query($query); + $data = "updated"; + } + echo $data; + exit(); + } + function scilab_fixer_aicte_form($form_state, $aicte_id) { $query = " @@ -342,7 +360,7 @@ } function scilab_fixer_aicte_edit_all($aicte_id=0) { - $page_content = ""; + $page_content = ""; if($aicte_id) { $page_content .= drupal_get_form("scilab_fixer_aicte_form", $aicte_id); } else { @@ -356,22 +374,29 @@ "Edition", "Action", ); $rows = array(); + while($row = db_fetch_object($result)) { - $item = array( + $item = array( "{$row->book}", "{$row->author}", "{$row->edition}", - l(t("Edit"), "fix/aicte/edit/{$row->id}") + l(t("Edit"), "fix/aicte/edit/{$row->id}") ); + if($row->selected) { + $check = ""; + } else { + $check = ""; + } + array_push($item, $check); array_push($rows, $item); - } + } $page_content .= theme("table", $headers, $rows); } return $page_content; } function scilab_fixer_aicte_in_all(){ - $page_content = ""; + $page_content = ""; $query = " SELECT * FROM textbook_companion_aicte "; -- cgit From 7cf256d69fca84e10c427468535e44386597ec08 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Wed, 31 Aug 2016 15:13:35 +0530 Subject: added readme --- README | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 README diff --git a/README b/README new file mode 100755 index 0000000..186df63 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +Textbook Companion Fixer for FOSSEE, IIT Bombay written in Drupal 7 + -- cgit From 5a8318eac17f4f5bafe30c5642600c03426b9de7 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Wed, 31 Aug 2016 16:22:06 +0530 Subject: Initial commit for drupal 7 module --- README~ | 2 + textbook_ companion_fixer.module~ | 598 ++++++++++++++++++++++++++++++++++ textbook_companion_fixer.info~ | 4 + textbook_companion_fixer.module~ | 651 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 1255 insertions(+) create mode 100755 README~ create mode 100755 textbook_ companion_fixer.module~ create mode 100755 textbook_companion_fixer.info~ create mode 100755 textbook_companion_fixer.module~ diff --git a/README~ b/README~ new file mode 100755 index 0000000..186df63 --- /dev/null +++ b/README~ @@ -0,0 +1,2 @@ +Textbook Companion Fixer for FOSSEE, IIT Bombay written in Drupal 7 + diff --git a/textbook_ companion_fixer.module~ b/textbook_ companion_fixer.module~ new file mode 100755 index 0000000..9ec5a9b --- /dev/null +++ b/textbook_ companion_fixer.module~ @@ -0,0 +1,598 @@ + "Fix TBC captions", + "page callback" => "scilab_fixer_caption_all", + "access arguments" => array("fix scilab"), + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array("fix scilab"), + "weight" => 30, + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte/new"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array("fix scilab"), + "weight" => 1, + "type" => MENU_DEFAULT_LOCAL_TASK + ); + $items["fix/aicte/edit"] = array( + "title" => "Edit AICTE books", + "page callback" => "scilab_fixer_aicte_edit_all", + "access arguments" => array("fix scilab"), + "weight" => 2, + "type" => MENU_LOCAL_TASK + ); + $items["fix/aicte/in"] = array( + "title" => "Mark Indian edition books", + "page callback" => "scilab_fixer_aicte_in_all", + "access arguments" => array("fix scilab"), + "type" => MENU_CALLBACK + ); + $items["fix/code"] = array( + "title" => "Edit TBC code", + "page callback" => "scilab_fixer_code_all", + "access arguments" => array("fix scilab"), + "type" => MENU_CALLBACK + ); + $items["fix/ajax"] = array( + "page callback" => "scilab_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["fix/aicte/book/ajax"] = array( + "page callback" => "scilab_fixer_aicte_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + return $items; + } + + function scilab_fixer_perm() { + return array( + "fix scilab" =>array( + "title" =>t("fix scilab code"), + 'restrict access' => TRUE, + ) + ); + } + + function scilab_fixer_caption_form($form, $form_state) { + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title"=> "Caption change form", + "#prefix" => "
", + "#suffix" => "
", + ); + $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_wrapper"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#prefix" => "
",
+            "#suffix" => "
", + ); + return $form; + } + + function scilab_fixer_caption_all() { + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + // $page_content .= drupal_get_form("scilab_fixer_caption_form"); + $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); + $page_content .= drupal_render($scilab_fixer_caption_form); + $page_content .= "
"; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; + 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);*/ + $query = db_select('textbook_companion_preference', 'pre'); + $query->fields('pre', array('id', 'book', 'author')); + $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); + $query->condition('pro.proposal_status', 3); + $query->condition('pre.approval_status', 1); + $query->condition('pre.category', $key); + $query->orderBy('pre.book', 'ASC'); + $result = $query->execute(); + + $data .= ""; + while($row =$result->fetchObject()) { + $data .= ""; + } + } else if($item == "book" && $key) { + /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('preference_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + + $data .= ""; + while($row = $result->fetchObject()) { + $data .= ""; + } + } else if($item == "chapter" && $key) { + /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + + $data .= ""; + while($row = $result->fetchObject()) { + $data .= ""; + } + } 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);*/ + $query = db_select('textbook_companion_example_files', 'fil'); + $query->fields('fil'); + $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); + $query->condition('example_id', $key); + $result = $query->execute(); + $row = $result->fetchObject(); + /* 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 .= "
{$row->caption}
"; + $data .= "
{$example}
"; + } 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);*/ + $query = db_update('textbook_companion_example'); + $query->fields(array( + 'caption' => $caption, + )); + $query->condition('id', $example_id); + $result = $query->execute(); + $data .= "Updated"; + } else if($item == "code" && $key) { + $code = $_POST["code"]; + /*$query = " + SELECT * FROM textbook_companion_example_files + WHERE example_id = %d AND filetype = 'S' + "; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example_files'); + $query->fields('textbook_companion_example_files'); + $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $result = $query->execute(); + $row = $result->fetchObject(); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; + } else if($item == "ind-ed" && $key) { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query,$args); + + $data .= "updated"; + }else { + $data = "Nothing to display."; + } + echo $data; + exit(); + } + function scilab_fixer_aicte_ajax($item="", $key="") { + $data = ""; + if($item == "selected") { + $query = " + UPDATE textbook_companion_aicte + SET selected = !selected + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query,$args); + $data = "updated"; + } + echo $data; + exit(); + } + + + function scilab_fixer_aicte_form($form, $form_state, $aicte_id='') { + /*$query = " + SELECT * FROM textbook_companion_aicte + WHERE id = {$aicte_id} + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->condition('id', $aicte_id); + $result = $query->execute(); + $row = $result->fetchObject(); + + $form = array(); + $form["book"] = array( + "#type" => "textfield", + "#title" => "Book Name", + "#default_value" => $row->book, + "#required" => TRUE + ); + $form["author"] = array( + "#type" => "textfield", + "#title" => "Author", + "#default_value" => $row->author, + "#required" => TRUE + ); + $form["category"] = array( + "#type" => "select", + "#title" => "Book 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' + ), + "#default_value" => $row->category, + "#required" => TRUE + ); + $form["isbn"] = array( + "#type" => "textfield", + "#title" => "ISBN", + "#default_value" => $row->isbn, + "#required" => FALSE + ); + $form["publisher"] = array( + "#type" => "textfield", + "#title" => "Publisher", + "#default_value" => $row->publisher, + "#required" => TRUE + ); + $form["edition"] = array( + "#type" => "textfield", + "#title" => "Edition", + "#default_value" => $row->edition, + "#required" => TRUE + ); + $form["year"] = array( + "#type" => "textfield", + "#title" => "Year of publication", + "#default_value" => $row->year, + "#required" => TRUE + ); + $form["aicte_id"] = array( + "#type" => "hidden", + "#value" => $row->id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; + } + + function scilab_fixer_aicte_form_validate($form, &$form_state) { + if(!$form_state["values"]["category"]) { + form_set_error("category", "Please select a category."); + } + if(!is_numeric($form_state["values"]["edition"])) { + form_set_error("edition", "Only digits are allowed."); + } + if(!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { + form_set_error("year", "Please enter a valid year. eg: 2011."); + } + } + + function scilab_fixer_aicte_form_submit($form, &$form_state) { + $v = $form_state["values"]; + if($v["aicte_id"]) { + /*$query = " + UPDATE textbook_companion_aicte + SET book = '%s', author = '%s', category = %d, + isbn = '%s', publisher = '%s', edition = %d, + year = %d + WHERE id = %d + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] + );*/ + + $query = db_update('textbook_companion_aicte'); + $query->fields(array( + 'book' => $v["book"], + 'author' => $v["author"], + 'category' => $v["category"], + 'isbn' => $v["isbn"], + 'publisher' => $v["publisher"], + 'edition' => $v["edition"], + 'year' => $v["year"], + )); + $query->condition('id', $v["aicte_id"]); + $num_updated = $query->execute(); + + + drupal_set_message("Book updated successfully", "status"); + } else { + $query = " + INSERT INTO textbook_companion_aicte + (book, author, category, isbn, publisher, edition, year) + VALUES + (:book, :author, :category, :isbn, :publisher, :edition, :year) + "; + $args = array( + ':book' => $v["book"], + ':author' => $v["author"], + ':category' => $v["category"], + ':isbn'=> $v["isbn"], + ':publisher' => $v["publisher"], + ':edition' => $v["edition"], + ':year' => $v["year"], + + ); + $result = db_query($query,$args); + drupal_set_message("Book added successfully", "status"); + } + } + + function scilab_fixer_aicte_all() { + $page_content = ""; + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); + $page_content .= drupal_render($scilab_fixer_aicte_form); + return $page_content; + } + + function scilab_fixer_aicte_edit_all($aicte_id=0) { + $page_content = ""; + if($aicte_id) { + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); + $page_content .= drupal_render($scilab_fixer_aicte_form); + } else { + /*$query = " + SELECT * FROM textbook_companion_aicte + ORDER BY time DESC + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->orderBy('time', 'DESC'); + $result = $query->execute(); + $headers = array( + "Book", "Author", + "Edition", "Action", + ); + $rows = array(); + + while($row = $result->fetchObject()) { + $item = array( + "{$row->book}", + "{$row->author}", + "{$row->edition}", + l(t("Edit"), "fix/aicte/edit/{$row->id}") + ); + if($row->selected) { + $check = ""; + } else { + $check = ""; + } + array_push($item, $check); + array_push($rows, $item); + } + //$page_content .= theme("table", $headers, $rows); + $page_content .= theme("table", array('header' => $headers,'rows'=> $rows)); + } + return $page_content; + } + + function scilab_fixer_aicte_in_all(){ + $page_content = ""; + /*$query = " + SELECT * FROM textbook_companion_aicte + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $result = $query->execute(); + $headers = array( + "Book", "Publisher", "Action" + ); + $rows = array(); + while($row = $result->fetchObject()) { + $item = array( + "data" => array( + "{$row->book}
by{$row->author}", + $row->publisher, + ), + ); + $ind_options = array( + /* # linking in drupal l() */ + "fragment" => " ", + "external" => TRUE, + "attributes" => array( + "class" => "ind-ed", + "data-aicte" => "{$row->id}", + ) + ); + /* ind-ed link */ + if($row->ind) { + array_push($item["data"], l("Unmark", "", $ind_options)); + } else { + array_push($item["data"], l("Mark", "", $ind_options)); + } + if($row->ind) { + $item["class"] .= " orange"; + } + array_push($rows, $item); + } + $page_content .= theme('table',array('header' =>$headers,'rows' => $rows)); + return $page_content; + } + + function scilab_fixer_code_form($form_state) { + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title"=> "Code edit form", + "#prefix" => "
", + "#suffix" => "
", + ); + $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"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor"), + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update" + ); + return $form; + } + + function scilab_fixer_code_all() { + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); + $page_content .= drupal_render($scilab_fixer_code_form); + $page_content .= "
"; + return $page_content; + } + + function scilab_fixer_init() { + drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); + //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); + } +?> diff --git a/textbook_companion_fixer.info~ b/textbook_companion_fixer.info~ new file mode 100755 index 0000000..bc72bc6 --- /dev/null +++ b/textbook_companion_fixer.info~ @@ -0,0 +1,4 @@ +name = Textbook Companion fixer +description = Module to fix scilab code bugs +core = 7.x +package = IITB diff --git a/textbook_companion_fixer.module~ b/textbook_companion_fixer.module~ new file mode 100755 index 0000000..13271d0 --- /dev/null +++ b/textbook_companion_fixer.module~ @@ -0,0 +1,651 @@ + "Fix TBC captions", + "page callback" => "scilab_fixer_caption_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 30, + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte/new"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 1, + "type" => MENU_DEFAULT_LOCAL_TASK + ); + $items["fix/aicte/edit"] = array( + "title" => "Edit AICTE books", + "page callback" => "scilab_fixer_aicte_edit_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 2, + "type" => MENU_LOCAL_TASK + ); + $items["fix/aicte/in"] = array( + "title" => "Mark Indian edition books", + "page callback" => "scilab_fixer_aicte_in_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_CALLBACK + ); + $items["fix/code"] = array( + "title" => "Edit TBC code", + "page callback" => "scilab_fixer_code_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_CALLBACK + ); + $items["fix/ajax"] = array( + "page callback" => "scilab_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["fix/aicte/book/ajax"] = array( + "page callback" => "scilab_fixer_aicte_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + return $items; +} +function scilab_fixer_perm() +{ + return array( + "fix scilab" => array( + "title" => t("fix scilab code"), + 'restrict access' => TRUE + ) + ); +} +function scilab_fixer_caption_form($form, &$form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Caption change form", + "#prefix" => "
", + "#suffix" => "
" + ); + $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_wrapper"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#prefix" => "
",
+		"#suffix" => "
" + ); + return $form; +} +function scilab_fixer_caption_all() +{ + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + // $page_content .= drupal_get_form("scilab_fixer_caption_form"); + $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); + $page_content .= drupal_render($scilab_fixer_caption_form); + $page_content .= "
"; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; + 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);*/ + $query = db_select('textbook_companion_preference', 'pre'); + $query->fields('pre', array( + 'id', + 'book', + 'author' + )); + $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); + $query->condition('pro.proposal_status', 3); + $query->condition('pre.approval_status', 1); + $query->condition('pre.category', $key); + $query->orderBy('pre.book', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "category" && $key + else if ($item == "book" && $key) + { + /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('preference_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "book" && $key + else if ($item == "chapter" && $key) + { + /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "chapter" && $key + 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);*/ + $query = db_select('textbook_companion_example_files', 'fil'); + $query->fields('fil'); + $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); + $query->condition('example_id', $key); + $result = $query->execute(); + $row = $result->fetchObject(); + /* 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 .= "
{$row->caption}
"; + $data .= "
{$example}
"; + } //$item == "example" && $key + 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);*/ + $query = db_update('textbook_companion_example'); + $query->fields(array( + 'caption' => $caption + )); + $query->condition('id', $example_id); + $result = $query->execute(); + $data .= "Updated"; + } //$item == "update" + else if ($item == "code" && $key) + { + $code = $_POST["code"]; + /*$query = " + SELECT * FROM textbook_companion_example_files + WHERE example_id = %d AND filetype = 'S' + "; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example_files'); + $query->fields('textbook_companion_example_files'); + $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $result = $query->execute(); + $row = $result->fetchObject(); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; + } //$item == "code" && $key + else if ($item == "ind-ed" && $key) + { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data .= "updated"; + } //$item == "ind-ed" && $key + else + { + $data = "Nothing to display."; + } + echo $data; + exit(); +} +function scilab_fixer_aicte_ajax($item = "", $key = "") +{ + $data = ""; + if ($item == "selected") + { + $query = " + UPDATE textbook_companion_aicte + SET selected = !selected + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data = "updated"; + } //$item == "selected" + echo $data; + exit(); +} +function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') +{ + /*$query = " + SELECT * FROM textbook_companion_aicte + WHERE id = {$aicte_id} + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->condition('id', $aicte_id); + $result = $query->execute(); + $row = $result->fetchObject(); + $form = array(); + $form["book"] = array( + "#type" => "textfield", + "#title" => "Book Name", + "#default_value" => $row->book, + "#required" => TRUE + ); + $form["author"] = array( + "#type" => "textfield", + "#title" => "Author", + "#default_value" => $row->author, + "#required" => TRUE + ); + $form["category"] = array( + "#type" => "select", + "#title" => "Book 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' + ), + "#default_value" => $row->category, + "#required" => TRUE + ); + $form["isbn"] = array( + "#type" => "textfield", + "#title" => "ISBN", + "#default_value" => $row->isbn, + "#required" => FALSE + ); + $form["publisher"] = array( + "#type" => "textfield", + "#title" => "Publisher", + "#default_value" => $row->publisher, + "#required" => TRUE + ); + $form["edition"] = array( + "#type" => "textfield", + "#title" => "Edition", + "#default_value" => $row->edition, + "#required" => TRUE + ); + $form["year"] = array( + "#type" => "textfield", + "#title" => "Year of publication", + "#default_value" => $row->year, + "#required" => TRUE + ); + $form["aicte_id"] = array( + "#type" => "hidden", + "#value" => $row->id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; +} +function scilab_fixer_aicte_form_validate($form, &$form_state) +{ + if (!$form_state["values"]["category"]) + { + form_set_error("category", "Please select a category."); + } //!$form_state["values"]["category"] + if (!is_numeric($form_state["values"]["edition"])) + { + form_set_error("edition", "Only digits are allowed."); + } //!is_numeric($form_state["values"]["edition"]) + if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) + { + form_set_error("year", "Please enter a valid year. eg: 2011."); + } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 +} +function scilab_fixer_aicte_form_submit($form, &$form_state) +{ + $v = $form_state["values"]; + if ($v["aicte_id"]) + { + /*$query = " + UPDATE textbook_companion_aicte + SET book = '%s', author = '%s', category = %d, + isbn = '%s', publisher = '%s', edition = %d, + year = %d + WHERE id = %d + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] + );*/ + $query = db_update('textbook_companion_aicte'); + $query->fields(array( + 'book' => $v["book"], + 'author' => $v["author"], + 'category' => $v["category"], + 'isbn' => $v["isbn"], + 'publisher' => $v["publisher"], + 'edition' => $v["edition"], + 'year' => $v["year"] + )); + $query->condition('id', $v["aicte_id"]); + $num_updated = $query->execute(); + drupal_set_message("Book updated successfully", "status"); + } //$v["aicte_id"] + else + { + $query = " + INSERT INTO textbook_companion_aicte + (book, author, category, isbn, publisher, edition, year) + VALUES + (:book, :author, :category, :isbn, :publisher, :edition, :year) + "; + $args = array( + ':book' => $v["book"], + ':author' => $v["author"], + ':category' => $v["category"], + ':isbn' => $v["isbn"], + ':publisher' => $v["publisher"], + ':edition' => $v["edition"], + ':year' => $v["year"] + ); + $result = db_query($query, $args); + drupal_set_message("Book added successfully", "status"); + } +} +function scilab_fixer_aicte_all() +{ + $page_content = ""; + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); + $page_content .= drupal_render($scilab_fixer_aicte_form); + return $page_content; +} +function scilab_fixer_aicte_edit_all($aicte_id = 0) +{ + $page_content = ""; + if ($aicte_id) + { + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); + $page_content .= drupal_render($scilab_fixer_aicte_form); + } //$aicte_id + else + { + /*$query = " + SELECT * FROM textbook_companion_aicte + ORDER BY time DESC + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->orderBy('time', 'DESC'); + $result = $query->execute(); + $headers = array( + "Book", + "Author", + "Edition", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) + { + $item = array( + "{$row->book}", + "{$row->author}", + "{$row->edition}", + l(t("Edit"), "fix/aicte/edit/{$row->id}") + ); + if ($row->selected) + { + $check = ""; + } //$row->selected + else + { + $check = ""; + } + array_push($item, $check); + array_push($rows, $item); + } //$row = $result->fetchObject() + //$page_content .= theme("table", $headers, $rows); + $page_content .= theme("table", array( + 'header' => $headers, + 'rows' => $rows + )); + } + return $page_content; +} +function scilab_fixer_aicte_in_all() +{ + $page_content = ""; + /*$query = " + SELECT * FROM textbook_companion_aicte + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $result = $query->execute(); + $headers = array( + "Book", + "Publisher", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) + { + $item = array( + "data" => array( + "{$row->book}
by{$row->author}", + $row->publisher + ) + ); + $ind_options = array( + /* # linking in drupal l() */ + "fragment" => " ", + "external" => TRUE, + "attributes" => array( + "class" => "ind-ed", + "data-aicte" => "{$row->id}" + ) + ); + /* ind-ed link */ + if ($row->ind) + { + array_push($item["data"], l("Unmark", "", $ind_options)); + } //$row->ind + else + { + array_push($item["data"], l("Mark", "", $ind_options)); + } + if ($row->ind) + { + $item["class"] .= " orange"; + } //$row->ind + array_push($rows, $item); + } //$row = $result->fetchObject() + $page_content .= theme('table', array( + 'header' => $headers, + 'rows' => $rows + )); + return $page_content; +} +function scilab_fixer_code_form($form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Code edit form", + "#prefix" => "
", + "#suffix" => "
" + ); + $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"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor") + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update" + ); + return $form; +} +function scilab_fixer_code_all() +{ + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); + $page_content .= drupal_render($scilab_fixer_code_form); + $page_content .= "
"; + return $page_content; +} +function scilab_fixer_init() +{ + drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); + //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); +} -- cgit From 67d1f6ee20bcf1c02edfcd3fa3d89c1f3f988c58 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Wed, 31 Aug 2016 16:23:06 +0530 Subject: Initial commit for drupal 7 module --- .gitignore | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 072b683..b8ed22c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,13 @@ # Ignore configuration files that may contain sensitive information. sites/*/*settings*.php + + +# Ignore paths that contain generated content. +cache/ +files/ +sites/*/files +sites/*/private +file_bck sites/example.sites.php # Ignore paths that contain generated content. @@ -17,6 +25,7 @@ robots.txt /MAINTAINERS.txt /UPGRADE.txt /README.txt +sites/all/README.txt sites/README.txt sites/all/libraries/README.txt sites/all/modules/README.txt @@ -37,3 +46,10 @@ xmlrpc.php /profiles /scripts /themes + +# Ignore vim temp. files +*.bak +*.swo +*.swp +*~ +*.*~ -- cgit From 861cf43350508d852b0c934fe5cf907586164c89 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:12:52 +0530 Subject: cleaned directory --- textbook_ companion_fixer.module~ | 598 ---------------------------------- textbook_companion_fixer.info | 4 + textbook_companion_fixer.info~ | 4 - textbook_companion_fixer.module | 651 ++++++++++++++++++++++++++++++++++++++ textbook_companion_fixer.module~ | 651 -------------------------------------- 5 files changed, 655 insertions(+), 1253 deletions(-) delete mode 100755 textbook_ companion_fixer.module~ create mode 100644 textbook_companion_fixer.info delete mode 100755 textbook_companion_fixer.info~ create mode 100644 textbook_companion_fixer.module delete mode 100755 textbook_companion_fixer.module~ diff --git a/textbook_ companion_fixer.module~ b/textbook_ companion_fixer.module~ deleted file mode 100755 index 9ec5a9b..0000000 --- a/textbook_ companion_fixer.module~ +++ /dev/null @@ -1,598 +0,0 @@ - "Fix TBC captions", - "page callback" => "scilab_fixer_caption_all", - "access arguments" => array("fix scilab"), - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array("fix scilab"), - "weight" => 30, - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte/new"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array("fix scilab"), - "weight" => 1, - "type" => MENU_DEFAULT_LOCAL_TASK - ); - $items["fix/aicte/edit"] = array( - "title" => "Edit AICTE books", - "page callback" => "scilab_fixer_aicte_edit_all", - "access arguments" => array("fix scilab"), - "weight" => 2, - "type" => MENU_LOCAL_TASK - ); - $items["fix/aicte/in"] = array( - "title" => "Mark Indian edition books", - "page callback" => "scilab_fixer_aicte_in_all", - "access arguments" => array("fix scilab"), - "type" => MENU_CALLBACK - ); - $items["fix/code"] = array( - "title" => "Edit TBC code", - "page callback" => "scilab_fixer_code_all", - "access arguments" => array("fix scilab"), - "type" => MENU_CALLBACK - ); - $items["fix/ajax"] = array( - "page callback" => "scilab_fixer_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - $items["fix/aicte/book/ajax"] = array( - "page callback" => "scilab_fixer_aicte_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - return $items; - } - - function scilab_fixer_perm() { - return array( - "fix scilab" =>array( - "title" =>t("fix scilab code"), - 'restrict access' => TRUE, - ) - ); - } - - function scilab_fixer_caption_form($form, $form_state) { - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title"=> "Caption change form", - "#prefix" => "
", - "#suffix" => "
", - ); - $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_wrapper"] = array( - "#type" => "fieldset", - "#description" => t("No code to display"), - "#prefix" => "
",
-            "#suffix" => "
", - ); - return $form; - } - - function scilab_fixer_caption_all() { - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - // $page_content .= drupal_get_form("scilab_fixer_caption_form"); - $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); - $page_content .= drupal_render($scilab_fixer_caption_form); - $page_content .= "
"; - $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; - 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);*/ - $query = db_select('textbook_companion_preference', 'pre'); - $query->fields('pre', array('id', 'book', 'author')); - $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); - $query->condition('pro.proposal_status', 3); - $query->condition('pre.approval_status', 1); - $query->condition('pre.category', $key); - $query->orderBy('pre.book', 'ASC'); - $result = $query->execute(); - - $data .= ""; - while($row =$result->fetchObject()) { - $data .= ""; - } - } else if($item == "book" && $key) { - /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('preference_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - - $data .= ""; - while($row = $result->fetchObject()) { - $data .= ""; - } - } else if($item == "chapter" && $key) { - /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example'); - $query->fields('textbook_companion_example'); - $query->condition('chapter_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - - $data .= ""; - while($row = $result->fetchObject()) { - $data .= ""; - } - } 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);*/ - $query = db_select('textbook_companion_example_files', 'fil'); - $query->fields('fil'); - $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); - $query->condition('example_id', $key); - $result = $query->execute(); - $row = $result->fetchObject(); - /* 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 .= "
{$row->caption}
"; - $data .= "
{$example}
"; - } 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);*/ - $query = db_update('textbook_companion_example'); - $query->fields(array( - 'caption' => $caption, - )); - $query->condition('id', $example_id); - $result = $query->execute(); - $data .= "Updated"; - } else if($item == "code" && $key) { - $code = $_POST["code"]; - /*$query = " - SELECT * FROM textbook_companion_example_files - WHERE example_id = %d AND filetype = 'S' - "; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example_files'); - $query->fields('textbook_companion_example_files'); - $query->condition('example_id', $key); - $query->condition('filetype', 'S'); - $result = $query->execute(); - $row = $result->fetchObject(); - $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; - $example_path = $uploads_dir . $row->filepath; - file_put_contents($example_path, $code); - $data .= "updated"; - } else if($item == "ind-ed" && $key) { - $query = " - UPDATE textbook_companion_aicte - SET ind = !ind - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query,$args); - - $data .= "updated"; - }else { - $data = "Nothing to display."; - } - echo $data; - exit(); - } - function scilab_fixer_aicte_ajax($item="", $key="") { - $data = ""; - if($item == "selected") { - $query = " - UPDATE textbook_companion_aicte - SET selected = !selected - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query,$args); - $data = "updated"; - } - echo $data; - exit(); - } - - - function scilab_fixer_aicte_form($form, $form_state, $aicte_id='') { - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE id = {$aicte_id} - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->condition('id', $aicte_id); - $result = $query->execute(); - $row = $result->fetchObject(); - - $form = array(); - $form["book"] = array( - "#type" => "textfield", - "#title" => "Book Name", - "#default_value" => $row->book, - "#required" => TRUE - ); - $form["author"] = array( - "#type" => "textfield", - "#title" => "Author", - "#default_value" => $row->author, - "#required" => TRUE - ); - $form["category"] = array( - "#type" => "select", - "#title" => "Book 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' - ), - "#default_value" => $row->category, - "#required" => TRUE - ); - $form["isbn"] = array( - "#type" => "textfield", - "#title" => "ISBN", - "#default_value" => $row->isbn, - "#required" => FALSE - ); - $form["publisher"] = array( - "#type" => "textfield", - "#title" => "Publisher", - "#default_value" => $row->publisher, - "#required" => TRUE - ); - $form["edition"] = array( - "#type" => "textfield", - "#title" => "Edition", - "#default_value" => $row->edition, - "#required" => TRUE - ); - $form["year"] = array( - "#type" => "textfield", - "#title" => "Year of publication", - "#default_value" => $row->year, - "#required" => TRUE - ); - $form["aicte_id"] = array( - "#type" => "hidden", - "#value" => $row->id - ); - $form["submit"] = array( - "#type" => "submit", - "#value" => "Submit" - ); - return $form; - } - - function scilab_fixer_aicte_form_validate($form, &$form_state) { - if(!$form_state["values"]["category"]) { - form_set_error("category", "Please select a category."); - } - if(!is_numeric($form_state["values"]["edition"])) { - form_set_error("edition", "Only digits are allowed."); - } - if(!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { - form_set_error("year", "Please enter a valid year. eg: 2011."); - } - } - - function scilab_fixer_aicte_form_submit($form, &$form_state) { - $v = $form_state["values"]; - if($v["aicte_id"]) { - /*$query = " - UPDATE textbook_companion_aicte - SET book = '%s', author = '%s', category = %d, - isbn = '%s', publisher = '%s', edition = %d, - year = %d - WHERE id = %d - "; - $result = db_query($query, - $v["book"], $v["author"], $v["category"], $v["isbn"], - $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] - );*/ - - $query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'book' => $v["book"], - 'author' => $v["author"], - 'category' => $v["category"], - 'isbn' => $v["isbn"], - 'publisher' => $v["publisher"], - 'edition' => $v["edition"], - 'year' => $v["year"], - )); - $query->condition('id', $v["aicte_id"]); - $num_updated = $query->execute(); - - - drupal_set_message("Book updated successfully", "status"); - } else { - $query = " - INSERT INTO textbook_companion_aicte - (book, author, category, isbn, publisher, edition, year) - VALUES - (:book, :author, :category, :isbn, :publisher, :edition, :year) - "; - $args = array( - ':book' => $v["book"], - ':author' => $v["author"], - ':category' => $v["category"], - ':isbn'=> $v["isbn"], - ':publisher' => $v["publisher"], - ':edition' => $v["edition"], - ':year' => $v["year"], - - ); - $result = db_query($query,$args); - drupal_set_message("Book added successfully", "status"); - } - } - - function scilab_fixer_aicte_all() { - $page_content = ""; - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); - $page_content .= drupal_render($scilab_fixer_aicte_form); - return $page_content; - } - - function scilab_fixer_aicte_edit_all($aicte_id=0) { - $page_content = ""; - if($aicte_id) { - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); - $page_content .= drupal_render($scilab_fixer_aicte_form); - } else { - /*$query = " - SELECT * FROM textbook_companion_aicte - ORDER BY time DESC - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->orderBy('time', 'DESC'); - $result = $query->execute(); - $headers = array( - "Book", "Author", - "Edition", "Action", - ); - $rows = array(); - - while($row = $result->fetchObject()) { - $item = array( - "{$row->book}", - "{$row->author}", - "{$row->edition}", - l(t("Edit"), "fix/aicte/edit/{$row->id}") - ); - if($row->selected) { - $check = ""; - } else { - $check = ""; - } - array_push($item, $check); - array_push($rows, $item); - } - //$page_content .= theme("table", $headers, $rows); - $page_content .= theme("table", array('header' => $headers,'rows'=> $rows)); - } - return $page_content; - } - - function scilab_fixer_aicte_in_all(){ - $page_content = ""; - /*$query = " - SELECT * FROM textbook_companion_aicte - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $result = $query->execute(); - $headers = array( - "Book", "Publisher", "Action" - ); - $rows = array(); - while($row = $result->fetchObject()) { - $item = array( - "data" => array( - "{$row->book}
by{$row->author}", - $row->publisher, - ), - ); - $ind_options = array( - /* # linking in drupal l() */ - "fragment" => " ", - "external" => TRUE, - "attributes" => array( - "class" => "ind-ed", - "data-aicte" => "{$row->id}", - ) - ); - /* ind-ed link */ - if($row->ind) { - array_push($item["data"], l("Unmark", "", $ind_options)); - } else { - array_push($item["data"], l("Mark", "", $ind_options)); - } - if($row->ind) { - $item["class"] .= " orange"; - } - array_push($rows, $item); - } - $page_content .= theme('table',array('header' =>$headers,'rows' => $rows)); - return $page_content; - } - - function scilab_fixer_code_form($form_state) { - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title"=> "Code edit form", - "#prefix" => "
", - "#suffix" => "
", - ); - $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"]["code"] = array( - "#type" => "textarea", - "#title" => t("Code Editor"), - ); - $form["wrapper"]["submit"] = array( - "#type" => "submit", - "#value" => "Update" - ); - return $form; - } - - function scilab_fixer_code_all() { - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); - $page_content .= drupal_render($scilab_fixer_code_form); - $page_content .= "
"; - return $page_content; - } - - function scilab_fixer_init() { - drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); - //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); - } -?> diff --git a/textbook_companion_fixer.info b/textbook_companion_fixer.info new file mode 100644 index 0000000..bc72bc6 --- /dev/null +++ b/textbook_companion_fixer.info @@ -0,0 +1,4 @@ +name = Textbook Companion fixer +description = Module to fix scilab code bugs +core = 7.x +package = IITB diff --git a/textbook_companion_fixer.info~ b/textbook_companion_fixer.info~ deleted file mode 100755 index bc72bc6..0000000 --- a/textbook_companion_fixer.info~ +++ /dev/null @@ -1,4 +0,0 @@ -name = Textbook Companion fixer -description = Module to fix scilab code bugs -core = 7.x -package = IITB diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module new file mode 100644 index 0000000..13271d0 --- /dev/null +++ b/textbook_companion_fixer.module @@ -0,0 +1,651 @@ + "Fix TBC captions", + "page callback" => "scilab_fixer_caption_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 30, + "type" => MENU_NORMAL_ITEM + ); + $items["fix/aicte/new"] = array( + "title" => "Add AICTE books", + "page callback" => "scilab_fixer_aicte_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 1, + "type" => MENU_DEFAULT_LOCAL_TASK + ); + $items["fix/aicte/edit"] = array( + "title" => "Edit AICTE books", + "page callback" => "scilab_fixer_aicte_edit_all", + "access arguments" => array( + "fix scilab" + ), + "weight" => 2, + "type" => MENU_LOCAL_TASK + ); + $items["fix/aicte/in"] = array( + "title" => "Mark Indian edition books", + "page callback" => "scilab_fixer_aicte_in_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_CALLBACK + ); + $items["fix/code"] = array( + "title" => "Edit TBC code", + "page callback" => "scilab_fixer_code_all", + "access arguments" => array( + "fix scilab" + ), + "type" => MENU_CALLBACK + ); + $items["fix/ajax"] = array( + "page callback" => "scilab_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["fix/aicte/book/ajax"] = array( + "page callback" => "scilab_fixer_aicte_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + return $items; +} +function scilab_fixer_perm() +{ + return array( + "fix scilab" => array( + "title" => t("fix scilab code"), + 'restrict access' => TRUE + ) + ); +} +function scilab_fixer_caption_form($form, &$form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Caption change form", + "#prefix" => "
", + "#suffix" => "
" + ); + $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_wrapper"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#prefix" => "
",
+		"#suffix" => "
" + ); + return $form; +} +function scilab_fixer_caption_all() +{ + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + // $page_content .= drupal_get_form("scilab_fixer_caption_form"); + $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); + $page_content .= drupal_render($scilab_fixer_caption_form); + $page_content .= "
"; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; + 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);*/ + $query = db_select('textbook_companion_preference', 'pre'); + $query->fields('pre', array( + 'id', + 'book', + 'author' + )); + $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); + $query->condition('pro.proposal_status', 3); + $query->condition('pre.approval_status', 1); + $query->condition('pre.category', $key); + $query->orderBy('pre.book', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "category" && $key + else if ($item == "book" && $key) + { + /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('preference_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "book" && $key + else if ($item == "chapter" && $key) + { + /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) + { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "chapter" && $key + 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);*/ + $query = db_select('textbook_companion_example_files', 'fil'); + $query->fields('fil'); + $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); + $query->condition('example_id', $key); + $result = $query->execute(); + $row = $result->fetchObject(); + /* 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 .= "
{$row->caption}
"; + $data .= "
{$example}
"; + } //$item == "example" && $key + 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);*/ + $query = db_update('textbook_companion_example'); + $query->fields(array( + 'caption' => $caption + )); + $query->condition('id', $example_id); + $result = $query->execute(); + $data .= "Updated"; + } //$item == "update" + else if ($item == "code" && $key) + { + $code = $_POST["code"]; + /*$query = " + SELECT * FROM textbook_companion_example_files + WHERE example_id = %d AND filetype = 'S' + "; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example_files'); + $query->fields('textbook_companion_example_files'); + $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $result = $query->execute(); + $row = $result->fetchObject(); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; + } //$item == "code" && $key + else if ($item == "ind-ed" && $key) + { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data .= "updated"; + } //$item == "ind-ed" && $key + else + { + $data = "Nothing to display."; + } + echo $data; + exit(); +} +function scilab_fixer_aicte_ajax($item = "", $key = "") +{ + $data = ""; + if ($item == "selected") + { + $query = " + UPDATE textbook_companion_aicte + SET selected = !selected + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data = "updated"; + } //$item == "selected" + echo $data; + exit(); +} +function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') +{ + /*$query = " + SELECT * FROM textbook_companion_aicte + WHERE id = {$aicte_id} + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->condition('id', $aicte_id); + $result = $query->execute(); + $row = $result->fetchObject(); + $form = array(); + $form["book"] = array( + "#type" => "textfield", + "#title" => "Book Name", + "#default_value" => $row->book, + "#required" => TRUE + ); + $form["author"] = array( + "#type" => "textfield", + "#title" => "Author", + "#default_value" => $row->author, + "#required" => TRUE + ); + $form["category"] = array( + "#type" => "select", + "#title" => "Book 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' + ), + "#default_value" => $row->category, + "#required" => TRUE + ); + $form["isbn"] = array( + "#type" => "textfield", + "#title" => "ISBN", + "#default_value" => $row->isbn, + "#required" => FALSE + ); + $form["publisher"] = array( + "#type" => "textfield", + "#title" => "Publisher", + "#default_value" => $row->publisher, + "#required" => TRUE + ); + $form["edition"] = array( + "#type" => "textfield", + "#title" => "Edition", + "#default_value" => $row->edition, + "#required" => TRUE + ); + $form["year"] = array( + "#type" => "textfield", + "#title" => "Year of publication", + "#default_value" => $row->year, + "#required" => TRUE + ); + $form["aicte_id"] = array( + "#type" => "hidden", + "#value" => $row->id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; +} +function scilab_fixer_aicte_form_validate($form, &$form_state) +{ + if (!$form_state["values"]["category"]) + { + form_set_error("category", "Please select a category."); + } //!$form_state["values"]["category"] + if (!is_numeric($form_state["values"]["edition"])) + { + form_set_error("edition", "Only digits are allowed."); + } //!is_numeric($form_state["values"]["edition"]) + if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) + { + form_set_error("year", "Please enter a valid year. eg: 2011."); + } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 +} +function scilab_fixer_aicte_form_submit($form, &$form_state) +{ + $v = $form_state["values"]; + if ($v["aicte_id"]) + { + /*$query = " + UPDATE textbook_companion_aicte + SET book = '%s', author = '%s', category = %d, + isbn = '%s', publisher = '%s', edition = %d, + year = %d + WHERE id = %d + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] + );*/ + $query = db_update('textbook_companion_aicte'); + $query->fields(array( + 'book' => $v["book"], + 'author' => $v["author"], + 'category' => $v["category"], + 'isbn' => $v["isbn"], + 'publisher' => $v["publisher"], + 'edition' => $v["edition"], + 'year' => $v["year"] + )); + $query->condition('id', $v["aicte_id"]); + $num_updated = $query->execute(); + drupal_set_message("Book updated successfully", "status"); + } //$v["aicte_id"] + else + { + $query = " + INSERT INTO textbook_companion_aicte + (book, author, category, isbn, publisher, edition, year) + VALUES + (:book, :author, :category, :isbn, :publisher, :edition, :year) + "; + $args = array( + ':book' => $v["book"], + ':author' => $v["author"], + ':category' => $v["category"], + ':isbn' => $v["isbn"], + ':publisher' => $v["publisher"], + ':edition' => $v["edition"], + ':year' => $v["year"] + ); + $result = db_query($query, $args); + drupal_set_message("Book added successfully", "status"); + } +} +function scilab_fixer_aicte_all() +{ + $page_content = ""; + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); + $page_content .= drupal_render($scilab_fixer_aicte_form); + return $page_content; +} +function scilab_fixer_aicte_edit_all($aicte_id = 0) +{ + $page_content = ""; + if ($aicte_id) + { + $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); + $page_content .= drupal_render($scilab_fixer_aicte_form); + } //$aicte_id + else + { + /*$query = " + SELECT * FROM textbook_companion_aicte + ORDER BY time DESC + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->orderBy('time', 'DESC'); + $result = $query->execute(); + $headers = array( + "Book", + "Author", + "Edition", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) + { + $item = array( + "{$row->book}", + "{$row->author}", + "{$row->edition}", + l(t("Edit"), "fix/aicte/edit/{$row->id}") + ); + if ($row->selected) + { + $check = ""; + } //$row->selected + else + { + $check = ""; + } + array_push($item, $check); + array_push($rows, $item); + } //$row = $result->fetchObject() + //$page_content .= theme("table", $headers, $rows); + $page_content .= theme("table", array( + 'header' => $headers, + 'rows' => $rows + )); + } + return $page_content; +} +function scilab_fixer_aicte_in_all() +{ + $page_content = ""; + /*$query = " + SELECT * FROM textbook_companion_aicte + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $result = $query->execute(); + $headers = array( + "Book", + "Publisher", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) + { + $item = array( + "data" => array( + "{$row->book}
by{$row->author}", + $row->publisher + ) + ); + $ind_options = array( + /* # linking in drupal l() */ + "fragment" => " ", + "external" => TRUE, + "attributes" => array( + "class" => "ind-ed", + "data-aicte" => "{$row->id}" + ) + ); + /* ind-ed link */ + if ($row->ind) + { + array_push($item["data"], l("Unmark", "", $ind_options)); + } //$row->ind + else + { + array_push($item["data"], l("Mark", "", $ind_options)); + } + if ($row->ind) + { + $item["class"] .= " orange"; + } //$row->ind + array_push($rows, $item); + } //$row = $result->fetchObject() + $page_content .= theme('table', array( + 'header' => $headers, + 'rows' => $rows + )); + return $page_content; +} +function scilab_fixer_code_form($form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Code edit form", + "#prefix" => "
", + "#suffix" => "
" + ); + $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"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor") + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update" + ); + return $form; +} +function scilab_fixer_code_all() +{ + $page_content = ""; + $page_content .= "
"; + $page_content .= "
Updating...
"; + $page_content .= "Done."; + $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); + $page_content .= drupal_render($scilab_fixer_code_form); + $page_content .= "
"; + return $page_content; +} +function scilab_fixer_init() +{ + drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); + //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); + drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); +} diff --git a/textbook_companion_fixer.module~ b/textbook_companion_fixer.module~ deleted file mode 100755 index 13271d0..0000000 --- a/textbook_companion_fixer.module~ +++ /dev/null @@ -1,651 +0,0 @@ - "Fix TBC captions", - "page callback" => "scilab_fixer_caption_all", - "access arguments" => array( - "fix scilab" - ), - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 30, - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte/new"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 1, - "type" => MENU_DEFAULT_LOCAL_TASK - ); - $items["fix/aicte/edit"] = array( - "title" => "Edit AICTE books", - "page callback" => "scilab_fixer_aicte_edit_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 2, - "type" => MENU_LOCAL_TASK - ); - $items["fix/aicte/in"] = array( - "title" => "Mark Indian edition books", - "page callback" => "scilab_fixer_aicte_in_all", - "access arguments" => array( - "fix scilab" - ), - "type" => MENU_CALLBACK - ); - $items["fix/code"] = array( - "title" => "Edit TBC code", - "page callback" => "scilab_fixer_code_all", - "access arguments" => array( - "fix scilab" - ), - "type" => MENU_CALLBACK - ); - $items["fix/ajax"] = array( - "page callback" => "scilab_fixer_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - $items["fix/aicte/book/ajax"] = array( - "page callback" => "scilab_fixer_aicte_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - return $items; -} -function scilab_fixer_perm() -{ - return array( - "fix scilab" => array( - "title" => t("fix scilab code"), - 'restrict access' => TRUE - ) - ); -} -function scilab_fixer_caption_form($form, &$form_state) -{ - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title" => "Caption change form", - "#prefix" => "
", - "#suffix" => "
" - ); - $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_wrapper"] = array( - "#type" => "fieldset", - "#description" => t("No code to display"), - "#prefix" => "
",
-		"#suffix" => "
" - ); - return $form; -} -function scilab_fixer_caption_all() -{ - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - // $page_content .= drupal_get_form("scilab_fixer_caption_form"); - $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); - $page_content .= drupal_render($scilab_fixer_caption_form); - $page_content .= "
"; - $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; - 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);*/ - $query = db_select('textbook_companion_preference', 'pre'); - $query->fields('pre', array( - 'id', - 'book', - 'author' - )); - $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); - $query->condition('pro.proposal_status', 3); - $query->condition('pre.approval_status', 1); - $query->condition('pre.category', $key); - $query->orderBy('pre.book', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) - { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "category" && $key - else if ($item == "book" && $key) - { - /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('preference_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) - { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "book" && $key - else if ($item == "chapter" && $key) - { - /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example'); - $query->fields('textbook_companion_example'); - $query->condition('chapter_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) - { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "chapter" && $key - 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);*/ - $query = db_select('textbook_companion_example_files', 'fil'); - $query->fields('fil'); - $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); - $query->condition('example_id', $key); - $result = $query->execute(); - $row = $result->fetchObject(); - /* 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 .= "
{$row->caption}
"; - $data .= "
{$example}
"; - } //$item == "example" && $key - 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);*/ - $query = db_update('textbook_companion_example'); - $query->fields(array( - 'caption' => $caption - )); - $query->condition('id', $example_id); - $result = $query->execute(); - $data .= "Updated"; - } //$item == "update" - else if ($item == "code" && $key) - { - $code = $_POST["code"]; - /*$query = " - SELECT * FROM textbook_companion_example_files - WHERE example_id = %d AND filetype = 'S' - "; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example_files'); - $query->fields('textbook_companion_example_files'); - $query->condition('example_id', $key); - $query->condition('filetype', 'S'); - $result = $query->execute(); - $row = $result->fetchObject(); - $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; - $example_path = $uploads_dir . $row->filepath; - file_put_contents($example_path, $code); - $data .= "updated"; - } //$item == "code" && $key - else if ($item == "ind-ed" && $key) - { - $query = " - UPDATE textbook_companion_aicte - SET ind = !ind - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query, $args); - $data .= "updated"; - } //$item == "ind-ed" && $key - else - { - $data = "Nothing to display."; - } - echo $data; - exit(); -} -function scilab_fixer_aicte_ajax($item = "", $key = "") -{ - $data = ""; - if ($item == "selected") - { - $query = " - UPDATE textbook_companion_aicte - SET selected = !selected - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query, $args); - $data = "updated"; - } //$item == "selected" - echo $data; - exit(); -} -function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') -{ - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE id = {$aicte_id} - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->condition('id', $aicte_id); - $result = $query->execute(); - $row = $result->fetchObject(); - $form = array(); - $form["book"] = array( - "#type" => "textfield", - "#title" => "Book Name", - "#default_value" => $row->book, - "#required" => TRUE - ); - $form["author"] = array( - "#type" => "textfield", - "#title" => "Author", - "#default_value" => $row->author, - "#required" => TRUE - ); - $form["category"] = array( - "#type" => "select", - "#title" => "Book 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' - ), - "#default_value" => $row->category, - "#required" => TRUE - ); - $form["isbn"] = array( - "#type" => "textfield", - "#title" => "ISBN", - "#default_value" => $row->isbn, - "#required" => FALSE - ); - $form["publisher"] = array( - "#type" => "textfield", - "#title" => "Publisher", - "#default_value" => $row->publisher, - "#required" => TRUE - ); - $form["edition"] = array( - "#type" => "textfield", - "#title" => "Edition", - "#default_value" => $row->edition, - "#required" => TRUE - ); - $form["year"] = array( - "#type" => "textfield", - "#title" => "Year of publication", - "#default_value" => $row->year, - "#required" => TRUE - ); - $form["aicte_id"] = array( - "#type" => "hidden", - "#value" => $row->id - ); - $form["submit"] = array( - "#type" => "submit", - "#value" => "Submit" - ); - return $form; -} -function scilab_fixer_aicte_form_validate($form, &$form_state) -{ - if (!$form_state["values"]["category"]) - { - form_set_error("category", "Please select a category."); - } //!$form_state["values"]["category"] - if (!is_numeric($form_state["values"]["edition"])) - { - form_set_error("edition", "Only digits are allowed."); - } //!is_numeric($form_state["values"]["edition"]) - if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) - { - form_set_error("year", "Please enter a valid year. eg: 2011."); - } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 -} -function scilab_fixer_aicte_form_submit($form, &$form_state) -{ - $v = $form_state["values"]; - if ($v["aicte_id"]) - { - /*$query = " - UPDATE textbook_companion_aicte - SET book = '%s', author = '%s', category = %d, - isbn = '%s', publisher = '%s', edition = %d, - year = %d - WHERE id = %d - "; - $result = db_query($query, - $v["book"], $v["author"], $v["category"], $v["isbn"], - $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] - );*/ - $query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'book' => $v["book"], - 'author' => $v["author"], - 'category' => $v["category"], - 'isbn' => $v["isbn"], - 'publisher' => $v["publisher"], - 'edition' => $v["edition"], - 'year' => $v["year"] - )); - $query->condition('id', $v["aicte_id"]); - $num_updated = $query->execute(); - drupal_set_message("Book updated successfully", "status"); - } //$v["aicte_id"] - else - { - $query = " - INSERT INTO textbook_companion_aicte - (book, author, category, isbn, publisher, edition, year) - VALUES - (:book, :author, :category, :isbn, :publisher, :edition, :year) - "; - $args = array( - ':book' => $v["book"], - ':author' => $v["author"], - ':category' => $v["category"], - ':isbn' => $v["isbn"], - ':publisher' => $v["publisher"], - ':edition' => $v["edition"], - ':year' => $v["year"] - ); - $result = db_query($query, $args); - drupal_set_message("Book added successfully", "status"); - } -} -function scilab_fixer_aicte_all() -{ - $page_content = ""; - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); - $page_content .= drupal_render($scilab_fixer_aicte_form); - return $page_content; -} -function scilab_fixer_aicte_edit_all($aicte_id = 0) -{ - $page_content = ""; - if ($aicte_id) - { - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); - $page_content .= drupal_render($scilab_fixer_aicte_form); - } //$aicte_id - else - { - /*$query = " - SELECT * FROM textbook_companion_aicte - ORDER BY time DESC - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->orderBy('time', 'DESC'); - $result = $query->execute(); - $headers = array( - "Book", - "Author", - "Edition", - "Action" - ); - $rows = array(); - while ($row = $result->fetchObject()) - { - $item = array( - "{$row->book}", - "{$row->author}", - "{$row->edition}", - l(t("Edit"), "fix/aicte/edit/{$row->id}") - ); - if ($row->selected) - { - $check = ""; - } //$row->selected - else - { - $check = ""; - } - array_push($item, $check); - array_push($rows, $item); - } //$row = $result->fetchObject() - //$page_content .= theme("table", $headers, $rows); - $page_content .= theme("table", array( - 'header' => $headers, - 'rows' => $rows - )); - } - return $page_content; -} -function scilab_fixer_aicte_in_all() -{ - $page_content = ""; - /*$query = " - SELECT * FROM textbook_companion_aicte - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $result = $query->execute(); - $headers = array( - "Book", - "Publisher", - "Action" - ); - $rows = array(); - while ($row = $result->fetchObject()) - { - $item = array( - "data" => array( - "{$row->book}
by{$row->author}", - $row->publisher - ) - ); - $ind_options = array( - /* # linking in drupal l() */ - "fragment" => " ", - "external" => TRUE, - "attributes" => array( - "class" => "ind-ed", - "data-aicte" => "{$row->id}" - ) - ); - /* ind-ed link */ - if ($row->ind) - { - array_push($item["data"], l("Unmark", "", $ind_options)); - } //$row->ind - else - { - array_push($item["data"], l("Mark", "", $ind_options)); - } - if ($row->ind) - { - $item["class"] .= " orange"; - } //$row->ind - array_push($rows, $item); - } //$row = $result->fetchObject() - $page_content .= theme('table', array( - 'header' => $headers, - 'rows' => $rows - )); - return $page_content; -} -function scilab_fixer_code_form($form_state) -{ - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title" => "Code edit form", - "#prefix" => "
", - "#suffix" => "
" - ); - $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"]["code"] = array( - "#type" => "textarea", - "#title" => t("Code Editor") - ); - $form["wrapper"]["submit"] = array( - "#type" => "submit", - "#value" => "Update" - ); - return $form; -} -function scilab_fixer_code_all() -{ - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); - $page_content .= drupal_render($scilab_fixer_code_form); - $page_content .= "
"; - return $page_content; -} -function scilab_fixer_init() -{ - drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); - //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); -} -- cgit From 601c7e0c45f8a66ef126a6a6ba232f995c631105 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:16:11 +0530 Subject: cleaned directory --- scilab_fixer.info | 3 - scilab_fixer.module | 514 ---------------------------------------------------- 2 files changed, 517 deletions(-) delete mode 100755 scilab_fixer.info delete mode 100755 scilab_fixer.module diff --git a/scilab_fixer.info b/scilab_fixer.info deleted file mode 100755 index b8707ea..0000000 --- a/scilab_fixer.info +++ /dev/null @@ -1,3 +0,0 @@ -name = Scilab fixer -description = Module to fix scilab bugs -core = 6.x diff --git a/scilab_fixer.module b/scilab_fixer.module deleted file mode 100755 index 33235e1..0000000 --- a/scilab_fixer.module +++ /dev/null @@ -1,514 +0,0 @@ - "Fix TBC captions", - "page callback" => "scilab_fixer_caption_all", - "access arguments" => array("fix scilab"), - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array("fix scilab"), - "weight" => 30, - "type" => MENU_NORMAL_ITEM - ); - $items["fix/aicte/new"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array("fix scilab"), - "weight" => 1, - "type" => MENU_DEFAULT_LOCAL_TASK - ); - $items["fix/aicte/edit"] = array( - "title" => "Edit AICTE books", - "page callback" => "scilab_fixer_aicte_edit_all", - "access arguments" => array("fix scilab"), - "weight" => 2, - "type" => MENU_LOCAL_TASK - ); - $items["fix/aicte/in"] = array( - "title" => "Mark Indian edition books", - "page callback" => "scilab_fixer_aicte_in_all", - "access arguments" => array("fix scilab"), - "type" => MENU_CALLBACK - ); - $items["fix/code"] = array( - "title" => "Edit TBC code", - "page callback" => "scilab_fixer_code_all", - "access arguments" => array("fix scilab"), - "type" => MENU_CALLBACK - ); - $items["fix/ajax"] = array( - "page callback" => "scilab_fixer_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - $items["fix/aicte/book/ajax"] = array( - "page callback" => "scilab_fixer_aicte_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" => "
", - "#suffix" => "
", - ); - $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_wrapper"] = array( - "#type" => "fieldset", - "#description" => t("No code to display"), - "#prefix" => "
",
-            "#suffix" => "
", - ); - return $form; - } - - function scilab_fixer_caption_all() { - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - $page_content .= drupal_get_form("scilab_fixer_caption_form"); - $page_content .= "
"; - $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; - 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 .= ""; - while($row = db_fetch_object($result)) { - $data .= ""; - } - } else if($item == "book" && $key) { - $query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; - $result = db_query($query, $key); - - $data .= ""; - while($row = db_fetch_object($result)) { - $data .= ""; - } - } else if($item == "chapter" && $key) { - $query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; - $result = db_query($query, $key); - - $data .= ""; - while($row = db_fetch_object($result)) { - $data .= ""; - } - } 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 .= "
{$row->caption}
"; - $data .= "
{$example}
"; - } 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 if($item == "code" && $key) { - $code = $_POST["code"]; - $query = " - SELECT * FROM textbook_companion_example_files - WHERE example_id = %d AND filetype = 'S' - "; - $result = db_query($query, $key); - $row = db_fetch_object($result); - $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; - $example_path = $uploads_dir . $row->filepath; - file_put_contents($example_path, $code); - $data .= "updated"; - } else if($item == "ind-ed" && $key) { - $query = " - UPDATE textbook_companion_aicte - SET ind = !ind - WHERE id = %d - "; - db_query($query, $key); - $data .= "updated"; - }else { - $data = "Nothing to display."; - } - echo $data; - exit(); - } - function scilab_fixer_aicte_ajax($item="", $key="") { - $data = ""; - if($item == "selected") { - $query = " - UPDATE textbook_companion_aicte - SET selected = !selected - WHERE id = {$key} - "; - db_query($query); - $data = "updated"; - } - echo $data; - exit(); - } - - - function scilab_fixer_aicte_form($form_state, $aicte_id) { - $query = " - SELECT * FROM textbook_companion_aicte - WHERE id = {$aicte_id} - "; - $result = db_query($query); - $row = db_fetch_object($result); - - $form = array(); - $form["book"] = array( - "#type" => "textfield", - "#title" => "Book Name", - "#default_value" => $row->book, - "#required" => TRUE - ); - $form["author"] = array( - "#type" => "textfield", - "#title" => "Author", - "#default_value" => $row->author, - "#required" => TRUE - ); - $form["category"] = array( - "#type" => "select", - "#title" => "Book 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' - ), - "#default_value" => $row->category, - "#required" => TRUE - ); - $form["isbn"] = array( - "#type" => "textfield", - "#title" => "ISBN", - "#default_value" => $row->isbn, - "#required" => FALSE - ); - $form["publisher"] = array( - "#type" => "textfield", - "#title" => "Publisher", - "#default_value" => $row->publisher, - "#required" => TRUE - ); - $form["edition"] = array( - "#type" => "textfield", - "#title" => "Edition", - "#default_value" => $row->edition, - "#required" => TRUE - ); - $form["year"] = array( - "#type" => "textfield", - "#title" => "Year of publication", - "#default_value" => $row->year, - "#required" => TRUE - ); - $form["aicte_id"] = array( - "#type" => "hidden", - "#value" => $row->id - ); - $form["submit"] = array( - "#type" => "submit", - "#value" => "Submit" - ); - return $form; - } - - function scilab_fixer_aicte_form_validate($form, &$form_state) { - if(!$form_state["values"]["category"]) { - form_set_error("category", "Please select a category."); - } - if(!is_numeric($form_state["values"]["edition"])) { - form_set_error("edition", "Only digits are allowed."); - } - if(!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { - form_set_error("year", "Please enter a valid year. eg: 2011."); - } - } - - function scilab_fixer_aicte_form_submit($form, &$form_state) { - $v = $form_state["values"]; - if($v["aicte_id"]) { - $query = " - UPDATE textbook_companion_aicte - SET book = '%s', author = '%s', category = %d, - isbn = '%s', publisher = '%s', edition = %d, - year = %d - WHERE id = %d - "; - $result = db_query($query, - $v["book"], $v["author"], $v["category"], $v["isbn"], - $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] - ); - drupal_set_message("Book updated successfully", "status"); - } else { - $query = " - INSERT INTO textbook_companion_aicte - (book, author, category, isbn, publisher, edition, year) - VALUES - ('%s', '%s', %d, '%s', '%s', %d, %d) - "; - $result = db_query($query, - $v["book"], $v["author"], $v["category"], $v["isbn"], - $v["publisher"], $v["edition"], $v["year"] - ); - drupal_set_message("Book added successfully", "status"); - } - } - - function scilab_fixer_aicte_all() { - $page_content = ""; - $page_content .= drupal_get_form("scilab_fixer_aicte_form"); - return $page_content; - } - - function scilab_fixer_aicte_edit_all($aicte_id=0) { - $page_content = ""; - if($aicte_id) { - $page_content .= drupal_get_form("scilab_fixer_aicte_form", $aicte_id); - } else { - $query = " - SELECT * FROM textbook_companion_aicte - ORDER BY time DESC - "; - $result = db_query($query); - $headers = array( - "Book", "Author", - "Edition", "Action", - ); - $rows = array(); - - while($row = db_fetch_object($result)) { - $item = array( - "{$row->book}", - "{$row->author}", - "{$row->edition}", - l(t("Edit"), "fix/aicte/edit/{$row->id}") - ); - if($row->selected) { - $check = ""; - } else { - $check = ""; - } - array_push($item, $check); - array_push($rows, $item); - } - $page_content .= theme("table", $headers, $rows); - } - return $page_content; - } - - function scilab_fixer_aicte_in_all(){ - $page_content = ""; - $query = " - SELECT * FROM textbook_companion_aicte - "; - $result = db_query($query); - $headers = array( - "Book", "Publisher", "Action" - ); - $rows = array(); - while($row = db_fetch_object($result)) { - $item = array( - "data" => array( - "{$row->book}
by{$row->author}", - $row->publisher, - ), - ); - $ind_options = array( - /* # linking in drupal l() */ - "fragment" => " ", - "external" => TRUE, - "attributes" => array( - "class" => "ind-ed", - "data-aicte" => "{$row->id}", - ) - ); - /* ind-ed link */ - if($row->ind) { - array_push($item["data"], l("Unmark", "", $ind_options)); - } else { - array_push($item["data"], l("Mark", "", $ind_options)); - } - if($row->ind) { - $item["class"] .= " orange"; - } - array_push($rows, $item); - } - $page_content .= theme("table", $headers, $rows); - return $page_content; - } - - function scilab_fixer_code_form($form_state) { - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title"=> "Code edit form", - "#prefix" => "
", - "#suffix" => "
", - ); - $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"]["code"] = array( - "#type" => "textarea", - "#title" => t("Code Editor"), - ); - $form["wrapper"]["submit"] = array( - "#type" => "submit", - "#value" => "Update" - ); - return $form; - } - - function scilab_fixer_code_all() { - $page_content = ""; - $page_content .= "
"; - $page_content .= "
Updating...
"; - $page_content .= "Done."; - $page_content .= drupal_get_form("scilab_fixer_code_form"); - $page_content .= "
"; - return $page_content; - } - - 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"); - drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/selection.js"); - } -?> -- cgit From 5316f8ccabceca4b4d5111cd00ac4ff306608e51 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:20:47 +0530 Subject: removed tmp readme --- README~ | 2 -- 1 file changed, 2 deletions(-) delete mode 100755 README~ diff --git a/README~ b/README~ deleted file mode 100755 index 186df63..0000000 --- a/README~ +++ /dev/null @@ -1,2 +0,0 @@ -Textbook Companion Fixer for FOSSEE, IIT Bombay written in Drupal 7 - -- cgit From ff3c6b954dfa626b1261d38227941b27f52a3255 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:38:29 +0530 Subject: changed css and js --- css/scilab_fixer.css | 47 ------------ js/scilab_fixer.js | 200 --------------------------------------------------- 2 files changed, 247 deletions(-) delete mode 100755 css/scilab_fixer.css delete mode 100755 js/scilab_fixer.js diff --git a/css/scilab_fixer.css b/css/scilab_fixer.css deleted file mode 100755 index 5634290..0000000 --- a/css/scilab_fixer.css +++ /dev/null @@ -1,47 +0,0 @@ -#fix-tbc-form #edit-caption { - width: 99% !important; -} -#fix-tbc-form .well { - margin-top: 25px; - width: 620px; - overflow-x: auto; -} -#fix-tbc-form #edit-example { - height: 250px; -} -#fix-tbc-page #updating, -#fix-tbc-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-tbc-page #updating { - background: #FF851B; -} -#fix-tbc-page #done { - background: #2ECC40; -} -textarea#edit-code { - height: 300px; - width: 650px; -} -.orange { - background: #FF9933 !important; -} -.sync-msg { - font-size: .8em; -} -.messages.success { - background: lightgreen; -} diff --git a/js/scilab_fixer.js b/js/scilab_fixer.js deleted file mode 100755 index 657cb61..0000000 --- a/js/scilab_fixer.js +++ /dev/null @@ -1,200 +0,0 @@ -$(document).ready(function() { - var basePath = Drupal.settings.basePath; - var modPath = basePath + "fix/"; - var modPath1 = basePath + "fix/aicte/book/"; - - - - $category = $("#fix-tbc-form #edit-category"); - $book = $("#fix-tbc-form #edit-book"); - $chapter = $("#fix-tbc-form #edit-chapter"); - $example = $("#fix-tbc-form #edit-example"); - $caption = $("#fix-tbc-form #edit-caption"); - $code = $("#fix-tbc-form #edit-code"); - $caption_form = $("#scilab-fixer-caption-form"); - $code_form = $("#scilab-fixer-code-form"); - $updating = $("#fix-tbc-page #updating"); - $done = $("#fix-tbc-page #done"); - $example.attr("multiple", "enabled"); - - function reset() { - for (var i = 0, l = arguments.length; i < l; i ++) { - switch(arguments[i]) { - case "book": - $book.html(""); - break; - - case "chapter": - $chapter.html(""); - break; - - case "example": - $example.html(""); - break; - - case "caption": - $caption.val(""); - break; - - } - } - } - - $category.change(function() { - reset("book", "chapter", "example", "caption"); - 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", "caption"); - 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", "caption"); - 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(); - reset("caption"); - console.log("########" + example_id); - $.ajax({ - url: modPath + "ajax/example/" + example_id, - type: "POST", - dataType: "html", - success: function(data) { - var code = $(data).filter("#code").html(); - /* checking whether it is for .well or textarea */ - if($code.hasClass("fix-caption-code")) { - $code.html(code); - } else { - $code.val(code); - } - var caption = $(data).filter("#caption").html(); - try { - $caption.val(caption); - } catch(e) { - return; - } - } - }); - }); - - $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(); - }); - - $code_form.submit(function(e) { - var example_id = $example.val(); - if(example_id != "0") { - var code = $code.val(); - $.ajax({ - url: modPath + "ajax/code/" + example_id, - type: "POST", - data: { - code: code - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No example selected.") - } - e.preventDefault(); - }); - -$Selected = $(".selected"); - $Selected.click(function (e) { - $(".sync-msg").remove(); - $(this).after("Saving..."); - $.ajax({ - url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), - success: function() { - $(".sync-msg").remove(); - console.log ("success"); - } - }); - - }); - - /* toggle in edition */ - $ind_ed = $(".ind-ed"); - - $ind_ed.click(function(e) { - var aicte_id = $(this).attr("data-aicte"); - $t = $(this); - $.ajax({ - url: modPath + "ajax/ind-ed/" + aicte_id, - type: "GET", - dataType: "html", - success: function(data) { - $tr = $t.parents("tr:first"); - if($tr.hasClass("orange")) { - $t.parents("tr:first").removeClass("orange"); - $t.html("Mark"); - } else { - $t.parents("tr:first").addClass("orange"); - $t.html("Unmark"); - } - console.log(data); - }, - }); - e.preventDefault(); - }); - -}); -- cgit From ca575c7aa48ad85669cf04957d5e4de3d8a27c2c Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:39:48 +0530 Subject: added renamed files --- css/textbook_companion_fixer.css | 47 +++++++++ js/textbook_companion_fixer.js | 202 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100755 css/textbook_companion_fixer.css create mode 100755 js/textbook_companion_fixer.js diff --git a/css/textbook_companion_fixer.css b/css/textbook_companion_fixer.css new file mode 100755 index 0000000..5634290 --- /dev/null +++ b/css/textbook_companion_fixer.css @@ -0,0 +1,47 @@ +#fix-tbc-form #edit-caption { + width: 99% !important; +} +#fix-tbc-form .well { + margin-top: 25px; + width: 620px; + overflow-x: auto; +} +#fix-tbc-form #edit-example { + height: 250px; +} +#fix-tbc-page #updating, +#fix-tbc-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-tbc-page #updating { + background: #FF851B; +} +#fix-tbc-page #done { + background: #2ECC40; +} +textarea#edit-code { + height: 300px; + width: 650px; +} +.orange { + background: #FF9933 !important; +} +.sync-msg { + font-size: .8em; +} +.messages.success { + background: lightgreen; +} diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js new file mode 100755 index 0000000..7a7e3fe --- /dev/null +++ b/js/textbook_companion_fixer.js @@ -0,0 +1,202 @@ +(function ($) { +$(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "fix/"; + var modPath1 = basePath + "fix/aicte/book/"; + + + + $category = $("#fix-tbc-form #edit-category"); + $book = $("#fix-tbc-form #edit-book"); + $chapter = $("#fix-tbc-form #edit-chapter"); + $example = $("#fix-tbc-form #edit-example"); + $caption = $("#fix-tbc-form #edit-caption"); + $code = $("#fix-tbc-form #edit-code"); + $caption_form = $("#scilab-fixer-caption-form"); + $code_form = $("#scilab-fixer-code-form"); + $updating = $("#fix-tbc-page #updating"); + $done = $("#fix-tbc-page #done"); + $example.attr("multiple", "enabled"); + + function reset() { + for (var i = 0, l = arguments.length; i < l; i ++) { + switch(arguments[i]) { + case "book": + $book.html(""); + break; + + case "chapter": + $chapter.html(""); + break; + + case "example": + $example.html(""); + break; + + case "caption": + $caption.val(""); + break; + + } + } + } + + $category.change(function() { + reset("book", "chapter", "example", "caption"); + 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", "caption"); + 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", "caption"); + 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(); + reset("caption"); + console.log("########" + example_id); + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + /* checking whether it is for .well or textarea */ + if($code.hasClass("fix-caption-code")) { + $code.html(code); + } else { + $code.val(code); + } + var caption = $(data).filter("#caption").html(); + try { + $caption.val(caption); + } catch(e) { + return; + } + } + }); + }); + + $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(); + }); + + $code_form.submit(function(e) { + var example_id = $example.val(); + if(example_id != "0") { + var code = $code.val(); + $.ajax({ + url: modPath + "ajax/code/" + example_id, + type: "POST", + data: { + code: code + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); + +$Selected = $(".selected"); + $Selected.click(function (e) { + $(".sync-msg").remove(); + $(this).after("Saving..."); + $.ajax({ + url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), + success: function() { + $(".sync-msg").remove(); + console.log ("success"); + } + }); + + }); + + /* toggle in edition */ + $ind_ed = $(".ind-ed"); + + $ind_ed.click(function(e) { + var aicte_id = $(this).attr("data-aicte"); + $t = $(this); + $.ajax({ + url: modPath + "ajax/ind-ed/" + aicte_id, + type: "GET", + dataType: "html", + success: function(data) { + $tr = $t.parents("tr:first"); + if($tr.hasClass("orange")) { + $t.parents("tr:first").removeClass("orange"); + $t.html("Mark"); + } else { + $t.parents("tr:first").addClass("orange"); + $t.html("Unmark"); + } + console.log(data); + }, + }); + e.preventDefault(); + }); + +}); +})(jQuery); -- cgit From c0fdf418952a5f8fb82ef77a85a979d7d2225295 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 1 Sep 2016 14:40:35 +0530 Subject: fixed module name issue --- textbook_companion_fixer.module | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 13271d0..43fd138 100644 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -146,7 +146,6 @@ function scilab_fixer_caption_all() $page_content .= "
"; $page_content .= "
Updating...
"; $page_content .= "Done."; - // $page_content .= drupal_get_form("scilab_fixer_caption_form"); $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); $page_content .= drupal_render($scilab_fixer_caption_form); $page_content .= "
"; @@ -644,8 +643,8 @@ function scilab_fixer_code_all() } function scilab_fixer_init() { - drupal_add_css(drupal_get_path("module", "textbook_ companion_fixer") . "/css/textbook_ companion_fixer.css"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/textbook_ companion_fixer.js"); + drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); + drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer.js"); //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); - drupal_add_js(drupal_get_path("module", "textbook_ companion_fixer") . "/js/selection.js"); + drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/selection.js"); } -- cgit From 3ae4e7999194b3e22643e352dc59b80368f51165 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 15:54:48 +0530 Subject: fixed dropdown issue and formated the code --- js/textbook_companion_fixer.js | 453 +++++++++++++++++++++++------------------ 1 file changed, 253 insertions(+), 200 deletions(-) diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js index 7a7e3fe..0ad82ad 100755 --- a/js/textbook_companion_fixer.js +++ b/js/textbook_companion_fixer.js @@ -1,202 +1,255 @@ -(function ($) { -$(document).ready(function() { - var basePath = Drupal.settings.basePath; - var modPath = basePath + "fix/"; - var modPath1 = basePath + "fix/aicte/book/"; +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "textbook_companion_fixer/"; + var modPath1 = basePath + "textbook_companion_fixer/aicte/book/"; + $category = $("#fix-tbc-form #edit-category"); + $book = $("#fix-tbc-form #edit-book"); + $chapter = $("#fix-tbc-form #edit-chapter"); + $example = $("#fix-tbc-form #edit-example"); + $caption = $("#fix-tbc-form #edit-caption"); + $code = $("#fix-tbc-form #edit-code"); + $caption_form = $("#scilab-fixer-caption-form"); + $code_form = $("#scilab-fixer-code-form"); + $updating = $("#fix-tbc-page #updating"); + $done = $("#fix-tbc-page #done"); + $example.attr("multiple", "enabled"); - - - $category = $("#fix-tbc-form #edit-category"); - $book = $("#fix-tbc-form #edit-book"); - $chapter = $("#fix-tbc-form #edit-chapter"); - $example = $("#fix-tbc-form #edit-example"); - $caption = $("#fix-tbc-form #edit-caption"); - $code = $("#fix-tbc-form #edit-code"); - $caption_form = $("#scilab-fixer-caption-form"); - $code_form = $("#scilab-fixer-code-form"); - $updating = $("#fix-tbc-page #updating"); - $done = $("#fix-tbc-page #done"); - $example.attr("multiple", "enabled"); - - function reset() { - for (var i = 0, l = arguments.length; i < l; i ++) { - switch(arguments[i]) { - case "book": - $book.html(""); - break; - - case "chapter": - $chapter.html(""); - break; - - case "example": - $example.html(""); - break; - - case "caption": - $caption.val(""); - break; - - } - } - } - - $category.change(function() { - reset("book", "chapter", "example", "caption"); - 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", "caption"); - 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", "caption"); - 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(); - reset("caption"); - console.log("########" + example_id); - $.ajax({ - url: modPath + "ajax/example/" + example_id, - type: "POST", - dataType: "html", - success: function(data) { - var code = $(data).filter("#code").html(); - /* checking whether it is for .well or textarea */ - if($code.hasClass("fix-caption-code")) { - $code.html(code); - } else { - $code.val(code); - } - var caption = $(data).filter("#caption").html(); - try { - $caption.val(caption); - } catch(e) { - return; - } - } - }); - }); - - $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(); - }); - - $code_form.submit(function(e) { - var example_id = $example.val(); - if(example_id != "0") { - var code = $code.val(); - $.ajax({ - url: modPath + "ajax/code/" + example_id, - type: "POST", - data: { - code: code - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No example selected.") - } - e.preventDefault(); - }); - -$Selected = $(".selected"); - $Selected.click(function (e) { - $(".sync-msg").remove(); - $(this).after("Saving..."); - $.ajax({ - url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), - success: function() { - $(".sync-msg").remove(); - console.log ("success"); - } - }); - - }); - - /* toggle in edition */ - $ind_ed = $(".ind-ed"); - - $ind_ed.click(function(e) { - var aicte_id = $(this).attr("data-aicte"); - $t = $(this); - $.ajax({ - url: modPath + "ajax/ind-ed/" + aicte_id, - type: "GET", - dataType: "html", - success: function(data) { - $tr = $t.parents("tr:first"); - if($tr.hasClass("orange")) { - $t.parents("tr:first").removeClass("orange"); - $t.html("Mark"); - } else { - $t.parents("tr:first").addClass("orange"); - $t.html("Unmark"); - } - console.log(data); - }, - }); - e.preventDefault(); - }); - -}); + function reset() { + for (var i = 0, l = arguments.length; i < l; i++) { + switch (arguments[i]) { + case "book": + $book.html(""); + break; + case "chapter": + $chapter.html(""); + break; + case "example": + $example.html(""); + break; + case "caption": + $caption.val(""); + break; + } + } + } + $(".select-book").hide(); + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + $category.change(function() { + reset("book", "chapter", "example", "caption"); + var category_id = $(this).val(); + if (category_id < 1) { + $(".select-book").hide(); + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + (".well").hide(); + $(".update-button").hide(); + } else { + $(".select-book").show(); + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } + $.ajax({ + url: modPath + "ajax/category/" + category_id, + type: "POST", + dataType: "html", + success: function(data) { + $book.html(data); + } + }); + }); + $book.change(function() { + reset("chapter", "example", "caption"); + var book_id = $(this).val(); + if (book_id < 1) { + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-chapter").show(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } + $.ajax({ + url: modPath + "ajax/book/" + book_id, + type: "POST", + dataType: "html", + success: function(data) { + $chapter.html(data); + } + }); + }); + $chapter.change(function() { + reset("example", "caption"); + var chapter_id = $(this).val(); + if (chapter_id < 1) { + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-example").show(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".update-button").hide(); + } + $.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(); + var example_caption = $(this).text(); + reset("caption"); + if (example_id < 1) { + $(".enter-caption").hide(); + // $("#edit-caption").val(""); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".enter-caption").show(); + // $("#edit-caption").val(example_caption); + $(".example-code-edit").show(); + $(".well").show(); + $(".update-button").show(); + } + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + /* checking whether it is for .well or textarea */ + if ($code.hasClass("fix-caption-code")) { + $code.html(code); + } else { + $code.val(code); + } + var caption = $(data).filter("#caption").html(); + try { + $caption.val(caption); + } catch (e) { + return; + } + } + }); + }); + $caption_form.submit(function(e) { + var example_id = $example.val(); + if (example_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + if (caption == '') { + alert('Please enter new caption '); + return false; + } + $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(); + }); + $code_form.submit(function(e) { + var example_id = $example.val(); + if (example_id != "0") { + var code = $code.val(); + code = code.trim(); + if (code == '') { + alert('Please enter new code'); + return false; + } + $.ajax({ + url: modPath + "ajax/code/" + example_id, + type: "POST", + data: { + code: code + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + $(".example-code-edit").show(); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); + $Selected = $(".selected"); + $Selected.click(function(e) { + $(".sync-msg").remove(); + $(this).after("Saving..."); + $.ajax({ + url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), + success: function() { + $(".sync-msg").remove(); + console.log("success"); + } + }); + }); + /* toggle in edition */ + $ind_ed = $(".ind-ed"); + $ind_ed.click(function(e) { + var aicte_id = $(this).attr("data-aicte"); + $t = $(this); + $.ajax({ + url: modPath + "ajax/ind-ed/" + aicte_id, + type: "GET", + dataType: "html", + success: function(data) { + $tr = $t.parents("tr:first"); + if ($tr.hasClass("orange")) { + $t.parents("tr:first").removeClass("orange"); + $t.html("Mark"); + } else { + $t.parents("tr:first").addClass("orange"); + $t.html("Unmark"); + } + }, + }); + e.preventDefault(); + }); + }); })(jQuery); -- cgit From bbd1a3e69dc1cdb658f6f171805c01f9d208ea39 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 15:55:32 +0530 Subject: fixed css issue and formated the code --- css/textbook_companion_fixer.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/css/textbook_companion_fixer.css b/css/textbook_companion_fixer.css index 5634290..1a91bb0 100755 --- a/css/textbook_companion_fixer.css +++ b/css/textbook_companion_fixer.css @@ -6,9 +6,9 @@ width: 620px; overflow-x: auto; } -#fix-tbc-form #edit-example { +/*#fix-tbc-form #edit-example { height: 250px; -} +}*/ #fix-tbc-page #updating, #fix-tbc-page #done { display: none; -- cgit From 521d9ca9ffd6ff78b9549fb8727b747517196adb Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 15:56:53 +0530 Subject: formated the code --- js/selection.js | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/js/selection.js b/js/selection.js index 6834aca..639afe5 100755 --- a/js/selection.js +++ b/js/selection.js @@ -1,26 +1,27 @@ function getSelectionText(divID) { - var selectedText = ""; - if (window.getSelection) { - var sel = window.getSelection(); - var div = document.getElementById(divID); - - if (sel.rangeCount) { - // Get the selected range - var range = sel.getRangeAt(0); - // Check that the selection is wholly contained within the div text - // if (range.commonAncestorContainer == div.firstChild) { - var selectedText = range.toString(); - // } - } - } - return selectedText; + var selectedText = ""; + if (window.getSelection) { + var sel = window.getSelection(); + var div = document.getElementById(divID); + if (sel.rangeCount) { + // Get the selected range + var range = sel.getRangeAt(0); + // Check that the selection is wholly contained within the div text + // if (range.commonAncestorContainer == div.firstChild) { + var selectedText = range.toString(); + // } + } + } + return selectedText; } -$(document).ready(function() { - $(".fix-caption-code").mousedown(function() { - $("#edit-caption").val(""); - }); - $(".fix-caption-code").mouseup(function() { - quotedText = getSelectionText("#fix-caption-code"); - $("#edit-caption").val(quotedText); - }); -}); +(function($) { + $(document).ready(function() { + $(".fix-caption-code").mousedown(function() { + $("#edit-caption").val(""); + }); + $(".fix-caption-code").mouseup(function() { + quotedText = getSelectionText("#fix-caption-code"); + $("#edit-caption").val(quotedText); + }); + }); +})(jQuery); -- cgit From 7d5c663a20f2f32ba1f8bc58c3ce8bc61770fa04 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 15:58:44 +0530 Subject: fixed validation issue and formated the code --- textbook_companion_fixer.module | 156 ++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 77 deletions(-) mode change 100644 => 100755 textbook_companion_fixer.module diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module old mode 100644 new mode 100755 index 43fd138..632f488 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -1,8 +1,8 @@ "Fix TBC captions", "page callback" => "scilab_fixer_caption_all", "access arguments" => array( @@ -10,7 +10,7 @@ function scilab_fixer_menu() ), "type" => MENU_NORMAL_ITEM ); - $items["fix/aicte"] = array( + $items["textbook_companion_fixer/aicte"] = array( "title" => "Add AICTE books", "page callback" => "scilab_fixer_aicte_all", "access arguments" => array( @@ -19,7 +19,7 @@ function scilab_fixer_menu() "weight" => 30, "type" => MENU_NORMAL_ITEM ); - $items["fix/aicte/new"] = array( + $items["textbook_companion_fixer/aicte/new"] = array( "title" => "Add AICTE books", "page callback" => "scilab_fixer_aicte_all", "access arguments" => array( @@ -28,7 +28,7 @@ function scilab_fixer_menu() "weight" => 1, "type" => MENU_DEFAULT_LOCAL_TASK ); - $items["fix/aicte/edit"] = array( + $items["textbook_companion_fixer/aicte/edit"] = array( "title" => "Edit AICTE books", "page callback" => "scilab_fixer_aicte_edit_all", "access arguments" => array( @@ -37,7 +37,7 @@ function scilab_fixer_menu() "weight" => 2, "type" => MENU_LOCAL_TASK ); - $items["fix/aicte/in"] = array( + $items["textbook_companion_fixer/aicte/in"] = array( "title" => "Mark Indian edition books", "page callback" => "scilab_fixer_aicte_in_all", "access arguments" => array( @@ -45,7 +45,7 @@ function scilab_fixer_menu() ), "type" => MENU_CALLBACK ); - $items["fix/code"] = array( + $items["textbook_companion_fixer/code"] = array( "title" => "Edit TBC code", "page callback" => "scilab_fixer_code_all", "access arguments" => array( @@ -53,19 +53,19 @@ function scilab_fixer_menu() ), "type" => MENU_CALLBACK ); - $items["fix/ajax"] = array( + $items["textbook_companion_fixer/ajax"] = array( "page callback" => "scilab_fixer_ajax", "access callback" => TRUE, "type" => MENU_CALLBACK ); - $items["fix/aicte/book/ajax"] = array( + $items["textbook_companion_fixer/aicte/book/ajax"] = array( "page callback" => "scilab_fixer_aicte_ajax", "access callback" => TRUE, "type" => MENU_CALLBACK ); return $items; } -function scilab_fixer_perm() +function textbook_companion_fixer_permission() { return array( "fix scilab" => array( @@ -86,55 +86,51 @@ function scilab_fixer_caption_form($form, &$form_state) $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' - ) + '#options' => _tbc_fixer_list_of_category(), ); $form["wrapper"]["book"] = array( "#type" => "select", "#title" => t("Please select the book."), "#options" => array( 0 => "Please select a book" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]["chapter"] = array( "#type" => "select", "#title" => t("Please select the chapter"), "#options" => array( 0 => "Please select a chapter" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]["example"] = array( "#type" => "select", "#title" => t("Please select the example"), "#options" => array( 0 => "Please select a example" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]["caption"] = array( "#type" => "textfield", - "#title" => t("Enter new caption") + "#title" => t("Enter new caption"), + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]["submit"] = array( "#type" => "submit", - "#value" => "Update" + "#value" => "Update", + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]["code_wrapper"] = array( "#type" => "fieldset", "#description" => t("No code to display"), + "#attributes" =>array("onclick" => "return check();"), "#prefix" => "
",
 		"#suffix" => "
" ); @@ -285,7 +281,7 @@ function scilab_fixer_ajax($item, $key) } //$item == "ind-ed" && $key else { - $data = "Nothing to display."; + $data = ""; } echo $data; exit(); @@ -337,22 +333,7 @@ function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') $form["category"] = array( "#type" => "select", "#title" => "Book 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' - ), + '#options' => _tbc_fixer_list_of_category(), "#default_value" => $row->category, "#required" => TRUE ); @@ -570,63 +551,59 @@ function scilab_fixer_aicte_in_all() )); return $page_content; } -function scilab_fixer_code_form($form_state) +function scilab_fixer_code_form($form, &$form_state) { $form = array(); - $form["wrapper"] = array( + $form["code_edit"] = array( "#type" => "fieldset", "#title" => "Code edit form", "#prefix" => "
", "#suffix" => "
" ); - $form["wrapper"]["category"] = array( + $form["code_edit"]["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' - ) + '#options' => _tbc_fixer_list_of_category(), ); - $form["wrapper"]["book"] = array( + $form["code_edit"]["book"] = array( "#type" => "select", "#title" => t("Please select the book."), "#options" => array( 0 => "Please select a book" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); - $form["wrapper"]["chapter"] = array( + $form["code_edit"]["chapter"] = array( "#type" => "select", "#title" => t("Please select the chapter"), "#options" => array( 0 => "Please select a chapter" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); - $form["wrapper"]["example"] = array( + $form["code_edit"]["example"] = array( "#type" => "select", "#title" => t("Please select the example"), "#options" => array( 0 => "Please select a example" - ) + ), + "#prefix" => "
", + "#suffix" => "
" ); - $form["wrapper"]["code"] = array( + $form["code_edit"]["code"] = array( "#type" => "textarea", - "#title" => t("Code Editor") + "#title" => t("Code Editor"), + '#resizable' => FALSE, + "#prefix" => "
", + "#suffix" => "
" ); - $form["wrapper"]["submit"] = array( + $form["code_edit"]["submit"] = array( "#type" => "submit", - "#value" => "Update" + "#value" => "Update", + "#prefix" => "
", + "#suffix" => "
" ); return $form; } @@ -641,6 +618,30 @@ function scilab_fixer_code_all() $page_content .= "
"; return $page_content; } +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} function scilab_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); @@ -648,3 +649,4 @@ function scilab_fixer_init() //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/selection.js"); } +?> -- cgit From 7dc4abc4c8c3bb4ce55890012c148c2ee39eb9e0 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 15:59:16 +0530 Subject: changed mode --- textbook_companion_fixer.info | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 textbook_companion_fixer.info diff --git a/textbook_companion_fixer.info b/textbook_companion_fixer.info old mode 100644 new mode 100755 -- cgit From 1244937f25cde55f8503d3f34f637f3245d93877 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 6 Sep 2016 16:11:52 +0530 Subject: changed menu type --- textbook_companion_fixer.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 632f488..43a7e4c 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -51,7 +51,7 @@ function textbook_companion_fixer_menu() "access arguments" => array( "fix scilab" ), - "type" => MENU_CALLBACK + "type" => MENU_NORMAL_ITEM ); $items["textbook_companion_fixer/ajax"] = array( "page callback" => "scilab_fixer_ajax", -- cgit From e489dbec533919c0eae69f0fa590c64e2902591a Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 5 Jan 2017 11:08:03 +0530 Subject: added new permisson and fixed jquery issue --- textbook_companion_fixer.module | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 43a7e4c..cfecdd5 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -3,10 +3,10 @@ function textbook_companion_fixer_menu() { $items = array(); $items["textbook_companion_fixer/caption"] = array( - "title" => "Fix TBC captions", + "title" => "Edit TBC captions", "page callback" => "scilab_fixer_caption_all", "access arguments" => array( - "fix scilab" + "fix scilab_code_caption" ), "type" => MENU_NORMAL_ITEM ); @@ -71,7 +71,12 @@ function textbook_companion_fixer_permission() "fix scilab" => array( "title" => t("fix scilab code"), 'restrict access' => TRUE - ) + ), + "fix scilab_code_caption" => array( + "title" => t("fix scilab code caption"), + 'restrict access' => TRUE + ) + ); } function scilab_fixer_caption_form($form, &$form_state) @@ -642,11 +647,10 @@ function _tbc_fixer_list_of_category($category_id = NULL) } //$category_list_data = $category_list->fetchObject() return $category; } -function scilab_fixer_init() +function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer.js"); //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/selection.js"); } -?> -- cgit From 89ef9d359b29352e8c22ee8642cf203ae2f0c84b Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Fri, 20 Jan 2017 15:28:14 +0530 Subject: added the chapter name edit option and traker mail for every edit --- js/selection.js | 9 ++ js/textbook_companion_fixer.js | 134 +++++++++++++++---- textbook_companion_fixer.module | 238 ++++++++++++++++++++++++---------- textbook_companion_fixer_email.inc | 154 ++++++++++++++++++++++ textbook_companion_fixer_settings.inc | 58 +++++++++ 5 files changed, 501 insertions(+), 92 deletions(-) create mode 100644 textbook_companion_fixer_email.inc create mode 100644 textbook_companion_fixer_settings.inc diff --git a/js/selection.js b/js/selection.js index 639afe5..6488c73 100755 --- a/js/selection.js +++ b/js/selection.js @@ -14,6 +14,8 @@ function getSelectionText(divID) { } return selectedText; } + + (function($) { $(document).ready(function() { $(".fix-caption-code").mousedown(function() { @@ -23,5 +25,12 @@ function getSelectionText(divID) { quotedText = getSelectionText("#fix-caption-code"); $("#edit-caption").val(quotedText); }); + $("#edit-example").mousedown(function() { + $("#edit-caption").val(""); + }); + $("#edit-example").mouseup(function() { + quotedText = $('option:selected', this).attr("data-exampleid"); + $("#edit-caption").val(quotedText); + }); }); })(jQuery); diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js index 0ad82ad..d7b617e 100755 --- a/js/textbook_companion_fixer.js +++ b/js/textbook_companion_fixer.js @@ -35,6 +35,8 @@ } $(".select-book").hide(); $(".select-chapter").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); $(".select-example").hide(); $(".enter-caption").hide(); $(".example-code-edit").hide(); @@ -46,14 +48,18 @@ if (category_id < 1) { $(".select-book").hide(); $(".select-chapter").hide(); + $(".enter-chapter-name").hide(); $(".select-example").hide(); $(".enter-caption").hide(); + $(".chapter-example-chk").hide(); $(".example-code-edit").hide(); (".well").hide(); $(".update-button").hide(); } else { $(".select-book").show(); $(".select-chapter").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); $(".select-example").hide(); $(".enter-caption").hide(); $(".example-code-edit").hide(); @@ -76,12 +82,16 @@ $(".select-chapter").hide(); $(".select-example").hide(); $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); $(".example-code-edit").hide(); $(".well").hide(); $(".update-button").hide(); } else { $(".select-chapter").show(); $(".select-example").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); $(".enter-caption").hide(); $(".example-code-edit").hide(); $(".well").hide(); @@ -98,18 +108,24 @@ }); $chapter.change(function() { reset("example", "caption"); + var chapter_name = $('option:selected', this).attr("data-chaptername"); var chapter_id = $(this).val(); if (chapter_id < 1) { $(".select-example").hide(); $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); $(".example-code-edit").hide(); $(".well").hide(); $(".update-button").hide(); } else { $(".select-example").show(); + $(".enter-chapter-name").show(); + $(".chapter-example-chk").show(); + $("#edit-chapter-name").val(chapter_name); $(".enter-caption").hide(); $(".example-code-edit").hide(); - $(".update-button").hide(); + $(".update-button").show(); } $.ajax({ url: modPath + "ajax/chapter/" + chapter_id, @@ -121,9 +137,10 @@ }); }); $example.change(function() { + reset("caption"); var example_id = $(this).val(); + var example_name = $('option:selected', this).attr("data-exampleid"); var example_caption = $(this).text(); - reset("caption"); if (example_id < 1) { $(".enter-caption").hide(); // $("#edit-caption").val(""); @@ -132,7 +149,7 @@ $(".update-button").hide(); } else { $(".enter-caption").show(); - // $("#edit-caption").val(example_caption); + $("#edit-caption").val(example_name); $(".example-code-edit").show(); $(".well").show(); $(".update-button").show(); @@ -158,33 +175,100 @@ } }); }); + //edit caption form submit $caption_form.submit(function(e) { var example_id = $example.val(); - if (example_id != "0") { - var caption = $caption.val(); - caption = caption.trim(); - if (caption == '') { - alert('Please enter new caption '); - return false; + var chapter_id = $('option:selected', $chapter).attr("data-chapterid"); + if ($('.chapter-caption-chk').prop('checked') == true && $( + '.example-caption-chk').prop('checked') == true) { + if (example_id != "0" && chapter_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + if (caption == '' || chapter_caption =='') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-both/", + type: "POST", + data: { + example_id: example_id, + caption: caption, + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No entry is selected.") } - $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 if ($('.example-caption-chk').prop('checked') == true) { + if (example_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + if (caption == '') { + alert('Please enter new caption '); + return false; } - }); + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-example/", + 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.") + } + } else if ($('.chapter-caption-chk').prop('checked') == true) { + if (chapter_id != "0") { + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + if (chapter_caption == '') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-chapter/", + type: "POST", + data: { + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } } else { - alert("No example selected.") + alert("Please select the checkbox option") } e.preventDefault(); }); diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index cfecdd5..1686c61 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -1,4 +1,5 @@ TRUE, "type" => MENU_CALLBACK ); + /* for admin */ + $items['admin/settings/textbook_companion_fixer_settings'] = array( + 'title' => 'textbook companion fixer Settings', + 'description' => 'Textbook Companion Fixer Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'textbook_companion_fixer_settings_form' + ), + 'access arguments' => array( + 'administer textbook companion fixer settings' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'textbook_companion_fixer_settings.inc' + ); return $items; } function textbook_companion_fixer_permission() @@ -73,10 +88,13 @@ function textbook_companion_fixer_permission() 'restrict access' => TRUE ), "fix scilab_code_caption" => array( - "title" => t("fix scilab code caption"), - 'restrict access' => TRUE - ) - + "title" => t("fix scilab code caption"), + 'restrict access' => TRUE + ), + "administer textbook companion fixer settings" => array( + "title" => t("administer textbook companion fixer settings"), + 'restrict access' => TRUE + ) ); } function scilab_fixer_caption_form($form, &$form_state) @@ -91,7 +109,7 @@ function scilab_fixer_caption_form($form, &$form_state) $form["wrapper"]["category"] = array( "#type" => "select", "#title" => t("Please select the category"), - '#options' => _tbc_fixer_list_of_category(), + '#options' => _tbc_fixer_list_of_category() ); $form["wrapper"]["book"] = array( "#type" => "select", @@ -111,9 +129,21 @@ function scilab_fixer_caption_form($form, &$form_state) "#prefix" => "
", "#suffix" => "
" ); + $form["wrapper"]["chapter_name"] = array( + "#type" => "textfield", + "#title" => t("Enter new chapter name"), + "#size" => 255, + "#maxlength" => 255, + "#attributes" => array( + "Style" => "width:100%" + ), + "#prefix" => "
", + "#suffix" => "
" + ); $form["wrapper"]["example"] = array( "#type" => "select", "#title" => t("Please select the example"), + "#description" => t("*Double click on example caption you want to edit"), "#options" => array( 0 => "Please select a example" ), @@ -123,9 +153,22 @@ function scilab_fixer_caption_form($form, &$form_state) $form["wrapper"]["caption"] = array( "#type" => "textfield", "#title" => t("Enter new caption"), + "#attributes" => array( + "Style" => "width:100%" + ), + "#size" => 255, + "#maxlength" => 255, "#prefix" => "
", "#suffix" => "
" ); + $form["wrapper"]["chapter_example"] = array( + "#markup" => " + Update Chapter caption
+ + Update Example caption", + "#prefix" => "
", + "#suffix" => "
" + ); $form["wrapper"]["submit"] = array( "#type" => "submit", "#value" => "Update", @@ -135,7 +178,9 @@ function scilab_fixer_caption_form($form, &$form_state) $form["wrapper"]["code_wrapper"] = array( "#type" => "fieldset", "#description" => t("No code to display"), - "#attributes" =>array("onclick" => "return check();"), + "#attributes" => array( + "onclick" => "return check();" + ), "#prefix" => "
",
 		"#suffix" => "
" ); @@ -156,8 +201,8 @@ function scilab_fixer_caption_all() function scilab_fixer_ajax($item, $key) { $data = ""; - if ($item == "category" && $key) - { + global $user; + 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 @@ -178,13 +223,11 @@ function scilab_fixer_ajax($item, $key) $query->orderBy('pre.book', 'ASC'); $result = $query->execute(); $data .= ""; - while ($row = $result->fetchObject()) - { + while ($row = $result->fetchObject()) { $data .= ""; } //$row = $result->fetchObject() } //$item == "category" && $key - else if ($item == "book" && $key) - { + else if ($item == "book" && $key) { /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; $result = db_query($query, $key);*/ $query = db_select('textbook_companion_chapter'); @@ -193,13 +236,11 @@ function scilab_fixer_ajax($item, $key) $query->orderBy('number', 'ASC'); $result = $query->execute(); $data .= ""; - while ($row = $result->fetchObject()) - { - $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; } //$row = $result->fetchObject() } //$item == "book" && $key - else if ($item == "chapter" && $key) - { + else if ($item == "chapter" && $key) { /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; $result = db_query($query, $key);*/ $query = db_select('textbook_companion_example'); @@ -208,13 +249,11 @@ function scilab_fixer_ajax($item, $key) $query->orderBy('number', 'ASC'); $result = $query->execute(); $data .= ""; - while ($row = $result->fetchObject()) - { - $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; } //$row = $result->fetchObject() } //$item == "chapter" && $key - else if ($item == "example" && $key) - { + 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 @@ -234,8 +273,7 @@ function scilab_fixer_ajax($item, $key) $data .= "
{$row->caption}
"; $data .= "
{$example}
"; } //$item == "example" && $key - else if ($item == "update") - { + else if ($item == "update-example") { $example_id = $_POST["example_id"]; $caption = $_POST["caption"]; /*$query = " @@ -251,9 +289,95 @@ function scilab_fixer_ajax($item, $key) $query->condition('id', $example_id); $result = $query->execute(); $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-example" + else if ($item == "update-chapter") { + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['chapter_updated']['chapter_id'] = $chapter_id; + $params['chapter_updated']['user_id'] = $user->uid; + $params['chapter_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('textbook_companion_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-chapter" + else if ($item == "update-both") { + $example_id = $_POST["example_id"]; + $caption = $_POST["caption"]; + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_exmaple = db_update('textbook_companion_example'); + $query_exmaple->fields(array( + 'caption' => $caption + )); + $query_exmaple->condition('id', $example_id); + $result_example = $query_exmaple->execute(); + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('textbook_companion_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE) } //$item == "update" - else if ($item == "code" && $key) - { + else if ($item == "code" && $key) { $code = $_POST["code"]; /*$query = " SELECT * FROM textbook_companion_example_files @@ -271,8 +395,7 @@ function scilab_fixer_ajax($item, $key) file_put_contents($example_path, $code); $data .= "updated"; } //$item == "code" && $key - else if ($item == "ind-ed" && $key) - { + else if ($item == "ind-ed" && $key) { $query = " UPDATE textbook_companion_aicte SET ind = !ind @@ -284,8 +407,7 @@ function scilab_fixer_ajax($item, $key) db_query($query, $args); $data .= "updated"; } //$item == "ind-ed" && $key - else - { + else { $data = ""; } echo $data; @@ -294,8 +416,7 @@ function scilab_fixer_ajax($item, $key) function scilab_fixer_aicte_ajax($item = "", $key = "") { $data = ""; - if ($item == "selected") - { + if ($item == "selected") { $query = " UPDATE textbook_companion_aicte SET selected = !selected @@ -378,24 +499,20 @@ function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') } function scilab_fixer_aicte_form_validate($form, &$form_state) { - if (!$form_state["values"]["category"]) - { + if (!$form_state["values"]["category"]) { form_set_error("category", "Please select a category."); } //!$form_state["values"]["category"] - if (!is_numeric($form_state["values"]["edition"])) - { + if (!is_numeric($form_state["values"]["edition"])) { form_set_error("edition", "Only digits are allowed."); } //!is_numeric($form_state["values"]["edition"]) - if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) - { + if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { form_set_error("year", "Please enter a valid year. eg: 2011."); } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 } function scilab_fixer_aicte_form_submit($form, &$form_state) { $v = $form_state["values"]; - if ($v["aicte_id"]) - { + if ($v["aicte_id"]) { /*$query = " UPDATE textbook_companion_aicte SET book = '%s', author = '%s', category = %d, @@ -421,8 +538,7 @@ function scilab_fixer_aicte_form_submit($form, &$form_state) $num_updated = $query->execute(); drupal_set_message("Book updated successfully", "status"); } //$v["aicte_id"] - else - { + else { $query = " INSERT INTO textbook_companion_aicte (book, author, category, isbn, publisher, edition, year) @@ -452,13 +568,11 @@ function scilab_fixer_aicte_all() function scilab_fixer_aicte_edit_all($aicte_id = 0) { $page_content = ""; - if ($aicte_id) - { + if ($aicte_id) { $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); $page_content .= drupal_render($scilab_fixer_aicte_form); } //$aicte_id - else - { + else { /*$query = " SELECT * FROM textbook_companion_aicte ORDER BY time DESC @@ -475,20 +589,17 @@ function scilab_fixer_aicte_edit_all($aicte_id = 0) "Action" ); $rows = array(); - while ($row = $result->fetchObject()) - { + while ($row = $result->fetchObject()) { $item = array( "{$row->book}", "{$row->author}", "{$row->edition}", l(t("Edit"), "fix/aicte/edit/{$row->id}") ); - if ($row->selected) - { + if ($row->selected) { $check = ""; } //$row->selected - else - { + else { $check = ""; } array_push($item, $check); @@ -518,8 +629,7 @@ function scilab_fixer_aicte_in_all() "Action" ); $rows = array(); - while ($row = $result->fetchObject()) - { + while ($row = $result->fetchObject()) { $item = array( "data" => array( "{$row->book}
by{$row->author}", @@ -536,16 +646,13 @@ function scilab_fixer_aicte_in_all() ) ); /* ind-ed link */ - if ($row->ind) - { + if ($row->ind) { array_push($item["data"], l("Unmark", "", $ind_options)); } //$row->ind - else - { + else { array_push($item["data"], l("Mark", "", $ind_options)); } - if ($row->ind) - { + if ($row->ind) { $item["class"] .= " orange"; } //$row->ind array_push($rows, $item); @@ -568,7 +675,7 @@ function scilab_fixer_code_form($form, &$form_state) $form["code_edit"]["category"] = array( "#type" => "select", "#title" => t("Please select the category"), - '#options' => _tbc_fixer_list_of_category(), + '#options' => _tbc_fixer_list_of_category() ); $form["code_edit"]["book"] = array( "#type" => "select", @@ -626,23 +733,20 @@ function scilab_fixer_code_all() function _tbc_fixer_list_of_category($category_id = NULL) { $category[0] = "Please select"; - if ($category_id == NULL) - { + if ($category_id == NULL) { $query = db_select('list_of_category'); $query->fields('list_of_category'); $query->orderBy('id', 'ASC'); $category_list = $query->execute(); } //$category_id == NULL - else - { + else { $query = db_select('list_of_category'); $query->fields('list_of_category'); $query->condition('category_id', $category_id); $query->orderBy('id', 'ASC'); $category_list = $query->execute(); } - while ($category_list_data = $category_list->fetchObject()) - { + while ($category_list_data = $category_list->fetchObject()) { $category[$category_list_data->category_id] = $category_list_data->category_name; } //$category_list_data = $category_list->fetchObject() return $category; diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc new file mode 100644 index 0000000..38df00b --- /dev/null +++ b/textbook_companion_fixer_email.inc @@ -0,0 +1,154 @@ +fields('textbook_companion_example'); + $query->condition('id', $params['chapter_example_updated']['example_id']); + $query->range(0, 1); + $result = $query->execute(); + $example_data = $result->fetchObject(); + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $example_data->chapter_id); + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['chapter_example_updated']['user_id']); + $message['headers'] = $params['chapter_example_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter, example caption for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' +Example number : ' . $example_data->number . ' +Caption : ' . $example_data->caption . ' + + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'chapter_updated': + + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $params['chapter_updated']['chapter_id']);; + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['chapter_updated']['user_id']); + $message['headers'] = $params['chapter_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter name for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'example_updated': + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('id', $params['example_updated']['example_id']); + $query->range(0, 1); + $result = $query->execute(); + $example_data = $result->fetchObject(); + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $example_data->chapter_id); + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['example_updated']['user_id']); + $message['headers'] = $params['example_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated example caption for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' +Example number : ' . $example_data->number . ' +Caption : ' . $example_data->caption . ' + + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + } //$key +} diff --git a/textbook_companion_fixer_settings.inc b/textbook_companion_fixer_settings.inc new file mode 100644 index 0000000..25af64c --- /dev/null +++ b/textbook_companion_fixer_settings.inc @@ -0,0 +1,58 @@ + 'textfield', + '#title' => t('(To) Notification emails'), + '#description' => t('A comma separated list of email addresses to receive notifications emails'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_fixer_to_emails', '') + ); + $form['bcc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(BCc) Notification emails'), + '#description' => t('Specify emails id for BCC option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_fixer_bcc_emails', '') + ); + $form['cc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(Cc) Notification emails'), + '#description' => t('Specify emails id for CC option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_fixer_cc_emails', '') + ); + $form['from_email'] = array( + '#type' => 'textfield', + '#title' => t('(From) Outgoing from email address'), + '#description' => t('Email address to be display in the from field of all outgoing messages'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_fixer_from_email', '') + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} +function textbook_companion_fixer_settings_form_validate($form, &$form_state) +{ + return; +} +function textbook_companion_fixer_settings_form_submit($form, &$form_state) +{ + variable_set('textbook_companion_fixer_to_emails', $form_state['values']['to_emails']); + variable_set('textbook_companion_fixer_bcc_emails', $form_state['values']['bcc_emails']); + variable_set('textbook_companion_fixer_cc_emails', $form_state['values']['cc_emails']); + variable_set('textbook_companion_fixer_from_email', $form_state['values']['from_email']); +} -- cgit From 2007de8e1386121d536ce6d7b3d0ad328826f326 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 24 Jan 2017 11:07:47 +0530 Subject: aaded new validation for captions --- js/textbook_companion_fixer.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js index d7b617e..b655b05 100755 --- a/js/textbook_companion_fixer.js +++ b/js/textbook_companion_fixer.js @@ -184,8 +184,18 @@ if (example_id != "0" && chapter_id != "0") { var caption = $caption.val(); caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text for example caption'); + return false; + } var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } if (caption == '' || chapter_caption =='') { alert('Please enter new caption '); return false; @@ -216,6 +226,11 @@ if (example_id != "0") { var caption = $caption.val(); caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text'); + return false; + } if (caption == '') { alert('Please enter new caption '); return false; @@ -242,7 +257,12 @@ } else if ($('.chapter-caption-chk').prop('checked') == true) { if (chapter_id != "0") { var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } if (chapter_caption == '') { alert('Please enter new caption '); return false; @@ -313,6 +333,10 @@ } }); }); + function validateCaption(text){ + var re = /([a-zA-Z|*|_|.|+|-|\\|?|/|!|~|!|@|#|$|%|^|&|(|)|<|>|{|}|;|:|\"|\'|,])\1{2,}/; + return re.test(text); + } /* toggle in edition */ $ind_ed = $(".ind-ed"); $ind_ed.click(function(e) { -- cgit From c46721c4d1be2c7d12ddd1727fc35dc758157232 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 24 Jan 2017 17:50:25 +0530 Subject: added page for edit category --- textbook_companion_fixer_edit_book_category.inc | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 textbook_companion_fixer_edit_book_category.inc diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc new file mode 100644 index 0000000..e14114d --- /dev/null +++ b/textbook_companion_fixer_edit_book_category.inc @@ -0,0 +1,52 @@ +0"); + $row = $result->fetchObject(); + $book_count = $row->book_count; + $i=1; + + /* get preference */ + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + while ($preference_data = $preference_q->fetchObject()) + { + $proposal_rows[] = array( + $i, + "{$preference_data->book}
by {$preference_data->author}", + _textbook_companion_fixer_list_of_category($preference_data->existing_category), + '', + '', + l('Edit', 'textbook_companion_fixer/category_edit' . $proposal_data->id) + ); + $i++; + } //$proposal_data = $proposal_q->fetchObject() + /* check if there are any pending proposals */ + if (!$proposal_rows) + { + drupal_set_message(t('There are no proposals.'), 'status'); + return ''; + } //!$proposal_rows + $output .= "Book count with category: " . $book_count; + $proposal_header = array( + 'No.', + 'Title of the Book', + 'Existing Category', + 'New Category', + 'Sub Category', + 'Action' + ); + $output .= theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; +} -- cgit From 5a104c26ade296722589f61b01ed45fd376b82d3 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Fri, 27 Jan 2017 16:12:56 +0530 Subject: added sub category --- textbook_companion_fixer.module | 94 +++++++++ textbook_companion_fixer_edit_book_category.inc | 246 +++++++++++++++++++++++- 2 files changed, 339 insertions(+), 1 deletion(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 1686c61..199b354 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -78,6 +78,29 @@ function textbook_companion_fixer_menu() 'type' => MENU_NORMAL_ITEM, 'file' => 'textbook_companion_fixer_settings.inc' ); + // edit book categoery + $items["textbook_companion_fixer/edit_book_category"] = array( + "title" => "Edit Completed Books Category", + "page callback" => "textbook_companion_fixer_edit_book_proposal_all", + "access arguments" => array( + "fix scilab_textbook_category" + ), + "type" => MENU_NORMAL_ITEM, + 'file' => 'textbook_companion_fixer_edit_book_category.inc' + ); + $items['textbook_companion_fixer/category_edit'] = array( + 'title' => 'Categorize', + 'description' => 'Edit Completed Books Category', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'textbook_companion_fixer_category_edit_form' + ), + 'access arguments' => array( + 'fix scilab_textbook_category' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'textbook_companion_fixer_edit_book_category.inc' + ); return $items; } function textbook_companion_fixer_permission() @@ -94,6 +117,10 @@ function textbook_companion_fixer_permission() "administer textbook companion fixer settings" => array( "title" => t("administer textbook companion fixer settings"), 'restrict access' => TRUE + ), + "fix scilab_textbook_category" => array( + "title" => t("fix scilab textbook category"), + 'restrict access' => TRUE ) ); } @@ -751,6 +778,73 @@ function _tbc_fixer_list_of_category($category_id = NULL) } //$category_list_data = $category_list->fetchObject() return $category; } +function _textbook_companion_fixer_list_of_category($category_id = NULL) +{ + if ($category_id == NULL ) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category_checkboxes() + + +{ + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + + + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname=$category_list_data->main_category; + if($categoryname!=null||strlen($categoryname)!=0){ + $category[$category_list_data->category_id] = $category_list_data->main_category; + } //$category_list_data = $category_list->fetchObject() +} + return $category; +} +function _textbook_companion_fixer_list_of_subcategory($category_id) +{ + + if ($category_id == NULL) + { + $query = db_select('list_of_subcategory'); + $query->fields('list_of_subcategory'); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_subcategory'); + $query->fields('list_of_subcategory'); + $query->condition('main_category', $category_id); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + } + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $category[$subcategory_list_data->id] = $subcategory_list_data->subcategory; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index e14114d..4cf42c9 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -25,7 +25,7 @@ function textbook_companion_fixer_edit_book_proposal_all() _textbook_companion_fixer_list_of_category($preference_data->existing_category), '', '', - l('Edit', 'textbook_companion_fixer/category_edit' . $proposal_data->id) + l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) ); $i++; } //$proposal_data = $proposal_q->fetchObject() @@ -50,3 +50,247 @@ function textbook_companion_fixer_edit_book_proposal_all() )); return $output; } +/* +function _edit_category_all(){ + // get pending proposals to be approved + $preference_rows = array(); + //$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY id DESC"); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('approval_status', 1); + $query->orderBy('id', 'DESC'); + $preference_q = $query->execute(); + while ($preference_data = $preference_q->fetchObject()) + { + switch ($preference_data->category) + { + case 0: + $category_data = 'Not Selected'; + break; + case 1: + $category_data = 'Fluid Mechanics'; + break; + case 2: + $category_data = 'Control Theory & Control Systems'; + break; + case 3: + $category_data = 'Chemical Engineering'; + break; + case 4: + $category_data = 'Thermodynamics'; + break; + case 5: + $category_data = 'Mechanical Engineering'; + break; + case 6: + $category_data = 'Signal Processing'; + break; + case 7: + $category_data = 'Digital Communications'; + break; + case 8: + $category_data = 'Electrical Technology'; + break; + case 9: + $category_data = 'Mathematics & Pure Science'; + break; + case 10: + $category_data = 'Analog Electronics'; + break; + case 11: + $category_data = 'Digital Electronics'; + break; + case 12: + $category_data = 'Computer Programming'; + break; + case 13: + $category_data = 'Others'; + break; + default: + $category_data = 'Unknown'; + break; + } //$preference_data->category + $preference_rows[] = array( + $preference_data->book . "
by " . $preference_data->author . "", + $preference_data->isbn, + $preference_data->publisher, + $preference_data->edition, + $preference_data->year, + $category_data, + l('Edit', 'manage_proposal/category/edit/' . $preference_data->id) + ); + } //$preference_data = $preference_q->fetchObject() + $preference_header = array( + 'Book', + 'ISBN', + 'Publisher', + 'Edition', + 'Year', + 'Category', + 'Status' + ); + $output = theme('table', array( + 'header' => $preference_header, + 'rows' => $preference_rows + )); + return $output; + +} +*/ +/******************************************************************************/ +/**************************** CATEGORY EDIT FORM ******************************/ +/******************************************************************************/ +function textbook_companion_fixer_category_edit_form($form, &$form_state) +{ + /* get current proposal */ + $preference_id = arg(2); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $preference_q = $query->execute(); + $preference_data = $preference_q->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); + drupal_goto('manage_proposal/category'); + return; + } //!$preference_data + $form['book'] = array( + '#type' => 'item', + '#title' => t('Title of the book'), + '#markup' => $preference_data->book + ); + $form['author'] = array( + '#type' => 'item', + '#title' => t('Author Name'), + '#markup' => $preference_data->author + ); + $form['isbn'] = array( + '#type' => 'item', + '#title' => t('ISBN No'), + '#markup' => $preference_data->isbn + ); + $form['publisher'] = array( + '#type' => 'item', + '#title' => t('Publisher & Place'), + '#markup' => $preference_data->publisher + ); + $form['edition'] = array( + '#type' => 'item', + '#title' => t('Edition'), + '#markup' => $preference_data->edition + ); + $form['year'] = array( + '#type' => 'item', + '#title' => t('Year of pulication'), + '#markup' => $preference_data->year + ); + + + //main_category = _textbook_companion_fixer_list_of_category_checkboxes(); + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + + + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname = $category_list_data->main_category; + if($categoryname!=null||strlen($categoryname)!=0){ + $category[$category_list_data->category_id] = $category_list_data->main_category; + + $form['main_category'.$category_list_data->category_id]= array( + '#type' => 'checkbox', + '#title' => $category_list_data->main_category, + '#ajax' => array( + 'wrapper' => 'ajax-subcategory-list-replace-'. $category_list_data->category_id, + 'callback' => 'ajax_subcategory_list_callback_'.$category_list_data->category_id + ), + ); + $form['main_subcategory_'. $category_list_data->category_id]= array( + '#type' => 'select', + '#options' => $category_list_data->main_category, + '#prefix' => '
', + '#suffix' => '
', + ); + + } //$category_list_data = $category_list->fetchObject() + } + + /* orm['main_category'] = array( + '#type' => 'checkboxes', + '#title' => t('Main category'), + '#options' => $main_category, + '#required' => TRUE + );*/ + + $form['category'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + '#default_value' => $preference_data->category + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') + ); + return $form; +} +function textbook_companion_fixer_category_edit_form_submit($form, &$form_state) +{ + // get current proposal + $preference_id = (int) arg(3); + //preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); + $preference_data = db_fetch_object($preference_q); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $preference_q = $query->execute(); + $preference_data = $preference_q->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); + drupal_goto('textbook_companion_fixer/edit_book_category'); + return; + } //!$preference_data + //db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id); + $query = db_update('textbook_companion_preference'); + $query->fields(array( + 'category' => $form_state['values']['category'] + )); + $query->condition('id', $preference_data->id); + $num_updated = $query->execute(); + drupal_set_message(t('Book Category Updated'), 'status'); + drupal_goto('textbook_companion_fixer/edit_book_category'); +} + + +/********************* Ajax callback ***************************/ +function ajax_subcategory_list_callback_1($form, $form_state) +{ + $category_default_value = 1; + if ($category_default_value > 0) + { + $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory($category_default_value); + $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); + + } //$category_default_value > 0 + else + { + $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory(); + $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); + + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +/*************************************************************************/ -- cgit From 40561078713460ec77b2e7fe260edf86d089e0fc Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 28 Jan 2017 21:38:46 +0530 Subject: added js for edit category --- js/textbook_companion_fixer_edit_category.js | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 js/textbook_companion_fixer_edit_category.js diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js new file mode 100644 index 0000000..9c2c4f7 --- /dev/null +++ b/js/textbook_companion_fixer_edit_category.js @@ -0,0 +1,84 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "textbook_companion_fixer/ajax/edit-book-category/"; + $category_form = $("#fix-tbc-category-form"); + $main_category1 = $(".main-category-1"); + $main_category2 = $(".main-category-2"); + $main_category3 = $(".main-category-3"); + $main_category4 = $(".main-category-4"); + $main_category5 = $(".main-category-5"); + $main_category6 = $(".main-category-6"); + $main_category7 = $(".main-category-7"); + $(".main-subcategory-1").hide(); + $(".main-subcategory-2").hide(); + $(".main-subcategory-3").hide(); + $(".main-subcategory-4").hide(); + $(".main-subcategory-5").hide(); + $(".main-subcategory-6").hide(); + $(".main-subcategory-7").hide(); + prop = $('.main-category-chk-1').prop('checked'); + console.log(prop); + $('.main-category-chk-1').change(function() { + if (!this.checked) { + $('.main-subcategory-1').hide(); + $('.main-subcategory-1').prop('selectedIndex', 0); + } else { + $('.main-subcategory-1').show(); + } + }); + $('.main-category-chk-2').change(function() { + if (!this.checked) { + $('.main-subcategory-2').hide(); + $('.main-subcategory-2').prop('selectedIndex', 0); + } else { + $('.main-subcategory-2').show(); + } + }); + $('.main-category-chk-3').change(function() { + if (!this.checked) { + $('.main-subcategory-3').hide(); + $('.main-subcategory-3').prop('selectedIndex', 0); + } else { + $('.main-subcategory-3').show(); + } + }); + $('.main-category-chk-4').change(function() { + if (!this.checked) { + $('.main-subcategory-4').hide(); + $('.main-subcategory-4').prop('selectedIndex', 0); + } else { + $('.main-subcategory-4').show(); + } + }); + $('.main-category-chk-5').change(function() { + if (!this.checked) { + $('.main-subcategory-5').hide(); + $('.main-subcategory-5').prop('selectedIndex', 0); + } else { + $('.main-subcategory-5').show(); + } + }); + $('.main-category-chk-6').change(function() { + if (!this.checked) { + $('.main-subcategory-6').hide(); + $('.main-subcategory-6').prop('selectedIndex', 0); + } else { + $('.main-subcategory-6').show(); + } + }); + $('.main-category-chk-7').change(function() { + if (!this.checked) { + $('.main-subcategory-7').hide(); + $('.main-subcategory-7').prop('selectedIndex', 0); + } else { + $('.main-subcategory-7').show(); + } + }); + //edit category form submit + $category_form.submit(function(e) { + e.preventDefault(); + }); + + }); +})(jQuery); -- cgit From 327a293e267170d2b53cf819352ea2837e936966 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 28 Jan 2017 21:39:43 +0530 Subject: added sub category hide show on checkbox action --- textbook_companion_fixer.module | 58 +++++--- textbook_companion_fixer_edit_book_category.inc | 190 +++--------------------- 2 files changed, 64 insertions(+), 184 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 199b354..b7a8c3e 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -64,6 +64,11 @@ function textbook_companion_fixer_menu() "access callback" => TRUE, "type" => MENU_CALLBACK ); + $items["textbook_companion_fixer/ajax/edit-book-category"] = array( + "page callback" => "textbook_companion_fixer_edit_book_category_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); /* for admin */ $items['admin/settings/textbook_companion_fixer_settings'] = array( 'title' => 'textbook companion fixer Settings', @@ -801,9 +806,32 @@ function _textbook_companion_fixer_list_of_category($category_id = NULL) } //$category_list_data = $category_list->fetchObject() return $category; } -function _textbook_companion_fixer_list_of_category_checkboxes() - +function textbook_companion_fixer_edit_book_category_ajax($item,$key){ + if ($item == "edit_book_category") { + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['category_updated']['pref_id'] = $pref_id; + $params['category_updated']['user_id'] = $user->uid; + $params['category_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'category_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } +} +function _textbook_companion_fixer_list_of_category_checkboxes() { $query = db_select('list_of_category'); $query->fields('list_of_category'); @@ -816,32 +844,25 @@ function _textbook_companion_fixer_list_of_category_checkboxes() { $categoryname=$category_list_data->main_category; if($categoryname!=null||strlen($categoryname)!=0){ - $category[$category_list_data->category_id] = $category_list_data->main_category; + //$category[$category_list_data->category_id] = $category_list_data->main_category; + + $category .= "".$category_list_data->main_category."
+


"; } //$category_list_data = $category_list->fetchObject() } return $category; } function _textbook_companion_fixer_list_of_subcategory($category_id) { - - if ($category_id == NULL) - { $query = db_select('list_of_subcategory'); $query->fields('list_of_subcategory'); - $query->orderBy('id', 'ASC'); - $subcategory_list = $query->execute(); - } //$category_id == NULL - else - { - $query = db_select('list_of_subcategory'); - $query->fields('list_of_subcategory'); - $query->condition('main_category', $category_id); - $query->orderBy('id', 'ASC'); - $subcategory_list = $query->execute(); - } + $query->condition('main_category', $category_id); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + $subcategory .= ""; while ($subcategory_list_data = $subcategory_list->fetchObject()) { - $category[$subcategory_list_data->id] = $subcategory_list_data->subcategory; + $subcategory .= ""; } //$category_list_data = $category_list->fetchObject() return $subcategory; } @@ -849,6 +870,7 @@ function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer.js"); + drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer_edit_category.js"); //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/selection.js"); } diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 4cf42c9..88311c5 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -50,93 +50,6 @@ function textbook_companion_fixer_edit_book_proposal_all() )); return $output; } -/* -function _edit_category_all(){ - // get pending proposals to be approved - $preference_rows = array(); - //$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY id DESC"); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('approval_status', 1); - $query->orderBy('id', 'DESC'); - $preference_q = $query->execute(); - while ($preference_data = $preference_q->fetchObject()) - { - switch ($preference_data->category) - { - case 0: - $category_data = 'Not Selected'; - break; - case 1: - $category_data = 'Fluid Mechanics'; - break; - case 2: - $category_data = 'Control Theory & Control Systems'; - break; - case 3: - $category_data = 'Chemical Engineering'; - break; - case 4: - $category_data = 'Thermodynamics'; - break; - case 5: - $category_data = 'Mechanical Engineering'; - break; - case 6: - $category_data = 'Signal Processing'; - break; - case 7: - $category_data = 'Digital Communications'; - break; - case 8: - $category_data = 'Electrical Technology'; - break; - case 9: - $category_data = 'Mathematics & Pure Science'; - break; - case 10: - $category_data = 'Analog Electronics'; - break; - case 11: - $category_data = 'Digital Electronics'; - break; - case 12: - $category_data = 'Computer Programming'; - break; - case 13: - $category_data = 'Others'; - break; - default: - $category_data = 'Unknown'; - break; - } //$preference_data->category - $preference_rows[] = array( - $preference_data->book . "
by " . $preference_data->author . "", - $preference_data->isbn, - $preference_data->publisher, - $preference_data->edition, - $preference_data->year, - $category_data, - l('Edit', 'manage_proposal/category/edit/' . $preference_data->id) - ); - } //$preference_data = $preference_q->fetchObject() - $preference_header = array( - 'Book', - 'ISBN', - 'Publisher', - 'Edition', - 'Year', - 'Category', - 'Status' - ); - $output = theme('table', array( - 'header' => $preference_header, - 'rows' => $preference_rows - )); - return $output; - -} -*/ /******************************************************************************/ /**************************** CATEGORY EDIT FORM ******************************/ /******************************************************************************/ @@ -155,122 +68,67 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) drupal_goto('manage_proposal/category'); return; } //!$preference_data - $form['book'] = array( + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Edit the existing book category to new category", + "#prefix" => "
", + "#suffix" => "
" + ); + $form["wrapper"]['book'] = array( '#type' => 'item', '#title' => t('Title of the book'), '#markup' => $preference_data->book ); - $form['author'] = array( + $form["wrapper"]['author'] = array( '#type' => 'item', '#title' => t('Author Name'), '#markup' => $preference_data->author ); - $form['isbn'] = array( + $form["wrapper"]['isbn'] = array( '#type' => 'item', '#title' => t('ISBN No'), '#markup' => $preference_data->isbn ); - $form['publisher'] = array( + $form["wrapper"]['publisher'] = array( '#type' => 'item', '#title' => t('Publisher & Place'), '#markup' => $preference_data->publisher ); - $form['edition'] = array( + $form["wrapper"]['edition'] = array( '#type' => 'item', '#title' => t('Edition'), '#markup' => $preference_data->edition ); - $form['year'] = array( + $form["wrapper"]['year'] = array( '#type' => 'item', '#title' => t('Year of pulication'), '#markup' => $preference_data->year ); - //main_category = _textbook_companion_fixer_list_of_category_checkboxes(); - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - //$query->fields(array('category_id','main_category')); - $query->orderBy('category_id', 'ASC'); - $category_list = $query->execute(); - - - while ($category_list_data = $category_list->fetchObject()) - { - $categoryname = $category_list_data->main_category; - if($categoryname!=null||strlen($categoryname)!=0){ - $category[$category_list_data->category_id] = $category_list_data->main_category; + $form["wrapper"]['main_category']= array( + "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), + ); - $form['main_category'.$category_list_data->category_id]= array( - '#type' => 'checkbox', - '#title' => $category_list_data->main_category, - '#ajax' => array( - 'wrapper' => 'ajax-subcategory-list-replace-'. $category_list_data->category_id, - 'callback' => 'ajax_subcategory_list_callback_'.$category_list_data->category_id + $form["wrapper"]['main_subcategory_'. $category_list_data->category_id] = array( + "#type" => "select", + "#title" => t("Please select the subcategory."), + "#options" => array( + 0 => "Please select a subcategory ".$category_list_data->category_id ), + "#prefix" => "
", + "#suffix" => "
" ); - $form['main_subcategory_'. $category_list_data->category_id]= array( - '#type' => 'select', - '#options' => $category_list_data->main_category, - '#prefix' => '
', - '#suffix' => '
', - ); - - } //$category_list_data = $category_list->fetchObject() - } - - /* orm['main_category'] = array( - '#type' => 'checkboxes', - '#title' => t('Main category'), - '#options' => $main_category, - '#required' => TRUE - );*/ - - $form['category'] = array( - '#type' => 'select', - '#title' => t('Category'), - '#options' => _tbc_list_of_category(), - '#required' => TRUE, - '#default_value' => $preference_data->category - ); - $form['submit'] = array( + $form["wrapper"]['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); - $form['cancel'] = array( + $form["wrapper"]['cancel'] = array( '#type' => 'markup', '#value' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') ); return $form; } -function textbook_companion_fixer_category_edit_form_submit($form, &$form_state) -{ - // get current proposal - $preference_id = (int) arg(3); - //preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); - $preference_data = db_fetch_object($preference_q); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $preference_id); - $preference_q = $query->execute(); - $preference_data = $preference_q->fetchObject(); - if (!$preference_data) - { - drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); - drupal_goto('textbook_companion_fixer/edit_book_category'); - return; - } //!$preference_data - //db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id); - $query = db_update('textbook_companion_preference'); - $query->fields(array( - 'category' => $form_state['values']['category'] - )); - $query->condition('id', $preference_data->id); - $num_updated = $query->execute(); - drupal_set_message(t('Book Category Updated'), 'status'); - drupal_goto('textbook_companion_fixer/edit_book_category'); -} - /********************* Ajax callback ***************************/ function ajax_subcategory_list_callback_1($form, $form_state) -- cgit From 8ffe399aa099cb67bed1611873cf655693f00521 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 31 Jan 2017 17:43:07 +0530 Subject: added submit function --- js/textbook_companion_fixer_edit_category.js | 33 +++++++++++----- textbook_companion_fixer.module | 23 +++++++++++- textbook_companion_fixer_edit_book_category.inc | 50 +++---------------------- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js index 9c2c4f7..2821382 100644 --- a/js/textbook_companion_fixer_edit_category.js +++ b/js/textbook_companion_fixer_edit_category.js @@ -1,15 +1,9 @@ (function($) { $(document).ready(function() { var basePath = Drupal.settings.basePath; + //var modPath = basePath + "textbook_companion_fixer/"; var modPath = basePath + "textbook_companion_fixer/ajax/edit-book-category/"; $category_form = $("#fix-tbc-category-form"); - $main_category1 = $(".main-category-1"); - $main_category2 = $(".main-category-2"); - $main_category3 = $(".main-category-3"); - $main_category4 = $(".main-category-4"); - $main_category5 = $(".main-category-5"); - $main_category6 = $(".main-category-6"); - $main_category7 = $(".main-category-7"); $(".main-subcategory-1").hide(); $(".main-subcategory-2").hide(); $(".main-subcategory-3").hide(); @@ -18,7 +12,6 @@ $(".main-subcategory-6").hide(); $(".main-subcategory-7").hide(); prop = $('.main-category-chk-1').prop('checked'); - console.log(prop); $('.main-category-chk-1').change(function() { if (!this.checked) { $('.main-subcategory-1').hide(); @@ -76,7 +69,29 @@ } }); //edit category form submit - $category_form.submit(function(e) { + $("#submit-button-category").click(function(e) { + var main_cat_chk_value = []; + $("input[name='ids[]']:checked").each(function (){ + main_cat_chk_value.push(parseInt($(this).val())); + }); + console.log(modPath); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + subcategory: "" + }, + dataType: "html", + success: function(data) { + $updating.hide(); + $done.show(); + console.log("data: +" + main_cat_chk_value); + $done.fadeOut("slow"); + //alert("ok"); + } + }); e.preventDefault(); }); diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index b7a8c3e..62350a7 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -808,8 +808,24 @@ function _textbook_companion_fixer_list_of_category($category_id = NULL) } function textbook_companion_fixer_edit_book_category_ajax($item,$key){ - if ($item == "edit_book_category") { + $data = ""; + $item = arg(2); + + if ($item == "edit-book-category") { $data .= "Updated"; + foreach($_POST['main_category'] as $main_category && $_POST['sub_category'] as $sub_category) { + $query = " + INSERT INTO textbook_companion_book_main_subcategories + (pref_id, main_category, sub_category) + VALUES + (:pref_id, :main_category, :subcategory) + "; + $args = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' =>$main_category, + ':subcategory' => $sub_category, + ); + $result = db_query($query, $args); /* sending email */ $email_to = $user->mail; $from = variable_get('textbook_companion_from_email', ''); @@ -829,7 +845,12 @@ function textbook_companion_fixer_edit_book_category_ajax($item,$key){ if (!drupal_mail('textbook_companion_fixer', 'category_updated', $email_to, language_default(), $params, $from, TRUE)) { $data .= 'Error sending email message.'; } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } + } + $data .= $main_cat; + echo $data; + exit(); } function _textbook_companion_fixer_list_of_category_checkboxes() { diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 88311c5..56429cc 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -1,9 +1,4 @@ t('Year of pulication'), '#markup' => $preference_data->year ); - - $form["wrapper"]['main_category']= array( - "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), - ); - - $form["wrapper"]['main_subcategory_'. $category_list_data->category_id] = array( - "#type" => "select", - "#title" => t("Please select the subcategory."), - "#options" => array( - 0 => "Please select a subcategory ".$category_list_data->category_id - ), - "#prefix" => "
", - "#suffix" => "
" + "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), ); $form["wrapper"]['submit'] = array( '#type' => 'submit', - '#value' => t('Submit') + '#value' => t('Submit'), + '#attributes' => array('id' => 'submit-button-category'), + "#prefix" => "
", + "#suffix" => "
" ); $form["wrapper"]['cancel'] = array( - '#type' => 'markup', - '#value' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') + '#markup' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') ); return $form; } - -/********************* Ajax callback ***************************/ -function ajax_subcategory_list_callback_1($form, $form_state) -{ - $category_default_value = 1; - if ($category_default_value > 0) - { - $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory($category_default_value); - $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); - - } //$category_default_value > 0 - else - { - $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory(); - $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); - - } - return array( - '#type' => 'ajax', - '#commands' => $commands - ); -} -/*************************************************************************/ -- cgit From 0f227125f2c6d996d1528048d00f3e9a23e08df0 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 2 Feb 2017 17:39:17 +0530 Subject: added some minor changes --- js/textbook_companion_fixer_edit_category.js | 14 +++++++++++--- textbook_companion_fixer_edit_book_category.inc | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js index 2821382..f10973b 100644 --- a/js/textbook_companion_fixer_edit_category.js +++ b/js/textbook_companion_fixer_edit_category.js @@ -74,20 +74,28 @@ $("input[name='ids[]']:checked").each(function (){ main_cat_chk_value.push(parseInt($(this).val())); }); - console.log(modPath); + var sub_cat_select_value = $.map($('select[name="subcats"] :selected'), function (val, _) { + var newObj = {}; + if(val.value > '0'){ + newObj.subcats = val.value; + } + return newObj; + }); + var pref_id = $('.prefrence_id').val(); + console.log(pref_id); $.ajax({ url: modPath, type: "POST", data: { pref_id: pref_id, main_category: main_cat_chk_value, - subcategory: "" + sub_category: sub_cat_select_value }, dataType: "html", success: function(data) { $updating.hide(); $done.show(); - console.log("data: +" + main_cat_chk_value); + console.log("data1: " + main_cat_chk_value + " data2: "+ sub_cat_select_value); $done.fadeOut("slow"); //alert("ok"); } diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 56429cc..d7b640b 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -98,6 +98,9 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) '#type' => 'item', '#title' => t('Year of pulication'), '#markup' => $preference_data->year + ); + $form["wrapper"]['pref_id'] = array( + '#markup' => '' ); $form["wrapper"]['main_category']= array( "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), -- cgit From a21a1be306598bc30845a6aa8ef4b52f4979ae82 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 8 May 2017 14:55:46 +0530 Subject: fixed numbering issue --- textbook_companion_fixer.module | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 62350a7..a844bda 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -296,6 +296,8 @@ function scilab_fixer_ajax($item, $key) $query->fields('fil'); $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $query->orderBy('number', 'ASC'); $result = $query->execute(); $row = $result->fetchObject(); /* fetching example file data */ @@ -626,7 +628,7 @@ function scilab_fixer_aicte_edit_all($aicte_id = 0) "{$row->book}", "{$row->author}", "{$row->edition}", - l(t("Edit"), "fix/aicte/edit/{$row->id}") + l(t("Edit"), "textbook_companion_fixer/aicte/edit/{$row->id}") ); if ($row->selected) { $check = ""; -- cgit From c8b0bd4ef8f3eb26d006fcd792ce628ac0b5f14b Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 8 May 2017 15:17:01 +0530 Subject: added new interface to edit the categories --- js/textbook_companion_fixer_edit_category.js | 206 +++++++++++------- textbook_companion_fixer.module | 127 +---------- textbook_companion_fixer_edit_book_category.inc | 272 +++++++++++++++++++++--- 3 files changed, 377 insertions(+), 228 deletions(-) diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js index f10973b..545f689 100644 --- a/js/textbook_companion_fixer_edit_category.js +++ b/js/textbook_companion_fixer_edit_category.js @@ -2,106 +2,156 @@ $(document).ready(function() { var basePath = Drupal.settings.basePath; //var modPath = basePath + "textbook_companion_fixer/"; - var modPath = basePath + "textbook_companion_fixer/ajax/edit-book-category/"; + var modPath = basePath + + "textbook_companion_fixer/ajax/edit-book-category/"; $category_form = $("#fix-tbc-category-form"); - $(".main-subcategory-1").hide(); - $(".main-subcategory-2").hide(); - $(".main-subcategory-3").hide(); - $(".main-subcategory-4").hide(); - $(".main-subcategory-5").hide(); - $(".main-subcategory-6").hide(); - $(".main-subcategory-7").hide(); - prop = $('.main-category-chk-1').prop('checked'); - $('.main-category-chk-1').change(function() { - if (!this.checked) { - $('.main-subcategory-1').hide(); - $('.main-subcategory-1').prop('selectedIndex', 0); - } else { - $('.main-subcategory-1').show(); - } - }); - $('.main-category-chk-2').change(function() { - if (!this.checked) { - $('.main-subcategory-2').hide(); - $('.main-subcategory-2').prop('selectedIndex', 0); - } else { - $('.main-subcategory-2').show(); - } - }); - $('.main-category-chk-3').change(function() { - if (!this.checked) { - $('.main-subcategory-3').hide(); - $('.main-subcategory-3').prop('selectedIndex', 0); - } else { - $('.main-subcategory-3').show(); - } - }); - $('.main-category-chk-4').change(function() { - if (!this.checked) { - $('.main-subcategory-4').hide(); - $('.main-subcategory-4').prop('selectedIndex', 0); - } else { - $('.main-subcategory-4').show(); - } - }); - $('.main-category-chk-5').change(function() { - if (!this.checked) { - $('.main-subcategory-5').hide(); - $('.main-subcategory-5').prop('selectedIndex', 0); - } else { - $('.main-subcategory-5').show(); - } - }); - $('.main-category-chk-6').change(function() { - if (!this.checked) { - $('.main-subcategory-6').hide(); - $('.main-subcategory-6').prop('selectedIndex', 0); + $(".main-subcategory-table-div").hide(); + + /*********************************************/ + //$('#main-subcategory-table-'+ 1).show(); + //var main_cat_chk_value = []; + $("input[name='ids[]']:checked").each(function() { + main_cat_chk_value = $(this).val(); + console.log('ooo' + main_cat_chk_value); + if (main_cat_chk_value) { + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); } else { - $('.main-subcategory-6').show(); + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); } }); - $('.main-category-chk-7').change(function() { - if (!this.checked) { - $('.main-subcategory-7').hide(); - $('.main-subcategory-7').prop('selectedIndex', 0); - } else { - $('.main-subcategory-7').show(); - } + + $('.main-category-checkbox').change(function() { + main_cat_chk_value = $(this).val(); + if (!this.checked) + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); + else + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); }); - //edit category form submit - $("#submit-button-category").click(function(e) { - var main_cat_chk_value = []; - $("input[name='ids[]']:checked").each(function (){ - main_cat_chk_value.push(parseInt($(this).val())); - }); - var sub_cat_select_value = $.map($('select[name="subcats"] :selected'), function (val, _) { - var newObj = {}; - if(val.value > '0'){ - newObj.subcats = val.value; - } - return newObj; + + $("#fix-tbc-category-form").on('click', '#btn-add', function() { + //$('#btn-add').click(function(){ + var selectID = $(this).attr("data-cid"); + console.log(selectID); + $('#subcats-' + selectID + ' option:selected').each(function() { + $('#selected-subcats-' + selectID).append(""); + + /**********************/ + console.log($('.main-subcategory-' + selectID).attr('data-cid')); + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + sub_category: sub_cat_select_value, + action: "add" + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log("data1: " + main_cat_chk_value + " data2: " + + sub_cat_select_value + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + /**********************/ + + $(this).remove(); }); - var pref_id = $('.prefrence_id').val(); - console.log(pref_id); + }); + $("#fix-tbc-category-form").on('click', '#btn-remove', function() { + //$('#btn-remove').click(function(){ + var selectID = $(this).attr("data-cid"); + $('#selected-subcats-' + selectID + ' option:selected').each(function() { + $('#subcats-' + selectID).append(""); + var action = "delete"; + /**********************/ + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); $.ajax({ url: modPath, type: "POST", data: { pref_id: pref_id, main_category: main_cat_chk_value, - sub_category: sub_cat_select_value + sub_category: sub_cat_select_value, + action: action }, dataType: "html", success: function(data) { + //alert("Updated"); + console.log("My data:" + data); $updating.hide(); $done.show(); - console.log("data1: " + main_cat_chk_value + " data2: "+ sub_cat_select_value); + console.log(action + "data1: " + main_cat_chk_value + + " data2: " + sub_cat_select_value + " data3: " + pref_id); $done.fadeOut("slow"); //alert("ok"); } }); - e.preventDefault(); + /**********************/ + $(this).remove(); + }); }); + //$("#main_cat_checkbox").change(function() { + $("#fix-tbc-category-form").on('change', '.main-category-checkbox', + function() { + var selectID = $(this).val(); + prop = $(this).prop('checked'); + if (prop) { + $('main-subcategory-table-' + selectID).show(); + } else { + if (confirm('Are you sure?')) { + alert('Thanks for confirming'); + var action = "delete-main-with-ub-category"; + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + //ConfirmFunction(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + action: action + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + location.reload(); + $('main-subcategory-table-' + selectID).hide(); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + } else { + alert('You have not confirmed the action'); + location.reload(); + } + } + }); + /**********************************************************************/ }); })(jQuery); + +function ConfirmFunction() { + confirm("Are you sure?"); +} diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index a844bda..d31eac8 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -67,7 +67,8 @@ function textbook_companion_fixer_menu() $items["textbook_companion_fixer/ajax/edit-book-category"] = array( "page callback" => "textbook_companion_fixer_edit_book_category_ajax", "access callback" => TRUE, - "type" => MENU_CALLBACK + "type" => MENU_CALLBACK, + "file" => "textbook_companion_fixer_edit_book_category.inc" ); /* for admin */ $items['admin/settings/textbook_companion_fixer_settings'] = array( @@ -764,131 +765,7 @@ function scilab_fixer_code_all() $page_content .= "
"; return $page_content; } -function _tbc_fixer_list_of_category($category_id = NULL) -{ - $category[0] = "Please select"; - if ($category_id == NULL) { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } //$category_id == NULL - else { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->condition('category_id', $category_id); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } - while ($category_list_data = $category_list->fetchObject()) { - $category[$category_list_data->category_id] = $category_list_data->category_name; - } //$category_list_data = $category_list->fetchObject() - return $category; -} -function _textbook_companion_fixer_list_of_category($category_id = NULL) -{ - if ($category_id == NULL ) - { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } //$category_id == NULL - else - { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->condition('category_id', $category_id); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } - while ($category_list_data = $category_list->fetchObject()) - { - $category = $category_list_data->category_name; - } //$category_list_data = $category_list->fetchObject() - return $category; -} - -function textbook_companion_fixer_edit_book_category_ajax($item,$key){ - $data = ""; - $item = arg(2); - - if ($item == "edit-book-category") { - $data .= "Updated"; - foreach($_POST['main_category'] as $main_category && $_POST['sub_category'] as $sub_category) { - $query = " - INSERT INTO textbook_companion_book_main_subcategories - (pref_id, main_category, sub_category) - VALUES - (:pref_id, :main_category, :subcategory) - "; - $args = array( - ':pref_id' => $_POST['pref_id'], - ':main_category' =>$main_category, - ':subcategory' => $sub_category, - ); - $result = db_query($query, $args); - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['category_updated']['pref_id'] = $pref_id; - $params['category_updated']['user_id'] = $user->uid; - $params['category_updated']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'category_updated', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) - } - - } - $data .= $main_cat; - echo $data; - exit(); -} -function _textbook_companion_fixer_list_of_category_checkboxes() -{ - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - //$query->fields(array('category_id','main_category')); - $query->orderBy('category_id', 'ASC'); - $category_list = $query->execute(); - - - while ($category_list_data = $category_list->fetchObject()) - { - $categoryname=$category_list_data->main_category; - if($categoryname!=null||strlen($categoryname)!=0){ - //$category[$category_list_data->category_id] = $category_list_data->main_category; - $category .= "".$category_list_data->main_category."
-


"; - } //$category_list_data = $category_list->fetchObject() -} - return $category; -} -function _textbook_companion_fixer_list_of_subcategory($category_id) -{ - $query = db_select('list_of_subcategory'); - $query->fields('list_of_subcategory'); - $query->condition('main_category', $category_id); - $query->orderBy('id', 'ASC'); - $subcategory_list = $query->execute(); - $subcategory .= ""; - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory .= ""; - } //$category_list_data = $category_list->fetchObject() - return $subcategory; -} function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index d7b640b..8efea2a 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -2,25 +2,22 @@ function textbook_companion_fixer_edit_book_proposal_all() { //get the book count - $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); - $row = $result->fetchObject(); - $book_count = $row->book_count; - $i=1; - - /* get preference */ - $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + $row = $result->fetchObject(); + $book_count = $row->book_count; + $i = 1; + /* get preference */ + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); - while ($preference_data = $preference_q->fetchObject()) + WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + while ($preference_data = $preference_q->fetchObject()) { $proposal_rows[] = array( $i, "{$preference_data->book}
by {$preference_data->author}", _textbook_companion_fixer_list_of_category($preference_data->existing_category), - '', - '', - l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) + _tbc_fixer_list_of_new_category($preference_data->pref_id), + l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) ); $i++; } //$proposal_data = $proposal_q->fetchObject() @@ -36,7 +33,6 @@ function textbook_companion_fixer_edit_book_proposal_all() 'Title of the Book', 'Existing Category', 'New Category', - 'Sub Category', 'Action' ); $output .= theme('table', array( @@ -100,20 +96,246 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) '#markup' => $preference_data->year ); $form["wrapper"]['pref_id'] = array( - '#markup' => '' + '#markup' => '' ); - $form["wrapper"]['main_category']= array( - "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), - ); - $form["wrapper"]['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - '#attributes' => array('id' => 'submit-button-category'), - "#prefix" => "
", - "#suffix" => "
" + $form["wrapper"]['main_category'] = array( + "#markup" => _textbook_companion_fixer_list_of_category_checkboxes() ); - $form["wrapper"]['cancel'] = array( - '#markup' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') + $form["wrapper"]['back'] = array( + '#markup' => l(t('Back'), 'textbook_companion_fixer/edit_book_category') ); return $form; } +function textbook_companion_fixer_edit_book_category_ajax($item, $key) +{ + $data = ""; + $item = arg(2); + if ($item == "edit-book-category") + { + if ($_POST['action'] == "add") + { + $main_category = $_POST['main_category']; + $sub_category = $_POST['sub_category']; + $query_in1 = " + INSERT INTO {textbook_companion_book_main_subcategories} + (pref_id, main_category, sub_category) + VALUES + (:pref_id, :main_category, :subcategory) + "; + $args_in1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $main_category, + ':subcategory' => $sub_category + ); + $result_in1 = db_query($query_in1, $args_in1); + } //$_POST['action'] == "add" + elseif ($_POST['action'] == "delete") + { + $query_del1 = "DELETE FROM textbook_companion_book_main_subcategories +WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory + "; + $args_del1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'], + ':subcategory' => $_POST['sub_category'] + ); + $result_del1 = db_query($query_del1, $args_del1); + } //$_POST['action'] == "delete" + elseif ($_POST['action'] == "delete-main-with-ub-category") + { + $query_del2 = "DELETE FROM textbook_companion_book_main_subcategories +WHERE pref_id= :pref_id AND main_category= :main_category + "; + $args_del2 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'] + ); + $result_del2 = db_query($query_del2, $args_del2); + } //$_POST['action'] == "delete-main-with-ub-category" + else + { + $data = "Not Updated"; + } + } //$item == "edit-book-category" + else + { + $data = "Not Updated"; + } + echo $data; + exit(); +} +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category($category_id) +{ + $category .= ""; + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('id', $category_id); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $category = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _tbc_fixer_list_of_new_category($pref_id) +{ + $category = ""; + $main_category_query = " + SELECT distinct(maincategory) + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id + "; + $args = array( + ':pref_id' => $pref_id + ); + $maincategory_list = db_query($main_category_query, $args); + $category .= "
    "; + while ($category_list_data = $maincategory_list->fetchObject()) + { + $category .= "
  1. $category_list_data->maincategory
  2. "; + $sub_category_query = " + SELECT DISTINCT (los.subcategory) + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue + "; + $sub_args = array( + ':pref_id' => $pref_id, + ':maincategoryvalue' => $category_list_data->maincategory + ); + $sub_category_list = db_query($sub_category_query, $sub_args); + while ($sub_category_list_data = $sub_category_list->fetchObject()) + { + $category .= "
    • $sub_category_list_data->subcategory
    "; + } //$sub_category_list_data = $sub_category_list->fetchObject() + } //$category_list_data = $maincategory_list->fetchObject() + $category .= "
"; + return $category; +} +function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) +{ + $category = ""; + $query = " + SELECT maincategory, los.subcategory as subcategory + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms + ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $category_list = db_query($query, $args); + while ($category_list_data = $category_list->fetchObject()) + { + $category .= $category_list_data->maincategory; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category_checkboxes() +{ + $pref_id = arg(2); + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname = $category_list_data->maincategory; + if ($categoryname != null || strlen($categoryname) != 0) + { + //$category[$category_list_data->category_id] = $category_list_data->main_category; + $existing_category = _tbc_fixer_list_of_ext_new_category($pref_id, $category_list_data->category_id); + $existing_subcategory = _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_list_data->category_id); + $checked = $existing_category ? 'checked="checked"' : ''; + $category .= "" . $category_list_data->maincategory . "
+
+ + + + + + + + +
Available sub categoriesSelected sub categories
+ Add » + « Remove + +
+
"; + } //$category_list_data = $category_list->fetchObject() + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_subcategory($pref_id, $category_id) +{ + $query = " + SELECT los.subcategory_id as subcat_id,los.subcategory as sub_category + FROM list_of_subcategory los WHERE los.maincategory_id= :category_id AND los.subcategory_id + NOT IN (SELECT los.subcategory_id as sub_id from list_of_subcategory los + LEFT OUTER JOIN textbook_companion_book_main_subcategories tcbms + ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id ORDER BY sub_id) + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$subcategory_list_data = $subcategory_list->fetchObject() + return $subcategory; +} +function _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_id) +{ + $subcategory = ""; + $query = " + SELECT DISTINCT (los.subcategory), maincategory, los.subcategory as subcategory, + los.subcategory_id as subcat_id FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} -- cgit From cd93bb9cfce5d1bb3ed2cf9d04ebcace6851cd70 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 11:48:17 +0530 Subject: fixed book count --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 8efea2a..9dc7bc3 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -9,7 +9,7 @@ function textbook_companion_fixer_edit_book_proposal_all() /* get preference */ $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0 ORDER BY pe.book ASC"); while ($preference_data = $preference_q->fetchObject()) { $proposal_rows[] = array( -- cgit From 4ef430950f632114d595680e8565b77099013a59 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 14:22:33 +0530 Subject: added email notifications for category changes --- textbook_companion_fixer_edit_book_category.inc | 67 ++++++++++- textbook_companion_fixer_email.inc | 141 +++++++++++++++++++++++- 2 files changed, 205 insertions(+), 3 deletions(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 9dc7bc3..531e07a 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -108,14 +108,15 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) } function textbook_companion_fixer_edit_book_category_ajax($item, $key) { + global $user; $data = ""; $item = arg(2); + $main_category = $_POST['main_category']; + $sub_category = $_POST['sub_category']; if ($item == "edit-book-category") { if ($_POST['action'] == "add") { - $main_category = $_POST['main_category']; - $sub_category = $_POST['sub_category']; $query_in1 = " INSERT INTO {textbook_companion_book_main_subcategories} (pref_id, main_category, sub_category) @@ -128,6 +129,27 @@ function textbook_companion_fixer_edit_book_category_ajax($item, $key) ':subcategory' => $sub_category ); $result_in1 = db_query($query_in1, $args_in1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['category_updated']['pref_id'] = $_POST['pref_id']; + $params['category_updated']['main_category'] = $main_category; + $params['category_updated']['sub_category'] = $sub_category; + $params['category_updated']['user_id'] = $user->uid; + $params['category_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_category_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "add" elseif ($_POST['action'] == "delete") { @@ -140,6 +162,27 @@ WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :su ':subcategory' => $_POST['sub_category'] ); $result_del1 = db_query($query_del1, $args_del1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['subcategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['subcategory_deleted']['main_category'] = $main_category; + $params['subcategory_deleted']['sub_category'] = $sub_category; + $params['subcategory_deleted']['user_id'] = $user->uid; + $params['subcategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_subcategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "delete" elseif ($_POST['action'] == "delete-main-with-ub-category") { @@ -151,6 +194,26 @@ WHERE pref_id= :pref_id AND main_category= :main_category ':main_category' => $_POST['main_category'] ); $result_del2 = db_query($query_del2, $args_del2); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['maincategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['maincategory_deleted']['main_category'] = $main_category; + $params['maincategory_deleted']['user_id'] = $user->uid; + $params['maincategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_maincategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "delete-main-with-ub-category" else { diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc index 38df00b..0e9117b 100644 --- a/textbook_companion_fixer_email.inc +++ b/textbook_companion_fixer_email.inc @@ -61,7 +61,6 @@ FOSSEE, IIT Bombay', array( ); break; case 'chapter_updated': - $query = db_select('textbook_companion_chapter'); $query->fields('textbook_companion_chapter'); $query->condition('id', $params['chapter_updated']['chapter_id']);; @@ -139,6 +138,146 @@ Example number : ' . $example_data->number . ' Caption : ' . $example_data->caption . ' +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_category_updated': + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['category_updated']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['category_updated']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['category_updated']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['category_updated']['user_id']); + $message['headers'] = $params['category_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have updated category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the category for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_subcategory_deleted': + query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['subcategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['subcategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['subcategory_deleted']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['subcategory_deleted']['user_id']); + $message['headers'] = $params['subcategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted subcategory for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_maincategory_deleted': + query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['maincategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['maincategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $user_data = user_load($params['maincategory_deleted']['user_id']); + $message['headers'] = $params['maincategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted main category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the main category with subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' + Best Wishes, Scilab TBC Team, -- cgit From 4214cfa2668bdf68f22b275f80f91c40ea3c5f15 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 14:24:35 +0530 Subject: fixed undefined variable issue --- textbook_companion_fixer_email.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc index 0e9117b..833e470 100644 --- a/textbook_companion_fixer_email.inc +++ b/textbook_companion_fixer_email.inc @@ -199,7 +199,7 @@ FOSSEE, IIT Bombay', array( ); break; case 'new_subcategory_deleted': - query = db_select('textbook_companion_preference'); + $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $params['subcategory_deleted']['pref_id']); $query->range(0, 1); @@ -248,7 +248,7 @@ FOSSEE, IIT Bombay', array( ); break; case 'new_maincategory_deleted': - query = db_select('textbook_companion_preference'); + $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $params['maincategory_deleted']['pref_id']); $query->range(0, 1); -- cgit From 02dc9ddc55fd8fa3c79714bc2ee37d2fcec6d186 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 11 May 2017 10:35:16 +0530 Subject: data fetched in order --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 531e07a..a4c421e 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -272,7 +272,7 @@ function _tbc_fixer_list_of_new_category($pref_id) FROM list_of_category loc LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id + WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id "; $args = array( ':pref_id' => $pref_id -- cgit From a227f785878fdbf6159b7a05c3ae45d055c46d39 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 22 May 2017 09:56:02 +0530 Subject: added missing function --- textbook_companion_fixer.module | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index d31eac8..e26f2ee 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -571,11 +571,11 @@ function scilab_fixer_aicte_form_submit($form, &$form_state) )); $query->condition('id', $v["aicte_id"]); $num_updated = $query->execute(); - drupal_set_message("Book updated successfully", "status"); + drupal_set_message(t('Book updated successfully'), 'status'); } //$v["aicte_id"] else { $query = " - INSERT INTO textbook_companion_aicte + INSERT INTO {textbook_companion_aicte} (book, author, category, isbn, publisher, edition, year) VALUES (:book, :author, :category, :isbn, :publisher, :edition, :year) @@ -590,7 +590,7 @@ function scilab_fixer_aicte_form_submit($form, &$form_state) ':year' => $v["year"] ); $result = db_query($query, $args); - drupal_set_message("Book added successfully", "status"); + drupal_set_message(t('Book added successfully'),'status'); } } function scilab_fixer_aicte_all() @@ -754,6 +754,30 @@ function scilab_fixer_code_form($form, &$form_state) ); return $form; } +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} function scilab_fixer_code_all() { $page_content = ""; -- cgit From 8b10fa6e0d8108adf26ff5016c7e74d2057e8f5f Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 22 May 2017 09:56:37 +0530 Subject: formated th code --- textbook_companion_fixer_edit_book_category.inc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index a4c421e..9c534a5 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -2,7 +2,7 @@ function textbook_companion_fixer_edit_book_proposal_all() { //get the book count - $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); + $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); $row = $result->fetchObject(); $book_count = $row->book_count; $i = 1; @@ -153,7 +153,7 @@ function textbook_companion_fixer_edit_book_category_ajax($item, $key) } //$_POST['action'] == "add" elseif ($_POST['action'] == "delete") { - $query_del1 = "DELETE FROM textbook_companion_book_main_subcategories + $query_del1 = "DELETE FROM {textbook_companion_book_main_subcategories} WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory "; $args_del1 = array( @@ -186,7 +186,7 @@ WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :su } //$_POST['action'] == "delete" elseif ($_POST['action'] == "delete-main-with-ub-category") { - $query_del2 = "DELETE FROM textbook_companion_book_main_subcategories + $query_del2 = "DELETE FROM {textbook_companion_book_main_subcategories} WHERE pref_id= :pref_id AND main_category= :main_category "; $args_del2 = array( @@ -269,9 +269,9 @@ function _tbc_fixer_list_of_new_category($pref_id) $category = ""; $main_category_query = " SELECT distinct(maincategory) - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id "; $args = array( @@ -284,9 +284,9 @@ function _tbc_fixer_list_of_new_category($pref_id) $category .= "
  • $category_list_data->maincategory
  • "; $sub_category_query = " SELECT DISTINCT (los.subcategory) - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue "; $sub_args = array( @@ -307,10 +307,10 @@ function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) $category = ""; $query = " SELECT maincategory, los.subcategory as subcategory - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id "; $args = array( -- cgit From a462834e913c3edd9bdad525a665af21bf831576 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 22 Aug 2017 12:20:35 +0530 Subject: fixed category issues --- textbook_companion_fixer.module | 25 +------------------------ textbook_companion_fixer_edit_book_category.inc | 3 ++- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index e26f2ee..bc8484c 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -1,5 +1,6 @@ fields('list_of_category'); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } //$category_id == NULL - else - { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->condition('category_id', $category_id); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } - while ($category_list_data = $category_list->fetchObject()) - { - $category[$category_list_data->category_id] = $category_list_data->category_name; - } //$category_list_data = $category_list->fetchObject() - return $category; -} function scilab_fixer_code_all() { $page_content = ""; diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 9c534a5..e54e009 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -368,7 +368,8 @@ function _textbook_companion_fixer_list_of_subcategory($pref_id, $category_id) FROM list_of_subcategory los WHERE los.maincategory_id= :category_id AND los.subcategory_id NOT IN (SELECT los.subcategory_id as sub_id from list_of_subcategory los LEFT OUTER JOIN textbook_companion_book_main_subcategories tcbms - ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id ORDER BY sub_id) + ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id and tcbms.main_category=:category_id + ORDER BY sub_id) "; $args = array( ':pref_id' => $pref_id, -- cgit From 2b157be8a005704e417895f7b06925bc4184ad1c Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 12 Jun 2018 16:19:11 +0530 Subject: fixed categoery id --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 textbook_companion_fixer_edit_book_category.inc diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc old mode 100644 new mode 100755 index e54e009..ed04c8e --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -241,7 +241,7 @@ function _tbc_fixer_list_of_category($category_id = NULL) { $query = db_select('list_of_category'); $query->fields('list_of_category'); - $query->condition('category_id', $category_id); + $query->condition('id', $category_id); $query->orderBy('id', 'ASC'); $category_list = $query->execute(); } -- cgit From 3a098517d28a3649bb1e3b46c56aa10e7199c557 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 10 Jul 2018 10:38:38 +0530 Subject: fixed tbc book category list display --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index ed04c8e..90156d0 100755 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -247,7 +247,7 @@ function _tbc_fixer_list_of_category($category_id = NULL) } while ($category_list_data = $category_list->fetchObject()) { - $category[$category_list_data->category_id] = $category_list_data->category_name; + $category[$category_list_data->id] = $category_list_data->category_name; } //$category_list_data = $category_list->fetchObject() return $category; } -- cgit From ab36969972e8f1f0c0078089bbbd2055028480c9 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 8 Jan 2019 10:32:27 +0530 Subject: fixed argument issue --- js/textbook_companion_fixer_edit_category.js | 1 - textbook_companion_fixer_edit_book_category.inc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js index 545f689..bad5ec7 100644 --- a/js/textbook_companion_fixer_edit_category.js +++ b/js/textbook_companion_fixer_edit_category.js @@ -37,7 +37,6 @@ .val() + "'>" + $(this).text() + ""); /**********************/ - console.log($('.main-subcategory-' + selectID).attr('data-cid')); var pref_id = $('.prefrence_id').val(); var main_cat_chk_value = selectID; var sub_cat_select_value = $(this).val(); diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 90156d0..1e5d01e 100755 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -106,7 +106,7 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) ); return $form; } -function textbook_companion_fixer_edit_book_category_ajax($item, $key) +function textbook_companion_fixer_edit_book_category_ajax() { global $user; $data = ""; -- cgit From 8d3bed544de846f7df096ab4e1a5c930522f7855 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 31 Aug 2019 13:02:09 +0530 Subject: updated readme --- README | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index 186df63..93afa19 100755 --- a/README +++ b/README @@ -1,2 +1,16 @@ -Textbook Companion Fixer for FOSSEE, IIT Bombay written in Drupal 7 +Module: R Textbook Companion Fixer +Site: https://r.fossee.in +Organization: FOSSEE, IIT Bomaby + +----------------------------------------------------------------- +Requirements: + +Drupal 7.x+ +PHP 7.2+ + +----------------------------------------------------------------- +Contributor: +Prashant Sinalkar, +FOSSEE, IIT Bombay. + -- cgit From 9079093f5ace76555b15e613ca9b8e473aa8461d Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 31 Aug 2019 15:31:32 +0530 Subject: updated the code for R TBC --- css/r_tbc_fixer.css | 47 ++ css/textbook_companion_fixer.css | 47 -- js/r_tbc_fixer.js | 330 ++++++++++ js/r_tbc_fixer_edit_category.js | 156 +++++ js/textbook_companion_fixer.js | 363 ----------- js/textbook_companion_fixer_edit_category.js | 156 ----- r_tbc.module | 778 ++++++++++++++++++++++++ r_tbc_fixer.info | 5 + r_tbc_fixer.module | 471 ++++++++++++++ r_tbc_fixer_edit_book_category.inc | 405 ++++++++++++ r_tbc_fixer_email.inc | 293 +++++++++ r_tbc_fixer_settings.inc | 58 ++ textbook_companion_fixer.info | 4 - textbook_companion_fixer.module | 777 ----------------------- textbook_companion_fixer_edit_book_category.inc | 405 ------------ textbook_companion_fixer_email.inc | 293 --------- textbook_companion_fixer_settings.inc | 58 -- 17 files changed, 2543 insertions(+), 2103 deletions(-) create mode 100755 css/r_tbc_fixer.css delete mode 100755 css/textbook_companion_fixer.css create mode 100755 js/r_tbc_fixer.js create mode 100755 js/r_tbc_fixer_edit_category.js delete mode 100755 js/textbook_companion_fixer.js delete mode 100644 js/textbook_companion_fixer_edit_category.js create mode 100644 r_tbc.module create mode 100755 r_tbc_fixer.info create mode 100755 r_tbc_fixer.module create mode 100755 r_tbc_fixer_edit_book_category.inc create mode 100755 r_tbc_fixer_email.inc create mode 100755 r_tbc_fixer_settings.inc delete mode 100755 textbook_companion_fixer.info delete mode 100755 textbook_companion_fixer.module delete mode 100755 textbook_companion_fixer_edit_book_category.inc delete mode 100644 textbook_companion_fixer_email.inc delete mode 100644 textbook_companion_fixer_settings.inc diff --git a/css/r_tbc_fixer.css b/css/r_tbc_fixer.css new file mode 100755 index 0000000..1a91bb0 --- /dev/null +++ b/css/r_tbc_fixer.css @@ -0,0 +1,47 @@ +#fix-tbc-form #edit-caption { + width: 99% !important; +} +#fix-tbc-form .well { + margin-top: 25px; + width: 620px; + overflow-x: auto; +} +/*#fix-tbc-form #edit-example { + height: 250px; +}*/ +#fix-tbc-page #updating, +#fix-tbc-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-tbc-page #updating { + background: #FF851B; +} +#fix-tbc-page #done { + background: #2ECC40; +} +textarea#edit-code { + height: 300px; + width: 650px; +} +.orange { + background: #FF9933 !important; +} +.sync-msg { + font-size: .8em; +} +.messages.success { + background: lightgreen; +} diff --git a/css/textbook_companion_fixer.css b/css/textbook_companion_fixer.css deleted file mode 100755 index 1a91bb0..0000000 --- a/css/textbook_companion_fixer.css +++ /dev/null @@ -1,47 +0,0 @@ -#fix-tbc-form #edit-caption { - width: 99% !important; -} -#fix-tbc-form .well { - margin-top: 25px; - width: 620px; - overflow-x: auto; -} -/*#fix-tbc-form #edit-example { - height: 250px; -}*/ -#fix-tbc-page #updating, -#fix-tbc-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-tbc-page #updating { - background: #FF851B; -} -#fix-tbc-page #done { - background: #2ECC40; -} -textarea#edit-code { - height: 300px; - width: 650px; -} -.orange { - background: #FF9933 !important; -} -.sync-msg { - font-size: .8em; -} -.messages.success { - background: lightgreen; -} diff --git a/js/r_tbc_fixer.js b/js/r_tbc_fixer.js new file mode 100755 index 0000000..dbb20d7 --- /dev/null +++ b/js/r_tbc_fixer.js @@ -0,0 +1,330 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "r_tbc_fixer/"; + var modPath1 = basePath + "textbook_companion_fixer/aicte/book/"; + $category = $("#fix-tbc-form #edit-category"); + $book = $("#fix-tbc-form #edit-book"); + $chapter = $("#fix-tbc-form #edit-chapter"); + $example = $("#fix-tbc-form #edit-example"); + $caption = $("#fix-tbc-form #edit-caption"); + $code = $("#fix-tbc-form #edit-code"); + $caption_form = $("#scilab-fixer-caption-form"); + $code_form = $("#scilab-fixer-code-form"); + $updating = $("#fix-tbc-page #updating"); + $done = $("#fix-tbc-page #done"); + $example.attr("multiple", "enabled"); + + function reset() { + for (var i = 0, l = arguments.length; i < l; i++) { + switch (arguments[i]) { + case "book": + $book.html(""); + break; + case "chapter": + $chapter.html(""); + break; + case "example": + $example.html(""); + break; + case "caption": + $caption.val(""); + break; + } + } + } + $(".select-book").hide(); + $(".select-chapter").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + $book.change(function() { + reset("chapter", "example", "caption"); + var book_id = $(this).val(); + if (book_id < 1) { + $(".select-chapter").hide(); + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-chapter").show(); + $(".select-example").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } + $.ajax({ + url: modPath + "ajax/book/" + book_id, + type: "POST", + dataType: "html", + success: function(data) { + $chapter.html(data); + } + }); + }); + $chapter.change(function() { + reset("example", "caption"); + var chapter_name = $('option:selected', this).attr("data-chaptername"); + var chapter_id = $(this).val(); + if (chapter_id < 1) { + $(".select-example").hide(); + $(".enter-caption").hide(); + $(".enter-chapter-name").hide(); + $(".chapter-example-chk").hide(); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".select-example").show(); + $(".enter-chapter-name").show(); + $(".chapter-example-chk").show(); + $("#edit-chapter-name").val(chapter_name); + $(".enter-caption").hide(); + $(".example-code-edit").hide(); + $(".update-button").show(); + } + $.ajax({ + url: modPath + "ajax/chapter/" + chapter_id, + type: "POST", + dataType: "html", + success: function(data) { + $example.html(data); + } + }); + }); + $example.change(function() { + reset("caption"); + var example_id = $(this).val(); + var example_name = $('option:selected', this).attr("data-exampleid"); + var example_caption = $(this).text(); + if (example_id < 1) { + $(".enter-caption").hide(); + // $("#edit-caption").val(""); + $(".example-code-edit").hide(); + $(".well").hide(); + $(".update-button").hide(); + } else { + $(".enter-caption").show(); + $("#edit-caption").val(example_name); + $(".example-code-edit").show(); + $(".well").show(); + $(".update-button").show(); + } + $.ajax({ + url: modPath + "ajax/example/" + example_id, + type: "POST", + dataType: "html", + success: function(data) { + var code = $(data).filter("#code").html(); + /* checking whether it is for .well or textarea */ + if ($code.hasClass("fix-caption-code")) { + $code.html(code); + } else { + $code.val(code); + } + var caption = $(data).filter("#caption").html(); + try { + $caption.val(caption); + } catch (e) { + return; + } + } + }); + }); + //edit caption form submit + $caption_form.submit(function(e) { + var example_id = $example.val(); + var chapter_id = $('option:selected', $chapter).attr("data-chapterid"); + if ($('.chapter-caption-chk').prop('checked') == true && $( + '.example-caption-chk').prop('checked') == true) { + if (example_id != "0" && chapter_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text for example caption'); + return false; + } + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } + if (caption == '' || chapter_caption =='') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-both/", + type: "POST", + data: { + example_id: example_id, + caption: caption, + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No entry is selected.") + } + } else if ($('.example-caption-chk').prop('checked') == true) { + if (example_id != "0") { + var caption = $caption.val(); + caption = caption.trim(); + caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(caption) == true) { + alert('Enter valid text'); + return false; + } + if (caption == '') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-example/", + 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.") + } + } else if ($('.chapter-caption-chk').prop('checked') == true) { + if (chapter_id != "0") { + var chapter_caption = $("#edit-chapter-name").val(); + chapter_caption = chapter_caption.trim(); + chapter_caption = caption.replace(/\s\s+/g, ' '); + if(validateCaption(chapter_caption) == true) { + alert('Enter valid text for chapter caption'); + return false; + } + if (chapter_caption == '') { + alert('Please enter new caption '); + return false; + } + $updating.show(); + $.ajax({ + url: modPath + "ajax/update-chapter/", + type: "POST", + data: { + chapter_id: chapter_id, + chapter_caption: chapter_caption + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $book.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + } + }); + } else { + alert("No example selected.") + } + } else { + alert("Please select the checkbox option") + } + e.preventDefault(); + }); + $code_form.submit(function(e) { + var example_id = $example.val(); + if (example_id != "0") { + var code = $code.val(); + code = code.trim(); + if (code == '') { + alert('Please enter new code'); + return false; + } + $.ajax({ + url: modPath + "ajax/code/" + example_id, + type: "POST", + data: { + code: code + }, + dataType: "html", + success: function(data) { + $chapter.trigger("change"); + $updating.hide(); + $done.show(); + $done.fadeOut("slow"); + $(".example-code-edit").show(); + } + }); + } else { + alert("No example selected.") + } + e.preventDefault(); + }); + $Selected = $(".selected"); + $Selected.click(function(e) { + $(".sync-msg").remove(); + $(this).after("Saving..."); + $.ajax({ + url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), + success: function() { + $(".sync-msg").remove(); + console.log("success"); + } + }); + }); + function validateCaption(text){ + var re = /([a-zA-Z|*|_|.|+|-|\\|?|/|!|~|!|@|#|$|%|^|&|(|)|<|>|{|}|;|:|\"|\'|,])\1{2,}/; + return re.test(text); + } + /* toggle in edition */ + $ind_ed = $(".ind-ed"); + $ind_ed.click(function(e) { + var aicte_id = $(this).attr("data-aicte"); + $t = $(this); + $.ajax({ + url: modPath + "ajax/ind-ed/" + aicte_id, + type: "GET", + dataType: "html", + success: function(data) { + $tr = $t.parents("tr:first"); + if ($tr.hasClass("orange")) { + $t.parents("tr:first").removeClass("orange"); + $t.html("Mark"); + } else { + $t.parents("tr:first").addClass("orange"); + $t.html("Unmark"); + } + }, + }); + e.preventDefault(); + }); + }); +})(jQuery); diff --git a/js/r_tbc_fixer_edit_category.js b/js/r_tbc_fixer_edit_category.js new file mode 100755 index 0000000..bad5ec7 --- /dev/null +++ b/js/r_tbc_fixer_edit_category.js @@ -0,0 +1,156 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + //var modPath = basePath + "textbook_companion_fixer/"; + var modPath = basePath + + "textbook_companion_fixer/ajax/edit-book-category/"; + $category_form = $("#fix-tbc-category-form"); + $(".main-subcategory-table-div").hide(); + + /*********************************************/ + //$('#main-subcategory-table-'+ 1).show(); + //var main_cat_chk_value = []; + $("input[name='ids[]']:checked").each(function() { + main_cat_chk_value = $(this).val(); + console.log('ooo' + main_cat_chk_value); + if (main_cat_chk_value) { + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); + } else { + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); + } + }); + + $('.main-category-checkbox').change(function() { + main_cat_chk_value = $(this).val(); + if (!this.checked) + $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); + else + $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); + }); + + $("#fix-tbc-category-form").on('click', '#btn-add', function() { + //$('#btn-add').click(function(){ + var selectID = $(this).attr("data-cid"); + console.log(selectID); + $('#subcats-' + selectID + ' option:selected').each(function() { + $('#selected-subcats-' + selectID).append(""); + + /**********************/ + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + sub_category: sub_cat_select_value, + action: "add" + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log("data1: " + main_cat_chk_value + " data2: " + + sub_cat_select_value + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + /**********************/ + + $(this).remove(); + }); + }); + $("#fix-tbc-category-form").on('click', '#btn-remove', function() { + //$('#btn-remove').click(function(){ + var selectID = $(this).attr("data-cid"); + $('#selected-subcats-' + selectID + ' option:selected').each(function() { + $('#subcats-' + selectID).append(""); + var action = "delete"; + /**********************/ + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + var sub_cat_select_value = $(this).val(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + sub_category: sub_cat_select_value, + action: action + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log(action + "data1: " + main_cat_chk_value + + " data2: " + sub_cat_select_value + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + /**********************/ + $(this).remove(); + }); + }); + + //$("#main_cat_checkbox").change(function() { + $("#fix-tbc-category-form").on('change', '.main-category-checkbox', + function() { + var selectID = $(this).val(); + prop = $(this).prop('checked'); + if (prop) { + $('main-subcategory-table-' + selectID).show(); + } else { + if (confirm('Are you sure?')) { + alert('Thanks for confirming'); + var action = "delete-main-with-ub-category"; + var pref_id = $('.prefrence_id').val(); + var main_cat_chk_value = selectID; + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + //ConfirmFunction(); + $.ajax({ + url: modPath, + type: "POST", + data: { + pref_id: pref_id, + main_category: main_cat_chk_value, + action: action + }, + dataType: "html", + success: function(data) { + //alert("Updated"); + location.reload(); + $('main-subcategory-table-' + selectID).hide(); + console.log("My data:" + data); + $updating.hide(); + $done.show(); + console.log(action + "data1: " + main_cat_chk_value + " data2: " + + action + " data3: " + pref_id); + $done.fadeOut("slow"); + //alert("ok"); + } + }); + } else { + alert('You have not confirmed the action'); + location.reload(); + } + } + }); + /**********************************************************************/ + }); +})(jQuery); + +function ConfirmFunction() { + confirm("Are you sure?"); +} diff --git a/js/textbook_companion_fixer.js b/js/textbook_companion_fixer.js deleted file mode 100755 index b655b05..0000000 --- a/js/textbook_companion_fixer.js +++ /dev/null @@ -1,363 +0,0 @@ -(function($) { - $(document).ready(function() { - var basePath = Drupal.settings.basePath; - var modPath = basePath + "textbook_companion_fixer/"; - var modPath1 = basePath + "textbook_companion_fixer/aicte/book/"; - $category = $("#fix-tbc-form #edit-category"); - $book = $("#fix-tbc-form #edit-book"); - $chapter = $("#fix-tbc-form #edit-chapter"); - $example = $("#fix-tbc-form #edit-example"); - $caption = $("#fix-tbc-form #edit-caption"); - $code = $("#fix-tbc-form #edit-code"); - $caption_form = $("#scilab-fixer-caption-form"); - $code_form = $("#scilab-fixer-code-form"); - $updating = $("#fix-tbc-page #updating"); - $done = $("#fix-tbc-page #done"); - $example.attr("multiple", "enabled"); - - function reset() { - for (var i = 0, l = arguments.length; i < l; i++) { - switch (arguments[i]) { - case "book": - $book.html(""); - break; - case "chapter": - $chapter.html(""); - break; - case "example": - $example.html(""); - break; - case "caption": - $caption.val(""); - break; - } - } - } - $(".select-book").hide(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - $category.change(function() { - reset("book", "chapter", "example", "caption"); - var category_id = $(this).val(); - if (category_id < 1) { - $(".select-book").hide(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - (".well").hide(); - $(".update-button").hide(); - } else { - $(".select-book").show(); - $(".select-chapter").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } - $.ajax({ - url: modPath + "ajax/category/" + category_id, - type: "POST", - dataType: "html", - success: function(data) { - $book.html(data); - } - }); - }); - $book.change(function() { - reset("chapter", "example", "caption"); - var book_id = $(this).val(); - if (book_id < 1) { - $(".select-chapter").hide(); - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".select-chapter").show(); - $(".select-example").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } - $.ajax({ - url: modPath + "ajax/book/" + book_id, - type: "POST", - dataType: "html", - success: function(data) { - $chapter.html(data); - } - }); - }); - $chapter.change(function() { - reset("example", "caption"); - var chapter_name = $('option:selected', this).attr("data-chaptername"); - var chapter_id = $(this).val(); - if (chapter_id < 1) { - $(".select-example").hide(); - $(".enter-caption").hide(); - $(".enter-chapter-name").hide(); - $(".chapter-example-chk").hide(); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".select-example").show(); - $(".enter-chapter-name").show(); - $(".chapter-example-chk").show(); - $("#edit-chapter-name").val(chapter_name); - $(".enter-caption").hide(); - $(".example-code-edit").hide(); - $(".update-button").show(); - } - $.ajax({ - url: modPath + "ajax/chapter/" + chapter_id, - type: "POST", - dataType: "html", - success: function(data) { - $example.html(data); - } - }); - }); - $example.change(function() { - reset("caption"); - var example_id = $(this).val(); - var example_name = $('option:selected', this).attr("data-exampleid"); - var example_caption = $(this).text(); - if (example_id < 1) { - $(".enter-caption").hide(); - // $("#edit-caption").val(""); - $(".example-code-edit").hide(); - $(".well").hide(); - $(".update-button").hide(); - } else { - $(".enter-caption").show(); - $("#edit-caption").val(example_name); - $(".example-code-edit").show(); - $(".well").show(); - $(".update-button").show(); - } - $.ajax({ - url: modPath + "ajax/example/" + example_id, - type: "POST", - dataType: "html", - success: function(data) { - var code = $(data).filter("#code").html(); - /* checking whether it is for .well or textarea */ - if ($code.hasClass("fix-caption-code")) { - $code.html(code); - } else { - $code.val(code); - } - var caption = $(data).filter("#caption").html(); - try { - $caption.val(caption); - } catch (e) { - return; - } - } - }); - }); - //edit caption form submit - $caption_form.submit(function(e) { - var example_id = $example.val(); - var chapter_id = $('option:selected', $chapter).attr("data-chapterid"); - if ($('.chapter-caption-chk').prop('checked') == true && $( - '.example-caption-chk').prop('checked') == true) { - if (example_id != "0" && chapter_id != "0") { - var caption = $caption.val(); - caption = caption.trim(); - caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(caption) == true) { - alert('Enter valid text for example caption'); - return false; - } - var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); - chapter_caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(chapter_caption) == true) { - alert('Enter valid text for chapter caption'); - return false; - } - if (caption == '' || chapter_caption =='') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-both/", - type: "POST", - data: { - example_id: example_id, - caption: caption, - chapter_id: chapter_id, - chapter_caption: chapter_caption - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $book.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No entry is selected.") - } - } else if ($('.example-caption-chk').prop('checked') == true) { - if (example_id != "0") { - var caption = $caption.val(); - caption = caption.trim(); - caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(caption) == true) { - alert('Enter valid text'); - return false; - } - if (caption == '') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-example/", - 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.") - } - } else if ($('.chapter-caption-chk').prop('checked') == true) { - if (chapter_id != "0") { - var chapter_caption = $("#edit-chapter-name").val(); - chapter_caption = chapter_caption.trim(); - chapter_caption = caption.replace(/\s\s+/g, ' '); - if(validateCaption(chapter_caption) == true) { - alert('Enter valid text for chapter caption'); - return false; - } - if (chapter_caption == '') { - alert('Please enter new caption '); - return false; - } - $updating.show(); - $.ajax({ - url: modPath + "ajax/update-chapter/", - type: "POST", - data: { - chapter_id: chapter_id, - chapter_caption: chapter_caption - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $book.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - } - }); - } else { - alert("No example selected.") - } - } else { - alert("Please select the checkbox option") - } - e.preventDefault(); - }); - $code_form.submit(function(e) { - var example_id = $example.val(); - if (example_id != "0") { - var code = $code.val(); - code = code.trim(); - if (code == '') { - alert('Please enter new code'); - return false; - } - $.ajax({ - url: modPath + "ajax/code/" + example_id, - type: "POST", - data: { - code: code - }, - dataType: "html", - success: function(data) { - $chapter.trigger("change"); - $updating.hide(); - $done.show(); - $done.fadeOut("slow"); - $(".example-code-edit").show(); - } - }); - } else { - alert("No example selected.") - } - e.preventDefault(); - }); - $Selected = $(".selected"); - $Selected.click(function(e) { - $(".sync-msg").remove(); - $(this).after("Saving..."); - $.ajax({ - url: modPath1 + "ajax/selected/" + $(this).attr("data-bid"), - success: function() { - $(".sync-msg").remove(); - console.log("success"); - } - }); - }); - function validateCaption(text){ - var re = /([a-zA-Z|*|_|.|+|-|\\|?|/|!|~|!|@|#|$|%|^|&|(|)|<|>|{|}|;|:|\"|\'|,])\1{2,}/; - return re.test(text); - } - /* toggle in edition */ - $ind_ed = $(".ind-ed"); - $ind_ed.click(function(e) { - var aicte_id = $(this).attr("data-aicte"); - $t = $(this); - $.ajax({ - url: modPath + "ajax/ind-ed/" + aicte_id, - type: "GET", - dataType: "html", - success: function(data) { - $tr = $t.parents("tr:first"); - if ($tr.hasClass("orange")) { - $t.parents("tr:first").removeClass("orange"); - $t.html("Mark"); - } else { - $t.parents("tr:first").addClass("orange"); - $t.html("Unmark"); - } - }, - }); - e.preventDefault(); - }); - }); -})(jQuery); diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js deleted file mode 100644 index bad5ec7..0000000 --- a/js/textbook_companion_fixer_edit_category.js +++ /dev/null @@ -1,156 +0,0 @@ -(function($) { - $(document).ready(function() { - var basePath = Drupal.settings.basePath; - //var modPath = basePath + "textbook_companion_fixer/"; - var modPath = basePath + - "textbook_companion_fixer/ajax/edit-book-category/"; - $category_form = $("#fix-tbc-category-form"); - $(".main-subcategory-table-div").hide(); - - /*********************************************/ - //$('#main-subcategory-table-'+ 1).show(); - //var main_cat_chk_value = []; - $("input[name='ids[]']:checked").each(function() { - main_cat_chk_value = $(this).val(); - console.log('ooo' + main_cat_chk_value); - if (main_cat_chk_value) { - $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); - } else { - $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); - } - }); - - $('.main-category-checkbox').change(function() { - main_cat_chk_value = $(this).val(); - if (!this.checked) - $('#main-subcategory-table-div-id-' + main_cat_chk_value).hide(); - else - $('#main-subcategory-table-div-id-' + main_cat_chk_value).show(); - }); - - $("#fix-tbc-category-form").on('click', '#btn-add', function() { - //$('#btn-add').click(function(){ - var selectID = $(this).attr("data-cid"); - console.log(selectID); - $('#subcats-' + selectID + ' option:selected').each(function() { - $('#selected-subcats-' + selectID).append(""); - - /**********************/ - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - var sub_cat_select_value = $(this).val(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - sub_category: sub_cat_select_value, - action: "add" - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log("data1: " + main_cat_chk_value + " data2: " + - sub_cat_select_value + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - /**********************/ - - $(this).remove(); - }); - }); - $("#fix-tbc-category-form").on('click', '#btn-remove', function() { - //$('#btn-remove').click(function(){ - var selectID = $(this).attr("data-cid"); - $('#selected-subcats-' + selectID + ' option:selected').each(function() { - $('#subcats-' + selectID).append(""); - var action = "delete"; - /**********************/ - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - var sub_cat_select_value = $(this).val(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - sub_category: sub_cat_select_value, - action: action - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log(action + "data1: " + main_cat_chk_value + - " data2: " + sub_cat_select_value + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - /**********************/ - $(this).remove(); - }); - }); - - //$("#main_cat_checkbox").change(function() { - $("#fix-tbc-category-form").on('change', '.main-category-checkbox', - function() { - var selectID = $(this).val(); - prop = $(this).prop('checked'); - if (prop) { - $('main-subcategory-table-' + selectID).show(); - } else { - if (confirm('Are you sure?')) { - alert('Thanks for confirming'); - var action = "delete-main-with-ub-category"; - var pref_id = $('.prefrence_id').val(); - var main_cat_chk_value = selectID; - console.log(action + "data1: " + main_cat_chk_value + " data2: " + - action + " data3: " + pref_id); - //ConfirmFunction(); - $.ajax({ - url: modPath, - type: "POST", - data: { - pref_id: pref_id, - main_category: main_cat_chk_value, - action: action - }, - dataType: "html", - success: function(data) { - //alert("Updated"); - location.reload(); - $('main-subcategory-table-' + selectID).hide(); - console.log("My data:" + data); - $updating.hide(); - $done.show(); - console.log(action + "data1: " + main_cat_chk_value + " data2: " + - action + " data3: " + pref_id); - $done.fadeOut("slow"); - //alert("ok"); - } - }); - } else { - alert('You have not confirmed the action'); - location.reload(); - } - } - }); - /**********************************************************************/ - }); -})(jQuery); - -function ConfirmFunction() { - confirm("Are you sure?"); -} diff --git a/r_tbc.module b/r_tbc.module new file mode 100644 index 0000000..3a601d6 --- /dev/null +++ b/r_tbc.module @@ -0,0 +1,778 @@ + "Edit TBC captions", + "page callback" => "R_fixer_caption_all", + "access arguments" => array( + "fix R_code_caption" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["r_tbc_fixer/aicte"] = array( + "title" => "Add AICTE books", + "page callback" => "R_fixer_aicte_all", + "access arguments" => array( + "fix R" + ), + "weight" => 30, + "type" => MENU_NORMAL_ITEM + ); + $items["r_tbc_fixer/aicte/new"] = array( + "title" => "Add AICTE books", + "page callback" => "R_fixer_aicte_all", + "access arguments" => array( + "fix R" + ), + "weight" => 1, + "type" => MENU_DEFAULT_LOCAL_TASK + ); + $items["r_tbc_fixer/aicte/edit"] = array( + "title" => "Edit AICTE books", + "page callback" => "R_fixer_aicte_edit_all", + "access arguments" => array( + "fix R" + ), + "weight" => 2, + "type" => MENU_LOCAL_TASK + ); + $items["r_tbc_fixer/aicte/in"] = array( + "title" => "Mark Indian edition books", + "page callback" => "R_fixer_aicte_in_all", + "access arguments" => array( + "fix R" + ), + "type" => MENU_CALLBACK + ); + $items["r_tbc_fixer/code"] = array( + "title" => "Edit TBC code", + "page callback" => "R_fixer_code_all", + "access arguments" => array( + "fix R" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["r_tbc_fixer/ajax"] = array( + "page callback" => "R_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["r_tbc_fixer/aicte/book/ajax"] = array( + "page callback" => "R_fixer_aicte_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["r_tbc_fixer/ajax/edit-book-category"] = array( + "page callback" => "r_tbc_fixer_edit_book_category_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK, + "file" => "r_tbc_fixer_edit_book_category.inc" + ); + /* for admin */ + $items['admin/settings/r_tbc_fixer_settings'] = array( + 'title' => 'textbook companion fixer Settings', + 'description' => 'Textbook Companion Fixer Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'r_tbc_fixer_settings_form' + ), + 'access arguments' => array( + 'administer textbook companion fixer settings' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_settings.inc' + ); + // edit book categoery + $items["r_tbc_fixer/edit_book_category"] = array( + "title" => "Edit Completed Books Category", + "page callback" => "r_tbc_fixer_edit_book_proposal_all", + "access arguments" => array( + "fix R_textbook_category" + ), + "type" => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_edit_book_category.inc' + ); + $items['r_tbc_fixer/category_edit'] = array( + 'title' => 'Categorize', + 'description' => 'Edit Completed Books Category', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'r_tbc_fixer_category_edit_form' + ), + 'access arguments' => array( + 'fix R_textbook_category' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_edit_book_category.inc' + ); + return $items; +} +function r_tbc_fixer_permission() +{ + return array( + "fix R" => array( + "title" => t("fix R code"), + 'restrict access' => TRUE + ), + "fix R_code_caption" => array( + "title" => t("fix R code caption"), + 'restrict access' => TRUE + ), + "administer textbook companion fixer settings" => array( + "title" => t("administer textbook companion fixer settings"), + 'restrict access' => TRUE + ), + "fix R_textbook_category" => array( + "title" => t("fix R textbook category"), + 'restrict access' => TRUE + ) + ); +} +function R_fixer_caption_form($form, &$form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Caption change form", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["category"] = array( + "#type" => "select", + "#title" => t("Please select the category"), + '#options' => _tbc_fixer_list_of_category() + ); + $form["wrapper"]["book"] = array( + "#type" => "select", + "#title" => t("Please select the book."), + "#options" => array( + 0 => "Please select a book" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["chapter"] = array( + "#type" => "select", + "#title" => t("Please select the chapter"), + "#options" => array( + 0 => "Please select a chapter" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["chapter_name"] = array( + "#type" => "textfield", + "#title" => t("Enter new chapter name"), + "#size" => 255, + "#maxlength" => 255, + "#attributes" => array( + "Style" => "width:100%" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["example"] = array( + "#type" => "select", + "#title" => t("Please select the example"), + "#description" => t("*Double click on example caption you want to edit"), + "#options" => array( + 0 => "Please select a example" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["caption"] = array( + "#type" => "textfield", + "#title" => t("Enter new caption"), + "#attributes" => array( + "Style" => "width:100%" + ), + "#size" => 255, + "#maxlength" => 255, + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["chapter_example"] = array( + "#markup" => " + Update Chapter caption
    + + Update Example caption", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["code_wrapper"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#attributes" => array( + "onclick" => "return check();" + ), + "#prefix" => "
    ",
    +		"#suffix" => "
    " + ); + return $form; +} +function R_fixer_caption_all() +{ + $page_content = ""; + $page_content .= "
    "; + $page_content .= "
    Updating...
    "; + $page_content .= "Done."; + $R_fixer_caption_form = drupal_get_form("R_fixer_caption_form"); + $page_content .= drupal_render($R_fixer_caption_form); + $page_content .= "
    "; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; + return $page_content; +} + +function R_fixer_ajax($item, $key) +{ + $data = ""; + global $user; + 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);*/ + $query = db_select('textbook_companion_preference', 'pre'); + $query->fields('pre', array( + 'id', + 'book', + 'author' + )); + $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); + $query->condition('pro.proposal_status', 3); + $query->condition('pre.approval_status', 1); + $query->condition('pre.category', $key); + $query->orderBy('pre.book', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "category" && $key + else if ($item == "book" && $key) { + /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('preference_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "book" && $key + else if ($item == "chapter" && $key) { + /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "chapter" && $key + 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);*/ + $query = db_select('textbook_companion_example_files', 'fil'); + $query->fields('fil'); + $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); + $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $row = $result->fetchObject(); + /* 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 .= "
    {$row->caption}
    "; + $data .= "
    {$example}
    "; + } //$item == "example" && $key + else if ($item == "update-example") { + $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);*/ + $query = db_update('textbook_companion_example'); + $query->fields(array( + 'caption' => $caption + )); + $query->condition('id', $example_id); + $result = $query->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-example" + else if ($item == "update-chapter") { + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['chapter_updated']['chapter_id'] = $chapter_id; + $params['chapter_updated']['user_id'] = $user->uid; + $params['chapter_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-chapter" + else if ($item == "update-both") { + $example_id = $_POST["example_id"]; + $caption = $_POST["caption"]; + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_exmaple = db_update('textbook_companion_example'); + $query_exmaple->fields(array( + 'caption' => $caption + )); + $query_exmaple->condition('id', $example_id); + $result_example = $query_exmaple->execute(); + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update" + else if ($item == "code" && $key) { + $code = $_POST["code"]; + /*$query = " + SELECT * FROM textbook_companion_example_files + WHERE example_id = %d AND filetype = 'S' + "; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example_files'); + $query->fields('textbook_companion_example_files'); + $query->condition('example_id', $key); + $query->condition('filetype', 'S'); + $result = $query->execute(); + $row = $result->fetchObject(); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; + $example_path = $uploads_dir . $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; + } //$item == "code" && $key + else if ($item == "ind-ed" && $key) { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data .= "updated"; + } //$item == "ind-ed" && $key + else { + $data = ""; + } + echo $data; + exit(); +} +function R_fixer_aicte_ajax($item = "", $key = "") +{ + $data = ""; + if ($item == "selected") { + $query = " + UPDATE textbook_companion_aicte + SET selected = !selected + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data = "updated"; + } //$item == "selected" + echo $data; + exit(); +} +function R_fixer_aicte_form($form, $form_state, $aicte_id = '') +{ + /*$query = " + SELECT * FROM textbook_companion_aicte + WHERE id = {$aicte_id} + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->condition('id', $aicte_id); + $result = $query->execute(); + $row = $result->fetchObject(); + $form = array(); + $form["book"] = array( + "#type" => "textfield", + "#title" => "Book Name", + "#default_value" => $row->book, + "#required" => TRUE + ); + $form["author"] = array( + "#type" => "textfield", + "#title" => "Author", + "#default_value" => $row->author, + "#required" => TRUE + ); + $form["category"] = array( + "#type" => "select", + "#title" => "Book Category", + '#options' => _tbc_fixer_list_of_category(), + "#default_value" => $row->category, + "#required" => TRUE + ); + $form["isbn"] = array( + "#type" => "textfield", + "#title" => "ISBN", + "#default_value" => $row->isbn, + "#required" => FALSE + ); + $form["publisher"] = array( + "#type" => "textfield", + "#title" => "Publisher", + "#default_value" => $row->publisher, + "#required" => TRUE + ); + $form["edition"] = array( + "#type" => "textfield", + "#title" => "Edition", + "#default_value" => $row->edition, + "#required" => TRUE + ); + $form["year"] = array( + "#type" => "textfield", + "#title" => "Year of publication", + "#default_value" => $row->year, + "#required" => TRUE + ); + $form["aicte_id"] = array( + "#type" => "hidden", + "#value" => $row->id + ); + $form["submit"] = array( + "#type" => "submit", + "#value" => "Submit" + ); + return $form; +} +function R_fixer_aicte_form_validate($form, &$form_state) +{ + if (!$form_state["values"]["category"]) { + form_set_error("category", "Please select a category."); + } //!$form_state["values"]["category"] + if (!is_numeric($form_state["values"]["edition"])) { + form_set_error("edition", "Only digits are allowed."); + } //!is_numeric($form_state["values"]["edition"]) + if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { + form_set_error("year", "Please enter a valid year. eg: 2011."); + } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 +} +function R_fixer_aicte_form_submit($form, &$form_state) +{ + $v = $form_state["values"]; + if ($v["aicte_id"]) { + /*$query = " + UPDATE textbook_companion_aicte + SET book = '%s', author = '%s', category = %d, + isbn = '%s', publisher = '%s', edition = %d, + year = %d + WHERE id = %d + "; + $result = db_query($query, + $v["book"], $v["author"], $v["category"], $v["isbn"], + $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] + );*/ + $query = db_update('textbook_companion_aicte'); + $query->fields(array( + 'book' => $v["book"], + 'author' => $v["author"], + 'category' => $v["category"], + 'isbn' => $v["isbn"], + 'publisher' => $v["publisher"], + 'edition' => $v["edition"], + 'year' => $v["year"] + )); + $query->condition('id', $v["aicte_id"]); + $num_updated = $query->execute(); + drupal_set_message(t('Book updated successfully'), 'status'); + } //$v["aicte_id"] + else { + $query = " + INSERT INTO {textbook_companion_aicte} + (book, author, category, isbn, publisher, edition, year) + VALUES + (:book, :author, :category, :isbn, :publisher, :edition, :year) + "; + $args = array( + ':book' => $v["book"], + ':author' => $v["author"], + ':category' => $v["category"], + ':isbn' => $v["isbn"], + ':publisher' => $v["publisher"], + ':edition' => $v["edition"], + ':year' => $v["year"] + ); + $result = db_query($query, $args); + drupal_set_message(t('Book added successfully'),'status'); + } +} +function R_fixer_aicte_all() +{ + $page_content = ""; + $R_fixer_aicte_form = drupal_get_form("R_fixer_aicte_form"); + $page_content .= drupal_render($R_fixer_aicte_form); + return $page_content; +} +function R_fixer_aicte_edit_all($aicte_id = 0) +{ + $page_content = ""; + if ($aicte_id) { + $R_fixer_aicte_form = drupal_get_form("R_fixer_aicte_form", $aicte_id); + $page_content .= drupal_render($R_fixer_aicte_form); + } //$aicte_id + else { + /*$query = " + SELECT * FROM textbook_companion_aicte + ORDER BY time DESC + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $query->orderBy('time', 'DESC'); + $result = $query->execute(); + $headers = array( + "Book", + "Author", + "Edition", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) { + $item = array( + "{$row->book}", + "{$row->author}", + "{$row->edition}", + l(t("Edit"), "r_tbc_fixer/aicte/edit/{$row->id}") + ); + if ($row->selected) { + $check = ""; + } //$row->selected + else { + $check = ""; + } + array_push($item, $check); + array_push($rows, $item); + } //$row = $result->fetchObject() + //$page_content .= theme("table", $headers, $rows); + $page_content .= theme("table", array( + 'header' => $headers, + 'rows' => $rows + )); + } + return $page_content; +} +function R_fixer_aicte_in_all() +{ + $page_content = ""; + /*$query = " + SELECT * FROM textbook_companion_aicte + "; + $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); + $query->fields('textbook_companion_aicte'); + $result = $query->execute(); + $headers = array( + "Book", + "Publisher", + "Action" + ); + $rows = array(); + while ($row = $result->fetchObject()) { + $item = array( + "data" => array( + "{$row->book}
    by{$row->author}", + $row->publisher + ) + ); + $ind_options = array( + /* # linking in drupal l() */ + "fragment" => " ", + "external" => TRUE, + "attributes" => array( + "class" => "ind-ed", + "data-aicte" => "{$row->id}" + ) + ); + /* ind-ed link */ + if ($row->ind) { + array_push($item["data"], l("Unmark", "", $ind_options)); + } //$row->ind + else { + array_push($item["data"], l("Mark", "", $ind_options)); + } + if ($row->ind) { + $item["class"] .= " orange"; + } //$row->ind + array_push($rows, $item); + } //$row = $result->fetchObject() + $page_content .= theme('table', array( + 'header' => $headers, + 'rows' => $rows + )); + return $page_content; +} +function R_fixer_code_form($form, &$form_state) +{ + $form = array(); + $form["code_edit"] = array( + "#type" => "fieldset", + "#title" => "Code edit form", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["category"] = array( + "#type" => "select", + "#title" => t("Please select the category"), + '#options' => _tbc_fixer_list_of_category() + ); + $form["code_edit"]["book"] = array( + "#type" => "select", + "#title" => t("Please select the book."), + "#options" => array( + 0 => "Please select a book" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["chapter"] = array( + "#type" => "select", + "#title" => t("Please select the chapter"), + "#options" => array( + 0 => "Please select a chapter" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["example"] = array( + "#type" => "select", + "#title" => t("Please select the example"), + "#options" => array( + 0 => "Please select a example" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor"), + '#resizable' => FALSE, + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["submit"] = array( + "#type" => "submit", + "#value" => "Update", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + return $form; +} +function R_fixer_code_all() +{ + $page_content = ""; + $page_content .= "
    "; + $page_content .= "
    Updating...
    "; + $page_content .= "Done."; + $R_fixer_code_form = drupal_get_form("R_fixer_code_form"); + $page_content .= drupal_render($R_fixer_code_form); + $page_content .= "
    "; + return $page_content; +} + +function r_tbc_fixer_init() +{ + drupal_add_css(drupal_get_path("module", "r_tbc_fixer") . "/css/r_tbc_fixer.css"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer.js"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer_edit_category.js"); + //drupal_add_js(drupal_get_path("module", "R_fixer") . "/js/jquery-noconfilct.js"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/selection.js"); +} diff --git a/r_tbc_fixer.info b/r_tbc_fixer.info new file mode 100755 index 0000000..79b1ac9 --- /dev/null +++ b/r_tbc_fixer.info @@ -0,0 +1,5 @@ +name = "R Textbook Companion fixer" +description = "Module to fix R code bugs" +version = "7.1.1" +core = "7.x" +package = IITB diff --git a/r_tbc_fixer.module b/r_tbc_fixer.module new file mode 100755 index 0000000..b89da85 --- /dev/null +++ b/r_tbc_fixer.module @@ -0,0 +1,471 @@ + "Edit TBC captions", + "page callback" => "R_fixer_caption_all", + "access arguments" => array( + "fix R_code_caption" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["r_tbc_fixer/code"] = array( + "title" => "Edit TBC code", + "page callback" => "R_fixer_code_all", + "access arguments" => array( + "fix R" + ), + "type" => MENU_NORMAL_ITEM + ); + $items["r_tbc_fixer/ajax"] = array( + "page callback" => "R_fixer_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); + $items["r_tbc_fixer/ajax/edit-book-category"] = array( + "page callback" => "r_tbc_fixer_edit_book_category_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK, + "file" => "r_tbc_fixer_edit_book_category.inc" + ); + /* for admin */ + $items['admin/settings/r_tbc_fixer_settings'] = array( + 'title' => 'textbook companion fixer Settings', + 'description' => 'Textbook Companion Fixer Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'r_tbc_fixer_settings_form' + ), + 'access arguments' => array( + 'administer textbook companion fixer settings' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_settings.inc' + ); + // edit book categoery + $items["r_tbc_fixer/edit_book_category"] = array( + "title" => "Edit Completed Books Category", + "page callback" => "r_tbc_fixer_edit_book_proposal_all", + "access arguments" => array( + "fix R_textbook_category" + ), + "type" => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_edit_book_category.inc' + ); + $items['r_tbc_fixer/category_edit'] = array( + 'title' => 'Categorize', + 'description' => 'Edit Completed Books Category', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'r_tbc_fixer_category_edit_form' + ), + 'access arguments' => array( + 'fix R_textbook_category' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'r_tbc_fixer_edit_book_category.inc' + ); + return $items; +} +function r_tbc_fixer_permission() +{ + return array( + "fix R" => array( + "title" => t("fix R code"), + 'restrict access' => TRUE + ), + "fix R_code_caption" => array( + "title" => t("fix R code caption"), + 'restrict access' => TRUE + ), + "administer textbook companion fixer settings" => array( + "title" => t("administer textbook companion fixer settings"), + 'restrict access' => TRUE + ), + "fix R_textbook_category" => array( + "title" => t("fix R textbook category"), + 'restrict access' => TRUE + ) + ); +} + +function R_fixer_caption_form($form, &$form_state) +{ + $form = array(); + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Caption change form", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["book"] = array( + "#type" => "select", + "#title" => t("Please select the book."), + "#options" => r_get_tbc_books(), + ); + $form["wrapper"]["chapter"] = array( + "#type" => "select", + "#title" => t("Please select the chapter"), + "#options" => array( + 0 => "Please select a chapter" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["chapter_name"] = array( + "#type" => "textfield", + "#title" => t("Enter new chapter name"), + "#size" => 255, + "#maxlength" => 255, + "#attributes" => array( + "Style" => "width:100%" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["example"] = array( + "#type" => "select", + "#title" => t("Please select the example"), + "#description" => t("*Double click on example caption you want to edit"), + "#options" => array( + 0 => "Please select a example" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["caption"] = array( + "#type" => "textfield", + "#title" => t("Enter new caption"), + "#attributes" => array( + "Style" => "width:100%" + ), + "#size" => 255, + "#maxlength" => 255, + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["chapter_example"] = array( + "#markup" => " + Update Chapter caption
    + + Update Example caption", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["submit"] = array( + "#type" => "submit", + "#value" => "Update", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]["code_wrapper"] = array( + "#type" => "fieldset", + "#description" => t("No code to display"), + "#attributes" => array( + "onclick" => "return check();" + ), + "#prefix" => "
    ",
    +		"#suffix" => "
    " + ); + return $form; +} + +function R_fixer_caption_all() +{ + $page_content = ""; + $page_content .= "
    "; + $page_content .= "
    Updating...
    "; + $page_content .= "Done."; + $R_fixer_caption_form = drupal_get_form("R_fixer_caption_form"); + $page_content .= drupal_render($R_fixer_caption_form); + $page_content .= "
    "; + $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; + return $page_content; +} + +function R_fixer_ajax($item, $key) +{ + $data = ""; + global $user; + 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);*/ + $query = db_select('textbook_companion_preference', 'pre'); + $query->fields('pre', array( + 'id', + 'book', + 'author' + )); + $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); + $query->condition('pro.proposal_status', 3); + $query->condition('pre.approval_status', 1); + $query->condition('pre.category', $key); + $query->orderBy('pre.book', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "category" && $key + else if ($item == "book" && $key) { + /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('preference_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "book" && $key + else if ($item == "chapter" && $key) { + /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; + $result = db_query($query, $key);*/ + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('chapter_id', $key); + $query->orderBy('number', 'ASC'); + $result = $query->execute(); + $data .= ""; + while ($row = $result->fetchObject()) { + $data .= ""; + } //$row = $result->fetchObject() + } //$item == "chapter" && $key + else if ($item == "example" && $key) { + + $result = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.filetype= 'S' AND tcef.example_id= :example_id", array( + ':example_id' => $key + )); + $row = $result->fetchObject(); + /* fetching example file data */ + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "r_uploads/tbc_uploads/"; + $example_path = $uploads_dir. $row->directory_name. '/'. $row->filepath; + $example = file_get_contents($example_path); + $data .= "
    {$row->caption}
    "; + $data .= "
    {$example}
    "; + } //$item == "example" && $key + else if ($item == "update-example") { + $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);*/ + $query = db_update('textbook_companion_example'); + $query->fields(array( + 'caption' => $caption + )); + $query->condition('id', $example_id); + $result = $query->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-example" + else if ($item == "update-chapter") { + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['chapter_updated']['chapter_id'] = $chapter_id; + $params['chapter_updated']['user_id'] = $user->uid; + $params['chapter_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update-chapter" + else if ($item == "update-both") { + $example_id = $_POST["example_id"]; + $caption = $_POST["caption"]; + $chapter_id = $_POST["chapter_id"]; + $chapter_caption = $_POST["chapter_caption"]; + $query_exmaple = db_update('textbook_companion_example'); + $query_exmaple->fields(array( + 'caption' => $caption + )); + $query_exmaple->condition('id', $example_id); + $result_example = $query_exmaple->execute(); + $query_chapter = db_update('textbook_companion_chapter'); + $query_chapter->fields(array( + 'name' => $chapter_caption + )); + $query_chapter->condition('id', $chapter_id); + $result_chapter = $query_chapter->execute(); + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['example_updated']['example_id'] = $example_id; + $params['example_updated']['user_id'] = $user->uid; + $params['example_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('r_tbc_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE) + } //$item == "update" + else if ($item == "code" && $key) { + $code = $_POST["code"]; + $result = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.filetype= 'S' AND tcef.example_id= :example_id", array( + ':example_id' => $key + )); + $row = $result->fetchObject(); + $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "r_uploads/tbc_uploads/"; + $example_path = $uploads_dir. $row->directory_name. '/'. $row->filepath; + file_put_contents($example_path, $code); + $data .= "updated"; + } //$item == "code" && $key + else if ($item == "ind-ed" && $key) { + $query = " + UPDATE textbook_companion_aicte + SET ind = !ind + WHERE id = :id + "; + $args = array( + ":id" => $key + ); + db_query($query, $args); + $data .= "updated"; + } //$item == "ind-ed" && $key + else { + $data = ""; + } + echo $data; + exit(); +} + +function R_fixer_code_form($form, &$form_state) +{ + $form = array(); + $form["code_edit"] = array( + "#type" => "fieldset", + "#title" => "Code edit form", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["book"] = array( + "#type" => "select", + "#title" => t("Please select the book."), + "#options" => r_get_tbc_books(), + ); + $form["code_edit"]["chapter"] = array( + "#type" => "select", + "#title" => t("Please select the chapter"), + "#options" => array( + 0 => "Please select a chapter" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["example"] = array( + "#type" => "select", + "#title" => t("Please select the example"), + "#options" => array( + 0 => "Please select a example" + ), + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["code"] = array( + "#type" => "textarea", + "#title" => t("Code Editor"), + '#resizable' => FALSE, + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["code_edit"]["submit"] = array( + "#type" => "submit", + "#value" => "Update", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + return $form; +} +function R_fixer_code_all() +{ + $page_content = ""; + $page_content .= "
    "; + $page_content .= "
    Updating...
    "; + $page_content .= "Done."; + $R_fixer_code_form = drupal_get_form("R_fixer_code_form"); + $page_content .= drupal_render($R_fixer_code_form); + $page_content .= "
    "; + return $page_content; +} + +function r_get_tbc_books(){ + $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 + ORDER BY pre.book ASC + "; + $book_list = db_query($query); + $book[0] = "Select any book"; + while ($book_list_data = $book_list->fetchObject()) + { + $book[$book_list_data->id] .= $book_list_data->book; + } + return $book; +} +function r_tbc_fixer_init() +{ + drupal_add_css(drupal_get_path("module", "r_tbc_fixer") . "/css/r_tbc_fixer.css"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer.js"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer_edit_category.js"); + drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/selection.js"); +} diff --git a/r_tbc_fixer_edit_book_category.inc b/r_tbc_fixer_edit_book_category.inc new file mode 100755 index 0000000..d25cec5 --- /dev/null +++ b/r_tbc_fixer_edit_book_category.inc @@ -0,0 +1,405 @@ +0"); + $row = $result->fetchObject(); + $book_count = $row->book_count; + $i = 1; + /* get preference */ + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0 ORDER BY pe.book ASC"); + while ($preference_data = $preference_q->fetchObject()) + { + $proposal_rows[] = array( + $i, + "{$preference_data->book}
    by {$preference_data->author}", + _r_tbc_fixer_list_of_category($preference_data->existing_category), + _tbc_fixer_list_of_new_category($preference_data->pref_id), + l('Edit', 'r_tbc_fixer/category_edit/' . $preference_data->pref_id) + ); + $i++; + } //$proposal_data = $proposal_q->fetchObject() + /* check if there are any pending proposals */ + if (!$proposal_rows) + { + drupal_set_message(t('There are no proposals.'), 'status'); + return ''; + } //!$proposal_rows + $output .= "Book count with category: " . $book_count; + $proposal_header = array( + 'No.', + 'Title of the Book', + 'Existing Category', + 'New Category', + 'Action' + ); + $output .= theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; +} +/******************************************************************************/ +/**************************** CATEGORY EDIT FORM ******************************/ +/******************************************************************************/ +function r_tbc_fixer_category_edit_form($form, &$form_state) +{ + /* get current proposal */ + $preference_id = arg(2); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $preference_q = $query->execute(); + $preference_data = $preference_q->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); + drupal_goto('manage_proposal/category'); + return; + } //!$preference_data + $form["wrapper"] = array( + "#type" => "fieldset", + "#title" => "Edit the existing book category to new category", + "#prefix" => "
    ", + "#suffix" => "
    " + ); + $form["wrapper"]['book'] = array( + '#type' => 'item', + '#title' => t('Title of the book'), + '#markup' => $preference_data->book + ); + $form["wrapper"]['author'] = array( + '#type' => 'item', + '#title' => t('Author Name'), + '#markup' => $preference_data->author + ); + $form["wrapper"]['isbn'] = array( + '#type' => 'item', + '#title' => t('ISBN No'), + '#markup' => $preference_data->isbn + ); + $form["wrapper"]['publisher'] = array( + '#type' => 'item', + '#title' => t('Publisher & Place'), + '#markup' => $preference_data->publisher + ); + $form["wrapper"]['edition'] = array( + '#type' => 'item', + '#title' => t('Edition'), + '#markup' => $preference_data->edition + ); + $form["wrapper"]['year'] = array( + '#type' => 'item', + '#title' => t('Year of pulication'), + '#markup' => $preference_data->year + ); + $form["wrapper"]['pref_id'] = array( + '#markup' => '' + ); + $form["wrapper"]['main_category'] = array( + "#markup" => _r_tbc_fixer_list_of_category_checkboxes() + ); + $form["wrapper"]['back'] = array( + '#markup' => l(t('Back'), 'r_tbc_fixer/edit_book_category') + ); + return $form; +} +function r_tbc_fixer_edit_book_category_ajax() +{ + global $user; + $data = ""; + $item = arg(2); + $main_category = $_POST['main_category']; + $sub_category = $_POST['sub_category']; + if ($item == "edit-book-category") + { + if ($_POST['action'] == "add") + { + $query_in1 = " + INSERT INTO {textbook_companion_book_main_subcategories} + (pref_id, main_category, sub_category) + VALUES + (:pref_id, :main_category, :subcategory) + "; + $args_in1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $main_category, + ':subcategory' => $sub_category + ); + $result_in1 = db_query($query_in1, $args_in1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['category_updated']['pref_id'] = $_POST['pref_id']; + $params['category_updated']['main_category'] = $main_category; + $params['category_updated']['sub_category'] = $sub_category; + $params['category_updated']['user_id'] = $user->uid; + $params['category_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'new_category_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } + } //$_POST['action'] == "add" + elseif ($_POST['action'] == "delete") + { + $query_del1 = "DELETE FROM {textbook_companion_book_main_subcategories} +WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory + "; + $args_del1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'], + ':subcategory' => $_POST['sub_category'] + ); + $result_del1 = db_query($query_del1, $args_del1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['subcategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['subcategory_deleted']['main_category'] = $main_category; + $params['subcategory_deleted']['sub_category'] = $sub_category; + $params['subcategory_deleted']['user_id'] = $user->uid; + $params['subcategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'new_subcategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } + } //$_POST['action'] == "delete" + elseif ($_POST['action'] == "delete-main-with-ub-category") + { + $query_del2 = "DELETE FROM {textbook_companion_book_main_subcategories} +WHERE pref_id= :pref_id AND main_category= :main_category + "; + $args_del2 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'] + ); + $result_del2 = db_query($query_del2, $args_del2); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('r_tbc_fixer_bcc_emails', ''); + $cc = variable_get('r_tbc_fixer_cc_emails', ''); + $params['maincategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['maincategory_deleted']['main_category'] = $main_category; + $params['maincategory_deleted']['user_id'] = $user->uid; + $params['maincategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('r_tbc_fixer', 'new_maincategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } + } //$_POST['action'] == "delete-main-with-ub-category" + else + { + $data = "Not Updated"; + } + } //$item == "edit-book-category" + else + { + $data = "Not Updated"; + } + echo $data; + exit(); +} +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _r_tbc_fixer_list_of_category($category_id) +{ + $category .= ""; + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('id', $category_id); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $category = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _tbc_fixer_list_of_new_category($pref_id) +{ + $category = ""; + $main_category_query = " + SELECT distinct(maincategory) + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id + "; + $args = array( + ':pref_id' => $pref_id + ); + $maincategory_list = db_query($main_category_query, $args); + $category .= "
      "; + while ($category_list_data = $maincategory_list->fetchObject()) + { + $category .= "
    1. $category_list_data->maincategory
    2. "; + $sub_category_query = " + SELECT DISTINCT (los.subcategory) + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue + "; + $sub_args = array( + ':pref_id' => $pref_id, + ':maincategoryvalue' => $category_list_data->maincategory + ); + $sub_category_list = db_query($sub_category_query, $sub_args); + while ($sub_category_list_data = $sub_category_list->fetchObject()) + { + $category .= "
      • $sub_category_list_data->subcategory
      "; + } //$sub_category_list_data = $sub_category_list->fetchObject() + } //$category_list_data = $maincategory_list->fetchObject() + $category .= "
    "; + return $category; +} +function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) +{ + $category = ""; + $query = " + SELECT maincategory, los.subcategory as subcategory + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms + ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $category_list = db_query($query, $args); + while ($category_list_data = $category_list->fetchObject()) + { + $category .= $category_list_data->maincategory; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _r_tbc_fixer_list_of_category_checkboxes() +{ + $pref_id = arg(2); + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname = $category_list_data->maincategory; + if ($categoryname != null || strlen($categoryname) != 0) + { + //$category[$category_list_data->category_id] = $category_list_data->main_category; + $existing_category = _tbc_fixer_list_of_ext_new_category($pref_id, $category_list_data->category_id); + $existing_subcategory = _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_list_data->category_id); + $checked = $existing_category ? 'checked="checked"' : ''; + $category .= "" . $category_list_data->maincategory . "
    +
    + + + + + + + + +
    Available sub categoriesSelected sub categories
    + Add » + « Remove + +
    +
    "; + } //$category_list_data = $category_list->fetchObject() + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _r_tbc_fixer_list_of_subcategory($pref_id, $category_id) +{ + $query = " + SELECT los.subcategory_id as subcat_id,los.subcategory as sub_category + FROM list_of_subcategory los WHERE los.maincategory_id= :category_id AND los.subcategory_id + NOT IN (SELECT los.subcategory_id as sub_id from list_of_subcategory los + LEFT OUTER JOIN textbook_companion_book_main_subcategories tcbms + ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id and tcbms.main_category=:category_id + ORDER BY sub_id) + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$subcategory_list_data = $subcategory_list->fetchObject() + return $subcategory; +} +function _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_id) +{ + $subcategory = ""; + $query = " + SELECT DISTINCT (los.subcategory), maincategory, los.subcategory as subcategory, + los.subcategory_id as subcat_id FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} diff --git a/r_tbc_fixer_email.inc b/r_tbc_fixer_email.inc new file mode 100755 index 0000000..2779022 --- /dev/null +++ b/r_tbc_fixer_email.inc @@ -0,0 +1,293 @@ +fields('textbook_companion_example'); + $query->condition('id', $params['chapter_example_updated']['example_id']); + $query->range(0, 1); + $result = $query->execute(); + $example_data = $result->fetchObject(); + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $example_data->chapter_id); + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['chapter_example_updated']['user_id']); + $message['headers'] = $params['chapter_example_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter, example caption for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' +Example number : ' . $example_data->number . ' +Caption : ' . $example_data->caption . ' + + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'chapter_updated': + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $params['chapter_updated']['chapter_id']);; + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['chapter_updated']['user_id']); + $message['headers'] = $params['chapter_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter name for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'example_updated': + $query = db_select('textbook_companion_example'); + $query->fields('textbook_companion_example'); + $query->condition('id', $params['example_updated']['example_id']); + $query->range(0, 1); + $result = $query->execute(); + $example_data = $result->fetchObject(); + $query = db_select('textbook_companion_chapter'); + $query->fields('textbook_companion_chapter'); + $query->condition('id', $example_data->chapter_id); + $query->range(0, 1); + $result = $query->execute(); + $chapter_data = $result->fetchObject(); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $user_data = user_load($params['example_updated']['user_id']); + $message['headers'] = $params['example_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion] You have updated example caption for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the following example: + +Title of the book : ' . $preference_data->book . ' +Title of the chapter : ' . $chapter_data->name . ' +Example number : ' . $example_data->number . ' +Caption : ' . $example_data->caption . ' + + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_category_updated': + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['category_updated']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['category_updated']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['category_updated']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['category_updated']['user_id']); + $message['headers'] = $params['category_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have updated category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the category for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_subcategory_deleted': + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['subcategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['subcategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['subcategory_deleted']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['subcategory_deleted']['user_id']); + $message['headers'] = $params['subcategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted subcategory for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_maincategory_deleted': + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['maincategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['maincategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $user_data = user_load($params['maincategory_deleted']['user_id']); + $message['headers'] = $params['maincategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted main category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the main category with subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' + +Best Wishes, + +R TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + } //$key +} diff --git a/r_tbc_fixer_settings.inc b/r_tbc_fixer_settings.inc new file mode 100755 index 0000000..73a9b5b --- /dev/null +++ b/r_tbc_fixer_settings.inc @@ -0,0 +1,58 @@ + 'textfield', + '#title' => t('(To) Notification emails'), + '#description' => t('A comma separated list of email addresses to receive notifications emails'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('r_tbc_fixer_to_emails', '') + ); + $form['bcc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(BCc) Notification emails'), + '#description' => t('Specify emails id for BCC option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('r_tbc_fixer_bcc_emails', '') + ); + $form['cc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(Cc) Notification emails'), + '#description' => t('Specify emails id for CC option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('r_tbc_fixer_cc_emails', '') + ); + $form['from_email'] = array( + '#type' => 'textfield', + '#title' => t('(From) Outgoing from email address'), + '#description' => t('Email address to be display in the from field of all outgoing messages'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('r_tbc_fixer_from_email', '') + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; +} +function r_tbc_fixer_settings_form_validate($form, &$form_state) +{ + return; +} +function r_tbc_fixer_settings_form_submit($form, &$form_state) +{ + variable_set('r_tbc_fixer_to_emails', $form_state['values']['to_emails']); + variable_set('r_tbc_fixer_bcc_emails', $form_state['values']['bcc_emails']); + variable_set('r_tbc_fixer_cc_emails', $form_state['values']['cc_emails']); + variable_set('r_tbc_fixer_from_email', $form_state['values']['from_email']); +} diff --git a/textbook_companion_fixer.info b/textbook_companion_fixer.info deleted file mode 100755 index bc72bc6..0000000 --- a/textbook_companion_fixer.info +++ /dev/null @@ -1,4 +0,0 @@ -name = Textbook Companion fixer -description = Module to fix scilab code bugs -core = 7.x -package = IITB diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module deleted file mode 100755 index bc8484c..0000000 --- a/textbook_companion_fixer.module +++ /dev/null @@ -1,777 +0,0 @@ - "Edit TBC captions", - "page callback" => "scilab_fixer_caption_all", - "access arguments" => array( - "fix scilab_code_caption" - ), - "type" => MENU_NORMAL_ITEM - ); - $items["textbook_companion_fixer/aicte"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 30, - "type" => MENU_NORMAL_ITEM - ); - $items["textbook_companion_fixer/aicte/new"] = array( - "title" => "Add AICTE books", - "page callback" => "scilab_fixer_aicte_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 1, - "type" => MENU_DEFAULT_LOCAL_TASK - ); - $items["textbook_companion_fixer/aicte/edit"] = array( - "title" => "Edit AICTE books", - "page callback" => "scilab_fixer_aicte_edit_all", - "access arguments" => array( - "fix scilab" - ), - "weight" => 2, - "type" => MENU_LOCAL_TASK - ); - $items["textbook_companion_fixer/aicte/in"] = array( - "title" => "Mark Indian edition books", - "page callback" => "scilab_fixer_aicte_in_all", - "access arguments" => array( - "fix scilab" - ), - "type" => MENU_CALLBACK - ); - $items["textbook_companion_fixer/code"] = array( - "title" => "Edit TBC code", - "page callback" => "scilab_fixer_code_all", - "access arguments" => array( - "fix scilab" - ), - "type" => MENU_NORMAL_ITEM - ); - $items["textbook_companion_fixer/ajax"] = array( - "page callback" => "scilab_fixer_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - $items["textbook_companion_fixer/aicte/book/ajax"] = array( - "page callback" => "scilab_fixer_aicte_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK - ); - $items["textbook_companion_fixer/ajax/edit-book-category"] = array( - "page callback" => "textbook_companion_fixer_edit_book_category_ajax", - "access callback" => TRUE, - "type" => MENU_CALLBACK, - "file" => "textbook_companion_fixer_edit_book_category.inc" - ); - /* for admin */ - $items['admin/settings/textbook_companion_fixer_settings'] = array( - 'title' => 'textbook companion fixer Settings', - 'description' => 'Textbook Companion Fixer Settings', - 'page callback' => 'drupal_get_form', - 'page arguments' => array( - 'textbook_companion_fixer_settings_form' - ), - 'access arguments' => array( - 'administer textbook companion fixer settings' - ), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'textbook_companion_fixer_settings.inc' - ); - // edit book categoery - $items["textbook_companion_fixer/edit_book_category"] = array( - "title" => "Edit Completed Books Category", - "page callback" => "textbook_companion_fixer_edit_book_proposal_all", - "access arguments" => array( - "fix scilab_textbook_category" - ), - "type" => MENU_NORMAL_ITEM, - 'file' => 'textbook_companion_fixer_edit_book_category.inc' - ); - $items['textbook_companion_fixer/category_edit'] = array( - 'title' => 'Categorize', - 'description' => 'Edit Completed Books Category', - 'page callback' => 'drupal_get_form', - 'page arguments' => array( - 'textbook_companion_fixer_category_edit_form' - ), - 'access arguments' => array( - 'fix scilab_textbook_category' - ), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'textbook_companion_fixer_edit_book_category.inc' - ); - return $items; -} -function textbook_companion_fixer_permission() -{ - return array( - "fix scilab" => array( - "title" => t("fix scilab code"), - 'restrict access' => TRUE - ), - "fix scilab_code_caption" => array( - "title" => t("fix scilab code caption"), - 'restrict access' => TRUE - ), - "administer textbook companion fixer settings" => array( - "title" => t("administer textbook companion fixer settings"), - 'restrict access' => TRUE - ), - "fix scilab_textbook_category" => array( - "title" => t("fix scilab textbook category"), - 'restrict access' => TRUE - ) - ); -} -function scilab_fixer_caption_form($form, &$form_state) -{ - $form = array(); - $form["wrapper"] = array( - "#type" => "fieldset", - "#title" => "Caption change form", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["category"] = array( - "#type" => "select", - "#title" => t("Please select the category"), - '#options' => _tbc_fixer_list_of_category() - ); - $form["wrapper"]["book"] = array( - "#type" => "select", - "#title" => t("Please select the book."), - "#options" => array( - 0 => "Please select a book" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["chapter"] = array( - "#type" => "select", - "#title" => t("Please select the chapter"), - "#options" => array( - 0 => "Please select a chapter" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["chapter_name"] = array( - "#type" => "textfield", - "#title" => t("Enter new chapter name"), - "#size" => 255, - "#maxlength" => 255, - "#attributes" => array( - "Style" => "width:100%" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["example"] = array( - "#type" => "select", - "#title" => t("Please select the example"), - "#description" => t("*Double click on example caption you want to edit"), - "#options" => array( - 0 => "Please select a example" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["caption"] = array( - "#type" => "textfield", - "#title" => t("Enter new caption"), - "#attributes" => array( - "Style" => "width:100%" - ), - "#size" => 255, - "#maxlength" => 255, - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["chapter_example"] = array( - "#markup" => " - Update Chapter caption
    - - Update Example caption", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["submit"] = array( - "#type" => "submit", - "#value" => "Update", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]["code_wrapper"] = array( - "#type" => "fieldset", - "#description" => t("No code to display"), - "#attributes" => array( - "onclick" => "return check();" - ), - "#prefix" => "
    ",
    -		"#suffix" => "
    " - ); - return $form; -} -function scilab_fixer_caption_all() -{ - $page_content = ""; - $page_content .= "
    "; - $page_content .= "
    Updating...
    "; - $page_content .= "Done."; - $scilab_fixer_caption_form = drupal_get_form("scilab_fixer_caption_form"); - $page_content .= drupal_render($scilab_fixer_caption_form); - $page_content .= "
    "; - $page_content .= "* Selecting text from above code-area with mouse will add it to the caption textbox."; - return $page_content; -} -function scilab_fixer_ajax($item, $key) -{ - $data = ""; - global $user; - 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);*/ - $query = db_select('textbook_companion_preference', 'pre'); - $query->fields('pre', array( - 'id', - 'book', - 'author' - )); - $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id'); - $query->condition('pro.proposal_status', 3); - $query->condition('pre.approval_status', 1); - $query->condition('pre.category', $key); - $query->orderBy('pre.book', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "category" && $key - else if ($item == "book" && $key) { - /*$query = "SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('preference_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "book" && $key - else if ($item == "chapter" && $key) { - /*$query = "SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number"; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example'); - $query->fields('textbook_companion_example'); - $query->condition('chapter_id', $key); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - $data .= ""; - while ($row = $result->fetchObject()) { - $data .= ""; - } //$row = $result->fetchObject() - } //$item == "chapter" && $key - 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);*/ - $query = db_select('textbook_companion_example_files', 'fil'); - $query->fields('fil'); - $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = fil.example_id'); - $query->condition('example_id', $key); - $query->condition('filetype', 'S'); - $query->orderBy('number', 'ASC'); - $result = $query->execute(); - $row = $result->fetchObject(); - /* 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 .= "
    {$row->caption}
    "; - $data .= "
    {$example}
    "; - } //$item == "example" && $key - else if ($item == "update-example") { - $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);*/ - $query = db_update('textbook_companion_example'); - $query->fields(array( - 'caption' => $caption - )); - $query->condition('id', $example_id); - $result = $query->execute(); - $data .= "Updated"; - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['example_updated']['example_id'] = $example_id; - $params['example_updated']['user_id'] = $user->uid; - $params['example_updated']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) - } //$item == "update-example" - else if ($item == "update-chapter") { - $chapter_id = $_POST["chapter_id"]; - $chapter_caption = $_POST["chapter_caption"]; - $query_chapter = db_update('textbook_companion_chapter'); - $query_chapter->fields(array( - 'name' => $chapter_caption - )); - $query_chapter->condition('id', $chapter_id); - $result_chapter = $query_chapter->execute(); - $data .= "Updated"; - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['chapter_updated']['chapter_id'] = $chapter_id; - $params['chapter_updated']['user_id'] = $user->uid; - $params['chapter_updated']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } //!drupal_mail('textbook_companion_fixer', 'chapter_updated', $email_to, language_default(), $params, $from, TRUE) - } //$item == "update-chapter" - else if ($item == "update-both") { - $example_id = $_POST["example_id"]; - $caption = $_POST["caption"]; - $chapter_id = $_POST["chapter_id"]; - $chapter_caption = $_POST["chapter_caption"]; - $query_exmaple = db_update('textbook_companion_example'); - $query_exmaple->fields(array( - 'caption' => $caption - )); - $query_exmaple->condition('id', $example_id); - $result_example = $query_exmaple->execute(); - $query_chapter = db_update('textbook_companion_chapter'); - $query_chapter->fields(array( - 'name' => $chapter_caption - )); - $query_chapter->condition('id', $chapter_id); - $result_chapter = $query_chapter->execute(); - $data .= "Updated"; - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['example_updated']['example_id'] = $example_id; - $params['example_updated']['user_id'] = $user->uid; - $params['example_updated']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } //!drupal_mail('textbook_companion_fixer', 'chapter_example_updated', $email_to, language_default(), $params, $from, TRUE) - } //$item == "update" - else if ($item == "code" && $key) { - $code = $_POST["code"]; - /*$query = " - SELECT * FROM textbook_companion_example_files - WHERE example_id = %d AND filetype = 'S' - "; - $result = db_query($query, $key);*/ - $query = db_select('textbook_companion_example_files'); - $query->fields('textbook_companion_example_files'); - $query->condition('example_id', $key); - $query->condition('filetype', 'S'); - $result = $query->execute(); - $row = $result->fetchObject(); - $uploads_dir = $_SERVER['DOCUMENT_ROOT'] . base_path() . "uploads/"; - $example_path = $uploads_dir . $row->filepath; - file_put_contents($example_path, $code); - $data .= "updated"; - } //$item == "code" && $key - else if ($item == "ind-ed" && $key) { - $query = " - UPDATE textbook_companion_aicte - SET ind = !ind - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query, $args); - $data .= "updated"; - } //$item == "ind-ed" && $key - else { - $data = ""; - } - echo $data; - exit(); -} -function scilab_fixer_aicte_ajax($item = "", $key = "") -{ - $data = ""; - if ($item == "selected") { - $query = " - UPDATE textbook_companion_aicte - SET selected = !selected - WHERE id = :id - "; - $args = array( - ":id" => $key - ); - db_query($query, $args); - $data = "updated"; - } //$item == "selected" - echo $data; - exit(); -} -function scilab_fixer_aicte_form($form, $form_state, $aicte_id = '') -{ - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE id = {$aicte_id} - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->condition('id', $aicte_id); - $result = $query->execute(); - $row = $result->fetchObject(); - $form = array(); - $form["book"] = array( - "#type" => "textfield", - "#title" => "Book Name", - "#default_value" => $row->book, - "#required" => TRUE - ); - $form["author"] = array( - "#type" => "textfield", - "#title" => "Author", - "#default_value" => $row->author, - "#required" => TRUE - ); - $form["category"] = array( - "#type" => "select", - "#title" => "Book Category", - '#options' => _tbc_fixer_list_of_category(), - "#default_value" => $row->category, - "#required" => TRUE - ); - $form["isbn"] = array( - "#type" => "textfield", - "#title" => "ISBN", - "#default_value" => $row->isbn, - "#required" => FALSE - ); - $form["publisher"] = array( - "#type" => "textfield", - "#title" => "Publisher", - "#default_value" => $row->publisher, - "#required" => TRUE - ); - $form["edition"] = array( - "#type" => "textfield", - "#title" => "Edition", - "#default_value" => $row->edition, - "#required" => TRUE - ); - $form["year"] = array( - "#type" => "textfield", - "#title" => "Year of publication", - "#default_value" => $row->year, - "#required" => TRUE - ); - $form["aicte_id"] = array( - "#type" => "hidden", - "#value" => $row->id - ); - $form["submit"] = array( - "#type" => "submit", - "#value" => "Submit" - ); - return $form; -} -function scilab_fixer_aicte_form_validate($form, &$form_state) -{ - if (!$form_state["values"]["category"]) { - form_set_error("category", "Please select a category."); - } //!$form_state["values"]["category"] - if (!is_numeric($form_state["values"]["edition"])) { - form_set_error("edition", "Only digits are allowed."); - } //!is_numeric($form_state["values"]["edition"]) - if (!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4) { - form_set_error("year", "Please enter a valid year. eg: 2011."); - } //!is_numeric($form_state["values"]["year"]) && strlen($form["values"]["year"]) != 4 -} -function scilab_fixer_aicte_form_submit($form, &$form_state) -{ - $v = $form_state["values"]; - if ($v["aicte_id"]) { - /*$query = " - UPDATE textbook_companion_aicte - SET book = '%s', author = '%s', category = %d, - isbn = '%s', publisher = '%s', edition = %d, - year = %d - WHERE id = %d - "; - $result = db_query($query, - $v["book"], $v["author"], $v["category"], $v["isbn"], - $v["publisher"], $v["edition"], $v["year"], $v["aicte_id"] - );*/ - $query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'book' => $v["book"], - 'author' => $v["author"], - 'category' => $v["category"], - 'isbn' => $v["isbn"], - 'publisher' => $v["publisher"], - 'edition' => $v["edition"], - 'year' => $v["year"] - )); - $query->condition('id', $v["aicte_id"]); - $num_updated = $query->execute(); - drupal_set_message(t('Book updated successfully'), 'status'); - } //$v["aicte_id"] - else { - $query = " - INSERT INTO {textbook_companion_aicte} - (book, author, category, isbn, publisher, edition, year) - VALUES - (:book, :author, :category, :isbn, :publisher, :edition, :year) - "; - $args = array( - ':book' => $v["book"], - ':author' => $v["author"], - ':category' => $v["category"], - ':isbn' => $v["isbn"], - ':publisher' => $v["publisher"], - ':edition' => $v["edition"], - ':year' => $v["year"] - ); - $result = db_query($query, $args); - drupal_set_message(t('Book added successfully'),'status'); - } -} -function scilab_fixer_aicte_all() -{ - $page_content = ""; - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form"); - $page_content .= drupal_render($scilab_fixer_aicte_form); - return $page_content; -} -function scilab_fixer_aicte_edit_all($aicte_id = 0) -{ - $page_content = ""; - if ($aicte_id) { - $scilab_fixer_aicte_form = drupal_get_form("scilab_fixer_aicte_form", $aicte_id); - $page_content .= drupal_render($scilab_fixer_aicte_form); - } //$aicte_id - else { - /*$query = " - SELECT * FROM textbook_companion_aicte - ORDER BY time DESC - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $query->orderBy('time', 'DESC'); - $result = $query->execute(); - $headers = array( - "Book", - "Author", - "Edition", - "Action" - ); - $rows = array(); - while ($row = $result->fetchObject()) { - $item = array( - "{$row->book}", - "{$row->author}", - "{$row->edition}", - l(t("Edit"), "textbook_companion_fixer/aicte/edit/{$row->id}") - ); - if ($row->selected) { - $check = ""; - } //$row->selected - else { - $check = ""; - } - array_push($item, $check); - array_push($rows, $item); - } //$row = $result->fetchObject() - //$page_content .= theme("table", $headers, $rows); - $page_content .= theme("table", array( - 'header' => $headers, - 'rows' => $rows - )); - } - return $page_content; -} -function scilab_fixer_aicte_in_all() -{ - $page_content = ""; - /*$query = " - SELECT * FROM textbook_companion_aicte - "; - $result = db_query($query);*/ - $query = db_select('textbook_companion_aicte'); - $query->fields('textbook_companion_aicte'); - $result = $query->execute(); - $headers = array( - "Book", - "Publisher", - "Action" - ); - $rows = array(); - while ($row = $result->fetchObject()) { - $item = array( - "data" => array( - "{$row->book}
    by{$row->author}", - $row->publisher - ) - ); - $ind_options = array( - /* # linking in drupal l() */ - "fragment" => " ", - "external" => TRUE, - "attributes" => array( - "class" => "ind-ed", - "data-aicte" => "{$row->id}" - ) - ); - /* ind-ed link */ - if ($row->ind) { - array_push($item["data"], l("Unmark", "", $ind_options)); - } //$row->ind - else { - array_push($item["data"], l("Mark", "", $ind_options)); - } - if ($row->ind) { - $item["class"] .= " orange"; - } //$row->ind - array_push($rows, $item); - } //$row = $result->fetchObject() - $page_content .= theme('table', array( - 'header' => $headers, - 'rows' => $rows - )); - return $page_content; -} -function scilab_fixer_code_form($form, &$form_state) -{ - $form = array(); - $form["code_edit"] = array( - "#type" => "fieldset", - "#title" => "Code edit form", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["code_edit"]["category"] = array( - "#type" => "select", - "#title" => t("Please select the category"), - '#options' => _tbc_fixer_list_of_category() - ); - $form["code_edit"]["book"] = array( - "#type" => "select", - "#title" => t("Please select the book."), - "#options" => array( - 0 => "Please select a book" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["code_edit"]["chapter"] = array( - "#type" => "select", - "#title" => t("Please select the chapter"), - "#options" => array( - 0 => "Please select a chapter" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["code_edit"]["example"] = array( - "#type" => "select", - "#title" => t("Please select the example"), - "#options" => array( - 0 => "Please select a example" - ), - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["code_edit"]["code"] = array( - "#type" => "textarea", - "#title" => t("Code Editor"), - '#resizable' => FALSE, - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["code_edit"]["submit"] = array( - "#type" => "submit", - "#value" => "Update", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - return $form; -} -function scilab_fixer_code_all() -{ - $page_content = ""; - $page_content .= "
    "; - $page_content .= "
    Updating...
    "; - $page_content .= "Done."; - $scilab_fixer_code_form = drupal_get_form("scilab_fixer_code_form"); - $page_content .= drupal_render($scilab_fixer_code_form); - $page_content .= "
    "; - return $page_content; -} - -function textbook_companion_fixer_init() -{ - drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); - drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer.js"); - drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/textbook_companion_fixer_edit_category.js"); - //drupal_add_js(drupal_get_path("module", "scilab_fixer") . "/js/jquery-noconfilct.js"); - drupal_add_js(drupal_get_path("module", "textbook_companion_fixer") . "/js/selection.js"); -} diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc deleted file mode 100755 index 1e5d01e..0000000 --- a/textbook_companion_fixer_edit_book_category.inc +++ /dev/null @@ -1,405 +0,0 @@ -0"); - $row = $result->fetchObject(); - $book_count = $row->book_count; - $i = 1; - /* get preference */ - $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date - FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0 ORDER BY pe.book ASC"); - while ($preference_data = $preference_q->fetchObject()) - { - $proposal_rows[] = array( - $i, - "{$preference_data->book}
    by {$preference_data->author}", - _textbook_companion_fixer_list_of_category($preference_data->existing_category), - _tbc_fixer_list_of_new_category($preference_data->pref_id), - l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) - ); - $i++; - } //$proposal_data = $proposal_q->fetchObject() - /* check if there are any pending proposals */ - if (!$proposal_rows) - { - drupal_set_message(t('There are no proposals.'), 'status'); - return ''; - } //!$proposal_rows - $output .= "Book count with category: " . $book_count; - $proposal_header = array( - 'No.', - 'Title of the Book', - 'Existing Category', - 'New Category', - 'Action' - ); - $output .= theme('table', array( - 'header' => $proposal_header, - 'rows' => $proposal_rows - )); - return $output; -} -/******************************************************************************/ -/**************************** CATEGORY EDIT FORM ******************************/ -/******************************************************************************/ -function textbook_companion_fixer_category_edit_form($form, &$form_state) -{ - /* get current proposal */ - $preference_id = arg(2); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $preference_id); - $preference_q = $query->execute(); - $preference_data = $preference_q->fetchObject(); - if (!$preference_data) - { - drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); - drupal_goto('manage_proposal/category'); - return; - } //!$preference_data - $form["wrapper"] = array( - "#type" => "fieldset", - "#title" => "Edit the existing book category to new category", - "#prefix" => "
    ", - "#suffix" => "
    " - ); - $form["wrapper"]['book'] = array( - '#type' => 'item', - '#title' => t('Title of the book'), - '#markup' => $preference_data->book - ); - $form["wrapper"]['author'] = array( - '#type' => 'item', - '#title' => t('Author Name'), - '#markup' => $preference_data->author - ); - $form["wrapper"]['isbn'] = array( - '#type' => 'item', - '#title' => t('ISBN No'), - '#markup' => $preference_data->isbn - ); - $form["wrapper"]['publisher'] = array( - '#type' => 'item', - '#title' => t('Publisher & Place'), - '#markup' => $preference_data->publisher - ); - $form["wrapper"]['edition'] = array( - '#type' => 'item', - '#title' => t('Edition'), - '#markup' => $preference_data->edition - ); - $form["wrapper"]['year'] = array( - '#type' => 'item', - '#title' => t('Year of pulication'), - '#markup' => $preference_data->year - ); - $form["wrapper"]['pref_id'] = array( - '#markup' => '' - ); - $form["wrapper"]['main_category'] = array( - "#markup" => _textbook_companion_fixer_list_of_category_checkboxes() - ); - $form["wrapper"]['back'] = array( - '#markup' => l(t('Back'), 'textbook_companion_fixer/edit_book_category') - ); - return $form; -} -function textbook_companion_fixer_edit_book_category_ajax() -{ - global $user; - $data = ""; - $item = arg(2); - $main_category = $_POST['main_category']; - $sub_category = $_POST['sub_category']; - if ($item == "edit-book-category") - { - if ($_POST['action'] == "add") - { - $query_in1 = " - INSERT INTO {textbook_companion_book_main_subcategories} - (pref_id, main_category, sub_category) - VALUES - (:pref_id, :main_category, :subcategory) - "; - $args_in1 = array( - ':pref_id' => $_POST['pref_id'], - ':main_category' => $main_category, - ':subcategory' => $sub_category - ); - $result_in1 = db_query($query_in1, $args_in1); - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['category_updated']['pref_id'] = $_POST['pref_id']; - $params['category_updated']['main_category'] = $main_category; - $params['category_updated']['sub_category'] = $sub_category; - $params['category_updated']['user_id'] = $user->uid; - $params['category_updated']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'new_category_updated', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } - } //$_POST['action'] == "add" - elseif ($_POST['action'] == "delete") - { - $query_del1 = "DELETE FROM {textbook_companion_book_main_subcategories} -WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory - "; - $args_del1 = array( - ':pref_id' => $_POST['pref_id'], - ':main_category' => $_POST['main_category'], - ':subcategory' => $_POST['sub_category'] - ); - $result_del1 = db_query($query_del1, $args_del1); - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['subcategory_deleted']['pref_id'] = $_POST['pref_id']; - $params['subcategory_deleted']['main_category'] = $main_category; - $params['subcategory_deleted']['sub_category'] = $sub_category; - $params['subcategory_deleted']['user_id'] = $user->uid; - $params['subcategory_deleted']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'new_subcategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } - } //$_POST['action'] == "delete" - elseif ($_POST['action'] == "delete-main-with-ub-category") - { - $query_del2 = "DELETE FROM {textbook_companion_book_main_subcategories} -WHERE pref_id= :pref_id AND main_category= :main_category - "; - $args_del2 = array( - ':pref_id' => $_POST['pref_id'], - ':main_category' => $_POST['main_category'] - ); - $result_del2 = db_query($query_del2, $args_del2); - /* sending email */ - $email_to = $user->mail; - $from = variable_get('textbook_companion_from_email', ''); - $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); - $cc = variable_get('textbook_companion_fixer_cc_emails', ''); - $params['maincategory_deleted']['pref_id'] = $_POST['pref_id']; - $params['maincategory_deleted']['main_category'] = $main_category; - $params['maincategory_deleted']['user_id'] = $user->uid; - $params['maincategory_deleted']['headers'] = array( - 'From' => $from, - 'MIME-Version' => '1.0', - 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', - 'Content-Transfer-Encoding' => '8Bit', - 'X-Mailer' => 'Drupal', - 'Cc' => $cc, - 'Bcc' => $bcc - ); - if (!drupal_mail('textbook_companion_fixer', 'new_maincategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { - $data .= 'Error sending email message.'; - } - } //$_POST['action'] == "delete-main-with-ub-category" - else - { - $data = "Not Updated"; - } - } //$item == "edit-book-category" - else - { - $data = "Not Updated"; - } - echo $data; - exit(); -} -function _tbc_fixer_list_of_category($category_id = NULL) -{ - $category[0] = "Please select"; - if ($category_id == NULL) - { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } //$category_id == NULL - else - { - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->condition('id', $category_id); - $query->orderBy('id', 'ASC'); - $category_list = $query->execute(); - } - while ($category_list_data = $category_list->fetchObject()) - { - $category[$category_list_data->id] = $category_list_data->category_name; - } //$category_list_data = $category_list->fetchObject() - return $category; -} -function _textbook_companion_fixer_list_of_category($category_id) -{ - $category .= ""; - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - $query->condition('id', $category_id); - $category_list = $query->execute(); - while ($category_list_data = $category_list->fetchObject()) - { - $category = $category_list_data->category_name; - } //$category_list_data = $category_list->fetchObject() - return $category; -} -function _tbc_fixer_list_of_new_category($pref_id) -{ - $category = ""; - $main_category_query = " - SELECT distinct(maincategory) - FROM {list_of_category} loc - LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id - "; - $args = array( - ':pref_id' => $pref_id - ); - $maincategory_list = db_query($main_category_query, $args); - $category .= "
      "; - while ($category_list_data = $maincategory_list->fetchObject()) - { - $category .= "
    1. $category_list_data->maincategory
    2. "; - $sub_category_query = " - SELECT DISTINCT (los.subcategory) - FROM {list_of_category} loc - LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue - "; - $sub_args = array( - ':pref_id' => $pref_id, - ':maincategoryvalue' => $category_list_data->maincategory - ); - $sub_category_list = db_query($sub_category_query, $sub_args); - while ($sub_category_list_data = $sub_category_list->fetchObject()) - { - $category .= "
      • $sub_category_list_data->subcategory
      "; - } //$sub_category_list_data = $sub_category_list->fetchObject() - } //$category_list_data = $maincategory_list->fetchObject() - $category .= "
    "; - return $category; -} -function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) -{ - $category = ""; - $query = " - SELECT maincategory, los.subcategory as subcategory - FROM {list_of_category} loc - LEFT JOIN {textbook_companion_book_main_subcategories} tcbms - ON loc.category_id = tcbms.main_category - LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id - "; - $args = array( - ':pref_id' => $pref_id, - ':category_id' => $category_id - ); - $category_list = db_query($query, $args); - while ($category_list_data = $category_list->fetchObject()) - { - $category .= $category_list_data->maincategory; - } //$category_list_data = $category_list->fetchObject() - return $category; -} -function _textbook_companion_fixer_list_of_category_checkboxes() -{ - $pref_id = arg(2); - $query = db_select('list_of_category'); - $query->fields('list_of_category'); - //$query->fields(array('category_id','main_category')); - $query->orderBy('category_id', 'ASC'); - $category_list = $query->execute(); - while ($category_list_data = $category_list->fetchObject()) - { - $categoryname = $category_list_data->maincategory; - if ($categoryname != null || strlen($categoryname) != 0) - { - //$category[$category_list_data->category_id] = $category_list_data->main_category; - $existing_category = _tbc_fixer_list_of_ext_new_category($pref_id, $category_list_data->category_id); - $existing_subcategory = _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_list_data->category_id); - $checked = $existing_category ? 'checked="checked"' : ''; - $category .= "" . $category_list_data->maincategory . "
    -
    - - - - - - - - -
    Available sub categoriesSelected sub categories
    - Add » - « Remove - -
    -
    "; - } //$category_list_data = $category_list->fetchObject() - } //$category_list_data = $category_list->fetchObject() - return $category; -} -function _textbook_companion_fixer_list_of_subcategory($pref_id, $category_id) -{ - $query = " - SELECT los.subcategory_id as subcat_id,los.subcategory as sub_category - FROM list_of_subcategory los WHERE los.maincategory_id= :category_id AND los.subcategory_id - NOT IN (SELECT los.subcategory_id as sub_id from list_of_subcategory los - LEFT OUTER JOIN textbook_companion_book_main_subcategories tcbms - ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id and tcbms.main_category=:category_id - ORDER BY sub_id) - "; - $args = array( - ':pref_id' => $pref_id, - ':category_id' => $category_id - ); - $subcategory_list = db_query($query, $args); - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory .= ""; - } //$subcategory_list_data = $subcategory_list->fetchObject() - return $subcategory; -} -function _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_id) -{ - $subcategory = ""; - $query = " - SELECT DISTINCT (los.subcategory), maincategory, los.subcategory as subcategory, - los.subcategory_id as subcat_id FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id - "; - $args = array( - ':pref_id' => $pref_id, - ':category_id' => $category_id - ); - $subcategory_list = db_query($query, $args); - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory .= ""; - } //$category_list_data = $category_list->fetchObject() - return $subcategory; -} diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc deleted file mode 100644 index 833e470..0000000 --- a/textbook_companion_fixer_email.inc +++ /dev/null @@ -1,293 +0,0 @@ -fields('textbook_companion_example'); - $query->condition('id', $params['chapter_example_updated']['example_id']); - $query->range(0, 1); - $result = $query->execute(); - $example_data = $result->fetchObject(); - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('id', $example_data->chapter_id); - $query->range(0, 1); - $result = $query->execute(); - $chapter_data = $result->fetchObject(); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $chapter_data->preference_id); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $user_data = user_load($params['chapter_example_updated']['user_id']); - $message['headers'] = $params['chapter_example_updated']['headers']; - $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter, example caption for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have updated the following example: - -Title of the book : ' . $preference_data->book . ' -Title of the chapter : ' . $chapter_data->name . ' -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - case 'chapter_updated': - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('id', $params['chapter_updated']['chapter_id']);; - $query->range(0, 1); - $result = $query->execute(); - $chapter_data = $result->fetchObject(); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $chapter_data->preference_id); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $user_data = user_load($params['chapter_updated']['user_id']); - $message['headers'] = $params['chapter_updated']['headers']; - $message['subject'] = t('[!site_name][Textbook companion] You have updated chapter name for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have updated the following example: - -Title of the book : ' . $preference_data->book . ' -Title of the chapter : ' . $chapter_data->name . ' - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - case 'example_updated': - $query = db_select('textbook_companion_example'); - $query->fields('textbook_companion_example'); - $query->condition('id', $params['example_updated']['example_id']); - $query->range(0, 1); - $result = $query->execute(); - $example_data = $result->fetchObject(); - $query = db_select('textbook_companion_chapter'); - $query->fields('textbook_companion_chapter'); - $query->condition('id', $example_data->chapter_id); - $query->range(0, 1); - $result = $query->execute(); - $chapter_data = $result->fetchObject(); - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $chapter_data->preference_id); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $user_data = user_load($params['example_updated']['user_id']); - $message['headers'] = $params['example_updated']['headers']; - $message['subject'] = t('[!site_name][Textbook companion] You have updated example caption for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have updated the following example: - -Title of the book : ' . $preference_data->book . ' -Title of the chapter : ' . $chapter_data->name . ' -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - case 'new_category_updated': - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $params['category_updated']['pref_id']); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $query_mcat = db_select('list_of_category'); - $query_mcat->fields('list_of_category'); - $query_mcat->condition('category_id', $params['category_updated']['main_category']); - $query_mcat->range(0, 1); - $result_mcat = $query_mcat->execute(); - $main_category_data = $result_mcat->fetchObject(); - $query_subcat = db_select('list_of_subcategory'); - $query_subcat->fields('list_of_subcategory'); - $query_subcat->condition('subcategory_id', $params['category_updated']['sub_category']); - $query_subcat->range(0, 1); - $result_subcat = $query_subcat->execute(); - $sub_category_data = $result_subcat->fetchObject(); - $user_data = user_load($params['category_updated']['user_id']); - $message['headers'] = $params['category_updated']['headers']; - $message['subject'] = t('[!site_name][Textbook companion][category] You have updated category for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have updated the category for following book : - -Title of the book : ' . $preference_data->book . ' -Author : ' . $preference_data->author. ' - -Main category : '. $main_category_data->maincategory .' -Sub category : '. $sub_category_data->subcategory .' - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - case 'new_subcategory_deleted': - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $params['subcategory_deleted']['pref_id']); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $query_mcat = db_select('list_of_category'); - $query_mcat->fields('list_of_category'); - $query_mcat->condition('category_id', $params['subcategory_deleted']['main_category']); - $query_mcat->range(0, 1); - $result_mcat = $query_mcat->execute(); - $main_category_data = $result_mcat->fetchObject(); - $query_subcat = db_select('list_of_subcategory'); - $query_subcat->fields('list_of_subcategory'); - $query_subcat->condition('subcategory_id', $params['subcategory_deleted']['sub_category']); - $query_subcat->range(0, 1); - $result_subcat = $query_subcat->execute(); - $sub_category_data = $result_subcat->fetchObject(); - $user_data = user_load($params['subcategory_deleted']['user_id']); - $message['headers'] = $params['subcategory_deleted']['headers']; - $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted subcategory for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have deleted the subcategory for following book : - -Title of the book : ' . $preference_data->book . ' -Author : ' . $preference_data->author. ' - -Main category : '. $main_category_data->maincategory .' -Sub category : '. $sub_category_data->subcategory .' - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - case 'new_maincategory_deleted': - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('id', $params['maincategory_deleted']['pref_id']); - $query->range(0, 1); - $result = $query->execute(); - $preference_data = $result->fetchObject(); - $query_mcat = db_select('list_of_category'); - $query_mcat->fields('list_of_category'); - $query_mcat->condition('category_id', $params['maincategory_deleted']['main_category']); - $query_mcat->range(0, 1); - $result_mcat = $query_mcat->execute(); - $main_category_data = $result_mcat->fetchObject(); - $user_data = user_load($params['maincategory_deleted']['user_id']); - $message['headers'] = $params['maincategory_deleted']['headers']; - $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted main category for textbook ' . $preference_data->book, array( - '!site_name' => variable_get('site_name', '') - ), array( - 'language' => $language->language - )); - $message['body'] = array( - 'body' => t(' -Dear !user_name, - -You have deleted the main category with subcategory for following book : - -Title of the book : ' . $preference_data->book . ' -Author : ' . $preference_data->author. ' - -Main category : '. $main_category_data->maincategory .' - -Best Wishes, - -Scilab TBC Team, -FOSSEE, IIT Bombay', array( - '!site_name' => variable_get('site_name', ''), - '!user_name' => $user_data->name - ), array( - 'language' => $language->language - )) - ); - break; - } //$key -} diff --git a/textbook_companion_fixer_settings.inc b/textbook_companion_fixer_settings.inc deleted file mode 100644 index 25af64c..0000000 --- a/textbook_companion_fixer_settings.inc +++ /dev/null @@ -1,58 +0,0 @@ - 'textfield', - '#title' => t('(To) Notification emails'), - '#description' => t('A comma separated list of email addresses to receive notifications emails'), - '#size' => 50, - '#maxlength' => 255, - '#required' => TRUE, - '#default_value' => variable_get('textbook_companion_fixer_to_emails', '') - ); - $form['bcc_emails'] = array( - '#type' => 'textfield', - '#title' => t('(BCc) Notification emails'), - '#description' => t('Specify emails id for BCC option of mail system with comma separated'), - '#size' => 50, - '#maxlength' => 255, - '#required' => TRUE, - '#default_value' => variable_get('textbook_companion_fixer_bcc_emails', '') - ); - $form['cc_emails'] = array( - '#type' => 'textfield', - '#title' => t('(Cc) Notification emails'), - '#description' => t('Specify emails id for CC option of mail system with comma separated'), - '#size' => 50, - '#maxlength' => 255, - '#required' => TRUE, - '#default_value' => variable_get('textbook_companion_fixer_cc_emails', '') - ); - $form['from_email'] = array( - '#type' => 'textfield', - '#title' => t('(From) Outgoing from email address'), - '#description' => t('Email address to be display in the from field of all outgoing messages'), - '#size' => 50, - '#maxlength' => 255, - '#required' => TRUE, - '#default_value' => variable_get('textbook_companion_fixer_from_email', '') - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - return $form; -} -function textbook_companion_fixer_settings_form_validate($form, &$form_state) -{ - return; -} -function textbook_companion_fixer_settings_form_submit($form, &$form_state) -{ - variable_set('textbook_companion_fixer_to_emails', $form_state['values']['to_emails']); - variable_set('textbook_companion_fixer_bcc_emails', $form_state['values']['bcc_emails']); - variable_set('textbook_companion_fixer_cc_emails', $form_state['values']['cc_emails']); - variable_set('textbook_companion_fixer_from_email', $form_state['values']['from_email']); -} -- cgit From 9d7ea3e909c40eec3c078f03c8209ae9b1261c38 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sun, 1 Sep 2019 21:51:58 +0530 Subject: modifed the code for R tbc --- js/r_tbc_fixer.js | 7 +++++-- js/r_tbc_fixer_edit_category.js | 2 +- r_tbc_fixer.info | 1 + r_tbc_fixer.module | 7 ++++--- r_tbc_fixer_edit_book_category.inc | 43 +++++++++++++++++++++++++++++++------- 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/js/r_tbc_fixer.js b/js/r_tbc_fixer.js index dbb20d7..92830b6 100755 --- a/js/r_tbc_fixer.js +++ b/js/r_tbc_fixer.js @@ -1,4 +1,4 @@ -(function($) { + (function($) { $(document).ready(function() { var basePath = Drupal.settings.basePath; var modPath = basePath + "r_tbc_fixer/"; @@ -15,6 +15,7 @@ $done = $("#fix-tbc-page #done"); $example.attr("multiple", "enabled"); + function reset() { for (var i = 0, l = arguments.length; i < l; i++) { switch (arguments[i]) { @@ -45,7 +46,7 @@ $book.change(function() { reset("chapter", "example", "caption"); var book_id = $(this).val(); - if (book_id < 1) { + if (book_id < 0) { $(".select-chapter").hide(); $(".select-example").hide(); $(".enter-caption").hide(); @@ -100,6 +101,7 @@ dataType: "html", success: function(data) { $example.html(data); + $example.attr("size", $("#fix-tbc-form #edit-example option").length); } }); }); @@ -115,6 +117,7 @@ $(".well").hide(); $(".update-button").hide(); } else { + $(".enter-caption").show(); $("#edit-caption").val(example_name); $(".example-code-edit").show(); diff --git a/js/r_tbc_fixer_edit_category.js b/js/r_tbc_fixer_edit_category.js index bad5ec7..b141363 100755 --- a/js/r_tbc_fixer_edit_category.js +++ b/js/r_tbc_fixer_edit_category.js @@ -3,7 +3,7 @@ var basePath = Drupal.settings.basePath; //var modPath = basePath + "textbook_companion_fixer/"; var modPath = basePath + - "textbook_companion_fixer/ajax/edit-book-category/"; + "r_tbc_fixer/ajax/edit-book-category/"; $category_form = $("#fix-tbc-category-form"); $(".main-subcategory-table-div").hide(); diff --git a/r_tbc_fixer.info b/r_tbc_fixer.info index 79b1ac9..b9b857f 100755 --- a/r_tbc_fixer.info +++ b/r_tbc_fixer.info @@ -3,3 +3,4 @@ description = "Module to fix R code bugs" version = "7.1.1" core = "7.x" package = IITB + diff --git a/r_tbc_fixer.module b/r_tbc_fixer.module index b89da85..335c184 100755 --- a/r_tbc_fixer.module +++ b/r_tbc_fixer.module @@ -47,7 +47,7 @@ function r_tbc_fixer_menu() ); // edit book categoery $items["r_tbc_fixer/edit_book_category"] = array( - "title" => "Edit Completed Books Category", + "title" => "Edit Books Category", "page callback" => "r_tbc_fixer_edit_book_proposal_all", "access arguments" => array( "fix R_textbook_category" @@ -243,7 +243,7 @@ function R_fixer_ajax($item, $key) } //$item == "chapter" && $key else if ($item == "example" && $key) { - $result = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.filetype= 'S' AND tcef.example_id= :example_id", array( + $result = db_query("select tcp.directory_name, tce.caption, tcef.filepath from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.filetype= 'S' AND tcef.example_id= :example_id", array( ':example_id' => $key )); $row = $result->fetchObject(); @@ -458,12 +458,13 @@ function r_get_tbc_books(){ $book[0] = "Select any book"; while ($book_list_data = $book_list->fetchObject()) { - $book[$book_list_data->id] .= $book_list_data->book; + $book[$book_list_data->id] .= $book_list_data->book ." (by " .$book_list_data->author. ")"; } return $book; } function r_tbc_fixer_init() { + drupal_add_css(drupal_get_path("module", "r_tbc_fixer") . "/css/r_tbc_fixer.css"); drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer.js"); drupal_add_js(drupal_get_path("module", "r_tbc_fixer") . "/js/r_tbc_fixer_edit_category.js"); diff --git a/r_tbc_fixer_edit_book_category.inc b/r_tbc_fixer_edit_book_category.inc index d25cec5..4d5cb04 100755 --- a/r_tbc_fixer_edit_book_category.inc +++ b/r_tbc_fixer_edit_book_category.inc @@ -2,20 +2,20 @@ function r_tbc_fixer_edit_book_proposal_all() { //get the book count - $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); + $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE pe.approval_status =1 "); $row = $result->fetchObject(); $book_count = $row->book_count; $i = 1; /* get preference */ - $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date, po.proposal_status FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0 ORDER BY pe.book ASC"); + WHERE pe.approval_status = 1 ORDER BY po.proposal_status ASC"); while ($preference_data = $preference_q->fetchObject()) { $proposal_rows[] = array( $i, "{$preference_data->book}
    by {$preference_data->author}", - _r_tbc_fixer_list_of_category($preference_data->existing_category), + get_proposal_status($preference_data->proposal_status), _tbc_fixer_list_of_new_category($preference_data->pref_id), l('Edit', 'r_tbc_fixer/category_edit/' . $preference_data->pref_id) ); @@ -27,12 +27,12 @@ function r_tbc_fixer_edit_book_proposal_all() drupal_set_message(t('There are no proposals.'), 'status'); return ''; } //!$proposal_rows - $output .= "Book count with category: " . $book_count; + $output = "Book count: " . $book_count; $proposal_header = array( 'No.', 'Title of the Book', - 'Existing Category', - 'New Category', + 'Proposal Status', + 'Current Category', 'Action' ); $output .= theme('table', array( @@ -41,6 +41,35 @@ function r_tbc_fixer_edit_book_proposal_all() )); return $output; } + +function get_proposal_status($proposal_value) +{ + $proposal_status = ''; + switch ($proposal_value) { + case 0: + $proposal_status = "Pending"; + break; + case 1: + $proposal_status = "Approved"; + break; + case 2: + $proposal_status = "Dis-approved"; + break; + case 3: + $proposal_status = "Completed"; + break; + case 4: + $proposal_status = "External"; + break; + case 5: + $proposal_status = "Submitted all codes"; + break; + default: + $proposal_status = "Unknown"; + break; + } + return $proposal_status; +} /******************************************************************************/ /**************************** CATEGORY EDIT FORM ******************************/ /******************************************************************************/ -- cgit From d0463962a2ad73c574f4433dc26c3369489c9d5e Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sun, 1 Sep 2019 22:15:54 +0530 Subject: removed md file --- README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index df4788a..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# R_TBC_fixer \ No newline at end of file -- cgit