/** * @before _secure, _school */ public function index() { $this->setSEO(array("title" => "Admin | School | Dashboard")); $view = $this->getActionView(); $counts = array(); $counts["students"] = Scholar::count(array("organization_id = ?" => $this->organization->id)); $counts["teachers"] = Educator::count(array("organization_id = ?" => $this->organization->id)); $counts["classes"] = Grade::count(array("organization_id = ?" => $this->organization->id)); $counts = ArrayMethods::toObject($counts); $session = Registry::get("session"); $message = $session->get("redirectMessage"); if ($message) { $view->set("message", $message); $session->erase("redirectMessage"); } $view->set("counts", $counts); }
/** * @before _secure, _school */ public function edit($teacher_id) { $teacher = \Educator::first(array("id = ?" => $teacher_id), array("user_id", "organization_id")); if (!$teacher || $teacher->organization_id != $this->organization->id) { self::redirect("/school"); } $this->setSEO(array("title" => "Profile")); $view = $this->getActionView(); $usr = \User::first(array("id = ?" => $teacher->user_id)); if (RequestMethods::post("action") == "editTeacher") { $email = RequestMethods::post("email"); $phone = RequestMethods::post("phone"); $emailExist = $email != $usr->email ? \User::first(array("email = ?" => $email), array("id")) : false; $phoneExist = $phone != $usr->phone ? \User::first(array("phone = ?" => $phone), array("id")) : false; if ($emailExist) { $view->set("error", true); $view->set("message", "Failed to edit the teacher! Email already exists"); } elseif ($phoneExist) { $view->set("error", true); $view->set("message", "Phone number already exists!! Enter different phone"); } else { $usr->name = RequestMethods::post("name"); $usr->email = $email; $usr->phone = $phone; $usr->save(); $view->set("message", "Teacher edited successfully!!"); } } $view->set("teacher", $usr); }
protected function _checkLogin() { if (RequestMethods::post("action") == "logmein") { $username = RequestMethods::post("username"); $password = RequestMethods::post("password"); $user = User::first(array("username = ?" => $username, "live = ?" => true)); if (!$user) { return array("error" => "Invalid username/password"); } if (!Markup::checkHash($password, $user->password)) { return array("error" => "Invalid username/password"); } $session = Registry::get("session"); $this->setUser($user); if ($user->admin) { self::redirect("/admin"); } $headers = getallheaders(); $scholar = Scholar::first(array("user_id = ?" => $user->id)); if ($scholar) { $session->set('scholar', $scholar); $organization = Organization::first(array("id = ?" => $scholar->organization_id)); $session->set('organization', $organization); if (isset($headers["X-Student-App"])) { $meta = $this->_meta($user, "student"); return array("success" => true, "meta" => $meta, "scholar" => $scholar); } else { self::redirect("/student"); } } $organization = Organization::first(array("user_id = ?" => $user->id)); if ($organization) { $session->set('organization', $organization); self::redirect("/school"); } $educator = Educator::first(array("user_id = ?" => $user->id)); if ($educator) { $session->set('educator', $educator); $organization = Organization::first(array("id = ?" => $educator->organization_id)); $session->set('organization', $organization); if (isset($headers["X-Teacher-App"])) { $meta = $this->_meta($user, "teacher"); return array("success" => true, "meta" => $meta, "educator" => $educator); } else { self::redirect("/teacher"); } } return array("error" => "Something went wrong please try again later"); } else { return array("error" => "Invalid Request"); } }
/** * @before _secure, _school */ public function edit($classroom_id, $grade_id) { $classroom = \Classroom::first(array("id = ?" => $classroom_id)); $grade = \Grade::first(array("id = ?" => $grade_id), array("id", "title", "organization_id")); if (!$classroom || $classroom->organization_id != $this->organization->id) { self::redirect("/school"); } if (!$grade || $classroom->grade_id != $grade->id || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } $this->setSEO(array("title" => "Edit Section | School")); $view = $this->getActionView(); if (RequestMethods::post("action") == "editClassroom") { $classroom->year = RequestMethods::post("year"); $classroom->section = RequestMethods::post("section"); $classroom->remarks = RequestMethods::post("remarks"); $classroom->educator_id = RequestMethods::post("educator"); $classroom->save(); $view->set("success", "Grade section edited successfully!!"); } $teachers = \Educator::all(array("organization_id = ?" => $this->organization->id), array("user_id", "organization_id", "id")); $view->set("teachers", $teachers); $view->set("grade", $grade); $view->set("classroom", $classroom); }