From 316c75e79b383e6e76177c08641176a2528f0340 Mon Sep 17 00:00:00 2001 From: Sashi20 Date: Fri, 3 May 2019 15:25:22 +0530 Subject: Implement lab migration interface for R --- README.md | 2 +- bulk_approval.inc | 1096 +++++++++++++++++++++++++++++++ bulk_upload_code.inc | 483 ++++++++++++++ code_approval.inc | 387 +++++++++++ dependency.inc | 195 ++++++ dependency_approval.inc | 156 +++++ download.inc | 281 ++++++++ email.inc | 758 +++++++++++++++++++++ full_download.inc | 241 +++++++ general_deletion.inc | 241 +++++++ lab_details.inc | 69 ++ lab_migration.info | 7 + lab_migration.install | 435 +++++++++++++ lab_migration.module | 764 ++++++++++++++++++++++ latex.inc | 274 ++++++++ latex/Initial_body | 58 ++ latex/latex_test.sh | 199 ++++++ latex/pdf_creator.sh | 18 + manage_proposal.inc | 1483 ++++++++++++++++++++++++++++++++++++++++++ manage_solution_proposal.inc | 340 ++++++++++ notes.inc | 104 +++ proposal.inc | 585 +++++++++++++++++ run.inc | 520 +++++++++++++++ settings.inc | 98 +++ solution_proposal.inc | 392 +++++++++++ upload_code.inc | 665 +++++++++++++++++++ upload_code_delete.inc | 95 +++ 27 files changed, 9945 insertions(+), 1 deletion(-) mode change 100644 => 100755 README.md create mode 100755 bulk_approval.inc create mode 100755 bulk_upload_code.inc create mode 100755 code_approval.inc create mode 100755 dependency.inc create mode 100755 dependency_approval.inc create mode 100755 download.inc create mode 100755 email.inc create mode 100755 full_download.inc create mode 100755 general_deletion.inc create mode 100755 lab_details.inc create mode 100755 lab_migration.info create mode 100755 lab_migration.install create mode 100755 lab_migration.module create mode 100755 latex.inc create mode 100755 latex/Initial_body create mode 100755 latex/latex_test.sh create mode 100755 latex/pdf_creator.sh create mode 100755 manage_proposal.inc create mode 100755 manage_solution_proposal.inc create mode 100755 notes.inc create mode 100755 proposal.inc create mode 100755 run.inc create mode 100755 settings.inc create mode 100755 solution_proposal.inc create mode 100755 upload_code.inc create mode 100755 upload_code_delete.inc diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 59ad223..f13caa0 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# r_lab_migration \ No newline at end of file +R Lab migration Module for FOSSEE, IIT Bombay written for Drupal 7 diff --git a/bulk_approval.inc b/bulk_approval.inc new file mode 100755 index 0000000..28e5a9e --- /dev/null +++ b/bulk_approval.inc @@ -0,0 +1,1096 @@ + 'select', + '#title' => t('Title of the lab'), + '#options' => _bulk_list_of_labs(), + '#default_value' => $selected, + '#ajax' => array( + 'callback' => 'ajax_bulk_experiment_list_callback' + ), + '#suffix' => '
' + ); + $form['lab_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for Entire Lab'), + '#options' => _bulk_list_lab_actions(), + '#default_value' => 0, + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['lab_experiment_list'] = array( + '#type' => 'select', + '#title' => t('Titile of the experiment'), + '#options' => _ajax_bulk_get_experiment_list($selected), + '#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_bulk_solution_list_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_experiment'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['lab_experiment_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for Entire Experiment'), + '#options' => _bulk_list_experiment_actions(), + '#default_value' => 0, + '#prefix' => '
', + '#suffix' => '
', + //'#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0),),), + '#states' => array( + 'invisible' => array( + array( + array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 0 + ) + ) + ) + ) + ) + ); + $form['lab_solution_list'] = array( + '#type' => 'select', + '#title' => t('Solution'), + '#options' => _ajax_bulk_get_solution_list($select_two), + '#default_value' => isset($form_state['values']['lab_solution_list']) ? $form_state['values']['lab_solution_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_bulk_solution_files_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['lab_experiment_solution_actions'] = array( + '#type' => 'select', + '#title' => t('Please select action for solution'), + '#options' => _bulk_list_solution_actions(), + '#default_value' => 0, + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['edit_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['solution_files'] = array( + '#type' => 'item', + //'#title' => t('List of solution_files'), + '#markup' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('If Dis-Approved please specify reason for Dis-Approval'), + '#prefix' => '
', + '#states' => array( + 'visible' => array( + array( + array( + ':input[name="lab_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_experiment_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_experiment_solution_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 4 + ) + ) + ) + ), + 'required' => array( + array( + array( + ':input[name="lab_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_experiment_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_experiment_solution_actions"]' => array( + 'value' => 3 + ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 4 + ) + ) + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + return $form; + } +/** + * Ajax callback triggered by select. + */ +function ajax_bulk_experiment_list_callback($form, $form_state) + { + $commands = array(); + $lab_default_value = $form_state['values']['lab']; + if ($lab_default_value != 0) + { + $commands[] = ajax_command_html('#ajax_selected_lab', l('Download', 'lab-migration/full-download/lab/' . $lab_default_value) . ' ' . t('(Download all the approved and unapproved solutions of the entire lab)')); + /*$commands[] = ajax_command_html('#ajax_selected_lab_pdf', l('Download PDF', 'lab_migration/generate_lab/' . $lab_default_value . '/1') . + ' ' . t('(Download PDF of all the approved and unapproved solution of the entire lab)')); */ + $form['lab_actions']['#options'] = _bulk_list_lab_actions(); + $form['lab_experiment_list']['#options'] = _ajax_bulk_get_experiment_list($lab_default_value); + $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab_experiment_list']); + $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_replace('#ajax_selected_lab_action', drupal_render($form['lab_actions'])); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_action', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); + $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']); + $commands[] = ajax_command_html('#ajax_selected_experiment', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_action', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_action', ''); + $commands[] = ajax_command_html('#ajax_download_experiment', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_bulk_solution_list_callback($form, $form_state) + { + $commands = array(); + $experiment_list_default_value = $form_state['values']['lab_experiment_list']; + //var_dump($lab_default_value); + if ($experiment_list_default_value != 0) + { + $form['lab_experiment_actions']['#options'] = _bulk_list_experiment_actions(); + $form['lab_solution_list']['#options'] = _ajax_bulk_get_solution_list($experiment_list_default_value); + $commands[] = ajax_command_html('#ajax_download_experiment', l('Download Experiment', 'lab-migration/full-download/experiment/' . $experiment_list_default_value)); + $commands[] = ajax_command_data('#ajax_selected_experiment', 'form_state_value_select', $form_state['values']['lab_experiment_list']); + $commands[] = ajax_command_html('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_action', drupal_render($form['lab_experiment_actions'])); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + else + { + $commands[] = ajax_command_html('#ajax_download_experiment', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_action', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + // $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_bulk_solution_files_callback($form, $form_state) + { + $commands = array(); + $solution_list_default_value = $form_state['values']['lab_solution_list']; + //var_dump($lab_default_value); + if ($solution_list_default_value != 0) + { + $form['lab_experiment_solution_actions']['#options'] = _bulk_list_solution_actions(); + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', drupal_render($form['lab_experiment_solution_actions'])); + /*************************************************************************************/ + //$solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['solution']); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_list_default_value); + $solution_list_q = $query->execute(); + if ($solution_list_q) + { + $solution_files_rows = array(); + while ($solution_list_data = $solution_list_q->fetchObject()) + { + $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 + ); + if (strlen($solution_list_data->pdfpath) >= 5) + { + $pdfname = substr($solution_list_data->pdfpath, strrpos($solution_list_data->pdfpath, '/') + 1); + $solution_files_rows[] = array( + l($pdfname, 'lab-migration/download/pdf/' . $solution_list_data->id), + "PDF File" + ); + } + } + /* dependency files */ + //$dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $form_state['values']['solution']); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_list_default_value); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $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', array( + 'header' => $solution_files_header, + 'rows' => $solution_files_rows + )); + } + $form['solution_files']['#title'] = 'List of solution files'; + $form['solution_files']['#markup'] = $solution_files; + $commands[] = ajax_command_html('#ajax_download_experiment_solution', l('Download Solution', 'lab-migration/download/solution/' . $solution_list_default_value)); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', l('Edit Solution', 'lab-migration/code-approval/editcode/' . $solution_list_default_value)); + // $commands[] = ajax_command_html('#ajax_solution_files', $solution_files); + $commands[] = ajax_command_html('#ajax_solution_files', drupal_render($form['solution_files'])); + /*************************************************************************************/ + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +/************************************************************/ +function lab_migration_bulk_approval_form_submit($form, &$form_state) + { + global $user; + $root_path = lab_migration_path(); + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if ($form_state['values']['lab']) + //lab_migration_del_lab_pdf($form_state['values']['lab']); + if (user_access('lab migration bulk manage code')) + { + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $form_state['values']['lab']); + $user_query = $query->execute(); + $user_info = $user_query->fetchObject(); + $user_data = user_load($user_info->uid); + if (($form_state['values']['lab_actions'] == 1) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + /* approving entire lab */ + // $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $form_state['values']['lab']); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ''; + while ($experiment_data = $experiment_q->fetchObject()) + { + // db_query("UPDATE {lab_migration_solution} SET approval_status = 1, approver_uid = %d WHERE experiment_id = %d AND approval_status = 0", $user->uid, $experiment_data->id); + db_query("UPDATE {lab_migration_solution} SET approval_status = 1, approver_uid = :approver_uid WHERE experiment_id = :experiment_id AND approval_status = 0", array( + ':approver_uid' => $user->uid, + ':experiment_id' => $experiment_data->id + )); + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + drupal_set_message(t('Approved Entire Lab.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your all the uploaded solutions for the Lab with the below detail has been approved: + +Title of Lab :' . $user_info->lab_title . ' + +List of experiments : ' . $experiment_list . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + } + elseif (($form_state['values']['lab_actions'] == 2) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + /* pending review entire lab */ + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $form_state['values']['lab']); + $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = :proposal_id", array( + ':proposal_id' => $form_state['values']['lab'] + )); + while ($experiment_data = $experiment_q->fetchObject()) + { + //db_query("UPDATE {lab_migration_solution} SET approval_status = 0 WHERE experiment_id = %d", $experiment_data->id); + db_query("UPDATE {lab_migration_solution} SET approval_status = 0 WHERE experiment_id = :experiment_id", array( + ":experiment_id" => $experiment_data->id + )); + } + drupal_set_message(t('Pending Review Entire Lab.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions have been marked as pending', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your all the uploaded solutions for the Lab with Title : ' . $user_info->lab_title . ' have been marked as pending to be reviewed. + +You will be able to see the solutions after they have been approved by one of our reviewers. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solutions have been marked as pending'); + $email_body = array(0 => t('Your all the uploaded solutions for the Lab have been marked as pending to be review. You will be able to see the solutions after they have been approved by one of our reviewers.'));*/ + } + elseif (($form_state['values']['lab_actions'] == 3) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error'); + return; + } + if (!user_access('lab migration bulk delete code')) + { + drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Lab.'), 'error'); + return; + } + if (lab_migration_delete_lab($form_state['values']['lab'])) + { + drupal_set_message(t('Dis-Approved and Deleted Entire Lab.'), 'status'); + } + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire Lab.'), 'error'); + } + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions have been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your all the uploaded solutions for the whole Lab with Title : ' . $user_info->lab_title . ' have been marked as dis-approved. + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solutions have been marked as dis-approved'); + $email_body = array(0 =>t('Your all the uploaded solutions for the whole Lab have been marked as dis-approved. + + Reason for dis-approval: + + ' . $form_state['values']['message']));*/ + } + elseif (($form_state['values']['lab_actions'] == 4) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + drupal_set_message("Please mention the reason for disapproval/deletion. Minimum 30 character required", 'error'); + return; + } + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ''; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + if (!user_access('lab migration bulk delete code')) + { + drupal_set_message(t('You do not have permission to Bulk Delete Entire Lab Including Proposal.'), 'error'); + return; + } + /* check if dependency files are present */ + $dep_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE proposal_id = :proposal_id", array( + ":proposal_id" => $form_state['values']['lab'] + )); + if ($dep_data = $dep_q->fetchObject()) + { + drupal_set_message(t("Cannot delete lab since it has dependency files that can be used by others. First delete the dependency files before deleting the lab."), 'error'); + return; + } + if (lab_migration_delete_lab($form_state['values']['lab'])) + { + drupal_set_message(t('Dis-Approved and Deleted Entire Lab solutions.'), 'status'); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $form_state['values']['lab']); + $proposal_q = $query->execute()->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $exp_path = $root_path . $proposal_q->directory_name . '/EXP' . $experiment_data->number; + $dir_path = $root_path . $proposal_q->directory_name; + if (is_dir($dir_path)) + { + rmdir($exp_path); + $res = rmdir($dir_path); + if (!$res) + { + drupal_set_message(t("Cannot delete Lab directory : " . $dir_path . ". Please contact administrator."), 'error'); + return; + } + } + else + { + drupal_set_message(t("Lab directory not present : " . $dir_path . ". Skipping deleting lab directory."), 'status'); + } + /* deleting full proposal */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $form_state['values']['lab']); + $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = :id", array( + ":id" => $form_state['values']['lab'] + )); + $proposal_data = $proposal_q->fetchObject(); + $proposal_id = $proposal_data->id; + db_query("DELETE FROM {lab_migration_experiment} WHERE proposal_id = :proposal_id", array( + ":proposal_id" => $proposal_id + )); + db_query("DELETE FROM {lab_migration_proposal} WHERE id = :id", array( + ":id" => $proposal_id + )); + drupal_set_message(t('Deleted Lab Proposal.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions including the Lab proposal have been deleted', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +We regret to inform you that all the uploaded Experiments of your Lab with following details have been deleted permanently. + +Title of Lab :' . $user_info->lab_title . ' + +List of experiments : ' . $experiment_list . ' + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solutions including the Lab proposal have been deleted'); + $email_body = array(0 =>t('Your all the uploaded solutions including the Lab proposal have been deleted permanently.'));*/ + } + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire Lab.'), 'error'); + } + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 1) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + db_query("UPDATE {lab_migration_solution} SET approval_status = 1, approver_uid = :approver_uid WHERE experiment_id = :experiment_id AND approval_status = 0", array( + ":approver_uid" => $user->uid, + ":experiment_id" => $form_state['values']['lab_experiment_list'] + )); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $form_state['values']['lab_experiment_list']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $form_state['values']['lab_experiment_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + drupal_set_message(t('Approved Entire Experiment.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solution have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your Experiment for R Lab Migration with the following details is approved. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solutions have been approved'); + $email_body = array(0 =>t('Your all the uploaded solutions for the experiment have been approved.'));*/ + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 2) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + db_query("UPDATE {lab_migration_solution} SET approval_status = 0 WHERE experiment_id = :experiment_id", array( + ":experiment_id" => $form_state['values']['lab_experiment_list'] + )); + drupal_set_message(t('Entire Experiment marked as Pending Review.'), 'status'); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $form_state['values']['lab_experiment_list']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $form_state['values']['lab_experiment_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solution have been marked as pending', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your all the uploaded solutions for the experiment have been marked as pending to be reviewed. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /*$email_subject = t('Your uploaded Lab Migration solutions have been marked as pending'); + $email_body = array(0 =>t('Your all the uploaded solutions for the experiment have been marked as pending to be review.'));*/ + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 3) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error'); + return; + } + if (!user_access('lab migration bulk delete code')) + { + drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Experiment.'), 'error'); + return; + } + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $form_state['values']['lab_experiment_list']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $form_state['values']['lab_experiment_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + if (lab_migration_delete_experiment($form_state['values']['lab_experiment_list'])) + { + drupal_set_message(t('Dis-Approved and Deleted Entire Experiment.'), 'status'); + } + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Entire Experiment.'), 'error'); + } + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solutions have been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +We regret to inform you that your experiment with the following details under R Lab Migration is disapproved and has been deleted. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Please resubmit the modified solution. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /*$email_subject = t('Your uploaded Lab Migration solutions have been marked as dis-approved'); + $email_body = array(0 => t('Your uploaded solutions for the entire experiment have been marked as dis-approved. + + Reason for dis-approval: + + ' . $form_state['values']['message']));*/ + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 1)) + { + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $form_state['values']['lab_solution_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_value->experiment_id); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + db_query("UPDATE {lab_migration_solution} SET approval_status = 1, approver_uid = :approver_uid WHERE id = :id", array( + ":approver_uid" => $user->uid, + ":id" => $form_state['values']['lab_solution_list'] + )); + drupal_set_message(t('Solution approved.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solution has been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your Experiment for R Lab Migration with the following details is approved. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solution has been approved'); + $email_body = array(0 =>t('Your uploaded solution has been approved.'));*/ + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 2)) + { + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $form_state['values']['lab_solution_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_value->experiment_id); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + db_query("UPDATE {lab_migration_solution} SET approval_status = 0 WHERE id = :id", array( + ":id" => $form_state['values']['lab_solution_list'] + )); + drupal_set_message(t('Solution marked as Pending Review.'), 'status'); + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solution has been marked as pending', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your all the uploaded solutions for the experiment have been marked as pending to be reviewed. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /*$email_subject = t('Your uploaded Lab Migration solution has been marked as pending'); + $email_body = array(0 =>t('Your uploaded solution has been marked as pending to be review.'));*/ + } + elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 3)) + { + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $form_state['values']['lab_solution_list']); + $query->orderBy('code_number', 'ASC'); + $solution_q = $query->execute(); + $solution_value = $solution_q->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_value->experiment_id); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_value = $experiment_q->fetchObject(); + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('')); + drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error'); + return; + } + if (lab_migration_delete_solution($form_state['values']['lab_solution_list'])) + { + drupal_set_message(t('Solution Dis-Approved and Deleted.'), 'status'); + } + else + { + drupal_set_message(t('Error Dis-Approving and Deleting Solution.'), 'error'); + } + /* email */ + $email_subject = t('[!site_name] Your uploaded Lab Migration solution has been marked as dis-approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +We regret to inform you that your experiment with the following details under R Lab Migration is disapproved and has been deleted. + +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' + +Reason for dis-approval: ' . $form_state['values']['message'] . ' + +Please resubmit the modified solution. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) + ); + /* email */ + /* $email_subject = t('Your uploaded Lab Migration solution has been marked as dis-approved'); + $email_body = array(0 =>t('Your uploaded solution has been marked as dis-approved. + + Reason for dis-approval: + + ' . $form_state['values']['message']));*/ + } + else + { + drupal_set_message(t('Please select only one action at a time'), 'error'); + return; + } + /** sending email when everything done **/ + if ($email_subject) + { + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['standard']['subject'] = $email_subject; + $param['standard']['body'] = $email_body; + $param['standard']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) + { + drupal_set_message('Error sending email message.', 'error'); + } + } + } + else + { + drupal_set_message(t('You do not have permission to bulk manage code.'), 'error'); + } + } + return; + } +function lab_migration_with_morefeature($key, &$message, $params) + { + if (isset($params['subject'])) + { + $message['subject'] = $params['subject']; + } + if (isset($params['body'])) + { + $message['body'][] = $params['body']; + } + if (isset($params['headers']) && is_array($params['headers'])) + { + $message['headers'] += $params['headers']; + } + } +/**********************************************************/ +function _bulk_list_of_labs() + { + $lab_titles = array( + '0' => 'Please select...' + ); + //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_display', 1); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + while ($lab_titles_data = $lab_titles_q->fetchObject()) + { + $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name . ')'; + } + return $lab_titles; + } +function _ajax_bulk_get_experiment_list($lab_default_value = '') + { + $experiments = array( + '0' => 'Please select...' + ); + //$experiments_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $lab_default_value); + $query->orderBy('number', 'ASC'); + $experiments_q = $query->execute(); + while ($experiments_data = $experiments_q->fetchObject()) + { + $experiments[$experiments_data->id] = $experiments_data->number . '. ' . $experiments_data->title; + } + return $experiments; + } +function _bulk_list_lab_actions() + { + $lab_actions = array( + 0 => 'Please select...' + ); + $lab_actions[1] = 'Approve Entire Lab'; + $lab_actions[2] = 'Pending Review Entire Lab'; + $lab_actions[3] = 'Dis-Approve Entire Lab (This will delete all the solutions in the lab)'; + $lab_actions[4] = 'Delete Entire Lab Including Proposal'; + return $lab_actions; + } +function _ajax_bulk_get_solution_list($lab_experiment_list = '') + { + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $lab_experiment_list); + //$query->orderBy("CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED", "ASC"); + $solutions_q = $query->execute(); + while ($solutions_data = $solutions_q->fetchObject()) + { + $solutions[$solutions_data->id] = $solutions_data->code_number . ' (' . $solutions_data->caption . ')'; + } + return $solutions; + } +function _bulk_list_experiment_actions() + { + $lab_experiment_actions = array( + 0 => 'Please select...' + ); + $lab_experiment_actions[1] = 'Approve Entire Experiment'; + $lab_experiment_actions[2] = 'Pending Review Entire Experiment'; + $lab_experiment_actions[3] = 'Dis-Approve Entire Experiment (This will delete all the solutions in the experiment)'; + return $lab_experiment_actions; + } +function _bulk_list_solution_actions() + { + $lab_solution_actions = array( + 0 => 'Please select...' + ); + $lab_solution_actions[1] = 'Approve Entire Solution'; + $lab_solution_actions[2] = 'Pending Review Entire Solution'; + $lab_solution_actions[3] = 'Dis-approve Solution (This will delete the solution)'; + return $lab_solution_actions; + } \ No newline at end of file diff --git a/bulk_upload_code.inc b/bulk_upload_code.inc new file mode 100755 index 0000000..884fb20 --- /dev/null +++ b/bulk_upload_code.inc @@ -0,0 +1,483 @@ +fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Invalid proposal selected", 'error'); + drupal_goto('lab_migration/code_approval/bulk'); + } + /* add javascript for dependency selection effects */ + $dep_selection_js = "(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() + '
'; + } + }); + /* 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'); + })(jQuery);"; + 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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $query->orderBy('id', 'ASC'); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + $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('Upload all the eSim project files in .zip format'), + '#prefix' => '
', + '#suffix' => '
' + ); + $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.') . '
' . 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' => '
', + '#suffix' => '
', + '#tree' => TRUE + ); + /* existing dependencies */ + $form['existing_depfile']['selected'] = array( + '#type' => 'item', + '#title' => t('Existing Dependency Files Selected'), + '#value' => '
' + ); + $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.') . '
' . 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.') . '
' . 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.') . '
' . 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.') . '
' . 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_approval/bulk') + ); + return $form; + } +function lab_migration_bulk_upload_code_form_validate($form, &$form_state) + { + if (!lab_migration_check_code_number($form_state['values']['code_number'])) + form_set_error('code_number', t('Invalid Code Number. Code Number can contain only numbers.')); + if (!lab_migration_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 = "(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() + '
'; + } + }); + /* 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'); + }(jQuery));"; + drupal_add_js($dep_selection_js, 'inline', 'header'); + } +function lab_migration_bulk_upload_code_form_submit($form, &$form_state) + { + global $user; + $root_path = lab_migration_path(); + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Invalid proposal selected", 'error'); + drupal_goto('lab_migration/code_approval/upload/' . $proposal_id); + } + $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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $experiment_id); + $query->condition('proposal_id', $proposal_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message("Invalid experiment seleted", 'error'); + drupal_goto('lab_migration/code_approval/upload/' . $proposal_id); + } + /* 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']); + $code_number = $experiment_data->number . '.' . $form_state['values']['code_number']; + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('code_number', $code_number); + $cur_solution_q = $query->execute(); + if ($cur_solution_d = $cur_solution_q->fetchObject()) + { + if ($cur_solution_d->approval_status == 1) + { + drupal_set_message(t("Solution already approved. Cannot overwrite it."), 'error'); + drupal_goto('lab_migration/code_approval/upload/' . $proposal_id); + 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-approval/upload/' . $proposal_id); + return; + } + else + { + drupal_set_message(t("Error uploading solution. Please contact administrator."), 'error'); + drupal_goto('lab-migration/code-approval/upload/' . $proposal_id); + 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 */ + $query = "INSERT INTO {lab_migration_solution} (experiment_id, approver_uid, code_number, caption, approval_date, approval_status, timestamp) VALUES (:experiment_id, :approver_uid, :code_number, :caption, :approval_date, :approval_status, :timestamp)"; + $args = array( + ":experiment_id" => $experiment_id, + ":approver_uid" => 0, + ":code_number" => $experiment_data->number . '.' . $form_state['values']['code_number'], + ":caption" => $form_state['values']['code_caption'], + ":approval_date" => 0, + ":approval_status" => 0, + ":timestamp" => time() + ); + $solution_id = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + /* linking existing dependencies */ + foreach ($form_state['values']['existing_depfile']['dep_experiment_files'] as $row) + { + if ($row > 0) + { + /* insterting into database */ + $query = "INSERT INTO {lab_migration_solution_dependency} (solution_id, dependency_id) + VALUES (:solution_id, :dependency_id)"; + $args = array( + ":solution_id" => $solution_id, + ":dependency_id" => $row + ); + db_query($query, $args); + } + } + /* 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 */ + $query = "INSERT INTO {lab_migration_solution_files} (solution_id, filename, filepath, filemime, filesize, filetype, timestamp) + VALUES (:solution_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":solution_id" => $solution_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => $_FILES['files']['type'][$file_form_name], + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + db_query($query, $args); + 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; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_uploaded']['solution_id'] = $solution_id; + $param['solution_uploaded']['user_id'] = $user->uid; + $param['solution_uploaded']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_uploaded', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_goto('lab-migration/code-approval/bulk/'); + } +/******************************************************************************/ +/************************** 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"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $or = db_or(); + $or->condition('approval_status', 1); + $or->condition('approval_status', 3); + $query->condition($or); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + while ($lab_titles_data = $lab_titles_q->fetchObject()) + { + $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"); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->orderBy('filename', 'ASC'); + $dependency_files_q = $query->execute(); + while ($dependency_files_data = $dependency_files_q->fetchObject()) + { + $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/code_approval.inc b/code_approval.inc new file mode 100755 index 0000000..383eee4 --- /dev/null +++ b/code_approval.inc @@ -0,0 +1,387 @@ +fields('lab_migration_solution'); + $query->condition('approval_status', 0); + $pending_solution_q = $query->execute(); + if (!$pending_solution_q) + { + drupal_set_message(t('There are no pending code approvals.'), 'status'); + return ''; + } + $pending_solution_rows = array(); + while ($pending_solution_data = $pending_solution_q->fetchObject()) + { + /* get experiment data */ + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $pending_solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $pending_solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + /* get solution provider details */ + $solution_provider_user_name = ''; + $user_data = user_load($proposal_data->solution_provider_uid); + if ($user_data) + { + $solution_provider_user_name = $user_data->name; + } + else + { + $solution_provider_user_name = ''; + } + /* setting table row information */ + $pending_solution_rows[] = array( + $proposal_data->lab_title, + $experiment_data->title, + $proposal_data->name, + $solution_provider_user_name, + l('Edit', 'lab-migration/code-approval/approve/' . $pending_solution_data->id) + ); + } + /* check if there are any pending solutions */ + if (!$pending_solution_rows) + { + drupal_set_message(t('There are no pending solutions'), 'status'); + return ''; + } + $header = array( + 'Title of the Lab', + 'Experiment', + 'Proposer', + 'Solution Provider', + 'Actions' + ); + //$output = theme_table($header, $pending_solution_rows); + $output = theme('table', array( + 'header' => $header, + 'rows' => $pending_solution_rows + )); + return $output; + } +function lab_migration_code_approval_form($form_state) + { + $solution_id = (int) arg(3); + /* get solution details */ + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution selected.'), 'status'); + drupal_goto('lab-migration/code-approval'); + } + if ($solution_data->approval_status == 1) + { + drupal_set_message(t('This solution has already been approved. Are you sure you want to change the approval status?'), 'error'); + } + if ($solution_data->approval_status == 2) + { + drupal_set_message(t('This solution has already been dis-approved. Are you sure you want to change the approval status?'), 'error'); + } + /* get experiment data */ + //xperiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + /* get solution provider details */ + $solution_provider_user_name = ''; + $user_data = user_load($proposal_data->solution_provider_uid); + if ($user_data) + { + $solution_provider_user_name = $user_data->name; + } + else + { + $solution_provider_user_name = ''; + } + $form['#tree'] = TRUE; + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab') + ); + $form['name'] = array( + '#type' => 'item', + '#markup' => $proposal_data->name, + '#title' => t('Contributor Name') + ); + $form['experiment']['number'] = array( + '#type' => 'item', + '#markup' => $experiment_data->number, + '#title' => t('Experiment Number') + ); + $form['experiment']['title'] = array( + '#type' => 'item', + '#markup' => $experiment_data->title, + '#title' => t('Title of the Experiment') + ); + $form['back_to_list'] = array( + '#type' => 'item', + '#markup' => l('Back to Code Approval List', 'lab-migration/code-approval') + ); + $form['code_number'] = array( + '#type' => 'item', + '#markup' => $solution_data->code_number, + '#title' => t('Code No') + ); + $form['code_caption'] = array( + '#type' => 'item', + '#markup' => $solution_data->caption, + '#title' => t('Caption') + ); + /* get solution files */ + $solution_files_html = ''; + //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d ORDER BY id ASC", $solution_id); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_id); + $query->orderBy('id', 'ASC'); + $solution_files_q = $query->execute(); + if ($solution_files_q) + { + while ($solution_files_data = $solution_files_q->fetchObject()) + { + $code_file_type = ''; + switch ($solution_files_data->filetype) + { + case 'S': + $code_file_type = 'Source'; + break; + case 'R': + $code_file_type = 'Result'; + break; + case 'X': + $code_file_type = 'Xcox'; + break; + case 'U': + $code_file_type = 'Unknown'; + break; + default: + $code_file_type = 'Unknown'; + break; + } + $solution_files_html .= l($solution_files_data->filename, 'lab-migration/download/file/' . $solution_files_data->id) . ' (' . $code_file_type . ')' . '
'; + /*if(strlen($solution_files_data->pdfpath)>=5){ + $pdfname=substr($solution_files_data->pdfpath, strrpos($solution_files_data->pdfpath, '/') + 1); + $solution_files_html .=l($pdfname, 'lab-migration/download/pdf/' . $solution_files_data->id). ' (PDF File)' . '
'; + }*/ + } + } + /* get dependencies files */ + //$dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d ORDER BY id ASC", $solution_id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_id); + $query->orderBy('id', 'ASC'); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $solution_file_type = 'Dependency file'; + $solution_files_html .= l($dependency_files_data->filename, 'lab-migration/download/dependency/' . $dependency_files_data->id) . ' (' . 'Dependency' . ')' . '
'; + } + $form['solution_files'] = array( + '#type' => 'item', + '#markup' => $solution_files_html, + '#title' => t('Solution') + ); + $form['approved'] = array( + '#type' => 'radios', + '#options' => array( + '0' => 'Pending', + '1' => 'Approved', + '2' => 'Dis-approved (Solution will be deleted)' + ), + '#title' => t('Approval'), + '#default_value' => $solution_data->approval_status + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Reason for dis-approval'), + '#states' => array( + 'visible' => array( + ':input[name="approved"]' => array( + 'value' => '2' + ) + ), + 'required' => array( + ':input[name="approved"]' => array( + 'value' => '2' + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#markup' => l(t('Cancel'), 'lab_migration/code_approval') + ); + return $form; + } +function lab_migration_code_approval_form_validate($form, &$form_state) + { + if ($form_state['values']['approved'] == 2) + { + if (strlen(trim($form_state['values']['message'])) <= 30) + { + form_set_error('message', t('Please mention the reason for disapproval.')); + } + } + return; + } +function lab_migration_code_approval_form_submit($form, &$form_state) + { + global $user; + $solution_id = (int) arg(3); + /* get solution details */ + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution selected.'), 'status'); + drupal_goto('lab_migration/code_approval'); + } + /* get experiment data */ + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + /* get proposal data */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + $user_data = user_load($proposal_data->uid); + $solution_prove_user_data = user_load($proposal_data->solution_provider_uid); + // **** TODO **** : del_lab_pdf($proposal_data->id); + if ($form_state['values']['approved'] == "0") + { + $query = "UPDATE {lab_migration_solution} SET approval_status = 0, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :solution_id"; + $args = array( + ":approver_uid" => $user->uid, + ":approval_date" => time(), + ":solution_id" => $solution_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_pending']['solution_id'] = $solution_id; + $param['solution_pending']['user_id'] = $user_data->uid; + $param['solution_pending']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_pending', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else if ($form_state['values']['approved'] == "1") + { + $query = "UPDATE {lab_migration_solution} SET approval_status = 1, approver_uid = :approver_uid, approval_date = :approval_date WHERE id = :solution_id"; + $args = array( + ":approver_uid" => $user->uid, + ":approval_date" => time(), + ":solution_id" => $solution_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_approved']['solution_id'] = $solution_id; + $param['solution_approved']['user_id'] = $user_data->uid; + $param['solution_approved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_approved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else if ($form_state['values']['approved'] == "2") + { + if (lab_migration_delete_solution($solution_id)) + { + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_disapproved']['experiment_number'] = $experiment_data->number; + $param['solution_disapproved']['experiment_title'] = $experiment_data->title; + $param['solution_disapproved']['solution_number'] = $solution_data->code_number; + $param['solution_disapproved']['solution_caption'] = $solution_data->caption; + $param['solution_disapproved']['user_id'] = $user_data->uid; + $param['solution_disapproved']['message'] = $form_state['values']['message']; + $param['solution_disapproved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_disapproved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else + { + drupal_set_message('Error disapproving and deleting solution. Please contact administrator.', 'error'); + } + } + drupal_set_message('Updated successfully.', 'status'); + drupal_goto('lab-migration/code-approval'); + } diff --git a/dependency.inc b/dependency.inc new file mode 100755 index 0000000..a507218 --- /dev/null +++ b/dependency.inc @@ -0,0 +1,195 @@ + "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') + ); + $form['existing_depfile'] = array( + '#type' => 'item', + '#value' => _list_existing_dependency($proposal_data->id), + '#title' => t('List of existing dependency files for this book') + ); + $form['depfile'] = array( + '#type' => 'fieldset', + '#title' => t('Upload Dependency Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['depfile']['depfile1'] = array( + '#type' => 'file', + '#title' => t('Upload dependency file'), + '#description' => t("Allowed file extensions : ") . variable_get('lab_migration_dependency_extensions', '') + ); + $form['depfile']['depfile1_caption'] = array( + '#type' => 'textfield', + '#title' => t('Caption for dependency file'), + '#size' => 15, + '#maxlength' => 100, + '#required' => TRUE + ); + $form['depfile']['depfile1_description'] = array( + '#type' => 'textarea', + '#title' => t('Brief Description of the dependency file') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Back'), 'lab_migration/code') + ); + return $form; + } +function lab_migration_upload_dependency_form_validate($form, &$form_state) + { + global $user; + /* get approved proposal details */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE uid = %d OR solution_provider_uid = %d ORDER BY id DESC LIMIT 1", $user->uid, $user->uid); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $or = db_or(); + $or->condition('uid', $user->uid); + $or->condition('solution_provider_uid', $user->uid); + $query->condition($or); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + form_set_error('', t('Invalid1')); + } + if (!lab_migration_check_name($form_state['values']['depfile1_caption'])) + form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.')); + if (isset($_FILES['files'])) + { + /* check for valid filename extensions */ + $allowed_extensions = explode(',', variable_get('lab_migration_dependency_extensions', '')); + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + $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 ' . variable_get('lab_migration_dependency_extensions', '') . ' 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 file already exists */ + //$dep_exists_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE filename = '%s'", $_FILES['files']['name'][$file_form_name]))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('filename', $_FILES['files']['name'][$file_form_name]); + $dep_exists_data = $query->execute(); + if ($dep_exists_data) + form_set_error($file_form_name, t('Dependency file with the same name has already been uploaded in this or some other lab solution. Please rename the file and try again.')); + /* 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, numbers and underscore is allowed as a valid filename.')); + } + } + } + } +function lab_migration_upload_dependency_form_submit($form, &$form_state) + { + global $user; + $root_path = lab_migration_path(); + $proposal_data = lab_migration_get_proposal(); + if (!$proposal_data) + { + drupal_goto(''); + return; + } + $dest_path .= 'DEPENDENCIES' . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + /* uploading dependencies */ + $file_upload_counter = 0; + $dependency_ids = array(); + $dependency_names = array(); + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* 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 */ + $query = "INSERT INTO {lab_migration_dependency_files} (proposal_id, filename, filepath, filemime, filesize, caption, description, timestamp) + VALUES (:proposal_id, :filename, :filepath, :filemime, :filesize, :caption, :description, :timestamp)"; + $args = array( + ":proposal_id" => $proposal_data->id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => $_FILES['files']['type'][$file_form_name], + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":caption" => check_plain($form_state['values'][$file_form_name . '_caption']), + ":description" => check_plain($form_state['values'][$file_form_name . '_description']), + ":timestamp" => time() + ); + $dependency_ids[] = db_query($query, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + $dependency_names[] = $_FILES['files']['name'][$file_form_name]; + $file_upload_counter++; + } + else + { + drupal_set_message('Error uploading dependency : ' . $dest_path . $_FILES['files']['name'][$file_form_name], 'error'); + } + } + } + if ($file_upload_counter > 0) + { + drupal_set_message('Dependencies uploaded successfully.', 'status'); + /* sending email */ + $param['dependency_uploaded']['user_id'] = $user->uid; + $param['dependency_uploaded']['dependency_names'] = $dependency_names; + $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + if (!drupal_mail('lab_migration', 'dependency_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/upload-dep'); + } +function _list_existing_dependency($proposal_id) + { + $return_html = ''; + return $return_html; + } diff --git a/dependency_approval.inc b/dependency_approval.inc new file mode 100755 index 0000000..625761c --- /dev/null +++ b/dependency_approval.inc @@ -0,0 +1,156 @@ + 'fieldset', + '#title' => t('Bulk Manage Code'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#prefix' => '
', + '#suffix' => '
', + '#tree' => TRUE + ); + $form['wrapper']['dependency'] = array( + '#type' => 'select', + '#title' => t('Dependency'), + '#options' => _list_of_dependencies(), + '#default_value' => $dependency_default_value, + '#tree' => TRUE, + '#attributes' => array( + 'id' => 'dependancy' + ) + ); + $form["wrapper"]['dependencyfiles'] = array( + '#markup' => '
' + ); + $form['wrapper']['delete_dependency'] = array( + '#type' => 'checkbox', + "#description" => 'Please unlink the dependency from the above solutions before deleting it', + '#title' => t('Delete Dependency'), + '#prefix' => '
', + '#attributes' => array( + 'id' => 'delete-dependancy' + ) + ); + $form['wrapper']['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#suffix' => '
' + ); + return $form; + } +function lab_migration_dependency_approval_ajax($item = "", $key = "") + { + $data = ""; + $dependency_default_value = $key; + $solution_list = array(); + //$solution_id_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE dependency_id = %d", $dependency_default_value); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('dependency_id', $dependency_default_value); + $solution_id_q = $query->execute(); + while ($solution_id_data = $solution_id_q->fetchObject()) + { + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id_data->solution_id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id_data->solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + //$lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $experiment_data->proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + $solution_list[] = array( + $solution_data->code_number, + $experiment_data->number . ' . ' . $experiment_data->title, + $lab_data->lab_title + ); + } + $solution_list_header = array( + 'Code', + 'Experiment', + 'Lab' + ); + //$solution = theme_table($solution_list_header, $solution_list); + $solution = theme('table', array( + 'header' => $solution_list_header, + 'rows' => $solution_list + )); + $data .= $solution; + echo $data; + } +function lab_migration_dependency_approval_form_submit($form, &$form_state) + { + global $user; + $root_path = lab_migration_path(); + if ($form_state['clicked_button']['#value'] == 'Submit') + { + if (user_access('bulk manage code')) + { + if ($form_state['values']['delete_dependency'] == "1") + { + //$solution_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE dependency_id = %d", $form_state['values']['wrapper']['dependency']); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('dependency_id', $form_state['values']['dependency']); + $solution_q = $query->execute(); + if ($solution_data = $solution_q->fetchObject()) + { + drupal_set_message('Cannot delete dependency since it is linked with some solutions', 'error'); + } + else + { + if (lab_migration_delete_dependency($form_state['values']['dependency'])) + { + drupal_set_message('Dependency deleted', 'status'); + /* email */ + $email_subject = t('Dependency deleted'); + $email_body = t('Dependency deleted : .') . $form_state['values']['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'); + } + } + } + } + } + } +function _list_of_dependencies() + { + $dependencies = array( + '0' => 'Please select...' + ); + //$dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} ORDER BY filename ASC"); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->orderBy('filename', 'ASC'); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + $dependencies[$dependency_data->id] = $dependency_data->filename . ' (' . $dependency_data->filepath . ')'; + } + return $dependencies; + } diff --git a/download.inc b/download.inc new file mode 100755 index 0000000..dcd5608 --- /dev/null +++ b/download.inc @@ -0,0 +1,281 @@ + $solution_file_id)); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('id', $solution_file_id); + $query->range(0, 1); + $solution_files_q = $query->execute();*/ + $solution_file_data = $solution_files_q->fetchObject(); + header('Content-Type: ' . $solution_file_data->filemime); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($solution_file_data->filename)) . '"'); + header('Content-Length: ' . filesize($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath)); + readfile($root_path . $solution_file_data->directory_name . '/' . $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); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_file_id); + $query->range(0, 1); + $dependency_files_q = $query->execute(); + $dependency_file_data = $dependency_files_q->fetchObject(); + header('Content-Type: ' . $dependency_file_data->filemime); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_id); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_id); + $solution_files_q = $query->execute();*/ + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_id)); + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_id); + $solution_dependency_files_q = $query->execute(); + $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 = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + } + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($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)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } + else + { + drupal_set_message("There are no files in this solutions to download", 'error'); + drupal_goto('lab-migration/lab-migration-run'); + } + } +function lab_migration_download_experiment() + { + $experiment_id = (int)arg(3); + + $root_path = lab_migration_path(); + /* get solution data */ + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.solution_id = :solution_id", array(':solution_id' => $solution_row->id)); + /* $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + // $solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name .'/'. $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + } + /* dependency files */ + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($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)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } + else + { + drupal_set_message("There are no solutions in this experiment to download", 'error'); + drupal_goto('lab-migration/lab-migration-run'); + } + } +function lab_migration_download_lab() + { + global $user; + $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); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $lab_id); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + $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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $lab_id); + $experiment_q = $query->execute(); + while ($experiment_row = $experiment_q->fetchObject()) + { + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_row->id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id)); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename))); + //var_dump($zip->numFiles); + } + // die; + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + if ($dependency_file_data) + $zip->addFile($root_path . $dependency_file_data->filepath, $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . str_replace(' ', '_', ($dependency_file_data->filename))); + } + } + } + $zip_file_count = $zip->numFiles; + $zip->close(); + if ($zip_file_count > 0) + { + if ($user->uid) + { + /* download zip file */ + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $lab_data->lab_title) . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + ob_clean(); + //flush(); + readfile($zip_filename); + unlink($zip_filename); + } + else + { + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $lab_data->lab_title) . '.zip"'); + header('Content-Length: ' . filesize($zip_filename)); + header("Content-Transfer-Encoding: binary"); + header('Expires: 0'); + header('Pragma: no-cache'); + ob_end_flush(); + ob_clean(); + flush(); + readfile($zip_filename); + unlink($zip_filename); + } + } + else + { + drupal_set_message("There are no solutions in this Lab to download", 'error'); + drupal_goto('lab-migration/lab-migration-run'); + } + } diff --git a/email.inc b/email.inc new file mode 100755 index 0000000..1d59122 --- /dev/null +++ b/email.inc @@ -0,0 +1,758 @@ +fields('lab_migration_proposal'); + $query->condition('id', $params['solution_proposal_approved']['proposal_id']); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + // $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", $params['solution_proposal_approved']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['solution_proposal_approved']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['solution_proposal_approved']['user_id']); + $message['headers'] = $params['solution_proposal_approved']['headers']; + $message['subject'] = t('[!site_name] Lab Migration Solution Proposal Approval', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 0 => t(' +Dear !user_name, + +Your following Lab migration solution proposal has been approved: + +Full Name : ' . $proposal_data->solution_provider_name_title . ' ' . $proposal_data->solution_provider_name . ' +Email : ' . $user_data->mail . ' +Contact No. : ' . $proposal_data->solution_provider_contact_ph . ' +Department/Branch : ' . $proposal_data->solution_provider_department . ' +University/Institute : ' . $proposal_data->solution_provider_university . ' +City : ' . $proposal_data->solution_provider_city . ' +State : ' . $proposal_data->solution_provider_state . ' + +List of experiments : ' . $experiment_list . ' + +Please ensure that ALL the codes follow guidelines at https://r.fossee.in/lab-migration/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_proposal_disapproved': + $user_data = user_load($params['solution_proposal_disapproved']['user_id']); + $proposal_id = $params['solution_proposal_disapproved']['proposal_id']; + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $message['headers'] = $params['solution_proposal_disapproved']['headers']; + $message['subject'] = t('[!site_name] Lab Migration Solution Disapproval', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +We regret to inform you that your Lab migration solution proposal has been disapproved. + +Title of Lab :' . $proposal_data->lab_title . ' + +List of experiments : ' . $experiment_list . ' + +Reason: ' . $params['solution_proposal_disapproved']['message'] . ' + +You are welcome to submit a new proposal. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'proposal_received': + /* initializing data */ + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']); + // $proposal_data = $proposal_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $params['proposal_received']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + /* $samplecodefilename = ""; + if (strlen($proposal_data->samplefilepath) >= 5) + { + $samplecodefilename = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1); + } + else + { + $samplecodefilename = "Not provided"; + }*/ + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider_user = 'Open'; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider_user = 'Proposer'; + } + else + { + $solution_provider_user = 'Unknown'; + } + // $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", + // $params['proposal_received']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['proposal_received']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['proposal_received']['user_id']); + $message['headers'] = $params['proposal_received']['headers']; + $message['subject'] = t('[!site_name] Your Lab migration proposal has been received', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +We have received your Lab migration proposal with the following details: + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->name . ' +Email : ' . $user_data->mail . ' +Contact No. : ' . $proposal_data->contact_ph . ' +Department/Branch : ' . $proposal_data->department . ' +University/Institute : ' . $proposal_data->university . ' +City : ' . $proposal_data->city . ' +State : ' . $proposal_data->state . ' + + +Solution Provided By : ' . $solution_provider_user . ' + +List of experiments : ' . $experiment_list . ' + +Your proposal is under review. You will soon receive an email when same has been approved/disapproved. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'proposal_disapproved': + /* initializing data */ + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']); + //$proposal_data = $proposal_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $params['proposal_disapproved']['proposal_id']); + $query->range(0, 1); + $proposal_data = $query->execute()->fetchObject(); + $samplecodefilename = ""; + if (strlen($proposal_data->samplefilepath) >= 5) + { + $samplecodefilename = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1); + } + else + { + $samplecodefilename = "Not provided"; + } + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider_user = 'Open'; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider_user = 'Proposer'; + } + else + { + $solution_provider_user = 'Unknown'; + } + // $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", $params['proposal_disapproved']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['proposal_disapproved']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['proposal_disapproved']['user_id']); + $message['headers'] = $params['proposal_disapproved']['headers']; + $message['subject'] = t('[!site_name] Your Lab migration proposal has been disapproved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +We regret to inform you that all the Experiments of your Lab with following details have been dis-approved. + +Reason for disapproval: ' . $proposal_data->message . ' + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->name . ' +Email : ' . $user_data->mail . ' +Contact No. : ' . $proposal_data->contact_ph . ' +Department/Branch : ' . $proposal_data->department . ' +University/Institute : ' . $proposal_data->university . ' +City : ' . $proposal_data->city . ' +State : ' . $proposal_data->state . ' + +Solution Provided By : ' . $solution_provider_user . ' + +List of experiments : ' . $experiment_list . ' + +Uploaded Sample Code : ' . $samplecodefilename . ' + + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'proposal_approved': + /* initializing data */ + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $params['proposal_approved']['proposal_id']); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + /* $samplecodefilename = ""; + if (strlen($proposal_data->samplefilepath) >= 5) + { + $samplecodefilename = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1); + } + else + { + $samplecodefilename = "Not provided"; + }*/ + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider_user = 'Open'; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider_user = 'Proposer'; + } + else + { + $solution_provider_user = 'Unknown'; + } + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", $params['proposal_approved']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['proposal_approved']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['proposal_approved']['user_id']); + $message['headers'] = $params['proposal_approved']['headers']; + $message['subject'] = t('[!site_name] Your Lab migration proposal has been approved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 0 => t(' +Dear !user_name, + +Congratulations! Your Lab migration proposal with the below details has been approved: + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->name . ' +Email : ' . $user_data->mail . ' +Contact No. : ' . $proposal_data->contact_ph . ' +Department/Branch : ' . $proposal_data->department . ' +University/Institute : ' . $proposal_data->university . ' +City : ' . $proposal_data->city . ' +State : ' . $proposal_data->state . ' + + +Solution Provided By : ' . $solution_provider_user . ' + +List of experiments : ' . $experiment_list . ' + +Please ensure that ALL the guidelines for coding are strictly followed: +https://r.fossee.in/lab-migration-project/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'proposal_completed': + /* initializing data */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $params['proposal_completed']['proposal_id']); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider_user = 'Open'; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider_user = 'Proposer'; + } + else + { + $user_data = user_load($proposal_data->solution_provider_uid); + if (!$user_data) + { + $solution_provider_user = 'Unknown'; + } + } + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", $params['proposal_completed']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['proposal_completed']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['proposal_completed']['user_id']); + $message['headers'] = $params['proposal_completed']['headers']; + $message['subject'] = t('[!site_name] Congratulations for completion of the Lab migration', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Following Lab migration has been completed sucessfully : + +Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->name . ' +Email : ' . $user_data->mail . ' +Contact No. : ' . $proposal_data->contact_ph . ' +Department/Branch : ' . $proposal_data->department . ' +University/Institute : ' . $proposal_data->university . ' +City : ' . $proposal_data->city . ' +State : ' . $proposal_data->state . ' + + +Solution Provided By : ' . $solution_provider_user . ' + +List of experiments : ' . $experiment_list . ' + +Your Lab solution is now available at following link to download. + +https://r.fossee.in/lab-migration/lab-migration-run/' . $proposal_data->id . ' + +Now you should be able to propose a new Lab migration. + +Please ensure that ALL the codes follow guidelines at https://r.fossee.in/lab-migration-project/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_proposal_received': + /* initializing data */ + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['solution_proposal_received']['proposal_id']); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $params['solution_proposal_received']['proposal_id']); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if ($proposal_data->solution_display == 1) + { + $solution_display = 'Yes'; + } + else + { + $solution_display = 'No'; + } + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number", $params['solution_proposal_received']['proposal_id'], 1); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $params['solution_proposal_received']['proposal_id']); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + $experiment_list = ' + '; + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_list .= '

' . $experiment_data->number . ') ' . $experiment_data->title . '
Description : ' . $experiment_data->description . '
'; + $experiment_list .= ' '; + $experiment_list .= '

'; + } + $user_data = user_load($params['solution_proposal_received']['user_id']); + $message['headers'] = $params['solution_proposal_received']['headers']; + $message['subject'] = t('[!site_name] Your Lab migration solution proposal has been received', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +We have received your proposal for providing solution for lab migration with the following details: + +List of experiments : ' . $experiment_list . ' + +Full Name : ' . $proposal_data->solution_provider_name_title . ' ' . $proposal_data->solution_provider_name . ' +Email : ' . $user->mail . ' +Contact No. : ' . $proposal_data->solution_provider_contact_ph . ' +Department/Branch : ' . $proposal_data->department . ' +University/Institute : ' . $proposal_data->solution_provider_university . ' + + +Your proposal is under review. You will soon receive an email when the same has been approved / disapproved. + +Please ensure that ALL the codes follow guidelines at https://r.fossee.in/lab-migration-project/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_uploaded': + // $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d LIMIT 1", $params['solution_uploaded']['solution_id']); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $params['solution_uploaded']['solution_id']); + $query->range(0, 1); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $user_data = user_load($params['solution_uploaded']['user_id']); + $message['subject'] = t('[!site_name] You have uploaded Lab migration solution', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['headers'] = $params['solution_uploaded']['headers']; + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have uploaded the following solution: + +Experiment Title : ' . $experiment_data->title . ' + +Solution number : ' . $solution_data->code_number . ' +Caption : ' . $solution_data->caption . ' + +The solution is under review. You will be notified when it has been approved. + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_approved': + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d LIMIT 1", $params['solution_approved']['solution_id']); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $params['solution_approved']['solution_id']); + $query->range(0, 1); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $user_data = user_load($params['solution_approved']['user_id']); + $message['headers'] = $params['solution_approved']['headers']; + $message['subject'] = t('[!site_name] Your uploaded Lab migration solution has been approved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following solution has been approved: + +Experiment Title : ' . $experiment_data->title . ' + +Solution number : ' . $solution_data->code_number . ' +Caption : ' . $solution_data->caption . ' + +Please ensure that ALL the codes follow guidelines at https://r.fossee.in/lab-migration-project/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_disapproved': + $user_data = user_load($params['solution_disapproved']['user_id']); + $message['headers'] = $params['solution_disapproved']['headers']; + $message['subject'] = t('[!site_name] Your uploaded Lab migration solution has been disapproved', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following solution has been disapproved: + +Solution number : ' . $params['solution_disapproved']['solution_number'] . ' +Caption : ' . $params['solution_disapproved']['solution_caption'] . ' + +Reason for dis-approval : ' . $params['solution_disapproved']['message'] . ' + + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'solution_deleted_user': + $user_data = user_load($params['solution_deleted_user']['user_id']); + $message['headers'] = $params['solution_deleted_user']['headers']; + $message['subject'] = t('[!site_name] User has deleted pending Lab migration solution', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your following pending solution has been deleted : + +Title of the Lab : ' . $params['solution_deleted_user']['lab_title'] . ' +Title of the Experiment : ' . $params['solution_deleted_user']['experiment_title'] . ' + +Solution number : ' . $params['solution_deleted_user']['solution_number'] . ' +Caption : ' . $params['solution_deleted_user']['solution_caption'] . ' + + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'dependency_uploaded': + $user_data = user_load($params['dependency_uploaded']['user_id']); + $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); + $message['headers'] = $params['dependency_uploaded']['headers']; + $message['subject'] = t('[!site_name] You have uploaded dependency file', array( + '!site_name' => variable_get('site_name', '') + ), array( + 'language' => $language->language + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +You have uploaded following dependency files : + ' . $dependency_files . ' + +Please ensure that ALL the codes follow guidelines at https://r.fossee.in/lab-migration-project/lab-migration-guidelines + +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + ), array( + 'language' => $language->language + )) + ); + break; + case 'standard': + $message['subject'] = $params['standard']['subject']; + $message['body'] = $params['standard']['body']; + $message['headers'] = $params['standard']['headers']; + break; + } + } diff --git a/full_download.inc b/full_download.inc new file mode 100755 index 0000000..a8e7173 --- /dev/null +++ b/full_download.inc @@ -0,0 +1,241 @@ +fields('lab_migration_experiment'); + $query->condition('id', $experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id)); + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name. '/' . $solution_files_row->filepath, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + // $dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + 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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('approval_status', 0); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id)); + + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + // $dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + 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); + var_dump($lab_id); + //die; + $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); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $lab_id); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + $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); + /* approved solutions */ + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $lab_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $lab_id); + $experiment_q = $query->execute(); + while ($experiment_row = $experiment_q->fetchObject()) + { + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_row->id); + $query->condition('approval_status', 1); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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); + /*$query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id)); + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path . $solution_files_row->directory_name. '/' . $solution_files_row->filepath, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + 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_row->id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_row->id); + $query->condition('approval_status', 0); + $solution_q = $query->execute(); + while ($solution_row = $solution_q->fetchObject()) + { + $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); + /* $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_row->id); + $solution_files_q = $query->execute();*/ + $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id)); + + //$solution_dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_row->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_row->id); + $solution_dependency_files_q = $query->execute(); + while ($solution_files_row = $solution_files_q->fetchObject()) + { + $zip->addFile($root_path .$solution_files_row->directory_name . '/' . $solution_files_row->filepath, $LAB_PATH . $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename); + } + /* dependency files */ + while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject()) + { + //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject(); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $solution_dependency_files_row->dependency_id); + $query->range(0, 1); + $dependency_file_data = $query->execute()->fetchObject(); + 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 */ + ob_clean(); + //flush(); + 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/general_deletion.inc b/general_deletion.inc new file mode 100755 index 0000000..fcddeea --- /dev/null +++ b/general_deletion.inc @@ -0,0 +1,241 @@ +fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution.'), 'error'); + return FALSE; + } + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message(t('Invalid experiment.'), 'error'); + return FALSE; + } + /* deleting solution files */ + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_id); + $solution_files_q = $query->execute(); + while ($solution_files_data = $solution_files_q->fetchObject()) + { + $ex_path = $proposal_data->directory_name . '/' . $solution_files_data->filepath; + $dir_path = $root_path . $ex_path; + if (!file_exists($dir_path)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $dir_path)), 'error'); + continue; + } + /* removing solution file */ + if (!unlink($dir_path)) + { + $status = FALSE; + drupal_set_message(t('Error deleting !file', array('!file' => $dir_path)), 'error'); + + /* sending email to admins */ + $email_to = variable_get('lab_migration_emails', ''); + $from = variable_get('lab_migration_from_email', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); + $param['standard']['subject'] = "[ERROR] Error deleting example file"; + $param['standard']['body'] = "Error deleting solution files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : + solution id : " . $solution_id . " + file id : " . $solution_files_data->id . " + file path : " . $solution_files_data->filepath." + PDF path : " . $PdfStatus; + $param['standard']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } + else { + /* deleting example files database entries */ + db_delete('lab_migration_solution_files')->condition('id', $solution_files_data->id)->execute(); + } + } + + if (!$status) + return FALSE; + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message(t('Invalid solution.'), 'error'); + return FALSE; + } + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + $dir_path = $root_path . $proposal_data->directory_name . '/EXP' . $experiment_data->number . '/CODE' . $solution_data->code_number; + if (is_dir($dir_path)) + { + if (!rmdir($dir_path)) + { + drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error'); + + /* sending email to admins */ + $email_to = variable_get('lab_migration_emails', ''); + $from = variable_get('lab_migration_from_email', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); + + + $param['standard']['subject'] = "[ERROR] Error deleting folder"; + $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $param['standard']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + return FALSE; + } + } + else + { + drupal_set_message(t('Cannot delete solution folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); + return FALSE; + } + + /* deleting solution dependency and solution database entries */ + db_delete('lab_migration_solution_dependency')->condition('solution_id', $solution_id)->execute(); + db_delete('lab_migration_solution')->condition('id', $solution_id)->execute(); + return $status; +} + +function lab_migration_delete_experiment($experiment_id) +{ + $status = TRUE; + $root_path = lab_migration_path(); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $experiment_id); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message('Invalid experiment.', 'error'); + return FALSE; + } + /* deleting solutions */ + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $solution_q = $query->execute(); + $delete_exp_folder = FALSE; + while ($solution_data = $solution_q->fetchObject()) + { + $delete_exp_folder = TRUE; + if (!lab_migration_delete_solution($solution_data->id)) + $status = FALSE; + } + if (!$delete_exp_folder) + { + return TRUE; + } + if ($status) + { + $dir_path = $root_path . $proposal_data->directory_name . '/EXP' . $experiment_data->number; + if (is_dir($dir_path)) + { + $res = rmdir($dir_path); + if (!$res) + { + drupal_set_message(t('Error deleting experiment folder !folder', array('!folder' => $dir_path)), 'error'); + /* sending email to admins */ + $email_to = variable_get('lab_migration_emails', ''); + $from = variable_get('lab_migration_from_email', ''); + $bcc=""; + $cc=variable_get('lab_migration_cc_emails', ''); + $param['standard']['subject'] = "[ERROR] Error deleting experiment folder"; + $param['standard']['body'] = "Error deleting folder " . $dir_path; + $param['standard']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param,$from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + return FALSE; + } + else + { + return TRUE; + } + } + else { + drupal_set_message(t('Cannot delete experiment folder. !folder does not exists.', array('!folder' => $dir_path)), 'error'); + return FALSE; + } + } + return FALSE; +} + +function lab_migration_delete_lab($lab_id) +{ + $status = TRUE; + $root_path = lab_migration_path(); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $lab_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('Invalid Lab.', 'error'); + return FALSE; + } + /* delete experiments */ + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + if (!lab_migration_delete_experiment($experiment_data->id)) + { + $status = FALSE; + } + } + return $status; +} diff --git a/lab_details.inc b/lab_details.inc new file mode 100755 index 0000000..b847f98 --- /dev/null +++ b/lab_details.inc @@ -0,0 +1,69 @@ +fields('lab_migration_proposal'); + $query->condition('approval_status', 3); + $result = $query->execute(); + //$result = db_query($query); + if ($result->rowCount() == 0) + { + $output .= "We will in process to update lab migration data"; + } + else + { + $preference_rows = array(); + $i = 1; + while ($row = $result->fetchObject()) + { + $approval_date = date("Y", $row->approval_date); + $preference_rows[] = array( + $i, + $row->university, + l($row->lab_title, "lab-migration/lab-migration-run/" . $row->id), + $approval_date + ); + $i++; + } + $preference_header = array( + 'No', + 'Institute', + 'Lab', + 'Year' + ); + $output .= theme('table', array( + 'header' => $preference_header, + 'rows' => $preference_rows + )); + } + return $output; + } +function lab_migration_labs_progress_all() + { + $page_content = ""; + //$query = "SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 and solution_status = 2"; + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('approval_status', 1); + $query->condition('solution_status', 2); + $result = $query->execute(); + if ($result->rowCount() == 0) + { + $page_content .= "We will in process to update lab migration data"; + } + else + { + //$result = db_query($query); + $page_content .= "
    "; + while ($row = $result->fetchObject()) + { + $page_content .= "
  1. "; + $page_content .= $row->university . " ({$row->lab_title})"; + $page_content .= "
  2. "; + } + $page_content .= "
"; + } + return $page_content; + } diff --git a/lab_migration.info b/lab_migration.info new file mode 100755 index 0000000..431f488 --- /dev/null +++ b/lab_migration.info @@ -0,0 +1,7 @@ +name = "Lab Migration" +description = "IIT Bombay Lab Migration project" +package = IITB +version = "7.x-1.3" +core = "7.x" + +;scripts[] = js/jquery-1.4.1.min.js diff --git a/lab_migration.install b/lab_migration.install new file mode 100755 index 0000000..5045632 --- /dev/null +++ b/lab_migration.install @@ -0,0 +1,435 @@ + 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 + ), + 'expected_completion_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 + ), + 'solution_provider_name_title' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '5', + 'not null' => TRUE + ), + 'solution_provider_name' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'solution_provider_contact_ph' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '15', + 'not null' => TRUE + ), + 'solution_provider_department' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + 'not null' => TRUE + ), + 'solution_provider_university' => array( + 'description' => t('TODO: please describe this field!'), + 'type' => 'varchar', + 'length' => '255', + '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' + ) + ); + /* 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' + ) + ); + /* 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' + ) + ); + /* 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' + ) + ); + /* 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' + ) + ); + /* 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' + ) + ); + return $schema; + } diff --git a/lab_migration.module b/lab_migration.module new file mode 100755 index 0000000..d50b896 --- /dev/null +++ b/lab_migration.module @@ -0,0 +1,764 @@ + 'Lab Migration Proposal', + 'description' => 'Lab Migration Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_proposal_form' + ), + 'access arguments' => array( + 'lab migration create proposal' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'proposal.inc' + ); + $items['lab-migration/manage-proposal'] = array( + 'title' => 'LM Manage Lab Proposals', + 'description' => 'Manage Lab Migration Proposals', + 'page callback' => 'lab_migration_proposal_pending', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/pending'] = array( + 'title' => 'Pending Proposals', + 'description' => 'Pending Lab Migration Proposals Queue', + 'page callback' => 'lab_migration_proposal_pending', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 1, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/pending-solution-proposal'] = array( + 'title' => 'Pending Solution Proposals', + 'description' => 'Pending Lab Migration Solution Proposals Queue', + 'page callback' => 'lab_migration_solution_proposal_pending', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'manage_solution_proposal.inc' + ); + $items['lab-migration/manage-proposal/pending-solution'] = array( + 'title' => 'Pending Solution', + 'description' => 'Pending Lab Migration Solution', + 'page callback' => 'lab_migration_proposal_pending_solution', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/all'] = array( + 'title' => 'All Proposals', + 'description' => 'All Proposals', + 'page callback' => 'lab_migration_proposal_all', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 4, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/category'] = array( + 'title' => 'Category', + 'description' => 'Category', + 'page callback' => 'lab_migration_category_all', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 5, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/category/edit'] = array( + 'title' => 'Edit Category', + 'description' => 'Edit category', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_category_edit_form' + ), + 'access arguments' => array( + 'lab migration edit proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/approve'] = array( + 'title' => 'Approve Proposal', + 'description' => 'Approve Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_proposal_approval_form' + ), + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/solution-proposal-approve'] = array( + 'title' => 'Approve Solution Proposal', + 'description' => 'Approve Solution Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_solution_proposal_approval_form' + ), + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_solution_proposal.inc' + ); + $items['lab-migration/manage-proposal/edit'] = array( + 'title' => 'Edit Proposal', + 'description' => 'Edit Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_proposal_edit_form' + ), + 'access arguments' => array( + 'lab migration manage proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + $items['lab-migration/manage-proposal/status'] = array( + 'title' => 'Proposal Status', + 'description' => 'Proposal Status', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_proposal_status_form' + ), + 'access arguments' => array( + 'lab migration approve proposal' + ), + 'type' => MENU_CALLBACK, + 'file' => 'manage_proposal.inc' + ); + /* SOLUTION PROPOSAL */ + $items['lab-migration/open-proposal'] = array( + 'title' => 'Lab Migration Solve', + 'description' => 'Lab Migration Proposal Open For Solution', + 'page callback' => 'lab_migration_proposal_open', + 'access arguments' => array( + 'lab migration propose solution' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'solution_proposal.inc' + ); + $items['lab-migration/show-proposal'] = array( + 'title' => 'Lab Migration Solution Proposal', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_solution_proposal_form' + ), + 'access arguments' => array( + 'lab migration propose solution' + ), + 'type' => MENU_CALLBACK, + 'file' => 'solution_proposal.inc' + ); + /* CODE REVIEW */ + $items['lab-migration/code-approval'] = array( + 'title' => 'LM Manage Code Approval', + 'description' => 'Manage Code Approval', + 'page callback' => 'lab_migration_code_approval', + 'access arguments' => array( + 'lab migration approve code' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'code_approval.inc' + ); + $items['lab-migration/code-approval/approve'] = array( + 'title' => 'Code Approval', + 'description' => 'Code Approval', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_code_approval_form' + ), + 'access arguments' => array( + 'lab migration approve code' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 1, + 'file' => 'code_approval.inc' + ); + $items['lab-migration/code-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_bulk_approval_form' + ), + 'access arguments' => array( + 'lab migration bulk manage code' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'bulk_approval.inc' + ); + $items['lab-migration/code-approval/bulk'] = array( + 'title' => 'Bulk Manage', + 'description' => 'Bulk Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_bulk_approval_form' + ), + 'access arguments' => array( + 'lab migration bulk manage code' + ), + 'type' => MENU_LOCAL_TASK, + 'weight' => 2, + 'file' => 'bulk_approval.inc' + ); + /*$items['lab_migration/code_approval/dependency'] = array( + 'title' => 'Dependency', + 'description' => 'Dependency Mangage', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('lab_migration_dependency_approval_form'), + 'access arguments' => array('lab migration bulk manage code'), + 'type' => MENU_LOCAL_TASK, + 'weight' => 3, + 'file' => 'dependency_approval.inc', + );*/ + $items['lab-migration/code-approval/upload'] = array( + 'title' => 'Upload Code', + 'description' => 'Admin Upload', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_bulk_upload_code_form' + ), + 'access arguments' => array( + 'lab migration bulk manage code' + ), + 'type' => MENU_CALLBACK, + 'weight' => 4, + 'file' => 'bulk_upload_code.inc' + ); + $items['lab-migration/code-approval/notes'] = array( + 'title' => 'Notes for Reviewers', + 'description' => 'Notes for Reviewers', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_lab_notes_form' + ), + 'access arguments' => array( + 'lab migration bulk manage code' + ), + 'type' => MENU_CALLBACK, + 'weight' => 4, + 'file' => 'notes.inc' + ); + /* CODE UPLOAD */ + $items['lab-migration/code'] = array( + 'title' => 'Code Submission', + 'description' => 'Code Submission', + 'page callback' => 'lab_migration_list_experiments', + 'access callback' => 'user_access', + 'access arguments' => array( + 'lab migration upload code' + ), + 'file' => 'upload_code.inc' + ); + $items['lab-migration/code/list-experiments'] = array( + 'title' => 'List Experiments', + 'description' => 'List Experiments', + 'page callback' => 'lab_migration_list_experiments', + 'access arguments' => array( + 'lab migration upload code' + ), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'file' => 'upload_code.inc', + 'weight' => 1 + ); + $items['lab-migration/code/upload'] = array( + 'title' => 'Code Submission', + 'description' => 'Code Submission', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_upload_code_form' + ), + 'access arguments' => array( + 'lab migration upload code' + ), + 'type' => MENU_LOCAL_TASK, + 'file' => 'upload_code.inc', + 'weight' => 2 + ); + /* $items['lab_migration/code/upload_dep'] = array( + 'title' => 'Upload Dependency', + 'description' => 'Upload Dependency Files', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('lab_migration_upload_dependency_form'), + 'access arguments' => array('lab migration upload code'), + 'type' => MENU_LOCAL_TASK, + 'file' => 'dependency.inc', + 'weight' => 3, + );*/ + $items['lab-migration/code/delete'] = array( + 'title' => 'Delete Solution', + 'description' => 'Delete Solution', + 'page callback' => 'lab_migration_upload_code_delete', + 'access arguments' => array( + 'lab migration upload code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'upload_code_delete.inc' + ); + /* CODE DOWNLOADS */ + $items['lab-migration/download/file'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_solution_file', + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + /*$items['lab_migration/download/dependency'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_dependency_file', + 'access arguments' => array('lab migration download code'), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc', + );*/ + $items['lab-migration/download/solution'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_solution', + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['lab-migration/download/experiment'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_experiment', + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc' + ); + $items['lab-migration/download/lab'] = array( + 'title' => 'Code Download', + 'description' => 'Code Download', + 'page callback' => 'lab_migration_download_lab', + 'access arguments' => array( + 'lab migration download code' + ), + '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( + 'lab migration 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( + 'lab migration approve code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'full_download.inc' + ); + /* COMPLETED LAB MIGRATIONS */ + $items['lab-migration/completed-labs'] = array( + 'title' => 'Completed Labs', + 'page callback' => 'lab_migration_completed_labs_all', + 'access arguments' => array( + 'lab migration download code' + ), + 'file' => 'lab_details.inc' + ); + /* LABS IN PROGRESS */ + $items['lab-migration/labs-progress'] = array( + 'title' => 'Labs in Progress', + 'page callback' => 'lab_migration_labs_progress_all', + 'access arguments' => array( + 'lab migration download code' + ), + 'file' => 'lab_details.inc' + ); + /* DOWNLOAD FOR EVERYONE */ + $items['lab-migration/lab-migration-run'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_run_form' + ), + 'access arguments' => array( + 'lab migration download code' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'run.inc' + ); + /*$items['lab_migration_run'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('lab_migration_run_form_ajax'), + 'access arguments' => array('access content'), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'run.inc', + ); + $items['lab_migration_run_ajax'] = array( + 'page callback' => 'lab_migration_run_ajax', + 'access callback' => TRUE, + 'file' => 'run.inc', + ); + $items['download_codes'] = array( + 'title' => 'Download Codes', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('lab_migration_run_form_ajax'), + 'access arguments' => array('access content'), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'run.inc', + );*/ + /* LATEX SCRIPT */ + $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( + 'lab migration generate lab' + ), + '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( + 'lab migration approve code' + ), + 'type' => MENU_CALLBACK, + 'file' => 'latex.inc' + ); + /* ADMIN SETTINGS */ + $items['admin/settings/lab-migration'] = array( + 'title' => 'Lab Migration Settings', + 'description' => 'Lab Migration Settings', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'lab_migration_settings_form' + ), + 'access arguments' => array( + 'administer lab migration' + ), + 'type' => MENU_NORMAL_ITEM, + 'file' => 'settings.inc' + ); + /* AJAX REQUEST */ + $items["lab-bulk-manage-exp/ajax"] = array( + "title" => "Ajax callbacks", + "page callback" => "lab_bulk_manage_exp_ajax", + "access arguments" => array( + "lab migration bulk manage code" + ), + "type" => MENU_CALLBACK, + 'file' => 'bulk_approval.inc' + ); + /* $items["lab_migration/code_approval/dependency/ajax"] = array( + "title" => "Ajax callbacks", + "page callback" => "lab_migration_dependency_approval_ajax", + "access arguments" => array("lab migration bulk manage code"), + "type" => MENU_CALLBACK, + 'file' => 'dependency_approval.inc', + );*/ + return $items; + } +/** + * Implementation of hook_perm(). + */ +function lab_migration_permission() + { + return array( + 'lab migration create proposal' => array( + 'title' => t('lab migration create proposal'), + 'restrict access' => TRUE + ), + 'lab migration manage proposal' => array( + 'title' => t('lab migration manage proposal'), + 'restrict access' => TRUE + ), + 'lab migration edit proposal' => array( + 'title' => t('lab migration edit proposal'), + 'restrict access' => TRUE + ), + 'lab migration approve proposal' => array( + 'title' => t('lab migration approve proposal'), + 'restrict access' => TRUE + ), + 'lab migration propose solution' => array( + 'title' => t('lab migration propose solution'), + 'restrict access' => TRUE + ), + 'lab migration approve code' => array( + 'title' => t('lab migration approve code'), + 'restrict access' => TRUE + ), + 'lab migration bulk manage code' => array( + 'title' => t('lab migration bulk manage code'), + 'restrict access' => TRUE + ), + 'lab migration bulk delete code' => array( + 'title' => t('lab migration bulk delete code'), + 'restrict access' => TRUE + ), + 'lab migration upload code' => array( + 'title' => t('lab migration upload code'), + 'restrict access' => TRUE + ), + 'lab migration download code' => array( + 'title' => t('lab migration download code'), + 'restrict access' => TRUE + ), + 'administer lab migration' => array( + 'title' => t('administer lab migration'), + 'restrict access' => TRUE + ), + 'lab migration generate lab' => array( + 'title' => t('lab migration generate lab'), + 'restrict access' => TRUE + ) + ); + // return array('lab migration create proposal', 'lab migration manage proposal', 'lab migration edit proposal', 'lab migration approve proposal', 'lab migration propose solution', 'lab migration approve code', 'lab migration bulk manage code', 'lab migration bulk delete code', 'lab migration upload code', 'lab migration download code', 'administer lab migration', 'lab migration generate lab'); + } +/* AJAX CALLS */ +function lab_migration_ajax() + { + $query_type = arg(2); + if ($query_type == 'chapter_title') + { + $chapter_number = arg(3); + $preference_id = arg(4); + //$chapter_q = db_query("SELECT * FROM {lab_migration_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id); + $query = db_select('lab_migration_chapter'); + $query->fields('lab_migration_chapter'); + $query->condition('number', $chapter_number); + $query->condition('preference_id', $preference_id); + $query->range(0, 1); + $chapter_q = $query->execute(); + if ($chapter_data = $chapter_q->fetchObject()) + { + echo $chapter_data->name; + return; + } + } + else if ($query_type == 'example_exists') + { + $chapter_number = arg(3); + $preference_id = arg(4); + $example_number = arg(5); + $chapter_id = 0; + $query = db_select('lab_migration_chapter'); + $query->fields('lab_migration_chapter'); + $query->condition('number', $chapter_number); + $query->condition('preference_id', $preference_id); + $query->range(0, 1); + $chapter_q = $query->execute(); + if (!$chapter_data = $chapter_q->fetchObject()) + { + echo ''; + return; + } + else + { + $chapter_id = $chapter_data->id; + } + $query = db_select('lab_migration_example'); + $query->fields('lab_migration_example'); + $query->condition('chapter_id', $chapter_id); + $query->condition('number', $example_number); + $query->range(0, 1); + $example_q = $query->execute(); + if ($example_data = $example_q->fetchObject()) + { + if ($example_data->approval_status == 1) + echo 'Warning! Solution already approved. You cannot upload the same solution again.'; + else + echo 'Warning! Solution already uploaded. Delete the solution and reupload it.'; + return; + } + } + echo ''; + } +/*************************** VALIDATION FUNCTIONS *****************************/ +function lab_migration_check_valid_filename($file_name) + { + if (!preg_match('/^[0-9a-zA-Z\.]+$/', $file_name)) + return FALSE; + else if (substr_count($file_name, ".") > 1) + return FALSE; + else + return TRUE; + } +function lab_migration_check_name($name = '') + { + if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) + return FALSE; + else + return TRUE; + } +function lab_migration_check_code_number($number = '') + { + if (!preg_match('/^[0-9]+$/', $number)) + return FALSE; + else + return TRUE; + } +function lab_migration_path() + { + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'r_uploads/lab_migration_uploads/'; + } +/************************* USER VERIFICATION FUNCTIONS ************************/ +function lab_migration_get_proposal() + { + global $user; + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = ".$user->uid." AND solution_status = 2 ORDER BY id DESC LIMIT 1"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_provider_uid', $user->uid); + $query->condition('solution_status', 2); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("You do not have any approved Lab migraion solution proposal. Please check the " . l('available', 'lab-migration/open-proposal') . " Lab migration proposal.", 'error'); + drupal_goto(''); + } + switch ($proposal_data->approval_status) + { + case 0: + drupal_set_message(t('Proposal is awaiting approval.'), 'status'); + return FALSE; + case 1: + return $proposal_data; + case 2: + drupal_set_message(t('Proposal has been dis-approved.'), 'error'); + return FALSE; + case 3: + drupal_set_message(t('Proposal has been marked as completed.'), 'status'); + return FALSE; + default: + drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error'); + return FALSE; + } + return FALSE; + } +/***************************** GENERAL FUNCTIONS ******************************/ +function lab_migration_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; + } +/*function lab_migration_init() { + +drupal_add_js(drupal_get_path('module', 'lab_migration') . '/js/lab_migration_ajax.js', array ('scope' => 'footer')); +}*/ +/*************************************************************************/ +/***** Function To convert only first charater of string in uppercase ****/ +/*************************************************************************/ +function lm_ucname($string) + { + $string = ucwords(strtolower($string)); + foreach (array( + '-', + '\'' + ) as $delimiter) + { + if (strpos($string, $delimiter) !== false) + { + $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string))); + } + } + return $string; + } + + + diff --git a/latex.inc b/latex.inc new file mode 100755 index 0000000..f630f36 --- /dev/null +++ b/latex.inc @@ -0,0 +1,274 @@ +fields('lab_migration_proposal'); + $query->condition('id', $lab_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + 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) + { + lab_migration_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 .= $proposal_data->solution_provider_name_title . $sep . $proposal_data->solution_provider_name . $sep . $proposal_data->solution_provider_department . $sep . $proposal_data->solution_provider_university . $eol; + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number DESC", $proposal_data->id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $query->orderBy('number', 'DESC'); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + if ($full_lab) + { + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY code_number DESC", $experiment_data->id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_data->id); + $query->orderBy('code_number', 'DESC'); + $solution_q = $query->execute(); + } + else + { + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1 ORDER BY code_number DESC", $experiment_data->id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_data->id); + $query->condition('approval_status', 1); + $query->orderBy('code_number', 'DESC'); + $solution_q = $query->execute(); + } + while ($solution_data = $solution_q->fetchObject()) + { + //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_data->id); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_data->id); + $solution_files_q = $query->execute(); + while ($solution_files_data = $solution_files_q->fetchObject()) + { + $latex_filedata .= $experiment_data->number . $sep; + $latex_filedata .= $experiment_data->title . $sep; + $latex_filedata .= $solution_data->code_number . $sep; + $latex_filedata .= $solution_data->caption . $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); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_data->id); + $dependency_files_q = $query->execute(); + while ($dependency_files_data = $dependency_files_q->fetchObject()) + { + //$dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $dependency_files_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_files_data->dependency_id); + $query->range(0, 1); + $dependency_q = $query->execute(); + if ($dependency_data = $dependency_q->fetchObject()) + { + if (substr($dependency_data->filename, -3) != "wav") + { + $latex_filedata .= $experiment_data->number . $sep; + $latex_filedata .= $experiment_data->title . $sep; + $latex_filedata .= $solution_data->code_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); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $row); + $query->range(0, 1); + $dependency_q = $query->execute(); + if ($dependency_data = $dependency_q->fetchObject()) + { + $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_title . '_' . $proposal_data->name_title . '_' . $proposal_data->name . '.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) + lab_migration_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("lab_migration_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); + lab_migration_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/latex/Initial_body b/latex/Initial_body new file mode 100755 index 0000000..53e82b4 --- /dev/null +++ b/latex/Initial_body @@ -0,0 +1,58 @@ +\nonstopmode +\documentclass[12pt]{report} +\usepackage{hyperref} +\hypersetup{colorlinks=true,linkcolor=blue} +\usepackage{theorem,graphicx} +\usepackage{listings,alltt} +\bibliographystyle{plain} + + +\lstset{ %configuring the display of scilab codes + tabsize=4, + language=scilab, + basicstyle=\ttfamily, + aboveskip={1\baselineskip}, + showstringspaces=false, + breaklines=true, + showspaces=false, + numbers=left, + numberstyle=\small, + stringstyle=\normalfont, + keywordstyle=\color{red}, + emph={clc, all, gca}, + emphstyle=\color{red}, + commentstyle=\color{blue}\normalfont} + + +% code environment +{\theorembodyfont{\rmfamily} \newtheorem{codemass}{Scilab code}[chapter]} +\newenvironment{code}% +{\begin{codemass}}{\hrule \end{codemass}} + +{\theorembodyfont{\rmfamily} \newtheorem{accmass}{Acc}[chapter]} +\newenvironment{acc-code}% +{\begin{accmass}}{\end{accmass}} + + +% create listing for code + +\newcommand\tcaption[1] + {\addcontentsline{cod}{section}{\protect\numberline {\thecodemass}#1}} +\makeatletter \newcommand\listofcode + {\chapter*{List of Experiments\markboth% + {\bf List of Scilab Codes}{}}% +\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{5em}}% +\addcontentsline{toc}{chapter}{\protect\numberline{List of Scilab Solutions}} +\@starttoc{cod}} +\newcommand\l@matlab[3] + {#1 \par\noindent#2, #3 \par} +\renewcommand\@pnumwidth{2.1em} +%\makeatother + +\makeatletter +\def\curlable#1{\def\thecodemass{#1}\def\@currentlabel{#1}} +\makeatother + +\newcommand{\coderef}[1]{Exa~\ref{#1}} +\newcommand{\figref}[1]{Fig.~\ref{#1}} +\renewcommand{\chaptername}{Experiment:} diff --git a/latex/latex_test.sh b/latex/latex_test.sh new file mode 100755 index 0000000..da6554a --- /dev/null +++ b/latex/latex_test.sh @@ -0,0 +1,199 @@ +#!/bin/bash +clear +Bk_details=$1 +Contrib_details=$2 +Data_all=$3 +Dep_dat=$4 + +CURDIR=$PWD; + +if [ -a /$CURDIR/TEX ] +then +rm TEX +fi + +if [ -a /$CURDIR/TEX_dep ] +then +rm TEX_dep +fi + +if [ -a /$CURDIR/TEX_new ] +then +rm TEX_new +fi + + +IFS_old="$IFS" +IFS=# read col1 col2 col3 col4 < $Contrib_details; +IFS=# read colB1 colB2 colB3 colB4 colB5 colB6 < $Bk_details; +col1=${col1/&/\\&}; +col2=${col2/&/\\&}; +col3=${col3/&/\\&}; +col4=${col4/&/\\&}; +colB1=${colB1/&/\\&}; +colB2=${colB2/&/\\&}; +colB3=${colB3/&/\\&}; +colB4=${colB4/&/\\&}; +colB5=${colB5/&/\\&}; +colB6=${colB6/&/\\&}; +echo \\title\{Scilab Manual \for "\\\\"$colB1"\\\\"by $colB2 $colB3""\\\\$colB4""\\\\$colB5"\\footnote{Funded by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Scilab Manual and Scilab codes written in it can be downloaded from the \"Migrated Labs\" section at the website http://scilab.in}}" >>$CURDIR/TEX + +echo \\author\{ Solutions provided by \\\\$col1 $col2\\\\$col3\\\\$col4\\\\ }>>$CURDIR/TEX + +IFS="$IFS_old" + +echo \\date{\\today}>>$CURDIR/TEX +echo \\begin{document}>>$CURDIR/TEX +echo \\maketitle >>$CURDIR/TEX + +#echo >>$CURDIR/TEX +#echo \\chapter*{Book Description}>>$CURDIR/TEX +#echo \\begin{description}>>$CURDIR/TEX +#echo \\item [Title:] ${colB1}>>$CURDIR/TEX +#echo \\item [Author:] ${colB2}>>$CURDIR/TEX +#echo \\item [Publisher:] ${colB4}>>$CURDIR/TEX +#echo \\item [Edition:] ${colB5}>>$CURDIR/TEX +#echo \\item [Year:] ${colB6}>>$CURDIR/TEX +#echo \\item [ISBN:] ${colB3}>>$CURDIR/TEX +#echo \\end{description}>>$CURDIR/TEX +echo >> $CURDIR/TEX + +echo \\newpage >> $CURDIR/TEX +echo \\vspace*{3cm}>>$CURDIR/TEX + +#echo Scilab numbering policy used in this document and the relation to the above book.>>$CURDIR/TEX +#echo \\begin{description}>>$CURDIR/TEX +#echo \\item[Exa] Example \(Solved example\)>>$CURDIR/TEX +#echo \\item[Eqn] Equation \(Particular equation of the above book\)>>$CURDIR/TEX +#echo \\item[AP] Appendix to Example\(Scilab Code that is an Appednix to a particular Example of the above book\)>>$CURDIR/TEX +#echo \\end{description}>>$CURDIR/TEX +#echo "For example, Exa~3.51 means solved example 3.51 of this book. Sec~2.3 means a scilab code whose theory is explained in Section 2.3 of the book.">>$CURDIR/TEX +#echo>>$CURDIR/TEX + +echo \\tableofcontents >>$CURDIR/TEX +echo \\listofcode >>$CURDIR/TEX + if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $Data_all + then + echo \\listoffigures >>$CURDIR/TEX + fi +echo>> $CURDIR/TEX +j=0; +k=1; +#sort -t '#' -k 3,3 -k 1,1 -g $Data_all > database_sort +sort -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n $Data_all > database_sort + +while IFS=# read col1 col2 col3 col4 col5 col6 col7 col8 col9; do +col2=${col2/&/\\&}; +col3=${col3/&/\\&}; +col4=${col4/&/\\&}; +col8=${col8/&/\\&}; +################## +col7=${col7/&/\\&}; +col8=${col8/&/\\&}; +col9=${col9/&/\\&}; +################# + +chap_diff=$(($col1 - $j)) +if [ $chap_diff -eq 1 ]; then + echo \\chapter{$col2}>>$CURDIR/TEX + echo >>$CURDIR/TEX +fi + +if [ $chap_diff -gt 1 ]; then + echo >>$CURDIR/TEX + echo \\setcounter{chapter}{$(($col1-1))}>>$CURDIR/TEX + echo \\chapter{$col2}>>$CURDIR/TEX + echo >>$CURDIR/TEX + +fi + +if [ $col7 != D ] +then +echo \\vspace*{10mm}>>$CURDIR/TEX +fi + + +if [ $col7 = S ] +then + echo \\curlable{Solution~$col3} >> $CURDIR/TEX + echo \\begin{code} >> $CURDIR/TEX + echo \\tcaption{$col4}{$col4} >> $CURDIR/TEX + echo \\lstinputlisting{../$col6} >> $CURDIR/TEX + echo \\end{code} >> $CURDIR/TEX + echo >>$CURDIR/TEX +fi + +if [ $col7 = D ] +then +#echo check Appendix \\ref{AP:$col9} for dependency \$$col5\$ >> $CURDIR/TEX +echo check Appendix \\ref{AP:$col9} for dependency: {\\begin{alltt} \\hspace{2mm} $col5 \\end{alltt}} >> $CURDIR/TEX +echo >> $CURDIR/TEX +fi + + +if [ $col7 = X ] +then +echo This code can be downloaded from the website wwww.scilab.in >> $CURDIR/TEX +fi + +if [ $col7 = R ] +then +echo $col6 > $CURDIR/Figure_files + if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $CURDIR/Figure_files + then + + echo \\curlable{Fig~$col3} >> $CURDIR/TEX + echo \\begin{figure} >> $CURDIR/TEX + echo \\includegraphics[scale=0.5]{../$col6} >> $CURDIR/TEX + echo \\caption{$col4} >> $CURDIR/TEX + echo \\end{figure} >> $CURDIR/TEX + echo >> $CURDIR/TEX + fi + +fi + +j=$col1 +done < database_sort +rm -f Figure_files + + +if [ -s $Dep_dat ] +then + +i=1; +echo \\chapter*{Appendix} >>$CURDIR/TEX + +while IFS=# read col1 col2 col3 col4; do +col3=${col3/&/\\&}; +echo \\curlable{AP~$i} >> $CURDIR/TEX; +echo $col2 > $CURDIR/image_files + if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $CURDIR/image_files + then + + echo \\begin{figure} >> $CURDIR/TEX + echo \\includegraphics[scale=0.5]{../$col2} >> $CURDIR/TEX + echo \\tcaption {$col3}{$col3} >> $CURDIR/TEX + echo \\end{figure} >> $CURDIR/TEX + echo >> $CURDIR/TEX + else + echo \\begin{code} >> $CURDIR/TEX; + echo \\label{AP:$col4} >> $CURDIR/TEX + echo \\lstinputlisting{../$col2} >> $CURDIR/TEX + echo \\tcaption {$col3}{$col3} >> $CURDIR/TEX + echo \\end{code} >> $CURDIR/TEX + echo >> $CURDIR/TEX + + fi +############## +#if [ $col2 = *.jpg] then echo \\includegraphics[scale=0.5]{../$col2} >> $CURDIR/TEX else +############### +#echo \\lstinputlisting{../$col2} >> $CURDIR/TEX +#fi +let "i+=1" +done < $Dep_dat +rm -f image_files +fi + +cat Initial_body TEX > TEX_final.tex +echo \\end{document} >> $CURDIR/TEX_final.tex +#clear diff --git a/latex/pdf_creator.sh b/latex/pdf_creator.sh new file mode 100755 index 0000000..1635e6d --- /dev/null +++ b/latex/pdf_creator.sh @@ -0,0 +1,18 @@ +#!/bin/bash + + +if [ -f TEX_final.tex ] +then + rm -f TEX_final.* + rm -f database_sort + rm -f database_sort.csv + rm -f TEX +fi + +./latex_test.sh $1 $2 $3 $4 +pdflatex TEX_final.tex > log.txt +pdflatex TEX_final.tex >> log1.txt +pdflatex TEX_final.tex >> log1.txt +pdflatex TEX_final.tex >> log1.txt + +rm log1.txt diff --git a/manage_proposal.inc b/manage_proposal.inc new file mode 100755 index 0000000..f79f3f3 --- /dev/null +++ b/manage_proposal.inc @@ -0,0 +1,1483 @@ +fields('lab_migration_proposal'); + $query->condition('approval_status', 0); + $query->orderBy('id', 'DESC'); + $pending_q = $query->execute(); + while ($pending_data = $pending_q->fetchObject()) + { + $pending_rows[$pending_data->id] = array( + date('d-m-Y', $pending_data->creation_date), + l($pending_data->name, 'user/' . $pending_data->uid), + $pending_data->lab_title, + $pending_data->department, + l('Approve', 'lab-migration/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'lab-migration/manage-proposal/edit/' . $pending_data->id) + ); + } + /* check if there are any pending proposals */ + if (!$pending_rows) + { + drupal_set_message(t('There are no pending proposals.'), 'status'); + return ''; + } + $pending_header = array( + 'Date of Submission', + 'Name', + 'Title of the Lab', + 'Department', + 'Action' + ); + //$output = theme_table($pending_header, $pending_rows); + $output = theme('table', array( + 'header' => $pending_header, + 'rows' => $pending_rows + )); + return $output; + } +function lab_migration_proposal_pending_solution() + { + /* get pending proposals to be approved */ + $pending_rows = array(); + //$pending_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 ORDER BY id DESC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('approval_status', 1); + $query->orderBy('id', 'DESC'); + $pending_q = $query->execute(); + while ($pending_data = $pending_q->fetchObject()) + { + $pending_rows[$pending_data->id] = array( + date('d-m-Y', $pending_data->creation_date), + date('d-m-Y', $pending_data->approval_date), + l($pending_data->name, 'user/' . $pending_data->uid), + $pending_data->lab_title, + $pending_data->department, + l('Status', 'lab-migration/manage-proposal/status/' . $pending_data->id) + ); + } + /* check if there are any pending proposals */ + if (!$pending_rows) + { + drupal_set_message(t('There are no proposals pending for solutions.'), 'status'); + return ''; + } + $pending_header = array( + 'Date of Submission', + 'Date of Approval', + 'Name', + 'Title of the Lab', + 'Department', + 'Action' + ); + $output = theme('table', array( + 'header' => $pending_header, + 'rows' => $pending_rows + )); + return $output; + } +function lab_migration_proposal_all() + { + /* get pending proposals to be approved */ + $proposal_rows = array(); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} ORDER BY id DESC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->orderBy('id', 'DESC'); + $proposal_q = $query->execute(); + while ($proposal_data = $proposal_q->fetchObject()) + { + $approval_status = ''; + switch ($proposal_data->approval_status) + { + case 0: + $approval_status = 'Pending'; + break; + case 1: + $approval_status = 'Approved'; + break; + case 2: + $approval_status = 'Dis-approved'; + break; + case 3: + $approval_status = 'Solved'; + break; + default: + $approval_status = 'Unknown'; + break; + } + $proposal_rows[] = array( + date('d-m-Y', $proposal_data->creation_date), + l($proposal_data->name, 'user/' . $proposal_data->uid), + $proposal_data->lab_title, + $proposal_data->department, + $approval_status, + l('Status', 'lab-migration/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'lab-migration/manage-proposal/edit/' . $proposal_data->id) + ); + } + /* check if there are any pending proposals */ + if (!$proposal_rows) + { + drupal_set_message(t('There are no proposals.'), 'status'); + return ''; + } + $proposal_header = array( + 'Date of Submission', + 'Name', + 'Title of the Lab', + 'Department', + 'Status', + 'Action' + ); + $output = theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; + } +function lab_migration_category_all() + { + /* get pending proposals to be approved */ + $proposal_rows = array(); + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} ORDER BY id DESC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->orderBy('id', 'DESC'); + $proposal_q = $query->execute(); + while ($proposal_data = $proposal_q->fetchObject()) + { + $proposal_rows[] = array( + date('d-m-Y', $proposal_data->creation_date), + l($proposal_data->name, 'user/' . $proposal_data->uid), + $proposal_data->lab_title, + $proposal_data->department, + $proposal_data->category, + l('Edit Category', 'lab-migration/manage-proposal/category/edit/' . $proposal_data->id) + ); + } + $proposal_header = array( + 'Date of Submission', + 'Name', + 'Title of the Lab', + 'Department', + 'Category', + 'Action' + ); + $output = theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + return $output; + } +/******************************************************************************/ +/************************** PROPOSAL APPROVAL FORM ****************************/ +/******************************************************************************/ +function lab_migration_proposal_approval_form($form, $form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + // var_dump($proposal_data->name_title); + // die; + $form['name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), + '#title' => t('Name') + ); + $form['email_id'] = array( + '#type' => 'item', + '#markup' => user_load($proposal_data->uid)->mail, + '#title' => t('Email') + ); + $form['contact_ph'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contact_ph, + '#title' => t('Contact No.') + ); + $form['department'] = array( + '#type' => 'item', + '#markup' => $proposal_data->department, + '#title' => t('Department/Branch') + ); + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->university, + '#title' => t('University/Institute') + ); + $form['country'] = array( + '#type' => 'item', + '#markup' => $proposal_data->country, + '#title' => t('Country') + ); + $form['all_state'] = array( + '#type' => 'item', + '#markup' => $proposal_data->state, + '#title' => t('State') + ); + $form['city'] = array( + '#type' => 'item', + '#markup' => $proposal_data->city, + '#title' => t('City') + ); + $form['pincode'] = array( + '#type' => 'item', + '#markup' => $proposal_data->pincode, + '#title' => t('Pincode/Postal code') + ); + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab') + ); + /* get experiment details */ + $experiment_list = ''; + $form['experiment'] = array( + '#type' => 'item', + '#markup' => $experiment_list, + '#title' => t('Experiments') + ); + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider = "User will not provide solution, we will have to provide solution"; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider = "Proposer will provide the solution of the lab"; + } + else + { + $solution_provider_user_data = user_load($proposal_data->solution_provider_uid); + if ($solution_provider_user_data) + $solution_provider = "Solution will be provided by user " . l($solution_provider_user_data->name, 'user/' . $proposal_data->solution_provider_uid); + else + $solution_provider = "User does not exists"; + } + $form['solution_provider_uid'] = array( + '#type' => 'item', + '#title' => t('Do you want to provide the solution'), + '#markup' => $solution_provider + ); + /* $form['solution_display'] = array( + '#type' => 'item', + '#title' => t('Do you want to display the solution on the www.r.fossee.in website'), + '#markup' => ($proposal_data->solution_display == 1) ? "Yes" : "No", + );*/ + $form['approval'] = array( + '#type' => 'radios', + '#title' => t('Lab migration proposal'), + '#options' => array( + '1' => 'Approve', + '2' => 'Disapprove' + ), + '#required' => TRUE + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Reason for disapproval'), + '#attributes' => array( + 'placeholder' => t('Enter reason for disapproval in minimum 30 characters '), + 'cols' => 50, + 'rows' => 4 + ), + '#states' => array( + 'visible' => array( + ':input[name="approval"]' => array( + 'value' => '2' + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l(t('Cancel'), 'lab-migration/manage-proposal') + ); + return $form; + } +function lab_migration_proposal_approval_form_validate($form, &$form_state) + { + if ($form_state['values']['approval'] == 2) + { + if ($form_state['values']['message'] == '') + { + form_set_error('message', t('Reason for disapproval could not be empty')); + } + } + } +function lab_migration_proposal_approval_form_submit($form, &$form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + if ($form_state['values']['approval'] == 1) + { + $query = "UPDATE {lab_migration_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 1, solution_status = 2 WHERE id = :proposal_id"; + $args = array( + ":uid" => $user->uid, + ":date" => time(), + ":proposal_id" => $proposal_id + ); + db_query($query, $args); + /* sending email */ + $user_data = user_load($proposal_data->uid); + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['proposal_approved']['proposal_id'] = $proposal_id; + $param['proposal_approved']['user_id'] = $proposal_data->uid; + $param['proposal_approved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'proposal_approved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('Lab migration proposal No. ' . $proposal_id . ' approved. User has been notified of the approval.', 'status'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + else if ($form_state['values']['approval'] == 2) + { + $query = "UPDATE {lab_migration_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 2, message = :message, solution_provider_uid = 0, solution_status = 0 WHERE id = :proposal_id"; + $args = array( + ":uid" => $user->uid, + ":date" => time(), + ":message" => $form_state['values']['message'], + ":proposal_id" => $proposal_id + ); + $result = db_query($query, $args); + /* sending email */ + $user_data = user_load($proposal_data->uid); + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['proposal_disapproved']['proposal_id'] = $proposal_id; + $param['proposal_disapproved']['user_id'] = $proposal_data->uid; + $param['proposal_disapproved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'proposal_disapproved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('Lab migration proposal No. ' . $proposal_id . ' dis-approved. User has been notified of the dis-approval.', 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } +/******************************************************************************/ +/*************************** PROPOSAL STATUS FORM *****************************/ +/******************************************************************************/ +function lab_migration_proposal_status_form($form, $form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + $form['name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), + '#title' => t('Name') + ); + $form['email_id'] = array( + '#type' => 'item', + '#markup' => user_load($proposal_data->uid)->mail, + '#title' => t('Email') + ); + $form['contact_ph'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contact_ph, + '#title' => t('Contact No.') + ); + $form['department'] = array( + '#type' => 'item', + '#markup' => $proposal_data->department, + '#title' => t('Department/Branch') + ); + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->university, + '#title' => t('University/Institute') + ); + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab') + ); + /* get experiment details */ + $experiment_list = ''; + $form['experiment'] = array( + '#type' => 'item', + '#markup' => $experiment_list, + '#title' => t('Experiments') + ); + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider = "User will not provide solution, we will have to provide solution"; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider = "Proposer will provide the solution of the lab"; + } + else + { + $solution_provider_user_data = user_load($proposal_data->solution_provider_uid); + if ($solution_provider_user_data) + $solution_provider = "Solution will be provided by user " . l($solution_provider_user_data->name, 'user/' . $proposal_data->solution_provider_uid); + else + $solution_provider = "User does not exists"; + } + $form['solution_provider_uid'] = array( + '#type' => 'item', + '#title' => t('Who will provide the solution'), + '#markup' => $solution_provider + ); + /*$form['solution_display'] = array( + '#type' => 'item', + '#title' => t('Display the solution on the www.r.fossee.in website'), + '#markup' => ($proposal_data->solution_display == 1) ? "Yes" : "No", + );*/ + $proposal_status = ''; + switch ($proposal_data->approval_status) + { + case 0: + $proposal_status = t('Pending'); + break; + case 1: + $proposal_status = t('Approved'); + break; + case 2: + $proposal_status = t('Dis-approved'); + break; + case 3: + $proposal_status = t('Completed'); + break; + default: + $proposal_status = t('Unkown'); + break; + } + $form['proposal_status'] = array( + '#type' => 'item', + '#markup' => $proposal_status, + '#title' => t('Proposal Status') + ); + if ($proposal_data->approval_status == 0) + { + $form['approve'] = array( + '#type' => 'item', + '#markup' => l('Click here', 'lab-migration/manage-proposal/approve/' . $proposal_id), + '#title' => t('Approve') + ); + } + if ($proposal_data->approval_status == 1) + { + $form['completed'] = array( + '#type' => 'checkbox', + '#title' => t('Completed'), + '#description' => t('Check if user has provided all experiment solutions.') + ); + } + if ($proposal_data->approval_status == 2) + { + $form['message'] = array( + '#type' => 'item', + '#markup' => $proposal_data->message, + '#title' => t('Reason for disapproval') + ); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#markup' => l(t('Cancel'), 'lab-migration/manage-proposal/all') + ); + return $form; + } +function lab_migration_proposal_status_form_submit($form, &$form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + /* set the book status to completed */ + if ($form_state['values']['completed'] == 1) + { + $up_query = "UPDATE lab_migration_proposal SET approval_status = :approval_status , expected_completion_date = :expected_completion_date WHERE id = :proposal_id"; + $args = array( + ":approval_status" => '3', + ":proposal_id" => $proposal_id, + ":expected_completion_date" => time() + ); + $result = db_query($up_query, $args); + CreateReadmeFileLabMigration($proposal_id); + if (!$result) + { + drupal_set_message('Error in update status', 'error'); + return; + } + /* sending email */ + $user_data = user_load($proposal_data->uid); + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['proposal_completed']['proposal_id'] = $proposal_id; + $param['proposal_completed']['user_id'] = $proposal_data->uid; + $param['proposal_completed']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'proposal_completed', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + /*$email_to = $user->mail . ', ' . variable_get('lab_migration_emails', '');; + if (!drupal_mail('lab_migration', 'proposal_completed', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) + drupal_set_message('Error sending email message.', 'error');*/ + drupal_set_message('Congratulations! Lab Migration proposal has been marked as completed. User has been notified of the completion.', 'status'); + } + drupal_goto('lab-migration/manage-proposal'); + return; + } +/******************************************************************************/ +/**************************** PROPOSAL EDIT FORM ******************************/ +/******************************************************************************/ +function lab_migration_proposal_edit_form($form, $form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + $user_data = user_load($proposal_data->uid); + $form['name_title'] = array( + '#type' => 'select', + '#title' => t('Title'), + '#options' => array( + 'Mr' => 'Mr', + 'Ms' => 'Ms', + 'Mrs' => 'Mrs', + 'Dr' => 'Dr', + 'Prof' => 'Prof' + ), + '#required' => TRUE, + '#default_value' => $proposal_data->name_title + ); + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Name of the Proposer'), + '#size' => 30, + '#maxlength' => 50, + '#required' => TRUE, + '#default_value' => $proposal_data->name + ); + $form['email_id'] = array( + '#type' => 'item', + '#title' => t('Email'), + '#markup' => $user_data->mail + ); + $form['contact_ph'] = array( + '#type' => 'textfield', + '#title' => t('Contact No.'), + '#size' => 30, + '#maxlength' => 15, + '#required' => TRUE, + '#default_value' => $proposal_data->contact_ph + ); + $form['department'] = array( + '#type' => 'select', + '#title' => t('Department/Branch'), + '#options' => _lm_list_of_departments(), + '#required' => TRUE, + '#default_value' => $proposal_data->department + ); + $form['university'] = array( + '#type' => 'textfield', + '#title' => t('University/Institute'), + '#size' => 30, + '#maxlength' => 50, + '#required' => TRUE, + '#default_value' => $proposal_data->university + ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others' + ), + '#default_value' => $proposal_data->country, + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#default_value' => $proposal_data->country, + '#attributes' => array( + 'placeholder' => t('Enter your country name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your state/region name') + ), + '#default_value' => $proposal_data->state, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your city name') + ), + '#default_value' => $proposal_data->city, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _lm_list_of_states(), + '#default_value' => $proposal_data->state, + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _lm_list_of_cities(), + '#default_value' => $proposal_data->city, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#default_value' => $proposal_data->pincode, + '#attributes' => array( + 'placeholder' => 'Insert pincode of your city/ village....' + ) + ); + $form['lab_title'] = array( + '#type' => 'textfield', + '#title' => t('Title of the Lab'), + '#size' => 30, + '#maxlength' => 50, + '#required' => TRUE, + '#default_value' => $proposal_data->lab_title + ); + /* get experiment details */ + // $experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY id ASC", $proposal_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $query->orderBy('id', 'ASC'); + $experiment_q = $query->execute(); + /*$form['lab_experiment'] = array( + '#type' => 'fieldset', + '#collapsible' => FALSE, + '#tree' => TRUE, + );*/ + for ($counter = 1; $counter <= 15; $counter++) + { + $experiment_title = ''; + $experiment_data = $experiment_q->fetchObject(); + if ($experiment_data) + { + $experiment_title = $experiment_data->title; + $experiment_description = $experiment_data->description; + /*$form['lab_experiment_']['update'][$experiment_data->id] = array( + '#type' => 'textfield', + '#title' => t('Title of the Experiment ') . $counter, + '#size' => 50, + '#required' => FALSE, + + '#default_value' => $experiment_title, + ); + $form['lab_experiment']['update1'][$experiment_data->id] = array( + '#type' => 'textarea', + + '#title' => t('Description for Experiment ') . $counter, + '#default_value' => $experiment_description, + );*/ + $form['lab_experiment_update' . $experiment_data->id] = array( + '#type' => 'textfield', + '#title' => t('Title of the Experiment ') . $counter, + '#size' => 50, + '#default_value' => $experiment_title + ); + $namefield = "lab_experiment_update" . $experiment_data->id; + $form['lab_experiment_description_update' . $experiment_data->id] = array( + '#type' => 'textarea', + '#attributes' => array( + 'placeholder' => t('Enter Description for your experiment ' . $counter) + ), + '#default_value' => $experiment_description, + '#title' => t('Description for Experiment ') . $counter + ); + } + else + { + $form['lab_experiment_insert' . $counter] = array( + '#type' => 'textfield', + '#title' => t('Title of the Experiment ') . $counter, + '#size' => 50, + '#required' => FALSE, + '#default_value' => $experiment_title + ); + $namefield = "lab_experiment_insert" . $counter; + $form['lab_experiment_description_insert' . $counter] = array( + '#type' => 'textarea', + '#attributes' => array( + 'placeholder' => t('Enter Description for your experiment ' . $counter) + ), + '#title' => t('Description for Experiment ') . $counter, + '#states' => array( + 'invisible' => array( + ':input[name=' . $namefield . ']' => array( + 'value' => "" + ) + ) + ) + ); + } + } + if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider_user = 'Open'; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider_user = 'Proposer'; + } + else + { + $user_data = user_load($proposal_data->solution_provider_uid); + if (!$user_data) + { + $solution_provider_user = 1; + drupal_set_message('Solution provider user name is invalid', 'error'); + } + $solution_provider_user = $user_data->name; + } + $form['solution_provider_uid'] = array( + '#type' => 'item', + '#title' => t('Who will provide the solution'), + '#markup' => $solution_provider_user + ); + $form['open_solution'] = array( + '#type' => 'checkbox', + '#title' => t('Open the solution for everyone') + ); + $form['solution_display'] = array( + '#type' => 'hidden', + '#title' => t('Do you want to display the solution on the www.r.fossee.in website'), + '#options' => array( + '1' => 'Yes' + ), + '#required' => TRUE, + // '#default_value' => ($proposal_data->solution_display == 1) ? "1" : "2", + '#default_value' => '1' + ); + $form['delete_proposal'] = array( + '#type' => 'checkbox', + '#title' => t('Delete Proposal') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l(t('Cancel'), 'lab-migration/manage-proposal') + ); + return $form; + } +function lab_migration_proposal_edit_form_validate($form, &$form_state) + { + $proposal_id = (int) arg(3); + /* 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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d", $experiment_data->id); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_data->id); + $solution_q = $query->execute(); + if ($solution_q->fetchObject()) + { + form_set_error('', t('Cannot delete proposal since there are solutions already uploaded. Use the "Bulk Manage" interface to delete this proposal')); + } + } + } + return; + } +function lab_migration_proposal_edit_form_submit($form, &$form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + /* delete proposal */ + if ($form_state['values']['delete_proposal'] == 1) + { + //db_query("DELETE FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_delete('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $num_deleted = $query->execute(); + //db_query("DELETE FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id); + $query = db_delete('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $num_deleted = $query->execute(); + drupal_set_message(t('Proposal Delete'), 'status'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + if ($form_state['values']['open_solution'] == 1) + { + // $query = "UPDATE {lab_migration_proposal} SET solution_provider_uid = :solution_provider_uid, solution_status = :solution_status, solution_provider_name_title = '', solution_provider_name = '', solution_provider_contact_ph = '', solution_provider_department = '', solution_provider_university = '' WHERE id = :proposal_id"; + // $args= array( + // ":solution_provider_uid" => 0, + // ":solution_status" => 0, + // ":proposal_id" => $proposal_id, + // ); + // $result = db_query($query, $args); + $result = db_update('lab_migration_proposal')->fields(array( + 'solution_provider_uid' => 0, + 'solution_status' => 0, + 'solution_provider_name_title' => '', + 'solution_provider_name' => '', + 'solution_provider_contact_ph' => '', + 'solution_provider_department' => '', + 'solution_provider_university' => '' + ))->condition('id', $proposal_id)->execute(); + if (!$result) + { + drupal_set_message(t('Solution already open for everyone.'), 'error'); + return; + } + } + $solution_display = 0; + if ($form_state['values']['solution_display'] == 1) + { + $solution_display = 1; + } + else + { + $solution_display = 0; + } + /* update proposal */ + $v = $form_state['values']; + //$query = "UPDATE {lab_migration_proposal} SET name_title = :name_title, name = :name, contact_ph = :contact_ph, department = :department, university = :unversity, lab_title = :lab_title, solution_display = :solution_display WHERE id = :id"; + // $args= array( + // ":name_title" => $v['name_title'], + // ":name" => $v['name'], + // "contact_ph" => $v['contact_ph'], + // ":department" => $v['department'], + // ":university" => $v['university'], + // ":lab_title" => $v['lab_title'], + // ":solution_display" => $solution_display, + // ":id" => $proposal_id, + // ); + + $lab_title = $v['lab_title']; + $proposar_name = $v['name_title'] . ' ' . $v['name']; + $university = $v['university']; + $directory_names = _lm_dir_name($lab_title, $proposar_name, $university); + if (LM_RenameDir($proposal_id, $directory_names)) + { + $directory_name = $directory_names; + } + else + { + return; + } + + $query = db_update('lab_migration_proposal')->fields(array( + 'name_title' => $v['name_title'], + 'name' => $v['name'], + 'contact_ph' => $v['contact_ph'], + 'department' => $v['department'], + 'university' => $v['university'], + 'city' => $v['city'], + 'pincode' => $v['pincode'], + 'state' => $v['all_state'], + 'lab_title' => $v['lab_title'], + 'solution_display' => $solution_display, + 'directory_name' => $directory_name + ))->condition('id', $proposal_id); + $result1 = $query->execute(); + //$result=db_query($query, $args); + /* updating existing experiments */ + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $query->orderBy('id', 'ASC'); + $experiment_q = $query->execute(); + for ($counter = 1; $counter <= 15; $counter++) + { + $experiment_data = $experiment_q->fetchObject(); + if ($experiment_data) + { + $experiment_field_name = 'lab_experiment_update' . $experiment_data->id; + $experiment_description = 'lab_experiment_description_update' . $experiment_data->id; + if (strlen(trim($form_state['values'][$experiment_field_name])) >= 1) + { + $query = "UPDATE {lab_migration_experiment} SET title = :title, description= :description WHERE id = :id"; + $args = array( + ":title" => trim($form_state['values'][$experiment_field_name]), + ":description" => trim($form_state['values'][$experiment_description]), + ":id" => $experiment_data->id + ); + $result2 = db_query($query, $args); + if (!$result2) + { + drupal_set_message(t('Could not update Title of the Experiment : ') . trim($form_state['values'][$experiment_field_name]), 'error'); + } + } + else + { + $query = "DELETE FROM {lab_migration_experiment} WHERE id = :id LIMIT 1"; + $args = array( + ":id" => $experiment_data->id + ); + $result3 = db_query($query, $args); + } + } + } + /* foreach ($form_state['values']['lab_experiment']['update'] as $update_id => $update_value) { + if (strlen(trim($update_value)) >= 1) { + $description= $form_state['values']['lab_experiment_description']['update']; + $query = "UPDATE {lab_migration_experiment} SET title = :title and description=:description WHERE id = :id"; + $args = array( + ":title"=> trim($update_value), + ":description"=>trim($description), + ":id"=> $update_id, + ); + $result2 = db_query($query, $args); + if (!$result2) + { + drupal_set_message(t('Could not update Title of the Experiment : ') . trim($update_value), 'error'); + } + } else { + $query = "DELETE FROM {lab_migration_experiment} WHERE id = :id LIMIT 1"; + $args = array( + ":id" => $update_id + ); + $result3 = db_query($query, $args); + } + }*/ + /* inserting new experiments */ + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $query->orderBy('number', 'DESC'); + $query->range(0, 1); + $number_q = $query->execute(); + if ($number_data = $number_q->fetchObject()) + { + $number = (int) $number_data->number; + $number++; + } + else + { + $number = 1; + } + for ($counter = 1; $counter <= 15; $counter++) + { + $lab_experiment_insert = 'lab_experiment_insert' . $counter; + $lab_experiment_description_insert = 'lab_experiment_description_insert' . $counter; + if (strlen(trim(isset($form_state['values'][$lab_experiment_insert]))) >= 1) + { + $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title, description) VALUES (:proposal_id, :number, :title, :description)"; + $args = array( + ":proposal_id" => $proposal_id, + ":number" => $number, + ":title" => trim($form_state['values'][$lab_experiment_insert]), + ":description" => trim($form_state['values'][$lab_experiment_description_insert]) + ); + $result4 = db_query($query, $args); + if (!$result4) + { + drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($form_state['values'][$lab_experiment_insert]), 'error'); + } + else + { + $number++; + } + } + } + /* $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $query->orderBy('number', 'DESC'); + $query->range(0, 1); + $number_q = $query->execute(); + if ($number_data = $number_q->fetchObject()) { + $number = (int)$number_data->number; + $number++; + } else { + $number = 1; + } + $insertvalue = array($insert_id => $insert_value); + $lab_experimentinsert = $form_state['values']['lab_experiment']['insert']; + $lab_exp_descriptioninsert=$form_state['values']['lab_experiment_description']['insert']; + if (is_array($lab_experimentinsert) || is_object($lab_experimentinsert)) + { + foreach ($lab_experimentinsert as $insertvalue) { + //foreach ($form_state['values']['lab_experiment']['insert'] as $insert_id => $insert_value) { + if (strlen(trim($insert_value)) >= 1) { + $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title, description) VALUES :proposal_id, :number, :title, :description"; + $args = array( + ":proposal_id" => $proposal_id, + ":number" => $number, + ":title" => trim($insert_value), + ":description"=>"" + ); + $result4 = db_query($query, $args); + if (!$result4) + { + drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($insert_value), 'error'); + } else { + $number++; + } + } + } + }*/ + drupal_set_message(t('Proposal Updated'), 'status'); + } +/******************************************************************************/ +/**************************** CATEGORY EDIT FORM ******************************/ +/******************************************************************************/ +function lab_migration_category_edit_form($form, $form_state) + { + /* get current proposal */ + $proposal_id = (int) arg(4); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + $form['name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), + '#title' => t('Name') + ); + $form['email_id'] = array( + '#type' => 'item', + '#markup' => user_load($proposal_data->uid)->mail, + '#title' => t('Email') + ); + $form['contact_ph'] = array( + '#type' => 'item', + '#markup' => $proposal_data->contact_ph, + '#title' => t('Contact No.') + ); + $form['department'] = array( + '#type' => 'item', + '#markup' => $proposal_data->department, + '#title' => t('Department/Branch') + ); + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->university, + '#title' => t('University/Institute') + ); + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab') + ); + $form['category'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _lm_list_of_departments(), + '#required' => TRUE, + '#default_value' => $proposal_data->category + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'item', + '#markup' => l(t('Cancel'), 'lab-migration/manage-proposal/category') + ); + return $form; + } +function lab_migration_category_edit_form_submit($form, &$form_state) + { + /* get current proposal */ + $proposal_id = (int) arg(4); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal'); + return; + } + $query = "UPDATE {lab_migration_proposal} SET category = :category WHERE id = :proposal_id"; + $args = array( + ":category" => $form_state['values']['category'], + ":proposal_id" => $proposal_data->id + ); + $result = db_query($query, $args); + drupal_set_message(t('Proposal Category Updated'), 'status'); + drupal_goto('lab-migration/manage-proposal/category'); + } +function _lm_list_of_departments() + { + $department = array( + 0 => '-Select-' + ); + $query = db_select('list_of_departments'); + $query->fields('list_of_departments'); + $query->orderBy('id', 'DESC'); + $department_list = $query->execute(); + while ($department_list_data = $department_list->fetchObject()) + { + $department[$department_list_data->department] = $department_list_data->department; + } + return $department; + } +function _lm_list_of_states() + { + $states = array( + 0 => '-Select-' + ); + $query = db_select('list_states_of_india'); + $query->fields('list_states_of_india'); + //$query->orderBy('', ''); + $states_list = $query->execute(); + while ($states_list_data = $states_list->fetchObject()) + { + $states[$states_list_data->state] = $states_list_data->state; + } + return $states; + } +function _lm_list_of_cities() + { + $city = array(); + $query = db_select('list_cities_of_india'); + $query->fields('list_cities_of_india'); + $query->orderBy('city', 'ASC'); + $city_list = $query->execute(); + while ($city_list_data = $city_list->fetchObject()) + { + $city[$city_list_data->city] = $city_list_data->city; + } + return $city; + } +function CreateReadmeFileLabMigration($proposal_id) + { + $result = db_query(" + SELECT * from lab_migration_proposal WHERE id = :proposal_id", array( + ":proposal_id" => $proposal_id + )); + $proposal_data = $result->fetchObject(); + $root_path = lab_migration_path(); + $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!"); + $txt = ""; + $txt .= "About the lab"; + $txt .= "\n" . "\n"; + $txt .= "Title Of The Lab: " . $proposal_data->lab_title . "\n"; + $txt .= "Proposar Name: " . $proposal_data->name_title . " " . $proposal_data->name . "\n"; + $txt .= "Department: " . $proposal_data->department . "\n"; + $txt .= "University: " . $proposal_data->university . "\n"; + $txt .= "Category: " . $proposal_data->department . "\n\n"; + $txt .= "\n" . "\n"; + $txt .= "Solution provider"; + $txt .= "\n" . "\n"; + $txt .= "Solution Provider Name: " . $proposal_data->solution_provider_name_title . " " . $proposal_data->solution_provider_name . "\n"; + $txt .= "Solution Provider University: " . $proposal_data->solution_provider_university . "\n"; + $txt .= "\n" . "\n"; + $txt .= "Lab Migration Project By FOSSEE, IIT Bombay" . "\n"; + fwrite($readme_file, $txt); + fclose($readme_file); + return $txt; + } +function LM_RenameDir($proposal_id, $dir_name) + { + $query = db_query("SELECT directory_name FROM lab_migration_proposal WHERE id = :proposal_id", array( + ':proposal_id' => $proposal_id + )); + $result = $query->fetchObject(); + $new_directory_name = rename(lab_migration_path() . $result->directory_name, lab_migration_path() . $dir_name) or drupal_set_message("Unable to rename folder"); + + return $new_directory_name; + + } +function _lm_dir_name($lab, $name, $university) + { + $lab_title = ucname($lab); + $proposar_name = ucname($name); + $university_name = ucname($university); + $dir_name = $lab_title . " " . "by" . " " . $proposar_name . ' ' . $university_name; + $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name)); + return $directory_name; + } diff --git a/manage_solution_proposal.inc b/manage_solution_proposal.inc new file mode 100755 index 0000000..3e9aad5 --- /dev/null +++ b/manage_solution_proposal.inc @@ -0,0 +1,340 @@ +fields('lab_migration_proposal'); + $query->condition('solution_provider_uid', 0, '!='); + $query->condition('solution_status', 1); + $query->orderBy('id', 'DESC'); + $pending_q = $query->execute(); + while ($pending_data = $pending_q->fetchObject()) + { + $pending_rows[$pending_data->id] = array( + l($pending_data->name, 'user/' . $pending_data->uid), + $pending_data->lab_title, + l('Approve', 'lab-migration/manage-proposal/solution-proposal-approve/' . $pending_data->id) + ); + } + /* check if there are any pending proposals */ + if (!$pending_rows) + { + drupal_set_message(t('There are no pending solution proposals.'), 'status'); + return ''; + } + $pending_header = array( + 'Proposer Name', + 'Title of the Lab', + 'Action' + ); + $output = theme('table', array( + 'header' => $pending_header, + 'rows' => $pending_rows + )); + return $output; + } +/******************************************************************************/ +/***************** SOLUTION PROPOSAL APPROVAL FORM ****************************/ +/******************************************************************************/ +function lab_migration_solution_proposal_approval_form($form, $form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal/pending-solution-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal/pending-solution-proposal'); + return; + } + $form['name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->solution_provider_name_title . ' ' . $proposal_data->solution_provider_name, 'user/' . $proposal_data->solution_provider_uid), + '#title' => t('Solution Provider Name'), + ); + $form['email_id'] = array( + '#type' => 'item', + '#markup' => user_load($proposal_data->solution_provider_uid)->mail, + '#title' => t('Solution Provider Email'), + ); + $form['contact_ph'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_contact_ph, + '#title' => t('Solution Provider Contact No.'), + ); + $form['department'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_department, + '#title' => t('Department/Branch'), + ); + $form['university'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_university, + '#title' => t('University/Institute'), + ); + +$form['country'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_country, + '#title' => t('Country') + ); + $form['all_state'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_state, + '#title' => t('State') + ); + $form['city'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_city, + '#title' => t('City') + ); + $form['pincode'] = array( + '#type' => 'item', + '#markup' => $proposal_data->solution_provider_pincode, + '#title' => t('Pincode/Postal code') + ); + + + $form['esim_version'] = array( + '#type' => 'item', + '#title' => t('eSim version used'), + '#markup'=>$proposal_data->esim_version, + ); + + + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab'), + ); + /* get experiment details */ + $experiment_list = ''; + $form['experiment'] = array( + '#type' => 'item', + '#markup' => $experiment_list, + '#title' => t('Experiments') + ); + $form['solution_display'] = array( + '#type' => 'item', + '#title' => t('Display the solution on the www.esim.fossee.in website'), + '#markup' => ($proposal_data->solution_display == 1) ? "Yes" : "No" + ); + /*if ($proposal_data->solution_provider_uid == 0) + { + $solution_provider = "Open"; + } + else if ($proposal_data->solution_provider_uid == $proposal_data->uid) + { + $solution_provider = "Proposer will provide the solution of the lab"; + } + else + { + $solution_provider_user_data = user_load($proposal_data->solution_provider_uid); + if ($solution_provider_user_data) + { + $solution_provider .= ''; + } + else + { + $solution_provider = "User does not exists"; + } + }*/ + + $proposer .= ''; + $form['proposer_details'] = array( + '#type' => 'item', + '#title' => t('Proposer of Lab :'), + '#markup' => $proposer, + ); + /*$form['solution_provider_uid'] = array( + '#type' => 'item', + '#title' => t('Solution Provider'), + '#markup' => $solution_provider + );*/ + $form['approval'] = array( + '#type' => 'radios', + '#title' => t('Solution Provider'), + '#options' => array( + '1' => 'Approve', + '2' => 'Disapprove' + ), + '#required' => TRUE + ); + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('Reason for disapproval') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'lab-migration/manage-proposal/pending-solution-proposal') + ); + return $form; + } +function lab_migration_solution_proposal_approval_form_validate($form, &$form_state) + { + $proposal_id = (int) arg(3); + // $solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $solution_provider_q = $query->execute(); + $solution_provider_data = $solution_provider_q->fetchObject(); + // $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); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_provider_uid', $solution_provider_data->uid); + $query->condition('approval_status', array( + 0, + 1 + ), 'IN'); + $query->condition('id', $proposal_id, '<>'); + $solution_provider_present_q = $query->execute(); + if ($x = $solution_provider_present_q->fetchObject()) + { + drupal_set_message($proposal_id); + form_set_error('', t('Solution provider has already one proposal active')); + } + } +function lab_migration_solution_proposal_approval_form_submit($form, &$form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + if ($proposal_q) + { + if ($proposal_data = $proposal_q->fetchObject()) + { + /* everything ok */ + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal/pending-solution-proposal'); + return; + } + } + else + { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('lab-migration/manage-proposal/pending-solution-proposal'); + return; + } + $user_data = user_load($proposal_data->solution_provider_uid); + if ($form_state['values']['approval'] == 1) + { + $query = "UPDATE {lab_migration_proposal} SET solution_status = 2 WHERE id =:proposal_id"; + $args = array( + ":proposal_id" => $proposal_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_proposal_approved']['proposal_id'] = $proposal_id; + $param['solution_proposal_approved']['user_id'] = $proposal_data->solution_provider_uid; + $param['solution_proposal_approved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_proposal_approved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + /*$email_to = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + if (!drupal_mail('lab_migration', 'solution_proposal_approved', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) + drupal_set_message('Error sending email message.', 'error');*/ + drupal_set_message('Lab migration solution proposal approved. User has been notified of the approval.', 'status'); + drupal_goto('lab-migration/manage-proposal/pending-solution_proposal'); + return; + } + else if ($form_state['values']['approval'] == 2) + { + $query = "UPDATE {lab_migration_proposal} SET solution_provider_uid = :solution_provider_uid, solution_status = :solution_status, solution_provider_name_title = '', solution_provider_name = '', solution_provider_contact_ph = '', solution_provider_department = '', solution_provider_university = '' WHERE id = :proposal_id"; + $args = array( + ":solution_provider_uid" => 0, + ":solution_status" => 0, + ":proposal_id" => $proposal_id + ); + db_query($query, $args); + /* sending email */ + $email_to = $user_data->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = $user->mail . ', ' . variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_proposal_disapproved']['proposal_id'] = $proposal_id; + $param['solution_proposal_disapproved']['user_id'] = $proposal_data->solution_provider_uid; + $param['solution_proposal_disapproved']['message'] = $form_state['values']['message']; + $param['solution_proposal_disapproved']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_proposal_disapproved', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message('Lab migration solution proposal dis-approved. User has been notified of the dis-approval.', 'status'); + drupal_goto('lab-migration/manage-proposal/pending-solution-proposal'); + return; + } + } diff --git a/notes.inc b/notes.inc new file mode 100755 index 0000000..8e7c144 --- /dev/null +++ b/notes.inc @@ -0,0 +1,104 @@ +fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t('Invalid lab selected. Please try again.'), 'error'); + drupal_goto('lab-migration/code-approval'); + return; + } + /* get current notes */ + $notes = ''; + //$notes_q = db_query("SELECT * FROM {lab_migration_notes} WHERE proposal_id = %d LIMIT 1", $proposal_id); + $query = db_select('lab_migration_notes'); + $query->fields('lab_migration_notes'); + $query->condition('proposal_id', $proposal_id); + $query->range(0, 1); + $notes_q = $query->execute(); + if ($notes_q) + { + $notes_data = $notes_q->fetchObject(); + $notes = $notes_data->notes; + } + $form['lab_details'] = array( + '#type' => 'item', + '#value' => 'About the Lab
' . 'Proposer: ' . $proposal_data->name . '
' . 'Title of the Lab: ' . $proposal_data->lab_title . '
' + ); + $form['notes'] = array( + '#type' => 'textarea', + '#rows' => 20, + '#title' => t('Notes for Reviewers'), + '#default_value' => $notes + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Back'), 'lab-migration/code-approval') + ); + return $form; + } +function lab_migration_lab_notes_form_submit($form, &$form_state) + { + global $user; + /* get current proposal */ + $proposal_id = (int) arg(3); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message(t('Invalid lab selected. Please try again.'), 'error'); + drupal_goto('lab-migration/code-approval'); + return; + } + /* find existing notes */ + //$notes_q = db_query("SELECT * FROM {lab_migration_notes} WHERE proposal_id = %d LIMIT 1", $proposal_id); + $query = db_select('lab_migration_notes'); + $query->fields('lab_migration_notes'); + $query->condition('proposal_id', $proposal_id); + $query->range(0, 1); + $notes_q = $query->execute(); + $notes_data = $notes_q->fetchObject(); + /* add or update notes in database */ + if ($notes_data) + { + $query = "UPDATE {lab_migration_notes} SET notes = :notes WHERE id = :notes_id"; + $args = array( + ":notes" => $form_state['values']['notes'], + ":notes_id" => $notes_data->id + ); + db_query($query, $args); + drupal_set_message('Notes updated successfully.', 'status'); + } + else + { + $query = "INSERT INTO {lab_migration_notes} (proposal_id, notes) VALUES (:proposal_id, :notes)"; + $args = array( + ":proposal_id" => $proposal_id, + ":notes" => $form_state['values']['notes'] + ); + db_query($query, $args); + drupal_set_message('Notes added successfully.', 'status'); + } + } diff --git a/proposal.inc b/proposal.inc new file mode 100755 index 0000000..311320c --- /dev/null +++ b/proposal.inc @@ -0,0 +1,585 @@ +uid == 0) { + $msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the lab proposal form. If you are new user please create a new account first.'), 'error'); + //drupal_goto('lab-migration-project'); + drupal_goto('user'); + return $msg; + } + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('uid', $user->uid); + $query->orderBy('id', 'DESC'); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if ($proposal_data) + { + if ($proposal_data->approval_status == 0 || $proposal_data->approval_status == 1) + { + drupal_set_message(t('We have already received your proposal.'), 'status'); + drupal_goto(''); + return; + } + } + $form['#attributes'] = array( + 'enctype' => "multipart/form-data" + ); + $form['name_title'] = array( + '#type' => 'select', + '#title' => t('Title'), + '#options' => array( + 'Dr' => 'Dr', + 'Prof' => 'Prof' + ), + '#required' => TRUE + ); + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Name of the Proposer'), + '#size' => 200, + '#attributes' => array( + 'placeholder' => t('Enter your full name') + ), + '#maxlength' => 200, + '#required' => TRUE + ); + $form['email_id'] = array( + '#type' => 'textfield', + '#title' => t('Email'), + '#size' => 30, + '#value' => $user->mail, + '#disabled' => TRUE + ); + $form['contact_ph'] = array( + '#type' => 'textfield', + '#title' => t('Contact No.'), + '#size' => 30, + '#attributes' => array( + 'placeholder' => t('Enter your contact number') + ), + '#maxlength' => 15, + '#required' => TRUE + ); + $form['department'] = array( + '#type' => 'select', + '#title' => t('Department/Branch'), + '#options' => _lm_list_of_departments(), + '#required' => TRUE + ); + $form['university'] = array( + '#type' => 'textfield', + '#title' => t('University/ Institute'), + '#size' => 80, + '#maxlength' => 200, + '#required' => TRUE, + '#attributes' => array( + 'placeholder' => 'Insert full name of your institute/ university.... ' + ) + ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others' + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your country name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your state/region name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your city name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _lm_list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _lm_list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' => array( + 'placeholder' => 'Enter pincode....' + ) + ); + /***************************************************************************/ + $form['hr'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['version'] = array( + '#type' => 'select', + '#title' => t('Version'), + '#options' => _lm_list_of_software_version(), + '#required' => TRUE + ); + $form['older'] = array( + '#type' => 'textfield', + '#size' => 30, + '#maxlength' => 50, + //'#required' => TRUE, + '#description' => t('Specify the Older version used'), + '#states' => array( + 'visible' => array( + ':input[name="version"]' => array( + 'value' => 'olderversion' + ) + ) + ) + ); + $form['lab_title'] = array( + '#type' => 'textfield', + '#title' => t('Title of the Lab'), + '#size' => 50, + '#required' => TRUE + ); + $first_experiemnt = TRUE; + for ($counter = 1; $counter <= 15; $counter++) + { + if ($counter <= 5) + { + $form['lab_experiment-' . $counter] = array( + '#type' => 'textfield', + '#title' => t('Title of the Experiment ') . $counter, + '#size' => 50, + '#required' => TRUE + ); + $namefield = "lab_experiment-" . $counter; + $form['lab_experiment_description-' . $counter] = array( + '#type' => 'textarea', + '#required' => TRUE, + '#attributes' => array( + 'placeholder' => t('Enter Description for your experiment ' . $counter), + 'cols' => 50, + 'rows' => 4 + ), + '#title' => t('Description for Experiment ') . $counter, + '#states' => array( + 'invisible' => array( + ':input[name=' . $namefield . ']' => array( + 'value' => "" + ) + ) + ) + ); + } + else + { + $form['lab_experiment-' . $counter] = array( + '#type' => 'textfield', + '#title' => t('Title of the Experiment ') . $counter, + '#size' => 50, + '#required' => FALSE + ); + $namefield = "lab_experiment-" . $counter; + $form['lab_experiment_description-' . $counter] = array( + '#type' => 'textarea', + '#required' => FALSE, + '#attributes' => array( + 'placeholder' => t('Enter Description for your experiment ' . $counter), + 'cols' => 50, + 'rows' => 4 + ), + '#title' => t('Description for Experiment ') . $counter, + '#states' => array( + 'invisible' => array( + ':input[name=' . $namefield . ']' => array( + 'value' => "" + ) + ) + ) + ); + } + $first_experiemnt = FALSE; + } + $form['solution_provider_uid'] = array( + '#type' => 'radios', + '#title' => t('Do you want to provide the solution'), + '#options' => array( + '1' => 'Yes', + '2' => 'No' + ), + '#required' => TRUE, + '#default_value' => '1', + '#description' => 'If you dont want to provide the solution then it will be opened for the community, anyone may come forward and provide the solution.' + ); + $form['solution_display'] = array( + '#type' => 'hidden', + '#title' => t('Do you want to display the solution on the www.r.fossee.in website'), + '#options' => array( + '1' => 'Yes' + ), + '#required' => TRUE, + '#default_value' => '1', + '#description' => 'If yes, solutions will be made available to everyone for downloading.', + '#disabled' => FALSE + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; + } +function lab_migration_proposal_form_validate($form, &$form_state) + { + if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['contact_ph'])) + { + form_set_error('contact_ph', t('Invalid contact phone number')); + } + if ($form_state['values']['country'] == 'Others') + { + if ($form_state['values']['other_country'] == '') + { + form_set_error('other_country', t('Enter country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['other_state'] == '') + { + form_set_error('other_state', t('Enter state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if ($form_state['values']['other_city'] == '') + { + form_set_error('other_city', t('Enter city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['city'] = $form_state['values']['other_city']; + } + } + else + { + if ($form_state['values']['country'] == '') + { + form_set_error('country', t('Select country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['all_state'] == '') + { + form_set_error('all_state', t('Select state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['city'] == '') + { + form_set_error('city', t('Select city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + } + for ($counter = 1; $counter <= 15; $counter++) + { + $experiment_field_name = 'lab_experiment-' . $counter; + $experiment_description = 'lab_experiment_description-' . $counter; + if (strlen(trim($form_state['values'][$experiment_field_name])) >= 1) + { + if (strlen(trim($form_state['values'][$experiment_description])) <= 49) + { + form_set_error($experiment_description, t('Description should be minimum of 50 characters')); + } + } + } + if ($form_state['values']['version'] == 'olderversion') + { + if ($form_state['values']['older'] == '') + { + form_set_error('older', t('Please provide valid version')); + } + } + return; + } +function lab_migration_proposal_form_submit($form, &$form_state) + { + global $user; + if (!$user->uid) + { + drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); + return; + } + $solution_provider_uid = 0; + $solution_status = 0; + $solution_provider_name_title = ''; + $solution_provider_name = ''; + $solution_provider_contact_ph = ''; + $solution_provider_department = ''; + $solution_provider_university = ''; + if ($form_state['values']['solution_provider_uid'] == "1") + { + $solution_provider_uid = $user->uid; + $solution_status = 1; + $solution_provider_name_title = $form_state['values']['name_title']; + $solution_provider_name = $form_state['values']['name']; + $solution_provider_contact_ph = $form_state['values']['contact_ph']; + $solution_provider_department = $form_state['values']['department']; + $solution_provider_university = $form_state['values']['university']; + } + else + { + $solution_provider_uid = 0; + } + $solution_display = 0; + if ($form_state['values']['solution_display'] == "1") + $solution_display = 1; + else + $solution_display = 1; + if ($form_state['values']['version'] == 'olderversion') + { + $form_state['values']['version'] = $form_state['values']['older']; + } + /* inserting the user proposal */ + $v = $form_state["values"]; + $lab_title = $v['lab_title']; + $proposar_name = $v['name_title']. ' ' . $v['name']; + $university = $v['university']; + $directory_name = _lm_dir_name($lab_title, $proposar_name, $university); + $result = "INSERT INTO {lab_migration_proposal} + (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, country, version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, directory_name) VALUES + (:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :pincode, :state, :country, + :version, :lab_title, :approval_status, :solution_status, :solution_provider_uid, :solution_display, :creation_date, + :approval_date, :solution_date, :solution_provider_name_title, :solution_provider_name, + :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :directory_name)"; + $args = array( + ":uid" => $user->uid, + ":approver_uid" => 0, + ":name_title" => $v['name_title'], + ":name" => $v['name'], + ":contact_ph" => $v['contact_ph'], + ":department" => $v['department'], + ":university" => $v['university'], + ":city" => $v['city'], + ":pincode" => $v['pincode'], + ":state" => $v['all_state'], + ":country" => $v['country'], + ":version" => $form_state['values']['version'], + ":lab_title" => $v['lab_title'], + ":approval_status" => 0, + ":solution_status" => $solution_status, + ":solution_provider_uid" => $solution_provider_uid, + ":solution_display" => $solution_display, + ":creation_date" => time(), + ":approval_date" => 0, + ":solution_date" => 0, + ":solution_provider_name_title" => $solution_provider_name_title, + ":solution_provider_name" => $solution_provider_name, + ":solution_provider_contact_ph" => $solution_provider_contact_ph, + ":solution_provider_department" => $solution_provider_department, + ":solution_provider_university" => $solution_provider_university, + ":directory_name" => $directory_name + ); + $proposal_id = db_query($result, $args, array( + 'return' => Database::RETURN_INSERT_ID + )); + if (!$proposal_id) + { + drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error'); + return; + } + /* proposal id */ + //$proposal_id = db_last_insert_id('lab_migration_proposal', 'id'); + /* adding experiments */ + $number = 1; + for ($counter = 1; $counter <= 15; $counter++) + { + $experiment_field_name = 'lab_experiment-' . $counter; + $experiment_description = 'lab_experiment_description-' . $counter; + if (strlen(trim($form_state['values'][$experiment_field_name])) >= 1) + { + //$query = "INSERT INTO {lab_migration_experiment} (proposal_id, directory_name, number, title,description) VALUES (:proposal_id, :directory_name, :number, :experiment_field_name,:description)"; + $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title,description) VALUES (:proposal_id, :number, :experiment_field_name,:description)"; + $args = array( + ":proposal_id" => $proposal_id, + // ":directory_name" => $directory_name, + ":number" => $number, + ":experiment_field_name" => trim($form_state['values'][$experiment_field_name]), + ":description" => trim($form_state['values'][$experiment_description]) + ); + $result = db_query($query, $args); + if (!$result) + { + drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($form_state['values'][$experiment_field_name]), 'error'); + } + else + { + $number++; + } + } + } + /* sending email */ + $email_to = $user->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['proposal_received']['proposal_id'] = $proposal_id; + $param['proposal_received']['user_id'] = $user->uid; + $param['proposal_received']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'proposal_received', $email_to, user_preferred_language($user), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + drupal_set_message(t('We have received you Lab migration proposal. We will get back to you soon.'), 'status'); + drupal_goto(''); + } +function _lm_list_of_states() + { + $states = array(0 => '-Select-'); + $query = db_select('list_states_of_india'); + $query->fields('list_states_of_india'); + //$query->orderBy('', ''); + $states_list = $query->execute(); + while ($states_list_data = $states_list->fetchObject()) + { + $states[$states_list_data->state] = $states_list_data->state; + } + return $states; + } +function _lm_list_of_cities() + { + $city = array(0 => '-Select-'); + $query = db_select('list_cities_of_india'); + $query->fields('list_cities_of_india'); + $query->orderBy('city', 'ASC'); + $city_list = $query->execute(); + while ($city_list_data = $city_list->fetchObject()) + { + $city[$city_list_data->city] = $city_list_data->city; + } + return $city; + } +function _lm_list_of_departments() + { + $department = array(); + $query = db_select('list_of_departments'); + $query->fields('list_of_departments'); + $query->orderBy('id', 'DESC'); + $department_list = $query->execute(); + while ($department_list_data = $department_list->fetchObject()) + { + $department[$department_list_data->department] = $department_list_data->department; + } + return $department; + } +function _lm_list_of_software_version() + { + $software_version = array(); + $query = db_select('r_software_version'); + $query->fields('r_software_version'); + $query->orderBy('id', 'DESC'); + $software_version_list = $query->execute(); + while ($software_version_list_data = $software_version_list->fetchObject()) + { + $software_version[$software_version_list_data->r_version] = $software_version_list_data->r_version; + } + return $software_version; + } +function _lm_dir_name($lab, $name, $university) + { + $lab_title = lm_ucname($lab); + $proposar_name = lm_ucname($lab); + $university_name = lm_ucname($university); + $dir_name = $lab_title . " " . "by". " " . $proposar_name . ' ' . $university_name; + $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name)); + return $directory_name; + } diff --git a/run.inc b/run.inc new file mode 100755 index 0000000..f3b39d0 --- /dev/null +++ b/run.inc @@ -0,0 +1,520 @@ + 'select', + '#title' => t('Title of the lab'), + '#options' => _list_of_labs(), + '#default_value' => $selected, + '#ajax' => array( + 'callback' => 'ajax_experiment_list_callback' + ) + ); + if (!$url_lab_id) + { + $form['selected_lab'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['selected_lab_r'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['selected_lab_pdf'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['lab_details'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['lab_experiment_list'] = array( + '#type' => 'select', + '#title' => t('Titile of the experiment'), + '#options' => _ajax_get_experiment_list($selected), + //'#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_solution_list_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_experiment'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['lab_solution_list'] = array( + '#type' => 'select', + '#title' => t('Solution'), + '#options' => _ajax_get_solution_list($select_two), + //'#default_value' => isset($form_state['values']['lab_solution_list']) ? + //$form_state['values']['lab_solution_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_solution_files_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['edit_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['solution_files'] = array( + '#type' => 'item', + // '#title' => t('List of solution_files'), + '#markup' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + } + else + { + $lab_default_value = $url_lab_id; + $form['selected_lab'] = array( + '#type' => 'item', + '#markup' => '
' . l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value) . '
' + ); + /* $form['selected_lab_pdf'] = array( + '#type' => 'item', + '#markup' => '
'. l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1') .'
', + + );*/ + if ($lab_default_value == '2') + { + $form['selected_lab_r'] = array( + '#type' => 'item', + '#markup' => '
' . l('Download Lab Solutions (r Version)', 'lab-migration-uploads/r_Version.zip') . '
' + ); + } + $form['lab_details'] = array( + '#type' => 'item', + '#markup' => '
' . _lab_details($lab_default_value) . '
' + ); + $form['lab_experiment_list'] = array( + '#type' => 'select', + '#title' => t('Titile of the experiment'), + '#options' => _ajax_get_experiment_list($selected), + // '#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_solution_list_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_experiment'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['lab_solution_list'] = array( + '#type' => 'select', + '#title' => t('Solution'), + '#options' => _ajax_get_solution_list($select_two), + '#default_value' => isset($form_state['values']['lab_solution_list']) ? $form_state['values']['lab_solution_list'] : '', + '#ajax' => array( + 'callback' => 'ajax_solution_files_callback' + ), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab_experiment_list"]' => array( + 'value' => 0 + ) + ) + ) + ); + $form['download_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['edit_solution'] = array( + '#type' => 'item', + '#markup' => '
' + ); + $form['solution_files'] = array( + '#type' => 'item', + // '#title' => t('List of solution_files'), + '#markup' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="lab_experiment_list"]' => array( + 'value' => 0 + ) + ) + ) + ); + } + /* + $form['message'] = array( + '#type' => 'textarea', + '#title' => t('If Dis-Approved please specify reason for Dis-Approval'), + '#prefix' => '
', + '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), + + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + '#suffix' => '
', + '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), + + );*/ + return $form; + } +function ajax_experiment_list_callback($form, $form_state) + { + $commands = array(); + $lab_default_value = $form_state['values']['lab']; + if ($lab_default_value != 0) + { + $form['lab_details']['#markup'] = _lab_details($lab_default_value); + $lab_details = _lab_information($lab_default_value); + $user_solution_provider = user_load($lab_details->solution_provider_uid); + //var_dump($lab_details->solution_provider_uid); + if ($lab_details->solution_provider_uid > 0) + { + $commands[] = ajax_command_html('#ajax_selected_lab', l('Download Lab Solutions', 'lab-migration/download/lab/' . $lab_default_value)); + if ($lab_default_value == '2') + { + $commands[] = ajax_command_html('#ajax_selected_lab_r', l('Download Lab Solutions (r Version)', 'lab-migration_uploads/r_Version.zip')); + } + /* $commands[] = ajax_command_html('#ajax_selected_lab_pdf', l('Download PDF of Lab Solutions', 'lab-migration/generate-lab/' . $lab_default_value . '/1'));*/ + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_r', ''); + } + $commands[] = ajax_command_html('#ajax_lab_details', _lab_details($lab_default_value)); + $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list($lab_default_value); + $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_download_experiments', ''); + } + else + { + $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list(); + $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_lab_details', ''); + $commands[] = ajax_command_html('#ajax_selected_lab', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_r', ''); + $commands[] = ajax_command_html('#ajax_selected_lab_pdf', ''); + $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']); + $commands[] = ajax_command_html('#ajax_selected_experiment', ''); + $commands[] = ajax_command_html('#ajax_download_experiments', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_solution_list_callback($form, $form_state) + { + $commands = array(); + $experiment_list_default_value = $form_state['values']['lab_experiment_list']; + //var_dump($lab_default_value); + if ($experiment_list_default_value != 0) + { + $form['lab_solution_list']['#options'] = _ajax_get_solution_list($experiment_list_default_value); + $commands[] = ajax_command_html('#ajax_download_experiments', l('Download Experiment', 'lab-migration/download/experiment/' . $experiment_list_default_value)); + $commands[] = ajax_command_html('#ajax_selected_experiment', drupal_render($form['lab_experiment_list'])); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + // $commands[] = ajax_command_html('#ajax_solution_files', ''); + // $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + } + else + { + $form['lab_solution_list']['#options'] = _ajax_get_solution_list(); + $commands[] = ajax_command_html('#ajax_selected_solution', drupal_render($form['lab_solution_list'])); + $commands[] = ajax_command_html('#ajax_download_experiments', ''); + $commands[] = ajax_command_html('#ajax_selected_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + // $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function ajax_solution_files_callback($form, $form_state) + { + $commands = array(); + $solution_list_default_value = $form_state['values']['lab_solution_list']; + //var_dump($lab_default_value); + if ($solution_list_default_value != 0) + { + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', drupal_render($form['lab_experiment_solution_actions'])); + /*************************************************************************************/ + //$solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['solution']); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_list_default_value); + $solution_list_q = $query->execute(); + if ($solution_list_q) + { + $solution_files_rows = array(); + while ($solution_list_data = $solution_list_q->fetchObject()) + { + $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']['solution']); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_list_default_value); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $solution_file_type = 'Dependency file'; + $solution_files_rows[] = array( + l($dependency_files_data->filename, 'lab-migration/download/dependency/' . $dependency_files_data->id), + $solution_file_type + ); + } + /* creating list of files table */ + $solution_files_header = array( + 'Filename', + 'Type' + ); + $solution_files = theme('table', array( + 'header' => $solution_files_header, + 'rows' => $solution_files_rows + )); + } + $form['solution_files']['#title'] = 'List of solution files'; + $form['solution_files']['#markup'] = $solution_files; + $commands[] = ajax_command_html('#ajax_download_experiment_solution', l('Download Solution', 'lab-migration/download/solution/' . $solution_list_default_value)); + // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', l('Edit Solution', 'code_approval/editcode/' . $solution_list_default_value)); + // $commands[] = ajax_command_html('#ajax_solution_files', $solution_files); + $commands[] = ajax_command_html('#ajax_solution_files', drupal_render($form['solution_files'])); + } + else + { + $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action', ''); + $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); + $commands[] = ajax_command_html('#ajax_solution_files', ''); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); + } +function bootstrap_table_format($headers, $rows) + { + $thead = ""; + $tbody = ""; + foreach ($headers as $header) + { + $thead .= "{$header}"; + } + foreach ($rows as $row) + { + $tbody .= ""; + foreach ($row as $data) + { + $tbody .= "{$data}"; + } + $tbody .= ""; + } + $table = " + + {$thead} + {$tbody} +
+ "; + return $table; + } +/*****************************************************/ +function _list_of_labs() + { + $lab_titles = array( + '0' => 'Please select...' + ); + //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_display', 1); + $query->condition('approval_status', 3); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + while ($lab_titles_data = $lab_titles_q->fetchObject()) + { + $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name_title .' '.$lab_titles_data->name . ')'; + } + return $lab_titles; + } +function _ajax_get_experiment_list($lab_default_value = '') + { + $experiments = array( + '0' => 'Please select...' + ); + //$experiments_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $lab_default_value); + $query->orderBy('number', 'ASC'); + $experiments_q = $query->execute(); + while ($experiments_data = $experiments_q->fetchObject()) + { + $experiments[$experiments_data->id] = $experiments_data->number . '. ' . $experiments_data->title; + } + return $experiments; + } +function _ajax_get_solution_list($lab_experiment_list = '') + { + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $lab_experiment_list); + //$query->orderBy("CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED", "ASC"); + // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED", "ASC"); + $solutions_q = $query->execute(); + while ($solutions_data = $solutions_q->fetchObject()) + { + $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); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $query->condition('approval_status', 3); + $lab_q = $query->execute(); + $lab_data = $lab_q->fetchObject(); + if($lab_data){ + return $lab_data; + } + else + { + return ; + } + + } +function _lab_details($lab_default_value) + { + //$lab_default_value = $form_state['values']['lab']; + $lab_details = _lab_information($lab_default_value); + if ($lab_default_value != 0) + { + if ($lab_details){ + if ($lab_details->solution_provider_uid > 0) + { + $user_solution_provider = user_load($lab_details->solution_provider_uid); + if ($user_solution_provider) + { + $solution_provider = 'Solution Provider
' . ''; + } + else + { + $solution_provider = 'Solution Provider
' . ''; + } + } + else + { + $solution_provider = 'Solution Provider
' . ''; + }} + else{ + drupal_goto('lab-migration/lab-migration-run'); + + } + $form['lab_details']['#markup'] = 'About the Lab
' . '' . $solution_provider; + $details = $form['lab_details']['#markup']; + return $details; + } + } diff --git a/settings.inc b/settings.inc new file mode 100755 index 0000000..1856a25 --- /dev/null +++ b/settings.inc @@ -0,0 +1,98 @@ + 'textfield', + '#title' => t('(Bcc) Notification emails'), + '#description' => t('Specify emails id for Bcc option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_emails', '') + ); + $form['cc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(Cc) Notification emails'), + '#description' => t('Specify emails id for Cc option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_cc_emails', '') + ); + $form['from_email'] = array( + '#type' => 'textfield', + '#title' => t('Outgoing from email address'), + '#description' => t('Email address to be display in the from field of all outgoing messages'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_from_email', '') + ); + $form['extensions']['source'] = array( + '#type' => 'textfield', + '#title' => t('Allowed source file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_source_extensions', '') + ); + $form['extensions']['dependency'] = array( + '#type' => 'textfield', + '#title' => t('Allowed dependency file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of dependency file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_dependency_extensions', '') + ); + $form['extensions']['result'] = array( + '#type' => 'textfield', + '#title' => t('Allowed result file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of result file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_result_extensions', '') + ); + $form['extensions']['xcos'] = array( + '#type' => 'textfield', + '#title' => t('Allowed xcos file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of xcos file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_xcos_extensions', '') + ); + $form['extensions']['pdf'] = array( + '#type' => 'textfield', + '#title' => t('Allowed pdf file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('lab_migration_pdf_extensions', '') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + return $form; + } +function lab_migration_settings_form_validate($form, &$form_state) + { + return; + } +function lab_migration_settings_form_submit($form, &$form_state) + { + variable_set('lab_migration_emails', $form_state['values']['emails']); + variable_set('lab_migration_cc_emails', $form_state['values']['cc_emails']); + variable_set('lab_migration_from_email', $form_state['values']['from_email']); + variable_set('lab_migration_source_extensions', $form_state['values']['source']); + variable_set('lab_migration_dependency_extensions', $form_state['values']['dependency']); + variable_set('lab_migration_result_extensions', $form_state['values']['result']); + variable_set('lab_migration_xcos_extensions', $form_state['values']['xcos']); + variable_set('lab_migration_pdf_extensions', $form_state['values']['pdf']); + drupal_set_message(t('Settings updated'), 'status'); + } diff --git a/solution_proposal.inc b/solution_proposal.inc new file mode 100755 index 0000000..da3c093 --- /dev/null +++ b/solution_proposal.inc @@ -0,0 +1,392 @@ +fields('lab_migration_proposal'); + $query->condition('approval_status', 1); + $query->condition('solution_provider_uid', 0); + $proposal_q = $query->execute(); + $proposal_q_count = $proposal_q->rowCount(); + if ($proposal_q_count != 0) + { + while ($proposal_data = $proposal_q->fetchObject()) + { + $proposal_rows[] = array( + l($proposal_data->lab_title, 'lab-migration/show-proposal/' . $proposal_data->id), + l('Apply', 'lab-migration/show-proposal/' . $proposal_data->id) + ); + } + $proposal_header = array( + 'Title of the Lab', + 'Actions' + ); + $return_html = theme('table', array( + 'header' => $proposal_header, + 'rows' => $proposal_rows + )); + + + } + else +{ + +$return_html = 'No proposals are available'; +} +return $return_html; + } +function lab_migration_solution_proposal_form($form, $form_state) + { + global $user; + $proposal_id = (int) arg(2); + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Invalid proposal.", 'error'); + drupal_goto(''); + } + //var_dump($proposal_data->name); die; + $form['name'] = array( + '#type' => 'item', + '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), + '#title' => t('Proposer Name') + ); + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab') + ); + $experiment_html = ''; + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_id); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + $experiment_html .= $experiment_data->title . "
"; + } + $form['experiment'] = array( + '#type' => 'item', + '#markup' => $experiment_html, + '#title' => t('Experiment List') + ); + $form['solution_provider_name_title'] = array( + '#type' => 'select', + '#title' => t('Title'), + '#options' => array( + 'Mr' => 'Mr', + 'Ms' => 'Ms', + 'Mrs' => 'Mrs', + 'Dr' => 'Dr', + 'Prof' => 'Prof' + ), + '#required' => TRUE + ); + $form['solution_provider_name'] = array( + '#type' => 'textfield', + '#title' => t('Name of the Solution Provider'), + '#size' => 30, + '#maxlength' => 50, + '#required' => TRUE + ); + $form['solution_provider_email_id'] = array( + '#type' => 'textfield', + '#title' => t('Email'), + '#size' => 30, + '#value' => $user->mail, + '#disabled' => TRUE + ); + $form['solution_provider_contact_ph'] = array( + '#type' => 'textfield', + '#title' => t('Contact No.'), + '#size' => 30, + '#maxlength' => 15, + '#required' => TRUE + ); + $form['solution_provider_department'] = array( + '#type' => 'select', + '#title' => t('Department/Branch'), + '#options' => _list_of_departments(), + '#required' => TRUE + ); + $form['solution_provider_university'] = array( + '#type' => 'textfield', + '#title' => t('University/Institute'), + '#size' => 30, + '#maxlength' => 50, + '#required' => TRUE + ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others' + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your country name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your state/region name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' => array( + 'placeholder' => t('Enter your city name') + ), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'Others' + ) + ) + ) + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _lm_list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _lm_list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array( + 'value' => 'India' + ) + ) + ) + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' => array( + 'placeholder' => 'Enter pincode....' + ) + ); + $form['version'] = array( + '#type' => 'select', + '#title' => t('Version'), + '#options' => _list_of_software_version(), + '#required' => TRUE + ); + $form['older'] = array( + '#type' => 'textfield', + '#size' => 30, + '#maxlength' => 50, + //'#required' => TRUE, + '#description' => t('Specify the Older version used'), + '#states' => array( + 'visible' => array( + ':input[name="version"]' => array( + 'value' => 'olderversion' + ) + ) + ) + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Apply for Solution') + ); + return $form; + } +function lab_migration_solution_proposal_form_validate($form, &$form_state) + { + global $user; + if ($form_state['values']['country'] == 'Others') + { + if ($form_state['values']['other_country'] == '') + { + form_set_error('other_country', t('Enter country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['other_state'] == '') + { + form_set_error('other_state', t('Enter state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if ($form_state['values']['other_city'] == '') + { + form_set_error('other_city', t('Enter city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + else + { + $form_state['values']['city'] = $form_state['values']['other_city']; + } + } + else + { + if ($form_state['values']['country'] == '') + { + form_set_error('country', t('Select country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['all_state'] == '') + { + form_set_error('all_state', t('Select state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if ($form_state['values']['city'] == '') + { + form_set_error('city', t('Select city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + } + + if ($form_state['values']['version'] == 'olderversion') + { + if ($form_state['values']['older'] == '') + { + form_set_error('older', t('Please provide valid version')); + } + } + return; + //$solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = ".$user->uid." AND approval_status IN (0, 1) AND solution_status IN (0, 1, 2)"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('solution_provider_uid', $user->uid); + $query->condition('approval_status', array( + 0, + 1 + ), 'IN'); + $query->condition('solution_status', array( + 0, + 1, + 2 + ), 'IN'); + $solution_provider_q = $query->execute(); + if ($solution_provider_q->fetchObject()) + { + 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'); + } + } +function lab_migration_solution_proposal_form_submit($form, &$form_state) + { + global $user; + $proposal_id = (int) arg(2); + if ($form_state['values']['version'] == 'olderversion') + { + $form_state['values']['version'] = $form_state['values']['older']; + } + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $proposal_id); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message("Invalid proposal.", 'error'); + drupal_goto('lab-migration/open-proposal'); + } + if ($proposal_data->solution_provider_uid != 0) + { + drupal_set_message("Someone has already applied for solving this Lab.", 'error'); + drupal_goto('lab-migration/open-proposal'); + } + $query = "UPDATE {lab_migration_proposal} set solution_provider_uid = :uid, solution_status = 1, solution_provider_name_title = :solution_provider_name_title, solution_provider_name = :solution_provider_contact_name, solution_provider_contact_ph = :solution_provider_contact_ph, solution_provider_department = :solution_provider_department, solution_provider_university = :solution_provider_university , solution_provider_city = :solution_provider_city, solution_provider_pincode = :solution_provider_pincode, solution_provider_state = :solution_provider_state,solution_provider_country = :solution_provider_country, version = :version WHERE id = :proposal_id"; + $args = array( + ":uid" => $user->uid, + ":solution_provider_name_title" => $form_state['values']['solution_provider_name_title'], + ":solution_provider_contact_name" => $form_state['values']['solution_provider_name'], + ":solution_provider_contact_ph" => $form_state['values']['solution_provider_contact_ph'], + ":solution_provider_department" => $form_state['values']['solution_provider_department'], + ":solution_provider_university" => $form_state['values']['solution_provider_university'], + ":solution_provider_city" => $form_state['values']['city'], + ":solution_provider_pincode" => $form_state['values']['pincode'], + ":solution_provider_state" => $form_state['values']['all_state'], + ":solution_provider_country" => $form_state['values']['country'], + ":version" => $form_state['values']['version'], + + ":proposal_id" => $proposal_id + ); + + $result = db_query($query, $args); + drupal_set_message("We have received your application. We will get back to you soon.", 'status'); + /* sending email */ + $email_to = $user->mail; + $from = variable_get('lab_migration_from_email', ''); + $bcc = variable_get('lab_migration_emails', ''); + $cc = variable_get('lab_migration_cc_emails', ''); + $param['solution_proposal_received']['proposal_id'] = $proposal_id; + $param['solution_proposal_received']['user_id'] = $user->uid; + $param['solution_proposal_received']['headers'] = array( + 'From' => $from, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal', + 'Cc' => $cc, + 'Bcc' => $bcc + ); + if (!drupal_mail('lab_migration', 'solution_proposal_received', $email_to, language_default(), $param, $from, TRUE)) + drupal_set_message('Error sending email message.', 'error'); + /* sending email */ + /* $email_to = variable_get('lab_migration_emails', ''); + if (!drupal_mail('lab_migration', 'solution_proposal_received', $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/open-proposal'); + } diff --git a/upload_code.inc b/upload_code.inc new file mode 100755 index 0000000..883c266 --- /dev/null +++ b/upload_code.inc @@ -0,0 +1,665 @@ +Title of the Lab:
' . $proposal_data->lab_title . '

'; + $return_html .= 'Proposer Name:
' . $proposal_data->name_title . ' ' . $proposal_data->name . '

'; + $return_html .= l('Upload Solution', 'lab-migration/code/upload') . '
'; + + /* get experiment list */ + $experiment_rows = array(); + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_data->id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $query->orderBy('number', 'ASC'); + $experiment_q = $query->execute(); + +//var_dump($experiment_q->fetchObject()); +//die; + + while ($experiment_data = $experiment_q->fetchObject()) + { + + + $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); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_data->id); + $query->orderBy('id', 'ASC'); + $solution_q = $query->execute(); + if ($solution_q) { + while ($solution_data = $solution_q->fetchObject()) { + $solution_status = ''; + switch ($solution_data->approval_status) { + case 0: $solution_status = "Pending"; break; + 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, ''); + } + /* 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); + $query = db_select('lab_migration_solution_files'); + $query->fields('lab_migration_solution_files'); + $query->condition('solution_id', $solution_data->id); + $query->orderBy('id', 'ASC'); + $solution_files_q = $query->execute(); + + if ($solution_files_q) { + while ($solution_files_data = $solution_files_q->fetchObject()) { + $code_file_type = ''; + switch ($solution_files_data->filetype) { + case 'S': $code_file_type = 'Source'; break; + case 'R': $code_file_type = 'Result'; break; + case 'X': $code_file_type = 'Xcox'; break; + 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, '', ''); + } + } + /* get dependencies files */ + //$dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d ORDER BY id ASC", $solution_data->id); + $query = db_select('lab_migration_solution_dependency'); + $query->fields('lab_migration_solution_dependency'); + $query->condition('solution_id', $solution_data->id); + $query->orderBy('id', 'ASC'); + $dependency_q = $query->execute(); + while ($dependency_data = $dependency_q->fetchObject()) + { + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->condition('id', $dependency_data->dependency_id); + $dependency_files_q = $query->execute(); + $dependency_files_data = $dependency_files_q->fetchObject(); + $experiment_rows[] = array("                  " . l($dependency_files_data->filename, 'lab-migration/download/dependency/' . $dependency_files_data->id), 'Dependency', '', ''); + } + } + } + } + + $experiment_header = array('No. Title of the Experiment', 'Type', 'Status', 'Actions'); + // $return_html .= theme_table($experiment_header, $experiment_rows); + + $return_html .= theme('table', array('header' => $experiment_header, 'rows' => $experiment_rows)); + return $return_html; +} + +function lab_migration_upload_code_form($form,$form_state) +{ + + global $user; + + $proposal_data = lab_migration_get_proposal(); + if (!$proposal_data) { + drupal_goto(''); + return; + } + + /* add javascript for dependency selection effects */ + $dep_selection_js = "(function ($) { + //alert('ok'); + $('#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(); + consloe.log(activeClass); + if ($(this).children().hasClass(activeClass)) { + $(this).show(); + } + if ($(this).children().attr('checked') == true) { + dep_selected += $(this).children().next().text() + '
'; + } + }); + /* 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'); + }(jQuery));"; + drupal_add_js($dep_selection_js, 'inline', 'header'); + + $form['#attributes'] = array('enctype' => "multipart/form-data"); + + $form['lab_title'] = array( + '#type' => 'item', + '#markup' => $proposal_data->lab_title, + '#title' => t('Title of the Lab'), + ); + $form['name'] = array( + '#type' => 'item', + '#markup' => $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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $proposal_data->id); + $query->orderBy('id', 'ASC'); + $experiment_q = $query->execute(); + while ($experiment_data = $experiment_q->fetchObject()) + { + $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['os_used'] = array( + '#type' => 'select', + '#title' => t('Operating System used'), + '#options' => array( + 'Linux' => 'Linux', + 'Windows' => 'Windows', + 'Mac' => 'Mac' + ), + '#required' => TRUE, + ); + $form['r_version'] = array( + '#type' => 'select', + '#title' => t('r version used'), + '#options' => _lm_list_of_software_version(), + '#required' => TRUE, + ); + $form['toolbox_used'] = array( + '#type' => 'hidden', + '#title' => t('Toolbox used (If any)'), +'#default_value'=>'none', + ); + $form['code_warning'] = array( + '#type' => 'item', + '#title' => t('Upload all the r project files in .zip format'), + '#prefix' => '
', + '#suffix' => '
', + ); + $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('Only alphabets and numbers are allowed as a valid filename.') . '
' . + 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' => '
', + '#suffix' => '
', + '#tree' => TRUE, + ); + + /* existing dependencies */ +/* $form['existing_depfile']['selected'] = array( + '#type' => 'item', + '#title' => t('Existing Dependency Files Selected'), + '#markup' => '
', + ); + +/* $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', + '#markup' => 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.') . '
' . + 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.') . '
' . + 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.') . '
' . + 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.') . '
' . + 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 lab_migration_upload_code_form_validate($form, &$form_state) +{ + if (!lab_migration_check_code_number($form_state['values']['code_number'])) + form_set_error('code_number', t('Invalid Code Number. Code Number can contain only numbers.')); + + if (!lab_migration_check_name($form_state['values']['code_caption'])) + form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.')); + + if(!$form_state['values']['os_used']) + form_set_error('os_used', t('Please select the operating system used.')); + + if(!$form_state['values']['r_version']) + form_set_error('r_version', t('Please select the r version used.')); + + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if ( ! ($_FILES['files']['name']['sourcefile1'] )) + form_set_error('sourcefile1', t('Please upload atleast one main or source 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); + $tmp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name])); + $temp_extension = end($tmp_ext); + 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 = " (function ($) { + + $('#edit-existing-depfile-dep-lab-title').change(function() { + console.log('ok'); + 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() + '
'; + } + }); + /* 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'); + })(jQuery);"; +drupal_add_js($dep_selection_js, 'inline', 'header'); + + // drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline'); + // drupal_static_reset('drupal_add_js') ; +} + +function lab_migration_upload_code_form_submit($form, &$form_state) { + global $user; + + $root_path = lab_migration_path(); + + $proposal_data = lab_migration_get_proposal(); + if (!$proposal_data) { + drupal_goto(''); + return; + } + + $proposal_id = $proposal_data->id; + $proposal_drectory = $proposal_data->directory_name; + + /************************ 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); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $experiment_id); + $query->condition('proposal_id', $proposal_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + $experiment_data = $experiment_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message("Invalid experiment seleted", 'error'); + drupal_goto('lab-migration/code'); + } + + /* create proposal folder if not present */ + $dest_path = $proposal_drectory . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + + /* get solution details - dont allow if already solution present */ + $code_number = $experiment_data->number . '.' . $form_state['values']['code_number']; + + //$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']); + $query = db_select('lab_migration_solution'); + $query->fields('lab_migration_solution'); + $query->condition('experiment_id', $experiment_id); + $query->condition('code_number', $code_number); + $cur_solution_q = $query->execute(); + if ($cur_solution_d = $cur_solution_q->fetchObject()) + { + 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 file path */ + $file_path = 'EXP' . $experiment_data->number . '/' . 'CODE' . $experiment_data->number . '.' . $form_state['values']['code_number'] . '/'; + /* creating solution database entry */ + $query = "INSERT INTO {lab_migration_solution} (experiment_id, approver_uid, code_number, caption, approval_date, approval_status, timestamp, os_used, r_version, toolbox_used) VALUES (:experiment_id, :approver_uid, :code_number, :caption, :approval_date, :approval_status, :timestamp, :os_used, :r_version, :toolbox_used)"; + $args = array( + ":experiment_id" => $experiment_id, + ":approver_uid" => 0, + ":code_number" => $experiment_data->number . '.' . $form_state['values']['code_number'], + ":caption" => $form_state['values']['code_caption'], + ":approval_date" => 0, + ":approval_status" => 0, + ":timestamp" => time(), + ":os_used" => $form_state['values']['os_used'], + ":r_version" => $form_state['values']['r_version'], + ":toolbox_used" => $form_state['values']['toolbox_used'] + ); + $solution_id = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); +//var_dump('solution id= '.$solution_id. '&&& dep file = '.array_filter($form_state['values']['existing_depfile']['dep_experiment_files'])); + +//die; + /* linking existing dependencies */ + /* foreach ($form_state['values']['existing_depfile']['dep_experiment_files'] as $row) + { + if ($row > 0) + {*/ + /* insterting into database */ + /* $query = "INSERT INTO {lab_migration_solution_dependency} (solution_id, dependency_id) + VALUES (:solution_id, :dependency_id)"; + $args = array( + ":solution_id" => $solution_id, + ":dependency_id" => $row + ); + db_query( $query,$args); + } + }*/ + + /* 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 */ + $query = "INSERT INTO {lab_migration_solution_files} (solution_id, filename, filepath, filemime, filesize, filetype, timestamp) + VALUES (:solution_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)"; + $args = array( + ":solution_id" => $solution_id, + ":filename" => $_FILES['files']['name'][$file_form_name], + ":filepath" => $file_path . $_FILES['files']['name'][$file_form_name], + ":filemime" => 'application/dwxml', + ":filesize" => $_FILES['files']['size'][$file_form_name], + ":filetype" => $file_type, + ":timestamp" => time() + ); + db_query($query,$args); + 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; + + $from = variable_get('lab_migration_from_email', ''); + $bcc= variable_get('lab_migration_emails', ''); + $cc=variable_get('lab_migration_cc_emails', ''); + $param['solution_uploaded']['solution_id'] = $solution_id; + $param['solution_uploaded']['user_id'] = $user->uid; + $param['solution_uploaded']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('lab_migration', 'solution_uploaded', $email_to, language_default(), $param, $from, 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"); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + + $or = db_or(); + $or->condition('approval_status', 1); + $or->condition('approval_status', 3); + $query->condition($or); + $query->orderBy('lab_title', 'ASC'); + $lab_titles_q = $query->execute(); + + while ($lab_titles_data = $lab_titles_q->fetchObject()) + { + $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() +{ +// $dependancy_proposal_id = $form_state['values']['existing_depfile']['dep_lab_title']; +//var_dump($dependancy_proposal_id); + $dependency_files = array(); + $dependency_files_class = array(); + //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE proposal_id = %d ORDER BY filename ASC", $dependancy_proposal_id); + $query = db_select('lab_migration_dependency_files'); + $query->fields('lab_migration_dependency_files'); + $query->orderBy('filename', 'ASC'); + // $query->condition('proposal_id',$dependancy_proposal_id); + $dependency_files_q = $query->execute(); + + while ($dependency_files_data = $dependency_files_q->fetchObject()) + { + $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, array('attributes' => array('class' => $dependency_files_data->proposal_id))); + $dependency_files_class[$dependency_files_data->id] = $dependency_files_data->proposal_id; + $dependency_files_value[$dependency_files_data->id] = $dependency_files_data->proposal_id; + } + return array($dependency_files, $dependency_files_class, $dependency_files_value); +} +function _lm_list_of_software_version() + { + $software_version = array(); + $query = db_select('r_software_version'); + $query->fields('r_software_version'); + $query->orderBy('id', 'ASC'); + $software_version_list = $query->execute(); + while ($software_version_list_data = $software_version_list->fetchObject()) + { + $software_version[$software_version_list_data->r_version] = $software_version_list_data->r_version; + } + return $software_version; + } + diff --git a/upload_code_delete.inc b/upload_code_delete.inc new file mode 100755 index 0000000..0c63e5f --- /dev/null +++ b/upload_code_delete.inc @@ -0,0 +1,95 @@ +fields('lab_migration_solution'); + $query->condition('id', $solution_id); + $query->range(0, 1); + $solution_q = $query->execute(); + $solution_data = $solution_q->fetchObject(); + if (!$solution_data) + { + drupal_set_message('Invalid solution.', 'error'); + drupal_goto('lab-migration/code'); + return; + } + if ($solution_data->approval_status != 0) + { + drupal_set_message('You cannnot delete a solution after it has been approved. Please contact site administrator if you want to delete this solution.', 'error'); + drupal_goto('lab-migration/code'); + return; + } + + //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d LIMIT 1", $solution_data->experiment_id); + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('id', $solution_data->experiment_id); + $query->range(0, 1); + $experiment_q = $query->execute(); + + $experiment_data = $experiment_q->fetchObject(); + if (!$experiment_data) + { + drupal_set_message('You do not have permission to delete this solution.', 'error'); + drupal_goto('lab-migration/code'); + return; + } + + //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d AND solution_provider_uid = %d LIMIT 1", $experiment_data->proposal_id, $user->uid); + $query = db_select('lab_migration_proposal'); + $query->fields('lab_migration_proposal'); + $query->condition('id', $experiment_data->proposal_id); + $query->condition('solution_provider_uid', $user->uid); + $query->range(0, 1); + $proposal_q = $query->execute(); + $proposal_data = $proposal_q->fetchObject(); + if (!$proposal_data) + { + drupal_set_message('You do not have permission to delete this solution.', 'error'); + drupal_goto('lab-migration/code'); + return; + } + + /* deleting solution files */ + if (lab_migration_delete_solution($solution_data->id)) + { + drupal_set_message('Solution deleted.', 'status'); + + /* sending email */ + $email_to = $user->mail; + + $from = variable_get('lab_migration_from_email', ''); + $bcc= variable_get('lab_migration_emails', ''); + $cc=variable_get('lab_migration_cc_emails', ''); + + $param['solution_deleted_user']['lab_title'] = $proposal_data->lab_title; + $param['solution_deleted_user']['experiment_title'] = $experiment_data->title; + $param['solution_deleted_user']['solution_number'] = $solution_data->code_number; + $param['solution_deleted_user']['solution_caption'] = $solution_data->caption; + $param['solution_deleted_user']['user_id'] = $user->uid; + $param['solution_deleted_user']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('lab_migration', 'solution_deleted_user', $email_to, language_default(), $param , $from , TRUE)) + drupal_set_message('Error sending email message.', 'error'); + } else { + drupal_set_message('Error deleting example.', 'status'); + } + + drupal_goto('lab-migration/code'); + return; +} -- cgit