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