array("min_range" => 1, "max_range" => 999999)); $Dept = filter_input(INPUT_POST, 'txtDept', FILTER_SANITIZE_STRIPPED); $DeptName = filter_input(INPUT_POST, 'txtDeptName', FILTER_SANITIZE_STRIPPED); $DeptAcctNum = filter_input(INPUT_POST, 'txtDeptAcct', FILTER_VALIDATE_INT, $acct_range); if ($Dept == NULL) { $errorMsg_Dept = "Please enter a Department ID"; } else if (strlen($Dept) != 3) { $errorMsg_Dept = "The Department ID needs to be 3 characters long."; } if ($DeptName == NULL) { $errorMsg_Dept_Name = "Please enter a Department Name"; } else if (strlen($DeptName) > 20) { $errorMsg_Dept_Name = "The Department Name can be no longer than 20 characters."; } if ($DeptAcctNum === NULL) { $errorMsg_Dept_Acct = "Please enter a Dept Acct #."; } else if ($DeptAcctNum === false) { $errorMsg_Dept_Acct = "The Dept Acct # must be a positive number."; } if (!empty($errorMsg_Dept) || !empty($errorMsg_Dept_Name) || !empty($errorMsg_Dept_Acct)) { include('departmentForm.php'); exit(); } } if (isset($_POST['btnDelete'])) { try { $bulk = new MongoDB\Driver\BulkWrite; $bulk->delete(['_id' => new MongoDB\BSON\ObjectId($ID)]); $mongodconn->executeBulkWrite('RobEmployee.Department', $bulk); header('Location: '. '../'); exit(); } catch (MongoDB\Driver\Exception\Exception $e) { $filename = basename(__FILE__); $output = 'Could not add to server: '; $errorException = $e->getMessage(); include('error.php'); exit(); } } if (isset($_POST['btnInsert'])) { try { $bulk = new MongoDB\Driver\BulkWrite; $doc = ['_id' => new MongoDB\BSON\ObjectID, 'department' => $Dept, 'department_name' => $DeptName, 'dept_acct_num' => $DeptAcctNum]; $bulk->insert($doc); $mongodconn->executeBulkWrite('RobEmployee.Department', $bulk); header('Location: '. '../index.php'); exit(); } catch (MongoDB\Driver\Exception\Exception $e) { $filename = basename(__FILE__); $output = 'Could not add to server: '; $errorException = $e->getMessage(); include('error.php'); exit(); } } if (isset($_POST['btnUpdate'])) { try { $bulk = new MongoDB\Driver\BulkWrite; $bulk->update(['_id' => new MongoDB\BSON\ObjectId($ID)], ['$set' => ['department' => $Dept, 'department_name' => $DeptName, 'dept_acct_num' => $DeptAcctNum]]); $mongodconn->executeBulkWrite('RobEmployee.Department', $bulk); header('Location: '. '../'); exit(); } catch (MongoDB\Driver\Exception\Exception $e) { $filename = basename(__FILE__); $output = 'Could not update database: '; $errorException = $e->getMessage(); include('error.php'); exit(); } } ?>