/**
  * Perform any extra validation for the license.
  * @param I2CE_Form $form
  */
 public function validate_form_training($form)
 {
     /**
     **Check to ensure that Level and semester are consistency
     **/
     $semester = $form->semester;
     $level = $form->academic_level;
     if ($semester[1] != 2 * $level[1] - 1 and $semester[1] != 2 * $level[1]) {
         $form->setInvalidMessage("academic_level", "Level And Semester Are Not Consistency");
         $form->setInvalidMessage("semester", "Level And Semester Are Not Consistency");
     }
     $parent_form = $form->getParent();
     $exam_types = $form->training_course_exam_type;
     //check to ensure that,each exam type selected has its assessment field
     foreach ($exam_types as $exam_type) {
         $value = $form->{$exam_type}[1];
         if ($value == "") {
             $form->setInvalidMessage($exam_type[1], ucfirst($exam_type[1]) . " Assessment Must Be Filled");
         } elseif (!is_numeric($value) or $value == 0) {
             $form->setInvalidMessage($exam_type[1], ucfirst($exam_type[1]) . " Must Be Numeric And Greater Than 0");
         } else {
             $total_assessment = $value + $total_assessment;
         }
     }
     //ensure that assessment sum up to 100
     if ($total_assessment > 100 or $total_assessment < 100) {
         foreach ($exam_types as $exam_type) {
             $form->setInvalidMessage($exam_type[1], "Assessments Must Sum Up To Hundred");
         }
     }
     //check to ensure that,no assessment is filled without being selected from exam types
     $exam_types = I2CE_FormStorage::listFields("training_course_exam_type", array("id"));
     foreach ($exam_types as $exam_type => $exam_type_array) {
         $exit = false;
         foreach ($form->training_course_exam_type as $form_exam_type) {
             if (in_array($exam_type, $form_exam_type)) {
                 $exit = true;
             }
         }
         if ($exit) {
             continue;
         }
         $value = $form->{$exam_type};
         if ($value != "") {
             $form->setInvalidMessage($exam_type, ucfirst($exam_type) . " Should Not Be Filled As It Is Not Selected From Exam Types");
         }
     }
 }
 /**
  * Ensures that a row exists in the given tablet
  * @param I2CE_Form $form
  * @param string $col
  * @param mixed $parent_col.  If a string it is the parent col to save the parent id in
  */
 protected function ensureFormId($form, $col, $parent_col)
 {
     $table = $this->getTable($form->getName());
     if (!$table) {
         I2CE::raiseError("No table specified for {$form}");
         return '0';
     }
     $id = $form->getId();
     if ($id == '0') {
         $new_id = $this->db->getBeforeID($table, $col, true, true);
         if (I2CE::pearError($new_id, "Cannot get next id")) {
             return '0';
         }
         $stmt = "INSERT INTO  SET `{$col}` = '" . $form->getName() . "|{$id}'";
         if (is_string($parent_col)) {
             $stmt .= ", `{$parent_col}` = '" . $form->getParent() . "'";
         }
         if (I2CE::pearError($this->db->exec($stmt), "Error inserting form " . $form->getName() . ": ")) {
             return '0';
         }
         $new_id = $this->db->getAfterID($new_id, $table, $col);
         $form->setId($new_id);
         $form->setChangeType(I2CE_FormStorage_Mechanism::CHANGE_INITIAL);
         return $new_id;
     } else {
         $stmt = "INSERT IGNORE INTO {$table} SET `{$col}` = '{$id}'";
         if (is_string($parent_col)) {
             $stmt .= ", `{$parent_col}` = '" . $form->getParent() . "'";
         }
         if (I2CE::pearError($this->db->exec($stmt), "Error inserting form " . $form->getName() . ": ")) {
             return '0';
         }
         return $id;
     }
 }