博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP 邮箱操作的Action
阅读量:7067 次
发布时间:2019-06-28

本文共 28463 字,大约阅读时间需要 94 分钟。


".$start ."

"; // $mail = M('sysinfo'); // $where['parameter'] = 'mailPageNum'; // $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 // $message = M('message'); // $emailCount = $message->count(); //数据一共多少条 // $arruser = $message->order('date desc')->limit('5')->select(); //取出所有数据 // //这里总数减一,是因为邮箱第一个数据不做有效数据. // $mailCount = (($emailCount - 1) / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. // echo $mailCount; // } function index($start = 0) //第一次打开, 初始化 { $mail = M('sysinfo'); $where['parameter'] = 'mailPageNum'; $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 $message = M('message'); $emailCount = $message->count(); $arruser = $message->order('date desc')->limit($mailListLength[0]['content'])->select(); //取出所有数据 //这里总数减一,是因为邮箱第一个数据不做有效数据. $mailCount = ceil($emailCount / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. if ($mailCount > 1) //有分页的情况 { $this->assign('mailCount', '1/' . $mailCount); $this->display("message"); $this->initMailList($arruser, $start, $mailListLength[0]['content'], $emailCount); } else //没有分页 { $this->assign('mailCount', '0/' . $mailCount); $this->display("message"); $this->initMailList($arruser, $start, count($arruser), $emailCount); } } //判断字符串长度, 含utf8中文计算长度 function utf8_strlen($str) { $count = 0; for($i = 0; $i < strlen($str); $i++) { $value = ord($str[$i]); if($value > 127) { $count++; if($value >= 192 && $value <= 223){ $i++; } elseif($value >= 224 && $value <= 239) { $i = $i + 2; } elseif($value >= 240 && $value <= 247) { $i = $i + 3; } else die('Not a UTF-8 compatible string'); } $count++; } return $count; } //初始化邮箱 function initMailList($arruser, $start, $offset, $mailLen) { //var_dump($arruser); $this->PrintMail($arruser, $start, $offset); if ($mailLen == 0) //没有邮件 { return; } else if ($start == 0 && $mailLen > ($start + $offset)) //就一页, 数据小于分页显示的数量 { $this->initMailPageControl(0, 1); return; } else if ($start == 0 && ($start + $offset) > $mailLen) //显示第一页,并且邮件长度不足一页显示的 { $this->initMailPageControl(0, 1); //第一页,没有上一页 return; } else //就是不需要显示分页,因为不足显示的类表长度,所有不需要上下分页. { // $this->initMailPageControl(1, 1); return; } } //初始化邮箱翻页操作, function initMailPageControl($left, $right) { if ($left == true) { echo ""; } else { echo ""; } if ($right == true) { echo ""; } else { echo ""; } } //打印邮件 function PrintMail($arruser, $start, $offset) { // echo "
".$start . " ===== ". $end; $strShow = "
"; if (0 >= $offset) { return; } $i = 1; foreach ($arruser as $keyOne=>$value) { //初始化 $strOne = ''; $strTwo = ''; $strOne .= "
"; $strOne .= "
"; $strTwo .= "
"; $strShow .= $strOne . $falgStr . $strTwo; $i++; if ($i > $offset) //判断,然后跳出循环 { break; } } $strShow .= "
"; $strOne .= "
"; $strTwo .= "
"; foreach ($value as $k=>$var) { if ($k == 'isRead') { if($value['isRead'] == '0') //未读 { $strTwo .= "
" ; } else if ($value['isRead'] == '1') //已读 { $strTwo .= "
" . "  " ."
"; } } if ($k == 'name') { $maxStr = 0; $nameLength = $this->utf8_strlen($value["name"]); //计算名字长度, if (preg_match("/[\x7f-\xff]/", $value["name"])) //判断是否有中文 { $maxStr = 5; //有中文, 长度最大为6个汉字 } else { $maxStr = 10; //没有中文,为12个英文字符. } if ($nameLength <= $maxStr ) { $strTwo .= "
" . $value['name'] . "
"; } else { $strTwo .= "
" . mb_substr($value['name'], 0, $maxStr, 'utf-8') . "...
"; //截取后显示 } } if ($k == 'isFlag') { if($value['isFlag'] == '0') //没标记 { $falgStr = "color:#000"; } else if ($value['isFlag'] == '1') //已标记 { $falgStr = "color:red"; } } if ($k == 'message') { $strTwo .= "
" . "
" . "
" ; if (strlen($value['message']) < 20) { $strTwo .= $value['message'] . "...
"; } else { //mb_substr防止中文乱码 $strTwo .= mb_substr($value['message'], 0, 20, 'utf-8') . "...
" ; } } if ($k == 'date') { $date = substr(date('Y-m-d', $value['date']), 2); $strTwo .= "" . $date . ""; } } $strTwo .= ""; $strTwo .= "
"; echo $strShow; } function mailNextPage() { if (!$this->isPost()) //不是post提交 { ; } else //post提交 { $start = $this->_post('pageEndMail'); $mail = M('sysinfo'); $where['parameter'] = 'mailPageNum'; $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 $message = M('message'); $emailCount = $message->count(); //取出所有数据 //这里总数减一,是因为邮箱第一个数据不做有效数据. $mailCount = ceil(count($arruser) / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. // echo $start. " ===== ". ($start + $mailListLength[0]['content']) . "=====".$emailCount; //$maildata = $message->order('date desc')->limit($start. "," . $mailListLength[0]['content'])->select(); if (($emailCount - $mailListLength[0]['content']) >= $start) { $maildata = $message->order('date desc')->limit($start. "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, $start, $mailListLength[0]['content'], $emailCount); //var_dump($maildata); } else { // $this->assign('mailCount', '0/' . $mailCount); // $this->display("message"); $maildata = $message->order('date desc')->limit($start . "," . ($emailCount - $start))->select(); $this->initMailList($maildata, $start, ($emailCount - $start), 0); } } } function mailProPage() { if (!$this->isPost()) //不是post提交 { ; } else //post提交 { $start = $this->_post('pageEndMail') - 1; $mail = M('sysinfo'); $where['parameter'] = 'mailPageNum'; $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 $message = M('message'); $emailCount = $message->count(); //数据一共多少条 //这里总数减一,是因为邮箱第一个数据不做有效数据. $mailCount = ceil(count($arruser) / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. // echo $start. " ===== ". ($start - $mailListLength[0]['content']) . "=====".$emailCount; if ($start - $mailListLength[0]['content'] >= 0) { $maildata = $message->order('date desc')->limit(($start - $mailListLength[0]['content']). "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, $start - $mailListLength[0]['content'], $mailListLength[0]['content'], $emailCount); } else { ; } } } function mailControlPage() { if (!$this->isPost()) //不是post提交 { ; } else //post提交 { $showPage = $this->_post('pageAim'); //将要显示的页面 $len = $this->_post('len'); //总共的页面数 $mail = M('sysinfo'); $where['parameter'] = 'mailPageNum'; $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 $message = M('message'); $emailCount = $message->count(); //数据一共多少条 $start = ($showPage - 1) * $mailListLength[0]['content']; $offset = 0; if ($emailCount - ($showPage - 1) * $mailListLength[0]['content'] > $mailListLength[0]['content']) { $offset = $mailListLength[0]['content']; } else { $offset = $emailCount - ($showPage - 1) * $mailListLength[0]['content']; } // echo $start . "===" . ($emailCount-1) . "===" . $offset; $maildata = $message->order('date desc')->limit($start . "," . $offset)->select(); $this->initMailList($maildata, $start, $offset, $emailCount); } } //查询倒序 第N个数据的id号 参数num 是邮件在所有邮件中的倒序位置 function findIdforNum($num) { $message = M('message'); $id = $message->order('date desc')->limit(($num - 1) . "," . $num)->field('id')->select(); return $id[0]['id']; } function mailLableRead() { if (!$this->isPost()) //不是post提交 { ; } else { $mailId = $this->_post('mailId'); // $message = M('message'); $id = $this->findIdforNum($mailId); $message = M('message'); $data['isRead'] = 1; if (false == $message->where("id = " . $id)->save($data)) { echo 0; } else { echo "
" . "  " ."
"; } } } function mailLableFlag() { if (!$this->isPost()) //不是post提交 { ; } else { $flagId = $this->_post('flagId'); $isFlag = $this->_post('isFlag'); $message = M('message'); $id = $this->findIdforNum($flagId); // echo $id; if ($isFlag == 1) //为真, 就标记 { $data['isFlag'] = 1; if (false == $message->where("id = " . $id)->save($data)) { echo 0; } else { //成功 echo 1; } } else // 取消标记 { $data['isFlag'] = 0; if (false == $message->where("id = " . $id)->save($data)) { echo 0; } else { //成功 echo 1; } } } } function mailLableDel() { if (!$this->isPost()) //不是post提交 { ; } else { $mailId = $this->_post('mailId').trim(); //邮箱的倒序排列 $start = $this->_post('start').trim(); //是哪一页的第1个的启示id $end = $this->_post('end').trim(); //是哪一页的第最一个id $pagelable = $this->_post('pagelable').trim(); //分页显示的数据 $id = $this->findIdforNum($mailId); $message = M('message'); $mailListLength = $this->getMailListLength(); if (false == $message->where("id = " . $id)->delete()) { echo 0; } else { $emailCount = $message->count(); //数据一共多少条 if ($pagelable != 0) //如果等于 0 , 就意味着只有一页, 不等于0,就是超过一页 { $lenPage = (int)substr($pagelable, stripos($pagelable,"/") + 1); $showPage = (int)substr($pagelable, stripos($pagelable,"/") - 1, 1); if ($showPage == $lenPage) //显示等于长度,就是最后一页 { if ($start == $end) //最后一页只有一条数据, 就向前翻一页 { // echo "$start == $end"; //echo (($lenPage - 1) * $mailListLength[0]['content']) . '===' . $mailListLength[0]['content']; $maildata = $message->order('date desc')->limit((($lenPage - 2) * $mailListLength[0]['content']). "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, (($lenPage - 2) * $mailListLength[0]['content']), $mailListLength[0]['content'], $emailCount); } else if ($start < $end) //不至一条 { // echo (($lenPage - 1) * $mailListLength[0]['content']) . "====" . ($emailCount - ($lenPage - 1) * $mailListLength[0]['content']); $maildata = $message->order('date desc')->limit((($lenPage - 1) * $mailListLength[0]['content']). ",". ($emailCount - ($lenPage - 1) * $mailListLength[0]['content']))->select(); $this->initMailList($maildata, ($lenPage - 1) * $mailListLength[0]['content'], $emailCount - ($lenPage - 1) * $mailListLength[0]['content'], $emailCount); } } else if ($showPage < $lenPage) //显示 小于 总长度 { if ($emailCount <= $mailListLength[0]['content']) //当只有2也的时候, 依然存在, 删除之后总数小于等于列表长度的可能 { $maildata = $message->order('date desc')->select(); $this->initMailList($maildata, 0, $emailCount, $emailCount); } else { $maildata = $message->order('date desc')->limit((($showPage - 1) * $mailListLength[0]['content']). "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, (($showPage - 1) * $mailListLength[0]['content']), $mailListLength[0]['content'], $emailCount); } } } else //$pagelable=0, 意味着就一页 { if ($emailCount == 0) //邮箱空 { echo ""; } else if ($emailCount <= $mailListLength[0]['content']) { $maildata = $message->order('date desc')->select(); $this->initMailList($maildata, 0, $emailCount, $emailCount); } else { $maildata = $message->order('date desc')->limit(0 . "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, 0, $mailListLength[0]['content'], $emailCount ); } } } } } function mailPageChangeShow() { if (!$this->isPost()) //不是post提交 { ; } else { $mailId = (int)$this->_post('mailId').trim(); //邮箱的倒序排列 $mailListLength = $this->getMailListLength(); $message = M('message'); $emailCount = $message->count(); $arruser = $message->order('date desc')->limit($mailListLength[0]['content'])->select(); //取出所有数据 //这里总数减一,是因为邮箱第一个数据不做有效数据. $maillength = ceil($emailCount / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. $mailShow = ceil($mailId / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. if ($emailCount <= $mailListLength[0]['content']) //只有一页 { echo 0; //让page跳转隐藏, 因为只有一页 return; } else if ($maillength < $mailShow) { $mailShow = $maillength; } echo $mailShow . "/" . $maillength . "
"; } } function mailDelPageChangeShow() { if (!$this->isPost()) //不是post提交 { ; } else { $mailId = (int)$this->_post('mailId').trim() - 1; //邮箱的倒序排列 $mailListLength = $this->getMailListLength(); $message = M('message'); $emailCount = $message->count(); $maillength = ceil($emailCount / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. // echo $emailCount . " === " .$maillength; if ($mailId > $emailCount) { $mailId -= $mailListLength[0]['content']; } $mailShow = ceil($mailId / $mailListLength[0]['content']); //计算一共的页数, 用信息的条数, 除以每一页的条数. if ($mailId == 0) { $mailShow = 1; } if ($emailCount <= $mailListLength[0]['content']) //只有一页 { echo '0'; //让page跳转隐藏, 因为只有一页 return; } else if ($maillength > $mailShow) { $mailShow = $maillength; } echo $mailShow . "/" . $maillength . "
"; } } function delMailButton() { if (!$this->isPost()) //不是post提交 { ; } else { $pagelable = $this->_post('pagelable').trim(); //邮箱的倒序排列 $end = (int)$this->_post('end').trim(); //邮箱的倒序排列 $singal = $this->_post('singal'); //删除的数组标号 $start = (int)$this->_post('start'); //邮箱列表第一个ID标号 $message = M('message'); $signalLabel = false; $deleteNum = 0; for ($k = $start, $i = 0; $i < strlen($singal); $i++, $k++) //顺序删除,被选择的邮件 { $id = $this->findIdforNum($k); //获取邮件真实id if ($singal[$i] == '1') //如是1, 就删除 { $idArr[$i] = $id; $signalLabel = ture; $deleteNum++; } } if($signalLabel == false) //没有要删除的数据 { echo "没有要删除的邮件"; return; } $where['id'] = array('in', $idArr); // var_dump($where); if (false == $message->where($where)->delete()) { echo false; return; } else { $mailListLength = $this->getMailListLength(); $emailCount = $message->count(); //数据一共多少条 if ($pagelable != 0) //如果等于 0 , 就意味着只有一页, 不等于0,就是超过一页 { $lenPage = (int)substr($pagelable, stripos($pagelable,"/") + 1); $showPage = (int)substr($pagelable, stripos($pagelable,"/") - 1, 1); if ($showPage == $lenPage) //显示等于长度,就是最后一页 { if (($start - 1 + $deleteNum) == $end) //最后一页全部删除, 就向前翻一页 { $maildata = $message->order('date desc')->limit((($lenPage - 2) * $mailListLength[0]['content']). "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, (($lenPage - 2) * $mailListLength[0]['content']), $mailListLength[0]['content'], $emailCount); } else if (($start - 1 + $deleteNum) < $end) //最后一页没有全部删除 { $maildata = $message->order('date desc')->limit((($lenPage - 1) * $mailListLength[0]['content']). ",". ($emailCount - ($lenPage - 1) * $mailListLength[0]['content']))->select(); $this->initMailList($maildata, ($lenPage - 1) * $mailListLength[0]['content'], $emailCount - ($lenPage - 1) * $mailListLength[0]['content'], $emailCount); } } else if ($showPage < $lenPage) //显示小于总长度 { //如果剩余的数据多过这一页,就全部添加完整, if (($start - 1 + $mailListLength[0]['content']) <= $emailCount) { // echo "如果剩余的数据多过这一页,就全部添加完整,"; $maildata = $message->order('date desc')->limit((($showPage - 1) * $mailListLength[0]['content']). "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, (($showPage - 1) * $mailListLength[0]['content']), $mailListLength[0]['content'], $emailCount); } else //如果剩余的数据,不足添加完整的一页,就把剩下的数据输出 { // echo "如果剩余的数据,不足添加完整的一页,就把剩下的数据输出"; $maildata = $message->order('date desc')->limit((($showPage - 1) * $mailListLength[0]['content']). "," . ($emailCount - ($start - 1)))->select(); $this->initMailList($maildata, (($showPage - 1) * $mailListLength[0]['content']), ($emailCount - ($start - 1)), $emailCount); } } } else //$pagelable=0, 意味着就一页 { if ($emailCount == 0) //邮箱空 { echo "没有邮件了"; } else if ($emailCount <= $mailListLength[0]['content']) { $maildata = $message->order('date desc')->select(); $this->initMailList($maildata, 0, $emailCount, $emailCount); } else { $maildata = $message->order('date desc')->limit(0 . "," . $mailListLength[0]['content'])->select(); $this->initMailList($maildata, 0, $mailListLength[0]['content'], $emailCount ); } } } } } function getMailListLength() { $mail = M('sysinfo'); $where['parameter'] = 'mailPageNum'; $mailListLength = $mail->where($where)->field('content')->select(); //获取系统设置里面单页显示的信息条数 return $mailListLength; } function markIsReadMail() //标记邮件为未读 { if (!$this->isPost()) //不是post提交 { ; } else { $funArgument = (int)$this->_post('funArgument'); //修改已读或者未读的数据 $start = (int)$this->_post('start').trim(); //邮箱的第一个id $end = (int)$this->_post('end').trim(); //邮箱的最后一个id $singal = $this->_post('singal').trim(); //邮箱的倒序排列 $mailListLength = $this->getMailListLength(); //获取一页的长度 $message = M('message'); $signalLabel = false; //标记位, 如果为真,就执行 $markNum = 0; for ($k = $start, $i = 0; $i < strlen($singal); $i++, $k++) //顺序删除,被选择的邮件 { $id = $this->findIdforNum($k); //获取邮件真实id if ($singal[$i] == '1') //如是1, 就标记为未读 { $idArr[$i] = $id; $signalLabel = ture; $deleteNum++; } } if($signalLabel == false) //没有要更新的数据 { echo "没有要标记的邮件"; echo false; return; } $where['id'] = array('in', $idArr); $data['isRead'] = $funArgument; if (false == $message->where($where)->save($data)) { echo false; return; } else { $start -= 1; // echo $start . "=====" .$end; $maildata = $message->order('date desc')->limit($start. "," . $end)->select(); //var_dump($maildata); $this->initMailList($maildata, $start, $mailListLength[0]['content'], $emailCount); } } } function markFlagMail() { if (!$this->isPost()) //不是post提交 { ; } else { $funArgument = (int)$this->_post('funArgument'); //修改已读或者未读的数据 $start = (int)$this->_post('start').trim(); //邮箱的第一个id $end = (int)$this->_post('end').trim(); //邮箱的最后一个id $singal = $this->_post('singal').trim(); //邮箱的倒序排列 $mailListLength = $this->getMailListLength(); //获取一页的长度 $message = M('message'); $signalLabel = false; //标记位, 如果为真,就执行 $markNum = 0; for ($k = $start, $i = 0; $i < strlen($singal); $i++, $k++) //顺序删除,被选择的邮件 { $id = $this->findIdforNum($k); //获取邮件真实id if ($singal[$i] == '1') //如是1, 就标记为未读 { $idArr[$i] = $id; $signalLabel = ture; $deleteNum++; } } if($signalLabel == false) //没有要更新的数据 { // echo "没有要标记的邮件"; // echo false; return; } $where['id'] = array('in', $idArr); $data['isFlag'] = $funArgument; if (false == $message->where($where)->save($data)) { // echo 'false'; return; } else { // echo "true"; $start -= 1; $maildata = $message->order('date desc')->limit($start. "," . $end)->select(); $this->initMailList($maildata, $start, $end, $emailCount); } } } //打开邮箱 function mailOpenMail() { $start = (int)$this->_get('start').trim(); //邮箱的第一个id $end = (int)$this->_get('end').trim(); //邮箱的最后一个id $mailId = (int)$this->_get('mailId').trim(); //邮箱的最后一个id $isRead = (int)$this->_get('isRead').trim(); //邮箱的最后一个id $message = M('message'); $id = $this->findIdforNum($mailId); //获取邮件真实id if ($isRead == 1) { $data['isRead'] = 1; $where['id'] = $id; if (false == $message->where($where)->save($data)) { //echo "更新为可读失败"; return; } } $data = $message->where('id='.$id)->select(); $sender = $data[0]['name']; $time = date('Y-m-d H:i:s', $data[0]['date']); $content = $data[0]['message']; if ($data[0]['email'] == '') { $email = " "; } else { $email = "《" . $data[0]['email'] . "》"; } $this->assign('sender', $sender); $this->assign('time', $time); $this->assign('email', $email); $this->assign('content', $content); $this->display('mailShow'); }}?>

 

