0) {
error_reporting(E_ALL); //For debug purposes - switch on in config.phh
}
if (ini_get("max_execution_time")<120) @set_time_limit(120); // Maximum execution time - works only if safe_mode is off
@ini_set("memory_limit",$memorylimit); // Set Memory Limit for big surveys
// Now check for PHP & db version
// Do not localize/translate this!
$ver = explode( '.', PHP_VERSION );
$ver_num = $ver[0] . $ver[1] . $ver[2];
$dieoutput='';
$maildebug='';
if ( $ver_num < 432 )
{
$dieoutput .= 'This script needs PHP 4.3.2 or above! Your version: '.phpversion().' ';
}
if (!function_exists('mb_convert_encoding'))
{
$dieoutput .= "This script needs the PHP Multibyte String Functions library installed: See FAQ and PHP documentation ";
}
if ($dieoutput!='') die($dieoutput);
##################################################################################
## DO NOT EDIT BELOW HERE
##################################################################################
require_once ($rootdir.'/classes/adodb/adodb.inc.php');
require_once ($rootdir.'/classes/phpmailer/class.phpmailer.php');
require_once ($rootdir.'/classes/php-gettext/gettextinc.php');
require_once ($rootdir.'/classes/core/surveytranslator.php');
require_once ($rootdir.'/classes/core/sanitize.php');
$dbprefix=strtolower($dbprefix);
define("_PHPVERSION", phpversion());
if($_SERVER['SERVER_SOFTWARE'] == "Xitami") //Deal with Xitami Issue
{
$_SERVER['PHP_SELF'] = substr($_SERVER['SERVER_URL'], 0, -1) .$_SERVER['SCRIPT_NAME'];
}
/*
* $sourcefrom variable checks the location of the current script against
* the administration directory, and if the current script is running
* in the administration directory, it is set to "admin". Otherwise it is set
* to "public". When $sourcefrom is "admin" certain administration only functions
* are loaded.
*/
$scriptlocation=realpath(".");
$slashlesspath=str_replace(array("\\", "/"), "", $scriptlocation);
$slashlesshome=str_replace(array("\\", "/"), "", $homedir);
// Uncomment the following line for debug purposes
// echo $slashlesspath." - ".$slashlesshome;
if (eregi($slashlesshome, $slashlesspath) || eregi("dump", $_SERVER['PHP_SELF'])) {
if (!eregi($slashlesshome."install", $slashlesspath))
{
$sourcefrom="admin";
}
else
{
$sourcefrom="install";
}
} else {
$sourcefrom="public";
}
// Set path for captcha verification.php
if ($sourcefrom == "admin")
{
$captchapath='../';
}
else
{
$captchapath='';
}
//BEFORE SESSIONCONTOL BECAUSE OF THE CONNECTION
//CACHE DATA
$connect=&ADONewConnection($databasetype);
$database_exists = FALSE;
switch ($databasetype)
{
case "mysql" :if ($databaseport!="default") {$dbport="$databaselocation:$databaseport";}
else {$dbport=$databaselocation;}
break;
case "odbc_mssql": $dbport="Driver={SQL Server};Server=$databaselocation;Database=".$databasename;
break;
case "postgres": if ($databaseport!="default") {$dbport="$databaselocation:$databaseport";}
else {$dbport=$databaselocation;}
break;
default: safe_die("Unknown database type");
}
// Now try connecting to the database
if (@$connect->Connect($dbport, $databaseuser, $databasepass, $databasename))
{ $database_exists = TRUE;}
else {
// If that doesnt work try connection without database-name
$connect->database = '';
if ($databasetype=='odbc_mssql') {$dbport="Driver={SQL Server};Server=$databaselocation;";}
if (!@$connect->Connect($dbport, $databaseuser, $databasepass))
{
safe_die("Can't connect to LimeSurvey database. Reason: ".$connect->ErrorMsg());
}
}
// AdoDB seems to be defaulting to ADODB_FETCH_NUM and we want to be sure that the right default mode is set
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
$dbexistsbutempty=($database_exists && checkifemptydb());
if ($databasetype=='mysql') {
if ($debug>1) { @$connect->Execute("SET SESSION SQL_MODE='STRICT_ALL_TABLES,ANSI'"); } //for development - use mysql in the strictest mode //Checked
$infoarray=$connect->ServerInfo();
if (version_compare ($infoarray['version'],'4.1','<'))
{
safe_die (" Error: You need at least MySQL version 4.1 to run LimeSurvey");
}
@$connect->Execute("SET CHARACTER SET 'utf8'"); //Checked
}
// Setting dateformat for mssql driver. It seems if you don't do that the in- and output format could be different
if ($databasetype=='odbc_mssql') {
@$connect->Execute('SET DATEFORMAT ymd;'); //Checked
}
// Check if the DB is up to date
If ($dbexistsbutempty && $sourcefrom=='admin') {
die (" The LimeSurvey database does exist but it seems to be empty. Please run the install script to create the necessary tables.");
}
// Check if the DB is up to date
If (!$dbexistsbutempty && $sourcefrom=='admin')
{
$usquery = "SELECT stg_value FROM ".db_table_name("settings_global")." where stg_name='DBVersion'";
$usresult = db_execute_assoc($usquery,'',true); //checked
if (!$usresult)
{
die (" The configured LimeSurvey database does not seem to exist and the LimeSurvey tables weren't found. Please check the online manual for installation instructions. If you already edited config.php please run the installation script.");
}
$usrow = $usresult->FetchRow();
if (intval($usrow['stg_value'])<$dbversionnumber)
{
die (" The LimeSurvey database is not up to date. Please run the installation script to upgrade your database.");
}
if (is_dir($homedir."/install") && $debug<2)
{
die (" Everything is fine - you just forgot to delete or rename your LimeSurvey installation directory (/admin/install). Please do so since it may be a security risk.");
}
}
//Admin menus and standards
//IF THIS IS AN ADMIN SCRIPT, RUN THE SESSIONCONTROL SCRIPT
if ($sourcefrom == "admin")
{
include(dirname(__FILE__)."/admin/sessioncontrol.php");
/**
* @param string $htmlheader
* This is the html header text for all administration pages
*
*/
$htmlheader = getAdminHeader();
}
//SET LANGUAGE DIRECTORY
if ($sourcefrom == "admin")
{
$langdir="$publicurl/locale/".$_SESSION['adminlang']."/help";
$langdirlocal="$rootdir/locale/".$_SESSION['adminlang']."/help";
if (!is_dir($langdirlocal)) // is_dir only works on local dirs
{
$langdir="$publicurl/locale/en/help"; //default to english if there is no matching language dir
}
}
//SET LOCAL TIME
if (substr($timeadjust,1,1)!='-' && substr($timeadjust,1,1)!='+') {$timeadjust='+'.$timeadjust.' hours';}
// SITE STYLES
$setfont = "";
$singleborderstyle = "style='border: 1px solid #111111'";
/**
* showadminmenu() function returns html text for the administration button bar
* @global string $homedir
* @global string $scriptname
* @global string $surveyid
* @global string $setfont
* @global string $imagefiles
* @return string $adminmenu
*/
function showadminmenu()
{
global $homedir, $scriptname, $surveyid, $setfont, $imagefiles, $clang, $debug;
$adminmenu = "
\n";
if ($_SESSION['pw_notify'] && $debug<2) {$adminmenu .="
".$clang->gT("Warning: You are still using the default password ('password'). Please change your password and re-login again.")."
\n";
return $adminmenu;
}
//DATA TYPES
$qtypeselect = getqtypelist();
function &db_execute_num($sql,$inputarr=false)
{
global $connect;
// Todo: Set fetchmode to previous state after changing
//$oldfetchmode=
$connect->SetFetchMode(ADODB_FETCH_NUM);
$dataset=$connect->Execute($sql,$inputarr); //Checked
//$connect->SetFetchMode($oldfetchmode);
return $dataset;
}
function &db_select_limit_num($sql,$numrows=-1,$offset=-1,$inputarr=false)
{
global $connect;
$dataset=$connect->SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false) or safe_die($sql);
return $dataset;
}
function &db_execute_assoc($sql,$inputarr=false,$silent=false)
{
global $connect;
// Todo: Set fetchmode to previous state after changing
// $oldfetchmode=
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
$dataset=$connect->Execute($sql,$inputarr); //Checked
if (!$silent && !$dataset) {safe_die($connect->ErrorMsg().':'.$sql);}
// $connect->SetFetchMode($oldfetchmode);
return $dataset;
}
function &db_select_limit_assoc($sql,$numrows=-1,$offset=-1,$inputarr=false,$dieonerror=true)
{
global $connect;
$connect->SetFetchMode(ADODB_FETCH_ASSOC);
$dataset=$connect->SelectLimit($sql,$numrows,$offset,$inputarr=false);
if (!$dataset && $dieonerror) {safe_die($connect->ErrorMsg().':'.$sql);}
return $dataset;
}
function db_quote_id($id)
// This functions quotes fieldnames accordingly
{
global $databasetype;
// WE DONT HAVE nor USE other thing that alfanumeric characters in the field names
// $quote = $connect->nameQuote;
// return $quote.str_replace($quote,$quote.$quote,$id).$quote;
switch ($databasetype)
{
case "mysql" :
return "`".$id."`";
break;
case "odbc_mssql" :
return "[".$id."]";
break;
case "postgres":
return "\"".$id."\"";
break;
default:
return "`".$id."`";
}
}
function db_random()
{
global $connect,$databasetype;
if ($databasetype=='odbc_mssql') {$srandom='NEWID()';}
else {$srandom=$connect->random;}
return $srandom;
}
function db_quote($str)
// This functions escapes the string only inside
{
global $connect;
return $connect->escape($str);
}
function db_quoteall($str,$ispostvar=false)
// This functions escapes the string inside and puts quotes around the string according to the used db type
// IF you are quoting a variable from a POST/GET then set $ispostvar to true so it doesnt get quoted twice.
{
global $connect;
if ($ispostvar) { return $connect->qstr($str, get_magic_quotes_gpc());}
else {return $connect->qstr($str);}
}
function db_table_name($name)
{
global $dbprefix;
return db_quote_id($dbprefix.$name);
}
function db_table_name_nq($name)
//returns the table name without quotes
{
global $dbprefix;
return $dbprefix.$name;
}
/*
* Return a sql statement for finding LIKE named tables
*/
function db_select_tables_like($table)
{
global $databasetype;
switch ($databasetype) {
case 'mysql' :
return "SHOW TABLES LIKE '$table'";
case 'odbc_mssql' :
return "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE' and TABLE_NAME LIKE '$table'";
case 'postgres' :
return "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' and table_name like '$table'";
default: safe_die ("Couldn't create 'select tables like' query for connection type 'databaseType'");
}
}
/*
* Return a boolean stating if the table(s) exist(s)
* Accepts '%' in names since it uses the 'like' statement
*/
function db_tables_exist($table)
{
global $connect;
$surveyHasTokensTblQ = db_select_tables_like("$table");
$surveyHasTokensTblResult = db_execute_num($surveyHasTokensTblQ); //Checked
if ($surveyHasTokensTblResult->RecordCount() >= 1)
{
return TRUE;
}
else
{
return FALSE;
}
}
/**
* getsurveylist() Queries the database (survey table) for a list of existing surveys
* @global string $surveyid
* @global string $dbprefix
* @global string $scriptname
* @return string This string is returned containing formatted list of existing surveys
*
*/
function getsurveylist()
{
global $surveyid, $dbprefix, $scriptname, $connect, $clang;
$surveyidquery = "SELECT a.sid, a.owner_id, surveyls_title, surveyls_description, a.admin, a.active, surveyls_welcometext, a.useexpiry, a.expires, "
. "a.adminemail, a.private, a.faxto, a.format, a.template, a.url, "
. "a.language, a.datestamp, a.ipaddr, a.refurl, a.usecookie, a.notification, a.allowregister, a.attribute1, a.attribute2, "
. "a.allowsave, a.autoredirect, a.allowprev, a.datecreated FROM ".db_table_name('surveys')." AS a "
. "INNER JOIN ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=a.sid and surveyls_language=a.language) ";
if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1)
{
$surveyidquery .= " INNER JOIN ".db_table_name('surveys_rights')." AS b ON a.sid = b.sid ";
$surveyidquery .= "WHERE b.uid =".$_SESSION['loginID'];
}
$surveyidquery .= " order by active DESC, surveyls_title";
$surveyidresult = db_execute_num($surveyidquery); //Checked
if (!$surveyidresult) {return "Database Error";}
$surveyselecter = "";
$surveynames = $surveyidresult->GetRows();
$activesurveys='';
$inactivesurveys='';
if ($surveynames)
{
foreach($surveynames as $sv)
{
if($sv[5]!='Y')
{
$inactivesurveys .= "\t\t\t";
}
if (!isset($svexist)) {$surveyselecter = "\t\t\t\n".$surveyselecter;}
else {$surveyselecter = "\t\t\t\n".$surveyselecter;}
return $surveyselecter;
}
/**
* getquestions() queries the database for a list of all questions matching the current survey sid
* @global string $surveyid
* @global string $gid
* @global string $qid
* @global string $dbprefix
* @global string $scriptname
* @return This string is returned containing formatted list of questions to current survey
*/
function getquestions($surveyid,$gid,$selectedqid)
{
global $dbprefix, $scriptname, $connect, $clang;
//MOD for multilanguage surveys
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$qquery = 'SELECT * FROM '.db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND language='{$s_lang}'";
$qresult = db_execute_assoc($qquery); //checked
$qrows = $qresult->GetRows();
// Perform a case insensitive natural sort on group name then question title of a multidimensional array
usort($qrows, 'CompareGroupThenTitle');
if (!isset($questionselecter)) {$questionselecter="";}
foreach ($qrows as $qrow)
{
$qrow['title'] = strip_tags($qrow['title']);
$questionselecter .= "\t\t\n".$questionselecter;
}
return $questionselecter;
}
// Gets number of groups inside a particular survey
function getGroupSum($surveyid, $lang)
{
global $surveyid,$dbprefix ;
$sumquery3 = "SELECT * FROM ".db_table_name('groups')." WHERE sid=$surveyid AND language='".$lang."'"; //Getting a count of questions for this survey
$sumresult3 = db_execute_assoc($sumquery3); //Checked
$groupscount = $sumresult3->RecordCount();
return $groupscount ;
}
// Gets number of questions inside a particular group
function getQuestionSum($surveyid, $groupid)
{
global $surveyid,$dbprefix ;
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$sumquery3 = "SELECT * FROM ".db_table_name('questions')." WHERE gid=$groupid and sid=$surveyid AND language='{$s_lang}'"; //Getting a count of questions for this survey
$sumresult3 = db_execute_assoc($sumquery3); //Checked
$questionscount = $sumresult3->RecordCount();
return $questionscount ;
}
/**
* getMaxgrouporder($surveyid) queries the database for the maximum sortorder of a group.
* @global string $surveyid
*/
function getMaxgrouporder($surveyid)
{
global $surveyid ;
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$max_sql = "SELECT max( group_order ) AS max FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}'" ;
$max_result =db_execute_assoc($max_sql) ; //Checked
$maxrow = $max_result->FetchRow() ;
$current_max = $maxrow['max'];
if($current_max=="")
{
return "0" ;
}
else return ++$current_max ;
}
/**
* getGroupOrder($surveyid,$gid) queries the database for the sortorder of a group.
*/
function getGroupOrder($surveyid,$gid)
{
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$grporder_sql = "SELECT group_order FROM ".db_table_name('groups')." WHERE sid =$surveyid AND language='{$s_lang}' AND gid=$gid" ;
$grporder_result =db_execute_assoc($grporder_sql); //Checked
$grporder_row = $grporder_result->FetchRow() ;
$group_order = $grporder_row['group_order'];
if($group_order=="")
{
return "0" ;
}
else return $group_order ;
}
/**
* getMaxquestionorder($gid) queries the database for the maximum sortorder of a question.
* @global string $surveyid
*/
function getMaxquestionorder($gid)
{
global $surveyid ;
$gid=sanitize_int($gid);
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$max_sql = "SELECT max( question_order ) AS max FROM ".db_table_name('questions')." WHERE gid='$gid' AND language='$s_lang'";
$max_result =db_execute_assoc($max_sql) ; //Checked
$maxrow = $max_result->FetchRow() ;
$current_max = $maxrow['max'];
if($current_max=="")
{
return "0" ;
}
else return $current_max ;
}
/**
* getanswers() queries the database for a list of all answers matching the current question qid
* @global string $surveyid
* @global string $gid
* @global string $qid
* @global string $dbprefix
* @global string $code
* @return This string is returned containing formatted list of answers matching current qid
*/
function getanswers()
{
global $surveyid, $gid, $qid, $code, $dbprefix, $connect, $clang;
$qid=sanitize_int($qid);
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$aquery = "SELECT code, answer FROM ".db_table_name('answers')." WHERE qid=$qid AND language='$s_lang' ORDER BY sortorder, answer";
$aresult = db_execute_assoc($aquery); //Checked
$answerselecter = "";
while ($arow = $aresult->FetchRow())
{
$answerselecter .= "\t\t\n".$answerselecter;}
return $answerselecter;
}
/**
* getqtypelist() Returns list of question types available in LimeSurvey. Edit this if you are adding a new
* question type
* @global string $publicurl
* @global string $sourcefrom
* @param string $SelectedCode Value of the Question Type (defaults to "T")
* @param string $ReturnType Type of output from this function (defaults to selector)
* @return depending on $ReturnType param, returns a straight "array" of question types, or an list
*/
function getqtypelist($SelectedCode = "T", $ReturnType = "selector")
{
global $publicurl;
global $sourcefrom, $clang;
if ($sourcefrom == "admin")
{
$qtypes = array(
"1"=>$clang->gT("Array (Flexible Labels) Dual Scale"),
"5"=>$clang->gT("5 Point Choice"),
"A"=>$clang->gT("Array (5 Point Choice)"),
"B"=>$clang->gT("Array (10 Point Choice)"),
"C"=>$clang->gT("Array (Yes/No/Uncertain)"),
"D"=>$clang->gT("Date"),
"E"=>$clang->gT("Array (Increase, Same, Decrease)"),
"F"=>$clang->gT("Array (Flexible Labels)"),
"G"=>$clang->gT("Gender"),
"H"=>$clang->gT("Array (Flexible Labels) by Column"),
"I"=>$clang->gT("Language Switch"),
"K"=>$clang->gT("Multiple Numerical Input"),
"L"=>$clang->gT("List (Radio)"),
"M"=>$clang->gT("Multiple Options"),
"N"=>$clang->gT("Numerical Input"),
"O"=>$clang->gT("List With Comment"),
"P"=>$clang->gT("Multiple Options With Comments"),
"Q"=>$clang->gT("Multiple Short Text"),
"R"=>$clang->gT("Ranking"),
"S"=>$clang->gT("Short Free Text"),
"T"=>$clang->gT("Long Free Text"),
"U"=>$clang->gT("Huge Free Text"),
"W"=>$clang->gT("List (Flexible Labels) (Dropdown)"),
"X"=>$clang->gT("Boilerplate Question"),
"Y"=>$clang->gT("Yes/No"),
"Z"=>$clang->gT("List (Flexible Labels) (Radio)"),
"!"=>$clang->gT("List (Dropdown)")
// "^"=>$clang->gT("Slider"),
);
asort($qtypes);
if ($ReturnType == "array") {return $qtypes;}
$qtypeselecter = "";
foreach($qtypes as $TypeCode=>$TypeDescription)
{
$qtypeselecter .= "\t\t formatted list of notification methods for current survey
*/
function getNotificationlist($notificationcode)
{
global $clang;
$ntypes = array(
"0"=>$clang->gT("No email notification"),
"1"=>$clang->gT("Basic email notification"),
"2"=>$clang->gT("Detailed email notification with result codes")
);
if (!isset($ntypeselector)) {$ntypeselector="";}
foreach($ntypes as $ntcode=>$ntdescription)
{
$ntypeselector .= "\t\t formatted list of groups to current survey
*/
function getgrouplist($gid)
{
global $surveyid, $dbprefix, $scriptname, $connect, $clang;
$groupselecter="";
$gid=sanitize_int($gid);
$surveyid=sanitize_int($surveyid);
if (!$surveyid) {$surveyid=returnglobal('sid');}
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$gidquery = "SELECT gid, group_name FROM ".db_table_name('groups')." WHERE sid='{$surveyid}' AND language='{$s_lang}' ORDER BY group_order";
$gidresult = db_execute_num($gidquery) or safe_die("Couldn't get group list in common.php $gidquery ".$connect->ErrorMsg()); //Checked
while($gv = $gidresult->FetchRow())
{
$groupselecter .= "\t\t\n".$groupselecter;}
else {$groupselecter .= "\t\t\n";}
}
return $groupselecter;
}
function getgrouplist2($gid)
{
global $surveyid, $dbprefix, $connect, $clang;
$groupselecter = "";
if (!$surveyid) {$surveyid=returnglobal('sid');}
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$gidquery = "SELECT gid, group_name FROM ".db_table_name('groups')." WHERE sid=$surveyid AND language='{$s_lang}' ORDER BY group_order";
$gidresult = db_execute_num($gidquery) or safe_die("Plain old did not work!"); //Checked
while ($gv = $gidresult->FetchRow())
{
$groupselecter .= "\t\t\n".$groupselecter;}
else {$groupselecter .= "\t\t\n";}
}
return $groupselecter;
}
function getgrouplist3($gid)
{
global $surveyid, $dbprefix, $connect;
if (!$surveyid) {$surveyid=returnglobal('sid');}
$groupselecter = "";
$s_lang = GetBaseLanguageFromSurveyID($surveyid);
$gidquery = "SELECT gid, group_name FROM ".db_table_name('groups')." WHERE sid=$surveyid AND language='{$s_lang}' ORDER BY group_order";
$gidresult = db_execute_num($gidquery) or safe_die("Plain old did not work!"); //Checked
while ($gv = $gidresult->FetchRow())
{
$groupselecter .= "\t\t\n".$groupselecter;}
else {$groupselecter .= "\t\t\n";}
}
return $groupselecter;
}
function getuserlist($outputformat='fullinfoarray')
{
global $dbprefix, $connect;
global $usercontrolSameGroupPolicy;
if (isset($_SESSION['loginID']))
{
$myuid=sanitize_int($_SESSION['loginID']);
}
if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1 && isset($usercontrolSameGroupPolicy) &&
$usercontrolSameGroupPolicy === true)
{
if (isset($myuid))
{
// List users from same group as me + all my childs
$uquery = "SELECT u.* FROM ".db_table_name('users')." AS u, ".db_table_name('user_in_groups')." AS ga ,".db_table_name('user_in_groups')." AS gb WHERE u.uid=$myuid OR (ga.ugid=gb.ugid AND ( (gb.uid=$myuid AND u.uid=ga.uid) OR (u.parent_id=$myuid) ) ) GROUP BY u.uid";
}
else
{
return Array(); // Or die maybe
}
}
else
{
$uquery = "SELECT * FROM ".db_table_name('users')." ORDER BY uid";
}
$uresult = db_execute_assoc($uquery); //Checked
if ($uresult->RecordCount()==0)
//user is not in a group and usercontrolSameGroupPolicy is activated - at least show his own userinfo
{
$uquery = "SELECT u.* FROM ".db_table_name('users')." AS u WHERE u.uid=".$myuid;
$uresult = db_execute_assoc($uquery);//Checked
}
$userlist = array();
$userlist[0] = "Reserved for logged in user";
while ($srow = $uresult->FetchRow())
{
if ($outputformat != 'onlyuidarray')
{
if ($srow['uid'] != $_SESSION['loginID'])
{
$userlist[] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']); //added by Dennis modified by Moses
}
else
{
$userlist[0] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']);
}
}
else
{
if ($srow['uid'] != $_SESSION['loginID'])
{
$userlist[] = $srow['uid'];
}
else
{
$userlist[0] = $srow['uid'];
}
}
}
return $userlist;
}
function gettemplatelist()
{
global $publicdir;
if (!$publicdir) {$publicdir=dirname(getcwd());}
$tloc="$publicdir/templates";
if ($handle = opendir($tloc))
{
while (false !== ($file = readdir($handle)))
{
if (!is_file("$tloc/$file") && $file != "." && $file != ".." && $file!=".svn")
{
$list_of_files[] = $file;
}
}
closedir($handle);
}
usort($list_of_files, 'StandardSort');
return $list_of_files;
}
function getSurveyInfo($surveyid, $languagecode='')
// Gets all survey infos in one big array including the language specific settings
// if $languagecode is not set then the base language from the survey is used
//
{
global $dbprefix, $siteadminname, $siteadminemail, $connect, $languagechanger;
$surveyid=sanitize_int($surveyid);
$languagecode=sanitize_languagecode($languagecode);
$thissurvey=false;
// if no language code is set then get the base language one
if (!isset($languagecode) || $languagecode=='')
{
$languagecode=GetBaseLanguageFromSurveyID($surveyid);;
}
$query="SELECT * FROM ".db_table_name('surveys').",".db_table_name('surveys_languagesettings')." WHERE sid=$surveyid and surveyls_survey_id=$surveyid and surveyls_language='$languagecode'";
$result=db_execute_assoc($query) or safe_die ("Couldn't access survey settings $query ".$connect->ErrorMsg()); //Checked
while ($row=$result->FetchRow())
{
$thissurvey=$row;
// now create some stupid array translations
// Newly added surveysettings don't have to be added specifically - these will be available by field name automatically
$thissurvey["name"]=$thissurvey['surveyls_title'];
$thissurvey["description"]=$thissurvey['surveyls_description'];
$thissurvey["welcome"]=$thissurvey['surveyls_welcometext'];
$thissurvey["templatedir"]=$thissurvey['template'];
$thissurvey["adminname"]=$thissurvey['admin'];
$thissurvey["tablename"]=$dbprefix."survey_".$thissurvey['sid'];
$thissurvey["urldescrip"]=$thissurvey['surveyls_urldescription'];
$thissurvey["sendnotification"]=$thissurvey['notification'];
$thissurvey["expiry"]=$thissurvey['expires'];
$thissurvey["email_invite_subj"]=$thissurvey['surveyls_email_invite_subj'];
$thissurvey["email_invite"]=$thissurvey['surveyls_email_invite'];
$thissurvey["email_remind_subj"]=$thissurvey['surveyls_email_remind_subj'];
$thissurvey["email_remind"]=$thissurvey['surveyls_email_remind'];
$thissurvey["email_confirm_subj"]=$thissurvey['surveyls_email_confirm_subj'];
$thissurvey["email_confirm"]=$thissurvey['surveyls_email_confirm'];
$thissurvey["email_register_subj"]=$thissurvey['surveyls_email_register_subj'];
$thissurvey["email_register"]=$thissurvey['surveyls_email_register'];
if (!isset($thissurvey['adminname'])) {$thissurvey['adminname']=$siteadminname;}
if (!isset($thissurvey['adminemail'])) {$thissurvey['adminemail']=$siteadminemail;}
if (!isset($thissurvey['urldescrip'])) {$thissurvey['urldescrip']=$thissurvey['url'];}
}
//not sure this should be here... ToDo: Find a better place
if (function_exists('makelanguagechanger')) $languagechanger = makelanguagechanger();
return $thissurvey;
}
function getlabelsets($languages=null)
// Returns a list with label sets
// if the $languages paramter is provided then only labelset containing all of the languages in the paramter are provided
{
global $dbprefix, $connect, $surveyid;
if ($languages){
$languages=sanitize_languagecodeS($languages);
$languagesarray=explode(' ',trim($languages));
}
$query = "SELECT ".db_table_name('labelsets').".lid as lid, label_name FROM ".db_table_name('labelsets');
if ($languages){
$query .=" where ";
foreach ($languagesarray as $item)
{
$query .=" ((languages like '% $item %') or (languages='$item') or (languages like '% $item') or (languages like '$item %')) and ";
}
$query .=" 1=1 ";
}
$query .=" order by label_name";
$result = db_execute_assoc($query) or safe_die ("Couldn't get list of label sets $query ".$connect->ErrorMsg()); //Checked
$labelsets=array();
while ($row=$result->FetchRow())
{
$labelsets[] = array($row['lid'], $row['lid'].": ".$row['label_name']);
}
return $labelsets;
}
function checkactivations()
{
global $dbprefix, $connect;
$tablelist = $connect->MetaTables();
$tablenames[] = "ListofTables"; //dummy entry because in_array never finds the first one!
foreach ($tablelist as $tbl)
{
$tablenames[] = $tbl;
}
$caquery = "SELECT sid FROM ".db_table_name('surveys')." WHERE active='Y'";
$caresult = db_execute_assoc($caquery); //Checked
if (!$caresult) {return "Database Error";}
while ($carow = $caresult->FetchRow())
{
$surveyname = "{$dbprefix}survey_{$carow['sid']}";
if (!in_array($surveyname, $tablenames))
{
$udquery = "UPDATE ".db_table_name('surveys')." SET active='N' WHERE sid={$carow['sid']}";
$udresult = $connect->Execute($udquery); //Checked
}
}
}
function checkifemptydb()
{
global $connect, $dbprefix;
$tablelist = $connect->MetaTables('TABLES');
if ( in_array($dbprefix.'surveys',$tablelist) ) {Return(false);}
else {Return(true);}
}
function checkfortables()
{
global $scriptname, $dbprefix, $setfont, $connect, $clang;
$alltables=array("{$dbprefix}surveys",
"{$dbprefix}groups",
"{$dbprefix}questions",
"{$dbprefix}answers",
"{$dbprefix}conditions",
"{$dbprefix}users",
"{$dbprefix}labelsets",
"{$dbprefix}labels");
$tables = $connect->MetaTables();
foreach($alltables as $at)
{
if (!sql_table_exists($at, $tables))
{
$checkfields="Y";
}
}
if (!isset($checkfields)) {$checkfields="";}
if ($checkfields=="Y")
{
echo " \n"
."
\n"
."\t
"
.$clang->gT("LimeSurvey Setup")."
\n"
."\t
$setfont\n"
."\t\t"
.$clang->gT("Error")." \n"
."\t\t"
.$clang->gT("It appears as if some tables or fields are missing from your database.")."