Skip to content

Commit

Permalink
config override
Browse files Browse the repository at this point in the history
  • Loading branch information
ridz1208 committed Apr 9, 2018
1 parent b3a5a51 commit 500b89e
Show file tree
Hide file tree
Showing 23 changed files with 1,528 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# loris-demo-project

This repository tracks chnages and oerrides made to the default loris installation in order to prevent users from being able to upload data to a Demo server.
This repository tracks changes and overrides made to the default loris installation
in order to prevent users from being able to upload data to a Demo server.
2 changes: 0 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<!-- MINC TOOLS PATH -->
<MINCToolsPath>/opt/minc/</MINCToolsPath>

<CouchDB>
</CouchDB>

<!-- study variables -->
<study>
Expand Down
73 changes: 73 additions & 0 deletions modules/configuration/ajax/process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* This file is used by the Configuration module to update
* or insert values into the Config table.
*
* PHP version 5
*
* @category Main
* @package Loris
* @author Tara Campbell <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris
*/

ini_set('default_charset', 'utf-8');

require_once "Database.class.inc";
require_once 'NDB_Client.class.inc';
require_once "Utility.class.inc";

$user =& User::singleton();
if (!$user->hasPermission('config')) {
header("HTTP/1.1 403 Forbidden");
exit;
}

$client = new NDB_Client();
$client->makeCommandLine();
$client->initialize();

$DB =& Database::singleton();
foreach ($_POST as $key => $value) {
if (is_numeric($key)) { //update
if ($value == "") {
//############################ DEMO ############################
// $DB->delete('Config', array('ID' => $key));
//############################ DEMO ############################
} else {
//############################ DEMO ############################
// $DB->update(
// 'Config',
// array('Value' => $value),
// array('ID' => $key)
// );
//############################ DEMO ############################
}
} else { //add new or remove
$keySplit = explode("-", $key);
$valueSplit = explode("-", $value);
if ($keySplit[0] == 'add') {
if ($value !== "") {
//############################ DEMO ############################
// $DB->insert(
// 'Config',
// array(
// 'ConfigID' => $keySplit[1],
// 'Value' => $value,
// )
// );
//############################ DEMO ############################
}
} elseif ($valueSplit[0] == 'remove') {
//############################ DEMO ############################
// $DB->delete('Config', array('ID' => $valueSplit[1]));
//############################ DEMO ############################
}
}
}


exit();

?>
59 changes: 59 additions & 0 deletions modules/configuration/ajax/updateProject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* This file is used by the Configuration module to update
* or insert values into the Project table.
*
* PHP version 5
*
* @category Main
* @package Loris
* @author Bruno Da Rosa Miranda <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris
*/

$user =& User::singleton();
if (!$user->hasPermission('config')) {
header("HTTP/1.1 403 Forbidden");
exit;
}

$client = new NDB_Client();
$client->makeCommandLine();
$client->initialize();

$factory = NDB_Factory::singleton();
$db = $factory->database();
$ProjectList = Utility::getProjectList();
$recTarget = empty($_POST['recruitmentTarget'])
? null : $_POST['recruitmentTarget'];
// if a new project is created add the new project.php
// Otherwise, update the existing project.
if ($_POST['ProjectID'] === 'new') {
if (!in_array($_POST['Name'], $ProjectList) && !empty($_POST['Name'])) {
$db->insert(
"Project",
array(
"Name" => $_POST['Name'],
"recruitmentTarget" => $recTarget,
)
);
} else {
header("HTTP/1.1 409 Conflict");
print '{ "error" : "Conflict" }';
exit();
}
} else {
$db->update(
"Project",
array(
"Name" => $_POST['Name'],
"recruitmentTarget" => $recTarget,
),
array("ProjectID" => $_POST['ProjectID'])
);
}
header("HTTP/1.1 200 OK");
print '{ "ok" : "Success" }';
exit();
?>
64 changes: 64 additions & 0 deletions modules/configuration/ajax/updateSubproject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* This file is used by the Configuration module to update
* or insert values into the Config table.
*
* PHP version 5
*
* @category Main
* @package Loris
* @author Tara Campbell <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris
*/

$user =& User::singleton();
if (!$user->hasPermission('config')) {
header("HTTP/1.1 403 Forbidden");
exit;
}

require_once __DIR__ . "/../../../vendor/autoload.php";
$client = new NDB_Client();
$client->makeCommandLine();
$client->initialize();

$factory = NDB_Factory::singleton();
$db = $factory->database();
$SubprojectList = Utility::getSubprojectList();
$recTarget = empty($_POST['RecruitmentTarget'])
? null : $_POST['RecruitmentTarget'];

if ($_POST['subprojectID'] === 'new') {
if (!in_array($_POST['title'], $SubprojectList) && !empty($_POST['title'])) {
$db->insert(
"subproject",
array(
"title" => $_POST['title'],
"useEDC" => $_POST['useEDC'],
"WindowDifference" => $_POST['WindowDifference'],
"RecruitmentTarget" => $recTarget,
)
);
} else {
header("HTTP/1.1 409 Conflict");
print '{ "error" : "Conflict" }';
exit();
}
} else {
$db->update(
"subproject",
array(
"title" => $_POST['title'],
"useEDC" => $_POST['useEDC'],
"WindowDifference" => $_POST['WindowDifference'],
"RecruitmentTarget" => $recTarget,
),
array("SubprojectID" => $_POST['subprojectID'])
);
}
header("HTTP/1.1 200 OK");
print '{ "ok" : "Success" }';
exit();

