diff options
author | prashant | 2015-10-11 17:06:23 +0530 |
---|---|---|
committer | prashant | 2015-10-11 17:06:23 +0530 |
commit | 75bddee850f35be8d56740ba66b0d93d6dc6072c (patch) | |
tree | 4c775a47edd9229904fef8b51cfe2581231e6738 | |
parent | f688bd4660c7e3159fab94d529a5b94197f5f35f (diff) | |
download | DWSIM_lab_migration_module-75bddee850f35be8d56740ba66b0d93d6dc6072c.tar.gz DWSIM_lab_migration_module-75bddee850f35be8d56740ba66b0d93d6dc6072c.tar.bz2 DWSIM_lab_migration_module-75bddee850f35be8d56740ba66b0d93d6dc6072c.zip |
removed temp files
-rwxr-xr-x | .gitignore | 1 | ||||
-rwxr-xr-x | bulk_approval.inc~ | 619 | ||||
-rwxr-xr-x | bulk_upload_code.inc~ | 510 | ||||
-rwxr-xr-x | code_approval.inc~ | 318 | ||||
-rwxr-xr-x | download.inc~ | 298 | ||||
-rwxr-xr-x | email.inc~ | 543 | ||||
-rwxr-xr-x | lab_migration.info~ | 7 | ||||
-rwxr-xr-x | lab_migration.module~ | 636 | ||||
-rwxr-xr-x | manage_proposal.inc~ | 1257 | ||||
-rwxr-xr-x | manage_solution_proposal.inc~ | 270 | ||||
-rwxr-xr-x | proposal.inc~ | 338 | ||||
-rwxr-xr-x | upload_code.inc~ | 645 |
12 files changed, 1 insertions, 5441 deletions
@@ -39,3 +39,4 @@ xmlrpc.php # Ignore vim temp. files *.swo *.swp +*~ diff --git a/bulk_approval.inc~ b/bulk_approval.inc~ deleted file mode 100755 index 64c4883..0000000 --- a/bulk_approval.inc~ +++ /dev/null @@ -1,619 +0,0 @@ -<?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); - - - $form = array(); - $form['lab'] = array( - '#type' => 'select', - '#title' => t('Title of the lab'), - '#options' => _bulk_list_of_labs(), - '#default_value' => $selected, - '#ajax' => array( - 'callback' => 'ajax_bulk_experiment_list_callback', - ), - '#suffix' => '<div id="ajax_selected_lab"></div><div id="ajax_selected_lab_pdf"></div>', - - ); - - $form['lab_actions'] = array( - '#type' => 'select', - '#title' => t('Please select action'), - '#options' => _bulk_list_lab_actions(), - '#default_value' => 0, - '#prefix' => '<div id="ajax_selected_lab_action" style="color:red;">', - '#suffix' => '</div>', - '#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' => '<div id="ajax_selected_experiment">', - '#suffix' => '</div>', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0),),), - ); - $form['download_experiment'] = array( - '#type' => 'item', - '#markup' => '<div id="ajax_download_experiment"></div>', - ); - - $form['lab_experiment_actions'] = array( - '#type' => 'select', - '#title' => t('Please select action'), - '#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),),), - ); - - $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' => '<div id="ajax_selected_solution">', - '#suffix' => '</div>', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0),),), - ); - - - $form['lab_experiment_solution_actions'] = array( - '#type' => 'select', - '#title' => t('Please select action'), - '#options' => _bulk_list_solution_actions(), - '#default_value' => 0, - '#prefix' => '<div id="ajax_selected_lab_experiment_solution_action" style="color:red;">', - '#suffix' => '</div>', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0),),), - ); - - $form['download_solution'] = array( - '#type' => 'item', - '#markup' => '<div id="ajax_download_experiment_solution"></div>', - ); - $form['edit_solution'] = array( - '#type' => 'item', - '#markup' => '<div id="ajax_edit_experiment_solution"></div>', - ); - $form['solution_files'] = array( - '#type' => 'item', - // '#title' => t('List of solution_files'), - '#markup' => '<div id="ajax_solution_files"></div>', - '#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' => '<div id= "message_submit">', - '#states' => array('invisible' => array(':input[name="lab"]' => array('value' => 0,),),), - - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - '#suffix' => '</div>', - '#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/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); - } - - /* 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', '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_validate($form, &$form_state){ -if(($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions']== 0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) - drupal_set_message("Wrong selection of action. Please select any one action", 'error'); - return; - if(($form_state['values']['lab_actions'] != 0) && ($form_state['values']['lab_experiment_actions'] != 0) && ($form_state['values']['lab_experiment_solution_actions'] != 0)) - drupal_set_message("Wrong selection of action. Please select any one action"); - return; - if(($form_state['values']['lab_actions'] != 0) && ($form_state['values']['lab_experiment_actions'] !=0) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) - drupal_set_message("Wrong selection of action. Please select any one action", 'error'); - return; - if(($form_state['values']['lab_actions'] != 0) && ($form_state['values']['lab_experiment_actions'] == 0) && ($form_state['values']['lab_experiment_solution_actions'] != 0)) - drupal_set_message("Wrong selection of action. Please select any one action", 'error'); - return; - -if(($form_state['values']['lab_actions'] == 0) && ($form_state['values']['lab_experiment_actions'] != 0) && ($form_state['values']['lab_experiment_solution_actions'] != 0)) - drupal_set_message("Wrong selection of action. Please select any one action", 'error'); - return; - - } - -function lab_migration_bulk_approval_form_submit($form, &$form_state){ - // var_dump($form_state['values']['lab_actions']); - // die; - 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')) - { - 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']); - $experiment_q = $query->execute(); - 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)); - } - drupal_set_message(t('Approved Entire Lab.'), 'status'); - - /* email */ - $email_subject = t('Your uploaded solutions have been approved'); - $email_body = array(0 => t('Your all the uploaded solutions for the Lab have been approved.')); - - } 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('Your uploaded 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 (!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('Your uploaded 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 (!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'); - - $dir_path = $root_path . $form_state['values']['lab']; - if (is_dir($dir_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('Your uploaded 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'])); - drupal_set_message(t('Approved Entire Experiment.'), 'status'); - - /* email */ - $email_subject = t('Your uploaded 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'); - - /* email */ - $email_subject = t('Your uploaded 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'] == 1) && ($form_state['values']['lab_experiment_actions']== 3) && ($form_state['values']['lab_experiment_solution_actions'] == 0)) { - - 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'])) - { - 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('Your uploaded 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)) { - - 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'])); - drupal_set_message(t('Solution approved.'), 'status'); - - /* email */ - $email_subject = t('Your uploaded 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)) { - - 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('Your uploaded 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)) { - - 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('Your uploaded 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'])); - - } - - /****** sending email when everything done ******/ - if ($email_subject) - { - /*$email_to = variable_get('lab_migration_emails', '') . ', ' . $user->mail; */ - // $email_to = "contact@scilab.in" . ', ' . $user->mail; - $email_to = "prashantsinalkar@gmail.com"; - $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'); - } - - } else { - drupal_set_message(t('You do not have permission to bulk manage code.'), 'error'); - } - - } - } - - -/************************************************************/ -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; -} diff --git a/bulk_upload_code.inc~ b/bulk_upload_code.inc~ deleted file mode 100755 index def81fe..0000000 --- a/bulk_upload_code.inc~ +++ /dev/null @@ -1,510 +0,0 @@ -<?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) - { - 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() + '<br />'; - } - }); - /* showing list of already existing dependencies */ - $('#existing_depfile_selected').html(dep_selected); - }); - - $('.form-checkboxes .option').change(function() { - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }); - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - })(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('You should upload all the files (main or source files, result files, executable file if any)'), - '#prefix' => '<div style="color:red">', - '#suffix' => '</div>', - ); - - $form['sourcefile'] = array( - '#type' => 'fieldset', - '#title' => t('Main or Source Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['sourcefile']['sourcefile1'] = array( - '#type' => 'file', - '#title' => t('Upload main or source file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', ''), - ); - - $form['dep_files'] = array( - '#type' => 'item', - '#title' => t('Dependency Files'), - ); - - /************ START OF EXISTING DEPENDENCIES **************/ - - /* existing dependencies */ - $form['existing_depfile'] = array( - '#type' => 'fieldset', - '#title' => t('Use Already Existing Dependency Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - '#prefix' => '<div id="existing-depfile-wrapper">', - '#suffix' => '</div>', - '#tree' => TRUE, - ); - - /* existing dependencies */ - $form['existing_depfile']['selected'] = array( - '#type' => 'item', - '#title' => t('Existing Dependency Files Selected'), - '#value' => '<div id="existing_depfile_selected"></div>', - ); - - $form['existing_depfile']['dep_lab_title'] = array( - '#type' => 'select', - '#title' => t('Title of the Lab'), - '#options' => _list_of_lab_titles(), - ); - - list($files_options, $files_options_class) = _list_of_dependency_files(); - $form['existing_depfile']['dep_experiment_files'] = array( - '#type' => 'checkboxes', - '#title' => t('Dependency Files'), - '#options' => $files_options, - '#options_class' => $files_options_class, - '#multiple' => TRUE, - ); - - $form['existing_depfile']['dep_upload'] = array( - '#type' => 'item', - '#value' => l('Upload New Depedency Files', 'lab_migration/code/upload_dep'), - ); - /************ END OF EXISTING DEPENDENCIES **************/ - - $form['result'] = array( - '#type' => 'fieldset', - '#title' => t('Result Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['result']['result1'] = array( - '#type' => 'file', - '#title' => t('Upload result file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - $form['result']['result2'] = array( - '#type' => 'file', - '#title' => t('Upload result file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - - $form['xcos'] = array( - '#type' => 'fieldset', - '#title' => t('XCOS Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['xcos']['xcos1'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - $form['xcos']['xcos2'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - $form['cancel'] = array( - '#type' => 'markup', - '#value' => l(t('Cancel'), 'lab_migration/code_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() + '<br />'; - } - }); - /* showing list of already existing dependencies */ - $('#existing_depfile_selected').html(dep_selected); - }); - - $('.form-checkboxes .option').change(function() { - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }); - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }(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 . ', ' . 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 . ')'; - } - 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~ deleted file mode 100755 index fd6cb47..0000000 --- a/code_approval.inc~ +++ /dev/null @@ -1,318 +0,0 @@ -<?php -// $Id$ - -function lab_migration_code_approval() -{ - /* get a list of unapproved solutions */ - //$pending_solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE approval_status = 0"); - $query = db_select('{lab_migration_solution}'); - $query->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 . ')' . '<br/>'; - } - } - /* 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' . ')' . '<br/>'; - } - - $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'), - ); - - $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_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 . ', ' . variable_get('lab_migration_emails', ''); - $param['solution_pending']['solution_id'] = $solution_id; - $param['solution_pending']['user_id'] = $user_data->uid; - if (!drupal_mail('lab_migration', 'solution_pending', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), 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 . ', ' . variable_get('lab_migration_emails', ''); - $param['solution_approved']['solution_id'] = $solution_id; - $param['solution_approved']['user_id'] = $user_data->uid; - if (!drupal_mail('lab_migration', 'solution_approved', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), 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 . ', ' . variable_get('lab_migration_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']; - if (!drupal_mail('lab_migration', 'solution_disapproved', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), 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/download.inc~ b/download.inc~ deleted file mode 100755 index 9e5fa33..0000000 --- a/download.inc~ +++ /dev/null @@ -1,298 +0,0 @@ -<?php -// $Id$ - -function lab_migration_download_solution_file() -{ - $solution_file_id = arg(3); - $root_path = lab_migration_path(); - - // $solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE id = %d LIMIT 1", $solution_file_id); - $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->filepath)); - readfile($root_path . $solution_file_data->filepath); -} - -function lab_migration_download_dependency_file() -{ - $dependency_file_id = arg(3); - $root_path = lab_migration_path(); - - //$dependency_file_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id); - $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_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->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_run'); - } -} - -function lab_migration_download_experiment() -{ - $experiment_id = arg(3); - $root_path = lab_migration_path(); - - /* get solution data */ - //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id); - $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); - $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->filepath, $EXP_PATH . $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, $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_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); - $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->filepath, $LAB_PATH . $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, $LAB_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $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="' . $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="' . $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_run'); - } -} - diff --git a/email.inc~ b/email.inc~ deleted file mode 100755 index a241ebb..0000000 --- a/email.inc~ +++ /dev/null @@ -1,543 +0,0 @@ -<?php - -/** - * Implementation of hook_mail(). - */ -function lab_migration_mail($key, &$message, $params) -{ - global $user; - $language = $message['language']; - //$language = user_preferred_language($user); - switch ($key) - { - case 'solution_proposal_approved': - - /* initializing data */ - //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $params['solution_proposal_approved']['proposal_id']); - $query = db_select('lab_migration_proposal'); - $query->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 . '<br/> '.$experiment_data->description.' '; - } - - $user_data = user_load($params['solution_proposal_approved']['user_id']); - - $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 . ' - -Display solution on website : ' . $solution_display . ' - -List of experiments : ' . $experiment_list . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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']); - - $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, - -Your Lab migration solution proposal has been disapproved. - -Reason: ' . $params['solution_proposal_disapproved']['message'] . ' - -Best Wishes, - -!site_name', 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(); - - 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 . ' - '; - } - - $user_data = user_load($params['proposal_received']['user_id']); - - $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 following Lab migration proposal: - -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 . ' - -Display solution on website : ' . $solution_display . ' - -Solution Provided By : ' . $solution_provider_user . ' - -List of experiments : ' . $experiment_list . ' - -Your proposal is under review and you will soon receive an email from us regarding the same. - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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(); - - - 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 . ' - '; - } - - $user_data = user_load($params['proposal_disapproved']['user_id']); - - $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, - -Your following Lab migration proposal has been disapproved: - -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 . ' - -Display solution on website : ' . $solution_display . ' - -Solution Provided By : ' . $solution_provider_user . ' - -List of experiments : ' . $experiment_list . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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(); - - 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 . ' - '; - } - - $user_data = user_load($params['proposal_approved']['user_id']); - $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, - -Your following Lab migration proposal 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 . ' - -Display solution on website : ' . $solution_display . ' - -Solution Provided By : ' . $solution_provider_user . ' - -List of experiments : ' . $experiment_list . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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 . ' - '; - } - - $user_data = user_load($params['proposal_completed']['user_id']); - - $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 . ' - -Display solution on website : ' . $solution_display . ' - -Solution Provided By : ' . $solution_provider_user . ' - -List of experiments : ' . $experiment_list . ' - -Your Lab solution is now available at following link to download. - -http://esim.fossee.in/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 http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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 . ' - '; - } - - $user_data = user_load($params['solution_proposal_received']['user_id']); - - $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 solution for following Lab migration : - -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 . ' - -Display solution on website : ' . $solution_display . ' - -Solution Provided By : ' . $solution_provider_user . ' - -List of experiments : ' . $experiment_list . ' - -Your proposal is under review and you will soon receive an email from us regarding the same. - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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(); - $user_data = user_load($params['solution_uploaded']['user_id']); - - $message['subject'] = t('[!site_name] You have uploaded solution', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); - $message['body'] = array('body' => t(' -Dear !user_name, - -You have uploaded the following solution: - -Example 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', 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(); - $user_data = user_load($params['solution_approved']['user_id']); - - $message['subject'] = t('[!site_name] Your uploaded 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: - -Solution number : ' . $solution_data->code_number . ' -Caption : ' . $solution_data->caption . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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['subject'] = t('[!site_name] Your uploaded 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'] . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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['subject'] = t('[!site_name] User has deleted pending 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'] . ' - -Please ensure that ALL the codes follow guidelines at http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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['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 http://www.esim.fossee.in/coding-guidelines-lab-migration - -Best Wishes, - -!site_name', 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']; - break; - } -} - diff --git a/lab_migration.info~ b/lab_migration.info~ deleted file mode 100755 index 431f488..0000000 --- a/lab_migration.info~ +++ /dev/null @@ -1,7 +0,0 @@ -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.module~ b/lab_migration.module~ deleted file mode 100755 index 735a40c..0000000 --- a/lab_migration.module~ +++ /dev/null @@ -1,636 +0,0 @@ -<?php -// $Id$ - -require_once('general_deletion.inc'); -require_once('email.inc'); - -/** - * Implementation of hook_menu(). - */ -function lab_migration_menu() -{ - $items = array(); - - /* PROPOSAL */ - $items['lab_migration/proposal'] = array( - 'title' => '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_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() . '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')); - }*/ diff --git a/manage_proposal.inc~ b/manage_proposal.inc~ deleted file mode 100755 index 21883a7..0000000 --- a/manage_proposal.inc~ +++ /dev/null @@ -1,1257 +0,0 @@ -<?php -// $Id$ - -function lab_migration_proposal_pending() -{ - /* get pending proposals to be approved */ - $pending_rows = array(); - //$pending_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 0 ORDER BY id DESC"); - $query = db_select('lab_migration_proposal'); - $query->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'); - $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()) - { - 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; - } - $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, $category_data, 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_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['lab_title'] = array( - '#type' => 'item', - '#markup' => $proposal_data->lab_title, - '#title' => t('Title of the Lab'), - ); - - /* get experiment details */ - $experiment_list = '<ul>'; - //$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(); - while ($experiment_data = $experiment_q->fetchObject()) - { - $experiment_list .= '<li>' . $experiment_data->title . '</li>Description of Experiment : '.$experiment_data->description.'<br>'; - } - $experiment_list .= '</ul>'; - - $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.esim.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'), - ); - - $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_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 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; - $param['proposal_approved']['proposal_id'] = $proposal_id; - $param['proposal_approved']['user_id'] = $proposal_data->uid; - // echo "To: ".$email_to." From: ".variable_get('lab_migration_from_email', NULL)."<br>"; - // echo "<pre>"; - // var_dump($param); die; - if (!drupal_mail('lab_migration', 'proposal_approved', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', ''); - if (!drupal_mail('lab_migration', '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 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; - $param['proposal_disapproved']['proposal_id'] = $proposal_id; - $param['proposal_disapproved']['user_id'] = $proposal_data->uid; - if (!drupal_mail('lab_migration', 'proposal_disapproved', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - $email_to = $user_data->mail . ', ' . variable_get('lab_migration_emails', '');; - if (!drupal_mail('lab_migration', 'proposal_disapproved', $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 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_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 = '<ul>'; - //$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(); - while ($experiment_data = $experiment_q->fetchObject()) - { - $experiment_list .= '<li>' . $experiment_data->title .'</li>Description of Experiment : '.$experiment_data->description.'<br>'; - } - $experiment_list .= '</ul>'; - - $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.esim.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' => 'item', - '#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) - { - $query = "UPDATE {lab_migration_proposal} SET approval_status = 3 and expected_completion_date= :date WHERE id = :proposal_id"; - $args = array( - ":proposal_id" => $proposal_id, - ":date" => time(), - ); - $result = db_query($query, $args); - - /* sending email */ - $user_data = user_load($proposal_data->uid); - $email_to = $user_data->mail; - $param['proposal_completed']['proposal_id'] = $proposal_id; - $param['proposal_completed']['user_id'] = $proposal_data->uid; - 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'); - - $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_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' => array('' => 'Please select...', - 'Computer Engineering' => 'Computer Engineering', - 'Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), - '#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['city'] = array( - '#type' => 'textfield', - '#title' => t('City/ Village'), - '#size' => 80, - '#maxlength' => 150, - '#default_value' => $proposal_data->city, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'), - ); -$form['pincode'] = array( - '#type' => 'textfield', - '#title' => t('Pincode'), - '#size' => 30, - '#maxlength' => 6, - '#required' => TRUE, - '#default_value' => $proposal_data->pincode, - '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'), -); -$form['all_state'] = array( - '#type' => 'select', - '#title' => t('State'), - '#options' => array( - '0' => 'Please select...', - 'Andhra Pradesh' => t('Andhra Pradesh'), - 'Arunachal Pradesh' => 'Arunachal Pradesh', - 'Assam' => 'Assam', - 'Bihar' => 'Bihar', - 'Chhattisgarh' => 'Chhattisgarh', - 'Goa' => 'Goa', - 'Gujarat' => 'Gujarat', - 'Haryana' => 'Haryana', - 'Himachal Pradesh' => 'Himachal Pradesh', - 'Jammu & Kashmir' => 'Jammu & Kashmir', - 'Jharkhand' => 'Jharkhand', - 'Karnataka' => 'Karnataka', - 'Kerala' => 'Kerala', - 'Madhya Pradesh' => 'Madhya Pradesh', - 'Maharashtra' => 'Maharashtra', - 'Manipur' => 'Manipur', - 'Meghalaya' => 'Meghalaya', - 'Mizoram' => 'Mizoram', - 'Nagaland' => 'Nagaland', - 'Odisha' => 'Odisha', - 'Punjab' => 'Punjab', - 'Rajasthan' => 'Rajasthan', - 'Sikkim' => 'Sikkim', - 'Tamil Nadu' => 'Tamil Nadu', - 'Telangana' => 'Telangana', - 'Tripura' => 'Tripura', - 'Uttarakhand' => 'Uttarakhand', - 'Uttar Pradesh'=> 'Uttar Pradesh', - 'West Bengal' => 'West Bengal', - 'Andaman & Nicobar' => 'Andaman & Nicobar', - 'Chandigarh' => 'Chandigarh', - 'Dadra and Nagar Haveli' => 'Dadra and Nagar Haveli', - 'Daman & Diu' => 'Daman & Diu', - 'Delhi' => 'Delhi', - 'Lakshadweep' => 'Lakshadweep', - 'Puducherry' => 'Puducherry', - 'Others' => 'Others', - ), - '#required' => TRUE, - '#tree' => TRUE, - '#validated' => TRUE, - '#default_value' => $proposal_data->state, - ); - - - - $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' => 'radios', - '#title' => t('Do you want to display the solution on the www.esim.fossee.in website'), - '#options' => array('1' => 'Yes', '2' => 'No'), - '#required' => TRUE, - '#default_value' => ($proposal_data->solution_display == 1) ? "1" : "2", - ); - - $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, - // ); - $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, - ))->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($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_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' => array(0 => 'Please select', - 1 => 'Fluid Mechanics', - 2 => 'Control Theory & Control Systems', - 3 => 'Chemical Engineering', - 4 => 'Thermodynamics', - 5 => 'Mechanical Engineering', - 6 => 'Signal Processing', - 7 => 'Digital Communications', - 8 => 'Electrical Technology', - 9 => 'Mathematics & Pure Science', - 10 => 'Analog Electronics', - 11 => 'Digital Electronics', - 12 => 'Computer Programming', - 13 => 'Others'), - '#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'); -} - diff --git a/manage_solution_proposal.inc~ b/manage_solution_proposal.inc~ deleted file mode 100755 index 2bace0c..0000000 --- a/manage_solution_proposal.inc~ +++ /dev/null @@ -1,270 +0,0 @@ -<?php -// $Id$ - -function lab_migration_solution_proposal_pending() -{ - /* get list of solution proposal where the solution_provider_uid is set to some userid except 0 and solution_status is also 1 */ - $pending_rows = array(); - //$pending_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid != 0 AND solution_status = 1 ORDER BY id DESC"); - $query = db_select('lab_migration_proposal'); - $query->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_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->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid), - '#title' => t('Proposer 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 = '<ul>'; - //$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(); - while ($experiment_data = $experiment_q->fetchObject()) - { - $experiment_list .= '<li>' . $experiment_data->title . '</li>Description of Experiment : '.$experiment_data->description.'<br>';; - } - $experiment_list .= '</ul>'; - - $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 .= '<ul>' . - '<li><strong>Solution Provider:</strong> ' . l($solution_provider_user_data->name, 'user/' . $proposal_data->solution_provider_uid) . '</li>' . - '<li><strong>Solution Provider Name:</strong> ' . $proposal_data->solution_provider_name_title . ' ' . $proposal_data->solution_provider_name . '</li>' . - '<li><strong>Department:</strong> ' . $proposal_data->solution_provider_department . '</li>' . - '<li><strong>University:</strong> ' . $proposal_data->solution_provider_university . '</li>' . - '</ul>'; - } else { - $solution_provider = "User does not exists"; - } - } - $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; - $param['solution_proposal_approved']['proposal_id'] = $proposal_id; - $param['solution_proposal_approved']['user_id'] = $proposal_data->solution_provider_uid; - 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'); - - $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; - $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']; - if (!drupal_mail('lab_migration', 'solution_proposal_disapproved', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), 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_disapproved', $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 dis-approved. User has been notified of the dis-approval.', 'status'); - drupal_goto('lab_migration/manage_proposal/pending_solution_proposal'); - return; - } -} - diff --git a/proposal.inc~ b/proposal.inc~ deleted file mode 100755 index 9f0d7c3..0000000 --- a/proposal.inc~ +++ /dev/null @@ -1,338 +0,0 @@ -<?php -// $Id$ - -/* - Approval Status : - 0 - Pending - 1 - Approved - 2 - Dis-Approved - 3 - Solved - Solution Status : - 0 - Pending - 1 - Approved - 2 - Dis-Approved - Solution Display : - 0 - No - 1 - Yes - - Tables : - lab_migration_solution : approval_status - 0 - Pending - 1 - Approved - 2 - Disapproved (delete it) -*/ - -function lab_migration_proposal_form($form_state) -{ - global $user; - - /************************ start approve book details ************************/ - $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' => 30, - '#maxlength' => 50, - '#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, - '#maxlength' => 15, - '#required' => TRUE, - ); - $form['department'] = array( - '#type' => 'select', - '#title' => t('Department/Branch'), - '#options' => array('' => 'Please select...', - 'Computer Engineering' => 'Computer Engineering', - 'Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), - '#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['city'] = array( - '#type' => 'textfield', - '#title' => t('City/ Village'), - '#size' => 80, - '#maxlength' => 150, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'), - ); -$form['pincode'] = array( - '#type' => 'textfield', - '#title' => t('Pincode'), - '#size' => 30, - '#maxlength' => 6, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'), -); -$form['all_state'] = array( - '#type' => 'select', - '#title' => t('State'), - '#options' => array( - '0' => 'Please select...', - 'Andhra Pradesh' => t('Andhra Pradesh'), - 'Arunachal Pradesh' => 'Arunachal Pradesh', - 'Assam' => 'Assam', - 'Bihar' => 'Bihar', - 'Chhattisgarh' => 'Chhattisgarh', - 'Goa' => 'Goa', - 'Gujarat' => 'Gujarat', - 'Haryana' => 'Haryana', - 'Himachal Pradesh' => 'Himachal Pradesh', - 'Jammu & Kashmir' => 'Jammu & Kashmir', - 'Jharkhand' => 'Jharkhand', - 'Karnataka' => 'Karnataka', - 'Kerala' => 'Kerala', - 'Madhya Pradesh' => 'Madhya Pradesh', - 'Maharashtra' => 'Maharashtra', - 'Manipur' => 'Manipur', - 'Meghalaya' => 'Meghalaya', - 'Mizoram' => 'Mizoram', - 'Nagaland' => 'Nagaland', - 'Odisha' => 'Odisha', - 'Punjab' => 'Punjab', - 'Rajasthan' => 'Rajasthan', - 'Sikkim' => 'Sikkim', - 'Tamil Nadu' => 'Tamil Nadu', - 'Telangana' => 'Telangana', - 'Tripura' => 'Tripura', - 'Uttarakhand' => 'Uttarakhand', - 'Uttar Pradesh'=> 'Uttar Pradesh', - 'West Bengal' => 'West Bengal', - 'Andaman & Nicobar' => 'Andaman & Nicobar', - 'Chandigarh' => 'Chandigarh', - 'Dadra and Nagar Haveli' => 'Dadra and Nagar Haveli', - 'Daman & Diu' => 'Daman & Diu', - 'Delhi' => 'Delhi', - 'Lakshadweep' => 'Lakshadweep', - 'Puducherry' => 'Puducherry', - 'Others' => 'Others', - ), - '#required' => TRUE, - '#tree' => TRUE, - '#validated' => TRUE, - ); - $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++) { - $form['lab_experiment-' . $counter] = array( - '#type' => 'textfield', - '#title' => t('Title of the Experiment ') . $counter, - '#size' => 50, - '#required' => $first_experiemnt, - ); - $namefield="lab_experiment-" . $counter; - $form['lab_experiment_description-' . $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' => ""), - ), - ), - ); - $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' => 'radios', - '#title' => t('Do you want to display the solution on the www.esim.fossee.in website'), - '#options' => array('1' => 'Yes', '2' => 'No'), - '#required' => TRUE, - '#default_value' => '2', - '#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')); - 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 = 0; - - /* inserting the user proposal */ - $v = $form_state["values"]; - $result = "INSERT INTO {lab_migration_proposal} - (uid, approver_uid, name_title, name, contact_ph, department, university, city, pincode, state, 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) VALUES - (:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :pincode, :state, :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)"; - $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'], - ":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 - ); - $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, number, title,description) VALUES (:proposal_id, :number, :experiment_field_name,:description)"; - $args= array( - ":proposal_id" => $proposal_id, - ":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; - $param['proposal_received']['proposal_id'] = $proposal_id; - $param['proposal_received']['user_id'] = $user->uid; - var_dump($param); - if (!drupal_mail('lab_migration', 'proposal_received', $email_to , user_preferred_language($user), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - /* sending email */ - $email_to = variable_get('lab_migration_emails', ''); - if (!drupal_mail('lab_migration', 'proposal_received', $email_to , user_preferred_language($user), $param, variable_get('lab_migration_from_email', NULL), 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(''); -} - diff --git a/upload_code.inc~ b/upload_code.inc~ deleted file mode 100755 index a924df2..0000000 --- a/upload_code.inc~ +++ /dev/null @@ -1,645 +0,0 @@ -<?php -// $Id$ - -function lab_migration_list_experiments() -{ - global $user; - - $proposal_data = lab_migration_get_proposal(); - if (!$proposal_data) { - drupal_goto(''); - return; - } - - $return_html = '<strong>Title of the Lab:</strong><br />' . $proposal_data->lab_title . '<br /><br />'; - $return_html .= '<strong>Proposer Name:</strong><br />' . $proposal_data->name_title . ' ' . $proposal_data->name . '<br /><br />'; - $return_html .= l('Upload Solution', 'lab_migration/code/upload') . '<br />'; - - /* 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_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() + '<br />'; - } - }); - /* showing list of already existing dependencies */ - $('#existing_depfile_selected').html(dep_selected); - }); - - $('.form-checkboxes .option').change(function() { - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }); - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }(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( - 0 => '--- Please select ---', - 'Linux' => 'Linux', - 'Windows' => 'Windows', - 'Mac' => 'Mac' - ), - '#required' => TRUE, - ); - $form['esim_version'] = array( - '#type' => 'select', - '#title' => t('esim version used'), - '#options' => array( - 0 => '--- Please select ---', - '1.0.0' => '1.0.0', - 'Older' => 'Older 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('You should upload all the files (main or source files, result files, executable file if any)'), - '#prefix' => '<div style="color:red">', - '#suffix' => '</div>', - ); - $form['sourcefile'] = array( - '#type' => 'fieldset', - '#title' => t('Main or Source Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['sourcefile']['sourcefile1'] = array( - '#type' => 'file', - '#title' => t('Upload main or source file'), - '#size' => 48, - '#description' => t('Only alphabets and numbers are allowed as a valid 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'), - '#markup' => '<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', - '#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.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - $form['result']['result2'] = array( - '#type' => 'file', - '#title' => t('Upload result file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''), - ); - - $form['xcos'] = array( - '#type' => 'fieldset', - '#title' => t('XCOS Files'), - '#collapsible' => FALSE, - '#collapsed' => FALSE, - ); - $form['xcos']['xcos1'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); - $form['xcos']['xcos2'] = array( - '#type' => 'file', - '#title' => t('Upload xcos file'), - '#size' => 48, - '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . - t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''), - ); -*/ - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - $form['cancel'] = array( - '#type' => 'markup', - '#value' => l(t('Cancel'), 'lab_migration/code'), - ); - return $form; -} - -function 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']['esim_version']) - form_set_error('esim_version', t('Please select the esim version used.')); - - 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() { - 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() + '<br />'; - } - }); - /* showing list of already existing dependencies */ - $('#existing_depfile_selected').html(dep_selected); - }); - - $('.form-checkboxes .option').change(function() { - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - }); - $('#edit-existing-depfile-dep-lab-title').trigger('change'); - })(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; - - /************************ 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_id . '/'; - 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 solution database entry */ - $query = "INSERT INTO {lab_migration_solution} (experiment_id, approver_uid, code_number, caption, approval_date, approval_status, timestamp, os_used, esim_version, toolbox_used) VALUES (:experiment_id, :approver_uid, :code_number, :caption, :approval_date, :approval_status, :timestamp, :os_used, :esim_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'], - ":esim_version" => $form_state['values']['esim_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" => $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 . ', ' . variable_get('lab_migration_emails', ''); - $param['solution_uploaded']['solution_id'] = $solution_id; - $param['solution_uploaded']['user_id'] = $user->uid; - if (!drupal_mail('lab_migration', 'solution_uploaded', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE)) - drupal_set_message('Error sending email message.', 'error'); - - drupal_goto('lab_migration/code'); -} - -/******************************************************************************/ -/************************** GENERAL FUNCTIONS *********************************/ -/******************************************************************************/ - -function _list_of_lab_titles() -{ - $lab_titles = array('0' => 'Please select...'); - //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 OR approval_status = 3 ORDER BY lab_title ASC"); - $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); -} - |