Code

Created trunk inside of 2.6-lhm
[gosa.git] / trunk / 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 {
12   public static function selectToView($type,$o_type = "")
13   {
14     if($o_type == ""){
15       return(sprintf(_("Select to list objects of type '%s'."),$type));
16     }elseif($o_type == "contains"){
17       return(sprintf(_("Select to list objects containig '%s'."),$type));
18     }elseif($o_type == "enabled"){
19       return(sprintf(_("Select to list objects that have '%s' enabled"),$type));
20     }elseif($o_type == "subsearch"){
21       return(_("Select to search within subtrees"));
22     }elseif($o_type == "subsearch_small"){
23       return(_("Search in subtrees"));
24     }
26   }
29   public static function deleteInfo($name= "",$type = "")
30   {
31     if ($name == "") { 
32       if($type == ""){
33         return (_("This object will be deleted!"));
34       }else{
35         return (sprintf(_("This '%s' object will be deleted!"), $type));
36       }
37     }
38     if (!is_array($name)){
39       if($type == ""){
40         return (sprintf(_("This object will be deleted: %s"), "<br><br><i>$name</i>"));
41       }else{
42         return (sprintf(_("This '%s' object will be deleted: %s"),$type, "<br><br><i>$name</i>"));
43       }
44     }
45     if (count($name) == 1){
46       if($type == ""){
47         return (_("This object will be deleted:")."<br>".msgPool::buildList($name));
48       }else{
49         return (sprintf(_("This '%s' object will be deleted:"),$type). "<br>".msgPool::buildList($name));
50       }
51     }
52     if($type == ""){
53       return (sprintf(_("These objects will be deleted: %s"), "<br>".msgPool::buildList($name)));
54     }else{
55       return (sprintf(_("These '%s' objects will be deleted: %s"),$type, "<br>".msgPool::buildList($name)));
56     }
57   }
60   public static function permDelete($name= "")
61   {
62     if ($name == "") { 
63       return (_("You have no permission to delete this object!"));
64     }
66     if (!is_array($name)){
67       return (_("You have no permission to delete the object:")."<br><br><i>$name</i>");
68     }
70     if (count($name) == 1){
71       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
72     }
74     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
75   }
78   public static function permCreate($name= "")
79   {
80     if ($name == "") { 
81       return (_("You have no permission to create this object!"));
82     }
84     if (!is_array($name)){
85       return (_("You have no permission to create the object:")."<br><br><i>$name</i>");
86     }
88     if (count($name) == 1){
89       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
90     }
92     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
93   }
96   public static function permModify($name= "")
97   {
98     if ($name == "") { 
99       return (_("You have no permission to modify this object!"));
100     }
102     if (!is_array($name)){
103       return (_("You have no permission to modify the object:")."<br><br><i>$name</i>");
104     }
106     if (count($name) == 1){
107       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
108     }
110     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
111   }
114   public static function permView($name= "")
115   {
116     if ($name == "") { 
117       return (_("You have no permission to view this object!"));
118     }
120     if (!is_array($name)){
121       return (_("You have no permission to view the object:")."<br><br><i>$name</i>");
122     }
124     if (count($name) == 1){
125       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
126     }
128     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
129   }
132   public static function permMove($name= "")
133   {
134     if ($name == "") { 
135       return (_("You have no permission to move this object!"));
136     }
138     if (!is_array($name)){
139       return (_("You have no permission to move the object:")."<br><br><i>$name</i>");
140     }
142     if (count($name) == 1){
143       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
144     }
146     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
147   }
150   public static function dbconnect($name, $error= "", $dbinfo= "")
151   {
152     if ($error != ""){
153       $error= "<br><br><i>"._("Error").":</i> ".$error;
154     }
155     if ($dbinfo != ""){
156       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
157     }
158     return (sprintf(_("Cannot connect to %s database!"), $name).$error);
159   }
162   public static function dbselect($name, $error= "", $dbinfo= "")
163   {
164     if ($error != ""){
165       $error= "<br><br><i>"._("Error").":</i> ".$error;
166     }
167     if ($dbinfo != ""){
168       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
169     }
170     return (sprintf(_("Cannot select %s database!"), $name).$error);
171   }
174   public static function noserver($name)
175   {
176     return (sprintf(_("No %s server defined!"), $name));
177   }
180   public static function dbquery($name, $error= "", $dbinfo= "")
181   {
182     if ($error != ""){
183       $error= "<br><br><i>"._("Error").":</i> ".$error;
184     }
185     if ($dbinfo != ""){
186       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
187     }
188     return (sprintf(_("Cannot query %s database!"), $name).$error);
189   }
192   public static function reserved($name)
193   {
194     return (sprintf(_("The field '%s' contains a reserved keyword!"), $name));
195   }
198   public static function cmdnotfound($type, $plugin)
199   {
200     return (sprintf(_("Command specified as %s hook for plugin '%s' does not exist!"), $type, $plugin));
201   }
204   public static function cmdinvalid($type, $command = "",$plugin="")
205   {
206     if(empty($command)){
207       return (sprintf(_("'%s' command is invalid!"), $type));
208     }elseif($command != "" && $plugin != ""){
209       return (sprintf(_("'%s' command (%s) for plugin %s is invalid!"), $type,$command,$plugin));
210     }elseif($plugin != "" && $command =""){
211       return (sprintf(_("'%s' command for plugin %s is invalid!"), $type,$plugin));
212     }else{
213       return (sprintf(_("'%s' command (%s) is invalid!"), $type,$command));
214     }
215   }
218   public static function cmdexecfailed($type, $command = "",$plugin="")
219   {
220     if(empty($command)){
221       return (sprintf(_("Cannot execute '%s' command!"), $type));
222     }elseif($command != "" && $plugin != ""){
223       return (sprintf(_("Cannot execute '%s' command (%s) for plugin %s!"), $type,$command,$plugin));
224     }elseif($plugin != "" && $command =""){
225       return (sprintf(_("Cannot execute '%s' command for plugin %s!"), $type,$plugin));
226     }else{
227       return (sprintf(_("Cannot execute '%s' command (%s)!"), $type,$command));
228     }
229   }
232   public static function toobig($name, $min= "")
233   {
234     if ($min == ""){
235       return (sprintf(_("Value for '%s' is too large!"), $name));
236     } else {
237       return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
238     }
239   }
242   public static function toosmall($name, $min= "")
243   {
244     if ($min == ""){
245       return (sprintf(_("Value for '%s' is too small!"), $name));
246     } else {
247       return (sprintf(_("'%s' must be %d or above!"), $name, $min));
248     }
249   }
252   public static function depends($name1, $name2)
253   {
254     return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
255   }
258   public static function duplicated($name)
259   {
260     return (sprintf(_("There is already an entry with this '%s' attribute in the system!"), $name));
261   }
264   public static function required($name)
265   {
266     return (sprintf(_("The required field '%s' is empty!"), $name));
267   }
270   public static function invalid($name, $data= "", $regex= "", $example= "")
271   {
272     /* Stylize example */
273     if ($example != ""){
274       $example= "<br><br><i>"._("Example").":</i> ".$example;
275     }
277     /* If validChars are posted, take data and paint all invalid
278        characters... */
279     if ($regex) {
280       $result= "";
281       $mismatch= "";
282       foreach (str_split($data) as $currentChar){
283         if (preg_match("$regex", $currentChar)){
284           $result.= $currentChar;
285         } else {
286           $result.= "<font style='color:red;text-decoration:underline;'>".htmlentities($currentChar)."</font>";
287           $mismatch.= $currentChar;
288         }
289       }
291       return sprintf(_("The Field '%s' contains invalid characters"), $name).". ".
292         (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed!"), htmlentities($mismatch))).
293         "<br><br> \"$result\"$example";
294     } else {
295       return sprintf(_("The Field '%s' contains invalid characters!"), $name)."!$example";
296     }
297   }
300   public static function missingext($name)
301   {
302     return sprintf(_("Missing %s PHP extension!"), $name);
303   }
306   public static function cancelButton()
307   {
308     return sprintf(_("Cancel"));
309   }
312   public static function okButton()
313   {
314     return sprintf(_("Ok"));
315   }
318   public static function applyButton()
319   {
320     return sprintf(_("Apply"));
321   }
324   public static function saveButton()
325   {
326     return sprintf(_("Save"));
327   }
330   public static function addButton($what= "")
331   {
332     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
333   }
336   public static function delButton($what= "")
337   {
338     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
339   }
342   public static function setButton($what= "")
343   {
344     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
345   }
348   public static function editButton($what= "")
349   {
350     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
351   }
354   public static function backButton($what= "")
355   {
356     return _("Back");
357   }
360   public static function buildList($data)
361   {
362     $objects= "<ul>";
363     foreach ($data as $key => $value){
364       if (is_numeric($key)){
365         $objects.= "<li>\n<i>$value</i></li>";
366       } else {
367         $objects.= "<li>\n$value (<i>$key</i>)</li>";
368       }
369     }
370     $objects.= "</ul>";
371     return($objects);
372   }
374   public static function noValidExtension($name)
375   {
376     return sprintf(_("This account has no valid %s extensions!"), $name);
377   }
379   public static function featuresEnabled($name, $depends= "")
380   {
381     if ($depends == ""){
382       return sprintf(_("This account has %s settings enabled. You can disable them by clicking below."), $name);
383     } else {
384       if (count($depends) == 1){
385         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $depends);
386       } else {
387         $deps= "";
388         foreach ($depends as $dep){
389           $deps.= "$dep / ";
390         }
391         $deps= preg_replace("/ \/ $/", "", $deps);
392         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $deps);
393       }
394     }
395   }
398   public static function featuresDisabled($name, $depends= "")
399   {
400     if ($depends == ""){
401       return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), $name);
402     } else {
403       if (count($depends) == 1){
404         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $depends);
405       } else {
406         $deps= "";
407         foreach ($depends as $dep){
408           $deps.= "$dep / ";
409         }
410         $deps= preg_replace("/ \/ $/", "", $deps);
411         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $deps);
412       }
413     }
414   }
417   public static function addFeaturesButton($name)
418   {
419     return sprintf(_("Add %s settings"), $name);
420   }
423   public static function removeFeaturesButton($name)
424   {
425     return sprintf(_("Remove %s settings"), $name);
426   }
429   public static function clickEditToChange()
430   {
431     return _("Click the 'Edit' button below to change informations in this dialog");
432   }
435   public static function months()
436   {
437     return array(_("January"), _("February"), _("March"), _("April"),
438         _("May"), _("June"), _("July"), _("August"), _("September"),
439         _("October"), _("November"), _("December"));
440   }
443   public static function weekdays()
444   {
445     return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
446   }
449   public static function ldaperror($error, $dn= "", $type= 0, $plugin= "")
450   {
451     /* Assign headline depending on type */
452     $typemap= array(1 => _("read operation"), _("add operation"), _("modify operation"),
453         _("delete operation"), _("search operation"), _("authentication"));
455     if (isset($typemap[$type])){
456       $headline= sprintf(_("LDAP %s failed!"), $typemap[$type]);
457     } else {
458       $headline= _("LDAP operation failed!");
459     }
461     /* Fill DN information */
462     if ($dn != ""){
463       $dn_info= "<br><br><i>"._("Object").":</i> ".LDAP::fix($dn);
464     }
466     return $headline.$dn_info."<br><br><i>"._("Error").":</i> ".$error;
467   }
470   public static function incorrectUpload($reason= "")
471   {
472     if ($reason == ""){
473       return _("Upload failed!");
474     }
476     return sprintf(_("Upload failed: %s"), "<br><br><i>$reason</i>");
477   }
480   public static function siError($error= "")
481   {
482     if ($error == ""){
483       return _("Communication failure with the infrastructure service!");
484     }
485     return sprintf(_("Communication failure with the infrastructure service: %s"), "<br><br>"._("Error").": ".$error);
486   }
489   public static function stillInUse($type, $objects= array())
490   {
491     if (!is_array($objects)){
492       return sprintf(_("This '%s' is still in use by this object: %s"), $type, "<br><br>".$objects);
493     }
494     if (count($objects) == 1){
495       return sprintf(_("This '%s' is still in use by this object: %s"), $type, "<br>".msgPool::buildList($objects));
496     }
497     if (count($objects) == 0){
498       return sprintf(_("This '%s' is still in use."), $type);
499     }
500     return sprintf(_("This '%s' is still in use by these objects: %s"), $type, "<br>".msgPool::buildList($objects));
501   }
504   public static function fileDoesNotExist($file)
505   {
506     return sprintf(_("File '%s' does not exist!"), $file);
507   }
510   public static function cannotReadFile($file)
511   {
512     return sprintf(_("Cannot open file '%s' for reading!"), $file);
513   }
516   public static function cannotWriteFile($file)
517   {
518     return sprintf(_("Cannot open file '%s' for writing!"), $file);
519   }
522   public static function invalidConfigurationAttribute($attr)
523   {
524     return sprintf(_("The value for '%s' is currently unconfigured or invalid, please check your configuration file!"), $attr);
525   }
528   public static function cannotDeleteFile($file)
529   {
530     return sprintf(_("Cannot delete file '%s'!"), $file);
531   }
534   public static function cannotCreateFolder($path)
535   {
536     return sprintf(_("Cannot create folder '%s'!"), $path);
537   }
540   public static function cannotDeleteFolder($path)
541   {
542     return sprintf(_("Cannot delete folder '%s'!"), $path);
543   }
546   public static function checkingFor($what)
547   {
548     return sprintf(_("Checking for %s support"), $what);
549   }
552   public static function installPhpModule($what)
553   {
554     return sprintf(_("Install and activate the %s PHP module."), $what);
555   }
558   public static function class_not_found($plugin)
559   {
560     return (sprintf(_("Cannot initialize class '%s'! Maybe there is a plugin missing in your gosa setup?"), $plugin));
561   }
563 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
564 ?>