//Array ( [2013] => Array ( [collegeid] => [school] => [academy] => [class] => [startyear] => 2013 ) )
 exit();
 */
 foreach ($EduArray as $key => $value) {
     if (empty($value['collegeid'])) {
         //教育信息
         if (!empty($value['startyear'])) {
             $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'], 'startyear' => $value['startyear']);
             inserttable('spaceinfo', $eduinfo, 1);
             //应该要加一个段记录该学生为本科还是研究生********************(缺)
             //还要考虑没有生日信息但有身份证号存在的情况................(缺)
             //加入群组:1,同年级;2,区域.
             $tagname = $value['startyear'] . '级本科生';
             joinGrade($newuid, $tagname, $_SGLOBAL['db']);
             $tagname = $value['startyear'] . '级' . $value['sourcearea'] . '本科生';
             joinArea($newuid, $tagname, $_SGLOBAL['db']);
         }
     } elseif (!empty($value['collegeid'])) {
         $thefour = intval(substr($value['collegeid'], 3, 1));
         if ($thefour == 2 || $value['class']) {
             $newclass = substr($value['collegeid'], 0, 7);
             $class = !empty($value['class']) ? $value['class'] : $newclass;
             $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'] . $value['startyear'] . '级' . $class . '班', 'startyear' => $value['startyear']);
             inserttable('spaceinfo', $eduinfo, 1);
             $tagname = $value['startyear'] . '年' . $class . '班';
             auto_join($newuid, $tagname, $_SGLOBAL['db']);
             $classB = preg_replace('/([a-zA-Z]*\\d{4})\\d*/', '${1}', $class);
             $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'] . $value['startyear'] . '级' . $classB . '大班', 'startyear' => $value['startyear']);
             inserttable('spaceinfo', $eduinfo, 1);
             $tagname = $value['startyear'] . '年' . $classB . '大班';
             $tagid = auto_join($newuid, $tagname, $_SGLOBAL['db']);
Example #2
0
function freshmanregister_interface($realname, $birthday, $email)
{
    global $_SCONFIG, $_SGLOBAL;
    $res_json = array();
    $email = isemail($email) ? $email : '';
    if (empty($realname)) {
        $res_json = array("status" => "error", "reason" => "Realname is empty!");
    }
    if (empty($birthday)) {
        $res_json = array("status" => "error", "reason" => "Birthday is empty!");
    }
    if (empty($email)) {
        $res_json = array("status" => "error", "reason" => "Email is empty or format error!");
    }
    if ($_SCONFIG['checkemail']) {
        if ($count = getcount('spacefield', array('email' => $email))) {
            $res_json = array("status" => "error", "reason" => "Email has been registered!");
        }
    }
    $ThisYear = date('Y');
    //获取当前年
    $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('baseprofile') . " WHERE realname='{$realname}' and birthday='{$birthday}' and startyear={$ThisYear} limit 1");
    $bp = $_SGLOBAL['db']->fetch_array($query);
    if (empty($bp)) {
        $res_json = array("status" => "error", "reason" => "Realname with birthday is invalid!");
    }
    if ($bp['isactive'] == 1) {
        $res_json = array("status" => "error", "reason" => "The user have actived!");
    }
    if ($bp['startyear'] < $ThisYear) {
        $res_json = array("status" => "error", "reason" => "This user is frashman!");
    }
    if (!@(include_once S_ROOT . './uc_client/client.php')) {
        $res_json = array("status" => "error", "reason" => "System error!");
    }
    $num = strpos($email, '@');
    $num = $num > 15 ? 15 : $num;
    $username = substr($email, 0, $num);
    $password = $birthday;
    $newuid = uc_user_register($username, $password, $email);
    if ($newuid <= 0) {
        if ($newuid == -1) {
            $res_json = array("status" => "error", "Username is not legitimate!");
        } elseif ($newuid == -2) {
            $res_json = array("status" => "error", "Include not registered words!");
        } elseif ($newuid == -3) {
            $res_json = array("status" => "error", "Please change an email address!");
        } elseif ($newuid == -4) {
            $res_json = array("status" => "error", "Email format is wrong");
        } elseif ($newuid == -5) {
            $res_json = array("status" => "error", "Email not registered");
        } else {
            $res_json = array("status" => "error", "Register error");
        }
    } else {
        //检查uid是否在ucenter里面,如果不在,就采取野蛮方式插入新纪录
        $q = $_SGLOBAL['db']->query("SELECT uid FROM ihomeuser_members WHERE uid='{$newuid}'");
        $members_match = $_SGLOBAL['db']->fetch_array($q);
        $members_match = $members_match['uid'];
        $q = $_SGLOBAL['db']->query("SELECT uid FROM ihomeuser_memberfields WHERE uid='{$newuid}'");
        $memberfields_match = $_SGLOBAL['db']->fetch_array($q);
        $memberfields_match = $memberfields_match['uid'];
        if (!$members_match && !$memberfields_match) {
            $salt = substr(uniqid(rand()), -6);
            $hhpassword = md5(md5($password) . $salt);
            $sqladd = "uid='" . intval($newuid) . "',";
            $sqladd .= " secques='',";
            $_SGLOBAL['db']->query("INSERT INTO ihomeuser_members SET {$sqladd} username='******', password='******', email='{$email}', regip='" . $_SERVER["HTTP_X_FORWARDED_FOR"] . "', regdate='" . time() . "', salt='{$salt}'");
            $_SGLOBAL['db']->query("INSERT INTO ihomeuser_memberfields SET uid='{$newuid}'");
        }
        $setarr = array('uid' => $newuid, 'username' => $username, 'password' => md5($password));
        inserttable('actionlog', array('uid' => "{$newuid}", 'dateline' => "{$_SGLOBAL['timestamp']}", 'action' => 'register', 'value' => 'freshman'));
        //更新本地用户库
        inserttable('member', $setarr, 0, true);
        //开通空间
        include_once S_ROOT . './source/function_space.php';
        $space = space_open($newuid, $username, 0, $email);
        //默认好友
        $flog = $inserts = $fuids = $pokes = array();
        if (!empty($_SCONFIG['defaultfusername'])) {
            $query = $_SGLOBAL['db']->query("SELECT uid,username FROM " . tname('space') . " WHERE\tusername IN (" . simplode(explode(',', $_SCONFIG['defaultfusername'])) . ")");
            while ($value = $_SGLOBAL['db']->fetch_array($query)) {
                $value = saddslashes($value);
                $fuids[] = $value['uid'];
                $inserts[] = "('{$newuid}','{$value['uid']}','{$value['username']}','1','{$_SGLOBAL['timestamp']}')";
                $inserts[] = "('{$value['uid']}','{$newuid}','{$username}','1','{$_SGLOBAL['timestamp']}')";
                $pokes[] = "('{$newuid}','{$value['uid']}','{$value['username']}','" . addslashes($_SCONFIG['defaultpoke']) . "','{$_SGLOBAL['timestamp']}')";
                //添加好友变更记录
                $flog[] = "('{$value['uid']}','{$newuid}','add','{$_SGLOBAL['timestamp']}')";
            }
            if ($inserts) {
                $_SGLOBAL['db']->query("REPLACE INTO " . tname('friend') . " (uid,fuid,fusername,status,dateline) VALUES " . implode(',', $inserts));
                $_SGLOBAL['db']->query("REPLACE INTO " . tname('poke') . " (uid,fromuid,fromusername,note,dateline) VALUES " . implode(',', $pokes));
                $_SGLOBAL['db']->query("REPLACE INTO " . tname('friendlog') . " (uid,fuid,action,dateline) VALUES " . implode(',', $flog));
                //添加到附加表
                $friendstr = empty($fuids) ? '' : implode(',', $fuids);
                updatetable('space', array('friendnum' => count($fuids), 'pokenum' => count($pokes)), array('uid' => $newuid));
                updatetable('spacefield', array('friend' => $friendstr, 'feedfriend' => $friendstr), array('uid' => $newuid));
                //更新默认用户好友缓存
                include_once S_ROOT . './source/function_cp.php';
                foreach ($fuids as $fuid) {
                    friend_cache($fuid);
                }
            }
        }
        //加入新用户
        inserttable('spacefield', array('uid' => $newuid), 0, true);
        //baseprofile的事情了!!
        $birth_year = intval(substr($birthday, 0, 4));
        $birth_month = intval(substr($birthday, 4, 2));
        $birth_day = intval(substr($birthday, 6, 2));
        if ($bp['sex'] == '男') {
            $sexc = 1;
        } elseif ($bp['sex'] == '女') {
            $sexc = 2;
        } else {
            $sexc = 0;
        }
        if (empty($bp['identifier'])) {
            $insertinfo = array('realname' => $bp['realname'], 'realbirth' => $birthday, 'sex' => $sexc, 'email' => $email, 'birthyear' => $birth_year, 'birthmonth' => $birth_month, 'birthday' => $birth_day);
            updatetable('spacefield', $insertinfo, array('uid' => $newuid));
        } else {
            $insertinfo = array('identifier' => $bp['identifier'], 'realname' => $bp['realname'], 'realbirth' => $birthday, 'sex' => $sexc, 'email' => $email, 'birthyear' => $birth_year, 'birthmonth' => $birth_month, 'birthday' => $birth_day);
            updatetable('spacefield', $insertinfo, array('uid' => $newuid));
        }
        if ($birth_year && $birth_month && $birth_day) {
            $_SGLOBAL['db']->query("INSERT INTO " . tname('spaceinfo') . " (type,subtype,uid,friend) VALUES ('base','birth'," . $newuid . ",3)");
        }
        $space = array('uid' => $newuid, 'name' => $bp['realname'], 'namestatus' => 1);
        updatetable('space', $space, array('uid' => $newuid));
        //获取该用户的所有基础信息用于填充其教育经历
        $EduArray = array();
        $userids = '';
        $query = $_SGLOBAL['db']->query("SELECT userid,collegeid,school,academy,startyear,class,sourcearea FROM " . tname('baseprofile') . " WHERE realname='{$realname}' and birthday='{$birthday}' order by startyear");
        while ($EduResult = $_SGLOBAL['db']->fetch_array($query)) {
            $userids .= $EduResult['userid'] . ",";
            if ($EduResult['startyear']) {
                if ($EduArray[$EduResult["startyear"]]) {
                    if ($EduResult['class']) {
                        $EduArray[$EduResult["startyear"]] = array('collegeid' => $EduResult['collegeid'], 'school' => $EduResult['school'], 'academy' => $EduResult['academy'], 'sourcearea' => $EduResult['sourcearea'], 'class' => $EduResult['class'], 'startyear' => $EduResult['startyear']);
                    }
                } else {
                    $EduArray[$EduResult["startyear"]] = array('collegeid' => $EduResult['collegeid'], 'school' => $EduResult['school'], 'academy' => $EduResult['academy'], 'sourcearea' => $EduResult['sourcearea'], 'class' => $EduResult['class'], 'startyear' => $EduResult['startyear']);
                }
            }
        }
        foreach ($EduArray as $key => $value) {
            if (empty($value['collegeid'])) {
                //教育信息
                if (!empty($value['startyear'])) {
                    $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'], 'startyear' => $value['startyear']);
                    inserttable('spaceinfo', $eduinfo, 1);
                    //应该要加一个段记录该学生为本科还是研究生********************(缺)
                    //还要考虑没有生日信息但有身份证号存在的情况................(缺)
                    //加入群组:1,同年级;2,区域.
                    $tagname = $value['startyear'] . '级本科生';
                    joinGrade($newuid, $tagname, $_SGLOBAL['db']);
                    $tagname = $value['startyear'] . '级' . $value['sourcearea'] . '本科生';
                    joinArea($newuid, $tagname, $_SGLOBAL['db']);
                }
            } elseif (!empty($value['collegeid'])) {
                $thefour = intval(substr($value['collegeid'], 3, 1));
                if ($thefour == 2 || $value['class']) {
                    $newclass = substr($value['collegeid'], 0, 7);
                    $class = !empty($value['class']) ? $value['class'] : $newclass;
                    $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'] . $value['startyear'] . '级' . $class . '班', 'startyear' => $value['startyear']);
                    inserttable('spaceinfo', $eduinfo, 1);
                    $tagname = $value['startyear'] . '年' . $class . '班';
                    auto_join($newuid, $tagname, $_SGLOBAL['db']);
                    $classB = preg_replace('/([a-zA-Z]*\\d{4})\\d*/', '${1}', $class);
                    $eduinfo = array('uid' => $newuid, 'type' => 'edu', 'title' => '北京航空航天大学', 'subtitle' => $value['academy'] . $value['startyear'] . '级' . $classB . '大班', 'startyear' => $value['startyear']);
                    inserttable('spaceinfo', $eduinfo, 1);
                    $tagname = $value['startyear'] . '年' . $classB . '大班';
                    $tagid = auto_join($newuid, $tagname, $_SGLOBAL['db']);
                    $assts = getGroupAsst($tagid);
                    foreach ($assts as $asst) {
                        $q = $_SGLOBAL['db']->query("SELECT username FROM " . tname("space") . " WHERE uid=" . $asst);
                        if ($v = $_SGLOBAL['db']->fetch_array($q)) {
                            $asstname = $v['username'];
                            friend_update($newuid, $username, $asst, $asstname, 'invite');
                        }
                    }
                }
            }
        }
        if (substr($userids, -1, 1) == ',') {
            $userids = substr($userids, 0, -1);
        }
        $_SGLOBAL['db']->query("update " . tname("baseprofile") . " set isactive='1',uid={$newuid} WHERE userid in ({$userids})");
        $res_json = array("status" => "correct", "uid" => $newuid, "email" => $email, "username" => $username, "password" => $password);
    }
    echo json_encode($res_json);
    return json_encode($res_json);
}