Skip to content

Commit

Permalink
Save extra data in admin panel - refs BT#9325
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Feb 3, 2015
1 parent 762c4b3 commit 646a600
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
9 changes: 7 additions & 2 deletions main/admin/index.php
Expand Up @@ -68,6 +68,8 @@
$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="">
Expand Down Expand Up @@ -108,6 +110,7 @@
$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="">
Expand Down Expand Up @@ -147,7 +150,7 @@
$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="" >
Expand All @@ -156,7 +159,6 @@
</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'));
Expand Down Expand Up @@ -195,6 +197,9 @@
$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="">
Expand Down
7 changes: 7 additions & 0 deletions main/css/base.css
Expand Up @@ -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;
}
43 changes: 43 additions & 0 deletions main/inc/ajax/admin.ajax.php
Expand Up @@ -35,6 +35,49 @@
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;
}


Expand Down
47 changes: 47 additions & 0 deletions main/template/default/admin/settings_index.tpl
Expand Up @@ -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>

Expand All @@ -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 }}
Expand All @@ -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>

0 comments on commit 646a600

Please sign in to comment.