0)
array_multisort($query_new_ord,SORT_ASC,$query_old_ord,SORT_ASC,$query_qid,SORT_ASC,$query_new_rep,SORT_ASC,$query_old_rep,SORT_ASC);
//updating each record individually
for($num = 1 ; $num <= sizeof($query_qid);$num++) {
//perform the queries only if the order has changed
if($query_old_ord[$num-1] != $num) {
//make sure that we are not swapping questions with identical question id's (this causes a problem when swapping question orders)
$query_test_dup_quest = sprintf("SELECT question_id FROM form_x_question WHERE form_id=%d AND form_question_num=%d",$_POST['form_id'],$num);
mysql_select_db($database_researcher, $researcher);
$result_test_dup_quest= mysql_query($query_test_dup_quest,$researcher) or die(mysql_error());
if($result_test_dup_quest != NULL)
$row_test_dup_quest = mysql_fetch_assoc($result_test_dup_quest);
//only update the form question order if it doesn't have the same question_id as the one we are swapping with
if($row_test_dup_quest['question_id'] != $query_qid[$num-1]) {
//printf("updating
");
//WHERE clause checks to see if the form_question_num AND the question_id match.
//This is an issue since we are iterating over each row that is updating (updating sets of values at the same time based on differing WHERE clauses is apparently not allowed
$update_query = sprintf("UPDATE form_x_question SET form_question_num=%d WHERE form_id=%d AND form_question_num=%d AND question_id=%d",$num,$_POST['form_id'],$query_old_ord[$num-1],$query_qid[$num-1]);
mysql_select_db($database_researcher, $researcher);
mysql_query($update_query,$researcher);
} //if
} //if ($query_old_ord[$num-1] != $num)
//see if the number of repeats have changed
if($query_new_rep[$num-1] < $query_old_rep[$num-1]) {
$delete_rep_query = sprintf("DELETE FROM form_x_question WHERE form_id=%d AND form_question_num=%d AND question_iteration > %d",$_POST['form_id'],$num,$query_new_rep[$num-1]);
mysql_select_db($database_researcher, $researcher);
mysql_query($delete_rep_query,$researcher);
} elseif($query_new_rep[$num-1] > $query_old_rep[$num-1]) {
for($iter = $query_old_rep[$num-1]+1;$iter <= $query_new_rep[$num-1];$iter++) {
$add_rep_query = sprintf("INSERT INTO form_x_question (form_id,question_id,question_iteration,form_question_num) VALUES(%d,%d,%d,%d)",$_POST['form_id'],$query_qid[$num-1],$iter,$num);
mysql_select_db($database_researcher, $researcher);
mysql_query($add_rep_query,$researcher);
}
} //elsif newrep > oldrep
} //for $num ...
} //if (form was posted)
if (!isset($_SESSION['editor_form_id'])) {
$_SESSION['editor_form_id'] = 1;
}
mysql_select_db($database_researcher, $researcher);
$query_form_info = sprintf("SELECT * FROM form WHERE form_id = %d",$_SESSION['editor_form_id']);
$form_info = mysql_query($query_form_info, $researcher) or die(mysql_error());
$row_form_info = mysql_fetch_assoc($form_info);
$totalRows_form_info = mysql_num_rows($form_info);
mysql_select_db($database_researcher, $researcher);
$query_form_questions = sprintf("SELECT question.question_id, question.question_text, question.heading_format, form_x_question.form_question_num, MAX(form_x_question.question_iteration) AS total_iterations FROM form_x_question,question WHERE form_x_question.form_id=%s AND question.question_id=form_x_question.question_id GROUP BY form_x_question.form_question_num ORDER BY form_x_question.form_question_num",$_SESSION['editor_form_id']);
$form_questions = mysql_query($query_form_questions, $researcher) or die(mysql_error());
$row_form_questions = mysql_fetch_assoc($form_questions);
$totalRows_form_questions = mysql_num_rows($form_questions);
//obtain the complete list of questions
mysql_select_db($database_researcher, $researcher);
$query_all_questions = "SELECT * FROM question order by question_id";
$all_questions = mysql_query($query_all_questions, $researcher) or die(mysql_error());
$row_all_questions = mysql_fetch_assoc($all_questions);
$totalRows_all_questions = mysql_num_rows($all_questions);
do {
$form_question_num[] = $row_form_questions['form_question_num'];
$form_question_text[] = $row_form_questions['question_text'];
$form_question_id[] = $row_form_questions['question_id'];
$form_question_fmt[] = $row_form_questions['heading_format'];
$form_question_total_iterations[] = $row_form_questions['total_iterations'];
} while ($row_form_questions = mysql_fetch_assoc($form_questions));
?>
Form Editor |
if ($totalRows_form_info != 0) { ?>
} //if (form was selected or added) else { //else (a form has not been selected) printf("