php js css php js css

Changes

Changes to Page: student-portal-email-test

143086
Today 2:07am
Nocos, John Robertson
Modified page
Can't Undo: The page /student-portal-email-test/ does not currently exist, it may have been moved or deleted. In order to undo this change, you first need to restore the page
143114
Today 2:07am
Nocos, John Robertson
Deleted page
Content Additional:
Id:
/student-portal-email-test/
/student-portal-email-test/
Title:
Student Portal Email Test
Student Portal Email Test
Content:
<templates:section>
<h1>Student Portal Email Test</h1>
<p>Enter your content here</p>
</templates:section>
<templates:section>
<h1>Student Portal Email Test</h1>
<p>Enter your content here</p>
</templates:section>
Css:

															

														
Js:

															

														
Php Source:
<?php

$arrPost = \Components\AF\Courses\Posts::get(40);
$arrContacts = \Components\AF\Courses::getClassList($arrPost['course_id']);

sendNewPostEmail($arrPost, $arrContacts);

function sendNewPostEmail($arrPost, $arrContacts = [])
{
if (!$arrContacts)
return;

$iCourseId = $arrPost['course_id'];
if (!$arrCourse = \Components\AF\Courses::get($iCourseId))
return;

// Set course title for either collective or private course
if ($arrCourse['course_type'] === 'collective')
{
$arrProduct = \Components\Commerce\Products::getIncludingDeleted($arrCourse['product_id']);
$strCourseTitle = $arrProduct['product_title'] ?? null;
} else
$strCourseTitle = $arrCourse['course_code'];

$strSubject = 'There\'s a new post for your ' . $strCourseTitle . ' class';
$strTemplatePageId = '/admin/af/courses/posts/email-templates/post-new/';

$iPostId = $arrPost['post_id'];

// Attachments
$arrAttachmentsData = [];
if ($arrAttachments = \Components\AF\Courses\Posts::attachmentsGet($iPostId))
{
$arrAttachmentsData['shared_folder_name'] = 'courses_posts_' . $iPostId; // Correspondence shared attachments folder

foreach ($arrAttachments as $strAttachment)
$arrAttachmentsData['attachments'][] = \Components\AF\Courses\Posts::getPrivateMediaDir() . $iPostId . '/' . $strAttachment;
}


// Build vars
$arrVariables = [
'course' => $arrCourse,
'post' => $arrPost,
'post_contact' => \Components\Customers\Contacts::get($arrPost['contact_id']),
'post_contact_title' => \Components\AF\Courses\Posts::renderTitleForContact($arrPost['contact_id'], $arrCourse['course_id']),
'course_title' => $strCourseTitle,
// 'media_attachments' => $arrMediaAttachments
];


// Send email notification
foreach ($arrContacts as $arrContact)
{
sendMail($arrContact, $strSubject, $strTemplatePageId, $arrVariables, $arrAttachmentsData);
}
}

