From 975937e1e2d45585325cc029864b40f3f7a88ba8 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 24 Jan 2017 17:50:25 +0530 Subject: added page for edit category --- textbook_companion_fixer_edit_book_category.inc | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 textbook_companion_fixer_edit_book_category.inc diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc new file mode 100644 index 0000000..e14114d --- /dev/null +++ b/textbook_companion_fixer_edit_book_category.inc @@ -0,0 +1,52 @@ +0"); + $row = $result->fetchObject(); + $book_count = $row->book_count; + $i=1; + + /* get preference */ + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + while ($preference_data = $preference_q->fetchObject()) + { + $proposal_rows[] = array( + $i, + "{$preference_data->book}
by {$preference_data->author}", + _textbook_companion_fixer_list_of_category($preference_data->existing_category), + '', + '', + l('Edit', 'textbook_companion_fixer/category_edit' . $proposal_data->id) + ); + $i++; + } //$proposal_data = $proposal_q->fetchObject() + /* check if there are any pending proposals */ + if (!$proposal_rows) + { + drupal_set_message(t('There are no proposals.'), 'status'); + return ''; + } //!$proposal_rows + $output .= "Book count with category: " . $book_count; + $proposal_header = array( + 'No.', + 'Title of the Book', + 'Existing Category', + 'New Category', + 'Sub Category', + 'Action' + ); + $output .= theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; +} -- cgit From 9e3b75ccef057b504b1315ed9279d3d46537760d Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Fri, 27 Jan 2017 16:12:56 +0530 Subject: added sub category --- textbook_companion_fixer.module | 94 +++++++++ textbook_companion_fixer_edit_book_category.inc | 246 +++++++++++++++++++++++- 2 files changed, 339 insertions(+), 1 deletion(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 1686c61..199b354 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -78,6 +78,29 @@ function textbook_companion_fixer_menu() 'type' => MENU_NORMAL_ITEM, 'file' => 'textbook_companion_fixer_settings.inc' ); + // edit book categoery + $items["textbook_companion_fixer/edit_book_category"] = array( + "title" => "Edit Completed Books Category", + "page callback" => "textbook_companion_fixer_edit_book_proposal_all", + "access arguments" => array( + "fix scilab_textbook_category" + ), + "type" => MENU_NORMAL_ITEM, + 'file' => 'textbook_companion_fixer_edit_book_category.inc' + ); + $items['textbook_companion_fixer/category_edit'] = array( + 'title' => 'Categorize', + 'description' => 'Edit Completed Books Category', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'textbook_companion_fixer_category_edit_form' + ), + 'access arguments' => array( + 'fix scilab_textbook_category' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'textbook_companion_fixer_edit_book_category.inc' + ); return $items; } function textbook_companion_fixer_permission() @@ -94,6 +117,10 @@ function textbook_companion_fixer_permission() "administer textbook companion fixer settings" => array( "title" => t("administer textbook companion fixer settings"), 'restrict access' => TRUE + ), + "fix scilab_textbook_category" => array( + "title" => t("fix scilab textbook category"), + 'restrict access' => TRUE ) ); } @@ -751,6 +778,73 @@ function _tbc_fixer_list_of_category($category_id = NULL) } //$category_list_data = $category_list->fetchObject() return $category; } +function _textbook_companion_fixer_list_of_category($category_id = NULL) +{ + if ($category_id == NULL ) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category_checkboxes() + + +{ + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + + + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname=$category_list_data->main_category; + if($categoryname!=null||strlen($categoryname)!=0){ + $category[$category_list_data->category_id] = $category_list_data->main_category; + } //$category_list_data = $category_list->fetchObject() +} + return $category; +} +function _textbook_companion_fixer_list_of_subcategory($category_id) +{ + + if ($category_id == NULL) + { + $query = db_select('list_of_subcategory'); + $query->fields('list_of_subcategory'); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_subcategory'); + $query->fields('list_of_subcategory'); + $query->condition('main_category', $category_id); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + } + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $category[$subcategory_list_data->id] = $subcategory_list_data->subcategory; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index e14114d..4cf42c9 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -25,7 +25,7 @@ function textbook_companion_fixer_edit_book_proposal_all() _textbook_companion_fixer_list_of_category($preference_data->existing_category), '', '', - l('Edit', 'textbook_companion_fixer/category_edit' . $proposal_data->id) + l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) ); $i++; } //$proposal_data = $proposal_q->fetchObject() @@ -50,3 +50,247 @@ function textbook_companion_fixer_edit_book_proposal_all() )); return $output; } +/* +function _edit_category_all(){ + // get pending proposals to be approved + $preference_rows = array(); + //$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY id DESC"); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('approval_status', 1); + $query->orderBy('id', 'DESC'); + $preference_q = $query->execute(); + while ($preference_data = $preference_q->fetchObject()) + { + switch ($preference_data->category) + { + case 0: + $category_data = 'Not Selected'; + break; + case 1: + $category_data = 'Fluid Mechanics'; + break; + case 2: + $category_data = 'Control Theory & Control Systems'; + break; + case 3: + $category_data = 'Chemical Engineering'; + break; + case 4: + $category_data = 'Thermodynamics'; + break; + case 5: + $category_data = 'Mechanical Engineering'; + break; + case 6: + $category_data = 'Signal Processing'; + break; + case 7: + $category_data = 'Digital Communications'; + break; + case 8: + $category_data = 'Electrical Technology'; + break; + case 9: + $category_data = 'Mathematics & Pure Science'; + break; + case 10: + $category_data = 'Analog Electronics'; + break; + case 11: + $category_data = 'Digital Electronics'; + break; + case 12: + $category_data = 'Computer Programming'; + break; + case 13: + $category_data = 'Others'; + break; + default: + $category_data = 'Unknown'; + break; + } //$preference_data->category + $preference_rows[] = array( + $preference_data->book . "
by " . $preference_data->author . "", + $preference_data->isbn, + $preference_data->publisher, + $preference_data->edition, + $preference_data->year, + $category_data, + l('Edit', 'manage_proposal/category/edit/' . $preference_data->id) + ); + } //$preference_data = $preference_q->fetchObject() + $preference_header = array( + 'Book', + 'ISBN', + 'Publisher', + 'Edition', + 'Year', + 'Category', + 'Status' + ); + $output = theme('table', array( + 'header' => $preference_header, + 'rows' => $preference_rows + )); + return $output; + +} +*/ +/******************************************************************************/ +/**************************** CATEGORY EDIT FORM ******************************/ +/******************************************************************************/ +function textbook_companion_fixer_category_edit_form($form, &$form_state) +{ + /* get current proposal */ + $preference_id = arg(2); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $preference_q = $query->execute(); + $preference_data = $preference_q->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); + drupal_goto('manage_proposal/category'); + return; + } //!$preference_data + $form['book'] = array( + '#type' => 'item', + '#title' => t('Title of the book'), + '#markup' => $preference_data->book + ); + $form['author'] = array( + '#type' => 'item', + '#title' => t('Author Name'), + '#markup' => $preference_data->author + ); + $form['isbn'] = array( + '#type' => 'item', + '#title' => t('ISBN No'), + '#markup' => $preference_data->isbn + ); + $form['publisher'] = array( + '#type' => 'item', + '#title' => t('Publisher & Place'), + '#markup' => $preference_data->publisher + ); + $form['edition'] = array( + '#type' => 'item', + '#title' => t('Edition'), + '#markup' => $preference_data->edition + ); + $form['year'] = array( + '#type' => 'item', + '#title' => t('Year of pulication'), + '#markup' => $preference_data->year + ); + + + //main_category = _textbook_companion_fixer_list_of_category_checkboxes(); + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + + + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname = $category_list_data->main_category; + if($categoryname!=null||strlen($categoryname)!=0){ + $category[$category_list_data->category_id] = $category_list_data->main_category; + + $form['main_category'.$category_list_data->category_id]= array( + '#type' => 'checkbox', + '#title' => $category_list_data->main_category, + '#ajax' => array( + 'wrapper' => 'ajax-subcategory-list-replace-'. $category_list_data->category_id, + 'callback' => 'ajax_subcategory_list_callback_'.$category_list_data->category_id + ), + ); + $form['main_subcategory_'. $category_list_data->category_id]= array( + '#type' => 'select', + '#options' => $category_list_data->main_category, + '#prefix' => '
', + '#suffix' => '
', + ); + + } //$category_list_data = $category_list->fetchObject() + } + + /* orm['main_category'] = array( + '#type' => 'checkboxes', + '#title' => t('Main category'), + '#options' => $main_category, + '#required' => TRUE + );*/ + + $form['category'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + '#default_value' => $preference_data->category + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') + ); + return $form; +} +function textbook_companion_fixer_category_edit_form_submit($form, &$form_state) +{ + // get current proposal + $preference_id = (int) arg(3); + //preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); + $preference_data = db_fetch_object($preference_q); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $preference_q = $query->execute(); + $preference_data = $preference_q->fetchObject(); + if (!$preference_data) + { + drupal_set_message(t('Invalid book selected. Please try again.'), 'error'); + drupal_goto('textbook_companion_fixer/edit_book_category'); + return; + } //!$preference_data + //db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id); + $query = db_update('textbook_companion_preference'); + $query->fields(array( + 'category' => $form_state['values']['category'] + )); + $query->condition('id', $preference_data->id); + $num_updated = $query->execute(); + drupal_set_message(t('Book Category Updated'), 'status'); + drupal_goto('textbook_companion_fixer/edit_book_category'); +} + + +/********************* Ajax callback ***************************/ +function ajax_subcategory_list_callback_1($form, $form_state) +{ + $category_default_value = 1; + if ($category_default_value > 0) + { + $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory($category_default_value); + $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); + + } //$category_default_value > 0 + else + { + $form['main_subcategory_1']['#options'] = _textbook_companion_fixer_list_of_subcategory(); + $commands[] = ajax_command_replace("#ajax-subcategory-list-replace-1", drupal_render($form['main_subcategory_1'])); + + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +/*************************************************************************/ -- cgit From 6df626312cf0a3719e197e4c2730294bfda4ff95 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 28 Jan 2017 21:38:46 +0530 Subject: added js for edit category --- js/textbook_companion_fixer_edit_category.js | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 js/textbook_companion_fixer_edit_category.js diff --git a/js/textbook_companion_fixer_edit_category.js b/js/textbook_companion_fixer_edit_category.js new file mode 100644 index 0000000..9c2c4f7 --- /dev/null +++ b/js/textbook_companion_fixer_edit_category.js @@ -0,0 +1,84 @@ +(function($) { + $(document).ready(function() { + var basePath = Drupal.settings.basePath; + var modPath = basePath + "textbook_companion_fixer/ajax/edit-book-category/"; + $category_form = $("#fix-tbc-category-form"); + $main_category1 = $(".main-category-1"); + $main_category2 = $(".main-category-2"); + $main_category3 = $(".main-category-3"); + $main_category4 = $(".main-category-4"); + $main_category5 = $(".main-category-5"); + $main_category6 = $(".main-category-6"); + $main_category7 = $(".main-category-7"); + $(".main-subcategory-1").hide(); + $(".main-subcategory-2").hide(); + $(".main-subcategory-3").hide(); + $(".main-subcategory-4").hide(); + $(".main-subcategory-5").hide(); + $(".main-subcategory-6").hide(); + $(".main-subcategory-7").hide(); + prop = $('.main-category-chk-1').prop('checked'); + console.log(prop); + $('.main-category-chk-1').change(function() { + if (!this.checked) { + $('.main-subcategory-1').hide(); + $('.main-subcategory-1').prop('selectedIndex', 0); + } else { + $('.main-subcategory-1').show(); + } + }); + $('.main-category-chk-2').change(function() { + if (!this.checked) { + $('.main-subcategory-2').hide(); + $('.main-subcategory-2').prop('selectedIndex', 0); + } else { + $('.main-subcategory-2').show(); + } + }); + $('.main-category-chk-3').change(function() { + if (!this.checked) { + $('.main-subcategory-3').hide(); + $('.main-subcategory-3').prop('selectedIndex', 0); + } else { + $('.main-subcategory-3').show(); + } + }); + $('.main-category-chk-4').change(function() { + if (!this.checked) { + $('.main-subcategory-4').hide(); + $('.main-subcategory-4').prop('selectedIndex', 0); + } else { + $('.main-subcategory-4').show(); + } + }); + $('.main-category-chk-5').change(function() { + if (!this.checked) { + $('.main-subcategory-5').hide(); + $('.main-subcategory-5').prop('selectedIndex', 0); + } else { + $('.main-subcategory-5').show(); + } + }); + $('.main-category-chk-6').change(function() { + if (!this.checked) { + $('.main-subcategory-6').hide(); + $('.main-subcategory-6').prop('selectedIndex', 0); + } else { + $('.main-subcategory-6').show(); + } + }); + $('.main-category-chk-7').change(function() { + if (!this.checked) { + $('.main-subcategory-7').hide(); + $('.main-subcategory-7').prop('selectedIndex', 0); + } else { + $('.main-subcategory-7').show(); + } + }); + //edit category form submit + $category_form.submit(function(e) { + e.preventDefault(); + }); + + }); +})(jQuery); -- cgit From 75e5048dbbdec6a5f401999cace110c925835787 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Sat, 28 Jan 2017 21:39:43 +0530 Subject: added sub category hide show on checkbox action --- textbook_companion_fixer.module | 58 +++++--- textbook_companion_fixer_edit_book_category.inc | 190 +++--------------------- 2 files changed, 64 insertions(+), 184 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index 199b354..b7a8c3e 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -64,6 +64,11 @@ function textbook_companion_fixer_menu() "access callback" => TRUE, "type" => MENU_CALLBACK ); + $items["textbook_companion_fixer/ajax/edit-book-category"] = array( + "page callback" => "textbook_companion_fixer_edit_book_category_ajax", + "access callback" => TRUE, + "type" => MENU_CALLBACK + ); /* for admin */ $items['admin/settings/textbook_companion_fixer_settings'] = array( 'title' => 'textbook companion fixer Settings', @@ -801,9 +806,32 @@ function _textbook_companion_fixer_list_of_category($category_id = NULL) } //$category_list_data = $category_list->fetchObject() return $category; } -function _textbook_companion_fixer_list_of_category_checkboxes() - +function textbook_companion_fixer_edit_book_category_ajax($item,$key){ + if ($item == "edit_book_category") { + $data .= "Updated"; + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['category_updated']['pref_id'] = $pref_id; + $params['category_updated']['user_id'] = $user->uid; + $params['category_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'category_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } //!drupal_mail('textbook_companion_fixer', 'example_updated', $email_to, language_default(), $params, $from, TRUE) + } +} +function _textbook_companion_fixer_list_of_category_checkboxes() { $query = db_select('list_of_category'); $query->fields('list_of_category'); @@ -816,32 +844,25 @@ function _textbook_companion_fixer_list_of_category_checkboxes() { $categoryname=$category_list_data->main_category; if($categoryname!=null||strlen($categoryname)!=0){ - $category[$category_list_data->category_id] = $category_list_data->main_category; + //$category[$category_list_data->category_id] = $category_list_data->main_category; + + $category .= "".$category_list_data->main_category."
+


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


"; - } //$category_list_data = $category_list->fetchObject() -} - return $category; -} -function _textbook_companion_fixer_list_of_subcategory($category_id) -{ - $query = db_select('list_of_subcategory'); - $query->fields('list_of_subcategory'); - $query->condition('main_category', $category_id); - $query->orderBy('id', 'ASC'); - $subcategory_list = $query->execute(); - $subcategory .= ""; - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory .= ""; - } //$category_list_data = $category_list->fetchObject() - return $subcategory; -} function textbook_companion_fixer_init() { drupal_add_css(drupal_get_path("module", "textbook_companion_fixer") . "/css/textbook_companion_fixer.css"); diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index d7b640b..8efea2a 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -2,25 +2,22 @@ function textbook_companion_fixer_edit_book_proposal_all() { //get the book count - $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); - $row = $result->fetchObject(); - $book_count = $row->book_count; - $i=1; - - /* get preference */ - $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + $row = $result->fetchObject(); + $book_count = $row->book_count; + $i = 1; + /* get preference */ + $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); - while ($preference_data = $preference_q->fetchObject()) + WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + while ($preference_data = $preference_q->fetchObject()) { $proposal_rows[] = array( $i, "{$preference_data->book}
by {$preference_data->author}", _textbook_companion_fixer_list_of_category($preference_data->existing_category), - '', - '', - l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) + _tbc_fixer_list_of_new_category($preference_data->pref_id), + l('Edit', 'textbook_companion_fixer/category_edit/' . $preference_data->pref_id) ); $i++; } //$proposal_data = $proposal_q->fetchObject() @@ -36,7 +33,6 @@ function textbook_companion_fixer_edit_book_proposal_all() 'Title of the Book', 'Existing Category', 'New Category', - 'Sub Category', 'Action' ); $output .= theme('table', array( @@ -100,20 +96,246 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) '#markup' => $preference_data->year ); $form["wrapper"]['pref_id'] = array( - '#markup' => '' + '#markup' => '' ); - $form["wrapper"]['main_category']= array( - "#markup" => _textbook_companion_fixer_list_of_category_checkboxes(), - ); - $form["wrapper"]['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - '#attributes' => array('id' => 'submit-button-category'), - "#prefix" => "
", - "#suffix" => "
" + $form["wrapper"]['main_category'] = array( + "#markup" => _textbook_companion_fixer_list_of_category_checkboxes() ); - $form["wrapper"]['cancel'] = array( - '#markup' => l(t('Cancel'), 'textbook_companion_fixer/edit_book_category') + $form["wrapper"]['back'] = array( + '#markup' => l(t('Back'), 'textbook_companion_fixer/edit_book_category') ); return $form; } +function textbook_companion_fixer_edit_book_category_ajax($item, $key) +{ + $data = ""; + $item = arg(2); + if ($item == "edit-book-category") + { + if ($_POST['action'] == "add") + { + $main_category = $_POST['main_category']; + $sub_category = $_POST['sub_category']; + $query_in1 = " + INSERT INTO {textbook_companion_book_main_subcategories} + (pref_id, main_category, sub_category) + VALUES + (:pref_id, :main_category, :subcategory) + "; + $args_in1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $main_category, + ':subcategory' => $sub_category + ); + $result_in1 = db_query($query_in1, $args_in1); + } //$_POST['action'] == "add" + elseif ($_POST['action'] == "delete") + { + $query_del1 = "DELETE FROM textbook_companion_book_main_subcategories +WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory + "; + $args_del1 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'], + ':subcategory' => $_POST['sub_category'] + ); + $result_del1 = db_query($query_del1, $args_del1); + } //$_POST['action'] == "delete" + elseif ($_POST['action'] == "delete-main-with-ub-category") + { + $query_del2 = "DELETE FROM textbook_companion_book_main_subcategories +WHERE pref_id= :pref_id AND main_category= :main_category + "; + $args_del2 = array( + ':pref_id' => $_POST['pref_id'], + ':main_category' => $_POST['main_category'] + ); + $result_del2 = db_query($query_del2, $args_del2); + } //$_POST['action'] == "delete-main-with-ub-category" + else + { + $data = "Not Updated"; + } + } //$item == "edit-book-category" + else + { + $data = "Not Updated"; + } + echo $data; + exit(); +} +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category($category_id) +{ + $category .= ""; + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('id', $category_id); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $category = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _tbc_fixer_list_of_new_category($pref_id) +{ + $category = ""; + $main_category_query = " + SELECT distinct(maincategory) + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id + "; + $args = array( + ':pref_id' => $pref_id + ); + $maincategory_list = db_query($main_category_query, $args); + $category .= "
    "; + while ($category_list_data = $maincategory_list->fetchObject()) + { + $category .= "
  1. $category_list_data->maincategory
  2. "; + $sub_category_query = " + SELECT DISTINCT (los.subcategory) + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue + "; + $sub_args = array( + ':pref_id' => $pref_id, + ':maincategoryvalue' => $category_list_data->maincategory + ); + $sub_category_list = db_query($sub_category_query, $sub_args); + while ($sub_category_list_data = $sub_category_list->fetchObject()) + { + $category .= ""; + } //$sub_category_list_data = $sub_category_list->fetchObject() + } //$category_list_data = $maincategory_list->fetchObject() + $category .= "
"; + return $category; +} +function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) +{ + $category = ""; + $query = " + SELECT maincategory, los.subcategory as subcategory + FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms + ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $category_list = db_query($query, $args); + while ($category_list_data = $category_list->fetchObject()) + { + $category .= $category_list_data->maincategory; + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_category_checkboxes() +{ + $pref_id = arg(2); + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + //$query->fields(array('category_id','main_category')); + $query->orderBy('category_id', 'ASC'); + $category_list = $query->execute(); + while ($category_list_data = $category_list->fetchObject()) + { + $categoryname = $category_list_data->maincategory; + if ($categoryname != null || strlen($categoryname) != 0) + { + //$category[$category_list_data->category_id] = $category_list_data->main_category; + $existing_category = _tbc_fixer_list_of_ext_new_category($pref_id, $category_list_data->category_id); + $existing_subcategory = _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_list_data->category_id); + $checked = $existing_category ? 'checked="checked"' : ''; + $category .= "" . $category_list_data->maincategory . "
+
+ + + + + + + + +
Available sub categoriesSelected sub categories
+ Add » + « Remove + +
+
"; + } //$category_list_data = $category_list->fetchObject() + } //$category_list_data = $category_list->fetchObject() + return $category; +} +function _textbook_companion_fixer_list_of_subcategory($pref_id, $category_id) +{ + $query = " + SELECT los.subcategory_id as subcat_id,los.subcategory as sub_category + FROM list_of_subcategory los WHERE los.maincategory_id= :category_id AND los.subcategory_id + NOT IN (SELECT los.subcategory_id as sub_id from list_of_subcategory los + LEFT OUTER JOIN textbook_companion_book_main_subcategories tcbms + ON los.subcategory_id=tcbms.sub_category WHERE tcbms.pref_id= :pref_id ORDER BY sub_id) + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$subcategory_list_data = $subcategory_list->fetchObject() + return $subcategory; +} +function _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_id) +{ + $subcategory = ""; + $query = " + SELECT DISTINCT (los.subcategory), maincategory, los.subcategory as subcategory, + los.subcategory_id as subcat_id FROM list_of_category loc + LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id + "; + $args = array( + ':pref_id' => $pref_id, + ':category_id' => $category_id + ); + $subcategory_list = db_query($query, $args); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory .= ""; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} -- cgit From 110d690d29c4c7ebce78827499f988c1fb5afd01 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 11:48:17 +0530 Subject: fixed book count --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 8efea2a..9dc7bc3 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -9,7 +9,7 @@ function textbook_companion_fixer_edit_book_proposal_all() /* get preference */ $preference_q = db_query("SELECT pe.id as pref_id, pe.book as book, pe.author as author,pe.category as existing_category, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id - WHERE po.proposal_status = 3 AND pe.approval_status = 1 ORDER BY pe.book ASC"); + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0 ORDER BY pe.book ASC"); while ($preference_data = $preference_q->fetchObject()) { $proposal_rows[] = array( -- cgit From 2f82a253ad55ecc760b41fdfee8212d535a07e33 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 14:22:33 +0530 Subject: added email notifications for category changes --- textbook_companion_fixer_edit_book_category.inc | 67 ++++++++++- textbook_companion_fixer_email.inc | 141 +++++++++++++++++++++++- 2 files changed, 205 insertions(+), 3 deletions(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 9dc7bc3..531e07a 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -108,14 +108,15 @@ function textbook_companion_fixer_category_edit_form($form, &$form_state) } function textbook_companion_fixer_edit_book_category_ajax($item, $key) { + global $user; $data = ""; $item = arg(2); + $main_category = $_POST['main_category']; + $sub_category = $_POST['sub_category']; if ($item == "edit-book-category") { if ($_POST['action'] == "add") { - $main_category = $_POST['main_category']; - $sub_category = $_POST['sub_category']; $query_in1 = " INSERT INTO {textbook_companion_book_main_subcategories} (pref_id, main_category, sub_category) @@ -128,6 +129,27 @@ function textbook_companion_fixer_edit_book_category_ajax($item, $key) ':subcategory' => $sub_category ); $result_in1 = db_query($query_in1, $args_in1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['category_updated']['pref_id'] = $_POST['pref_id']; + $params['category_updated']['main_category'] = $main_category; + $params['category_updated']['sub_category'] = $sub_category; + $params['category_updated']['user_id'] = $user->uid; + $params['category_updated']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_category_updated', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "add" elseif ($_POST['action'] == "delete") { @@ -140,6 +162,27 @@ WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :su ':subcategory' => $_POST['sub_category'] ); $result_del1 = db_query($query_del1, $args_del1); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['subcategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['subcategory_deleted']['main_category'] = $main_category; + $params['subcategory_deleted']['sub_category'] = $sub_category; + $params['subcategory_deleted']['user_id'] = $user->uid; + $params['subcategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_subcategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "delete" elseif ($_POST['action'] == "delete-main-with-ub-category") { @@ -151,6 +194,26 @@ WHERE pref_id= :pref_id AND main_category= :main_category ':main_category' => $_POST['main_category'] ); $result_del2 = db_query($query_del2, $args_del2); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_fixer_bcc_emails', ''); + $cc = variable_get('textbook_companion_fixer_cc_emails', ''); + $params['maincategory_deleted']['pref_id'] = $_POST['pref_id']; + $params['maincategory_deleted']['main_category'] = $main_category; + $params['maincategory_deleted']['user_id'] = $user->uid; + $params['maincategory_deleted']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('textbook_companion_fixer', 'new_maincategory_deleted', $email_to, language_default(), $params, $from, TRUE)) { + $data .= 'Error sending email message.'; + } } //$_POST['action'] == "delete-main-with-ub-category" else { diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc index 38df00b..0e9117b 100644 --- a/textbook_companion_fixer_email.inc +++ b/textbook_companion_fixer_email.inc @@ -61,7 +61,6 @@ FOSSEE, IIT Bombay', array( ); break; case 'chapter_updated': - $query = db_select('textbook_companion_chapter'); $query->fields('textbook_companion_chapter'); $query->condition('id', $params['chapter_updated']['chapter_id']);; @@ -139,6 +138,146 @@ Example number : ' . $example_data->number . ' Caption : ' . $example_data->caption . ' +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_category_updated': + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['category_updated']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['category_updated']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['category_updated']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['category_updated']['user_id']); + $message['headers'] = $params['category_updated']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have updated category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have updated the category for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_subcategory_deleted': + query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['subcategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['subcategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $query_subcat = db_select('list_of_subcategory'); + $query_subcat->fields('list_of_subcategory'); + $query_subcat->condition('subcategory_id', $params['subcategory_deleted']['sub_category']); + $query_subcat->range(0, 1); + $result_subcat = $query_subcat->execute(); + $sub_category_data = $result_subcat->fetchObject(); + $user_data = user_load($params['subcategory_deleted']['user_id']); + $message['headers'] = $params['subcategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted subcategory for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' +Sub category : '. $sub_category_data->subcategory .' + +Best Wishes, + +Scilab TBC Team, +FOSSEE, IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'new_maincategory_deleted': + query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $params['maincategory_deleted']['pref_id']); + $query->range(0, 1); + $result = $query->execute(); + $preference_data = $result->fetchObject(); + $query_mcat = db_select('list_of_category'); + $query_mcat->fields('list_of_category'); + $query_mcat->condition('category_id', $params['maincategory_deleted']['main_category']); + $query_mcat->range(0, 1); + $result_mcat = $query_mcat->execute(); + $main_category_data = $result_mcat->fetchObject(); + $user_data = user_load($params['maincategory_deleted']['user_id']); + $message['headers'] = $params['maincategory_deleted']['headers']; + $message['subject'] = t('[!site_name][Textbook companion][category] You have deleted main category for textbook ' . $preference_data->book, array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have deleted the main category with subcategory for following book : + +Title of the book : ' . $preference_data->book . ' +Author : ' . $preference_data->author. ' + +Main category : '. $main_category_data->maincategory .' + Best Wishes, Scilab TBC Team, -- cgit From 905dad1e6a77f456544d3575af43daab91ee2f2e Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Tue, 9 May 2017 14:24:35 +0530 Subject: fixed undefined variable issue --- textbook_companion_fixer_email.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/textbook_companion_fixer_email.inc b/textbook_companion_fixer_email.inc index 0e9117b..833e470 100644 --- a/textbook_companion_fixer_email.inc +++ b/textbook_companion_fixer_email.inc @@ -199,7 +199,7 @@ FOSSEE, IIT Bombay', array( ); break; case 'new_subcategory_deleted': - query = db_select('textbook_companion_preference'); + $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $params['subcategory_deleted']['pref_id']); $query->range(0, 1); @@ -248,7 +248,7 @@ FOSSEE, IIT Bombay', array( ); break; case 'new_maincategory_deleted': - query = db_select('textbook_companion_preference'); + $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $params['maincategory_deleted']['pref_id']); $query->range(0, 1); -- cgit From fdce8b8b09ae2b7deb798c2108c60e352ee81404 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Thu, 11 May 2017 10:35:16 +0530 Subject: data fetched in order --- textbook_companion_fixer_edit_book_category.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index 531e07a..a4c421e 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -272,7 +272,7 @@ function _tbc_fixer_list_of_new_category($pref_id) FROM list_of_category loc LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category - WHERE tcbms.pref_id = :pref_id + WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id "; $args = array( ':pref_id' => $pref_id -- cgit From eca558da012c997961a6c576cd865af17374009a Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 22 May 2017 09:56:02 +0530 Subject: added missing function --- textbook_companion_fixer.module | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/textbook_companion_fixer.module b/textbook_companion_fixer.module index d31eac8..e26f2ee 100755 --- a/textbook_companion_fixer.module +++ b/textbook_companion_fixer.module @@ -571,11 +571,11 @@ function scilab_fixer_aicte_form_submit($form, &$form_state) )); $query->condition('id', $v["aicte_id"]); $num_updated = $query->execute(); - drupal_set_message("Book updated successfully", "status"); + drupal_set_message(t('Book updated successfully'), 'status'); } //$v["aicte_id"] else { $query = " - INSERT INTO textbook_companion_aicte + INSERT INTO {textbook_companion_aicte} (book, author, category, isbn, publisher, edition, year) VALUES (:book, :author, :category, :isbn, :publisher, :edition, :year) @@ -590,7 +590,7 @@ function scilab_fixer_aicte_form_submit($form, &$form_state) ':year' => $v["year"] ); $result = db_query($query, $args); - drupal_set_message("Book added successfully", "status"); + drupal_set_message(t('Book added successfully'),'status'); } } function scilab_fixer_aicte_all() @@ -754,6 +754,30 @@ function scilab_fixer_code_form($form, &$form_state) ); return $form; } +function _tbc_fixer_list_of_category($category_id = NULL) +{ + $category[0] = "Please select"; + if ($category_id == NULL) + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } //$category_id == NULL + else + { + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } //$category_list_data = $category_list->fetchObject() + return $category; +} function scilab_fixer_code_all() { $page_content = ""; -- cgit From 493f60e320870df2535759a5f95645323ede1f57 Mon Sep 17 00:00:00 2001 From: prashantsinalkar Date: Mon, 22 May 2017 09:56:37 +0530 Subject: formated th code --- textbook_companion_fixer_edit_book_category.inc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/textbook_companion_fixer_edit_book_category.inc b/textbook_companion_fixer_edit_book_category.inc index a4c421e..9c534a5 100644 --- a/textbook_companion_fixer_edit_book_category.inc +++ b/textbook_companion_fixer_edit_book_category.inc @@ -2,7 +2,7 @@ function textbook_companion_fixer_edit_book_proposal_all() { //get the book count - $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); + $result = db_query("SELECT COUNT( pe.book ) AS book_count FROM {textbook_companion_preference} pe LEFT JOIN {textbook_companion_proposal} po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0"); $row = $result->fetchObject(); $book_count = $row->book_count; $i = 1; @@ -153,7 +153,7 @@ function textbook_companion_fixer_edit_book_category_ajax($item, $key) } //$_POST['action'] == "add" elseif ($_POST['action'] == "delete") { - $query_del1 = "DELETE FROM textbook_companion_book_main_subcategories + $query_del1 = "DELETE FROM {textbook_companion_book_main_subcategories} WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :subcategory "; $args_del1 = array( @@ -186,7 +186,7 @@ WHERE pref_id= :pref_id AND main_category= :main_category AND sub_category = :su } //$_POST['action'] == "delete" elseif ($_POST['action'] == "delete-main-with-ub-category") { - $query_del2 = "DELETE FROM textbook_companion_book_main_subcategories + $query_del2 = "DELETE FROM {textbook_companion_book_main_subcategories} WHERE pref_id= :pref_id AND main_category= :main_category "; $args_del2 = array( @@ -269,9 +269,9 @@ function _tbc_fixer_list_of_new_category($pref_id) $category = ""; $main_category_query = " SELECT distinct(maincategory) - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id ORDER BY loc.category_id "; $args = array( @@ -284,9 +284,9 @@ function _tbc_fixer_list_of_new_category($pref_id) $category .= "
  • $category_list_data->maincategory
  • "; $sub_category_query = " SELECT DISTINCT (los.subcategory) - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id and maincategory = :maincategoryvalue "; $sub_args = array( @@ -307,10 +307,10 @@ function _tbc_fixer_list_of_ext_new_category($pref_id, $category_id) $category = ""; $query = " SELECT maincategory, los.subcategory as subcategory - FROM list_of_category loc - LEFT JOIN textbook_companion_book_main_subcategories tcbms + FROM {list_of_category} loc + LEFT JOIN {textbook_companion_book_main_subcategories} tcbms ON loc.category_id = tcbms.main_category - LEFT JOIN list_of_subcategory los ON los.subcategory_id = tcbms.sub_category + LEFT JOIN {list_of_subcategory} los ON los.subcategory_id = tcbms.sub_category WHERE tcbms.pref_id = :pref_id AND loc.category_id = :category_id "; $args = array( -- cgit