api.olltvservice.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. <?php
  2. /**
  3. * OllTV OTT service implementation
  4. */
  5. class OllTVService {
  6. /**
  7. * Contains system alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * System messages helper instance
  14. *
  15. * @var object
  16. */
  17. protected $messages = '';
  18. /**
  19. * Olltv low-level API layer
  20. *
  21. * @var object
  22. */
  23. protected $api = '';
  24. /**
  25. * OllTv subscribers database abstraction layer
  26. *
  27. * @var object
  28. */
  29. protected $subscribersDb = '';
  30. /**
  31. * OllTv tariffs database abstraction layer
  32. *
  33. * @var object
  34. */
  35. protected $tariffsDb = '';
  36. /**
  37. * Contains all available users data as login=>userData
  38. *
  39. * @var array
  40. */
  41. protected $allUsersData = array();
  42. /**
  43. * Contains pseudo-mail domain to generate subs emails
  44. *
  45. * @var string
  46. */
  47. protected $mailDomain = '';
  48. /**
  49. * Contains all existing subscribers data as login=>data
  50. *
  51. * @var array
  52. */
  53. protected $allUsers = array();
  54. /**
  55. * Contains all available tariffs as id=>tariffData
  56. *
  57. * @var array
  58. */
  59. protected $allTariffs = array();
  60. /**
  61. * Contains all available tariff names as tariffId=>name
  62. *
  63. * @var array
  64. */
  65. protected $allTariffNames = array();
  66. /**
  67. * Country code to skip from mobile numbers
  68. *
  69. * @var string
  70. */
  71. protected $countryCode = '+38';
  72. //some predefined routes, urls, paths etc
  73. const LOG_PATH = 'exports/olltv.log';
  74. const TABLE_SUBSCRIBERS = 'ot_users';
  75. const TABLE_TARIFFS = 'ot_tariffs';
  76. const URL_ME = '?module=olltv';
  77. const ROUTE_SUBLIST = 'subscribers';
  78. const ROUTE_TARIFFS = 'tariffs';
  79. const ROUTE_DELTARIFF = 'deletetariffid';
  80. const ROUTE_AJSUBSLIST = 'ajsubscriberslist';
  81. const ROUTE_SUBSCRIBER = 'showsubscriber';
  82. const ROUTE_SUBSEARCH = 'username';
  83. const ROUTE_ACTIVATE = 'subactivate';
  84. const ROUTE_DEACTIVATE = 'subdeactivate';
  85. const PROUTE_NEWTARIFF = 'createnewtariff';
  86. const PROUTE_EDITTARIFF = 'editariffid';
  87. const PROUTE_TARIFFNAME = 'newtariffname';
  88. const PROUTE_TARIFFALIAS = 'newtariffalias';
  89. const PROUTE_TARIFFFEE = 'newtarifffee';
  90. const PROUTE_TARIFFMAIN = 'newtariffmain';
  91. const PROUTE_SUBSETTARIF = 'settariffsublogin';
  92. const PROUTE_SUBTARIFFID = 'subsetariffid';
  93. const PROUTE_MANUALREGISTER = 'manualsubregister';
  94. // o
  95. // o /
  96. // \ /
  97. // \ /
  98. // UNICORN \ / TV
  99. // +--------------v-------------+
  100. // | __________________ @ |
  101. // | / \ |
  102. // | | ,-,/ | (\) |
  103. // | | _ ___/ /\| | |
  104. // | | ,;`( )__, ) ~ | (-) |
  105. // | | // o// '--; | |
  106. // | \ ' o \ | / :|||: |
  107. // | -ooo-------------- :|||: |
  108. // +----------------------------+
  109. // [] []
  110. /**
  111. * Creates new OLLTV service instance
  112. *
  113. * @return object
  114. */
  115. public function __construct() {
  116. $this->initMessages();
  117. $this->loadAlter();
  118. $this->setOptions();
  119. $this->initApi();
  120. $this->loadUserData();
  121. $this->initSubscribers();
  122. $this->loadSubscribers();
  123. $this->initTariffs();
  124. $this->loadTariffs();
  125. }
  126. /**
  127. * Loads some required config data
  128. *
  129. * @return void
  130. */
  131. protected function loadAlter() {
  132. global $ubillingConfig;
  133. $this->altCfg = $ubillingConfig->getAlter();
  134. }
  135. /**
  136. * Sets some properties
  137. *
  138. * @return void
  139. */
  140. protected function setOptions() {
  141. $this->mailDomain = $this->altCfg['OLLTV_DOMAIN'];
  142. }
  143. /**
  144. * Inits messages helper for further usage
  145. *
  146. * @return void
  147. */
  148. protected function initMessages() {
  149. $this->messages = new UbillingMessageHelper();
  150. }
  151. /**
  152. * Inits Olltv low-level API layer
  153. *
  154. * @return void
  155. */
  156. protected function initApi() {
  157. if (!empty($this->altCfg['OLLTV_LOGIN']) AND ! empty($this->altCfg['OLLTV_PASSWORD'])) {
  158. $this->api = new OllTv($this->altCfg['OLLTV_LOGIN'], $this->altCfg['OLLTV_PASSWORD'], false, self::LOG_PATH, $this->altCfg['OLLTV_DEBUG']);
  159. } else {
  160. throw new Exception('EX_EMPTY_OLLTVOPTIONS');
  161. }
  162. }
  163. /**
  164. * Inits subscribers database abstraction layer
  165. *
  166. * @return void
  167. */
  168. protected function initSubscribers() {
  169. $this->subscribersDb = new NyanORM(self::TABLE_SUBSCRIBERS);
  170. }
  171. /**
  172. * Loads available subscribers data from database
  173. *
  174. * @return void
  175. */
  176. protected function loadSubscribers() {
  177. $this->allUsers = $this->subscribersDb->getAll('login');
  178. }
  179. /**
  180. * Inits tariffs database abstraction layer
  181. *
  182. * @return void
  183. */
  184. protected function initTariffs() {
  185. $this->tariffsDb = new NyanORM(self::TABLE_TARIFFS);
  186. }
  187. /**
  188. * Loads available subscribers data from database
  189. *
  190. * @return void
  191. */
  192. protected function loadTariffs() {
  193. $this->allTariffs = $this->tariffsDb->getAll('id');
  194. if (!empty($this->allTariffs)) {
  195. foreach ($this->allTariffs as $io => $each) {
  196. $this->allTariffNames[$each['id']] = $each['name'];
  197. }
  198. }
  199. }
  200. /**
  201. * Loads all available users data from database
  202. *
  203. * @return void
  204. */
  205. protected function loadUserData() {
  206. $this->allUsersData = zb_UserGetAllData();
  207. }
  208. /**
  209. * Transforms stdObject into array
  210. *
  211. * @param mixed $data
  212. *
  213. * @return array
  214. */
  215. protected function makeArray($data) {
  216. $result = array();
  217. if (!empty($data)) {
  218. $result = json_decode(json_encode($data), true);
  219. }
  220. return($result);
  221. }
  222. /**
  223. * Returns existing users array
  224. *
  225. * @return array
  226. */
  227. public function getUserList() {
  228. $result = $this->makeArray($this->api->getUserList());
  229. return($result);
  230. }
  231. /**
  232. * Generates user pseudo-mail or returns real mail if it exists in database
  233. *
  234. * @param string $login
  235. *
  236. * @return string
  237. */
  238. protected function generateMail($login) {
  239. if (!empty($this->mailDomain)) {
  240. $result = $login . '@' . $this->mailDomain;
  241. }
  242. if (isset($this->allUsersData[$login])) {
  243. if (!empty($this->allUsersData[$login]['email'])) {
  244. $result = $this->allUsersData[$login]['email'];
  245. }
  246. }
  247. return($result);
  248. }
  249. /**
  250. * Prepares mobile number for registration
  251. *
  252. * @param string $mobile
  253. *
  254. * @return string
  255. */
  256. protected function prepareMobile($mobile) {
  257. $result = '';
  258. if (!empty($mobile)) {
  259. $result = str_replace($this->countryCode, '', $mobile);
  260. }
  261. return($result);
  262. }
  263. /**
  264. * Creates new subscriber depends on system user data
  265. *
  266. * @param string $login Existing user login
  267. *
  268. * @return void/string on error
  269. */
  270. public function createSubscriber($login) {
  271. $result = '';
  272. if (!empty($login)) {
  273. if (!isset($this->allUsers[$login])) {
  274. if (isset($this->allUsersData[$login])) {
  275. $userData = $this->allUsersData[$login];
  276. $mail = $this->generateMail($login);
  277. if (!empty($mail)) {
  278. $mobile = $this->prepareMobile($userData['mobile']);
  279. if (!empty($mobile)) {
  280. $addParams = array('phone' => $mobile);
  281. $creationResult = $this->api->addUser($mail, $login, $addParams);
  282. if ($creationResult) {
  283. $result = '';
  284. //registering new subscriber in local database
  285. $this->subscribersDb->data('date', curdatetime());
  286. $this->subscribersDb->data('remoteid', $creationResult);
  287. $this->subscribersDb->data('login', $login);
  288. $this->subscribersDb->data('email', $mail);
  289. $this->subscribersDb->data('phone', $mobile);
  290. $this->subscribersDb->create();
  291. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') AS [' . $creationResult . ']');
  292. }
  293. } else {
  294. $result .= 'Empty mobile';
  295. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') FAIL EMPTY_MOBILE');
  296. }
  297. } else {
  298. $result .= 'Empty email';
  299. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') FAIL EMPTY_EMAIL');
  300. }
  301. } else {
  302. $result .= 'User not exists';
  303. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') FAIL LOGIN_NOT_EXIST');
  304. }
  305. } else {
  306. $result .= 'User already registered';
  307. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') FAIL ALREADY_REGISTERED');
  308. }
  309. } else {
  310. $result .= 'Empty login';
  311. log_register('OLLTV CREATE SUBSCRIBER (' . $login . ') FAIL EMPTY_LOGIN');
  312. }
  313. return($result);
  314. }
  315. /**
  316. * Returns existing olltv subscriber data
  317. *
  318. * @param string $login
  319. *
  320. * @return array
  321. */
  322. public function getSubscriberData($login) {
  323. $result = $this->makeArray($this->api->getUserInfo(array('account' => $login)));
  324. return($result);
  325. }
  326. /**
  327. * Deletes existing subscriber
  328. *
  329. * @param string $login
  330. *
  331. * @return void
  332. */
  333. public function deleteSubscriber($login) {
  334. $params = array('account' => $login);
  335. $subscriberData = $this->getSubscriberData($login);
  336. if (!empty($subscriberData)) {
  337. $this->api->deleteAccount($params);
  338. $this->subscribersDb->where('login', '=', $login);
  339. $this->subscribersDb->delete();
  340. log_register('OLLTV DELETE SUBSCRIBER (' . $login . ')');
  341. }
  342. }
  343. /**
  344. * Renders existing subscribers list
  345. *
  346. * @return string
  347. */
  348. public function renderSubscribersList() {
  349. $result = '';
  350. $result .= wf_modalAuto(web_icon_create() . ' ' . __('Users registration'), __('Users registration'), $this->renderSubscriberRegisterForm(), 'ubButton');
  351. $result .= wf_delimiter();
  352. if (!empty($this->allUsers)) {
  353. $columns = array('ID', 'Login', 'Real Name', 'Full address', 'Cash', 'Current tariff', 'Date', 'Active', 'Actions');
  354. $opts = '"order": [[ 0, "desc" ]]';
  355. $result .= wf_JqDtLoader($columns, self::URL_ME . '&' . self::ROUTE_AJSUBSLIST . '=true', false, __('Users'), 100, $opts);
  356. } else {
  357. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'info');
  358. }
  359. return($result);
  360. }
  361. /**
  362. * Renders existing subscribers ajax list
  363. */
  364. public function ajSubscribersList() {
  365. $json = new wf_JqDtHelper();
  366. if (!empty($this->allUsers)) {
  367. foreach ($this->allUsers as $eachLogin => $subData) {
  368. $userData = $this->allUsersData[$eachLogin];
  369. $userAddress = (isset($userData['fulladress'])) ? $userData['fulladress'] : '';
  370. if (!empty($userAddress)) {
  371. $userLink = wf_Link(UserProfile::URL_PROFILE . $eachLogin, web_profile_icon() . ' ' . $userAddress);
  372. } else {
  373. $userLink = $eachLogin;
  374. }
  375. $data[] = $subData['id'];
  376. $data[] = $subData['login'];
  377. $data[] = @$userData['realname'];
  378. $data[] = $userLink;
  379. $data[] = @$userData['Cash'];
  380. $data[] = @$this->allTariffNames[$subData['tariffid']];
  381. $data[] = $subData['date'];
  382. $data[] = web_bool_led($subData['active'], true);
  383. $subControls = wf_Link(self::URL_ME . '&' . self::ROUTE_SUBSCRIBER . '=' . $subData['login'], web_edit_icon());
  384. $data[] = $subControls;
  385. $json->addRow($data);
  386. unset($data);
  387. }
  388. }
  389. $json->getJson();
  390. }
  391. /**
  392. * Renders module controls
  393. *
  394. * @return string
  395. */
  396. public function renderPanel() {
  397. $result = '';
  398. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_SUBLIST . '=true', wf_img('skins/ukv/users.png') . ' ' . __('Subscriptions'), false, 'ubButton');
  399. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_TARIFFS . '=true', wf_img('skins/ukv/dollar.png') . ' ' . __('Tariffs'), false, 'ubButton');
  400. return($result);
  401. }
  402. /**
  403. * Renders manual subscriber registering form
  404. *
  405. * @return string
  406. */
  407. protected function renderSubscriberRegisterForm() {
  408. $result = '';
  409. $inputs = wf_TextInput(self::PROUTE_MANUALREGISTER, __('Login'), '', false, 20);
  410. $inputs .= wf_Submit(__('Register'));
  411. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  412. return($result);
  413. }
  414. /**
  415. * Renders available tariffs list
  416. *
  417. * @return string
  418. */
  419. public function renderTariffsList() {
  420. $result = '';
  421. $result .= wf_modalAuto(web_icon_create() . ' ' . __('Create new tariff'), __('Create new tariff'), $this->renderTariffCreateForm(), 'ubButton');
  422. $result .= wf_delimiter(1);
  423. if (!empty($this->allTariffs)) {
  424. $cells = wf_TableCell(__('ID'));
  425. $cells .= wf_TableCell(__('Name'));
  426. $cells .= wf_TableCell(__('Service ID'));
  427. $cells .= wf_TableCell(__('Fee'));
  428. $cells .= wf_TableCell(__('Primary'));
  429. $cells .= wf_TableCell(__('Actions'));
  430. $rows = wf_TableRow($cells, 'row1');
  431. foreach ($this->allTariffs as $io => $each) {
  432. $cells = wf_TableCell($each['id']);
  433. $cells .= wf_TableCell($each['name']);
  434. $cells .= wf_TableCell($each['alias']);
  435. $cells .= wf_TableCell($each['fee']);
  436. $cells .= wf_TableCell(web_bool_led($each['main']));
  437. $delUrl = self::URL_ME . '&' . self::ROUTE_DELTARIFF . '=' . $each['id'];
  438. $tariffControls = wf_JSAlert($delUrl, web_delete_icon(), $this->messages->getDeleteAlert()) . ' ';
  439. $tariffControls .= wf_modalAuto(web_edit_icon(), __('Edit tariff') . ' ' . $each['name'], $this->renderTariffEditForm($each['id']));
  440. $cells .= wf_TableCell($tariffControls);
  441. $rows .= wf_TableRow($cells, 'row5');
  442. }
  443. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  444. } else {
  445. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  446. }
  447. return($result);
  448. }
  449. /**
  450. * Renders new tariff creation form
  451. *
  452. * @return string
  453. */
  454. protected function renderTariffCreateForm() {
  455. $result = '';
  456. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  457. $inputs = wf_HiddenInput(self::PROUTE_NEWTARIFF, 'true');
  458. $inputs .= wf_TextInput(self::PROUTE_TARIFFNAME, __('Tariff name') . $sup, '', true, 20);
  459. $inputs .= wf_TextInput(self::PROUTE_TARIFFALIAS, __('Service ID') . $sup, '', true, 20);
  460. $inputs .= wf_TextInput(self::PROUTE_TARIFFFEE, __('Fee') . $sup, '', true, 5, 'finance');
  461. $inputs .= wf_CheckInput(self::PROUTE_TARIFFMAIN, __('Primary'), true, true);
  462. $inputs .= wf_Submit(__('Create'));
  463. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  464. return($result);
  465. }
  466. /**
  467. * Renders existing tariff editing form
  468. *
  469. * @param int $tariffId
  470. *
  471. * @return string
  472. */
  473. protected function renderTariffEditForm($tariffId) {
  474. $result = '';
  475. $tariffId = ubRouting::filters($tariffId, 'int');
  476. if (isset($this->allTariffs[$tariffId])) {
  477. $tariffData = $this->allTariffs[$tariffId];
  478. $sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  479. $inputs = wf_HiddenInput(self::PROUTE_EDITTARIFF, $tariffId);
  480. $inputs .= wf_TextInput(self::PROUTE_TARIFFNAME, __('Tariff name') . $sup, $tariffData['name'], true, 20);
  481. $inputs .= wf_TextInput(self::PROUTE_TARIFFALIAS, __('Service ID') . $sup, $tariffData['alias'], true, 20);
  482. $inputs .= wf_TextInput(self::PROUTE_TARIFFFEE, __('Fee') . $sup, $tariffData['fee'], true, 5, 'finance');
  483. $inputs .= wf_CheckInput(self::PROUTE_TARIFFMAIN, __('Primary'), true, $tariffData['main']);
  484. $inputs .= wf_Submit(__('Save'));
  485. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  486. } else {
  487. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Tariff') . ' [' . $tariffId . ']' . ' ' . __('Not exists'), 'error');
  488. }
  489. return($result);
  490. }
  491. /**
  492. * Creates new tariff in database
  493. *
  494. * @return void
  495. */
  496. public function createTariff() {
  497. if (ubRouting::checkPost(self::PROUTE_NEWTARIFF)) {
  498. if (ubRouting::checkPost(array(self::PROUTE_TARIFFNAME, self::PROUTE_TARIFFALIAS))) {
  499. $this->tariffsDb->data('name', ubRouting::post(self::PROUTE_TARIFFNAME, 'mres'));
  500. $this->tariffsDb->data('alias', ubRouting::post(self::PROUTE_TARIFFALIAS, 'mres'));
  501. $this->tariffsDb->data('fee', ubRouting::post(self::PROUTE_TARIFFFEE));
  502. $this->tariffsDb->data('period', 'month');
  503. $isMain = (ubRouting::checkPost(self::PROUTE_TARIFFMAIN)) ? 1 : 0;
  504. $this->tariffsDb->data('main', $isMain);
  505. $this->tariffsDb->create();
  506. $newId = $this->tariffsDb->getLastId();
  507. log_register('OLLTV CREATE TARIFF [' . $newId . ']');
  508. }
  509. }
  510. }
  511. /**
  512. * Saves tariff data in database
  513. *
  514. * @return void
  515. */
  516. public function saveTariff() {
  517. if (ubRouting::checkPost(self::PROUTE_EDITTARIFF)) {
  518. $tariffId = ubRouting::post(self::PROUTE_EDITTARIFF, 'int');
  519. if (ubRouting::checkPost(array(self::PROUTE_TARIFFNAME, self::PROUTE_TARIFFALIAS))) {
  520. $this->tariffsDb->where('id', '=', $tariffId);
  521. $this->tariffsDb->data('name', ubRouting::post(self::PROUTE_TARIFFNAME, 'mres'));
  522. $this->tariffsDb->data('alias', ubRouting::post(self::PROUTE_TARIFFALIAS, 'mres'));
  523. $this->tariffsDb->data('fee', ubRouting::post(self::PROUTE_TARIFFFEE));
  524. $this->tariffsDb->data('period', 'month');
  525. $isMain = (ubRouting::checkPost(self::PROUTE_TARIFFMAIN)) ? 1 : 0;
  526. $this->tariffsDb->data('main', $isMain);
  527. $this->tariffsDb->save();
  528. log_register('OLLTV SAVE TARIFF [' . $tariffId . ']');
  529. }
  530. }
  531. }
  532. /**
  533. * Deletes existing tariff from database
  534. *
  535. * @param int $tariffId
  536. *
  537. * @return void/string on error
  538. */
  539. public function deleteTariff($tariffId) {
  540. $result = '';
  541. $tariffId = ubRouting::filters($tariffId, 'int');
  542. if (!$this->isTariffProtected($tariffId)) {
  543. $this->tariffsDb->where('id', '=', $tariffId);
  544. $this->tariffsDb->delete();
  545. log_register('OLLTV DELETE TARIFF [' . $tariffId . ']');
  546. } else {
  547. log_register('OLLTV DELETE TARIFF FAIL [' . $tariffId . '] IS_PROTECTED');
  548. }
  549. return($result);
  550. }
  551. /**
  552. * Returns existing subscriberId by user login
  553. *
  554. * @param string $login
  555. *
  556. * @return int/bool
  557. */
  558. public function getSubscriberId($login) {
  559. $result = false;
  560. if (isset($this->allUsers[$login])) {
  561. $result = $this->allUsers[$login]['id'];
  562. }
  563. return($result);
  564. }
  565. /**
  566. * Renders tariff apply form for some subscriber login
  567. *
  568. * @param string $subscriberLogin
  569. *
  570. * @return string
  571. */
  572. public function renderTariffChangeForm($subscriberLogin) {
  573. $result = '';
  574. $subData = $this->allUsers[$subscriberLogin];
  575. $inputs = wf_HiddenInput(self::PROUTE_SUBSETTARIF, $subscriberLogin);
  576. $tariffSelector = array(0 => '-');
  577. $tariffSelector += $this->allTariffNames;
  578. $inputs .= wf_Selector(self::PROUTE_SUBTARIFFID, $tariffSelector, __('Tariff'), $subData['tariffid'], false) . ' ';
  579. $inputs .= wf_Submit(__('Change'));
  580. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  581. return($result);
  582. }
  583. /**
  584. * Renders existing subscriber profile
  585. *
  586. * @param login $login
  587. *
  588. * @return string
  589. */
  590. public function renderSubscriberProfile($login) {
  591. $result = '';
  592. if (isset($this->allUsers[$login])) {
  593. $subData = $this->allUsers[$login];
  594. $userData = $this->allUsersData[$login];
  595. $remoteData = $this->api->getUserInfo(array('account' => $login));
  596. $cells = wf_TableCell(__('Real Name'), '50%', 'row2');
  597. $cells .= wf_TableCell($userData['realname']);
  598. $rows = wf_TableRow($cells, 'row3');
  599. $cells = wf_TableCell(__('Login'), '', 'row2');
  600. $cells .= wf_TableCell($subData['login']);
  601. $rows .= wf_TableRow($cells, 'row3');
  602. $cells = wf_TableCell(__('Full address'), '', 'row2');
  603. $userLink = wf_Link(UserProfile::URL_PROFILE . $subData['login'], web_profile_icon() . ' ' . $userData['fulladress']);
  604. $cells .= wf_TableCell($userLink);
  605. $rows .= wf_TableRow($cells, 'row3');
  606. $cells = wf_TableCell(__('Email'), '', 'row2');
  607. $cells .= wf_TableCell($subData['email']);
  608. $rows .= wf_TableRow($cells, 'row3');
  609. $cells = wf_TableCell(__('Mobile'), '', 'row2');
  610. $cells .= wf_TableCell($subData['phone']);
  611. $rows .= wf_TableRow($cells, 'row3');
  612. $cells = wf_TableCell(__('Tariff'), '', 'row2');
  613. $tariffName = (isset($this->allTariffNames[$subData['tariffid']])) ? $this->allTariffNames[$subData['tariffid']] : __('No');
  614. $cells .= wf_TableCell($tariffName);
  615. $rows .= wf_TableRow($cells, 'row3');
  616. $cells = wf_TableCell(__('Additional tariff'), '', 'row2');
  617. $tariffName = (isset($this->allTariffNames[$subData['addtariffid']])) ? $this->allTariffNames[$subData['addtariffid']] : __('No');
  618. $cells .= wf_TableCell($tariffName);
  619. $rows .= wf_TableRow($cells, 'row3');
  620. $cells = wf_TableCell(__('Date'), '', 'row2');
  621. $cells .= wf_TableCell($subData['date']);
  622. $rows .= wf_TableRow($cells, 'row3');
  623. $cells = wf_TableCell(__('Cash'), '', 'row2');
  624. $cells .= wf_TableCell($userData['Cash']);
  625. $rows .= wf_TableRow($cells, 'row3');
  626. $cells = wf_TableCell(__('Active'), '', 'row2');
  627. $cells .= wf_TableCell(web_bool_led($subData['active']));
  628. $rows .= wf_TableRow($cells, 'row3');
  629. $cells = wf_TableCell(__('Activation code'), '', 'row2');
  630. $cells .= wf_TableCell($subData['code']);
  631. $rows .= wf_TableRow($cells, 'row3');
  632. if ($this->altCfg['OLLTV_DEBUG']) {
  633. $cells = wf_TableCell(__('User inside'), '', 'row2');
  634. $remoteProfile = wf_tag('pre') . print_r($remoteData, true) . wf_tag('pre', true);
  635. $cells .= wf_TableCell(wf_modalAuto(__('Show'), __('User inside'), $remoteProfile));
  636. $rows .= wf_TableRow($cells, 'row3');
  637. }
  638. $result .= wf_TableBody($rows, '100%', 0);
  639. } else {
  640. $result .= $this->messages->getStyledMessage(__('Something went wrong'), 'error');
  641. }
  642. return($result);
  643. }
  644. /**
  645. * Renders some manual subscriber management controls
  646. *
  647. * @param string $login
  648. *
  649. * @return string
  650. */
  651. public function renderSubscriberControls($login) {
  652. $result = '';
  653. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_DEACTIVATE . '=' . $login, web_bool_led(false) . ' ' . __('Deactivate subscription'), false, 'ubButton') . ' ';
  654. $result .= wf_Link(self::URL_ME . '&' . self::ROUTE_ACTIVATE . '=' . $login, web_bool_led(true) . ' ' . __('Activate subscription'), false, 'ubButton') . ' ';
  655. return($result);
  656. }
  657. /**
  658. * Renders user devices if they available
  659. *
  660. * @param string $login
  661. *
  662. * @return string
  663. */
  664. public function renderUserDevices($login) {
  665. $result = '';
  666. $userDevices = $this->api->getDeviceList($login);
  667. if (!empty($userDevices)) {
  668. $cells = wf_TableCell(__('ID'));
  669. $cells .= wf_TableCell(__('Date'));
  670. $cells .= wf_TableCell(__('Serial number'));
  671. $cells .= wf_TableCell(__('MAC'));
  672. $cells .= wf_TableCell(__('Code'));
  673. $rows = wf_TableRow($cells, 'row1');
  674. foreach ($userDevices as $io => $eachDevice) {
  675. $eachDevice = $this->makeArray($eachDevice);
  676. $cells = wf_TableCell($eachDevice['ID']);
  677. $cells .= wf_TableCell($eachDevice['date_added']);
  678. $cells .= wf_TableCell($eachDevice['serial_number']);
  679. $cells .= wf_TableCell($eachDevice['mac']);
  680. $cells .= wf_TableCell($eachDevice['binding_code']);
  681. $rows .= wf_TableRow($cells, 'row5');
  682. }
  683. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  684. } else {
  685. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  686. }
  687. return($result);
  688. }
  689. /**
  690. * Sets some tariff for selected subscriber
  691. *
  692. * @param string $login
  693. * @param int $tariffId
  694. *
  695. * @return void/string on error
  696. */
  697. public function setSubTariffId($login, $tariffId) {
  698. $result = '';
  699. if (isset($this->allUsers[$login])) {
  700. $userData = $this->allUsers[$login];
  701. if (isset($this->allTariffs[$tariffId])) {
  702. $tariffData = $this->allTariffs[$tariffId];
  703. $check = $this->api->checkBundle(array('account' => $login), $tariffData['alias']);
  704. if ($check !== false) {
  705. //primary tariff management
  706. if ($tariffData['main']) {
  707. //unsubscribe old tariff if required
  708. if ($userData['tariffid']) {
  709. $oldUserTariffData = $this->allTariffs[$userData['tariffid']];
  710. $oldUserTariffAlias = $oldUserTariffData['alias'];
  711. $bundleDeleteResult = $this->api->disableBundle(array('account' => $login), $oldUserTariffAlias, 'subs_no_device');
  712. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSET TARIFF [' . $userData['tariffid'] . ']');
  713. }
  714. $bundleSetResult = $this->api->enableBundle(array('account' => $login), $tariffData['alias'], 'subs_no_device');
  715. if ($bundleSetResult) {
  716. $this->subscribersDb->where('id', '=', $userData['id']);
  717. //devices activation code here
  718. $this->subscribersDb->data('code', $bundleSetResult);
  719. //write tariff to sub profile
  720. $this->subscribersDb->data('tariffid', $tariffId);
  721. $this->subscribersDb->data('active', 1);
  722. $this->subscribersDb->save();
  723. log_register('OLLTV SUBSCRIBER (' . $login . ') SET TARIFF [' . $tariffId . ']');
  724. }
  725. } else {
  726. //Additional tariffs management
  727. if (!$userData['addtariffid']) {
  728. //user have no additional tariff now
  729. if ($userData['tariffid']) {
  730. $bundleSetResult = $this->api->enableBundle(array('account' => $login), $tariffData['alias'], 'subs_no_device');
  731. $this->subscribersDb->where('id', '=', $userData['id']);
  732. //write additional tariff to subscriber profile
  733. $this->subscribersDb->data('addtariffid', $tariffId);
  734. $this->subscribersDb->data('active', 1);
  735. $this->subscribersDb->save();
  736. log_register('OLLTV SUBSCRIBER (' . $login . ') SET ADDTARIFF [' . $tariffId . ']');
  737. } else {
  738. log_register('OLLTV SUBSCRIBER (' . $login . ') SET ADDTARIFF [' . $tariffId . '] HAVENOMAINSUB');
  739. }
  740. } else {
  741. log_register('OLLTV SUBSCRIBER (' . $login . ') SET ADDTARIFF [' . $tariffId . '] ALREADY_HAVEADDSUB');
  742. }
  743. }
  744. } else {
  745. log_register('OLLTV SUBSCRIBER (' . $login . ') TARIFF [' . $userTariffId . '] NOT_ALLOWED');
  746. $result .= 'Tariff not allowed';
  747. }
  748. } else {
  749. //unsub on empty tariff received
  750. if (empty($tariffId)) {
  751. $userTariffId = $userData['tariffid'];
  752. $userAddTariffId = $userData['addtariffid'];
  753. if (isset($this->allTariffs[$userTariffId])) {
  754. //unsubscribe additional tariff first
  755. if ($userAddTariffId) {
  756. $addTariffAlias = $this->allTariffs[$userAddTariffId]['alias'];
  757. $this->api->disableBundle(array('account' => $login), $addTariffAlias, 'subs_no_device');
  758. $this->subscribersDb->where('id', '=', $userData['id']);
  759. $this->subscribersDb->data('addtariffid', 0);
  760. $this->subscribersDb->save();
  761. log_register('OLLTV SUBSCRIBER (' . $login . ') DROP ADDTARIFF [' . $userAddTariffId . ']');
  762. }
  763. //unsubscribe primary tariff
  764. $userTariffAlias = $this->allTariffs[$userTariffId]['alias'];
  765. $bundleDeleteResult = $this->api->disableBundle(array('account' => $login), $userTariffAlias, 'subs_no_device');
  766. $this->subscribersDb->where('id', '=', $userData['id']);
  767. //devices activation code cleanup here
  768. $this->subscribersDb->data('code', '');
  769. //write tariff to sub profile
  770. $this->subscribersDb->data('tariffid', 0);
  771. $this->subscribersDb->data('active', 0);
  772. $this->subscribersDb->save();
  773. log_register('OLLTV SUBSCRIBER (' . $login . ') DROP TARIFF [' . $userTariffId . ']');
  774. } else {
  775. $result .= 'Tariff not exists';
  776. }
  777. }
  778. }
  779. } else {
  780. $result .= 'Subscriber not exists';
  781. }
  782. return($result);
  783. }
  784. /**
  785. * Suspends existing user
  786. *
  787. * @param string $login
  788. *
  789. * @return void
  790. */
  791. public function suspendSubscriber($login) {
  792. if (isset($this->allUsers[$login])) {
  793. $userData = $this->allUsers[$login];
  794. $userTariff = $userData['tariffid'];
  795. $userAddTariff = $userData['addtariffid'];
  796. if (isset($this->allTariffs[$userTariff])) {
  797. //is user active?
  798. if ($userData['active']) {
  799. //user have some additional tariff?
  800. if ($userAddTariff) {
  801. $addTariffData = $this->allTariffs[$userAddTariff];
  802. $this->api->disableBundle(array('account' => $login), $addTariffData['alias'], 'subs_negative_balance');
  803. log_register('OLLTV SUBSCRIBER (' . $login . ') SUSPEND ADDTARIFF [' . $userAddTariff . ']');
  804. }
  805. //suspend primary tariff
  806. $tariffData = $this->allTariffs[$userTariff];
  807. $bundleSuspResult = $this->api->disableBundle(array('account' => $login), $tariffData['alias'], 'subs_negative_balance');
  808. $this->subscribersDb->where('id', '=', $userData['id']);
  809. $this->subscribersDb->data('active', '0');
  810. $this->subscribersDb->save();
  811. log_register('OLLTV SUBSCRIBER (' . $login . ') SUSPEND TARIFF [' . $userTariff . ']');
  812. } else {
  813. log_register('OLLTV SUBSCRIBER (' . $login . ') SUSPEND FAIL NOT_ACTIVE');
  814. }
  815. } else {
  816. log_register('OLLTV SUBSCRIBER (' . $login . ') SUSPEND FAIL NO_TARIFF [' . $userTariff . ']');
  817. }
  818. } else {
  819. log_register('OLLTV SUBSCRIBER (' . $login . ') SUSPEND FAIL USER_NOT_EXISTS');
  820. }
  821. }
  822. /**
  823. * Unsuspends existing user
  824. *
  825. * @param string $login
  826. *
  827. * @return void
  828. */
  829. public function unsuspendSubscriber($login) {
  830. if (isset($this->allUsers[$login])) {
  831. $userData = $this->allUsers[$login];
  832. $userTariff = $userData['tariffid'];
  833. $userAddTariff = $userData['addtariffid'];
  834. if (isset($this->allTariffs[$userTariff])) {
  835. //is user suspended now?
  836. if (!$userData['active']) {
  837. //primary tariff unsuspend
  838. $tariffData = $this->allTariffs[$userTariff];
  839. $bundleSuspResult = $this->api->enableBundle(array('account' => $login), $tariffData['alias'], 'subs_renew');
  840. $this->subscribersDb->where('id', '=', $userData['id']);
  841. $this->subscribersDb->data('active', '1');
  842. $this->subscribersDb->save();
  843. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSUSPEND TARIFF [' . $userTariff . ']');
  844. //unsuspend additional tariffs?
  845. if ($userAddTariff) {
  846. $addTariffData = $this->allTariffs[$userAddTariff];
  847. $this->api->enableBundle(array('account' => $login), $addTariffData['alias'], 'subs_renew');
  848. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSUSPEND ADDTARIFF [' . $userAddTariff . ']');
  849. }
  850. //update users state
  851. $this->loadSubscribers();
  852. } else {
  853. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSUSPEND FAIL ALREADY_ACTIVE');
  854. }
  855. } else {
  856. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSUSPEND FAIL NO_TARIFF [' . $userTariff . ']');
  857. }
  858. } else {
  859. log_register('OLLTV SUBSCRIBER (' . $login . ') UNSUSPEND FAIL USER_NOT_EXISTS');
  860. }
  861. }
  862. /**
  863. * Renders JSON reply for some userstats frontend requests
  864. *
  865. * @param array $reply
  866. *
  867. * @return void
  868. */
  869. protected function jsonRenderReply($reply) {
  870. $reply = json_encode($reply);
  871. die($reply);
  872. }
  873. /**
  874. * Renders user subscription data for some login
  875. *
  876. * @param string $userLogin
  877. *
  878. * @return void
  879. */
  880. public function usReplyUserData($userLogin) {
  881. $reply = array();
  882. if (isset($this->allUsers[$userLogin])) {
  883. $reply = $this->allUsers[$userLogin];
  884. }
  885. $this->jsonRenderReply($reply);
  886. }
  887. /**
  888. * Renders available tariffs list
  889. *
  890. * @return void
  891. */
  892. public function usReplyTariffs() {
  893. $reply = array();
  894. if (!empty($this->allTariffs)) {
  895. foreach ($this->allTariffs as $io => $each) {
  896. $reply[$io] = $each;
  897. }
  898. }
  899. $this->jsonRenderReply($reply);
  900. }
  901. /**
  902. * Renders user devices list
  903. *
  904. * @param string $userLogin
  905. *
  906. * @return void
  907. */
  908. public function usReplyDevices($userLogin) {
  909. $reply = array();
  910. $userDevices = $this->api->getDeviceList($userLogin);
  911. if (!empty($userDevices)) {
  912. foreach ($userDevices as $io => $eachDevice) {
  913. $eachDevice = $this->makeArray($eachDevice);
  914. $reply[] = $eachDevice;
  915. }
  916. }
  917. $this->jsonRenderReply($reply);
  918. }
  919. /**
  920. * Just deactivates service from user account
  921. *
  922. * @param string $userLogin
  923. * @param int $tariffId
  924. *
  925. * @return void
  926. */
  927. public function usUnsubscribe($userLogin, $tariffId) {
  928. $reply = array();
  929. if (isset($this->allUsers[$userLogin])) {
  930. $userData = $this->allUsers[$userLogin];
  931. $userTariffId = $userData['tariffid'];
  932. $userAddTariffId = $userData['addtariffid'];
  933. if ($userTariffId == $tariffId OR $userAddTariffId = $tariffId) {
  934. $this->setSubTariffId($userLogin, 0);
  935. } else {
  936. log_register('OLLTV SUBSCRIBER (' . $userLogin . ') DROP TARIFF [' . $tariffId . '] FAILED [' . $userTariffId . '] MISMATCH');
  937. }
  938. }
  939. $this->jsonRenderReply($reply);
  940. }
  941. /**
  942. * Subscribes user to some service
  943. *
  944. * @param string $userLogin
  945. * @param int $tariffId
  946. *
  947. * @return void
  948. */
  949. public function usSubscribe($userLogin, $tariffId) {
  950. $reply = array();
  951. if (isset($this->allTariffs[$tariffId])) {
  952. //may be thats new user?
  953. $subscriberId = $this->getSubscriberId($userLogin);
  954. if (!$subscriberId) {
  955. $creationResult = $this->createSubscriber($userLogin);
  956. if (!empty($creationResult)) {
  957. $reply['error'] = $creationResult;
  958. }
  959. //update subscriberId
  960. $this->loadSubscribers();
  961. $subscriberId = $this->getSubscriberId($userLogin);
  962. }
  963. //subscriber exists
  964. if ($subscriberId) {
  965. $userData = $this->allUsers[$userLogin];
  966. if ($userData['active']) {
  967. //just switch tariff
  968. $tariffChangeResult = $this->setSubTariffId($userLogin, $tariffId);
  969. if (empty($tariffChangeResult)) {
  970. //charge tariff fee after
  971. $this->chargeUserFee($userLogin, $tariffId);
  972. } else {
  973. $reply['error'] = $tariffChangeResult;
  974. }
  975. } else {
  976. //user is suspended and have tariff - unsuspend it and charge tariff fee right now
  977. if (!$userData['active'] AND $userData['tariffid']) {
  978. $userCash = $this->allUsersData[$userLogin]['Cash'];
  979. $userTariff = $userData['tariffid'];
  980. $userAddTariff = $userData['addtariffid'];
  981. $tariffFee = $this->allTariffs[$tariffId]['fee'];
  982. //append additional tariff fee
  983. if ($userAddTariff) {
  984. $tariffFee += $this->allTariffs[$userAddTariff]['fee'];
  985. }
  986. //balance check
  987. if ($userCash >= $tariffFee) {
  988. //tariff is the same? Just unsuspend and charge
  989. if ($userTariff == $tariffId) {
  990. $this->unsuspendSubscriber($userLogin);
  991. //charge additional tariff fee if it assigned
  992. if ($userAddTariff) {
  993. $this->chargeUserFee($userLogin, $userAddTariff);
  994. }
  995. } else {
  996. //changing tariff to new
  997. $this->setSubTariffId($userLogin, $tariffId);
  998. }
  999. //charge fee on tariff activation
  1000. $this->chargeUserFee($userLogin, $tariffId);
  1001. } else {
  1002. $reply['error'] = 'No enought money';
  1003. log_register('OLLTV SUBSCRIBER (' . $userLogin . ') FAIL UNSUSPEND NO_MONEY');
  1004. }
  1005. } else {
  1006. //user have no tariff and not active - set him new tariff and charge fee
  1007. if (!$userData['active'] AND ! $userData['tariffid']) {
  1008. $tariffSetResult = $this->setSubTariffId($userLogin, $tariffId);
  1009. if (empty($tariffSetResult)) {
  1010. //charge tariff fee after
  1011. $this->chargeUserFee($userLogin, $tariffId);
  1012. } else {
  1013. $reply['error'] = $tariffSetResult;
  1014. }
  1015. }
  1016. }
  1017. }
  1018. } else {
  1019. $reply['error'] = 'Something went wrong - subscriber not found';
  1020. }
  1021. } else {
  1022. $reply['error'] = 'Wrong tariff';
  1023. }
  1024. $this->jsonRenderReply($reply);
  1025. }
  1026. /**
  1027. * Charges some tariff fee from existing user account
  1028. *
  1029. * @param string $userLogin
  1030. * @param int $tariffId
  1031. *
  1032. * @return void/string on error
  1033. */
  1034. public function chargeUserFee($userLogin, $tariffId) {
  1035. $result = '';
  1036. if (isset($this->allUsers[$userLogin]) AND isset($this->allUsersData[$userLogin])) {
  1037. if (isset($this->allTariffs[$tariffId])) {
  1038. $subscriberId = $this->getSubscriberId($userLogin);
  1039. $tariffFee = $this->allTariffs[$tariffId]['fee'];
  1040. zb_CashAdd($userLogin, '-' . $tariffFee, 'add', 1, 'OLLTV:' . $tariffId);
  1041. log_register('OLLTV CHARGE TARIFF [' . $tariffId . '] FEE `' . $tariffFee . '` FOR (' . $userLogin . ') AS [' . $subscriberId . ']');
  1042. } else {
  1043. log_register('OLLTV CHARGE FAIL NOTARIFF [' . $tariffId . '] FOR (' . $userLogin . ') AS [' . $subscriberId . ']');
  1044. }
  1045. } else {
  1046. log_register('OLLTV CHARGE FAIL NOUSER (' . $userLogin . ')');
  1047. }
  1048. return($result);
  1049. }
  1050. /**
  1051. * Check is tariff used by someone of existing users?
  1052. *
  1053. * @param int $tariffId
  1054. *
  1055. * @return bool
  1056. */
  1057. public function isTariffProtected($tariffId) {
  1058. $tariffId = ubRouting::filters($tariffId, 'int');
  1059. $result = false;
  1060. if (!empty($this->allUsers)) {
  1061. foreach ($this->allUsers as $io => $each) {
  1062. if ($each['tariffid'] == $tariffId) {
  1063. $result = true;
  1064. }
  1065. }
  1066. }
  1067. return($result);
  1068. }
  1069. /**
  1070. * Performs fee processing of all registered subscribers
  1071. *
  1072. * @return void
  1073. */
  1074. public function feeProcessing() {
  1075. if (!empty($this->allUsers)) {
  1076. foreach ($this->allUsers as $io => $eachSub) {
  1077. $userLogin = $eachSub['login'];
  1078. $subscriberId = $eachSub['id'];
  1079. $userTariff = $eachSub['tariffid'];
  1080. $userAddTariff = $eachSub['addtariffid'];
  1081. $userFee = 0;
  1082. if (isset($this->allUsersData[$userLogin])) {
  1083. $userCash = $this->allUsersData[$userLogin]['Cash'];
  1084. $userPassive = $this->allUsersData[$userLogin]['Passive'];
  1085. //user subscription is active now
  1086. if ($eachSub['active']) {
  1087. //user have tariff assigned
  1088. if ($userTariff) {
  1089. if (isset($this->allTariffs[$userTariff])) {
  1090. $tariffFee = $this->allTariffs[$userTariff]['fee'];
  1091. //some additional tariffs assigned?
  1092. if ($userAddTariff) {
  1093. $tariffFee += $this->allTariffs[$userAddTariff]['fee'];
  1094. }
  1095. if ($userCash >= $tariffFee AND ! $userPassive) {
  1096. //charge primary tariff
  1097. $this->chargeUserFee($userLogin, $userTariff);
  1098. //charge addiotional tariffs if assigned
  1099. if ($userAddTariff) {
  1100. $this->chargeUserFee($userLogin, $userAddTariff);
  1101. }
  1102. } else {
  1103. $this->suspendSubscriber($userLogin);
  1104. }
  1105. }
  1106. }
  1107. }
  1108. } else {
  1109. log_register('OLLTV CHARGE (' . $userLogin . ') AS [' . $subscriberId . '] FAIL MISS');
  1110. }
  1111. }
  1112. }
  1113. }
  1114. }