Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function savePFSettings($pf)
- {
- $s1 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Profit Frequency"), array("value"), array($pf[0]));
- $s2 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Percentage Profit"), array("value"), array($pf[1]));
- $s3 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Payment Window Time"), array("value"), array($pf[2]));
- return ($s1 && $s2 && $s3);
- }
- public function members()
- {
- $allmenbers = array();
- $members = $this->db->Select($this->db->MembersTable, NULL, array("activated"), array("Yes"));
- if(is_array($members))
- {
- foreach($members as $m){
- $allmenbers[$m["member_id"]] = $m;
- }
- }
- return $allmenbers;
- }
- public function postTestimony($mid, $testimony)
- {
- $db = new DB();
- if($db->Insert($db->TestimoniesTable, array("member_id", "testimony","approved", "date"), array($mid, $testimony, "No", date("Y-m-d H:i:s"))))
- return true;
- return false;
- }
- public function getTestimony()
- {
- $db = new DB();
- return $db->SelectX("SELECT * FROM " . $db->TestimoniesTable . " WHERE approved='Yes' ");
- }
- public function getTestimonies($type)
- {
- $db = new DB();
- return $db->SelectX("SELECT m.name,m.phone, t.* FROM " . $db->TestimoniesTable . " t INNER JOIN ".$db->MembersTable .
- " m ON t.member_id=m.member_id WHERE t.approved='$type' ORDER BY t.date DESC");
- }
- public function approveTestimony($tid)
- {
- return $this->db->Update($this->db->TestimoniesTable, array("testimony_id"), array($tid), array("approved"), array("Yes"));
- }
- public function getNews()
- {
- $db = new DB();
- return $db->SelectX("SELECT * FROM " . $db->NewsTable . " ORDER BY news_id DESC");
- }
- public function deleteTestimony($tid)
- {
- $db = new DB();
- return $db->Delete($db->TestimoniesTable, array("testimony_id"), array($tid));
- }
- public function evidenceSavedBefore($phmid)
- {
- $db = new DB();
- $check = $db->Select($db->PaymentsTable, NULL, array("phmid"), array($phmid));
- return is_array($check);
- }
- public function savePaymentEvidence($phmid)
- {
- $db = new DB();
- $pay = $db->Select($db->PHMatchingTable, NULL, array("phmid"), array($phmid));
- if(is_array($pay))
- {
- $pay = $pay[0];
- return $db->Insert($db->PaymentsTable, NULL, array(NULL,$pay["phid"], $pay["payer_id"],$phmid,$pay["receiver_id"],$pay["amount"],
- date("Y-m-d H:i:s"), '../member/payments/' . $phmid . '.jpg', 'Not Confirmed'));
- }
- return false;
- }
- public function getPaymentEvidence()
- {
- $db = new DB();
- $pevidence = $db->Select($db->PaymentEvidenceTable);
- $evidenceData = array();
- if(is_array($pevidence))
- {
- foreach($pevidence as $pe)
- {
- $evidenceData[$pe["type"].$pe["ref_number"]] = $pe;
- }
- }
- return $evidenceData;
- }
- public function getVIPPaymentEvidence()
- {
- $pevidence = $this->db->SelectX("SELECT * FROM " . $this->db->PaymentsTable . " WHERE status='Not Confirmed' AND receiver_id>100000000");
- $evidenceData = array();
- if(is_array($pevidence))
- {
- foreach($pevidence as $pe)
- {
- $evidenceData[$pe["phmid"]] = $pe;
- }
- }
- return $evidenceData;
- }
- public function confirmPH($phid)
- {
- $phMatchings = $this->db->Select($this->db->PHMatchingTable, NULL, array("phid"),array($phid));
- foreach($phMatchings as $phm)
- {
- if($phm["status"] != "Confirmed")
- return false;
- }
- $this->db->Update($this->db->PHTable, array("phid"), array($phid), array("status"), array("Confirmed"));
- return true;
- }
- public function confirmPayment($phmid)
- {
- $matching = $this->db->Select($this->db->PHMatchingTable, NULL, array("phmid"),array($phmid));
- if(is_array($matching))
- {
- $matching = $matching[0];
- if($this->db->Update($this->db->PaymentsTable, array("phmid"), array($phmid), array("status"), array("Confirmed")))
- {
- if($this->db->Update($this->db->PHMatchingTable, array("phmid"), array($phmid), array("status"), array("Confirmed")))
- {
- $ghid = $matching["ghid"];
- $gh = $this->db->Select($this->db->GHTable, NULL, array("ghid"),array($ghid));
- if($gh[0]["amount"] == $matching["amount"])
- {
- if($this->db->Update($this->db->GHTable, array("ghid"), array($ghid), array("status"), array("Confirmed")))
- {
- $this->confirmPH($matching["phid"]);
- return true;
- }
- }
- else
- {
- $this->confirmPH($matching["phid"]);
- return true;
- }
- }
- //reverse the process
- $this->db->Update($this->db->PaymentsTable, array("phmid"), array($phmid), array("status"), array("Not Confirmed"));
- $this->db->Update($this->db->PHMatchingTable, array("phmid"), array($phmid), array("status"), array("Pending"));
- }
- }
- return false;
- }
- public function getVerification($filter)
- {
- $db = new DB();
- $verData = array();
- if($filter == "")
- {
- $verData = $db->SelectX("SELECT v.member_id,m.name,v.ple,v.poa,v.kyc,v.date_uploaded,v.date_verified,v.verified FROM " .
- $db->VerifiedMembersTable . " v INNER JOIN $db->MembersTable m ON v.member_id=m.member_id ORDER BY v.verified");
- }
- else
- {
- $verData = $db->SelectX("SELECT v.member_id,m.name, v.ple, v.poa, v.kyc, v.date_uploaded, v.date_verified, v.verified FROM $db->VerifiedMembersTable v
- INNER JOIN $db->MembersTable m ON v.member_id=m.member_id WHERE v.verified='$filter' ORDER BY v.verified");
- }
- return $verData;
- }
- public function getTransaction($mid)
- {
- return $this->db->SelectX("SELECT * FROM " . $this->db->PaymentsTable . " WHERE (payer_id='$mid' OR receiver_id='$mid') AND `status`='Confirmed'");
- }
- public function getSettings($settings)
- {
- return $this->db->getRowData($this->db->SettingsTable, "settings", $settings, "value");
- }
- public function sendMail($receivers, $subject, $message)
- {
- date_default_timezone_set('Etc/UTC');
- //Create a new PHPMailer instance
- $mail = new PHPMailer;
- //Tell PHPMailer to use SMTP
- $mail->isSMTP();
- //Enable SMTP debugging
- // 0 = off (for production use)
- // 1 = client messages
- // 2 = client and server messages
- $mail->SMTPDebug = 0;
- //Ask for HTML-friendly debug output
- $mail->Debugoutput = 'html';
- //Set the hostname of the mail server
- $mail->Host = 'smtp.gmail.com';
- // use
- // $mail->Host = gethostbyname('smtp.gmail.com');
- // if your network does not support SMTP over IPv6
- //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
- $mail->Port = 587;
- //Set the encryption system to use - ssl (deprecated) or tls
- $mail->SMTPSecure = 'tls';
- //Whether to use SMTP authentication
- $mail->SMTPAuth = true;
- //Username to use for SMTP authentication - use full email address for gmail
- $mail->Username = "noreplyback2017.com@gmail.com";
- //Password to use for SMTP authentication
- $mail->Password = "noreply100%";
- //Set who the message is to be sent from
- $mail->setFrom('noreplyback2017.com@gmail.com', 'Xtraearners');
- //Set an alternative reply-to address
- $mail->addReplyTo('noreplyback2017.com@gmail.com', 'Xtraearners');
- //Set who the message is to be sent to
- $receiver = explode(":", $receivers);
- $mail->addAddress($receiver[0], $receiver[1]);
- //Set the subject line
- $mail->Subject = $subject;// 'PHPMailer GMail SMTP test';
- //Read an HTML message body from an external file, convert referenced images to embedded,
- //convert HTML into a basic plain-text alternative body
- //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
- $mail->msgHTML($message, dirname(__FILE__));
- //Replace the plain text body with one created manually
- //$mail->AltBody = $message;// 'This is a plain-text message body';
- //Attach an image file
- //$mail->addAttachment('images/phpmailer_mini.png');
- //send the message, check for errors
- if (!$mail->send()) {
- return "Mailer Error: " . $mail->ErrorInfo;
- }
- return "Message sent!";
- }
- public function getPHExpiry($phDate)
- {
- $expiry = $this->db->getRowData($this->db->SettingsTable, "settings", "Payment Window Time", "value");
- return strtotime($phDate) + ($expiry * 3600);
- }
- public function PHEnabled()
- {
- $enabled = $this->db->getRowData($this->db->SettingsTable, "settings", "PH Enabled", "value");
- return $enabled == "True";
- }
- //Matching implementation
- public function PH($mid, $amount)
- {
- $members = array();
- $expiryDate = $this->getPHExpiry(date("Y-m-d H:i:s"));
- $phid = 0;
- $investmentPeriod = $this->db->getRowData($this->db->SettingsTable, "settings", "Profit Frequency", "value");
- $date = time() + ($investmentPeriod*3600);
- $d = date("Y-m-d H:i:s");
- $returnAmount = $this->db->getRowData($this->db->SettingsTable, "settings", "Percentage Profit", "value") * $amount + $amount;
- $vipAccounts = $this->getVIPAccounts();
- $minVIPAmount = $this->db->getRowData($this->db->SettingsTable, "settings", "Minimum Amount VIP Matching when in Mode B", "value");
- if($this->db->Insert($this->db->PHTable, NULL, array(NULL, $mid, $amount, $returnAmount, date("Y-m-d H:i:s"), $date, "Pending", "No")))
- {
- //THIS POPULATE THE REF TABLE
- //$this-> Ref($mid, $amount,$date);
- $phid = $this->db->LastInsertedId;
- $systemGH = $this->db->getRowData($this->db->SettingsTable, "settings", "System Fees", "value") * $amount;
- $amount -= $systemGH;
- $matchingMode = $this->db->getRowData($this->db->SettingsTable, "settings", "Matching Mode", "value");
- $ghData = $this->db->SelectX("SELECT g.*,m.account_holder,m.bank_name AS bank, m.account_number,m.phone FROM ". $this->db->MembersTable." m
- INNER JOIN ".$this->db->GHTable." g ON m.member_id=g.member_id WHERE g.unmatched>0 AND g.gh_type='member' AND m.member_id!='$mid'");
- $totalVip = $this->db->tablerows($this->db->VIPAccountsTable);
- if($matchingMode=="C" || !is_array($ghData)) //VIP ONLY
- {
- $i = 0;
- $vipAccount = $vipAccounts[100000001];
- if($systemGH>0){
- $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid, $vipAccount["vip_id"], $systemGH, $d, "Pending",
- $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
- unset($vipAccounts[100000001]);
- }
- $ghData = $vipAccounts;
- $totalLoops = $this->smartSplit($amount, count($vipAccounts));
- $single = $amount / $totalLoops;
- shuffle($ghData);
- foreach($ghData as $ghd)
- {
- $ghid = $this->GH($ghd["vip_id"], 0, "vip", $single);
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $single, $d, "Pending",
- $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- ++$i;
- if($i==$totalLoops) return true;
- }
- }
- else if($matchingMode == "A" && is_array($ghData)) //Normal Matching
- {
- $vipAccount = $vipAccounts[100000001];
- if($systemGH>0){
- $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$vipAccount["vip_id"], $systemGH, $d, "Pending",
- $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
- unset($vipAccounts[100000001]);
- }
- foreach($ghData as $ghd)
- {
- $ghAmount = $ghd["unmatched"];
- if($amount == $ghAmount)
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $amount, $d, "Pending",
- $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
- $amount=0;
- return true;
- }
- else if($ghAmount > $amount)
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $amount, $d, "Pending",
- $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array($ghAmount-$amount));
- $amount = 0;
- return true;
- }
- else
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $ghAmount, $d, "Pending",
- $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
- $amount -= $ghAmount;
- }
- }
- //Check if there is unmatched cash and match it
- $ghData = $vipAccounts;
- $totalLoops = $this->smartSplit($amount, count($ghData));
- $i = 0;
- $single = $amount / $totalLoops;
- foreach($ghData as $ghd)
- {
- $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
- $amt = $single;
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
- $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- ++$i;
- if($i==$totalLoops) return true;
- }
- }
- else if($matchingMode == "B") //Members + VIP matching
- {
- $matched = 0;
- $matchedB4Vip = $this->db->getRowData($this->db->SettingsTable, "settings", "Matches Before VIP", "value");
- $vipAccount = $vipAccounts[100000001];
- if($systemGH>0){
- $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$vipAccount["vip_id"], $systemGH, $d, "Pending",
- $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
- unset($vipAccounts[100000001]);
- }
- if(!is_array($ghData)) //No member to match
- {
- $ghData = $vipAccounts;
- $totalLoops = $this->smartSplit($amount, count($ghData));
- $i = 0;
- $single = $amount / $totalLoops;
- foreach($ghData as $ghd)
- {
- $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
- $amt = $single;
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
- $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- ++$i;
- if($i==$totalLoops) return true;
- }
- }
- else
- {
- foreach($ghData as $ghd)
- {
- $ghAmount = $ghd["unmatched"];
- if($amount == $ghAmount)
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
- $amount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
- $amount=0;
- return true;
- }
- else if($ghAmount > $amount)
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
- $amount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array($ghAmount-$amount));
- $amount = 0;
- return true;
- }
- else
- {
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
- $ghAmount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
- $amount -= $ghAmount;
- }
- if(++$matched % $matchedB4Vip == 0)
- {
- foreach($vipAccounts as $ghd)
- {
- $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
- $amt = $amount <= $minVIPAmount ? $amount : $minVIPAmount;
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
- $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- $amount -= $amt;
- if($amount==0) return true;
- break;
- }
- }
- }
- //
- //Check if there is unmatched cash and match it
- $ghData = $this->getVIPAccounts();
- unset($ghData[100000001]);
- $totalLoops = $this->smartSplit($amount, count($ghData));
- $i = 0;
- $single = $amount / $totalLoops;
- foreach($ghData as $ghd)
- {
- $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
- $amt = $single;
- $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
- $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
- ++$i;
- if($i==$totalLoops) return true;
- }
- }
- }
- }
- //end of function PH
- }
- /*public function Ref($mid, $amount,$date)
- {
- //this function get PHID AND AMOUNT AND DURATION PLUS UPLINERS WHO GOT THE MEMBER TO PH OF A PARTICULAR TNX
- $ghData1 = $this->db->SelectX("SELECT upliner, member_id FROM " . $this->db->MembersTable . " WHERE member_id ='$mid' ");
- if(is_array($ghData1)){
- foreach ($ghData1 as $key) {
- $upliner = $key['upliner'];
- $midd = $key['member_id'];
- # code...
- $ghData2 = $this->db->SelectX("SELECT * FROM " . $this->db->PHTable . " WHERE member_id ='$mid' ");
- if(is_array($ghData2))
- {
- $ref_percent = $this->db->getRowData($this->db->SettingsTable, "settings", "Referral Commission", "value");
- foreach ($ghData2 as $get) {
- $phid1 = $get['phid'];
- $mid1 = $get['member_id'];
- $ref_money1 = $amount * $ref_percent/100;
- return $this->db->Insert($this->db->RefTable, NULL, array($phid1,$mid, $upliner, $ref_money1,"pending","unpaid", $date));
- # code...
- }}
- }
- }
- }*/
- public function autoCancelPH()
- {
- $phs = $this->db->SelectX("SELECT ph.* FROM ".$this->db->PHTable." ph WHERE ph.status!='Cancelled' AND
- ph.phid NOT IN (SELECT p.phid FROM ".$this->db->PaymentsTable." p)");
- if(is_array($phs))
- {
- foreach($phs as $ph)
- {
- $phmatching = $this->db->Select($this->db->PHMatchingTable, NULL, array("phid"), array($ph["phid"]));
- $pid = $ph["phid"];
- if(is_array($phmatching))
- {
- if(time() >= $phmatching[0]["expiry_date"])
- {
- ///THIS DELETE CANCELLED PH
- //$this->db->Delete($this->db->RefTable, array("pid"), array($pid));
- foreach($phmatching as $phm)
- {
- if($phm["receiver_id"] > 100000000)
- $this->db->Execute("UPDATE ".$this->db->GHTable . " SET `status`='Cancelled' WHERE ghid='".$phm["ghid"]."'");
- else
- $this->db->Execute("UPDATE ".$this->db->GHTable." SET unmatched=unmatched+".$phm["amount"]." WHERE ghid='".$phm["ghid"]."'");
- }
- $this->db->Execute("UPDATE ".$this->db->PHMatchingTable . " SET `status`='Cancelled' WHERE phid='".$ph["phid"]."'");
- $this->db->Execute("UPDATE ".$this->db->PHTable . " SET `status`='Cancelled' WHERE phid='".$ph["phid"]."'");
- // function to cancell any ref bonus of any PH using theis function CancelPHforReferrals($phid)
- //$this->CancelPHforReferrals($pid);
- }
- }
- }
- }
- }
- public function GH($mid,$phid, $type, $amount)
- {
- if($type == "vip")
- {
- $this->db->Insert($this->db->GHTable, NULL, array(NULL, $mid, $phid, $type, $amount, 0, date("Y-m-d"), "Pending"));
- return $this->db->LastInsertedId;
- }
- $check = $this->db->getRowData($this->db->GHTable, "phid", $phid);
- if(count($check) == 0)
- $this->db->Insert($this->db->GHTable, NULL, array(NULL, $mid, $phid, $type, $amount, $amount, date("Y-m-d"), "Pending"));
- return $this->db->LastInsertedId;
- }
- public function getCommissions()
- {
- $commissions = array();
- $com = $this->db->SelectX("SELECT SUM(amount) AS commission, member_id FROM ".$this->db->CommissionTable . " WHERE `status`='Pending'
- GROUP BY member_id");
- if(is_array($com))
- {
- foreach($com as $c)
- {
- $commissions[$c["member_id"]] = $c["commission"];
- }
- }
- return $commissions;
- }
- private function smartSplit($amount, $vips)
- {
- if($vips == 2 || $vips ==1) return $vips;
- if($amount<50000) return 1;
- if($amount > 500000)
- return $vips;
- else
- {
- for($n = $vips; $n >= 2; $n--)
- {
- $single = $amount / $vips;
- if($single >= 50000)
- return $n;
- }
- }
- return 2;
- }
- public function getCurrentPH($mid)
- {
- $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
- if(is_array($phData))
- {
- //$matchingExpiryDate = $this->db->getRowData($this->db->PHMatchingTable, "phid", $phData["phid"], "expiry_date");
- //$phData[] = $matchingExpiryDate;
- return $phData[0];
- }
- return NULL;
- }
- public function midd($mid)
- {
- $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
- if(is_array($phData))
- {
- //$matchingExpiryDate = $this->db->getRowData($this->db->PHMatchingTable, "phid", $phData["phid"], "expiry_date");
- //$phData[] = $matchingExpiryDate;
- return $phData[0];
- }
- return NULL;
- }
- public function getGHtimer($mid)
- {
- $ghData = $this->db->SelectX("SELECT date_for_gh AS timer FROM " . $this->db->PHTable . " WHERE gh_activated='No' AND
- member_id='$mid' AND `status`='Confirmed'");
- if(is_array($ghData))
- {
- if($ghData[0]["timer"] > time())
- return $ghData[0]["timer"] - time();
- return 0;
- }
- return -1;
- }
- public function getAwaitingGH($mid)
- {
- $ghData = $this->db->SelectX("SELECT return_amount FROM " . $this->db->PHTable . " WHERE gh_activated='No' AND
- member_id='$mid' AND `status`='Confirmed'");
- if(is_array($ghData))
- {
- return $ghData[0]["return_amount"] ;
- }
- return 0;
- }
- public function getUnmatchedGH($mid)
- {
- $ghunmatched = $this->db->SelectX("SELECT * FROM " . $this->db->GHTable . " WHERE member_id='$mid' AND unmatched>0");
- if(is_array($ghunmatched))
- {
- $ghu = $this->db->SelectX("SELECT SUM(amount) paid FROM ".$this->db->PHMatchingTable." WHERE ghid='".$ghunmatched[0]["ghid"].
- "' AND `status`='Confirmed'");
- $paid = is_array($ghu) ? $ghu[0]["paid"] : 0;
- return $ghunmatched[0]["amount"] - $paid;
- }
- return 0;
- }
- public function canCountdown($mid)
- {
- $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
- if(is_array($phData))
- {
- $phmData = $this->db->SelectX("SELECT * FROM ".$this->db->PHMatchingTable." WHERE payer_id='$mid' AND phid='".$phData[0]["phid"]."' AND
- `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
- foreach($phmData as $phm)
- {
- if($phm["status"]!="Confirmed")
- return false;
- }
- return true;
- }
- return false;
- }
- public function getPHCountdownTime($mid)
- {
- $phmData = $this->db->SelectX("SELECT * FROM ".$this->db->PHMatchingTable." WHERE payer_id='$mid' AND
- `status`='Pending' ORDER BY phmid DESC LIMIT 0,1");
- if(is_array($phmData))
- {
- foreach($phmData as $phm)
- {
- if(time() < $phm["expiry_date"])
- return $phm["expiry_date"];
- }
- }
- return 0;
- }
- public function getMyPHMatchings($mid)
- {
- return $this->db->SelectX("SELECT m.*,p.payment_id,p.`status` AS pstatus,p.evidence FROM " . $this->db->PHMatchingTable . " m LEFT JOIN " .
- $this->db->PaymentsTable ." p ON m.phmid=p.phmid WHERE (m.payer_id='$mid' OR m.receiver_id='$mid') AND
- m.`status`!='Confirmed' ORDER BY m.phmid DESC");
- }
- public function clearPHMatching($phid)
- {
- if($this->db->Execute("INSERT INTO " . $this->db->PHMatchingClearedTable . "(`phmid`, `ghid`, `phid`, `payer_id`, `receiver_id`, `amount`,
- `date_matched`, `status`,`account_holder`,`bank`,`account_number`,`phone`,`expiry_date`) SELECT * FROM " . $this->db->PHMatchingTable .
- " WHERE phid='$phid'"))
- {
- $this->db->Execute("DELETE FROM " . $this->db->PHMatchingTable. " WHERE phid='$phid'");
- $this->db->Execute("DELETE FROM " . $this->db->PHTable. " WHERE phid='$phid'");
- return true;
- }
- return false;
- }
- public function getVIPAccounts()
- {
- $accounts = array();
- foreach($this->db->Select($this->db->VIPAccountsTable) as $vip)
- {
- $accounts[$vip["vip_id"]] = $vip;
- }
- return $accounts;
- }
- public function addVipAccount($name, $bank, $acc, $bitcoin, $phone, $email, $username)
- {
- return $this->db->Insert($this->db->VIPAccountsTable, NULL, array(NULL,$name, $bank, $acc, $bitcoin, $phone, $email, $username,"vip"));
- }
- public function vipExists($user)
- {
- return $this->db->IsExists($user, "username", $this->db->MembersTable) || $this->db->IsExists($user, "username", $this->db->VIPAccountsTable);
- }
- public function PHGH($mid)
- {
- $phgh = array(0,0,0);
- $ph = $this->db->SelectX("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable . " WHERE `status`='Confirmed' AND payer_id='$mid'");
- if(is_array($ph))
- $phgh[0] = $ph[0]["amt"];
- $gh = $this->db->SelectX("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable . " WHERE `status`='Confirmed' AND receiver_id='$mid'");
- if(is_array($gh))
- $phgh[1] = $gh[0]["amt"];
- if($phgh[1]>=$phgh[0])
- $phgh[2] = $phgh[1]-$phgh[0];
- return $phgh;
- }
- public function hasOutstandingPH($mid)
- {
- return is_array($this->db->SelectX("SELECT * FROM " . $this->db->PHMatchingTable . " WHERE `status`='Pending' AND payer_id='$mid'"));
- }
- public function PHSuccess()
- {
- return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Confirmed"));
- }
- public function PHPending()
- {
- return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Pending"));
- }
- public function PHCancelled()
- {
- return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Cancelled"));
- }
- public function PHUnpaired()
- {
- return "";
- }
- public function hasOustandingPH($mid)
- {
- $ph = $this->db->Select($this->db->PHTable, NULL, array("member_id", "status"), array($mid, "Pending"));
- return is_array($ph);
- }
- public function adminDashboard()
- {
- $dashboard = array("Total Members"=> $this->db->tablerows($this->db->MembersTable),
- "Pending GH"=>$this->db->dataRows($this->db->GHTable, "status", "Pending"),
- "Pending PH"=>$this->db->dataRows($this->db->PHTable, "status", "Pending"),
- "Cycle Completed"=>$this->db->dataRows($this->db->PHMatchingTable, "status", "Confirmed"),
- "TOTAL GH PAID"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable .
- " WHERE `status`='Confirmed' AND receiver_id<100000001"),
- "TOTAL GH PAID TODAY"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
- " WHERE `status`='Confirmed' AND receiver_id<100000001 AND payment_date LIKE '".date("Y-m-d")."%'"),
- "TOTAL GH PAID VIP"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
- " WHERE `status`='Confirmed' AND receiver_id>=100000001"),
- "TOTAL GH PAID VIP TODAY"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
- " WHERE `status`='Confirmed' AND receiver_id>=100000001 AND payment_date LIKE '".date("Y-m-d")."%'")
- );
- return $dashboard;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement