|
11 | 11 | */ |
12 | 12 | class Plugin |
13 | 13 | { |
14 | | - public static $name = 'Licensing'; |
15 | | - public static $description = 'Allows selling of Licenses.'; |
16 | | - public static $help = ''; |
17 | | - public static $module = 'licenses'; |
18 | | - public static $type = 'module'; |
19 | | - public static $settings = [ |
20 | | - 'SERVICE_ID_OFFSET' => 5000, |
21 | | - 'USE_REPEAT_INVOICE' => true, |
22 | | - 'USE_PACKAGES' => true, |
23 | | - 'BILLING_DAYS_OFFSET' => 0, |
24 | | - 'IMGNAME' => 'certificate.png', |
25 | | - 'REPEAT_BILLING_METHOD' => NORMAL_BILLING, |
26 | | - 'DELETE_PENDING_DAYS' => 45, |
27 | | - 'SUSPEND_DAYS' => 9, |
28 | | - 'SUSPEND_WARNING_DAYS' => 7, |
29 | | - 'TITLE' => 'Licensing', |
30 | | - 'EMAIL_FROM' => 'invoice@cpaneldirect.net', |
31 | | - 'TBLNAME' => 'Licenses', |
32 | | - 'TABLE' => 'licenses', |
33 | | - 'PREFIX' => 'license', |
34 | | - 'TITLE_FIELD' => 'license_ip', |
35 | | - 'TITLE_FIELD2' => 'license_hostname', |
36 | | - 'MENUNAME' => 'Licensing']; |
| 14 | + public static $name = 'Licensing'; |
| 15 | + public static $description = 'Allows selling of Licenses.'; |
| 16 | + public static $help = ''; |
| 17 | + public static $module = 'licenses'; |
| 18 | + public static $type = 'module'; |
| 19 | + public static $settings = [ |
| 20 | + 'SERVICE_ID_OFFSET' => 5000, |
| 21 | + 'USE_REPEAT_INVOICE' => true, |
| 22 | + 'USE_PACKAGES' => true, |
| 23 | + 'BILLING_DAYS_OFFSET' => 0, |
| 24 | + 'IMGNAME' => 'certificate.png', |
| 25 | + 'REPEAT_BILLING_METHOD' => NORMAL_BILLING, |
| 26 | + 'DELETE_PENDING_DAYS' => 45, |
| 27 | + 'SUSPEND_DAYS' => 9, |
| 28 | + 'SUSPEND_WARNING_DAYS' => 7, |
| 29 | + 'TITLE' => 'Licensing', |
| 30 | + 'EMAIL_FROM' => 'invoice@cpaneldirect.net', |
| 31 | + 'TBLNAME' => 'Licenses', |
| 32 | + 'TABLE' => 'licenses', |
| 33 | + 'PREFIX' => 'license', |
| 34 | + 'TITLE_FIELD' => 'license_ip', |
| 35 | + 'TITLE_FIELD2' => 'license_hostname', |
| 36 | + 'MENUNAME' => 'Licensing']; |
37 | 37 |
|
38 | | - /** |
39 | | - * Plugin constructor. |
40 | | - */ |
41 | | - public function __construct() |
42 | | - { |
43 | | - } |
| 38 | + /** |
| 39 | + * Plugin constructor. |
| 40 | + */ |
| 41 | + public function __construct() |
| 42 | + { |
| 43 | + } |
44 | 44 |
|
45 | | - /** |
46 | | - * @return array |
47 | | - */ |
48 | | - public static function getHooks() |
49 | | - { |
50 | | - return [ |
51 | | - 'api.register' => [__CLASS__, 'apiRegister'], |
52 | | - 'function.requirements' => [__CLASS__, 'getRequirements'], |
53 | | - self::$module.'.load_processing' => [__CLASS__, 'loadProcessing'], |
54 | | - self::$module.'.settings' => [__CLASS__, 'getSettings'] |
55 | | - ]; |
56 | | - } |
| 45 | + /** |
| 46 | + * @return array |
| 47 | + */ |
| 48 | + public static function getHooks() |
| 49 | + { |
| 50 | + return [ |
| 51 | + 'api.register' => [__CLASS__, 'apiRegister'], |
| 52 | + 'function.requirements' => [__CLASS__, 'getRequirements'], |
| 53 | + self::$module.'.load_processing' => [__CLASS__, 'loadProcessing'], |
| 54 | + self::$module.'.settings' => [__CLASS__, 'getSettings'] |
| 55 | + ]; |
| 56 | + } |
57 | 57 |
|
58 | | - /** |
59 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
60 | | - */ |
61 | | - public static function getRequirements(GenericEvent $event) |
62 | | - { |
63 | | - $loader = $event->getSubject(); |
64 | | - $loader->add_requirement('api_get_license_types', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
65 | | - $loader->add_requirement('api_cancel_license_ip', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
66 | | - $loader->add_requirement('api_cancel_license', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
67 | | - $loader->add_requirement('api_buy_license_prepay', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
68 | | - $loader->add_requirement('api_buy_license', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
69 | | - $loader->add_requirement('api_change_license_ip', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
70 | | - $loader->add_requirement('api_change_license_ip_by_id', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
71 | | - } |
72 | | - |
73 | | - /** |
74 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
75 | | - */ |
76 | | - public static function apiRegister(GenericEvent $event) |
77 | | - { |
78 | | - /** |
79 | | - * @var \ServiceHandler $subject |
80 | | - */ |
81 | | - //$subject = $event->getSubject(); |
82 | | - api_register_array_array('license_types', 'license_type'); |
83 | | - api_register_array('license_type', ['services_id' => 'int', 'services_name' => 'string', 'services_cost' => 'float']); |
84 | | - api_register_array('buy_license_return', ['status' => 'string', 'status_text' => 'string', 'invoice' => 'int', 'cost' => 'float']); |
85 | | - api_register_array('change_license_ip_return', ['status' => 'string', 'status_text' => 'string']); |
86 | | - api_register_array('change_license_ip_by_id_return', ['status' => 'string', 'status_text' => 'string']); |
87 | | - api_register_array('cancel_license_return', ['status' => 'string', 'status_text' => 'string']); |
88 | | - api_register_array('cancel_license_ip_return', ['status' => 'string', 'status_text' => 'string']); |
89 | | - api_register('api_get_license_types', [], ['return' => 'license_types'], 'Get a license of the various license types.', false, false); |
90 | | - api_register('api_cancel_license_ip', ['sid' => 'string', 'ip' => 'string', 'type' => 'int'], ['return' => 'cancel_license_ip_return'], 'Cancel a License by IP and Type.', true, false); |
91 | | - api_register('api_cancel_license', ['sid' => 'string', 'id' => 'int'], ['return' => 'cancel_license_return'], 'Cancel a License.', true, false); |
92 | | - api_register('api_buy_license', ['sid' => 'string', 'ip' => 'string', 'type' => 'int', 'coupon' => 'string'], ['return' => 'buy_license_return'], 'Purchase a License. Returns an invoice ID.', true, false); |
93 | | - api_register('api_buy_license_prepay', ['sid' => 'string', 'ip' => 'string', 'type' => 'int', 'coupon' => 'string', 'use_prepay' => 'boolean'], ['return' => 'buy_license_return'], 'Purchase a License and optionally uses PrePay. Will return an error if use_prepay is true not enough PrePay funds are available.', true, false); |
94 | | - api_register('api_change_license_ip', ['sid' => 'string', 'oldip' => 'string', 'newip' => 'string'], ['return' => 'change_license_ip_return'], 'Change the IP on an active license.', true, false); |
95 | | - api_register('api_change_license_ip_by_id', ['sid' => 'string', 'id' => 'int', 'newip' => 'string'], ['return' => 'change_license_ip_by_id_return'], 'Change the IP on an active license.', true, false); |
96 | | - } |
| 58 | + /** |
| 59 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 60 | + */ |
| 61 | + public static function getRequirements(GenericEvent $event) |
| 62 | + { |
| 63 | + $loader = $event->getSubject(); |
| 64 | + $loader->add_requirement('api_get_license_types', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 65 | + $loader->add_requirement('api_cancel_license_ip', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 66 | + $loader->add_requirement('api_cancel_license', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 67 | + $loader->add_requirement('api_buy_license_prepay', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 68 | + $loader->add_requirement('api_buy_license', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 69 | + $loader->add_requirement('api_change_license_ip', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 70 | + $loader->add_requirement('api_change_license_ip_by_id', '/../vendor/detain/myadmin-licenses-module/src/api.php'); |
| 71 | + } |
97 | 72 |
|
98 | | - /** |
99 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
100 | | - */ |
101 | | - public static function loadProcessing(GenericEvent $event) |
102 | | - { |
103 | | - /** |
104 | | - * @var \ServiceHandler $service |
105 | | - */ |
106 | | - $service = $event->getSubject(); |
107 | | - $service->setModule(self::$module) |
108 | | - ->setEnable(function ($service) { |
109 | | - $serviceTypes = run_event('get_service_types', false, self::$module); |
110 | | - $serviceInfo = $service->getServiceInfo(); |
111 | | - $settings = get_module_settings(self::$module); |
112 | | - $db = get_module_db(self::$module); |
113 | | - $db->query("update {$settings['TABLE']} set {$settings['PREFIX']}_status='active' where {$settings['PREFIX']}_id='{$serviceInfo[$settings['PREFIX'].'_id']}'", __LINE__, __FILE__); |
114 | | - $GLOBALS['tf']->history->add($settings['TABLE'], 'change_status', 'active', $serviceInfo[$settings['PREFIX'].'_id'], $serviceInfo[$settings['PREFIX'].'_custid']); |
115 | | - $smarty = new \TFSmarty; |
116 | | - $smarty->assign('license_ip', $serviceInfo[$settings['PREFIX'].'_ip']); |
117 | | - $smarty->assign('service_name', $serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name']); |
118 | | - $email = $smarty->fetch('email/admin/license_created.tpl'); |
119 | | - //$subject = $smarty->get_template_vars('subject'); |
120 | | - $subject = 'New '.$serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name'].' License Created '.$serviceInfo[$settings['PREFIX'].'_ip']; |
121 | | - (new \MyAdmin\Mail())->adminMail($subject, $email, false, 'admin/license_created.tpl'); |
122 | | - })->setReactivate(function ($service) { |
123 | | - $serviceTypes = run_event('get_service_types', false, self::$module); |
124 | | - $serviceInfo = $service->getServiceInfo(); |
125 | | - $settings = get_module_settings(self::$module); |
126 | | - $db = get_module_db(self::$module); |
127 | | - $db->query("update {$settings['TABLE']} set {$settings['PREFIX']}_status='active' where {$settings['PREFIX']}_id='{$serviceInfo[$settings['PREFIX'].'_id']}'", __LINE__, __FILE__); |
128 | | - $GLOBALS['tf']->history->add($settings['TABLE'], 'change_status', 'active', $serviceInfo[$settings['PREFIX'].'_id'], $serviceInfo[$settings['PREFIX'].'_custid']); |
129 | | - $smarty = new \TFSmarty; |
130 | | - $smarty->assign('license_ip', $serviceInfo[$settings['PREFIX'].'_ip']); |
131 | | - $smarty->assign('service_name', $serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name']); |
132 | | - $email = $smarty->fetch('email/admin/license_reactivated.tpl'); |
133 | | - $subject = $serviceInfo[$settings['TITLE_FIELD']].' '.$serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name'].' '.$settings['TBLNAME'].' Reactivated'; |
134 | | - (new \MyAdmin\Mail())->adminMail($subject, $email, false, 'admin/license_reactivated.tpl'); |
135 | | - })->setDisable(function () { |
136 | | - })->register(); |
137 | | - } |
| 73 | + /** |
| 74 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 75 | + */ |
| 76 | + public static function apiRegister(GenericEvent $event) |
| 77 | + { |
| 78 | + /** |
| 79 | + * @var \ServiceHandler $subject |
| 80 | + */ |
| 81 | + //$subject = $event->getSubject(); |
| 82 | + api_register_array_array('license_types', 'license_type'); |
| 83 | + api_register_array('license_type', ['services_id' => 'int', 'services_name' => 'string', 'services_cost' => 'float']); |
| 84 | + api_register_array('buy_license_return', ['status' => 'string', 'status_text' => 'string', 'invoice' => 'int', 'cost' => 'float']); |
| 85 | + api_register_array('change_license_ip_return', ['status' => 'string', 'status_text' => 'string']); |
| 86 | + api_register_array('change_license_ip_by_id_return', ['status' => 'string', 'status_text' => 'string']); |
| 87 | + api_register_array('cancel_license_return', ['status' => 'string', 'status_text' => 'string']); |
| 88 | + api_register_array('cancel_license_ip_return', ['status' => 'string', 'status_text' => 'string']); |
| 89 | + api_register('api_get_license_types', [], ['return' => 'license_types'], 'Get a license of the various license types.', false, false); |
| 90 | + api_register('api_cancel_license_ip', ['sid' => 'string', 'ip' => 'string', 'type' => 'int'], ['return' => 'cancel_license_ip_return'], 'Cancel a License by IP and Type.', true, false); |
| 91 | + api_register('api_cancel_license', ['sid' => 'string', 'id' => 'int'], ['return' => 'cancel_license_return'], 'Cancel a License.', true, false); |
| 92 | + api_register('api_buy_license', ['sid' => 'string', 'ip' => 'string', 'type' => 'int', 'coupon' => 'string'], ['return' => 'buy_license_return'], 'Purchase a License. Returns an invoice ID.', true, false); |
| 93 | + api_register('api_buy_license_prepay', ['sid' => 'string', 'ip' => 'string', 'type' => 'int', 'coupon' => 'string', 'use_prepay' => 'boolean'], ['return' => 'buy_license_return'], 'Purchase a License and optionally uses PrePay. Will return an error if use_prepay is true not enough PrePay funds are available.', true, false); |
| 94 | + api_register('api_change_license_ip', ['sid' => 'string', 'oldip' => 'string', 'newip' => 'string'], ['return' => 'change_license_ip_return'], 'Change the IP on an active license.', true, false); |
| 95 | + api_register('api_change_license_ip_by_id', ['sid' => 'string', 'id' => 'int', 'newip' => 'string'], ['return' => 'change_license_ip_by_id_return'], 'Change the IP on an active license.', true, false); |
| 96 | + } |
138 | 97 |
|
139 | | - /** |
140 | | - * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
141 | | - */ |
142 | | - public static function getSettings(GenericEvent $event) |
143 | | - { |
144 | | - /** |
145 | | - * @var \MyAdmin\Settings $settings |
146 | | - **/ |
147 | | - $settings = $event->getSubject(); |
148 | | - $settings->add_dropdown_setting(self::$module, _('General'), 'outofstock_licenses', _('Out Of Stock Licenses'), _('Enable/Disable Sales Of This Type'), $settings->get_setting('OUTOFSTOCK_LICENSES'), ['0', '1'], ['No', 'Yes']); |
149 | | - } |
| 98 | + /** |
| 99 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 100 | + */ |
| 101 | + public static function loadProcessing(GenericEvent $event) |
| 102 | + { |
| 103 | + /** |
| 104 | + * @var \ServiceHandler $service |
| 105 | + */ |
| 106 | + $service = $event->getSubject(); |
| 107 | + $service->setModule(self::$module) |
| 108 | + ->setEnable(function ($service) { |
| 109 | + $serviceTypes = run_event('get_service_types', false, self::$module); |
| 110 | + $serviceInfo = $service->getServiceInfo(); |
| 111 | + $settings = get_module_settings(self::$module); |
| 112 | + $db = get_module_db(self::$module); |
| 113 | + $db->query("update {$settings['TABLE']} set {$settings['PREFIX']}_status='active' where {$settings['PREFIX']}_id='{$serviceInfo[$settings['PREFIX'].'_id']}'", __LINE__, __FILE__); |
| 114 | + $GLOBALS['tf']->history->add($settings['TABLE'], 'change_status', 'active', $serviceInfo[$settings['PREFIX'].'_id'], $serviceInfo[$settings['PREFIX'].'_custid']); |
| 115 | + $smarty = new \TFSmarty(); |
| 116 | + $smarty->assign('license_ip', $serviceInfo[$settings['PREFIX'].'_ip']); |
| 117 | + $smarty->assign('service_name', $serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name']); |
| 118 | + $email = $smarty->fetch('email/admin/license_created.tpl'); |
| 119 | + //$subject = $smarty->get_template_vars('subject'); |
| 120 | + $subject = 'New '.$serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name'].' License Created '.$serviceInfo[$settings['PREFIX'].'_ip']; |
| 121 | + (new \MyAdmin\Mail())->adminMail($subject, $email, false, 'admin/license_created.tpl'); |
| 122 | + })->setReactivate(function ($service) { |
| 123 | + $serviceTypes = run_event('get_service_types', false, self::$module); |
| 124 | + $serviceInfo = $service->getServiceInfo(); |
| 125 | + $settings = get_module_settings(self::$module); |
| 126 | + $db = get_module_db(self::$module); |
| 127 | + $db->query("update {$settings['TABLE']} set {$settings['PREFIX']}_status='active' where {$settings['PREFIX']}_id='{$serviceInfo[$settings['PREFIX'].'_id']}'", __LINE__, __FILE__); |
| 128 | + $GLOBALS['tf']->history->add($settings['TABLE'], 'change_status', 'active', $serviceInfo[$settings['PREFIX'].'_id'], $serviceInfo[$settings['PREFIX'].'_custid']); |
| 129 | + $smarty = new \TFSmarty(); |
| 130 | + $smarty->assign('license_ip', $serviceInfo[$settings['PREFIX'].'_ip']); |
| 131 | + $smarty->assign('service_name', $serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name']); |
| 132 | + $email = $smarty->fetch('email/admin/license_reactivated.tpl'); |
| 133 | + $subject = $serviceInfo[$settings['TITLE_FIELD']].' '.$serviceTypes[$serviceInfo[$settings['PREFIX'].'_type']]['services_name'].' '.$settings['TBLNAME'].' Reactivated'; |
| 134 | + (new \MyAdmin\Mail())->adminMail($subject, $email, false, 'admin/license_reactivated.tpl'); |
| 135 | + })->setDisable(function () { |
| 136 | + })->register(); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * @param \Symfony\Component\EventDispatcher\GenericEvent $event |
| 141 | + */ |
| 142 | + public static function getSettings(GenericEvent $event) |
| 143 | + { |
| 144 | + /** |
| 145 | + * @var \MyAdmin\Settings $settings |
| 146 | + **/ |
| 147 | + $settings = $event->getSubject(); |
| 148 | + $settings->add_dropdown_setting(self::$module, _('General'), 'outofstock_licenses', _('Out Of Stock Licenses'), _('Enable/Disable Sales Of This Type'), $settings->get_setting('OUTOFSTOCK_LICENSES'), ['0', '1'], ['No', 'Yes']); |
| 149 | + } |
150 | 150 | } |
0 commit comments