function updateValuesSecure(&$action,&$possibleTables = array(),&$queryTables = array()){
$db = JFactory::getDBO();
$app = JFactory::getApplication();
$tableType = explode('_',$action['type']);
// Special cases
if(preg_match('/order_product/',$action['type'])) $tableType = array('order_product');
if($tableType[0] == 'joomla') $queryTables[] = $tableType[0].'_'.$tableType[1];
else $queryTables[] = $tableType[0];
// check if the column type match with the action type
$mainFields = array();
foreach($possibleTables as $possibleTable){
if(!is_string($possibleTable)) continue;
if(version_compare(JVERSION,'3.0','<')){
if(preg_match('/joomla_/',$possibleTable)){
$fieldsTable = $db->getTableFields('#__'.str_replace('joomla_','',$possibleTable));
$fields = reset($fieldsTable);
// foreach($fields as $key => $field){
// $fields['joomla_'.$key] = $fields[$key];
// unset($fields[$key]);
// }
$fieldsTable = $fields;
}
else{
$fieldsTable = $db->getTableFields('#__hikashop_'.$possibleTable);
$fields = reset($fieldsTable);
}
} else {
if(preg_match('/joomla_/',$possibleTable)){
$fields = $db->getTableColumns('#__'.str_replace('joomla_','',$possibleTable));
// foreach($fields as $key => $field){
// $fields['joomla_'.$key] = $fields[$key];
// unset($fields[$key]);
// }
}
else $fields = $db->getTableColumns('#__hikashop_'.$possibleTable);
}
$mainFields = array_merge($mainFields,$fields);
}
foreach($mainFields as $key => $field){
$field = str_replace(',','',$field);
if($key == $action['type']){
switch($action['operation']){
case 'int':
if(in_array($field,array('boolean'))){
$app->enqueueMessage(JText::sprintf( 'WRONG_COLUMN_TYPE', $field));
$queryTables = '';
}
break;
case 'float':
if(in_array($field,array('int','boolean'))){
$app->enqueueMessage(JText::sprintf( 'WRONG_COLUMN_TYPE', $field));
$queryTables = '';
}
break;
case 'string':
if(!in_array($field,array('varchar','text','char'))){
$app->enqueueMessage(JText::sprintf( 'WRONG_COLUMN_TYPE', $field));
$queryTables = '';
}
break;
}
}
}
if($action['operation'] == 'int'){$value = (int)$action['value'];}
elseif($action['operation'] == 'float'){$value = (float)$action['value'];}
elseif($action['operation'] == 'string'){$value = $db->quote($action['value']);}
elseif($action['operation'] == 'operation'){
$strings = array();
// Regex
$symbols = array('%','+','-','/','*','(',')');
$string = str_replace($symbols,'||',$action['value']);
$entries = explode('||',$string);
foreach($entries as $entry){
$data = explode('.',$entry);
if(!isset($data[1]) || (is_numeric($data[0]) && is_numeric($data[1])))
continue;
$strings[]['table'] = $data[0];
$strings[]['column'] = $data[1];
}
$type = 'table';
if(!empty($mainFields)){
foreach($strings as $string){
if(isset($string['table']) && $type == 'table'){
if(!in_array($string['table'], $possibleTables)){
$app->enqueueMessage(JText::sprintf('TABLE_NOT_EXIST',$string['table']));
$queryTables = '';
continue;
}
if(!in_array($string, $queryTables)){
$queryTables[] = 'hk_'.$string;
}
$type = 'column';
}elseif(isset($string['column']) && $type == 'column'){
$colKey = array();
foreach($mainFields as $key => $field){
$colKey[] = $key;
}
if(!in_array($string['column'], $colKey)){
$app->enqueueMessage(JText::sprintf('COLUMN_NOT_EXIST',$string['column']));
$queryTables = '';
}
$type = 'table';
}
}
}
// if !number
if(!preg_match('/^(?:\d+|\d*\.\d+)$/',$action['value'])){
// if operation (ex: +5, -2) increment the value in the type selected table
if(in_array($action['value'][0], array('+','-'))){
$value = $action['type'].$action['value'];
}
// else add the prefix
else{
$value = $action['value'];
// Group the available tables in only one entry
$tables = array();
foreach($strings as $string){
if(isset($string['table'])){
$tables[$string['table']] = $string['table'];
}
}
// add the prefix
foreach($tables as $table){
$value = str_replace($table.'.','hk_'.$table.'.',$value);
}
}
$value = strip_tags($value);
}
// default value
else{
$value = $db->quote($action['value']);
}
}else{$value = '';}
return $value;
}