Skip to content

Commit

Permalink
Email preview
Browse files Browse the repository at this point in the history
  • Loading branch information
husseinalhammad committed May 23, 2019
1 parent 200c6f4 commit c69d52b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 15 deletions.
38 changes: 23 additions & 15 deletions pipit_emails/modes/email.edit.post.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@
if (is_object($Email)) {
$Smartbar = new PerchSmartbar($CurrentUser, $HTML, $Lang);

$Smartbar->add_item([
'active' => true,
'type' => 'breadcrumb',
'links' => [
[
'title' => 'Emails',
'link' => $API->app_nav(),
'translate' => false,
$Smartbar->add_item([
'active' => true,
'type' => 'breadcrumb',
'links' => [
[
'title' => 'Emails',
'link' => $API->app_nav(),
'translate' => false,
],
[
'title' => $Email->title(),
'link' => $API->app_nav() . '/edit/?id=' .$Email->id(),
'translate' => false,
]
],
[
'title' => $Email->title(),
'link' => $API->app_nav() . '/edit/?id=' .$Email->id(),
'translate' => false,
]
],
]);
]);

$Smartbar->add_item([
'active' => false,
'link' => $API->app_nav() . '/preview/?id=' .$Email->id(),
'title' => 'Preview',
'icon' => 'core/document',
'position' => 'end',
]);

echo $Smartbar->render();
}
Expand Down
49 changes: 49 additions & 0 deletions pipit_emails/modes/email.preview.post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
echo $HTML->title_panel([
'heading' => $Lang->get('Editing email'),
], $CurrentUser);


if($message) echo $message;


if (is_object($Email)) {
$Smartbar = new PerchSmartbar($CurrentUser, $HTML, $Lang);

$Smartbar->add_item([
'active' => true,
'type' => 'breadcrumb',
'links' => [
[
'title' => 'Emails',
'link' => $API->app_nav(),
'translate' => false,
],
[
'title' => $Email->title(),
'link' => $API->app_nav() . '/edit/?id=' .$Email->id(),
'translate' => false,
],
[
'title' => 'Preview',
'link' => $API->app_nav() . '/edit/?id=' .$Email->id(),
],
],
]);


$Smartbar->add_item([
'active' => false,
'link' => $API->app_nav() . '/edit/?id=' .$Email->id(),
'title' => 'Edit',
'icon' => 'core/pencil',
'position' => 'end',
]);

echo $Smartbar->render();
}


// render Email in iframe
$iframe_src = $API->app_path() . '/render/?id=' . $Email->id();
echo '<iframe src="'. $iframe_src .'" style="width:97%; height:80vh; margin-left:24px; border:1px solid #e9eaea"></iframe>';
37 changes: 37 additions & 0 deletions pipit_emails/modes/email.preview.pre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
$Emails = new PipitEmails_Emails($API);
$Email = false;
$message = '';
$details = array();

if (PerchUtil::get('id')) {
if (!$CurrentUser->has_priv('pipit_emails.email.edit')) {
PerchUtil::redirect($API->app_path());
}

$emailID = (int) $_GET['id'];
$Email = $Emails->find($emailID);
if (is_object($Email)) {
$details = $Email->to_array();
} else {
PerchUtil::redirect($API->app_path() . '/edit');
}

} else {
if (!$CurrentUser->has_priv('pipit_emails.email.create')) {
PerchUtil::redirect($API->app_path());
}
}



if ($Email && $Email->template() != '') {
$template_status = $Template->set('emails/'.$Email->template(), 'email');
if($template_status > 400) {
$Template->set('emails/default.html', 'email');
$message = $HTML->failure_message('Template ' . $Email->template() . ' could not be found.');
}
} else {
$Template->set('emails/default.html', 'email');
}

9 changes: 9 additions & 0 deletions pipit_emails/preview/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
$mode = 'email.preview';
$title = 'Preview email';
$classes = [
'lib/PipitEmails_Emails.class.php',
'lib/PipitEmails_Email.class.php',
];

include('../_default_index.php');
50 changes: 50 additions & 0 deletions pipit_emails/render/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
# include the API and classes
include(__DIR__.'/../../../../core/inc/api.php');

$classes = [
'../lib/PipitEmails_Emails.class.php',
'../lib/PipitEmails_Email.class.php',
];

if($classes) {
foreach($classes as $class) { include($class); }
}

$API = new PerchAPI(1.0, 'pipit_emails');
$Lang = $API->get('Lang');
$HTML = $API->get('HTML');
$Template = $API->get('Template');
$Emails = new PipitEmails_Emails($API);
$Email = false;


if (PerchUtil::get('id')) {
$emailID = (int) $_GET['id'];
$Email = $Emails->find($emailID);
if (is_object($Email)) {
$details = $Email->to_array();
} else {
PerchUtil::redirect($API->app_path() . '/edit');
}

} else {
if (!$CurrentUser->has_priv('pipit_emails.email.create')) {
PerchUtil::redirect($API->app_path());
}
}


if ($Email && $Email->template() != '') {
$template_status = $Template->set('emails/'.$Email->template(), 'email');
if($template_status > 400) {
$Template->set('emails/default.html', 'email');
$message = $HTML->failure_message('Template ' . $Email->template() . ' could not be found.');
}
} else {
$Template->set('emails/default.html', 'email');
}

//echo '<pre>' . print_r($Template, 1) . '</pre>';
//echo '<pre>' . print_r($details, 1) . '</pre>';
echo $Template->render($details);

0 comments on commit c69d52b

Please sign in to comment.