21 import(
'Dataface/Table.php');
22 import(
'Dataface/Error.php');
36 $larr[
'decimal_point'],
37 $larr[
'mon_decimal_point'],
38 $larr[
'thousands_sep'],
39 $larr[
'mon_thousands_sep'],
40 $larr[
'currency_symbol'],
41 $larr[
'int_curr_symbol']
43 $replace = array(
'.',
'.',
'',
'',
'',
'');
45 return str_replace($search, $replace, $value);
61 if ( is_string($value) and preg_match(
'/^__(.*)__$/', $value)){
66 if ( $value === null ){
84 throw new Exception(
$field->getMessage());
87 $delegate =&
$table->getDelegate();
88 if ( $delegate !== null and method_exists($delegate,
$fieldname.
"__serialize") ){
89 $val = call_user_func(array(&$delegate,
$fieldname.
"__serialize"), $value);
93 $widget =
$field[
'widget'];
94 $type = $widget[
'type'];
97 if ( $handleRepeat and
$field[
'repeat'] and is_array($value) ){
98 foreach ($value as $key=>$val){
102 $value = implode(
$field[
'separator'], $value);
109 $evt->value = $value;
111 $this->_table->app->fireEvent(
'serialize_field_value', $evt);
118 if ( !isset($value) || !$value )
return null;
120 if ( is_string($params) and strtotime($params) ){
121 $timestamp = strtotime($params);
124 return date(
'Y-m-d', $timestamp);
127 return date(
'Y-m-d h:i:s', $timestamp);
129 return date(
'h:i:s', $timestamp);
131 return date(
'Y', $timestamp);
135 if ( !is_array($params) )
return null;
138 $datestr = str_pad($params[
'year'],4,
"0",STR_PAD_LEFT).
'-'.str_pad($params[
'month'],2,
"0",STR_PAD_LEFT).
'-'.str_pad($params[
'day'],2,
"0",STR_PAD_LEFT);
139 $timestr = str_pad($params[
'hours'],2,
"0",STR_PAD_LEFT).
':'.str_pad($params[
'minutes'],2,
"0",STR_PAD_LEFT).
':'.str_pad($params[
'seconds'], 2,
"0",STR_PAD_LEFT);
146 return $datestr.
' '.$timestr;
149 return str_pad($params[
'year'],4,
"0",STR_PAD_LEFT).str_pad($params[
'month'],2,
"0",STR_PAD_LEFT).str_pad($params[
'day'],2,
"0",STR_PAD_LEFT).str_pad($params[
'hours'],2,
"0",STR_PAD_LEFT).str_pad($params[
'minutes'],2,
"0",STR_PAD_LEFT).str_pad($params[
'seconds'],2,
"0",STR_PAD_LEFT);
153 return str_pad($params[
'year'],4,
"0",STR_PAD_LEFT);
170 if ( is_array( $value ) ){
171 if ( $widget[
'type'] ==
'table' or $widget[
'type'] ==
'group'){
172 import(
'XML/Serializer.php');
173 $serializer =
new XML_Serializer(array(
'typeHints'=>
true));
174 $ser_res =& $serializer->serialize($value);
176 return $serializer->getSerializedData();
180 throw new Exception(
"Trying to serialize value for field '$fieldname' that we don't know what to do with. The value is an array and we don't know how to parse it.", E_USER_ERROR);
199 throw new Exception(
"Not implemented yet.", E_USER_ERROR);
209 if ( !isset($value) ) $value =
'';
222 error_log(
$field->getMessage().
"\n".implode(
"\n",
$field->getBacktrace()));
223 throw new Exception(
"Failed to encrypt field $fieldname. See error log for details.", E_USER_ERROR);
226 if ( isset(
$field[
'encryption']) ){
227 switch(strtolower(
$field[
'encryption'])){
229 return 'MD5('.$value.
')';
231 return 'PASSWORD('.$value.
')';
233 return 'SHA1('.$value.
')';
235 return 'ENCRYPT('.$value.
')';
237 return 'AES_ENCRYPT('.$value.
',\''.addslashes(
$field[
'aes_key']).
'\')
';