/** * Adds an user * * @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded. * @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array * @param array $notifications_data The notifications settings for the new user * @return the new user's ID. */ function user_add($user_row, $cp_data = false, $notifications_data = null) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; global $phpbb_dispatcher, $phpbb_container; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { return false; } $username_clean = utf8_clean_string($user_row['username']); if (empty($username_clean)) { return false; } $sql_ary = array('username' => $user_row['username'], 'username_clean' => $username_clean, 'user_password' => isset($user_row['user_password']) ? $user_row['user_password'] : '', 'user_email' => strtolower($user_row['user_email']), 'user_email_hash' => phpbb_email_hash($user_row['user_email']), 'group_id' => $user_row['group_id'], 'user_type' => $user_row['user_type']); // These are the additional vars able to be specified $additional_vars = array('user_permissions' => '', 'user_timezone' => $config['board_timezone'], 'user_dateformat' => $config['default_dateformat'], 'user_lang' => $config['default_lang'], 'user_style' => (int) $config['default_style'], 'user_actkey' => '', 'user_ip' => '', 'user_regdate' => time(), 'user_passchg' => time(), 'user_options' => 230271, 'user_new' => 0, 'user_inactive_reason' => 0, 'user_inactive_time' => 0, 'user_lastmark' => time(), 'user_lastvisit' => 0, 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, 'user_colour' => '', 'user_avatar' => '', 'user_avatar_type' => '', 'user_avatar_width' => 0, 'user_avatar_height' => 0, 'user_new_privmsg' => 0, 'user_unread_privmsg' => 0, 'user_last_privmsg' => 0, 'user_message_rules' => 0, 'user_full_folder' => PRIVMSGS_NO_BOX, 'user_emailtime' => 0, 'user_notify' => 0, 'user_notify_pm' => 1, 'user_notify_type' => NOTIFY_EMAIL, 'user_allow_pm' => 1, 'user_allow_viewonline' => 1, 'user_allow_viewemail' => 1, 'user_allow_massemail' => 1, 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', 'user_form_salt' => unique_id()); // Now fill the sql array with not required variables foreach ($additional_vars as $key => $default_value) { $sql_ary[$key] = isset($user_row[$key]) ? $user_row[$key] : $default_value; } // Any additional variables in $user_row not covered above? $remaining_vars = array_diff(array_keys($user_row), array_keys($sql_ary)); // Now fill our sql array with the remaining vars if (sizeof($remaining_vars)) { foreach ($remaining_vars as $key) { $sql_ary[$key] = $user_row[$key]; } } /** * Use this event to modify the values to be inserted when a user is added * * @event core.user_add_modify_data * @var array user_row Array of user details submited to user_add * @var array cp_data Array of Custom profile fields submited to user_add * @var array sql_ary Array of data to be inserted when a user is added * @since 3.1.0-a1 * @change 3.1.0-b5 */ $vars = array('user_row', 'cp_data', 'sql_ary'); extract($phpbb_dispatcher->trigger_event('core.user_add_modify_data', compact($vars))); ///archi11 code starts $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $last_user_id = $db->sql_nextid(); // **** CVC-11/22/15 $sql1 = "INSERT INTO " . USER_SUBACCOUNT . " (uid,alias_accout_id) values('" . $user->data['user_id'] . "','" . $last_user_id . "')"; // **** CVC-11/22/15 $db->sql_query($sql1); // **** CVC-11/22/15 $user_id = $db->sql_nextid(); // Insert Custom Profile Fields if ($cp_data !== false && sizeof($cp_data)) { $cp_data['user_id'] = (int) $user_id; $cp = $phpbb_container->get('profilefields.manager'); if (!class_exists('custom_profile')) { // **** CVC-11/22/15 include_once $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx; // **** CVC-11/22/15 } // **** CVC-11/22/15 $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', custom_profile::build_insert_sql_array($cp_data)); // **** CVC-11/22/15 //$db->sql_build_array('INSERT', $cp->build_insert_sql_array($cp_data)); $db->sql_query($sql); } // Place into appropriate group... $sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => (int) $user_id, 'group_id' => (int) $user_row['group_id'], 'user_pending' => 0)); $db->sql_query($sql); // Now make it the users default group... group_set_user_default($user_row['group_id'], array($user_id), false); // Add to newly registered users group if user_new is 1 if ($config['new_member_post_limit'] && $sql_ary['user_new']) { $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\tWHERE group_name = 'NEWLY_REGISTERED'\n\t\t\t\tAND group_type = " . GROUP_SPECIAL; $result = $db->sql_query($sql); $add_group_id = (int) $db->sql_fetchfield('group_id'); $db->sql_freeresult($result); if ($add_group_id) { global $phpbb_log; // Because these actions only fill the log unneccessarily we skip the add_log() entry. $phpbb_log->disable('admin'); // Add user to "newly registered users" group and set to default group if admin specified so. if ($config['new_member_group_default']) { group_user_add($add_group_id, $user_id, false, false, true); $user_row['group_id'] = $add_group_id; } else { group_user_add($add_group_id, $user_id); } $phpbb_log->enable('admin'); } } // set the newest user and adjust the user count if the user is a normal user and no activation mail is sent if ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_FOUNDER) { set_config('newest_user_id', $user_id, true); set_config('newest_username', $user_row['username'], true); set_config_count('num_users', 1, true); $sql = 'SELECT group_colour FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . (int) $user_row['group_id']; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); set_config('newest_user_colour', $row['group_colour'], true); } // Use default notifications settings if notifications_data is not set if ($notifications_data === null) { $notifications_data = array(array('item_type' => 'notification.type.post', 'method' => 'notification.method.email'), array('item_type' => 'notification.type.topic', 'method' => 'notification.method.email')); } // Subscribe user to notifications if necessary if (!empty($notifications_data)) { $phpbb_notifications = $phpbb_container->get('notification_manager'); foreach ($notifications_data as $subscription) { $phpbb_notifications->add_subscription($subscription['item_type'], 0, $subscription['method'], $user_id); } } /** * Event that returns user id, user detals and user CPF of newly registared user * * @event core.user_add_after * @var int user_id User id of newly registared user * @var array user_row Array of user details submited to user_add * @var array cp_data Array of Custom profile fields submited to user_add * @since 3.1.0-b5 */ $vars = array('user_id', 'user_row', 'cp_data'); extract($phpbb_dispatcher->trigger_event('core.user_add_after', compact($vars))); return $user_id; }
/** * Adds an user * * @param mixed $user_row An array containing the following keys (and the appropriate values): username, group_id (the group to place the user in), user_email and the user_type(usually 0). Additional entries not overridden by defaults will be forwarded. * @param string $cp_data custom profile fields, see custom_profile::build_insert_sql_array * @return the new user's ID. */ function user_add($user_row, $cp_data = false) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { return false; } $username_clean = utf8_clean_string($user_row['username']); if (empty($username_clean)) { return false; } $sql_ary = array('username' => $user_row['username'], 'username_clean' => $username_clean, 'user_password' => isset($user_row['user_password']) ? $user_row['user_password'] : '', 'user_pass_convert' => 0, 'user_email' => strtolower($user_row['user_email']), 'user_email_hash' => crc32(strtolower($user_row['user_email'])) . strlen($user_row['user_email']), 'group_id' => $user_row['group_id'], 'user_type' => $user_row['user_type']); // These are the additional vars able to be specified $additional_vars = array('user_permissions' => '', 'user_timezone' => $config['board_timezone'], 'user_dateformat' => $config['default_dateformat'], 'user_lang' => $config['default_lang'], 'user_style' => (int) $config['default_style'], 'user_actkey' => '', 'user_ip' => '', 'user_regdate' => time(), 'user_passchg' => time(), 'user_options' => 895, 'user_inactive_reason' => 0, 'user_inactive_time' => 0, 'user_lastmark' => time(), 'user_lastvisit' => 0, 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, 'user_dst' => (int) $config['board_dst'], 'user_colour' => '', 'user_occ' => '', 'user_interests' => '', 'user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0, 'user_new_privmsg' => 0, 'user_unread_privmsg' => 0, 'user_last_privmsg' => 0, 'user_message_rules' => 0, 'user_full_folder' => PRIVMSGS_NO_BOX, 'user_emailtime' => 0, 'user_notify' => 0, 'user_notify_pm' => 1, 'user_notify_type' => NOTIFY_EMAIL, 'user_allow_pm' => 1, 'user_allow_viewonline' => 1, 'user_allow_viewemail' => 1, 'user_allow_massemail' => 1, 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '', 'user_form_salt' => unique_id()); // Now fill the sql array with not required variables foreach ($additional_vars as $key => $default_value) { $sql_ary[$key] = isset($user_row[$key]) ? $user_row[$key] : $default_value; } // Any additional variables in $user_row not covered above? $remaining_vars = array_diff(array_keys($user_row), array_keys($sql_ary)); // Now fill our sql array with the remaining vars if (sizeof($remaining_vars)) { foreach ($remaining_vars as $key) { $sql_ary[$key] = $user_row[$key]; } } $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $user_id = $db->sql_nextid(); // Insert Custom Profile Fields if ($cp_data !== false && sizeof($cp_data)) { $cp_data['user_id'] = (int) $user_id; if (!class_exists('custom_profile')) { include_once $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx; } $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', custom_profile::build_insert_sql_array($cp_data)); $db->sql_query($sql); } // Place into appropriate group... $sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => (int) $user_id, 'group_id' => (int) $user_row['group_id'], 'user_pending' => 0)); $db->sql_query($sql); // Now make it the users default group... group_set_user_default($user_row['group_id'], array($user_id), false); // set the newest user and adjust the user count if the user is a normal user and no activation mail is sent if ($user_row['user_type'] == USER_NORMAL) { set_config('newest_user_id', $user_id, true); set_config('newest_username', $user_row['username'], true); set_config('num_users', $config['num_users'] + 1, true); $sql = 'SELECT group_colour FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . (int) $user_row['group_id']; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); set_config('newest_user_colour', $row['group_colour'], true); } return $user_id; }
/** * Add User */ function user_add($user_row, $cp_data = false) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { return false; } $sql_ary = array('username' => $user_row['username'], 'user_password' => isset($user_row['user_password']) ? $user_row['user_password'] : '', 'user_email' => $user_row['user_email'], 'user_email_hash' => (int) crc32(strtolower($user_row['user_email'])) . strlen($user_row['user_email']), 'group_id' => $user_row['group_id'], 'user_type' => $user_row['user_type']); // These are the additional vars able to be specified $additional_vars = array('user_permissions' => '', 'user_timezone' => 0, 'user_dateformat' => $config['default_dateformat'], 'user_lang' => $config['default_lang'], 'user_style' => $config['default_style'], 'user_allow_pm' => 1, 'user_actkey' => '', 'user_ip' => '', 'user_regdate' => time(), 'user_lastmark' => time(), 'user_lastvisit' => 0, 'user_lastpost_time' => 0, 'user_lastpage' => '', 'user_posts' => 0, 'user_dst' => 0, 'user_colour' => '', 'user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0, 'user_new_privmsg' => 0, 'user_unread_privmsg' => 0, 'user_last_privmsg' => 0, 'user_message_rules' => 0, 'user_full_folder' => PRIVMSGS_NO_BOX, 'user_emailtime' => 0, 'user_notify' => 0, 'user_notify_pm' => 1, 'user_notify_type' => NOTIFY_EMAIL, 'user_allow_pm' => 1, 'user_allow_email' => 1, 'user_allow_viewonline' => 1, 'user_allow_viewemail' => 1, 'user_allow_massemail' => 1, 'user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => 0); // Now fill the sql array with not required variables foreach ($additional_vars as $key => $default_value) { $sql_ary[$key] = isset($user_row[$key]) ? $user_row[$key] : $default_value; } // Any additional variables in $user_row not covered above? $remaining_vars = array_diff(array_keys($user_row), array_keys($sql_ary)); // Now fill our sql array with the remaining vars if (sizeof($remaining_vars)) { foreach ($remaining_vars as $key) { $sql_ary[$key] = $user_row[$key]; } } $db->sql_transaction('begin'); $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $user_id = $db->sql_nextid(); // Insert Custom Profile Fields if ($cp_data !== false && sizeof($cp_data)) { $cp_data['user_id'] = (int) $user_id; if (!class_exists('custom_profile')) { include_once $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx; } $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', custom_profile::build_insert_sql_array($cp_data)); $db->sql_query($sql); } // Place into appropriate group... $sql = 'INSERT INTO ' . USER_GROUP_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => (int) $user_id, 'group_id' => (int) $user_row['group_id'], 'user_pending' => 0)); $db->sql_query($sql); $db->sql_transaction('commit'); return $user_id; }