Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once(ROOT."module/model.class.php");
- class account_obj{
- public $info;
- public $_utable;
- public $link;
- public $db_server;
- public function __construct(){
- global $db_table;
- global $db_server;
- global $error_info;
- $this->error_info = $error_info;
- $this->db_server = $db_server;
- $this->link["main"] = new model($db_server["main"],"main");
- $this->_utable = $db_table["users"];
- $this->_ufieldstable = $db_table["userfields"];
- $this->_corptable = $db_table["corporation"];
- }
- function register_user_info($data){
- global $global_role_info;
- $email = $data["email"];
- $corp_code = $data["corp_code"];
- $original_passwd = $data["passwd"];
- $passwd = md5($original_passwd);
- $info = array();
- $error_no = "";
- $match = check_mail($email);
- if ($email == ""){
- $error_no = "8";
- }else{
- if (!$match){
- $error_no = "8";
- }else if ($this->is_email_exists($email)){
- $error_no = "9";
- }
- }
- if ($error_no == "") {
- if ($this->is_corp_exists($corp_code)){
- $error_no = "10";
- }
- }
- if ($error_no == ""){
- $info["email"] = $email;
- $info["passwd"] = $passwd;
- $time = my_time();
- $info["created"] = $time;
- $info["original_passwd"] = $original_passwd;
- $info["username"] = $data["username"];
- $info["firstname"] = $data["firstname"];
- $info["lastname"] = $data["lastname"];
- $info["userpass"] = $passwd;
- $info["corp_code"] = $data["corp_code"];
- $info["corp_name"] = $data["corp_name"];
- $role = $global_role_info["administrator"];
- $info["role_id"] = $role;
- $info["blocked"] = "0";
- $info['is_emailverified'] = "pass";
- $info['zone_val'] = $data['zone_val'];
- $info_arr = $this->add_user_info($info,$role);
- $info["request"] = $info_arr;
- }
- if ($error_no==""&&!$info_arr){
- $error_no = "11";
- }
- $log_type = $error_no ?$error_no : 0;
- $reason = $log_type."|".$role."|".$info["blocked"]."|".$info['is_emailverified'];
- $log_data = array(
- 'email'=>$email,
- 'operation'=>'register',
- 'reason'=>$reason,
- 'created'=>$time,
- );
- $sys_obj = new sys_obj();
- $sys_obj->add_log($log_data);
- if ($error_no!=""){
- $info = array();
- }
- $return_arr = array(
- "info"=>$info,
- "error_no"=>$error_no
- );
- return $return_arr;
- }
- function add_user_info($data,$role='administrator'){
- $err = false;
- $ip = get_ip();
- $expire_time = mktime(date(H),date(i),date(s),date(m)+1,date(d),date(Y));
- $this->link["main"]->query_data("START TRANSACTION");
- $fields = array("email","username","password","role_id","blocked","is_emailverified","created","upgrade_date","expire_date");
- $value = array($data["email"],$data["username"],$data["passwd"],$role,$data["blocked"],$data['is_emailverified'],$data["created"],$data["created"],$expire_time);
- $lastid = $this->link["main"]->insert_data($this->_utable,$fields,$value,"","",$debug=false,$lock=false);
- if ($lastid>0){
- $fields_1 = array("user_id","email","username","first_name","last_name","ip");
- $value_1 = array($lastid,$data['email'],$data['username'],$data['firstname'],$data['lastname'],$ip);
- $ufield_id = $this->link["main"]->insert_data($this->_ufieldstable,$fields_1,$value_1,"","",$debug=false,$lock=false);
- if ($ufield_id>0){
- $fields_2 = array("user_id","corporation_code","corporation_name","is_registerd","zone_val","set_code","created","allow_portal");
- $value_2 = array($lastid,$data['corp_code'],$data['corp_name'],1,$data['zone_val'],1,$data['created'],1);
- $corp_id = $this->link["main"]->insert_data($this->_corptable,$fields_2,$value_2,"","",$debug=false,$lock=false);
- if ($corp_id>0){
- $fields_3 = array("corporation_id","modified");
- $value_3 = array($corp_id,$data['created']);
- $where = "id=".$lastid;
- $us = $this->link["main"]->update_data($this->_utable,$fields_3,$value_3,$where,"","",$debug=false);
- $err = $us ?false : true;
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- if($err) {
- $this->link["main"]->query_data("ROLLBACK");
- $user_info = array();
- }else {
- $this->link["main"]->query_data("COMMIT");
- $user_info = array(
- 'userid'=>$lastid,
- 'corp_id'=>$corp_id,
- );
- }
- return $user_info;
- }
- function is_email_exists($email,$where=""){
- $where = empty($where) ?"email='$email'": "email='$email' and ".$where;
- $rs = $this->link["main"]->select_data($this->_utable,"count(1) as nums",$where,"-1","-1","","",false);
- return (intval($rs[0]["nums"])>0) ?true : false;
- }
- function is_trial_exists($email,$where=""){
- $where = empty($where) ?"email='$email'": "email='$email' and ".$where;
- $rs = $this->link["main"]->select_data($this->_utable,"id,password",$where,"0","1","","",false);
- return is_array($rs) ?$rs : "";
- }
- function is_corp_exists($corp_code,$where=""){
- $where = empty($where) ?"corporation_code='$corp_code'": "corporation_code='$corp_code' and ".$where;
- $rs = $this->link["main"]->select_data($this->_corptable,"count(1) as nums",$where,"-1","-1","","",false);
- return (intval($rs[0]["nums"])>0) ?true : false;
- }
- function check_corp_exists($corp_id,$where=""){
- $where = empty($where) ?"id='$corp_id'": "id='$corp_id' and ".$where;
- $rs = $this->link["main"]->select_data($this->_corptable,"count(1) as nums",$where,"-1","-1","","",false);
- return (intval($rs[0]["nums"])>0) ?true : false;
- }
- function register_full_user($data){
- global $global_role_info;
- $email = $data["email"];
- $regkey = $data["regcode"];
- $corp_code = $data['corp_code'];
- $original_passwd = $data["passwd"];
- $passwd = md5($original_passwd);
- $info = array();
- $error_no = "";
- $up_flag = false;
- $match = check_mail($email);
- if ($email==""){
- $error_no = "8";
- }else{
- if (!$match){
- $error_no = "8";
- }else if($chereg = $this->is_trial_exists($email)){
- if (is_array($chereg) &&$chereg !=""){
- if ($passwd === $chereg["password"]){
- $up_flag = true;
- }else{
- $error_no = "15";
- }
- }
- }
- }
- if ($error_no == ""){
- $where = $up_flag ?" user_id<>".$chereg['id'] : "";
- if ($corp_code == ""){
- $error_no = 16;
- }else {
- if ($this->is_corp_exists($corp_code,$where)){
- $error_no = "10";
- }
- }
- }
- if ($regkey == ""){
- $error_no = "17";
- }else{
- $purchased = 1;
- }
- if ($error_no == ""){
- $info["email"] = $email;
- $info["username"] = $data["username"];
- $info["firstname"] = $data["firstname"];
- $info["lastname"] = $data["lastname"];
- $info["passwd"] = $passwd;
- $time = my_time();
- $info["created"] = $time;
- $info["regkey"] = $regkey;
- $info["corp_code"] = $corp_code;
- $info["corp_name"] = $data["corp_name"];
- $info["up_flag"] = $up_flag;
- $role = $global_role_info["administrator"];
- $info["blocked"] = "1";
- $info['is_emailverified'] = "pass";
- $info['purchased'] = $purchased;
- $info_arr = $this->add_full_user($info,$role);
- $info["request"] = $info_arr;
- }
- if ($error_no==""&&!$info_arr){
- $error_no = "11";
- }
- $log_type = $error_no ?$error_no : 0;
- $reason = $log_type."|".$role."|".$info["blocked"]."|".$info['is_emailverified']."|".$regkey;
- $log_data = array(
- 'email'=>$email,
- 'operation'=>'register',
- 'reason'=>$reason,
- 'created'=>$time,
- );
- $sys_obj = new sys_obj();
- $sys_obj->add_log($log_data);
- if ($error_no!=""){
- $info = array();
- }
- $return_arr = array(
- "info"=>$info,
- "error_no"=>$error_no
- );
- return $return_arr;
- }
- function add_full_user($data,$role='administrator'){
- $err = false;
- $this->link["main"]->query_data("START TRANSACTION");
- $expire_time = mktime(date(H),date(i),date(s),date(m)+6,date(d),date(Y));
- if ($data["up_flag"]){
- $where = "email='$data[email]'";
- $user_info = $this->link["main"]->select_data($this->_utable,"id,corporation_id",$where,"0","1","","",false);
- if ($user_info){
- $fields = array("username","role_id","blocked","purchased","registration_code","is_emailverified","modified","license_type","upgrade_date","expire_date");
- $value = array($data["username"],$role,$data['blocked'],$data['purchased'],$data['regkey'],$data['is_emailverified'],$data['created'],"unlimited",$data['created'],$expire_time);
- $where = "id=".$user_info["id"];
- $us = $this->link["main"]->update_data($this->_utable,$fields,$value,$where,"","",$debug=false);
- if ($us){
- $fields_1 = array("username","first_name","last_name");
- $value_1 = array($data["username"],$data['firstname'],$data['lastname']);
- $where_1 = "user_id=".$user_info["id"];
- $fields_us = $this->link["main"]->update_data($this->_ufieldstable,$fields_1,$value_1,$where_1,"","",$debug=false);
- if ($fields_us){
- $fields_2 = array("corporation_code","corporation_name","modified");
- $value_2 = array($data["corp_code"],$data["corp_name"],$data["created"]);
- $corp_us = $this->link["main"]->update_data($this->_corptable,$fields_2,$value_2,$where_1,"","",$debug=false);
- $err = $corp_us ?false : true;
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- }else {
- $fields = array("email","username","password","role_id","blocked","is_emailverified","purchased","registration_code","created","license_type","upgrade_date","expire_date");
- $value = array($data["email"],$data["username"],$data["passwd"],$role,$data['blocked'],$data['is_emailverified'],$data["purchased"],$data['regkey'],$data["created"],"unlimited",$data['created'],$expire_time);
- $lastid = $this->link["main"]->insert_data($this->_utable,$fields,$value,"","",$debug=false,$lock=false);
- if ($lastid>0){
- $ip = get_ip();
- $fields_1 = array("user_id","email","username","first_name","last_name","ip");
- $value_1 = array($lastid,$data['email'],$data['username'],$data['firstname'],$data['lastname'],$ip);
- $ufields_id = $this->link["main"]->insert_data($this->_ufieldstable,$fields_1,$value_1,"","",$debug=false,$lock=false);
- if ($ufields_id){
- $fields_2 = array("user_id","corporation_code","corporation_name","is_registerd","created");
- $value_2 = array($lastid,$data['corp_code'],$data['corp_name'],1,$data['created']);
- $corp_id = $this->link["main"]->insert_data($this->_corptable,$fields_2,$value_2,"","",$debug=false,$lock=false);
- if ($corp_id>0){
- $fields_3 = array("corporation_id","modified");
- $value_3 = array($corp_id,$data['created']);
- $where = "id=".$lastid;
- $us = $this->link["main"]->update_data($this->_utable,$fields_3,$value_3,$where,"","",false);
- $err = $us ?false : true;
- $user_info = array(
- 'id'=>$lastid,
- 'corporation_id'=>$corp_id,
- );
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- }
- if($err) {
- $this->link["main"]->query_data("ROLLBACK");
- $user_info = array();
- }else {
- $this->link["main"]->query_data("COMMIT");
- }
- return $user_info;
- }
- function reg_part_user($data){
- global $global_role_info,$config;
- $email = $data["email"];
- $corp_id = $data['corp_id'];
- $original_passwd = $data["passwd"];
- $passwd = md5($original_passwd);
- $info = array();
- $error_no = "";
- $match = check_mail($email);
- if ($email==""){
- $error_no = "8";
- }else{
- if (!$match){
- $error_no = "8";
- }else if ($this->is_email_exists($email)){
- $error_no = "9";
- }
- }
- if ($error_no == ""){
- $auth = $this->check_reg_auth($email,$corp_id);
- $error_no = isset($auth['error_no']) ?$auth['error_no'] : "";
- $reg_verified = isset($auth['reg_verified']) ?$auth['reg_verified'] : "";
- }
- $user_obj = new user_obj();
- $where = "id=".$corp_id;
- $corp_info = $user_obj->get_corpinfo_bycondition($result_fields="user_id,corporation_code",$where,$start="0",$limit="1",$order="",$debug=false);
- if ($corp_info){
- $info['corp_code'] = $corp_info['corporation_code'];
- }else {
- $error_no = 11;
- }
- $time = my_time();
- if (!$reg_verified &&$error_no ==''){
- if (INSTALLTYPE == STANDALONE){
- $limit_participant = sys_authcode(LICENSELIMIT,'DECODE','W');
- }else {
- $where = "id='$corp_info[user_id]'";
- $rs = $user_obj->get_userinfo_bycondition('license_type,expire_date',$where,0,1,'',false);
- $license_type = $rs['license_type'] ?$rs['license_type'] : $config['trial_license'];
- $where = "license_level='$license_type' AND (status=1 || status=2)";
- $rs2 = $user_obj->get_licenseinfo_bycondition('limit_participant',$where,0,1,'','',false);
- $limit_participant = $rs2['limit_participant'];
- }
- $where = "corporation_id='$corp_id' and role_id='participant' and blocked =1 AND is_emailverified='pass'";
- $user_rs = $user_obj->get_userinfo_bycondition("count(1) as nums",$where);
- $participant_nums = $user_rs[0]["nums"] >0 ?$user_rs[0]["nums"] : 0;
- $error_no = ($participant_nums >= $limit_participant) &&$limit_participant !='Unlimited'?18 : '';
- if ($error_no ==''&&INSTALLTYPE != STANDALONE){
- $error_no = $rs['expire_date'] <$time ?19 : '';
- }
- }
- $info["email"] = $email;
- $info["passwd"] = $passwd;
- $info["username"] = $data["username"];
- $info["firstname"] = $data["firstname"];
- $info["lastname"] = $data["lastname"];
- $info["created"] = $time;
- $info["corp_id"] = $corp_id;
- $info["reg_verified"] = $reg_verified;
- $info["is_emailverified"] = "pass";
- $info["blocked"] = $reg_verified ?2 : 1 ;
- $role = $global_role_info["participant"];
- if ($error_no == ""){
- $info_arr = $this->add_part_user($info,$role);
- $info["request"] = $info_arr;
- }
- if ($error_no==""&&!$info_arr){
- $error_no = "11";
- }else {
- }
- $log_type = $error_no ?$error_no : 0;
- $reason = $log_type."|".$role."|".$info["blocked"]."|".$info["is_emailverified"];
- $log_data = array(
- 'email'=>$email,
- 'operation'=>'register',
- 'reason'=>$reason,
- 'created'=>$time,
- );
- $sys_obj = new sys_obj();
- $sys_obj->add_log($log_data);
- if ($error_no !=""){
- $info = array();
- }
- $return_arr = array(
- "info"=>$info,
- "error_no"=>$error_no
- );
- return $return_arr;
- }
- function check_reg_auth($email,$corp_id){
- $email_limit = true;
- $error_no = "";
- $where = empty($where) ?"id='$corp_id'": "id='$corp_id' and ".$where;
- $rs = $this->link["main"]->select_data($this->_corptable,"*",$where,"0","1","","",false);
- if ($rs) {
- if ($rs['is_registerd'] == '0') {
- $error_no = "13";
- }else {
- if ($rs['limit_register'] != ''){
- $email_limit_arr = explode(",",$rs['limit_register']);
- foreach ($email_limit_arr as $item) {
- $pattern = str_replace("*","(.*)",$item);
- $match = preg_match("/$pattern/is",$email,$reg);
- if($match &&$reg[0] == $email){
- $email_limit = false;
- break;
- }
- }
- }else {
- $email_limit = false;
- }
- $error_no = $email_limit ?"14": "";
- }
- }else {
- $error_no = "12";
- }
- $is_register_verified = isset($rs['is_register_verified']) ?$rs['is_register_verified'] : "";
- $return_arr = array(
- 'error_no'=>$error_no,
- 'reg_verified'=>$is_register_verified
- );
- return $return_arr;
- }
- function add_part_user($data,$role='participant'){
- $err = false;
- $this->link["main"]->query_data("START TRANSACTION");
- $fields = array("email","username","password","role_id","corporation_id","blocked","is_emailverified","setup_code","created");
- $value = array($data["email"],$data["username"],$data["passwd"],$role,$data['corp_id'],$data["blocked"],$data['is_emailverified'],$data['setup_code'],$data["created"]);
- $lastid = $this->link["main"]->insert_data($this->_utable,$fields,$value,"","",$debug=false,$lock=false);
- if ($lastid>0){
- $ip = get_ip();
- $fields = array("user_id","username","email","first_name","last_name","ip");
- $value = array($lastid,$data["username"],$data["email"],$data['firstname'],$data['lastname'],$ip);
- $rs = $this->link["main"]->insert_data($this->_ufieldstable,$fields,$value,"","",$debug=false,$lock=false);
- $err = $rs ?false : true;
- }else {
- $err = true;
- }
- if($err) {
- $this->link["main"]->query_data("ROLLBACK");
- $user_info = array();
- }else {
- $this->link["main"]->query_data("COMMIT");
- $user_info = array(
- 'id'=>$lastid
- );
- }
- return $user_info;
- }
- function register_role_info($data){
- global $global_role_info,$config;
- $checkreg_email = $data["reg_email"];
- $checkreg_firstname = $data["reg_firstname"];
- $checkreg_lastname = $data["reg_lastname"];
- $checkreg_passwd = $data["reg_passwd"];
- $corp_id = $data['corp_id'];
- $user_id = $data['user_id'];
- $import_group_id = $data['import_group_id'];
- $addition_import_group_id = $data['addition_import_group_id'];
- $is_purchased = $data['is_purchased'];
- $issend_mail = $data['send_email'];
- $return_arr = array();
- $register_group = array();
- $error_no = "";
- $info = array();
- $valid_email = array();
- $exists_email = array();
- $error_email = array();
- $reg_email = array();
- $user_obj = new user_obj();
- $isRegPublisher = $data["role"] == $global_role_info['publisher'] ?true : false;
- $isRegParticipant = $data["role"] == $global_role_info['participant'] ?true : false;
- if ($_FILES['reg_file']['error'] == 0 &&$_FILES['reg_file']['size'] >0){
- $return_arr = $this->parse_register_file($_FILES,$data["set_passwd"]);
- if ($return_arr['error_no']){
- $error_no = $return_arr['error_no'];
- }else {
- $email_arr = $return_arr['reg_info'];
- $register_group = $return_arr['group_info'];
- }
- }elseif ($data['reg_type'] !='file') {
- $tmp_email = array();
- if ($checkreg_email &&is_array($checkreg_email)){
- foreach ($checkreg_email as $key =>$row){
- if ($row ==''&&$checkreg_firstname[$key] ==''&&$checkreg_lastname[$key] ==''&&$checkreg_passwd[$key]=='') continue;
- $email_arr[$key]['email'] = trim($row);
- $email_arr[$key]['firstname'] = trim($checkreg_firstname[$key]);
- $email_arr[$key]['lastname'] = trim($checkreg_lastname[$key]);
- $cur_pwd = trim($checkreg_passwd[$key]);
- $email_arr[$key]['group_id'] = $import_group_id;
- if($email_arr[$key]['email'] == ''){
- $error_no = 3;
- break;
- }
- if($email_arr[$key]['firstname']==''||$email_arr[$key]['lastname'] ==''){
- $error_no = 15;
- break;
- }
- if ($data['set_passwd'] ==2){
- if (strlen($cur_pwd) >5 &&strlen($cur_pwd) <33){
- $email_arr[$key]['passwd'] = $cur_pwd;
- }else {
- $error_no = 1;
- break;
- }
- }
- }
- }
- }
- if($error_no ==""&&(!is_array($email_arr) ||count($email_arr)<=0)){
- $error_no = 3;
- }
- if ($error_no == ""){
- foreach ($email_arr as $key =>$row){
- $email = is_array($row) ?$row['email'] : $row;
- if (in_array($email,$tmp_email)){
- continue;
- }else {
- $tmp_email[] = $email;
- }
- $firstname = is_array($row) ?str_replace("'","'",$row['firstname']) : "";
- $lastname = is_array($row) ?str_replace("'","'",$row['lastname']) : "";
- $username = $firstname ||$lastname ?$firstname." ".$lastname : substr($email,0,strpos($email,'@'));
- $match = check_mail($email);
- if ($match){
- if ($this->is_email_exists($email)){
- $exists_email[] = $email;
- }else {
- $valid_email[$key]['email'] = $email;
- $valid_email[$key]['username'] = $username;
- $valid_email[$key]['firstname'] = $firstname;
- $valid_email[$key]['lastname'] = $lastname;
- $valid_email[$key]['passwd'] = isset($row['passwd']) ?$row['passwd'] : '';
- $valid_email[$key]['group'] = $row['group']>0 ?$row['group'] : 0;
- $valid_email[$key]['group_id'] = $row['group_id']>0 ?$row['group_id'] : 0;
- }
- }else {
- if ($email){
- $error_email[] = $email;
- }
- }
- }
- if ($error_email){
- $error_no = 9;
- $error_info = implode(',',$error_email);
- }elseif ($exists_email){
- $error_no = 10;
- $error_info = implode(',',$exists_email);
- }
- }
- if ($valid_email &&$error_no ==''){
- $where = "id=".$corp_id;
- $result_fields = "corporation_code,user_id,corporation_name";
- $corp_info = $user_obj->get_corpinfo_byconditon($result_fields,$where,$start="0",$limit="1",$order="",$debug=false);
- if (!$is_purchased &&$isRegPublisher &&INSTALLTYPE != STANDALONE){
- $result_fields = "COUNT(*) AS nums";
- $where = "(role_id='$global_role_info[administrator]' or role_id='$global_role_info[publisher]') AND corporation_id='$corp_id' AND blocked<>-1";
- $qid = $user_obj->get_userinfo_bycondition($result_fields,$where);
- if ($qid[0]['nums'] >$config['reg_limit_publisher']){
- $error_no = "11";
- }
- }
- if ($error_no == ''){
- if ($register_group){
- $group_info = array();
- $group_type = $isRegPublisher ?1 : 0;
- foreach ($register_group as $key =>$item){
- $where = "corporation_id='$corp_id' AND group_name='$item' and type='$group_type' ";
- $rs = $user_obj->get_groupinfo_bycondition($result_fields="count(1) as nums,id",$where,-1,-1,"","",$debug=false);
- if($rs&&$rs[0]["nums"]>0){
- $group_info[$item] = $rs[0]['id'];
- unset($register_group[$key]);
- }
- }
- if($error_no == ""){
- foreach ($register_group as $item){
- $g_data = array(
- 'corp_id'=>$corp_id,
- 'group_name'=>$item,
- 'type'=>$group_type,
- 'user_id'=>$user_id,
- 'description'=>'',
- 'group_parent_id'=>0,
- 'is_checked'=>1
- );
- $g_rs = $user_obj->add_group($g_data);
- $group_info[$item] = $g_rs['group_id'] >0 ?$g_rs['group_id'] : 0;
- }
- }
- }
- if($error_no == ""){
- foreach ($valid_email as $key =>$row){
- $tmp_group = array();
- $reg_email[$key]['email'] = $row['email'];
- $reg_email[$key]['username'] = $row['username'];
- $reg_email[$key]['firstname'] = $row['firstname'];
- $reg_email[$key]['lastname'] = $row['lastname'];
- $reg_email[$key]['group_id'] = $row['group_id'];
- if ($data["set_passwd"] == 1){
- $reg_email[$key]['passwd'] = $data["passwd"];
- $reg_email[$key]['auth_passwd'] = md5($data["passwd"]);
- }elseif ($data["set_passwd"] == 2){
- $reg_email[$key]['passwd'] = $row["passwd"];
- $reg_email[$key]['auth_passwd'] = md5($row["passwd"]);
- }else {
- $auto_passwd = set_rand_password();
- $reg_email[$key]['passwd'] = $auto_passwd;
- $reg_email[$key]['auth_passwd'] = md5($auto_passwd);
- }
- if ($row['group']){
- foreach ($row['group'] as $val){
- if ($group_info[$val] >0){
- $tmp_group[] = $group_info[$val];
- }
- }
- }
- if ($import_group_id >0 &&!in_array($import_group_id,$tmp_group)){
- $tmp_group[] = $import_group_id;
- }
- if ($addition_import_group_id >0 &&!in_array($addition_import_group_id,$tmp_group)){
- $tmp_group[] = $addition_import_group_id;
- }
- if(count($tmp_group) >0){
- $reg_email[$key]['group_id'] = @implode(',',$tmp_group);
- }else{
- $reg_email[$key]['group_id'] = 0;
- }
- }
- }
- }
- }elseif ($error_no == "") {
- $error_no = 4;
- }
- $info['reg_email'] = $reg_email;
- $info['exists_email'] = $exists_email;
- $info['error_email'] = $error_email;
- $time = my_time();
- $info["created"] = $time;
- $info["corp_id"] = $corp_id;
- $info["role"] = $data["role"];
- $info["blocked"] = "1";
- $info["is_emailverified"] = "pass";
- $info['corp_code'] = $corp_info['corporation_code'];
- $account_data['reg_nums'] = count($info['reg_email']);
- $account_data['corp_id'] = $corp_id;
- if($data["admin_type"] == "publisher") {
- $account_data["user_id"] = $corp_info["user_id"];
- }else {
- $account_data['user_id'] = $user_id;
- }
- $reg_status = $user_obj->check_account_rule($account_data);
- $error_no = $error_no ?$error_no : $reg_status;
- if ($error_no == ""&&$reg_email){
- $info_arr = $this->add_role_info($info);
- }
- if ($error_no==""&&!$info_arr){
- $error_no = "5";
- }
- unset($_FILES);
- $log_type = $error_no ?$error_no : 0;
- $reason = $log_type."|".$info["role"]."|".$info["blocked"]."|".$info["is_emailverified"];
- $log_data = array(
- 'email'=>$reg_email,
- 'operation'=>'register',
- 'reason'=>$reason,
- 'created'=>$time,
- );
- $sys_obj = new sys_obj();
- $sys_obj->add_log($log_data);
- $section = 'register_role_action';
- if ($error_no){
- $log_type = ($error_no ==5 ||$error_no == 6 ||$error_no == 8) ?'error': 'warn';
- }else {
- $log_type = 'notice';
- }
- if ($exists_email){
- $exists_str = implode(',',$exists_email);
- }
- if ($error_email){
- $error_str = implode(',',$error_email);
- }
- $reg_mailstr = array2sqlstr($reg_email,'email');
- $log_str = 'regemail:'.$reg_mailstr.';extemail:'.$exists_str.';erremail:'.$error_str.";operuid:".$user_id.";errno:".$error_no;
- sys_insert_log($log_str,$section,$log_type);
- if ($error_no !=""){
- $info = array();
- }elseif ($info_arr &&$reg_email &&$issend_mail){
- $sys_obj = new sys_obj();
- $tpl_id = "register_notify";
- $sitedomain = INSTALLTYPE == STANDALONE ?DOMAIN_MAIN : get_corp_url($info["corp_code"]);
- $cur_userinfo = $user_obj->get_userinfo_byuserid($user_id,'email,username','',false);
- foreach ($reg_email as $item){
- $tpl_vars = array(
- "corp_id"=>$corp_id,
- "email_from"=>$cur_userinfo['email'],
- "email_fromname"=>$cur_userinfo['username'],
- "email_to"=>$item['email'],
- "passwd"=>$item['passwd'],
- "username"=>$item['username'],
- "sitedomain"=>$sitedomain
- );
- $recipient = array('0'=>$item['email']);
- $sys_obj->add_mail_queue($tpl_id,$tpl_vars,$time_to_send="",$ip="",$sender="",$recipient,$try_sent=0,$delete_after_send=1,$ishtml=1);
- }
- if (INSTALLTYPE == STANDALONE){
- include_once(ROOT."shell/mailer/mailer_behavior.class.php");
- $mail_behavior = new mailer_behavior();
- $mail_behavior->send_mail_queue();
- }
- }
- $return_arr = array(
- "info"=>$info,
- "error_no"=>$error_no,
- "error_info"=>$error_info
- );
- return $return_arr;
- }
- function parse_register_file($_FILES,$set_passwd){
- global $parse_file_type;
- $error_no = "";
- $reg_info = array();
- $group_arr = array();
- if ($_FILES["reg_file"]["error"] == UPLOAD_ERR_OK &&$_FILES["reg_file"]["size"] >0) {
- $tmp_name = $_FILES["reg_file"]["tmp_name"];
- $name = $_FILES["reg_file"]["name"];
- $file_match = array();
- preg_match("/(.+)\.([^.]+)$/i",$name,$file_match);
- $file_type = strtolower($file_match[2]);
- $file_name = strtolower($file_match[0]);
- if(in_array($file_type,$parse_file_type)){
- if(!$fh = fopen($tmp_name,'r')) {
- $error_no = 8;
- }else {
- $cont2arr = array();
- $index = 0;
- while(!feof($fh)){
- $index++;
- $line = fgets($fh,255);
- if (!$line ||$index == 1) {
- continue;
- }
- $cont2arr = split(',',$line);
- $reg_info[$index]['email'] = escape_ctrl_char(trim($cont2arr[0]));
- $reg_info[$index]['passwd'] = trim($cont2arr[1]);
- $reg_info[$index]['firstname'] = escape_ctrl_char(trim($cont2arr[2]));
- $reg_info[$index]['lastname'] = escape_ctrl_char(trim($cont2arr[3]));
- $reg_info[$index]['username'] = $reg_info[$index]['firstname']." ".$reg_info[$index]['lastname'];
- $reg_info[$index]['email'] = escape_ctrl_char(trim($cont2arr[0]));
- if ($set_passwd == 2){
- if ($reg_info[$index]['passwd'] !=''&&strlen($reg_info[$index]['passwd']) >5){
- }else {
- $error_no = 14;
- }
- }else {
- $reg_info[$index]['passwd'] = '';
- }
- $cur_group = array();
- $tmp_group1 = escape_ctrl_char(trim($cont2arr[4]));
- $tmp_group2 = escape_ctrl_char(trim($cont2arr[5]));
- $tmp_group3 = escape_ctrl_char(trim($cont2arr[6]));
- if ($tmp_group1){
- $cur_group[] = $tmp_group1;
- $group_arr[] = $tmp_group1;
- }
- if ($tmp_group2){
- $cur_group[] = $tmp_group2;
- $group_arr[] = $tmp_group2;
- }
- if ($tmp_group3){
- $cur_group[] = $tmp_group3;
- $group_arr[] = $tmp_group3;
- }
- $reg_info[$index]['group'] = array_unique($cur_group);
- $group_arr = array_unique($group_arr);
- }
- }
- }else {
- $error_no = 7;
- }
- }else {
- $error_no = 6;
- }
- if ($error_no){
- $reg_info = array();
- }
- $return_arr = array(
- "error_no"=>$error_no,
- "reg_info"=>$reg_info,
- "group_info"=>$group_arr
- );
- return $return_arr;
- }
- function add_role_info($data){
- $err = false;
- $field_info = array();
- $reg_email = $data['reg_email'];
- $index = 1;
- $value_str = "";
- $fields_str = "email, username, password, role_id, corporation_id, blocked, is_emailverified, group_id, created";
- $int_total = count($reg_email);
- foreach ($reg_email as $item){
- $field_info[$item['email']]['firstname'] = $item['firstname'];
- $field_info[$item['email']]['lastname'] = $item['lastname'];
- $field_info[$item['email']]['phone'] = $item['phone'];
- $field_info[$item['email']]['fax'] = $item['fax'];
- $field_info[$item['email']]['address'] = $item['address'];
- $field_info[$item['email']]['desc'] = $item['desc'];
- if ($int_total == $index){
- $value_str .= "('$item[email]','$item[username]','$item[auth_passwd]','$data[role]','$data[corp_id]','$data[blocked]','$data[is_emailverified]','$item[group_id]','$data[created]')";
- }else {
- $value_str .= "('$item[email]','$item[username]','$item[auth_passwd]','$data[role]','$data[corp_id]','$data[blocked]','$data[is_emailverified]','$item[group_id]','$data[created]'),";
- }
- $index++;
- }
- $this->link["main"]->query_data("START TRANSACTION");
- $sql = "INSERT INTO ".$this->_utable."(".$fields_str.") VALUES ".$value_str;
- $rs = $this->link["main"]->query_data($sql,false);
- if ($rs) {
- $email_str = array2sqlstr($reg_email,"email");
- $where = "email IN ({$email_str})";
- $user_rs = $this->link["main"]->select_data($this->_utable,"id,email,username",$where,"-1","-1","","",false);
- if ($user_rs){
- $ip = get_ip();
- $fields_str = "user_id,email,username,first_name,last_name,phone,fax,address,description,ip";
- $total = count($user_rs);
- $index = 1;
- $value_str = "";
- foreach ($user_rs as $row){
- $first_name = $field_info[$row['email']]['firstname'];
- $last_name = $field_info[$row['email']]['lastname'];
- $phone = $field_info[$row['email']]['phone'];
- $fax = $field_info[$row['email']]['fax'];
- $address = $field_info[$row['email']]['address'];
- $desc = $field_info[$row['email']]['desc'];
- if ($total == $index){
- $value_str .= "('$row[id]','$row[email]','$row[username]','$first_name','$last_name','$phone','$fax','$address','$desc','$ip')";
- }else {
- $value_str .= "('$row[id]','$row[email]','$row[username]','$first_name','$last_name','$phone','$fax','$address','$desc','$ip'),";
- }
- $index++;
- }
- $ufields_sql = "INSERT INTO ".$this->_ufieldstable."(".$fields_str.") VALUES ".$value_str;
- $ufields_rs = $this->link["main"]->query_data($ufields_sql,false);
- $err = $ufields_rs ?false : true;
- }else {
- $err = true;
- }
- }else {
- $err = true;
- }
- if($err) {
- $this->link["main"]->query_data("ROLLBACK");
- $return = false;
- }else {
- $this->link["main"]->query_data("COMMIT");
- $return = true;
- }
- return $return;
- }
- function auto_reg_guest($data){
- global $lang;
- $Tcookie = get_qms_cookie("Tcookie");
- $is_allow_cookie = false;
- if($Tcookie!=""){
- $is_allow_cookie = true;
- }else{
- $is_allow_cookie = false;
- }
- if(isset($_SESSION["Tcookie"])){
- $retry_nums = $_SESSION["Tcookie"];
- }else{
- $retry_nums = 0;
- }
- if($retry_nums >3){
- $msg = $lang['cookie_forbiden'];
- $msg = urlencode($msg);
- report_error($msg);
- die();
- }
- if(!$is_allow_cookie){
- $cookies = array("Tcookie"=>"qms");
- set_qms_cookie($cookies,-2);
- $Tcookie = get_qms_cookie("Tcookie");
- session_register("Tcookie");
- $retry_nums = intval($retry_nums) +1;
- $_SESSION["Tcookie"] = $retry_nums;
- $this_url = "index.php?module=account&submod=account&method=sys_experience";
- redirect($this_url);
- die();
- }
- $guid_code = "";
- if($_SERVER["HTTP_USER_AGENT"] !=""&&$_SERVER["HTTP_ACCEPT"] !=""&&$_SERVER["HTTP_CONNECTION"]){
- $qms_registerid = get_qms_cookie("qms_registerid");
- if($qms_registerid!=""){
- $up_auth_id = $qms_registerid;
- $id_arr = explode("|",base64_decode(sys_authcode($up_auth_id,'DECODE')));
- $cur_userid = $id_arr[0];
- $guid_code = $id_arr[1];
- }else{
- require_once(ROOT."phplibs/php_guid.class.php");
- $guid = new Guid();
- $guid_code = $guid->toString();
- $guid_code = "{".$guid_code."}";
- $cur_userid = "-1";
- $up_auth_id = sys_authcode(base64_encode($cur_userid."|".$guid_code),"ENCODE");
- $qms_registerid = $up_auth_id;
- $cookies = array("qms_registerid"=>$up_auth_id);
- set_qms_cookie($cookies,-2);
- }
- }
- preg_match("/\{([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})\}/i",$guid_code,$match);
- if($cur_userid == "-1"&&$match[1]!=""&&$match[2]!=""){
- $is_register = false;
- if($_SERVER["HTTP_USER_AGENT"] !=""&&$_SERVER["HTTP_ACCEPT"] !=""&&$_SERVER["HTTP_CONNECTION"]){
- $is_register = true;
- }
- if($is_register){
- $register_data = array("register_id"=>$up_auth_id);
- $return_arr = $this->auto_register($register_data);
- if(!isset($return_arr["error_no"]) ||$return_arr["error_no"] == ""){
- $register_info = $return_arr["info"];
- $login_data = array(
- "email"=>$register_info["email"],
- "userpass"=>md5($register_info["original_passwd"]),
- "mode"=>"autologin",
- );
- $user_obj = new user_obj();
- $login_rs = $user_obj->user_login($login_data);
- $user_info = $login_rs;
- if(!isset($login_rs["error_no"]) ||$login_rs["error_no"] == ""){
- $up_auth_id = $login_rs["auth_id"];
- $cookies = array(
- "qms_cur_userid"=>$login_rs["userid"],
- "qms_cur_email"=>$login_rs["email"],
- "qms_username"=>$login_rs["username"],
- "qms_pass"=>sys_authcode($login_data["userpass"],'ENCODE'),
- "qms_is_try"=>$login_rs["is_try"],
- "qms_auth_id"=>$login_rs['auth_id'],
- );
- $arr = array("qms_dcur_userid"=>"qms_test");
- set_qms_cookie($cookies,-2);
- }
- return $user_info;
- }
- }
- }
- return false;
- }
- function auto_reg_anonymous($data){
- global $lang;
- $guid_code = "";
- $corp_id = $data['corporation_id'];
- require_once(ROOT."phplibs/php_guid.class.php");
- $guid = new Guid();
- $guid_code = $guid->toString();
- $guid_code = "{".$guid_code."}";
- $cur_userid = "-1";
- $up_auth_id = sys_authcode(base64_encode($cur_userid."|".$guid_code."|".$corp_id),"ENCODE");
- $qms_registerid = $up_auth_id;
- preg_match("/\{([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})\}/i",$guid_code,$match);
- if($cur_userid == "-1"&&$match[1]!=""&&$match[2]!=""){
- $is_register = true;
- }else {
- $error_no = 2;
- }
- $register_data = array(
- "register_id"=>$up_auth_id,
- "error_no"=>$error_no
- );
- return $register_data;
- }
- function auto_register($data){
- global $global_guest_user_info,$global_role_info;
- $register_data = array();
- $register_data = array();
- $error_no = "";
- $individ_email = $data['email'];
- $id_arr = explode("|",base64_decode(sys_authcode($data["register_id"],"DECODE")));
- $cur_userid = $id_arr[0];
- $setup_code = $id_arr[1];
- preg_match("/\{([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})\}/i",$setup_code,$match);
- $email_hex = $match[1].$match[2].$match[3].$match[4].$match[5];
- if($match[1]!=""&&$match[2]!=""&&$match[3]!=""&&$match[4]!=""&&$match[5]!=""){
- $email = $email_hex.$global_guest_user_info["email"];
- $nick = $individ_email ?$individ_email : $global_guest_user_info["nick"].time();
- $original_passwd = set_rand_password();
- $passwd = md5($original_passwd);
- $role_id = $global_guest_user_info["role_id"];
- $register_data["email"] = escape_ctrl_char(trim($email));
- $register_data["username"] = escape_ctrl_char(trim($nick));
- $register_data["passwd"] = escape_ctrl_char(trim($passwd));
- $register_data["role_id"] = (isset($role_id) &&$role_id !='') ?$role_id : "guest_participant";
- $register_data["corp_id"] = $data['corporation_id'] ?$data['corporation_id'] : '';
- $register_data["blocked"] = 0;
- $register_data["is_emailverified"] = "pass";
- $register_data["created"] = my_time();
- $register_data["original_passwd"] = $original_passwd;
- $auth_passwd_rs = auth_passwd($register_data["original_passwd"],"ENCODE",$setup_code);
- $register_data["setup_code"] = $auth_passwd_rs["passwd"];
- $user_obj = new user_obj();
- $where = "email='".$register_data["email"]."'";
- $result_fields = "id,username,email,password,setup_code";
- $user_rs = $user_obj->get_userinfo_bycondition($result_fields,$where,0,1,"id desc","",false);
- if(is_array($user_rs) &&count($user_rs) >0 &&$user_rs["id"] >0){
- $setup_code = $user_rs["setup_code"];
- $passwd_rs = auth_passwd($setup_code,"DECODE");
- $original_passwd = $passwd_rs["passwd"];
- $user_rs["original_passwd"] = $original_passwd;
- $return_arr = array(
- "error_no"=>"",
- "info"=>$user_rs
- );
- }else{
- $reg_info = $this->add_part_user($register_data,$role=$register_data["role_id"]);
- if (count($reg_info) >0 &&$reg_info['id']>0){
- $register_data['id'] = $reg_info['id'];
- $return_arr = array(
- "error_no"=>"",
- "info"=>$register_data,
- );
- }
- }
- }else{
- $return_arr = array(
- "error_no"=>"2",
- "info"=>$register_data,
- );
- }
- return $return_arr;
- }
- function user_activation($data){
- global $lang;
- $get = my_get();
- $email = isset($data["email"]) ?strtolower(escape_ctrl_char(trim($data["email"]))) : "";
- $retake_validate = isset($data["s"]) ?trim($data["s"]) : "";
- $error_no = "";
- $user_info = array();
- $result_fields = "*";
- $where = "email='$email'";
- $user_obj = new user_obj();
- $user_info = $user_obj->get_userinfo_bycondition($result_fields,$where,0,1);
- if (is_array($user_info) &&count($user_info)>0){
- if($user_info['is_emailverified'] == 'pend'){
- if($retake_validate == retake_get_validate($user_info["email"],$user_info["created"])){
- $auth_id = encode_user_auth($user_info['id'],$user_info['email'],$user_info['corporation_id'],$auth_pass=0,$user_suffix=0);
- $time = date("Y-m-d H:i:s");
- $fields = array("is_emailverified","modified");
- $value = array("pass",$time);
- $where = "email='$email' and is_emailverified='pend'";
- $modified_rs = $user_obj->modify_user_info($fields,$value,$where,$other_fields,$other_value);
- if($modified_rs){
- }else{
- $error_no = 4;
- }
- }else{
- $error_no = 3;
- }
- }else {
- $error_no = 2;
- }
- }else {
- $error_no = 1;
- }
- $error_message = $this->error_info["user_activation"][$error_no] ?$this->error_info["user_activation"][$error_no] : $lang["activation_success"];
- $result_array = array(
- "error_no"=>$error_no,
- "result"=>$error_message,
- "email"=>$email,
- );
- return $result_array;
- }
- function update_activation($data){
- global $lang,$global_role_info;
- $get = my_get();
- $type = "update";
- $email = isset($data["email"]) ?strtolower(escape_ctrl_char($data["email"])) : "";
- $update_validate = isset($data["s"]) ?trim($data["s"]) : "";
- $auth_str = base64_decode(sys_authcode($update_validate,"DECODE"));
- $auth_arr = explode("|",$auth_str);
- $regcode = $auth_arr[0];
- $sign = $auth_arr[1];
- $expire_time = mktime(date(H),date(i),date(s),date(m)+6,date(d),date(Y));
- $error_no = "";
- $user_info = array();
- $result_fields = "id,role_id,purchased";
- $where = "email='$email'";
- $user_obj = new user_obj();
- $user_info = $user_obj->get_userinfo_bycondition($result_fields,$where,0,1);
- if (is_array($user_info) &&count($user_info)>0){
- if($user_info['role_id'] == $global_role_info['administrator']){
- if($is_register = check_full_register($email,$regcode,strtolower($sign))){
- $time = my_time();
- $fields = array("blocked","purchased","registration_code","is_emailverified","modified","license_type","upgrade_date","expire_date");
- $value = array('1','1',$regcode,'pass',$time,"unlimited",$time,$expire_time);
- $where = "id=".$user_info["id"];
- $update_rs = $this->link["main"]->update_data($this->_utable,$fields,$value,$where,"","",$debug=false);
- $error_no = $update_rs ?'': 4;
- }else{
- $error_no = 3;
- }
- }else {
- $error_no = 2;
- }
- }else {
- $error_no = 1;
- }
- $error_message = $this->error_info["update_activation"][$error_no] ?$this->error_info["update_activation"][$error_no] : $lang["update_success"];
- $result_array = array(
- "error_no"=>$error_no,
- "result"=>$error_message,
- "email"=>$email,
- );
- return $result_array;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement