/**
  * Handles the sections for 
  * both quizzes and surveys.
  * 
  * @since 2.0
  */
 public function _doSections()
 {
     if ($_SERVER['REQUEST_METHOD'] == "POST") {
         $nameNeeded = array();
         for ($row = 0; $row < intval($_POST['row_count']); $row++) {
             if (!isset($_POST['section_name'][$row]) || $_POST['section_name'][$row] == "") {
                 $nameNeeded[] = $row;
                 continue;
             }
             $sectionName = wp_kses_stripslashes($_POST['section_name'][$row]);
             if (!isset($_POST['number'][$row]) || $_POST['number'][$row] == "") {
                 $_POST['number'][$row] = 0;
             }
             if (!isset($_POST['sectionid'][$row]) || empty($_POST['sectionid'][$row])) {
                 $difficulty = isset($_POST['difficulty'][$row]) ? $_POST['difficulty'][$row] : false;
                 Wpsqt_System::insertSection($_GET['id'], $sectionName, $_POST['number'][$row], $_POST['order'][$row], $difficulty);
                 continue;
             }
             if (isset($_POST['delete'][$row]) && !empty($_POST['delete'][$row])) {
                 Wpsqt_System::deleteSection($_POST['sectionid'][$row]);
             } else {
                 $difficulty = isset($_POST['difficulty'][$row]) ? $_POST['difficulty'][$row] : false;
                 Wpsqt_System::updateSection($_POST['sectionid'][$row], $sectionName, $_POST['number'][$row], $_POST['order'][$row], $difficulty);
             }
         }
         $this->_pageVars['successMessage'] = "Sections updated";
     }
     $validData = Wpsqt_System::fetchSections($_GET['id']);
     if (!empty($validData)) {
         $this->_pageVars['validData'] = $validData;
     }
 }
 /**
  * Tests to see if the full lifecycle of sections is 
  * working properly. Starts off with creating a 
  * quiz since we'll need the quiz id then it
  * inserts the section then checks to see if
  * actually exists in the database. Then moves
  * on to updating the sections.
  * 
  * @since 2.0
  */
 public function testSectionsFullLifecycle()
 {
     global $wpdb;
     $this->dummyQuizId = Wpsqt_System::insertItemDetails($this->dummyQuizDetails, 'quiz');
     Wpsqt_System::insertSection($this->dummyQuizId, 'Section Name', '1', 'random', 'mixed');
     $sections = $wpdb->get_results("SELECT * FROM `" . WPSQT_TABLE_SECTIONS . "` WHERE item_id = " . $this->dummyQuizId, ARRAY_A);
     // Should be only one since we have just created
     // the quiz and only inserted one section.
     $this->assertEquals(sizeof($sections), 1, "Sections count doesn't match after insertion");
     $this->assertEquals("Section Name", $sections[0]['name'], "The sections names don't match after insertion");
     Wpsqt_System::updateSection($sections[0]['id'], "Update Section", 0, "random", "mixed");
     $sections = $wpdb->get_results("SELECT * FROM `" . WPSQT_TABLE_SECTIONS . "` WHERE item_id = " . $this->dummyQuizId, ARRAY_A);
     $this->assertEquals(sizeof($sections), 1, "Sections count doesn't match after update");
     $this->assertEquals("Update Section", $sections[0]['name'], "The sections names don't match after update");
     Wpsqt_System::deleteSection($sections[0]['id']);
     $sections = $wpdb->get_results("SELECT * FROM `" . WPSQT_TABLE_SECTIONS . "` WHERE item_id = " . $this->dummyQuizId, ARRAY_A);
     $this->assertEquals(sizeof($sections), 0, "Sections count doesn't match after deletion");
 }