diff options
-rw-r--r-- | bulk_approval.inc | 20 | ||||
-rwxr-xr-x | code_approval.inc | 14 | ||||
-rwxr-xr-x | dependency.inc | 2 | ||||
-rwxr-xr-x | download.inc | 188 | ||||
-rwxr-xr-x | full_download.inc | 160 | ||||
-rwxr-xr-x | lab_migration.module | 26 | ||||
-rwxr-xr-x | manage_proposal.inc | 16 | ||||
-rwxr-xr-x | run.inc | 276 | ||||
-rwxr-xr-x | upload_code.inc | 27 |
9 files changed, 696 insertions, 33 deletions
diff --git a/bulk_approval.inc b/bulk_approval.inc index 581b1c6..03cdc31 100644 --- a/bulk_approval.inc +++ b/bulk_approval.inc @@ -202,18 +202,14 @@ function bulk_approval_form($form_state) } /* dependency files */ - $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption - FROM {lab_migration_solution_dependency} solution_dependency LEFT JOIN {lab_migration_dependency_files} dependency - ON solution_dependency.dependency_id = dependency.id - WHERE solution_dependency.solution_id = %d", $form_state['values']['run']['solution']); - while ($dependency_list_data = db_fetch_object($dependency_list_q)) - { - $solution_file_type = 'Dependency file'; - $temp_caption = ''; - if ($dependency_list_data->dependency_caption) - $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')'; - $solution_files_rows[] = array(l($dependency_list_data->dependency_filename, 'lab_migration/download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $solution_file_type); - } + $dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $form_state['values']['run']['solution']); + while ($dependency_data = db_fetch_object($dependency_q)) + { + $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); + $solution_file_type = 'Dependency file'; + $solution_files_rows[] = array(l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->dependency_id), $solution_file_type); + } /* creating list of files table */ $solution_files_header = array('Filename', 'Type'); diff --git a/code_approval.inc b/code_approval.inc index a2c6e72..73fdc26 100755 --- a/code_approval.inc +++ b/code_approval.inc @@ -138,15 +138,17 @@ function code_approval_form($form_state) case 'U': $code_file_type = 'Unknown'; break; default: $code_file_type = 'Unknown'; break; } - $solution_files_html .= l($solution_files_data->filename, '') . ' (' . $code_file_type . ')' . '<br/>'; + $solution_files_html .= l($solution_files_data->filename, 'lab_migration/download/file/' . $solution_files_data->id) . ' (' . $code_file_type . ')' . '<br/>'; } } /* get dependencies files */ - $dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE proposal_id = %d ORDER BY id ASC", $proposal_data->id); - if ($dependency_files_q) { - while ($dependency_files_data = db_fetch_object($dependency_files_q)) { - $solution_files_html .= l($dependency_files_data->filename, '') . ' (' . 'Dependency' . ')' . '<br/>'; - } + $dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d ORDER BY id ASC", $solution_id); + while ($dependency_data = db_fetch_object($dependency_q)) + { + $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); + $solution_file_type = 'Dependency file'; + $solution_files_html .= l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->id) . ' (' . 'Dependency' . ')' . '<br/>'; } $form['solution_files'] = array( diff --git a/dependency.inc b/dependency.inc index da9c567..5bf044e 100755 --- a/dependency.inc +++ b/dependency.inc @@ -180,7 +180,7 @@ function _list_existing_dependency($proposal_id) $temp_caption = ''; if ($proposal_dependency_files_data->caption) $temp_caption = ' (' . $proposal_dependency_files_data->caption . ')'; - $return_html .= '<li>' . l($proposal_dependency_files_data->filename . $temp_caption, 'download/dependency/' . $proposal_dependency_files_data->id) . '</li>'; + $return_html .= '<li>' . l($proposal_dependency_files_data->filename . $temp_caption, 'lab_migration/download/dependency/' . $proposal_dependency_files_data->id) . '</li>'; $counter++; } if ($counter == 0) diff --git a/download.inc b/download.inc new file mode 100755 index 0000000..2707686 --- /dev/null +++ b/download.inc @@ -0,0 +1,188 @@ +<?php +// $Id$ + +function lab_migration_download_solution_file() +{ + $solution_file_id = arg(3); + $root_path = lab_migration_path(); + + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE id = %d LIMIT 1", $solution_file_id); + $solution_file_data = db_fetch_object($solution_files_q); + header('Content-Type: ' . $solution_file_data->filemime); + header('Content-disposition: attachment; filename="' . $solution_file_data->filename . '"'); + header('Content-Length: ' . filesize($root_path . $solution_file_data->filepath)); + readfile($root_path . $solution_file_data->filepath); +} + +function lab_migration_download_dependency_file() +{ + $dependency_file_id = arg(3); + $root_path = lab_migration_path(); + + $dependency_file_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id); + $dependency_file_data = db_fetch_object($dependency_file_q); + header('Content-Type: ' . $dependency_file_data->filemime); + header('Content-disposition: attachment; filename="' . $dependency_file_data->filename . '"'); + header('Content-Length: ' . filesize($root_path . $dependency_file_data->filepath)); + readfile($root_path . $dependency_file_data->filepath); +} + +function lab_migration_download_solution() +{ + $solution_id = arg(3); + $root_path = lab_migration_path(); + + /* get solution data */ + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id); + $solution_data = db_fetch_object($solution_q); + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); + $experiment_data = db_fetch_object($experiment_q); + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_id); + + $CODE_PATH = 'CODE' . $solution_data->code_number . '/'; + + /* zip filename */ + $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + + /* creating zip archive on the server */ + $zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + $zip_file_count = $zip->numFiles; + $zip->close(); + + if ($zip_file_count > 0) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="CODE' . $solution_data->code_number . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + readfile($zip_filename); + unlink($zip_filename); + } else { + drupal_set_message("There are no files in this solutions to download", 'error'); + drupal_goto('lab_migration_run'); + } +} + +function lab_migration_download_experiment() +{ + $experiment_id = arg(3); + $root_path = lab_migration_path(); + + /* get solution data */ + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id); + $experiment_data = db_fetch_object($experiment_q); + $EXP_PATH = 'EXP' . $experiment_data->number . '/'; + + /* zip filename */ + $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + + /* creating zip archive on the server */ + $zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + $zip_file_count = $zip->numFiles; + $zip->close(); + + if ($zip_file_count > 0) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="EXP' . $experiment_data->number . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + readfile($zip_filename); + unlink($zip_filename); + } else { + drupal_set_message("There are no solutions in this experiment to download", 'error'); + drupal_goto('lab_migration_run'); + } +} + +function lab_migration_download_lab() +{ + $lab_id = arg(3); + $root_path = lab_migration_path(); + + /* get solution data */ + $lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $lab_id); + $lab_data = db_fetch_object($lab_q); + $LAB_PATH = $lab_data->lab_title . '/'; + + /* zip filename */ + $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + + /* creating zip archive on the server */ + $zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $lab_id); + while ($experiment_row = db_fetch_object($experiment_q)) + { + $EXP_PATH = 'EXP' . $experiment_row->number . '/'; + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_row->id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $LAB_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $LAB_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + } + $zip_file_count = $zip->numFiles; + $zip->close(); + + if ($zip_file_count > 0) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . $lab_data->lab_title . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + readfile($zip_filename); + unlink($zip_filename); + } else { + drupal_set_message("There are no solutions in this Lab to download", 'error'); + drupal_goto('lab_migration_run'); + } +} + diff --git a/full_download.inc b/full_download.inc new file mode 100755 index 0000000..7dcc2c5 --- /dev/null +++ b/full_download.inc @@ -0,0 +1,160 @@ +<?php +// $Id$ + +function lab_migration_download_full_experiment() +{ + $experiment_id = arg(3); + $root_path = lab_migration_path(); + $APPROVE_PATH = 'APPROVED/'; + $PENDING_PATH = 'PENDING/'; + + /* get solution data */ + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id); + $experiment_data = db_fetch_object($experiment_q); + $EXP_PATH = 'EXP' . $experiment_data->number . '/'; + + /* zip filename */ + $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + + /* creating zip archive on the server */ + $zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + + /* approved solutions */ + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + + /* unapproved solutions */ + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 0", $experiment_id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $PENDING_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + + $zip_file_count = $zip->numFiles; + $zip->close(); + + if ($zip_file_count > 0) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="EXP' . $experiment_data->number . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + readfile($zip_filename); + unlink($zip_filename); + } else { + drupal_set_message("There are no solutions in this experiment to download", 'error'); + drupal_goto('lab_migration/code_approval/bulk'); + } +} + +function lab_migration_download_full_lab() +{ + $lab_id = arg(3); + $root_path = lab_migration_path(); + $APPROVE_PATH = 'APPROVED/'; + $PENDING_PATH = 'PENDING/'; + + /* get solution data */ + $lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $lab_id); + $lab_data = db_fetch_object($lab_q); + $LAB_PATH = $lab_data->lab . '/'; + + /* zip filename */ + $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip'; + + /* creating zip archive on the server */ + $zip = new ZipArchive; + $zip->open($zip_filename, ZipArchive::CREATE); + + /* approved solutions */ + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $lab_id); + while ($experiment_row = db_fetch_object($experiment_q)) + { + $EXP_PATH = 'EXP' . $experiment_row->number . '/'; + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_row->id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $LAB_PATH . $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $LAB_PATH . $APPROVE_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + + /* unapproved solutions */ + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 0", $experiment_row->id); + while ($solution_row = db_fetch_object($solution_q)) + { + $CODE_PATH = 'CODE' . $solution_row->code_number . '/'; + $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id); + $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = db_fetch_object($solution_files_q)) + { + $zip->addFile($root_path . $solution_files_row->filepath, $LAB_PATH . $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = db_fetch_object($solution_dependency_files_q)) + { + $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id)); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $LAB_PATH . $PENDING_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename); + } + } + } + + $zip_file_count = $zip->numFiles; + $zip->close(); + + if ($zip_file_count > 0) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . $lab_data->lab_title . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + readfile($zip_filename); + unlink($zip_filename); + } else { + drupal_set_message("There are no solutions in this lab to download", 'error'); + drupal_goto('lab_migration/code_approval/bulk'); + } +} + diff --git a/lab_migration.module b/lab_migration.module index f0b74af..5d7fda8 100755 --- a/lab_migration.module +++ b/lab_migration.module @@ -264,6 +264,32 @@ function lab_migration_menu() 'type' => MENU_CALLBACK, 'file' => 'download.inc', ); + $items['lab_migration/full_download/experiment'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_full_experiment', + 'access arguments' => array('approve code'), + 'type' => MENU_CALLBACK, + 'file' => 'full_download.inc', + ); + $items['lab_migration/full_download/lab'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_full_lab', + 'access arguments' => array('approve code'), + 'type' => MENU_CALLBACK, + 'file' => 'full_download.inc', + ); + + /* DOWNLOAD FOR EVERYONE */ + $items['lab_migration_run'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('lab_migration_run_form'), + 'access arguments' => array('access content'), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'run.inc', + ); return $items; } diff --git a/manage_proposal.inc b/manage_proposal.inc index 641eb1d..cd683f1 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -212,7 +212,7 @@ function proposal_approval_form($form_state) '#required' => TRUE, ); - $form['message'] = array( + $form['message'] = array( '#type' => 'textarea', '#title' => t('Reason for disapproval'), ); @@ -662,11 +662,25 @@ function proposal_edit_form($form_state) function proposal_edit_form_validate($form, &$form_state) { + $proposal_id = (int)arg(3); + if ($form_state['values']['solution_provider_uid'] == 3) { if (!user_load(array('name' => check_plain($form_state['values']['solution_provider_user_name'])))) { form_set_error('solution_provider_user_name', t('Solution provider user name does not exists')); } } + + /* check before delete proposal */ + if ($form_state['values']['delete_proposal'] == 1) { + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id); + while ($experiment_data = db_fetch_object($experiment_q)) { + $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d", $experiment_data->id); + if (db_fetch_object($solution_q)) { + form_set_error('', t('Cannot delete proposal since there are solutions already uploaded. Use the "Bulk Manage" interface to delete this proposal')); + } + } + } + return; } function proposal_edit_form_submit($form, &$form_state) @@ -0,0 +1,276 @@ +<?php +// $Id$ +function lab_migration_run_form($form_state) +{ + $form['#redirect'] = FALSE; + + ahah_helper_register($form, $form_state); + + /* default value for ahah fields */ + if (!isset($form_state['storage']['run']['lab'])) + { + $lab_default_value = 0; + } else { + $lab_default_value = $form_state['storage']['run']['lab']; + } + + if (!isset($form_state['storage']['run']['experiment'])) + { + $experiment_default_value = 0; + } else { + if ($form_state['values']['run']['lab_hidden'] != $form_state['values']['run']['lab']) + $experiment_default_value = 0; + else + $experiment_default_value = $form_state['storage']['run']['experiment']; + } + + if (!isset($form_state['storage']['run']['solution'])) + { + $solution_default_value = 0; + } else { + if ($form_state['values']['run']['lab_hidden'] != $form_state['values']['run']['lab']) + $solution_default_value = 0; + else if ($form_state['values']['run']['experiment_hidden'] != $form_state['values']['run']['experiment']) + $solution_default_value = 0; + else + $solution_default_value = $form_state['storage']['run']['solution']; + } + + $form['run'] = array( + '#type' => 'fieldset', + '#title' => t('Download Codes'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#prefix' => '<div id="run-wrapper">', + '#suffix' => '</div>', + '#tree' => TRUE, + ); + + $form['run']['lab'] = array( + '#type' => 'select', + '#title' => t('Title of the Lab'), + '#options' => _list_of_labs(), + '#default_value' => $lab_default_value, + '#tree' => TRUE, + '#ahah' => array( + 'event' => 'change', + 'effect' => 'none', + 'path' => ahah_helper_path(array('run')), + 'wrapper' => 'run-wrapper', + 'progress' => array( + 'type' => 'throbber', + 'message' => t(''), + ), + ), + ); + + /* hidden form elements */ + $form['run']['lab_hidden'] = array( + '#type' => 'hidden', + '#value' => $form_state['values']['run']['lab'], + ); + + /* hidden form elements */ + $form['run']['experiment_hidden'] = array( + '#type' => 'hidden', + '#value' => $form_state['values']['run']['experiment'], + ); + + if ($lab_default_value > 0) + { + $lab_details = _lab_information($lab_default_value); + + /* solution provider */ + if ($lab_details->solution_provider_uid > 0) { + $user_solution_provider = user_load($lab_details->solution_provider_uid); + if ($user_solution_provider) { + $solution_provider = '<li><strong>Solution Provider: </strong>' . l($user_solution_provider->name, 'user/' . $lab_details->solution_provider_uid) . '</li>'; + } else { + $solution_provider = '<li><strong>Solution Provider: </strong> (Open) </li>'; + } + } else { + $solution_provider = '<li><strong>Solution Provider: </strong> (Open) </li>'; + } + + $category_data = ''; + switch ($lab_details->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; + } + + $form['run']['lab_details'] = array( + '#type' => 'item', + '#value' => '<span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span></td><td style="width: 35%;"><br />' . + '<ul>' . + '<li><strong>Proposer Name:</strong> ' . $lab_details->name_title . ' ' . $lab_details->name . '</li>' . + '<li><strong>Title of the Lab:</strong> ' . $lab_details->lab_title . '</li>' . + '<li><strong>Department:</strong> ' . $lab_details->department . '</li>' . + '<li><strong>University:</strong> ' . $lab_details->university . '</li>' . + '<li><strong>Category:</strong> ' . $category_data . '</li>' . + $solution_provider . + '</ul>', + ); + + $form['run']['download_lab'] = array( + '#type' => 'item', + '#value' => l('Download Lab Solutions', 'lab_migration/download/lab/' . $lab_default_value), + ); + $form['run']['download_pdf'] = array( + '#type' => 'item', + '#value' => l('Download PDF of Lab Solutions', 'lab_migration/generate_lab/' . $lab_default_value . '/1'), + ); + + $form['run']['experiment'] = array( + '#type' => 'select', + '#title' => t('Title of the Experiment'), + '#options' => _list_of_experiments($lab_default_value), + '#default_value' => $experiment_default_value, + '#tree' => TRUE, + '#ahah' => array( + 'event' => 'change', + 'effect' => 'none', + 'path' => ahah_helper_path(array('run')), + 'wrapper' => 'run-wrapper', + 'progress' => array( + 'type' => 'throbber', + 'message' => t(''), + ), + ), + ); + if ($experiment_default_value > 0) + { + $form['run']['download_experiment'] = array( + '#type' => 'item', + '#value' => l('Download Experiment', 'lab_migration/download/experiment/' . $experiment_default_value), + ); + + $form['run']['solution'] = array( + '#type' => 'select', + '#title' => t('Solution No. (Caption)'), + '#options' => _list_of_solutions($experiment_default_value), + '#default_value' => $solution_default_value, + '#tree' => TRUE, + '#ahah' => array( + 'event' => 'change', + 'effect' => 'none', + 'path' => ahah_helper_path(array('run')), + 'wrapper' => 'run-wrapper', + 'progress' => array( + 'type' => 'throbber', + 'message' => t(''), + ), + ), + ); + } + } + + /************ START OF $_POST **************/ + if ($_POST) + { + if (($lab_default_value > 0) && ($experiment_default_value > 0) && ($solution_default_value > 0)) + { + $solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['run']['solution']); + if ($solution_list_q) + { + $solution_files_rows = array(); + while ($solution_list_data = db_fetch_object($solution_list_q)) + { + $solution_file_type = ''; + switch ($solution_list_data->filetype) + { + case 'S' : $solution_file_type = 'Source or Main file'; break; + case 'R' : $solution_file_type = 'Result file'; break; + case 'X' : $solution_file_type = 'xcos file'; break; + default : $solution_file_type = 'Unknown'; break; + } + $solution_files_rows[] = array(l($solution_list_data->filename, 'lab_migration/download/file/' . $solution_list_data->id), $solution_file_type); + } + + /* dependency files */ + $dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $form_state['values']['run']['solution']); + while ($dependency_data = db_fetch_object($dependency_q)) + { + $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); + $solution_file_type = 'Dependency file'; + $solution_files_rows[] = array(l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->dependency_id), $solution_file_type); + } + + /* creating list of files table */ + $solution_files_header = array('Filename', 'Type'); + $solution_files = theme_table($solution_files_header, $solution_files_rows); + } + $form['run']['download_solution'] = array( + '#type' => 'item', + '#value' => l('Download Solution', 'lab_migration/download/solution/' . $solution_default_value), + ); + + $form['run']['solution_files'] = array( + '#type' => 'item', + '#title' => 'List of solution files', + '#value' => $solution_files, + ); + } + } + /************ END OF $_POST **************/ + + return $form; +} + +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"); + 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_experiments($proposal_id = 0) +{ + $experiments = array('0' => 'Please select...'); + $experiments_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_id); + while ($experiments_data = db_fetch_object($experiments_q)) + { + $experiments[$experiments_data->id] = $experiments_data->number . '. ' . $experiments_data->title; + } + return $experiments; +} + +function _list_of_solutions($experiment_id = 0) +{ + $solutions = array('0' => 'Please select...'); + $solutions_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY + CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY) ASC, + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED) ASC, + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED) ASC", $experiment_id); + while ($solutions_data = db_fetch_object($solutions_q)) + { + $solutions[$solutions_data->id] = $solutions_data->code_number . ' (' . $solutions_data->caption . ')'; + } + return $solutions; +} + +function _lab_information($proposal_id) +{ + $lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $lab_data = db_fetch_object($lab_q); + return $lab_data; +} + diff --git a/upload_code.inc b/upload_code.inc index b8f161a..5b763cb 100755 --- a/upload_code.inc +++ b/upload_code.inc @@ -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) { @@ -33,9 +33,9 @@ function list_experiments() 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)); + $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, ''); + $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,21 +48,22 @@ function list_experiments() case 'U': $code_file_type = 'Unknown'; break; default: $code_file_type = 'Unknown'; break; } - $experiment_rows[] = array('', "                " . $solution_files_data->filename, $code_file_type, '', ''); - } - } - /* get dependencies files */ - $dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE proposal_id = %d ORDER BY id ASC", $proposal_data->id); - if ($dependency_files_q) { - while ($dependency_files_data = db_fetch_object($dependency_files_q)) { - $experiment_rows[] = array('', "                " . $dependency_files_data->filename, 'Dependency', '', ''); + $experiment_rows[] = array("                  " . l($solution_files_data->filename, 'lab_migration/download/file/' . $solution_files_data->id), $code_file_type, '', ''); } } + /* get dependencies files */ + $dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d ORDER BY id ASC", $solution_data->id); + while ($dependency_data = db_fetch_object($dependency_q)) + { + $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_header = array('Exp. Number', 'Title of the Experiment', 'Type', 'Status', 'Actions'); + $experiment_header = array('No. Title of the Experiment', 'Type', 'Status', 'Actions'); $return_html .= theme_table($experiment_header, $experiment_rows); return $return_html; } @@ -516,7 +517,7 @@ function _list_of_dependency_files() $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, 'download/dependency/' . $dependency_files_data->id); + $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); |