Save extra data in admin panel - refs BT#9325

1.9.x
Angel Fernando Quiroz Campos 10 years ago
parent 762c4b3f2c
commit 646a600e3e
  1. 9
      main/admin/index.php
  2. 7
      main/css/base.css
  3. 43
      main/inc/ajax/admin.ajax.php
  4. 47
      main/template/default/admin/settings_index.tpl

@ -68,6 +68,8 @@ $blocks['users']['label'] = api_ucfirst(get_lang('Users'));
$blocks['users']['class'] = 'block-admin-users';
if (api_is_platform_admin()) {
$blocks['users']['editable'] = true;
$search_form = '
<form method="get" class="form-search" action="user_list.php">
<input class="span3" type="text" name="keyword" value="">
@ -108,6 +110,7 @@ if (api_is_platform_admin()) {
$blocks['courses']['icon'] = Display::return_icon('course.gif', get_lang('Courses'), array(), ICON_SIZE_MEDIUM, false);
$blocks['courses']['label'] = api_ucfirst(get_lang('Courses'));
$blocks['courses']['class'] = 'block-admin-courses';
$blocks['courses']['editable'] = true;
$search_form = ' <form method="get" class="form-search" action="course_list.php">
<input class="span3" type="text" name="keyword" value="">
@ -147,7 +150,7 @@ if (api_is_platform_admin()) {
$blocks['platform']['icon'] = Display::return_icon('platform.png', get_lang('Platform'), array(), ICON_SIZE_MEDIUM, false);
$blocks['platform']['label'] = api_ucfirst(get_lang('Platform'));
$blocks['platform']['class'] = 'block-admin-platform';
$blocks['platform']['editable'] =true;
$search_form = ' <form method="get" action="settings.php" class="form-search">
<input class="span3" type="text" name="search_field" value="" >
@ -156,7 +159,6 @@ if (api_is_platform_admin()) {
</form>';
$blocks['platform']['search_form'] = $search_form;
$items = array();
$items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings'));
$items[] = array('url'=>'settings.php?category=Plugins','label' => get_lang('Plugins'));
@ -195,6 +197,9 @@ $blocks['sessions']['icon'] = Display::return_icon('session.png', get_lang('Ses
$blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions'));
$blocks['sessions']['class'] = 'block-admin-sessions';
if (api_is_platform_admin()) {
$blocks['sessions']['editable'] = true;
}
$search_form = ' <form method="GET" class="form-search" action="session_list.php">
<input class="span3" type="text" name="keyword" value="">

@ -5304,3 +5304,10 @@ i.size-32.icon-new-work{
{
height: 52px;
}
#settings .span6 .well_border .edit-block {
display: none;
}
#settings .span6 .well_border:hover .edit-block {
display: block;
}

@ -35,6 +35,49 @@ switch ($action) {
case 'version':
echo version_check();
break;
case 'save_block_extra':
$content = isset($_POST['content']) ? Security::remove_XSS($_POST['content']) : null;
$blockId = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
if (empty($content) || empty($blockId)) {
die;
}
if (api_is_multiple_url_enabled()) {
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId == -1) {
die;
}
$urlInfo = api_get_access_url($accessUrlId);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
$cleanUrl = replace_dangerous_char($url);
$cleanUrl = str_replace('/', '-', $cleanUrl);
$newUrlDir = api_get_path(SYS_PATH) . "home/$cleanUrl/admin/";
} else {
$newUrlDir = api_get_path(SYS_PATH) . "home/admin/";
}
if (!is_dir($newUrlDir)) {
mkdir($newUrlDir, api_get_permissions_for_new_directories());
}
$fullFilePath = "{$newUrlDir}{$blockId}_extra.txt";
echo $fullFilePath;
if (file_exists($fullFilePath)) {
unlink($fullFilePath);
}
touch($fullFilePath);
file_put_contents($fullFilePath, $content);
break;
}

@ -6,6 +6,30 @@ $(document).ready(function() {
$(".admin-block-version").html(version);
}
});
$('.edit-block a').on('click', function(e) {
e.preventDefault();
var $self = $(this);
$('#extra-block').val($self.data('id'));
$('#modal-extra-title').text($self.data('label'));
$('#modal-extra').modal('show');
});
$('#btn-block-editor-save').on('click', function(e) {
e.preventDefault();
var save = $.ajax('{{ _p.web_ajax }}admin.ajax.php', {
type: 'post',
data: $('#block-extra-data').serialize() + '&a=save_block_extra'
});
$.when(save).done(function() {
window.location.reload();
});
});
});
</script>
@ -14,6 +38,13 @@ $(document).ready(function() {
{% for block_item in blocks %}
<div id="tabs-{{ loop.index }}" class="span6">
<div class="well_border {{ block_item.class }}">
{% if block_item.editable and _u.status == 1 %}
<div class="pull-right edit-block" id="edit-{{ block_item.class }}">
<a href="#" data-label="{{ block_item.label }}" data-id="{{ block_item.class }}">
<img src="{{ _p.web_img }}icons/22/edit.png" alt="{{ 'Edit' | get_lang }}" title="{{ 'Edit' | get_lang }}">
</a>
</div>
{% endif %}
<h4>{{ block_item.icon }} {{ block_item.label }}</h4>
<div style="list-style-type:none">
{{ block_item.search_form }}
@ -40,3 +71,19 @@ $(document).ready(function() {
{% endfor %}
</div>
</div>
<div id="modal-extra" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="modal-extra-title" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 id="modal-extra-title">{{ 'Blocks' | get_lang }}</h3>
</div>
<div class="modal-body">
<form action="#" method="post" id="block-extra-data">
<textarea rows="5" name="content" class="input-block-level" id="extra-content"></textarea>
<input type="hidden" name="block" id="extra-block" value="">
</form>
</div>
<div class="modal-footer">
<a href="#" id="btn-block-editor-save" class="btn btn-primary">{{ 'Save' | get_lang }}</a>
</div>
</div>

Loading…
Cancel
Save