Esempio n. 1
0
 public static function thumbnail($img)
 {
     $thumbnail = imagecreatetruecolor(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
     $black = imagecolorallocate($thumbnail, 0, 0, 0);
     imagecolortransparent($thumbnail, $black);
     $image = $img[0];
     $file_name = $img[1];
     $src_width = imagesx($image);
     $src_height = imagesy($image);
     /*        $src_width = $img[2][0];
             $src_height = $img[2][0];*/
     imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, $src_width, $src_height);
     //create a new directory for each day
     $date = date('Y-m-d');
     $dir = 'Images/small/' . $date . '/';
     if (!is_dir($dir)) {
         mkdir($dir, 0777);
     }
     imagejpeg($thumbnail, $dir . $file_name . '-small.jpeg');
     $db_writer = new DBWorker();
     $db_writer->saveImage(56700, $file_name, $date);
     imagedestroy($thumbnail);
     imagedestroy($image);
     unset($img);
 }
Esempio n. 2
0
 public static function listCities($tag = 'li')
 {
     $cities = DBWorker::getCities();
     if (!empty($cities)) {
         foreach ($cities as $city) {
             if ($tag == 'option') {
                 echo '<option value="' . $city['id'] . '">' . $city['city'] . '</option>';
             } else {
                 echo '<li>' . $city['city'] . '</li>';
             }
         }
     }
 }
Esempio n. 3
0
 public function __construct($user_id)
 {
     $this->uid = $user_id;
     $user = DBWorker::getRow('SELECT * FROM users WHERE user_id = :uid AND active = 1', ':uid', $user_id);
     if ($user) {
         $this->email = $user['email'];
         $this->alias = $user['alias'];
         $this->name = $user['name'];
         $this->city = $user['city'];
         $this->phone = $user['phone'];
         $this->about = $user['about'];
         $this->sex = $user['sex'];
         $this->date_joined = $user['date_joined'];
     }
 }
Esempio n. 4
0
 /**
  * @param $token
  * @param null $user_agent_string
  * @param string $intent save, kill or Update session
  * @param stringuser_id
  * @return bool success
  */
 public static function alter($token, $user_agent_string = null, $intent, $user_id = null)
 {
     $sid = filter_var($token, FILTER_SANITIZE_STRING);
     $uas = filter_var($user_agent_string, FILTER_SANITIZE_STRING);
     $uid = Helper::word($user_id);
     $status = false;
     $sql = '';
     switch ($intent) {
         case 'save':
             $sql = 'INSERT INTO session (user_id, token, user_agent_string, expires) VALUES (:uid, :sid , :uas, DATE_ADD(NOW(), INTERVAL 1 MINUTE ))';
             setcookie('_ut35', $sid, COOKIE_LIFE);
             $_SESSION['uid'] = $user_id;
             break;
         case 'kill':
             setcookie('_ut35', null, time() - 1000);
             $sql = 'DELETE FROM session WHERE token = :sid  AND user_agent_string = :uas';
             break;
         case 'update':
             $sql = 'UPDATE session SET token = :sid, expires = DATE_ADD(NOW(), INTERVAL 2 MINUTE) WHERE token = :sid AND user_agent_string = :uas';
             // $_SESSION['uid'] = $user_id;
             setcookie('_ut35', $sid, COOKIE_LIFE);
             break;
         default:
             break;
     }
     try {
         $dbh = DBWorker::connect();
         $stmt = $dbh->prepare($sql);
         $stmt->bindParam(":sid", $sid, PDO::PARAM_STR);
         $stmt->bindParam(":uas", $uas, PDO::PARAM_STR);
         if ($intent == 'save') {
             $stmt->bindParam(':uid', $uid, PDO::PARAM_STR);
         }
         $stmt->execute();
         $status = $stmt->rowCount() > 0;
         DBWorker::disconnect($dbh);
     } catch (Exception $ex) {
         die($ex->getMessage());
     }
     return $status;
 }
Esempio n. 5
0
 /**
  * @return bool
  *Pull password from schema and check it against user password
  */
 public function check()
 {
     if (Helper::validateEmail($this->email) == true) {
         //if email is invalid don't bother checking in the schema
         $user = DBWorker::getRow('SELECT password FROM users WHERE email = :email AND active = 1', ':email', $this->email);
         if (!$user) {
             $this->valid = false;
             $this->error = '<p class="warning"><strong>Error :</strong>Username and password do not match </p>';
             //email is found. go on to check the password
         } elseif ($user) {
             //match user password against the one in the found row in the schema
             if (crypt($this->pass, $user['password']) === $user['password']) {
                 $this->valid = true;
             } else {
                 $this->error = '<p class="warning"><strong>Error :</strong>Username and password do not match </p>';
             }
         }
     } else {
         $this->error = '<p class="warning"><strong>Error :</strong> Please enter a valid email</p>';
         $this->valid = false;
     }
     return $this->valid;
 }
Esempio n. 6
0
        if (isset($_SESSION['uid'])) {
            $debug['COOKIE_OK_l'] = true;
        }
        header('Location: panel.php');
    }
}
$auth = null;
$error = '';
$user = null;
//Post data
if (isset($_POST['email']) && isset($_POST['password'])) {
    $email = isset($_POST['email']) ? trim($_POST['email']) : '';
    $pass = isset($_POST['password']) ? trim($_POST['password']) : '';
    $auth = new Auth($email, $pass);
    if ($auth->check() === false) {
        $error = $auth->getError();
    } else {
        if (!empty($_POST['keep_session'])) {
            if ($_POST['keep_session'] == 'keep_session') {
                $user = DBWorker::getRow('SELECT user_id FROM users WHERE email = :email AND active = 1', ':email', $email);
                Session::alter(Numbers::_randKey(), $user_agent_string, 'save', $user['user_id']);
                $debug['SaveSession'] = true;
            }
        }
        $debug['login'] = true;
        header('Location: panel.php');
    }
}
/*var_dump($debug);
var_dump($_SESSION);
var_dump($_COOKIE);*/
Esempio n. 7
0
 * User: Peter
 * Date: 8/14/15
 * Time: 6:39 PM
 * To change this template use File | Settings | File Templates.
 */
session_start();
if (isset($_SESSION['uid'])) {
    header('Location: home.php');
    exit;
}
require_once "includes/database/DBWorker.php";
$success = null;
if (!empty($_POST['login'])) {
    $user_name = !empty($_POST['username']) ? trim($_POST['username']) : '';
    $password = !empty($_POST['password']) ? $_POST['password'] : '';
    $user = DBWorker::getRow('SELECT * FROM users WHERE username = :username', ':username', $user_name);
    if ($user) {
        if (md5($password) == $user['password']) {
            $_SESSION['uid'] = md5($username);
            $_SESSION['username'] = $username;
            header('Location: home.php');
            exit;
        }
    }
    $success = false;
}
?>
<!doctype html>
<html>
<head>
    <link rel="stylesheet" href="css/header.css" type="text/css"/>
Esempio n. 8
0
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Peter
 * Date: 8/9/15
 * Time: 11:12 PM
 * To change this template use File | Settings | File Templates.
 */
require_once "auth.inc.php";
require_once "includes/database/DBWorker.php";
require_once "includes/utils/helper.class.php";
$error_msg = array();
$success = false;
$dbh = new DBWorker();
$app_id = isset($_GET['app']) ? abs($_GET['app']) : null;
$app = null;
if (isset($app_id)) {
    $app = DBWorker::getRow('SELECT * FROM apps WHERE id = :id', ':id', $app_id);
}
if (isset($_POST['add_app'])) {
    $id = isset($_POST['id']) ? abs($_POST['id']) : -1;
    $app_date = $_POST['app_date'];
    $app_summary = trim($_POST['app_summary']);
    $patient_name = $_POST['patient_name'];
    if (preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $app_date) < 1) {
        $error_msg[] = 'Invalid date';
    }
    if (strlen(trim($patient_name)) < 3) {
        $error_msg[] = 'Client name too short';
    }
Esempio n. 9
0
    $page = 1;
}
$view_option = 'monthly';
$limit = 47;
if (!empty($_GET['view'])) {
    if ($_GET['view'] == 'weekly') {
        $limit = 7;
        $view_option = 'weekly';
    }
}
$start = time() + ($page - 1) * $limit * 86400;
$offset = strtotime("Monday this week", $start);
$dbh = new DBWorker();
$apps = null;
$get_apps = 'SELECT * FROM apps WHERE app_date > UNIX_TIMESTAMP(NOW())';
$apps = DBWorker::getRows($get_apps);
function search($time)
{
    global $apps;
    if (!empty($apps)) {
        foreach ($apps as $app) {
            if (in_array($time, $app)) {
                return $app['app_date'];
            }
        }
    }
    return false;
}
$stats = array('today' => 0, 'this_week' => 0, 'this_month' => 0, 'this_year' => 0);
function countApps()
{
Esempio n. 10
0
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Peter
 * Date: 8/9/15
 * Time: 11:13 PM
 * To change this template use File | Settings | File Templates.
 */
require_once "auth.inc.php";
require_once "includes/database/DBWorker.php";
$day = !empty($_GET['app']) ? intval($_GET['app']) : 0;
$apps = null;
$lower_limit = strtotime('midnight today', $day);
$upper_limit = $lower_limit + 86400;
$app_to_delete = !empty($_GET['h']) ? $_GET['h'] : null;
if ($app_to_delete) {
    DBWorker::lookup('DELETE FROM apps WHERE id = :id', ':id', $app_to_delete);
}
$get_apps_today = "SELECT * FROM apps WHERE app_date >= {$lower_limit} AND app_date <= {$upper_limit}";
$apps = DBWorker::getRows($get_apps_today);
//echo '<pre>', print_r($apps), '</pre>';
Esempio n. 11
0
 private function checkPhone()
 {
     if (Helper::validatePhone(trim($this->phone)) === false) {
         User::addError('phone', 'Please enter a valid phone number');
     } elseif (DBWorker::lookup('SELECT * FROM users WHERE phone = :phone', ':phone', Helper::filterPhone($this->phone)) === true) {
         User::addError('phone', 'Number already exists');
     }
 }
Esempio n. 12
0
 * Created by JetBrains PhpStorm.
 * User: Peter
 * Date: 8/14/15
 * Time: 6:39 PM
 * To change this template use File | Settings | File Templates.
 */
require_once "auth.inc.php";
require_once "includes/database/DBWorker.php";
$success = null;
if (!empty($_POST['login'])) {
    $user_name = !empty($_POST['username']) ? trim($_POST['username']) : '';
    $name = !empty($_POST['name']) ? trim($_POST['name']) : '';
    $password = !empty($_POST['password']) ? $_POST['password'] : '';
    $email = !empty($_POST['email']) ? $_POST['email'] : '';
    $password = !empty($_POST['password']) ? $_POST['password'] : '';
    $db = new DBWorker();
    $vars = array(':username' => $user_name, ':password' => md5($password), ':email' => $email, ':name' => $name);
    $db->insertMany('INSERT INTO users (username, password, email, name) VALUES (:username, :password, :email, :name)', $vars);
    $success = true;
}
?>
<!doctype html>
<html>
<head>
    <link rel="stylesheet" href="css/header.css" type="text/css"/>
    <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/bootstrap-theme.min.css" type="text/css"/>
    <style type="text/css">
        .container {
            width: 400px;
            margin: auto;
Esempio n. 13
0
            $resend = false;
        } else {
            $error = 'Invalid activation key please enter your email to get your key';
        }
    }
}
if (isset($_POST['email'])) {
    $email = trim($_POST['email']);
    if (strlen($email) < 6 || strlen($email) > 32 || preg_match('/[^a-zA-Z0-9_@\\.]/', $email)) {
        $error = 'Invalid email';
    } else {
        $user = DBWorker::getRow('SELECT * FROM users WHERE email = :email AND active = 0', ':email', Helper::filterEmail($email));
        if ($user !== false) {
            $uid = filter_var($user['user_id'], FILTER_SANITIZE_STRING);
            $key = DBWorker::getRow('SELECT * FROM confirmation WHERE user_id = :uid', ':uid', $uid);
            if ($key !== false) {
                $token = $key['user_key'];
                $user_id = $key['user_id'];
                P_MAIL::sendConfirmation($user_id, $key['user_key'], $user['alias'], $user['email']);
            } else {
                //the key is unavailable
                DBWorker::insert('INSERT INTO confirmation (user_id, user_key, expires) VALUES (:uid, ' . filter_var(Numbers::_randKey(), FILTER_SANITIZE_NUMBER_INT) . ', DATE_ADD(NOW(), INTERVAL 6 MONTH ))', ':uid', $user['user_id']);
                //resend key to user's mail box
                P_MAIL::sendConfirmation($user['user_id'], Numbers::_randKey(), $user['alias'], $user['email']);
            }
        } elseif (DBWorker::getRow('SELECT * FROM users WHERE email = :email AND active = 1', ':email', Helper::filterEmail($_POST['email']))) {
            $error = 'Account already activated. Please <a href="../user/login.php?' . $append . '">login</a> to access your panel';
            $resend = false;
        }
    }
}