<?php session_start(); include "header.php"; include "leftnav.php"; ?> <td 
valign="top" class="border"> <script language='javascript' 
src="js/popcalendar.js"></script> <SCRIPT LANGUAGE="JavaScript" 
SRC="js/lw_layers.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript" 
SRC="js/lw_menu.js"></SCRIPT> <br> <?php $staffid = isloggedin(session_id());
        
        $act = $_POST["act"];

        if ($staffid == -1)
        {
                if ($act == "login")
                {
                        $staffname = $_POST["staffname"];
                        $staffpass = $_POST["staffpass"];
                        
                        login($staffname, $staffpass);
                }
                else
                {
                        loginform();
                }
        }
        else //display content
        {
                if ($act == "logoff")
                {
                        logoff($staffid);
                }

                elseif($act == "profile")
                {
                        displayprofileform($staffid);
                }
                
                elseif($act == "modprofile")
                {
                        updateprofile($staffid);
                }
                
                elseif($act == "addmove")
                {
                        addmove($staffid);
                }
                
                elseif($act == "modmove")
                {
                        modmoveform();
                }
                elseif($act == "modthis")
                {
                        modmove();
                }
                
                elseif ($act == "delmove")
                {
                        delmoveform();
                }
                elseif ($act == "delthis")
                {
                        delmove();
                }

                else
                {
                        displaycontent($staffid);
                }
        }
        ?>
</td>
<?php
if (!($staffid>0))
{
        include "rightnews.php";
}
include "footer.php";
?>

<?php
function isloggedin($sessid)
{
        include_once "conn.php";
        
        $query = "select loginstaff.staffid from loginstaff, staff where loginstaff.sessid='$sessid' and loginstaff.staffid=staff.staffid";
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $staffid = $row[0];
                return $staffid;
        }
        
        return -1;
}

function loginform($err='')
{
        ?>
        <table border=0 width=100% cellspacing=0 cellpadding=5>
          
  <tr class="heading"> 
    <td height="78" valign="top"><font color="#669900"> <img src="img/staffbutton.jpg" width="237" height="21"> 
      <br>
      <br>
      <font color="#000000">For Staff use only. Please log-in with valid Name 
      and Password.</font></font></td>
          </tr>
          
          <tr>
            <td valign="top">
              <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
              <table width=100% border=0 cellspacing=0 cellpadding=5>
                <tr><td colspan=2 align="center"><?php echo "$err&nbsp;"; ?></td></tr>
                <tr>
                  <td>Name</td>
                  <td><input type="text" name="staffname" value=""></td>
                <tr>
                
                <tr>
                  <td>Password</td>
                  <td><input type="password" name="staffpass">
              <input name="submit" type="submit" value=" Login "></td>
                </tr>
                
                <tr>
                  <td colspan=2 align="center"><input type="hidden" name="act" value="login">
            </td>
                </tr>
              </table>
              </form>
            </td>
          </tr>
        </table>        
        <?php
}

function login($staffname, $staffpass)
{
        $query = "select staffid from staff where staffname='$staffname' and staffpass='$staffpass'";
        $result = mysql_query($query) or die (mysql_error());
        
        if ($row = mysql_fetch_array($result))
        {
                $staffid = $row[0];
                $query = "delete from loginstaff where staffid='$staffid'";
                mysql_query($query) or die (mysql_error());
                
                $query = "insert into loginstaff values('$staffid', now(), '";
                $query .= session_id();
                $query .= "')";
                mysql_query($query) or die (mysql_error());
                echo "<script>window.location = 'staffarea.php'</script>";
        }
        else
        {
                $err = "invalid name and password combination";
                //echo "call loginform($err)";
                loginform($err);
        }
}

