Procházet zdrojové kódy

Change date/time inputs in project form; add nesbot/carbon library

Alan Lam před 5 roky
rodič
revize
c898bbfaa5

+ 2 - 1
composer.json

@@ -12,6 +12,7 @@
     "ext-mbstring": "*",
     "ext-mbstring": "*",
     "robmorgan/phinx": "^0.11.1",
     "robmorgan/phinx": "^0.11.1",
 	  "ext-readline": "*",
 	  "ext-readline": "*",
-	  "ext-simplexml": "*"
+	  "ext-simplexml": "*",
+    "nesbot/carbon": "^2.50"
   }
   }
 }
 }

+ 269 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
         "This file is @generated automatically"
     ],
     ],
-    "content-hash": "fa97f12a32a3704f46b0ebcbcf64686c",
+    "content-hash": "4570d5746e1c6ae231b08dbcfd4d228c",
     "packages": [
     "packages": [
         {
         {
             "name": "cakephp/cache",
             "name": "cakephp/cache",
@@ -582,6 +582,99 @@
             ],
             ],
             "time": "2020-06-29T13:22:24+00:00"
             "time": "2020-06-29T13:22:24+00:00"
         },
         },
+        {
+            "name": "nesbot/carbon",
+            "version": "2.50.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/briannesbitt/Carbon.git",
+                "reference": "f47f17d17602b2243414a44ad53d9f8b9ada5fdb"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f47f17d17602b2243414a44ad53d9f8b9ada5fdb",
+                "reference": "f47f17d17602b2243414a44ad53d9f8b9ada5fdb",
+                "shasum": ""
+            },
+            "require": {
+                "ext-json": "*",
+                "php": "^7.1.8 || ^8.0",
+                "symfony/polyfill-mbstring": "^1.0",
+                "symfony/translation": "^3.4 || ^4.0 || ^5.0"
+            },
+            "require-dev": {
+                "doctrine/orm": "^2.7",
+                "friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
+                "kylekatarnls/multi-tester": "^2.0",
+                "phpmd/phpmd": "^2.9",
+                "phpstan/extension-installer": "^1.0",
+                "phpstan/phpstan": "^0.12.54",
+                "phpunit/phpunit": "^7.5.20 || ^8.5.14",
+                "squizlabs/php_codesniffer": "^3.4"
+            },
+            "bin": [
+                "bin/carbon"
+            ],
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.x-dev",
+                    "dev-3.x": "3.x-dev"
+                },
+                "laravel": {
+                    "providers": [
+                        "Carbon\\Laravel\\ServiceProvider"
+                    ]
+                },
+                "phpstan": {
+                    "includes": [
+                        "extension.neon"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Carbon\\": "src/Carbon/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Brian Nesbitt",
+                    "email": "brian@nesbot.com",
+                    "homepage": "https://markido.com"
+                },
+                {
+                    "name": "kylekatarnls",
+                    "homepage": "https://github.com/kylekatarnls"
+                }
+            ],
+            "description": "An API extension for DateTime that supports 281 different languages.",
+            "homepage": "https://carbon.nesbot.com",
+            "keywords": [
+                "date",
+                "datetime",
+                "time"
+            ],
+            "support": {
+                "issues": "https://github.com/briannesbitt/Carbon/issues",
+                "source": "https://github.com/briannesbitt/Carbon"
+            },
+            "funding": [
+                {
+                    "url": "https://opencollective.com/Carbon",
+                    "type": "open_collective"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/nesbot/carbon",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-06-28T22:38:45+00:00"
+        },
         {
         {
             "name": "paragonie/random_compat",
             "name": "paragonie/random_compat",
             "version": "v9.99.99",
             "version": "v9.99.99",
@@ -1897,6 +1990,179 @@
             ],
             ],
             "time": "2020-07-08T08:27:49+00:00"
             "time": "2020-07-08T08:27:49+00:00"
         },
         },
