ChangeUser.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. Lib::loadClass('RouteToolBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('Theme');
  6. require_once dirname(__FILE__) . '/../auth.php'; // Theme_Auth_panel_biall_net
  7. // class name must have the same name as file
  8. // index.php?_route=UrlAction_ChangeUser - uruchamia defaultAction
  9. class RouteTool_ChangeUser extends RouteToolBase {
  10. function handleAuth() {
  11. $idAdmin = V::get('id_admin', '', $_GET);
  12. if ($idAdmin && User::isAdmin()) return $this->handleRootAuth($idAdmin);
  13. $id = V::get('id', '', $_POST);
  14. $authIds = (!empty($_SESSION['PANEL_BN_USERS'])) ? array_map(V::makePick('ID'), $_SESSION['PANEL_BN_USERS']) : [];
  15. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser to({$id}) ids:[".implode(",", $authIds)."]", E_USER_NOTICE);
  16. if (!$id || !in_array($id, $authIds)) {
  17. return Response::sendRedirect( "index.php" );
  18. }
  19. foreach ($_SESSION['PANEL_BN_USERS'] as $item) {
  20. if ($id != $item['ID']) continue;
  21. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser changed to({$id})", E_USER_NOTICE);
  22. @session_start();
  23. $_SESSION['ADM_ID'] = $item['ID'];
  24. // 'ADM_ACCOUNT' => $item['LOGIN'], // AUTHORIZE_USER, ADM_ACCOUNT
  25. $_SESSION['ADM_NAME'] = implode(" ", [ $item['P_NAME'], $item['P_NAME_SECOND'] ]); // ADM_NAME
  26. $_SESSION['ADM_COMPANY'] = $item['BILLING_OWNER']; // ADM_COMPANY
  27. session_write_close();
  28. sleep(1);
  29. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser ses: { ID: {$_SESSION['ID']}, ADM_NAME: {$_SESSION['ADM_NAME']} }", E_USER_NOTICE);
  30. }
  31. return Response::sendRedirect( "index.php" );
  32. }
  33. function handleRootAuth($idAdmin) {
  34. if (!User::isAdmin()) {
  35. return Response::sendRedirect( "index.php" );
  36. }
  37. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser root: { ID: {$_SESSION['ID']}, ADM_NAME: {$_SESSION['ADM_NAME']} }", E_USER_NOTICE);
  38. $_SESSION['PANEL_BN_USERS'] = [];
  39. $_SESSION['PANEL_BN_USERS'][] = [
  40. 'ID' => User::getID(),
  41. 'LOGIN' => User::getLogin(),
  42. 'P_NAME' => User::getName(),
  43. 'P_NAME_SECOND' => '',
  44. 'BILLING_OWNER' => '3', // BN
  45. ];
  46. $userInfo = DB::getPDO()->fetchFirst("
  47. select
  48. c.ID as `ID`
  49. , c.user_mail_contact as `LOGIN`
  50. , c.P_NAME as `P_NAME`
  51. , c.P_NAME_SECOND as `P_NAME_SECOND`
  52. , c.BILLING_OWNER as `BILLING_OWNER`
  53. from COMPANIES as c
  54. where c.ID = :id
  55. ", [
  56. ':id' => $idAdmin,
  57. ]);
  58. $_SESSION['PANEL_BN_USERS'][] = $userInfo;
  59. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser root ses bn users: " . json_encode($_SESSION['PANEL_BN_USERS']), E_USER_NOTICE);
  60. $_SESSION['PANEL_BN_USER_SELECTED'] = $idAdmin;
  61. // $_SESSION['ADM_ID'] = $userInfo['ID'];
  62. // // 'ADM_ACCOUNT' => $userInfo['LOGIN'], // AUTHORIZE_USER, ADM_ACCOUNT
  63. // $_SESSION['ADM_NAME'] = implode(" ", [ $userInfo['P_NAME'], $userInfo['P_NAME_SECOND'] ]); // ADM_NAME
  64. // $_SESSION['ADM_COMPANY'] = $userInfo['BILLING_OWNER']; // ADM_COMPANY
  65. session_write_close();
  66. // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser root/ses: { ID: {$_SESSION['ID']}, ADM_NAME: {$_SESSION['ADM_NAME']} }", E_USER_NOTICE);
  67. sleep(1);
  68. return Response::sendRedirect( "index.php" );
  69. }
  70. function defaultAction() {
  71. UI::gora();
  72. echo '<h1>ChangeUser Tool</h1>';
  73. UI::dol();
  74. }
  75. }