Code

Updated generateLdif method
[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 /*! \brief Some common needed messages */ 
10 class msgPool
11 {
13   public static function deleteInfo($name= "",$type = "")
14   {
15     if ($name == "") { 
16       if($type == ""){
17         return (_("This object will be deleted!"));
18       }else{
19         return (sprintf(_("This %s object will be deleted!"), bold($type)));
20       }
21     }
22     if (!is_array($name)){
23       if($type == ""){
24         return (sprintf(_("This object will be deleted: %s"), "<br><br>$name"));
25       }else{
26         return (sprintf(_("This %s object will be deleted: %s"), bold($type), "<br><br>$name"));
27       }
28     }
29     if (count($name) == 1){
30       if($type == ""){
31         return (_("This object will be deleted:")."<br>".msgPool::buildList($name));
32       }else{
33         return (sprintf(_("This %s object will be deleted:"), bold($type)). "<br>".msgPool::buildList($name));
34       }
35     }
36     if($type == ""){
37       return (sprintf(_("These objects will be deleted: %s"), "<br><br>".msgPool::buildList($name)));
38     }else{
39       return (sprintf(_("These %s objects will be deleted: %s"), bold($type), "<br>".msgPool::buildList($name)));
40     }
41   }
44   public static function permDelete($name= "")
45   {
46     if ($name == "") { 
47       return (_("You have no permission to delete this object!"));
48     }
50     if (!is_array($name)){
51       return (_("You have no permission to delete the object:")."<br><br>$name");
52     }
54     if (count($name) == 1){
55       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
56     }
58     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
59   }
62   public static function permCreate($name= "")
63   {
64     if ($name == "") { 
65       return (_("You have no permission to create this object!"));
66     }
68     if (!is_array($name)){
69       return (_("You have no permission to create the object:")."<br><br>$name");
70     }
72     if (count($name) == 1){
73       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
74     }
76     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
77   }
80   public static function permModify($name= "")
81   {
82     if ($name == "") { 
83       return (_("You have no permission to modify this object!"));
84     }
86     if (!is_array($name)){
87       return (_("You have no permission to modify the object:")."<br><br>$name");
88     }
90     if (count($name) == 1){
91       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
92     }
94     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
95   }
98   public static function permView($name= "")
99   {
100     if ($name == "") { 
101       return (_("You have no permission to view this object!"));
102     }
104     if (!is_array($name)){
105       return (_("You have no permission to view the object:")."<br><br>$name");
106     }
108     if (count($name) == 1){
109       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
110     }
112     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
113   }
116   public static function permMove($name= "")
117   {
118     if ($name == "") { 
119       return (_("You have no permission to move this object!"));
120     }
122     if (!is_array($name)){
123       return (_("You have no permission to move the object:")."<br><br>$name");
124     }
126     if (count($name) == 1){
127       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
128     }
130     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
131   }
134   public static function dbconnect($name, $error= "", $dbinfo= "")
135   {
136     if ($error != ""){
137       $error= "<br><br>"._("Error").": ".bold($error);
138     }
139     if ($dbinfo != ""){
140       $error.= "<br><br>"._("Connection information").": ".bold($dbinfo);
141     }
142     return (sprintf(_("Cannot connect to %s database!"), bold($name)).$error);
143   }
146   public static function dbselect($name, $error= "", $dbinfo= "")
147   {
148     if ($error != ""){
149       $error= "<br><br>"._("Error").": ".bold($error);
150     }
151     if ($dbinfo != ""){
152       $error.= "<br><br>"._("Connection information").": ".bold($dbinfo);
153     }
154     return (sprintf(_("Cannot select %s database!"), bold($name)).$error);
155   }
158   public static function noserver($name)
159   {
160     return (sprintf(_("No %s server defined!"), bold($name)));
161   }
164   public static function dbquery($name, $error= "", $dbinfo= "")
165   {
166     if ($error != ""){
167       $error= "<br><br>"._("Error").": ".bold($error);
168     }
169     if ($dbinfo != ""){
170       $error.= "<br><br>"._("Connection information").": ".bold($dbinfo);
171     }
172     return (sprintf(_("Cannot query %s database!"), bold($name)).$error);
173   }
176   public static function reserved($name)
177   {
178     return (sprintf(_("The field %s contains a reserved keyword!"), bold($name)));
179   }
182   public static function cmdnotfound($type, $plugin)
183   {
184     return (sprintf(_("Command specified as %s hook for plugin %s does not exist!"), bold($type), bold($plugin)));
185   }
188   public static function cmdinvalid($type, $command = "",$plugin="")
189   {
190     if(empty($command)){
191       return (sprintf(_("%s command is invalid!"), bold($type)));
192     }elseif($command != "" && $plugin != ""){
193       return (sprintf(_("%s command (%s) for plugin %s is invalid!"), bold($type), bold($command) ,bold($plugin)));
194     }elseif($plugin != "" && $command =""){
195       return (sprintf(_("%s command for plugin %s is invalid!"), bold($type), bold($plugin)));
196     }else{
197       return (sprintf(_("%s command (%s) is invalid!"), bold($type), bold($command)));
198     }
199   }
202   public static function cmdexecfailed($type, $command = "",$plugin="")
203   {
204     if(empty($command)){
205       return (sprintf(_("Cannot execute %s command!"), bold($type)));
206     }elseif($command != "" && $plugin != ""){
207       return (sprintf(_("Cannot execute %s command (%s) for plugin %s!"), bold($type), bold($command), bold($plugin)));
208     }elseif($plugin != "" && $command =""){
209       return (sprintf(_("Cannot execute %s command for plugin %s!"), bold($type), bold($plugin)));
210     }else{
211       return (sprintf(_("Cannot execute %s command (%s)!"), bold($type), bold($command)));
212     }
213   }
216   public static function toobig($name, $min= "")
217   {
218     if ($min == ""){
219       return (sprintf(_("Value for %s is too large!"), bold($name)));
220     } else {
221       return (sprintf(_("%s must be smaller than %s!"), bold($name), bold($min)));
222     }
223   }
226   public static function toosmall($name, $min= "")
227   {
228     if ($min == ""){
229       return (sprintf(_("Value for %s is too small!"), bold($name)));
230     } else {
231       return (sprintf(_("%s must be %s or above!"), bold($name), bold($min)));
232     }
233   }
236   public static function depends($name1, $name2)
237   {
238     return (sprintf(_("%s depends on %s - please provide both values!"), bold($name1), bold($name2)));
239   }
242   public static function duplicated($name)
243   {
244     return (sprintf(_("There is already an entry with this %s attribute in the system!"), bold($name)));
245   }
248   public static function required($name)
249   {
250     return (sprintf(_("The required field %s is empty!"), bold($name)));
251   }
254   public static function invalid($name, $data= "", $regex= "", $example= "")
255   {
256     /* Stylize example */
257     if ($example != ""){
258       $example= "<br><br>"._("Example").": ".bold($example);
259     }
261     /* If validChars are posted, take data and paint all invalid
262        characters... */
263     if ($regex) {
264       $result= "";
265       $mismatch= "";
267       mb_internal_encoding('UTF-8');
268       for($i=0; $i<=mb_strlen($data);$i++){
269         $currentChar= mb_substr($data, $i,1);
270         if (preg_match("$regex", $currentChar)){
271           $result.= $currentChar;
272         } else {
273           $result.= "<font style='color:red;text-decoration:underline;'>".($currentChar)."</font>";
274           $mismatch.= $currentChar;
275         }
276       }
278       return sprintf(_("The Field %s contains invalid characters"), bold($name)).". ".
279         (strlen($mismatch)==1?sprintf(_("%s is not allowed:"), bold($mismatch)):sprintf(_("%s are not allowed!"), bold($mismatch))).
280         "<br><br> \"$result\"$example";
281     } else {
282       return sprintf(_("The Field %s contains invalid characters!"), bold($name))."!$example";
283     }
284   }
287   public static function missingext($name)
288   {
289     return sprintf(_("Missing %s PHP extension!"), bold($name));
290   }
293   public static function cancelButton()
294   {
295     return sprintf(_("Cancel"));
296   }
299   public static function okButton()
300   {
301     return sprintf(_("OK"));
302   }
305   public static function applyButton()
306   {
307     return sprintf(_("Apply"));
308   }
311   public static function saveButton()
312   {
313     return sprintf(_("Save"));
314   }
317   public static function addButton($what= "")
318   {
319     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
320   }
323   public static function delButton($what= "")
324   {
325     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
326   }
329   public static function setButton($what= "")
330   {
331     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
332   }
335   public static function editButton($what= "")
336   {
337     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
338   }
341   public static function backButton($what= "")
342   {
343     return _("Back");
344   }
347   public static function buildList($data)
348   {
349     $objects= "<ul class='object-list'>";
350     foreach ($data as $key => $value){
351       if (is_numeric($key)){
352         $objects.= "<li>\n$value</li>";
353       } else {
354         $objects.= "<li>\n$value <span>$key</span></li>";
355       }
356     }
357     $objects.= "</ul>";
358     return($objects);
359   }
361   public static function noValidExtension($name)
362   {
363     return sprintf(_("This account has no valid %s extensions!"), bold($name));
364   }
366   public static function featuresEnabled($name, $depends= "")
367   {
368     if ($depends == ""){
369       return sprintf(_("This account has %s settings enabled. You can disable them by clicking below."), bold($name));
370     } else {
371       if (count($depends) == 1){
372         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), bold($name), bold($depends));
373       } else {
374         $deps= "";
375         foreach ($depends as $dep){
376           $deps.= "$dep / ";
377         }
378         $deps= preg_replace("/ \/ $/", "", $deps);
379         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), bold($name), bold($deps));
380       }
381     }
382   }
385   public static function featuresDisabled($name, $depends= "")
386   {
387     if ($depends == ""){
388       return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), bold($name));
389     } else {
390       if (count($depends) == 1){
391         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), bold($name), bold($depends));
392       } else {
393         $deps= "";
394         foreach ($depends as $dep){
395           $deps.= "$dep / ";
396         }
397         $deps= preg_replace("/ \/ $/", "", $deps);
398         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), bold($name), bold($deps));
399       }
400     }
401   }
404   public static function addFeaturesButton($name)
405   {
406     return sprintf(_("Add %s settings"), $name);
407   }
410   public static function removeFeaturesButton($name)
411   {
412     return sprintf(_("Remove %s settings"), $name);
413   }
416   public static function clickEditToChange()
417   {
418     return _("Click the 'Edit' button below to change informations in this dialog");
419   }
422   public static function months()
423   {
424     return array(_("January"), _("February"), _("March"), _("April"),
425         _("May"), _("June"), _("July"), _("August"), _("September"),
426         _("October"), _("November"), _("December"));
427   }
430   public static function weekdays()
431   {
432     return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
433   }
436   public static function mysqlerror($error,  $plugin= "")
437   {
438     /* Assign headline depending on type */
439     $headline= _("MySQL operation failed!");
440     return $headline."<br><br>"._("Error").": ".bold($error);
441   }
444   public static function ldaperror($error, $dn= "", $type= 0, $plugin= "")
445   {
446     /* Assign headline depending on type */
447     $typemap= array(1 => _("read operation"), _("add operation"), _("modify operation"),
448         _("delete operation"), _("search operation"), _("authentication"));
450     if (isset($typemap[$type])){
451       $headline= sprintf(_("LDAP %s failed!"), bold($typemap[$type]));
452     } else {
453       $headline= _("LDAP operation failed!");
454     }
456     /* Fill DN information */
457     if ($dn != ""){
458       $dn_info= "<br><br>"._("Object").": ".bold(LDAP::fix($dn));
459     }
461     return $headline.$dn_info."<br><br>"._("Error").": ".bold($error);
462   }
465   public static function incorrectUpload($reason= "")
466   {
467     if ($reason == ""){
468       return _("Upload failed!");
469     }
471     return sprintf(_("Upload failed: %s"), "<br><br>".bold($reason));
472   }
475   public static function siError($error= "")
476   {
477     if ($error == ""){
478       return _("Communication failure with the infrastructure service!");
479     }
480     return sprintf(_("Communication failure with the infrastructure service: %s"), "<br><br>".$error);
481   }
484   public static function rpcError($error= "")
485   {
486     if ($error == ""){
487       return _("Communication failure with the GOSA-NG service!");
488     }
489     return sprintf(_("Communication failure with the GOSA-NG service: %s"), "<br><br>".$error);
490   }
493   public static function stillInUse($type, $objects= array())
494   {
495     if (!is_array($objects)){
496       return sprintf(_("This %s is still in use by this object: %s"), bold($type), "<br><br>".$objects);
497     }
498     if (count($objects) == 1){
499       return sprintf(_("This %s is still in use by this object: %s"), bold($type), "<br>".msgPool::buildList($objects));
500     }
501     if (count($objects) == 0){
502       return sprintf(_("This %s is still in use."), bold($type));
503     }
504     return sprintf(_("This %s is still in use by these objects: %s"), bold($type), "<br>".msgPool::buildList($objects));
505   }
508   public static function fileDoesNotExist($file)
509   {
510     return sprintf(_("File %s does not exist!"), bold($file));
511   }
514   public static function cannotReadFile($file)
515   {
516     return sprintf(_("Cannot open file %s for reading!"), bold($file));
517   }
520   public static function cannotWriteFile($file)
521   {
522     return sprintf(_("Cannot open file %s for writing!"), bold($file));
523   }
526   public static function invalidConfigurationAttribute($attr)
527   {
528     return sprintf(_("The value for %s is currently unconfigured or invalid, please check your configuration file!"), bold($attr));
529   }
532   public static function cannotDeleteFile($file)
533   {
534     return sprintf(_("Cannot delete file %s!"), bold($file));
535   }
538   public static function cannotCreateFolder($path)
539   {
540     return sprintf(_("Cannot create folder %s!"), bold($path));
541   }
544   public static function cannotDeleteFolder($path)
545   {
546     return sprintf(_("Cannot delete folder %s!"), bold($path));
547   }
550   public static function checkingFor($what)
551   {
552     return sprintf(_("Checking for %s support"), bold($what));
553   }
556   public static function installPhpModule($what)
557   {
558     return sprintf(_("Install and activate the %s PHP module."), bold($what));
559   }
562   public static function class_not_found($plugin)
563   {
564     return (sprintf(_("Cannot initialize class %s! Maybe there is a plugin missing in your gosa setup?"), bold($plugin)));
565   }
568   public static function check_base()
569   {
570     return _("The supplied base is not valid and has been reset to its previous value!");
571   }
574 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
575 ?>