| | |
| | | | program/include/main.inc | |
| | | | | |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2009, Roundcube Dev, - Switzerland | |
| | | | Copyright (C) 2005-2009, The Roundcube Dev Team | |
| | | | Licensed under the GNU GPL | |
| | | | | |
| | | | PURPOSE: | |
| | |
| | | |
| | | // format each col |
| | | foreach ($a_show_cols as $col) |
| | | $table->add($col, Q($row_data[$col])); |
| | | $table->add($col, Q(is_array($row_data[$col]) ? $row_data[$col][0] : $row_data[$col])); |
| | | |
| | | $c++; |
| | | } |
| | |
| | | * @return string HTML field definition |
| | | */ |
| | | function rcmail_get_edit_field($col, $value, $attrib, $type='text') |
| | | { |
| | | $fname = '_'.$col; |
| | | $attrib['name'] = $fname; |
| | | { |
| | | static $colcounts = array(); |
| | | |
| | | if ($type=='checkbox') |
| | | { |
| | | $fname = '_'.$col; |
| | | $attrib['name'] = $fname . ($attrib['array'] ? '[]' : ''); |
| | | $attrib['class'] = trim($attrib['class'] . ' ff_' . $col); |
| | | |
| | | if ($type == 'checkbox') { |
| | | $attrib['value'] = '1'; |
| | | $input = new html_checkbox($attrib); |
| | | } |
| | | else if ($type=='textarea') |
| | | { |
| | | } |
| | | else if ($type == 'textarea') { |
| | | $attrib['cols'] = $attrib['size']; |
| | | $input = new html_textarea($attrib); |
| | | } |
| | | else |
| | | } |
| | | else if ($type == 'select') { |
| | | $input = new html_select($attrib); |
| | | $input->add('---', ''); |
| | | $input->add(array_values($attrib['options']), array_keys($attrib['options'])); |
| | | } |
| | | else { |
| | | if ($attrib['type'] != 'text' && $attrib['type'] != 'hidden') |
| | | $attrib['type'] = 'text'; |
| | | $input = new html_inputfield($attrib); |
| | | } |
| | | |
| | | // use value from post |
| | | if (!empty($_POST[$fname])) |
| | | $value = get_input_value($fname, RCUBE_INPUT_POST, |
| | | $type == 'textarea' && strpos($attrib['class'], 'mce_editor')!==false ? true : false); |
| | | if (isset($_POST[$fname])) { |
| | | $postvalue = get_input_value($fname, RCUBE_INPUT_POST, |
| | | $type == 'textarea' && strpos($attrib['class'], 'mce_editor')!==false ? true : false); |
| | | $value = $attrib['array'] ? $postvalue[intval($colcounts[$col]++)] : $postvalue; |
| | | } |
| | | |
| | | $out = $input->show($value); |
| | | |
| | | |
| | | return $out; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | |
| | | /** |
| | | * Improved equivalent to strtotime() |
| | | * |
| | | * @param string Date string |
| | | * @return int |
| | | */ |
| | | function rcube_strtotime($date) |
| | | { |
| | | // check for MS Outlook vCard date format YYYYMMDD |
| | | if (preg_match('/^([12][90]\d\d)([01]\d)(\d\d)$/', trim($date), $matches)) { |
| | | return mktime(0,0,0, intval($matches[2]), intval($matches[3]), intval($matches[1])); |
| | | } |
| | | else if (is_numeric($date)) |
| | | return $date; |
| | | |
| | | // support non-standard "GMTXXXX" literal |
| | | $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); |
| | | |
| | | // if date parsing fails, we have a date in non-rfc format. |
| | | // remove token from the end and try again |
| | | while ((($ts = @strtotime($date)) === false) || ($ts < 0)) { |
| | | $d = explode(' ', $date); |
| | | array_pop($d); |
| | | if (!$d) break; |
| | | $date = implode(' ', $d); |
| | | } |
| | | |
| | | return $ts; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Convert the given date to a human readable form |
| | | * This uses the date formatting properties from config |
| | | * |
| | |
| | | |
| | | $ts = NULL; |
| | | |
| | | if (is_numeric($date)) |
| | | $ts = $date; |
| | | else if (!empty($date)) |
| | | { |
| | | // support non-standard "GMTXXXX" literal |
| | | $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); |
| | | // if date parsing fails, we have a date in non-rfc format. |
| | | // remove token from the end and try again |
| | | while ((($ts = @strtotime($date))===false) || ($ts < 0)) |
| | | { |
| | | $d = explode(' ', $date); |
| | | array_pop($d); |
| | | if (!$d) break; |
| | | $date = implode(' ', $d); |
| | | } |
| | | } |
| | | if (!empty($date)) |
| | | $ts = rcube_strtotime($date); |
| | | |
| | | if (empty($ts)) |
| | | return ''; |
| | |
| | | if (!$RCMAIL->config->get('log_logins') || !$RCMAIL->user) |
| | | return; |
| | | |
| | | $address = $_SERVER['REMOTE_ADDR']; |
| | | // append the NGINX X-Real-IP header, if set |
| | | if (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
| | | $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; |
| | | } |
| | | // append the X-Forwarded-For header, if set |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| | | $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; |
| | | } |
| | | |
| | | if (!empty($remote_ip)) |
| | | $address .= '(' . implode(',', $remote_ip) . ')'; |
| | | |
| | | write_log('userlogins', sprintf('Successful login for %s (ID: %d) from %s', |
| | | $RCMAIL->user->get_username(), $RCMAIL->user->ID, $address)); |
| | | $RCMAIL->user->get_username(), $RCMAIL->user->ID, rcmail_remote_ip())); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns remote IP address and forwarded addresses if found |
| | | * |
| | | * @return string Remote IP address(es) |
| | | */ |
| | | function rcmail_remote_ip() |
| | | { |
| | | $address = $_SERVER['REMOTE_ADDR']; |
| | | |
| | | // append the NGINX X-Real-IP header, if set |
| | | if (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
| | | $remote_ip[] = 'X-Real-IP: ' . $_SERVER['HTTP_X_REAL_IP']; |
| | | } |
| | | // append the X-Forwarded-For header, if set |
| | | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| | | $remote_ip[] = 'X-Forwarded-For: ' . $_SERVER['HTTP_X_FORWARDED_FOR']; |
| | | } |
| | | |
| | | if (!empty($remote_ip)) |
| | | $address .= '(' . implode(',', $remote_ip) . ')'; |
| | | |
| | | return $address; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | return microtime(true); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @access private |
| | |
| | | $classes[] = 'unread'; |
| | | |
| | | $js_name = JQ($folder['id']); |
| | | $html_name = Q($foldername . ($unread ? " ($unread)" : '')); |
| | | $html_name = Q($foldername) . ($unread ? html::span('unreadcount', " ($unread)") : ''); |
| | | $link_attrib = $folder['virtual'] ? array() : array( |
| | | 'href' => rcmail_url('', array('_mbox' => $folder['id'])), |
| | | 'onclick' => sprintf("return %s.command('list','%s',this)", JS_OBJECT_NAME, $js_name), |
| | |
| | | |
| | | |
| | | /** |
| | | * Outputs error message according to server error/response codes |
| | | * |
| | | * @param string Fallback message label |
| | | * @param string Fallback message label arguments |
| | | * |
| | | * @return void |
| | | */ |
| | | function rcmail_display_server_error($fallback=null, $fallback_args=null) |
| | | { |
| | | global $RCMAIL; |
| | | |
| | | $err_code = $RCMAIL->imap->get_error_code(); |
| | | $res_code = $RCMAIL->imap->get_response_code(); |
| | | |
| | | if ($res_code == rcube_imap::NOPERM) { |
| | | $RCMAIL->output->show_message('errornoperm', 'error'); |
| | | } |
| | | else if ($res_code == rcube_imap::READONLY) { |
| | | $RCMAIL->output->show_message('errorreadonly', 'error'); |
| | | } |
| | | else if ($err_code && ($err_str = $RCMAIL->imap->get_error_str())) { |
| | | $RCMAIL->output->show_message('servererrormsg', 'error', array('msg' => $err_str)); |
| | | } |
| | | else if ($fallback) { |
| | | $RCMAIL->output->show_message($fallback, 'error', $fallback_args); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Output HTML editor scripts |
| | | * |
| | | * @param string Editor mode |
| | |
| | | ':-(' => 'smiley-frown', |
| | | ':-D' => 'smiley-laughing', |
| | | ':-)' => 'smiley-smile', |
| | | ':-/' => 'smiley-undecided', |
| | | ':-X' => 'smiley-embarassed', |
| | | '0:-)' => 'smiley-innocent', |
| | | ':-S' => 'smiley-undecided', |
| | | ':-$' => 'smiley-embarassed', |
| | | 'O:-)' => 'smiley-innocent', |
| | | ':-|' => 'smiley-money-mouth', |
| | | ':-0' => 'smiley-surprised', |
| | | ':-O' => 'smiley-surprised', |
| | | ';-)' => 'smiley-wink', |
| | | ); |
| | | |
| | |
| | | * Replaces hostname variables |
| | | * |
| | | * @param string $name Hostname |
| | | * @param string $host Optional IMAP hostname |
| | | * @return string |
| | | */ |
| | | function rcube_parse_host($name) |
| | | function rcube_parse_host($name, $host='') |
| | | { |
| | | // %n - host |
| | | $n = preg_replace('/:\d+$/', '', $_SERVER['SERVER_NAME']); |
| | | // %d - domain name without first part, e.g. %d=mail.domain.tld, %m=domain.tld |
| | | $d = preg_replace('/^[^\.]+\./', '', $n); |
| | | // %h - IMAP host |
| | | $h = $_SESSION['imap_host']; |
| | | $h = $_SESSION['imap_host'] ? $_SESSION['imap_host'] : $host; |
| | | // %z - IMAP domain without first part, e.g. %h=imap.domain.tld, %z=domain.tld |
| | | $z = preg_replace('/^[^\.]+\./', '', $h); |
| | | |