summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashant2015-10-11 16:51:38 +0530
committerprashant2015-10-11 16:51:38 +0530
commitf688bd4660c7e3159fab94d529a5b94197f5f35f (patch)
tree86bbdcd7e584ad12e72ccca57cfe60baa3add640
downloadDWSIM_lab_migration-f688bd4660c7e3159fab94d529a5b94197f5f35f.tar.gz
DWSIM_lab_migration-f688bd4660c7e3159fab94d529a5b94197f5f35f.tar.bz2
DWSIM_lab_migration-f688bd4660c7e3159fab94d529a5b94197f5f35f.zip
Initial repo
-rwxr-xr-x.gitignore41
-rwxr-xr-xbulk_approval.inc619
-rwxr-xr-xbulk_approval.inc~619
-rwxr-xr-xbulk_upload_code.inc510
-rwxr-xr-xbulk_upload_code.inc~510
-rwxr-xr-xcode_approval.inc318
-rwxr-xr-xcode_approval.inc~318
-rwxr-xr-xdependency.inc214
-rwxr-xr-xdependency_approval.inc150
-rwxr-xr-xdownload.inc298
-rwxr-xr-xdownload.inc~298
-rwxr-xr-xemail.inc538
-rwxr-xr-xemail.inc~543
-rwxr-xr-xfull_download.inc252
-rwxr-xr-xgeneral_deletion.inc268
-rwxr-xr-xlab_details.inc40
-rwxr-xr-xlab_migration.info7
-rwxr-xr-xlab_migration.info~7
-rwxr-xr-xlab_migration.install431
-rwxr-xr-xlab_migration.module636
-rwxr-xr-xlab_migration.module~636
-rwxr-xr-xlatex.inc261
-rwxr-xr-xlatex/Initial_body58
-rwxr-xr-xlatex/latex_test.sh199
-rwxr-xr-xlatex/pdf_creator.sh18
-rwxr-xr-xmanage_proposal.inc1279
-rwxr-xr-xmanage_proposal.inc~1257
-rwxr-xr-xmanage_solution_proposal.inc270
-rwxr-xr-xmanage_solution_proposal.inc~270
-rwxr-xr-xnotes.inc119
-rwxr-xr-xproposal.inc461
-rwxr-xr-xproposal.inc~338
-rwxr-xr-xrun.inc459
-rwxr-xr-xsettings.inc85
-rwxr-xr-xsolution_proposal.inc195
-rwxr-xr-xupload_code.inc645
-rwxr-xr-xupload_code.inc~645
-rwxr-xr-xupload_code_delete.inc88
38 files changed, 13900 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..b6788e8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,41 @@
+# Ignore configuration files that may contain sensitive information.
+sites/*/*settings*.php
+
+# Ignore paths that contain generated content.
+cache/
+files/
+sites/*/files
+sites/*/private
+
+# Ignore default text files
+robots.txt
+/CHANGELOG.txt
+/COPYRIGHT.txt
+/INSTALL*.txt
+/LICENSE.txt
+/MAINTAINERS.txt
+/UPGRADE.txt
+/README.txt
+sites/all/README.txt
+sites/all/modules/README.txt
+sites/all/themes/README.txt
+
+# Ignore everything but the "sites" folder ( for non core developer )
+.htaccess
+web.config
+authorize.php
+cron.php
+index.php
+install.php
+update.php
+xmlrpc.php
+/includes
+/misc
+/modules
+/profiles
+/scripts
+/themes
+
+# Ignore vim temp. files
+*.swo
+*.swp
diff --git a/bulk_approval.inc b/bulk_approval.inc
new file mode 100755
index 0000000..668f39c
--- /dev/null
+++ b/bulk_approval.inc
@@ -0,0 +1,619 @@
+<?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_approval.inc~ b/bulk_approval.inc~
new file mode 100755
index 0000000..64c4883
--- /dev/null
+++ b/bulk_approval.inc~
@@ -0,0 +1,619 @@
+<?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
new file mode 100755
index 0000000..d4776e9
--- /dev/null
+++ b/bulk_upload_code.inc
@@ -0,0 +1,510 @@
+<?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('Upload all the eSim project files in .zip format'),
+ '#prefix' => '<div style="color:red">',
+ '#suffix' => '</div>',
+ );
+
+ $form['sourcefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Main or Source Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload main or source file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_source_extensions', ''),
+ );
+
+ $form['dep_files'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files'),
+ );
+
+ /************ START OF EXISTING DEPENDENCIES **************/
+
+ /* existing dependencies */
+ $form['existing_depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Use Already Existing Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="existing-depfile-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE,
+ );
+
+ /* existing dependencies */
+ $form['existing_depfile']['selected'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Dependency Files Selected'),
+ '#value' => '<div id="existing_depfile_selected"></div>',
+ );
+
+ $form['existing_depfile']['dep_lab_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Lab'),
+ '#options' => _list_of_lab_titles(),
+ );
+
+ list($files_options, $files_options_class) = _list_of_dependency_files();
+ $form['existing_depfile']['dep_experiment_files'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Dependency Files'),
+ '#options' => $files_options,
+ '#options_class' => $files_options_class,
+ '#multiple' => TRUE,
+ );
+
+ $form['existing_depfile']['dep_upload'] = array(
+ '#type' => 'item',
+ '#value' => l('Upload New Depedency Files', 'lab_migration/code/upload_dep'),
+ );
+ /************ END OF EXISTING DEPENDENCIES **************/
+
+ $form['result'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Result Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload result file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''),
+ );
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload result file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_result_extensions', ''),
+ );
+
+ $form['xcos'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('XCOS Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload xcos file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''),
+ );
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload xcos file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
+ t('Allowed file extensions : ') . variable_get('lab_migration_xcos_extensions', ''),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'lab_migration/code_approval/bulk'),
+ );
+ return $form;
+}
+
+function lab_migration_bulk_upload_code_form_validate($form, &$form_state)
+{
+ if (!lab_migration_check_code_number($form_state['values']['code_number']))
+ form_set_error('code_number', t('Invalid Code Number. Code Number can contain only numbers.'));
+
+ if (!lab_migration_check_name($form_state['values']['code_caption']))
+ form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.'));
+
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if ( ! ($_FILES['files']['name']['sourcefile1'] || $_FILES['files']['name']['xcos1']))
+ form_set_error('sourcefile1', t('Please upload atleast one main or source file or xcos file.'));
+
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* 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/bulk_upload_code.inc~ b/bulk_upload_code.inc~
new file mode 100755
index 0000000..def81fe
--- /dev/null
+++ b/bulk_upload_code.inc~
@@ -0,0 +1,510 @@
+<?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
new file mode 100755
index 0000000..7868935
--- /dev/null
+++ b/code_approval.inc
@@ -0,0 +1,318 @@
+<?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/code_approval.inc~ b/code_approval.inc~
new file mode 100755
index 0000000..fd6cb47
--- /dev/null
+++ b/code_approval.inc~
@@ -0,0 +1,318 @@
+<?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/dependency.inc b/dependency.inc
new file mode 100755
index 0000000..0137ca4
--- /dev/null
+++ b/dependency.inc
@@ -0,0 +1,214 @@
+<?php
+// $Id$
+
+function lab_migration_upload_dependency_form($form_state)
+{
+ global $user;
+
+ $proposal_data = lab_migration_get_proposal();
+ if (!$proposal_data) {
+ drupal_goto('');
+ return;
+ }
+
+ $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'),
+ );
+
+ $form['existing_depfile'] = array(
+ '#type' => 'item',
+ '#value' => _list_existing_dependency($proposal_data->id),
+ '#title' => t('List of existing dependency files for this book'),
+ );
+
+ $form['depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Upload Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+ $form['depfile']['depfile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload dependency file'),
+ '#description' => t("Allowed file extensions : ") . variable_get('lab_migration_dependency_extensions', ''),
+ );
+ $form['depfile']['depfile1_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption for dependency file'),
+ '#size' => 15,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ );
+ $form['depfile']['depfile1_description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Brief Description of the dependency file'),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Back'), 'lab_migration/code'),
+ );
+ return $form;
+}
+
+function lab_migration_upload_dependency_form_validate($form, &$form_state)
+{
+ global $user;
+
+ /* get approved proposal details */
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE uid = %d OR solution_provider_uid = %d ORDER BY id DESC LIMIT 1", $user->uid, $user->uid);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+
+ $or = db_or();
+ $or->condition('uid', $user->uid);
+ $or->condition('solution_provider_uid', $user->uid);
+ $query->condition($or);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ form_set_error('', t('Invalid1'));
+ }
+
+ if (!lab_migration_check_name($form_state['values']['depfile1_caption']))
+ form_set_error('code_caption', t('Caption can contain only alphabets, numbers and spaces.'));
+
+ if (isset($_FILES['files']))
+ {
+ /* check for valid filename extensions */
+ $allowed_extensions = explode(',' , variable_get('lab_migration_dependency_extensions', ''));
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only ' . variable_get('lab_migration_dependency_extensions', '') . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+
+ /* check if file already exists */
+ //$dep_exists_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE filename = '%s'", $_FILES['files']['name'][$file_form_name]))->fetchObject();
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('filename', $_FILES['files']['name'][$file_form_name]);
+ $dep_exists_data = $query->execute();
+ if ($dep_exists_data)
+ form_set_error($file_form_name, t('Dependency file with the same name has already been uploaded in this or some other lab solution. Please rename the file and try again.'));
+
+ /* check if valid file name */
+ if (!lab_migration_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ }
+ }
+ }
+}
+
+function lab_migration_upload_dependency_form_submit($form, &$form_state) {
+ global $user;
+
+ $root_path = lab_migration_path();
+
+ $proposal_data = lab_migration_get_proposal();
+ if (!$proposal_data) {
+ drupal_goto('');
+ return;
+ }
+
+ $dest_path .= 'DEPENDENCIES' . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+
+ /* uploading dependencies */
+ $file_upload_counter = 0;
+ $dependency_ids = array();
+ $dependency_names = array();
+
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* uploading file */
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ /* for uploaded files making an entry in the database */
+ $query = "INSERT INTO {lab_migration_dependency_files} (proposal_id, filename, filepath, filemime, filesize, caption, description, timestamp)
+ VALUES (:proposal_id, :filename, :filepath, :filemime, :filesize, :caption, :description, :timestamp)";
+ $args = array(
+ ":proposal_id" => $proposal_data->id,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => $_FILES['files']['type'][$file_form_name],
+ ":filesize" => $_FILES['files']['size'][$file_form_name],
+ ":caption" => check_plain($form_state['values'][$file_form_name . '_caption']),
+ ":description" => check_plain($form_state['values'][$file_form_name . '_description']),
+ ":timestamp" => time()
+ );
+ $dependency_ids[] = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ $dependency_names[] = $_FILES['files']['name'][$file_form_name];
+ $file_upload_counter++;
+ } else {
+ drupal_set_message('Error uploading dependency : ' . $dest_path . $_FILES['files']['name'][$file_form_name], 'error');
+ }
+ }
+ }
+
+ if ($file_upload_counter > 0)
+ {
+ drupal_set_message('Dependencies uploaded successfully.', 'status');
+
+ /* sending email */
+ $param['dependency_uploaded']['user_id'] = $user->uid;
+ $param['dependency_uploaded']['dependency_names'] = $dependency_names;
+
+ $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', '');
+ if (!drupal_mail('lab_migration', 'dependency_uploaded', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_goto('lab_migration/code/upload_dep');
+}
+
+function _list_existing_dependency($proposal_id)
+{
+ $return_html = '<ul>';
+ // $proposal_dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE proposal_id = %d ORDER BY filename ASC", $proposal_id);
+ $query = db_select('lab_migration_dependency_files');
+$query->fields('lab_migration_dependency_files');
+$query->condition('proposal_id', $proposal_id);
+$query->orderBy('filename', 'ASC');
+$proposal_dependency_files_q = $query->execute();
+
+ $counter = 0;
+ while ($proposal_dependency_files_data = $proposal_dependency_files_q->fetchObject())
+ {
+ $temp_caption = '';
+ if ($proposal_dependency_files_data->caption)
+ $temp_caption = ' (' . $proposal_dependency_files_data->caption . ')';
+ $return_html .= '<li>' . l($proposal_dependency_files_data->filename . $temp_caption, 'lab_migration/download/dependency/' . $proposal_dependency_files_data->id) . '</li>';
+ $counter++;
+ }
+ if ($counter == 0)
+ $return_html .= '<li>(None)</li>';
+ $return_html .= '</ul>';
+ return $return_html;
+}
+
diff --git a/dependency_approval.inc b/dependency_approval.inc
new file mode 100755
index 0000000..e8f5819
--- /dev/null
+++ b/dependency_approval.inc
@@ -0,0 +1,150 @@
+<?php
+
+/******************************************************************************/
+/********************************* BULK APPROVAL ******************************/
+/******************************************************************************/
+
+function lab_migration_dependency_approval_form($form, $form_state)
+{
+
+ /* default value for ahah fields */
+ if (!isset($form_state['values']['dependency']))
+ {
+ $dependency_default_value = 0;
+ } else {
+ $dependency_default_value = $form_state['values']['dependency'];
+ }
+
+ $form['wrapper'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Bulk Manage Code'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="run-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE,
+ );
+
+ $form['wrapper']['dependency'] = array(
+ '#type' => 'select',
+ '#title' => t('Dependency'),
+ '#options' => _list_of_dependencies(),
+ '#default_value' => $dependency_default_value,
+ '#tree' => TRUE,
+ '#attributes' => array('id' => 'dependancy'),
+ );
+
+ $form["wrapper"]['dependencyfiles'] = array(
+ '#markup' =>'<div id = "dependency-files"></div>',
+ );
+
+ $form['wrapper']['delete_dependency'] = array(
+ '#type' => 'checkbox',
+ "#description" => 'Please unlink the dependency from the above solutions before deleting it',
+ '#title' => t('Delete Dependency'),
+ '#prefix' => '<div id="delete-dependency-file">',
+ '#attributes' => array('id' => 'delete-dependancy'),
+ );
+ $form['wrapper']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ '#suffix' => '</div>',
+ );
+
+
+ return $form;
+}
+
+function lab_migration_dependency_approval_ajax($item="",$key=""){
+ $data = "";
+ $dependency_default_value = $key;
+ $solution_list = array();
+ //$solution_id_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE dependency_id = %d", $dependency_default_value);
+ $query = db_select('lab_migration_solution_dependency');
+ $query->fields('lab_migration_solution_dependency');
+ $query->condition('dependency_id', $dependency_default_value);
+ $solution_id_q = $query->execute();
+
+ while ($solution_id_data = $solution_id_q->fetchObject()) {
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d", $solution_id_data->solution_id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('id', $solution_id_data->solution_id);
+ $solution_q = $query->execute();
+ $solution_data = $solution_q->fetchObject();
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $solution_data->experiment_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('id', $solution_data->experiment_id);
+ $experiment_q = $query->execute();
+
+ $experiment_data = $experiment_q->fetchObject();
+ //$lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $experiment_data->proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $experiment_data->proposal_id );
+ $lab_q = $query->execute();
+ $lab_data = $lab_q->fetchObject();
+ $solution_list[] = array($solution_data->code_number, $experiment_data->number . ' . ' . $experiment_data->title, $lab_data->lab_title);
+ }
+ $solution_list_header = array('Code', 'Experiment', 'Lab');
+ //$solution = theme_table($solution_list_header, $solution_list);
+ $solution = theme('table', array('header' => $solution_list_header, 'rows' => $solution_list));
+ $data .= $solution;
+ echo $data;
+}
+
+
+function lab_migration_dependency_approval_form_submit($form, &$form_state)
+{
+ global $user;
+ $root_path = lab_migration_path();
+
+ if ($form_state['clicked_button']['#value'] == 'Submit')
+ {
+ if (user_access('bulk manage code'))
+ {
+ if ($form_state['values']['delete_dependency'] == "1")
+ {
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE dependency_id = %d", $form_state['values']['wrapper']['dependency']);
+
+ $query = db_select('lab_migration_solution_dependency');
+ $query->fields('lab_migration_solution_dependency');
+ $query->condition('dependency_id', $form_state['values']['dependency']);
+ $solution_q = $query->execute();
+ if ($solution_data = $solution_q->fetchObject()) {
+ drupal_set_message('Cannot delete dependency since it is linked with some solutions' , 'error');
+ } else {
+ if (lab_migration_delete_dependency($form_state['values']['dependency']))
+ {
+ drupal_set_message('Dependency deleted' , 'status');
+
+ /* email */
+ $email_subject = t('Dependency deleted');
+ $email_body = t('Dependency deleted : .') . $form_state['values']['dependency'];
+ $email_to = variable_get('lab_migration_emails', '') . ', ' . $user->mail;
+ $param['standard']['subject'] = $email_subject;
+ $param['standard']['body'] = $email_body;
+ if (!drupal_mail('lab_migration', 'standard', $email_to, language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ }
+ }
+ }
+ }
+ }
+}
+
+function _list_of_dependencies()
+{
+ $dependencies = array('0' => 'Please select...');
+ //$dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} ORDER BY filename ASC");
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->orderBy('filename', 'ASC');
+ $dependency_q = $query->execute();
+ while ($dependency_data = $dependency_q->fetchObject())
+ {
+ $dependencies[$dependency_data->id] = $dependency_data->filename . ' (' . $dependency_data->filepath . ')';
+ }
+ return $dependencies;
+}
diff --git a/download.inc b/download.inc
new file mode 100755
index 0000000..f84694b
--- /dev/null
+++ b/download.inc
@@ -0,0 +1,298 @@
+<?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/' . str_replace(' ','_',($dependency_file_data->filename)));
+ }
+ }
+ }
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+
+ if ($zip_file_count > 0)
+ {
+ if($user->uid) {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' .str_replace(' ', '_', $lab_data->lab_title) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ ob_clean();
+ //flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } else {
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' .str_replace(' ', '_', $lab_data->lab_title) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ ob_end_flush();
+ ob_clean();
+ flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ }
+ } else {
+ drupal_set_message("There are no solutions in this Lab to download", 'error');
+ drupal_goto('lab_migration_run');
+ }
+}
+
diff --git a/download.inc~ b/download.inc~
new file mode 100755
index 0000000..9e5fa33
--- /dev/null
+++ b/download.inc~
@@ -0,0 +1,298 @@
+<?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
new file mode 100755
index 0000000..440346e
--- /dev/null
+++ b/email.inc
@@ -0,0 +1,538 @@
+<?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 . '<br/> '.$experiment_data->description.' ';
+ }
+
+ $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 . '<br/> '.$experiment_data->description.' ';
+ }
+
+ $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 . '<br/> '.$experiment_data->description.' ';
+ }
+
+ $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 . '<br/> '.$experiment_data->description.' ';
+ }
+
+ $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 . '<br/> Description: '.$experiment_data->description.'<br/><br/> ';
+ }
+
+ $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/email.inc~ b/email.inc~
new file mode 100755
index 0000000..a241ebb
--- /dev/null
+++ b/email.inc~
@@ -0,0 +1,543 @@
+<?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/full_download.inc b/full_download.inc
new file mode 100755
index 0000000..31527ca
--- /dev/null
+++ b/full_download.inc
@@ -0,0 +1,252 @@
+<?php
+// $Id$
+
+function lab_migration_download_full_experiment()
+{
+ $experiment_id = arg(3);
+ $root_path = lab_migration_path();
+ $APPROVE_PATH = 'APPROVED/';
+ $PENDING_PATH = 'PENDING/';
+
+ /* get solution data */
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d", $experiment_id);
+ $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);
+
+ /* approved solutions */
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_id);
+ $query->condition('approval_status', 1);
+ $result = $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, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename);
+ }
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ // $dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $solution_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $dependency_file_data = $query->execute()->fetchObject();
+ if ($dependency_file_data)
+ $zip->addFile($root_path . $dependency_file_data->filepath, $APPROVE_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
+ }
+ }
+
+ /* unapproved solutions */
+ // $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 0", $experiment_id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_id);
+ $query->condition('approval_status', 0);
+ $solution_q = $query->execute();
+ while ($solution_row = $solution_q->fetchObject())
+ {
+ $CODE_PATH = 'CODE' . $solution_row->code_number . '/';
+ //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id);
+ $query = db_select('lab_migration_solution_files');
+ $query->fields('lab_migration_solution_files');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_files_q = $query->execute();
+ //$solution_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, $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename);
+ }
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ // $dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $solution_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $dependency_file_data = $query->execute()->fetchObject();
+ if ($dependency_file_data)
+ $zip->addFile($root_path . $dependency_file_data->filepath, $PENDING_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
+ }
+ }
+
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="EXP' . $experiment_data->number . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } else {
+ drupal_set_message("There are no solutions in this experiment to download", 'error');
+ drupal_goto('lab_migration/code_approval/bulk');
+ }
+}
+
+function lab_migration_download_full_lab()
+{
+ $lab_id = arg(3);
+ var_dump($lab_id);
+ //die;
+ $root_path = lab_migration_path();
+ $APPROVE_PATH = 'APPROVED/';
+ $PENDING_PATH = 'PENDING/';
+
+ /* get solution data */
+ //$lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $lab_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $lab_id);
+ $lab_q = $query->execute();
+ $lab_data = $lab_q->fetchObject();
+ $LAB_PATH = $lab_data->lab . '/';
+
+ /* zip filename */
+ $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
+
+ /* creating zip archive on the server */
+ $zip = new ZipArchive;
+ $zip->open($zip_filename, ZipArchive::CREATE);
+
+ /* approved solutions */
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $lab_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $lab_id);
+ $experiment_q = $query->execute();
+ while ($experiment_row = $experiment_q->fetchObject())
+ {
+ $EXP_PATH = 'EXP' . $experiment_row->number . '/';
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_row->id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_row->id);
+ $query->condition('approval_status', 1);
+ $solution_q = $query->execute();
+ while ($solution_row = $solution_q->fetchObject())
+ {
+ $CODE_PATH = 'CODE' . $solution_row->code_number . '/';
+ //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id);
+ $query = db_select('lab_migration_solution_files');
+ $query->fields('lab_migration_solution_files');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_files_q = $query->execute();
+ //$solution_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 . $APPROVE_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename);
+ }
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $solution_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $dependency_file_data = $query->execute()->fetchObject();
+ if ($dependency_file_data)
+ $zip->addFile($root_path . $dependency_file_data->filepath, $LAB_PATH . $APPROVE_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
+ }
+ }
+
+ /* unapproved solutions */
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 0", $experiment_row->id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_row->id);
+ $query->condition('approval_status', 0);
+ $solution_q = $query->execute();
+ while ($solution_row = $solution_q->fetchObject())
+ {
+ $CODE_PATH = 'CODE' . $solution_row->code_number . '/';
+ //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_row->id);
+ $query = db_select('lab_migration_solution_files');
+ $query->fields('lab_migration_solution_files');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_files_q = $query->execute();
+ //$solution_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 . $PENDING_PATH . $EXP_PATH . $CODE_PATH . $solution_files_row->filename);
+ }
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ //$dependency_file_data = (db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $solution_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $dependency_file_data = $query->execute()->fetchObject();
+ if ($dependency_file_data)
+ $zip->addFile($root_path . $dependency_file_data->filepath, $LAB_PATH . $PENDING_PATH . $EXP_PATH . $CODE_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
+ }
+ }
+ }
+
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ ob_clean();
+ //flush();
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . $lab_data->lab_title . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } else {
+ drupal_set_message("There are no solutions in this lab to download", 'error');
+ drupal_goto('lab_migration/code_approval/bulk');
+ }
+}
+
diff --git a/general_deletion.inc b/general_deletion.inc
new file mode 100755
index 0000000..b39fc4d
--- /dev/null
+++ b/general_deletion.inc
@@ -0,0 +1,268 @@
+<?php
+
+/******************************************************************************/
+/****************************** DELETION FUNCTIONS ****************************/
+/******************************************************************************/
+
+function lab_migration_delete_solution($solution_id)
+{
+ global $user;
+ $root_path = lab_migration_path();
+ $status = TRUE;
+
+ //$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.'), 'error');
+ return FALSE;
+ }
+
+ //$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();
+ if (!$experiment_data)
+ {
+ drupal_set_message(t('Invalid experiment.'), 'error');
+ return FALSE;
+ }
+
+ /* deleting solution files */
+ //$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();
+ while ($solution_files_data = $solution_files_q->fetchObject())
+ {
+ if (!file_exists($root_path . $solution_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $solution_files_data->filepath)), 'error');
+ continue;
+ }
+
+ /* removing solution file */
+ if (!unlink($root_path . $solution_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file', array('!file' => $solution_files_data->filepath)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting example file";
+ $param['standard']['body'] = "Error deleting solution files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ solution id : " . $solution_id . "
+ file id : " . $solution_files_data->id . "
+ file path : " . $solution_files_data->filepath;
+ 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 {
+ /* deleting example files database entries */
+
+ db_delete('lab_migration_solution_files')
+ ->condition('id', $solution_files_data->id)
+ ->execute();
+ }
+ }
+
+ if (!$status)
+ return FALSE;
+
+ /* removing code folder */
+ $ex_path = $experiment_data->proposal_id . '/EXP' . $experiment_data->number . '/CODE' . $solution_data->code_number;
+ $dir_path = $root_path . $ex_path;
+ if (is_dir($dir_path))
+ {
+ if (!rmdir($dir_path))
+ {
+ drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting folder";
+ $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ 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');
+ return FALSE;
+ }
+ } else {
+ drupal_set_message(t('Cannot delete solution folder. !folder does not exists.', array('!folder' => $dir_path)), 'error');
+ return FALSE;
+ }
+
+ /* deleting solution dependency and solution database entries */
+ db_delete('lab_migration_solution_dependency')->condition('solution_id', $solution_id)->execute();
+
+ db_delete('lab_migration_solution')->condition('id', $solution_id)->execute();
+
+ return $status;
+}
+
+function lab_migration_delete_experiment($experiment_id)
+{
+ $status = TRUE;
+ $root_path = lab_migration_path();
+
+ //$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();
+ if (!$experiment_data)
+ {
+ drupal_set_message('Invalid experiment.', 'error');
+ return FALSE;
+ }
+
+ /* deleting solutions */
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d", $experiment_id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_id);
+ $solution_q = $query->execute();
+
+ $delete_exp_folder = FALSE;
+ while ($solution_data = $solution_q->fetchObject())
+ {
+ $delete_exp_folder = TRUE;
+ if (!lab_migration_delete_solution($solution_data->id))
+ $status = FALSE;
+ }
+
+ if (!$delete_exp_folder)
+ {
+ return TRUE;
+ }
+
+ if ($status)
+ {
+ $dir_path = $root_path . $experiment_data->proposal_id . '/EXP' . $experiment_data->number;
+
+ if (is_dir($dir_path))
+ {
+ $res = rmdir($dir_path);
+ if (!$res)
+ {
+ drupal_set_message(t('Error deleting experiment folder !folder', array('!folder' => $dir_path)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting experiment folder";
+ $param['standard']['body'] = "Error deleting folder " . $dir_path;
+ 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');
+ return FALSE;
+ } else {
+ return TRUE;
+ }
+ } else {
+ drupal_set_message(t('Cannot delete experiment folder. !folder does not exists.', array('!folder' => $dir_path)), 'error');
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
+function lab_migration_delete_lab($lab_id)
+{
+ $status = TRUE;
+ $root_path = lab_migration_path();
+
+ //$proposal_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);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message('Invalid Lab.', 'error');
+ return FALSE;
+ }
+
+ /* delete experiments */
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_data->id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_data->id);
+ $experiment_q = $query->execute();
+
+
+ while ($experiment_data = $experiment_q->fetchObject())
+ {
+ if (!lab_migration_delete_experiment($experiment_data->id))
+ {
+ $status = FALSE;
+ }
+ }
+ return $status;
+}
+
+function lab_migration_del_lab_pdf($lab_id)
+{
+ $root_path = lab_migration_path();
+ $dir_path = $root_path . "latex/";
+ $pdf_filename = "lab_" . $lab_id . ".pdf";
+ if (file_exists($dir_path . $pdf_filename))
+ unlink($dir_path . $pdf_filename);
+}
+
+
+function lab_migration_delete_dependency($dependency_id)
+{
+ global $user;
+ $root_path = lab_migration_path();
+ $status = TRUE;
+
+ //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_id);
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $dependency_id);
+ $dependency_files_q = $query->execute();
+ $dependency_files_data = $dependency_files_q->fetchObject();
+ if (!$dependency_files_data)
+ {
+ drupal_set_message(t('Invalid dependency.'), 'error');
+ return FALSE;
+ }
+
+ if (!file_exists($root_path . $dependency_files_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $dependency_files_data->filepath)), 'error');
+ return FALSE;
+ }
+
+ /* removing dependency file */
+ if (!unlink($root_path . $dependency_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file', array('!file' => $dependency_files_data->filepath)), 'error');
+
+ /* sending email to admins */
+ $email_to = variable_get('lab_migration_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting dependency file";
+ $param['standard']['body'] = "Error deleting dependency files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ dependency id : " . $dependency_id . "
+ file id : " . $dependency_files_data->id . "
+ file path : " . $dependency_files_data->filepath;
+ 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 {
+ /* deleting dependency files database entries */
+ db_delete('lab_migration_dependency_files')
+ ->condition('id', $dependency_id)
+ ->execute();
+ }
+
+ return $status;
+}
+
diff --git a/lab_details.inc b/lab_details.inc
new file mode 100755
index 0000000..59898da
--- /dev/null
+++ b/lab_details.inc
@@ -0,0 +1,40 @@
+<?php
+ function lab_migration_completed_labs_all() {
+ $page_content = "";
+ //$query = "SELECT * FROM {lab_migration_proposal} WHERE approval_status = 3";
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('approval_status', 3);
+ $result = $query->execute();
+ //$result = db_query($query);
+ $proposal_rows = array();
+ $i=1;
+ while($row = $result->fetchObject()) {
+ $approval_date=date("Y", $row->approval_date);
+ $preference_rows[] = array($i, $row->university , l($row->lab_title,"lab_migration_run/".$row->id),$approval_date);
+ $i++;
+ }
+ $preference_header = array('No','Institute', 'Lab', 'Year');
+ $output = theme('table', array('header' => $preference_header, 'rows' => $preference_rows));
+ return $output;
+ }
+
+ function lab_migration_labs_progress_all() {
+ $page_content = "";
+ //$query = "SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 and solution_status = 2";
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('approval_status', 1);
+ $query->condition('solution_status', 2);
+ $result = $query->execute();
+ //$result = db_query($query);
+ $page_content .= "<ol>";
+ while($row = $result->fetchObject()) {
+ $page_content .= "<li>";
+ $page_content .= $row->university . " ({$row->lab_title})";
+ $page_content .= "</li>";
+ }
+ $page_content .= "</ol>";
+ return $page_content;
+ }
+?>
diff --git a/lab_migration.info b/lab_migration.info
new file mode 100755
index 0000000..431f488
--- /dev/null
+++ b/lab_migration.info
@@ -0,0 +1,7 @@
+name = "Lab Migration"
+description = "IIT Bombay Lab Migration project"
+package = IITB
+version = "7.x-1.3"
+core = "7.x"
+
+;scripts[] = js/jquery-1.4.1.min.js
diff --git a/lab_migration.info~ b/lab_migration.info~
new file mode 100755
index 0000000..431f488
--- /dev/null
+++ b/lab_migration.info~
@@ -0,0 +1,7 @@
+name = "Lab Migration"
+description = "IIT Bombay Lab Migration project"
+package = IITB
+version = "7.x-1.3"
+core = "7.x"
+
+;scripts[] = js/jquery-1.4.1.min.js
diff --git a/lab_migration.install b/lab_migration.install
new file mode 100755
index 0000000..6589a42
--- /dev/null
+++ b/lab_migration.install
@@ -0,0 +1,431 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function lab_migration_install() {
+ // Create tables.
+ drupal_install_schema('lab_migration');
+ variable_set('lab_migration_emails', '');
+ variable_set('lab_migration_from_email', '');
+ variable_set('lab_migration_source_extensions', '');
+ variable_set('lab_migration_dependency_extensions', '');
+ variable_set('lab_migration_result_extensions', '');
+ variable_set('lab_migration_xcos_extensions', '');
+
+ // create uploads folder
+ $upload_path = $_SERVER['DOCUMENT_ROOT'] . base_path() . 'lab_migration_uploads';
+ if (!is_dir($upload_path))
+ mkdir($upload_path);
+ if (!is_dir($upload_path . '/latex'))
+ mkdir($upload_path . '/latex');
+ if (!is_dir($upload_path . '/DEPENDENCIES'))
+ mkdir($upload_path . '/DEPENDENCIES');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function lab_migration_uninstall() {
+ // Remove tables.
+ drupal_uninstall_schema('lab_migration');
+ // Remove variables
+ variable_del('lab_migration_emails');
+ variable_del('lab_migration_from_email');
+ variable_del('lab_migration_source_extensions');
+ variable_del('lab_migration_dependency_extensions');
+ variable_del('lab_migration_result_extensions');
+ variable_del('lab_migration_xcos_extensions');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function lab_migration_schema() {
+
+ /* proposal */
+ $schema['lab_migration_proposal'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'name_title' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '5',
+ 'not null' => TRUE,
+ ),
+ 'name' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'contact_ph' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '15',
+ 'not null' => TRUE,
+ ),
+ 'department' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'university' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'lab_title' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'category' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'solution_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'solution_display' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'creation_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approval_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'solution_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'expected_completion_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'message' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_name_title' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '5',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_name' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_contact_ph' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '15',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_department' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'solution_provider_university' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* experiment */
+ $schema['lab_migration_experiment'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'proposal_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'number' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'title' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* solution */
+ $schema['lab_migration_solution'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'experiment_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'code_number' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '10',
+ 'not null' => TRUE,
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'approval_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* solution files */
+ $schema['lab_migration_solution_files'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'solution_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'filename' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filepath' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE,
+ ),
+ 'filemime' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filesize' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'filetype' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '1',
+ 'not null' => TRUE,
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE,
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* depedency files */
+ $schema['lab_migration_dependency_files'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'proposal_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'filename' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filepath' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE,
+ ),
+ 'filemime' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE,
+ ),
+ 'filesize' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE,
+ ),
+ 'description' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE,
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* dependency files - links */
+ $schema['lab_migration_solution_dependency'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'solution_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'dependency_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ /* notes */
+ $schema['lab_migration_notes'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE,
+ ),
+ 'proposal_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE,
+ ),
+ 'notes' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('id'),
+ );
+
+ return $schema;
+}
+
diff --git a/lab_migration.module b/lab_migration.module
new file mode 100755
index 0000000..c1b2072
--- /dev/null
+++ b/lab_migration.module
@@ -0,0 +1,636 @@
+<?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/lab_migration.module~ b/lab_migration.module~
new file mode 100755
index 0000000..735a40c
--- /dev/null
+++ b/lab_migration.module~
@@ -0,0 +1,636 @@
+<?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/latex.inc b/latex.inc
new file mode 100755
index 0000000..c6778a6
--- /dev/null
+++ b/latex.inc
@@ -0,0 +1,261 @@
+<?php
+
+function lab_migration_download_lab_pdf()
+{
+ $lab_id = arg(2);
+ _latex_copy_script_file();
+ $full_lab = arg(3);
+ if ($full_lab == "1"){
+ _latex_generate_files($lab_id, TRUE);
+ }else{
+ _latex_generate_files($lab_id, FALSE);
+}
+}
+
+
+/* full lab parameter is for gennerating the entire lab pdf including all unapproved solutions */
+function _latex_generate_files($lab_id, $full_lab = FALSE)
+{
+
+ $root_path = lab_migration_path();
+ $dir_path = $root_path . "latex/";
+
+ $lab_filedata = "";
+ $solution_provider_filedata = "";
+ $latex_filedata = "";
+ $latex_dep_filedata = "";
+
+ $depedency_list = array();
+
+ $eol = "\n";
+ $sep = "#";
+
+ //$proposal_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);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message('Invalid lab specified.', 'error');
+ drupal_goto('');
+ }
+ if ($proposal_data->approval_status == 0)
+ {
+ drupal_set_message('Lab proposal is still in pending review.', 'error');
+ drupal_goto('');
+ }
+
+ $category_data = '';
+ switch ($proposal_data->category)
+ {
+ case 0: $category_data = 'Not Selected'; break;
+ case 1: $category_data = 'Fluid Mechanics'; break;
+ case 2: $category_data = 'Control Theory & Control Systems'; break;
+ case 3: $category_data = 'Chemical Engineering'; break;
+ case 4: $category_data = 'Thermodynamics'; break;
+ case 5: $category_data = 'Mechanical Engineering'; break;
+ case 6: $category_data = 'Signal Processing'; break;
+ case 7: $category_data = 'Digital Communications'; break;
+ case 8: $category_data = 'Electrical Technology'; break;
+ case 9: $category_data = 'Mathematics & Pure Science'; break;
+ case 10: $category_data = 'Analog Electronics'; break;
+ case 11: $category_data = 'Digital Electronics'; break;
+ case 12: $category_data = 'Computer Programming'; break;
+ case 13: $category_data = 'Others'; break;
+ default: $category_data = 'Unknown'; break;
+ }
+
+ $lab_filedata = $proposal_data->lab_title . $sep . $proposal_data->name_title . $sep . $proposal_data->name . $sep . $proposal_data->department . $sep . $proposal_data->university . $sep . $category_data . $eol;
+
+ /* regenerate lab if full lab selected */
+ if ($full_lab){
+ lab_migration_del_lab_pdf($proposal_data->id);
+}
+ /* check if lab already generated */
+ if (file_exists($dir_path . "lab_" . $proposal_data->id . ".pdf"))
+ {
+ /* download zip file */
+ header('Content-Type: application/pdf');
+ header('Content-disposition: attachment; filename="' . $proposal_data->lab_title . '.pdf"');
+ header('Content-Length: ' . filesize($dir_path . "lab_" . $proposal_data->id . ".pdf"));
+ readfile($dir_path . "lab_" . $proposal_data->id . ".pdf");
+ return;
+ }
+
+ $solution_provider_user = user_load($proposal_data->solution_provider_uid);
+ if (!$solution_provider_user)
+ {
+ drupal_set_message('Could not fetch solution provider information for the lab specified.', 'error');
+ }
+ $solution_provider_filedata .= $proposal_data->solution_provider_name_title . $sep . $proposal_data->solution_provider_name . $sep . $proposal_data->solution_provider_department . $sep . $proposal_data->solution_provider_university . $eol;
+
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number DESC", $proposal_data->id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->orderBy('number', 'DESC');
+ $experiment_q = $query->execute();
+ while ($experiment_data = $experiment_q->fetchObject())
+ {
+ if ($full_lab){
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY code_number DESC", $experiment_data->id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_data->id);
+ $query->orderBy('code_number', 'DESC');
+ $solution_q = $query->execute();
+ }else{
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d AND approval_status = 1 ORDER BY code_number DESC", $experiment_data->id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_data->id);
+ $query->condition('approval_status', 1);
+ $query->orderBy('code_number', 'DESC');
+ $solution_q = $query->execute();
+}
+ while ($solution_data = $solution_q->fetchObject())
+ {
+ //$solution_files_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $solution_data->id);
+ $query = db_select('lab_migration_solution_files');
+ $query->fields('lab_migration_solution_files');
+ $query->condition('solution_id', $solution_data->id);
+ $solution_files_q = $query->execute();
+ while ($solution_files_data = $solution_files_q->fetchObject())
+ {
+ $latex_filedata .= $experiment_data->number . $sep;
+ $latex_filedata .= $experiment_data->title . $sep;
+ $latex_filedata .= $solution_data->code_number . $sep;
+ $latex_filedata .= $solution_data->caption . $sep;
+ $latex_filedata .= $solution_files_data->filename . $sep;
+ $latex_filedata .= $solution_files_data->filepath . $sep;
+ $latex_filedata .= $solution_files_data->filetype . $sep;
+ $latex_filedata .= $sep;
+ $latex_filedata .= $solution_files_data->id;
+ $latex_filedata .= $eol;
+ }
+ //$dependency_files_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $solution_data->id);
+ $query = db_select('lab_migration_solution_dependency');
+ $query->fields('lab_migration_solution_dependency');
+ $query->condition('solution_id', $solution_data->id);
+ $dependency_files_q = $query->execute();
+ while ($dependency_files_data = $dependency_files_q->fetchObject())
+ {
+ //$dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $dependency_files_data->dependency_id);
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $dependency_files_data->dependency_id);
+ $query->range(0, 1);
+ $dependency_q = $query->execute();
+ if ($dependency_data = $dependency_q->fetchObject())
+ {
+ if(substr($dependency_data->filename, -3) != "wav") {
+ $latex_filedata .= $experiment_data->number . $sep;
+ $latex_filedata .= $experiment_data->title . $sep;
+ $latex_filedata .= $solution_data->code_number . $sep;
+ $latex_filedata .= $solution_data->caption . $sep;
+ $latex_filedata .= $dependency_data->filename . $sep;
+ $latex_filedata .= $dependency_data->filepath . $sep;
+ $latex_filedata .= 'D' . $sep;
+ $latex_filedata .= $dependency_data->caption . $sep;
+ $latex_filedata .= $dependency_data->id;
+ $latex_filedata .= $eol;
+
+ $depedency_list[$dependency_data->id] = "D";
+ }
+
+ }
+ }
+ }
+ }
+
+ foreach ($depedency_list as $row => $data) {
+ //$dependency_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d LIMIT 1", $row);
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $row);
+ $query->range(0, 1);
+ $dependency_q = $query->execute();
+ if ($dependency_data = $dependency_q->fetchObject())
+ {
+ $latex_dep_filedata .= $dependency_data->filename . $sep;
+ $latex_dep_filedata .= $dependency_data->filepath . $sep;
+ $latex_dep_filedata .= $dependency_data->caption . $sep;
+ $latex_dep_filedata .= $dependency_data->id;
+ $latex_dep_filedata .= $eol;
+ }
+ }
+
+ /**************************** WRITE TO FILES ********************************/
+ $download_filename = $proposal_data->lab;
+ $lab_filename = "tmp_" . $proposal_data->id . "_lab.txt";
+ $solution_provider_filename = "tmp_" . $proposal_data->id . "_solution_provider.txt";
+ $latex_filename = "tmp_" . $proposal_data->id . "_data.txt";
+ $latex_dep_filename = "tmp_" . $proposal_data->id . "_dep_data.txt";
+ $pdf_filename = "lab_" . $proposal_data->id . ".pdf";
+
+ $fb = fopen($dir_path . $lab_filename, 'w');
+ fwrite($fb, $lab_filedata);
+ fclose($fb);
+
+ $fc = fopen($dir_path . $solution_provider_filename, 'w');
+ fwrite($fc, $solution_provider_filedata);
+ fclose($fc);
+
+ $fl = fopen($dir_path . $latex_filename, 'w');
+ fwrite($fl, $latex_filedata);
+ fclose($fl);
+
+ $fd = fopen($dir_path . $latex_dep_filename, 'w');
+ fwrite($fd, $latex_dep_filedata);
+ fclose($fd);
+ if (_latex_run_script($lab_filename, $solution_provider_filename, $latex_filename, $latex_dep_filename, $pdf_filename))
+ {
+ /* download zip file */
+ header('Content-Type: application/pdf');
+ header('Content-disposition: attachment; filename="' . $proposal_data->lab_title . '_' . $proposal_data->name_title . '_' . $proposal_data->name . '.pdf"');
+ header('Content-Length: ' . filesize($dir_path . $pdf_filename));
+ readfile($dir_path . $pdf_filename);
+ } else {
+ drupal_set_message("Error occurred when generating the PDF version of the Book.", 'error');
+ }
+
+ /*********************** DELETING TEMPORARY FILES ***************************/
+ /* regenerate lab if full lab selected */
+ if ($full_lab)
+ lab_migration_del_lab_pdf($proposal_data->id);
+}
+
+function _latex_copy_script_file()
+{
+ exec("cp ./" . drupal_get_path('module', 'lab_migration') . "/latex/* " . lab_migration_path() . "latex");
+ exec("chmod u+x ./uploads/latex/*.sh");
+}
+
+function _latex_run_script($lab_filename, $solution_provider_filename, $latex_filename, $latex_dep_filename, $pdf_filename)
+{
+ $root_path = lab_migration_path();
+ $ret = 0;
+ chdir("lab_migration_uploads");
+ chdir("latex");
+
+ $sh_command = "./pdf_creator.sh " . $lab_filename . " " . $solution_provider_filename . " " . $latex_filename . " " . $latex_dep_filename;
+ exec($sh_command);
+ exec("mv TEX_final.pdf " . $pdf_filename);
+
+ if ($ret == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+function lab_migration_delete_lab_pdf()
+{
+ $lab_id = arg(3);
+ lab_migration_del_lab_pdf($lab_id);
+ drupal_set_message(t('Lab schedule for regeneration.'), 'status');
+ drupal_goto('lab_migration/code_approval/bulk');
+ return;
+}
+
diff --git a/latex/Initial_body b/latex/Initial_body
new file mode 100755
index 0000000..53e82b4
--- /dev/null
+++ b/latex/Initial_body
@@ -0,0 +1,58 @@
+\nonstopmode
+\documentclass[12pt]{report}
+\usepackage{hyperref}
+\hypersetup{colorlinks=true,linkcolor=blue}
+\usepackage{theorem,graphicx}
+\usepackage{listings,alltt}
+\bibliographystyle{plain}
+
+
+\lstset{ %configuring the display of scilab codes
+ tabsize=4,
+ language=scilab,
+ basicstyle=\ttfamily,
+ aboveskip={1\baselineskip},
+ showstringspaces=false,
+ breaklines=true,
+ showspaces=false,
+ numbers=left,
+ numberstyle=\small,
+ stringstyle=\normalfont,
+ keywordstyle=\color{red},
+ emph={clc, all, gca},
+ emphstyle=\color{red},
+ commentstyle=\color{blue}\normalfont}
+
+
+% code environment
+{\theorembodyfont{\rmfamily} \newtheorem{codemass}{Scilab code}[chapter]}
+\newenvironment{code}%
+{\begin{codemass}}{\hrule \end{codemass}}
+
+{\theorembodyfont{\rmfamily} \newtheorem{accmass}{Acc}[chapter]}
+\newenvironment{acc-code}%
+{\begin{accmass}}{\end{accmass}}
+
+
+% create listing for code
+
+\newcommand\tcaption[1]
+ {\addcontentsline{cod}{section}{\protect\numberline {\thecodemass}#1}}
+\makeatletter \newcommand\listofcode
+ {\chapter*{List of Experiments\markboth%
+ {\bf List of Scilab Codes}{}}%
+\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{5em}}%
+\addcontentsline{toc}{chapter}{\protect\numberline{List of Scilab Solutions}}
+\@starttoc{cod}}
+\newcommand\l@matlab[3]
+ {#1 \par\noindent#2, #3 \par}
+\renewcommand\@pnumwidth{2.1em}
+%\makeatother
+
+\makeatletter
+\def\curlable#1{\def\thecodemass{#1}\def\@currentlabel{#1}}
+\makeatother
+
+\newcommand{\coderef}[1]{Exa~\ref{#1}}
+\newcommand{\figref}[1]{Fig.~\ref{#1}}
+\renewcommand{\chaptername}{Experiment:}
diff --git a/latex/latex_test.sh b/latex/latex_test.sh
new file mode 100755
index 0000000..da6554a
--- /dev/null
+++ b/latex/latex_test.sh
@@ -0,0 +1,199 @@
+#!/bin/bash
+clear
+Bk_details=$1
+Contrib_details=$2
+Data_all=$3
+Dep_dat=$4
+
+CURDIR=$PWD;
+
+if [ -a /$CURDIR/TEX ]
+then
+rm TEX
+fi
+
+if [ -a /$CURDIR/TEX_dep ]
+then
+rm TEX_dep
+fi
+
+if [ -a /$CURDIR/TEX_new ]
+then
+rm TEX_new
+fi
+
+
+IFS_old="$IFS"
+IFS=# read col1 col2 col3 col4 < $Contrib_details;
+IFS=# read colB1 colB2 colB3 colB4 colB5 colB6 < $Bk_details;
+col1=${col1/&/\\&};
+col2=${col2/&/\\&};
+col3=${col3/&/\\&};
+col4=${col4/&/\\&};
+colB1=${colB1/&/\\&};
+colB2=${colB2/&/\\&};
+colB3=${colB3/&/\\&};
+colB4=${colB4/&/\\&};
+colB5=${colB5/&/\\&};
+colB6=${colB6/&/\\&};
+echo \\title\{Scilab Manual \for "\\\\"$colB1"\\\\"by $colB2 $colB3""\\\\$colB4""\\\\$colB5"\\footnote{Funded by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro. This Scilab Manual and Scilab codes written in it can be downloaded from the \"Migrated Labs\" section at the website http://scilab.in}}" >>$CURDIR/TEX
+
+echo \\author\{ Solutions provided by \\\\$col1 $col2\\\\$col3\\\\$col4\\\\ }>>$CURDIR/TEX
+
+IFS="$IFS_old"
+
+echo \\date{\\today}>>$CURDIR/TEX
+echo \\begin{document}>>$CURDIR/TEX
+echo \\maketitle >>$CURDIR/TEX
+
+#echo >>$CURDIR/TEX
+#echo \\chapter*{Book Description}>>$CURDIR/TEX
+#echo \\begin{description}>>$CURDIR/TEX
+#echo \\item [Title:] ${colB1}>>$CURDIR/TEX
+#echo \\item [Author:] ${colB2}>>$CURDIR/TEX
+#echo \\item [Publisher:] ${colB4}>>$CURDIR/TEX
+#echo \\item [Edition:] ${colB5}>>$CURDIR/TEX
+#echo \\item [Year:] ${colB6}>>$CURDIR/TEX
+#echo \\item [ISBN:] ${colB3}>>$CURDIR/TEX
+#echo \\end{description}>>$CURDIR/TEX
+echo >> $CURDIR/TEX
+
+echo \\newpage >> $CURDIR/TEX
+echo \\vspace*{3cm}>>$CURDIR/TEX
+
+#echo Scilab numbering policy used in this document and the relation to the above book.>>$CURDIR/TEX
+#echo \\begin{description}>>$CURDIR/TEX
+#echo \\item[Exa] Example \(Solved example\)>>$CURDIR/TEX
+#echo \\item[Eqn] Equation \(Particular equation of the above book\)>>$CURDIR/TEX
+#echo \\item[AP] Appendix to Example\(Scilab Code that is an Appednix to a particular Example of the above book\)>>$CURDIR/TEX
+#echo \\end{description}>>$CURDIR/TEX
+#echo "For example, Exa~3.51 means solved example 3.51 of this book. Sec~2.3 means a scilab code whose theory is explained in Section 2.3 of the book.">>$CURDIR/TEX
+#echo>>$CURDIR/TEX
+
+echo \\tableofcontents >>$CURDIR/TEX
+echo \\listofcode >>$CURDIR/TEX
+ if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $Data_all
+ then
+ echo \\listoffigures >>$CURDIR/TEX
+ fi
+echo>> $CURDIR/TEX
+j=0;
+k=1;
+#sort -t '#' -k 3,3 -k 1,1 -g $Data_all > database_sort
+sort -t '.' -k 1,1n -k 2,2n -k 3,3n -k 4,4n $Data_all > database_sort
+
+while IFS=# read col1 col2 col3 col4 col5 col6 col7 col8 col9; do
+col2=${col2/&/\\&};
+col3=${col3/&/\\&};
+col4=${col4/&/\\&};
+col8=${col8/&/\\&};
+##################
+col7=${col7/&/\\&};
+col8=${col8/&/\\&};
+col9=${col9/&/\\&};
+#################
+
+chap_diff=$(($col1 - $j))
+if [ $chap_diff -eq 1 ]; then
+ echo \\chapter{$col2}>>$CURDIR/TEX
+ echo >>$CURDIR/TEX
+fi
+
+if [ $chap_diff -gt 1 ]; then
+ echo >>$CURDIR/TEX
+ echo \\setcounter{chapter}{$(($col1-1))}>>$CURDIR/TEX
+ echo \\chapter{$col2}>>$CURDIR/TEX
+ echo >>$CURDIR/TEX
+
+fi
+
+if [ $col7 != D ]
+then
+echo \\vspace*{10mm}>>$CURDIR/TEX
+fi
+
+
+if [ $col7 = S ]
+then
+ echo \\curlable{Solution~$col3} >> $CURDIR/TEX
+ echo \\begin{code} >> $CURDIR/TEX
+ echo \\tcaption{$col4}{$col4} >> $CURDIR/TEX
+ echo \\lstinputlisting{../$col6} >> $CURDIR/TEX
+ echo \\end{code} >> $CURDIR/TEX
+ echo >>$CURDIR/TEX
+fi
+
+if [ $col7 = D ]
+then
+#echo check Appendix \\ref{AP:$col9} for dependency \$$col5\$ >> $CURDIR/TEX
+echo check Appendix \\ref{AP:$col9} for dependency: {\\begin{alltt} \\hspace{2mm} $col5 \\end{alltt}} >> $CURDIR/TEX
+echo >> $CURDIR/TEX
+fi
+
+
+if [ $col7 = X ]
+then
+echo This code can be downloaded from the website wwww.scilab.in >> $CURDIR/TEX
+fi
+
+if [ $col7 = R ]
+then
+echo $col6 > $CURDIR/Figure_files
+ if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $CURDIR/Figure_files
+ then
+
+ echo \\curlable{Fig~$col3} >> $CURDIR/TEX
+ echo \\begin{figure} >> $CURDIR/TEX
+ echo \\includegraphics[scale=0.5]{../$col6} >> $CURDIR/TEX
+ echo \\caption{$col4} >> $CURDIR/TEX
+ echo \\end{figure} >> $CURDIR/TEX
+ echo >> $CURDIR/TEX
+ fi
+
+fi
+
+j=$col1
+done < database_sort
+rm -f Figure_files
+
+
+if [ -s $Dep_dat ]
+then
+
+i=1;
+echo \\chapter*{Appendix} >>$CURDIR/TEX
+
+while IFS=# read col1 col2 col3 col4; do
+col3=${col3/&/\\&};
+echo \\curlable{AP~$i} >> $CURDIR/TEX;
+echo $col2 > $CURDIR/image_files
+ if grep -c ".jpg\|.JPEG\|.png\|.jpeg\|.JPG" $CURDIR/image_files
+ then
+
+ echo \\begin{figure} >> $CURDIR/TEX
+ echo \\includegraphics[scale=0.5]{../$col2} >> $CURDIR/TEX
+ echo \\tcaption {$col3}{$col3} >> $CURDIR/TEX
+ echo \\end{figure} >> $CURDIR/TEX
+ echo >> $CURDIR/TEX
+ else
+ echo \\begin{code} >> $CURDIR/TEX;
+ echo \\label{AP:$col4} >> $CURDIR/TEX
+ echo \\lstinputlisting{../$col2} >> $CURDIR/TEX
+ echo \\tcaption {$col3}{$col3} >> $CURDIR/TEX
+ echo \\end{code} >> $CURDIR/TEX
+ echo >> $CURDIR/TEX
+
+ fi
+##############
+#if [ $col2 = *.jpg] then echo \\includegraphics[scale=0.5]{../$col2} >> $CURDIR/TEX else
+###############
+#echo \\lstinputlisting{../$col2} >> $CURDIR/TEX
+#fi
+let "i+=1"
+done < $Dep_dat
+rm -f image_files
+fi
+
+cat Initial_body TEX > TEX_final.tex
+echo \\end{document} >> $CURDIR/TEX_final.tex
+#clear
diff --git a/latex/pdf_creator.sh b/latex/pdf_creator.sh
new file mode 100755
index 0000000..1635e6d
--- /dev/null
+++ b/latex/pdf_creator.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+
+if [ -f TEX_final.tex ]
+then
+ rm -f TEX_final.*
+ rm -f database_sort
+ rm -f database_sort.csv
+ rm -f TEX
+fi
+
+./latex_test.sh $1 $2 $3 $4
+pdflatex TEX_final.tex > log.txt
+pdflatex TEX_final.tex >> log1.txt
+pdflatex TEX_final.tex >> log1.txt
+pdflatex TEX_final.tex >> log1.txt
+
+rm log1.txt
diff --git a/manage_proposal.inc b/manage_proposal.inc
new file mode 100755
index 0000000..3687d3e
--- /dev/null
+++ b/manage_proposal.inc
@@ -0,0 +1,1279 @@
+<?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','Action');
+ $output = theme('table', array('header' => $proposal_header, 'rows' => $proposal_rows ));
+ return $output;
+}
+
+function lab_migration_category_all()
+{
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} ORDER BY id DESC");
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->orderBy('id', 'DESC');
+ $proposal_q = $query->execute();
+ while ($proposal_data = $proposal_q->fetchObject())
+ {
+ 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, $form_state)
+{
+ global $user;
+
+ /* get current proposal */
+ $proposal_id = (int)arg(3);
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+ // var_dump($proposal_data->name_title);
+ // die;
+ $form['name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid),
+ '#title' => t('Name'),
+ );
+ $form['email_id'] = array(
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contact_ph'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contact_ph,
+ '#title' => t('Contact No.'),
+ );
+ $form['department'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->department,
+ '#title' => t('Department/Branch'),
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->university,
+ '#title' => t('University/Institute'),
+ );
+ $form['country'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->country,
+ '#title' => t('Country'),
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State'),
+ );
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->city,
+ '#title' => t('City'),
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode/Postal code'),
+ );
+ $form['lab_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->lab_title,
+ '#title' => t('Title of the Lab'),
+ );
+
+ /* get experiment details */
+ $experiment_list = '<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.dwsim.fossee.in website'),
+ '#markup' => ($proposal_data->solution_display == 1) ? "Yes" : "No",
+ );*/
+
+ $form['approval'] = array(
+ '#type' => 'radios',
+ '#title' => t('Lab migration proposal'),
+ '#options' => array('1' => 'Approve', '2' => 'Disapprove'),
+ '#required' => TRUE,
+ );
+
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Reason for disapproval'),
+ '#attributes' =>array('placeholder' => t('Enter reason for disapproval in minimum 30 characters '), 'cols' => 50, 'rows' => 4),
+ );
+
+ $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,$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.dwsim.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, $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' => 'hidden',
+ '#title' => t('Do you want to display the solution on the www.dwsim.fossee.in website'),
+ '#options' => array('1' => 'Yes'),
+ '#required' => TRUE,
+ // '#default_value' => ($proposal_data->solution_display == 1) ? "1" : "2",
+ '#default_value'=>'1',
+ );
+
+ $form['delete_proposal'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Proposal')
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'lab-migration/manage-proposal'),
+ );
+ return $form;
+}
+
+function lab_migration_proposal_edit_form_validate($form, &$form_state)
+{
+ $proposal_id = (int)arg(3);
+
+ /* check before delete proposal */
+ if ($form_state['values']['delete_proposal'] == 1) {
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_id);
+ $experiment_q = $query->execute();
+ while ($experiment_data = $experiment_q->fetchObject()) {
+ //$solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d", $experiment_data->id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $experiment_data->id);
+ $solution_q = $query->execute();
+
+ if ($solution_q->fetchObject()) {
+ form_set_error('', t('Cannot delete proposal since there are solutions already uploaded. Use the "Bulk Manage" interface to delete this proposal'));
+ }
+ }
+ }
+ return;
+}
+
+function lab_migration_proposal_edit_form_submit($form, &$form_state)
+{
+ global $user;
+
+ /* get current proposal */
+ $proposal_id = (int)arg(3);
+ // $proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+
+ /* delete proposal */
+ if ($form_state['values']['delete_proposal'] == 1) {
+ //db_query("DELETE FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_delete('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $num_deleted = $query->execute();
+ //db_query("DELETE FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id);
+ $query = db_delete('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_id);
+ $num_deleted = $query->execute();
+ drupal_set_message(t('Proposal Delete'), 'status');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+
+ if ($form_state['values']['open_solution'] == 1) {
+ // $query = "UPDATE {lab_migration_proposal} SET solution_provider_uid = :solution_provider_uid, solution_status = :solution_status, solution_provider_name_title = '', solution_provider_name = '', solution_provider_contact_ph = '', solution_provider_department = '', solution_provider_university = '' WHERE id = :proposal_id";
+ // $args= array(
+ // ":solution_provider_uid" => 0,
+ // ":solution_status" => 0,
+ // ":proposal_id" => $proposal_id,
+ // );
+
+ // $result = db_query($query, $args);
+
+
+
+ $result = db_update('lab_migration_proposal')
+ ->fields(array(
+ 'solution_provider_uid' => 0,
+ 'solution_status' => 0,
+ 'solution_provider_name_title' => '',
+ 'solution_provider_name' => '',
+ 'solution_provider_contact_ph' => '',
+ 'solution_provider_department' => '',
+ 'solution_provider_university' => '',
+ ))
+ ->condition('id',$proposal_id )->execute();
+ if (!$result)
+ {
+ drupal_set_message(t('Solution already open for everyone.'), 'error');
+ return;
+ }
+
+ }
+
+ $solution_display = 0;
+ if ($form_state['values']['solution_display'] == 1) {
+ $solution_display = 1;
+ } else {
+ $solution_display = 0;
+ }
+
+ /* update proposal */
+ $v = $form_state['values'];
+
+ //$query = "UPDATE {lab_migration_proposal} SET name_title = :name_title, name = :name, contact_ph = :contact_ph, department = :department, university = :unversity, lab_title = :lab_title, solution_display = :solution_display WHERE id = :id";
+ // $args= array(
+ // ":name_title" => $v['name_title'],
+ // ":name" => $v['name'],
+ // "contact_ph" => $v['contact_ph'],
+ // ":department" => $v['department'],
+ // ":university" => $v['university'],
+ // ":lab_title" => $v['lab_title'],
+ // ":solution_display" => $solution_display,
+ // ":id" => $proposal_id,
+ // );
+ $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(isset($form_state['values'][$lab_experiment_insert]))) >= 1){
+ $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title, description) VALUES (:proposal_id, :number, :title, :description)";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":number" => $number,
+ ":title" => trim($form_state['values'][$lab_experiment_insert]),
+ ":description"=>trim($form_state['values'][$lab_experiment_description_insert]),
+ );
+ $result4 = db_query($query, $args);
+ if (!$result4)
+ {
+ drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($form_state['values'][$lab_experiment_insert]), 'error');
+ } else {
+ $number++;
+ }
+}
+}
+
+ /* $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('number', 'DESC');
+ $query->range(0, 1);
+ $number_q = $query->execute();
+ if ($number_data = $number_q->fetchObject()) {
+ $number = (int)$number_data->number;
+ $number++;
+ } else {
+ $number = 1;
+ }
+ $insertvalue = array($insert_id => $insert_value);
+ $lab_experimentinsert = $form_state['values']['lab_experiment']['insert'];
+ $lab_exp_descriptioninsert=$form_state['values']['lab_experiment_description']['insert'];
+if (is_array($lab_experimentinsert) || is_object($lab_experimentinsert))
+{
+foreach ($lab_experimentinsert as $insertvalue) {
+//foreach ($form_state['values']['lab_experiment']['insert'] as $insert_id => $insert_value) {
+ if (strlen(trim($insert_value)) >= 1) {
+ $query = "INSERT INTO {lab_migration_experiment} (proposal_id, number, title, description) VALUES :proposal_id, :number, :title, :description";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":number" => $number,
+ ":title" => trim($insert_value),
+ ":description"=>""
+ );
+ $result4 = db_query($query, $args);
+ if (!$result4)
+ {
+ drupal_set_message(t('Could not insert Title of the Experiment : ') . trim($insert_value), 'error');
+ } else {
+ $number++;
+ }
+ }
+ }
+ }*/
+
+ drupal_set_message(t('Proposal Updated'), 'status');
+}
+
+
+
+/******************************************************************************/
+/**************************** CATEGORY EDIT FORM ******************************/
+/******************************************************************************/
+
+function lab_migration_category_edit_form($form,$form_state)
+{
+ /* get current proposal */
+ $proposal_id = (int)arg(4);
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+ } else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('lab-migration/manage-proposal');
+ return;
+ }
+
+ $form['name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid),
+ '#title' => t('Name'),
+ );
+ $form['email_id'] = array(
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contact_ph'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contact_ph,
+ '#title' => t('Contact No.'),
+ );
+ $form['department'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->department,
+ '#title' => t('Department/Branch'),
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->university,
+ '#title' => t('University/Institute'),
+ );
+ $form['lab_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->lab_title,
+ '#title' => t('Title of the Lab'),
+ );
+
+ $form['category'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => 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_proposal.inc~ b/manage_proposal.inc~
new file mode 100755
index 0000000..21883a7
--- /dev/null
+++ b/manage_proposal.inc~
@@ -0,0 +1,1257 @@
+<?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
new file mode 100755
index 0000000..2bace0c
--- /dev/null
+++ b/manage_solution_proposal.inc
@@ -0,0 +1,270 @@
+<?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/manage_solution_proposal.inc~ b/manage_solution_proposal.inc~
new file mode 100755
index 0000000..2bace0c
--- /dev/null
+++ b/manage_solution_proposal.inc~
@@ -0,0 +1,270 @@
+<?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/notes.inc b/notes.inc
new file mode 100755
index 0000000..8b0bc98
--- /dev/null
+++ b/notes.inc
@@ -0,0 +1,119 @@
+<?php
+// $Id$
+
+/******************************************************************************/
+/***************************** BOOK NOTES *************************************/
+/******************************************************************************/
+
+function lab_migration_lab_notes_form($form_state)
+{
+ global $user;
+
+ /* get current proposal */
+ $proposal_id = (int)arg(3);
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t('Invalid lab selected. Please try again.'), 'error');
+ drupal_goto('lab_migration/code_approval');
+ return;
+ }
+
+ /* get current notes */
+ $notes = '';
+ //$notes_q = db_query("SELECT * FROM {lab_migration_notes} WHERE proposal_id = %d LIMIT 1", $proposal_id);
+ $query = db_select('lab_migration_notes');
+ $query->fields('lab_migration_notes');
+ $query->condition('proposal_id', $proposal_id);
+ $query->range(0, 1);
+ $notes_q = $query->execute();
+
+ if ($notes_q)
+ {
+ $notes_data = $notes_q->fetchObject();
+ $notes = $notes_data->notes;
+ }
+
+ $form['lab_details'] = array(
+ '#type' => 'item',
+ '#value' => '<span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span><br />' .
+ '<strong>Proposer:</strong> ' . $proposal_data->name . '<br />' .
+ '<strong>Title of the Lab:</strong> ' . $proposal_data->lab_title . '<br />'
+ );
+
+ $form['notes'] = array(
+ '#type' => 'textarea',
+ '#rows' => 20,
+ '#title' => t('Notes for Reviewers'),
+ '#default_value' => $notes,
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Back'), 'lab_migration/code_approval'),
+ );
+ return $form;
+}
+
+function lab_migration_lab_notes_form_submit($form, &$form_state)
+{
+ global $user;
+
+ /* get current proposal */
+ $proposal_id = (int)arg(3);
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d LIMIT 1", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t('Invalid lab selected. Please try again.'), 'error');
+ drupal_goto('lab_migration/code_approval');
+ return;
+ }
+
+ /* find existing notes */
+ //$notes_q = db_query("SELECT * FROM {lab_migration_notes} WHERE proposal_id = %d LIMIT 1", $proposal_id);
+ $query = db_select('lab_migration_notes');
+ $query->fields('lab_migration_notes');
+ $query->condition('proposal_id', $proposal_id);
+ $query->range(0, 1);
+ $notes_q = $query->execute();
+
+
+ $notes_data = $notes_q->fetchObject();
+
+ /* add or update notes in database */
+ if ($notes_data) {
+ $query = "UPDATE {lab_migration_notes} SET notes = :notes WHERE id = :notes_id";
+ $args = array(
+ ":notes" => $form_state['values']['notes'],
+ ":notes_id" => $notes_data->id,
+ );
+ db_query($query, $args);
+ drupal_set_message('Notes updated successfully.', 'status');
+ } else {
+ $query = "INSERT INTO {lab_migration_notes} (proposal_id, notes) VALUES (:proposal_id, :notes)";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":notes" =>$form_state['values']['notes'],
+ );
+ db_query($query, $args);
+ drupal_set_message('Notes added successfully.', 'status');
+ }
+}
+
diff --git a/proposal.inc b/proposal.inc
new file mode 100755
index 0000000..a7d0376
--- /dev/null
+++ b/proposal.inc
@@ -0,0 +1,461 @@
+<?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,$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' => 200,
+ '#attributes' =>array('placeholder' => t('Enter your full name')),
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ );
+ $form['email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE,
+ );
+ $form['contact_ph'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact No.'),
+ '#size' => 30,
+ '#attributes' =>array('placeholder' => t('Enter your contact number')),
+ '#maxlength' => 15,
+ '#required' => TRUE,
+ );
+ $form['department'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => _list_of_departments(),
+ '#required' => TRUE,
+ );
+
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/ Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' =>array('placeholder' =>'Insert full name of your institute/ university.... '),
+ );
+
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others',
+ ),
+ '#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE,
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#attributes' =>array('placeholder' => t('Enter your country name')),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array('value' => 'Others'),
+ ),
+ ),
+ );
+ $form['other_state'] = array(
+ '#type' => 'textfield',
+ '#title' => t('State other than India'),
+ '#size' => 100,
+ '#attributes' =>array('placeholder' => t('Enter your state/region name')),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array('value' => 'Others'),
+ ),
+ ),
+ );
+ $form['other_city'] = array(
+ '#type' => 'textfield',
+ '#title' => t('City other than India'),
+ '#size' => 100,
+ '#attributes' =>array('placeholder' => t('Enter your city name')),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array('value' => 'Others'),
+ ),
+ ),
+ );
+ $form['all_state'] = array(
+ '#type' => 'select',
+ '#title' => t('State'),
+ '#options' => _list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array('value' => 'India'),
+ ),
+ ),
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _list_of_cities(),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array('value' => 'India'),
+ ),
+ ),
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#required' => False,
+ '#attributes' =>array('placeholder' =>'Enter pincode....'),
+ );
+ /***************************************************************************/
+ $form['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>',
+ );
+
+ $form['lab_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Lab'),
+ '#size' => 50,
+ '#required' => TRUE,
+ );
+
+ $first_experiemnt = TRUE;
+ for ($counter = 1; $counter <= 15; $counter++) {
+
+ if($counter<=5){
+ $form['lab_experiment-' . $counter] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Experiment ') . $counter,
+ '#size' => 50,
+ '#required' => TRUE,
+ );
+ $namefield="lab_experiment-" . $counter;
+ $form['lab_experiment_description-' . $counter] = array(
+ '#type' => 'textarea',
+ '#required' => TRUE,
+ '#attributes' =>array('placeholder' => t('Enter Description for your experiment '.$counter), 'cols' => 50, 'rows' => 4),
+ '#title' => t('Description for Experiment ') . $counter,
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name='.$namefield.']' => array('value' => ""),
+ ),
+ ),
+ );
+ }else{
+ $form['lab_experiment-' . $counter] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Experiment ') . $counter,
+ '#size' => 50,
+ '#required' => FALSE,
+ );
+ $namefield="lab_experiment-" . $counter;
+ $form['lab_experiment_description-' . $counter] = array(
+ '#type' => 'textarea',
+ '#required' => FALSE,
+ '#attributes' =>array('placeholder' => t('Enter Description for your experiment '.$counter)),
+ '#title' => t('Description for Experiment ') . $counter,
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name='.$namefield.']' => array('value' => ""),
+ ),
+ ),
+ );
+ }
+ $first_experiemnt = FALSE;
+
+ }
+
+ $form['solution_provider_uid'] = array(
+ '#type' => 'radios',
+ '#title' => t('Do you want to provide the solution'),
+ '#options' => array('1' => 'Yes', '2' => 'No'),
+ '#required' => TRUE,
+ '#default_value' => '1',
+ '#description' => 'If you dont want to provide the solution then it will be opened for the community, anyone may come forward and provide the solution.',
+ );
+
+ $form['solution_display'] = array(
+ '#type' => 'hidden',
+ '#title' => t('Do you want to display the solution on the www.dwsim.fossee.in website'),
+ '#options' => array('1' => 'Yes'),
+ '#required' => TRUE,
+ '#default_value' => '1',
+ '#description' => 'If yes, solutions will be made available to everyone for downloading.',
+ '#disabled' => FALSE,
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+
+function lab_migration_proposal_form_validate($form, &$form_state)
+{
+
+ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['contact_ph'])){
+ form_set_error('contact_ph', t('Invalid contact phone number'));
+
+ }
+ if($form_state['values']['country']=='Others'){
+ if($form_state['values']['other_country']== ''){
+ form_set_error('other_country', t('Enter country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }else{
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if($form_state['values']['other_state']== ''){
+ form_set_error('other_state', t('Enter state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }else{
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ }
+ if($form_state['values']['other_city']== ''){
+ form_set_error('other_city', t('Enter city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }else{
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ }else{
+ if($form_state['values']['country']== ''){
+ form_set_error('country', t('Select country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if($form_state['values']['all_state']== ''){
+ form_set_error('all_state', t('Select state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if($form_state['values']['city']== ''){
+ form_set_error('city', t('Select city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+
+
+ }
+
+ for ($counter = 1; $counter <= 15; $counter++) {
+ $experiment_field_name = 'lab_experiment-' . $counter;
+ $experiment_description='lab_experiment_description-' . $counter;
+ if (strlen(trim($form_state['values'][$experiment_field_name])) >= 1) {
+ if (strlen(trim($form_state['values'][$experiment_description])) <=49) {
+ form_set_error($experiment_description, t('Description should be minimum of 50 characters'));
+ }
+ }
+ }
+ return;
+}
+
+function lab_migration_proposal_form_submit($form, &$form_state)
+{
+ global $user;
+
+ if (!$user->uid) {
+ drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ return;
+ }
+
+ $solution_provider_uid = 0;
+ $solution_status = 0;
+ $solution_provider_name_title = '';
+ $solution_provider_name = '';
+ $solution_provider_contact_ph = '';
+ $solution_provider_department = '';
+ $solution_provider_university = '';
+ if ($form_state['values']['solution_provider_uid'] == "1") {
+ $solution_provider_uid = $user->uid;
+ $solution_status = 1;
+ $solution_provider_name_title = $form_state['values']['name_title'];
+ $solution_provider_name = $form_state['values']['name'];
+ $solution_provider_contact_ph = $form_state['values']['contact_ph'];
+ $solution_provider_department = $form_state['values']['department'];
+ $solution_provider_university = $form_state['values']['university'];
+ } else {
+ $solution_provider_uid = 0;
+ }
+
+ $solution_display = 0;
+ if ($form_state['values']['solution_display'] == "1")
+ $solution_display = 1;
+ else
+ $solution_display = 1;
+
+ /* 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, country, 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, :country, :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'],
+ ":country" => $v['country'],
+ ":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('');
+}
+
+function _list_of_states(){
+ $states = array(0 => '-Select-');
+ $query = db_select('list_states_of_india');
+ $query->fields('list_states_of_india');
+
+ //$query->orderBy('', '');
+ $states_list = $query->execute();
+ while ($states_list_data = $states_list->fetchObject())
+ {
+ $states[$states_list_data->state] = $states_list_data->state;
+ }
+ return $states;
+}
+
+function _list_of_cities(){
+ $city = array(0 => '-Select-');
+ $query = db_select('list_cities_of_india');
+ $query->fields('list_cities_of_india');
+ $query->orderBy('city', 'ASC');
+ $city_list = $query->execute();
+ while ($city_list_data = $city_list->fetchObject())
+ {
+ $city[$city_list_data->city] = $city_list_data->city;
+ }
+ return $city;
+}
+
+function _list_of_departments(){
+ $department = array(0 => '-Select-');
+ $query = db_select('list_of_departments');
+ $query->fields('list_of_departments');
+ $query->orderBy('id', 'DESC');
+ $department_list = $query->execute();
+ while ($department_list_data = $department_list->fetchObject())
+ {
+ $department[$department_list_data->department] = $department_list_data->department;
+ }
+ return $department;
+}
+
+
diff --git a/proposal.inc~ b/proposal.inc~
new file mode 100755
index 0000000..9f0d7c3
--- /dev/null
+++ b/proposal.inc~
@@ -0,0 +1,338 @@
+<?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/run.inc b/run.inc
new file mode 100755
index 0000000..c7d87b9
--- /dev/null
+++ b/run.inc
@@ -0,0 +1,459 @@
+<?php
+
+ function lab_migration_run_form($form, &$form_state) {
+
+ $options_first =_list_of_labs();
+ $options_two = _ajax_get_experiment_list();
+
+ $select_two = isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] :
+ key($options_two);
+ $url_lab_id = (int)arg(1);
+ if(!$url_lab_id){
+ $selected = isset($form_state['values']['lab']) ? $form_state['values']['lab'] : key($options_first);
+ }elseif($url_lab_id == ''){
+ $selected = 0;
+ }else{
+ $selected = $url_lab_id;;
+ }
+
+ $form = array();
+ $form['lab'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the lab'),
+ '#options' => _list_of_labs(),
+ '#default_value' => $selected,
+ '#ajax' => array(
+ 'callback' => 'ajax_experiment_list_callback',
+ ),
+ );
+ if(!$url_lab_id){
+ $form['selected_lab'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab"></div>',
+ );
+ $form['selected_lab_freeeda'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab_freeeda"></div>',
+ );
+ $form['selected_lab_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab_pdf"></div>',
+ );
+ $form['lab_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_lab_details"></div>',
+ );
+ $form['lab_experiment_list'] = array(
+ '#type' => 'select',
+ '#title' => t('Titile of the experiment'),
+ '#options' => _ajax_get_experiment_list($selected),
+ //'#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '',
+ '#ajax' => array(
+ 'callback' => 'ajax_solution_list_callback',
+ ),
+ '#prefix' => '<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_experiments"></div>',
+ );
+ $form['lab_solution_list'] = array(
+ '#type' => 'select',
+ '#title' => t('Solution'),
+ '#options' => _ajax_get_solution_list($select_two),
+ //'#default_value' => isset($form_state['values']['lab_solution_list']) ?
+ //$form_state['values']['lab_solution_list'] : '',
+ '#ajax' => array(
+ 'callback' => 'ajax_solution_files_callback',
+ ),
+ '#prefix' => '<div id="ajax_selected_solution">',
+ '#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),),),
+ );
+ }else{
+ $lab_default_value = $url_lab_id;
+ $form['selected_lab'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab">'.l('Download Lab Solutions', 'lab_migration/download/lab/' . $lab_default_value).'</div>',
+
+ );
+ $form['selected_lab_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab_pdf">'. l('Download PDF of Lab Solutions', 'lab_migration/generate_lab/' . $lab_default_value . '/1') .'</div>',
+
+ );
+
+if($lab_default_value=='2'){
+$form['selected_lab_freeeda'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_lab_freeeda">'.l('Download Lab Solutions (FreeEDA Version)', 'lab_migration_uploads/Open_Source_EDA_Lab_FreeEDA_Version.zip').'</div>',
+
+ );
+}
+ $form['lab_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_lab_details">'._lab_details($lab_default_value).'</div>',
+ );
+ $form['lab_experiment_list'] = array(
+ '#type' => 'select',
+ '#title' => t('Titile of the experiment'),
+ '#options' => _ajax_get_experiment_list($selected),
+ // '#default_value' => isset($form_state['values']['lab_experiment_list']) ? $form_state['values']['lab_experiment_list'] : '',
+ '#ajax' => array(
+ 'callback' => 'ajax_solution_list_callback',
+ ),
+ '#prefix' => '<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_experiments"></div>',
+ );
+ $form['lab_solution_list'] = array(
+ '#type' => 'select',
+ '#title' => t('Solution'),
+ '#options' => _ajax_get_solution_list($select_two),
+ '#default_value' => isset($form_state['values']['lab_solution_list']) ? $form_state['values']['lab_solution_list'] : '',
+ '#ajax' => array(
+ 'callback' => 'ajax_solution_files_callback',
+ ),
+ '#prefix' => '<div id="ajax_selected_solution">',
+ '#suffix' => '</div>',
+ '#states' => array('invisible' => array(':input[name="lab_experiment_list"]' => 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_experiment_list"]' => 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;
+ }
+
+function ajax_experiment_list_callback($form, $form_state) {
+
+ $commands = array();
+ $lab_default_value = $form_state['values']['lab'];
+ if($lab_default_value !=0){
+ $form['lab_details']['#markup'] = _lab_details($lab_default_value);
+ $lab_details = _lab_information($lab_default_value);
+ $user_solution_provider = user_load($lab_details->solution_provider_uid);
+ //var_dump($lab_details->solution_provider_uid);
+ if ($lab_details->solution_provider_uid > 0) {
+ $commands[] = ajax_command_html('#ajax_selected_lab', l('Download Lab Solutions', 'lab_migration/download/lab/' . $lab_default_value));
+ if($lab_default_value=='2'){
+ $commands[] = ajax_command_html('#ajax_selected_lab_freeeda', l('Download Lab Solutions (FreeEDA Version)', 'lab_migration_uploads/Open_Source_EDA_Lab_FreeEDA_Version.zip'));}
+ $commands[] = ajax_command_html('#ajax_selected_lab_pdf', l('Download PDF of Lab Solutions', 'lab_migration/generate_lab/' . $lab_default_value . '/1'));
+
+ }else{
+ $commands[] = ajax_command_html('#ajax_selected_lab', '');
+ $commands[] = ajax_command_html('#ajax_selected_lab_pdf', '');
+ $commands[] = ajax_command_html('#ajax_selected_lab_freeeda', '');
+ }
+
+ $commands[] = ajax_command_html('#ajax_lab_details', _lab_details($lab_default_value));
+ $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list($lab_default_value);
+ $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list']));
+ $commands[] = ajax_command_html('#ajax_selected_solution', '');
+ $commands[] = ajax_command_html('#ajax_solution_files', '');
+ $commands[] = ajax_command_html('#ajax_download_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_download_experiments', '');
+
+ }else{
+ $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list();
+ $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list']));
+
+ $commands[] = ajax_command_html('#ajax_lab_details', '');
+ $commands[] = ajax_command_html('#ajax_selected_lab', '');
+ $commands[] = ajax_command_html('#ajax_selected_lab_freeeda', '');
+ $commands[] = ajax_command_html('#ajax_selected_lab_pdf', '');
+ $commands[] = ajax_command_data('#ajax_selected_lab', 'form_state_value_select', $form_state['values']['lab']);
+ $commands[] = ajax_command_html('#ajax_selected_experiment','');
+ $commands[] = ajax_command_html('#ajax_download_experiments', '');
+ $commands[] = ajax_command_html('#ajax_selected_solution','');
+ $commands[] = ajax_command_html('#ajax_solution_files', '');
+ $commands[] = ajax_command_html('#ajax_download_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');
+
+ }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+function ajax_solution_list_callback($form, $form_state){
+
+ $commands = array();
+ $experiment_list_default_value = $form_state['values']['lab_experiment_list'];
+ //var_dump($lab_default_value);
+ if($experiment_list_default_value !=0){
+
+ $form['lab_solution_list']['#options'] = _ajax_get_solution_list($experiment_list_default_value);
+
+ $commands[] = ajax_command_html('#ajax_download_experiments', l('Download Experiment', 'lab_migration/download/experiment/' . $experiment_list_default_value));
+
+ $commands[] = ajax_command_html('#ajax_selected_experiment',drupal_render($form['lab_experiment_list']));
+
+ $commands[] = ajax_command_html('#ajax_selected_solution',drupal_render($form['lab_solution_list']));
+
+ // $commands[] = ajax_command_html('#ajax_solution_files', '');
+ // $commands[] = ajax_command_html('#ajax_download_experiment_solution', '');
+ // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');
+
+ }else
+ {
+ $form['lab_solution_list']['#options'] = _ajax_get_solution_list();
+ $commands[] = ajax_command_html('#ajax_selected_solution',drupal_render($form['lab_solution_list']));
+
+ $commands[] = ajax_command_html('#ajax_download_experiments', '');
+ $commands[] = ajax_command_html('#ajax_selected_solution','');
+ $commands[] = ajax_command_html('#ajax_solution_files', '');
+ $commands[] = ajax_command_html('#ajax_download_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');
+ // $commands[] = ajax_command_replace('#ajax_selected_experiment',drupal_render($form['lab_experiment_list']));
+
+ }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+ function ajax_solution_files_callback($form, $form_state){
+ $commands = array();
+ $solution_list_default_value = $form_state['values']['lab_solution_list'];
+ //var_dump($lab_default_value);
+ if($solution_list_default_value !=0){
+ $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action',drupal_render($form['lab_experiment_solution_actions']));
+ /*************************************************************************************/
+ //$solution_list_q = db_query("SELECT * FROM {lab_migration_solution_files} WHERE solution_id = %d", $form_state['values']['solution']);
+ $query = db_select('lab_migration_solution_files');
+ $query->fields('lab_migration_solution_files');
+ $query->condition('solution_id', $solution_list_default_value);
+ $solution_list_q = $query->execute();
+ if ($solution_list_q)
+ {
+ $solution_files_rows = array();
+ while ($solution_list_data = $solution_list_q->fetchObject())
+ {
+ $solution_file_type = '';
+ switch ($solution_list_data->filetype)
+ {
+ case 'S' : $solution_file_type = 'Source or Main file'; break;
+ case 'R' : $solution_file_type = 'Result file'; break;
+ case 'X' : $solution_file_type = 'xcos file'; break;
+ default : $solution_file_type = 'Unknown'; break;
+ }
+ $solution_files_rows[] = array(l($solution_list_data->filename, 'lab_migration/download/file/' . $solution_list_data->id), $solution_file_type);
+ }
+
+ /* dependency files */
+ //$dependency_q = db_query("SELECT * FROM {lab_migration_solution_dependency} WHERE solution_id = %d", $form_state['values']['solution']);
+ $query = db_select('lab_migration_solution_dependency');
+ $query->fields('lab_migration_solution_dependency');
+ $query->condition('solution_id', $solution_list_default_value);
+ $dependency_q = $query->execute();
+ while ($dependency_data = $dependency_q->fetchObject())
+ {
+ //$dependency_files_q = db_query("SELECT * FROM {lab_migration_dependency_files} WHERE id = %d", $dependency_data->dependency_id);
+ $query = db_select('lab_migration_dependency_files');
+ $query->fields('lab_migration_dependency_files');
+ $query->condition('id', $dependency_data->dependency_id);
+ $dependency_files_q = $query->execute();
+ $dependency_files_data = $dependency_files_q->fetchObject();
+ $solution_file_type = 'Dependency file';
+ $solution_files_rows[] = array(l($dependency_files_data->filename, 'lab_migration/download/dependency/' . $dependency_files_data->id), $solution_file_type);
+ }
+
+ /* creating list of files table */
+ $solution_files_header = array('Filename', 'Type');
+ $solution_files = theme('table', array('header' => $solution_files_header, 'rows' => $solution_files_rows));
+
+ }
+ $form['solution_files']['#title'] = 'List of solution files';
+ $form['solution_files']['#markup'] = $solution_files;
+ $commands[] = ajax_command_html('#ajax_download_experiment_solution', l('Download Solution', 'lab_migration/download/solution/' . $solution_list_default_value));
+ // $commands[] = ajax_command_html('#ajax_edit_experiment_solution', l('Edit Solution', 'code_approval/editcode/' . $solution_list_default_value));
+ // $commands[] = ajax_command_html('#ajax_solution_files', $solution_files);
+ $commands[] = ajax_command_html('#ajax_solution_files',drupal_render($form['solution_files']));
+ }else{
+ $commands[] = ajax_command_html('#ajax_selected_lab_experiment_solution_action','');
+ $commands[] = ajax_command_html('#ajax_download_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_edit_experiment_solution', '');
+ $commands[] = ajax_command_html('#ajax_solution_files', '');
+ }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+ function bootstrap_table_format($headers, $rows) {
+ $thead = "";
+ $tbody = "";
+ foreach($headers as $header) {
+ $thead .= "<th>{$header}</th>";
+ }
+ foreach($rows as $row) {
+ $tbody .= "<tr>";
+ foreach($row as $data) {
+ $tbody .= "<td>{$data}</td>";
+ }
+ $tbody .= "</tr>";
+ }
+ $table = "
+ <table class='table table-bordered table-hover' style='margin-left:-140px'>
+ <thead>{$thead}</thead>
+ <tbody>{$tbody}</tbody>
+ </table>
+ ";
+ return $table;
+ }
+
+ /*****************************************************/
+function _list_of_labs()
+ {
+ $lab_titles = array('0' => 'Please select...');
+ //$lab_titles_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC");
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('solution_display', 1);
+ $query->condition('approval_status', 3);
+ $query->orderBy('lab_title', 'ASC');
+ $lab_titles_q = $query->execute();
+ while ($lab_titles_data = $lab_titles_q->fetchObject())
+ {
+ $lab_titles[$lab_titles_data->id] = $lab_titles_data->lab_title . ' (Proposed by ' . $lab_titles_data->name . ')';
+ }
+ return $lab_titles;
+}
+
+ function _ajax_get_experiment_list($lab_default_value = ''){
+ $experiments = array('0' => 'Please select...');
+ //$experiments_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $lab_default_value);
+ $query->orderBy('number', 'ASC');
+ $experiments_q = $query->execute();
+ while ($experiments_data = $experiments_q->fetchObject())
+ {
+ $experiments[$experiments_data->id] = $experiments_data->number . '. ' . $experiments_data->title;
+ }
+ return $experiments;
+ }
+
+
+ function _ajax_get_solution_list($lab_experiment_list=''){
+ $solutions = array('0' => 'Please select...');
+ // $solutions_q = db_query("SELECT * FROM {lab_migration_solution} WHERE experiment_id = %d ORDER BY
+ // CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY) ASC,
+ // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED) ASC,
+ // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED) ASC", $experiment_id);
+
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('experiment_id', $lab_experiment_list);
+ //$query->orderBy("CAST(SUBSTRING_INDEX(code_number, '.', 1) AS BINARY", "ASC");
+ // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', 2), '.', -1) AS UNSIGNED", "ASC");
+ // $query->orderBy("CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(code_number , '.', -1), '.', 1) AS UNSIGNED", "ASC");
+ $solutions_q = $query->execute();
+ while ($solutions_data = $solutions_q->fetchObject())
+ {
+ $solutions[$solutions_data->id] = $solutions_data->code_number . ' (' . $solutions_data->caption . ')';
+ }
+ return $solutions;
+ }
+
+ function _lab_information($proposal_id)
+{
+ //$lab_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $lab_q = $query->execute();
+ $lab_data = $lab_q->fetchObject();
+ return $lab_data;
+}
+
+
+ function _lab_details($lab_default_value){
+ //$lab_default_value = $form_state['values']['lab'];
+ $lab_details = _lab_information($lab_default_value);
+ if($lab_default_value !=0){
+ if ($lab_details->solution_provider_uid > 0) {
+ $user_solution_provider = user_load($lab_details->solution_provider_uid);
+ if ($user_solution_provider) {
+ $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' .
+ '<ul>' .
+ '<li><strong>Solution Provider Name:</strong> ' . $lab_details->solution_provider_name_title . ' ' . $lab_details->solution_provider_name . '</li>' .
+ '<li><strong>Department:</strong> ' . $lab_details->solution_provider_department . '</li>' .
+ '<li><strong>University:</strong> ' . $lab_details->solution_provider_university . '</li>' .
+ '</ul>';
+
+
+ } else {
+ $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' .
+ '<ul>' .
+ '<li><strong>Solution Provider: </strong> (Open) </li>' .
+ '</ul>';
+ }
+ } else {
+ $solution_provider = '<span style="color: rgb(128, 0, 0);"><strong>Solution Provider</strong></span></td><td style="width: 35%;"><br />' .
+ '<ul>' .
+ '<li><strong>Solution Provider: </strong> (Open) </li>' .
+ '</ul>';
+ }
+ }
+$form['lab_details']['#markup']= '<span style="color: rgb(128, 0, 0);"><strong>About the Lab</strong></span></td><td style="width: 35%;"><br />' .
+ '<ul>' .
+ '<li><strong>Proposer Name:</strong> ' . $lab_details->name_title . ' ' . $lab_details->name . '</li>' .
+ '<li><strong>Title of the Lab:</strong> ' . $lab_details->lab_title . '</li>' .
+ '<li><strong>Department:</strong> ' . $lab_details->department . '</li>' .
+ '<li><strong>University:</strong> ' . $lab_details->university . '</li>' .
+ '<li><strong>Category:</strong> ' . $category_data . '</li>' .
+ '</ul>' .
+ $solution_provider;
+
+ $details = $form['lab_details']['#markup'];
+ return $details;
+ }
diff --git a/settings.inc b/settings.inc
new file mode 100755
index 0000000..528e712
--- /dev/null
+++ b/settings.inc
@@ -0,0 +1,85 @@
+<?php
+// $Id$
+
+function lab_migration_settings_form($form_state)
+{
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Notification emails'),
+ '#description' => t('A comma separated list of email addresses to receive notifications emails'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_emails', ''),
+ );
+
+ $form['from_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Outgoing from email address'),
+ '#description' => t('Email address to be display in the from field of all outgoing messages'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_from_email', ''),
+ );
+
+ $form['extensions']['source'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed source file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_source_extensions', ''),
+ );
+ $form['extensions']['dependency'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed dependency file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of dependency file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_dependency_extensions', ''),
+ );
+ $form['extensions']['result'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed result file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of result file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_result_extensions', ''),
+ );
+ $form['extensions']['xcos'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed xcos file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of xcos file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('lab_migration_xcos_extensions', ''),
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+
+function lab_migration_settings_form_validate($form, &$form_state)
+{
+ return;
+}
+
+function lab_migration_settings_form_submit($form, &$form_state)
+{
+ variable_set('lab_migration_emails', $form_state['values']['emails']);
+ variable_set('lab_migration_from_email', $form_state['values']['from_email']);
+ variable_set('lab_migration_source_extensions', $form_state['values']['source']);
+ variable_set('lab_migration_dependency_extensions', $form_state['values']['dependency']);
+ variable_set('lab_migration_result_extensions', $form_state['values']['result']);
+ variable_set('lab_migration_xcos_extensions', $form_state['values']['xcos']);
+ drupal_set_message(t('Settings updated'), 'status');
+}
+
diff --git a/solution_proposal.inc b/solution_proposal.inc
new file mode 100755
index 0000000..14c388e
--- /dev/null
+++ b/solution_proposal.inc
@@ -0,0 +1,195 @@
+<?php
+// $Id$
+
+function lab_migration_proposal_open()
+{
+ global $user;
+
+ /* get open proposal list */
+ $proposal_rows = array();
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE approval_status = 1 AND solution_provider_uid = 0");
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('approval_status', 1);
+ $query->condition('solution_provider_uid', 0);
+ $proposal_q = $query->execute();
+ while ($proposal_data = $proposal_q->fetchObject())
+ {
+ $proposal_rows[] = array(l($proposal_data->lab_title, 'lab_migration/show_proposal/' . $proposal_data->id), l('Apply', 'lab_migration/show_proposal/' . $proposal_data->id));
+ }
+
+ $proposal_header = array('Title of the Lab', 'Actions');
+ $return_html = theme('table', array('header' => $proposal_header, 'rows' => $proposal_rows));
+ //$return_html = theme_table($proposal_header, $proposal_rows);
+ return $return_html;
+}
+
+function lab_migration_solution_proposal_form($form_state)
+{
+ global $user;
+
+ $proposal_id = (int)arg(2);
+
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Invalid proposal.", 'error');
+ drupal_goto('');
+ }
+ //var_dump($proposal_data->name); die;
+ $form['name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->name, 'user/' . $proposal_data->uid),
+ '#title' => t('Proposer Name'),
+ );
+ $form['lab_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->lab_title,
+ '#title' => t('Title of the Lab'),
+ );
+
+ $experiment_html = '';
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE proposal_id = %d", $proposal_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('proposal_id', $proposal_id);
+ $experiment_q = $query->execute();
+ while ($experiment_data = $experiment_q->fetchObject()) {
+ $experiment_html .= $experiment_data->title . "<br/>";
+ }
+ $form['experiment'] = array(
+ '#type' => 'item',
+ '#markup' => $experiment_html,
+ '#title' => t('Experiment List'),
+ );
+
+ $form['solution_provider_name_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title'),
+ '#options' => array('Mr' => 'Mr', 'Ms' => 'Ms', 'Mrs' => 'Mrs', 'Dr' => 'Dr', 'Prof' => 'Prof'),
+ '#required' => TRUE,
+ );
+ $form['solution_provider_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Solution Provider'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ );
+ $form['solution_provider_email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE,
+ );
+ $form['solution_provider_contact_ph'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact No.'),
+ '#size' => 30,
+ '#maxlength' => 15,
+ '#required' => TRUE,
+ );
+ $form['solution_provider_department'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => 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['solution_provider_university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ );
+
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Apply for Solution')
+ );
+ return $form;
+}
+
+function lab_migration_solution_proposal_form_validate($form_state, &$form_state)
+{
+ global $user;
+
+ //$solution_provider_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE solution_provider_uid = ".$user->uid." AND approval_status IN (0, 1) AND solution_status IN (0, 1, 2)");
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('solution_provider_uid', $user->uid);
+ $query->condition('approval_status', array(0, 1), 'IN');
+ $query->condition('solution_status', array(0, 1, 2), 'IN');
+ $solution_provider_q = $query->execute();
+ if ($solution_provider_q->fetchObject()) {
+ form_set_error('', t("You have already applied for a solution. Please compelete that before applying for another solution."));
+ drupal_goto('lab_migration/open_proposal');
+ }
+}
+
+function lab_migration_solution_proposal_form_submit($form_state, &$form_state)
+{
+ global $user;
+
+ $proposal_id = (int)arg(2);
+
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Invalid proposal.", 'error');
+ drupal_goto('lab_migration/open_proposal');
+ }
+ if ($proposal_data->solution_provider_uid != 0) {
+ drupal_set_message("Someone has already applied for solving this Lab.", 'error');
+ drupal_goto('lab_migration/open_proposal');
+ }
+
+ $query = "UPDATE {lab_migration_proposal} set solution_provider_uid = :uid, solution_status = 1, solution_provider_name_title = :solution_provider_name_title, solution_provider_name = :solution_provider_contact_name, solution_provider_contact_ph = :solution_provider_contact_ph, solution_provider_department = :solution_provider_department, solution_provider_university = :solution_provider_university WHERE id = :proposal_id";
+ $args = array(
+ ":uid" => $user->uid,
+ ":solution_provider_name_title" => $form_state['values']['solution_provider_name_title'],
+ ":solution_provider_contact_name" => $form_state['values']['solution_provider_name'],
+ ":solution_provider_contact_ph" => $form_state['values']['solution_provider_contact_ph'],
+ ":solution_provider_department" => $form_state['values']['solution_provider_department'],
+ ":solution_provider_university" => $form_state['values']['solution_provider_university'],
+ ":proposal_id" => $proposal_id
+ );
+ $result = db_query($query, $args);
+ drupal_set_message("We have received your application. We will get back to you soon.", 'status');
+
+ /* sending email */
+ $email_to = $user->mail;
+ $param['solution_proposal_received']['proposal_id'] = $proposal_id;
+ $param['solution_proposal_received']['user_id'] = $user->uid;
+ if (!drupal_mail('lab_migration', 'solution_proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+
+ /* sending email */
+ $email_to = variable_get('lab_migration_emails', '');
+ if (!drupal_mail('lab_migration', 'solution_proposal_received', $email_to , language_default(), $param, variable_get('lab_migration_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+
+ drupal_goto('lab_migration/open_proposal');
+}
+
diff --git a/upload_code.inc b/upload_code.inc
new file mode 100755
index 0000000..b591991
--- /dev/null
+++ b/upload_code.inc
@@ -0,0 +1,645 @@
+<?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 . ')&nbsp;&nbsp;&nbsp;&nbsp;' . $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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, l('Delete', 'lab_migration/code/delete/' . $solution_data->id));
+ } else {
+ $experiment_rows[] = array("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 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('Upload all the eSim project files in .zip format'),
+ '#prefix' => '<div style="color:red">',
+ '#suffix' => '</div>',
+ );
+ $form['sourcefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Main or Source Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload main or source file'),
+ '#size' => 48,
+ '#description' => t('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);
+}
+
diff --git a/upload_code.inc~ b/upload_code.inc~
new file mode 100755
index 0000000..a924df2
--- /dev/null
+++ b/upload_code.inc~
@@ -0,0 +1,645 @@
+<?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 . ')&nbsp;&nbsp;&nbsp;&nbsp;' . $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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $solution_data->code_number . " " . $solution_data->caption, '', $solution_status, l('Delete', 'lab_migration/code/delete/' . $solution_data->id));
+ } else {
+ $experiment_rows[] = array("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . 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);
+}
+
diff --git a/upload_code_delete.inc b/upload_code_delete.inc
new file mode 100755
index 0000000..21ae4c3
--- /dev/null
+++ b/upload_code_delete.inc
@@ -0,0 +1,88 @@
+<?php
+
+/******************************************************************************/
+/***************************** DELETE CODE ************************************/
+/******************************************************************************/
+
+function lab_migration_upload_code_delete()
+{
+ global $user;
+
+ $root_path = lab_migration_path();
+ $solution_id = (int)arg(3);
+
+ /* check solution */
+ // $solution_q = db_query("SELECT * FROM {lab_migration_solution} WHERE id = %d LIMIT 1", $solution_id);
+ $query = db_select('lab_migration_solution');
+ $query->fields('lab_migration_solution');
+ $query->condition('id', $solution_id);
+ $query->range(0, 1);
+ $solution_q = $query->execute();
+ $solution_data = $solution_q->fetchObject();
+ if (!$solution_data)
+ {
+ drupal_set_message('Invalid solution.', 'error');
+ drupal_goto('lab_migration/code');
+ return;
+ }
+ if ($solution_data->approval_status != 0)
+ {
+ drupal_set_message('You cannnot delete a solution after it has been approved. Please contact site administrator if you want to delete this solution.', 'error');
+ drupal_goto('lab_migration/code');
+ return;
+ }
+
+ //$experiment_q = db_query("SELECT * FROM {lab_migration_experiment} WHERE id = %d LIMIT 1", $solution_data->experiment_id);
+ $query = db_select('lab_migration_experiment');
+ $query->fields('lab_migration_experiment');
+ $query->condition('id', $solution_data->experiment_id);
+ $query->range(0, 1);
+ $experiment_q = $query->execute();
+
+ $experiment_data = $experiment_q->fetchObject();
+ if (!$experiment_data)
+ {
+ drupal_set_message('You do not have permission to delete this solution.', 'error');
+ drupal_goto('lab_migration/code');
+ return;
+ }
+
+ //$proposal_q = db_query("SELECT * FROM {lab_migration_proposal} WHERE id = %d AND solution_provider_uid = %d LIMIT 1", $experiment_data->proposal_id, $user->uid);
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $experiment_data->proposal_id);
+ $query->condition('solution_provider_uid', $user->uid);
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message('You do not have permission to delete this solution.', 'error');
+ drupal_goto('lab_migration/code');
+ return;
+ }
+
+ /* deleting solution files */
+ if (lab_migration_delete_solution($solution_data->id))
+ {
+ drupal_set_message('Solution deleted.', 'status');
+
+ /* sending email */
+ $email_to = $user->mail . ', ' . variable_get('lab_migration_emails', '');
+ $param['solution_deleted_user']['lab_title'] = $proposal_data->lab_title;
+ $param['solution_deleted_user']['experiment_title'] = $experiment_data->title;
+ $param['solution_deleted_user']['solution_number'] = $solution_data->code_number;
+ $param['solution_deleted_user']['solution_caption'] = $solution_data->caption;
+ $param['example_deleted_user']['user_id'] = $user->uid;
+
+ if (!drupal_mail('lab_migration', 'solution_deleted_user', $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 deleting example.', 'status');
+ }
+
+ drupal_goto('lab_migration/code');
+ return;
+}
+
+?>