function latexAppendQuestion($name, $desc, $type, $answer) { $typeArray = getTypeArray($type); $question_string = ""; if ($typeArray['type'] == "text") { if ($name != "") { $question_string .= '\\textbf{' . latexSpecialChars($name) . '}'; //add main in bold } if ($desc != "") { if ($name != "") { $question_string .= '\\newline'; } $question_string .= '\\emph{' . latexSpecialChars($desc) . '}'; //add description in italics } $question_string .= '\\newline\\newline'; return $question_string; } else { if ($typeArray['type'] == "latex") { $question_string .= $desc; return $question_string; } else { if ($typeArray['type'] == "code") { $question_string .= '\\text{' . get_html_to_latex(page_convert($desc)) . '}'; return $question_string; } else { if ($typeArray['type'] == "repeat") { $num = $typeArray['num']; $subtype_array = explode("|", $typeArray['subtype']); $desc_array = explode("|", $desc); $name_array = explode("|", $name); if ($answer != '') { $answer_array = toArray($answer, "|", "="); } else { $answer_array = array_fill(0, count($name_array) * $num, ''); } //find minimum length, which will be the number to repeat for $min_length = min(count($subtype_array), count($desc_array), count($name_array)); for ($i = 0; $i < $min_length * $num; $i++) { $index = $i % $min_length; $n = intval($i / $min_length); $thisName = getRepeatThisValue($name_array, $index, $n); $thisDesc = getRepeatThisValue($desc_array, $index, $n); $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n)); $question_string .= latexAppendQuestion($thisName, $thisDesc, $thisType, $answer_array[$i]); } } else { if ($name != "") { $question_string .= '\\textbf{' . latexSpecialChars($name) . '}'; //add question in bold } //add description (in bold) for essays and short answer if (($typeArray['type'] == "essay" || $typeArray['type'] == "short") && $desc != "") { if ($name != "") { $question_string .= '\\newline'; } $question_string .= '\\emph{' . latexSpecialChars($desc) . '}'; //add description in italics } //add a separator depending on main type of the question if ($typeArray['type'] == "essay") { $question_string .= "\n\n"; } if ($typeArray['type'] == "select" && $typeArray['method'] != "dropdown") { //in this case, we add tick marks and check the correct ones $choices = explode(";", $desc); //get answer as array in case we're using multiple selection $config = $GLOBALS['config']; $answerArray = explode($config['form_array_delimiter'], $answer); //this is used to indent the answer choices $question_string .= "\n\\begin{quote}\n"; //output each choice with check box before it on a separate line in the quote for ($i = 0; $i < count($choices); $i++) { $choice = $choices[$i]; if ($i != 0) { $question_string .= "\\\\\n "; } if (in_array($choice, $answerArray)) { $question_string .= '\\xbox'; } else { $question_string .= '\\tickbox'; } $question_string .= " \\hspace{4pt} " . latexSpecialChars($choice); } $question_string .= "\\end{quote}"; } else { //append the response if ($typeArray['type'] == "essay") { if ($answer != "") { $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . '\\end{quote}'; } else { $question_string .= '\\vspace{5ex}'; } } else { if ($answer != "") { $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . ' \\end{quote}'; } else { $question_string .= '\\vspace{1ex}'; } } } $question_string .= "\n\n"; } } } } return $question_string; }
function responseStatistics($club_id, $include_short, $limit) { global $config; $club_id = escape($club_id); //first, get a map of variables ids that either type=short or type=select $result = mysql_query("SELECT id, varname, vartype FROM supplements WHERE club_id = '{$club_id}' ORDER BY orderId"); $responseMap = array(); while ($row = mysql_fetch_array($result)) { $typeArray = getTypeArray($row['vartype']); if ($typeArray['type'] == "short" && $include_short || $typeArray['type'] == "select") { $responseMap[$row['id']] = array($row['varname'], array()); } } //now get the user responses $result = mysql_query("SELECT answers.var_id, answers.val FROM answers, applications WHERE answers.application_id = applications.id AND applications.club_id = '{$club_id}' AND applications.submitted = ''"); while ($row = mysql_fetch_array($result)) { if (array_key_exists($row[0], $responseMap)) { //this is true unless supplements desynchronize //response might have multiple parts with form_array_delimiter $responseArray = explode($config['form_array_delimiter'], $row[1]); foreach ($responseArray as $response) { if (!array_key_exists($response, $responseMap[$row[0]][1])) { //if we haven't encountered this response yet for this question $responseMap[$row[0]][1][$response] = 0; } else { if ($responseMap[$row[0]][1][$response] >= $limit) { //if we're going to be displaying too many options continue; } } $responseMap[$row[0]][1][$response]++; } } } return $responseMap; }
function getAnsArray($q) { $x = preg_grep_keys("/a{$q}\\_\\d/", $_POST); foreach ($x as $key => $value) { $x[$key] = addslashes($value); } return $x; } function getTypeArray($q) { $x = preg_grep_keys("/t{$q}\\_\\d/", $_POST); unset($x["t" . $q . "_0"]); return $x; } for ($i = 1; $i <= $_POST['num_q']; $i++) { $survey[] = ['question' => addslashes($_POST['q' . $i]), 'type' => $_POST['t' . $i . '_0'], 'answer' => getAnsArray($i), 'ans_types' => getTypeArray($i)]; } //Eventually the below code will append statements to an sql query $sql = ["START TRANSACTION;"]; $sql[] = "INSERT INTO `2601166_entity_surveys` (`title`,`open`,`close`) VALUES ('{$survey[0]}',CURDATE(),'{$_POST['close']}');"; $sql[] = "SELECT LAST_INSERT_ID() INTO @CUR_SURVEY_ID;"; for ($i = 1; $i < count($survey); $i++) { $sql[] = "INSERT INTO brandon.2601166_entity_questions (question, q_num, type_id) VALUES ('{$survey[$i]['question']}', '{$i}', '{$survey[$i]['type']}');"; $sql[] = "SELECT LAST_INSERT_ID() INTO @CUR_QUESTION_ID;"; $sql[] = "INSERT INTO brandon.2601166_xref_surveys_questions (survey_id, question_id) VALUES (@CUR_SURVEY_ID, @CUR_QUESTION_ID);"; for ($c = 1; $c <= count($survey[$i]['answer']); $c++) { $sql[] = "INSERT INTO brandon.2601166_entity_answers (answer, a_num, type_id) VALUES ('{$survey[$i]['answer']['a' . $i . '_' . $c]}', '{$c}', '{$survey[$i]['ans_types']['t' . $i . '_' . $c]}');"; $sql[] = "SELECT LAST_INSERT_ID() INTO @CUR_ANSWER_ID;"; $sql[] = "INSERT INTO brandon.2601166_xref_questions_answers (question_id, answer_id) VALUES (@CUR_QUESTION_ID, @CUR_ANSWER_ID);"; } }
function writeField($id, $answer_id, $name, $desc, $type, $answer = "", $mutable = true, $repeat_id = 256) { //see if style provides this function $styleFunction = style_function("writeField"); if ($styleFunction !== FALSE) { return $styleFunction($str); } $mutableString = ""; if (!$mutable) { $mutableString = "readonly=\"readonly\""; } //trim the string fields $name = trim($name); $desc = trim($desc); $type = trim($type); $fieldName = "a_" . $id . "_" . $answer_id . "_" . $repeat_id; $type_array = getTypeArray($type); $maxLength = $type_array['length']; $lengthRemaining = $maxLength - strlen($answer); if ($type_array['type'] == "essay") { $height = ""; if ($type_array['size'] == "large") { $height = "height:200px"; } else { if ($type_array['size'] == "huge") { $height = "height:400px"; } } echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<textarea "; if ($type_array['showchars']) { echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; } echo "name=\"{$fieldName}\" {$mutableString} style=\"resize:vertical;{$height}\" />" . htmlspecialchars($answer) . "</textarea>"; echo "<p class=\"formHint\">{$desc}"; if ($type_array['showchars']) { echo "<br />Characters Remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />"; } echo "</p>"; } else { if ($type_array['type'] == "short") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<input "; if ($type_array['showchars']) { echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" maxlength=\"{$maxLength}\" "; } echo "type=\"text\" name=\"{$fieldName}\" {$mutableString} value=\"" . htmlspecialchars($answer) . "\" /> "; echo "<p class=\"formHint\">{$desc}"; if ($type_array['showchars']) { echo "<br />Characters remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />"; } echo "</p>"; } else { if ($type_array['type'] == "select") { echo '<p class="label">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</p>"; $choices = explode(";", $desc); $tname = "checkbox"; if ($type_array['method'] == "multiple") { $tname = "checkbox"; $fieldName .= "[]"; //for multiple selection, PHP needs to know with an [] at the end of field name echo "<ul>"; } else { if ($type_array['method'] == "single") { $tname = "radio"; echo "<ul>"; } else { if ($type_array['method'] == "dropdown") { $tname = false; echo "<select name=\"{$fieldName}\"{$mutableString}>"; } } } //for checkboxes, answer will be an array separated by $config['form_array_delimiter'] // we just explode it anyway for convenience and get one element if it's single selection $config = $GLOBALS['config']; $answerArray = explode($config['form_array_delimiter'], $answer); foreach ($choices as $choice) { $selectedString = ""; if (in_array($choice, $answerArray)) { if ($tname === false) { $selectedString = " selected"; } else { $selectedString = " checked"; } } if ($tname == false) { echo "<option{$selectedString} value=\"{$choice}\">{$choice}</option>"; } else { echo "<li><label for=\"\"><input{$selectedString} type=\"{$tname}\" name=\"{$fieldName}\"{$mutableString} value=\"{$choice}\" /> {$choice}</label></li>"; } } if ($tname == false) { //select echo "</select>"; } else { echo "</ul>"; } //need to add some sort of hint factor for selects (change hint so that it is a type variable) } else { if ($type_array['type'] == "text") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>{$desc}"; } else { if ($type_array['type'] == "repeat") { $num = $type_array['num']; $subtype_array = explode("|", $type_array['subtype']); $desc_array = explode("|", $desc); $name_array = explode("|", $name); if ($answer != '') { $answer_array = toArray($answer, "|", "="); } else { $answer_array = array_fill(0, count($name_array) * $num, ''); } //find minimum length, which will be the number to repeat for $min_length = min(count($subtype_array), count($desc_array), count($name_array)); for ($i = 0; $i < $min_length * $num; $i++) { $index = $i % $min_length; $n = intval($i / $min_length); $thisName = getRepeatThisValue($name_array, $index, $n); $thisDesc = getRepeatThisValue($desc_array, $index, $n); $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n)); if ($type_array['globalstatus'] == 1) { $thisType .= "; status:optional"; } writeField($id, $answer_id, $thisName, $thisDesc, $thisType, $answer_array[$i], $mutable, $i); } } else { if ($type_array['type'] == "code") { echo page_convert($desc); } else { if ($type_array['type'] == "upload") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<input type=\"file\" name=\"{$fieldName}\" {$mutableString} />"; echo "<p class=\"formHint\">{$desc}<br />Currently Uploaded: "; if ($answer != "") { $answer_parts = explode(":", $answer, 3); $file_id = $answer_parts[1]; $file_name = $answer_parts[2]; echo "<a href=\"../download.php?file={$file_id}&filename={$file_name}\">View Here</a>"; } else { echo "None"; } echo '</p>'; } } } } } } } }
function customSubmit($instance_id, $sectionheader = "Custom", $extrainfo = "Custom") { $instance_id = escape($instance_id); //make sure all fields have been filled completely $result = mysql_query("SELECT custom.vartype FROM custom_response LEFT JOIN custom ON custom_response.var_id = custom.id WHERE custom_response.instance_id='{$instance_id}' AND custom_response.val = ''"); while ($row = mysql_fetch_array($result)) { $typeArray = getTypeArray($row[0]); if ($typeArray['status'] == "required") { return -2; } } //create the PDF $result = mysql_query("SELECT custom.varname, custom.vardesc, custom.vartype, custom_response.val FROM custom_response LEFT JOIN custom ON custom_response.var_id = custom.id WHERE custom_response.instance_id = '{$instance_id}' ORDER BY custom.orderId"); $createResult = generatePDFByResult($result, "../submit/", $sectionheader, $extrainfo); if (!$createResult[0]) { //if error during PDF generation return -1; } $filename = $createResult[1]; return $filename; }
function checkCompletedApplication($user_id, $club_id, $application_id) { $user_id = escape($user_id); $club_id = escape($club_id); $application_id = escape($application_id); //verify application belongs to user and hasn't been submitted $checkResult = checkApplication($user_id, $application_id, true); if ($checkResult[0] !== 0) { return array("This application cannot be submitted at this time (has not been started or not in available window)."); } if ($club_id != $checkResult[1]) { return array("Club ID is incorrect!"); } $warnings = array(); if ($club_id == 0) { $result = mysql_query("SELECT baseapp.varname, baseapp.vartype, basecat.name FROM answers, baseapp, basecat WHERE answers.application_id = '{$application_id}' AND answers.var_id = baseapp.id AND answers.val = '' AND basecat.id = baseapp.category ORDER by basecat.orderId"); $category = ""; while ($row = mysql_fetch_array($result)) { $typeArray = getTypeArray($row[1]); if ($typeArray['status'] == "required") { if ($category != $row[2]) { array_push($warnings, "<b>" . $row[2] . "</b>"); $category = $row[2]; } array_push($warnings, "<ul class=\"errorlist\"><li><p>" . $row[0] . "</p></li></ul>"); } } } else { $result = mysql_query("SELECT supplements.varname, supplements.vartype FROM answers, supplements WHERE answers.application_id='{$application_id}' AND answers.var_id = supplements.id AND answers.val = ''"); while ($row = mysql_fetch_array($result)) { $typeArray = getTypeArray($row[1]); if ($typeArray['status'] == "required") { array_push($warnings, $row[0]); } } } return $warnings; }