<?php
class IPN
{
//メンバー
public $pdo;
//コンストラクタ
public function __construct(){
}
function connectDB() {
$iniArray = parse_ini_file("../imagegetter/lib/config.ini", true);
$host = $iniArray['db']['host'];
$dbname = $iniArray['db']['dbName'];
$user = $iniArray['db']['user'];
$password = $iniArray['db']['password'];
try {
$this->pdo = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8',$user,$password,
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
));
} catch (PDOException $e) {
die('データベース接続失敗。'.$e->getMessage());
}
}
// 取得
function getUser($email, $password){
$password = hash('sha256', $password);
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = :email AND password = :password");
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch();
}
function getActiveUser($email, $password){
$password = hash('sha256', $password);
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = :email AND password = :password AND unsubscribed = 0 AND active_member = 1");
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch();
}
function getUserById($id){
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetch();
}
// 作成
function createUser($email, $password, $piId){
$password = hash('sha256', $password);
$this->pdo->beginTransaction();
$stmt = $this->pdo->prepare("INSERT INTO users (email, password, piId) VALUES (:email, :password, :piId)");
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':piId', $piId, PDO::PARAM_INT);
$stmt->execute();
$lastId = $this->pdo->lastInsertId('id');
$this->pdo->commit();
return $lastId;
}
function updateUserActiveStatus($id, $flag){
$stmt = $this->pdo->prepare("UPDATE users SET active_member = :flag WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':flag', $flag, PDO::PARAM_INT);
$stmt->execute();
}
function updateUserUnsubscribedStatus($id, $flag){
$stmt = $this->pdo->prepare("UPDATE users SET unsubscribed = :flag WHERE id = :id");
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':flag', $flag, PDO::PARAM_INT);
$stmt->execute();
}
function listUsers(){
$stmt = $this->pdo->prepare("SELECT id, email, created_time, active_member, unsubscribed FROM users ORDER BY created_time DESC");
$stmt->execute();
$output = array();
while($row = $stmt -> fetch(PDO::FETCH_ASSOC)) {
array_push($output, $row);
}
return $output;
}
//insert paypal data
function ppdataRequest($runRequest){
$this->pdo->beginTransaction();
$stmt = $this->pdo->prepare("INSERT INTO ppdata (runRequest) VALUES (:runRequest)");
$stmt->bindParam(':runRequest', $runRequest, PDO::PARAM_STR);
$stmt->execute();
$lastId = $this->pdo->lastInsertId('id');
$this->pdo->commit();
return $lastId;
}
//insert paypal data会員登録
function ppUserRegister($pe, $in, $pr, $ti){
$this->pdo->beginTransaction();
$stmt = $this->pdo->prepare("INSERT INTO paymentInfo (payerEmail, itemNumber, price, payId)
VALUES (:payerEmail, :itemNumber, :price, :payId)");
$stmt->bindParam(':payerEmail', $pe, PDO::PARAM_STR);
$stmt->bindParam(':itemNumber', $in, PDO::PARAM_STR);
$stmt->bindParam(':price' , $pr, PDO::PARAM_INT);
$stmt->bindParam(':payId' , $ti, PDO::PARAM_STR);
$stmt->execute();
$lastId = $this->pdo->lastInsertId('id');
$this->pdo->commit();
return $lastId;
}
//支払いテーブルからpiIdを取得
function getpiId($payerEmail, $payId){
$stmt = $this->pdo->prepare("SELECT * FROM paymentInfo WHERE payerEmail = :payerEmail AND payId = :payId");
$stmt->bindParam(':payerEmail', $payerEmail, PDO::PARAM_STR);
$stmt->bindParam(':payId' , $payId , PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetch();
}
//キャンセル時のログイン不可情報更新
function updateActiveUserOff($piId){
$stmt = $this->pdo->prepare("UPDATE users SET active_member = 0 WHERE piId = :piId");
$stmt->bindParam(':piId', $piId, PDO::PARAM_INT);
$stmt->execute();
}
//20.03.05追加
function sbscrKind($subscribeType, $payment_status){
}
}
?>