36,49d35
<  * Implementation of hook_init().
<  */
< function checkout_init() {
<   global $user;
<   if ($user->uid && user_access('check out documents')) {
<     // Avoid AJAX requests unlocking a node. This header is automatically set
<     // when doing AJAX requests through jQuery.
<     if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {
<       checkout_handle_request($user->uid);
<     }
<   }
< }
< 
< /**
66a53,58
>   $items['admin/content/%/checkout/releaseown'] = array(
>     'page callback' => 'checkout_release_own_item',
>     'page arguments' => array(2),
>     'access arguments' => array('check out documents'),
>     'type' => MENU_CALLBACK,
>   );
114a107,121
> 
>   global $user;
>   if(!$user->uid || !user_access('check out documents')) { // user has no right to lock nodes at all
>     return;
>   }
>   $nid = $form['nid']['#value'];
> 
>   if($form_state['submitted'] === false && $nid != "") { /// node editing starts and we are editing a node
>     // current nid
> 
> 
>     if(checkout_node($nid, $user->uid) == false) {// could not lock node, its locked by someone else
>         drupal_goto("node/$nid");
>     }
>   }
151c158
<     
---
> 
154a162,166
> 
>     case 'view':
>         global $user;
>         checkout_warn_pending_locks($user->uid); // check if the user has pending locks and warn him
>     break;
176,228d187
<  * Handle node locking.
<  * 
<  * When landing on a node edit page the current node needs to be locked.
<  * When coming from an edit page the previous node needs to be unlocked.
<  *
<  * @param $uid
<  *   The user id to (un)lock nodes for.
<  */
< function checkout_handle_request($uid) {
<   global $base_path;
<   
<   // Build referer path
<   $referer_uri = parse_url(referer_uri());
<   if (variable_get('clean_url', 0)) {
<     $referer = substr($referer_uri['path'], strlen($base_path));
<   }
<   else {
<     $vars = array();
<     if (isset($referer_uri['query'])) {
<       parse_str($referer_uri['query'], $vars);
<     }
<     $referer = isset($vars['q']) ? $vars['q'] : '';
<   }
<   if ($referer = rtrim($referer, '/')) {
<     $referer = drupal_get_normal_path($referer);
<   }
< 
<   // If refering and current paths match we can abort, since there can't be any
<   // locking action involved.
<   if ($_GET['q'] == $referer) {
<     return;
<   }
< 
<   // Otherwise try to extract nid from path.
<   $previous_nid = checkout_get_nid($referer);
<   $current_nid = checkout_get_nid($_GET['q']);
< 
<   // Check whether to release a previously edited node.
<   if ($previous_nid && (!$current_nid || $current_nid != $previous_nid)) {
<     checkout_release($previous_nid, $uid);
<   }
< 
<   // Check whether to lock the current node.
<   if ($current_nid && (!$previous_nid || $previous_nid != $current_nid)) {
<     // Try to lock the node.
<     if (!checkout_node($current_nid, $uid)) {
<       // Node already locked: send back to refering page.
<       drupal_goto(referer_uri());
<     }
<   }
< }
< 
< /**
288d246
< 
292c250,252
<     if ($lock->uid != $uid || !$lock->persistent) {
---
> 
> 
>     if ($lock->uid != $uid) {
307a268
> 
312d272
< 
362c322
<   } 
---
>   }
369c329
<   
---
> 
374c334
<   
---
> 
386c346
<   
---
> 
413a374,406
> /**
>  * For every lock a user current have on any nodes, print a warning messagt
>  * with an link to release this node.
>  *
>  */
> function checkout_warn_pending_locks($uid) {
>     // cache
>     static $warned_nodes = array();
>     $result = db_query("SELECT * FROM {checkout} WHERE uid = %d", $uid);
>     while($lock = db_fetch_object($result)) {
>         // we have warned this one already, lets pass
>         if($warned_nodes[$lock->nid] === true)
>             continue;
> 
>         $node = node_load($lock->nid);
>         $warned_nodes[$node->nid] = true;
>         $unlocklink = "/admin/content/$node->nid/checkout/releaseown";
>         drupal_set_message(t("You still have an open lock on '!nodetitle', so nobody can edit this node. You might <a href='!unlocklink'>unlock</a> the node by klicking <a href='!unlocklink'>here</a>", array ('!nodetitle' => $node->title, '!unlocklink' => $unlocklink)),"error");
>     }
> }
> /**
>  * Release the lock of a node. We are using the current users uid, so the user only can delete
>  * his own locks. We never fail, as if the lock does not exist, the node is unlocked anyway
>  */
> function checkout_release_own_item($node) {
>     global $user;
> 
>     if(!$node)
>         echo "error";
>     checkout_release($node,$user->uid,true);
>     drupal_set_message('Lock removed from this node. Other users can now edit it again');
>     drupal_goto("/node/$node");
> }
