[ghelda-devel] [42] Add an "array index" parameter to g_getFormattedFields |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/ghelda-devel Archives
]
Revision: 42
Author: odyx
Date: 2009-05-20 13:48:16 +0200 (Wed, 20 May 2009)
Log Message:
-----------
Add an "array index" parameter to g_getFormattedFields
Modified Paths:
--------------
trunk/inc/g_functions.php
Modified: trunk/inc/g_functions.php
===================================================================
--- trunk/inc/g_functions.php 2009-05-20 11:48:15 UTC (rev 41)
+++ trunk/inc/g_functions.php 2009-05-20 11:48:16 UTC (rev 42)
@@ -33,26 +33,39 @@
define('G_DB_PEOPLE_LOCALE','locale');
define('G_DB_PEOPLE_ID','people_id');
-function g_getFormattedField($ArrayVals,$type,$fieldName,$fieldSpec) {
+function g_getFormattedField($ArrayVals,$type,$fieldName,$fieldSpec, $fieldIndex = NULL) {
+ // Two different behaviours
+ // Normal behavior
+ $value = $ArrayVals[$fieldName];
+ $value_year = $ArrayVals[$fieldName.'_year'];
+ $value_month = $ArrayVals[$fieldName.'_month'];
+ $value_day = $ArrayVals[$fieldName.'_day'];
+ // Behaviour for multiply defined values
+ if(!is_null($fieldIndex)) {
+ $value = $value[$fieldIndex];
+ $value_year = $value_year[$fieldIndex];
+ $value_month = $value_month[$fieldIndex];
+ $value_day = $value_day[$fieldIndex];
+ }
// For dates
if(stripos($type,'date') !== false) {
// It's a date
- if(empty($ArrayVals[$fieldName.'_year']) || empty($ArrayVals[$fieldName.'_month']) || empty($ArrayVals[$fieldName.'_day'])) {
+ if(empty($value_year) || empty($value_month) || empty($value_day)) {
return '0-0-0';
- } elseif(checkdate((int)$ArrayVals[$fieldName.'_month'],(int)$ArrayVals[$fieldName.'_day'],(int)$ArrayVals[$fieldName.'_year'])) {
- return $ArrayVals[$fieldName.'_year'].'-'.$ArrayVals[$fieldName.'_month'].'-'.$ArrayVals[$fieldName.'_day'];
+ } elseif(checkdate((int)$value_month,(int)$value_day,(int)$value_year)) {
+ return $value_year.'-'.$value_month.'-'.$value_day;
}
} elseif(array_key_exists('ereg',$fieldSpec)) { // for fields which have a verification pattern
- if(ereg($fieldSpec['ereg'],$ArrayVals[$fieldName]) || empty($ArrayVals[$fieldName])) {
- return $ArrayVals[$fieldName];
+ if(ereg($fieldSpec['ereg'],$value) || empty($value)) {
+ return $value;
}
return false;
} elseif(array_key_exists('preg',$fieldSpec)) { // for fields which have a verification pattern
- if(preg_match($fieldSpec['preg'],$ArrayVals[$fieldName])|| empty($ArrayVals[$fieldName])) {
- return $ArrayVals[$fieldName];
+ if(preg_match($fieldSpec['preg'],$value)|| empty($value)) {
+ return $value;
}
} else {
- return $ArrayVals[$fieldName];
+ return $value;
}
return false;
}