Esempio n. 1
0
 public function checkAccess($transaction, $access, $deny = false)
 {
     //mdump($transaction);
     //mdump('--------------------');
     //mdump($access);
     $module = Manager::getModule();
     $ok = false;
     if (!is_numeric($access)) {
         $access = $this->access[$access];
     }
     if ($this->auth->isLogged()) {
         $login = $this->auth->getLogin();
         // MLogin object
         $transaction = strtoupper($transaction);
         // Transaction name
         $isAdmin = $login->isAdmin();
         // Is administrator?
         $rights = (int) $login->getRights($transaction);
         // user rights
         $rightsInAll = (int) $login->getRights('ALL');
         // user rights in all transactions
         $ok = ($rights & $access) == $access || ($rightsInAll & $access) == $access || $isAdmin;
         if (!$ok && $deny) {
             $msg = _M('Acesso Negado') . "<br><br>\n" . "<center><big><i><font color=red>" . _M('Transação: ') . "{$transaction}</font></i></big></center><br><br>\n" . _M('Informe um login válido para acessar esta página.') . "<br>";
             //$go = Manager::getCurrentURL();
             //$error = MPrompt::error($msg, $go, $caption, '');
             //Manager::prompt($error, $deny);
             throw new \Maestro\Services\ESecurityException($msg);
         }
     } else {
         if ($deny) {
             $currentUrl = urlencode(\Manager::getCurrentURL());
             $module = Manager::getConf('maestro.login.module');
             $url = Manager::getURL("{$module}/main.login", array('return_to' => $currentUrl));
             Manager::getPage()->redirect($url);
         }
     }
     return $ok;
 }
Esempio n. 2
0
 public function getService($service, $module = '')
 {
     $service = MApp::getService(Manager::getApp(), $module == '' ? Manager::getModule() : $module, $service);
     $service->setData();
     return $service;
 }
Esempio n. 3
0
 public function buildURL($action = '', $parameters = array())
 {
     $app = Manager::getApp();
     $module = Manager::getModule();
     if ($action[0] == '@') {
         $url = Manager::getAppURL($app);
         $action = substr($action, 1);
     } elseif ($action[0] == '>') {
         $url = Manager::getAppURL($app);
         $action = substr($action, 1);
     } elseif ($action[0] == '#') {
         $url = Manager::getStaticURL();
         $action = substr($action, 1);
     } else {
         $url = Manager::getAppURL($app);
     }
     $path = '';
     $parts = explode('/', $action);
     $i = 0;
     $n = count($parts);
     if ($parts[$i] == $app) {
         ++$i;
         --$n;
     }
     if ($n == 3) {
         //module
         $path = '/' . $parts[$i] . '/' . $parts[$i + 1] . '/' . $parts[$i + 2];
     } elseif ($n == 2) {
         $path = '/' . $parts[$i] . '/' . $parts[$i + 1];
     } elseif ($n == 1) {
         $path = '/' . $parts[$i];
     } else {
         throw new EMException(_M('Error building URL. Action = ' . $action));
     }
     if (count($parameters)) {
         $query = http_build_query($parameters);
         $path .= (strpos($path, '?') === false ? '?' : '') . $query;
     }
     $url .= $path;
     return $url;
 }