You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
18 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. /*
  3. * @copyright Leyun internet Technology(Shanghai)Co.,Ltd
  4. * @license http://www.dzzoffice.com/licenses/license.txt
  5. * @package DzzOffice
  6. * @link http://www.dzzoffice.com
  7. * @author zyx(zyx@dzz.cc)
  8. */
  9. if (!defined('IN_DZZ')) {
  10. exit('Access Denied');
  11. }
  12. require_once libfile('function/user', '', 'user');
  13. require_once libfile('function/mail');
  14. require_once libfile('function/organization');
  15. if (!$_G['cache']['usergroups'])
  16. loadcache('usergroups');
  17. $do = trim($_GET['do']);
  18. $uid = intval($_GET['uid']);
  19. if (!$uid)
  20. $do = 'add';
  21. if (empty($do) && $uid)
  22. $do = 'edit';
  23. if ($do == 'add') {
  24. if (submitcheck('accountadd')) {
  25. //处理用户部门和职位
  26. $orgids = array();
  27. foreach ($_GET['orgids'] as $key => $orgid) {
  28. if (!$orgid)
  29. continue;
  30. if (C::t('organization_admin')->ismoderator_by_uid_orgid($orgid, $_G['uid'], 1)) {
  31. $orgids[$orgid] = intval($_GET['jobids'][$key]);
  32. }
  33. }
  34. if (!$orgids && $_G['adminid'] != 1)
  35. showmessage('no_parallelism_jurisdiction');
  36. //用户名验证
  37. $username = trim($_GET['username']);
  38. if ($username) {
  39. $usernamelen = dstrlen($_GET['username']);
  40. if ($usernamelen < 3) {
  41. showmessage('profile_username_tooshort');
  42. } elseif ($usernamelen > 30) {
  43. showmessage('profile_username_toolong');
  44. }
  45. if ($_G['setting']['censoruser'] && @preg_match($censorexp, $username)) {
  46. showmessage('profile_username_protect');
  47. }
  48. //如果输入用户名,检查用户名不能重复
  49. if (C::t('user')->fetch_by_username($username)) {
  50. showmessage('user_registered_retry');
  51. }
  52. }
  53. $user_extra = array();
  54. //如果输入手机号码,检查手机号码不能重复
  55. $phone = trim($_GET['phone']);
  56. if ($phone) {
  57. if (!preg_match("/^\d+$/", $phone)) {
  58. showmessage('user_phone_illegal');
  59. }
  60. if (C::t('user')->fetch_by_phone($phone)) {
  61. showmessage('user_phone_registered');
  62. }
  63. $user_extra['phone'] = $phone;
  64. }
  65. //如果输入微信号,检查微信号不能重复
  66. $weixinid = trim($_GET['weixinid']);
  67. if ($weixinid) {
  68. if (!preg_match("/^[a-zA-Z\d_]{5,}$/i", $weixinid)) {
  69. showmessage(lang('weixin_illegal'));
  70. }
  71. if (C::t('user')->fetch_by_weixinid($weixinid)) {
  72. showmessage('weixin_registered');
  73. }
  74. $user_extra['weixinid'] = $weixinid;
  75. }
  76. //邮箱验证部分
  77. $email = strtolower(trim($_GET['email']));
  78. checkemail($_GET['email']);
  79. //密码验证部分
  80. if ($_G['setting']['pwlength']) {
  81. if (strlen($_GET['password']) < $_G['setting']['pwlength']) {
  82. showmessage('profile_password_tooshort', '', array('pwlength' => $_G['setting']['pwlength']));
  83. }
  84. }
  85. if (!$_GET['password'] || $_GET['password'] != addslashes($_GET['password'])) {
  86. showmessage('profile_passwd_illegal');
  87. }
  88. $password = $_GET['password'];
  89. $result = uc_user_register(addslashes($username), $password, $email, $nickname, $questionid, $answer, $_G['clientip'], 0);
  90. if (is_array($result)) {
  91. $uid = $result['uid'];
  92. $password = $result['password'];
  93. } else {
  94. $uid = $result;
  95. }
  96. if ($uid <= 0) {
  97. if ($uid == -1) {
  98. showmessage('profile_username_illegal');
  99. } elseif ($uid == -2) {
  100. showmessage('profile_username_protect');
  101. } elseif ($uid == -3) {
  102. showmessage('profile_username_duplicate');
  103. } elseif ($uid == -4) {
  104. showmessage('profile_email_illegal');
  105. } elseif ($uid == -5) {
  106. showmessage('profile_email_domain_illegal');
  107. } elseif ($uid == -6) {
  108. showmessage('profile_email_duplicate');
  109. } elseif ($uid == -7) {
  110. showmessage('profile_username_illegal');
  111. } else {
  112. showmessage('undefined_action');
  113. }
  114. }
  115. //插入用户状态表
  116. $status = array('uid' => $uid, 'regip' => '', 'lastip' => '', 'lastvisit' => TIMESTAMP, 'lastactivity' => TIMESTAMP, 'lastsendmail' => 0);
  117. C::t('user_status')->insert($status, false, true);
  118. //处理管理员
  119. C::t('user')->setAdministror($uid, intval($_GET['groupid']));
  120. //加入额外信息
  121. if ($user_extra)
  122. C::t('user')->update($uid, $user_extra);
  123. //处理额外空间
  124. $addsize = intval($_GET['addsize']);
  125. if (C::t('user_field')->fetch($uid)) {
  126. C::t('user_field')->update($uid, array('addsize' => $addsize, 'perm' => 0));
  127. } else {
  128. C::t('user_field')->insert(array('uid' => $uid, 'addsize' => $addsize, 'perm' => 0, 'iconview' => $_G['setting']['desktop_default']['iconview'] ? $_G['setting']['desktop_default']['iconview'] : 2, 'taskbar' => $_G['setting']['desktop_default']['taskbar'] ? $_G['setting']['desktop_default']['taskbar'] : 'bottom', 'iconposition' => intval($_G['setting']['desktop_default']['iconposition']), 'direction' => intval($_G['setting']['desktop_default']['direction']),));
  129. }
  130. if ($orgids)
  131. C::t('organization_user')->replace_orgid_by_uid($uid, $orgids);
  132. //处理上司职位;
  133. C::t('organization_upjob')->insert_by_uid($uid, intval($_GET['upjobid']));
  134. Hook::listen('syntoline_user', $uid, 'add');//注册绑定到钉钉部门表
  135. if ($_GET['sendmail']) {
  136. $email_password_message = lang('email_password_message', array('sitename' => $_G['setting']['sitename'], 'siteurl' => $_G['siteurl'], 'email' => $_GET['email'], 'password' => $_GET['password']));
  137. if (!sendmail_cron("$_GET[email] <$_GET[email]>", lang('email_password_subject'), $email_password_message)) {
  138. runlog('sendmail', "$_GET[email] sendmail failed.");
  139. }
  140. }
  141. showmessage('add_user_success', MOD_URL . '#user_' . $uid, array('uid' => $uid, 'orgids' => $orgids));
  142. } else {
  143. $orgid = intval($_GET['orgid']);
  144. if (!C::t('organization_admin')->ismoderator_by_uid_orgid($orgid, $_G['uid'])) {
  145. exit(lang('orguser_edituser_add_user'));
  146. }
  147. if ($org = C::t('organization')->fetch($orgid)) {
  148. $org['jobs'] = C::t('organization_job')->fetch_all_by_orgid($org['orgid']);
  149. $orgpath = getPathByOrgid($org['orgid']);
  150. $org['depart'] = implode('-', ($orgpath));
  151. }
  152. include template('adduser');
  153. exit();
  154. }
  155. } elseif ($do == 'edit') {
  156. if (submitcheck('accountedit')) {
  157. //判断是否对此用户有管理权限
  158. $uperm = false;
  159. if ($_G['adminid'] != 1) {
  160. if ($orgids_uid = C::t('organization_user')->fetch_orgids_by_uid($uid)) {
  161. foreach ($orgids_uid as $orgid) {
  162. if (C::t('organization_admin')->ismoderator_by_uid_orgid($orgid, $_G['uid'])) {
  163. $uperm = true;
  164. break;
  165. }
  166. }
  167. if (!$uperm)
  168. showmessage('privilege');
  169. } else {
  170. showmessage('privilege');
  171. }
  172. }
  173. $orgids = array();
  174. foreach ($_GET['orgids'] as $key => $orgid) {
  175. if ($orgid) $orgids[$orgid] = intval($_GET['jobids'][$key]);
  176. }
  177. $user = C::t('user')->fetch_by_uid($uid);
  178. if ($user['groupid'] < $_G['groupid'] || (C::t('user')->checkfounder($user) && !C::t('user')->checkfounder($_G['member']))) {
  179. //处理用户部门和职位
  180. if($orgids) {
  181. C::t('organization_user')->replace_orgid_by_uid($uid, $orgids);
  182. } else {
  183. C::t('organization_user')->delete_by_uid($uid);
  184. }
  185. //处理上司职位;
  186. C::t('organization_upjob')->insert_by_uid($uid, intval($_GET['upjobid']));
  187. showmessage('edit_user_success', MOD_URL . '#user_' . $uid);
  188. }
  189. //禁用创始人验证
  190. $status = intval($_GET['status']) ? 1 : 0;
  191. if ($status == 1 && C::t('user')->checkfounder($user)) {
  192. showmessage('创始人账号不能禁用');
  193. }
  194. //用户名验证
  195. $username = trim($_GET['username']);
  196. $usernamelen = dstrlen($_GET['username']);
  197. if ($usernamelen < 3) {
  198. showmessage('profile_username_tooshort');
  199. } elseif ($usernamelen > 30) {
  200. showmessage('profile_username_toolong');
  201. } elseif (!check_username(addslashes(trim(stripslashes($username))))) {
  202. showmessage('profile_username_illegal');
  203. }
  204. //如果输入用户名,检查用户名不能重复
  205. if ($username != $user['username']) {
  206. if (C::t('user')->fetch_by_username($username)) {
  207. showmessage('user_registered_retry');
  208. }
  209. if ($_G['setting']['censoruser'] && @preg_match($censorexp, $username)) {
  210. showmessage('profile_username_protect');
  211. }
  212. }
  213. //如果输入手机号码,检查手机号码不能重复
  214. $phone = trim($_GET['phone']);
  215. if ($phone) {
  216. if (!preg_match("/^\d+$/", $phone)) {
  217. showmessage('user_phone_illegal');
  218. }
  219. if ($phone != $user['phone'] && C::t('user')->fetch_by_phone($phone)) {
  220. showmessage('user_phone_registered');
  221. }
  222. }
  223. //如果输入微信号,检查微信号不能重复
  224. $weixinid = trim($_GET['weixinid']);
  225. if ($weixinid) {
  226. if (!preg_match("/^[a-zA-Z\d_]{5,}$/i", $weixinid)) {
  227. showmessage(lang('weixin_illegal'));
  228. }
  229. if ($weixinid != $user['weixinid'] && C::t('user')->fetch_by_weixinid($weixinid)) {
  230. showmessage('weixin_registered');
  231. }
  232. }
  233. //邮箱验证部分
  234. $email = strtolower(trim($_GET['email']));
  235. if (!isemail($email)) {
  236. showmessage('profile_email_illegal');
  237. } elseif (!check_emailaccess($email)) {
  238. showmessage('profile_email_domain_illegal');
  239. }
  240. if ($email != strtolower($user['email'])) {
  241. //邮箱不能重复
  242. if (C::t('user')->fetch_by_email($email)) {
  243. showmessage('email_registered_retry');
  244. }
  245. }
  246. //密码验证部分
  247. if ($_GET['password']) {
  248. if ($_G['setting']['pwlength']) {
  249. if (strlen($_GET['password']) < $_G['setting']['pwlength']) {
  250. showmessage('profile_password_tooshort', '', array('pwlength' => $_G['setting']['pwlength']));
  251. }
  252. }
  253. if ($_GET['password'] !== $_GET['password2']) {
  254. showmessage('profile_passwd_notmatch');
  255. }
  256. // 添加密码的合法性校验
  257. if ($_GET['password'] != addslashes($_GET['password'])) {
  258. showmessage('profile_passwd_illegal');
  259. }
  260. }
  261. $password = $_GET['password'];
  262. if ($password) {
  263. $salt = substr(uniqid(rand()), -6);
  264. $setarr = array('salt' => $salt, 'password' => md5(md5($password) . $salt), 'username' => $username, 'phone' => $phone, 'weixinid' => $weixinid, 'secques' => '', 'email' => $email, 'status' => intval($_GET['status']));
  265. } else {
  266. $setarr = array('username' => $username, 'email' => $email, 'phone' => $phone, 'weixinid' => $weixinid, 'status' => intval($_GET['status']));
  267. }
  268. C::t('user')->update($uid, $setarr);
  269. //处理管理员
  270. C::t('user')->setAdministror($uid, intval($_GET['groupid']));
  271. //处理额外空间和用户空间
  272. //$addsize = intval($_GET['addsize']);
  273. $userspace = intval($_GET['userspace']);
  274. if (C::t('user_field')->fetch($uid)) {
  275. C::t('user_field')->update($uid, array('userspace' => $userspace, 'perm' => 0));
  276. } else {
  277. C::t('user_field')->insert(array('uid' => $uid, 'userspace' => $userspace, 'perm' => 0, 'iconview' => $_G['setting']['desktop_default']['iconview'] ? $_G['setting']['desktop_default']['iconview'] : 2, 'taskbar' => $_G['setting']['desktop_default']['taskbar'] ? $_G['setting']['desktop_default']['taskbar'] : 'bottom', 'iconposition' => intval($_G['setting']['desktop_default']['iconposition']), 'direction' => intval($_G['setting']['desktop_default']['direction']),));
  278. }
  279. //处理用户部门和职位
  280. if ($orgids) {
  281. C::t('organization_user')->replace_orgid_by_uid($uid, $orgids);
  282. } else {
  283. C::t('organization_user')->delete_by_uid($uid);
  284. }
  285. //处理上司职位;
  286. C::t('organization_upjob')->insert_by_uid($uid, intval($_GET['upjobid']));
  287. Hook::listen('syntoline_user', $uid, 'edit');//注册绑定到钉钉部门表
  288. showmessage('edit_user_success', MOD_URL . '#user_' . $uid);
  289. } else {
  290. require_once libfile('function/organization');
  291. $user = C::t('user')->fetch_by_uid($uid);
  292. $userfield = C::t('user_field')->fetch($uid);
  293. //$user['status']=$user['status']>0?0:1;
  294. $departs = array();
  295. $data_depart = array();
  296. //$departs=getDepartmentByUid($uid);
  297. $orgids = C::t('organization_user')->fetch_orgids_by_uid($uid);
  298. //判断是否对此用户有管理权限
  299. $uperm = false;
  300. if ($_G['adminid'] != 1) {
  301. foreach ($orgids as $orgid) {
  302. if (C::t('organization_admin')->ismoderator_by_uid_orgid($orgid, $_G['uid'])) {
  303. $uperm = true;
  304. break;
  305. }
  306. }
  307. if (!$uperm) exit(lang('orguser_edituser_add_user1'));
  308. }
  309. //获取系统可分配空间大小
  310. $allowallotspace = C::t('organization')->get_system_allowallot_space();
  311. //如果该用户之前有分配空间,当前用户可分配空间=系统可分配空间+该用户之前分配空间(若无,则加上当前用户已使用空间)
  312. if ($userfield['userspace'] > 0) {
  313. $currentuserAllotspace = $allowallotspace + $userfield['userspace'] * 1024 * 1024;
  314. } else {
  315. $currentuserAllotspace = $allowallotspace + $userfield['usesize'];
  316. }
  317. $departs = C::t('organization')->fetch_all($orgids);
  318. foreach ($departs as $key => $value) {
  319. $orgpath = getPathByOrgid($value['orgid']);
  320. $value['depart'] = implode('-', ($orgpath));
  321. $value['ismoderator'] = C::t('organization_admin')->ismoderator_by_uid_orgid($value['orgid'], $_G['uid']);
  322. $value['jobs'] = C::t('organization_job')->fetch_all_by_orgid($value['orgid']);
  323. $value['user'] = C::t('organization_user')->fetch_by_uid_orgid($uid, $value['orgid']);
  324. $value['jobid'] = $value['user']['jobid'];
  325. $value['jobname'] = $value['jobs'][$value['jobid']] ? $value['jobs'][$value['jobid']]['name'] : lang('none');
  326. $data_depart[$key] = $value;
  327. }
  328. //$orgtree_admin=getDepartmentOption_admin(0);
  329. if ($upjob = C::t('organization_upjob')->fetch_by_uid($uid)) {
  330. $upjob['jobs'] = C::t('organization_job')->fetch_all_by_orgid($upjob['orgid']);
  331. } else {
  332. $upjob = array('jobid' => 0, 'depart' => lang('please_select_a_organization_or_department'), 'name' => lang('none'));
  333. }
  334. //$orgtree_all=getDepartmentOption_admin(0,'',true);
  335. $perm = 1;
  336. if ($user['groupid'] < $_G['groupid'] || (C::t('user')->checkfounder($user) && !C::t('user')->checkfounder($_G['member']))) {
  337. $perm = 0;
  338. }
  339. include template('edituser');
  340. exit();
  341. }
  342. } elseif ($do == 'profile') {
  343. //判断是否对此用户有管理权限
  344. $uperm = false;
  345. if ($_G['adminid'] != 1) {
  346. if ($orgids = C::t('organization_user')->fetch_orgids_by_uid($uid)) {
  347. foreach ($orgids as $orgid) {
  348. if (C::t('organization_admin')->ismoderator_by_uid_orgid($orgid, $_G['uid'])) {
  349. $uperm = true;
  350. break;
  351. }
  352. }
  353. }
  354. if (!$uperm)
  355. exit(lang('orguser_edituser_add_user1'));
  356. }
  357. include_once libfile('function/profile', '', 'user');
  358. $space = getuserbyuid($uid);
  359. space_merge($space, 'profile');
  360. loadcache('profilesetting');
  361. if (empty($_G['cache']['profilesetting'])) {
  362. loadcache('profilesetting');
  363. }
  364. if (submitcheck('profilesubmit')) {
  365. $setarr = array();
  366. foreach ($_GET as $key => $value) {
  367. $field = $_G['cache']['profilesetting'][$key];
  368. if (empty($field)) {
  369. continue;
  370. } elseif (profile_check($key, $value, $space)) {
  371. $setarr[$key] = dhtmlspecialchars(trim($value));
  372. }
  373. }
  374. if (isset($_POST['birthmonth']) && ($space['birthmonth'] != $_POST['birthmonth'] || $space['birthday'] != $_POST['birthday'])) {
  375. $setarr['constellation'] = get_constellation($_POST['birthmonth'], $_POST['birthday']);
  376. }
  377. if (isset($_POST['birthyear']) && $space['birthyear'] != $_POST['birthyear']) {
  378. $setarr['zodiac'] = get_zodiac($_POST['birthyear']);
  379. }
  380. if ($setarr) {
  381. $setarr['uid'] = $uid;
  382. C::t('user_profile')->insert($setarr);
  383. }
  384. showmessage('subscriber_data_alter_success', MOD_URL . '#user_' . $uid . '_profile');
  385. } else {
  386. $allowitems = array();
  387. foreach ($_G['cache']['profilesetting'] as $key => $value) {
  388. if ($value['available'] > 0)
  389. $allowitems[] = $key;
  390. }
  391. $htmls = $settings = array();
  392. foreach ($allowitems as $fieldid) {
  393. if (!in_array($fieldid, array('department', 'timeoffset'))) {
  394. $html = profile_setting($fieldid, $space, false, true);
  395. if ($html) {
  396. $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
  397. $htmls[$fieldid] = $html;
  398. }
  399. }
  400. }
  401. $active = array('profile' => 'class="active"');
  402. include template('profile');
  403. }
  404. }
  405. exit();
  406. ?>