1 | <?php |
---|
2 | /**************************************************************************\ |
---|
3 | * eGroupWare API - Commononly used functions * |
---|
4 | * This file written by Dan Kuykendall <seek3r@phpgroupware.org> * |
---|
5 | * and Joseph Engo <jengo@phpgroupware.org> * |
---|
6 | * and Mark Peters <skeeter@phpgroupware.org> * |
---|
7 | * and Lars Kneschke <lkneschke@linux-at-work.de> * |
---|
8 | * Functions commonly used by eGroupWare developers * |
---|
9 | * Copyright (C) 2000, 2001 Dan Kuykendall * |
---|
10 | * Copyright (C) 2003 Lars Kneschke * |
---|
11 | * -------------------------------------------------------------------------* |
---|
12 | * This library is part of the eGroupWare API * |
---|
13 | * http://www.egroupware.org * |
---|
14 | * ------------------------------------------------------------------------ * |
---|
15 | * This library is free software; you can redistribute it and/or modify it * |
---|
16 | * under the terms of the GNU Lesser General Public License as published by * |
---|
17 | * the Free Software Foundation; either version 2.1 of the License, * |
---|
18 | * or any later version. * |
---|
19 | * This library is distributed in the hope that it will be useful, but * |
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
---|
22 | * See the GNU Lesser General Public License for more details. * |
---|
23 | * You should have received a copy of the GNU Lesser General Public License * |
---|
24 | * along with this library; if not, write to the Free Software Foundation, * |
---|
25 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
---|
26 | \**************************************************************************/ |
---|
27 | |
---|
28 | |
---|
29 | $d1 = strtolower(@substr(PHPGW_API_INC,0,3)); |
---|
30 | $d2 = strtolower(@substr(PHPGW_SERVER_ROOT,0,3)); |
---|
31 | $d3 = strtolower(@substr(PHPGW_APP_INC,0,3)); |
---|
32 | if($d1 == 'htt' || $d1 == 'ftp' || $d2 == 'htt' || $d2 == 'ftp' || $d3 == 'htt' || $d3 == 'ftp') |
---|
33 | { |
---|
34 | echo 'Failed attempt to break in via an old Security Hole!<br>'."\n"; |
---|
35 | exit; |
---|
36 | } |
---|
37 | unset($d1);unset($d2);unset($d3); |
---|
38 | |
---|
39 | /*! |
---|
40 | @class common |
---|
41 | @abstract common class that contains commonly used functions |
---|
42 | */ |
---|
43 | class common |
---|
44 | { |
---|
45 | var $debug_info; // An array with debugging info from the API |
---|
46 | var $found_files; |
---|
47 | |
---|
48 | /*! |
---|
49 | @function cmp_version |
---|
50 | @abstract Compares two Version strings and return 1 if str2 is newest (bigger version number) than str1 |
---|
51 | @discussion This function checks for major version only. |
---|
52 | @param $str1 |
---|
53 | @param $str2 |
---|
54 | */ |
---|
55 | function cmp_version($str1,$str2,$debug=False) |
---|
56 | { |
---|
57 | ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)",$str1,$regs); |
---|
58 | ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)",$str2,$regs2); |
---|
59 | if($debug) { echo "<br>$regs[0] - $regs2[0]"; } |
---|
60 | |
---|
61 | for($i=1;$i<5;$i++) |
---|
62 | { |
---|
63 | if($debug) { echo "<br>$i: $regs[$i] - $regs2[$i]"; } |
---|
64 | if($regs2[$i] == $regs[$i]) |
---|
65 | { |
---|
66 | continue; |
---|
67 | } |
---|
68 | if($regs2[$i] > $regs[$i]) |
---|
69 | { |
---|
70 | return 1; |
---|
71 | } |
---|
72 | elseif($regs2[$i] < $regs[$i]) |
---|
73 | { |
---|
74 | return 0; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | /*! |
---|
80 | @function cmp_version_long |
---|
81 | @abstract Compares two Version strings and return 1 if str2 is newest (bigger version number) than str1 |
---|
82 | @discussion This function checks all fields. cmp_version() checks release version only. |
---|
83 | @param $str1 |
---|
84 | @param $str2 |
---|
85 | */ |
---|
86 | function cmp_version_long($str1,$str2,$debug=False) |
---|
87 | { |
---|
88 | ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)\.([0-9]*)",$str1,$regs); |
---|
89 | ereg("([0-9]+)\.([0-9]+)\.([0-9]+)[a-zA-Z]*([0-9]*)\.([0-9]*)",$str2,$regs2); |
---|
90 | if($debug) { echo "<br>$regs[0] - $regs2[0]"; } |
---|
91 | |
---|
92 | for($i=1;$i<6;$i++) |
---|
93 | { |
---|
94 | if($debug) { echo "<br>$i: $regs[$i] - $regs2[$i]"; } |
---|
95 | |
---|
96 | if($regs2[$i] == $regs[$i]) |
---|
97 | { |
---|
98 | if($debug) { echo ' are equal...'; } |
---|
99 | continue; |
---|
100 | } |
---|
101 | if($regs2[$i] > $regs[$i]) |
---|
102 | { |
---|
103 | if($debug) { echo ', and a > b'; } |
---|
104 | return 1; |
---|
105 | } |
---|
106 | elseif($regs2[$i] < $regs[$i]) |
---|
107 | { |
---|
108 | if($debug) { echo ', and a < b'; } |
---|
109 | return 0; |
---|
110 | } |
---|
111 | } |
---|
112 | if($debug) { echo ' - all equal.'; } |
---|
113 | } |
---|
114 | |
---|
115 | // Convert an array into the format needed for the access column. |
---|
116 | /*! |
---|
117 | @function array_to_string |
---|
118 | @abstract Convert an array into the format needed for the access column |
---|
119 | @param $access |
---|
120 | @param $array |
---|
121 | */ |
---|
122 | function array_to_string($access,$array) |
---|
123 | { |
---|
124 | $this->debug_info[] = 'array_to_string() is a depreciated function - use ACL instead'; |
---|
125 | $s = ''; |
---|
126 | if ($access == 'group' || $access == 'public' || $access == 'none') |
---|
127 | { |
---|
128 | if (count($array)) |
---|
129 | { |
---|
130 | while ($t = each($array)) |
---|
131 | { |
---|
132 | $s .= ',' . $t[1]; |
---|
133 | } |
---|
134 | $s .= ','; |
---|
135 | } |
---|
136 | if (! count($array) && $access == 'none') |
---|
137 | { |
---|
138 | $s = ''; |
---|
139 | } |
---|
140 | } |
---|
141 | return $s; |
---|
142 | } |
---|
143 | |
---|
144 | // This is used for searching the access fields |
---|
145 | /*! |
---|
146 | @function sql_search |
---|
147 | @abstract this function is used for searching the access fields |
---|
148 | @param $table |
---|
149 | @param $owner |
---|
150 | */ |
---|
151 | function sql_search($table,$owner=0) |
---|
152 | { |
---|
153 | $this->debug_info[] = 'sql_search() is a deprecated function - use ACL instead'; |
---|
154 | $s = ''; |
---|
155 | if (!$owner) |
---|
156 | { |
---|
157 | $owner = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
158 | } |
---|
159 | $groups = $GLOBALS['phpgw']->accounts->membership((int)$owner); |
---|
160 | if(@is_array($groups)) |
---|
161 | { |
---|
162 | while ($group = each($groups)) |
---|
163 | { |
---|
164 | $s .= " OR $table LIKE '%," . $group[2] . ",%'"; |
---|
165 | } |
---|
166 | } |
---|
167 | return $s; |
---|
168 | } |
---|
169 | |
---|
170 | // return a array of installed languages |
---|
171 | /*! |
---|
172 | @function getInstalledLanguages |
---|
173 | @abstract return an array of installed languages |
---|
174 | @result $installedLanguages; an array containing the installed languages |
---|
175 | */ |
---|
176 | function getInstalledLanguages() |
---|
177 | { |
---|
178 | $GLOBALS['phpgw']->db->query('SELECT DISTINCT lang FROM phpgw_lang'); |
---|
179 | while (@$GLOBALS['phpgw']->db->next_record()) |
---|
180 | { |
---|
181 | $installedLanguages[$GLOBALS['phpgw']->db->f('lang')] = $GLOBALS['phpgw']->db->f('lang'); |
---|
182 | } |
---|
183 | |
---|
184 | return $installedLanguages; |
---|
185 | } |
---|
186 | |
---|
187 | // return the preferred language of the users |
---|
188 | // it's using HTTP_ACCEPT_LANGUAGE (send from the users browser) |
---|
189 | // and ...(to find out which languages are installed) |
---|
190 | /*! |
---|
191 | @function getPreferredLanguage |
---|
192 | @abstract return the preferred langugae of the users |
---|
193 | @discussion it uses HTTP_ACCEPT_LANGUAGE (from the users browser) <br> |
---|
194 | and .... to find out which languages are installed |
---|
195 | */ |
---|
196 | function getPreferredLanguage() |
---|
197 | { |
---|
198 | // create a array of languages the user is accepting |
---|
199 | $userLanguages = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); |
---|
200 | $supportedLanguages = $this->getInstalledLanguages(); |
---|
201 | |
---|
202 | // find usersupported language |
---|
203 | // while (list($key,$value) = each($userLanguages)) |
---|
204 | foreach($userLanguages as $key => $value) |
---|
205 | { |
---|
206 | // remove everything behind '-' example: de-de |
---|
207 | $value = trim($value); |
---|
208 | $pieces = explode('-', $value); |
---|
209 | $value = $pieces[0]; |
---|
210 | # print 'current lang $value<br>'; |
---|
211 | if ($supportedLanguages[$value]) |
---|
212 | { |
---|
213 | $retValue=$value; |
---|
214 | break; |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | // no usersupported language found -> return english |
---|
219 | if (empty($retValue)) |
---|
220 | { |
---|
221 | $retValue='en'; |
---|
222 | } |
---|
223 | |
---|
224 | return $retValue; |
---|
225 | } |
---|
226 | |
---|
227 | /*! |
---|
228 | @function ldap_addslashes |
---|
229 | @abstract escapes a string for use in searchfilters meant for ldap_search. |
---|
230 | Escaped Characters are: '*', '(', ')', ' ', '\', NUL |
---|
231 | It's actually a PHP-Bug, that we have to escape space. |
---|
232 | For all other Characters, refer to RFC2254. |
---|
233 | @param $string string to be escaped |
---|
234 | */ |
---|
235 | function ldap_addslashes($string='') |
---|
236 | { |
---|
237 | return str_replace(array('\\','*','(',')','\0',' '),array('\\\\','\*','\(','\)','\\0','\20'),$string); |
---|
238 | } |
---|
239 | |
---|
240 | // connect to the ldap server and return a handle |
---|
241 | /*! |
---|
242 | @function ldapConnect |
---|
243 | @abstract connect to the ldap server and return a handle |
---|
244 | @param $host ldap host |
---|
245 | @param $dn ldap_root_dn |
---|
246 | @param $passwd ldap_root_pw |
---|
247 | */ |
---|
248 | function ldapConnect($host='', $dn='', $passwd='', $ldapreferral=false) |
---|
249 | { |
---|
250 | if(!$host || $host == $GLOBALS['phpgw_info']['server']['ldap_host'] && !$dn ) { |
---|
251 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
252 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
253 | $host = $GLOBALS['phpgw_info']['server']['ldap_host']; |
---|
254 | } |
---|
255 | else if(strstr($host, "ldap://")){ |
---|
256 | $dn = ''; |
---|
257 | $passwd = ''; |
---|
258 | } |
---|
259 | |
---|
260 | if(!function_exists('ldap_connect')) |
---|
261 | { |
---|
262 | /* log does not exist in setup(, yet) */ |
---|
263 | if(is_object($GLOBALS['phpgw']->log)) |
---|
264 | { |
---|
265 | $GLOBALS['phpgw']->log->message('F-Abort, LDAP support unavailable'); |
---|
266 | $GLOBALS['phpgw']->log->commit(); |
---|
267 | } |
---|
268 | |
---|
269 | printf('<b>Error: LDAP support unavailable</b><br>',$host); |
---|
270 | return False; |
---|
271 | } |
---|
272 | |
---|
273 | // connect to ldap server |
---|
274 | if(!$ds = ldap_connect($host)) |
---|
275 | { |
---|
276 | /* log does not exist in setup(, yet) */ |
---|
277 | if(is_object($GLOBALS['phpgw']->log)) |
---|
278 | { |
---|
279 | $GLOBALS['phpgw']->log->message('F-Abort, Failed connecting to LDAP server'); |
---|
280 | $GLOBALS['phpgw']->log->commit(); |
---|
281 | } |
---|
282 | |
---|
283 | printf("<b>Error: Can't connect to LDAP server %s!</b><br>",$host); |
---|
284 | return False; |
---|
285 | } |
---|
286 | |
---|
287 | if($GLOBALS['phpgw_info']['server']['ldap_version3']) |
---|
288 | { |
---|
289 | if(!ldap_set_option($ds,LDAP_OPT_PROTOCOL_VERSION,3)) |
---|
290 | { |
---|
291 | $GLOBALS['phpgw_info']['server']['ldap_version3'] = False; |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | ldap_set_option($ds, LDAP_OPT_REFERRALS, $ldapreferral); |
---|
296 | //Para realizar o rebind em caso de referrals |
---|
297 | if($GLOBALS['phpgw_info']['server']['diretorioescravo']) |
---|
298 | { |
---|
299 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
300 | ldap_set_rebind_proc($ds, array($this, 'rebindProc')); |
---|
301 | } |
---|
302 | if($dn && $passwd && ! ldap_bind($ds,$dn,$passwd)) |
---|
303 | { |
---|
304 | if(is_object($GLOBALS['phpgw']->log)) |
---|
305 | { |
---|
306 | $GLOBALS['phpgw']->log->message('F-Abort, Failed binding to LDAP server'); |
---|
307 | $GLOBALS['phpgw']->log->commit(); |
---|
308 | } |
---|
309 | if(!$GLOBALS['phpgw_info']['server']['diretorioescravo']) |
---|
310 | { |
---|
311 | //Para nao colocar a tela de erro em caso de negacao de login por expiracao de senha |
---|
312 | printf("<b>Error: Can't bind to LDAP server: %s!</b><br>",$dn); |
---|
313 | } |
---|
314 | return False; |
---|
315 | } |
---|
316 | // bind as anonymous |
---|
317 | if(!$dn && !$passwd && ! ldap_bind($ds)) |
---|
318 | { |
---|
319 | if(is_object($GLOBALS['phpgw']->log)) |
---|
320 | { |
---|
321 | $GLOBALS['phpgw']->log->message('F-Abort, Failed (anonymous bind) to LDAP server'); |
---|
322 | $GLOBALS['phpgw']->log->commit(); |
---|
323 | } |
---|
324 | printf("<b>Error: Can't bind to LDAP server (anonymous bind): %s!</b><br>",$dn); |
---|
325 | return False; |
---|
326 | } |
---|
327 | return $ds; |
---|
328 | } |
---|
329 | //Usada para fazer rebind em caso de escrita em slave (quando volta uma referral) |
---|
330 | function rebindProc($conn, $who) |
---|
331 | { |
---|
332 | /* Strip out the hostname we're being redirected to. */ |
---|
333 | $who = preg_replace(array('|^.*://|', '|:\d*$|'), '', $who); |
---|
334 | //system('echo "REBIND DO COMMON" >> /tmp/controle'); |
---|
335 | $bind = ldap_bind($conn,$GLOBALS['phpgw_info']['server']['ldap_root_dn'],$GLOBALS['phpgw_info']['server']['ldap_root_pw']); |
---|
336 | return 0; |
---|
337 | } |
---|
338 | // This function is used if the developer wants to stop a running app in the middle of execution |
---|
339 | // We may need to do some clean up before hand |
---|
340 | /*! |
---|
341 | @function phpgw_exit |
---|
342 | @abstract function to stop running an app |
---|
343 | @discussion used to stop running an app in the middle of execution <br> |
---|
344 | There may need to be some cleanup before hand |
---|
345 | @param $call_footer boolean value to if true then call footer else exit |
---|
346 | */ |
---|
347 | function phpgw_exit($call_footer = False) |
---|
348 | { |
---|
349 | if (!defined('PHPGW_EXIT')) |
---|
350 | { |
---|
351 | define('PHPGW_EXIT',True); |
---|
352 | |
---|
353 | if ($call_footer) |
---|
354 | { |
---|
355 | $this->phpgw_footer(); |
---|
356 | } |
---|
357 | } |
---|
358 | exit; |
---|
359 | } |
---|
360 | |
---|
361 | function phpgw_final() |
---|
362 | { |
---|
363 | if (!defined('PHPGW_FINAL')) |
---|
364 | { |
---|
365 | define('PHPGW_FINAL',True); |
---|
366 | |
---|
367 | /*if (is_object($GLOBALS['phpgw']->accounts)) |
---|
368 | { |
---|
369 | $GLOBALS['phpgw']->accounts->save_session_cache(); |
---|
370 | }*/ |
---|
371 | // call the asyncservice check_run function if it is not explicitly set to cron-only |
---|
372 | // |
---|
373 | if (!$GLOBALS['phpgw_info']['server']['asyncservice']) // is default |
---|
374 | { |
---|
375 | ExecMethod('phpgwapi.asyncservice.check_run','fallback'); |
---|
376 | } |
---|
377 | /* Clean up mcrypt */ |
---|
378 | if (@is_object($GLOBALS['phpgw']->crypto)) |
---|
379 | { |
---|
380 | $GLOBALS['phpgw']->crypto->cleanup(); |
---|
381 | unset($GLOBALS['phpgw']->crypto); |
---|
382 | } |
---|
383 | $GLOBALS['phpgw']->db->disconnect(); |
---|
384 | } |
---|
385 | } |
---|
386 | |
---|
387 | /*! |
---|
388 | @function randomstring |
---|
389 | @abstract return a random string of size $size |
---|
390 | @param $size int-size of random string to return |
---|
391 | */ |
---|
392 | function randomstring($size) |
---|
393 | { |
---|
394 | $s = ''; |
---|
395 | srand((double)microtime()*1000000); |
---|
396 | $random_char = array( |
---|
397 | '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', |
---|
398 | 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', |
---|
399 | 'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L', |
---|
400 | 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' |
---|
401 | ); |
---|
402 | |
---|
403 | for ($i=0; $i<$size; $i++) |
---|
404 | { |
---|
405 | $s .= $random_char[rand(1,61)]; |
---|
406 | } |
---|
407 | return $s; |
---|
408 | } |
---|
409 | |
---|
410 | // Look at the note towards the top of this file (jengo) |
---|
411 | function filesystem_separator() |
---|
412 | { |
---|
413 | return filesystem_separator(); |
---|
414 | } |
---|
415 | |
---|
416 | /*! |
---|
417 | @function error_list |
---|
418 | @abstract This is used for reporting errors in a nice format. |
---|
419 | @param $error - array of errors |
---|
420 | */ |
---|
421 | function error_list($errors,$text='Error') |
---|
422 | { |
---|
423 | if (! is_array($errors)) |
---|
424 | { |
---|
425 | return False; |
---|
426 | } |
---|
427 | |
---|
428 | $html_error = '<table border="0" width="100%"><tr><td align="right"><b>' . lang($text) |
---|
429 | . '</b>: </td><td align="left">' . $errors[0] . '</td></tr>'; |
---|
430 | for ($i=1; $i<count($errors); $i++) |
---|
431 | { |
---|
432 | $html_error .= '<tr><td> </td><td align="left">' . $errors[$i] . '</td></tr>'; |
---|
433 | } |
---|
434 | return $html_error . '</table>'; |
---|
435 | } |
---|
436 | |
---|
437 | /*! |
---|
438 | @function check_owner |
---|
439 | @abstract none yet |
---|
440 | @param $record ? |
---|
441 | @param $link ? |
---|
442 | @param $label ? |
---|
443 | @param $extravars |
---|
444 | */ |
---|
445 | // This is a depreciated function - use ACL instead (jengo) |
---|
446 | function check_owner($record,$link,$label,$extravars = '') |
---|
447 | { |
---|
448 | $this->debug_info[] = 'check_owner() is a depreciated function - use ACL instead'; |
---|
449 | /* |
---|
450 | $s = '<a href="' . $GLOBALS['phpgw']->link($link,$extravars) . '"> ' . lang($label) . ' </a>'; |
---|
451 | if (ereg('^[0-9]+$',$record)) |
---|
452 | { |
---|
453 | if ($record != $GLOBALS['phpgw_info']['user']['account_id']) |
---|
454 | { |
---|
455 | $s = ' '; |
---|
456 | } |
---|
457 | } |
---|
458 | else |
---|
459 | { |
---|
460 | if ($record != $GLOBALS['phpgw_info']['user']['userid']) |
---|
461 | { |
---|
462 | $s = ' '; |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | return $s; |
---|
467 | */ |
---|
468 | } |
---|
469 | |
---|
470 | /*! |
---|
471 | @function display_fullname |
---|
472 | @abstract return the fullname of a user |
---|
473 | @param $lid account loginid |
---|
474 | @param $firstname firstname |
---|
475 | @param $lastname lastname |
---|
476 | */ |
---|
477 | function display_fullname($lid = '', $firstname = '', $lastname = '') |
---|
478 | { |
---|
479 | if (! $lid && ! $firstname && ! $lastname) |
---|
480 | { |
---|
481 | $lid = $GLOBALS['phpgw_info']['user']['account_lid']; |
---|
482 | $firstname = $GLOBALS['phpgw_info']['user']['firstname']; |
---|
483 | $lastname = $GLOBALS['phpgw_info']['user']['lastname']; |
---|
484 | } |
---|
485 | |
---|
486 | //$display = 'firstname';//original esta na linha de baixo; no Serpro nao interessa exibir uid (cpf); |
---|
487 | $display = $GLOBALS['phpgw_info']['user']['preferences']['common']['account_display']; |
---|
488 | |
---|
489 | if ($firstname && $lastname) |
---|
490 | { |
---|
491 | $delimiter = ', '; |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | $delimiter = ''; |
---|
496 | } |
---|
497 | |
---|
498 | $name = ''; |
---|
499 | switch($display) |
---|
500 | { |
---|
501 | case 'firstname': |
---|
502 | $name = $firstname . ' ' . $lastname; |
---|
503 | break; |
---|
504 | case 'lastname': |
---|
505 | $name = $lastname . $delimiter . $firstname; |
---|
506 | break; |
---|
507 | case 'username': |
---|
508 | $name = $lid; |
---|
509 | break; |
---|
510 | case 'firstall': |
---|
511 | $name = $firstname . ' ' . $lastname . ' ['.$lid.']'; |
---|
512 | break; |
---|
513 | case 'lastall': |
---|
514 | $name = $lastname . $delimiter . $firstname . ' ['.$lid.']'; |
---|
515 | break; |
---|
516 | case 'all': |
---|
517 | /* fall through */ |
---|
518 | default: |
---|
519 | $name = '['.$lid.'] ' . $firstname . ' ' . $lastname; |
---|
520 | } |
---|
521 | return $name; |
---|
522 | } |
---|
523 | |
---|
524 | /*! |
---|
525 | @function grab_owner_name |
---|
526 | @abstract grab the owner name |
---|
527 | @param $id account id |
---|
528 | */ |
---|
529 | function grab_owner_name($accountid = '') |
---|
530 | { |
---|
531 | $GLOBALS['phpgw']->accounts->get_account_name($accountid,$lid,$fname,$lname); |
---|
532 | return $this->display_fullname($lid,$fname,$lname); |
---|
533 | } |
---|
534 | |
---|
535 | /*! |
---|
536 | @function create_tabs |
---|
537 | @abstract create tabs |
---|
538 | @param $tabs ? |
---|
539 | @param $selected ? |
---|
540 | @param $fontsize optional |
---|
541 | */ |
---|
542 | function create_tabs($tabs, $selected, $fontsize = '') |
---|
543 | { |
---|
544 | $output_text = '<table border="0" cellspacing="0" cellpadding="0"><tr>'; |
---|
545 | |
---|
546 | /* This is a php3 workaround */ |
---|
547 | if(PHPGW_IMAGES_DIR == 'PHPGW_IMAGES_DIR') |
---|
548 | { |
---|
549 | $ir = ExecMethod('phpgwapi.phpgw.common.get_image_path', 'phpgwapi'); |
---|
550 | } |
---|
551 | else |
---|
552 | { |
---|
553 | $ir = PHPGW_IMAGES_DIR; |
---|
554 | } |
---|
555 | |
---|
556 | if ($fontsize) |
---|
557 | { |
---|
558 | $fs = '<font size="' . $fontsize . '">'; |
---|
559 | $fse = '</font>'; |
---|
560 | } |
---|
561 | |
---|
562 | $i = 1; |
---|
563 | while ($tab = each($tabs)) |
---|
564 | { |
---|
565 | if ($tab[0] == $selected) |
---|
566 | { |
---|
567 | if ($i == 1) |
---|
568 | { |
---|
569 | $output_text .= '<td align="right"><img src="' . $ir . '/tabs-start1.gif"></td>'; |
---|
570 | } |
---|
571 | |
---|
572 | $output_text .= '<td align="left" background="' . $ir . '/tabs-bg1.gif"> <b><a href="' |
---|
573 | . $tab[1]['link'] . '" class="tablink" '.$tab[1]['target'].'>' . $fs . $tab[1]['label'] |
---|
574 | . $fse . '</a></b> </td>'; |
---|
575 | if ($i == count($tabs)) |
---|
576 | { |
---|
577 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>'; |
---|
578 | } |
---|
579 | else |
---|
580 | { |
---|
581 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>'; |
---|
582 | } |
---|
583 | } |
---|
584 | else |
---|
585 | { |
---|
586 | if ($i == 1) |
---|
587 | { |
---|
588 | $output_text .= '<td align="right"><img src="' . $ir . '/tabs-start0.gif"></td>'; |
---|
589 | } |
---|
590 | $output_text .= '<td align="left" background="' . $ir . '/tabs-bg0.gif"> <b><a href="' |
---|
591 | . $tab[1]['link'] . '" class="tablink" '.$tab[1]['target'].'>' . $fs . $tab[1]['label'] . $fse |
---|
592 | . '</a></b> </td>'; |
---|
593 | if (($i + 1) == $selected) |
---|
594 | { |
---|
595 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepl.gif"></td>'; |
---|
596 | } |
---|
597 | elseif ($i == $selected || $i != count($tabs)) |
---|
598 | { |
---|
599 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepm.gif"></td>'; |
---|
600 | } |
---|
601 | elseif ($i == count($tabs)) |
---|
602 | { |
---|
603 | if ($i == $selected) |
---|
604 | { |
---|
605 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end1.gif"></td>'; |
---|
606 | } |
---|
607 | else |
---|
608 | { |
---|
609 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-end0.gif"></td>'; |
---|
610 | } |
---|
611 | } |
---|
612 | else |
---|
613 | { |
---|
614 | if ($i != count($tabs)) |
---|
615 | { |
---|
616 | $output_text .= '<td align="left"><img src="' . $ir . '/tabs-sepr.gif"></td>'; |
---|
617 | } |
---|
618 | } |
---|
619 | } |
---|
620 | $i++; |
---|
621 | $output_text .= "\n"; |
---|
622 | } |
---|
623 | $output_text .= "</table>\n"; |
---|
624 | return $output_text; |
---|
625 | } |
---|
626 | |
---|
627 | /*! |
---|
628 | @function get_app_dir |
---|
629 | @abstract get directory of application |
---|
630 | @discussion $appname can either be passed or derived from $phpgw_info['flags']['currentapp']; |
---|
631 | @param $appname name of application |
---|
632 | */ |
---|
633 | function get_app_dir($appname = '') |
---|
634 | { |
---|
635 | if ($appname == '') |
---|
636 | { |
---|
637 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
638 | } |
---|
639 | if ($appname == 'home' || $appname == 'logout' || $appname == 'login') |
---|
640 | { |
---|
641 | $appname = 'phpgwapi'; |
---|
642 | } |
---|
643 | |
---|
644 | $appdir = PHPGW_INCLUDE_ROOT . '/'.$appname; |
---|
645 | $appdir_default = PHPGW_SERVER_ROOT . '/'.$appname; |
---|
646 | |
---|
647 | if (@is_dir ($appdir)) |
---|
648 | { |
---|
649 | return $appdir; |
---|
650 | } |
---|
651 | elseif (@is_dir ($appdir_default)) |
---|
652 | { |
---|
653 | return $appdir_default; |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | return False; |
---|
658 | } |
---|
659 | } |
---|
660 | |
---|
661 | /*! |
---|
662 | @function get_inc_dir |
---|
663 | @abstract get inc (include dir) of application |
---|
664 | @discussion $appname can either be passed or derived from $phpgw_info['flags']['currentapp']; |
---|
665 | @param $appname name of application |
---|
666 | */ |
---|
667 | function get_inc_dir($appname = '') |
---|
668 | { |
---|
669 | if (! $appname) |
---|
670 | { |
---|
671 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
672 | } |
---|
673 | if ($appname == 'home' || $appname == 'logout' || $appname == 'login' || $appname == 'about') |
---|
674 | { |
---|
675 | $appname = 'phpgwapi'; |
---|
676 | } |
---|
677 | |
---|
678 | $incdir = PHPGW_INCLUDE_ROOT . '/' . $appname . '/inc'; |
---|
679 | $incdir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/inc'; |
---|
680 | |
---|
681 | if (@is_dir ($incdir)) |
---|
682 | { |
---|
683 | return $incdir; |
---|
684 | } |
---|
685 | elseif (@is_dir ($incdir_default)) |
---|
686 | { |
---|
687 | return $incdir_default; |
---|
688 | } |
---|
689 | else |
---|
690 | { |
---|
691 | return False; |
---|
692 | } |
---|
693 | } |
---|
694 | |
---|
695 | /*! |
---|
696 | @function list_themes |
---|
697 | @abstract list themes available |
---|
698 | @note themes can either be css file like in HEAD (if the template has a css-dir and has css-files in is) \ |
---|
699 | or ordinary .14 themes-files |
---|
700 | */ |
---|
701 | function list_themes() |
---|
702 | { |
---|
703 | $tpl_dir = $this->get_tpl_dir('phpgwapi'); |
---|
704 | |
---|
705 | if ($dh = @opendir($tpl_dir . SEP . 'css')) |
---|
706 | { |
---|
707 | while ($file = readdir($dh)) |
---|
708 | { |
---|
709 | if (eregi("\.css$", $file) && $file != 'phpgw.css') |
---|
710 | { |
---|
711 | $list[] = substr($file,0,strpos($file,'.')); |
---|
712 | } |
---|
713 | } |
---|
714 | } |
---|
715 | if(!is_array($list)) |
---|
716 | { |
---|
717 | $dh = opendir(PHPGW_SERVER_ROOT . '/phpgwapi/themes'); |
---|
718 | while ($file = readdir($dh)) |
---|
719 | { |
---|
720 | if (eregi("\.theme$", $file)) |
---|
721 | { |
---|
722 | $list[] = substr($file,0,strpos($file,'.')); |
---|
723 | } |
---|
724 | } |
---|
725 | } |
---|
726 | closedir($dh); |
---|
727 | reset ($list); |
---|
728 | return $list; |
---|
729 | } |
---|
730 | |
---|
731 | /** |
---|
732 | * List available templates |
---|
733 | * |
---|
734 | * @returns array alphabetically sorted list of templates |
---|
735 | */ |
---|
736 | function list_templates() |
---|
737 | { |
---|
738 | $d = dir(PHPGW_SERVER_ROOT . '/phpgwapi/templates'); |
---|
739 | while ($entry=$d->read()) |
---|
740 | { |
---|
741 | if ($entry != 'CVS' && $entry != '.' && $entry != '..' |
---|
742 | && $entry != 'phpgw_website' |
---|
743 | && is_dir(PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry)) |
---|
744 | { |
---|
745 | $list[$entry]['name'] = $entry; |
---|
746 | $f = PHPGW_SERVER_ROOT . '/phpgwapi/templates/' . $entry . '/details.inc.php'; |
---|
747 | if (file_exists ($f)) |
---|
748 | { |
---|
749 | include($f); |
---|
750 | $list[$entry]['title'] = 'Use '.$GLOBALS['phpgw_info']['template'][$entry]['title'].'interface'; |
---|
751 | } |
---|
752 | else |
---|
753 | { |
---|
754 | $list[$entry]['title'] = $entry; |
---|
755 | } |
---|
756 | } |
---|
757 | } |
---|
758 | $d->close(); |
---|
759 | ksort($list); |
---|
760 | return $list; |
---|
761 | } |
---|
762 | |
---|
763 | /*! |
---|
764 | @function get_tpl_dir |
---|
765 | @abstract get template dir of an application |
---|
766 | @param $appname appication name optional can be derived from $phpgw_info['flags']['currentapp']; |
---|
767 | */ |
---|
768 | function get_tpl_dir($appname = '') |
---|
769 | { |
---|
770 | if (! $appname) |
---|
771 | { |
---|
772 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
773 | } |
---|
774 | if ($appname == 'home' || $appname == 'logout' || $appname == 'login') |
---|
775 | { |
---|
776 | $appname = 'phpgwapi'; |
---|
777 | } |
---|
778 | |
---|
779 | if (!isset($GLOBALS['phpgw_info']['server']['template_set']) && isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'])) |
---|
780 | { |
---|
781 | $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']; |
---|
782 | } |
---|
783 | |
---|
784 | // Setting this for display of template choices in user preferences |
---|
785 | if ($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice') |
---|
786 | { |
---|
787 | $GLOBALS['phpgw_info']['server']['usrtplchoice'] = 'user_choice'; |
---|
788 | } |
---|
789 | |
---|
790 | if (($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice' || |
---|
791 | !isset($GLOBALS['phpgw_info']['server']['template_set'])) && |
---|
792 | isset($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'])) |
---|
793 | { |
---|
794 | $GLOBALS['phpgw_info']['server']['template_set'] = $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']; |
---|
795 | } |
---|
796 | elseif ($GLOBALS['phpgw_info']['server']['template_set'] == 'user_choice' || |
---|
797 | !isset($GLOBALS['phpgw_info']['server']['template_set'])) |
---|
798 | { |
---|
799 | $GLOBALS['phpgw_info']['server']['template_set'] = 'default'; |
---|
800 | } |
---|
801 | |
---|
802 | $tpldir = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/' . $GLOBALS['phpgw_info']['server']['template_set']; |
---|
803 | $tpldir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/default'; |
---|
804 | |
---|
805 | if (@is_dir($tpldir)) |
---|
806 | { |
---|
807 | return $tpldir; |
---|
808 | } |
---|
809 | elseif (@is_dir($tpldir_default)) |
---|
810 | { |
---|
811 | return $tpldir_default; |
---|
812 | } |
---|
813 | else |
---|
814 | { |
---|
815 | return False; |
---|
816 | } |
---|
817 | } |
---|
818 | |
---|
819 | /*! |
---|
820 | @function is_image_dir |
---|
821 | @abstract checks if image_dir exists and has more than just a navbar-icon |
---|
822 | @note this is just a workaround for idots, better to use find_image, which has a fallback \ |
---|
823 | on a per image basis to the default dir |
---|
824 | */ |
---|
825 | function is_image_dir($dir) |
---|
826 | { |
---|
827 | if (!@is_dir($dir)) |
---|
828 | { |
---|
829 | return False; |
---|
830 | } |
---|
831 | if ($d = opendir($dir)) |
---|
832 | { |
---|
833 | while ($f = readdir($d)) |
---|
834 | { |
---|
835 | $ext = strtolower(strrchr($f,'.')); |
---|
836 | if (($ext == '.gif' || $ext == '.png') && strstr($f,'navbar') === False) |
---|
837 | { |
---|
838 | return True; |
---|
839 | } |
---|
840 | } |
---|
841 | } |
---|
842 | return False; |
---|
843 | } |
---|
844 | |
---|
845 | /*! |
---|
846 | @function get_image_dir |
---|
847 | @abstract get image dir of an application |
---|
848 | @param $appname application name optional can be derived from $phpgw_info['flags']['currentapp']; |
---|
849 | */ |
---|
850 | function get_image_dir($appname = '') |
---|
851 | { |
---|
852 | if ($appname == '') |
---|
853 | { |
---|
854 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
855 | } |
---|
856 | if (empty($GLOBALS['phpgw_info']['server']['template_set'])) |
---|
857 | { |
---|
858 | $GLOBALS['phpgw_info']['server']['template_set'] = 'default'; |
---|
859 | } |
---|
860 | |
---|
861 | $imagedir = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/' |
---|
862 | . $GLOBALS['phpgw_info']['server']['template_set'] . '/images'; |
---|
863 | $imagedir_default = PHPGW_SERVER_ROOT . '/' . $appname . '/templates/default/images'; |
---|
864 | $imagedir_olddefault = PHPGW_SERVER_ROOT . '/' . $appname . '/images'; |
---|
865 | |
---|
866 | if ($this->is_image_dir ($imagedir)) |
---|
867 | { |
---|
868 | return $imagedir; |
---|
869 | } |
---|
870 | elseif ($this->is_image_dir ($imagedir_default)) |
---|
871 | { |
---|
872 | return $imagedir_default; |
---|
873 | } |
---|
874 | elseif ($this->is_image_dir ($imagedir_olddefault)) |
---|
875 | { |
---|
876 | return $imagedir_olddefault; |
---|
877 | } |
---|
878 | else |
---|
879 | { |
---|
880 | return False; |
---|
881 | } |
---|
882 | } |
---|
883 | |
---|
884 | /*! |
---|
885 | @function get_image_path |
---|
886 | @abstract get image path of an application |
---|
887 | @param $appname appication name optional can be derived from $phpgw_info['flags']['currentapp']; |
---|
888 | */ |
---|
889 | function get_image_path($appname = '') |
---|
890 | { |
---|
891 | if ($appname == '') |
---|
892 | { |
---|
893 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
894 | } |
---|
895 | |
---|
896 | if (empty($GLOBALS['phpgw_info']['server']['template_set'])) |
---|
897 | { |
---|
898 | $GLOBALS['phpgw_info']['server']['template_set'] = 'default'; |
---|
899 | } |
---|
900 | |
---|
901 | $imagedir = PHPGW_SERVER_ROOT . '/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['server']['template_set'].'/images'; |
---|
902 | $imagedir_default = PHPGW_SERVER_ROOT . '/'.$appname.'/templates/default/images'; |
---|
903 | $imagedir_olddefault = PHPGW_SERVER_ROOT . '/'.$appname.'/images'; |
---|
904 | |
---|
905 | if ($this->is_image_dir ($imagedir)) |
---|
906 | { |
---|
907 | return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['server']['template_set'].'/images'; |
---|
908 | } |
---|
909 | elseif ($this->is_image_dir ($imagedir_default)) |
---|
910 | { |
---|
911 | return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/templates/default/images'; |
---|
912 | } |
---|
913 | elseif ($this->is_image_dir ($imagedir_olddefault)) |
---|
914 | { |
---|
915 | return $GLOBALS['phpgw_info']['server']['webserver_url'].'/'.$appname.'/images'; |
---|
916 | } |
---|
917 | else |
---|
918 | { |
---|
919 | return False; |
---|
920 | } |
---|
921 | } |
---|
922 | |
---|
923 | function find_image($appname,$image) |
---|
924 | { |
---|
925 | $imagedir = '/'.$appname.'/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images'; |
---|
926 | |
---|
927 | if (!@is_array($this->found_files[$appname])) |
---|
928 | { |
---|
929 | $imagedir_olddefault = '/'.$appname.'/images'; |
---|
930 | $imagedir_default = '/'.$appname.'/templates/default/images'; |
---|
931 | |
---|
932 | if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir_olddefault)) |
---|
933 | { |
---|
934 | $d = dir(PHPGW_INCLUDE_ROOT.$imagedir_olddefault); |
---|
935 | while (false != ($entry = $d->read())) |
---|
936 | { |
---|
937 | if ($entry != '.' && $entry != '..') |
---|
938 | { |
---|
939 | $this->found_files[$appname][$entry] = $imagedir_olddefault; |
---|
940 | } |
---|
941 | } |
---|
942 | $d->close(); |
---|
943 | } |
---|
944 | |
---|
945 | if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir_default)) |
---|
946 | { |
---|
947 | $d = dir(PHPGW_INCLUDE_ROOT.$imagedir_default); |
---|
948 | while (false != ($entry = $d->read())) |
---|
949 | { |
---|
950 | if ($entry != '.' && $entry != '..') |
---|
951 | { |
---|
952 | $this->found_files[$appname][$entry] = $imagedir_default; |
---|
953 | } |
---|
954 | } |
---|
955 | $d->close(); |
---|
956 | } |
---|
957 | |
---|
958 | if (@is_dir(PHPGW_INCLUDE_ROOT.$imagedir)) |
---|
959 | { |
---|
960 | $d = dir(PHPGW_INCLUDE_ROOT.$imagedir); |
---|
961 | while (false != ($entry = $d->read())) |
---|
962 | { |
---|
963 | if ($entry != '.' && $entry != '..') |
---|
964 | { |
---|
965 | $this->found_files[$appname][$entry] = $imagedir; |
---|
966 | } |
---|
967 | } |
---|
968 | $d->close(); |
---|
969 | } |
---|
970 | } |
---|
971 | |
---|
972 | if (!$GLOBALS['phpgw_info']['server']['image_type']) |
---|
973 | { |
---|
974 | // priority: GIF->JPG->PNG |
---|
975 | $img_type=array('.gif','.jpg','.png'); |
---|
976 | } |
---|
977 | else |
---|
978 | { |
---|
979 | // priority: : PNG->JPG->GIF |
---|
980 | $img_type=array('.png','.jpg','.gif'); |
---|
981 | } |
---|
982 | |
---|
983 | // first look in the selected template dir |
---|
984 | if(@$this->found_files[$appname][$image.$img_type[0]]==$imagedir) |
---|
985 | { |
---|
986 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[0]].'/'.$image.$img_type[0]; |
---|
987 | } |
---|
988 | elseif(@$this->found_files[$appname][$image.$img_type[1]]==$imagedir) |
---|
989 | { |
---|
990 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[1]].'/'.$image.$img_type[1]; |
---|
991 | } |
---|
992 | elseif(@$this->found_files[$appname][$image.$img_type[2]]==$imagedir) |
---|
993 | { |
---|
994 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[2]].'/'.$image.$img_type[2]; |
---|
995 | } |
---|
996 | // then look everywhere else |
---|
997 | elseif(isset($this->found_files[$appname][$image.$img_type[0]])) |
---|
998 | { |
---|
999 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[0]].'/'.$image.$img_type[0]; |
---|
1000 | } |
---|
1001 | elseif(isset($this->found_files[$appname][$image.$img_type[1]])) |
---|
1002 | { |
---|
1003 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[1]].'/'.$image.$img_type[1]; |
---|
1004 | } |
---|
1005 | elseif(isset($this->found_files[$appname][$image.$img_type[2]])) |
---|
1006 | { |
---|
1007 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image.$img_type[2]].'/'.$image.$img_type[2]; |
---|
1008 | } |
---|
1009 | elseif(isset($this->found_files[$appname][$image])) |
---|
1010 | { |
---|
1011 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$image].'/'.$image; |
---|
1012 | } |
---|
1013 | else |
---|
1014 | { |
---|
1015 | // searching the image in the api-dirs |
---|
1016 | if (!isset($this->found_files['phpgwapi'])) |
---|
1017 | { |
---|
1018 | $this->find_image('phpgwapi',''); |
---|
1019 | } |
---|
1020 | |
---|
1021 | if(isset($this->found_files['phpgwapi'][$image.$img_type[0]])) |
---|
1022 | { |
---|
1023 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[0]].'/'.$image.$img_type[0]; |
---|
1024 | } |
---|
1025 | elseif(isset($this->found_files['phpgwapi'][$image.$img_type[1]])) |
---|
1026 | { |
---|
1027 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[1]].'/'.$image.$img_type[1]; |
---|
1028 | } |
---|
1029 | elseif(isset($this->found_files['phpgwapi'][$image.$img_type[2]])) |
---|
1030 | { |
---|
1031 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image.$img_type[2]].'/'.$image.$img_type[2]; |
---|
1032 | } |
---|
1033 | elseif(isset($this->found_files['phpgwapi'][$image])) |
---|
1034 | { |
---|
1035 | $imgfile = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files['phpgwapi'][$image].'/'.$image; |
---|
1036 | } |
---|
1037 | else |
---|
1038 | { |
---|
1039 | $imgfile = ''; |
---|
1040 | } |
---|
1041 | } |
---|
1042 | return $imgfile; |
---|
1043 | } |
---|
1044 | |
---|
1045 | function image($appname,$image='',$ext='',$use_lang=True) |
---|
1046 | { |
---|
1047 | if (!is_array($image)) |
---|
1048 | { |
---|
1049 | if (empty($image)) |
---|
1050 | { |
---|
1051 | return ''; |
---|
1052 | } |
---|
1053 | $image = array($image); |
---|
1054 | } |
---|
1055 | if ($use_lang) |
---|
1056 | { |
---|
1057 | while (list(,$img) = each($image)) |
---|
1058 | { |
---|
1059 | $lang_images[] = $img . '_' . $GLOBALS['phpgw_info']['user']['preferences']['common']['lang']; |
---|
1060 | $lang_images[] = $img; |
---|
1061 | } |
---|
1062 | $image = $lang_images; |
---|
1063 | } |
---|
1064 | while (empty($image_found) && list(,$img) = each($image)) |
---|
1065 | { |
---|
1066 | if(isset($this->found_files[$appname][$img.$ext])) |
---|
1067 | { |
---|
1068 | $image_found = $GLOBALS['phpgw_info']['server']['webserver_url'].$this->found_files[$appname][$img.$ext].'/'.$img.$ext; |
---|
1069 | } |
---|
1070 | else |
---|
1071 | { |
---|
1072 | $image_found = $this->find_image($appname,$img.$ext); |
---|
1073 | } |
---|
1074 | } |
---|
1075 | return $image_found; |
---|
1076 | } |
---|
1077 | |
---|
1078 | function image_on($appname,$image,$extension='_on') |
---|
1079 | { |
---|
1080 | $with_extension = $this->image($appname,$image,$extension); |
---|
1081 | $without_extension = $this->image($appname,$image); |
---|
1082 | if($with_extension != '') |
---|
1083 | { |
---|
1084 | return $with_extension; |
---|
1085 | } |
---|
1086 | elseif($without_extension != '') |
---|
1087 | { |
---|
1088 | return $without_extension; |
---|
1089 | } |
---|
1090 | else |
---|
1091 | { |
---|
1092 | return ''; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | |
---|
1096 | /*! |
---|
1097 | @function navbar |
---|
1098 | @abstract none yet |
---|
1099 | @discussion *someone wanna add some detail here* |
---|
1100 | */ |
---|
1101 | function navbar() |
---|
1102 | { |
---|
1103 | $GLOBALS['phpgw_info']['navbar']['home']['title'] = 'Home'; |
---|
1104 | $GLOBALS['phpgw_info']['navbar']['home']['url'] = $GLOBALS['phpgw']->link('/home.php'); |
---|
1105 | $GLOBALS['phpgw_info']['navbar']['home']['icon'] = $this->image('phpgwapi',Array('home','nonav')); |
---|
1106 | $GLOBALS['phpgw_info']['navbar']['home']['icon_hover'] = $this->image_on('phpgwapi',Array('home','nonav'),'-over'); |
---|
1107 | |
---|
1108 | list($first) = each($GLOBALS['phpgw_info']['user']['apps']); |
---|
1109 | if(is_array($GLOBALS['phpgw_info']['user']['apps']['admin']) && $first != 'admin') |
---|
1110 | { |
---|
1111 | $newarray['admin'] = $GLOBALS['phpgw_info']['user']['apps']['admin']; |
---|
1112 | foreach($GLOBALS['phpgw_info']['user']['apps'] as $index => $value) |
---|
1113 | { |
---|
1114 | if($index != 'admin') |
---|
1115 | { |
---|
1116 | $newarray[$index] = $value; |
---|
1117 | } |
---|
1118 | } |
---|
1119 | $GLOBALS['phpgw_info']['user']['apps'] = $newarray; |
---|
1120 | reset($GLOBALS['phpgw_info']['user']['apps']); |
---|
1121 | } |
---|
1122 | unset($index); |
---|
1123 | unset($value); |
---|
1124 | unset($newarray); |
---|
1125 | |
---|
1126 | foreach($GLOBALS['phpgw_info']['user']['apps'] as $app => $data) |
---|
1127 | { |
---|
1128 | if (is_long($app)) |
---|
1129 | { |
---|
1130 | continue; |
---|
1131 | } |
---|
1132 | |
---|
1133 | if ($app == 'preferences' || $GLOBALS['phpgw_info']['apps'][$app]['status'] != 2 && $GLOBALS['phpgw_info']['apps'][$app]['status'] != 3) |
---|
1134 | { |
---|
1135 | $GLOBALS['phpgw_info']['navbar'][$app]['title'] = $GLOBALS['phpgw_info']['apps'][$app]['title']; |
---|
1136 | $GLOBALS['phpgw_info']['navbar'][$app]['url'] = $GLOBALS['phpgw']->link('/' . $app . '/index.php',$GLOBALS['phpgw_info']['flags']['params'][$app]); |
---|
1137 | $GLOBALS['phpgw_info']['navbar'][$app]['name'] = $app; |
---|
1138 | |
---|
1139 | // create popup target |
---|
1140 | if ($data['status'] == 4) |
---|
1141 | { |
---|
1142 | $GLOBALS['phpgw_info']['navbar'][$app]['target'] = ' target="'.$app.'" onClick="'."if (this != '') { window.open(this+'". |
---|
1143 | (strstr($GLOBALS['phpgw_info']['navbar'][$app]['url'],'?') || |
---|
1144 | ini_get('session.use_trans_sid') && $GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4' ?'&':'?'). |
---|
1145 | "referer='+encodeURI(location),this.target,'width=800,height=600,scrollbars=yes,resizable=yes'); return false; } else { return true; }".'"'; |
---|
1146 | } |
---|
1147 | |
---|
1148 | if ($app != $GLOBALS['phpgw_info']['flags']['currentapp']) |
---|
1149 | { |
---|
1150 | $GLOBALS['phpgw_info']['navbar'][$app]['icon'] = $this->image($app,Array('navbar','nonav')); |
---|
1151 | $GLOBALS['phpgw_info']['navbar'][$app]['icon_hover'] = $this->image_on($app,Array('navbar','nonav'),'-over'); |
---|
1152 | } |
---|
1153 | else |
---|
1154 | { |
---|
1155 | $GLOBALS['phpgw_info']['navbar'][$app]['icon'] = $this->image_on($app,Array('navbar','nonav'),'-over'); |
---|
1156 | $GLOBALS['phpgw_info']['navbar'][$app]['icon_hover'] = $this->image($app,Array('navbar','nonav')); |
---|
1157 | } |
---|
1158 | |
---|
1159 | // if($GLOBALS['phpgw_info']['navbar'][$app]['icon'] == '') |
---|
1160 | // { |
---|
1161 | // $GLOBALS['phpgw_info']['navbar'][$app]['icon'] = $this->image('phpgwapi','nonav'); |
---|
1162 | // } |
---|
1163 | } |
---|
1164 | } |
---|
1165 | if ($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' || $GLOBALS['phpgw_info']['flags']['currentapp'] == 'preferences' || $GLOBALS['phpgw_info']['flags']['currentapp'] == 'about') |
---|
1166 | { |
---|
1167 | $app = $app_title = 'eGroupWare'; |
---|
1168 | } |
---|
1169 | else |
---|
1170 | { |
---|
1171 | $app = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
1172 | $app_title = $GLOBALS['phpgw_info']['apps'][$app]['title']; |
---|
1173 | } |
---|
1174 | |
---|
1175 | if ($GLOBALS['phpgw_info']['user']['apps']['preferences']) // preferences last |
---|
1176 | { |
---|
1177 | $prefs = $GLOBALS['phpgw_info']['navbar']['preferences']; |
---|
1178 | unset($GLOBALS['phpgw_info']['navbar']['preferences']); |
---|
1179 | $GLOBALS['phpgw_info']['navbar']['preferences'] = $prefs; |
---|
1180 | } |
---|
1181 | |
---|
1182 | // We handle this here becuase its special |
---|
1183 | $GLOBALS['phpgw_info']['navbar']['about']['title'] = lang('About %1',$app_title); |
---|
1184 | |
---|
1185 | $GLOBALS['phpgw_info']['navbar']['about']['url'] = $GLOBALS['phpgw']->link('/about.php','app='.$app); |
---|
1186 | $GLOBALS['phpgw_info']['navbar']['about']['icon'] = $this->image('phpgwapi',Array('about','nonav')); |
---|
1187 | $GLOBALS['phpgw_info']['navbar']['about']['icon_hover'] = $this->image_on('phpgwapi',Array('about','nonav'),'-over'); |
---|
1188 | |
---|
1189 | $GLOBALS['phpgw_info']['navbar']['logout']['title'] = lang('Logout'); |
---|
1190 | $GLOBALS['phpgw_info']['navbar']['logout']['url'] = $GLOBALS['phpgw']->link('/logout.php'); |
---|
1191 | $GLOBALS['phpgw_info']['navbar']['logout']['icon'] = $this->image('phpgwapi',Array('logout','nonav')); |
---|
1192 | $GLOBALS['phpgw_info']['navbar']['logout']['icon_hover'] = $this->image_on('phpgwapi',Array('logout','nonav'),'-over'); |
---|
1193 | } |
---|
1194 | |
---|
1195 | /*! |
---|
1196 | @function app_header |
---|
1197 | @abstract load header.inc.php for an application |
---|
1198 | */ |
---|
1199 | function app_header() |
---|
1200 | { |
---|
1201 | if (file_exists(PHPGW_APP_INC . '/header.inc.php')) |
---|
1202 | { |
---|
1203 | include(PHPGW_APP_INC . '/header.inc.php'); |
---|
1204 | } |
---|
1205 | } |
---|
1206 | /*! |
---|
1207 | @function phpgw_header |
---|
1208 | @abstract load the phpgw header |
---|
1209 | */ |
---|
1210 | function phpgw_header() |
---|
1211 | { |
---|
1212 | // add a content-type header to overwrite an existing default charset in apache (AddDefaultCharset directiv) |
---|
1213 | header('Content-type: text/html; charset='.$GLOBALS['phpgw']->translation->charset()); |
---|
1214 | include(PHPGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] |
---|
1215 | . '/head.inc.php'); |
---|
1216 | $this->navbar(False); |
---|
1217 | include(PHPGW_INCLUDE_ROOT . '/phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] |
---|
1218 | . '/navbar.inc.php'); |
---|
1219 | if (!@$GLOBALS['phpgw_info']['flags']['nonavbar'] && !@$GLOBALS['phpgw_info']['flags']['navbar_target']) |
---|
1220 | { |
---|
1221 | echo parse_navbar(); |
---|
1222 | } |
---|
1223 | } |
---|
1224 | |
---|
1225 | function phpgw_footer() |
---|
1226 | { |
---|
1227 | if (!defined('PHPGW_FOOTER')) |
---|
1228 | { |
---|
1229 | define('PHPGW_FOOTER',True); |
---|
1230 | if (!isset($GLOBALS['phpgw_info']['flags']['nofooter']) || !$GLOBALS['phpgw_info']['flags']['nofooter']) |
---|
1231 | { |
---|
1232 | include(PHPGW_API_INC . '/footer.inc.php'); |
---|
1233 | } |
---|
1234 | } |
---|
1235 | } |
---|
1236 | |
---|
1237 | /** |
---|
1238 | * Used by template headers for including CSS in the header |
---|
1239 | * |
---|
1240 | * This first loads up the basic global CSS definitions, which support |
---|
1241 | * the selected user theme colors. Next we load up the app CSS. This is |
---|
1242 | * all merged into the selected theme's css.tpl file. |
---|
1243 | * |
---|
1244 | * @author Dave Hall (*based* on verdilak? css inclusion code) |
---|
1245 | */ |
---|
1246 | function get_css() |
---|
1247 | { |
---|
1248 | $tpl = createObject('phpgwapi.Template', $this->get_tpl_dir('phpgwapi')); |
---|
1249 | $tpl->set_file('css', 'css.tpl'); |
---|
1250 | $tpl->set_var($GLOBALS['phpgw_info']['theme']); |
---|
1251 | $app_css = ''; |
---|
1252 | if(@isset($_GET['menuaction'])) |
---|
1253 | { |
---|
1254 | list($app,$class,$method) = explode('.',$_GET['menuaction']); |
---|
1255 | if(is_array($GLOBALS[$class]->public_functions) && |
---|
1256 | $GLOBALS[$class]->public_functions['css']) |
---|
1257 | { |
---|
1258 | $app_css .= $GLOBALS[$class]->css(); |
---|
1259 | } |
---|
1260 | } |
---|
1261 | if (isset($GLOBALS['phpgw_info']['flags']['css'])) |
---|
1262 | { |
---|
1263 | $app_css .= $GLOBALS['phpgw_info']['flags']['css']; |
---|
1264 | } |
---|
1265 | $tpl->set_var('app_css', $app_css); |
---|
1266 | |
---|
1267 | // search for app specific css file |
---|
1268 | if(@isset($GLOBALS['phpgw_info']['flags']['currentapp'])) |
---|
1269 | { |
---|
1270 | $appname = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
1271 | |
---|
1272 | if(file_exists(PHPGW_SERVER_ROOT . SEP . $appname . SEP |
---|
1273 | . 'templates' . SEP . $GLOBALS['phpgw_info']['server']['template_set'] |
---|
1274 | . SEP . 'app.css') |
---|
1275 | ) |
---|
1276 | { |
---|
1277 | $tpl->set_var('css_file', '<LINK href="'.$GLOBALS['phpgw_info']['server']['webserver_url'] |
---|
1278 | . "/$appname/templates/".$GLOBALS['phpgw_info']['server']['template_set'] |
---|
1279 | . "/app.css".'" type=text/css rel=StyleSheet>'); |
---|
1280 | } |
---|
1281 | elseif(file_exists(PHPGW_SERVER_ROOT . SEP . $appname . SEP |
---|
1282 | . 'templates' . SEP . 'default' |
---|
1283 | . SEP . 'app.css') |
---|
1284 | ) |
---|
1285 | { |
---|
1286 | $tpl->set_var('css_file', '<LINK href="'.$GLOBALS['phpgw_info']['server']['webserver_url'] |
---|
1287 | ."/$appname/templates/default/app.css".'" type=text/css rel=StyleSheet>'); |
---|
1288 | } |
---|
1289 | } |
---|
1290 | |
---|
1291 | return $tpl->subst('css'); |
---|
1292 | } |
---|
1293 | |
---|
1294 | /** |
---|
1295 | * Used by the template headers for including javascript in the header |
---|
1296 | * |
---|
1297 | * The method is included here to make it easier to change the js support |
---|
1298 | * in phpgw. One change then all templates will support it (as long as they |
---|
1299 | * include a call to this method). |
---|
1300 | * |
---|
1301 | * @author Dave Hall (*vaguely based* on verdilak? css inclusion code) |
---|
1302 | * @return string the javascript to be included |
---|
1303 | */ |
---|
1304 | function get_java_script() |
---|
1305 | { |
---|
1306 | $java_script = ''; |
---|
1307 | |
---|
1308 | /* this flag is for all javascript code that has to be put before other jscode. |
---|
1309 | Think of conf vars etc... (pim@lingewoud.nl) */ |
---|
1310 | if (isset($GLOBALS['phpgw_info']['flags']['java_script_thirst'])) |
---|
1311 | { |
---|
1312 | $java_script .= $GLOBALS['phpgw_info']['flags']['java_script_thirst'] . "\n"; |
---|
1313 | } |
---|
1314 | |
---|
1315 | if(@is_object($GLOBALS['phpgw']->js)) |
---|
1316 | { |
---|
1317 | $java_script .= $GLOBALS['phpgw']->js->get_script_links(); |
---|
1318 | } |
---|
1319 | |
---|
1320 | if(@isset($_GET['menuaction'])) |
---|
1321 | { |
---|
1322 | list($app,$class,$method) = explode('.',$_GET['menuaction']); |
---|
1323 | if(is_array($GLOBALS[$class]->public_functions) && |
---|
1324 | $GLOBALS[$class]->public_functions['java_script']) |
---|
1325 | { |
---|
1326 | $java_script .= $GLOBALS[$class]->java_script(); |
---|
1327 | } |
---|
1328 | } |
---|
1329 | if (isset($GLOBALS['phpgw_info']['flags']['java_script'])) |
---|
1330 | { |
---|
1331 | $java_script .= $GLOBALS['phpgw_info']['flags']['java_script'] . "\n"; |
---|
1332 | } |
---|
1333 | return $java_script; |
---|
1334 | } |
---|
1335 | |
---|
1336 | /** |
---|
1337 | * Returns on(Un)Load attributes from js class |
---|
1338 | * |
---|
1339 | *@author Dave Hall - skwashd at phpgroupware.org |
---|
1340 | *@returns string body attributes |
---|
1341 | */ |
---|
1342 | function get_body_attribs() |
---|
1343 | { |
---|
1344 | if(@is_object($GLOBALS['phpgw']->js)) |
---|
1345 | { |
---|
1346 | return $GLOBALS['phpgw']->js->get_body_attribs(); |
---|
1347 | } |
---|
1348 | else |
---|
1349 | { |
---|
1350 | return ''; |
---|
1351 | } |
---|
1352 | } |
---|
1353 | |
---|
1354 | function hex2bin($data) |
---|
1355 | { |
---|
1356 | $len = strlen($data); |
---|
1357 | return @pack('H' . $len, $data); |
---|
1358 | } |
---|
1359 | |
---|
1360 | /*! |
---|
1361 | @function encrypt |
---|
1362 | @abstract encrypt data passed to the function |
---|
1363 | @param $data data (string?) to be encrypted |
---|
1364 | */ |
---|
1365 | function encrypt($data) |
---|
1366 | { |
---|
1367 | return $GLOBALS['phpgw']->crypto->encrypt($data); |
---|
1368 | } |
---|
1369 | |
---|
1370 | /*! |
---|
1371 | @function decrypt |
---|
1372 | @abstract decrypt $data |
---|
1373 | @param $data data to be decrypted |
---|
1374 | */ |
---|
1375 | function decrypt($data) |
---|
1376 | { |
---|
1377 | return $GLOBALS['phpgw']->crypto->decrypt($data); |
---|
1378 | } |
---|
1379 | |
---|
1380 | /*! |
---|
1381 | @function encrypt_password |
---|
1382 | @abstract legacy wrapper for newer auth class function, encrypt_password |
---|
1383 | @abstract uses the encryption type set in setup and calls the appropriate encryption functions |
---|
1384 | @param $password password to encrypt |
---|
1385 | */ |
---|
1386 | function encrypt_password($password,$sql=False) |
---|
1387 | { |
---|
1388 | if(!@is_object($GLOBALS['phpgw']->auth)) |
---|
1389 | { |
---|
1390 | $GLOBALS['phpgw']->auth = CreateObject('phpgwapi.auth'); |
---|
1391 | } |
---|
1392 | return $GLOBALS['phpgw']->auth->encrypt_password($password,$sql); |
---|
1393 | } |
---|
1394 | |
---|
1395 | /*! |
---|
1396 | @function find_portal_order |
---|
1397 | @abstract find the current position of the app is the users portal_order preference |
---|
1398 | @param $app application id to find current position - required |
---|
1399 | @discussion No discussion |
---|
1400 | */ |
---|
1401 | function find_portal_order($app) |
---|
1402 | { |
---|
1403 | if(!is_array($GLOBALS['phpgw_info']['user']['preferences']['portal_order'])) |
---|
1404 | { |
---|
1405 | return -1; |
---|
1406 | } |
---|
1407 | @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']); |
---|
1408 | while(list($seq,$appid) = each($GLOBALS['phpgw_info']['user']['preferences']['portal_order'])) |
---|
1409 | { |
---|
1410 | if($appid == $app) |
---|
1411 | { |
---|
1412 | @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']); |
---|
1413 | return $seq; |
---|
1414 | } |
---|
1415 | } |
---|
1416 | @reset($GLOBALS['phpgw_info']['user']['preferences']['portal_order']); |
---|
1417 | return -1; |
---|
1418 | } |
---|
1419 | |
---|
1420 | /*! |
---|
1421 | @function hook |
---|
1422 | @abstract temp wrapper to new hooks class |
---|
1423 | */ |
---|
1424 | function hook($location, $appname = '', $no_permission_check = False) |
---|
1425 | { |
---|
1426 | echo '$'."GLOBALS['phpgw']common->hook()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->process()".'. For now this will act as a wrapper<br>'; |
---|
1427 | return $GLOBALS['phpgw']->hooks->process($location, $order, $no_permission_check); |
---|
1428 | } |
---|
1429 | |
---|
1430 | /*! |
---|
1431 | @function hook_single |
---|
1432 | @abstract temp wrapper to new hooks class |
---|
1433 | */ |
---|
1434 | // Note: $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) |
---|
1435 | function hook_single($location, $appname = '', $no_permission_check = False) |
---|
1436 | { |
---|
1437 | echo '$'."GLOBALS['phpgw']common->hook_single()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->single()".'. For now this will act as a wrapper<br>'; |
---|
1438 | return $GLOBALS['phpgw']->hooks->single($location, $order, $no_permission_check); |
---|
1439 | } |
---|
1440 | |
---|
1441 | /*! |
---|
1442 | @function hook_count |
---|
1443 | @abstract temp wrapper to new hooks class |
---|
1444 | */ |
---|
1445 | function hook_count($location) |
---|
1446 | { |
---|
1447 | echo '$'."GLOBALS['phpgw']common->hook_count()".' has been replaced. Please change to the new $'."GLOBALS['phpgw']hooks->count()".'. For now this will act as a wrapper<br>'; |
---|
1448 | return $GLOBALS['phpgw']->hooks->count($location); |
---|
1449 | } |
---|
1450 | |
---|
1451 | /* Wrapper to the session->appsession() */ |
---|
1452 | function appsession($data = '##NOTHING##') |
---|
1453 | { |
---|
1454 | $this->debug_info[] = '$phpgw->common->appsession() is a depreciated function' |
---|
1455 | . ' - use $phpgw->session->appsession() instead'; |
---|
1456 | |
---|
1457 | return $GLOBALS['phpgw']->session->appsession('default','',$data); |
---|
1458 | } |
---|
1459 | |
---|
1460 | /*! |
---|
1461 | @function show_date |
---|
1462 | @abstract show current date |
---|
1463 | @param $t time - optional can be pulled from user preferences |
---|
1464 | @param $format - optional can be pulled from user prefernces |
---|
1465 | */ |
---|
1466 | function show_date($t = '', $format = '') |
---|
1467 | { |
---|
1468 | if(!is_object($GLOBALS['phpgw']->datetime)) |
---|
1469 | { |
---|
1470 | $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); |
---|
1471 | } |
---|
1472 | |
---|
1473 | if (!$t || (int)$t <= 0) |
---|
1474 | { |
---|
1475 | $t = $GLOBALS['phpgw']->datetime->gmtnow; |
---|
1476 | } |
---|
1477 | |
---|
1478 | // + (date('I') == 1?3600:0) |
---|
1479 | $t += $GLOBALS['phpgw']->datetime->tz_offset; |
---|
1480 | |
---|
1481 | if (! $format) |
---|
1482 | { |
---|
1483 | $format = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] . ' - '; |
---|
1484 | if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12') |
---|
1485 | { |
---|
1486 | $format .= 'h:i a'; |
---|
1487 | } |
---|
1488 | else |
---|
1489 | { |
---|
1490 | $format .= 'H:i'; |
---|
1491 | } |
---|
1492 | } |
---|
1493 | if((PHP_OS == 'Windows' || PHP_OS == 'WINNT') && (int)$t < 21600) |
---|
1494 | /*if(PHP_OS == 'Windows' && (int)$t < 21600)*/ |
---|
1495 | { |
---|
1496 | $t = 21600; |
---|
1497 | } |
---|
1498 | return date($format,$t); |
---|
1499 | } |
---|
1500 | |
---|
1501 | /*! |
---|
1502 | @function dateformatorder |
---|
1503 | @abstract |
---|
1504 | @param $yearstr year - string |
---|
1505 | @param $monthstr month - string |
---|
1506 | @param $day day - string |
---|
1507 | @param $add_seperator boolean defaults to false |
---|
1508 | */ |
---|
1509 | function dateformatorder($yearstr,$monthstr,$daystr,$add_seperator = False) |
---|
1510 | { |
---|
1511 | $dateformat = strtolower($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']); |
---|
1512 | $sep = substr($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],1,1); |
---|
1513 | |
---|
1514 | $dlarr[strpos($dateformat,'y')] = $yearstr; |
---|
1515 | $dlarr[strpos($dateformat,'m')] = $monthstr; |
---|
1516 | $dlarr[strpos($dateformat,'d')] = $daystr; |
---|
1517 | ksort($dlarr); |
---|
1518 | |
---|
1519 | if ($add_seperator) |
---|
1520 | { |
---|
1521 | return (implode($sep,$dlarr)); |
---|
1522 | } |
---|
1523 | else |
---|
1524 | { |
---|
1525 | return (implode(' ',$dlarr)); |
---|
1526 | } |
---|
1527 | } |
---|
1528 | |
---|
1529 | /*! |
---|
1530 | @function formattime |
---|
1531 | @abstract format the time takes settings from user preferences |
---|
1532 | @param $hour hour |
---|
1533 | @param $min minutes |
---|
1534 | @param $sec defaults to '' |
---|
1535 | */ |
---|
1536 | function formattime($hour,$min,$sec='') |
---|
1537 | { |
---|
1538 | $h12 = $hour; |
---|
1539 | if ($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12') |
---|
1540 | { |
---|
1541 | if ($hour >= 12) |
---|
1542 | { |
---|
1543 | $ampm = ' pm'; |
---|
1544 | } |
---|
1545 | else |
---|
1546 | { |
---|
1547 | $ampm = ' am'; |
---|
1548 | } |
---|
1549 | |
---|
1550 | $h12 %= 12; |
---|
1551 | |
---|
1552 | if ($h12 == 0 && $hour) |
---|
1553 | { |
---|
1554 | $h12 = 12; |
---|
1555 | } |
---|
1556 | if ($h12 == 0 && !$hour) |
---|
1557 | { |
---|
1558 | $h12 = 0; |
---|
1559 | } |
---|
1560 | } |
---|
1561 | else |
---|
1562 | { |
---|
1563 | $h12 = $hour; |
---|
1564 | } |
---|
1565 | |
---|
1566 | if ($sec !== '') |
---|
1567 | { |
---|
1568 | $sec = ":$sec"; |
---|
1569 | } |
---|
1570 | |
---|
1571 | return "$h12:$min$sec$ampm"; |
---|
1572 | } |
---|
1573 | |
---|
1574 | // This is not the best place for it, but it needs to be shared bewteen Aeromail and SM |
---|
1575 | /*! |
---|
1576 | @function get_email_passwd_ex |
---|
1577 | @abstract uses code in /email class msg to obtain the appropriate password for email |
---|
1578 | @param (none - it will abtain the info it needs on its own) |
---|
1579 | */ |
---|
1580 | /* |
---|
1581 | function get_email_passwd_ex() |
---|
1582 | { |
---|
1583 | // ---- Create the email Message Class if needed ----- |
---|
1584 | if (is_object($GLOBALS['phpgw']->msg)) |
---|
1585 | { |
---|
1586 | $do_free_me = False; |
---|
1587 | } |
---|
1588 | else |
---|
1589 | { |
---|
1590 | $GLOBALS['phpgw']->msg = CreateObject('email.mail_msg'); |
---|
1591 | $do_free_me = True; |
---|
1592 | } |
---|
1593 | // use the Msg class to obtain the appropriate password |
---|
1594 | $tmp_prefs = $GLOBALS['phpgw']->preferences->read(); |
---|
1595 | if (!isset($tmp_prefs['email']['passwd'])) |
---|
1596 | { |
---|
1597 | $email_passwd = $GLOBALS['phpgw_info']['user']['passwd']; |
---|
1598 | } |
---|
1599 | else |
---|
1600 | { |
---|
1601 | $email_passwd = $GLOBALS['phpgw']->msg->decrypt_email_passwd($tmp_prefs['email']['passwd']); |
---|
1602 | } |
---|
1603 | // cleanup and return |
---|
1604 | if ($do_free_me) |
---|
1605 | { |
---|
1606 | unset ($GLOBALS['phpgw']->msg); |
---|
1607 | } |
---|
1608 | return $email_passwd; |
---|
1609 | } |
---|
1610 | */ |
---|
1611 | |
---|
1612 | // This is not the best place for it, but it needs to be shared bewteen Aeromail and SM |
---|
1613 | /*! |
---|
1614 | @function create_emailpreferences |
---|
1615 | @abstract create email preferences |
---|
1616 | @discussion This is not the best place for it, but it needs to be shared between Aeromail and SM |
---|
1617 | @param $prefs |
---|
1618 | @param $account_id -optional defaults to : phpgw_info['user']['account_id'] |
---|
1619 | */ |
---|
1620 | function create_emailpreferences($prefs='',$accountid='') |
---|
1621 | { |
---|
1622 | return $GLOBALS['phpgw']->preferences->create_email_preferences($accountid); |
---|
1623 | // ---- Create the email Message Class if needed ----- |
---|
1624 | if (is_object($GLOBALS['phpgw']->msg)) |
---|
1625 | { |
---|
1626 | $do_free_me = False; |
---|
1627 | } |
---|
1628 | else |
---|
1629 | { |
---|
1630 | $GLOBALS['phpgw']->msg = CreateObject('email.mail_msg'); |
---|
1631 | $do_free_me = True; |
---|
1632 | } |
---|
1633 | |
---|
1634 | // this sets the preferences into the phpgw_info structure |
---|
1635 | $GLOBALS['phpgw']->msg->create_email_preferences(); |
---|
1636 | |
---|
1637 | // cleanup and return |
---|
1638 | if ($do_free_me) |
---|
1639 | { |
---|
1640 | unset ($GLOBALS['phpgw']->msg); |
---|
1641 | } |
---|
1642 | } |
---|
1643 | |
---|
1644 | /* |
---|
1645 | function create_emailpreferences($prefs,$accountid='') |
---|
1646 | { |
---|
1647 | $account_id = get_account_id($accountid); |
---|
1648 | |
---|
1649 | // NEW EMAIL PASSWD METHOD (shared between SM and aeromail) |
---|
1650 | $prefs['email']['passwd'] = $this->get_email_passwd_ex(); |
---|
1651 | |
---|
1652 | // Add default preferences info |
---|
1653 | if (!isset($prefs['email']['userid'])) |
---|
1654 | { |
---|
1655 | if ($GLOBALS['phpgw_info']['server']['mail_login_type'] == 'vmailmgr') |
---|
1656 | { |
---|
1657 | $prefs['email']['userid'] = $GLOBALS['phpgw']->accounts->id2name($account_id) |
---|
1658 | . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']; |
---|
1659 | } |
---|
1660 | else |
---|
1661 | { |
---|
1662 | $prefs['email']['userid'] = $GLOBALS['phpgw']->accounts->id2name($account_id); |
---|
1663 | } |
---|
1664 | } |
---|
1665 | // Set Server Mail Type if not defined |
---|
1666 | if (empty($GLOBALS['phpgw_info']['server']['mail_server_type'])) |
---|
1667 | { |
---|
1668 | $GLOBALS['phpgw_info']['server']['mail_server_type'] = 'imap'; |
---|
1669 | } |
---|
1670 | |
---|
1671 | // OLD EMAIL PASSWD METHOD |
---|
1672 | if (!isset($prefs['email']['passwd'])) |
---|
1673 | { |
---|
1674 | $prefs['email']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; |
---|
1675 | } |
---|
1676 | else |
---|
1677 | { |
---|
1678 | $prefs['email']['passwd'] = $this->decrypt($prefs['email']['passwd']); |
---|
1679 | } |
---|
1680 | // NEW EMAIL PASSWD METHOD Located at the begining of this function |
---|
1681 | |
---|
1682 | if (!isset($prefs['email']['address'])) |
---|
1683 | { |
---|
1684 | $prefs['email']['address'] = $GLOBALS['phpgw']->accounts->id2name($account_id) |
---|
1685 | . '@' . $GLOBALS['phpgw_info']['server']['mail_suffix']; |
---|
1686 | } |
---|
1687 | if (!isset($prefs['email']['mail_server'])) |
---|
1688 | { |
---|
1689 | $prefs['email']['mail_server'] = $GLOBALS['phpgw_info']['server']['mail_server']; |
---|
1690 | } |
---|
1691 | if (!isset($prefs['email']['mail_server_type'])) |
---|
1692 | { |
---|
1693 | $prefs['email']['mail_server_type'] = $GLOBALS['phpgw_info']['server']['mail_server_type']; |
---|
1694 | } |
---|
1695 | if (!isset($prefs['email']['imap_server_type'])) |
---|
1696 | { |
---|
1697 | $prefs['email']['imap_server_type'] = $GLOBALS['phpgw_info']['server']['imap_server_type']; |
---|
1698 | } |
---|
1699 | // These sets the mail_port server variable |
---|
1700 | if ($prefs['email']['mail_server_type']=='imap') |
---|
1701 | { |
---|
1702 | $prefs['email']['mail_port'] = '143'; |
---|
1703 | } |
---|
1704 | elseif ($prefs['email']['mail_server_type']=='pop3') |
---|
1705 | { |
---|
1706 | $prefs['email']['mail_port'] = '110'; |
---|
1707 | } |
---|
1708 | elseif ($prefs['email']['mail_server_type']=='imaps') |
---|
1709 | { |
---|
1710 | $prefs['email']['mail_port'] = '993'; |
---|
1711 | } |
---|
1712 | elseif ($prefs['email']['mail_server_type']=='pop3s') |
---|
1713 | { |
---|
1714 | $prefs['email']['mail_port'] = '995'; |
---|
1715 | } |
---|
1716 | // This is going to be used to switch to the nntp class |
---|
1717 | if (isset($phpgw_info['flags']['newsmode']) && |
---|
1718 | $GLOBALS['phpgw_info']['flags']['newsmode']) |
---|
1719 | { |
---|
1720 | $prefs['email']['mail_server_type'] = 'nntp'; |
---|
1721 | } |
---|
1722 | // DEBUG |
---|
1723 | //echo "<br>prefs['email']['passwd']: " .$prefs['email']['passwd'] .'<br>'; |
---|
1724 | return $prefs; |
---|
1725 | } |
---|
1726 | */ |
---|
1727 | |
---|
1728 | // This will be moved into the applications area. |
---|
1729 | /*! |
---|
1730 | @function check_code |
---|
1731 | @abstract ? |
---|
1732 | @discussion This will be moved into the applications area |
---|
1733 | */ |
---|
1734 | function check_code($code) |
---|
1735 | { |
---|
1736 | $s = '<br>'; |
---|
1737 | switch ($code) |
---|
1738 | { |
---|
1739 | case 13: $s .= lang('Your message has been sent');break; |
---|
1740 | case 14: $s .= lang('New entry added sucessfully');break; |
---|
1741 | case 15: $s .= lang('Entry updated sucessfully'); break; |
---|
1742 | case 16: $s .= lang('Entry has been deleted sucessfully'); break; |
---|
1743 | case 18: $s .= lang('Password has been updated'); break; |
---|
1744 | case 38: $s .= lang('Password could not be changed'); break; |
---|
1745 | case 19: $s .= lang('Session has been killed'); break; |
---|
1746 | case 27: $s .= lang('Account has been updated'); break; |
---|
1747 | case 28: $s .= lang('Account has been created'); break; |
---|
1748 | case 29: $s .= lang('Account has been deleted'); break; |
---|
1749 | case 30: $s .= lang('Your settings have been updated'); break; |
---|
1750 | case 31: $s .= lang('Group has been added'); break; |
---|
1751 | case 32: $s .= lang('Group has been deleted'); break; |
---|
1752 | case 33: $s .= lang('Group has been updated'); break; |
---|
1753 | case 34: $s .= lang('Account has been deleted') . '<p>' |
---|
1754 | . lang('Error deleting %1 %2 directory',lang('users'),' '.lang('private').' ') |
---|
1755 | . ',<br>' . lang('Please %1 by hand',lang('delete')) . '<br><br>' |
---|
1756 | . lang('To correct this error for the future you will need to properly set the') |
---|
1757 | . '<br>' . lang('permissions to the files/users directory') |
---|
1758 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1759 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/'); |
---|
1760 | break; |
---|
1761 | case 35: $s .= lang('Account has been updated') . '<p>' |
---|
1762 | . lang('Error renaming %1 %2 directory',lang('users'), |
---|
1763 | ' '.lang('private').' ') |
---|
1764 | . ',<br>' . lang('Please %1 by hand', |
---|
1765 | lang('rename')) . '<br><br>' |
---|
1766 | . lang('To correct this error for the future you will need to properly set the') |
---|
1767 | . '<br>' . lang('permissions to the files/users directory') |
---|
1768 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1769 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/'); |
---|
1770 | break; |
---|
1771 | case 36: $s .= lang('Account has been created') . '<p>' |
---|
1772 | . lang('Error creating %1 %2 directory',lang('users'), |
---|
1773 | ' '.lang('private').' ') |
---|
1774 | . ',<br>' . lang('Please %1 by hand', |
---|
1775 | lang('create')) . '<br><br>' |
---|
1776 | . lang('To correct this error for the future you will need to properly set the') |
---|
1777 | . '<br>' . lang('permissions to the files/users directory') |
---|
1778 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1779 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/users/'); |
---|
1780 | break; |
---|
1781 | case 37: $s .= lang('Group has been added') . '<p>' |
---|
1782 | . lang('Error creating %1 %2 directory',lang('groups'),' ') |
---|
1783 | . ',<br>' . lang('Please %1 by hand', |
---|
1784 | lang('create')) . '<br><br>' |
---|
1785 | . lang('To correct this error for the future you will need to properly set the') |
---|
1786 | . '<br>' . lang('permissions to the files/users directory') |
---|
1787 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1788 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/'); |
---|
1789 | break; |
---|
1790 | case 38: $s .= lang('Group has been deleted') . '<p>' |
---|
1791 | . lang('Error deleting %1 %2 directory',lang('groups'),' ') |
---|
1792 | . ',<br>' . lang('Please %1 by hand', |
---|
1793 | lang('delete')) . '<br><br>' |
---|
1794 | . lang('To correct this error for the future you will need to properly set the') |
---|
1795 | . '<br>' . lang('permissions to the files/users directory') |
---|
1796 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1797 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/'); |
---|
1798 | break; |
---|
1799 | case 39: $s .= lang('Group has been updated') . '<p>' |
---|
1800 | . lang('Error renaming %1 %2 directory',lang('groups'),' ') |
---|
1801 | . ',<br>' . lang('Please %1 by hand', |
---|
1802 | lang('rename')) . '<br><br>' |
---|
1803 | . lang('To correct this error for the future you will need to properly set the') |
---|
1804 | . '<br>' . lang('permissions to the files/users directory') |
---|
1805 | . '<br>' . lang('On *nix systems please type: %1','chmod 770 ' |
---|
1806 | . $GLOBALS['phpgw_info']['server']['files_dir'] . '/groups/'); |
---|
1807 | break; |
---|
1808 | case 40: $s .= lang('You have not entered a title').'.'; |
---|
1809 | break; |
---|
1810 | case 41: $s .= lang('You have not entered a valid time of day').'.'; |
---|
1811 | break; |
---|
1812 | case 42: $s .= lang('You have not entered a valid date').'.'; |
---|
1813 | break; |
---|
1814 | case 43: $s .= lang('You have not entered participants').'.'; |
---|
1815 | break; |
---|
1816 | default: return ''; |
---|
1817 | } |
---|
1818 | return $s; |
---|
1819 | } |
---|
1820 | /*! |
---|
1821 | @function phpgw_error |
---|
1822 | @abstract process error message |
---|
1823 | @param $error error |
---|
1824 | @param $line line |
---|
1825 | @param $file file |
---|
1826 | */ |
---|
1827 | function phpgw_error($error,$line = '', $file = '') |
---|
1828 | { |
---|
1829 | echo '<p><b>phpGroupWare internal error:</b><p>'.$error; |
---|
1830 | if ($line) |
---|
1831 | { |
---|
1832 | echo 'Line: '.$line; |
---|
1833 | } |
---|
1834 | if ($file) |
---|
1835 | { |
---|
1836 | echo 'File: '.$file; |
---|
1837 | } |
---|
1838 | echo '<p>Your session has been halted.'; |
---|
1839 | exit; |
---|
1840 | } |
---|
1841 | |
---|
1842 | /*! |
---|
1843 | @function create_phpcode_from_array |
---|
1844 | @abstract create phpcode from array |
---|
1845 | @param $array - array |
---|
1846 | */ |
---|
1847 | function create_phpcode_from_array($array) |
---|
1848 | { |
---|
1849 | while (list($key, $val) = each($array)) |
---|
1850 | { |
---|
1851 | if (is_array($val)) |
---|
1852 | { |
---|
1853 | while (list($key2, $val2) = each($val)) |
---|
1854 | { |
---|
1855 | if (is_array($val2)) |
---|
1856 | { |
---|
1857 | while (list($key3, $val3) = each ($val2)) |
---|
1858 | { |
---|
1859 | if (is_array($val3)) |
---|
1860 | { |
---|
1861 | while (list($key4, $val4) = each ($val3)) |
---|
1862 | { |
---|
1863 | $s .= '$phpgw_info["' . $key . '"]["' . $key2 . '"]["' . $key3 . '"]["' .$key4 . '"]="' . $val4 . '";'; |
---|
1864 | $s .= "\n"; |
---|
1865 | } |
---|
1866 | } |
---|
1867 | else |
---|
1868 | { |
---|
1869 | $s .= '$phpgw_info["' . $key . '"]["' . $key2 . '"]["' . $key3 . '"]="' . $val3 . '";'; |
---|
1870 | $s .= "\n"; |
---|
1871 | } |
---|
1872 | } |
---|
1873 | } |
---|
1874 | else |
---|
1875 | { |
---|
1876 | $s .= '$phpgw_info["' . $key .'"]["' . $key2 . '"]="' . $val2 . '";'; |
---|
1877 | $s .= "\n"; |
---|
1878 | } |
---|
1879 | } |
---|
1880 | } |
---|
1881 | else |
---|
1882 | { |
---|
1883 | $s .= '$phpgw_info["' . $key . '"]="' . $val . '";'; |
---|
1884 | $s .= "\n"; |
---|
1885 | } |
---|
1886 | } |
---|
1887 | return $s; |
---|
1888 | } |
---|
1889 | |
---|
1890 | // This will return the full phpgw_info array, used for debugging |
---|
1891 | /*! |
---|
1892 | @function debug_list_array_contents |
---|
1893 | @abstract return the full phpgw_info array for debugging |
---|
1894 | @param array - array |
---|
1895 | */ |
---|
1896 | function debug_list_array_contents($array) |
---|
1897 | { |
---|
1898 | while (list($key, $val) = each($array)) |
---|
1899 | { |
---|
1900 | if (is_array($val)) |
---|
1901 | { |
---|
1902 | while (list($key2, $val2) = each($val)) |
---|
1903 | { |
---|
1904 | if (is_array($val2)) |
---|
1905 | { |
---|
1906 | while (list($key3, $val3) = each ($val2)) |
---|
1907 | { |
---|
1908 | if (is_array($val3)) |
---|
1909 | { |
---|
1910 | while (list($key4, $val4) = each ($val3)) |
---|
1911 | { |
---|
1912 | echo $$array . "[$key][$key2][$key3][$key4]=$val4<br>"; |
---|
1913 | } |
---|
1914 | } |
---|
1915 | else |
---|
1916 | { |
---|
1917 | echo $$array . "[$key][$key2][$key3]=$val3<br>"; |
---|
1918 | } |
---|
1919 | } |
---|
1920 | } |
---|
1921 | else |
---|
1922 | { |
---|
1923 | echo $$array . "[$key][$key2]=$val2<br>"; |
---|
1924 | } |
---|
1925 | } |
---|
1926 | } |
---|
1927 | else |
---|
1928 | { |
---|
1929 | echo $$array . "[$key]=$val<br>"; |
---|
1930 | } |
---|
1931 | } |
---|
1932 | } |
---|
1933 | |
---|
1934 | // This will return a list of functions in the API |
---|
1935 | /*! |
---|
1936 | @function debug_list_core_functions |
---|
1937 | @abstract return a list of functionsin the API |
---|
1938 | */ |
---|
1939 | function debug_list_core_functions() |
---|
1940 | { |
---|
1941 | echo '<br><b>core functions</b><br>'; |
---|
1942 | echo '<pre>'; |
---|
1943 | chdir(PHPGW_INCLUDE_ROOT . '/phpgwapi'); |
---|
1944 | system("grep -r '^[ \t]*function' *"); |
---|
1945 | echo '</pre>'; |
---|
1946 | } |
---|
1947 | |
---|
1948 | // This will return a value for the next id an app/class may need to insert values into ldap. |
---|
1949 | /*! |
---|
1950 | @function next_id |
---|
1951 | @abstract return the next higher value for an integer, and increment it in the db. |
---|
1952 | */ |
---|
1953 | function next_id($appname,$min=0,$max=0) |
---|
1954 | { |
---|
1955 | if (!$appname) |
---|
1956 | { |
---|
1957 | return -1; |
---|
1958 | } |
---|
1959 | |
---|
1960 | $GLOBALS['phpgw']->db->query("SELECT id FROM phpgw_nextid WHERE appname='".$appname."'",__LINE__,__FILE__); |
---|
1961 | while( $GLOBALS['phpgw']->db->next_record() ) |
---|
1962 | { |
---|
1963 | $id = $GLOBALS['phpgw']->db->f('id'); |
---|
1964 | } |
---|
1965 | |
---|
1966 | if (empty($id) || !$id) |
---|
1967 | { |
---|
1968 | $id = 1; |
---|
1969 | $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_nextid (appname,id) VALUES ('".$appname."',".$id.")",__LINE__,__FILE__); |
---|
1970 | } |
---|
1971 | elseif($id<$min) |
---|
1972 | { |
---|
1973 | $id = $min; |
---|
1974 | $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__); |
---|
1975 | } |
---|
1976 | elseif ($max && ($id > $max)) |
---|
1977 | { |
---|
1978 | return False; |
---|
1979 | } |
---|
1980 | else |
---|
1981 | { |
---|
1982 | $id = $id + 1; |
---|
1983 | $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__); |
---|
1984 | } |
---|
1985 | |
---|
1986 | return (int)$id; |
---|
1987 | } |
---|
1988 | |
---|
1989 | // This will return a value for the last id entered, which an app may need to check |
---|
1990 | // values for ldap. |
---|
1991 | /*! |
---|
1992 | @function last_id |
---|
1993 | @abstract return the current id in the next_id table for a particular app/class. |
---|
1994 | */ |
---|
1995 | function last_id($appname,$min=0,$max=0) |
---|
1996 | { |
---|
1997 | if (!$appname) |
---|
1998 | { |
---|
1999 | return -1; |
---|
2000 | } |
---|
2001 | |
---|
2002 | $GLOBALS['phpgw']->db->query("SELECT id FROM phpgw_nextid WHERE appname='".$appname."'",__LINE__,__FILE__); |
---|
2003 | while( $GLOBALS['phpgw']->db->next_record() ) |
---|
2004 | { |
---|
2005 | $id = $GLOBALS['phpgw']->db->f('id'); |
---|
2006 | } |
---|
2007 | |
---|
2008 | if (empty($id) || !$id) |
---|
2009 | { |
---|
2010 | if($min) |
---|
2011 | { |
---|
2012 | $id = $min; |
---|
2013 | } |
---|
2014 | else |
---|
2015 | { |
---|
2016 | $id = 1; |
---|
2017 | } |
---|
2018 | $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_nextid (appname,id) VALUES ('".$appname."',".$id.")",__LINE__,__FILE__); |
---|
2019 | } |
---|
2020 | elseif($id<$min) |
---|
2021 | { |
---|
2022 | $id = $min; |
---|
2023 | $GLOBALS['phpgw']->db->query("UPDATE phpgw_nextid SET id=".$id." WHERE appname='".$appname."'",__LINE__,__FILE__); |
---|
2024 | } |
---|
2025 | elseif ($max && ($id > $max)) |
---|
2026 | { |
---|
2027 | return False; |
---|
2028 | } |
---|
2029 | return (int)$id; |
---|
2030 | } |
---|
2031 | }//end common class |
---|