$clang->gT("ARMSCII-8 Armenian") ,"ascii"=>$clang->gT("US ASCII") ,"auto"=>$clang->gT("Automatic") ,"big5"=>$clang->gT("Big5 Traditional Chinese") ,"binary"=>$clang->gT("Binary pseudo charset") ,"cp1250"=>$clang->gT("Windows Central European") ,"cp1251"=>$clang->gT("Windows Cyrillic") ,"cp1256"=>$clang->gT("Windows Arabic") ,"cp1257"=>$clang->gT("Windows Baltic") ,"cp850"=>$clang->gT("DOS West European") ,"cp852"=>$clang->gT("DOS Central European") ,"cp866"=>$clang->gT("DOS Russian") ,"cp932"=>$clang->gT("SJIS for Windows Japanese") ,"dec8"=>$clang->gT("DEC West European") ,"eucjpms"=>$clang->gT("UJIS for Windows Japanese") ,"euckr"=>$clang->gT("EUC-KR Korean") ,"gb2312"=>$clang->gT("GB2312 Simplified Chinese") ,"gbk"=>$clang->gT("GBK Simplified Chinese") ,"geostd8"=>$clang->gT("GEOSTD8 Georgian") ,"greek"=>$clang->gT("ISO 8859-7 Greek") ,"hebrew"=>$clang->gT("ISO 8859-8 Hebrew") ,"hp8"=>$clang->gT("HP West European") ,"keybcs2"=>$clang->gT("DOS Kamenicky Czech-Slovak") ,"koi8r"=>$clang->gT("KOI8-R Relcom Russian") ,"koi8u"=>$clang->gT("KOI8-U Ukrainian") ,"latin1"=>$clang->gT("cp1252 West European") ,"latin2"=>$clang->gT("ISO 8859-2 Central European") ,"latin5"=>$clang->gT("ISO 8859-9 Turkish") ,"latin7"=>$clang->gT("ISO 8859-13 Baltic") ,"macce"=>$clang->gT("Mac Central European") ,"macroman"=>$clang->gT("Mac West European") ,"sjis"=>$clang->gT("Shift-JIS Japanese") ,"swe7"=>$clang->gT("7bit Swedish") ,"tis620"=>$clang->gT("TIS620 Thai") ,"ucs2"=>$clang->gT("UCS-2 Unicode") ,"ujis"=>$clang->gT("EUC-JP Japanese") ,"utf8"=>$clang->gT("UTF-8 Unicode")); if (isset($_POST['csvcharset']) && $_POST['csvcharset']) //sanitize charset - if encoding is not found sanitize to 'auto' { $uploadcharset=$_POST['csvcharset']; if (!array_key_exists($uploadcharset,$encodingsarray)) {$uploadcharset='auto';} $filterduplicatetoken=(isset($_POST['filterduplicatetoken']) && $_POST['filterduplicatetoken']=='on'); $filterblankemail=(isset($_POST['filterblankemail']) && $_POST['filterblankemail']=='on'); } } if ($subaction == "importldap" || $subaction == "uploadldap" ) { $filterduplicatetoken=(isset($_POST['filterduplicatetoken']) && $_POST['filterduplicatetoken']=='on'); $filterblankemail=(isset($_POST['filterblankemail']) && $_POST['filterblankemail']=='on'); } $tokenoutput = ""; $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); $sumrows5 = $sumresult5->FetchRow(); if ($subaction == "export" && ( $sumrows5['export'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) )//EXPORT FEATURE SUBMITTED BY PIETERJAN HEYSE { header("Content-Disposition: attachment; filename=tokens_".$surveyid.".csv"); header("Content-type: text/comma-separated-values; charset=UTF-8"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: cache"); $bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid"); $bquery .= " ORDER BY tid"; $bresult = db_execute_assoc($bquery) or die ("$bquery
".htmlspecialchars($connect->ErrorMsg())); $bfieldcount=$bresult->FieldCount(); $tokenoutput .= "firstname, lastname, email, emailstatus, token, language code, attribute1, attribute2, tid\n"; while ($brow = $bresult->FetchRow()) { $tokenoutput .= '"'.trim($brow['firstname'])."\","; $tokenoutput .= '"'.trim($brow['lastname'])."\","; $tokenoutput .= '"'.trim($brow['email'])."\","; $tokenoutput .= '"'.trim($brow['emailstatus'])."\","; $tokenoutput .= '"'.trim($brow['token'])."\","; $tokenoutput .= '"'.trim($brow['language'])."\""; if($bfieldcount > 8) { $tokenoutput .= ","; $tokenoutput .= '"'.trim($brow['attribute_1'])."\","; $tokenoutput .= '"'.trim($brow['attribute_2'])."\","; $tokenoutput .= '"'.trim($brow['tid'])."\""; } $tokenoutput .= "\n"; } echo $tokenoutput; exit; } if ($subaction == "delete" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $_SESSION['metaHeader']=""; } //Show Help $tokenoutput .= "\n"; $tokenoutput .= "\n" ."\t\n" ."\t\t\n" ."\t\n" ."
\n" ."\t\t
\n"; $tokenoutput .= "\n"; // MAKE SURE THAT THERE IS A SID if (!isset($surveyid) || !$surveyid) { $tokenoutput .= "\t\n" ."\t\n" ."\n" ."\n"; return; } // MAKE SURE THAT THE SURVEY EXISTS $chquery = "SELECT * FROM ".db_table_name('surveys')." as a inner join ".db_table_name('surveys_languagesettings')." as b on (b.surveyls_survey_id=a.sid and b.surveyls_language=a.language) WHERE a.sid=$surveyid"; $chresult=db_execute_assoc($chquery); $chcount=$chresult->RecordCount(); if (!$chcount) { $tokenoutput .= "\t
" .$clang->gT("Token Control").":

" .$clang->gT("Error")."
".$clang->gT("The survey you selected does not exist") ."

\n\t

