184 lines
4.3 KiB
PHP
Executable File
184 lines
4.3 KiB
PHP
Executable File
<?php declare(strict_types=1);
|
|
namespace IR\App\Controllers;
|
|
if (!defined("IR_START")) {
|
|
exit("<pre>No direct script access allowed</pre>");
|
|
}
|
|
/**
|
|
* @framework iResponse Framework
|
|
* @version 1.0
|
|
* @author Amine Idrissi <contact@iresponse.tech>
|
|
* @date 2019
|
|
* @name Tools.php
|
|
*/
|
|
|
|
# defaults
|
|
use \DOMDocument;
|
|
|
|
# core
|
|
use IR\Core\Application as Application;
|
|
|
|
# mvc
|
|
use IR\Mvc\Controller as Controller;
|
|
|
|
# models
|
|
use IR\App\Models\Admin\ServerVmta as ServerVmta;
|
|
|
|
# http
|
|
use IR\Http\Request as Request;
|
|
|
|
# helpers
|
|
use IR\App\Helpers\Authentication as Authentication;
|
|
use IR\App\Helpers\DataTable;
|
|
use IR\App\Helpers\Page as Page;
|
|
use IR\App\Helpers\Permissions as Permissions;
|
|
use IR\App\Models\Admin\OfficeAccount;
|
|
use IR\App\Models\Admin\OfficeAccountAdmin;
|
|
use IR\App\Models\Admin\ServerProvider;
|
|
# exceptions
|
|
use IR\Exceptions\Types\PageException as PageException;
|
|
use IR\Logs\Logger;
|
|
|
|
/**
|
|
* @name Tools
|
|
* @description Tools Controller
|
|
*/
|
|
class OfficeAdmins extends Controller
|
|
{
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $app;
|
|
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
protected $authenticatedUser;
|
|
|
|
/**
|
|
* @name init
|
|
* @description initializing process before the action method executed
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function init()
|
|
{
|
|
# set the current application to a local variable
|
|
$this->app = Application::getCurrent();
|
|
|
|
# connect to the database
|
|
$this->app->database("system")->connect();
|
|
|
|
# check for authentication
|
|
if (!Authentication::isUserAuthenticated()) {
|
|
Page::redirect(
|
|
$this->app->http->request->getBaseURL() .
|
|
RDS .
|
|
"auth" .
|
|
RDS .
|
|
"login." .
|
|
DEFAULT_EXTENSION
|
|
);
|
|
}
|
|
|
|
# check users roles
|
|
Authentication::checkUserRoles();
|
|
|
|
# get the authenticated user
|
|
$this->authenticatedUser = Authentication::getAuthenticatedUser();
|
|
}
|
|
|
|
/**
|
|
* @name edit
|
|
* @description the edit action
|
|
* @before init
|
|
* @after closeConnections,checkForMessage
|
|
*/
|
|
public function edit()
|
|
{
|
|
# check for permissions
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
|
|
if ($access == false) {
|
|
throw new PageException('Access Denied !', 403);
|
|
}
|
|
|
|
$arguments = func_get_args();
|
|
$id = isset($arguments) && count($arguments) > 0 ? $arguments[0] : null;
|
|
$valid = true;
|
|
|
|
if (!isset($id) || !is_numeric($id) || intval($id) == 0) {
|
|
$valid = false;
|
|
}
|
|
|
|
$officeAdmin = OfficeAccountAdmin::first(OfficeAccountAdmin::FETCH_ARRAY, ['id = ?', $id]);
|
|
|
|
|
|
if (count($officeAdmin) == 0) {
|
|
$valid = false;
|
|
}
|
|
|
|
if ($valid == true)
|
|
{
|
|
# set menu status
|
|
$this->masterView->set([
|
|
'tools' => 'true',
|
|
'office_365'=> 'true',
|
|
'show_OfficeAdmin' => 'true'
|
|
]);
|
|
# set data to the page view
|
|
$this->pageView->set([
|
|
'officeAdmin' => $officeAdmin
|
|
]);
|
|
}
|
|
else
|
|
{
|
|
|
|
# stores the message in the session
|
|
Page::registerMessage('error', 'Invalid affiliate network id !');
|
|
|
|
# redirect to lists page
|
|
Page::redirect();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* @name closeConnections
|
|
* @description close all connections
|
|
* @once
|
|
* @protected
|
|
*/
|
|
|
|
/** @name add @description the add action @before init @after closeConnections,checkForMessage */
|
|
public function add()
|
|
{
|
|
$access = Permissions::checkForAuthorization($this->authenticatedUser, __CLASS__, __FUNCTION__);
|
|
if($access == false) { throw new PageException('Access Denied !', 403); }
|
|
$this->masterView->set(['exchange' => 'true', 'office_admins' => 'true', 'office_admins_add' => 'true']);
|
|
}
|
|
|
|
public function closeConnections()
|
|
{
|
|
# connect to the database
|
|
$this->app->database("system")->disconnect();
|
|
$this->app->database("clients")->disconnect();
|
|
}
|
|
|
|
/**
|
|
* @name checkForMessage
|
|
* @description checks for session messages
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function checkForMessage()
|
|
{
|
|
# check for message
|
|
Page::checkForMessage($this);
|
|
}
|
|
}
|