summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2017-01-27 16:12:56 +0530
committerprashantsinalkar2019-09-01 22:13:09 +0530
commit5a104c26ade296722589f61b01ed45fd376b82d3 (patch)
tree3e580a41236ba65d4dc69c0bbf2e4a53c71fcb83
parentc46721c4d1be2c7d12ddd1727fc35dc758157232 (diff)
downloadr_tbc_fixer-5a104c26ade296722589f61b01ed45fd376b82d3.tar.gz
r_tbc_fixer-5a104c26ade296722589f61b01ed45fd376b82d3.tar.bz2
r_tbc_fixer-5a104c26ade296722589f61b01ed45fd376b82d3.zip
added sub category
-rwxr-xr-xtextbook_companion_fixer.module94
-rw-r--r--textbook_companion_fixer_edit_book_category.inc246
2 files changed, 339 insertions, 1 deletions
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 . "<br> <i>by " . $preference_data->author . "</i>",
+ $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' => '<div id="ajax-subcategory-list-replace-'. $category_list_data->category_id.'">',
+ '#suffix' => '</div>',
+ );
+
+ } //$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
+ );
+}
+/*************************************************************************/