AdminController.php 48 KB

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