From 9bf07631e00b13d50991a855b0bdaedbbf94e91b Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Wed, 15 Jul 2015 14:19:55 +0000 Subject: [PATCH] Fix custom field order renumbering to keep at multiples of 10. --- admin/inc/class.customfields.inc.php | 5 ++- phpgwapi/inc/class.egw_customfields.inc.php | 47 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/admin/inc/class.customfields.inc.php b/admin/inc/class.customfields.inc.php index ebddb2a213..0d56406f4e 100644 --- a/admin/inc/class.customfields.inc.php +++ b/admin/inc/class.customfields.inc.php @@ -432,7 +432,10 @@ class customfields } // Include type-specific value help - $content['options'] = lang(self::$type_option_help); + foreach(self::$type_option_help as $key => $value) + { + $content['options'][$key] = lang($value); + } $content['statustext'] = $content['options'][$content['cf_type']]; $content['attributes'] = self::$type_attribute_flags; diff --git a/phpgwapi/inc/class.egw_customfields.inc.php b/phpgwapi/inc/class.egw_customfields.inc.php index 0e8f8046fc..622f0c7c64 100755 --- a/phpgwapi/inc/class.egw_customfields.inc.php +++ b/phpgwapi/inc/class.egw_customfields.inc.php @@ -365,6 +365,43 @@ class egw_customfields implements IteratorAggregate { $op = $cf['id'] ? 'update' : 'insert'; + // Check to see if field order needs to be re-done + $update = array(); + + $cfs = egw_customfields::get($cf['app'], true); + $old = $cfs[$cf['name']]; + + // Add new one in for numbering + if(!$cf['id']) + { + $cfs[$cf['name']] = $cf; + } + + if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0) + { + $cfs[$cf['name']]['order'] = $cf['order']; + uasort($cfs, function($a1, $a2){ + return $a1['order'] - $a2['order']; + }); + $n = 0; + foreach($cfs as $old_cf) + { + $n += 10; + if($old_cf['order'] != $n) + { + $old_cf['order'] = $n; + if($old_cf['name'] != $cf['name']) + { + $update[] = $old_cf; + } + else + { + $cf['order'] = $n; + } + } + } + } + self::$db->$op(self::TABLE, array( 'cf_label' => $cf['label'], 'cf_type' => $cf['type'], @@ -383,6 +420,16 @@ class egw_customfields implements IteratorAggregate 'cf_app' => $cf['app'], ), __LINE__, __FILE__); + foreach($update as $old_cf) + { + self::$db->$op(self::TABLE, array( + 'cf_order' => $old_cf['order'], + ), array( + 'cf_name' => $old_cf['name'], + 'cf_app' => $old_cf['app'], + ), __LINE__, __FILE__); + } + self::invalidate_cache($cf['app']); }