/**
  * (non-PHPdoc)
  * @see FrontController::loadModule()
  */
 public function loadModule()
 {
     $resolver = new Resolver($this->getRequest());
     // load the responsible extension
     common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId());
     \Context::getInstance()->setExtensionName($resolver->getExtensionId());
     //if the controller is a rest controller we try to authenticate the user
     $controllerClass = $resolver->getControllerClass();
     if (is_subclass_of($controllerClass, 'tao_actions_CommonRestModule')) {
         $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest());
         try {
             $user = $authAdapter->authenticate();
             $session = new \common_session_RestSession($user);
             \common_session_SessionManager::startSession($session);
         } catch (\common_user_auth_AuthFailedException $e) {
             $class = new $controllerClass();
             $class->requireLogin();
         }
     }
     try {
         $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $this->getRequest()->getParams());
         $enforcer->execute();
     } catch (InterruptedActionException $iE) {
         // Nothing to do here.
     }
 }
 public function redirect($url, $statusCode = 302)
 {
     $context = Context::getInstance();
     header(HTTPToolkit::statusCodeHeader($statusCode));
     header(HTTPToolkit::locationHeader($url));
     throw new InterruptedActionException('Interrupted action after a redirection', $context->getModuleName(), $context->getActionName());
 }
Example #3
0
 public static function outputFile($relPath, $filename = null)
 {
     $fullpath = self::getExportPath() . DIRECTORY_SEPARATOR . $relPath;
     if (tao_helpers_File::securityCheck($fullpath, true) && file_exists($fullpath)) {
         Context::getInstance()->getResponse()->setContentHeader(tao_helpers_File::getMimeType($fullpath));
         $fileName = empty($filename) ? basename($fullpath) : $filename;
         header('Content-Disposition: attachment; fileName="' . $fileName . '"');
         header("Content-Length: " . filesize($fullpath));
         //Clean all levels of output buffering
         while (ob_get_level() > 0) {
             ob_end_clean();
         }
         flush();
         $fp = fopen($fullpath, "r");
         if ($fp !== false) {
             while (!feof($fp)) {
                 echo fread($fp, 65536);
                 flush();
             }
             fclose($fp);
             @unlink($fullpath);
         } else {
             common_Logger::e('Unable to open File to export' . $fullpath);
         }
     } else {
         common_Logger::e('Could not find File to export: ' . $fullpath);
     }
 }
 private function __getTemplate($content)
 {
     $oContext = Context::getInstance();
     $oTemplate = new Template('site/searchPages.tpl.php');
     $oTemplate->pages = $content;
     return $oTemplate->parse();
 }
 /**
  * render the main layout
  *
  * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu}
  */
 public function index()
 {
     if ($this->hasRequestParameter('openFolder')) {
         $folder = $this->getRequestParameter('openFolder');
         if (tao_helpers_File::securityCheck($folder, true)) {
             $folder = preg_replace('/^\\//', '', $folder);
             $folder = preg_replace('/\\/$/', '', $folder);
             $this->setData('openFolder', $folder);
         }
     }
     if ($this->hasRequestParameter('urlData')) {
         $this->setData('urlData', $this->getRequestParameter('urlData'));
     }
     if ($this->hasRequestParameter('error')) {
         $this->setData('error', $this->getRequestParameter('error'));
     }
     // Show select action?
     $this->setData('showSelect', false);
     if ($this->hasRequestParameter('showselect') && $this->getRequestParameter('showselect') == '1') {
         $this->setData('showSelect', true);
     }
     //creates the URL of the action used to configure the client side
     $context = Context::getInstance();
     $clientConfigParameters = array('extension' => $context->getExtensionName(), 'module' => $context->getModuleName(), 'action' => $context->getActionName());
     $this->setData('client_config_url', _url('config', 'ClientConfig', 'tao', $clientConfigParameters));
     $this->setData('upload_limit', $this->getFileUploadLimit());
     $this->setView('index.tpl');
 }
Example #6
0
 /**
  * Run the controller
  * 
  * @param common_http_Request $pRequest
  * @throws \ActionEnforcingException
  * @throws \Exception
  * @throws \common_exception_Error
  * @throws \common_ext_ExtensionException
  */
 public function legacy(common_http_Request $pRequest)
 {
     $resolver = new Resolver($pRequest);
     // load the responsible extension
     $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId());
     \Context::getInstance()->setExtensionName($resolver->getExtensionId());
     // load translations
     $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage();
     \tao_helpers_I18n::init($ext, $uiLang);
     //if the controller is a rest controller we try to authenticate the user
     $controllerClass = $resolver->getControllerClass();
     if (is_subclass_of($controllerClass, \tao_actions_RestController::class)) {
         $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest());
         try {
             $user = $authAdapter->authenticate();
             $session = new \common_session_RestSession($user);
             \common_session_SessionManager::startSession($session);
         } catch (\common_user_auth_AuthFailedException $e) {
             $data['success'] = false;
             $data['errorCode'] = '401';
             $data['errorMsg'] = 'You are not authorized to access this functionality.';
             $data['version'] = TAO_VERSION;
             header('HTTP/1.0 401 Unauthorized');
             header('WWW-Authenticate: Basic realm="' . GENERIS_INSTANCE_NAME . '"');
             echo json_encode($data);
             exit(0);
         }
     }
     try {
         $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $pRequest->getParams());
         $enforcer->execute();
     } catch (InterruptedActionException $iE) {
         // Nothing to do here.
     }
 }
Example #7
0
 /**
  * Prepare runtime context - tell DB class that current DB is CUBRID
  */
 protected function setUp()
 {
     $oContext =& Context::getInstance();
     $db_info->master_db = array('db_type' => 'sqlite3_pdo', 'db_table_prefix' => 'xe_');
     $db_info->slave_db = array(array('db_type' => 'sqlite3_pdo', 'db_table_prefix' => 'xe_'));
     $oContext->setDbInfo($db_info);
     DB::getParser(true);
 }
Example #8
0
 public function __construct()
 {
     $this->context = Context::getInstance();
     $this->_helper = new ViewHelper();
     $date = date('m');
     $this->headerImg = 'MLink/images/structure/';
     $this->headerImg .= 'newheader.png';
 }
 public function delete()
 {
     $context = Context::getInstance();
     $role = $this->checkAccess($context->user);
     if ($role <= Acl::READER) {
         throw new PermissionDenied("No permission to delete");
     }
     parent::delete();
 }
Example #10
0
 public static function getInstance()
 {
     if (empty(self::$_instance)) {
         $db = new Db();
         $context = Context::getInstance();
         self::$_instance = new self($db, $context);
     }
     return self::$_instance;
 }
 public function loadModule()
 {
     $enforcer = new RoutingActionEnforcer(Context::getInstance());
     try {
         $enforcer->execute();
     } catch (InterruptedActionException $iE) {
         // Nothing to do here.
     }
 }
Example #12
0
 /**
  * Prepare runtime context - tell DB class that current DB is CUBRID
  */
 protected function setUp()
 {
     $oContext =& Context::getInstance();
     $db_info->master_db = array('db_type' => 'cubrid', 'db_table_prefix' => 'xe_');
     $db_info->slave_db = array(array('db_type' => 'cubrid', 'db_table_prefix' => 'xe_'));
     $oContext->setDbInfo($db_info);
     $db = new MockDb();
     $db->getParser(true);
 }
Example #13
0
 function AllTests()
 {
     $oContext =& Context::getInstance();
     $oContext->init();
     $this->TestSuite('Classes Test');
     $this->addFile(dirname(__FILE__) . '/classes/context/Context.test.php');
     $this->TestSuite('Module Test');
     $this->addFile(dirname(__FILE__) . '/modules/module/module.test.php');
     $this->addFile(dirname(__FILE__) . '/modules/module/opage.test.php');
 }
 public function ltiOverview()
 {
     //creates the URL of the action used to configure the client side
     $context = \Context::getInstance();
     $clientConfigParameters = array('extension' => $context->getExtensionName(), 'module' => $context->getModuleName(), 'action' => $context->getActionName());
     $this->setData('client_config_url', _url('config', 'ClientConfig', 'tao', $clientConfigParameters));
     $this->setData('delivery', $this->getRequestParameter('delivery'));
     $this->setData('allowRepeat', true);
     $this->setView('learner/overview.tpl');
 }
 public static function setCookieToken(User $user, $salt)
 {
     $instance = new UserToken();
     $instance->sid = $salt;
     $instance->uid = $user->id;
     $instance->save(true);
     $cookie_val = sprintf('%s_%s_%s', $instance->uid, $instance->sid, $instance->token);
     $context = Context::getInstance();
     $context->session->set_cookie('frmauth', $cookie_val, time() + 60 * 60 * 24 * 30);
 }
 /**
  * 
  * @access
  * @author "Lionel Lecaque, <*****@*****.**>"
  */
 function loadModule()
 {
     //with or without extiontion ActionEnforcer or ExtensionActionEnforcer;
     $enforcer = new ActionEnforcer(Context::getInstance());
     try {
         $enforcer->execute();
     } catch (InterruptedActionException $iE) {
         // Nothing to do here.
     }
 }
 public static function getAllLanguages()
 {
     if (is_null(Language::$langs)) {
         $context = Context::getInstance();
         $oLang = Language::getLanguageById($context->session->lang);
         $order = sprintf("(CASE WHEN id=%d THEN 0 ELSE 1 END)", $oLang->id);
         $rs = Identifiable::getAllItemsByTable(new Language(), $order);
         Language::$langs = new ObjectSet($rs, __CLASS__);
     }
     return Language::$langs;
 }
 public static function getIndexTemplate()
 {
     $context = Context::getInstance();
     $oIndex = new Template('admin/ui.index.tpl');
     $oIndex->navbar = Admin::getNavBar();
     $oIndex->user = $context->user->username;
     if ($context->user->id == User::ADMIN) {
         $oIndex->sections = '<li><a href="/admin/modules">Admin Panel</a></li>';
     }
     return $oIndex;
 }
Example #19
0
 /**
  * Prepare runtime context - tell DB class that current DB is CUBRID
  */
 protected function setUp()
 {
     $this->markTestSkipped();
     $oContext =& Context::getInstance();
     $db_info->master_db = array('db_type' => 'cubrid', 'db_port' => '33000', 'db_hostname' => '10.0.0.206', 'db_userid' => 'dba', 'db_password' => 'arniarules', 'db_database' => 'xe15QA', 'db_table_prefix' => 'xe_');
     $db_info->slave_db = array(array('db_type' => 'cubrid', 'db_port' => '33000', 'db_hostname' => '10.0.0.206', 'db_userid' => 'dba', 'db_password' => 'arniarules', 'db_database' => 'xe15QA', 'db_table_prefix' => 'xe_'));
     $oContext->setDbInfo($db_info);
     // remove cache dir
     FileHandler::removeDir(_XE_PATH_ . 'files/cache');
     DB::getParser(true);
 }
 public function delete($id)
 {
     if ($id == User::ADMIN || $id == User::GUEST) {
         $context = Context::getInstance();
         $context->response->httpCode = 403;
         $context->response->body = 'Permission denied';
         $context->response->write();
     }
     $user = User::getUserById($id);
     $user->delete();
     return true;
 }
 /**
  * @deprecated use \oat\tao\model\requiredAction\implementation\RequiredActionRedirectUrlPart instead
  *
  * Execute an action
  * @param array $params
  * @return mixed
  */
 public function execute(array $params = [])
 {
     $context = \Context::getInstance();
     $excludedRoutes = $this->getExcludedRoutes();
     $currentRoute = ['extension' => $context->getExtensionName(), 'module' => $context->getModuleName(), 'action' => $context->getActionName()];
     if (!in_array($currentRoute, $excludedRoutes)) {
         $currentUrl = \common_http_Request::currentRequest()->getUrl();
         $url = $this->url . (parse_url($this->url, PHP_URL_QUERY) ? '&' : '?') . 'return_url=' . urlencode($currentUrl);
         $flowController = new FlowController();
         $flowController->redirect($url);
     }
 }
 public function delete($id)
 {
     if ($id == Group::ADMINS || $id == Group::EVERYONE || $id == Group::AUTHUSERS) {
         $context = Context::getInstance();
         $context->response->httpCode = 403;
         $context->response->body = 'Permission denied';
         $context->response->write();
     }
     $group = Group::getGroupById($id);
     $group->delete();
     return true;
 }
Example #23
0
 public static function dateTimeFormat($date, $timezone = 'GMT')
 {
     $context = Context::getInstance();
     $lang = Language::getLanguageById($context->session->lang);
     $fromTimezone = new \DateTimeZone($timezone);
     $datetime = new \DateTime($date, $fromTimezone);
     $toTimezone = new \DateTimeZone($lang->timezone);
     $datetime->setTimezone($toTimezone);
     $strings = $lang->getStrings();
     $stamp = $datetime->getTimeStamp();
     return static::format($stamp, $strings->DATETIME_FORMAT);
 }
 public static function BasicAuthenticationCheck()
 {
     //return true;
     $oContext = Context::getInstance();
     $auth = substr($oContext->request->get->HTTP_AUTHORIZATION, 6);
     list($authUser, $authPass) = explode(':', base64_decode($auth));
     if (!in_array($authUser, array_keys(self::$users))) {
         return false;
     }
     if ($authPass != self::$users[$authUser]) {
         return false;
     }
     return true;
 }
Example #25
0
 /**
  * constructor
  *
  * @access public
  * @author Cédric Alfonsi, <*****@*****.**>
  * @param  array options
  *
  */
 public function __construct($options = array())
 {
     $success = isset($options['success']) ? $options['success'] : true;
     $type = isset($options['type']) ? $options['type'] : 'json';
     $data = isset($options['data']) ? $options['data'] : null;
     $message = isset($options['message']) ? $options['message'] : '';
     //position the header of the response
     $context = Context::getInstance();
     $context->getResponse()->setContentHeader('text/json');
     //set the response object
     $response = array('success' => $success, 'type' => $type, 'message' => $message, 'data' => $data);
     //write the response
     echo json_encode($response);
 }
Example #26
0
 /**
  * If you want strictly to check if the resource is locked,
  * you should use LockManager::getImplementation()->isLocked($resource)
  * Controller level convenience method to check if @resource is being locked, prepare data ans sets view,
  *
  * @param core_kernel_classes_Resource $resource
  * @param $view
  *
  * @return boolean
  */
 protected function isLocked($resource, $view = null)
 {
     $lock = LockManager::getImplementation()->getLockData($resource);
     if (!is_null($lock) && $lock->getOwnerId() != common_session_SessionManager::getSession()->getUser()->getIdentifier()) {
         //if (LockManager::getImplementation()->isLocked($resource)) {
         $params = array('id' => $resource->getUri(), 'topclass-label' => $this->getRootClass()->getLabel());
         if (!is_null($view)) {
             $params['view'] = $view;
             $params['ext'] = Context::getInstance()->getExtensionName();
         }
         $this->forward('locked', 'Lock', 'tao', $params);
     }
     return false;
 }
	/**
	 * Prepare runtime context - tell DB class about current db connection info
	 *
	 * @author Corina Udrescu (dev@xpressengine.org)
	 */
	protected function setUp()
	{
		parent::setUp();

		$oContext = &Context::getInstance();

		$db_info = include dirname(__FILE__) . '/../config/db.config.php';

		$db = new stdClass();
		$db->master_db = $db_info;
		$db->slave_db = array($db_info);
		$oContext->setDbInfo($db);

		DB::getParser(TRUE);
	}
