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