\n" ."\n"; return; } // A survey DOES exist while ($chrow = $chresult->FetchRow()) { $tokenoutput .= "\t" .$clang->gT("Token Control").": " ."{$chrow['surveyls_title']}\n"; $surveyprivate = $chrow['private']; } // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $tkquery = "SELECT * FROM ".db_table_name("tokens_$surveyid"); if (!$tkresult = $connect->Execute($tkquery)) //If the query fails, assume no tokens table exists { if (isset($_POST['createtable']) && $_POST['createtable']=="Y" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $createtokentable= "tid int I NOTNULL AUTO PRIMARY,\n " . "firstname C(40) ,\n " . "lastname C(40) ,\n "; //MSSQL needs special treatment because of some strangeness in ADODB if ($databasetype=='odbc_mssql') { $createtokentable.= "email C(320) ,\n " ."emailstatus C(300) DEFAULT 'OK',\n "; } else { $createtokentable.= "email X(320) ,\n " ."emailstatus X(300) DEFAULT 'OK',\n "; } $createtokentable.= "token C(36) ,\n " . "language C(25) ,\n " . "sent C(17) DEFAULT 'N',\n " . "completed C(17) DEFAULT 'N',\n " . "attribute_1 C(100) ,\n" . "attribute_2 C(100) ,\n" . "mpid I "; $tabname = "{$dbprefix}tokens_{$surveyid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL) $taboptarray = array('mysql' => 'TYPE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci'); $dict = NewDataDictionary($connect); $sqlarray = $dict->CreateTableSQL($tabname, $createtokentable, $taboptarray); $execresult=$dict->ExecuteSQLArray($sqlarray, false); if ($execresult==0 || $execresult==1) { $tokenoutput .= "\t\n" ."\t\t\n" . "
\n\n" . "\n" . "" ."\t\t\t\n" ."\t\t\n" ."\t\n" ."\n" ."
\n" ."\n"; } else { $createtokentableindex = $dict->CreateIndexSQL("{$tabname}_idx", $tabname, array('token')); $dict->ExecuteSQLArray($createtokentableindex, false) or safe_die ("Failed to create token table index
$createtokentableindex

".$connect->ErrorMsg()); $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\t

\n" ."\t\t\t".$clang->gT("A token table has been created for this survey.")." (\"".$dbprefix."tokens_$surveyid\")

\n" ."\t\t\t\n" ."\t\t\n" ."\t\n" ."\n" ."
\n" ."\n"; } return; } elseif (returnglobal('restoretable') == "Y" && returnglobal('oldtable') && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $query = db_rename_table(returnglobal('oldtable') , db_table_name("tokens_$surveyid")); $result=$connect->Execute($query) or safe_die("Failed Rename!
".$query."
".$connect->ErrorMsg()); $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\t

\n" ."\t\t\t".$clang->gT("A token table has been created for this survey.")." (\"".$dbprefix."tokens_$surveyid\")

\n" ."\t\t\t\n" ."\t\t\n" ."\t\n" ."\n" ."
\n" ."\n"; return; } else { $query=db_select_tables_like("{$dbprefix}old_tokens_".$surveyid."_%"); $result=db_execute_num($query) or safe_die("Couldn't get old table list
".$query."
".$connect->ErrorMsg()); $tcount=$result->RecordCount(); if ($tcount > 0) { while($rows=$result->FetchRow()) { $oldlist[]=$rows[0]; } } $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\t
".$clang->gT("Warning")."
\n" ."\t\t\t".$clang->gT("Tokens have not been initialised for this survey.")."

\n"; if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $tokenoutput .= "\t\t\t".$clang->gT("If you initialise tokens for this survey, the survey will only be accessible to users who have been assigned a token.") ."\t\t\t

\n"; $thissurvey=getSurveyInfo($surveyid); if ($thissurvey['private'] == 'Y') { $tokenoutput .= "\t\t\t".$clang->gT("If you turn on the -Anonymous answers- option and create a tokens table, LimeSurvey will mark your completed tokens only with a 'Y' instead of date/time to ensure the anonymity of your participants.") ."\t\t\t

\n"; } $tokenoutput .= "\t\t\t".$clang->gT("Do you want to create a tokens table for this survey?"); $tokenoutput .= "

\n"; $tokenoutput .= "\t\t\t
\n"; .$clang->gT("Initialise Tokens")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&createtable=Y")."\" />
\n"; } $tokenoutput .= "\t\t\t

\n"; // Do not offer old postgres token tables for restore since these are having an issue with missing index if ($tcount>0 && $databasetype!='postgres' && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\n" ."\n" ."\n" ."\n" ."
".$clang->gT("Restore Options").":\n" ."
\n" .$clang->gT("The following old token tables could be restored:")."
\n" ."
\n" ."\n" ."\n" ."\n" ."
\n"; } $tokenoutput .= "\t\t\n" ."\t\n" ."\n" ."
\n" ."\n"; return; } } #Lookup the names of the attributes $query = "SELECT attribute1, attribute2 FROM ".db_table_name('surveys')." WHERE sid=$surveyid"; $result = db_execute_assoc($query) or safe_die("Couldn't execute query:
$query
".$connect->ErrorMsg()); $row = $result->FetchRow(); if ($row["attribute1"]) {$attr1_name = $row["attribute1"];} else {$attr1_name=$clang->gT("Attribute 1");} if ($row["attribute2"]) {$attr2_name = $row["attribute2"];} else {$attr2_name=$clang->gT("Attribute 2");} // IF WE MADE IT THIS FAR, THEN THERE IS A TOKENS TABLE, SO LETS DEVELOP THE MENU ITEMS $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\tgT("Show Help", "js")."');return false\">" . "\n" ."\t\t\tgT("Return to Survey Administration", "js")."');return false\">" . "\n" ."\t\t\t\n" ."\t\t\tgT("Show Token Summary", "js")."');return false\" >" ."\t\t\t\n" ."\n" ."\t\t\t\n" ."\t\t\tgT("Display Tokens", "js")."');return false\">" ."\n"; if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $tokenoutput .= "\t\t\tgT("Add new token entry", "js")."');return false\">" . "\n" ."\t\t\t\n" ."\t\t\tgT("Import Tokens from CSV File", "js")."');return false\"> " ."\t\t\tgT("Import Tokens from LDAP Query", "js")."');return false\"> "; } if ($sumrows5['export'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $tokenoutput .= "\t\t\tgT("Export Tokens to CSV file", "js")."');return false\">". "\n"; } if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $tokenoutput .= "\t\t\t\n" ."\t\t\tgT("Edit Email Templates", "js")."');return false\">" . "\n" ."\t\t\tgT("Send email invitation", "js")."');return false\">" . "\n" ."\t\t\tgT("Send email reminder", "js")."');return false\">" . "\n" ."\t\t\t\n" // ."\t\t\tgT("Generate Tokens", "js")."');return false\">" . ."\t\t\tgT("Generate Tokens", "js")."');return false\">" . "\n" ."\t\t\t\n" // ."\t\t\tgT("Drop tokens table", "js")."');return false\">" . ."\t\t\tgT("Drop tokens table", "js")."');return false\">" . "\n" ."\t\t\n"; } $tokenoutput .= "\t\n"; // SEE HOW MANY RECORDS ARE IN THE TOKEN TABLE $tkcount = $tkresult->RecordCount(); $tokenoutput .= "\t\n" ."\t\t\n"; // GIVE SOME INFORMATION ABOUT THE TOKENS if ($subaction==''){ $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t
\n" ."\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t
\n" ."\t\t\t\t\t".$clang->gT("Total Records in this Token Table").": $tkcount
\n"; $tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE token IS NULL OR token=''"; $tksr = db_execute_num($tksq); while ($tkr = $tksr->FetchRow()) {$tokenoutput .= "\t\t\t\t\t\t".$clang->gT("Total With No Unique Token").": $tkr[0] / $tkcount
\n";} $tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE (sent!='N' and sent<>'')"; $tksr = db_execute_num($tksq); while ($tkr = $tksr->FetchRow()) {$tokenoutput .= "\t\t\t\t\t\t".$clang->gT("Total Invitations Sent").": $tkr[0] / $tkcount
\n";} $tksq = "SELECT count(*) FROM ".db_table_name("tokens_$surveyid")." WHERE (completed!='N' and completed<>'')"; $tksr = db_execute_num($tksq) or safe_die ("Couldn't execute token selection query
$abquery
".$connect->ErrorMsg()); while ($tkr = $tksr->FetchRow()) {$tokenoutput .= "\t\t\t\t\t\t".$clang->gT("Total Surveys Completed").": $tkr[0] / $tkcount\n";} $tokenoutput .= "\t\t\t\t\t
\n" ."\t\t\t
\n" ."\t\t\n" ."\t\n" ."\n" ."
\n"; } $tokenoutput .= "\n"; ############################################################################################# // NOW FOR VARIOUS ACTIONS: if ($subaction == "emailsettings") { $grplangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($grplangs,$baselang); if (getEmailFormat($surveyid) == 'html') { $ishtml=true; } else { $ishtml=false; } $tokenoutput .= PrepareEditorScript(); $tokenoutput .="\n"; } // Save the updated email settings if ($subaction == "updateemailsettings" && ($_SESSION['USER_RIGHT_SUPERADMIN'] == 1 || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $_POST = array_map('db_quote', $_POST); $languagelist = GetAdditionalLanguagesFromSurveyID($surveyid); $languagelist[]=GetBaseLanguageFromSurveyID($surveyid); foreach ($languagelist as $langname) { if ($langname) { $usquery = "UPDATE ".db_table_name('surveys_languagesettings')." \n" . "SET surveyls_email_invite_subj='".$_POST['email_invite_subj_'.$langname]."',\n" . "surveyls_email_invite='".$_POST['email_invite_'.$langname]."', surveyls_email_remind_subj='".$_POST['email_remind_subj_'.$langname]."',\n" . "surveyls_email_remind='".$_POST['email_remind_'.$langname]."', surveyls_email_register_subj='".$_POST['email_register_subj_'.$langname]."',\n" . "surveyls_email_register='".$_POST['email_register_'.$langname]."', surveyls_email_confirm_subj='".$_POST['email_confirm_subj_'.$langname]."',\n" . "surveyls_email_confirm='".$_POST['email_confirm_'.$langname]."'\n" . "WHERE surveyls_survey_id=".$surveyid." and surveyls_language='".$langname."'"; $usresult = $connect->Execute($usquery) or safe_die("Error updating
".$usquery."

".$connect->ErrorMsg()); } } $tokenoutput .= "
".$clang->gT("Token Email Settings have been saved.")."
 \n"; } if ($subaction == "deleteall" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $query="DELETE FROM ".db_table_name("tokens_$surveyid"); $result=$connect->Execute($query) or safe_die ("Couldn't update sent field
$query
".$connect->ErrorMsg()); $tokenoutput .= "".$clang->gT("All token entries have been deleted.")."\n"; $subaction=""; } if ($subaction == "clearinvites" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $query="UPDATE ".db_table_name("tokens_$surveyid")." SET sent='N'"; $result=$connect->Execute($query) or safe_die ("Couldn't update sent field
$query
".$connect->ErrorMsg()); $tokenoutput .= "".$clang->gT("All invite entries have been set to 'Not Invited'.")."\n"; $subaction=""; } if ($subaction == "cleartokens" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $query="UPDATE ".db_table_name("tokens_$surveyid")." SET token=''"; $result=$connect->Execute($query) or safe_die("Couldn't reset the tokens field
$query
".$connect->ErrorMsg()); $tokenoutput .= "".$clang->gT("All unique token numbers have been removed.")."\n"; $subaction=""; } if (!$subaction && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" .$clang->gT("Token Database Administration Options").":\n" ."\t\n" ."\t\t\n" ."\t\t\t
\n" ."\t\t\t
\n" // ."\t\t\t
\n" ."\t\t\n" ."\t\n" ."\n"; } if ($subaction == "settings" && ($sumrows5['export'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1)) //ToDO: Which right? { } if ($subaction == "browse" || $subaction == "search") { if (!isset($limit)) {$limit = 100;} if (!isset($start)) {$start = 0;} if ($limit > $tkcount) {$limit=$tkcount;} $next=$start+$limit; $last=$start-$limit; $end=$tkcount-$limit; if ($end < 0) {$end=0;} if ($last <0) {$last=0;} if ($next >= $tkcount) {$next=$tkcount-$limit;} if ($end < 0) {$end=0;} //ALLOW SELECTION OF NUMBER OF RECORDS SHOWN $tokenoutput .= "\t" .$clang->gT("Data View Control").":\n" ."\t\n" ."\t\t\t\n" ."\t\t\t\n" ."\t\t\tgT("Show start..", "js")."');return false\">". "\n" ."\t\t\tgT("Show previous...", "js")."');return false\">" . "\n" ."\t\t\t\n" ."\t\t\tgT("Show next...", "js")."');return false\">" . "\n" ."\t\t\tgT("Show last...", "js")."');return false\">". "\n" ."\t\t\t\n" ."\t\t\t\n" ."\t\t\t\t
\n" ."\t\t\t\t\t\n" ."\t\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t\n" ."\t\t\t\t
\n" ."\t\t\n" ."\t\t
\n" ."\t\t" ." ".$clang->gT("Records Displayed:")."" ." ".$clang->gT("Starting From:")."" ." \n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t
\n" ."\t\n"; $bquery = "SELECT * FROM ".db_table_name("tokens_$surveyid"); $bresult = db_select_limit_assoc($bquery, 1) or safe_die($clang->gT("Error")." counting fields
".$connect->ErrorMsg()); $bfieldcount=$bresult->FieldCount()-1; $bquery = "SELECT tid,firstname,lastname,email,emailstatus,token,language,sent,completed,attribute_1,attribute_2,mpid FROM ".db_table_name("tokens_$surveyid"); if ($searchstring) { $bquery .= " WHERE firstname LIKE '%$searchstring%' " . "OR lastname LIKE '%$searchstring%' " . "OR email LIKE '%$searchstring%' " . "OR emailstatus LIKE '%$searchstring%' " . "OR token LIKE '%$searchstring%'"; if ($bfieldcount == 11) { $bquery .= " OR attribute_1 like '%$searchstring%' " . "OR attribute_2 like '%$searchstring%'"; } } if (!isset($order) || !$order) {$bquery .= " ORDER BY tid";} else {$bquery .= " ORDER BY $order"; } //safe_die($bquery.":::".$start.":::".$limit); $bresult = db_select_limit_assoc($bquery, $limit, $start) or safe_die ($clang->gT("Error").": $bquery
".$connect->ErrorMsg()); $bgc=""; $tokenoutput .= "\n" ."\n"; //COLUMN HEADINGS $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n"; if ($bfieldcount == 11) { $tokenoutput .= "\t\t\n" ."\t\t\n"; //."\t\t\n"; } $tokenoutput .= "\t\t\n" ."\t\n"; while ($brow = $bresult->FetchRow()) { $brow['token'] = trim($brow['token']); if ($bgc == "evenrow") {$bgc = "oddrow";} else {$bgc = "evenrow";} $tokenoutput .= "\t\n"; foreach ($brow as $a=>$b) { if ($a =='email' && $brow['emailstatus'] != 'OK') { $tokenoutput .= "\t\t\n"; } else { $tokenoutput .= "\t\t\n"; } } if ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $tokenoutput .= "\t\t\n"; } if ($brow['completed'] != "N" && $brow['completed']!="" && $surveyprivate == "N") { // Get response Id $query="SELECT id FROM ".db_table_name("survey_$surveyid")." WHERE token='".$brow['token']."' ORDER BY id desc"; $result=db_execute_num($query) or safe_die ("
Could not find token!
\n" .$connect->ErrorMsg()); list($id) = $result->FetchRow(); // UPDATE button to the tokens display in the MPID Actions column if ($id) { $tokenoutput .= "\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n"; $tokenoutput .= "\t\t\n"; $tokenoutput .= "\t\t\n" ."\t\t\n" ."\t\t\n" // ."\t\t\n" ."\t\t\n" ."\t\t\n" ."\t\t\n"; } } elseif ($brow['completed'] == "N" && $brow['token'] && $brow['sent'] == "N") { $tokenoutput .= "\t\t\n"; } elseif ($brow['completed'] == "N" && $brow['token'] && $brow['sent'] != "N") { $tokenoutput .= "\t\t\n"; } else { $tokenoutput .= "\t\t\n"; } $tokenoutput .= "\t\n"; } $tokenoutput .= "
" ."" .""."ID" ."" ."".$clang->gT("First Name")."" ."" ."".$clang->gT("Last Name")."" ."" ."".$clang->gT("Email")."" ."" ."".$clang->gT("Email Status")."" ."" ."".$clang->gT("Token")."" ."" ."".$clang->gT("Language")."" ."" ."".$clang->gT("Invite sent?")."" ."" ."".$clang->gT("Completed?")."" ."" ."".$attr1_name."" ."" ."".$attr2_name."" //."" //.""
		//.$clang->gT("Sort by: ").$clang->gT("MPID")."".$clang->gT("MPID")."".$clang->gT("Actions")."
$brow[$a]$brow[$a]\n" ."\t\t\t" .""; .$clang->gT("Delete Token Entry")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=delete&tid=".$brow['tid']."&limit=$limit&start=$start&order=$order")."\" />"; if (($brow['completed'] == "N" || $brow['completed'] == "") &&$brow['token']) {$tokenoutput .= "\n";} $tokenoutput .= "\n\t\t
\n" ."\t\t\t\n" ."\t\t
\n" ."\t\t\t\n" ."\t\t\n" ."\t\t\t" ."\t\t\n" ."\t\t\t" ."\t\t\n" ."\t\t
\n" ."\n"; } if ($subaction == "kill" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $date = date('YmdHis'); $tokenoutput .= "\t" ."".$clang->gT("Delete Tokens Table").":" ."\n" ."\t\n" ."
\n"; // ToDo: Just delete it if there is no token in the table if (!isset($_POST['ok']) || !$_POST['ok']) { $tokenoutput .= "".$clang->gT("Warning")."
\n" .$clang->gT("If you delete this table tokens will no longer be required to access this survey.")."
".$clang->gT("A backup of this table will be made if you proceed. Your system administrator will be able to access this table.")."
\n" ."( \"old_tokens_{$surveyid}_$date\" )

\n" ."
\n" .$clang->gT("Delete Tokens")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=kill&ok=surething")."\" />
\n" ."\n"; } elseif (isset($_POST['ok']) && $_POST['ok'] == "surething") { $oldtable = "tokens_$surveyid"; $newtable = "old_tokens_{$surveyid}_$date"; $deactivatequery = db_rename_table( db_table_name_nq($oldtable), db_table_name_nq($newtable)); if ($databasetype=='postgres') { // If you deactivate a postgres table you have to rename the according sequence too and alter the id field to point to the changed sequence $oldTableJur = db_table_name_nq($oldtable); $deactivatequery = db_rename_table(db_table_name_nq($oldtable),db_table_name_nq($newtable).'_tid_seq'); $deactivateresult = $connect->Execute($deactivatequery) or die ("oldtable : ".$oldtable. " / oldtableJur : ". $oldTableJur . " / ".htmlspecialchars($deactivatequery)." / Could not rename the old sequence for this token table. The database reported the following error:
".htmlspecialchars($connect->ErrorMsg())."

".$clang->gT("Main Admin Screen").""); $setsequence="ALTER TABLE ".db_table_name_nq($newtable)."_tid_seq ALTER COLUMN tid SET DEFAULT nextval('".db_table_name_nq($newtable)."_tid_seq'::regclass);"; $deactivateresult = $connect->Execute($setsequence) or die (htmlspecialchars($setsequence)." Could not alter the field tid to point to the new sequence name for this token table. The database reported the following error:
".htmlspecialchars($connect->ErrorMsg())."

Survey was not deactivated either.

".$clang->gT("Main Admin Screen").""); $setidx="ALTER INDEX ".db_table_name_nq($oldtable)."_idx RENAME TO ".db_table_name_nq($newtable)."_idx;"; $deactivateresult = $connect->Execute($setidx) or die (htmlspecialchars($setidx)." Could not alter the index for this token table. The database reported the following error:
".htmlspecialchars($connect->ErrorMsg())."

Survey was not deactivated either.

".$clang->gT("Main Admin Screen").""); } else { $deactivateresult = $connect->Execute($deactivatequery) or die ("Couldn't deactivate because:
\n".htmlspecialchars($connect->ErrorMsg())." - Query: ".htmlspecialchars($deactivatequery)."

\nAdmin\n"); } $tokenoutput .= "\n" .$clang->gT("The tokens table has now been removed and tokens are no longer required to access this survey.")."
".$clang->gT("A backup of this table has been made and can be accessed by your system administrator.")."
\n" ."(\"{$dbprefix}old_tokens_{$surveyid}_$date\")"."

\n" ."\n" ."
\n"; } $tokenoutput .= "\n" ."
\n"; } if ($subaction == "email" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { if (getEmailFormat($surveyid) == 'html') { $ishtml=true; } else { $ishtml=false; } $tokenoutput .= PrepareEditorScript(); $tokenoutput .= "\t\n\t\t" ."" .$clang->gT("Email Invitation").":\n\t\n" ."\t\n\t\t\n"; if (!isset($_POST['ok']) || !$_POST['ok']) { $tokenoutput .= "
"; $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($surveylangs,$baselang); $tokenoutput .= "
"; foreach ($surveylangs as $language) { //GET SURVEY DETAILS $thissurvey=getSurveyInfo($surveyid,$language); if (!$thissurvey['email_invite']) { if ($ishtml===true) { $thissurvey['email_invite']=html_escape(str_replace("\n", "
", $clang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}",'unescaped'))); } else { $thissurvey['email_invite']=str_replace("\n", "\r\n", $clang->gT("Dear {FIRSTNAME},\n\nYou have been invited to participate in a survey.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}")); } } if (!$thissurvey['email_invite_subj']) { $thissurvey['email_invite_subj']=$clang->gT("Invitation to participate in survey"); } $fieldsarray["{ADMINNAME}"]= $thissurvey['adminname']; $fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail']; $fieldsarray["{SURVEYNAME}"]=$thissurvey['name']; $fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description']; $subject=Replacefields($thissurvey['email_invite_subj'], $fieldsarray); $textarea=Replacefields($thissurvey['email_invite'], $fieldsarray); $tokenoutput .= '

