function save_xml_file($filename, $xml_file) { global $app_strings; $handle = fopen($filename, 'w'); //fwrite($handle,iconv("GBK","UTF-8",$xml_file)); if (!$handle) { return; } // Write $somecontent to our opened file.) if ($app_strings['LBL_CHARSET'] == "GBK") { if (function_exists('iconv')) { $xml_file = iconv_ec("GB2312", "UTF-8", $xml_file); } else { $chs = new Chinese("GBK", "UTF8", trim($xml_file)); $xml_file = $chs->ConvertIT(); } if (fwrite($handle, $xml_file) === FALSE) { return false; } } else { if ($app_strings['LBL_CHARSET'] != "UTF-8") { //$xml_file = iconv("ISO-8859-1","UTF-8",$xml_file); if (fwrite($handle, utf8_encode($xml_file)) === FALSE) { return false; } } else { if (fwrite($handle, $xml_file) === FALSE) { return false; } } } fclose($handle); return true; }
/** Function used to send email * $module -- current module * $to_email -- to email address * $from_name -- currently loggedin user name * $from_email -- currently loggedin ec_users's email id. you can give as '' if you are not in HelpDesk module * $subject -- subject of the email you want to send * $contents -- body of the email you want to send * $cc -- add email ids with comma seperated. - optional * $bcc -- add email ids with comma seperated. - optional. * $attachment -- whether we want to attach the currently selected file or all ec_files.[values = current,all] - optional * $emailid -- id of the email object which will be used to get the ec_attachments */ function send_webmail($module, $to_email, $from_name, $from_email, $subject, $contents, $cc = '', $bcc = '', $attachment = '', $emailid = '') { global $adb, $log; $log->debug("Entering send_webmail() method ..."); $smtphandle = new SMTPMailer(); if (!isset($_SESSION["MAILLIST_PLAINTEXT"])) { $smtphandle->UseHTML(1); // set email format to HTML $headertag = "<HEAD><META http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\"></HEAD>"; $contents = from_html($contents); $contents = eregi_replace('<BODY', $headertag . '<BODY', $contents); } $smtphandle->charset = 'GBK'; //convert UTF-8 to GBK $subject = iconv_ec("UTF-8", "GBK", $subject); $contents = iconv_ec("UTF-8", "GBK", $contents); $emailid = iconv_ec("UTF-8", "GBK", $emailid); //$from_email = ""; $smtphandle->subject = $subject; $smtphandle->body = $contents; $res = $adb->query("select * from ec_systems where server_type='email'"); $rownum = $adb->num_rows($res); if ($rownum == 0) { return "No Smtp Server!"; } $server = $adb->query_result($res, 0, 'server'); $username = $adb->query_result($res, 0, 'server_username'); $password = $adb->query_result($res, 0, 'server_password'); $smtp_auth = $adb->query_result($res, 0, 'smtp_auth'); $server_port = $adb->query_result($res, 0, 'server_port'); if ($from_email == '') { $from_email = $adb->query_result($res, 0, 'from_email'); } if ($from_name == '') { $from_name = $adb->query_result($res, 0, 'from_name'); } $from_name = iconv_ec("UTF-8", "GBK", $from_name); $from_email = iconv_ec("UTF-8", "GBK", $from_email); $smtphandle->SetHost($server, $server_port); $smtphandle->UseAuthLogin($username, $password); $smtphandle->SetFrom($from_email, $from_name); $smtphandle->AddReplyTo($from_email, $from_name); if ($to_email != '') { if (is_array($to_email)) { for ($j = 0, $num = count($to_email); $j < $num; $j++) { $smtphandle->AddTo($to_email[$j]); } } else { $_tmp = explode(",", $to_email); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { $smtphandle->AddTo($_tmp[$j]); } } } if ($cc != '') { if (is_array($cc)) { for ($j = 0, $num = count($cc); $j < $num; $j++) { $smtphandle->AddCc($cc[$j]); } } else { $_tmp = explode(",", $cc); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { $smtphandle->AddCc($_tmp[$j]); } } } if ($bcc != '') { if (is_array($bcc)) { for ($j = 0, $num = count($bcc); $j < $num; $j++) { $smtphandle->AddBcc($bcc[$j]); } } else { $_tmp = explode(",", $bcc); for ($j = 0, $num = count($_tmp); $j < $num; $j++) { $smtphandle->AddBcc($_tmp[$j]); } } } if ($attachment != "") { $query = "select * from ec_attachments where attachmentsid='" . $attachment . "'"; $result = $adb->query($query); $rownum = $adb->num_rows($result); if ($rownum > 0) { $attachmentsid = $adb->query_result($result, 0, 'attachmentsid'); $filename = $adb->query_result($result, 0, 'name'); $filename = iconv_ec("UTF-8", "GBK", $filename); $encode_filename = base64_encode_filename($adb->query_result($result, 0, 'name')); $filepath = $adb->query_result($result, 0, 'path'); $filetype = $adb->query_result($result, 0, 'type'); global $root_directory; $fullpath = $root_directory . $filepath . $attachmentsid . "_" . $encode_filename; $log->info("send_webmail :: fullpath:" . $fullpath); if (file_exists($fullpath)) { $attachment_status = $smtphandle->AddAttachment($fullpath, $filename, $filetype); if (!$attachment_status) { $log->info("send_webmail :: errormsg:" . $smtphandle->errormsg); } } } } $errMsg = ""; $sentmsg = $smtphandle->Send(); if ($sentmsg === false) { $errMsg = $smtphandle->errormsg . '<br>'; $log->info("send_webmail :: errormsg:" . $smtphandle->errormsg); } $log->debug("Exit send_webmail() method ..."); return $errMsg; }
function MSSQLMetaData($f) { $this->name = iconv_ec("GBK", "UTF-8", $f['Name']); $this->type = $this->realtype($f['Type']); }
$_SESSION['nick'] = ''; //echo "<script>window.close();</script>"; //echo "<script>location.href='index.php?module=$module&action=index';</script>"; } $top_appkey = $_GET['top_appkey']; $top_parameters = $_GET['top_parameters']; $top_session = $_GET['top_session']; $top_sign = $_GET['top_sign']; $md5 = md5($top_appkey . $top_parameters . $top_session . $appSecret, true); $sign = base64_encode($md5); if ($sign != $top_sign) { echo "signature invalid."; exit; } $parameters = array(); parse_str(base64_decode($top_parameters), $parameters); $now = time(); $ts = $parameters['ts'] / 1000; if ($ts > $now + 60 * 10 || $now > $ts + 60 * 30) { echo "request out of date."; exit; } $_SESSION['topsession'] = $_REQUEST['top_session']; $_SESSION['nick'] = iconv_ec("GBK", "UTF-8", $parameters['visitor_nick']); //Assign the entered global search string to a variable and display it again if (isset($_REQUEST['query_string']) && $_REQUEST['query_string'] != '') { $smarty->assign("QUERY_STRING", $_REQUEST['query_string']); } else { $smarty->assign("QUERY_STRING", $app_strings["LBL_SEARCH_STRING"]); } $smarty->display("Header.tpl");
<?php $skipped_rows = array(); $rows = array(); if (isset($_SESSION['skipped_rows_in_excel']) && $_SESSION['skipped_rows_in_excel'] != "") { $skipped_rows = $_SESSION['skipped_rows_in_excel']; } foreach ($skipped_rows as $rowKey => $row) { foreach ($row as $k => $v) { $row[$k] = iconv_ec("UTF-8", "GBK", $v); } $rows[$rowKey] = $row; } require_once "include/excel/excel_class.php"; $file_name = "Skipped.xls"; Create_Excel_File($file_name, $rows);
while ($row = $adb->fetch_array($result)) { $reportData .= "\"" . $for_i . "\""; $reportData .= ",\"" . $row['groupdate'] . "\""; if ($reporttyp == 'salesprice') { $totalsum = $row['totalsum']; $acctnum = $row['acctnum']; $salesrate = sprintf("%.2f", $totalsum / $acctnum); } else { $salesrate = $row['groupnum']; } $reportData .= ",\"" . $salesrate . "\""; $reportData .= "\r\n"; $sumtotalcols += $row['groupnum']; $for_i++; } } $reportData .= "\"\",\"小计\""; $reportData .= ",\"" . $sumtotalcols . "\""; $reportData .= "\r\n"; ob_clean(); header("Pragma: cache"); header("Content-type: application/octet-stream; charset=GBK"); header("Content-Disposition: attachment; filename={$_REQUEST['module']}.csv"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . strlen($reportData)); $reportData = iconv_ec("UTF-8", "GBK", $reportData); print $reportData; exit;
function send_webmail($to_email, $from_name, $from_email, $subject, $contents, $sjid = '') { ini_set('date.timezone', 'Asia/Shanghai'); global $adb, $log; global $current_user; $log->debug("Entering send_webmail() method ..."); $smtphandle = new SMTPMailer(); if (!isset($_SESSION["MAILLIST_PLAINTEXT"])) { $smtphandle->UseHTML(1); // set email format to HTML $headertag = "<HEAD><META http-equiv=\"Content-Type\" content=\"text/html; charset=GBK\"></HEAD>"; $contents = from_html($contents); $contents = eregi_replace('<BODY', $headertag . '<BODY', $contents); } $smtphandle->charset = 'GBK'; //convert UTF-8 to GBK $subject = iconv_ec("UTF-8", "GBK", $subject); $contents = iconv_ec("UTF-8", "GBK", $contents); //$from_name = iconv_ec("UTF-8","GBK",$from_name); //$from_email = ""; $smtphandle->subject = $subject; $smtphandle->body = $contents; $res = $adb->query("select * from ec_systems where server_type='email' and smownerid='" . $current_user->id . "'"); $rownum = $adb->num_rows($res); if ($rownum == 0) { return "No Smtp Server!"; } $server = $adb->query_result($res, 0, 'server'); $username = $adb->query_result($res, 0, 'server_username'); $password = $adb->query_result($res, 0, 'server_password'); $smtp_auth = $adb->query_result($res, 0, 'smtp_auth'); $server_port = $adb->query_result($res, 0, 'server_port'); $from_email = $adb->query_result($res, 0, 'from_email'); $from_name = $adb->query_result($res, 0, 'from_name'); $from_name = iconv_ec("UTF-8", "GBK", $from_name); $from_email = iconv_ec("UTF-8", "GBK", $from_email); $smtphandle->SetHost($server, $server_port); $smtphandle->UseAuthLogin($username, $password); $smtphandle->SetFrom($from_email, $from_name); $smtphandle->AddReplyTo($from_email, $from_name); if ($to_email != '') { $smtphandle->AddTo($to_email); } if ($sjid != "") { $query = "select ec_attachments.* from ec_attachments " . " inner join ec_attachmentsjrel on ec_attachmentsjrel.attachmentsid = ec_attachments.attachmentsid " . "where ec_attachmentsjrel.sjid={$sjid} and ec_attachments.deleted=0 order by ec_attachments.attachmentsid asc"; $result = $adb->query($query); $rownum = $adb->num_rows($result); if ($rownum > 0) { while ($row = $adb->fetch_array($result)) { $attachmentsid = $row['attachmentsid']; $filename = $row['name']; $filename = iconv_ec("UTF-8", "GBK", $filename); $encode_filename = base64_encode_filename($row['name']); $filepath = $row['path']; $filetype = $row['type']; global $root_directory; $fullpath = $root_directory . $filepath . $attachmentsid . "_" . $encode_filename; $log->info("send_webmail :: fullpath:" . $fullpath); if (file_exists($fullpath)) { $attachment_status = $smtphandle->AddAttachment($fullpath, $filename, $filetype); if (!$attachment_status) { $log->info("send_webmail :: errormsg:" . $smtphandle->errormsg); } } } } } $errMsg = ""; $sentmsg = $smtphandle->Send(); if ($sentmsg === false) { $errMsg = $smtphandle->errormsg . '<br>'; $log->info("send_webmail :: errormsg:" . $smtphandle->errormsg); } $log->debug("Exit send_webmail() method ..."); return $errMsg; }
function get_userfolder($userid) { $key = "get_userfolder_" . $userid; $userfolder = getSqlCacheData($key); if (!$userfolder) { global $adb, $mailstore_directory; //global $log; $userfolder = ""; $current_username = getUserName($userid); if ($current_username == "") { return $mailstore_directory; } require_once "include/utils/ChineseSpellUtils.php"; $spell = new ChineseSpell(); $length = str_len($current_username); $current_username = iconv_ec("UTF-8", "GBK", $current_username); $current_username = $spell->getFullSpell($current_username, ""); $current_username = strtolower($current_username); $userfolder = $mailstore_directory . $current_username . "/"; setSqlCacheData($key, $userfolder); } return $userfolder; }
/** Function to save the user information into the database * @param $module -- module name:: Type varchar * */ function save($module_name) { global $log; $log->debug("module name is " . $module_name); //GS Save entity being called with the modulename as parameter $this->saveentity($module_name); if ($this->column_fields['user_name'] != "") { require_once "include/utils/ChineseSpellUtils.php"; $spell = new ChineseSpell(); $chineseStr = $this->column_fields['user_name']; $chineseStr = iconv_ec("UTF-8", "GBK", $chineseStr); $prefixa = $spell->getFullSpell($chineseStr, ''); $prefixa = strtoupper($prefixa); $query = "update ec_users set prefix='" . $prefixa . "' where id='" . $this->id . "'"; $this->db->query($query); } }
$content .= $header; $column_list = implode(",", array_values($fields_array)); while ($val = $adb->fetchByAssoc($result, -1, false)) { $new_arr = array(); foreach ($val as $key => $value) { if ($key == "description") { $value = br2nl_vt($value); } array_push($new_arr, preg_replace("/\"/", "\"\"", $value)); } $line = implode("\",\"", $new_arr); $line = "\"" . $line; $line .= "\"\r\n"; $content .= $line; } $log->debug("Exiting export_all method ..."); return $content; } $content = export_all($_REQUEST['module']); ob_clean(); header("Pragma: cache"); header("Content-type: application/octet-stream; charset=GBK"); header("Content-Disposition: attachment; filename={$_REQUEST['module']}.csv"); header("Content-transfer-encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: post-check=0, pre-check=0", false); header("Content-Length: " . strlen($content)); $content = iconv_ec("UTF-8", "GBK", $content); print $content; exit;
$product_line[$j]["spec"] = $serial_no[$i]; $product_line[$j]["code"] = $productcode[$i]; $product_line[$j]["imagename"] = $imagename[$i]; $product_line[$j]["unit"] = $usageunit[$i]; $product_line[$j]["qty"] = $qty[$i] . $usageunit[$i]; $product_line[$j]["num"] = $qty[$i]; $product_line[$j]["price"] = $list_price[$i]; $product_line[$j]["total"] = $prod_total[$i]; $product_line[$j]["description"] = $prod_description[$i]; $product_focus = null; } $price_total = ec_number_format($focus->column_fields["total"]); $TOTAL = $price_total; //金额 $TOTAL_BIG = toCNcap($price_total); //大写金额 $TOTAL_BIG = iconv_ec("GBK", "UTF-8", $TOTAL_BIG); } $MODULE_LABEL = $app_strings["Memdays"]; $TBS = new clsTinyButStrong(); $TBS->NoErr = true; // no more error message displayed. // Load the template if (isset($module_enable_product) && $module_enable_product) { $TBS->LoadTemplate('modules/Memdays/' . $templatefile . '.html', 'UTF-8'); $TBS->MergeBlock('product', $product_line); } else { $TBS->LoadTemplate('modules/Memdays/' . $templatefile . '.html', 'UTF-8'); } // Final merge and download file $TBS->Show();
function Read_Excel_File($ExcelFile, &$result) { $exc = new ExcelFileParser("", ABC_NO_LOG); $res = $exc->ParseFromFile($ExcelFile); $result = null; switch ($res) { case 0: break; case 1: $err = "无法打开文件"; break; case 2: $err = "文件太小,可能不是Excel文件"; break; case 3: $err = "文件头读取错误"; break; case 4: $err = "读取文件时出错"; break; case 5: $err = "这不是一个Excel文件或者是Excel5.0以前版本文件"; break; case 6: $err = "文件损坏"; break; case 7: $err = "在文件中没有发现Excel数据"; break; case 8: $err = "不支持的文件版本"; break; default: $err = "未知错误"; break; } for ($ws_num = 0; $ws_num < count($exc->worksheet['name']); $ws_num++) { $Sheetname = $exc->worksheet['name'][$ws_num]; $ws = $exc->worksheet['data'][$ws_num]; for ($j = 0; $j <= $ws['max_row']; $j++) { for ($i = 0; $i <= $ws['max_col']; $i++) { $data = $ws['cell'][$j][$i]; switch ($data['type']) { // string case 0: $ind = $data['data']; if ($exc->sst['unicode'][$ind]) { //$s = uc2html($exc->sst['data'][$ind]); $s = iconv_ec('utf-16le', 'utf-8', $exc->sst['data'][$ind]); } else { $s = $exc->sst['data'][$ind]; } if (strlen(trim($s)) == 0) { $V = ""; } else { $V = $s; } break; // integer number // integer number case 1: $V = (int) $data['data']; break; // float number // float number case 2: $V = (double) $data['data']; break; // date // date case 3: $ret = $exc->getDateArray($data['data']); $V = $ret['year'] . "-" . $ret['month'] . "-" . $ret['day'] . " " . $ret['hour']; break; default: break; } $result[$Sheetname][$j][$i] = $V; } } } if ($err == '') { return 0; } else { return $err; } }
function parse_import_csv_new($file_name, $delimiter, $max_lines, $has_header) { $line_count = 0; $field_count = 0; $rows = array(); /*if (! is_file($file_name)) { return -1; }*/ // $s = new SaeStorage(); // // $fh = $s->read( 'upload' , $file_name) ; $fh = file_get_contents($file_name); //echo "fh:".$fh."<br>"; //$encode = chkCode($fh); // if($encode !='GBK'){ // return -5; // } if ($fh == false) { return -3; } $fh = iconv_ec("GBK", "UTF-8", $fh); //echo "fh2:".$fh."<br>"; //phpinfo(); //exit(); $line_arr = str_getcsv($fh, "\n"); $line_count = count($line_arr); // num if ($line_count > 2001) { return -4; } $rows = array(); foreach ($line_arr as $key => $line) { $arr = str_getcsv($line, ","); $rows[$key] = $arr; } $ret_array = array("rows" => &$rows, "field_count" => $line_count); //$s->delete( 'upload' , $file_name) ; unlink($file_name); return $ret_array; }
function parse_import_csv_new($file_name, $delimiter, $max_lines, $has_header) { $line_count = 0; $field_count = 0; $rows = array(); if (!is_file($file_name)) { return -1; } $fh = fopen($file_name, "r"); if (!$fh) { return -1; } setlocale(LC_ALL, 'zh_CN.GBK'); while (($fields = fgetcsv($fh, 4096, $delimiter)) !== FALSE && ($max_lines == -1 || $max_lines != '')) { if (count($fields) == 1 && isset($fields[0]) && $fields[0] == '') { break; } $this_field_count = count($fields); if ($this_field_count > $field_count) { $field_count = $this_field_count; } array_push($rows, $fields); $line_count++; } if (is_file($file_name)) { @unlink($file_name); } // got no rows if (count($rows) == 0) { return -3; } else { // converted to UTF-8 global $default_export_charset; foreach ($rows as $rowKey => $row) { foreach ($row as $k => $v) { $row[$k] = iconv_ec("GBK", "UTF-8", $v); } $rows[$rowKey] = $row; } } $ret_array = array("rows" => &$rows, "field_count" => $field_count); return $ret_array; }