AdminController.php 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class AdminController extends DooController {
  6. public $staff;
  7. public static $NEW = 0;
  8. public $nature=array('1'=>'设计',
  9. '2'=>'造价管理',
  10. '3'=>'业主',
  11. '4'=>'交通局',
  12. '5'=>'公路局',
  13. '6'=>'审计',
  14. '7'=>'财政',
  15. '8'=>'审核',
  16. '9'=>'施工',
  17. '10'=>'咨询',
  18. '11'=>'招标代理',
  19. '12'=>'监理',
  20. '13'=>'学校',
  21. '14'=>'个人',
  22. '15'=>'合作伙伴',
  23. );
  24. public $tooltip=array('1'=>array('L','点击筛选标签'),
  25. '2'=>array('M','点击筛选标签'),
  26. '3'=>array('N','点击筛选标签'),
  27. '4'=>array('O','点击筛选标签'),
  28. '5'=>array('P','点击筛选标签'),
  29. '6'=>array('Q','点击筛选标签'),
  30. '7'=>array('R','点击筛选标签'),
  31. );
  32. public $webPath="http://cld.smartcost.com.cn/upload/emailAnnex/";
  33. function __construct() {
  34. if(isset($_COOKIE["adStaff"])){
  35. if(!empty($_COOKIE["adStaff"])){
  36. Doo::loadModel ( 'staff' );
  37. $staff = new staff ();
  38. $this->staff=$staff->getUserByIdList($_COOKIE["adStaff"]);
  39. self::$NEW= $this->getReceiptCount();include './protected/controller/ReceiptController.php';
  40. ReceiptController::$NEW=self::$NEW;
  41. if ($this->staff[0]['isadmin']==1&&$this->staff[0]['username']=='admin'){
  42. return "/adminoffice";
  43. }
  44. }
  45. }
  46. //添加注释8998
  47. //我的代码
  48. Doo::loadCore ( 'uri/DooUriRouter' );
  49. $router = new DooUriRouter ();
  50. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  51. if($routeRs['1']!="adlogin"){
  52. header ( 'Content-Type:text/html;charset=utf-8' );
  53. @header ( "Location: /adlogin" );
  54. }
  55. }
  56. function adlogin(){
  57. $passwork = isset ( $_POST['passwork'] ) ? $_POST['passwork'] : "";
  58. $uid = isset ( $_POST['user'] ) ? $_POST['user'] : "";
  59. Doo::loadModel ( 'staff' );
  60. $staff = new staff ();
  61. if(!empty($passwork)){
  62. $userinfo=$staff->getOne(array('where'=>"username='admin'",'asArray'=>true));
  63. if(!empty($userinfo)){
  64. if ($userinfo['username']==$uid&&$userinfo['passwork']==md5($passwork)){
  65. setcookie("adStaff", $userinfo['sid'], time()+36000,"/");
  66. return "/adminoffice";
  67. }
  68. }
  69. }
  70. $data ['staff'] = "";
  71. $data['login']="";
  72. if(!empty($passwork))
  73. $data['login']="inputErrow";
  74. $this->render ( "/admin/adminLogin", $data );
  75. }
  76. function adout(){
  77. setcookie("adStaff", "", time()-3600,"/");
  78. return "/adlogin";
  79. }
  80. function adminPW(){
  81. $msg= $this->params['msg']?$this->params['msg']:"";
  82. $data['msg']="msg";
  83. $data['memu']="adminpw";
  84. $data['staff']=$this->staff;
  85. $data['msg']=urldecode($this->params['msg']);
  86. $this->render ( "/admin/admin-admininfo", $data );
  87. }
  88. function upAdP(){
  89. $opw=$this->get_args('opw')?$this->get_args('opw'):"";
  90. $npw1=$this->get_args('npw1')?$this->get_args('npw1'):"";
  91. $npw2=$this->get_args('npw2')?$this->get_args('npw2'):"";
  92. if(!empty($opw)){
  93. Doo::loadModel ( 'staff' );
  94. $staff = new staff ();
  95. $userinfo=$staff->getOne(array('where'=>"username='admin'",'asArray'=>true));
  96. if(!empty($userinfo)){
  97. if ($userinfo['sid']==$_COOKIE["adStaff"]&&$userinfo['passwork']==md5($opw)){
  98. if (($npw1==$npw2)&&($npw1!="")){
  99. $staff->passwork=md5($npw1);
  100. $staff->update(array('where'=>"sid='".$_COOKIE["adStaff"]."'"));
  101. return "/adminpw/".urlencode('密码修改成功');
  102. }else
  103. return "/adminpw/".urlencode('新密码不一致');
  104. }else
  105. return "/adminpw/".urlencode('旧密码不正确');
  106. }else
  107. return "/adminpw/".urlencode('未找到用户');
  108. }else
  109. return "/adminpw/".urlencode('请输入旧密码');
  110. }
  111. function adminoffice(){
  112. $data['memu']="adminoffice";
  113. $data['staff']=$this->staff;
  114. Doo::loadModel ( 'L_category' );
  115. Doo::loadModel ( 'staff' );
  116. Doo::loadModel('district');
  117. $district= new district();
  118. $staff = new staff ();
  119. $L_category = new L_category ();
  120. $data['category']=$L_category->getCategory();
  121. $data['district']=$district->get_lv(1);
  122. foreach ($data['category'] as $key=>$value){
  123. $data['category'][$key]['count']=$staff->count(array('where'=>'cid='.$value['cid']));
  124. }
  125. $data['msg']=urldecode($this->params['msg']);
  126. $this->render ( "/admin/admin_group", $data );
  127. }
  128. function addCategory(){
  129. $msg="添加成功";
  130. $title=isset($_POST['title'])?$_POST['title']:"";
  131. $district=isset($_POST['district'])?$_POST['district']:"";
  132. if(!empty($title)&&!empty($district)){
  133. Doo::loadModel ( 'L_category' );
  134. $L_category = new L_category ();
  135. $L_category->title=$title;
  136. $L_category->districtid=$district;
  137. $L_category->insert();
  138. }else{
  139. $msg="请输入正确的信息";
  140. }
  141. return "/adminoffice/".$msg;
  142. }
  143. function adminuser(){
  144. $data['memu']="adminuser";
  145. $data['staff']=$this->staff;
  146. Doo::loadModel ( 'L_category' );
  147. Doo::loadModel ( 'staff' );
  148. $staff = new staff ();
  149. $L_category = new L_category ();
  150. $data['category']=$L_category->getCategory();
  151. $data['stafflist']=$staff->getStaff();
  152. $data['staff']=$this->staff;
  153. $this->render ( "/admin/admin_user", $data );
  154. }
  155. function adduser(){
  156. $username=$this->get_args('username')?$this->get_args('username'):"";
  157. $password=$this->get_args('password')?$this->get_args('password'):"";
  158. $cid=is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  159. $hiredate=$this->get_args('hiredate')?$this->get_args('hiredate'):"";
  160. $nature=is_numeric($this->get_args('nature'))?$this->get_args('nature'):1;
  161. if(!empty($username)&&!empty($password)&&!empty($cid)&&!empty($hiredate)&&!empty($nature)){
  162. Doo::loadModel ( 'L_category' );
  163. Doo::loadModel ( 'staff' );
  164. Doo::loadModel ( 'tag' );
  165. $staff = new staff ();
  166. $L_category = new L_category ();
  167. //加入默认总部分类
  168. $cagegory=$L_category->getCategoryById($cid);
  169. //根据这个分类加入管理权限
  170. if($cagegory[0]['defult']==1){
  171. $staff->isadmin=1;
  172. }
  173. $staff->username=$username;
  174. $staff->passwork=md5($password);
  175. $staff->cid=$cagegory[0]['cid'];
  176. $staff->category=$cagegory[0]['title'];
  177. $staff->hiredate=$hiredate;
  178. $staff->nature=$nature;
  179. $id=$staff->insert();
  180. for ($i=1;$i<=7;$i++){
  181. $tag = new tag ();
  182. $tag->name="个人标签";
  183. $tag->sid=$id;
  184. $tag->colorid=$i;
  185. $tag->insert();
  186. }
  187. }
  188. return "/adminuser";
  189. }
  190. function adminEdiUser(){
  191. $sid= is_numeric($this->params['sid'])?$this->params['sid']:0;
  192. $msg= isset($this->params['msg'])?$this->params['msg']:"";
  193. if(!empty($sid)){
  194. $data['msg']=urldecode($msg);
  195. Doo::loadModel ( 'L_category' );
  196. Doo::loadModel ( 'staff' );
  197. $staff = new staff ();
  198. $L_category = new L_category ();
  199. $data['newPw']='';
  200. $data['staffInfo']=$staff->getUserById($sid);
  201. $data['category']=$L_category->getCategory();
  202. $data['staff']=$this->staff;
  203. $data['memu']="adminuser";
  204. $this->render ( "/admin/admin_EdiUser", $data );
  205. }else
  206. return "/adminuser";
  207. }
  208. function adminResetUserPw(){
  209. $sid= is_numeric($this->params['sid'])?$this->params['sid']:0;
  210. $msg= isset($this->params['msg'])?$this->params['msg']:"";
  211. if(!empty($sid)){
  212. $data['msg']=urldecode($msg);
  213. Doo::loadModel ( 'L_category' );
  214. Doo::loadModel ( 'staff' );
  215. $staff = new staff ();
  216. $L_category = new L_category ();
  217. $newPw=$this->getRandChar(6);
  218. $staff->sid=$sid;
  219. $staff->passwork=md5($newPw);
  220. $staff->update();
  221. $data['newPw']=$newPw;
  222. $data['staffInfo']=$staff->getUserById($sid);
  223. $data['category']=$L_category->getCategory();
  224. $data['staff']=$this->staff;
  225. $data['memu']="adminuser";
  226. $this->render ( "/admin/admin_EdiUser", $data );
  227. }else
  228. return "/adminuser";
  229. }
  230. function adminDoEdiUser(){
  231. $sid=is_numeric($this->get_args('sid'))?$this->get_args('sid'):0;
  232. $cid=is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  233. $gender=$this->get_args('gender')?$this->get_args('gender'):"";
  234. $qq=is_numeric($this->get_args('qq'))?$this->get_args('qq'):0;
  235. $phone=$this->get_args('phone')?$this->get_args('phone'):"";
  236. $telephone=$this->get_args('telephone')?$this->get_args('telephone'):"";
  237. $email=$this->get_args('email')?$this->get_args('email'):"";
  238. $username=$this->get_args('username')?$this->get_args('username'):"";
  239. $nature=$this->get_args('nature')?$this->get_args('nature'):"";
  240. $hiredate=$this->get_args('hiredate')?$this->get_args('hiredate'):"";
  241. if(!empty($sid)){
  242. $msg="";
  243. Doo::loadModel ( 'L_category' );
  244. Doo::loadModel ( 'staff' );
  245. $staff = new staff ();
  246. $L_category = new L_category ();
  247. $categoryInfo=$L_category->getCategoryById($cid);
  248. $staff->sid=$sid;
  249. if ($cid!=0){
  250. $staff->cid=$categoryInfo[0]['cid'];
  251. $staff->category=$categoryInfo[0]['title'];
  252. }
  253. if($categoryInfo[0]['defult']==1){
  254. $staff->isadmin=1;
  255. }else{
  256. $staff->isadmin=0;
  257. }
  258. if (!empty($username))
  259. $staff->username=$username;
  260. if(!empty($gender))
  261. $staff->gender=$gender;
  262. if(!empty($qq)&&is_numeric($qq))
  263. $staff->qq=$qq;
  264. if(!empty($phone))
  265. $staff->phone=$phone;
  266. if(!empty($telephone))
  267. $staff->telephone=$telephone;
  268. if(!empty($email)&&filter_var($email, FILTER_VALIDATE_EMAIL))
  269. $staff->email=$email;
  270. else
  271. $msg="邮箱不正确";
  272. if(!empty($hiredate))
  273. $staff->hiredate=$hiredate;
  274. $staff->nature=$nature;
  275. $staff->update();
  276. return "/edi/user/".$sid."/".$msg;
  277. }else{
  278. return "/adminuser";
  279. }
  280. }
  281. function adminDoAddCategory(){
  282. $sid=is_numeric($this->get_args('sid'))?$this->get_args('sid'):0;
  283. $cid=is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  284. if(!empty($sid)){
  285. Doo::loadModel ( 'L_category' );
  286. Doo::loadModel ( 'staff' );
  287. $staff = new staff ();
  288. $L_category = new L_category ();
  289. $stfInfo=$staff->getOne(array('where'=>'sid ='.$sid,'asArray'=>true));
  290. if($stfInfo['cid']==$cid)
  291. return "/adminuser";
  292. $othcid=explode(',', $stfInfo['othercid']);
  293. if(in_array($cid, $othcid))
  294. return "/adminuser";
  295. array_push($othcid, $cid);
  296. $strCid=implode(',',array_filter($othcid));
  297. $catename=$L_category->getCategoryById($cid);
  298. $othcategory=explode(',', $stfInfo['othercategory']);
  299. array_push($othcategory, $catename[0]['title']);
  300. $strcategory=implode(',',array_filter($othcategory));
  301. $staff->sid=$sid;
  302. $staff->othercid=$strCid;
  303. $staff->othercategory=$strcategory;
  304. $staff->update();
  305. }
  306. return "/adminuser";
  307. }
  308. function adminDeleteUser(){
  309. $sid= is_numeric($this->params['sid'])?$this->params['sid']:0;
  310. if (!empty($sid)){
  311. Doo::loadModel ( 'staff' );
  312. $staff = new staff ();
  313. $staff->sid=$sid;
  314. $staff->delete();
  315. }
  316. return "/adminuser";
  317. }
  318. function adminproduct(){
  319. $data['memu']="adminproduct";
  320. $data['staff']=$this->staff;
  321. Doo::loadModel ( 'product' );
  322. Doo::loadModel ( 'longle' );
  323. $product = new product ();
  324. $longle = new longle ();
  325. $data['product']=$product->getProudct();
  326. foreach ($data['product'] as $key=>$value){
  327. $data['product'][$key]['count']=$longle->count(array('where'=>'product="'.$value['title'].'"'));
  328. }
  329. $this->render ( "/admin/admin_product", $data );
  330. }
  331. function addproduct(){
  332. $title=$this->get_args('title')?$this->get_args('title'):"";
  333. if(!empty($title)){
  334. Doo::loadModel ( 'product' );
  335. $product = new product ();
  336. $product->title=$title;
  337. $product->insert();
  338. }
  339. return "/adminproduct";
  340. }
  341. function adminDeleteProduct(){
  342. $pid= is_numeric($this->params['pid'])?$this->params['pid']:0;
  343. if (!empty($pid)){
  344. Doo::loadModel ( 'product' );
  345. $product = new product ();
  346. $product->pid=$pid;
  347. $product->delete();
  348. }
  349. return "/adminproduct";
  350. }
  351. function adminEdiProduct(){
  352. $pid= is_numeric($this->params['pid'])?$this->params['pid']:0;
  353. $msg= isset($this->params['msg'])?$this->params['msg']:"";
  354. if(!empty($pid)){
  355. $data['msg']=urldecode($msg);
  356. Doo::loadModel ( 'product' );
  357. $product = new product ();
  358. $data['productInfo']=$product->getProductById($pid);
  359. $data['memu']="adminproduct";
  360. $data['staff']=$this->staff;
  361. $this->render ( "/admin/admin_EdiProduct", $data );
  362. }else
  363. return "/adminproduct";
  364. }
  365. function adminDoEdiProduct(){
  366. $pid=is_numeric($this->get_args('pid'))?$this->get_args('pid'):"";
  367. $title=$this->get_args('title')?$this->get_args('title'):"";
  368. $typeid=$this->get_args('typeid')?$this->get_args('typeid'):"";
  369. if(!empty($pid)&&!empty($title)&&!empty($typeid)){
  370. $msg="";
  371. Doo::loadModel ( 'product' );
  372. $product = new product ();
  373. $product->pid=$pid;
  374. $product->title=$title;
  375. $product->typeid=$typeid;
  376. $product->update();
  377. return "/adminproduct";
  378. }else{
  379. return "/adminproduct";
  380. }
  381. }
  382. function adminverify(){
  383. Doo::loadModel('staff');
  384. Doo::loadModel("verify");
  385. $verify=new verify();
  386. $staff=new staff();
  387. Doo::loadModel("role");
  388. $role=new role();
  389. $data['staffList']=$staff->find(array('select'=>'username,sid,avatar','asArray'=>true));
  390. $list=$verify->find(array('asArray'=>true));
  391. $roleList=$role->find(array('asArray'=>true));
  392. foreach ($roleList as $key=>$value){
  393. $staffList=json_decode($value['staff']);
  394. foreach ($staffList as $k=>$v){
  395. $staffList[$k]=substr(strstr($v, '_'), 1);
  396. }
  397. $roleList[$key]['staff']=implode(',', $staffList);
  398. }
  399. foreach ($list as $key=>$value){
  400. $name=json_decode($value['staff']);
  401. $list[$key]['staff']="";
  402. foreach ($name as $k=>$v){
  403. if ($v[1]=='ROLE'){
  404. $roleInfo=$role->getOne(array('where'=>'rid = "'.$v[0].'"','asArray'=>true));
  405. $v[1]=$roleInfo['name'];
  406. }
  407. $list[$key]['staff'].=" ".$v[1];
  408. }
  409. }
  410. $data['roleList']=$roleList;
  411. $data['verify']=$list;
  412. $data['memu']="verify";
  413. $data['staff']=$this->staff;
  414. $this->render ( "/admin/admin_reportGroup", $data );
  415. }
  416. function addVerify(){
  417. $description=$this->get_args('description')?$this->get_args('description'):"";
  418. $staff=$this->get_args('staff')?$this->get_args('staff'):"";
  419. $uidlist=$this->get_args('uidlist')?$this->get_args('uidlist'):"";
  420. $uidlist=explode(",", $uidlist);
  421. Doo::loadModel("role");
  422. $role=new role();
  423. $list=array();
  424. foreach ($uidlist as $key=>$value){
  425. $info=explode(":", $value);
  426. if ($info[1]=='ROLE'){
  427. $roleInfo=$role->getOne(array('where'=>'rid = "'.$info[0].'"','asArray'=>true));
  428. array_push($info, $roleInfo['staff']);
  429. }
  430. array_push($list, $info);
  431. }
  432. if(!empty($description)&&!empty($list)){
  433. Doo::loadModel("verify");
  434. $verify=new verify();
  435. $verify->description=$description;
  436. $verify->staff=json_encode($list);
  437. $verify->insert();
  438. }
  439. return "/adminverify";
  440. }
  441. function adminRole(){
  442. Doo::loadModel('staff');
  443. $staff=new staff();
  444. Doo::loadModel("verify");
  445. $verify=new verify();
  446. Doo::loadModel("role");
  447. $role=new role();
  448. $data['staffList']=$staff->find(array('select'=>'username,sid,avatar','asArray'=>true));
  449. $list=$verify->find(array('asArray'=>true));
  450. $roleList=$role->find(array('asArray'=>true));
  451. foreach ($list as $key=>$value){
  452. $name=json_decode($value['staff']);
  453. $list[$key]['staff']="";
  454. foreach ($name as $k=>$v){
  455. $list[$key]['staff'].=" ".$v[1];
  456. }
  457. }
  458. foreach ($roleList as $key=>$value){
  459. $staff=json_decode($value['staff']);
  460. foreach ($staff as $k=>$v){
  461. //print_r($info);
  462. //$staff[$k]=substr(strstr($v, '_'), 1);
  463. $info=explode('_', $v);
  464. $staff[$k]=$info;
  465. }
  466. $roleList[$key]['list']=$staff;
  467. }
  468. $data['roleList']=$roleList;
  469. $data['verify']=$list;
  470. $data['memu']="verify";
  471. $data['staff']=$this->staff;
  472. $this->render ( "/admin/adminReportGroupRole", $data );
  473. }
  474. function addRole(){
  475. $name=$this->get_args('title')?$this->get_args('title'):"";
  476. $staff=$this->get_args('staff')?$this->get_args('staff'):"";
  477. $list=array();
  478. foreach ($staff as $key=>$value){
  479. $na=explode(":", $value);
  480. array_push($list, $na[0].'_'.$na[1]);
  481. }
  482. if(!empty($name)&&!empty($list)){
  483. Doo::loadModel("role");
  484. $role=new role();
  485. $role->name=$name;
  486. $role->staff=json_encode($list);
  487. $role->insert();
  488. }
  489. return "/adminRole";
  490. }
  491. function delRole(){
  492. $rid= isset($this->params['rid'])?$this->params['rid']:0;
  493. if(!empty($rid)){
  494. Doo::loadModel("role");
  495. $role=new role();
  496. $role->delete(array('where'=>'rid="'.$rid.'"'));
  497. }
  498. return "/adminRole";
  499. }
  500. function updateRole(){
  501. $oldStaff=$this->get_args('oldStaff')?$this->get_args('oldStaff'):"";
  502. $newStaff=$this->get_args('newStaff')?$this->get_args('newStaff'):"";
  503. $rid=$this->get_args('rid')?$this->get_args('rid'):"";
  504. if(!empty($oldStaff)&&!empty($newStaff)&&!empty($rid)){
  505. Doo::loadModel("role");
  506. $role=new role();
  507. $roleInfo=$role->getOne(array('where'=>'rid = "'.$rid.'"','asArray'=>true));
  508. $staffList=json_decode($roleInfo['staff'],true);
  509. foreach ($staffList as $key=>$value){
  510. if ($value==$oldStaff){
  511. $staffList[$key]=$newStaff;
  512. break;
  513. }
  514. }
  515. $role->staff=json_encode($staffList);
  516. $role->update(array('where'=>'rid = "'.$rid.'"'));
  517. }
  518. return "/adminRole";
  519. }
  520. function adminExecute(){
  521. Doo::loadModel('staff');
  522. $staff=new staff();
  523. Doo::loadModel("execute");
  524. $execute=new execute();
  525. $data['staffList']=$staff->find(array('select'=>'username,sid,avatar','asArray'=>true));
  526. $list=$execute->find(array('asArray'=>true));
  527. $execute=array('借款执行人'=>'','借款费用执行人'=>'','报销单执行人'=>'','对公汇款执行人'=>'');
  528. foreach ($list as $key=>$value){
  529. $name=json_decode($value['staff']);
  530. $staffString="";
  531. if (!empty($name)){
  532. foreach ($name as $k=>$v){
  533. $staffString.=" ".$v[1].'<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/'.$v[0].'/'.$value['eid'].'\'" title="删除" class="icon-">k</a>';
  534. }
  535. }
  536. foreach ($execute as $k=>$v){
  537. if ($k==$value['mold']){
  538. $execute[$k]=$name=$staffString;
  539. }
  540. }
  541. }
  542. //print_r($execute);die;
  543. $data['execute']=$execute;
  544. $data['memu']="verify";
  545. $data['staff']=$this->staff;
  546. $this->render ( "/admin/adminCarriedout", $data );
  547. }
  548. function addExecute(){
  549. $mold=$this->get_args('mold')?$this->get_args('mold'):"";
  550. $staff=$this->get_args('staff')?$this->get_args('staff'):"";
  551. if(!empty($mold)&&!empty($staff)){
  552. Doo::loadModel("execute");
  553. $execute=new execute();
  554. $executeInfo=$execute->getOne(array('where'=>'mold ="'.$mold.'" ','asArray'=>true));
  555. if (empty($executeInfo)){
  556. $list=array();
  557. foreach ($staff as $key=>$value){
  558. $info=explode(":", $value);
  559. array_push($list, $info);
  560. }
  561. $execute->mold=$mold;
  562. $execute->staff=json_encode($list);
  563. $execute->insert();
  564. }else{
  565. $list=json_decode($executeInfo['staff'],true);
  566. foreach ($staff as $k=>$v){
  567. $info=explode(":", $v);
  568. foreach ($list as $key=>$value){
  569. if($value[1]==$info[1]){
  570. unset($staff[$k]);
  571. break;
  572. }
  573. }
  574. }
  575. foreach ($staff as $k=>$v){
  576. $info=explode(":", $v);
  577. array_push($list, $info);
  578. }
  579. $execute->staff=json_encode($list);
  580. $execute->update(array('where'=>'eid = '.$executeInfo['eid']));
  581. }
  582. }
  583. return "/adminExecute";
  584. }
  585. function delExecute(){
  586. $uid=isset($this->params['uid'])&&is_numeric($this->params['uid'])?$this->params['uid']:0;
  587. $eid=isset($this->params['eid'])&&is_numeric($this->params['eid'])?$this->params['eid']:0;
  588. if(!empty($uid)&&!empty($eid)){
  589. Doo::loadModel("execute");
  590. $execute=new execute();
  591. $executeInfo=$execute->getOne(array('where'=>'eid ="'.$eid.'" ','asArray'=>true));
  592. if (empty($executeInfo))
  593. return "/adminExecute";
  594. $ini=array();
  595. $list=json_decode($executeInfo['staff'],true);
  596. foreach ($list as $k=>$v){
  597. if ($v[0]==$uid){
  598. $ini=$list[$k];
  599. unset($list[$k]);break;
  600. }
  601. }
  602. file_put_contents("protected/config/execute/execute.ini", ",".$ini[0], FILE_APPEND);
  603. $execute->staff=json_encode($list);
  604. $execute->update(array('where'=>'eid = '.$executeInfo['eid']));
  605. }
  606. return "/adminExecute";
  607. }
  608. function ajaxRoleStaff(){
  609. $name=$this->get_args('name')?$this->get_args('name'):"";
  610. Doo::loadModel('staff');
  611. $staff=new staff();
  612. $staffList=$staff->find(array('select'=>'username,sid,avatar','where'=>'username != "'.$name.'" and username !="admin"','asArray'=>true));
  613. $html='';
  614. foreach ($staffList as $key=>$value){
  615. $html.='<option value='.$value['sid'].'_'.$value['username'].'>'.$value['username'].'</option>';
  616. }
  617. echo json_encode(array("success"=>true,'html'=>$html));die;
  618. }
  619. function loadCVS(){
  620. Doo::loadModel('longle');
  621. $longle=new longle();
  622. $list=$longle->find(array('select'=>'key_num','asArray' => TRUE));
  623. $file = fopen(DOO::conf()->SITE_PATH."upload/key2.csv",'r');
  624. while ($data = fgetcsv($file)) {
  625. $goods_list[$data[0]] = $data[1] ;
  626. }
  627. fclose($file);
  628. $sqlArray=array();
  629. $sql='UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  630. foreach($list as $key=>$value){
  631. if(array_key_exists($value['key_num'],$goods_list)){
  632. //echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  633. //$longle->SerialNumber=$goods_list[$value['key_num']];
  634. //$longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  635. $sql.=' WHEN "'.$value['key_num'].'" THEN "'.$goods_list[$value['key_num']].'" ';
  636. array_push($sqlArray, '"'.$value['key_num'].'"');
  637. unset($goods_list[$value['key_num']]);
  638. }
  639. }
  640. $sql.='END WHERE key_num IN ('.implode(',', $sqlArray).')';
  641. echo $sql.'<br/>--------------------------------<br/>';
  642. foreach ($goods_list as $key=>$value){
  643. echo $key.','.$value.'<br/>';
  644. }
  645. }
  646. private function getRandChar($length){
  647. $str = null;
  648. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  649. $max = strlen($strPol)-1;
  650. for($i=0;$i<$length;$i++){
  651. $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
  652. }
  653. return $str;
  654. }
  655. private function getReceiptCount(){
  656. $status=2;
  657. $year=date('Y');
  658. Doo::loadModel('receipt');
  659. $receipt=new receipt();
  660. Doo::loadModel('verify');
  661. $verify=new verify();
  662. //user verify ID
  663. $vidList=array();
  664. $verifyDetail=$verify->find(array('where'=>'staff like "%\"'.$this->staff[0]['sid'].'\"%"','asArray'=>true));
  665. foreach ($verifyDetail as $key=>$value){
  666. array_push($vidList, $value['vid']);
  667. }
  668. $vid=implode(",", $vidList);
  669. if(empty($verifyDetail))
  670. $vid=0;
  671. $dateCondition=" and Year(date) =".$year;
  672. $approvalCondition=' and verifyStaff not like "%\"'.$this->staff[0]['sid'].'\":{%" ';
  673. $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  674. return count($receiptList);
  675. }
  676. /**
  677. * 格式化excel文件为数组
  678. * @param unknown_type $file_url
  679. * @param unknown_type $mcid
  680. */
  681. function _format_excel_to_array($file_url = "") {
  682. if (! file_exists ( $file_url ))
  683. return array ();
  684. Doo::loadClass ( 'PHPExcel' );
  685. $PHPExcel = new PHPExcel ();
  686. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  687. if (! $PHPReader->canRead ( $file_url )) {
  688. $PHPReader = new PHPExcel_Reader_Excel5 ();
  689. if (! $PHPReader->canRead ( $file_url )) {
  690. echo 'no Excel';
  691. return;
  692. }
  693. }
  694. $PHPExcel = $PHPReader->load ( $file_url );
  695. /**读取excel文件中的第一个工作表*/
  696. $currentSheet = $PHPExcel->getSheet ( 0 );
  697. /**取得最大的列号*/
  698. $allColumn = $currentSheet->getHighestColumn ();
  699. /**取得一共有多少行*/
  700. $allRow = $currentSheet->getHighestRow ();
  701. $excel_array = array ();
  702. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  703. $excel_column = array ();
  704. //后期改进
  705. if($allColumn=='AM')
  706. $allColumn='Z';
  707. /**从第A列开始输出*/
  708. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  709. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  710. /**ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',*/
  711. $val = "'" . addslashes ( $val ) . "'";
  712. if ($currentColumn == 'A')
  713. $excel_column ['key_num'] = $val;
  714. elseif ($currentColumn == 'C')
  715. $excel_column ['product'] = $val;
  716. elseif ($currentColumn == 'D'){
  717. $val=str_replace("'","",$val);
  718. $excel_column ['make_day'] = $this->excelTime($val);
  719. }elseif($currentColumn == 'E'){
  720. $val=str_replace("'","",$val);
  721. $excel_column ['alloted_time'] = $this->excelTime($val);
  722. }elseif($currentColumn == 'F'){
  723. $val=str_replace("'","",$val);
  724. $excel_column ['version'] = $val;
  725. }elseif ($currentColumn == 'B'){
  726. $val=str_replace("'","",$val);
  727. $excel_column ['SerialNumber'] = $val;
  728. }
  729. }
  730. array_push ( $excel_array, $excel_column );
  731. }
  732. return $excel_array;
  733. }
  734. function excelTime($date, $time = false)
  735. {
  736. if (function_exists ( 'GregorianToJD' ))
  737. {
  738. if (is_numeric ( $date ))
  739. {
  740. $jd = GregorianToJD ( 1, 1, 1970 );
  741. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  742. $date = explode ( '/', $gregorian );
  743. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" .
  744. str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" .
  745. str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  746. return $date_str;
  747. }
  748. } else
  749. {
  750. $date = $date > 25568 ? $date + 1 : 25569;
  751. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  752. $ofs = (70 * 365 + 17 + 2) * 86400;
  753. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  754. }
  755. return $date;
  756. }
  757. function _GetFileEXT($filename) {
  758. $pics = explode ( '.', $filename );
  759. $num = count ( $pics );
  760. return $pics [$num - 1];
  761. }
  762. /**
  763. * 获取get或者POST值
  764. * @param string $name 属性名称
  765. * @return fixed 值
  766. */
  767. function get_args($name) {
  768. if (isset ( $_GET [$name] )) {
  769. if (is_array ( $_GET [$name] ))
  770. return $_GET [$name];
  771. else {
  772. return addslashes ( $_GET [$name] );
  773. //return $_GET [$name] ;
  774. }
  775. } elseif (isset ( $_POST [$name] )) {
  776. if (is_array ( $_POST [$name] ))
  777. return $_POST [$name];
  778. else {
  779. return addslashes ( $_POST [$name] );
  780. //return $_POST [$name];
  781. }
  782. } else {
  783. return false;
  784. }
  785. }
  786. function get_previous($on_page = 1) {
  787. return $on_page != 0 ? $on_page - 1 : $on_page;
  788. }
  789. /**
  790. * 获得分页数据
  791. * @param unknown_type $table
  792. * @param unknown_type $condition
  793. * @param unknown_type $on_page
  794. * @param unknown_type $page_size
  795. */
  796. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "",$tagSQL) {
  797. $page_c = "";
  798. $page ['previous'] = $this->get_previous ( $on_page );
  799. $page ['on_page'] = $on_page;
  800. $total_count = $this->get_table_Tcount ( $table, $condition,$tagSQL );
  801. $total = intval ( $total_count / $page_size );
  802. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  803. $page ['total_data'] = $total_count;
  804. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  805. $i = 1;
  806. $page_max = 1;
  807. if ($on_page > 10) {
  808. $page_max = intval ( $on_page / 10 ) + 1;
  809. $i = intval ( $on_page / 10 ) * 10 - 1;
  810. }
  811. $page ['page'] = $page_c;
  812. $page ['lower'] = (-- $on_page) * $page_size;
  813. return $page;
  814. }
  815. /**
  816. * 获得分页数据
  817. * @param unknown_type $table
  818. * @param unknown_type $condition
  819. * @param unknown_type $on_page
  820. * @param unknown_type $page_size
  821. */
  822. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page",$staffid="",$search,$tooltip,$cateid,$tagSQL) {
  823. $page_c = "";
  824. $page ['previous'] = $this->get_previous ( $on_page );
  825. $page ['on_page'] = $on_page;
  826. $total_count = $this->get_table_count ( $table, $condition ,$staffid,$search,$tooltip,$cateid,$tagSQL);
  827. $total = intval ( $total_count / $page_size );
  828. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  829. $page ['total_data'] = $total_count;
  830. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  831. $i = 1;
  832. $page_max = 1;
  833. if ($on_page > 10) {
  834. $page_max = intval ( $on_page / 10 ) + 1;
  835. $i = intval ( $on_page / 10 ) * 10 - 1;
  836. }
  837. for(; $i <= $page ['total_page']; $i ++) {
  838. if ($i == $on_page) {
  839. if ($other == "page")
  840. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  841. else
  842. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  843. } else if ($other == "page")
  844. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  845. else
  846. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  847. if ($i == (10 * $page_max))
  848. break;
  849. }
  850. $page ['page'] = $page_c;
  851. $page ['lower'] = (-- $on_page) * $page_size;
  852. return $page;
  853. }
  854. /**
  855. * 获取总页数
  856. * @param unknown_type $table
  857. * @param unknown_type $condition
  858. */
  859. public function get_table_Tcount($table = "", $condition = "",$tagSQL) {
  860. if ($tagSQL)
  861. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where ".$condition ;
  862. else
  863. $sql = "select count(*) as count from CLD_company where " . $condition ;
  864. $query = Doo::db ()->query ( $sql );
  865. $result = $query->fetch ();
  866. return $result ['count'];
  867. }
  868. /**
  869. * 获取总页数
  870. * @param unknown_type $table
  871. * @param unknown_type $condition
  872. */
  873. public function get_table_count($table = "", $condition = "",$staffid="",$search,$tooltip,$cateid,$tagSQL) {
  874. //$sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  875. //echo $staffid;die;
  876. //
  877. if (!empty($staffid)){
  878. //$staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  879. $sql = "select count(*) as count from CLD_client as b left join CLD_tag_client as c on (b.cid=c.client) where 1 " . $condition ;
  880. }else{
  881. if(strlen($condition)==1||empty($condition))
  882. $sql = "select count(*) as count from CLD_client as a ".$condition;
  883. else
  884. $sql = "select count(*) as count from CLD_client as a left join CLD_tag_client as c on (a.cid=c.client) where 1 ".$condition;
  885. }
  886. if(!empty($search))
  887. $sql = "select count(*) as count from CLD_client as a where 1 ".$condition ;
  888. if(!empty($tooltip)){
  889. $condition=str_replace("a.","c.",$condition);
  890. if ($tagSQL)
  891. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_tag_client as c on (a.cid=c.client) left join CLD_client as b on (c.client=b.cid ) where a.name like '%".$tooltip."%' and a.cateid = ".$cateid." ".$condition ;
  892. else
  893. $sql = "select count(*) as count from CLD_C_tooltip as a left join CLD_client as b on (a.cid=b.cid ) where a.name like '%".$tooltip."%' and a.cateid = ".$cateid." ".$condition ;
  894. }
  895. //echo $sql;
  896. $query = Doo::db ()->query ( $sql );
  897. $result = $query->fetch ();
  898. return $result ['count'];
  899. }
  900. //录入用户假期信息
  901. public function AddStaffHoliday(){
  902. Doo::loadModel('staff');
  903. $staff = new staff();
  904. $stafflist = $staff->find(array('select' => 'sid,hiredate','where' => 'nature=1', 'asArray' => TRUE));
  905. var_dump($stafflist);
  906. exit;
  907. Doo::loadModel('holidaystaff');
  908. }
  909. }
  910. ?>