From 11cb8a66c33ca9375590feec95bf621e8cffe49b Mon Sep 17 00:00:00 2001 From: Saketh1499 Date: Wed, 13 Oct 2021 15:36:35 +0530 Subject: Adding a option to download proposals in csv format --- download.inc | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ dwsim_flowsheet.module | 20 +++++++++++++++++++ proposals_review_tab.inc | 51 ++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 116 insertions(+), 6 deletions(-) diff --git a/download.inc b/download.inc index d8a6839..62470cb 100755 --- a/download.inc +++ b/download.inc @@ -303,3 +303,54 @@ function dwsim_flowsheet_download_lab() drupal_goto('lab-migration/lab-migration-run'); } } + +function dwsim_flowsheet_download_proposals() +{ + $output = ""; + //$output = "
Click here to download the Proposals of the participants";
+
+ $root_path = dwsim_flowsheet_path();
+ $result = db_query("SELECT e.contributor_name as Contirbutor_Name, u.mail as Email_ID, e.project_title as Title, e.contact_no as Contact, from_unixtime(actual_completion_date,'%Y') as Year FROM dwsim_flowsheet_proposal as e JOIN users as u ON e.uid = u.uid WHERE e.approval_status=3 ORDER BY actual_completion_date DESC");
+
+ //$all_proposals_q = $result->execute();
+ $participants_proposal_id_file = $root_path . "participants-proposals.csv";
+ $fp = fopen($participants_proposal_id_file, "w");
+ /* making the first row */
+ $items = array(
+ 'Contirbutor_Name',
+ 'Email_ID',
+ 'Title',
+ 'Contact',
+ 'Year'
+ );
+ fputcsv($fp, $items);
+ while($row = $result->fetchObject()) {
+ $items = array(
+ '$row->contributor_name',
+ '$row->mail',
+ '$row->project_title',
+ '$row->contact_no',
+ '$row->actual_completion_date'
+ );
+ fputcsv($fp, $items);
+ }
+ fclose($fp);
+ if($participants_proposal_id_file){
+ ob_clean();
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: public");
+ header("Content-Description: File Transfer");
+ header('Content-Type: application/csv');
+ header('Content-disposition: attachment; filename=participants-proposals.csv');
+ header('Content-Length:' . filesize($participants_proposal_id_file));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ readfile($participants_proposal_id_file);
+ /*ob_end_flush();
+ ob_clean();
+ flush();*/
+ }
+}
\ No newline at end of file
diff --git a/dwsim_flowsheet.module b/dwsim_flowsheet.module
index 302f003..ea1b475 100755
--- a/dwsim_flowsheet.module
+++ b/dwsim_flowsheet.module
@@ -93,6 +93,16 @@ function dwsim_flowsheet_menu()
'weight' => 5,
'file' => 'proposals_review_tab.inc'
);
+ /*$items['flowsheeting-project/download'] = array(
+ 'title' => 'Flowsheet Download Proposals',
+ 'description' => 'Flowsheet Download Proposals',
+ 'page callback' => 'dwsim_flowsheet_download_proposals_tab',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dwsim flowsheet manage proposal'
+ ),
+ 'file' => 'proposals_review_tab.inc'
+ );*/
$items['flowsheeting-project/manage-proposal/approve'] = array(
'title' => 'Approve Proposal',
'description' => 'Approve Proposal',
@@ -355,6 +365,16 @@ function dwsim_flowsheet_menu()
'type' => MENU_CALLBACK,
'file' => 'full_download.inc'
);
+ $items['flowsheeting-project/download-proposals'] = array(
+ 'title' => 'Download Proposals',
+ 'description' => 'Download Proposals',
+ 'page callback' => 'dwsim_flowsheet_download_proposals',
+ 'access arguments' => array(
+ 'dwsim flowsheet download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
/* COMPLETED dwsim flowsheetS */
$items['flowsheeting-project/completed-flowsheet'] = array(
'title' => 'Completed Flowsheets',
diff --git a/proposals_review_tab.inc b/proposals_review_tab.inc
index fe74640..4294607 100644
--- a/proposals_review_tab.inc
+++ b/proposals_review_tab.inc
@@ -98,18 +98,20 @@ function dwsim_flowsheet_uploaded_tab()
function dwsim_flowsheet_completed_tab_form($form, $form_state)
{
-
+ $options_first = _flowsheet_details_year_wise();
+ $selected = isset($form_state['values']['howmany_select']) ? $form_state['values']['howmany_select'] : key($options_first);
$form['howmany_select'] = array(
'#title' => t('Sorting projects according to year:'),
'#type' => 'select',
- '#options' => array(
+ '#options' => _flowsheet_details_year_wise(),
+ /*'#options' => array(
'Please select...' => 'Please select...',
'2017' => '2017',
'2018' => '2018',
'2019' => '2019',
'2020' => '2020',
- '2021' => '2021'),
- //'#default_value' => 'Please select...',
+ '2021' => '2021'),*/
+ '#default_value' => $selected,
'#ajax' => array(
'callback' => 'ajax_example_autocheckboxes_callback',
),
@@ -142,23 +144,46 @@ function ajax_example_autocheckboxes_callback($form, $form_state)
);
}
+function _flowsheet_details_year_wise()
+ {
+ $flowsheet_years = array(
+ '0' => 'Please select...'
+ );
+ $result = db_query("SELECT from_unixtime(actual_completion_date, '%Y ') from dwsim_flowsheet_proposal WHERE approval_status = 3");
+
+ /*$query = db_select('dwsim_flowsheet_proposal');
+ $query->fields('dwsim_flowsheet_proposal');
+ $query->condition('from_unixtime(actual_completion_date)');
+ $query->condition('approval_status', 3);*/
+ //$query->orderBy('id', 'DESC');
+ //$year_wise_list = $query->execute();
+ while ($year_wise_list_data = $result->fetchObject())
+ {
+ $flowsheet_years[$year_wise_list_data->id] = $year_wise_list_data->actual_completion_date;
+ }
+ return $flowsheet_years;
+ }
+
function _flowsheet_details($flowsheet_proposal_id)
{
$output = "";
+ $output = "Click here to download the Proposals of the participants
";
$result = db_query("SELECT * from {dwsim_flowsheet_proposal} WHERE approval_status = 3 and from_unixtime(actual_completion_date, '%Y') = :year",
array(
':year' => $flowsheet_proposal_id)
);
if ($result->rowCount() == 0)
- {
+ {
+ // $output = "Click here to download the Proposals of the participants";
$output .= "Work has been completed for the following flow sheets.";
}
else
{
- $output .= "Work has been completed for the following flow sheets: " . $result->rowCount() . "
Click here to download the Proposals of the participants";
-
$root_path = dwsim_flowsheet_path();
- $result = db_query("SELECT e.contributor_name as Contirbutor_Name, u.mail as Email_ID, e.project_title as Title, e.contact_no as Contact, from_unixtime(actual_completion_date,'%Y') as Year FROM dwsim_flowsheet_proposal as e JOIN users as u ON e.uid = u.uid WHERE e.approval_status=3 ORDER BY actual_completion_date DESC");
+ $result = db_query("SELECT e.contributor_name as Contirbutor_Name, u.mail as Email_ID, e.project_title as Title, e.contact_no as Contact, from_unixtime(actual_completion_date,'%Y') as Year FROM dwsim_flowsheet_proposal as e JOIN users as u ON e.uid = u.uid WHERE e.approval_status=3 ORDER BY actual_completion_date DESC");
//$all_proposals_q = $result->execute();
$participants_proposal_id_file = $root_path . "participants-proposals.csv";
@@ -326,11 +323,11 @@ function dwsim_flowsheet_download_proposals()
fputcsv($fp, $items);
while($row = $result->fetchObject()) {
$items = array(
- '$row->contributor_name',
- '$row->mail',
- '$row->project_title',
- '$row->contact_no',
- '$row->actual_completion_date'
+ $row->contributor_name,
+ $row->mail,
+ $row->project_title,
+ $row->contact_no,
+ $row->actual_completion_date
);
fputcsv($fp, $items);
}
--
cgit
From 599fadcc804c30709569b02bb42aca7b55a83e60 Mon Sep 17 00:00:00 2001
From: Saketh1499
Date: Mon, 18 Oct 2021 15:46:34 +0530
Subject: Adding a option to download proposals in csv format
---
download.inc | 12 ++++++------
dwsim_flowsheet.module | 6 +++++-
proposals_review_tab.inc | 30 ++++++++----------------------
3 files changed, 19 insertions(+), 29 deletions(-)
diff --git a/download.inc b/download.inc
index a329bf3..c034eac 100755
--- a/download.inc
+++ b/download.inc
@@ -308,7 +308,7 @@ function dwsim_flowsheet_download_proposals()
{
$root_path = dwsim_flowsheet_path();
$result = db_query("SELECT e.contributor_name as Contirbutor_Name, u.mail as Email_ID, e.project_title as Title, e.contact_no as Contact, from_unixtime(actual_completion_date,'%Y') as Year FROM dwsim_flowsheet_proposal as e JOIN users as u ON e.uid = u.uid WHERE e.approval_status=3 ORDER BY actual_completion_date DESC");
-
+//var_dump($result->rowCount());die();
//$all_proposals_q = $result->execute();
$participants_proposal_id_file = $root_path . "participants-proposals.csv";
$fp = fopen($participants_proposal_id_file, "w");
@@ -323,11 +323,11 @@ function dwsim_flowsheet_download_proposals()
fputcsv($fp, $items);
while($row = $result->fetchObject()) {
$items = array(
- $row->contributor_name,
- $row->mail,
- $row->project_title,
- $row->contact_no,
- $row->actual_completion_date
+ $row->Contirbutor_Name,
+ $row->Email_ID,
+ $row->Title,
+ $row->Contact,
+ $row->Year
);
fputcsv($fp, $items);
}
diff --git a/dwsim_flowsheet.module b/dwsim_flowsheet.module
index ea1b475..7e2a5a9 100755
--- a/dwsim_flowsheet.module
+++ b/dwsim_flowsheet.module
@@ -370,7 +370,7 @@ function dwsim_flowsheet_menu()
'description' => 'Download Proposals',
'page callback' => 'dwsim_flowsheet_download_proposals',
'access arguments' => array(
- 'dwsim flowsheet download code'
+ 'dwsim flowsheet download proposals'
),
'type' => MENU_CALLBACK,
'file' => 'download.inc'
@@ -562,6 +562,10 @@ function dwsim_flowsheet_permission()
'title' => t('dwsim flowsheet download code'),
'restrict access' => TRUE
),
+ 'dwsim flowsheet download proposals' => array(
+ 'title' => t('dwsim flowsheet download proposals'),
+ 'restrict access' => TRUE
+ ),
'administer dwsim flowsheet' => array(
'title' => t('administer dwsim flowsheet'),
'restrict access' => TRUE
diff --git a/proposals_review_tab.inc b/proposals_review_tab.inc
index 4294607..bccb440 100644
--- a/proposals_review_tab.inc
+++ b/proposals_review_tab.inc
@@ -100,8 +100,9 @@ function dwsim_flowsheet_completed_tab_form($form, $form_state)
{
$options_first = _flowsheet_details_year_wise();
$selected = isset($form_state['values']['howmany_select']) ? $form_state['values']['howmany_select'] : key($options_first);
+ $form = array();
$form['howmany_select'] = array(
- '#title' => t('Sorting projects according to year:'),
+ '#title' => t('Sorting projects according to year:'),
'#type' => 'select',
'#options' => _flowsheet_details_year_wise(),
/*'#options' => array(
@@ -144,12 +145,13 @@ function ajax_example_autocheckboxes_callback($form, $form_state)
);
}
+
function _flowsheet_details_year_wise()
{
$flowsheet_years = array(
'0' => 'Please select...'
);
- $result = db_query("SELECT from_unixtime(actual_completion_date, '%Y ') from dwsim_flowsheet_proposal WHERE approval_status = 3");
+ $result = db_query("SELECT from_unixtime(actual_completion_date, '%Y ') as Year from dwsim_flowsheet_proposal WHERE approval_status = 3");
/*$query = db_select('dwsim_flowsheet_proposal');
$query->fields('dwsim_flowsheet_proposal');
@@ -159,7 +161,7 @@ function _flowsheet_details_year_wise()
//$year_wise_list = $query->execute();
while ($year_wise_list_data = $result->fetchObject())
{
- $flowsheet_years[$year_wise_list_data->id] = $year_wise_list_data->actual_completion_date;
+ $flowsheet_years[$year_wise_list_data->Year] = $year_wise_list_data->Year;
}
return $flowsheet_years;
}
@@ -168,22 +170,20 @@ function _flowsheet_details_year_wise()
function _flowsheet_details($flowsheet_proposal_id)
{
$output = "";
- $output = "Click here to download the Proposals of the participants
";
+ //$output = "Click here to download the Proposals of the participants
";
$result = db_query("SELECT * from {dwsim_flowsheet_proposal} WHERE approval_status = 3 and from_unixtime(actual_completion_date, '%Y') = :year",
array(
':year' => $flowsheet_proposal_id)
);
if ($result->rowCount() == 0)
- {
- // $output = "Click here to download the Proposals of the participants";
+ {
$output .= "Work has been completed for the following flow sheets.";
}
else
{
-
- $output .= "Work has been completed for the following flow sheets: " . $result->rowCount() ;
+ $output .= "Work has been completed for the following flow sheets: " . $result->rowCount() . "