From: cajus Date: Mon, 3 Mar 2008 14:18:09 +0000 (+0000) Subject: Added error msg unifyer X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f33a33219e6aa7088341488689833a6f9ec2d54c;p=gosa.git Added error msg unifyer git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9246 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_msgPool.inc b/gosa-core/include/class_msgPool.inc new file mode 100644 index 000000000..e7e6d7817 --- /dev/null +++ b/gosa-core/include/class_msgPool.inc @@ -0,0 +1,85 @@ +
"._("Example:")." ".$example; + } + + /* If validChars are posted, take data and paint all invalid + characters... */ + if ($regex) { + $result= ""; + $mismatch= ""; + foreach (str_split($data) as $currentChar){ + if (preg_match("$regex", $currentChar)){ + $result.= $currentChar; + } else { + $result.= "".htmlentities($currentChar).""; + $mismatch.= $currentChar; + } + } + + return sprintf(_("The Field '%s' contains invalid characters"), $name).". ". + (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed."), htmlentities($mismatch))). + "

\"$result\"$example"; + } else { + return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example"; + } + } + +} diff --git a/gosa-core/include/class_msg_dialog.inc b/gosa-core/include/class_msg_dialog.inc index 004c029d5..0a9a6a566 100644 --- a/gosa-core/include/class_msg_dialog.inc +++ b/gosa-core/include/class_msg_dialog.inc @@ -164,5 +164,6 @@ class msg_dialog } return($return); } + } ?> diff --git a/gosa-core/include/functions.inc b/gosa-core/include/functions.inc index 3697a7199..9b7356936 100644 --- a/gosa-core/include/functions.inc +++ b/gosa-core/include/functions.inc @@ -1361,15 +1361,8 @@ function show_errors($message) /* Assemble the message array to a plain string */ foreach ($message as $error){ - if ($complete == ""){ - $complete= $error; - } else { - $complete= "$error
$complete"; - } + msg_dialog::display(_("Error"), $error, ERROR_DIALOG); } - - /* Fill ERROR variable with nice error dialog */ - msg_dialog::display(_("Error"), $complete, ERROR_DIALOG); } diff --git a/gosa-core/plugins/personal/generic/class_user.inc b/gosa-core/plugins/personal/generic/class_user.inc index 40dbc61d1..6edbf93e3 100644 --- a/gosa-core/plugins/personal/generic/class_user.inc +++ b/gosa-core/plugins/personal/generic/class_user.inc @@ -1106,59 +1106,58 @@ class user extends plugin /* In template mode, the uid and givenName are autogenerated... */ if (!$this->is_template){ if ($this->sn == ""){ - $message[]= _("The required field 'Name' is not set."); + $message[]= msgPool::required(_("Name")); } if ($this->givenName == ""){ - $message[]= _("The required field 'Given name' is not set."); + $message[]= msgPool::required(_("Given name")); } if ($this->uid == ""){ - $message[]= _("The required field 'Login' is not set."); + $message[]= msgPool::required(_("Login")); } if (!(isset($this->config->current['DNMODE']) && $this->config->current['DNMODE'] == "uid")){ $ldap->cat($this->new_dn); if ($ldap->count() != 0 && $this->dn != $this->new_dn && $this->dn == 'new'){ - $message[]= _("There's already a person with this 'Name'/'Given name' combination in the database."); + $message[]= msgPool::duplicated("cn=".$this->cn); } } } /* Check for valid input */ if ($this->is_modified && !tests::is_uid($this->uid)){ - $message[]= _("The field 'Login' contains invalid characters. Lowercase, numbers and dashes are allowed."); + + if (strict_uid_mode()){ + $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/"); + } else { + $message[]= msgPool::invalid(_("Login"), $this->uid, "/[a-z0-9_-]/i"); + } } if (!tests::is_url($this->labeledURI)){ - $message[]= _("The field 'Homepage' contains an invalid URL definition."); - } - if (preg_match ("/[\\\\]/", $this->sn)){ - $message[]= _("The field 'Name' contains invalid characters."); - } - if (preg_match ("/[\\\\]/", $this->givenName)){ - $message[]= _("The field 'Given name' contains invalid characters."); + $message[]= msgPool::invalid(_("Homepage"), "", "", "http://www.example.com/yourname"); } /* Check phone numbers */ if (!tests::is_phone_nr($this->telephoneNumber)){ - $message[]= _("The field 'Phone' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){ - $message[]= _("The field 'Fax' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->mobile)){ - $message[]= _("The field 'Mobile' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->pager)){ - $message[]= _("The field 'Pager' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/"); } /* Check for reserved characers */ - if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName)){ - $message[]= _("The field 'Given name' contains invalid characters."); - } - if (preg_match ('/[,+"?\'()=<>;]/', $this->sn)){ - $message[]= _("The field 'Name' contains invalid characters."); - } + if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName)){ + $message[]= msgPool::invalid(_("Given name"), $this->givenName, '/[^,+"?\'()=<>;\\\\]/'); + } + if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn)){ + $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/'); + } - return $message; + return $message; } @@ -1523,31 +1522,25 @@ class user extends plugin $this->set_acl_base($this->base); } if (!tests::is_url($this->labeledURI) && in_array("labeledURI",$this->multi_boxes)){ - $message[]= _("The field 'Homepage' contains an invalid URL definition."); - } - if (preg_match ("/[\\\\]/", $this->sn) && in_array("sn",$this->multi_boxes)){ - $message[]= _("The field 'Name' contains invalid characters."); - } - if (preg_match ("/[\\\\]/", $this->givenName) && in_array("givenName",$this->multi_boxes)){ - $message[]= _("The field 'Given name' contains invalid characters."); + $message[]= msgPool::invalid(_("Homepage")); } if (!tests::is_phone_nr($this->telephoneNumber) && in_array("telephoneNumber",$this->multi_boxes)){ - $message[]= _("The field 'Phone' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->facsimileTelephoneNumber) && in_array("facsimileTelephoneNumber",$this->multi_boxes)){ - $message[]= _("The field 'Fax' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->mobile) && in_array("mobile",$this->multi_boxes)){ - $message[]= _("The field 'Mobile' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Mobile"), $this->mobile, "/[\/0-9 ()+*-]/"); } if (!tests::is_phone_nr($this->pager) && in_array("pager",$this->multi_boxes)){ - $message[]= _("The field 'Pager' contains an invalid phone number."); + $message[]= msgPool::invalid(_("Pager"), $this->pager, "/[\/0-9 ()+*-]/"); } - if (preg_match ('/[,+"?\'()=<>;]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){ - $message[]= _("The field 'Given name' contains invalid characters."); + if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->givenName) && in_array("givenName",$this->multi_boxes)){ + $message[]= msgPool::invalid(_("Given name"), $this->giveName, '/[^,+"?\'()=<>;\\\\]/'); } - if (preg_match ('/[,+"?\'()=<>;]/', $this->sn) && in_array("sn",$this->multi_boxes)){ - $message[]= _("The field 'Name' contains invalid characters."); + if (preg_match ('/[,+"?\'()=<>;\\\\]/', $this->sn) && in_array("sn",$this->multi_boxes)){ + $message[]= msgPool::invalid(_("Name"), $this->sn, '/[^,+"?\'()=<>;\\\\]/'); } return($message); } diff --git a/gosa-core/plugins/personal/posix/class_posixAccount.inc b/gosa-core/plugins/personal/posix/class_posixAccount.inc index ce6e993d6..750469f28 100644 --- a/gosa-core/plugins/personal/posix/class_posixAccount.inc +++ b/gosa-core/plugins/personal/posix/class_posixAccount.inc @@ -982,10 +982,10 @@ class posixAccount extends plugin /* must: homeDirectory */ if ($this->homeDirectory == ""){ - $message[]= _("The required field 'Home directory' is not set."); + $message[]= msgPool::required(_("Home directory")); } if (!tests::is_path($this->homeDirectory)){ - $message[]= _("Please enter a valid path in 'Home directory' field."); + $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" ); } /* Check ID's if they are forced by user */ @@ -993,17 +993,17 @@ class posixAccount extends plugin /* Valid uid/gid? */ if (!tests::is_id($this->uidNumber)){ - $message[]= _("Value specified as 'UID' is not valid."); + $message[]= msgPool::invalid(_("UID"), $this->uidNumber, "/[0-9]/"); } else { if ($this->uidNumber < $this->config->current['MINID']){ - $message[]= _("Value specified as 'UID' is too small."); + $message[]= msgPool::toosmall(_("UID"), $this->config->current['MINID']); } } if (!tests::is_id($this->gidNumber)){ - $message[]= _("Value specified as 'GID' is not valid."); + $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/"); } else { if ($this->gidNumber < $this->config->current['MINID']){ - $message[]= _("Value specified as 'GID' is too small."); + $message[]= msgPool::toosmall(_("GID"), $this->config->current['MINID']); } } } @@ -1011,46 +1011,42 @@ class posixAccount extends plugin /* Check shadow settings, well I like spaghetties... */ if ($this->activate_shadowMin){ if (!tests::is_id($this->shadowMin)){ - $message[]= _("Value specified as 'shadowMin' is not valid."); + $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/"); } } if ($this->activate_shadowMax){ if (!tests::is_id($this->shadowMax)){ - $message[]= _("Value specified as 'shadowMax' is not valid."); + $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/"); } } if ($this->activate_shadowWarning){ if (!tests::is_id($this->shadowWarning)){ - $message[]= _("Value specified as 'shadowWarning' is not valid."); + $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/"); } if (!$this->activate_shadowMax){ - $message[]= _("'shadowWarning' without 'shadowMax' makes no sense."); + $message[]= msgPool::depends("shadowWarning", "shadowMax"); } if ($this->shadowWarning > $this->shadowMax){ - $message[]= _("Value specified as 'shadowWarning' should be smaller than 'shadowMax'."); + $message[]= msgPool::smaller("shadowWarning", "shadowMax"); } if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin){ - $message[]= _("Value specified as 'shadowWarning' should be greater than 'shadowMin'."); + $message[]= msgPool::bigger("shadowWarning", "shadowMin"); } } if ($this->activate_shadowInactive){ if (!tests::is_id($this->shadowInactive)){ - $message[]= _("Value specified as 'shadowInactive' is not valid."); + $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/"); } if (!$this->activate_shadowMax){ - $message[]= _("'shadowInactive' without 'shadowMax' makes no sense."); + $message[]= msgPool::depends("shadowInactive", "shadowMax"); } } if ($this->activate_shadowMin && $this->activate_shadowMax){ if ($this->shadowMin > $this->shadowMax){ - $message[]= _("Value specified as 'shadowMin' should be smaller than 'shadowMax'."); + $message[]= msgPool::smaller("shadowMin", "shadowMax"); } } - // if(empty($this->gosaDefaultPrinter)){ - // $message[]= _("You need to specify a valid default printer."); - // } - return ($message); } @@ -1059,48 +1055,48 @@ class posixAccount extends plugin { $message = plugin::multiple_check(); if ($this->homeDirectory == "" && in_array("homeDirectory",$this->multi_boxes)){ - $message[]= _("The required field 'Home directory' is not set."); + $message[]= msgPool::required(_("Home directory")); } if (!tests::is_path($this->homeDirectory) && in_array("homeDirectory",$this->multi_boxes)){ - $message[]= _("Please enter a valid path in 'Home directory' field."); + $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" ); } /* Check shadow settings, well I like spaghetties... */ if ($this->activate_shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){ if (!tests::is_id($this->shadowMin)){ - $message[]= _("Value specified as 'shadowMin' is not valid."); + $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/"); } } if ($this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){ if (!tests::is_id($this->shadowMax)){ - $message[]= _("Value specified as 'shadowMax' is not valid."); + $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/"); } } if ($this->activate_shadowWarning && in_array("activate_shadowWarning",$this->multi_boxes)){ if (!tests::is_id($this->shadowWarning)){ - $message[]= _("Value specified as 'shadowWarning' is not valid."); + $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/"); } if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){ - $message[]= _("'shadowWarning' without 'shadowMax' makes no sense."); + $message[]= msgPool::depends("shadowWarning", "shadowMax"); } if ($this->shadowWarning > $this->shadowMax && in_array("activate_shadowWarning",$this->multi_boxes)){ - $message[]= _("Value specified as 'shadowWarning' should be smaller than 'shadowMax'."); + $message[]= msgPool::smaller("shadowWarning", "shadowMax"); } if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){ - $message[]= _("Value specified as 'shadowWarning' should be greater than 'shadowMin'."); + $message[]= msgPool::bigger("shadowWarning", "shadowMin"); } } if ($this->activate_shadowInactive && in_array("activate_shadowInactive",$this->multi_boxes)){ if (!tests::is_id($this->shadowInactive)){ - $message[]= _("Value specified as 'shadowInactive' is not valid."); + $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/"); } if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){ - $message[]= _("'shadowInactive' without 'shadowMax' makes no sense."); + $message[]= msgPool::depends("shadowInactive", "shadowMax"); } } if ($this->activate_shadowMin && $this->activate_shadowMax && in_array("activate_shadowMin",$this->multi_boxes)){ if ($this->shadowMin > $this->shadowMax){ - $message[]= _("Value specified as 'shadowMin' should be smaller than 'shadowMax'."); + $message[]= msgPool::smaller("shadowMin", "shadowMax"); } }