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