1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- Lib::loadClass('RouteToolBase');
- Lib::loadClass('UI');
- Lib::loadClass('Response');
- Lib::loadClass('Theme');
- require_once dirname(__FILE__) . '/../auth.php'; // Theme_Auth_panel_biall_net
- // class name must have the same name as file
- // index.php?_route=UrlAction_ChangeUser - uruchamia defaultAction
- class RouteTool_ChangeUser extends RouteToolBase {
- function handleAuth() {
- $idAdmin = V::get('id_admin', '', $_GET);
- if ($idAdmin && User::isAdmin()) return $this->handleRootAuth($idAdmin);
- $id = V::get('id', '', $_POST);
- $authIds = (!empty($_SESSION['PANEL_BN_USERS'])) ? array_map(V::makePick('ID'), $_SESSION['PANEL_BN_USERS']) : [];
- // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser to({$id}) ids:[".implode(",", $authIds)."]", E_USER_NOTICE);
- if (!$id || !in_array($id, $authIds)) {
- return Response::sendRedirect( "index.php" );
- }
- foreach ($_SESSION['PANEL_BN_USERS'] as $item) {
- if ($id != $item['ID']) continue;
- // trigger_error(date("Y-m-d H:i:s") . "\t" . "panel_bn/RouteTool_ChangeUser changed to({$id})", E_USER_NOTICE);
- @session_start();
- $_SESSION['ADM_ID'] = $item['ID'];
- // 'ADM_ACCOUNT' => $item['LOGIN'], // AUTHORIZE_USER, ADM_ACCOUNT
- $_SESSION['ADM_NAME'] = implode(" ", [ $item['P_NAME'], $item['P_NAME_SECOND'] ]); // ADM_NAME
- $_SESSION['ADM_COMPANY'] = $item['BILLING_OWNER']; // ADM_COMPANY
- session_write_close();
- sleep(1);
- // 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);
- }
- return Response::sendRedirect( "index.php" );
- }
- function handleRootAuth($idAdmin) {
- if (!User::isAdmin()) {
- return Response::sendRedirect( "index.php" );
- }
- // 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);
- $_SESSION['PANEL_BN_USERS'] = [];
- $_SESSION['PANEL_BN_USERS'][] = [
- 'ID' => User::getID(),
- 'LOGIN' => User::getLogin(),
- 'P_NAME' => User::getName(),
- 'P_NAME_SECOND' => '',
- 'BILLING_OWNER' => '3', // BN
- ];
- $userInfo = DB::getPDO()->fetchFirst("
- select
- c.ID as `ID`
- , c.user_mail_contact as `LOGIN`
- , c.P_NAME as `P_NAME`
- , c.P_NAME_SECOND as `P_NAME_SECOND`
- , c.BILLING_OWNER as `BILLING_OWNER`
- from COMPANIES as c
- where c.ID = :id
- ", [
- ':id' => $idAdmin,
- ]);
- $_SESSION['PANEL_BN_USERS'][] = $userInfo;
- // 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);
- $_SESSION['PANEL_BN_USER_SELECTED'] = $idAdmin;
- // $_SESSION['ADM_ID'] = $userInfo['ID'];
- // // 'ADM_ACCOUNT' => $userInfo['LOGIN'], // AUTHORIZE_USER, ADM_ACCOUNT
- // $_SESSION['ADM_NAME'] = implode(" ", [ $userInfo['P_NAME'], $userInfo['P_NAME_SECOND'] ]); // ADM_NAME
- // $_SESSION['ADM_COMPANY'] = $userInfo['BILLING_OWNER']; // ADM_COMPANY
- session_write_close();
- // 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);
- sleep(1);
- return Response::sendRedirect( "index.php" );
- }
- function defaultAction() {
- UI::gora();
- echo '<h1>ChangeUser Tool</h1>';
- UI::dol();
- }
- }
|