diff --git a/pipit_emails/modes/email.edit.post.php b/pipit_emails/modes/email.edit.post.php index c2c8cbb..a0d883b 100644 --- a/pipit_emails/modes/email.edit.post.php +++ b/pipit_emails/modes/email.edit.post.php @@ -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(); } diff --git a/pipit_emails/modes/email.preview.post.php b/pipit_emails/modes/email.preview.post.php new file mode 100644 index 0000000..a5db269 --- /dev/null +++ b/pipit_emails/modes/email.preview.post.php @@ -0,0 +1,49 @@ +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 ''; diff --git a/pipit_emails/modes/email.preview.pre.php b/pipit_emails/modes/email.preview.pre.php new file mode 100644 index 0000000..54ae8d5 --- /dev/null +++ b/pipit_emails/modes/email.preview.pre.php @@ -0,0 +1,37 @@ +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'); + } + diff --git a/pipit_emails/preview/index.php b/pipit_emails/preview/index.php new file mode 100644 index 0000000..4317d73 --- /dev/null +++ b/pipit_emails/preview/index.php @@ -0,0 +1,9 @@ +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 '
' . print_r($Template, 1) . '
'; + //echo '
' . print_r($details, 1) . '
'; + echo $Template->render($details); \ No newline at end of file