Commit 1d3609fa authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon

Bug 1734182: Add the first privacy statement of an institution

behatnotneeded

Change-Id: I1330f4975460a5fff7313b0af139735caf8b9d99
parent 121c0f10
......@@ -18,6 +18,7 @@ define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'institutionprivacy');
define('MENUITEM', 'manageinstitutions/privacy');
require_once('institution.php');
$versionid = param_integer('id', null);
if (!is_logged_in()) {
throw new AccessDeniedException();
......@@ -45,10 +46,82 @@ $institutionselector = pieform(array(
'institution' => $institutionelement,
)
));
$wwwroot = get_config('wwwroot');
$data = '<div class="no-results">' . get_string('noinstitutionprivacy', 'admin') . '</div>'; //privacy data to show
// 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';
$wwwroot = get_config('wwwroot');
$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.institution = ?
ORDER BY s.id DESC", array($institution));
$form = false;
if ($versionid !== null) {
$form = pieform(array(
'name' => 'editsitepage',
'jsform' => false,
'jssuccesscallback' => 'contentSaved',
'elements' => array(
'version' => array(
'type' => 'text',
'title' => get_string('version', 'admin'),
'description' => '',
'defaultvalue' => '',
'rules' => array(
'required' => true,
'maxlength' => 15
)
),
'pageinstitution' => array('type' => 'hidden', 'value' => $institution),
'pagetext' => array(
'name' => 'pagetext',
'type' => 'wysiwyg',
'rows' => 25,
'cols' => 100,
'title' => get_string('pagetext', 'admin'),
'defaultvalue' => '',
'rules' => array(
'maxlength' => 65536,
'required' => true
)
),
'submit' => array(
'class' => 'btn-primary',
'type' => 'submit',
'value' => get_string('savechanges', 'admin')
),
)
));
}
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/users/institutionprivacy.php?institution=' . $values['pageinstitution']);
}
// Site privacy to display in an expandable panel
$siteprivacycontent = get_record_sql("
......@@ -72,8 +145,11 @@ $smarty = smarty();
setpageicon($smarty, 'icon-umbrella');
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->assign('data', $data);
$smarty->assign('href', $href);
$smarty->assign('siteprivacycontent', $siteprivacycontent);
$smarty->assign('lastupdated', get_string('lastupdatedon', 'blocktype.externalfeed', format_date(strtotime($siteprivacycontent->ctime))));
$smarty->assign('versionid', $versionid);
$smarty->assign('privacies', $privacies);
$smarty->assign('pageeditform', $form);
$smarty->assign('institutionselector', $institutionselector);
$smarty->display('admin/users/institutionprivacy.tpl');
......@@ -182,6 +182,8 @@ if ($institution || $add) {
delete_records('institution_config', 'institution', $values['i']);
delete_records('usr_custom_layout', 'institution', $values['i']);
delete_records('usr_registration', 'institution', $values['i']);
delete_records('site_content_version', 'institution', $values['i']);
delete_records('oauth_server_registry', 'institution', $values['i']);
delete_records('institution', 'name', $values['i']);
db_commit();
......
......@@ -1332,3 +1332,4 @@ $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.';
$string['siteprivacystatement'] = 'Site privacy statement';
$string['addoneversionlink'] = '<a href="%s">Add one</a> if you need it.';
......@@ -19,9 +19,56 @@
</fieldset>
</div>
</div>
<div class="panel panel-default">
<div id="institutionprivacylistcontainer">
{$data|safe}
{if $versionid !== null}
<div class="panel panel-default">
<div class="panel-body">
{$pageeditform|safe}
</div>
</div>
</div>
{else}
{if $privacies}
<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"></td>
</tr>
{/foreach}
</tbody>
</table>
</div>
</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>
{/if}
{/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