function pf_dosurvey() { global $wpdb; global $table_prefix; if (!isset($wpdb->pf_groups)) { $wpdb->pf_groups = $table_prefix . 'pf_groups'; } $message = ""; //gets current group $current_group = $_GET['groupID']; //test to see if it is set. if not report error. if so, continue echo "current group is:" . $current_group; //gets selected student $fromstudent = $_POST['studentID']; //test to see if student is set. if not go to pick student from list. if so, mkae form for that student. //make form for student //gets survey info for current group $surveyinfo = pf_getsurveyinfo($current_group); //if survey disabled, report error if ($surveyinfo->survey_disable == 'true') { $message .= "Error: Survey Disabled<br>"; } //figure out how many columns the table should have (depends on survey settings) $columns = 1; if ($surveyinfo->survey_askscore == 'true') { $columns++; } if ($surveyinfo->survey_askcomment == 'true') { $columns++; } if ($columns == 1) { $message .= "Error: No questions are selected<br>"; } //make scores array $scores = explode(',', trim($surveyinfo->survey_scores)); echo "<table>"; echo "<form name='feedback' method='POST' action='' accept-charset='UTF-8'>"; echo "<tr>"; echo " <td colspan=" . $columns . ">" . $surveyinfo->survey_prompt . "</td>"; echo "</tr>"; // do the following row for each student echo "<tr>\n <td>Feedback for:<br>TOSTUDENT NAME</td>"; if ($surveyinfo->survey_askscore == 'true') { echo "<td>Score:<br><select name='score_TOSTUDENTID'>"; foreach ($scores as $score) { echo "<option value='" . $score . "'>" . $score . "</option>"; } echo "</select></td>"; } if ($surveyinfo->survey_askcomment == 'true') { echo "<td>Comment:<br>"; $id = 'prompt'; $settings = array('textarea_rows' => 4, 'teeny' => true); wp_editor('', $id, $settings); echo "</td>"; } echo "</tr>"; // end of do following for each student $columns--; echo "<tr>\n <td>Enter your password</td>\n <td colspan=" . $columns . "><input type='password' size='20' maxlength='20' name='password'></td>\n </tr>"; $columns++; echo "<tr>\n <td colspan=" . $columns . ">"; echo "<font color=red>" . $message . "</font>"; echo "<input type='hidden' name='WhichForm' value='feedback'>\n <input type='submit' name='Submit' value='Submit my Peer Feedback'> \n </td>\n </tr>\n \n </form>\n </table>"; }
function pf_survey() { global $wpdb; global $table_prefix; if (!isset($wpdb->pf_groups)) { $wpdb->pf_groups = $table_prefix . 'pf_groups'; } //gets current user info global $current_user; get_currentuserinfo(); //gets current group $current_group = get_user_meta($current_user->ID, 'pf_currentgroup', true); $message = ""; //edit survey if (isset($_POST['Submit']) && $_POST['WhichForm'] == 'editsurvey') { if ($_POST['askscore'] != 'true') { $_POST['askscore'] = 'false'; } if ($_POST['askcomment'] != 'true') { $_POST['askcomment'] = 'false'; } if ($_POST['disable'] != 'true') { $_POST['disable'] = 'false'; } $validator = new FormValidator(); $validator->addValidation("prompt", "req", "Error: Survey prompt required."); $validator->addValidation("scores", "req", "Error: Possible scores required."); $validator->addValidation("scores", "maxlen=30", "Error: Possible scores required."); $validator->addValidation("scores", "regexp=/^(([0-9a-zA-Z .]*)([,][0-9a-zA-Z .]*)*)\$/", "Error: Possible scores must be letters and numbers separated by commas."); if ($validator->ValidateForm()) { //update db $wpdb->query($wpdb->prepare("\n UPDATE {$wpdb->pf_groups} \n SET \n survey_prompt='" . $_POST['prompt'] . "',\n survey_askscore='" . $_POST['askscore'] . "',\n survey_scores='" . $_POST['scores'] . "',\n survey_askcomment='" . $_POST['askcomment'] . "',\n survey_disable='" . $_POST['disable'] . "'\n WHERE ID=" . $current_group)); $message .= "Changes Saved"; } else { $error_hash = $validator->GetErrors(); foreach ($error_hash as $inpname => $inp_err) { $message .= "{$inp_err}<br>\n"; } } } //gets survey info for current group $surveyinfo = pf_getsurveyinfo($current_group); echo "<font color=red>" . $message . "</font>"; echo "<table>"; echo "<form name='editsurvey' method='POST' action='' accept-charset='UTF-8'>"; echo "<tr>"; echo " <td>Survey Prompt</td>"; echo " <td>"; $content = $surveyinfo->survey_prompt; $id = 'prompt'; $settings = array('textarea_rows' => 8, 'tinymce' => true); wp_editor($content, $id, $settings); echo " </td>"; echo "</tr>\n \n <tr>\n <td>Ask for score</td>\n <td><input type='checkbox' name='askscore' value='true'"; if ($surveyinfo->survey_askscore == 'true') { echo " checked"; } echo "></td>\n </tr>\n \n <tr>\n <td>Possible scores<br><em>comma separated<br>(eg 4,3,2,1 or A,B,C,D,F)</em></td>\n <td><input type='textbox' size='30' maxlength='30' name='scores' value='" . $surveyinfo->survey_scores . "'></td>\n </tr>\n \n <tr>\n <td>Ask for comments</td>\n <td><input type='checkbox' name='askcomment' value='true'"; if ($surveyinfo->survey_askcomment == 'true') { echo " checked"; } echo "></td>\n </tr>\n \n <tr>\n <td>Disable survey</td>\n <td><input type='checkbox' name='disable' value='true'"; if ($surveyinfo->survey_disable == 'true') { echo " checked"; } echo "></td>\n </tr>\n \n <tr>\n <td><input type='hidden' name='WhichForm' value='editsurvey'>\n <input type='submit' name='Submit' value='Save Changes'> </td>\n <td><b><a href='http://www.peerfeedback.org/?page_id=188&groupID=" . $current_group . "' target='_blank'>Preview Survey</a></b>\n <br><br>\n </td>\n </tr>\n \n <tr>\n <td>Embed this survey in your site<br><em>copy and paste the text</em></td>\n <td><input type='text' size='100' value='<iframe src='http://www.peerfeedback.org/?page_id=188&groupID=" . $current_group . "' width=550 height=500 frameborder=0 marginheight=0 marginwidth=0>Loading...</iframe>'></td>\n </tr>\n \n <tr>\n <td>Link to this survey<br><em>copy and paste the text</em></td>\n <td><input type='text' size='100' value='http://www.peerfeedback.org/?page_id=188&groupID=" . $current_group . "'></td>\n </tr>\n \n </form>\n </table>"; }