$survey_args['response_' . $relation_step] = json_encode($_POST); // save $survey_pod->save($survey_args); $posted_answers = $_POST; // release the session key $myJSONRPCClient->release_session_key($sessionKey); $durations = ['TM' => 5, 'OM' => 10, 'OP' => 20]; $details = ['role' => $current_user->roles[0], 'company_or_agency' => get_user_meta($current_user->ID, 'company_or_agency', true), 'company' => $relation_pod->display('company'), 'agency' => $relation_pod->display('agency'), 'brand' => $relation_pod->display('brand'), 'country' => $relation_pod->display('country'), 'duration' => isset($durations[$current_user->roles[0]]) ? $durations[$current_user->roles[0]] : 20, 'expiration' => "11th September"]; $details['source_company'] = $details['company_or_agency'] == 'company' ? $details['company'] : $details['agency']; $details['target_company'] = $details['company_or_agency'] == 'company' ? $details['agency'] : $details['company']; // send notification Email $email = new Emailer(); $email->headers[] = 'Cc: Jasper Kums <*****@*****.**>' . "\r\n"; $status_response = ['status' => 'OK', 'message' => json_encode($success_status)]; try { $email->compose(['template' => 'surveycompleted', 'pre_header' => '', 'title' => 'Thank you for your input', 'name' => $current_user->display_name, 'date' => date_i18n('j M Y'), 'details' => $details]); $result = $email->send(['subject' => 'Thank you for your input ' . $current_user->display_name . ' ' . time(), 'to' => $current_user->user_email]); $survey_title = 'Survey submission - ' . $survey_post['ID'] . ' - ' . html_entity_decode(get_the_title((int) $survey_post['ID'])); mail('*****@*****.**', $survey_title, json_encode($_POST)); } catch (Exception $e) { // Something went wrong sending the e-mail, return error and error message header('Content-Type: application/json'); print_r(json_encode(['error' => 'error', 'message' => $e->getMessage()])); } } // response output header("Content-Type: application/json"); echo json_encode($status_response); exit; } }
$evaluation_id = get_post_meta($invitation_id, 'evaluation', true)['ID']; $evaluation_pod = pods('evaluation', $evaluation_id); $relation_pod = pods('relation', $evaluation_pod->field('relation')['ID']); error_log('>>> Expiration ' . json_encode($evaluation_pod->field('expiration'))); $details = ['role' => $user_role, 'company_or_agency' => get_user_meta($user_id, 'company_or_agency', true), 'company' => $relation_pod->display('company'), 'agency' => $relation_pod->display('agency'), 'brand' => $relation_pod->display('brand'), 'country' => $relation_pod->display('country'), 'duration' => $durations[$user_role], 'expiration' => date_i18n('j F', strtotime('+ 2weeks'))]; $details['source_company'] = $details['company_or_agency'] == 'company' ? $details['company'] : $details['agency']; $details['target_company'] = $details['company_or_agency'] == 'company' ? $details['agency'] : $details['company']; if (!($details['company_or_agency'] === 'company' || $details['company_or_agency'] === 'agency')) { throw new Exception('User is neither of type agency or company'); } $invitation_postfix = $details['company_or_agency'] === 'company' ? 'client' : 'agency'; //error_log('got this far'); $email = new Emailer(); $email->headers[] = 'Cc: Jasper Kums <*****@*****.**>' . "\r\n"; try { $email->compose(['template' => $is_reminder ? 'reminder' : ($is_reporting ? 'reporting' : 'invitation' . $invitation_postfix), 'pre_header' => '', 'title' => $is_reminder ? 'Reminder ProCync Survey' : 'Welcome to ProCync', 'name' => $user->display_name, 'date' => date_i18n('j M Y'), 'button_text' => $is_reporting ? 'VIEW REPORTING' : 'START SURVEY', 'button_url' => get_bloginfo('url') . ($is_reporting ? '/reporting/' : '/survey/') . $token, 'details' => $details]); $timestamp = time(); $result = $email->send(['subject' => ($is_reminder ? 'Reminder ProCync Survey, ' : 'Welcome to ProCync, ') . $user->display_name . ' - ' . $timestamp, 'to' => $user->user_email]); if ($result) { // Update post meta, so we know an invitation has already been sent update_post_meta($invitation_id, 'invitation_send', 1); update_post_meta($invitation_id, 'invitation_send_date', $timestamp); // Return success and the timestamp so we can update the row with javascript header('Content-Type: application/json'); print_r(json_encode(['success' => 'success', 'date' => date_i18n('d-M-Y G:i', $timestamp)])); } else { // Something went wrong sending the e-mail, but we don't know what header('Content-Type: application/json'); print_r(json_encode(['error' => 'error', 'message' => 'failed to send e-mail'])); } } catch (Exception $e) {