diff options
author | Sanmugasundaram K | 2015-04-30 12:53:52 +0530 |
---|---|---|
committer | tslee | 2015-05-05 15:47:16 +0530 |
commit | 1a548df4a2ec5a1ad6a8d4aa7a1d1afff63cd036 (patch) | |
tree | 43dc05e38c9ddda00e6a18c7b6fdfe37786009d6 | |
parent | 2b9093bd87d05c7e1296b8208237cdfb04759fa8 (diff) | |
download | scilab_textbook_companion-1a548df4a2ec5a1ad6a8d4aa7a1d1afff63cd036.tar.gz scilab_textbook_companion-1a548df4a2ec5a1ad6a8d4aa7a1d1afff63cd036.tar.bz2 scilab_textbook_companion-1a548df4a2ec5a1ad6a8d4aa7a1d1afff63cd036.zip |
deleted backup filed
-rwxr-xr-x | search.inc.bak-23Oct2013 | 249 | ||||
-rwxr-xr-x | textbook_companion.module.backup-feb-3-2014 | 1785 | ||||
-rwxr-xr-x | textbook_companion.module.bak-16Sep2012 | 1476 | ||||
-rwxr-xr-x | textbook_companion.module.bak-23Oct2013 | 1785 |
4 files changed, 0 insertions, 5295 deletions
diff --git a/search.inc.bak-23Oct2013 b/search.inc.bak-23Oct2013 deleted file mode 100755 index df92e8a..0000000 --- a/search.inc.bak-23Oct2013 +++ /dev/null @@ -1,249 +0,0 @@ -<?php -// $Id$ - -function textbook_companion_search_form() -{ - $form['#redirect'] = FALSE; - $form['search'] = array( - '#type' => 'textfield', - '#title' => t('Search'), - '#size' => 48, - ); - - $form['search_by_title'] = array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Search by Title of the Book'), - ); - - $form['search_by_author'] = array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Search by Author of the Book'), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Search') - ); - - $form['cancel'] = array( - '#type' => 'markup', - '#value' => l(t('Cancel'), ''), - ); - - if ($_POST) - { - $output = ''; - $search_rows = array(); - $search_query = ''; - if ($_POST['search_by_title'] && $_POST['search_by_author']) - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND (book LIKE '%%%s%%' OR author LIKE '%%%s%%')", $_POST['search'], $_POST['search']); - else if ($_POST['search_by_title']) - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND book LIKE '%%%s%%'", $_POST['search']); - else if ($_POST['search_by_author']) - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND author LIKE '%%%s%%'", $_POST['search']); - else - drupal_set_message('Please select whether to search by Title and/or Author of the Book.', 'error'); - while ($search_data = db_fetch_object($search_q)) - { - $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author); - } - if ($search_rows) - { - $search_header = array('Title of the Book', 'Author Name'); - $output .= theme_table($search_header, $search_rows); - $form['search_results'] = array( - '#type' => 'item', - '#title' => t('Search results for "') . $_POST['search'] . '"', - '#value' => $output, - ); - } else { - $form['search_results'] = array( - '#type' => 'item', - '#title' => t('Search results for "') . $_POST['search'] . '"', - '#value' => 'No results found', - ); - } - } - return $form; -} - -/******************************************************************************/ -/**************************** BROWSE BY FORMS *********************************/ -/******************************************************************************/ - -function textbook_companion_browse_book() -{ - $return_html = _browse_list('book'); - $return_html .= '<br /><br />'; - $query_character = arg(2); - if (!$query_character) { - /* all books */ - $return_html .= "Please select the starting character of the title of the book"; - return $return_html; - } - $book_rows = array(); - $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE book like '%s%%' AND approval_status = 1", $query_character); - while ($book_data = db_fetch_object($book_q)) - { - $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author); - } - if (!$book_rows) - { - $return_html .= "Sorry no books are available with that title"; - } else { - $book_header = array('Title of the Book', 'Author Name'); - $return_html .= theme_table($book_header, $book_rows); - } - return $return_html; -} - -function textbook_companion_browse_author() -{ - $return_html = _browse_list('author'); - $return_html .= '<br /><br />'; - $query_character = arg(2); - if (!$query_character) { - /* all books */ - $return_html .= "Please select the starting character of the author's name"; - return $return_html; - } - $book_rows = array(); - $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE author like '%s%%' AND approval_status = 1", $query_character); - while ($book_data = db_fetch_object($book_q)) - { - $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author); - } - if (!$book_rows) - { - $return_html .= "Sorry no books are available with that author's name"; - } else { - $book_header = array('Title of the Book', 'Author Name'); - $return_html .= theme_table($book_header, $book_rows); - } - return $return_html; -} - -function textbook_companion_browse_student() -{ - $return_html = _browse_list('student'); - $return_html .= '<br /><br />'; - $query_character = arg(2); - if (!$query_character) { - /* all books */ - $return_html .= "Please select the starting character of the student's name"; - return $return_html; - } - $book_rows = array(); - $query = "SELECT * FROM textbook_companion_proposal WHERE full_name like '".$query_character."%' ORDER BY full_name ASC"; - $student_q = db_query($query); - while ($student_data = db_fetch_object($student_q)) - { - $query = "SELECT * FROM textbook_companion_preference WHERE proposal_id = " . $student_data->id . " AND approval_status = 1"; - $book_q = db_query($query); - while ($book_data = db_fetch_object($book_q)) - { - $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $student_data->full_name); - } - } - if (!$book_rows) - { - $return_html .= "Sorry no books are available with that student's name"; - } else { - $book_header = array('Title of the Book', 'Student Name'); - $return_html .= theme_table($book_header, $book_rows); - } - return $return_html; -} - -function _browse_list($type) -{ - $return_html = ''; - $char_list = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); - foreach ($char_list as $char_name) - { - $return_html .= l($char_name, 'textbook_search/' . $type . '/' . $char_name); - if ($char_name != 'Z') - $return_html .= ' | '; - } - return $return_html; -} -function _list_of_colleges() -{ - $college_names = array('0' => '--- select ---'); - $college_names_q = db_query("SELECT DISTINCT university FROM {textbook_companion_proposal} WHERE proposal_status=1 OR proposal_status=3 ORDER BY university ASC"); - while ($college_names_data = db_fetch_object($college_names_q)) - { - $college_names[$college_names_data->university] = $college_names_data->university; - } - return $college_names; -} - -function _list_books_by_college($college) { - $query = "SELECT pro.full_name, pro.proposal_status, pre.id as preid, pre.book, pre.isbn FROM textbook_companion_proposal pro, textbook_companion_preference pre WHERE pro.university='".$college."' AND (pro.proposal_status=1 OR pro.proposal_status=3) AND pre.proposal_id=pro.id AND pre.approval_status=1"; - $result = db_query($query); - $output = '<table><tr><th>SNO</th><th>Name</th><th>Book</th><th>ISBN</th><th>Status</th></tr>'; - $sno = 1; - while($row = db_fetch_object($result)) { - - if($row->proposal_status == 1) { - $output .= '<tr><td>'.$sno++.'</td><td>'.$row->full_name.'</td><td>'.$row->book.'</td><td>'.str_replace("-", "", $row->isbn).'</td><td style="color: orange;">Approved</td>'; - }else { - $output .= '<tr><td>'.$sno++.'</td><td>'.$row->full_name.'</td><td><a target="_blank" href="'.base_path().'textbook_run/'.$row->preid.'">'.$row->book.'</a></td><td>'.str_replace("-", "", $row->isbn).'</td><td style="color: green;">Completed</td>'; - } - $output .= '</tr>'; - } - - return $output; -} - -function textbook_companion_browse_college_form($form_state) { - $form = array(); - - ahah_helper_register($form, $form_state); - - - if (!isset($form_state['storage']['college_info']['college'])) { - $usage_default_value = '0'; - } - else { - $usage_default_value = $form_state['storage']['college_info']['college']; - } - - $form['college_info'] = array( - '#type' => 'fieldset', - '#prefix' => '<div id="college-info-wrapper">', - '#suffix' => '</div>', - '#tree' => TRUE, - ); - $form['college_info']['college'] = array( - '#type' => 'select', - '#title' => t('College Name'), - '#options' => _list_of_colleges(), - '#default_value' => $usage_default_value, - '#ahah' => array( - 'event' => 'change', - 'path' => ahah_helper_path(array('college_info')), - 'wrapper' => 'college-info-wrapper', - ), - ); - - - if ($usage_default_value != '0') { - $form['college_info']['book_details'] = array( - '#type' => 'item', - '#value' => _list_books_by_college($usage_default_value) - ); - } - - return $form; -} - -function textbook_companion_browse_college_form_validate($form, &$form_state) { - -} - -function textbook_companion_browse_college_form_submit($form, &$form_state) { - -} diff --git a/textbook_companion.module.backup-feb-3-2014 b/textbook_companion.module.backup-feb-3-2014 deleted file mode 100755 index 9c8d4e5..0000000 --- a/textbook_companion.module.backup-feb-3-2014 +++ /dev/null @@ -1,1785 +0,0 @@ -<?php -// $Id$ - -/** - * Implementation of hook_menu(). - */ -function textbook_companion_menu() -{ - $items = array(); - - /* users */ - $items['proposal'] = array( - 'title' => 'Book Proposal Form', - 'description' => 'Book Proposal Form.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_proposal_form'), - 'access callback' => 'user_access', - 'access arguments' => array('create book proposal'), - 'type' => MENU_NORMAL_ITEM, - ); - - /* for reviewers */ - $items['manage_proposal'] = array( - 'title' => 'Manage Book Proposals', - 'description' => 'Manage Book Proposals', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/pending'] = array( - 'title' => 'Pending Proposals', - 'description' => 'Pending Proposals Queue', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/all'] = array( - 'title' => 'All Proposals', - 'description' => 'All Proposals', - 'page callback' => '_proposal_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category'] = array( - 'title' => 'Categorize', - 'description' => 'Categorize Books', - 'page callback' => '_category_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/approve'] = array( - 'title' => 'Proposal Approval', - 'description' => 'Proposal Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_approval_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/status'] = array( - 'title' => 'Proposal Status', - 'description' => 'Proposal Status', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_status_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/edit'] = array( - 'title' => 'Edit Proposal', - 'description' => 'Edit Proposal', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category/edit'] = array( - 'title' => 'Edit Category', - 'description' => 'Edit category', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('category_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - - $items['code_approval'] = array( - 'title' => 'Manage Code Approval', - 'description' => 'Manage Code Approval', - 'page callback' => 'code_approval', - 'access arguments' => array('approve code'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'code_approval.inc', - ); - $items['code_approval/approve'] = array( - 'title' => 'Code Approval', - 'description' => 'Code Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('code_approval_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'code_approval.inc', - ); - $items['code_approval/bulk'] = array( - 'title' => 'Bulk Manage', - 'description' => 'Bulk Mangage', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('bulk_approval_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'code_approval.inc', - ); - $items['code_approval/editcode'] = array( - 'title' => 'Admin Edit Example', - 'description' => 'Admin Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_admin_edit_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'weight' => 3, - 'file' => 'editcodeadmin.inc', - ); - $items['code_approval/notes'] = array( - 'title' => 'Notes for Reviewers', - 'description' => 'Notes for Reviewers', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_notes_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_CALLBACK, - 'weight' => 4, - 'file' => 'notes.inc', - ); - $items['code_approval/dependency'] = array( - 'title' => 'Dependency', - 'description' => 'Dependency', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_dependency_approval_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 3, - 'file' => 'dependency_approval.inc', - ); - - $items['textbook_companion/code'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'list_chapters', - 'access callback' => 'user_access', - 'access arguments' => array('upload code'), - 'file' => 'general.inc', - ); - $items['textbook_companion/code/list_chapters'] = array( - 'title' => 'List Chapters', - 'description' => 'List Chapters', - 'page callback' => 'list_chapters', - 'access arguments' => array('upload code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'general.inc', - 'weight' => 1, - ); - $items['textbook_companion/code/upload'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'upload_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'code.inc', - 'weight' => 2, - ); - $items['textbook_companion/code/upload_dep'] = array( - 'title' => 'Upload Dependency', - 'description' => 'Upload Dependency Files', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_dependency_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'dependency.inc', - 'weight' => 3, - ); - $items['textbook_companion/code/edit'] = array( - 'title' => 'Edit Example', - 'description' => 'Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_edit_form'), - 'access arguments' => array('edit uploaded code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/delete'] = array( - 'title' => 'Delete Example', - 'description' => 'Delete Example', - 'page callback' => '_upload_examples_delete', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'code.inc', - ); - $items['textbook_companion/code/chapter/edit'] = array( - 'title' => 'Edit Chapter Title', - 'description' => 'Edit Chapter Title', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('edit_chapter_title_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/list_examples'] = array( - 'title' => 'List Examples', - 'description' => 'List Examples', - 'page callback' => 'list_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'general.inc', - 'weight' => 3, - ); - - $items['textbook_search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'search.inc', - ); - $items['textbook_search/search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 1, - ); - $items['textbook_search/book'] = array( - 'title' => 'By Book Title', - 'description' => '', - 'page callback' => 'textbook_companion_browse_book', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 2, - ); - $items['textbook_search/author'] = array( - 'title' => 'By Author', - 'description' => '', - 'page callback' => 'textbook_companion_browse_author', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 3, - ); - $items['textbook_search/college'] = array( - 'title' => 'By College', - 'description' => '', - 'page callback' => 'textbook_companion_browse_college', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_browse_college_form'), - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 4, - ); - $items['textbook_search/student'] = array( - 'title' => 'By Student', - 'description' => '', - 'page callback' => 'textbook_companion_browse_student', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 5, - ); - - $items['textbook_run'] = array( - 'title' => 'Download Codes', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_run_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'run.inc', - ); - - /* download callbacks */ - $items['download/file'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/dependency'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_dependency_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/example'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_chapter', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - - /* reviewer download */ - $items['full_download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_chapter', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - $items['full_download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - - /* latex script for book generation */ - $items['textbook_companion/generate_book'] = array( - 'title' => 'Generate Book', - 'description' => 'Generate Book From Latex Script', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('generate book'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - $items['textbook_companion/delete_book'] = array( - 'title' => 'Delete Book PDF', - 'description' => 'Delete Book PDF', - 'page callback' => 'textbook_companion_delete_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - - /* general purpose callbacks */ - $items['textbook_companion/ajax'] = array( - 'title' => 'Ajax', - 'description' => 'Ajax', - 'page callback' => 'textbook_companion_ajax', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - - /* for admin */ - $items['admin/settings/book_companion'] = array( - 'title' => 'Book Companion Settings', - 'description' => 'Book Companion Settings', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_settings_form'), - 'access arguments' => array('administer book companion'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'settings.inc', - ); - /* for data entry */ - $items['dataentry_book'] = array( - 'title' => 'Approved books list', - 'page callback' => '_data_entry_proposal_all', - 'access callback' => 'user_access', - 'access arguments' => array('dataentry book proposal'), - 'file' => 'manage_proposal.inc', - ); - $items['dataentry_edit'] = array( - 'title' => 'Edit book details', - 'page callback' => 'dataentry_edit', - 'access callback' => 'user_access', - 'access arguments' => array('dataentry book proposal'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'manage_proposal.inc', - ); - /*Cheque Details and Contact Form */ - $items['cheque_manage/all'] = array( - 'title' => 'Cheque Proposals', - 'description' => 'Cheque Proposals', - 'page callback' => 'cheque_proposal_all', - 'access arguments' => array('cheque proposal'), - 'file' => 'cheque_manage.inc', - ); - $items['mycontact'] = array( - 'title' => 'Update Contact Details', - 'description' => 'Update Contact Details', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('contact_details'), - 'access arguments' => array('contact_details'), - 'file' => 'cheque_contact.inc', - ); - - $items['cheque_contct'] = array( - 'title' => 'Report', - 'description' => 'Cheque Contact Form', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_contct_form'), - 'access arguments' => array('cheque contct form'), - 'file' => 'cheque_contact.inc', - ); - $items['cheque_contact/status'] = array( - 'title' => 'Cheque Status', - 'description' => 'Cheque Status', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_status_form'), - 'access' => 'user_is_logged_in', - 'access arguments' => array('cheque status form'), - 'file' => 'cheque_contact.inc', - ); - $items['cheque_contct/report'] = array( - 'title' => 'Report', - 'description' => 'Report', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_report_form'), - 'access' => 'user_is_logged_in', - 'access arguments' => array('cheque report form'), - 'file' => 'cheque_contact.inc', - ); - $items['certificate'] = array( - 'title' => 'List Of All Certificates', - 'description' => 'List Of All Certificates', - 'page callback' => '_list_all_certificates', - 'access arguments' => array('list all certificates'), - 'file' => 'pdf/list_all_certificates.inc', - ); - $items['certificate/generate_pdf'] = array( - 'title' => 'Download Certificate', - 'description' => 'Download Certificate', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('generate_pdf'), - 'access arguments' => array('generate pdf'), - 'file' => 'pdf/generate_pdf.inc', - ); - $items['manage_proposal/paper_submission'] = array( - 'title' => 'Application Submission', - 'description' => 'Application Submission', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('paper_submission_form'), - 'access arguments' => array('paper submission form'), - 'type' => MENU_CALLBACK, - 'file' => 'cheque_contact.inc', - ); - return $items; -} - -/** - * Implementation of hook_perm(). - */ -function textbook_companion_perm() { - - return array('create book proposal', 'approve book proposal', 'approve code', 'upload code', 'edit uploaded code', 'download code', 'create feedback', 'bulk manage code', 'bulk delete code', 'edit book proposal', 'administer book companion', 'generate book', 'cheque contct form', 'contact_details', 'comment cheque', 'list all certificates', 'generate pdf', 'paper submission form', 'cheque status form' ,'cheque report form' ,'cheque proposal'); -} - - -function book_proposal_form($form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* check if user has already submitted a proposal */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); - if ($proposal_q) - { - if ($proposal_data = db_fetch_object($proposal_q)) - { - switch ($proposal_data->proposal_status) - { - case 0: - drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); - return; - break; - case 1: - drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status'); - drupal_goto(''); - return; - break; - case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error'); - break; - case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status'); - break; - default: - drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - break; - } - } - } - - $form['imp_notice'] = array( - '#type' => 'item', - '#value' => '<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('Scilab Website' => 'Scilab 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' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), - '#required' => TRUE, - ); - $form['university'] = array( - '#type' => 'textfield', - '#title' => t('University/Institute'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['faculty'] = array( - '#type' => 'textfield', - '#title' => t('College Teacher/Professor'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['faculty_email'] = array( - '#type' => 'textfield', - '#title' => t('Teacher/Professor Email Id'), - '#default_value' => '@email.com', - '#size' => 30, - '#maxlength' => 50, - ); - $form['reviewer'] = array( - '#type' => 'textfield', - '#title' => t('Reviewer'), - '#size' => 30, - '#maxlength' => 50, - ); - $form['version'] = array( - '#type' => 'select', - '#title' => t('Version'), - '#options' => array('scilab 5.4.1' => 'Scilab 5.4.1', - 'scilab 5.3.3' => 'Scilab 5.3.3', - 'olderversion' => 'Older Version'), - '#required' => TRUE, - ); - $form['older'] = array( - '#type' => 'textfield', - '#size' => 30, - '#maxlength' => 50, - //'#required' => TRUE, - '#description' => t('Specify the Older version used'), - ); - $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, - ); - /*$form['scilab_version'] = array( - '#type' => 'textfield', - '#title' => t('Scilab Version'), - '#required' => TRUE, - '#size' => 10, - '#maxlength' => 10, - );*/ - $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, - ); - $form['preference1']['isbn1'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference1']['publisher1'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference1']['edition1'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference1']['year1'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference2']['author2'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference2']['isbn2'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference2']['publisher2'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference2']['edition2'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference2']['year2'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference3']['author3'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference3']['isbn3'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference3']['publisher3'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference3']['edition3'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference3']['year3'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#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['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - return $form; -} - -function book_proposal_form_validate($form, &$form_state) -{ - /* mobile */ - if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) - form_set_error('mobile', t('Invalid mobile number')); - - /* date of completion */ - if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date'])) - form_set_error('completion_date', t('Invalid expected date of completion')); - - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $d = (int)$d; $m = (int)$m; $y = (int)$y; - if (!checkdate($m, $d, $y)) - form_set_error('completion_date', t('Invalid expected date of completion')); - if (mktime(0, 0, 0, $m, $d, $y) <= time()) - form_set_error('completion_date', t('Expected date of completion should be in future')); - - /* edition */ - if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1'])) - form_set_error('edition1', t('Invalid edition for Book Preference 1')); - 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-9][0-9]{0,1}$/', $form_state['values']['edition3'])) - form_set_error('edition3', t('Invalid edition for Book Preference 3')); - - /* year of publication */ - if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1'])) - form_set_error('year1', t('Invalid year of pulication for Book Preference 1')); - 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 (!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')); - - /* year of publication */ - $cur_year = date('Y'); - if ((int)$form_state['values']['year1'] > $cur_year) - form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1')); - 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 ((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')); - - /* isbn */ - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1'])) - form_set_error('isbn1', t('Invalid ISBN for Book Preference 1')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])) - form_set_error('isbn2', t('Invalid ISBN for Book Preference 2')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) - form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); - - if($form_state['values']['version'] == 'olderversion'){ - if($form_state['values']['older'] == ''){ - form_set_error('older', t('Please provide valid version')); - } - } - return; -} - -function book_proposal_form_submit($form, &$form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* completion date to timestamp */ - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y); - - - $scilab_version = $form_state['values']['version']; - - if($form_state['values']['version'] == 'olderversion'){ - $scilab_version = $form_state['values']['older']; - } - - //var_dump($form_state['values']); - - $query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')"; - - $result = db_query($query); - if (!$result) - { - drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); - return; - } - /* proposal id */ - $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id'); - - /* 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 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your first book preference.'), 'error'); - } - } - - /* inserting second book preference */ - 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, - 2, - ucwords(strtolower($form_state['values']['book2'])), - ucwords(strtolower($form_state['values']['author2'])), - $form_state['values']['isbn2'], - ucwords(strtolower($form_state['values']['publisher2'])), - $form_state['values']['edition2'], - $form_state['values']['year2'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your second book preference.'), 'error'); - } - } - - /* inserting third book preference */ - 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, - 3, - ucwords(strtolower($form_state['values']['book3'])), - ucwords(strtolower($form_state['values']['author3'])), - $form_state['values']['isbn3'], - ucwords(strtolower($form_state['values']['publisher3'])), - $form_state['values']['edition3'], - $form_state['values']['year3'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your third book preference.'), 'error'); - } - } - - /* sending email */ - $email_to = $user->mail; - $param['proposal_received']['proposal_id'] = $proposal_id; - $param['proposal_received']['user_id'] = $user->uid; - if (!drupal_mail('textbook_companion', 'proposal_received', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); -} - -/** - * Implementation of hook_mail(). - */ -function textbook_companion_mail($key, &$message, $params) -{ - global $user; - $language = $message['lianguage']; - $tbc_bcc_emails = array( - 'Bcc' => variable_get('textbook_companion_emails', ''), - ); - switch ($key) - { - case 'proposal_received': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_received']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following book proposal: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Your proposal is under review and you will soon receive an email from us regarding the same. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_disapproved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been disapproved: - -Reason for disapproval: ' . $proposal_data->message . ' - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_approved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been approved: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_completed': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_completed']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_completed']['user_id']); - - $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Following book has been completed sucessfully by you: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Your book is now available at following link to download. - -http://scilab.in/textbook_run/' . $approved_preference_data->id . ' - -Now you should be able to propose a new book... - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_uploaded': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_uploaded']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_uploaded']['user_id']); - - $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated']['user_id']); - - $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is still under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated_admin': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated_admin']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated_admin']['user_id']); - - $message['subject'] = t('[!site_name] Reviewer have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Reviewer have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_approved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_approved']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been approved: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_disapproved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['example_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been disapproved: - -Example number : ' . $params['example_disapproved']['example_number'] . ' -Caption : ' . $params['example_disapproved']['example_caption'] . ' - -Reason for dis-approval : ' . $params['example_disapproved']['message'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_deleted_user': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['example_deleted_user']['user_id']); - - $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following pending example has been deleted : - -Title of the Book : ' . $params['example_deleted_user']['book_title'] . ' -Title of the Chapter : ' . $params['example_deleted_user']['chapter_title'] . ' -Example number : ' . $params['example_deleted_user']['example_number'] . ' -Caption : ' . $params['example_deleted_user']['example_caption'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'dependency_uploaded': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['dependency_uploaded']['user_id']); - $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); - - $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded following dependency files : - ' . $dependency_files . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'feedback_received': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['feedback_received']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following feedback - -Title of the Book: ' . $params['feedback_received']['book_title'] . ' -Title of the Chapter: ' . $params['feedback_received']['chapter_number'] . ' ' . $params['feedback_received']['chapter_title'] . ' -Example No.: ' . $params['feedback_received']['example_no'] . ' - -Your feedback : -' . $params['feedback_received']['feedback'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'internshipform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['internshipform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Internship Form Application for the book - -Title of the Book: ' . $params['internshipform']['book_title'] . ' -Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . ' -Example No.: ' . $params['internshipform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - -case 'copyrighttransferform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['copyrighttransferform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Copyright Form Application for the book - -Title of the Book: ' . $params['copyrighttransferform']['book_title'] . ' -Title of the Chapter: ' . $params['copyrighttransferform']['chapter_number'] . ' ' . $params['copyrighttransferform']['chapter_title'] . ' -Example No.: ' . $params['copyrighttransferform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - -case 'undertakingform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['undertakingform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Undertaking Form Application for the book - -Title of the Book: ' . $params['undertakingform']['book_title'] . ' -Title of the Chapter: ' . $params['undertakingform']['chapter_number'] . ' ' . $params['undertakingform']['chapter_title'] . ' -Example No.: ' . $params['undertakingform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - -case 'remark': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['remark']['user_id']); - - $message['subject'] = t('[!site_name] A remark has been given.Please check your contact detail form', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -A Remark has been given.Please check your Contact Detail Form - -Title of the Book: ' . $params['internshipform']['book_title'] . ' -Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . ' -Example No.: ' . $params['internshipform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'cheque_sent': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['cheque_sent']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have Sent Cheque for the following book proposed - -Title of the Book: ' . $params['cheque_sent']['book_title'] . ' -Title of the Chapter: ' . $params['cheque_sent']['chapter_number'] . ' ' . $params['cheque_sent']['chapter_title'] . ' -Example No.: ' . $params['cheque_sent']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - - case 'standard': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $message['subject'] = $params['standard']['subject']; - $message['body'] = $params['standard']['body']; - break; - } -} - -/* AJAX CALLS */ -function textbook_companion_ajax() -{ - $query_type = arg(2); - if ($query_type == 'chapter_title') - { - $chapter_number = arg(3); - $preference_id = arg(4); - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if ($chapter_data = db_fetch_object($chapter_q)) - { - echo $chapter_data->name; - return; - } - } else if ($query_type == 'example_exists') { - $chapter_number = arg(3); - $preference_id = arg(4); - $example_number = arg(5); - - $chapter_id = 0; - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if (!$chapter_data = db_fetch_object($chapter_q)) - { - echo ''; - return; - } else { - $chapter_id = $chapter_data->id; - } - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s' LIMIT 1", $chapter_id, $example_number); - if ($example_data = db_fetch_object($example_q)) - { - if ($example_data->approval_status == 1) - echo 'Warning! Example already approved. You cannot upload the same example again.'; - else - echo 'Warning! Example already uploaded. Delete the example and reupload it.'; - return; - } - } - echo ''; -} - -/*************************** VALIDATION FUNCTIONS *****************************/ -function textbook_companion_check_valid_filename($file_name) { - if (!preg_match('/^[0-9a-zA-Z\_\.]+$/', $file_name)) - return FALSE; - else - if (substr_count($file_name, ".") > 1) - return FALSE; - else - return TRUE; -} - -function check_name($name = '') { - if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) - return FALSE; - else - return TRUE; -} - -function check_chapter_number($name = '') { - if (!preg_match('/^([0-9])+(\.([0-9a-zA-Z])+)+$/', $name)) - return FALSE; - else - return TRUE; -} - -function textbook_companion_path() { - return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/'; -} - -/****************************** DELETION FUNCTIONS ****************************/ - -function delete_example($example_id) -{ - global $user; - $root_path = textbook_companion_path(); - $status = TRUE; - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id); - $example_data = db_fetch_object($example_q); - if (!$example_data) - { - drupal_set_message(t('Invalid example.'), 'error'); - return FALSE; - } - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message(t('Invalid example chapter.'), 'error'); - return FALSE; - } - - /* deleting example files */ - $examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id); - while ($examples_files_data = db_fetch_object($examples_files_q)) - { - if (!file_exists($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $examples_files_data->filepath)), 'error'); - continue; - } - - /* removing example file */ - if (!unlink($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file', array('!file' => $examples_files_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting example file"; - $param['standard']['body'] = "Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - example id : " . $example_id . " - file id : " . $examples_files_data->id . " - file path : " . $examples_files_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id); - } - } - - if (!$status) - return FALSE; - - /* removing example folder */ - $ex_path = $chapter_data->preference_id . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number; - $dir_path = $root_path . $ex_path; - if (is_dir($dir_path)) - { - if (!rmdir($dir_path)) - { - drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } - } else { - drupal_set_message(t('Cannot delete example folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - - /* deleting example dependency and exmaple database entries */ - db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id); - db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id); - - return $status; -} - -function delete_chapter($chapter_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message('Invalid chapter.', 'error'); - return FALSE; - } - - /* deleting examples */ - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id); - while ($example_data = db_fetch_object($example_q)) - { - if (!delete_example($example_data->id)) - $status = FALSE; - } - - if ($status) - { - $dir_path = $root_path . $chapter_data->preference_id . '/CH' . $chapter_data->number; - - if (is_dir($dir_path)) - { - $res = rmdir($dir_path); - if (!$res) - { - drupal_set_message(t('Error deleting chapter folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting chapter details from database */ - db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - return TRUE; - } - } else { - drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - } - return FALSE; -} - -function delete_book($book_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id); - $preference_data = db_fetch_object($preference_q); - if (!$preference_data) - { - drupal_set_message('Invalid book.', 'error'); - return FALSE; - } - - /* delete chapters */ - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id); - while ($chapter_data = db_fetch_object($chapter_q)) - { - if (!delete_chapter($chapter_data->id)) - { - $status = FALSE; - } - } - return $status; -} - -function delete_file($file_id) -{ - $root_path = textbook_companion_path(); - - $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id); - $file_data = db_fetch_object($file_q); - if (!$file_data) - { - drupal_set_message('Invalid file specified.', 'error'); - return FALSE; - } - - if (!file_exists($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $file_data->filepath)), 'error'); - return FALSE; - } - - /* removing example file */ - if (!unlink($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file', array('!file' => $file_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting file"; - $param['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - file id : " . $file_id . " - file path : " . $file_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id); - return TRUE; - } -} - -function del_book_pdf($book_id) -{ - $root_path = textbook_companion_path(); - $dir_path = $root_path . "latex/"; - $pdf_filename = "book_" . $book_id . ".pdf"; - if (file_exists($dir_path . $pdf_filename)) - unlink($dir_path . $pdf_filename); -} -function textbook_companion_init(){ - //drupal_add_css('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external')); - //drupal_add_js('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external')); - //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery-ui.js'); - //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery.js'); - drupal_add_css(drupal_get_path('module', 'textbook_companion') .'/css/textbook_companion.css'); - drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/textbook_companion.js'); -} diff --git a/textbook_companion.module.bak-16Sep2012 b/textbook_companion.module.bak-16Sep2012 deleted file mode 100755 index f83485b..0000000 --- a/textbook_companion.module.bak-16Sep2012 +++ /dev/null @@ -1,1476 +0,0 @@ -<?php -// $Id$ - -/** - * Implementation of hook_menu(). - */ -function textbook_companion_menu() -{ - $items = array(); - - /* users */ - $items['proposal'] = array( - 'title' => 'Book Proposal Form', - 'description' => 'Book Proposal Form.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_proposal_form'), - 'access callback' => 'user_access', - 'access arguments' => array('create book proposal'), - 'type' => MENU_NORMAL_ITEM, - ); - - /* for reviewers */ - $items['manage_proposal'] = array( - 'title' => 'Manage Book Proposals', - 'description' => 'Manage Book Proposals', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/pending'] = array( - 'title' => 'Pending Proposals', - 'description' => 'Pending Proposals Queue', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/all'] = array( - 'title' => 'All Proposals', - 'description' => 'All Proposals', - 'page callback' => '_proposal_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category'] = array( - 'title' => 'Categorize', - 'description' => 'Categorize Books', - 'page callback' => '_category_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/approve'] = array( - 'title' => 'Proposal Approval', - 'description' => 'Proposal Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_approval_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/status'] = array( - 'title' => 'Proposal Status', - 'description' => 'Proposal Status', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_status_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/edit'] = array( - 'title' => 'Edit Proposal', - 'description' => 'Edit Proposal', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category/edit'] = array( - 'title' => 'Edit Category', - 'description' => 'Edit category', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('category_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - - $items['code_approval'] = array( - 'title' => 'Manage Code Approval', - 'description' => 'Manage Code Approval', - 'page callback' => 'code_approval', - 'access arguments' => array('approve code'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'code_approval.inc', - ); - $items['code_approval/approve'] = array( - 'title' => 'Code Approval', - 'description' => 'Code Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('code_approval_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'code_approval.inc', - ); - $items['code_approval/bulk'] = array( - 'title' => 'Bulk Manage', - 'description' => 'Bulk Mangage', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('bulk_approval_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'code_approval.inc', - ); - $items['code_approval/editcode'] = array( - 'title' => 'Admin Edit Example', - 'description' => 'Admin Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_admin_edit_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'weight' => 3, - 'file' => 'editcodeadmin.inc', - ); - $items['code_approval/notes'] = array( - 'title' => 'Notes for Reviewers', - 'description' => 'Notes for Reviewers', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_notes_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_CALLBACK, - 'weight' => 4, - 'file' => 'notes.inc', - ); - - $items['textbook_companion/code'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'list_chapters', - 'access callback' => 'user_access', - 'access arguments' => array('upload code'), - 'file' => 'general.inc', - ); - $items['textbook_companion/code/list_chapters'] = array( - 'title' => 'List Chapters', - 'description' => 'List Chapters', - 'page callback' => 'list_chapters', - 'access arguments' => array('upload code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'general.inc', - 'weight' => 1, - ); - $items['textbook_companion/code/upload'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'upload_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'code.inc', - 'weight' => 2, - ); - $items['textbook_companion/code/upload_dep'] = array( - 'title' => 'Upload Dependency', - 'description' => 'Upload Dependency Files', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_dependency_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'dependency.inc', - 'weight' => 3, - ); - $items['textbook_companion/code/edit'] = array( - 'title' => 'Edit Example', - 'description' => 'Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_edit_form'), - 'access arguments' => array('edit uploaded code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/delete'] = array( - 'title' => 'Delete Example', - 'description' => 'Delete Example', - 'page callback' => '_upload_examples_delete', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'code.inc', - ); - $items['textbook_companion/code/chapter/edit'] = array( - 'title' => 'Edit Chapter Title', - 'description' => 'Edit Chapter Title', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('edit_chapter_title_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/list_examples'] = array( - 'title' => 'List Examples', - 'description' => 'List Examples', - 'page callback' => 'list_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'general.inc', - 'weight' => 3, - ); - - $items['textbook_search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'search.inc', - ); - $items['textbook_search/search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 1, - ); - $items['textbook_search/book'] = array( - 'title' => 'Browse By Title of the Book', - 'description' => '', - 'page callback' => 'textbook_companion_browse_book', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 2, - ); - $items['textbook_search/author'] = array( - 'title' => 'Browse By Author Name', - 'description' => '', - 'page callback' => 'textbook_companion_browse_author', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 3, - ); - - $items['textbook_run'] = array( - 'title' => 'Download Codes', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_run_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'run.inc', - ); - - /* download callbacks */ - $items['download/file'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/dependency'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_dependency_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/example'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_chapter', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - - /* reviewer download */ - $items['full_download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_chapter', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - $items['full_download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - - /* latex script for book generation */ - $items['textbook_companion/generate_book'] = array( - 'title' => 'Generate Book', - 'description' => 'Generate Book From Latex Script', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('generate book'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - $items['textbook_companion/delete_book'] = array( - 'title' => 'Delete Book PDF', - 'description' => 'Delete Book PDF', - 'page callback' => 'textbook_companion_delete_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - - /* general purpose callbacks */ - $items['textbook_companion/ajax'] = array( - 'title' => 'Ajax', - 'description' => 'Ajax', - 'page callback' => 'textbook_companion_ajax', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - - /* for admin */ - $items['admin/settings/book_companion'] = array( - 'title' => 'Book Companion Settings', - 'description' => 'Book Companion Settings', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_settings_form'), - 'access arguments' => array('administer book companion'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'settings.inc', - ); - - return $items; -} - -/** - * Implementation of hook_perm(). - */ -function textbook_companion_perm() { - return array('create book proposal', 'approve book proposal', 'approve code', 'upload code', 'edit uploaded code', 'download code', 'create feedback', 'bulk manage code', 'bulk delete code', 'edit book proposal', 'administer book companion', 'generate book'); -} - -function book_proposal_form($form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* check if user has already submitted a proposal */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); - if ($proposal_q) - { - if ($proposal_data = db_fetch_object($proposal_q)) - { - switch ($proposal_data->proposal_status) - { - case 0: - drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); - return; - break; - case 1: - drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status'); - drupal_goto(''); - return; - break; - case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error'); - break; - case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status'); - break; - default: - drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - break; - } - } - } - - $form['imp_notice'] = array( - '#type' => 'item', - '#value' => '<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['how_project'] = array( - '#type' => 'select', - '#title' => t('How did you come to know about this project'), - '#options' => array('Scilab Website' => 'Scilab 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' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), - '#required' => TRUE, - ); - $form['university'] = array( - '#type' => 'textfield', - '#title' => t('University/Institute'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['faculty'] = array( - '#type' => 'textfield', - '#title' => t('College Teacher/Professor'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['reviewer'] = array( - '#type' => 'textfield', - '#title' => t('Reviewer'), - '#size' => 30, - '#maxlength' => 50, - ); - $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['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, - ); - $form['preference1']['isbn1'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference1']['publisher1'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference1']['edition1'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference1']['year1'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference2']['author2'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference2']['isbn2'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference2']['publisher2'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference2']['edition2'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference2']['year2'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference3']['author3'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference3']['isbn3'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference3']['publisher3'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference3']['edition3'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference3']['year3'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - return $form; -} - -function book_proposal_form_validate($form, &$form_state) -{ - /* mobile */ - if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) - form_set_error('mobile', t('Invalid mobile number')); - - /* date of completion */ - if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date'])) - form_set_error('completion_date', t('Invalid expected date of completion')); - - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $d = (int)$d; $m = (int)$m; $y = (int)$y; - if (!checkdate($m, $d, $y)) - form_set_error('completion_date', t('Invalid expected date of completion')); - if (mktime(0, 0, 0, $m, $d, $y) <= time()) - form_set_error('completion_date', t('Expected date of completion should be in future')); - - /* edition */ - if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1'])) - form_set_error('edition1', t('Invalid edition for Book Preference 1')); - 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-9][0-9]{0,1}$/', $form_state['values']['edition3'])) - form_set_error('edition3', t('Invalid edition for Book Preference 3')); - - /* year of publication */ - if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1'])) - form_set_error('year1', t('Invalid year of pulication for Book Preference 1')); - 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 (!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')); - - /* year of publication */ - $cur_year = date('Y'); - if ((int)$form_state['values']['year1'] > $cur_year) - form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1')); - 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 ((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')); - - /* isbn */ - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1'])) - form_set_error('isbn1', t('Invalid ISBN for Book Preference 1')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])) - form_set_error('isbn2', t('Invalid ISBN for Book Preference 2')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) - form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); - return; -} - -function book_proposal_form_submit($form, &$form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* completion date to timestamp */ - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y); - - /* inserting the user proposal */ - $result = db_query("INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status) VALUES - (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)", - $user->uid, - 0, - ucwords(strtolower($form_state['values']['full_name'])), - $form_state['values']['mobile'], - $form_state['values']['how_project'], - $form_state['values']['course'], - $form_state['values']['branch'], - $form_state['values']['university'], - ucwords(strtolower($form_state['values']['faculty'])), - ucwords(strtolower($form_state['values']['reviewer'])), - $completion_date_timestamp, - time(), - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); - return; - } - /* proposal id */ - $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id'); - - /* 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 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your first book preference.'), 'error'); - } - } - - /* inserting second book preference */ - 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, - 2, - ucwords(strtolower($form_state['values']['book2'])), - ucwords(strtolower($form_state['values']['author2'])), - $form_state['values']['isbn2'], - ucwords(strtolower($form_state['values']['publisher2'])), - $form_state['values']['edition2'], - $form_state['values']['year2'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your second book preference.'), 'error'); - } - } - - /* inserting third book preference */ - 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, - 3, - ucwords(strtolower($form_state['values']['book3'])), - ucwords(strtolower($form_state['values']['author3'])), - $form_state['values']['isbn3'], - ucwords(strtolower($form_state['values']['publisher3'])), - $form_state['values']['edition3'], - $form_state['values']['year3'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your third book preference.'), 'error'); - } - } - - /* sending email */ - $email_to = $user->mail . ', ' . variable_get('textbook_companion_emails', ''); - $param['proposal_received']['proposal_id'] = $proposal_id; - $param['proposal_received']['user_id'] = $user->uid; - if (!drupal_mail('textbook_companion', 'proposal_received', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); -} - -/** - * Implementation of hook_mail(). - */ -function textbook_companion_mail($key, &$message, $params) -{ - global $user; - $language = $message['language']; - switch ($key) - { - case 'proposal_received': - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_received']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following book proposal: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Your proposal is under review and you will soon receive an email from us regarding the same. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_disapproved': - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been disapproved: - -Reason for disapproval: ' . $proposal_data->message . ' - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_approved': - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been approved: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_completed': - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_completed']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_completed']['user_id']); - - $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Following book has been completed sucessfully by you: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Your book is now available at following link to download. - -http://scilab.in/textbook_run/' . $approved_preference_data->id . ' - -Now you should be able to propose a new book... - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_uploaded': - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_uploaded']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_uploaded']['user_id']); - - $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated': - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated']['user_id']); - - $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is still under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated_admin': - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated_admin']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated_admin']['user_id']); - - $message['subject'] = t('[!site_name] Reviewer have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Reviewer have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_approved': - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_approved']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been approved: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_disapproved': - $user_data = user_load($params['example_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been disapproved: - -Example number : ' . $params['example_disapproved']['example_number'] . ' -Caption : ' . $params['example_disapproved']['example_caption'] . ' - -Reason for dis-approval : ' . $params['example_disapproved']['message'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_deleted_user': - $user_data = user_load($params['example_deleted_user']['user_id']); - - $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following pending example has been deleted : - -Title of the Book : ' . $params['example_deleted_user']['book_title'] . ' -Title of the Chapter : ' . $params['example_deleted_user']['chapter_title'] . ' -Example number : ' . $params['example_deleted_user']['example_number'] . ' -Caption : ' . $params['example_deleted_user']['example_caption'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'dependency_uploaded': - $user_data = user_load($params['dependency_uploaded']['user_id']); - $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); - - $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded following dependency files : - ' . $dependency_files . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'feedback_received': - $user_data = user_load($params['feedback_received']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following feedback - -Title of the Book: ' . $params['feedback_received']['book_title'] . ' -Title of the Chapter: ' . $params['feedback_received']['chapter_number'] . ' ' . $params['feedback_received']['chapter_title'] . ' -Example No.: ' . $params['feedback_received']['example_no'] . ' - -Your feedback : -' . $params['feedback_received']['feedback'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'standard': - $message['subject'] = $params['standard']['subject']; - $message['body'] = $params['standard']['body']; - break; - } -} - -/* AJAX CALLS */ -function textbook_companion_ajax() -{ - $query_type = arg(2); - if ($query_type == 'chapter_title') - { - $chapter_number = arg(3); - $preference_id = arg(4); - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if ($chapter_data = db_fetch_object($chapter_q)) - { - echo $chapter_data->name; - return; - } - } else if ($query_type == 'example_exists') { - $chapter_number = arg(3); - $preference_id = arg(4); - $example_number = arg(5); - - $chapter_id = 0; - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if (!$chapter_data = db_fetch_object($chapter_q)) - { - echo ''; - return; - } else { - $chapter_id = $chapter_data->id; - } - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s' LIMIT 1", $chapter_id, $example_number); - if ($example_data = db_fetch_object($example_q)) - { - if ($example_data->approval_status == 1) - echo 'Warning! Example already approved. You cannot upload the same example again.'; - else - echo 'Warning! Example already uploaded. Delete the example and reupload it.'; - return; - } - } - echo ''; -} - -/*************************** VALIDATION FUNCTIONS *****************************/ -function textbook_companion_check_valid_filename($file_name) { - if (!preg_match('/^[0-9a-zA-Z\_\.]+$/', $file_name)) - return FALSE; - else - if (substr_count($file_name, ".") > 1) - return FALSE; - else - return TRUE; -} - -function check_name($name = '') { - if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) - return FALSE; - else - return TRUE; -} - -function check_chapter_number($name = '') { - if (!preg_match('/^([0-9])+(\.([0-9a-zA-Z])+)+$/', $name)) - return FALSE; - else - return TRUE; -} - -function textbook_companion_path() { - return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/'; -} - -/****************************** DELETION FUNCTIONS ****************************/ - -function delete_example($example_id) -{ - global $user; - $root_path = textbook_companion_path(); - $status = TRUE; - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id); - $example_data = db_fetch_object($example_q); - if (!$example_data) - { - drupal_set_message(t('Invalid example.'), 'error'); - return FALSE; - } - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message(t('Invalid example chapter.'), 'error'); - return FALSE; - } - - /* deleting example files */ - $examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id); - while ($examples_files_data = db_fetch_object($examples_files_q)) - { - if (!file_exists($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $examples_files_data->filepath)), 'error'); - continue; - } - - /* removing example file */ - if (!unlink($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file', array('!file' => $examples_files_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting example file"; - $param['standard']['body'] = "Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - example id : " . $example_id . " - file id : " . $examples_files_data->id . " - file path : " . $examples_files_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id); - } - } - - if (!$status) - return FALSE; - - /* removing example folder */ - $ex_path = $chapter_data->preference_id . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number; - $dir_path = $root_path . $ex_path; - if (is_dir($dir_path)) - { - if (!rmdir($dir_path)) - { - drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } - } else { - drupal_set_message(t('Cannot delete example folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - - /* deleting example dependency and exmaple database entries */ - db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id); - db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id); - - return $status; -} - -function delete_chapter($chapter_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message('Invalid chapter.', 'error'); - return FALSE; - } - - /* deleting examples */ - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id); - while ($example_data = db_fetch_object($example_q)) - { - if (!delete_example($example_data->id)) - $status = FALSE; - } - - if ($status) - { - $dir_path = $root_path . $chapter_data->preference_id . '/CH' . $chapter_data->number; - - if (is_dir($dir_path)) - { - $res = rmdir($dir_path); - if (!$res) - { - drupal_set_message(t('Error deleting chapter folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting chapter details from database */ - db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - return TRUE; - } - } else { - drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - } - return FALSE; -} - -function delete_book($book_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id); - $preference_data = db_fetch_object($preference_q); - if (!$preference_data) - { - drupal_set_message('Invalid book.', 'error'); - return FALSE; - } - - /* delete chapters */ - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id); - while ($chapter_data = db_fetch_object($chapter_q)) - { - if (!delete_chapter($chapter_data->id)) - { - $status = FALSE; - } - } - return $status; -} - -function delete_file($file_id) -{ - $root_path = textbook_companion_path(); - - $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id); - $file_data = db_fetch_object($file_q); - if (!$file_data) - { - drupal_set_message('Invalid file specified.', 'error'); - return FALSE; - } - - if (!file_exists($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $file_data->filepath)), 'error'); - return FALSE; - } - - /* removing example file */ - if (!unlink($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file', array('!file' => $file_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting file"; - $param['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - file id : " . $file_id . " - file path : " . $file_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id); - return TRUE; - } -} - -function del_book_pdf($book_id) -{ - $root_path = textbook_companion_path(); - $dir_path = $root_path . "latex/"; - $pdf_filename = "book_" . $book_id . ".pdf"; - if (file_exists($dir_path . $pdf_filename)) - unlink($dir_path . $pdf_filename); -} diff --git a/textbook_companion.module.bak-23Oct2013 b/textbook_companion.module.bak-23Oct2013 deleted file mode 100755 index 9c8d4e5..0000000 --- a/textbook_companion.module.bak-23Oct2013 +++ /dev/null @@ -1,1785 +0,0 @@ -<?php -// $Id$ - -/** - * Implementation of hook_menu(). - */ -function textbook_companion_menu() -{ - $items = array(); - - /* users */ - $items['proposal'] = array( - 'title' => 'Book Proposal Form', - 'description' => 'Book Proposal Form.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_proposal_form'), - 'access callback' => 'user_access', - 'access arguments' => array('create book proposal'), - 'type' => MENU_NORMAL_ITEM, - ); - - /* for reviewers */ - $items['manage_proposal'] = array( - 'title' => 'Manage Book Proposals', - 'description' => 'Manage Book Proposals', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/pending'] = array( - 'title' => 'Pending Proposals', - 'description' => 'Pending Proposals Queue', - 'page callback' => '_proposal_pending', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/all'] = array( - 'title' => 'All Proposals', - 'description' => 'All Proposals', - 'page callback' => '_proposal_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category'] = array( - 'title' => 'Categorize', - 'description' => 'Categorize Books', - 'page callback' => '_category_all', - 'access callback' => 'user_access', - 'access arguments' => array('approve book proposal'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/approve'] = array( - 'title' => 'Proposal Approval', - 'description' => 'Proposal Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_approval_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/status'] = array( - 'title' => 'Proposal Status', - 'description' => 'Proposal Status', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_status_form'), - 'access arguments' => array('approve book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/edit'] = array( - 'title' => 'Edit Proposal', - 'description' => 'Edit Proposal', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('proposal_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - $items['manage_proposal/category/edit'] = array( - 'title' => 'Edit Category', - 'description' => 'Edit category', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('category_edit_form'), - 'access arguments' => array('edit book proposal'), - 'type' => MENU_CALLBACK, - 'file' => 'manage_proposal.inc', - ); - - $items['code_approval'] = array( - 'title' => 'Manage Code Approval', - 'description' => 'Manage Code Approval', - 'page callback' => 'code_approval', - 'access arguments' => array('approve code'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'code_approval.inc', - ); - $items['code_approval/approve'] = array( - 'title' => 'Code Approval', - 'description' => 'Code Approval', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('code_approval_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 1, - 'file' => 'code_approval.inc', - ); - $items['code_approval/bulk'] = array( - 'title' => 'Bulk Manage', - 'description' => 'Bulk Mangage', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('bulk_approval_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 2, - 'file' => 'code_approval.inc', - ); - $items['code_approval/editcode'] = array( - 'title' => 'Admin Edit Example', - 'description' => 'Admin Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_admin_edit_form'), - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'weight' => 3, - 'file' => 'editcodeadmin.inc', - ); - $items['code_approval/notes'] = array( - 'title' => 'Notes for Reviewers', - 'description' => 'Notes for Reviewers', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('book_notes_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_CALLBACK, - 'weight' => 4, - 'file' => 'notes.inc', - ); - $items['code_approval/dependency'] = array( - 'title' => 'Dependency', - 'description' => 'Dependency', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_dependency_approval_form'), - 'access arguments' => array('bulk manage code'), - 'type' => MENU_LOCAL_TASK, - 'weight' => 3, - 'file' => 'dependency_approval.inc', - ); - - $items['textbook_companion/code'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'list_chapters', - 'access callback' => 'user_access', - 'access arguments' => array('upload code'), - 'file' => 'general.inc', - ); - $items['textbook_companion/code/list_chapters'] = array( - 'title' => 'List Chapters', - 'description' => 'List Chapters', - 'page callback' => 'list_chapters', - 'access arguments' => array('upload code'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'general.inc', - 'weight' => 1, - ); - $items['textbook_companion/code/upload'] = array( - 'title' => 'Code Submission', - 'description' => 'Code Submission', - 'page callback' => 'upload_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'code.inc', - 'weight' => 2, - ); - $items['textbook_companion/code/upload_dep'] = array( - 'title' => 'Upload Dependency', - 'description' => 'Upload Dependency Files', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_dependency_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'dependency.inc', - 'weight' => 3, - ); - $items['textbook_companion/code/edit'] = array( - 'title' => 'Edit Example', - 'description' => 'Edit Example', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_edit_form'), - 'access arguments' => array('edit uploaded code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/delete'] = array( - 'title' => 'Delete Example', - 'description' => 'Delete Example', - 'page callback' => '_upload_examples_delete', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'code.inc', - ); - $items['textbook_companion/code/chapter/edit'] = array( - 'title' => 'Edit Chapter Title', - 'description' => 'Edit Chapter Title', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('edit_chapter_title_form'), - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'editcode.inc', - ); - $items['textbook_companion/code/list_examples'] = array( - 'title' => 'List Examples', - 'description' => 'List Examples', - 'page callback' => 'list_examples', - 'access arguments' => array('upload code'), - 'type' => MENU_CALLBACK, - 'file' => 'general.inc', - 'weight' => 3, - ); - - $items['textbook_search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'search.inc', - ); - $items['textbook_search/search'] = array( - 'title' => 'Book Search', - 'description' => '', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_search_form'), - 'access arguments' => array('access content'), - 'type' => MENU_DEFAULT_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 1, - ); - $items['textbook_search/book'] = array( - 'title' => 'By Book Title', - 'description' => '', - 'page callback' => 'textbook_companion_browse_book', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 2, - ); - $items['textbook_search/author'] = array( - 'title' => 'By Author', - 'description' => '', - 'page callback' => 'textbook_companion_browse_author', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 3, - ); - $items['textbook_search/college'] = array( - 'title' => 'By College', - 'description' => '', - 'page callback' => 'textbook_companion_browse_college', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_browse_college_form'), - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 4, - ); - $items['textbook_search/student'] = array( - 'title' => 'By Student', - 'description' => '', - 'page callback' => 'textbook_companion_browse_student', - 'access arguments' => array('access content'), - 'type' => MENU_LOCAL_TASK, - 'file' => 'search.inc', - 'weight' => 5, - ); - - $items['textbook_run'] = array( - 'title' => 'Download Codes', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_run_form'), - 'access arguments' => array('access content'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'run.inc', - ); - - /* download callbacks */ - $items['download/file'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/dependency'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_dependency_file', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/example'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_example', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_chapter', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - $items['download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('download code'), - 'type' => MENU_CALLBACK, - 'file' => 'download.inc', - ); - - /* reviewer download */ - $items['full_download/chapter'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_chapter', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - $items['full_download/book'] = array( - 'title' => 'Code Download', - 'description' => 'Code Download', - 'page callback' => 'textbook_companion_download_full_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'full_download.inc', - ); - - /* latex script for book generation */ - $items['textbook_companion/generate_book'] = array( - 'title' => 'Generate Book', - 'description' => 'Generate Book From Latex Script', - 'page callback' => 'textbook_companion_download_book', - 'access arguments' => array('generate book'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - $items['textbook_companion/delete_book'] = array( - 'title' => 'Delete Book PDF', - 'description' => 'Delete Book PDF', - 'page callback' => 'textbook_companion_delete_book', - 'access arguments' => array('approve code'), - 'type' => MENU_CALLBACK, - 'file' => 'latex.inc', - ); - - /* general purpose callbacks */ - $items['textbook_companion/ajax'] = array( - 'title' => 'Ajax', - 'description' => 'Ajax', - 'page callback' => 'textbook_companion_ajax', - 'access arguments' => array('access content'), - 'type' => MENU_CALLBACK, - ); - - /* for admin */ - $items['admin/settings/book_companion'] = array( - 'title' => 'Book Companion Settings', - 'description' => 'Book Companion Settings', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('textbook_companion_settings_form'), - 'access arguments' => array('administer book companion'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'settings.inc', - ); - /* for data entry */ - $items['dataentry_book'] = array( - 'title' => 'Approved books list', - 'page callback' => '_data_entry_proposal_all', - 'access callback' => 'user_access', - 'access arguments' => array('dataentry book proposal'), - 'file' => 'manage_proposal.inc', - ); - $items['dataentry_edit'] = array( - 'title' => 'Edit book details', - 'page callback' => 'dataentry_edit', - 'access callback' => 'user_access', - 'access arguments' => array('dataentry book proposal'), - 'type' => MENU_NORMAL_ITEM, - 'file' => 'manage_proposal.inc', - ); - /*Cheque Details and Contact Form */ - $items['cheque_manage/all'] = array( - 'title' => 'Cheque Proposals', - 'description' => 'Cheque Proposals', - 'page callback' => 'cheque_proposal_all', - 'access arguments' => array('cheque proposal'), - 'file' => 'cheque_manage.inc', - ); - $items['mycontact'] = array( - 'title' => 'Update Contact Details', - 'description' => 'Update Contact Details', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('contact_details'), - 'access arguments' => array('contact_details'), - 'file' => 'cheque_contact.inc', - ); - - $items['cheque_contct'] = array( - 'title' => 'Report', - 'description' => 'Cheque Contact Form', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_contct_form'), - 'access arguments' => array('cheque contct form'), - 'file' => 'cheque_contact.inc', - ); - $items['cheque_contact/status'] = array( - 'title' => 'Cheque Status', - 'description' => 'Cheque Status', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_status_form'), - 'access' => 'user_is_logged_in', - 'access arguments' => array('cheque status form'), - 'file' => 'cheque_contact.inc', - ); - $items['cheque_contct/report'] = array( - 'title' => 'Report', - 'description' => 'Report', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('cheque_report_form'), - 'access' => 'user_is_logged_in', - 'access arguments' => array('cheque report form'), - 'file' => 'cheque_contact.inc', - ); - $items['certificate'] = array( - 'title' => 'List Of All Certificates', - 'description' => 'List Of All Certificates', - 'page callback' => '_list_all_certificates', - 'access arguments' => array('list all certificates'), - 'file' => 'pdf/list_all_certificates.inc', - ); - $items['certificate/generate_pdf'] = array( - 'title' => 'Download Certificate', - 'description' => 'Download Certificate', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('generate_pdf'), - 'access arguments' => array('generate pdf'), - 'file' => 'pdf/generate_pdf.inc', - ); - $items['manage_proposal/paper_submission'] = array( - 'title' => 'Application Submission', - 'description' => 'Application Submission', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('paper_submission_form'), - 'access arguments' => array('paper submission form'), - 'type' => MENU_CALLBACK, - 'file' => 'cheque_contact.inc', - ); - return $items; -} - -/** - * Implementation of hook_perm(). - */ -function textbook_companion_perm() { - - return array('create book proposal', 'approve book proposal', 'approve code', 'upload code', 'edit uploaded code', 'download code', 'create feedback', 'bulk manage code', 'bulk delete code', 'edit book proposal', 'administer book companion', 'generate book', 'cheque contct form', 'contact_details', 'comment cheque', 'list all certificates', 'generate pdf', 'paper submission form', 'cheque status form' ,'cheque report form' ,'cheque proposal'); -} - - -function book_proposal_form($form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* check if user has already submitted a proposal */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); - if ($proposal_q) - { - if ($proposal_data = db_fetch_object($proposal_q)) - { - switch ($proposal_data->proposal_status) - { - case 0: - drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); - return; - break; - case 1: - drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status'); - drupal_goto(''); - return; - break; - case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error'); - break; - case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status'); - break; - default: - drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - break; - } - } - } - - $form['imp_notice'] = array( - '#type' => 'item', - '#value' => '<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('Scilab Website' => 'Scilab 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' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), - '#required' => TRUE, - ); - $form['university'] = array( - '#type' => 'textfield', - '#title' => t('University/Institute'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['faculty'] = array( - '#type' => 'textfield', - '#title' => t('College Teacher/Professor'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['faculty_email'] = array( - '#type' => 'textfield', - '#title' => t('Teacher/Professor Email Id'), - '#default_value' => '@email.com', - '#size' => 30, - '#maxlength' => 50, - ); - $form['reviewer'] = array( - '#type' => 'textfield', - '#title' => t('Reviewer'), - '#size' => 30, - '#maxlength' => 50, - ); - $form['version'] = array( - '#type' => 'select', - '#title' => t('Version'), - '#options' => array('scilab 5.4.1' => 'Scilab 5.4.1', - 'scilab 5.3.3' => 'Scilab 5.3.3', - 'olderversion' => 'Older Version'), - '#required' => TRUE, - ); - $form['older'] = array( - '#type' => 'textfield', - '#size' => 30, - '#maxlength' => 50, - //'#required' => TRUE, - '#description' => t('Specify the Older version used'), - ); - $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, - ); - /*$form['scilab_version'] = array( - '#type' => 'textfield', - '#title' => t('Scilab Version'), - '#required' => TRUE, - '#size' => 10, - '#maxlength' => 10, - );*/ - $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, - ); - $form['preference1']['isbn1'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference1']['publisher1'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference1']['edition1'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference1']['year1'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference2']['author2'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference2']['isbn2'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference2']['publisher2'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference2']['edition2'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference2']['year2'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#required' => TRUE, - ); - $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, - ); - $form['preference3']['author3'] = array( - '#type' => 'textfield', - '#title' => t('Author Name'), - '#size' => 30, - '#maxlength' => 100, - '#required' => TRUE, - ); - $form['preference3']['isbn3'] = array( - '#type' => 'textfield', - '#title' => t('ISBN No'), - '#size' => 30, - '#maxlength' => 25, - '#required' => TRUE, - ); - $form['preference3']['publisher3'] = array( - '#type' => 'textfield', - '#title' => t('Publisher & Place'), - '#size' => 30, - '#maxlength' => 50, - '#required' => TRUE, - ); - $form['preference3']['edition3'] = array( - '#type' => 'textfield', - '#title' => t('Edition'), - '#size' => 4, - '#maxlength' => 2, - '#required' => TRUE, - ); - $form['preference3']['year3'] = array( - '#type' => 'textfield', - '#title' => t('Year of pulication'), - '#size' => 4, - '#maxlength' => 4, - '#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['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - return $form; -} - -function book_proposal_form_validate($form, &$form_state) -{ - /* mobile */ - if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) - form_set_error('mobile', t('Invalid mobile number')); - - /* date of completion */ - if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date'])) - form_set_error('completion_date', t('Invalid expected date of completion')); - - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $d = (int)$d; $m = (int)$m; $y = (int)$y; - if (!checkdate($m, $d, $y)) - form_set_error('completion_date', t('Invalid expected date of completion')); - if (mktime(0, 0, 0, $m, $d, $y) <= time()) - form_set_error('completion_date', t('Expected date of completion should be in future')); - - /* edition */ - if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1'])) - form_set_error('edition1', t('Invalid edition for Book Preference 1')); - 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-9][0-9]{0,1}$/', $form_state['values']['edition3'])) - form_set_error('edition3', t('Invalid edition for Book Preference 3')); - - /* year of publication */ - if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1'])) - form_set_error('year1', t('Invalid year of pulication for Book Preference 1')); - 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 (!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')); - - /* year of publication */ - $cur_year = date('Y'); - if ((int)$form_state['values']['year1'] > $cur_year) - form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1')); - 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 ((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')); - - /* isbn */ - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1'])) - form_set_error('isbn1', t('Invalid ISBN for Book Preference 1')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])) - form_set_error('isbn2', t('Invalid ISBN for Book Preference 2')); - if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) - form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); - - if($form_state['values']['version'] == 'olderversion'){ - if($form_state['values']['older'] == ''){ - form_set_error('older', t('Please provide valid version')); - } - } - return; -} - -function book_proposal_form_submit($form, &$form_state) -{ - global $user; - - if (!$user->uid) { - drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); - return; - } - - /* completion date to timestamp */ - list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); - $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y); - - - $scilab_version = $form_state['values']['version']; - - if($form_state['values']['version'] == 'olderversion'){ - $scilab_version = $form_state['values']['older']; - } - - //var_dump($form_state['values']); - - $query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')"; - - $result = db_query($query); - if (!$result) - { - drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); - return; - } - /* proposal id */ - $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id'); - - /* 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 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your first book preference.'), 'error'); - } - } - - /* inserting second book preference */ - 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, - 2, - ucwords(strtolower($form_state['values']['book2'])), - ucwords(strtolower($form_state['values']['author2'])), - $form_state['values']['isbn2'], - ucwords(strtolower($form_state['values']['publisher2'])), - $form_state['values']['edition2'], - $form_state['values']['year2'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your second book preference.'), 'error'); - } - } - - /* inserting third book preference */ - 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, - 3, - ucwords(strtolower($form_state['values']['book3'])), - ucwords(strtolower($form_state['values']['author3'])), - $form_state['values']['isbn3'], - ucwords(strtolower($form_state['values']['publisher3'])), - $form_state['values']['edition3'], - $form_state['values']['year3'], - 0, - 0 - ); - if (!$result) - { - drupal_set_message(t('Error receiving your third book preference.'), 'error'); - } - } - - /* sending email */ - $email_to = $user->mail; - $param['proposal_received']['proposal_id'] = $proposal_id; - $param['proposal_received']['user_id'] = $user->uid; - if (!drupal_mail('textbook_companion', 'proposal_received', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); -} - -/** - * Implementation of hook_mail(). - */ -function textbook_companion_mail($key, &$message, $params) -{ - global $user; - $language = $message['lianguage']; - $tbc_bcc_emails = array( - 'Bcc' => variable_get('textbook_companion_emails', ''), - ); - switch ($key) - { - case 'proposal_received': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_received']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following book proposal: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Your proposal is under review and you will soon receive an email from us regarding the same. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_disapproved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - /* initializing data */ - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q); - $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 2); - $preference2_data = db_fetch_object($preference2_q); - $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q); - $user_data = user_load($params['proposal_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been disapproved: - -Reason for disapproval: ' . $proposal_data->message . ' - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Your Book Preferences : - -Book Preference 1 :- -Title of the book : ' . $preference1_data->book . ' -Author name : ' . $preference1_data->author . ' -ISBN No. : ' . $preference1_data->isbn . ' -Publisher and Place : ' . $preference1_data->publisher . ' -Edition : ' . $preference1_data->edition . ' -Year of publication : ' . $preference1_data->year . ' - -Book Preference 2 :- -Title of the book : ' . $preference2_data->book . ' -Author name : ' . $preference2_data->author . ' -ISBN No. : ' . $preference2_data->isbn . ' -Publisher and Place : ' . $preference2_data->publisher . ' -Edition : ' . $preference2_data->edition . ' -Year of publication : ' . $preference2_data->year . ' - -Book Preference 3 :- -Title of the book : ' . $preference3_data->book . ' -Author name : ' . $preference3_data->author . ' -ISBN No. : ' . $preference3_data->isbn . ' -Publisher and Place : ' . $preference3_data->publisher . ' -Edition : ' . $preference3_data->edition . ' -Year of publication : ' . $preference3_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_approved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following book proposal has been approved: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'proposal_completed': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q); - $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_completed']['proposal_id']); - $approved_preference_data = db_fetch_object($approved_preference_q); - $user_data = user_load($params['proposal_completed']['user_id']); - - $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Following book has been completed sucessfully by you: - -Full Name : ' . $proposal_data->full_name . ' -Email : ' . $user_data->mail . ' -Mobile : ' . $proposal_data->mobile . ' -Course : ' . $proposal_data->course . ' -Department/Branch : ' . $proposal_data->branch . ' -University/Institute : ' . $proposal_data->university . ' -College Teacher / Professor : ' . $proposal_data->faculty . ' -Reviewer : ' . $proposal_data->reviewer . ' -Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . ' - -Title of the book : ' . $approved_preference_data->book . ' -Author name : ' . $approved_preference_data->author . ' -ISBN No. : ' . $approved_preference_data->isbn . ' -Publisher and Place : ' . $approved_preference_data->publisher . ' -Edition : ' . $approved_preference_data->edition . ' -Year of publication : ' . $approved_preference_data->year . ' - -Your book is now available at following link to download. - -http://scilab.in/textbook_run/' . $approved_preference_data->id . ' - -Now you should be able to propose a new book... - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_uploaded': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_uploaded']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_uploaded']['user_id']); - - $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated']['user_id']); - - $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -The example is still under review. You will be notified when it has been approved. - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_updated_admin': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated_admin']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_updated_admin']['user_id']); - - $message['subject'] = t('[!site_name] Reviewer have updated example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Reviewer have updated the following example: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_approved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_approved']['example_id']); - $example_data = db_fetch_object($example_q); - $user_data = user_load($params['example_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been approved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been approved: - -Example number : ' . $example_data->number . ' -Caption : ' . $example_data->caption . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_disapproved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['example_disapproved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded example has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following example has been disapproved: - -Example number : ' . $params['example_disapproved']['example_number'] . ' -Caption : ' . $params['example_disapproved']['example_caption'] . ' - -Reason for dis-approval : ' . $params['example_disapproved']['message'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'example_deleted_user': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['example_deleted_user']['user_id']); - - $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -Your following pending example has been deleted : - -Title of the Book : ' . $params['example_deleted_user']['book_title'] . ' -Title of the Chapter : ' . $params['example_deleted_user']['chapter_title'] . ' -Example number : ' . $params['example_deleted_user']['example_number'] . ' -Caption : ' . $params['example_deleted_user']['example_caption'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'dependency_uploaded': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['dependency_uploaded']['user_id']); - $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); - - $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -You have uploaded following dependency files : - ' . $dependency_files . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'feedback_received': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $user_data = user_load($params['feedback_received']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your following feedback - -Title of the Book: ' . $params['feedback_received']['book_title'] . ' -Title of the Chapter: ' . $params['feedback_received']['chapter_number'] . ' ' . $params['feedback_received']['chapter_title'] . ' -Example No.: ' . $params['feedback_received']['example_no'] . ' - -Your feedback : -' . $params['feedback_received']['feedback'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'internshipform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['internshipform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Internship Form Application for the book - -Title of the Book: ' . $params['internshipform']['book_title'] . ' -Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . ' -Example No.: ' . $params['internshipform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - -case 'copyrighttransferform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['copyrighttransferform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Copyright Form Application for the book - -Title of the Book: ' . $params['copyrighttransferform']['book_title'] . ' -Title of the Chapter: ' . $params['copyrighttransferform']['chapter_number'] . ' ' . $params['copyrighttransferform']['chapter_title'] . ' -Example No.: ' . $params['copyrighttransferform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - -case 'undertakingform': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['undertakingform']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have received your Undertaking Form Application for the book - -Title of the Book: ' . $params['undertakingform']['book_title'] . ' -Title of the Chapter: ' . $params['undertakingform']['chapter_number'] . ' ' . $params['undertakingform']['chapter_title'] . ' -Example No.: ' . $params['undertakingform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - -case 'remark': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['remark']['user_id']); - - $message['subject'] = t('[!site_name] A remark has been given.Please check your contact detail form', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -A Remark has been given.Please check your Contact Detail Form - -Title of the Book: ' . $params['internshipform']['book_title'] . ' -Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . ' -Example No.: ' . $params['internshipform']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - case 'cheque_sent': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - $user_data = user_load($params['cheque_sent']['user_id']); - - $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language); - $message['body'] = t(' -Dear !user_name, - -We have Sent Cheque for the following book proposed - -Title of the Book: ' . $params['cheque_sent']['book_title'] . ' -Title of the Chapter: ' . $params['cheque_sent']['chapter_number'] . ' ' . $params['cheque_sent']['chapter_title'] . ' -Example No.: ' . $params['cheque_sent']['example_no'] . ' - -Best Wishes, - -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language); - break; - - - case 'standard': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - $message['subject'] = $params['standard']['subject']; - $message['body'] = $params['standard']['body']; - break; - } -} - -/* AJAX CALLS */ -function textbook_companion_ajax() -{ - $query_type = arg(2); - if ($query_type == 'chapter_title') - { - $chapter_number = arg(3); - $preference_id = arg(4); - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if ($chapter_data = db_fetch_object($chapter_q)) - { - echo $chapter_data->name; - return; - } - } else if ($query_type == 'example_exists') { - $chapter_number = arg(3); - $preference_id = arg(4); - $example_number = arg(5); - - $chapter_id = 0; - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); - if (!$chapter_data = db_fetch_object($chapter_q)) - { - echo ''; - return; - } else { - $chapter_id = $chapter_data->id; - } - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s' LIMIT 1", $chapter_id, $example_number); - if ($example_data = db_fetch_object($example_q)) - { - if ($example_data->approval_status == 1) - echo 'Warning! Example already approved. You cannot upload the same example again.'; - else - echo 'Warning! Example already uploaded. Delete the example and reupload it.'; - return; - } - } - echo ''; -} - -/*************************** VALIDATION FUNCTIONS *****************************/ -function textbook_companion_check_valid_filename($file_name) { - if (!preg_match('/^[0-9a-zA-Z\_\.]+$/', $file_name)) - return FALSE; - else - if (substr_count($file_name, ".") > 1) - return FALSE; - else - return TRUE; -} - -function check_name($name = '') { - if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) - return FALSE; - else - return TRUE; -} - -function check_chapter_number($name = '') { - if (!preg_match('/^([0-9])+(\.([0-9a-zA-Z])+)+$/', $name)) - return FALSE; - else - return TRUE; -} - -function textbook_companion_path() { - return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/'; -} - -/****************************** DELETION FUNCTIONS ****************************/ - -function delete_example($example_id) -{ - global $user; - $root_path = textbook_companion_path(); - $status = TRUE; - - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id); - $example_data = db_fetch_object($example_q); - if (!$example_data) - { - drupal_set_message(t('Invalid example.'), 'error'); - return FALSE; - } - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message(t('Invalid example chapter.'), 'error'); - return FALSE; - } - - /* deleting example files */ - $examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id); - while ($examples_files_data = db_fetch_object($examples_files_q)) - { - if (!file_exists($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $examples_files_data->filepath)), 'error'); - continue; - } - - /* removing example file */ - if (!unlink($root_path . $examples_files_data->filepath)) - { - $status = FALSE; - drupal_set_message(t('Error deleting !file', array('!file' => $examples_files_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting example file"; - $param['standard']['body'] = "Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - example id : " . $example_id . " - file id : " . $examples_files_data->id . " - file path : " . $examples_files_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id); - } - } - - if (!$status) - return FALSE; - - /* removing example folder */ - $ex_path = $chapter_data->preference_id . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number; - $dir_path = $root_path . $ex_path; - if (is_dir($dir_path)) - { - if (!rmdir($dir_path)) - { - drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } - } else { - drupal_set_message(t('Cannot delete example folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - - /* deleting example dependency and exmaple database entries */ - db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id); - db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id); - - return $status; -} - -function delete_chapter($chapter_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - $chapter_data = db_fetch_object($chapter_q); - if (!$chapter_data) - { - drupal_set_message('Invalid chapter.', 'error'); - return FALSE; - } - - /* deleting examples */ - $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id); - while ($example_data = db_fetch_object($example_q)) - { - if (!delete_example($example_data->id)) - $status = FALSE; - } - - if ($status) - { - $dir_path = $root_path . $chapter_data->preference_id . '/CH' . $chapter_data->number; - - if (is_dir($dir_path)) - { - $res = rmdir($dir_path); - if (!$res) - { - drupal_set_message(t('Error deleting chapter folder !folder', array('!folder' => $dir_path)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = "Error deleting folder " . $dir_path; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting chapter details from database */ - db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id); - return TRUE; - } - } else { - drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); - return FALSE; - } - } - return FALSE; -} - -function delete_book($book_id) -{ - $status = TRUE; - $root_path = textbook_companion_path(); - - $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id); - $preference_data = db_fetch_object($preference_q); - if (!$preference_data) - { - drupal_set_message('Invalid book.', 'error'); - return FALSE; - } - - /* delete chapters */ - $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id); - while ($chapter_data = db_fetch_object($chapter_q)) - { - if (!delete_chapter($chapter_data->id)) - { - $status = FALSE; - } - } - return $status; -} - -function delete_file($file_id) -{ - $root_path = textbook_companion_path(); - - $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id); - $file_data = db_fetch_object($file_q); - if (!$file_data) - { - drupal_set_message('Invalid file specified.', 'error'); - return FALSE; - } - - if (!file_exists($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $file_data->filepath)), 'error'); - return FALSE; - } - - /* removing example file */ - if (!unlink($root_path . $file_data->filepath)) - { - drupal_set_message(t('Error deleting !file', array('!file' => $file_data->filepath)), 'error'); - - /* sending email to admins */ - $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting file"; - $param['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : - file id : " . $file_id . " - file path : " . $file_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - return FALSE; - } else { - /* deleting example files database entries */ - db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id); - return TRUE; - } -} - -function del_book_pdf($book_id) -{ - $root_path = textbook_companion_path(); - $dir_path = $root_path . "latex/"; - $pdf_filename = "book_" . $book_id . ".pdf"; - if (file_exists($dir_path . $pdf_filename)) - unlink($dir_path . $pdf_filename); -} -function textbook_companion_init(){ - //drupal_add_css('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external')); - //drupal_add_js('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external')); - //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery-ui.js'); - //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery.js'); - drupal_add_css(drupal_get_path('module', 'textbook_companion') .'/css/textbook_companion.css'); - drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/textbook_companion.js'); -} |