58 if (empty($outputLang)) {
59 $this->outputLang = $langs;
61 $this->outputLang = $outputLang;
64 if (!is_object($this->outputLang) || !method_exists($this->outputLang,
'load')) {
68 $this->outputLang->loadLangs(array(
'validate',
'errors'));
91 $this->error = $errMsg;
101 public function isEmail($email, $maxLength = 0)
103 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
104 $this->error = $this->outputLang->trans(
'RequireValidEmail');
118 if (!preg_match(
'/^[0-9]{1,10}(\.[0-9]{1,9})?$/ui', $price)) {
119 $this->error = $this->outputLang->trans(
'RequireValidValue');
133 if (!is_numeric($stamp) && (
int) $stamp == $stamp) {
134 $this->error = $this->outputLang->trans(
'RequireValidDate');
148 if (!preg_match(
'/^[+0-9. ()-]*$/ui', $phone)) {
149 $this->error = $this->outputLang->trans(
'RequireValidPhone');
164 if (strlen($string) > $length) {
165 $this->error = $this->outputLang->trans(
'RequireMaxLength', $length);
179 if (!strlen($string)) {
180 $this->error = $this->outputLang->trans(
'RequireANotEmptyValue');
195 if (strlen($string) < $length) {
196 $this->error = $this->outputLang->trans(
'RequireMinLength', $length);
210 if (!filter_var($url, FILTER_VALIDATE_URL)) {
211 $this->error = $this->outputLang->trans(
'RequireValidUrl');
225 if (!is_int($duration) && $duration >= 0) {
226 $this->error = $this->outputLang->trans(
'RequireValidDuration');
240 if (!is_numeric($string)) {
241 $this->error = $this->outputLang->trans(
'RequireValidNumeric');
255 if (!(is_null($bool) || is_bool($bool) || preg_match(
'/^[0|1]{1}$/ui', $bool))) {
256 $this->error = $this->outputLang->trans(
'RequireValidBool');
271 public function isInDb($values, $table, $col)
273 if (!is_array($values)) {
274 $value_arr = array($values);
276 $value_arr = $values;
279 if (!count($value_arr)) {
280 $this->error = $this->outputLang->trans(
'RequireValue');
284 foreach ($value_arr as $val) {
285 $sql =
"SELECT ".$col.
" FROM ".$this->db->prefix().$table.
" WHERE ".$col.
" = '".$this->db->escape($val).
"' LIMIT 1";
286 $resql = $this->db->query($sql);
288 $obj = $this->db->fetch_object($resql);
294 $this->error = $this->outputLang->trans(
'RequireValidExistingElement');
310 public function isFetchable(
$id, $classname, $classpath)
312 if (!empty($classpath)) {
314 if ($classname && class_exists($classname)) {
316 $object =
new $classname($this->db);
317 '@phan-var-force CommonObject|User $object';
319 if (!is_callable(array(
$object,
'fetch')) || !is_callable(array(
$object,
'isExistingObject'))) {
320 $this->error = $this->outputLang->trans(
'BadSetupOfFieldFetchNotCallable');
327 $this->error = $this->outputLang->trans(
'RequireValidExistingElement');
330 $this->error = $this->outputLang->trans(
'BadSetupOfFieldClassNotFoundForValidation');
333 $this->error = $this->outputLang->trans(
'BadSetupOfFieldFileNotFound');
336 $this->error = $this->outputLang->trans(
'BadSetupOfField');
354 return $this->isFetchable(
$id, $elementProperty[
'classname'], $elementProperty[
'classpath'].
'/'.$elementProperty[
'classfile'].
'.class.php');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class toolbox to validate values.
isMinLength($string, $length)
Check for string min length validity.
isNotEmptyString($string)
Check for string not empty.
isNumeric($string)
Check numeric validity.
isDuration($duration)
Check Duration validity.
isInDb($values, $table, $col)
Check for all values in db.
isMaxLength($string, $length)
Check for string max length validity.
__construct($db, $outputLang=null)
Constructor.
clear()
Use to clear errors msg or other ghost vars.
isFetchableElement($id, $element_type)
Check for all values in db for an element.
setError($errMsg)
Use to clear errors msg or other ghost vars.
isPrice($price)
Check for price validity.
isBool($bool)
Check for boolean validity.
isTimestamp($stamp)
Check for timestamp validity.
isEmail($email, $maxLength=0)
Check for e-mail validity.
isPhone($phone)
Check for phone validity.
isUrl($url)
Check url validity.
getElementProperties($elementType)
Get an array with properties of an element.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.