Example #28
0
 public function __construct()
 {
     $this->context = Context::getInstance();
     $this->model = Model_Manager::getInstance();
     $this->container = Service_Container::getInstance();
     $this->view = new AppView();
     $this->view->page = !empty($_GET['page']) ? strtolower($_GET['page']) : 'user';
     $this->view->action = !empty($_GET['action']) ? strtolower($_GET['page']) : 'index';
     if (!empty($this->_JS)) {
         $this->addJSLibraries();
     }
     $this->context->buildParams();
     if (!empty($_GET['msg'])) {
         $this->showMessage();
     }
 }
Example #29
0
 /**
  * Does EVERYTHING
  * @todo cleanup interface
  * @requiresRight id READ
  */
 public function index()
 {
     $formData = array();
     if ($this->hasRequestParameter('classUri')) {
         if (trim($this->getRequestParameter('classUri')) != '') {
             $formData['class'] = new core_kernel_classes_Class(tao_helpers_Uri::decode($this->getRequestParameter('classUri')));
         }
     }
     if ($this->hasRequestParameter('uri') && $this->hasRequestParameter('classUri')) {
         if (trim($this->getRequestParameter('uri')) != '') {
             $formData['instance'] = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
         }
     }
     $formData['id'] = $this->getRequestParameter('id');
     $handlers = $this->getAvailableExportHandlers();
     $exporter = $this->getCurrentExporter();
     $selectedResource = isset($formData['instance']) ? $formData['instance'] : $formData['class'];
     $formFactory = new tao_actions_form_Export($handlers, $exporter->getExportForm($selectedResource), $formData);
     $myForm = $formFactory->getForm();
     if (!is_null($exporter)) {
         $myForm->setValues(array('exportHandler' => get_class($exporter)));
     }
     $this->setData('myForm', $myForm->render());
     if ($this->hasRequestParameter('exportChooser_sent') && $this->getRequestParameter('exportChooser_sent') == 1) {
         //use method GET to allow direct file download (not ajax compatible)
         $exportData = $_GET;
         if (isset($exportData['instances'])) {
             $instanceCount = count($exportData['instances']);
             for ($i = 0; $i < $instanceCount; $i++) {
                 $exportData['instances'][$i] = tao_helpers_Uri::decode($exportData['instances'][$i]);
             }
         } elseif (isset($exportData['exportInstance'])) {
             $exportData['exportInstance'] = tao_helpers_Uri::decode($exportData['exportInstance']);
         }
         $file = $exporter->export($exportData, tao_helpers_Export::getExportPath());
         if (!is_null($file) && file_exists($file)) {
             return tao_helpers_Export::outputFile(tao_helpers_Export::getRelativPath($file));
         }
     }
     $context = Context::getInstance();
     $this->setData('export_extension', $context->getExtensionName());
     $this->setData('export_module', $context->getModuleName());
     $this->setData('export_action', $context->getActionName());
     $this->setData('formTitle', __('Export '));
     $this->setView('form/export.tpl', 'tao');
 }
 /**
  * Constructor inic variables with parameters or defaults
  *
  * @param string $url = ''
  * @param integer $timeOut = 30
  * @param string $acceptType='text/html'
  * @param string $verb='GET'
  * @param boolean $includeHeader = false
  * @param boolean $followlocation = true
  * @param integer $maxRedirecs = 4
  * @param boolean $binaryTransfer = false
  * @param boolean $noBody = false
  *
  * @return void
  */
 protected function __construct($url = '', $timeOut = 5, $acceptType = 'text/html', $verb = 'GET', $includeHeader = false, $followlocation = true, $maxRedirecs = 4, $binaryTransfer = false, $noBody = false)
 {
     $this->_url = $url;
     $this->_followlocation = $followlocation;
     $this->_timeout = $timeOut;
     $this->_maxRedirects = $maxRedirecs;
     $this->_noBody = $noBody;
     $this->_includeHeader = $includeHeader;
     $this->_binaryTransfer = $binaryTransfer;
     $this->_verb = $verb;
     $this->_requestBody = null;
     $this->_acceptType = strtolower($acceptType);
     $this->_responseInfo = null;
     $config = Config::getInstance(Context::getInstance());
     $this->_cookieFileLocation = $config->cokieFile;
     $this->_proxy = is_array($config->proxy) ? $config->proxy : array();
 }