Question

Update multiple checkboxes (PHP/MySQL)

Asked by: kcalder

I have a set of checkboxes (see screenshot) which provide the user with the ability to set the visibility of the related document in a listing elsewhere on the site. I have reviewed a number of the entries on EE that deal with multiple checkboxes but cannot quite get it to work. When the user changes the status of the checkbox(es) and the update button clicked, the checkbox values should be updated in the MySQL database and I'd like a bit of help with how the query loop should look, presumbly using 'foreach'. The bit of jQuery in the code is simply to control the enable/disable status of the submit button. All assistance much appreciated.

<form method="post" name="setDocVisibility" id="setDocVisibility">
    <?php do 
    { ?>
        <tr>
            <td class="visDocListTitle">
	        <input type="hidden" name="docPK[]" value="<?php echo $row_rstVisDocList['doc_pk']; ?>" />
		<input type="checkbox" name="checkbox[]" id="checkbox"
		<?php if ($row_rstVisDocList['docVisible'] == 1) echo 'checked="checked"'; ?>
							onclick="$('#setVisButton').removeAttr('disabled').addClass('boldRed');"
		value="<?php echo $row_rstVisDocList['docVisible']; ?>"
		/>
		<?php echo $row_rstVisDocList['docTitle']; ?>
		</td>
		<td class="visDocListRevision"><?php
			if (!strcmp($row_rstVisDocList['docRevision'],"")) 
				echo '-';
			else
				echo $row_rstVisDocList['docRevision']; ?></td>
		<td class="visDocListZone"><?php echo $row_rstVisDocList['zoneTitle']; ?></td>
	</tr>
    <?php } while ($row_rstVisDocList = mysql_fetch_assoc($rstVisDocList)); ?>
    <tr>
	<td class="visDocListTitle" colspan="4">
    	    <input name="setVisButton" id="setVisButton" type="submit" disabled="disabled" value="Update" />
	</td>							
    </tr>
    <input type="hidden" name="tab" id="tab" value="2" />
</form>

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-06 at 01:16:56ID24710686
Tags

PHP

,

MySQL

Topic

PHP and Databases

Participating Experts
1
Points
125
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. mysql_fetch_row() and foreach() to get mysql data
    I dont know if I have understod the function of mysql_fetch_row to get mysql data with a foreach() loop. I get this error-message: Warning: Invalid argument supplied for foreach() in C:\Inetpub\wwwroot\learning-php\listmail_backup.php on line 52 Warning: Invalid argument s...
  2. Using foreach statement in PHP to insert multiple rows in My…
    I have a table that displays 3 fields that are repeated depending on the number of rows that a user chooses. These 3 fields need to be inserted into MySQL when the form is submitted. I'm not sure how to use a foreach statement to insert these 3 fields repeatedly depending o...
  3. php to mysql
    in a .txt document firstname lastname email address firstname lastname email address how could someone read this data in php and put it on a mysql table
  4. can i get dynamic photo gallery in jquery anywhere with my…
    can i get dynamic photo gallery in jquery anywhere with mysql database and php and jquery? if it is without jquery, that would be great else also great.
  5. PHP/MySQL foreach Unique output
    I have a table called "customers". This has all the customer information, such as billing and service addresses and other information about the customer. I also have a table called "customerservicedate". This table holds all service data that is done to...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: kcalderPosted on 2009-09-06 at 01:24:28ID: 25269122

Oops, just seen that I forgot to add the screenshot!

 

by: Ray_PaseurPosted on 2009-09-06 at 07:11:23ID: 25269990

Checkboxes that are not checked do not appear in the $_POST array.  See the code snippet...

<?php // RAY_checkbox_test.php
error_reporting(E_ALL);
 
// IF THE FIELDS HAVE BEEN POSTED
if (!empty($_POST["_submit"]))
{
// CHECK FOR AT LEAST ONE BOX CHECKED - REMOTE THE SUBMIT BUTTON
   unset($_POST["_submit"]);
 
// IF THE POST ARRAY IS EMPTY NOW, NO BUTTONS WERE CHECKED
   if (empty($_POST))
   {
      echo "YOU DID NOT CHOOSE A CHECKBOX";
   }
   else
   {
      echo "THANK YOU!";
      var_dump($_POST); // SHOW WHAT WAS CHECKED
   }
}
// END OF PHP - PUT UP FORM
?>
<html>
<body>
<form method="POST">
CHECK OR UNCHECK BOXES<br/>
BOX1 <input name="box1" type="checkbox" value="MyBox1" <?php if (isset($_POST["box1"])) echo " checked"; ?> /><br/>
BOX2 <input name="box2" type="checkbox" value="MyBox2" <?php if (isset($_POST["box2"])) echo " checked"; ?> /><br/>
<input type="submit" name="_submit"  value="go" />
</form>
</body>
</html>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-09-06 at 07:14:39ID: 25270003

Your example looks more like this one (not a "delete" but similar, in that it uses an array for the checkboxes).  I think your script needs to be aware of the checkboxes so it can test for and update the on and off conditions for each checkbox.  Perhaps using a named element of the checkbox() array would be an easy way to go after this problem.

Best regards, ~Ray

<?php // RAY_checkbox_delete.php
error_reporting(E_ALL);
echo "<pre>\n";
 
// IF ANYTHING IS POSTED?
if (!empty($_POST))
{
// DUMP THE POST ARRAY TO SHOW WHAT CAME THROUGH
   echo "POST: "; var_dump($_POST); echo "\n\n";
 
// ITERATE OVER THE "box" SUB-ARRAY TO SHOW WHAT WAS CHECKED
   foreach ($_POST["box"] as $id)
   {
      $sql = 'DELETE FROM mytable WHERE id = ' . $id;
      echo "\n$sql"; // IN REAL LIVE WE WOULD RUN THIS QUERY - HERE WE JUST PRINT IT
   }
}// END PHP, PUT UP THE FORM
?>
<form method="POST">
CHECK A BOX TO INDICATE THAT YOU WANT TO DELETE THE RECORD
<input name=box[] type="checkbox" value="1">ONE
<input name=box[] type="checkbox" value="2">TWO
<input name=box[] type="checkbox" value="3">TRE
<input name=box[] type="checkbox" value="4">FOR
<input type="submit" />
</form>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

Select allOpen in new window

 

by: kcalderPosted on 2009-09-06 at 11:11:00ID: 25270881

Thanks for posting. I need to loop through to determine the checked status of each checkbox in order to update the table. For this I need to identify not just the checkbox value but the checked status (0 or 1). How can I achieve this?

 

by: Ray_PaseurPosted on 2009-09-06 at 11:12:10ID: 25270887

I _think_ a named element in the checkbox might work.  I'll experiment and post a script if I can get this to work...

 

by: Ray_PaseurPosted on 2009-09-06 at 11:35:09ID: 25270971

<?php // RAY_checkbox_names.php
error_reporting(E_ALL);
echo "<pre>\n";
 
// TEST DATA IN AN ARRAY
$arr = array('cats', 'dogs', 'pigs', 'cows','fish');
 
// MAKE AN ARRAY TO HOLD OUR POST DATA RESULTS
$animals = array();
foreach ($arr as $animal)
{
    $animals[$animal] = 'off';
}
 
 
 
 
 
 
// IF ANYTHING IS POSTED
if (!empty($_POST))
{
// USE OUR TEST DATA ARRAY TO BE AWARE OF THE CHECKBOX ELEMENTS FROM THE FORM
    foreach ($animals as $animal => $flag)
    {
        if (isset($_POST["box"][$animal])) $animals[$animal] = 'on';
    }
    echo "\nTHE \$animals() ARRAY:\n";
    print_r($animals);
}
 
 
 
 
 
// PUT UP THE FORM BASED ON THE ARRAY OF ANIMALS IN $arr
echo "<form method=\"post\">\n";
foreach ($animals as $animal => $flag)
{
    echo "<input type=\"checkbox\" name=\"box[$animal]\"";
    if ($flag == 'on') echo " checked ";
    echo "/> $animal \n";
}
echo "<input type=\"submit\" />\n";
echo "</form>\n";

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:

Select allOpen in new window

 

by: kcalderPosted on 2009-09-07 at 23:11:58ID: 25279019

As you can see from my code I am using a repeat region behaviour to list out the items rather than a 'foreach' loop so I am not sure how to apply the flag to the checkbox.

 

by: Ray_PaseurPosted on 2009-09-08 at 05:10:37ID: 25280976

I don't think the choice of iterator matters.  The key here is knowing what checkboxes are expected and applying some predictable name to the checkboxes in the form script.  Then in the action script, you also need to know what checkboxes are expected, so you can know that the ones which are omitted from the POST array are the ones that are "off".

Referring to the snippet posted above, at line 12 we produce an associative array of animals.  This is the predictable set of names for the checkboxes.  That array is available to both the action script and the form script.  The action script processing is shown in lines 20~30.  The form script is shown in lines 36~45.

You might want to install this code snippet and run it so you can watch the behavior.  HTH, ~Ray

 

by: kcalderPosted on 2009-09-08 at 06:17:43ID: 25281515

Yes, thanks I have tried the script and it works well. It's just that I cannot see how to incorporate it into my code. In my form script I show an array of checkboxes where the value is set as the check value (0 or 1) which is obviously incorrect so I have changed the value to the item ID (primary key). However, I can't see how to embed the principles of your code into it, and I am looking to update the database using a routine like the one below. Could you possibly incorporate the logic into the code I have posted?

<?php
// Manually update the database
if (isset($_POST['setVisButton']))
{
    // Create an array of user names to use in finding persons who have checked out documents
    @ $db = new mysqli('host', 'user', 'pw', 'db');
    if (!$db) die ('Could not connect to the database: '.mysql_error());
    // Update the database with all 
    foreach($_POST['checkbox'] as $id)
    {
	$query = sprintf("UPDATE document SET docVisible=%d WHERE doc_pk=%s", $checked, $id);
	$result = $db->query($query);
    }
}
?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-09-08 at 06:23:53ID: 25281567

Please post the entire script you're using and I will see if I can help.  It's a hectic week, and I may not have time be very useful to you beyond showing the principles, but before I have to sign off this question, I'll take a look...

 

by: kcalderPosted on 2009-09-08 at 07:40:58ID: 25282328

Much appreciated. Script below...

<form method="post" name="setDocVisibility" id="setDocVisibility">
						<?php 
						do 
						{ ?>
							<tr>
								<td class="visDocListTitle">
									<input type="checkbox" name="checkbox[]" id="checkbox"
										<?php if ($row_rstVisDocList['docVisible'] == 1) echo 'checked="checked"'; ?>
										onclick="$('#setVisButton').removeAttr('disabled').addClass('boldRed');"
										value="<?php echo $row_rstVisDocList['doc_pk']; ?>"
									/>
									<?php echo $row_rstVisDocList['docTitle']; ?>
								</td>
								<td class="visDocListRevision"><?php
								if (!strcmp($row_rstVisDocList['docRevision'],"")) 
									echo '-';
								else
									echo $row_rstVisDocList['docRevision']; ?></td>
								<td class="visDocListZone"><?php echo $row_rstVisDocList['zoneTitle']; ?></td>
							</tr>
						<?php } while ($row_rstVisDocList = mysql_fetch_assoc($rstVisDocList)); 
						?>
						<tr>
							<td class="visDocListTitle" colspan="4">
								<input name="setVisButton" id="setVisButton" type="submit" disabled="disabled" value="Update" />
							</td>							
						</tr>
						<input type="hidden" name="tab" id="tab" value="2" />
					</form>
					<?php } 
					// Manually update the database
					if (isset($_POST['setVisButton']))
					{
						// Create an array of user names to use in finding persons who have checked out documents
						@ $db = new mysqli('host', 'user', 'pw', 'db');
						if (!$db) die ('Could not connect to the database: '.mysql_error());
						// Update the database with all 
						foreach($_POST['checkbox'] as $id)
						{
							$query = sprintf("UPDATE document SET docVisible=%d WHERE doc_pk=%s", $checked, $id);
							$result = $db->query($query);
						}
					}
					?>

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:

Select allOpen in new window

 

by: Ray_PaseurPosted on 2009-09-08 at 09:28:39ID: 25283526

I'm confused here - it looks like the var $checked in undefined in this script, yet it's being used in a query.  ??

 

by: kcalderPosted on 2009-09-08 at 13:13:42ID: 25285725

Yes that's right, it's there as a reminder but doesn't do anything at the moment. However, the MySQL query does need both an ID and a value for the checked status, it's just that I don't know how to get that out of the code above it.

 

by: Ray_PaseurPosted on 2009-09-09 at 04:55:28ID: 25290185

"don't know how to get that out of the code above it."

What code "above it?"

Let me ask this again, "Please post the entire script" so we do not have to guess at the contents of undefined variables.  Also, I would ask you to do two additional things to help debug this.

1.  Turn on the error reporting by adding this to the top of the script:

error_reporting(E_ALL);

2.  Use "echo" to print out the value of $query after it is prepared on line 40 and before it is used on line 41.  Use var_dump() to print out the value of $result after line 41.

Thanks, ~Ray

 

by: kcalderPosted on 2009-09-09 at 08:37:03ID: 25292386

Perhaps the best thing is if I simply upload the whole file but it has to be in txt format. The code section of interest is within the div called TabbedPanel4

  • file.txt
    • 74 KB

    file showing checkboxes

 

by: Ray_PaseurPosted on 2009-09-09 at 11:07:06ID: 25293952

It's best to use the code snippet for code - that way we can all see the same line numbers.

But I have to say, I do not think a 1,600+ line script is something to get debugged at EE.   We can answer questions, and I have done that, showing you what must be done to identify checkboxes that are not checked.  But for something of this size you should hire a software developer who can get paid for the time it is going to take to work through all of this.

best of luck with your project, ~Ray

<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "Director,admin,MD,docOwner,docGroupAdmin,businessManager";
$MM_donotCheckaccess = "false";
 
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 
 
  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}
 
$MM_restrictGoTo = "../denied.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php require_once('../connections/RED_links.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$currentPage = $_SERVER["PHP_SELF"];
 
if ((isset($_POST['deleteRadio'])) && ($_POST['deleteRadio'] != "")) {
  $deleteSQL = sprintf("DELETE FROM `document` WHERE doc_pk=%s",
                       GetSQLValueString($_POST['deleteRadio'], "int"));
 
  mysql_select_db($database_RED_links, $RED_links);
  $Result1 = mysql_query($deleteSQL, $RED_links) or die(mysql_error());
}
 
$maxRows_rstCheckoutDocList = 5;
$pageNum_rstCheckoutDocList = 0;
if (isset($_GET['pageNum_rstCheckoutDocList'])) {
  $pageNum_rstCheckoutDocList = $_GET['pageNum_rstCheckoutDocList'];
}
$startRow_rstCheckoutDocList = $pageNum_rstCheckoutDocList * $maxRows_rstCheckoutDocList;
 
$userPK_rstCheckoutDocList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstCheckoutDocList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstCheckoutDocList = sprintf("SELECT doc_pk, docTitle, docFilename, docApplication, docRevision, docEditable, docFileType_id, docFileType, zoneTitle, docOwnerPK, docPassword, docArchived, docCheckedOut, docCheckedOutBy FROM document  LEFT JOIN docRevision ON docRevision_id = docRevision_pk LEFT JOIN docFileType ON docFileType_id = docFileType_pk  LEFT JOIN adminGroup ON adminGroup_pk = docAdminGroup LEFT JOIN zone ON docZone_id = zone_pk LEFT JOIN user ON user_pk = %s WHERE docTRL = 0 AND docArchived = 0 AND (((docOwnerPK = %s) OR (docAdminGroup = adminGroupA) OR (docAdminGroup = adminGroupB) OR (docAdminGroup = adminGroupC) OR (docAdminGroup = adminGroupD) OR (docAdminGroup = adminGroupE) OR (docAdminGroup = adminGroupF) OR (docAdminGroup = adminGroupG) OR (docAdminGroup = adminGroupH) OR (docAdminGroup = adminGroupI) OR (docAdminGroup = adminGroupJ) OR (docAdminGroup = adminGroupK) OR (docAdminGroup = adminGroupL) OR (docAdminGroup = adminGroupM))) ORDER BY docTitle ASC, docRevision DESC", GetSQLValueString($userPK_rstCheckoutDocList, "int"),GetSQLValueString($userPK_rstCheckoutDocList, "int"));
$query_limit_rstCheckoutDocList = sprintf("%s LIMIT %d, %d", $query_rstCheckoutDocList, $startRow_rstCheckoutDocList, $maxRows_rstCheckoutDocList);
$rstCheckoutDocList = mysql_query($query_limit_rstCheckoutDocList, $RED_links) or die(mysql_error());
$row_rstCheckoutDocList = mysql_fetch_assoc($rstCheckoutDocList);
 
if (isset($_GET['totalRows_rstCheckoutDocList'])) {
  $totalRows_rstCheckoutDocList = $_GET['totalRows_rstCheckoutDocList'];
} else {
  $all_rstCheckoutDocList = mysql_query($query_rstCheckoutDocList);
  $totalRows_rstCheckoutDocList = mysql_num_rows($all_rstCheckoutDocList);
}
$totalPages_rstCheckoutDocList = ceil($totalRows_rstCheckoutDocList/$maxRows_rstCheckoutDocList)-1;
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstZoneHelp = "SELECT helpText FROM helpText WHERE helpText_pk = 3";
$rstZoneHelp = mysql_query($query_rstZoneHelp, $RED_links) or die(mysql_error());
$row_rstZoneHelp = mysql_fetch_assoc($rstZoneHelp);
$totalRows_rstZoneHelp = mysql_num_rows($rstZoneHelp);
 
$userPK_rstDocOwner = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstDocOwner = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstDocOwner = sprintf("SELECT user_pk, firstName, lastName FROM user WHERE user_pk = %s", $userPK_rstDocOwner);
$rstDocOwner = mysql_query($query_rstDocOwner, $RED_links) or die(mysql_error());
$row_rstDocOwner = mysql_fetch_assoc($rstDocOwner);
$totalRows_rstDocOwner = mysql_num_rows($rstDocOwner);
 
$maxRows_rstDocOwnerList = 5;
$pageNum_rstDocOwnerList = 0;
if (isset($_GET['pageNum_rstDocOwnerList'])) {
  $pageNum_rstDocOwnerList = $_GET['pageNum_rstDocOwnerList'];
}
$startRow_rstDocOwnerList = $pageNum_rstDocOwnerList * $maxRows_rstDocOwnerList;
 
$userPK_rstDocOwnerList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstDocOwnerList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstDocOwnerList = sprintf("SELECT doc_pk, docTitle, docRevision, docZone_id, zoneTitle, docArchived, user_pk FROM document LEFT JOIN docRevision ON docRevision_id = docRevision_pk LEFT JOIN zone ON docZone_id = zone_pk LEFT JOIN user ON %s = user_pk WHERE docOwnerPK = %s ORDER BY zoneTitle ASC, docTitle ASC, docRevision ASC", GetSQLValueString($userPK_rstDocOwnerList, "int"),GetSQLValueString($userPK_rstDocOwnerList, "int"));
$query_limit_rstDocOwnerList = sprintf("%s LIMIT %d, %d", $query_rstDocOwnerList, $startRow_rstDocOwnerList, $maxRows_rstDocOwnerList);
$rstDocOwnerList = mysql_query($query_limit_rstDocOwnerList, $RED_links) or die(mysql_error());
$row_rstDocOwnerList = mysql_fetch_assoc($rstDocOwnerList);
 
if (isset($_GET['totalRows_rstDocOwnerList'])) {
  $totalRows_rstDocOwnerList = $_GET['totalRows_rstDocOwnerList'];
} else {
  $all_rstDocOwnerList = mysql_query($query_rstDocOwnerList);
  $totalRows_rstDocOwnerList = mysql_num_rows($all_rstDocOwnerList);
}
$totalPages_rstDocOwnerList = ceil($totalRows_rstDocOwnerList/$maxRows_rstDocOwnerList)-1;
 
$maxRows_rstAddRevisedDocList = 5;
$pageNum_rstAddRevisedDocList = 0;
if (isset($_GET['pageNum_rstAddRevisedDocList'])) {
  $pageNum_rstAddRevisedDocList = $_GET['pageNum_rstAddRevisedDocList'];
}
$startRow_rstAddRevisedDocList = $pageNum_rstAddRevisedDocList * $maxRows_rstAddRevisedDocList;
 
$userPK_rstAddRevisedDocList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstAddRevisedDocList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstAddRevisedDocList = sprintf("SELECT doc_pk, docTitle, docFilename, docRevision_id, docRevision, docFileType_id, docFileType, docAdminGroup, docEditable, docApplication, docPassword, zone_pk, zoneTitle, sector_pk, sectorTitle FROM document LEFT JOIN docRevision ON docRevision_id + 1 = docRevision_pk LEFT JOIN adminGroup ON adminGroup_pk = docAdminGroup LEFT JOIN zone ON zone_pk = docZone_id LEFT JOIN sector ON sector_pk = docSector_id LEFT JOIN docFileType ON docFileType_id = docFileType_pk  LEFT JOIN user ON docOwnerPK = user_pk WHERE docTRL = 0 AND docCheckedOut = 1 AND docOwnerPK = %s ORDER BY zone_pk ASC, docTitle ASC, docRevision_id ASC", GetSQLValueString($userPK_rstAddRevisedDocList, "int"));
$query_limit_rstAddRevisedDocList = sprintf("%s LIMIT %d, %d", $query_rstAddRevisedDocList, $startRow_rstAddRevisedDocList, $maxRows_rstAddRevisedDocList);
$rstAddRevisedDocList = mysql_query($query_limit_rstAddRevisedDocList, $RED_links) or die(mysql_error());
$row_rstAddRevisedDocList = mysql_fetch_assoc($rstAddRevisedDocList);
 
if (isset($_GET['totalRows_rstAddRevisedDocList'])) {
  $totalRows_rstAddRevisedDocList = $_GET['totalRows_rstAddRevisedDocList'];
} else {
  $all_rstAddRevisedDocList = mysql_query($query_rstAddRevisedDocList);
  $totalRows_rstAddRevisedDocList = mysql_num_rows($all_rstAddRevisedDocList);
}
$totalPages_rstAddRevisedDocList = ceil($totalRows_rstAddRevisedDocList/$maxRows_rstAddRevisedDocList)-1;
 
$userPK_rstUserSector1 = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstUserSector1 = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstUserSector1 = sprintf("SELECT sector_pk, sectorTitle, isDirector, director_sector1_id FROM sector LEFT JOIN user ON sector_pk = director_sector1_id WHERE user_pk = %s", GetSQLValueString($userPK_rstUserSector1, "int"));
$rstUserSector1 = mysql_query($query_rstUserSector1, $RED_links) or die(mysql_error());
$row_rstUserSector1 = mysql_fetch_assoc($rstUserSector1);
$totalRows_rstUserSector1 = mysql_num_rows($rstUserSector1);
 
$userPK_rstUserSector2 = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstUserSector2 = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstUserSector2 = sprintf("SELECT sector_pk, sectorTitle, director_sector2_id FROM sector LEFT JOIN user ON sector_pk = director_sector2_id WHERE user_pk = %s", GetSQLValueString($userPK_rstUserSector2, "int"));
$rstUserSector2 = mysql_query($query_rstUserSector2, $RED_links) or die(mysql_error());
$row_rstUserSector2 = mysql_fetch_assoc($rstUserSector2);
$totalRows_rstUserSector2 = mysql_num_rows($rstUserSector2);
 
