}
     //all jobs are named laptop repair???? if not add this variable with a specific name to each case above
     $jobName = "Laptop Repair for " . $_POST['jOwner'];
     //make a query to add a job
     $makeJobQuery = "INSERT INTO `jobs`(`name`, `description`, `skillcatid`, `status`, `points`, `repeatable`, `limitone`, `claimedby`, `priority`, `requirement_id`) VALUES ('" . $jobName . "','" . $jobMessage . "'," . $jobSkill . ",1," . $jobPoints . ",0,0,0," . $jobPriority . "," . $requirement_id . ")";
     //commence query if it fails it returns false
     $result = mysql_query($makeJobQuery);
     //announce whether a job was created and query was successful
     if (!$result) {
         echo "Job Creation Failed<BR><BR>";
         die('Invalid query: ' . mysql_error());
     } else {
         echo "New Job Created!<BR>";
     }
     // Give the student a point
     queryFunc("INSERT INTO points (student_id, points, category_id) VALUES ('" . $_SESSION['loginid'] . "', 1, 1)");
     //
     //add this device to the devices table below
     //
     //make query to add to devices table
     $makeDevicesQuery = "INSERT INTO `devices`(`owner`, `assignedto_id`, `received`, `problem`, `resolution`, `notes`, `repaired`, `returned`, `last_update`, `receivedby_id`, `serial`, `status_id`) VALUES ('" . $_POST['jOwner'] . "','','" . date('Y-m-d H:i:s') . "','" . $jobMessage . "','','" . $notes . "','','','','" . $_SESSION['loginid'] . "','" . $_POST['jLaptopNumber'] . "', '1')";
     //commence query and returns false if query failed
     $result = mysql_query($makeDevicesQuery);
     //announce whether a job was created and query was successful
     if (!$result) {
         echo "Device Failed to be added to devices table<BR><BR>";
         die('Invalid query: ' . mysql_error());
     } else {
         echo "Device added to devices table!<br>";
     }
 }
