public static function createInstance($server, $user, $password, $db, $encoding)
 {
     self::$_instance = new self($server, $user, $password, $db, $encoding);
 }
Example #2
0
 public function deleteType($id)
 {
     try {
         if ($id == null || $id == -1) {
             return false;
         }
         if (!parent::getBdd()->inTransaction()) {
             parent::getBdd()->beginTransaction();
         }
         $query = "DELETE FROM TYPE WHERE ID = :id";
         $request = parent::getBdd()->prepare($query);
         $request->bindParam(':id', $id);
         $request->execute();
         parent::getBdd()->commit();
         $request->closeCursor();
         return true;
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return false;
 }
Example #3
0
<!-- Script for extending table of short IDs -->

<?php 
// Administrator Page used to extend the Link characters used.
// autoload the database class so we can easily connect to the database as required.
function __autoload($class_name)
{
    require $class_name . '.php';
}
$datab = new DataBaseConnection();
$datab->connectSelect();
// Array to hold the characters for the algorithm
$arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
// Array to hold number of possible links per characters in the shortlink
$arrLinks = array(1 => 62, 2 => 3906, 3 => 242234, 4 => 15018570);
// Function to calculate the quantities to be displayed.
function calculateQuantities($datab, $arrLinks, &$linksTotal, &$linksAvailable, &$linksTotal, &$linksUsed, &$linksNextExtend)
{
    // Get the max link from the link table, this is the number of links in the database.
    $sql = "SELECT max(id) FROM link";
    $result = mysqli_query($datab->link, $sql);
    // Check if the query didn't run
    if (!$result) {
        echo "Could not create new link, database error" . mysql_error();
        die;
    } else {
        $row = mysqli_fetch_array($result, MYSQLI_NUM);
        $linksUsed = $row[0];
    }
    // Find the available links by getting the max id from the linklookup table and taking the used links away from it.
    $sql = "SELECT max(id) FROM linklookup";
Example #4
0
<?php

// Page that allows the user to maintain their links and password.
session_start();
// autoload the database class so we can easily connect to the database as required.
function __autoload($class_name)
{
    require $class_name . '.php';
}
$datab = new DataBaseConnection();
$datab->connectSelect();
// Function to check that the password is valid and that they match.
function checkEntries(&$arr)
{
    // If pass length <10 or pass has no numbersthen report as bad
    if (strlen($_POST['newPass']) < 10 || preg_match("/\\d/", $_POST['newPass']) == 0) {
        $arr["newPass"] = "******";
    }
    // Check if the confirm password is the same as the new password
    if ($_POST['newPass'] != $_POST['confirmNewPass']) {
        $arr["confirmPass"] = "******";
    }
    // If new password is valid and has been confirmed correctly
    if (!empty($arr["newPass"]) || !empty($arr["confirmNewPass"])) {
        return false;
    } else {
        return true;
    }
}
// Create an array to hold invalid entries for Registration
$validationArray = array("newPass" => "", "confirmPass" => "", "email" => "");
Example #5
0
 public function getContactByName($firstName, $name)
 {
     if ($name == null) {
         return null;
     }
     $list = [];
     try {
         if (!parent::getBdd()->inTransaction()) {
             parent::getBdd()->beginTransaction();
         }
         if ($firstName != null) {
             $query = "SELECT * FROM CONTACT WHERE firstName like :firstName and name like :name";
         } else {
             $query = "SELECT * FROM CONTACT WHERE name like :name";
         }
         $request = parent::getBdd()->prepare($query);
         if ($firstName != null) {
             $firstName = '%' . $firstName . '%';
             $request->bindParam(':firstName', $firstName);
         }
         $name = '%' . $name . '%';
         $request->bindParam(':name', $name);
         $request->execute();
         while ($data = $request->fetch()) {
             $contact = $this->parseContact($data);
             array_push($list, $contact);
         }
         $request->closeCursor();
         if ($list == []) {
             return null;
         }
         return $list;
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return null;
 }
Example #6
0
 public function getAddressesByRayon($address, $rayon)
 {
     $list = [];
     try {
         if (!parent::getBdd()->inTransaction()) {
             parent::getBdd()->beginTransaction();
         }
         $query = "SELECT *, ( 6371 * acos( cos( radians(:latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:longitude) )\n              + sin( radians(:latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM address HAVING distance < :rayon ORDER BY distance LIMIT 0 , 150;";
         $request = parent::getBdd()->prepare($query);
         $request->bindParam(':latitude', $address->getLatitude());
         $request->bindParam(':longitude', $address->getLongitude());
         $request->bindParam(':rayon', $rayon);
         $request->execute();
         while ($data = $request->fetch()) {
             $address = new Address();
             $address->setId($data['id']);
             $address->setLine1($data['line1']);
             $address->setLine2($data['line2']);
             $address->setZipCode($data['zipcode']);
             $address->setCity($data['city']);
             $address->setLatitude($data['latitude']);
             $address->setLongitude($data['longitude']);
             array_push($list, $address);
         }
         if ($list == []) {
             return null;
         }
         return $list;
     } catch (Exception $e) {
         error_log($e->getMessage());
     }
     return null;
 }
Example #7
0
 public function __construct()
 {
     $this->connection = DataBaseConnection::getInstance();
 }