Skip to content

Commit

Permalink
dev Removed TokenTableExists function and replaced it with a generic …
Browse files Browse the repository at this point in the history
…tableExists function

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@7992 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 26, 2009
1 parent dda08ac commit d394735
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 59 deletions.
8 changes: 1 addition & 7 deletions admin/browse.php
Expand Up @@ -25,13 +25,7 @@
if (!isset($dbprefix) || isset($_REQUEST['dbprefix'])) {die("Cannot run this script directly");}

//Check if results table exists
$tablelist = $connect->MetaTables() or safe_die ("Error getting tokens<br />".$connect->ErrorMsg());
foreach ($tablelist as $tbl)
{
if (db_quote_id($tbl) == db_table_name('survey_'.$surveyid)) $resultsexist = 1;
}

if (!isset($resultsexist)) die("Your results table is missing!");
if (tableExists('survey_'.$surveyid)==false) die("Your results table is missing!");

$sumquery5 = "SELECT b.* FROM {$dbprefix}surveys AS a INNER JOIN {$dbprefix}surveys_rights AS b ON a.sid = b.sid WHERE a.sid=$surveyid AND b.uid = ".$_SESSION['loginID']; //Getting rights for this survey and user
$sumresult5 = db_execute_assoc($sumquery5);
Expand Down
12 changes: 6 additions & 6 deletions admin/dataentry.php
Expand Up @@ -139,15 +139,15 @@
}
}

