public function borrow2() { //$user = user::where('email', '=', Input::get('bemail'))->firstOrFail(); $returnData = ""; $name = Input::get("name"); $email = Input::get("email"); if (Request::ajax()) { $userCount = User::where('email', '=', Input::get('email'))->count(); $bookCount = Book::where('barcode', '=', Input::get('barcode'))->count(); if ($userCount == 1) { $returnData = $returnData . " user existed "; $user = User::where('email', '=', Input::get('email'))->find(1); } if ($userCount == 0) { $name = Input::get("name"); $email = Input::get("email"); $user = user::create(array('email' => $email, 'name' => $name)); $returnData = $returnData . " user is created "; } if ($bookCount == 1) { $returnData = $returnData . " book existed "; $book = Book::where('barcode', '=', Input::get('barcode'))->find(1); } if ($bookCount == 0) { $title = Input::get('title'); $author = Input::get('author'); $barcode = Input::get('barcode'); $book = book::create(array('title' => $title, 'author' => $author, 'barcode' => $barcode)); $returnData = $returnData . " book is created "; } $borrow = Borrow::create(array('user_id' => $user->id, 'book_id' => $book->id)); $returnData = $returnData . " borrowing is successful user id =" . $user->id . " book id =" . $book->id; } return $returnData; }
public function buy() { if (Request::ajax()) { $id = Request::get('id'); $qty = Request::get('qty'); $book = book::where('id', $id)->first(); $price = $book->price - $book->price * $book->discount / 100; Cart::add(['id' => $id, 'name' => $book->name, 'qty' => $qty, 'price' => $price, 'options' => ['image' => $book->image]]); $cart = ''; //print_r(Cart::content()->toArray()) ; foreach (Cart::content() as $item) { $cart = $cart . ' <div class="lica mxClrAft" id="' . $item->rowid . '"> <div class="ttl left"> <a href="' . route('home.detail', $item->id) . '" class="is-2r"> ' . $item->name . ' </a> </div> <div class="cartbox left"> <div class="num left"> <input type="text" class="n left" value="' . $item->qty . '"> <div class="ctrlnum left"> <div class="fa fa-angle-up is-up"></div> <div class="fa fa-angle-down is-down"></div> </div> <div class="clear"></div> </div> </div> <div class="sls left" value="' . $item->price . '"> ' . number_format($item->price, 0, ',', '.') . 'đ </div> <div class="fa fa-trash-o right"></div> </div> '; } $data = ['cart' => $cart, 'total' => Cart::total()]; return $data; } else { return redirect()->route('home.index'); } }
public function showUpdateForm($id) { if (Auth::user()->role !== 1) { return redirect('/'); } $this->book = book::where('id', '=', $id)->first(); $book_book_cates = $this->book->book_book_cates; $i = 0; $cates = array(); $book_cates = array(); $book_cate_ids = array(); foreach ($book_book_cates as $book_book_cate) { $book_cate = $book_book_cate->book_cate; $book_cates[$i] = $book_cate->name; $book_cate_ids[$i] = $book_cate->id; $cate = $book_cate->category; $cates[$i] = $cate->name; $i++; } return Controller::myView('admin_book.update')->with("book", $this->book)->with("cates", $cates)->with("book_cate_names", $book_cates)->with("book_cate_ids", $book_cate_ids); }
$book->description = $description; $book->isbn = $isbn; $book->datePublished = $datePublished; $book->image = $image; $book->save(); }); /* Actualizacion de un libro en concreto */ /* Obtención de un libro en concreto */ $app->put('/books/:name', function ($name) use($app) { // Creamos un objeto collection + json con el libro pasado como parámetro // Obtenemos el objeto request, que representa la petición HTTP $req = $app->request; // Obtenemos la ruta absoluta de este recurso $absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri(); // Obtenemos el libro de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP $p = \book::find($name); $body = $app->request->getBody(); $template = json_decode($app->request->getBody(), true); $datos = $template['template']['data']; foreach ($datos as $item) { switch ($item['name']) { case 'name': $nombre = $item['value']; break; case 'description': $description = $item['value']; break; case 'isbn': $isbn = $item['value']; break; case 'datePublished':
} else { echo "You currently have " . $count . " books in your library."; } ?> </h2> </div> <div id="lastbook"> <?php if ($count != 0) { echo '<h2 style="margin-top:70px;">Last book you added;</h2>'; $result = $del->fetchAll(); //print_r($result[$count-1]); $row = $result[$count - 1]; //echo $row['book_name']; $lastbook = new book($user_id, $row['book_name'], $row['author'], $row['genre'], $row['publisher'], $row['location'], $row['book_id']); $lastbook->display_books_search(); //echo "lol"; } ?> </div> </section>
/** * 修改账本 */ public static final function modify() { $item_types = book_item::get_items(); $ccys = book::get_ccy(); $error = array(); // 获取数据 $book = new self(); $book->book_id = isset($_GET['book_id']) ? $_GET['book_id'] : null; if (!is_numeric($book->book_id) || !$book->select()) { $error = '该日志不存在'; front::view2('error.tpl', compact('error')); return; } $post = get_object_vars($book); $online = front::online(); $book_items = self::selects('book_item_id,item,info', '#@__book_item', array('user_id' => $online->user_id), array('ORDER BY book_item_id ASC'), array('book_item_id', 'assoc' => null)); $opposites = self::selects('opposite', null, array('user_id' => $online->user_id), array('GROUP BY opposite'), array(null, 'column|table=book' => 'opposite')); $item_txts = self::selects('item_txt', null, array('user_id' => $online->user_id), array(' GROUP BY item_txt'), array(NULL, 'column|table=book' => 'item_txt')); if (!$item_txts) { $item_txts = array(); } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据消毒 $time = time(); $post = array('item' => isset($_POST['item']) ? $_POST['item'] : '', 'item_txt' => isset($_POST['item_txt']) ? $_POST['item_txt'] : '', 'remark' => isset($_POST['remark']) ? $_POST['remark'] : '', 'opposite' => isset($_POST['opposite']) ? $_POST['opposite'] : '', 'book_item_id' => isset($_POST['book_item_id']) ? $_POST['book_item_id'] : '', 'ccy' => isset($_POST['ccy']) ? $_POST['ccy'] : '', 'net' => isset($_POST['net']) ? $_POST['net'] : '0', 'otype' => isset($_POST['otype']) ? $_POST['otype'] : '', 'amount' => isset($_POST['amount']) ? $_POST['amount'] : '', 'user_id' => $online->user_id, 'create_date' => isset($_POST['create_date']) ? $_POST['create_date'] : '', 'create_time' => isset($_POST['create_time']) ? $_POST['create_time'] : '', 'update_date' => date('Y-m-d', $time), 'update_time' => date('H:i:s', $time)); if (get_magic_quotes_gpc()) { $post = array_map('stripslashes', $post); } if (!empty($_POST['item_txt2'])) { $post['item_txt'] = $_POST['item_txt2']; } if (!empty($_POST['opposite2'])) { $post['opposite'] = $_POST['opposite2']; } if ($post['book_item_id']) { $post['item'] = $book_items[$post['book_item_id']]['item']; } // 数据验证 if (empty($post['item'])) { $post['item'] = substr($post['item'], 0, 15); } if ($post['otype'] == 'IN') { $post['amount'] = abs($post['amount']); } else { $post['amount'] = -abs($post['amount']); } $reg = "/(\\d{4})-(\\d{1,2})-(\\d{1,2})/"; if (!empty($post['create_date'])) { preg_match($reg, $post['create_date'], $arr); //checkdate ( int $month , int $day , int $year ) if (!$arr || !checkdate($arr[2], $arr[3], $arr[1])) { $error['create_date'] = '日期格式不正确'; } } else { $error['create_date'] = '请输入日期'; } if (!empty($error)) { break; } $book->struct($post); $book->update(); $online = front::online(); self::update_statement_net($online->user_id, 0, $post['ccy']); header('Location: ?' . $_GET['query']); return; } // 页面显示 foreach (array('item', 'item_txt', 'typeid', 'remark', 'ccy', 'net', 'otype', 'amount', 'create_date', 'create_time') as $value) { $post[$value] = htmlspecialchars($post[$value]); } front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'error', 'item_txts', 'otype', 'item_types', 'book_items', 'opposites', 'ccys')); }
var $title; var $author; var $yearOfPublishing; var $format = "paperback"; function bookPrice() { return "1200 rub. "; } // keyword this function summary() { // return "Author: " . $ this ->author . "."; return "Book Price: " . $this->bookPrice(); } } $book = new book(); $book->title = "Lord of the Rings. "; $book->author = "JR Tolkien"; $book->yearOfPublishing = "1928"; $book->format; // ="Hardcover"; echo "Title: " . $book->title . $book->summary(); //Inheritance class Animal { var $color; var $location = "North America. "; function getColor() { return $this->color; }
<?php class book { public $id; public $name; public $author; public function setValue($a, $b, $c) { $this->id = $a; $this->name = $b; $this->author = $c; } public function getValue() { echo $this->id . "<br/>"; echo $this->name . "<br/>"; echo $this->author . "<br/>"; } } $obj = new book(); $obj->setValue(1, 'harry potter', 'J.K. Rowling'); $obj->getValue(); $obj1 = new book(); $obj1->setValue(2, 'wings of fire', 'A.P.J Abdul Kalam'); $obj1->getValue();
static function SetConnection(mysqli $newConnection) { book::$connection = $newConnection; }
<div class="container-fluid"> <div class="row"> <div class="col-lg-1"></div> <div class="col-lg-7"> <div class="page-header"> <h4>Documentos recientes</h4> </div> <table class="table table-hover"> <tr> <th>No</th> <th>Nombre</th> <th>Ranking</th> <th>Usuario</th> </tr> <?php $book = new book(); $lista = $book->new_entries_by_category(3); $elemento = new element_book(0, 0, "", ""); $x = 0; while ($x < count($lista)) { $elemento = $lista[$x]; echo '<tr><th>' . ($x + 1) . '</th><td><a href="fileprofile.php?id=' . $elemento->getId() . '">' . $elemento->getTitle() . '</a></td><td>'; $estrellas = round($elemento->getPunteo()); $blancas = 5 - $estrellas; $y = $blancas; while ($y < 5) { ?> <span class="glyphicon glyphicon-star"></span><?php $y++; } $y = 0;
/** * 添加关系 */ public static final function append() { $error = array(); $online = front::online(); $get = array('s_type' => isset($_GET['s_type']) ? $_GET['s_type'] : '', 't_type' => isset($_GET['t_type']) ? $_GET['t_type'] : '', 's_id' => isset($_GET['s_id']) ? (int) $_GET['s_id'] : '0', 't_id' => isset($_GET['t_id']) ? (int) $_GET['t_id'] : '0'); $s_list = null; if ($get['s_type'] == 'channel') { $s_list = channel::get_channel_select(0, 0, $get['s_id'], null, null); } elseif ($get['s_type'] == 'address') { $s_lists = address::selects('address_id as id,name', null, array('user_id' => $online->user_id), array('ORDER BY address_id DESC'), array('id', 'column|table=address' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'book') { $s_lists = book::selects('book_id as id,concat_ws(\',\',create_date,item_txt,remark,ccy,amount,otype) as name', null, array('user_id' => $online->user_id), array('ORDER BY create_date DESC,book_id DESC'), array('id', 'column|table=book' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'diary') { $s_lists = diary::selects('diary_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY diary_id DESC'), array('id', 'column|table=diary' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'doc') { $s_lists = doc::selects('doc_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY doc_id DESC'), array('id', 'column|table=doc' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'site') { $s_lists = site::selects('site_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY site_id DESC'), array('id', 'column|table=site' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } elseif ($get['s_type'] == 'user') { $s_lists = user::selects('user_id as id,username as name', null, array('user_id' => $online->user_id), array('ORDER BY user_id DESC'), array('id', 'column|table=user' => 'name')); if ($s_lists) { $s_list = make_option($s_lists, $get['s_id']); } } else { } $t_list = null; if ($get['t_type'] == 'channel') { $t_list = channel::get_channel_select(0, 0, $get['t_id'], null, null); } elseif ($get['t_type'] == 'address') { $t_lists = address::selects('address_id as id,name', null, array('user_id' => $online->user_id), array('ORDER BY address_id DESC'), array('id', 'column|table=address' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'book') { $t_lists = book::selects('book_id as id,concat_ws(\',\',create_date,item_txt,remark,ccy,amount,otype) as name', null, array('user_id' => $online->user_id), array('ORDER BY create_date DESC,book_id DESC'), array('id', 'column|table=book' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'diary') { $t_lists = diary::selects('diary_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY diary_id DESC'), array('id', 'column|table=diary' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'doc') { $t_lists = doc::selects('doc_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY doc_id DESC'), array('id', 'column|table=doc' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'site') { $t_lists = site::selects('site_id as id,title as name', null, array('user_id' => $online->user_id), array('ORDER BY site_id DESC'), array('id', 'column|table=site' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } elseif ($get['t_type'] == 'user') { $t_lists = user::selects('user_id as id,username as name', null, array('user_id' => $online->user_id), array('ORDER BY user_id DESC'), array('id', 'column|table=user' => 'name')); if ($t_lists) { $t_list = make_option($t_lists, $get['t_id']); } } else { } // 表单处理 while (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { // 数据消毒 $post = array('s_type' => isset($_POST['s_type']) ? $_POST['s_type'] : '', 't_type' => isset($_POST['t_type']) ? $_POST['t_type'] : '', 's_id' => isset($_POST['s_id']) ? (int) $_POST['s_id'] : '0', 't_id' => isset($_POST['t_id']) ? (int) $_POST['t_id'] : '0', 'user_id' => $online->user_id); if (!$post['s_type']) { $error['s_type'] = '请选择源类型'; } if (!$post['t_type']) { $error['t_type'] = '请选择目标类型'; } if (!$post['s_id']) { $error['s_id'] = '请选择源内容'; } if (!$post['t_id']) { $error['t_id'] = '请选目标内容'; } if (!$error['t_id']) { if ($post['s_type'] == $post['t_type'] && $post['s_id'] == $post['t_id']) { $error['t_id'] = '不能和自己关联'; } } if (!$error['t_id']) { $related_id = self::selects('related_id', null, array('user_id' => $online->user_id, 's_id' => $post['s_id'], 's_type' => $post['s_type'], 't_id' => $post['t_id'], 't_type' => $post['t_type']), null, array('column' => 'related_id')); if (!$related_id) { $related_id = self::selects('related_id', null, array('user_id' => $online->user_id, 's_id' => $post['t_id'], 's_type' => $post['t_type'], 't_id' => $post['s_id'], 't_type' => $post['s_type']), null, array('column' => 'related_id')); } if ($related_id) { $error['t_id'] = '目标内容已经关联,请重新选择'; } } if (!empty($error)) { break; } // 数据入库 $related = new self(); $related->related_id = null; $related->struct($post); $related->insert(); $error = '添加成功'; front::view2('error.tpl', compact('error')); return; } $types = array('address' => '地址', 'book' => '账本', 'channel' => '分类', 'diary' => '日志', 'doc' => '文章', 'site' => '网址', 'user' => '用户'); front::view2(__CLASS__ . '.' . 'form.tpl', compact('post', 'get', 'error', 'types', 's_list', 't_list')); }
<?php require_once 'book.php'; $book = new book(); $book->setTitle("ハリーポッター"); print $book->getTitle(); print $book->buyBook(400);
public function cate($id) { if (Request::ajax()) { $limit = Request::get('limit'); $data = Request::get('data'); $sort = Request::get('sort'); $list = Request::get('list'); $model = book::where('cate_id', $id)->where('publishing_date', '<', date('y-m-d'))->orderBy('publishing_date', 'DESC'); $model = HomeController::sort($model, $sort)->paginate($limit); return view('front.partials.list_book_item_info_page', ['data' => $model, 'list' => $list]); } $bestsellers = book::where('publishing_date', '<', date('y-m-d'))->orderBy('qty_saled', 'DESC')->paginate(5); $cate_name = cate::where('id', $id)->first()->name; return view('front.xemthem', ['data' => $bestsellers, 'name' => $cate_name]); }
<?php class book { private $id; private $name; private $author; public function book($a, $b, $c) { $this->id = $a; $this->name = $b; $this->author = $c; } public function getValue() { echo $this->id . "<br/>"; echo $this->name . "<br/>"; echo $this->author . "<br/>"; } } $obj = new book(1, 'abc', 'xyz'); $obj->getValue();
$db_book->bindparam(":bigbookid", $bigbookid); $db_book->bindparam(":user_id", $user_id); $db_book->execute(); if (!$db_book) { die('<br/>MySQL Error: ' . mysql_error()); header("home.php"); /* Redirect browser */ exit; } else { //echo '<br />Result is true'; $row = $db_book->fetch(PDO::FETCH_ASSOC); //echo '<br />tryed fetching row'; if (!isset($row['book_id'])) { echo "<h2>You don't have any books with the ID " . $bigbookid . "</h2>"; } else { $bigbook = new book($user_id, $row['book_name'], $row['author'], $row['genre'], $row['publisher'], $row['location'], $row['book_id']); $bigbook->display_bigbook(); echo ' <div id="bookoptions_wrapper"> <div id="bookoptions"> <h2>Options:</h2> <i class="fa fa-trash-o" id="delete_button" title="Delete"></i> '; if (!is_null($row['lended_to'])) { //echo "wow"; //echo $row['lended_to']; echo '<i class="fa fa-hand-rock-o" id="unlend_button" title="Unlend"></i>'; echo '<form method="post" id="unlend_form"> <button type="submit" name="btn_unlend" value="unlend" id="btn_unlend"> </button> </form>
$validID = true; //Headers already sent errro. TO DO //header('book.php?id=' . $query); } else { $validID = false; echo "<h2>Please only enter numeric input for Book ID</h2>"; } } else { $raw_results = $DB_con->prepare("SELECT * FROM books\n WHERE (`user_id` LIKE {$user_id} ) AND \n ((`book_name` LIKE '%" . $query . "%') OR \n (`book_id` LIKE '%" . $query . "%') OR \n (`location` LIKE '%" . $query . "%')OR \n (`genre` LIKE '%" . $query . "%') OR \n (`publisher` LIKE '%" . $query . "%') OR \n (`author` LIKE '%" . $query . "%'))"); } } if ($validID) { $raw_results->execute(); if ($raw_results->rowCount() > 0) { while ($results = $raw_results->fetch(PDO::FETCH_ASSOC)) { $newbook = new book($user_id, $results['book_name'], $results['author'], $results['genre'], $results['publisher'], $results['location'], $results['book_id']); $newbook->display_books_search(); } } else { // if there is no matching rows do following echo "<h2>No results</h2>"; } } } else { // if query length is less than minimum //echo "Minimum length is ".$min_length; echo "<h2>Enter something.</h2>"; } if (isset($check)) { $user->display_add_message($check, $newbook); }