DefaultNotifications.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\manager;
  3. use MGModule\DNSManager2\models\whmcs\emailtemplate;
  4. class DefaultNotifications {
  5. const GENERAL_ZONE_CREATED_NOTIFICATION = 'DNS Manager Zone Created Notification';
  6. const GENERAL_ZONE_ALTERED_NOTIFICATION = 'DNS Manager Zone Altered Notification';
  7. const GENERAL_ZONE_REMOVED_NOTIFICATION = 'DNS Manager Zone Removed Notification';
  8. const ADMIN_CRON_SYNCHRONIZATOR_NOTIFIACTION = 'DNS Manager Cron Synchronizator Notification';
  9. const ADMIN_CRON_MIGRATOR_NOTIFICATION = 'DNS Manager Cron Migrator Notification';
  10. const ADMIN_CRON_CLEANER_NOTIFICATION = 'DNS Manager Cron Cleaner Notification';
  11. public static function createDefaultTemplates() {
  12. foreach(self::getDefaultTemplates() as $type => $templates) {
  13. foreach($templates as $name => $message) {
  14. if(!is_null(emailtemplate\emailtemplate::factory()->byTypeAndName($type,$name))) {
  15. continue ;
  16. }
  17. $emailtemplate = new emailtemplate\emailtemplate();
  18. $emailtemplate->type = $type;
  19. $emailtemplate->name = $name;
  20. $emailtemplate->subject = $name;
  21. $emailtemplate->message = $message;
  22. $emailtemplate->custom = 1;
  23. $emailtemplate->plaintext = 0;
  24. $emailtemplate->attachments = '';
  25. $emailtemplate->fromname = '';
  26. $emailtemplate->fromemail = \MGModule\DNSManager2\models\whmcs\configuration\configuration::bySetting('Email')->value;
  27. $emailtemplate->disabled = 0;
  28. $emailtemplate->language = '';
  29. $emailtemplate->copyto = '';
  30. $emailtemplate->save();
  31. }
  32. }
  33. }
  34. public static function updateDefaultAdminTemplates() {
  35. $templates = self::getDefaultTemplates();
  36. foreach($templates['admin'] as $name => $message) {
  37. $template = emailtemplate\emailtemplate::factory()->byTypeAndName('admin', $name);
  38. if(!is_null($template)) {
  39. $template->subject = $name;
  40. $template->message = $message;
  41. $template->save();
  42. }
  43. }
  44. }
  45. public static function removeDefaultTemplates() {
  46. foreach(self::getDefaultTemplates() as $type => $templates) {
  47. foreach($templates as $name => $message) {
  48. $template = emailtemplate\emailtemplate::factory()->byTypeAndName($type,$name);
  49. if(!is_null($template)) {
  50. $template->delete();
  51. }
  52. }
  53. }
  54. }
  55. public static function getMessagesIDs() {
  56. $out = array();
  57. foreach(self::getDefaultTemplates() as $type => $templates) {
  58. foreach($templates as $name => $message) {
  59. $rep = new emailtemplate\repository();
  60. $rep->setFilter('type', $type);
  61. $rep->setFilter('name', $name);
  62. $tpls = $rep->get();
  63. if(!empty($tpls)) {
  64. $tpl = array_pop($tpls);
  65. $out[$name] = $tpl->id;
  66. }
  67. }
  68. }
  69. return $out;
  70. }
  71. public static function getDefaultTemplates() {
  72. return array(
  73. 'general' => array(
  74. self::GENERAL_ZONE_CREATED_NOTIFICATION =>
  75. 'Dear {$client_name}
  76. A new zone ({$zone_name}) has been created.
  77. {$signature}',
  78. self::GENERAL_ZONE_ALTERED_NOTIFICATION =>
  79. 'Dear {$client_name}
  80. Your zone ({$zone_name}) has been altered.
  81. {$signature}',
  82. self::GENERAL_ZONE_REMOVED_NOTIFICATION =>
  83. 'Dear {$client_name}
  84. Your zone ({$zone_name}) has been removed.
  85. {$signature}'
  86. ),
  87. 'admin' =>array(
  88. self::ADMIN_CRON_SYNCHRONIZATOR_NOTIFIACTION =>
  89. '{if $notify_only}It is adviced to check synchronization of the below zones:
  90. {foreach from=$zones_synchronized item="zone"}{$zone}, {/foreach}
  91. {else}DNS Manager Synchronizator synchronize {$zones_synchronized_count} zones.
  92. Zones synchronized list:
  93. {foreach from=$zones_synchronized item="zone"}{$zone}, {/foreach}
  94. {/if}',
  95. self::ADMIN_CRON_MIGRATOR_NOTIFICATION =>
  96. '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.
  97. {if $zones_migrated_unsuccessfully_count}
  98. Zones unsuccessfully migrated:
  99. {foreach from=$zones_migrated_unsuccessfully key=zone item=reason}
  100. {$zone} - {$reason}
  101. {/foreach}
  102. {/if}
  103. {if $zones_migrated_successfully_count}
  104. Zones successfully migrated:
  105. {foreach from=$zones_migrated_successfully item=zone}{$zone},{/foreach}
  106. {/if}',
  107. self::ADMIN_CRON_CLEANER_NOTIFICATION =>
  108. '{if $notify_only}It is adviced to check the below zones:
  109. {foreach from=$zones_removed key="zone" item="reason"}{$zone} - {$reason}
  110. {/foreach}
  111. {else}DNS Manager Cleaner remove {$zones_removed_count} zones.
  112. Zones removed list:
  113. {foreach from=$zones_removed key="zone" item="reason"}{$zone} - {$reason}
  114. {/foreach}
  115. {/if}'
  116. )
  117. );
  118. }
  119. }