if (tokenTableExists($thissurvey['sid']) && (!isset($_POST['token']) || !$_POST['token']))
if (tableExists('token_'.$thissurvey['sid']) && (!isset($_POST['token']) || !$_POST['token']))
{// First Check if the survey uses tokens and if a token has been provided
$errormsg="<strong><font color='red'>".$clang->gT("Error").":</font> ".$clang->gT("This is a closed-access survey, so you must supply a valid token. Please contact the administrator for assistance.")."</strong>\n";
}
elseif (tokenTableExists($thissurvey['sid']) && $lastanswfortoken == 'UnknownToken')
elseif (tableExists('token_'.$thissurvey['sid']) && $lastanswfortoken == 'UnknownToken')
{
$errormsg="<strong><font color='red'>".$clang->gT("Error").":</font> ".$clang->gT("The token you have provided is not valid or has already been used.")."</strong>\n";
}
elseif (tokenTableExists($thissurvey['sid']) && $lastanswfortoken != '')
elseif (tableExists('token_'.$thissurvey['sid']) && $lastanswfortoken != '')
{
$errormsg="<strong><font color='red'>".$clang->gT("Error").":</font> ".$clang->gT("There is already a recorded answer for this token")."</strong>\n";
if ($lastanswfortoken != 'PrivacyProtected')
Expand Down Expand Up @@ -414,7 +414,7 @@
$insertqr = substr($insertqr, 0, -3); //Strip off the last comma-space

//NOW SHOW SCREEN
if (tokenTableExists($thissurvey['sid']) &&
if (tableExists('token_'.$thissurvey['sid']) &&
isset($_POST['token']) && $_POST['token'] &&
$thissurvey['private'] == 'N') //handle tokens if survey needs them
{
Expand Down Expand Up @@ -1881,7 +1881,7 @@ function saveshow(value)
."</td>\n"
."\t</tr>\n";

if (tokenTableExists($thissurvey['sid'])) //Give entry field for token id
if (tableExists('token_'.$thissurvey['sid'])) //Give entry field for token id
{
$dataentryoutput .= "\t<tr>\n"
."<td valign='top' width='1%'></td>\n"
Expand Down Expand Up @@ -2994,7 +2994,7 @@ function saveshow(value)
$dataentryoutput .= "<td colspan='3' align='center'>\n";
$dataentryoutput .= "\t<input type='submit' id='submitdata' value='".$clang->gT("Submit")."'";

if (tokenTableExists($thissurvey['sid']))
if (tableExists('token_'.$thissurvey['sid']))
{
$dataentryoutput .= " disabled='disabled'/>\n";
}
Expand Down
3 changes: 1 addition & 2 deletions admin/deactivate.php
Expand Up @@ -38,8 +38,7 @@
else
{
//See if there is a tokens table for this survey
$tablelist = $connect->MetaTables();
if (in_array("{$dbprefix}tokens_{$postsid}", $tablelist))
if (tableExists("tokens_{$postsid}"))
{
$toldtable="tokens_{$postsid}";
$tnewtable="old_tokens_{$postsid}_{$date}";
Expand Down
12 changes: 4 additions & 8 deletions admin/deletesurvey.php
Expand Up @@ -33,24 +33,21 @@

if (!isset($deleteok) || !$deleteok)
{
$tablelist = $connect->MetaTables();

$deletesurveyoutput .= "\t<div class='warningheader'>\n".$clang->gT("Warning")."</div><br />\n";
$deletesurveyoutput .= "\t<strong>".$clang->gT("You are about to delete this survey")." ($surveyid)</strong><br /><br />\n";
$deletesurveyoutput .= "\t".$clang->gT("This process will delete this survey, and all related groups, questions answers and conditions.")."<br /><br />\n";
$deletesurveyoutput .= "\t".$clang->gT("We recommend that before you delete this survey you export the entire survey from the main administration screen.")."\n";

if (in_array("{$dbprefix}survey_$surveyid", $tablelist))
if (tableExists("survey_$surveyid"))
{
$deletesurveyoutput .= "\t<br /><br />\n".$clang->gT("This survey is active and a responses table exists. If you delete this survey, these responses will be deleted. We recommend that you export the responses before deleting this survey.")."<br /><br />\n";
}

if (in_array("{$dbprefix}tokens_$surveyid", $tablelist))
if (tableExists("tokens_$surveyid"))
{
$deletesurveyoutput .= "\t".$clang->gT("This survey has an associated tokens table. If you delete this survey this tokens table will be deleted. We recommend that you export or backup these tokens before deleting this survey.")."<br /><br />\n";
}


$deletesurveyoutput .= "<p>\n";
$deletesurveyoutput .= "\t<input type='submit' value='".$clang->gT("Delete survey")."' onclick=\"".get2post("$scriptname?action=deletesurvey&amp;sid=$surveyid&amp;deleteok=Y")."\" />\n";
$deletesurveyoutput .= "\t<input type='submit' value='".$clang->gT("Cancel")."' onclick=\"window.open('admin.php?sid=$surveyid', '_top')\" />\n";
Expand All @@ -59,17 +56,16 @@

else //delete the survey
{
$tablelist = $connect->MetaTables();
$dict = NewDataDictionary($connect);

if (in_array("{$dbprefix}survey_$surveyid", $tablelist)) //delete the survey_$surveyid table
if (tableExists("survey_$surveyid")) //delete the survey_$surveyid table
{
$dsquery = $dict->DropTableSQL("{$dbprefix}survey_$surveyid");
//$dict->ExecuteSQLArray($sqlarray);
$dsresult = $dict->ExecuteSQLArray($dsquery) or safe_die ("Couldn't \"$dsquery\" because <br />".$connect->ErrorMsg());
}

if (in_array("{$dbprefix}tokens_$surveyid", $tablelist)) //delete the tokens_$surveyid table
if (tableExists("tokens_$surveyid")) //delete the tokens_$surveyid table
{
$dsquery = $dict->DropTableSQL("{$dbprefix}tokens_$surveyid");
$dsresult = $dict->ExecuteSQLArray($dsquery) or safe_die ("Couldn't \"$dsquery\" because <br />".$connect->ErrorMsg());
Expand Down
2 changes: 1 addition & 1 deletion admin/export_data_functions.php
Expand Up @@ -292,7 +292,7 @@ function spss_fieldmap($prefix = 'V') {
$fieldmap = createFieldMap($surveyid, 'full'); //Create a FULL fieldmap

#See if tokens are being used
$tokensexist = tokenTableExists($surveyid);
$tokensexist = tableExists('token_'.$surveyid);

#Lookup the names of the attributes
$query="SELECT sid, private, language FROM {$dbprefix}surveys WHERE sid=$surveyid";
Expand Down
2 changes: 1 addition & 1 deletion admin/exportresults.php
Expand Up @@ -365,7 +365,7 @@
// Actual export routines start here !
// ======================================================================

$tokenTableExists=tokenTableExists($surveyid);
$tokenTableExists=tableExists('token_'.$surveyid);

if ($tokenTableExists)
{
Expand Down
2 changes: 1 addition & 1 deletion admin/html.php
Expand Up @@ -68,7 +68,7 @@
else $privacy =$clang->gT("No") ;


if (tokenTableExists($rows['sid']))
if (tableExists('token_'.$rows['sid']))
{
$visibility = $clang->gT("Closed-access");
}
Expand Down
1 change: 0 additions & 1 deletion admin/install/cmd_install.php
Expand Up @@ -158,7 +158,6 @@
if ($upgradedbtype=='mssql_n' || $upgradedbtype=='odbc_mssql' || $upgradedbtype=='odbtp') $upgradedbtype='mssql';

include ('upgrade-'.$upgradedbtype.'.php');
$tables = $connect->MetaTables();

$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='DBVersion'";
$usresult = db_execute_assoc($usquery);
Expand Down
3 changes: 0 additions & 3 deletions admin/resetsurveylogic.php
Expand Up @@ -34,8 +34,6 @@

if (!isset($ok) || !$ok)
{
$tablelist = $connect->MetaTables();

$resetsurveylogicoutput .= "\t<tr>\n";
$resetsurveylogicoutput .= "\t\t<td align='center'><br />\n";
$resetsurveylogicoutput .= "\t\t\t<font color='red'><strong>".$clang->gT("Warning")."</strong></font><br />\n";
Expand All @@ -56,7 +54,6 @@

else //delete conditions in the survey
{
$tablelist = $connect->MetaTables();
$dict = NewDataDictionary($connect);

$resetlogicquery = "DELETE FROM {$dbprefix}conditions WHERE qid in (select qid from {$dbprefix}questions where sid=$surveyid)";
Expand Down
2 changes: 1 addition & 1 deletion admin/tokens.php
Expand Up @@ -282,7 +282,7 @@
}

// CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY
$tokenexists=tokenTableExists($surveyid);
$tokenexists=tableExists('token_'.$surveyid);
if (!$tokenexists) //If no tokens table exists
{
if (isset($_POST['createtable']) && $_POST['createtable']=="Y" &&
Expand Down
3 changes: 1 addition & 2 deletions admin/vvimport.php
Expand Up @@ -73,8 +73,7 @@
}

//Make sure that the survey is active
$tablelist = $connect->MetaTables();
if (in_array("{$dbprefix}survey_$surveyid", $tablelist))
if (tableExists("survey_$surveyid"))
{

$vvoutput = browsemenubar($clang->gT("Import VV file")).
Expand Down
34 changes: 9 additions & 25 deletions common.php
Expand Up @@ -198,7 +198,7 @@

$connect->SetFetchMode(ADODB_FETCH_ASSOC);

$dbexistsbutempty=($database_exists && checkifemptydb());
$dbexistsbutempty=($database_exists && tableExists('surveys'));



Expand Down Expand Up @@ -1552,22 +1552,6 @@ function getlabelsets($languages=null)
return $labelsets;
}


function checkifemptydb()
{
global $connect, $dbprefix;
$tablelist = $connect->MetaTables('TABLES');
if ( in_array($dbprefix.'surveys',$tablelist) ) {Return(false);}
else {Return(true);}
}


function sql_table_exists($tableName, $tables)
{
return(in_array($tableName, $tables));
}


/**
* Compares two elements from an array (passed by the usort function)
* and returns -1, 0 or 1 depending on the result of the comparison of
Expand Down Expand Up @@ -5889,12 +5873,12 @@ function retrieve_Answer($code, $phpdateformat=null)
}

/**
* Check if token table odes exist
* Check if a table does exist in the database
*
* @param mixed $sid The survey id to check
* @return boolean true if thesurvey has a token table defined
* @param mixed $sid Table name to check for (without dbprefix!))
* @return boolean True or false if table exists or not
*/
function tokenTableExists($surveyid)
function tableExists($tablename)
{
global $connect;
$tablelist = $connect->MetaTables() or safe_die ("Error getting tokens<br />".$connect->ErrorMsg());
Expand All @@ -5914,7 +5898,7 @@ function tokenTableExists($surveyid)
// Returns true otherwise
function bIsTokenCompletedDatestamped($thesurvey)
{
if ($thesurvey['private'] == 'Y' && tokenTableExists($thesurvey['sid']))
if ($thesurvey['private'] == 'Y' && tableExists('token_'.$thesurvey['sid']))
{
return false;
}
Expand Down Expand Up @@ -6843,9 +6827,9 @@ function filterforattributes ($fieldname)
function GetAttributeFieldNames($surveyid)
{
global $dbprefix, $connect;
if (tokenTableExists($surveyid) === false)
if (tableExists('token_'.$surveyid) === false)
{
return Array();
return Array();
}
$tokenfieldnames = array_values($connect->MetaColumnNames("{$dbprefix}tokens_$surveyid", true));
return array_filter($tokenfieldnames,'filterforattributes');
Expand Down Expand Up @@ -6873,7 +6857,7 @@ function GetTokenConditionsFieldNames($surveyid)
function GetTokenFieldsAndNames($surveyid, $onlyAttributes=false)
{
global $dbprefix, $connect, $clang;
if (tokenTableExists($surveyid) === false)
if (tableExists('token_'.$surveyid) === false)
{
return Array();
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -423,7 +423,7 @@

//SEE IF SURVEY USES TOKENS
$i = 0; //$tokensexist = 0;
if ($surveyexists == 1 && tokenTableExists($thissurvey['sid']))
if ($surveyexists == 1 && tableExists('token_'.$thissurvey['sid']))
{
$tokensexist = 1;
}
Expand Down

0 comments on commit d394735

Please sign in to comment.