function displaycontent($staffid)
{
        $query = "select firstname, lastname, staffname from staff where staffid='$staffid'";
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $firstname = $row[0];
                $lastname = $row[1];
                $staffname = $row[2];
        }
        ?>
        <table border=0 width=100% cellspacing=0 cellpadding=5>
          <tr class="heading">
            
    <td valign="top"><a href="index.php"><font color="#669900">Home</font></a> 
      <font color="#669900">> <a href="staffarea.php">Staff</a></font></td>
          </tr>
          
          <tr>
            <td valign="top">
              <table width=100% cellspacing=0 cellpadding=3 border=0>
                <tr>
                  <td colspan=2>
                  Welcome <?php echo "<b>$firstname</b>, you are logged in as <b>$staffname</b>"; ?>
                  <br>Today is <?php echo  date("jS M Y"); ?>
                  </td>
                </tr>
                <tr>
                  <td colspan=2>
                  <table cellspacing=0 cellpadding=0 border=0 width=100%>
                  <tr>
                  <td><form name=pro action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="hidden" name="act" value="profile"><table cellpadding=0 cellspacing=0><tr><td><input type="image" src="img/folder_small.gif"></td><td onclick="pro.submit()" onmouseover="this.style.cursor='hand'"><u>Profile</u></td></tr></table></td></form>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=fb.php><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.location='staffarea.php'" onmouseover="this.style.cursor='hand'"><u>Movements</u></td></tr></table></td>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=fb.php><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.location='fb.php'" onmouseover="this.style.cursor='hand'"><u>Facility Booking</u></td></tr></table></td>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=gen.php onclick="window.open('gen.php', '', 'width=600, height=300, resizable, scrollbars');return false"><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.open('gen.php', '', 'width=600, height=300, resizable, scrollbars')" onmouseover="this.style.cursor='hand'"><u>Report</u></td></tr></table></td>
                  <td><form name=log action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="hidden" name="act" value="logoff"><table cellpadding=0 cellspacing=0><tr><td><input type="image" src="img/folder_small.gif"></td><td onclick="log.submit()" onmouseover="this.style.cursor='hand'"><u>Logoff</u></td></tr></table></td></form>
                  </tr>
                  </table>
                  </td>
                </tr>
                
                <tr>
                  <td colspan=2>
                  <?php
                  latestmove($staffid);
                  ?>
                  </td>
                </tr>
                
                <tr>
                  <td colspan=2>
                  <?php
                  addmoveform($staffid);
                  ?>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
        <?php
}

function logoff($staffid)
{
        $query = "delete from loginstaff where staffid='$staffid'";
        mysql_query($query) or die (mysql_error());
        echo "<script>window.location = 'staffarea.php'</script>";
}

function displayprofileform($staffid, $err='')
{
        $query = "select firstname, lastname, staffname from staff where staffid='$staffid'";
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $firstname = $row[0];
                $lastname = $row[1];
                $staffname = $row[2];
        }
        ?>
        <table border=0 width=100% cellspacing=0 cellpadding=5>
          <tr class="heading">
            
    <td valign="top"><a href="index.php"><font color="#669900">Home</font></a> 
      <font color="#669900">> <a href="staffarea.php">Staff</a> > Update Profile</font></td>
          </tr>
          <tr><td><table cellspacing=0 cellpadding=0 border=0 width=100%>
                  <tr>
                  <td><form name=pro action="staffarea.php" method="post"><input type="hidden" name="act" value="profile"><table cellpadding=0 cellspacing=0><tr><td><input type="image" src="img/folder_small.gif"></td><td onclick="pro.submit()" onmouseover="this.style.cursor='hand'"><u>Profile</u></td></tr></table></td></form>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=fb.php><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.location='staffarea.php'" onmouseover="this.style.cursor='hand'"><u>Movements</u></td></tr></table></td>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=fb.php><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.location='fb.php'" onmouseover="this.style.cursor='hand'"><u>Facility Booking</u></td></tr></table></td>
                  <td><table cellspacing=0 cellpadding=0 border=0><tr><td><a href=gen.php onclick="window.open('gen.php', '', 'width=600, height=300, resizable, scrollbars');return false"><img border=0 src="img/folder_small.gif"></a></td><td onclick="window.open('gen.php', '', 'width=600, height=300, resizable, scrollbars')" onmouseover="this.style.cursor='hand'"><u>Report</u></td></tr></table></td>
                  <td><form name=log action="staffarea.php" method="post"><input type="hidden" name="act" value="logoff"><table cellpadding=0 cellspacing=0><tr><td><input type="image" src="img/folder_small.gif"></td><td onclick="log.submit()" onmouseover="this.style.cursor='hand'"><u>Logoff</u></td></tr></table></td></form>
                  </tr>
                  </table></td></tr>
          <tr>
            <td>
              <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
              <table width=100% cellspacing=0 cellpadding=3>
                <tr>
                  <td colspan=2 align="center"><?php echo "$err &nbsp;"; ?></td>
                </tr>
                
                <tr>
                  <td>First Name</td>
                  <td><input type="text" name="firstname" value="<?php echo $firstname; ?>"></td>
                </tr>
                
                <tr>
                  <td>Last Name</td>
                  <td><input type="text" name="lastname" value="<?php echo $lastname; ?>"></td>
                </tr>
                
                <tr>
                  <td>Access Name</td>
                  <td><input type="text" name="staffname" value="<?php echo $staffname; ?>"></td>
                </tr>
                
                <tr>
                  <td>Password</td>
                  <td><input type="password" name="password1"></td>
                </tr>
                
                <tr>
                  <td>Confirm Password</td>
                  <td><input type="password" name="password2"></td>
                </tr>
                
                <tr>
                  <td colspan=2 align="center"><input type="hidden" name="act" value="modprofile"><input type="submit" value="Modify">&nbsp;<input type="reset" value="Cancel"></td>
                </tr>
              </table>
              </form>
            </td>
          </tr>
        </table>
        <?php
}

