Code

Added ldap error message to replace show_ldap_errors
[gosa.git] / gosa-core / include / utils / class_msgPool.inc
1 <?php
2 define ("LDAP_READ",   1);
3 define ("LDAP_ADD",    2);
4 define ("LDAP_MOD",    3);
5 define ("LDAP_DEL",    4);
6 define ("LDAP_SEARCH", 5);
7 define ("LDAP_AUTH",   6);
9 class msgPool
10 {
11   public static function permDelete($name= "")
12   {
13     if ($name == "") { 
14       return (_("You have no permission to delete this object!"));
15     }
17     if (!is_array($name)){
18       return (_("You have no permission to delete the object:")."<br><br><i>$name</i>");
19     }
21     msgPool::buildList($name);
22     if (count($name) == 1){
23       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
24     }
26     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
27   }
30   public static function permCreate($name= "")
31   {
32     if ($name == "") { 
33       return (_("You have no permission to create this object!"));
34     }
36     if (!is_array($name)){
37       return (_("You have no permission to create the object:")."<br><br><i>$name</i>");
38     }
40     if (count($name) == 1){
41       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
42     }
44     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
45   }
48   public static function permModify($name= "")
49   {
50     if ($name == "") { 
51       return (_("You have no permission to modify this object!"));
52     }
54     if (!is_array($name)){
55       return (_("You have no permission to modify the object:")."<br><br><i>$name</i>");
56     }
58     if (count($name) == 1){
59       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
60     }
62     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
63   }
66   public static function permView($name= "")
67   {
68     if ($name == "") { 
69       return (_("You have no permission to view this object!"));
70     }
72     if (!is_array($name)){
73       return (_("You have no permission to view the object:")."<br><br><i>$name</i>");
74     }
76     if (count($name) == 1){
77       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
78     }
80     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
81   }
84   public static function permMove($name= "")
85   {
86     if ($name == "") { 
87       return (_("You have no permission to move this object!"));
88     }
90     if (!is_array($name)){
91       return (_("You have no permission to move the object:")."<br><br><i>$name</i>");
92     }
94     if (count($name) == 1){
95       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
96     }
98     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
99   }
102   public static function dbconnect($name, $error= "", $dbinfo= "")
103   {
104     if ($error != ""){
105       $error= "<br><br><i>"._("Error").":</i> ".$error;
106     }
107     if ($dbinfo != ""){
108       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
109     }
110     return (sprintf(_("Cannot connect to %s database!"), $name).$error);
111   }
114   public static function dbselect($name, $error= "", $dbinfo= "")
115   {
116     if ($error != ""){
117       $error= "<br><br><i>"._("Error").":</i> ".$error;
118     }
119     if ($dbinfo != ""){
120       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
121     }
122     return (sprintf(_("Cannot select %s database!"), $name).$error);
123   }
126   public static function noserver($name)
127   {
128     return (sprintf(_("No %s server defined!"), $name));
129   }
132   public static function dbquery($name, $error= "", $dbinfo= "")
133   {
134     if ($error != ""){
135       $error= "<br><br><i>"._("Error").":</i> ".$error;
136     }
137     if ($dbinfo != ""){
138       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
139     }
140     return (sprintf(_("Cannot query %s database!"), $name).$error);
141   }
144   public static function reserved($name)
145   {
146     return (sprintf(_("The field '%s' contains a reserved keyword!"), $name));
147   }
150   public static function cmdnotfound($type, $plugin)
151   {
152     return (sprintf(_("Command specified as %s hook for plugin '%s' does not exist!"), $type, $plugin));
153   }
156   public static function toobig($name, $min= "")
157   {
158     if ($min == ""){
159       return (sprintf(_("Value for '%s' is too large!"), $name));
160     } else {
161       return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
162     }
163   }
166   public static function toosmall($name, $min= "")
167   {
168     if ($min == ""){
169       return (sprintf(_("Value for '%s' is too small!"), $name));
170     } else {
171       return (sprintf(_("'%s' must be %d or above!"), $name, $min));
172     }
173   }
176   public static function depends($name1, $name2)
177   {
178     return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
179   }
182   public static function duplicated($name)
183   {
184     return (sprintf(_("There is already an entry with this '%s' attribute in the system!"), $name));
185   }
188   public static function required($name)
189   {
190     return (sprintf(_("The required field '%s' is empty!"), $name));
191   }
194   public static function invalid($name, $data= "", $regex= "", $example= "")
195   {
196     /* Stylize example */
197     if ($example != ""){
198       $example= "<br><br><i>"._("Example").":</i> ".$example;
199     }
201     /* If validChars are posted, take data and paint all invalid
202        characters... */
203     if ($regex) {
204       $result= "";
205       $mismatch= "";
206       foreach (str_split($data) as $currentChar){
207         if (preg_match("$regex", $currentChar)){
208           $result.= $currentChar;
209         } else {
210           $result.= "<font style='color:red;text-decoration:underline;'>".htmlentities($currentChar)."</font>";
211           $mismatch.= $currentChar;
212         }
213       }
215       return sprintf(_("The Field '%s' contains invalid characters"), $name).". ".
216              (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed."), htmlentities($mismatch))).
217              "<br><br> \"$result\"$example";
218     } else {
219       return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example";
220     }
221   }
224   public static function missingext($name)
225   {
226     return sprintf(_("Missing %s PHP extension!"), $name);
227   }
230   public static function cancelButton()
231   {
232     return sprintf(_("Cancel"));
233   }
236   public static function okButton()
237   {
238     return sprintf(_("Ok"));
239   }
242   public static function applyButton()
243   {
244     return sprintf(_("Apply"));
245   }
248   public static function saveButton()
249   {
250     return sprintf(_("Save"));
251   }
254   public static function addButton($what= "")
255   {
256     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
257   }
260   public static function delButton($what= "")
261   {
262     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
263   }
266   public static function setButton($what= "")
267   {
268     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
269   }
272   public static function editButton($what= "")
273   {
274     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
275   }
278   public static function buildList($data)
279   {
280     $objects= "";
281     foreach ($name as $key => $value){
282       if (is_numeric($key)){
283         $objects.= "<br>\n<i>$value</i>";
284       } else {
285         $objects.= "<br>\n$value (<i>$key</i>)";
286       }
287     }
288   }
290   public static function noValidExtension($name)
291   {
292         return sprintf(_("This account has no valid %s extensions!", $name));
293   }
295   public static function featuresEnabled($name, $depends= "")
296   {
297         if ($depends == ""){
298                 return sprintf(_("This account has %s settings enabled. You can disable them by clicking below."), $name);
299         } else {
300                 if (is_array($depends)){
301                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $depends);
302                 } else {
303                         $deps= "";
304                         foreach ($depends as $dep){
305                                 $deps.= "$dep / ";
306                         }
307                         $deps= preg_replace("/ \/ $/", "", $deps);
308                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $deps);
309                 }
310         }
311   }
314   public static function featuresDisabled($name, $depends= "")
315   {
316         if ($depends == ""){
317                 return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), $name);
318         } else {
319                 if (is_array($depends)){
320                         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $depends);
321                 } else {
322                         $deps= "";
323                         foreach ($depends as $dep){
324                                 $deps.= "$dep / ";
325                         }
326                         $deps= preg_replace("/ \/ $/", "", $deps);
327                         return sprintf(_("This account has %s features settings. To disable them, you'll need to add the %s settings first!"), $deps);
328                 }
329         }
330   }
333   public static function addFeaturesButton($name)
334   {
335         return sprintf(_("Add %s settings"), $name);
336   }
339   public static function removeFeaturesButton($name)
340   {
341         return sprintf(_("Remove %s settings"), $name);
342   }
345   public static function clickEditToChange()
346   {
347         return _("Click the 'Edit' button below to change informations in this dialog");
348   }
351   public static function months()
352   {
353         return array(_("January"), _("February"), _("March"), _("April"),
354                         _("May"), _("June"), _("July"), _("August"), _("September"),
355                         _("October"), _("November"), _("December"));
356   }
359   public static function weekdays()
360   {
361         return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
362   }
365   public static function ldaperror($error, $dn= "", $type= 0, $plugin= "")
366   {
367         /* Assign headline depending on type */
368         $typemap= array(1 => _("read operation"), _("add operation"), _("modify operation"),
369                              _("delete operation"), _("search operation"), _("authentication"));
370         
371         if (isset($typemap[$type])){
372                 $headline= sprintf(_("LDAP %s failed!"), $typemap[$type]);
373         } else {
374                 $headline= _("LDAP operation failed!");
375         }
377         /* Fill DN information */
378         if ($dn != ""){
379                 $dn_info= "<br><br><i>"._("Object").":</i> ".LDAP::fix($dn);
380         }
382         return $headline.$dn_info."<br><br><i>"._("Error").":</i> ".$error;
383   }
388 ?>