?>
14 changes: 14 additions & 0 deletions modules/configuration/css/configuration.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.entry {
margin-bottom: 10px;
}

.config-dev-name {
color:grey;
font-size: 11px;
padding-right: 15px;
margin-top: -3px;
}

.submit-area {
margin-top: 30px;
}
9 changes: 9 additions & 0 deletions modules/configuration/help/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Configuration Module

The Configuration Module allows admin-level users to edit customized configuration settings from the front end of LORIS. (Any settings not currently in the Configuration Module are located in the <i>project/config.xml</i> file.)

The Config Settings are organized into sections such as Study, Paths, WWW, etc. An admin-level user can edit individual settings within each of these sections.

Some configuration settings can accept multiple values. For these settings, add/remove additional values using the "Add Field" and “Delete” buttons.

Click “Submit” at the bottom of each section to confirm and save any changes to settings in that section. You will see a brief success message “Submitted”, after changes are saved.\r\n\r\nCare should be taken when editing the fields as there is currently no way to revert changes once saved. To cancel any unsaved changes to configuration settings, click “Reset” to reload the section with the previously-stored values.
2 changes: 2 additions & 0 deletions modules/configuration/js/SubprojectRelations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions modules/configuration/js/SubprojectRelations.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions modules/configuration/js/configuration_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*global document: false, $: false, window: false*/
$(function () {
"use strict";

$('div').tooltip();

var count = 0;
$(".add").click(function (e) {
e.preventDefault();

count = count + 1;

// Field that will be copied
var currentField = $(this).parent().find(".entry:first-child");

var id = $(currentField).parent().attr('id'),
name = 'add-' + id + '-' + count;

// Setup the new form field
var newField = currentField.clone();
newField.find(".form-control").attr('name', name);
$(newField).find(".btn-remove").addClass('remove-new').removeClass('btn-remove');
resetForm(newField);

newField.appendTo($(this).parent().children(":first"));

});

$('body').on('click','.remove-new', function () {
if ($(this).parent().parent().parent().children().length > 1) {
$(this).parent().parent().remove();
}
else {
resetForm($(this).parent().parent());
}
});

$('.btn-remove').click(function(e) {

e.preventDefault();

var id = $(this).attr('name');
var button = this;

$.ajax({
type: 'post',
url: loris.BaseURL + '/configuration/ajax/process.php',
data: {id: id},
success: function () {
if ($(button).parent().parent().parent().children().length > 1) {
$(button).parent().parent().remove();
}
else {
var parent_id = $(button).parent().parent().parent().attr('id');
var name = 'add-' + parent_id;

resetForm($(button).parent().parent());
$(button).parent().parent().children('.form-control').attr('name', name);
$(button).addClass('remove-new').removeClass('btn-remove')
}
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
});
});

// On form submit, process the changes through an AJAX call
$('form').on('submit', function(e) {
e.preventDefault();

var form = $(this).serialize();

//validate(form);

$.ajax({
type: 'post',
url: loris.BaseURL + '/configuration/ajax/process.php',
data: form,
success: function () {
var html = "<label>Submitted</label>";
$(html).hide().appendTo('.submit-area').fadeIn(500).delay(1000).fadeOut(500)
$('input[type="reset"]').attr('disabled','disabled');
},
error: function(xhr, desc, err) {
console.log(xhr);
console.log("Details: " + desc + "\nError:" + err);
}
});
});
});

/*
function validate(form) {
// age
// year
// email - this should be done already
// not same instrument twice
}
*/

function resetForm(form) {
"use strict";

$(form).find('input:text, input:password, input:file, select, textarea').val('');
$(form).find('input:radio, input:checkbox')
.removeAttr('checked').removeAttr('selected');
}
40 changes: 40 additions & 0 deletions modules/configuration/js/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
$(document).ready(function() {
"use strict";
$(".saveproject").click(function(e) {
var form = $(e.currentTarget).closest('form');

var ProjectID = $(form.find(".ProjectID")).val();
var Name = $(form.find(".projectName")).val();
var recruitmentTarget= $(form.find(".projectrecruitmentTarget")).val();
e.preventDefault();
var successClosure = function(i, form) {
return function() {
$(form.find(".saveStatus")).text("Successfully saved").css({ 'color': 'black'}).fadeIn(500).delay(1000).fadeOut(500);
setTimeout(function(){
location.reload();
}, 1000);
}
}

var errorClosure = function(i, form) {
return function() {
$(form.find(".saveStatus")).text("Failed to save, same name already exist!").css({ 'color': 'red'}).fadeIn(500).delay(1000).fadeOut(500);
}
}

jQuery.ajax(
{
"type" : "post",
"url" : loris.BaseURL + "/configuration/ajax/updateProject.php",
"data" : {
"ProjectID" : ProjectID,
"Name" : Name,
"recruitmentTarget" : recruitmentTarget,
},
"success" : successClosure(ProjectID, form),
"error" : errorClosure(ProjectID, form)
}

);
});
});
Loading

0 comments on commit 500b89e

Please sign in to comment.