Exemplo n.º 1
0
 public function get($data = null)
 {
     parent::__construct(array(), ArrayObject::ARRAY_AS_PROPS);
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             if (is_array($value)) {
                 $value = new self($value);
             }
             $this->offsetSet($key, $value);
         }
     } else {
         if ($data instanceof self) {
             $data = $this->toArray($data);
             $this->get($data);
         } else {
             if (is_string($data)) {
                 $db = MySQL::getInstance();
                 $db->query($data);
                 if ($db->numRows() > 0) {
                     $this->get($db->fetchRow());
                 }
             }
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 public function updateSorting($itemID, $sorting)
 {
     $db = MySQL::getInstance();
     foreach ($sorting as $position => $id) {
         $db->query("UPDATE `catalog_image` SET `Position` = " . $db->escape((int) $position) . "\n\t\t\t\tWHERE ItemID = " . $db->escape($itemID) . " AND ImageID = " . $db->escape((int) $id));
     }
 }
Exemplo n.º 3
0
function getSuburbMetroARIA($suburbName)
{
    $query = MySQL::getInstance()->prepare("SELECT MIN(metroariac) as minariac, ROUND(AVG(metroariac),0) as avgariac, MAX(metroariac) as maxariac,\n\t\t\t\tMIN(metroedu) as minedu, ROUND(AVG(metroedu),0) as avgedu, MAX(metroedu) as maxedu,\n\t\t\t\tMIN(metrofinpost) as minfinpost, ROUND(AVG(metrofinpost),0) as avgfinpost, MAX(metrofinpost) as maxfinpost,\n\t\t\t\tMIN(metrohealth) as minhealth, ROUND(AVG(metrohealth),0) as avghealth, MAX(metrohealth) as maxhealth,\n\t\t\t\tMIN(metrotransport) as mintransport, ROUND(AVG(metrotransport),0) as avgtransport, MAX(metrotransport) as maxtransport,\n\t\t\t\tMIN(metroshop) as minshop, ROUND(AVG(metroshop),0) as avgshop, MAX(metroshop) as maxshop,\n\t\t\t\tCOUNT(metroariac) as cnt FROM metro WHERE locality = :suburbName");
    $query->bindValue("suburbName", $suburbName, PDO::PARAM_STR);
    $query->execute();
    return $query->fetchALL();
}
Exemplo n.º 4
0
function send_payload($payload)
{
    $query = MySQL::getInstance()->prepare("INSERT INTO queue (payload) VALUES (:payload)");
    $query->bindValue(':payload', $payload, PDO::PARAM_STR);
    $query->execute();
    log_operation('send');
}
Exemplo n.º 5
0
 public function updateSorting($newsletterID, $sorting)
 {
     $db = MySQL::getInstance();
     foreach ($sorting as $position => $id) {
         $db->query("UPDATE newsletter_image SET `Position` = " . $db->escape((int) $position) . "\n\t\t\t\tWHERE NewsletterID = " . $db->escape($newsletterID) . " AND ImageID = " . $db->escape((int) $id));
     }
 }
Exemplo n.º 6
0
function save_comment($article_id, $name, $body)
{
    $query = MySQL::getInstance()->prepare("INSERT INTO comments (article_id, name, body) VALUES (:article_id, :name, :body)");
    $query->bindValue(':article_id', $article_id, PDO::PARAM_INT);
    $query->bindValue(':name', $name, PDO::PARAM_STR);
    $query->bindValue(':body', $body, PDO::PARAM_STR);
    $query->execute();
}
Exemplo n.º 7
0
 public function __construct(Request $request)
 {
     $this->_request = $request;
     $this->_template = new Template();
     $this->_template->_controller($request->controller())->_module($request->module())->_action($request->action());
     $params = array('user' => 'sharpy', 'password' => 'sharpy', 'dbname' => 'sharpy', 'host' => 'localhost');
     $this->_db = MySQL::getInstance($params);
 }
Exemplo n.º 8
0
 public static function findPage(Controller $oController)
 {
     if (self::$currentPageID > 0) {
         return;
     }
     if ($oController->indexPage()) {
         $oPage = new Page();
         if ($oPage->loadIndexPage()) {
             if (Controller::getInstance()->controllerExists($oPage["Link"])) {
                 $oController->route[self::$level] = $oPage["Link"];
             }
             self::$level = 1;
             self::$page = $oPage;
             self::$currentPageID = $oPage->PageID;
         }
     } else {
         $db = MySQL::getInstance();
         $db->query("SELECT PageID, StaticPath, Level, LeftKey, RightKey, Link\n\t\t\t\tFROM `page` WHERE\n\t\t\t\t\tWebsiteID = " . $db->escape(WEBSITE_ID) . "\n\t\t\t\t\tAND StaticPath IN (" . implode(", ", $db->escape($oController->route)) . ")\n\t\t\t\t\tAND LanguageCode = " . $db->escape(LANG) . "\n\t\t\t\t\tAND Level > 1\n\t\t\t\tORDER BY LeftKey");
         self::$level = 0;
         $moduleFound = false;
         $currentPageID = null;
         while ($row = $db->fetchRow()) {
             if ($row["StaticPath"] == $oController->route[0] && $row["Level"] == 2) {
                 $currentPageID = $row["PageID"];
                 self::$currentLeftKey = $row["LeftKey"];
                 self::$currentRightKey = $row["RightKey"];
                 if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                     $oController->route[0] = $row["Link"];
                     break;
                 }
                 self::$level++;
                 continue;
             }
             if (!is_null($currentPageID) && count($oController->route) > self::$level) {
                 if ($row["StaticPath"] == $oController->route[self::$level] && $row["LeftKey"] > self::$currentLeftKey && $row["RightKey"] < self::$currentRightKey) {
                     $currentPageID = $row["PageID"];
                     self::$currentLeftKey = $row["LeftKey"];
                     self::$currentRightKey = $row["RightKey"];
                     if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                         $oController->route[self::$level] = $row["Link"];
                         break;
                     }
                     self::$level++;
                 }
             }
         }
         if (self::$level == count($oController->route) || $moduleFound != false) {
             $oPage = new Page();
             if ($oPage->loadByID($currentPageID)) {
                 self::$page = $oPage;
                 self::$currentPageID = $oPage->PageID;
             }
         }
     }
     for ($i = 0; $i < self::$level; $i++) {
         array_shift($oController->route);
     }
 }
Exemplo n.º 9
0
 private static function getKeys()
 {
     self::$vars = new Object();
     $db = MySQL::getInstance();
     $db->query('SELECT FieldName, FieldValue FROM `config`');
     while (list($key, $value) = $db->fetchRow()) {
         self::$vars->{$key} = $value;
     }
     self::$vars->Page = 1;
 }
Exemplo n.º 10
0
 public function load($id = null)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT * FROM `user` WHERE `UserID` = " . $db->escape((int) $id) . "");
     if ($row = $db->fetchRow()) {
         $this->data = $row;
         $this->loaded = true;
     }
     return $this;
 }
Exemplo n.º 11
0
 public function deleteFile($ID)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT `Image` FROM `catalog_brand` WHERE `BrandID` =" . $db->escape($ID));
     $fileName = $db->fetchField();
     if (!empty($fileName)) {
         File::delete($fileName, 'var/brand/');
         File::delete('thumb_' . $fileName, 'var/brand/');
     }
     $db->query("UPDATE `catalog_brand` SET `Image` = NULL WHERE `BrandID` =" . $db->escape($ID));
 }
Exemplo n.º 12
0
 public function isEmptyProperty($id)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT * FROM `catalog_property` WHERE `CategoryID` = " . $id);
     if ($db->numRows() == 0) {
         return true;
     } else {
         throw new Exception(lang('к подгруппе привязаны свойства..'));
         return false;
     }
 }
Exemplo n.º 13
0
Arquivo: Cp.php Projeto: kizz66/meat
 public function delete()
 {
     if (!empty($this->data[0])) {
         $db = MySQL::getInstance();
         $db->query("SELECT `FieldValue` FROM `config` WHERE `FieldName` = " . $db->escape($this->data[0]));
         if ($fileName = $db->fetchField()) {
             File::delete($fileName, 'var/upload/');
             $db->query("UPDATE `config` SET `FieldValue` = '' WHERE `FieldName` = " . $db->escape($this->data[0]));
         }
     }
     redirect(BASE_PATH . 'admin/cp');
 }
Exemplo n.º 14
0
 /**
  * Start testing
  *
  * @return void
  */
 public function __construct()
 {
     // Set text on browser
     if (php_sapi_name() != 'cli') {
         header('Content-type: text/plain');
     }
     // Set object
     $this->_object = MySQL::getInstance();
     // Get tests
     $tests = get_class_methods($this);
     // Set print mask
     $masker = "| %-30.30s | %7s |" . PHP_EOL;
     // Print header
     printf($masker, '------------------------------', '-------');
     printf($masker, 'Test', 'Result');
     printf($masker, '------------------------------', '-------');
     // Load db first
     $link = mysql_connect(TEST_HOST, TEST_USER, TEST_PASS);
     $statements = explode(';', file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'MySQL_Test_Schema.sql'));
     foreach ($statements as $statement) {
         mysql_query(trim($statement)) or die(mysql_error());
     }
     mysql_close($link);
     // Go through each test
     foreach ($tests as $test) {
         // Skip private/protected methods
         if (substr($test, 0, 1) == '_') {
             continue;
         }
         // Get mysql_* method
         $name = strtolower(str_replace('_Test', '', $test));
         // Increment # of tests
         $this->results['tests']++;
         // If it doesn't exist, naf it (not a function)
         if (!function_exists($name)) {
             $this->results['naf']++;
             printf($masker, $test, 'NAF');
             continue;
         }
         // Run tests
         if ($this->{$test}()) {
             $this->results['valid']++;
             printf($masker, $test, 'Success');
         } else {
             $this->results['invalid']++;
             printf($masker, $test, 'Failure');
         }
     }
     // Print footer
     printf($masker, '------------------------------', '-------');
 }
Exemplo n.º 15
0
function get_resource_type_custom($resource)
{
    return MySQL::getInstance()->get_resource_type($resource);
}
Exemplo n.º 16
0
 public function end()
 {
     $db = MySQL::getInstance();
     $db->close();
 }
Exemplo n.º 17
0
    public function delete($commentID)
    {
        $db = MySQL::getInstance();
        $db->query('SELECT LeftKey, RightKey, NewsletterID FROM `newsletter_comment` WHERE CommentID = ' . $db->escape((int) $commentID));
        if ($db->numRows() > 0) {
            list($leftKey, $rightKey, $newsletterID) = $db->fetchRow();
            $db->startTransaction();
            // Удалятся так же и дочерние сообщения
            $db->query('DELETE FROM `newsletter_comment`
				WHERE LeftKey >= ' . $db->escape((int) $leftKey) . '
					AND RightKey <= ' . $db->escape((int) $rightKey) . '
					AND NewsletterID = ' . $db->escape((int) $newsletterID));
            // Обновляем ключи сортировки
            $db->query('UPDATE `newsletter_comment` SET
					LeftKey = IF(LeftKey > ' . $db->escape((int) $leftKey) . ', LeftKey - (' . $db->escape((int) $rightKey) . ' - ' . $db->escape((int) $leftKey) . ' + 1), LeftKey),
					RightKey = RightKey - (' . $db->escape((int) $rightKey) . ' - ' . $db->escape((int) $leftKey) . ' + 1)
				WHERE RightKey > ' . $db->escape((int) $rightKey) . '
					AND NewsletterID = ' . $db->escape((int) $newsletterID));
            // Обновляем счетчик
            $db->query("UPDATE `newsletter_comment_count` SET\n\t\t\t\t\tCount = (\n\t\t\t\t\t\tSELECT COUNT(*) FROM `newsletter_comment` WHERE NewsletterID = " . $db->escape((int) $newsletterID) . "\n\t\t\t\t\t)\n\t\t\t\tWHERE NewsletterID = " . $db->escape((int) $newsletterID));
            $db->stopTransaction();
            return $newsletterID;
        }
        return false;
    }
Exemplo n.º 18
0
 public function deleteFile($newsletterIDs)
 {
     if (!is_array($newsletterIDs)) {
         $newsletterIDs = array($newsletterIDs);
     }
     $db = MySQL::getInstance();
     $db->query("SELECT `Image` FROM `newsletter` WHERE `NewsletterID` IN (" . implode(',', $db->escape($newsletterIDs)) . ")");
     while ($fileName = $db->fetchField()) {
         if (!empty($fileName)) {
             File::delete($fileName, 'var/newsletter/');
             File::delete('thumb_' . $fileName, 'var/newsletter/');
         }
     }
     $db->query("UPDATE `newsletter` SET `Image` = NULL WHERE `NewsletterID` IN (" . implode(',', $db->escape($newsletterIDs)) . ")");
 }
Exemplo n.º 19
0
    }
}
if (check_ver() == 'True') {
    setcookie("ie", "yes", time() + 60 * 60 * 24 * 360);
    header("Location: /ie6/ie6.html");
}
date_default_timezone_set('Asia/Novosibirsk');
define('START_TIME', microtime(true));
ob_start();
error_reporting(E_ALL | E_STRICT);
ini_set('register_globals', 0);
ini_set('display_errors', 1);
mb_internal_encoding('utf-8');
define('DOC_ROOT', realpath(dirname(__FILE__)) . "/");
define('CORE_ROOT', DOC_ROOT . 'core/');
include CORE_ROOT . 'error_handlers.php';
include CORE_ROOT . 'config.php';
include CORE_ROOT . 'functions.php';
if (get_magic_quotes_gpc()) {
    $_POST = RemoveQuotes($_POST);
    $_GET = RemoveQuotes($_GET);
    $_COOKIE = RemoveQuotes($_COOKIE);
    $_REQUEST = RemoveQuotes($_REQUEST);
}
Router::init();
MySQL::getInstance();
Config::init();
MySession::getInstance();
File::init();
Controller::getInstance()->run();
die;
Exemplo n.º 20
0
Arquivo: User.php Projeto: kizz66/meat
 public function delete()
 {
     $db = MySQL::getInstance();
     $db->query("DELETE FROM `user` WHERE `UserID` = " . $db->escape((int) $this->UserID));
     return true;
 }
Exemplo n.º 21
0
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/
require_once '../sharpy/Sharpy.php';
Sharpy::run();
/**
 * This file is currently only used for testing purposes.
 */
#require_once('../sharpy/Sharpy/Database/PostgreSQL.php');
#$params = array('user' => 'postgres', 'password' => '123456', 'dbname' => 'mydatabase', 'host' => 'localhost');
#$P = PostgreSQL::getInstance($params);
require_once '../sharpy/Sharpy/Database/MySQL.php';
$params = array('user' => 'sharpy', 'password' => 'sharpy', 'dbname' => 'sharpy', 'host' => 'localhost');
$M = MySQL::getInstance($params);
$M->debug();
require_once '../sharpy/Sharpy/User.php';
$U = new User($M);
print_r($U->id(1)->find());
#print_r($U->find(array('peaches' => sha1('password'))));
#$U->dump();
// need to get this converting to $U->Login->find();
#print_r($U->Login->find());
#require_once(SHARPY_PATH.'/models/Blog.php');
#$B = new Blog($M, $U);
#print_r($B->find());
Exemplo n.º 22
0
 public function index()
 {
     $this->show['Title'] = 'Оформление заказа';
     $this->session = MySession::getInstance();
     $trash = $this->session->get('trash');
     if (sizeof($trash) < 1) {
         $this->show['Title'] = 'Ваша корзина пуста...';
     } else {
         $this->show->basketList = array();
         $catalog = new Catalog();
         foreach ($trash as $i => $item) {
             $str = $catalog->getById($item['id']);
             $str['col'] = $item['col'];
             $this->show->basketList[$i] = $str;
             $this->show->basketList[$i]['col'] = $item['col'];
         }
     }
     if (isset($_POST['mode']) && $_POST['mode'] == 'send') {
         $db = MySQL::getInstance();
         $db->query('SELECT FieldName, FieldValue FROM `config` WHERE FieldName="Title"');
         $str = $db->fetchRow();
         $sitename = $str['FieldValue'];
         if (substr(PHP_OS, 0, 3) == "WIN") {
             $n = "\r\n";
         } else {
             $n = "\n";
         }
         $mail = htmlspecialchars(stripslashes(trim($_POST['mail'])));
         $name = htmlspecialchars(stripslashes(trim($_POST['name'])));
         $phone = htmlspecialchars(stripslashes(trim($_POST['phone'])));
         $description = htmlspecialchars(stripslashes(trim($_POST['description'])));
         $body = 'Заказ с сайта ' . $sitename . $n;
         $body .= 'тел:' . $phone . '   ' . $name . $n . $n;
         $w = array('n' => 4, 'cod' => 15, 'name' => 30, 'x' => 20);
         $row = 1;
         $total = 0;
         foreach ($this->show->basketList as $key => $val) {
             $body .= str_pad($row, $w['n'], " ", STR_PAD_RIGHT);
             $body .= str_pad($val['Code'], $w['cod'], " ", STR_PAD_RIGHT);
             $body .= str_pad($val['Title'], $w['name'], " ", STR_PAD_RIGHT) . $n . $n;
             $body .= str_pad(' ', $w['n'], " ", STR_PAD_RIGHT);
             $body .= str_pad('Цена ', $w['x'], " ", STR_PAD_RIGHT) . $val['Price'] . " руб." . $n;
             $body .= str_pad(' ', $w['n'], " ", STR_PAD_RIGHT);
             $body .= str_pad('Кол-во ', $w['x'], " ", STR_PAD_RIGHT) . $val['col'] . ' ' . $val['Ed'] . $n;
             $body .= str_pad(' ', $w['n'], " ", STR_PAD_RIGHT);
             $body .= str_pad('Сумма ', $w['x'], " ", STR_PAD_RIGHT) . $val['col'] * $val['Price'] . ' руб.' . $n;
             $total += $val['col'] * $val['Price'];
             $row++;
             $body .= $n . str_pad('_', 60, "_", STR_PAD_RIGHT) . $n;
         }
         $body .= $n . '          ИТОГО на сумму: ' . $total . ' руб.' . $n . $n . $n;
         $body .= $description;
         $to = [$this->show->Email];
         $subject = 'Заказ с сайта ' . $sitename . '--' . $mail;
         $transport = Swift_SmtpTransport::newInstance($this->show->Smtp, $this->show->Port, "ssl")->setUsername($this->show->Login)->setPassword($this->show->Password);
         $mailer = Swift_Mailer::newInstance($transport);
         $message = Swift_Message::newInstance($subject)->setFrom(array($this->show->Email))->setTo($to)->setBody($body);
         $result = $mailer->send($message);
         if ($result == 1) {
             $trash = null;
             $this->session->delete('trash');
             $this->show->basketList = null;
             exit('ok');
         }
         exit('error');
     }
 }
Exemplo n.º 23
0
 public function loadByStaticPath($staticPath = NULL)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT n.* FROM projects AS n WHERE  n.StaticPath = " . $db->escape($staticPath));
     if ($db->numRows() > 0) {
         $item = $db->fetchRow();
         $oImageList = new Projects_Image();
         $item['ImageList'] = $oImageList->getList((int) $item['ProjectID']);
         $this->get($item);
         return true;
     }
     return false;
 }
Exemplo n.º 24
0
 public function putDescription($ImageID, $Title, $Description)
 {
     $db = MySQL::getInstance();
     $db->query("UPDATE `gallery_image` SET\n\t\t\t\tTitle = '{$Title}',\n\t\t\t\tDescription = '{$Description}'\n\t\t\tWHERE ImageID = " . $ImageID);
     return 0;
 }
Exemplo n.º 25
0
 /**
  * Finds a new unique token, using a loop to make sure that the token does
  * not already exist in the database. This could potentially become an
  * infinite loop, but the chances of that happening are very unlikely.
  *
  * @return  string
  */
 protected function createToken()
 {
     $db = MySQL::getInstance();
     $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $max = strlen($pool) - 1;
     $length = 32;
     while (TRUE) {
         $str = '';
         for ($i = 0; $i < $length; $i++) {
             $str .= $pool[mt_rand(0, $max)];
         }
         if (ctype_alpha($str)) {
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(48, 57));
         } elseif (ctype_digit($str)) {
             $str[mt_rand(0, $length - 1)] = chr(mt_rand(65, 90));
         }
         // Create a random token
         $token = $str;
         // Make sure the token does not already exist
         $db->query("SELECT COUNT(*) FROM `user_token` WHERE `Token` = " . $db->escape($token));
         $count = $db->fetchField();
         if ($count === 0) {
             // A unique token has been found
             return $token;
         }
     }
 }
Exemplo n.º 26
0
 /**
  * @param $id
  */
 public static function delete($id)
 {
     $cur_row = self::getById($id);
     $old_file = $cur_row->file;
     File::delete($old_file, self::IMAGE_PATH);
     File::delete(self::TMB_PREFIX . $old_file, self::IMAGE_PATH);
     $db = MySQL::getInstance();
     $query_str = 'DELETE FROM ' . self::TABLE_NAME;
     $query_str .= ' WHERE id=' . $db->escape((int) $id);
     $db->query($query_str);
     return;
 }
Exemplo n.º 27
0
 public function isEmptyProperty($id)
 {
     $db = MySQL::getInstance();
     $db->query("SELECT * FROM `catalog` WHERE `PropertyID` = " . $id);
     if ($db->numRows() == 0) {
         return true;
     } else {
         throw new Exception(lang('в каталоге есть товар с таким свойством..'));
         return false;
     }
 }
Exemplo n.º 28
0
 public function __construct()
 {
     $this->session = Session::getInstance();
     $this->db = MySQL::getInstance();
 }
Exemplo n.º 29
0
function getData()
{
    $query = MySQL::getInstance()->query("SELECT * FROM Item WHERE Discarded!=1 ORDER BY Date_Last_Worn DESC");
    return $query->fetchALL();
}
Exemplo n.º 30
0
Arquivo: Auth.php Projeto: kizz66/meat
 /**
  * Creates new user
  *
  * @param array $user_data user data to add
  * @param string $second name of second unique field to verify
  * @return  boolean
  */
 public function createUser($user_data = NULL)
 {
     if (empty($user_data) or !$user_data instanceof User) {
         return FALSE;
     }
     $user = new User();
     $db = MySQL::getInstance();
     $db->query("SELECT COUNT(*) FROM `user` WHERE `Email` = " . $db->escape($user_data->Email) . " OR `Login` = " . $db->escape($user_data->Login) . "");
     $user_exist = $db->fetchField();
     if (!$user_exist) {
         if (isset($user_data->ActiveTo) and !is_numeric($user->ActiveTo)) {
             $user_data->ActiveTo = 0;
         }
         // to make sure that $user_data['admin']=true works the same as $user_data['admin']=1
         $user_data->Role = array_key_exists($user_data->Role, $this->config['roles']) ? $user_data->Role : 0;
         $user->merge($user_data);
         $user->Password = $this->hash($user->Password);
         return $result = $user->add() ? TRUE : FALSE;
     }
     return FALSE;
 }