mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-06-14 05:50:18 +00:00
because that model was too complex to be useful. We also explicitly indicate whether the relationship source or destination are groups separately.
113 lines
4.5 KiB
PHP
113 lines
4.5 KiB
PHP
<?php
|
|
require_once("../inc/always.php");
|
|
require_once("RSCDSSession.php");
|
|
$session->LoginRequired();
|
|
|
|
require_once("interactive-page.php");
|
|
|
|
require_once("DataEntry.php");
|
|
require_once("DataUpdate.php");
|
|
require_once("classBrowser.php");
|
|
$c->stylesheets[] = "$c->base_url/css/browse.css";
|
|
|
|
$confirmation_required = false;
|
|
if ( ($session->AllowedTo("Admin") || $session->AllowedTo("Support")) &&
|
|
!$session->just_logged_in && (isset($_POST['submit']) || isset($_GET['action'])) ) {
|
|
$action = (isset($_POST['submit']) ? $_POST['submit'] : $_GET['action'] );
|
|
dbg_error_log( "relationship_types", " action type is %s.", $action );
|
|
$rt_id = intval($_GET['rt_id']);
|
|
$rt = new DBRecord();
|
|
$rt->Initialise('relationship_type', array( 'rt_id' => $rt_id ) );
|
|
switch( strtolower($action) ) {
|
|
case 'delete':
|
|
if ( $session->CheckConfirmationHash('GET', 'confirm') ) {
|
|
$qry = new PgQuery("DELETE FROM relationship_type WHERE rt_id = $rt_id;");
|
|
if ( $qry->Exec() ) {
|
|
$c->messages[] = i18n("Relationship Type Deleted.");
|
|
}
|
|
else {
|
|
$c->messages[] = i18n("Database Error.");
|
|
if ( preg_match("/violates foreign key constraint/", $qry->errorstring ) ) {
|
|
$c->messages[] = i18n("That relationship type is being used. See ##RelationshipTypeUsed##");
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$c->messages[] = i18n("Please Confirm Deletion");
|
|
$confirmation_required = true;
|
|
$confirmation_hash = $session->BuildConfirmationHash('GET', 'confirm');
|
|
}
|
|
break;
|
|
|
|
case 'add':
|
|
$rt->PostToValues();
|
|
if ( $rt->Write() ) {
|
|
$c->messages[] = i18n("Relationship Type Added.");
|
|
}
|
|
else {
|
|
$c->messages[] = i18n("Database Error.");
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
$c->page_title = translate("Relationship Types");
|
|
$browser = new Browser($c->page_title);
|
|
|
|
$browser->AddColumn( 'rt_id', 'Id' );
|
|
$browser->AddColumn( 'rt_name', translate('Name') );
|
|
$browser->AddColumn( 'rt_fromgroup', translate('From Group?'), '', '', "CASE WHEN rt_fromgroup THEN 'Yes' ELSE 'No' END" );
|
|
$browser->AddColumn( 'rt_togroup', translate('To Group?'), '', '', "CASE WHEN rt_togroup THEN 'Yes' ELSE 'No' END" );
|
|
$browser->AddColumn( 'confers', translate('Rights') );
|
|
$browser->AddColumn( 'action', translate("Action"), "", "", "'<a href=\"$c->base_url/relationship_types.php?action=delete&rt_id=' || rt_id || '\">".translate("Delete")."</a>'" );
|
|
|
|
$browser->SetJoins( 'relationship_type' );
|
|
|
|
if ( isset( $_GET['o']) && isset($_GET['d']) ) {
|
|
$browser->AddOrder( $_GET['o'], $_GET['d'] );
|
|
}
|
|
else
|
|
$browser->AddOrder( 'rt_name', 'A' );
|
|
|
|
$browser->RowFormat( "<tr class=\"r%d\">\n", "</tr>\n", '#even' );
|
|
$browser->DoQuery();
|
|
|
|
$rt_name_field = new EntryField( "text", "rt_name",
|
|
array("title" => translate("Enter the name for this resource type"),
|
|
"size" => "20") );
|
|
|
|
$rt_fromgroup_field = new EntryField( "checkbox", "rt_fromgroup",
|
|
array("title" => translate("Is the source of this relationship a group of access rights?")) );
|
|
|
|
$rt_fromgroup_field = new EntryField( "checkbox", "rt_togroup",
|
|
array("title" => translate("Is the target of this relationship a group of access rights?")) );
|
|
|
|
$confers_field = new EntryField( "text", "confers",
|
|
array("title" => translate("Is this access read ('R') or Read and Write ('RW')?"),
|
|
"size" => "5") );
|
|
|
|
$browser->AddRow( array(
|
|
'rt_id' => 'new',
|
|
'rt_name' => $rt_name_field->Render(),
|
|
'rt_link' => $rt_name_field->Render(),
|
|
'rt_fromgroup' => $rt_fromgroup_field->Render(),
|
|
'rt_togroup' => $rt_togroup_field->Render(),
|
|
'confers' => $confers_field->Render(),
|
|
'action' => '<input type="submit" name="submit" value="'.translate("Add").'" class="fsubmit">'
|
|
) );
|
|
|
|
$active_menu_pattern = "#^$c->base_url/relationship#";
|
|
|
|
include("page-header.php");
|
|
|
|
if ( $confirmation_required ) {
|
|
printf('<p><a href="%s&%s">%s</a></p>', $_SERVER['REQUEST_URI'], $confirmation_hash, translate("Confirm Deletion of the Relationship Type"));
|
|
}
|
|
|
|
printf( '<form method="post" enctype="multipart/form-data" action="%s">', $_SERVER['REQUEST_URI']);
|
|
echo $browser->Render();
|
|
echo "</form>";
|
|
|
|
include("page-footer.php");
|
|
?>
|