$page = empty($_GET['page']) ? 1 : intval($_GET['page']); $perpage = 20; $gets = array('mod' => 'member', 'keyword' => $keyword, 'orgid' => $orgid, 'groupid' => $groupid); $theurl = BASESCRIPT . "?" . url_implode($gets); $order = 'ORDER BY uid DESC'; $start = ($page - 1) * $perpage; $sql = '1'; $param[] = array('user'); if ($keyword) { if ($count = DB::result_first("SELECT COUNT(*) FROM " . DB::table('user') . " WHERE username like '%{$keyword}%' or email like '%{$keyword}%'")) { $user = DB::fetch_all("SELECT * FROM " . DB::table('user') . " WHERE username like '%{$keyword}%' or email like '%{$keyword}%' {$order} limit {$start},{$perpage}"); $multi = multi($count, $perpage, $page, $theurl, 'pull-right'); } } else { if ($orgid) { $orgids = getOrgidTree($orgid); $uids = C::t('organization_user')->fetch_uids_by_orgid($orgids); if ($count = DB::result_first("SELECT COUNT(*) FROM " . DB::table('user') . " WHERE uid IN (" . dimplode($uids) . ")")) { $user = DB::fetch_all("SELECT * FROM " . DB::table('user') . " WHERE uid IN (" . dimplode($uids) . ") {$order} limit {$start},{$perpage}"); $multi = multi($count, $perpage, $page, $theurl, 'pull-right'); } } else { if ($count = DB::result_first("SELECT COUNT(*) FROM " . DB::table('user') . " WHERE 1 ")) { $user = DB::fetch_all("SELECT * FROM " . DB::table('user') . " WHERE 1 {$order} limit {$start},{$perpage}"); $multi = multi($count, $perpage, $page, $theurl, 'pull-right'); } } } $list = array(); foreach ($user as $value) { $value['department'] = getDepartmentByUid($value['uid']);
} $openarr = json_encode(array('orgid' => $open)); include template('export'); exit; } else { if (!is_array($_GET['item'])) { showmessage("请选择导出项目", dreferer()); } foreach ($h0 as $key => $value) { if (!in_array($key, $_GET['item'])) { unset($h0[$key]); } } $title = ''; if ($org = C::t('organization')->fetch($orgid)) { $orgids = getOrgidTree($org['orgid']); if ($org['forgid'] > 0) { $toporgid = C::t('organization')->getTopOrgid($orgid); $toporg = C::t('organization')->fetch($toporgid); $title = $_G['setting']['sitename'] . '-' . $toporg['orgname'] . '-' . $org['orgname']; } else { $title = $_G['setting']['sitename'] . '-' . $org['orgname']; } } else { $title = $_G['setting']['sitename']; } $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator($_G['username'])->setTitle($title . ' - 人员信息表 - DzzOffice')->setSubject($title . ' - 人员信息表')->setDescription($title . ' - 人员信息表 Export By DzzOffice ' . date('Y-m-d H:i:s'))->setKeywords($title . ' - 人员信息表')->setCategory("人员信息表"); $list = array(); // Create a first sheet $objPHPExcel->setActiveSheetIndex(0);
foreach (DB::fetch_all("select orgname,orgid,forgid from %t {$sql_org} limit 10", $param_org) as $org) { $porgids = array_reverse(getUpOrgidTree($org['orgid'])); $titles = array(); foreach ($porgids as $porgid) { if ($porg = C::t('organization')->fetch($porgid)) { $titles[] = $porg['orgname']; } } $data[] = array('name' => $org['orgname'], 'title' => implode('-', $titles), 'searchkey' => $py->getAllPY($org['orgname']) . $org['orgname'], 'id' => 'g' . $org['orgid'], 'icon' => $org['forgid'] ? 'dzz/system/images/department.png' : 'dzz/system/images/organization.png'); } } break; case 2: //本机构 foreach (C::t('organization_user')->fetch_orgids_by_uid($_G['uid']) as $orgid) { $orgids = array_merge($orgids, getOrgidTree($orgid)); $orgids = array_merge($orgids, getUpOrgidTree($orgid)); } if ($orgids) { $sql_org .= " and orgid IN(%n)"; $param_org[] = $orgids; foreach (DB::fetch_all("select orgname,orgid,forgid from %t {$sql_org} limit 10", $param_org) as $org) { $porgids = array_reverse(getUpOrgidTree($org['orgid'])); $titles = array(); foreach ($porgids as $porgid) { if ($porg = C::t('organization')->fetch($porgid)) { $titles[] = $porg['orgname']; } } $data[] = array('name' => $org['orgname'], 'title' => implode('-', $titles), 'searchkey' => $py->getAllPY($org['orgname']) . $org['orgname'], 'id' => 'g' . $org['orgid'], 'icon' => $org['forgid'] ? 'dzz/system/images/department.png' : 'dzz/system/images/organization.png'); }
function wx_updateUser($uids) { @set_time_limit(0); if (!getglobal('setting/CorpID') || !getglobal('setting/CorpSecret')) { return; } $uids = (array) $uids; $wx = new qyWechat(array('appid' => getglobal('setting/CorpID'), 'appsecret' => getglobal('setting/CorpSecret'), 'agentid' => 0)); $ret = 0; $syngids = array(); if ($syngid = getglobal('setting/synorgid')) { //设置的需要同步的部门 $syngids = getOrgidTree($syngid); } foreach ($uids as $uid) { if (!($user = C::t('user')->fetch($uid))) { continue; } $worgids = array(); if ($orgids = C::t('organization_user')->fetch_orgids_by_uid($uid)) { if ($syngids) { $orgids = array_intersect($orgids, $syngids); } if ($orgids) { foreach (C::t('organization')->fetch_all($orgids) as $value) { if ($value['worgid']) { $worgids[] = $value['worgid']; } else { if ($worgid = C::t('organization')->wx_update($value['orgid'])) { $worgids[] = $worgid; } } } } } if (!$worgids) { //用户不在机构和部门中,微信中应该禁用此用户 $data = array("userid" => "dzz-" . $user['uid'], "enable" => 0, "department" => 1); if ($wx->updateUser($data)) { $ret += 1; } else { $message = 'deleteUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg; runlog('wxlog', $message); } } else { $profile = C::t('user_profile1')->fetch_all($user['uid']); if ($wxuser = $wx->getUserInfo('dzz-' . $user['uid'])) { //更新用户信息 $data = array("userid" => "dzz-" . $user['uid'], "name" => $user['username'], "enable" => 1, "email" => $user['email'], "enable" => $user['status'] ? 0 : 1); if (array_diff($wxuser['department'], $worgids)) { $data['department'] = $worgids; } if ($user['phone'] && $user['phone'] != $wxuser['mobile']) { $data['mobile'] = $user['phone']; } if ($user['weixinid'] && $wxuser['wechat_status'] == 4) { $data['weixinid'] = $user['weixinid']; } if ($profile['telephone'] && $profile['telephone'] != $wxuser['tel']) { $data['tel'] = $profile['telephone']; } if ($profile['gender'] && $profile['gender'] - 1 != $wxuser['gender']) { $data['gender'] = $profile['gender'] - 1; } if ($wx->updateUser($data)) { $ret += 1; } else { $message = 'updateUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg; runlog('wxlog', $message); } $setarr = array('wechat_status' => $wxuser['status']); $setarr['weixinid'] = empty($wxuser['weixinid']) ? $user['weixinid'] : $wxuser['weixinid']; $setarr['phone'] = empty($user['phone']) ? $wxuser['phone'] : $user['phone']; $setarr['wechat_userid'] = 'dzz-' . $user['uid']; C::t('user')->update($user['uid'], $setarr); } else { //创建用户信息 $data = array("userid" => "dzz-" . $user['uid'], "name" => $user['username'], "department" => $worgids, "email" => $user['email'], "weixinid" => $user['wechat'], "enable" => $user['status'] ? 0 : 1); if ($user['phone']) { $data['mobile'] = $user['phone']; } if ($profile['telephone']) { $data['tel'] = $profile['telephone']; } if ($profile['gender']) { $data['gender'] = $profile['gender'] - 1; } if ($wx->createUser($data)) { C::t('user')->update($user['uid'], array('wechat_userid' => 'dzz-' . $user['uid'])); $ret += 1; } else { $message = 'createUser:errCode:' . $wx->errCode . ';errMsg:' . $wx->errMsg; runlog('wxlog', $message); } } } } return $ret; }
function getOrgidByUid($uid, $sub = true) { //获取用户所在部门ID和所有下级部门ID $ret = array(); $orgids = C::t('organization_user')->fetch_orgids_by_uid($uid); if ($sub) { foreach ($orgids as $orgid) { $ret = array_merge($ret, getOrgidTree($orgid)); } } else { $ret = $orgids; } return array_unique($ret); }
exit(json_encode(array('msg' => 'continue', 'start' => $org['orgid'], 'message' => $org['orgname'] . ' <span class="success">更新成功</span>'))); } } } exit(json_encode(array('msg' => 'continue', 'start' => $org['orgid'], 'message' => $org['orgname'] . ' <span class="danger">' . $wx->errCode . ':' . $wx->errMsg . '</span>'))); } } } else { exit(json_encode(array('msg' => 'success'))); } } elseif ($do == 'qiwechat_syn_user') { $i = intval($_GET['i']); $syngids = array(); if ($syngid = getglobal('setting/synorgid')) { //设置的需要同步的部门 $syngids = getOrgidTree($syngid); } $wx = new qyWechat(array('appid' => $_G['setting']['CorpID'], 'appsecret' => $_G['setting']['CorpSecret'], 'agentid' => 0)); if ($user = DB::fetch_first("select u.*,o.orgid from " . DB::table('user') . " u LEFT JOIN " . DB::table('organization_user') . " o ON o.uid=u.uid where u.uid>{$i} and o.orgid>0 order by uid")) { $worgids = array(); if ($orgids = C::t('organization_user')->fetch_orgids_by_uid($user['uid'])) { if ($syngids) { $orgids = array_intersect($orgids, $syngids); } if ($orgids) { foreach (C::t('organization')->fetch_all($orgids) as $value) { if ($value['worgid']) { $worgids[] = $value['worgid']; } else { if ($worgid = C::t('organization')->wx_update($value['orgid'])) { $worgids[] = $worgid;
$uids = C::t('organization_user')->fetch_uids_by_orgid($value['gid']); $ismoderator = C::t('organization_admin')->ismoderator_by_uid_orgid($value['gid'], $_G['uid']); if (!in_array($_G['uid'], $uids) && !$ismoderator && $_G['adminid'] != 1) { continue; } $orglist[$value['gid']] = $value; continue; } $folderids[] = $value['fid']; $data[] = array('attr' => array('id' => 'f-' . $value['fid'] . '-' . $winid, 'rel' => $value['flag']), 'data' => $value['fname'], 'state' => 'closed'); } if ($orglist) { include_once libfile('function/organization'); $list = array(); foreach ($orglist as $orgid) { foreach ($orgids = getOrgidTree($orgid) as $gid) { if (isset($orglist[$gid])) { $list[] = $orglist[$gid]; unset($orglist[$gid]); } } } if ($orglist) { $list = array_merge($orglist, $list); } foreach ($list as $value) { $folderids[] = $value['fid']; $data[] = array('attr' => array('id' => 'f-' . $value['fid'] . '-' . $winid, 'rel' => 'department'), 'data' => $value['fname'], 'state' => 'closed'); } } if ($folderids) {
public function fetch_orgids_by_uid($uid, $getsub = 0) { $orgids = array(); $arr = DB::fetch_all("select orgid from %t where uid = %d ", array($this->_table, $uid)); foreach ($arr as $value) { if ($getsub > 0) { $subs = getOrgidTree($value['orgid']); $orgids = array_merge($orgids, $subs); } else { $orgids[] = $value['orgid']; } } return array_unique($orgids); }