public function postApplication()
 {
     $username = Input::get("username");
     $applicantId = Input::get("applicant_id");
     $orderOfPreference = Input::get("schoolPiority");
     $schoolId = Input::get("schoolId");
     $type = Input::get("type");
     $distance = Input::get("distanceT");
     $medium = '';
     if (Input::get("MediumT") == 0) {
         $medium = 'Sinhala';
     } else {
         $medium = 'Tamil';
     }
     $guardianNic = Input::get("guardianNic");
     $schoolIds = array(Input::get("schoolId1"), Input::get("schoolId2"), Input::get("schoolId3"), Input::get("schoolId4"), Input::get("schoolId5"), Input::get("schoolId6"), Input::get("schoolId7"), Input::get("schoolId8"), Input::get("schoolId9"), Input::get("schoolId10"));
     $yearset = array(Input::get("year1"), Input::get("year2"), Input::get("year3"), Input::get("year4"), Input::get("year5"), Input::get("year6"));
     $divisionSet = array(Input::get("division1"), Input::get("division2"), Input::get("division3"), Input::get("division4"), Input::get("division5"), Input::get("division6"));
     $application = new application();
     $application->setOrderOfPreference($orderOfPreference);
     $application->setType($type);
     $application->setSchool_id($schoolId);
     $application->setDistance($distance);
     $application->setMedium($medium);
     $application->setApplicant_id($applicantId);
     $isStudentApplySchoolFromThisCategory = DBApplicationController::isStudentApplySchoolFromThisCategory($applicantId, $schoolId, $type);
     if ($isStudentApplySchoolFromThisCategory) {
         return "you have allready added  this type of application to this school";
     }
     switch ($type) {
         case 0:
             $resultCD = DBGuardianController::hasCategory1Detail($guardianNic);
             if ($resultCD) {
                 $applicantResult = DBApplicationController::addApplication($application);
                 if ($applicantResult) {
                     return "added successfully";
                 } else {
                     return "not aded successfully";
                 }
             } else {
                 return View::make('G1SAS/category1')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             }
             break;
         case 1:
             // never reached because "a" is already matched with 0
             return View::make('G1SAS/category2')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             break;
         case 2:
             return View::make('G1SAS/category3')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             break;
         case 3:
             // never reached because "a" is already matched with 0
             return View::make('G1SAS/category4')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             break;
         case 4:
             return View::make('G1SAS/category5')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             break;
         case 5:
             return View::make('G1SAS/category6')->with('application', $application)->with('username', $username)->with('schools', $schoolIds)->with('yArray', $yearset)->with('guardianNic', $guardianNic)->with('dArray', $divisionSet);
             break;
     }
 }
 public static function addCategory1($application, $category1, $schoolIds, $yArray, $dArray, $guardianNic)
 {
     $db = Connection::getInstance();
     $mysqli = $db->getConnection();
     $mysqli->autocommit(FALSE);
     $applicantResult = DBApplicationController::addApplication($application);
     if ($applicantResult) {
         $resultSchoolSet = true;
         $isApplicanthasCSS = DBSchoolController::isApplicanthasCSS($application->getApplicant_id());
         if ($isApplicanthasCSS) {
             //do not need add school set
         } else {
             // return $schoolIds[1];
             $resultSchoolSet = DBSchoolController::addCloseSchoolSet($application->getApplicant_id(), $schoolIds);
         }
         if ($resultSchoolSet) {
             $resultEL = true;
             $isGuardianHasEL = DBGuardianController::isGuardianHasEL($guardianNic);
             if ($isGuardianHasEL) {
             } else {
                 $resultEL = DBElectrocalListController::addElectrocalListDetail($dArray, $yArray, $guardianNic);
             }
             if ($resultEL) {
                 $resultC = true;
                 $resultCD = DBGuardianController::hasCategory1Detail($guardianNic);
                 if ($resultCD == false) {
                     $resultC = DBCategory1Controller::addCategory1($category1);
                 }
                 if ($resultC) {
                     $mysqli->commit();
                     return true;
                 } else {
                     $mysqli->rollback();
                     $mysqli->commit();
                     return false;
                 }
             } else {
                 $mysqli->rollback();
                 $mysqli->commit();
                 return FALSE;
             }
         } else {
             $mysqli->rollback();
             $mysqli->commit();
             return FALSE;
         }
     } else {
         $mysqli->rollback();
         $mysqli->commit();
         return FALSE;
     }
 }