function updateprofile($staffid)
{
        $firstname = $_POST["firstname"];
        $lastname = $_POST["lastname"];
        $staffname = $_POST["staffname"];
        $staffpass = $_POST["password1"];
        
        $query = "update staff set firstname='$firstname', lastname='$lastname', staffname='$staffname' where staffid='$staffid'";
        mysql_query($query) or die (mysql_error());
        
        if ($staffpass)
        {
                $query = "update staff set staffpass='$staffpass' where staffid='$staffid'";
                mysql_query($query) or die (mysql_error());
        }
        echo "<script>window.location = 'staffarea.php'</script>";
}

function addmoveform($staffid)
{
        ?>
        <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name=form1 onsubmit="return (checkthis(this))">
        <table cellspacing=0 cellpadding=3 border=0 width=100%>
          <tr>
      <td colspan=2><b><font color="#669900">Add movement form</font></b></td>
    </tr>
          <?php
          $res = mysql_query("select recep from staff where staffid='$staffid'");
          if (mysql_result($res, 0, 0) == 1)
          {
                ?>
                <tr><td>Staff</td><td><select name=alsdjf>
                <?php
                $res = mysql_query("select staffid, staffname from staff order by staffname asc");
                while ($row = mysql_fetch_array($res))
                {
                        $alsdjf = $row[0];
                        $lsf = $row[1];
                        echo "<option value=$alsdjf>$lsf</option>";
                }
                ?></select></td></tr>
                <?php
        }
          ?>
          
          <tr><td>Type</td><td><?php movetype(); ?></td></tr>
          
          <tr><td>Activity</td><td><input type="text" name="movetitle" value=""></td></tr>
          
          <tr><td>Start Date</td><td><input type="text" name="movedate" value="" readonly onfocus='popUpCalendar(this, form1.movedate, "yyyy-mm-dd")'></td></tr>
          <tr><td>Start Time</td><td><input type="text" name="starttime" value="">(24 hour format 12:34)</td></tr>
          
          <tr><td>Stop Date</td><td><input type="text" name="stopdate" value="" readonly onfocus='popUpCalendar(this, form1.stopdate, "yyyy-mm-dd")'></td></tr>
          <tr><td>Stop Time</td><td><input type="text" name="stoptime" value="">(24 hour format 12:34)</td></tr>
<!--
          <tr><td valign="top">Detail</td><td><textarea name="movedetail" rows=3 cols=20 wrap="virtual"></textarea></td></tr>
        -->  
          <tr><td colspan=2 align="center"><input type="hidden" name="act" value="addmove"><input type="submit" value=" Add ">&nbsp;<input type="reset" value="Cancel"></td></tr>
        </table>
        </form>
        <?php
}

function movetype($type=0)
{
        echo "<select name=\"typeid\">";
        $query = "select typeid, typename from movetype";
        $result = mysql_query($query) or die (mysql_error());
        while ($row = mysql_fetch_array($result))
        {
                $typeid = $row[0];
                $typename = $row[1];
                if ($typeid == $type)
                {
                        echo "<option value=\"$typeid\" selected>$typename</option>";
                }
                else
                {
                        echo "<option value=\"$typeid\">$typename</option>";
                }
        }
        echo "</select>";
}

