/** * Generates emails from the templates & datas. * - For each emails and for each active locale : * - Check if the emails is empty or does not exists anymore. If so, do nothing. * - Combines templates and datas to produce the s_title and s_text fields. * - Saves those settings for next run. * @return void. */ public function update() { // Decode and transform into a PHP array (true as a second parameter). $data = json_decode(Params::getParam("email_datas", false, false), true); if (!is_array($data)) { mdh_handle_error(sprintf(__("Given JSON datas are not correct (Error #%d)", mdh_current_plugin_name()), json_last_error()), mdh_emailmagick_url()); } // Get the HTML template. $template = Params::getParam("email_template", false, false); // This is current emails datas (stored in the database). $currentDatas = json_decode(osc_get_preference("email_datas", mdh_current_preferences_section()), true); // Create a new array, merge of the old and the new one. $newDatas = array("emails" => array(), "footer" => array("locales" => Madhouse_EmailMagick_Utils::mergeLocales($currentDatas["footer"]["locales"], $data["footer"]["locales"]))); // Iterate through new submitted emails data to update. $i = 0; foreach ($data["emails"] as $e) { // Get the old email datas, as they are right now. $oe = Madhouse_Utils_Collections::findByField($currentDatas["emails"], "s_internal_name", $e["s_internal_name"]); if (is_null($oe)) { // Not found in old emails. => new email has been installed. $locales = $e["locales"]; } else { // Found in old emails. Merge with new locales. $locales = Madhouse_EmailMagick_Utils::mergeLocales($oe["locales"], $e["locales"]); } // Email exists, create in order to be filled and pushed to the new datas (at the end). $nEmail = array("s_internal_name" => $e["s_internal_name"], "locales" => $locales); // Get the email from the database. $email = Page::newInstance()->findByInternalName($e["s_internal_name"]); if ($email !== false && count($email) > 0) { // Update the email. $updated = Madhouse_EmailMagick_Models_Emails::newInstance()->update($template, $email["pk_i_id"], $newDatas, $nEmail); $i += $updated; } array_push($newDatas["emails"], $nEmail); } // Saves the settings. Madhouse_Utils_Controllers::doSettingsPost(array("email_template", "email_datas"), array("email_template" => $template, "email_datas" => json_encode($newDatas)), mdh_emailmagick_url(), null, sprintf(__("Sucessfully updated %d emails (out of %d)!", mdh_current_plugin_name()), $i, count($data["emails"]) * count(osc_get_locales()))); }
<div class="bg-light"> <div class="bg-white"> <ul class="nav nav-tabs nav-tabs-alt nav-md vpadder-lg"> <li class="active"> <a href="<?php echo mdh_emailmagick_url(); ?> "> <?php _e("Manage your emails", mdh_current_plugin_name()); ?> </a> </li> <li class=""> <a href="http://market.osclass.org/user/profile/madhouse" target="_blank"> <span class="label label-primary"> <?php _e("See more plugins by Madhouse", mdh_current_plugin_name()); ?> </span> </a> </li> </ul> </div> <div class=""> <form action="<?php echo mdh_emailmagick_do_url(); ?> " method="post"> <div class="vpadder-lg lt b-b"> <div class="hpadder-md">
/** * Adds a submenu to the Madhouse main admin menu. * (hook: admin_menu_init) */ function mdh_emailmagick_admin_init() { osc_add_admin_submenu_divider('madhouse', "EmailMagick", mdh_current_plugin_name(), 'administrator'); osc_add_admin_submenu_page('madhouse', __('Manage your emails', mdh_current_plugin_name()), mdh_emailmagick_url(), mdh_current_plugin_name(), 'administrator'); }