Commit 99561341 authored by Maria Sorica's avatar Maria Sorica

Bug 1734182: Add the edit/view logic to the site privacy page

behatnotneeded

Change-Id: I5559d777409f9416e52b911dedd73a3c6fb36fe4
parent de00191e
......@@ -17,6 +17,7 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'privacy');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('privacy', 'admin'));
$versionid = param_integer('id', null);
if (!is_logged_in()) {
throw new AccessDeniedException();
......@@ -24,13 +25,99 @@ if (!is_logged_in()) {
$data = get_records_sql_assoc("
SELECT s.id, s.version, u.firstname, u.lastname, u.id AS userid, s.content, s.ctime
FROM {site_content_version} s
LEFT JOIN {usr} u ON s.author = u.id");
FROM {site_content_version} s
LEFT JOIN {usr} u ON s.author = u.id
WHERE s.institution = ?
ORDER BY s.id DESC", array('mahara'));
krsort($data);
if ($versionid) {
if ($pageoptions = get_record('site_content_version', 'id', $versionid, 'institution', 'mahara')) {
$form = pieform(array(
'name' => 'editsitepage',
'jsform' => false,
'jssuccesscallback' => 'contentSaved',
'elements' => array(
'version' => array(
'type' => 'text',
'title' => get_string('version', 'admin'),
'description' => get_string('lastversion', 'admin', $pageoptions->version),
'defaultvalue' => '',
'rules' => array(
'required' => true,
'maxlength' => 15
)
),
'pageinstitution' => array('type' => 'hidden', 'value' => 'mahara'),
'pagetext' => array(
'name' => 'pagetext',
'type' => 'wysiwyg',
'rows' => 25,
'cols' => 100,
'title' => get_string('pagetext', 'admin'),
'defaultvalue' => $pageoptions->content,
'rules' => array(
'maxlength' => 65536,
'required' => true
)
),
'submit' => array(
'class' => 'btn-primary',
'type' => 'submit',
'value' => get_string('savechanges', 'admin')
),
)
));
}
else {
throw new ViewNotFoundException(get_string('siteprivacystatementnotfound', 'error', $versionid));
}
}
$smarty = smarty();
setpageicon($smarty, 'icon-umbrella');
function editsitepage_validate(Pieform $form, $values) {
// Check if the version entered by the user already exists.
if (record_exists('site_content_version', 'institution', $values['pageinstitution'], 'version', $values['version'])) {
$form->set_error('version', get_string('versionalreadyexist', 'admin', $values['version']));
}
}
function editsitepage_submit(Pieform $form, $values) {
global $USER, $SESSION;
$id = get_field('site_content_version', 'id', 'version', $values['version']);
require_once('embeddedimage.php');
// Update the pagetext with any embedded image info
$pagetext = EmbeddedImage::prepare_embedded_images($values['pagetext'], 'staticpages', $id);
$data = new StdClass;
$data->content = $pagetext;
$data->author = $USER->get('id');
$data->institution = $values['pageinstitution'];
$data->ctime = db_format_timestamp(time());
$data->version = $values['version'];
$data->type = 'privacy';
try {
insert_record('site_content_version', $data);
$SESSION->add_ok_msg(get_string('pagesaved', 'admin'));
}
catch (SQLException $e) {
$SESSION->add_ok_msg(get_string('savefailed', 'admin'));
}
redirect(get_config('wwwroot').'admin/site/privacy.php');
}
if ($versionid && $pageoptions) {
$smarty = smarty(array('adminsitepages'), array(), array('admin' => array('discardpageedits')));
$smarty->assign('pageeditform', $form);
$smarty->assign('content', $pageoptions->content);
$smarty->assign('version', $pageoptions->version);
}
else {
$smarty = smarty();
}
setpageicon($smarty, 'icon-umbrella');
$smarty->assign('results', $data);
$smarty->assign('latestversion', reset($data)->version);
$smarty->assign('versionid', $versionid);
$smarty->assign('latestprivacyid', reset($data)->id);
$smarty->display('admin/site/privacy.tpl');
......@@ -1327,3 +1327,7 @@ $string['author'] = 'Author';
$string['content'] = 'Content';
$string['creationdate'] = 'Creation date';
$string['version'] = 'Version';
$string['viewversion'] = 'View version %s';
$string['editversion'] = 'Edit version %s';
$string['lastversion'] = 'Privacy statements must have unique version names of up to 15 characters. The latest version for this privacy statement is "%s".';
$string['versionalreadyexist'] = 'A privacy statement with the version name "%s" already exists.';
......@@ -94,7 +94,7 @@ $string['accessdeniedobjection'] = 'Access denied. The objection has already bee
$string['accessdeniedexception'] = 'You do not have access to view this page.';
$string['accessdeniednourlsecret'] = 'You do not have access to this functionality. Please provide the value for "urlsecret" from your config.php file as part of the URL.';
$string['accessdeniedbadge'] = 'You do not have access to view this badge.';
$string['siteprivacystatementnotfound'] = 'Site privacy statement with id %s not found.';
$string['viewnotfoundexceptiontitle'] = 'Page not found';
$string['viewnotfoundexceptionmessage'] = 'You tried to access a page that does not exist.';
$string['viewnotfound'] = 'Page with id %s not found.';
......
{include file="header.tpl"}
<div class="lead">{str tag="privacypagedescription" section="admin"}</div>
{if $versionid}
{if $version == $latestversion}
<div class="lead">{str tag="privacypagedescription" section="admin"}</div>
{if $pageeditform}
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">
{$pageeditform|safe}
</div>
</div>
</div>
{/if}
</div>
{else}
{$content|clean_html|safe}
{/if}
{else}
<div class="lead">{str tag="privacypagedescription" section="admin"}</div>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default view-container">
......@@ -27,8 +44,22 @@
{/if}
</td>
<td>{$result->content|truncate:100:"..."|htmlspecialchars_decode|strip_tags}</td>
<td>{$result->ctime|date_format:'%d %b %Y %H:%I'}</td>
<td class="control-buttons"></td>
<td>{$result->ctime|date_format:'%d %b %Y %H:%M'}</td>
<td class="control-buttons">
{if $key === $latestprivacyid}
<div class="btn-group">
<a href="{$WWWROOT}admin/site/privacy.php?id={$result->id}" title="{str tag=editversion section='admin' arg1='$result->version'}" class="btn btn-default btn-xs">
<span class="icon icon-pencil icon-lg" role="presentation" aria-hidden="true"></span>
</a>
</div>
{else}
<div class="btn-group">
<a href="{$WWWROOT}admin/site/privacy.php?id={$result->id}" title="{str tag=viewversion section='admin' arg1='$result->version'}" class="btn btn-default btn-xs">
<span class="icon icon-eye icon-lg" role="presentation" aria-hidden="true"></span>
</a>
</div>
{/if}
</td>
</tr>
{/foreach}
</tbody>
......@@ -38,4 +69,5 @@
</div>
</div>
</div>
{/if}
{include file="footer.tpl"}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment