diff options
author | prashant | 2015-11-04 17:59:59 +0530 |
---|---|---|
committer | prashant | 2015-11-04 18:05:53 +0530 |
commit | cf4aee0e5675851843062a070ed67b3194ddd7cf (patch) | |
tree | c9ea024ffa13b774dd2e32b14f205ef634882eac | |
parent | f0bb83fe2c52a1fe25e1ed0068eca96037bed785 (diff) | |
download | DWSIM_lab_migration-cf4aee0e5675851843062a070ed67b3194ddd7cf.tar.gz DWSIM_lab_migration-cf4aee0e5675851843062a070ed67b3194ddd7cf.tar.bz2 DWSIM_lab_migration-cf4aee0e5675851843062a070ed67b3194ddd7cf.zip |
changes done in mail function and formated code
-rwxr-xr-x | bulk_approval.inc | 790 | ||||
-rwxr-xr-x | bulk_upload_code.inc | 855 |
2 files changed, 980 insertions, 665 deletions
diff --git a/bulk_approval.inc b/bulk_approval.inc index 36910d8..f5a1ff0 100755 --- a/bulk_approval.inc +++ b/bulk_approval.inc @@ -1,13 +1,10 @@ <?php function lab_migration_bulk_approval_form($form, &$form_state) -{ + { $options_first = _bulk_list_of_labs(); $options_two = _ajax_bulk_get_experiment_list(); $selected = isset($form_state['values']['lab']) ? $form_state['values']['lab'] : key($options_first); $select_two = isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : key($options_two); - $action_first = _bulk_list_lab_actions(); - $action_two = _bulk_list_experiment_actions(); - $selected_action = isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : key($action_first); $form = array(); $form['lab'] = array( '#type' => 'select', @@ -21,7 +18,7 @@ function lab_migration_bulk_approval_form($form, &$form_state) ); $form['lab_actions'] = array( '#type' => 'select', - '#title' => t('Please select action for lab'), + '#title' => t('Please select action for Entire Lab'), '#options' => _bulk_list_lab_actions(), '#default_value' => 0, '#prefix' => '<div id="ajax_selected_lab_action" style="color:red;">', @@ -58,15 +55,26 @@ function lab_migration_bulk_approval_form($form, &$form_state) ); $form['lab_experiment_actions'] = array( '#type' => 'select', - '#title' => t('Please select action for lab experiment'), + '#title' => t('Please select action for Entire Experiment'), '#options' => _bulk_list_experiment_actions(), '#default_value' => 0, '#prefix' => '<div id="ajax_selected_lab_experiment_action" style="color:red;">', '#suffix' => '</div>', + //'#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0),),), '#states' => array( 'invisible' => array( - ':input[name="lab"]' => array( - 'value' => 0 + array( + array( + ':input[name="lab"]' => array( + 'value' => 0 + ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 0 + ) + ) ) ) ) @@ -114,7 +122,7 @@ function lab_migration_bulk_approval_form($form, &$form_state) ); $form['solution_files'] = array( '#type' => 'item', - // '#title' => t('List of solution files'), + //'#title' => t('List of solution_files'), '#markup' => '<div id="ajax_solution_files"></div>', '#states' => array( 'invisible' => array( @@ -147,14 +155,19 @@ function lab_migration_bulk_approval_form($form, &$form_state) ':input[name="lab_experiment_solution_actions"]' => array( 'value' => 3 ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 4 + ) ) ) ), - 'or', 'required' => array( array( array( - ':input[name="book_actions"]' => array( + ':input[name="lab_actions"]' => array( 'value' => 3 ) ), @@ -169,6 +182,12 @@ function lab_migration_bulk_approval_form($form, &$form_state) ':input[name="lab_experiment_solution_actions"]' => array( 'value' => 3 ) + ), + 'or', + array( + ':input[name="lab_actions"]' => array( + 'value' => 4 + ) ) ) ) @@ -187,17 +206,19 @@ function lab_migration_bulk_approval_form($form, &$form_state) ) ); 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) { + 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)')); */ + /*$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']); @@ -209,7 +230,9 @@ function ajax_bulk_experiment_list_callback($form, $form_state) $commands[] = ajax_command_html('#ajax_solution_files', ''); $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); - } else { + } + 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']); @@ -221,18 +244,19 @@ function ajax_bulk_experiment_list_callback($form, $form_state) $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) { + 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/download/experiment/' . $experiment_list_default_value)); @@ -244,7 +268,9 @@ function ajax_bulk_solution_list_callback($form, $form_state) $commands[] = ajax_command_html('#ajax_solution_files', ''); $commands[] = ajax_command_html('#ajax_download_experiment_solution', ''); $commands[] = ajax_command_html('#ajax_edit_experiment_solution', ''); - } else { + } + else + { $commands[] = ajax_command_html('#ajax_download_experiment', ''); $commands[] = ajax_command_html('#ajax_selected_lab_experiment_action', ''); $commands[] = ajax_command_html('#ajax_selected_solution', ''); @@ -253,18 +279,19 @@ function ajax_bulk_solution_list_callback($form, $form_state) $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) { + 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'])); /*************************************************************************************/ @@ -273,11 +300,14 @@ function ajax_bulk_solution_files_callback($form, $form_state) $query->fields('lab_migration_solution_files'); $query->condition('solution_id', $solution_list_default_value); $solution_list_q = $query->execute(); - if ($solution_list_q) { + if ($solution_list_q) + { $solution_files_rows = array(); - while ($solution_list_data = $solution_list_q->fetchObject()) { + while ($solution_list_data = $solution_list_q->fetchObject()) + { $solution_file_type = ''; - switch ($solution_list_data->filetype) { + switch ($solution_list_data->filetype) + { case 'S': $solution_file_type = 'Source or Main file'; break; @@ -295,14 +325,23 @@ function ajax_bulk_solution_files_callback($form, $form_state) 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()) { + 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'); @@ -314,7 +353,7 @@ function ajax_bulk_solution_files_callback($form, $form_state) 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', @@ -324,147 +363,235 @@ function ajax_bulk_solution_files_callback($form, $form_state) '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_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 { + } + 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) -{ - // In most cases, it is recomended that you put this logic in form generation - // rather than the callback. Submit driven forms are an exception, because - // you may not want to return the form at all. + } +/************************************************************/ +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']) { + 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)) { + 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(); - while ($experiment_data = $experiment_q->fetchObject()) { + $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 .= '<p>' . $experiment_data->number . ') ' . $experiment_data->title . '<br> Description : ' . $experiment_data->description . '<br>'; + $experiment_list .= ' '; + $experiment_list .= '</p>'; + } 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('Your all the uploaded solutions for the Lab have been approved.') + 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)) { + } + 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()) { + 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('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.') + 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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 3) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) { - if (!$form_state['values']['message']) { - if (strlen(trim($form_state['values']['message'])) <= 30) { - form_set_error('message', t('')); - drupal_set_message("Please mention the reason for disapproval.", 'error'); - return; - } - } - if (!user_access('lab migration bulk delete code')) { + /* 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'])) { + } + if (lab_migration_delete_lab($form_state['values']['lab'])) + { drupal_set_message(t('Dis-Approved and Deleted Entire Lab.'), 'status'); - } else { + } + 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('Your all the uploaded solutions for the whole Lab have been marked as dis-approved. + 0 => t(' - Reason for dis-approval: +Dear !user_name, - ' . $form_state['values']['message']) +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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 4) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) { - if (!$form_state['values']['message']) { - if (strlen(trim($form_state['values']['message'])) <= 30) { - form_set_error('message', t('')); - drupal_set_message("Please mention the reason for disapproval.", 'error'); - return; - } - } - if (!user_access('lab migration bulk delete code')) { + /* 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 .= '<p>' . $experiment_data->number . ') ' . $experiment_data->title . '<br> Description : ' . $experiment_data->description . '<br>'; + $experiment_list .= ' '; + $experiment_list .= '</p>'; + } + 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()) { + 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'])) { + } + if (lab_migration_delete_lab($form_state['values']['lab'])) + { drupal_set_message(t('Dis-Approved and Deleted Entire Lab solutions.'), 'status'); - $dir_path = $root_path . $form_state['values']['lab']; - if (is_dir($dir_path)) { + $query = db_select('lab_migration_experiment'); + $query->fields('lab_migration_experiment'); + $query->condition('proposal_id', $form_state['values']['lab']); + $experiment_q = $query->execute()->fetchObject(); + $dir_path = $root_path . $experiment_q->directory_name; + if (is_dir($dir_path)) + { $res = rmdir($dir_path); - if (!$res) { + if (!$res) + { drupal_set_message(t("Cannot delete Lab directory : " . $dir_path . ". Please contact administrator."), 'error'); return; - } - } else { + } + } + 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( @@ -484,68 +611,208 @@ function lab_migration_bulk_approval_form_submit($form, $form_state) '!site_name' => variable_get('site_name', '') )); $email_body = array( - 0 => t('Your all the uploaded solutions including the Lab proposal have been deleted permanently.') + 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 + )) ); - } else { + /* 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)) { + } + } + 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 solutions have been approved', array( + $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('Your all the uploaded solutions for the experiment have been approved.') + 0 => t(' + +Dear !user_name, + +Your Experiment for DWSIM 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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 2) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) { + /* 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 solutions have been marked as pending', array( + $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('Your all the uploaded solutions for the experiment have been marked as pending to be review.') + 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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 3) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) { - if (!$form_state['values']['message']) { - if (strlen(trim($form_state['values']['message'])) <= 30) { - form_set_error('message', t('')); - drupal_set_message("Please mention the reason for disapproval.", 'error'); - return; - } - } - if (!user_access('lab migration bulk delete code')) { + /* 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; - } - if (lab_migration_delete_experiment($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(); + if (lab_migration_delete_experiment($form_state['values']['lab_experiment_list'])) + { drupal_set_message(t('Dis-Approved and Deleted Entire Experiment.'), 'status'); - } else { + } + 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('Your uploaded solutions for the entire experiment have been marked as dis-approved. + 0 => t(' + +Dear !user_name, + +We regret to inform you that your experiment with the following details under DWSIM Lab Migration is disapproved and has been deleted. - Reason for dis-approval: +Experiment name : ' . $experiment_value->title . ' +Caption : ' . $solution_value->caption . ' - ' . $form_state['values']['message']) +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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 1)) { + /* 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']['solution'] + ":id" => $form_state['values']['lab_solution_list'] )); drupal_set_message(t('Solution approved.'), 'status'); /* email */ @@ -553,9 +820,41 @@ function lab_migration_bulk_approval_form_submit($form, $form_state) '!site_name' => variable_get('site_name', '') )); $email_body = array( - 0 => t('Your uploaded solution has been approved.') + 0 => t(' + +Dear !user_name, + +Your Experiment for DWSIM 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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 2)) { + /* 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'] )); @@ -565,119 +864,160 @@ function lab_migration_bulk_approval_form_submit($form, $form_state) '!site_name' => variable_get('site_name', '') )); $email_body = array( - 0 => t('Your uploaded solution has been marked as pending to be review.') + 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 + )) ); - } elseif (($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] == 3)) { - if (!$form_state['values']['message']) { - if (strlen(trim($form_state['values']['message'])) <= 30) { - form_set_error('message', t('')); - drupal_set_message("Please mention the reason for disapproval.", 'error'); - return; - } - } - if (lab_migration_delete_solution($form_state['values']['lab_solution_list'])) { + /* 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 { + } + 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('Your uploaded solution has been marked as dis-approved. + 0 => t(' + +Dear !user_name, + +We regret to inform you that your experiment with the following details under DWSIM 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'] . ' - Reason for dis-approval: +Please resubmit the modified solution. - ' . $form_state['values']['message']) +Best Wishes, + +!site_name Team, +FOSSEE,IIT Bombay', array( + '!site_name' => variable_get('site_name', ''), + '!user_name' => $user_data->name + )) ); - } else { - drupal_set_message("Please select any one action at a time", 'error'); + /* 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 (isset($email_subject)) { - $email_to = variable_get('lab_migration_emails', '') . ', ' . $user->mail; - // $email_to = "contact@scilab.in" . ', ' . $user->mail; - //$email_to = "prashantsinalkar@gmail.com"; + } + /** 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; - if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) + $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'); - }*/ - - /**** sending email when everything done ****/ - if ($email_subject) - { - $email_to = $user_data->mail; - $from = "contact-dwsim@fossee.in"; - // $email_to = "contact@scilab.in" . ', ' . $user->mail; - //$email_to = "prashantsinalkar@gmail.com"; - // $email_bcc= variable_get('lab_migration_emails', ''); - $email_bcc = 'diptiiitb17@gmail.com' ; - $email_cc="essarmax21@gmail.com"; - //$email_bcc=array('Bcc' => $header_bcc,'Cc' => $header_cc); - $param['standard']['subject'] = $email_subject; - $param['standard']['body'] = $email_body; - $param['standard']['headers'] = $email_bcc; - - - // if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - if (!send_mail($from, $email_to,$email_cc, $email_bcc, $email_subject, $email_body)) - drupal_set_message('Error sending email message.', 'error'); - } - } else { + } + } + } + else + { drupal_set_message(t('You do not have permission to bulk manage code.'), 'error'); - } - } + } + } return; -} - -function send_mail($from, $email_to,$email_cc, $email_bcc, $email_subject, $email_body) { - $my_module = 'lab_migration'; - $my_mail_token = microtime(); - $message = array( - 'id' => $my_module . '_' . $my_mail_token, - 'to' => $email_to, - 'subject' => $email_subject, - 'body' => $email_body, - 'headers' => array( - 'From' => $from, - 'Sender' => $from, - 'Return-Path' => $from, - 'Cc' => $email_cc, - 'Bcc' => $email_bcc, - ), - ); - $system = drupal_mail_system($my_module, $my_mail_token); - $message = $system->format($message); - if ($system->mail($message)) { - return TRUE; - } - else { - return FALSE; - } - } -/************************************************************/ + } +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('approval_status', 2, '<>'); $query->condition('solution_display', 1); $query->orderBy('lab_title', 'ASC'); $lab_titles_q = $query->execute(); - while ($lab_titles_data = $lab_titles_q->fetchObject()) { + 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...' ); @@ -687,24 +1027,25 @@ function _ajax_bulk_get_experiment_list($lab_default_value = '') $query->condition('proposal_id', $lab_default_value); $query->orderBy('number', 'ASC'); $experiments_q = $query->execute(); - while ($experiments_data = $experiments_q->fetchObject()) { + 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( - '' => 'Please Select .....' + 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...' ); @@ -719,28 +1060,29 @@ function _ajax_bulk_get_solution_list($lab_experiment_list = '') // $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()) { + 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( - '' => 'Please Select .....' + 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( - '' => 'Please Select .....' + 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; -} + } diff --git a/bulk_upload_code.inc b/bulk_upload_code.inc index d4776e9..884fb20 100755 --- a/bulk_upload_code.inc +++ b/bulk_upload_code.inc @@ -1,25 +1,22 @@ <?php // $Id$ - -function lab_migration_bulk_upload_code_form($form_state) -{ - global $user; - - $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) +function lab_migration_bulk_upload_code_form($form, $form_state) { - drupal_set_message("Invalid proposal selected", 'error'); - drupal_goto('lab_migration/code_approval/bulk'); - } - - /* add javascript for dependency selection effects */ - $dep_selection_js = "(function ($) { + global $user; + $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/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 */ @@ -42,238 +39,211 @@ function lab_migration_bulk_upload_code_form($form_state) }); $('#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; + 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' => '<div style="color:red">', + '#suffix' => '</div>' + ); + $form['sourcefile'] = array( + '#type' => 'fieldset', + '#title' => t('Main or Source Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['sourcefile']['sourcefile1'] = array( + '#type' => 'file', + '#title' => t('Upload main or source file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', '') + ); + $form['dep_files'] = array( + '#type' => 'item', + '#title' => t('Dependency Files') + ); + /************ START OF EXISTING DEPENDENCIES **************/ + /* existing dependencies */ + $form['existing_depfile'] = array( + '#type' => 'fieldset', + '#title' => t('Use Already Existing Dependency Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + '#prefix' => '<div id="existing-depfile-wrapper">', + '#suffix' => '</div>', + '#tree' => TRUE + ); + /* existing dependencies */ + $form['existing_depfile']['selected'] = array( + '#type' => 'item', + '#title' => t('Existing Dependency Files Selected'), + '#value' => '<div id="existing_depfile_selected"></div>' + ); + $form['existing_depfile']['dep_lab_title'] = array( + '#type' => 'select', + '#title' => t('Title of the Lab'), + '#options' => _list_of_lab_titles() + ); + list($files_options, $files_options_class) = _list_of_dependency_files(); + $form['existing_depfile']['dep_experiment_files'] = array( + '#type' => 'checkboxes', + '#title' => t('Dependency Files'), + '#options' => $files_options, + '#options_class' => $files_options_class, + '#multiple' => TRUE + ); + $form['existing_depfile']['dep_upload'] = array( + '#type' => 'item', + '#value' => l('Upload New Depedency Files', 'lab_migration/code/upload_dep') + ); + /************ END OF EXISTING DEPENDENCIES **************/ + $form['result'] = array( + '#type' => 'fieldset', + '#title' => t('Result Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['result']['result1'] = array( + '#type' => 'file', + '#title' => t('Upload result file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', '') + ); + $form['result']['result2'] = array( + '#type' => 'file', + '#title' => t('Upload result file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', '') + ); + $form['xcos'] = array( + '#type' => 'fieldset', + '#title' => t('XCOS Files'), + '#collapsible' => FALSE, + '#collapsed' => FALSE + ); + $form['xcos']['xcos1'] = array( + '#type' => 'file', + '#title' => t('Upload xcos file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', '') + ); + $form['xcos']['xcos2'] = array( + '#type' => 'file', + '#title' => t('Upload xcos file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', '') + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#type' => 'markup', + '#value' => l(t('Cancel'), 'lab_migration/code_approval/bulk') + ); + return $form; } - $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' => '<div style="color:red">', - '#suffix' => '</div>', - ); - - $form['sourcefile'] = array( - '#type' => 'fieldset', - '#title' => t('Main or Source Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['sourcefile']['sourcefile1'] = array( - '#type' => 'file', - '#title' => t('Upload main or source file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', ''), - ); - - $form['dep_files'] = array( - '#type' => 'item', - '#title' => t('Dependency Files'), - ); - - /************ START OF EXISTING DEPENDENCIES **************/ - - /* existing dependencies */ - $form['existing_depfile'] = array( - '#type' => 'fieldset', - '#title' => t('Use Already Existing Dependency Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - '#prefix' => '<div id="existing-depfile-wrapper">', - '#suffix' => '</div>', - '#tree' => TRUE, - ); - - /* existing dependencies */ - $form['existing_depfile']['selected'] = array( - '#type' => 'item', - '#title' => t('Existing Dependency Files Selected'), - '#value' => '<div id="existing_depfile_selected"></div>', - ); - - $form['existing_depfile']['dep_lab_title'] = array( - '#type' => 'select', - '#title' => t('Title of the Lab'), - '#options' => _list_of_lab_titles(), - ); - - list($files_options, $files_options_class) = _list_of_dependency_files(); - $form['existing_depfile']['dep_experiment_files'] = array( - '#type' => 'checkboxes', - '#title' => t('Dependency Files'), - '#options' => $files_options, - '#options_class' => $files_options_class, - '#multiple' => TRUE, - ); - - $form['existing_depfile']['dep_upload'] = array( - '#type' => 'item', - '#value' => l('Upload New Depedency Files', 'lab_migration/code/upload_dep'), - ); - /************ END OF EXISTING DEPENDENCIES **************/ - - $form['result'] = array( - '#type' => 'fieldset', - '#title' => t('Result Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['result']['result1'] = array( - '#type' => 'file', - '#title' => t('Upload result file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - $form['result']['result2'] = array( - '#type' => 'file', - '#title' => t('Upload result file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - - $form['xcos'] = array( - '#type' => 'fieldset', - '#title' => t('XCOS Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['xcos']['xcos1'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - $form['xcos']['xcos2'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - $form['cancel'] = array( - '#type' => 'markup', - '#value' => l(t('Cancel'), 'lab_migration/code_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) + 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'])) { - /* 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.')); + /* 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 ($) { + /* 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 */ @@ -296,215 +266,218 @@ function lab_migration_bulk_upload_code_form_validate($form, &$form_state) }); $('#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); + drupal_add_js($dep_selection_js, 'inline', 'header'); } - - $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) +function lab_migration_bulk_upload_code_form_submit($form, &$form_state) { - 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])) + 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(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error'); - return; + drupal_set_message("Invalid proposal selected", 'error'); + drupal_goto('lab_migration/code_approval/upload/' . $proposal_id); } - - /* uploading file */ - if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + $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) { - /* 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() + 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); - drupal_set_message($file_name . ' uploaded successfully.', 'status'); - } else { - drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error'); + 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/'); } - drupal_set_message('Solution uploaded successfully.', 'status'); - - /* sending email */ - $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', ''); - $param['solution_uploaded']['solution_id'] = $solution_id; - $param['solution_uploaded']['user_id'] = $user->uid; - if (!drupal_mail('lab_migration', 'solution_uploaded', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - drupal_goto('lab_migration/code_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 . ')'; + $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; } - 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; + $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 + ); } - return array($dependency_files, $dependency_files_class); -} - |