$userPK_rstUserSector3 = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstUserSector3 = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstUserSector3 = sprintf("SELECT sector_pk, sectorTitle, director_sector3_id FROM sector LEFT JOIN user ON sector_pk = director_sector3_id WHERE user_pk = %s", GetSQLValueString($userPK_rstUserSector3, "int"));
$rstUserSector3 = mysql_query($query_rstUserSector3, $RED_links) or die(mysql_error());
$row_rstUserSector3 = mysql_fetch_assoc($rstUserSector3);
$totalRows_rstUserSector3 = mysql_num_rows($rstUserSector3);
 
$maxRows_rstDelDocList = 5;
$pageNum_rstDelDocList = 0;
if (isset($_GET['pageNum_rstDelDocList'])) {
  $pageNum_rstDelDocList = $_GET['pageNum_rstDelDocList'];
}
$startRow_rstDelDocList = $pageNum_rstDelDocList * $maxRows_rstDelDocList;
 
$userPK_rstDelDocList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstDelDocList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstDelDocList = sprintf("SELECT doc_pk, docTitle, docFilename, docFileType, docRevision, docZone_id, zoneTitle, docArchived, user_pk FROM document LEFT JOIN docRevision ON docRevision_id = docRevision_pk LEFT JOIN docFileType ON docFileType_id = docFileType_pk LEFT JOIN zone ON docZone_id = zone_pk LEFT JOIN user ON %s = user_pk WHERE docOwnerPK = %s AND docCheckedOut = 0 ORDER BY docTitle ASC, docRevision DESC, zoneTitle ASC", GetSQLValueString($userPK_rstDelDocList, "int"),GetSQLValueString($userPK_rstDelDocList, "int"));
$query_limit_rstDelDocList = sprintf("%s LIMIT %d, %d", $query_rstDelDocList, $startRow_rstDelDocList, $maxRows_rstDelDocList);
$rstDelDocList = mysql_query($query_limit_rstDelDocList, $RED_links) or die(mysql_error());
$row_rstDelDocList = mysql_fetch_assoc($rstDelDocList);
 
if (isset($_GET['totalRows_rstDelDocList'])) {
  $totalRows_rstDelDocList = $_GET['totalRows_rstDelDocList'];
} else {
  $all_rstDelDocList = mysql_query($query_rstDelDocList);
  $totalRows_rstDelDocList = mysql_num_rows($all_rstDelDocList);
}
$totalPages_rstDelDocList = ceil($totalRows_rstDelDocList/$maxRows_rstDelDocList)-1;
 
$postVal_rstDownloadFile = "1";
if (isset($_POST['checkoutRadio'])) {
  $postVal_rstDownloadFile = $_POST['checkoutRadio'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstDownloadFile = sprintf("SELECT doc_pk, docFilename, docFileType FROM document LEFT JOIN docFileType ON docFileType_id = docFileType_pk WHERE doc_pk = %s", GetSQLValueString($postVal_rstDownloadFile, "int"));
$rstDownloadFile = mysql_query($query_rstDownloadFile, $RED_links) or die(mysql_error());
$row_rstDownloadFile = mysql_fetch_assoc($rstDownloadFile);
$totalRows_rstDownloadFile = mysql_num_rows($rstDownloadFile);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextCheckout = "SELECT helpText FROM helpText WHERE helpText_pk = 100";
$rstHelpTextCheckout = mysql_query($query_rstHelpTextCheckout, $RED_links) or die(mysql_error());
$row_rstHelpTextCheckout = mysql_fetch_assoc($rstHelpTextCheckout);
$totalRows_rstHelpTextCheckout = mysql_num_rows($rstHelpTextCheckout);
 
$maxRows_rstArchivedDocList = 5;
$pageNum_rstArchivedDocList = 0;
if (isset($_GET['pageNum_rstArchivedDocList'])) {
  $pageNum_rstArchivedDocList = $_GET['pageNum_rstArchivedDocList'];
}
$startRow_rstArchivedDocList = $pageNum_rstArchivedDocList * $maxRows_rstArchivedDocList;
 
$userPK_rstArchivedDocList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstArchivedDocList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstArchivedDocList = sprintf("SELECT doc_pk, docTitle, docFilename, docApplication, docRevision, docFileType, zoneTitle, docOwnerPK, docPassword FROM document  LEFT JOIN docRevision ON docRevision_id = docRevision_pk LEFT JOIN docFileType ON docFileType_id = docFileType_pk  LEFT JOIN adminGroup ON adminGroup_pk = docAdminGroup LEFT JOIN zone ON docZone_id = zone_pk LEFT JOIN user ON user_pk = %s WHERE docArchived = 1 AND docTRL = 0 AND (((docOwnerPK = %s) OR (docAdminGroup = adminGroupA) OR (docAdminGroup = adminGroupB) OR (docAdminGroup = adminGroupC) OR (docAdminGroup = adminGroupD) OR (docAdminGroup = adminGroupE) OR (docAdminGroup = adminGroupF) OR (docAdminGroup = adminGroupG) OR (docAdminGroup = adminGroupH) OR (docAdminGroup = adminGroupI) OR (docAdminGroup = adminGroupJ) OR (docAdminGroup = adminGroupK) OR (docAdminGroup = adminGroupL) OR (docAdminGroup = adminGroupM))) ORDER BY docTitle ASC, docRevision DESC", GetSQLValueString($userPK_rstArchivedDocList, "int"),GetSQLValueString($userPK_rstArchivedDocList, "int"));
$query_limit_rstArchivedDocList = sprintf("%s LIMIT %d, %d", $query_rstArchivedDocList, $startRow_rstArchivedDocList, $maxRows_rstArchivedDocList);
$rstArchivedDocList = mysql_query($query_limit_rstArchivedDocList, $RED_links) or die(mysql_error());
$row_rstArchivedDocList = mysql_fetch_assoc($rstArchivedDocList);
 
if (isset($_GET['totalRows_rstArchivedDocList'])) {
  $totalRows_rstArchivedDocList = $_GET['totalRows_rstArchivedDocList'];
} else {
  $all_rstArchivedDocList = mysql_query($query_rstArchivedDocList);
  $totalRows_rstArchivedDocList = mysql_num_rows($all_rstArchivedDocList);
}
$totalPages_rstArchivedDocList = ceil($totalRows_rstArchivedDocList/$maxRows_rstArchivedDocList)-1;
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextAddRevised = "SELECT helpText FROM helpText WHERE helpText_pk = 101";
$rstHelpTextAddRevised = mysql_query($query_rstHelpTextAddRevised, $RED_links) or die(mysql_error());
$row_rstHelpTextAddRevised = mysql_fetch_assoc($rstHelpTextAddRevised);
$totalRows_rstHelpTextAddRevised = mysql_num_rows($rstHelpTextAddRevised);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextAddNew = "SELECT helpText FROM helpText WHERE helpText_pk = 103";
$rstHelpTextAddNew = mysql_query($query_rstHelpTextAddNew, $RED_links) or die(mysql_error());
$row_rstHelpTextAddNew = mysql_fetch_assoc($rstHelpTextAddNew);
$totalRows_rstHelpTextAddNew = mysql_num_rows($rstHelpTextAddNew);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextDrop = "SELECT helpText FROM helpText WHERE helpText_pk = 105";
$rstHelpTextDrop = mysql_query($query_rstHelpTextDrop, $RED_links) or die(mysql_error());
$row_rstHelpTextDrop = mysql_fetch_assoc($rstHelpTextDrop);
$totalRows_rstHelpTextDrop = mysql_num_rows($rstHelpTextDrop);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextArchive = "SELECT helpText FROM helpText WHERE helpText_pk = 104";
$rstHelpTextArchive = mysql_query($query_rstHelpTextArchive, $RED_links) or die(mysql_error());
$row_rstHelpTextArchive = mysql_fetch_assoc($rstHelpTextArchive);
$totalRows_rstHelpTextArchive = mysql_num_rows($rstHelpTextArchive);
 
$userPK_rstAdminGroups = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstAdminGroups = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstAdminGroups = sprintf("SELECT adminGroup_pk, agMembers FROM adminGroup LEFT JOIN user ON user_pk = %s WHERE (isDirector = 1 AND agMember1_id = 99) OR (agMember1_id = %s OR agMember2_id = %s OR agMember3_id = %s OR agMember4_id = %s OR agMember5_id = %s OR agMember6_id = %s OR agMember7_id = %s OR agMember8_id = %s OR agMember9_id = %s) ORDER BY agMembers ASC", GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"),GetSQLValueString($userPK_rstAdminGroups, "int"));
$rstAdminGroups = mysql_query($query_rstAdminGroups, $RED_links) or die(mysql_error());
$row_rstAdminGroups = mysql_fetch_assoc($rstAdminGroups);
$totalRows_rstAdminGroups = mysql_num_rows($rstAdminGroups);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstPMSZones = "SELECT * FROM zone ORDER BY zoneTitle ASC";
$rstPMSZones = mysql_query($query_rstPMSZones, $RED_links) or die(mysql_error());
$row_rstPMSZones = mysql_fetch_assoc($rstPMSZones);
$totalRows_rstPMSZones = mysql_num_rows($rstPMSZones);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstDocumentType = "SELECT * FROM docType ORDER BY docType ASC";
$rstDocumentType = mysql_query($query_rstDocumentType, $RED_links) or die(mysql_error());
$row_rstDocumentType = mysql_fetch_assoc($rstDocumentType);
$totalRows_rstDocumentType = mysql_num_rows($rstDocumentType);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstDocumentSubject = "SELECT * FROM docSubjectRED ORDER BY docSubjectRED";
$rstDocumentSubject = mysql_query($query_rstDocumentSubject, $RED_links) or die(mysql_error());
$row_rstDocumentSubject = mysql_fetch_assoc($rstDocumentSubject);
$totalRows_rstDocumentSubject = mysql_num_rows($rstDocumentSubject);
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstOffices = "SELECT office_pk, location FROM office ORDER BY office_pk";
$rstOffices = mysql_query($query_rstOffices, $RED_links) or die(mysql_error());
$row_rstOffices = mysql_fetch_assoc($rstOffices);
$totalRows_rstOffices = mysql_num_rows($rstOffices);
 
$userPK_rstUserSector4 = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstUserSector4 = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstUserSector4 = sprintf("SELECT sector_pk, sectorTitle, director_sector4_id FROM sector LEFT JOIN user ON sector_pk = director_sector4_id WHERE user_pk = %s", GetSQLValueString($userPK_rstUserSector4, "int"));
$rstUserSector4 = mysql_query($query_rstUserSector4, $RED_links) or die(mysql_error());
$row_rstUserSector4 = mysql_fetch_assoc($rstUserSector4);
$totalRows_rstUserSector4 = mysql_num_rows($rstUserSector4);
 
$userPK_rstUserSector5 = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstUserSector5 = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstUserSector5 = sprintf("SELECT sector_pk, sectorTitle, director_sector5_id FROM sector LEFT JOIN user ON sector_pk = director_sector5_id WHERE user_pk = %s", GetSQLValueString($userPK_rstUserSector5, "int"));
$rstUserSector5 = mysql_query($query_rstUserSector5, $RED_links) or die(mysql_error());
$row_rstUserSector5 = mysql_fetch_assoc($rstUserSector5);
$totalRows_rstUserSector5 = mysql_num_rows($rstUserSector5);
 
$maxRows_rstVisDocList = 5;
$pageNum_rstVisDocList = 0;
if (isset($_GET['pageNum_rstVisDocList'])) {
  $pageNum_rstVisDocList = $_GET['pageNum_rstVisDocList'];
}
$startRow_rstVisDocList = $pageNum_rstVisDocList * $maxRows_rstVisDocList;
 
$userPK_rstVisDocList = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstVisDocList = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstVisDocList = sprintf("SELECT doc_pk, docTitle, docRevision, docZone_id, zoneTitle, docArchived, user_pk, docVisible FROM document LEFT JOIN docRevision ON docRevision_id = docRevision_pk LEFT JOIN zone ON docZone_id = zone_pk LEFT JOIN user ON %s = user_pk WHERE docOwnerPK = %s AND docCheckedOut = 0 ORDER BY docTitle ASC, docRevision DESC, zoneTitle ASC", GetSQLValueString($userPK_rstVisDocList, "int"),GetSQLValueString($userPK_rstVisDocList, "int"));
$query_limit_rstVisDocList = sprintf("%s LIMIT %d, %d", $query_rstVisDocList, $startRow_rstVisDocList, $maxRows_rstVisDocList);
$rstVisDocList = mysql_query($query_limit_rstVisDocList, $RED_links) or die(mysql_error());
$row_rstVisDocList = mysql_fetch_assoc($rstVisDocList);
 
if (isset($_GET['totalRows_rstVisDocList'])) {
  $totalRows_rstVisDocList = $_GET['totalRows_rstVisDocList'];
} else {
  $all_rstVisDocList = mysql_query($query_rstVisDocList);
  $totalRows_rstVisDocList = mysql_num_rows($all_rstVisDocList);
}
$totalPages_rstVisDocList = ceil($totalRows_rstVisDocList/$maxRows_rstVisDocList)-1;
 
mysql_select_db($database_RED_links, $RED_links);
$query_rstHelpTextVisibility = "SELECT helpText FROM helpText WHERE helpText_pk = 102";
$rstHelpTextVisibility = mysql_query($query_rstHelpTextVisibility, $RED_links) or die(mysql_error());
$row_rstHelpTextVisibility = mysql_fetch_assoc($rstHelpTextVisibility);
$totalRows_rstHelpTextVisibility = mysql_num_rows($rstHelpTextVisibility);
 
$userPK_rstDocListing = "1";
if (isset($_SESSION['MM_Username'])) {
  $userPK_rstDocListing = $_SESSION['MM_Username'];
}
mysql_select_db($database_RED_links, $RED_links);
$query_rstDocListing = sprintf("SELECT docListing_pk, docListingTitle FROM docListing LEFT JOIN user ON user_pk = %s WHERE docListing_pk = 1 OR (docListingMember1 = 99 AND isDirector = 1) OR docListingMember2 = %s ORDER BY docListing_pk ASC", GetSQLValueString($userPK_rstDocListing, "int"),GetSQLValueString($userPK_rstDocListing, "int"));
$rstDocListing = mysql_query($query_rstDocListing, $RED_links) or die(mysql_error());
$row_rstDocListing = mysql_fetch_assoc($rstDocListing);
$totalRows_rstDocListing = mysql_num_rows($rstDocListing);
 
$queryString_rstCheckoutDocList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstCheckoutDocList") == false && 
        stristr($param, "totalRows_rstCheckoutDocList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstCheckoutDocList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstCheckoutDocList = sprintf("&totalRows_rstCheckoutDocList=%d%s", $totalRows_rstCheckoutDocList, $queryString_rstCheckoutDocList);
 
$queryString_rstAddRevisedDocList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstAddRevisedDocList") == false && 
        stristr($param, "totalRows_rstAddRevisedDocList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstAddRevisedDocList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstAddRevisedDocList = sprintf("&totalRows_rstAddRevisedDocList=%d%s", $totalRows_rstAddRevisedDocList, $queryString_rstAddRevisedDocList);
 
$queryString_rstVisDocList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstVisDocList") == false && 
        stristr($param, "totalRows_rstVisDocList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstVisDocList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstVisDocList = sprintf("&totalRows_rstVisDocList=%d%s", $totalRows_rstVisDocList, $queryString_rstVisDocList);
 
$queryString_rstArchivedDocList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstArchivedDocList") == false && 
        stristr($param, "totalRows_rstArchivedDocList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstArchivedDocList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstArchivedDocList = sprintf("&totalRows_rstArchivedDocList=%d%s", $totalRows_rstArchivedDocList, $queryString_rstArchivedDocList);
 
$queryString_rstDelDocList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstDelDocList") == false && 
        stristr($param, "totalRows_rstDelDocList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstDelDocList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstDelDocList = sprintf("&totalRows_rstDelDocList=%d%s", $totalRows_rstDelDocList, $queryString_rstDelDocList);
 
$queryString_rstDocOwnerList = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rstDocOwnerList") == false && 
        stristr($param, "totalRows_rstDocOwnerList") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rstDocOwnerList = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rstDocOwnerList = sprintf("&totalRows_rstDocOwnerList=%d%s", $totalRows_rstDocOwnerList, $queryString_rstDocOwnerList);
?>
<?php
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != ""))
{
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true"))
{
  //to fully log out a visitor we need to clear the session varialbles
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  $logoutGoTo = "../index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
 
// Helper function to pad a string with a specific number of zeros
function padNumberWithZeros ($number,$n) 
{
	return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}
 
// Function to rev-up the drawing being checked out so that it can be added back without undertaking a file name change
function revUp($filename, $currentRevision)
{
	// Get the filename without the revision number (after '_')
	$abridgedFilename = substr($filename,0,15);
	// Increment the current revision number
	$newRevisionNum = $currentRevision + 1;
	// Pad out the revision number if necessary
	$newRevisionNum = padNumberWithZeros($newRevisionNum,2);
	// Convert new revision number to a string
	$newRevisionStr = (string)$newRevisionNum;
	// Create the new filename
	$newFilename = $abridgedFilename.$newRevisionStr;
	
	return $newFilename;
}
 
function dropFile($currentFilename, $newFilename)
{
	$sourceFolder = "../docsRED/";
	$destinationFolder = "../docsRED/dropped/";
	$current = $sourceFolder.$currentFilename;
	$new = $destinationFolder.$newFilename;
	rename($current, $new);
}
 
// Control of default Spry tabbed panel
if (isset($_GET['tab'])) 
	$tab = $_GET['tab'];
else if (isset($_POST['tab']))
	$tab = $_POST['tab'];
else $tab = 0;
 
// the IE7 script is only required to be loaded once
require('../includes/php/loadIE7.php'); 
include('../includes/php/lib.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>RED Practice Management System</title>
<link href="../css/common.css" rel="stylesheet" type="text/css" />
<link href="../css/docZone.css" rel="stylesheet" type="text/css" /><!-- menu navigation only -->
<link href="../css/mgtZone.css" rel="stylesheet" type="text/css" />
<link href="../css/mgtHelpAccordion.css" rel="stylesheet" type="text/css" />
<link href="../css/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<link href="../css/SpryAccordion.css" rel="stylesheet" type="text/css" />
<link href="../css/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="../css/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript" src="../includes/js/lib.js"></script>
<script type="text/javascript" src="../includes/js/jQuery.js"></script>
<script type="text/javascript" src="../includes/Spry/SpryTabbedPanels.js"></script>
<script type="text/javascript" src="../includes/Spry/SpryAccordion.js"></script>
<script type="text/javascript" src="../includes/Spry/SpryValidationTextField.js"></script>
<script type="text/javascript" src="../includes/Spry/SpryValidationSelect.js"></script>
<script type="text/javascript">
// jQuery functions
$(document).ready(function()
{
	$('#uploadFile').click(function()
	{
		// Clear text field
		$('#title').val('');
		// Set doc sector to None
		$('#selectDocSector :eq(0)').attr('checked','checked');
		// Set the document zone to zero option
		$('#selectDocZone option:nth(0)').attr('selected','selected');
		// Set the administration group to zero option
		$('#selectAdminGroup option:nth(0)').attr('selected','selected');
	});
	
	$('#delete').click(function()
	{
		// Cause the confirm delete button to appear and post a warning
		$('#delete').removeClass('boldRed').attr('disabled', 'disabled');
		$('#confirm').removeClass('noShow').addClass('boldRed');
		alert('To permanently delete the file click the confirm button');
	});		
});
</script>
</head>
<body onload="startTime()">
<?php
 
$user = $_SESSION['MM_Username'];
 
// Create an array of user names to use in finding persons who have checked out documents
@ $db = new mysqli('host', 'user', 'pw', 'db');
if (!$db) die ('Could not connect to the database: '.mysql_error());
// Get the list of all users for use in finding out the name of the person who has checked out a document
$query = "SELECT user_pk, firstName, lastName FROM user";
$result = $db->query($query);
$num_results = $result->num_rows;
$user = array();
for ($i = 0; $i < $num_results; $i++)
{
	$row = $result->fetch_assoc();
	$name = $row['firstName'].' '.$row['lastName'];
	$user[$i][0] = $row['user_pk'];
	$user[$i][1] = $name;
}
// free up the resultset
$result->free();
?>
<div id="header">
	<div id="clock"></div>
</div>
<div id="content">
	<h1>Practice Management System<span style="font-size:9px; color: #CCC;">&nbsp;&nbsp;Phase 1</span></h1>
	<h2>Manage RED Documents</h2>
	<div id="TabbedPanels1" class="TabbedPanels">
		<ul class="TabbedPanelsTabGroup">
			<li class="TabbedPanelsTab">Checkout</li>
			<li class="TabbedPanelsTab">Add Revised</li>
			<li class="TabbedPanelsTab">Add New</li>
			<li class="TabbedPanelsTab">Visibility</li>
			<li class="TabbedPanelsTab">Retrieve</li>
			<li class="TabbedPanelsTab">Delete</li>
			<li class="TabbedPanelsTab"><span class="boldRed">Help</span></li>
		</ul>
		<div class="TabbedPanelsContentGroup">
			<div id="TabbedPanel1" class="TabbedPanelsContent">
				<h4 class="bold">Checkout and download documents for revision</h4>
				<table class="docList">
					<tr>
						<th class="revDocListTitle">Document title</th>
						<th class="revDocListRevision">Revision</th>
						<th class="revDocListApplication">Application</th>
						<th class="revDocListOwner">Owner</th>
						<th class="revDocListZone">PMS Zone</th>
						<th class="revDocListPassword">Password</th>
					</tr>
					<tr>
						<td class="docNumbers" colspan="6">
							<?php 
							if ($totalRows_rstCheckoutDocList == 0) echo 'There are no documents';
							else if ($totalRows_rstCheckoutDocList == 1) echo 'There is one document';
							else echo 'There are '.$totalRows_rstCheckoutDocList.' documents';
							echo ' in your check out list';
							if ($totalRows_rstCheckoutDocList > $maxRows_rstCheckoutDocList)
							{
								if (min($startRow_rstCheckoutDocList + $maxRows_rstCheckoutDocList, $totalRows_rstCheckoutDocList) == $totalRows_rstCheckoutDocList) echo '.  Showing final document(s) in results set.';
								else echo '. Showing documents '.($startRow_rstCheckoutDocList + 1).' to '.min($startRow_rstCheckoutDocList + $maxRows_rstCheckoutDocList, $totalRows_rstCheckoutDocList).'.';
							}
						?>
						</td>
					</tr>
					<?php
					// Only show the rows if there is at least one document available
					if ($totalRows_rstCheckoutDocList > 0)
					{ ?>
						<form action="checkout.php" method="post" name="checkoutDoc" id="checkoutDoc">
							<?php 
							// Create the repeat region
							do { ?>
							<tr>
								<?php
								// Find the name of the document owner
								$docOwner = '';
										
								// Walk the user array 
								for ($j = 0; $j < sizeof($user); $j++) if ($user[$j][0] == $row_rstCheckoutDocList['docOwnerPK']) $docOwner = $user[$j][1];
						
								// Display changes according to whether the item has been checked out or not and to whom
								if ($row_rstCheckoutDocList['docCheckedOut'] == 0)
								{ 
									// The document has not been checked out and is available for checking out
									?>        
									<td class="revDocListTitle">
										<input name="checkoutRadio" id="checkoutRadio" type="radio" class="checkout" 
										onclick="$('#checkoutButton').removeAttr('disabled').addClass('boldRed');"
										value="<?php echo $row_rstCheckoutDocList['doc_pk']; ?>" 
										/><?php echo ' '.$row_rstCheckoutDocList['docTitle']; ?>
									</td>
									<td class="revDocListRevision"><?php 
										if (!strcmp($row_rstCheckoutDocList['docRevision'],"")) 
											echo '-';
										else
											echo $row_rstCheckoutDocList['docRevision']; ?>
									</td>
									<td class="revDocListApplication"><?php echo $row_rstCheckoutDocList['docApplication']; ?></td>
									<td class="revDocListOwner"><?php echo $docOwner; ?></td>
									<td class="revDocListZone"><?php echo $row_rstCheckoutDocList['zoneTitle']; ?></td>
									<?php 
									if ($row_rstCheckoutDocList['docFileType_id'] == 7 || $row_rstCheckoutDocList['docFileType_id'] == 8)
										echo '<td class="revDocListPassword">---</td>';
									else if ($row_rstCheckoutDocList['docFileType_id'] == 2) 
										echo '<td class="revDocListPasswordNone">Non-editable</td>';
									else echo '<td class="revDocListPassword">'.$row_rstCheckoutDocList['docPassword'].'</td>';
									?>				
									<input type="hidden" name="s" id="s" value="RED" />
								<?php }
								else
								{ 
									// The document has been checked out so find the name of the person who checked it out
									$checkedOutBy = '';
													
									// Walk the array 
									for ($k = 0; $k < sizeof($user); $k++) if ($user[$k][0] == $row_rstCheckoutDocList['docCheckedOutBy']) $checkedOutBy = $user[$k][1];
									?>
									<td class="revDocListTitleCheckedOut"><input name="checkoutDoc" type="radio" value="<?php echo $row_rstCheckoutDocList['doc_pk']; ?>" disabled="disabled">
										<a class="menuCheckedOut" href="#" title="<?php 
										if ($row_rstCheckoutDocList['docCheckedOutBy'] == $_SESSION['MM_Username'])
											echo 'This document is currently checked out to you';
										else	
											echo 'This document is currently checked out to '.$checkedOutBy; ?>"><?php echo $row_rstCheckoutDocList['docTitle']; ?>
										</a>
									</td>
									<td class="revDocListRevisionCheckedOut"><?php 
										if (!strcmp($row_rstCheckoutDocList['docRevision'],"")) 
											echo '-';
										else
											echo $row_rstCheckoutDocList['docRevision']; ?>
									</td>
									<td class="revDocListApplicationCheckedOut"><?php echo $row_rstCheckoutDocList['docApplication']; ?></td>
									<td class="revDocListOwnerCheckedOut"><?php echo $docOwner; ?></td>
									<td class="revDocListZoneCheckedOut"><?php echo $row_rstCheckoutDocList['zoneTitle']; ?></td>
									<?php 
									if ($row_rstCheckoutDocList['docFileType_id'] == 7 || $row_rstCheckoutDocList['docFileType_id'] == 8)
										echo '<td class="revDocListPasswordCheckedOut">---</td>';
									else if ($row_rstCheckoutDocList['docFileType_id'] == 2) 
										echo '<td class="revDocListPasswordNoneCheckedOut">Non-editable</td>';
									else echo '<td class="revDocListPasswordCheckedOut">'.$row_rstCheckoutDocList['docPassword'].'</td>';
									?>					
								<?php } ?>
							</tr>
							<?php } while ($row_rstCheckoutDocList = mysql_fetch_assoc($rstCheckoutDocList)); ?>
							<tr>
								<td class="revDocListTitle" colspan="6">
									<input name="checkoutButton" id="checkoutButton" type="submit" disabled="disabled" value="Checkout" />
								</td>							
							</tr>
							<input type="hidden" name="tab" id="tab" value="0" />
						</form>
					<?php } // end if ?>
				</table>
				<?php // Only show the navigation table if it is required
				if  ($totalRows_rstCheckoutDocList > $maxRows_rstCheckoutDocList) 
				{ ?>
					<table class="navigation">
						<tr>
							<td class="navigation">
								<a <?php 
									if ($pageNum_rstCheckoutDocList > 0) 
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstCheckoutDocList=%d%s%s", $currentPage, 0, $queryString_rstCheckoutDocList, '&tab=0'); ?>">First page</a>
							</td>
							<td class="navigation">
								<a <?php
									if ($pageNum_rstCheckoutDocList > 1) 
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstCheckoutDocList=%d%s%s", $currentPage, max(0, $pageNum_rstCheckoutDocList - 1), $queryString_rstCheckoutDocList, '&tab=0'); ?>">Previous page</a></td>
							<td class="navigation">navigation</td>
							<td class="navigation">
								<a <?php 
									if ($pageNum_rstCheckoutDocList < $totalPages_rstCheckoutDocList - 1)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstCheckoutDocList=%d%s%s", $currentPage, min($totalPages_rstCheckoutDocList, $pageNum_rstCheckoutDocList + 1), $queryString_rstCheckoutDocList, '&tab=0'); ?>">Next page</a> 
							</td>
							<td class="navigation">
								<a <?php 
									if ($pageNum_rstCheckoutDocList < $totalPages_rstCheckoutDocList)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstCheckoutDocList=%d%s%s", $currentPage, $totalPages_rstCheckoutDocList, $queryString_rstCheckoutDocList, '&tab=0'); ?>">Last page</a> 
							</td>
						</tr>
					</table>	
				<?php } ?>
			</div>		
			<div id="TabbedPanel2" class="TabbedPanelsContent">
				<h4 class="bold">Add a new revision of a document in your ownership</h4>
					<form enctype="multipart/form-data" action="upload.php" method="post" name="addRevisedDoc" id="addrevisedDoc">
						<input type="hidden" name="MAX_FILE_SIZE" value="25000000">
						<input type="hidden" name="fileSource" id="fileSource" value="RED" />
						<input type="hidden" name="docStatus" id="docStatus" value="Revised" />
						<table class="docList">
							<tr>
								<th class="addRevDocListTitle">Document title</th>
								<th class="addRevDocListRevision">New Revision</th>
								<th class="addRevDocListApplication">Application</th>
								<th class="addRevDocListZone">Zone</th>
								<th class="addRevDocListSector">Sector</th>
								<th class="addRevDocListPassword">Password</th>
							</tr>
							<?php 
							if ($totalRows_rstAddRevisedDocList == 0)
							{
								// Nothing is currently checked out to this person
								?>
								<tr>
									<td class="docNumbers" colspan="6">There are no documents in your ownership currently checked out for revision</td>
								</tr>
							<?php }
							else
							{ 
								do { ?>
								<tr>
									<td class="addRevDocListTitle">
										<input name="addRevisedRadio" id ="addRevisedRadio" type="radio" 
											value="<?php echo $row_rstAddRevisedDocList['doc_pk']; ?>"	
											onclick="$('#file').removeAttr('disabled'); $('#uploadFile').attr('disabled', 'disabled')" 
										/><?php echo ' '.$row_rstAddRevisedDocList['docTitle']; ?>
									</td>
									<td class="addRevDocListRevision"><?php echo $row_rstAddRevisedDocList['docRevision']; ?></td>
									<td class="addRevDocListApplication"><?php echo $row_rstAddRevisedDocList['docApplication']; ?></td>
									<td class="addRevDocListZone"><?php echo $row_rstAddRevisedDocList['zoneTitle']; ?></td>
									<td class="addRevDocListSector">
										<?php 
										if (!strcmp($row_rstAddRevisedDocList['sectorTitle'], "")) echo 'None';
										else echo $row_rstAddRevisedDocList['sectorTitle']; 
										?>
									</td>
									<?php 
									if ($row_rstAddRevisedDocList['docFileType_id'] == 7 || $row_rstAddRevisedDocList['docFileType_id'] == 8)
										echo '<td class="addRevDocListPassword">---</td>';
									else if ($row_rstAddRevisedDocList['docFileType_id'] == 2) 
										echo '<td class="addRevDocListPasswordNone">Non-editable</td>';
									else echo '<td class="addRevDocListPassword">'.$row_rstAddRevisedDocList['docPassword'].'</td>';
									?>
								</tr>
								<?php } while ($row_rstAddRevisedDocList = mysql_fetch_assoc($rstAddRevisedDocList)); ?>
								<tr>
									<td class="addRevDocListTitle" colspan="6">
									<input type="file" name="file" id="file" disabled="disabled" onclick="$('#uploadFile').removeAttr('disabled')" />
									<input name="uploadFile" id="uploadFile" type="submit" value="Upload" disabled="disabled" />
									</td>							
								</tr>
							<?php } // end else ?>
						</table>
						<input type="hidden" name="tab" id="tab" value="1" />
					</form>
					<?php // Only show the navigation table if it is required
					if  ($totalRows_rstAddRevisedDocList > $maxRows_rstAddRevisedDocList) 
					{ ?>
						<table class="navigation">
							<tr>
								<td class="navigation">
									<a <?php
									if ($pageNum_rstAddRevisedDocList > 0) 
											echo ' class="searchNavVisible" ';
										else
											echo ' class="searchNavInvisible" ';								
									?> href="<?php printf("%s?pageNum_rstAddRevisedDocList=%d%s%s", $currentPage, 0, $queryString_rstAddRevisedDocList, '&tab=1'); ?>">First page
									</a>
								</td>
								<td class="navigation">
									<a <?php
									if ($pageNum_rstAddRevisedDocList > 1) 
											echo ' class="searchNavVisible" ';
										else
											echo ' class="searchNavInvisible" ';
									?> href="<?php printf("%s?pageNum_rstAddRevisedDocList=%d%s%s", $currentPage, max(0, $pageNum_rstAddRevisedDocList - 1), $queryString_rstAddRevisedDocList, '&tab=1'); ?>">Previous page
									</a>
								</td>
								<td class="navigation">navigation</td>
								<td class="navigation">
									<a <?php 
									if ($pageNum_rstAddRevisedDocList < $totalPages_rstAddRevisedDocList - 1)
											echo ' class="searchNavVisible" ';
										else
											echo ' class="searchNavInvisible" ';								
									?> href="<?php printf("%s?pageNum_rstAddRevisedDocList=%d%s%s", $currentPage, min($totalPages_rstAddRevisedDocList, $pageNum_rstAddRevisedDocList + 1), $queryString_rstAddRevisedDocList, '&tab=1'); ?>">Next page
									</a>
								</td>
								<td class="navigation">
									<a <?php 
									if ($pageNum_rstAddRevisedDocList < $totalPages_rstAddRevisedDocList)
											echo ' class="searchNavVisible" ';
										else
											echo ' class="searchNavInvisible" ';
									?>href="<?php printf("%s?pageNum_rstAddRevisedDocList=%d%s%s", $currentPage, $totalPages_rstAddRevisedDocList, $queryString_rstAddRevisedDocList, '&tab=1'); ?>">Last page
									</a>
								</td>
							</tr>
						</table>	
					<?php } ?>
				</div>
			<div id="TabbedPanel3" class="TabbedPanelsContent">
				<h4 class="bold">Add a new document to the intranet</h4>
				<form enctype="multipart/form-data" action="upload.php" method="post" name="addDocForm" id="addDocForm">
					<input type="hidden" name="MAX_FILE_SIZE" value="25000000">
					<input type="hidden" name="fileSource" id="fileSource" value="RED" />
					<input type="hidden" name="docStatus" id="docStatus" value="New" />
					<?php
					// Generate a random password
					$password = generatePassword(8);
					?>
					<table class="addDoc">					
						<tr>
							<td class="addDocListHeader">Document Title (10-128 characters)</td>
							<td class="addDocListTitle" colspan="4">
								<span id="sprytextfield1">
									<input name="docTitle" id="docTitle" type="text" class="title" maxlength="128" tabindex=1 />
									<span class="textfieldRequiredMsg">The document must have a title</span>
									<span class="textfieldMinCharsMsg">The title length must be at least 10 characters</span>
									<span class="textfieldMaxCharsMsg">The title length cannot exceed 128 characters</span>
								</span>
							</td>
							<td class="fifteen">&nbsp;</td>
						</tr>
						<tr>
							<td class="addDocListHeader">PMS Zone / Admin Group</td>
							<td class="addDocListZone" colspan="2">
								<span id="spryselect1">
									<select name="docZoneID" id="docZoneID" class="selectZone" tabindex=2>
										<option value="0">Select a PMS Zone...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstPMSZones['zone_pk']; ?>"><?php echo $row_rstPMSZones['zoneTitle']; ?></option>
										<?php } while ($row_rstPMSZones = mysql_fetch_assoc($rstPMSZones)); ?>
									</select>
									<span class="selectInvalidMsg">Please select a PMS zone for the document</span>
									<span class="selectRequiredMsg">Please select a PMS zone for the document</span>
								</span>
							</td>
							<td class="addDocListAdminGroup" colspan="2">
								<span id="spryselect2">
									<select name="adminGroupID" id="adminGroupID" class="selectAdminGroup" tabindex=3>
										<option value="0">Select an admin group...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstAdminGroups['adminGroup_pk']; ?>"><?php echo $row_rstAdminGroups['agMembers']; ?></option>
										<?php } while ($row_rstAdminGroups = mysql_fetch_assoc($rstAdminGroups)); ?>
									</select>
									<span class="selectInvalidMsg">Please select an administration group responsible for the document</span>
									<span class="selectRequiredMsg">Please select an administration group responsible for the document</span>
								</span>
							</td>
							<td class="fifteen">&nbsp;</td>
						</tr>
						<tr>
							<td class="addDocListHeader">Document Type / Subject</td>
							<td class="addDocListDocType" colspan="2">
								<span id="spryselect3">
									<select name="docTypeID" id="docTypeID" class="selectDocType" tabindex=4>
										<option value="0">Select a Document Type...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstDocumentType['docType_pk']; ?>"><?php echo $row_rstDocumentType['docType']; ?></option>
										<?php } while ($row_rstDocumentType = mysql_fetch_assoc($rstDocumentType)); ?>
									</select>
									<span class="selectInvalidMsg">Please select a document type</span>
									<span class="selectRequiredMsg">Please select a document type</span>
								</span>
							</td>
							<td class="addDocListDocSubject" colspan="2">
								<span id="spryselect4">
									<select name="docSubjectID" id="docSubjectID" class="selectDocSubject" tabindex=5>
										<option value="0">Select a Document Subject...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstDocumentSubject['docSubjectRED_pk']; ?>"><?php echo $row_rstDocumentSubject['docSubjectRED']; ?></option>
										<?php } while ($row_rstDocumentSubject = mysql_fetch_assoc($rstDocumentSubject)); ?>
									</select>
									<span class="selectInvalidMsg">Please select a document subject</span>
									<span class="selectRequiredMsg">Please select a document subject</span>
								</span>
							</td>
							<td class="fifteen">&nbsp;</td>
						</tr>
						<tr>
							<td class="addDocListHeader">Relevant Office(s) / Listing</td>
							<td class="addDocListDocType" colspan="2">
								<span id="spryselect5">
									<select name="officeID" id="officeID" class="selectOffice" tabindex=6>
										<option value="0">Select relevant office(s)...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstOffices['office_pk']; ?>"><?php echo $row_rstOffices['location']; ?></option>
										<?php } while ($row_rstOffices = mysql_fetch_assoc($rstOffices)); ?>
									</select>
									<span class="selectInvalidMsg">Please select which office(s) the document relates to</span>
									<span class="selectRequiredMsg">Please select which office(s) the document relates to</span>
								</span>
							</td>
							<td class="addDocListDocListing" colspan="2">
								<span id="spryselect6">
									<select name="docListingID" id="docListingID" class="selectListing" tabindex=7>
										<option value="0">Select document listing...</option>
										<?php do { ?>
											<option value="<?php echo $row_rstDocListing['docListing_pk']; ?>"><?php echo $row_rstDocListing['docListingTitle']; ?></option>
										<?php } while ($row_rstDocListing = mysql_fetch_assoc($rstDocListing)); ?>
									</select>
									<span class="selectInvalidMsg">Please select the person(s) who will be able to download/view the document</span>
									<span class="selectRequiredMsg">Please select the person(s) who will be able to download/view the document</span>
								</span>
							</td>
						</tr>
						<tr>
							<td class="addDocListHeader">Relevant business sector</td>
							<td class="addDocListSector">
								<input class="sector" name="docSectorID" id="docSectorID" type="radio" checked="checked" value="1"  tabindex=8 />None
							</td>
						</tr>
						<?php
						if ($row_rstUserSector1['isDirector'] == 1)
						{ ?>
						<tr>
							<td class="addDocListHeader">&nbsp;</td>
							<?php
							if ($row_rstUserSector1['director_sector1_id'] > 0)
							{ ?>
								<td class="addDocListSector">
									<input class="sector" name="docSectorID" id="docSectorID" type="radio" tabindex=9
										value="<?php echo $row_rstUserSector1['director_sector1_id']; ?>" /><?php echo $row_rstUserSector1['sectorTitle']; ?>
								</td>
								<?php 
								if ($row_rstUserSector2['director_sector2_id'] > 0) 
								{ ?>
									<td class="addDocListSector">
										<input class="sector" name="docSectorID" id="docSectorID" type="radio" tabindex=10
											value="<?php echo $row_rstUserSector2['director_sector2_id']; ?>" /><?php echo $row_rstUserSector2['sectorTitle']; ?>
									</td>
									<?php								
									if ($row_rstUserSector3['director_sector3_id'] > 0) 
									{ ?>
										<td class="addDocListSector">
											<input class="sector" name="docSectorID" id="docSectorID" type="radio" tabindex=11 
												value="<?php echo $row_rstUserSector3['director_sector3_id']; ?>" /><?php echo $row_rstUserSector3['sectorTitle']; ?>
										</td>
										<?php								
										if ($row_rstUserSector4['director_sector4_id'] > 0) 
										{ ?>
											<td class="addDocListSector">
											<input class="sector" name="docSectorID" id="docSectorID" type="radio" tabindex=12 
												value="<?php echo $row_rstUserSector4['director_sector4_id']; ?>" /><?php echo $row_rstUserSector4['sectorTitle']; ?>
											</td>
											<?php								
											if ($row_rstUserSector5['director_sector5_id'] > 0) 
											{ ?>
												<td class="addDocListSector">
												<input class="sector" name="docSectorID" id="docSectorID" type="radio" tabindex=13 
													value="<?php echo $row_rstUserSector5['director_sector5_id']; ?>" /><?php echo $row_rstUserSector5['sectorTitle']; ?>
												</td>
											<?php }
											else
											{ ?>
												<td class="fifteen">&nbsp;</td>
											<?php }
										}
										else
										{ ?>
										<td class="thirty" colspan="2">&nbsp;</td>
										<?php }
									}
									else
									{ ?>
										<td class="fortyFive" colspan="3">&nbsp;</td>
									<?php }
								}
								else
								{ ?>
									<td class="sixty" colspan="4">&nbsp;</td>
								<?php }
							}
							else
							{ ?>
								<td class="seventyFive" colspan="5">&nbsp;</td>
							<?php }
						} ?>
						</tr>
						<tr>
							<td class="addDocListHeader">Password</td>
							<td class="addDocListPassword">
								<input name="pw" id="pw" class="pw" type="text" size="25" maxlength="8" readonly="true" value="<?php echo $password; ?>"/>
							</td>
							<td class="sixty" colspan="4">&nbsp;</td>
						</tr>
						<tr>
							<td class="addDocListHeader">Select the file to upload</td>
							<td class="addDocListFile" colspan="2"><input class="file" name="file" id="file" type="file" tabindex=14 
								onclick="$('#uploadFile').removeAttr('disabled')"/>
							</td>
							<td class="fortyFive" colspan="3">&nbsp;</td>
						</tr>
						<tr>
							<td class="addDocListHeader">&nbsp;</td>
							<td class="addDocListUpload" colspan="2">
								<input name="uploadFile" id="uploadFile" type="submit" value="Upload" disabled="disabled" />
							</td>
							<td class="fortyFive" colspan="3">&nbsp;</td>
						</tr>	
					</table>
					<input type="hidden" name="tab" id="tab" value="4" />
				</form>
			</div>
			<div id="TabbedPanel4" class="TabbedPanelsContent">
				<h4 class="bold">Set the visibility of documents in your ownership</h4>
				<table class="docList">
					<tr>
						<th class="visDocListTitle">Document title</th>
						<th class="visDocListRevision">Revision</th>
						<th class="visDocListZone">PMS Zone</th>
					</tr>
					<?php
					if ($totalRows_rstVisDocList == 0)
					{
						// Nothing is currently owned by this person
						?>
						<tr>
							<td class="docNumbers" colspan="3">
								<span style="color: #900;">There are no documents currently in your ownership</span>
							</td>
						</tr>
					<?php }
					else
					{ ?>
					<tr>
						<td class="docNumbers" colspan="3">
						<?php 
							if ($totalRows_rstVisDocList == 1) 
								echo 'There is one document';
							else 
								echo 'There are '.$totalRows_rstVisDocList.' documents';
							echo ' currently in your ownership';
							if ($totalRows_rstVisDocList > $maxRows_rstVisDocList)
							{
								if (min($startRow_rstVisDocList + $maxRows_rstVisDocList, $totalRows_rstVisDocList) == $totalRows_rstVisDocList) echo '.  Showing final document(s) in results set.';
								else echo '. Showing documents '.($startRow_rstVisDocList + 1).' to '.min($startRow_rstVisDocList + $maxRows_rstVisDocList, $totalRows_rstVisDocList).'.';
							}
						?>
						</td>
					</tr>
					<form method="post" name="setDocVisibility" id="setDocVisibility">
						<?php 
						do 
						{ ?>
							<tr>
								<td class="visDocListTitle">
									<input type="checkbox" name="checkbox[]" id="checkbox"
										<?php if ($row_rstVisDocList['docVisible'] == 1) echo 'checked="checked"'; ?>
										onclick="$('#setVisButton').removeAttr('disabled').addClass('boldRed');"
										value="<?php echo $row_rstVisDocList['doc_pk']; ?>"
									/>
									<?php echo $row_rstVisDocList['docTitle']; ?>
								</td>
								<td class="visDocListRevision"><?php
								if (!strcmp($row_rstVisDocList['docRevision'],"")) 
									echo '-';
								else
									echo $row_rstVisDocList['docRevision']; ?></td>
								<td class="visDocListZone"><?php echo $row_rstVisDocList['zoneTitle']; ?></td>
							</tr>
						<?php } while ($row_rstVisDocList = mysql_fetch_assoc($rstVisDocList)); 
						?>
						<tr>
							<td class="visDocListTitle" colspan="4">
								<input name="setVisButton" id="setVisButton" type="submit" disabled="disabled" value="Update" />
							</td>							
						</tr>
						<input type="hidden" name="tab" id="tab" value="2" />
					</form>
					<?php } 
					// Manually update the database - THIS DOES NOT WORK AT PRESENT BECAUSE OF NEED TO GET CHECKBOX ID AND VALUE FOR CHECKED AND UNCHECKED BOXES
					/*
					if (isset($_POST['setVisButton']))
					{
						// Create an array of user names to use in finding persons who have checked out documents
						//@ $db = new mysqli('localhost', 'kcalder', 'kC->RED%zERO', 'intranet');
						@ $db = new mysqli('localhost', 'root', 'hpfHPF840', 'intranet');
						if (!$db) die ('Could not connect to the database: '.mysql_error());
						// Update the database with all 
						foreach($_POST['checkbox'] as $id)
						{
							$query = sprintf("UPDATE document SET docVisible=%d WHERE doc_pk=%s", $checked, $id);
							$result = $db->query($query);
						}
					}
					*/
					?>
				</table>
				<?php // Only show the navigation table if it is required
				if  ($totalRows_rstVisDocList > $maxRows_rstVisDocList) 
				{ ?>
					<table class="navigation">
						<tr>
							<td class="navigation">
								<a <?php
									if ($pageNum_rstVisDocList > 0)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';	
								?> href="<?php printf("%s?pageNum_rstVisDocList=%d%s%s", $currentPage, 0, $queryString_rstVisDocList, '&tab=2'); ?>">First page
								</a>
							</td>
							<td class="navigation">
								<a <?php
									if ($pageNum_rstVisDocList > 1)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';	
								?> href="<?php printf("%s?pageNum_rstVisDocList=%d%s%s", $currentPage, max(0, $pageNum_rstVisDocList - 1), $queryString_rstVisDocList, '&tab=2'); ?>">Previous page
								</a>
							</td>
							<td class="navigation">navigation</td>
							<td class="navigation">
								<a <?php
									if ($pageNum_rstVisDocList < $totalPages_rstVisDocList - 1)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';	
								?> href="<?php printf("%s?pageNum_rstVisDocList=%d%s%s", $currentPage, min($totalPages_rstVisDocList, $pageNum_rstVisDocList + 1), $queryString_rstVisDocList, '&tab=2'); ?>">Next page
								</a>
							</td>
							<td class="navigation">
								<a <?php 
									if ($pageNum_rstVisDocList < $totalPages_rstVisDocList)
										echo ' class="searchNavVisible" ';
									else
										echo ' class="searchNavInvisible" ';								
								?> href="<?php printf("%s?pageNum_rstVisDocList=%d%s%s", $currentPage, $totalPages_rstVisDocList, $queryString_rstVisDocList, '&tab=2'); ?>">Last page
								</a>
							</td>
						</tr>
					</table>	
				<?php } ?>		
			</div>
			<div id="TabbedPanel5" class="TabbedPanelsContent">
				<h4 class="bold">Retrieve a superseded document from the archive</h4>
				<form action="../common/php/download.php" name="downloadForm" id="downloadForm" method="get">
				<table class="docList">
					<tr>
						<th class="arcDocListTitle">Document title</th>
						<th class="arcDocListRevision">Revision</th>
						<th class="arcDocListApplication">Application</th>
						<th class="arcDocListZone">PMS Zone</th>
					</tr>
					<?php 
					if ($totalRows_rstArchivedDocList == 0)
					{
						// There is nothing available to this user is in the archive
						?>
						<tr>
							<td class="addRevDocListTitle" colspan="6">
								<span style="color: #900;">There are no archived documents either owned by you or associated with your administration group(s)</span>
							</td>
						</tr>
					<?php }
					else
					{ ?>
						<?php do { ?>
						<tr>
							<td class="arcDocListTitle">
								<?php 
								$fileName = 'ARCHIVE - ';
								if (!strcmp($row_rstArchivedDocList['docRevision'],"")) 
									$fileName .= $row_rstArchivedDocList['docTitle'].'.'.$row_rstArchivedDocList['docFileType'];
								else
									$fileName .= $row_rstArchivedDocList['docTitle'].' - Revision '.$row_rstArchivedDocList['docRevision'].'.'.$row_rstArchivedDocList['docFileType']; 
									?>
								<a class="menu" href="../common/php/download.php?s=RED&c=Archive&f=<?php echo $fileName; ?>&fc=<?php echo $fileName; ?>" 
									title="<?php echo 'Click to download this document' ?>">
									<?php 
										if (!strcmp($row_rstArchivedDocList['docRevision'],"")) 
											echo $row_rstArchivedDocList['docTitle'];
										else
											echo $row_rstArchivedDocList['docTitle'].' - Revision '.$row_rstArchivedDocList['docRevision'];
									?>
								</a>
							</td>
							<td class="arcDocListRevision"><?php 
								if (!strcmp($row_rstArchivedDocList['docRevision'],"")) 
									echo '-';
								else
									echo $row_rstArchivedDocList['docRevision']; ?>
							</td>
							<td class="arcDocListApplication"><?php echo $row_rstArchivedDocList['docApplication']; ?></td>
							<td class="arcDocListZone"><?php echo $row_rstArchivedDocList['zoneTitle']; ?></td>
						</tr>
						<?php } while ($row_rstArchivedDocList = mysql_fetch_assoc($rstArchivedDocList)); ?>
					<?php } ?>
				</table>
				<input type="hidden" name="tab" id="tab" value="5" />
			</form>
			<?php // Only show the navigation table if it is required
				if  ($totalRows_rstArchivedDocList > $maxRows_rstArchivedDocList) 
				{ ?>
					<table class="navigation">
						<tr>
							<td class="navigation">
								<a <?php
								if ($pageNum_rstArchivedDocList > 0) 
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';			
								?> href="<?php printf("%s?pageNum_rstArchivedDocList=%d%s%s", $currentPage, 0, $queryString_rstArchivedDocList, '&tab=4'); ?>">First page
								</a>
							</td>
							<td class="navigation">
								<a <?php
								if ($pageNum_rstArchivedDocList > 1) 
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstArchivedDocList=%d%s%s", $currentPage, max(0, $pageNum_rstArchivedDocList - 1), $queryString_rstArchivedDocList, '&tab=4'); ?>">Previous page
								</a>
							</td>
							<td class="navigation">navigation</td>
							<td class="navigation">
								<a <?php
								if ($pageNum_rstArchivedDocList < $totalPages_rstArchivedDocList - 1)
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';				
								?> href="<?php printf("%s?pageNum_rstArchivedDocList=%d%s%s", $currentPage, min($totalPages_rstArchivedDocList, $pageNum_rstArchivedDocList + 1), $queryString_rstArchivedDocList, '&tab=4'); ?>">Next page
								</a>
							</td>
							<td class="navigation">
								<a <?php
								if ($pageNum_rstArchivedDocList < $totalPages_rstArchivedDocList)
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstArchivedDocList=%d%s%s", $currentPage, $totalPages_rstArchivedDocList, $queryString_rstArchivedDocList, '&tab=4'); ?>">Last page
								</a>
							</td>
						</tr>
					</table>	
				<?php } ?>	
			</div>	
			<div id="TabbedPanel6" class="TabbedPanelsContent">
				<h4 class="bold">Delete a document in your ownership</h4>
				<table class="docList">
					<tr>
						<th class="delDocListTitle">Document title</th>
						<th class="delDocListRevision">Revision</th>
						<th class="delDocListZone">PMS Zone</th>
					</tr>
					<tr>
					<?php
					if ($totalRows_rstDelDocList == 0)
					{
						// Nothing is currently owned by this person
						?>
						<tr>
							<td class="docNumbers" colspan="3">
								<span style="color: #900;">There are no documents currently in your ownership</span>
							</td>
						</tr>
					<?php }
					else
					{ ?>
						<tr>
							<td class="docNumbers" colspan="3">
							<?php 
								if ($totalRows_rstDelDocList == 1) echo 'There is one document';
								else echo 'There are '.$totalRows_rstDelDocList.' documents';
								echo ' currently in your ownership';
								if ($totalRows_rstDelDocList > $maxRows_rstDelDocList)
								{
									if (min($startRow_rstDelDocList + $maxRows_rstDelDocList, $totalRows_rstDelDocList) == $totalRows_rstDelDocList) echo '.  Showing final document(s) in results set.';
									else echo '. Showing documents '.($startRow_rstDelDocList + 1).' to '.min($startRow_rstDelDocList + $maxRows_rstDelDocList, $totalRows_rstDelDocList).'.';
								}
							?>
							</td>
						</tr>
						<form action="mgtRED.php" method="post" name="delDoc" id="delDoc">
							<?php do { ?>
								<tr>
									<td class="delDocListTitle">
										<input name="deleteRadio" id="deleteRadio" type="radio" 
											onclick="$('#confirm').addClass('noShow');
													 $('#delete').removeAttr('disabled').addClass('boldRed');"
										value="<?php echo $row_rstDelDocList['doc_pk']; ?>" />
										<?php echo $row_rstDelDocList['docTitle']; ?>
									</td>
									<td class="delDocListRevision"><?php
										if (!strcmp($row_rstDelDocList['docRevision'],"")) 
											echo '-';
										else
											echo $row_rstDelDocList['docRevision']; ?>
									</td>
									<td class="delDocListZone"><?php echo $row_rstDelDocList['zoneTitle']; ?></td>
								</tr>
								<input type="hidden" name="fileName" id="fileName" value="<?php echo $row_rstDelDocList['fileName'].'.'.$row_rstDelDocList['fileType']; ?>" />
								<input type="hidden" name="title" id="title" value="<?php echo $row_rstDelDocList['docTitle']; ?>" />
								<input type="hidden" name="revision" id="revision" value="<?php echo $row_rstDelDocList['docRevision']; ?>" />
							<?php } while ($row_rstDelDocList = mysql_fetch_assoc($rstDelDocList)); ?>
							<tr>
								<td class="delDocListTitle" colspan="3">
									<input name="delete" id="delete" type="button" disabled="disabled" value="Delete" />
									<input name="confirm" id="confirm" type="submit" value="Confirm" class="noShow" />
								</td>							
							</tr>
							<input type="hidden" name="tab" id="tab" value="5" />
						</form>
						<?php
						if (isset($_POST['confirm']))
						{
							$currentFile = $_POST['fileName'];
							$newFile = 'DELETED - '.$_POST['title'].' Revision - '.$_POST['revision'];
							dropFile($currentFile, $newFile);
						}
					} ?>
				</table>
				<?php // Only show the navigation table if it is required
				if  ($totalRows_rstDelDocList > $maxRows_rstDelDocList) 
				{ ?>
					<table class="navigation">
						<tr>
							<td class="navigation">
								<a <?php 
								if ($pageNum_rstDelDocList > 0) 
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';	
								?> href="<?php printf("%s?pageNum_rstDelDocList=%d%s%s", $currentPage, 0, $queryString_rstDelDocList, '&tab=5'); ?>">First page
								</a>
							</td>
							<td class="navigation">
								<a <?php 
								if ($pageNum_rstDelDocList > 1) 
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstDelDocList=%d%s%s", $currentPage, max(0, $pageNum_rstDelDocList - 1), $queryString_rstDelDocList, '&tab=5'); ?>">Previous page
								</a>
							</td>
							<td class="navigation">navigation</td>
							<td class="navigation">
								<a <?php 
								if ($pageNum_rstDelDocList < $totalPages_rstDelDocList - 1)
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';				
								?> href="<?php printf("%s?pageNum_rstDelDocList=%d%s%s", $currentPage, min($totalPages_rstDelDocList, $pageNum_rstDelDocList + 1), $queryString_rstDelDocList, '&tab=5'); ?>">Next page
								</a>
							</td>
							<td class="navigation">
								<a <?php
								if ($pageNum_rstDelDocList < $totalPages_rstDelDocList)
									echo ' class="searchNavVisible" ';
								else
									echo ' class="searchNavInvisible" ';
								?> href="<?php printf("%s?pageNum_rstDelDocList=%d%s%s", $currentPage, $totalPages_rstDelDocList, $queryString_rstDelDocList, '&tab=5'); ?>">Last page
								</a>
							</td>
						</tr>
					</table>	
				<?php } ?>		
			</div>
			<div id="TabbedPanel7" class="TabbedPanelsContent">
			<div id="Accordion1" class="Accordion">
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Checkout</div>
							<div class="AccordionPanelContent"> 
								<?php echo $row_rstHelpTextCheckout['helpText']; ?> 
							</div>
					</div>
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Add Revised</div>
							<div class="AccordionPanelContent">
								<?php echo $row_rstHelpTextAddRevised['helpText']; ?>
							</div>
					</div>
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Set Visibility</div>
							<div class="AccordionPanelContent">
								<?php echo $row_rstHelpTextVisibility['helpText']; ?>
							</div>
					</div>
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Add New</div>
							<div class="AccordionPanelContent">
								<?php echo $row_rstHelpTextAddNew['helpText']; ?>
							</div>
					</div>
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Retrieve from Archive</div>
							<div class="AccordionPanelContent">
								<?php echo $row_rstHelpTextArchive['helpText']; ?>
							</div>
					</div>
					<div class="AccordionPanel">
							<div class="AccordionPanelTab">Drop from Database</div>
							<div class="AccordionPanelContent">
								<?php echo $row_rstHelpTextDrop['helpText']; ?>
							</div>
					</div>
			</div>
		</div>
	</div> <?php // end TabbedPanels1 ?>
</div>
<p><a class="generalPageNav" href="../menu.php">Main menu</a></p>
<p><a class="generalPageNav" href="<?php echo $logoutAction ?>">Log out</a></p>
</div><!-- content -->
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: <?php echo $tab; ?>  });
var Accordion1 = new Spry.Widget.Accordion("Accordion1");
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {minChars:10, maxChars:128, validateOn:["blur"]});
var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {invalidValue:"0", validateOn:["change"]});
var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {invalidValue:"0", validateOn:["change"]});
var spryselect3 = new Spry.Widget.ValidationSelect("spryselect3", {invalidValue:"0", validateOn:["change"]});
var spryselect4 = new Spry.Widget.ValidationSelect("spryselect4", {invalidValue:"0", validateOn:["change"]});
var spryselect5 = new Spry.Widget.ValidationSelect("spryselect5", {invalidValue:"0", validateOn:["change"]});
var spryselect6 = new Spry.Widget.ValidationSelect("spryselect6", {invalidValue:"0", validateOn:["change"]});
//-->
</script>
<?php 
	// If the file has successfully uploaded then notify the user
	if ($_SESSION['fileUploadStatus'] == true)
	{ 
		echo '<script language="javascript" type="text/javascript">';
		echo 'alert("The file was added and is now visible on the Intranet")'; 
		echo '</script>';
		// Reset the session flag
		$_SESSION['fileUploadStatus'] = false;
	}
