<?php
session_start();
// This prg automatically fixes a meeting after a scan for free slots
//get the list from //$_SESSION['check_array'] for the emp_no's
class Mfix{
function db()
{
$met = mysql_connect("","","");
if (!$met)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $met);
}
function max_time()
{
// find out the highest figure in the array for the timeEnd, then add 100 for the next hour
//$_SESSION['$endt']= array($e_row['emp_no'] => $e_row['timeEnd']);
//foreach ($_SESSION['$endt'] as $key => $val)
FOREACH($_SESSION['$endt'] as $key => $val)
{
if ($val == max($_SESSION['$endt']))
{
$_SESSION['my_key'] = $key;
}
}
add_time();
}
function add_time()
{
// increase the time to 1 hour forward
$_SESSION['my_key'] = $_SESSION['my_key'] + 100;
if ($_SESSION['my_key'] > 1700)
{
// discard scan plus writing record - pass control to abandon
}elseif ($_SESSION['my_key']<= 1700)
{
// do the new scan
scan();
}
}
function scan()
{
// connect to db
db();
//accept variables
FOREACH ($_SESSION['check_array'] as $check_array)
{
$e_date = $_SESSION['meet_date'];
$s_time = $_SESSION['my_key']; // new value for timeEnd
//$emp_no = $check_array;
/**
* query the db
*/
$sql = 'SELECT staff.emp_no, staff.fName, staff.lName, event.event_date, event.timeStart, event.timeEnd, event .emp_no, event.agenda FROM `staff`, `event` WHERE staff.emp_no = event.emp_no AND event.emp_no = "' .$check_array.'" AND event.event_date = "'.$e_date.'" AND event.timeStart = "'.$s_time.'"';
$result = mysql_query($sql) or die(mysql_error());
// check for num_row_count if > 0 means trouble
$crazy=mysql_num_rows($result);
if ($crazy==0)
{ // insert record into event
write_meet();
}elseif($crazy>0)
{
// check value of $_SESSION['my_key']
if ($_SESSION['my_key'] >= 1700)
{
// end of the road - report can't continue with auto fix unless date is changed
popup();
}elseif ($_SESSION['my_key']< 1700)
{
//go back and add extra hour b4 scanning
add_time();
}
}
}
function write_meet()
{ // connect to db
db();
// declare variable to count number of records inserted
$_SESSION['kount']=1;
// accept the $_SESSION variables
FOREACH ($_SESSION['check_array'] as $check_array){
$event_date = $_SESSION['meet_date'];
$timeStart = $_SESSION['stime'];
$timeEnd = $_SESSION['etime'];
$location = $_SESSION['locate'];
$agenda = $_SESSION['mdescription'];
$emp_no = $check_array;
$originator = $_SESSION['emp_numb'];
/**
* insert the above details into the db
*/
$sql="INSERT INTO event ( event_id, event_date, timeStart, timeEnd, location, agenda, emp_no, originator)
VALUES
('Null','$event_date','$timeStart','$timeEnd','$location','$agenda','$emp_no','$originator')";
$_SESSION['kount']++;
}
// close db
if (!mysql_query($sql,$met))
{
die('Error: ' . mysql_error());
}
mysql_close($met);
echo "\n\n\t\t\t\t\t\t\t\tRecord Added";
// send control to monthly.php
header('location:my_meeting.php');
}
function popup()
{
// pop up window after pressing ok send control to my_meeting for change of date.
echo "\n\n\t\t\t\tSorry, Auto Fix of your Meeting request\n";
echo "\t\t\t\tIs not Possible until you change\n";
echo "\t\t\t\tyour date for the event ";
?>
<html>
<form method="post" action="my_meeting.php">
<p><input type="submit" name="fix_eror" value="OK"></p></form>
</html>
<?php
}
}
}
?>