Location: PHPKode > projects > Care For Kids > careforkids/ovcgroup/content.inc.php
<script language="javascript" type="text/javascript">
<!--
	
	function form_confirm()
	{
				telephoneCheck();
				$telnum = document.getElementById("telnum").value
				titlecaps();
		// Checks the ovc Group form
		
		if (document.getElementById("church").value == "")
		{
			alert("Please enter a Church name.")
			document.getElementById("church").focus();
		}
		else if (document.getElementById("community").value == "")
		{
			alert("Please enter a Community.")
			document.getElementById("community").focus();
		}
		else if ($telnum.length != 10 )
		{
			
			alert("Please enter a valid Telephone Number.")
			document.getElementById("telnum").focus();
		}
		else 
		{
			document.getElementById("ovcgrp_form").submit();
			
		}
	   
	
	}
	
function telephoneCheck()
{
   var ValidChars = "0123456789";
   var Char;
   var $telnum = document.getElementById("telnum").value;
 	var $newTel="";

 i = 0;
   do 
      { 
      Char = $telnum.charAt(i); 
	  if (ValidChars.indexOf(Char) != -1 ) 
         {
         $newTel = $newTel+Char; 
         }
      i++;
	  }
  while  (i < $telnum.length ) 
  document.getElementById("telnum").value = $newTel;
 }	
	
	
function titlecaps()
	{
	
		 UpperCase(document.getElementById("church").value,"church");
		  UpperCase(document.getElementById("community").value,"community");
	}	
		
function UpperCase(name,type)
{
var htext, nhtext;
	
	htext= name;
		
	htext=htext.toLowerCase();
	// Just in case they're all caps.
	j=htext.length;
	nhtext="";
	
	for(i=0;i<j;i++)
	{
		if(i==0)
		// To capitalize the first character.
		{
			nhtext=nhtext+htext.substr(i,1).toUpperCase();
		}
		else if(htext.charAt(i)==" ")
		{
		// Checks for the appearance of the space character.
		nhtext=nhtext+htext.substr(i,1);
		// Adds that space character to the string.
		nhtext=nhtext+htext.substr(++i,1).toUpperCase();
		// Capitalizes and adds the next character to the
		// string.
		}
		else if(htext.charAt(i)=="")
		{
		// Checks for the appearance of the newline
	
		nhtext=nhtext+htext.substr(i,1);
		// Adds the newline character to the string.
		nhtext=nhtext+htext.substr(++i,1).toUpperCase();
		// Capitalizes and adds the next character to the
		// string.
		}
		else
		{
			nhtext=nhtext+htext.substr(i,1);
		// Adds the character in a normal way.
		}
	}
	if (type == "church")
	{
	document.getElementById("church").value=nhtext;
	}
	else if (type == "community")
	{
	document.getElementById("community").value=nhtext;
	}
}
	function cancel_form()
	{
	window.location="index.php?action=viewAll&clear=clearAll";
	}
	

	function edit_activate()
	{
		
		document.getElementById("update").disabled = false;
		document.getElementById("edit_details").disabled = true;
		document.getElementById("discard").disabled = false;
		document.getElementById("canceladd").disabled = true;
		document.getElementById("church").readOnly = false;
		document.getElementById("community").readOnly = false;
		document.getElementById("telnum").readOnly = false;
	}
	
	
	function confirm_discard()
	{
		var conf = confirm("Are you sure you want to discard your changes?");
		if (conf == true) // if user confirms, then reload the edit page
		{ // switch to php to generate the correct userid to load the viewChurch section with ...
			<? echo "document.location='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewChurch&ovcgrpID=".$_REQUEST['ovcgrpID']."'"; ?>
		} // otherwise do nothing
	}	
	
function pass()
{
escapeSlash('church');
escapeSlash('community');
}

function escapeSlash(type)