function main()
{
    //check for any forms submitted
    echo "<script> ignoreCount = 0;</script>";
    echo "<script>jobCount = 0;</script>";
    $formMessage = "";
    $formCheck = "False";
    //check if any of the forms were submitted
    if (isset($_POST['formIdentifier'])) {
        //logic for job claim,unclaim, and resolve logic
        if ($_POST['claimStatButt'] == 1) {
            $viewerInfoQuery = "";
            //get info for processing
            $jobInfoQuery = "SELECT * FROM `jobs` WHERE id=" . $_POST['formIdentifier'];
            //send query
            $jobInfo = queryFunc($jobInfoQuery);
            //process query
            $jobdata = mysql_fetch_assoc($jobInfo);
            $claimQuery = "SELECT COUNT(*) as count FROM jobs WHERE STATUS<3 && bypassLimit=0 && claimedby='" . $_SESSION['loginid'] . "'";
            $claimResult = queryFunc($claimQuery);
            $numClaimed = mysql_fetch_assoc($claimResult);
            if ($numClaimed['count'] < 3) {
                // If they haven't claimed too many jobs already
                if ($jobdata['requirement_id'] == '0') {
                    // If they have the skill needed to do the job
                    if ($jobdata['repeatable'] != 1) {
                        //make a query to claim a job
                        $claimStatQuery = "UPDATE `jobs` SET `claimedby`=" . $_SESSION['loginid'] . " WHERE id=" . $_POST['formIdentifier'];
                        queryFunc($claimStatQuery);
                        //give a status message
                        $formMessage = "You have Successfully Claimed a Job";
                    } else {
                        //make the duplicate job if its repeatable
                        $addDupJobQuery = "INSERT INTO `jobs`(`name`, `description`, `skillcatid`, `status`, `points`, `repeatable`, `limitone`, `claimedby`, `priority`, `bypassLimit`) VALUES ('" . $jobdata['name'] . "','" . $jobdata['description'] . "'," . $jobdata['skillcatid'] . ",1 ," . $jobdata['points'] . ",1 ," . $jobdata['limitone'] . "," . $_SESSION['loginid'] . "," . $jobdata['priority'] . "," . $jobdata['bypassLimit'] . ")";
                        queryFunc($addDupJobQuery);
                        //ignore the original job so they cant claim it multiple times
                        $ignoreJobQuery = "INSERT INTO `ignorejobs`(`studentname`, `jobid`) VALUES (" . $_SESSION['loginid'] . "," . $_POST['formIdentifier'] . ")";
                        queryFunc($ignoreJobQuery);
                        //give a status message
                        $formMessage = "You have Successfully Claimed a Repeatable Job";
                    }
                    //give a status message
                    $formMessage = "You have Successfully Claimed a Job";
                } else {
                    $formMessage = "You do not have the required skill to claim that job.";
                }
            } else {
                $formMessage = "<p style='color:red;'>You can't claim this job, you are already working on " . $numClaimed['count'] . " jobs!!!</p>";
            }
        } else {
            if ($_POST['claimStatButt'] == 2) {
                //get info for processing
                $jobInfoQuery = "SELECT * FROM `jobs` WHERE id=" . $_POST['formIdentifier'];
                //send query
                $jobInfo = queryFunc($jobInfoQuery);
                //process query
                $jobdata = mysql_fetch_assoc($jobInfo);
                if ($jobdata['repeatable'] == 1) {
                    //make a query to unclaim a job
                    $claimStatQuery = "DELETE FROM `jobs` WHERE id=" . $_POST['formIdentifier'];
                    queryFunc($claimStatQuery);
                    $formMessage = "You have Successfully Unclaimed a Job";
                } else {
                    //make a query to unclaim a job
                    $claimStatQuery = "UPDATE `jobs` SET `claimedby`=0 WHERE id=" . $_POST['formIdentifier'];
                    queryFunc($claimStatQuery);
                    $formMessage = "You have Successfully Unclaimed a Job";
                }
            } else {
                if ($_POST['claimStatButt'] == 3) {
                    //make a query to resolve a job
                    $resolveQuery = "UPDATE `jobs` SET `status`=3 WHERE id=" . $_POST['formIdentifier'];
                    //send query
                    queryFunc($resolveQuery);
                    //get info for adding points
                    $jobInfoQuery = "SELECT * FROM `jobs` WHERE id=" . $_POST['formIdentifier'];
                    //send query
                    $jobInfo = queryFunc($jobInfoQuery);
                    //process query
                    $jobdata = mysql_fetch_assoc($jobInfo);
                    //make points query
                    $addPointsQuery = "INSERT INTO `points`(`job_id`, `student_id`, `points`, `category_id`) VALUES (" . $_POST['formIdentifier'] . "," . $_SESSION['loginid'] . "," . $jobdata['points'] . "," . $jobdata['skillcatid'] . ")";
                    //add points with query
                    queryFunc($addPointsQuery);
                    $formMessage = "You have Successfully Resolved a Job";
                } else {
                    if ($_POST['claimStatButt'] == 4) {
                        //ignore a job
                        $ignoreJobQuery = "INSERT INTO `ignorejobs`(`studentname`, `jobid`) VALUES (" . $_SESSION['loginid'] . "," . $_POST['formIdentifier'] . ")";
                        queryFunc($ignoreJobQuery);
                        $formMessage = "You have Successfully Ignored a Job";
                    } else {
                        if ($_POST['claimStatButt'] == 5) {
                            //unignore a job
                            $unignoreJobQuery = "DELETE FROM `ignorejobs` WHERE jobid =" . $_POST['formIdentifier'] . " AND studentname =" . $_SESSION['loginid'];
                            queryFunc($unignoreJobQuery);
                            $formMessage = "You have Successfully Unignored a Job";
                        }
                    }
                }
            }
        }
        $formCheck = "True";
        $_POST['jobsToList'] = $_SESSION['jobsection'];
    }
    //end of form check for claiming,unclaiming, resolving, and ignoring
    //determine how it should be sorted
    if (isset($_POST['sortButt'])) {
        switch ($_POST['sortButt']) {
            case 1:
                //if name is sorted
                if ($_SESSION['jobsortdirection'] == 1) {
                    //asc
                    $_SESSION['sortby'] = " ORDER BY name ASC;";
                    $_SESSION['jobsortdirection'] = 2;
                } else {
                    //desc
                    $_SESSION['sortby'] = " ORDER BY name DESC;";
                    $_SESSION['jobsortdirection'] = 1;
                }
                break;
                //sort by description
            //sort by description
            case 2:
                if ($_SESSION['jobsortdirection'] == 1) {
                    //asc
                    $_SESSION['sortby'] = " ORDER BY description ASC;";
                    $_SESSION['jobsortdirection'] = 2;
                } else {
                    //desc
                    $_SESSION['sortby'] = " ORDER BY description DESC;";
                    $_SESSION['jobsortdirection'] = 1;
                }
                break;
            case 3:
                //sort by name
                if ($_SESSION['jobsortdirection'] == 1) {
                    //asc
                    $_SESSION['sortby'] = " ORDER BY points ASC;";
                    $_SESSION['jobsortdirection'] = 2;
                } else {
                    //desc
                    $_SESSION['sortby'] = " ORDER BY points DESC;";
                    $_SESSION['jobsortdirection'] = 1;
                }
                break;
            case 4:
                // sort by category
                if ($_SESSION['jobsortdirection'] == 1) {
                    //asc
                    $_SESSION['sortby'] = " ORDER BY skillcatid ASC;";
                    $_SESSION['jobsortdirection'] = 2;
                } else {
                    //desc
                    $_SESSION['sortby'] = " ORDER BY skillcatid DESC;";
                    $_SESSION['jobsortdirection'] = 1;
                }
                break;
            case 5:
                //sort by who has claimed it
                if ($_SESSION['jobsortdirection'] == 1) {
                    //asc
                    $_SESSION['sortby'] = " ORDER BY claimedby ASC;";
                    $_SESSION['jobsortdirection'] = 2;
                } else {
                    //desc
                    $_SESSION['sortby'] = " ORDER BY claimedby DESC;";
                    $_SESSION['jobsortdirection'] = 1;
                }
                break;
            default:
                //this shouldnt ever happen
                $_SESSION['sortby'] = "";
        }
        $_POST['jobsToList'] = $_SESSION['jobsection'];
    } else {
        $_SESSION['sortby'] = "";
        $_SESSION['jobsortdirection'] = 0;
    }
    //check for what jobs should be displayed and how
    if (isset($_POST['jobsToList']) && $_POST['jobsToList'] == 1) {
        //display all jobs
        $jobQuery = "SELECT * FROM jobs " . $_SESSION['sortby'];
        echo "<style>.allButt{background:white;color:black;}</style>";
        $_SESSION['jobsection'] = "1";
    } else {
        if (isset($_POST['jobsToList']) && $_POST['jobsToList'] == 2) {
            //display all unclaimed jobs
            $jobQuery = "SELECT * FROM jobs WHERE claimedby=0" . $_SESSION['sortby'];
            echo "<style>.unclaimedButt{background:white;color:black;}</style>";
            $_SESSION['jobsection'] = "2";
        } else {
            if (isset($_POST['jobsToList']) && $_POST['jobsToList'] == 3) {
                //display only your jobs
                $jobQuery = "SELECT * FROM jobs WHERE claimedby=" . $_SESSION['loginid'] . $_SESSION['sortby'];
                echo "<style>.myButt{background:white;color:black;}</style>";
                $_SESSION['jobsection'] = "3";
            } else {
                if (isset($_POST['showIgnored']) && $_POST['showIgnored'] == 1) {
                    //display all jobs with ignored jobs
                    $jobQuery = "SELECT * FROM jobs " . $_SESSION['sortby'];
                    echo "<style>.allButt{background:white;color:black;}</style>";
                    $_SESSION['jobsection'] = "1";
                    $_SESSION['showIgnoredJobs'] = "True";
                } else {
                    if (isset($_POST['showIgnored']) && $_POST['showIgnored'] == 2) {
                        //display all jobs
                        $jobQuery = "SELECT * FROM jobs " . $_SESSION['sortby'];
                        echo "<style>.allButt{background:white;color:black;}</style>";
                        $_SESSION['jobsection'] = "1";
                        $_SESSION['showIgnoredJobs'] = "False";
                    } else {
                        //display all jobs if no button has been selected yet
                        $jobQuery = "SELECT * FROM jobs WHERE claimedby=" . $_SESSION['loginid'];
                        echo "<style>.myButt{background:white;color:black;}</style>";
                        $_SESSION['jobsection'] = "3";
                    }
                }
            }
        }
    }
    //add the job display buttons to the screen
    echo "\n  <div class='jobDisplayButtons' name='jobDisplay'>\n    <form method='post' name='jobdisplaybutts'>\n\t\t\n    <button class='myButt' type='submit' name='jobsToList' value='3'>My Jobs</button>\n\t\t\n    <button class='unclaimedButt' type='submit' name='jobsToList' value='2'>Unclaimed Jobs</button>\n\t\t\n    <button class='allButt' type='submit' name='jobsToList' value='1'>All Jobs</button>\n\t\t\n\t\t<p id='status' style='float:right;font:45px;margin:25px 10px 0 0'>\n\t\t\tStatus: " . $formMessage . "\n\t\t</p>\n\t\t\n\t\t</form>\n  </div>\n  ";
    //load you dang css
    //commence query                <-- wats this????????????
    $jobQueryResult = mysql_query($jobQuery);
    //make a table
    echo "\n\t<center>\n\t\t<table style='width:100%;margin-bottom:10px;'>\n\t\t<tr>\n\t\t\t<form method='post' name='sortButtons'>\n\t\t\t\t<td><button class='sortRowButts' type='submit' name='sortButt' value='1'>Job Name</button></td>\n\t\t\t\t<td><button class='sortRowButts' type='submit' name='sortButt' value='2'>Job Description</button></td>\n\t\t\t\t<td><button class='sortRowButts' type='submit' name='sortButt' value='3'>Job Points</button></td>\n\t\t\t\t<td><button class='sortRowButts' type='submit' name='sortButt' value='4'>Job Category</button></td>\n\t\t\t\t<td><button class='sortRowButts' type='submit' name='sortButt' value='5'>Claim Status</button></td>\n\t\t\t</form>\n\t\t</tr>";
    //create an object for every job
    while ($jobdata = mysql_fetch_assoc($jobQueryResult)) {
        $job[$jobdata['id']] = new jobs($jobdata['id'], $jobdata['name'], $jobdata['description'], $jobdata['skillcatid'], $jobdata['status'], $jobdata['points'], $jobdata['repeatable'], $jobdata['limitone'], $jobdata['claimedby'], $jobdata['priority'], $jobdata['bypassLimit']);
        $job[$jobdata['id']]->printJob();
        //print the row for a job
        echo "<script>jobCount++;</script>";
    }
    //print the job count to the screen
    if ($formCheck == "False") {
        echo "\n\t\t<script>\n\t\t\tdocument.getElementById('status').innerHTML = 'Status: '+(jobCount - ignoreCount)+' Jobs were retrieved!';\n\t\t</script>\n\t\t";
    }
    //finish the table
    echo "</table></center>";
    if (isset($_SESSION['showIgnoredJobs']) && $_SESSION['showIgnoredJobs'] == "False" && $_SESSION['jobsection'] != "3") {
        echo "\n\t<form name='ignoreShow' method='POST'>\n\t<button type='submit' name='showIgnored' value='1'>Show Ignored Jobs</button>\n\t</form>\n\t";
    } else {
        if (isset($_SESSION['showIgnoredJobs']) && $_SESSION['showIgnoredJobs'] == "True" && $_SESSION['jobsection'] != "3") {
            echo "\n\t\t\n\t<form name='ignoreShow' method='POST'>\n\t<button type='submit' name='showIgnored' value='2'>Hide Ignored Jobs</button>\n\t</form>\n\t";
        }
    }
}
 function jobCategoryAndNameFunc($type)
 {
     //determine what to query
     if ($type == 1) {
         //make a query for category name
         $jobcategoryAndNameQuery = "SELECT `category` FROM `skillcategories` WHERE id=" . $this->job_Category;
         $placeholder = "category";
     } else {
         //make a query for persons name
         $jobcategoryAndNameQuery = "SELECT `name` FROM `students` WHERE id=" . $this->job_ClaimedBy;
         $placeholder = "name";
     }
     //do query and process it
     while ($data = mysql_fetch_assoc(queryFunc($jobcategoryAndNameQuery))) {
         return $data[$placeholder];
     }
 }