public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do batch processing // if ($req->isLoggedIn()) { set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble if (isset($this->opa_options['isBatchDelete']) && $this->opa_options['isBatchDelete']) { $va_errors = BatchProcessor::deleteBatchForSet($this->request, $this->ot_set, $this->ot_subject, array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchEditorProgress', 'reportCallback' => 'caCreateBatchEditorResultsReport'))); } elseif (isset($this->opa_options['isBatchTypeChange']) && $this->opa_options['isBatchTypeChange']) { $va_errors = BatchProcessor::changeTypeBatchForSet($this->request, $this->opa_options['type_id'], $this->ot_set, $this->ot_subject, array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchEditorProgress', 'reportCallback' => 'caCreateBatchEditorResultsReport'))); } else { $va_errors = BatchProcessor::saveBatchEditorFormForSet($this->request, $this->ot_set, $this->ot_subject, array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchEditorProgress', 'reportCallback' => 'caCreateBatchEditorResultsReport'))); } } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do reindexing // if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) { set_time_limit(3600 * 8); $o_db = new Db(); $t_timer = new Timer(); $o_dm = Datamodel::load(); $va_table_names = $o_dm->getTableNames(); $vn_tc = 0; foreach ($va_table_names as $vs_table) { if ($o_instance = $o_dm->getInstanceByTableName($vs_table)) { if ($o_instance->isHierarchical()) { if (!$o_instance->rebuildAllHierarchicalIndexes()) { $o_instance->rebuildHierarchicalIndex(); } } caIncrementHierachicalReindexProgress(_t('Rebuilding hierarchical index for %1', $o_instance->getProperty('NAME_PLURAL')), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $o_instance->tableNum(), $o_instance->getProperty('NAME_PLURAL'), $vn_tc + 1); } $vn_tc++; } caIncrementHierachicalReindexProgress(_t('Index rebuild complete!'), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, null, null, sizeof($va_table_names)); } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do batch processing // if ($req->isLoggedIn()) { set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble if (isset($_FILES['sourceFile']['tmp_name']) && $_FILES['sourceFile']['tmp_name']) { $vs_input = $_FILES['sourceFile']['tmp_name']; } elseif (!($vs_input = $req->getParameter('sourceUrl', pString))) { $vs_input = $req->getParameter('sourceText', pString); } $vs_file_input = caGetOption('fileInput', $this->opa_options, null); $vs_base_import_dir = $req->config->get('batch_media_import_root_directory'); $vs_file_import_directory = caGetOption('fileImportPath', $this->opa_options, null); if ($vs_file_input === 'import' && is_dir($vs_base_import_dir . '/' . $vs_file_import_directory)) { // grab files from import directory $vs_input = $vs_base_import_dir . '/' . $vs_file_import_directory; } $va_errors = BatchProcessor::importMetadata($req, $vs_input, $req->getParameter('importer_id', pInteger), $req->getParameter('inputFormat', pString), array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchMetadataImportProgress', 'reportCallback' => 'caUpdateBatchMetadataImportResultsReport'))); } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do export // if ($req->isLoggedIn()) { set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble $vn_id = $req->getParameter('exporter_id', pInteger); $vs_search = $req->getParameter('search', pString); $t_exporter = new ca_data_exporters($vn_id); $vs_file = tempnam(caGetTempDirPath(), 'export'); ca_data_exporters::exportRecordsFromSearchExpression($t_exporter->get('exporter_code'), $vs_search, $vs_file, array('request' => $req, 'progressCallback' => 'caIncrementBatchMetadataExportProgress')); } // export done, move file to application tmp dir and create download link (separate action in the export controller) if (filesize($vs_file)) { $vs_new_filename = $vn_id . "_" . md5($vs_file); rename($vs_file, __CA_APP_DIR__ . '/tmp/' . $vs_new_filename); caExportAddDownloadLink($req, $vs_new_filename); } }
/** * Get request object for current request. Returns null if no request is available * (if, for example, the plugin is being run in a batch script - scripts don't use the request/response model) * * @return Request object or null if no request object is available */ public function getRequest() { if (($o_app = AppController::getInstance()) && ($o_req = $o_app->getRequest())) { return $o_req; } return null; }
public function __construct($ps_widget_path, $pa_settings) { $this->ops_widget_path = $ps_widget_path; if (is_array($pa_settings)) { $this->opa_settings = $pa_settings; } if (AppController::instanceExists() && ($o_app = AppController::getInstance()) && ($o_req = $o_app->getRequest())) { $this->request = $o_req; } }
public function __construct(&$po_request, &$po_response, $pa_view_paths = null) { parent::__construct($po_request, $po_response, $pa_view_paths); // we don't want headers or footers output for feeds $app = AppController::getInstance(); $app->removeAllPlugins(); // kills the pageFormat plugin added in /index.php // set http content-type header to XML $this->response->addHeader('Content-type', 'text/xml', true); }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do export // if (!$req->isLoggedIn()) { return; } set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble $vn_id = $req->getParameter('exporter_id', pInteger); $t_exporter = new ca_data_exporters($vn_id); $vs_file = tempnam(__CA_APP_DIR__ . DIRECTORY_SEPARATOR . 'tmp', 'dataExport'); // we have 3 different sources for batch exports: search/browse result, sets and search expressions (deprecated) // they all operate on different parameters and on different static functions in ca_data_exporters if ($req->getParameter('caIsExportFromSearchOrBrowseResult', pInteger)) { // batch export from search or browse result $vs_find_type = $req->getParameter('find_type', pString); $vo_result_context = new ResultContext($req, $t_exporter->getTargetTableName(), $vs_find_type); $t_instance = $t_exporter->getTargetTableInstance(); $o_result = $t_instance->makeSearchResult($t_instance->tableName(), $vo_result_context->getResultList()); ca_data_exporters::exportRecordsFromSearchResult($t_exporter->get('exporter_code'), $o_result, $vs_file, array('request' => $req, 'progressCallback' => 'caIncrementBatchMetadataExportProgress')); } else { if ($vn_set_id = $req->getParameter('set_id', pInteger)) { // batch export from set ca_data_exporters::exportRecordsFromSet($t_exporter->get('exporter_code'), $vn_set_id, $vs_file, array('request' => $req, 'progressCallback' => 'caIncrementBatchMetadataExportProgress')); } else { // batch export from search expression (deprecated) $vs_search = $req->getParameter('search', pString); ca_data_exporters::exportRecordsFromSearchExpression($t_exporter->get('exporter_code'), $vs_search, $vs_file, array('request' => $req, 'progressCallback' => 'caIncrementBatchMetadataExportProgress')); } } // export done, record it in session for later usage in download/destination action if (filesize($vs_file)) { $o_session = $req->getSession(); $o_session->setVar('export_file', $vs_file); $o_session->setVar('export_content_type', $t_exporter->getContentType()); $o_session->setVar('exporter_id', $t_exporter->getPrimaryKey()); caExportAddDownloadLink($req); } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do batch processing // if ($req->isLoggedIn()) { set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble $va_errors = BatchProcessor::importMetadata($req, isset($_FILES['sourceFile']['tmp_name']) && $_FILES['sourceFile']['tmp_name'] ? $_FILES['sourceFile']['tmp_name'] : $req->getParameter('sourceUrl', pString), $req->getParameter('importer_id', pInteger), $req->getParameter('inputFormat', pString), array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchMetadataImportProgress', 'reportCallback' => 'caUpdateBatchMetadataImportResultsReport'))); } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do batch processing // if ($req->isLoggedIn()) { set_time_limit(3600 * 24); // if it takes more than 24 hours we're in trouble $va_errors = BatchProcessor::importMediaFromDirectory($this->request, array_merge($this->opa_options, array('progressCallback' => 'caIncrementBatchMediaImportProgress', 'reportCallback' => 'caCreateBatchMediaImportResultsReport'))); } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do reindexing // if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) { set_time_limit(3600 * 8); $o_si = new SearchIndexer(); $o_si->reindex(null, array('showProgress' => false, 'interactiveProgressDisplay' => false, 'callback' => "caIncrementSearchReindexProgress")); } }
/** * */ function caDisplayFatalError($pn_errno, $ps_errstr, $ps_errfile, $pn_errline, $pa_symboltable) { $pa_errcontext = debug_backtrace(); array_shift($pa_errcontext); // remove entry for error handler $pa_errcontext_args = caExtractStackTraceArguments($pa_errcontext); $pa_request_params = caExtractRequestParams(); switch ($pn_errno) { case E_WARNING: case E_NOTICE: case E_STRICT: case E_DEPRECATED: //print "ARGH: $ps_errstr<br>"; break; default: if (class_exists('AppController')) { AppController::getInstance()->removeAllPlugins(); } require_once (defined("__CA_THEME_DIR__") ? __CA_THEME_DIR__ : __DIR__ . "/../../themes/default") . "/views/system/fatal_error_html.php"; exit; } }
public function preDispatch() { if (!$this->getRequest()->config->get('do_content_caching')) { return null; } // does this need to be cached? if ($vs_key = $this->getKeyForRequest()) { // is this cached? if ($this->opo_content_cache->isInCache($vs_key)) { // yep... so prevent dispatch and output cache in postDispatch $this->opb_output_from_cache = true; $app = AppController::getInstance(); $app->removeAllPlugins(); $o_dispatcher = $app->getDispatcher(); $o_dispatcher->setPlugins(array($this)); return array('dont_dispatch' => true); } else { // not cached so dispatch and cache in postDispatch $this->opb_needs_to_be_cached = true; } } return null; }
$o_db = new Db(null, null, false); if (!$o_db->connected()) { $opa_error_messages = array("Could not connect to database. Check your database configuration in <em>setup.php</em>."); require_once __CA_BASE_DIR__ . "/themes/default/views/system/configuration_error_html.php"; exit; } // // do a sanity check on application and server configuration before servicing a request // require_once __CA_APP_DIR__ . '/lib/pawtucket/ConfigurationCheck.php'; ConfigurationCheck::performQuick(); if (ConfigurationCheck::foundErrors()) { ConfigurationCheck::renderErrorsAsHTMLOutput(); exit; } $app = AppController::getInstance(); $g_request = $app->getRequest(); $resp = $app->getResponse(); // TODO: move this into a library so $_, $g_ui_locale_id and $g_ui_locale gets set up automatically require_once __CA_APP_DIR__ . "/helpers/initializeLocale.php"; $va_ui_locales = $g_request->config->getList('ui_locales'); if ($vs_lang = $g_request->getParameter('lang', pString)) { if (in_array($vs_lang, $va_ui_locales)) { $g_request->session->setVar('lang', $vs_lang); } } if (!($g_ui_locale = $g_request->session->getVar('lang'))) { $g_ui_locale = $va_ui_locales[0]; } if (!in_array($g_ui_locale, $va_ui_locales)) { $g_ui_locale = $va_ui_locales[0];
* * This program is free software; you may redistribute it and/or modify it under * the terms of the provided license as published by Whirl-i-Gig * * CollectiveAccess is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This source code is free and modifiable under the terms of * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See * the "license.txt" file for details, or visit the CollectiveAccess web site at * http://www.CollectiveAccess.org * * ---------------------------------------------------------------------- */ AppController::getInstance()->removeAllPlugins(); ?> <html> <head> <title><?php print $this->request->config->get("app_display_name"); ?> </title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link href="<?php print $this->request->getThemeUrlPath(); ?> /css/login.css" rel="stylesheet" type="text/css" /> <?php print AssetLoadManager::getLoadHTML($this->request);
public function process($pa_parameters) { $o_response = new ResponseHTTP(); $o_request = new RequestHTTP($o_response, array('simulateWith' => $x = array('POST' => $pa_parameters['values'], 'SCRIPT_NAME' => join('/', array(__CA_URL_ROOT__, 'index.php')), 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => join('/', array(__CA_URL_ROOT__, 'index.php', 'batch', 'Editor', 'Save', $pa_parameters['screen'], 'set_id', $pa_parameters['set_id'])), 'PATH_INFO' => '/' . join('/', array('batch', 'Editor', 'Save', $pa_parameters['screen'], 'set_id', $pa_parameters['set_id'])), 'REMOTE_ADDR' => $pa_parameters['ip_address'], 'HTTP_USER_AGENT' => 'batchEditor', 'user_id' => $pa_parameters['user_id']))); $o_app = AppController::getInstance($o_request, $o_response); $t_set = new ca_sets($pa_parameters['set_id']); $o_dm = Datamodel::load(); $t_subject = $o_dm->getInstanceByTableNum($t_set->get('table_num')); $va_report = BatchProcessor::saveBatchEditorFormForSet($o_request, $t_set, $t_subject, array('sendMail' => (bool) $pa_parameters['sendMail'], 'sendSMS' => (bool) $pa_parameters['sendSMS'])); return $va_report; }
public function process($pa_parameters) { $o_response = new ResponseHTTP(); $o_request = new RequestHTTP($o_response, array('simulateWith' => array('POST' => $pa_parameters['values'], 'SCRIPT_NAME' => join('/', array(__CA_URL_ROOT__, 'index.php')), 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => join('/', array(__CA_URL_ROOT__, 'index.php', 'batch', 'MediaImport', 'Save', $pa_parameters['screen'])), 'PATH_INFO' => '/' . join('/', array('batch', 'MediaImport', 'Save', $pa_parameters['screen'])), 'REMOTE_ADDR' => $pa_parameters['ip_address'], 'HTTP_USER_AGENT' => 'mediaImport', 'user_id' => $pa_parameters['user_id']))); $o_app = AppController::getInstance($o_request, $o_response); $va_report = BatchProcessor::importMediaFromDirectory($o_request, $pa_parameters); return $va_report; }
/** * HTML Form element generation * Optional name parameter allows you to generate a form element for a field but give it a * name different from the field name * * @param string $ps_field field name * @param string $ps_format field format * @param array $pa_options additional options * TODO: document them. */ public function htmlFormElement($ps_field, $ps_format = null, $pa_options = null) { $o_db = $this->getDb(); // init options if (!is_array($pa_options)) { $pa_options = array(); } foreach (array('display_form_field_tips', 'classname', 'maxOptionLength', 'textAreaTagName', 'display_use_count', 'display_omit_items__with_zero_count', 'display_use_count_filters', 'display_use_count_filters', 'selection', 'name', 'value', 'dont_show_null_value', 'size', 'multiple', 'show_text_field_for_vars', 'nullOption', 'empty_message', 'displayMessageForFieldValues', 'DISPLAY_FIELD', 'WHERE', 'select_item_text', 'hide_select_if_only_one_option', 'field_errors', 'display_form_field_tips', 'form_name', 'no_tooltips', 'tooltip_namespace', 'extraLabelText', 'width', 'height', 'label', 'list_code', 'hide_select_if_no_options', 'id', 'lookup_url', 'progress_indicator', 'error_icon', 'maxPixelWidth', 'displayMediaVersion', 'FIELD_TYPE', 'DISPLAY_TYPE', 'choiceList', 'readonly', 'description', 'hidden') as $vs_key) { if (!isset($pa_options[$vs_key])) { $pa_options[$vs_key] = null; } } $va_attr = $this->getFieldInfo($ps_field); foreach (array('DISPLAY_WIDTH', 'DISPLAY_USE_COUNT', 'DISPLAY_SHOW_COUNT', 'DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT', 'DISPLAY_TYPE', 'IS_NULL', 'DEFAULT_ON_NULL', 'DEFAULT', 'LIST_MULTIPLE_DELIMITER', 'FIELD_TYPE', 'LIST_CODE', 'DISPLAY_FIELD', 'WHERE', 'DISPLAY_WHERE', 'DISPLAY_ORDERBY', 'LIST', 'BOUNDS_CHOICE_LIST', 'BOUNDS_LENGTH', 'DISPLAY_DESCRIPTION', 'LABEL', 'DESCRIPTION', 'SUB_LABEL', 'SUB_DESCRIPTION', 'MAX_PIXEL_WIDTH') as $vs_key) { if (!isset($va_attr[$vs_key])) { $va_attr[$vs_key] = null; } } if (isset($pa_options['FIELD_TYPE'])) { $va_attr['FIELD_TYPE'] = $pa_options['FIELD_TYPE']; } if (isset($pa_options['DISPLAY_TYPE'])) { $va_attr['DISPLAY_TYPE'] = $pa_options['DISPLAY_TYPE']; } $vn_display_width = isset($pa_options['width']) && $pa_options['width'] > 0 ? $pa_options['width'] : $va_attr["DISPLAY_WIDTH"]; $vn_display_height = isset($pa_options['height']) && $pa_options['height'] > 0 ? $pa_options['height'] : $va_attr["DISPLAY_HEIGHT"]; $va_parsed_width = caParseFormElementDimension($vn_display_width); $va_parsed_height = caParseFormElementDimension($vn_display_height); $va_dim_styles = array(); if ($va_parsed_width['type'] == 'pixels') { $va_dim_styles[] = "width: " . $va_parsed_width['dimension'] . "px;"; } if ($va_parsed_height['type'] == 'pixels') { $va_dim_styles[] = "height: " . $va_parsed_height['dimension'] . "px;"; } //if ($vn_max_pixel_width) { // $va_dim_styles[] = "max-width: {$vn_max_pixel_width}px;"; //} $vs_dim_style = trim(join(" ", $va_dim_styles)); $vs_field_label = isset($pa_options['label']) && strlen($pa_options['label']) > 0 ? $pa_options['label'] : $va_attr["LABEL"]; $vs_errors = ''; // TODO: PULL THIS FROM A CONFIG FILE $pa_options["display_form_field_tips"] = true; if (isset($pa_options['classname'])) { $vs_css_class_attr = ' class="' . $pa_options['classname'] . '" '; } else { $vs_css_class_attr = ''; } if (!isset($pa_options['id'])) { $pa_options['id'] = $pa_options['name']; } if (!isset($pa_options['id'])) { $pa_options['id'] = $ps_field; } if (!isset($pa_options['maxPixelWidth']) || (int) $pa_options['maxPixelWidth'] <= 0) { $vn_max_pixel_width = $va_attr['MAX_PIXEL_WIDTH']; } else { $vn_max_pixel_width = (int) $pa_options['maxPixelWidth']; } if ($vn_max_pixel_width <= 0) { $vn_max_pixel_width = null; } if (!isset($pa_options["maxOptionLength"]) && isset($vn_display_width)) { $pa_options["maxOptionLength"] = isset($vn_display_width) ? $vn_display_width : null; } $vs_text_area_tag_name = 'textarea'; if (isset($pa_options["textAreaTagName"]) && $pa_options['textAreaTagName']) { $vs_text_area_tag_name = isset($pa_options['textAreaTagName']) ? $pa_options['textAreaTagName'] : null; } if (!isset($va_attr["DISPLAY_USE_COUNT"]) || !($vs_display_use_count = $va_attr["DISPLAY_USE_COUNT"])) { $vs_display_use_count = isset($pa_options["display_use_count"]) ? $pa_options["display_use_count"] : null; } if (!isset($va_attr["DISPLAY_SHOW_COUNT"]) || !($vb_display_show_count = (bool) $va_attr["DISPLAY_SHOW_COUNT"])) { $vb_display_show_count = isset($pa_options["display_show_count"]) ? (bool) $pa_options["display_show_count"] : null; } if (!isset($va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"]) || !($vb_display_omit_items__with_zero_count = (bool) $va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"])) { $vb_display_omit_items__with_zero_count = isset($pa_options["display_omit_items__with_zero_count"]) ? (bool) $pa_options["display_omit_items__with_zero_count"] : null; } if (!isset($va_attr["DISPLAY_OMIT_ITEMS_WITH_ZERO_COUNT"]) || !($va_display_use_count_filters = $va_attr["DISPLAY_USE_COUNT_FILTERS"])) { $va_display_use_count_filters = isset($pa_options["display_use_count_filters"]) ? $pa_options["display_use_count_filters"] : null; } if (!isset($va_display_use_count_filters) || !is_array($va_display_use_count_filters)) { $va_display_use_count_filters = null; } if (isset($pa_options["selection"]) && is_array($pa_options["selection"])) { $va_selection = isset($pa_options["selection"]) ? $pa_options["selection"] : null; } else { $va_selection = array(); } if (isset($pa_options["choiceList"]) && is_array($pa_options["choiceList"])) { $va_attr["BOUNDS_CHOICE_LIST"] = $pa_options["choiceList"]; } $vs_element = $vs_subelement = ""; if ($va_attr) { # --- Skip omitted fields completely if ($va_attr["DISPLAY_TYPE"] == DT_OMIT) { return ""; } if (!isset($pa_options["name"]) || !$pa_options["name"]) { $pa_options["name"] = htmlspecialchars($ps_field, ENT_QUOTES, 'UTF-8'); } $va_js = array(); $va_handlers = array("onclick", "onchange", "onkeypress", "onkeydown", "onkeyup"); foreach ($va_handlers as $vs_handler) { if (isset($pa_options[$vs_handler]) && $pa_options[$vs_handler]) { $va_js[] = "{$vs_handler}='" . $pa_options[$vs_handler] . "'"; } } $vs_js = join(" ", $va_js); if (!isset($pa_options["value"])) { // allow field value to be overriden with value from options array $vm_field_value = $this->get($ps_field, $pa_options); } else { $vm_field_value = $pa_options["value"]; } $vm_raw_field_value = $vm_field_value; $vb_is_null = isset($va_attr["IS_NULL"]) ? $va_attr["IS_NULL"] : false; if (isset($pa_options['dont_show_null_value']) && $pa_options['dont_show_null_value']) { $vb_is_null = false; } if (!is_array($vm_field_value) && strlen($vm_field_value) == 0 && (!isset($vb_is_null) || !$vb_is_null || (isset($va_attr["DEFAULT_ON_NULL"]) ? $va_attr["DEFAULT_ON_NULL"] : 0))) { $vm_field_value = isset($va_attr["DEFAULT"]) ? $va_attr["DEFAULT"] : ""; } # --- Return hidden fields if ($va_attr["DISPLAY_TYPE"] == DT_HIDDEN || caGetOption('hidden', $pa_options, false)) { return '<input type="hidden" name="' . $pa_options["name"] . '" value="' . $this->escapeHTML($vm_field_value) . '"/>'; } if (isset($pa_options["size"]) && $pa_options["size"] > 0) { $ps_size = " size='" . $pa_options["size"] . "'"; } else { if (($va_attr["DISPLAY_TYPE"] == DT_LIST_MULTIPLE || $va_attr["DISPLAY_TYPE"] == DT_LIST) && $vn_display_height > 1) { $ps_size = " size='" . $vn_display_height . "'"; } else { $ps_size = ''; } } $vs_multiple_name_extension = ''; if ($vs_is_multiple = isset($pa_options["multiple"]) && $pa_options["multiple"] || $va_attr["DISPLAY_TYPE"] == DT_LIST_MULTIPLE ? "multiple='1'" : "") { $vs_multiple_name_extension = '[]'; if (!($vs_list_multiple_delimiter = $va_attr['LIST_MULTIPLE_DELIMITER'])) { $vs_list_multiple_delimiter = ';'; } $va_selection = array_merge($va_selection, explode($vs_list_multiple_delimiter, $vm_field_value)); } # --- Return form element switch ($va_attr["FIELD_TYPE"]) { # ---------------------------- case FT_NUMBER: case FT_TEXT: case FT_VARS: if ($va_attr["FIELD_TYPE"] == FT_VARS) { if (!$pa_options['show_text_field_for_vars']) { break; } if (!is_string($vm_field_value) && !is_numeric($vm_field_value)) { $vm_value = ''; } } if ($va_attr['DISPLAY_TYPE'] == DT_COUNTRY_LIST) { $vs_element = caHTMLSelect($ps_field, caGetCountryList(), array('id' => $ps_field), array('value' => $vm_field_value)); if ($va_attr['STATEPROV_FIELD']) { $vs_element .= "<script type='text/javascript'>\n"; $vs_element .= "var caStatesByCountryList = " . json_encode(caGetStateList()) . ";\n"; $vs_element .= "\n\t\t\t\t\t\t\t\tjQuery('#{$ps_field}').click({countryID: '{$ps_field}', stateProvID: '" . $va_attr['STATEPROV_FIELD'] . "', value: '" . addslashes($this->get($va_attr['STATEPROV_FIELD'])) . "', statesByCountryList: caStatesByCountryList}, caUI.utils.updateStateProvinceForCountry);\n\t\t\t\t\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\t\t\t\t\tcaUI.utils.updateStateProvinceForCountry({data: {countryID: '{$ps_field}', stateProvID: '" . $va_attr['STATEPROV_FIELD'] . "', value: '" . addslashes($this->get($va_attr['STATEPROV_FIELD'])) . "', statesByCountryList: caStatesByCountryList}});\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t"; $vs_element .= "</script>\n"; } break; } if ($va_attr['DISPLAY_TYPE'] == DT_STATEPROV_LIST) { $vs_element = caHTMLSelect($ps_field . '_select', array(), array('id' => $ps_field . '_select'), array('value' => $vm_field_value)); $vs_element .= caHTMLTextInput($ps_field . '_name', array('id' => $ps_field . '_text', 'value' => $vm_field_value)); break; } if ($vn_display_width > 0 && in_array($va_attr["DISPLAY_TYPE"], array(DT_SELECT, DT_LIST, DT_LIST_MULTIPLE))) { # # Generate auto generated <select> (from foreign key, from ca_lists or from field-defined choice list) # # TODO: CLEAN UP THIS CODE, RUNNING VARIOUS STAGES THROUGH HELPER FUNCTIONS; ALSO FORMALIZE AND DOCUMENT VARIOUS OPTIONS // ----- // from ca_lists // ----- if (!($vs_list_code = $pa_options['list_code'])) { if (isset($va_attr['LIST_CODE']) && $va_attr['LIST_CODE']) { $vs_list_code = $va_attr['LIST_CODE']; } } if ($vs_list_code) { $va_many_to_one_relations = $this->_DATAMODEL->getManyToOneRelations($this->tableName()); if ($va_many_to_one_relations[$ps_field]) { $vs_key = 'item_id'; } else { $vs_key = 'item_value'; } $vs_null_option = null; if (!$pa_options["nullOption"] && $vb_is_null) { $vs_null_option = _t("- NONE -"); } else { if ($pa_options["nullOption"]) { $vs_null_option = $pa_options["nullOption"]; } } $t_list = new ca_lists(); $va_list_attrs = array('id' => $pa_options['id']); //if ($vn_max_pixel_width) { $va_list_attrs['style'] = $vs_width_style; } if (method_exists($this, 'getTypeFieldName') && $ps_field == $this->getTypeFieldName()) { $va_limit_list = caGetTypeListForUser($this->tableName(), array('access' => __CA_BUNDLE_ACCESS_EDIT__)); } // NOTE: "raw" field value (value passed into method, before the model default value is applied) is used so as to allow the list default to be used if needed $vs_element = $t_list->getListAsHTMLFormElement($vs_list_code, $pa_options["name"] . $vs_multiple_name_extension, $va_list_attrs, array('value' => $vm_raw_field_value, 'key' => $vs_key, 'nullOption' => $vs_null_option, 'readonly' => $pa_options['readonly'], 'restrictTypeListForTable' => $this->tableName(), 'limitToItemsWithID' => $va_limit_list ? $va_limit_list : null)); if (isset($pa_options['hide_select_if_no_options']) && $pa_options['hide_select_if_no_options'] && !$vs_element) { $vs_element = ""; $ps_format = '^ERRORS^ELEMENT'; } } else { // ----- // from related table // ----- $va_many_to_one_relations = $this->_DATAMODEL->getManyToOneRelations($this->tableName()); if (isset($va_many_to_one_relations[$ps_field]) && $va_many_to_one_relations[$ps_field]) { # # Use foreign key to populate <select> # $o_one_table = $this->_DATAMODEL->getTableInstance($va_many_to_one_relations[$ps_field]["one_table"]); $vs_one_table_primary_key = $o_one_table->primaryKey(); if ($o_one_table->isHierarchical()) { # # Hierarchical <select> # $va_hier = $o_one_table->getHierarchyAsList(0, $vs_display_use_count, $va_display_use_count_filters, $vb_display_omit_items__with_zero_count); if (!is_array($va_hier)) { return ''; } $va_display_fields = $va_attr["DISPLAY_FIELD"]; if (!in_array($vs_one_table_primary_key, $va_display_fields)) { $va_display_fields[] = $o_one_table->tableName() . "." . $vs_one_table_primary_key; } if (!is_array($va_display_fields) || sizeof($va_display_fields) < 1) { $va_display_fields = array("*"); } $vs_hier_parent_id_fld = $o_one_table->getProperty("HIER_PARENT_ID_FLD"); $va_options = array(); if ($pa_options["nullOption"]) { $va_options[""] = array($pa_options["nullOption"]); } $va_suboptions = array(); $va_suboption_values = array(); $vn_selected = 0; $vm_cur_top_level_val = null; $vm_selected_top_level_val = null; foreach ($va_hier as $va_option) { if (!$va_option["NODE"][$vs_hier_parent_id_fld]) { continue; } $vn_val = $va_option["NODE"][$o_one_table->primaryKey()]; $vs_selected = $vn_val == $vm_field_value ? 'selected="1"' : ""; $vn_indent = $va_option["LEVEL"] - 1; $va_display_data = array(); foreach ($va_display_fields as $vs_fld) { $va_bits = explode(".", $vs_fld); if ($va_bits[1] != $vs_one_table_primary_key) { $va_display_data[] = $va_option["NODE"][$va_bits[1]]; } } $vs_option_label = join(" ", $va_display_data); $va_options[$vn_val] = array($vs_option_label, $vn_indent, $va_option["HITS"], $va_option['NODE']); } if (sizeof($va_options) == 0) { $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available'; } else { $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options["id"] . $vs_multiple_name_extension . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n"; if (!$pa_options["nullOption"] && $vb_is_null) { $vs_element .= "<option value=''>" . _t('- NONE -') . "</option>\n"; } else { if ($pa_options["nullOption"]) { $vs_element .= "<option value=''>" . $pa_options["nullOption"] . "</option>\n"; } } foreach ($va_options as $vn_val => $va_option_info) { $vs_selected = $vn_val == $vm_field_value || in_array($vn_val, $va_selection) ? "selected='selected'" : ""; $vs_element .= "<option value='" . $vn_val . "' {$vs_selected}>"; $vn_indent = $va_option_info[1] * 2; $vs_indent = ""; if ($vn_indent > 0) { $vs_indent = str_repeat(" ", ($vn_indent - 1) * 2) . " "; $vn_indent++; } $vs_option_text = $va_option_info[0]; $vs_use_count = ""; if ($vs_display_use_count && $vb_display_show_count && $vn_val != "") { $vs_use_count = " (" . intval($va_option_info[2]) . ")"; } $vs_display_message = ''; if (is_array($pa_options['displayMessageForFieldValues'])) { foreach ($pa_options['displayMessageForFieldValues'] as $vs_df => $va_df_vals) { if (isset($va_option_info[3][$vs_df]) && is_array($va_df_vals)) { $vs_tmp = $va_option_info[3][$vs_df]; if (isset($va_df_vals[$vs_tmp])) { $vs_display_message = ' ' . $va_df_vals[$vs_tmp]; } } } } if ($pa_options["maxOptionLength"] && strlen($vs_option_text) + strlen($vs_use_count) + $vn_indent > $pa_options["maxOptionLength"]) { if (($vn_strlen = $pa_options["maxOptionLength"] - strlen($vs_indent) - strlen($vs_use_count) - 3) < $pa_options["maxOptionLength"]) { $vn_strlen = $pa_options["maxOptionLength"]; } $vs_option_text = unicode_substr($vs_option_text, 0, $vn_strlen) . "..."; } $vs_element .= $vs_indent . $vs_option_text . $vs_use_count . $vs_display_message . "</option>\n"; } $vs_element .= "</select>\n"; } } else { # # "Flat" <select> # if (!is_array($va_display_fields = $pa_options["DISPLAY_FIELD"])) { $va_display_fields = $va_attr["DISPLAY_FIELD"]; } if (!is_array($va_display_fields)) { return "Configuration error: DISPLAY_FIELD directive for field '{$ps_field}' must be an array of field names in the format tablename.fieldname"; } if (!in_array($vs_one_table_primary_key, $va_display_fields)) { $va_display_fields[] = $o_one_table->tableName() . "." . $vs_one_table_primary_key; } if (!is_array($va_display_fields) || sizeof($va_display_fields) < 1) { $va_display_fields = array("*"); } $vs_sql = "\n\t\t\t\t\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM " . $va_many_to_one_relations[$ps_field]["one_table"] . "\n\t\t\t\t\t\t\t\t\t\t\t"; if (isset($pa_options["WHERE"]) && (is_array($pa_options["WHERE"]) && ($vs_where = join(" AND ", $pa_options["WHERE"]))) || is_array($va_attr["DISPLAY_WHERE"]) && ($vs_where = join(" AND ", $va_attr["DISPLAY_WHERE"]))) { $vs_sql .= " WHERE {$vs_where} "; } if (isset($va_attr["DISPLAY_ORDERBY"]) && $va_attr["DISPLAY_ORDERBY"] && ($vs_orderby = join(",", $va_attr["DISPLAY_ORDERBY"]))) { $vs_sql .= " ORDER BY {$vs_orderby} "; } $qr_res = $o_db->query($vs_sql); if ($o_db->numErrors()) { $vs_element = "Error creating menu: " . join(';', $o_db->getErrors()); break; } $va_opts = array(); if (isset($pa_options["nullOption"]) && $pa_options["nullOption"]) { $va_opts[$pa_options["nullOption"]] = array($pa_options["nullOption"], null); } else { if ($vb_is_null) { $va_opts[_t("- NONE -")] = array(_t("- NONE -"), null); } } if ($pa_options["select_item_text"]) { $va_opts[$pa_options["select_item_text"]] = array($pa_options["select_item_text"], null); } $va_fields = array(); foreach ($va_display_fields as $vs_field) { $va_tmp = explode(".", $vs_field); $va_fields[] = $va_tmp[1]; } while ($qr_res->nextRow()) { $vs_display = ""; foreach ($va_fields as $vs_field) { if ($vs_field != $vs_one_table_primary_key) { $vs_display .= $qr_res->get($vs_field) . " "; } } $va_opts[] = array($vs_display, $qr_res->get($vs_one_table_primary_key), $qr_res->getRow()); } if (sizeof($va_opts) == 0) { $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available'; } else { if (isset($pa_options['hide_select_if_only_one_option']) && $pa_options['hide_select_if_only_one_option'] && sizeof($va_opts) == 1) { $vs_element = "<input type='hidden' name='" . $pa_options["name"] . "' " . $vs_js . " " . $ps_size . " id='" . $pa_options["id"] . "' value='" . ($vm_field_value ? $vm_field_value : $va_opts[0][1]) . "' {$vs_css_class_attr}/>"; $ps_format = '^ERRORS^ELEMENT'; } else { $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options["id"] . $vs_multiple_name_extension . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n"; foreach ($va_opts as $va_opt) { $vs_option_text = $va_opt[0]; $vs_value = $va_opt[1]; $vs_selected = $vs_value == $vm_field_value || in_array($vs_value, $va_selection) ? "selected='selected'" : ""; $vs_use_count = ""; if ($vs_display_use_count && $vb_display_show_count && $vs_value != "") { //$vs_use_count = "(".intval($va_option_info[2]).")"; } if ($pa_options["maxOptionLength"] && strlen($vs_option_text) + strlen($vs_use_count) > $pa_options["maxOptionLength"]) { $vs_option_text = unicode_substr($vs_option_text, 0, $pa_options["maxOptionLength"] - 3 - strlen($vs_use_count)) . "..."; } $vs_display_message = ''; if (is_array($pa_options['displayMessageForFieldValues'])) { foreach ($pa_options['displayMessageForFieldValues'] as $vs_df => $va_df_vals) { if (isset($va_opt[2][$vs_df]) && is_array($va_df_vals)) { $vs_tmp = $va_opt[2][$vs_df]; if (isset($va_df_vals[$vs_tmp])) { $vs_display_message = ' ' . $va_df_vals[$vs_tmp]; } } } } $vs_element .= "<option value='{$vs_value}' {$vs_selected}>"; $vs_element .= $vs_option_text . $vs_use_count . $vs_display_message; $vs_element .= "</option>\n"; } $vs_element .= "</select>\n"; } } } } else { # # choice list # $vs_element = ''; // if 'LIST' is set try to stock over choice list with the contents of the list if (isset($va_attr['LIST']) && $va_attr['LIST']) { // NOTE: "raw" field value (value passed into method, before the model default value is applied) is used so as to allow the list default to be used if needed $vs_element = ca_lists::getListAsHTMLFormElement($va_attr['LIST'], $pa_options["name"] . $vs_multiple_name_extension, array('class' => $pa_options['classname'], 'id' => $pa_options['id']), array('key' => 'item_value', 'value' => $vm_raw_field_value, 'nullOption' => $pa_options['nullOption'], 'readonly' => $pa_options['readonly'])); } if (!$vs_element && (isset($va_attr["BOUNDS_CHOICE_LIST"]) && is_array($va_attr["BOUNDS_CHOICE_LIST"]))) { if (sizeof($va_attr["BOUNDS_CHOICE_LIST"]) == 0) { $vs_element = isset($pa_options['empty_message']) ? $pa_options['empty_message'] : 'No options available'; } else { $vs_element = "<select name='" . $pa_options["name"] . $vs_multiple_name_extension . "' " . $vs_js . " " . $vs_is_multiple . " " . $ps_size . " id='" . $pa_options['id'] . $vs_multiple_name_extension . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n"; if ($pa_options["select_item_text"]) { $vs_element .= "<option value=''>" . $this->escapeHTML($pa_options["select_item_text"]) . "</option>\n"; } if (!$pa_options["nullOption"] && $vb_is_null) { $vs_element .= "<option value=''>" . _t('- NONE -') . "</option>\n"; } else { if ($pa_options["nullOption"]) { $vs_element .= "<option value=''>" . $pa_options["nullOption"] . "</option>\n"; } } foreach ($va_attr["BOUNDS_CHOICE_LIST"] as $vs_option => $vs_value) { $vs_selected = strval($vs_value) === strval($vm_field_value) || in_array($vs_value, $va_selection) ? "selected='selected'" : ""; if ($pa_options["maxOptionLength"] && strlen($vs_option) > $pa_options["maxOptionLength"]) { $vs_option = unicode_substr($vs_option, 0, $pa_options["maxOptionLength"] - 3) . "..."; } $vs_element .= "<option value='{$vs_value}' {$vs_selected}>" . $this->escapeHTML($vs_option) . "</option>\n"; } $vs_element .= "</select>\n"; } } } } } else { if ($va_attr["DISPLAY_TYPE"] === DT_COLORPICKER) { // COLORPICKER $vs_element = '<input name="' . $pa_options["name"] . '" type="hidden" size="' . ($pa_options['size'] ? $pa_options['size'] : $vn_display_width) . '" value="' . $this->escapeHTML($vm_field_value) . '" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' style='{$vs_dim_style}'/>\n"; $vs_element .= '<div id="' . $pa_options["id"] . '_colorchip" class="colorpicker_chip" style="background-color: #' . $vm_field_value . '"><!-- empty --></div>'; $vs_element .= "<script type='text/javascript'>jQuery(document).ready(function() { jQuery('#" . $pa_options["name"] . "_colorchip').ColorPicker({\n\t\t\t\t\t\t\t\tonShow: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeIn(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonHide: function (colpkr) {\n\t\t\t\t\t\t\t\t\tjQuery(colpkr).fadeOut(500);\n\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonChange: function (hsb, hex, rgb) {\n\t\t\t\t\t\t\t\t\tjQuery('#" . $pa_options["name"] . "').val(hex);\n\t\t\t\t\t\t\t\t\tjQuery('#" . $pa_options["name"] . "_colorchip').css('backgroundColor', '#' + hex);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tcolor: jQuery('#" . $pa_options["name"] . "').val()\n\t\t\t\t\t\t\t})}); </script>\n"; if (method_exists('AssetLoadManager', 'register')) { AssetLoadManager::register('jquery', 'colorpicker'); } } else { # normal controls: all non-DT_SELECT display types are returned as DT_FIELD's. We could generate # radio-button controls for foreign key and choice lists, but we don't bother because it's never # really necessary. if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '"' . ($pa_options['readonly'] ? ' readonly="readonly" disabled="disabled"' : '') . ' wrap="soft" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' style='{$vs_dim_style}' " . $vs_css_class_attr . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>' . "\n"; } else { $vs_element = '<input name="' . $pa_options["name"] . '" type="text" size="' . ($pa_options['size'] ? $pa_options['size'] : $vn_display_width) . '"' . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ' value="' . $this->escapeHTML($vm_field_value) . '" ' . $vs_js . ' id=\'' . $pa_options["id"] . "' {$vs_css_class_attr} style='{$vs_dim_style}'/>\n"; } if (isset($va_attr['UNIQUE_WITHIN']) && is_array($va_attr['UNIQUE_WITHIN'])) { $va_within_fields = array(); foreach ($va_attr['UNIQUE_WITHIN'] as $vs_within_field) { $va_within_fields[$vs_within_field] = $this->get($vs_within_field); } $vs_element .= "<span id='" . $pa_options["id"] . '_uniqueness_status' . "'></span>"; $vs_element .= "<script type='text/javascript'>\n\tcaUI.initUniquenessChecker({\n\t\terrorIcon: '" . $pa_options['error_icon'] . "',\n\t\tprocessIndicator: '" . $pa_options['progress_indicator'] . "',\n\t\tstatusID: '" . $pa_options["id"] . "_uniqueness_status',\n\t\tlookupUrl: '" . $pa_options['lookup_url'] . "',\n\t\tformElementID: '" . $pa_options["id"] . "',\n\t\trow_id: " . intval($this->getPrimaryKey()) . ",\n\t\ttable_num: " . $this->tableNum() . ",\n\t\tfield: '" . $ps_field . "',\n\t\twithinFields: " . json_encode($va_within_fields) . ",\n\t\t\n\t\talreadyInUseMessage: '" . addslashes(_t('Value must be unique. Please try another.')) . "'\n\t});\n</script>"; } else { if (isset($va_attr['LOOKUP']) && $va_attr['LOOKUP']) { if (class_exists("AppController") && ($app = AppController::getInstance()) && ($req = $app->getRequest())) { AssetLoadManager::register('jquery', 'autocomplete'); $vs_element .= "<script type='text/javascript'>\n\tjQuery('#" . $pa_options["id"] . "').autocomplete({ source: '" . caNavUrl($req, 'lookup', 'Intrinsic', 'Get', array('bundle' => $this->tableName() . ".{$ps_field}", "max" => 500)) . "', minLength: 3, delay: 800});\n</script>"; } } } if (isset($pa_options['usewysiwygeditor']) && $pa_options['usewysiwygeditor']) { AssetLoadManager::register("ckeditor"); $vs_width = $vn_display_width; $vs_height = $vn_display_height; if (!preg_match("!^[\\d\\.]+px\$!i", $vs_width)) { $vs_width = (int) $vs_width * 6 . "px"; } if (!preg_match("!^[\\d\\.]+px\$!i", $vs_height)) { $vs_height = (int) $vs_height * 16 . "px"; } if (!is_array($va_toolbar_config = $this->getAppConfig()->getAssoc('wysiwyg_editor_toolbar'))) { $va_toolbar_config = array(); } $vs_element .= "<script type='text/javascript'>jQuery(document).ready(function() {\n\t\t\t\t\t\t\t\tvar ckEditor = CKEDITOR.replace( '" . $pa_options['id'] . "',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttoolbar : " . json_encode(array_values($va_toolbar_config)) . ",\n\t\t\t\t\t\t\t\t\twidth: '{$vs_width}',\n\t\t\t\t\t\t\t\t\theight: '{$vs_height}',\n\t\t\t\t\t\t\t\t\ttoolbarLocation: 'top',\n\t\t\t\t\t\t\t\t\tenterMode: CKEDITOR.ENTER_BR\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tckEditor.on('instanceReady', function(){ \n\t\t\t\t\t\t\t\t\t ckEditor.document.on( 'keydown', function(e) {if (caUI && caUI.utils) { caUI.utils.showUnsavedChangesWarning(true); } });\n\t\t\t\t\t\t\t\t});\n \t});\t\t\t\t\t\t\t\t\t\n</script>"; } } } break; # ---------------------------- # ---------------------------- case FT_TIMESTAMP: if ($this->get($ps_field)) { # is timestamp set? $vs_element = $this->escapeHTML($vm_field_value); # return printed date } else { $vs_element = "[Not set]"; # return text instead of 1969 date } break; # ---------------------------- # ---------------------------- case FT_DATETIME: case FT_HISTORIC_DATETIME: case FT_DATE: case FT_HISTORIC_DATE: if (!$vm_field_value) { $vm_field_value = $pa_options['value']; } switch ($va_attr["DISPLAY_TYPE"]) { case DT_TEXT: $vs_element = $vm_field_value ? $vm_field_value : "[Not set]"; break; default: $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>'; } else { $vs_element = '<input type="text" name="' . $pa_options["name"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; } break; } break; # ---------------------------- # ---------------------------- case FT_TIME: if (!$this->get($ps_field)) { $vm_field_value = ""; } switch ($va_attr["DISPLAY_TYPE"]) { case DT_TEXT: $vs_element = $vm_field_value ? $vm_field_value : "[Not set]"; break; default: $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>'; } else { $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr}' style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; } break; } break; # ---------------------------- # ---------------------------- case FT_DATERANGE: case FT_HISTORIC_DATERANGE: switch ($va_attr["DISPLAY_TYPE"]) { case DT_TEXT: $vs_element = $vm_field_value ? $vm_field_value : "[Not set]"; break; default: $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>'; } else { $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vn_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; } break; } break; # ---------------------------- # ---------------------------- case FT_TIMERANGE: switch ($va_attr["DISPLAY_TYPE"]) { case DT_TEXT: $vs_element = $vm_field_value ? $vm_field_value : "[Not set]"; break; default: $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vm_field_value) . '</' . $vs_text_area_tag_name . '>'; } else { $vs_element = '<input type="text" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; } break; } break; # ---------------------------- # ---------------------------- case FT_TIMECODE: $o_tp = new TimecodeParser(); $o_tp->setParsedValueInSeconds($vm_field_value); $vs_timecode = $o_tp->getText("COLON_DELIMITED", array("BLANK_ON_ZERO" => true)); $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } if ($vn_display_height > 1) { $vs_element = '<' . $vs_text_area_tag_name . ' name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" rows="' . $vn_display_height . '" cols="' . $vn_display_width . '" wrap="soft" ' . $vs_js . ' ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . ">" . $this->escapeHTML($vs_timecode) . '</' . $vs_text_area_tag_name . '>'; } else { $vs_element = '<input type="text" NAME="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vs_timecode) . "\" size='{$vn_display_width}' {$vs_max_length} {$vs_js} {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; } break; # ---------------------------- # ---------------------------- case FT_MEDIA: case FT_FILE: $vs_element = '<input type="file" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" ' . $vs_js . '/>'; // show current media icon if ($vs_version = array_key_exists('displayMediaVersion', $pa_options) ? $pa_options['displayMediaVersion'] : 'icon') { $va_valid_versions = $this->getMediaVersions($ps_field); if (!in_array($vs_version, $va_valid_versions)) { $vs_version = $va_valid_versions[0]; } if ($vs_tag = $this->getMediaTag($ps_field, $vs_version)) { $vs_element .= $vs_tag; } } break; # ---------------------------- # ---------------------------- case FT_PASSWORD: $vn_max_length = $va_attr["BOUNDS_LENGTH"][1]; $vs_max_length = ''; if ($vn_max_length > 0) { $vs_max_length = 'maxlength="' . $vn_max_length . '"'; } $vs_element = '<input type="password" name="' . $pa_options["name"] . '" id="' . $pa_options["id"] . '" value="' . $this->escapeHTML($vm_field_value) . '" size="' . $vn_display_width . '" ' . $vs_max_length . ' ' . $vs_js . ' autocomplete="off" ' . $vs_css_class_attr . " style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; break; # ---------------------------- # ---------------------------- case FT_BIT: switch ($va_attr["DISPLAY_TYPE"]) { case DT_FIELD: $vs_element = '<input type="text" name="' . $pa_options["name"] . "\" value='{$vm_field_value}' maxlength='1' size='2' {$vs_js} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' readonly="readonly" ' : '') . "/>"; break; case DT_SELECT: $vs_element = "<select name='" . $pa_options["name"] . "' " . $vs_js . " id='" . $pa_options["id"] . "' {$vs_css_class_attr} style='{$vs_dim_style}'" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">\n"; foreach (array("Yes" => 1, "No" => 0) as $vs_option => $vs_value) { $vs_selected = $vs_value == $vm_field_value ? "selected='selected'" : ""; $vs_element .= "<option value='{$vs_value}' {$vs_selected}" . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ">" . _t($vs_option) . "</option>\n"; } $vs_element .= "</select>\n"; break; case DT_CHECKBOXES: $vs_element = '<input type="checkbox" name="' . $pa_options["name"] . '" value="1" ' . ($vm_field_value ? 'checked="1"' : '') . ' ' . $vs_js . ($pa_options['readonly'] ? ' disabled="disabled" ' : '') . ' id="' . $pa_options["id"] . '"/>'; break; case DT_RADIO_BUTTONS: $vs_element = 'Radio buttons not supported for bit-type fields'; break; } break; # ---------------------------- } # Apply format $vs_formatting = ""; if (isset($pa_options['field_errors']) && is_array($pa_options['field_errors']) && sizeof($pa_options['field_errors'])) { $va_field_errors = array(); foreach ($pa_options['field_errors'] as $o_e) { $va_field_errors[] = $o_e->getErrorDescription(); } $vs_errors = join('; ', $va_field_errors); } else { $vs_errors = ''; } if (is_null($ps_format)) { if (isset($pa_options['field_errors']) && is_array($pa_options['field_errors']) && sizeof($pa_options['field_errors'])) { $ps_format = $this->_CONFIG->get('form_element_error_display_format'); } else { $ps_format = $this->_CONFIG->get('form_element_display_format'); } } if ($ps_format != '') { $ps_formatted_element = $ps_format; $ps_formatted_element = str_replace("^ELEMENT", $vs_element, $ps_formatted_element); if ($vs_subelement) { $ps_formatted_element = str_replace("^SUB_ELEMENT", $vs_subelement, $ps_formatted_element); } $vb_fl_display_form_field_tips = false; if ($pa_options["display_form_field_tips"] || !isset($pa_options["display_form_field_tips"]) && $va_attr["DISPLAY_DESCRIPTION"] || !isset($pa_options["display_form_field_tips"]) && !isset($va_attr["DISPLAY_DESCRIPTION"]) && $vb_fl_display_form_field_tips) { if (preg_match("/\\^DESCRIPTION/", $ps_formatted_element)) { $ps_formatted_element = str_replace("^LABEL", $vs_field_label, $ps_formatted_element); $ps_formatted_element = str_replace("^DESCRIPTION", isset($pa_options["description"]) && $pa_options["description"] ? $pa_options["description"] : $va_attr["DESCRIPTION"], $ps_formatted_element); } else { // no explicit placement of description text, so... $vs_field_id = '_' . $this->tableName() . '_' . $this->getPrimaryKey() . '_' . $pa_options["name"] . '_' . $pa_options['form_name']; $ps_formatted_element = str_replace("^LABEL", '<span id="' . $vs_field_id . '">' . $vs_field_label . '</span>', $ps_formatted_element); if (!isset($pa_options['no_tooltips']) || !$pa_options['no_tooltips']) { TooltipManager::add('#' . $vs_field_id, "<h3>{$vs_field_label}</h3>" . (isset($pa_options["description"]) && $pa_options["description"] ? $pa_options["description"] : $va_attr["DESCRIPTION"]), $pa_options['tooltip_namespace']); } } if (!isset($va_attr["SUB_LABEL"])) { $va_attr["SUB_LABEL"] = ''; } if (!isset($va_attr["SUB_DESCRIPTION"])) { $va_attr["SUB_DESCRIPTION"] = ''; } if (preg_match("/\\^SUB_DESCRIPTION/", $ps_formatted_element)) { $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element); $ps_formatted_element = str_replace("^SUB_DESCRIPTION", $va_attr["SUB_DESCRIPTION"], $ps_formatted_element); } else { // no explicit placement of description text, so... // ... make label text itself rollover for description text because no icon was specified $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element); } } else { $ps_formatted_element = str_replace("^LABEL", $vs_field_label, $ps_formatted_element); $ps_formatted_element = str_replace("^DESCRIPTION", "", $ps_formatted_element); if ($vs_subelement) { $ps_formatted_element = str_replace("^SUB_LABEL", $va_attr["SUB_LABEL"], $ps_formatted_element); $ps_formatted_element = str_replace("^SUB_DESCRIPTION", "", $ps_formatted_element); } } $ps_formatted_element = str_replace("^ERRORS", $vs_errors, $ps_formatted_element); $ps_formatted_element = str_replace("^EXTRA", isset($pa_options['extraLabelText']) ? $pa_options['extraLabelText'] : '', $ps_formatted_element); $vs_element = $ps_formatted_element; } else { $vs_element .= "<br/>" . $vs_subelement; } return $vs_element; } else { $this->postError(716, _t("'%1' does not exist in this object", $ps_field), "BaseModel->formElement()"); return ""; } return ""; }
public function postError($pn_num, $ps_message, $ps_context, $ps_source = '') { $o_error = new ApplicationError(); $o_error->setErrorOutput($this->error_output); $o_error->setError($pn_num, $ps_message, $ps_context, $ps_source); if (!$this->errors) { $this->errors = array(); } array_push($this->errors, $o_error); if (($app = AppController::getInstance()) && ($o_request = $app->getRequest()) && defined('__CA_ENABLE_DEBUG_OUTPUT__') && __CA_ENABLE_DEBUG_OUTPUT__) { $va_trace = debug_backtrace(); array_shift($va_trace); $vs_stacktrace = ''; while ($va_source = array_shift($va_trace)) { $vs_stacktrace .= " [{$va_source['file']}:{$va_source['line']}]"; } $o_notification = new NotificationManager($o_request); $o_notification->addNotification("[{$pn_num}] {$ps_message} ({$ps_context}" . ($ps_source ? "; {$ps_source}" : '') . $vs_stacktrace); } return true; }
/** * * * @param array $pa_options Array of options passed through to _initView */ public function ChangeType($pa_options = null) { if (!is_array($pa_options)) { $pa_options = array(); } list($vn_set_id, $t_set, $t_subject, $t_ui) = $this->_initView($pa_options); if (!$vn_set_id) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3200?r=' . urlencode($this->request->getFullUrlPath())); return; } // Can user batch edit this table? if (!$this->request->user->canDoAction('can_batch_edit_' . $t_set->getAppDatamodel()->getTableName($t_set->get('table_num')))) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3210?r=' . urlencode($this->request->getFullUrlPath())); return; } if (!$this->request->user->canDoAction("can_change_type_" . $t_subject->tableName()) || !method_exists($t_subject, "getTypeList")) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3260?r=' . urlencode($this->request->getFullUrlPath())); return; } $vn_new_type_id = $this->request->getParameter('new_type_id', pInteger); $va_type_list = $t_subject->getTypeList(); if (!isset($va_type_list[$vn_new_type_id])) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3260?r=' . urlencode($this->request->getFullUrlPath())); return; } $va_last_settings = array('set_id' => $vn_set_id, 'screen' => $this->request->getActionExtra(), 'user_id' => $this->request->getUserID(), 'values' => $_REQUEST, 'sendMail' => (bool) $this->request->getParameter('send_email_when_done', pInteger), 'sendSMS' => (bool) $this->request->getParameter('send_sms_when_done', pInteger)); if ((bool) $this->request->config->get('queue_enabled') && (bool) $this->request->getParameter('run_in_background', pInteger)) { // queue for background processing $o_tq = new TaskQueue(); $vs_row_key = $vs_entity_key = join("/", array($this->request->getUserID(), $t_set->getPrimaryKey(), time(), rand(1, 999999))); if (!$o_tq->addTask('batchEditor', array_merge($va_last_settings, array('isBatchTypeChange' => true, 'new_type_id' => $vn_new_type_id)), array("priority" => 100, "entity_key" => $vs_entity_key, "row_key" => $vs_row_key, 'user_id' => $this->request->getUserID()))) { //$this->postError(100, _t("Couldn't queue batch processing for"),"EditorContro->_processMedia()"); } $this->render('editor/batch_queued_html.php'); } else { // run now $app = AppController::getInstance(); $app->registerPlugin(new BatchEditorProgress($this->request, $t_set, $t_subject, array('type_id' => $vn_new_type_id, 'isBatchTypeChange' => true, 'sendMail' => (bool) $this->request->getParameter('send_email_when_done', pInteger), 'sendSMS' => (bool) $this->request->getParameter('send_sms_when_done', pInteger), 'runInBackground' => (bool) $this->request->getParameter('run_in_background', pInteger)))); $this->render('editor/batch_results_html.php'); } $this->request->user->setVar('batch_editor_last_settings', $va_last_settings); }
/** * Returns a display label for a given criterion and facet. * * @param string $ps_facet_name Name of facet * @param mixed $pm_criterion * @return string */ public function getCriterionLabel($ps_facet_name, $pn_row_id) { if (!($va_facet_info = $this->getInfoForFacet($ps_facet_name))) { return null; } switch ($va_facet_info['type']) { # ----------------------------------------------------- case 'has': $vs_yes_text = isset($va_facet_info['label_yes']) && $va_facet_info['label_yes'] ? $va_facet_info['label_yes'] : _t('Yes'); $vs_no_text = isset($va_facet_info['label_no']) && $va_facet_info['label_no'] ? $va_facet_info['label_no'] : _t('No'); return (bool) $pn_row_id ? $vs_yes_text : $vs_no_text; break; # ----------------------------------------------------- # ----------------------------------------------------- case 'label': if (!($t_table = $this->opo_datamodel->getInstanceByTableName(isset($va_facet_info['relative_to']) && $va_facet_info['relative_to'] ? $va_facet_info['relative_to'] : $this->ops_browse_table_name, true))) { break; } if (!$t_table->load($pn_row_id)) { return '???'; } return $t_table->getLabelForDisplay(); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'authority': if (!($t_table = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table'], true))) { break; } if (!$t_table->load($pn_row_id)) { return '???'; } return $t_table->getLabelForDisplay(); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'attribute': $t_element = new ca_metadata_elements(); if (!$t_element->load(array('element_code' => $va_facet_info['element_code']))) { return urldecode($pn_row_id); } $vn_element_id = $t_element->getPrimaryKey(); switch ($vn_element_type = $t_element->get('datatype')) { case __CA_ATTRIBUTE_VALUE_LIST__: $t_list = new ca_lists(); return $t_list->getItemFromListForDisplayByItemID($t_element->get('list_id'), $pn_row_id, true); break; case __CA_ATTRIBUTE_VALUE_OBJECTS__: case __CA_ATTRIBUTE_VALUE_ENTITIES__: case __CA_ATTRIBUTE_VALUE_PLACES__: case __CA_ATTRIBUTE_VALUE_OCCURRENCES__: case __CA_ATTRIBUTE_VALUE_COLLECTIONS__: case __CA_ATTRIBUTE_VALUE_LOANS__: case __CA_ATTRIBUTE_VALUE_MOVEMENTS__: case __CA_ATTRIBUTE_VALUE_STORAGELOCATIONS__: case __CA_ATTRIBUTE_VALUE_OBJECTLOTS__: if ($t_rel_item = AuthorityAttributeValue::elementTypeToInstance($vn_element_type)) { return $t_rel_item->load($pn_row_id) ? $t_rel_item->getLabelForDisplay() : "???"; } break; default: return urldecode($pn_row_id); break; } break; # ----------------------------------------------------- # ----------------------------------------------------- case 'field': if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) { break; } if ($vb_is_bit = $t_item->getFieldInfo($va_facet_info['field'], 'FIELD_TYPE') == FT_BIT) { return (bool) $pn_row_id ? caGetOption('label_yes', $va_facet_info, _t('Yes')) : caGetOption('label_no', $va_facet_info, _t('No')); } return urldecode($pn_row_id); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'violations': if (!($t_rule = $this->opo_datamodel->getInstanceByTableName('ca_metadata_dictionary_rules', true))) { break; } if ($t_rule->load(array('rule_code' => $pn_row_id))) { return $t_rule->getSetting('label'); } return urldecode($pn_row_id); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'checkouts': $vs_status_text = null; $vs_status_code = isset($va_facet_info['status']) && $va_facet_info['status'] ? $va_facet_info['status'] : $pn_row_id; switch ($vs_status_code) { case 'overdue': $vs_status_text = _t('Overdue'); break; case 'reserved': $vs_status_text = _t('Reserved'); break; case 'available': $vs_status_text = _t('Available'); break; default: case 'out': $vs_status_text = _t('Out'); break; } $va_params = array(); switch ($va_facet_info['mode']) { case 'user': $vs_name = null; $t_user = new ca_users($pn_row_id); if ($t_user->getPrimaryKey()) { $vs_name = $t_user->get('fname') . ' ' . $t_user->get('lname') . (($vs_email = $t_user->get('email')) ? " ({$vs_email})" : ""); return _t('%1 for %2', $vs_status_text, $vs_name); } break; default: case 'all': return $vs_status_text; break; } return urldecode($pn_row_id); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'location': $va_tmp = explode(":", urldecode($pn_row_id)); $vs_loc_table_name = $this->opo_datamodel->getTableName($va_tmp[0]); $va_collapse_map = $this->getCollapseMapForLocationFacet($va_facet_info); $t_instance = $this->opo_datamodel->getInstanceByTableName($vs_loc_table_name, true); if (($vs_table_name = $vs_loc_table_name) == 'ca_objects_x_storage_locations') { $vs_table_name = 'ca_storage_locations'; } if (isset($va_collapse_map[$vs_table_name][$va_tmp[1]])) { // Class/subclass is collapsable return $va_collapse_map[$vs_table_name][$va_tmp[1]]; } elseif (isset($va_collapse_map[$vs_table_name]['*'])) { // Class is collapsable return $va_collapse_map[$vs_table_name]['*']; } elseif ($va_tmp[2] && ($qr_res = caMakeSearchResult($vs_table_name, array($va_tmp[2]))) && $qr_res->nextHit()) { // Return label for id $va_config = ca_objects::getConfigurationForCurrentLocationType($vs_table_name, $va_tmp[1]); $vs_template = isset($va_config['template']) ? $va_config['template'] : "^{$vs_table_name}.preferred_labels"; return caTruncateStringWithEllipsis($qr_res->getWithTemplate($vs_template), 30, 'end'); } return '???'; break; # ----------------------------------------------------- # ----------------------------------------------------- case 'normalizedLength': $vn_start = urldecode($pn_row_id); if (!($vs_output_units = caGetLengthUnitType($vs_units = caGetOption('units', $va_facet_info, 'm')))) { $vs_output_units = Zend_Measure_Length::METER; } $vs_increment = caGetOption('increment', $va_facet_info, '1 m'); $vo_increment = caParseLengthDimension($vs_increment); $vn_increment_in_current_units = (double) $vo_increment->convertTo($vs_output_units, 6, 'en_US'); $vn_end = $vn_start + $vn_increment_in_current_units; return "{$vn_start} {$vs_units} - {$vn_end} {$vs_units}"; break; # ----------------------------------------------------- # ----------------------------------------------------- case 'normalizedDates': return $pn_row_id === 'null' ? _t('Date unknown') : urldecode($pn_row_id); break; # ----------------------------------------------------- # ----------------------------------------------------- case 'fieldList': if (!($t_item = $this->opo_datamodel->getInstanceByTableName($this->ops_browse_table_name, true))) { break; } $vs_field_name = $va_facet_info['field']; $va_field_info = $t_item->getFieldInfo($vs_field_name); $t_list = new ca_lists(); if ($vs_list_name = $va_field_info['LIST_CODE']) { $t_list_item = new ca_list_items($pn_row_id); if ($vs_tmp = $t_list_item->getLabelForDisplay()) { return $vs_tmp; } return '???'; } else { if ($vs_list_name = $va_field_info['LIST']) { if (is_array($va_list_items = $t_list->getItemsForList($vs_list_name))) { $va_list_items = caExtractValuesByUserLocale($va_list_items); foreach ($va_list_items as $vn_id => $va_list_item) { if ($va_list_item['item_value'] == $pn_row_id) { return $va_list_item['name_plural']; } } } } } if (isset($va_field_info['BOUNDS_CHOICE_LIST'])) { $va_choice_list = $va_field_info['BOUNDS_CHOICE_LIST']; if (is_array($va_choice_list)) { foreach ($va_choice_list as $vs_val => $vn_id) { if ($vn_id == $pn_row_id) { return $vs_val; } } } } if ($va_facet_info['table'] && ($t_browse_table = $this->opo_datamodel->getInstanceByTableName($vs_facet_table = $va_facet_info['table'], true))) { if (!($app = AppController::getInstance())) { return '???'; } if ($t_browse_table->load($pn_row_id) && $t_browse_table->isReadable($app->getRequest(), 'preferred_labels')) { return $t_browse_table->get("{$vs_facet_table}.preferred_labels"); } } return '???'; break; # ----------------------------------------------------- # ----------------------------------------------------- default: if ($ps_facet_name == '_search') { return $pn_row_id; } return 'Invalid type'; break; # ----------------------------------------------------- } }
public function dispatchLoopShutdown() { // // Force output to be sent - we need the client to have the page before // we start flushing progress bar updates // $app = AppController::getInstance(); $req = $app->getRequest(); $resp = $app->getResponse(); $resp->sendResponse(); $resp->clearContent(); // // Do reindexing // if ($req->isLoggedIn() && $req->user->canDoAction('can_do_search_reindex')) { set_time_limit(3600 * 8); $o_db = new Db(); $t_timer = new Timer(); $va_table_names = array('ca_objects', 'ca_object_lots', 'ca_places', 'ca_entities', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_object_representations', 'ca_representation_annotations', 'ca_lists', 'ca_list_items', 'ca_loans', 'ca_movements', 'ca_tours', 'ca_tour_stops'); $vn_tc = 0; foreach ($va_table_names as $vs_table) { require_once __CA_MODELS_DIR__ . "/{$vs_table}.php"; $t_table = new $vs_table(); $vs_pk = $t_table->primaryKey(); $qr_res = $o_db->query("SELECT {$vs_pk} FROM {$vs_table}"); if ($vs_label_table_name = $t_table->getLabelTableName()) { require_once __CA_MODELS_DIR__ . "/{$vs_label_table_name}.php"; $va_table_names[] = $vs_label_table_name; $t_label = new $vs_label_table_name(); $vs_label_pk = $t_label->primaryKey(); $qr_labels = $o_db->query("SELECT {$vs_label_pk} FROM {$vs_label_table_name}"); $vn_c = 0; $vn_num_rows = $qr_labels->numRows(); $vn_table_num = $t_label->tableNum(); while ($qr_labels->nextRow()) { $vn_label_pk_val = $qr_labels->get($vs_label_pk); if (!($vn_c % 100)) { caIncrementSortValueReloadProgress($vn_c, $vn_num_rows, null, null, $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $vn_table_num, $t_label->getProperty('NAME_PLURAL'), $vn_tc + 1); } if ($t_label->load($vn_label_pk_val)) { $t_label->setMode(ACCESS_WRITE); $t_label->update(); } $vn_c++; } $vn_tc++; } $vn_table_num = $t_table->tableNum(); $vn_num_rows = $qr_res->numRows(); $vn_c = 0; while ($qr_res->nextRow()) { $vn_pk_val = $qr_res->get($vs_pk); if (!($vn_c % 100)) { caIncrementSortValueReloadProgress($vn_c, $vn_num_rows, null, null, $t_timer->getTime(2), memory_get_usage(true), $va_table_names, $vn_table_num, $t_table->getProperty('NAME_PLURAL'), $vn_tc + 1); } if ($t_table->load($vn_pk_val)) { $t_table->setMode(ACCESS_WRITE); if ($vs_table == 'ca_object_representations') { $t_table->set('md5', $t_table->getMediaInfo('ca_object_representations.media', 'original', 'MD5')); $t_table->set('mimetype', $t_table->getMediaInfo('ca_object_representations.media', 'original', 'MIMETYPE')); $va_media_info = $t_table->getMediaInfo('ca_object_representations.media'); $t_table->set('original_filename', $va_media_info['ORIGINAL_FILENAME']); } $t_table->update(); if ($vs_table == 'ca_object_representations') { if (!$t_table->getPreferredLabelCount()) { $t_table->addLabel(array('name' => trim($va_media_info['ORIGINAL_FILENAME']) ? $va_media_info['ORIGINAL_FILENAME'] : _t('Representation')), $pn_locale_id, null, true); } } } $vn_c++; } $vn_tc++; } caIncrementSortValueReloadProgress(1, 1, _t('Elapsed time: %1', caFormatInterval($t_timer->getTime(2))), _t('Index rebuild complete!'), $t_timer->getTime(2), memory_get_usage(true), $va_table_names, null, null, sizeof($va_table_names)); } }
define("APP_CONTR_DIR", APP_DIR . "controller/"); define("APP_VIEW_DIR", APP_DIR . "view/"); // VIEWS // specific Views are not autoloaded so fa: //require(APP_VIEW_DIR."specific/SpecificView.class.php"); // Autoloading function __autoload($classname) { if (file_exists(MAIN_DIR . "view/" . $classname . ".class.php")) { require MAIN_DIR . "view/" . $classname . ".class.php"; } if (file_exists(APP_CONTR_DIR . $classname . ".class.php")) { require APP_CONTR_DIR . $classname . ".class.php"; } if (file_exists(APP_CONTR_DIR . "forms/" . $classname . ".class.php")) { require APP_CONTR_DIR . "forms/" . $classname . ".class.php"; } if (file_exists(APP_CONTR_DIR . "exceptions/" . $classname . ".class.php")) { require APP_CONTR_DIR . "exceptions/" . $classname . ".class.php"; } if (file_exists(APP_VIEW_DIR . $classname . ".class.php")) { require APP_VIEW_DIR . $classname . ".class.php"; } if (file_exists(MODEL_DIR . $classname . ".php")) { require MODEL_DIR . $classname . ".php"; } DIYFrameworkLoader::__autoload($classname, "lib/diy-framework/classes/diy-framework/"); } // Runs controller AppController::getInstance()->process(Request::getInstance(), Response::getInstance(), AppMapping::getInstance());
/** * * * */ public function ImportData() { global $g_ui_locale_id; $t_importer = $this->getImporterInstance(); if (!($t_subject = $t_importer->getAppDatamodel()->getInstanceByTableNum($t_importer->get('table_num'), true))) { return $this->Index(); } $va_options = array('sendMail' => (bool) $this->request->getParameter('send_email_when_done', pInteger), 'sendSMS' => (bool) $this->request->getParameter('send_sms_when_done', pInteger), 'locale_id' => $g_ui_locale_id, 'user_id' => $this->request->getUserID(), 'logLevel' => $this->request->getParameter("logLevel", pInteger), 'dryRun' => $this->request->getParameter("dryRun", pInteger), 'fileInput' => $this->request->getParameter("fileInput", pString), 'fileImportPath' => $this->request->getParameter("fileImportPath", pString), 'importAllDatasets' => (bool) $this->request->getParameter("importAllDatasets", pInteger), 'originalFilename' => $vs_name); $va_last_settings = $va_options; $va_last_settings['importer_id'] = $this->request->getParameter("importer_id", pInteger); $va_last_settings['inputFormat'] = $this->request->getParameter("inputFormat", pString); $va_last_settings['logLevel'] = $this->request->getParameter("logLevel", pInteger); $va_last_settings['dryRun'] = $this->request->getParameter("dryRun", pInteger); if ($vs_file_input = $this->request->getParameter("fileInput", pString)) { $va_last_settings['fileInput'] = $vs_file_input; } if ($vs_file_import_path = $this->request->getParameter("fileImportPath", pString)) { $va_last_settings['fileImportPath'] = $vs_file_import_path; } $this->request->user->setVar('batch_metadata_last_settings', $va_last_settings); $this->view->setVar("t_subject", $t_subject); // run now $app = AppController::getInstance(); $app->registerPlugin(new BatchMetadataImportProgress($this->request, $va_options)); $this->render('metadataimport/batch_results_html.php'); }
/** * Export list/set of records via Batch processor */ public function ExportData() { // Can user batch export? if (!$this->getRequest()->user->canDoAction('can_batch_export_metadata')) { $this->getResponse()->setRedirect($this->getRequest()->config->get('error_display_url') . '/n/3440?r=' . urlencode($this->getRequest()->getFullUrlPath())); return; } $t_exporter = $this->getExporterInstance(); $t_subject = $t_exporter->getAppDatamodel()->getInstanceByTableNum($t_exporter->get('table_num'), true); // Can user export records of this type? if (!$this->getRequest()->user->canDoAction('can_export_' . $t_subject->tableName())) { $this->getResponse()->setRedirect($this->getRequest()->config->get('error_display_url') . '/n/3430?r=' . urlencode($this->getRequest()->getFullUrlPath())); return; } $this->getView()->setVar("t_subject", $t_subject); // run now $app = AppController::getInstance(); $app->registerPlugin(new BatchMetadataExportProgress($this->getRequest())); $this->render('export/export_results_html.php'); }
/** * */ public function Present() { AssetLoadManager::register("reveal.js"); $o_app = AppController::getInstance(); $o_app->removeAllPlugins(); $t_set = $this->_getSet(); $this->view->setVar("set", $t_set); $this->render("Sets/present_html.php"); }
/** * Saves the content of a form editing new or existing records. It returns the same form + status messages rendered into the current view, inherited from ActionController * * @param array $pa_options Array of options passed through to _initView and saveBundlesForScreen() */ public function Save($pa_options = null) { global $g_ui_locale_id; if (!is_array($pa_options)) { $pa_options = array(); } list($t_ui) = $this->_initView($pa_options); $vs_import_target = $this->getRequest()->getParameter('import_target', pString); if (!$this->getRequest()->getAppDatamodel()->tableExists($vs_import_target)) { $vs_import_target = 'ca_objects'; } $vs_directory = $this->request->getParameter('directory', pString); $vs_batch_media_import_root_directory = $this->request->config->get('batch_media_import_root_directory'); if (preg_match("!/\\.\\.!", $vs_directory) || preg_match("!\\.\\./!", $vs_directory)) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3250?r=' . urlencode($this->request->getFullUrlPath())); return; } if (!is_dir($vs_batch_media_import_root_directory . '/' . $vs_directory)) { $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/3250?r=' . urlencode($this->request->getFullUrlPath())); return; } $va_options = array('sendMail' => (bool) $this->request->getParameter('send_email_when_done', pInteger), 'sendSMS' => (bool) $this->request->getParameter('send_sms_when_done', pInteger), 'runInBackground' => (bool) $this->request->getParameter('run_in_background', pInteger), 'importFromDirectory' => $vs_batch_media_import_root_directory . '/' . $vs_directory, 'includeSubDirectories' => (bool) $this->request->getParameter('include_subdirectories', pInteger), 'deleteMediaOnImport' => (bool) $this->request->getParameter('delete_media_on_import', pInteger), 'importMode' => $this->request->getParameter('import_mode', pString), 'matchMode' => $this->request->getParameter('match_mode', pString), 'matchType' => $this->request->getParameter('match_type', pString), $vs_import_target . '_limit_matching_to_type_ids' => $this->request->getParameter($vs_import_target . '_limit_matching_to_type_ids', pArray), $vs_import_target . '_type_id' => $this->request->getParameter($vs_import_target . '_type_id', pInteger), 'ca_object_representations_type_id' => $this->request->getParameter('ca_object_representations_type_id', pInteger), $vs_import_target . '_status' => $this->request->getParameter($vs_import_target . '_status', pInteger), 'ca_object_representations_status' => $this->request->getParameter('ca_object_representations_status', pInteger), $vs_import_target . '_access' => $this->request->getParameter($vs_import_target . '_access', pInteger), 'ca_object_representations_access' => $this->request->getParameter('ca_object_representations_access', pInteger), $vs_import_target . '_mapping_id' => $this->request->getParameter($vs_import_target . '_mapping_id', pInteger), 'ca_object_representations_mapping_id' => $this->request->getParameter('ca_object_representations_mapping_id', pInteger), 'setMode' => $this->request->getParameter('set_mode', pString), 'setCreateName' => $this->request->getParameter('set_create_name', pString), 'set_id' => $this->request->getParameter('set_id', pInteger), 'idnoMode' => $this->request->getParameter('idno_mode', pString), 'idno' => $this->request->getParameter('idno', pString), 'representationIdnoMode' => $this->request->getParameter('representation_idno_mode', pString), 'representation_idno' => $this->request->getParameter('idno_representation_number', pString), 'logLevel' => $this->request->getParameter('log_level', pString), 'allowDuplicateMedia' => $this->request->getParameter('allow_duplicate_media', pInteger), 'locale_id' => $g_ui_locale_id, 'user_id' => $this->request->getUserID(), 'skipFileList' => $this->request->getParameter('skip_file_list', pString), 'importTarget' => $vs_import_target); if ($vn_rel_type = $this->request->getParameter($vs_import_target . '_representation_relationship_type', pInteger)) { $va_options[$vs_import_target . '_representation_relationship_type'] = $vn_rel_type; } if (is_array($va_create_relationships_for = $this->request->getParameter('create_relationship_for', pArray))) { $va_options['create_relationship_for'] = $va_create_relationships_for; foreach ($va_create_relationships_for as $vs_rel_table) { $va_options['relationship_type_id_for_' . $vs_rel_table] = $this->request->getParameter('relationship_type_id_for_' . $vs_rel_table, pString); } } $va_last_settings = $va_options; $va_last_settings['importFromDirectory'] = preg_replace("!{$vs_batch_media_import_root_directory}[/]*!", "", $va_last_settings['importFromDirectory']); $this->request->user->setVar('batch_mediaimport_last_settings', $va_last_settings); if ((bool) $this->request->config->get('queue_enabled') && (bool) $this->request->getParameter('run_in_background', pInteger)) { // queue for background processing $o_tq = new TaskQueue(); $vs_row_key = $vs_entity_key = join("/", array($this->request->getUserID(), $va_options['importFromDirectory'], time(), rand(1, 999999))); if (!$o_tq->addTask('mediaImport', $va_options, array("priority" => 100, "entity_key" => $vs_entity_key, "row_key" => $vs_row_key, 'user_id' => $this->request->getUserID()))) { //$this->postError(100, _t("Couldn't queue batch processing for"),"EditorContro->_processMedia()"); } $this->render('mediaimport/batch_queued_html.php'); } else { // run now $app = AppController::getInstance(); $app->registerPlugin(new BatchMediaImportProgress($this->request, $va_options)); $this->render('mediaimport/batch_results_html.php'); } }