'Books in Progress', 'page callback' => 'tbc_books_in_progress_all', 'access arguments' => array( 'display books in progress' ), 'type' => MENU_LOCAL_TASK, 'file' => 'display_books.inc' ); $items['proposal'] = array( 'title' => 'Book Proposal Form', 'description' => 'Book Proposal Form.', 'page callback' => 'textbook_companion_proposal_all', 'access callback' => 'user_access', 'access arguments' => array( 'create book proposal' ), 'type' => MENU_CALLBACK, 'file' => 'proposal.inc' ); $items["aicte_proposal"] = array( "title" => "AICTE Book Proposal", "description" => "AICTE Book Proposal Form", "page callback" => "textbook_companion_aicte_proposal_all", 'access arguments' => array( 'create book proposal' ), 'type' => MENU_CALLBACK, 'file' => 'proposal.inc' ); $items["nonaicte_proposal"] = array( "title" => "Book Suggestion Form ", "description" => "NON-AICTE Book Proposal Form", 'page callback' => 'textbook_companion_nonaicte_proposal_all', 'access arguments' => array( 'create book proposal' ), 'type' => MENU_CALLBACK, 'file' => 'proposal.inc' ); $items["all_proposal"] = array( "title" => "Book Proposal", "description" => "Book Proposal Form", "page callback" => "textbook_companion_aicte_proposal_all", 'access arguments' => array( 'create book proposal' ), 'type' => MENU_CALLBACK, 'file' => 'proposal.inc' ); /* 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/failed'] = array( 'title' => 'Failed Proposals', 'description' => 'Failed to submit code', 'page callback' => '_failed_all', 'access callback' => 'user_access', 'access arguments' => array( 'approve book proposal' ), 'type' => MENU_LOCAL_TASK, 'weight' => 3, '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_dep'] = array( 'title' => 'Edit Dependency', 'description' => 'Edit Dependency File', 'page callback' => 'edit_dependency', 'access arguments' => array( 'upload code' ), 'type' => MENU_CALLBACK, 'file' => 'dependency.inc' ); $items['textbook_companion/code/delete_dep'] = array( 'title' => 'Delete Dependency', 'description' => 'Delete Dependency File', 'page callback' => 'delete_dependency', 'access arguments' => array( 'upload code' ), 'type' => MENU_CALLBACK, 'file' => 'dependency.inc' ); $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_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' ); $items['download_codes'] = 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/samplecode'] = array( 'title' => 'Sample Code Download', 'description' => 'Sample Code Download', 'page callback' => 'textbook_companion_download_sample_code', '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' ); /* external reviewer download */ $items['full_download_external/chapter'] = array( 'title' => 'Code Download', 'description' => 'Code Download', 'page callback' => 'textbook_companion_download_full_chapter', 'access arguments' => array( 'download books to review' ), 'type' => MENU_CALLBACK, 'file' => 'full_download.inc' ); $items['full_download_external/book'] = array( 'title' => 'Code Download', 'description' => 'Code Download', 'page callback' => 'textbook_companion_download_full_book', 'access arguments' => array( 'download books to review' ), '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['certificates'] = 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['certificates/generate_pdf'] = array( 'title' => 'Download Certificate', 'description' => 'Download Certificate', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'generate_pdf' ), 'type' => MENU_CALLBACK, 'access arguments' => array( 'generate pdf' ), 'file' => 'pdf/generate_pdf.inc' ); $items["certificates/verify"] = array( "title" => "Certificate Verification", "page callback" => "verify_certificates", "access arguments" => array( "verify certificates" ), 'type' => MENU_CALLBACK, 'file' => 'pdf/verify_certificates.inc', ); /*******************/ $items['Summer_Internship_Forms/forms'] = array( 'title' => 'List of all Copyright Form and Undertaking Form for books', 'description' => 'List of all Copyright Form for books', 'page callback' => '_list_all_copyright_forms', 'access arguments' => array( 'list all certificates' ), 'type' => MENU_LOCAL_TASK, 'file' => 'pdf/list_all_form_pdf.inc' ); $items['Summer_Internship_Forms/copyright-form/generate_pdf'] = array( 'title' => 'Download Copyright Form for books', 'description' => 'Download Copyright Form for books', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'generate_copyright_form_pdf' ), 'access arguments' => array( 'generate pdf' ), 'type' => MENU_LOCAL_TASK, 'file' => 'pdf/generate_pdf.inc' ); $items['Summer_Internship_Forms/undertaking-form/generate_pdf'] = array( 'title' => 'Download Undertaking Form for books', 'description' => 'Download Undertaking Form for books', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'generate_undertaking_form_pdf' ), 'access arguments' => array( 'generate pdf' ), 'type' => MENU_LOCAL_TASK, '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_permission(). */ function textbook_companion_permission() { return array( "create book proposal" => array( "title" => t("Book Proposal Form"), "description" => t("Book Proposal Form.") ), "display books in progress" => array( "title" => t("Book display books in progress"), "description" => t("display books in progress.") ), "approve book proposal" => array( "title" => t("Approve book proposal"), "description" => t("Allows users to approve book proposal.") ), "approve code" => array( "title" => t("Approve code"), "description" => t("Allows users to approve code.") ), "upload code" => array( "title" => t("Upload code"), "description" => t("Allows users to upload code.") ), "edit uploaded code" => array( "title" => t("Edit uploaded code"), "description" => t("Allows users to edit uploaded code.") ), "download code" => array( "title" => t("Download code"), "description" => t("Allows users to download code.") ), "create feedback" => array( "title" => t("Create feedback"), "description" => t("Allows users to create feedback.") ), "bulk manage code" => array( "title" => t("Bulk manage code"), "description" => t("Allows users to manage Bulk code.") ), "bulk delete code" => array( "title" => t("Bulk delete code"), "description" => t("Allows users to delete bulk code.") ), "edit book proposal" => array( "title" => t("Edit book proposal"), "description" => t("Allows users to edit book proposal.") ), "administer book companion" => array( "title" => t("Administer book companion"), "description" => t("Allows users to administer book companion.") ), "generate book" => array( "title" => t("Generate book"), "description" => t("Allows users to generate book.") ), "cheque contct form" => array( "title" => t("Cheque contact form"), "description" => t("Cheque contct form.") ), "contact_details" => array( "title" => t("Contact_details"), "description" => t("Contact_details.") ), "comment cheque" => array( "title" => t("Comment cheque"), "description" => t("Comment cheque.") ), "list all certificates" => array( "title" => t("list all certificates"), "description" => t("Allows users to list all certificates.") ), "verify certificates" => array( "title" => t("Verify certificates"), "description" => t("Allows users to verify certificates.") ), "generate pdf" => array( "title" => t("Generate pdf"), "description" => t("Allows users to Generate pdf.") ), "paper submission form" => array( "title" => t("paper submission form"), "description" => t("Paper submission form.") ), "cheque status form" => array( "title" => t("Cheque status form"), "description" => t("Cheque status form.") ), "cheque report form" => array( "title" => t("Cheque report form"), "description" => t("Cheque report form.") ), "cheque proposal" => array( "title" => t("Cheque proposal"), "description" => t("Cheque proposal.") ), "download books to review" => array( "title" => t("download books to review"), "description" => t("Download books to review.") ) ); } 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 _tbc_list_of_states() { $states = array( 0 => '-Select-' ); $query = db_select('list_states_of_india'); $query->fields('list_states_of_india'); //$query->orderBy('', ''); $states_list = $query->execute(); while ($states_list_data = $states_list->fetchObject()) { $states[$states_list_data->state] = $states_list_data->state; } //$states_list_data = $states_list->fetchObject() return $states; } function _tbc_list_of_cities() { $city = array( 0 => '-Select-' ); $query = db_select('list_cities_of_india'); $query->fields('list_cities_of_india'); $query->orderBy('city', 'ASC'); $city_list = $query->execute(); while ($city_list_data = $city_list->fetchObject()) { $city[$city_list_data->city] = $city_list_data->city; } //$city_list_data = $city_list->fetchObject() return $city; } function _tbc_list_of_departments() { $query = db_select('list_of_departments'); $query->fields('list_of_departments'); $query->orderBy('id', 'DESC'); $department_list = $query->execute(); while ($department_list_data = $department_list->fetchObject()) { $department[$department_list_data->department] = $department_list_data->department; } //$department_list_data = $department_list->fetchObject() return $department; } function _tbc_list_of_category($category_id = NULL) { if ($category_id == NULL) { $query = db_select('list_of_category'); $query->fields('list_of_category'); $query->orderBy('id', 'ASC'); $category_list = $query->execute(); } //$category_id == NULL else { $query = db_select('list_of_category'); $query->fields('list_of_category'); $query->condition('category_id', $category_id); $query->orderBy('id', 'ASC'); $category_list = $query->execute(); } while ($category_list_data = $category_list->fetchObject()) { $category[$category_list_data->category_id] = $category_list_data->category_name; } //$category_list_data = $category_list->fetchObject() return $category; } function _tbc_sentence_case($string) { $string =ucwords(strtolower($string)); foreach (array('-', '\'') as $delimiter) { if (strpos($string, $delimiter)!==false) { $string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string))); } } return $string; } /*************************** 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/'; } function textbook_companion_samplecode_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'tbc_sample_code/'; } /****************************** 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);*/ $query = db_select('textbook_companion_example'); $query->fields('textbook_companion_example'); $query->condition('id', $example_id); $example_q = $query->execute(); $example_data = $example_q->fetchObject(); if (!$example_data) { drupal_set_message(t('Invalid example.'), 'error'); return FALSE; } //!$example_data /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id); $chapter_data = db_fetch_object($chapter_q);*/ $query = db_select('textbook_companion_chapter'); $query->fields('textbook_companion_chapter'); $query->condition('id', $example_data->chapter_id); $chapter_q = $query->execute(); $chapter_data = $chapter_q->fetchObject(); if (!$chapter_data) { drupal_set_message(t('Invalid example chapter.'), 'error'); return FALSE; } //!$chapter_data /* deleting example files */ /*$examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/ $query = db_select('textbook_companion_example_files'); $query->fields('textbook_companion_example_files'); $query->condition('example_id', $example_id); $examples_files_q = $query->execute(); while ($examples_files_data = $examples_files_q->fetchObject()) { 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; } //!file_exists($root_path . $examples_files_data->filepath) /* removing example file */ if (!drupal_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', ''); $params['standard']['subject'] = "[ERROR] Error deleting example file"; $params['standard']['body'] = array( 0 => "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(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); } //!drupal_unlink($root_path . $examples_files_data->filepath) else { /* deleting example files database entries */ /*db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id);*/ $query = db_delete('textbook_companion_example_files'); $query->condition('id', $examples_files_data->id); $num_deleted = $query->execute(); } } //$examples_files_data = $examples_files_q->fetchObject() 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 (!drupal_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', ''); $params['standard']['subject'] = "[ERROR] Error deleting folder"; $params['standard']['body'] = array( 0 => "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(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); return FALSE; } //!drupal_rmdir($dir_path) } //is_dir($dir_path) 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);*/ $query = db_delete('textbook_companion_example_dependency'); $query->condition('example_id', $example_id); $num_deleted = $query->execute(); /*db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id);*/ $query = db_delete('textbook_companion_example'); $query->condition('id', $example_id); $num_deleted = $query->execute(); 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);*/ $query = db_select('textbook_companion_chapter'); $query->fields('textbook_companion_chapter'); $query->condition('id', $chapter_id); $chapter_q = $query->execute(); $chapter_data = $chapter_q->fetchObject(); if (!$chapter_data) { drupal_set_message('Invalid chapter.', 'error'); return FALSE; } //!$chapter_data /* deleting examples */ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id);*/ $query = db_select('textbook_companion_example'); $query->fields('textbook_companion_example'); $query->condition('chapter_id', $chapter_id); $example_q = $query->execute(); while ($example_data = $example_q->fetchObject()) { if (!delete_example($example_data->id)) $status = FALSE; } //$example_data = $example_q->fetchObject() 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', ''); $params['standard']['subject'] = "[ERROR] Error deleting folder"; $params['standard']['body'] = "Error deleting folder " . $dir_path; if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); return FALSE; } //!$res else { /* deleting chapter details from database */ /*db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);*/ $query = db_delete('textbook_companion_chapter'); $query->condition('id', $chapter_id); $num_deleted = $query->execute(); return TRUE; } } //is_dir($dir_path) else { drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array( '!folder' => $dir_path )), 'error'); return FALSE; } } //$status 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);*/ $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $book_id); $preference_q = $query->execute(); $preference_data = $preference_q->fetchObject(); if (!$preference_data) { drupal_set_message('Invalid book.', 'error'); return FALSE; } //!$preference_data /* delete chapters */ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id);*/ $query = db_select('textbook_companion_chapter'); $query->fields('textbook_companion_chapter'); $query->condition('preference_id', $preference_data->id); $chapter_q = $query->execute(); while ($chapter_data = $chapter_q->fetchObject()) { if (!delete_chapter($chapter_data->id)) { $status = FALSE; } //!delete_chapter($chapter_data->id) } //$chapter_data = $chapter_q->fetchObject() 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);*/ $query = db_select('textbook_companion_example_files'); $query->fields('textbook_companion_example_files'); $query->condition('id', $file_id); $query->range(0, 1); $file_q = $query->execute(); $file_data = $file_q->fetchObject(); if (!$file_data) { drupal_set_message('Invalid file specified.', 'error'); return FALSE; } //!$file_data 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; } //!file_exists($root_path . $file_data->filepath) /* 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', ''); $params['standard']['subject'] = "[ERROR] Error deleting file"; $params['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(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); return FALSE; } //!unlink($root_path . $file_data->filepath) else { /* deleting example files database entries */ /*db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id);*/ $query = db_delete('textbook_companion_example_files'); $query->condition('id', $file_id); $num_deleted = $query->execute(); return TRUE; } } function textbook_companion_init() { $path = drupal_get_path('module', 'textbook_companion'); drupal_add_css($path . '/css/textbook_companion.css'); drupal_add_js($path . '/js/textbook_companion.js'); }