<?php /** * Created by PhpStorm. * @author albert * Date: 1/29/15 * Time: 1:10 AM */ require 'add_configure.php'; class my_db extends add_adodb_mysql { public function Connect() { $this->adodb->Connect('localhost', 'root', 'wrongPassword'); return $this; } } my_db::singleton();
protected function save() { $db = my_db::open(); $db->set($this->id, 'acc', array('acc_id' => $this->acc_id->value(), 'name' => $this->name->value(), 'total' => $this->total)); util::redirect('acc', 'load', array('id' => $this->id)); }
public function __construct() { parent::__construct(); security::logged_in(); $this->db = my_db::open(); }
{ if ($_SERVER['HTTP_HOST'] == 'localhost' || substr($_SERVER['HTTP_HOST'], 0, 3) == '10.' || $_SERVER['HTTP_HOST'] == 'which-widgets-build.app.local' || substr($_SERVER['HTTP_HOST'], 0, 7) == '192.168') { return true; } return false; } $localEnv = is_local(); if ($localEnv) { //local define('DB_MAIN', '127.0.0.1|root|abc123|widgets'); } else { //live define('DB_MAIN', 'db.test.which-testing.co.uk|widget|SRTe89VG973R|widget'); } // Connect to database db1 $db = new my_db(DB_MAIN); //retrieve token $token = $_GET['tkn']; $rows = $db->fetchAll('SELECT * FROM embed WHERE token="' . $token . '"'); //get signup count from the tools $count = file_get_contents("https://whichcouk.cp.bsd.net/utils/cons_counter/signup_counter.ajax.php?signup_form_id=" . $rows[0]->form_ID); $count = $count + 10000; $count = number_format($count); //add signup count to the db rows returned array_push($rows, array('signup' => $count)); echo json_encode($rows); class my_db { private static $databases; private $connection; public function __construct($connDetails)
public function post() { $this->message = ''; $this->name->post(); $this->date->post(); $this->total = 0; foreach ($this->entry as $entry) { $entry['acc_id']->post(); $entry['amount']->post(); $this->total += (double) $entry['amount']->value(); } switch (key($_POST['action'])) { case 'set': break; case 'commit': // validate if (abs($this->total) < 0.01) { if (count($this->entry) > 1) { $ok = true; foreach ($this->entry as $entry) { if (abs($entry['amount']->value()) < 0.01) { $ok = false; } } if ($ok) { $this->db = my_db::open(); $this->db->query('begin'); $this->id = $this->db->set($this->id, 'trn', array('name' => $this->name->value(), 'dte' => $this->date->value())); $ids = array(); foreach ($this->entry as $entry) { if ($entry['id']) { $ids[] = $entry['id']; } } if ($ids) { $this->db->query('delete from ent where trn_id=? and id not in (' . join(',', $ids) . ')', $this->id); } foreach ($this->entry as &$entry) { $entry['id'] = $this->db->set($entry['id'], 'ent', array('trn_id' => $this->id, 'acc_id' => $entry['acc_id']->value(), 'amount' => $entry['amount']->value())); } unset($entry); $this->db->query('commit'); util::redirect('trn', 'load', array('id' => $this->id)); } else { $this->message = 'One or more entries has a balance of 0.00'; } } else { $this->message = 'There must be two or more entries to commit.'; } } else { $this->message = 'Your total must be 0.00'; } break; case 'cancel': util::redirect('secure'); case 'remove': $i = key($_POST['action']['remove']); $this->total -= $this->entry[$i]['amount']->value(); unset($this->entry[$i]); break; case 'add': $this->add_entry(); break; } util::redirect($this); }
<?php //This script inserts the generated markup and JS into the DB on W? server and assigns it a token so that it can retrieved require "config.php"; error_reporting(E_ALL); ini_set('display_errors', 'On'); //This script inserts the generated markup and JS into the DB on W? server and assigns it a token so that it can retrieved define('DB_MAIN', '' . $config['dbhost'] . '|' . $config['dbuser'] . '|' . $config['dbpass'] . '|' . $config['dbname'] . ''); // Connect to database db1 $db = new my_db(DB_MAIN); if ($_POST['type'] === "insert") { $sql = "INSERT INTO embed (token, form_id, thankyou_redirect, embed_script, embed_html, date_added) VALUES (:token, :formID, :thankyou, :embedJS, :embedHTML, :dateadded)"; $query = $db->insert($sql); } function crypto_rand_secure($min, $max) { //create token $range = $max - $min; if ($range < 1) { return $min; } // not so random... $log = ceil(log($range, 2)); $bytes = (int) ($log / 8) + 1; // length in bytes $bits = (int) $log + 1; // length in bits $filter = (int) (1 << $bits) - 1; // set all lower bits to 1 do { $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));