summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrashant S2017-03-01 09:52:30 +0530
committerGitHub2017-03-01 09:52:30 +0530
commita36ce35db402dcf3f45a6d9e871d4f7c94606758 (patch)
tree7a4bef434e9578c160edbf1297fdbe063d6c794e
parentd341dbfd330b16eefb0a6b75c75844e964d54b53 (diff)
parentee4c3b2d36f7b106d9074a9a6c6e4b7efdf96301 (diff)
downloaddwsim_flowsheet-a36ce35db402dcf3f45a6d9e871d4f7c94606758.tar.gz
dwsim_flowsheet-a36ce35db402dcf3f45a6d9e871d4f7c94606758.tar.bz2
dwsim_flowsheet-a36ce35db402dcf3f45a6d9e871d4f7c94606758.zip
Merge pull request #1 from prashantsinalkar/drupal_7.x
flowsheeting proposal form interface
-rwxr-xr-xdownload.inc305
-rwxr-xr-xdwsim_flowsheet.info7
-rwxr-xr-xdwsim_flowsheet.module958
-rwxr-xr-xemail.inc538
-rwxr-xr-xfull_download.inc241
-rwxr-xr-xgeneral_deletion.inc301
-rwxr-xr-xmanage_proposal.inc1067
-rwxr-xr-xproposal.inc794
-rwxr-xr-xsettings.inc98
-rwxr-xr-xupload_code.inc317
-rwxr-xr-xupload_code_delete.inc95
11 files changed, 4721 insertions, 0 deletions
diff --git a/download.inc b/download.inc
new file mode 100755
index 0000000..d52982c
--- /dev/null
+++ b/download.inc
@@ -0,0 +1,305 @@
+<?php
+// $Id$
+function dwsim_flowsheet_download_user_defined_compound()
+{
+ $proposal_id = arg(3);
+ $root_path = dwsim_flowsheet_document_path();
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $dwsim_flowsheet_user_compund_data = $result->fetchObject();
+ $samplecodename = substr($dwsim_flowsheet_user_compund_data->user_defined_compound_filepath, strrpos($dwsim_flowsheet_user_compund_data->user_defined_compound_filepath, '/') + 1);
+ header('Content-Type: txt/zip');
+ header('Content-disposition: attachment; filename="' . $samplecodename . '"');
+ header('Content-Length: ' . filesize($root_path . $dwsim_flowsheet_user_compund_data->directory_name . '/' . $dwsim_flowsheet_user_compund_data->user_defined_compound_filepath));
+ ob_clean();
+ readfile($root_path . $dwsim_flowsheet_user_compund_data->directory_name . '/' . $dwsim_flowsheet_user_compund_data->user_defined_compound_filepath);
+}
+function dwsim_flowsheet_download_solution_file()
+{
+ $solution_file_id = arg(3);
+ $root_path = dwsim_flowsheet_path();
+ // $solution_files_q = db_query("SELECT * FROM {dwsim_flowsheet_solution_files} WHERE id = %d LIMIT 1", $solution_file_id);
+ $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM dwsim_flowsheet_solution_files lmsf JOIN dwsim_flowsheet_solution lms JOIN dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id LIMIT 1", array(
+ ':solution_id' => $solution_file_id
+ ));
+ /*$query = db_select('dwsim_flowsheet_solution_files');
+ $query->fields('dwsim_flowsheet_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-Type: application/octet-stram');
+ header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($solution_file_data->filename)) . '"');
+ header('Content-Length: ' . filesize($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath));
+ readfile($root_path . $solution_file_data->directory_name . '/' . $solution_file_data->filepath);
+}
+function dwsim_flowsheet_download_dependency_file()
+{
+ $dependency_file_id = arg(3);
+ $root_path = dwsim_flowsheet_path();
+ //$dependency_file_q = db_query("SELECT * FROM {dwsim_flowsheet_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id);
+ $query = db_select('dwsim_flowsheet_dependency_files');
+ $query->fields('dwsim_flowsheet_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 dwsim_flowsheet_download_solution()
+{
+ $solution_id = arg(3);
+ $root_path = dwsim_flowsheet_path();
+ /* get solution data */
+ //$solution_q = db_query("SELECT * FROM {dwsim_flowsheet_solution} WHERE id = %d", $solution_id);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_solution');
+ $query->condition('id', $solution_id);
+ $solution_q = $query->execute();
+ $solution_data = $solution_q->fetchObject();
+ //$experiment_q = db_query("SELECT * FROM {dwsim_flowsheet_experiment} WHERE id = %d", $solution_data->experiment_id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_experiment');
+ $query->condition('id', $solution_data->experiment_id);
+ $experiment_q = $query->execute();
+ $experiment_data = $experiment_q->fetchObject();
+ //$solution_files_q = db_query("SELECT * FROM {dwsim_flowsheet_solution_files} WHERE solution_id = %d", $solution_id);
+ /*$query = db_select('dwsim_flowsheet_solution_files');
+ $query->fields('dwsim_flowsheet_solution_files');
+ $query->condition('solution_id', $solution_id);
+ $solution_files_q = $query->execute();*/
+ $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM dwsim_flowsheet_solution_files lmsf JOIN dwsim_flowsheet_solution lms JOIN dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(
+ ':solution_id' => $solution_id
+ ));
+ //$solution_dependency_files_q = db_query("SELECT * FROM {dwsim_flowsheet_solution_dependency} WHERE solution_id = %d", $solution_id);
+ $query = db_select('dwsim_flowsheet_solution_dependency');
+ $query->fields('dwsim_flowsheet_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->directory_name . '/' . $solution_files_row->filepath, $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename)));
+ } //$solution_files_row = $solution_files_q->fetchObject()
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ //$dependency_file_data = (db_query("SELECT * FROM {dwsim_flowsheet_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('dwsim_flowsheet_dependency_files');
+ $query->fields('dwsim_flowsheet_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)));
+ } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject()
+ $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);
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no files in this solutions to download", 'error');
+ drupal_goto('lab-migration/lab-migration-run');
+ }
+}
+function dwsim_flowsheet_download_experiment()
+{
+ $experiment_id = (int) arg(3);
+ $root_path = dwsim_flowsheet_path();
+ /* get solution data */
+ //$experiment_q = db_query("SELECT * FROM {dwsim_flowsheet_experiment} WHERE id = %d", $experiment_id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_id);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_solution_files} WHERE solution_id = %d", $solution_row->id);
+ $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM dwsim_flowsheet_solution_files lmsf JOIN dwsim_flowsheet_solution lms JOIN dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.solution_id = :solution_id", array(
+ ':solution_id' => $solution_row->id
+ ));
+ /* $query = db_select('dwsim_flowsheet_solution_files');
+ $query->fields('dwsim_flowsheet_solution_files');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_files_q = $query->execute();*/
+ // $solution_dependency_files_q = db_query("SELECT * FROM {dwsim_flowsheet_solution_dependency} WHERE solution_id = %d", $solution_row->id);
+ while ($solution_files_row = $solution_files_q->fetchObject())
+ {
+ $zip->addFile($root_path . $solution_files_row->directory_name . '/' . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename)));
+ } //$solution_files_row = $solution_files_q->fetchObject()
+ /* dependency files */
+ $query = db_select('dwsim_flowsheet_solution_dependency');
+ $query->fields('dwsim_flowsheet_solution_dependency');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_dependency_files_q = $query->execute();
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ //$dependency_file_data = (db_query("SELECT * FROM {dwsim_flowsheet_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('dwsim_flowsheet_dependency_files');
+ $query->fields('dwsim_flowsheet_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)));
+ } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject()
+ } //$solution_row = $solution_q->fetchObject()
+ $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);
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no solutions in this experiment to download", 'error');
+ drupal_goto('lab-migration/lab-migration-run');
+ }
+}
+function dwsim_flowsheet_download_lab()
+{
+ global $user;
+ $lab_id = arg(3);
+ $root_path = dwsim_flowsheet_path();
+ /* get solution data */
+ //$lab_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $lab_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_experiment} WHERE proposal_id = %d", $lab_id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_solution} WHERE experiment_id = %d AND approval_status = 1", $experiment_row->id);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_solution_files} WHERE solution_id = %d", $solution_row->id);
+ $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM dwsim_flowsheet_solution_files lmsf JOIN dwsim_flowsheet_solution lms JOIN dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(
+ ':solution_id' => $solution_row->id
+ ));
+ /*$query = db_select('dwsim_flowsheet_solution_files');
+ $query->fields('dwsim_flowsheet_solution_files');
+ $query->condition('solution_id', $solution_row->id);
+ $solution_files_q = $query->execute();*/
+ //$solution_dependency_files_q = db_query("SELECT * FROM {dwsim_flowsheet_solution_dependency} WHERE solution_id = %d", $solution_row->id);
+ $query = db_select('dwsim_flowsheet_solution_dependency');
+ $query->fields('dwsim_flowsheet_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->directory_name . '/' . $solution_files_row->filepath, $EXP_PATH . $CODE_PATH . str_replace(' ', '_', ($solution_files_row->filename)));
+ //var_dump($zip->numFiles);
+ } //$solution_files_row = $solution_files_q->fetchObject()
+ // die;
+ /* dependency files */
+ while ($solution_dependency_files_row = $solution_dependency_files_q->fetchObject())
+ {
+ //$dependency_file_data = (db_query("SELECT * FROM {dwsim_flowsheet_dependency_files} WHERE id = %d LIMIT 1", $solution_dependency_files_row->dependency_id))->fetchObject();
+ $query = db_select('dwsim_flowsheet_dependency_files');
+ $query->fields('dwsim_flowsheet_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)));
+ } //$solution_dependency_files_row = $solution_dependency_files_q->fetchObject()
+ } //$solution_row = $solution_q->fetchObject()
+ } //$experiment_row = $experiment_q->fetchObject()
+ $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);
+ } //$user->uid
+ 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);
+ }
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no solutions in this Lab to download", 'error');
+ drupal_goto('lab-migration/lab-migration-run');
+ }
+}
diff --git a/dwsim_flowsheet.info b/dwsim_flowsheet.info
new file mode 100755
index 0000000..564e188
--- /dev/null
+++ b/dwsim_flowsheet.info
@@ -0,0 +1,7 @@
+name = "DWSIM Flowsheet"
+description = "DWSIM Project, FOSSEE, IIT Bombay"
+package = FOSSEE
+version = "7.x"
+core = "7.x"
+
+;scripts[] = js/jquery-1.4.1.min.js
diff --git a/dwsim_flowsheet.module b/dwsim_flowsheet.module
new file mode 100755
index 0000000..48a865f
--- /dev/null
+++ b/dwsim_flowsheet.module
@@ -0,0 +1,958 @@
+<?php
+// $Id$
+require_once('general_deletion.inc');
+require_once('email.inc');
+/**
+ * Implementation of hook_menu().
+ */
+function dwsim_flowsheet_menu()
+{
+ $items = array();
+ /* PROPOSAL */
+ $items['flowsheeting-project/proposal'] = array(
+ 'title' => 'Flowsheet Proposal Form',
+ 'description' => 'Flowsheet Proposal Form Proposal Form',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_proposal_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet create proposal'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal'] = array(
+ 'title' => 'Manage Flowsheet Proposals',
+ 'description' => 'Manage Flowsheet Proposals',
+ 'page callback' => 'dwsim_flowsheet_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/pending'] = array(
+ 'title' => 'Pending Proposals',
+ 'description' => 'Pending dwsim flowsheet Proposals Queue',
+ 'page callback' => 'dwsim_flowsheet_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/all'] = array(
+ 'title' => 'All Proposals',
+ 'description' => 'All Proposals',
+ 'page callback' => 'dwsim_flowsheet_proposal_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 4,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/approve'] = array(
+ 'title' => 'Approve Proposal',
+ 'description' => 'Approve Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_proposal_approval_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/solution-proposal-approve'] = array(
+ 'title' => 'Approve Solution Proposal',
+ 'description' => 'Approve Solution Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_solution_proposal_approval_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_solution_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/edit'] = array(
+ 'title' => 'Edit Proposal',
+ 'description' => 'Edit Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_proposal_edit_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/manage-proposal/status'] = array(
+ 'title' => 'Proposal Status',
+ 'description' => 'Proposal Status',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_proposal_status_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet approve proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['flowsheeting-project/show-proposal'] = array(
+ 'title' => 'dwsim flowsheet Solution Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_solution_proposal_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet propose solution'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'solution_proposal.inc'
+ );
+ /* CODE REVIEW */
+ $items['flowsheeting-project/code-approval'] = array(
+ 'title' => 'LM Manage Code Approval',
+ 'description' => 'Manage Code Approval',
+ 'page callback' => 'dwsim_flowsheet_code_approval',
+ 'access arguments' => array(
+ 'dwsim flowsheet approve code'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'code_approval.inc'
+ );
+ $items['flowsheeting-project/code-approval/approve'] = array(
+ 'title' => 'Code Approval',
+ 'description' => 'Code Approval',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_code_approval_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet approve code'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ 'file' => 'code_approval.inc'
+ );
+ $items['flowsheeting-project/code-approval/bulk'] = array(
+ 'title' => 'Bulk Manage',
+ 'description' => 'Bulk Mangage',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_bulk_approval_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet bulk manage code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'bulk_approval.inc'
+ );
+ $items['flowsheeting-project/code-approval/bulk'] = array(
+ 'title' => 'Bulk Manage',
+ 'description' => 'Bulk Mangage',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_bulk_approval_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet bulk manage code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'bulk_approval.inc'
+ );
+ /*$items['dwsim_flowsheet/code_approval/dependency'] = array(
+ 'title' => 'Dependency',
+ 'description' => 'Dependency Mangage',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('dwsim_flowsheet_dependency_approval_form'),
+ 'access arguments' => array('dwsim flowsheet bulk manage code'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
+ 'file' => 'dependency_approval.inc',
+ );*/
+ $items['flowsheeting-project/code-approval/upload'] = array(
+ 'title' => 'Upload Code',
+ 'description' => 'Admin Upload',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_bulk_upload_code_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet bulk manage code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'weight' => 4,
+ 'file' => 'bulk_upload_code.inc'
+ );
+ $items['flowsheeting-project/code-approval/notes'] = array(
+ 'title' => 'Notes for Reviewers',
+ 'description' => 'Notes for Reviewers',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_lab_notes_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet bulk manage code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'weight' => 4,
+ 'file' => 'notes.inc'
+ );
+ /* CODE UPLOAD */
+ $items['flowsheeting-project/abstract-code'] = array(
+ 'title' => 'Abstract Submission',
+ 'description' => 'Abstract Submission',
+ 'page callback' => 'dwsim_flowsheet_abstract',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dwsim flowsheet upload code'
+ ),
+ 'file' => 'upload_code.inc'
+ );
+ $items['flowsheeting-project/abstract-code/flowsheet-project-list'] = array(
+ 'title' => 'Flowsheet project',
+ 'description' => 'List Experiments',
+ 'page callback' => 'dwsim_flowsheet_abstract',
+ 'access arguments' => array(
+ 'dwsim flowsheet upload code'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'file' => 'upload_code.inc',
+ 'weight' => 1
+ );
+ $items['flowsheeting-project/abstract-code/upload'] = array(
+ 'title' => 'Abstract Submission',
+ 'description' => 'Abstract Submission',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_upload_abstract_code_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet upload code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'upload_code.inc',
+ 'weight' => 2
+ );
+ /* $items['dwsim_flowsheet/code/upload_dep'] = array(
+ 'title' => 'Upload Dependency',
+ 'description' => 'Upload Dependency Files',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('dwsim_flowsheet_upload_dependency_form'),
+ 'access arguments' => array('dwsim flowsheet upload code'),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'dependency.inc',
+ 'weight' => 3,
+ );*/
+ $items['flowsheeting-project/abstract-code/delete'] = array(
+ 'title' => 'Delete Solution',
+ 'description' => 'Delete Solution',
+ 'page callback' => 'dwsim_flowsheet_upload_code_delete',
+ 'access arguments' => array(
+ 'dwsim flowsheet upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'upload_code_delete.inc'
+ );
+ /* CODE DOWNLOADS */
+ $items['flowsheeting-project/download/file'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_solution_file',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ /*$items['dwsim_flowsheet/download/dependency'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_dependency_file',
+ 'access arguments' => array('dwsim flowsheet download code'),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc',
+ );*/
+ $items['flowsheeting-project/download/solution'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_solution',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['flowsheeting-project/download/experiment'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_experiment',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['flowsheeting-project/download/lab'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_lab',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['flowsheeting-project/full-download/experiment'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_full_experiment',
+ 'access arguments' => array(
+ 'dwsim flowsheet approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ $items['flowsheeting-project/full-download/lab'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'dwsim_flowsheet_download_full_lab',
+ 'access arguments' => array(
+ 'dwsim flowsheet approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ /* COMPLETED dwsim flowsheetS */
+ $items['flowsheeting-project/completed-labs'] = array(
+ 'title' => 'Completed Labs',
+ 'page callback' => 'dwsim_flowsheet_completed_labs_all',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'file' => 'lab_details.inc'
+ );
+ /* LABS IN PROGRESS */
+ $items['flowsheeting-project/labs-progress'] = array(
+ 'title' => 'Labs in Progress',
+ 'page callback' => 'dwsim_flowsheet_labs_progress_all',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'file' => 'lab_details.inc'
+ );
+ /* DOWNLOAD FOR EVERYONE */
+ $items['flowsheeting-project/dwsim-flowsheet-run'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_run_form'
+ ),
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc'
+ );
+ $items['flowsheeting-project/download/user-defined-compound-file'] = array(
+ 'title' => 'Download user defined compound file',
+ 'description' => 'Download user defined compound',
+ 'page callback' => 'dwsim_flowsheet_download_user_defined_compound',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ /*$items['dwsim_flowsheet_run'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('dwsim_flowsheet_run_form_ajax'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );
+ $items['dwsim_flowsheet_run_ajax'] = array(
+ 'page callback' => 'dwsim_flowsheet_run_ajax',
+ 'access callback' => TRUE,
+ 'file' => 'run.inc',
+ );
+ $items['download_codes'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('dwsim_flowsheet_run_form_ajax'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );*/
+ /* LATEX SCRIPT */
+ $items['flowsheeting-project/generate-lab'] = array(
+ 'title' => 'Generate Lab',
+ 'description' => 'Generate Lab From Latex Script',
+ 'page callback' => 'dwsim_flowsheet_download_lab_pdf',
+ 'access arguments' => array(
+ 'dwsim flowsheet generate lab'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'latex.inc'
+ );
+ $items['flowsheeting-project/delete-lab'] = array(
+ 'title' => 'Delete Lab PDF',
+ 'description' => 'Delete Lab PDF',
+ 'page callback' => 'dwsim_flowsheet_delete_lab_pdf',
+ 'access arguments' => array(
+ 'dwsim flowsheet approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'latex.inc'
+ );
+ /* ADMIN SETTINGS */
+ $items['admin/settings/dwsim-flowsheet'] = array(
+ 'title' => 'dwsim flowsheet Settings',
+ 'description' => 'dwsim flowsheet Settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'dwsim_flowsheet_settings_form'
+ ),
+ 'access arguments' => array(
+ 'administer dwsim flowsheet'
+ ),
+ '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(
+ "dwsim flowsheet bulk manage code"
+ ),
+ "type" => MENU_CALLBACK,
+ 'file' => 'bulk_approval.inc'
+ );
+ /* $items["dwsim_flowsheet/code_approval/dependency/ajax"] = array(
+ "title" => "Ajax callbacks",
+ "page callback" => "dwsim_flowsheet_dependency_approval_ajax",
+ "access arguments" => array("dwsim flowsheet bulk manage code"),
+ "type" => MENU_CALLBACK,
+ 'file' => 'dependency_approval.inc',
+ );*/
+ return $items;
+}
+/**
+ * Implementation of hook_perm().
+ */
+function dwsim_flowsheet_permission()
+{
+ return array(
+ 'dwsim flowsheet create proposal' => array(
+ 'title' => t('dwsim flowsheet create proposal'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet manage proposal' => array(
+ 'title' => t('dwsim flowsheet manage proposal'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet edit proposal' => array(
+ 'title' => t('dwsim flowsheet edit proposal'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet approve proposal' => array(
+ 'title' => t('dwsim flowsheet approve proposal'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet propose solution' => array(
+ 'title' => t('dwsim flowsheet propose solution'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet approve code' => array(
+ 'title' => t('dwsim flowsheet approve code'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet bulk manage code' => array(
+ 'title' => t('dwsim flowsheet bulk manage code'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet bulk delete code' => array(
+ 'title' => t('dwsim flowsheet bulk delete code'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet upload code' => array(
+ 'title' => t('dwsim flowsheet upload code'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet download code' => array(
+ 'title' => t('dwsim flowsheet download code'),
+ 'restrict access' => TRUE
+ ),
+ 'administer dwsim flowsheet' => array(
+ 'title' => t('administer dwsim flowsheet'),
+ 'restrict access' => TRUE
+ ),
+ 'dwsim flowsheet generate lab' => array(
+ 'title' => t('dwsim flowsheet generate lab'),
+ 'restrict access' => TRUE
+ )
+ );
+ // return array('dwsim flowsheet create proposal', 'dwsim flowsheet manage proposal', 'dwsim flowsheet edit proposal', 'dwsim flowsheet approve proposal', 'dwsim flowsheet propose solution', 'dwsim flowsheet approve code', 'dwsim flowsheet bulk manage code', 'dwsim flowsheet bulk delete code', 'dwsim flowsheet upload code', 'dwsim flowsheet download code', 'administer dwsim flowsheet', 'dwsim flowsheet generate lab');
+}
+/* AJAX CALLS */
+function dwsim_flowsheet_ajax()
+{
+ $query_type = arg(2);
+ if ($query_type == 'chapter_title')
+ {
+ $chapter_number = arg(3);
+ $preference_id = arg(4);
+ //$chapter_q = db_query("SELECT * FROM {dwsim_flowsheet_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);
+ $query = db_select('dwsim_flowsheet_chapter');
+ $query->fields('dwsim_flowsheet_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;
+ } //$chapter_data = $chapter_q->fetchObject()
+ } //$query_type == 'chapter_title'
+ else if ($query_type == 'example_exists')
+ {
+ $chapter_number = arg(3);
+ $preference_id = arg(4);
+ $example_number = arg(5);
+ $chapter_id = 0;
+ $query = db_select('dwsim_flowsheet_chapter');
+ $query->fields('dwsim_flowsheet_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;
+ } //!$chapter_data = $chapter_q->fetchObject()
+ else
+ {
+ $chapter_id = $chapter_data->id;
+ }
+ $query = db_select('dwsim_flowsheet_example');
+ $query->fields('dwsim_flowsheet_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;
+ } //$example_data = $example_q->fetchObject()
+ } //$query_type == 'example_exists'
+ echo '';
+}
+/*************************** VALIDATION FUNCTIONS *****************************/
+function dwsim_flowsheet_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 dwsim_flowsheet_check_name($name = '')
+{
+ if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name))
+ return FALSE;
+ else
+ return TRUE;
+}
+function dwsim_flowsheet_check_code_number($number = '')
+{
+ if (!preg_match('/^[0-9]+$/', $number))
+ return FALSE;
+ else
+ return TRUE;
+}
+function dwsim_flowsheet_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/dwsim_flowsheet_uploads/';
+}
+/************************* USER VERIFICATION FUNCTIONS ************************/
+function dwsim_flowsheet_get_proposal()
+{
+ global $user;
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE solution_provider_uid = ".$user->uid." AND solution_status = 2 ORDER BY id DESC LIMIT 1");
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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)
+ {
+ drupal_set_message("You do not have any approved DWSIM Flowsheet proposal. Please propose the flowsheet proposal", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ 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;
+ } //$proposal_data->approval_status
+ return FALSE;
+}
+/*************************************************************************/
+/***** Function To convert only first charater of string in uppercase ****/
+/*************************************************************************/
+function dwsim_flowsheet_ucname($string)
+{
+ $string = ucwords(strtolower($string));
+ foreach (array(
+ '-',
+ '\''
+ ) as $delimiter)
+ {
+ if (strpos($string, $delimiter) !== false)
+ {
+ $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
+ } //strpos($string, $delimiter) !== false
+ } //array( '-', '\'' ) as $delimiter
+ return $string;
+}
+function _df_sentence_case($string)
+{
+ $string = ucwords(strtolower($string));
+ foreach (array(
+ '-',
+ '\''
+ ) as $delimiter)
+ {
+ if (strpos($string, $delimiter) !== false)
+ {
+ $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
+ } //strpos($string, $delimiter) !== false
+ } //array( '-', '\'' ) as $delimiter
+ return $string;
+}
+function _df_list_of_dwsim_compound()
+{
+ $dwsim_compound = array();
+ $query = db_select('dwsim_flowsheet_compounds_from_dwsim');
+ $query->fields('dwsim_flowsheet_compounds_from_dwsim');
+ $query->orderBy('id', 'ASC');
+ $dwsim_compound_list = $query->execute();
+ while ($dwsim_compound_list_data = $dwsim_compound_list->fetchObject())
+ {
+ $dwsim_compound[$dwsim_compound_list_data->compound] = $dwsim_compound_list_data->compound;
+ } //$dwsim_compound_list_data = $dwsim_compound_list->fetchObject()
+ return $dwsim_compound;
+}
+function _df_list_of_unit_operations()
+{
+ $dwsim_unit_operations = array();
+ $query = db_select('dwsim_flowsheet_unit_operations');
+ $query->fields('dwsim_flowsheet_unit_operations');
+ $query->orderBy('id', 'ASC');
+ $dwsim_unit_operations_list = $query->execute();
+ while ($dwsim_unit_operations_list_data = $dwsim_unit_operations_list->fetchObject())
+ {
+ $dwsim_unit_operations[$dwsim_unit_operations_list_data->unit_operations] = $dwsim_unit_operations_list_data->unit_operations;
+ } //$dwsim_unit_operations_list_data = $dwsim_unit_operations_list->fetchObject()
+ return $dwsim_unit_operations;
+}
+function _df_list_of_thermodynamic_packages()
+{
+ $dwsim_thermodynamic_packages = array();
+ $query = db_select('dwsim_flowsheet_thermodynamic_packages');
+ $query->fields('dwsim_flowsheet_thermodynamic_packages');
+ $query->orderBy('id', 'ASC');
+ $dwsim_thermodynamic_packages_list = $query->execute();
+ while ($dwsim_thermodynamic_packages_list_data = $dwsim_thermodynamic_packages_list->fetchObject())
+ {
+ $dwsim_thermodynamic_packages[$dwsim_thermodynamic_packages_list_data->thermodynamic_packages] = $dwsim_thermodynamic_packages_list_data->thermodynamic_packages;
+ } //$dwsim_thermodynamic_packages_list_data = $dwsim_thermodynamic_packages_list->fetchObject()
+ return $dwsim_thermodynamic_packages;
+}
+function _df_list_of_logical_block()
+{
+ $dwsim_logical_block = array();
+ $query = db_select('dwsim_flowsheet_logical_block');
+ $query->fields('dwsim_flowsheet_logical_block');
+ $query->orderBy('id', 'ASC');
+ $dwsim_logical_block_list = $query->execute();
+ while ($dwsim_logical_block_list_data = $dwsim_logical_block_list->fetchObject())
+ {
+ $dwsim_logical_block[$dwsim_logical_block_list_data->logical_block] = $dwsim_logical_block_list_data->logical_block;
+ } //$dwsim_logical_block_list_data = $dwsim_logical_block_list->fetchObject()
+ return $dwsim_logical_block;
+}
+function _df_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;
+ } //$states_list_data = $states_list->fetchObject()
+ return $states;
+}
+function _df_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;
+ } //$city_list_data = $city_list->fetchObject()
+ return $city;
+}
+function _df_list_of_pincodes()
+{
+ $pincode = array(
+ 0 => '-Select-'
+ );
+ $query = db_select('list_of_all_india_pincode');
+ $query->fields('list_of_all_india_pincode');
+ $query->orderBy('pincode', 'ASC');
+ $pincode_list = $query->execute();
+ while ($pincode_list_data = $pincode_list->fetchObject())
+ {
+ $pincode[$pincode_list_data->pincode] = $pincode_list_data->pincode;
+ } //$pincode_list_data = $pincode_list->fetchObject()
+ return $pincode;
+}
+function _df_list_of_departments()
+{
+ $department = array();
+ $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;
+ } //$department_list_data = $department_list->fetchObject()
+ return $department;
+}
+function _df_list_of_software_version()
+{
+ $software_version = array();
+ $query = db_select('dwsim_software_version');
+ $query->fields('dwsim_software_version');
+ $query->orderBy('dwsim_version', 'ASC');
+ $software_version_list = $query->execute();
+ while ($software_version_list_data = $software_version_list->fetchObject())
+ {
+ $software_version[$software_version_list_data->dwsim_version] = $software_version_list_data->dwsim_version;
+ } //$software_version_list_data = $software_version_list->fetchObject()
+ return $software_version;
+}
+function _df_dir_name($project, $proposar_name)
+{
+ $project_title = ucname($project);
+ $proposar_name = ucname($proposar_name);
+ $dir_name = $project_title . ' By ' . $proposar_name;
+ $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name));
+ return $directory_name;
+}
+function dwsim_flowsheet_document_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/dwsim_flowsheet_uploads/';
+}
+function DF_RenameDir($proposal_id, $dir_name)
+{
+ $proposal_id = $proposal_id;
+ $dir_name = $dir_name;
+ $query = db_query("SELECT directory_name,id FROM dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
+ ':proposal_id' => $proposal_id
+ ));
+ $result = $query->fetchObject();
+ if ($result != NULL)
+ {
+ $files = scandir(dwsim_flowsheet_path());
+ $files_id_dir = dwsim_flowsheet_path() . $result->id;
+ //var_dump($files);die;
+ $file_dir = dwsim_flowsheet_path() . $result->directory_name;
+ if (is_dir($file_dir))
+ {
+ $new_directory_name = rename(dwsim_flowsheet_path() . $result->directory_name, dwsim_flowsheet_path() . $dir_name);
+ return $new_directory_name;
+ } //is_dir($file_dir)
+ else if (is_dir($files_id_dir))
+ {
+ $new_directory_name = rename(dwsim_flowsheet_path() . $result->id, dwsim_flowsheet_path() . $dir_name);
+ return $new_directory_name;
+ } //is_dir($files_id_dir)
+ else
+ {
+ drupal_set_message('Directory not available for rename.');
+ return;
+ }
+ } //$result != NULL
+ else
+ {
+ drupal_set_message('Project directory name not present in databse');
+ return;
+ }
+ //var_dump($files);die;
+ /* if ($files != NULL)
+ {
+ $new_directory_name = rename(dwsim_flowsheet_path() . $result->directory_name, dwsim_flowsheet_path() . $dir_name) or drupal_set_message("Unable to rename folder");
+ }
+ else
+ {
+ $new_directory_name = 'Can not rename the directory. Directory not present';
+ }*/
+ return;
+}
+function CreateReadmeFileDWSIMFlowsheetingProject($proposal_id)
+{
+ $result = db_query("
+ SELECT * from dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
+ ":proposal_id" => $proposal_id
+ ));
+ $proposal_data = $result->fetchObject();
+ $root_path = dwsim_flowsheet_path();
+ $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!");
+ $txt = "";
+ $txt .= "About the lab";
+ $txt .= "\n" . "\n";
+ $txt .= "Title Of The Flowsheet Project: " . $proposal_data->project_title . "\n";
+ $txt .= "Proposar Name: " . $proposal_data->name_title . " " . $proposal_data->student_name . "\n";
+ $txt .= "University: " . $proposal_data->university . "\n";
+ $txt .= "\n" . "\n";
+ $txt .= "DWSIM Flowsheet Project By FOSSEE, IIT Bombay" . "\n";
+ fwrite($readme_file, $txt);
+ fclose($readme_file);
+ return $txt;
+}
+function rrmdir_project($prop_id)
+{
+ $proposal_id = $prop_id;
+ $result = db_query("
+ SELECT * from dwsim_flowsheet_proposal WHERE id = :proposal_id", array(
+ ":proposal_id" => $proposal_id
+ ));
+ $proposal_data = $result->fetchObject();
+ $root_path = dwsim_flowsheet_document_path();
+ $dir = $root_path . $proposal_data->directory_name;
+ if ($proposal_data->id == $prop_id)
+ {
+ if (is_dir($dir))
+ {
+ $objects = scandir($dir);
+ foreach ($objects as $object)
+ {
+ if ($object != "." && $object != "..")
+ {
+ if (filetype($dir . "/" . $object) == "dir")
+ {
+ rrmdir($dir . "/" . $object);
+ } //filetype($dir . "/" . $object) == "dir"
+ else
+ {
+ unlink($dir . "/" . $object);
+ }
+ } //$object != "." && $object != ".."
+ } //$objects as $object
+ reset($objects);
+ rmdir($dir);
+ $msg = drupal_set_message("Directory deleted successfully");
+ return $msg;
+ } //is_dir($dir)
+ $msg = drupal_set_message("Directory not present");
+ return $msg;
+ } //$proposal_data->id == $prop_id
+ else
+ {
+ $msg = drupal_set_message("Data not found");
+ return $msg;
+ }
+}
+function rrmdir($dir)
+{
+ if (is_dir($dir))
+ {
+ $objects = scandir($dir);
+ foreach ($objects as $object)
+ {
+ if ($object != "." && $object != "..")
+ {
+ if (filetype($dir . "/" . $object) == "dir")
+ rrmdir($dir . "/" . $object);
+ else
+ unlink($dir . "/" . $object);
+ } //$object != "." && $object != ".."
+ } //$objects as $object
+ reset($objects);
+ rmdir($dir);
+ } //is_dir($dir)
+}
+function _dwsim_flowsheet_list_of_user_defined_compound($proposal_id)
+{
+ $data = "";
+ $query = db_select('dwsim_flowsheet_user_defined_compound');
+ $query->fields('dwsim_flowsheet_user_defined_compound');
+ $query->condition('proposal_id', $proposal_id, '=');
+ $query->orderBy('user_defined_compound', 'ASC');
+ $user_defined_compound_list = $query->execute();
+ $headers = array(
+ "User defined compound",
+ "CAS No."
+ );
+ $rows = array();
+ while ($row = $user_defined_compound_list->fetchObject())
+ {
+ $item = array(
+ "{$row->user_defined_compound}",
+ "{$row->cas_no}"
+ );
+ array_push($rows, $item);
+ } //$row = $user_defined_compound_list->fetchObject()
+ $data .= theme('table', array(
+ 'header' => $headers,
+ 'rows' => $rows
+ ));
+ return $data;
+}
diff --git a/email.inc b/email.inc
new file mode 100755
index 0000000..a8b34e1
--- /dev/null
+++ b/email.inc
@@ -0,0 +1,538 @@
+<?php
+/**
+ * Implementation of hook_mail().
+ */
+function dwsim_flowsheet_mail($key, &$message, $params)
+{
+ global $user;
+ $language = $message['language'];
+ //$language = user_preferred_language($user);
+ switch ($key)
+ {
+ case 'dwsim_flowsheet_proposal_received':
+ /* initializing data */
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $params['dwsim_flowsheet_proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['dwsim_flowsheet_proposal_received']['user_id']);
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+
+ $message['headers'] = $params['dwsim_flowsheet_proposal_received']['headers'];
+ $message['subject'] = t('[!site_name][Flowsheeting Project] Your DWSIM Flowsheeting Project 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 DWSIM Flowsheeting Project proposal with the following details:
+
+Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email : ' . $user_data->mail . '
+Month and Year of Award of Degree : ' . $proposal_data->month_year_of_degree . '
+University/Institute : ' . $proposal_data->university . '
+City : ' . $proposal_data->city . '
+State : ' . $proposal_data->state . '
+Country : ' . $proposal_data->country . '
+
+Project Guide : ' . $project_guide_name . '
+Project Guide Email : ' . $project_guide_email_id . '
+
+DWSIM Version : ' . $proposal_data->version . '
+
+Project Title : ' . $proposal_data->project_title . '
+
+Name of compound for which process development is carried out : ' . $proposal_data->process_development_compound_name . '
+
+
+Your proposal is under review. You will soon receive an email when same has been approved/disapproved.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'dwsim_flowsheet_proposal_disapproved':
+ /* initializing data */
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $params['dwsim_flowsheet_proposal_disapproved']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['dwsim_flowsheet_proposal_disapproved']['user_id']);
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+ $message['headers'] = $params['dwsim_flowsheet_proposal_disapproved']['headers'];
+ $message['subject'] = t('[!site_name][Flowsheeting Project] Your DWSIM Flowsheeting Project proposal has been disapproved', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+We regret to inform you that your DWSIM Flowsheeting Project proposal with following details have been disapproved:
+
+Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email : ' . $user_data->mail . '
+Month and Year of Award of Degree : ' . $proposal_data->month_year_of_degree . '
+University/Institute : ' . $proposal_data->university . '
+City : ' . $proposal_data->city . '
+State : ' . $proposal_data->state . '
+Country : ' . $proposal_data->country . '
+
+Project Guide : ' . $project_guide_name . '
+Project Guide Email : ' . $project_guide_email_id . '
+
+DWSIM Version : ' . $proposal_data->version . '
+
+Project Title : ' . $proposal_data->project_title . '
+
+Name of compound for which process development is carried out : ' . $proposal_data->process_development_compound_name . '
+
+
+Reason for rejection: : ' . $proposal_data->dissapproval_reason . '
+
+
+You are welcome to submit a new proposal.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'dwsim_flowsheet_proposal_approved':
+ /* initializing data */
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $params['dwsim_flowsheet_proposal_approved']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['dwsim_flowsheet_proposal_approved']['user_id']);
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+ $message['headers'] = $params['dwsim_flowsheet_proposal_approved']['headers'];
+ $message['subject'] = t('[!site_name][Flowsheeting Project] Your DWSIM Flowsheeting Project proposal has been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your DWSIM Flowsheeting Project proposal with the following details has been approved:
+
+Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email : ' . $user_data->mail . '
+Month and Year of Award of Degree : ' . $proposal_data->month_year_of_degree . '
+University/Institute : ' . $proposal_data->university . '
+City : ' . $proposal_data->city . '
+State : ' . $proposal_data->state . '
+Country : ' . $proposal_data->country . '
+
+Project Guide : ' . $project_guide_name . '
+Project Guide Email : ' . $project_guide_email_id . '
+
+DWSIM Version : ' . $proposal_data->version . '
+
+Project Title : ' . $proposal_data->project_title . '
+
+Name of compound for which process development is carried out : ' . $proposal_data->process_development_compound_name . '
+
+
+You can upload your abstract using abstract submission interface.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'dwsim_flowsheet_proposal_completed':
+ /* initializing data */
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $params['dwsim_flowsheet_proposal_approved']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['dwsim_flowsheet_proposal_approved']['user_id']);
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+ $message['headers'] = $params['dwsim_flowsheet_proposal_approved']['headers'];
+ $message['subject'] = t('[!site_name][Flowsheeting Project] Your DWSIM Flowsheeting Project proposal has been completed', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your DWSIM flowsheet and abstract on the following process have been completed successfully.
+
+Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email : ' . $user_data->mail . '
+Month and Year of Award of Degree : ' . $proposal_data->month_year_of_degree . '
+University/Institute : ' . $proposal_data->university . '
+City : ' . $proposal_data->city . '
+State : ' . $proposal_data->state . '
+Country : ' . $proposal_data->country . '
+
+Project Guide : ' . $project_guide_name . '
+Project Guide Email : ' . $project_guide_email_id . '
+
+DWSIM Version : ' . $proposal_data->version . '
+
+Project Title : ' . $proposal_data->project_title . '
+
+Name of compound for which process development is carried out : ' . $proposal_data->process_development_compound_name . '
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'dwsim_flowsheet_proposal_deleted':
+ /* initializing data */
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $params['dwsim_flowsheet_proposal_deleted']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['dwsim_flowsheet_proposal_deleted']['user_id']);
+
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+ $message['headers'] = $params['dwsim_flowsheet_proposal_deleted']['headers'];
+ $message['subject'] = t('[!site_name][Flowsheeting Project] Your DWSIM Flowsheeting Project proposal has been deleted', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your DWSIM Flowsheeting Project proposal with the following details has been deleted :
+
+Full Name : ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email : ' . $user_data->mail . '
+Month and Year of Award of Degree : ' . $proposal_data->month_year_of_degree . '
+University/Institute : ' . $proposal_data->university . '
+City : ' . $proposal_data->city . '
+State : ' . $proposal_data->state . '
+Country : ' . $proposal_data->country . '
+
+Project Guide : ' . $project_guide_name . '
+Project Guide Email : ' . $project_guide_email_id . '
+
+DWSIM Version : ' . $proposal_data->version . '
+
+Project Title : ' . $proposal_data->project_title . '
+
+Name of compound for which process development is carried out : ' . $proposal_data->process_development_compound_name . '
+
+
+
+You can propose a new flowsheet project.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', 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 {dwsim_flowsheet_solution} WHERE id = %d LIMIT 1", $params['solution_uploaded']['solution_id']);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_solution');
+ $query->condition('id', $params['solution_uploaded']['solution_id']);
+ $query->range(0, 1);
+ $solution_q = $query->execute();
+ $solution_data = $solution_q->fetchObject();
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_experiment');
+ $query->condition('id', $solution_data->experiment_id);
+ $query->range(0, 1);
+ $experiment_q = $query->execute();
+ $experiment_data = $experiment_q->fetchObject();
+ $user_data = user_load($params['solution_uploaded']['user_id']);
+ $message['subject'] = t('[!site_name] You have uploaded DWSIM flowsheet solution', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['headers'] = $params['solution_uploaded']['headers'];
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+You have uploaded the following solution:
+
+Experiment Title : ' . $experiment_data->title . '
+
+Solution 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 Team,
+FOSSEE,IIT Bombay', 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 {dwsim_flowsheet_solution} WHERE id = %d LIMIT 1", $params['solution_approved']['solution_id']);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_solution');
+ $query->condition('id', $params['solution_approved']['solution_id']);
+ $query->range(0, 1);
+ $solution_q = $query->execute();
+ $solution_data = $solution_q->fetchObject();
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_experiment');
+ $query->condition('id', $solution_data->experiment_id);
+ $query->range(0, 1);
+ $experiment_q = $query->execute();
+ $experiment_data = $experiment_q->fetchObject();
+ $user_data = user_load($params['solution_approved']['user_id']);
+ $message['headers'] = $params['solution_approved']['headers'];
+ $message['subject'] = t('[!site_name] Your uploaded DWSIM flowsheet 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:
+
+Experiment Title : ' . $experiment_data->title . '
+
+Solution number : ' . $solution_data->code_number . '
+Caption : ' . $solution_data->caption . '
+
+Please ensure that ALL the codes follow guidelines at http://dwsim.fossee.in/dwsim-flowsheet-project/dwsim-flowsheet-guidelines
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', 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['headers'] = $params['solution_disapproved']['headers'];
+ $message['subject'] = t('[!site_name] Your uploaded DWSIM flowsheet 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'] . '
+
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', 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['headers'] = $params['solution_deleted_user']['headers'];
+ $message['subject'] = t('[!site_name] User has deleted pending DWSIM flowsheet 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'] . '
+
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', 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['headers'] = $params['dependency_uploaded']['headers'];
+ $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://dwsim.fossee.in/dwsim-flowsheet-project/dwsim-flowsheet-guidelines
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', 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'];
+ $message['headers'] = $params['standard']['headers'];
+ break;
+ } //$key
+}
diff --git a/full_download.inc b/full_download.inc
new file mode 100755
index 0000000..a8e7173
--- /dev/null
+++ b/full_download.inc
@@ -0,0 +1,241 @@
+<?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);
+ $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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id));
+ //$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->directory_name. '/' . $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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id));
+
+ //$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->directory_name . '/' . $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_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);
+ /* 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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id));
+ //$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->directory_name. '/' . $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_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_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM lab_migration_solution_files lmsf JOIN lab_migration_solution lms JOIN lab_migration_experiment lme JOIN lab_migration_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_row->id));
+
+ //$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->directory_name . '/' . $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..6999595
--- /dev/null
+++ b/general_deletion.inc
@@ -0,0 +1,301 @@
+<?php
+/******************************************************************************/
+/****************************** DELETION FUNCTIONS ****************************/
+/******************************************************************************/
+function dwsim_flowsheet_delete_solution($solution_id)
+ {
+ global $user;
+ $root_path = dwsim_flowsheet_path();
+ $status = TRUE;
+ //$solution_q = db_query("SELECT * FROM {dwsim_flowsheet_solution} WHERE id = %d", $solution_id);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_experiment} WHERE id = %d", $solution_data->experiment_id);
+ $experiment_q = db_query("SELECT lme.*, lmp.id, lmp.directory_name FROM dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lmp.id = lme.proposal_id AND lme.id = :experiment_id",array(':experiment_id' => $solution_data->experiment_id));
+ $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 {dwsim_flowsheet_solution_files} WHERE solution_id = %d", $solution_id);
+ $solution_files_q = db_query("SELECT lmsf.*, lmp.directory_name FROM dwsim_flowsheet_solution_files lmsf JOIN dwsim_flowsheet_solution lms JOIN dwsim_flowsheet_experiment lme JOIN dwsim_flowsheet_proposal lmp WHERE lms.id = lmsf.solution_id AND lme.id = lms.experiment_id AND lmp.id = lme.proposal_id AND lmsf.id = :solution_id", array(':solution_id' => $solution_id));
+ /*$query = db_select('dwsim_flowsheet_solution_files');
+ $query->fields('dwsim_flowsheet_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->directory_name. '/'. $solution_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file. File does not exists.', array(
+ '!file' => $solution_files_data->directory_name. '/' . $solution_files_data->filepath
+ )), 'error');
+ continue;
+ }
+ /* removing solution file */
+ if (!unlink($root_path . $solution_files_data->directory_name. '/'. $solution_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file', array(
+ '!file' => $solution_files_data->directory_name. '/' . $solution_files_data->filepath
+ )), 'error');
+ /* sending email to admins */
+ $email_to = variable_get('dwsim_flowsheet_emails', '');
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = "";
+ $cc = variable_get('dwsim_flowsheet_cc_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->directory_name. '/'. $solution_files_data->filepath . "
+ PDF path : " . $PdfStatus;
+ $param['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'standard', $email_to, language_default(), $param, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ }
+ else
+ {
+ /* deleting example files database entries */
+ db_delete('dwsim_flowsheet_solution_files')->condition('id', $solution_files_data->id)->execute();
+ }
+ }
+ if (!$status)
+ return FALSE;
+ /* removing code folder */
+ $ex_path = $experiment_data->directory_name . '/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('dwsim_flowsheet_emails', '');
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = "";
+ $cc = variable_get('dwsim_flowsheet_cc_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'];
+ $param['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'standard', $email_to, language_default(), $param, $from, 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('dwsim_flowsheet_solution_dependency')->condition('solution_id', $solution_id)->execute();
+ db_delete('dwsim_flowsheet_solution')->condition('id', $solution_id)->execute();
+ return $status;
+ }
+function dwsim_flowsheet_delete_experiment($experiment_id)
+ {
+ $status = TRUE;
+ $root_path = dwsim_flowsheet_path();
+ //$experiment_q = db_query("SELECT * FROM {dwsim_flowsheet_experiment} WHERE id = %d", $experiment_id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_solution} WHERE experiment_id = %d", $experiment_id);
+ $query = db_select('dwsim_flowsheet_solution');
+ $query->fields('dwsim_flowsheet_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 (!dwsim_flowsheet_delete_solution($solution_data->id))
+ $status = FALSE;
+ }
+ if (!$delete_exp_folder)
+ {
+ return TRUE;
+ }
+ if ($status)
+ {
+ $dir_path = $root_path . $experiment_data->directory_name . '/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('dwsim_flowsheet_emails', '');
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = "";
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting experiment folder";
+ $param['standard']['body'] = "Error deleting folder " . $dir_path;
+ $param['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'standard', $email_to, language_default(), $param, $from, 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 dwsim_flowsheet_delete_lab($lab_id)
+ {
+ $status = TRUE;
+ $root_path = dwsim_flowsheet_path();
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $lab_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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 {dwsim_flowsheet_experiment} WHERE proposal_id = %d", $proposal_data->id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_experiment');
+ $query->condition('proposal_id', $proposal_data->id);
+ $experiment_q = $query->execute();
+ while ($experiment_data = $experiment_q->fetchObject())
+ {
+ if (!dwsim_flowsheet_delete_experiment($experiment_data->id))
+ {
+ $status = FALSE;
+ }
+ }
+ return $status;
+ }
+function dwsim_flowsheet_del_lab_pdf($lab_id)
+ {
+ $root_path = dwsim_flowsheet_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 dwsim_flowsheet_delete_dependency($dependency_id)
+ {
+ global $user;
+ $root_path = dwsim_flowsheet_path();
+ $status = TRUE;
+ //$dependency_files_q = db_query("SELECT * FROM {dwsim_flowsheet_dependency_files} WHERE id = %d", $dependency_id);
+ $query = db_select('dwsim_flowsheet_dependency_files');
+ $query->fields('dwsim_flowsheet_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('dwsim_flowsheet_emails', '');
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = "";
+ $cc = variable_get('dwsim_flowsheet_cc_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;
+ $param['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'standard', $email_to, language_default(), $param, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ }
+ else
+ {
+ /* deleting dependency files database entries */
+ db_delete('dwsim_flowsheet_dependency_files')->condition('id', $dependency_id)->execute();
+ }
+ return $status;
+ }
diff --git a/manage_proposal.inc b/manage_proposal.inc
new file mode 100755
index 0000000..3e07608
--- /dev/null
+++ b/manage_proposal.inc
@@ -0,0 +1,1067 @@
+<?php
+// $Id$
+function dwsim_flowsheet_proposal_pending()
+{
+ /* get pending proposals to be approved */
+ $pending_rows = array();
+ //$pending_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE approval_status = 0 ORDER BY id DESC");
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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_title . ' ' . $pending_data->contributor_name, 'user/' . $pending_data->uid),
+ $pending_data->project_title,
+ l('Approve', 'flowsheeting-project/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'flowsheeting-project/manage-proposal/edit/' . $pending_data->id)
+ );
+ } //$pending_data = $pending_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$pending_rows)
+ {
+ drupal_set_message(t('There are no pending proposals.'), 'status');
+ return '';
+ } //!$pending_rows
+ $pending_header = array(
+ 'Date of Submission',
+ 'Student Name',
+ 'Title of the Flowsheet Project',
+ 'Action'
+ );
+ //$output = theme_table($pending_header, $pending_rows);
+ $output = theme('table', array(
+ 'header' => $pending_header,
+ 'rows' => $pending_rows
+ ));
+ return $output;
+}
+function dwsim_flowsheet_proposal_pending_solution()
+{
+ /* get pending proposals to be approved */
+ $pending_rows = array();
+ //$pending_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE approval_status = 1 ORDER BY id DESC");
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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->project_title,
+ $pending_data->department,
+ l('Status', 'flowsheeting-project/manage-proposal/status/' . $pending_data->id)
+ );
+ } //$pending_data = $pending_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$pending_rows)
+ {
+ drupal_set_message(t('There are no proposals pending for solutions.'), 'status');
+ return '';
+ } //!$pending_rows
+ $pending_header = array(
+ 'Date of Submission',
+ 'Date of Approval',
+ 'Student name',
+ 'Title of the Flowsheet Project',
+ 'Department',
+ 'Action'
+ );
+ $output = theme('table', array(
+ 'header' => $pending_header,
+ 'rows' => $pending_rows
+ ));
+ return $output;
+}
+function dwsim_flowsheet_proposal_all()
+{
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} ORDER BY id DESC");
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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 = 'Completed';
+ break;
+ default:
+ $approval_status = 'Unknown';
+ break;
+ } //$proposal_data->approval_status
+ if ($proposal_data->actual_completion_date == 0)
+ {
+ $actual_completion_date = "Not Completed";
+ } //$proposal_data->actual_completion_date == 0
+ else
+ {
+ $actual_completion_date = date('d-m-Y', $proposal_data->actual_completion_date);
+ }
+ $proposal_rows[] = array(
+ date('d-m-Y', $proposal_data->creation_date),
+ l($proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ $proposal_data->project_title,
+ $actual_completion_date,
+ $approval_status,
+ l('Status', 'flowsheeting-project/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'flowsheeting-project/manage-proposal/edit/' . $proposal_data->id)
+ );
+ } //$proposal_data = $proposal_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows)
+ {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'Date of Submission',
+ 'Student Name',
+ 'Title of the Lab',
+ 'Date of Completion',
+ 'Status',
+ 'Action'
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows
+ ));
+ return $output;
+}
+/******************************************************************************/
+/************************** PROPOSAL APPROVAL FORM ****************************/
+/******************************************************************************/
+function dwsim_flowsheet_proposal_approval_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ if ($proposal_data->project_guide_name == "NULL" || $proposal_data->project_guide_name == "")
+ {
+ $project_guide_name = "Not Entered";
+ } //$proposal_data->project_guide_name == NULL
+ else
+ {
+ $project_guide_name = $proposal_data->project_guide_name;
+ }
+ if ($proposal_data->project_guide_email_id == "NULL" || $proposal_data->project_guide_email_id == "")
+ {
+ $project_guide_email_id = "Not Entered";
+ } //$proposal_data->project_guide_email_id == NULL
+ else
+ {
+ $project_guide_email_id = $proposal_data->project_guide_email_id;
+ }
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ '#title' => t('Student name')
+ );
+ $form['student_email_id'] = array(
+ '#title' => t('Student Email'),
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email')
+ );
+ $form['month_year_of_degree'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Month and year of award of degree'),
+ '#date_label_position' => '',
+ '#description' => '',
+ '#default_value' => $proposal_data->month_year_of_degree,
+ '#date_format' => 'M-Y',
+ '#date_increment' => 0,
+ '#date_year_range' => '1960:+0',
+ '#datepicker_options' => array(
+ 'maxDate' => 0
+ ),
+ '#disabled' => TRUE
+ );
+ $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['version'] = array(
+ '#type' => 'item',
+ '#title' => t('DWSIM version'),
+ '#markup' => $proposal_data->version
+ );
+ $form['project_guide_name'] = array(
+ '#type' => 'item',
+ '#title' => t('Project guide'),
+ '#markup' => $project_guide_name
+ );
+ $form['project_guide_email_id'] = array(
+ '#type' => 'item',
+ '#title' => t('Project guide email'),
+ '#markup' => $project_guide_email_id
+ );
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Flowsheet Project')
+ );
+ $headers = array(
+ "User defined compound",
+ "CAS No."
+ );
+ $rows = array();
+ $item = array(
+ "{$proposal_data->process_development_compound_name}",
+ "{$proposal_data->process_development_compound_cas_number}"
+ );
+ array_push($rows, $item);
+ $prodata = theme('table', array(
+ 'header' => $headers,
+ 'rows' => $rows
+ ));
+ $form['process_development_compound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('Name of compound for which process development is carried out'),
+ '#markup' => $prodata
+ );
+ /*
+ $form['process_development_compound_cas_number'] = array(
+ '#type' => 'item',
+ '#title' => t('CAS Number of compound for which process development is carried out'),
+ '#markup' => $proposal_data->process_development_compound_cas_number
+ );*/
+ $form['dwsim_database_compound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('List of compounds from DWSIM Database used in process flowsheet'),
+ '#markup' => $proposal_data->dwsim_database_compound_name
+ );
+ $form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#markup' => _dwsim_flowsheet_list_of_user_defined_compound($proposal_id)
+ );
+ if ($proposal_data->user_defined_compound_filepath != "")
+ {
+ $form['user_defined_compound_filepath'] = array(
+ '#type' => 'item',
+ '#title' => t('Uploaded the user defined compound '),
+ '#markup' => l('Download user defined compound list', 'flowsheeting-project/download/user-defined-compound-file/' . $proposal_id) . "<br><br>"
+ );
+ } //$proposal_data->user_defined_compound_filepath != ""
+ else
+ {
+ $form['user_defined_compound_filepath'] = array(
+ '#type' => 'item',
+ '#title' => t('Uploaded the user defined compound '),
+ '#markup' => "Not uploaded<br><br>"
+ );
+ }
+ $form['approval'] = array(
+ '#type' => 'radios',
+ '#title' => t('DWSIM flowsheeting 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
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="approval"]' => array(
+ 'value' => '2'
+ )
+ )
+ )
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'flowsheeting-project/manage-proposal')
+ );
+ return $form;
+}
+function dwsim_flowsheet_proposal_approval_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['approval'] == 2)
+ {
+ if ($form_state['values']['message'] == '')
+ {
+ form_set_error('message', t('Reason for disapproval could not be empty'));
+ } //$form_state['values']['message'] == ''
+ } //$form_state['values']['approval'] == 2
+}
+function dwsim_flowsheet_proposal_approval_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ // $proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ if ($form_state['values']['approval'] == 1)
+ {
+ $query = "UPDATE {dwsim_flowsheet_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;
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['dwsim_flowsheet_proposal_approved']['proposal_id'] = $proposal_id;
+ $params['dwsim_flowsheet_proposal_approved']['user_id'] = $proposal_data->uid;
+ $params['dwsim_flowsheet_proposal_approved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'dwsim_flowsheet_proposal_approved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('DWSIM flowsheeting proposal No. ' . $proposal_id . ' approved. User has been notified of the approval.', 'status');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ } //$form_state['values']['approval'] == 1
+ else if ($form_state['values']['approval'] == 2)
+ {
+ $query = "UPDATE {dwsim_flowsheet_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 2, dissapproval_reason = :dissapproval_reason WHERE id = :proposal_id";
+ $args = array(
+ ":uid" => $user->uid,
+ ":date" => time(),
+ ":dissapproval_reason" => $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;
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['dwsim_flowsheet_proposal_disapproved']['proposal_id'] = $proposal_id;
+ $params['dwsim_flowsheet_proposal_disapproved']['user_id'] = $proposal_data->uid;
+ $params['dwsim_flowsheet_proposal_disapproved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'dwsim_flowsheet_proposal_disapproved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('DWSIM flowsheeting proposal No. ' . $proposal_id . ' dis-approved. User has been notified of the dis-approval.', 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ } //$form_state['values']['approval'] == 2
+}
+/******************************************************************************/
+/*************************** PROPOSAL STATUS FORM *****************************/
+/******************************************************************************/
+function dwsim_flowsheet_proposal_status_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ '#title' => t('Student name')
+ );
+ $form['student_email_id'] = array(
+ '#title' => t('Student Email'),
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email')
+ );
+ $form['month_year_of_degree'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Month and year of award of degree'),
+ '#date_label_position' => '',
+ '#description' => '',
+ '#default_value' => $proposal_data->month_year_of_degree,
+ '#date_format' => 'M-Y',
+ '#date_increment' => 0,
+ '#date_year_range' => '1960:+0',
+ '#datepicker_options' => array(
+ 'maxDate' => 0
+ ),
+ '#disabled' => TRUE
+ );
+ $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['version'] = array(
+ '#type' => 'item',
+ '#title' => t('DWSIM version'),
+ '#markup' => $proposal_data->version
+ );
+ $form['project_guide_name'] = array(
+ '#type' => 'item',
+ '#title' => t('Project guide'),
+ '#markup' => $proposal_data->project_guide_name
+ );
+ $form['project_guide_email_id'] = array(
+ '#type' => 'item',
+ '#title' => t('Project guide email'),
+ '#markup' => $proposal_data->project_guide_email_id
+ );
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Flowsheet Project')
+ );
+ $form['process_development_compound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('Name of compound for which process development is carried out'),
+ '#markup' => $proposal_data->process_development_compound_name
+ );
+ $form['process_development_compound_cas_number'] = array(
+ '#type' => 'item',
+ '#title' => t('CAS Number of compound for which process development is carried out'),
+ '#markup' => $proposal_data->process_development_compound_cas_number
+ );
+ $form['dwsim_database_compound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('List of compounds from DWSIM Database used in process flowsheet'),
+ '#markup' => $proposal_data->dwsim_database_compound_name
+ );
+ if ($proposal_data->user_defined_compounds_used_in_process != "" || $proposal_data->user_defined_compounds_used_in_process != NULL)
+ {
+ $form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#markup' => $proposal_data->user_defined_compounds_used_in_process
+ );
+ } //$proposal_data->user_defined_compounds_used_in_process != "" || $proposal_data->user_defined_compounds_used_in_process != NULL
+ else
+ {
+ $form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'item',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#markup' => "Not entered"
+ );
+ }
+ if ($proposal_data->user_defined_compound_filepath != "")
+ {
+ $form['user_defined_compound_filepath'] = array(
+ '#type' => 'item',
+ '#title' => t('Uploaded the user defined compound '),
+ '#markup' => l('Download user defined compound list', 'flowsheeting-project/download/user-defined-compound-file/' . $proposal_id) . "<br><br>"
+ );
+ } //$proposal_data->user_defined_compound_filepath != ""
+ else
+ {
+ $form['user_defined_compound_filepath'] = array(
+ '#type' => 'item',
+ '#title' => t('Uploaded the user defined compound '),
+ '#markup' => "Not uploaded<br><br>"
+ );
+ }
+ $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;
+ } //$proposal_data->approval_status
+ $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', 'flowsheeting-project/manage-proposal/approve/' . $proposal_id),
+ '#title' => t('Approve')
+ );
+ } //$proposal_data->approval_status == 0
+ if ($proposal_data->approval_status == 1)
+ {
+ $form['completed'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Completed'),
+ '#description' => t('Check if user has provided all the required files and pdfs.')
+ );
+ } //$proposal_data->approval_status == 1
+ if ($proposal_data->approval_status == 2)
+ {
+ $form['message'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->message,
+ '#title' => t('Reason for disapproval')
+ );
+ } //$proposal_data->approval_status == 2
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#markup' => l(t('Cancel'), 'flowsheeting-project/manage-proposal/all')
+ );
+ return $form;
+}
+function dwsim_flowsheet_proposal_status_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ /* set the book status to completed */
+ if ($form_state['values']['completed'] == 1)
+ {
+ $up_query = "UPDATE dwsim_flowsheet_proposal SET approval_status = :approval_status , actual_completion_date = :expected_completion_date WHERE id = :proposal_id";
+ $args = array(
+ ":approval_status" => '3',
+ ":proposal_id" => $proposal_id,
+ ":expected_completion_date" => time()
+ );
+ $result = db_query($up_query, $args);
+ CreateReadmeFileDWSIMFlowsheetingProject($proposal_id);
+ if (!$result)
+ {
+ drupal_set_message('Error in update status', 'error');
+ return;
+ } //!$result
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['proposal_completed']['proposal_id'] = $proposal_id;
+ $params['proposal_completed']['user_id'] = $proposal_data->uid;
+ $params['proposal_completed']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'proposal_completed', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ /*$email_to = $user->mail . ', ' . variable_get('dwsim_flowsheet_emails', '');;
+ if (!drupal_mail('dwsim_flowsheet', 'proposal_completed', $email_to , language_default(), $params, variable_get('dwsim_flowsheet_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');*/
+ drupal_set_message('Congratulations! DWSIM flowsheeting proposal has been marked as completed. User has been notified of the completion.', 'status');
+ } //$form_state['values']['completed'] == 1
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+}
+/******************************************************************************/
+/**************************** PROPOSAL EDIT FORM ******************************/
+/******************************************************************************/
+function dwsim_flowsheet_proposal_edit_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ $user_data = user_load($proposal_data->uid);
+ $form['name_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title'),
+ '#options' => array(
+ 'Dr' => 'Dr',
+ 'Prof' => 'Prof',
+ 'Mr' => 'Mr',
+ 'Mrs' => 'Mrs',
+ 'Ms' => 'Ms'
+ ),
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->name_title
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Proposer'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->contributor_name
+ );
+ $form['student_email_id'] = array(
+ '#type' => 'item',
+ '#title' => t('Email'),
+ '#markup' => $user_data->mail
+ );
+ $form['month_year_of_degree'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Month and year of award of degree'),
+ '#date_label_position' => '',
+ '#description' => '',
+ '#default_value' => $proposal_data->month_year_of_degree,
+ '#date_format' => 'M-Y',
+ '#date_increment' => 0,
+ '#date_year_range' => '1960:+0',
+ '#datepicker_options' => array(
+ 'maxDate' => 0
+ ),
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->university
+ );
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others'
+ ),
+ '#default_value' => $proposal_data->country,
+ '#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#default_value' => $proposal_data->country,
+ '#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')
+ ),
+ '#default_value' => $proposal_data->state,
+ '#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')
+ ),
+ '#default_value' => $proposal_data->city,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['all_state'] = array(
+ '#type' => 'select',
+ '#title' => t('State'),
+ '#options' => _df_list_of_states(),
+ '#default_value' => $proposal_data->state,
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _df_list_of_cities(),
+ '#default_value' => $proposal_data->city,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#default_value' => $proposal_data->pincode,
+ '#attributes' => array(
+ 'placeholder' => 'Insert pincode of your city/ village....'
+ )
+ );
+ $form['project_title'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Title of the Flowsheet Project'),
+ '#size' => 300,
+ '#maxlength' => 350,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->project_title
+ );
+ $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'), 'flowsheeting-project/manage-proposal')
+ );
+ return $form;
+}
+/*
+function dwsim_flowsheet_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 {dwsim_flowsheet_experiment} WHERE proposal_id = %d", $proposal_id);
+$query = db_select('dwsim_flowsheet_user_defined_compound');
+$query->fields('dwsim_flowsheet_user_defined_compound');
+$query->condition('proposal_id', $proposal_id);
+$experiment_q = $query->execute();
+while ($experiment_data = $experiment_q->fetchObject())
+{
+//$solution_q = db_query("SELECT * FROM {dwsim_flowsheet_solution} WHERE experiment_id = %d", $experiment_data->id);
+$query = db_select('dwsim_flowsheet_user_defined_compound');
+$query->fields('dwsim_flowsheet_user_defined_compound');
+$query->condition('proposal_id', $proposal_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'));
+} //$solution_q->fetchObject()
+} //$experiment_data = $experiment_q->fetchObject()
+} //$form_state['values']['delete_proposal'] == 1
+return;
+}*/
+function dwsim_flowsheet_proposal_edit_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ // $proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ }
+ /* delete proposal */
+ if ($form_state['values']['delete_proposal'] == 1)
+ {
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['dwsim_flowsheet_proposal_deleted']['proposal_id'] = $proposal_id;
+ $params['dwsim_flowsheet_proposal_deleted']['user_id'] = $user->uid;
+ //$params['dwsim_flowsheet_proposal_deleted']['file_name'] = $_FILES['files']['name'][$file_form_name];
+ $params['dwsim_flowsheet_proposal_deleted']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'dwsim_flowsheet_proposal_deleted', $email_to, user_preferred_language($user), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t('DWSIM Flowsheeting proposal has been deleted.'), 'status');
+ //db_query("DELETE FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ if (rrmdir_project($proposal_id) == TRUE)
+ {
+ $query = db_delete('dwsim_flowsheet_proposal');
+ $query->condition('id', $proposal_id);
+ $num_deleted = $query->execute();
+ db_query("DELETE FROM {dwsim_flowsheet_user_defined_compound} WHERE proposal_id = :proposal_id", array(
+ ":proposal_id" => $proposal_id
+ ));
+ drupal_set_message(t('Proposal Deleted'), 'status');
+ drupal_goto('flowsheeting-project/manage-proposal');
+ return;
+ } //rrmdir_project($proposal_id) == TRUE
+ } //$form_state['values']['delete_proposal'] == 1
+ /* update proposal */
+ $v = $form_state['values'];
+ $project_title = $v['project_title'];
+ $proposar_name = $v['name_title'] . ' ' . $v['contributor_name'];
+ $university = $v['university'];
+ $directory_names = _df_dir_name($project_title, $proposar_name);
+ if (DF_RenameDir($proposal_id, $directory_names))
+ {
+ $directory_name = $directory_names;
+ } //LM_RenameDir($proposal_id, $directory_names)
+ else
+ {
+ return;
+ }
+ $query = "UPDATE dwsim_flowsheet_proposal SET
+ name_title=:name_title,
+ contributor_name=:contributor_name,
+ university=:university,
+ city=:city,
+ pincode=:pincode,
+ state=:state,
+ project_title=:project_title,
+ directory_name=:directory_name
+ WHERE id=:proposal_id";
+ $args = array(
+ ':name_title' => $v['name_title'],
+ ':contributor_name' => $v['contributor_name'],
+ ':university' => $v['university'],
+ ':city' => $v['city'],
+ ':pincode' => $v['pincode'],
+ ':state' => $v['all_state'],
+ ':project_title' => $project_title,
+ ':directory_name' => $directory_name,
+ ':proposal_id' => $proposal_id
+ );
+ $result = db_query($query, $args);
+ drupal_set_message(t('Proposal Updated'), 'status');
+}
diff --git a/proposal.inc b/proposal.inc
new file mode 100755
index 0000000..6564ae7
--- /dev/null
+++ b/proposal.inc
@@ -0,0 +1,794 @@
+<?php
+// $Id$
+/*
+Approval Status :
+0 - Pending
+1 - Approved
+2 - Dis-Approved
+3 - Completed
+Solution Status :
+0 - Pending
+1 - Approved
+2 - Dis-Approved
+Solution Display :
+0 - No
+1 - Yes
+
+Tables :
+dwsim_flowsheet_solution : approval_status
+0 - Pending
+1 - Approved
+2 - Disapproved (delete it)
+*/
+function dwsim_flowsheet_proposal_form($form, &$form_state, $no_js_use = FALSE)
+{
+ global $user;
+ /************************ start approve book details ************************/
+ if ($user->uid == 0)
+ {
+ $msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the lab proposal form. If you are new user please create a new account first.'), 'error');
+ //drupal_goto('dwsim-flowsheet-project');
+ drupal_goto('user');
+ return $msg;
+ } //$user->uid == 0
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_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;
+ } //$proposal_data->approval_status == 0 || $proposal_data->approval_status == 1
+ } //$proposal_data
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['name_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title'),
+ '#options' => array(
+ 'Dr' => 'Dr',
+ 'Prof' => 'Prof',
+ 'Mr' => 'Mr',
+ 'Mrs' => 'Mrs',
+ 'Ms' => 'Ms'
+ ),
+ '#required' => TRUE
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the contributor'),
+ '#size' => 250,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your full name.....')
+ ),
+ '#maxlength' => 250,
+ '#required' => TRUE
+ );
+ $form['contributor_contact_no'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact No.'),
+ '#size' => 10,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your contact number')
+ ),
+ '#maxlength' => 250
+ );
+ $form['gender'] = array(
+ '#type' => 'select',
+ '#title' => t('Gender'),
+ '#options' => array(
+ 'Male' => 'Male',
+ 'Female' => 'Female',
+ 'Other' => 'Other'
+ ),
+ '#required' => TRUE
+ );
+ $form['month_year_of_degree'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Month and year of award of degree'),
+ '#date_label_position' => '',
+ '#description' => '',
+ '#default_value' => '',
+ '#date_format' => 'M-Y',
+ '#date_increment' => 0,
+ '#date_year_range' => '1960:+0',
+ '#datepicker_options' => array(
+ 'maxDate' => 0
+ ),
+ '#required' => TRUE
+ );
+ $form['contributor_email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE
+ );
+ $form['project_guide_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Project guide'),
+ '#size' => 250,
+ '#attributes' => array(
+ 'placeholder' => t('Enter full name of project guide')
+ ),
+ '#maxlength' => 250
+ );
+ $form['project_guide_email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Project guide email'),
+ '#size' => 30
+ );
+ $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' => _df_list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _df_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....'
+ ),
+ '#required' => TRUE
+ );
+ /***************************************************************************/
+ $form['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>'
+ );
+ $form['project_title'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Project Title'),
+ '#size' => 250,
+ '#description' => t('Maximum character limit is 250'),
+ '#required' => TRUE
+ );
+ $form['version'] = array(
+ '#type' => 'select',
+ '#title' => t('Version'),
+ '#options' => _df_list_of_software_version(),
+ '#required' => TRUE
+ );
+ $form['older'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other Version'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ //'#required' => TRUE,
+ '#description' => t('Specify the Older version used as format "DWSIM v2.0"'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="version"]' => array(
+ 'value' => 'Old version'
+ )
+ )
+ )
+ );
+ $form['process_development_compound_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of compound for which process development is carried out'),
+ '#size' => 50,
+ '#description' => t('Mention the compound name as shown:
+Ex: Ethanol'),
+ '#required' => TRUE
+ );
+ $form['process_development_compound_cas_no'] = array(
+ '#type' => 'textfield',
+ '#title' => t('CAS number for compound which process development is carried out'),
+ '#size' => 50,
+ '#description' => t('Mention the compound CAS No as shown:
+Ex: 64-17-5'),
+ '#required' => TRUE
+ );
+ $form['dwsim_database_compound_name'] = array(
+ '#type' => 'select',
+ '#title' => t('List of compounds from DWSIM Database used in process flowsheet'),
+ '#multiple' => TRUE,
+ '#size' => '20',
+ '#description' => t('Select all the compounds used in flowsheet which are available in above DWSIM compound list [You can select multiple options by holding ctrl + left key of mouse]'),
+ '#options' => _df_list_of_dwsim_compound(),
+ '#required' => TRUE
+ );
+ $form['ucompound'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Is user defined compound used?')
+ );
+ /*$form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'textarea',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="ucompound"]' => array(
+ 'checked' => True
+ )
+ )
+ )
+ );*/
+ $form['upload_u_compound'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Upload user defind compound'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="ucompound"]' => array(
+ 'checked' => True
+ )
+ )
+ )
+ );
+ $form['upload_u_compound']['udc_field1_fieldset'] = array(
+ '#type' => 'fieldset',
+ '#tree' => TRUE,
+ '#prefix' => '<div id="udc-field1-fieldset-wrapper">',
+ '#suffix' => '</div>',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="ucompound"]' => array(
+ 'checked' => True
+ )
+ )
+ )
+ );
+ if (empty($form_state['user_defined_compound_num']))
+ {
+ $form_state['user_defined_compound_num'] = 1;
+ } //empty($form_state['user_defined_compound_num'])
+ $udc_temp1 = 0;
+ for ($udc_i = 0; $udc_i < $form_state['user_defined_compound_num']; $udc_i++)
+ {
+ $udc_temp1 = $udc_i;
+ $form['upload_u_compound']['udc_field1_fieldset'][$udc_i]["compound"] = array(
+ "#type" => "textfield",
+ "#title" => "Name of User defined compound " . ($udc_temp1 + 1),
+ "#default_value" => ""
+ );
+ $form['upload_u_compound']['udc_field1_fieldset'][$udc_i]["cas_no"] = array(
+ "#type" => "textfield",
+ "#title" => "CAS Number of User defined compound " . ($udc_temp1 + 1),
+ "#default_value" => ""
+ );
+ } //$i = 0; $i < $form_state['step1_num_compound']; $i++
+ $form['upload_u_compound']['udc_field1_fieldset']["udc_compound_count"] = array(
+ "#type" => "hidden",
+ "#value" => $udc_temp1
+ );
+ $form['upload_u_compound']['udc_field1_fieldset']['add_compound'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add more compound'),
+ '#limit_validation_errors' => array(),
+ '#submit' => array(
+ 'udc_compound_add_more_add_one'
+ ),
+ '#ajax' => array(
+ 'callback' => 'udc_compound_add_more_callback',
+ 'wrapper' => array(
+ 'udc-field1-fieldset-wrapper'
+ )
+ )
+ );
+ if ($form_state['user_defined_compound_num'] > 1)
+ {
+ $form['upload_u_compound']['udc_field1_fieldset']['remove_compound'] = array(
+ '#type' => 'submit',
+ '#value' => t('Remove compound'),
+ '#limit_validation_errors' => array(),
+ '#submit' => array(
+ 'udc_compound_add_more_remove_one'
+ ),
+ '#ajax' => array(
+ 'callback' => 'udc_compound_add_more_callback',
+ 'wrapper' => array(
+ 'udc-field1-fieldset-wrapper'
+ )
+ )
+ );
+ } //$form_state['step1_num_compound'] > 1
+ if ($no_js_use)
+ {
+ if (!empty($form['upload_u_compound']['udc_field1_fieldset']['remove_compound']['#ajax']))
+ {
+ unset($form['upload_u_compound']['udc_field1_fieldset']['remove_compound']['#ajax']);
+ } //!empty($form['udc_field1_fieldset']['remove_compound']['#ajax'])
+ unset($form['upload_u_compound']['udc_field1_fieldset']['add_compound']['#ajax']);
+ } //$no_js_use
+ $form['upload_u_compound']['upload_user_compound'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload user defined compound'),
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('dwsim_flowsheet_user_defind_compound_source_extensions', '') . '</span>',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="ucompound"]' => array(
+ 'checked' => True
+ )
+ )
+ )
+ );
+ $form['term_condition'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Terms And Conditions'),
+ '#options' => array(
+ 'status' => t('<a href="/term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>')
+ ),
+ '#required' => TRUE
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+/***************************************/
+function udc_compound_add_more_add_one($form, &$form_state)
+{
+ $form_state['user_defined_compound_num']++;
+ $form_state['rebuild'] = TRUE;
+ //$form_state['no_redirect'] = TRUE;
+}
+function udc_compound_add_more_remove_one($form, &$form_state)
+{
+ if ($form_state['user_defined_compound_num'] > 1)
+ {
+ $form_state['user_defined_compound_num']--;
+ } //$form_state['user_defined_compound_num'] > 1
+ $form_state['rebuild'] = TRUE;
+}
+function udc_compound_add_more_callback($form, &$form_state)
+{
+ return $form['upload_u_compound']['udc_field1_fieldset'];
+}
+/***************************************/
+function dwsim_flowsheet_proposal_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['term_condition'] == '1')
+ {
+ form_set_error('term_condition', t('Please check the terms and conditions'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['term_condition'] == '1'
+ 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'];
+ } //$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'];
+ } //$form_state['values']['other_state'] == ''
+ 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'];
+ } //$form_state['values']['other_city'] == ''
+ else
+ {
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ } //$form_state['values']['country'] == 'Others'
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
+ form_set_error('country', t('Select country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['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'];
+ } //$form_state['values']['all_state'] == ''
+ if ($form_state['values']['city'] == '')
+ {
+ form_set_error('city', t('Select city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['city'] == ''
+ }
+ //Validation for project title
+ $form_state['values']['project_title'] = trim($form_state['values']['project_title']);
+ if ($form_state['values']['project_title'] != '')
+ {
+ if (strlen($form_state['values']['project_title']) > 250)
+ {
+ form_set_error('project_title', t('Maximum charater limit is 250 charaters only, please check the length of the project title'));
+ } //strlen($form_state['values']['project_title']) > 250
+ else if (strlen($form_state['values']['project_title']) < 10)
+ {
+ form_set_error('project_title', t('Minimum charater limit is 10 charaters, please check the length of the project title'));
+ } //strlen($form_state['values']['project_title']) < 10
+ } //$form_state['values']['project_title'] != ''
+ else
+ {
+ form_set_error('project_title', t('Project title shoud not be empty'));
+ }
+ // validation for Name of compound for which process development is carried out
+ $form_state['values']['process_development_compound_name'] = trim($form_state['values']['process_development_compound_name']);
+ if ($form_state['values']['process_development_compound_name'] != '')
+ {
+ if (strlen($form_state['values']['process_development_compound_name']) >= 50)
+ {
+ form_set_error('process_development_compound_name', t('Maximum charater limit is 50 charaters only, please check the length'));
+ } //strlen($form_state['values']['process_development_compound_name']) >= 50
+ else if (strlen($form_state['values']['process_development_compound_name']) < 1)
+ {
+ form_set_error('process_development_compound_name', t('Minimum charater limit is 1 charaters, please check the length'));
+ } //strlen($form_state['values']['process_development_compound_name']) < 1
+ } //$form_state['values']['process_development_compound_name'] != ''
+ else
+ {
+ form_set_error('process_development_compound_name', t('Field should not be empty'));
+ }
+ $form_state['values']['process_development_compound_cas_no'] = trim($form_state['values']['process_development_compound_cas_no']);
+ if ($form_state['values']['process_development_compound_cas_no'] != '')
+ {
+ if (strlen($form_state['values']['process_development_compound_cas_no']) < 1)
+ {
+ form_set_error('process_development_compound_cas_no', t('Minimum charater limit is 1 charaters, please check the length'));
+ } //strlen($form_state['values']['process_development_compound_cas_no']) < 1
+ } //$form_state['values']['process_development_compound_cas_no'] != ''
+ else
+ {
+ form_set_error('process_development_compound_cas_no', t('CAS number field should not be empty'));
+ }
+ if ($form_state['values']['version'] == 'Old version')
+ {
+ if ($form_state['values']['older'] == '')
+ {
+ form_set_error('older', t('Please provide valid version'));
+ } //$form_state['values']['older'] == ''
+ } //$form_state['values']['version'] == 'Old version'
+ if ($form_state['values']['dwsim_database_compound_name'])
+ {
+ $dwsim_database_compound_name = implode(", ", $_POST['dwsim_database_compound_name']);
+ $form_state['values']['dwsim_database_compound_name'] = trim($dwsim_database_compound_name);
+ } //$form_state['values']['dwsim_database_compound_name']
+ if ($form_state['values']['ucompound'] == 1)
+ {
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['upload_user_compound']))
+ form_set_error('upload_user_compound', t('Please upload a 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, 'user_compound'))
+ $file_type = 'S';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('dwsim_flowsheet_user_defind_compound_source_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($fnames);
+ 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 (!textbook_companion_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'])
+ } //$form_state['values']['ucompound'] == 1
+ return;
+}
+function dwsim_flowsheet_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;
+ } //!$user->uid
+ if ($form_state['values']['version'] == 'Old version')
+ {
+ $form_state['values']['version'] = trim($form_state['values']['older']);
+ } //$form_state['values']['version'] == 'Old version'
+ /* inserting the user proposal */
+ $v = $form_state["values"];
+ $project_title = trim($v['project_title']);
+ $proposar_name = $v['name_title'] . ' ' . $v['contributor_name'];
+ $university = $v['university'];
+ $month_year_of_degree = $v['month_year_of_degree'];
+ $directory_name = _df_dir_name($project_title, $proposar_name);
+ $result = "INSERT INTO {dwsim_flowsheet_proposal}
+ (
+ uid,
+ approver_uid,
+ name_title,
+ contributor_name,
+ contact_no,
+ gender,
+ month_year_of_degree,
+ university,
+ city,
+ pincode,
+ state,
+ country,
+ version,
+ project_guide_name,
+ project_guide_email_id,
+ project_title,
+ process_development_compound_name,
+ process_development_compound_cas_number,
+ dwsim_database_compound_name,
+ approval_status,
+ dissapproval_reason,
+ creation_date,
+ approval_date,
+ directory_name,
+ user_defined_compound_filepath
+ ) VALUES
+ (
+ :uid,
+ :approver_uid,
+ :name_title,
+ :contributor_name,
+ :contact_no,
+ :gender,
+ :month_year_of_degree,
+ :university,
+ :city,
+ :pincode,
+ :state,
+ :country,
+ :version,
+ :project_guide_name,
+ :project_guide_email_id,
+ :project_title,
+ :process_development_compound_name,
+ :process_development_compound_cas_number,
+ :dwsim_database_compound_name,
+ :approval_status,
+ :dissapproval_reason,
+ :creation_date,
+ :approval_date,
+ :directory_name,
+ :user_defined_compound_filepath
+ )";
+ $args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":name_title" => $v['name_title'],
+ ":contributor_name" => _df_sentence_case(trim($v['contributor_name'])),
+ ":contact_no" => $v['contributor_contact_no'],
+ ":gender" => $v['gender'],
+ ":month_year_of_degree" => $month_year_of_degree,
+ ":university" => _df_sentence_case($v['university']),
+ ":city" => $v['city'],
+ ":pincode" => $v['pincode'],
+ ":state" => $v['all_state'],
+ ":country" => $v['country'],
+ ":version" => $v['version'],
+ ":project_guide_name" => _df_sentence_case($v['project_guide_name']),
+ ":project_guide_email_id" => trim($v['project_guide_email_id']),
+ ":project_title" => _df_sentence_case($v['project_title']),
+ ":process_development_compound_name" => _df_sentence_case($v['process_development_compound_name']),
+ ":process_development_compound_cas_number" => $v['process_development_compound_cas_no'],
+ ":dwsim_database_compound_name" => trim($v['dwsim_database_compound_name']),
+ ":approval_status" => 0,
+ ":dissapproval_reason" => "NULL",
+ ":creation_date" => time(),
+ ":approval_date" => 0,
+ ":directory_name" => $directory_name,
+ ":user_defined_compound_filepath" => "NULL"
+ );
+ //var_dump($args);die;
+ $proposal_id = db_query($result, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ if ($form_state['values']['ucompound'] == 1)
+ {
+ /* For adding compounds */
+ $compounds = 0;
+ for ($i = 0; $i <= $v['udc_field1_fieldset']["udc_compound_count"]; $i++)
+ {
+ if ($v['udc_field1_fieldset'][$i]["compound"] != "" && $v['udc_field1_fieldset'][$i]["cas_no"] != "")
+ {
+ $compoundquery = "
+ INSERT INTO dwsim_flowsheet_user_defined_compound
+ (proposal_id, user_defined_compound, cas_no, compound_type)
+ VALUES
+ (:proposal_id, :user_defined_compound, :cas_no, :compound_type)
+ ";
+ $compoundargs = array(
+ ":proposal_id" => $proposal_id,
+ ":user_defined_compound" => trim($v['udc_field1_fieldset'][$i]["compound"]),
+ ":cas_no" => trim($v['udc_field1_fieldset'][$i]["cas_no"]),
+ ":compound_type" => 'U'
+ );
+ /* storing the row id in $result */
+ $compoundresult = db_query($compoundquery, $compoundargs, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ if ($compoundresult != 0)
+ {
+ $compounds++;
+ } //$compoundresult != 0
+ } //$v['udc_field1_fieldset'][$i]["compound"] != ""
+ } //$i = 0; $i <= $v['udc_field1_fieldset']["udc_compound_count"]; $i++
+ $root_path = dwsim_flowsheet_document_path();
+ $dest_path1 = $directory_name . '/';
+ $dest_path2 = 'user_defined_compound/';
+ $dest_path = $dest_path1 . 'user_defined_compound/';
+ $db_path = 'user_defined_compound/';
+ if (!is_dir($root_path . $dest_path1))
+ mkdir($root_path . $dest_path1);
+ 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');
+ unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]);
+ } //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 {dwsim_flowsheet_proposal} SET user_defined_compound_filepath = :user_defined_compound_filepath WHERE id = :id";
+ $args = array(
+ ":user_defined_compound_filepath" => $dest_path2 . $_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 : ' . $db_path . '/' . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //$form_state['values']['ucompound'] == 1
+ else
+ {
+ $file_name = "Not Uploaded";
+ }
+ if (!$proposal_id)
+ {
+ drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
+ return;
+ } //!$proposal_id
+ /* sending email */
+ $email_to = $user->mail;
+ $form = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['dwsim_flowsheet_proposal_received']['proposal_id'] = $proposal_id;
+ $params['dwsim_flowsheet_proposal_received']['user_id'] = $user->uid;
+ $params['dwsim_flowsheet_proposal_received']['headers'] = array(
+ 'From' => $form,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'dwsim_flowsheet_proposal_received', $email_to, user_preferred_language($user), $params, $form, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t('We have received your DWSIM Flowsheeting proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+}
diff --git a/settings.inc b/settings.inc
new file mode 100755
index 0000000..c7dff42
--- /dev/null
+++ b/settings.inc
@@ -0,0 +1,98 @@
+<?php
+// $Id$
+function dwsim_flowsheet_settings_form($form, $form_state)
+{
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Bcc) Notification emails'),
+ '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('dwsim_flowsheet_emails', '')
+ );
+ $form['cc_emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Cc) Notification emails'),
+ '#description' => t('Specify emails id for Cc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('dwsim_flowsheet_cc_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('dwsim_flowsheet_from_email', '')
+ );
+ $form['extensions']['user_defind_compound_source'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed source file extensions for user defind compound'),
+ '#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('dwsim_flowsheet_user_defind_compound_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('dwsim_flowsheet_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('dwsim_flowsheet_result_extensions', '')
+ );
+ $form['extensions']['abstract_upload'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed abstract file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('dwsim_flowsheet_abstract_upload_extensions', '')
+ );
+ $form['extensions']['flowsheet_upload'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed DWSIM flowsheet for the developed process'),
+ '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('dwsim_flowsheet_flowsheet_developed_process_source_extensions', '')
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+function dwsim_flowsheet_settings_form_validate($form, &$form_state)
+{
+ return;
+}
+function dwsim_flowsheet_settings_form_submit($form, &$form_state)
+{
+ variable_set('dwsim_flowsheet_emails', $form_state['values']['emails']);
+ variable_set('dwsim_flowsheet_cc_emails', $form_state['values']['cc_emails']);
+ variable_set('dwsim_flowsheet_from_email', $form_state['values']['from_email']);
+ variable_set('dwsim_flowsheet_user_defind_compound_source_extensions', $form_state['values']['user_defind_compound_source']);
+ variable_set('dwsim_flowsheet_dependency_extensions', $form_state['values']['dependency']);
+ variable_set('dwsim_flowsheet_result_extensions', $form_state['values']['result']);
+ variable_set('dwsim_flowsheet_abstract_upload_extensions', $form_state['values']['abstract_upload']);
+ variable_set('dwsim_flowsheet_flowsheet_developed_process_source_extensions', $form_state['values']['flowsheet_upload']);
+ drupal_set_message(t('Settings updated'), 'status');
+}
diff --git a/upload_code.inc b/upload_code.inc
new file mode 100755
index 0000000..2b53a89
--- /dev/null
+++ b/upload_code.inc
@@ -0,0 +1,317 @@
+<?php
+// $Id$
+function dwsim_flowsheet_abstract()
+{
+ global $user;
+ $proposal_data = dwsim_flowsheet_get_proposal();
+ if (!$proposal_data)
+ {
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $return_html = '<strong>Title of the Flowsheet Project:</strong><br />' . $proposal_data->project_title . '<br /><br />';
+ $return_html .= '<strong>Proposer Name:</strong><br />' . $proposal_data->name_title . ' ' . $proposal_data->student_name . '<br /><br />';
+ $return_html .= l('Upload abstract', 'flowsheeting-project/abstract-code/upload') . '<br />';
+ /* get experiment list */
+ $experiment_rows = array();
+ //$experiment_q = db_query("SELECT * FROM {dwsim_flowsheet_experiment} WHERE proposal_id = %d ORDER BY number ASC", $proposal_data->id);
+ $query = db_select('dwsim_flowsheet_experiment');
+ $query->fields('dwsim_flowsheet_experiment');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->orderBy('number', 'ASC');
+ $experiment_q = $query->execute();
+ $experiment_header = array(
+ 'No. Uploaded File',
+ '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 dwsim_flowsheet_upload_abstract_code_form($form, &$form_state)
+{
+ global $user;
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ /* get current proposal */
+ //$proposal_id = (int) arg(3);
+ $uid = $user->uid;
+ //$proposal_q = db_query("SELECT * FROM {dwsim_flowsheet_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('uid', $uid);
+ $query->condition('approval_status', '1');
+ $proposal_q = $query->execute();
+ if ($proposal_q)
+ {
+ if ($proposal_data = $proposal_q->fetchObject())
+ {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/abstract-code');
+ return;
+ }
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('flowsheeting-project/abstract-code');
+ return;
+ }
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Flowsheet Project')
+ );
+ $form['version'] = array(
+ '#type' => 'item',
+ '#title' => t('DWSIM version'),
+ '#markup' => $proposal_data->version
+ );
+ $form['unit_operations_used_in_dwsim'] = array(
+ '#type' => 'select',
+ '#title' => t('Unit Operations used in DWSIM'),
+ '#options' => _df_list_of_unit_operations(),
+ '#required' => TRUE,
+ '#multiple' => TRUE,
+ '#description' => t('[You can select multiple options by holding ctrl + left key of mouse]')
+ );
+ $form['thermodynamic_packages_used'] = array(
+ '#type' => 'select',
+ '#title' => t('Thermodynamic Packages Used'),
+ '#options' => _df_list_of_thermodynamic_packages(),
+ '#required' => TRUE,
+ '#multiple' => TRUE,
+ '#description' => t('[You can select multiple options by holding ctrl + left key of mouse]')
+ );
+ $form['logical_blocks_used'] = array(
+ '#type' => 'select',
+ '#title' => t('Logical Blocks used (If any)'),
+ '#options' => _df_list_of_logical_block(),
+ '#required' => TRUE,
+ '#multiple' => TRUE,
+ '#description' => t('[You can select multiple options by holding ctrl + left key of mouse]')
+ );
+ $form['process_development_compound_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of compound for which process development is carried out'),
+ '#size' => 50,
+ '#description' => t('Mention the compound name with CAS No as shown below:
+Ex: Ethanol (64-17-5)')
+ );
+ $form['list_of_compounds_from_dwsim_database_used_in_process_flowsheet'] = array(
+ '#type' => 'select',
+ '#title' => t('List of compounds from DWSIM Database used in process flowsheet'),
+ '#options' => _df_list_of_dwsim_compound(),
+ '#multiple' => TRUE,
+ '#description' => t('[You can select multiple options by holding ctrl + left key of mouse]')
+ );
+ $form['user_defined_compounds_used_in_process_flowsheetcompound_name'] = array(
+ '#type' => 'textarea',
+ '#title' => t('List of user defined compounds used in process flowsheet'),
+ '#required' => FALSE,
+ '#description' => 'List all user defined compounds with CAS No. as in format - Ex: Ethylene (74-85-1)'
+ );
+ $form['upload_an_abstract'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload an abstract (brief outline) of the project.'),
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('dwsim_flowsheet_abstract_upload_extensions', '') . '</span>'
+ );
+ $form['upload_flowsheet_developed_process'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload the DWSIM flowsheet for the developed process.'),
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('dwsim_flowsheet_flowsheet_developed_process_source_extensions', '') . '</span>'
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'flowsheeting-project/manage-proposal')
+ );
+ return $form;
+}
+function dwsim_flowsheet_upload_abstract_code_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['unit_operations_used_in_dwsim'])
+ {
+ $unit_operations_used_in_dwsim = implode(", ", $_POST['unit_operations_used_in_dwsim']);
+ $form_state['values']['unit_operations_used_in_dwsim'] = $unit_operations_used_in_dwsim;
+ } //$form_state['values']['unit_operations_used_in_dwsim']
+ if ($form_state['values']['thermodynamic_packages_used'])
+ {
+ $thermodynamic_packages_used = implode(", ", $_POST['thermodynamic_packages_used']);
+ $form_state['values']['thermodynamic_packages_used'] = $thermodynamic_packages_used;
+ } //$form_state['values']['thermodynamic_packages_used']
+ if ($form_state['values']['logical_blocks_used'])
+ {
+ $logical_blocks_used = implode(", ", $_POST['logical_blocks_used']);
+ $form_state['values']['logical_blocks_used'] = $logical_blocks_used;
+ } //$form_state['values']['logical_blocks_used']
+ if ($form_state['values']['list_of_compounds_from_dwsim_database_used_in_process_flowsheet'])
+ {
+ $list_of_compounds_from_dwsim_database_used_in_process_flowsheet = implode(", ", $_POST['list_of_compounds_from_dwsim_database_used_in_process_flowsheet']);
+ $form_state['values']['list_of_compounds_from_dwsim_database_used_in_process_flowsheet'] = $list_of_compounds_from_dwsim_database_used_in_process_flowsheet;
+ } //$form_state['values']['list_of_compounds_from_dwsim_database_used_in_process_flowsheet']
+ if (isset($_FILES['files']))
+ {
+ /* check if file is uploaded */
+ if (!($_FILES['files']['name']['upload_flowsheet_developed_process']))
+ form_set_error('upload_flowsheet_developed_process', t('Please upload the file.'));
+ if (!($_FILES['files']['name']['upload_an_abstract']))
+ form_set_error('upload_an_abstract', t('Please upload the 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, 'upload_flowsheet_developed_process'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'upload_an_abstract'))
+ $file_type = 'A';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('dwsim_flowsheet_flowsheet_developed_process_source_extensions', '');
+ break;
+ case 'A':
+ $allowed_extensions_str = variable_get('dwsim_flowsheet_abstract_upload_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $tmp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($tmp_ext);
+ 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 (!dwsim_flowsheet_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'])
+ // drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
+ // drupal_static_reset('drupal_add_js') ;
+}
+function dwsim_flowsheet_upload_abstract_code_form_submit($form, &$form_state)
+{
+ global $user;
+ $v = $form_state['values'];
+ $root_path = dwsim_flowsheet_path();
+ $proposal_data = dwsim_flowsheet_get_proposal();
+ $proposal_id = $proposal_data->id;
+ if (!$proposal_data)
+ {
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $proposal_id = $proposal_data->id;
+ $proposal_drectory = $proposal_data->directory_name;
+ /* create proposal folder if not present */
+ $dest_path = $proposal_drectory . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* creating solution database entry */
+ $query = "INSERT INTO {dwsim_flowsheet_submitted_abstracts} (proposal_id, approver_uid, abstract_approval_status, unit_operations_used_in_dwsim, thermodynamic_packages_used, logical_blocks_used, process_development_compound_name, list_of_compounds_from_dwsim_database_used_in_process_flowsheet, user_defined_compounds_used_in_process_flowsheet, abstract_upload_date, abstract_approval_date) VALUES (:proposal_id, :approver_uid, :abstract_approval_status, :unit_operations_used_in_dwsim,
+ :thermodynamic_packages_used, :logical_blocks_used, :process_development_compound_name,
+ :list_of_compounds_from_dwsim_database_used_in_process_flowsheet,
+ :user_defined_compounds_used_in_process_flowsheet, :abstract_upload_date, :abstract_approval_date)";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":approver_uid" => 0,
+ ":abstract_approval_status" => 0,
+ ":unit_operations_used_in_dwsim" => $v['unit_operations_used_in_dwsim'],
+ ":thermodynamic_packages_used" => $v['thermodynamic_packages_used'],
+ ":logical_blocks_used" => $v['logical_blocks_used'],
+ ":process_development_compound_name" => $v['process_development_compound_name'],
+ ":list_of_compounds_from_dwsim_database_used_in_process_flowsheet" => $v['list_of_compounds_from_dwsim_database_used_in_process_flowsheet'],
+ ":user_defined_compounds_used_in_process_flowsheet" => $v['user_defined_compounds_used_in_process_flowsheetcompound_name'],
+ ":abstract_upload_date" => time(),
+ ":abstract_approval_date" => 0
+ );
+ $submitted_abstract_id = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ /* 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;
+ } //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]))
+ {
+ /* for uploaded files making an entry in the database */
+ $query = "INSERT INTO {dwsim_flowsheet_submitted_abstracts_file} (submitted_abstract_id, proposal_id,approvar_uid, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:submitted_abstract_id, :proposal_id,:approvar_uid, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":submitted_abstract_id" => $submitted_abstract_id,
+ ":proposal_id" => $proposal_id,
+ ":approvar_uid" => 0,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $file_path . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => mime_content_type($root_path . $dest_path . $_FILES['files']['name'][$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');
+ } //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
+ drupal_set_message('Solution uploaded successfully.', 'status');
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('dwsim_flowsheet_from_email', '');
+ $bcc = variable_get('dwsim_flowsheet_emails', '');
+ $cc = variable_get('dwsim_flowsheet_cc_emails', '');
+ $params['solution_uploaded']['solution_id'] = $solution_id;
+ $params['solution_uploaded']['user_id'] = $user->uid;
+ $params['solution_uploaded']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('dwsim_flowsheet', 'solution_uploaded', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_goto('flowsheeting-project/abstract-code');
+}
diff --git a/upload_code_delete.inc b/upload_code_delete.inc
new file mode 100755
index 0000000..0c63e5f
--- /dev/null
+++ b/upload_code_delete.inc
@@ -0,0 +1,95 @@
+<?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;
+
+ $from = variable_get('lab_migration_from_email', '');
+ $bcc= variable_get('lab_migration_emails', '');
+ $cc=variable_get('lab_migration_cc_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['solution_deleted_user']['user_id'] = $user->uid;
+ $param['solution_deleted_user']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
+ 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
+
+ if (!drupal_mail('lab_migration', 'solution_deleted_user', $email_to, language_default(), $param , $from , TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } else {
+ drupal_set_message('Error deleting example.', 'status');
+ }
+
+ drupal_goto('lab-migration/code');
+ return;
+}