summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lab_migration.install17
-rw-r--r--lab_migration.module21
-rw-r--r--manage_proposal.inc24
-rw-r--r--migrated_labs.inc16
-rw-r--r--proposal.inc4
-rw-r--r--solution.inc228
6 files changed, 301 insertions, 9 deletions
diff --git a/lab_migration.install b/lab_migration.install
index 8530b7a..8573b97 100644
--- a/lab_migration.install
+++ b/lab_migration.install
@@ -54,6 +54,11 @@ function lab_migration_schema()
'type' => 'int',
'not null' => TRUE,
),
+ 'solver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
'name_title' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'varchar',
@@ -99,6 +104,13 @@ function lab_migration_schema()
'approval_status' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
+ 'length' => '1',
+ 'not null' => TRUE,
+ ),
+ 'solution_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'length' => '1',
'not null' => TRUE,
),
'creation_date' => array(
@@ -111,6 +123,11 @@ function lab_migration_schema()
'type' => 'int',
'not null' => TRUE,
),
+ 'solution_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',
diff --git a/lab_migration.module b/lab_migration.module
index a148103..37262c5 100644
--- a/lab_migration.module
+++ b/lab_migration.module
@@ -46,6 +46,16 @@ function lab_migration_menu()
'weight' => 1,
'file' => 'manage_proposal.inc',
);
+ $items['lab_migration/manage_proposal/pending_solution'] = array(
+ 'title' => 'Pending Solution',
+ 'description' => 'Pending Lab Migration Solution',
+ 'page callback' => '_proposal_pending_solution',
+ 'access callback' => 'user_access',
+ 'access arguments' => array('manage proposal'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'solution.inc',
+ );
$items['lab_migration/manage_proposal/all'] = array(
'title' => 'All Proposals',
'description' => 'All Proposals',
@@ -53,7 +63,7 @@ function lab_migration_menu()
'access callback' => 'user_access',
'access arguments' => array('manage proposal'),
'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
+ 'weight' => 3,
'file' => 'manage_proposal.inc',
);
$items['lab_migration/manage_proposal/approve'] = array(
@@ -74,6 +84,15 @@ function lab_migration_menu()
'type' => MENU_CALLBACK,
'file' => 'manage_proposal.inc',
);
+ $items['lab_migration/manage_proposal/solution'] = array(
+ 'title' => 'Proposal Solution',
+ 'description' => 'Proposal Solution',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('proposal_solution_form'),
+ 'access arguments' => array('manage proposal'),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'solution.inc',
+ );
/* for admin */
$items['admin/settings/lab_migration'] = array(
diff --git a/manage_proposal.inc b/manage_proposal.inc
index c024027..4c4cb4d 100644
--- a/manage_proposal.inc
+++ b/manage_proposal.inc
@@ -34,7 +34,12 @@ function _proposal_all()
case 2: $proposal_status = 'Dis-approved'; break;
default: $proposal_status = 'Unknown'; break;
}
- $proposal_rows[] = array(date('d-m-Y', $proposal_data->creation_date), l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), $proposal_data->department, $proposal_data->university, $proposal_data->lab_title, $proposal_status, l('Approve', 'lab_migration/manage_proposal/approve/' . $proposal_data->id) . ' | ' . l('Edit', 'lab_migration/manage_proposal/edit/' . $proposal_data->id));
+ if ($proposal_data->solution_status == 1) {
+ $proposal_status = 'Migrated';
+ $proposal_rows[] = array(date('d-m-Y', $proposal_data->creation_date), l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), $proposal_data->department, $proposal_data->university, $proposal_data->lab_title, $proposal_status, l('Edit', 'lab_migration/manage_proposal/edit/' . $proposal_data->id));
+ } else {
+ $proposal_rows[] = array(date('d-m-Y', $proposal_data->creation_date), l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), $proposal_data->department, $proposal_data->university, $proposal_data->lab_title, $proposal_status, l('Approve', 'lab_migration/manage_proposal/approve/' . $proposal_data->id) . ' | ' . l('Edit', 'lab_migration/manage_proposal/edit/' . $proposal_data->id));
+ }
}
/* check if there are any pending proposals */
@@ -65,6 +70,11 @@ function proposal_approval_form($form_state)
drupal_goto('lab_migration/manage_proposal');
return;
}
+ if ($row->solution_status != 0) {
+ drupal_set_message(t('Cannot change approval status of solved approval.'), 'error');
+ drupal_goto('lab_migration/manage_proposal');
+ return;
+ }
$form['name_title'] = array(
'#type' => 'item',
@@ -330,6 +340,18 @@ function proposal_edit_form($form_state)
);
}
+ if ($row->solution_status == 1) {
+ $sol_file_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'A'", $row->id);
+ $sol_file_data = db_fetch_object($sol_file_q);
+ if ($sol_file_data) {
+ $form['solution_file'] = array(
+ '#type' => 'item',
+ '#value' => l($sol_file_data->filename, $dl_root_path . $sol_file_data->filepath),
+ '#title' => t('Solution file'),
+ );
+ }
+ }
+
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
diff --git a/migrated_labs.inc b/migrated_labs.inc
index 285e12c..eed0f41 100644
--- a/migrated_labs.inc
+++ b/migrated_labs.inc
@@ -21,12 +21,18 @@ function migrated_labs()
$file_links .= '<br/>' . l('Suplementary Files', $dl_root_path . $sup_data->filepath);
$migration_status = '';
- switch ($labs_data) {
- case 1: $migration_status = '(In Progress)'; break;
- case 3: $migration_status = '(Completed)'; break;
+ if ($labs_data->solution_status == 0) {
+ $migration_status = 'In Progress';
+ } else if ($labs_data->solution_status == 1) {
+ $migration_status = 'Migrated';
+ if (($user->uid == $labs_data->uid) || user_access('manage proposal')) {
+ $sol_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'A'", $labs_data->id);
+ $sol_data = db_fetch_object($sol_q);
+ $file_links .= '<br/>' . l('Solution File', $dl_root_path . $sol_data->filepath);
+ }
}
- $labs_rows[] = array($labs_data->university . '<br/>' . $migration_status, $labs_data->lab_title, $labs_data->problem_topic . $file_links, l($labs_data->name_title . ' ' . $labs_data->name, 'user/' . $labs_data->uid) . '<br/>' . $labs_data->department);
+ $labs_rows[] = array($labs_data->university, $labs_data->lab_title, $labs_data->problem_topic . $file_links, l($labs_data->name_title . ' ' . $labs_data->name, 'user/' . $labs_data->uid) . '<br/>' . $labs_data->department, $migration_status);
}
/* check if there are any pending proposals */
@@ -35,7 +41,7 @@ function migrated_labs()
return '';
}
- $labs_header = array('University/Institute', 'Title of the Lab', 'Title of the Problem', 'Name of the Proposer and Department');
+ $labs_header = array('University/Institute', 'Title of the Lab', 'Title of the Problem', 'Name of the Proposer and Department', 'Status');
$output = theme_table($labs_header, $labs_rows);
return $output;
}
diff --git a/proposal.inc b/proposal.inc
index a3f513f..ef96c1f 100644
--- a/proposal.inc
+++ b/proposal.inc
@@ -140,8 +140,8 @@ function lab_migration_proposal_form_submit($form, &$form_state)
/* inserting the user proposal */
$result = db_query("INSERT INTO {lab_migration_proposal}
- (uid, approver_uid, name_title, name, contact_ph, department, university, lab_title, problem_topic, approval_status, creation_date, approval_date) VALUES
- (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
+ (uid, approver_uid, solver_uid, name_title, name, contact_ph, department, university, lab_title, problem_topic, approval_status, solution_status, creation_date, approval_date, solution_date) VALUES
+ (%d, %d, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, 0, %d, %d, 0)",
$user->uid,
0,
$form_state['values']['name_title'],
diff --git a/solution.inc b/solution.inc
new file mode 100644
index 0000000..61c4b45
--- /dev/null
+++ b/solution.inc
@@ -0,0 +1,228 @@
+<?php
+// $Id$
+
+function _proposal_pending_solution()
+{
+ /* get pending proposals to be approved */
+ $pending_rows = array();
+ $pending_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 AND solution_status = 0 ORDER BY id DESC");
+ while ($pending_data = db_fetch_object($pending_q)) {
+ $pending_rows[$pending_data->id] = array(date('d-m-Y', $pending_data->creation_date), l($pending_data->name_title . ' ' . $pending_data->name, 'user/' . $pending_data->uid), $pending_data->department, $pending_data->university, $pending_data->lab_title, l('Upload Solution', '/lab_migration/manage_proposal/solution/' . $pending_data->id));
+ }
+
+ /* check if there are any pending proposals */
+ if (!$pending_rows) {
+ drupal_set_message(t('There are no pending proposals to be solved.'), 'status');
+ return '';
+ }
+
+ $pending_header = array('Date of Submission', 'Name of the Proposer', 'Department/Branch', 'University/Institute', 'Title of the Lab', 'Action');
+ $output = theme_table($pending_header, $pending_rows);
+ return $output;
+}
+
+/******************************************************************************/
+/************************** PROPOSAL SOLUTION FORM ****************************/
+/******************************************************************************/
+
+function proposal_solution_form($form_state)
+{
+ global $user;
+ $dl_root_path = 'sites/default/files/lab_migration/';
+
+ /* get current proposal */
+ $proposal_id = arg(3);
+ $result = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ if (!($row = db_fetch_object($result))) {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab_migration/manage_proposal/pending_proposal');
+ return;
+ }
+ if ($row->approval_status != 1) {
+ drupal_set_message(t('Selected Proposal has not been approved yet.'), 'error');
+ drupal_goto('lab_migration/manage_proposal/pending_proposal');
+ return;
+ }
+ if ($row->solution_status != 0) {
+ drupal_set_message(t('Selected Proposal has already been solved.'), 'error');
+ drupal_goto('lab_migration/manage_proposal/pending_proposal');
+ return;
+ }
+
+ $form['#attributes'] = array('enctype' => "multipart/form-data");
+
+ $form['name_title'] = array(
+ '#type' => 'item',
+ '#value' => $row->name_title,
+ '#title' => t('Title'),
+ );
+ $form['name'] = array(
+ '#type' => 'item',
+ '#value' => l($row->name, 'user/' . $row->uid),
+ '#title' => t('Name of the Proposer'),
+ );
+ $form['email'] = array(
+ '#type' => 'item',
+ '#value' => user_load($row->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contact_ph'] = array(
+ '#type' => 'item',
+ '#value' => $row->contact_ph,
+ '#title' => t('Contact Phone No.'),
+ );
+ $form['department'] = array(
+ '#type' => 'item',
+ '#value' => $row->department,
+ '#title' => t('Department/Branch'),
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#value' => $row->university,
+ '#title' => t('University/Institute'),
+ );
+ $form['lab_title'] = array(
+ '#type' => 'item',
+ '#value' => $row->lab_title,
+ '#title' => t('Title of the Lab'),
+ );
+ $form['problem_topic'] = array(
+ '#type' => 'item',
+ '#value' => $row->problem_topic,
+ '#title' => t('Topic of the Problem'),
+ );
+
+ $problem_file_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'P'", $row->id);
+ $problem_file_data = db_fetch_object($problem_file_q);
+ if ($problem_file_data) {
+ $form['problem_file'] = array(
+ '#type' => 'item',
+ '#value' => l($problem_file_data->filename, $dl_root_path . $problem_file_data->filepath),
+ '#title' => t('Problem statement'),
+ );
+ }
+
+ $sup_file_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filetype = 'S'", $row->id);
+ $sup_file_data = db_fetch_object($sup_file_q);
+ if ($sup_file_data) {
+ $form['supplementary_file'] = array(
+ '#type' => 'item',
+ '#value' => l($sup_file_data->filename, $dl_root_path . $sup_file_data->filepath),
+ '#title' => t('Supplementary file'),
+ );
+ }
+
+ $approver_user_data = user_load($row->approver_uid );
+ $form['approval_details'] = array(
+ '#type' => 'item',
+ '#value' => 'By : ' . l($approver_user_data->name, 'user/' . $row->approver_uid) . '<br />'
+ . 'On : ' . date('d-m-Y', $row->approval_date),
+ );
+
+ $form['solution_file'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload solution 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['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'lab_migration/manage_proposal/pending_solution'),
+ );
+
+ return $form;
+}
+
+function proposal_solution_form_validate($form, &$form_state)
+{
+ $proposal_id = arg(3);
+
+ if ( ! ($_FILES['files']['name']['solution_file'])) {
+ form_set_error('problem_file', t('Solution 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']['solution_file'])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error('solution_file', t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size']['solution_file'] <= 0)
+ form_set_error('solution_file', t('File size cannot be zero.'));
+
+ /* check if valid file name */
+ if (!lab_migration_check_valid_filename($_FILES['files']['name']['solution_file']))
+ form_set_error('solution_file', t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+
+ /* if file already exists */
+ $file_exists_q = db_query("SELECT * FROM {lab_migration_files} WHERE link_id = %d AND filename = '%s'", $proposal_id, $_FILES['files']['name']['solution_file']);
+ if (db_fetch_object($file_exists_q))
+ form_set_error('solution_file', t('File with the same name already exists. Please rename the solution file and try again.'));
+ }
+ return;
+}
+
+function proposal_solution_form_submit($form, &$form_state)
+{
+ global $user;
+ $root_path = lab_migration_path();
+
+ /* get current proposal */
+ $proposal_id = (int)arg(3);
+ $result = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ if (!($row = db_fetch_object($result))) {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab_migration/manage_proposal');
+ return;
+ }
+ if ($row->approval_status != 1) {
+ drupal_set_message(t('Selected Proposal has not been approved yet.'), 'error');
+ drupal_goto('lab_migration/manage_proposal/pending_solution');
+ return;
+ }
+ if ($row->solution_status != 0) {
+ drupal_set_message(t('Selected Proposal has already been solved.'), 'error');
+ drupal_goto('lab_migration/manage_proposal/pending_solution');
+ return;
+ }
+
+ /************** 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']['solution_file']))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['solution_file'])), 'error');
+ return;
+ }
+
+ /* uploading file */
+ $filename = $_FILES['files']['name']['solution_file'];
+ if (move_uploaded_file($_FILES['files']['tmp_name']['solution_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']['solution_file'],
+ $_FILES['files']['size']['solution_file'],
+ 'A',
+ time()
+ );
+
+ db_query("UPDATE {lab_migration_proposal} SET solution_status = 1, solver_uid = %d, solution_date = %d WHERE id = %d", $user->uid, time(), $proposal_id);
+ } else {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $filename, 'error');
+ }
+
+ drupal_goto('lab_migration/manage_proposal/pending_solution');
+}
+