Example #1
0
        $product['cover'] = 1;
        //trim($cover[0]);
        // save picture
        @file_put_contents(PT_PATH . 'picture/' . $product['id'] . '.jpg', base64_decode($cover[1]));
    }
}
// preg product's star
if (preg_match('/5つ星のうち ([0-9.]+)/i', $html, $star)) {
    $product['star'] = $star[1];
}
$db->beginTrans();
$product = filter::apply('refresh', $product, $html);
// Save
$id = $product['id'];
unset($product['id']);
list($sql, $value) = array_values(update_array($product));
$value[':id'] = $id;
$rs = $db->prepare("UPDATE `a_good` SET {$sql} WHERE `id`=:id")->execute($value);
if ($rs === false) {
    $db->rollback();
    json_return(null, 1, 'Load page\'s data fail, please retry.');
}
// Commit
if (!$db->commit()) {
    $db->rollback();
    json_return(null, 9, 'Load page\'s data fail, please retry.');
}
$product['id'] = $id;
template::assign('v', $product);
$html = template::fetch('_tr');
json_return($html);
Example #2
0
// session start
define("SESSION_ON", true);
// define project's config
define("CONFIG", '/conf/web.php');
// debug switch
define("DEBUG", true);
// include framework entrance file
include './common.php';
// simplify use class
use pt\framework\debug\console as debug;
use pt\framework\template;
use pt\framework\db;
// include your project common functions.
// this is a demo that have some useful functions.
include COMMON_PATH . 'web_func.php';
if ($_POST) {
    if (empty($_POST['username']) || empty($_POST['password'])) {
        json_return(null, 1, 'Username / Password can\'t be empty.');
    }
    $db = db::init();
    $user = $db->prepare("SELECT `id`,`username`,`password`,`md` FROM `a_user` WHERE BINARY `username`=:user")->execute(array(':user' => $_POST['username']));
    if (!$user || $user[0]['password'] != md5(md5($_POST['password']) . $user[0]['md'])) {
        json_return(null, 1, 'Incorrect password.');
    } else {
        $_SESSION['uid'] = $user[0]['id'];
        json_return(1);
    }
}
template::display('login');
Example #3
0
if (defined('SESSION_ON')) {
    $sessionName = ini_get('session.name');
    if ($_POST && isset($_POST[$sessionName])) {
        session_id($_POST[$sessionName]);
    } else {
        if (isset($_GET[$sessionName])) {
            session_id($_GET[$sessionName]);
        }
    }
    session_start();
}
header("Power-By: pt-framework [https://github.com/page7/pt]");
// need resflesh all browser catch
if (isset($_REQUEST[config('web.reflesh_var')])) {
    header("Expires: Wed,01 Jan 2014 00:00:00 GMT");
    // :p pt的开发日期
    header('Last-Modified:' . date('D,d M Y H:i:s') . ' GMT');
    header("Cache-Control: no-cache, must-revalidate");
    header("Pragma: no-cache");
}
// language
if (config('web.i18n')) {
    \pt\framework\language::init();
}
// template
if (config('template')) {
    \pt\framework\template::init();
}
if (DEBUG) {
    $GLOBALS['_initTime'] = microtime(TRUE);
}
Example #4
0
        // Delete
    // Delete
    case 'delete':
        if ($_POST) {
            $id = (int) $_POST['id'];
            $db = db::init();
            $db->beginTrans();
            $rs = $db->prepare("DELETE FROM `a_good` WHERE `id`=:id")->execute(array(':id' => $id));
            if (false === $rs) {
                $db->rollback();
                json_return(null, 1, 'Operation failed.');
            }
            action::exec('delete', $id);
            if ($db->commit()) {
                json_return(1);
            }
            json_return(null, 9, 'Operation failed.');
        }
        break;
        // List page
    // List page
    case 'default':
    default:
        $keyword = '';
        template::assign('keyword', $keyword);
        $db = db::init();
        $sql = "SELECT * FROM `a_good` WHERE `user`=:uid ORDER BY `id` DESC";
        $list = $db->prepare($sql)->execute(array(':uid' => $uid));
        template::assign('list', $list);
        template::display('index');
}