#!/usr/bin/env perl
BEGIN {
if
(
$ENV
{ASNMTAP_PERL5LIB} ) {
eval
'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'
; } }
$PROGNAME
=
"displayGroups.pl"
;
my
$prgtext
=
"Display Groups"
;
my
$version
=
do
{
my
@r
= (
q$Revision: 3.002.003$
=~ /\d+/g);
sprintf
"%d."
.
"%03d"
x
$#r
,
@r
}; # must be all on one line or MakeMaker will get confused.
my
$cgi
= new CGI;
my
$pagedir
= (
defined
$cgi
->param(
'pagedir'
)) ?
$cgi
->param(
'pagedir'
) :
'<NIHIL>'
;
$pagedir
=~ s/\+/ /g;
my
$pageset
= (
defined
$cgi
->param(
'pageset'
)) ?
$cgi
->param(
'pageset'
) :
'sadmin'
;
$pageset
=~ s/\+/ /g;
my
$debug
= (
defined
$cgi
->param(
'debug'
)) ?
$cgi
->param(
'debug'
) :
'F'
;
my
$pageNo
= (
defined
$cgi
->param(
'pageNo'
)) ?
$cgi
->param(
'pageNo'
) : 1;
my
$pageOffset
= (
defined
$cgi
->param(
'pageOffset'
)) ?
$cgi
->param(
'pageOffset'
) : 0;
my
$orderBy
= (
defined
$cgi
->param(
'orderBy'
)) ?
$cgi
->param(
'orderBy'
) :
'groupTitle asc'
;
my
$action
= (
defined
$cgi
->param(
'action'
)) ?
$cgi
->param(
'action'
) :
'listView'
;
my
$CcatalogID
= (
defined
$cgi
->param(
'catalogID'
)) ?
$cgi
->param(
'catalogID'
) :
$CATALOGID
;
my
$CcatalogIDreload
= (
defined
$cgi
->param(
'catalogIDreload'
)) ?
$cgi
->param(
'catalogIDreload'
) : 0;
my
$CdisplayGroupID
= (
defined
$cgi
->param(
'displayGroupID'
)) ?
$cgi
->param(
'displayGroupID'
) :
'new'
;
my
$CgroupTitle
= (
defined
$cgi
->param(
'groupTitle'
)) ?
$cgi
->param(
'groupTitle'
) :
''
;
my
$Cactivated
= (
defined
$cgi
->param(
'activated'
)) ?
$cgi
->param(
'activated'
) :
'off'
;
my
$htmlTitle
=
$APPLICATION
;
my
(
$rv
,
$dbh
,
$sth
,
$sql
,
$header
,
$numberRecordsIntoQuery
,
$nextAction
,
$formDisabledAll
,
$formDisabledPrimaryKey
,
$submitButton
);
my
(
$sessionID
,
$iconAdd
,
$iconDelete
,
$iconDetails
,
$iconEdit
,
$iconQuery
,
$iconTable
,
$errorUserAccessControl
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
undef
,
$subTitle
) = user_session_and_access_control (1,
'admin'
,
$cgi
,
$pagedir
,
$pageset
,
$debug
,
$htmlTitle
,
"Display Groups"
,
undef
);
my
$urlAccessParameters
=
"pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&pageNo=$pageNo&pageOffset=$pageOffset&orderBy=$orderBy&action=$action&catalogID=$CcatalogID&catalogIDreload=$CcatalogIDreload&displayGroupID=$CdisplayGroupID&groupTitle=$CgroupTitle&activated=$Cactivated"
;
print
"<pre>pagedir : $pagedir<br>pageset : $pageset<br>debug : $debug<br>CGISESSID : $sessionID<br>page no : $pageNo<br>page offset : $pageOffset<br>order by : $orderBy<br>action : $action<br>catalog ID : $CcatalogID<br>catalog ID reload : $CcatalogIDreload<br>display group ID : $CdisplayGroupID<br>groupTitle : $CgroupTitle<br>activated : $Cactivated<br>URL ... : $urlAccessParameters</pre>"
if
(
$debug
eq
'T'
);
if
(
defined
$sessionID
and !
defined
$errorUserAccessControl
) {
my
(
$catalogIDSelect
,
$matchingDisplayGroups
,
$navigationBar
);
my
$urlWithAccessParameters
=
$ENV
{SCRIPT_NAME} .
"?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&catalogID=$CcatalogID"
;
$rv
= 1;
$dbh
= DBI->
connect
(
"dbi:mysql:$DATABASE:$SERVERNAMEREADWRITE:$SERVERPORTREADWRITE"
,
"$SERVERUSERREADWRITE"
,
"$SERVERPASSREADWRITE"
) or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot connect to the database"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
if
(
$dbh
and
$rv
) {
$formDisabledAll
=
$formDisabledPrimaryKey
=
''
;
if
(
$action
eq
'duplicateView'
or
$action
eq
'insertView'
) {
$formDisabledPrimaryKey
=
'disabled'
;
$htmlTitle
=
"Insert Display Group"
;
$submitButton
=
"Insert"
;
$nextAction
=
"insert"
if
(
$rv
);
$CcatalogID
=
$CATALOGID
if
(
$action
eq
'insertView'
);
}
elsif
(
$action
eq
'insert'
) {
$htmlTitle
=
"Check if Display Group $CdisplayGroupID from $CcatalogID exist before to insert"
;
$sql
=
"select displayGroupID from $SERVERTABLDISPLAYGRPS WHERE catalogID = '$CcatalogID' and displayGroupID='$CdisplayGroupID'"
;
(
$rv
,
$numberRecordsIntoQuery
) = do_action_DBI (
$rv
,
$dbh
,
$sql
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
if
(
$numberRecordsIntoQuery
) {
$htmlTitle
=
"Display Group $CdisplayGroupID from $CcatalogID exist already"
;
$nextAction
=
"insertView"
;
}
else
{
$htmlTitle
=
"Display Group $CdisplayGroupID from $CcatalogID inserted"
;
my
$dummyActivated
= (
$Cactivated
eq
'on'
) ? 1 : 0;
$sql
=
'INSERT INTO '
.
$SERVERTABLDISPLAYGRPS
.
' SET catalogID="'
.
$CcatalogID
.
'", groupTitle="'
.
$CgroupTitle
.
'", activated="'
.
$dummyActivated
.
'"'
;
$dbh
->
do
(
$sql
) or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot dbh->do: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
$nextAction
=
"listView"
if
(
$rv
);
}
}
elsif
(
$action
eq
'deleteView'
) {
$formDisabledPrimaryKey
=
$formDisabledAll
=
'disabled'
;
$htmlTitle
=
"Delete Display Group $CdisplayGroupID from $CcatalogID"
;
$submitButton
=
"Delete"
;
$nextAction
=
"delete"
if
(
$rv
);
}
elsif
(
$action
eq
'delete'
) {
$sql
=
"select uKey, displayDaemon from $SERVERTABLVIEWS where catalogID = '$CcatalogID' and displayGroupID = '$CdisplayGroupID' order by displayDaemon, uKey"
;
(
$rv
,
$matchingDisplayGroups
) = check_record_exist (
$rv
,
$dbh
,
$sql
,
'Views from '
.
$CcatalogID
,
'Unique Key'
,
'Display Daemon'
,
''
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
if
(
$matchingDisplayGroups
eq
''
) {
$htmlTitle
=
"Display Group $CdisplayGroupID from $CcatalogID deleted"
;
$sql
=
'DELETE FROM '
.
$SERVERTABLDISPLAYGRPS
.
' WHERE catalogID="'
.
$CcatalogID
.
'" and displayGroupID="'
.
$CdisplayGroupID
.
'"'
;
$dbh
->
do
(
$sql
) or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot dbh->do: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
}
else
{
$htmlTitle
=
"Display Group $CdisplayGroupID from $CcatalogID not deleted, still used by"
;
}
$nextAction
=
"listView"
if
(
$rv
);
}
elsif
(
$action
eq
'displayView'
) {
$formDisabledPrimaryKey
=
$formDisabledAll
=
'disabled'
;
$htmlTitle
=
"Display Display Group $CdisplayGroupID from $CcatalogID"
;
$nextAction
=
"listView"
if
(
$rv
);
}
elsif
(
$action
eq
'editView'
) {
$formDisabledPrimaryKey
=
'disabled'
;
$htmlTitle
=
"Edit Display Group $CdisplayGroupID from $CcatalogID"
;
$submitButton
=
"Edit"
;
$nextAction
=
"edit"
if
(
$rv
);
}
elsif
(
$action
eq
'edit'
) {
$htmlTitle
=
"Display Group $CdisplayGroupID from $CcatalogID updated"
;
my
$dummyActivated
= (
$Cactivated
eq
'on'
) ? 1 : 0;
$sql
=
'UPDATE '
.
$SERVERTABLDISPLAYGRPS
.
' SET catalogID="'
.
$CcatalogID
.
'", displayGroupID="'
.
$CdisplayGroupID
.
'", groupTitle="'
.
$CgroupTitle
.
'", activated="'
.
$dummyActivated
.
'" WHERE catalogID="'
.
$CcatalogID
.
'" and displayGroupID="'
.
$CdisplayGroupID
.
'"'
;
$dbh
->
do
(
$sql
) or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot dbh->do: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
$nextAction
=
"listView"
if
(
$rv
);
}
elsif
(
$action
eq
'listView'
) {
$htmlTitle
=
"All display groups listed"
;
$nextAction
=
"listView"
;
if
(
$CcatalogIDreload
) {
$pageNo
= 1;
$pageOffset
= 0;
}
$sql
=
"select catalogID, catalogName from $SERVERTABLCATALOG where not catalogID = '$CATALOGID' and activated = '1' order by catalogName asc"
;
(
$rv
,
$catalogIDSelect
,
undef
) = create_combobox_from_DBI (
$rv
,
$dbh
,
$sql
, 1,
''
,
$CcatalogID
,
'catalogID'
,
$CATALOGID
,
'-Parent-'
,
''
,
'onChange="javascript:submitForm();"'
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
$sql
=
"select SQL_NO_CACHE count(displayGroupID) from $SERVERTABLDISPLAYGRPS where catalogID = '$CcatalogID'"
;
(
$rv
,
$numberRecordsIntoQuery
) = do_action_DBI (
$rv
,
$dbh
,
$sql
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
$navigationBar
= record_navigation_bar (
$pageNo
,
$numberRecordsIntoQuery
,
$RECORDSONPAGE
,
$ENV
{SCRIPT_NAME} .
"?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&action=listView&catalogID=$CcatalogID&orderBy=$orderBy"
);
$navigationBar
.= record_navigation_bar_alpha (
$rv
,
$dbh
,
$SERVERTABLDISPLAYGRPS
,
'groupTitle'
,
"catalogID = '$CcatalogID'"
,
$numberRecordsIntoQuery
,
$RECORDSONPAGE
,
$ENV
{SCRIPT_NAME} .
"?pagedir=$pagedir&pageset=$pageset&debug=$debug&CGISESSID=$sessionID&action=listView&catalogID=$CcatalogID"
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
$sql
=
"select catalogID, displayGroupID, groupTitle, activated from $SERVERTABLDISPLAYGRPS where catalogID = '$CcatalogID' order by $orderBy limit $pageOffset, $RECORDSONPAGE"
;
$header
=
"<th><a href=\"$urlWithAccessParameters&action=listView&orderBy=catalogID desc, groupTitle asc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{up}\" ALT=\"Up\" BORDER=0></a> Catalog ID <a href=\"$urlWithAccessParameters&action=listView&orderBy=catalogID asc, groupTitle asc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{down}\" ALT=\"Down\" BORDER=0></a></th><th><a href=\"$urlWithAccessParameters&action=listView&orderBy=groupTitle desc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{up}\" ALT=\"Up\" BORDER=0></a> Group Name <a href=\"$urlWithAccessParameters&action=listView&orderBy=groupTitle asc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{down}\" ALT=\"Down\" BORDER=0></a></th><th><a href=\"$urlWithAccessParameters&action=listView&orderBy=activated desc, groupTitle asc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{up}\" ALT=\"Up\" BORDER=0></a> Activated <a href=\"$urlWithAccessParameters&action=listView&orderBy=activated asc, groupTitle asc\"><IMG SRC=\"$IMAGESURL/$ICONSRECORD{down}\" ALT=\"Down\" BORDER=0></a></th>"
;
(
$rv
,
$matchingDisplayGroups
,
$nextAction
) = record_navigation_table (
$rv
,
$dbh
,
$sql
,
'Display Group'
,
'catalogID|displayGroupID'
,
'0|1'
,
'1'
,
''
,
''
,
$orderBy
,
$header
,
$navigationBar
,
$iconAdd
,
$iconDelete
,
$iconDetails
,
$iconEdit
,
$nextAction
,
$pagedir
,
$pageset
,
$pageNo
,
$pageOffset
,
$htmlTitle
,
$subTitle
,
$sessionID
,
$debug
);
}
if
(
$action
eq
'deleteView'
or
$action
eq
'displayView'
or
$action
eq
'duplicateView'
or
$action
eq
'editView'
) {
$sql
=
"select catalogID, displayGroupID, groupTitle, activated from $SERVERTABLDISPLAYGRPS where catalogID='$CcatalogID' and displayGroupID='$CdisplayGroupID'"
;
$sth
=
$dbh
->prepare(
$sql
) or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot dbh->prepare: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
$sth
->execute() or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot sth->execute: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
)
if
$rv
;
if
(
$rv
) {
(
$CcatalogID
,
$CdisplayGroupID
,
$CgroupTitle
,
$Cactivated
) =
$sth
->fetchrow_array() or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot $sth->fetchrow_array: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
)
if
(
$sth
->rows);
if
(
$action
eq
'duplicateView'
) {
$CcatalogID
=
$CATALOGID
;
$CdisplayGroupID
=
'new'
;
}
$Cactivated
= (
$Cactivated
== 1) ?
'on'
:
'off'
;
$sth
->finish() or
$rv
= error_trap_DBI(
*STDOUT
,
"Cannot sth->finish: $sql"
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
}
}
$dbh
->disconnect or
$rv
= error_trap_DBI(
*STDOUT
,
"Sorry, the database was unable to add your entry."
,
$debug
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
$sessionID
);
}
if
(
$rv
) {
if
(
$action
eq
'duplicateView'
or
$action
eq
'editView'
or
$action
eq
'insertView'
) {
print_header (
*STDOUT
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
'F'
,
''
,
$sessionID
);
print
<<HTML;
<script language="JavaScript1.2" type="text/javascript">
function validateForm() {
if ( document.displayGroups.groupTitle.value == null || document.displayGroups.groupTitle.value == '' ) {
document.displayGroups.groupTitle.focus();
alert('Please enter a group title!');
return false;
}
return true;
}
</script>
<form action="$ENV{SCRIPT_NAME}" method="post" name="displayGroups" onSubmit="return validateForm();">
HTML
}
elsif
(
$action
eq
'listView'
) {
print_header (
*STDOUT
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
'F'
,
''
,
$sessionID
);
print
<<HTML;
<script language="JavaScript1.2" type="text/javascript">
function submitForm() {
document.displayGroups.catalogIDreload.value = 1;
document.displayGroups.submit();
return true;
}
</script>
<form action="$ENV{SCRIPT_NAME}" method="post" name="displayGroups">
HTML
}
elsif
(
$action
eq
'deleteView'
) {
print_header (
*STDOUT
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
'F'
,
''
,
$sessionID
);
print
"<form action=\""
.
$ENV
{SCRIPT_NAME} .
"\" method=\"post\" name=\"displayGroupID\">\n"
;
$pageNo
= 1;
$pageOffset
= 0;
}
else
{
print_header (
*STDOUT
,
$pagedir
,
$pageset
,
$htmlTitle
,
$subTitle
, 3600,
''
,
'F'
,
''
,
$sessionID
);
}
if
(
$action
eq
'deleteView'
or
$action
eq
'duplicateView'
or
$action
eq
'editView'
or
$action
eq
'insertView'
or
$action
eq
'listView'
) {
print
<<HTML;
<input type="hidden" name="pagedir" value="$pagedir">
<input type="hidden" name="pageset" value="$pageset">
<input type="hidden" name="debug" value="$debug">
<input type="hidden" name="CGISESSID" value="$sessionID">
<input type="hidden" name="pageNo" value="$pageNo">
<input type="hidden" name="pageOffset" value="$pageOffset">
<input type="hidden" name="action" value="$nextAction">
<input type="hidden" name="orderBy" value="$orderBy">
<input type="hidden" name="catalogIDreload" value="0">
HTML
}
else
{
print
"<br>\n"
;
}
print
" <input type=\"hidden\" name=\"catalogID\" value=\"$CcatalogID\">\n <input type=\"hidden\" name=\"displayGroupID\" value=\"$CdisplayGroupID\">\n"
if
(
$formDisabledPrimaryKey
ne
''
and
$action
ne
'displayView'
);
print
<<HTML;
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center"><td>
<table border="0" cellspacing="0" cellpadding="0"><tr>
HTML
if
(
$iconAdd
) {
print
<<HTML;
<td class="StatusItem"><a href="$urlWithAccessParameters&pageNo=1&pageOffset=0&action=insertView&orderBy=$orderBy">[Insert display groups]</a></td>
<td class="StatusItem"> </td>
HTML
}
print
<<HTML;
<td class="StatusItem"><a href="$urlWithAccessParameters&pageNo=1&pageOffset=0&action=listView&orderBy=$orderBy">[List all display groups]</a></td>
</tr></table>
</td></tr>
HTML
if
(
$action
eq
'deleteView'
or
$action
eq
'displayView'
or
$action
eq
'duplicateView'
or
$action
eq
'editView'
or
$action
eq
'insertView'
) {
my
$activatedChecked
= (
$Cactivated
eq
'on'
) ?
' checked'
:
''
;
print
<<HTML;
<tr><td> </td></tr>
<tr><td>
<table border="0" cellspacing="0" cellpadding="0">
<tr><td><b>Catalog ID: </b></td><td>
<input type="text" name="catalogID" value="$CcatalogID" size="5" maxlength="5" disabled>
</td></tr>
<tr><td><b>Display Group ID: </b></td><td>
<input type="text" name="displayGroupID" value="$CdisplayGroupID" size="11" maxlength="11" $formDisabledPrimaryKey>
<tr><td><b>Group Name: </b></td><td>
<input type="text" name="groupTitle" value="$CgroupTitle" size="100" maxlength="100" $formDisabledAll>
<tr><td><b>Activated: </b></td><td>
<input type="checkbox" name="activated" $activatedChecked $formDisabledAll>
</td></tr>
HTML
print
" <tr><td> </td><td><br>Please enter all required information before committing the required information. Required fields are marked in bold.</td></tr>\n"
if
(
$action
eq
'duplicateView'
or
$action
eq
'editView'
or
$action
eq
'insertView'
);
print
" <tr align=\"left\"><td align=\"right\"><br><input type=\"submit\" value=\"$submitButton\"></td><td><br><input type=\"reset\" value=\"Reset\"></td></tr>\n"
if
(
$action
ne
'displayView'
);
print
" </table>\n"
;
}
elsif
(
$action
eq
'delete'
or
$action
eq
'edit'
or
$action
eq
'insert'
) {
print
" <tr><td align=\"center\"><br><br><h1>Unique Key: $htmlTitle</h1></td></tr>"
;
print
" <tr><td align=\"center\">$matchingDisplayGroups</td></tr>"
if
(
defined
$matchingDisplayGroups
and
$matchingDisplayGroups
ne
''
);
}
else
{
print
" <tr><td><br><table align=\"center\" border=0 cellpadding=1 cellspacing=1 bgcolor='#333344'><tr><td align=\"left\"><b>Catalog ID: </b></td><td>$catalogIDSelect</td></tr></table></td></tr>"
;
print
" <tr><td align=\"center\"><br>$matchingDisplayGroups</td></tr>"
;
}
print
" </table>\n"
;
if
(
$action
eq
'deleteView'
or
$action
eq
'duplicateView'
or
$action
eq
'editView'
or
$action
eq
'insertView'
or
$action
eq
'listView'
) {
print
"</form>\n"
;
}
else
{
print
"<br>\n"
;
}
}
}
print_legend (
*STDOUT
);
print
'</BODY>'
,
"\n"
,
'</HTML>'
,
"\n"
;