You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/webht/third_party/outlook/controllers/index.php

836 lines
36 KiB
PHTML

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Index extends CI_Controller {
public $textline = 1;
public $textline2 = 1;
public function __construct() {
parent::__construct();
$this->permission->is_admin(false);
$this->load->model('Outlook_model');
}
//VALUE邮件窗口
public function index() {
$this->permission->is_admin(true);
$data = array();
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$data['user_ip'] = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($data['user_ip'], '*');
$data['verify_tpl'] = $this->get_verify_tpl($data['user_ip'], $current_user);
if (!empty($current_user)) {
$data['uname'] = $current_user->whu_uname;
}
$data['current_user'] = $current_user;
$this->load->view('header', $data);
$this->load->view('index');
$this->load->view('footer');
}
//VALUE排行榜
public function rank_value() {
$this->permission->is_admin(true);
$data = array();
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$data['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$data['uname'] = $current_user->whu_uname;
}
if ($this->input->post('from_date')) {
$from_date = strtotime(trim($this->input->post('from_date')));
} else {
$from_date = strtotime(date('Y-m-01', time()));
}
if ($this->input->post('to_date')) {
$to_date = strtotime(trim($this->input->post('to_date')) . ' 23:59:59');
} else {
$to_date = time();
$firstday = date('Y-m-01 23:59:59', time());
$to_date = strtotime("$firstday +1 month -1 day");
}
if ($this->input->post('valuetype') && $this->input->post('valuetype') != '-') {
$valuetype = $this->input->post('valuetype');
} else {
$valuetype = false;
}
$data['from_date'] = date('m/d/Y', $from_date);
$data['to_date'] = date('m/d/Y', $to_date);
$data['valuetype'] = $valuetype;
//value邮件内容
$rank_text = array();
$double_value_array = array();
$rank_mail = $this->Outlook_model->get_rank_mail($from_date, $to_date, $valuetype);
foreach ($rank_mail as $m) {
$rank_text[$m->whum_whu_uname][] = $m;
!isset($double_value_array[$m->whum_whu_uname]) && $double_value_array[$m->whum_whu_uname] = 2;
if (strripos($m->whm_value_key, 'discovery4') !== false) {
$double_value_array[$m->whum_whu_uname]+=4;
} elseif (strripos($m->whm_value_key, 'customer2') !== false) {
$double_value_array[$m->whum_whu_uname]+=2;
}
}
//总积分叠加
$rank = $this->Outlook_model->get_value_rank($from_date, $to_date, $valuetype);
$user_str = '';
foreach ($rank as $r) {
isset($double_value_array[$r->whum_whu_uname]) && $r->like_count+=$double_value_array[$r->whum_whu_uname];
}
//重新按照排名高低进行排序
$volume = array();
foreach ($rank as $row) {
$volume[] = $row->like_count;
}
array_multisort($volume, SORT_DESC, $rank);
$data['rank'] = $rank;
$data['rank_text'] = $rank_text;
$data['current_user'] = $current_user;
$this->load->view('header', $data);
$this->load->view('rank_value');
$this->load->view('footer');
}
public function example_table() {
$this->permission->is_admin(true);
$data = array();
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$data['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$data['uname'] = $current_user->whu_uname;
}
$from_date = $this->input->post('from_date');
$to_date = $this->input->post('to_date');
if (!empty($from_date) && !empty($to_date)) {
$from_date = strtotime($from_date);
$to_date = strtotime($to_date);
} else {
$firstday = date('Y-m-01', time());
$from_date = strtotime("$firstday -1 month +16 day");
$to_date = strtotime(date('Y-m-16', time()));
}
$data['from_date'] = $from_date;
$data['to_date'] = $to_date;
//$from_date = strtotime("$firstday -4 month");
//$to_date=strtotime(date('Y-03-31',time()));
$value_mail = $this->Outlook_model->get_rank_mail($from_date, $to_date, false);
$mail_text = array();
$team_title = array();
foreach ($value_mail as $v) {
$title_arr = explode(';[', $v->whm_subject);
$userlist = explode(';', trim(str_replace('values+', '', $title_arr[0])));
if (count($userlist) > 1) {
if (!in_array($v->whm_subject, $team_title)) {
$mail_text['集体事迹'][] = $v;
$team_title[] = $v->whm_subject;
}
} else {
$mail_text[$v->whum_whu_uname][] = $v;
}
}
$temp_list = isset($mail_text['集体事迹']) ? $mail_text['集体事迹'] : array();
unset($mail_text['集体事迹']);
$mail_text['集体事迹'] = $temp_list;
$data['mail_text'] = $mail_text;
$data['current_user'] = $current_user;
$this->load->view('header', $data);
$this->load->view('example_table');
$this->load->view('footer');
}
public function rank_person() {
$this->permission->is_admin(true);
$data = array();
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$data['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$data['uname'] = $current_user->whu_uname;
}
$data['current_user'] = $current_user;
//周榜
$monday = strtotime('this week');
$sunday = strtotime('last day this week +7 day');
$data['rank_week'] = $this->Outlook_model->get_person_rank($monday, $sunday);
//月榜
$from_date = strtotime(date('Y-m-01', time()));
$firstday = date('Y-m-01', time());
$to_date = strtotime("$firstday +1 month -1 day");
$data['rank_month'] = $this->Outlook_model->get_person_rank($from_date, $to_date);
//年榜
$year_start = strtotime(date('Y-01-01', time()));
$year_end = strtotime(date('Y-12-31', time()));
$data['rank_year'] = $this->Outlook_model->get_person_rank($year_start, $year_end);
//总榜
//$data['rank_all']=$this->Outlook_model->get_person_rank();
//每条价值观对应获得最多的人
/* ycc暂时不需要了
$rank=array();
$value_array=array('team','chengxin','customer','discovery','system');
foreach ($value_array as $value) {
$rank[$value]=$this->Outlook_model->value_key_rank($value);
for ($i=1; $i < 5; $i++) {
$value_key=$value.$i;
$rank[$value_key]=$this->Outlook_model->value_key_rank($value_key);
}
}
$data['rank']=$rank;
*/
$this->load->view('header', $data);
$this->load->view('rank_person');
$this->load->view('footer');
}
//value邮件
public function like($whc_whm_identify, $linktype = 'like') {
$this->permission->is_admin(true);
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
if (!empty($current_user)) {
$tpldata['uname'] = $current_user->whu_uname;
}
$tip_type = 'comment'; //等于comment时页面不弹出提示
if ($current_user->whu_uid && $linktype != 'comment') {
$data['whc_type'] = $linktype;
$data['whc_whm_identify'] = $whc_whm_identify;
$data['whc_uid'] = $current_user->whu_uid;
$has_like = $this->Outlook_model->is_liked($data);
if (!$has_like) {
$data['whc_content'] = $linktype;
$data['whc_createtime'] = time();
$whc_id = $this->Outlook_model->add_like($data);
$tip_type = $linktype;
}
}
$tpldata['mail_text'] = $this->Outlook_model->get_mail_text($whc_whm_identify);
$tpldata['list'] = $this->Outlook_model->get_comment_list($whc_whm_identify);
$tpldata['like_list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'like');
$tpldata['unlike_list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'unlike');
$tpldata['current_user'] = $current_user;
$tpldata['type'] = $tip_type;
$tpldata['whc_whm_identify'] = $whc_whm_identify;
$tpldata['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
$this->load->view('header', $tpldata);
$this->load->view('like');
$this->load->view('footer');
}
//普通邮件详细页
public function infocenter($user, $linktype = 'comment', $whc_whm_identify = false) {
$this->permission->is_admin(true);
$tpldata['userinfo'] = $this->Outlook_model->get_webhtuser_by_filed('whu_email', $user . '@citsguilin.com', '*');
//如果是第一次访问,则保存邮件(只有标题)
$mail_text = $this->Outlook_model->get_mail_text($whc_whm_identify);
if (empty($mail_text)) {
$dates = explode('-', $whc_whm_identify);
$datestring = '';
for ($i = 1; $i < 7; $i++) {
if ($dates[$i] < 10) {
$dates[$i] = '0' . $dates[$i];
}
if ($i < 3) {
$datestring.=$dates[$i] . '-';
} elseif ($i == 3) {
$datestring.=$dates[$i] . ' ';
} elseif ($i < 6) {
$datestring.=$dates[$i] . ':';
} else {
$datestring.=$dates[$i];
}
}
$datestring = strtotime($datestring);
$data['whm_content'] = htmlspecialchars($this->input->get('subject'));
$data['whm_fromuser'] = $tpldata['userinfo']->whu_uname;
$data['whm_subject'] = $this->input->get('subject');
$data['whm_touser'] = '';
$data['whm_ccuser'] = '';
$data['whm_value_key'] = '';
$data['whm_createtime'] = $datestring;
$data['whm_identify'] = $whc_whm_identify;
$whm_id = $this->Outlook_model->add_mail($data);
//邮件所有人
$vudata['whum_whu_uname'] = $tpldata['userinfo']->whu_uname;
$vudata['whum_whm_identify'] = $data['whm_identify'];
$vudata['whum_createtime'] = $datestring;
$whum_id = $this->Outlook_model->add_value_user($vudata);
}
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$tpldata['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$tpldata['uname'] = $current_user->whu_uname;
}
//comment时页面不弹出提示
$tip_type = 'comment';
if ($current_user->whu_uid && $linktype != 'comment' && $tpldata['userinfo']->whu_uid != $current_user->whu_uid) {
$map_is_like['whc_type'] = $linktype;
$map_is_like['whc_whm_identify'] = $whc_whm_identify;
$map_is_like['whc_uid'] = $current_user->whu_uid;
$like_count = $this->Outlook_model->is_liked($map_is_like);
if (empty($like_count)) {
$data['whc_type'] = $linktype;
$data['whc_whm_identify'] = $whc_whm_identify;
$data['whc_uid'] = $current_user->whu_uid;
$data['whc_content'] = $linktype;
$data['whc_createtime'] = time();
$whc_id = $this->Outlook_model->add_like($data);
$tip_type = $linktype;
//普通邮件每天第一次有人赞或者踩的时候发邮件通知发件人
$comment_count = $this->Outlook_model->get_comment_count($whc_whm_identify);
if ($comment_count == 1) {
$tomail[] = $user . '@citsguilin.com';
$subject = '你收获了今天的第一个赞';
$mailbody = '<div style="overflow:hidden">
<a style="height:auto;text-decoration: none;" href="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/space/' . $user . '">
<img src="http://' . $_SERVER['HTTP_HOST'] . '/css/images/Comment.png" />
</a>
<br/>
<img style="float:left;clear:both;" src="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/display_like_img/' . $whc_whm_identify . '/1"/>
</div>';
$this->do_sendmail($current_user->whu_email, $tomail, array(), $subject, $mailbody);
}
}
}
$tpldata['list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'comment', 'DESC');
$tpldata['like_list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'like', 'DESC');
$tpldata['unlike_list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'unlike', 'DESC');
$tpldata['mail_text'] = $this->Outlook_model->get_mail_text($whc_whm_identify);
$tpldata['type'] = $tip_type;
$tpldata['current_user'] = $current_user;
$tpldata['whc_whm_identify'] = $whc_whm_identify;
$tpldata['user_sn'] = $user;
$this->load->view('header', $tpldata);
$this->load->view('infocenter');
$this->load->view('footer');
}
//旧个人主页
public function usercenter($whc_whm_identify, $linktype = 'comment') {
$this->permission->is_admin(true);
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$tpldata['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$tpldata['uname'] = $current_user->whu_uname;
}
$tip_type = 'comment'; //等于comment时页面不弹出提示
$tpldata['list'] = $this->Outlook_model->get_comment_list($whc_whm_identify, 'comment', 'DESC');
$tpldata['mail_text'] = $this->Outlook_model->get_mail_text($whc_whm_identify);
$tpldata['userinfo'] = $this->Outlook_model->get_webhtuser_by_filed('whu_email', $whc_whm_identify . '@citsguilin.com', '*');
if ($current_user->whu_uid && $linktype != 'comment' && $tpldata['userinfo']->whu_uid != $current_user->whu_uid) {
$like_count = $this->Outlook_model->get_comment_count($whc_whm_identify, $linktype, $current_user->whu_uid);
if ($like_count < 3) {
$data['whc_type'] = $linktype;
$data['whc_whm_identify'] = $whc_whm_identify;
$data['whc_uid'] = $current_user->whu_uid;
$data['whc_content'] = $linktype;
$data['whc_createtime'] = time();
$whc_id = $this->Outlook_model->add_like($data);
$tip_type = $linktype;
//普通邮件每天第一次有人赞或者踩的时候发邮件通知发件人
$comment_count = $this->Outlook_model->get_comment_count($whc_whm_identify);
if ($comment_count == 1) {
$tomail[] = $whc_whm_identify . '@citsguilin.com';
$subject = '你收获了今天的第一个赞';
$mailbody = '<div style="overflow:hidden">
<a style="height:auto;text-decoration: none;" href="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/space/' . $whc_whm_identify . '">
<img src="http://' . $_SERVER['HTTP_HOST'] . '/css/images/Comment.png" />
</a>
<br/>
<img style="float:left;clear:both;" src="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/display_like_img/' . $whc_whm_identify . '/1"/>
</div>';
$this->do_sendmail($current_user->whu_email, $tomail, array(), $subject, $mailbody);
}
}
}
$tpldata['list_count'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $whc_whm_identify, 'comment', true);
$tpldata['like_list'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $whc_whm_identify, 'like');
$tpldata['unlike_list'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $whc_whm_identify, 'unlike');
$tpldata['type'] = $tip_type;
$tpldata['current_user'] = $current_user;
$tpldata['whc_whm_identify'] = $whc_whm_identify;
$this->load->view('header', $tpldata);
$this->load->view('usercenter');
$this->load->view('footer');
}
//新个人主页 cht07@citsgulin.com
public function space($user = '') {
$this->permission->is_admin(true);
$session_chtcdn = $this->session->userdata('admin_chtcdn');
if (empty($user)) {
$usermail = $session_chtcdn['whu_email'];
$usermail_arr = explode('@', $session_chtcdn['whu_email']);
$user = trim($usermail_arr[0]);
}
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$tpldata['verify_tpl'] = $this->get_verify_tpl($user_ip, $current_user);
if (!empty($current_user)) {
$tpldata['uname'] = $current_user->whu_uname;
}
$tpldata['current_user'] = $current_user;
$tpldata['whc_whm_identify'] = $user;
$tpldata['userinfo'] = $this->Outlook_model->get_webhtuser_by_filed('whu_email', $user . '@citsguilin.com', '*');
$tpldata['list_count'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $user, 'comment', true);
$tpldata['like_list'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $user, 'like');
$tpldata['unlike_list'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $user, 'unlike');
$tpldata['comment_list'] = $this->Outlook_model->get_space_comment($tpldata['userinfo']->whu_uname, $user, 'all');
$this->load->view('header', $tpldata);
$this->load->view('space');
$this->load->view('footer');
}
public function add_comment() {
$comment_count = $this->Outlook_model->get_comment_count($this->input->post('whc_whm_identify'));
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$current_user = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$data['whc_uid'] = $current_user->whu_uid;
$data['whc_type'] = 'comment';
$data['whc_whm_identify'] = $this->input->post('whc_whm_identify');
$whc_content = str_replace(PHP_EOL, '', $this->input->post('comment'));
$data['whc_content'] = $whc_content;
$data['whc_createtime'] = time();
$whc_id = $this->Outlook_model->add_like($data);
echo $whc_id;
}
public function delete_comment($whc_whm_identify, $linktype = 'like') {
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$list = $this->Outlook_model->get_comment_list($whc_whm_identify, $linktype, 'DESC', $session_chtcdn['whu_uid']);
$whc_id = $list[0]->whc_id;
$result = $this->Outlook_model->delete_comment($whc_id);
echo json_encode(array('status' => 'ok_go', 'link' => site_url('apps/outlook/index/space/' . $whc_whm_identify)));
}
public function get_verify_tpl($user_ip, $current_user) {
$fromuser = $current_user;
$verify_data['user_ip'] = $user_ip;
if (empty($user_ip) || $user_ip == 'NULL' || is_null($user_ip) || trim($user_ip) == '') {
$this->load->model('operator_model');
$verify_data['user_ip'] = $this->operator_model->get_client_ip();
}
$verify_data['uname'] = '';
if (!empty($fromuser)) {
$verify_data['uname'] = $fromuser->whu_uname;
}
$verify_data['display'] = 'none';
if (empty($fromuser) || $fromuser->whu_status != 1) {
$verify_data['display'] = 'block';
}
$verify_tpl = $this->load->view('verify', $verify_data, true);
return $verify_tpl;
}
public function display_like_img($whm_identify, $flag = false) {
$like = $this->Outlook_model->get_comment_list($whm_identify, 'like');
$unlike = $this->Outlook_model->get_comment_list($whm_identify, 'unlike');
//if (!$flag) {
$comment = $list = $this->Outlook_model->get_comment_list($whm_identify, 'comment', 'DESC');
//}else{
// $comment = array();
//}
Header("Content-type: image/png");
if (empty($like) && empty($comment) && empty($unlike)) {
$im = imagecreate(1, 1);
$black = ImageColorAllocate($im, 255, 255, 255);
ImagePng($im);
ImageDestroy($im);
return;
}
//给点赞列表文字添加换行
$like_str = '';
if (!empty($like)) {
foreach ($like as $k => $z) {
$z->whu_uname = preg_replace("/\(.*\)/", '', $z->whu_uname);
$like_str.=$z->whu_uname . ',';
if ($k > 13 && $k % 14 == 0)
$like_str.="~";
}
$like_str = rtrim($like_str, ',');
if ($like_str != '')
$like_str = '  ' . $like_str . ' ...他们都觉得很赞!`';
$str = $this->autowrap(12, 0, '/css/webht/SIMYOU.TTF', $like_str, 700, true);
}
//给拍砖列表文字添加换行
$unlike_str = '';
$like_height = 20 * ($this->textline2 - 1) + 42;
if (!empty($unlike)) {
foreach ($unlike as $i => $u) {
$u->whu_uname = preg_replace("/\(.*\)/", '', $u->whu_uname);
$unlike_str.=$u->whu_uname . ',';
if ($i > 14 && $i % 15 == 0)
$unlike_str.="~";
}
$unlike_str = rtrim($unlike_str, ',');
if ($unlike_str != '')
$unlike_str = '  ' . $unlike_str . '`';
$unlike_str = $this->autowrap(12, 0, '/css/webht/SIMYOU.TTF', $unlike_str, 700, true);
}
//给评论列表文字添加换行
$c_str = '';
if (!empty($comment)) {
foreach ($comment as $key => $c) {
$m_space = ': ';
$c->whu_uname = preg_replace("/\(.*\)/", '', $c->whu_uname);
if (strlen($c->whu_uname) == 6) {
$m_space = ': ';
}
$c_str.=$c->whu_uname . $m_space . $c->whc_content . '`';
}
//给文字添加换行
$str2 = $this->autowrap(12, 0, '/css/webht/SIMYOU.TTF', $c_str, 820, false, $flag);
}
//整张图片的高度
$height = 23 * ($this->textline - 1) + 30;
$height = $flag == 'reply' ? 180 : $height;
//创建基本图层
$im = imagecreate(1000, $height);
$background = ImageColorAllocate($im, 240, 244, 247);
$color = ImageColorAllocate($im, 0, 0, 0);
//拼接赞的用户列表
if (!empty($like)) {
ImageTTFText($im, 12, 0, 15, 35, $color, "/css/webht/SIMYOU.TTF", "$str");
//添加赞按钮图标
$src = imagecreatefromjpeg('http://' . $_SERVER['HTTP_HOST'] . '/css/images/php.jpg');
imagecopy($im, $src, 15, 15, 0, 0, 24, 24);
}
//拼接拍砖的用户列表
if (!empty($unlike)) {
ImageTTFText($im, 12, 0, 15, $like_height - 15, $color, "/css/webht/SIMYOU.TTF", "$unlike_str");
//添加拍砖按钮图标
$src = imagecreatefromjpeg('http://' . $_SERVER['HTTP_HOST'] . '/css/images/unlike.jpg');
imagecopy($im, $src, 15, $like_height - 32, 0, 0, 24, 24);
}
//拼接评论列表
if (!empty($comment)) {
//点赞和拍砖用户列表的高度
$zan_height = 20 * ($this->textline2 - 1) + 30;
ImageTTFText($im, 12, 0, 15, $zan_height, $color, "/css/webht/SIMYOU.TTF", "$str2");
}
//输出图片
ImagePng($im);
ImageDestroy($im);
}
public function sendmail() {
if (!$this->input->post('emaillist')) {
echo -1;
return;
}
$session_chtcdn = $this->session->userdata('admin_chtcdn');
$user_ip = $session_chtcdn['whu_ip'];
$fromuser = $this->Outlook_model->get_webhtuser_by_ip($user_ip, '*');
$cht_maillist = $this->lang->line('cht_maillist');
$data['whm_content'] = htmlspecialchars($this->input->post('emailcontent'));
$data['whm_fromuser'] = $fromuser->whu_uname;
$data['whm_subject'] = $this->input->post('mail_subject');
$data['whm_touser'] = $this->input->post('emaillist');
$data['whm_ccuser'] = $this->input->post('cs_emaillist');
$data['whm_value_key'] = $this->input->post('whm_value_key');
$data['whm_createtime'] = time();
$data['whm_identify'] = 'UID' . $fromuser->whu_uid . '_' . time();
$whm_id = $this->Outlook_model->add_mail($data);
//邮件所有人如果是value邮件则属于被value的人如果不是则属于发邮件的人
if ($this->input->post('whum_value_user')) {
$value_user_array = explode(';', $this->input->post('whum_value_user'));
foreach ($value_user_array as $vu) {
if (!empty($vu)) {
$vudata['whum_whu_uname'] = $vu;
$vudata['whum_whm_identify'] = $data['whm_identify'];
$vudata['whum_createtime'] = $data['whm_createtime'];
$whum_id = $this->Outlook_model->add_value_user($vudata);
}
}
} else {
$vudata['whum_whu_uname'] = $fromuser->whu_uname;
$vudata['whum_whm_identify'] = $data['whm_identify'];
$vudata['whum_createtime'] = $data['whm_createtime'];
$whum_id = $this->Outlook_model->add_value_user($vudata);
}
//收件人
$tolist_array = array();
$nowlist_array = explode(';', $this->input->post('emaillist'));
foreach ($nowlist_array as $v) {
if (isset($cht_maillist[$v])) {
$tolist_array[] = $cht_maillist[$v];
}
}
//抄送
$cclist_array = array();
$ccmail_array = explode(';', $this->input->post('cs_emaillist'));
foreach ($ccmail_array as $c) {
if (isset($cht_maillist[$c])) {
$cclist_array[] = $cht_maillist[$c];
}
}
$mailbody = '<div style="overflow:hidden">
<a style="height:auto;text-decoration: none;" href="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/like/' . $data['whm_identify'] . '/comment">
<img src="http://' . $_SERVER['HTTP_HOST'] . '/css/images/Comment.png" />
</a>
<a style="height:auto;text-decoration: none;" href="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/like/' . $data['whm_identify'] . '" >
<img src="http://' . $_SERVER['HTTP_HOST'] . '/css/images/like.png" />
</a>
<a style="height:auto;text-decoration: none;" href="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/like/' . $data['whm_identify'] . '/unlike" >
<img src="http://' . $_SERVER['HTTP_HOST'] . '/css/images/unlike.png" />
</a>
<br/>
<img style="float:left;clear:both;" src="http://' . $_SERVER['HTTP_HOST'] . '/webht.php/apps/outlook/index/display_like_img/' . $data['whm_identify'] . '"/>
</div>';
$fromemail = $fromuser->whu_email;
$subject = $this->input->post('mail_subject');
$body = $this->input->post('emailcontent') . $mailbody;
if (!$this->do_sendmail($fromemail, $tolist_array, $cclist_array, $subject, $body)) {
$result = 0; //"邮件发送有误: " . $mail->ErrorInfo;
} else {
//是value邮件的话默认发送人点赞
if ($this->input->post('whum_value_user')) {
$likedata['whc_type'] = 'like';
$likedata['whc_whm_identify'] = $data['whm_identify'];
$likedata['whc_uid'] = $fromuser->whu_uid;
$likedata['whc_content'] = 'like';
$likedata['whc_createtime'] = time();
$whc_id = $this->Outlook_model->add_like($likedata);
}
$result = 1;
}
echo $result;
return;
}
//执行邮件发送操作
public function do_sendmail($fromuser, $tolist_array, $cclist_array, $subject, $mailbody) {
$this->load->library('Phpmailer_lib');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = '202.103.68.122:25';
$mail->SMTPAuth = true;
$mail->Username = "cht58@citsguilin.com";
$mail->Password = "B047f21d654e07";
$mail->SMTPSecure = 'tls';
$mail->CharSet = "utf-8";
$mail->Encoding = "base64";
$mail->IsHTML(true);
$mail->From = $fromuser; //发件人
foreach ($tolist_array as $v) {
$mail->AddAddress($v); //收件人
}
foreach ($cclist_array as $c) {
$mail->addCC($c); //抄送
}
$mail->Subject = $subject; //邮件主题
$mail->Body = $mailbody; //邮件内容
if (!$mail->Send()) {
$result = false; //"邮件发送有误: " . $mail->ErrorInfo;
} else {
$result = true;
}
return $result;
}
//自动提示
public function get_user_list() {
$q = $this->input->get('q');
$str_array = explode(';', $q);
$q = end($str_array);
if (!$q)
return;
$showcount = 1;
$tmp = $this->lang->line('cht_maillist');
foreach ($tmp as $name => $mail) {
if ($showcount > 8)
break;
if (strstr($name, $q)) {
echo $name . ';' . "\n";
$showcount++;
}
}
}
function get_client_ip($type = 0) {
$type = $type ? 1 : 0;
static $ip = NULL;
if ($ip !== NULL)
return $ip[$type];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$pos = array_search('unknown', $arr);
if (false !== $pos)
unset($arr[$pos]);
$ip = trim($arr[0]);
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// IP地址合法验证
$long = sprintf("%u", ip2long($ip));
$ip = $long ? array($ip, $long) : array('127.0.0.1', 0);
return $ip[$type];
}
public function chararray($str, $charset = "utf-8") {
$re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
$re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
$re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
preg_match_all($re[$charset], $str, $match);
return $match;
}
/* 返回一个字符串在图片中所占的宽度 */
public function charwidth($fontsize, $fontangle, $ttfpath, $char) {
$box = @imagettfbbox($fontsize, $fontangle, $ttfpath, $char);
$width = max($box[2], $box[4]) - min($box[0], $box[6]);
return $width;
}
/* 这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度, 编码 */
public function autowrap($fontsize, $fontangle, $ttfpath, $str, $width, $flag = false, $follow = false) {
$_string = "";
$_width = 0;
$temp = $this->chararray($str);
foreach ($temp[0] as $k => $v) {
$w = $this->charwidth($fontsize, $fontangle, $ttfpath, $v);
$_width += intval($w);
if ($v == '`') {
$_width = 0;
if (!$follow) {
$_string .= "\n\n";
$this->textline++;
$this->textline++;
if ($flag) {
$this->textline2++;
$this->textline2++;
}
} else {
$_string .= "\n";
$this->textline++;
if ($flag) {
$this->textline2++;
}
}
} elseif ($v == '~') {
$_string .= "\n";
$_width = 0;
$this->textline++;
if ($flag) {
$this->textline2++;
}
} elseif (($_width > $width) && ($v !== "")) {
$_string .= "\n    ";
$_width = 0;
$this->textline++;
if ($flag) {
$this->textline2++;
}
}
if ($v != '`' && $v != '~') {
$_string .= $v;
}
$w = 0;
}
$_string = mb_convert_encoding($_string, "html-entities", "utf-8");
return $_string;
}
public function upload_photos() {
$save_path = date('Y-m-d');
$jsfunction = 'get_photo_url';
$upload_id = 'Profile_file';
$config['upload_path'] = APPPATH . 'upload/' . $save_path;
if (!is_dir($config['upload_path'])) {
@mkdir($config['upload_path'], 0777, true);
}
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($upload_id)) {
$error = array('error' => $this->upload->display_errors());
var_dump($error);
} else {
$data = array('upload_data' => $this->upload->data());
$file_name = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $config['upload_path'] . '/' . $data['upload_data']['file_name'];
echo "<script>parent.$jsfunction('$file_name');</script>";
}
}
public function verify() {
$whu_uname = explode(';', $this->input->post('uname'));
$whu_uname = $whu_uname[0];
$whu_ip = $this->input->post('whu_ip');
$result = $this->Outlook_model->verify_user($whu_uname, $whu_ip);
echo $result;
}
public function check_value_user() {
$value_user_array = explode(';', $this->input->post('value_user'));
foreach ($value_user_array as $vu) {
if (!empty($vu)) {
$result = $this->Outlook_model->has_user($vu);
if (empty($result)) {
echo 0;
return;
}
}
}
echo 1;
return;
}
}