Index: trunk/kernel/units/languages/languages_config.php
===================================================================
diff -u -N -r1566 -r1763
--- trunk/kernel/units/languages/languages_config.php (.../languages_config.php) (revision 1566)
+++ trunk/kernel/units/languages/languages_config.php (.../languages_config.php) (revision 1763)
@@ -117,6 +117,7 @@
'DecimalPoint' => Array('type' => 'string','not_null' => '1','default' => '.'),
'ThousandSep' => Array('type' => 'string','not_null' => '1','default' => ','),
'Charset' => Array('type' => 'string','not_null' => '1','default' => '','required'=>1),
+ 'UnitSystem' => Array('type' => 'int','not_null' => '1','default' => '1','formatter' => 'kOptionsFormatter','options' => Array(1 => 'la_Metric', 2 => 'la_US_UK'),'use_phrases' => 1),
),
'VirtualFields' => Array(
Index: trunk/admin/install/upgrades/inportal_upgrade_v1.1.0.sql
===================================================================
diff -u -N -r1588 -r1763
--- trunk/admin/install/upgrades/inportal_upgrade_v1.1.0.sql (.../inportal_upgrade_v1.1.0.sql) (revision 1588)
+++ trunk/admin/install/upgrades/inportal_upgrade_v1.1.0.sql (.../inportal_upgrade_v1.1.0.sql) (revision 1763)
@@ -17,4 +17,6 @@
INSERT INTO ConfigurationAdmin VALUES ('Email_As_Login', 'la_Text_General', 'la_use_emails_as_login', 'checkbox', NULL, NULL, 1, 0);
INSERT INTO ConfigurationValues VALUES ('Email_As_Login', '1', 'In-Portal:Users', 'in-portal:configure_users');
+ALTER TABLE Language ADD COLUMN UnitSystem TINYINT DEFAULT '1' NOT NULL;
+
UPDATE Modules SET Version = '1.1.0' WHERE Name = 'In-Portal';
\ No newline at end of file
Index: trunk/core/kernel/application.php
===================================================================
diff -u -N -r1723 -r1763
--- trunk/core/kernel/application.php (.../application.php) (revision 1723)
+++ trunk/core/kernel/application.php (.../application.php) (revision 1763)
@@ -228,6 +228,7 @@
$this->registerClass('kMultiLanguage', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kPasswordFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kCCDateFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kUnitFormatter', KERNEL_PATH.'/utility/formatters.php');
$this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php');
Index: trunk/admin/install/inportal_schema.sql
===================================================================
diff -u -N -r1588 -r1763
--- trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 1588)
+++ trunk/admin/install/inportal_schema.sql (.../inportal_schema.sql) (revision 1763)
@@ -265,6 +265,7 @@
DecimalPoint char(2) NOT NULL default '.',
ThousandSep char(1) NOT NULL default ',',
Charset varchar(20) NOT NULL default '',
+ UnitSystem tinyint(4) NOT NULL default '1',
PRIMARY KEY (LanguageId)
)
Index: trunk/kernel/admin_templates/regional/languages_edit.tpl
===================================================================
diff -u -N -r1662 -r1763
--- trunk/kernel/admin_templates/regional/languages_edit.tpl (.../languages_edit.tpl) (revision 1662)
+++ trunk/kernel/admin_templates/regional/languages_edit.tpl (.../languages_edit.tpl) (revision 1763)
@@ -71,6 +71,7 @@
+
">
Index: trunk/core/kernel/utility/formatters.php
===================================================================
diff -u -N -r1560 -r1763
--- trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 1560)
+++ trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 1763)
@@ -842,63 +842,159 @@
}
+/**
+ * Credit card expiration date formatter
+ *
+ */
+class kCCDateFormatter extends kFormatter
+{
+ function PrepareOptions($field_name, &$field_options, &$object)
+ {
+ $add_fields = Array();
+
+ $i = 1;
+ $options = Array('00' => '');
+ while($i <= 12)
+ {
+ $options[ sprintf('%02d',$i) ] = sprintf('%02d',$i);
+ $i++;
+ }
+ $add_fields[ $field_options['month_field'] ] = Array('formatter'=>'kOptionsFormatter', 'options' => $options, 'not_null' => true, 'default' => '00');
+ $add_fields[ $field_options['year_field'] ] = Array('type' => 'string', 'default' => '');
+
+ $add_fields = array_merge_recursive2($add_fields, $object->VirtualFields);
+ $object->setVirtualFields($add_fields);
+ }
+
+ function UpdateSubFields($field, $value, &$options, &$object)
+ {
+ if(!$value) return false;
+ $date = explode('/', $value);
+ $object->SetDBField( $options['month_field'], $date[0] );
+ $object->SetDBField( $options['year_field'], $date[1] );
+ }
+
/**
- * Credit card expiration date formatter
+ * Will work in future if we could attach 2 formatters to one field
*
+ * @param string $value
+ * @param string $field_name
+ * @param kBase $object
+ * @return string
*/
- class kCCDateFormatter extends kFormatter
+ function Parse($value, $field_name, &$object)
{
- function PrepareOptions($field_name, &$field_options, &$object)
+// if ( is_null($value) ) return '';
+
+ $options = $object->GetFieldOptions($field_name);
+
+ $month = $object->GetDirtyField($options['month_field']);
+ $year = $object->GetDirtyField($options['year_field']);
+
+ if( !(int)$month && !(int)$year ) return NULL;
+ $is_valid = ($month >= 1 && $month <= 12) && ($year >= 0 && $year <= 99);
+
+ if(!$is_valid) $object->FieldErrors[$field_name]['pseudo'] = 'bad_type';
+ return $month.'/'.$year;
+ }
+
+}
+
+class kUnitFormatter extends kFormatter {
+
+ function PrepareOptions($field_name, &$field_options, &$object)
+ {
+ if( !isset($field_options['master_field']) )
{
+ $regional =& $this->Application->recallObject('lang.current');
$add_fields = Array();
-
- $i = 1;
- $options = Array('00' => '');
- while($i <= 12)
+ $options = Array('type' => 'int','error_field' => $field_name,'master_field' => $field_name,'formatter' => 'kUnitFormatter');
+ $options = array_merge_recursive2($field_options, $options);
+ switch( $regional->GetDBField('UnitSystem') )
{
- $options[ sprintf('%02d',$i) ] = sprintf('%02d',$i);
- $i++;
+ case 2: // US/UK
+ $add_fields[$field_name.'_a'] = $options;
+ $add_fields[$field_name.'_b'] = $options;
+ break;
+ default:
}
- $add_fields[ $field_options['month_field'] ] = Array('formatter'=>'kOptionsFormatter', 'options' => $options, 'not_null' => true, 'default' => '00');
- $add_fields[ $field_options['year_field'] ] = Array('type' => 'string', 'default' => '');
-
$add_fields = array_merge_recursive2($add_fields, $object->VirtualFields);
$object->setVirtualFields($add_fields);
}
+ }
- function UpdateSubFields($field, $value, &$options, &$object)
+ function UpdateMasterFields($field, $value, &$options, &$object)
+ {
+ if( !isset($options['master_field']) )
{
- if(!$value) return false;
- $date = explode('/', $value);
- $object->SetDBField( $options['month_field'], $date[0] );
- $object->SetDBField( $options['year_field'], $date[1] );
+ $regional =& $this->Application->recallObject('lang.current');
+ switch( $regional->GetDBField('UnitSystem') )
+ {
+ case 2: // US/UK
+ $major = $object->GetDirtyField($field.'_a');
+ $minor = $object->GetDirtyField($field.'_b');
+ $value = $major / 2 + $minor / 32;
+ break;
+ default:
+ }
+ $object->SetDBField($field, $value);
}
-
- /**
- * Will work in future if we could attach 2 formatters to one field
- *
- * @param string $value
- * @param string $field_name
- * @param kBase $object
- * @return string
- */
- function Parse($value, $field_name, &$object)
+ }
+
+ function UpdateSubFields($field, $value, &$options, &$object)
+ {
+ if( !isset($options['master_field']) )
{
-// if ( is_null($value) ) return '';
-
- $options = $object->GetFieldOptions($field_name);
-
- $month = $object->GetDirtyField($options['month_field']);
- $year = $object->GetDirtyField($options['year_field']);
-
- if( !(int)$month && !(int)$year ) return NULL;
- $is_valid = ($month >= 1 && $month <= 12) && ($year >= 0 && $year <= 99);
-
- if(!$is_valid) $object->FieldErrors[$field_name]['pseudo'] = 'bad_type';
- return $month.'/'.$year;
+ $regional =& $this->Application->recallObject('lang.current');
+ switch( $regional->GetDBField('UnitSystem') )
+ {
+ case 2: // US/UK
+ $major = floor( $value / 0.5 );
+ $minor = ($value - $major * 0.5) * 32;
+ $major = $object->SetDBField($field.'_a', $major);
+ $minor = $object->SetDBField($field.'_b', $minor);
+ break;
+ default:
+ }
}
-
}
+
+/* function Format($value, $field_name, &$object, $format=null)
+ {
+ if( isset($field_options['master_field']) )
+ {
+ $regional =& $this->Application->recallObject('lang.current');
+ switch( $regional->GetDBField('UnitSystem') )
+ {
+ case 2: // US/UK
+ $major = floor( $value / 0.5 );
+ $minor = $value - $major;
+ $major = $object->SetDBField($field_name.'_a', $major);
+ $minor = $object->SetDBField($field_name.'_b', $minor);
+ break;
+ default:
+ }
+ }
+ return parent::Format($value, $field_name, $object);
+ }*/
+
+ /*function Parse($value, $field_name, &$object)
+ {
+ $regional =& $this->Application->recallObject('lang.current');
+ switch($regional->GetDBField('UnitSystem'))
+ {
+ case 1: // metric
+ return $object->GetDBField('UnitSystem_a');
+ break;
+ case 2: // US/UK
+ return $object->GetDBField('UnitSystem_a') * 0.5 +
+ $object->GetDBField('UnitSystem_b') * 0.5 / 16;
+ break;
+ default:
+ }
+ }*/
+
+}
?>
Index: trunk/core/units/languages/languages_config.php
===================================================================
diff -u -N -r1566 -r1763
--- trunk/core/units/languages/languages_config.php (.../languages_config.php) (revision 1566)
+++ trunk/core/units/languages/languages_config.php (.../languages_config.php) (revision 1763)
@@ -117,6 +117,7 @@
'DecimalPoint' => Array('type' => 'string','not_null' => '1','default' => '.'),
'ThousandSep' => Array('type' => 'string','not_null' => '1','default' => ','),
'Charset' => Array('type' => 'string','not_null' => '1','default' => '','required'=>1),
+ 'UnitSystem' => Array('type' => 'int','not_null' => '1','default' => '1','formatter' => 'kOptionsFormatter','options' => Array(1 => 'la_Metric', 2 => 'la_US_UK'),'use_phrases' => 1),
),
'VirtualFields' => Array(