+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015 |
+ | Copyright CiviCRM LLC (c) 2004-2016 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
*/
require_once 'HTML/QuickForm/Rule/Email.php';
return TRUE;
}
+ /**
+ * @param $str
+ *
+ * @return bool
+ */
+ public static function mysqlColumnNameLoose($str) {
+ // check the length.
+ // This check can be incorrect for the <table>.<column> format, which can be
+ // a problem.
+ if (empty($str) || strlen($str) > 64) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Validate an acceptable column name for sorting results.
+ *
+ * @param $str
+ *
+ * @return bool
+ */
+ public static function mysqlColumnName($str) {
+ // Check the length.
+ if (empty($str) || strlen($str) > 64) {
+ return FALSE;
+ }
+
+ // Make sure it only contains valid characters (alphanumeric and underscores).
+ //
+ // MySQL permits column names that don't match this (eg containing spaces),
+ // but CiviCRM won't create those ...
+ if (!preg_match('/^[\w_]+(\.[\w_]+)?$/i', $str)) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * Validate that a string is ASC or DESC.
+ *
+ * Empty string should be treated as invalid and ignored => default = ASC.
+ *
+ * @param $str
+ * @return bool
+ */
+ public static function mysqlOrderByDirection($str) {
+ if (!preg_match('/^(asc|desc)$/i', $str)) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
/**
* @param $str
*
return ($key) ? CRM_Core_Key::valid($key) : FALSE;
}
+ /**
+ * Check if the values in the date range are in correct chronological order.
+ *
+ * @param array $fields
+ * Fields of the form.
+ * @param $fieldName
+ * Name of date range field.
+ * @param $errors
+ * The error array.
+ * @param $title
+ * Title of the date range to be displayed in the error message.
+ */
+ public static function validDateRange($fields, $fieldName, &$errors, $title) {
+ $lowDate = strtotime($fields[$fieldName . '_low']);
+ $highDate = strtotime($fields[$fieldName . '_high']);
+
+ if ($lowDate > $highDate) {
+ $errors[$fieldName . '_range_error'] = ts('%1: Please check that your date range is in correct chronological order.', array(1 => $title));
+ }
+ }
+
}