public function reserve() { global $base_path; global $smarty_api; if ($this->valid !== true) { throw new ReservationNotValid("Please call is_valid() before saving!"); } global $DB; $sql = ' INSERT INTO reservations (`timeunit_id`,`username`,`price`,`status`,`add_date`) VALUES(:timeunit_id,:username,:price,1,NOW()) '; $sth = $DB->prepare($sql); $sth->bindParam(':timeunit_id', $this->timeunit_id, PDO::PARAM_INT); $sth->bindParam(':username', $this->user->username, PDO::PARAM_STR); $sth->bindParam(':price', $this->price, PDO::PARAM_INT); $sth->execute(); $reservation_id = $DB->lastInsertId(); $sql = 'UPDATE timeunits SET reserved_by=:reserved_by,prereserved_expire=NULL WHERE id=:timeunit_id'; $sth = $DB->prepare($sql); $sth->bindParam(':timeunit_id', $this->timeunit_id, PDO::PARAM_INT); $sth->bindParam(':reserved_by', $this->user->username, PDO::PARAM_STR); $sth->execute(); $usertransaction = new UserTransaction(); $usertransaction->user = $this->user; $usertransaction->type = 1; $usertransaction->object_id = $reservation_id; $usertransaction->value = 0 - $this->price; $valid = $usertransaction->is_valid(); if ($valid === true) { $usertransaction->save(); } $smarty_api->assign('user', $this->user); $smarty_api->assign('reservation', $this); $body = $smarty_api->fetch('emails/reservation-body.tpl'); $subject = $smarty_api->fetch('emails/reservation-subject.tpl'); $email = new Email($this->user->email, $subject, $body); $email->sendHtml(); if (CFG::ADMIN_RESERVE_EMAIL != "") { $body = $smarty_api->fetch('emails/admin-reservation-body.tpl'); $subject = $smarty_api->fetch('emails/admin-reservation-subject.tpl'); $email = new Email(CFG::ADMIN_RESERVE_EMAIL, $subject, $body); $email->sendHtml(); } }
/** * @return \yii\db\ActiveQuery */ public function getTxn() { return $this->hasOne(UserTransaction::className(), ['id' => 'txn_id']); }
<?php require_once $base_path . 'classes/checkframework.php'; if (count($_POST) > 0) { $usertransaction = new UserTransaction($_POST); $usertransaction->user = $user; $usertransaction->type = 0; $usertransaction->admin_username = $admin_username; $errors = array(); $valid = $usertransaction->is_valid(); if ($valid === true) { $usertransaction->save(); } else { $errors = $valid; } $smarty->assign('errors', $errors); $smarty->display('return.tpl'); }