+        {
+            "name": "symfony/translation",
+            "version": "v5.3.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/translation.git",
+                "reference": "380b8c9e944d0e364b25f28e8e555241eb49c01c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/translation/zipball/380b8c9e944d0e364b25f28e8e555241eb49c01c",
+                "reference": "380b8c9e944d0e364b25f28e8e555241eb49c01c",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=7.2.5",
+                "symfony/deprecation-contracts": "^2.1",
+                "symfony/polyfill-mbstring": "~1.0",
+                "symfony/polyfill-php80": "^1.15",
+                "symfony/translation-contracts": "^2.3"
+            },
+            "conflict": {
+                "symfony/config": "<4.4",
+                "symfony/dependency-injection": "<5.0",
+                "symfony/http-kernel": "<5.0",
+                "symfony/twig-bundle": "<5.0",
+                "symfony/yaml": "<4.4"
+            },
+            "provide": {
+                "symfony/translation-implementation": "2.3"
+            },
+            "require-dev": {
+                "psr/log": "~1.0",
+                "symfony/config": "^4.4|^5.0",
+                "symfony/console": "^4.4|^5.0",
+                "symfony/dependency-injection": "^5.0",
+                "symfony/finder": "^4.4|^5.0",
+                "symfony/http-kernel": "^5.0",
+                "symfony/intl": "^4.4|^5.0",
+                "symfony/polyfill-intl-icu": "^1.21",
+                "symfony/service-contracts": "^1.1.2|^2",
+                "symfony/yaml": "^4.4|^5.0"
+            },
+            "suggest": {
+                "psr/log-implementation": "To use logging capability in translator",
+                "symfony/config": "",
+                "symfony/yaml": ""
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "Resources/functions.php"
+                ],
+                "psr-4": {
+                    "Symfony\\Component\\Translation\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Provides tools to internationalize your application",
+            "homepage": "https://symfony.com",
+            "support": {
+                "source": "https://github.com/symfony/translation/tree/v5.3.3"
+            },
+            "funding": [
+                {
+                    "url": "https://symfony.com/sponsor",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/fabpot",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-06-27T12:22:47+00:00"
+        },
+        {
+            "name": "symfony/translation-contracts",
+            "version": "v2.4.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/translation-contracts.git",
+                "reference": "95c812666f3e91db75385749fe219c5e494c7f95"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/95c812666f3e91db75385749fe219c5e494c7f95",
+                "reference": "95c812666f3e91db75385749fe219c5e494c7f95",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=7.2.5"
+            },
+            "suggest": {
+                "symfony/translation-implementation": ""
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-main": "2.4-dev"
+                },
+                "thanks": {
+                    "name": "symfony/contracts",
+                    "url": "https://github.com/symfony/contracts"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Contracts\\Translation\\": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Nicolas Grekas",
+                    "email": "p@tchwork.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Generic abstractions related to translation",
+            "homepage": "https://symfony.com",
+            "keywords": [
+                "abstractions",
+                "contracts",
+                "decoupling",
+                "interfaces",
+                "interoperability",
+                "standards"
+            ],
+            "support": {
+                "source": "https://github.com/symfony/translation-contracts/tree/v2.4.0"
+            },
+            "funding": [
+                {
+                    "url": "https://symfony.com/sponsor",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/fabpot",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-03-23T23:28:01+00:00"
+        },
         {
         {
             "name": "symfony/yaml",
             "name": "symfony/yaml",
             "version": "v5.1.3",
             "version": "v5.1.3",
@@ -1979,5 +2245,6 @@
         "ext-readline": "*",
         "ext-readline": "*",
         "ext-simplexml": "*"
         "ext-simplexml": "*"
     },
     },
-    "platform-dev": []
+    "platform-dev": [],
+    "plugin-api-version": "2.0.0"
 }
 }

+ 34 - 27
controllers/project_add.php

@@ -1,12 +1,14 @@
 <?php /** @noinspection PhpUnhandledExceptionInspection */
 <?php /** @noinspection PhpUnhandledExceptionInspection */
 
 
+use Carbon\CarbonImmutable;
+
 Core::addScript("public/js/app-project-form.js");
 Core::addScript("public/js/app-project-form.js");
 
 
 $page_title = "Add Project";
 $page_title = "Add Project";
 
 
 $customer = Customer::getForAdmin();
 $customer = Customer::getForAdmin();
 
 
-if(empty($customer)) throw new Exception("Customer not found.");
+if($customer === null) throw new Exception("Customer not found.");
 
 
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account/projects", "Projects");
 Core::addBreadcrumb("/account/projects", "Projects");
@@ -27,31 +29,31 @@ $location_ids = http::value("location_ids");
 $location_ids = explode(", ", $location_ids);
 $location_ids = explode(", ", $location_ids);
 $location_ids = array_filter($location_ids);
 $location_ids = array_filter($location_ids);
 
 
-$submit = http::value("submit");
+$submit = HTTP::value("submit");
 if($submit) {
 if($submit) {
 	try {
 	try {
 		Core::validateCSRFToken($submit);
 		Core::validateCSRFToken($submit);
 
 
-		$project->template_id = http::value("template_id", "int");
+		$project->template_id = HTTP::value("template_id", "int");
 		$project->setTemplateKeys(HTTP::value("template_keys"));
 		$project->setTemplateKeys(HTTP::value("template_keys"));
-		$project->name = http::value("name", "trim");
-		$project->test_count = http::value("test_count", "int");
-		$project->min_age = http::value("min_age", "int");
-		$project->max_age = http::value("max_age", "int");
-		$project->default_tester_fee = http::value("default_tester_fee", "float");
-		$project->time_of_day = http::value("time_of_day", "trim");
-		$project->tester_can_claim = http::value("tester_can_claim", "trim");
-
-		$date_start = http::getDateFromFields("date_start");
-		$date_deadline = http::getDateFromFields("date_deadline");
-		$date_report = http::getDateFromFields("date_report");
+		$project->name = HTTP::value("name", "trim");
+		$project->test_count = HTTP::value("test_count", "int");
+		$project->min_age = HTTP::value("min_age", "int");
+		$project->max_age = HTTP::value("max_age", "int");
+		$project->default_tester_fee = HTTP::value("default_tester_fee", "float");
+		$project->time_of_day = HTTP::value("time_of_day", "trim");
+		$project->tester_can_claim = HTTP::value("tester_can_claim", "trim");
+
+		$date_start = HTTP::value("date_start");
+		$date_deadline = HTTP::value("date_deadline");
+		$date_report = HTTP::value("date_report");
 
 
 		$form_exception = new FormException;
 		$form_exception = new FormException;
 
 
 		if(empty($project->template_id)) $form_exception->addError("Template is required.");
 		if(empty($project->template_id)) $form_exception->addError("Template is required.");
 		else {
 		else {
 			$template = Template::get($project->template_id);
 			$template = Template::get($project->template_id);
-			if($template->customer_id != $customer->id) $form_exception->addError("Invalid template selected.");
+			if((int) $template->customer_id !== (int) $customer->id) $form_exception->addError("Invalid template selected.");
 		}
 		}
 		if(empty($project->name)) $form_exception->addError("Name is required.");
 		if(empty($project->name)) $form_exception->addError("Name is required.");
 		if(empty($project->test_count)) $form_exception->addError("Test count is required.");
 		if(empty($project->test_count)) $form_exception->addError("Test count is required.");
@@ -64,30 +66,35 @@ if($submit) {
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 
 
-		$unix_start = strtotime($date_start . " 00:00:00");
-		$unix_deadline = strtotime($date_deadline . " 23:59:59");
-		$unix_report = null;
-		if(!empty($date_report)) {
-			$unix_report = strtotime($date_report . " 12:00:00");
-		}
+		$dt_start = CarbonImmutable::createFromFormat("Y-m-d", $date_start, "UTC");
+		if(!$dt_start) $form_exception->addError("Start Date is invalid.");
 
 
-		$project->dts_start = Util::getDateTime($unix_start);
-		$project->dts_deadline = Util::getDateTime($unix_deadline);
-		$project->dts_created = Util::getDateTime();
-		$project->dts_report = Util::getDateTime($unix_report);
+		$dt_deadline = CarbonImmutable::createFromFormat("Y-m-d", $date_deadline, "UTC");
+		if(!$dt_deadline) $form_exception->addError("Deadline is invalid.");
 
 
-		if($unix_start > $unix_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
+		$dt_report = null;
+		if($date_report) {
+			$dt_report = CarbonImmutable::createFromFormat("Y-m-d", $date_report, "UTC");
+			if(!$dt_report) $form_exception->addError("Report Month is invalid.");
+		}
+
+		if($dt_start && $dt_deadline && $dt_start > $dt_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
 
 
 		// Verify location IDs
 		// Verify location IDs
 		Location::load($location_ids);
 		Location::load($location_ids);
 		foreach($location_ids as $location_id) {
 		foreach($location_ids as $location_id) {
 			$location = Location::get($location_id);
 			$location = Location::get($location_id);
 			if(!$location) $form_exception->addError("An invalid location was picked.");
 			if(!$location) $form_exception->addError("An invalid location was picked.");
-			if($location->customer_id != $customer->id) $form_exception->addError("An invalid location was picked.");
+			if((int) $location->customer_id !== (int) $customer->id) $form_exception->addError("An invalid location was picked.");
 		}
 		}
 
 
 		if($form_exception->hasErrors()) throw $form_exception;
 		if($form_exception->hasErrors()) throw $form_exception;
 
 
+		$project->dts_start = (string) $dt_start->setTime(0, 0);
+		$project->dts_deadline = (string) $dt_deadline->setTime(23, 59, 59);
+		$project->dts_created = DB::dts();
+		$project->dts_report = $dt_report ? (string) $dt_report->setTime(12, 0, 0) : null;
+
 		$success = $project->commit();
 		$success = $project->commit();
 		if(!$success) throw new Exception("Project could not be added at this time. Please try again later.");
 		if(!$success) throw new Exception("Project could not be added at this time. Please try again later.");
 
 

+ 36 - 29
controllers/project_edit.php

@@ -1,9 +1,11 @@
-<?php
+<?php /** @noinspection PhpUnhandledExceptionInspection */
 
 
 /**
 /**
  * @var int $id
  * @var int $id
  */
  */
 
 
+use Carbon\CarbonImmutable;
+
 $project = Project::get($id);
 $project = Project::get($id);
 if(!$project) throw new Exception("Project not found.");
 if(!$project) throw new Exception("Project not found.");
 
 
@@ -30,34 +32,34 @@ if($submit) {
 	try {
 	try {
 		Core::validateCSRFToken($submit);
 		Core::validateCSRFToken($submit);
 
 
-		$new_location_ids = http::value("location_ids");
+		$new_location_ids = HTTP::value("location_ids");
 		$new_location_ids = explode(", ", $new_location_ids);
 		$new_location_ids = explode(", ", $new_location_ids);
 		$new_location_ids = array_filter($new_location_ids);
 		$new_location_ids = array_filter($new_location_ids);
 
 
 		$location_ids_to_add = array_diff($new_location_ids, $location_ids);
 		$location_ids_to_add = array_diff($new_location_ids, $location_ids);
 		$location_ids_to_delete = array_diff($location_ids, $new_location_ids);
 		$location_ids_to_delete = array_diff($location_ids, $new_location_ids);
 
 
-		$project->template_id = http::value("template_id", "int");
+		$project->template_id = HTTP::value("template_id", "int");
 		$project->setTemplateKeys(HTTP::value("template_keys"));
 		$project->setTemplateKeys(HTTP::value("template_keys"));
-		$project->name = http::value("name", "trim");
-		$project->test_count = http::value("test_count", "int");
-		$project->min_age = http::value("min_age", "int");
-		$project->max_age = http::value("max_age", "int");
-		$project->default_customer_fee = http::value("default_customer_fee", "float");
-		$project->default_tester_fee = http::value("default_tester_fee", "float");
-		$project->time_of_day = http::value("time_of_day", "trim");
-		$project->tester_can_claim = http::value("tester_can_claim", "trim");
-
-		$date_start = http::getDateFromFields("date_start");
-		$date_deadline = http::getDateFromFields("date_deadline");
-		$date_report = http::getDateFromFields("date_report");
+		$project->name = HTTP::value("name", "trim");
+		$project->test_count = HTTP::value("test_count", "int");
+		$project->min_age = HTTP::value("min_age", "int");
+		$project->max_age = HTTP::value("max_age", "int");
+		$project->default_customer_fee = HTTP::value("default_customer_fee", "float");
+		$project->default_tester_fee = HTTP::value("default_tester_fee", "float");
+		$project->time_of_day = HTTP::value("time_of_day", "trim");
+		$project->tester_can_claim = HTTP::value("tester_can_claim", "trim");
+
+		$date_start = HTTP::value("date_start");
+		$date_deadline = HTTP::value("date_deadline");
+		$date_report = HTTP::value("date_report");
 
 
 		$form_exception = new FormException;
 		$form_exception = new FormException;
 
 
 		if(empty($project->template_id)) $form_exception->addError("Template is required.");
 		if(empty($project->template_id)) $form_exception->addError("Template is required.");
 		else {
 		else {
 			$template = Template::get($project->template_id);
 			$template = Template::get($project->template_id);
-			if($template->customer_id != $customer->id) $form_exception->addError("Invalid template selected.");
+			if((int) $template->customer_id !== (int) $customer->id) $form_exception->addError("Invalid template selected.");
 		}
 		}
 		if(empty($project->name)) $form_exception->addError("Name is required.");
 		if(empty($project->name)) $form_exception->addError("Name is required.");
 		if(empty($project->test_count)) $form_exception->addError("Test count is required.");
 		if(empty($project->test_count)) $form_exception->addError("Test count is required.");
@@ -71,29 +73,34 @@ if($submit) {
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 
 
-		$unix_start = strtotime($date_start . " 00:00:00");
-		$unix_deadline = strtotime($date_deadline . " 23:59:59");
-		$unix_report = null;
-		if(!empty($date_report)) {
-			$unix_report = strtotime($date_report . " 12:00:00");
-		}
+		$dt_start = CarbonImmutable::createFromFormat("Y-m-d", $date_start, "UTC");
+		if(!$dt_start) $form_exception->addError("Start Date is invalid.");
 
 
-		$project->dts_start = Util::getDateTime($unix_start);
-		$project->dts_deadline = Util::getDateTime($unix_deadline);
-		$project->dts_report = is_null($unix_report) ? null : Util::getDateTime($unix_report);
+		$dt_deadline = CarbonImmutable::createFromFormat("Y-m-d", $date_deadline, "UTC");
+		if(!$dt_deadline) $form_exception->addError("Deadline is invalid.");
 
 
-		if($unix_start > $unix_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
+		$dt_report = null;
+		if($date_report) {
+			$dt_report = CarbonImmutable::createFromFormat("Y-m-d", $date_report, "UTC");
+			if(!$dt_report) $form_exception->addError("Report Month is invalid.");
+		}
+
+		if($dt_start && $dt_deadline && $dt_start > $dt_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
 
 
 		// Verify location IDs
 		// Verify location IDs
 		Location::load($location_ids_to_add);
 		Location::load($location_ids_to_add);
 		foreach($location_ids_to_add as $location_id) {
 		foreach($location_ids_to_add as $location_id) {
 			$location = Location::get($location_id);
 			$location = Location::get($location_id);
 			if(!$location) $form_exception->addError("An invalid location was picked.");
 			if(!$location) $form_exception->addError("An invalid location was picked.");
-			if($location->customer_id != $customer->id) $form_exception->addError("An invalid location was picked.");
+			if((int) $location->customer_id !== (int) $customer->id) $form_exception->addError("An invalid location was picked.");
 		}
 		}
 
 
 		if($form_exception->hasErrors()) throw $form_exception;
 		if($form_exception->hasErrors()) throw $form_exception;
 
 
+		$project->dts_start = (string) $dt_start->setTime(0, 0);
+		$project->dts_deadline = (string) $dt_deadline->setTime(23, 59, 59);
+		$project->dts_report = $dt_report ? (string) $dt_report->setTime(12, 0, 0) : null;
+
 		$success = $project->commit();
 		$success = $project->commit();
 		if(!$success) throw new Exception("Project could not be edited at this time. Please try again later.");
 		if(!$success) throw new Exception("Project could not be edited at this time. Please try again later.");
 
 
@@ -137,8 +144,8 @@ $project_locations = $project->getLocations();
 $project_location_ids = array_column($project_locations, "id");
 $project_location_ids = array_column($project_locations, "id");
 
 
 $locations = $customer->getLocations();
 $locations = $customer->getLocations();
-$locations = array_filter($locations, function(Location $location) use ($project_location_ids) {
-	if(in_array($location->id, $project_location_ids)) return true;
+$locations = array_filter($locations, static function(Location $location) use ($project_location_ids) {
+	if(in_array($location->id, $project_location_ids, false)) return true;
 	if($location->closed || $location->isArchived()) return false;
 	if($location->closed || $location->isArchived()) return false;
 	return true;
 	return true;
 });
 });

+ 11 - 0
db/migrations/20210716210434_change_project_dts_updated_nullable.php

@@ -0,0 +1,11 @@
+<?php
+
+use Phinx\Migration\AbstractMigration;
+
+class ChangeProjectDtsUpdatedNullable extends AbstractMigration {
+	public function change() {
+		$this->table("project")
+			->changeColumn("dts_updated", "datetime", ["null" => true])
+			->update();
+	}
+}

+ 0 - 35
engine/http.php

@@ -78,41 +78,6 @@ class HTTP {
 		return $date;
 		return $date;
 	}
 	}
 
 
-	/**
-	 * @param string $prefix
-	 * @return bool|string
-	 * @throws Exception
-	 */
-	public static function getDateTimeFromFields(string $prefix = "") {
-		$date = http::getDateFromFields($prefix);
-		if($date === false) return false;
-
-		if(empty($prefix)) {
-			$hour_field = "hour";
-			$minute_field = "minute";
-			$second_field = "second";
-		}
-		else {
-			$hour_field = $prefix . "_hour";
-			$minute_field = $prefix . "_minute";
-			$second_field = $prefix . "_second";
-		}
-
-		$hour = http::value($hour_field, "int");
-		$minute = http::value($minute_field, "int");
-		$second = http::value($second_field, "int");
-
-		if(strlen($hour) == 0) return false;
-		if(strlen($minute) == 0) return false;
-		if(strlen($second) == 0) return false;
-
-		list($hour, $minute, $second) = array_map(function($part) {
-			return str_pad($part, 2, "0", STR_PAD_LEFT);
-		}, [$hour, $minute, $second]);
-
-		return "$date $hour:$minute:$second";
-	}
-
 	/**
 	/**
 	 * @param string $key
 	 * @param string $key
 	 * @param string $validation
 	 * @param string $validation

+ 22 - 0
engine/project.php

@@ -1,5 +1,7 @@
 <?php /** @noinspection PhpIncludeInspection */
 <?php /** @noinspection PhpIncludeInspection */
 
 
+use Carbon\CarbonImmutable;
+
 /**
 /**
  * @property int $id
  * @property int $id
  * @property int $customer_id
  * @property int $customer_id
@@ -40,6 +42,14 @@ class Project extends Model {
 
 
 	// Static methods
 	// Static methods
 
 
+	public static function getTimeOfDayOptions(): array {
+		return [
+			self::TOD_ANYTIME => "Anytime",
+			self::TOD_DAYTIME => "Daytime",
+			self::TOD_NIGHTTIME => "Night",
+		];
+	}
+
 	/**
 	/**
 	 * @param string $processing_file
 	 * @param string $processing_file
 	 * @param Project[] $projects
 	 * @param Project[] $projects
@@ -517,4 +527,16 @@ class Project extends Model {
 		return $keys ?: [];
 		return $keys ?: [];
 	}
 	}
 
 
+	public function getDateTimeStart(): CarbonImmutable {
+		return CarbonImmutable::parse($this->dts_start, "UTC");
+	}
+
+	public function getDateTimeDeadline(): CarbonImmutable {
+		return CarbonImmutable::parse($this->dts_deadline, "UTC");
+	}
+
+	public function getDateTimeReport(): CarbonImmutable {
+		return CarbonImmutable::parse($this->dts_report, "UTC");
+	}
+
 }
 }

+ 26 - 19
public/js/app-project-form.js

@@ -5,35 +5,37 @@ $(function() {
 	$(document).on("click", "#not-selected-locations-list-group button", handleSelectButton);
 	$(document).on("click", "#not-selected-locations-list-group button", handleSelectButton);
 	$(document).on("click", "#selected-locations-list-group button", handleDeselectButton);
 	$(document).on("click", "#selected-locations-list-group button", handleDeselectButton);
 
 
-	$("input[data-filter-target]").keyup(function(event) {
+	$("input[data-filter-target]").on("input", event => {
 
 
-		let value = $(this).val().toLowerCase();
-		let target = $(this).data("filter-target");
+		const $input = $(event.currentTarget);
+
+		const value = $input.val().toLowerCase();
+		const target = $input.data("filter-target");
 
 
 		if(value.length == 0) {
 		if(value.length == 0) {
 			$(target).children().show();
 			$(target).children().show();
 			return true;
 			return true;
 		}
 		}
 
 
-		$(target).children().each(function() {
+		$(target).children().each((index, element) => {
 
 
 			let number = parseInt(value);
 			let number = parseInt(value);
-			var show;
+			let show;
 			if(isNaN(number)) {
 			if(isNaN(number)) {
-				show = $(this).data("filter-value").indexOf(value) != -1;
+				show = $(element).data("filter-value").indexOf(value) != -1;
 			}
 			}
 			else {
 			else {
-				let test1 = (number == $(this).data("location-id"));
-				let test2 = (number == $(this).data("internal-id"));
+				let test1 = (number == $(element).data("location-id"));
+				let test2 = (number == $(element).data("internal-id"));
 
 
 				show = test1 || test2;
 				show = test1 || test2;
 			}
 			}
 
 
 			if(show) {
 			if(show) {
-				$(this).show();
+				$(element).show();
 			}
 			}
 			else {
 			else {
-				$(this).hide();
+				$(element).hide();
 			}
 			}
 		});
 		});
 
 
@@ -48,7 +50,8 @@ $(function() {
 
 
 	const $templateDropdown = $("#template-id");
 	const $templateDropdown = $("#template-id");
 
 
-	$("#template-id, #time-of-day, #date-start-month, #date-start-year").on("change", () => autogenProjectName());
+	$("#template-id, #time-of-day, #date-start").on("change", () => autogenProjectName());
+
 	$templateDropdown.on("change", () => {
 	$templateDropdown.on("change", () => {
 		const keys = $templateDropdown.find("option:selected").data("keys");
 		const keys = $templateDropdown.find("option:selected").data("keys");
 		const keyCount = keys.length;
 		const keyCount = keys.length;
@@ -84,12 +87,16 @@ $(function() {
 
 
 	$("#template-id").trigger("change");
 	$("#template-id").trigger("change");
 
 
-	$("#autogen-name").on("change", event => {
-		const checked = event.currentTarget.checked;
+	const $autogenSwitch = $("#autogen-name");
+
+	$autogenSwitch.on("change", event => {
+		const checked = $autogenSwitch.prop("checked");
 		$("#name").prop("readonly", checked);
 		$("#name").prop("readonly", checked);
 		if(checked) autogenProjectName();
 		if(checked) autogenProjectName();
 	});
 	});
 
 
+
+
 });
 });
 
 
 function getCheckedTemplateKeys() {
 function getCheckedTemplateKeys() {
@@ -171,8 +178,7 @@ function refreshLocationIds() {
 
 
 function refreshLocationAlerts() {
 function refreshLocationAlerts() {
 
 
-	let count = 0;
-	count = $("#not-selected-locations-list-group .list-group-item").length;
+	let count = $("#not-selected-locations-list-group .list-group-item").length;
 	if(count > 0) {
 	if(count > 0) {
 		$("#not-selected-locations-alert").hide();
 		$("#not-selected-locations-alert").hide();
 	}
 	}
@@ -196,8 +202,9 @@ function autogenProjectName() {
 
 
 	const customerName = $("#customer-name").text();
 	const customerName = $("#customer-name").text();
 	const templateName = $.trim($("#template-id").find("option:selected").text());
 	const templateName = $.trim($("#template-id").find("option:selected").text());
-	const dateStartMonth = $("#date-start-month").find("option:selected").text();
-	const dateStartYear = $("#date-start-year").find("option:selected").text();
+
+	const dateStart = new Date($("#date-start").val());
+
 	const timeOfDay = $("#time-of-day").find("option:selected").text();
 	const timeOfDay = $("#time-of-day").find("option:selected").text();
 
 
 	const templateWords = templateName.split(" ");
 	const templateWords = templateName.split(" ");
@@ -211,8 +218,8 @@ function autogenProjectName() {
 
 
 	const parts = [];
 	const parts = [];
 	parts.push(customerName);
 	parts.push(customerName);
-	parts.push(dateStartMonth);
-	parts.push(dateStartYear);
+	parts.push(dateStart.toLocaleString("default", {month: "long"}));
+	parts.push(dateStart.getFullYear());
 	parts.push(templateInitials.join(""));
 	parts.push(templateInitials.join(""));
 
 
 	if(templateKeys.length > 0) {
 	if(templateKeys.length > 0) {

+ 16 - 81
views/project_form.php

@@ -9,23 +9,13 @@
  * @var Template $template
  * @var Template $template
  */
  */
 
 
-$date_start = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_start . " UTC")))[0];
-$date_start_parts = explode("-", $date_start);
+use Carbon\CarbonImmutable;
 
 
-$date_deadline = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_deadline . " UTC")))[0];
-$date_deadline_parts = explode("-", $date_deadline);
+$dt_start = $project->getDateTimeStart();
+$dt_deadline = $project->getDateTimeDeadline();
 
 
-$date_report_parts = [0, 0, 0];
-if($project->dts_report) {
-	$date_report = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_report . " UTC")))[0];
-	$date_report_parts = explode("-", $date_report);
-}
-
-$time_of_day_options = [
-	"A" => "Anytime",
-	"D" => "Daytime",
-	"N" => "Night",
-];
+$dt_report = $project->getDateTimeReport() ?: null;
+$date_report = $dt_report ? $dt_report->format("Y-m-d") : "";
 
 
 $name_readonly = $project->id ? "" : "readonly";
 $name_readonly = $project->id ? "" : "readonly";
 $autogen_checked = $project->id ? "" : "checked";
 $autogen_checked = $project->id ? "" : "checked";
@@ -39,10 +29,10 @@ if($project->id) {
 	}
 	}
 }
 }
 
 
-$selected_locations = array_filter($locations, function(Location $l) use ($location_ids) { return in_array($l->id, $location_ids); });
-$deselected_locations = array_filter($locations, function(Location $l) use ($location_ids) { return !in_array($l->id, $location_ids); });
+$selected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return in_array($l->id, $location_ids, false); });
+$deselected_locations = array_filter($locations, static function(Location $l) use ($location_ids) { return !in_array($l->id, $location_ids, false); });
 
 
-$output_locations = function(array $locations, bool $selected) use ($location_test) {
+$output_locations = static function(array $locations, bool $selected) use ($location_test) {
 	foreach($locations as $location) {
 	foreach($locations as $location) {
 		$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 		$address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 
 
@@ -136,7 +126,7 @@ $output_locations = function(array $locations, bool $selected) use ($location_te
 						<select class="form-control" name="template_id" id="template-id" required>
 						<select class="form-control" name="template_id" id="template-id" required>
 						<?php
 						<?php
 						foreach($templates as $template) {
 						foreach($templates as $template) {
-							$selected = ($template->id == $project->template_id) ? "selected" : "";
+							$selected = ((int) $template->id === (int) $project->template_id) ? "selected" : "";
 							$keys = $template->getTemplateKeys();
 							$keys = $template->getTemplateKeys();
 							$keys_json = json_encode($keys);
 							$keys_json = json_encode($keys);
 							?>
 							?>
@@ -190,8 +180,8 @@ $output_locations = function(array $locations, bool $selected) use ($location_te
 					<div class="col-sm">
 					<div class="col-sm">
 						<select class="form-control" name="time_of_day" id="time-of-day" required>
 						<select class="form-control" name="time_of_day" id="time-of-day" required>
 						<?php
 						<?php
-						foreach($time_of_day_options as $value => $display) {
-							$selected = ($value == $project->time_of_day) ? "selected" : "";
+						foreach(Project::getTimeOfDayOptions() as $value => $display) {
+							$selected = ($value === $project->time_of_day) ? "selected" : "";
 							?>
 							?>
 							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
 							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
 							<?php
 							<?php
@@ -206,7 +196,7 @@ $output_locations = function(array $locations, bool $selected) use ($location_te
 						<select class="form-control" name="tester_can_claim" id="tester-can-claim">
 						<select class="form-control" name="tester_can_claim" id="tester-can-claim">
 						<?php
 						<?php
 						foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
 						foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
-							$selected = ($value == $project->tester_can_claim) ? "selected" : "";
+							$selected = ($value === (int) $project->tester_can_claim) ? "selected" : "";
 							?>
 							?>
 							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
 							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
 							<?php
 							<?php
@@ -232,76 +222,21 @@ $output_locations = function(array $locations, bool $selected) use ($location_te
 					</div>
 					</div>
 				</div>
 				</div>
 				<div class="row mb-1">
 				<div class="row mb-1">
-					<label class="col-sm-4 col-form-label" for="date-start-day">Start Date</label>
+					<label class="col-sm-4 col-form-label" for="date-start">Start Date</label>
 					<div class="col-sm">
 					<div class="col-sm">
-						<label class="sr-only" for="date-start-day"></label>
-						<select class="form-control w-auto d-inline-block" name="date_start_day" id="date-start-day">
-							<option value="">Day</option>
-							<?php
-							Form::renderDayOptions($date_start_parts[2]);
-							?>
-						</select>
-						<label class="sr-only" for="date-start-month"></label>
-						<select class="form-control w-auto d-inline-block" name="date_start_month" id="date-start-month">
-							<option value="">Month</option>
-							<?php
-							Form::renderMonthOptions($date_start_parts[1]);
-							?>
-						</select>
-						<label class="sr-only" for="date-start-year"></label>
-						<select class="form-control w-auto d-inline-block" name="date_start_year" id="date-start-year">
-							<option value="">Year</option>
-							<?php
-							Form::renderYearOptions(2017, date("Y") + 1, $date_start_parts[0]);
-							?>
-						</select>
+						<input class="form-control" type="date" name="date_start" id="date-start" value="<?=$dt_start->format("Y-m-d")?>" required />
 					</div>
 					</div>
 				</div>
 				</div>
 				<div class="row mb-1">
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
 					<label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
 					<div class="col-sm">
 					<div class="col-sm">
-						<label for="date-deadline-day" class="sr-only">Day</label>
-						<select class="form-control w-auto d-inline-block" name="date_deadline_day" id="date-deadline-day">
-							<option value="">Day</option>
-							<?php
-							Form::renderDayOptions($date_deadline_parts[2]);
-							?>
-						</select>
-						<label for="date-deadline-month" class="sr-only">Month</label>
-						<select class="form-control w-auto d-inline-block" name="date_deadline_month" id="date-deadline-month">
-							<option value="">Month</option>
-							<?php
-							Form::renderMonthOptions($date_deadline_parts[1]);
-							?>
-						</select>
-						<label for="date-deadline-year" class="sr-only">Year</label>
-						<select class="form-control w-auto d-inline-block" name="date_deadline_year" id="date-deadline-year">
-							<option value="">Year</option>
-							<?php
-							Form::renderYearOptions(2017, date("Y") + 1, $date_deadline_parts[0]);
-							?>
-						</select>
+						<input class="form-control" type="date" name="date_deadline" id="date-deadline" value="<?=$dt_deadline->format("Y-m-d")?>" required />
 					</div>
 					</div>
 				</div>
 				</div>
 				<div class="row mb-1">
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
 					<label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
 					<div class="col-sm">
 					<div class="col-sm">
-						<input name="date_report_day" id="date-report-day" value="12" type="hidden" />
-
-						<label for="date-report-month"></label>
-						<select class="form-control w-auto d-inline-block" name="date_report_month" id="date-report-month">
-							<option value="">Month</option>
-							<?php
-							Form::renderMonthOptions($date_report_parts[1]);
-							?>
-						</select>
-						<label for="date-report-year"></label>
-						<select class="form-control w-auto d-inline-block" name="date_report_year" id="date-report-year">
-							<option value="">Year</option>
-							<?php
-							Form::renderYearOptions(2017, date("Y") + 1, $date_report_parts[0]);
-							?>
-						</select>
+						<input class="form-control" type="date" name="date_report" id="date-report" value="<?=$date_report?>" required />
 					</div>
 					</div>
 				</div>
 				</div>
 			</div>
 			</div>