. */ include("./include/include.php"); admin_header(); if( !in_array("application_setup_extra_q_view", $_SESSION['sess_functions']) ) { echoln("You are not authorized to see this page."); }else { echoln("

Application extra questions setup

"); $questionsAnswered = false; $query = "SELECT COUNT(*) AS `count` FROM `appl_extraanswers`"; if( @mysql_num_rows( $res = doquery($query))==1 ) { $row = mysql_fetch_assoc($res); $questionsAnswered = $row['count'] > 0; } $error = false; if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && isset($_REQUEST['new']) ) { ########### ### New ### ########### $data['id'] = 0; $data['question'] = ""; $data['maxlength'] = 100; } if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && (isset($_REQUEST['edit']) || isset($_REQUEST['delete']) || isset($_REQUEST['up']) || isset($_REQUEST['down'])) ) { ################# ### Load Data ### ################# $query = "SELECT `id`, `question`, `maxlength`, `order` FROM `appl_extraquestions` WHERE `id`=".addslashes(get_int('id')); if( @mysql_num_rows( $res=doquery($query) )==1 ) { // Ok, load data $data = mysql_fetch_assoc($res); }else { // Query failed echoln("

Error: unable to load the question. Please try again later.

"); $error = true; } } if( !$questionsAnswered && in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && isset($_REQUEST['delete']) && !$error ) { ############## ### DELETE ### ############## if( isset($_GET['confirm']) ) { // Delete this user $query = "DELETE FROM `appl_extraquestions` WHERE `id`=".addslashes($data['id']); if( doquery($query) ) { // Successfull echoln("Successfully deleted '".$data['question']."'.

"); $query = "SELECT `id` FROM `appl_extraquestions` ORDER BY `order`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $order = 1; while( $row = mysql_fetch_assoc($res) ) { $query = "UPDATE `appl_extraquestions` SET `order`=" . addslashes($order++) . " WHERE `id`=" . addslashes($row['id']); doquery($query); } } }else { // Error echoln("Unable to delete question. Please try again.

"); } unset($_REQUEST['delete']); }else { // Ask for confirmation echoln("Are you sure you want to delete '".$data['question']."'?"); echoln("

Yes  "); echoln("No

"); } } if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && isset($_REQUEST['save']) && !$error ) { ################### ### ERROR CHECK ### ################### $errors = ""; $errorFields = array(); // Check for errors before saving $data['id'] = get_int('id'); //Question $data['question'] = $_POST['question']; if( strlen($data['question'])<3 || strlen($data['question'])>255 ) { $errors .= "
  • The question must be maximum 255 characters.
  • "; $error = true; } //Access $data['maxlength'] = get_int('maxlength'); if( $data['maxlength']<1 || $data['maxlength']>4000 ) { $errors .= "
  • The maximum length must be between 1 and 4000.
  • "; $error = true; } //Order if( $data['id']<1 ) { $query = "SELECT MAX(`order`) + 1 AS `order` FROM `appl_extraquestions`"; if( @mysql_num_rows( $res=doquery($query) )==1 ) { $orderResult = mysql_fetch_assoc($res); if( $orderResult['order']==NULL ) { $data['order'] = 1; }else { $data['order'] = $orderResult['order']; } } } if( $errors!="" ) { echoln(""); } if( !$error ) { ################# ### SAVE DATA ### ################# if( $data['id']>0 ) { // Edited entry, update $query = "UPDATE `appl_extraquestions` SET `question`='".addslashes($data['question'])."', `maxlength`=".addslashes($data['maxlength'])." "; $query.= "WHERE `id`=".addslashes($data['id']); if( doquery($query) ) { // Saving succeeded echoln("Question saved successfully.

    "); }else { // Saving failed echoln("Saving of question failed. Please try again.

    "); } }else { // New entry, insert $query = "INSERT INTO `appl_extraquestions` (`question`, `maxlength`, `order`) "; $query.= "VALUES ('".addslashes($data['question'])."', ".addslashes($data['maxlength']).", ".addslashes($data['order']).")"; if( doquery($query) ) { $data['id'] = mysql_insert_id(); // Saving succeeded echoln("New question saved successfully.

    "); }else { // Saving failed echoln("Saving of new question failed. Please try again.

    "); } } }else { // Error found, reshow form $error = false; if( $data['id']>0 ) { $_REQUEST['edit'] = true; // id avail, so this was an edit }else { $_REQUEST['new'] = true; // id unavailable, so this was a new entry } } } if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && isset($_REQUEST['up']) && !$error ) { $query = "SELECT `id` FROM `appl_extraquestions` WHERE `order` = " . addslashes($data['order'] - 1); if( @mysql_num_rows( $res = doquery($query) ) ) { $row = mysql_fetch_assoc($res); $otherId = $row['id']; $query1 = "UPDATE `appl_extraquestions` SET `order` = " . addslashes($data['order']) . " WHERE `id` = " . addslashes($otherId); $query2 = "UPDATE `appl_extraquestions` SET `order` = " . addslashes($data['order'] - 1) . " WHERE `id` = " . addslashes($data['id']); if( doquery($query1) && doquery($query2) ) { echoln("Question moved up successfully.

    "); }else { echoln("Moving up of question failed. Please try again.

    "); } }else { echoln("Moving up of question failed, there is no question above.

    "); } } if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && isset($_REQUEST['down']) && !$error ) { $query = "SELECT `id` FROM `appl_extraquestions` WHERE `order` = " . addslashes($data['order'] + 1); if( @mysql_num_rows( $res = doquery($query) ) ) { $row = mysql_fetch_assoc($res); $otherId = $row['id']; $query1 = "UPDATE `appl_extraquestions` SET `order` = " . addslashes($data['order']) . " WHERE `id` = " . addslashes($otherId); $query2 = "UPDATE `appl_extraquestions` SET `order` = " . addslashes($data['order'] + 1) . " WHERE `id` = " . addslashes($data['id']); if( doquery($query1) && doquery($query2) ) { echoln("Question moved down successfully.

    "); }else { echoln("Moving down of question failed. Please try again.

    "); } }else { echoln("Moving down of question failed, there is no question below.

    "); } } if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) && (isset($_REQUEST['new']) || isset($_REQUEST['edit'])) && !$error ) { ################# ### Show form ### ################# echoln("Back

    "); echoln("

    "); echoln(" "); echoln(" "); echoln(" "); echoln(" "); echoln("
    Question:
    Maximum length:

    "); ///// Show buttons ///// if( isset($_REQUEST['new']) ) { echoln("   "); echoln(" "); }else { echoln("   "); echoln(" "); } echoln("

    "); echoln(" "); }elseif( !isset($_REQUEST['delete']) || (isset($_REQUEST['delete']) && isset($_GET['confirm'])) ) { ################# ### Show list ### ################# if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) ) { echoln("Add new question"); } $query="SELECT `id`, `question`, `maxlength`, `order` FROM `appl_extraquestions` ORDER BY `order`"; if( @mysql_num_rows( $res=doquery($query) )>0 ) { echoln("

    "); echoln(" "); echoln(" "); echoln(" "); if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) ) { echoln(" "); } echoln(" "); $r=0; while( $row=mysql_fetch_array($res) ) { echoln(" "); echoln(" "); echoln(" "); if( in_array("application_setup_extra_q_edit", $_SESSION['sess_functions']) ) { echoln(" "); } echoln(" "); } echoln("
    QuestionMaximum length 
    ".$row['question']."".$row['maxlength'].""); if( $row['order'] > 1 ) { echoln(" up  "); } if( $row['order'] < mysql_num_rows($res) ) { echoln(" down  "); } echoln(" edit  "); if( !$questionsAnswered ) { echoln(" delete"); } echoln("
    "); } } } admin_footer(); ?>