I am modifying a system, where I need to add error log on registration failures when existing e-mail found, existing National Identity card(NIC) found and in captcha failures. To insert error log records, going to use the table z_error_log. I think this need to be done in the “else” part of the Vendor_cont.php file. Currently this provides an error messgae if an existing e-mail is used. I need to send that error log to the db. This is the code and I really appreciate your help as I am getting stuck on this point. Thanks in advance.
=====Vendor_cont.php file=======
public function register_vendor(){
//require('recaptcha-master/src/autoload.php');
if (!empty($_POST['register'] ))
{
$business_type=$this->CModel->filter_input($_POST['business_type']);
$business_name=$this->CModel->filter_input($_POST['business_name']);
$street=$this->CModel->filter_input($_POST['street']);
$street_line2=$this->CModel->filter_input($_POST['street_line2']);
$city=$this->CModel->filter_input($_POST['city']);
$state=$this->CModel->filter_input($_POST['state']);
$country=$this->CModel->filter_input($_POST['country']);
$phone=$this->CModel->filter_input($_POST['phone']);
$email=$this->CModel->filter_input($_POST['email']);
$nic=$this->CModel->filter_input($_POST['nic']);
$website=$this->CModel->filter_input($_POST['website']);
$business_reg_no=$this->CModel->filter_input($_POST['business_reg_no']);
$business_reg_authority=$this->CModel->filter_input($_POST['business_reg_authority']);
$value_of_proc_of_interest_rad=$_POST['val_of_bsns_interest'];
switch ($value_of_proc_of_interest_rad) {
case '1':
$value_of_proc_of_interest=$this->CModel->parseToNumber($_POST['val_of_bsns_1']);
break;
case '2':
$value_of_proc_of_interest=$this->CModel->parseToNumber($_POST['val_of_bsns_1_1']).'-'.$this->CModel->parseToNumber($_POST['val_of_bsns_1_2']);
break;
case '3':
$value_of_proc_of_interest=$this->CModel->parseToNumber($_POST['val_of_bsns_3']);
break;
default:
$value_of_proc_of_interest=$this->CModel->parseToNumber($_POST['val_of_bsns_1']);
}
$nature_of_the_bsns=$_POST['nature_of_the_bsns'];
//$password_row=substr(str_shuffle(MD5(microtime())), 0, 10);
$password_row= $this->CModel->randomPassword(); // 12345678;
$password= password_hash($password_row, PASSWORD_BCRYPT, array('cost'=>10));
if (isset($_POST['g-recaptcha-response'])) // validate
{
$captcha = $_POST['g-recaptcha-response'];
$secretKey = "6Lde3mwUAAAAACFpPEDmddGyOTqhGTnowwz5hmRE";
$ip = $_SERVER['REMOTE_ADDR'];
$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secretKey) . '&response=' . urlencode($captcha);
$response = file_get_contents($url);
$responseKeys = json_decode($response,true);
if($responseKeys['success']){
if(EMPTY( $checked_nic= $this->CModel->check_email($email) )){
if(EMPTY( $this->CModel->check_nic($nic) )){
$userData = array(
'user_role'=>'2',
'email' => $email,
'nic' => $nic,
'password' =>$password,
'payment' =>0,
'reg_date' =>date('Y-m-d H:i:s')
);
if ($inserted_user_id= $this->CModel->add_payment_user($userData)){
$this->LModel->createLog( $inserted_user_id,$inserted_user_id,'Vendor_cont/register_vendor- add main user',$userData,$_SERVER['PHP_SELF']); //create log
$number_type = 'V';
$group_label = 'VENDOR';
$autoNumberData = array(
'number_type' => $number_type,
'group_label' => $group_label
);
if ($inserted_auto_number_id = $this->CModel->add_auto_number($autoNumberData)) {
$this->LModel->createLog($inserted_auto_number_id, $inserted_auto_number_id, 'Vendor_cont/register_vendor- add auto number', $autoNumberData, $_SERVER['PHP_SELF']); //create log
while (strlen($inserted_auto_number_id) < 6) {
$inserted_auto_number_id = "0" . $inserted_auto_number_id;
}
$registration_no = $number_type . $inserted_auto_number_id;
$venData = array(
'user_id'=>$inserted_user_id,
'registration_no' => $registration_no,
'business_type'=>$business_type,
'business_name'=>$business_name,
'street' => $street,
'street_line2' => $street_line2,
'city' => $city,
'state' => $state,
'country' => $country,
'phone' => $phone,
'website' => $website,
'business_reg_no' => $business_reg_no,
'business_reg_authority' => $business_reg_authority,
'value_of_proc_of_interest_rad_value' => $value_of_proc_of_interest_rad,
'value_of_proc_of_interest' => $value_of_proc_of_interest
);
if ($inserted_id= $this->VModel->add_ven($venData)){
$this->LModel->createLog( $inserted_id,$inserted_user_id,'Vendor_cont/register_vendor- add vendor',$venData,$_SERVER['PHP_SELF']); //create log
//add vendor_nature_of_bsns
foreach($nature_of_the_bsns as $nb){
$aData = array(
'user_id' =>$inserted_user_id,
'nature_of_bsns_id' => $nb
);
$inserted_V=$this->VModel->add_vendor_nature_of_the_bsns($aData);
$this->LModel->createLog( $inserted_V,$inserted_user_id,'Vendor_cont/register_vendor- add_vendor_nature_of_the_bsns',$aData,$_SERVER['PHP_SELF']); //create log
}
if(isset($_POST['dist_arr'])){
$interested_bsns_areas_dists=$_POST['dist_arr'];
$array_dist = explode(',', $interested_bsns_areas_dists);
if($interested_bsns_areas_dists !=''){
//save all districts
foreach($array_dist as $ibad){
$aData = array(
'user_id' =>$inserted_user_id,
'district_city_id' => $ibad,
'flag1'=>1
);
$inserted_V=$this->VModel->add_vendor_interested_bsns_areas($aData);
$this->LModel->createLog( $inserted_V,$inserted_user_id,'Vendor_cont/register_vendor/add_vendor_interested_bsns_areas',$aData,$_SERVER['PHP_SELF']); //create log
}
}
}
if(isset($_POST['city_arr'])){
$interested_bsns_areas_cities=$_POST['city_arr'];
$array_city = explode(',', $interested_bsns_areas_cities);
if($interested_bsns_areas_cities !=''){
foreach($array_city as $ibad){
$aData = array(
'user_id' =>$inserted_user_id,
'district_city_id' => $ibad,
'flag1'=>2
);
//check whether this city's distrcit has saved. if it is skip that city. else save
$checked_state= $this->CModel->check_cities_district_saved($ibad,$inserted_user_id);
if($checked_state){
$inserted_V=$this->VModel->add_vendor_interested_bsns_areas($aData);
$this->LModel->createLog( $inserted_V,$inserted_user_id,'Vendor_cont/register_vendor/add_vendor_interested_bsns_areas',$aData,$_SERVER['PHP_SELF']); //create log
}
}
}
}
//upload documents
$upload_path='uploads/vendor_documents/';
// Count total files
$countfiles = count($_FILES['file_input']['name']);
// Looping all files
for($i=0;$i<$countfiles;$i++){
//$filename = $_FILES['file']['name'][$i];
$temp = explode(".", $_FILES["file_input"]["name"][$i]);
$newfilename = uniqid().round(microtime(true)) . '.' . end($temp);
move_uploaded_file($_FILES['file_input']['tmp_name'][$i],$upload_path.$newfilename);
//insert in to the table
$aData = array(
'related_id' =>$inserted_user_id,
'name' => $upload_path.$newfilename ,
'doc_type_main'=>1,
'doc_name'=>$this->CModel->filter_input($_POST["file_name"][$i])
);
$inserted_doc_id=$this->CModel->insert_document($aData);
$this->LModel->createLog( $inserted_doc_id,$inserted_user_id,'Vendor_cont/register_vendor-insert_document',$aData,$_SERVER['PHP_SELF']); //create log
}
//$this->LModel->createLog( $inserted_id,$inserted_user_id,'Vendor_cont/register_vendor-POST',$_POST,$_SERVER['PHP_SELF']); //create log
// $_SESSION['Smessages'] = '<h3> Thank you very much for registration as a Vendors with System . Please check your email given in your application for official acknowledgement and password generated by the system.
// You may please login to the System using the password input the information requested.
// ! </h3>';
//send mail that use login to pay
$mail_sub='Temporary Login Details ';
$mail_body=" "; //content of the body
if( $this->mailModel->send_mail($email,$mail_sub,$mail_body)){
$status=1;
}else{
$status=0;
}
$this->LModel->mail_log($inserted_user_id, $mail_body,"User Password",__METHOD__,$status,$email); //create log
$_SESSION['Smessages'] = 'Registration Success. Pay the Registration fee to continue';
header("Location:".ROOT_URL."?p=payment_cont&a=vendor_reg_fee&id=".$this->CModel->encode($inserted_user_id));
die();
} else{
$_SESSION['Emessages'] = 'An error has occurred! Please try again later.'; //set Error message
}
} else {
$_SESSION['Emessages'] = 'An error has occurred! Please try again later.'; //set Error message
}
}else{
$_SESSION['Emessages'] = 'An error has occurred during user registration! Please try again later.'; //set Error message
}
}
}else{
//check whether paid fee or not
$paid= $this->UserModel->get_user_data($checked_nic->user_id);
if($paid->payment =='0'){
//didnt pay.
$_SESSION['Smessages'] = 'Registration Success. Pay the Registration fee to continue';
header("Location:".ROOT_URL."?p=payment_cont&a=vendor_reg_fee&id=".$this->CModel->encode($checked_nic->user_id));
}
if($paid->confirmed =='0' && $paid->payment =='1'){
//didnt pay.
$_SESSION['Emessages'] = 'Your information has been received.
e-Gp system administrator will check your registration documents and will send you a new login credentials to your given email.';
}
if(($paid->confirmed =='1' && $paid->payment =='1') || $paid->payment =='2'){
//didnt pay.
$_SESSION['Emessages'] = ' Given E-mail already exists in the System. ';
}
}
} else {
$_SESSION['Emessages'] = 'Recaptcha Failed. Please try again later';
// $this->LModel->createErrorLog(0,'Vendor_cont/register_vendor/recaptcha_fail',$responseKeys['success'],$_POST); //create log
}
}else{
$_SESSION['Emessages'] = 'Captcha Required';
}
}
$this->oUtil->business_type=$this->CModel->getData('z_vendor_bsns_type','1=1','name');
$this->oUtil->business_reg_au=$this->CModel->getData('z_business_reg_au','1=1','name');
$this->oUtil->nature_of_the_bsns=$this->CModel->getData('z_nature_of_the_business','1=1','name');
$this->oUtil->interested_bsns_areas=$this->CModel->getData('z_districts','1=1','name_en');
$this->oUtil->cities=$this->CModel->getData('z_cities','1=1','name_en');
$this->oUtil->provinces=$this->CModel->getData('z_provinces','1=1','name_en');
$this->oUtil->countries=$this->CModel->getData('z_countries','1=1','country_name');
$this->oUtil->form_type='insert';
$max_file_size_data=$this->CModel->get_variable_value('validation_file_size');
$this->oUtil->max_file_size=$max_file_size_data->value;
$this->oUtil->getView('vendor/frm_register_vendor');
}
========Log_model.php============
public function createErrorLog($user,$function,$error_data,$data){
$ip=$_SERVER['REMOTE_ADDR'];
$browser_os= $_SERVER['HTTP_USER_AGENT'];
$data= (array) $data_obj;
//print_r($data);
if (is_array($data)) {
$val = '(' . implode(',', array_keys($data)) . ')';
$val .= '=(' . implode(',', $data) . ')';
} else {
$val = $data;
}
$oStmt= $this->oDb->prepare('INSERT INTO z_error_log (`row_id`,`user`,`ip`,`page`,`function`,`data`,`browser_os`) VALUES (:row_id,:user,:ip,:page,:function,:data,:browser_os)');
$oStmt->bindParam(':row_id', $row_id, \PDO::PARAM_INT);
$oStmt->bindParam(':user', $user, \PDO::PARAM_INT);
$oStmt->bindParam(':ip', $ip, \PDO::PARAM_STR);
$oStmt->bindParam(':page', $page1, \PDO::PARAM_STR);
$oStmt->bindParam(':function', $page_url, \PDO::PARAM_STR);
$oStmt->bindParam(':data', $val, \PDO::PARAM_STR);
$oStmt->bindParam(':browser_os', $browser_os, \PDO::PARAM_STR);
$oStmt->execute();
return $this->oDb->lastInsertId();
}