public static function g_onCCK_PaymentValidate($data, $success, &$config) { $update = 'pay_return = "' . JCckDatabase::escape(json_encode($data['order'])) . '",' . 'pay_return_payments = "' . JCckDatabase::escape(json_encode($data['payments'])) . '",' . 'state = ' . $data['order_state']; JCckDatabase::execute('UPDATE #__cck_more_ecommerce_orders SET ' . $update . ' WHERE pay_key = "' . $config['pay_key'] . '"'); if (!$success) { return; } // Cart $cart_id = (int) JCckDatabase::loadResult('SELECT a.id FROM #__cck_more_ecommerce_carts AS a WHERE a.pay_key = "' . $config['pay_key'] . '"'); if ($cart_id) { JCckDatabase::execute('UPDATE #__cck_more_ecommerce_carts SET pay_key = "" WHERE id = ' . $cart_id); JCckDatabase::execute('DELETE a.* FROM #__cck_more_ecommerce_cart_product AS a WHERE a.cart_id = ' . $cart_id); } // Execute Processings (Invoice, Notifications, ...) if (JCckToolbox::getConfig()->get('processing', 0)) { $event = 'onCckPaymentSuccess'; $processing = JCckDatabaseCache::loadObjectListArray('SELECT type, scriptfile, options FROM #__cck_more_processings WHERE published = 1 ORDER BY ordering', 'type'); if (isset($processing[$event])) { foreach ($processing[$event] as $p) { if (is_file(JPATH_SITE . $p->scriptfile)) { $options = new JRegistry($p->options); include_once JPATH_SITE . $p->scriptfile; } } } } }
public static function _replace($name, $value, $value_old, $string, &$config = array()) { return str_replace(self::_format($name, JCckDatabase::escape($value_old)), self::_format($name, JCckDatabase::escape($value)), $string); }
public function ajaxSaveIntegration() { $app = JFactory::getApplication(); $json = JCck::on() ? $app->input->JSON->getRaw() : $app->input->getRaw('integration'); $objects = json_decode($json); if (count($objects)) { $query = 'UPDATE #__cck_core_objects SET options = CASE name'; foreach ($objects as $k => $v) { $query .= ' WHEN "' . $k . '" THEN "' . JCckDatabase::escape(json_encode($v)) . '"'; $in .= '"' . $k . '",'; } $in = substr($in, 0, -1); $query .= ' ELSE options END WHERE name IN (' . $in . ')'; JCckDatabase::execute($query); } }
$and = ''; $column = $app->input->getString('avColumn', ''); $key = $app->input->getString('avKey', ''); $where = $app->input->getString('avWhere', ''); $table = $app->input->getString('avTable', ''); // Process if ($where) { $fields = JCckDatabase::loadObjectList('SELECT name, storage, storage_table, storage_field FROM #__cck_core_fields WHERE name IN ("' . str_replace(',', '","', $where) . '")', 'name'); $where = explode(',', $where); foreach ($where as $w) { if (isset($fields[$w]) && $fields[$w]->storage == 'standard' && $fields[$w]->storage_table == '#__' . $table) { $v = $app->input->get($w); if ($v != '') { $and .= ' ' . $fields[$w]->storage_field . '="' . JCckDatabase::escape($v) . '"'; } } } $and = $and ? ' AND' . $and : ''; } if ($key) { $pk = $app->input->getInt('avPk', 0); $pv = $app->input->getString('avPv', ''); $pv = str_replace(array('%26lt;', '%26gt;', '%27'), array('<', '>', "'"), $pv); $count = (int) JCckDatabase::loadResult('SELECT ' . $key . ' FROM #__' . $table . ' WHERE ' . $column . ' = "' . JCckDatabase::escape($value) . '"' . $and); $res[1] = $count > 0 && $count != $pk ? false : true; } else { $count = (int) JCckDatabase::loadResult('SELECT COUNT(' . $column . ') FROM #__' . $table . ' WHERE ' . $column . ' = "' . JCckDatabase::escape($value) . '"' . $and); $res[1] = $count > 0 ? false : true; } // Set echo json_encode($res);
public static function onCCK_StoragePrepareSearch(&$field, $match, $value, $name, $name2, $target, $fields = array(), &$config = array()) { $sql = ''; switch ($match) { case 'exact': $sql = $target . ' = ' . JCckDatabase::quote($value); break; case 'empty': $sql = $target . ' = ""'; break; case 'alpha': $sql = $target . ' LIKE ' . JCckDatabase::quote(JCckDatabase::escape($value, true) . '%', false); break; case 'zeta': /* Zeta is not the last letter of Greek alphabet but.. this won't be an issue here. */ $sql = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true), false); break; case 'any': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($v, true) . '%', false); } } if (count($fragments)) { $sql = '((' . implode(') OR (', $fragments) . '))'; } } break; case 'any_exact': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); $var_type = $field->match_options ? $field->match_options->get('var_type', 1) : 1; if (!$var_type) { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $v; } } } else { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = JCckDatabase::quote($v); } } } if (count($fragments)) { $sql = $target . ' IN (' . implode(',', $fragments) . ')'; } } break; case 'each': case 'each_exact': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); if ($match == 'each_exact') { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $target . ' = ' . JCckDatabase::quote($v) . ' OR ' . $target . ' LIKE ' . JCckDatabase::quote(JCckDatabase::escape($v, true) . $separator . '%', false) . ' OR ' . $target . ' LIKE ' . JCckDatabase::quote('%' . $separator . JCckDatabase::escape($v, true) . $separator . '%', false) . ' OR ' . $target . ' LIKE ' . JCckDatabase::quote('%' . $separator . JCckDatabase::escape($v, true), false); } } } else { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($v, true) . '%', false); } } } if (count($fragments)) { $sql = '((' . implode(') AND (', $fragments) . '))'; } } break; case 'date_past_only': $sql = $target . ' < ' . JCckDatabase::quote($value); break; case 'date_past': $sql = $target . ' <= ' . JCckDatabase::quote($value); break; case 'date_future': $sql = $target . ' >= ' . JCckDatabase::quote($value); break; case 'date_future_only': $sql = $target . ' > ' . JCckDatabase::quote($value); break; case 'nested_exact': $table = $field->match_options ? $field->match_options->get('table', $field->storage_table) : $field->storage_table; $column = 'id'; $values = JCckDevHelper::getBranch($table, $value); if ($column != 'id') { if (count($values)) { $fragments = array(); foreach ($values as $v) { if ($v != '') { $fragments[] = JCckDatabase::quote($v); } } if (count($fragments)) { $sql = $target . ' IN (' . implode(',', $fragments) . ')'; } } } else { if (count($values)) { $sql = $target . ' IN (' . implode(',', $values) . ')'; } } break; case 'num_higher': $sql = $target . ' >= ' . JCckDatabase::quote($value); break; case 'num_higher_only': $sql = $target . ' > ' . JCckDatabase::quote($value); break; case 'num_lower': $sql = $target . ' <= ' . JCckDatabase::quote($value); break; case 'num_lower_only': $sql = $target . ' < ' . JCckDatabase::quote($value); break; case 'not_alpha': $sql = $target . ' NOT LIKE ' . JCckDatabase::quote(JCckDatabase::escape($value, true) . '%', false); break; case 'not_any_exact': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = JCckDatabase::quote($v); } } if (count($fragments)) { $sql = $target . ' NOT IN (' . implode(',', $fragments) . ')'; } } break; case 'not_zeta': /* Zeta is not the last letter of Greek alphabet but.. this won't be an issue here. */ $sql = $target . ' NOT LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true), false); break; case 'not_empty': $sql = $target . ' != ""'; break; case 'not_equal': $sql = $target . ' != ' . JCckDatabase::quote($value); break; case 'not_like': $sql = $target . ' NOT LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true) . '%', false); break; case 'not_null': $sql = $target . ' != "0"'; break; case 'is_null': $sql = $target . ' IS NULL'; break; case 'is_not_null': $sql = $target . ' IS NOT NULL'; break; case 'radius_higher': case 'radius_lower': $t = explode('.', $target); $f_lat = $field->match_options->get('fieldname1', ''); $f_lng = $field->match_options->get('fieldname2', ''); $f_rad = $field->match_options->get('fieldname3', ''); $lat = isset($fields[$f_lat]) ? $fields[$f_lat]->value : ''; $lng = isset($fields[$f_lng]) ? $fields[$f_lng]->value : ''; $s_lat = isset($fields[$f_lat]->storage_field) && $fields[$f_lat]->storage_field ? $fields[$f_lat]->storage_field : $f_lat; $s_lng = isset($fields[$f_lng]->storage_field) && $fields[$f_lng]->storage_field ? $fields[$f_lng]->storage_field : $f_lng; if ($lat != '' && $lng != '') { $alias = 'distance'; $mod = $field->match_options->get('var_unit', '1') ? '' : '*1.609344'; $radius = isset($fields[$f_rad]) ? $fields[$f_rad]->value : ''; $sign = $match == 'radius_higher' ? '>' : '<'; $config['query_parts']['select'][] = '(((acos(sin((' . (double) $lat . '*pi()/180)) * sin((' . $t[0] . '.' . $s_lat . '*pi()/180))+cos((' . (double) $lat . '*pi()/180)) * cos((' . $t[0] . '.' . $s_lat . '*pi()/180)) * cos(((' . (double) $lng . '- ' . $t[0] . '.' . $s_lng . ')*pi()/180))))*180/pi())*60*1.1515' . $mod . ') AS ' . $alias; if ((int) $radius > 0) { $config['query_parts']['having'][] = $alias . ' ' . $sign . ' ' . $radius; $sql = '()'; // todo } else { $lat = number_format($lat, 8); $lng = number_format($lng, 8); $sql = '(' . $t[0] . '.' . $s_lat . ' = ' . JCckDatabase::quote($lat) . ' AND ' . $t[0] . '.' . $s_lng . ' = ' . JCckDatabase::quote($lng) . ')'; } } else { $sql = '()'; // todo } break; case 'none': return; break; default: $sql = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true) . '%', false); break; } return $sql; }
protected static function _where($table, $fieldnames, $values, $method = 'array') { $and = ''; $fields = JCckDatabase::loadObjectList('SELECT name, storage, storage_table, storage_field FROM #__cck_core_fields WHERE name IN ("' . str_replace('||', '","', $fieldnames) . '")', 'name'); $s_fields = array(); $where = explode('||', $fieldnames); if ($method == 'object') { foreach ($where as $w) { if (isset($fields[$w]) && $fields[$w]->storage == 'standard' && $fields[$w]->storage_table == $table) { $s_field = $fields[$w]->storage_field; $v = isset($values->{$s_field}) ? $values->{$s_field} : ''; if ($v != '' && !isset($s_fields[$s_field])) { $s_fields[$s_field] = ''; $and .= ' AND ' . $s_field . '="' . JCckDatabase::escape($v) . '"'; } } } } else { foreach ($where as $w) { if (isset($fields[$w]) && $fields[$w]->storage == 'standard' && $fields[$w]->storage_table == $table) { $v = $fields[$w]->value; if ($v != '' && !isset($s_fields[$s_field])) { $s_fields[$s_field] = ''; $and .= ' ' . $values[$w]->storage_field . '="' . JCckDatabase::escape($v) . '"'; } } } } return $and; }
public static function onCCK_StoragePrepareSearch(&$field, $match, $value, $name, $name2, $target) { $sql = ''; switch ($match) { case 'exact': $sql = $target . ' = ' . JCckDatabase::quote($value); break; case 'alpha': $sql = $target . ' LIKE ' . JCckDatabase::quote(JCckDatabase::escape($value, true) . '%', false); break; case 'zeta': /* Zeta is not the last letter of Greek alphabet but.. this won't be an issue here. */ $sql = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true), false); break; case 'any': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($v, true) . '%', false); } } if (count($fragments)) { $sql = '((' . implode(') OR (', $fragments) . '))'; } } break; case 'any_exact': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); $var_type = $field->match_options ? $field->match_options->get('var_type', 1) : 1; if (!$var_type) { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $v; } } } else { foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = JCckDatabase::quote($v); } } } if (count($fragments)) { $sql = $target . ' IN (' . implode(',', $fragments) . ')'; } } break; case 'each': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($v, true) . '%', false); } } if (count($fragments)) { $sql = '((' . implode(') AND (', $fragments) . '))'; } } break; case 'date_past_only': $sql = $target . ' < ' . JCckDatabase::quote($value); break; case 'date_past': $sql = $target . ' <= ' . JCckDatabase::quote($value); break; case 'date_future': $sql = $target . ' >= ' . JCckDatabase::quote($value); break; case 'date_future_only': $sql = $target . ' > ' . JCckDatabase::quote($value); break; case 'nested_exact': $table = $field->match_options ? $field->match_options->get('table', $field->storage_table) : $field->storage_table; $column = 'id'; $values = JCckDevHelper::getBranch($table, $value); if ($column != 'id') { if (count($values)) { $fragments = array(); foreach ($values as $v) { if ($v != '') { $fragments[] = JCckDatabase::quote($v); } } if (count($fragments)) { $sql = $target . ' IN (' . implode(',', $fragments) . ')'; } } } else { if (count($values)) { $sql = $target . ' IN (' . implode(',', $values) . ')'; } } break; case 'num_higher': $sql = $target . ' >= ' . JCckDatabase::quote($value); break; case 'num_higher_only': $sql = $target . ' > ' . JCckDatabase::quote($value); break; case 'num_lower': $sql = $target . ' <= ' . JCckDatabase::quote($value); break; case 'num_lower_only': $sql = $target . ' < ' . JCckDatabase::quote($value); break; case 'not_alpha': $sql = $target . ' NOT LIKE ' . JCckDatabase::quote(JCckDatabase::escape($value, true) . '%', false); break; case 'not_any_exact': $separator = $field->match_value ? $field->match_value : ' '; $values = explode($separator, $value); if (count($values)) { $fragments = array(); foreach ($values as $v) { if (strlen($v) > 0) { $fragments[] = JCckDatabase::quote($v); } } if (count($fragments)) { $sql = $target . ' NOT IN (' . implode(',', $fragments) . ')'; } } break; case 'not_zeta': /* Zeta is not the last letter of Greek alphabet but.. this won't be an issue here. */ $sql = $target . ' NOT LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true), false); break; case 'not_empty': $sql = $target . ' != ""'; break; case 'not_equal': $sql = $target . ' != ' . JCckDatabase::quote($value); break; case 'not_like': $sql = $target . ' NOT LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true) . '%', false); break; case 'not_null': $sql = $target . ' != "0"'; break; case 'is_null': $sql = $target . ' IS NULL'; break; case 'is_not_null': $sql = $target . ' IS NOT NULL'; break; case 'none': return; break; default: $sql = $target . ' LIKE ' . JCckDatabase::quote('%' . JCckDatabase::escape($value, true) . '%', false); break; } return $sql; }