diff --git a/admin/database.php b/admin/database.php index a90a19f3518..4f0a8d1de9a 100644 --- a/admin/database.php +++ b/admin/database.php @@ -131,26 +131,43 @@ elseif ($action == "updatequestion") { + $cqquery = "SELECT type FROM questions WHERE qid={$_POST['qid']}"; + $cqresult=mysql_query($cqquery) or die ("Couldn't get question type to check for change
$cqquery
".mysql_error()); + while ($cqr=mysql_fetch_array($cqresult)) {$oldtype=$cqr['type'];} + if ($oldtype != $_POST['type']) + { + //Make sure there are no conditions based on this question, since we are changing the type + $ccquery = "SELECT * FROM conditions WHERE cqid={$_POST['qid']}"; + $ccresult = mysql_query($ccquery) or die ("Couldn't get list of cqids for this question
$ccquery
".mysql_error()); + $cccount=mysql_num_rows($ccresult); + while ($ccr=mysql_fetch_array($ccresult)) {$qidarray[]=$ccr['qid'];} + if ($qidarray) {$qidlist=implode(", ", $qidarray);} + } if (get_magic_quotes_gpc() == "0") { $_POST['title'] = addcslashes($_POST['title'], "'"); $_POST['question'] = addcslashes($_POST['question'], "'"); $_POST['help'] = addcslashes($_POST['help'], "'"); } - $uqquery = "UPDATE questions SET type='{$_POST['type']}', title='{$_POST['title']}', " - . "question='{$_POST['question']}', help='{$_POST['help']}', gid='{$_POST['gid']}', " - . "other='{$_POST['other']}', mandatory='{$_POST['mandatory']}' " - . "WHERE sid={$_POST['sid']} AND qid={$_POST['qid']}"; - //echo $uqquery; - $uqresult = mysql_query($uqquery); - if ($uqresult) - { - //echo "\n"; + if ($cccount) + { + echo "\n"; } else { - echo "\n"; - //echo "$uqquery | ".mysql_error(); + $uqquery = "UPDATE questions SET type='{$_POST['type']}', title='{$_POST['title']}', " + . "question='{$_POST['question']}', help='{$_POST['help']}', gid='{$_POST['gid']}', " + . "other='{$_POST['other']}', mandatory='{$_POST['mandatory']}' " + . "WHERE sid={$_POST['sid']} AND qid={$_POST['qid']}"; + //echo $uqquery; + $uqresult = mysql_query($uqquery); + if ($uqresult) + { + } + else + { + echo "\n"; + } } }