function addmove($staffid)
{
        $typeid = $_POST["typeid"];
        $movetitle = $_POST["movetitle"];
        $movedate = $_POST["movedate"];
        $movedetail = $_POST["movedetail"];
        $stopdate = $_POST["stopdate"];
        $starttime = $_POST["starttime"];
        $stoptime = $_POST["stoptime"];
        
        $query = "insert into move(movetitle, startdate, movedetail, stopdate, starttime, stoptime) values ('$movetitle', '$movedate', '$movedetail', '$stopdate', '$starttime', '$stoptime')";
        mysql_query($query) or die (mysql_error());
        
        $query = "select last_insert_id() from move";
        $result = mysql_query($query) or die (mysql_error());
        while ($row = mysql_fetch_array($result))
        {
                $moveid = $row[0];
        }
        
        $res = mysql_query("select startdate, stopdate from move where moveid='$moveid'");
        if ($row = mysql_fetch_array($res))
        {
                $startdate = $row[0];
                $stopdate = $row[1];
                
                if ($startdate == "0000-00-00")
                {
                        mysql_query("update move set startdate=now() where moveid='$moveid'");
                        $startdate = date("Y-m-d");
                }
                
                if ($stopdate < $startdate)
                {
                        mysql_query("update move set stopdate=startdate where moveid='$moveid'");
                }
        }
        
        $query = "insert into move_type values ('$moveid', '$typeid')";
        mysql_query($query) or die (mysql_error());
        
          $res = mysql_query("select recep from staff where staffid='$staffid'");
          if (mysql_result($res, 0, 0) == 1)
          {
                $alsdjf = $_POST["alsdjf"];
        $query = "insert into move_staff values('$moveid', '$alsdjf')";         
        }
        else
        $query = "insert into move_staff values('$moveid', '$staffid')";
          
        mysql_query($query) or die (mysql_error());
        
        echo "<script>window.location = 'staffarea.php'</script>";
}

