本文整理汇总了PHP中AjaxResponse::prepare_ajax_response方法的典型用法代码示例。如果您正苦于以下问题:PHP AjaxResponse::prepare_ajax_response方法的具体用法?PHP AjaxResponse::prepare_ajax_response怎么用?PHP AjaxResponse::prepare_ajax_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AjaxResponse
的用法示例。
在下文中一共展示了AjaxResponse::prepare_ajax_response方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_module_settings
/**
* Save module settings
*/
function save_module_settings()
{
global $xoopsSecurity, $xoopsDB;
$mod = RMHttpRequest::post('mod', 'string', '');
$via_ajax = RMHttpRequest::post('via_ajax', 'integer', 0);
if ($via_ajax) {
$ajax = new AjaxResponse();
$ajax->prepare_ajax_response();
}
if ($mod == '') {
RMUris::redirect_with_message(__('A module has not been specified!', 'rmcommon'), 'settings.php', RMMSG_ERROR);
}
//echo RMHttpRequest::request('CUTOKEN_REQUEST', 'string', '') . ' ' . print_r($_SESSION['CUTOKEN_SESSION'], true); die();
if (!$xoopsSecurity->check(true, false, $via_ajax ? 'CUTOKEN' : 'XOOPS_TOKEN')) {
if ($via_ajax) {
$ajax->ajax_response(__('Session token expired. Please try again.', 'rmcommon'), 1, 0);
} else {
RMUris::redirect_with_message(__('Session token expired. Please try again.', 'rmcommon'), 'settings.php', RMMSG_WARN);
}
}
$module = RMModules::load_module($mod);
if (!$module) {
if ($via_ajax) {
$ajax->ajax_response(__('The specified module does not exists.', 'rmcommon'), 1, 1);
} else {
RMUris::redirect_with_message(__('The specified module does not exists.', 'rmcommon'), 'settings.php', RMMSG_ERROR);
}
}
$current_settings = (array) RMSettings::module_settings($module->getVar('dirname'));
$new_settings = RMHttpRequest::post(ucfirst($module->getVar('dirname')), 'array', array());
$configs = $module->getInfo('config');
$fields = array();
// Container for all fields and values
foreach ($configs as $option) {
$id = $option['name'];
$field = new stdClass();
$field->id = $id;
$field->value = isset($values->{$id}) ? $values->{$id} : $option['default'];
$field->caption = defined($option['title']) ? constant($option['title']) : $option['title'];
$field->description = defined($option['description']) ? constant($option['description']) : $option['description'];
$field->field = $option['formtype'];
$field->type = $option['valuetype'];
$field->options = isset($option['options']) ? $option['options'] : null;
$category = isset($option['category']) ? $option['category'] : 'all';
$fields[$id] = $field;
}
/**
* This keys already exists in database
*/
$to_save = array_intersect_key($new_settings, $current_settings);
/**
* This settings will be added to database beacause don't exists in table
*/
$to_add = array_diff_key($new_settings, $current_settings);
/**
* This keys has been removed from xoops_version.php file and then
* must be removed from table
*/
$to_delete = array_diff_key($current_settings, $new_settings);
$errors = '';
// Errors ocurred while saving
/**
* First for all, remove unused items
*/
$keys = array_keys($to_delete);
if (!empty($keys)) {
$sql = "DELETE FROM " . $xoopsDB->prefix("config") . " WHERE conf_modid = " . $module->mid() . " AND (conf_name = '" . implode("' OR conf_name='", $keys) . "')";
if (!$xoopsDB->queryF($sql)) {
$errors .= $xoopsDB->error() . '<br>';
}
}
/**
* Save existing items
*/
if (!empty($to_save)) {
foreach ($to_save as $name => $value) {
$item = new Rmcommon_Config_Item($name, $module->mid());
if (isset($fields[$name])) {
$item->setVar('conf_valuetype', $fields[$name]->type);
$item->setVar('conf_title', $fields[$name]->caption);
$item->setVar('conf_desc', $fields[$name]->description);
$item->setVar('conf_formtype', $fields[$name]->field);
}
$item->set_value($value, $item->getVar('conf_valuetype'));
$item->save();
}
}
/**
* Add new items
*/
if (!empty($to_add)) {
foreach ($to_add as $name => $value) {
$item = new Rmcommon_Config_Item($name, $module->mid());
if (isset($fields[$name])) {
$item->setVar('conf_modid', $module->mid());
$item->setVar('conf_name', $name);
$item->setVar('conf_valuetype', $fields[$name]->type);
//.........这里部分代码省略.........