Beispiel #1
0
 static function saveLent($option, $bids, $task = "")
 {
     global $database, $Itemid;
     PHP_booklibrary::addTitleAndMetaTags();
     $checkB = mosGetParam($_REQUEST, 'checkbook');
     if ($checkB != "on") {
         echo "<script> alert('Select an item to Lend'); window.history.go(-1);</script>\n";
         exit;
     }
     $data = JFactory::getDBO();
     $bookid = mosGetParam($_REQUEST, 'bookid');
     $id = mosGetParam($_REQUEST, 'id');
     $lend_from = mosGetParam($_REQUEST, 'lend_from');
     $lend_until = mosGetParam($_REQUEST, 'lend_until');
     if (!is_array($bids) || count($bids) < 1) {
         echo "<script> alert('Select an item to lend'); window.history.go(-1);</script>\n";
         exit;
     }
     $lend = new mosBookLibrary_lend($database);
     if ($task == "edit_lend") {
         $lend->load($bids[0]);
     }
     $query = "SELECT * FROM #__booklibrary_lend where fk_bookid = " . $id . " AND lend_return is NULL ";
     $data->setQuery($query);
     $lendTerm = $data->loadObjectList();
     if ($lend_from > $lend_until) {
         echo "<script> alert('" . $lend_from . " more then " . $lend_until . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $lend_from = substr($lend_from, 0, 10);
     $lend_until = substr($lend_until, 0, 10);
     if (isset($lendTerm[0])) {
         for ($e = 0, $m = count($lendTerm); $e < $m; $e++) {
             if ($task == "edit_lend" && $bids[0] == $lendTerm[$e]->id) {
                 continue;
             }
             $lendTerm[$e]->lend_from = substr($lendTerm[$e]->lend_from, 0, 10);
             $lendTerm[$e]->lend_until = substr($lendTerm[$e]->lend_until, 0, 10);
             //check lend
             if ($lend_from >= $lendTerm[$e]->lend_from && $lend_from <= $lendTerm[$e]->lend_until || $lend_from <= $lendTerm[$e]->lend_from && $lend_until >= $lendTerm[$e]->lend_until || $lend_until >= $lendTerm[$e]->lend_from && $lend_until <= $lendTerm[$e]->lend_until) {
                 echo "<script> alert('Sorry, this item already lend out from " . $lendTerm[$e]->lend_from . " until " . $lendTerm[$e]->lend_until . "'); window.history.go(-1); </script>\n";
                 exit;
             }
         }
     }
     //if end
     if (mosGetParam($_REQUEST, 'lend_from') != "") {
         $lend->lend_from = data_transformer(mosGetParam($_REQUEST, 'lend_from'), "to");
     } else {
         $lend->lend_from = null;
     }
     if (mosGetParam($_REQUEST, 'lend_until') != "") {
         $lend->lend_until = data_transformer(mosGetParam($_REQUEST, 'lend_until'), "to");
     } else {
         $lend->lend_until = null;
     }
     $lend->fk_bookid = $id;
     $userid = mosGetParam($_REQUEST, 'userid');
     if ($userid == "-1") {
         $lend->user_name = mosGetParam($_REQUEST, 'user_name', '');
         $lend->user_email = mosGetParam($_REQUEST, 'user_email', '');
     } else {
         $lend->fk_userid = $userid;
     }
     if (!$lend->check($lend)) {
         echo "<script> alert('" . $lend->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     if (!$lend->store()) {
         echo "<script> alert('" . $lend->getError() . "'); window.history.go(-1); </script>\n";
         exit;
     }
     $lend->checkin();
     $book = new mosBooklibrary($database);
     $book->load($id);
     $book->fk_lendid = $lend->id;
     $book->store();
     $book->checkin();
     if ($option == 'com_comprofiler') {
         $link_for_mosRedirect = "index.php?option=" . $option . "&tab=getmybooksTab&Itemid=" . $Itemid;
     } else {
         $link_for_mosRedirect = "index.php?option=" . $option . "&view=show_my_books&layout=mybooks";
     }
     //print_r($link_for_mosRedirect);exit;
     //mosRedirect($link_for_mosRedirect);
     PHP_booklibrary::showMyBooks($option);
 }
Beispiel #2
0
function saveLend_return($option, $lids)
{
    global $database, $my;
    $id = mosGetParam($_POST, 'id');
    if (!is_array($lids) || count($lids) < 1) {
        echo "<script> alert('Select an item to return'); window.history.go(-1);</script>\n";
        exit;
    }
    for ($i = 0, $n = count($lids); $i < $n; $i++) {
        $lend = new mosBookLibrary_lend($database);
        $lend->load($lids[$i]);
        $lend->lend_return = date("Y-m-d H:i:s");
        if (!$lend->check($lend)) {
            echo "<script> alert('" . addslashes($lend->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        if (!$lend->store()) {
            echo "<script> alert('" . addslashes($lend->getError()) . "'); window.history.go(-1); </script>\n";
            exit;
        }
        $lend->checkin();
        //$book = new mosBookLibrary($database);
        //$book->load($lend->fk_bookid);
        //$book->fk_lendid = 0;
        $is_update_book_lend = true;
        if ($is_update_book_lend) {
            $book = new mosBooklibrary($database);
            $book->load($id);
            $query = "SELECT * FROM #__booklibrary_lend WHERE fk_bookid=" . $id . " AND lend_return IS NULL ";
            $database->setQuery($query);
            $check_lends = $database->loadObjectList();
            if (isset($check_lends[0]->id)) {
                $book->fk_lendid = $check_lends[0]->id;
                $is_update_book_lend = false;
            } else {
                //$book->load($lend->fk_bookid);
                $book->fk_lendid = 0;
            }
            $book->store();
            $book->checkin();
        }
    }
    mosRedirect("index.php?option={$option}");
}
 function getLend()
 {
     $lend = null;
     if ($this->fk_lendid != null && $this->fk_lendid != 0) {
         $lend = new mosBookLibrary_lend($this->_db);
         // load the row from the db table
         $lend->load(intval($this->fk_lendid));
     }
     return $lend;
 }