'.getLanguageNameFromCode($language,false); if ($language==$baselang) { $tokenoutput .= "(".$clang->gT("Base Language").")"; } $tokenoutput .= "

\n" ."\n"; $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n" ."\t\t\n" ."\t
".$clang->gT("From").":\" />
".$clang->gT("Subject").":
".$clang->gT("Message").":\n" ."\t\t\t\n" . getEditor("email-inv","message_$language","[".$clang->gT("Invitation Email:", "js")."](".$language.")",$surveyid,'','',$action) ."\t\t
\n"; } $tokenoutput .= "
"; if (isset($tokenid)) { $tokenoutput .= ""; } $tokenoutput .="\t\n" ."\t\n"; if (isset($tokenid)) {$tokenoutput .= "\t";} $tokenoutput .= "\n" ."
" .$clang->gT("Sending to Token ID").": ".$tokenid ."
 ".$clang->gT("Bypass token with failing email addresses").": 
\n" . "\t\n" . "\t\n" ."\t\n" ."\t\n" ."\t
\n"; } else { $tokenoutput .= $clang->gT("Sending Invitations"); if (isset($tokenid)) {$tokenoutput .= " (".$clang->gT("Sending to Token ID").": {$tokenid})";} $tokenoutput .= "
\n"; if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y') { $SQLemailstatuscondition = " AND emailstatus = 'OK'"; } else { $SQLemailstatuscondition = ""; } $ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != '' $SQLemailstatuscondition"; if (isset($tokenid)) {$ctquery .= " AND tid='{$tokenid}'";} $tokenoutput .= "\n"; $ctresult = $connect->Execute($ctquery) or safe_die("Database error!
\n" . $connect->ErrorMsg()); $ctcount = $ctresult->RecordCount(); $ctfieldcount = $ctresult->FieldCount(); $emquery = "SELECT firstname, lastname, email, token, tid, language"; if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE ((completed ='N') or (completed='')) AND ((sent ='N') or (sent='')) AND token !='' AND email != '' $SQLemailstatuscondition"; if (isset($tokenid)) {$emquery .= " and tid='{$tokenid}'";} $tokenoutput .= "\n\n\n\n"; $emresult = db_select_limit_assoc($emquery,$maxemails) or safe_die ("Couldn't do query.
\n$emquery
\n".$connect->ErrorMsg()); $emcount = $emresult->RecordCount(); $tokenoutput .= "\n" ."\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n"; } $tokenoutput .= "
\n"; $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselanguage = GetBaseLanguageFromSurveyID($surveyid); array_unshift($surveylangs,$baselanguage); foreach ($surveylangs as $language) { $_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]); $_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]); if ($ishtml) $_POST['message_'.$language] = html_entity_decode_php4($_POST['message_'.$language], ENT_QUOTES, "UTF-8"); } if ($emcount > 0) { while ($emrow = $emresult->FetchRow()) { unset($fieldsarray); $to = $emrow['email']; $fieldsarray["{EMAIL}"]=$emrow['email']; $fieldsarray["{FIRSTNAME}"]=$emrow['firstname']; $fieldsarray["{LASTNAME}"]=$emrow['lastname']; $fieldsarray["{TOKEN}"]=$emrow['token']; $fieldsarray["{LANGUAGE}"]=$emrow['language']; $fieldsarray["{ATTRIBUTE_1}"]=$emrow['attribute_1']; $fieldsarray["{ATTRIBUTE_2}"]=$emrow['attribute_2']; $emrow['language']=trim($emrow['language']); if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default $found = array_search($emrow['language'], $surveylangs); if ($found==false) {$emrow['language']=$baselanguage;} $from = $_POST['from_'.$emrow['language']]; if ($ishtml === false) { $fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}"; } else { $fieldsarray["{SURVEYURL}"]="".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}").""; } $modsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray); $modmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray); if (MailTextMessage($modmessage, $modsubject, $to , $from, $sitename, $ishtml, getBounceEmail($surveyid))) { // Put date into sent $today = date_shift(date("Y-m-d H:i:s"), "Y-m-d H:i", $timeadjust); $udequery = "UPDATE ".db_table_name("tokens_{$surveyid}")."\n" ."SET sent='$today' WHERE tid={$emrow['tid']}"; // $uderesult = $connect->Execute($udequery) or safe_die ("Could not update tokens
$udequery
".$connect->ErrorMsg()); $tokenoutput .= "[".$clang->gT("Invitation sent to:")."{$emrow['firstname']} {$emrow['lastname']} ($to)]
\n"; } else { $tokenoutput .= ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."
", $fieldsarray); if ($debug>0) { $tokenoutput .= "
Subject : $modsubject

".htmlspecialchars($maildebugbody)."
"; } } } if ($ctcount > $emcount) { $lefttosend = $ctcount-$maxemails; $tokenoutput .= "\t\t
".$clang->gT("Warning")."
\n" ."\t\t\t
" .$clang->gT("There are more emails pending than can be sent in one batch. Continue sending emails by clicking below.")."

\n"; $tokenoutput .= str_replace("{EMAILCOUNT}", "$lefttosend", $clang->gT("There are {EMAILCOUNT} emails still to be sent.")); $tokenoutput .= "

\n"; $tokenoutput .= "\t\t\t\n" ."\t\t\t\n" ."\t\t\t\n" ."\t\t\t\n" ."\t\t\t\n"; foreach ($surveylangs as $language) { $message = html_escape($_POST['message_'.$language]); $subject = html_escape($_POST['subject_'.$language]); $tokenoutput .="\t\t\t\n" ."\t\t\t\n" ."\t\t\t\n"; } $tokenoutput .="\t\t\t
\n"; } } else { $tokenoutput .= "
".$clang->gT("Warning")."
\n".$clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of - having an email address, not having been sent an invitation already, having already completed the survey and having a token.")."
\n"; } $tokenoutput .= "\t\t
\n"; } if ($subaction == "remind" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= PrepareEditorScript(); $tokenoutput .= "\t" .$clang->gT("Email Reminder").":\n" ."\t\n"; if (!isset($_POST['ok']) || !$_POST['ok']) { //GET SURVEY DETAILS $tokenoutput .= "
"; $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselang = GetBaseLanguageFromSurveyID($surveyid); array_unshift($surveylangs,$baselang); $tokenoutput .= "
"; foreach ($surveylangs as $language) { //GET SURVEY DETAILS $thissurvey=getSurveyInfo($surveyid,$language); if (!$thissurvey['email_remind']) {$thissurvey['email_remind']=str_replace("\n", "\r\n", $clang->gT("Dear {FIRSTNAME},\n\nRecently we invited you to participate in a survey.\n\nWe note that you have not yet completed the survey, and wish to remind you that the survey is still available should you wish to take part.\n\nThe survey is titled:\n\"{SURVEYNAME}\"\n\n\"{SURVEYDESCRIPTION}\"\n\nTo participate, please click on the link below.\n\nSincerely,\n\n{ADMINNAME} ({ADMINEMAIL})\n\n----------------------------------------------\nClick here to do the survey:\n{SURVEYURL}"));} $tokenoutput .= '