function latestmove($staffid)
{
	$res = mysql_query("select recep from staff where staffid='$staffid'");
        $recep = mysql_result($res, 0, 0);

        $year = $_GET["year"]?$_GET["year"]:date("Y");
        $month = $_GET["month"]?$_GET["month"]:date ("m");
        $upper = date("Y-m-d", mktime(0,0,0, $month+1, 0, $year));
        $lower = date("Y-m-d", mktime(0,0,0, $month, 0, $year));
        
        //echo "$lower $upper";
        
        $nexyear = date("Y", mktime(0,0,0, $month+1, 1, $year));
        $nexmonth = date("m", mktime(0,0,0, $month+1, 1, $year));
        $preyear = date("Y", mktime(0,0,0, $month-1, 1, $year));
        $premonth = date("m", mktime(0,0,0, $month-1, 1, $year));
        
        if ($recep != 1)
        {
        	$query = "select move.moveid, move.movetitle, move.startdate, move.stopdate, move.starttime, move.stoptime from move, move_staff where move_staff.staffid='$staffid' and move_staff.moveid=move.moveid and ((startdate>'$lower' and startdate<='$upper') or (stopdate>'$lower' and stopdate<='$upper')) order by move.startdate desc, moveid desc";
        	$result = mysql_query($query) or die (mysql_error());
        	echo "<table cellspacing=1 cellpadding=3 border=0 width=100%>";
        	echo "<tr><td colspan=6 width=100%><table width=100% cellspacing=0 cellpadding=0><tr><td width=1%><a href=?year=$preyear&month=$premonth>&lt;&lt;</a></td><td align=center><b>Movements for " . date("F Y", mktime(0,0,0, $month, 1, $year)) . "</b></td><td width=1% align=right><a href=?year=$nexyear&month=$nexmonth>&gt;&gt;</a></td></tr></table></td></tr>";
        	echo "<tr bgcolor=\"#a0a0a0\"><th width=1% nowrap align=left><font color=ffffff>Start</font></th><th width=1% nowrap align=left><font color=ffffff>End</font></th><th align=left><font color=ffffff>Activities</font></th><th align=left width=1%><font color=ffffff>Type</font></th><th colspan=2 wdith=1% nowrap align=left><font color=ffffff>Options</font></th></tr>";
        }
        else
        {
        	$query = "select move.moveid, move.movetitle, move.startdate, move.stopdate, move.starttime, move.stoptime, staff.staffname from move, move_staff, staff where move_staff.moveid=move.moveid and ((startdate>'$lower' and startdate<='$upper') or (stopdate>'$lower' and stopdate<='$upper')) and move_staff.staffid=staff.staffid order by move.startdate desc, moveid desc";
        	$result = mysql_query($query) or die (mysql_error());
        	echo "<table cellspacing=1 cellpadding=3 border=0 width=100%>";
        	echo "<tr><td colspan=7 width=100%><table width=100% cellspacing=0 cellpadding=0><tr><td width=1%><a href=?year=$preyear&month=$premonth>&lt;&lt;</a></td><td align=center><b>Movements for " . date("F Y", mktime(0,0,0, $month, 1, $year)) . "</b></td><td width=1% align=right><a href=?year=$nexyear&month=$nexmonth>&gt;&gt;</a></td></tr></table></td></tr>";
        	echo "<tr bgcolor=\"#a0a0a0\"><th width=1% nowrap align=left><font color=ffffff>Staff</font></th><th width=1% nowrap align=left><font color=ffffff>Start</font></th><th width=1% nowrap align=left><font color=ffffff>End</font></th><th align=left><font color=ffffff>Activities</font></th><th align=left width=1%><font color=ffffff>Type</font></th><th colspan=2 wdith=1% nowrap align=left><font color=ffffff>Options</font></th></tr>";
        }
        
        $trigger = 1;
        
        while ($row = mysql_fetch_array($result))
        {
                $moveid = $row[0];
                $movetitle = $row[1];
                $movedate = $row[2];
                $stopdate = $row[3];
                $starttime = substr($row[4], 0, 5);
                $stoptime = substr($row[5], 0, 5);
                
                $movedate = fd($movedate);
                $stopdate = fd($stopdate);
                
                $trigger = ($trigger + 1) % 2;
                if ($trigger)
                {
                        echo "<tr bgcolor=\"#c9c9c9\">";
                }
                else
                {
                        echo "<tr bgcolor=\"#e9e9e9\">";
                }
                
                if ($recep == 1)
                {
                	$staffname = $row[6];
                	echo "<td width=1% nowrap>$staffname</td>";
                }
                
                echo "<td width=1% nowrap>$movedate $starttime</td>";
                echo "<td width=1% nowrap>$stopdate $stoptime</td>";
                echo "<td>$movetitle</td>";
                ?>
                <td>
                <?php
                $jkasd = mysql_query("select typename from movetype, move_type where move_type.moveid=$moveid and move_type.typeid=movetype.typeid") or die (mysql_error());
                if ($kk = mysql_fetch_array($jkasd))
                {
                        echo $kk[0];
                }
                ?>
                </td>
                <td width=1%><form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="hidden" name="act" value="modmove"><input type="hidden" name="id" value="<?php echo $moveid; ?>"><input type="submit" value="Modify"></td></form>
                <td width=1%><form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="hidden" name="act" value="delmove"><input type="hidden" name="id" value="<?php echo $moveid; ?>"><input type="submit" value="Delete"></td></form>
                <?php
                echo "</tr>";
        }
        
        echo "</table>";
}

function modmoveform()
{
        $moveid = $_POST["id"];
        $query = "select movetitle, startdate, movedetail, stopdate, starttime, stoptime from move where moveid='$moveid'";
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $movetitle = $row[0];
                $movedate = $row[1];
                $movedetail = $row[2];
                $stopdate = $row[3];
                $starttime = substr($row[4], 0, 5);
                $stoptime = substr($row[5], 0, 5);
        }
        
        $query = "select typeid from move_type where moveid='$moveid'";
        //echo $query;exit;
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $typeid = $row[0];
        }
        
        ?>
        <table border=0 width=100% cellspacing=0 cellpadding=5>
          <tr class="heading">
            
    <td valign="top"><a href="index.php"><font color="#669900">Home</font></a> 
      <font color="#669900">> <a href="staffarea.php">Staff</a> > Update Movement</font></td>
          </tr>
          
          <tr>
            <td valign="top">
        <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name=form1>
        <table cellspacing=0 cellpadding=3 border=0 width=100%>
          <tr><td colspan=2><b>Update movement form</b></td></tr>
          
          <tr>
            <td>Type</td>
            <td><?php movetype($typeid); ?></td>
          </tr>
          
          <tr>
            <td>Activity</td>
            <td><input type="text" name="movetitle" value="<?php echo $movetitle; ?>"></td>
          </tr>
          
          <tr><td>Start Date</td><td><input type="text" name="movedate" value="<?php echo $movedate; ?>" readonly onfocus='popUpCalendar(this, form1.movedate, "yyyy-mm-dd")'></td></tr>
          <tr><td>Start Time</td><td><input type="text" name="starttime" value="<?php echo $starttime; ?>"></td></tr> 

          <tr><td>Stop Date</td><td><input type="text" name="stopdate" value="<?php echo $stopdate; ?>"  readonly onfocus='popUpCalendar(this, form1.stopdate, "yyyy-mm-dd")'></td></tr>
         <tr><td>Stop Time</td><td><input type="text" name="stoptime" value="<?php echo $stoptime; ?>"></td></tr>
          <!--
          <tr>
            <td valign="top">Detail</td>
            <td><textarea name="movedetail" rows=3 cols=20 wrap="virtual"><?php echo $movedetail; ?></textarea></td>
          </tr>
          -->
          <tr>
            <td colspan=2 align="center"><input type="hidden" name="act" value="modthis"><input type="hidden" name="id" value="<?php echo $moveid; ?>"><input type="submit" value="Modify">&nbsp;<input type="reset" value="Cancel"></td>
          </tr>
        </table>
        </form>
            </td>
          </tr>
        </table>
        <?php
}

