Merge pull request #468 from AngelFQC/BT9325

Add extra content in admin panels - refs BT#9325
1.9.x
Yannick Warnier 10 years ago
commit 6b9b7b5832
  1. 45
      main/admin/index.php
  2. 11
      main/css/base.css
  3. 68
      main/inc/ajax/admin.ajax.php
  4. 64
      main/template/default/admin/settings_index.tpl

@ -26,6 +26,20 @@ api_protect_admin_script(true);
$nameTools = get_lang('PlatformAdmin'); $nameTools = get_lang('PlatformAdmin');
if (api_is_multiple_url_enabled()) {
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId != -1) {
$urlInfo = api_get_access_url($accessUrlId);
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $urlInfo['url']));
$cleanUrl = str_replace('/', '-', $url);
$adminExtraContentDir = api_get_path(SYS_PATH) . "home/$cleanUrl/admin/";
}
} else {
$adminExtraContentDir = api_get_path(SYS_PATH) . "home/admin/";
}
// Displaying the header // Displaying the header
$message = ''; $message = '';
@ -67,7 +81,15 @@ $blocks['users']['icon'] = Display::return_icon('members.gif', get_lang('Users'
$blocks['users']['label'] = api_ucfirst(get_lang('Users')); $blocks['users']['label'] = api_ucfirst(get_lang('Users'));
$blocks['users']['class'] = 'block-admin-users'; $blocks['users']['class'] = 'block-admin-users';
$usersBlockExtraFile = "{$adminExtraContentDir}block-admin-users_extra.html";
if (file_exists($usersBlockExtraFile)) {
$blocks['users']['extraContent'] = file_get_contents($usersBlockExtraFile);
}
if (api_is_platform_admin()) { if (api_is_platform_admin()) {
$blocks['users']['editable'] = true;
$search_form = ' $search_form = '
<form method="get" class="form-search" action="user_list.php"> <form method="get" class="form-search" action="user_list.php">
<input class="span3" type="text" name="keyword" value=""> <input class="span3" type="text" name="keyword" value="">
@ -108,6 +130,13 @@ if (api_is_platform_admin()) {
$blocks['courses']['icon'] = Display::return_icon('course.gif', get_lang('Courses'), array(), ICON_SIZE_MEDIUM, false); $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']['label'] = api_ucfirst(get_lang('Courses'));
$blocks['courses']['class'] = 'block-admin-courses'; $blocks['courses']['class'] = 'block-admin-courses';
$blocks['courses']['editable'] = true;
$coursesBlockExtraFile = "{$adminExtraContentDir}block-admin-courses_extra.html";
if (file_exists($coursesBlockExtraFile)) {
$blocks['courses']['extraContent'] = file_get_contents($coursesBlockExtraFile);
}
$search_form = ' <form method="get" class="form-search" action="course_list.php"> $search_form = ' <form method="get" class="form-search" action="course_list.php">
<input class="span3" type="text" name="keyword" value=""> <input class="span3" type="text" name="keyword" value="">
@ -147,7 +176,13 @@ if (api_is_platform_admin()) {
$blocks['platform']['icon'] = Display::return_icon('platform.png', get_lang('Platform'), array(), ICON_SIZE_MEDIUM, false); $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']['label'] = api_ucfirst(get_lang('Platform'));
$blocks['platform']['class'] = 'block-admin-platform'; $blocks['platform']['class'] = 'block-admin-platform';
$blocks['platform']['editable'] = true;
$platformBlockExtraFile = "{$adminExtraContentDir}block-admin-platform_extra.html";
if (file_exists($platformBlockExtraFile)) {
$blocks['platform']['extraContent'] = file_get_contents($platformBlockExtraFile);
}
$search_form = ' <form method="get" action="settings.php" class="form-search"> $search_form = ' <form method="get" action="settings.php" class="form-search">
<input class="span3" type="text" name="search_field" value="" > <input class="span3" type="text" name="search_field" value="" >
@ -156,7 +191,6 @@ if (api_is_platform_admin()) {
</form>'; </form>';
$blocks['platform']['search_form'] = $search_form; $blocks['platform']['search_form'] = $search_form;
$items = array(); $items = array();
$items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings')); $items[] = array('url'=>'settings.php', 'label' => get_lang('PlatformConfigSettings'));
$items[] = array('url'=>'settings.php?category=Plugins','label' => get_lang('Plugins')); $items[] = array('url'=>'settings.php?category=Plugins','label' => get_lang('Plugins'));
@ -195,6 +229,15 @@ $blocks['sessions']['icon'] = Display::return_icon('session.png', get_lang('Ses
$blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions')); $blocks['sessions']['label'] = api_ucfirst(get_lang('Sessions'));
$blocks['sessions']['class'] = 'block-admin-sessions'; $blocks['sessions']['class'] = 'block-admin-sessions';
$sessionsBlockExtraFile = "{$adminExtraContentDir}block-admin-sessions_extra.html";
if (file_exists($sessionsBlockExtraFile)) {
$blocks['sessions']['extraContent'] = file_get_contents($sessionsBlockExtraFile);
}
if (api_is_platform_admin()) {
$blocks['sessions']['editable'] = true;
}
$search_form = ' <form method="GET" class="form-search" action="session_list.php"> $search_form = ' <form method="GET" class="form-search" action="session_list.php">
<input class="span3" type="text" name="keyword" value=""> <input class="span3" type="text" name="keyword" value="">

@ -5304,3 +5304,14 @@ i.size-32.icon-new-work{
{ {
height: 52px; height: 52px;
} }
#settings .span6 .well_border .edit-block {
display: none;
}
#settings .span6 .well_border:hover .edit-block {
display: block;
}
#settings .span6:nth-child(2n+1) {
clear:left
}

@ -35,6 +35,74 @@ switch ($action) {
case 'version': case 'version':
echo version_check(); echo version_check();
break; break;
case 'save_block_extra':
$content = isset($_POST['content']) ? Security::remove_XSS($_POST['content']) : null;
$blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
if (empty($blockName)) {
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 = str_replace('/', '-', $url);
$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(), true);
}
$fullFilePath = "{$newUrlDir}{$blockName}_extra.html";
if (file_exists($fullFilePath)) {
@unlink($fullFilePath);
}
@touch($fullFilePath);
@file_put_contents($fullFilePath, $content);
break;
case 'get_extra_content':
$blockName = isset($_POST['block']) ? Security::remove_XSS($_POST['block']) : null;
if (empty($blockName)) {
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 = str_replace('/', '-', $url);
$newUrlDir = api_get_path(SYS_PATH) . "home/$cleanUrl/admin/";
} else {
$newUrlDir = api_get_path(SYS_PATH) . "home/admin/";
}
if (Security::check_abs_path("{$newUrlDir}{$blockName}_extra.html", $newUrlDir)) {
echo @file_get_contents("{$newUrlDir}{$blockName}_extra.html");
}
break;
} }

@ -6,6 +6,41 @@ $(document).ready(function() {
$(".admin-block-version").html(version); $(".admin-block-version").html(version);
} }
}); });
$('.edit-block a').on('click', function(e) {
e.preventDefault();
var $self = $(this);
var extraContent = $.ajax('{{ _p.web_ajax }}admin.ajax.php', {
type: 'post',
data: {
a: 'get_extra_content',
block: $self.data('id')
}
});
$.when(extraContent).done(function(content) {
$('#extra-content').val(content);
$('#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> </script>
@ -14,6 +49,13 @@ $(document).ready(function() {
{% for block_item in blocks %} {% for block_item in blocks %}
<div id="tabs-{{ loop.index }}" class="span6"> <div id="tabs-{{ loop.index }}" class="span6">
<div class="well_border {{ block_item.class }}"> <div class="well_border {{ block_item.class }}">
{% if block_item.editable and _u.is_admin %}
<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> <h4>{{ block_item.icon }} {{ block_item.label }}</h4>
<div style="list-style-type:none"> <div style="list-style-type:none">
{{ block_item.search_form }} {{ block_item.search_form }}
@ -35,8 +77,30 @@ $(document).ready(function() {
{{ block_item.extra }} {{ block_item.extra }}
</div> </div>
{% endif %} {% endif %}
{% if block_item.extraContent %}
<div>{{ block_item.extraContent }}</div>
{% endif %}
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% if _u.is_admin %}
<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">
<button id="btn-block-editor-save" class="btn btn-primary">{{ 'Save' | get_lang }}</button>
</div>
</div>
{% endif %}

Loading…
Cancel
Save