/** * Read txt file in specified language mutation, parse and saparate to headers and body and do replacements. * * For more info about choice txt file read {@link multidomain_get_lang_file} * Txt files in serweb (as emails, terms and conditions etc.) are stored in * special format. At the beginning (but only at beginning) of these files may * be comments. Lines with comments begins by "#". Rest of file is separated * into two parts separated by empty line: headers and body. * * Each header contain header name and header value. Each header must be on * own line. Header name and header value is separated by ":". * * Body is the rest of txt file after first empty line. * * When txt file is readed, function replace all strings in form #@#some_name#@# * by replacement. The parametr $replacements is array of pairs. First element * of each pair is name of replacement and second element from pair is value * by which is replaced. * * Function's finding replacements in body and in header values. * * Function return array with two keys: "headers" and "body". Body is only * string. Headers contain associative array with header names as keys. * * @param string $filename name of file is searching for * @param string $ddir subdirectory in of domain dir * @param string $lang language in "official" ISO 639 language code see {@link config_lang.php} for more info * @param array $replacements see above * @return array parsed file or false on error */ function read_lang_txt_file($filename, $ddir, $lang, $replacements) { $f = multidomain_get_lang_file($filename, $ddir, $lang); if (!$f) { sw_log("Can't find txt file " . $filename . ", subdir:" . $ddir . ", lang:" . $lang, PEAR_LOG_ERR); return false; } return read_txt_file($f, $replacements); }
/** * function sends missed calls of user to given email address * * @param string $uid * @param string $email_address * @return bool TRUE on success, FALSE on error */ function send_mail_with_missed_calls($uid, $email_address, $mail_from) { global $config, $data, $lang_set; /* get missed calls */ if (false === ($missed_calls = $data->get_missed_calls_of_yesterday($uid, null))) { return false; } if (!count($missed_calls)) { return true; } //there are no missed calls - nothing to do /* check if imap extension is loaded */ if (!function_exists('imap_mail_compose')) { ErrorHandler::add_errors("Can not send mail. IMAP extension for PHP is not installed."); return false; } /* * Create table of missed calls */ $table = '<html><body><table border="1" cellspacing="0" cellpadding="1">' . "\n"; $table .= '<tr>'; $table .= '<th>calling subscriber</th>'; $table .= '<th>time</th>'; $table .= '<th>reply status</th>'; $table .= '</tr>' . "\n"; foreach ($missed_calls as $row) { $table .= '<tr>'; $table .= '<td>' . $row->from_uri . ' </td>'; $table .= '<td>' . $row->request_timestamp . ' </td>'; $table .= '<td>' . $row->sip_status . ' </td>'; $table .= '</tr>' . "\n"; } $table .= '</table></body></html>' . "\n"; /* * Get language of user */ if (false === ($lang = Attributes::get_attribute($config->attr_names['lang'], array("uid" => $uid)))) { return false; } $lang = lang_detect($lang, 3); //translate $lang to be a index into $available_languages array if (!$lang) { $lang = $config->default_lang; } /* * Read file containing the mail body */ $mail_file = multidomain_get_lang_file("mail_missed_calls.txt", "txt", $lang); $m = read_txt_file($mail_file, array()); if ($m === false) { ErrorHandler::add_error("Can't read file with mail body."); return false; } /* get charset */ $charset = null; if (isset($m['headers']['content-type']) and eregi("charset=([-a-z0-9]+)", $m['headers']['content-type'], $regs)) { $charset = $regs[1]; } /* add information about charset to the header */ if ($charset) { $m['headers']['subject'] = "=?" . $charset . "?Q?" . imap_8bit($m['headers']['subject']) . "?="; } /* * Compose the mail message */ if ($mail_from) { $envelope["from"] = $mail_from; } else { $envelope["from"] = $config->mail_header_from; } $envelope["to"] = $email_address; $part1["type"] = TYPEMULTIPART; $part1["subtype"] = "mixed"; $part2["type"] = TYPETEXT; $part2["subtype"] = "plain"; $part2["contents.data"] = $m['body']; if ($charset) { $part2["charset"] = $charset; } $part3["type"] = TYPETEXT; $part3["subtype"] = "html"; $part3["contents.data"] = $table; $part3["charset"] = $lang_set['charset']; $body[1] = $part1; $body[2] = $part2; $body[3] = $part3; $mail = imap_mail_compose($envelope, $body); list($m_header, $m_body) = split("\r\n\r\n", $mail, 2); /* * Send mail */ if (!mail($email_address, $m['headers']['subject'], $m_body, $m_header)) { $errors[] = "can't send missed calls to " . $email_address; } return true; }
/** * create html form * * @param array $errors array with error messages * @return null FALSE on failure */ function create_html_form(&$errors) { global $available_languages; parent::create_html_form($errors); $file_content = ""; $kind = ""; if ($this->action['action'] == "edit_text_file" or $this->action['action'] == "edit_layout_file") { $kind = $this->action['action'] == "edit_text_file" ? "text" : "layout"; if ($this->opt['nr_backups']) { if (false === $this->get_versions($kind == "text", $errors)) { return false; } } $ds =& Domain_settings::singleton($this->domain_id, $this->get_filename($kind == "text"), $this->opt['nr_backups']); if (is_null($this->file_ver)) { if (false === ($ver = $ds->get_last_version())) { return false; } $this->file_ver = $ver; } if (false === ($file_content = $ds->get_file_content($this->file_ver))) { return false; } if (is_null($file_content) and $kind == "text") { $f = multidomain_get_lang_file($this->filename, "txt", $this->lang, "_default"); if (!empty($f)) { $fp = fopen($f, "r"); $file_content = fread($fp, 65536); fclose($fp); } } /* strip first line containing die() preventing this script from displaying throught http */ if (!empty($this->fileinfo['ini'])) { $first_eol = strpos($file_content, "\n"); $first_line = substr($file_content, 0, $first_eol); if (false !== strpos($first_line, "<?php die(")) { $file_content = substr($file_content, $first_eol); } } } $this->f->add_element(array("type" => "textarea", "name" => "dl_content", "rows" => 25, "cols" => 80, "value" => $file_content, "wrap" => "off")); $this->f->add_element(array("type" => "hidden", "name" => "dl_filename", "value" => $this->filename)); $this->f->add_element(array("type" => "hidden", "name" => "dl_kind_of_file", "value" => $kind)); $this->f->add_element(array("type" => "hidden", "name" => "dl_lang", "value" => $this->lang)); }