/** * @brief error 错误输出函数 * * @param $errCode 错误码 * * @return void */ public static function error($errCode, $errMessage = '') { // 清除输出缓存 @ob_end_clean(); if (array_key_exists($errCode, self::$_httpCode)) { $errMessage = self::$_httpCode[$errCode]; @header("HTTP/1.1 {$errCode} {$errMessage}"); @header("status: {$errCode} {$errMessage}"); } if (Request::isAjax()) { // 如果是 Ajax 请求 if (defined('LOGX_DEBUG')) { $r = array('success' => FALSE, 'message' => $errMessage); } else { $r = array('success' => FALSE, 'message' => _t('Sorry, some error occured.')); } self::ajaxReturn($r); } else { echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; echo '<html xmlns="http://www.w3.org/1999/xhtml"><head>'; echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; echo "<title>{$errCode}</title>"; echo '<style type="text/css">'; echo 'body { background: #f7fbe9; font-family: "Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana; }'; echo '#error { background: #59c6e0; width: 360px; margin: 100px auto; color: #fff; padding: 10px; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; }'; echo 'h1 { padding: 10px; margin: 0; font-size: 36px; }'; echo 'p { padding: 0 20px 20px 20px; margin: 0; font-size: 12px; }'; echo 'img { padding: 0 0 5px 300px; }'; echo '</style></head><body><div id="error">'; echo "<h1>{$errCode}</h1><p>{$errMessage}</p>"; echo '<img src="' . LOGX_PATH . '?591E-D5FC-8065-CD36-D3E8-E45C-DB86-9197" /></div></body></html>'; } exit; }
/** * Common code for all actions: set default layout and page title. * * @param type $action * @param type $args */ function before_filter(&$action, &$args) { $this->validate_args($args, array('option', 'option')); parent::before_filter($action, $args); // set correct encoding if this is an ajax-call if (Request::isAjax()) { header('Content-Type: text/html; charset=Windows-1252'); } $this->flash = Trails_Flash::instance(); // set default layout $layout = $GLOBALS['template_factory']->open('layouts/base'); $this->set_layout($layout); // Set help keyword for Stud.IP's user-documentation and page title PageLayout::setHelpKeyword('Basis.Forum'); PageLayout::setTitle($_SESSION['SessSemName']['header_line'] . ' - ' . _('Forum')); $this->AVAILABLE_DESIGNS = array('web20', 'studip'); if ($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] && $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] != '/') { $this->picturepath = $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] . '/' . $this->dispatcher->trails_root . '/img'; } else { $this->picturepath = '/' . $this->dispatcher->trails_root . '/img'; } // we want to display the dates in german setlocale(LC_TIME, 'de_DE@euro', 'de_DE', 'de', 'ge'); // the default for displaying timestamps $this->time_format_string = "%a %d. %B %Y, %H:%M"; $this->time_format_string_short = "%d.%m.%Y, %H:%M"; $this->template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../templates'); //$this->check_token(); ForumVisit::setVisit($this->getId()); if (Request::int('page')) { ForumHelpers::setPage(Request::int('page')); } $this->seminar_id = $this->getId(); }
/** * Display the HTML-Footer */ public function displayFooter() { if (!Request::isAjax()) { include 'tpl/tpl.Frontend.footer.php'; } Error::getInstance()->footer_sent = true; }
public function BuildFromList($list_id = null) { $Lid = is_null($list_id) ? $this->post->list_id : $list_id; if (is_numeric($Lid)) { #Retorna o array com os posts da TL $timeline = Timeline::build_from_list($this->session->user->id, $Lid, new stdClass()); $posts = $this->render($timeline); } elseif ($Lid == 'bookmarks') { #Retorna os favoritos do usuário $favs = $this->MyFavorites(new stdClass()); $posts = $this->render($favs); } elseif ($Lid == 'all_posts') { $posts = Timeline::get_public_posts(new stdClass()); $posts = $this->render($posts); } else { $posts = $this->SimpleBuild(); } if (Request::isAjax()) { header("Content-type:text/html; charset=utf-8"); if (is_array($posts)) { echo implode('', $posts); } else { die('{status: "FAIL"}'); } } else { return is_array($posts) ? $posts : false; } }
public function testMethods() { $_SERVER['REQUEST_METHOD'] = 'POST'; $Request = new Request(); $this->assertTrue($Request->isPost()); $this->assertFalse($Request->isGet()); $this->assertEqual($Request->method(), 'POST'); $_SERVER['REQUEST_METHOD'] = 'GET'; $Request = new Request(); $this->assertFalse($Request->isPost()); $this->assertTrue($Request->isGet()); $this->assertEqual($Request->method(), 'GET'); $this->assertFalse($Request->isAjax()); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->assertTrue($Request->isAjax()); }
public function run() { $route = $this->router->match($this->request); if ($route === false) { $actionName = self::ACTION_NOT_FOUND; } else { $actionName = $route->getName(); } if (!$this->actions->has($actionName)) { throw new \Exception(sprintf('Action %s not found', $actionName)); } $this->store->setFileName($actionName); if ($this->request->isAjax()) { $this->view->setRenderType(View::RENDER_JSON); } else { $this->view->setContentView('error'); } $action = $this->actions->get($actionName); call_user_func_array($action, array($this)); if (is_callable($this->postAction)) { call_user_func_array($this->postAction, array($this)); } $this->response->setContent($this->view->render()); $this->response->send(); }
/** * Send JSON error message * * @return string */ protected function _errorResponse($msg) { if (Request::isAjax()) { Response::jsonError($msg); } else { Response::redirect(Request::url(array('index'), true)); } }
public function new_topic_action() { Navigation::activateItem('/course/schedule/dates'); if (Request::isAjax()) { PageLayout::setTitle(_("Thema hinzufügen")); } $this->date = new CourseDate(Request::option("termin_id")); $this->course = Course::findCurrent(); }
public function listAction() { if (Request::isAjax() && Request::isPost()) { $user = UsersPDO::get(AuthModel::getUserName()); $receiverId = $_POST['receiverId']; $model = new ChatModel($user['Id']); $result = $model->getChat($receiverId); $this->renderJSON($result); } }
private static function isLogin() { if (!($userid = session_get('USERID'))) { if (Request::isAjax()) { exit(json_encode(array('code' => -1, 'msg' => 'please login'))); } else { exit(app::run(array('home', 'page', 'login'))); } } return $userid; }
function edit_action($area_id) { ForumPerm::check('edit_area', $this->getId(), $area_id); if (Request::isAjax()) { ForumEntry::update($area_id, studip_utf8decode(Request::get('name')), studip_utf8decode(Request::get('content'))); $this->render_json(array('content' => ForumEntry::killFormat(ForumEntry::killEdit(studip_utf8decode(Request::get('content')))))); } else { ForumEntry::update($area_id, Request::get('name'), Request::get('content')); $this->flash['messages'] = array('success' => _('Die Änderungen am Bereich wurden gespeichert.')); $this->redirect(PluginEngine::getLink('coreforum/index/index')); } }
function dumpError($sql) { if (Kennel::$ROOT_URL && !Request::isAjax()) { // Non-ajax HTTP Request $table = XML::element('table', null, array('border' => '1')); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, array('colspan' => '2'), "SQL query returned an error"); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'query'); $td = XML::element('td', $tr, null, syntax::mysql($sql)); $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'error'); $td = XML::element('td', $tr, null, mysql_error(self::$CONN)); $full_backtrace = debug_backtrace(); $backtrace = $full_backtrace[2]; if (isset($backtrace['file'])) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'file'); $td = XML::element('td', $tr, null, $backtrace['file']); } if (isset($backtrace['line'])) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'line'); $td = XML::element('td', $tr, null, $backtrace['line']); } if ($backtrace['class']) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'class'); $td = XML::element('td', $tr, null, $backtrace['class']); } if ($backtrace['function']) { $tr = XML::element('tr', $table); $th = XML::element('th', $tr, null, 'function'); $td = XML::element('td', $tr, null, $backtrace['function']); } echo $table; } else { // Ajax or cli $default = "[0m"; echo "\n[1;30;41m"; // red background, bold echo "SQL query returned an error:{$default}\n"; $lines = explode("\n", $sql); foreach ($lines as $line) { echo " {$line}\n"; } $error = mysql_error(self::$CONN); echo "[31m"; // red echo "{$error}{$default}\n\n"; } die; }
function execute() { $user = ConnectionHelper::userLogin(); $model = new connectionFeedbackAnswerModel(); $data = Request::post('answer'); $data['user'] = $user['id']; $result = $model->add($data); if (!Request::isAjax()) { Request::redirect('/profile/support/' . $data['ticket'] . '/'); } return $result ? 'success' : 'error'; }
public function __construct() { if (Request::isAjax()) { Render::setReply(['reply' => false, 'message' => self::$_content]); } else { Layout::renderMenu(false); Layout::renderFooter(false); Layout::loadContent(self::$_content); if (!Layout::haveContent()) { Layout::putContent(self::$_content); } } }
function Auth() { if (!Sentry::check()) { if (Request::isAjax()) { Response::headers()->set('Content-Type', 'application/json'); Response::setBody(json_encode(array('success' => false, 'message' => 'Session expired or unauthorized access.', 'code' => 401))); App::stop(); } else { $redirect = Request::getResourceUri(); Response::redirect(App::urlFor('login') . '?redirect=' . base64_encode($redirect)); } } }
/** * Function to display the HTML-Footer */ public function displayFooter() { if (!Request::isAjax()) { if (self::$IS_IFRAME) { include 'tpl/tpl.FrontendSharedIframe.footer.php'; } include 'tpl/tpl.Frontend.footer.php'; } if (RUNALYZE_DEBUG && Error::getInstance()->hasErrors()) { Error::getInstance()->display(); } Error::getInstance()->footer_sent = true; }
/** * Run controller * @param string $controller - controller class * @param string $action - action name * @return mixed */ public function runController($controller, $action = false) { if (!class_exists($controller)) { return false; } $controller = new $controller(); $controller->setRouter($this); if ($controller instanceof Router_Interface) { return $controller->route(); } if ($action === false || !strlen($action) || !method_exists($controller, $action . 'Action')) { if (strlen($action) && Request::isAjax()) { Response::jsonError(Lang::lang()->get('WRONG_REQUEST') . ' ' . Request::getInstance()->getUri()); } $action = 'index'; } return $controller->{$action . 'Action'}(); }
public function tablemapping_action($table_id) { PageLayout::setTitle(_("Datenmapping einstellen")); $this->table = new FleximportTable($table_id); Navigation::activateItem("/fleximport/process_" . $this->table['process_id']); if (Request::isPost()) { $tabledata = Request::getArray("tabledata"); $tabledata = array_merge($this->table['tabledata'], $tabledata); $this->table['tabledata'] = $tabledata; $this->table->store(); PageLayout::postMessage(MessageBox::success(_("Daten wurden gespeichert."))); } $datafield_object_types = array('User' => "user", 'Course' => "sem", 'CourseMember' => "usersemdata"); $this->datafields = Datafield::findBySQL("object_type = :object_type", array('object_type' => $datafield_object_types[$this->table['import_type']])); if (Request::isAjax() && Request::isPost()) { $output = array('func' => "STUDIP.Fleximport.updateTable", 'payload' => array('table_id' => $table_id, 'name' => $this->table['name'], 'html' => $this->render_template_as_string("import/_table.php"))); $this->response->add_header("X-Dialog-Execute", json_encode(studip_utf8encode($output))); } }
public function listAction() { if (!AuthModel::isLogin()) { header('Location: /auth/login/'); return; } $number = 10; $page = isset($_GET['page']) ? $_GET['page'] : 1; $limitOffset = ($page - 1) * $number; $this->page = $page; $this->pageCount = ceil(UsersPDO::count() / $number); $this->users = UsersPDO::getAllLimit($limitOffset, $number); if (Request::isAjax()) { $this->partialView('user_list_partial'); } else { $this->title = 'Users list'; $this->view('user_list'); } }
/** * Route request to the Controller * @return void */ public function route() { $cfg = Registry::get('backend', 'config'); $controller = $this->_request->getPart(1); $controller = Utils_String::formatClassName(Filter::filterValue('pagecode', $controller)); if (in_array('Backend_' . $controller . '_Controller', $cfg->get('system_controllers'))) { $controller = 'Backend_' . $controller . '_Controller'; } else { $manager = new Backend_Modules_Manager(); $controller = $manager->getModuleController($controller); if ($controller === false) { if (Request::isAjax()) { Response::jsonError(Lang::lang()->get('WRONG_REQUEST') . ' ' . Request::getInstance()->getUri()); } $controller = 'Backend_Index_Controller'; } } $this->runController($controller, $this->_request->getPart(2)); }
/** * @brief doAdmin 处理后台请求 * * @param $params 传入参数 * * @return void */ public function doAdmin($params) { // 验证用户权限 if (!Widget::getWidget('User')->isEditor()) { return; } // 分发请求 if (method_exists($this, $params['do'] . 'Do')) { if (!Request::isAjax() && $params['do'] != 'upload') { $this->display('head.php'); } $this->action = $params['do']; $this->{$params['do'] . 'Do'}(); if (!Request::isAjax() && $params['do'] != 'upload') { $this->display('foot.php'); } } else { Response::error(404); } }
private static function deliveryResponse() { $isAjax = Request::isAjax(); if ($isAjax) { if (empty(self::$_reply) || !is_array(self::$_reply)) { exit('No reply seted by ajax controller or reply is not an array'); } foreach (self::$_reply as $key => $value) { if ($key != 'reply' && !is_numeric($value) && !is_array($value) && $value) { self::$_reply[$key] = Language::translation($value); } } Request::responseHeader(); echo json_encode(self::$_reply); } else { Layout::MenuFooterAutoload(); Layout::replaceTag(); Layout::translation(); Request::responseHeader(); echo Layout::getLayout(); } }
<?php /** * Sample group routing with user check in middleware */ Route::group('/admin', function () { if (!Sentry::check()) { if (Request::isAjax()) { Response::headers()->set('Content-Type', 'application/json'); Response::setBody(json_encode(array('success' => false, 'message' => 'Session expired or unauthorized access.', 'code' => 401))); App::stop(); } else { $redirect = Request::getResourceUri(); Response::redirect(App::urlFor('login') . '?redirect=' . base64_encode($redirect)); } } }, function () use($app) { /** sample namespaced controller */ Route::get('/', 'Admin\\AdminController:index')->name('admin'); foreach (Module::getModules() as $module) { $module->registerAdminRoute(); } }); Route::get('/login', 'Admin\\AdminController:login')->name('login'); Route::get('/logout', 'Admin\\AdminController:logout')->name('logout'); Route::post('/login', 'Admin\\AdminController:doLogin'); /** Route to documentation */ Route::get('/doc(/:page+)', 'DocController:index'); foreach (Module::getModules() as $module) { $module->registerPublicRoute(); }
<?php echo Icon::create("vote", "clickable")->asimg("20px", array('class' => "text-bottom")); ?> <?php echo formatReady($vote['questiondata']['question']); ?> </h3> <? if (count($vote->answers) > 0 && count($data['options']) > 0) : ?> <div style="max-height: none; opacity: 1;" id="questionnaire_<?php echo $vote->getId(); ?> _chart" class="ct-chart"></div> <script> <?php echo Request::isAjax() ? 'jQuery(document).add(".questionnaire_results").one("dialog-open", function () {' : 'jQuery(function () {'; ?> var data = { labels: <?php echo json_encode(studip_utf8encode($ordered_options)); ?> , series: [<?php echo json_encode(studip_utf8encode($ordered_results)); ?> ] }; <? if ($vote['questiondata']['multiplechoice']) : ?> new Chartist.Bar('#questionnaire_<?php echo $vote->getId(); ?>
/** * @todo Implement testIsAjax(). */ public function testIsAjax() { $this->assertEquals(false, $this->request->isAjax()); }
$_GET['type'] = 'week'; include 'window.plotSumData.shared.php'; exit; } } require '../inc/class.Frontend.php'; require '../inc/class.FrontendShared.php'; require '../inc/class.FrontendSharedList.php'; $Frontend = new FrontendSharedList(); if (!Request::isAjax()) { if ($Frontend->userAllowsStatistics()) { echo '<div class="panel" style="width:960px;margin:5px auto;">'; $Frontend->displayGeneralStatistics(); echo '</div>'; } echo '<div id="data-browser" class="panel" style="width:960px;margin:5px auto;">'; echo '<div id="' . DATA_BROWSER_SHARED_ID . '">'; } $Frontend->displaySharedView(); if (!Request::isAjax()) { echo '</div>'; echo '</div>'; echo '<div id="statistics-inner" class="panel" style="width:960px;margin:5px auto;"> <div class="panel-content"> <p class="info"> ' . __('Click on an activity to see more details.') . '<br> ' . __('Public activities are marked: ') . ' ' . Icon::$ADD_SMALL_GREEN . '. </p> </div> </div>'; }
/** * Handles default exception if it wasn't handled before * * @param Exception $e exception to be handled * @return void * @static */ private function handleDefaultException($e) { Log::out(get_class($e) . ', ' . $e->getMessage(), Log::LEVEL_CRIT); if (php_sapi_name() == 'cli') { print "\n" . get_class($e) . " occured\n" . 'Message: ' . $e->getMessage() . "\n" . 'Code: ' . $e->getCode() . "\n" . $e->getTraceAsString() . "\n"; } else { if ($e instanceof BakedCarrotNotFoundException) { if (!headers_sent()) { header('HTTP/1.0 404 Not Found'); } if (Request::isAjax() || Request::isFlash()) { print $e->getMessage(); } else { print '<html><head></head><body style="font: 10pt arial; margin: 40px;">' . '<h1 style="font-weight: normal; font-size: 30px;">404 Page Not Found</h1>' . ($e->getMessage() ? '<h3 style="margin: 0; font-weight: normal;">Message: ' . $e->getMessage() . '</h3>' : '') . (self::isDevMode() ? '<p>' . nl2br($e->getTraceAsString()) . '</p>' : '') . '</body>'; } } else { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } if (Request::isAjax() || Request::isFlash()) { print 'EXCEPTION (' . get_class($e) . '): ' . $e->getMessage() . "\n"; if (self::isDevMode() && get_class($e) == 'PDOException') { print 'SQL: ' . Db::lastSql(); } } else { print '<html><head></head><body style="font: 10pt arial; margin: 40px;">' . '<h1 style="font-weight: normal; font-size: 30px;">' . get_class($e) . ' occured</h1>' . '<h3 style="margin: 0; font-weight: normal;">Message: ' . $e->getMessage() . '</h3>' . '<h3 style="margin: 0; font-weight: normal;">Code: ' . $e->getCode() . '</h3>' . (self::isDevMode() && get_class($e) == 'PDOException' ? '<h3 style="margin: 0;">SQL: ' . Db::lastSql() . '</h3>' : '') . (self::isDevMode() ? '<p>' . nl2br($e->getTraceAsString()) . '</p>' : '') . '<h4 style="font-weight: normal;"><em>Baked Carrot ver ' . BAKEDCARROT_VERSION . '</em></h4>' . '</body>'; } } } exit(-1); }
/** * Process the request * @param Request $request */ public function processRequest(TrackerManager $tracker_manager, $request, $current_user) { $renderer_parameters = $request->get('renderer_table'); $this->initiateSession(); if ($renderer_parameters && is_array($renderer_parameters)) { //Update the chunksz parameter if (isset($renderer_parameters['chunksz'])) { $new_chunksz = abs((int) $renderer_parameters['chunksz']); if ($new_chunksz && $this->chunksz != $new_chunksz) { $this->report_session->set("{$this->id}.chunksz", $new_chunksz); $this->report_session->setHasChanged(); $this->chunksz = $new_chunksz; } } //Add an aggregate function if (isset($renderer_parameters['add_aggregate']) && is_array($renderer_parameters['add_aggregate'])) { list($field_id, $agg) = each($renderer_parameters['add_aggregate']); //Is the field used by the tracker? $ff = $this->getFieldFactory(); if ($field = $ff->getUsedFormElementById($field_id)) { //Has the field already an aggregate function? $aggregates = $this->getAggregates(); if (isset($aggregates[$field_id])) { //Yes. Check if it has already the wanted aggregate function $found = false; reset($aggregates[$field_id]); while (!$found && (list($key, $row) = each($aggregates[$field_id]))) { if ($row['aggregate'] === $agg) { $found = true; //remove it (toggle) unset($aggregates[$field_id][$key]); $this->report_session->set("{$this->id}.aggregates.{$field_id}", $aggregates[$field_id]); } } if (!$found) { //Add it $aggregates[$field_id][] = array('renderer_id' => $this->id, 'field_id' => $field_id, 'aggregate' => $agg); $this->report_session->set("{$this->id}.aggregates.{$field_id}", $aggregates[$field_id]); } $this->report_session->setHasChanged(); //TODO } else { //No. Add it $this->report_session->set("{$this->id}.aggregates.{$field_id}", array(array('renderer_id' => $this->id, 'field_id' => $field_id, 'aggregate' => $agg))); $this->report_session->setHasChanged(); } } } //toggle a sort column if (isset($renderer_parameters['sort_by'])) { $sort_by = (int) $renderer_parameters['sort_by']; if ($sort_by) { //Is the field used by the tracker? $ff = $this->getFieldFactory(); if ($field = $ff->getUsedFormElementById($sort_by)) { //Is the field used as a column? $columns = $this->getColumns(); if (isset($columns[$sort_by])) { //Is the field already used to sort results? $sort_fields = $this->getSort(); if (isset($sort_fields[$sort_by])) { $is_desc =& $this->report_session->get("{$this->id}.sort.{$sort_by}.is_desc"); //toggle $desc = 1; if ($is_desc == 1) { $desc = 0; } $this->report_session->set("{$this->id}.sort.{$sort_by}.is_desc", $desc); $this->report_session->setHasChanged(); } else { if (!$this->multisort) { //Drop existing sort foreach ($sort_fields as $id => $sort_field) { $this->report_session->remove("{$this->id}.sort", $id); } } //Add new sort $this->report_session->set("{$this->id}.sort.{$sort_by}", array('is_desc' => 0, 'rank' => count($this->report_session->get("{$this->id}.sort")))); $this->report_session->setHasChanged(); } } } } } //Reset sort if (isset($renderer_parameters['resetsort'])) { //Drop existing sort $this->report_session->remove("{$this->id}", "sort"); $this->report_session->setHasChanged(); } //Toggle multisort if (isset($renderer_parameters['multisort'])) { $sort_fields = $this->getSort(); list($keep_it, ) = each($sort_fields); $this->multisort = !$this->multisort; $this->report_session->set("{$this->id}.multisort", $this->multisort); if (!$this->multisort) { $sort = $this->report_session->get("{$this->id}.sort"); foreach ($sort as $field_id => $properties) { if ($field_id != $keep_it) { $this->report_session->remove("{$this->id}.sort", $field_id); $this->report_session->setHasChanged(); } } } } //Remove column if (isset($renderer_parameters['remove-column'])) { if ($field_id = (int) $renderer_parameters['remove-column']) { //Is the field used by the tracker? $ff = $this->getFieldFactory(); if ($field = $ff->getUsedFormElementById($field_id)) { //Is the field used as a column? $columns = $this->getColumns(); if (isset($columns[$field_id])) { //Is the field already used to sort results? $sort_fields = $this->getSort(); if (isset($sort_fields[$field_id])) { //remove from session $this->report_session->remove("{$this->id}.sort", $field_id); $this->report_session->setHasChanged(); } //remove from session $this->report_session->remove("{$this->id}.columns", $field_id); $this->report_session->setHasChanged(); } } } } //Add column if (isset($renderer_parameters['add-column'])) { if ($field_id = (int) $renderer_parameters['add-column']) { $added = false; //Is the field used by the tracker? $ff = $this->getFieldFactory(); if ($field = $ff->getUsedFormElementById($field_id)) { //Is the field used as a column? $columns = $this->getColumns(); if (!isset($columns[$field_id])) { $session_table_columns = $this->report_session->get("{$this->id}.columns"); $nb_col = count($session_table_columns); //Update session with new column $this->report_session->set("{$this->id}.columns.{$field_id}", array('width' => 12, 'rank' => $nb_col)); $this->report_session->setHasChanged(); $added = true; } } if ($added && $request->isAjax()) { $matching_ids = $this->report->getMatchingIds(); $offset = (int) $request->get('offset'); $extracolumn = self::NO_EXTRACOLUMN; $total_rows = $matching_ids['id'] ? substr_count($matching_ids['id'], ',') + 1 : 0; echo $this->fetchTHead($extracolumn, $field_id); echo $this->fetchTBody($matching_ids, $total_rows, $offset, $extracolumn, $field_id); } } } //Reorder columns if (isset($renderer_parameters['reorder-column']) && is_array($renderer_parameters['reorder-column'])) { list($field_id, $new_position) = each($renderer_parameters['reorder-column']); $field_id = (int) $field_id; $field_id_s = $field_id; $new_position = (int) $new_position; if ($field_id) { //Is the field used by the tracker? $ff = $this->getFieldFactory(); if ($field = $ff->getUsedFormElementById($field_id)) { //Is the field used as a column? $columns = $this->getColumns(); if (isset($columns[$field_id])) { $columns =& $this->report_session->get("{$this->id}.columns"); if ($new_position == '-1') { //beginning foreach ($columns as $id => $properties) { $columns[$id]['rank'] = $properties['rank'] + 1; } $columns[$field_id]['rank'] = 0; } else { if ($new_position == '-2') { //end $max = 0; foreach ($columns as $id => $properties) { if ($properties['rank'] > $max) { $max = $properties['rank']; } } $columns[$field_id]['rank'] = $max + 1; } else { //other case $replaced_rank = $columns[$new_position]['rank'] + 1; // rank of the element to shift right foreach ($columns as $id => $properties) { if ($properties['rank'] >= $replaced_rank && $id != $field_id) { $columns[$id]['rank'] += 1; } } $columns[$field_id]['rank'] = $replaced_rank; } } $this->report_session->setHasChanged(); } } } } //Resize column if (isset($renderer_parameters['resize-column']) && is_array($renderer_parameters['resize-column'])) { $ff = $this->getFieldFactory(); foreach ($renderer_parameters['resize-column'] as $field_id => $new_width) { $field_id = (int) $field_id; $new_width = (int) $new_width; if ($field_id) { //Is the field used by the tracker? if ($field = $ff->getUsedFormElementById($field_id)) { //Is the field used as a column? $columns = $this->getColumns(); if (isset($columns[$field_id])) { $old_width = $columns[$field_id]['width']; $this->report_session->set("{$this->id}.columns.{$field_id}.width", $new_width); $this->report_session->setHasChanged(); } } } } } //export if (isset($renderer_parameters['export'])) { $only_columns = isset($renderer_parameters['export_only_displayed_fields']) && $renderer_parameters['export_only_displayed_fields']; $this->exportToCSV($only_columns); } } }
public function testIsXhr() { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XmlHttpRequest'; $this->assertTrue(Request::isAjax()); $this->assertTrue(Request::isXhr()); }
<form action="<?php echo URLHelper::getLink("dispatch.php/questionnaire/context/" . $questionnaire->getId()); ?> " method="post" class="default" <?php echo Request::isAjax() ? "data-dialog" : ""; ?> > <fieldset> <label> <input type="checkbox" name="user" value="1"<?php echo $profile ? " checked" : ""; ?> > <?php echo _("Auf der persönlichen Profilseite"); ?> </label> <label> <input type="checkbox" name="public" value="1"<?php echo $public ? " checked" : ""; ?> > <?php echo _("Als öffentlicher Link für unangemeldete Nutzer"); ?> <?php echo formatReady($GLOBALS['ABSOLUTE_URI_STUDIP'] . "dispatch.php/questionnaire/answer/" . $questionnaire->getId()); ?>