unable to insert multiple array data from dynamic generated field? - php

I am unable to enter multiple data, it enter only single data. I have tried using for loop and then entering data, using 3 user and 2 task, there is an error previously offset.
public function add($postData)
{
// dd($postData);
$c = count($postData['user_name']);
$t = count($postData['task_name']);
for ($i = 0; $i < $c; $i++) {
$user_name = $postData['user_name'][$i];
$user_email = $postData['user_email'][$i];
$data['insert']['user_name'] = $user_name;
$data['insert']['user_email'] = $user_email;
}
for ($j = 0; $j < $t; $j++) {
$task_name = $postData['task_name'][$j];
$data['insert']['task_name'] = $task_name;
}
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
if ($result == true) {
$response['status'] = 'success';
$response['message'] = 'Project created';
} else {
$response['status'] = 'danger';
$response['message'] = DEFAULT_MESSAGE;
}
return $response;
}

As Per lack of question details attached, I am supposing that you want to insert multiple task entry with project name, description etc.
Here is updated code:
<?php
// dd($postData);
$username = $postData['username'];
$user_email = $postData['user_email'];
$task_name = $postData['task_name'];
foreach ($username as $key => $value) {
$data['insert']['name'] = $postData['name'];
$data['insert']['description'] = $postData['description'];
$data['insert']['customer_name'] = $postData['customer_name'];
$data['insert']['billing_method'] = $postData['billing_method'];
$data['insert']['username'] = $value;
$data['insert']['user_email'] = $user_email[$key];
$data['insert']['task_name'] = $task_name[$key];
$data['insert']['dt_created'] = DT;
$data['table'] = PROJECT;
$result = $this->insertRecord($data);
}

Related

Finicity API Issue

We are using the finicity API to get statements and transaction. We have followed below steps, but we are getting "aggregationStatusCode:185" while fetching the customer accounts [ https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts ].
To get the custommer account I am using https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts.
Then we are fetching statements for account using "https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts/['account_id']/statement?index=1; this loops for 6 times. We need 6 months statement for each account.
Then, we are fetching transaction for account using "https://api.finicity.com/aggregation/v1/customers/['customer_id']/accounts/['account_id']/transactions?fromDate=".$from."&toDate=".strtotime(date('Y-m-d'))."&limit=".$transactionLimit."&includePending=true";
We are facing the below two issues.
1. Getting timeout error, when selecting more than 2 accounts.
2. Getting "aggregationStatusCode:185" for some live accounts.
Below are the code for reference.
function get_statements(){
$FinicityAppToken=$_POST['FinicityAppToken'];
$customerId=$_POST['customerId'];
$leadId=$_POST['leadId'];
$finicityConnectUrl=$_POST['finicityConnectUrl'];
$NoOFStatements = 6;
$transactionLimit = 100;
$transactionsMonth = 1;
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts";
$response=callAPI('POST', $url,false,$FinicityAppToken);
$response = json_decode($response);
$allstatements=array();
if($response){
if(isset($response->accounts)){
$accounts = array();
$array = array();
foreach($response->accounts as $account){
if ($account->aggregationStatusCode == 0 && $account->aggregationSuccessDate != '' && $account->aggregationAttemptDate != '') {
for($i=1;$i<=$NoOFStatements;$i++) {
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts/".$account->id."/statement?index=".$i;
$stateresponse=callAPI('GET', $url,false,$FinicityAppToken);
$temp = array();
$temp['accountId'] = $account->id;
$temp['statement'] = base64_encode($stateresponse);
$statements[]=$temp;
}
$act = array();
$month = date('m') - $transactionsMonth;
$from = strtotime(date('Y').'-'.$month.'-1');
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId."/accounts/".$account->id."/transactions?fromDate=".$from."&toDate=".strtotime(date('Y-m-d'))."&limit=".$transactionLimit."&includePending=true";
$data['url'] = $url;
$transactions = json_decode(callAPI('GET', $url,false,$FinicityAppToken));
$act['account']['accountNumber'] = $account->number;
unset($account->number);
$act['account']['currencySymbol'] = $account->currency;
unset($account->currency);
if(empty((array) $account->detail)) {
$account->detail = (object) transactionsDetailsEmpty();
}
$act['account'] = json_decode(json_encode($account), true);
if(isset($transactions->transactions)) {
$act['transactions'] = $transactions->transactions;
} else {
$act['transactions'] = array();
}
// echo "step";
$accounts[] = $act;
} else {
$data['success'] = 1;
$data['response']=$response ;
$data['finicityConnectUrl'] = $finicityConnectUrl;
$data['leadId'] = $leadId;
$data['FinicityAppToken'] = $FinicityAppToken;
$data['customerId'] = $customerId;
echo json_encode($data);
die();
}
$j++;
}
$array['accounts'] = $accounts;
$array['leadId'] = $leadId;
$data['accounts'] = $array;
$url="https://api.finicity.com/aggregation/v1/customers/".$customerId;
$response=callAPI('DELETE', $url,false,$FinicityAppToken);
}
}
}

