AdminController.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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->yearnum = $nature == 1 ? (time () > strtotime ( "+ 1 year", strtotime ( $hiredate ) ) ? 5 : 0) : 0;
  212. $holidaystaff->insert ();
  213. for($i = 1; $i <= 7; $i ++) {
  214. $tag = new tag ();
  215. $tag->name = "个人标签";
  216. $tag->sid = $id;
  217. $tag->colorid = $i;
  218. $tag->insert ();
  219. }
  220. }
  221. return "/adminuser";
  222. }
  223. function adminEdiUser() {
  224. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  225. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  226. if (! empty ( $sid )) {
  227. $data ['msg'] = urldecode ( $msg );
  228. Doo::loadModel ( 'L_category' );
  229. Doo::loadModel ( 'staff' );
  230. $staff = new staff ();
  231. $L_category = new L_category ();
  232. $data ['newPw'] = '';
  233. $data ['staffInfo'] = $staff->getUserById ( $sid );
  234. $data ['category'] = $L_category->getCategory ();
  235. $data ['staff'] = $this->staff;
  236. $data ['memu'] = "adminuser";
  237. $this->render ( "/admin/admin_EdiUser", $data );
  238. } else
  239. return "/adminuser";
  240. }
  241. function adminResetUserPw() {
  242. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  243. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  244. if (! empty ( $sid )) {
  245. $data ['msg'] = urldecode ( $msg );
  246. Doo::loadModel ( 'L_category' );
  247. Doo::loadModel ( 'staff' );
  248. $staff = new staff ();
  249. $L_category = new L_category ();
  250. $newPw = $this->getRandChar ( 6 );
  251. $staff->sid = $sid;
  252. $staff->passwork = md5 ( $newPw );
  253. $staff->update ();
  254. $data ['newPw'] = $newPw;
  255. $data ['staffInfo'] = $staff->getUserById ( $sid );
  256. $data ['category'] = $L_category->getCategory ();
  257. $data ['staff'] = $this->staff;
  258. $data ['memu'] = "adminuser";
  259. $this->render ( "/admin/admin_EdiUser", $data );
  260. } else
  261. return "/adminuser";
  262. }
  263. function adminDoEdiUser() {
  264. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  265. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  266. $gender = $this->get_args ( 'gender' ) ? $this->get_args ( 'gender' ) : "";
  267. $qq = is_numeric ( $this->get_args ( 'qq' ) ) ? $this->get_args ( 'qq' ) : 0;
  268. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  269. $telephone = $this->get_args ( 'telephone' ) ? $this->get_args ( 'telephone' ) : "";
  270. $email = $this->get_args ( 'email' ) ? $this->get_args ( 'email' ) : "";
  271. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  272. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  273. $hiredate = $this->get_args ( 'hiredate' ) ? $this->get_args ( 'hiredate' ) : "";
  274. if (! empty ( $sid )) {
  275. $msg = "";
  276. Doo::loadModel ( 'L_category' );
  277. Doo::loadModel ( 'staff' );
  278. $staff = new staff ();
  279. $L_category = new L_category ();
  280. $categoryInfo = $L_category->getCategoryById ( $cid );
  281. $staff->sid = $sid;
  282. if ($cid != 0) {
  283. $staff->cid = $categoryInfo [0] ['cid'];
  284. $staff->category = $categoryInfo [0] ['title'];
  285. }
  286. if ($categoryInfo [0] ['defult'] == 1) {
  287. $staff->isadmin = 1;
  288. } else {
  289. $staff->isadmin = 0;
  290. }
  291. if (! empty ( $username ))
  292. $staff->username = $username;
  293. if (! empty ( $gender ))
  294. $staff->gender = $gender;
  295. if (! empty ( $qq ) && is_numeric ( $qq ))
  296. $staff->qq = $qq;
  297. if (! empty ( $phone ))
  298. $staff->phone = $phone;
  299. if (! empty ( $telephone ))
  300. $staff->telephone = $telephone;
  301. if (! empty ( $email ) && filter_var ( $email, FILTER_VALIDATE_EMAIL ))
  302. $staff->email = $email;
  303. else
  304. $msg = "邮箱不正确";
  305. if (! empty ( $hiredate ))
  306. $staff->hiredate = $hiredate;
  307. $staff->nature = $nature;
  308. $staff->update ();
  309. $staffmsg = $staff->getUserById ( $sid );
  310. $this->updateAnnualLeave ( $staffmsg [0] );
  311. return "/edi/user/" . $sid . "/" . $msg;
  312. } else {
  313. return "/adminuser";
  314. }
  315. }
  316. function adminDoAddCategory() {
  317. $sid = is_numeric ( $this->get_args ( 'sid' ) ) ? $this->get_args ( 'sid' ) : 0;
  318. $cid = is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  319. if (! empty ( $sid )) {
  320. Doo::loadModel ( 'L_category' );
  321. Doo::loadModel ( 'staff' );
  322. $staff = new staff ();
  323. $L_category = new L_category ();
  324. $stfInfo = $staff->getOne ( array (
  325. 'where' => 'sid =' . $sid,
  326. 'asArray' => true
  327. ) );
  328. if ($stfInfo ['cid'] == $cid)
  329. return "/adminuser";
  330. $othcid = explode ( ',', $stfInfo ['othercid'] );
  331. if (in_array ( $cid, $othcid ))
  332. return "/adminuser";
  333. array_push ( $othcid, $cid );
  334. $strCid = implode ( ',', array_filter ( $othcid ) );
  335. $catename = $L_category->getCategoryById ( $cid );
  336. $othcategory = explode ( ',', $stfInfo ['othercategory'] );
  337. array_push ( $othcategory, $catename [0] ['title'] );
  338. $strcategory = implode ( ',', array_filter ( $othcategory ) );
  339. $staff->sid = $sid;
  340. $staff->othercid = $strCid;
  341. $staff->othercategory = $strcategory;
  342. $staff->update ();
  343. }
  344. return "/adminuser";
  345. }
  346. function adminDeleteUser() {
  347. $sid = is_numeric ( $this->params ['sid'] ) ? $this->params ['sid'] : 0;
  348. if (! empty ( $sid )) {
  349. Doo::loadModel ( 'staff' );
  350. $staff = new staff ();
  351. $staff->sid = $sid;
  352. $staff->delete ();
  353. }
  354. return "/adminuser";
  355. }
  356. function adminproduct() {
  357. $data ['memu'] = "adminproduct";
  358. $data ['staff'] = $this->staff;
  359. Doo::loadModel ( 'product' );
  360. Doo::loadModel ( 'longle' );
  361. $product = new product ();
  362. $longle = new longle ();
  363. $data ['product'] = $product->getProudct ();
  364. foreach ( $data ['product'] as $key => $value ) {
  365. $data ['product'] [$key] ['count'] = $longle->count ( array (
  366. 'where' => 'product="' . $value ['title'] . '"'
  367. ) );
  368. }
  369. $this->render ( "/admin/admin_product", $data );
  370. }
  371. function addproduct() {
  372. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  373. if (! empty ( $title )) {
  374. Doo::loadModel ( 'product' );
  375. $product = new product ();
  376. $product->title = $title;
  377. $product->insert ();
  378. }
  379. return "/adminproduct";
  380. }
  381. function adminDeleteProduct() {
  382. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  383. if (! empty ( $pid )) {
  384. Doo::loadModel ( 'product' );
  385. $product = new product ();
  386. $product->pid = $pid;
  387. $product->delete ();
  388. }
  389. return "/adminproduct";
  390. }
  391. function adminEdiProduct() {
  392. $pid = is_numeric ( $this->params ['pid'] ) ? $this->params ['pid'] : 0;
  393. $msg = isset ( $this->params ['msg'] ) ? $this->params ['msg'] : "";
  394. if (! empty ( $pid )) {
  395. $data ['msg'] = urldecode ( $msg );
  396. Doo::loadModel ( 'product' );
  397. $product = new product ();
  398. $data ['productInfo'] = $product->getProductById ( $pid );
  399. $data ['memu'] = "adminproduct";
  400. $data ['staff'] = $this->staff;
  401. $this->render ( "/admin/admin_EdiProduct", $data );
  402. } else
  403. return "/adminproduct";
  404. }
  405. function adminDoEdiProduct() {
  406. $pid = is_numeric ( $this->get_args ( 'pid' ) ) ? $this->get_args ( 'pid' ) : "";
  407. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  408. $typeid = $this->get_args ( 'typeid' ) ? $this->get_args ( 'typeid' ) : "";
  409. if (! empty ( $pid ) && ! empty ( $title ) && ! empty ( $typeid )) {
  410. $msg = "";
  411. Doo::loadModel ( 'product' );
  412. $product = new product ();
  413. $product->pid = $pid;
  414. $product->title = $title;
  415. $product->typeid = $typeid;
  416. $product->update ();
  417. return "/adminproduct";
  418. } else {
  419. return "/adminproduct";
  420. }
  421. }
  422. function adminverify() {
  423. Doo::loadModel ( 'staff' );
  424. Doo::loadModel ( "verify" );
  425. $verify = new verify ();
  426. $staff = new staff ();
  427. Doo::loadModel ( "role" );
  428. $role = new role ();
  429. $data ['staffList'] = $staff->find ( array (
  430. 'select' => 'username,sid,avatar',
  431. 'asArray' => true
  432. ) );
  433. $list = $verify->find ( array (
  434. 'asArray' => true
  435. ) );
  436. $roleList = $role->find ( array (
  437. 'asArray' => true
  438. ) );
  439. foreach ( $roleList as $key => $value ) {
  440. $staffList = json_decode ( $value ['staff'] );
  441. foreach ( $staffList as $k => $v ) {
  442. $staffList [$k] = substr ( strstr ( $v, '_' ), 1 );
  443. }
  444. $roleList [$key] ['staff'] = implode ( ',', $staffList );
  445. }
  446. foreach ( $list as $key => $value ) {
  447. $name = json_decode ( $value ['staff'] );
  448. $list [$key] ['staff'] = "";
  449. foreach ( $name as $k => $v ) {
  450. if ($v [1] == 'ROLE') {
  451. $roleInfo = $role->getOne ( array (
  452. 'where' => 'rid = "' . $v [0] . '"',
  453. 'asArray' => true
  454. ) );
  455. $v [1] = $roleInfo ['name'];
  456. }
  457. $list [$key] ['staff'] .= " " . $v [1];
  458. }
  459. }
  460. $data ['roleList'] = $roleList;
  461. $data ['verify'] = $list;
  462. $data ['memu'] = "verify";
  463. $data ['staff'] = $this->staff;
  464. $this->render ( "/admin/admin_reportGroup", $data );
  465. }
  466. function addVerify() {
  467. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  468. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  469. $uidlist = $this->get_args ( 'uidlist' ) ? $this->get_args ( 'uidlist' ) : "";
  470. $uidlist = explode ( ",", $uidlist );
  471. Doo::loadModel ( "role" );
  472. $role = new role ();
  473. $list = array ();
  474. foreach ( $uidlist as $key => $value ) {
  475. $info = explode ( ":", $value );
  476. if ($info [1] == 'ROLE') {
  477. $roleInfo = $role->getOne ( array (
  478. 'where' => 'rid = "' . $info [0] . '"',
  479. 'asArray' => true
  480. ) );
  481. array_push ( $info, $roleInfo ['staff'] );
  482. }
  483. array_push ( $list, $info );
  484. }
  485. if (! empty ( $description ) && ! empty ( $list )) {
  486. Doo::loadModel ( "verify" );
  487. $verify = new verify ();
  488. $verify->description = $description;
  489. $verify->staff = json_encode ( $list );
  490. $verify->insert ();
  491. }
  492. return "/adminverify";
  493. }
  494. function adminRole() {
  495. Doo::loadModel ( 'staff' );
  496. $staff = new staff ();
  497. Doo::loadModel ( "verify" );
  498. $verify = new verify ();
  499. Doo::loadModel ( "role" );
  500. $role = new role ();
  501. $data ['staffList'] = $staff->find ( array (
  502. 'select' => 'username,sid,avatar',
  503. 'asArray' => true
  504. ) );
  505. $list = $verify->find ( array (
  506. 'asArray' => true
  507. ) );
  508. $roleList = $role->find ( array (
  509. 'asArray' => true
  510. ) );
  511. foreach ( $list as $key => $value ) {
  512. $name = json_decode ( $value ['staff'] );
  513. $list [$key] ['staff'] = "";
  514. foreach ( $name as $k => $v ) {
  515. $list [$key] ['staff'] .= " " . $v [1];
  516. }
  517. }
  518. foreach ( $roleList as $key => $value ) {
  519. $staff = json_decode ( $value ['staff'] );
  520. foreach ( $staff as $k => $v ) {
  521. // print_r($info);
  522. // $staff[$k]=substr(strstr($v, '_'), 1);
  523. $info = explode ( '_', $v );
  524. $staff [$k] = $info;
  525. }
  526. $roleList [$key] ['list'] = $staff;
  527. }
  528. $data ['roleList'] = $roleList;
  529. $data ['verify'] = $list;
  530. $data ['memu'] = "verify";
  531. $data ['staff'] = $this->staff;
  532. $this->render ( "/admin/adminReportGroupRole", $data );
  533. }
  534. function addRole() {
  535. $name = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  536. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  537. $list = array ();
  538. foreach ( $staff as $key => $value ) {
  539. $na = explode ( ":", $value );
  540. array_push ( $list, $na [0] . '_' . $na [1] );
  541. }
  542. if (! empty ( $name ) && ! empty ( $list )) {
  543. Doo::loadModel ( "role" );
  544. $role = new role ();
  545. $role->name = $name;
  546. $role->staff = json_encode ( $list );
  547. $role->insert ();
  548. }
  549. return "/adminRole";
  550. }
  551. function delRole() {
  552. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  553. if (! empty ( $rid )) {
  554. Doo::loadModel ( "role" );
  555. $role = new role ();
  556. $role->delete ( array (
  557. 'where' => 'rid="' . $rid . '"'
  558. ) );
  559. }
  560. return "/adminRole";
  561. }
  562. function updateRole() {
  563. $oldStaff = $this->get_args ( 'oldStaff' ) ? $this->get_args ( 'oldStaff' ) : "";
  564. $newStaff = $this->get_args ( 'newStaff' ) ? $this->get_args ( 'newStaff' ) : "";
  565. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  566. if (! empty ( $oldStaff ) && ! empty ( $newStaff ) && ! empty ( $rid )) {
  567. Doo::loadModel ( "role" );
  568. $role = new role ();
  569. $roleInfo = $role->getOne ( array (
  570. 'where' => 'rid = "' . $rid . '"',
  571. 'asArray' => true
  572. ) );
  573. $staffList = json_decode ( $roleInfo ['staff'], true );
  574. foreach ( $staffList as $key => $value ) {
  575. if ($value == $oldStaff) {
  576. $staffList [$key] = $newStaff;
  577. break;
  578. }
  579. }
  580. $role->staff = json_encode ( $staffList );
  581. $role->update ( array (
  582. 'where' => 'rid = "' . $rid . '"'
  583. ) );
  584. }
  585. return "/adminRole";
  586. }
  587. function adminExecute() {
  588. Doo::loadModel ( 'staff' );
  589. $staff = new staff ();
  590. Doo::loadModel ( "execute" );
  591. $execute = new execute ();
  592. $data ['staffList'] = $staff->find ( array (
  593. 'select' => 'username,sid,avatar',
  594. 'asArray' => true
  595. ) );
  596. $list = $execute->find ( array (
  597. 'asArray' => true
  598. ) );
  599. $execute = array (
  600. '借款执行人' => '',
  601. '借款费用执行人' => '',
  602. '报销单执行人' => '',
  603. '对公汇款执行人' => ''
  604. );
  605. foreach ( $list as $key => $value ) {
  606. $name = json_decode ( $value ['staff'] );
  607. $staffString = "";
  608. if (! empty ( $name )) {
  609. foreach ( $name as $k => $v ) {
  610. $staffString .= " " . $v [1] . '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/delExecute/' . $v [0] . '/' . $value ['eid'] . '\'" title="删除" class="icon-">k</a>';
  611. }
  612. }
  613. foreach ( $execute as $k => $v ) {
  614. if ($k == $value ['mold']) {
  615. $execute [$k] = $name = $staffString;
  616. }
  617. }
  618. }
  619. // print_r($execute);die;
  620. $data ['execute'] = $execute;
  621. $data ['memu'] = "verify";
  622. $data ['staff'] = $this->staff;
  623. $this->render ( "/admin/adminCarriedout", $data );
  624. }
  625. function addExecute() {
  626. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  627. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  628. if (! empty ( $mold ) && ! empty ( $staff )) {
  629. Doo::loadModel ( "execute" );
  630. $execute = new execute ();
  631. $executeInfo = $execute->getOne ( array (
  632. 'where' => 'mold ="' . $mold . '" ',
  633. 'asArray' => true
  634. ) );
  635. if (empty ( $executeInfo )) {
  636. $list = array ();
  637. foreach ( $staff as $key => $value ) {
  638. $info = explode ( ":", $value );
  639. array_push ( $list, $info );
  640. }
  641. $execute->mold = $mold;
  642. $execute->staff = json_encode ( $list );
  643. $execute->insert ();
  644. } else {
  645. $list = json_decode ( $executeInfo ['staff'], true );
  646. foreach ( $staff as $k => $v ) {
  647. $info = explode ( ":", $v );
  648. foreach ( $list as $key => $value ) {
  649. if ($value [1] == $info [1]) {
  650. unset ( $staff [$k] );
  651. break;
  652. }
  653. }
  654. }
  655. foreach ( $staff as $k => $v ) {
  656. $info = explode ( ":", $v );
  657. array_push ( $list, $info );
  658. }
  659. $execute->staff = json_encode ( $list );
  660. $execute->update ( array (
  661. 'where' => 'eid = ' . $executeInfo ['eid']
  662. ) );
  663. }
  664. }
  665. return "/adminExecute";
  666. }
  667. function delExecute() {
  668. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  669. $eid = isset ( $this->params ['eid'] ) && is_numeric ( $this->params ['eid'] ) ? $this->params ['eid'] : 0;
  670. if (! empty ( $uid ) && ! empty ( $eid )) {
  671. Doo::loadModel ( "execute" );
  672. $execute = new execute ();
  673. $executeInfo = $execute->getOne ( array (
  674. 'where' => 'eid ="' . $eid . '" ',
  675. 'asArray' => true
  676. ) );
  677. if (empty ( $executeInfo ))
  678. return "/adminExecute";
  679. $ini = array ();
  680. $list = json_decode ( $executeInfo ['staff'], true );
  681. foreach ( $list as $k => $v ) {
  682. if ($v [0] == $uid) {
  683. $ini = $list [$k];
  684. unset ( $list [$k] );
  685. break;
  686. }
  687. }
  688. file_put_contents ( "protected/config/execute/execute.ini", "," . $ini [0], FILE_APPEND );
  689. $execute->staff = json_encode ( $list );
  690. $execute->update ( array (
  691. 'where' => 'eid = ' . $executeInfo ['eid']
  692. ) );
  693. }
  694. return "/adminExecute";
  695. }
  696. function adminInvoice() {
  697. Doo::loadModel ( 'staff' );
  698. $staff = new staff ();
  699. Doo::loadModel ( "invoiceManage" );
  700. $invoiceManage = new invoiceManage ();
  701. $data ['staffList'] = $staff->find ( array (
  702. 'select' => 'username,sid,avatar',
  703. 'asArray' => true
  704. ) );
  705. $list = $invoiceManage->find ( array (
  706. 'asArray' => true
  707. ) );
  708. $execute = array (
  709. '收款管理' => '',
  710. '发票审批' => '',
  711. '发票打印' => '',
  712. '发票邮寄' => '',
  713. '公司汇总查阅' => ''
  714. );
  715. foreach ( $list as $key => $value ) {
  716. $name = json_decode ( $value ['staff'] );
  717. $staffString = "";
  718. if (! empty ( $name )) {
  719. foreach ( $name as $k => $v ) {
  720. $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>';
  721. }
  722. }
  723. foreach ( $execute as $k => $v ) {
  724. if ($k == $value ['mold']) {
  725. $execute [$k] = $name = $staffString;
  726. }
  727. }
  728. }
  729. $data ['invoice'] = $execute;
  730. $data ['memu'] = "invoice";
  731. $data ['staff'] = $this->staff;
  732. $this->render ( "/admin/adminInvoice", $data );
  733. }
  734. function addInvoiceManage() {
  735. $mold = $this->get_args ( 'mold' ) ? $this->get_args ( 'mold' ) : "";
  736. $staff = $this->get_args ( 'staff' ) ? $this->get_args ( 'staff' ) : "";
  737. if (! empty ( $mold ) && ! empty ( $staff )) {
  738. Doo::loadModel ( "invoiceManage" );
  739. $execute = new invoiceManage ();
  740. $executeInfo = $execute->getOne ( array (
  741. 'where' => 'mold ="' . $mold . '" ',
  742. 'asArray' => true
  743. ) );
  744. if (empty ( $executeInfo )) {
  745. $list = array ();
  746. foreach ( $staff as $key => $value ) {
  747. $info = explode ( ":", $value );
  748. array_push ( $list, $info );
  749. }
  750. $execute->mold = $mold;
  751. $execute->staff = json_encode ( $list );
  752. $execute->insert ();
  753. } else {
  754. $list = json_decode ( $executeInfo ['staff'], true );
  755. foreach ( $staff as $k => $v ) {
  756. $info = explode ( ":", $v );
  757. foreach ( $list as $key => $value ) {
  758. if ($value [1] == $info [1]) {
  759. unset ( $staff [$k] );
  760. break;
  761. }
  762. }
  763. }
  764. foreach ( $staff as $k => $v ) {
  765. $info = explode ( ":", $v );
  766. array_push ( $list, $info );
  767. }
  768. $execute->staff = json_encode ( $list );
  769. $execute->update ( array (
  770. 'where' => 'iid = ' . $executeInfo ['iid']
  771. ) );
  772. }
  773. }
  774. return "/adminInvoice";
  775. }
  776. /**
  777. * 发票相关权限配置,把相关组的审批人删除。不会影响已经生成发票数据,修改后只会影响修改后生成的发票数据
  778. * @return string 返回配置页
  779. */
  780. function delInvoiceManage() {
  781. $uid = isset ( $this->params ['uid'] ) && is_numeric ( $this->params ['uid'] ) ? $this->params ['uid'] : 0;
  782. $iid = isset ( $this->params ['iid'] ) && is_numeric ( $this->params ['iid'] ) ? $this->params ['iid'] : 0;
  783. if (! empty ( $uid ) && ! empty ( $iid )) {
  784. Doo::loadModel ( "invoiceManage" );
  785. $execute = new invoiceManage ();
  786. $executeInfo = $execute->getOne ( array (
  787. 'where' => 'iid ="' . $iid . '" ',
  788. 'asArray' => true
  789. ) );
  790. if (empty ( $executeInfo ))
  791. return "/adminInvoice";
  792. $ini = array ();
  793. $list = json_decode ( $executeInfo ['staff'], true );
  794. foreach ( $list as $k => $v ) {
  795. if ($v [0] == $uid) {
  796. $ini = $list [$k];
  797. unset ( $list [$k] );
  798. break;
  799. }
  800. }
  801. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  802. if (! empty ( $fileInvoice )) {
  803. $fileInvoice = json_decode ( $fileInvoice, true );
  804. if (isset ( $fileInvoice [$executeInfo ['mold']] ))
  805. $fileInvoice [$executeInfo ['mold']] .= "," . $ini [0];
  806. else
  807. $fileInvoice [$executeInfo ['mold']] = '';
  808. $moldArray = explode ( ',', $fileInvoice [$executeInfo ['mold']] );
  809. $moldArray = array_unique ( $moldArray );
  810. $fileInvoice [$executeInfo ['mold']] = implode ( ',', $moldArray );
  811. $fileInvoice = json_encode ( $fileInvoice );
  812. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  813. } else {
  814. $fileInvoice = array (
  815. $executeInfo ['mold'] => $ini [0]
  816. );
  817. $fileInvoice = json_encode ( $fileInvoice );
  818. file_put_contents ( "protected/config/invoice/invoice.ini", $fileInvoice );
  819. }
  820. file_put_contents ( "protected/config/execute/invoice.ini", "," . $ini [0], FILE_APPEND );
  821. $execute->staff = json_encode ( $list );
  822. $execute->update ( array (
  823. 'where' => 'iid = ' . $executeInfo ['iid']
  824. ) );
  825. }
  826. return "/adminInvoice";
  827. }
  828. function ajaxRoleStaff() {
  829. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : "";
  830. Doo::loadModel ( 'staff' );
  831. $staff = new staff ();
  832. $staffList = $staff->find ( array (
  833. 'select' => 'username,sid,avatar',
  834. 'where' => 'username != "' . $name . '" and username !="admin"',
  835. 'asArray' => true
  836. ) );
  837. $html = '';
  838. foreach ( $staffList as $key => $value ) {
  839. $html .= '<option value=' . $value ['sid'] . '_' . $value ['username'] . '>' . $value ['username'] . '</option>';
  840. }
  841. echo json_encode ( array (
  842. "success" => true,
  843. 'html' => $html
  844. ) );
  845. die ();
  846. }
  847. function loadCVS() {
  848. Doo::loadModel ( 'longle' );
  849. $longle = new longle ();
  850. $list = $longle->find ( array (
  851. 'select' => 'key_num',
  852. 'asArray' => TRUE
  853. ) );
  854. $file = fopen ( DOO::conf ()->SITE_PATH . "upload/key2.csv", 'r' );
  855. while ( $data = fgetcsv ( $file ) ) {
  856. $goods_list [$data [0]] = $data [1];
  857. }
  858. fclose ( $file );
  859. $sqlArray = array ();
  860. $sql = 'UPDATE CLD_longle SET SerialNumber = CASE key_num ';
  861. foreach ( $list as $key => $value ) {
  862. if (array_key_exists ( $value ['key_num'], $goods_list )) {
  863. // echo $value['key_num'].'-'.$goods_list[$value['key_num']].'<br/>';
  864. // $longle->SerialNumber=$goods_list[$value['key_num']];
  865. // $longle->update(array('where'=>'key_num="'.$value['key_num'].'"'));
  866. $sql .= ' WHEN "' . $value ['key_num'] . '" THEN "' . $goods_list [$value ['key_num']] . '" ';
  867. array_push ( $sqlArray, '"' . $value ['key_num'] . '"' );
  868. unset ( $goods_list [$value ['key_num']] );
  869. }
  870. }
  871. $sql .= 'END WHERE key_num IN (' . implode ( ',', $sqlArray ) . ')';
  872. echo $sql . '<br/>--------------------------------<br/>';
  873. foreach ( $goods_list as $key => $value ) {
  874. echo $key . ',' . $value . '<br/>';
  875. }
  876. }
  877. private function getRandChar($length) {
  878. $str = null;
  879. $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
  880. $max = strlen ( $strPol ) - 1;
  881. for($i = 0; $i < $length; $i ++) {
  882. $str .= $strPol [rand ( 0, $max )]; // rand($min,$max)生成介于min和max两个数之间的一个随机整数
  883. }
  884. return $str;
  885. }
  886. private function getReceiptCount() {
  887. $status = 2;
  888. $year = date ( 'Y' );
  889. Doo::loadModel ( 'receipt' );
  890. $receipt = new receipt ();
  891. Doo::loadModel ( 'verify' );
  892. $verify = new verify ();
  893. // user verify ID
  894. $vidList = array ();
  895. $verifyDetail = $verify->find ( array (
  896. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '\"%"',
  897. 'asArray' => true
  898. ) );
  899. foreach ( $verifyDetail as $key => $value ) {
  900. array_push ( $vidList, $value ['vid'] );
  901. }
  902. $vid = implode ( ",", $vidList );
  903. if (empty ( $verifyDetail ))
  904. $vid = 0;
  905. $dateCondition = " and Year(date) =" . $year;
  906. $approvalCondition = ' and verifyStaff not like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  907. $receiptList = $receipt->find ( array (
  908. 'where' => 'verify in(' . $vid . ') and status=' . $status . $dateCondition . $approvalCondition,
  909. 'desc' => 'rid',
  910. 'asArray' => true
  911. ) );
  912. return count ( $receiptList );
  913. }
  914. /**
  915. * 格式化excel文件为数组
  916. * @param unknown_type $file_url
  917. * @param unknown_type $mcid
  918. */
  919. function _format_excel_to_array($file_url = "") {
  920. if (! file_exists ( $file_url ))
  921. return array ();
  922. Doo::loadClass ( 'PHPExcel' );
  923. $PHPExcel = new PHPExcel ();
  924. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  925. if (! $PHPReader->canRead ( $file_url )) {
  926. $PHPReader = new PHPExcel_Reader_Excel5 ();
  927. if (! $PHPReader->canRead ( $file_url )) {
  928. echo 'no Excel';
  929. return;
  930. }
  931. }
  932. $PHPExcel = $PHPReader->load ( $file_url );
  933. /**
  934. * 读取excel文件中的第一个工作表
  935. */
  936. $currentSheet = $PHPExcel->getSheet ( 0 );
  937. /**
  938. * 取得最大的列号
  939. */
  940. $allColumn = $currentSheet->getHighestColumn ();
  941. /**
  942. * 取得一共有多少行
  943. */
  944. $allRow = $currentSheet->getHighestRow ();
  945. $excel_array = array ();
  946. for($currentRow = 2; $currentRow <= $allRow; $currentRow ++) {
  947. $excel_column = array ();
  948. // 后期改进
  949. if ($allColumn == 'AM')
  950. $allColumn = 'Z';
  951. /**
  952. * 从第A列开始输出
  953. */
  954. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  955. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  956. /**
  957. * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312',
  958. */
  959. $val = "'" . addslashes ( $val ) . "'";
  960. if ($currentColumn == 'A')
  961. $excel_column ['key_num'] = $val;
  962. elseif ($currentColumn == 'C')
  963. $excel_column ['product'] = $val;
  964. elseif ($currentColumn == 'D') {
  965. $val = str_replace ( "'", "", $val );
  966. $excel_column ['make_day'] = $this->excelTime ( $val );
  967. } elseif ($currentColumn == 'E') {
  968. $val = str_replace ( "'", "", $val );
  969. $excel_column ['alloted_time'] = $this->excelTime ( $val );
  970. } elseif ($currentColumn == 'F') {
  971. $val = str_replace ( "'", "", $val );
  972. $excel_column ['version'] = $val;
  973. } elseif ($currentColumn == 'B') {
  974. $val = str_replace ( "'", "", $val );
  975. $excel_column ['SerialNumber'] = $val;
  976. }
  977. }
  978. array_push ( $excel_array, $excel_column );
  979. }
  980. return $excel_array;
  981. }
  982. function excelTime($date, $time = false) {
  983. if (function_exists ( 'GregorianToJD' )) {
  984. if (is_numeric ( $date )) {
  985. $jd = GregorianToJD ( 1, 1, 1970 );
  986. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  987. $date = explode ( '/', $gregorian );
  988. $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" : '');
  989. return $date_str;
  990. }
  991. } else {
  992. $date = $date > 25568 ? $date + 1 : 25569;
  993. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  994. $ofs = (70 * 365 + 17 + 2) * 86400;
  995. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  996. }
  997. return $date;
  998. }
  999. function _GetFileEXT($filename) {
  1000. $pics = explode ( '.', $filename );
  1001. $num = count ( $pics );
  1002. return $pics [$num - 1];
  1003. }
  1004. /**
  1005. * 获取get或者POST值
  1006. * @param string $name 属性名称
  1007. * @return fixed 值
  1008. */
  1009. function get_args($name) {
  1010. if (isset ( $_GET [$name] )) {
  1011. if (is_array ( $_GET [$name] ))
  1012. return $_GET [$name];
  1013. else {
  1014. return addslashes ( $_GET [$name] );
  1015. // return $_GET [$name] ;
  1016. }
  1017. } elseif (isset ( $_POST [$name] )) {
  1018. if (is_array ( $_POST [$name] ))
  1019. return $_POST [$name];
  1020. else {
  1021. return addslashes ( $_POST [$name] );
  1022. // return $_POST [$name];
  1023. }
  1024. } else {
  1025. return false;
  1026. }
  1027. }
  1028. function get_previous($on_page = 1) {
  1029. return $on_page != 0 ? $on_page - 1 : $on_page;
  1030. }
  1031. /**
  1032. * 获得分页数据
  1033. * @param unknown_type $table
  1034. * @param unknown_type $condition
  1035. * @param unknown_type $on_page
  1036. * @param unknown_type $page_size
  1037. */
  1038. function get_Tpage($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $tagSQL) {
  1039. $page_c = "";
  1040. $page ['previous'] = $this->get_previous ( $on_page );
  1041. $page ['on_page'] = $on_page;
  1042. $total_count = $this->get_table_Tcount ( $table, $condition, $tagSQL );
  1043. $total = intval ( $total_count / $page_size );
  1044. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1045. $page ['total_data'] = $total_count;
  1046. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1047. $i = 1;
  1048. $page_max = 1;
  1049. if ($on_page > 10) {
  1050. $page_max = intval ( $on_page / 10 ) + 1;
  1051. $i = intval ( $on_page / 10 ) * 10 - 1;
  1052. }
  1053. $page ['page'] = $page_c;
  1054. $page ['lower'] = (-- $on_page) * $page_size;
  1055. return $page;
  1056. }
  1057. /**
  1058. * 获得分页数据
  1059. * @param unknown_type $table
  1060. * @param unknown_type $condition
  1061. * @param unknown_type $on_page
  1062. * @param unknown_type $page_size
  1063. */
  1064. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1065. $page_c = "";
  1066. $page ['previous'] = $this->get_previous ( $on_page );
  1067. $page ['on_page'] = $on_page;
  1068. $total_count = $this->get_table_count ( $table, $condition, $staffid, $search, $tooltip, $cateid, $tagSQL );
  1069. $total = intval ( $total_count / $page_size );
  1070. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  1071. $page ['total_data'] = $total_count;
  1072. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  1073. $i = 1;
  1074. $page_max = 1;
  1075. if ($on_page > 10) {
  1076. $page_max = intval ( $on_page / 10 ) + 1;
  1077. $i = intval ( $on_page / 10 ) * 10 - 1;
  1078. }
  1079. for(; $i <= $page ['total_page']; $i ++) {
  1080. if ($i == $on_page) {
  1081. if ($other == "page")
  1082. $page_c .= '<a href="javascript:void(0);" class="current">' . $i . '</a>';
  1083. else
  1084. $page_c .= '&nbsp;<span class="current">' . $i . '</span>&nbsp;';
  1085. } else if ($other == "page")
  1086. $page_c .= '<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>';
  1087. else
  1088. $page_c .= '&nbsp;<a href="' . $action . $i . $get . '" class="paginate">' . $i . '</a>&nbsp;';
  1089. if ($i == (10 * $page_max))
  1090. break;
  1091. }
  1092. $page ['page'] = $page_c;
  1093. $page ['lower'] = (-- $on_page) * $page_size;
  1094. return $page;
  1095. }
  1096. /**
  1097. * 获取总页数
  1098. * @param unknown_type $table
  1099. * @param unknown_type $condition
  1100. */
  1101. public function get_table_Tcount($table = "", $condition = "", $tagSQL) {
  1102. if ($tagSQL)
  1103. $sql = "select count(*) as count from CLD_tagCompanyNexus as a left join CLD_company as b on (a.company=b.cid ) where " . $condition;
  1104. else
  1105. $sql = "select count(*) as count from CLD_company where " . $condition;
  1106. $query = Doo::db ()->query ( $sql );
  1107. $result = $query->fetch ();
  1108. return $result ['count'];
  1109. }
  1110. /**
  1111. * 获取总页数
  1112. * @param unknown_type $table
  1113. * @param unknown_type $condition
  1114. */
  1115. public function get_table_count($table = "", $condition = "", $staffid = "", $search, $tooltip, $cateid, $tagSQL) {
  1116. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  1117. // echo $staffid;die;
  1118. //
  1119. if (! empty ( $staffid )) {
  1120. // $staffid="and a.sid= '".$staffid."'"; " . $table . " as a left join on (a.cid=b.cid ".$staffid.")
  1121. $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;
  1122. } else {
  1123. if (strlen ( $condition ) == 1 || empty ( $condition ))
  1124. $sql = "select count(*) as count from CLD_client as a " . $condition;
  1125. else
  1126. $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;
  1127. }
  1128. if (! empty ( $search ))
  1129. $sql = "select count(*) as count from CLD_client as a where 1 " . $condition;
  1130. if (! empty ( $tooltip )) {
  1131. $condition = str_replace ( "a.", "c.", $condition );
  1132. if ($tagSQL)
  1133. $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;
  1134. else
  1135. $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;
  1136. }
  1137. // echo $sql;
  1138. $query = Doo::db ()->query ( $sql );
  1139. $result = $query->fetch ();
  1140. return $result ['count'];
  1141. }
  1142. public function holidayGroup() {
  1143. Doo::loadModel ( 'staff' );
  1144. Doo::loadModel ( "holidayacman" );
  1145. $acman = new HACMan ();
  1146. $staff = new staff ();
  1147. $data ['staffList'] = $staff->find ( array (
  1148. 'select' => 'username,sid,wxid',
  1149. 'where' => 'cid!=1',
  1150. 'asArray' => true
  1151. ) );
  1152. $acmanlist = $acman->find ( array (
  1153. 'where' => 'type=0',
  1154. 'asArray' => true
  1155. ) );
  1156. $data ['acmanlist'] = $acmanlist;
  1157. $data ['staff'] = $this->staff;
  1158. $data ['memu'] = 'holiday';
  1159. $this->render ( "/admin/admin_holidayGroup", $data );
  1160. }
  1161. public function addHolidayApprover() {
  1162. if (! isset ( $_POST ['title'] ) || empty ( $_POST ['title'] )) {
  1163. exit ( '请输入组名' );
  1164. }
  1165. if (! isset ( $_POST ['staff'] ) || empty ( $_POST ['staff'] )) {
  1166. exit ( '请选择成员' );
  1167. }
  1168. $idname = $name = $pinyinname = array ();
  1169. foreach ( $_POST ['staff'] as $k => $v ) {
  1170. $msg = explode ( ':', $v );
  1171. array_push ( $idname, $msg [0] );
  1172. array_push ( $name, $msg [1] );
  1173. array_push ( $pinyinname, $msg [2] );
  1174. }
  1175. var_dump ( $idname );
  1176. var_dump ( $name );
  1177. var_dump ( $pinyinname );
  1178. exit ();
  1179. Doo::loadModel ( "holidayacman" );
  1180. $acman = new HACMan ();
  1181. $acman->typename = $_POST ['title'];
  1182. var_dump ( $_POST );
  1183. exit ();
  1184. }
  1185. public function holidayCSGroup() {
  1186. $data ['memu'] = 'holiday';
  1187. $this->render ( "/admin/admin_holidayGroup_cc", $data );
  1188. }
  1189. // 检查年假是否过期并更新年假
  1190. private function updateAnnualLeave($staff) {
  1191. Doo::loadModel ( 'holidaystaff' );
  1192. $hstaff = new HStaff ();
  1193. $hstaffmsg = $hstaff->getOne ( array (
  1194. 'where' => 'uid=' . $staff ['sid'],
  1195. 'asArray' => TRUE
  1196. ) );
  1197. $hiredate = $staff ['hiredate'];
  1198. if (intval ( (time () - strtotime ( $hiredate )) / (86400 * 365) ) != $hstaffmsg ['hadyear'] && $staff ['nature'] == 1) {
  1199. $hstaff->uid = $staff ['sid'];
  1200. $hstaff->hadyear = intval ( (time () - strtotime ( $hiredate )) / (86400 * 365) );
  1201. $hstaff->yearnum = intval ( (time () - strtotime ( $hiredate )) / (86400 * 365) ) != 0 ? 5 : 0;
  1202. $hstaff->update ();
  1203. }
  1204. }
  1205. }
  1206. ?>