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" => ""
+ );
+ 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" => ""
+ );
+ 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 .= "- $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
+ 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 categories |
+ Selected 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" => ""
- );
- 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 .= "- $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
- 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 categories |
- Selected 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