diff --git a/db/cats_schema.sql b/db/cats_schema.sql index 5807a8888..6fbd1dbcc 100755 --- a/db/cats_schema.sql +++ b/db/cats_schema.sql @@ -801,7 +801,7 @@ CREATE TABLE `joborder` ( `is_hot` int(1) NOT NULL DEFAULT '0', `openings` int(11) DEFAULT NULL, `city` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `state` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', + `state` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL, `start_date` datetime DEFAULT NULL, `date_created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `date_modified` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', diff --git a/lib/DatabaseConnection.php b/lib/DatabaseConnection.php index fcd6f3814..8f3f7e407 100755 --- a/lib/DatabaseConnection.php +++ b/lib/DatabaseConnection.php @@ -507,9 +507,9 @@ public function makeQueryString($string) */ public function makeQueryStringOrNULL($string) { - $string = trim($string); + $string = trim((string) $string); - if (empty($string)) + if ($string === '') { return 'NULL'; } diff --git a/lib/JobOrders.php b/lib/JobOrders.php index 43f7b69e3..ce46d55af 100755 --- a/lib/JobOrders.php +++ b/lib/JobOrders.php @@ -221,7 +221,7 @@ public function update($jobOrderID, $title, $companyJobID, $companyID, $this->_db->makeQueryString($status), $this->_db->makeQueryString($salary), $this->_db->makeQueryString($city), - $this->_db->makeQueryString($state), + $this->_db->makeQueryStringOrNULL($state), $this->_db->makeQueryInteger($departmentID), $this->_db->makeQueryInteger($recruiter), $this->_db->makeQueryInteger($owner), diff --git a/lib/StringUtility.php b/lib/StringUtility.php index fc0a845df..17ce4e6d4 100755 --- a/lib/StringUtility.php +++ b/lib/StringUtility.php @@ -605,8 +605,8 @@ public static function makeInitialName($firstName, $lastName, */ public static function makeCityStateString($city, $state) { - $city = trim($city); - $state = trim($state); + $city = trim((string) $city); + $state = trim((string) $state); if (!empty($city)) { diff --git a/modules/install/Schema.php b/modules/install/Schema.php index ae2842a7d..6be26b691 100755 --- a/modules/install/Schema.php +++ b/modules/install/Schema.php @@ -1494,6 +1494,10 @@ public static function get() } } ', + '378' => ' + ALTER TABLE `joborder` + CHANGE `state` `state` VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL; + ', ); } diff --git a/modules/joborders/Add.tpl b/modules/joborders/Add.tpl index 3040d1db4..af66cf0ed 100755 --- a/modules/joborders/Add.tpl +++ b/modules/joborders/Add.tpl @@ -167,9 +167,9 @@ selectedCompanyID !== false): ?> -  * + -  * + diff --git a/modules/joborders/Edit.tpl b/modules/joborders/Edit.tpl index feec3ed13..c7bf8364e 100755 --- a/modules/joborders/Edit.tpl +++ b/modules/joborders/Edit.tpl @@ -178,7 +178,7 @@ -  * + diff --git a/modules/joborders/JobOrdersUI.php b/modules/joborders/JobOrdersUI.php index 8fd8fce5c..18bd4ad72 100755 --- a/modules/joborders/JobOrdersUI.php +++ b/modules/joborders/JobOrdersUI.php @@ -825,7 +825,7 @@ private function onAdd() $notes = $this->getTrimmedInput('notes', $_POST); /* Bail out if any of the required fields are empty. */ - if (empty($title) || empty($type) || empty($city) || empty($state)) + if (empty($title) || empty($type) || empty($city)) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.'); } @@ -1163,7 +1163,7 @@ private function onEdit() $notes = $this->getTrimmedInput('notes', $_POST); /* Bail out if any of the required fields are empty. */ - if (empty($title) || empty($type) || empty($city) || empty($state)) + if (empty($title) || empty($type) || empty($city)) { CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.'); } diff --git a/modules/joborders/validator.js b/modules/joborders/validator.js index 352216087..f9045174a 100755 --- a/modules/joborders/validator.js +++ b/modules/joborders/validator.js @@ -16,7 +16,6 @@ function checkAddForm(form) errorMessage += checkCompany(); errorMessage += checkRecruiter(); errorMessage += checkCity(); - errorMessage += checkState(); errorMessage += checkOpenings(); if (errorMessage != "") @@ -36,7 +35,6 @@ function checkEditForm(form) errorMessage += checkCompany(); errorMessage += checkRecruiter(); errorMessage += checkCity(); - errorMessage += checkState(); errorMessage += checkOpenings(); errorMessage += checkOpeningsAvailable(); errorMessage += checkOwner(); @@ -135,26 +133,6 @@ function checkCity() return errorMessage; } -function checkState() -{ - var errorMessage = ""; - - fieldValue = document.getElementById("state").value; - fieldLabel = document.getElementById("stateLabel"); - if (fieldValue == "") - { - errorMessage = " - You must enter a state.\n"; - - fieldLabel.style.color = "#ff0000"; - } - else - { - fieldLabel.style.color = "#000"; - } - - return errorMessage; -} - function checkCompany() { var errorMessage = ""; @@ -336,6 +314,3 @@ function checkFilename() return errorMessage; } - - - diff --git a/src/OpenCATS/Entity/JobOrderRepository.php b/src/OpenCATS/Entity/JobOrderRepository.php index df182b4da..041114b28 100644 --- a/src/OpenCATS/Entity/JobOrderRepository.php +++ b/src/OpenCATS/Entity/JobOrderRepository.php @@ -91,7 +91,7 @@ function persist(JobOrder $jobOrder, \History $history) $this->databaseConnection->makeQueryInteger($jobOrder->getAvailableOpenings()), $this->databaseConnection->makeQueryString($jobOrder->getSalary()), $this->databaseConnection->makeQueryString($jobOrder->getCity()), - $this->databaseConnection->makeQueryString($jobOrder->getState()), + $this->databaseConnection->makeQueryStringOrNULL($jobOrder->getState()), $this->databaseConnection->makeQueryInteger($jobOrder->getDepartmentId()), $this->databaseConnection->makeQueryStringOrNULL($jobOrder->getStartDate()), $this->databaseConnection->makeQueryInteger($jobOrder->getEnteredBy()), @@ -117,4 +117,4 @@ function persist(JobOrder $jobOrder, \History $history) throw new JobOrderRepositoryException('errorPersistingJobOrder'); } } -} \ No newline at end of file +} diff --git a/src/OpenCATS/Tests/IntegrationTests/DatabaseConnectionTest.php b/src/OpenCATS/Tests/IntegrationTests/DatabaseConnectionTest.php index 7227efe9d..861984fc1 100644 --- a/src/OpenCATS/Tests/IntegrationTests/DatabaseConnectionTest.php +++ b/src/OpenCATS/Tests/IntegrationTests/DatabaseConnectionTest.php @@ -63,10 +63,12 @@ function testMakeQueryStringOrNULL() array('te\'st', "'te\\'st'"), array('\'; DELETE FROM test_table; SELECT \'', "'\'; DELETE FROM test_table; SELECT \''"), array('te\'s`t', "'te\\'s`t'"), + array('0', "'0'"), array(' ', 'NULL'), array(' ', 'NULL'), array(' ', 'NULL'), - array('', 'NULL') + array('', 'NULL'), + array(null, 'NULL') ); foreach ($strings as $key => $value) diff --git a/src/OpenCATS/Tests/UnitTests/StringUtilityTest.php b/src/OpenCATS/Tests/UnitTests/StringUtilityTest.php index 392a722d8..7a299856f 100644 --- a/src/OpenCATS/Tests/UnitTests/StringUtilityTest.php +++ b/src/OpenCATS/Tests/UnitTests/StringUtilityTest.php @@ -556,6 +556,44 @@ function testMakeFirstInitialName() ); } + function testMakeCityStateString() + { + $this->assertSame( + 'Chicago, IL', + StringUtility::makeCityStateString('Chicago', 'IL') + ); + + $this->assertSame( + 'Chicago', + StringUtility::makeCityStateString('Chicago', '') + ); + + $this->assertSame( + 'IL', + StringUtility::makeCityStateString('', 'IL') + ); + + $this->assertSame( + '', + StringUtility::makeCityStateString('', '') + ); + + $this->assertSame( + 'Chicago', + StringUtility::makeCityStateString('Chicago', null) + ); + + $this->assertSame( + 'IL', + StringUtility::makeCityStateString(null, 'IL') + ); + + $this->assertSame( + '', + StringUtility::makeCityStateString(null, null) + ); + } + /* Tests for escapeSingleQuotes(). */ function testEscapeSingleQuotes() { diff --git a/test/features/job-orders.feature b/test/features/job-orders.feature index 5341962b5..f4f4a5804 100644 --- a/test/features/job-orders.feature +++ b/test/features/job-orders.feature @@ -49,7 +49,6 @@ Feature: Job Orders Then I should see "Form Error" in alert popup And I should see "You must select a company" in alert popup And I should see "You must enter a city" in alert popup - And I should see "You must enter a state" in alert popup And I confirm the popup @javascript