- Posts: 54
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
<p class="normal-welcome">This is the normal welcome text...<p> <p class="survey-full-welcome" style="display:none">Sorry, this survey is full.<p>
function handleCompletes(sid, maxCount) { // Identify some stuff... var surveyRoot = location.pathname.split('index.php')[0]; var templateName = $('head link[href*="template.css"]').attr('href').replace(/\/template.css/, '').split('/templates/')[1]; var templatePath = surveyRoot+'upload/templates/'+templateName+'/'; // AJAX call $.ajax({ url: templatePath+'db_query.php', // The PHP file async: true, cache : false, // No caching in IE data: { sid: sid // Send the survey ID to the PHP file }, success: function(results){ // If we're at or above the maximum completes if($.isNumeric(results) && results >= maxCount) { // Handle the welcome text elements $('.normal-welcome').hide(); $('.survey-full-welcome').show(); // Remove all of the buttons $('#movenextbtn, #loadallbtn, #clearall, #therearexquestions').remove(); // Redirect here if you want } }, error: function(){ alert('Could not connect!'); } }); }
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ handleCompletes({SID}, 10); }); </script>
<?php define( 'LS_DB_HOST', 'localhost' ); define( 'LS_DB_NAME', 'database_name' ); define( 'LS_DB_USER', 'database_user_name' ); define( 'LS_DB_PASS', 'database_user_password' ); define( 'LS_DB_TABLEPREFIX', 'lime_' ); $sid = $_GET["sid"]; if(ctype_alnum($sid) && strlen($sid) == 6) { // Valid SID format $link = mysqli_connect(LS_DB_HOST, LS_DB_USER, LS_DB_PASS, LS_DB_NAME); // Check the connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // Query the survey table for all completed responses if ($result = mysqli_query($link, "SELECT * FROM ".LS_DB_TABLEPREFIX."survey_".$sid." WHERE `submitdate` IS NOT NULL")) { // Count number of rows in the result */ $completedCount = mysqli_num_rows($result); // Return that value echo $completedCount; // Close result set mysqli_free_result($result); } // Close the connection mysqli_close($link); } else { // Invalid SID format die( 'Invalid format!' ); } ?>
<?php require_once 'jsonRPCClient.php'; define( 'LS_BASEURL', 'https://path/to/limeSurvey/'); define( 'LS_USER', 'limesurvey_user_name' ); define( 'LS_PASSWORD', 'limesurvey_user_password' ); define( 'LS_DB_HOST', 'localhost' ); define( 'LS_DB_NAME', 'database_name' ); define( 'LS_DB_USER', 'database_user_name' ); define( 'LS_DB_PASS', 'database_user_password' ); define( 'LS_DB_TABLEPREFIX', 'lime_' ); $sid = $_GET["sid"]; if(ctype_alnum($sid) && strlen($sid) == 6) { // Valid SID format // Instantiate a new RPC client $myJSONRPCClient = new jsonRPCClient( LS_BASEURL.'/index.php/admin/remotecontrol' ); // Get a session key $sessionKey= $myJSONRPCClient->get_session_key( LS_USER, LS_PASSWORD ); // Call the API with the get_summary() method $completedCount = $myJSONRPCClient->get_summary($sessionKey, $sid, 'completed_responses'); // Return the completed surveys count echo $completedCount; // Release the session key $myJSONRPCClient->release_session_key( $sessionKey ); } else { // Invalid SID format die( 'Invalid format!' ); } ?>