Code:
if ($errors_c==0) {
// ADD STUDENTS //
$uc=0;
$grade_ids = '';
$attach_receipt = 0;
for($i=1; $i<=$total_students; $i++) {
if ($this->input->post('fname_'.$i)!="" || $this->input->post('lname_'.$i)!="" || $this->input->post('email_'.$i)!="" || $this->input->post('userid_'.$i)!="" || $this->input->post('passwd_'.$i)!="") {
$userid_new="";
$iterate_mid="";
$course_names="";
$uc++;
$fname=$this->input->post('fname_'.$i);
$lname=$this->input->post('lname_'.$i);
$userid_new=$this->input->post('userid_'.$i);
$email=$this->input->post('email_'.$i);
$passwd=$this->input->post('passwd_'.$i);
if ($this->input->post('userid_'.$i)==$userid) {
$iterate_mid=$this->input->post('mid_'.$i.'_1');
$m_count++;
$data = array(
'fname' => $fname,
'lname' => $lname,
'module_id' => $iterate_mid
);
$this->db->where('id',$uid);
$this->db->update('t_users',$data);
$tmpid=$uid; }
if ($this->input->post('userid_'.$i)!=$userid) {
$passwd = $this->encrypt->encode($passwd);
$data = array(
'userid' => $userid_new,
'company' => $company,
'fname' => $fname,
'lname' => $lname,
'phone' => $phone,
'email' => $email,
'passwd' => $passwd,
'address' => $address,
'address2' => $address2,
'city' => $city,
'state' => $state,
'zip' => $zip,
'region' => $region,
'country' => 'US',
'cert_address' => $cert_address,
'cert_address2' => $cert_address2,
'cert_city' => $cert_city,
'cert_state' => $cert_state,
'cert_zip' => $cert_zip,
'cert_region' => $cert_region,
'cert_country' => '',
'company_id' => $company_id,
'module_id' => $mid,
'register_date' => $mysql_date_now,
'role_admin' => 'f',
'last_activity' => $mysql_date_now
);
$tmpid="";
$this->db->insert('t_users',$data);
$tmpid=$this->db->insert_id();
}
$my_courses_ids[] = $s_courses;
$course_quantity = array_count_values($my_courses_ids);
foreach($my_courses_ids as $course_id) {
if(array_count_values($course_id) > 2) {
}
}
//Add selected courses
for($j=1; $j<5; $j++) {
$iterate_mid="";
$iterate_mid=$this->input->post('mid_'.$i.'_'.$j);
if ($iterate_mid!="1000" && $iterate_mid!="") {
$group_c++;
if ($this->input->post('userid_'.$i)==$userid) {
$this->session->set_userdata('current_module_id',$iterate_mid);
}
$mid=$iterate_mid;
$data = array(
'user_id' => $tmpid,
'module_id' => $mid
);
$this->db->insert('t_user_modules',$data);
$data = array(
'module_id' => $mid
);
$this->db->where('id',$tmpid);
$this->db->update('t_users',$data);
$price="0.00";
$this->db->from('t_modules');
$this->db->where("id", $mid);
$this->db->limit(1);
$query = $this->db->get();
$result = $query->result();
foreach ($result as $r) {
$price=$r->price;
$course_names.=$r->name.",";
}
$data = array(
'user_id' => $tmpid,
'module_id' => $mid,
'total' => $price,
'paid' => '',
'cardtype' => $cardtype,
'bill_email' => $bill_email,
'cardnum' => substr($cardnum, -4),
'po_num' => $po_num,
'po_fname' => $po_fname,
'po_lname' => $po_lname,
'po_email' => $po_email,
'status' => 'Open',
'auth_transactionid' => 0,
'auth_transactionststaus' => '',
'auth_captureamount' => 0,
'auth_refundamount' => 0,
'billto' => $UseCard ? $UseCard : 'C',
);
if($UseCard == 'I') {
$data['billto_status'] = 'Invoice Sent';
if ($CompanyData->is_billed_eom == 1) {
$data['billto_status'] = 'Invoice EOM';
$data['status'] = 'Closed';
}
}
$oid="";
$this->db->set('current_ts', 'NOW()', FALSE);
$this->db->set('order_date', 'NOW()', FALSE);
$this->db->insert('t_orders',$data);
$oid=$this->db->insert_id();
if ($this->input->post('userid_'.$i)==$userid) {
$this->session->set_userdata('ne_order_id',$oid);
}
$data = array(
'user_id' => $tmpid,
'quiz_id' => '20',
'module_id' => $mid,
'grade' => '',
'timer_h' => '0',
'timer_m' => '0',
'timer_s' => '0',
'exam_date' => $mysql_date_now, //'0000-00-00 00:00:00',
'cert_date' => $mysql_date_now, //'0000-00-00 00:00:00',
'certified' => 'f',
'answers' => '',
'order_id' => $oid
);
$current_grade_id="";
$this->db->insert('t_grades',$data);
$current_grade_id=$this->db->insert_id();
$grade_ids .= $current_grade_id.',';
if ($this->input->post('userid_'.$i)==$userid) {
// Set the session values for the Grade id
$this->session->set_userdata('current_grade_id',$current_grade_id);
$this->nativesession->set('current_grade_id',$current_grade_id);
}
$Amount = 0;
$Amount += $price;
if($UseCard != "I"){
if (!$Auth_PaymentProfileID)
{
$this->session->set_flashdata('message', "Could not get the Payment Details for these Orders");
$this->session->set_flashdata('messageClass','bad');
$errors_c = "33";
$errors = "Payment Failed 0";
}
if ($Amount == 0)
{
$this->session->set_flashdata('message', "Orders combined total is 0.00. Cannot process.");
$this->session->set_flashdata('messageClass','bad');
$errors_c = "33";
$errors = "Payment Failed 1";
}
if($errors_c == 0){
$Response = Transaction($Auth_CustomerID, $Auth_PaymentProfileID, $Amount, Array("duplicateWindow" => 0));
if ($Response["Status"] == "Success" )
{
if ($Response["Status"] == "Success")
{
$this->db->where('id', $oid);
$this->db->update('t_orders', Array("card_name" => '', "cardnum" => $CardNum, "expmonth" => '', "expyear" => '', "status"=>"Closed",
"billto_status" => "Payment Processed", "auth_transactionid" => $Auth_TransactionID, "auth_transactionststaus" => "Capture", "paid" => $Amount));
$this->orders_model->closeorder($oid); //changed for credit card success
$this->email_invoice_confirmation($EmailTo, $oid, $Amount);
$this->session->set_flashdata('message', "Orders have been charged and Updated.");
$this->session->set_flashdata('messageClass','good');
} else {
//failure - Update to "Payment Failed"
$this->db->where('id', $oid);
$this->db->update('t_orders', Array("billto_status" => "Payment Failed", "auth_transactionid" => $Auth_TransactionID, "auth_transactionststaus" => "Authorize"));
$errors_c = "33";
$errors = "Payment Failed 2";
$this->session->set_flashdata('message', "Order was authorized but could not be captured: ".$Response["Message"]);
$this->session->set_flashdata('messageClass','bad');
}
} else {
//failure - Update to "Payment Failed"
$this->db->where('id', $oid);
$this->db->update('t_orders', Array("billto_status" => "Payment Failed"));
$errors_c = "33";
$errors = "Payment Failed 3";
$this->session->set_flashdata('message', "Order could not be processed: ".$Response["Message"]);
$this->session->set_flashdata('messageClass','bad');
}
}
}
}
}
// END LOOP THROUGH THE COURSES
}