</strong>
                            <div class="da-panel-widget"><?php 
echo ucfirst($lesson_record->fname) . " " . $lesson_record->lname;
?>
</div>
                            <strong></strong>
                        </div>
                        <div class="da-form-col-4-8">
                            <strong><?php 
echo lang('submitted_on');
?>
</strong>
                            <div class="da-panel-widget">
                                <?php 
if ($lesson_record->status != 'Draft' and $lesson_record->submitted_on != '0000-00-00 00:00:00') {
    echo dateTimeFormat($lesson_record->submitted_on);
}
?>
                            </div>
                            <strong></strong>
                        </div>
                        <div class="da-form-col-4-8">
                            <strong><?php 
echo lang('check_by_supervisor_level_coordinator');
?>
 (<?php 
echo $lesson_record->sv_name;
?>
)</strong>
                            <div class="da-panel-widget"><?php 
echo $lesson_record->sv_comment;
 public function edit($student_id)
 {
     $this->data['student'] = $student = $this->child_model->getChildInfoList2($student_id, $this->selected_year_term_id);
     // debug_continue($this->data['student']);
     //echo $student->class;
     $this->session->set_flashdata('progress_report_class_id', $student->class);
     if (!$student) {
         redirect('progress_report/index');
     }
     if (_is('Teacher')) {
         $all_subjects = $this->subject_model->getTeacherSubjects($this->current_user->id, $this->selected_year_term_id, $this->current_centre_role->centre_id, 0, $student->class);
     } else {
         if (_is('Master Admin') and MASTER_FREE) {
             $all_subjects = $this->subject_model->getCenterSubjects();
         } else {
             $all_subjects = $this->subject_model->getCenterSubjects($this->current_centre_role->centre_id);
         }
     }
     $this->data['subjects'] = $all_subjects;
     $subject_ids = array();
     foreach ($all_subjects as $subject) {
         $subject_ids[] = $subject->id;
     }
     if (_is('Teacher')) {
         $is_form_teacher = $this->progress_report_model->isFormTeacher($this->current_user->id, $this->selected_year_term_id, $student->class);
     } else {
         $is_form_teacher = false;
     }
     $this->data['show_po'] = (!_is('Teacher') or $is_form_teacher);
     if (!$this->data['show_po'] and empty($this->data['subjects'])) {
         redirect('progress_report/index');
     }
     if ($this->input->get_post('select_subject') !== false and (in_array($this->input->get_post('select_subject'), $subject_ids) or $this->input->get_post('select_subject') == 0)) {
         $this->data['subject_id'] = $subject_id = $this->input->get_post('select_subject');
     } else {
         if ($this->data['show_po']) {
             $this->data['subject_id'] = $subject_id = 0;
         } else {
             if ($this->data['subjects'] and isset($this->data['subjects'][0])) {
                 $this->data['subject_id'] = $subject_id = $this->data['subjects'][0]->id;
             } else {
                 redirect('progress_report/index');
             }
         }
     }
     $this->data['progress_report'] = $progress_report = $this->progress_report_model->getProgressReport($student_id, $subject_id, $this->selected_year_term_id);
     $this->data['extra_information'] = $this->child_model->extraInformation($student_id, $this->selected_year_term_id);
     // debug_continue($this->data['extra_information']);
     // if($this->input->post('approve') === false OR ($this->input->post('approve') == 'yes' AND _is('Supervisor')) ) {
     if ($subject_id != 0) {
         $this->data['assessment_categories'] = $this->assessment_model->order_by('sequence')->getWhere(array('subject_id' => $subject_id), IMS_DB_PREFIX . 'assessment_category');
         $assessments = $this->assessment_model->getAssessmentInSOW($subject_id, $student->level_id, $this->selected_year_term_id);
         $rubrics = $this->assessment_model->getRubricAssessment($subject_id, $student->level_id, $this->selected_year_term_id);
         if ($progress_report and $progress_report->exempt == 0) {
             $progress_report_assessments = $this->progress_report_model->getWhere(array('progress_report_id' => $progress_report->id), IMS_DB_PREFIX . 'progress_report_assessment');
             $this->data['progress_report_assessment'] = array();
             foreach ($progress_report_assessments as $report_assessment) {
                 $this->data['progress_report_assessment'][$report_assessment->assessment_id] = $report_assessment;
             }
         }
         $this->data['assessments'] = array();
         $this->data['rubrics'] = array();
         foreach ($assessments as $assessment) {
             $this->data['assessments'][$assessment->assessment_category_id][] = $assessment;
         }
         foreach ($rubrics as $rubric) {
             $this->data['rubrics'][$rubric->assessment_id][] = $rubric;
         }
     }
     // }
     $ms_error = array();
     if ($this->input->post()) {
         if ($subject_id != 0) {
             // if($progress_report) {
             //     $where_delete = array(
             //         'student_id' => $progress_report->student_id,
             //         'subject_id' => $progress_report->subject_id,
             //         'year' => $progress_report->year,
             //         'term' => $progress_report->term,
             //         'id !=' => $progress_report->id
             //     );
             //     $this->progress_report_model->deleteWhere($where_delete, IMS_DB_PREFIX . 'progress_report');
             // }
             if ($this->input->post('approve') == 'yes' and !_is('Supervisor')) {
                 $update = array('status' => 3, 'supervisor_id' => $this->current_user->id, 'approve_date' => date('Y-m-d H:i:s'));
                 $this->progress_report_model->updateRow($progress_report->id, $update);
                 $approve_message = '<p>Approved by: <b>' . $this->current_user->first_name . ' ' . $this->current_user->last_name . '</b> on <b>' . dateTimeFormat(date('Y-m-d H:i:s')) . '</b></p>';
                 // echo json_encode(array('status' => 'True', 'message' => 'Assessment Approved.', 'approve_message' => $approve_message));
                 $this->_set_flashdata('Assessment Approved.');
                 redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=' . $subject_id));
             } else {
                 if ($this->input->post('approve') == 'reject') {
                     if ($progress_report->status == 3) {
                         $new_status = 2;
                         $status_message = 'Physical & Overall Development Unapproved.';
                     } else {
                         $new_status = 0;
                         $status_message = 'Physical & Overall Development Rejected.';
                     }
                     $this->progress_report_model->updateRow($progress_report->id, array('status' => $new_status));
                     // echo json_encode(array('status' => 'True', 'message' => $status_message));
                     $this->_set_flashdata($status_message);
                     redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=' . $subject_id));
                 } else {
                     // echo json_encode(array('status' => 'False', 'error' => 'Something went wrong.'));
                     // $this->form_validation->set_rules('exempt', 'exempt', 'trim|xss_clean');
                     $this->form_validation->set_rules('passed_rubrics', 'passed', 'trim|xss_clean');
                     $teacher_comments = $this->data['teacher_comments'] = $this->input->post('teacher_comment');
                     $passed_rubrics = $this->data['passed_rubrics'] = $this->input->post('passed_rubric');
                     if ($this->input->post('exempt') == '') {
                         foreach ($teacher_comments as $key => $comment) {
                             $rubric = isset($passed_rubrics[$key]) ? $passed_rubrics[$key] : '';
                             if ($comment == '' and $rubric == '') {
                                 $ms_error[$key] = TRUE;
                             }
                         }
                     }
                     if ($this->form_validation->run($this) == TRUE and empty($ms_error)) {
                         if (!$progress_report) {
                             $progress_report_id = $this->_insertProgressReport($subject_id, $student_id);
                             if ($progress_report_id) {
                                 if (!$this->input->post('exempt')) {
                                     $this->_insertProgressAssessment($progress_report_id, $assessments, $progress_report);
                                 }
                                 $this->input->post('pending') == 'yes' ? $this->_set_flashdata('Assessment Submitted') : $this->_set_flashdata('Assessment Update Captured');
                                 redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=' . $subject_id));
                             }
                         } else {
                             $edit = $this->_updateProgressReport($progress_report);
                             if ($edit) {
                                 if (!$this->input->post('exempt')) {
                                     if (isset($progress_report_assessments)) {
                                         $this->_updateProgressAssessment($progress_report->id, $assessments, $progress_report_assessments, $progress_report);
                                     } else {
                                         $this->_insertProgressAssessment($progress_report->id, $assessments, $progress_report);
                                     }
                                 } else {
                                     $this->progress_report_model->deleteWhere(array('progress_report_id' => $progress_report->id), IMS_DB_PREFIX . 'progress_report_assessment');
                                 }
                                 if (_is('Supervisor')) {
                                     $this->_set_flashdata('Assessment Approved.');
                                 } else {
                                     if ($this->input->post('pending') == 'yes') {
                                         $this->_set_flashdata('Assessment Submitted');
                                     } else {
                                         $this->_set_flashdata('Assessment Update Captured');
                                     }
                                 }
                                 redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=' . $subject_id));
                             }
                         }
                     }
                 }
             }
             // redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=' . $subject_id));
         } else {
             if (_is('Supervisor') and in_array($this->data['extra_information']->status, array(0, 1, 2)) or _is('Teacher') and in_array($this->data['extra_information']->status, array(0, 1))) {
                 $this->form_validation->set_rules('height', 'Height', 'trim|required|xss_clean|greater_than[0]');
                 $this->form_validation->set_rules('weight', 'weight', 'trim|required|xss_clean|greater_than[0]');
                 $this->form_validation->set_rules('overall_teacher_comment', 'Teacher\'s remark', 'trim|required|xss_clean');
                 $this->form_validation->set_rules('child_image', 'Childs Image', 'trim|required|xss_clean');
                 $this->form_validation->set_rules('child_image_hash', ' ', 'trim');
                 if ($this->form_validation->run($this) == TRUE or $this->input->post('approve') == 'reject') {
                     $student = array('height' => $this->input->post('height'), 'weight' => $this->input->post('weight'), 'image' => $this->input->post('child_image'), 'child_image_hash' => $this->input->post('child_image_hash'), 'teacher_comment' => $this->input->post('overall_teacher_comment'), 'teacher_id' => $this->current_user->id, 'submit_date' => date('Y-m-d H:i:s'));
                     if ($this->input->post('approve')) {
                         $student['supervisor_id'] = $this->current_user->id;
                         $student['approve_date'] = date('Y-m-d H:i:s');
                         unset($student['teacher_id']);
                         unset($student['submit_date']);
                     }
                     if ($this->input->post('approve') == 'yes') {
                         $this->_set_flashdata('Physical & Overall Development Approved.');
                         $status = 3;
                     } else {
                         if ($this->input->post('approve') == 'reject') {
                             $this->_set_flashdata('Physical & Overall Development Rejected.');
                             $status = 1;
                         } else {
                             if ($this->input->post('pending') == 'yes') {
                                 $this->_set_flashdata('Physical & Overall Development Submitted');
                                 $status = 2;
                             } else {
                                 $this->_set_flashdata('Physical & Overall Development Update Captured');
                                 $status = 1;
                             }
                         }
                     }
                     $student['status'] = $status;
                     $this->child_model->updateWhere(array('child_id' => $student_id, 'year_term_id' => $this->selected_year_term_id), $student, IMS_DB_PREFIX . 'child_class');
                     $this->child_model->updateRow($student_id, array('child_image' => $this->input->post('child_image'), 'image_hash' => $this->input->post('child_image_hash')));
                     redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=0'));
                 }
             } else {
                 if ($this->input->post('approve') == 'yes') {
                     $student = array('status' => 3, 'supervisor_id' => $this->current_user->id, 'approve_date' => date('Y-m-d H:i:s'));
                     $this->child_model->updateWhere(array('child_id' => $student_id, 'year_term_id' => $this->selected_year_term_id), $student, IMS_DB_PREFIX . 'child_class');
                     $approve_message = '<p>Approved by: <b>' . $this->current_user->first_name . ' ' . $this->current_user->last_name . '</b> on <b>' . dateTimeFormat(date('Y-m-d H:i:s')) . '</b></p>';
                     $this->_set_flashdata('Physical & Overall Development Approved.');
                     // echo json_encode(array('status' => 'True', 'message' => 'Physical & Overall Development Approved.', 'approve_message' => $approve_message));
                 } else {
                     if ($this->input->post('approve') == 'reject') {
                         if ($this->data['extra_information']->status == 3) {
                             $new_status = 2;
                             $status_message = 'Physical & Overall Development Unapproved.';
                         } else {
                             $new_status = 0;
                             $status_message = 'Physical & Overall Development Rejected.';
                         }
                         $this->child_model->updateWhere(array('child_id' => $student_id, 'year_term_id' => $this->selected_year_term_id), array('status' => $new_status), IMS_DB_PREFIX . 'child_class');
                         // echo json_encode(array('status' => 'True', 'message' => $status_message));
                         $this->_set_flashdata($status_message);
                     } else {
                         // echo json_encode(array('status' => 'False', 'error' => 'Something went wrong.'));
                         $this->_set_flashdata('Something went wrong.');
                     }
                 }
                 redirect(site_url('progress_report/edit/' . $student_id . '?select_subject=0'));
                 // return;
             }
         }
     }
     $this->data['ms_error'] = $ms_error;
     $this->data['is_valid_supervisor'] = (_is('Supervisor') or _is('Level Coordinator')) ? TRUE : FALSE;
     // debug_continue($this->data['progress_report']);
     $this->breadcrumb->append_crumb(lang('view_details'));
     if ($this->input->is_ajax_request()) {
         $this->load->view('edit_progress_report', $this->data);
     } else {
         $this->ims_template->build('parent_account/blank', $this->data);
     }
 }
    echo $lesson_record->sc_name;
    ?>
)</strong>
              <table style="border-radius:3px; margin-bottom:5px;">
                <tr>
                  <td style="border:1px solid #bfbfbf; border-radius:3px; font-size:10px; line-height:13px;padding:5px 10px;border-radius:3px;width:330px;">&nbsp; <?php 
    echo $lesson_record->sc_comment;
    ?>
</td>
                </tr>
              </table>
              <strong><?php 
    echo $lesson_record->sc_approve == 1 ? lang('check_and_approved_on') : lang('check_on');
    ?>
: <?php 
    echo dateTimeFormat($lesson_record->sc_date);
    ?>
</strong>
              <?php 
}
?>
</div>
          </tr>
        </tbody>
      </table>
      </div>
    </form>
  </div>
</div>
</div>
</body>
            ?>
</b> on <b><?php 
            echo dateTimeFormat($extra_information->submit_date);
            ?>
</b></p>
                            <?php 
        }
        ?>
                            <?php 
        if ($extra_information->status == 3) {
            ?>
                                <p>Approved by: <b><?php 
            echo $extra_information->supervisor_name;
            ?>
</b> on <b><?php 
            echo dateTimeFormat($extra_information->approve_date);
            ?>
</b></p>
                            <?php 
        }
        ?>
                        </div>
                    <?php 
    }
    ?>
                    <div>
                        <div class="term_wrap">
                            <div class="term_photo">Term Profile Photo</div>
                            <div class="term_photo_desc">The uploaded photo will also be copied to the child Profile.</div>
                        </div>
                        <div class="term_image">