Code

Updated pool message
[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 deleteInfo($name= "",$type = "")
12   {
13           if ($name == "") { 
14                   if($type == ""){
15                           return (_("This object will be deleted!"));
16                   }else{
17                           return (sprintf(_("This '%s' object will be deleted!"), $type));
18                   }
19           }
20           if (!is_array($name)){
21                   if($type == ""){
22                           return (sprintf(_("This object will be deleted: $s"), "<br><br><i>$name</i>"));
23                   }else{
24                           return (sprintf(_("This '%s' object will be deleted: %s"),$type, "<br><br><i>$name</i>"));
25                   }
26           }
27           if (count($name) == 1){
28                   if($type == ""){
29                           return (_("This object will be deleted:")."<br>".msgPool::buildList($name));
30                   }else{
31                           return (sprintf(_("This '%s' object will be deleted:"),$type, "<br>".msgPool::buildList($name)));
32                   }
33           }
34           if($type == ""){
35                   return (sprintf(_("These objects will be deleted: %s"), "<br>".msgPool::buildList($name)));
36           }else{
37                   return (sprintf(_("These '%s' objects will be deleted: %s"),$type, "<br>".msgPool::buildList($name)));
38           }
39   }
42   public static function permDelete($name= "")
43   {
44     if ($name == "") { 
45       return (_("You have no permission to delete this object!"));
46     }
48     if (!is_array($name)){
49       return (_("You have no permission to delete the object:")."<br><br><i>$name</i>");
50     }
52     msgPool::buildList($name);
53     if (count($name) == 1){
54       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
55     }
57     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
58   }
61   public static function permCreate($name= "")
62   {
63     if ($name == "") { 
64       return (_("You have no permission to create this object!"));
65     }
67     if (!is_array($name)){
68       return (_("You have no permission to create the object:")."<br><br><i>$name</i>");
69     }
71     if (count($name) == 1){
72       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
73     }
75     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
76   }
79   public static function permModify($name= "")
80   {
81     if ($name == "") { 
82       return (_("You have no permission to modify this object!"));
83     }
85     if (!is_array($name)){
86       return (_("You have no permission to modify the object:")."<br><br><i>$name</i>");
87     }
89     if (count($name) == 1){
90       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
91     }
93     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
94   }
97   public static function permView($name= "")
98   {
99     if ($name == "") { 
100       return (_("You have no permission to view this object!"));
101     }
103     if (!is_array($name)){
104       return (_("You have no permission to view the object:")."<br><br><i>$name</i>");
105     }
107     if (count($name) == 1){
108       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
109     }
111     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
112   }
115   public static function permMove($name= "")
116   {
117     if ($name == "") { 
118       return (_("You have no permission to move this object!"));
119     }
121     if (!is_array($name)){
122       return (_("You have no permission to move the object:")."<br><br><i>$name</i>");
123     }
125     if (count($name) == 1){
126       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
127     }
129     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
130   }
133   public static function dbconnect($name, $error= "", $dbinfo= "")
134   {
135     if ($error != ""){
136       $error= "<br><br><i>"._("Error").":</i> ".$error;
137     }
138     if ($dbinfo != ""){
139       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
140     }
141     return (sprintf(_("Cannot connect to %s database!"), $name).$error);
142   }
145   public static function dbselect($name, $error= "", $dbinfo= "")
146   {
147     if ($error != ""){
148       $error= "<br><br><i>"._("Error").":</i> ".$error;
149     }
150     if ($dbinfo != ""){
151       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
152     }
153     return (sprintf(_("Cannot select %s database!"), $name).$error);
154   }
157   public static function noserver($name)
158   {
159     return (sprintf(_("No %s server defined!"), $name));
160   }
163   public static function dbquery($name, $error= "", $dbinfo= "")
164   {
165     if ($error != ""){
166       $error= "<br><br><i>"._("Error").":</i> ".$error;
167     }
168     if ($dbinfo != ""){
169       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
170     }
171     return (sprintf(_("Cannot query %s database!"), $name).$error);
172   }
175   public static function reserved($name)
176   {
177     return (sprintf(_("The field '%s' contains a reserved keyword!"), $name));
178   }
181   public static function cmdnotfound($type, $plugin)
182   {
183     return (sprintf(_("Command specified as %s hook for plugin '%s' does not exist!"), $type, $plugin));
184   }
187   public static function toobig($name, $min= "")
188   {
189     if ($min == ""){
190       return (sprintf(_("Value for '%s' is too large!"), $name));
191     } else {
192       return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
193     }
194   }
197   public static function toosmall($name, $min= "")
198   {
199     if ($min == ""){
200       return (sprintf(_("Value for '%s' is too small!"), $name));
201     } else {
202       return (sprintf(_("'%s' must be %d or above!"), $name, $min));
203     }
204   }
207   public static function depends($name1, $name2)
208   {
209     return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
210   }
213   public static function duplicated($name)
214   {
215     return (sprintf(_("There is already an entry with this '%s' attribute in the system!"), $name));
216   }
219   public static function required($name)
220   {
221     return (sprintf(_("The required field '%s' is empty!"), $name));
222   }
225   public static function invalid($name, $data= "", $regex= "", $example= "")
226   {
227     /* Stylize example */
228     if ($example != ""){
229       $example= "<br><br><i>"._("Example").":</i> ".$example;
230     }
232     /* If validChars are posted, take data and paint all invalid
233        characters... */
234     if ($regex) {
235       $result= "";
236       $mismatch= "";
237       foreach (str_split($data) as $currentChar){
238         if (preg_match("$regex", $currentChar)){
239           $result.= $currentChar;
240         } else {
241           $result.= "<font style='color:red;text-decoration:underline;'>".htmlentities($currentChar)."</font>";
242           $mismatch.= $currentChar;
243         }
244       }
246       return sprintf(_("The Field '%s' contains invalid characters"), $name).". ".
247              (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed."), htmlentities($mismatch))).
248              "<br><br> \"$result\"$example";
249     } else {
250       return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example";
251     }
252   }
255   public static function missingext($name)
256   {
257     return sprintf(_("Missing %s PHP extension!"), $name);
258   }
261   public static function cancelButton()
262   {
263     return sprintf(_("Cancel"));
264   }
267   public static function okButton()
268   {
269     return sprintf(_("Ok"));
270   }
273   public static function applyButton()
274   {
275     return sprintf(_("Apply"));
276   }
279   public static function saveButton()
280   {
281     return sprintf(_("Save"));
282   }
285   public static function addButton($what= "")
286   {
287     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
288   }
291   public static function delButton($what= "")
292   {
293     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
294   }
297   public static function setButton($what= "")
298   {
299     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
300   }
303   public static function editButton($what= "")
304   {
305     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
306   }
309   public static function backButton($what= "")
310   {
311     return $what == "" ? sprintf(_("Back...")): sprintf(_("Back %s..."), $what);
312   }
315   public static function buildList($data)
316   {
317     $objects= "";
318     foreach ($data as $key => $value){
319       if (is_numeric($key)){
320         $objects.= "<br>\n<i>$value</i>";
321       } else {
322         $objects.= "<br>\n$value (<i>$key</i>)";
323       }
324     }
325   }
327   public static function noValidExtension($name)
328   {
329         return sprintf(_("This account has no valid %s extensions!"), $name);
330   }
332   public static function featuresEnabled($name, $depends= "")
333   {
334         if ($depends == ""){
335                 return sprintf(_("This account has %s settings enabled. You can disable them by clicking below."), $name);
336         } else {
337                 if (count($depends) == 1){
338                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $depends);
339                 } else {
340                         $deps= "";
341                         foreach ($depends as $dep){
342                                 $deps.= "$dep / ";
343                         }
344                         $deps= preg_replace("/ \/ $/", "", $deps);
345                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $deps);
346                 }
347         }
348   }
351   public static function featuresDisabled($name, $depends= "")
352   {
353         if ($depends == ""){
354                 return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), $name);
355         } else {
356                 if (count($depends) == 1){
357                         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $depends);
358                 } else {
359                         $deps= "";
360                         foreach ($depends as $dep){
361                                 $deps.= "$dep / ";
362                         }
363                         $deps= preg_replace("/ \/ $/", "", $deps);
364                         return sprintf(_("This account has %s features settings. To disable them, you'll need to add the %s settings first!"), $name, $deps);
365                 }
366         }
367   }
370   public static function addFeaturesButton($name)
371   {
372         return sprintf(_("Add %s settings"), $name);
373   }
376   public static function removeFeaturesButton($name)
377   {
378         return sprintf(_("Remove %s settings"), $name);
379   }
382   public static function clickEditToChange()
383   {
384         return _("Click the 'Edit' button below to change informations in this dialog");
385   }
388   public static function months()
389   {
390         return array(_("January"), _("February"), _("March"), _("April"),
391                         _("May"), _("June"), _("July"), _("August"), _("September"),
392                         _("October"), _("November"), _("December"));
393   }
396   public static function weekdays()
397   {
398         return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
399   }
402   public static function ldaperror($error, $dn= "", $type= 0, $plugin= "")
403   {
404         /* Assign headline depending on type */
405         $typemap= array(1 => _("read operation"), _("add operation"), _("modify operation"),
406                              _("delete operation"), _("search operation"), _("authentication"));
407         
408         if (isset($typemap[$type])){
409                 $headline= sprintf(_("LDAP %s failed!"), $typemap[$type]);
410         } else {
411                 $headline= _("LDAP operation failed!");
412         }
414         /* Fill DN information */
415         if ($dn != ""){
416                 $dn_info= "<br><br><i>"._("Object").":</i> ".LDAP::fix($dn);
417         }
419         return $headline.$dn_info."<br><br><i>"._("Error").":</i> ".$error;
420   }
425 ?>