Commit 94533acc authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1746259: Display and edit the T&C of an institution

behatnotneeded

Change-Id: I71f21f76129bc160904cffd1ff62dc6c7fd83c27
parent 4e67c147
......@@ -19,8 +19,8 @@ define('MENUITEM', 'manageinstitutions/privacy');
require_once('institution.php');
define('TITLE', get_string('legal', 'admin'));
define('SUBSECTIONHEADING', get_string('privacy', 'admin'));
$versionid = param_integer('id', null);
$fs = param_alpha('fs', 'privacy');
if (!is_logged_in()) {
throw new AccessDeniedException();
......@@ -51,19 +51,38 @@ $institutionselector = pieform(array(
$wwwroot = get_config('wwwroot');
// The "Add one" link displayed when an institution has no privay statement of its own.
$href = $wwwroot . 'admin/users/institutionprivacy.php?institution=' . $institution . '&id=0';
$privacies = 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
WHERE s.type = 'privacy' AND s.institution = ?
ORDER BY s.id DESC", array($institution));
$href = $wwwroot . 'admin/users/institutionprivacy.php?institution=' . $institution . '&id=0&fs=' . $fs;
// Get the institution's privacy statements and T&Cs.
$privacies = get_institution_versioned_content($institution);
// Add to an array the latest versions of both T&C and privacy statement.
$latestVersions = array(); $types = array();
if ($privacies) {
foreach ($privacies as $key => $content) {
if ($content->current != null) {
array_push($latestVersions, $key);
}
if (!in_array($content->type, $types)) {
// Useful in case an institution has just one type of content.
// Will use the $types to know on which tab to display the versions table.
array_push($types, $content->type);
}
$content->displayname = display_name($content->userid, null, true);
}
}
// Add 0 to $latestVersions, to allow the creation of a first privacy/T&C
if (count($types) <= 1) {
array_push($latestVersions, 0);
}
// Site privacy and T&C to display in an expandable panel.
$sitecontent = get_latest_privacy_versions(array('mahara'));
$selectedtab = $fs;
$form = false;
if ($versionid !== null) {
$pageoptions = get_record('site_content_version', 'id', $versionid, 'institution', $institution);
if ($versionid === 0 || $pageoptions) {
$selectedtab = ($versionid === 0) ? $selectedtab : $pageoptions->type;
$form = pieform(array(
'name' => 'editsitepage',
'jsform' => false,
......@@ -72,7 +91,7 @@ if ($versionid !== null) {
'version' => array(
'type' => 'text',
'title' => get_string('version', 'admin'),
'description' => $pageoptions ? get_string('lastversion', 'admin', $pageoptions->version) : '',
'description' => $pageoptions ? get_string($privacies[$versionid]->type . 'lastversion', 'admin', $pageoptions->version) : '',
'defaultvalue' => '',
'rules' => array(
'required' => true,
......@@ -80,6 +99,7 @@ if ($versionid !== null) {
)
),
'pageinstitution' => array('type' => 'hidden', 'value' => $institution),
'activetab' => array('type' => 'hidden', 'value' => $selectedtab),
'pagetext' => array(
'name' => 'pagetext',
'type' => 'wysiwyg',
......@@ -96,7 +116,7 @@ if ($versionid !== null) {
'class' => 'btn-primary',
'type' => 'submitcancel',
'value' => array(get_string('savechanges', 'admin'), get_string('cancel')),
'goto' => get_config('wwwroot') . 'admin/users/institutionprivacy.php?institution=' . $institution,
'goto' => get_config('wwwroot') . 'admin/users/institutionprivacy.php?institution=' . $institution . '&fs=' . $selectedtab,
),
)
));
......@@ -107,69 +127,67 @@ if ($versionid !== null) {
}
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']));
// Check if the version entered by the user already exists for a specific content type.
if (record_exists('site_content_version', 'institution', $values['pageinstitution'], 'version', $values['version'], 'type', $values['activetab'])) {
$form->set_error('version', get_string('versionalreadyexist', 'admin', get_string($values['activetab'] . 'lowcase', '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->content = $values['pagetext'];
$data->author = $USER->get('id');
$data->institution = $values['pageinstitution'];
$data->ctime = db_format_timestamp(time());
$data->version = $values['version'];
$data->type = 'privacy';
$data->type = $values['activetab'];
try {
insert_record('site_content_version', $data);
$id = insert_record('site_content_version', $data, 'id', true);
if ($id) {
require_once('embeddedimage.php');
$pagetext = EmbeddedImage::prepare_embedded_images($values['pagetext'], 'staticpages', $id);
// If there is an embedded image, update the src so users can have visibility
if ($values['pagetext'] != $pagetext) {
// Update the pagetext with any embedded image info
$updated = new stdClass();
$updated->id = $id;
$updated->content = $pagetext;
update_record('site_content_version', $updated, 'id');
}
// Auto accept the PS/T&C to avoid situation in which
// the admin is asked to agree to the PS/T&C he has just created.
save_user_reply_to_agreement($USER->get('id'), $id, 1);
}
$SESSION->add_ok_msg(get_string('pagesaved', 'admin'));
}
catch (SQLException $e) {
$SESSION->add_ok_msg(get_string('savefailed', 'admin'));
}
redirect(get_config('wwwroot').'admin/users/institutionprivacy.php?institution=' . $values['pageinstitution']);
redirect(get_config('wwwroot').'admin/users/institutionprivacy.php?institution=' . $values['pageinstitution'] . '&fs=' . $values['activetab']);
}
// Site privacy to display in an expandable panel
$siteprivacycontent = get_record_sql("
SELECT s.content, s.ctime
FROM {site_content_version} s
WHERE s.type = 'privacy' AND s.institution = ?
ORDER BY s.id DESC
LIMIT 1", array('mahara'));
$js = <<< EOF
jQuery(function($) {
function reloadUsers() {
window.location.href = '{$wwwroot}admin/users/institutionprivacy.php?institution=' + $('#usertypeselect_institution').val();
}
$(document).ready(function() {
checkActiveTab('$selectedtab');
$('#usertypeselect_institution').on('change', reloadUsers);
});
EOF;
$smarty = smarty();
$smarty = smarty(array('privacy'));
setpageicon($smarty, 'icon-umbrella');
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('href', $href);
$smarty->assign('siteprivacycontent', $siteprivacycontent);
$smarty->assign('lastupdated', get_string('lastupdatedon', 'blocktype.externalfeed', format_date(strtotime($siteprivacycontent->ctime))));
$smarty->assign('sitecontent', $sitecontent);
$smarty->assign('versionid', $versionid);
$smarty->assign('privacies', $privacies);
$smarty->assign('results', $privacies);
$smarty->assign('pageeditform', $form);
$smarty->assign('institution', $institution);
$smarty->assign('latestversion', $privacies ? reset($privacies)->version : 0);
$smarty->assign('latestprivacyid', $privacies ? reset($privacies)->id : 0);
$smarty->assign('version', $versionid && $pageoptions ? $pageoptions->version : '');
$smarty->assign('latestVersions', $latestVersions);
$smarty->assign('institutionselector', $institutionselector);
$smarty->assign('types', implode(' ', $types));
$smarty->assign('link', "admin/users/institutionprivacy.php?institution={$institution}&id=");
$smarty->display('admin/users/institutionprivacy.tpl');
......@@ -931,20 +931,25 @@ function fetch_graph_data(opts) {
function updateUrlParameter(url, param, value) {
var found = false;
var vars = url.split("?");
varparams = vars[1].split("&");
for (var i = 0; i < varparams.length; i++) {
var pair = varparams[i].split("=");
if (pair[0] == param) {
pair[1] = value;
found = true;
if (typeof(vars[1]) !== 'undefined') {
varparams = vars[1].split("&");
for (var i = 0; i < varparams.length; i++) {
var pair = varparams[i].split("=");
if (pair[0] == param) {
pair[1] = value;
found = true;
}
varparams[i] = pair.join("=");
}
vars[1] = varparams.join("&");
url = vars.join("?");
if (!found) {
url = url + '&' + param + '=' + value;
}
varparams[i] = pair.join("=");
}
vars[1] = varparams.join("&");
url = vars.join("?");
if (!found) {
url = url + '&' + param + '=' + value;
else {
url = url + '?' + param + '=' + value;
}
return url;
}
......
......@@ -15,6 +15,9 @@ function checkActiveTab(activeTab) {
}
function showTab(el) {
var newurl = updateUrlParameter(location.href, 'fs', el.replace("#", ""));
history.pushState(null, null, newurl);
var i;
var x = $(".tab");
for (i = 0; i < x.length; i++) {
......@@ -22,4 +25,38 @@ function showTab(el) {
}
$(el).removeClass("js-hidden");
$(el + '-text').removeClass("js-hidden");
// Useful in case an institution has just one type of content
if (typeof types != 'undefined') {
showNoContentAddOne(el);
}
}
function showNoContentAddOne(el) {
$('.nocontent').addClass("js-hidden");
var activetab = el.replace("#", "");
if (types.indexOf(activetab) != -1) {
$('#results').removeClass("js-hidden");
$('#no-results').addClass("js-hidden");
$('#no-' + activetab).addClass("js-hidden");
}
else {
$('#results').addClass("js-hidden");
$('#no-results').removeClass("js-hidden");
$('#no-' + activetab).removeClass("js-hidden");
var url = $('#no-results').find('a').prop('href');
if (url) {
if (getUrlParameter('fs', url)) {
var newurl = updateUrlParameter(url, 'fs', activetab);
$('#no-results').find('a').prop('href', newurl);
}
}
}
}
function reloadUsers() {
var appendfs = '';
if (url = getUrlParameter('fs', location.href)) {
appendfs = '&fs=' + url;
}
window.location.href = config.wwwroot + 'admin/users/institutionprivacy.php?institution=' + $('#usertypeselect_institution').val() + appendfs;
}
......@@ -89,7 +89,9 @@ $string['usedefault'] = 'Use site default';
$string['usedefaultdescription3'] = 'Use the site\'s default text for the selected page type.';
$string['staticpagesdescription'] = 'Edit the content of static pages in Mahara (Home, Terms and Conditions, etc.)';
$string['institutionprivacypagedescription'] = 'Edit the privacy statement for your institution, which is displayed in addition to the site privacy statement. The version you edited last becomes the current privacy statement automatically. You see the current site privacy statement as reference.';
$string['institutiontermspagedescription'] = 'Edit the terms and conditions for your institution, which is displayed in addition to the site terms and conditions. The version you edited last becomes the current terms and conditions automatically. You see the current site terms and conditions as reference.';
$string['noinstitutionprivacy'] = 'There is no privacy statement for this institution yet.';
$string['noinstitutionterms'] = 'There are no terms and conditions for this institution yet.';
$string['menus'] = 'Menus';
$string['menusdescription'] = 'Manage the links and files within the "Links and resources" and footer menus';
$string['sitefiles'] = 'Site files';
......@@ -1344,6 +1346,7 @@ $string['privacylastversion'] = 'Privacy statements must have unique version nam
$string['termsandconditionslastversion'] = 'Terms and conditions must have unique version names of up to 15 characters. The latest version for this privacy statement is "%s".';
$string['versionalreadyexist'] = 'A %s version with the name "%s" already exists.';
$string['siteprivacystatement'] = 'Site privacy statement';
$string['sitetermsstatement'] = 'Site terms and conditions';
$string['addoneversionlink'] = '<a href="%s">Add one</a> if you need it.';
$string['privacyversionfor'] = 'Privacy statement for version "%s" is as follows:';
$string['termsversionfor'] = 'Terms and conditions for version "%s" is as follows:';
......
......@@ -3244,18 +3244,17 @@ function get_latest_privacy_versions($institutions = array(), $ignoreagreevalue
$useragreementsql = $joinsql . " {usr_agreement} u ON s2.current = u.sitecontentid AND u.usr = ? AND u.agreed = 1";
$params = array($USER->get('id'));
}
$latestversions = get_records_sql_array("
SELECT s.id, s.version, s.content, s.ctime, s.institution, " . $userdetails . "
CASE s.institution WHEN 'mahara' THEN 1 ELSE 2 END as type
$select = count($institutions) == 1 ? 's.type, s.id' : 's.id, s.type';
$latestversions = get_records_sql_assoc("
SELECT " . $select . ", s.id, s.version, s.content, s.ctime, s.institution, " . $userdetails . "
CASE s.institution WHEN 'mahara' THEN 1 ELSE 2 END AS site
FROM {site_content_version} s
INNER JOIN (SELECT MAX(id) as current, institution
INNER JOIN (SELECT MAX(id) AS current, institution, type
FROM {site_content_version}
WHERE type = 'privacy'
GROUP BY institution) s2 ON s.institution = s2.institution AND s.id = s2.current
GROUP BY institution, type) s2 ON s.institution = s2.institution AND s.id = s2.current
" . $useragreementsql . "
WHERE s.type = 'privacy' AND s.institution IN (" . join(',',array_map('db_quote',$institutions)) . ")
ORDER BY type", $params);
WHERE s.institution IN (" . join(',',array_map('db_quote',$institutions)) . ")
ORDER BY site", $params);
return $latestversions;
}
......
......@@ -3083,7 +3083,7 @@ function footer_menu($all=false) {
$menu = array(
'termsandconditions' => array(
'url' => $wwwroot . 'terms.php',
'url' => ($USER->is_logged_in() ? $wwwroot . 'account/userprivacy.php' : $wwwroot . 'terms.php'),
'title' => get_string('termsandconditions'),
),
'privacystatement' => array(
......
......@@ -18,9 +18,9 @@ $privacycontent = get_field_sql("
SELECT s.content
FROM {site_content_version} s
WHERE s.institution = ?
AND s.type = 'privacy'
ORDER BY s.version DESC
LIMIT 1", array('mahara'));
$smarty = smarty();
$smarty->assign('page_content', $privacycontent);
$smarty->display('sitepage.tpl');
......@@ -14,6 +14,13 @@ define('PUBLIC', 1);
require('init.php');
define('TITLE', get_string('termsandconditions'));
$termscontent = get_field_sql("
SELECT s.content
FROM {site_content_version} s
WHERE s.institution = ?
AND s.type = 'termsandconditions'
ORDER BY s.version DESC
LIMIT 1", array('mahara'));
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content('termsandconditions'));
$smarty->assign('page_content', $termscontent);
$smarty->display('sitepage.tpl');
{include file="header.tpl"}
<div class="panel panel-default">
<div class="last form-group collapsible-group">
<fieldset class="pieform-fieldset last collapsible">
<legend>
<h4>
<a href="#dropdown" data-toggle="collapse" aria-expanded="false" aria-controls="dropdown" class="collapsed">
{str tag="siteprivacystatement" section="admin"}
<span class="icon icon-chevron-down collapse-indicator right pull-right"> </span>
</a>
</h4>
</legend>
<div class="fieldset-body collapse " id="dropdown">
<span class="text-midtone pull-right">{$lastupdated}</span>
<br>
{$siteprivacycontent->content|safe}
</div>
</fieldset>
<script type="text/javascript">
var types = '{$types}';
</script>
{if $versionid === null || !in_array($versionid, $latestVersions)}
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">
<a href="#privacy" role="tab" data-toggle="tab" aria-expanded="true" onclick="showTab('#privacy')">
{str tag="privacy" section="admin"}
</a>
</li>
<li role="presentation">
<a href="#termsandconditions" role="tab" data-toggle="tab" aria-expanded="false" onclick="showTab('#termsandconditions')">
{str tag="termsandconditions" section="admin"}
</a>
</li>
</ul>
<br>
{/if}
<div id="privacy-text" class="tab">
<div class="panel panel-default" id="privacyst">
<div class="last form-group collapsible-group">
<fieldset class="pieform-fieldset last collapsible">
<legend>
<h4>
<a href="#dropdown-privacyst-{$sitecontent['privacy']->id}" data-toggle="collapse" aria-expanded="false" aria-controls="dropdown" class="collapsed">
{str tag="siteprivacystatement" section="admin"}
<span class="icon icon-chevron-down collapse-indicator right pull-right"> </span>
</a>
</h4>
</legend>
<div class="fieldset-body collapse" id="dropdown-privacyst-{$sitecontent['privacy']->id}">
<span class="text-midtone pull-right">
{str tag="lastupdated" section="admin"} {$sitecontent['privacy']->ctime|date_format:'%d %B %Y %H:%M %p'}
</span>
<br>
{$sitecontent['privacy']->content|safe}
</div>
</fieldset>
</div>
</div>
</div>
{if $versionid !== null && $version == $latestversion}
<div class="lead">{str tag="institutionprivacypagedescription" section="admin"}</div>
</div>
<div id="termsandconditions-text" class="tab">
<div class="panel panel-default" id="terms">
<div class="last form-group collapsible-group">
<fieldset class="pieform-fieldset last collapsible">
<legend>
<h4>
<a href="#dropdown-terms-{$sitecontent['termsandconditions']->id}" data-toggle="collapse" aria-expanded="false" aria-controls="dropdown" class="collapsed">
{str tag="sitetermsstatement" section="admin"}
<span class="icon icon-chevron-down collapse-indicator right pull-right"> </span>
</a>
</h4>
</legend>
<div class="fieldset-body collapse" id="dropdown-terms-{$sitecontent['termsandconditions']->id}">
<span class="text-midtone pull-right">
{str tag="lastupdated" section="admin"} {$sitecontent['termsandconditions']->ctime|date_format:'%d %B %Y %H:%M %p'}
</span>
<br>
{$sitecontent['termsandconditions']->content|safe}
</div>
</fieldset>
</div>
</div>
<div class="lead">{str tag="institutiontermspagedescription" section="admin"}</div>
</div>
{if $versionid !== null && in_array($versionid, $latestVersions)}
<div class="panel panel-default">
<div class="panel-body">
{$pageeditform|safe}
</div>
</div>
{else}
{if $privacies}
<div class="lead">{str tag="institutionprivacypagedescription" section="admin"}</div>
<div class="panel panel-default">
<div class="table-responsive">
<table id="adminstitutionslist" class="fullwidth table table-striped">
<thead>
<tr>
<th>{str tag="version" section="admin"}</th>
<th>{str tag="author" section="admin"}</th>
<th>{str tag="content" section="admin"}</th>
<th>{str tag="creationdate" section="admin"}</th>
<th><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
</tr>
</thead>
<tbody>
{foreach from=$privacies item=result key=key}
<tr>
<td>{$result->version}</td>
<td>{if $result->firstname === NULL}
{str tag=default}
{else}
<a href="{$WWWROOT}user/view.php?id={$result->userid}">
{$result->firstname} {$result->lastname}
</a>
{/if}
</td>
<td>{$result->content|truncate:100:"..."|htmlspecialchars_decode|strip_tags}</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/users/institutionprivacy.php?institution={$institution}&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/users/institutionprivacy.php?institution={$institution}&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>
{if $result->version === $version}
<tr>
<td colspan="5">
<div>{str tag=versionfor section=admin arg1="$result->version"}</div>
{$result->content|clean_html|safe}
</td>
</tr>
<div id="results" class="panel panel-default">
<div class="table-responsive">
<table id="adminstitutionslist" class="fullwidth table table-striped">
<thead>
<tr>
<th>{str tag="version" section="admin"}</th>
<th>{str tag="author" section="admin"}</th>
<th>{str tag="content" section="admin"}</th>
<th>{str tag="creationdate" section="admin"}</th>
<th><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
</tr>
</thead>
<tbody id="privacy" class="tab">
{foreach from=$results item=result}
{if $result->type == 'privacy'}
{include file="admin/site/privacytable.tpl"}
{/if}
{/foreach}
</tbody>
</table>
</div>
<tbody id="termsandconditions" class="tab js-hidden">
{foreach from=$results item=result}
{if $result->type == 'termsandconditions'}
{include file="admin/site/privacytable.tpl"}
{/if}
{/foreach}
</tbody>
</table>
</div>
{else}
<div class="panel panel-default">
<div id="institutionprivacylistcontainer">
<div class="no-results">
{str tag="noinstitutionprivacy" section="admin"}
{str tag="addoneversionlink" section="admin" arg1=$href}
</div>
</div>
<div id="no-results" class="panel panel-default js-hidden">
<div id="institutionprivacylistcontainer">
<div class="no-results ">
<span id="no-privacy" class="nocontent">{str tag="noinstitutionprivacy" section="admin"}</span>
<span id="no-termsandconditions" class="nocontent">{str tag="noinstitutionterms" section="admin"}</span>
{str tag="addoneversionlink" section="admin" arg1=$href}
</div>
</div>
{/if}
</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