{
var inValidChars = "<>;\"\'";
var Char;
var $new="";
   
 if ( type == "church")
	{
	var $check = document.getElementById("church").value;
	}
else if ( type == "community")
	{
	var $check = document.getElementById("community").value;
	}

  var i= 0 ;
   do 
      { 
      Char = $check.charAt(i); 
	  if (inValidChars.indexOf(Char) == -1 ) 
         {
         $new = $new+Char; 
         }
      i++;
	  }
 while  (i < $check.length ) 

 if ( type == "church")
	{
	document.getElementById("church").value = $new;
	}
else if ( type == "community")
	{
	document.getElementById("community").value = $new;
	}
	
  
 }
	

</script>

<?php
	
	include_once($_SESSION['base_dir']."/classes/ovc_group.inc.php");

	// Sort 2d Array
	// Limitation - Must edit 2nd last line of function - array_multisort to have correct no of keys at end
	// SYNTAX: TwoDSort(name of 2d array,name of index to be sorted, asc / desc, str / int) 
	// Not case sensitive
	function TwoDSort($arr,$sortBy,$sortOrder,$sortType)
	{
		if (strtolower($sortOrder) == "asc")
		{
			$sO = SORT_ASC;
		}
		else if (strtolower($sortOrder) == "desc")
		{
			$sO = SORT_DESC;
		}
		if (strtolower($sortType) == "str")
		{
			$sT = SORT_STRING;
		}
		else if (strtolower($sortType) == "int")
		{
			$sT = SORT_NUMERIC;
		}
		//Finds all the categories in the array
		$keyNames = array_keys($arr);
		$c = 0;
		// keyLeft has the chosen sort category removed
		for ($i=1;$i<count($keyNames);$i++)
		{
			if ($keyNames[$i] != $sortBy)
			{
				$keyLeft[$c] = $keyNames[$i];
				$c++;
			}
		}
		if (count($arr[$sortBy])>0)
		{
		array_multisort($arr[$sortBy], $sO, $sT, $arr[$keyLeft[0]],$arr[$keyLeft[1]],$arr[$keyLeft[2]]);
		return $arr;
		}
	}

	if ($_REQUEST['action'] == 'viewAll')
	{
		// display a grid view of OVCgroups, allowing the user to sort by columns or select a ovcgroup to edit
	  	echo "<h2>Church Administration</h2>";
		echo "<div id='top_buttons'>";
	  	echo "<form class='formbuttons' name='view_ovcgrp' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='post'>";
		echo "<input class='button' type='submit' name='nav' value='Add New'>";
		echo "<input type='hidden' name='action' value='add'>";
		echo "</form>";

 		echo "<form class='formbuttons' name='nav_help' target='help_window' action='".$_SESSION['base_url']."/help/index.php' method='get'>";
		echo "<input class='button' type='submit' name='help' value='Help' />";
		echo "<input type='hidden' name='chapter' value='ovcgroupmanagement' />";
//		echo "<input type='hidden' name='section' value='search'>";
		echo "</form>";

		echo "</div>";
		
		if ($_SESSION['church_msg_disp'] == true)
		{
			echo "<p class='message'>".$_SESSION['church_msg']."</p>";
			$_SESSION['church_msg_disp'] = false;
		}

		// If clearText button is clicked, delete all filtering session vars so $details reverts to all record and shows only active
		if ($_REQUEST['clear'] == 'clearAll')
		{
			unset($_SESSION['churchStart']);
			unset($_SESSION['churchFiltered']);
			unset($_SESSION['churchSorted']);
			unset($_SESSION['churchSortBy']);
			unset($_SESSION['churchNoShown']);
		}
		if (!isset($_SESSION['churchStart']))
		{
			$_SESSION['churchStart'] = '0';
			$_SESSION['churchDepth'] = '0';
		}
		if (!isset($_SESSION['churchNoShown']))
		{
			$_SESSION['churchNoShown'] = '10';
		}
		if ($_REQUEST['direction'] == 'next')
		{
			unset($_SESSION['churchSorted']);
			unset($_SESSION['churchSortBy']);
			$_SESSION['churchStart'] = $_SESSION['churchDepth'];
		}
		if ($_REQUEST['direction'] == 'previous')
		{
			unset($_SESSION['churchSorted']);
			unset($_SESSION['churchSortBy']);
			$_SESSION['churchDepth'] = $_SESSION['churchStart'];
			$_SESSION['churchDepth']--;
		}
		// if no sorting stipulated then set defaults - Church Ascending
		if (!isset($_SESSION['churchSortBy']))
		{
			$_SESSION['churchSortBy'] = "Church";
			$_SESSION['churchLastSortBy'] = "";
			$_SESSION['churchOrder'] = "ASC";
			$_REQUEST['sortType'] = "str";
		}

		$results = Group::getAllGroups();
		// 2d array structure
		$details = array(array("Church" => "","Community" => "","TelNum" => "","ovcGroupID" => ""));
		$count = 0; 
		// Populating a 2d array using ovcgroup info
		if (count($results)>0)
		{
		foreach($results as $result)
		{
			$details['Church'][$count] = $result->church;
			$details['Community'][$count] = $result->community;
			$details['TelNum'][$count] = $result->telNum;
			$details['ovcGroupID'][$count] = $result->ovcgrpID;
			$count++;
		}
		}
		$details = TwoDSort($details,'Church','asc','str');
		
		// If filtering has been done, replace $details (which is all info) with filtered info
		if (isset($_SESSION['churchFiltered']))
		{
			$details = $_SESSION['churchFiltered'];
		}
		$_SESSION['churchDetails'] = $details;
		if (count($details['Church']) != 0)
		{
			// Form for filtering choices
			echo "<div id='search'>";
			echo "<form class='formbuttons' name='filtering' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='get'>";
			echo "Search for ";
			echo "<input type='text' name='filter' value=''>";
			echo " in ";
			echo "<SELECT name='category'>";
			echo "<OPTION SELECTED value='Church'> Church";
			echo "<OPTION value='Community'> Community";
			echo "</SELECT>";
			echo "<br><br>";
			echo "Display ";
			$choices = array('10','30','50','100','500');
			echo "<SELECT name='numberRecords'>";
			for ($k=0;$k<5;$k++)
			{
				echo "<OPTION value='".$choices[$k]."'";
				if ($choices[$k] == $_SESSION['churchNoShown'])
				{
					echo " selected='selected'";
				}
				echo ">".$choices[$k];
			}
			echo "</SELECT> records / page &nbsp; &nbsp; &nbsp; ";
			echo "<input class='button' type='submit' name='filter_button' value='Perform Search'>";
			echo " ";
			echo "<input type='hidden' name='action' value='filtered'>";
			echo "</form> ";
			// Clear All form
			echo "<form class='formbuttons' name='clearForm' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='get'>";
			echo "<input class='button' type='submit' name='clearText' value='Clear Results'>";
			echo "<input type='hidden' name='action' value='viewAll'>";
			echo "<input type='hidden' name='clear' value='clearAll'>";
			echo "</form>";
			echo "</div>";
			echo "<div id='main_content'";
	
			// Start of child info grid
			echo "<table class='grid'>";
			echo "<tr>";
			echo "<th width='250'>";
			echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=sorting&sortBy=Church&sortType=str'>Church </a>";
			if ($_SESSION['churchSortBy'] == 'Church')
			{
				if ($_SESSION['churchOrder'] == 'ASC')
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortUp.gif'>";
				}
				else
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortDown.gif'>";
				}
			}
			echo "</th>";
			echo "<th width='170'>";
			echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=sorting&sortBy=Community&sortType=str"."'>Community </a>";
			if ($_SESSION['churchSortBy'] == 'Community')
			{
				if ($_SESSION['churchOrder'] == 'ASC')
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortUp.gif'>";
				}
				else
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortDown.gif'>";
				}
			}
			echo "</th>";
			echo "<th width='170'>";
			echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=sorting&sortBy=TelNum&sortType=str"."'>Telephone Number </a>";
			if ($_SESSION['churchSortBy'] == 'TelNum')
			{
				if ($_SESSION['churchOrder'] == 'ASC')
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortUp.gif'>";
				}
				else
				{
					echo "<img src='".$_SESSION['base_url']."/images/arrowSortDown.gif'>";
				}
			}
			echo "</th>";
			echo "</tr>";
			$col = 1;
			// If sorting the depth of output doesn't need to be adjusted
			if (!isset($_SESSION['churchSorted']))
			{
				if ($_REQUEST['direction'] == 'previous')
				{
					$_SESSION['churchDepth'] = $_SESSION['churchDepth'] - $_SESSION['churchNoShown'];
				}
				else
				{
					$_SESSION['churchDepth'] = $_SESSION['churchDepth'] + $_SESSION['churchNoShown'];
				}
			}
			// If viewing all households and on last page then depth is simply total number of records
			if ($_SESSION['churchDepth'] > count($details['Church']))
			{
				$_SESSION['churchDepth'] = count($details['Church']);
			}
			// If using 'previous' tab then depth is one off (due to dec at top) and start and depth values the wrong way round
			if ($_REQUEST['direction'] == 'previous')
			{
				$_SESSION['churchDepth']++;
				$placeholder = $_SESSION['churchDepth'];
				$_SESSION['churchDepth'] = $_SESSION['churchStart'];
				$_SESSION['churchStart'] = $placeholder;
			}
			// Sets record set to sorted set just before outputting. After outputting sets it back to original again.
			if (isset($_SESSION['churchSorted']))
			{
				$details = $_SESSION['churchSorted'];
			}
			// Outputing Details
			for ($i=$_SESSION['churchStart'];$i<$_SESSION['churchDepth'];$i++)
			{
				if ($col == 1)
				{
					$col = 2;
				}
				else 
				{
					$col = 1;
				}		
				echo "<tr>";
				echo "<td class='data$col'>";
				echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewChurch&ovcgrpID=".$details['ovcGroupID'][$i]."'>";
				echo $details['Church'][$i]."</a>";
				echo "</td>";
				echo "<td class='data$col'>";
				echo $details['Community'][$i];
				echo "</td>";
				echo "<td class='data$col'>";
				echo $details['TelNum'][$i];
				echo "</td>";
				echo "</tr>";
			}
			echo "</table>";
			
			// Returns $details to 'orginal' pre-sorted state
			if (isset($_SESSION['churchFiltered']))
			{
				$details = $_SESSION['churchFiltered'];
			}
			else
			{
				$details = $_SESSION['churchDetails'];
			} 
	
			// Beginning of page checks and calculating all the numbers for "Showing X - Y of Z"
			// Checks if at the start of the record set. 
			$firstPage = false;
			if ($_SESSION['churchStart'] == 0)
			{
				$firstPage = true;
			}
			// Checks if at end of record set. If only showing active, assume it is the last page and then check to see if its not.
			if ($_SESSION['churchDepth'] >= count($details['Church']))
			{
				$lastPage = true;
			}
	
			echo "<table>";
			echo "<tr>";
			echo "<td class='grid_scroll'>";
			// If so disables left tab
			if ($firstPage)
			{
				$_SESSION['churchStartingRecord'] = 1;
			}
			else
			{
				echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&direction=previous'> Previous </a>";
			}
			echo "</td>";
			
			echo "<td class='grid_records'>";
			// Checking size of record set
			$totalRecords = count($details['Church']);
			// Checks if direction is previous and NOT the first page (Important) 
			if (($_REQUEST['direction'] == 'previous') && (!$firstPage))
			{
				$_SESSION['churchStartingRecord'] = $_SESSION['churchStartingRecord'] - $_SESSION['churchNoShown'];
			}
			// Direction forward
			if ($_REQUEST['direction'] == 'next')
			{
				$_SESSION['churchStartingRecord'] = $_SESSION['churchStartingRecord'] + $_SESSION['churchNoShown'];
			}	
			echo "Showing ".$_SESSION['churchStartingRecord']." - ";
			// If last page then top end is obviously the total numbers of records
			if (!$lastPage)
			{
				echo $_SESSION['churchStartingRecord'] + $_SESSION['churchNoShown'] - 1;
			}
			else
			{
				echo $totalRecords; 		
			}
			echo " of ".$totalRecords;
			echo "</td>";
			echo "<td class='grid_scroll'>";
			//Checks if at the end of the record set. If so disables right tab
			if (!$lastPage)
			{
				echo "<a href='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&direction=next'> Next </a>";
			}
			echo "</td>";
			echo "</tr>";
			echo "</table>";
			echo "</div>";
		}
		else
		{
			echo "<div id='main_content'>";
			echo "At present there are no churches on record.";
			echo "<br><br>";
			echo "Churchs can be entered using the 'Add New' Button above.";
			echo "</div>";
		}
	}
	
	else if ($_REQUEST['action'] == 'filtered')
	{
		$filtered = array(array("Church" => "","Community" => "","TelNum" => "","ovcGroupID" => ""));
		$_SESSION['churchNoShown'] = $_REQUEST['numberRecords'];
		$c = 0;
		$clear = "";
		$match = false;
		unset($_SESSION['churchStart']);
		unset($_SESSION['churchSorted']);
		unset($_SESSION['churchSortBy']);
		for ($i=0;$i<count($_SESSION['churchDetails']['Church']);$i++)
		{
			// Take substring of chosen categoty at the length of the filter word and compare it to the filter choice
			if (strncasecmp($_SESSION['churchDetails'][$_REQUEST['category']][$i],$_REQUEST['filter'],strlen($_REQUEST['filter'])) == 0)
			{
				$filtered['Church'][$c] = $_SESSION['churchDetails']['Church'][$i];
				$filtered['Community'][$c] = $_SESSION['churchDetails']['Community'][$i];
				$filtered['TelNum'][$c] = $_SESSION['churchDetails']['TelNum'][$i];
				$filtered['ovcGroupID'][$c] = $_SESSION['churchDetails']['ovcGroupID'][$i];
				$c++;
				$match = true;
			}
		}
		if (!$match)
		{
			$_SESSION['church_msg_disp'] = true;
			$_SESSION['church_msg'] = "Your search did not return any results - showing all records.";
			$clear = 'clearAll';
		}
		$_SESSION['churchFiltered'] = $filtered;
		echo "<script language = 'javascript'>document.location='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&clear=".$clear."';</script>";
	} 
	
	else if ($_REQUEST['action'] == 'sorting')
	{
		// if session variables are set, then store the previous sortby and assign the new
		$_SESSION['churchLastSortBy'] = $_SESSION['churchSortBy'];
		$_SESSION['churchSortBy'] = $_REQUEST['sortBy'];
		// if lastsortby and sortby are the same, then flip the value of the ASC/DESC
		if ($_SESSION['churchLastSortBy'] == $_SESSION['churchSortBy'])
		{
			if ($_SESSION['churchOrder'] == "ASC")
			{
				$_SESSION['churchOrder'] = "DESC";
			}
			else $_SESSION['churchOrder'] = "ASC";
		}
		else
		{
			// otherwise, the sort must be ASC
			$_SESSION['churchOrder'] = "ASC";
		}
		$sorted = array(array("Church" => "","Community" => "","TelNum" => "","ovcGroupID" => ""));
		$c = 0;
		// Creating smaller array out just the records in the current page section (e.g 8 - 15)
		for ($i=$_SESSION['churchStart'];$i<$_SESSION['churchDepth'];$i++)
		{
			$sorted['Church'][$i] = $_SESSION['churchDetails']['Church'][$i];
			$sorted['Community'][$i] = $_SESSION['churchDetails']['Community'][$i];
			$sorted['TelNum'][$i] = $_SESSION['churchDetails']['TelNum'][$i];
			$sorted['ovcGroupID'][$i] = $_SESSION['churchDetails']['ovcGroupID'][$i];
		}
		$sorted = TwoDSort($sorted,$_SESSION['churchSortBy'],$_SESSION['churchOrder'],$_REQUEST['sortType']);

		// php in its infinite wisdom shifts the indexing of the array up to 0 if there are empty spaces. So if the record 
		// set was for 8 - 15 it could be shifted up to 0 - 7. This destroys the outputting logic as all my counters are
		// based the position of the records in terms of the full 2d array. so such childSorted starts as a copy
		// of the full 2d array and then gets the current page records overwritten with sorted ones.
		$_SESSION['churchSorted'] = $_SESSION['churchDetails'];
		for ($i=$_SESSION['churchStart'];$i<$_SESSION['churchDepth'];$i++)
		{
			$_SESSION['churchSorted']['Church'][$i] = $sorted['Church'][$c];
			$_SESSION['churchSorted']['Community'][$i] = $sorted['Community'][$c];
			$_SESSION['churchSorted']['TelNum'][$i] = $sorted['TelNum'][$c];
			$_SESSION['churchSorted']['ovcGroupID'][$i] = $sorted['ovcGroupID'][$c];
			$c++;
		}
		echo "<script language = 'javascript'>document.location='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&sortBy=sorting';</script>";
	}

	else if ($_REQUEST['action'] == 'add')
	{
		// Add a new group
		echo "<h2>Add Church</h2>";

		echo "<div id='top_buttons'>";
		echo "<form class='formbuttons' name='nav_help' target='help_window' action='".$_SESSION['base_url']."/help/index.php' method='get'>";
    echo "<input class='button' type='submit' name='help' value='Help' />";
		echo "<input type='hidden' name='chapter' value='ovcgroupmanagement' />";
		echo "<input type='hidden' name='section' value='add'>";
		echo "</form>";
		echo "</div>";


		echo "<div id='main_content'>";
		echo "<table class= 'form'>";
		echo "<form name='ovcgrp_form' id='ovcgrp_form' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='post'>";
		echo "<th>OVC Group Details</th>";
		echo "<tr>";
		echo "<td class='data1'  >Church</td><td class='data1'><input type='text'  name='church' id='church' onblur= 'javascript:titlecaps();' onkeyup= 'javascript:pass();' ></td>";
		echo "</tr>";

		echo "<tr>";
		echo "<td class='data2'>Community</td><td class='data2'><input type='text' name='community' id='community'  onblur= 'javascript:titlecaps();' onkeyup= 'javascript:pass();'></td>";
		echo "</tr>";

		echo "<tr>";
		echo "<td class='data1'>Telephone No.</td><td class='data1'><input type='text' name='telnum' id='telnum' onkeydown='javascript: telephoneCheck();' onblur='javascript:telephoneCheck();' ></td>";
		echo "</tr>";
		
		echo "<tr>";
    	echo "<td >";
		echo "</td>";
		echo "<td >";
		echo "<input class= 'button'  type='button' name='addovcgrp' value='Save' onClick='javascript: form_confirm();'>";
		echo "<input class= 'button' type='button' name='cancel' value='Cancel' onclick='javascript: cancel_form();'>";
		echo "<input type='hidden' name='action' value='addgroup'>";
		echo "</td>";
		echo "</tr>";
    	echo "</form>";
		echo "</table>";
		echo "</div>";
	}

	else if ($_REQUEST['action'] == 'addgroup')
	{
		// create an instance of the group class
		$g = new Group();
		// fill it with the new group info
		$g->setGroup($_REQUEST['church'],$_REQUEST['community'],$_REQUEST['telnum']);
		// write to the database
		$g->saveGroup();
		// redirect the user to the initial grid edit page with a confirmation message
		echo "<script language = 'javascript'>document.location='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&clear=clearAll&msg= ".$_REQUEST['church']." added.';</script>";
		
	}

	else if ($_REQUEST['action'] == 'viewChurch')
	{
		$g = new Group;
		$g->getGroup($_REQUEST['ovcgrpID']);

		echo "<h2>Church Management</h2>";
		echo "<div id='top_buttons'>";
		echo "<input class='button' type='button' name='edit_details' id='edit_details' value='Edit Details' onclick='javascript: edit_activate();'>";
		echo "&nbsp;";

 		echo "<form class='formbuttons' name='nav_help' target='help_window' action='".$_SESSION['base_url']."/help/index.php' method='get'>";
		echo "<input class='button' type='submit' name='help' value='Help' />";
		echo "<input type='hidden' name='chapter' value='ovcgroupmanagement' />";
		echo "<input type='hidden' name='section' value='view'>";
		echo "</form>";

		echo "<input class='button' type='button' name='canceladd' id='canceladd' value='Exit' onClick='javascript: document.location=\"".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&clear=clearAll\";'>";
		echo "<form class='formbuttons' name='delete_form' id='delete_form' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='post'>";
		
		echo "<input type='hidden' name='service' value='".$_REQUEST['ovcgrpID']."'>";
  		echo "&nbsp;";
		echo "</form>";
		echo "</div>";
		
		echo "<div id='main_content'>";
    	echo "<table class='form'  >";
		echo "<th >";
		echo "".$g->church."";
		echo "</th>";
				
		echo "<form name='ovcgrp_form' id='ovcgrp_form' action='".$_SESSION['base_url']."/ovcgroup/index.php' method='post'>";
		echo "<input type='hidden' name='ovcgrpID' value='".$_REQUEST['ovcgrpID']."'>";
		echo "<input type='hidden' name='action' value='update'>";
		echo "<tr >";
		echo "<td class = 'data1'>Church</td><td class ='data1'><input type='text' name='church'  id='church' value='".$g->church."' readonly='readonly'  onblur= 'javascript:titlecaps();' onkeyup= 'javascript:pass();'></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td class='data2'>Community</td><td class='data2'><input type='text' name='community' id='community' value='".$g->community."' readonly='readonly'  onblur= 'javascript:titlecaps();' onkeyup= 'javascript:pass();'></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td class='data1'>Tel Num</td><td class='data1'><input type='text' onkeydown='javascript: telephoneCheck();' onblur='javascript:telephoneCheck();' name='telnum' id='telnum'  readonly='readonly' value='".$g->telNum."' ></td>";
		echo "</tr>";
		echo "<tr>";
		
		echo "<td>";
    	echo "</td>";
		echo "<td>";
		echo "<input class='button' type='button' name='update' id='update' value='Save' onclick='javascript: form_confirm();' disabled='disabled'>";
		echo "<input class='button' type='button' name='discard' id='discard' value='Discard Changes' onClick='javascript: confirm_discard();' disabled='disabled'>";
		echo "</td>";
		echo "</tr>";
		echo "</form>";
		echo "</table>";
		echo "</div>";
	}

	else if ($_REQUEST['action'] == 'update')
	{
		
		// create an instance of the Group class
		$g = new Group();
		// fill it with the info corresponding to the given Group id
		$g->getGroup($_REQUEST['ovcgrpID']);
		// set the new values
		$g->church = $_REQUEST['church'];
		$g->community = $_REQUEST['community'];
		$g->telNum = $_REQUEST['telnum'];
		// write to the database
		$g->updateGroup();
		// redirect the user to the initial grid edit page with a confirmation message
		echo "<script language = 'javascript'>document.location='".$_SESSION['base_url']."/ovcgroup/index.php?action=viewAll&clear=clearAll&msg= ".$_REQUEST['church']." editted.';</script>";
	}

	else
	{
		echo "<p class='error'>Application Error: Please contact your system administrator.";
	}
?>
Return current item: Care For Kids