PanelKlientaBiallNet.php 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('Request');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('UI');
  6. class Route_UrlAction_PanelKlientaBiallNet extends RouteBase {
  7. static $PANEL_URL = "https://biuro.biall-net.pl/panel/pl/index.php?_route=UrlAction_ChangeUser&id_admin={id}";
  8. static $PANEL_DEV_URL = "https://biuro.biall-net.pl/dev-pl/se-projects/panel_biall_net/SE/index.php?_route=UrlAction_ChangeUser&id_admin={id}";
  9. function defaultAction() { UI::layout([ $this, 'defaultView' ]); }
  10. function defaultView() {
  11. $id = V::get('id', '', $_GET);
  12. if (!$id) throw new Exception("Missing id");
  13. $devPrefix = 'https://biuro.biall-net.pl/dev-pl';
  14. $panelUrl = str_replace('{id}', $id, self::$PANEL_URL);
  15. // Response::sendRedirect( str_replace('{id}', $id, $panelUrl) );
  16. $devPanelUrl = str_replace('{id}', $id, self::$PANEL_DEV_URL);
  17. $projectFolder = APP_PATH_ROOT . DS . 'projects' . DS . 'panel_biall_net';
  18. if (!file_exists($projectFolder)) throw new Exception("Project folder not exists! ('panel_biall_net')");
  19. if (!file_exists($projectFolder . DS . 'auth.php')) throw new Exception("Project auth file not exists! ('panel_biall_net')");
  20. require_once $projectFolder . DS . 'auth.php'; // Theme_Auth_panel_biall_net
  21. if (!class_exists('Theme_Auth_panel_biall_net')) throw new Exception("Project auth class not exists! ('panel_biall_net')");
  22. $company = DB::getPDO()->fetchFirst("
  23. select c.ID
  24. , c.user_mail_contact
  25. , c.P_NAME, c.P_NAME_SECOND
  26. from COMPANIES c
  27. where c.ID = :id
  28. ", [ ':id' => $id ]);
  29. if (!$company) throw new Exception("Company not exists! Nr {$id}.");
  30. if (!User::isAdmin()) throw new Exception("Access Denied");
  31. $email = $company['user_mail_contact'];
  32. $postTask = V::get('_postTask', '', $_POST);
  33. $_testUserInfo = null;
  34. switch ($postTask) {
  35. // case 'makeAccounts': {
  36. // Theme_Auth_panel_biall_net::makeActiveUsers($email);
  37. // } break;
  38. // case 'resetPasswd': {
  39. // Theme_Auth_panel_biall_net::makeActiveUsers($email);
  40. // $remindKey = Theme_Auth_panel_biall_net::generateRemindKey($email);
  41. // $resetLink = Router::getRoute('UrlAction_RemindPasswd')->getLink('rp', [ 'login' => $email, 'key' => $remindKey ]);
  42. // Theme_Auth_panel_biall_net::sendRemindPasswd($email, $resetLink, $recipient = "piotrl86+bn-test-remind@gmail.com");
  43. // } break;
  44. case 'testAuth': {
  45. $passwd = V::get('passwd', '', $_POST);
  46. $_testUserInfo = Theme_Auth_panel_biall_net::testAuth($email, $passwd);
  47. } break;
  48. }
  49. $activeUsers = Theme_Auth_panel_biall_net::makeActiveUsers($company['user_mail_contact']);
  50. echo UI::h('div', [ 'style' => "margin-top:24px" ], [
  51. UI::h('h3', [], "Klient: [{$company['ID']}] {$company['P_NAME']} {$company['P_NAME_SECOND']}"),
  52. UI::h('a', [ 'href' => $panelUrl, 'target' => "_blank", 'class' => "btn btn-primary" ], "Zobacz panel klienta"),
  53. ($devPrefix === substr(Request::getScriptUri(), 0, strlen($devPrefix)))
  54. ? UI::h('a', [ 'href' => $devPanelUrl, 'target' => "_blank", 'class' => "btn btn-warning" ], "DEV: panel klienta")
  55. : "",
  56. UI::h('form', [ 'method' => "POST", 'class' => "form-horizontal", 'style' => "margin:24px 0; padding: 24px; border:1px solid #eee" ], [
  57. UI::h('input', [ 'type' => "hidden", 'name' => "email", 'value' => $email ]),
  58. UI::h('label', [ 'class' => "col-md-1 control-label" ], "Hasło:"),
  59. UI::h('div', [ 'method' => "POST", 'class' => "col-md-4" ], [
  60. UI::h('input', [ 'type' => "text", 'name' => "passwd", 'value' => '', 'class' => "form-control" ]),
  61. ]),
  62. UI::h('input', [ 'type' => "hidden", 'name' => "_postTask", 'value' => 'testAuth' ]),
  63. UI::h('input', [ 'type' => "submit", 'value' => "Testuj logowanie do panelu klienta", 'class' => "btn btn-default" ]),
  64. ($_testUserInfo)
  65. ? UI::h('div', [ 'class' => "alert alert-success" ], [
  66. UI::h('p', [], "Klient: [{$_testUserInfo['ID']}] '{$_testUserInfo['P_NAME']} {$_testUserInfo['P_NAME_SECOND']}'"),
  67. ])
  68. : UI::h('div', [], "..."),
  69. ]),
  70. UI::h('p', [], "All users:"),
  71. UI::hTable([
  72. 'rows' => array_map(function ($item) {
  73. return array_merge([
  74. 'ID' => $item['ID'],
  75. 'Akcja' => UI::h('a', [ 'href' => $this->getLink('', [ 'id' => $item['ID'] ]) ], "wybierz"),
  76. ], $item);
  77. }, Theme_Auth_panel_biall_net::test_fetchAllUsers($email))
  78. ]),
  79. UI::h('p', [], "Active BIALL-NET users (BILLING_OWNER: 1 BN, 3 NETDAY):"),
  80. UI::hTable([ 'rows' => Theme_Auth_panel_biall_net::fetchActiveUsers($email) ]),
  81. ]);
  82. }
  83. }