Laravel - Import excel keep looping

Dears,
i have an excel file with 5K rows and i'm importing it to my table in the DB successfully.
But the error, when the system finish all the rows, it keeps looping and the page doesn't stop running and not redirecting to my view.
My controller:
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->select('id')->get()->toArray();
if(empty($res)) {
$polic = new policies();
$polic->cust_id = $row['custno'];
$polic->policy = '';
$polic->bord_date = $borddate;
$polic->client_id = $row['clientid'];
$polic->client_no = $row['clientno'];
$polic->client_name = $row['clientname'];
$polic->draft_no = $row['draftno'];
if ($row['status'] == '') {
$polic->status = '';
} else {
$polic->status = $row['status'];
}
$polic->due_date = $duedate;
if ($row['curno'] == 'USD') {
$polic->currency = 1;
} else {
$polic->currency = 0;
}
$polic->amount = $row['amnt'];
$polic->zone = $row['zone'];
$polic->broker_id = $row['brokercode'];
$polic->broker_name = $row['brokername'];
$polic->remarks = $row['remarks'];
$polic->phone = $row['phone'];
$polic->insured_name = $row['insname'];
// $polic->cust_id = $row['valuedate'];
$polic->address = ''; //address
if (trim($row['status']) == 'P') {
$polic->paid_at = date('Y-m-d');
}
$polic->new = 1; //address
$polic->save();
}
else {
//am updating the imported date in the DB
}
what is very strange that in my localhost is working fine, but in digitaloceans cloud, keep looping without redirecting.
Thanks for your help.
I can be because you have 5000 rows to insert and 5000 insert operation consumes lots of memory. What you can try is batch insert operation.
In your policies.php make all fields fillable
protected $fillable=['cust_id ','policy','bord_date','client_id','client_no','client_name ','draft_no','bord_date','status','due_date','currency','amount','zone','broker_id','broker_name','remarks','phone','insured_name','address','paid_at','new'];
And on your excel file import use exists rather than getting collections.
if($request->hasFile('import_file')){
$path = $request->file('import_file')->getRealPath();
$data = \Excel::load($path)->get();
$data=[];
$i=0;
foreach ($data as $key => $row) {
$res = policies::where('phone', '=', $row['phone'])
->where('draft_no', '=', $row['draftno'])
->where('due_date', '=', $duedate)
->exists();
if(!$res) {
$i++;
$data[$i]['cust_id ']=$row['custno'];
$data['policy'] = '';
$data['bord_date'] = $borddate;
$data[$i]['client_id'] = $row['clientid'];
$data[$i]['client_no'] = $row['clientno'];
$data[$i]['client_name'] = $row['clientname'];
$data[$i]['draft_no'] = $row['draftno'];
if ($row['status'] == '') {
$data[$i]['status'] = '';
} else {
$data[$i]['status'] = $row['status'];
}
$data[$i]['due_date'] = $duedate;
if ($row['curno'] == 'USD') {
$data[$i]['currency'] = 1;
} else {
$data[$i]['currency'] = 0;
}
$data[$i]['amount'] = $row['amnt'];
$data[$i]['zone'] = $row['zone'];
$data[$i]['broker_id'] = $row['brokercode'];
$data[$i]['broker_name'] = $row['brokername'];
$data[$i]['remarks'] = $row['remarks'];
$data[$i]['phone'] = $row['phone'];
$data[$i]['insured_name'] = $row['insname'];
// $data[$i]['cust_id'] = $row['valuedate'];
$data[$i]['address'] = ''; //address
if (trim($row['status']) == 'P') {
$data[$i]['paid_at'] = date('Y-m-d');
}
$data[$i]['new'] = 1; //address
}
else {
//am updating the imported date in the DB
}
}
policies::insert($data);

Web scraping publication from a google scholar profile via simplehtmldom PHP

I'm trying to scrape publication from a google scholar profile,but i have no idea how to scrape every publication from a profile, i know the maximum publication the profile page can show is 100 per page from this question :
Google Scholar profile scrape PHP
I just want to know how to apply the url to my php code so that i can get every publication from a profile and insert them to a array
I am able to put every publication in a single page to a array with this code:
<?php
set_time_limit(0);
include 'simple_html_dom.php';
$data = json_decode(file_get_contents('php://input'),true);
$scholarID = $data["gScholarID"];
$kodeDosen = $data["kodeDosen"];
$page = 1;
$offset = ($page - 1)* 100;
$cStart = 0+$offset;
$profile = 'https://scholar.google.com/citations?user='.$scholarID.'&hl=en&cstart='.$cStart.'&view_op=list_works&pagesize=100';
$html = file_get_html($profile);
$table = $html->find('#gsc_a_t',0);
$rowData = array();
foreach($table->find('tr.gsc_a_tr') as $row){
$paperjudul = $row->find('td.gsc_a_t a', 0)->plaintext;
$paper['kodeDosen'] = $kodeDosen;
$paper['judul'] = $paperjudul;
$cited = $row->find('td.gsc_a_c', 0)->plaintext;
if($cited === ''){
$cited = 0;
}
$cited = preg_replace('/[\*]+/', '', $cited);
$paper['citedBy'] = $cited;
$paper['namaJurnal'] = $row->find('td.gsc_a_t .gs_gray', 1)->plaintext;
if($paper['namaJurnal'] === ''){
$paper['namaJurnal'] = 'n/a';
}
$paper['periode'] = $row->find('td.gsc_a_y', 0)->plaintext;
if($paper['periode'] === ' '){
$paper['periode'] = 'n/a';
}
$paper['status'] = 'Published';
$rowData[] = $paper;
}
print_r($rowData);
?>
I just want to know how to apply this code to multiple pages to get all publication from a google scholar profile
I found a method that works, first, i create a loop that searches the web page for an indication that the page has no publication to show and inserts the url that contains the publication which i then loop to scrape the publication within the url.
This is the code that i used:
<?php
set_time_limit(0);
include 'simple_html_dom.php';
include 'connectdb.php';
$scholarID = $_GET["gScholarID"];
$kodeDosen = $_GET["kodeDosen"];
$page = 1;
$finalPage = false;
$sqlTest = 'INSERT INTO tbl_publikasi(kodeDosen,jenis,namaJurnal,judul,status,tipePublikasi,periode,tahun,citedCount) VALUES ';
$response = array();
while (!$finalPage) {
$offset = ($page - 1)* 100;
$cStart = 0+$offset;
$profile = 'https://scholar.google.com/citations?user='.$scholarID.'&hl=en&cstart='.$cStart.'&view_op=list_works&pagesize=100';
$html = file_get_html($profile);
if(is_object($html)){
$empty = $html->find('td.gsc_a_e',0);
if($empty){
$finalPage = true;
unset($html);
}
else{
$urlArray[] = $profile;
$page++;
}
}
else{
$response['success'] = 0;
$response['message'] = "URL tidak valid ";
}
}
if($finalPage){
foreach ($urlArray as $urlPublikasi) {
$html = file_get_html($urlPublikasi);
$table = $html->find('#gsc_a_t',0);
$rowData = array();
if($table){
foreach($table->find('tr.gsc_a_tr') as $row){
$paper['kodeDosen'] = $kodeDosen;
$paperjudul = $row->find('td.gsc_a_t a', 0)->plaintext;
$paper['judul'] = $paperjudul;
$cited = $row->find('td.gsc_a_c', 0)->plaintext;
if($cited === ''){
$cited = 0;
}
$cited = preg_replace('/[\*]+/', '', $cited);
$paper['citedBy'] = trim($cited);
$paper['jenis'] = 'Scholar';
$paper['namaJurnal'] = $row->find('td.gsc_a_t .gs_gray', 1)->plaintext;
if($paper['namaJurnal'] === ''){
$paper['namaJurnal'] = 'n/a';
}
$paper['periode'] = 'n/a';
$paper['tahun'] = $row->find('td.gsc_a_y', 0)->plaintext;
if($paper['tahun'] === ' '){
$paper['tahun'] = '0000';
}
$paper['tipePublikasi'] = 'Scholar';
$paper['status'] = 'Published';
$rowData[] = $paper;
}
foreach ($rowData as $paperValue) {
$judul = $paperValue['judul'];
$jenis = $paperValue['jenis'];
$citedCount = $paperValue['citedBy'];
$namaJurnal = $paperValue['namaJurnal'];
$periode = $paperValue['periode'];
$tahun = $paperValue['tahun'];
$status = $paperValue['status'];
$tipePublikasi = $paperValue['tipePublikasi'];
$sqlTest .= "('".$kodeDosen."','".$jenis."','".$namaJurnal."','".$judul."','".$status."','".$tipePublikasi."','".$periode."','".trim($tahun)."','".$citedCount."'),";
}
$query = rtrim($sqlTest, ',');
$query .= "ON DUPLICATE KEY UPDATE idPublikasi=LAST_INSERT_ID(idPublikasi), kodeDosen = VALUES(kodeDosen), jenis = VALUES(jenis),
namaJurnal=VALUES(namaJurnal),status=VALUES(status),
tipePublikasi = VALUES(tipePublikasi),periode=VALUES(periode),tahun = VALUES(tahun),citedCount = VALUES(citedCount)";
}
else{
$response['success'] = 0;
$response['message'] = "Tabel Publikasi tidak ditemukan ";
}
}
if (mysqli_query($conn, $query)) {
$response['success'] = 1;
$response['message'] = "Array Uploaded Successfully";
}
else {
$response['success'] = 0;
$response['message'] = "Array Upload Failed, Alasan : ".mysqli_error($conn);
}
}
else{
$response['success'] = 0;
$response['message'] = "Gagal ditemukan ";
}
echo json_encode($response);
?>

Undefined variable: error in adding field into db

I'm getting error:Undefined variable: error
in my code:
public function add(){
$this->polls_model->rules = Pf::event()->trigger("filter","polls-adding-validation-rule",$this->polls_model->rules);
$template = null;
$template = Pf::event()->trigger("filter","polls-add-template",$template);
if ($this->request->is_post()){
$data = array();
$data["polls_question"] = $this->post->{"polls_question"};
$data["polls_pubdate"] = str_to_mysqldate($this->post->{"polls_pubdate"},$this->polls_model->elements_value["polls_pubdate"],"Y-m-d H:i:s");
$data["polls_unpubdate"] = str_to_mysqldate($this->post->{"polls_unpubdate"},$this->polls_model->elements_value["polls_unpubdate"],"Y-m-d H:i:s");
if (is_array($this->post->{"polls_status"})){
$data["polls_status"] = implode(",",$this->post->{"polls_status"});
}else{
$data["polls_status"] = $this->post->{"polls_status"};
}
$port_answer = isset($this->post->{"answer"}) ? $this->post->{"answer"} : array();
$data = Pf::event()->trigger("filter","polls-post-data",$data);
$data = Pf::event()->trigger("filter","polls-adding-post-data",$data);
$var = array();
$pollq_multiple_yes = intval($this->post->{'pollq_multiple_yes'});
$data['polls_multiple'] = 0;
if ($pollq_multiple_yes == 1) {
if(intval($this->post->{'pollq_multiple'}) > count($port_answer)){
$data['polls_multiple'] = 1;
}else{
$data['polls_multiple'] = intval($this->post->{'pollq_multiple'});
}
} else {
$data['polls_multiple'] = 1;
}
//debug($data);
Pf::database()->query('START TRANSACTION');
$inserted = $this->polls_model->insert($data);
if($inserted === false){
Pf::database()->query('ROLLBACK');
}else{
$new_id = $this->polls_model->insert_id();
$insert_meta = true;
if(count($port_answer) > 0){
$custom = array();
$int = count($port_answer);
for ($i = 0; $i < $int ; $i++) {
if(!empty($port_answer[$i])){
$custom = array(
'pollsa_qid' => $new_id,
'pollsa_answers' => e($port_answer[$i]),
);
}
$insert_meta = $this->answers_model->insert($custom);
}
if($insert_meta === false){
Pf::database()->query('ROLLBACK');
}else{
Pf::database()->query('COMMIT');
}
}
Pf::database()->query('COMMIT');
}
$errors = Pf::validator()->get_readable_errors(false);
foreach ($errors as $key => $value) {
$error[$key][0] = $errors[$key][0];
}
$this->view->errors = $error; // error here!
$var['content'] = $this->view->fetch($template);
if (count($error) > 0){// and here!!!
$var['error'] = 1;
}else{
Pf::event()->trigger("action","polls-add-successfully",$this->polls_model->insert_id(),$data);
$var['error'] = 0;
$var['url'] = admin_url($this->action.'=index&ajax=&id=&token=');
}
echo json_encode($var);
}else{
$this->view->render($template);
}
}
I edited code, added function code.
This is my add function, if I want add poll with answers.
It gives me this error to my log.
I found this tutorial Undefined Variable error in View
I've googled it but didnt find anything special what helps me out.
Initiate the variable as an array.
because if the $error is empty the compiler will see it as an array.
if not it will get an error.
$error = [];
$errors = Pf::validator()->get_readable_errors(false);
foreach ($errors as $key => $value) {
// $error[$key][0] = $errors[$key][0];
// the right way is below
// i actually dont know what you want to do but this is the right way
// but providing [0] will make it some how constant.
$error[$key] = $errors[$key]
}
$this->view->errors = $error; // error showing here!
$var['content'] = $this->view->fetch($template);
if (count($error) > 0){ // and here???
$var['error'] = 1;
}else{
Pf::event()->trigger("action","polls-add-successfully",$this->polls_model->insert_id(),$data);
$var['error'] = 0;
$var['url'] = admin_url($this->action.'=index&ajax=&id=&token=');
}

Issues with PHP for loop entering names into database

I am using the following code to enter submitted names into the database. The code, when working correctly, should capture the names and other information submitted in the form and create three unique entries in the database. This is not happening. Instead the code is capturing the last name in the three pack and entering its information into the database. You can view the form here beta website. The payment processing script is disabled on the form. What do I need to change in the for loop code to fix this issue? Any assistance is greatly appreciated. Thank you. I have added all of the code that is used in the script below. Hopefully this will give you a better understanding of what is going on in the script.
class DreamModelDream extends JModel {
function getDetails()
{
$session = JFactory::getSession();
if($session->get('dreamticket'))
{
return $session->get('dreamticket');
}
$data = new stdClass();
$data->tickets = -1;
$data->fiftytickets = '';
$data->qty = 0;
$data->fiftyqty = 0;
$data->firstname = '';
$data->firstname2 = '';
$data->firstname3 = '';
$data->lastname = '';
$data->lastname2 = '';
$data->lastname3 = '';
$data->address = '';
$data->address2 = '';
$data->address3 = '';
$data->city = '';
$data->city2 = '';
$data->city3 = '';
$data->postal = '';
$data->postal2 = '';
$data->postal3 = '';
$data->phone = '';
$data->phone2 = '';
$data->phone3 = '';
$data->altphone = '';
$data->altphone2 = '';
$data->altphone3 = '';
$data->email = '';
$data->email2 = '';
$data->email3 = '';
$data->giftname = '';
$data->giftaddress = '';
$data->giftcity = '';
$data->giftpostal = '';
$data->sec_firstname = '';
$data->sec_firstname2 = '';
$data->sec_firstname3 = '';
$data->sec_lastname = '';
$data->sec_lastname2 = '';
$data->sec_lastname3 = '';
$data->agegroup = 0;
$data->expm = 0;
$data->expy = 0;
$data->nameoncard = '';
$data->cctype = '';
$data->ccnum = '';
$data->Media_Radio = false;
$data->Media_TV = false;
$data->Media_Newspaper = false;
$data->Media_Mail = false;
$data->Media_Web = false;
$data->Media_Kinsmen_Member = false;
$data->Media_Other = false;
$data->Radio_CJCY = false;
$data->Radio_MY96 = false;
$data->Radio_ROCK = false;
$data->Radio_CHAT = false;
$data->Radio_POWER = false;
$data->Radio_Other = false;
$data->total = false;
$data->billingphone = '';
$data->agree = 0;
$data->ord_type = 0;
$data->creditcard = '';
$data->user_ip = $_SERVER['REMOTE_ADDR'];
return $data;
}
function getConfirmDetails()
{
$post = JRequest::get('post');
$ticket = new stdClass();
foreach($post as $key => $value)
{
$ticket->$key = $value;
}
$session = JFactory::getSession();
$session->set('dreamticket', $ticket);
if(!strlen($post['firstname'])){
return "Your first name is missing<br>";
}
if(!strlen($post['lastname'])){
return "Your last name is missing<br>";
}
if(!strlen($post['address'])){
return "Your address is missing<br>";
}
if(!strlen($post['city'])){
return "Your city is missing<br>";
}
if(!strlen($post['postal'])){
return "Your postal code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal'])) {
//return "Your postal code is invalid for this province<br>";
}
if(!strlen($post['phone'])){
return "Your phone number is missing<br>";
}
if(!strlen($post['email'])){
return "Your email is missing<br>";
}
if($post['tickets'] == '-1'){
////////// TICKET 2
if(!strlen($post['firstname2'])){
return "Your first2 name is missing<br>";
}
if(!strlen($post['lastname2'])){
return "Your last2 name is missing<br>";
}
if(!strlen($post['address2'])){
return "Your address2 is missing<br>";
}
if(!strlen($post['city2'])){
return "Your city2 is missing<br>";
}
if(!strlen($post['postal2'])){
return "Your postal2 code is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal2'])) {
//return "Your postal2 code is invalid for this province<br>";
}
if(!strlen($post['phone2'])){
return "Your phone number2 is missing<br>";
}
/////////////Ticket 3
if(!strlen($post['firstname3'])){
return "Your first name3 is missing<br>";
}
if(!strlen($post['lastname3'])){
return "Your last name3 is missing<br>";
}
if(!strlen($post['address3'])){
return "Your address3 is missing<br>";
}
if(!strlen($post['city3'])){
return "Your city3 is missing<br>";
}
if(!strlen($post['postal3'])){
return "Your postal code3 is missing<br>";
}
if (!preg_match("/^T\d\w\d\w\d$/i", $post['postal3'])) {
//return "Your postal code3 is invalid for this province<br>";
}
if(!strlen($post['phone3'])){
return "Your phone number3 is missing<br>";
}
}
//////// END TICKET CHECK
if(!strlen($post['nameoncard'])){
return "Your Name on Credit Card is missing<br>";
}
if($post['cctype'] == "Please select one"){
return "Your Credit Card Type is missing<br>";
}
if(!strlen($post['ccnum'])){
return "Your Credit Card Number is missing<br>";
}
if(!strlen($post['billingphone'])){
return "Your billing phone number is missing<br>";
}
if(!strlen($post['agree'])){
return "Your must agree to the Lottery rules in order to proceed<br>";
}
return $ticket;
}
function process()
{
$user = JFactory::getUser();
jimport('joomla.database.table');
$params = JComponentHelper::getParams('com_dream');
$session = JFactory::getSession();
$data = $session->get('dreamticket');
if(!is_object($data))
{
return false;
}
$dif = strtotime("-1 hour");
$timestamp = date("F j, Y, g:i a",$dif);
$ord_id = date('ymdHis') . rand(1000,9999);
$ticket_total = (int) (($data->tickets == '-1') ? '250' : (int) $data->tickets * 100);
$fiftyticket_total = (int) (($data->fiftytickets == '0') ? '' : (int) $data->fiftytickets * 10);
$ordertotal = $ticket_total + $fiftyticket_total;
if(strlen($data->expm) == 1)
{
$data->expm = '0'.$data->expm;
}
if(strlen($data->expy) != 2)
{
$data->expy = substr($data->expy, 2, 2);
}
$data->total = $ordertotal;
JTable::addIncludePath(JPATH_BASE.DS.'administrator'.DS.'components'.DS.'com_dream'.DS.'tables');
$table = JTable::getInstance('Tickets', 'Table');
$table->auth = $auth;
$table->billingphone = $data->billingphone;
$table->Media_Radio = isset($data->Media_Radio) ? 1 : 0;
$table->Media_TV = isset($data->Media_TV) ? 1 : 0;
$table->Media_Newspaper = isset($data->Media_Newspaper) ? 1 : 0;
$table->Media_Mail = isset($data->Media_Mail) ? 1 : 0;
$table->Media_Web = isset($data->Media_Web) ? 1 : 0;
$table->Media_Kinsmen_Member = isset($data->Media_Kinsmen_Member) ? 1 : 0;
$table->Media_Other = isset($data->Media_Other) ? 1 : 0;
$table->Radio_CJCY = isset($data->Radio_CJCY) ? 1 : 0;
$table->Radio_MY96 = isset($data->Radio_MY96) ? 1 : 0;
$table->Radio_ROCK = isset($data->Radio_ROCK) ? 1 : 0;
$table->Radio_CHAT = isset($data->Radio_CHAT) ? 1 : 0;
$table->Radio_POWER = isset($data->Radio_POWER) ? 1 : 0;
$table->Radio_Other = isset($data->Radio_Other) ? 1 : 0;
$table->agegroup = $data->agegroup;
$table->orderdate = date('Y-m-d H:i:s');
$table->ip = $_SERVER['REMOTE_ADDR'];
$table->ord_type = ($user->get('id') > 0) ? 'CallCentre' : 'online';
$table->ord_id = $ord_id;
if($data->tickets == '0') {
$table->ticket_type = 'None';
} elseif($data->tickets == '-1') {
$table->ticket_type = '3Pack';
} elseif($data->tickets == '1') {
$table->ticket_type = '1ticket';
} elseif($data->tickets == '5') {
$table->ticket_type = '8tickets';
}
if($data->fiftytickets == '0') {
$table->fiftyticket_type = 'None';
} elseif($data->fiftytickets == '1') {
$table->fiftyticket_type = '1ticket';
} elseif($data->fiftytickets == '2') {
$table->fiftyticket_type = '3tickets';
}
$table->province = 'AB';
$table->creditcard = $data->cctype;
if(isset($data->giftpurchase)) {
$table->giftname = $data->giftname;
$table->giftadress = $data->giftadress;
$table->giftcity = $data->giftcity;
$table->giftpostal = $data->giftpostal;
}
$data->ord_id = $ord_id;
$tickets = 1;
$table->qty = $data->tickets;
if($data->tickets === '-1')
{
$tickets = 3;
$table->qty = 3;
} elseif($data->tickets === '1')
{
$tickets = 1;
$table->qty = 1;
} elseif($data->tickets === '5')
{
$tickets = 8;
$table->qty = 8;
}
$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;
$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
if($data->tickets === '-1' || $data->tickets === '5')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}
}
$fiftytickets = 1;
$table->fiftyqty = $data->fiftytickets;
if($data->fiftytickets === '1')
{
$fiftytickets = 1;
$table->fiftyqty = 1;
} elseif($data->fiftytickets === '2')
{
$fiftytickets = 3;
$table->fiftyqty = 3;
}
$table->order_total = $data->total;
$table->store();
//sending confirmation mail
$mailcontent = '';
for($i = 0; $i < $data->tickets; $i++)
I have figured out the issues with the for loop. The fiftytickets code needed to be moved above the for loop and the $table->store() function needed to be moved into the for loop and placed after the $table->id line. Now when a ticket or tickets are purchased, three entries with the same name or unique names are inserted into the database.

Categories