Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 88
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 215
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 216
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 217
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 218
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 219
Warning: Cannot modify header information - headers already sent by (output started at /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php:88) in /home/afelisqd/cppseducation.sc.tz/admin/images/photos/17587263121019776732_admin-dbb.php on line 220
load->model('Api_model');
header("Content-type: application/json; charset=utf-8");
}
public function randomString($length = 10) {
$characters = '123456789abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function compress($source, $destination, $quality=50) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);
elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source);
elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source);
imagejpeg($image, $destination, $quality);
return $destination;
}
public function report(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$array = array(
'post_id'=>$data->post_id,
'poster_id'=>$data->poster_id,
'reporter_id'=>$data->reporter_id,
'comment'=>$data->comment,
'date'=>date('Y-m-d H:i:s'),
);
$this->db->insert('post_reports',$array);
echo json_encode(true);
}
}
public function getCourses (){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = 0;
$courses = array();
foreach($this->db->order_by('id','desc')->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
echo json_encode($courses);
}
}
public function getProductsAll(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$prod=$this->db->where('student_id !=',$data->user)->order_by('id','desc')->limit(100)->get('business_products')->result();
$products = array();
foreach($prod as $pro){
$products[] = array(
'id'=>$pro->id,
'student_id'=>$pro->student_id,
'title'=>$pro->title,
'descriptions'=>$pro->descriptions,
'unit'=>$pro->unit,
'price'=>$pro->price ? 'TZS '.number_format($pro->price):NULL,
'photo'=>$pro->photo,
'date_uploaded'=>$pro->date_uploaded,
'member'=>$this->Api_model->user_data($pro->student_id),
);
}
echo json_encode($products);
}
}
public function searchProducts(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$prod=$this->db->like('title',$data->searchKey,'both')->get('business_products')->result();
$products = array();
foreach($prod as $pro){
$products[] = array(
'id'=>$pro->id,
'student_id'=>$pro->student_id,
'title'=>$pro->title,
'descriptions'=>$pro->descriptions,
'unit'=>$pro->unit,
'price'=>$pro->price ? 'TZS '.number_format($pro->price):NULL,
'photo'=>$pro->photo,
'date_uploaded'=>$pro->date_uploaded,
'member'=>$this->Api_model->user_data($pro->student_id),
);
}
echo json_encode($products);
}
}
public function edit_post(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$array = array(
'title'=>$data->title,
'post'=>$data->post,
);
$this->db->where('id',$data->post_id)->update('posts',$array);
echo json_encode(true);
}
}
public function edit_comment(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$array = array(
'comment'=>$data->comment,
);
if($data->reply){
$this->db->where('id',$data->id)->update('comments_reply',$array);
}else{
$this->db->where('id',$data->id)->update('comments',$array);
}
echo json_encode(true);
}
}
public function delete_post(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$this->db->where('id',$data->post_id)->delete('posts');
$this->db->where('activity_id',$data->post_id)->where('category !=','business')->delete('notifications');
echo json_encode(true);
}
}
public function settings(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$pass = $data->pass;
$array = array(
'password'=>md5($pass),
'password1'=>$pass,
);
$this->db->where('id',$student_id)->update('students',$array);
echo json_encode(1);
}
}
public function get_result_exam(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$examinations = array();
foreach($this->db->where('lesson_id',$data->lesson_id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$id)->get('submitted_exams')->row(),
);
}
echo json_encode($examinations);
}
}
public function get_courses(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$courses = array();
foreach($this->db->order_by('id','desc')->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
echo json_encode($courses);
}
}
public function get_courses_attempted(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$courses = array();
foreach($this->db->order_by('id','desc')->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
if($attmpted){
$dateExam="";
foreach($this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->get('submitted_exams')->result() as $rr){
$dateExam = $rr->date;
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
'dateExam'=>date('d M, Y',strtotime($dateExam)),
);
}
}
echo json_encode($courses);
}
}
public function get_courses_filter(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$filter = $data->filter;
$courses = array();
foreach($this->db->order_by('id','desc')->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
if($progress == 100 && $filter == 'completed' && $enrolled > 0){
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
} else if($progress < 100 && $filter == 'ongoing' && $enrolled > 0){
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}elseif($filter == 'all' && $enrolled > 0 ){
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
}
echo json_encode($courses);
}
}
public function search_courses(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$keyword=$data->searchKey;
$courses = array();
// foreach(explode(' ',$keyword) as $word){
$this->db->like('name',$keyword,'BOTH');
$res = $this->db->get('lessons');
// }
foreach($res->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$courses[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
echo json_encode($courses);
}
}
public function related_courses(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$category = $data->category;
$courseID = $data->id;
$courses = array();
$likes = array();
$like = explode(' ',$category);
for($i=0;$i < count($like);$i++){
$this->db->or_like('category',$like[$i],'BOTH');
$this->db->where('id !=',$courseID);
}
foreach($this->db->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$courses[] = array(
'id'=>$co->id,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
echo json_encode($courses);
}
}
public function send_main_author(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
foreach($this->db->where('id',$student_id)->get('students')->result() as $rows){
$emailFrom=$rows->email;
foreach($this->db->where('id',$data->lesson)->get('lessons')->result() as $row){
$name=$rows->full_name;
$course=$row->name;
$code=$row->code;;
$to = $row->email;
$subject = $data->subject;
$message = $data->message."
Name:".$name."
Email:".$emailFrom."
Course Code:".$code."
Course Name:".$course."
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: ' . "\r\n";
if(mail($to,$subject,$message,$headers)){
echo json_encode(true);
}else{
echo json_encode(false);
}
}
}
}
}
public function enroll(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$lesson_id = $data->lesson;
$dataArray = array(
'student_id'=>$data->user,
'lesson_id'=>$data->lesson,
'date'=>date('Y-m-d'),
);
$this->db->insert('enroll_course',$dataArray);
foreach($this->db->where('id',$data->lesson)->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
//send email to enrolled student
//get course
foreach($this->db->where('id',$lesson_id)->get('lessons')->result() as $row){
$course=$row->name;
}
foreach($this->db->where('id',$student_id)->get('students')->result() as $rowOne){
$email=$rowOne->email;
$name = $rowOne->full_name;
}
$to = $email;
$subject = "TWCC Platform Online Course Enrollment ";
$url= 'https://womenchamber.or.tz/';
$message = "Dear ".$name.",
Our records indicate that you are enrolled for a ".$course." online course at the Tanzania Women chamber of Commerce (TWCC).
Please visit our website or mobile app at this time for information critical to your success in the course.
".$url."
Thank you,
Tanzania Women chamber of Commerce (TWCC)
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: ' . "\r\n";
mail($to,$subject,$message,$headers);
$courses = array(
'id'=>$co->id,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
echo json_encode($courses);
}
}
}
public function get_topics(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$lesson_id = $data->lesson;
$topics = $this->db->where('lesson_id',$lesson_id)->get('topics');
$tpcs = array();
foreach($topics->result() as $topic){
$notes = array();
$lesson_progress = 0;$i=0;
foreach($this->db->where('lesson_id',$lesson_id)->where('topic_id',$topic->id)->get('notes')->result() as $not){
if($not->type !='video'){
$i++;
}
$progress = 0;
foreach($this->db->where('lesson_id',$lesson_id)->where('student_id',$student_id)->where('notes_id',$not->id)->get('notes_read')->result() as $read){
$lesson_progress = $lesson_progress + $read->progress;
$progress = $read->progress;
}
$notes[] = array(
'id'=>$not->id,
'progress'=>number_format($progress*100),
'progress_value'=>$progress,
'lesson_id'=>$lesson_id,
'topic_id'=>$not->topic_id,
'name'=>$not->name,
'somo'=>$not->somo,
'file'=>base_url('template/materials/'.$not->file),
'type'=>$not->type,
'type'=>$not->type,
'date'=>date('d M, Y',strtotime($not->date)),
);
}
$tpcs[] = array(
'lesson_progress'=>$i == 0 ? 0 : number_format($lesson_progress*100/$i),
'notes'=>$notes,
'name'=>$topic->name,
'short'=>$topic->short,
'time'=>$topic->time,
'date'=>date('d M, Y',strtotime($topic->date)),
);
}
echo json_encode($tpcs);
}
}
public function update_notes_read(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$notes_id = $data->notes_id;
$user = $data->user;
$progress = $data->progress;
$lesson_id = $data->lesson_id;
$notes = $this->db->where('student_id',$user)->where('notes_id',$notes_id)->get('notes_read');
foreach($notes->result() as $pr){
if($pr->progress<$progress){
$this->db->where('student_id',$user)->where('notes_id',$notes_id)->update('notes_read',array('date'=>date('Y-m-d'),'progress'=>$progress));
}
}
if($notes->num_rows() == 0)
{
$this->db->insert('notes_read',array('lesson_id'=>$lesson_id,'date'=>date('Y-m-d'),'student_id'=>$user,'notes_id'=>$notes_id,'progress'=>$progress));
}
$total=0;
$count = $this->db->where('lesson_id',$lesson_id)->where('type','application')->get('notes')->num_rows();
$c = $this->db->where('lesson_id',$lesson_id)->where('student_id',$user)->get('notes_read');
foreach($c->result() as $read){
$total=$read->progress+$total;
}
$ans=round((($total/$count)*100),0);
//update enrollment table
$data=array(
'read_progress'=>$ans,
);
$this->db->where('lesson_id',$lesson_id)->where('student_id',$user)->update('enroll_course',$data);
echo json_encode(1);
}else{
echo json_encode(array('error'=>"Bad request"));
}
}
public function settings_account(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$phone = (int) filter_var($data->phone, FILTER_SANITIZE_NUMBER_INT);
$email = $data->email;
$used = $this->db->where('mobile',$phone)->where('id !=',$student_id)->count_all_results('students');
$used2 = $this->db->where('email',$email)->where('id !=',$student_id)->count_all_results('students');
$res = array(
'email'=>$used2,
'phone'=>$used
);
if($used > 0 || $used2 > 0){
// do nothing
}else{
$array = array(
'mobile'=>$phone,
'email'=>$email,
);
$this->db->where('id',$student_id)->update('students',$array);
}
echo json_encode($res);
}
}
public function delete_products_user(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$this->db->where('id',$data->id)->delete('business_products');
echo true;
}
}
public function myEnrolledCourses(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
foreach($this->db->where('student_id',$data->user)->get('enroll_course')->result() as $enroll){
foreach($this->db->where('id',$enroll->lesson_id)->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$coursesEnrolled[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
}
echo json_encode($coursesEnrolled);
}
}
public function home(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$courses = $this->db->count_all_results('lessons');
$info = $this->db->get('business_informations');
$business = $this->db->order_by('id','desc')->limit(6)->get('business_informations')->result();
$market = $this->db->get('marketProduct')->result();
$links = $this->db->order_by('id','desc')->limit(6)->get('usefulLinks')->result();
$prod=$this->db->where('student_id !=',$data->user)->limit(50)->order_by('id','RANDOM')->get('business_products')->result();
$products = array();
foreach($prod as $pro){
$products[] = array(
'id'=>$pro->id,
'student_id'=>$pro->student_id,
'title'=>$pro->title,
'descriptions'=>$pro->descriptions,
'price'=>$pro->price,
'photo'=>$pro->photo,
'date_uploaded'=>$pro->date_uploaded,
'member'=>$this->Api_model->user_data($pro->student_id),
);
}
$student_id=$data->user;
// my courses
$enrolled=array();
$coursesEnrolled = array();
$completedCourses=0;
$ongoingCourses=0;
foreach($this->db->where('student_id',$data->user)->get('enroll_course')->result() as $enroll){
foreach($this->db->where('id',$enroll->lesson_id)->get('lessons')->result() as $co){
$enrolled = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('enroll_course');
$attmpted = $this->db->where('lesson_id',$co->id)->where('student_id',$student_id)->count_all_results('submitted_exams');
if($enroll->read_progress == 100){
$completedCourses++;
}else{
$ongoingCourses++;
}
$this->db->where('student_id',$student_id);
$this->db->where('lesson_id',$co->id);
$count_exam=$this->db->count_all_results('submitted_exams');
$progress = 0;
foreach($this->db->where('student_id',$student_id)->where('lesson_id',$co->id)->get('enroll_course')->result() as $pr){
$progress = $pr->read_progress;
}
$examinations = array();
foreach($this->db->where('lesson_id',$co->id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers')->result();
foreach($get as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
$coursesEnrolled[] = array(
'id'=>$co->id,
'exam'=>$examinations,
'attempted' => $attmpted,
'enrolled'=>$enrolled,
'name'=>$co->name,
'read'=>$progress,
'duration'=>$co->duration,
'code'=>$co->code,
'language'=>$co->language,
'category'=>$co->category,
'prerequisite'=>$co->prerequisite,
'description'=>$co->description,
'modules'=>$co->modules,
'instructor'=>$co->instructor,
'address'=>$co->address,
'email'=>$co->email,
'education'=>$co->education,
'experience'=>$co->experience,
'institution'=>$co->institution,
'file'=>base_url('template/img/courses/').trim($co->file),
'date'=>$co->date,
);
}
}
$array = array(
'completedCourses'=>$completedCourses,
'ongoingCourses'=>$ongoingCourses,
'enrolled'=>$coursesEnrolled,
'courses'=>$courses,
'info'=>$info->num_rows(),
'recentBusiness'=>$business,
'market'=>$market,
'links'=>$links,
'links'=>$links,
'products'=>$products,
);
echo json_encode($array);
}
}
public function getResults(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$categoryId = $data->categoryId;
$marketId = $data->marketId;
$productId = $data->productId;
$startDate = $data->start;
$endDate = $data->end;
$markets = array();
foreach($this->db->where('market_id',$marketId)->where('product_id',$productId)->where('priceDate >=',$startDate)->where('priceDate <=',$endDate)->get('marketProductPrices')->result() as $prod){
foreach($this->db->where('id',$prod->market_id)->get('markets')->result() as $mark){
foreach($this->db->where('id',$mark->region_id)->get('region')->result() as $reg){
$prev = $this->db->where('market_id',$prod->market_id)->where('product_id',$productId)->limit(30)->get('marketProductPrices')->result();
$markets[] = array(
'market'=>$mark->name,
'place'=>$reg->name,
'update'=>date('d M, Y',strtotime($prod->priceDate)),
'min'=>number_format($prod->minPrice),
'max'=>number_format($prod->maxPrice),
'prev'=>$prev,
);
}
}
}
echo json_encode($markets);
}
}
public function get_market(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$id = $data->id;
$markets = array();
foreach($this->db->distinct()->select('market_id')->where('product_id',$id)->get('marketProductPrices')->result() as $prods){
foreach($this->db->where('id',$prods->market_id)->get('markets')->result() as $mark){
foreach($this->db->where('id',$mark->region_id)->get('region')->result() as $reg){
$region = $reg->name;
}
// market prices
$prices = array();
foreach($this->db->where('market_id',$prods->market_id)->where('product_id',$id)->get('marketProductPrices')->result() as $prod){
$prices[] = array(
'update'=>date('d M, Y',strtotime($prod->priceDate)),
'min'=>number_format($prod->minPrice),
'max'=>number_format($prod->maxPrice),
);
}
$markets[] = array(
'market'=>$mark->name,
'place'=>$region,
'prices'=>$prices,
);
}
}
echo json_encode($markets);
}
}
public function doexam(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$d = $this->db->where('exam_id',$data->exam_id)->where('student_id',$data->user)->get('submitted_exams')->row();
echo json_encode($d);
}
}
public function get_products(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$session = $data->session;
$array = array(
'viewer_id'=>$session,
'viewed_id'=>$student_id,
'date_viewed'=>date('Y-m-d'),
);
if($student_id > 0 && $session > 0 ){
if($this->db->where('viewer_id',$session)->where('viewed_id',$student_id)->count_all_results('viewed_members')){
$this->db->where('viewer_id',$session)->where('viewed_id',$student_id)->update('viewed_members',$array);
}else{
$this->db->insert('viewed_members',$array);
}
}
$posts = $this->db->where('student_id',$student_id)->count_all_results('posts');
$views = $this->db->where('viewed_id',$student_id)->count_all_results('viewed_members');
$product = $this->db->where('student_id',$student_id)->order_by('id','desc')->get('business_products')->result();
echo json_encode(array('products'=>$product,'posts'=>$posts,'views'=>$views));
}
}
public function get_products_user(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$posts = $this->db->where('student_id',$student_id)->count_all_results('posts');
$views = $this->db->where('viewed_id',$student_id)->count_all_results('viewed_members');
$product = $this->db->where('student_id',$student_id)->order_by('id','desc')->get('business_products')->result();
echo json_encode(array('products'=>$product,'posts'=>$posts,'views'=>$views));
}
}
public function getSingleInfo(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$id = $data->info_id;
$student_id = $data->user;
$user = $data->user;
$clicked = $data->clicked;
$info = array();
$author = "";
$this->db->select('i.*, c.name');
$this->db->order_by('i.id','desc')->limit(50);
$this->db->where('i.id',$id);
$this->db->from('business_informations as i');
$this->db->join('business_categories as c','c.id=i.category_id');
$infoData = $this->db->get()->result();
foreach($infoData as $data){
// related news
$this->db->select('i.*, c.name');
$this->db->where('i.category_id',$data->category_id);
$this->db->where('i.id != ',$data->id);
$this->db->limit(10)->order_by('i.id','RANDOM');
$this->db->from('business_informations as i');
$this->db->join('business_categories as c','c.id=i.category_id');
$infoData = $this->db->get()->result();
$info_related = array();
foreach($infoData as $dataRelated){
$info_related[] = array(
'id'=>$dataRelated->id,
'category_id'=>$dataRelated->category_id,
'title'=>$dataRelated->title,
'contents'=>$dataRelated->contents,
'file'=>$dataRelated->file,
'type'=>$dataRelated->type,
'date'=>$dataRelated->date,
'name'=>$dataRelated->name,
'views'=>$this->db->where('info_id',$dataRelated->id)->count_all_results('b_informations_readers'),
'read'=>$this->db->where('info_id',$dataRelated->id)->where('reader_id',$student_id)->count_all_results('b_informations_readers'),
);
}
$info= array(
'id'=>$data->id,
'category_id'=>$data->category_id,
'title'=>$data->title,
'contents'=>$data->contents,
'file'=>$data->file,
'type'=>$data->type,
'date'=>$data->date,
'name'=>$data->name,
'views'=>$this->db->where('info_id',$data->id)->count_all_results('b_informations_readers'),
'read'=>$this->db->where('info_id',$data->id)->where('reader_id',$id)->count_all_results('b_informations_readers'),
'author'=>$data->author ?? '',
'related'=>$info_related,
);
}
$array = array('info_id' =>$id, 'reader_id' =>$student_id, 'date'=>date('Y-m-d H:i:s'));
$data = array(
'info_id'=>$id,
'reader_id'=>$user,
'date'=>date('Y-m-d')
);
$count = $this->db->where('info_id',$id)->where('reader_id',$user)->count_all_results('b_informations_readers');
if($count){
$this->db->where('info_id',$id)->where('reader_id',$user)->update('b_informations_readers',$data);
}else{
$this->db->insert('b_informations_readers',$data);
}
if($clicked == 'yes'){
foreach($this->db->where('activity_id',$id)->where('audience','all')->get('notifications')->result() as $note){
$this->db->where('notification_id',$note->id)->update('notification_view',array('clicked'=>'yes'));
}
}
echo json_encode($info);
}
}
public function getSinglePost(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$post_id = $data->post_id;
$student_id = $data->student_id;
$clicked = $data->clicked;
$postArray = array();
$this->db->where('id',$post_id);
$posts = $this->db->get('posts');
foreach($posts->result() as $post){
$name = $photo = ''; $comments = $likes = array();
$postName = $postPhoto = '';
foreach($this->db->where('id',$post->student_id)->get('students')->result() as $student){
$name = $student->full_name;
$photo = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$commentor=0;
foreach($this->db->where('post_id',$post->id)->where('deleted',0)->get('comments')->result() as $comment){
$commentor = $comment->student_id;
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$comments[] = array(
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'comment'=>$comment->comment,
'date'=>$comment->date,
'time'=>$comment->time,
);
}
if($clicked == 'yes'){
foreach($this->db->where('student_id',$student_id)->where('category','comment')->where('notify_id',$commentor)->where('activity_id',$post_id)->get('notifications')->result() as $notification){
$this->db->where('notification_id',$notification->id)->update('notification_view',array('clicked'=>'yes'));
}
}
foreach($this->db->where('post_id',$post->id)->get('likes')->result() as $like){
foreach($this->db->where('id',$like->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$likes[] = array(
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'date'=>$like->date,
'time'=>$like->time,
);
}
$isliked = $this->db->where('student_id',$student_id)->where('post_id',$post->id)->count_all_results('likes');
$postArray = array(
'poster_id'=>$post->student_id,
'id'=>$post->id,
'name'=>$name,
'post_image'=>$post->post_image,
'photo'=>$photo,
'date'=>$post->date,
'time'=>$post->time,
'post'=>$post->post,
'title'=>$post->title,
'comments'=>$comments,
'likes'=>$likes,
'isliked'=>$isliked,
);
}
echo json_encode($postArray);
}
}
public function getSinglePostLikes(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$comments = $likes = array();
$data = json_decode($inputs);
$post_id = $data->post_id;
$student_id = $data->student_id;
$clicked = $data->clicked;
$postArray = array();
$this->db->where('id',$post_id);
$posts = $this->db->get('posts');
foreach($posts->result() as $post){
$name = $photo = '';
$postName = $postPhoto = '';
foreach($this->db->where('id',$post->student_id)->get('students')->result() as $student){
$name = $student->full_name;
$photo = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$liker=0;
foreach($this->db->where('post_id',$post->id)->order_by('id','desc')->get('likes')->result() as $comment){
$liker=$comment->student_id;
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$comments[] = array(
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'date'=>$comment->date,
'time'=>$comment->time,
);
}
if($clicked == 'yes'){
foreach($this->db->where('student_id',$student_id)->where('category','like')->where('notify_id',$liker)->where('activity_id',$post_id)->get('notifications')->result() as $notification){
$this->db->where('notification_id',$notification->id)->update('notification_view',array('clicked'=>'yes'));
}
}
$postArray = array(
'poster_id'=>$post->student_id,
'id'=>$post->id,
'name'=>$name,
'post_image'=>$post->post_image,
'photo'=>$photo,
'date'=>$post->date,
'time'=>$post->time,
'post'=>$post->post,
'title'=>$post->title,
'likes'=>$comments,
);
}
echo json_encode($postArray);
}
}
public function get_notification_count(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$nots = array();
$unread = 0;
$not = $this->db->limit(50)->where('notify_id !=',$student_id)->or_where('audience','all')->order_by('id','desc')->get('notifications');
foreach($not->result() as $notify){
if($student_id == $notify->student_id){
if($this->db->where('student_id',$student_id)->where('notification_id',$notify->id)->count_all_results('notification_view') == 0){
$unread++;
}
}else{
if($this->db->where('notification_id',$notify->id)->count_all_results('notification_view') == 0){
$unread++;
}
}
}
if($unread > 99 ){
$unread = $unread."+";
}
echo json_encode(array('unread'=>$unread));
}
}
public function get_notification(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$nots = array();
$unread = 0;
$not = $this->db->where('notify_id !=',$student_id)->or_where('audience','all')->limit(50)->order_by('id','desc')->get('notifications');
foreach($not->result() as $notify){
$clicked = 'no';
//insert to notification seen;
$array = array(
'notification_id'=>$notify->id,
'student_id'=>$student_id,
'datetime'=>date('Y-m-d H:i:s'),
'seen'=>'yes',
'clicked'=>'no',
);
if($this->db->where('notification_id',$notify->id)->count_all_results('notification_view') == 0){
$this->db->insert('notification_view',$array);
}
$readstatus = 'unseen';
$location = $name = $photo=NULL;
if($notify->notify_id > 0){
foreach($this->db->where('id',$notify->notify_id)->get('students')->result() as $student){
$name = $student->full_name;
$location = $student->location;
$photo = $student->profile_photo;
}
}
if($student_id == $notify->student_id){
foreach($this->db->where('student_id',$student_id)->where('notification_id',$notify->id)->get('notification_view')->result() as $clickedd){
$clicked = $clickedd->clicked;
}
}else{
foreach($this->db->where('notification_id',$notify->id)->get('notification_view')->result() as $clickedd){
$clicked = $clickedd->clicked;
}
}
$nots[] = array(
'seen'=>'yes',
'clicked'=>$clicked,
'photo'=>$photo,
'location'=>$location,
'name'=>$name,
'student_id'=>$notify->student_id,
'notify_id'=>$notify->notify_id,
'content'=>$notify->content,
'audience'=>$notify->audience,
'activity_id'=>$notify->activity_id,
'category'=>$notify->category,
'date'=>$notify->date,
);
}
if($unread > 99 ){
$unread = $unread."+";
}
echo json_encode(array('unread'=>$unread,'notifications'=>$nots));
}
}
public function post_exam(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$question_id = $data->data->id;
$question_id = $data->data->id;
$answer = $data->data->answer;
$jibu = $data->data->jibu;
$exam_id = $data->data->exam_id;
if(strtolower($data->data->answer) == strtolower($data->data->jibu)){
$mark = $data->data->mark;
}else{
$mark = 0;
}
$data = array(
'exam_id'=>$exam_id,
'question_id'=>$question_id,
'student_id'=>$student_id,
'correct_answer'=>strtolower($answer),
'student_answer'=>strtolower($jibu),
'mark'=>$mark,
'date'=>date('Y-m-d h:i'),
);
$dataUpdate = array(
'student_answer'=>strtolower($jibu),
'mark'=>$mark,
'date'=>date('Y-m-d h:i'),
);
$this->db->where('exam_id',$exam_id);
$this->db->where('question_id',$question_id);
$this->db->where('student_id',$student_id);
$c=$this->db->count_all_results('student_answers');
if($c>0){
$this->db->where('exam_id',$exam_id);
$this->db->where('question_id',$question_id);
$this->db->where('student_id',$student_id);
$this->db->update('student_answers',$dataUpdate);
}else{
$this->db->insert('student_answers',$data);
}
$student_score=0;
$this->db->select_sum('mark');
$this->db->from('student_answers');
$this->db->where('exam_id',$exam_id);
$this->db->where('student_id',$student_id);
foreach($this->db->get()->result() as $row_sum){
$sum=$row_sum->mark;
$student_score=$row_sum->mark;
}
$pass_mark='';
$this->db->where('id',$exam_id);
$get_pass=$this->db->get('exams');
foreach($get_pass->result() as $row_mark){
$pass_mark=$row_mark->pass;
}
if($pass_mark<=$student_score){
$remark='Pass';
}else{
$remark='Fail';
}
$dataSubmitted = array();
$this->db->where('exam_id',$exam_id);
$this->db->where('student_id',$student_id);
$submitted=$this->db->get('submitted_exams');
if($submitted->num_rows() > 0){
foreach($submitted->result() as $sub){
$dataSubmitted=array(
'exam_id'=>$exam_id,
'lesson_id'=>$sub->lesson_id,
'student_id'=>$student_id,
'pass_mark'=>$pass_mark,
'student_score'=>$student_score,
'remark'=>$remark,
'year'=>date('Y'),
'date'=>date('Y-m-d')
);
$this->db->where('exam_id',$exam_id);
$this->db->where('student_id',$student_id);
$this->db->update('submitted_exams',$dataSubmitted);
}
}else{
if($this->db->where('student_id',$student_id)->where('exam_id',$exam_id)->count_all_results('student_answers') > 0){
foreach($this->db->where('id',$exam_id)->get('exams')->result() as $sub){
$dataSubmitted=array(
'exam_id'=>$exam_id,
'lesson_id'=>$sub->lesson_id,
'student_id'=>$student_id,
'pass_mark'=>$pass_mark,
'student_score'=>$student_score,
'remark'=>$remark,
'year'=>date('Y'),
'date'=>date('D M')
);
$this->db->insert('submitted_exams',$dataSubmitted);
}
}
}
echo json_encode($dataSubmitted);
}else{
echo json_encode(array('error'=>"Bad request"));
}
}
public function like_post(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$post_id = $data->post;
$isliked = $this->db->where('student_id',$student_id)->where('post_id',$post_id)->count_all_results('likes');
if($isliked){
$this->db->where('student_id',$student_id)->where('post_id',$post_id)->delete('likes');
foreach($this->db->where('id',$post_id)->get('posts')->result() as $post){
$this->db->where('student_id',$post->student_id)->where('notify_id',$student_id)->where('category','like')->where('activity_id',$post_id)->delete('notifications');
}
}else{
$this->db->insert('likes',array('student_id'=>$student_id,'post_id'=>$post_id,'date'=>date('Y-m-d'),'time'=>date('H:i:s'),'status'=>0));
// notification here
foreach($this->db->where('id',$post_id)->get('posts')->result() as $post){
if($student_id != $post->student_id){
$count = $this->db->where('student_id',$post->student_id)->where('notify_id',$student_id)->where('category','like')->where('activity_id',$post_id)->count_all_results('notifications');
if($count == 0){
$note = array(
'student_id'=>$post->student_id,
'notify_id'=>$student_id,
'content'=>'liked your post',
'category'=>'like',
'activity_id'=>$post_id,
'audience'=>'single',
'date'=>date('Y-m-d H:i:s'),
);
$this->db->insert('notifications',$note);
}
}
}
}
}
}
public function send_comment(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$post_id = $data->post;
$comment = $data->comment;
if($data->reply){
$this->db->insert('comments_reply',array('comment_id'=>$data->comment_id,'student_id'=>$student_id,'post_id'=>$post_id,'comment'=>$this->Api_model->emoji($comment),'date'=>date('Y-m-d'),'time'=>date('H:i'),'status'=>0));
}else{
$this->db->insert('comments',array('student_id'=>$student_id,'post_id'=>$post_id,'comment'=>$this->Api_model->emoji($comment),'date'=>date('Y-m-d'),'time'=>date('H:i'),'status'=>0));
}
$comments = array();
foreach($this->db->where('post_id',$post_id)->where('deleted',0)->get('comments')->result() as $comment){
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$comments[] = array(
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'comment'=>$comment->comment,
'date'=>$comment->date,
'time'=>$comment->time,
);
}
// notification here
foreach($this->db->where('id',$post_id)->get('posts')->result() as $post){
if($student_id != $post->student_id ){
$note = array(
'student_id'=>$post->student_id,
'notify_id'=>$student_id,
'content'=>$data->reply ? 'replied on your comment':'commented on your post',
'category'=>'comment',
'activity_id'=>$post_id,
'audience'=>'single',
'date'=>date('Y-m-d H:i:s'),
);
$this->db->insert('notifications',$note);
}
}
echo json_encode($comments);
}
}
public function load_comments(){
// for user posts
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$id = $data->post_id;
$comments = array();
foreach($this->db->where('post_id',$id)->where('deleted',0)->get('comments')->result() as $comment){
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$replys = array();
foreach($this->db->where('post_id',$id)->where('comment_id',$comment->id)->where('deleted',0)->get('comments_reply')->result() as $commentRep){
foreach($this->db->where('id',$commentRep->student_id)->get('students')->result() as $student){
$postNameReply = $student->full_name;
$postPhotoReply = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$replys[] = array(
'id'=>$commentRep->id,
'student_id'=>$commentRep->student_id,
'name'=>$postNameReply,
'photo'=>$postPhotoReply,
'comment'=>$commentRep->comment,
'date'=>$commentRep->date,
'time'=>$commentRep->time,
'member'=>$this->Api_model->user_data($commentRep->student_id),
);
}
$comments[] = array(
'replys'=>$replys,
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'comment'=>$comment->comment,
'date'=>$comment->date,
'time'=>$comment->time,
'member'=>$this->Api_model->user_data($comment->student_id),
);
}
echo json_encode($comments);
}
}
public function delete_comment(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$comment_id = $data->comment_id;
$student_id = $data->user;
$update = array(
'date_deleted'=>date('Y-m-d H:i:s'),
'deletor'=>$student_id,
'deleted'=>1,
);
if($data->reply){
$this->db->where('id',$comment_id)->update('comments_reply',$update);
}else{
$this->db->where('id',$comment_id)->update('comments',$update);
}
foreach($this->db->where('id',$comment_id)->get('comments')->result() as $comm){
foreach($this->db->where('id',$comm->post_id)->get('posts')->result() as $post){
$this->db->where('student_id',$post->student_id)->where('notify_id',$student_id)->where('category','comment')->where('activity_id',$post->id)->delete('notifications');
}
}
echo json_encode(true);
}
}
public function load_market(){
$markets = array();
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$start = $data->start;
$limit = $data->limit;
$search = $data->search;
if(strlen($search) > 2){
$marketProduct = $this->db->like('name',$search,'BOTH')->limit(4)->get('marketProduct')->result();
}else{
$marketProduct = $this->db->limit($limit,$start)->get('marketProduct')->result();
}
foreach($marketProduct as $market){
$minPrice=$maxPrice=$date="";
$limit=0;
foreach($this->db->select('*, AVG(minPrice) as minPrice, AVG(maxPrice) as maxPrice, ')->where('product_id',$market->id)->order_by('date','desc')->get('marketProductPrices')->result() as $prod){
// tunapata last
$minPrice = $prod->minPrice;
$maxPrice = $prod->maxPrice;
}
$lastdate = $this->db->select('priceDate')->where('product_id',$market->id)->order_by('priceDate','desc')->limit(1)->get('marketProductPrices')->result();
foreach($lastdate as $d){
$date = date('d M, Y',strtotime($d->priceDate));
}
$markets[] = array(
'id'=>$market->id,
'name'=>$market->name,
'kipimo'=>$market->kipimo,
'date'=>$date,
'photo'=>$market->file,
'minPrice'=>number_format($minPrice),
'maxPrice'=>number_format($maxPrice),
'average'=>number_format(($minPrice+$maxPrice)/2),
);
}
echo json_encode($markets);
}
}
public function load_info(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$start = $data->start;
$limit = $data->limit;
$search = $data->search;
$info = array();
// this is for information
if(strlen($search) > 2){
$this->db->select('i.*, c.name');
$this->db->order_by('i.id','desc')->limit(5);
$this->db->like('i.title',$search,'BOTH');
$this->db->from('business_informations as i');
$this->db->join('business_categories as c','c.id=i.category_id');
$infoData = $this->db->get()->result();
}else{
$this->db->select('i.*, c.name');
$this->db->order_by('i.id','desc')->limit($limit,$start);
$this->db->from('business_informations as i');
$this->db->join('business_categories as c','c.id=i.category_id');
$infoData = $this->db->get()->result();
}
foreach($infoData as $data){
$info[] = array(
'id'=>$data->id,
'category_id'=>$data->category_id,
'title'=>$data->title,
'contents'=>$data->contents,
'file'=>$data->file,
'type'=>$data->type,
'date'=>$data->date,
'name'=>$data->name,
'views'=>$this->db->where('info_id',$data->id)->count_all_results('b_informations_readers'),
'read'=>$this->db->where('info_id',$data->id)->where('reader_id',$student_id)->count_all_results('b_informations_readers'),
);
}
echo json_encode($info);
}
}
public function load_posts(){
// for user posts
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$start = $data->start;
$limit = $data->limit;
$this->db->order_by('id','desc')->limit($limit,$start);
$posts = $this->db->get('posts');
$postArray = array();
foreach($posts->result() as $post){
$name = $photo = ''; $comments = $likes = array();
$postName = $postPhoto = '';
foreach($this->db->where('id',$post->student_id)->get('students')->result() as $student){
$name = $student->full_name;
$photo = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$totalComments = $this->db->where('post_id',$post->id)->where('deleted',0)->count_all_results('comments_reply');
$totalComments = $totalComments + $this->db->where('post_id',$post->id)->where('deleted',0)->count_all_results('comments');
foreach($this->db->where('post_id',$post->id)->where('deleted',0)->get('comments')->result() as $comment){
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$comments[] = array(
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'comment'=>$comment->comment,
'date'=>$comment->date,
'time'=>$comment->time,
);
}
foreach($this->db->where('post_id',$post->id)->get('likes')->result() as $like){
foreach($this->db->where('id',$like->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$likes[] = array(
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'date'=>$like->date,
'time'=>$like->time,
);
}
$isliked = $this->db->where('student_id',$student_id)->where('post_id',$post->id)->count_all_results('likes');
$postArray[] = array(
'poster_id'=>$post->student_id,
'id'=>$post->id,
'name'=>$name,
'post_image'=>$post->post_image,
'photo'=>$photo,
'date'=>$post->date,
'time'=>$post->time,
'title'=>$post->title,
'post'=>$post->post,
'comments'=>$comments,
'likes'=>$likes,
'isliked'=>$isliked,
'total_comments'=>$totalComments,
'member'=>$this->Api_model->user_data($post->student_id),
);
}
echo json_encode($postArray);
}
}
public function certificate(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$exam_id = $data->exam_id;
$lesson_id = $data->lesson_id;
$name = "";
foreach($this->db->where('id',$student_id)->get('students')->result() as $data){
$name = strtoupper($data->full_name);
}
$lesson = "";
foreach($this->db->where('id',$lesson_id)->get('lessons')->result() as $data){
$lesson = strtoupper($data->name);
}
$date = "";
foreach($this->db->where('exam_id',$exam_id)->where('lesson_id',$lesson_id)->where('student_id',$student_id)->get('submitted_exams')->result() as $data){
$date = strtoupper($data->date);
}
echo json_encode(array('name'=>$name,'date'=>$date,'lesson'=>$lesson));
}
}
public function exam_score(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$student_id = $data->user;
$exam_id = $data->exam_id;
$lesson_id = $data->lesson_id;
$remark = "";$pass = 0;
foreach($this->db->where('exam_id',$exam_id)->where('student_id',$student_id)->get('submitted_exams')->result() as $da){
$remark = $da->student_score."% ".$da->remark;
if($da->remark == 'Pass'){
$pass = 1;
}
}
$examinations = array();
foreach($this->db->where('id',$exam_id)->where('lesson_id',$lesson_id)->where('status','On')->get('exams')->result() as $exam){
$lesson = $exam->lesson_id;
$title = $exam->title;
$other_title = $exam->other_title;
$instructions = $exam->instructions;
$date = $exam->date;
$sections = array();
foreach($this->db->where('exam_id',$exam->id)->get('exam_sections')->result() as $section){
$sectiontitle = $section->title;
$sectioninstructions = $section->instructions;
$no_of_questions = $section->no_of_questions;
$questions = array();
foreach($this->db->where('section_id',$section->id)->get('exam_questions')->result() as $question){
$subquestions = array();
$this->db->where('exam_id',$exam->id)->where('section_id',$section->id)->where('question_id',$question->id);
foreach($this->db->get('questions')->result() as $sub){
$jibu = "";
$this->db->where('exam_id',$exam->id)->where('question_id',$sub->id)->where('student_id',$student_id);
$get = $this->db->get('student_answers');
foreach($get->result() as $da){
$jibu = $da->student_answer;
}
$subquestions[] = array(
'id'=>$sub->id,
'exam_id'=>$sub->exam_id,
'section_id'=>$sub->section_id,
'question_id'=>$sub->question_id,
'question_number'=>$sub->question_number,
'isList'=>$sub->isList,
'question'=>$sub->question,
'answer'=>$sub->answer,
'mark'=>$sub->mark,
'date'=>$sub->date,
'jibu'=>$jibu,
);
}
$questions[] = array(
'question_id'=>$question->id,
'section_id'=>$question->section_id,
'question_number'=>$question->question_number,
'swali'=>$question->swali,
'isList'=>$question->isList,
'subquestion'=>$subquestions,
'no_of_list_questions'=>$question->no_of_list_questions,
'type_of_list'=>$question->type_of_list,
'question_type'=>$question->question_type,
);
}
$sections[] = array(
'title'=>$sectiontitle = $section->title,
'instructions'=>$sectioninstructions = $section->instructions,
'questions_no'=>$no_of_questions = $section->no_of_questions,
'questions'=>$questions,
);
}
$examinations = array(
'exam'=>$exam->id,
'time'=>$exam->time,
'lesson_id'=>$exam->lesson_id,
'title'=>$title = $exam->title,
'other_title'=>$other_title = $exam->other_title,
'instructions'=>$instructions = $exam->instructions,
'date'=>$date = $exam->date,
'sections'=>$sections,
'results'=>$this->db->where('exam_id',$exam->id)->where('student_id',$student_id)->get('submitted_exams')->row(),
);
}
echo json_encode(array('passed'=>$pass,'remark'=>$remark,'exam'=>$examinations));
}
}
public function send_post(){
$student_id = $this->input->post('user');
$post = $this->Api_model->emoji($this->input->post('post'));
$this->db->insert('posts',array('title'=>$this->input->post('title'),'student_id'=>$student_id,'post'=>$post,'date'=>date('Y-m-d'),'time'=>date('H:i:s'),'status'=>0));
$post_id = $this->db->insert_id();
if(isset($_FILES['picture'])){
$filename = basename($_FILES['picture']['name']);
$ext = end(explode('.',$filename));
$target = time() . rand().".".$ext;
$storagename = "./template/img/posts/". $target;
$source_img = $_FILES["picture"]["tmp_name"];
$destination_img = $storagename;
}
$d = $this->compress($source_img, $destination_img, 50);
$this->db->where('id',$post_id)->update('posts',array('post_image'=>$target));
}
public function read_info(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$user = $data->user;
$info = $data->info;
$clicked = $data->clicked;
$data = array(
'info_id'=>$info,
'reader_id'=>$user,
'date'=>date('Y-m-d')
);
$count = $this->db->where('info_id',$info)->where('reader_id',$user)->count_all_results('b_informations_readers');
if($count){
$this->db->where('info_id',$info)->where('reader_id',$user)->update('b_informations_readers',$data);
}else{
$this->db->insert('b_informations_readers',$data);
}
if($clicked == 'yes'){
foreach($this->db->where('activity_id',$info)->where('audience','all')->get('notifications')->result() as $note){
$this->db->where('notification_id',$note->id)->update('notification_view',array('clicked'=>'yes'));
}
}
}
}
public function forgot_password(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$username = trim(str_replace(' ','',$data->username));
$this->db->where('mobile', $username);
$this->db->or_where('email', $username);
$this->db->limit(1);
$users = $this->db->get('students');
$newpassword = $this->randomString(6);
foreach($users->result() as $user){
$to = $user->email;
$subject = 'Password reset notification';
$message = 'Hello '.$user->full_name.' your new password is '.$newpassword;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: support@womenchamber.or.tz' . "\r\n" .
'Reply-To: support@womenchamber.or.tz' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){
$this->db->where('id',$user->id)->update('students',array('password'=>md5($newpassword),'password1'=>$newpassword));
}
echo json_encode(1);
}
if($users->num_rows() == 0){
echo json_encode(0);
}
}else{
echo json_encode(array('error'=>"Bad request"));
}
}
public function getCats(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo json_encode($this->db->get('business_categories')->result());
}
}
public function getCategories(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo json_encode($this->db->get('productCategories')->result());
}
}
public function getRegions(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo json_encode($this->db->get('region')->result());
}
}
public function getProducts(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo json_encode($this->db->where('category_id',$data->categoryId)->get('marketProduct')->result());
}
}
public function getMarkets(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo json_encode($this->db->where('region_id',$data->regionId)->get('markets')->result());
}
}
public function autologin() {
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
echo $this->Api_model->user($data->id);
}
}
public function create_product(){
error_reporting(0);
if($_POST){
$filename = basename($_FILES['picture']['name']);
$ext = end(explode('.',$filename));
$target = time() . rand().".".$ext;
$storagename = "./template/img/products/". $target;
$source_img = $_FILES["picture"]["tmp_name"];
$destination_img = $storagename;
$d = $this->compress($source_img, $destination_img, 50);
$array = array(
'student_id'=>$_POST['user'],
'title'=>str_replace('_','',$_POST['title']),
'descriptions'=>str_replace('}','',$_POST['desc']),
'price'=>$_POST['price'],
'unit'=>$_POST['unit'],
'photo'=>$target,
'date_uploaded'=>date('Y-m-d'),
);
if($_POST['id'] > 0){
$array = array(
'title'=>str_replace('_','',$_POST['title']),
'descriptions'=>str_replace('}','',$_POST['desc']),
'price'=>$_POST['price'],
'unit'=>$_POST['unit'],
);
$this->db->where('id',$_POST['id'])->update('business_products',$array);
}else{
$this->db->insert('business_products',$array);
}
}
}
public function get_user_posts(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$posts = $this->db->where('student_id',$data->user)->get('posts');
$postArray = array();
foreach($posts->result() as $post){
$name = $photo = ''; $comments = $likes = array();
$postName = $postPhoto = '';
foreach($this->db->where('id',$post->student_id)->get('students')->result() as $student){
$name = $student->full_name;
$photo = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
foreach($this->db->where('post_id',$post->id)->where('deleted',0)->get('comments')->result() as $comment){
foreach($this->db->where('id',$comment->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$comments[] = array(
'id'=>$comment->id,
'student_id'=>$comment->student_id,
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'comment'=>$comment->comment,
'date'=>$comment->date,
'time'=>$comment->time,
'member'=>$this->Api_model->user_data($comment->student_id),
);
}
foreach($this->db->where('post_id',$post->id)->get('likes')->result() as $like){
foreach($this->db->where('id',$like->student_id)->get('students')->result() as $student){
$postName = $student->full_name;
$postPhoto = $student->profile_photo ? base_url()."template/img/students_profiles/".$student->profile_photo :'';
}
$likes[] = array(
'name'=>$postName,
'photo'=>$postPhoto,
'name'=>$postName,
'date'=>$like->date,
'time'=>$like->time,
'member'=>$this->Api_model->user_data($student->id),
);
}
$isliked = $this->db->where('student_id',$data->session)->where('post_id',$post->id)->count_all_results('likes');
$postArray[] = array(
'poster_id'=>$post->student_id,
'id'=>$post->id,
'name'=>$name,
'post_image'=>$post->post_image,
'photo'=>$photo,
'date'=>$post->date,
'time'=>$post->time,
'post'=>$post->post,
'comments'=>$comments,
'likes'=>$likes,
'isliked'=>$isliked,
'member'=>$this->Api_model->user_data($post->student_id),
);
}
echo json_encode($postArray);
}
}
public function delete_product(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$this->db->where('id',$data->product)->where('student_id',$data->user)->delete('business_products');
}
echo 1;
}
public function update_student(){
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$type = $_REQUEST['type'];
if($type == 'personal'){
$data_ary = array(
'full_name'=>$data->name,
'email'=>$data->email,
'mobile'=>$data->mobile,
'other_mobile'=>$data->other_mobile,
'location'=>$data->location,
);
$this->db->where('id',$data->id);
$this->db->update('students',$data_ary);
}else{
$data_ary = array(
'business_name'=>$data->business,
'descriptions'=>$data->descriptions,
'business_address'=>$data->business_address,
'business_hours'=>$data->business_hours,
'call_number'=>$data->call_number,
'whatsapp_number'=>$data->whatsapp_number,
'business_email'=>$data->business_email,
'business_website'=>$data->business_website,
'facebook'=>$data->facebook,
'instagram'=>$data->instagram,
'twitter'=>$data->twitter,
);
$this->db->where('student_id',$data->id);
$this->db->update('business_profiles',$data_ary);
}
echo $this->Api_model->user($data->id);
}else{
echo json_encode('');
}
}
public function validate() {
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$username = trim(str_replace(' ','',$data->username));
$password = trim(str_replace(' ','',$data->password));
// checking if user use email of phone
$email = $username;
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// echo("$email is a valid email address");
$this->db->where('confirm', 1);
$this->db->where('email', $username);
$this->db->where('password', md5($password));
} else {
// echo("$email is not a valid email address");
$username = (int) filter_var($username, FILTER_SANITIZE_NUMBER_INT);
$username = '255'.substr($username,-9);
$this->db->where('confirm', 1);
$this->db->where('mobile', $username);
$this->db->where('password', md5($password));
}
$user = $this->db->get('students');
if($user->num_rows() == 0){
echo json_encode('Invalid');
}else{
foreach($user->result() as $u){
echo $this->Api_model->user($u->id);
}
}
}else{
echo json_encode(array('error'=>"Bad request"));
}
}
public function register() {
$inputs = file_get_contents("php://input");
if(json_decode($inputs)){
$data = json_decode($inputs);
$phone = (int) filter_var($data->phone, FILTER_SANITIZE_NUMBER_INT);
$email = strtolower($data->email);
$data_ary = array(
'full_name'=>$data->name,
'email'=>$email,
'gender'=>$data->gender,
'mobile'=>$phone,
'location'=>$data->location,
'password'=>md5($data->password),
'password1'=>$data->password,
'date_registered'=>date('Y-m-d H:i:s'),
'registered_through'=>'app',
);
$phoneCount = $this->db->where('mobile',$phone)->count_all_results('students');
$emailCount = $this->db->where('email',$email)->count_all_results('students');
if(($phoneCount + $emailCount) > 0){
echo json_encode(array('error'=>array('email'=>$emailCount, 'phone'=>$phoneCount)));
}else{
$this->db->insert('students',$data_ary);
$student_id=$this->db->insert_id();
$data1=array(
'student_id'=>$student_id,
'business_name'=>$data->business,
'descriptions'=>$data->details,
);
$this->db->insert('business_profiles',$data1);
//function to send email
$name=$data->name;
$to = $data->email;
$subject = "Welcome to TWCC Platform";
$username=$data->phone;
$email=$data->email;
// $url= 'https://womenchamber.or.tz/Welcome/verify_email?verified='.base64_encode($student_id);
$message = "Use your phone number (".$username.") or email address(".$email. ") to login.
Tanzania Women chamber of Commerce (TWCC)
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers = 'From: support@womenchamber.or.tz' . "\r\n" .
'Reply-To: support@womenchamber.or.tz' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$headers);
echo $this->Api_model->user($student_id);
}
}else{
echo json_encode(array('error'=>"Bad request"));
}
}
public function change_profile(){
// Turn off all error reporting
error_reporting(0);
// $user = $_REQUEST['id'];
$user = $this->input->post('user');
$filename = basename($_FILES['picture']['name']);
$ext = end(explode('.',$filename));
$target = time() . rand().".".$ext;
$storagename = "./template/img/students_profiles/". $target;
$source_img = $_FILES["picture"]["tmp_name"];
$destination_img = $storagename;
$d = $this->compress($source_img, $destination_img, 50);
$this->db->where('id',$user)->update('students',array('profile_photo'=>$target));
echo json_encode(array('profile_photo'=>base_url('template/img/students_profiles/'.$target)));
// if(move_uploaded_file($_FILES["picture"]["tmp_name"], $storagename)){
// $this->db->where('id',$user)->update('students',array('profile_photo'=>$target));
// echo 1;
// }else{
// echo 0;
// }
//$this->db->where('id',$user)->update('students',array('profile_photo'=>$targetFile));
}
}