diff --git a/assets/js/multi_user.js b/assets/js/multi_user.js index 1d04d24..8fc40a1 100644 --- a/assets/js/multi_user.js +++ b/assets/js/multi_user.js @@ -1,28 +1,52 @@ jQuery(document).ready(function($) { - //get User info + function saveUser(id, entry, ajaxURL){ + $.ajax({ + method: 'GET', + url: ajaxURL, + data: { + id: id, + entry: parseInt(entry) + } + }) + } + + //get info id = parseInt($('#session li').eq(0).find('a').attr('href').match(/\/([^\/]+)\/?$/)[1]); - name = $('#session li').eq(0).find('a').text(); + // name = $('#session li').eq(0).find('a').text(); entry = document.URL.match(/\/([^\/]+)\/?$/)[1]; + ajaxURL = Symphony.Context.get('symphony') + '/extension/multi_user_edit/multi_user/'; - - //send User info - console.log('test'); - - var ajaxURL = Symphony.Context.get('symphony') + '/extension/multi_user_edit/multi_user/'; - + //Check if the entry is being used by another author $.ajax({ method: 'GET', url: ajaxURL, data: { - id: id, - name: name, entry: parseInt(entry) + }, + success: function(response){ + response = $(response); + if(response.hasClass('locked')){ + //if locked, get difference in minutes + $diff = response.find('#diff').text(); + if($diff > 5){ + //Gain access to the article as author is taking too long. + console.log('Exceeded 5 minutes; Updated log.') + saveUser(id, entry, ajaxURL); + } + else{ + console.log(response.find('.show').text()); + console.log((5 - $diff).toFixed(2) + ' minute/s to go.'); + } + } + else{ + //Save User info + saveUser(id, entry, ajaxURL); + } } - }).done(function(response){ // after the request has been loaded... - $('#results').html(response); // put the response in the div + }).done(function(response){ + //code.. }); - }); \ No newline at end of file diff --git a/content/content.multi_user.php b/content/content.multi_user.php index 511c08c..776c313 100644 --- a/content/content.multi_user.php +++ b/content/content.multi_user.php @@ -1,10 +1,13 @@ update($update, 'sym_multi_user', "`entry_id` = ".$entryId)){ echo('Success'); } else{ echo('error'); } - die; } + //Check if entry is being used + if(isset($_GET['entry']) && !isset($_GET['id'])){ + + $entryId = MySQL::cleanValue($_GET['entry']); + + $query = "SELECT session_start, user_id + FROM sym_multi_user + WHERE `entry_id` = '".$entryId."' + LIMIT 1"; + + $userId = Symphony::Database()->fetchVar('user_id',0,$query); + + if( $userId == 0){ + echo('