Skip to content

Commit

Permalink
implementing the feature of changing the profiles order
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Wolniewicz committed Nov 25, 2024
1 parent 0787a84 commit ed2e50e
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/IdP.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function __construct(int $instId)
*/
public function listProfiles(bool $activeOnly = FALSE)
{
$query = "SELECT profile_id FROM profile WHERE inst_id = $this->identifier" . ($activeOnly ? " AND showtime = 1" : "");
$query = "SELECT profile_id FROM profile WHERE inst_id = $this->identifier" . ($activeOnly ? " AND showtime = 1" : "")." ORDER BY preference";
$allProfiles = $this->databaseHandle->exec($query);
$returnarray = [];
// SELECT -> resource, not boolean
Expand Down
28 changes: 28 additions & 0 deletions schema/2_1_2-2_1_2_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* *****************************************************************************
* Contributions to this work were made on behalf of the GÉANT project, a
* project that has received funding from the European Union’s Framework
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
* Horizon 2020 research and innovation programme under Grant Agreements No.
* 691567 (GN4-1) and No. 731122 (GN4-2) and from the Horizon Europe programme
* under Grant Agreement No: 101100680 (GN5-1).
* On behalf of the aforementioned projects, GEANT Association is the sole owner
* of the copyright in all material which was developed by a member of the GÉANT
* project. GÉANT Vereniging (Association) is registered with the Chamber of
* Commerce in Amsterdam with registration number 40535155 and operates in the
* UK as a branch of GÉANT Vereniging.
*
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands.
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
*
* License: see the web/copyright.inc.php file in the file structure or
* <base_url>/copyright.php after deploying the software
*/

/**
* @author Tomasz Wolniewicz <[email protected]>
* Created: 20 Nov 2024
*/


ALTER TABLE profile ADD COLUMN `preference` int DEFAULT '1000';
1 change: 1 addition & 0 deletions schema/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ CREATE TABLE `profile` (
`sufficient_config` tinyint(1) NULL DEFAULT NULL,
`openroaming` int(2) NOT NULL DEFAULT 4,
`last_change` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`preference` int DEFAULT '1000',
PRIMARY KEY (`profile_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Expand Down
139 changes: 139 additions & 0 deletions web/admin/sort_profiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php
/*
* *****************************************************************************
* Contributions to this work were made on behalf of the GÉANT project, a
* project that has received funding from the European Union’s Framework
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
* Horizon 2020 research and innovation programme under Grant Agreements No.
* 691567 (GN4-1) and No. 731122 (GN4-2).
* On behalf of the aforementioned projects, GEANT Association is the sole owner
* of the copyright in all material which was developed by a member of the GÉANT
* project. GÉANT Vereniging (Association) is registered with the Chamber of
* Commerce in Amsterdam with registration number 40535155 and operates in the
* UK as a branch of GÉANT Vereniging.
*
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands.
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
*
* License: see the web/copyright.inc.php file in the file structure or
* <base_url>/copyright.php after deploying the software
*/

/**
* This page is used to change the sorting order of IdP profiles by its administrator.
*
* @author Tomasz Wolniewicz <[email protected]>
*/
?>

<?php
require_once dirname(dirname(dirname(__FILE__))) . "/config/_config.php";

$deco = new \web\lib\admin\PageDecoration();
$validator = new \web\lib\common\InputValidation();
$auth = new \web\lib\admin\Authentication();
$uiElements = new \web\lib\admin\UIElements();
$auth->authenticate();
[$my_inst, $editMode] = $validator->existingIdPInt($_GET['inst_id'], $_SESSION['user']);

echo $deco->defaultPagePrelude(sprintf(_("%s: Profile ordering for '%s'"), \config\Master::APPEARANCE['productname'], $my_inst->name));
require_once "inc/click_button_js.php";

?>
<style>
span.hidden {
display: none;
}
#cat_profiiles {
background: green;
padding: 5px;
}
li.hidden {
background-color: lightblue;
}

</style>
<!-- JQuery -->
<link rel="stylesheet" type="text/css" href="../external/jquery/jquery-ui.css" />
<script type="text/javascript" src="../external/jquery/jquery-migrate.js"></script>
<script type="text/javascript" src="../external/jquery/jquery-ui.js"></script>
<!-- EAP sorting code -->
<script>

$(function () {
$("#sortable").sortable({
connectWith: "ol.eapmethods",
tolerance: 'pointer',
stop: function (event, ui) {
$(".profiles").removeAttr('value');
$("#sortable").children().each(function (index) {
var v = $(this).children().first().html();
$("#profile-" + v).val(index+1);
});
}
}).disableSelection();
});

</script>

<link rel='stylesheet' type='text/css' href='css/eapSorter.css.php' />
<!-- EAP sorting code end -->

<?php
echo "<body>";
echo $deco->productheader("ADMIN-IDP");
if ($editMode !== 'fullaccess') {
echo "<h2>"._("No write access to this IdP");
echo $deco->footer();
exit;
}

$profiles_for_this_idp = $my_inst->listProfiles();

?>
<h1><?php printf(_("Change the order of profiles for '%s'"), $my_inst->name); ?></h1>

<div class="profilebox">
<?php echo _("Pofiles with orange background are not visible in the public download interface"); ?><p>
<table style="border:none">
<caption><?php echo _("EAP type support"); ?></caption>
<tr>
<td id="cat_profiiles">
<ol id="sortable" class="eapmethods">
<?php
$D = [];
$prio = 1;
foreach ($profiles_for_this_idp as $profile) {
if ($profile->getAttributes("profile:production")[0]['value'] !== 'on') {
$li_class = 'style="background-color:orange"';
} else {
$li_class = '';
}
print '<li '.$li_class.'><span class="hidden">'.$profile->identifier.'</span>'.$profile->name."</li>\n";
$D[$profile->identifier] = $prio;
$prio++;
}
?>
</ol>
</td>
<td rowspan=3 style="text-align:center; width:12em; padding:1em">
<?php echo _('Use "drag &amp; drop" to arrange the profiles order.'); ?>
</td>
</tr>
</table>
</div>
<form action="sort_profiles_result.php?inst_id=<?php echo $my_inst->identifier?>" method='post' accept-charset='UTF-8'>
<button type=submit">Save profiles order</button>
<button type="button" class="delete" id="cancel" name="cancel" value="abort" onclick="javascript:window.location = 'overview_org.php?inst_id=<?php echo $my_inst->identifier?>'"><?php echo _("Cancel") ?></button>
<?php
foreach ($D as $id=>$priority) {
echo "<input type='hidden' class='profiles' id='profile-$id' name='profile-$id' value='$priority'>";
}
?>
</form>
<?php echo $deco->footer();





62 changes: 62 additions & 0 deletions web/admin/sort_profiles_result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/*
* *****************************************************************************
* Contributions to this work were made on behalf of the GÉANT project, a
* project that has received funding from the European Union’s Framework
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
* Horizon 2020 research and innovation programme under Grant Agreements No.
* 691567 (GN4-1) and No. 731122 (GN4-2).
* On behalf of the aforementioned projects, GEANT Association is the sole owner
* of the copyright in all material which was developed by a member of the GÉANT
* project. GÉANT Vereniging (Association) is registered with the Chamber of
* Commerce in Amsterdam with registration number 40535155 and operates in the
* UK as a branch of GÉANT Vereniging.
*
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands.
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
*
* License: see the web/copyright.inc.php file in the file structure or
* <base_url>/copyright.php after deploying the software
*/

/**
* This page is used to save changes of the sorting order of IdP profiles by its administrator.
*
* @author Tomasz Wolniewicz <[email protected]>
*/
?>

<?php
require_once dirname(dirname(dirname(__FILE__))) . "/config/_config.php";

$deco = new \web\lib\admin\PageDecoration();
$validator = new \web\lib\common\InputValidation();
$auth = new \web\lib\admin\Authentication();
$auth->authenticate();
[$my_inst, $editMode] = $validator->existingIdPInt($_GET['inst_id'], $_SESSION['user']);

echo $deco->defaultPagePrelude(sprintf(_("%s: Profile sorting"), \config\Master::APPEARANCE['productname']));
if ($editMode !== 'fullaccess') {
echo "<h2>"._("No write access to this IdP");
echo $deco->footer();
exit;
}
$handle = \core\DBConnection::handle("INST");

echo "<body>";
echo $deco->productheader("ADMIN-IDP");
printf("<h1>"._("Saved new profiles order for '%s'")."</h1>", $my_inst->name);
$q = "UPDATE profile SET preference = ? WHERE profile_id = ?";
foreach ($_POST as $key => $value) {
if (!preg_match('/^profile-(\d+)$/', $key, $matches)) {
continue;
}
$profileId = $matches[1];
$handle->exec($q, 'ii', $value, $profileId);
}


?>

<button type="button" id="cancel" name="cancel" value="abort" onclick="javascript:window.location = 'overview_org.php?inst_id=<?php echo $my_inst->identifier?>'"><?php echo _("Continue to dashboard"); ?></button>
<?php echo $deco->footer();

0 comments on commit ed2e50e

Please sign in to comment.