summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashant P. Shah2011-07-06 16:45:51 +0530
committerPrashant P. Shah2011-07-06 16:45:51 +0530
commit7e73501b986b4d61ef28adc79cefbf4929587075 (patch)
tree05737a4427f79145264d9068d45a99336c356966
downloadscilab_lab_migration-7e73501b986b4d61ef28adc79cefbf4929587075.tar.gz
scilab_lab_migration-7e73501b986b4d61ef28adc79cefbf4929587075.tar.bz2
scilab_lab_migration-7e73501b986b4d61ef28adc79cefbf4929587075.zip
initial commit
Signed-off-by: Prashant P. Shah <pshah.mumbai@gmail.com>
-rw-r--r--lab_migration.info6
-rw-r--r--lab_migration.install169
-rw-r--r--lab_migration.module399
-rw-r--r--proposal.inc226
-rw-r--r--settings.inc49
5 files changed, 849 insertions, 0 deletions
diff --git a/lab_migration.info b/lab_migration.info
new file mode 100644
index 0000000..f76bc68
--- /dev/null
+++ b/lab_migration.info
@@ -0,0 +1,6 @@
+name = Lab Migration
+description = IIT Bombay Lab Migration project
+package = IITB
+version = VERSION
+core = 6.x
+
diff --git a/lab_migration.install b/lab_migration.install
new file mode 100644
index 0000000..2ccd4ac
--- /dev/null
+++ b/lab_migration.install
@@ -0,0 +1,169 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function lab_migration_install() {
+ // Create tables.
+ drupal_install_schema('lab_migration');
+ // Set variables
+ variable_set('lab_migration_emails', '');
+ variable_set('lab_migration_from_email', '');
+ variable_set('lab_migration_uploads_extensions', '');
+
+ /* creating upload directory */
+ if (!is_dir($_SERVER['DOCUMENT_ROOT'] . base_path() . 'sites/default/files/lab_migration/'))
+ mkdir($_SERVER['DOCUMENT_ROOT'] . base_path() . 'sites/default/files/lab_migration/');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function lab_migration_uninstall() {
+ // Remove tables.
+ drupal_uninstall_schema('lab_migration');
+ // Remove variables
+ variable_del('lab_migration_emails');
+ variable_del('lab_migration_from_email');
+ variable_del('lab_migration_uploads_extensions');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function lab_migration_schema() {
+
+ $schema['lab_migration_proposal'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'name' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'contact_ph' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '15',
+ 'not null' => TRUE,
+ ),
+ 'department' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'university' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'lab_title' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'problem_topic' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'creation_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approval_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'message' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ $schema['lab_migration_files'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'link_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'filename' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filepath' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE,
+ ),
+ 'filemime' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filesize' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'filetype' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '1',
+ 'not null' => TRUE,
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ return $schema;
+}
+
diff --git a/lab_migration.module b/lab_migration.module
new file mode 100644
index 0000000..b587f48
--- /dev/null
+++ b/lab_migration.module
@@ -0,0 +1,399 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_menu().
+ */
+function lab_migration_menu()
+{
+ $items = array();
+
+ /* for admin */
+ $items['lab_migration/proposal'] = array(
+ 'title' => 'Lab Migration Proposal',
+ 'description' => 'Lab Migration Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('lab_migration_proposal_form'),
+ 'access arguments' => array('create proposal'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'proposal.inc',
+ );
+
+ /* for admin */
+ $items['admin/settings/lab_migration'] = array(
+ 'title' => 'Lab Migration Settings',
+ 'description' => 'Lab Migration Settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('lab_migration_settings_form'),
+ 'access arguments' => array('administer lab migration'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'settings.inc',
+ );
+
+ return $items;
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function lab_migration_perm() {
+ return array('create proposal', 'reply proposal', 'approve proposal', 'view questions', 'view answers', 'administer lab migration');
+}
+
+/**
+ * Implementation of hook_mail().
+ */
+function lab_migration_mail($key, &$message, $params)
+{
+ global $user;
+ $language = $message['language'];
+ switch ($key)
+ {
+ case 'proposal_received':
+ /* initializing data */
+ $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);
+ $user_data = user_load($params['proposal_received']['user_id']);
+
+ $message['subject'] = t('[!site_name] Your Lab migration proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language);
+ $message['body'] = t('
+Dear !user_name,
+
+We have received your following lab migration proposal:
+
+Name of the Professor : ' . $proposal_data->name . '
+Email : ' . $user_data->mail . '
+Contact Phone No. : ' . $proposal_data->contact_ph . '
+Department/Branch : ' . $proposal_data->department . '
+University/Institute : ' . $proposal_data->university . '
+Title of the Lab : ' . $proposal_data->lab_title . '
+Topic of the Problem : ' . $proposal_data->problem_topic . '
+
+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;
+ }
+}
+
+/******************************************************************************/
+/**************************** GENERAL FUNCTION ********************************/
+/******************************************************************************/
+
+function lab_migration_path() {
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'sites/default/files/lab_migration/';
+}
+
+/******************************************************************************/
+/*************************** VALIDATION FUNCTIONS *****************************/
+/******************************************************************************/
+
+function lab_migration_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;
+}
+
diff --git a/proposal.inc b/proposal.inc
new file mode 100644
index 0000000..460a86d
--- /dev/null
+++ b/proposal.inc
@@ -0,0 +1,226 @@
+<?php
+// $Id$
+
+function lab_migration_proposal_form($form_state)
+{
+ global $user;
+
+ $form['#attributes'] = array('enctype' => "multipart/form-data");
+
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Professor'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ );
+ $form['email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE,
+ );
+ $form['contact_ph'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact Phone No.'),
+ '#size' => 30,
+ '#maxlength' => 15,
+ '#required' => TRUE,
+ );
+ $form['department'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => array('' => 'Please select...',
+ '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['lab_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Lab'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ );
+ $form['problem_topic'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Topic of the Problem'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ );
+ $form['problem_file'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload problem statement'),
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_uploads_extensions', ''),
+ );
+ $form['supplementary_file'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload supplementary files (eg. existing soultion of problem in any other software)'),
+ '#description' => t('If more than one file, then compress and upload as .zip or .tar file') . '<br />' .
+ t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_uploads_extensions', ''),
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+
+function lab_migration_proposal_form_validate($form, &$form_state)
+{
+ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['contact_ph']))
+ form_set_error('mobile', t('Invalid contact phone number'));
+
+ if ( ! ($_FILES['files']['name']['problem_file'])) {
+ form_set_error('problem_file', t('Problem statement file is required.'));
+ } else {
+ $allowed_extensions_str = variable_get('lab_migration_uploads_extensions', '');
+ $allowed_extensions = explode(',' , $allowed_extensions_str);
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name']['problem_file'])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error('problem_file', t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size']['problem_file'] <= 0)
+ form_set_error('problem_file', t('File size cannot be zero.'));
+
+ /* check if valid file name */
+ if (!lab_migration_check_valid_filename($_FILES['files']['name']['problem_file']))
+ form_set_error('problem_file', t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ }
+
+ if ($_FILES['files']['name']['supplementary_file']) {
+ $allowed_extensions_str = variable_get('lab_migration_uploads_extensions', '');
+ $allowed_extensions = explode(',' , $allowed_extensions_str);
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name']['supplementary_file'])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error('supplementary_file', t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size']['supplementary_file'] <= 0)
+ form_set_error('supplementary_file', t('File size cannot be zero.'));
+
+ /* check if valid file name */
+ if (!lab_migration_check_valid_filename($_FILES['files']['name']['supplementary_file']))
+ form_set_error('supplementary_file', t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+
+ /* if file already exists */
+ if ($_FILES['files']['name']['problem_file'] == $_FILES['files']['name']['supplementary_file']) {
+ form_set_error('supplementary_file', t('Supplementary file cannot be same as the problem statement file.'));
+ }
+ }
+ return;
+}
+
+function lab_migration_proposal_form_submit($form, &$form_state)
+{
+ global $user;
+ $root_path = lab_migration_path();
+
+ /* inserting the user proposal */
+ $result = db_query("INSERT INTO {lab_migration_proposal}
+ (uid, approver_uid, name, contact_ph, department, university, lab_title, problem_topic, approval_status, creation_date, approval_date) VALUES
+ (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
+ $user->uid,
+ 0,
+ $form_state['values']['name'],
+ $form_state['values']['contact_ph'],
+ $form_state['values']['department'],
+ $form_state['values']['university'],
+ $form_state['values']['lab_title'],
+ $form_state['values']['problem_topic'],
+ 0,
+ time(),
+ 0
+ );
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
+ return;
+ }
+ /* proposal id */
+ $proposal_id = db_last_insert_id('lab_migration_proposal', 'id');
+
+ /************** uploading file *******************/
+ /* creating directories */
+ $dest_path = $proposal_id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['problem_file']))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['problem_file'])), 'error');
+ return;
+ }
+
+ /* uploading file */
+ $filename = $_FILES['files']['name']['problem_file'];
+ if (move_uploaded_file($_FILES['files']['tmp_name']['problem_file'], $root_path . $dest_path . $filename))
+ {
+ /* for uploaded files making an entry in the database */
+ db_query("INSERT INTO {lab_migration_files} (link_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $proposal_id,
+ $filename,
+ $dest_path . $filename,
+ $_FILES['files']['type']['problem_file'],
+ $_FILES['files']['size']['problem_file'],
+ 'P',
+ time()
+ );
+ } else {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $filename, 'error');
+ }
+
+ /* uploading file */
+ $filename = $_FILES['files']['name']['supplementary_file'];
+ if (move_uploaded_file($_FILES['files']['tmp_name']['supplementary_file'], $root_path . $dest_path . $filename))
+ {
+ /* for uploaded files making an entry in the database */
+ db_query("INSERT INTO {lab_migration_files} (link_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $proposal_id,
+ $filename,
+ $dest_path . $filename,
+ $_FILES['files']['type']['supplementary_file'],
+ $_FILES['files']['size']['supplementary_file'],
+ 'S',
+ time()
+ );
+ } else {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $filename, 'error');
+ }
+
+ /* sending email */
+ $email_to = $user->mail;
+ $param['proposal_received']['proposal_id'] = $proposal_id;
+ $param['proposal_received']['user_id'] = $user->uid;
+ if (!drupal_mail('lab_migration', 'proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+
+ /* sending email */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['proposal_received']['proposal_id'] = $proposal_id;
+ $param['proposal_received']['user_id'] = $user->uid;
+ if (!drupal_mail('lab_migration', 'proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+
+ drupal_set_message(t('We have received you lab migration proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+}
+
diff --git a/settings.inc b/settings.inc
new file mode 100644
index 0000000..e7dcd39
--- /dev/null
+++ b/settings.inc
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+function lab_migration_settings_form($form_state)
+{
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Notification emails'),
+ '#description' => t('A comma separated list of email addresses to receive notifications emails'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_emails', ''),
+ );
+
+ $form['from_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Outgoing from email address'),
+ '#description' => t('Email address to be display in the from field of all outgoing messages'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_from_email', ''),
+ );
+
+ $form['upload_extensions'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed source file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_uploads_extensions', ''),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+
+function lab_migration_settings_form_submit($form, &$form_state)
+{
+ variable_set('lab_migration_emails', $form_state['values']['emails']);
+ variable_set('lab_migration_from_email', $form_state['values']['from_email']);
+ variable_set('lab_migration_uploads_extensions', $form_state['values']['upload_extensions']);
+ drupal_set_message(t('Settings updated'), 'status');
+}