diff options
author | prashant | 2015-04-09 16:49:35 +0530 |
---|---|---|
committer | prashant | 2015-04-09 16:49:35 +0530 |
commit | 402f914839595e8e27331264ffc2291baa34e0d1 (patch) | |
tree | c52d50e4dafafbb0966754fa4f44bc4d1e55a6e7 | |
parent | a3632961ddd70c0e1839b8c3bc1765935154dd04 (diff) | |
download | DWSIM_textbook_companion-402f914839595e8e27331264ffc2291baa34e0d1.tar.gz DWSIM_textbook_companion-402f914839595e8e27331264ffc2291baa34e0d1.tar.bz2 DWSIM_textbook_companion-402f914839595e8e27331264ffc2291baa34e0d1.zip |
done some minor changes
-rwxr-xr-x | run.inc | 148 |
1 files changed, 43 insertions, 105 deletions
@@ -3,23 +3,10 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) { - $form['#redirect'] = FALSE; - $book_default_value = 0; + ahah_helper_register($form, $form_state); - if (!isset($form_state['storage']['run']['category'])) - { - $category_default_value = 0; - if($pref_id){ - $query = "select category from textbook_companion_preference where id=".$pref_id; - $result = db_query($query); - $row = db_fetch_object($result); - $category_default_value = $row->category; - $book_default_value = $pref_id; - } - } else { - $category_default_value = $form_state['storage']['run']['category']; - } + /* default value for ahah fields */ if (!isset($form_state['storage']['run']['book'])) { @@ -33,6 +20,8 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) $('#edit-run-book').change(); });"; drupal_add_js($chapter_name_js, 'inline', 'footer'); + } else { + $book_default_value = 0; } } else { $book_default_value = $form_state['storage']['run']['book']; @@ -59,7 +48,7 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) else $example_default_value = $form_state['storage']['run']['example']; } - + $form['run'] = array( '#type' => 'fieldset', '#title' => t('Run Book Example'), @@ -69,57 +58,24 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) '#suffix' => '</div>', '#tree' => TRUE, ); - $form['run']['category'] = array( - '#type' => 'select', - '#title' => t('Category'), - '#options' => array(0 => 'Please select', - 1 => 'Fluid Mechanics', - 2 => 'Control Theory & Control Systems', - 3 => 'Chemical Engineering', - 4 => 'Thermodynamics', - 5 => 'Mechanical Engineering', - 6 => 'Signal Processing', - 7 => 'Digital Communications', - 8 => 'Electrical Technology', - 9 => 'Mathematics & Pure Science', - 10 => 'Analog Electronics', - 11 => 'Digital Electronics', - 12 => 'Computer Programming', - 13 => 'Others'), - '#default_value' => $category_default_value, - '#tree' => TRUE, - '#ahah' => array( - 'event' => 'change', - 'effect' => 'none', - 'path' => ahah_helper_path(array('run')), - 'wrapper' => 'run-wrapper', - 'progress' => array( - 'type' => 'throbber', - 'message' => t(''), - ), - ), - ); - if($category_default_value > 0) { - $form['run']['book'] = array( - '#type' => 'select', - '#title' => t('Title of the Book'), - '#options' => _list_of_books($category_default_value), - '#default_value' => $book_default_value, - '#tree' => TRUE, - '#ahah' => array( - 'event' => 'change', - 'effect' => 'none', - 'path' => ahah_helper_path(array('run')), - 'wrapper' => 'run-wrapper', - 'progress' => array( - 'type' => 'throbber', - 'message' => t(''), - ), - ), - ); - }else { - $book_default_value = 0; - } + + $form['run']['book'] = array( + '#type' => 'select', + '#title' => t('Title of the Book'), + '#options' => _list_of_books(), + '#default_value' => $book_default_value, + '#tree' => TRUE, + '#ahah' => array( + 'event' => 'change', + 'effect' => 'none', + 'path' => ahah_helper_path(array('run')), + 'wrapper' => 'run-wrapper', + 'progress' => array( + 'type' => 'throbber', + 'message' => t(''), + ), + ), + ); /* hidden form elements */ $form['run']['book_hidden'] = array( @@ -156,13 +112,13 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) $form['run']['download_book'] = array( '#type' => 'item', - '#value' => l('Download', 'download/book/' . $book_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples)'), + '#value' => l('Download', 'download/book/' . $book_default_value) . ' ' . t('(Download all the examples of the entire book)'), ); - $form['run']['download_book_pdf'] = array( + /*$form['run']['download_book_pdf'] = array( '#type' => 'item', - '#value' => l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)'), - ); + '#value' => l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value) . ' ' . t('(Download PDF for all examples of the entire book)'), + );*/ $form['run']['chapter'] = array( '#type' => 'select', @@ -185,7 +141,7 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) { $form['run']['download_chapter'] = array( '#type' => 'item', - '#value' => l('Download', 'download/chapter/' . $chapter_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples from the Chapter)'), + '#value' => l('Download', 'download/chapter/' . $chapter_default_value) . ' ' . t('(Download all the examples of the entire chapter)'), ); $form['run']['example'] = array( '#type' => 'select', @@ -233,38 +189,17 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) $example_files_rows = array(); while ($example_list_data = db_fetch_object($example_list_q)) { - $example_file_type = ''; - switch ($example_list_data->filetype) - { - case 'S' : $example_file_type = 'Source or Main file'; break; - case 'R' : $example_file_type = 'Result file'; break; - case 'X' : $example_file_type = 'xcos file'; break; - default : $example_file_type = 'Unknown'; break; - } + $example_file_type = 'Source or Main file'; $example_files_rows[] = array(l($example_list_data->filename, 'download/file/' . $example_list_data->id), $example_file_type); } - /* dependency files */ - $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption - FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency - ON example_dependency.dependency_id = dependency.id - WHERE example_dependency.example_id = %d", $form_state['values']['run']['example']); - while ($dependency_list_data = db_fetch_object($dependency_list_q)) - { - $example_file_type = 'Dependency file'; - $temp_caption = ''; - if ($dependency_list_data->dependency_caption) - $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')'; - $example_files_rows[] = array(l($dependency_list_data->dependency_filename, 'download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $example_file_type); - } - /* creating list of files table */ $example_files_header = array('Filename', 'Type'); $example_files = theme_table($example_files_header, $example_files_rows); } $form['run']['download_example'] = array( '#type' => 'item', - '#value' => l('Download Scilab code for the example', 'download/example/' . $example_default_value), + '#value' => l('Download Example', 'download/example/' . $example_default_value), ); $form['run']['example_files'] = array( '#type' => 'item', @@ -295,11 +230,11 @@ function textbook_companion_run_form($form_state, $pref_id = NULL) function textbook_companion_run_form_submit($form, &$form_state) { - global $user; + global $user; - if ($form_state['clicked_button']['#value'] == 'Submit') - { - if (user_access('create feedback')) + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if (user_access('create feedback')) { $example_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $form_state['values']['run']['example'])); if (!$example_data) @@ -340,8 +275,7 @@ function textbook_companion_run_form_submit($form, &$form_state) $param['feedback_received']['example_no'] = $example_data->number; $param['feedback_received']['feedback'] = $form_state['values']['run']['feedback']; - $email_to = $user->mail; - // . ', ' . user_load($proposal_data->uid)->mail. ', ' . user_load($example_data->approver_uid)->mail; + $email_to = $user->mail;// . ', ' . user_load($proposal_data->uid)->mail. ', ' . user_load($example_data->approver_uid)->mail; if (!drupal_mail('textbook_companion', 'feedback_received', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); @@ -349,14 +283,18 @@ function textbook_companion_run_form_submit($form, &$form_state) } else { drupal_set_message(t('You do not have permission to submit feeback.'), 'error'); } - } + } } -function _list_of_books($category_default_value) +function _list_of_books() { $book_titles = array('0' => 'Please select...'); - // $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category=".$category_default_value." AND approval_status = 1 OR approval_status = 3 ORDER BY book ASC"); - $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category=".$category_default_value." AND approval_status = 1 AND proposal_id IN (SELECT id FROM textbook_companion_proposal WHERE proposal_status=3) ORDER BY book ASC"); + $qq = " + SELECT pre.id AS id, pre.* FROM textbook_companion_preference pre + LEFT JOIN textbook_companion_proposal pro ON pro.id = pre.proposal_id + WHERE pre.approval_status = 1 AND pro.proposal_status = 3 ORDER BY pre.book ASC + "; + $book_titles_q = db_query($qq); while ($book_titles_data = db_fetch_object($book_titles_q)) { $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')'; |