Code

Added upload 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     if (count($name) == 1){
53       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
54     }
56     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
57   }
60   public static function permCreate($name= "")
61   {
62     if ($name == "") { 
63       return (_("You have no permission to create this object!"));
64     }
66     if (!is_array($name)){
67       return (_("You have no permission to create the object:")."<br><br><i>$name</i>");
68     }
70     if (count($name) == 1){
71       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
72     }
74     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
75   }
78   public static function permModify($name= "")
79   {
80     if ($name == "") { 
81       return (_("You have no permission to modify this object!"));
82     }
84     if (!is_array($name)){
85       return (_("You have no permission to modify the object:")."<br><br><i>$name</i>");
86     }
88     if (count($name) == 1){
89       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
90     }
92     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
93   }
96   public static function permView($name= "")
97   {
98     if ($name == "") { 
99       return (_("You have no permission to view this object!"));
100     }
102     if (!is_array($name)){
103       return (_("You have no permission to view the object:")."<br><br><i>$name</i>");
104     }
106     if (count($name) == 1){
107       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
108     }
110     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
111   }
114   public static function permMove($name= "")
115   {
116     if ($name == "") { 
117       return (_("You have no permission to move this object!"));
118     }
120     if (!is_array($name)){
121       return (_("You have no permission to move the object:")."<br><br><i>$name</i>");
122     }
124     if (count($name) == 1){
125       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
126     }
128     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
129   }
132   public static function dbconnect($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 connect to %s database!"), $name).$error);
141   }
144   public static function dbselect($name, $error= "", $dbinfo= "")
145   {
146     if ($error != ""){
147       $error= "<br><br><i>"._("Error").":</i> ".$error;
148     }
149     if ($dbinfo != ""){
150       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
151     }
152     return (sprintf(_("Cannot select %s database!"), $name).$error);
153   }
156   public static function noserver($name)
157   {
158     return (sprintf(_("No %s server defined!"), $name));
159   }
162   public static function dbquery($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 query %s database!"), $name).$error);
171   }
174   public static function reserved($name)
175   {
176     return (sprintf(_("The field '%s' contains a reserved keyword!"), $name));
177   }
180   public static function cmdnotfound($type, $plugin)
181   {
182     return (sprintf(_("Command specified as %s hook for plugin '%s' does not exist!"), $type, $plugin));
183   }
186   public static function toobig($name, $min= "")
187   {
188     if ($min == ""){
189       return (sprintf(_("Value for '%s' is too large!"), $name));
190     } else {
191       return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
192     }
193   }
196   public static function toosmall($name, $min= "")
197   {
198     if ($min == ""){
199       return (sprintf(_("Value for '%s' is too small!"), $name));
200     } else {
201       return (sprintf(_("'%s' must be %d or above!"), $name, $min));
202     }
203   }
206   public static function depends($name1, $name2)
207   {
208     return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
209   }
212   public static function duplicated($name)
213   {
214     return (sprintf(_("There is already an entry with this '%s' attribute in the system!"), $name));
215   }
218   public static function required($name)
219   {
220     return (sprintf(_("The required field '%s' is empty!"), $name));
221   }
224   public static function invalid($name, $data= "", $regex= "", $example= "")
225   {
226     /* Stylize example */
227     if ($example != ""){
228       $example= "<br><br><i>"._("Example").":</i> ".$example;
229     }
231     /* If validChars are posted, take data and paint all invalid
232        characters... */
233     if ($regex) {
234       $result= "";
235       $mismatch= "";
236       foreach (str_split($data) as $currentChar){
237         if (preg_match("$regex", $currentChar)){
238           $result.= $currentChar;
239         } else {
240           $result.= "<font style='color:red;text-decoration:underline;'>".htmlentities($currentChar)."</font>";
241           $mismatch.= $currentChar;
242         }
243       }
245       return sprintf(_("The Field '%s' contains invalid characters"), $name).". ".
246              (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed."), htmlentities($mismatch))).
247              "<br><br> \"$result\"$example";
248     } else {
249       return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example";
250     }
251   }
254   public static function missingext($name)
255   {
256     return sprintf(_("Missing %s PHP extension!"), $name);
257   }
260   public static function cancelButton()
261   {
262     return sprintf(_("Cancel"));
263   }
266   public static function okButton()
267   {
268     return sprintf(_("Ok"));
269   }
272   public static function applyButton()
273   {
274     return sprintf(_("Apply"));
275   }
278   public static function saveButton()
279   {
280     return sprintf(_("Save"));
281   }
284   public static function addButton($what= "")
285   {
286     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
287   }
290   public static function delButton($what= "")
291   {
292     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
293   }
296   public static function setButton($what= "")
297   {
298     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
299   }
302   public static function editButton($what= "")
303   {
304     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
305   }
308   public static function backButton($what= "")
309   {
310     return $what == "" ? sprintf(_("Back...")): sprintf(_("Back %s..."), $what);
311   }
314   public static function buildList($data)
315   {
316     $objects= "";
317     foreach ($data as $key => $value){
318       if (is_numeric($key)){
319         $objects.= "<br>\n<i>$value</i>";
320       } else {
321         $objects.= "<br>\n$value (<i>$key</i>)";
322       }
323     }
324   }
326   public static function noValidExtension($name)
327   {
328         return sprintf(_("This account has no valid %s extensions!"), $name);
329   }
331   public static function featuresEnabled($name, $depends= "")
332   {
333         if ($depends == ""){
334                 return sprintf(_("This account has %s settings enabled. You can disable them by clicking below."), $name);
335         } else {
336                 if (count($depends) == 1){
337                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $depends);
338                 } else {
339                         $deps= "";
340                         foreach ($depends as $dep){
341                                 $deps.= "$dep / ";
342                         }
343                         $deps= preg_replace("/ \/ $/", "", $deps);
344                         return sprintf(_("This account has %s settings enabled. To disable them, you'll need to remove the %s settings first!"), $name, $deps);
345                 }
346         }
347   }
350   public static function featuresDisabled($name, $depends= "")
351   {
352         if ($depends == ""){
353                 return sprintf(_("This account has %s settings disabled. You can enable them by clicking below."), $name);
354         } else {
355                 if (count($depends) == 1){
356                         return sprintf(_("This account has %s settings disabled. To enable them, you'll need to add the %s settings first!"), $name, $depends);
357                 } else {
358                         $deps= "";
359                         foreach ($depends as $dep){
360                                 $deps.= "$dep / ";
361                         }
362                         $deps= preg_replace("/ \/ $/", "", $deps);
363                         return sprintf(_("This account has %s features settings. To disable them, you'll need to add the %s settings first!"), $name, $deps);
364                 }
365         }
366   }
369   public static function addFeaturesButton($name)
370   {
371         return sprintf(_("Add %s settings"), $name);
372   }
375   public static function removeFeaturesButton($name)
376   {
377         return sprintf(_("Remove %s settings"), $name);
378   }
381   public static function clickEditToChange()
382   {
383         return _("Click the 'Edit' button below to change informations in this dialog");
384   }
387   public static function months()
388   {
389         return array(_("January"), _("February"), _("March"), _("April"),
390                         _("May"), _("June"), _("July"), _("August"), _("September"),
391                         _("October"), _("November"), _("December"));
392   }
395   public static function weekdays()
396   {
397         return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
398   }
401   public static function ldaperror($error, $dn= "", $type= 0, $plugin= "")
402   {
403         /* Assign headline depending on type */
404         $typemap= array(1 => _("read operation"), _("add operation"), _("modify operation"),
405                              _("delete operation"), _("search operation"), _("authentication"));
406         
407         if (isset($typemap[$type])){
408                 $headline= sprintf(_("LDAP %s failed!"), $typemap[$type]);
409         } else {
410                 $headline= _("LDAP operation failed!");
411         }
413         /* Fill DN information */
414         if ($dn != ""){
415                 $dn_info= "<br><br><i>"._("Object").":</i> ".LDAP::fix($dn);
416         }
418         return $headline.$dn_info."<br><br><i>"._("Error").":</i> ".$error;
419   }
422   function incorrectUpload($reason= "")
423   {
424         if ($reason == ""){
425                 return _("Upload failed!");
426         }
428         return sprintf(_("Upload failed: %s"), "<br><br><i>$reason</i>");
429   }
433 ?>