function modmove()
{
        $moveid = $_POST["id"];
        $typeid = $_POST["typeid"];
        $movetitle = $_POST["movetitle"];
        $movedate = $_POST["movedate"];
        $movedetail = $_POST["movedetail"];
        $stopdate = $_POST["stopdate"];
        $starttime = $_POST["starttime"];
        $stoptime = $_POST["stoptime"];
        
        $query = "update move set movetitle='$movetitle', startdate='$movedate', movedetail='$movedetail', stopdate='$stopdate', starttime='$starttime', stoptime='$stoptime' where moveid='$moveid'";
        mysql_query($query) or die (mysql_error());
        
        $res = mysql_query("select startdate, stopdate from move where moveid='$moveid'");
        if ($row = mysql_fetch_array($res))
        {
                $startdate = $row[0];
                $stopdate = $row[1];
                
                if ($startdate == "0000-00-00")
                {
                        mysql_query("update move set startdate=now() where moveid='$moveid'");
                        $startdate = date("Y-m-d");
                }
                if ($stopdate < $startdate)
                {
                        mysql_query("update move set stopdate=startdate where moveid='$moveid'");
                }
        }
        
        mysql_query("delete from move_type where moveid='$moveid'") or die (mysql_error());
        
        mysql_query("insert into move_type values ('$moveid', '$typeid')") or die (mysql_error());
        
        echo "<script>window.location = 'staffarea.php'</script>";
}

function delmoveform()
{
        $moveid = $_POST["id"];
        
        $query = "select movetitle from move where moveid='$moveid'";
        $result = mysql_query($query) or die (mysql_error());
        if ($row = mysql_fetch_array($result))
        {
                $movetitle = $row[0];
        }
        ?>
        <table border=0 cellspacing=0 cellpadding=5>
          <tr class="heading">
            
    <td valign="top"><a href="index.php"><font color="#669900">Home</font></a> 
      <font color="#669900">> <a href="staffarea.php">Staff</a> > Delete Movement</font></td>
          </tr>
          
          <tr>
            <td>Are you sure you want to delete the movement: <b><?php echo $movetitle; ?></b>?</td>
          </tr>
          
          <tr>
            <td align="center"><form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="hidden" name="act" value="delthis"><input type="hidden" name="id" value="<?php echo $moveid; ?>"><input type="submit" value="Yes"></td></form>
          </tr>
          
          <tr>
            <td align="center"><form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post"><input type="submit" value=" No "></td></form>
          </tr>
        </table>
        <?php
}

function delmove()
{
        $moveid = $_POST["id"];
        
        mysql_query("delete from move where moveid='$moveid'") or die (mysql_error());
        
        mysql_query("delete from move_type where moveid='$moveid'") or die (mysql_error());
        
        mysql_query("delete from move_staff where moveid='$moveid'") or die (mysql_error());
        
        echo "<script>window.location = 'staffarea.php'</script>";
}

function fd($date)
{
        $split = explode("-", $date);
        $date = date("M jS, Y", mktime(0,0,0,$split[1], $split[2], $split[0]));
        return $date;
}
?>
<script language="javascript">
function checkthis(form)
{
        if (form.movetitle.value == '')
        {
                window.alert("Form incomplete");
                return false;
        }
}
</script>