Skip to content

Instantly share code, notes, and snippets.

@yellowstonebum
Last active March 12, 2020 15:00
Show Gist options
  • Save yellowstonebum/c7128a2380219dbe368b573cc9827f8b to your computer and use it in GitHub Desktop.
Save yellowstonebum/c7128a2380219dbe368b573cc9827f8b to your computer and use it in GitHub Desktop.
Function file for SO
<?php
function gaws_edit_entry( $entry, $form ) {
$form_id = $form['id'];
if( $form_id == 2 ){
$data = array();
$csv0 = array(
array(
'Client ID',
'Requestor Name (First Last)',
'Requestor Email Address',
'Administrator Name (First Last)',
'Administrator Email Address',
'Survey Project',
'Client Organization',
'Client Cohort',
'Participant Name (First)',
'Participant Name (Last)',
'Participant Email Address',
'Division',
'Department',
'Level',
'Team',
'Location',
'Rater Name (First)',
'Rater Name (Last)',
'Rater Email Address',
'Rater Group',
'Requested Launch Date',
'Close Date',
'Reminder Date',
'Final Reminder Date',
'Report target date',
'Summary Report Target Date',
'Survey Logo',
'Report Logo',
'Normative Data',
'Upload Normative Data',
'Data Redaction',
'Correspondence',
'Upload Correspondence',
'Report Options',
'Additional Instructions'
)
);
$csv1 = array(
array(
'First Name',
'Last Name',
'Email',
'Role'
)
);
$csv2 = array(
array(
'First Name',
'Last Name',
'Email',
'Role'
)
);
$csv3 = array(
array(
'First Name',
'Last Name',
'Email',
'Role'
)
);
$find[] = ',';
$input_44 = str_replace( $find, '&#44;', rgar( $entry, 44 ) ); //Client ID
$input_4 = str_replace( $find, '&#44;', rgar( $entry, 4 ) ); // Name (first last)/Requestor Name (First Last)
$input_5 = str_replace( $find, '&#44;', rgar( $entry, 5 ) ); // Email Address/Requestor Email Address
$input_7 = str_replace( $find, '&#44;', rgar( $entry, 7 ) ); // Name (first last)/Administrator Name (First Last)
$input_8 = str_replace( $find, '&#44;', rgar( $entry, 8 ) ); // Email Address/Administrator Email Address
$input_12 = str_replace( $find, '&#44;', rgar( $entry, 12 ) ); // Survey Project
$input_13 = str_replace( $find, '&#44;', rgar( $entry, 13 ) ); // Client Organization
$input_14 = str_replace( $find, '&#44;', rgar( $entry, 14 ) ); // Client Cohort
$input_21 = str_replace( $find, '&#44;', rgar( $entry, 21 ) ); // First Name/Participant Name (First)
$input_22 = str_replace( $find, '&#44;', rgar( $entry, 22 ) ); // Last Name/Participant Name (Last)
$input_23 = str_replace( $find, '&#44;', rgar( $entry, 23 ) ); // Email Address/Participant Email Address
$input_25 = str_replace( $find, '&#44;', rgar( $entry, 25 ) ); // Division
$input_26 = str_replace( $find, '&#44;', rgar( $entry, 26 ) ); // Department
$input_27 = str_replace( $find, '&#44;', rgar( $entry, 27 ) ); // Level
$input_28 = str_replace( $find, '&#44;', rgar( $entry, 28 ) ); // Team
$input_71 = str_replace( $find, '&#44;', rgar( $entry, 71 ) ); // Location
$input_30 = str_replace( $find, '&#44;', rgar( $entry, 30 ) );
$input_15 = str_replace( $find, '&#44;', rgar( $entry, 15 ) ); // Requested Launch Date
$input_16 = str_replace( $find, '&#44;', rgar( $entry, 16 ) ); // Close Date
$input_61 = str_replace( $find, '&#44;', rgar( $entry, 61 ) ); // Reminder Date
$input_63 = str_replace( $find, '&#44;', rgar( $entry, 63 ) ); // Final Reminder Date
$input_69 = str_replace( $find, '&#44;', rgar( $entry, 69 ) ); // Report target date
$input_62 = str_replace( $find, '&#44;', rgar( $entry, 62 ) ); // Summary Report Target Date
$input_33 = str_replace( $find, '&#44;', rgar( $entry, 33 ) ); // Survey Logo
$input_34 = str_replace( $find, '&#44;', rgar( $entry, 34 ) ); // Report Logo
$input_35 = str_replace( $find, '&#44;', rgar( $entry, 35 ) ); // Normative Data
$input_36 = str_replace( $find, '&#44;', rgar( $entry, 36 ) ); // Upload Normative Data
$input_52 = str_replace( $find, '&#44;', rgar( $entry, 52 ) ); // Data Redaction
$input_37 = str_replace( $find, '&#44;', rgar( $entry, 37 ) ); // Correspondence
$input_38 = str_replace( $find, '&#44;', rgar( $entry, 38 ) ); // Upload Correspondence
$input_40 = str_replace( $find, '&#44;', $entry['40.1'] ); // Report Options
$input_41 = str_replace( $find, '&#44;', rgar( $entry, 41 ) ); // Additional Instructions
$input_30_arr = unserialize( $input_30 );
array_push($csv1, array( $input_21, $input_22, $input_23, 'Self' ) );
if( is_array( $input_30_arr ) ){
foreach( $input_30_arr as $input_30_item){
$rater_group = $input_30_item['Rater Group'];
array_push($csv0, array($input_44, $input_4, $input_5, $input_7, $input_8, $input_12, $input_13, $input_14, $input_21, $input_22, $input_23, $input_25, $input_26, $input_27, $input_28, $input_71, $input_30_item['First Name'], $input_30_item['Last Name'], $input_30_item['Email Address'], $rater_group, $input_15, $input_16, $input_61, $input_63, $input_69, $input_62, $input_33, $input_34, $input_35, $input_36, $input_52, $input_37, $input_38, $input_40, $input_41 ) );
if( (strpos( $rater_group, 'Manager' ) !== false) || (strpos( $rater_group, 'Boss' ) !== false) ){
// print_r($rater_group);
array_push($csv2, array( $input_30_item['First Name'], $input_30_item['Last Name'], $input_30_item['Email Address'], $input_30_item['Rater Group'] ) );
} else {
array_push($csv3, array( $input_30_item['First Name'], $input_30_item['Last Name'], $input_30_item['Email Address'], $input_30_item['Rater Group'] ) );
}
}
}
$str = wp_generate_password( 6, false, false);
$file_0 = $str.'_entry.csv';
$file_1 = $str.'_participant_self.csv';
$file_2 = $str.'_participant_managers.csv';
$file_3 = $str.'_participant_others.csv';
$entry_id = $entry['id'];
gaws_outputCsv($file_0, $csv0, 74, $entry_id );
gaws_outputCsv($file_1, $csv1, 75, $entry_id );
gaws_outputCsv($file_2, $csv2, 76, $entry_id );
gaws_outputCsv($file_3, $csv3, 77, $entry_id );
return;
}
return false;
}
function gaws_outputCsv($file, $csv, $fid, $entry_id )
{
ob_clean();
ob_start();
$dir = 'wp-content/uploads/csv';
if( ! is_dir ( $dir ) ){
mkdir($dir);
}
ini_set('include_path', $dir);
$fp = fopen($dir . '/' . $file, 'x+', 1);
$headers = dirname(__FILE__);
GFAPI::update_entry_field( $entry_id, 53, serialize( $headers ) );
foreach($csv as $values){
fputcsv($fp, $values);
}
fclose($fp);
$file_url = get_site_url() . '/' . $dir . '/' . $file;
GFAPI::update_entry_field( $entry_id, $fid, $file_url );
ob_end_flush();
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment