diff options
author | prashantsinalkar | 2017-05-08 15:17:01 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-05-08 15:17:01 +0530 |
commit | c37080cb2d893cdbf62b46cc35805081164914a7 (patch) | |
tree | a5d99fdd2a7b2a7938cef3a29b136abda409cc28 | |
parent | 9bb4d56b6bd962b453692ceb83274eba8d516e6d (diff) | |
download | textbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.tar.gz textbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.tar.bz2 textbook_companion_fixer-c37080cb2d893cdbf62b46cc35805081164914a7.zip |
added new interface to edit the categories
-rw-r--r-- | js/textbook_companion_fixer_edit_category.js | 206 | ||||
-rwxr-xr-x | textbook_companion_fixer.module | 127 | ||||
-rw-r--r-- | 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("<option value='" + $(this) + .val() + "'>" + $(this).text() + "</option>"); + + /**********************/ + 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("<option value='" + $(this).val() + + "'>" + $(this).text() + "</option>"); + 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 .= "</div>"; 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 .= "<input type='checkbox' name='ids[]' value='".$category_list_data->category_id."' class='main-category-chk-".$category_list_data->category_id."' >".$category_list_data->main_category."<br> - <select class='main-subcategory-".$category_list_data->category_id."'>"._textbook_companion_fixer_list_of_subcategory($category_list_data->category_id)."</select><br><br><hr>"; - } //$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 .= "<option value='0'> Please select a subcategory </option>"; - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory .= "<option value='".$subcategory_list_data->id."' data-name='".$subcategory_list_data->subcategory."'>".$subcategory_list_data->subcategory."</option>"; - } //$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} <br> <em>by {$preference_data->author}</em>", _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' => '<input class="prefrence_id" type="hidden" name="pref_id" value="'.$preference_data->id.'">' + '#markup' => '<input class="prefrence_id" type="hidden" name="pref_id" value="' . $preference_data->id . '">' ); - $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" => "<div class='update-button-category'>", - "#suffix" => "</div>" + $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 .= "<ol>"; + while ($category_list_data = $maincategory_list->fetchObject()) + { + $category .= "<li>$category_list_data->maincategory</li>"; + $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 .= "<ul><li>$sub_category_list_data->subcategory</li></ul>"; + } //$sub_category_list_data = $sub_category_list->fetchObject() + } //$category_list_data = $maincategory_list->fetchObject() + $category .= "</ol>"; + 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 .= "<input id='main_cat_checkbox-" . $category_list_data->category_id . "' type='checkbox' name='ids[]' value='" . $category_list_data->category_id . "' class='main-category-checkbox' " . $checked . " >" . $category_list_data->maincategory . "<br> + <div id ='main-subcategory-table-div-id-" . $category_list_data->category_id . "' class='main-subcategory-table-div'><table id='main-subcategory-table-" . $category_list_data->category_id . "' class='main-subcategory-table'> + <tr> + <th>Available sub categories</th> + <th>Selected sub categories</th> + </tr> + <tr> + <td rowspan='3'><select id='subcats-" . $category_list_data->category_id . "' name='subcats' class='main-subcategory' size='10' multiple name='subcat' data-cid='" . $category_list_data->category_id . "'>" . _textbook_companion_fixer_list_of_subcategory($pref_id, $category_list_data->category_id) . "</select> + <a href='JavaScript:void(0);' id='btn-add' class='select-main-subcategory-" . $category_list_data->category_id . "' data-cid='" . $category_list_data->category_id . "'>Add »</a> + </td> + <td rowspan='3'><a href='JavaScript:void(0);' id='btn-remove' class='select-main-subcategory-" . $category_list_data->category_id . "'data-cid='" . $category_list_data->category_id . "'>« Remove</a> + <select id='selected-subcats-" . $category_list_data->category_id . "' name='subcats' class='select-main-subcategory-list' size='10' multiple name='subcat' data-cid='" . $category_list_data->category_id . "'>" . _tbc_fixer_list_of_ext_new_subcategory($pref_id, $category_list_data->category_id) . "</select> + </td> + </tr> +</table></div> + <hr>"; + } //$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 .= "<option value='" . $subcategory_list_data->subcat_id . "' data-name='" . $subcategory_list_data->sub_category . "' data-mcid='" . $category_id . "'>" . $subcategory_list_data->sub_category . "</option>"; + } //$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 .= "<option value='" . $subcategory_list_data->subcat_id . "' data-name='" . $subcategory_list_data->subcategory . "' data-mcid='" . $category_id . "'>" . $subcategory_list_data->subcategory . "</option>"; + } //$category_list_data = $category_list->fetchObject() + return $subcategory; +} |