| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom\manager;
- use MGModule\DNSManager2\models\whmcs\emailtemplate;
- class DefaultNotifications {
- const GENERAL_ZONE_CREATED_NOTIFICATION = 'DNS Manager Zone Created Notification';
- const GENERAL_ZONE_ALTERED_NOTIFICATION = 'DNS Manager Zone Altered Notification';
- const GENERAL_ZONE_REMOVED_NOTIFICATION = 'DNS Manager Zone Removed Notification';
- const ADMIN_CRON_SYNCHRONIZATOR_NOTIFIACTION = 'DNS Manager Cron Synchronizator Notification';
- const ADMIN_CRON_MIGRATOR_NOTIFICATION = 'DNS Manager Cron Migrator Notification';
- const ADMIN_CRON_CLEANER_NOTIFICATION = 'DNS Manager Cron Cleaner Notification';
-
- public static function createDefaultTemplates() {
- foreach(self::getDefaultTemplates() as $type => $templates) {
- foreach($templates as $name => $message) {
- if(!is_null(emailtemplate\emailtemplate::factory()->byTypeAndName($type,$name))) {
- continue ;
- }
- $emailtemplate = new emailtemplate\emailtemplate();
- $emailtemplate->type = $type;
- $emailtemplate->name = $name;
- $emailtemplate->subject = $name;
- $emailtemplate->message = $message;
- $emailtemplate->custom = 1;
- $emailtemplate->plaintext = 0;
- $emailtemplate->attachments = '';
- $emailtemplate->fromname = '';
- $emailtemplate->fromemail = \MGModule\DNSManager2\models\whmcs\configuration\configuration::bySetting('Email')->value;
- $emailtemplate->disabled = 0;
- $emailtemplate->language = '';
- $emailtemplate->copyto = '';
- $emailtemplate->save();
- }
- }
- }
-
- public static function updateDefaultAdminTemplates() {
- $templates = self::getDefaultTemplates();
- foreach($templates['admin'] as $name => $message) {
- $template = emailtemplate\emailtemplate::factory()->byTypeAndName('admin', $name);
- if(!is_null($template)) {
- $template->subject = $name;
- $template->message = $message;
- $template->save();
- }
- }
-
- }
-
- public static function removeDefaultTemplates() {
- foreach(self::getDefaultTemplates() as $type => $templates) {
- foreach($templates as $name => $message) {
- $template = emailtemplate\emailtemplate::factory()->byTypeAndName($type,$name);
- if(!is_null($template)) {
- $template->delete();
- }
- }
- }
- }
-
- public static function getMessagesIDs() {
- $out = array();
- foreach(self::getDefaultTemplates() as $type => $templates) {
- foreach($templates as $name => $message) {
- $rep = new emailtemplate\repository();
- $rep->setFilter('type', $type);
- $rep->setFilter('name', $name);
-
- $tpls = $rep->get();
- if(!empty($tpls)) {
- $tpl = array_pop($tpls);
- $out[$name] = $tpl->id;
- }
-
- }
- }
- return $out;
- }
-
- public static function getDefaultTemplates() {
- return array(
- 'general' => array(
- self::GENERAL_ZONE_CREATED_NOTIFICATION =>
- 'Dear {$client_name}
- A new zone ({$zone_name}) has been created.
- {$signature}',
- self::GENERAL_ZONE_ALTERED_NOTIFICATION =>
- 'Dear {$client_name}
-
- Your zone ({$zone_name}) has been altered.
- {$signature}',
- self::GENERAL_ZONE_REMOVED_NOTIFICATION =>
- 'Dear {$client_name}
-
- Your zone ({$zone_name}) has been removed.
- {$signature}'
- ),
- 'admin' =>array(
- self::ADMIN_CRON_SYNCHRONIZATOR_NOTIFIACTION =>
- '{if $notify_only}It is adviced to check synchronization of the below zones:
- {foreach from=$zones_synchronized item="zone"}{$zone}, {/foreach}
- {else}DNS Manager Synchronizator synchronize {$zones_synchronized_count} zones.
- Zones synchronized list:
- {foreach from=$zones_synchronized item="zone"}{$zone}, {/foreach}
- {/if}',
- self::ADMIN_CRON_MIGRATOR_NOTIFICATION =>
- 'DNS Manager Migrator was trying to migrate {$zones_migrated_count} zones, {$zones_migrated_successfully_count} of them was successfully migrated but {$zones_migrated_unsuccessfully_count} fails to migrate.
- {if $zones_migrated_unsuccessfully_count}
- Zones unsuccessfully migrated:
- {foreach from=$zones_migrated_unsuccessfully key=zone item=reason}
- {$zone} - {$reason}
- {/foreach}
- {/if}
- {if $zones_migrated_successfully_count}
- Zones successfully migrated:
- {foreach from=$zones_migrated_successfully item=zone}{$zone},{/foreach}
- {/if}',
- self::ADMIN_CRON_CLEANER_NOTIFICATION =>
- '{if $notify_only}It is adviced to check the below zones:
- {foreach from=$zones_removed key="zone" item="reason"}{$zone} - {$reason}
- {/foreach}
- {else}DNS Manager Cleaner remove {$zones_removed_count} zones.
- Zones removed list:
- {foreach from=$zones_removed key="zone" item="reason"}{$zone} - {$reason}
- {/foreach}
- {/if}'
- )
- );
- }
- }
|