MaillistAction.class.php
8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
Class MaillistAction extends CommonAction{
private $tab = 'Webuser';
private $tab2 = 'Department';
private $tabview = 'MaillistView';
public function _initialize() {
parent::_initialize();
$this->assign('page_title','通讯录');
$this->checkLog(); //判断用户是否已经登录
$this->assign('authlist',$this->getPower()); //用户权限
}
public function index(){
if(I('title','','trim')){
$where['name']=array('like','%'.I('title','','trim').'%');
$search['title']=I('title','','trim');
}
if(I('depart','','trim')){
$where['depart_name']=array('like','%'.I('depart','','trim').'%');
$search['depart']=I('depart','','trim');
}
$this->assign('search',$search);
$where['isshow'] = array('eq',1);
$order = 'id desc';
$model = M($this->tab);
$field = array('id','name','depart_name','pid','mobile','tel','email','addtime');
$data = $this->_getLists($model,$where,$order,$field,100,'Pages3',array('header'=>'<li style="border:none;">共%totalRows%条记录','pages'=>'%nowPage%/%totalPages%页 </li>','prev'=>'<上一页','next'=>'下一页>','first'=>'首页','last'=>'尾页','theme'=>'%header% %pages% %prePage% %linkPage% %nextPage% %end%'));
$this->assign('list',$data['list']?$data['list']:array()); //列表
$this->assign('page',$data['page']); //分页
$this->assign('p',$data['p']); //当前页数
$this->assign('page_title','通讯录');
$this->assign('empty','<tr><td colspan="7" style="padding-left:15px;font-size:14px;">暂无相关信息!</td></tr>');
$this->display();
}
public function edit()
{
$Admin=D($this->tab);
$id=I('id',0,'intval');
if(!$id){
$this->error('参数有误!');
}
if($this->isPost()){
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
$lastid=$Admin->save();
if($lastid>0){
$this->success('通讯录信息修改成功',U('index'));
}else{
$this->error('通讯录信息修改失败');
}
}
}else{
$data=$Admin->where('id='.$id)->find();
$this->assign('depart',$this->getDepartment());
$this->assign('data',$data);
$this->display();
}
}
/**
* 添加通讯录
*/
public function add(){
$Admin=D($this->tab);
if($this->isPost()){
//添加用户
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
$lastid=$Admin->add();
if($lastid>0){
$this->success('通讯录信息添加成功',U('index'));
}else{
$this->error('通讯录信息添加失败');
}
}
}else{
$this->assign('depart',$this->getDepartment());
$this->display();
}
}
/**
* 公用删除
* @param int $id [description]
* @param object $model [description]
* @return bool [description]
*/
private function pubDelete($id,$model){
if(is_array($id)){
$map['id'] = array('in',$id);
}else{
$map['id']=array('eq',$id);
}
$aa=$model->where($map)->delete();
if($aa){
return true;
}else{
return false;
}
}
/**
* 删除通讯录
*/
public function delete()
{
$id=I('id',0,'intval');
if(!$id){
$this->error('参数有误!');
}
$m=M($this->tab);
$back=$this->pubDelete($id,$m);
if($back){
$this->success('通讯录信息删除成功',U('index',array('p'=>I('p',1,'intval'))));
}else{
$this->error('通讯录删除失败');
}
}
/**
* 导出excel
*/
public function download(){
set_time_limit(0);
$fields = array('id','name','tel','email','username');
$filename = '通讯录-'.date('_YmdHis');
$filenamebac=$filename;
$filename = iconv('utf-8', 'gb2312', $filename);//文件名称
$dir=str_replace('\\','/',realpath(__ROOT__));
if(!file_exists($dir.'/Uploads/excel')){
@mkdir($dir.'/Uploads/excel','0777');
}
$pp_file_path='/Uploads/excel/'.$filename.'.xls';
$pp_file_pathbac='/Uploads/excel/'.$filenamebac.'.xls';
$pp_file = $dir.$pp_file_path;
$order['id'] = 'desc';
$where['isshow']=array('eq',1);
$list=M($this->tab)->where($where)->field($fields)->order($order)->select();
$f=fopen($pp_file, "w");
fwrite($f,'<table width="100%" border="1" cellpadding="0" cellspacing="1">');
fwrite($f,'');
fwrite($f,'<tr><td align="center">'.iconv("UTF-8", "GBK", "序号").'</td><td align="center">'.iconv("UTF-8", "GBK", "登录帐号").'</td><td align="center">'.iconv("UTF-8", "GBK", "姓名").'</td><td align="center">'.iconv("UTF-8", "GBK", "手机").'</td><td align="center">Email</td></tr>');
if($list){
foreach($list as $k => $v){
fwrite($f,'<tr>');
fwrite($f,'<td align="center">'.($k+1).'</td><td align="center">'.iconv("UTF-8", "GBK", $v['username']).'</td><td align="center">'.iconv("UTF-8", "GBK", $v['name']).'</td><td align="center">'.iconv("UTF-8", "GBK", $v['tel']).'</td><td align="center">'.iconv("UTF-8", "GBK", $v['email']).'</td>');
fwrite($f,'</tr>');
}
}
fwrite($f,'</table>');
fclose($f);
echo '<script>location.href="'.$pp_file_pathbac.'";setTimeout("window.close();",6000);</script>';
}
/**
* 返回部门信息 id name
* @return array
*/
private function getDepartment(){
$field='id,name';
$order='firstname';
$info=M('Department')->field($field)->order($order)->select();
return $info;
}
/**
* 部门管理
*/
public function department(){
if(I('title','','trim')){
$where['name']=array('like','%'.I('title','','trim').'%');
$search['title']=I('title','','trim');
}
$this->assign('search',$search);
$order='firstname';
$model=M($this->tab2);
$field=array('id','name','firstname','addtime');
$data = $this->_getLists($model,$where,$order,$field,12,'Pages3',array('header'=>'<li style="border:none;">共%totalRows%条记录','pages'=>'%nowPage%/%totalPages%页 </li>','prev'=>'<上一页','next'=>'下一页>','first'=>'首页','last'=>'尾页','theme'=>'%header% %pages% %prePage% %linkPage% %nextPage% %end%'));
$this->assign('list',$data['list']?$data['list']:array()); //列表
$this->assign('page',$data['page']); //分页
$this->assign('p',$data['p']); //当前页数
$this->assign('page_title','部门管理');
$this->assign('empty','<tr><td colspan="4" style="padding-left:15px;font-size:14px;">暂无相关信息!</td></tr>');
$this->display();
}
/**
* 添加通讯录
*/
public function add_depart(){
$Admin=D($this->tab2);
if($this->isPost()){
//添加部门
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
$lastid=$Admin->add();
if($lastid>0){
$this->success('部门添加成功',U('department',array('p',I('p',1,'intval'))));
}else{
$this->error('部门添加失败');
}
}
}else{
$this->assign('p',I('p',1,'intval'));
$this->assign('page_title','部门信息');
$this->display();
}
}
/**
* 修改部门信息
* @return [type] [description]
*/
public function edit_depart()
{
$Admin=D($this->tab2);
$id=I('id',0,'intval');
if(!$id){
$this->error('参数有误!');
}
if($this->isPost()){
//修改
if(!$Admin->create()){
$this->error($Admin->getError());
}else{
$lastid=$Admin->save();
if($lastid>0){
$this->success('部门信息修改成功',U('department',array('p'=>I('p',1,'intval'))));
}else{
$this->error('部门信息修改失败');
}
}
}else{
$where['id'] = array('eq',$id);
$data=$Admin->where($where)->find();
$this->assign('data',$data);
$this->assign('page_title','部门信息');
$this->assign('p',I('p',1,'intval'));
$this->display();
}
}
/**
* 删除部门信息
*/
public function del_depart(){
$id=I('id',0,'intval');
if(!$id){
$this->error('参数有误!');
}
$m=M($this->tab2);
$back=$this->pubDelete($id,$m); //公用删除
if($back){
$this->success('部门信息删除成功',U('department',array('p'=>I('p',1,'intval'))));
}else{
$this->error('部门删除失败');
}
}
/**
* ajax 获取首字母
*/
public function ajaxname(){
$name=pinyin1(I('name','trim'));
echo $name;
}
}