/
Plugin.php
70 lines (59 loc) · 3.29 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Detain\MyAdminVpsHd;
use Symfony\Component\EventDispatcher\GenericEvent;
class Plugin {
public static $name = 'Additional HD Space VPS Addon';
public static $description = 'Allows selling of HD Space Upgrades to a VPS.';
public static $help = '';
public static $module = 'vps';
public static $type = 'addon';
public function __construct() {
}
public static function getHooks() {
return [
self::$module.'.load_addons' => [__CLASS__, 'getAddon'],
self::$module.'.settings' => [__CLASS__, 'getSettings'],
];
}
public static function getAddon(GenericEvent $event) {
$service = $event->getSubject();
function_requirements('class.Addon');
$addon = new \Addon();
$addon->setModule(self::$module)
->set_text('Additional GB')
->set_text_match('Additional (.*) GB')
->set_cost(VPS_HD_COST)
->set_require_ip(FALSE)
->set_enable([__CLASS__, 'doEnable'])
->set_disable([__CLASS__, 'doDisable'])
->register();
$service->addAddon($addon);
}
public static function doEnable(\Service_Order $serviceOrder, $repeatInvoiceId, $regexMatch = FALSE) {
$serviceInfo = $serviceOrder->getServiceInfo();
$settings = get_module_settings(self::$module);
$space = $regexMatch;
myadmin_log(self::$module, 'info', self::$name." Activating {$space} GB additional HD space for {$settings['TBLNAME']} {$serviceInfo[$settings['PREFIX'].'_id']}", __LINE__, __FILE__);
$GLOBALS['tf']->history->add(self::$module.'queue', $serviceInfo[$settings['PREFIX'].'_id'], 'update_hdsize', $space, $serviceInfo[$settings['PREFIX'].'_custid']);
}
public static function doDisable(\Service_Order $serviceOrder, $repeatInvoiceId, $regexMatch = FALSE) {
$serviceInfo = $serviceOrder->getServiceInfo();
$settings = get_module_settings(self::$module);
require_once __DIR__.'/../../../../include/licenses/license.functions.inc.php';
$space = $regexMatch;
myadmin_log(self::$module, 'info', self::$name." Deactivating $space GB additional HD space for {$settings['TBLNAME']} {$serviceInfo[$settings['PREFIX'].'_id']}", __LINE__, __FILE__);
$GLOBALS['tf']->history->add(self::$module.'queue', $serviceInfo[$settings['PREFIX'].'_id'], 'update_hdsize', $space, $serviceInfo[$settings['PREFIX'].'_custid']);
add_output('Additional '.$space.' GB HD Space Removed And Canceled');
$email = $settings['TBLNAME'].' ID: '.$serviceInfo[$settings['PREFIX'].'_id'].'<br>'.$settings['TBLNAME'].' Hostname: '.$serviceInfo[$settings['PREFIX'].'_hostname'].'<br>'."Invoice: $repeatInvoiceId<br>" . "Additional Space : $space GB<br>" . "Description: {$repeat_invoice->getDescription()}<br>";
$subject = $settings['TBLNAME'].' '.$repeat_invoice->getService().' Canceled Additional '.$space.' GB HD Space';
$headers = '';
$headers .= 'MIME-Version: 1.0'.EMAIL_NEWLINE;
$headers .= 'Content-type: text/html; charset=UTF-8'.EMAIL_NEWLINE;
$headers .= 'From: '.$settings['TITLE'].' <'.$settings['EMAIL_FROM'].'>'.EMAIL_NEWLINE;
admin_mail($subject, $email, $headers, false, 'admin_email_vps_hdspace_canceled.tpl');
}
public static function getSettings(GenericEvent $event) {
$settings = $event->getSubject();
$settings->add_text_setting(self::$module, 'Addon Costs', 'vps_hd_cost', 'VPS Additional HD Space Cost:', 'This is the cost for purchasing additional HD space for a VPS.', $settings->get_setting('VPS_HD_COST'));
}
}