AdminController.php 31 KB

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