Code

Updated msgpool
[gosa.git] / gosa-core / include / utils / class_msgPool.inc
1 <?php
3 class msgPool
4 {
5   public static function permDelete($name= "")
6   {
7     if ($name == "") { 
8       return (_("You have no permission to delete this object!"));
9     }
11     if (!is_array($name)){
12       return (_("You have no permission to delete the object:")."<br><br><i>$name</i>");
13     }
15     msgPool::buildList($name);
16     if (count($name) == 1){
17       return (_("You have no permission to delete the object:")."<br>".msgPool::buildList($name));
18     }
20     return (_("You have no permission to delete these objects:")."<br>".msgPool::buildList($name));
21   }
24   public static function permCreate($name= "")
25   {
26     if ($name == "") { 
27       return (_("You have no permission to create this object!"));
28     }
30     if (!is_array($name)){
31       return (_("You have no permission to create the object:")."<br><br><i>$name</i>");
32     }
34     if (count($name) == 1){
35       return (_("You have no permission to create the object:")."<br>".msgPool::buildList($name));
36     }
38     return (_("You have no permission to create these objects:")."<br>".msgPool::buildList($name));
39   }
42   public static function permModify($name= "")
43   {
44     if ($name == "") { 
45       return (_("You have no permission to modify this object!"));
46     }
48     if (!is_array($name)){
49       return (_("You have no permission to modify the object:")."<br><br><i>$name</i>");
50     }
52     if (count($name) == 1){
53       return (_("You have no permission to modify the object:")."<br>".msgPool::buildList($name));
54     }
56     return (_("You have no permission to modify these objects:")."<br>".msgPool::buildList($name));
57   }
60   public static function permView($name= "")
61   {
62     if ($name == "") { 
63       return (_("You have no permission to view this object!"));
64     }
66     if (!is_array($name)){
67       return (_("You have no permission to view the object:")."<br><br><i>$name</i>");
68     }
70     if (count($name) == 1){
71       return (_("You have no permission to view the object:")."<br>".msgPool::buildList($name));
72     }
74     return (_("You have no permission to view these objects:")."<br>".msgPool::buildList($name));
75   }
78   public static function permMove($name= "")
79   {
80     if ($name == "") { 
81       return (_("You have no permission to move this object!"));
82     }
84     if (!is_array($name)){
85       return (_("You have no permission to move the object:")."<br><br><i>$name</i>");
86     }
88     if (count($name) == 1){
89       return (_("You have no permission to move the object:")."<br>".msgPool::buildList($name));
90     }
92     return (_("You have no permission to move these objects:")."<br>".msgPool::buildList($name));
93   }
96   public static function dbconnect($name, $error= "", $dbinfo= "")
97   {
98     if ($error != ""){
99       $error= "<br><br><i>"._("Error").":</i> ".$error;
100     }
101     if ($dbinfo != ""){
102       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
103     }
104     return (sprintf(_("Cannot connect to %s database!"), $name).$error);
105   }
108   public static function dbselect($name, $error= "", $dbinfo= "")
109   {
110     if ($error != ""){
111       $error= "<br><br><i>"._("Error").":</i> ".$error;
112     }
113     if ($dbinfo != ""){
114       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
115     }
116     return (sprintf(_("Cannot select %s database!"), $name).$error);
117   }
120   public static function noserver($name)
121   {
122     return (sprintf(_("No %s server defined!"), $name));
123   }
126   public static function dbquery($name, $error= "", $dbinfo= "")
127   {
128     if ($error != ""){
129       $error= "<br><br><i>"._("Error").":</i> ".$error;
130     }
131     if ($dbinfo != ""){
132       $error.= "<br><br><i>"._("Connection information").":</i> ".$dbinfo;
133     }
134     return (sprintf(_("Cannot query %s database!"), $name).$error);
135   }
138   public static function reserved($name)
139   {
140     return (sprintf(_("The field '%s' contains a reserved keyword!"), $name));
141   }
144   public static function cmdnotfound($type, $plugin)
145   {
146     return (sprintf(_("Command specified as %s hook for plugin '%s' does not exist!"), $type, $plugin));
147   }
150   public static function toobig($name, $min= "")
151   {
152     if ($min == ""){
153       return (sprintf(_("Value for '%s' is too big!"), $name));
154     } else {
155       return (sprintf(_("'%s' must be smaller than %d!"), $name, $min));
156     }
157   }
160   public static function toosmall($name, $min= "")
161   {
162     if ($min == ""){
163       return (sprintf(_("Value for '%s' is too small!"), $name));
164     } else {
165       return (sprintf(_("'%s' must be %d or above!"), $name, $min));
166     }
167   }
170   public static function bigger($name1, $name2)
171   {
172     return (sprintf(_("'%s' should be bigger than '%s'!"), $name1, $name2));
173   }
176   public static function smaller($name1, $name2)
177   {
178     return (sprintf(_("'%s' should be smaller than '%s'!"), $name1, $name2));
179   }
182   public static function depends($name1, $name2)
183   {
184     return (sprintf(_("'%s' depends on '%s' - please provide both values!"), $name1, $name2));
185   }
188   public static function duplicated($name)
189   {
190     return (sprintf(_("There is already an entry with this '%s' attribute in the system!"), $name));
191   }
194   public static function required($name)
195   {
196     return (sprintf(_("The required field '%s' is empty!"), $name));
197   }
200   public static function invalid($name, $data= "", $regex= "", $example= "")
201   {
202     /* Stylize example */
203     if ($example != ""){
204       $example= "<br><br><i>"._("Example").":</i> ".$example;
205     }
207     /* If validChars are posted, take data and paint all invalid
208        characters... */
209     if ($regex) {
210       $result= "";
211       $mismatch= "";
212       foreach (str_split($data) as $currentChar){
213         if (preg_match("$regex", $currentChar)){
214           $result.= $currentChar;
215         } else {
216           $result.= "<font style='color:red;text-decoration:underline;'>".htmlentities($currentChar)."</font>";
217           $mismatch.= $currentChar;
218         }
219       }
221       return sprintf(_("The Field '%s' contains invalid characters"), $name).". ".
222              (strlen($mismatch)==1?sprintf(_("'%s' is not allowed:"), htmlentities($mismatch)):sprintf(_("'%s' are not allowed."), htmlentities($mismatch))).
223              "<br><br> \"$result\"$example";
224     } else {
225       return sprintf(_("The Field '%s' contains invalid characters"), $name)."!$example";
226     }
227   }
230   public static function missingext($name)
231   {
232     return sprintf(_("Missing %s PHP extension!"), $name);
233   }
236   public static function cancelButton()
237   {
238     return sprintf(_("Cancel"));
239   }
242   public static function okButton()
243   {
244     return sprintf(_("Ok"));
245   }
248   public static function applyButton()
249   {
250     return sprintf(_("Apply"));
251   }
254   public static function saveButton()
255   {
256     return sprintf(_("Save"));
257   }
260   public static function addButton($what= "")
261   {
262     return $what == "" ? sprintf(_("Add")): sprintf(_("Add %s"), $what);
263   }
266   public static function delButton($what= "")
267   {
268     return $what == "" ? sprintf(_("Delete")): sprintf(_("Delete %s"), $what);
269   }
272   public static function setButton($what= "")
273   {
274     return $what == "" ? sprintf(_("Set")): sprintf(_("Set %s"), $what);
275   }
278   public static function editButton($what= "")
279   {
280     return $what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what);
281   }
284   public static function buildList($data)
285   {
286     $objects= "";
287     foreach ($name as $key => $value){
288       if (is_numeric($key)){
289         $objects.= "<br>\n<i>$value</i>";
290       } else {
291         $objects.= "<br>\n$value (<i>$key</i>)";
292       }
293     }
294   }