Skip to content

Commit

Permalink
Implement lab migration interface for R
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashi20 committed May 3, 2019
1 parent 5cb1079 commit 316c75e
Show file tree
Hide file tree
Showing 27 changed files with 9,945 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# r_lab_migration
R Lab migration Module for FOSSEE, IIT Bombay written for Drupal 7
1,096 changes: 1,096 additions & 0 deletions bulk_approval.inc

Large diffs are not rendered by default.

483 changes: 483 additions & 0 deletions bulk_upload_code.inc

Large diffs are not rendered by default.

387 changes: 387 additions & 0 deletions code_approval.inc

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions dependency.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php
// $Id$
function lab_migration_upload_dependency_form($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;
}
156 changes: 156 additions & 0 deletions dependency_approval.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?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;
}
Loading

0 comments on commit 316c75e

Please sign in to comment.