Files
CHIEFSOFT\ameye 4842904874 ecsrow
2024-09-23 13:05:54 -04:00

274 lines
11 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Bkosmember extends Bkomember_Controller {
public function userdash() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
$data = $this->bkoUserDashData($_SESSION['bko_selected_id']);
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_userdash', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function listcoupon(){
$data = array();
$data = $this->bkoUserDashData($_SESSION['bko_selected_id']);
if ($_GET){
$data['from_coupon'] = $this->input->get('from_coupon')*100;
$data['to_coupon'] = $this->input->get('to_coupon')*100;
$sql = "SELECT id ,
substring(code,0,4)||'XXXXXXXX' AS code,
amount*0.01 AS amount,
description,
created::date ,
'<div id=\"c_sec'||id||'\"><button type=\"button\" class=\"btn btn-primary btn-sm\" onclick=\"assignCoupon('||id||')\">Assign</button></div>' AS assign
FROM coupons
WHERE active IS NULL
AND amount BETWEEN ".$data['from_coupon']." AND ".$data['to_coupon']."
ORDER BY amount ASC LIMIT 5";
$q = $this->db->query($sql);
echo $this->table->generate( $q);
}
else
{
echo "Wrong Call";
}
}
public function assigncoupon(){
if ($_GET){
$data['coupon_id'] = $this->input->get('coupon_id');
//echo 'ameye olusesan';
$sql1= "SELECT * FROM coupons WHERE id=". $data['coupon_id']." AND status = 0";
$q1 = $this->db->query($sql1);
if ($q1->num_rows()) {
$member_id = $_SESSION['bko_selected_id'];
$couponArr = $q1->result_array();
$code = $couponArr[0]['code'];
$amount = $couponArr[0]['amount'];
$data['action'] = WRENCHBOARD_COUPON_ACTIVATE;
$data['member_id'] = $member_id;
$data['code'] = $code;
$data['amount'] = $amount;
// $data[''] = ;
$this->load->model('backend_model');
$out = array();
$res = $this->backend_model->wrenchboard_api($data, $out);
/*
$sql2 = "INSERT INTO coupons_allocation (member_id,code,amount,status) VALUES ( $member_id, '$code', $amount, ".COUPON_ACTIVE." ) ";
$this->db->query($sql2);
$sql0 = "UPDATE coupons SET active=now(), status=".COUPON_ALLOC_STARTED." WHERE code='".$code."'";
$this->db->query($sql0);
*/
echo "Assigned";
} else {
echo "Fail";
}
/*
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["code"] = rec["code"]; xx["code"].set_valid(true);
xx["amount"] = rec["amount"]; xx["amount"].set_valid(true);
xx["status"] = COUPON_ACTIVE;
res = pgsql_query("SELECT * FROM coupons WHERE code='%s' AND status = 0", in["code"].c_str());
if (res != NULL && pgsql_num_rows(res) > 0) {
map<const char*, const char*>f = pgsql_fetch_assoc(res, 0);
CVars rec;
map_to_cvars(f, rec);
pgsql_exec("UPDATE coupons SET status=%lu WHERE code='%s' AND status=%lu",COUPON_ALLOC_ALLOCATED,in["code"].c_str(),COUPON_ALLOC_STARTED);
// Now We start
CREATE TABLE coupons_allocation (
id SERIAL,
code VARCHAR(15) UNIQUE REFERENCES coupons( code ) NOT NULL,
amount INT DEFAULT 0,
member_id INT REFERENCES members(id) NOT NULL,
added timestamp without time zone DEFAULT now(),
active timestamp DEFAULT NULL,
loc INET,
status INT DEFAULT 0
);
wrenchboard=> SELECT substring(ca.code,0,4)||'XXXXXXXX' as code, ca.amount,m.email,m.firstname FROM coupons_allocation ca LEFT JOIN members m ON m.id=ca.member_id;
code | amount | email | firstname
-------------+--------+----------------------+-----------
1M5XXXXXXXX | 0 | ses66181+1@gmail.com | Olusesan
CVars xx;
xx["member_id"] = in["member_id"]; xx["member_id"].set_valid(true);
xx["code"] = rec["code"]; xx["code"].set_valid(true);
xx["amount"] = rec["amount"]; xx["amount"].set_valid(true);
xx["status"] = COUPON_ACTIVE; xx["status"].set_valid(true);
coupon_id = insert_db_record(DBS_VALID, "coupons_allocation", "coupons_allocation_id_seq", xx);
if (coupon_id > 0 ){
CVars inx;
inx["member_id"] = xx["member_id"]; inx["member_id"].set_valid(true);
inx["coupon_id"] = coupon_id; inx["coupon_id"].set_valid(true);
// mark status on coupon
pgsql_exec("UPDATE coupons SET active=now(), status=%lu WHERE code='%s' AND status=0",COUPON_ALLOC_STARTED,in["code"].c_str());
// send allocation email
*/
}
}
public function usercoupon(){
$data = array();
$data = $this->bkoUserDashData($_SESSION['bko_selected_id']);
//print_r($_SESSION);
$this->load->model('coupons_model');
$data['active_coupons_result'] = $this->coupons_model->loadActiveMemberCoupons($_SESSION['bko_selected_id'], []);
$data['coupons_recent_alloc'] = $this->table->generate($data['active_coupons_result']);
$data['redeem_coupons_result'] = $this->coupons_model->loadRedeemMemberCoupons($_SESSION['bko_selected_id'], []);
$data['coupons_redeem_alloc'] = $this->table->generate($data['redeem_coupons_result']);
$this->secureBkoPage('view_bko_usercoupon',$data);
}
public function mtransfer() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
$data = $this->bkoDashData();
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_dash', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function mpayments() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
$data = $this->bkoDashData();
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_dash', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function mjobsdone() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
$data = $this->bkoDashData();
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_dash', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function mjobposted() {
// $this->load->view('bko/view_bko_header', $data);
$data = array();
$data = $this->bkoDashData();
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_dash', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function escrows(){
// $this->load->view('bko/view_bko_header', $data);
// $actual_link = 'http://'.$_SERVER['HTTP_HOST'].'/bkosmember/escrows';
$actual_link = 'bkosmember/escrows';
// $actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[REQUEST_URI]";
$config = $this->PrepPagination(15, 3,$actual_link );
$actual_link = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://$_SERVER[REQUEST_URI]";
$mysql0 = "SELECT id FROM members_payments WHERE member_id = ".$_SESSION['bko_selected_id']." AND code ='OFDPS' AND confirmation IS NOT NULL AND flags = 4";
$q = $this->db->query($mysql0);
$config["total_rows"] = $q->num_rows();
$this->load->library('pagination');
$this->pagination->initialize($config);
$data["pagination_links"] = $this->pagination->create_links();
$this->load->library('table');
$this->table->set_template($this->template);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$page = is_numeric($page) ? $page : 0;
$mysql = "SELECT p.amount*0.01 AS Reward ,p.currency, j.title, mo.offer_code, m1.email AS Owner, m2.email AS worker,mo.expire::date ,
'<input type=button id=\"dacc\" onclick=\"return refundWallet()\" name=\"refund_wallet\" class=\"btn btn-danger btn-xs\" value=\"RF Wallet\">' AS RefundWallet,
'<input type=button id=\"dacc\" onclick=\"return refundWallet()\" name=\"refund_wallet\" class=\"btn btn-info btn-xs\" value=\"RF Wrench\">' AS RefundWrench
FROM members_payments p
LEFT JOIN members_jobs_offer mo ON mo.payment_id = p.id
LEFT JOIN members_jobs j ON j.id = mo.job_id
LEFT JOIN members m1 ON m1.id = mo.member_id
LEFT JOIN members m2 ON m2.id = mo.client_id
WHERE p.member_id = ".$_SESSION['bko_selected_id']." AND p.code ='OFDPS' AND p.confirmation IS NOT NULL
AND p.flags = 4 AND mo.status = 1
ORDER BY p.id DESC LIMIT " . $config["per_page"] . " OFFSET " . $page;
$query = $this->db->query($mysql);
// $this->table->set_heading('Dates', 'Username', 'Name', 'Status', 'Verify Link', 'Action');
$this->table->function = 'smart_htmlspecialchars';
$data['job_list_table'] = $this->table->generate($query);
$data['page_title'] = "Escrow List";
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_escrow', $data);
$this->load->view('bko/view_bko_footer', $data);
}
public function onesingal() {
// $this->load->view('bko/view_bko_header', $data);
if (!isset($_SESSION['bko_selected_row']) || !is_object($_SESSION['bko_selected_row']) || strlen($_SESSION['bko_selected_row']->uid) < 9) {
die('This method needs error handling: invalid member UID!');
}
$data = array();
$data = $this->bkoDashData();
$data['member_uid'] = $_SESSION['bko_selected_row']->uid;
$data['member_push_text'] = "";
$data['message'] = "";
if ($this->input->post()) {
$this->load->model('backend_model');
$in = array();
$in['member_uid'] = $this->input->post('member_uid');
$in['push_text'] = $this->input->post('member_push_text');
$in['action'] = WRENCHBOARD_BKO_SEND_PUSH;
$out = array();
$res = $this->backend_model->wrenchboard_api($in, $out);
if ($res == PHP_API_OK) {
$data['message'] = "Push notification submitted successfully for delivery";
} else {
$data['message'] = "Failed to submit push notification for delivery";
$data['member_uid'] = $in['member_uid'];
$data['member_push_text'] = $in['push_text'];
}
}
$this->load->view('bko/view_bko_header', $data);
$this->load->view('bko/view_bko_dash_onesignal', $data);
$this->load->view('bko/view_bko_footer', $data);
}
}