'.getLanguageNameFromCode($language,false); if ($language==$baselang) { $tokenoutput .= "(".$clang->gT("Base Language").")"; } $tokenoutput .= "

\n" ."\n" ."\t\n" ."\t\t\n" ."\t\t\n" ."\t\n" ."\t\n" ."\t\t\n"; $fieldsarray["{ADMINNAME}"]= $thissurvey['adminname']; $fieldsarray["{ADMINEMAIL}"]=$thissurvey['adminemail']; $fieldsarray["{SURVEYNAME}"]=$thissurvey['name']; $fieldsarray["{SURVEYDESCRIPTION}"]=$thissurvey['description']; $subject=Replacefields($thissurvey['email_remind_subj'], $fieldsarray); $textarea=Replacefields($thissurvey['email_remind'], $fieldsarray); $tokenoutput .= "\t\t\n" ."\t\n"; $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\n" ."
".$clang->gT("From").":\" />
".$clang->gT("Subject").":
" .$clang->gT("Message").":\n" ."\t\t\t\n" . getEditor("email-rem","message_$language","[".$clang->gT("Reminder Email:", "js")."](".$language.")",$surveyid,'','',$action) ."\t\t
"; } $tokenoutput .= "
\n"; if (isset($tokenid)) { $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\n"; } else { $tokenoutput .= "\t\n" ."\t\t\n" ."\t\t\n" ."\t\n"; } $tokenoutput .="\t\t\n" ."\t\n"; if (isset($tokenid)) {$tokenoutput .= "\t\n";} $tokenoutput .= "\t
" .$clang->gT("Start at Token ID No:")."
" .$clang->gT("Sending to Token ID").": {$tokenid}
 \n" .$clang->gT("Bypass token with failing email addresses").": \n" ."\t\t\t
