From f650d8b5fe054770069d27a1e13fda042c532525 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 30 Nov 2015 16:10:23 +0000 Subject: [PATCH] Some more checks to avoid invalid status / percent combinations - changing type in edit dialog, and need to load default status for new type - changing status via context menu --- infolog/inc/class.infolog_bo.inc.php | 10 ++++++++++ infolog/inc/class.infolog_ui.inc.php | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php index ad794304e6..f5884019b9 100644 --- a/infolog/inc/class.infolog_bo.inc.php +++ b/infolog/inc/class.infolog_bo.inc.php @@ -804,10 +804,20 @@ class infolog_bo { $values['info_datecompleted'] = $user2server ? $this->user_time_now : $this->now; // set date completed to today if status == done } + // Check for valid status / percent combinations if (in_array($values['info_status'],array('done','billed'))) { $values['info_percent'] = 100; } + else if (in_array($values['info_status'], array('not-started'))) + { + $values['info_percent'] = 0; + } + else if ((int)$values['info_percent'] == 100 || $values['info_percent'] == 0) + { + // We change percent to match status, not status to match percent + $values['info_percent'] = 10; + } if ((int)$values['info_percent'] == 100 && !in_array($values['info_status'],array('done','billed','cancelled','archive'))) { //echo "check_defaults:"; _debug_array($this->status[$values['info_type']]); diff --git a/infolog/inc/class.infolog_ui.inc.php b/infolog/inc/class.infolog_ui.inc.php index 1d1c4f22e4..7bf742a448 100644 --- a/infolog/inc/class.infolog_ui.inc.php +++ b/infolog/inc/class.infolog_ui.inc.php @@ -1845,7 +1845,23 @@ class infolog_ui if (!array_key_exists($content['info_status'],$this->bo->status[$content['info_type']])) { $content['info_status'] = $this->bo->status['defaults'][$content['info_type']]; - if ($content['info_status'] != 'done') $content['info_datecompleted'] = ''; + // Make sure we don't end up with invalid status / percent combinations + if ($content['info_status'] != 'done') + { + $content['info_datecompleted'] = ''; + if((int)$content['info_percent'] === 100) + { + $content['info_percent'] = 10; + } + } + else + { + $content['info_percent'] = 100; + } + if($content['info_status'] != 'not-started' && (int)$content['info_percent'] == 0) + { + $content['info_percent'] = 10; + } } } else // new call via GET