function sendMail($arrContact, $strSubject, $strTemplatePageId, $arrVariables, $arrAttachmentsData = [])
{
$pMessage = new \Framework\Mail\Message();
$pMessage->setSubject($strSubject);

$strFromEmail = \Components\AF\Courses::configGetValue('student_portal_from_email') ?: \Components\Settings\ConfigurationItems::getValue('\Components\Settings\MyAccount', 'account_contact_email');
$strFromName = \Components\AF\Courses::configGetValue('student_portal_from_name') ?: \Components\Settings\ConfigurationItems::getValue('\Components\Settings\MyAccount', 'account_title');

// Set addresses
$pMessage->setFrom($strFromEmail);
$pMessage->setReplyTo($strFromEmail);

$pMessage->setFromName($strFromName);
$pMessage->setReplyToName($strFromName);

$pMessage->setTo($arrContact['contact_email']);

\Components\Customers\Contacts::impersonateBegin($arrContact['contact_id']);

foreach($arrVariables as $strKey => &$strValue)
\Framework\DOM\CurrentContext::setVariable($strKey, $strValue);

$arrPage = \Components\Website\Pages::get($strTemplatePageId);
$arrPage['design_id'] = \Components\AF\Courses::configGetValue('student_portal_email_design_id');

$pMessage->setContentHTMLBodyFromPage($arrPage);
$strContent = $pMessage->generateBodyHTML();

// Add attachments to email
if (isset($arrAttachmentsData['attachments']) && $arrAttachmentsData['attachments'])
{
foreach ($arrAttachmentsData['attachments'] as $strAttachment)
$pMessage->addAttachmentFromFile($strAttachment);
}

$pMessage->send();
\Components\Customers\Contacts::impersonateEnd();

// Record Correspondence
$arrRecord = [];
$arrRecord['contact_correspondence_is_outbound'] = 1;
$arrRecord['contact_correspondence_type'] = 'email';
$arrRecord['contact_correspondence_subject'] = $pMessage->getSubject();
$arrRecord['contact_correspondence_content'] = $strContent;
$arrRecord['contact_correspondence_source'] = 'form';
$arrRecord['contact_id'] = $arrContact['contact_id'];
$arrRecord['contact_correspondence_shared_attachments_folder'] = null;

$bHasAttachments = false;

if ($arrAttachmentsData && isset($arrAttachmentsData['attachments']) && count($arrAttachmentsData['attachments']))
$bHasAttachments = true;

if ($bHasAttachments && isset($arrAttachmentsData['shared_folder_name']))
$arrRecord['contact_correspondence_shared_attachments_folder'] = $arrAttachmentsData['shared_folder_name'];

$iCorrespondenceId = \Components\Customers\Contacts\Correspondence::save($arrRecord);


// Copy entity attachments to a correspondence folder
$strAttachmentsDir = '';
if ($arrRecord['contact_correspondence_shared_attachments_folder'])
{
$strAttachmentsDir = '../Private/media/customers_contacts_correspondence/' . $arrAttachmentsData['shared_folder_name'] . '/';
} else
{
if ($bHasAttachments)
$strAttachmentsDir = '../Private/media/customers_contacts_correspondence/' . $iCorrespondenceId . '/';
}

if ($strAttachmentsDir && !file_exists($strAttachmentsDir))
{
\Framework\System\FileSystem::mkdir($strAttachmentsDir);
foreach ($arrAttachmentsData['attachments'] as $strAttachment)
\Framework\System\FileSystem::copy($strAttachment, $strAttachmentsDir . basename($strAttachment));
}
}

?>
<?php

$arrPost = \Components\AF\Courses\Posts::get(40);
$arrContacts = \Components\AF\Courses::getClassList($arrPost['course_id']);

sendNewPostEmail($arrPost, $arrContacts);

function sendNewPostEmail($arrPost, $arrContacts = [])
{
if (!$arrContacts)
return;

$iCourseId = $arrPost['course_id'];
if (!$arrCourse = \Components\AF\Courses::get($iCourseId))
return;

// Set course title for either collective or private course
if ($arrCourse['course_type'] === 'collective')
{
$arrProduct = \Components\Commerce\Products::getIncludingDeleted($arrCourse['product_id']);
$strCourseTitle = $arrProduct['product_title'] ?? null;
} else
$strCourseTitle = $arrCourse['course_code'];

$strSubject = 'There\'s a new post for your ' . $strCourseTitle . ' class';
$strTemplatePageId = '/admin/af/courses/posts/email-templates/post-new/';

$iPostId = $arrPost['post_id'];

// Attachments
$arrAttachmentsData = [];
if ($arrAttachments = \Components\AF\Courses\Posts::attachmentsGet($iPostId))
{
$arrAttachmentsData['shared_folder_name'] = 'courses_posts_' . $iPostId; // Correspondence shared attachments folder

foreach ($arrAttachments as $strAttachment)
$arrAttachmentsData['attachments'][] = \Components\AF\Courses\Posts::getPrivateMediaDir() . $iPostId . '/' . $strAttachment;
}


// Build vars
$arrVariables = [
'course' => $arrCourse,
'post' => $arrPost,
'post_contact' => \Components\Customers\Contacts::get($arrPost['contact_id']),
'post_contact_title' => \Components\AF\Courses\Posts::renderTitleForContact($arrPost['contact_id'], $arrCourse['course_id']),
'course_title' => $strCourseTitle,
// 'media_attachments' => $arrMediaAttachments
];


// Send email notification
foreach ($arrContacts as $arrContact)
{
sendMail($arrContact, $strSubject, $strTemplatePageId, $arrVariables, $arrAttachmentsData);
}
}

