diff options
author | Prashant P. Shah | 2012-05-10 14:48:55 +0530 |
---|---|---|
committer | Prashant P. Shah | 2012-05-10 14:48:55 +0530 |
commit | 5e72b8f943dc5a53e75242ec28255a3c3c5429d7 (patch) | |
tree | 4c7a316e68bf59839960dc7377f5533eb002178e | |
parent | b15406a6fca8d4921ab2038c19f3a54c92aa0ba5 (diff) | |
download | scilab_lab_migration-5e72b8f943dc5a53e75242ec28255a3c3c5429d7.tar.gz scilab_lab_migration-5e72b8f943dc5a53e75242ec28255a3c3c5429d7.tar.bz2 scilab_lab_migration-5e72b8f943dc5a53e75242ec28255a3c3c5429d7.zip |
adds latex PDF generation
Signed-off-by: Prashant P. Shah <pshah.mumbai@gmail.com>
-rwxr-xr-x | lab_migration.install | 666 | ||||
-rwxr-xr-x | lab_migration.module | 18 | ||||
-rwxr-xr-x | latex.inc | 217 | ||||
-rwxr-xr-x | upload_code.inc | 19 |
4 files changed, 578 insertions, 342 deletions
diff --git a/lab_migration.install b/lab_migration.install index 1fe969b..8bdad94 100755 --- a/lab_migration.install +++ b/lab_migration.install @@ -36,351 +36,351 @@ function lab_migration_uninstall() { function lab_migration_schema() { /* proposal */ -$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, - ), - 'solution_provider_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', - 'length' => '5', - '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, - ), - 'category' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'approval_status' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'solution_status' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'solution_display' => 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, - ), - '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', - 'size' => 'medium', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $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, + ), + 'solution_provider_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', + 'length' => '5', + '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, + ), + 'category' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'solution_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'solution_display' => 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, + ), + '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', + 'size' => 'medium', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* experiment */ -$schema['lab_migration_experiment'] = array( - 'description' => t('TODO: please describe this table!'), - 'fields' => array( - 'id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'serial', - 'not null' => TRUE, - ), - 'proposal_id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'number' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'title' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'varchar', - 'length' => '500', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_experiment'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE, + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'number' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'title' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '500', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* solution */ -$schema['lab_migration_solution'] = array( - 'description' => t('TODO: please describe this table!'), - 'fields' => array( - 'id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'serial', - 'not null' => TRUE, - ), - 'experiment_id' => 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, - ), - 'code_number' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'varchar', - 'length' => '10', - 'not null' => TRUE, - ), - 'caption' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'varchar', - 'length' => '255', - 'not null' => TRUE, - ), - 'approval_date' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'approval_status' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'timestamp' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_solution'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE, + ), + 'experiment_id' => 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, + ), + 'code_number' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '10', + 'not null' => TRUE, + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE, + ), + 'approval_date' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'approval_status' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* solution files */ -$schema['lab_migration_solution_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, - ), - 'solution_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, - ), - 'caption' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'varchar', - 'length' => '100', - 'not null' => TRUE, - ), - 'timestamp' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_solution_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, + ), + 'solution_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, + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE, + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* depedency files */ -$schema['lab_migration_dependency_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, - ), - 'proposal_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, - ), - 'caption' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'varchar', - 'length' => '100', - 'not null' => TRUE, - ), - 'description' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'text', - 'size' => 'medium', - 'not null' => TRUE, - ), - 'timestamp' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_dependency_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, + ), + 'proposal_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, + ), + 'caption' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '100', + 'not null' => TRUE, + ), + 'description' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'size' => 'medium', + 'not null' => TRUE, + ), + 'timestamp' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* dependency files - links */ -$schema['lab_migration_solution_dependency'] = array( - 'description' => t('TODO: please describe this table!'), - 'fields' => array( - 'id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'serial', - 'not null' => TRUE, - ), - 'solution_id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'dependency_id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_solution_dependency'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE, + ), + 'solution_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'dependency_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); /* notes */ -$schema['lab_migration_notes'] = array( - 'description' => t('TODO: please describe this table!'), - 'fields' => array( - 'id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'serial', - 'not null' => TRUE, - ), - 'proposal_id' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'int', - 'not null' => TRUE, - ), - 'notes' => array( - 'description' => t('TODO: please describe this field!'), - 'type' => 'text', - 'size' => 'medium', - 'not null' => TRUE, - ), - ), - 'primary key' => array('id'), -); + $schema['lab_migration_notes'] = array( + 'description' => t('TODO: please describe this table!'), + 'fields' => array( + 'id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'serial', + 'not null' => TRUE, + ), + 'proposal_id' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'int', + 'not null' => TRUE, + ), + 'notes' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'text', + 'size' => 'medium', + 'not null' => TRUE, + ), + ), + 'primary key' => array('id'), + ); return $schema; } diff --git a/lab_migration.module b/lab_migration.module index 5d7fda8..8f93b16 100755 --- a/lab_migration.module +++ b/lab_migration.module @@ -281,6 +281,24 @@ function lab_migration_menu() 'file' => 'full_download.inc', ); + /* latex script for lab generation */ + $items['lab_migration/generate_lab'] = array( + 'title' => 'Generate Lab', + 'description' => 'Generate Lab From Latex Script', + 'page callback' => 'lab_migration_download_lab_pdf', + 'access arguments' => array('generate book'), + 'type' => MENU_CALLBACK, + 'file' => 'latex.inc', + ); + $items['lab_migration/delete_lab'] = array( + 'title' => 'Delete Lab PDF', + 'description' => 'Delete Lab PDF', + 'page callback' => 'lab_migration_delete_lab_pdf', + 'access arguments' => array('approve code'), + 'type' => MENU_CALLBACK, + 'file' => 'latex.inc', + ); + /* DOWNLOAD FOR EVERYONE */ $items['lab_migration_run'] = array( 'title' => 'Download Codes', diff --git a/latex.inc b/latex.inc new file mode 100755 index 0000000..3f6b797 --- /dev/null +++ b/latex.inc @@ -0,0 +1,217 @@ +<?php + +function lab_migration_download_lab_pdf() +{ + $lab_id = arg(2); + _latex_copy_script_file(); + $full_lab = arg(3); + if ($full_lab == "1") + _latex_generate_files($lab_id, TRUE); + else + _latex_generate_files($lab_id, FALSE); +} + +/* full lab parameter is for gennerating the entire lab pdf including all unapproved solutions */ +function _latex_generate_files($lab_id, $full_lab = FALSE) +{ + $root_path = lab_migration_path(); + $dir_path = $root_path . "latex/"; + + $lab_filedata = ""; + $solution_provider_filedata = ""; + $latex_filedata = ""; + $latex_dep_filedata = ""; + + $depedency_list = array(); + + $eol = "\n"; + $sep = "#"; + + $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $lab_id); + $proposal_data = db_fetch_object($proposal_q); + if (!$proposal_data) + { + drupal_set_message('Invalid lab specified.', 'error'); + drupal_goto(''); + } + if ($proposal_data->approval_status == 0) + { + drupal_set_message('Lab proposal is still in pending review.', 'error'); + drupal_goto(''); + } + + $category_data = ''; + switch ($proposal_data->category) + { + case 0: $category_data = 'Not Selected'; break; + case 1: $category_data = 'Fluid Mechanics'; break; + case 2: $category_data = 'Control Theory & Control Systems'; break; + case 3: $category_data = 'Chemical Engineering'; break; + case 4: $category_data = 'Thermodynamics'; break; + case 5: $category_data = 'Mechanical Engineering'; break; + case 6: $category_data = 'Signal Processing'; break; + case 7: $category_data = 'Digital Communications'; break; + case 8: $category_data = 'Electrical Technology'; break; + case 9: $category_data = 'Mathematics & Pure Science'; break; + case 10: $category_data = 'Analog Electronics'; break; + case 11: $category_data = 'Digital Electronics'; break; + case 12: $category_data = 'Computer Programming'; break; + case 13: $category_data = 'Others'; break; + default: $category_data = 'Unknown'; break; + } + + $lab_filedata = $proposal_data->lab_title . $sep . $proposal_data->name_title . $sep . $proposal_data->name . $sep . $proposal_data->department . $sep . $proposal_data->university . $sep . $category_data . $eol; + + /* regenerate lab if full lab selected */ + if ($full_lab) + del_lab_pdf($proposal_data->id); + + /* check if lab already generated */ + if (file_exists($dir_path . "lab_" . $proposal_data->id . ".pdf")) + { + /* download zip file */ + header('Content-Type: application/pdf'); + header('Content-disposition: attachment; filename="' . $proposal_data->lab_title . '.pdf"'); + header('Content-Length: ' . filesize($dir_path . "lab_" . $proposal_data->id . ".pdf")); + readfile($dir_path . "lab_" . $proposal_data->id . ".pdf"); + return; + } + + $solution_provider_user = user_load($proposal_data->solution_provider_uid); + if (!$solution_provider_user) + { + drupal_set_message('Could not fetch solution provider information for the lab specified.', 'error'); + } + $solution_provider_filedata .= $solution_provider_user->name . $sep . $solution_provider_user->mail . $eol; + + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE lab_id = %d ORDER BY number DESC", $proposal_data->id); + while ($experiment_data = db_fetch_object($experiment_q)) + { + if ($full_lab) + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY number DESC", $experiment_data->id); + else + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1 ORDER BY number DESC", $experiment_data->id); + while ($solution_data = db_fetch_object($solution_q)) + { + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_data->id); + while ($solution_files_data = db_fetch_object($solution_files_q)) + { + $latex_filedata .= $experiment_data->number . $sep; + $latex_filedata .= $experiment_data->name . $sep; + $latex_filedata .= $solution_data->number . $sep; + $latex_filedata .= $solution_files_data->filename . $sep; + $latex_filedata .= $solution_files_data->filepath . $sep; + $latex_filedata .= $solution_files_data->filetype . $sep; + $latex_filedata .= $sep; + $latex_filedata .= $solution_files_data->id; + $latex_filedata .= $eol; + } + $dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_data->id); + while ($dependency_files_data = db_fetch_object($dependency_files_q)) + { + $dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $dependency_files_data->dependency_id); + if ($dependency_data = db_fetch_object($dependency_q)) + { + $latex_filedata .= $experiment_data->number . $sep; + $latex_filedata .= $experiment_data->name . $sep; + $latex_filedata .= $solution_data->number . $sep; + $latex_filedata .= $solution_data->caption . $sep; + $latex_filedata .= $dependency_data->filename . $sep; + $latex_filedata .= $dependency_data->filepath . $sep; + $latex_filedata .= 'D' . $sep; + $latex_filedata .= $dependency_data->caption . $sep; + $latex_filedata .= $dependency_data->id; + $latex_filedata .= $eol; + + $depedency_list[$dependency_data->id] = "D"; + } + } + } + } + + foreach ($depedency_list as $row => $data) { + $dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $row); + if ($dependency_data = db_fetch_object($dependency_q)) + { + $latex_dep_filedata .= $dependency_data->filename . $sep; + $latex_dep_filedata .= $dependency_data->filepath . $sep; + $latex_dep_filedata .= $dependency_data->caption . $sep; + $latex_dep_filedata .= $dependency_data->id; + $latex_dep_filedata .= $eol; + } + } + + /**************************** WRITE TO FILES ********************************/ + $download_filename = $proposal_data->lab; + $lab_filename = "tmp_" . $proposal_data->id . "_lab.txt"; + $solution_provider_filename = "tmp_" . $proposal_data->id . "_solution_provider.txt"; + $latex_filename = "tmp_" . $proposal_data->id . "_data.txt"; + $latex_dep_filename = "tmp_" . $proposal_data->id . "_dep_data.txt"; + $pdf_filename = "lab_" . $proposal_data->id . ".pdf"; + + $fb = fopen($dir_path . $lab_filename, 'w'); + fwrite($fb, $lab_filedata); + fclose($fb); + + $fc = fopen($dir_path . $solution_provider_filename, 'w'); + fwrite($fc, $solution_provider_filedata); + fclose($fc); + + $fl = fopen($dir_path . $latex_filename, 'w'); + fwrite($fl, $latex_filedata); + fclose($fl); + + $fd = fopen($dir_path . $latex_dep_filename, 'w'); + fwrite($fd, $latex_dep_filedata); + fclose($fd); + + if (_latex_run_script($lab_filename, $solution_provider_filename, $latex_filename, $latex_dep_filename, $pdf_filename)) + { + /* download zip file */ + header('Content-Type: application/pdf'); + header('Content-disposition: attachment; filename="' . $proposal_data->lab . '_' . $proposal_data->author . '.pdf"'); + header('Content-Length: ' . filesize($dir_path . $pdf_filename)); + readfile($dir_path . $pdf_filename); + } else { + drupal_set_message("Error occurred when generating the PDF version of the Book.", 'error'); + } + + /*********************** DELETING TEMPORARY FILES ***************************/ + /* regenerate lab if full lab selected */ + if ($full_lab) + del_lab_pdf($proposal_data->id); +} + +function _latex_copy_script_file() +{ + exec("cp ./" . drupal_get_path('module', 'lab_migration') . "/latex/* " . lab_migration_path() . "latex"); + exec("chmod u+x ./uploads/latex/*.sh"); +} + +function _latex_run_script($lab_filename, $solution_provider_filename, $latex_filename, $latex_dep_filename, $pdf_filename) +{ + $root_path = lab_migration_path(); + $ret = 0; + + chdir("uploads"); + chdir("latex"); + + $sh_command = "./pdf_creator.sh " . $lab_filename . " " . $solution_provider_filename . " " . $latex_filename . " " . $latex_dep_filename; + exec($sh_command); + exec("mv TEX_final.pdf " . $pdf_filename); + + if ($ret == 0) + return TRUE; + else + return FALSE; +} + +function lab_migration_delete_lab_pdf() +{ + $lab_id = arg(3); + del_lab_pdf($lab_id); + drupal_set_message(t('Lab schedule for regeneration.'), 'status'); + drupal_goto('lab_migration/code_approval/bulk'); + return; +} + diff --git a/upload_code.inc b/upload_code.inc index 5b763cb..bc1e5a6 100755 --- a/upload_code.inc +++ b/upload_code.inc @@ -12,7 +12,7 @@ function list_experiments() } $return_html = '<br />'; - $return_html .= '<strong>Title of the Experiment:</strong><br />' . $proposal_data->lab_title . '<br /><br />'; + $return_html .= '<strong>Title of the Lab:</strong><br />' . $proposal_data->lab_title . '<br /><br />'; $return_html .= '<strong>Proposer Name:</strong><br />' . $proposal_data->name_title . ' ' . $proposal_data->name . '<br /><br />'; $return_html .= l('Upload Example Code', 'lab_migration/code/upload') . '<br />'; @@ -21,7 +21,7 @@ function list_experiments() $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_data->id); while ($experiment_data = db_fetch_object($experiment_q)) { - $experiment_rows[] = array($experiment_data->number . ')    ' . $experiment_data->title, '', '', ''); + $experiment_rows[] = array($experiment_data->number . ') ' . $experiment_data->title, '', '', ''); /* get solution list */ $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY id ASC", $experiment_data->id); if ($solution_q) { @@ -32,10 +32,11 @@ function list_experiments() case 1: $solution_status = "Approved"; break; default: $solution_status = "Unknown"; break; } - if ($solution_data->approval_status == 0) - $experiment_rows[] = array("              " . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, l('Delete', 'lab_migration/code/delete/' . $solution_data->id)); - else - $experiment_rows[] = array("              " . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, ''); + if ($solution_data->approval_status == 0) { + $experiment_rows[] = array(" " . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, l('Delete', 'lab_migration/code/delete/' . $solution_data->id)); + } else { + $experiment_rows[] = array(" " . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, ''); + } /* get solution files */ $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d ORDER BY id ASC", $solution_data->id); if ($solution_files_q) { @@ -48,7 +49,7 @@ function list_experiments() case 'U': $code_file_type = 'Unknown'; break; default: $code_file_type = 'Unknown'; break; } - $experiment_rows[] = array("                  " . l($solution_files_data->filename, 'lab_migration/download/file/' . $solution_files_data->id), $code_file_type, '', ''); + $experiment_rows[] = array(" " . l($solution_files_data->filename, 'lab_migration/download/file/' . $solution_files_data->id), $code_file_type, '', ''); } } /* get dependencies files */ @@ -57,7 +58,7 @@ function list_experiments() { $dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); $dependency_files_data = db_fetch_object($dependency_files_q); - $experiment_rows[] = array("                  " . l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->id), 'Dependency', '', ''); + $experiment_rows[] = array(" " . l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->id), 'Dependency', '', ''); } } } @@ -273,7 +274,7 @@ function upload_code_form($form_state) function upload_code_form_validate($form, &$form_state) { if (!check_code_number($form_state['values']['code_number'])) - form_set_error('code_number', t('Invalid Code Number. Code Number can contain only alphabets and numbers sepereated by dot.')); + form_set_error('code_number', t('Invalid Code Number. Code Number can contain only number dot number.')); if (!check_name($form_state['values']['code_caption'])) form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.')); |