diff options
author | Sashi20 | 2019-08-26 16:26:08 +0530 |
---|---|---|
committer | Sashi20 | 2019-08-26 16:26:08 +0530 |
commit | c4b7c243bf045dab16e62fc5d5990430c0ade608 (patch) | |
tree | 5e7d5b1d9a8a73ca35b45a6457055d30f834e658 | |
parent | 100027ecf8a36eb12052b2772edf16f9bd3f8eed (diff) | |
download | r_textbook_companion-c4b7c243bf045dab16e62fc5d5990430c0ade608.tar.gz r_textbook_companion-c4b7c243bf045dab16e62fc5d5990430c0ade608.tar.bz2 r_textbook_companion-c4b7c243bf045dab16e62fc5d5990430c0ade608.zip |
Add fields to edit main and subcategories for completed books and Download pdf option
-rwxr-xr-x | code_approval.inc | 4 | ||||
-rwxr-xr-x | latex/Initial_body | 10 | ||||
-rwxr-xr-x | latex/latex_test.sh | 13 | ||||
-rwxr-xr-x | manage_proposal.inc | 412 | ||||
-rwxr-xr-x | run.inc | 2 | ||||
-rwxr-xr-x | textbook_companion.module | 998 |
6 files changed, 171 insertions, 1268 deletions
diff --git a/code_approval.inc b/code_approval.inc index 0d06f33..b0da7f3 100755 --- a/code_approval.inc +++ b/code_approval.inc @@ -1210,8 +1210,8 @@ function ajax_bulk_chapter_list_callback($form, $form_state) $book_default_value = $form_state['values']['book']; if ($book_default_value > 0) { $commands[] = ajax_command_html('#ajax_selected_book', l('Download', 'textbook-companion/full-download/book/' . $book_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire book)')); - /*$commands[] = ajax_command_html('#ajax_selected_book_pdf', l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value . '/1') . ' ' . t('(Download PDF of all the approved and unapproved examples of the entire book)')); - $commands[] = ajax_command_html('#ajax_selected_book_regenerate_pdf', l('Regenerate PDF', 'textbook_companion/delete_book/' . $book_default_value) . ' ' . t('(Manually Regenerate PDF of the entire book)'));*/ + $commands[] = ajax_command_html('#ajax_selected_book_pdf', l('Download PDF', 'textbook-companion/generate-book/' . $book_default_value . '/1') . ' ' . t('(Download PDF of all the approved and unapproved examples of the entire book)')); + $commands[] = ajax_command_html('#ajax_selected_book_regenerate_pdf', l('Regenerate PDF', 'textbook_companion/delete_book/' . $book_default_value) . ' ' . t('(Manually Regenerate PDF of the entire book)')); /*$commands[] = ajax_command_html('#ajax_selected_book_notes', l('Notes for Reviewers', 'code_approval/notes/' . $book_default_value));*/ $form['book_actions']['#options'] = _bulk_list_book_actions(); $commands[] = ajax_command_replace('#ajax_selected_book_action', drupal_render($form['book_actions'])); diff --git a/latex/Initial_body b/latex/Initial_body index c0a6b63..571a3af 100755 --- a/latex/Initial_body +++ b/latex/Initial_body @@ -7,7 +7,7 @@ \bibliographystyle{plain} -\lstset{ %configuring the display of scilab codes +\lstset{ %configuring the display of R codes tabsize=4, language=R, basicstyle=\ttfamily, @@ -25,7 +25,7 @@ % code environment -{\theorembodyfont{\rmfamily} \newtheorem{codemass}{Scilab code}[chapter]} +{\theorembodyfont{\rmfamily} \newtheorem{codemass}{R code}[chapter]} \newenvironment{code}% {\begin{codemass}}{\hrule \end{codemass}} @@ -39,10 +39,10 @@ \newcommand\tcaption[1] {\addcontentsline{cod}{section}{\protect\numberline {\thecodemass}#1}} \makeatletter \newcommand\listofcode - {\chapter*{List of Scilab Codes\markboth% - {\bf List of Scilab Codes}{}}% + {\chapter*{List of R Codes\markboth% + {\bf List of R Codes}{}}% \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{5em}}% -\addcontentsline{toc}{chapter}{\protect\numberline{List of Scilab Codes}} +\addcontentsline{toc}{chapter}{\protect\numberline{List of R Codes}} \@starttoc{cod}} \newcommand\l@matlab[3] {#1 \par\noindent#2, #3 \par} diff --git a/latex/latex_test.sh b/latex/latex_test.sh index ebd71eb..4e88d63 100755 --- a/latex/latex_test.sh +++ b/latex/latex_test.sh @@ -41,7 +41,7 @@ colB4=${colB4/&/\\&}; colB5=${colB5/&/\\&}; colB6=${colB6/&/\\&}; colB7=${colB7/&/\\&}; -echo \\title\{Scilab Textbook Companion \for "\\\\"$colB1"\\\\"by $colB2"\\footnote{Funded by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and Scilab codes written in it can be downloaded from the \"Textbook Companion Project\" section at the website http://scilab.in}}" >>$CURDIR/TEX +echo \\title\{R Textbook Companion \for "\\\\"$colB1"\\\\"by $colB2"\\footnote{Funded by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Textbook Companion and R codes written in it can be downloaded from the \"Textbook Companion Project\" section at the website http://R.in}}" >>$CURDIR/TEX echo \\author\{ Created by \\\\$col1\\\\$col2\\\\$col3\\\\$col4\\\\ College Teacher\\\\$col5\\\\Cross\-Checked by \\\\$col6\\\\$col8}>>$CURDIR/TEX @@ -66,13 +66,13 @@ echo >> $CURDIR/TEX echo \\newpage >> $CURDIR/TEX echo \\vspace*{3cm}>>$CURDIR/TEX -echo Scilab numbering policy used in this document and the relation to the above book.>>$CURDIR/TEX +echo R numbering policy used in this document and the relation to the above book.>>$CURDIR/TEX echo \\begin{description}>>$CURDIR/TEX echo \\item[Exa] Example \(Solved example\)>>$CURDIR/TEX echo \\item[Eqn] Equation \(Particular equation of the above book\)>>$CURDIR/TEX -echo \\item[AP] Appendix to Example\(Scilab Code that is an Appednix to a particular Example of the above book\)>>$CURDIR/TEX +echo \\item[AP] Appendix to Example\(R Code that is an Appednix to a particular Example of the above book\)>>$CURDIR/TEX echo \\end{description}>>$CURDIR/TEX -echo "For example, Exa~3.51 means solved example 3.51 of this book. Sec~2.3 means a scilab code whose theory is explained in Section 2.3 of the book.">>$CURDIR/TEX +echo "For example, Exa~3.51 means solved example 3.51 of this book. Sec~2.3 means a R code whose theory is explained in Section 2.3 of the book.">>$CURDIR/TEX echo>>$CURDIR/TEX echo \\tableofcontents >>$CURDIR/TEX @@ -132,7 +132,7 @@ fi if [ $col7 = X ] then -echo This code can be downloaded from the website wwww.scilab.in >> $CURDIR/TEX +echo This code can be downloaded from the website wwww.R.in >> $CURDIR/TEX fi if [ $col7 = R ] @@ -154,7 +154,6 @@ j=$col1 done < database_sort #rm Figure_files - if [ -s $Dep_dat ] then @@ -173,7 +172,7 @@ echo >> $CURDIR/TEX let "i+=1" done < $Dep_dat -fi +fi cat Initial_body TEX > TEX_final.tex echo \\end{document} >> $CURDIR/TEX_final.tex diff --git a/manage_proposal.inc b/manage_proposal.inc index 47d9e52..2678194 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -140,7 +140,6 @@ function _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); @@ -152,43 +151,31 @@ function _category_all() $category_data = 'Not Selected'; break; case 1: - $category_data = 'Fluid Mechanics'; + $category_data = 'Statistics'; break; case 2: - $category_data = 'Control Theory & Control Systems'; + $category_data = 'Engineering'; break; case 3: - $category_data = 'Chemical Engineering'; + $category_data = 'Business Management'; break; case 4: - $category_data = 'Thermodynamics'; + $category_data = 'Economics'; break; case 5: - $category_data = 'Mechanical Engineering'; + $category_data = 'Psychology'; break; case 6: - $category_data = 'Signal Processing'; + $category_data = 'Business Statistics'; break; case 7: - $category_data = 'Digital Communications'; + $category_data = 'Medical'; break; case 8: - $category_data = 'Electrical Technology'; + $category_data = 'Bio Science'; 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'; + $category_data = 'Mathematics'; break; default: $category_data = 'Unknown'; @@ -469,22 +456,6 @@ function proposal_approval_form_submit($form, &$form_state) )); $query->condition('proposal_id', $proposal_id); $num_updated = $query->execute(); - /* unlock all the aicte books */ - /*$query = " - UPDATE textbook_companion_aicte - SET status = 0, uid = 0, proposal_id = 0, preference_id = 0 - WHERE proposal_id = {$proposal_id} - "; - db_query($query);*/ - /*$query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'status' => 0, - 'uid' => 0, - 'proposal_id' => 0, - 'preference_id' => 0, - )); - $query->condition('proposal_id', $proposal_id); - $num_updated = $query->execute();*/ /* sending email */ $book_user = user_load($row->uid); $email_to = $book_user->mail; @@ -885,7 +856,7 @@ function proposal_status_form_submit($form, &$form_state) /******************************************************************************/ /**************************** PROPOSAL EDIT FORM ******************************/ /******************************************************************************/ -function proposal_edit_form($form, &$form_state, $nonaicte_book) +function proposal_edit_form($form, &$form_state) { global $user; /* get current proposal */ @@ -895,21 +866,19 @@ function proposal_edit_form($form, &$form_state, $nonaicte_book) $query->fields('textbook_companion_proposal'); $query->condition('id', $proposal_id); $proposal_q = $query->execute(); - if ($proposal_q) { - $proposal_data = $proposal_q->fetchObject(); - if (!$proposal_data) { + $proposal_data = $proposal_q->fetchObject(); + /*if (!$proposal_data) { drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); - drupal_goto('textbook-companion/manage-proposal'); + //drupal_goto('textbook-companion/manage-proposal'); return; } - } else { - drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); - drupal_goto('textbook-companion/manage-proposal'); - return; - } + else { + //drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + //drupal_goto('textbook-companion/manage-proposal'); + // return; + }*/ $user_data = user_load($proposal_data->uid); - /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1); - $preference1_data = db_fetch_object($preference1_q);*/ + // var_dump($user_data->mail);die; $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -917,23 +886,9 @@ function proposal_edit_form($form, &$form_state, $nonaicte_book) $query->range(0, 1); $preference1_q = $query->execute(); $preference1_data = $preference1_q->fetchObject(); - /********************************************************************/ - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('proposal_id', $proposal_id); - $query->condition('pref_number', 2); - $query->range(0, 1); - $preference2_q = $query->execute(); - $preference2_data = $preference2_q->fetchObject(); - /**************************************************************************/ - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('proposal_id', $proposal_id); - $query->condition('pref_number', 3); - $query->range(0, 1); - $preference3_q = $query->execute(); - $preference3_data = $preference3_q->fetchObject(); - /*************************************************************************/ + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); $form['name_title'] = array( '#type' => 'select', '#title' => t('Title'), @@ -1207,135 +1162,46 @@ function proposal_edit_form($form, &$form_state, $nonaicte_book) '#required' => TRUE, '#default_value' => $preference1_data->year ); - if ($preference2_data) { - $form['preference2'] = array( - '#type' => 'fieldset', - '#title' => t('Book Preference 2'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $form['preference2']['book2'] = array( - '#type' => 'textfield', - '#title' => t('Title of the book'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - '#default_value' => $preference2_data->book - ); - $form['preference2']['author2'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - '#default_value' => $preference2_data->author - ); - $form['preference2']['isbn2'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - '#default_value' => $preference2_data->isbn - ); - $form['preference2']['publisher2'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - '#default_value' => $preference2_data->publisher - ); - $form['preference2']['edition2'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - '#default_value' => $preference2_data->edition - ); - $form['preference2']['year2'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - '#default_value' => $preference2_data->year - ); - } - if ($preference3_data) { - $form['preference3'] = array( - '#type' => 'fieldset', - '#title' => t('Book Preference 3'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $form['preference3']['book3'] = array( - '#type' => 'textfield', - '#title' => t('Title of the book'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - '#default_value' => $preference3_data->book - ); - $form['preference3']['author3'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - '#default_value' => $preference3_data->author - ); - $form['preference3']['isbn3'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - '#default_value' => $preference3_data->isbn - ); - $form['preference3']['publisher3'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - '#default_value' => $preference3_data->publisher - ); - $form['preference3']['edition3'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - '#default_value' => $preference3_data->edition - ); - $form['preference3']['year3'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - '#default_value' => $preference3_data->year - ); - } - /* hidden fields */ $form['hidden_preference_id1'] = array( '#type' => 'hidden', - '#value' => $preference1_data->id - ); - /* $form['hidden_preference_id2'] = array( - '#type' => 'hidden', - '#value' => $preference2_data->id + '#default_value' => $preference1_data->id ); - $form['hidden_preference_id3'] = array( - '#type' => 'hidden', - '#value' => $preference3_data->id - );*/ + //var_dump($proposal_id);die; $form['hidden_proposal_id'] = array( '#type' => 'hidden', - '#value' => $proposal_id + '#default_value' => $proposal_id + ); + //var_dump($preference1_data->category);die; + $form['main_category'] = array( + '#type' => 'select', + '#title' => t('Select the main category'), + '#default_value' => $preference1_data->category, + '#options' => _tbc_list_of_main_categories(), + '#tree' => TRUE, + '#ajax' => array( + 'callback' => 'ajax_subcategory_list_callback', + 'wrapper' => 'ajax-subcategory-list-replace', + // 'method' => 'replace', + ), + ); + $main_category = isset($form_state['values']['main_category']) ? $form_state['values']['main_category'] : $preference1_data->category; + $form['subcategory'] = array( + '#type' => 'select', + '#title' => 'List of subcategory', + '#prefix' => '<div id="ajax-subcategory-list-replace">', + '#suffix' => '</div>', + '#options' => _tbc_list_of_subcategories($main_category), + '#multiple' => TRUE, + '#default_value' => default_value_for_selections($preference1_data->id), + '#states' => array( + 'invisible' => array( + ':input[name="main_category"]' => array( + 'value' => 0 + ) + ) + ) ); + /* hidden fields */ $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') @@ -1346,6 +1212,11 @@ function proposal_edit_form($form, &$form_state, $nonaicte_book) ); return $form; } +function ajax_subcategory_list_callback($form, &$form_state) +{ + return $form['subcategory']; +} + function proposal_edit_form_validate($form, &$form_state) { if ($form_state['values']['book1'] && $form_state['values']['author1']) { @@ -1355,26 +1226,6 @@ function proposal_edit_form_validate($form, &$form_state) $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']); } } - /*if ($form_state['values']['book2'] && $form_state['values']['author2']) - { - $bk2 = trim($form_state['values']['book2']); - $auth2 = trim($form_state['values']['author2']); - - if (_dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']) != NULL) - { - $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']); - } - } - if ($form_state['values']['book3'] && $form_state['values']['author3']) - { - $bk3 = trim($form_state['values']['book3']); - $auth3 = trim($form_state['values']['author3']); - - if (_dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']) != NULL) - { - $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']); - } - } /* mobile */ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) form_set_error('mobile', t('Invalid mobile number')); @@ -1407,6 +1258,11 @@ function proposal_edit_form_validate($form, &$form_state) form_set_error('older', t('Please provide valid version')); } } + if ($form_state['values']['subcategory']) + { + $subcategory = implode("| ", $_POST['subcategory']); + $form_state['values']['subcategory'] = trim($subcategory); + } return; } function proposal_edit_form_submit($form, &$form_state) @@ -1462,83 +1318,70 @@ function proposal_edit_form_submit($form, &$form_state) 'publisher' => $form_state['values']['publisher1'], 'edition' => $form_state['values']['edition1'], 'year' => $form_state['values']['year1'], + 'category' => $form_state['values']['main_category'], + 'subcategory' => $form_state['values']['subcategory'], 'directory_name' => $form_state['values']['dir_name1'] )); $query->condition('id', $preference1_id); $num_updated = $query->execute(); } - /**************************************************************/ - /**$query = db_select('textbook_companion_preference'); + drupal_set_message(t('Proposal Updated'), 'status'); +} +function default_value_for_selections($id) +{ + $subcategory_list_data = new stdClass(); + $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); - $query->condition('proposal_id', $proposal_id); - $query->condition('pref_number', 2); - $query->range(0, 1); - $preference2_q = $query->execute(); - $preference2_data = $preference2_q->fetchObject(); - $preference2_id = $preference2_data->id; - if ($preference2_data) + $query->condition('id', $id); + $default_subcategory = $query->execute()->fetchObject(); + $subcategory = array(); + $subcategory_value = explode('| ', $default_subcategory->subcategory); + $subcategory_list = 0; + foreach ($subcategory_value as $subcategory_list_data->$subcategory_list) { - del_book_pdf($preference2_data->id); - RenameDir($preference2_id, $form_state['values']['dir_name2']); - $query = db_update('textbook_companion_preference'); - $query->fields(array( - 'book' => $form_state['values']['book2'], - 'author' => $form_state['values']['author2'], - 'isbn' => $form_state['values']['isbn2'], - 'publisher' => $form_state['values']['publisher2'], - 'edition' => $form_state['values']['edition2'], - 'year' => $form_state['values']['year2'], - 'directory_name' => $form_state['values']['dir_name2'] - )); - $query->condition('id', $preference2_id); - $num_updated = $query->execute(); - } - /*****************************************************************/ - /**$query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('proposal_id', $proposal_id); - $query->condition('pref_number', 3); - $query->range(0, 1); - $preference3_q = $query->execute(); - $preference3_data = $preference3_q->fetchObject(); - $preference3_id = $preference3_data->id; - if ($preference3_data) + $query = db_select('tbc_subcategory'); + $query->fields('tbc_subcategory'); + $query->condition('id', $subcategory_value); + //$query->orderBy('id', 'ASC'); + $subcategory_list_1 = $query->execute(); + while ($subcategory_list_data_1 = $subcategory_list_1->fetchObject()) { - del_book_pdf($preference3_data->id); - RenameDir($preference3_id, $form_state['values']['dir_name3']); - $query = db_update('textbook_companion_preference'); - $query->fields(array( - 'book' => $form_state['values']['book3'], - 'author' => $form_state['values']['author3'], - 'isbn' => $form_state['values']['isbn3'], - 'publisher' => $form_state['values']['publisher3'], - 'edition' => $form_state['values']['edition3'], - 'year' => $form_state['values']['year3'], - 'directory_name' => $form_state['values']['dir_name3'] - )); - $query->condition('id', $preference3_id); - $num_updated = $query->execute(); - }**/ - drupal_set_message(t('Proposal Updated'), 'status'); + $subcategory[$subcategory_list_data_1->id] = $subcategory_list_data_1->id; + $subcategory_list++; + } + } + //var_dump($subcategory);die; + return $subcategory; } /******************************************************************************/ /**************************** CATEGORY EDIT FORM ******************************/ /******************************************************************************/ -function category_edit_form($from, $form_state) +/*function category_edit_form($form, &$form_state) { - /* get current proposal */ - $preference_id = arg(3); - /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); - $preference_data = db_fetch_object($preference_q);*/ + /* get current proposal + $preference_id = arg(4); $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $preference_id); - $result = $query->execute(); + $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/manage-proposal/category'); return; } + if ($preference_id) + { + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $preference_id); + $result = $query->execute()->fetchObject(); + $category_default_value = $result->category; + } //$url_book_pref_id + else + { + $category_default_value = 0; + } $form['book'] = array( '#type' => 'item', '#title' => t('Title of the book'), @@ -1572,9 +1415,16 @@ function category_edit_form($from, $form_state) $form['category'] = array( '#type' => 'select', '#title' => t('Category'), - '#options' => _tbc_list_of_categories(), + '#options' => _tbc_list_of_main_categories(), '#required' => TRUE, - '#default_value' => $preference_data->category + '#default_value' => $category_default_value, + ); + // $maincategory_value = isset($form_state['values']['category']) ? $form_state['values']['category'] : ''; + $form['subcategory'] = array( + '#type' => 'select', + '#title' => 'List of subcategory', + '#options' => _tbc_list_of_subcategories($category_default_value), + // '#default_value' => isset($form_state['values']['category']) ? $form_state['values']['category'] : '', ); $form['submit'] = array( '#type' => 'submit', @@ -1586,12 +1436,28 @@ function category_edit_form($from, $form_state) ); return $form; } + +function _tbc_list_of_subcategories($maincategory_id) +{ + $subcategory = array(); + $query = db_select('tbc_subcategory'); + $query->fields('tbc_subcategory'); + $query->condition('maincategory_id', $maincategory_id); + $query->orderBy('id', 'ASC'); + $subcategory_list = $query->execute(); + while ($subcategory_list_data = $subcategory_list->fetchObject()) + { + $subcategory[$subcategory_list_data->id] = $subcategory_list_data->subcategory_name; + } //$software_version_list_data = $software_version_list->fetchObject() + return $subcategory; +} function category_edit_form_submit($form, &$form_state) { - /* get current proposal */ - $preference_id = (int) arg(3); + /* get current proposal + + $preference_id = (int) arg(4); /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); - $preference_data = db_fetch_object($preference_q);*/ + $preference_data = db_fetch_object($preference_q); $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $preference_id); @@ -1602,7 +1468,7 @@ function category_edit_form_submit($form, &$form_state) drupal_goto('textbook-companion/manage-proposal/category'); return; } - /*db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id);*/ + /*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'] @@ -1942,4 +1808,4 @@ function RenameDir($preference_id, $dir_name) return; } return; -} +}
\ No newline at end of file @@ -260,7 +260,7 @@ function ajax_chapter_list_callback($form, $form_state) } else { $commands[] = ajax_command_html("#ajax-download-freeeda-book-replace", ''); } -// $commands[] = ajax_command_html("#ajax-download-book-pdf-replace", l('Download PDF', 'textbook-companion/generate-book/' . $book_list_default_value) . ' ' . t('(Download the PDF file containing R codes for all the solved examples)')); + $commands[] = ajax_command_html("#ajax-download-book-pdf-replace", l('Download PDF', 'textbook-companion/generate-book/' . $book_list_default_value) . ' ' . t('(Download the PDF file containing R codes for all the solved examples)')); $commands[] = ajax_command_replace("#ajax-chapter-list-replace", drupal_render($form['chapter'])); $commands[] = ajax_command_html("#ajax-example-list-replace", ''); $commands[] = ajax_command_html("#ajax-download-example-code-replace", ''); diff --git a/textbook_companion.module b/textbook_companion.module index b7b29d0..638ac7a 100755 --- a/textbook_companion.module +++ b/textbook_companion.module @@ -67,7 +67,7 @@ function textbook_companion_menu() 'weight' => 2, 'file' => 'manage_proposal.inc' ); - /*$items['manage_proposal/category'] = array( + /*$items['textbook-companion/manage-proposal/category'] = array( 'title' => 'Categorize', 'description' => 'Categorize Books', 'page callback' => '_category_all', @@ -128,7 +128,7 @@ function textbook_companion_menu() 'type' => MENU_CALLBACK, 'file' => 'manage_proposal.inc' ); - /*$items['manage_proposal/category/edit'] = array( + /*$items['textbook-companion/manage-proposal/category/edit'] = array( 'title' => 'Edit Category', 'description' => 'Edit category', 'page callback' => 'drupal_get_form', @@ -845,183 +845,6 @@ function textbook_companion_permission() ) ); } -/* Aicte books pickup before the proposal form */ -/*function textbook_companion_aicte_proposal_form($form_state) { -/* $query = " -SELECT * FROM textbook_companion_aicte -WHERE status = 0 AND selected = 0 -"; -$result = db_query($query);*/ -/* $query = " -SELECT * FROM textbook_companion_aicte -WHERE status = :status AND selected = :selected -"; -$args = array( -':status' => 0, -':selected' => 0, -); -$result = db_query($query,$args); */ -/* $query = db_select('textbook_companion_aicte'); -$query->fields('textbook_companion_aicte'); -$query->condition('status', 0); -$query->condition('selected', 0); -$result = $query->execute(); - -$form = array(); -$form["wrapper"] = array( -"#type" => "fieldset", -"#prefix" => "<div id='aicte-form-wrapper'>", -"#suffix" => "</div>", -); -// $num_rows = mysql_num_rows($result); -$num_rows = $query->countQuery(); -if ($num_rows > 0) { -while($row = $result->fetchObject()) { -/* fixing title string */ -/* $title = ""; -$edition = ""; -$year = ""; -$title = "{$row->book} by {$row->author}"; -if($row->edition) { -$edition = "<i>ed</i>: {$row->edition}"; -} -if($row->year) { -if($row->edition) { -$year = ", <i>pub</i>: {$row->year}"; -} else { -$year = "<i>pub</i>: {$row->year}"; -} -} -if($edition or $year) { -$title .= "({$edition} {$year})"; -} -$form["wrapper"][$row->id] = array( -"#type" => "checkbox", -"#title" => $title, -"#prefix" => "<div class='title'>", -"#suffix" => "</div>", -); -} -} -$form["submit"] = array( -"#type" => "submit", -"#value" => "Submit Book Selections" -); -return $form; -}*/ -/*function textbook_companion_aicte_proposal_form_validate($form, &$form_state) { -/*$query = " -SELECT * FROM textbook_companion_aicte -WHERE status = 0 AND selected = 0 -"; -$result = db_query($query);*/ -/*$query = db_select('textbook_companion_aicte'); -$query->fields('textbook_companion_aicte'); -$query->condition('status', 0); -$query->condition('selected', 0); -$result = $query->execute(); - -$count = 0; -$selections = array(); -while($row = $result->fetchObject()) { -if($form_state["values"][$row->id] == 1) { -$count++; -array_push($selections, $row->id); -} -} -/* user can choose only 3 books to propose */ -/* if($count != 3) { -form_set_error("", "Please select exactly <strong>3</strong> books. You currently selected <strong>{$count}</strong>"); -} else { -$form_state["values"]["selections"] = $selections; -} -}*/ -/*function textbook_companion_aicte_proposal_form_submit($form, &$form_state) { -global $user; -$selections = $form_state["values"]["selections"]; -var_dump($selections); -variable_set("aicte_".$user->uid, $selections); -drupal_goto("proposal"); -}*/ -/*function textbook_companion_aicte_report_form($form_state) { -/*$query = " -SELECT * FROM textbook_companion_aicte -WHERE status = 0 -ORDER BY book -"; -$result = db_query($query);*/ -/*$query = db_select('textbook_companion_aicte'); -$query->fields('textbook_companion_aicte'); -$query->condition('status', 0); -$query->orderBy('book', 'ASC'); -$result = $query->execute(); - -$books = array(); -$books[0] = "Please select a book"; -while($row = $result->fetchObject()) { -$books[$row->id] = "{$row->book} ({$row->author})"; -} -$form = array(); -$form["name"] = array( -"#type" => "textfield", -"#title" => "Name", -"#description" => t("Please enter your name."), -); -$form["email"] = array( -"#type" => "textfield", -"#title" => "Email", -"#description" => t("Please enter your valid email id."), -); -$form["number"] = array( -"#type" => "textfield", -"#title" => "Number", -"#description" => t("Please enter your valid phone number."), -); -$form["book"] = array( -"#type" => "select", -"#title" => "AICTE Book", -"#description" => t("Please select a book."), -"#options" => $books -); -$form["comment"] = array( -"#type" => "textarea", -"#title" => "Any other comment?", -"#description" => t("Please enter your query (if any)") -); -$form["submit"] = array( -"#type" => "submit", -"#value" => "Submit" -); -return $form; -} -*/ -/*function textbook_companion_aicte_report_form_submit($form, &$form_state) { -$v = $form_state["values"]; - -/*$query = " -INSERT INTO textbook_companion_aicte_report -(aicte_id, name, number, email, comment) -VALUES -(%d, '%s', '%s', '%s', '%s') -"; -$result = db_query($query, -$v["book"], $v["name"], $v["number"], $v["email"], $v["comment"] -);*/ -/*$query = "INSERT INTO textbook_companion_aicte_report -(aicte_id, name, number, email, comment) -VALUES (:aicte_id, :name, :number, :email, :comment)"; -$args = array( -":aicte_id" => $v["book"], -":name" => $v["name"], -":number" => $v["number"], -":email" =>$v["email"], -":comment" => $v["comment"] -); -$result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); - -drupal_set_message("Thank you for reporting.", "status"); -} -*/ function textbook_companion_aicte_proposal_all() { global $user; @@ -1244,510 +1067,6 @@ function textbook_companion_proposal_all() // drupal_goto("aicte_proposal"); return $page_content; } -/*function book_proposal_form($form, $form_state) -{ -global $user; -$form = array(); -$form['imp_notice'] = array( -'#type' => 'item', -'#markup' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion</b></font>' -); -$form['full_name'] = array( -'#type' => 'textfield', -'#title' => t('Full Name'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -); -$form['email_id'] = array( -'#type' => 'textfield', -'#title' => t('Email'), -'#size' => 30, -'#value' => $user->mail, -'#disabled' => TRUE -); -$form['mobile'] = array( -'#type' => 'textfield', -'#title' => t('Mobile No.'), -'#size' => 30, -'#maxlength' => 15, -'#required' => TRUE -); -$form['gender'] = array( -'#type' => 'radios', -'#title' => t('Gender'), -'#options' => array( -'M' => 'Male', -'F' => 'Female' -), -'#required' => TRUE -); -$form['how_project'] = array( -'#type' => 'select', -'#title' => t('How did you come to know about this project'), -'#options' => array( -'r Website' => 'r Website', -'Friend' => 'Friend', -'Professor/Teacher' => 'Professor/Teacher', -'Mailing List' => 'Mailing List', -'Poster in my/other college' => 'Poster in my/other college', -'Others' => 'Others' -), -'#required' => TRUE -); -$form['course'] = array( -'#type' => 'textfield', -'#title' => t('Course'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -); -$form['branch'] = array( -'#type' => 'select', -'#title' => t('Department/Branch'), -'#options' => _list_of_departments(), -'#required' => TRUE -); -$form['university'] = array( -'#type' => 'textfield', -'#title' => t('University/ Institute'), -'#size' => 80, -'#maxlength' => 200, -'#required' => TRUE, -'#attributes' => array( -'placeholder' => 'Insert full name of your institute/ university.... ' -) -); -$form['country'] = array( -'#type' => 'select', -'#title' => t('Country'), -'#options' => array( -'India' => 'India', -'Others' => 'Others' -), -'#required' => TRUE, -'#tree' => TRUE, -'#validated' => TRUE -); -$form['other_country'] = array( -'#type' => 'textfield', -'#title' => t('Other than India'), -'#size' => 100, -'#attributes' => array( -'placeholder' => t('Enter your country name') -), -'#states' => array( -'visible' => array( -':input[name="country"]' => array( -'value' => 'Others' -) -) -) -); -$form['other_state'] = array( -'#type' => 'textfield', -'#title' => t('State other than India'), -'#size' => 100, -'#attributes' => array( -'placeholder' => t('Enter your state/region name') -), -'#states' => array( -'visible' => array( -':input[name="country"]' => array( -'value' => 'Others' -) -) -) -); -$form['other_city'] = array( -'#type' => 'textfield', -'#title' => t('City other than India'), -'#size' => 100, -'#attributes' => array( -'placeholder' => t('Enter your city name') -), -'#states' => array( -'visible' => array( -':input[name="country"]' => array( -'value' => 'Others' -) -) -) -); -$form['all_state'] = array( -'#type' => 'select', -'#title' => t('State'), -'#selected' => array( -'' => '-select-' -), -'#options' => _list_of_states(), -'#validated' => TRUE, -'#states' => array( -'visible' => array( -':input[name="country"]' => array( -'value' => 'India' -) -) -) -); -$form['city'] = array( -'#type' => 'select', -'#title' => t('City'), -'#options' => _list_of_cities(), -'#states' => array( -'visible' => array( -':input[name="country"]' => array( -'value' => 'India' -) -) -) -); -$form['pincode'] = array( -'#type' => 'textfield', -'#title' => t('Pincode'), -'#size' => 30, -'#maxlength' => 6, -'#required' => False, -'#attributes' => array( -'placeholder' => 'Enter pincode....' -) -); -/***************************************************************************/ -/* $form['hr'] = array( -'#type' => 'item', -'#markup' => '<hr>' -); -$form['faculty'] = array( -'#type' => 'hidden', -'#value' => 'None', -'#title' => t('College Teacher/Professor'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -); -$form['faculty_email'] = array( -'#type' => 'hidden', -'#value' => 'None', -'#title' => t('Teacher/Professor Email Id'), -'#value' => '@email.com', -'#size' => 30, -'#maxlength' => 50 -); -$form['reviewer'] = array( -'#type' => 'hidden', -'#value' => 'None', -'#title' => t('Reviewer'), -'#size' => 30, -'#maxlength' => 50 -); - -$form['version'] = array( -'#type' => 'select', -'#title' => t('Version'), -'#options' => _list_of_software_version(), -'#required' => TRUE -); -$form['other_version'] = array( -'#type' => 'textfield', -'#size' => 30, -'#maxlength' => 50, -//'#required' => TRUE, -'#description' => t('Specify the Older version used'), -'#states' => array( -'visible' => array( -':input[name="version"]' => array( -'value' => 'Other version' -) -) -) -); -$form['completion_date'] = array( -'#type' => 'textfield', -'#title' => t('Expected Date of Completion'), -'#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'), -'#size' => 10, -'#maxlength' => 10 -); -$form['operating_system'] = array( -'#type' => 'textfield', -'#title' => t('Operating System'), -'#required' => TRUE, -'#size' => 30, -'#maxlength' => 50 -); -$reason = array( -'Used in more than one University' => t('Used in more than one University'), -'The book has multiple editions' => t('The book has multiple editions'), -'Extremely useful' => t('Extremely useful'), -'Other reason' => t('Any other reason state below') -); -$form['reason'] = array( -'#type' => 'hidden', -'#default_value' => 'Not available' -); -/*$form['reason'] = array( -'#type' => 'checkboxes', -'#title' => t('Reasons'), -'#options' => $reason, -'#required' => TRUE -); -$form['other_reason'] = array( -'#type' => 'textarea', -'#size' => 300, -'#maxlength' => 300, -'#states' => array( -'visible' => array( -':input[name="reason[Other reason]"]' => array( -'checked' => TRUE -) -) -) -//'#required' => FALSE, -);*/ -/*$form['proposal_type'] = array( -'#type' => 'hidden', -'#default_value' => '0', -'#required' => FALSE -); -$form['reference'] = array( -'#type' => 'hidden', -'#default_value' => 'Not available', -); -/*$form['reference'] = array( -'#type' => 'textarea', -'#title' => t('Reference'), -'#required' => TRUE, -'#size' => 500, -'#maxlength' => 500, -'#attributes' => array( -'placeholder' => 'Links of the syllabus must be provided....' -) -);*/ -/*$form['scilab_version'] = array( -'#type' => 'textfield', -'#title' => t('Scilab Version'), -'#required' => TRUE, -'#size' => 10, -'#maxlength' => 10, -);*/ -/*$form['form_type'] = array( -'#type' => 'hidden', -'#value' => 1 -); -$form['preference1'] = array( -'#type' => 'fieldset', -'#title' => t('Book Preference 1'), -'#collapsible' => TRUE, -'#collapsed' => FALSE -); -$form['preference1']['book1'] = array( -'#type' => 'textfield', -'#title' => t('Title of the book'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -); -$form['preference1']['author1'] = array( -'#type' => 'textfield', -'#title' => t('Author Name'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -//'#value' => $row1->author, -//'#disabled' => ($row1->author?TRUE:FALSE), -); -$form['preference1']['isbn1'] = array( -'#type' => 'textfield', -'#title' => t('ISBN No'), -'#size' => 30, -'#maxlength' => 25, -'#required' => TRUE -// '#value' => $row1->isbn, -// '#disabled' => ($row1->isbn?TRUE:FALSE), -); -$form['preference1']['publisher1'] = array( -'#type' => 'textfield', -'#title' => t('Publisher & Place'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -//'#value' => $row1->publisher, -); -$form['preference1']['edition1'] = array( -'#type' => 'textfield', -'#title' => t('Edition'), -'#size' => 4, -'#maxlength' => 2, -'#required' => TRUE -//'#value' => $row1->edition, -); -$form['preference1']['year1'] = array( -'#type' => 'textfield', -'#title' => t('Year of pulication'), -'#size' => 4, -'#maxlength' => 4, -'#required' => TRUE -//'#value' => $row1->year, -); -$form['preference2'] = array( -'#type' => 'fieldset', -'#title' => t('Book Preference 2'), -'#collapsible' => TRUE, -'#collapsed' => FALSE -); -$form['preference2']['book2'] = array( -'#type' => 'textfield', -'#title' => t('Title of the book'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -//'#value' => $row2->book, -//'#disabled' => ($row2->book?TRUE:FALSE), -); -$form['preference2']['author2'] = array( -'#type' => 'textfield', -'#title' => t('Author Name'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -//'#value' => $row2->author, -//'#disabled' => ($row2->author?TRUE:FALSE), -); -$form['preference2']['isbn2'] = array( -'#type' => 'textfield', -'#title' => t('ISBN No'), -'#size' => 30, -'#maxlength' => 25, -'#required' => TRUE -// '#value' => $row2->isbn, -// '#disabled' => ($row2->isbn?TRUE:FALSE), -); -$form['preference2']['publisher2'] = array( -'#type' => 'textfield', -'#title' => t('Publisher & Place'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -//'#value' => $row2->publisher, -); -$form['preference2']['edition2'] = array( -'#type' => 'textfield', -'#title' => t('Edition'), -'#size' => 4, -'#maxlength' => 2, -'#required' => TRUE -//'#value' => $row2->edition, -); -$form['preference2']['year2'] = array( -'#type' => 'textfield', -'#title' => t('Year of pulication'), -'#size' => 4, -'#maxlength' => 4, -'#required' => TRUE -//'#value' => $row2->year, -); -$form['preference3'] = array( -'#type' => 'fieldset', -'#title' => t('Book Preference 3'), -'#collapsible' => TRUE, -'#collapsed' => FALSE -); -$form['preference3']['book3'] = array( -'#type' => 'textfield', -'#title' => t('Title of the book'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -//'#value' => $row3->book, -//'#disabled' => ($row3->book?TRUE:FALSE), -); -$form['preference3']['author3'] = array( -'#type' => 'textfield', -'#title' => t('Author Name'), -'#size' => 30, -'#maxlength' => 100, -'#required' => TRUE -//'#value' => $row3->author, -// '#disabled' => ($row3->author?TRUE:FALSE), -); -$form['preference3']['isbn3'] = array( -'#type' => 'textfield', -'#title' => t('ISBN No'), -'#size' => 30, -'#maxlength' => 25, -'#required' => TRUE -//'#value' => $row3->isbn, -//'#disabled' => ($row3->isbn?TRUE:FALSE), -); -$form['preference3']['publisher3'] = array( -'#type' => 'textfield', -'#title' => t('Publisher & Place'), -'#size' => 30, -'#maxlength' => 50, -'#required' => TRUE -// '#value' => $row3->publisher, -); -$form['preference3']['edition3'] = array( -'#type' => 'textfield', -'#title' => t('Edition'), -'#size' => 4, -'#maxlength' => 2, -'#required' => TRUE -//'#value' => $row3->edition, -); -$form['preference3']['year3'] = array( -'#type' => 'textfield', -'#title' => t('Year of pulication'), -'#size' => 4, -'#maxlength' => 4, -'#required' => TRUE -//'#value' => $row3->year, -); -/*$form['termconditions'] = array( -'#type' => 'checkboxes', -'#title' => t('Terms And Conditions'), -'#options' => array( -'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),), -'#required' => TRUE, -);*/ -/*$form['samplefile'] = array( -'#type' => 'fieldset', -'#title' => t('Sample Source Files'), -'#collapsible' => FALSE, -'#collapsed' => FALSE -);*/ -/*$form['samplefile']['samplefile1'] = array( -'#type' => 'file', -'#title' => t('Upload sample source file'), -'#size' => 48, -'#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '') . '</span>' -);*/ -/*$form['submit'] = array( -'#type' => 'submit', -'#value' => t('Submit') -); -$form['dir_name1'] = array( -'#type' => 'hidden', -'#value' => 'None' -); -$form['dir_name2'] = array( -'#type' => 'hidden', -'#value' => 'None' -); -$form['dir_name3'] = array( -'#type' => 'hidden', -'#value' => 'None' -); -/* #value fix for #default_value bug drupal6 -foreach(array("preference1", "preference2", "preference3") as $preference) { -foreach($form[$preference] as $key => $value) { -if(!$form[$preference][$key]["#value"]) { -unset($form[$preference][$key]["#value"]); -} -} -}*/ -/* return $form; -}*/ function book_proposal_form($form, &$form_state) { global $user; @@ -2107,127 +1426,12 @@ function book_proposal_form($form, &$form_state) '#required' => TRUE //'#value' => $row1->year, ); - /*$form['preference2'] = array( - '#type' => 'fieldset', - '#title' => t('Book Preference 2'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $form['preference2']['book2'] = array( - '#type' => 'textfield', - '#title' => t('Title of the book'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE - //'#value' => $row2->book, - //'#disabled' => ($row2->book?TRUE:FALSE), - ); - $form['preference2']['author2'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE - //'#value' => $row2->author, - //'#disabled' => ($row2->author?TRUE:FALSE), - ); - $form['preference2']['isbn2'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE - // '#value' => $row2->isbn, - // '#disabled' => ($row2->isbn?TRUE:FALSE), - ); - $form['preference2']['publisher2'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE - //'#value' => $row2->publisher, - ); - $form['preference2']['edition2'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE - //'#value' => $row2->edition, - ); - $form['preference2']['year2'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE - //'#value' => $row2->year, - ); - $form['preference3'] = array( - '#type' => 'fieldset', - '#title' => t('Book Preference 3'), - '#collapsible' => TRUE, - '#collapsed' => FALSE - ); - $form['preference3']['book3'] = array( - '#type' => 'textfield', - '#title' => t('Title of the book'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE - //'#value' => $row3->book, - //'#disabled' => ($row3->book?TRUE:FALSE), - ); - $form['preference3']['author3'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE - //'#value' => $row3->author, - // '#disabled' => ($row3->author?TRUE:FALSE), - ); - $form['preference3']['isbn3'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE - //'#value' => $row3->isbn, - //'#disabled' => ($row3->isbn?TRUE:FALSE), - ); - $form['preference3']['publisher3'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE - // '#value' => $row3->publisher, - ); - $form['preference3']['edition3'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE - //'#value' => $row3->edition, - ); - $form['preference3']['year3'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE - //'#value' => $row3->year, + $form['preference1']['category'] = array( + '#type' => 'select', + '#title' => t('Select the category'), + '#options' => _tbc_list_of_main_categories(), + '#required' => TRUE ); - /*$form['termconditions'] = array( - '#type' => 'checkboxes', - '#title' => t('Terms And Conditions'), - '#options' => array( - 'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),), - '#required' => TRUE, - );*/ $form['samplefile'] = array( '#type' => 'fieldset', '#title' => t('Sample Source Files'), @@ -2248,14 +1452,6 @@ function book_proposal_form($form, &$form_state) '#type' => 'hidden', '#value' => 'None' ); - /* #value fix for #default_value bug drupal6 - foreach(array("preference1", "preference2", "preference3") as $preference) { - foreach($form[$preference] as $key => $value) { - if(!$form[$preference][$key]["#value"]) { - unset($form[$preference][$key]["#value"]); - } - } - }*/ return $form; } function book_proposal_form_validate($form, &$form_state) @@ -2298,44 +1494,7 @@ function book_proposal_form_validate($form, &$form_state) $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $pref_id); } //_dir_name($bk1, $auth1, $pref_id) != NULL } //$form_state['values']['book1'] && $form_state['values']['author1'] - /***************************************************************************** - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])) - form_set_error('isbn2', t('Invalid ISBN for Book Preference 2')); - if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2'])) - form_set_error('edition2', t('Invalid edition for Book Preference 2')); - if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2'])) - form_set_error('year2', t('Invalid year of pulication for Book Preference 2')); - if ((int) $form_state['values']['year2'] > $cur_year) - form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2')); - if ($form_state['values']['book2'] && $form_state['values']['author2']) { - $bk2 = trim($form_state['values']['book2']); - $auth2 = trim($form_state['values']['author2']); - //var_dump(_dir_name($bk1, $auth1)) - $pref_id = NULL; - if (_dir_name($bk2, $auth2, $pref_id) != NULL) { - $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $pref_id); - } - /***************************************************************************** - } - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) - form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); - if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3'])) - form_set_error('edition3', t('Invalid edition for Book Preference 3')); - if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3'])) - form_set_error('year3', t('Invalid year of pulication for Book Preference 3')); - if ((int) $form_state['values']['year3'] > $cur_year) - form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3')); - if ($form_state['values']['book3'] && $form_state['values']['author3']) { - $bk3 = trim($form_state['values']['book3']); - $auth3 = trim($form_state['values']['author3']); - //var_dump(_dir_name($bk1, $auth1)) - $pref_id = NULL; - if (_dir_name($bk1, $auth1, $pref_id) != NULL) { - $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $pref_id); - } - /***************************************************************************** - }*/ if (isset($form_state['values']['reason'])) { $my_reason = $form_state['values']['other_reason']; @@ -2525,26 +1684,12 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) /* inserting first book preference */ if ($form_state['values']['book1']) { - /*$result = db_query("INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES - (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", - $proposal_id, - 1, - ucwords(strtolower($form_state['values']['book1'])), - ucwords(strtolower($form_state['values']['author1'])), - $form_state['values']['isbn1'], - ucwords(strtolower($form_state['values']['publisher1'])), - $form_state['values']['edition1'], - $form_state['values']['year1'], - 0, - 0 - );*/ $bk1 = trim($form_state['values']['book1']); $auth1 = trim($form_state['values']['author1']); $pref_id = NULL; $directory_name = _dir_name($bk1, $auth1, $pref_id); $query = "INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name) + (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :subcategory, :approval_status, :directory_name) "; $args = array( ":proposal_id" => $proposal_id, @@ -2555,7 +1700,8 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher1']))), ":edition" => trim($form_state['values']['edition1']), ":year" => trim($form_state['values']['year1']), - ":category" => 0, + ":category" => $form_state['values']['category'], + ':subcategory' => 0, ":approval_status" => 0, ":directory_name" => $form_state['values']['dir_name1'] ); @@ -2567,96 +1713,6 @@ function book_proposal_form_submit($form, &$form_state, $directory_name = NULL) drupal_set_message(t('Error receiving your first book preference.'), 'error'); } //!$result } //$form_state['values']['book1'] - /*******************************************************/ - /* if ($form_state['values']['book2']) { - /*$result = db_query("INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES - (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", - $proposal_id, - 1, - ucwords(strtolower($form_state['values']['book1'])), - ucwords(strtolower($form_state['values']['author1'])), - $form_state['values']['isbn1'], - ucwords(strtolower($form_state['values']['publisher1'])), - $form_state['values']['edition1'], - $form_state['values']['year1'], - 0, - 0 - );*/ - /**$bk2 = trim($form_state['values']['book2']); - $auth2 = trim($form_state['values']['author2']); - $pref_id = NULL; - $directory_name = _dir_name($bk2, $auth2, $pref_id); - $query = "INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name) - "; - $args = array( - ":proposal_id" => $proposal_id, - - - ":pref_number" => 2, - ":book" => trim(ucwords(strtolower($form_state['values']['book2']))), - ":author" => trim(ucwords(strtolower($form_state['values']['author2']))), - ":isbn" => trim($form_state['values']['isbn2']), - ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher2']))), - ":edition" => trim($form_state['values']['edition2']), - ":year" => trim($form_state['values']['year2']), - ":category" => 0, - ":approval_status" => 0, - ":directory_name" => $form_state['values']['dir_name2'] - ); - $result = db_query($query, $args, array( - 'return' => Database::RETURN_INSERT_ID - )); - if (!$result) { - drupal_set_message(t('Error receiving your second book preference.'), 'error'); - } - }**/ - /*******************************************************/ - /**if ($form_state['values']['book3']) { - /*$result = db_query("INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES - (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)", - $proposal_id, - 1, - ucwords(strtolower($form_state['values']['book1'])), - ucwords(strtolower($form_state['values']['author1'])), - $form_state['values']['isbn1'], - ucwords(strtolower($form_state['values']['publisher1'])), - $form_state['values']['edition1'], - $form_state['values']['year1'], - 0, - 0 - );*/ - /** $bk3 = trim($form_state['values']['book3']); - $auth3 = trim($form_state['values']['author3']); - $pref_id = NULL; - $directory_name = _dir_name($bk3, $auth3, $pref_id); - $query = "INSERT INTO {textbook_companion_preference} - (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name) - "; - $args = array( - ":proposal_id" => $proposal_id, - ":pref_number" => 3, - ":book" => trim(ucwords(strtolower($form_state['values']['book3']))), - ":author" => trim(ucwords(strtolower($form_state['values']['author3']))), - ":isbn" => trim($form_state['values']['isbn3']), - ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher3']))), - ":edition" => trim($form_state['values']['edition3']), - ":year" => trim($form_state['values']['year3']), - ":category" => 0, - ":approval_status" => 0, - ":directory_name" => $form_state['values']['dir_name3'] - ); - $result = db_query($query, $args, array( - 'return' => Database::RETURN_INSERT_ID - )); - if (!$result) { - drupal_set_message(t('Error receiving your third book preference.'), 'error'); - } - - }**/ - /*******************************************************/ /* sending email */ $email_to = $user->mail; $from = variable_get('textbook_companion_from_email', ''); @@ -4401,7 +3457,7 @@ function book_proposal_nonaicte_form_submit($form, &$form_state) ":publisher" => ucwords(strtolower($form_state['values']['publisher1'])), ":edition" => $form_state['values']['edition1'], ":year" => $form_state['values']['year1'], - ":category" => 0, + ":category" => $form_state['values']['category'], ":approval_status" => 0, ":nonaicte_book" => 1 ); @@ -4499,42 +3555,24 @@ function _list_of_cities() } //$city_list_data = $city_list->fetchObject() return $city; } -/* -function _tbc_list_of_main_categories() + +function _tbc_list_of_main_categories() { - $maincategory = array(); + $maincategory = array( + 0 => 'Please select ...' + ); + //$maincategory = array(); $query = db_select('tbc_maincategory'); $query->fields('tbc_maincategory'); $query->orderBy('id', 'ASC'); $maincategory_list = $query->execute(); while ($maincategory_list_data = $maincategory_list->fetchObject()) { - $maincategory[$maincategory_list_data->maincategory_name] = $maincategory_list_data->maincategory_name; + $maincategory[$maincategory_list_data->id] = $maincategory_list_data->maincategory_name; } //$software_version_list_data = $software_version_list->fetchObject() return $maincategory; } -function _tbc_list_of_sub_categories() -{ - $maincategory = array(); - $query = db_select('tbc_maincategory'); - $query->fields('tbc_maincategory'); - $query->orderBy('id', 'ASC'); - $maincategory_list = $query->execute(); - $maincategory_id = $maincategory_list->fetchObject()->id; - $subcategory = array(); - $query = db_select('tbc_subcategory'); - $query->fields('tbc_subcategory'); - $query->condition('maincategory_id', $maincategory_id); - $query->orderBy('id', 'ASC'); - $subcategory_list = $query->execute(); - while ($subcategory_list_data = $subcategory_list->fetchObject()) - { - $subcategory[$subcategory_list_data->subcategory_name] = $subcategory_list_data->subcategory_name; - } //$software_version_list_data = $software_version_list->fetchObject() - return $subcategory; -} */ - /*************************************************************************/ /***** Function To convert only first charater of string in uppercase ****/ /*************************************************************************/ |