public function setReverseValues() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $values = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); $resource = new core_kernel_classes_Resource($this->getRequestParameter('resourceUri')); $property = new core_kernel_classes_Property($this->getRequestParameter('propertyUri')); $currentValues = array(); foreach ($property->getDomain() as $domain) { $instances = $domain->searchInstances(array($property->getUri() => $resource), array('recursive' => true, 'like' => false)); $currentValues = array_merge($currentValues, array_keys($instances)); } $toAdd = array_diff($values, $currentValues); $toRemove = array_diff($currentValues, $values); $success = true; foreach ($toAdd as $uri) { $subject = new core_kernel_classes_Resource($uri); $success = $success && $subject->setPropertyValue($property, $resource); } foreach ($toRemove as $uri) { $subject = new core_kernel_classes_Resource($uri); $success = $success && $subject->removePropertyValue($property, $resource); } echo json_encode(array('saved' => $success)); }
/** * create a new QTI item * * @requiresRight id WRITE */ public function createItem() { if (!\tao_helpers_Request::isAjax()) { throw new \Exception("wrong request mode"); } $clazz = new \core_kernel_classes_Resource($this->getRequestParameter('id')); if ($clazz->isClass()) { $clazz = new \core_kernel_classes_Class($clazz); } else { foreach ($clazz->getTypes() as $type) { // determine class from selected instance $clazz = $type; break; } } $service = \taoItems_models_classes_ItemsService::singleton(); $label = $service->createUniqueLabel($clazz); $item = $service->createInstance($clazz, $label); if (!is_null($item)) { $service->setItemModel($item, new \core_kernel_classes_Resource(ItemModel::MODEL_URI)); $response = array('label' => $item->getLabel(), 'uri' => $item->getUri()); } else { $response = false; } $this->returnJson($response); }
private static function getParametersFromUrl($url) { $returnValue = array(); // get parameters parse_str(parse_url($url, PHP_URL_QUERY), $returnValue); // encoded in url $parts = explode('/', tao_helpers_Request::getRelativeUrl($url), 4); if (count($parts) == 4) { list($extension, $module, $action, $codedUri) = $parts; $base64String = base64_decode($codedUri); if ($base64String !== false) { // old serialised url if (substr($base64String, 0, strlen('a:')) == 'a:') { $additionalParams = unserialize($base64String); } else { $additionalParams = json_decode($base64String, true); } if ($additionalParams !== false && is_array($additionalParams)) { foreach ($additionalParams as $key => $value) { $returnValue[$key] = $value; } } } } return $returnValue; }
/** * Displays the three action box for the test center */ public function testCenter() { $testCenters = TestCenterHelper::getTestCenters(); $testCenter = $this->getCurrentTestCenter(); $data = array('testCenter' => $testCenter->getUri(), 'title' => sprintf($this->convert('Test site %s'), $testCenter->getLabel()), 'list' => TestCenterHelper::getTestCenterActions($testCenter)); if (\tao_helpers_Request::isAjax()) { $this->returnJson($data); } else { $this->composeView('testcenters-testcenter', $data, array(BreadcrumbsHelper::testCenters(), BreadcrumbsHelper::testCenter($testCenter, $testCenters))); } }
public function render() { $relPath = tao_helpers_Request::getRelativeUrl(); list($extension, $module, $action, $codedUri, $path) = explode('/', $relPath, 5); $uri = base64_decode($codedUri); $item = new core_kernel_classes_Resource($uri); if ($path == 'index') { $this->renderItem($item); } else { $this->renderResource($item, urldecode($path)); } }
/** * view and item * @return void */ public function viewItem() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $itemClass = $this->getCurrentClass(); $item = $this->getCurrentInstance(); $lang = null; if ($this->hasRequestParameter('target_lang')) { $lang = $this->getRequestParameter('target_lang'); } $hiddenProperties = array(taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT); $properties = array(); foreach ($this->service->getClazzProperties($itemClass) as $property) { if (in_array($property->getUri(), $hiddenProperties)) { continue; } $range = $property->getRange(); if (is_null($lang)) { $propValues = $item->getPropertyValues($property); } else { $propContainer = $item->getPropertyValuesByLg($property, $lang); $propValues = $propContainer->getIterator(); } foreach ($propValues as $propValue) { $value = ''; if ($range->getUri() == RDFS_LITERAL) { $value = (string) $propValue; } else { $resource = new core_kernel_classes_Resource($propValue); $value = $resource->getLabel(); } $properties[] = array('name' => $property->getLabel(), 'value' => $value); } } $previewData = $this->initPreview($item, $itemClass); if (count($previewData) == 0) { $this->setData('preview', false); $this->setData('previewMsg', __('Not yet available')); } else { $this->setData('preview', true); $this->setData('instanceUri', tao_helpers_Uri::encode($item->getUri(), false)); foreach ($previewData as $key => $value) { $this->setData($key, $value); } } $this->setData('uri', tao_helpers_Uri::encode($item->getUri())); $this->setData('classUri', tao_helpers_Uri::encode($itemClass->getUri())); $this->setData('label', $item->getLabel()); $this->setData('itemProperties', $properties); $this->setView('view.tpl'); }
public function resolve($relativeUrl) { $config = $this->getConfig(); try { $relNs = \tao_helpers_Request::getRelativeUrl($config['namespace']); if (substr($relativeUrl, 0, strlen($relNs)) == $relNs) { return 'oat\\ontoBrowser\\actions\\Browse@standAlone'; } } catch (\ResolverException $r) { // namespace does not match URL, aborting } return null; }
/** * Delete a result or a result class * @return void */ public function delete() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->getRequestParameter('uri')) { $deleted = $this->service->deleteResult($this->getCurrentInstance()); } else { $deleted = $this->service->deleteResultClass($this->getCurrentClass()); } echo json_encode(array('deleted' => $deleted)); }
public function render() { $relPath = tao_helpers_Request::getRelativeUrl(); list($extension, $module, $action, $codedUri, $path) = explode('/', $relPath, 5); $path = rawurldecode($path); $uri = base64_decode($codedUri); if (!common_Utils::isUri($uri)) { throw new common_exception_BadRequest('"' . $codedUri . '" does not decode to a valid item URI'); } $item = new core_kernel_classes_Resource($uri); if ($path === 'index') { $this->renderItem($item); } else { $this->renderResource($item, $path); } }
public function deliveriesByProctor() { $deliveryData = array(); if (\common_ext_ExtensionsManager::singleton()->isInstalled('ltiDeliveryProvider')) { /** @var DeliveryService $service */ $service = $this->getServiceManager()->get(DeliveryService::CONFIG_ID); $deliveries = $service->getAccessibleDeliveries(); if (!empty($deliveries)) { try { $dataStore = new \tao_models_classes_oauth_DataStore(); $test_consumer = $dataStore->lookup_consumer('proctoring_key'); } catch (\tao_models_classes_oauth_Exception $e) { $secret = uniqid('proctoring_'); \taoLti_models_classes_ConsumerService::singleton()->getRootClass()->createInstanceWithProperties(array(RDFS_LABEL => 'proctoring', PROPERTY_OAUTH_KEY => 'proctoring_key', PROPERTY_OAUTH_SECRET => $secret)); $test_consumer = new \OAuthConsumer('proctoring_key', $secret); } $session = \common_session_SessionManager::getSession(); $ltiData = array('lti_message_type' => 'basic-lti-launch-request', 'lti_version' => 'LTI-1p0', 'resource_link_id' => rand(0, 9999999), 'resource_link_title' => 'Launch Title', 'resource_link_label' => 'Launch label', 'context_title' => 'Launch Title', 'context_label' => 'Launch label', 'user_id' => $session->getUserUri(), 'roles' => 'Learner', 'lis_person_name_full' => $session->getUserLabel(), 'tool_consumer_info_product_family_code' => PRODUCT_NAME, 'tool_consumer_info_version' => TAO_VERSION, 'custom_skip_thankyou' => 'true', 'launch_presentation_return_url' => _url('logout', 'Main', 'tao')); $hmac_method = new \OAuthSignatureMethod_HMAC_SHA1(); $test_token = new \OAuthToken($test_consumer, ''); foreach ($deliveries as $delivery) { $launchUrl = LTIDeliveryTool::singleton()->getLaunchUrl(array('delivery' => $delivery->getUri())); $acc_req = \OAuthRequest::from_consumer_and_token($test_consumer, $test_token, 'GET', $launchUrl, $ltiData); $acc_req->sign_request($hmac_method, $test_consumer, $test_token); $deliveryData[] = array('id' => $delivery->getUri(), 'label' => $delivery->getLabel(), 'url' => $acc_req->to_url(), 'text' => __('Test')); } } } $this->setData('title', __('Available Deliveries')); if (\tao_helpers_Request::isAjax()) { $this->returnJson(array('list' => $deliveryData)); } else { try { $testCenter = $this->getCurrentTestCenter(); $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters(), BreadcrumbsHelper::testCenter($testCenter, TestCenterHelper::getTestCenters()), BreadcrumbsHelper::diagnostics($testCenter, array(BreadcrumbsHelper::deliveries($testCenter))), BreadcrumbsHelper::deliveriesByProctor($testCenter))); } catch (\common_Exception $e) { $this->composeView('diagnostic-deliveries', array('list' => $deliveryData), array(BreadcrumbsHelper::testCenters())); } } }
/** * save the related items from the checkbox tree or from the sequence box * @return void */ public function saveItems() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $saved = false; $candidates = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); foreach ($this->getRequestParameters() as $key => $value) { if (preg_match("/^instance_/", $key)) { $candidates[] = tao_helpers_Uri::decode($value); } } $items = array(); foreach ($candidates as $uri) { $item = new core_kernel_classes_Resource($uri); $itemModel = $item->getOnePropertyValue(new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY)); $supported = false; if (!is_null($itemModel)) { foreach ($itemModel->getPropertyValues(new core_kernel_classes_Property(TAO_ITEM_MODELTARGET_PROPERTY)) as $targeturi) { if ($targeturi == TAO_ITEM_ONLINE_TARGET) { $supported = true; break; } } } if ($supported) { array_push($items, $item); } else { throw new common_Exception($item->getLabel() . ' cannot be added to a test'); } } if ($this->service->setTestItems($this->getCurrentInstance(), $items)) { $saved = true; } $this->returnJson(array('saved' => $saved)); }
/** * Function to return an user readable error * Does not work with ajax Requests yet * * @param string $description error to show * @param boolean $returnLink whenever or not to add a return link */ protected function returnError($description, $returnLink = true) { if (tao_helpers_Request::isAjax()) { common_Logger::w('Called ' . __FUNCTION__ . ' in an unsupported AJAX context'); throw new common_Exception($description); } else { $this->setData('message', $description); $this->setData('returnLink', $returnLink); $this->setView('error/user_error.tpl', 'tao'); } }
/** * simplified Version of TaoModule function * * @return void */ public function sasGetOntologyData() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $showInstances = $this->hasRequestParameter('hideInstances') ? !(bool) $this->getRequestParameter('hideInstances') : true; $hideNode = $this->hasRequestParameter('classUri'); $clazz = $this->hasRequestParameter('classUri') ? $this->getCurrentClass() : $this->getRootClass(); if ($this->hasRequestParameter('offset')) { $options['offset'] = $this->getRequestParameter('offset'); } $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : 0; $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0; $factory = new GenerisTreeFactory($showInstances, array($clazz->getUri()), $limit, $offset); $tree = $factory->buildTree($clazz); $returnValue = $hideNode ? $tree['children'] : $tree; echo json_encode($returnValue); }
/** * Render the add index sub form. * @throws Exception * @return void */ public function addPropertyIndex() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } if (!$this->hasRequestParameter('uri')) { throw new Exception("wrong request Parameter"); } $uri = $this->getRequestParameter('uri'); $clazz = $this->getCurrentClass(); $index = 1; if ($this->hasRequestParameter('index')) { $index = $this->getRequestParameter('index'); } $propertyIndex = 1; if ($this->hasRequestParameter('propertyIndex')) { $propertyIndex = $this->getRequestParameter('propertyIndex'); } //create and attach the new index property to the property $property = new core_kernel_classes_Property(tao_helpers_Uri::decode($uri)); $class = new \core_kernel_classes_Class("http://www.tao.lu/Ontologies/TAO.rdf#Index"); //get property range to select a default tokenizer /** @var core_kernel_classes_Class $range */ $range = $property->getRange(); //range is empty select item content $tokenizer = null; if (is_null($range)) { $tokenizer = new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer'); } else { $tokenizer = $range->getUri() === RDFS_LITERAL ? new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer') : new core_kernel_classes_Resource('http://www.tao.lu/Ontologies/TAO.rdf#LabelTokenizer'); } $indexClass = new core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAO.rdf#Index'); $i = 0; $indexIdentifierBackup = preg_replace('/[^a-z_0-9]/', '_', strtolower($property->getLabel())); $indexIdentifierBackup = ltrim(trim($indexIdentifierBackup, '_'), '0..9'); $indexIdentifier = $indexIdentifierBackup; do { if ($i !== 0) { $indexIdentifier = $indexIdentifierBackup . '_' . $i; } $resources = $indexClass->searchInstances(array(INDEX_PROPERTY_IDENTIFIER => $indexIdentifier), array('like' => false)); $count = count($resources); $i++; } while ($count !== 0); $indexProperty = $class->createInstanceWithProperties(array(RDFS_LABEL => preg_replace('/_/', ' ', ucfirst($indexIdentifier)), INDEX_PROPERTY_IDENTIFIER => $indexIdentifier, INDEX_PROPERTY_TOKENIZER => $tokenizer, INDEX_PROPERTY_FUZZY_MATCHING => GENERIS_TRUE, INDEX_PROPERTY_DEFAULT_SEARCH => GENERIS_FALSE)); $property->setPropertyValue(new core_kernel_classes_Property(INDEX_PROPERTY), $indexProperty); //generate form $indexFormContainer = new tao_actions_form_IndexProperty($clazz, $indexProperty, array('index' => $index, 'propertyindex' => $propertyIndex)); $myForm = $indexFormContainer->getForm(); $form = trim(preg_replace('/\\s+/', ' ', $myForm->renderElements())); echo json_encode(array('form' => $form)); }
/** * Duplicate a process instance * * @access public * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} * @return void */ public function cloneProcess() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $clone = $this->service->cloneProcess($this->getCurrentInstance(), $this->getCurrentClass()); if (!is_null($clone)) { echo json_encode(array('label' => $clone->getLabel(), 'uri' => tao_helpers_Uri::encode($clone->getUri()))); } }
/** * Remove the list element in parameter * @return void */ public function removeListElement() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $deleted = false; if ($this->hasRequestParameter('uri')) { $deleted = $this->service->removeListElement(new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')))); } echo json_encode(array('deleted' => $deleted)); }
private function dispatchError(Exception $e, $httpStatus, $message = '', $trace = '') { // Set relevant HTTP header. header(HTTPToolkit::statusCodeHeader($httpStatus)); if (tao_helpers_Request::isAjax()) { new common_AjaxResponse(array("success" => false, "type" => 'Exception', "data" => array('ExceptionType' => get_class($e)), "message" => $message)); } else { require_once Template::getTemplate("error/error{$httpStatus}.tpl", 'tao'); } }
/** * Get XML content. * * @access protected * @author Aleh Hutnikau, <*****@*****.**> * @param boolean $refresh load content again. * @return string */ protected function getContent($refresh = false) { if ($this->content === null || $refresh) { try { switch ($this->sourceType) { case self::SOURCE_FILE: //check file if (!file_exists($this->source)) { throw new Exception("File {$this->source} not found."); } if (!is_readable($this->source)) { throw new Exception("Unable to read file {$this->source}."); } if (!preg_match("/\\.{$this->fileExtension}\$/", basename($this->source))) { throw new Exception("Wrong file extension in " . basename($this->source) . ", {$this->fileExtension} extension is expected"); } if (!tao_helpers_File::securityCheck($this->source)) { throw new Exception("{$this->source} seems to contain some security issues"); } $this->content = file_get_contents($this->source); break; case self::SOURCE_URL: //only same domain if (!preg_match("/^" . preg_quote(BASE_URL, '/') . "/", $this->source)) { throw new Exception("The given uri must be in the domain {$_SERVER['HTTP_HOST']}"); } $this->content = tao_helpers_Request::load($this->source, true); break; case self::SOURCE_STRING: $this->content = $this->source; break; case self::SOURCE_FLYFILE: if (!$this->source->exists()) { throw new common_Exception('Source file does not exists ("' . $this->source->getPath() . '").'); } if (!($this->content = $this->source->read())) { throw new common_Exception('Unable to read file ("' . $this->source->getPath() . '").'); } break; } } catch (Exception $e) { $this->addError($e); } } return $this->content; }
/** * action used to check if a login can be used * @return void */ public function checkLogin() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $data = array('available' => false); if ($this->hasRequestParameter('login')) { $data['available'] = $this->userService->loginAvailable($this->getRequestParameter('login')); } $this->returnJson($data); }
public function getUsers() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } else { $userService = tao_models_classes_UserService::singleton(); echo json_encode($userService->toTree(new core_kernel_classes_Class(CLASS_TAO_USER), array())); } }
public function saveExcluded() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } if (!$this->hasRequestParameter('excluded')) { throw new common_exception_MissingParameter('excluded'); } $jsonArray = json_decode($_POST['excluded']); if (!is_array($jsonArray)) { throw new common_Exception('parameter "excluded" should be a json encoded array'); } $assembly = $this->getCurrentInstance(); $success = $assembly->editPropertyValues(new core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP), $jsonArray); echo json_encode(array('saved' => $success)); }
public function addActionAccess() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } else { $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $actionService = funcAcl_models_classes_ActionAccessService::singleton(); $actionService->add($role, $uri); echo json_encode(array('uri' => $uri)); } }
/** * Get the data to populate the tree of deliveries * @return void */ public function getDeliveries() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $options = array('chunk' => false); if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); $options['chunk'] = true; } else { $clazz = new core_kernel_classes_Class(TAO_DELIVERY_CLASS); } if ($this->hasRequestParameter('selected')) { $selected = $this->getRequestParameter('selected'); if (!is_array($selected)) { $selected = array($selected); } $options['browse'] = $selected; } echo json_encode($this->service->toTree($clazz, $options)); }
public function accessFile() { list($extension, $module, $action, $code, $filePath) = explode('/', tao_helpers_Request::getRelativeUrl(), 5); list($key, $subPath) = explode(' ', base64_decode($code), 2); $source = WebsourceManager::singleton()->getWebsource($key); if ($source instanceof ActionWebSource) { $path = $source->getFileSystem()->getPath() . $subPath . (empty($filePath) ? '' : DIRECTORY_SEPARATOR . $filePath); tao_helpers_Http::returnFile($path); } }
/** * Get the root SimpleXMLElement object of the currently parsed manifest. * * @throws common_exception_Error * @return SimpleXMLElement */ private function getSimpleXMLElement() { switch ($this->sourceType) { case self::SOURCE_FILE: $xml = simplexml_load_file($this->source); break; case self::SOURCE_URL: $xmlContent = tao_helpers_Request::load($this->source, true); $xml = simplexml_load_string($xmlContent); break; case self::SOURCE_STRING: $xml = simplexml_load_string($this->source); break; default: throw new taoItems_models_classes_Import_ImportException('Invalid sourceType'); } if ($xml === false) { $this->addErrors(libxml_get_errors()); libxml_clear_errors(); throw new common_exception_Error('Invalid XML.'); } return $xml; }
/** * Print an error report into the response. * After you have called this method, you must prevent other actions to be processed and must close the response. * @param string $message * @param int $code */ protected function notifyError($message, $code = 0) { $ctx = array('success' => false, 'state' => $this->getTestSession()->getState(), 'message' => $message, 'code' => $code); $this->setData('assessmentTestContext', $ctx); if (\tao_helpers_Request::isAjax()) { $this->returnJson($ctx); } }
/** * Duplicate a resultServer instance * @return void * @throws Exception */ public function cloneResultServer() { if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $resultServer = $this->getCurrentResultServer(); $clazz = $this->getCurrentClass(); $clone = $this->service->createInstance($clazz); if (!is_null($clone)) { foreach ($clazz->getProperties() as $property) { foreach ($resultServer->getPropertyValues($property) as $propertyValue) { $clone->setPropertyValue($property, $propertyValue); } } $clone->setLabel($resultServer->getLabel() . "'"); echo json_encode(array('label' => $clone->getLabel(), 'uri' => tao_helpers_Uri::encode($clone->getUri()))); } }
/** * Render the add property sub form. * @throws Exception * @return void */ public function removeClassProperty() { $success = false; if (!tao_helpers_Request::isAjax()) { throw new Exception("wrong request mode"); } $class = new core_kernel_classes_Class($this->getRequestParameter('classUri')); $property = new core_kernel_classes_Property($this->getRequestParameter('uri')); //delete property mode foreach ($class->getProperties() as $classProperty) { if ($classProperty->equals($property)) { //delete property and the existing values of this property if ($property->delete(true)) { $success = true; break; } } } if ($success) { return $this->returnJson(array('success' => true)); } else { $this->returnError(__('Unable to remove the property.')); } }
/** * Check if the system is ready */ public function isReady() { if (tao_helpers_Request::isAjax()) { // the default ajax response is successful style rastafarai $ajaxResponse = new common_AjaxResponse(); } else { throw new common_exception_IsAjaxAction(__CLASS__ . '::' . __METHOD__ . '()'); } }
/** * Generic class deletion action * * @throws Exception * @requiresRight id WRITE */ public function deleteClass() { if (!tao_helpers_Request::isAjax() || !$this->hasRequestParameter('id')) { throw new Exception("wrong request mode"); } $clazz = new core_kernel_classes_Class($this->getRequestParameter('id')); if ($this->getRootClass()->equals($clazz)) { $success = false; $msg = __('You cannot delete the root node'); } else { $label = $clazz->getLabel(); $success = $this->getClassService()->deleteClass($clazz); $msg = $success ? __('%s has been deleted', $label) : __('Unable to delete %s', $label); } return $this->returnJson(array('deleted' => $success, 'msg' => $msg)); }