cleanup AddDownloadLog
This commit is contained in:
@@ -18,110 +18,86 @@ class NetBiblio extends WebService
|
||||
private $login = '';
|
||||
private $client = 'website';
|
||||
|
||||
/**
|
||||
* @param $IP
|
||||
* @param $client
|
||||
* @param $login
|
||||
* @param $code
|
||||
* @throws SqlException
|
||||
* @return array
|
||||
*/
|
||||
public function AddDownloadLog($IP, $client, $login, $code)
|
||||
{
|
||||
$client = str_replace("'", "", $client);
|
||||
$login = str_replace("'", "", $login);
|
||||
$code = ltrim(str_replace("'", "", $code), '0');
|
||||
$itemNr = $code . 'V';
|
||||
$itemId = '';
|
||||
$userId = '';
|
||||
|
||||
/* Récupération de l'id de l'exemplaire */
|
||||
$sql = "SELECT itemID from Netbiblio3.dbo.items where ltrim(rtrim(itemnr))='$itemNr';";
|
||||
$sql = "SELECT itemID FROM Items WHERE LTRIM(RTRIM(ItemNr)) = '$itemNr';";
|
||||
$result = Connection::execute($sql, false);
|
||||
|
||||
if ($row = $result->next()) {
|
||||
if ($row = $result->current()) {
|
||||
$itemId = $row['itemID'];
|
||||
}
|
||||
|
||||
/* Récupération de l'id du compte */
|
||||
$sql = "SELECT useraccountID from Netbiblio3.dbo.UserAccounts where ltrim(rtrim(useraccountnr))='$login';";
|
||||
$result = Connection::execute($sql, false);
|
||||
if ($row = $result->next()) {
|
||||
$userId = $row['useraccountID'];
|
||||
}
|
||||
|
||||
$sql = "SELECT circulationId from Netbiblio3.dbo.OldCirculations where useraccountID=$userId AND itemID=$itemId AND ltrim(rtrim(remark))='$client';";
|
||||
$result = Connection::execute($sql, false);
|
||||
|
||||
if ($existingEntry = $result->next()) {
|
||||
$existingId = $existingEntry['circulationId'];
|
||||
$logSql = "UPDATE OldCirculations SET CheckInDate=GETDATE(), CheckOutDate=GETDATE() WHERE circulationID=$existingId";
|
||||
} else {
|
||||
$sql = "SELECT TOP 1 circulationID FROM oldcirculations ORDER BY CirculationID DESC";
|
||||
$result = Connection::execute($sql, false);
|
||||
if ($row = $result->next()) {
|
||||
$nextId = $row['circulationID'] + 1;
|
||||
} else {
|
||||
$nextId = 1;
|
||||
}
|
||||
|
||||
/* Ajout d'un ancien prêt dans OldCirculations */
|
||||
$worker_id = Configuration::get('netbiblio_worker_id');
|
||||
$logSql = "INSERT INTO Netbiblio3.dbo.OldCirculations (" .
|
||||
" CirculationID, " .
|
||||
" ItemID, " .
|
||||
" UseraccountID, " .
|
||||
" 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);
|
||||
throw new WebException("ItemNotFound", "cannot find item", -1030);
|
||||
}
|
||||
Connection::execute($logSql);
|
||||
|
||||
return array(true);
|
||||
$sql = "SELECT UserAccountID FROM UserAccounts WHERE LTRIM(RTRIM(UserAccountNr)) = '$login';";
|
||||
$result = Connection::execute($sql, false);
|
||||
if ($row = $result->current()) {
|
||||
$userId = $row['UserAccountID'];
|
||||
} else {
|
||||
throw new WebException("UserNotFound", "cannot find user", -1031);
|
||||
}
|
||||
|
||||
$sql = "SELECT circulationId
|
||||
FROM OldCirculations
|
||||
WHERE
|
||||
useraccountID= $userId AND
|
||||
itemID = $itemId AND
|
||||
LTRIM(RTRIM(remark)) = '$client';";
|
||||
$result = Connection::execute($sql, false);
|
||||
|
||||
if ($row = $result->current()) {
|
||||
$id = $row['circulationId'];
|
||||
$sql = "UPDATE OldCirculations
|
||||
SET
|
||||
CheckInDate=GETDATE(),
|
||||
CheckOutDate=GETDATE()
|
||||
WHERE circulationID = $id";
|
||||
Connection::execute($sql);
|
||||
return true;
|
||||
}
|
||||
|
||||
$sql = "SELECT TOP 1 circulationID FROM OldCirculations ORDER BY CirculationID DESC";
|
||||
$result = Connection::execute($sql, false);
|
||||
if ($row = $result->current()) {
|
||||
$nextId = $row['circulationID'] + 1;
|
||||
} else {
|
||||
$nextId = 1;
|
||||
}
|
||||
|
||||
$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")
|
||||
|
||||
Reference in New Issue
Block a user