\n" ."\t\t\t\n" ."\t\n" ."\t\n" ."\t\n" ."\t\t
\n" ."
\n"; } else { $tokenoutput .= $clang->gT("Sending Reminders")."
\n"; $surveylangs = GetAdditionalLanguagesFromSurveyID($surveyid); $baselanguage = GetBaseLanguageFromSurveyID($surveyid); array_unshift($surveylangs,$baselanguage); foreach ($surveylangs as $language) { $_POST['message_'.$language]=auto_unescape($_POST['message_'.$language]); $_POST['subject_'.$language]=auto_unescape($_POST['subject_'.$language]); } if (isset($starttokenid)) {$tokenoutput .= " (".$clang->gT("From Token ID").": {$starttokenid})";} if (isset($tokenid)) {$tokenoutput .= " (".$clang->gT("Sending to Token ID").": {$tokenid})";} if (isset($_POST['bypassbademails']) && $_POST['bypassbademails'] == 'Y') { $SQLemailstatuscondition = " AND emailstatus = 'OK'"; } else { $SQLemailstatuscondition = ""; } $ctquery = "SELECT * FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed ='N' or completed ='') AND sent<>'' AND sent<>'N' AND token <>'' AND email <> '' $SQLemailstatuscondition"; if (isset($starttokenid)) {$ctquery .= " AND tid > '{$starttokenid}'";} if (isset($tokenid) && $tokenid) {$ctquery .= " AND tid = '{$tokenid}'";} $tokenoutput .= "\n"; $ctresult = $connect->Execute($ctquery) or safe_die ("Database error!
\n" . $connect->ErrorMsg()); $ctcount = $ctresult->RecordCount(); $ctfieldcount = $ctresult->FieldCount(); $emquery = "SELECT firstname, lastname, email, token, tid, language "; if ($ctfieldcount > 7) {$emquery .= ", attribute_1, attribute_2";} // TLR change to put date into sent $emquery .= " FROM ".db_table_name("tokens_{$surveyid}")." WHERE (completed = 'N' or completed = '') AND sent <> 'N' and sent<>'' AND token <>'' AND EMAIL <>'' $SQLemailstatuscondition"; if (isset($starttokenid)) {$emquery .= " AND tid > '{$starttokenid}'";} if (isset($tokenid) && $tokenid) {$emquery .= " AND tid = '{$tokenid}'";} $emquery .= " ORDER BY tid "; $emresult = db_select_limit_assoc($emquery, $maxemails) or safe_die ("Couldn't do query.
$emquery
".$connect->ErrorMsg()); $emcount = $emresult->RecordCount(); $tokenoutput .= "\n" ."\t\n" ."\t\t\n" ."\t\n" ."\t" ."\t\t\n" ."\t\n" ."\t\n" ."\t\n" ."\t\n"; foreach ($surveylangs as $language) { $message = html_escape($_POST['message_'.$language]); $tokenoutput .="\t\t\t\n" ."\t\t\t\n" ."\t\t\t\n"; } $tokenoutput.="\t\n" ."\t\n"; } } else { $tokenoutput .= "
".$clang->gT("Warning")."
\n" .$clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of - having an email address, having been sent an invitation, but not having yet completed the survey.")."\n" ."

