<?php

/*
  PHP version 5
  Copyright (c) 2002-2018 ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030
*/

use application\ESPCMS_Core;

class lib_im {

	public static function call_im($parameter, $filename = 'im', $outHTML = null) {
		global $espcms_db_cache;
		$espcms_lib_template = espcms_web_template();
		$espcms_lib_template->libfile = true;
		$para = espcms_array_getvalue($parameter);
		$app_config = ESPCMS_Core::get_app_config('onlineService', false);
		if (!$app_config['isetup'] || !$app_config['isopen']) {
			return false;
		}
		$lng = espcms_lancode();
		$wxid = $para['wxid'] && espcms_ismatches($para['wxid']) ? $para['wxid'] : 0;
		$db_table = ESPCMS_DB_PREFIX . "calling";
		$cache_key = ESPCMS_CACHE_DBLIST_NAME . $db_table . '_' . $lng . '_1';
		$db_where = " AND isclass=1 AND lng='$lng'";
		$talbe_field_array = espcms_field_out($db_table);
		$call_array = $espcms_db_cache->cacheCheck($cache_key, false);
		if (!$call_array) {
			$call_list = espcms_db_list_array($db_table, $talbe_field_array, $db_where, 'pid,cid DESC');
			if (is_array($call_list)) {
				foreach ($call_list as $key => $value) {
					$call_array[] = $value;
				}
			}
			$espcms_db_cache->cacheSave($cache_key, $call_array);
		}
		$espcms_lib_template->into('array', $call_array);
		if (!empty($outHTML)) {
			$output = $espcms_lib_template->fetch(null, null, $outHTML);
		} else {
			$output = $espcms_lib_template->fetch('lib/' . $filename);
		}
		return $output;
	}

}
