Saw this in an earlier post by deano(no s):
That would be inaccurate. You would need to obtain the next index value. If the last member that was added was deleted then the next member id would not match the index thus would not be the actual member id that gets assigned to the new account.
You need to go by the index.
How would I get the next index number? My current code uses a random number generator which leaves room for the number to duplicated. Only a clinical provider can add a new Client/Patient member and below is my code for that:
function getBlockCode_AddClient()
{
$aProfiles = $GLOBALS['MySQL']->getPairs("SELECT `ID` , `NickName` FROM `Profiles` WHERE UserType = 'Staff' OR UserType = 'Lead Staff'", 'ID', 'NickName');
$userID = mt_rand(123123123, 999999999);
$aForm = array(
'form_attrs' => array(
'name' => 'form_add_client',
'method' => 'post',
),
'params' => array (
'db' => array(
'table' => 'Profiles', // table name
'key' => 'ID', // key field name
'uri' => '', // uri field name
'uri_title' => '', // title field to generate uri from
'submit_name' => 'submit_add_client_form', // some filed name with non empty value to determine if the for was submitted,
// in most cases it is submit button name
),
'csrf' => array(
'disable' => true, //if it wasn't set or has some other value then CSRF checking is enabled for current form, take a look at sys_security_form_token_enable to disable CSRF checking completely.
)
),
'inputs' => array (
'header1' => array(
'type' => 'block_header',
'caption' => _t("Basic Info"),
),
'ID' => array(
'type' => 'hidden',
'name' => 'ID',
'value' => $userID,
'db' => array (
'pass' => 'Xss',
),
),
'NickName' => array(
'type' => 'text',
'name' => 'NickName',
'value' => $userID,
'info' => 'This number is given to client as username to log in. The password is Password. Please advise them to change their password at their earliest convenience.',
'attrs' => array (
'readonly' => true,
),
'caption' => _t("Client ID"),
'db' => array (
'pass' => 'Xss',
),
),
'FirstName' => array(
'type' => 'text',
'name' => 'FirstName',
'caption' => _t("First Name"),
'attrs' => array (
'autocomplete' => 'off',
),
'checker' => array (
'func' => 'length',
'params' => array(1, 35),
'error' => _t('_sys_adm_form_err_required_field'),
),
'db' => array (
'pass' => 'Xss',
),
),
'LastName' => array(
'type' => 'text',
'name' => 'LastName',
'caption' => _t("Last Name"),
'value' => '',
'checker' => array (
'func' => 'length',
'params' => array(1, 35),
'error' => _t('_sys_adm_form_err_required_field'),
),
'db' => array (
'pass' => 'Xss',
),
),
'Sex' => array(
'type' => 'radio_set',
'name' => 'Sex',
'caption' => _t("Gender"),
'value' => '',
'values' => array (
'Male' => 'Male',
'Female' => 'Female',
),
'checker' => array (
'func' => 'avail',
'error' => _t('_sys_adm_form_err_required_field'),
),
'db' => array (
'pass' => 'Xss',
),
),
'DateOfBirth' => array(
'type' => 'date',
'name' => 'DateOfBirth',
'caption' => _t("Date Of Birth"),
'value' => '',
'checker' => array (
'func' => 'length',
'params' => array(1, 12),
'error' => _t('_sys_adm_form_err_required_field'),
),
'db' => array (
'pass' => 'Xss',
),
),
'Phone' => array(
'type' => 'text',
'name' => 'Phone',
'value' => '',
'caption' => _t("Phone"),
'db' => array (
'pass' => 'Xss',
),
),
'Email' => array(
'type' => 'text',
'name' => 'Email',
'value' => '',
'caption' => _t("Email"),
'db' => array (
'pass' => 'Xss',
),
),
'Comments' => array(
'type' => 'textarea',
'name' => 'Comments',
'value' => '',
'caption' => _t("Comments"),
'db' => array (
'pass' => 'Xss',
),
),
'Provider' => array(
'type' => 'select',
'name' => 'Provider',
'value' => '',
'caption' => _t("Provider"),
'values' => $aProfiles,
'db' => array (
'pass' => 'Xss',
),
),
'Service' => array(
'type' => 'hidden',
'name' => 'Service',
'value' => '',
'caption' => _t("Service Type"),
'values' => array (
'Individual' => 'Individual',
'Couple' => 'Couple',
'Group' => 'Group',
),
'db' => array (
'pass' => 'Xss',
),
),
'ClientStatus' => array(
'type' => 'hidden',
'name' => 'ClientStatus',
'value' => '',
'caption' => _t("Status"),
'values' => array (
'Pending Assignment' => 'Pending Assignment',
'Pending Triage Evaluation' => 'Pending Triage Evaluation',
'Pending Nursing Evaluation' => 'Pending Nursing Evaluation',
'Inpatient (Active)' => 'Inpatient (Active)',
'IOP Patient (Active)' => 'IOP Patient (Active)',
'PHP Patient (Active)' => 'PHP Patient (Active)',
'Awaiting Consult' => 'Awaiting Consult',
'Consult followup' => 'Consult followup',
'Inactive' => 'Inactive',
),
'db' => array (
'pass' => 'Xss',
),
),
'Password' => array(
'type' => 'hidden',
'name' => 'Password',
'caption' => 'Password',
'value' => '697e48bf9a0ee12ea897142800f2759d46ed0512',
'db' => array (
'pass' => 'Xss',
),
),
'Salt' => array(
'type' => 'hidden',
'name' => 'Salt',
'caption' => 'Salt',
'value' => 'yykEY5Gv',
'db' => array (
'pass' => 'Xss',
),
),
'header1_end' => array(
'type' => 'block_end'
),
'header2' => array(
'type' => 'block_header',
'caption' => _t("Referral Info"),
),
'Referral' => array(
'type' => 'radio_set',
'name' => 'Referral',
'caption' => _t("Referred"),
'values' => array (
'Yes' => 'Yes',
'No' => 'No',
),
'db' => array (
'pass' => 'Xss',
),
),
'ReferralSource' => array(
'type' => 'text',
'name' => 'ReferralSource',
'value' => '',
'caption' => _t("Referral Source (Name)"),
'db' => array (
'pass' => 'Xss',
),
),
'ReferralReason' => array(
'type' => 'textarea',
'name' => 'ReferralReason',
'value' => '',
'caption' => _t("Referral Notes"),
'db' => array (
'pass' => 'Xss',
),
),
'InsuranceIssues' => array(
'type' => 'text',
'name' => 'InsuranceIssues',
'value' => '',
'caption' => _t("Insurance Issues"),
'db' => array (
'pass' => 'Xss',
),
),
'header2_end' => array(
'type' => 'block_end'
),
'submit_send' => array(
'type' => 'submit',
'name' => 'submit_add_client_form',
'value' => _t("Add client"),
),
)
);
$oForm = new BxTemplFormView ($aForm);
$oForm->initChecker();
if ($oForm->isSubmittedAndValid ()) {
// add additional vars to database, in this case creation date field is added
$aValsAdd = array (
'status' => 'Active',
);
if ($oForm->insert ($aValsAdd)) {
$NickName = $_POST['NickName'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$time = time();
$When = date("Y-m-d h:i:s", $time);
$Provider = $_POST['Provider'];
$NewClient = mysql_query("INSERT INTO sys_client_list (`ID`, `Profile`, `Check`, `When`, `Services`) VALUES ('$Provider', '$NickName', '1', '$When', 'Individual')");
if ($NewClient) {
$me = $_COOKIE['memberID'];
header("location: viewClients.php?iUser=$me");
}
$wall = mysql_query("INSERT INTO bx_wall_events (owner_id, object_id, type, content, title, description, date) VALUES ('$NickName', '$Provider', 'wall_common_text', '<div class=\"wall-post-text bx-def-font-h2\">New Client Added: $FirstName $LastName</div>', 'New Client Added: $FirstName $LastName', 'New Client Added: $FirstName $LastName', '$time')");
}
}
return array($sStatusText . $oForm->getCode(), array(), array(), false);
}
Any help would be greatly appreciated. Thanks in advance.