Index: trunk/core/kernel/startup.php
===================================================================
diff -u -r3369 -r3431
--- trunk/core/kernel/startup.php (.../startup.php) (revision 3369)
+++ trunk/core/kernel/startup.php (.../startup.php) (revision 3431)
@@ -2,7 +2,7 @@
define('KERNEL_PATH', FULL_PATH.'/kernel/kernel4');
include_once(KERNEL_PATH.'/globals.php'); // non OOP functions used through kernel, e.g. print_pre
-
+
if( constOn('ADMIN') ) define('SPECIAL_TEMPLATES_FOLDER', '/kernel/admin_templates');
define('INPORTAL_ENV', 1);
@@ -16,10 +16,10 @@
safeDefine('INPORTAL_TAGS', true);
safeDefine('SERVER_NAME', $_SERVER['HTTP_HOST']);
safeDefine('KERNEL_PATH', FULL_PATH.'/kernel4');
-
+
$https_mark = getArrayValue($_SERVER, 'HTTPS');
safeDefine('PROTOCOL', ($https_mark == 'on') || ($https_mark == '1') ? 'https://' : 'http://');
-
+
$vars = parse_portal_ini(FULL_PATH.'/config.php');
if($vars === false)
@@ -28,7 +28,7 @@
echo 'In-Portal is probably not installed, or configuration file is missing.
';
echo 'Please use the installation script to fix the problem.
';
if ( !preg_match('/admin/', __FILE__) ) $ins = '/admin';
-
+
echo 'Go to installation script
';
flush();
exit;
@@ -49,15 +49,15 @@
define('GW_CLASS_PATH', MODULES_PATH.'/in-commerce/units/gateways/gw_classes'); // Payment Gateway Classes Path
safeDefine('ENV_VAR_NAME','env');
-
+
k4_include_once(KERNEL_PATH.'/application.php');
k4_include_once(MODULES_PATH.'/kernel/units/general/my_application.php');
if( file_exists(FULL_PATH.'/debug.php') )
{
k4_include_once(FULL_PATH.'/debug.php');
if( constOn('DEBUG_MODE') ) include_once(KERNEL_PATH.'/utility/debugger.php');
- }
+ }
k4_include_once(KERNEL_PATH.'/db/db_connection.php');
@@ -71,29 +71,32 @@
safeDefine('CACHE_CONFIGS_FILES', 1);
safeDefine('EXPERIMENTAL_PRE_PARSE', 1);
safeDefine('SILENT_LOG', 0);
-
+
k4_include_once(KERNEL_PATH."/kbase.php");
k4_include_once(KERNEL_PATH.'/utility/event.php');
k4_include_once(KERNEL_PATH."/utility/factory.php");
k4_include_once(KERNEL_PATH."/languages/phrases_cache.php");
if( !function_exists('adodb_mktime') ) k4_include_once(KERNEL_PATH.'/utility/adodb-time.inc.php');
-
+
// We should get rid of these includes:
k4_include_once(KERNEL_PATH."/db/dblist.php");
k4_include_once(KERNEL_PATH."/db/dbitem.php");
-
+
k4_include_once(KERNEL_PATH.'/processors/tag_processor.php');
k4_include_once(KERNEL_PATH."/db/db_tag_processor.php");
-
+
k4_include_once(KERNEL_PATH."/event_handler.php");
k4_include_once(KERNEL_PATH.'/db/db_event_handler.php');
k4_include_once(MODULES_PATH.'/kernel/units/general/inp_db_event_handler.php');
-
+
k4_include_once(KERNEL_PATH."/utility/temp_handler.php"); // needed because of static calls from kBase
// up to here
// global constants
define ('FALSE_ON_NULL', 1);
define ('EMPTY_ON_NULL', 2);
+ define ('KG_TO_POUND', 2.20462262);
+ define ('POUND_TO_KG', 0.45359237);
+
?>
\ No newline at end of file
Index: trunk/core/kernel/application.php
===================================================================
diff -u -r3427 -r3431
--- trunk/core/kernel/application.php (.../application.php) (revision 3427)
+++ trunk/core/kernel/application.php (.../application.php) (revision 3431)
@@ -1027,7 +1027,7 @@
{
$params_str .= $join_string.$param.'='.$value;
}
- $ret .= preg_replace('/^'.$join_string.'(.*)/', '?\\1', $params_str);
+ $ret .= $params_str;
if ($encode) $ret = str_replace('\\', '%5C', $ret);
return $ret;
Index: trunk/core/kernel/globals.php
===================================================================
diff -u -r3344 -r3431
--- trunk/core/kernel/globals.php (.../globals.php) (revision 3344)
+++ trunk/core/kernel/globals.php (.../globals.php) (revision 3431)
@@ -368,7 +368,7 @@
eval("\$result =& {$call}({$argumentString});");
return $result;
}
-
+
if( !function_exists('constOn') )
{
/**
@@ -382,5 +382,17 @@
return defined($const_name) && constant($const_name);
}
}
-
+
+ function Kg2Pounds($kg)
+ {
+ $major = floor( round($kg / POUND_TO_KG, 2) );
+ $minor = abs(round(($kg - $major * POUND_TO_KG) / POUND_TO_KG * 16, 2));
+ return array($major, $minor);
+ }
+
+ function Pounds2Kg($pounds, $ounces=0)
+ {
+ return round(($pounds + ($ounces / 16)) * POUND_TO_KG, 4);
+ }
+
?>
\ No newline at end of file
Index: trunk/core/kernel/utility/formatters.php
===================================================================
diff -u -r3282 -r3431
--- trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 3282)
+++ trunk/core/kernel/utility/formatters.php (.../formatters.php) (revision 3431)
@@ -1,8 +1,8 @@
GetFieldOptions($field_name);
$tc_value = $this->TypeCast($value,$options);
if($tc_value === false) return $value; // for leaving badly formatted date on the form
-
+
if( isset($options['type']) )
{
if( preg_match('#double|float|real|numeric#', $options['type']) ) $tc_value = str_replace(',', '.', $tc_value);
}
-
+
if( isset($options['regexp']) )
{
if( !preg_match($options['regexp'], $value) )
{
- $object->FieldErrors[$field_name]['pseudo'] = 'invalid_format';
+ $object->FieldErrors[$field_name]['pseudo'] = 'invalid_format';
}
}
-
+
return $tc_value;
}
-
+
function HumanFormat($format)
{
return $format;
}
-
-
+
+
/**
* The method is supposed to alter config options or cofigure object in some way based on its usage of formatters
* The methods is called for every field with formatter defined when configuring item.
@@ -92,11 +92,11 @@
*/
function PrepareOptions($field_name, &$field_options, &$object)
{
-
+
}
-
+
/**
- * Used for split fields like timestamp -> date, time
+ * Used for split fields like timestamp -> date, time
* Called from DBItem to update sub fields values after loading item
*
* @param unknown_type $field
@@ -106,9 +106,9 @@
*/
function UpdateSubFields($field, $value, &$options, &$object)
{
-
+
}
-
+
/**
* Used for split fields like timestamp -> date, time
* Called from DBItem Validate (before validation) to get back master field value from its sub_fields
@@ -120,9 +120,9 @@
*/
function UpdateMasterFields($field, $value, &$options, &$object)
{
-
+
}
-
+
/* function GetErrorMsg($pseudo_error, $options)
{
if ( isset($options['error_msgs'][$pseudo_error]) ) {
@@ -135,9 +135,9 @@
function GetSample($field, &$options, &$object)
{
-
+
}
-
+
}
class kOptionsFormatter extends kFormatter {
@@ -146,10 +146,10 @@
function Format($value, $field_name, &$object, $format=null)
{
if ( is_null($value) ) return '';
-
+
$options = $object->GetFieldOptions($field_name);
if ( isset($format) ) $options['format'] = $format;
-
+
$label = getArrayValue($options['options'], $value);
if( $label !== false )
{
@@ -178,42 +178,42 @@
* where requested options are located.
*/
class kLEFTFormatter extends kFormatter {
-
+
//function Format($value, $options, &$errors)
function Format($value, $field_name, &$object, $format=null)
{
if ( is_null($value) ) return '';
-
+
$options = $object->GetFieldOptions($field_name);
if ( isset($format) ) $options['format'] = $format;
-
- if( !isset($options['options'][$value]) )
+
+ if( !isset($options['options'][$value]) )
{
- // required option is not defined in config => query for it
+ // required option is not defined in config => query for it
$db =& $this->Application->GetADODBConnection();
$sql = sprintf($options['left_sql'],$options['left_title_field'],$options['left_key_field'],$value);
$options['options'][$value] = $db->GetOne($sql);
}
return $options['options'][$value];
}
-
+
//function Parse($value, $options, &$errors)
function Parse($value, $field_name, &$object)
{
if ($value == '') return NULL;
-
+
$options = $object->GetFieldOptions($field_name);
- if( !array_search($value,$options['options']) )
+ if( !array_search($value,$options['options']) )
{
- // required option is not defined in config => query for it
+ // required option is not defined in config => query for it
$db =& $this->Application->GetADODBConnection();
$sql = sprintf($options['left_sql'],$options['left_key_field'],$options['left_title_field'],$value);
$found = $db->GetOne($sql);
if($found !== false) $options['options'][$found] = $value;
}
else
{
- $found = array_search($value,$options['options']);
+ $found = array_search($value,$options['options']);
}
if($found === false) $found = $options['default'];
return $found;
@@ -222,7 +222,7 @@
class kDateFormatter extends kFormatter {
-
+
/* function kDateFormatter()
{
parent::kFormatter();
@@ -234,34 +234,34 @@
{
$date_format = getArrayValue($field_options, 'date_format');
$time_format = getArrayValue($field_options, 'time_format');
-
+
$language =& $this->Application->recallObject('lang.current');
-
+
if ($date_format === false) $date_format = $language->GetDBField('DateFormat');
if ($time_format === false) $time_format = $language->GetDBField('TimeFormat');
-
+
if (!isset($field_options['date_time_separator'])) $field_options['date_time_separator'] = ' ';
$field_options['format'] = $date_format.$field_options['date_time_separator'].$time_format;
$field_options['sub_fields'] = Array('date' => $field_name.'_date', 'time' => $field_name.'_time');
-
+
$add_fields = Array();
-
+
$opts = Array('master_field' => $field_name, 'formatter'=>'kDateFormatter', 'format'=>$date_format);
if ( isset($field_options['default']) ) $opts['default'] = $field_options['default'];
if ( isset($field_options['required']) ) $opts['required'] = $field_options['required'];
-
+
$add_fields[$field_name.'_date'] = $opts;
$opts['format'] = $time_format;
$add_fields[$field_name.'_time'] = $opts;
-
+
$filter_type = getArrayValue($field_options, 'filter_type');
if($filter_type == 'range')
{
$opts['format'] = $field_options['format'];
$add_fields[$field_name.'_rangefrom'] = $opts;
$add_fields[$field_name.'_rangeto'] = $opts;
}
-
+
if ( !isset($object->VirtualFields[$field_name]) ) {
// adding caluclated field to format date directly in the query
if ( !isset($object->CalculatedFields) || !is_array($object->CalculatedFields) ) {
@@ -273,11 +273,11 @@
unset($opts['master_field']);
$add_fields[$field_name.'_formatted'] = $opts;
}
-
+
$add_fields = array_merge_recursive2($add_fields, $object->VirtualFields);
$object->setVirtualFields($add_fields);
}
-
+
function UpdateSubFields($field, $value, &$options, &$object)
{
if ( $sub_fields = getArrayValue($options, 'sub_fields') ) {
@@ -288,7 +288,7 @@
}
}
}
-
+
function UpdateMasterFields($field, $value, &$options, &$object)
{
// when in master field - set own value from sub_fields
@@ -305,24 +305,24 @@
// when in one of sub_fields - call update for master_field to update its value from sub_fields [are you following ? :) ]
elseif ($master_field = getArrayValue($options, 'master_field') ) {
$opt = $object->GetFieldOptions($master_field);
- $this->UpdateMasterFields($master_field, null, $opt, $object);
+ $this->UpdateMasterFields($master_field, null, $opt, $object);
}
}
-
+
//function Format($value, $options, &$errors)
function Format($value, $field_name, &$object, $format=null)
{
if ( is_null($value) ) return '';
if ( !is_numeric($value) ) return $value; // for leaving badly formatted date on the form
settype($value, 'int');
if ( !is_int($value) ) return $value;
-
+
$options = $object->GetFieldOptions($field_name);
if ( isset($format) ) $options['format'] = $format;
-
+
return adodb_date($options['format'], $value);
}
-
+
function HumanFormat($format)
{
$patterns = Array('/m/',
@@ -350,13 +350,13 @@
$res = preg_replace($patterns, $replace, $format);
return $res;
}
-
+
function SQLFormat($format)
{
$mapping = Array(
'/%/' => '%%',
'/(? '%p', // Lowercase Ante meridiem and Post meridiem => MySQL provides only uppercase
- '/(? '%p', // Uppercase Ante meridiem and Post meridiem
+ '/(? '%p', // Uppercase Ante meridiem and Post meridiem
'/(? '%d', // Day of the month, 2 digits with leading zeros
'/(? '%a', // A textual representation of a day, three letters
'/(? '%M', // A full textual representation of a month, such as January or March
@@ -366,7 +366,7 @@
'/(? '%H', // 24-hour format of an hour with leading zeros
'/(? '%i', // Minutes with leading zeros
'/(? 'N/A', // Whether or not the date is in daylights savings time
-
+
'/(? 'N/A', // English ordinal suffix for the day of the month, 2 characters, see below
'/jS/' => '%D', // MySQL can't return separate suffix, but could return date with suffix
'/(? '%e', // Day of the month without leading zeros
@@ -384,43 +384,43 @@
'/(? 'N/A', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
'/(? '%w', // Numeric representation of the day of the week
'/(? '%v', // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
- '/(? '%Y', // A full numeric representation of a year, 4 digits
- '/(? '%y', // A two digit representation of a year
+ '/(? '%Y', // A full numeric representation of a year, 4 digits
+ '/(? '%y', // A two digit representation of a year
'/(? 'N/A', // The day of the year (starting from 0) => MySQL starts from 1
'/(? 'N/A', // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
);
-
+
$patterns = array_keys($mapping);
$replacements = array_values($mapping);
-
+
$res = preg_replace($patterns, $replacements, $format);
return $res;
}
-
+
//function Parse($value, $options, &$errors)
function Parse($value, $field_name, &$object)
{
$options = $object->GetFieldOptions($field_name);
-
+
$dt_separator = getArrayValue($options,'date_time_separator');
if($dt_separator) $value = trim($value, $dt_separator);
if($value == '') return NULL;
//return strtotime($value);
-
+
$format = $options['format'];
if($dt_separator) $format = trim($format, $dt_separator);
-
+
$object->FieldErrors[$field_name]['params'] = Array( $this->HumanFormat($format), adodb_date($format) );
$object->FieldErrors[$field_name]['value'] = $value;
-
+
$hour = 0;
$minute = 0;
$second = 0;
$month = 1;
$day = 1;
$year = 1970;
- $patterns['n'] = '([0-9]{1,2})';
+ $patterns['n'] = '([0-9]{1,2})';
$patterns['m'] = '([0-9]{1,2})';
$patterns['d'] = '([0-9]{1,2})';
$patterns['j'] = '([0-9]{1,2})';
@@ -434,24 +434,24 @@
$patterns['s'] = '([0-9]{2})';
$patterns['a'] = '(am|pm)';
$patterns['A'] = '(AM|PM)';
-
+
$holders_mask = eregi_replace('[a-zA-Z]{1}', '([a-zA-Z]{1})', $format);
if (!ereg($holders_mask, $format, $holders)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
$values_mask = '/^'.str_replace('/','\/',$format).'$/';
foreach ($patterns as $key => $val) {
$values_mask = ereg_replace($key, $val, $values_mask);
}
- // echo " values_mask : $values_mask
";
-
+ // echo " values_mask : $values_mask
";
+
if (!preg_match($values_mask, $value, $values)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
for ($i = 1; $i < count($holders); $i++) {
switch ($holders[$i]) {
case 'n':
@@ -498,56 +498,56 @@
break;
}
}
-
+
//echo "day: $day, month: $month, year: $year, hour: $hour, minute: $minute
";
-
+
/*if (!($year >= 1970 && $year <= 2037)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}*/
-
+
if (!($month >= 1 && $month <= 12)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
$months_days = Array ( 1 => 31,2 => 28, 3 => 31, 4 => 30,5 => 31,6 => 30, 7 => 31, 8 => 31,9 => 30,10 => 31,11 => 30,12 => 31);
if ($year % 4 == 0) $months_days[2] = 29;
-
+
if (!($day >=1 && $day <= $months_days[$month])) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
if (!($hour >=0 && $hour <= 23)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
if (!($minute >=0 && $minute <= 59)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
-
+
if (!($second >=0 && $second <= 59)) {
$object->FieldErrors[$field_name]['pseudo'] = 'bad_date_format';
return $value;
}
// echo "day: $day, month: $month, year: $year, hour: $hour, minute: $minute
";
return adodb_mktime($hour, $minute, $second, $month, $day, $year);
}
-
+
function GetSample($field, &$options, &$object)
{
- return $this->Format( adodb_mktime(), $field, $object);
+ return $this->Format( adodb_mktime(), $field, $object);
}
}
class kUploadFormatter extends kFormatter
{
var $DestinationPath;
var $FullPath;
-
+
function kUploadFormatter()
{
if ($this->DestinationPath)
@@ -556,30 +556,30 @@
}
parent::kBase();
}
-
-
+
+
//function Parse($value, $options, &$errors)
function Parse($value, $field_name, &$object)
{
$ret = '';
$options = $object->GetFieldOptions($field_name);
-
+
if(getArrayValue($options, 'upload_dir'))
{
$this->DestinationPath = $options['upload_dir'];
$this->FullPath = FULL_PATH.$this->DestinationPath;
}
-
+
if (getArrayValue($value, 'upload') && getArrayValue($value, 'error') == UPLOAD_ERR_NO_FILE)
{
return getArrayValue($value, 'upload');
}
-
+
if ( is_array($value) && $value['size'] )
{
- if ( is_array($value) && $value['error'] === UPLOAD_ERR_OK )
- {
- if ( getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types']) )
+ if ( is_array($value) && $value['error'] === UPLOAD_ERR_OK )
+ {
+ if ( getArrayValue($options, 'allowed_types') && !in_array($value['type'], $options['allowed_types']) )
{
$object->FieldErrors[$field_name]['pseudo'] = 'bad_file_format';
}
@@ -591,7 +591,7 @@
{
$object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
}
- else
+ else
{
$real_name = $this->ValidateFileName($this->FullPath, $value['name']);
$file_name = $this->FullPath.$real_name;
@@ -620,42 +620,42 @@
else
{
$object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
- }
+ }
}
- else
+ else
{
if(getArrayValue($options, 'required'))
{
$object->FieldErrors[$field_name]['pseudo'] = 'required';
}
}
-
+
if ($value['error'] && !( $value['error'] == UPLOAD_ERR_NO_FILE ) && !$object->FieldErrors[$field_name]['pseudo'])
{
$object->FieldErrors[$field_name]['pseudo'] = 'cant_save_file';
}
-
+
return $ret;
}
-
+
function ValidateFileName($path, $name)
{
$parts = pathinfo($name);
$ext = '.'.$parts['extension'];
$filename = substr($parts['basename'], 0, -strlen($ext));
$new_name = $filename.$ext;
- while ( file_exists($path.'/'.$new_name) )
+ while ( file_exists($path.'/'.$new_name) )
{
if ( preg_match("/({$filename}_)([0-9]*)($ext)/", $new_name, $regs) ) {
$new_name = $regs[1].($regs[2]+1).$regs[3];
}
else {
$new_name = $filename.'_1'.$ext;
}
- }
- return $new_name;
+ }
+ return $new_name;
}
-
+
}
class kPictureFormatter extends kUploadFormatter
@@ -667,34 +667,34 @@
$this->DestinationPath = IMAGES_PENDING_PATH;
parent::kUploadFormatter();
}
-
+
}
-class kMultiLanguage extends kFormatter
+class kMultiLanguage extends kFormatter
{
-
- function LangFieldName($field_name)
+
+ function LangFieldName($field_name)
{
$lang = $this->Application->GetVar('m_lang');
return 'l'.$lang.'_'.$field_name;
}
-
+
function PrepareOptions($field_name, &$field_options, &$object)
{
if (getArrayValue($object->Fields, $field_name, 'master_field')) return;
-
+
$lang_field_name = $this->LangFieldName($field_name);
-
+
//substitude title field
$title_field = $this->Application->getUnitOption($object->Prefix, 'TitleField');
if ($title_field == $field_name) {
$this->Application->setUnitOption($object->Prefix, 'TitleField', $lang_field_name);
}
-
+
//substitude fields
$fields = $this->Application->getUnitOption($object->Prefix, 'Fields');
if ( isset($fields[$field_name]) ) {
-
+
$fields[$lang_field_name] = $fields[$field_name];
$fields[$lang_field_name]['master_field'] = $field_name;
$object->Fields[$lang_field_name] = $fields[$lang_field_name];
@@ -703,7 +703,7 @@
$object->VirtualFields[$field_name] = $object->Fields[$field_name];
}
$this->Application->setUnitOption($object->Prefix, 'Fields', $fields);
-
+
//substitude virtual fields
$virtual_fields = $this->Application->getUnitOption($object->Prefix, 'VirtualFields');
if ( isset($virtual_fields[$field_name]) ) {
@@ -714,7 +714,7 @@
$object->VirtualFields[$field_name]['required'] = false;
}
$this->Application->setUnitOption($object->Prefix, 'VirtualFields', $virtual_fields);
-
+
//substitude grid fields
$grids = $this->Application->getUnitOption($object->Prefix, 'Grids');
foreach ($grids as $name => $grid) {
@@ -723,7 +723,7 @@
}
}
$this->Application->setUnitOption($object->Prefix, 'Grids', $grids);
-
+
//substitude default sortings
$sortings = $this->Application->getUnitOption($object->Prefix, 'ListSortings');
foreach ($sortings as $special => $the_sortings) {
@@ -735,20 +735,20 @@
}
}
$this->Application->setUnitOption($object->Prefix, 'ListSortings', $sortings);
-
+
//TODO: substitude possible language-fields sortings after changing language
}
-
+
/*function UpdateSubFields($field, $value, &$options, &$object)
{
-
+
}
-
+
function UpdateMasterFields($field, $value, &$options, &$object)
{
-
+
}*/
-
+
function Format($value, $field_name, &$object, $format=null)
{
$master_field = getArrayValue($object->Fields, $field_name, 'master_field');
@@ -759,64 +759,64 @@
}
if ( $value == '' && $format != 'no_default') { // try to get default language value
$def_lang_value = $object->GetDBField('l'.$this->Application->GetDefaultLanguageId().'_'.$master_field);
- if ($def_lang_value == '') return NULL;
+ if ($def_lang_value == '') return NULL;
return $def_lang_value; //return value from default language
}
return $value;
}
-
+
function Parse($value, $field_name, &$object)
{
$lang = $this->Application->GetVar('m_lang');
$def_lang = $this->Application->GetDefaultLanguageId();
$master_field = getArrayValue($object->Fields, $field_name, 'master_field');
-
+
if ( getArrayValue($object->Fields, $field_name, 'required') && ( (string) $value == '' ) ) {
$object->FieldErrors[$master_field]['pseudo'] = 'required';
};
-
+
if (!$this->Application->GetVar('allow_translation') && $lang != $def_lang && getArrayValue($object->Fields, $field_name, 'required')) {
$def_lang_field = 'l'.$def_lang.'_'.$master_field;
if ( !$object->ValidateRequired($def_lang_field, $object->Fields[$field_name]) ) {
$object->FieldErrors[$master_field]['pseudo'] = 'primary_lang_required';
}
- }
-
+ }
+
if ($value == '') return NULL;
return $value;
}
-
+
}
-class kPasswordFormatter extends kFormatter
+class kPasswordFormatter extends kFormatter
{
-
+
function PrepareOptions($field_name, &$field_options, &$object)
{
if( isset( $field_options['verify_field'] ) )
{
$add_fields = Array();
$options = Array('master_field' => $field_name, 'formatter'=>'kPasswordFormatter');
$add_fields[ $field_options['verify_field'] ] = $options;
-
+
$add_fields[$field_name.'_plain'] = Array('type'=>'string', 'error_field'=>$field_name);
$add_fields[ $field_options['verify_field'].'_plain' ] = Array('type'=>'string', 'error_field'=>$field_options['verify_field'] );
-
+
$add_fields = array_merge_recursive2($add_fields, $object->VirtualFields);
$object->setVirtualFields($add_fields);
}
}
-
+
function Format($value, $field_name, &$object, $format=null)
{
return $value;
}
-
+
function Parse($value, $field_name, &$object)
{
$options = $object->GetFieldOptions($field_name);
-
+
$fields = Array('master_field','verify_field');
$fields_set = true;
$flip_count = 0;
@@ -829,14 +829,14 @@
{
$object->Fields[ $options[ $fields[0] ] ][$fields[1].'_set'] = true;
}
-
+
$password_field = $options[ $fields[0] ];
$verify_field = $field_name;
}
$fields = array_reverse($fields);
$flip_count++;
}
-
+
if( getArrayValue($object->Fields[$password_field], 'verify_field_set') && getArrayValue($object->Fields[$verify_field], 'master_field_set') )
{
$new_password = $object->GetDBField($password_field.'_plain');
@@ -855,7 +855,7 @@
return null;
}
}
-
+
$min_length = $this->Application->ConfigValue('Min_Password');
if( strlen($new_password) >= $min_length )
{
@@ -876,7 +876,7 @@
if($value == '') return $object->GetDBField($field_name);
return $this->EncryptPassword($value);
}
-
+
function EncryptPassword($value)
{
return md5($value);
@@ -888,12 +888,12 @@
* Credit card expiration date formatter
*
*/
-class kCCDateFormatter extends kFormatter
+class kCCDateFormatter extends kFormatter
{
function PrepareOptions($field_name, &$field_options, &$object)
{
$add_fields = Array();
-
+
$i = 1;
$options = Array('00' => '');
while($i <= 12)
@@ -903,19 +903,19 @@
}
$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] );
}
-
+
/**
* Will work in future if we could attach 2 formatters to one field
*
@@ -927,19 +927,19 @@
function Parse($value, $field_name, &$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 {
@@ -957,7 +957,7 @@
case 2: // US/UK
$field_options_copy = $field_options;
unset($field_options_copy['min_value_exc']);
- $add_fields[$field_name.'_a'] = array_merge_recursive2($field_options_copy, $options_a);
+ $add_fields[$field_name.'_a'] = array_merge_recursive2($field_options_copy, $options_a);
$add_fields[$field_name.'_b'] = array_merge_recursive2($field_options_copy, $options_b);
break;
default:
@@ -966,7 +966,7 @@
$object->setVirtualFields($add_fields);
}
}
-
+
function UpdateMasterFields($field, $value, &$options, &$object)
{
if( !isset($options['master_field']) )
@@ -986,17 +986,17 @@
unset($object->Fields[$field]);
return;
}
- else
+ else
{
- $value = $major / 2 + $minor / 32;
+ $value = Pounds2Kg($major, $minor);
}
break;
default:
}
$object->SetDBField($field, $value);
}
}
-
+
function UpdateSubFields($field, $value, &$options, &$object)
{
if( !isset($options['master_field']) )
@@ -1010,11 +1010,12 @@
$major = null;
$minor = null;
}
- else
+ else
{
- $major = floor( $value / 0.5 );
- $minor = ($value - $major * 0.5) * 32;
- }
+ list($major,$minor) = Kg2Pounds($value);
+ /*$major = floor( $value / 0.5 );
+ $minor = ($value - $major * 0.5) * 32;*/
+ }
$object->SetDBField($field.'_a', $major);
$object->SetDBField($field.'_b', $minor);
break;