function select_or_insert_where() { global $auth_session; global $db; $domain_id = domain_id::get($this->domain_id); if ($this->filter == "date") { $where = "and ap.ac_date between '{$this->start_date}' and '{$this->end_date}'"; } $sql = "SELECT \n pt_id,\n\t\t count(DISTINCT pt_id) as count\n from \n " . TB_PREFIX . "payment_types \n WHERE \n pt_description = :pt_description\n\t\t AND \n\t\t domain_id = :domain_id\n GROUP BY\n pt_id;"; $sth = $db->query($sql, ':pt_description', $this->type, ':domain_id', $domain_id); $pt = $sth->fetch(); if ($pt['count'] == "1") { return $pt['pt_id']; } //add new patmeny type if no Paypal type if ($pt == "") { $new_pt = new payment_type(); $new_pt->pt_description = $this->type; $new_pt->pt_enabled = "1"; $new_pt->insert(); $payment_type = new payment_type(); $payment_type->type = $this->type; $payment_type->domain_id = $domain_id; return $payment_type->select_or_insert_where(); } }
function select_or_insert_where() { $sql = "SELECT \n pt_id,\n\t\t count(DISTINCT pt_id) as count\n FROM \n " . TB_PREFIX . "payment_types \n WHERE \n pt_description = :pt_description\n\t\t AND \n\t\t domain_id = :domain_id\n\t\t {$where}\n GROUP BY\n pt_id;"; $sth = dbQuery($sql, ':pt_description', $this->type, ':domain_id', $this->domain_id); $pt = $sth->fetch(); if ($pt['count'] == "1") { return $pt['pt_id']; } //add new payment type if no Paypal type if ($pt == '') { $new_pt = new payment_type(); $new_pt->pt_description = $this->type; $new_pt->pt_enabled = "1"; $new_pt->insert(); $payment_type = new payment_type(); $payment_type->type = $this->type; $payment_type->domain_id = $this->domain_id; return $payment_type->select_or_insert_where(); } }