rendered paste body<?
error_reporting(E_ALL);
ini_set('display_errors', 'on');
print "eyeBeam license tool<br>\n";
include('../header.php');
$eyebeam = connect($dbconf['eyebeam']);
if ($_REQUEST['addlicenses'] == true) {
$path = './licenses/';
$file = 'licenses.txt';
$infile = $path . $file;
$amount = 0;
$lines = 0;
foreach(file($infile, FILE_SKIP_EMPTY_LINES) as $license) {
$lines++;
$license = rtrim($license);
$license = mysql_real_escape_string($license);
$query = "INSERT INTO `licenses` (licensekey, brandid) VALUES ('{$license}', '85944');";
print $query;
$result = mysql_query($query);
$amount = mysql_affected_rows() + $amount;
$amount = $amount < 0 ? 0 : $amount;
}
$amount = $lines - $amount;
print "$amount duplicate licenses were omitted.";
}
?>
<?php
class Database {
private $connections;
public $connection;
public $table;
public $fields = array();
public $oncondition;
public function __construct() {
require ('dbconf.php');
// Loop through hosts
// Loop through hosts
foreach($dbconf as $db => $props) {
$this->db = $db;
$this->server = $props['server'];
$this->user = $props['user'];
$this->passwd = $props['passwd'];
$this->dbname = $props['dbname'];
$this->connect();
}
}
private function connect() {
$this->connections[$this->db] = mysql_connect($this->server, $this->user, $this->passwd) or die(mysql_error());
mysql_select_db($this->dbname, $this->connections[$this->db]);
}
public function getDatabases() {
return array_keys($this->connections);
}
public function getConnections() {
return $this->connections;
}
public function set_conn($connection) {
$this->connection = $this->connections[$connection];
}
public function prepare($sql) {
$this->sql = $sql;
}
public function execute() {
$this->result = mysql_query($this->sql, $this->connection) or die(mysql_error());
$this->get_num_rows();
}
public function query($sql = null) {
$this->sql = $sql == null ? $this->sql : $sql;
$this->result = mysql_query($this->sql, $this->connection) or die(mysql_error());
}
public function select() {
$this->what = !isset($this->what) ? '*' : $this->what;
$this->sql = $this->oncondition == null ? "SELECT $this->what FROM $this->table" : "SELECT $this->what FROM $this->table WHERE $this->oncondition";
$this->query();
$this->get_num_rows();
}
public function insert() {
// loop through the fields..
$fields = '';
$values = '';
foreach ($this->fields as $field => $value) {
$fields .= $field . ",";
$values .= "'" . $value . "',";
}
// strip the trailing , off of the fields/values
if ( substr( $fields, -1 ) == ',' ) {
$this->fields = substr( $fields, 0, -1 );
}
if ( substr( $values, -1 ) == ',' ) {
$this->values = substr( $values, 0, -1 );
}
$this->sql = "INSERT INTO `$this->table` ($this->fields) VALUES ($this->values);";
print $this->sql;
$this->query();
$this->get_affected_rows();
}
public function update() {
}
public function set_on($oncondition) {
$this->oncondition = $oncondition;
}
public function fetch_array() {
$this->result = mysql_fetch_array($this->result);
}
public function fetch_assoc() {
$this->result = mysql_fetch_assoc($this->result);
}
public function get_num_rows(){
$this->rows = mysql_num_rows($this->result);
}
public function get_affected_rows(){
$this->rows = mysql_affected_rows();
}
}
?>
private function manage_licenses_add() {
if (isset($_FILES) && isset($_POST['brandid'])) {
$db =& $this->db;
// $path = './licenses/';
// $file = 'licenses.txt';
$db->set_conn('eyebeam');
$db->table = 'licenses';
$brandid = $_POST['brandid'];
$path = $_FILES['licensefile']['tmp_name'];
$file = '';
$infile = $path . $file;
$amount = 0;
$lines = 0;
foreach(file($infile, FILE_SKIP_EMPTY_LINES) as $license) {
$lines++;
$license = rtrim($license);
$license = mysql_real_escape_string($license);
$brandid = mysql_real_escape_string($brandid);
$db->fields = array('licensekey' => $license, 'brandid' => $brandid);
$db->insert();
//
// $query = "INSERT INTO `licenses` (licensekey) VALUES ('{$license}');";
// $result = mysql_query($query);
$added = $db->rows + $added;
$added = $added < 0 ? 0 : $added;
}
$amount = $lines - $amount;
$this->smarty->assign('duplicates',$amount);
}
}