public static function setMySQLServerTime($offset = "-0:00") { pjAppModel::factory()->prepare("SET SESSION time_zone = :offset;")->exec(compact('offset')); }
public function pjActionExport() { $this->setAjax(true); $this->setLayout('pjActionEmpty'); if (isset($_POST['export']) && isset($_POST['separator']) && $this->isLoged() && $this->isAdmin()) { @set_time_limit(600); //10 min $name = 'pjLocale-' . time(); $AppModel = pjAppModel::factory(); $pjFieldModel = pjFieldModel::factory(); $pjMultiLangModel = pjMultiLangModel::factory(); $locale_arr = pjLocaleModel::factory()->select('t1.*, t2.title')->join('pjLocaleLanguage', 't2.iso=t1.language_iso')->orderBy('t1.sort ASC')->findAll()->getDataPair('id'); if (empty($locale_arr)) { exit; } $multi_lang_arr = $pjMultiLangModel->select('t1.locale, t1.content, t2.id, t2.key')->join('pjField', 't2.id=t1.foreign_id', 'left outer')->where('t1.model', 'pjField')->where('t1.field', 'title')->whereIn('t1.locale', array_keys($locale_arr))->where('t1.source !=', 'data')->findAll()->getData(); if (empty($multi_lang_arr)) { exit; } $export_arr = array(); foreach ($multi_lang_arr as $k => $item) { if (!isset($export_arr[$item['id']])) { $export_arr[$item['id']] = array('key' => $item['key'], 'locales' => array()); } $export_arr[$item['id']]['locales'][$item['locale']] = $item['content']; } $csv = array(); $separators = array('comma' => ",", 'semicolon' => ";", 'tab' => "\t"); $separator = $separators[$_POST['separator']]; $header = array('id', 'key'); foreach ($locale_arr as $id => $data) { $header[] = $id . '::' . $data['title']; } $csv[] = join($separator, $header); foreach ($export_arr as $id => $data) { $cells = array(); $cells[] = '"' . (int) $id . '"'; $cells[] = '"' . str_replace(array("\r\n", "\n", "\t", '"'), array('\\n', '\\n', '\\t', '""'), $data['key']) . '"'; foreach ($locale_arr as $locale_id => $item) { if (isset($data['locales'][$locale_id])) { $cells[] = '"' . str_replace(array("\r\n", "\n", "\t", '"'), array('\\n', '\\n', '\\t', '""'), $data['locales'][$locale_id]) . '"'; } else { $cells[] = '""'; } } $csv[] = "\n"; $csv[] = join($separator, $cells); } $content = join("", $csv); pjToolkit::download($content, $name . '.csv'); } exit; }
public function pjActionSecureSetUpdate() { $this->setAjax(true); if ($this->isXHR() && $this->isLoged()) { # Next will init dbo pjAppModel::factory(); $dbo = NULL; $registry = pjRegistry::getInstance(); if ($registry->is('dbo')) { $dbo = $registry->get('dbo'); } if (!isset($_REQUEST['module'])) { pjAppController::jsonResponse(array('status' => 'ERR', 'code' => 100, 'text' => 'Module parameter is missing.')); } switch ($_REQUEST['module']) { case 'plugin': $pattern = '|^' . str_replace('\\', '/', PJ_PLUGINS_PATH) . '|'; break; case 'script': default: $pattern = '|^app/config/updates|'; break; } if (isset($_POST['path']) && !empty($_POST['path'])) { if (preg_match($pattern, str_replace('\\', '/', $_POST['path']))) { $response = self::pjActionExecuteSQL($dbo, $_POST['path']); pjAppController::jsonResponse($response); } else { pjAppController::jsonResponse(array('status' => 'ERR', 'code' => 100, 'text' => 'Filename pattern doesn\'t match.')); } } if (isset($_POST['record']) && !empty($_POST['record'])) { foreach ($_POST['record'] as $record) { if (!preg_match($pattern, str_replace('\\', '/', $record))) { continue; } $response = self::pjActionExecuteSQL($dbo, $record); if ($response['status'] == 'ERR') { pjAppController::jsonResponse($response); } } pjAppController::jsonResponse($response); } } exit; }