From 962dd6237d64e201387e38e30ca3b987a80db225 Mon Sep 17 00:00:00 2001
From: Saketh1499
Date: Mon, 6 Sep 2021 11:21:26 +0530
Subject: Adding section to upload syllabus for lab migration proposal
---
download.inc | 22 ++++++++++++
lab_migration.module | 10 ++++++
manage_proposal.inc | 7 ++++
proposal.inc | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++--
settings.inc | 10 ++++++
5 files changed, 143 insertions(+), 3 deletions(-)
diff --git a/download.inc b/download.inc
index d95c5a2..e91eee8 100755
--- a/download.inc
+++ b/download.inc
@@ -281,3 +281,25 @@ function lab_migration_download_lab()
drupal_goto('lab-migration/lab-migration-run');
}
}
+function lab_migration_download_syllabus_copy()
+{
+ $proposal_id = arg(2);
+ $root_path = lab_migration_path();
+ $query = db_select('lab_migration_proposal');
+ $query->fields('lab_migration_proposal');
+ $query->condition('id', $proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $syllabus_copy_file_data = $result->fetchObject();
+ $syllabus_copy_file_name = substr($syllabus_copy_file_data->syllabus_copy_file_path, strrpos($syllabus_copy_file_data->syllabus_copy_file_path, '/') + 1);
+ error_reporting(0); //Errors may corrupt download
+ ob_start(); //Insert this
+ header('Content-Description: File Transfer');
+ header('Content-Type: application/octet-stream');
+ header('Content-disposition: attachment; filename="' . $syllabus_copy_file_name . '"');
+ header('Content-Length: ' . filesize($root_path . $syllabus_copy_file_data->syllabus_copy_file_path));
+ ob_clean();
+ ob_end_flush();
+ readfile($root_path . $syllabus_copy_file_data->syllabus_copy_file_path);
+ exit;
+}
\ No newline at end of file
diff --git a/lab_migration.module b/lab_migration.module
index 6a861a1..b888926 100755
--- a/lab_migration.module
+++ b/lab_migration.module
@@ -569,6 +569,16 @@ function lab_migration_menu()
),
'file' => 'pdf/verify_lab_migration_certificates.inc'
);
+ $items['download/syllabus_copy_file'] = array(
+ 'title' => 'Syllabus Copy Download',
+ 'description' => 'Syllabus Copy Download',
+ 'page callback' => 'lab_migration_download_syllabus_copy',
+ 'access arguments' => array(
+ 'lab migration bulk manage code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
return $items;
}
/**
diff --git a/manage_proposal.inc b/manage_proposal.inc
index b9071ab..cb94a7e 100755
--- a/manage_proposal.inc
+++ b/manage_proposal.inc
@@ -281,6 +281,13 @@ function lab_migration_proposal_approval_form($form, $form_state)
'#markup' => $experiment_list,
'#title' => t('Experiments')
);
+ if ($proposal_data->syllabus_copy_file_path != "None")
+ {
+ $form['syllabus_copy_file_path'] = array(
+ '#type' => 'markup',
+ '#markup' => l('Click here to download uploaded syllabus copy', 'download/syllabus_copy_file/' . $proposal_id) . "
"
+ );
+ } //$row->samplefilepath != "None"
if ($proposal_data->solution_provider_uid == 0)
{
$solution_provider = "User will not provide solution, we will have to provide solution";
diff --git a/proposal.inc b/proposal.inc
index 85175f8..c8d450d 100755
--- a/proposal.inc
+++ b/proposal.inc
@@ -279,6 +279,22 @@ function lab_migration_proposal_form($form, &$form_state)
)
)
);
+
+ $form['syllabus_copy'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Syllabus copy (PDF) Files *'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['syllabus_copy']['syllabus_copy_file'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload pdf file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') .
+ '
' . t('Allowed file extensions : ') .
+ variable_get('lab_migration_syllabus_file_extensions', '') . ''
+ );
+
$form['lab_title'] = array(
'#type' => 'textfield',
'#title' => t('Title of the Lab'),
@@ -445,6 +461,44 @@ function lab_migration_proposal_form_validate($form, &$form_state)
form_set_error('older', t('Please provide valid version'));
}
}
+
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['syllabus_copy_file']))
+ form_set_error('syllabus_copy_file', t('Please upload pdf 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, 'syllabus'))
+ $file_type = 'S';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('lab_migration_syllabus_file_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]);
+ $allowd_files = explode('.', $allowd_file);
+ $temp_extension = end($allowd_files);
+ 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.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+
return;
}
function lab_migration_proposal_form_submit($form, &$form_state)
@@ -462,6 +516,7 @@ function lab_migration_proposal_form_submit($form, &$form_state)
$solution_provider_contact_ph = '';
$solution_provider_department = '';
$solution_provider_university = '';
+ $syllabus_copy_file_path = '';
if ($form_state['values']['solution_provider_uid'] == "1")
{
$solution_provider_uid = $user->uid;
@@ -492,11 +547,11 @@ function lab_migration_proposal_form_submit($form, &$form_state)
$university = $v['university'];
$directory_name = _lm_dir_name($lab_title, $proposar_name, $university);
$result = "INSERT INTO {lab_migration_proposal}
- (uid, approver_uid, name_title, name, contact_ph, department, university, city, district, pincode, state, country, r_version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, directory_name) VALUES
+ (uid, approver_uid, name_title, name, contact_ph, department, university, city, district, pincode, state, country, r_version, lab_title, approval_status, solution_status, solution_provider_uid, solution_display, creation_date, approval_date, solution_date, solution_provider_name_title, solution_provider_name, solution_provider_contact_ph, solution_provider_department, solution_provider_university, directory_name,syllabus_copy_file_path) VALUES
(:uid, :approver_uid, :name_title, :name, :contact_ph, :department, :university, :city, :district, :pincode, :state, :country,
:r_version, :lab_title, :approval_status, :solution_status, :solution_provider_uid, :solution_display, :creation_date,
:approval_date, :solution_date, :solution_provider_name_title, :solution_provider_name,
- :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :directory_name)";
+ :solution_provider_contact_ph, :solution_provider_department, :solution_provider_university, :directory_name,:syllabus_copy_file_path)";
$args = array(
":uid" => $user->uid,
":approver_uid" => 0,
@@ -524,11 +579,47 @@ function lab_migration_proposal_form_submit($form, &$form_state)
":solution_provider_contact_ph" => $solution_provider_contact_ph,
":solution_provider_department" => $solution_provider_department,
":solution_provider_university" => $solution_provider_university,
- ":directory_name" => $directory_name
+ ":directory_name" => $directory_name,
+ ":syllabus_copy_file_path" => "",
);
$proposal_id = db_query($result, $args, array(
'return' => Database::RETURN_INSERT_ID
));
+ $root_path = lab_migration_path();
+ $dest_path = $proposal_id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* uploading files */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ $file_type = 'S';
+ 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;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ $query = "UPDATE {lab_migration_proposal} SET syllabus_copy_file_path = :syllabus_copy_file_path WHERE id = :id";
+ $args = array(
+ ":syllabus_copy_file_path" => $dest_path . $_FILES['files']['name'][$file_form_name],
+ ":id" => $proposal_id
+ );
+ $updateresult = db_query($query, $args);
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
if (!$proposal_id)
{
drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
diff --git a/settings.inc b/settings.inc
index 1856a25..aa7945c 100755
--- a/settings.inc
+++ b/settings.inc
@@ -74,6 +74,15 @@ function lab_migration_settings_form($form, $form_state)
'#required' => TRUE,
'#default_value' => variable_get('lab_migration_pdf_extensions', '')
);
+ $form['extensions']['syllabus'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed syllabus 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_syllabus_file_extensions', '')
+ );
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
@@ -94,5 +103,6 @@ function lab_migration_settings_form_submit($form, &$form_state)
variable_set('lab_migration_result_extensions', $form_state['values']['result']);
variable_set('lab_migration_xcos_extensions', $form_state['values']['xcos']);
variable_set('lab_migration_pdf_extensions', $form_state['values']['pdf']);
+ variable_set('lab_migration_syllabus_file_extensions', $form_state['values']['syllabus']);
drupal_set_message(t('Settings updated'), 'status');
}
--
cgit