Example #1
0
 /**
  * Create a new order record and return the last inserted orderId
  * @return int
  */
 protected function createOrderRecord()
 {
     $userId = $this->session->get('user_id');
     $query = '
     insert into
         aca_order (user_id, order_date)
     values
         (' . $userId . ', NOW())';
     return $this->db->executeSql($query);
 }
Example #2
0
 public function getOrderProducts()
 {
     $orderId = $this->session->get('completed_order_id');
     $query = '
         select
               *
         from
         	  aca_order_product op
         	  left join aca_product p on (op.product_id = p.product_id)
         	  left join aca_cart c on (op.order_id = c.cart_id)
         WHERE
               order_id = "' . $orderId . '"';
     return $this->db->fetchRowMany($query);
 }
Example #3
0
 /**
  * Determine if a new proposed user profile can be created, provide status message, and if info is valid create new user
  * @param $username
  * @param $password
  * @param $passwordCheck
  * @param $name
  * @return null|string
  * @throws \Simplon\Mysql\MysqlException
  */
 public function checkRegistration($username, $password, $passwordCheck, $name)
 {
     $msg = null;
     // If some fields are left empty tell user
     if (empty($username) || empty($password) || empty($passwordCheck) || empty($name)) {
         $msg = 'Please make sure you have entered information in all fields';
         // Prevent MySQL injection - if anything uses illegal characters, tell user
     } else {
         if (!preg_match("#^[a-zA-Z0-9]+\$#", $username) || !preg_match("#^[a-zA-Z0-9]+\$#", $password) || !preg_match("#^[a-zA-Z0-9]+\$#", $passwordCheck) || !preg_match("#^[a-zA-Z0-9]+\$#", $name)) {
             $msg = 'Make sure everything contains only numbers and letters';
             // Now that we know there is no MySQL injection, query DB to make sure login doesn't already exist
         } else {
             if (!$this->registrationIsNew($username)) {
                 $msg = 'That username already exists - please try another';
                 // Login does not exist but password was entered improperly
             } else {
                 if ($password != $passwordCheck) {
                     $msg = 'Please make sure you properly entered your password in both fields';
                     // Login does not exist and password was entered properly
                 } else {
                     // Create new user
                     $userId = $this->db->insert('aca_user', array('name' => $name, 'username' => $username, 'password' => $password));
                     // Set render array variable now that user credentials have been created
                     $loggedIn = true;
                     // Set and save session values
                     $this->setSession($loggedIn, $name, $username, $password, $userId);
                 }
             }
         }
     }
     return $msg;
 }
Example #4
0
 /**
  * Delete the entire shopping cart
  * @throws Exception
  */
 public function nixCart()
 {
     $cartId = $this->getCartId();
     $this->db->delete('aca_cart_product', array('cart_id' => $cartId));
     $this->db->delete('aca_cart', array('cart_id' => $cartId));
     //create a new black cart
     //        $this->getCartId();
 }
Example #5
0
    public function getAllCartProducts()
    {
        $userId = $this->session->get('user_id');
        $query = 'select
            cp.id,
            p.name,
            p.description,
            p.image,
            cp.unit_price as price,
            cp.qty
        from
	        aca_cart_product as cp
	        left join aca_product as p on(p.id = cp.product_id)
	        left join aca_cart as c on(c.id = cp.cart_id)
        where
	        c.user_id = ' . $userId;
        return $this->db->fetchRowMany($query, array('myCartid' => $this->getCartId()));
    }
Example #6
0
 /**
  * Get array of order details such as shipping and billing data
  * @return array|null
  */
 public function getSessionOrderDetails()
 {
     $query = '
         SELECT
           *
         FROM
           aca_order
         WHERE
           id= :orderId';
     $data = $this->db->fetchrow($query, array('orderId' => $this->session->get('order_id')));
     return $data;
 }
Example #7
0
 /**
  * Updated a user's email
  * @param string $newEmail
  * @throws \Simplon\Mysql\MysqlException
  */
 public function updateEmail($newEmail)
 {
     $this->db->update('aca_user', array('id' => $this->session->get('user_id')), array('email' => $newEmail));
 }
