/** * генерация отчета * * @param $type * @param $params */ public static function generate($params) { if (empty($params['type']) || !in_array($params['type'], array_keys(Model_Report::$reportTypes)) || empty($params['contract_id'])) { return false; } $config = Kohana::$config->load('jasper'); $client = new Client($config['host'], $config['login'], $config['password']); $controls = self::_prepareControls($params); $format = empty($params['format']) ? 'xls' : $params['format']; $type = self::$reportTypes[$params['type']]; if ($params['type'] == self::REPORT_TYPE_BILL) { $user = Auth_Oracle::instance()->get_user(); $type = str_replace('ru/aN', 'ru/a' . $user['AGENT_ID'], $type); } $report = $client->reportService()->runReport('/reports/' . $type, $format, null, null, $controls); $name = 'report_' . $params['type'] . '_' . date('Y_m_d') . '.' . $format; $headers = self::$formatHeaders[$format]; foreach ($headers as &$header) { $header = str_replace('__NAME__', $name, $header); } return ['report' => $report, 'headers' => $headers]; }
/** * функция проверки доступа */ public static function allow($action) { if (empty($action)) { return true; } $user = Auth_Oracle::instance()->get_user(); if (in_array($user['role'], [self::ROLE_ROOT])) { return true; } $access = Kohana::$config->load('access')->as_array(); $allow = $access['allow']; $deny = $access['deny']; if (isset($allow[$action]) && (!in_array($user['role'], $allow[$action]) && !in_array('u_' . $user['MANAGER_ID'], $allow[$action]) && !in_array('a_' . $user['AGENT_ID'], $allow[$action])) || isset($deny[$action]) && (in_array($user['role'], $deny[$action]) || in_array('u_' . $user['MANAGER_ID'], $deny[$action]) || in_array('a_' . $user['AGENT_ID'], $deny[$action]))) { return false; } //если нет явного запрета или наоборот, доступа только конкретной роли return true; }
/** * прописываем глобальные конфиги * * @throws Kohana_Exception */ public function after() { $this->_appendFiles(); if (!$this->request->is_ajax()) { $this->_appendFilesAfter(); } View::set_global('user', Auth_Oracle::instance()->get_user()); $config = Kohana::$config->load('main')->as_array(); foreach ($config as $k => $v) { View::set_global($k, $v); } View::set_global('title', implode(" :: ", $this->title)); View::set_global('errors', $this->errors); if (Auth::instance()->logged_in()) { View::set_global('notices', Model_Message::getList(['not_read' => true])); } $this->template->content = $this->tpl; parent::after(); }