?>
</body>
</html>
<?php
mysql_free_result($rstCheckoutDocList);
mysql_free_result($rstZoneHelp);
mysql_free_result($rstDocOwner);
mysql_free_result($rstDocOwnerList);
mysql_free_result($rstAddRevisedDocList);
mysql_free_result($rstUserSector1);
mysql_free_result($rstUserSector2);
mysql_free_result($rstUserSector3);
mysql_free_result($rstUserSector4);
mysql_free_result($rstUserSector5);
mysql_free_result($rstDelDocList);
mysql_free_result($rstDownloadFile);
mysql_free_result($rstHelpTextCheckout);
mysql_free_result($rstArchivedDocList);
mysql_free_result($rstHelpTextAddRevised);
mysql_free_result($rstHelpTextAddNew);
mysql_free_result($rstHelpTextDrop);
mysql_free_result($rstHelpTextArchive);
mysql_free_result($rstAdminGroups);
mysql_free_result($rstPMSZones);
mysql_free_result($rstDocumentType);
mysql_free_result($rstDocumentSubject);
mysql_free_result($rstOffices);
mysql_free_result($rstVisDocList);
mysql_free_result($rstHelpTextVisibility);
mysql_free_result($rstDocListing);
?>
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
723:
724:
725:
726:
727:
728:
729:
730:
731:
732:
733:
734:
735:
736:
737:
738:
739:
740:
741:
742:
743:
744:
745:
746:
747:
748:
749:
750:
751:
752:
753:
754:
755:
756:
757:
758:
759:
760:
761:
762:
763:
764:
765:
766:
767:
768:
769:
770:
771:
772:
773:
774:
775:
776:
777:
778:
779:
780:
781:
782:
783:
784:
785:
786:
787:
788:
789:
790:
791:
792:
793:
794:
795:
796:
797:
798:
799:
800:
801:
802:
803:
804:
805:
806:
807:
808:
809:
810:
811:
812:
813:
814:
815:
816:
817:
818:
819:
820:
821:
822:
823:
824:
825:
826:
827:
828:
829:
830:
831:
832:
833:
834:
835:
836:
837:
838:
839:
840:
841:
842:
843:
844:
845:
846:
847:
848:
849:
850:
851:
852:
853:
854:
855:
856:
857:
858:
859:
860:
861:
862:
863:
864:
865:
866:
867:
868:
869:
870:
871:
872:
873:
874:
875:
876:
877:
878:
879:
880:
881:
882:
883:
884:
885:
886:
887:
888:
889:
890:
891:
892:
893:
894:
895:
896:
897:
898:
899:
900:
901:
902:
903:
904:
905:
906:
907:
908:
909:
910:
911:
912:
913:
914:
915:
916:
917:
918:
919:
920:
921:
922:
923:
924:
925:
926:
927:
928:
929:
930:
931:
932:
933:
934:
935:
936:
937:
938:
939:
940:
941:
942:
943:
944:
945:
946:
947:
948:
949:
950:
951:
952:
953:
954:
955:
956:
957:
958:
959:
960:
961:
962:
963:
964:
965:
966:
967:
968:
969:
970:
971:
972:
973:
974:
975:
976:
977:
978:
979:
980:
981:
982:
983:
984:
985:
986:
987:
988:
989:
990:
991:
992:
993:
994:
995:
996:
997:
998:
999:
1000:
1001:
1002:
1003:
1004:
1005:
1006:
1007:
1008:
1009:
1010:
1011:
1012:
1013:
1014:
1015:
1016:
1017:
1018:
1019:
1020:
1021:
1022:
1023:
1024:
1025:
1026:
1027:
1028:
1029:
1030:
1031:
1032:
1033:
1034:
1035:
1036:
1037:
1038:
1039:
1040:
1041:
1042:
1043:
1044:
1045:
1046:
1047:
1048:
1049:
1050:
1051:
1052:
1053:
1054:
1055:
1056:
1057:
1058:
1059:
1060:
1061:
1062:
1063:
1064:
1065:
1066:
1067:
1068:
1069:
1070:
1071:
1072:
1073:
1074:
1075:
1076:
1077:
1078:
1079:
1080:
1081:
1082:
1083:
1084:
1085:
1086:
1087:
1088:
1089:
1090:
1091:
1092:
1093:
1094:
1095:
1096:
1097:
1098:
1099:
1100:
1101:
1102:
1103:
1104:
1105:
1106:
1107:
1108:
1109:
1110:
1111:
1112:
1113:
1114:
1115:
1116:
1117:
1118:
1119:
1120:
1121:
1122:
1123:
1124:
1125:
1126:
1127:
1128:
1129:
1130:
1131:
1132:
1133:
1134:
1135:
1136:
1137:
1138:
1139:
1140:
1141:
1142:
1143:
1144:
1145:
1146:
1147:
1148:
1149:
1150:
1151:
1152:
1153:
1154:
1155:
1156:
1157:
1158:
1159:
1160:
1161:
1162:
1163:
1164:
1165:
1166:
1167:
1168:
1169:
1170:
1171:
1172:
1173:
1174:
1175:
1176:
1177:
1178:
1179:
1180:
1181:
1182:
1183:
1184:
1185:
1186:
1187:
1188:
1189:
1190:
1191:
1192:
1193:
1194:
1195:
1196:
1197:
1198:
1199:
1200:
1201:
1202:
1203:
1204:
1205:
1206:
1207:
1208:
1209:
1210:
1211:
1212:
1213:
1214:
1215:
1216:
1217:
1218:
1219:
1220:
1221:
1222:
1223:
1224:
1225:
1226:
1227:
1228:
1229:
1230:
1231:
1232:
1233:
1234:
1235:
1236:
1237:
1238:
1239:
1240:
1241:
1242:
1243:
1244:
1245:
1246:
1247:
1248:
1249:
1250:
1251:
1252:
1253:
1254:
1255:
1256:
1257:
1258:
1259:
1260:
1261:
1262:
1263:
1264:
1265:
1266:
1267:
1268:
1269:
1270:
1271:
1272:
1273:
1274:
1275:
1276:
1277:
1278:
1279:
1280:
1281:
1282:
1283:
1284:
1285:
1286:
1287:
1288:
1289:
1290:
1291:
1292:
1293:
1294:
1295:
1296:
1297:
1298:
1299:
1300:
1301:
1302:
1303:
1304:
1305:
1306:
1307:
1308:
1309:
1310:
1311:
1312:
1313:
1314:
1315:
1316:
1317:
1318:
1319:
1320:
1321:
1322:
1323:
1324:
1325:
1326:
1327:
1328:
1329:
1330:
1331:
1332:
1333:
1334:
1335:
1336:
1337:
1338:
1339:
1340:
1341:
1342:
1343:
1344:
1345:
1346:
1347:
1348:
1349:
1350:
1351:
1352:
1353:
1354:
1355:
1356:
1357:
1358:
1359:
1360:
1361:
1362:
1363:
1364:
1365:
1366:
1367:
1368:
1369:
1370:
1371:
1372:
1373:
1374:
1375:
1376:
1377:
1378:
1379:
1380:
1381:
1382:
1383:
1384:
1385:
1386:
1387:
1388:
1389:
1390:
1391:
1392:
1393:
1394:
1395:
1396:
1397:
1398:
1399:
1400:
1401:
1402:
1403:
1404:
1405:
1406:
1407:
1408:
1409:
1410:
1411:
1412:
1413:
1414:
1415:
1416:
1417:
1418:
1419:
1420:
1421:
1422:
1423:
1424:
1425:
1426:
1427:
1428:
1429:
1430:
1431:
1432:
1433:
1434:
1435:
1436:
1437:
1438:
1439:
1440:
1441:
1442:
1443:
1444:
1445:
1446:
1447:
1448:
1449:
1450:
1451:
1452:
1453:
1454:
1455:
1456:
1457:
1458:
1459:
1460:
1461:
1462:
1463:
1464:
1465:
1466:
1467:
1468:
1469:
1470:
1471:
1472:
1473:
1474:
1475:
1476:
1477:
1478:
1479:
1480:
1481:
1482:
1483:
1484:
1485:
1486:
1487:
1488:
1489:
1490:
1491:
1492:
1493:
1494:
1495:
1496:
1497:
1498:
1499:
1500:
1501:
1502:
1503:
1504:
1505:
1506:
1507:
1508:
1509:
1510:
1511:
1512:
1513:
1514:
1515:
1516:
1517:
1518:
1519:
1520:
1521:
1522:
1523:
1524:
1525:
1526:
1527:
1528:
1529:
1530:
1531:
1532:
1533:
1534:
1535:
1536:
1537:
1538:
1539:
1540:
1541:
1542:
1543:
1544:
1545:
1546:
1547:
1548:
1549:
1550:
1551:
1552:
1553:
1554:
1555:
1556:
1557:
1558:
1559:
1560:
1561:
1562:
1563:
1564:
1565:
1566:
1567:
1568:
1569:
1570:
1571:
1572:
1573:
1574:
1575:
1576:
1577:
1578:
1579:
1580:
1581:
1582:
1583:
1584:
1585:
1586:
1587:
1588:
1589:
1590:
1591:
1592:
1593:
1594:
1595:
1596:
1597:
1598:
1599:
1600:
1601:
1602:
1603:
1604:
1605:
1606:
1607:
1608:
1609:
1610:
1611:
1612:
1613:
1614:
1615:
1616:
1617:
1618:
1619:
1620:
1621:
1622:
1623:

Select allOpen in new window

 

by: kcalderPosted on 2009-09-09 at 11:44:31ID: 25294281

I have no intention of having anything like the full page code debugged, it doesn't need it. 99% of the page works very nicely. I am simply having difficulty with getting the checkbox routine working and that's what I needed help with. I appreciate you taking the time to provide me with some snippets and I'll work at trying to integrate the principles you have shown. Thanks.

 

by: kcalderPosted on 2009-09-09 at 11:49:16ID: 31626764

I have not managed to translate the code snippet based on a manual loop into my code. I am using Dreamweaver's repeat region behaviour for looping through the form and cannot work out how to tag the checkboxes both in terms of ID and 'checked' value. Once I get that sorted I know how to develop an appropriate MySQL update query. I do appreciate that experts do not always want merely to provide 'cut and paste' answers to problems but to help enquirers to think for themselves and that's good. Perhaps I need to go away and scratch my head a bit harder!

 

by: Ray_PaseurPosted on 2009-09-09 at 13:09:09ID: 25295085

@kcalder: No disrespect meant, but I think you got a lot of effort out of EE over a 125 point question, and I wonder if you expected me to rework your code in order to get a grade of "A"?  If so, you might want to review the grading guidelines before you exercise someone else on such a big task for so little reward.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...