diff options
author | Prashant P. Shah | 2012-05-23 11:42:15 +0530 |
---|---|---|
committer | Prashant P. Shah | 2012-05-23 11:42:15 +0530 |
commit | 976ca90225cabd9d59845fbc667ddd81f64ae2fa (patch) | |
tree | 92b0b74081c10eb52ab3111de6b7b90015d4cd79 | |
parent | 830fc0dd5f1838ab5ec9d20668af1e596c0cda78 (diff) | |
download | scilab_lab_migration-976ca90225cabd9d59845fbc667ddd81f64ae2fa.tar.gz scilab_lab_migration-976ca90225cabd9d59845fbc667ddd81f64ae2fa.tar.bz2 scilab_lab_migration-976ca90225cabd9d59845fbc667ddd81f64ae2fa.zip |
adds bulk upload code
Signed-off-by: Prashant P. Shah <pshah.mumbai@gmail.com>
-rwxr-xr-x | bulk_upload_code.inc | 458 | ||||
-rwxr-xr-x | dependency_approval.inc | 9 | ||||
-rwxr-xr-x | general.inc | 226 | ||||
-rwxr-xr-x | lab_migration.module | 57 | ||||
-rwxr-xr-x | latex.inc | 2 | ||||
-rwxr-xr-x | manage_solution_proposal.inc | 5 | ||||
-rwxr-xr-x | run.inc | 2 | ||||
-rwxr-xr-x | solution_proposal.inc | 2 |
8 files changed, 509 insertions, 252 deletions
diff --git a/bulk_upload_code.inc b/bulk_upload_code.inc new file mode 100755 index 0000000..71d2b15 --- /dev/null +++ b/bulk_upload_code.inc @@ -0,0 +1,458 @@ +<?php +// $Id$ + +function bulk_upload_code_form($form_state) +{ + global $user; + + $proposal_data = get_proposal(); + if (!$proposal_data) { + drupal_goto(''); + return; + } + + /* add javascript for dependency selection effects */ + $dep_selection_js = " $(document).ready(function() { + $('#edit-existing-depfile-dep-lab-title').change(function() { + var dep_selected = ''; + /* showing and hiding relevant files */ + $('.form-checkboxes .option').hide(); + $('.form-checkboxes .option').each(function(index) { + var activeClass = $('#edit-existing-depfile-dep-lab-title').val(); + if ($(this).children().hasClass(activeClass)) { + $(this).show(); + } + if ($(this).children().attr('checked') == true) { + dep_selected += $(this).children().next().text() + '<br />'; + } + }); + /* showing list of already existing dependencies */ + $('#existing_depfile_selected').html(dep_selected); + }); + + $('.form-checkboxes .option').change(function() { + $('#edit-existing-depfile-dep-lab-title').trigger('change'); + }); + $('#edit-existing-depfile-dep-lab-title').trigger('change'); + });"; + drupal_add_js($dep_selection_js, 'inline', 'header'); + + $form['#attributes'] = array('enctype' => "multipart/form-data"); + + $form['lab_title'] = array( + '#type' => 'item', + '#value' => $proposal_data->lab_title, + '#title' => t('Title of the Lab'), + ); + $form['name'] = array( + '#type' => 'item', + '#value' => $proposal_data->name_title . ' ' . $proposal_data->name, + '#title' => t('Proposer Name'), + ); + + /* get experiment list */ + $experiment_rows = array(); + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY id ASC", $proposal_data->id); + while ($experiment_data = db_fetch_object($experiment_q)) + { + $experiment_rows[$experiment_data->id] = $experiment_data->number . '. ' . $experiment_data->title; + } + $form['experiment'] = array( + '#type' => 'select', + '#title' => t('Title of the Experiment'), + '#options' => $experiment_rows, + '#multiple' => FALSE, + '#size' => 1, + '#required' => TRUE, + ); + + $form['code_number'] = array( + '#type' => 'textfield', + '#title' => t('Code No'), + '#size' => 5, + '#maxlength' => 10, + '#description' => t(""), + '#required' => TRUE, + ); + $form['code_caption'] = array( + '#type' => 'textfield', + '#title' => t('Caption'), + '#size' => 40, + '#maxlength' => 255, + '#description' => t(''), + '#required' => TRUE, + ); + $form['code_warning'] = array( + '#type' => 'item', + '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'), + '#prefix' => '<div style="color:red">', + '#suffix' => '</div>', + ); + + $form['sourcefile'] = array( + '#type' => 'fieldset', + '#title' => t('Main or Source Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['sourcefile']['sourcefile1'] = array( + '#type' => 'file', + '#title' => t('Upload main or source file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', ''), + ); + + $form['dep_files'] = array( + '#type' => 'item', + '#title' => t('Dependency Files'), + ); + + /************ START OF EXISTING DEPENDENCIES **************/ + + /* existing dependencies */ + $form['existing_depfile'] = array( + '#type' => 'fieldset', + '#title' => t('Use Already Existing Dependency Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#prefix' => '<div id="existing-depfile-wrapper">', + '#suffix' => '</div>', + '#tree' => TRUE, + ); + + /* existing dependencies */ + $form['existing_depfile']['selected'] = array( + '#type' => 'item', + '#title' => t('Existing Dependency Files Selected'), + '#value' => '<div id="existing_depfile_selected"></div>', + ); + + $form['existing_depfile']['dep_lab_title'] = array( + '#type' => 'select', + '#title' => t('Title of the Lab'), + '#options' => _list_of_lab_titles(), + ); + + list($files_options, $files_options_class) = _list_of_dependency_files(); + $form['existing_depfile']['dep_experiment_files'] = array( + '#type' => 'checkboxes', + '#title' => t('Dependency Files'), + '#options' => $files_options, + '#options_class' => $files_options_class, + '#multiple' => TRUE, + ); + + $form['existing_depfile']['dep_upload'] = array( + '#type' => 'item', + '#value' => l('Upload New Depedency Files', 'lab_migration/code/upload_dep'), + ); + /************ END OF EXISTING DEPENDENCIES **************/ + + $form['result'] = array( + '#type' => 'fieldset', + '#title' => t('Result Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['result']['result1'] = array( + '#type' => 'file', + '#title' => t('Upload result file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), + ); + $form['result']['result2'] = array( + '#type' => 'file', + '#title' => t('Upload result file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), + ); + + $form['xcos'] = array( + '#type' => 'fieldset', + '#title' => t('XCOS Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['xcos']['xcos1'] = array( + '#type' => 'file', + '#title' => t('Upload xcos file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), + ); + $form['xcos']['xcos2'] = array( + '#type' => 'file', + '#title' => t('Upload xcos file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'lab_migration/code'), + ); + return $form; +} + +function bulk_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 numbers.')); + + if (!check_name($form_state['values']['code_caption'])) + form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.')); + + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if ( ! ($_FILES['files']['name']['sourcefile1'] || $_FILES['files']['name']['xcos1'])) + form_set_error('sourcefile1', t('Please upload atleast one main or source file or xcos file.')); + + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'source')) + $file_type = 'S'; + else if (strstr($file_form_name, 'result')) + $file_type = 'R'; + else if (strstr($file_form_name, 'xcos')) + $file_type = 'X'; + else + $file_type = 'U'; + + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('lab_migration_source_extensions', ''); + break; + case 'R': + $allowed_extensions_str = variable_get('lab_migration_result_extensions', ''); + break; + case 'X': + $allowed_extensions_str = variable_get('lab_migration_xcos_extensions', ''); + break; + } + + $allowed_extensions = explode(',' , $allowed_extensions_str); + $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name]))); + if (!in_array($temp_extension, $allowed_extensions)) + form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); + if ($_FILES['files']['size'][$file_form_name] <= 0) + form_set_error($file_form_name, t('File size cannot be zero.')); + + /* check if valid file name */ + if (!lab_migration_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + } + } + } + + /* add javascript dependency selection effects */ + $dep_selection_js = " $(document).ready(function() { + $('#edit-existing-depfile-dep-lab-title').change(function() { + var dep_selected = ''; + /* showing and hiding relevant files */ + $('.form-checkboxes .option').hide(); + $('.form-checkboxes .option').each(function(index) { + var activeClass = $('#edit-existing-depfile-dep-lab-title').val(); + if ($(this).children().hasClass(activeClass)) { + $(this).show(); + } + if ($(this).children().attr('checked') == true) { + dep_selected += $(this).children().next().text() + '<br />'; + } + }); + /* showing list of already existing dependencies */ + $('#existing_depfile_selected').html(dep_selected); + }); + + $('.form-checkboxes .option').change(function() { + $('#edit-existing-depfile-dep-lab-title').trigger('change'); + }); + $('#edit-existing-depfile-dep-lab-title').trigger('change'); + });"; + drupal_add_js($dep_selection_js, 'inline', 'header'); +} + +function bulk_upload_code_form_submit($form, &$form_state) { + global $user; + + $root_path = lab_migration_path(); + + $proposal_data = get_proposal(); + if (!$proposal_data) { + drupal_goto(''); + return; + } + + $proposal_id = $proposal_data->id; + + /************************ check experiment details ************************/ + $experiment_id = (int)$form_state['values']['experiment']; + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d AND proposal_id = %d LIMIT 1", $experiment_id, $proposal_id); + $experiment_data = db_fetch_object($experiment_q); + if (!$experiment_data) + { + drupal_set_message("Invalid experiment seleted", 'error'); + drupal_goto('lab_migration/code'); + } + + /* create proposal folder if not present */ + $dest_path = $proposal_id . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + + /* get solution details - dont allow if already solution present */ + $cur_solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND code_number = '%s'", $experiment_id, $experiment_data->number . '.' . $form_state['values']['code_number']); + if ($cur_solution_d = db_fetch_object($cur_solution_q)) + { + if ($cur_solution_d->approval_status == 1) + { + drupal_set_message(t("Solution already approved. Cannot overwrite it."), 'error'); + drupal_goto('lab_migration/code'); + return; + } else if ($cur_solution_d->approval_status == 0) { + drupal_set_message(t("Solution is under pending review. Delete the solution and reupload it."), 'error'); + drupal_goto('lab_migration/code'); + return; + } else { + drupal_set_message(t("Error uploading solution. Please contact administrator."), 'error'); + drupal_goto('lab_migration/code'); + return; + } + } + + /* creating experiment directories */ + $dest_path .= 'EXP' . $experiment_data->number . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + + /* creating code directories */ + $dest_path .= 'CODE' . $experiment_data->number . '.' . $form_state['values']['code_number'] . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + + /* creating solution database entry */ + db_query("INSERT INTO {lab_migration_solution} (experiment_id, approver_uid, code_number, caption, approval_date, approval_status, timestamp) VALUES (%d, %d, '%s', '%s', %d, %d, %d)", + $experiment_id, + 0, + $experiment_data->number . '.' . $form_state['values']['code_number'], + $form_state['values']['code_caption'], + 0, + 0, + time() + ); + $solution_id = db_last_insert_id('lab_migration_solution', 'id'); + + /* linking existing dependencies */ + foreach ($form_state['values']['existing_depfile']['dep_experiment_files'] as $row) + { + if ($row > 0) + { + /* insterting into database */ + db_query("INSERT INTO {lab_migration_solution_dependency} (solution_id, dependency_id) + VALUES (%d, %d)", + $solution_id, + $row + ); + } + } + + /* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'source')) + $file_type = 'S'; + else if (strstr($file_form_name, 'result')) + $file_type = 'R'; + else if (strstr($file_form_name, 'xcos')) + $file_type = 'X'; + else + $file_type = 'U'; + + if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error'); + return; + } + + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + /* for uploaded files making an entry in the database */ + db_query("INSERT INTO {lab_migration_solution_files} (solution_id, filename, filepath, filemime, filesize, filetype, timestamp) + VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)", + $solution_id, + $_FILES['files']['name'][$file_form_name], + $dest_path . $_FILES['files']['name'][$file_form_name], + $_FILES['files']['type'][$file_form_name], + $_FILES['files']['size'][$file_form_name], + $file_type, + time() + ); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } else { + drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error'); + } + } + } + drupal_set_message('Solution uploaded successfully.', 'status'); + + /* sending email */ + $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $param['solution_uploaded']['solution_id'] = $solution_id; + $param['solution_uploaded']['user_id'] = $user->uid; + if (!drupal_mail('lab_migration', 'solution_uploaded', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) + drupal_set_message('Error sending email message.', 'error'); + + drupal_goto('lab_migration/code'); +} + +/******************************************************************************/ +/************************** GENERAL FUNCTIONS *********************************/ +/******************************************************************************/ + +function _list_of_lab_titles() +{ + $lab_titles = array('0' => 'Please select...'); + $lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 OR approval_status = 3 ORDER BY lab_title ASC"); + while ($lab_titles_data = db_fetch_object($lab_titles_q)) + { + $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name . ')'; + } + return $lab_titles; +} + +function _list_of_dependency_files() +{ + $dependency_files = array(); + $dependency_files_class = array(); + $dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} ORDER BY filename ASC"); + + while ($dependency_files_data = db_fetch_object($dependency_files_q)) + { + $temp_caption = ''; + if ($dependency_files_data->caption) + $temp_caption .= ' (' . $dependency_files_data->caption . ')'; + $dependency_files[$dependency_files_data->id] = l($dependency_files_data->filename . $temp_caption, 'lab_migration/download/dependency/' . $dependency_files_data->id); + $dependency_files_class[$dependency_files_data->id] = $dependency_files_data->proposal_id; + } + return array($dependency_files, $dependency_files_class); +} + diff --git a/dependency_approval.inc b/dependency_approval.inc index b82849f..447cd8f 100755 --- a/dependency_approval.inc +++ b/dependency_approval.inc @@ -118,6 +118,15 @@ function dependency_approval_form_submit($form, &$form_state) if (delete_dependency($form_state['values']['run']['dependency'])) { drupal_set_message('Dependency deleted' , 'status'); + + /* email */ + $email_subject = t('Dependency deleted'); + $email_body = t('Dependency deleted : .') . $form_state['values']['run']['dependency']; + $email_to = variable_get('lab_migration_emails', '') . ', ' . $user->mail; + $param['standard']['subject'] = $email_subject; + $param['standard']['body'] = $email_body; + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) + drupal_set_message('Error sending email message.', 'error'); } } } diff --git a/general.inc b/general.inc deleted file mode 100755 index df0707e..0000000 --- a/general.inc +++ /dev/null @@ -1,226 +0,0 @@ -<?php -// $Id$ - -function list_chapters() -{ - global $user; - - /************************ start approve book details ************************/ - $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); - $proposal_data = db_fetch_object($proposal_q); - if (!$proposal_data) - { - drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error'); - drupal_goto(''); - } - if ($proposal_data->proposal_status != 1) - { - switch ($proposal_data->proposal_status ) - { - case 0: - drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); - return; - break; - case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); - drupal_goto(''); - return; - break; - case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status'); - drupal_goto(''); - return; - break; - default: - drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - break; - } - } - - $preference_q = db_query("SELECT * FROM {lab_migration_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); - $preference_data = db_fetch_object($preference_q); - if (!$preference_data) - { - drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - } - /************************ end approve book details **************************/ - - $return_html = '<br />'; - $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />'; - $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />'; - $return_html .= l('Upload Example Code', 'lab_migration/code/upload') . '<br />'; - - /* get chapter list */ - $chapter_rows = array(); - $chapter_q = db_query("SELECT * FROM {lab_migration_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_data->id); - while ($chapter_data = db_fetch_object($chapter_q)) - { - /* get example list */ - $example_q = db_query("SELECT count(*) as example_count FROM {lab_migration_example} WHERE chapter_id = %d", $chapter_data->id); - $example_data = db_fetch_object($example_q); - $chapter_rows[] = array($chapter_data->number, $chapter_data->name . ' (' . l('Edit', 'lab_migration/code/chapter/edit/' . $chapter_data->id) . ')', $example_data->example_count, l('View', 'lab_migration/code/list_examples/' . $chapter_data->id)); - } - - /* check if there are any chapters */ - if (!$chapter_rows) - { - drupal_set_message(t('No uploads found.'), 'status'); - return $return_html; - } - - $chapter_header = array('Chapter No.', 'Title of the Chapter', 'Uploaded Examples', 'Actions'); - $return_html .= theme_table($chapter_header, $chapter_rows); - return $return_html; -} - -function list_examples() -{ - global $user; - - /************************ start approve book details ************************/ - $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid); - $proposal_data = db_fetch_object($proposal_q); - if (!$proposal_data) - { - drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error'); - drupal_goto(''); - } - if ($proposal_data->proposal_status != 1) - { - switch ($proposal_data->proposal_status ) - { - case 0: - drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status'); - drupal_goto(''); - return; - break; - case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); - drupal_goto(''); - return; - break; - case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status'); - drupal_goto(''); - return; - break; - default: - drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - break; - } - } - - $preference_q = db_query("SELECT * FROM {lab_migration_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id); - $preference_data = db_fetch_object($preference_q); - if (!$preference_data) - { - drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error'); - drupal_goto(''); - return; - } - /************************ end approve book details **************************/ - - /* get chapter details */ - $chapter_id = arg(3); - $chapter_q = db_query("SELECT * FROM {lab_migration_chapter} WHERE id = %d AND preference_id = %d LIMIT 1", $chapter_id, $preference_data->id); - if ($chapter_data = db_fetch_object($chapter_q)) - { - $return_html = '<br />'; - $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />'; - $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />'; - $return_html .= '<strong>Chapter Number:</strong><br />' . $chapter_data->number . '<br /><br />'; - $return_html .= '<strong>Title of the Chapter:</strong><br />' . $chapter_data->name . '<br />'; - } else { - drupal_set_message(t('Invalid chapter.'), 'error'); - drupal_goto('lab_migration/code'); - return; - } - - $return_html .= '<br />' . l('Back to Chapter List', 'lab_migration/code'); - - /* get example list */ - $example_rows = array(); - $example_q = db_query("SELECT * FROM {lab_migration_example} WHERE chapter_id = %d ORDER BY - CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC, - CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC, - CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id); - while ($example_data = db_fetch_object($example_q)) - { - /* approval status */ - $approval_status = ''; - switch ($example_data->approval_status) - { - case 0: $approval_status = 'Pending'; break; - case 1: $approval_status = 'Approved'; break; - case 2: $approval_status = 'Rejected'; break; - } - - /* example files */ - $example_files = ''; - $example_files_q = db_query("SELECT * FROM {lab_migration_example_files} WHERE example_id = %d ORDER BY filetype", $example_data->id); - while ($example_files_data = db_fetch_object($example_files_q)) - { - $file_type = ''; - switch ($example_files_data->filetype) - { - case 'S': $file_type = 'Main or Source'; break; - case 'R': $file_type = 'Result'; break; - case 'X': $file_type = 'xcos'; break; - default: - } - $example_files .= l($example_files_data->filename, 'download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />'; - } - /* dependency files */ - $dependency_files = ''; - $dependency_files_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename - FROM {lab_migration_example_dependency} example_dependency JOIN {lab_migration_dependency_files} dependency - ON example_dependency.dependency_id = dependency.id - WHERE example_dependency.example_id = %d", $example_data->id); - while ($dependency_files_data = db_fetch_object($dependency_files_q)) - { - $dependency_files .= l($dependency_files_data->dependency_filename, 'download/dependency/' . $dependency_files_data->dependency_id) . ' (Dependency)<br />'; - } - $example_files .= $dependency_files; - - if ($example_data->approval_status == 0) - { - $example_rows[] = array('data' => array($example_data->number, $example_data->caption, $approval_status, $example_files, l('Edit', 'lab_migration/code/edit/' . $example_data->id) . ' | ' . l('Delete', 'lab_migration/code/delete/' . $example_data->id, array('attributes' => array('onClick' => 'return confirm("Are you sure you want to delete the example?")')))), 'valign' => 'top'); - } else { - $example_rows[] = array('data' => array($example_data->number, $example_data->caption, $approval_status, $example_files, l('Download', 'download/example/' . $example_data->id)), 'valign' => 'top'); - } - } - - $example_header = array('Example No.', 'Caption', 'Status', 'Files', 'Action'); - $return_html .= theme_table($example_header, $example_rows); - return $return_html; -} - -function get_category_name($category_id) { - $category_data = ''; - switch ($category_id) - { - 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; - } - return $category_data; -} diff --git a/lab_migration.module b/lab_migration.module index 8ca981c..63588d1 100755 --- a/lab_migration.module +++ b/lab_migration.module @@ -1,7 +1,6 @@ <?php // $Id$ -require_once('general.inc'); require_once('general_deletion.inc'); require_once('email.inc'); @@ -183,15 +182,15 @@ function lab_migration_menu() 'weight' => 3, 'file' => 'dependency_approval.inc', ); - $items['lab_migration/code_approval/editcode'] = array( - 'title' => 'Admin Edit Example', - 'description' => 'Admin Edit Example', + $items['lab_migration/code_approval/upload'] = array( + 'title' => 'Admin Upload', + 'description' => 'Admin Upload', 'page callback' => 'drupal_get_form', - 'page arguments' => array('upload_examples_admin_edit_form'), - 'access arguments' => array('approve code'), + 'page arguments' => array('bulk_upload_code_form'), + 'access arguments' => array('bulk manage code'), 'type' => MENU_CALLBACK, - 'weight' => 3, - 'file' => 'editcodeadmin.inc', + 'weight' => 4, + 'file' => 'bulk_upload_code.inc', ); $items['lab_migration/code_approval/notes'] = array( 'title' => 'Notes for Reviewers', @@ -242,18 +241,9 @@ function lab_migration_menu() 'file' => 'dependency.inc', 'weight' => 3, ); - $items['lab_migration/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['lab_migration/code/delete'] = array( - 'title' => 'Delete Example', - 'description' => 'Delete Example', + 'title' => 'Delete Solution', + 'description' => 'Delete Solution', 'page callback' => 'upload_code_delete', 'access arguments' => array('upload code'), 'type' => MENU_CALLBACK, @@ -400,9 +390,9 @@ function lab_migration_ajax() if ($example_data = db_fetch_object($example_q)) { if ($example_data->approval_status == 1) - echo 'Warning! Example already approved. You cannot upload the same example again.'; + echo 'Warning! Solution already approved. You cannot upload the same solution again.'; else - echo 'Warning! Example already uploaded. Delete the example and reupload it.'; + echo 'Warning! Solution already uploaded. Delete the solution and reupload it.'; return; } } @@ -471,3 +461,28 @@ function get_proposal() { return FALSE; } +/***************************** GENERAL FUNCTIONS ******************************/ + +function get_category_name($category_id) { + $category_data = ''; + switch ($category_id) + { + 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; + } + return $category_data; +} + @@ -193,7 +193,7 @@ function _latex_run_script($lab_filename, $solution_provider_filename, $latex_fi { $root_path = lab_migration_path(); $ret = 0; - + chdir("lab_migration"); chdir("uploads"); chdir("latex"); diff --git a/manage_solution_proposal.inc b/manage_solution_proposal.inc index 4bdea77..f6acbd7 100755 --- a/manage_solution_proposal.inc +++ b/manage_solution_proposal.inc @@ -157,8 +157,9 @@ function solution_proposal_approval_form_validate($form, &$form_state) $solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); $solution_provider_data = db_fetch_object($solution_provider_q); - $solution_provider_present_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = %d AND approval_status IN (0, 1, 2) AND id != %d", $solution_provider_data->uid, $proposal_id); - if (db_fetch_object($solution_provider_present_q)) { + $solution_provider_present_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = %d AND approval_status IN (0, 1) AND id != %d", $solution_provider_data->uid, $proposal_id); + if ($x = db_fetch_object($solution_provider_present_q)) { + drupal_set_message($proposal_id); form_set_error('', t('Solution provider has already one proposal active')); } } @@ -239,7 +239,7 @@ function lab_migration_run_form($form_state) function _list_of_labs() { $lab_titles = array('0' => 'Please select...'); - $lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} ORDER BY lab_title ASC"); + $lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); while ($lab_titles_data = db_fetch_object($lab_titles_q)) { $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name . ')'; diff --git a/solution_proposal.inc b/solution_proposal.inc index f829d8e..04c473e 100755 --- a/solution_proposal.inc +++ b/solution_proposal.inc @@ -116,7 +116,7 @@ function lab_migration_solution_proposal_form_validate($form_state, &$form_state { global $user; - $solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = %d AND approval_status IN (0, 1, 2) AND solution_status IN (0, 1)", $user->uid); + $solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = %d AND approval_status IN (0, 1) AND solution_status IN (0, 1, 2)", $user->uid); if (db_fetch_object($solution_provider_q)) { form_set_error('', t("You have already applied for a solution. Please compelete that before applying for another solution.")); drupal_goto('lab_migration/open_proposal'); |