转载于:https://www.cnblogs.com/hgonlywj/p/4842719.html

你可能感兴趣的文章
Vue Router
查看>>
你所听到的技术原理、技术本质到底是什么?
查看>>
决战燕京城-10 前往天寿山
查看>>
WebMvcTest与SpringBootTest
查看>>
面试官:你接受免费加班吗?程序员这样怼回去,网友:老铁没毛病
查看>>
分享我的个人项目:Wildfire 野火评论系统
查看>>
【机器视觉与图像处理】基于MATLAB的角度计算
查看>>
一篇很全面的IOS面试题(下)
查看>>
极简.高性能.分布式框架,可运行于多种环境(apache/php-fpm,swoole)
查看>>
DESTOON7.0农产品B2B供应求购交易平台源码
查看>>
node js 批量处理pdf,提取关键信息,并导出excel
查看>>
05 Objective C数组的四种遍历方法总结
查看>>
少侠请重新来过 - Vue学习笔记(五) - 指令
查看>>
重学前端(六)-JavaScript中的class
查看>>
技术并非一切,做做 Side Project 吧
查看>>
ViewPager+seekBar的联动效果
查看>>
RPA:制造业的下一个改变者
查看>>
VSCode Python开发环境配置
查看>>
208道 java 高频面试题和答案
查看>>
nginx反向代理配置
查看>>