Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 534 lines (498 sloc) 24.848 kB
c88a74c Fix line ending
c_schmitz authored
1 <?php
2 /*
3 * LimeSurvey
4 * Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
5 * All rights reserved.
6 * License: GNU/GPL License v2 or later, see LICENSE.php
7 * LimeSurvey is free software. This version may have been modified pursuant
8 * to the GNU General Public License, and as distributed it includes or
9 * is derivative of works licensed under the GNU General Public License or
10 * other free or open source software licenses.
11 * See COPYRIGHT.php for copyright notices and details.
12 *
13 * $Id: activate_functions.php 12339 2012-02-04 12:48:38Z c_schmitz $
14 * Files Purpose: holds functions to activate a survey and precheck the consistency of the survey
15 */
16
17 /**
18 * fixes the numbering of questions
19 * @global $dbprefix $dbprefix
20 * @global $connect $connect
21 * @global $clang $clang
22 * @param <type> $fixnumbering
23 */
24 function fixNumbering($fixnumbering)
25 {
26
27 global $dbprefix, $connect, $clang, $surveyid;
28
29 LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
30 //Fix a question id - requires renumbering a question
31 $oldqid = $fixnumbering;
32 $query = "SELECT qid FROM {$dbprefix}questions ORDER BY qid DESC";
33 $result = db_select_limit_assoc($query, 1) or safe_die($query."<br />".$connect->ErrorMsg());
34 while ($row=$result->FetchRow()) {$lastqid=$row['qid'];}
35 $newqid=$lastqid+1;
36 $query = "UPDATE {$dbprefix}questions SET qid=$newqid WHERE qid=$oldqid";
37 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
38 // Update subquestions
39 $query = "UPDATE {$dbprefix}questions SET parent_qid=$newqid WHERE parent_qid=$oldqid";
40 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
41 //Update conditions.. firstly conditions FOR this question
42 $query = "UPDATE {$dbprefix}conditions SET qid=$newqid WHERE qid=$oldqid";
43 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
44 //Now conditions based upon this question
45 $query = "SELECT cqid, cfieldname FROM {$dbprefix}conditions WHERE cqid=$oldqid";
46 $result = db_execute_assoc($query) or safe_die($query."<br />".$connect->ErrorMsg());
47 while ($row=$result->FetchRow())
48 {
49 $switcher[]=array("cqid"=>$row['cqid'], "cfieldname"=>$row['cfieldname']);
50 }
51 if (isset($switcher))
52 {
53 foreach ($switcher as $switch)
54 {
55 $query = "UPDATE {$dbprefix}conditions
56 SET cqid=$newqid,
57 cfieldname='".str_replace("X".$oldqid, "X".$newqid, $switch['cfieldname'])."'
58 WHERE cqid=$oldqid";
59 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
60 }
61 }
62 //Now question_attributes
63 $query = "UPDATE {$dbprefix}question_attributes SET qid=$newqid WHERE qid=$oldqid";
64 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
65 //Now answers
66 $query = "UPDATE {$dbprefix}answers SET qid=$newqid WHERE qid=$oldqid";
67 $result = $connect->Execute($query) or safe_die($query."<br />".$connect->ErrorMsg());
68
69 LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
70 }
71 /**
72 * checks consistency of groups
73 * @global $dbprefix
74 * @global $connect
75 * @global $clang
76 * @return <type>
77 */
78 function checkGroup($postsid)
79 {
80 global $dbprefix, $connect, $clang;
81
82 $baselang = GetBaseLanguageFromSurveyID($postsid);
83 $groupquery = "SELECT g.gid,g.group_name,count(q.qid) as count from {$dbprefix}questions as q RIGHT JOIN {$dbprefix}groups as g ON q.gid=g.gid AND g.language=q.language WHERE g.sid=$postsid AND g.language='$baselang' group by g.gid,g.group_name;";
84 $groupresult=db_execute_assoc($groupquery) or safe_die($groupquery."<br />".$connect->ErrorMsg());
85 while ($row=$groupresult->FetchRow())
86 { //TIBO
87 if ($row['count'] == 0)
88 {
89 $failedgroupcheck[]=array($row['gid'], $row['group_name'], ": ".$clang->gT("This group does not contain any question(s)."));
90 }
91 }
92 if(isset($failedgroupcheck))
93 return $failedgroupcheck;
94 else
95 return false;
96
97 }
98 /**
99 * checks questions in a survey for consistency
100 * @global <type> $dbprefix
101 * @global <type> $connect
102 * @global <type> $clang
103 * @param <type> $postsid
104 * @param <type> $surveyid
105 * @return array $faildcheck
106 */
107 function checkQuestions($postsid, $surveyid, $qtypes)
108 {
109 global $dbprefix, $connect, $clang;
110
111
112 //CHECK TO MAKE SURE ALL QUESTION TYPES THAT REQUIRE ANSWERS HAVE ACTUALLY GOT ANSWERS
113 //THESE QUESTION TYPES ARE:
114 // # "L" -> LIST
115 // # "O" -> LIST WITH COMMENT
116 // # "M" -> Multiple choice
117 // # "P" -> Multiple choice with comments
118 // # "A", "B", "C", "E", "F", "H", "^" -> Various Array Types
119 // # "R" -> RANKING
120 // # "U" -> FILE CSV MORE
121 // # "I" -> LANGUAGE SWITCH
122 // # ":" -> Array Multi Flexi Numbers
123 // # ";" -> Array Multi Flexi Text
124 // # "1" -> MULTI SCALE
125
126 $chkquery = "SELECT qid, question, gid, type FROM {$dbprefix}questions WHERE sid={$surveyid} and parent_qid=0";
127 $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't get list of questions<br />$chkquery<br />".$connect->ErrorMsg());
128 while ($chkrow = $chkresult->FetchRow())
129 {
130 if ($qtypes[$chkrow['type']]['subquestions']>0)
131 {
132 $chaquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid = {$chkrow['qid']} ORDER BY question_order";
133 $charesult=$connect->Execute($chaquery);
134 $chacount=$charesult->RecordCount();
135 if ($chacount == 0)
136 {
137 $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a subquestion type question but has no configured subquestions."), $chkrow['gid']);
138 }
139 }
140 if ($qtypes[$chkrow['type']]['answerscales']>0)
141 {
142 $chaquery = "SELECT * FROM {$dbprefix}answers WHERE qid = {$chkrow['qid']} ORDER BY sortorder, answer";
143 $charesult=$connect->Execute($chaquery);
144 $chacount=$charesult->RecordCount();
145 if ($chacount == 0)
146 {
147 $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a multiple answer type question but has no answers."), $chkrow['gid']);
148 }
149 }
150 }
151
152 //NOW CHECK THAT ALL QUESTIONS HAVE A 'QUESTION TYPE' FIELD SET
153 $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type = ''";
154 $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing types<br />$chkquery<br />".$connect->ErrorMsg());
155 while ($chkrow = $chkresult->FetchRow())
156 {
157 $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question does not have a question 'type' set."), $chkrow['gid']);
158 }
159
160
161
162
163 //ChECK THAT certain array question types have answers set
164 $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=0)=0 and sid={$_GET['sid']} AND type IN ('F', 'H', 'W', 'Z', '1') and q.parent_qid=0";
165 $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing answers<br />$chkquery<br />".$connect->ErrorMsg());
166 while($chkrow = $chkresult->FetchRow()){
167 $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires answers, but none are set."), $chkrow['gid']);
168 } // while
169
170 //CHECK THAT DUAL Array has answers set
171 $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=1)=0 and sid={$_GET['sid']} AND type='1' and q.parent_qid=0";
172 $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing 2nd answer set<br />$chkquery<br />".$connect->ErrorMsg());
173 while($chkrow = $chkresult->FetchRow()){
174 $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second answer set but none is set."), $chkrow['gid']);
175 } // while
176
177
178 //CHECK THAT ALL CONDITIONS SET ARE FOR QUESTIONS THAT PRECEED THE QUESTION CONDITION
179 //A: Make an array of all the qids in order of appearance
180 // $qorderquery="SELECT * FROM {$dbprefix}questions, {$dbprefix}groups WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND {$dbprefix}questions.sid={$_GET['sid']} ORDER BY {$dbprefix}groups.sortorder, {$dbprefix}questions.title";
181 // $qorderresult=$connect->Execute($qorderquery) or safe_die("Couldn't generate a list of questions in order<br />$qorderquery<br />".$connect->ErrorMsg());
182 // $qordercount=$qorderresult->RecordCount();
183 // $c=0;
184 // while ($qorderrow=$qorderresult->FetchRow())
185 // {
186 // $qidorder[]=array($c, $qorderrow['qid']);
187 // $c++;
188 // }
189 //TO AVOID NATURAL SORT ORDER ISSUES, FIRST GET ALL QUESTIONS IN NATURAL SORT ORDER, AND FIND OUT WHICH NUMBER IN THAT ORDER THIS QUESTION IS
190 $qorderquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND type not in ('S', 'D', 'T', 'Q')";
191 $qorderresult = db_execute_assoc($qorderquery) or safe_die ("$qorderquery<br />".$connect->ErrorMsg());
192 $qrows = array(); //Create an empty array in case FetchRow does not return any rows
193 while ($qrow = $qorderresult->FetchRow()) {$qrows[] = $qrow;} // Get table output into array
194 usort($qrows, 'GroupOrderThenQuestionOrder'); // Perform a case insensitive natural sort on group name then question title of a multidimensional array
195 $c=0;
196 foreach ($qrows as $qr)
197 {
198 $qidorder[]=array($c, $qrow['qid']);
199 $c++;
200 }
201 $qordercount="";
202 //1: Get each condition's question id
203 $conquery= "SELECT {$dbprefix}conditions.qid, cqid, {$dbprefix}questions.question, "
204 . "{$dbprefix}questions.gid "
205 . "FROM {$dbprefix}conditions, {$dbprefix}questions, {$dbprefix}groups "
206 . "WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid "
207 . "AND {$dbprefix}questions.gid={$dbprefix}groups.gid ORDER BY {$dbprefix}conditions.qid";
208 $conresult=db_execute_assoc($conquery) or safe_die("Couldn't check conditions for relative consistency<br />$conquery<br />".$connect->ErrorMsg());
209 //2: Check each conditions cqid that it occurs later than the cqid
210 while ($conrow=$conresult->FetchRow())
211 {
212 $cqidfound=0;
213 $qidfound=0;
214 $b=0;
215 while ($b<$qordercount)
216 {
217 if ($conrow['cqid'] == $qidorder[$b][1])
218 {
219 $cqidfound = 1;
220 $b=$qordercount;
221 }
222 if ($conrow['qid'] == $qidorder[$b][1])
223 {
224 $qidfound = 1;
225 $b=$qordercount;
226 }
227 if ($qidfound == 1)
228 {
229 $failedcheck[]=array($conrow['qid'], $conrow['question'], ": ".$clang->gT("This question has a condition set, however the condition is based on a question that appears after it."), $conrow['gid']);
230 }
231 $b++;
232 }
233 }
234 //CHECK THAT ALL THE CREATED FIELDS WILL BE UNIQUE
dcb71de @Shnoulle Dev : remove argument naming from function call
Shnoulle authored
235 $fieldmap=createFieldMap($surveyid, 'full', true,false, GetBaseLanguageFromSurveyID($surveyid));// createFieldMap($surveyid, $styl, $force_refresh,$questionid, $sQuestionLanguage);
c88a74c Fix line ending
c_schmitz authored
236 $clang = new limesurvey_lang($_SESSION['adminlang']);
237 if (isset($fieldmap))
238 {
239 foreach($fieldmap as $fielddata)
240 {
241 $fieldlist[]=$fielddata['fieldname'];
242 }
243 $fieldlist=array_reverse($fieldlist); //let's always change the later duplicate, not the earlier one
244 }
245 $checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;');
246 @$duplicates = array_keys (array_filter (array_count_values($fieldlist), $checkKeysUniqueComparison));
247 if (isset($duplicates))
248 {
249 foreach ($duplicates as $dup)
250 {
251 $badquestion=arraySearchByKey($dup, $fieldmap, "fieldname", 1);
252 $fix = "[<a href='$scriptname?action=activate&amp;sid=$surveyid&amp;fixnumbering=".$badquestion['qid']."'>Click Here to Fix</a>]";
253 $failedcheck[]=array($badquestion['qid'], $badquestion['question'], ": Bad duplicate fieldname $fix", $badquestion['gid']);
254 }
255 }
256 if(isset($failedcheck))
257 return $failedcheck;
258 else
259 return false;
260 }
261 /**
262 * Function to activate a survey
263 * @global $dbprefix $dbprefix
264 * @global $connect $connect
265 * @global $clang $clang
266 * @param int $postsid
267 * @param int $surveyid
268 * @return string
269 */
270 function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
271 {
272 global $dbprefix, $connect, $clang, $databasetype,$databasetabletype, $uploaddir;
273
274 $createsurvey='';
275 $activateoutput='';
276 $createsurveytimings='';
277 $createsurveydirectory=false;
278 //Check for any additional fields for this survey and create necessary fields (token and datestamp)
279 $pquery = "SELECT anonymized, allowregister, datestamp, ipaddr, refurl, savetimings FROM {$dbprefix}surveys WHERE sid={$postsid}";
280 $presult=db_execute_assoc($pquery);
281 $prow=$presult->FetchRow();
282 if ($prow['allowregister'] == "Y")
283 {
284 $surveyallowsregistration="TRUE";
285 }
286 if ($prow['savetimings'] == "Y")
287 {
288 $savetimings="TRUE";
289 }
290
291 //Get list of questions for the base language
dcb71de @Shnoulle Dev : remove argument naming from function call
Shnoulle authored
292 $fieldmap=createFieldMap($surveyid, 'full', true,false, GetBaseLanguageFromSurveyID($surveyid));// createFieldMap($surveyid, $styl, $force_refresh,$questionid, $sQuestionLanguage);
c88a74c Fix line ending
c_schmitz authored
293 foreach ($fieldmap as $arow) //With each question, create the appropriate field(s)
294 {
295 if ($createsurvey!='') {$createsurvey .= ",\n";}
296 $createsurvey .= ' `'.$arow['fieldname'].'`';
297 switch($arow['type'])
298 {
299 case 'startlanguage':
300 $createsurvey .= " C(20) NOTNULL";
301 break;
302 case 'id':
303 $createsurvey .= " I NOTNULL AUTO PRIMARY";
304 $createsurveytimings .= " `{$arow['fieldname']}` I NOTNULL PRIMARY,\n";
305 break;
306 case "startdate":
307 case "datestamp":
308 $createsurvey .= " T NOTNULL";
309 break;
310 case "submitdate":
311 $createsurvey .= " T";
312 break;
313 case "lastpage":
314 $createsurvey .= " I";
315 break;
316 case "N": //NUMERICAL
317 $createsurvey .= " F";
318 break;
319 case "S": //SHORT TEXT
320 if ($databasetype=='mysql' || $databasetype=='mysqli') {$createsurvey .= " X";}
321 else {$createsurvey .= " C(255)";}
322 break;
323 case "L": //LIST (RADIO)
324 case "!": //LIST (DROPDOWN)
325 case "M": //Multiple choice
326 case "P": //Multiple choice with comment
327 case "O": //DROPDOWN LIST WITH COMMENT
328 if ($arow['aid'] != 'other' && strpos($arow['aid'],'comment')===false && strpos($arow['aid'],'othercomment')===false)
329 {
330 $createsurvey .= " C(5)";
331 }
332 else
333 {
334 $createsurvey .= " X";
335 }
336 break;
337 case "K": // Multiple Numerical
338 $createsurvey .= " F";
339 break;
340 case "U": //Huge text
341 case "Q": //Multiple short text
342 case "T": //LONG TEXT
343 case ";": //Multi Flexi
344 case ":": //Multi Flexi
345 $createsurvey .= " X";
346 break;
347 case "D": //DATE
348 $createsurvey .= " D";
349 break;
350 case "5": //5 Point Choice
351 case "G": //Gender
352 case "Y": //YesNo
353 case "X": //Boilerplate
354 $createsurvey .= " C(1)";
355 break;
356 case "I": //Language switch
357 $createsurvey .= " C(20)";
358 break;
359 case "|":
360 $createsurveydirectory = true;
361 if (strpos($arow['fieldname'], "_"))
362 $createsurvey .= " I1";
363 else
364 $createsurvey .= " X";
365 break;
366 case "ipaddress":
367 if ($prow['ipaddr'] == "Y")
368 $createsurvey .= " X";
369 break;
370 case "url":
371 if ($prow['refurl'] == "Y")
372 $createsurvey .= " X";
373 break;
374 case "token":
375 if ($prow['anonymized'] == "N")
376 {
377 $createsurvey .= " C(36)";
378 }
379 break;
380 case '*': // Equation
381 $createsurvey .= " X"; // could be anything, from numeric to a long message, so default to text
382 break;
383 default:
384 $createsurvey .= " C(5)";
385 }
386 }
387 $timingsfieldmap = createTimingsFieldMap($surveyid);
388 $createsurveytimings .= '`'.implode("` F DEFAULT '0',\n`",array_keys($timingsfieldmap)) . "` F DEFAULT '0'";
389
390 // If last question is of type MCABCEFHP^QKJR let's get rid of the ending coma in createsurvey
391 $createsurvey = rtrim($createsurvey, ",\n")."\n"; // Does nothing if not ending with a comma
392
393 $tabname = "{$dbprefix}survey_{$postsid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)
394
395 $taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci',
396 'mysqli'=> 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
397 $dict = NewDataDictionary($connect);
398 $sqlarray = $dict->CreateTableSQL($tabname, $createsurvey, $taboptarray);
399
400 if (isset($savetimings) && $savetimings=="TRUE")
401 {
402 $tabnametimings = $tabname .'_timings';
403 $sqlarraytimings = $dict->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray);
404 }
405
406 $execresult=$dict->ExecuteSQLArray($sqlarray,1);
407 if ($execresult==0 || $execresult==1)
408 {
409 $activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n" .
410 "<div class='header ui-widget-header'>".$clang->gT("Activate Survey")." ($surveyid)</div>\n" .
411 "<div class='warningheader'>".$clang->gT("Survey could not be actived.")."</div>\n" .
412 "<p>" .
413 $clang->gT("Database error:")."\n <font color='red'>" . $connect->ErrorMsg() . "</font>\n" .
414 "<pre>$createsurvey</pre>\n
415 <a href='$scriptname?sid={$postsid}'>".$clang->gT("Main Admin Screen")."</a>\n</div>" ;
416 }
417 if ($execresult != 0 && $execresult !=1)
418 {
419 $anquery = "SELECT autonumber_start FROM {$dbprefix}surveys WHERE sid={$postsid}";
420 if ($anresult=db_execute_assoc($anquery))
421 {
422 //if there is an autonumber_start field, start auto numbering here
423 while($row=$anresult->FetchRow())
424 {
425 if ($row['autonumber_start'] > 0)
426 {
427 if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $databasetype=='mssqlnative') {
428 mssql_drop_primary_index('survey_'.$postsid);
429 mssql_drop_constraint('id','survey_'.$postsid);
430 $autonumberquery = "alter table {$dbprefix}survey_{$postsid} drop column id ";
431 $connect->Execute($autonumberquery);
432 $autonumberquery = "alter table {$dbprefix}survey_{$postsid} add [id] int identity({$row['autonumber_start']},1)";
433 $connect->Execute($autonumberquery);
434 }
435 else
436 {
437 $autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = ".$row['autonumber_start'];
438 $result = @$connect->Execute($autonumberquery);
439
440 }
441 }
442 }
443 if (isset($savetimings) && $savetimings=="TRUE")
444 {
445 $dict->ExecuteSQLArray($sqlarraytimings,1); // create a timings table for this survey
446 }
447 }
448
449 $activateoutput .= "<br />\n<div class='messagebox ui-corner-all'>\n";
450 $activateoutput .= "<div class='header ui-widget-header'>".$clang->gT("Activate Survey")." ($surveyid)</div>\n";
451 $activateoutput .= "<div class='successheader'>".$clang->gT("Survey has been activated. Results table has been successfully created.")."</div><br /><br />\n";
452
453 // create the survey directory where the uploaded files can be saved
454 if ($createsurveydirectory)
455 if (!file_exists($uploaddir."/surveys/" . $postsid . "/files"))
456 {
457 if (!(mkdir($uploaddir."/surveys/" . $postsid . "/files", 0777, true)))
458 {
459 $activateoutput .= "<div class='warningheader'>".
460 $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>";
461
462 }
463 else
464 {
465 file_put_contents($uploaddir."/surveys/" . $postsid . "/files/index.html",'<html><head></head><body></body></html>');
466 }
467 }
468
469 $acquery = "UPDATE {$dbprefix}surveys SET active='Y' WHERE sid=".$surveyid;
470 $acresult = $connect->Execute($acquery);
471
472 if (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE")
473 {
474 $activateoutput .= $clang->gT("This survey allows public registration. A token table must also be created.")."<br /><br />\n";
475 $activateoutput .= "<input type='submit' value='".$clang->gT("Initialise tokens")."' onclick=\"".get2post("$scriptname?action=tokens&amp;sid={$postsid}&amp;createtable=Y")."\" />\n";
476 }
477 else
478 {
479 $activateoutput .= $clang->gT("This survey is now active, and responses can be recorded.")."<br /><br />\n";
480 $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";
481 $activateoutput .= "<input type='submit' value='".$clang->gT("Switch to closed-access mode")."' onclick=\"".get2post("$scriptname?action=tokens&amp;sid={$postsid}&amp;createtable=Y")."\" />\n";
482 $activateoutput .= "<input type='submit' value='".$clang->gT("No, thanks.")."' onclick=\"".get2post("$scriptname?sid={$postsid}")."\" />\n";
483 }
484 $activateoutput .= "</div><br />&nbsp;\n";
485 $lsrcOutput = true;
486 }
487
488 if($scriptname=='lsrc')
489 {
490 if($lsrcOutput==true)
491 return true;
492 else
493 return $activateoutput;
494 }
495 else
496 {
497 return $activateoutput;
498 }
499 }
500
501 function mssql_drop_constraint($fieldname, $tablename)
502 {
503 global $dbprefix, $connect, $modifyoutput;
504 // find out the name of the default constraint
505 // Did I already mention that this is the most suckiest thing I have ever seen in MSSQL database?
506 $dfquery ="SELECT c_obj.name AS constraint_name
507 FROM sys.sysobjects AS c_obj INNER JOIN
508 sys.sysobjects AS t_obj ON c_obj.parent_obj = t_obj.id INNER JOIN
509 sys.sysconstraints AS con ON c_obj.id = con.constid INNER JOIN
510 sys.syscolumns AS col ON t_obj.id = col.id AND con.colid = col.colid
511 WHERE (c_obj.xtype = 'D') AND (col.name = '$fieldname') AND (t_obj.name='{$dbprefix}{$tablename}')";
512 $defaultname=$connect->GetRow($dfquery);
513 if ($defaultname!=false)
514 {
515 modify_database("","ALTER TABLE [prefix_$tablename] DROP CONSTRAINT {$defaultname[0]}"); echo $modifyoutput; flush();
516 }
517 }
518
519
520 function mssql_drop_primary_index($tablename)
521 {
522 global $dbprefix, $connect, $modifyoutput;
523 // find out the constraint name of the old primary key
524 $pkquery = "SELECT CONSTRAINT_NAME "
525 ."FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS "
526 ."WHERE (TABLE_NAME = '{$dbprefix}{$tablename}') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')";
527
528 $primarykey=$connect->GetOne($pkquery);
529 if ($primarykey!=false)
530 {
531 modify_database("","ALTER TABLE [prefix_{$tablename}] DROP CONSTRAINT {$primarykey}"); echo $modifyoutput; flush();
532 }
533 }
Something went wrong with that request. Please try again.