function showSavedList($surveyid) { global $dbprefix, $connect, $clang, $savedsurveyoutput, $scriptname, $imagefiles, $surrows; $query = "SELECT scid, srid, identifier, ip, saved_date, email, access_code\n" . "FROM {$dbprefix}saved_control\n" . "WHERE sid={$surveyid}\n" . "ORDER BY saved_date desc"; $result = db_execute_assoc($query) or safe_die("Couldn't summarise saved entries<br />{$query}<br />" . $connect->ErrorMsg()); if ($result->RecordCount() > 0) { $savedsurveyoutput .= "<table class='browsetable' align='center'>\n"; $savedsurveyoutput .= "<thead><tr><th>SCID</th><th>" . $clang->gT("Actions") . "</th><th>" . $clang->gT("Identifier") . "</th><th>" . $clang->gT("IP Address") . "</th><th>" . $clang->gT("Date Saved") . "</th><th>" . $clang->gT("Email Address") . "</th>" . "</tr></thead><tbody>\n"; while ($row = $result->FetchRow()) { $savedsurveyoutput .= "<tr>\n\t\t\t\t<td>" . $row['scid'] . "</td>\n\t\t\t\t<td align='center'>"; if ($surrows['delete_survey'] || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $savedsurveyoutput .= "<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='{$imagefiles}/token_edit.png' title='" . $clang->gT("Edit entry") . "' onclick=\"window.open('{$scriptname}?action=dataentry&sid={$surveyid}&subaction=edit&id={$row['srid']}', '_top')\" />" . "<input style='height: 16; width: 16px; font-size: 8; font-family: verdana' type='image' src='{$imagefiles}/token_delete.png' title='" . $clang->gT("Delete entry") . "' onclick=\"if (confirm('" . $clang->gT("Are you sure you want to delete this entry?", "js") . "')) {" . get2post("{$scriptname}?action=saved&sid={$surveyid}&subaction=delete&scid={$row['scid']}&srid={$row['srid']}") . "}\" />"; /* $savedsurveyoutput .= "[<a href='$scriptname?action=saved&sid=$surveyid&subaction=delete&scid={$row['scid']}&srid={$row['srid']}'" ." onclick='return confirm(\"".$clang->gT("Are you sure you want to delete this entry?","js")."\")'" .">".$clang->gT("Delete")."</a>]"; $savedsurveyoutput .= "[<a href='".$scriptname."?action=dataentry&subaction=edit&id=".$row['srid']."&sid={$surveyid}&surveytable={$surveytable}'>".$clang->gT("Edit")."</a>]"; */ } else { $savedsurveyoutput .= "[<a href='" . $scriptname . "?action=dataentry&subaction=edit&id=" . $row['srid'] . "&sid={$surveyid}'>" . $clang->gT("View") . "</a>]"; } $savedsurveyoutput .= "</td>\n <td>" . $row['identifier'] . "</td>\n <td>" . $row['ip'] . "</td>\n <td>" . $row['saved_date'] . "</td>\n <td><a href='mailto:" . $row['email'] . "'>" . $row['email'] . "</td>\n \n\t\t\t </tr>\n"; } // while $savedsurveyoutput .= "</tbody></table><br /> \n"; } }
//NOW GET THE ANSWERS AND DISPLAY THEM $query = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid=$lid"; $result = db_execute_assoc($query); while ($row=$result->FetchRow()) { $labelsoutput.= "<div class='menubar'>\n" ."<div class='menubar-title ui-widget-header'>\n" ."\t<strong>".$clang->gT("Label Set").":</strong> {$row['label_name']}\n" ."</div>\n" ."<div class='menubar-main'>\n" ."\t<div class='menubar-left'>\n" ."\t<img src='$imageurl/blank.gif' width='40' height='20' border='0' hspace='0' align='left' alt='' />\n" ."\t<img src='$imageurl/seperator.gif' border='0' hspace='0' align='left' alt='' />\n" ."\t<a href='admin.php?action=editlabelset&lid=$lid' title=\"".$clang->gTview("Edit label set")."\" >" . "<img name='EditLabelsetButton' src='$imageurl/edit.png' alt='".$clang->gT("Edit label set")."' align='left' /></a>" ."\t<a href='#' title='".$clang->gTview("Delete label set")."' onclick=\"if (confirm('".$clang->gT("Do you really want to delete this label set?","js")."')) {".get2post("admin.php?action=deletelabelset&lid=$lid")."}\" >" ."<img src='$imageurl/delete.png' border='0' alt='".$clang->gT("Delete label set")."' align='left' /></a>\n" ."\t<img src='$imageurl/seperator.gif' border='0' hspace='0' align='left' alt='' />\n" ."\t<a href='admin.php?action=dumplabel&lid=$lid' title=\"".$clang->gTview("Export this label set")."\" >" . "<img src='$imageurl/dumplabel.png' alt='".$clang->gT("Export this label set")."' align='left' /></a>" ."\t</div>\n" ."\t<div class='menubar-right'>\n" ."\t<input type='image' src='$imageurl/close.gif' title='".$clang->gT("Close")."'" ."onclick=\"window.open('admin.php?action=labels', '_top')\" />\n" ."\t</div>\n" ."\t</div>\n" ."\t</div>\n"; $labelsoutput .= "<p style='margin:0;font-size:1px;line-height:1px;height:1px;'> </p>"; //CSS Firefox 2 transition fix }
$tokenoutput .= "<input type='hidden' name='from_{$language}' value=\"" . $_POST['from_' . $language] . "\" />\n" . "<input type='hidden' name='subject_{$language}' value=\"" . $_POST['subject_' . $language] . "\" />\n" . "<input type='hidden' name='message_{$language}' value=\"{$message}\" />\n"; } $tokenoutput .= "\t<input type='hidden' name='last_tid' value=\"{$lasttid}\" />\n" . "\t</form>\n"; } $tokenoutput .= "\t</tr>\n" . "</table>\n"; } else { $tokenoutput .= "<div class='warningheader'>" . $clang->gT("Warning") . "</div>\n" . $clang->gT("There were no eligible emails to send. This will be because none satisfied the criteria of:") . "\n" . "<br/> <ul><li>" . $clang->gT("having a valid email address") . "</li>" . "<li>" . $clang->gT("not having been sent an invitation already") . "</li>" . "<li>" . $clang->gT("but not having already completed the survey") . "</li>" . "</ul><br />\n"; } $tokenoutput .= "</div>\n"; } } if ($subaction == "tokenify" && bHasSurveyPermission($surveyid, 'tokens', 'update')) { $tokenoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Create tokens") . "</div>\n"; $tokenoutput .= "<div class='messagebox ui-corner-all'>\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?") . "<br /><br />\n" . "<input type='submit' value='" . $clang->gT("Yes") . "' onclick=\"" . get2post("{$scriptname}?action=tokens&sid={$surveyid}&subaction=tokenify&ok=Y") . "\" />\n" . "<input type='submit' value='" . $clang->gT("No") . "' onclick=\"window.open('{$scriptname}?action=tokens&sid={$surveyid}', '_top')\" />\n" . "<br />\n"; } else { //get token length from survey settings $tlquery = "SELECT tokenlength FROM " . db_table_name("surveys") . " WHERE sid={$surveyid}"; $tlresult = db_execute_assoc($tlquery); while ($tlrow = $tlresult->FetchRow()) { $tokenlength = $tlrow['tokenlength']; } //if tokenlength is not set or there are other problems use the default value (15) if (!isset($tokenlength) || $tokenlength == '') { $tokenlength = 15; } // select all existing tokens $ntquery = "SELECT token FROM " . db_table_name("tokens_{$surveyid}") . " group by token"; $ntresult = db_execute_assoc($ntquery); while ($tkrow = $ntresult->FetchRow()) {
if ($dtrow[$fnames[$i][0]] == NULL) { $browsedatafield = "N"; } else { $browsedatafield = "Y"; } } if (isset($fnames[$i]['type']) && $fnames[$i]['type'] == "|") { $index = $fnames[$i]['index']; $metadata = $fnames[$i]['metadata']; $phparray = json_decode($dtrow[$fnames[$i][0]], true); if (isset($phparray[$index])) { if ($metadata === "size") { $browseoutput .= "<td align='center'>" . rawurldecode((int) $phparray[$index][$metadata] . " KB") . "</td>\n"; } else { if ($metadata === "name") { $browseoutput .= "<td align='center'><a href='#' onclick=\" " . get2post($scriptname . '?action=browse&subaction=all&downloadindividualfile=' . $phparray[$index][$metadata] . '&fieldname=' . $fnames[$i][0] . '&id=' . $dtrow['id'] . '&sid=' . $surveyid) . "\" >" . rawurldecode($phparray[$index][$metadata]) . "</a></td>\n"; } else { $browseoutput .= "<td align='center'>" . rawurldecode($phparray[$index][$metadata]) . "</td>\n"; } } } else { $browseoutput .= "<td align='center'> </td>\n"; } } else { $browseoutput .= "<td align='center'>{$browsedatafield}</td>\n"; } } $browseoutput .= "\t</tr>\n"; } $browseoutput .= "</table>\n <input type='hidden' name='sid' value='{$surveyid}' />\n <input type='hidden' name='subaction' value='all' />\n <input id='deleteanswer' name='deleteanswer' value='' type='hidden' />\n <input id='downloadfile' name='downloadfile' value='' type='hidden' />\n </form>\n<br />\n"; } elseif ($surveyinfo['savetimings'] == "Y" && $subaction == "time") {
foreach ($tmp_survlangs as $tmp_lang) { $surveysummary .= "<li><a target='_blank' onclick=\"\$('#previewquestion').qtip('hide');\" href='{$scriptname}?action=previewquestion&sid={$surveyid}&qid={$qid}&lang={$tmp_lang}' accesskey='d'>" . getLanguageNameFromCode($tmp_lang, false) . "</a></li>"; } $surveysummary .= "</ul></div>"; } } // SEPARATOR // $questionsummary .= "<img src='$imageurl/blank.gif' alt='' width='117' height='20' />\n"; // EDIT CURRENT QUESTION BUTTON if (bHasSurveyPermission($surveyid, 'surveycontent', 'update')) { $questionsummary .= "" . "<a href='{$scriptname}?action=editquestion&sid={$surveyid}&gid={$gid}&qid={$qid}'" . " title=\"" . $clang->gTview("Edit current question") . "\">" . "<img src='{$imageurl}/edit.png' alt='" . $clang->gT("Edit Current Question") . "' name='EditQuestion' /></a>\n"; } // DELETE CURRENT QUESTION BUTTON if (($qct == 0 && $activated != "Y" || $activated != "Y") && bHasSurveyPermission($surveyid, 'surveycontent', 'delete')) { if (is_null($condarray)) { $questionsummary .= "<a href='#'" . "onclick=\"if (confirm('" . $clang->gT("Deleting this question will also delete any answer options and subquestions it includes. Are you sure you want to continue?", "js") . "')) {" . get2post("{$scriptname}?action=delquestion&sid={$surveyid}&gid={$gid}&qid={$qid}") . "}\">" . "<img src='{$imageurl}/delete.png' name='DeleteWholeQuestion' alt='" . $clang->gT("Delete current question") . "' " . "border='0' hspace='0' /></a>\n"; } else { $questionsummary .= "<a href='{$scriptname}?sid={$surveyid}&gid={$gid}&qid={$qid}'" . "onclick=\"alert('" . $clang->gT("It's impossible to delete this question because there is at least one question having a condition on it.", "js") . "')\"" . "title=\"" . $clang->gTview("Disabled - Delete current question") . "\">" . "<img src='{$imageurl}/delete_disabled.png' name='DeleteWholeQuestion' alt='" . $clang->gT("Disabled - Delete current question") . "' /></a>\n"; } } else { $questionsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='40' />\n"; } // EXPORT CURRENT QUESTION BUTTON if (bHasSurveyPermission($surveyid, 'surveycontent', 'export')) { $questionsummary .= "<a href='{$scriptname}?action=exportstructureQuestion&sid={$surveyid}&gid={$gid}&qid={$qid}'" . " title=\"" . $clang->gTview("Export this question") . "\" >" . "<img src='{$imageurl}/dumpquestion.png' alt='" . $clang->gT("Export this question") . "' name='ExportQuestion' /></a>\n"; } $questionsummary .= "<img src='{$imageurl}/seperator.gif' alt='' />\n"; // COPY CURRENT QUESTION BUTTON if (bHasSurveyPermission($surveyid, 'surveycontent', 'create')) { if ($activated != "Y") { $questionsummary .= "<a href='{$scriptname}?action=copyquestion&sid={$surveyid}&gid={$gid}&qid={$qid}'" . " title=\"" . $clang->gTview("Copy Current Question") . "\" >" . "<img src='{$imageurl}/copy.png' alt='" . $clang->gT("Copy Current Question") . "' name='CopyQuestion' /></a>\n" . "<img src='{$imageurl}/seperator.gif' alt='' />\n";
return; } if (!isset($deleteok) || !$deleteok) { $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("It will also delete any resources/files that have been uploaded for this survey.") . "<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 (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 (including any uploaded files) will be deleted. We recommend that you export the responses (and files) before deleting this survey.") . "<br /><br />\n"; } 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&sid={$surveyid}&deleteok=Y") . "\" />\n"; $deletesurveyoutput .= "\t<input type='submit' value='" . $clang->gT("Cancel") . "' onclick=\"window.open('admin.php?sid={$surveyid}', '_top')\" />\n"; } else { $dict = NewDataDictionary($connect); if (tableExists("survey_{$surveyid}")) { $dsquery = $dict->DropTableSQL("{$dbprefix}survey_{$surveyid}"); //$dict->ExecuteSQLArray($sqlarray); $dsresult = $dict->ExecuteSQLArray($dsquery) or safe_die("Couldn't \"{$dsquery}\" because <br />" . $connect->ErrorMsg()); } if (tableExists("survey_{$surveyid}_timings")) { $dsquery = $dict->DropTableSQL("{$dbprefix}survey_{$surveyid}_timings"); //$dict->ExecuteSQLArray($sqlarraytimings); $dsresult = $dict->ExecuteSQLArray($dsquery) or safe_die("Couldn't \"{$dsquery}\" because <br />" . $connect->ErrorMsg()); } if (tableExists("tokens_{$surveyid}")) { $dsquery = $dict->DropTableSQL("{$dbprefix}tokens_{$surveyid}");
foreach ($tab_title as $i => $eachtitle) { $labelsoutput .= "<li><a href='#neweditlblset{$i}'>{$eachtitle}</a></li>"; } $labelsoutput .= "</ul>"; foreach ($tab_content as $i => $eachcontent) { $labelsoutput .= "<div id='neweditlblset{$i}'>{$eachcontent}</div>"; } $labelsoutput .= "</div>"; } //SET SELECTED if (isset($lid) && $action != "editlabelset" && $lid) { //NOW GET THE ANSWERS AND DISPLAY THEM $query = "SELECT * FROM " . db_table_name('labelsets') . " WHERE lid={$lid}"; $result = db_execute_assoc($query); while ($row = $result->FetchRow()) { $labelsoutput .= "<div class='menubar'>\n" . "<div class='menubar-title ui-widget-header'>\n" . "\t<strong>" . $clang->gT("Label Set") . ":</strong> {$row['label_name']}\n" . "</div>\n" . "<div class='menubar-main'>\n" . "\t<div class='menubar-left'>\n" . "\t<img src='{$imageurl}/blank.gif' width='40' height='20' border='0' hspace='0' align='left' alt='' />\n" . "\t<img src='{$imageurl}/seperator.gif' border='0' hspace='0' align='left' alt='' />\n" . "\t<a href='admin.php?action=editlabelset&lid={$lid}' title=\"" . $clang->gTview("Edit label set") . "\" >" . "<img name='EditLabelsetButton' src='{$imageurl}/edit.png' alt='" . $clang->gT("Edit label set") . "' align='left' /></a>" . "\t<a href='#' title='" . $clang->gTview("Delete label set") . "' onclick=\"if (confirm('" . $clang->gT("Do you really want to delete this label set?", "js") . "')) {" . get2post("admin.php?action=deletelabelset&lid={$lid}") . "}\" >" . "<img src='{$imageurl}/delete.png' border='0' alt='" . $clang->gT("Delete label set") . "' align='left' /></a>\n" . "\t<img src='{$imageurl}/seperator.gif' border='0' hspace='0' align='left' alt='' />\n" . "\t<a href='admin.php?action=dumplabel&lid={$lid}' title=\"" . $clang->gTview("Export this label set") . "\" >" . "<img src='{$imageurl}/dumplabel.png' alt='" . $clang->gT("Export this label set") . "' align='left' /></a>" . "\t</div>\n" . "\t<div class='menubar-right'>\n" . "\t<input type='image' src='{$imageurl}/close.gif' title='" . $clang->gT("Close Window") . "'" . "onclick=\"window.open('admin.php?action=labels', '_top')\" />\n" . "\t</div>\n" . "\t</div>\n" . "\t</div>\n"; $labelsoutput .= "<p style='margin:0;font-size:1px;line-height:1px;height:1px;'> </p>"; //CSS Firefox 2 transition fix } //LABEL ANSWERS - SHOW THE MASK FOR EDITING THE LABELS $js_admin_includes[] = 'scripts/updateset.js'; $qulabelset = "SELECT * FROM " . db_table_name('labelsets') . " WHERE lid={$lid}"; $rslabelset = db_execute_assoc($qulabelset) or safe_die($connect->ErrorMsg()); $rwlabelset = $rslabelset->FetchRow(); $lslanguages = explode(" ", trim($rwlabelset['languages'])); $labelsoutput .= PrepareEditorScript(); $maxquery = "SELECT max(sortorder) as maxsortorder FROM " . db_table_name('labels') . " WHERE lid={$lid} and language='{$lslanguages[0]}'"; $maxresult = db_execute_assoc($maxquery) or safe_die($connect->ErrorMsg()); $msorow = $maxresult->FetchRow(); $maxsortorder = $msorow['maxsortorder'] + 1; // labels table
$questionsummary .= "" // ."<img src='$imageurl/seperator.gif' alt='' />\n" . "<a href='$scriptname?action=editquestion&sid=$surveyid&gid=$gid&qid=$qid'" . " title=\"".$clang->gTview("Edit current question")."\">" . "<img src='$imageurl/edit.png' alt='".$clang->gT("Edit Current Question")."' name='EditQuestion' /></a>\n" ; } // DELETE CURRENT QUESTION BUTTON if ((($qct == 0 && $activated != "Y") || $activated != "Y") && bHasSurveyPermission($surveyid,'surveycontent','delete')) { if (is_null($condarray)) { $questionsummary .= "<a href='#'" . "onclick=\"if (confirm('".$clang->gT("Deleting this question will also delete any answer options and subquestions it includes. Are you sure you want to continue?","js")."')) {".get2post("$scriptname?action=delquestion&sid=$surveyid&gid=$gid&qid=$qid")."}\">" . "<img src='$imageurl/delete.png' name='DeleteWholeQuestion' alt='".$clang->gT("Delete current question")."' " . "border='0' hspace='0' /></a>\n"; } else { $questionsummary .= "<a href='$scriptname?sid=$surveyid&gid=$gid&qid=$qid'" . "onclick=\"alert('".$clang->gT("It's impossible to delete this question because there is at least one question having a condition on it.","js")."')\"" . "title=\"".$clang->gTview("Disabled - Delete current question")."\">" . "<img src='$imageurl/delete_disabled.png' name='DeleteWholeQuestion' alt='".$clang->gT("Disabled - Delete current question")."' /></a>\n"; } } else {$questionsummary .= "<img src='$imageurl/blank.gif' alt='' width='40' />\n";} // EXPORT CURRENT QUESTION BUTTON
/** * Function to activate a survey * @global $dbprefix $dbprefix * @global $connect $connect * @global $clang $clang * @param int $postsid * @param int $surveyid * @return string */ function activateSurvey($postsid, $surveyid, $scriptname = 'admin.php') { global $dbprefix, $connect, $clang, $databasetype, $databasetabletype, $uploaddir; $createsurvey = ''; $activateoutput = ''; $createsurveytimings = ''; $createsurveydirectory = false; //Check for any additional fields for this survey and create necessary fields (token and datestamp) $pquery = "SELECT anonymized, allowregister, datestamp, ipaddr, refurl, savetimings FROM {$dbprefix}surveys WHERE sid={$postsid}"; $presult = db_execute_assoc($pquery); $prow = $presult->FetchRow(); if ($prow['allowregister'] == "Y") { $surveyallowsregistration = "TRUE"; } if ($prow['savetimings'] == "Y") { $savetimings = "TRUE"; } //strip trailing comma and new line feed (if any) $createsurvey = rtrim($createsurvey, ",\n"); //strip trailing comma and new line feed (if any) $createsurvey = rtrim($createsurvey, ",\n"); //Get list of questions for the base language $fieldmap = createFieldMap($surveyid); foreach ($fieldmap as $arow) { if ($createsurvey != '') { $createsurvey .= ",\n"; } $createsurvey .= ' `' . $arow['fieldname'] . '`'; switch ($arow['type']) { case 'startlanguage': $createsurvey .= " C(20) NOTNULL"; break; case 'id': $createsurvey .= " I NOTNULL AUTO PRIMARY"; $createsurveytimings .= " `{$arow['fieldname']}` I NOTNULL PRIMARY,\n"; break; case "startdate": case "datestamp": $createsurvey .= " T NOTNULL"; break; case "submitdate": $createsurvey .= " T"; break; case "lastpage": $createsurvey .= " I"; break; case "N": //NUMERICAL $createsurvey .= " F"; break; case "S": //SHORT TEXT if ($databasetype == 'mysql' || $databasetype == 'mysqli') { $createsurvey .= " X"; } else { $createsurvey .= " C(255)"; } break; case "L": //LIST (RADIO) //LIST (RADIO) case "!": //LIST (DROPDOWN) //LIST (DROPDOWN) case "M": //Multiple choice //Multiple choice case "P": //Multiple choice with comment //Multiple choice with comment case "O": //DROPDOWN LIST WITH COMMENT if ($arow['aid'] != 'other' && strpos($arow['aid'], 'comment') === false && strpos($arow['aid'], 'othercomment') === false) { $createsurvey .= " C(5)"; } else { $createsurvey .= " X"; } break; case "K": // Multiple Numerical $createsurvey .= " F"; break; case "U": //Huge text //Huge text case "Q": //Multiple short text //Multiple short text case "T": //LONG TEXT //LONG TEXT case ";": //Multi Flexi //Multi Flexi case ":": //Multi Flexi $createsurvey .= " X"; break; case "D": //DATE $createsurvey .= " D"; break; case "5": //5 Point Choice //5 Point Choice case "G": //Gender //Gender case "Y": //YesNo //YesNo case "X": //Boilerplate $createsurvey .= " C(1)"; break; case "I": //Language switch $createsurvey .= " C(20)"; break; case "|": $createsurveydirectory = true; if (strpos($arow['fieldname'], "_")) { $createsurvey .= " I1"; } else { $createsurvey .= " X"; } break; case "ipaddress": if ($prow['ipaddr'] == "Y") { $createsurvey .= " X"; } break; case "url": if ($prow['refurl'] == "Y") { $createsurvey .= " X"; } break; case "token": if ($prow['anonymized'] == "N") { $createsurvey .= " C(36)"; } break; default: $createsurvey .= " C(5)"; } } $timingsfieldmap = createTimingsFieldMap($surveyid); $createsurveytimings .= '`' . implode("` F DEFAULT '0',\n`", array_keys($timingsfieldmap)) . "` F DEFAULT '0'"; // If last question is of type MCABCEFHP^QKJR let's get rid of the ending coma in createsurvey $createsurvey = rtrim($createsurvey, ",\n") . "\n"; // Does nothing if not ending with a comma $tabname = "{$dbprefix}survey_{$postsid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL) $taboptarray = array('mysql' => 'ENGINE=' . $databasetabletype . ' CHARACTER SET utf8 COLLATE utf8_unicode_ci', 'mysqli' => 'ENGINE=' . $databasetabletype . ' CHARACTER SET utf8 COLLATE utf8_unicode_ci'); $dict = NewDataDictionary($connect); $sqlarray = $dict->CreateTableSQL($tabname, $createsurvey, $taboptarray); if (isset($savetimings) && $savetimings == "TRUE") { $tabnametimings = $tabname . '_timings'; $sqlarraytimings = $dict->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray); } $execresult = $dict->ExecuteSQLArray($sqlarray, 1); if ($execresult == 0 || $execresult == 1) { $activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n" . "<div class='header ui-widget-header'>" . $clang->gT("Activate Survey") . " ({$surveyid})</div>\n" . "<div class='warningheader'>" . $clang->gT("Survey could not be actived.") . "</div>\n" . "<p>" . $clang->gT("Database error:") . "\n <font color='red'>" . $connect->ErrorMsg() . "</font>\n" . "<pre>{$createsurvey}</pre>\n\n <a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>\n</div>"; } if ($execresult != 0 && $execresult != 1) { $anquery = "SELECT autonumber_start FROM {$dbprefix}surveys WHERE sid={$postsid}"; if ($anresult = db_execute_assoc($anquery)) { //if there is an autonumber_start field, start auto numbering here while ($row = $anresult->FetchRow()) { if ($row['autonumber_start'] > 0) { if ($databasetype == 'odbc_mssql' || $databasetype == 'odbtp' || $databasetype == 'mssql_n' || $databasetype == 'mssqlnative') { mssql_drop_primary_index('survey_' . $postsid); mssql_drop_constraint('id', 'survey_' . $postsid); $autonumberquery = "alter table {$dbprefix}survey_{$postsid} drop column id "; $connect->Execute($autonumberquery); $autonumberquery = "alter table {$dbprefix}survey_{$postsid} add [id] int identity({$row['autonumber_start']},1)"; $connect->Execute($autonumberquery); } else { $autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = " . $row['autonumber_start']; $result = @$connect->Execute($autonumberquery); } } } if (isset($savetimings) && $savetimings == "TRUE") { $dict->ExecuteSQLArray($sqlarraytimings, 1); // create a timings table for this survey } } $activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n"; $activateoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Activate Survey") . " ({$surveyid})</div>\n"; $activateoutput .= "<div class='successheader'>" . $clang->gT("Survey has been activated. Results table has been successfully created.") . "</div><br /><br />\n"; // create the survey directory where the uploaded files can be saved if ($createsurveydirectory) { if (!file_exists($uploaddir . "/surveys/" . $postsid . "/files")) { if (!mkdir($uploaddir . "/surveys/" . $postsid . "/files", 0777, true)) { $activateoutput .= "<div class='warningheader'>" . $clang->gT("The required directory for saving the uploaded files couldn't be created. Please check file premissions on the limesurvey/upload/surveys directory.") . "</div>"; } else { file_put_contents($uploaddir . "/surveys/" . $postsid . "/files/index.html", '<html><head></head><body></body></html>'); } } } $acquery = "UPDATE {$dbprefix}surveys SET active='Y' WHERE sid=" . $surveyid; $acresult = $connect->Execute($acquery); if (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE") { $activateoutput .= $clang->gT("This survey allows public registration. A token table must also be created.") . "<br /><br />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("Initialise tokens") . "' onclick=\"" . get2post("{$scriptname}?action=tokens&sid={$postsid}&createtable=Y") . "\" />\n"; } else { $activateoutput .= $clang->gT("This survey is now active, and responses can be recorded.") . "<br /><br />\n"; $activateoutput .= "<strong>" . $clang->gT("Open-access mode") . ":</strong> " . $clang->gT("No invitation code is needed to complete the survey.") . "<br />" . $clang->gT("You can switch to the closed-access mode by initialising a token table with the button below.") . "<br /><br />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("Switch to closed-access mode") . "' onclick=\"" . get2post("{$scriptname}?action=tokens&sid={$postsid}&createtable=Y") . "\" />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("No, thanks.") . "' onclick=\"" . get2post("{$scriptname}?sid={$postsid}") . "\" />\n"; } $activateoutput .= "</div><br /> \n"; $lsrcOutput = true; } if ($scriptname == 'lsrc') { if ($lsrcOutput == true) { return true; } else { return $activateoutput; } } else { return $activateoutput; } }
$resetsurveylogicoutput .= "</body>\n</html>"; return; } if (!isset($ok) || !$ok) { $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"; $resetsurveylogicoutput .= "\t\t\t<strong>" . $clang->gT("You are about to delete all conditions on this survey's questions") . " ({$surveyid})</strong><br /><br />\n"; $resetsurveylogicoutput .= "\t\t\t" . $clang->gT("We recommend that before you proceed, you export the entire survey from the main administration screen.") . "\n"; $resetsurveylogicoutput .= "\t\t</td>\n"; $resetsurveylogicoutput .= "\t</tr>\n"; $resetsurveylogicoutput .= "\t<tr>\n"; $resetsurveylogicoutput .= "\t\t<td align='center'><br />\n"; $resetsurveylogicoutput .= "\t\t\t<input type='submit' value='" . $clang->gT("Cancel") . "' onclick=\"window.open('admin.php?sid={$surveyid}', '_self')\" /><br />\n"; // $resetsurveylogicoutput .= "\t\t\t<input type='submit' value='".$clang->gT("Delete")."' onclick=\"window.open('$scriptname?action=resetsurveylogic&sid=$surveyid&ok=Y','_self')\" />\n"; $resetsurveylogicoutput .= "\t\t\t<input type='submit' value='" . $clang->gT("Delete") . "' onclick=\"" . get2post("{$scriptname}?action=resetsurveylogic&sid={$surveyid}&ok=Y") . "\" />\n"; $resetsurveylogicoutput .= "\t\t</td>\n"; $resetsurveylogicoutput .= "\t</tr>\n"; $resetsurveylogicoutput .= "\n"; } else { $dict = NewDataDictionary($connect); LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid); $resetlogicquery = "DELETE FROM {$dbprefix}conditions WHERE qid in (select qid from {$dbprefix}questions where sid={$surveyid})"; $resetlogicresult = $connect->Execute($resetlogicquery) or safe_die("Couldn't delete conditions<br />{$resetlogicquery}<br />" . $connect->ErrorMsg()); $resetsurveylogicoutput .= "\t<tr>\n"; $resetsurveylogicoutput .= "\t\t<td align='center'><br />\n"; $resetsurveylogicoutput .= "\t\t\t<strong>" . $clang->gT("All conditions in this survey have been deleted.") . "<br /><br />\n"; $resetsurveylogicoutput .= "\t\t\t<input type='submit' value='" . $clang->gT("Continue") . "' onclick=\"window.open('{$scriptname}?sid={$surveyid}', '_self')\" />\n"; $resetsurveylogicoutput .= "\t\t</strong></td>\n"; $resetsurveylogicoutput .= "\t</tr>\n"; $surveyid = false;
$_SESSION['loginID'] == $grow['owner_id']) { $usergroupsummary .= "<a href=\"#\" onclick=\"window.location='$scriptname?action=editusergroup&ugid=$ugid'\"" . " title='".$clang->gTview("Edit Current User Group")."'>" . "<img src='$imageurl/edit.png' alt='".$clang->gT("Edit Current User Group")."' name='EditUserGroup' /></a>\n" ; } else { $usergroupsummary .= "<img src='$imageurl/blank.gif' alt='' width='40' height='20' />\n"; } if($ugid && $grpresultcount > 0 && $_SESSION['loginID'] == $grow['owner_id']) { // $usergroupsummary .= "<a href='$scriptname?action=delusergroup&ugid=$ugid' onclick=\"return confirm('".$clang->gT("Are you sure you want to delete this entry?","js")."')\"" $usergroupsummary .= "<a href='#' onclick=\"if (confirm('".$clang->gT("Are you sure you want to delete this entry?","js")."')) {".get2post("$scriptname?action=delusergroup&ugid=$ugid")."}\" " . "title='".$clang->gTview("Delete Current User Group")."'>" . "<img src='$imageurl/delete.png' alt='".$clang->gT("Delete Current User Group")."' name='DeleteUserGroup' /></a>\n"; } else { $usergroupsummary .= "<img src='$imageurl/blank.gif' alt='' width='40' height='20' />\n"; } $usergroupsummary .= "<img src='$imageurl/blank.gif' alt='' width='92' height='20' />\n" . "<img src='$imageurl/seperator.gif' alt='' />\n" . "</div>\n" . "<div class='menubar-right'>\n" . "<font class=\"boxcaption\">".$clang->gT("User Groups").":</font> <select name='ugid' " . "onchange=\"window.location=this.options[this.selectedIndex].value\">\n" . getusergrouplist() . "</select>\n";
$acresult = $connect->Execute($acquery); // Private means data privacy, not closed access survey // if (isset($surveynotprivate) && $surveynotprivate) //This survey is tracked, and therefore a tokens table MUST exist // { // $activateoutput .= $clang->gT("This is not an anonymous survey. A token table must also be created.")."<br /><br />\n"; // $activateoutput .= "<input type='submit' value='".$clang->gT("Initialise Tokens")."' onclick=\"window.open('$scriptname?action=tokens&sid={$_GET['sid']}&createtable=Y', '_top')\" />\n"; // } // elseif (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE") if (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE") { $activateoutput .= $clang->gT("This survey allows public registration. A token table must also be created.") . "<br /><br />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("Initialise Tokens") . "' onclick=\"" . get2post("{$scriptname}?action=tokens&sid={$postsid}&createtable=Y") . "\" />\n"; } else { $activateoutput .= $clang->gT("This survey is now active, and responses can be recorded.") . "<br /><br />\n"; $activateoutput .= "<strong>" . $clang->gT("Open-access mode") . ":</strong> " . $clang->gT("No invitation code is needed to complete the survey.") . "<br />" . $clang->gT("You can switch to the closed-access mode by initialising a token table with the button below.") . "<br /><br />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("Switch to closed-access mode") . "' onclick=\"" . get2post("{$scriptname}?action=tokens&sid={$postsid}&createtable=Y") . "\" />\n"; $activateoutput .= "<input type='submit' value='" . $clang->gT("No, thanks.") . "' onclick=\"" . get2post("{$scriptname}?sid={$postsid}") . "\" />\n"; } $activateoutput .= "</div><br /> \n"; } } function mssql_drop_constraint($fieldname, $tablename) { global $dbprefix, $connect, $modifyoutput; // find out the name of the default constraint // Did I already mention that this is the most suckiest thing I have ever seen in MSSQL database? $dfquery = "SELECT c_obj.name AS constraint_name\n FROM sys.sysobjects AS c_obj INNER JOIN\n sys.sysobjects AS t_obj ON c_obj.parent_obj = t_obj.id INNER JOIN\n sys.sysconstraints AS con ON c_obj.id = con.constid INNER JOIN\n sys.syscolumns AS col ON t_obj.id = col.id AND con.colid = col.colid\n WHERE (c_obj.xtype = 'D') AND (col.name = '{$fieldname}') AND (t_obj.name='{$dbprefix}{$tablename}')"; $defaultname = $connect->GetRow($dfquery); if ($defaultname != false) { modify_database("", "ALTER TABLE [prefix_{$tablename}] DROP CONSTRAINT {$defaultname[0]}"); echo $modifyoutput; flush();
} else { $idquery .= "{$surveytable}.id = {$id}"; } $idresult = db_execute_assoc($idquery) or safe_die("Couldn't get entry<br />\n{$idquery}<br />\n" . $connect->ErrorMsg()); while ($idrow = $idresult->FetchRow()) { $id = $idrow['id']; $rlanguage = $idrow['startlanguage']; } $next = $id + 1; $last = $id - 1; $browseoutput .= "<div class='menubar'>\n" . "<div class='menubar-title'>" . "<strong>" . $clang->gT("View Response") . ":</strong> {$id}\n" . "\t</div><div class='menubar-main'>\n" . "<img src='{$imagefiles}/blank.gif' width='31' height='20' border='0' hspace='0' align='left' alt='' />\n" . "<img src='{$imagefiles}/seperator.gif' border='0' hspace='0' align='left' alt='' />\n"; if (isset($rlanguage)) { $browseoutput .= "<a href='{$scriptname}?action=dataentry&subaction=edit&id={$id}&sid={$surveyid}&language={$rlanguage}' " . "title='" . $clang->gTview("Edit this entry") . "'>" . "<img align='left' src='{$imagefiles}/edit.png' alt='" . $clang->gT("Edit this entry") . "' /></a>\n"; } if (bHasRight($surveyid, 'delete_survey') && isset($rlanguage)) { $browseoutput .= "<a href='#' title='" . $clang->gTview("Delete this entry") . "' onclick=\"if (confirm('" . $clang->gT("Are you sure you want to delete this entry?", "js") . "')) {" . get2post($scriptname . '?action=dataentry&subaction=delete&id=' . $id . '&sid=' . $surveyid) . "}\" >" . "<img align='left' hspace='0' border='0' src='{$imagefiles}/delete.png' alt='" . $clang->gT("Delete this entry") . "' /></a>\n"; } else { $browseoutput .= "<img align='left' hspace='0' border='0' src='{$imagefiles}/delete_disabled.png' alt='" . $clang->gT("You don't have permission to delete this entry.") . "'/>"; } //Export this response $browseoutput .= "<a href='{$scriptname}?action=exportresults&sid={$surveyid}&id={$id}'" . "title='" . $clang->gTview("Export this Response") . "' >" . "<img name='ExportAnswer' src='{$imagefiles}/export.png' alt='" . $clang->gT("Export this Response") . "' align='left' /></a>\n" . "<img src='{$imagefiles}/seperator.gif' border='0' hspace='0' align='left' alt='' />\n" . "<img src='{$imagefiles}/blank.gif' width='20' height='20' border='0' hspace='0' align='left' alt='' />\n" . "<a href='{$scriptname}?action=browse&subaction=id&id={$last}&sid={$surveyid}' " . "title='" . $clang->gTview("Show previous...") . "' >" . "<img name='DataBack' align='left' src='{$imagefiles}/databack.png' alt='" . $clang->gT("Show previous...") . "' /></a>\n" . "<img src='{$imagefiles}/blank.gif' width='13' height='20' border='0' hspace='0' align='left' alt='' />\n" . "<a href='{$scriptname}?action=browse&subaction=id&id={$next}&sid={$surveyid}' title='" . $clang->gTview("Show next...") . "'>" . "<img name='DataForward' align='left' src='{$imagefiles}/dataforward.png' alt='" . $clang->gT("Show next...") . "' /></a>\n" . "</div>\n" . "\t</div>\n"; $browseoutput .= "<table class='detailbrowsetable' width='99%'>\n"; $idresult = db_execute_assoc($idquery) or safe_die("Couldn't get entry<br />{$idquery}<br />" . $connect->ErrorMsg()); while ($idrow = $idresult->FetchRow()) { $i = 0; $highlight = false; for ($i; $i < $nfncount + 1; $i++) { $inserthighlight = ''; if ($highlight) { $inserthighlight = "class='highlight'"; }
} $usergroupsummary .= "</div>\n" . "<div class='menubar-main'>\n" . "<div class='menubar-left'>\n" . "<img src='{$imageurl}/blank.gif' alt='' width='55' height='20' />\n" . "<img src='{$imageurl}/seperator.gif' alt='' />\n"; if ($ugid && $grpresultcount > 0) { $usergroupsummary .= "<a href=\"#\" onclick=\"window.location='{$scriptname}?action=mailusergroup&ugid={$ugid}'\"" . " title='" . $clang->gTview("Mail to all Members") . "'> " . "<img src='{$imageurl}/invite.png' alt='" . $clang->gT("Mail to all Members") . "' name='MailUserGroup' /></a>\n"; } else { $usergroupsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='40' height='20' />\n"; } $usergroupsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='78' height='20' />\n" . "<img src='{$imageurl}/seperator.gif' alt='' />\n"; if ($ugid && $grpresultcount > 0 && $_SESSION['loginID'] == $grow['owner_id']) { $usergroupsummary .= "<a href=\"#\" onclick=\"window.location='{$scriptname}?action=editusergroup&ugid={$ugid}'\"" . " title='" . $clang->gTview("Edit Current User Group") . "'>" . "<img src='{$imageurl}/edit.png' alt='" . $clang->gT("Edit Current User Group") . "' name='EditUserGroup' /></a>\n"; } else { $usergroupsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='40' height='20' />\n"; } if ($ugid && $grpresultcount > 0 && $_SESSION['loginID'] == $grow['owner_id']) { // $usergroupsummary .= "<a href='$scriptname?action=delusergroup&ugid=$ugid' onclick=\"return confirm('".$clang->gT("Are you sure you want to delete this entry?","js")."')\"" $usergroupsummary .= "<a href='#' onclick=\"if (confirm('" . $clang->gT("Are you sure you want to delete this entry?", "js") . "')) {" . get2post("{$scriptname}?action=delusergroup&ugid={$ugid}") . "}\" " . "title='" . $clang->gTview("Delete Current User Group") . "'>" . "<img src='{$imageurl}/delete.png' alt='" . $clang->gT("Delete Current User Group") . "' name='DeleteUserGroup' /></a>\n"; } else { $usergroupsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='40' height='20' />\n"; } $usergroupsummary .= "<img src='{$imageurl}/blank.gif' alt='' width='92' height='20' />\n" . "<img src='{$imageurl}/seperator.gif' alt='' />\n" . "</div>\n" . "<div class='menubar-right'>\n" . "<font class=\"boxcaption\">" . $clang->gT("User Groups") . ":</font> <select name='ugid' " . "onchange=\"window.location=this.options[this.selectedIndex].value\">\n" . getusergrouplist() . "</select>\n"; if ($_SESSION['USER_RIGHT_SUPERADMIN'] == 1) { $usergroupsummary .= "<a href='{$scriptname}?action=addusergroup'" . " title='" . $clang->gTview("Add New User Group") . "'>" . "<img src='{$imageurl}/add.png' alt='" . $clang->gT("Add New User Group") . "' " . "name='AddNewUserGroup' onclick=\"window.location=''\" /></a>\n"; } $usergroupsummary .= "<img src='{$imageurl}/seperator.gif' alt='' />\n" . "<img src='{$imageurl}/blank.gif' alt='' width='82' height='20' />\n" . "</div></div>\n" . "</div>\n"; $usergroupsummary .= "<p style='margin:0;font-size:1px;line-height:1px;height:1px;'> </p>"; //CSS Firefox 2 transition fix } if ($action == "adduser" || $action == "deluser" || $action == "finaldeluser" || $action == "moduser" || $action == "userrights" || $action == "usertemplates") { include "usercontrol.php"; } if ($action == "setusertemplates") {
."</ul><br />\n"; } $tokenoutput .= "</div>\n"; } } if ($subaction == "tokenify" && bHasSurveyPermission($surveyid, 'tokens', 'update')) { $tokenoutput .= "<div class='header ui-widget-header'>".$clang->gT("Create tokens")."</div>\n"; $tokenoutput .= "<div class='messagebox ui-corner-all'>\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?")."<br /><br />\n" ."<input type='submit' value='" // .$clang->gT("Yes")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid&subaction=tokenify&ok=Y', '_top')\" />\n" .$clang->gT("Yes")."' onclick=\"".get2post("$scriptname?action=tokens&sid=$surveyid&subaction=tokenify&ok=Y")."\" />\n" ."<input type='submit' value='" .$clang->gT("No")."' onclick=\"window.open('$scriptname?action=tokens&sid=$surveyid', '_top')\" />\n" ."<br />\n"; } else { //get token length from survey settings $tlquery = "SELECT tokenlength FROM ".db_table_name("surveys")." WHERE sid=$surveyid"; $tlresult = db_execute_assoc($tlquery); while ($tlrow = $tlresult->FetchRow()) { $tokenlength = $tlrow['tokenlength']; } //if tokenlength is not set or there are other problems use the default value (15)
$postsid = returnglobal('sid'); $date = date('YmdHis'); //'Hi' adds 24hours+minutes to name to allow multiple deactiviations in a day $deactivateoutput = ''; if (!isset($_POST['ok']) || !$_POST['ok']) { $deactivateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n"; $deactivateoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Deactivate Survey") . " ({$surveyid})</div>\n"; $deactivateoutput .= "\t<div class='warningheader'>\n"; $deactivateoutput .= $clang->gT("Warning") . "<br />" . $clang->gT("READ THIS CAREFULLY BEFORE PROCEEDING"); $deactivateoutput .= "</div>\n"; $deactivateoutput .= "\t" . $clang->gT("In an active survey, a table is created to store all the data-entry records.") . "\n"; $deactivateoutput .= "\t<p>" . $clang->gT("When you deactivate a survey all the data entered in the original table will be moved elsewhere, and when you activate the survey again, the table will be empty. You will not be able to access this data using LimeSurvey any more.") . "</p>\n"; $deactivateoutput .= "\t<p>" . $clang->gT("Deactivated survey data can only be accessed by system administrators using a Database data access tool like phpmyadmin. If your survey uses tokens, this table will also be renamed and will only be accessible by system administrators.") . "</p>\n"; $deactivateoutput .= "\t<p>" . $clang->gT("Your responses table will be renamed to:") . " {$dbprefix}old_{$_GET['sid']}_{$date}</p>\n"; $deactivateoutput .= "\t<p>" . $clang->gT("Also you should export your responses before deactivating.") . "</p>\n"; $deactivateoutput .= "\t<input type='submit' value='" . $clang->gT("Deactivate Survey") . "' onclick=\"" . get2post("{$scriptname}?action=deactivate&ok=Y&sid={$_GET['sid']}") . "\" />\n"; $deactivateoutput .= "</div><br />\n"; } else { //See if there is a tokens table for this survey if (tableExists("tokens_{$postsid}")) { $toldtable = "tokens_{$postsid}"; $tnewtable = "old_tokens_{$postsid}_{$date}"; $tdeactivatequery = db_rename_table(db_table_name_nq($toldtable), db_table_name_nq($tnewtable)); $tdeactivateresult = $connect->Execute($tdeactivatequery) or die("Couldn't deactivate tokens table because:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br /><br />Survey was not deactivated either.<br /><br /><a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>"); 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 $deactivatequery = db_rename_table(db_table_name_nq($toldtable) . '_tid_seq', db_table_name_nq($tnewtable) . '_tid_seq'); $deactivateresult = $connect->Execute($deactivatequery) or die("Could not rename the old sequence for this token table. The database reported the following error:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br /><br /><a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>"); $setsequence = "ALTER TABLE " . db_table_name_nq($tnewtable) . " ALTER COLUMN tid SET DEFAULT nextval('" . db_table_name_nq($tnewtable) . "_tid_seq'::regclass);"; $deactivateresult = $connect->Execute($setsequence) or die("Could not alter the field 'tid' to point to the new sequence name for this token table. The database reported the following error:<br />" . htmlspecialchars($connect->ErrorMsg()) . "<br /><br />Survey was not deactivated either.<br /><br /><a href='{$scriptname}?sid={$postsid}'>" . $clang->gT("Main Admin Screen") . "</a>"); $setidx = "ALTER INDEX " . db_table_name_nq($toldtable) . "_idx RENAME TO " . db_table_name_nq($tnewtable) . "_idx;";
*/ /* * Set completed answers to the incomplete state and reset the tokens to 'not used' so that * the survey can be published again to the same set of participants. * Partipants will see their previous answers and may change them. */ include_once 'login_check.php'; include 'html_functions.php'; if (!isset($surveyid)) { $surveyid = returnglobal('sid'); } if (!isset($subaction)) { // subaction is not set, then display instructions $iteratesurveyoutput = browsemenubar($clang->gT('Iterate survey')); $iteratesurveyoutput .= "<div class='header ui-widget-header'>" . $clang->gT("Iterate survey") . "</div>\n"; $iteratesurveyoutput .= "<div class='messagebox ui-corner-all'><div class='header ui-widget-header'>" . $clang->gT("Important instructions") . "</div>" . "<br/>" . $clang->gT("Click on the following button if you want to") . ":<br />\n" . "<ol>" . "<li>" . $clang->gT("Delete all incomplete answers that correspond to a token for which a completed answers is already recorded") . "</li>" . "<li>" . $clang->gT("Reset the completed answers to the incomplete state") . "</li>" . "<li>" . $clang->gT("Reset all your tokens to the 'not used' state") . "</li>" . "</ol><br />\n" . "<input type='button' onclick=\"if( confirm('" . $clang->gT("Are you really sure you want to *delete* some incomplete answers and reset the completed state of both answers and tokens?", "js") . "')){" . get2post("{$scriptname}?action=iteratesurvey&sid={$surveyid}&subaction=unfinalizeanswers") . "}\" value='" . $clang->gT("Reset answers and token completed state") . "' />" . "</div>"; } if ($subaction == 'unfinalizeanswers') { $iteratesurveyoutput = browsemenubar($clang->gT('Iterate survey')); $baselang = GetBaseLanguageFromSurveyID($surveyid); $surveytable = db_table_name("survey_{$surveyid}"); // First delete incomplete answers that correspond to a token for which a completed answers is already recorded // subquery in delete or update are tricky things when using the same table for delete and Select // see http://www.developpez.net/forums/d494961/bases-donnees/mysql/requetes/cant-specify-target-in-from-clause/ $updateqr = "DELETE from {$surveytable} WHERE submitdate IS NULL AND token in (SELECT * FROM ( SELECT answ2.token from {$surveytable} AS answ2 WHERE answ2.submitdate IS NOT NULL) tmp );\n"; // $updateqr = "DELETE from $surveytable WHERE submitdate IS NULL AND token in (SELECT b.token from $surveytable AS b WHERE b.submitdate IS NOT NULL);\n"; //error_log("TIBO query = $updateqr"); $updateres = $connect->Execute($updateqr) or safe_die("Delete incomplete answers with duplicate tokens failed:<br />\n" . $connect->ErrorMsg() . "<br />{$updateqr}"); // Then set all remaining answers to incomplete state $updateqr = "UPDATE {$surveytable} SET submitdate=NULL, lastpage=NULL;\n"; $updateres = $connect->Execute($updateqr) or safe_die("UnFinilize answers failed:<br />\n" . $connect->ErrorMsg() . "<br />{$updateqr}");