/** * The construct of Base_controller * * Definitions of what is done in this constructor: * Set the default timezone configured in the codeigniter * * Initializate the variable $jsfile and $css_files for use in the views * * Load the language file * */ function __construct() { parent::__construct(); $this->data['data'] = array(); //Set the default timezone configured in the codeigniter date_default_timezone_set($this->config->item('default_timezone')); //set default for ctrlr_name and class_name $class_name = get_class($this); $this->ctrlr_name = strtolower($class_name); $this->class_name = $class_name; //Set default for header and ctrl //$this->_set_title($class_name); $this->data['ctrlr_name'] = $this->ctrlr_name; //Verifica se a função que chamou esta função é 'show', se não for chama a view com o nome dela //$this->router = & load_class('Router'); $class = $this->router->fetch_class(); $action = $this->router->fetch_method(); $this->action = $action; $this->data['data']['action'] = $this->action; $this->uriaction = $this->uri->segment(1); $this->data['data']['uriaction'] = $this->uriaction; $this->data['data']['site_name'] = "Corre D'água"; $this->data['content'] = $this->ctrlr_name . '/' . $this->action . '_view'; $this->data['data']['pagination'] = !empty($this->data['data']['pagination']) ? $this->data['data']['pagination'] : ''; $this->data['data']['site_name'] = !empty($this->data['data']['site_name']) ? $this->data['data']['site_name'] : ''; $this->data['data']['site_title'] = !empty($this->data['data']['site_title']) ? $this->data['data']['site_title'] : ''; if (!isAjax()) { //$this->output->enable_profiler(true); } else { $this->output->set_content_type('application/json'); } }
function url($skip_ajax = false) { if ($skip_ajax == false) { $is_ajax = isAjax(); if ($is_ajax == false) { } else { if ($_SERVER['HTTP_REFERER'] != false) { return $_SERVER['HTTP_REFERER']; } else { } } } $pageURL = 'http'; if (isset($_SERVER["HTTPS"])) { if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL; }
/** * List all the users. * * It receives 2 post parameters with ajax call for user filteration * * @return settings/user view */ public function users() { $data['current_role'] = $currentRoleID = $this->role_id; $data['is_ajax'] = FALSE; $roles = $this->roles->get_roles_list($currentRoleID)->result(); $params = null; if (isAjax()) { $data['is_ajax'] = TRUE; $params = array('station_id' => $this->input->post('station_id'), 'role_id' => $this->input->post('role_id')); } $data['users'] = $this->users->get_users($currentRoleID, $params)->result(); $data['roles'][''] = 'Select'; $data['stations'][''] = 'Select'; foreach ($roles as $value) { $data['roles'][$value->id] = $value->name; } $stations = $this->station_model->get_all(); foreach ($stations as $value) { $data['stations'][$value->id] = $value->station_name; } if (isAjax()) { echo $this->load->view('settings/user', $data, TRUE); exit_function(); } $this->load->view('settings/user', $data); }
public function actionLogin() { $model = $this->createModel('LoginForm'); if (isPostOrAjaxRequest()) { if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate()) { $model->login(); } if (isAjax()) { if ($model->hasErrors()) { // was validation errors $this->validationErrorsAjaxResponse($model, FALSE); } else { // success if (Yii::app()->user->returnUrl) { $response['redirect'] = Yii::app()->user->returnUrl; } else { $response['redirect'] = $this->createUrl('index'); } $this->successfulAjaxResponse($response); } } else { $this->setModel($model); } } } $this->setLayout('login-backend'); $this->render('login', array('model' => $this->getModel())); }
/** * Dump function * * @param mixed $var * @param int $dump * @param int $trace */ function qqq($var, $dump = 0, $trace = 0) { ob_start(); if ($dump == 2) { var_export($var); } elseif ($dump == 1) { var_dump($var); } else { print_r($var); } if ($trace == 1) { echo PHP_EOL; $e = new Exception(); echo $e->getTraceAsString(); } elseif ($trace == 2) { echo PHP_EOL; debug_print_backtrace(); } $res = ob_get_contents(); ob_end_clean(); if (!isAjax() && !extension_loaded('xdebug') && $dump == 1) { $res = htmlspecialchars($res); } if (!isset($_SERVER['argv']) || !$_SERVER['argv']) { echo PHP_EOL . (!isAjax() ? '<pre>' : '/*'), $res, !isAjax() ? '</pre>' : '*/'; } else { echo PHP_EOL, ' ', $res; } }
public function redirect($param = null) { if (is_null($param)) { $param = '/'; } if (!is_array($param)) { $param = ['location' => $param]; } if (isAjax()) { // если идет вызов редиректа при ajax-запросе, // то значит сессия устарела // но работе это мешать не должно return; } $location = get_param($param, 'location', '/'); if (get_param($param, 'back') === 1) { $location = get_param($_SERVER, 'HTTP_REFERER', $location); } if (get_param($param, 'soft') === 1) { $delay = get_param($param, 'delay', 3); printf('<meta http-equiv="refresh" content="%d; url=%s">', $delay, $location); } else { header("Location: {$location}"); die; } }
public function actionLoginHandler() { $model = new LoginForm(); if (isPostOrAjaxRequest()) { if (isset($_POST['LoginForm'])) { $model->attributes = $_POST['LoginForm']; if ($model->validate()) { if (!$model->isUserBanned()) { $model->login(); } else { $response['redirect'] = $this->createUrl('banned'); $this->successfulAjaxResponse($response); } } if (isAjax()) { if ($model->hasErrors()) { $this->validationErrorsAjaxResponse($model, FALSE); } else { $response['redirect'] = Yii::app()->getRequest()->getUrlReferrer(); $this->successfulAjaxResponse($response); } } } } }
/** * Ends an ajax-age * * @return string returns the end of an ajax-div */ public static function endAjax() { if (isAjax()) { exit; } else { return '</div>'; } }
function pajax() { if (isAjax() && isset($_POST['pajax'])) { echo "<!-- Loaded via Pajax -->"; echo get_page_content(); // Please let me know if you know of a better way to do this than die(). die; } }
/** * Load Facet sidebar for both assets tab and instantations tab. * * @return view */ function load_facet_columns() { if (isAjax()) { $is_all_facet = $this->input->post('issearch'); $index = $this->input->post('index'); $this->load->library('sphnixrt'); if ($is_all_facet > 0 || $this->is_station_user) { $states = $this->sphinx->facet_index('state', $index); $data['org_states'] = sortByOneKey($states['records'], 'state'); unset($states); $stations = $this->sphinx->facet_index('organization', $index); $data['stations'] = sortByOneKey($stations['records'], 'organization'); unset($stations); $nomination = $this->sphinx->facet_index('status', $index); $data['nomination_status'] = sortByOneKey($nomination['records'], 'status'); unset($nomination); $media_type = $this->sphinx->facet_index('media_type', $index); $media_type = $this->make_facet($media_type, 'media_type', 'media_type'); $data['media_types'] = sortByOneKey($media_type, 'media_type', TRUE); unset($media_type); $p_format = $this->sphinx->facet_index('physical_format_name', $index, 'physical'); $p_format = $this->make_facet($p_format, 'physical_format_name', 'physical_format'); $data['physical_formats'] = sortByOneKey($p_format, 'physical_format_name', TRUE); unset($p_format); $d_format = $this->sphinx->facet_index('digital_format_name', $index, 'digital'); $d_format = $this->make_facet($d_format, 'digital_format_name', 'digital_format'); $data['digital_formats'] = sortByOneKey($d_format, 'digital_format_name', TRUE); unset($d_format); $generation = $this->sphinx->facet_index('facet_generation', $index); $generation = $this->make_facet($generation, 'facet_generation', 'generation'); $data['generations'] = sortByOneKey($generation, 'facet_generation', TRUE); unset($generation); $digitized = $this->sphinx->facet_index('digitized', $index, 'digitized'); $data['digitized'] = $digitized['records']; $migration = $this->sphinx->facet_index('migration', $index, 'migration'); $data['migration'] = $migration['records']; } else { if ($index == 'assets_list') { $key_name = 'asset'; } else { $key_name = 'ins'; } $data['org_states'] = json_decode($this->memcached_library->get($key_name . '_state'), TRUE); $data['stations'] = json_decode($this->memcached_library->get($key_name . '_stations'), TRUE); $data['nomination_status'] = json_decode($this->memcached_library->get($key_name . '_status'), TRUE); $data['media_types'] = json_decode($this->memcached_library->get($key_name . '_media_type'), TRUE); $data['physical_formats'] = json_decode($this->memcached_library->get($key_name . '_physical'), TRUE); $data['digital_formats'] = json_decode($this->memcached_library->get($key_name . '_digital'), TRUE); $data['generations'] = json_decode($this->memcached_library->get($key_name . '_generations'), TRUE); $data['digitized'] = json_decode($this->memcached_library->get($key_name . '_digitized'), TRUE); $data['migration'] = json_decode($this->memcached_library->get($key_name . '_migration'), TRUE); } echo $this->load->view('instantiations/_facet_columns', $data, TRUE); exit_function(); } show_404(); }
public function auto_complete($str_q = NULL) { $this->load->model('zanox_model'); $this->load->model('product_model'); $arr = $this->product_model->get_auto_complete_terms($str_q); if (!isAjax()) { show_404(); } echo json_encode($arr, true); }
/** 输出调试信息 * @param $str string or array 输出内容 * @return string */ function outPut($str) { if (isAjax()) { return false; } if (is_array($str)) { $str = var_export($str, true); } echo '<div style="border:1px #996600 solid; padding:5px; margin:10px; background:#F1EBEE; font-size:12px"><pre>' . $str . '</pre></div>'; }
/** * Redirect to URL or close dialog. * * @param string $url * @param bool $dialogRedirect If true, this will redirect dialogs as well, otherwise just close the dialog. */ public static function redirect($url, $dialogRedirect = true) { $url = (string) $url; $redirectJs = '<script type="text/javascript">window.location.href = ' . json_encode($url) . ';</script>'; if (isAjax()) { // we're in a dialog, use javascript to redirect self::returnPartial($dialogRedirect ? $redirectJs : ''); } else { throw new ResponseException(RedirectResponse::create($url)); } }
/** * Return true if client sent an Accept header with application/json or * if the request is AJAX (in which case we assume that the client wants to see * JSON) * @return bool */ function wantsJson() { $hdr = false; $hdrs = getallheaders(); foreach ($hdrs as $k => $v) { if ($k == "Accept" && strstr($v, "application/json") !== false) { $hdr = true; break; } } return $hdr || isAjax(); }
function error_redirect($extra, $flash = "") { if (isAjax()) { if (wantsScript()) { die("alert(\"" . addslashes($flash) . "\");"); } else { die("<script>alert(\"" . addslashes($flash) . "\");</script>"); } } else { redirect($extra, $flash); } }
function APIData($data = '') { $statusCode = 200; if (isset($data['error'])) { $statusCode = 400; $data['_status_'] = $statusCode; } if (isAjax()) { return response(json_encode($data), $statusCode)->header('Access-Control-Allow-Origin', '*')->header('Content-Type', 'application/json'); } else { return $data; } }
/** * Vtiger specific custom config startup for CSRF */ function csrf_startup() { //Override the default expire time of token $GLOBALS['csrf']['expires'] = 259200; /**if an ajax request initiated, then if php serves content with <html> tags * as a response, then unnecessarily we are injecting csrf magic javascipt * in the response html at <head> and <body> using csrf_ob_handler(). * So, to overwride above rewriting we need following config. */ if (isAjax()) { $GLOBALS['csrf']['frame-breaker'] = false; $GLOBALS['csrf']['rewrite-js'] = null; } }
public function runMultilingual() { // check if action is configured $this->checkConditions(array('updateRecordId', 'formModelClass', 'tableModelClass', 'nonAjaxRedirectUrl')); $model = $this->getController()->createModel($this->formModelClass); $model->setTableModelClassName($this->tableModelClass); // load data to model via model method $model->loadData($this->updateRecordId); $this->getController()->setModel($model); $this->getController()->processUpdate(); if (!isAjax()) { $this->redirect($this->nonAjaxRedirectUrl); } }
function delete() { $id = $this->input->post('id') ? (int) $this->input->post('id') : $this->uri->segment(3); if ($this->clientcontacts_model->deleteClientContact($id)) { if (isAjax()) { return $id; } else { $this->session->set_flashdata('clientContact', $id); redirect('clients/'); } } else { $this->session->set_flashdata('message', $this->lang->line('clients_contact_delete_fail')); redirect('clients/'); } }
protected function _checkLogin($returnBool = false) { if (steadmin::$adminInfo['user_id']) { return true; } else { if ($returnBool) { return false; } elseif (isAjax()) { return $this->JsonReturn('必须登录后才能进行此操作'); } else { jumpTo(U('login/index')); } return $returnBool ? false : jumpTo(U('login/index')); } }
function do_upgrade() { if (!isAjax() && !$this->input->is_cli_request()) return FALSE; $row = $this->db->get('migrations')->row(); $current = $row->version + 1; //if ($current <= $this->config->item('migration_version')) { $this->migration->latest(); //} if ($this->input->is_cli_request()) echo _('Successfully updated the database.') . PHP_EOL; else echo json_encode(array('href' => site_url('admin/'))); return TRUE; }
function do_upgrade() { if (!isAjax() && !$this->input->is_cli_request()) { return FALSE; } // migrate $this->migration->latest(); // give the correct kind of output, be it JSON via javascript or CLI request if ($this->input->is_cli_request()) { $this->output->set_output(_('Successfully updated the database.') . PHP_EOL); } else { $this->output->set_output(json_encode(array('href' => site_url('admin/')))); } // give the url to go back to return TRUE; }
public function runMultilingual() { // check if action is configured $this->checkConditions(array('model', 'deleteCriteria', 'deleteParams', 'nonAjaxRedirect')); $models = $this->model->findAll($this->deleteCriteria, $this->deleteParams); if (!empty($models)) { foreach ($models as $model) { $model->delete(); } } if (isAjax()) { $this->getController()->successfulAjaxResponse(); } else { $this->getController()->redirect($this->nonAjaxRedirect); } }
public function index($id = null, $first = null, $jenis = '') { if ($id != null) { $data['comment'] = $this->Commentmodel->getcomment($id, $jenis); } if (!empty($data['comment'])) { foreach ($data['comment'] as $idhis => $datahis) { $data['comment'][$idhis]['reply'] = $this->Commentmodel->getcommentreply($datahis['id']); } } foreach ($data['comment'] as $ky => $dt) { if ($dt['id_group'] == 12) { $id_siswa[] = $dt['id_user']; } else { $id_pegawai[] = $dt['id_user']; } $data['comment'][$ky]['date'] = $this->getday($dt['date']); foreach ($dt['reply'] as $ky1 => $dt1) { if ($dt1['id_group'] == 12) { $id_siswa[] = $dt1['id_user']; } else { $id_pegawai[] = $dt1['id_user']; } $data['comment'][$ky]['reply'][$ky1]['date'] = $this->getday($dt1['date']); } } //echo "<pre>"; //pr($id_siswa); //pr($id_pegawai); //dapatkan foto $foto = $this->Commentmodel->getcommentfoto($id_siswa, $id_pegawai); //pr($foto); //echo "</pre>"; //echo $this->getday(); $data['first'] = $first; $data['jenis'] = $jenis; $data['foto'] = $foto; $data['id'] = $id; $data['main'] = 'akademik/comment/index'; if (isAjax()) { $this->load->view('layout/ad_blank', $data); } else { $this->load->view('layout/ad_adminsekolah', $data); } }
public static function handleException($e) { $err_code = $e->getCode(); $err_message = $e->getMessage(); $err_file = $e->getFile(); $err_line = $e->getLine(); if (IS_DEBUG) { self::$_errors[] = '==== handleException ===='; self::$_errors[] = array('code' => $err_code, 'message' => $err_message, 'file' => $err_file, 'line' => $err_line, 'trace' => $e->getTrace()); // Exception 终止运行,故在此输出错误信息 self::showErrors(); } else { IS_CLI ? print $err_message : (isAjax() ? ajaxReturn(0, '服务器端错误') : redirect(SITE_URI . '/error.html')); } // 转换为相对路径,降低log 长度=。=! $err_file = str_replace(APPLICATION_PATH, '', $err_file); Core_Log::getInstance()->error("{$err_message} CODE:{$err_code} FILE:{$err_file} LINE:{$err_line}"); }
public function login($uname, $pwd) { if (isAjax()) { if ($uname == '*****@*****.**' && $pwd == 'mayrand') { if (!isset($this->session->userdata['admin'])) { $this->session->set_userdata(array('lang' => 'fr')); $this->session->set_userdata(array('admin' => 'admin')); $user = $this->users_model->get_name($uname); $this->session->set_userdata('name', $user[0]->first_name . ' ' . $user[0]->family_name); } echo 1; } else { echo 0; } } else { echo 0; } }
public function run() { // check if all necessary properties are set $this->checkConditions(array('model', 'listHeaders', 'primaryField')); $modelClass = get_class($this->model); $actionCreateUrl = $this->getProperUrl($this->actionCreateUrl, $this->actionCreate); $actionEditUrl = $this->getProperUrl($this->actionEditUrl, $this->actionEdit); $actionDeleteUrl = $this->getProperUrl($this->actionDeleteUrl, $this->actionDelete); $actionGroupEditUrl = $this->getProperUrl($this->actionGroupEditUrl, $this->actionGroupEdit); $actionGroupDeleteUrl = $this->getProperUrl($this->actionGroupDeleteUrl, $this->actionGroupDelete); if (isAjax()) { if (isset($_GET[$modelClass])) { $this->model->attributes = $_GET[$modelClass]; } $this->getController()->renderPartial($this->partialView, array('model' => $this->model, 'listHeaders' => $this->listHeaders, 'listFilters' => $this->listFilters, 'primaryField' => $this->primaryField, 'widgetWrapperId' => $this->widgetWrapperId, 'widgetFormId' => $this->widgetFormId, 'groupingCheckboxName' => $this->groupingCheckboxName, 'skipScripts' => TRUE, 'rowCellsGetterMethod' => $this->rowCellsGetterMethod, 'dataProviderGetterMethod' => $this->dataProviderGetterMethod, 'actionCreateUrl' => $actionCreateUrl, 'actionEditUrl' => $actionEditUrl, 'actionDeleteUrl' => $actionDeleteUrl, 'actionGroupEditUrl' => $actionGroupEditUrl, 'actionGroupDeleteUrl' => $actionGroupDeleteUrl, 'actionCreate' => $this->actionCreate, 'actionEdit' => $this->actionEdit, 'actionDelete' => $this->actionDelete, 'actionGroupEdit' => $this->actionGroupEdit, 'actionGroupDelete' => $this->actionGroupDelete)); } else { $this->getController()->render($this->view, array('partialView' => $this->partialView, 'model' => $this->model, 'listHeaders' => $this->listHeaders, 'listFilters' => $this->listFilters, 'primaryField' => $this->primaryField, 'pageTitle' => $this->pageTitle, 'listTitle' => $this->listTitle, 'widgetWrapperId' => $this->widgetWrapperId, 'widgetFormId' => $this->widgetFormId, 'groupingCheckboxName' => $this->groupingCheckboxName, 'skipScripts' => FALSE, 'rowCellsGetterMethod' => $this->rowCellsGetterMethod, 'dataProviderGetterMethod' => $this->dataProviderGetterMethod, 'actionCreateUrl' => $actionCreateUrl, 'actionEditUrl' => $actionEditUrl, 'actionDeleteUrl' => $actionDeleteUrl, 'actionGroupEditUrl' => $actionGroupEditUrl, 'actionGroupDeleteUrl' => $actionGroupDeleteUrl, 'actionCreate' => $this->actionCreate, 'actionEdit' => $this->actionEdit, 'actionDelete' => $this->actionDelete, 'actionGroupEdit' => $this->actionGroupEdit, 'actionGroupDelete' => $this->actionGroupDelete)); } }
public function message($info, $state = 1, $url = '', $data = array()) { if (isAjax()) { $result = array(); $result['state'] = $state; $result['info'] = $info; $result['url'] = $url; $result['data'] = $data; header('Content-Type:text/html; charset=utf-8'); exit(json_encode($result)); } if (empty($url) && isset($_SERVER["HTTP_REFERER"])) { $url = $_SERVER["HTTP_REFERER"]; } $this->view(); $this->view->assign('time', 3); $this->view->assign('url', $url); $this->view->assign('state', $state); $this->view->assign('info', $info); $this->view->display('_message'); exit; }
function installPajaxInTheme() { if (!isAjax() || !isset($_GET['pajaxThemeInstall'])) { return; } $theme = $_GET['pajaxThemeInstall']; echo "<br/><b>***************************** modifying {$theme} *****************************</b><br />"; //$theme="mycompany"; $themeFiles = rglob("*.php", 0, GSTHEMESPATH . $theme); $cBefore = "echo '<span class=\"pajaxContent\">';"; $tBefore = "echo '<span class=\"pajaxTitle\">';"; $nBefore = "echo '<span class=\"pajaxNav\">';"; $after = "echo '</span>';"; $find = array("get_page_content();", "get_page_title();", "get_page_clean_title();", "get_navigation();", "get_navigation(return_page_slug());", "get_i18n_navigation();", "my_get_navigation(return_page_slug(FALSE));", "get_navigation(get_page_slug(FALSE));", "get_nested_navigation();"); $replace = array($cBefore . "get_page_content();" . $after, $tBefore . "get_page_title();" . $after, $tBefore . "get_page_clean_title();" . $after, $nBefore . "get_navigation();" . $after, $nBefore . "get_navigation(return_page_slug());" . $after, $nBefore . "get_i18n_navigation();" . $after, $nBefore . "my_get_navigation(return_page_slug(FALSE));" . $after, $nBefore . "get_navigation(get_page_slug(FALSE));" . $after, $nBefore . "get_nested_navigation();" . $after); $time_start = microtime(); foreach ($themeFiles as $file) { openReplace($file, $find, $replace); } $time_end = microtime(); $time = $time_end - $time_start; die("all theme files searched and modified in {$time} microseconds <br /><hr />"); }
if (!empty($_POST)) { /* hash */ unset($error_bucket); /* simple error list */ unset($input_errors); unset($do_action); $reqdfields = explode(" ", "action object"); $reqdfieldsn = explode(",", "Action,Object"); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); if (is_array($error_bucket)) { foreach ($error_bucket as $elem) { $input_errors[] =& $elem["error"]; } } /* if this is an AJAX caller then handle via JSON */ if (isAjax() && is_array($error_bucket)) { input_errors2Ajax(NULL, $error_bucket); exit; } if (!$input_errors) { $do_action = true; $action = $_POST['action']; $object = $_POST['object']; } } if (!isset($do_action)) { $do_action = false; $action = ''; $object = ''; } include "head.inc";