示例#1
0
			$book['edition'] = $_POST['edition'];
			$book['publisher'] = $_POST['publisher'];
			$book['published_year'] = $_POST['published_year'];
			$book['subjects'] = $_POST['subjects'];
			$book['lang'] = $_POST['lang'];
			$book['series'] = $_POST['series'];
			$book['pages'] = $_POST['pages'];
			// Validate data
			if($book['title']==""){
				displayMsgInSamePage('Title is required');
			}
			if($book['isbn']==""){
				displayMsgInSamePage('ISBN is required');
			}
			if($book['authors']==""){
				displayMsgInSamePage('Authors is required');
			}

			/*if(($acquired_on!="") && (strtotime($acquired_on)==-1)){
				  $msg = "The 'Acquired Date' should be in the format yyyy-mm-dd";
				header("Location: book_add.php?msg=" .$msg . "&" . $querystring);
				exit();
			} */

			//Add Book                  
			$bks = new Books;
			$bks->addBook($book);				  
        }

        // Check ISBN /////////////////////////////////////////////////////
		if(isset($_POST['BtnCheckISBN'])){
示例#2
0
    function addCopy($copy)
    {
        //[Validate new record fields]--------------------
        if (($copy['acquired_on'] != "") && (strtotime($copy['acquired_on']) == -1)) {
            $msg = "The 'Acquired Date' should be either blank or in the format <strong>yyyy-mm-dd</strong>";
            displayMsgInSamePage($msg, $copy['bid'], 'Error: Acquired Date is Invalid');
        }
        if (!($copy['access_no'] > 0)) {
            $msg = "The access number must be a number.";
            displayMsgInSamePage($msg, $copy['bid'], 'Error: Access Number Invalid');
        }


        //[Check if the new record is unique]--------------------
        $sql = "SELECT * FROM copy WHERE access_no='" . $copy['access_no'] . "'";
        $rs = executeSqlQuery($sql);
        $count = mysql_num_rows($rs);
        if ($count >= 1) {
            $msg = "The access number " . $copy['access_no'] . " already exists!<br>" .
                   'Please enter a unique access number for each copy';
            displayMsgInSamePage($msg, $copy['bid'], 'ERROR: Duplicate Access Number');
        }


        //[Add new record]--------------------
        $sql = sprintf("INSERT INTO copy (bid, access_no, reference, lending_type, acquired_on, notes) VALUES (%d,'%s',%d,'%s', '%s', '%s')",
                       $copy['bid'], $copy['access_no'], $copy['reference'], $copy['lending_type'], $copy['acquired_on'], $copy['notes']);
        $a = executeSqlNonQuery($sql);
        $rows_affected = $a['rows'];
        $new_id = $a['id'];
        if ($rows_affected == 0) { //TEST
            $msg = 'The system could not add a new copy to the following book.<br>' .
                   'Please review the settings you entered and try again.<hr>' .
                   $this->toStringCopy($copy) . '<hr>' .
                   "<a href='book_edit.php?ID=" . $copy['bid'] . "'>Try Again</a>";
            $title = 'Failed to Add New Copy';
            displayMsg($msg, $title);
        } elseif ($rows_affected == 1) {
            $msg = 'A new copy was added.<br>' .
                   $this->toStringCopy($copy) .
                   "<a href='book_copy_edit.php?ID=" . $new_id . "'>Edit/Delete this Copy</a>";

            //[Log Event]---------------------------
            $des = '[BID=' . $new_id . " ACC#" . $copy['access_no'] . ' ' . $book['lending_type'] . "]";
            logEvent('COPY_ADDED', $_SESSION['CurrentUser']['mid'], 0, addslashes($des));

            displayMsgInSamePage($msg, $copy['bid'], 'New Copy Added');
        }
    } // function addCopy($copy)