function save_data($file, $module, $UserId)
 {
     $name = $file["classlist"]["name"];
     $temp = $file["classlist"]["tmp_name"];
     if ($file["classlist"]["type"] != "application/pdf") {
         return "PDF has not been uploaded. Invalid file type.";
     }
     include APPPATH . 'libraries/pdfparse.php';
     //create new instance of class pdfparse
     $pdfdata = new PDFparse();
     //just set the path of the file
     $pdfdata->setFilename($temp);
     //it will get the infos like subj,sect,schedule and stud number/name
     $pdfdata->decodePDF();
     //convert into array
     $data = $pdfdata->output();
     //get max count for the loop later
     $count = count($data["studs"]);
     $num_students = $count / 2;
     //---get subj title---//
     $s = $this->slugify($data["info"][5]);
     $subj = explode('-', $s);
     $subj[0] = strtoupper($subj[0]);
     $s = implode(" ", $subj);
     $t = ucwords($s);
     $subj_title = $t;
     //---get subj title---//
     $class_block = $data["info"][3];
     //class block
     $class_yr_sem = $data["info"][1];
     //yr and sem
     $class_schedule = $data["info"][7];
     // schedule
     //---check if pdf is invalid for upload---//
     $this->db->where('SubjectTitle', $subj_title);
     $query_exist_subj = $this->db->get('subjects');
     if ($query_exist_subj->num_rows() > 0) {
         foreach ($query_exist_subj->result() as $check_subj) {
             //now find if same class exists within same school year
             $this->db->where('SubjectId', $check_subj->Id);
             $this->db->where('ClassBlock', $class_block);
             $this->db->where('ModuleType', $module);
             $this->db->where('YrSem', $class_yr_sem);
             $validate_class = $this->db->get('class');
             if ($validate_class->num_rows() > 0) {
                 return "PDF of same school year has already been uploaded.";
             }
         }
     }
     //save each information consecutively
     //---save subject---//
     $subject = array('UserId' => $UserId, 'SubjectTitle' => $subj_title);
     $this->db->insert('subjects', $subject);
     //get newly created subj id
     $SubjectId = $this->db->insert_id();
     //--save class--//
     $class = array('SubjectId' => $SubjectId, 'ClassBlock' => $class_block, 'ModuleType' => $module, 'NumOfStudents' => $num_students, 'YrSem' => $class_yr_sem, 'Schedule' => $class_schedule);
     $this->db->insert('class', $class);
     $ClassId = $this->db->insert_id();
     $init_att = false;
     $init_assign = false;
     $init_sw = false;
     $init_ex = false;
     $init_rec = false;
     $init_quiz = false;
     $init_le = false;
     $init_mexam = false;
     $init_fexam = false;
     $init_lab = false;
     $init_prac = false;
     $init_proj = false;
     for ($c = 0; $c < $count; $c += 2) {
         //---block of code for getting first;middle and last name---//
         $text = strtolower($data["studs"][$c + 1]);
         $text = utf8_encode($text);
         // to read special characters ñ
         $name = explode(',', $text);
         $first_middle_name = explode(' ', $name[1]);
         $first_name = "";
         $last_name = $name[0];
         //get last item on array
         $middle_name = end($first_middle_name);
         //convert string to array
         $fname = explode(' ', substr($name[1], 1));
         $cnt = count($fname);
         for ($d = 0; $d < $cnt - 1; $d++) {
             $first_name = $first_name . $fname[$d] . " ";
         }
         //remove last space
         substr($first_name, -1);
         //---block of code for getting first,middle and last name---//
         $stud_num = $data["studs"][$c];
         //stud number
         // now save each student
         $student = array('ClassId' => $ClassId, 'FName' => $first_name, 'MName' => $middle_name, 'LName' => $last_name, 'StudentNumber' => $stud_num);
         $this->db->insert('students', $student);
         //get student id and insert to 'grades table'
         $stud_id = $this->db->insert_id();
         $this->Grades_model->init_grades($stud_id);
         //know the module to be used 'Lec' or 'Lab'
         //if 'Lec'
         if ($module == 'Lec') {
             if ($init_att == false) {
                 //insert att
                 $init_att = $this->Grades_model->init_att($stud_id, $num_students);
                 $init_mod_att = $this->Grades_model->init_mod_att($ClassId);
             }
             if ($init_assign == false) {
                 //insert assign
                 $init_assign = $this->Grades_model->init_assign($stud_id, $num_students);
                 $init_mod_assign = $this->Grades_model->init_mod_assign($ClassId);
             }
             if ($init_sw == false) {
                 //insert sw
                 $init_sw = $this->Grades_model->init_sw($stud_id, $num_students);
                 $init_mod_sw = $this->Grades_model->init_mod_sw($ClassId);
             }
             if ($init_ex == false) {
                 //insert ex
                 $init_ex = $this->Grades_model->init_ex($stud_id, $num_students);
                 $init_mod_ex = $this->Grades_model->init_mod_ex($ClassId);
             }
             if ($init_rec == false) {
                 //insert rec
                 $init_rec = $this->Grades_model->init_rec($stud_id, $num_students);
                 $init_mod_rec = $this->Grades_model->init_mod_rec($ClassId);
             }
             if ($init_quiz == false) {
                 //insert quiz
                 $init_quiz = $this->Grades_model->init_quiz($stud_id, $num_students);
                 $init_mod_quiz = $this->Grades_model->init_mod_quiz($ClassId);
             }
             if ($init_le == false) {
                 //insert le
                 $init_le = $this->Grades_model->init_le($stud_id, $num_students);
                 $init_mod_le = $this->Grades_model->init_mod_le($ClassId);
             }
             if ($init_mexam == false) {
                 //insert midterm exam
                 $init_mexam = $this->Grades_model->init_mexam($stud_id, $num_students);
                 $init_mod_me = $this->Grades_model->init_mod_me($ClassId);
             }
             if ($init_fexam == false) {
                 //insert final exam
                 $init_fexam = $this->Grades_model->init_fexam($stud_id, $num_students);
                 $init_mod_fe = $this->Grades_model->init_mod_fe($ClassId);
             }
         } else {
             if ($init_lab == false) {
                 //insert lab/machine ex
                 $init_lab = $this->Grades_model->init_lab($stud_id, $num_students);
                 $init_mod_lab = $this->Grades_model->init_mod_lab($ClassId);
             }
             if ($init_prac == false) {
                 //insert prac exam
                 $init_prac = $this->Grades_model->init_prac($stud_id, $num_students);
                 $init_mod_prac = $this->Grades_model->init_mod_prac($ClassId);
             }
             if ($init_proj == false) {
                 //insert proj
                 $init_proj = $this->Grades_model->init_proj($stud_id, $num_students);
                 $init_mod_proj = $this->Grades_model->init_mod_proj($ClassId);
             }
         }
     }
     return "PDF has been successfully uploaded.";
 }
 function save_data($file, $module, $UserId)
 {
     $name = $file["classlist"]["name"];
     $temp = $file["classlist"]["tmp_name"];
     if (file_exists('resources/uploads/' . $name) || $file["classlist"]["type"] != "application/pdf") {
         return false;
     }
     move_uploaded_file($temp, "resources/uploads/" . $name);
     include APPPATH . 'libraries/pdfparse.php';
     //create new instance of class pdfparse
     $pdfdata = new PDFparse();
     //just set the path of the file
     $pdfdata->setFilename('resources/uploads/' . $name);
     //it will get the infos like subj,sect,schedule and stud number/name
     $pdfdata->decodePDF();
     //convert into array
     $data = $pdfdata->output();
     //get max count for the loop later
     $count = count($data["studs"]);
     //---get subj title---//
     $s = $this->slugify($data["info"][5]);
     $subj = explode('-', $s);
     $subj[0] = strtoupper($subj[0]);
     $s = implode(" ", $subj);
     $t = ucwords($s);
     $subj_title = $t;
     //---get subj title---//
     $class_block = $data["info"][3];
     //class block
     $class_yr_sem = $data["info"][1];
     //yr and sem
     $class_schedule = $data["info"][7];
     // schedule
     //save each information consecutively
     //---save subject---//
     $subject = array('UserId' => $UserId, 'SubjectTitle' => $subj_title);
     $this->db->insert('subjects', $subject);
     //get newly created subj id
     $SubjectId = $this->db->insert_id();
     //--save class--//
     $class = array('SubjectId' => $SubjectId, 'ClassBlock' => $class_block, 'ModuleType' => $module, 'NumOfStudents' => $count / 2, 'YrSem' => $class_yr_sem, 'Schedule' => $class_schedule);
     $this->db->insert('class', $class);
     $ClassId = $this->db->insert_id();
     for ($c = 0; $c < $count; $c += 2) {
         //---block of code for getting first,middle and last name---//
         $text = strtolower($data["studs"][$c + 1]);
         $text = utf8_encode($text);
         // to read special characters ñ
         $name = explode(',', $text);
         $first_middle_name = explode(' ', $name[1]);
         $first_name = "";
         $last_name = $name[0];
         //get last item on array
         $middle_name = end($first_middle_name);
         //convert string to array
         $fname = explode(' ', substr($name[1], 1));
         $cnt = count($fname);
         for ($d = 0; $d < $cnt - 1; $d++) {
             $first_name = $first_name . $fname[$d] . " ";
         }
         //remove last space
         substr($first_name, -1);
         //---block of code for getting first,middle and last name---//
         $stud_num = $data["studs"][$c];
         //stud number
         // now save each student
         $student = array('ClassId' => $ClassId, 'FName' => $first_name, 'MName' => $middle_name, 'LName' => $last_name, 'StudentNumber' => $stud_num);
         $this->db->insert('students', $student);
     }
     return true;
 }