\n" ."\t\t\n"; } $tokenoutput .= "\t
\n" ."
\n"; if ($emcount > 0) { while ($emrow = $emresult->FetchRow()) { unset($fieldsarray); $to = $emrow['email']; $fieldsarray["{EMAIL}"]=$emrow['email']; $fieldsarray["{FIRSTNAME}"]=$emrow['firstname']; $fieldsarray["{LASTNAME}"]=$emrow['lastname']; $fieldsarray["{TOKEN}"]=$emrow['token']; $fieldsarray["{LANGUAGE}"]=$emrow['language']; $fieldsarray["{ATTRIBUTE_1}"]=$emrow['attribute_1']; $fieldsarray["{ATTRIBUTE_2}"]=$emrow['attribute_2']; $emrow['language']=trim($emrow['language']); if ($emrow['language']=='') {$emrow['language']=$baselanguage;} //if language is not give use default $found = array_search($emrow['language'], $surveylangs); if ($found==false) {$emrow['language']=$baselanguage;} $from = $_POST['from_'.$emrow['language']]; if (getEmailFormat($surveyid) == 'html') { $ishtml=true; } else { $ishtml=false; } if ($ishtml === false) { $fieldsarray["{SURVEYURL}"]="$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}"; } else { $fieldsarray["{SURVEYURL}"]="".htmlspecialchars("$publicurl/index.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}").""; $_POST['message_'.$emrow['language']] = html_entity_decode_php4($_POST['message_'.$emrow['language']], ENT_QUOTES, "UTF-8"); } $msgsubject=Replacefields($_POST['subject_'.$emrow['language']], $fieldsarray); $sendmessage=Replacefields($_POST['message_'.$emrow['language']], $fieldsarray); if (MailTextMessage($sendmessage, $msgsubject, $to, $from, $sitename,$ishtml,getBounceEmail($surveyid))) { $tokenoutput .= "\t\t\t({$emrow['tid']})[".$clang->gT("Reminder sent to:")." {$emrow['firstname']} {$emrow['lastname']}]
\n"; } else { $tokenoutput .= $emrow['tid'] ." ".ReplaceFields($clang->gT("Email to {FIRSTNAME} {LASTNAME} ({EMAIL}) failed. Error Message:")." ".$maildebug."
", $fieldsarray); if ($debug>0) { $tokenoutput .= "
Subject : $msgsubject

".htmlspecialchars($maildebugbody)."
"; } } $lasttid = $emrow['tid']; } if ($ctcount > $emcount) { $lefttosend = $ctcount-$maxemails; $tokenoutput .= "\t\t
\n" ."\t\t\t".$clang->gT("Warning")."

\n" .$clang->gT("There are more emails pending than can be sent in one batch. Continue sending emails by clicking below.")."

\n" .str_replace("{EMAILCOUNT}", $lefttosend, $clang->gT("There are {EMAILCOUNT} emails still to be sent.")) ."
\n" ."\t\t\t\n" ."\t\t
\n"; } $tokenoutput .= "\n"; } if ($subaction == "tokenify" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t".$clang->gT("Create Tokens").":\n"; $tokenoutput .= "\t
\n"; if (!isset($_POST['ok']) || !$_POST['ok']) { $tokenoutput .= "
".$clang->gT("Clicking yes will generate tokens for all those in this token list that have not been issued one. Is this OK?")."

\n" ."\n" .$clang->gT("Yes")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=tokenify&ok=Y")."\" />\n" ."\n" ."

\n"; } else { $newtokencount = 0; $tkquery = "SELECT * FROM ".db_table_name("tokens_$surveyid")." WHERE token IS NULL OR token=''"; $tkresult = db_execute_assoc($tkquery) or safe_die ("Mucked up!
$tkquery
".$connect->ErrorMsg()); while ($tkrow = $tkresult->FetchRow()) { $insert = "NO"; while ($insert != "OK") { $newtoken = randomkey(15); $ntquery = "SELECT * FROM ".db_table_name("tokens_$surveyid")." WHERE token='$newtoken'"; $ntresult = $connect->Execute($ntquery); if (!$ntresult->RecordCount()) {$insert = "OK";} } $itquery = "UPDATE ".db_table_name("tokens_$surveyid")." SET token='$newtoken' WHERE tid={$tkrow['tid']}"; $itresult = $connect->Execute($itquery); $newtokencount++; } $message=str_replace("{TOKENCOUNT}", $newtokencount, $clang->gT("{TOKENCOUNT} tokens have been created")); $tokenoutput .= "
$message

\n"; } $tokenoutput .= "\t\n"; } if ($subaction == "delete" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $dlquery = "DELETE FROM ".db_table_name("tokens_$surveyid")." WHERE tid={$tokenid}"; $dlresult = $connect->Execute($dlquery) or safe_die ("Couldn't delete record {$tokenid}
".$connect->ErrorMsg()); $tokenoutput .= "\t" .$clang->gT("Delete")."\n" ."\t
\n" ."
".$clang->gT("Token has been deleted.")."
\n" ."".$clang->gT("Reloading Screen. Please wait.")."

\n" ."\t\n"; } if (($subaction == "edit" || $subaction == "addnew") && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { if ($subaction == "edit") { $edquery = "SELECT * FROM ".db_table_name("tokens_$surveyid")." WHERE tid={$tokenid}"; $edresult = db_execute_assoc($edquery); $edfieldcount = $edresult->FieldCount(); while($edrow = $edresult->FetchRow()) { //Create variables with the same names as the database column names and fill in the value foreach ($edrow as $Key=>$Value) {$$Key = $Value;} } } if ($subaction != "edit") { $edquery = "SELECT * FROM ".db_table_name("tokens_$surveyid"); $edresult = db_select_limit_assoc($edquery, 1); $edfieldcount = $edresult->FieldCount(); } $tokenoutput .= "\t\n" ."
\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" // TLR change to put date into sent and completed // ."\t\n" ."\n" ."\n" ."\t\n" // TLR change to put date into sent and completed // ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\t\n" ."\n\n" ."
\n" .$clang->gT("Add or Edit Token Entry")."
ID:"; if ($subaction == "edit") {$tokenoutput .=$tokenid;} else {$tokenoutput .=$clang->gT("Auto");} $tokenoutput .= "
".$clang->gT("First Name").":
".$clang->gT("Last Name").":
".$clang->gT("Email").":
".$clang->gT("Email Status").":
".$clang->gT("Token").":\n"; if ($subaction == "addnew") { $tokenoutput .= "\t\t".$clang->gT("You can leave this blank, and automatically generate tokens using 'Create Tokens'")."\n"; } $tokenoutput .= "\t
".$clang->gT("Language").":"; if (isset($language)) {$tokenoutput .= languageDropdownClean($surveyid,$language);} else { $tokenoutput .= languageDropdownClean($surveyid,GetBaseLanguageFromSurveyID($surveyid)); } $tokenoutput .= "
".$clang->gT("Invite sent?").":
".$clang->gT("Completed?").": 7) { $tokenoutput .= "\" />
".$attr1_name.":
".$attr2_name.":
"; switch($subaction) { case "edit": $tokenoutput .= "\t\t\n" ."\t\t\n" ."\t\t\n"; break; case "addnew": $tokenoutput .= "\t\t\n" ."\t\t\n"; break; } $tokenoutput .= "\t\t\n" ."\t
\n"; } if ($subaction == "updatetoken" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" .$clang->gT("Add or Edit Token Entry")."\n" ."\t\n"; $data = array(); $data[] = $_POST['firstname']; $data[] = $_POST['lastname']; $data[] = sanitize_email($_POST['email']); $data[] = $_POST['emailstatus']; $santitizedtoken=sanitize_xss_string(strip_tags($_POST['token'])); $data[] = $santitizedtoken; $data[] = sanitize_languagecode($_POST['language']); $data[] = $_POST['sent']; $data[] = $_POST['completed']; $udresult = $connect->Execute("Select * from ".db_table_name("tokens_$surveyid")." where tid<>{$tokenid} and token<>'' and token='{$santitizedtoken}'") or safe_die ("Update record {$tokenid} failed:
\n$udquery
\n".$connect->ErrorMsg()); if ($udresult->RecordCount()==0) { // Using adodb Execute with blinding method so auto-dbquote is done $udquery = "UPDATE ".db_table_name("tokens_$surveyid")." SET firstname=?, " . "lastname=?, email=?, emailstatus=?, " . "token=?, language=?, sent=?, completed=?"; if (isset($_POST['attribute1'])) { $data[] = $_POST['attribute1']; $data[] = $_POST['attribute2']; $udquery .= ", attribute_1=?, attribute_2=?"; } $udquery .= " WHERE tid={$tokenid}"; $udresult = $connect->Execute($udquery, $data) or safe_die ("Update record {$tokenid} failed:
\n$udquery
\n".$connect->ErrorMsg()); $tokenoutput .= "
".$clang->gT("Success")."
\n" ."
".$clang->gT("Updated Token")."

\n" ."".$clang->gT("Display Tokens")."

\n" ."\t\n"; } else { $tokenoutput .= "
".$clang->gT("Failed")."
\n" ."
".$clang->gT("There is already an entry with that exact token in the table. The same token cannot be used in multiple entries.")."

\n" ."".$clang->gT("Show this token entry")."

\n" ."\t\n"; } } if ($subaction == "inserttoken" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $santitizedtoken=trim(sanitize_xss_string(strip_tags($_POST['token']))); $tokenoutput .= "\t" .$clang->gT("Add or Edit Token Entry")."\n" ."\t\n"; $data = array('firstname' => $_POST['firstname'], 'lastname' => $_POST['lastname'], 'email' => sanitize_email($_POST['email']), 'emailstatus' => $_POST['emailstatus'], 'token' => $santitizedtoken, 'language' => sanitize_languagecode($_POST['language']), 'sent' => $_POST['sent'], 'completed' => $_POST['completed']); if (isset($_POST['attribute1'])) { $data['attribute_1'] = $_POST['attribute1']; $data['attribute_2'] = $_POST['attribute2']; } $tblInsert=db_table_name('tokens_'.$surveyid); $udresult = $connect->Execute("Select * from ".db_table_name("tokens_$surveyid")." where token<>'' and token='{$santitizedtoken}'"); if ($udresult->RecordCount()==0) { // AutoExecute $inresult = $connect->AutoExecute($tblInsert, $data, 'INSERT') or safe_die ("Add new record failed:
\n$inquery
\n".$connect->ErrorMsg()); $tokenoutput .= "
".$clang->gT("Success")."
\n" ."
".$clang->gT("Added New Token")."

\n" ."".$clang->gT("Display Tokens")."
\n" ."".$clang->gT("Add new token entry")."

\n" ."\t\n"; } else { $tokenoutput .= "
".$clang->gT("Failed")."
\n" ."
".$clang->gT("There is already an entry with that exact token in the table. The same token cannot be used in multiple entries.")."

\n" ."".$clang->gT("Display Tokens")."
\n" ."".$clang->gT("Add new token entry")."

\n" ."\t\n"; } } if ($subaction == "import" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" ."".$clang->gT("Upload CSV File")."\n" ."\t
\n"; form_csv_upload(); $tokenoutput .= "
\n" ."\t\n" ."\t\t\n" ."\t\n" ."
\n" ."\t\t\t".$clang->gT("Note:")."
\n" ."\t\t\t".$clang->gT("File should be a standard CSV (comma delimited) file with double quotes around values (default for openoffice and excel). The first line should contain header information (will be removed). Data should be ordered as \"firstname, lastname, email, [emailstatus], [token], [language code], [attribute1], [attribute2]\".")."\n" ."\t\t

\n" ."\n"; } if ($subaction == "importldap" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" ."" .$clang->gT("Upload LDAP entries")."\n" ."\t\n"; formldap(); $tokenoutput .= "\n" ."\t\n" ."\t\t\n" ."\t\n" ."
\n" ."\t\t\t".$clang->gT("Note:")."
\n" ."\t\t\t".$clang->gT("LDAP queries are defined by the administrator in the config-ldap.php file")."\n" ."\t\t

\n" ."\n"; } if ($subaction == "upload" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" .$clang->gT("Upload CSV File")."\n" ."\t\n"; if (!isset($tempdir)) { $the_path = $homedir; } else { $the_path = $tempdir; } $the_file_name = $_FILES['the_file']['name']; $the_file = $_FILES['the_file']['tmp_name']; $the_full_file_path = $the_path."/".$the_file_name; if (!@move_uploaded_file($the_file, $the_full_file_path)) { $errormessage="".$clang->gT("Error").": ".$clang->gT("Upload file not found. Check your permissions and path for the upload directory")."\n"; form_csv_upload($errormessage); } else { $tokenoutput .= "
".$clang->gT("Importing CSV File")."
\n".$clang->gT("Success")."

\n" .$clang->gT("Creating Token Entries")."
\n"; $xz = 0; $xx = 0; $xy = 0; $xv = 0; $invalidemailcount = 0; // This allows to read file with MAC line endings too @ini_set('auto_detect_line_endings', true); // open it and trim the ednings $tokenlistarray = array_map('rtrim',file($the_full_file_path)); if (!isset($tokenlistarray)) {$tokenoutput .= "Failed to open the uploaded file!\n";} foreach ($tokenlistarray as $buffer) { $buffer=@mb_convert_encoding($buffer,"UTF-8",$uploadcharset); $firstname = ""; $lastname = ""; $email = ""; $emailstatus="OK"; $token = ""; $language=""; $attribute1=""; $attribute2=""; //Clear out values from the last path, in case the next line is missing a value if ($xx==0) { //THIS IS THE FIRST LINE. IT IS THE HEADINGS. IGNORE IT } else { $line = convertCSVRowToArray($buffer,',','"'); // sanitize it before writing into table $line = array_map('db_quote',$line); if (isset($line[0]) && $line[0] != "" & isset($line[1]) && $line[1] != "" && isset($line[2])) { // If old export file with first col as TID // with no attribute if (is_numeric($line[0])) { $line[8] = $line[0]; $line[0] = $line[1]; $line[1] = $line[2]; $line[2] = $line[3]; $line[3] = "OK"; $line[4] = $line[4]; $line[5] = $line[5]; $line[6] = $line[6]; } $dupfound=false; $invalidemail=false; if ($filterduplicatetoken) { $dupquery = "SELECT firstname, lastname from ".db_table_name("tokens_$surveyid")." where email=".$connect->qstr($line[2])." and firstname = ".$connect->qstr($line[0])." and lastname= ".$connect->qstr($line[1]).""; $dupresult = $connect->Execute($dupquery); if ( $dupresult->RecordCount() > 0) { $dupfound = true; } } $line[2] = trim($line[2]); //treat blank emails if ($filterblankemail && $line[2]=='') { $invalidemail=true; } if ($line[2]!='' && !validate_email($line[2])) { $invalidemail=true;; } if ($invalidemail) { ++$invalidemailcount; } elseif ($dupfound) { ++$xy; } else { if (!isset($line[3]) || $line[3]=='') $line[3] = "OK"; if (!isset($line[4]) || $line[4] == "") $line[4] = ""; if (!isset($line[5]) || $line[5] == "") $line[5] = GetBaseLanguageFromSurveyID($surveyid); if (!isset($line[6])) $line[6] = ""; if (!isset($line[7])) $line[7] = ""; $iq = "INSERT INTO ".db_table_name("tokens_$surveyid")." \n" . "(firstname, lastname, email, emailstatus, token, language, attribute_1, attribute_2, sent, completed) \n" . "VALUES ("; $iq .= $connect->qstr($line[0]).", ".$connect->qstr($line[1]).", ".$connect->qstr($line[2]).", ".$connect->qstr($line[3]).", ".strtolower($connect->qstr($line[4]))." , ".$connect->qstr($line[5]).", ".$connect->qstr($line[6]).", ".$connect->qstr($line[7]).", ".$connect->qstr('N').", ".$connect->qstr('N'); $iq .= ")"; $ir = $connect->Execute($iq); if (!$ir) $xy++; $xz++; } $xv++; } } $xx++; } $xx = $xx-1; if ($xz != 0) { $tokenoutput .= "".$clang->gT("Success")."

\n"; } else { $tokenoutput .= "".$clang->gT("Failed")."

\n"; } $message = "$xx ".$clang->gT("Records in CSV").".
\n"; $message .= "$xv ".$clang->gT("Records met minumum requirements").".
\n"; $message .= "$xz ".$clang->gT("Records imported").".
\n"; $message .= "$xy ".$clang->gT("Duplicate records removed").".
\n"; $message .= "$invalidemailcount ".$clang->gT("Records with invalid email address removed").".
\n"; $tokenoutput .= "$message
\n"; unlink($the_full_file_path); } $tokenoutput .= "\t\t\t\n"; } if ($subaction == "uploadldap" && ($sumrows5['edit_survey_property'] || $sumrows5['activate_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) ) { $tokenoutput .= "\t" .$clang->gT("Uploading LDAP Query")."\n" ."\t\n"; $ldapq=$_POST['ldapQueries']; // the ldap query id $ldap_server_id=$ldap_queries[$ldapq]['ldapServerId']; $ldapserver=$ldap_server[$ldap_server_id]['server']; $ldapport=$ldap_server[$ldap_server_id]['port']; // define $attrlist: list of attributes to read from users' entries $attrparams = array('firstname_attr','lastname_attr', 'email_attr','token_attr', 'language', 'attr1', 'attr2'); foreach ($attrparams as $id => $attr) { if (array_key_exists($attr,$ldap_queries[$ldapq]) && $ldap_queries[$ldapq][$attr] != '') { $attrlist[]=$ldap_queries[$ldapq][$attr]; } } // Open connection to server $ds = ldap_getCnx($ldap_server_id); if ($ds) { // bind to server $resbind=ldap_bindCnx($ds, $ldap_server_id); if ($resbind) { $ResArray=array(); $resultnum=ldap_doTokenSearch($ds, $ldapq, $ResArray); $xz = 0; // imported token count $xv = 0; // meet minim requirement count $xy = 0; // duplicate tokens skipped count $invalidemailcount = 0; if ($resultnum >= 1) { foreach ($ResArray as $responseGroupId => $responseGroup) { for($j = 0;$j < $responseGroup['count']; $j++) { // first let's initialize everything to '' $myfirstname=''; $mylastname=''; $myemail=''; $mylanguage=''; $mytoken=''; $myattr1=''; $myattr2=''; // The first 3 attrs MUST exist in the ldap answer // ==> send PHP notice msg to apache logs otherwise $meetminirequirements=true; if (isset($responseGroup[$j][$ldap_queries[$ldapq]['firstname_attr']]) && isset($responseGroup[$j][$ldap_queries[$ldapq]['lastname_attr']]) ) { // minimum requirement for ldap // * at least a firstanme // * at least a lastname // * if filterblankemail is set (default): at least an email address $myfirstname = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['firstname_attr']]); $mylastname = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['lastname_attr']]); if (isset($responseGroup[$j][$ldap_queries[$ldapq]['email_attr']])) { $myemail = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['email_attr']]); $myemail= sanitize_email($myemail); ++$xv; } elseif ($filterblankemail !==true) { $myemail = ''; ++$xv; } else { $meetminirequirements=false; } } else { $meetminirequirements=false; } // The following attrs are optionnal if ( isset($responseGroup[$j][$ldap_queries[$ldapq]['token_attr']]) ) $mytoken = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['token_attr']]); if ( isset($responseGroup[$j][$ldap_queries[$ldapq]['attr1']]) ) $myattr1 = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['attr1']]); if ( isset($responseGroup[$j][$ldap_queries[$ldapq]['attr2']]) ) $myattr2 = ldap_readattr($responseGroup[$j][$ldap_queries[$ldapq]['attr2']]); if ( isset($responseGroup[$j][$ldap_queries[$ldapq]['language']]) ) $mylanguage = ldap_readattr($response[$ldap_queries[$ldapq]['language']]); // Now check for duplicates or bad formatted email addresses $dupfound=false; $invalidemail=false; if ($filterduplicatetoken) { $dupquery = "SELECT firstname, lastname from ".db_table_name("tokens_$surveyid")." where email='$myemail' and firstname='$myfirstname' and lastname='$mylastname'"; $dupresult = $connect->Execute($dupquery); if ( $dupresult->RecordCount() > 0) { $dupfound = true; } } if ($filterblankemail && $myemail=='') { $invalidemail=true; } if ($myemail!='' && !validate_email($myemail)) { $invalidemail=true;; } if ($invalidemail) { ++$invalidemailcount; } elseif ($dupfound) { ++$xy; } elseif ($meetminirequirements===true) { // No issue, let's import $iq = "INSERT INTO ".db_table_name("tokens_$surveyid")." \n" . "(firstname, lastname, email, emailstatus, token, language"; if (!empty($myattr1)) {$iq .= ", attribute_1";} if (!empty($myattr2)) {$iq .= ", attribute_2";} $iq .=") \n" . "VALUES ('$myfirstname', '$mylastname', '$myemail', 'OK', '$mytoken', '$mylanguage'"; if (!empty($myattr1)) {$iq .= ", '$myattr1'";} if (!empty($myattr2)) {$iq .= ", '$myattr2'";} $iq .= ")"; $ir = $connect->Execute($iq); if (!$ir) $xy++; $xz++; // or safe_die ("Couldn't insert line
\n$buffer
\n".htmlspecialchars($connect->ErrorMsg())."
$iq
\n"); } } // End for each entry } // End foreach responseGroup } // End of if resnum >= 1 if ($xz != 0) { $tokenoutput .= "".$clang->gT("Success")."

\n"; } else { $tokenoutput .= "".$clang->gT("Failed")."

\n"; } $message = "$resultnum ".$clang->gT("Results from LDAP Query").".
\n"; $message .= "$xv ".$clang->gT("Records met minumum requirements").".
\n"; $message .= "$xz ".$clang->gT("Records imported").".
\n"; $message .= "$xy ".$clang->gT("Duplicate records removed").".
\n"; $message .= "$invalidemailcount ".$clang->gT("Records with invalid email address removed").".
\n"; $tokenoutput .= "$message
\n"; } else { $errormessage="".$clang->gT("Error").": ".$clang->gT("Can't bind to the LDAP directory")."\n"; formldap($errormessage); } @ldap_close($ds); } else { $errormessage="".$clang->gT("Error").": ".$clang->gT("Can't connect to the LDAP directory")."\n"; formldap($errormessage); } } $tokenoutput .= "\t\t\n" ."\n"; function form_csv_upload($error=false) { global $surveyid, $tokenoutput,$scriptname, $clang, $encodingsarray; if ($error) {$tokenoutput .= $error . "

\n";} asort($encodingsarray); $charsetsout=''; foreach ($encodingsarray as $charset=>$title) { $charsetsout.="