Example #8
0
 /**
  * Delete a shopping cart. Because SRP
  * @see https://en.wikipedia.org/wiki/Single_responsibility_principle
  * @throws \Exception
  */
 public function nixCart()
 {
     $cartId = $this->getCartId();
     $this->db->delete('aca_cart_product', array('cart_id' => $cartId));
     $this->db->delete('aca_cart', array('id' => $cartId));
 }
 public function __construct($host, $user, $password, $database, $fetchMode = \PDO::FETCH_ASSOC, $charset = 'utf8', array $options = array())
 {
     parent::__construct($host, $user, $password, $database, $fetchMode, $charset, $options);
 }
Example #10
0
 /**
  * Updates the quantity of a product in the cart.
  * @param int $cartProductID
  * @param int $newQty
  * @return bool
  * @throws \Simplon\Mysql\MysqlException
  */
 public function updateProductQty($cartProductID, $newQty)
 {
     return $this->db->update('aca_cart_product', array('id' => $cartProductID), array('quantity' => $newQty));
 }
Example #11
0
 /**
  * Delete a shopping cart
  * @throws \Exception
  */
 public function removeCart()
 {
     // Delete order from cart
     $this->db->delete('aca_cart_product', array('cart_id' => $this->cartId));
     $this->db->delete('aca_cart', array('id' => $this->cartId));
 }
 *
 */
// App config
require 'config.php';
//
// Use Dependencies
//
use Simplon\Mysql\Mysql as Connection;
// MySql Connection
use Mailgun\Mailgun;
// Mailgun wrapper
//
// DB connect
//
$dbcfg = unserialize(DB_CONFIG);
$db = new Connection($dbcfg['host'], $dbcfg['user'], $dbcfg['password'], $dbcfg['database'], $dbcfg['fetchMode'], $dbcfg['charset'], array('port' => $dbcfg['port']));
//
// Get the newest posted article
//
$article = $db->fetchRow("\n    SELECT \n        * \n    FROM \n        jobarticles\n    WHERE \n        post_id > 0\n        AND \n        sent_at IS NULL\n    ORDER BY \n        date DESC\n    LIMIT 1\n");
if (!$article) {
    echo "no articles to send";
    exit;
}
//
// Preparing Article for inserting in article
//
$letter_template = file_get_contents('letter_template.html');
$content_full = $article['content'];
$cut_pos = strpos(strip_tags($content_full), ' ', 330);
$content_short = substr(strip_tags($content_full), 0, $cut_pos);
require 'config.php';
// App config
require 'filter_article.php';
// Articles' filters
//
// Use Dependencies
//
use PicoFeed\Reader\Reader;
// RSS Reader
use Simplon\Mysql\Mysql as Connection;
// MySql Connection
//
// DB connect
//
$dbcfg = unserialize(DB_CONFIG);
$db = new Connection($dbcfg['host'], $dbcfg['user'], $dbcfg['password'], $dbcfg['database'], $dbcfg['fetchMode'], $dbcfg['charset'], array('port' => $dbcfg['port']));
//
// Loop through every source
//
foreach (unserialize(ARTICLE_FEEDS) as $source_id => $source_url) {
    echo sprintf("Source #%d (%s). ---- Go:<br>", $source_id, $source_url);
    //
    // RSS fetch
    //
    try {
        $reader = new Reader();
        $resource = $reader->download($source_url);
        $parser = $reader->getParser($resource->getUrl(), $resource->getContent(), $resource->getEncoding());
        $feed = $parser->execute();
    } catch (Exception $e) {
        echo "RSS Fetch Error: " . $e->getMessage();
 * @category   JobArticle
 * @author     Larry Cinnabar
 *
 */
// App config
require 'config.php';
//
// Use Dependencies
//
use Simplon\Mysql\Mysql as Connection;
// MySql Connection
//
// DB connect
//
$dbcfg = unserialize(DB_CONFIG);
$db = new Connection($dbcfg['host'], $dbcfg['user'], $dbcfg['password'], $dbcfg['database'], $dbcfg['fetchMode'], $dbcfg['charset'], array('port' => $dbcfg['port']));
//
// Get the oldest unsent article
//
$article = $db->fetchRow("\n    SELECT \n        * \n    FROM \n        jobarticles\n    WHERE \n        post_id = 0\n    ORDER BY \n        date ASC\n    LIMIT 1\n");
if (!$article) {
    echo "no articles to post";
    exit;
}
//
// Post this article
$post_id = -1;
// Setup the author, slug, and title for the post
$slug = $article['source_id'] . '_' . slugify($article['title']);
$title = $article['title'];
// If the page doesn't already exist, then create it