public function searchBooks() { $success = true; $errMsg = ''; $bookData = array(); $web = $this->uri->segment(3) ? true : false; if ($web != true) { if ($this->session->userdata('a_session')) { $idA = $this->session->userdata('id_a'); $idS = $this->session->userdata('id_s'); } else { if ($this->session->userdata('k_session')) { $idA = $this->input->post('id_a'); $idBB = $this->input->post('id_bb'); $idS = $this->input->post('id_s'); } } } else { $idS = $this->input->post('id_s'); } $searchProccess = false; //Listado de ISBN que vienen del textarea de search. $arrISBN = explode("\n", $this->input->post('isbn')); if (!empty($arrISBN)) { foreach ($arrISBN as $isbn) { $isbn = $this->_swap290(trim(str_replace(" ", "", str_replace("-", "", $isbn)))); if (strlen($isbn) == 13 or strlen($isbn) == 10) { $bookData = $this->_getBookFromKf($idS, $isbn); //Cargo bookData if (!$bookData) { //Busco en KF $bookData = $this->_getFromBooksList($idS, $isbn); //Cargo bookData if (!$bookData) { //Busco en books $bookData = $this->_getBookFromAPIs($idS, $isbn); //Cargo bookData } } $success = true; //Quito el key timestamp de los datos que traigo de books porque no existe ese campo en las session tables unset($bookData['timestamp']); if ($web != true) { if ($this->session->userdata('k_session')) { //Para agents $bookData['id_bb'] = $idBB; $this->Buybacks_mod->addBookToAdminBuybackSession($bookData); //En este metodo guardo el libro nuevo en la tabla buybacks book. Solo el admin. } elseif ($this->session->userdata('a_session')) { //Para admin $this->Buybacks_mod->addBookToAgentBuybackSession($bookData); //Si encontre en algun lugar el book lo cargo en la buyback session del agent. } } else { $imageUrl = $this->_getImageByIsbn($bookData['isbn13']); $bookData = $this->_getFromBooksList($idS, $isbn); $bookData['image'] = '<img src="' . $imageUrl . '" class="img-responsive" alt="Responsive image">'; $bookData['title'] = truncTitle($bookData['title'], 60); } $this->_addSearchToLog($isbn); $searchProccess = true; } } } echo json_encode(array('success' => $success, 'errMsg' => $errMsg, 'data' => $bookData)); }
public function getAdminSpecialPricesList() { $this->_existsKarolSession($this->uri->segment(3)); $list = $this->Specialprices_mod->getSpecialPricesList(); $aaData = array(); if ($list) { foreach ($list as $l) { $l->title = $this->agent->is_mobile() ? truncTitle($l->title, 30) : truncTitle($l->title, 55); $edit = '<span data-id="' . $l->id_s . '" data-isbn="' . $l->isbn13 . '" data-may_price="' . $l->may_price . '" data-aug_price="' . $l->aug_price . '" class="glyphicon glyphicon-pencil cursor edit-price"></span>'; $remove = '<span data-id="' . $l->id_s . '" data-isbn13="' . $l->isbn13 . '" class="glyphicon glyphicon-remove cursor remove-specialprice"></span>'; $row = array($l->title, $l->isbn13, $l->isbn10, $l->may_price, $l->aug_price, $edit, $remove); $aaData[] = $row; } } $result['aaData'] = $aaData; $result = json_encode($result); $result = str_replace('null', '""', $result); echo $result; }
public function getAgentBuybackBooksSession() { $this->_existSession($this->uri->segment(3)); $success = true; $errMsg = ''; $idS = $this->session->userdata('id_s'); $idA = $this->session->userdata('id_a'); $idBB = $this->session->userdata('id_bb'); $idSession = $this->session->userdata('bb_session'); //Aca le paso el id_bb para traer todos los libros de las 2 tablas (buybacks_books y agents_bb_sessions) $books = $this->Buybacks_mod->getBooksForAgentBuybackSession($idBB, $idSession); $aaData = array(); if ($books) { if (!$this->agent->is_mobile()) { foreach ($books as $b) { $bookData = ' <div class="container-fluid cus-book-data"> <img src="' . base_url() . 'resources/book_covers/' . $b->isbn13 . '.jpg' . '" class="img-responsive thumb-book"> <span><strong>' . truncTitle($b->title, 42) . '</strong></span> <br><br> <p>ISBN13: ' . $b->isbn13 . '</p> <p>ISBN10: ' . $b->isbn10 . '</p> </div>'; $removeBook = '<span data-type="' . $b->type . '" data-id="' . $b->id_type . '" class="glyphicon glyphicon-remove cursor remove-session-book"></span>'; $row = array($bookData, $b->may_price, $b->aug_price, $removeBook); $aaData[] = $row; } } else { //Si es mobile foreach ($books as $b) { $bookData = ' <div class="container-fluid"> <div class="row"> <div class="col-xs-12"> <p><strong>' . truncTitle($b->title, 25) . '</strong></p> </div> </div> <div class="row"> <div class="col-xs-8"> <img src="' . base_url() . 'resources/book_covers/' . $b->isbn13 . '.jpg' . '" class="img-responsive thumb-book"> </div> </div> <div class="row"> <div class="col-xs-12"> <span class="label label-warning">ISBN13</span><span class="label label-default">' . $b->isbn13 . '</span> </div> </div> <div class="row"> <div class="col-xs-12"> <span class="label label-info">ISBN10</span><span class="label label-default">' . $b->isbn10 . '</span> </div> </div> </div> '; $removeBook = '<span data-type="' . $b->type . '" data-id="' . $b->id_type . '" class="glyphicon glyphicon-remove cursor remove-session-book"></span>'; $row = array($b->isbn13, $b->may_price, $b->aug_price, $removeBook, $bookData); $aaData[] = $row; } } } $result['aaData'] = $aaData; $result = json_encode($result); $result = str_replace('null', '""', $result); echo $result; }
public function getAdminBuybackBooksForEdit() { $this->_existsKarolSession($this->uri->segment(3)); $idBB = $this->input->post('id_bb'); //Si ya esta seteado curr_id_bb es porque en algun momento se edito un libro. //Si esto es asÃ, y el id_bb que viene es distinto al actual, borro los libros de buybacks_books_session que pueden haber quedado residuales if ($idBB != $this->session->userdata('curr_id_bb')) { $this->Buybacks_mod->deleteResidualBooksFromAdminBBBooksSession($this->session->userdata('curr_id_bb')); } //Ahora cargo el buevo id_bb para editar en la session cookie $this->session->set_userdata('curr_id_bb', $idBB); //Guardo en la session el buyback que estoy editando. $books = $this->Buybacks_mod->getAdminBuybackBooksForEdit($idBB); $aaData = array(); $data = array(); if ($books) { $length = !$this->agent->is_mobile() ? 55 : 25; foreach ($books as $b) { $bookData = ' <div class="container-fluid"> <div class="row"> <div class="col-xs-12"> <p><strong>' . truncTitle($b->title, $length) . '</strong></p> </div> </div> <div class="row"> <div class="col-xs-8"> <img src="' . base_url() . 'resources/book_covers/' . $b->isbn13 . '.jpg' . '" class="img-responsive thumb-book"> </div> </div> <div class="row"> <div class="col-xs-12"> <span class="label label-warning">ISBN13</span><span class="label label-default">' . $b->isbn13 . '</span> </div> </div> <div class="row"> <div class="col-xs-12"> <span class="label label-info">ISBN10</span><span class="label label-default">' . $b->isbn10 . '</span> </div> </div> </div> '; //Paso el removo span asi porque en este caso elimino un book que cumpla con los 2 campos, y si hay mas de uno no importa porque uso LIMIT 1 $removeBook = '<span data-id="' . $b->id_bb . '" data-isbn="' . $b->isbn13 . '" class="glyphicon glyphicon-remove cursor remove-book"></span>'; $row = array($bookData, $b->may_price, $b->aug_price, $removeBook); $data[] = $row; } $aaData['aaData'] = $data; } echo json_encode($aaData); }