Advertisement
Guest User

Untitled

a guest
Apr 12th, 2017
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.65 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. public function savePFSettings($pf)
  5. {
  6. $s1 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Profit Frequency"), array("value"), array($pf[0]));
  7. $s2 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Percentage Profit"), array("value"), array($pf[1]));
  8. $s3 = $this->db->Update($this->db->SettingsTable, array("settings"), array("Payment Window Time"), array("value"), array($pf[2]));
  9. return ($s1 && $s2 && $s3);
  10. }
  11.  
  12. public function members()
  13. {
  14. $allmenbers = array();
  15. $members = $this->db->Select($this->db->MembersTable, NULL, array("activated"), array("Yes"));
  16. if(is_array($members))
  17. {
  18. foreach($members as $m){
  19. $allmenbers[$m["member_id"]] = $m;
  20. }
  21. }
  22. return $allmenbers;
  23. }
  24.  
  25. public function postTestimony($mid, $testimony)
  26. {
  27. $db = new DB();
  28. if($db->Insert($db->TestimoniesTable, array("member_id", "testimony","approved", "date"), array($mid, $testimony, "No", date("Y-m-d H:i:s"))))
  29. return true;
  30. return false;
  31. }
  32.  
  33. public function getTestimony()
  34. {
  35. $db = new DB();
  36. return $db->SelectX("SELECT * FROM " . $db->TestimoniesTable . " WHERE approved='Yes' ");
  37. }
  38.  
  39. public function getTestimonies($type)
  40. {
  41. $db = new DB();
  42. return $db->SelectX("SELECT m.name,m.phone, t.* FROM " . $db->TestimoniesTable . " t INNER JOIN ".$db->MembersTable .
  43. " m ON t.member_id=m.member_id WHERE t.approved='$type' ORDER BY t.date DESC");
  44. }
  45. public function approveTestimony($tid)
  46. {
  47. return $this->db->Update($this->db->TestimoniesTable, array("testimony_id"), array($tid), array("approved"), array("Yes"));
  48. }
  49. public function getNews()
  50. {
  51. $db = new DB();
  52. return $db->SelectX("SELECT * FROM " . $db->NewsTable . " ORDER BY news_id DESC");
  53. }
  54.  
  55. public function deleteTestimony($tid)
  56. {
  57. $db = new DB();
  58. return $db->Delete($db->TestimoniesTable, array("testimony_id"), array($tid));
  59. }
  60.  
  61. public function evidenceSavedBefore($phmid)
  62. {
  63. $db = new DB();
  64. $check = $db->Select($db->PaymentsTable, NULL, array("phmid"), array($phmid));
  65. return is_array($check);
  66. }
  67. public function savePaymentEvidence($phmid)
  68. {
  69. $db = new DB();
  70. $pay = $db->Select($db->PHMatchingTable, NULL, array("phmid"), array($phmid));
  71. if(is_array($pay))
  72. {
  73. $pay = $pay[0];
  74. return $db->Insert($db->PaymentsTable, NULL, array(NULL,$pay["phid"], $pay["payer_id"],$phmid,$pay["receiver_id"],$pay["amount"],
  75. date("Y-m-d H:i:s"), '../member/payments/' . $phmid . '.jpg', 'Not Confirmed'));
  76. }
  77. return false;
  78. }
  79.  
  80. public function getPaymentEvidence()
  81. {
  82. $db = new DB();
  83. $pevidence = $db->Select($db->PaymentEvidenceTable);
  84. $evidenceData = array();
  85. if(is_array($pevidence))
  86. {
  87. foreach($pevidence as $pe)
  88. {
  89. $evidenceData[$pe["type"].$pe["ref_number"]] = $pe;
  90. }
  91. }
  92. return $evidenceData;
  93. }
  94.  
  95. public function getVIPPaymentEvidence()
  96. {
  97. $pevidence = $this->db->SelectX("SELECT * FROM " . $this->db->PaymentsTable . " WHERE status='Not Confirmed' AND receiver_id>100000000");
  98. $evidenceData = array();
  99. if(is_array($pevidence))
  100. {
  101. foreach($pevidence as $pe)
  102. {
  103. $evidenceData[$pe["phmid"]] = $pe;
  104. }
  105. }
  106. return $evidenceData;
  107. }
  108.  
  109. public function confirmPH($phid)
  110. {
  111. $phMatchings = $this->db->Select($this->db->PHMatchingTable, NULL, array("phid"),array($phid));
  112. foreach($phMatchings as $phm)
  113. {
  114. if($phm["status"] != "Confirmed")
  115. return false;
  116. }
  117. $this->db->Update($this->db->PHTable, array("phid"), array($phid), array("status"), array("Confirmed"));
  118. return true;
  119. }
  120.  
  121. public function confirmPayment($phmid)
  122. {
  123. $matching = $this->db->Select($this->db->PHMatchingTable, NULL, array("phmid"),array($phmid));
  124. if(is_array($matching))
  125. {
  126. $matching = $matching[0];
  127. if($this->db->Update($this->db->PaymentsTable, array("phmid"), array($phmid), array("status"), array("Confirmed")))
  128. {
  129. if($this->db->Update($this->db->PHMatchingTable, array("phmid"), array($phmid), array("status"), array("Confirmed")))
  130. {
  131. $ghid = $matching["ghid"];
  132. $gh = $this->db->Select($this->db->GHTable, NULL, array("ghid"),array($ghid));
  133. if($gh[0]["amount"] == $matching["amount"])
  134. {
  135. if($this->db->Update($this->db->GHTable, array("ghid"), array($ghid), array("status"), array("Confirmed")))
  136. {
  137. $this->confirmPH($matching["phid"]);
  138. return true;
  139. }
  140. }
  141. else
  142. {
  143. $this->confirmPH($matching["phid"]);
  144. return true;
  145. }
  146. }
  147. //reverse the process
  148. $this->db->Update($this->db->PaymentsTable, array("phmid"), array($phmid), array("status"), array("Not Confirmed"));
  149. $this->db->Update($this->db->PHMatchingTable, array("phmid"), array($phmid), array("status"), array("Pending"));
  150. }
  151. }
  152. return false;
  153. }
  154.  
  155. public function getVerification($filter)
  156. {
  157. $db = new DB();
  158. $verData = array();
  159. if($filter == "")
  160. {
  161. $verData = $db->SelectX("SELECT v.member_id,m.name,v.ple,v.poa,v.kyc,v.date_uploaded,v.date_verified,v.verified FROM " .
  162. $db->VerifiedMembersTable . " v INNER JOIN $db->MembersTable m ON v.member_id=m.member_id ORDER BY v.verified");
  163. }
  164. else
  165. {
  166. $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
  167. INNER JOIN $db->MembersTable m ON v.member_id=m.member_id WHERE v.verified='$filter' ORDER BY v.verified");
  168. }
  169. return $verData;
  170. }
  171.  
  172. public function getTransaction($mid)
  173. {
  174. return $this->db->SelectX("SELECT * FROM " . $this->db->PaymentsTable . " WHERE (payer_id='$mid' OR receiver_id='$mid') AND `status`='Confirmed'");
  175. }
  176.  
  177. public function getSettings($settings)
  178. {
  179. return $this->db->getRowData($this->db->SettingsTable, "settings", $settings, "value");
  180. }
  181.  
  182. public function sendMail($receivers, $subject, $message)
  183. {
  184. date_default_timezone_set('Etc/UTC');
  185. //Create a new PHPMailer instance
  186. $mail = new PHPMailer;
  187.  
  188. //Tell PHPMailer to use SMTP
  189. $mail->isSMTP();
  190.  
  191. //Enable SMTP debugging
  192. // 0 = off (for production use)
  193. // 1 = client messages
  194. // 2 = client and server messages
  195. $mail->SMTPDebug = 0;
  196.  
  197. //Ask for HTML-friendly debug output
  198. $mail->Debugoutput = 'html';
  199.  
  200. //Set the hostname of the mail server
  201. $mail->Host = 'smtp.gmail.com';
  202. // use
  203. // $mail->Host = gethostbyname('smtp.gmail.com');
  204. // if your network does not support SMTP over IPv6
  205.  
  206. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  207. $mail->Port = 587;
  208.  
  209. //Set the encryption system to use - ssl (deprecated) or tls
  210. $mail->SMTPSecure = 'tls';
  211.  
  212. //Whether to use SMTP authentication
  213. $mail->SMTPAuth = true;
  214.  
  215. //Username to use for SMTP authentication - use full email address for gmail
  216. $mail->Username = "noreplyback2017.com@gmail.com";
  217.  
  218. //Password to use for SMTP authentication
  219. $mail->Password = "noreply100%";
  220.  
  221. //Set who the message is to be sent from
  222. $mail->setFrom('noreplyback2017.com@gmail.com', 'Xtraearners');
  223.  
  224. //Set an alternative reply-to address
  225. $mail->addReplyTo('noreplyback2017.com@gmail.com', 'Xtraearners');
  226.  
  227. //Set who the message is to be sent to
  228. $receiver = explode(":", $receivers);
  229. $mail->addAddress($receiver[0], $receiver[1]);
  230.  
  231.  
  232. //Set the subject line
  233. $mail->Subject = $subject;// 'PHPMailer GMail SMTP test';
  234.  
  235. //Read an HTML message body from an external file, convert referenced images to embedded,
  236. //convert HTML into a basic plain-text alternative body
  237. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  238. $mail->msgHTML($message, dirname(__FILE__));
  239.  
  240. //Replace the plain text body with one created manually
  241. //$mail->AltBody = $message;// 'This is a plain-text message body';
  242.  
  243. //Attach an image file
  244. //$mail->addAttachment('images/phpmailer_mini.png');
  245.  
  246. //send the message, check for errors
  247. if (!$mail->send()) {
  248. return "Mailer Error: " . $mail->ErrorInfo;
  249. }
  250. return "Message sent!";
  251. }
  252.  
  253. public function getPHExpiry($phDate)
  254. {
  255. $expiry = $this->db->getRowData($this->db->SettingsTable, "settings", "Payment Window Time", "value");
  256. return strtotime($phDate) + ($expiry * 3600);
  257. }
  258.  
  259. public function PHEnabled()
  260. {
  261. $enabled = $this->db->getRowData($this->db->SettingsTable, "settings", "PH Enabled", "value");
  262. return $enabled == "True";
  263. }
  264. //Matching implementation
  265. public function PH($mid, $amount)
  266. {
  267. $members = array();
  268. $expiryDate = $this->getPHExpiry(date("Y-m-d H:i:s"));
  269. $phid = 0;
  270. $investmentPeriod = $this->db->getRowData($this->db->SettingsTable, "settings", "Profit Frequency", "value");
  271. $date = time() + ($investmentPeriod*3600);
  272. $d = date("Y-m-d H:i:s");
  273. $returnAmount = $this->db->getRowData($this->db->SettingsTable, "settings", "Percentage Profit", "value") * $amount + $amount;
  274. $vipAccounts = $this->getVIPAccounts();
  275. $minVIPAmount = $this->db->getRowData($this->db->SettingsTable, "settings", "Minimum Amount VIP Matching when in Mode B", "value");
  276. if($this->db->Insert($this->db->PHTable, NULL, array(NULL, $mid, $amount, $returnAmount, date("Y-m-d H:i:s"), $date, "Pending", "No")))
  277. {
  278. //THIS POPULATE THE REF TABLE
  279. //$this-> Ref($mid, $amount,$date);
  280.  
  281. $phid = $this->db->LastInsertedId;
  282. $systemGH = $this->db->getRowData($this->db->SettingsTable, "settings", "System Fees", "value") * $amount;
  283. $amount -= $systemGH;
  284. $matchingMode = $this->db->getRowData($this->db->SettingsTable, "settings", "Matching Mode", "value");
  285. $ghData = $this->db->SelectX("SELECT g.*,m.account_holder,m.bank_name AS bank, m.account_number,m.phone FROM ". $this->db->MembersTable." m
  286. 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'");
  287. $totalVip = $this->db->tablerows($this->db->VIPAccountsTable);
  288.  
  289. if($matchingMode=="C" || !is_array($ghData)) //VIP ONLY
  290. {
  291. $i = 0;
  292. $vipAccount = $vipAccounts[100000001];
  293. if($systemGH>0){
  294. $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
  295. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid, $vipAccount["vip_id"], $systemGH, $d, "Pending",
  296. $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
  297. unset($vipAccounts[100000001]);
  298. }
  299. $ghData = $vipAccounts;
  300. $totalLoops = $this->smartSplit($amount, count($vipAccounts));
  301. $single = $amount / $totalLoops;
  302. shuffle($ghData);
  303. foreach($ghData as $ghd)
  304. {
  305. $ghid = $this->GH($ghd["vip_id"], 0, "vip", $single);
  306. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $single, $d, "Pending",
  307. $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  308. ++$i;
  309. if($i==$totalLoops) return true;
  310. }
  311. }
  312. else if($matchingMode == "A" && is_array($ghData)) //Normal Matching
  313. {
  314. $vipAccount = $vipAccounts[100000001];
  315. if($systemGH>0){
  316. $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
  317. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$vipAccount["vip_id"], $systemGH, $d, "Pending",
  318. $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
  319. unset($vipAccounts[100000001]);
  320. }
  321. foreach($ghData as $ghd)
  322. {
  323. $ghAmount = $ghd["unmatched"];
  324. if($amount == $ghAmount)
  325. {
  326. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $amount, $d, "Pending",
  327. $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  328. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
  329. $amount=0;
  330. return true;
  331. }
  332. else if($ghAmount > $amount)
  333. {
  334. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $amount, $d, "Pending",
  335. $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  336. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array($ghAmount-$amount));
  337. $amount = 0;
  338. return true;
  339. }
  340. else
  341. {
  342. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"], $ghAmount, $d, "Pending",
  343. $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  344. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
  345. $amount -= $ghAmount;
  346. }
  347. }
  348. //Check if there is unmatched cash and match it
  349. $ghData = $vipAccounts;
  350. $totalLoops = $this->smartSplit($amount, count($ghData));
  351. $i = 0;
  352. $single = $amount / $totalLoops;
  353. foreach($ghData as $ghd)
  354. {
  355. $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
  356. $amt = $single;
  357. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
  358. $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  359. ++$i;
  360. if($i==$totalLoops) return true;
  361. }
  362. }
  363. else if($matchingMode == "B") //Members + VIP matching
  364. {
  365. $matched = 0;
  366. $matchedB4Vip = $this->db->getRowData($this->db->SettingsTable, "settings", "Matches Before VIP", "value");
  367. $vipAccount = $vipAccounts[100000001];
  368. if($systemGH>0){
  369. $ghid = $this->GH($vipAccount["vip_id"], 0, "vip", $systemGH);
  370. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$vipAccount["vip_id"], $systemGH, $d, "Pending",
  371. $vipAccount["name"], $vipAccount["bank"], $vipAccount["account_number"], $vipAccount["phone"], $expiryDate));
  372. unset($vipAccounts[100000001]);
  373. }
  374. if(!is_array($ghData)) //No member to match
  375. {
  376. $ghData = $vipAccounts;
  377. $totalLoops = $this->smartSplit($amount, count($ghData));
  378. $i = 0;
  379. $single = $amount / $totalLoops;
  380. foreach($ghData as $ghd)
  381. {
  382. $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
  383. $amt = $single;
  384. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
  385. $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  386. ++$i;
  387. if($i==$totalLoops) return true;
  388. }
  389. }
  390. else
  391. {
  392. foreach($ghData as $ghd)
  393. {
  394. $ghAmount = $ghd["unmatched"];
  395. if($amount == $ghAmount)
  396. {
  397. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
  398. $amount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  399. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
  400. $amount=0;
  401. return true;
  402. }
  403. else if($ghAmount > $amount)
  404. {
  405. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
  406. $amount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  407. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array($ghAmount-$amount));
  408. $amount = 0;
  409. return true;
  410. }
  411. else
  412. {
  413. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghd["ghid"], $phid, $mid,$ghd["member_id"],
  414. $ghAmount, $d, "Pending", $ghd["account_holder"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  415. $this->db->Update($this->db->GHTable, array("ghid"), array($ghd["ghid"]), array("unmatched"),array(0));
  416. $amount -= $ghAmount;
  417. }
  418. if(++$matched % $matchedB4Vip == 0)
  419. {
  420. foreach($vipAccounts as $ghd)
  421. {
  422. $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
  423. $amt = $amount <= $minVIPAmount ? $amount : $minVIPAmount;
  424. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
  425. $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  426. $amount -= $amt;
  427. if($amount==0) return true;
  428. break;
  429. }
  430. }
  431. }
  432. //
  433. //Check if there is unmatched cash and match it
  434. $ghData = $this->getVIPAccounts();
  435. unset($ghData[100000001]);
  436. $totalLoops = $this->smartSplit($amount, count($ghData));
  437. $i = 0;
  438. $single = $amount / $totalLoops;
  439. foreach($ghData as $ghd)
  440. {
  441. $ghid = $this->GH($ghd["vip_id"], 0, "vip", $systemGH);
  442. $amt = $single;
  443. $this->db->Insert($this->db->PHMatchingTable, NULL, array(NULL,$ghid, $phid, $mid,$ghd["vip_id"], $amt, $d, "Pending",
  444. $ghd["name"], $ghd["bank"], $ghd["account_number"], $ghd["phone"], $expiryDate));
  445. ++$i;
  446. if($i==$totalLoops) return true;
  447. }
  448. }
  449. }
  450. }
  451.  
  452.  
  453.  
  454. //end of function PH
  455. }
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. /*public function Ref($mid, $amount,$date)
  469. {
  470. //this function get PHID AND AMOUNT AND DURATION PLUS UPLINERS WHO GOT THE MEMBER TO PH OF A PARTICULAR TNX
  471.  
  472. $ghData1 = $this->db->SelectX("SELECT upliner, member_id FROM " . $this->db->MembersTable . " WHERE member_id ='$mid' ");
  473. if(is_array($ghData1)){
  474. foreach ($ghData1 as $key) {
  475. $upliner = $key['upliner'];
  476. $midd = $key['member_id'];
  477. # code...
  478.  
  479. $ghData2 = $this->db->SelectX("SELECT * FROM " . $this->db->PHTable . " WHERE member_id ='$mid' ");
  480. if(is_array($ghData2))
  481. {
  482. $ref_percent = $this->db->getRowData($this->db->SettingsTable, "settings", "Referral Commission", "value");
  483.  
  484. foreach ($ghData2 as $get) {
  485. $phid1 = $get['phid'];
  486. $mid1 = $get['member_id'];
  487. $ref_money1 = $amount * $ref_percent/100;
  488. return $this->db->Insert($this->db->RefTable, NULL, array($phid1,$mid, $upliner, $ref_money1,"pending","unpaid", $date));
  489.  
  490.  
  491. # code...
  492. }}
  493. }
  494. }
  495. }*/
  496.  
  497. public function autoCancelPH()
  498. {
  499. $phs = $this->db->SelectX("SELECT ph.* FROM ".$this->db->PHTable." ph WHERE ph.status!='Cancelled' AND
  500. ph.phid NOT IN (SELECT p.phid FROM ".$this->db->PaymentsTable." p)");
  501. if(is_array($phs))
  502. {
  503.  
  504. foreach($phs as $ph)
  505. {
  506. $phmatching = $this->db->Select($this->db->PHMatchingTable, NULL, array("phid"), array($ph["phid"]));
  507. $pid = $ph["phid"];
  508.  
  509.  
  510. if(is_array($phmatching))
  511. {
  512. if(time() >= $phmatching[0]["expiry_date"])
  513. {
  514. ///THIS DELETE CANCELLED PH
  515. //$this->db->Delete($this->db->RefTable, array("pid"), array($pid));
  516.  
  517. foreach($phmatching as $phm)
  518. {
  519. if($phm["receiver_id"] > 100000000)
  520. $this->db->Execute("UPDATE ".$this->db->GHTable . " SET `status`='Cancelled' WHERE ghid='".$phm["ghid"]."'");
  521. else
  522. $this->db->Execute("UPDATE ".$this->db->GHTable." SET unmatched=unmatched+".$phm["amount"]." WHERE ghid='".$phm["ghid"]."'");
  523. }
  524. $this->db->Execute("UPDATE ".$this->db->PHMatchingTable . " SET `status`='Cancelled' WHERE phid='".$ph["phid"]."'");
  525. $this->db->Execute("UPDATE ".$this->db->PHTable . " SET `status`='Cancelled' WHERE phid='".$ph["phid"]."'");
  526. // function to cancell any ref bonus of any PH using theis function CancelPHforReferrals($phid)
  527. //$this->CancelPHforReferrals($pid);
  528.  
  529. }
  530. }
  531. }
  532. }
  533. }
  534. public function GH($mid,$phid, $type, $amount)
  535. {
  536. if($type == "vip")
  537. {
  538. $this->db->Insert($this->db->GHTable, NULL, array(NULL, $mid, $phid, $type, $amount, 0, date("Y-m-d"), "Pending"));
  539. return $this->db->LastInsertedId;
  540. }
  541. $check = $this->db->getRowData($this->db->GHTable, "phid", $phid);
  542. if(count($check) == 0)
  543. $this->db->Insert($this->db->GHTable, NULL, array(NULL, $mid, $phid, $type, $amount, $amount, date("Y-m-d"), "Pending"));
  544. return $this->db->LastInsertedId;
  545. }
  546.  
  547. public function getCommissions()
  548. {
  549. $commissions = array();
  550. $com = $this->db->SelectX("SELECT SUM(amount) AS commission, member_id FROM ".$this->db->CommissionTable . " WHERE `status`='Pending'
  551. GROUP BY member_id");
  552. if(is_array($com))
  553. {
  554. foreach($com as $c)
  555. {
  556. $commissions[$c["member_id"]] = $c["commission"];
  557. }
  558. }
  559. return $commissions;
  560. }
  561.  
  562. private function smartSplit($amount, $vips)
  563. {
  564. if($vips == 2 || $vips ==1) return $vips;
  565. if($amount<50000) return 1;
  566. if($amount > 500000)
  567. return $vips;
  568. else
  569. {
  570. for($n = $vips; $n >= 2; $n--)
  571. {
  572. $single = $amount / $vips;
  573. if($single >= 50000)
  574. return $n;
  575. }
  576. }
  577. return 2;
  578. }
  579.  
  580. public function getCurrentPH($mid)
  581. {
  582. $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
  583. if(is_array($phData))
  584. {
  585. //$matchingExpiryDate = $this->db->getRowData($this->db->PHMatchingTable, "phid", $phData["phid"], "expiry_date");
  586. //$phData[] = $matchingExpiryDate;
  587. return $phData[0];
  588. }
  589. return NULL;
  590. }
  591.  
  592.  
  593.  
  594. public function midd($mid)
  595. {
  596. $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
  597. if(is_array($phData))
  598. {
  599. //$matchingExpiryDate = $this->db->getRowData($this->db->PHMatchingTable, "phid", $phData["phid"], "expiry_date");
  600. //$phData[] = $matchingExpiryDate;
  601. return $phData[0];
  602. }
  603. return NULL;
  604. }
  605.  
  606.  
  607.  
  608. public function getGHtimer($mid)
  609. {
  610. $ghData = $this->db->SelectX("SELECT date_for_gh AS timer FROM " . $this->db->PHTable . " WHERE gh_activated='No' AND
  611. member_id='$mid' AND `status`='Confirmed'");
  612. if(is_array($ghData))
  613. {
  614. if($ghData[0]["timer"] > time())
  615. return $ghData[0]["timer"] - time();
  616. return 0;
  617. }
  618. return -1;
  619. }
  620.  
  621. public function getAwaitingGH($mid)
  622. {
  623. $ghData = $this->db->SelectX("SELECT return_amount FROM " . $this->db->PHTable . " WHERE gh_activated='No' AND
  624. member_id='$mid' AND `status`='Confirmed'");
  625. if(is_array($ghData))
  626. {
  627. return $ghData[0]["return_amount"] ;
  628. }
  629. return 0;
  630. }
  631.  
  632. public function getUnmatchedGH($mid)
  633. {
  634. $ghunmatched = $this->db->SelectX("SELECT * FROM " . $this->db->GHTable . " WHERE member_id='$mid' AND unmatched>0");
  635. if(is_array($ghunmatched))
  636. {
  637. $ghu = $this->db->SelectX("SELECT SUM(amount) paid FROM ".$this->db->PHMatchingTable." WHERE ghid='".$ghunmatched[0]["ghid"].
  638. "' AND `status`='Confirmed'");
  639. $paid = is_array($ghu) ? $ghu[0]["paid"] : 0;
  640. return $ghunmatched[0]["amount"] - $paid;
  641. }
  642. return 0;
  643. }
  644.  
  645. public function canCountdown($mid)
  646. {
  647. $phData = $this->db->SelectX("SELECT * FROM ".$this->db->PHTable." WHERE member_id='$mid' AND `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
  648. if(is_array($phData))
  649. {
  650. $phmData = $this->db->SelectX("SELECT * FROM ".$this->db->PHMatchingTable." WHERE payer_id='$mid' AND phid='".$phData[0]["phid"]."' AND
  651. `status`!='Confirmed' ORDER BY phid DESC LIMIT 0,1");
  652. foreach($phmData as $phm)
  653. {
  654. if($phm["status"]!="Confirmed")
  655. return false;
  656. }
  657. return true;
  658. }
  659. return false;
  660. }
  661.  
  662. public function getPHCountdownTime($mid)
  663. {
  664. $phmData = $this->db->SelectX("SELECT * FROM ".$this->db->PHMatchingTable." WHERE payer_id='$mid' AND
  665. `status`='Pending' ORDER BY phmid DESC LIMIT 0,1");
  666. if(is_array($phmData))
  667. {
  668. foreach($phmData as $phm)
  669. {
  670. if(time() < $phm["expiry_date"])
  671. return $phm["expiry_date"];
  672. }
  673. }
  674. return 0;
  675. }
  676.  
  677. public function getMyPHMatchings($mid)
  678. {
  679. return $this->db->SelectX("SELECT m.*,p.payment_id,p.`status` AS pstatus,p.evidence FROM " . $this->db->PHMatchingTable . " m LEFT JOIN " .
  680. $this->db->PaymentsTable ." p ON m.phmid=p.phmid WHERE (m.payer_id='$mid' OR m.receiver_id='$mid') AND
  681. m.`status`!='Confirmed' ORDER BY m.phmid DESC");
  682. }
  683.  
  684. public function clearPHMatching($phid)
  685. {
  686. if($this->db->Execute("INSERT INTO " . $this->db->PHMatchingClearedTable . "(`phmid`, `ghid`, `phid`, `payer_id`, `receiver_id`, `amount`,
  687. `date_matched`, `status`,`account_holder`,`bank`,`account_number`,`phone`,`expiry_date`) SELECT * FROM " . $this->db->PHMatchingTable .
  688. " WHERE phid='$phid'"))
  689. {
  690. $this->db->Execute("DELETE FROM " . $this->db->PHMatchingTable. " WHERE phid='$phid'");
  691. $this->db->Execute("DELETE FROM " . $this->db->PHTable. " WHERE phid='$phid'");
  692. return true;
  693. }
  694. return false;
  695. }
  696.  
  697. public function getVIPAccounts()
  698. {
  699. $accounts = array();
  700. foreach($this->db->Select($this->db->VIPAccountsTable) as $vip)
  701. {
  702. $accounts[$vip["vip_id"]] = $vip;
  703. }
  704. return $accounts;
  705. }
  706.  
  707. public function addVipAccount($name, $bank, $acc, $bitcoin, $phone, $email, $username)
  708. {
  709. return $this->db->Insert($this->db->VIPAccountsTable, NULL, array(NULL,$name, $bank, $acc, $bitcoin, $phone, $email, $username,"vip"));
  710. }
  711.  
  712. public function vipExists($user)
  713. {
  714. return $this->db->IsExists($user, "username", $this->db->MembersTable) || $this->db->IsExists($user, "username", $this->db->VIPAccountsTable);
  715. }
  716.  
  717. public function PHGH($mid)
  718. {
  719. $phgh = array(0,0,0);
  720. $ph = $this->db->SelectX("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable . " WHERE `status`='Confirmed' AND payer_id='$mid'");
  721. if(is_array($ph))
  722. $phgh[0] = $ph[0]["amt"];
  723. $gh = $this->db->SelectX("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable . " WHERE `status`='Confirmed' AND receiver_id='$mid'");
  724. if(is_array($gh))
  725. $phgh[1] = $gh[0]["amt"];
  726. if($phgh[1]>=$phgh[0])
  727. $phgh[2] = $phgh[1]-$phgh[0];
  728. return $phgh;
  729. }
  730.  
  731. public function hasOutstandingPH($mid)
  732. {
  733. return is_array($this->db->SelectX("SELECT * FROM " . $this->db->PHMatchingTable . " WHERE `status`='Pending' AND payer_id='$mid'"));
  734. }
  735.  
  736. public function PHSuccess()
  737. {
  738. return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Confirmed"));
  739. }
  740.  
  741. public function PHPending()
  742. {
  743. return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Pending"));
  744. }
  745.  
  746. public function PHCancelled()
  747. {
  748. return $this->db->Select($this->db->PHMatchingTable, NULL, array("status"), array("Cancelled"));
  749. }
  750.  
  751. public function PHUnpaired()
  752. {
  753. return "";
  754. }
  755.  
  756. public function hasOustandingPH($mid)
  757. {
  758. $ph = $this->db->Select($this->db->PHTable, NULL, array("member_id", "status"), array($mid, "Pending"));
  759. return is_array($ph);
  760. }
  761.  
  762. public function adminDashboard()
  763. {
  764. $dashboard = array("Total Members"=> $this->db->tablerows($this->db->MembersTable),
  765. "Pending GH"=>$this->db->dataRows($this->db->GHTable, "status", "Pending"),
  766. "Pending PH"=>$this->db->dataRows($this->db->PHTable, "status", "Pending"),
  767. "Cycle Completed"=>$this->db->dataRows($this->db->PHMatchingTable, "status", "Confirmed"),
  768. "TOTAL GH PAID"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PHMatchingTable .
  769. " WHERE `status`='Confirmed' AND receiver_id<100000001"),
  770. "TOTAL GH PAID TODAY"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
  771. " WHERE `status`='Confirmed' AND receiver_id<100000001 AND payment_date LIKE '".date("Y-m-d")."%'"),
  772. "TOTAL GH PAID VIP"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
  773. " WHERE `status`='Confirmed' AND receiver_id>=100000001"),
  774. "TOTAL GH PAID VIP TODAY"=>(float)$this->db->GetData("SELECT SUM(amount) AS amt FROM " . $this->db->PaymentsTable .
  775. " WHERE `status`='Confirmed' AND receiver_id>=100000001 AND payment_date LIKE '".date("Y-m-d")."%'")
  776. );
  777. return $dashboard;
  778. }
  779. }
  780. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement