forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas CARPi
committed
Mar 26, 2014
1 parent
2c183a2
commit dbbf0ce
Showing
8 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/******************************************************************************** | ||
* * | ||
* Copyright 2012 Nicolas CARPi (nicolas.carpi@gmail.com) * | ||
* http://www.elabftw.net/ * | ||
* * | ||
********************************************************************************/ | ||
|
||
/******************************************************************************** | ||
* This file is part of eLabFTW. * | ||
* * | ||
* eLabFTW is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU Affero General Public License as * | ||
* published by the Free Software Foundation, either version 3 of * | ||
* the License, or (at your option) any later version. * | ||
* * | ||
* eLabFTW is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied * | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * | ||
* PURPOSE. See the GNU Affero General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU Affero General Public * | ||
* License along with eLabFTW. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
********************************************************************************/ | ||
$page_title = 'Revisions'; | ||
require_once 'inc/head.php'; | ||
require_once 'inc/common.php'; | ||
require_once 'inc/menu.php'; | ||
|
||
if (isset($_GET['exp_id']) && !empty($_GET['exp_id']) && is_pos_int($_GET['exp_id'])) { | ||
$exp_id = $_GET['exp_id']; | ||
} else { | ||
die('Bad experiment id.'); | ||
} | ||
|
||
if (isset($_GET['action']) && $_GET['action'] === 'restore' && is_pos_int($_GET['rev_id'])) { | ||
// get the body of the restored time | ||
$sql = "SELECT body FROM experiments_revisions WHERE id = :rev_id"; | ||
$req = $pdo->prepare($sql); | ||
$req->bindParam(':rev_id', $_GET['rev_id'], PDO::PARAM_INT); | ||
$req->execute(); | ||
$revision = $req->fetch(); | ||
|
||
// we don't update if the experiment is locked | ||
// first check if it's locked | ||
$sql = "SELECT locked FROM experiments WHERE id = :exp_id"; | ||
$req = $pdo->prepare($sql); | ||
$req->bindParam(':exp_id', $exp_id, PDO::PARAM_INT); | ||
$req->execute(); | ||
$locked = $req->fetch(); | ||
if ($locked['locked'] == 1) { | ||
$message = "You cannot restore a revision of a locked experiment !"; | ||
display_message('error', $message); | ||
require_once 'inc/footer.php'; | ||
die(); | ||
} | ||
|
||
// experiment is not locked, we can continue | ||
// sql to update the body of the experiment with the restored one | ||
$sql = "UPDATE experiments SET body = :body WHERE id = :exp_id"; | ||
$req = $pdo->prepare($sql); | ||
$req->bindParam(':body', $revision['body']); | ||
$req->bindParam(':exp_id', $exp_id, PDO::PARAM_INT); | ||
$req->execute(); | ||
} | ||
|
||
// Get the currently stored body | ||
$sql = "SELECT * FROM experiments | ||
WHERE id = :id"; | ||
$req = $pdo->prepare($sql); | ||
$req->bindParam(':id', $exp_id, PDO::PARAM_INT); | ||
$req->execute(); | ||
$experiment = $req->fetch(); | ||
echo "<div class='item'>Current :<br>".$experiment['body']."</div>"; | ||
|
||
// Get list of revisions | ||
$sql = "SELECT * FROM experiments_revisions WHERE exp_id = :exp_id AND userid = :userid ORDER BY savedate DESC"; | ||
$req = $pdo->prepare($sql); | ||
$req->execute(array( | ||
'exp_id' => $exp_id, | ||
'userid' => $_SESSION['userid'] | ||
)); | ||
while($revisions = $req->fetch()) { | ||
echo "<div class='item'>Saved on : ".$revisions['savedate']." <a href='revision.php?exp_id=".$exp_id."&action=restore&rev_id=".$revisions['id']."'>Restore</a><br>"; | ||
echo $revisions['body']."</div>"; | ||
} | ||
?> | ||
|
||
<?php | ||
require_once 'inc/footer.php'; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters