AdminController.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  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 = $this->get_args('passwork') ? $this->get_args('passwork') : "";
  76. $uid = $this->get_args('user') ? $this->get_args('user') : "";
  77. Doo::loadModel ( 'staff' );
  78. $staff = new staff ();
  79. Doo::loadClass ( 'XDeode' );
  80. $XDeode = new XDeode ( 5 );
  81. if (! empty ( $passwork )) {
  82. $userinfo = $staff->getOne ( array (
  83. 'where' => "username='admin'",
  84. 'asArray' => true
  85. ) );
  86. if (! empty ( $userinfo )) {
  87. if ($userinfo ['username'] == $uid && $userinfo ['passwork'] == md5 ( $passwork )) {
  88. setcookie ( "adStaff", $XDeode->encode ($userinfo ['sid']), time () + 36000, "/" );
  89. return "/adminoffice";
  90. }
  91. }
  92. }
  93. $data ['staff'] = "";
  94. $data ['login'] = "";
  95. if (! empty ( $passwork ))
  96. $data ['login'] = "inputErrow";
  97. $this->render ( "/admin/adminLogin", $data );
  98. }
  99. function adout() {
  100. setcookie ( "adStaff", "", time () - 3600, "/" );
  101. return "/adlogin";
  102. }
  103. function adminPW() {
  104. $msg = $this->params ['msg'] ? $this->params ['msg'] : "";
  105. $data ['msg'] = "msg";
  106. $data ['memu'] = "adminpw";
  107. $data ['staff'] = $this->staff;
  108. $data ['msg'] = urldecode ( $this->params ['msg'] );
  109. $this->render ( "/admin/admin-admininfo", $data );
  110. }
  111. function upAdP() {
  112. $opw = $this->get_args ( 'opw' ) ? $this->get_args ( 'opw' ) : "";
  113. $npw1 = $this->get_args ( 'npw1' ) ? $this->get_args ( 'npw1' ) : "";
  114. $npw2 = $this->get_args ( 'npw2' ) ? $this->get_args ( 'npw2' ) : "";
  115. if (! empty ( $opw )) {
  116. Doo::loadModel ( 'staff' );
  117. $staff = new staff ();
  118. $userinfo = $staff->getOne ( array (
  119. 'where' => "username='admin'",
  120. 'asArray' => true
  121. ) );
  122. if (! empty ( $userinfo )) {
  123. if ($userinfo ['sid'] == $_COOKIE ["adStaff"] && $userinfo ['passwork'] == md5 ( $opw )) {
  124. if (($npw1 == $npw2) && ($npw1 != "")) {
  125. $staff->passwork = md5 ( $npw1 );
  126. $staff->update ( array (
  127. 'where' => "sid='" . $_COOKIE ["adStaff"] . "'"
  128. ) );
  129. return "/adminpw/" . urlencode ( '密码修改成功' );
  130. } else
  131. return "/adminpw/" . urlencode ( '新密码不一致' );
  132. } else
  133. return "/adminpw/" . urlencode ( '旧密码不正确' );
  134. } else
  135. return "/adminpw/" . urlencode ( '未找到用户' );
  136. } else
  137. return "/adminpw/" . urlencode ( '请输入旧密码' );
  138. }
  139. function adminoffice() {
  140. $data ['memu'] = "adminoffice";
  141. $data ['staff'] = $this->staff;
  142. Doo::loadModel ( 'L_category' );
  143. Doo::loadModel ( 'staff' );
  144. Doo::loadModel ( 'district' );
  145. $district = new district ();
  146. $staff = new staff ();
  147. $L_category = new L_category ();
  148. $data ['category'] = $L_category->getCategory ();
  149. $data ['district'] = $district->get_lv ( 1 );
  150. foreach ( $data ['category'] as $key => $value ) {
  151. $data ['category'] [$key] ['count'] = $staff->count ( array (
  152. 'where' => 'cid=' . $value ['cid']
  153. ) );
  154. }
  155. $data ['msg'] = urldecode ( $this->params ['msg'] );
  156. $this->render ( "/admin/admin_group", $data );
  157. }
  158. function addCategory() {
  159. $msg = "添加成功";
  160. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  161. $district = $this->get_args ( 'district' ) ? $this->get_args ( 'district' ) : "";
  162. if (! empty ( $title ) && ! empty ( $district )) {
  163. Doo::loadModel ( 'L_category' );
  164. $L_category = new L_category ();
  165. $L_category->title = $title;
  166. $L_category->districtid = $district;
  167. $L_category->insert ();
  168. } else {
  169. $msg = "请输入正确的信息";
  170. }
  171. return "/adminoffice/" . $msg;
  172. }
  173. function adminuser() {
  174. $data ['memu'] = "adminuser";
  175. $data ['staff'] = $this->staff;
  176. Doo::loadModel ( 'L_category' );
  177. Doo::loadModel ( 'staff' );
  178. $staff = new staff ();
  179. $L_category = new L_category ();
  180. $data ['category'] = $L_category->getCategory ();
  181. $data ['stafflist'] = $staff->getStaff ();
  182. $data ['staff'] = $this->staff;
  183. $this->render ( "/admin/admin_user", $data );
  184. }
  185. function adduser() {
  186. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  187. $password = $this->get_args ( 'password' ) ? $this->get_args ( 'password' ) : "";
  188. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  189. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  190. $nature = is_numeric ( $this->get_args ( 'nature' ) ) ? $this->get_args ( 'nature' ) : 1;
  191. if (! empty ( $username ) && ! empty ( $password ) && ! empty ( $cid ) && ! empty ( $hiredate ) && ! empty ( $nature )) {
  192. Doo::loadModel ( 'L_category' );
  193. Doo::loadModel ( 'staff' );
  194. Doo::loadModel ( 'tag' );
  195. Doo::loadModel ( 'holidaystaff' );
  196. $staff = new staff ();
  197. $L_category = new L_category ();
  198. // 加入默认总部分类
  199. $cagegory = $L_category->getCategoryById ( $cid );
  200. // 根据这个分类加入管理权限
  201. if ($cagegory [0] ['defult'] == 1) {
  202. $staff->isadmin = 1;
  203. }
  204. $staff->username = $username;
  205. $staff->passwork = md5 ( $password );
  206. $staff->cid = $cagegory [0] ['cid'];
  207. $staff->category = $cagegory [0] ['title'];
  208. $staff->hiredate = $hiredate;
  209. $staff->nature = $nature;
  210. $id = $staff->insert ();
  211. $holidaystaff = new HStaff ();
  212. $holidaystaff->uid = $id;
  213. $holidaystaff->insert();
  214. $staffmsg = $staff->getUserById($id);
  215. $this->updateAnnualLeave($staffmsg[0]);
  216. for ($i=1;$i<=7;$i++){
  217. $tag = new tag ();
  218. $tag->name = "个人标签";
  219. $tag->sid = $id;
  220. $tag->colorid = $i;
  221. $tag->insert ();
  222. }
  223. }
  224. return "/adminuser";
  225. }
  226. function adminEdiUser() {
  227. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  228. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  229. if (! empty ( $sid )) {
  230. $data ['msg'] = urldecode ( $msg );
  231. Doo::loadModel ( 'L_category' );
  232. Doo::loadModel ( 'staff' );
  233. $staff = new staff ();
  234. $L_category = new L_category ();
  235. $data ['newPw'] = '';
  236. $data ['staffInfo'] = $staff->getUserById ( $sid );
  237. $data ['category'] = $L_category->getCategory ();
  238. $data ['staff'] = $this->staff;
  239. $data ['memu'] = "adminuser";
  240. $this->render ( "/admin/admin_EdiUser", $data );
  241. } else
  242. return "/adminuser";
  243. }
  244. function adminResetUserPw() {
  245. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  246. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  247. if (! empty ( $sid )) {
  248. $data ['msg'] = urldecode ( $msg );
  249. Doo::loadModel ( 'L_category' );
  250. Doo::loadModel ( 'staff' );
  251. $staff = new staff ();
  252. $L_category = new L_category ();
  253. $newPw = $this->getRandChar ( 6 );
  254. $staff->sid = $sid;
  255. $staff->passwork = md5 ( $newPw );
  256. $staff->update ();
  257. $data ['newPw'] = $newPw;
  258. $data ['staffInfo'] = $staff->getUserById ( $sid );
  259. $data ['category'] = $L_category->getCategory ();
  260. $data ['staff'] = $this->staff;
  261. $data ['memu'] = "adminuser";
  262. $this->render ( "/admin/admin_EdiUser", $data );
  263. } else
  264. return "/adminuser";
  265. }
  266. function adminDoEdiUser() {
  267. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  268. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  269. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  270. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $this->get_args ( 'qq' ) : 0;
  271. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  272. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  273. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  274. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  275. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  276. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  277. if (! empty ( $sid )) {
  278. $msg = "";
  279. Doo::loadModel ( 'L_category' );
  280. Doo::loadModel ( 'staff' );
  281. $staff = new staff ();
  282. $L_category = new L_category ();
  283. $categoryInfo = $L_category->getCategoryById ( $cid );
  284. $staff->sid = $sid;
  285. if ($cid != 0) {
  286. $staff->cid = $categoryInfo [0] ['cid'];
  287. $staff->category = $categoryInfo [0] ['title'];
  288. }
  289. if ($categoryInfo [0] ['defult'] == 1) {
  290. $staff->isadmin = 1;
  291. } else {
  292. $staff->isadmin = 0;
  293. }
  294. if (! empty ( $username ))
  295. $staff->username = $username;
  296. if (! empty ( $gender ))
  297. $staff->gender = $gender;
  298. if (! empty ( $qq ) && is_numeric ( $qq ))
  299. $staff->qq = $qq;
  300. if (! empty ( $phone ))
  301. $staff->phone = $phone;
  302. if (! empty ( $telephone ))
  303. $staff->telephone = $telephone;
  304. if (! empty ( $email ) && filter_var ( $email, FILTER_VALIDATE_EMAIL ))
  305. $staff->email = $email;
  306. else
  307. $msg = "邮箱不正确";
  308. if (! empty ( $hiredate ))
  309. $staff->hiredate = $hiredate;
  310. $staff->nature = $nature;
  311. $staff->update ();
  312. $staffmsg = $staff->getUserById ( $sid );
  313. $this->updateAnnualLeave ( $staffmsg [0] );
  314. return "/edi/user/" . $sid . "/" . $msg;
  315. } else {
  316. return "/adminuser";
  317. }
  318. }
  319. function adminDoAddCategory() {
  320. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  321. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  322. if (! empty ( $sid )) {
  323. Doo::loadModel ( 'L_category' );
  324. Doo::loadModel ( 'staff' );
  325. $staff = new staff ();
  326. $L_category = new L_category ();
  327. $stfInfo = $staff->getOne ( array (
  328. 'where' => 'sid =' . $sid,
  329. 'asArray' => true
  330. ) );
  331. if ($stfInfo ['cid'] == $cid)
  332. return "/adminuser";
  333. $othcid = explode ( ',', $stfInfo ['othercid'] );
  334. if (in_array ( $cid, $othcid ))
  335. return "/adminuser";
  336. array_push ( $othcid, $cid );
  337. $strCid = implode ( ',', array_filter ( $othcid ) );
  338. $catename = $L_category->getCategoryById ( $cid );
  339. $othcategory = explode ( ',', $stfInfo ['othercategory'] );
  340. array_push ( $othcategory, $catename [0] ['title'] );
  341. $strcategory = implode ( ',', array_filter ( $othcategory ) );
  342. $staff->sid = $sid;
  343. $staff->othercid = $strCid;
  344. $staff->othercategory = $strcategory;
  345. $staff->update ();
  346. }
  347. return "/adminuser";
  348. }
  349. function adminDeleteUser() {
  350. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  351. if (! empty ( $sid )) {
  352. Doo::loadModel ( 'staff' );
  353. $staff = new staff ();
  354. $staff->sid = $sid;
  355. $staff->delete ();
  356. Doo::loadModel ('holidaystaff');
  357. $hstaff = new HStaff();
  358. $hstaff->uid = $sid;
  359. $hstaff->delete();
  360. }
  361. return "/adminuser";
  362. }
  363. function adminproduct() {
  364. $data ['memu'] = "adminproduct";
  365. $data ['staff'] = $this->staff;
  366. Doo::loadModel ( 'product' );
  367. Doo::loadModel ( 'longle' );
  368. $product = new product ();
  369. $longle = new longle ();
  370. $data ['product'] = $product->getProudct ();
  371. foreach ( $data ['product'] as $key => $value ) {
  372. $data ['product'] [$key] ['count'] = $longle->count ( array (
  373. 'where' => 'product="' . $value ['title'] . '"'
  374. ) );
  375. }
  376. $this->render ( "/admin/admin_product", $data );
  377. }
  378. function addproduct() {
  379. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  380. if (! empty ( $title )) {
  381. Doo::loadModel ( 'product' );
  382. $product = new product ();
  383. $product->title = $title;
  384. $product->insert ();
  385. }
  386. return "/adminproduct";
  387. }
  388. function adminDeleteProduct() {
  389. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  390. if (! empty ( $pid )) {
  391. Doo::loadModel ( 'product' );
  392. $product = new product ();
  393. $product->pid = $pid;
  394. $product->delete ();
  395. }
  396. return "/adminproduct";
  397. }
  398. function adminEdiProduct() {
  399. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  400. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  401. if (! empty ( $pid )) {
  402. $data ['msg'] = urldecode ( $msg );
  403. Doo::loadModel ( 'product' );
  404. $product = new product ();
  405. $data ['productInfo'] = $product->getProductById ( $pid );
  406. $data ['memu'] = "adminproduct";
  407. $data ['staff'] = $this->staff;
  408. $this->render ( "/admin/admin_EdiProduct", $data );
  409. } else
  410. return "/adminproduct";
  411. }
  412. function adminDoEdiProduct() {
  413. $pid = is_numeric ( $this->get_args ( 'pid' ) ) ? $this->get_args ( 'pid' ) : "";
  414. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  415. $typeid = $this->get_args ( 'typeid' ) ? $this->get_args ( 'typeid' ) : "";
  416. if (! empty ( $pid ) && ! empty ( $title ) && ! empty ( $typeid )) {
  417. $msg = "";
  418. Doo::loadModel ( 'product' );
  419. $product = new product ();
  420. $product->pid = $pid;
  421. $product->title = $title;
  422. $product->typeid = $typeid;
  423. $product->update ();
  424. return "/adminproduct";
  425. } else {
  426. return "/adminproduct";
  427. }
  428. }
  429. function adminverify() {
  430. Doo::loadModel ( 'staff' );
  431. Doo::loadModel ( "verify" );
  432. $verify = new verify ();
  433. $staff = new staff ();
  434. Doo::loadModel ( "role" );
  435. $role = new role ();
  436. $data ['staffList'] = $staff->find ( array (
  437. 'select' => 'username,sid,avatar',
  438. 'asArray' => true
  439. ) );
  440. $list = $verify->find ( array (
  441. 'asArray' => true
  442. ) );
  443. $roleList = $role->find ( array (
  444. 'asArray' => true
  445. ) );
  446. foreach ( $roleList as $key => $value ) {
  447. $staffList = json_decode ( $value ['staff'] );
  448. foreach ( $staffList as $k => $v ) {
  449. $staffList [$k] = substr ( strstr ( $v, '_' ), 1 );
  450. }
  451. $roleList [$key] ['staff'] = implode ( ',', $staffList );
  452. }
  453. foreach ( $list as $key => $value ) {
  454. $name = json_decode ( $value ['staff'] );
  455. $list [$key] ['staff'] = "";
  456. foreach ( $name as $k => $v ) {
  457. if ($v [1] == 'ROLE') {
  458. $roleInfo = $role->getOne ( array (
  459. 'where' => 'rid = "' . $v [0] . '"',
  460. 'asArray' => true
  461. ) );
  462. $v [1] = $roleInfo ['name'];
  463. }
  464. $list [$key] ['staff'] .= " " . $v [1];
  465. }
  466. }
  467. $data ['roleList'] = $roleList;
  468. $data ['verify'] = $list;
  469. $data ['memu'] = "verify";
  470. $data ['staff'] = $this->staff;
  471. $this->render ( "/admin/admin_reportGroup", $data );
  472. }
  473. function addVerify() {
  474. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  475. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  476. $uidlist = $this->get_args ( 'uidlist' ) ? $this->get_args ( 'uidlist' ) : "";
  477. $uidlist = explode ( ",", $uidlist );
  478. Doo::loadModel ( "role" );
  479. $role = new role ();
  480. $list = array ();
  481. foreach ( $uidlist as $key => $value ) {
  482. $info = explode ( ":", $value );
  483. if ($info [1] == 'ROLE') {
  484. $roleInfo = $role->getOne ( array (
  485. 'where' => 'rid = "' . $info [0] . '"',
  486. 'asArray' => true
  487. ) );
  488. array_push ( $info, $roleInfo ['staff'] );
  489. }
  490. array_push ( $list, $info );
  491. }
  492. if (! empty ( $description ) && ! empty ( $list )) {
  493. Doo::loadModel ( "verify" );
  494. $verify = new verify ();
  495. $verify->description = $description;
  496. $verify->staff = json_encode ( $list );
  497. $verify->insert ();
  498. }
  499. return "/adminverify";
  500. }
  501. function adminRole() {
  502. Doo::loadModel ( 'staff' );
  503. $staff = new staff ();
  504. Doo::loadModel ( "verify" );
  505. $verify = new verify ();
  506. Doo::loadModel ( "role" );
  507. $role = new role ();
  508. $data ['staffList'] = $staff->find ( array (
  509. 'select' => 'username,sid,avatar',
  510. 'asArray' => true
  511. ) );
  512. $list = $verify->find ( array (
  513. 'asArray' => true
  514. ) );
  515. $roleList = $role->find ( array (
  516. 'asArray' => true
  517. ) );
  518. foreach ( $list as $key => $value ) {
  519. $name = json_decode ( $value ['staff'] );
  520. $list [$key] ['staff'] = "";
  521. foreach ( $name as $k => $v ) {
  522. $list [$key] ['staff'] .= " " . $v [1];
  523. }
  524. }
  525. foreach ( $roleList as $key => $value ) {
  526. $staff = json_decode ( $value ['staff'] );
  527. foreach ( $staff as $k => $v ) {
  528. // print_r($info);
  529. // $staff[$k]=substr(strstr($v, '_'), 1);
  530. $info = explode ( '_', $v );
  531. $staff [$k] = $info;
  532. }
  533. $roleList [$key] ['list'] = $staff;
  534. }
  535. $data ['roleList'] = $roleList;
  536. $data ['verify'] = $list;
  537. $data ['memu'] = "verify";
  538. $data ['staff'] = $this->staff;
  539. $this->render ( "/admin/adminReportGroupRole", $data );
  540. }
  541. function addRole() {
  542. $name = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  543. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  544. $list = array ();
  545. foreach ( $staff as $key => $value ) {
  546. $na = explode ( ":", $value );
  547. array_push ( $list, $na [0] . '_' . $na [1] );
  548. }
  549. if (! empty ( $name ) && ! empty ( $list )) {
  550. Doo::loadModel ( "role" );
  551. $role = new role ();
  552. $role->name = $name;
  553. $role->staff = json_encode ( $list );
  554. $role->insert ();
  555. }
  556. return "/adminRole";
  557. }
  558. function delRole() {
  559. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  560. if (! empty ( $rid )) {
  561. Doo::loadModel ( "role" );
  562. $role = new role ();
  563. $role->delete ( array (
  564. 'where' => 'rid="' . $rid . '"'
  565. ) );
  566. }
  567. return "/adminRole";
  568. }
  569. function updateRole() {
  570. $oldStaff = $this->get_args ( 'oldStaff' ) ? $this->get_args ( 'oldStaff' ) : "";
  571. $newStaff = $this->get_args ( 'newStaff' ) ? $this->get_args ( 'newStaff' ) : "";
  572. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  573. if (! empty ( $oldStaff ) && ! empty ( $newStaff ) && ! empty ( $rid )) {
  574. Doo::loadModel ( "role" );
  575. $role = new role ();
  576. $roleInfo = $role->getOne ( array (
  577. 'where' => 'rid = "' . $rid . '"',
  578. 'asArray' => true
  579. ) );
  580. $staffList = json_decode ( $roleInfo ['staff'], true );
  581. foreach ( $staffList as $key => $value ) {
  582. if ($value == $oldStaff) {
  583. $staffList [$key] = $newStaff;
  584. break;
  585. }
  586. }
  587. $role->staff = json_encode ( $staffList );
  588. $role->update ( array (
  589. 'where' => 'rid = "' . $rid . '"'
  590. ) );
  591. }
  592. return "/adminRole";
  593. }
  594. function adminExecute() {
  595. Doo::loadModel ( 'staff' );
  596. $staff = new staff ();
  597. Doo::loadModel ( "execute" );
  598. $execute = new execute ();
  599. $data ['staffList'] = $staff->find ( array (
  600. 'select' => 'username,sid,avatar',
  601. 'asArray' => true
  602. ) );
  603. $list = $execute->find ( array (
  604. 'asArray' => true
  605. ) );
  606. $execute = array (
  607. '借款执行人' => '',
  608. '借款费用执行人' => '',
  609. '报销单执行人' => '',
  610. '对公汇款执行人' => ''
  611. );
  612. foreach ( $list as $key => $value ) {
  613. $name = json_decode ( $value ['staff'] );
  614. $staffString = "";
  615. if (! empty ( $name )) {
  616. foreach ( $name as $k => $v ) {
  617. $staffString .= " " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/' . $v [0] . '/' . $value ['eid'] . '\'" title="删除" class="icon-">k</a>';
  618. }
  619. }
  620. foreach ( $execute as $k => $v ) {
  621. if ($k == $value ['mold']) {
  622. $execute [$k] = $name = $staffString;
  623. }
  624. }
  625. }
  626. // print_r($execute);die;
  627. $data ['execute'] = $execute;
  628. $data ['memu'] = "verify";
  629. $data ['staff'] = $this->staff;
  630. $this->render ( "/admin/adminCarriedout", $data );
  631. }
  632. function addExecute() {
  633. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  634. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  635. if (! empty ( $mold ) && ! empty ( $staff )) {
  636. Doo::loadModel ( "execute" );
  637. $execute = new execute ();
  638. $executeInfo = $execute->getOne ( array (
  639. 'where' => 'mold ="' . $mold . '" ',
  640. 'asArray' => true
  641. ) );
  642. if (empty ( $executeInfo )) {
  643. $list = array ();
  644. foreach ( $staff as $key => $value ) {
  645. $info = explode ( ":", $value );
  646. array_push ( $list, $info );
  647. }
  648. $execute->mold = $mold;
  649. $execute->staff = json_encode ( $list );
  650. $execute->insert ();
  651. } else {
  652. $list = json_decode ( $executeInfo ['staff'], true );
  653. foreach ( $staff as $k => $v ) {
  654. $info = explode ( ":", $v );
  655. foreach ( $list as $key => $value ) {
  656. if ($value [1] == $info [1]) {
  657. unset ( $staff [$k] );
  658. break;
  659. }
  660. }
  661. }
  662. foreach ( $staff as $k => $v ) {
  663. $info = explode ( ":", $v );
  664. array_push ( $list, $info );
  665. }
  666. $execute->staff = json_encode ( $list );
  667. $execute->update ( array (
  668. 'where' => 'eid = ' . $executeInfo ['eid']
  669. ) );
  670. }
  671. }
  672. return "/adminExecute";
  673. }
  674. function delExecute() {
  675. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  676. $eid = isset ( $this->params ['eid'] ) && is_numeric ( $this->params ['eid'] ) ? $this->params ['eid'] : 0;
  677. if (! empty ( $uid ) && ! empty ( $eid )) {
  678. Doo::loadModel ( "execute" );
  679. $execute = new execute ();
  680. $executeInfo = $execute->getOne ( array (
  681. 'where' => 'eid ="' . $eid . '" ',
  682. 'asArray' => true
  683. ) );
  684. if (empty ( $executeInfo ))
  685. return "/adminExecute";
  686. $ini = array ();
  687. $list = json_decode ( $executeInfo ['staff'], true );
  688. foreach ( $list as $k => $v ) {
  689. if ($v [0] == $uid) {
  690. $ini = $list [$k];
  691. unset ( $list [$k] );
  692. break;
  693. }
  694. }
  695. file_put_contents ( "protected/config/execute/execute.ini", "," . $ini [0], FILE_APPEND );
  696. $execute->staff = json_encode ( $list );
  697. $execute->update ( array (
  698. 'where' => 'eid = ' . $executeInfo ['eid']
  699. ) );
  700. }
  701. return "/adminExecute";
  702. }
  703. function adminInvoice() {
  704. Doo::loadModel ( 'staff' );
  705. $staff = new staff ();
  706. Doo::loadModel ( "invoiceManage" );
  707. $invoiceManage = new invoiceManage ();
  708. $data ['staffList'] = $staff->find ( array (
  709. 'select' => 'username,sid,avatar',
  710. 'asArray' => true
  711. ) );
  712. $list = $invoiceManage->find ( array (
  713. 'asArray' => true
  714. ) );
  715. $execute = array (
  716. '收款管理' => '',
  717. '发票审批' => '',
  718. '发票打印' => '',
  719. '发票邮寄' => '',
  720. '发票退票' => '',
  721. '公司汇总查阅' => ''
  722. );
  723. foreach ( $list as $key => $value ) {
  724. $name = json_decode ( $value ['staff'] );
  725. $staffString = "";
  726. if (! empty ( $name )) {
  727. foreach ( $name as $k => $v ) {
  728. $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>';
  729. }
  730. }
  731. foreach ( $execute as $k => $v ) {
  732. if ($k == $value ['mold']) {
  733. $execute [$k] = $name = $staffString;
  734. }
  735. }
  736. }
  737. $data ['invoice'] = $execute;
  738. $data ['memu'] = "invoice";
  739. $data ['staff'] = $this->staff;
  740. $this->render ( "/admin/adminInvoice", $data );
  741. }
  742. function addInvoiceManage() {
  743. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  744. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  745. if (! empty ( $mold ) && ! empty ( $staff )) {
  746. Doo::loadModel ( "invoiceManage" );
  747. $execute = new invoiceManage ();
  748. $executeInfo = $execute->getOne ( array (
  749. 'where' => 'mold ="' . $mold . '" ',
  750. 'asArray' => true
  751. ) );
  752. if (empty ( $executeInfo )) {
  753. $list = array ();
  754. foreach ( $staff as $key => $value ) {
  755. $info = explode ( ":", $value );
  756. array_push ( $list, $info );
  757. }
  758. $execute->mold = $mold;
  759. $execute->staff = json_encode ( $list );
  760. $execute->insert ();
  761. } else {
  762. $list = json_decode ( $executeInfo ['staff'], true );
  763. foreach ( $staff as $k => $v ) {
  764. $info = explode ( ":", $v );
  765. foreach ( $list as $key => $value ) {
  766. if ($value [1] == $info [1]) {
  767. unset ( $staff [$k] );
  768. break;
  769. }
  770. }
  771. }
  772. foreach ( $staff as $k => $v ) {
  773. $info = explode ( ":", $v );
  774. array_push ( $list, $info );
  775. }
  776. $execute->staff = json_encode ( $list );
  777. $execute->update ( array (
  778. 'where' => 'iid = ' . $executeInfo ['iid']
  779. ) );
  780. }
  781. }
  782. return "/adminInvoice";
  783. }
  784. /**
  785. * 发票相关权限配置,把相关组的审批人删除。不会影响已经生成发票数据,修改后只会影响修改后生成的发票数据
  786. * @return string 返回配置页
  787. */
  788. function delInvoiceManage() {
  789. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  790. $iid = isset ( $this->params ['iid'] ) && is_numeric ( $this->params ['iid'] ) ? $this->params ['iid'] : 0;
  791. if (! empty ( $uid ) && ! empty ( $iid )) {
  792. Doo::loadModel ( "invoiceManage" );
  793. $execute = new invoiceManage ();
  794. $executeInfo = $execute->getOne ( array (
  795. 'where' => 'iid ="' . $iid . '" ',
  796. 'asArray' => true
  797. ) );
  798. if (empty ( $executeInfo ))
  799. return "/adminInvoice";
  800. $ini = array ();
  801. $list = json_decode ( $executeInfo ['staff'], true );
  802. foreach ( $list as $k => $v ) {
  803. if ($v [0] == $uid) {
  804. $ini = $list [$k];
  805. unset ( $list [$k] );
  806. break;
  807. }
  808. }
  809. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  810. if (! empty ( $fileInvoice )) {
  811. $fileInvoice = json_decode ( $fileInvoice, true );
  812. if (isset ( $fileInvoice [$executeInfo ['mold']] ))
  813. $fileInvoice [$executeInfo ['mold']] .= "," . $ini [0];
  814. else
  815. $fileInvoice [$executeInfo ['mold']] = '';
  816. $moldArray = explode ( ',', $fileInvoice [$executeInfo ['mold']] );
  817. $moldArray = array_unique ( $moldArray );
  818. $fileInvoice [$executeInfo ['mold']] = implode ( ',', $moldArray );
  819. $fileInvoice = json_encode ( $fileInvoice );
  820. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  821. } else {
  822. $fileInvoice = array (
  823. $executeInfo ['mold'] => $ini [0]
  824. );
  825. $fileInvoice = json_encode ( $fileInvoice );
  826. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  827. }
  828. file_put_contents ( "protected/config/execute/invoice.ini", "," . $ini [0], FILE_APPEND );
  829. $execute->staff = json_encode ( $list );
  830. $execute->update ( array (
  831. 'where' => 'iid = ' . $executeInfo ['iid']
  832. ) );
  833. }
  834. return "/adminInvoice";
  835. }
  836. function ajaxRoleStaff() {
  837. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  838. Doo::loadModel ( 'staff' );
  839. $staff = new staff ();
  840. $staffList = $staff->find ( array (
  841. 'select' => 'username,sid,avatar',
  842. 'where' => 'username != "' . $name . '" and username !="admin"',
  843. 'asArray' => true
  844. ) );
  845. $html = '';
  846. foreach ( $staffList as $key => $value ) {
  847. $html .= '<option value=' . $value ['sid'] . '_' . $value ['username'] . '>' . $value ['username'] . '</option>';
  848. }
  849. echo json_encode ( array (
  850. "success" => true,
  851. 'html' => $html
  852. ) );
  853. die ();
  854. }
  855. function loadCVS() {
  856. Doo::loadModel ( 'longle' );
  857. $longle = new longle ();
  858. $list = $longle->find ( array (
  859. 'select' => 'key_num',
  860. 'asArray' => TRUE
  861. ) );
  862. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  863. while ( $data = fgetcsv ( $file ) ) {
  864. $goods_list [$data [0]] = $data [1];
  865. }
  866. fclose ( $file );
  867. $sqlArray = array ();
  868. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  869. foreach ( $list as $key => $value ) {
  870. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  871. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  872. // $longle->SerialNumber=$goods_list[$value['key_num']];
  873. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  874. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  875. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  876. unset ( $goods_list [$value ['key_num']] );
  877. }
  878. }
  879. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  880. echo $sql . '<br/>--------------------------------<br/>';
  881. foreach ( $goods_list as $key => $value ) {
  882. echo $key . ',' . $value . '<br/>';
  883. }
  884. }
  885. private function getRandChar($length) {
  886. $str = null;
  887. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  888. $max = strlen ( $strPol ) - 1;
  889. for($i = 0; $i < $length; $i ++) {
  890. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  891. }
  892. return $str;
  893. }
  894. private function getReceiptCount() {
  895. $status = 2;
  896. $year = date ( 'Y' );
  897. Doo::loadModel ( 'receipt' );
  898. $receipt = new receipt ();
  899. Doo::loadModel ( 'verify' );
  900. $verify = new verify ();
  901. // user verify ID
  902. $vidList = array ();
  903. $verifyDetail = $verify->find ( array (
  904. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '\"%"',
  905. 'asArray' => true
  906. ) );
  907. foreach ( $verifyDetail as $key => $value ) {
  908. array_push ( $vidList, $value ['vid'] );
  909. }
  910. $vid = implode ( ",", $vidList );
  911. if (empty ( $verifyDetail ))
  912. $vid = 0;
  913. $dateCondition = " and Year(date) =" . $year;
  914. $approvalCondition = ' and verifyStaff not like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  915. $receiptList = $receipt->find ( array (
  916. 'where' => 'verify in(' . $vid . ') and status=' . $status . $dateCondition . $approvalCondition,
  917. 'desc' => 'rid',
  918. 'asArray' => true
  919. ) );
  920. return count ( $receiptList );
  921. }
  922. /**
  923. * 格式化excel文件为数组
  924. * @param unknown_type $file_url
  925. * @param unknown_type $mcid
  926. */
  927. function _format_excel_to_array($file_url = "") {
  928. if (! file_exists ( $file_url ))
  929. return array ();
  930. Doo::loadClass ( 'PHPExcel' );
  931. $PHPExcel = new PHPExcel ();
  932. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  933. if (! $PHPReader->canRead ( $file_url )) {
  934. $PHPReader = new PHPExcel_Reader_Excel5 ();
  935. if (! $PHPReader->canRead ( $file_url )) {
  936. echo 'no Excel';
  937. return;
  938. }
  939. }
  940. $PHPExcel = $PHPReader->load ( $file_url );
  941. /**
  942. * 读取excel文件中的第一个工作表
  943. */
  944. $currentSheet = $PHPExcel->getSheet ( 0 );
  945. /**
  946. * 取得最大的列号
  947. */
  948. $allColumn = $currentSheet->getHighestColumn ();
  949. /**
  950. * 取得一共有多少行
  951. */
  952. $allRow = $currentSheet->getHighestRow ();
  953. $excel_array = array ();
  954. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  955. $excel_column = array ();
  956. // 后期改进
  957. if ($allColumn == 'AM')
  958. $allColumn = 'Z';
  959. /**
  960. * 从第A列开始输出
  961. */
  962. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  963. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  964. /**
  965. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  966. */
  967. $val = "'" . addslashes ( $val ) . "'";
  968. if ($currentColumn == 'A')
  969. $excel_column ['key_num'] = $val;
  970. elseif ($currentColumn == 'C')
  971. $excel_column ['product'] = $val;
  972. elseif ($currentColumn == 'D') {
  973. $val = str_replace ( "'", "", $val );
  974. $excel_column ['make_day'] = $this->excelTime ( $val );
  975. } elseif ($currentColumn == 'E') {
  976. $val = str_replace ( "'", "", $val );
  977. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  978. } elseif ($currentColumn == 'F') {
  979. $val = str_replace ( "'", "", $val );
  980. $excel_column ['version'] = $val;
  981. } elseif ($currentColumn == 'B') {
  982. $val = str_replace ( "'", "", $val );
  983. $excel_column ['SerialNumber'] = $val;
  984. }
  985. }
  986. array_push ( $excel_array, $excel_column );
  987. }
  988. return $excel_array;
  989. }
  990. function excelTime($date, $time = false) {
  991. if (function_exists ( 'GregorianToJD' )) {
  992. if (is_numeric ( $date )) {
  993. $jd = GregorianToJD ( 1, 1, 1970 );
  994. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  995. $date = explode ( '/', $gregorian );
  996. $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" : '');
  997. return $date_str;
  998. }
  999. } else {
  1000. $date = $date > 25568 ? $date + 1 : 25569;
  1001. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  1002. $ofs = (70 * 365 + 17 + 2) * 86400;
  1003. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  1004. }
  1005. return $date;
  1006. }
  1007. function _GetFileEXT($filename) {
  1008. $pics = explode ( '.', $filename );
  1009. $num = count ( $pics );
  1010. return $pics [$num - 1];
  1011. }
  1012. /**
  1013. * 获取get或者POST值
  1014. * @param string $name 属性名称
  1015. * @return fixed 值
  1016. */
  1017. function get_args($name) {
  1018. if (isset ( $_GET [$name] )) {
  1019. if (is_array ( $_GET [$name] ))
  1020. return $_GET [$name];
  1021. else {
  1022. return addslashes ( $_GET [$name] );
  1023. }
  1024. } elseif (isset ( $_POST [$name] )) {
  1025. if (is_array ( $_POST [$name] ))
  1026. return $_POST [$name];
  1027. else {
  1028. return addslashes ( $_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. Doo::loadModel('holidaystaff');
  1331. $hstaff = new HStaff();
  1332. $hstaffmsg = $hstaff->getOne(array('where' => 'uid=?','param' => array($cidstaff[0]), 'asArray' => TRUE));
  1333. if(!empty($hstaffmsg) && $hstaffmsg['iscc'] == 0){
  1334. $hstaff->uid = $cidstaff[0];
  1335. $hstaff->iscc = 1;
  1336. $hstaff->update();
  1337. }
  1338. return '/hcsgroup';
  1339. }
  1340. public function delHolidayCS(){
  1341. if(!isset($_POST['approvalid']) || empty($_POST['approvalid']) || !is_numeric($_POST['approvalid'])){
  1342. exit('审批id出错');
  1343. }
  1344. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1345. exit('抄送信息出错');
  1346. }
  1347. $cidstaff = explode(':',$_POST['cidstaff']);
  1348. Doo::loadModel('holidayacman');
  1349. $acman = new HACMan();
  1350. $csmsg = $acman->getOne(array('where' => 'type='.$_POST['approvalid'], 'asArray' => TRUE));
  1351. if(!empty($csmsg['idname'])){
  1352. $idnamearr = explode(',', $csmsg['idname']);
  1353. foreach($idnamearr as $ik => $iv){
  1354. if($iv == $cidstaff[0]){
  1355. unset($idnamearr[$ik]);
  1356. break;
  1357. }
  1358. }
  1359. $csidmsg = implode(',',$idnamearr);
  1360. }
  1361. if(!empty($csmsg['name'])){
  1362. $namearr = explode(' ', $csmsg['name']);
  1363. foreach($namearr as $nk => $nv){
  1364. if($nv == $cidstaff[1]){
  1365. unset($namearr[$nk]);
  1366. break;
  1367. }
  1368. }
  1369. $csnamemsg = implode(' ',$namearr);
  1370. }
  1371. if(!empty($csmsg['pinyinname'])){
  1372. $pinyinnamearr = explode('|', $csmsg['pinyinname']);
  1373. foreach($pinyinnamearr as $pk => $pv){
  1374. if($pv == $cidstaff[2]){
  1375. unset($pinyinnamearr[$pk]);
  1376. break;
  1377. }
  1378. }
  1379. $cspinyinnamemsg = implode('|',$pinyinnamearr);
  1380. }
  1381. $acman->id = $csmsg['id'];
  1382. if(isset($csidmsg)){
  1383. $acman->idname = $csidmsg;
  1384. }
  1385. if(isset($csnamemsg)){
  1386. $acman->name = $csnamemsg;
  1387. }
  1388. if(isset($cspinyinnamemsg)){
  1389. $acman->pinyinname = $cspinyinnamemsg;
  1390. }
  1391. $acman->update();
  1392. //删除抄送员资格
  1393. $acman3 = new HACMan();
  1394. $same = 0;
  1395. $approverlist = $acman3->find(array('where' => 'idname like "%'.$cidstaff[0].'%" and type!=0', 'asArray' => TRUE));
  1396. if(!empty($approverlist)){
  1397. foreach($approverlist as $ak => $av){
  1398. $aidname = explode(',', $av['idname']);
  1399. foreach($aidname as $ik => $iv){
  1400. if($iv == $cidstaff[0]){
  1401. $same = 1;
  1402. break;
  1403. }
  1404. }
  1405. }
  1406. }
  1407. if($same == 0){
  1408. Doo::loadModel('holidaystaff');
  1409. $hstaff = new HStaff();
  1410. $hstaff->uid = $cidstaff[0];
  1411. $hstaff->iscc = 0;
  1412. $hstaff->update();
  1413. }
  1414. return '/hcsgroup';
  1415. }
  1416. public function HolidayAdmin(){
  1417. Doo::loadModel('staff');
  1418. $staff=new staff();
  1419. $staffList=$staff->find(array('select'=>'username,sid', 'where' => 'cid!=1','asArray'=>true));
  1420. Doo::loadModel('holidayadmin');
  1421. $admin = new HAdmin();
  1422. $adminList = $admin->find(array('asArray' => TRUE));
  1423. if(!empty($adminList)){
  1424. foreach($adminList as $k => $v){
  1425. foreach($staffList as $sk => $sv){
  1426. if($sv['sid'] == $v['uid']){
  1427. array_splice($staffList, $sk,1);
  1428. break;
  1429. }
  1430. }
  1431. }
  1432. }
  1433. $data['staffList'] = $staffList;
  1434. $data['adminList'] = $adminList;
  1435. $data['memu'] = 'holiday';
  1436. $data['noindexjs'] = 'noindexjs';
  1437. $this->render( "/admin/admin_holidayuser", $data );
  1438. }
  1439. public function addHolidayAdmin(){
  1440. if(!isset($_POST['staff']) || empty($_POST['staff'])){
  1441. exit('请选择管理人');
  1442. }
  1443. Doo::loadModel('holidayadmin');
  1444. foreach($_POST['staff'] as $k => $v){
  1445. $staffmsg = explode(':',$v);
  1446. $admin = new HAdmin();
  1447. $admin->uid = $staffmsg[0];
  1448. $admin->username = $staffmsg[1];
  1449. $admin->insert();
  1450. }
  1451. return '/holidayadmin';
  1452. }
  1453. public function delHolidayAdmin(){
  1454. if(!isset($_POST['cidstaff']) || empty($_POST['cidstaff'])){
  1455. exit('请选择管理人删除');
  1456. }
  1457. Doo::loadModel('holidayadmin');
  1458. $admin = new HAdmin();
  1459. $admin->id = $_POST['cidstaff'];
  1460. $admin->delete();
  1461. return '/holidayadmin';
  1462. }
  1463. //检查年假是否过期并更新年假
  1464. private function updateAnnualLeave($staff){
  1465. Doo::loadModel('holidaystaff');
  1466. $hstaff = new HStaff();
  1467. $hstaffmsg = $hstaff->getOne(array('where' => 'uid='.$staff['sid'],'asArray' => TRUE));
  1468. $hiredate = $staff['hiredate'];
  1469. $hadyear = intval((time()-strtotime($hiredate))/(86400*365));
  1470. if($hadyear != $hstaffmsg['hadyear']){
  1471. $hstaff->uid = $staff['sid'];
  1472. $hstaff->hadyear = $hadyear;
  1473. $hstaff->yearnum = $hadyear == 0 ? 0 : (($hadyear < 10 && $hadyear >= 1) ? 5 : (($hadyear >= 10 && $hadyear < 20) ? 10 : 15));
  1474. $hstaff->update();
  1475. }
  1476. }
  1477. }
  1478. ?>