AdminController.php 31 KB

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