cleanup AddDownloadLog

master
Gilles Crettenand 11 years ago
parent fdf081493e
commit 55a80f3d65

@ -18,110 +18,86 @@ class NetBiblio extends WebService
private $login = ''; private $login = '';
private $client = 'website'; private $client = 'website';
/**
* @param $IP
* @param $client
* @param $login
* @param $code
* @throws SqlException
* @return array
*/
public function AddDownloadLog($IP, $client, $login, $code) public function AddDownloadLog($IP, $client, $login, $code)
{ {
$client = str_replace("'", "", $client); $client = str_replace("'", "", $client);
$login = str_replace("'", "", $login); $login = str_replace("'", "", $login);
$code = ltrim(str_replace("'", "", $code), '0'); $code = ltrim(str_replace("'", "", $code), '0');
$itemNr = $code . 'V'; $itemNr = $code . 'V';
$itemId = '';
$userId = '';
/* Récupération de l'id de l'exemplaire */ $sql = "SELECT itemID FROM Items WHERE LTRIM(RTRIM(ItemNr)) = '$itemNr';";
$sql = "SELECT itemID from Netbiblio3.dbo.items where ltrim(rtrim(itemnr))='$itemNr';";
$result = Connection::execute($sql, false); $result = Connection::execute($sql, false);
if ($row = $result->current()) {
if ($row = $result->next()) {
$itemId = $row['itemID']; $itemId = $row['itemID'];
} else {
throw new WebException("ItemNotFound", "cannot find item", -1030);
} }
/* Récupération de l'id du compte */ $sql = "SELECT UserAccountID FROM UserAccounts WHERE LTRIM(RTRIM(UserAccountNr)) = '$login';";
$sql = "SELECT useraccountID from Netbiblio3.dbo.UserAccounts where ltrim(rtrim(useraccountnr))='$login';";
$result = Connection::execute($sql, false); $result = Connection::execute($sql, false);
if ($row = $result->next()) { if ($row = $result->current()) {
$userId = $row['useraccountID']; $userId = $row['UserAccountID'];
} else {
throw new WebException("UserNotFound", "cannot find user", -1031);
} }
$sql = "SELECT circulationId from Netbiblio3.dbo.OldCirculations where useraccountID=$userId AND itemID=$itemId AND ltrim(rtrim(remark))='$client';"; $sql = "SELECT circulationId
FROM OldCirculations
WHERE
useraccountID= $userId AND
itemID = $itemId AND
LTRIM(RTRIM(remark)) = '$client';";
$result = Connection::execute($sql, false); $result = Connection::execute($sql, false);
if ($existingEntry = $result->next()) { if ($row = $result->current()) {
$existingId = $existingEntry['circulationId']; $id = $row['circulationId'];
$logSql = "UPDATE OldCirculations SET CheckInDate=GETDATE(), CheckOutDate=GETDATE() WHERE circulationID=$existingId"; $sql = "UPDATE OldCirculations
} else { SET
$sql = "SELECT TOP 1 circulationID FROM oldcirculations ORDER BY CirculationID DESC"; CheckInDate=GETDATE(),
$result = Connection::execute($sql, false); CheckOutDate=GETDATE()
if ($row = $result->next()) { WHERE circulationID = $id";
$nextId = $row['circulationID'] + 1; Connection::execute($sql);
} else { return true;
$nextId = 1; }
}
/* Ajout d'un ancien prêt dans OldCirculations */ $sql = "SELECT TOP 1 circulationID FROM OldCirculations ORDER BY CirculationID DESC";
$worker_id = Configuration::get('netbiblio_worker_id'); $result = Connection::execute($sql, false);
$logSql = "INSERT INTO Netbiblio3.dbo.OldCirculations (" . if ($row = $result->current()) {
" CirculationID, " . $nextId = $row['circulationID'] + 1;
" ItemID, " . } else {
" UseraccountID, " . $nextId = 1;
" DueDate, " .
" Remark, " .
" CheckOutDate, " .
" CheckOutBranchofficeID, " .
" CheckOutEmployeeID, " .
" CheckInDate, " .
" CheckInBranchofficeID, " .
" CheckInEmployeeID, " .
" Reminders, " .
" Renewals, " .
" Prereminder, " .
" InfoCode, " .
" CheckOutSIP2Info, " .
" CheckInSIP2Info " .
") VALUES ( " .
" $nextId, " .
" $itemId, " .
" $userId, " .
" DATEADD(month, 2, GETDATE()), " .
" '$client', " .
" GETDATE(), " .
" 2, " .
" $worker_id, " .
" GETDATE(), " .
" 2, " .
" $worker_id, " .
" 0, " .
" 0, " .
" 1, " .
" '-', " .
" 1, " .
" 1 " .
");";
/* Incrément du compteur de prêts "Circulations" dans Items (exemplaires) */
$incrementUserCountersSQL =
"UPDATE Useraccounts " .
"SET Circulations=Circulations+1, TotalCirculations=TotalCirculations+1 " .
"WHERE UseraccountID=$userId;";
Connection::execute($incrementUserCountersSQL);
/* Incrément du compteur de prêts "TotalCirculations" dans UserAccounts (comptes auditeurs) */
$incrementItemCountersSQL =
"UPDATE Items " .
"SET Circulations=Circulations+1, TotalCirculations=TotalCirculations+1 " .
"WHERE ItemID=$itemId;";
Connection::execute($incrementItemCountersSQL);
} }
Connection::execute($logSql);
return array(true); $sql = "UPDATE Useraccounts
SET
Circulations = Circulations + 1,
TotalCirculations = TotalCirculations + 1
WHERE UseraccountID = $userId;";
Connection::execute($sql);
$sql = "UPDATE Items
SET
Circulations = Circulations + 1,
TotalCirculations = TotalCirculations + 1
WHERE ItemID = $itemId;";
Connection::execute($sql);
$worker_id = Configuration::get('netbiblio_worker_id');
$sql = "INSERT INTO OldCirculations (
CirculationID, ItemID, UseraccountID,
Remark,
DueDate, CheckOutDate, CheckInDate,
CheckOutBranchofficeID, CheckOutEmployeeID, CheckInBranchofficeID, CheckInEmployeeID,
Reminders, Renewals, Prereminder, InfoCode, CheckOutSIP2Info, CheckInSIP2Info
) VALUES (
$nextId, $itemId, $userId,
'$client',
DATEADD(month, 2, GETDATE()), GETDATE(), GETDATE(),
2, $worker_id, 2, $worker_id,
0, 0, 1, '-', 1, 1
);";
Connection::execute($sql);
return true;
} }
public function Authenticate($login, $password, $client = "website") public function Authenticate($login, $password, $client = "website")

Loading…
Cancel
Save