function sendMail($arrContact, $strSubject, $strTemplatePageId, $arrVariables, $arrAttachmentsData = [])
{
$pMessage = new \Framework\Mail\Message();
$pMessage->setSubject($strSubject);

$strFromEmail = \Components\AF\Courses::configGetValue('student_portal_from_email') ?: \Components\Settings\ConfigurationItems::getValue('\Components\Settings\MyAccount', 'account_contact_email');
$strFromName = \Components\AF\Courses::configGetValue('student_portal_from_name') ?: \Components\Settings\ConfigurationItems::getValue('\Components\Settings\MyAccount', 'account_title');

// Set addresses
$pMessage->setFrom($strFromEmail);
$pMessage->setReplyTo($strFromEmail);

$pMessage->setFromName($strFromName);
$pMessage->setReplyToName($strFromName);

$pMessage->setTo($arrContact['contact_email']);

\Components\Customers\Contacts::impersonateBegin($arrContact['contact_id']);

foreach($arrVariables as $strKey => &$strValue)
\Framework\DOM\CurrentContext::setVariable($strKey, $strValue);

$arrPage = \Components\Website\Pages::get($strTemplatePageId);
$arrPage['design_id'] = \Components\AF\Courses::configGetValue('student_portal_email_design_id');

$pMessage->setContentHTMLBodyFromPage($arrPage);
$strContent = $pMessage->generateBodyHTML();

// Add attachments to email
if (isset($arrAttachmentsData['attachments']) && $arrAttachmentsData['attachments'])
{
foreach ($arrAttachmentsData['attachments'] as $strAttachment)
$pMessage->addAttachmentFromFile($strAttachment);
}

$pMessage->send();
\Components\Customers\Contacts::impersonateEnd();

// Record Correspondence
$arrRecord = [];
$arrRecord['contact_correspondence_is_outbound'] = 1;
$arrRecord['contact_correspondence_type'] = 'email';
$arrRecord['contact_correspondence_subject'] = $pMessage->getSubject();
$arrRecord['contact_correspondence_content'] = $strContent;
$arrRecord['contact_correspondence_source'] = 'form';
$arrRecord['contact_id'] = $arrContact['contact_id'];
$arrRecord['contact_correspondence_shared_attachments_folder'] = null;

$bHasAttachments = false;

if ($arrAttachmentsData && isset($arrAttachmentsData['attachments']) && count($arrAttachmentsData['attachments']))
$bHasAttachments = true;

if ($bHasAttachments && isset($arrAttachmentsData['shared_folder_name']))
$arrRecord['contact_correspondence_shared_attachments_folder'] = $arrAttachmentsData['shared_folder_name'];

$iCorrespondenceId = \Components\Customers\Contacts\Correspondence::save($arrRecord);


// Copy entity attachments to a correspondence folder
$strAttachmentsDir = '';
if ($arrRecord['contact_correspondence_shared_attachments_folder'])
{
$strAttachmentsDir = '../Private/media/customers_contacts_correspondence/' . $arrAttachmentsData['shared_folder_name'] . '/';
} else
{
if ($bHasAttachments)
$strAttachmentsDir = '../Private/media/customers_contacts_correspondence/' . $iCorrespondenceId . '/';
}

if ($strAttachmentsDir && !file_exists($strAttachmentsDir))
{
\Framework\System\FileSystem::mkdir($strAttachmentsDir);
foreach ($arrAttachmentsData['attachments'] as $strAttachment)
\Framework\System\FileSystem::copy($strAttachment, $strAttachmentsDir . basename($strAttachment));
}
}

?>
Accept Child 404:
0
0
Search Title:

															

														
Search Title Prefix:

															

														
Search Description:

															

														
Search Keywords:

															

														
Search Noindex:
0
0
Search Nofollow:
0
0
Search Change Frequency:

															

														
Search Priority:
0.5
0.5
Search Canonical Override:

															

														
Is Offline:
1
1
Is Hidden In Navigation:
1
1
Is Hidden In Sitemap:
1
1
Security New:
0
0
Security Contact Mode:

															

														
Security Contact Squeeze Viewlimit:

															

														
Security Contact Require Login:

															

														
Security Contact Groups:

															

														
Security Condition Id:

															

														
Security Heading:

															

														
Security Description:

															

														
Other Fields:

															

														
Order:
11
11
Parent Id:
/
/
Contact Id:
0
0
Design Id:
0
0
Header Functions:

															

														
Header Category:

															

														
Is Domain:
0
0
Post Category Id: