AdminController.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class AdminController extends DooController {
  6. public $staff;
  7. public $nature = array (
  8. '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 (
  25. '1' => array (
  26. 'L',
  27. '点击筛选标签'
  28. ),
  29. '2' => array (
  30. 'M',
  31. '点击筛选标签'
  32. ),
  33. '3' => array (
  34. 'N',
  35. '点击筛选标签'
  36. ),
  37. '4' => array (
  38. 'O',
  39. '点击筛选标签'
  40. ),
  41. '5' => array (
  42. 'P',
  43. '点击筛选标签'
  44. ),
  45. '6' => array (
  46. 'Q',
  47. '点击筛选标签'
  48. ),
  49. '7' => array (
  50. 'R',
  51. '点击筛选标签'
  52. )
  53. );
  54. public $webPath = "http://cld.smartcost.com.cn/upload/emailAnnex/";
  55. function __construct() {
  56. if (isset ( $_COOKIE ["adStaff"] )) {
  57. if (! empty ( $_COOKIE ["adStaff"] )) {
  58. Doo::loadModel ( 'staff' );
  59. $staff = new staff ();
  60. $this->staff = $staff->getUserByIdList ( $_COOKIE ["adStaff"] );
  61. if ($this->staff [0] ['isadmin'] == 1 && $this->staff [0] ['username'] == 'admin') {
  62. return "/adminoffice";
  63. }
  64. }
  65. }
  66. Doo::loadCore ( 'uri/DooUriRouter' );
  67. $router = new DooUriRouter ();
  68. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  69. if ($routeRs ['1'] != "adlogin") {
  70. header ( 'Content-Type:text/html;charset=utf-8' );
  71. @header ( "Location: /adlogin" );
  72. }
  73. }
  74. function adlogin() {
  75. $passwork = isset ( $_POST ['passwork'] ) ? $_POST ['passwork'] : "";
  76. $uid = isset ( $_POST ['user'] ) ? $_POST ['user'] : "";
  77. Doo::loadModel ( 'staff' );
  78. $staff = new staff ();
  79. if (! empty ( $passwork )) {
  80. $userinfo = $staff->getOne ( array (
  81. 'where' => "username='admin'",
  82. 'asArray' => true
  83. ) );
  84. if (! empty ( $userinfo )) {
  85. if ($userinfo ['username'] == $uid && $userinfo ['passwork'] == md5 ( $passwork )) {
  86. setcookie ( "adStaff", $userinfo ['sid'], time () + 36000, "/" );
  87. return "/adminoffice";
  88. }
  89. }
  90. }
  91. $data ['staff'] = "";
  92. $data ['login'] = "";
  93. if (! empty ( $passwork ))
  94. $data ['login'] = "inputErrow";
  95. $this->render ( "/admin/adminLogin", $data );
  96. }
  97. function adout() {
  98. setcookie ( "adStaff", "", time () - 3600, "/" );
  99. return "/adlogin";
  100. }
  101. function adminPW() {
  102. $msg = $this->params ['msg'] ? $this->params ['msg'] : "";
  103. $data ['msg'] = "msg";
  104. $data ['memu'] = "adminpw";
  105. $data ['staff'] = $this->staff;
  106. $data ['msg'] = urldecode ( $this->params ['msg'] );
  107. $this->render ( "/admin/admin-admininfo", $data );
  108. }
  109. function upAdP() {
  110. $opw = $this->get_args ( 'opw' ) ? $this->get_args ( 'opw' ) : "";
  111. $npw1 = $this->get_args ( 'npw1' ) ? $this->get_args ( 'npw1' ) : "";
  112. $npw2 = $this->get_args ( 'npw2' ) ? $this->get_args ( 'npw2' ) : "";
  113. if (! empty ( $opw )) {
  114. Doo::loadModel ( 'staff' );
  115. $staff = new staff ();
  116. $userinfo = $staff->getOne ( array (
  117. 'where' => "username='admin'",
  118. 'asArray' => true
  119. ) );
  120. if (! empty ( $userinfo )) {
  121. if ($userinfo ['sid'] == $_COOKIE ["adStaff"] && $userinfo ['passwork'] == md5 ( $opw )) {
  122. if (($npw1 == $npw2) && ($npw1 != "")) {
  123. $staff->passwork = md5 ( $npw1 );
  124. $staff->update ( array (
  125. 'where' => "sid='" . $_COOKIE ["adStaff"] . "'"
  126. ) );
  127. return "/adminpw/" . urlencode ( '密码修改成功' );
  128. } else
  129. return "/adminpw/" . urlencode ( '新密码不一致' );
  130. } else
  131. return "/adminpw/" . urlencode ( '旧密码不正确' );
  132. } else
  133. return "/adminpw/" . urlencode ( '未找到用户' );
  134. } else
  135. return "/adminpw/" . urlencode ( '请输入旧密码' );
  136. }
  137. function adminoffice() {
  138. $data ['memu'] = "adminoffice";
  139. $data ['staff'] = $this->staff;
  140. Doo::loadModel ( 'L_category' );
  141. Doo::loadModel ( 'staff' );
  142. Doo::loadModel ( 'district' );
  143. $district = new district ();
  144. $staff = new staff ();
  145. $L_category = new L_category ();
  146. $data ['category'] = $L_category->getCategory ();
  147. $data ['district'] = $district->get_lv ( 1 );
  148. foreach ( $data ['category'] as $key => $value ) {
  149. $data ['category'] [$key] ['count'] = $staff->count ( array (
  150. 'where' => 'cid=' . $value ['cid']
  151. ) );
  152. }
  153. $data ['msg'] = urldecode ( $this->params ['msg'] );
  154. $this->render ( "/admin/admin_group", $data );
  155. }
  156. function addCategory() {
  157. $msg = "添加成功";
  158. $title = isset ( $_POST ['title'] ) ? $_POST ['title'] : "";
  159. $district = isset ( $_POST ['district'] ) ? $_POST ['district'] : "";
  160. if (! empty ( $title ) && ! empty ( $district )) {
  161. Doo::loadModel ( 'L_category' );
  162. $L_category = new L_category ();
  163. $L_category->title = $title;
  164. $L_category->districtid = $district;
  165. $L_category->insert ();
  166. } else {
  167. $msg = "请输入正确的信息";
  168. }
  169. return "/adminoffice/" . $msg;
  170. }
  171. function adminuser() {
  172. $data ['memu'] = "adminuser";
  173. $data ['staff'] = $this->staff;
  174. Doo::loadModel ( 'L_category' );
  175. Doo::loadModel ( 'staff' );
  176. $staff = new staff ();
  177. $L_category = new L_category ();
  178. $data ['category'] = $L_category->getCategory ();
  179. $data ['stafflist'] = $staff->getStaff ();
  180. $data ['staff'] = $this->staff;
  181. $this->render ( "/admin/admin_user", $data );
  182. }
  183. function adduser() {
  184. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  185. $password = $this->get_args ( 'password' ) ? $this->get_args ( 'password' ) : "";
  186. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  187. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  188. $nature = is_numeric ( $this->get_args ( 'nature' ) ) ? $this->get_args ( 'nature' ) : 1;
  189. if (! empty ( $username ) && ! empty ( $password ) && ! empty ( $cid ) && ! empty ( $hiredate ) && ! empty ( $nature )) {
  190. Doo::loadModel ( 'L_category' );
  191. Doo::loadModel ( 'staff' );
  192. Doo::loadModel ( 'tag' );
  193. Doo::loadModel ( 'holidaystaff' );
  194. $staff = new staff ();
  195. $L_category = new L_category ();
  196. // 加入默认总部分类
  197. $cagegory = $L_category->getCategoryById ( $cid );
  198. // 根据这个分类加入管理权限
  199. if ($cagegory [0] ['defult'] == 1) {
  200. $staff->isadmin = 1;
  201. }
  202. $staff->username = $username;
  203. $staff->passwork = md5 ( $password );
  204. $staff->cid = $cagegory [0] ['cid'];
  205. $staff->category = $cagegory [0] ['title'];
  206. $staff->hiredate = $hiredate;
  207. $staff->nature = $nature;
  208. $id = $staff->insert ();
  209. $holidaystaff = new HStaff ();
  210. $holidaystaff->uid = $id;
  211. $holidaystaff->insert();
  212. $staffmsg = $staff->getUserById($id);
  213. $this->updateAnnualLeave($staffmsg[0]);
  214. for ($i=1;$i<=7;$i++){
  215. $tag = new tag ();
  216. $tag->name = "个人标签";
  217. $tag->sid = $id;
  218. $tag->colorid = $i;
  219. $tag->insert ();
  220. }
  221. }
  222. return "/adminuser";
  223. }
  224. function adminEdiUser() {
  225. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  226. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  227. if (! empty ( $sid )) {
  228. $data ['msg'] = urldecode ( $msg );
  229. Doo::loadModel ( 'L_category' );
  230. Doo::loadModel ( 'staff' );
  231. $staff = new staff ();
  232. $L_category = new L_category ();
  233. $data ['newPw'] = '';
  234. $data ['staffInfo'] = $staff->getUserById ( $sid );
  235. $data ['category'] = $L_category->getCategory ();
  236. $data ['staff'] = $this->staff;
  237. $data ['memu'] = "adminuser";
  238. $this->render ( "/admin/admin_EdiUser", $data );
  239. } else
  240. return "/adminuser";
  241. }
  242. function adminResetUserPw() {
  243. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  244. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  245. if (! empty ( $sid )) {
  246. $data ['msg'] = urldecode ( $msg );
  247. Doo::loadModel ( 'L_category' );
  248. Doo::loadModel ( 'staff' );
  249. $staff = new staff ();
  250. $L_category = new L_category ();
  251. $newPw = $this->getRandChar ( 6 );
  252. $staff->sid = $sid;
  253. $staff->passwork = md5 ( $newPw );
  254. $staff->update ();
  255. $data ['newPw'] = $newPw;
  256. $data ['staffInfo'] = $staff->getUserById ( $sid );
  257. $data ['category'] = $L_category->getCategory ();
  258. $data ['staff'] = $this->staff;
  259. $data ['memu'] = "adminuser";
  260. $this->render ( "/admin/admin_EdiUser", $data );
  261. } else
  262. return "/adminuser";
  263. }
  264. function adminDoEdiUser() {
  265. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  266. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  267. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  268. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $this->get_args ( 'qq' ) : 0;
  269. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  270. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  271. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  272. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  273. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  274. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  275. if (! empty ( $sid )) {
  276. $msg = "";
  277. Doo::loadModel ( 'L_category' );
  278. Doo::loadModel ( 'staff' );
  279. $staff = new staff ();
  280. $L_category = new L_category ();
  281. $categoryInfo = $L_category->getCategoryById ( $cid );
  282. $staff->sid = $sid;
  283. if ($cid != 0) {
  284. $staff->cid = $categoryInfo [0] ['cid'];
  285. $staff->category = $categoryInfo [0] ['title'];
  286. }
  287. if ($categoryInfo [0] ['defult'] == 1) {
  288. $staff->isadmin = 1;
  289. } else {
  290. $staff->isadmin = 0;
  291. }
  292. if (! empty ( $username ))
  293. $staff->username = $username;
  294. if (! empty ( $gender ))
  295. $staff->gender = $gender;
  296. if (! empty ( $qq ) && is_numeric ( $qq ))
  297. $staff->qq = $qq;
  298. if (! empty ( $phone ))
  299. $staff->phone = $phone;
  300. if (! empty ( $telephone ))
  301. $staff->telephone = $telephone;
  302. if (! empty ( $email ) && filter_var ( $email, FILTER_VALIDATE_EMAIL ))
  303. $staff->email = $email;
  304. else
  305. $msg = "邮箱不正确";
  306. if (! empty ( $hiredate ))
  307. $staff->hiredate = $hiredate;
  308. $staff->nature = $nature;
  309. $staff->update ();
  310. $staffmsg = $staff->getUserById ( $sid );
  311. $this->updateAnnualLeave ( $staffmsg [0] );
  312. return "/edi/user/" . $sid . "/" . $msg;
  313. } else {
  314. return "/adminuser";
  315. }
  316. }
  317. function adminDoAddCategory() {
  318. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  319. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  320. if (! empty ( $sid )) {
  321. Doo::loadModel ( 'L_category' );
  322. Doo::loadModel ( 'staff' );
  323. $staff = new staff ();
  324. $L_category = new L_category ();
  325. $stfInfo = $staff->getOne ( array (
  326. 'where' => 'sid =' . $sid,
  327. 'asArray' => true
  328. ) );
  329. if ($stfInfo ['cid'] == $cid)
  330. return "/adminuser";
  331. $othcid = explode ( ',', $stfInfo ['othercid'] );
  332. if (in_array ( $cid, $othcid ))
  333. return "/adminuser";
  334. array_push ( $othcid, $cid );
  335. $strCid = implode ( ',', array_filter ( $othcid ) );
  336. $catename = $L_category->getCategoryById ( $cid );
  337. $othcategory = explode ( ',', $stfInfo ['othercategory'] );
  338. array_push ( $othcategory, $catename [0] ['title'] );
  339. $strcategory = implode ( ',', array_filter ( $othcategory ) );
  340. $staff->sid = $sid;
  341. $staff->othercid = $strCid;
  342. $staff->othercategory = $strcategory;
  343. $staff->update ();
  344. }
  345. return "/adminuser";
  346. }
  347. function adminDeleteUser() {
  348. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  349. if (! empty ( $sid )) {
  350. Doo::loadModel ( 'staff' );
  351. $staff = new staff ();
  352. $staff->sid = $sid;
  353. $staff->delete ();
  354. Doo::loadModel ('holidaystaff');
  355. $hstaff = new HStaff();
  356. $hstaff->uid = $sid;
  357. $hstaff->delete();
  358. }
  359. return "/adminuser";
  360. }
  361. function adminproduct() {
  362. $data ['memu'] = "adminproduct";
  363. $data ['staff'] = $this->staff;
  364. Doo::loadModel ( 'product' );
  365. Doo::loadModel ( 'longle' );
  366. $product = new product ();
  367. $longle = new longle ();
  368. $data ['product'] = $product->getProudct ();
  369. foreach ( $data ['product'] as $key => $value ) {
  370. $data ['product'] [$key] ['count'] = $longle->count ( array (
  371. 'where' => 'product="' . $value ['title'] . '"'
  372. ) );
  373. }
  374. $this->render ( "/admin/admin_product", $data );
  375. }
  376. function addproduct() {
  377. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  378. if (! empty ( $title )) {
  379. Doo::loadModel ( 'product' );
  380. $product = new product ();
  381. $product->title = $title;
  382. $product->insert ();
  383. }
  384. return "/adminproduct";
  385. }
  386. function adminDeleteProduct() {
  387. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  388. if (! empty ( $pid )) {
  389. Doo::loadModel ( 'product' );
  390. $product = new product ();
  391. $product->pid = $pid;
  392. $product->delete ();
  393. }
  394. return "/adminproduct";
  395. }
  396. function adminEdiProduct() {
  397. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  398. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  399. if (! empty ( $pid )) {
  400. $data ['msg'] = urldecode ( $msg );
  401. Doo::loadModel ( 'product' );
  402. $product = new product ();
  403. $data ['productInfo'] = $product->getProductById ( $pid );
  404. $data ['memu'] = "adminproduct";
  405. $data ['staff'] = $this->staff;
  406. $this->render ( "/admin/admin_EdiProduct", $data );
  407. } else
  408. return "/adminproduct";
  409. }
  410. function adminDoEdiProduct() {
  411. $pid = is_numeric ( $this->get_args ( 'pid' ) ) ? $this->get_args ( 'pid' ) : "";
  412. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  413. $typeid = $this->get_args ( 'typeid' ) ? $this->get_args ( 'typeid' ) : "";
  414. if (! empty ( $pid ) && ! empty ( $title ) && ! empty ( $typeid )) {
  415. $msg = "";
  416. Doo::loadModel ( 'product' );
  417. $product = new product ();
  418. $product->pid = $pid;
  419. $product->title = $title;
  420. $product->typeid = $typeid;
  421. $product->update ();
  422. return "/adminproduct";
  423. } else {
  424. return "/adminproduct";
  425. }
  426. }
  427. function adminverify() {
  428. Doo::loadModel ( 'staff' );
  429. Doo::loadModel ( "verify" );
  430. $verify = new verify ();
  431. $staff = new staff ();
  432. Doo::loadModel ( "role" );
  433. $role = new role ();
  434. $data ['staffList'] = $staff->find ( array (
  435. 'select' => 'username,sid,avatar',
  436. 'asArray' => true
  437. ) );
  438. $list = $verify->find ( array (
  439. 'asArray' => true
  440. ) );
  441. $roleList = $role->find ( array (
  442. 'asArray' => true
  443. ) );
  444. foreach ( $roleList as $key => $value ) {
  445. $staffList = json_decode ( $value ['staff'] );
  446. foreach ( $staffList as $k => $v ) {
  447. $staffList [$k] = substr ( strstr ( $v, '_' ), 1 );
  448. }
  449. $roleList [$key] ['staff'] = implode ( ',', $staffList );
  450. }
  451. foreach ( $list as $key => $value ) {
  452. $name = json_decode ( $value ['staff'] );
  453. $list [$key] ['staff'] = "";
  454. foreach ( $name as $k => $v ) {
  455. if ($v [1] == 'ROLE') {
  456. $roleInfo = $role->getOne ( array (
  457. 'where' => 'rid = "' . $v [0] . '"',
  458. 'asArray' => true
  459. ) );
  460. $v [1] = $roleInfo ['name'];
  461. }
  462. $list [$key] ['staff'] .= " " . $v [1];
  463. }
  464. }
  465. $data ['roleList'] = $roleList;
  466. $data ['verify'] = $list;
  467. $data ['memu'] = "verify";
  468. $data ['staff'] = $this->staff;
  469. $this->render ( "/admin/admin_reportGroup", $data );
  470. }
  471. function addVerify() {
  472. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  473. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  474. $uidlist = $this->get_args ( 'uidlist' ) ? $this->get_args ( 'uidlist' ) : "";
  475. $uidlist = explode ( ",", $uidlist );
  476. Doo::loadModel ( "role" );
  477. $role = new role ();
  478. $list = array ();
  479. foreach ( $uidlist as $key => $value ) {
  480. $info = explode ( ":", $value );
  481. if ($info [1] == 'ROLE') {
  482. $roleInfo = $role->getOne ( array (
  483. 'where' => 'rid = "' . $info [0] . '"',
  484. 'asArray' => true
  485. ) );
  486. array_push ( $info, $roleInfo ['staff'] );
  487. }
  488. array_push ( $list, $info );
  489. }
  490. if (! empty ( $description ) && ! empty ( $list )) {
  491. Doo::loadModel ( "verify" );
  492. $verify = new verify ();
  493. $verify->description = $description;
  494. $verify->staff = json_encode ( $list );
  495. $verify->insert ();
  496. }
  497. return "/adminverify";
  498. }
  499. function adminRole() {
  500. Doo::loadModel ( 'staff' );
  501. $staff = new staff ();
  502. Doo::loadModel ( "verify" );
  503. $verify = new verify ();
  504. Doo::loadModel ( "role" );
  505. $role = new role ();
  506. $data ['staffList'] = $staff->find ( array (
  507. 'select' => 'username,sid,avatar',
  508. 'asArray' => true
  509. ) );
  510. $list = $verify->find ( array (
  511. 'asArray' => true
  512. ) );
  513. $roleList = $role->find ( array (
  514. 'asArray' => true
  515. ) );
  516. foreach ( $list as $key => $value ) {
  517. $name = json_decode ( $value ['staff'] );
  518. $list [$key] ['staff'] = "";
  519. foreach ( $name as $k => $v ) {
  520. $list [$key] ['staff'] .= " " . $v [1];
  521. }
  522. }
  523. foreach ( $roleList as $key => $value ) {
  524. $staff = json_decode ( $value ['staff'] );
  525. foreach ( $staff as $k => $v ) {
  526. // print_r($info);
  527. // $staff[$k]=substr(strstr($v, '_'), 1);
  528. $info = explode ( '_', $v );
  529. $staff [$k] = $info;
  530. }
  531. $roleList [$key] ['list'] = $staff;
  532. }
  533. $data ['roleList'] = $roleList;
  534. $data ['verify'] = $list;
  535. $data ['memu'] = "verify";
  536. $data ['staff'] = $this->staff;
  537. $this->render ( "/admin/adminReportGroupRole", $data );
  538. }
  539. function addRole() {
  540. $name = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  541. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  542. $list = array ();
  543. foreach ( $staff as $key => $value ) {
  544. $na = explode ( ":", $value );
  545. array_push ( $list, $na [0] . '_' . $na [1] );
  546. }
  547. if (! empty ( $name ) && ! empty ( $list )) {
  548. Doo::loadModel ( "role" );
  549. $role = new role ();
  550. $role->name = $name;
  551. $role->staff = json_encode ( $list );
  552. $role->insert ();
  553. }
  554. return "/adminRole";
  555. }
  556. function delRole() {
  557. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  558. if (! empty ( $rid )) {
  559. Doo::loadModel ( "role" );
  560. $role = new role ();
  561. $role->delete ( array (
  562. 'where' => 'rid="' . $rid . '"'
  563. ) );
  564. }
  565. return "/adminRole";
  566. }
  567. function updateRole() {
  568. $oldStaff = $this->get_args ( 'oldStaff' ) ? $this->get_args ( 'oldStaff' ) : "";
  569. $newStaff = $this->get_args ( 'newStaff' ) ? $this->get_args ( 'newStaff' ) : "";
  570. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  571. if (! empty ( $oldStaff ) && ! empty ( $newStaff ) && ! empty ( $rid )) {
  572. Doo::loadModel ( "role" );
  573. $role = new role ();
  574. $roleInfo = $role->getOne ( array (
  575. 'where' => 'rid = "' . $rid . '"',
  576. 'asArray' => true
  577. ) );
  578. $staffList = json_decode ( $roleInfo ['staff'], true );
  579. foreach ( $staffList as $key => $value ) {
  580. if ($value == $oldStaff) {
  581. $staffList [$key] = $newStaff;
  582. break;
  583. }
  584. }
  585. $role->staff = json_encode ( $staffList );
  586. $role->update ( array (
  587. 'where' => 'rid = "' . $rid . '"'
  588. ) );
  589. }
  590. return "/adminRole";
  591. }
  592. function adminExecute() {
  593. Doo::loadModel ( 'staff' );
  594. $staff = new staff ();
  595. Doo::loadModel ( "execute" );
  596. $execute = new execute ();
  597. $data ['staffList'] = $staff->find ( array (
  598. 'select' => 'username,sid,avatar',
  599. 'asArray' => true
  600. ) );
  601. $list = $execute->find ( array (
  602. 'asArray' => true
  603. ) );
  604. $execute = array (
  605. '借款执行人' => '',
  606. '借款费用执行人' => '',
  607. '报销单执行人' => '',
  608. '对公汇款执行人' => ''
  609. );
  610. foreach ( $list as $key => $value ) {
  611. $name = json_decode ( $value ['staff'] );
  612. $staffString = "";
  613. if (! empty ( $name )) {
  614. foreach ( $name as $k => $v ) {
  615. $staffString .= " " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/' . $v [0] . '/' . $value ['eid'] . '\'" title="删除" class="icon-">k</a>';
  616. }
  617. }
  618. foreach ( $execute as $k => $v ) {
  619. if ($k == $value ['mold']) {
  620. $execute [$k] = $name = $staffString;
  621. }
  622. }
  623. }
  624. // print_r($execute);die;
  625. $data ['execute'] = $execute;
  626. $data ['memu'] = "verify";
  627. $data ['staff'] = $this->staff;
  628. $this->render ( "/admin/adminCarriedout", $data );
  629. }
  630. function addExecute() {
  631. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  632. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  633. if (! empty ( $mold ) && ! empty ( $staff )) {
  634. Doo::loadModel ( "execute" );
  635. $execute = new execute ();
  636. $executeInfo = $execute->getOne ( array (
  637. 'where' => 'mold ="' . $mold . '" ',
  638. 'asArray' => true
  639. ) );
  640. if (empty ( $executeInfo )) {
  641. $list = array ();
  642. foreach ( $staff as $key => $value ) {
  643. $info = explode ( ":", $value );
  644. array_push ( $list, $info );
  645. }
  646. $execute->mold = $mold;
  647. $execute->staff = json_encode ( $list );
  648. $execute->insert ();
  649. } else {
  650. $list = json_decode ( $executeInfo ['staff'], true );
  651. foreach ( $staff as $k => $v ) {
  652. $info = explode ( ":", $v );
  653. foreach ( $list as $key => $value ) {
  654. if ($value [1] == $info [1]) {
  655. unset ( $staff [$k] );
  656. break;
  657. }
  658. }
  659. }
  660. foreach ( $staff as $k => $v ) {
  661. $info = explode ( ":", $v );
  662. array_push ( $list, $info );
  663. }
  664. $execute->staff = json_encode ( $list );
  665. $execute->update ( array (
  666. 'where' => 'eid = ' . $executeInfo ['eid']
  667. ) );
  668. }
  669. }
  670. return "/adminExecute";
  671. }
  672. function delExecute() {
  673. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  674. $eid = isset ( $this->params ['eid'] ) && is_numeric ( $this->params ['eid'] ) ? $this->params ['eid'] : 0;
  675. if (! empty ( $uid ) && ! empty ( $eid )) {
  676. Doo::loadModel ( "execute" );
  677. $execute = new execute ();
  678. $executeInfo = $execute->getOne ( array (
  679. 'where' => 'eid ="' . $eid . '" ',
  680. 'asArray' => true
  681. ) );
  682. if (empty ( $executeInfo ))
  683. return "/adminExecute";
  684. $ini = array ();
  685. $list = json_decode ( $executeInfo ['staff'], true );
  686. foreach ( $list as $k => $v ) {
  687. if ($v [0] == $uid) {
  688. $ini = $list [$k];
  689. unset ( $list [$k] );
  690. break;
  691. }
  692. }
  693. file_put_contents ( "protected/config/execute/execute.ini", "," . $ini [0], FILE_APPEND );
  694. $execute->staff = json_encode ( $list );
  695. $execute->update ( array (
  696. 'where' => 'eid = ' . $executeInfo ['eid']
  697. ) );
  698. }
  699. return "/adminExecute";
  700. }
  701. function adminInvoice() {
  702. Doo::loadModel ( 'staff' );
  703. $staff = new staff ();
  704. Doo::loadModel ( "invoiceManage" );
  705. $invoiceManage = new invoiceManage ();
  706. $data ['staffList'] = $staff->find ( array (
  707. 'select' => 'username,sid,avatar',
  708. 'asArray' => true
  709. ) );
  710. $list = $invoiceManage->find ( array (
  711. 'asArray' => true
  712. ) );
  713. $execute = array (
  714. '收款管理' => '',
  715. '发票审批' => '',
  716. '发票打印' => '',
  717. '发票邮寄' => '',
  718. '发票退票' => '',
  719. '公司汇总查阅' => ''
  720. );
  721. foreach ( $list as $key => $value ) {
  722. $name = json_decode ( $value ['staff'] );
  723. $staffString = "";
  724. if (! empty ( $name )) {
  725. foreach ( $name as $k => $v ) {
  726. $staffString .= "<span class='tagGroup'> " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delInvoiceManage/' . $v [0] . '/' . $value ['iid'] . '\'" title="删除" class="icon-">k</a></span>';
  727. }
  728. }
  729. foreach ( $execute as $k => $v ) {
  730. if ($k == $value ['mold']) {
  731. $execute [$k] = $name = $staffString;
  732. }
  733. }
  734. }
  735. $data ['invoice'] = $execute;
  736. $data ['memu'] = "invoice";
  737. $data ['staff'] = $this->staff;
  738. $this->render ( "/admin/adminInvoice", $data );
  739. }
  740. function addInvoiceManage() {
  741. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  742. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  743. if (! empty ( $mold ) && ! empty ( $staff )) {
  744. Doo::loadModel ( "invoiceManage" );
  745. $execute = new invoiceManage ();
  746. $executeInfo = $execute->getOne ( array (
  747. 'where' => 'mold ="' . $mold . '" ',
  748. 'asArray' => true
  749. ) );
  750. if (empty ( $executeInfo )) {
  751. $list = array ();
  752. foreach ( $staff as $key => $value ) {
  753. $info = explode ( ":", $value );
  754. array_push ( $list, $info );
  755. }
  756. $execute->mold = $mold;
  757. $execute->staff = json_encode ( $list );
  758. $execute->insert ();
  759. } else {
  760. $list = json_decode ( $executeInfo ['staff'], true );
  761. foreach ( $staff as $k => $v ) {
  762. $info = explode ( ":", $v );
  763. foreach ( $list as $key => $value ) {
  764. if ($value [1] == $info [1]) {
  765. unset ( $staff [$k] );
  766. break;
  767. }
  768. }
  769. }
  770. foreach ( $staff as $k => $v ) {
  771. $info = explode ( ":", $v );
  772. array_push ( $list, $info );
  773. }
  774. $execute->staff = json_encode ( $list );
  775. $execute->update ( array (
  776. 'where' => 'iid = ' . $executeInfo ['iid']
  777. ) );
  778. }
  779. }
  780. return "/adminInvoice";
  781. }
  782. /**
  783. * 发票相关权限配置,把相关组的审批人删除。不会影响已经生成发票数据,修改后只会影响修改后生成的发票数据
  784. * @return string 返回配置页
  785. */
  786. function delInvoiceManage() {
  787. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  788. $iid = isset ( $this->params ['iid'] ) && is_numeric ( $this->params ['iid'] ) ? $this->params ['iid'] : 0;
  789. if (! empty ( $uid ) && ! empty ( $iid )) {
  790. Doo::loadModel ( "invoiceManage" );
  791. $execute = new invoiceManage ();
  792. $executeInfo = $execute->getOne ( array (
  793. 'where' => 'iid ="' . $iid . '" ',
  794. 'asArray' => true
  795. ) );
  796. if (empty ( $executeInfo ))
  797. return "/adminInvoice";
  798. $ini = array ();
  799. $list = json_decode ( $executeInfo ['staff'], true );
  800. foreach ( $list as $k => $v ) {
  801. if ($v [0] == $uid) {
  802. $ini = $list [$k];
  803. unset ( $list [$k] );
  804. break;
  805. }
  806. }
  807. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  808. if (! empty ( $fileInvoice )) {
  809. $fileInvoice = json_decode ( $fileInvoice, true );
  810. if (isset ( $fileInvoice [$executeInfo ['mold']] ))
  811. $fileInvoice [$executeInfo ['mold']] .= "," . $ini [0];
  812. else
  813. $fileInvoice [$executeInfo ['mold']] = '';
  814. $moldArray = explode ( ',', $fileInvoice [$executeInfo ['mold']] );
  815. $moldArray = array_unique ( $moldArray );
  816. $fileInvoice [$executeInfo ['mold']] = implode ( ',', $moldArray );
  817. $fileInvoice = json_encode ( $fileInvoice );
  818. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  819. } else {
  820. $fileInvoice = array (
  821. $executeInfo ['mold'] => $ini [0]
  822. );
  823. $fileInvoice = json_encode ( $fileInvoice );
  824. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  825. }
  826. file_put_contents ( "protected/config/execute/invoice.ini", "," . $ini [0], FILE_APPEND );
  827. $execute->staff = json_encode ( $list );
  828. $execute->update ( array (
  829. 'where' => 'iid = ' . $executeInfo ['iid']
  830. ) );
  831. }
  832. return "/adminInvoice";
  833. }
  834. function ajaxRoleStaff() {
  835. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  836. Doo::loadModel ( 'staff' );
  837. $staff = new staff ();
  838. $staffList = $staff->find ( array (
  839. 'select' => 'username,sid,avatar',
  840. 'where' => 'username != "' . $name . '" and username !="admin"',
  841. 'asArray' => true
  842. ) );
  843. $html = '';
  844. foreach ( $staffList as $key => $value ) {
  845. $html .= '<option value=' . $value ['sid'] . '_' . $value ['username'] . '>' . $value ['username'] . '</option>';
  846. }
  847. echo json_encode ( array (
  848. "success" => true,
  849. 'html' => $html
  850. ) );
  851. die ();
  852. }
  853. function loadCVS() {
  854. Doo::loadModel ( 'longle' );
  855. $longle = new longle ();
  856. $list = $longle->find ( array (
  857. 'select' => 'key_num',
  858. 'asArray' => TRUE
  859. ) );
  860. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  861. while ( $data = fgetcsv ( $file ) ) {
  862. $goods_list [$data [0]] = $data [1];
  863. }
  864. fclose ( $file );
  865. $sqlArray = array ();
  866. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  867. foreach ( $list as $key => $value ) {
  868. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  869. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  870. // $longle->SerialNumber=$goods_list[$value['key_num']];
  871. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  872. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  873. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  874. unset ( $goods_list [$value ['key_num']] );
  875. }
  876. }
  877. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  878. echo $sql . '<br/>--------------------------------<br/>';
  879. foreach ( $goods_list as $key => $value ) {
  880. echo $key . ',' . $value . '<br/>';
  881. }
  882. }
  883. private function getRandChar($length) {
  884. $str = null;
  885. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  886. $max = strlen ( $strPol ) - 1;
  887. for($i = 0; $i < $length; $i ++) {
  888. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  889. }
  890. return $str;
  891. }
  892. private function getReceiptCount() {
  893. $status = 2;
  894. $year = date ( 'Y' );
  895. Doo::loadModel ( 'receipt' );
  896. $receipt = new receipt ();
  897. Doo::loadModel ( 'verify' );
  898. $verify = new verify ();
  899. // user verify ID
  900. $vidList = array ();
  901. $verifyDetail = $verify->find ( array (
  902. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '\"%"',
  903. 'asArray' => true
  904. ) );
  905. foreach ( $verifyDetail as $key => $value ) {
  906. array_push ( $vidList, $value ['vid'] );
  907. }
  908. $vid = implode ( ",", $vidList );
  909. if (empty ( $verifyDetail ))
  910. $vid = 0;
  911. $dateCondition = " and Year(date) =" . $year;
  912. $approvalCondition = ' and verifyStaff not like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  913. $receiptList = $receipt->find ( array (
  914. 'where' => 'verify in(' . $vid . ') and status=' . $status . $dateCondition . $approvalCondition,
  915. 'desc' => 'rid',
  916. 'asArray' => true
  917. ) );
  918. return count ( $receiptList );
  919. }
  920. /**
  921. * 格式化excel文件为数组
  922. * @param unknown_type $file_url
  923. * @param unknown_type $mcid
  924. */
  925. function _format_excel_to_array($file_url = "") {
  926. if (! file_exists ( $file_url ))
  927. return array ();
  928. Doo::loadClass ( 'PHPExcel' );
  929. $PHPExcel = new PHPExcel ();
  930. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  931. if (! $PHPReader->canRead ( $file_url )) {
  932. $PHPReader = new PHPExcel_Reader_Excel5 ();
  933. if (! $PHPReader->canRead ( $file_url )) {
  934. echo 'no Excel';
  935. return;
  936. }
  937. }
  938. $PHPExcel = $PHPReader->load ( $file_url );
  939. /**
  940. * 读取excel文件中的第一个工作表
  941. */
  942. $currentSheet = $PHPExcel->getSheet ( 0 );
  943. /**
  944. * 取得最大的列号
  945. */
  946. $allColumn = $currentSheet->getHighestColumn ();
  947. /**
  948. * 取得一共有多少行
  949. */
  950. $allRow = $currentSheet->getHighestRow ();
  951. $excel_array = array ();
  952. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  953. $excel_column = array ();
  954. // 后期改进
  955. if ($allColumn == 'AM')
  956. $allColumn = 'Z';
  957. /**
  958. * 从第A列开始输出
  959. */
  960. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  961. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  962. /**
  963. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  964. */
  965. $val = "'" . addslashes ( $val ) . "'";
  966. if ($currentColumn == 'A')
  967. $excel_column ['key_num'] = $val;
  968. elseif ($currentColumn == 'C')
  969. $excel_column ['product'] = $val;
  970. elseif ($currentColumn == 'D') {
  971. $val = str_replace ( "'", "", $val );
  972. $excel_column ['make_day'] = $this->excelTime ( $val );
  973. } elseif ($currentColumn == 'E') {
  974. $val = str_replace ( "'", "", $val );
  975. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  976. } elseif ($currentColumn == 'F') {
  977. $val = str_replace ( "'", "", $val );
  978. $excel_column ['version'] = $val;
  979. } elseif ($currentColumn == 'B') {
  980. $val = str_replace ( "'", "", $val );
  981. $excel_column ['SerialNumber'] = $val;
  982. }
  983. }
  984. array_push ( $excel_array, $excel_column );
  985. }
  986. return $excel_array;
  987. }
  988. function excelTime($date, $time = false) {
  989. if (function_exists ( 'GregorianToJD' )) {
  990. if (is_numeric ( $date )) {
  991. $jd = GregorianToJD ( 1, 1, 1970 );
  992. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  993. $date = explode ( '/', $gregorian );
  994. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  995. return $date_str;
  996. }
  997. } else {
  998. $date = $date > 25568 ? $date + 1 : 25569;
  999. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  1000. $ofs = (70 * 365 + 17 + 2) * 86400;
  1001. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  1002. }
  1003. return $date;
  1004. }
  1005. function _GetFileEXT($filename) {
  1006. $pics = explode ( '.', $filename );
  1007. $num = count ( $pics );
  1008. return $pics [$num - 1];
  1009. }
  1010. /**
  1011. * 获取get或者POST值
  1012. * @param string $name 属性名称
  1013. * @return fixed 值
  1014. */
  1015. function get_args($name) {
  1016. if (isset ( $_GET [$name] )) {
  1017. if (is_array ( $_GET [$name] ))
  1018. return $_GET [$name];
  1019. else {
  1020. return addslashes ( $_GET [$name] );
  1021. // return $_GET [$name] ;
  1022. }
  1023. } elseif (isset ( $_POST [$name] )) {
  1024. if (is_array ( $_POST [$name] ))
  1025. return $_POST [$name];
  1026. else {
  1027. return addslashes ( $_POST [$name] );
  1028. // return $_POST [$name];
  1029. }
  1030. } else {
  1031. return false;
  1032. }
  1033. }
  1034. function get_previous($on_page = 1) {
  1035. return $on_page != 0 ? $on_page - 1 : $on_page;
  1036. }
  1037. /**
  1038. * 获得分页数据
  1039. * @param unknown_type $table
  1040. * @param unknown_type $condition
  1041. * @param unknown_type $on_page
  1042. * @param unknown_type $page_size
  1043. */
  1044. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  1045. $page_c = "";
  1046. $page ['previous'] = $this->get_previous ( $on_page );
  1047. $page ['on_page'] = $on_page;
  1048. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  1049. $total = intval ( $total_count / $page_size );
  1050. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1051. $page ['total_data'] = $total_count;
  1052. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1053. $i = 1;
  1054. $page_max = 1;
  1055. if ($on_page > 10) {
  1056. $page_max = intval ( $on_page / 10 ) + 1;
  1057. $i = intval ( $on_page / 10 ) * 10 - 1;
  1058. }
  1059. $page ['page'] = $page_c;
  1060. $page ['lower'] = (-- $on_page) * $page_size;
  1061. return $page;
  1062. }
  1063. /**
  1064. * 获得分页数据
  1065. * @param unknown_type $table
  1066. * @param unknown_type $condition
  1067. * @param unknown_type $on_page
  1068. * @param unknown_type $page_size
  1069. */
  1070. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1071. $page_c = "";
  1072. $page ['previous'] = $this->get_previous ( $on_page );
  1073. $page ['on_page'] = $on_page;
  1074. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  1075. $total = intval ( $total_count / $page_size );
  1076. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1077. $page ['total_data'] = $total_count;
  1078. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1079. $i = 1;
  1080. $page_max = 1;
  1081. if ($on_page > 10) {
  1082. $page_max = intval ( $on_page / 10 ) + 1;
  1083. $i = intval ( $on_page / 10 ) * 10 - 1;
  1084. }
  1085. for(; $i <= $page ['total_page']; $i ++) {
  1086. if ($i == $on_page) {
  1087. if ($other == "page")
  1088. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  1089. else
  1090. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  1091. } else if ($other == "page")
  1092. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  1093. else
  1094. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  1095. if ($i == (10 * $page_max))
  1096. break;
  1097. }
  1098. $page ['page'] = $page_c;
  1099. $page ['lower'] = (-- $on_page) * $page_size;
  1100. return $page;
  1101. }
  1102. /**
  1103. * 获取总页数
  1104. * @param unknown_type $table
  1105. * @param unknown_type $condition
  1106. */
  1107. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  1108. if ($tagSQL)
  1109. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  1110. else
  1111. $sql = "select count(*) as count from CLD_company where " . $condition;
  1112. $query = Doo::db ()->query ( $sql );
  1113. $result = $query->fetch ();
  1114. return $result ['count'];
  1115. }
  1116. /**
  1117. * 获取总页数
  1118. * @param unknown_type $table
  1119. * @param unknown_type $condition
  1120. */
  1121. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1122. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  1123. // echo $staffid;die;
  1124. //
  1125. if (! empty ( $staffid )) {
  1126. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  1127. $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;
  1128. } else {
  1129. if (strlen ( $condition ) == 1 || empty ( $condition ))
  1130. $sql = "select count(*) as count from CLD_client as a " . $condition;
  1131. else
  1132. $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;
  1133. }
  1134. if (! empty ( $search ))
  1135. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  1136. if (! empty ( $tooltip )) {
  1137. $condition = str_replace ( "a.", "c.", $condition );
  1138. if ($tagSQL)
  1139. $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;
  1140. else
  1141. $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;
  1142. }
  1143. // echo $sql;
  1144. $query = Doo::db ()->query ( $sql );
  1145. $result = $query->fetch ();
  1146. return $result ['count'];
  1147. }
  1148. public function holidayGroup(){
  1149. Doo::loadModel('staff');
  1150. Doo::loadModel("holidayacman");
  1151. Doo::loadModel('L_category');
  1152. $L_category = new L_category();
  1153. $acman=new HACMan();
  1154. $staff=new staff();
  1155. $data['staffList']=$staff->find(array('select'=>'username,sid,wxid', 'where' => 'cid!=1','asArray'=>true));
  1156. $acmanlist=$acman->find(array('where' => 'type=0', 'desc' => 'id','asArray'=>true));
  1157. if(!empty($acmanlist)){
  1158. foreach($acmanlist as $k => $v){
  1159. $acmanlist[$k]['name'] = implode('->', explode(' ', $v['name']));
  1160. $category = explode(',',$v['category']);
  1161. $categoryname = array();
  1162. if(!empty($category)){
  1163. foreach($category as $key => $value){
  1164. $name = $L_category->getOne(array('where' => 'cid="'.$value.'"', 'asArray' => TRUE));
  1165. array_push($categoryname,$name['title']);
  1166. }
  1167. }
  1168. $acmanlist[$k]['categoryname'] = implode(',',$categoryname);
  1169. }
  1170. }
  1171. //获取办事处列表
  1172. $data['category']=$L_category->getCategory();
  1173. $data['acmanlist'] = $acmanlist;
  1174. $data['staff']=$this->staff;
  1175. $data['memu'] = 'holiday';
  1176. $data['noindexjs'] = 'noindexjs';
  1177. $this->render( "/admin/admin_holidayGroup", $data );
  1178. }
  1179. public function addHolidayApprover() {
  1180. if (! isset ( $_POST ['title'] ) || empty ( $_POST ['title'] )) {
  1181. exit ( '请输入组名' );
  1182. }
  1183. if (! isset ( $_POST ['staff'] ) || empty ( $_POST ['staff'] )) {
  1184. exit ( '请选择成员' );
  1185. }
  1186. $idname = $name = $pinyinname = array ();
  1187. $stafflist = explode(',',$_POST['staff']);
  1188. foreach ( $stafflist as $k => $v ) {
  1189. $msg = explode ( ':', $v );
  1190. array_push ( $idname, $msg [0] );
  1191. array_push ( $name, $msg [1] );
  1192. array_push ( $pinyinname, $msg [2] );
  1193. }
  1194. Doo::loadModel("holidayacman");
  1195. $acman=new HACMan();
  1196. $acman->typename = $_POST['title'];
  1197. $acman->idname = implode(',', $idname);
  1198. $acman->name = implode(' ', $name);
  1199. $acman->pinyinname = implode('|', $pinyinname);
  1200. $acman->type = 0;
  1201. $result = $acman->insert();
  1202. if($result){
  1203. $acman2=new HACMan();
  1204. $acman2->type = $result;
  1205. $acman2->insert();
  1206. Doo::loadModel('holidaystaff');
  1207. foreach($idname as $ik => $iv){
  1208. $hstaff = new HStaff();
  1209. $hstaff->uid = $iv;
  1210. $hstaff->isadmin = 1;
  1211. $hstaff->update();
  1212. }
  1213. }
  1214. return '/holidaygroup';
  1215. }
  1216. public function setHolidaySee(){
  1217. if(!isset($_POST['groupid']) || empty($_POST['groupid']) || !is_numeric($_POST['groupid'])){
  1218. exit('审批组id出错');
  1219. }
  1220. $category = !empty($_POST['category']) ? implode(',', $_POST['category']) : '';
  1221. Doo::loadModel('holidayacman');
  1222. $acman = new HACMan();
  1223. $acman->id = $_POST['groupid'];
  1224. $acman->category = $category;
  1225. $acman->update();
  1226. return '/holidaygroup';
  1227. }
  1228. public function delHolidayGroup(){
  1229. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1230. exit('审批组id出错');
  1231. }
  1232. Doo::loadModel('holidayacman');
  1233. $acman = new HACMan();
  1234. $idname = $acman->getOne(array('where' => 'id='.$_POST['approvalid'], 'asArray' => TRUE));
  1235. $idname = explode(',', $idname['idname']);
  1236. $acman->id = $_POST['approvalid'];
  1237. $acman->delete();
  1238. // $acman2 = new HACMan();
  1239. // $acman2->type = $_POST['approvalid'];
  1240. // $acman2->delete();
  1241. //删除管理员资格
  1242. $acman3 = new HACMan();
  1243. foreach($idname as $k => $v){
  1244. $same = 0;
  1245. $approverlist = $acman3->find(array('where' => 'idname like "%'.$v.'%" and type=0', 'asArray' => TRUE));
  1246. if(!empty($approverlist)){
  1247. foreach($approverlist as $ak => $av){
  1248. $aidname = explode(',', $av['idname']);
  1249. foreach($aidname as $ik => $iv){
  1250. if($iv == $v){
  1251. $same = 1;
  1252. break;
  1253. }
  1254. }
  1255. }
  1256. }
  1257. if($same == 0){
  1258. Doo::loadModel('holidaystaff');
  1259. $hstaff = new HStaff();
  1260. $hstaff->uid = $v;
  1261. $hstaff->isadmin = 0;
  1262. $hstaff->update();
  1263. }
  1264. }
  1265. return '/holidaygroup';
  1266. }
  1267. public function holidayCSGroup(){
  1268. Doo::loadModel('staff');
  1269. Doo::loadModel('holidayacman');
  1270. $acman = new HACMan();
  1271. $staff = new staff();
  1272. $approverlist = $acman->find(array('where' => 'type=0', 'desc' => 'id', 'asArray' => TRUE));
  1273. if(!empty($approverlist)){
  1274. foreach($approverlist as $k => $v){
  1275. $csman = $acman->getOne(array('where' => 'type='.$v['id'], 'asArray' => TRUE));
  1276. if(!empty($csman['name'])){
  1277. $idname = explode(',',$csman['idname']);
  1278. $name = explode(' ',$csman['name']);
  1279. $pinyinname = explode('|',$csman['pinyinname']);
  1280. $csmsg = array();
  1281. foreach($idname as $ik => $iv){
  1282. $csmsg[$ik]['csidname'] = $iv;
  1283. $csmsg[$ik]['csname'] = $name[$ik];
  1284. $csmsg[$ik]['cspinyinname'] = $pinyinname[$ik];
  1285. }
  1286. $approverlist[$k]['csmsg'] = $csmsg;
  1287. }
  1288. }
  1289. $data['approverlist'] = $approverlist;
  1290. }
  1291. //获取总部人员列表
  1292. $zongbu = $staff->getStaffByCid(12);
  1293. $data['zongbu'] = $zongbu;
  1294. //获取办事处列表
  1295. Doo::loadModel('L_category');
  1296. $L_category = new L_category();
  1297. $data['category']=$L_category->getCategory();
  1298. $data['memu'] = 'holiday';
  1299. $data['noindexjs'] = 'noindexjs';
  1300. $this->render( "/admin/admin_holidayGroup_cc", $data );
  1301. }
  1302. public function getStaffCategory(){
  1303. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  1304. Doo::loadModel('staff');
  1305. $staff = new staff();
  1306. $stafflist = $staff->getStaffByCid($_POST['cid']);
  1307. exit(json_encode(array('code' => 200, 'stafflist' => $stafflist)));
  1308. }
  1309. exit(json_encode(array('code' => 400)));
  1310. }
  1311. public function addHolidayCS(){
  1312. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1313. exit('审批组出错');
  1314. }
  1315. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1316. exit('抄送人出错');
  1317. }
  1318. $cidstaff = explode(':',$_POST['cidstaff']);
  1319. Doo::loadModel('holidayacman');
  1320. $acman = new HACMan();
  1321. $csmsg = $acman->getOne(array('where' => 'type='.$_POST['approvalid'], 'asArray' => TRUE));
  1322. $csidmsg = !empty($csmsg['idname']) ? $csmsg['idname'].','.$cidstaff[0] : $cidstaff[0];
  1323. $csnamemsg = !empty($csmsg['name']) ? $csmsg['name'].' '.$cidstaff[1] : $cidstaff[1];
  1324. $cspinyinnamemsg = !empty($csmsg['pinyinname']) ? $csmsg['pinyinname'].'|'.$cidstaff[2] : $cidstaff[2];
  1325. $acman->id = $csmsg['id'];
  1326. $acman->idname = $csidmsg;
  1327. $acman->name = $csnamemsg;
  1328. $acman->pinyinname = $cspinyinnamemsg;
  1329. $acman->update();
  1330. return '/hcsgroup';
  1331. }
  1332. public function delHolidayCS(){
  1333. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1334. exit('审批id出错');
  1335. }
  1336. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1337. exit('抄送信息出错');
  1338. }
  1339. $cidstaff = explode(':',$_POST['cidstaff']);
  1340. Doo::loadModel('holidayacman');
  1341. $acman = new HACMan();
  1342. $csmsg = $acman->getOne(array('where' => 'type='.$_POST['approvalid'], 'asArray' => TRUE));
  1343. if(!empty($csmsg['idname'])){
  1344. $idnamearr = explode(',', $csmsg['idname']);
  1345. foreach($idnamearr as $ik => $iv){
  1346. if($iv == $cidstaff[0]){
  1347. unset($idnamearr[$ik]);
  1348. break;
  1349. }
  1350. }
  1351. $csidmsg = implode(',',$idnamearr);
  1352. }
  1353. if(!empty($csmsg['name'])){
  1354. $namearr = explode(' ', $csmsg['name']);
  1355. foreach($namearr as $nk => $nv){
  1356. if($nv == $cidstaff[1]){
  1357. unset($namearr[$nk]);
  1358. break;
  1359. }
  1360. }
  1361. $csnamemsg = implode(' ',$namearr);
  1362. }
  1363. if(!empty($csmsg['pinyinname'])){
  1364. $pinyinnamearr = explode('|', $csmsg['pinyinname']);
  1365. foreach($pinyinnamearr as $pk => $pv){
  1366. if($pv == $cidstaff[2]){
  1367. unset($pinyinnamearr[$pk]);
  1368. break;
  1369. }
  1370. }
  1371. $cspinyinnamemsg = implode('|',$pinyinnamearr);
  1372. }
  1373. $acman->id = $csmsg['id'];
  1374. if(isset($csidmsg)){
  1375. $acman->idname = $csidmsg;
  1376. }
  1377. if(isset($csnamemsg)){
  1378. $acman->name = $csnamemsg;
  1379. }
  1380. if(isset($cspinyinnamemsg)){
  1381. $acman->pinyinname = $cspinyinnamemsg;
  1382. }
  1383. $acman->update();
  1384. return '/hcsgroup';
  1385. }
  1386. public function HolidayAdmin(){
  1387. Doo::loadModel('staff');
  1388. $staff=new staff();
  1389. $staffList=$staff->find(array('select'=>'username,sid', 'where' => 'cid!=1','asArray'=>true));
  1390. Doo::loadModel('holidayadmin');
  1391. $admin = new HAdmin();
  1392. $adminList = $admin->find(array('asArray' => TRUE));
  1393. if(!empty($adminList)){
  1394. foreach($adminList as $k => $v){
  1395. foreach($staffList as $sk => $sv){
  1396. if($sv['sid'] == $v['uid']){
  1397. array_splice($staffList, $sk,1);
  1398. break;
  1399. }
  1400. }
  1401. }
  1402. }
  1403. $data['staffList'] = $staffList;
  1404. $data['adminList'] = $adminList;
  1405. $data['memu'] = 'holiday';
  1406. $data['noindexjs'] = 'noindexjs';
  1407. $this->render( "/admin/admin_holidayuser", $data );
  1408. }
  1409. public function addHolidayAdmin(){
  1410. if(!isset($_POST['staff']) || empty($_POST['staff'])){
  1411. exit('请选择管理人');
  1412. }
  1413. Doo::loadModel('holidayadmin');
  1414. foreach($_POST['staff'] as $k => $v){
  1415. $staffmsg = explode(':',$v);
  1416. $admin = new HAdmin();
  1417. $admin->uid = $staffmsg[0];
  1418. $admin->username = $staffmsg[1];
  1419. $admin->insert();
  1420. }
  1421. return '/holidayadmin';
  1422. }
  1423. public function delHolidayAdmin(){
  1424. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1425. exit('请选择管理人删除');
  1426. }
  1427. Doo::loadModel('holidayadmin');
  1428. $admin = new HAdmin();
  1429. $admin->id = $_POST['cidstaff'];
  1430. $admin->delete();
  1431. return '/holidayadmin';
  1432. }
  1433. //检查年假是否过期并更新年假
  1434. private function updateAnnualLeave($staff){
  1435. Doo::loadModel('holidaystaff');
  1436. $hstaff = new HStaff();
  1437. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1438. $hiredate = $staff['hiredate'];
  1439. $hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  1440. if($hadyear != $hstaffmsg['hadyear']){
  1441. $hstaff->uid = $staff['sid'];
  1442. $hstaff->hadyear = $hadyear;
  1443. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1444. $hstaff->update();
  1445. }
  1446. }
  1447. }
  1448. ?>