Files

478 lines
18 KiB
Perl
Executable File

#!/usr/sbin/perl
#**************************************************************************
#* *
#* Copyright (c) 1996 Silicon Graphics, Inc. *
#* All Rights Reserved *
#* *
#* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
#* *
#* The copyright notice above does not evidence any actual of intended *
#* publication of such source code, and is an unpublished work by Silicon *
#* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
#* the property of Silicon Graphics, Inc. Any use, duplication or *
#* disclosure not specifically authorized by Silicon Graphics is strictly *
#* prohibited. *
#* *
#* RESTRICTED RIGHTS LEGEND: *
#* *
#* Use, duplication or disclosure by the Government is subject to *
#* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
#* Technical Data and Computer Software clause at DFARS 52.227-7013, *
#* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
#* Supplement. Unpublished - rights reserved under the Copyright Laws of *
#* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
#* Shoreline Blvd., Mountain View, CA 94039-7311 *
#**************************************************************************
# DEMO_add.pl
#
# Routines to add or edit demos
1; # return true
# INPUT: %in {global}
# Based on the CGI input, we can take the appropriate actions and generate
# the appropriate pages.
sub Generate_Maint_Add_Page {
if ($in{$CGI_ADD_NAME_SWITCH}) {
if ($in{$CGI_ADD_WRITE_SWITCH}) {
&Generate_Example_Page;
} else {
&Generate_Edit_Info_Page("$in{$CGI_ADD_NAME_SWITCH}","$in{$CGI_TREE_SWITCH}");
}
} else {
# Print the default top level page
&Print_Add_Front_Page;
}
}
# INPUT: %in
# Given the user input to the add/edit forms page, take the following actions
# - Create header image with the demos title on top
# - Write a new .index file
# - Update the tables in the background
# - Notify user that we are updating tables
# - Print a message to the error log
# - Finally, display what the page will look like
sub Generate_Example_Page {
$tree_path = &Tree_Path_From_Name("$in{$CGI_TREE_SWITCH}");
&Create_Header_Image;
&Write_Index_File;
&Update_Tables;
# &Notify_User;
&Print_Error("$ERROR_INFO","Added $in{$CGI_ADD_NAME_SWITCH} to interface.","$STATUS_MINOR");
&Display_Example_Page;
}
# INPUT: %in
# After add/editing a page, display it by calling a routine from DEMO_main.pl
sub Display_Example_Page {
&Print_Demo_Info_Page($in{$CGI_ADD_NAME_SWITCH}, $in{$CGI_TREE_SWITCH}, 1);
}
# INPUT:
# Notify the user about updating tables by calling routine from DEMO_pop.pl
sub Notify_User {
&Pop("Updating Demo Information", "$FILE_UPDATE_NOTIFY") if ($NOTIFY_USER);
}
# INPUT: %in
# Write user input data to the .index file of a demo
sub Write_Index_File {
open(INDEX, ">$tree_path/$in{$CGI_ADD_NAME_SWITCH}/$DEMOSRC_INDEX");
select(INDEX);
print "MARKETS:\n";
print "$in{'MARKETS'}\n";
print "END_MARKETS\n";
print "\n";
print "FEATURES:\n";
print "$in{'FEATURES'}\n";
print "END_FEATURES\n";
print "\n";
print "HARDWARE:\n";
print "$in{'HARDWARE'}\n";
print "END_HARDWARE\n";
print "\n";
print "OTHER_INFORMATION:\n";
print "$in{'OTHER_INFORMATION'}\n";
print "END_OTHER_INFORMATION\n";
print "\n";
print "TITLE:\n";
print "$in{'TITLE'}\n";
print "END_TITLE\n";
print "\n";
print "AUTHOR:\n";
print "$in{'AUTHOR'}\n";
print "END_AUTHOR\n";
print "\n";
print "DESCRIPTION:\n";
print "$in{'DESCRIPTION'}\n";
print "END_DESCRIPTION\n";
print "\n";
print "BRIEF_INSTRUCTIONS:\n";
print "$in{'BRIEF_INSTRUCTIONS'}\n";
print "END_BRIEF_INSTRUCTIONS\n";
print "\n";
print "DETAILED_INSTRUCTIONS:\n";
print "$in{'DETAILED_INSTRUCTIONS'}\n";
print "END_DETAILED_INSTRUCTIONS\n";
print "\n";
print "SYSTEM_REQS:\n";
print "$in{'SYSTEM_REQS'}\n";
print "END_SYSTEM_REQS\n";
print "\n";
print "END_HTMLUI\n";
print "# Information in this section is either not used by\n";
print "# the HTML interface or is misformatted and can't\n";
print "# be read by the HTML interface.\n";
print "#\n";
print "\n";
select(STDOUT);
close(INDEX);
}
# INPUT: %in
# Create a header image using the appropriate text string using the "imgcomp"
# script by Paul Harberli
sub Create_Header_Image {
# Make imgcomp script
open(IMGSCRIPT, ">$FILE_IMGCOMP_TMP");
print IMGSCRIPT "GLOBALSCALE 1.0\n";
print IMGSCRIPT "IMGSIZE 617 134\n";
print IMGSCRIPT "SETCOLOR 253 186 53\n";
print IMGSCRIPT "CLEARSCREEN\n";
print IMGSCRIPT "SETFONT Times-Roman 33\n";
print IMGSCRIPT "SHOWIMAGE $FILE_HEADER_BACK 0 0\n";
print IMGSCRIPT "SETCOLOR 253 186 53\n";
print IMGSCRIPT "CHARPOS 600 80\n";
print IMGSCRIPT "LEFTTEXT $in{'TITLE'}\n";
close(IMGSCRIPT);
# Set environment vaiable
$ENV{'IL_READ_THREADS'} = 0;
# Generate the header image
`$CMD_IMGCOMP $FILE_IMGCOMP_TMP $FILE_HEADER_TMP.$EXT_RGB 1$CMD_NULLIFY 2>&1 `;
`$CMD_IMGCOPY $CMD_IMGCOPY_FLAGS $FILE_HEADER_TMP.$EXT_RGB $FILE_HEADER_TMP.$EXT_JPG 1$CMD_NULLIFY 2>&1 `;
# Move the image
`$CMD_MV $FILE_HEADER_TMP.$EXT_JPG $tree_path/$in{$CGI_ADD_NAME_SWITCH}/$DEMOSRC_HEADER 2>&1 `;
# Remove the comp file
`$CMD_RM $FILE_IMGCOMP_TMP`;
}
# INPUT: ($demo_name, $tree_name)
# Manage the editing of an already existing demo. This includes adding default
# images, checking permissions and setup, and creating info forms.
sub Generate_Edit_Info_Page {
&Add_Thumbnail_Image("$_[0]", "$_[1]") if ("$in{$CGI_ADD_THUMBNAIL_SWITCH}" eq "$CGI_MAINT_TRUE_FLAG");
&Add_Pic_Image("$_[0]", "$_[1]") if ("$in{$CGI_ADD_PIC_SWITCH}" eq "$CGI_MAINT_TRUE_FLAG");
if (!&Demo_Dir_Exists("$_[0]", "$_[1]")) {
&Print_No_Dir_Error_Page;
} elsif (!&Dir_Setup_Legal("$_[0]", "$_[1]")) {
&Print_Not_Legal_Error_Page;
} else {
&Print_Edit_Info_Page;
}
}
# INPUT: %in
# Create the edit info forms, the last step in editing a demo.
sub Print_Edit_Info_Page {
local($path);
$path = &Tree_Path_From_Name("$in{$CGI_TREE_SWITCH}");
&Parse_Demo_Info("$path/$in{$CGI_ADD_NAME_SWITCH}/$DEMOSRC_INDEX") if ($indexfound);
&Print_Maint_Top("Edit Demo: Customize Demo Information", "$IMGSRC_HEADER_EDITINFO");
print "<font size=+3 color=red>I</font><font size=+1 color=red>NFORMATION</font><p>\n";
print "<table width=0 border=0 cellpadding=5 cellspacing=0 bgcolor=$INPUT_BGCOLOR>\n<tr><td>";
print "<form method=POST target=$FRAME_MAIN action=\"$WWW_SCRIPT\">\n";
print "<tr><td align=right bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>DEMO NAME:</font></td> \n";
print "<td bgcolor=\"$INPUT_BGCOLOR\">$in{$CGI_ADD_NAME_SWITCH}</td></tr>\n";
print "<tr><td align=right bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>DEMO PATH:</font></td> \n";
print "<td bgcolor=\"$INPUT_BGCOLOR\">$path/$in{$CGI_ADD_NAME_SWITCH}/</td></tr>\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$CGI_MAINT_ADD_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<input type=hidden name=\"$CGI_ADD_WRITE_SWITCH\" value=\"$CGI_MAINT_TRUE_FLAG\">\n";
print "<input type=hidden name=\"$CGI_ADD_NAME_SWITCH\" value=\"$in{$CGI_ADD_NAME_SWITCH}\" size=50>\n";
print "<input type=hidden name=\"$CGI_TREE_SWITCH\" value=\"$in{$CGI_TREE_SWITCH}\" size=50>\n";
print "<tr><td align=right bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>TITLE:</font></td>\n";
print "<td bgcolor=\"$INPUT_BGCOLOR\"><input name=\"TITLE\" value=\"$demo_info{'TITLE'}\"></td></tr>\n";
print "<tr><td align=right bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>AUTHOR:</font></td>\n";
print "<td bgcolor=\"$INPUT_BGCOLOR\"><input name=\"AUTHOR\" value=\"$demo_info{'AUTHOR'}\"></td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>DESCRIPTION:</font><br>\n";
print "<textarea wrap=virtual name=\"DESCRIPTION\" rows=10 cols=60>$demo_info{'DESCRIPTION'}</textarea></td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>BRIEF INSTRUCTIONS:</font><br>\n";
print "<textarea wrap=virtual name=\"BRIEF_INSTRUCTIONS\" rows=15 cols=60>$demo_info{'BRIEF_INSTRUCTIONS'}</textarea></td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>DETAILED INSTRUCTIONS:</font><br>\n";
print "<textarea wrap=virtual name=\"DETAILED_INSTRUCTIONS\" rows=20 cols=60>$demo_info{'DETAILED_INSTRUCTIONS'}</textarea></td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>OTHER INFORMATION:</font><br>\n";
print "<textarea wrap=virtual name=\"OTHER_INFORMATION\" rows=10 cols=60>$demo_info{'OTHER_INFORMATION'}</textarea></td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"$INPUT_BGCOLOR\"><font color=blue>SYSTEM REQUIREMENTS:</font><br>\n";
print "<textarea wrap=virtual name=\"SYSTEM_REQS\" rows=5 cols=60>$demo_info{'SYSTEM_REQS'}</textarea></td></tr>\n";
print "</table>\n";
print "<table width=100% border=0 cellpadding=5 cellspacing=0 bgcolor=$INPUT_BGCOLOR>\n";
print "<tr>\n";
print "<td bgcolor=\"$INPUT_BGCOLOR\" align=center>\n";
print "<font color=blue>INDUSTRIES:</font><br>\n";
&Print_Category_Chooser("MARKETS", @markets_categories);
print "</td><td bgcolor=\"$INPUT_BGCOLOR\" align=center>\n<p>\n";
print "<font color=blue>FEATURES:</font><br>\n";
&Print_Category_Chooser("FEATURES", @features_categories);
print "</td>\n</tr>\n</table>\n<center>\n";
print "<table border=0 cellpadding=5 cellspacing=0 bgcolor=$INPUT_BGCOLOR>\n<tr>\n<td align=center bgcolor=\"$INPUT_BGCOLOR\">\n";
print "<font color=blue>HARDWARE:</font><br>\n";
&Print_Category_Chooser("HARDWARE", @hardware_categories);
print "</center>\n<p>\n";
print "<font color=blue>\n";
print "<center><input type=reset value=\"Undo Changes\">\n";
print "<input type=submit value=\"Update\"></center><br>\n";
print "</td>\n</tr>\n</table>\n";
print "</font>\n";
print "</form>\n";
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
# INPUT: ($category)
# Create the category chooser as part of the edit info page
sub Print_Category_Chooser {
local($category, $bullet, @links);
$category = shift(@_);
@links = split(/\n/, $demo_info{$category});
print "<select name=\"$category\" multiple size=8>\n";
for $bullet (@_) {
print "<option value=\"$bullet\" ";
print "selected" if grep(/^$bullet$/i, @links);
print ">\U$bullet\E\n";
}
print "</select>\n";
}
# INPUT: ($demo_name, $tree_name)
# Add a thumbnail image to a demo directory
sub Add_Thumbnail_Image {
local($path);
$path = &Tree_Path_From_Name("$_[1]");
&Copy_File("$FILE_DEFAULT_THUMB", "$path/$_[0]/$DEMOSRC_THUMBNAIL");
}
# INPUT: ($demo_name, $tree_name)
# Add a demo image to a demo directory
sub Add_Pic_Image {
local($path);
$path = &Tree_Path_From_Name("$_[1]");
&Copy_File("$FILE_DEFAULT_DEMO", "$path/$_[0]/$DEMOSRC_DEMOPIC");
}
# INPUT: ($location1, $location2)
# Copy a file from one location to another
sub Copy_File {
`cp $_[0] $_[1]`;
}
# INPUT: ($demo_name, $tree_name)
# Test the permissions and setup of a particular demo directory
sub Dir_Setup_Legal {
local($path);
$path = &Tree_Path_From_Name("$_[1]");
&Legal_Properties("$path/$_[0]");
if (!$indexfound) {
$indexVal = 1;
} else {
$indexVal = $indexstate;
}
if (!$headerfound) {
$headerVal = 1;
} else {
$headerVal = $headerstate;
}
return( $directorystate && $demostate && $thumbstate && $headerVal && $picstate && $indexVal );
}
# INPUT: %in
# Print out an error page if the directory setup is not legal
sub Print_Not_Legal_Error_Page {
local($path);
$path = &Tree_Path_From_Name("$in{$CGI_TREE_SWITCH}");
&Print_Maint_Top("Error: Necessary Files/Permissions Not Found", "$IMGSRC_HEADER_ADDEDIT");
print "<font size=+3 color=red>I</font><font size=+1 color=red>NFORMATION</font><p>\n";
print "The directory <br>\n";
print "<center><i>$path/<b>$in{$CGI_ADD_NAME_SWITCH}</b></i></center>\n<br>\n";
print "did not contain the necessary files and/or permissions\n";
print "<br>\n<p>\n<hr noshade>\n<br>\n";
&Print_Not_Legal_Error_List;
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
# INPUT: %in
# Print out the body of the error page, with pop-up links
sub Print_Not_Legal_Error_List {
print "<font size=+3 color=red>E</font><font size=+1 color=red>RRORS</font><p>\n";
print "<form target=$FRAME_MAIN method=GET action=\"$WWW_SCRIPT\">\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$CGI_MAINT_ADD_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<input type=hidden name=\"$CGI_ADD_NAME_SWITCH\" value=\"$in{$CGI_ADD_NAME_SWITCH}\">\n";
print "<input type=hidden name=\"$CGI_TREE_SWITCH\" value=\"$in{$CGI_TREE_SWITCH}\">\n";
&Print_Directorystate_Error if (! $directorystate);
&Print_Indexstate_Error if (! $indexVal);
&Print_Thumbfound_Error if (! $thumbfound);
&Print_Thumbstate_Error if ( (!$thumbstate) && ($thumbfound) );
&Print_Picfound_Error if (! $picfound);
&Print_Picstate_Error if ( (!$picstate) && ($picfound) );
&Print_Demofound_Error if (! $demofound);
&Print_Demostate_Error if ( (!$demostate) && ($demofound) );
&Print_Headerstate_Error if ( !$headerVal);
print "<center>\n";
print "<font size=2 color=red>\n";
print "<input type=submit value=\"Try Again\">";
print "</font>\n";
print "</form>\n";
print "</center>\n";
}
# INPUT: ($demo_name, $tree_name)
# Test to see if a demo dir exists
sub Demo_Dir_Exists {
local($path);
$path = &Tree_Path_From_Name("$_[1]");
return(chdir("$path/$_[0]"));
}
# INPUT: %in
# Print error page when a directory does not exist
sub Print_No_Dir_Error_Page {
&Print_Maint_Top("Error: Directory Not Found", "$IMGSRC_HEADER_ADDEDIT");
print "<font size=+3 color=red>I</font><font size=+1 color=red>NFORMATION</font><p>\n";
print "The directory <br>\n";
$path = &Tree_Path_From_Name("$in{$CGI_TREE_SWITCH}");
print "<center><i>$path/<b>$in{$CGI_ADD_NAME_SWITCH}</b></i></center>\n<br>\n";
print "was not found. Please specify a new demo. \n";
# print "<br>\n<p>\n<hr noshade>\n<br>\n";
# &Print_Add_Form;
print "<br>\n<p>\n<hr noshade>\n<br>\n";
&Print_Edit_Form;
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
# INPUT:
# Print out the from page for adding a demo
sub Print_Add_Front_Page {
&Print_Maint_Top("Add a Demo", "$IMGSRC_HEADER_ADDEDIT");
print "<font size=+3 color=red>I</font><font size=+1 color=red>NSTRUCTIONS</font><p>\n";
print "<li>Select a <i>demo list</i> and enter the demo name.<br>\n";
print "<li>The named demo must reside in the same directory as the rest of the demos in the tree that it is being added to.<br>\n";
print "<li>If you wish to add a group of new of demos, please use the \n";
print "&quot;Add a Group of Demos&quot; utility.\n";
print "<br><p>\n<hr noshade>\n";
&Print_Add_Form;
# print "<br>\n<p>\n<hr noshade>\n";
# &Print_Edit_Form;
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
# INPUT:
# Print out the from page for adding a demo
sub Print_Edit_Front_Page {
&Print_Maint_Top("Edit Demo", "$IMGSRC_HEADER_EDITINFO");
print "<font size=+3 color=red>I</font><font size=+1 color=red>NSTRUCTIONS</font><p>\n";
print "Select a demo name and edit that demo's detailed information. \n";
# print "<p>\n<hr noshade>\n";
# &Print_Add_Form;
print "<br>\n<p>\n<hr noshade>\n";
&Print_Edit_Form;
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
# INPUT:
# Print out the edit a demo chooser form
sub Print_Edit_Form {
local($curr_col, $demo, $tree);
print "<font size=+3 color=red>E</font><font size=+1 color=red>DIT</font><p>\n";
for $tree ( &List_Tree_Names ) {
print "<p><b>$tree</b><p>\n";
print "<font size=2>\n";
print "<table>\n";
$curr_col = 1;
for $demo (&Demos_In_Tree("$tree")) {
if (&Is_Basically_Legal(&Tree_Path_From_Name("$tree"), "$demo") ) {
print "<tr>\n" if ($curr_col == 1);
print "<td>\n";
print "<a href=\"$WWW_SCRIPT?$CGI_SWITCH=$CGI_MAINT_FLAG&";
print "$CGI_SUB_SWITCH=$CGI_MAINT_ADD_FLAG&$CGI_MAINT_OUTSIDE_SWITCH=$CGI_MAINT_FALSE_FLAG&";
print "$CGI_TREE_SWITCH=";
print &HTTP_Syntax("$tree");
print "&$CGI_ADD_NAME_SWITCH=";
print &HTTP_Syntax($demo);
print "\">$demo</a>\n";
print "</td>\n";
print "</tr>\n" if ($curr_col == $ADD_COLUMNS);
$curr_col = 0 if ($curr_col == $ADD_COLUMNS);
++$curr_col;
}
}
print "</table>\n";
print "</font>\n";
}
}
# INPUT:
# Print out the add a demo form
sub Print_Add_Form {
local($tree);
print "<font size=+3 color=red>A</font><font size=+1 color=red>DD</font><p>\n";
print "<form target=$FRAME_MAIN method=GET action=\"$WWW_SCRIPT\">\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$CGI_MAINT_ADD_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<table bgcolor=$INPUT_BGCOLOR>\n<tr>\n<td>\n";
@tree_names = &List_Tree_Names;
if ($#tree_names >= 1) {
print "<font color=blue>List: ";
print "<select name=\"$CGI_TREE_SWITCH\">\n";
for (@tree_names) {
print "<option value=\"$_\"";
print " selected" if ("$in{$CGI_TREE_SWITCH}" eq "$_");
print ">$_\n";
}
print "</select>\n";
print "</font>\n";
} else {
print "<input type=hidden name=\"$CGI_TREE_SWITCH\" value=\"$tree_names[0]\">\n";
}
print "<font color=blue>\n";
print "</td></tr><tr><td>Name: <input name=\"$CGI_ADD_NAME_SWITCH\" value=\"$in{$CGI_ADD_NAME_SWITCH}\" size=15></td></tr>\n";
print "<tr align=center><td><input type=submit value=\"Add Demo\"></td></tr>\n\n";
print "</font>\n";
print "</td>\n</tr>\n</table>\n";
print "</form>\n";
}