AdminController.php 48 KB

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