mode_emailmAction.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. class mode_emailmClassAction extends inputAction{
  3. protected function savebefore($table, $arr, $id, $addbo){
  4. $barr['sendid'] = $this->adminid;
  5. $barr['sendname'] = $this->adminname;
  6. $barr['senddt'] = $this->now;
  7. $isfile = 0;
  8. if($this->post('fileid') != '')$isfile = '1';
  9. $barr['isfile'] = $isfile;
  10. $type = (int)$arr['type'];
  11. //外发
  12. if($type==1 && $arr['isturn']==1){
  13. $vsl = $this->option->getval('email_recexin_'.$this->adminid.'');
  14. if(isempt($vsl))return '未成功收信过,不能外发邮件';
  15. }
  16. if($type == 1){
  17. $urs = m('admin')->getone($this->adminid, 'id,name,email');
  18. $barr['sendname'] = ''.$urs['name'].'('.$urs['email'].')';
  19. }
  20. //回复的ID
  21. $huiid = $this->post('huiid');
  22. if(!isempt($huiid)){
  23. $barr['hid'] = $huiid;
  24. m('emails')->update('ishui=1','`mid`='.$huiid.' and `uid`='.$this->adminid.' and `type`=0');//更新已回复
  25. }
  26. return array('rows'=>$barr);
  27. }
  28. protected function saveafter($table, $arr, $id, $addbo)
  29. {
  30. $isturn = (int)$arr['isturn'];
  31. $type = (int)$arr['type'];
  32. if($isturn==1){
  33. if($type==0){
  34. $this->flow->savesubmid($arr['receid'], $id, 0,0);
  35. $this->flow->savesubmid($arr['ccid'], $id, 1,0);
  36. }
  37. $this->flow->savesubmid($arr['sendid'], $id, 2,1);
  38. //外发发邮件的
  39. if($type == 1){
  40. $emsa = $this->getrecename($arr['receid']);
  41. m($table)->update('`outzt`=0', $id);
  42. if($emsa != ''){
  43. $ccsa = $this->getrecename($arr['ccid']);
  44. $fjar = m('file')->getfilepath('emailm', $id);
  45. m('email')->sendemailout($this->adminid, array(
  46. 'title' => $arr['title'],
  47. 'body' => $arr['content'],
  48. 'receemail' => $emsa[0],
  49. 'recename' => $emsa[1],
  50. 'ccemail' => $ccsa[0],
  51. 'ccname' => $ccsa[1],
  52. 'attachpath'=> $fjar[0],
  53. 'attachname'=> $fjar[1],
  54. 'mid' => $id,
  55. ), 0);
  56. }
  57. }
  58. }
  59. }
  60. private function faemail($id, $arr)
  61. {
  62. $emsa = $this->getrecename($arr['receid']);
  63. m('emailm')->update('`outzt`=0', $id);
  64. if($emsa[0] != ''){
  65. $ccsa = $this->getrecename($arr['ccid']);
  66. $fjar = m('file')->getfilepath('emailm', $id);
  67. return m('email')->sendemailout($this->adminid, array(
  68. 'title' => $arr['title'],
  69. 'body' => $arr['content'],
  70. 'receemail' => $emsa[0],
  71. 'recename' => $emsa[1],
  72. 'ccemail' => $ccsa[0],
  73. 'ccname' => $ccsa[1],
  74. 'attachpath'=> $fjar[0],
  75. 'attachname'=> $fjar[1],
  76. 'mid' => $id,
  77. ), 0);
  78. }else{
  79. return '接收空的';
  80. }
  81. }
  82. /**
  83. * 重新请求外发
  84. */
  85. public function reoutfaAjax()
  86. {
  87. $id = (int)$this->get('sid','0');
  88. $arr = m('emailm')->getone($id);
  89. if($arr['type']!='1')return;
  90. $msg = $this->faemail($id, $arr);
  91. return $msg;
  92. }
  93. private function getrecename($sid)
  94. {
  95. $sem = $scn = '';
  96. if(!isempt($sid)){
  97. $rows = m('vcard')->getall("`id` in($sid)");
  98. foreach($rows as $k=>$rs){
  99. $sem.=','.$rs['email'].'';
  100. $scn.=','.$rs['name'].'';
  101. }
  102. }
  103. if($sem!=''){
  104. $sem = substr($sem, 1);
  105. $scn = substr($scn, 1);
  106. }
  107. return array($sem, $scn);
  108. }
  109. //邮件回复的
  110. public function emailhuifuAjax()
  111. {
  112. $mid = (int)$this->post('mid');
  113. $cont = $this->post('cont');
  114. $flow = m('flow')->initflow('emailm', $mid);
  115. echo $flow->huifu($cont);
  116. }
  117. //获取个人通讯录上联系人,外发发邮件的
  118. public function getvcardAjax()
  119. {
  120. $row = $this->getvcard();
  121. $this->returnjson($row);
  122. }
  123. public function getvcard()
  124. {
  125. $rows = m('vcard')->getall("uid='$this->adminid' and `email` is not null",'id,name,email','sort,optdt desc');
  126. $row = array();
  127. foreach($rows as $k=>$rs){
  128. $row[] = array(
  129. 'value' => $rs['id'],
  130. 'name' => ''.$rs['name'].'('.$rs['email'].')',
  131. );
  132. }
  133. return $row;
  134. }
  135. public function getzfcontAjax()
  136. {
  137. $zfid = (int)$this->get('zfid');
  138. $zflx = (int)$this->get('zflx');
  139. $rs = m('emailm')->getone($zfid,'title,content,type,sendid,sendname,fromemail,id');
  140. if($zflx==0){
  141. $zffes = m('file')->copyfile('emailm', $zfid); //转发附件
  142. $rs['filers'] = $zffes;
  143. }else{
  144. //外发时读取
  145. if($rs['type']==1){
  146. $rs['sendid'] = '';
  147. $rs['sendname'] = '';
  148. $rsem = m('emails')->getone("`mid`='$zfid' and `type`=2");
  149. if($rsem){
  150. $toemail = $rsem['email'];
  151. $toname = $rsem['personal'];
  152. //加入到个人通讯录上
  153. $rse = m('vcard')->getone("`uid`='$this->adminid' and `email`='$toemail'");
  154. if(!$rse){
  155. $toid = m('vcard')->insert(array(
  156. 'name' => $toname,
  157. 'uid' => $this->adminid,
  158. 'email' => $toemail,
  159. 'gname' => '未分组',
  160. 'optdt' => $this->now,
  161. ));
  162. }else{
  163. $toid = $rse['id'];
  164. }
  165. $rs['sendid'] = $toid;
  166. $rs['sendname'] = $toname.'('.$toemail.')';
  167. }
  168. $flow = m('flow')->initflow('emailm');
  169. $rs['content'] = '<br><br><br>'.$flow->getoldcont($zfid, false);
  170. }
  171. }
  172. $rs['zflx'] = $zflx;
  173. $this->returnjson($rs);
  174. }
  175. }
粤ICP备19079148号