summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1cfa87a)
raw | patch | inline | side by side (parent: 1cfa87a)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 3 Mar 2008 14:18:09 +0000 (14:18 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 3 Mar 2008 14:18:09 +0000 (14:18 +0000) |
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
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+
+class msgPool
+{
+
+ public static function toobig($name, $min= "")
+ {
+ if ($min == ""){
+ return (sprintf(_("Value for '%s' is too big!"), $name));
+ } else {
+ return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
+ }
+ }
+
+
+ public static function toosmall($name, $min= "")
+ {
+ if ($min == ""){
+ return (sprintf(_("Value for '%s' is too small!"), $name));
+ } else {
+ return (sprintf(_("'%s' must be %d or above!"), $name, $min));
+ }
+ }
+
+
+ public static function bigger($name1, $name2)
+ {
+ return (sprintf(_("'%s' should be bigger than '%s'!"), $name1, $name2));
+ }
+
+
+ public static function smaller($name1, $name2)
+ {
+ return (sprintf(_("'%s' should be smaller than '%s'!"), $name1, $name2));
+ }
+
+
+ public static function depends($name1, $name2)
+ {
+ return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
+ }
+
+
+ public static function duplicated($name)
+ {
+ return (sprintf(_("There is already an entry named '%s' in the system!"), $name));
+ }
+
+
+ public static function required($name)
+ {
+ return (sprintf(_("The required field '%s' is empty!"), $name));
+ }
+
+
+ public static function invalid($name, $data= "", $regex= "", $example= "")
+ {
+ /* Stylize example */
+ if ($example != ""){
+ $example= "<br><br>"._("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.= "<font style='color:red;'>".htmlentities($currentChar)."</font>";
+ $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))).
+ "<br><br> \"$result\"$example";
+ } else {
+ return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example";
+ }
+ }
+
+}
index 004c029d54b4343190352eac6a2a89f7e2930b00..0a9a6a566b125124f0369547bd6cd364b2671e17 100644 (file)
}
return($return);
}
+
}
?>
index 3697a719907df97a96dfff4762f8193a3d9a1432..9b735693646d6ac239757b0fac8b3cbb4f2867e2 100644 (file)
/* Assemble the message array to a plain string */
foreach ($message as $error){
- if ($complete == ""){
- $complete= $error;
- } else {
- $complete= "$error<br>$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 40dbc61d130661647e587f75cc66e356f28c5a0e..6edbf93e3bcfe894cc280c43709f8e9be7538e53 100644 (file)
/* 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;
}
$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 ce6e993d6b2f7a18c7306a288a0a67d0a4ab2756..750469f28deaf7e6f00f22ee2aa23b28147daffe 100644 (file)
/* 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 */
/* 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']);
}
}
}
/* 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);
}
{
$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");
}
}