/** * @before _secure, _vendor */ public function settings() { $this->seo(array("title" => "Settings", "view" => $this->getLayoutView())); $view = $this->getActionView(); $centre = Centre::first(array("id = ?" => $this->member->centre_id)); $location = Location::first(array("id = ?" => $centre->location_id)); $area = Area::first(array("id = ?" => $location->area_id)); if (RequestMethods::post("action") == "settings") { $phone = RequestMethods::post("phone"); $user = $this->user; $message = null; if ($phone != $user->phone) { $exist = User::first(array("phone = ?" => $phone)); if ($exist) { $message = "Phone number already exists"; } else { $user->phone = $phone; } } $user->name = RequestMethods::post("name"); $user->save(); $this->setUser($user); $location = \Location::saveRecord($user, $location); $phone = RequestMethods::post("cphone"); if ($centre->phone != $phone) { $exist = Centre::first(array("phone = ?" => $phone)); if ($exist) { $message = "Landline already exists!!"; } else { $centre->phone = $phone; $centre->save(); } } if (!$message) { $message = "Info updated!!"; } $view->set("message", $message); } if (RequestMethods::post("action") == "operations") { $operations = RequestMethods::post("operations"); foreach ($operations as $key => $value) { $operation = Operation::first(array("centre_id = ?" => $id, "area_id = ?" => $value)); if (!$operation) { $operation = new Operation(array("user_id" => $this->user->id, "centre_id" => $id, "organization_id" => $this->organization->id, "area_id" => $value, "live" => 1)); $operation->save(); } } } $ops = Operation::all(array("centre_id = ?" => $id), array("area_id")); $opa = array(); foreach ($ops as $o) { $opa[] = $o->area_id; } $view->set("centre", $centre); $view->set("area", $area); $view->set("location", $location); $view->set("opa", $opa); }
/** * @before _secure, _vendor */ public function create() { $this->seo(array("title" => "Create runner", "view" => $this->getLayoutView())); $view = $this->getActionView(); $msg = ""; $centres = Centre::all(array("organization_id = ?" => $this->organization->id), array("id", "location_id")); $upload = function ($key) { if (isset($_FILES["image"]["name"][$key])) { $file = $_FILES["image"]; $path = APP_PATH . "/public/assets/uploads/images/"; $extension = pathinfo($file["name"][$key], PATHINFO_EXTENSION); if (!preg_match("/^(jpe?g|gif|png|bmp)\$/", $extension)) { return false; } $filename = uniqid() . ".{$extension}"; if (move_uploaded_file($file["tmp_name"][$key], $path . $filename)) { return $filename; } else { return FALSE; } } else { return false; } }; if (RequestMethods::post("phone")) { $phone = RequestMethods::post("phone"); $name = RequestMethods::post("name"); $centre_id = RequestMethods::post("centre_id"); foreach ($phone as $key => $value) { if (!empty($value)) { $exist = User::first(array("phone = ?" => $phone[$key]), array("id")); $img = $upload($key); if (!$img) { $msg = 'Not a vaild image'; } else { if ($exist) { $msg = 'Phone number already exists'; } } if (!$exist && $img) { $user = new User(array("name" => $name[$key], "email" => "", "phone" => $phone[$key], "password" => sha1(rand(100000, 9999999)), "gender" => $gender[$key], "birthday" => "", "live" => true)); $user->save(); foreach ($centre_id[$key] as $k => $v) { $runner = new Member(array("user_id" => $user->id, "organization_id" => $this->organization->id, "centre_id" => $v, "designation" => "runner", "image" => $img, "live" => true)); $runner->save(); } $msg = "Runner Created Successfully"; } else { $msg .= ", Not all were added"; } } } $view->set("message", $msg); } $locations = array(); foreach ($centres as $c) { $l = Location::first(array("id = ?" => $c->location_id), array("area_id")); $a = Area::first(array("id = ?" => $l->area_id), array("name", "id")); $data = array("id" => $c->id, "name" => $a->name); $data = ArrayMethods::toObject($data); $locations[$c->id] = $data; } $view->set("centres", $locations); }
/** * @before _secure, _school */ public function edit($user_id) { $this->setSEO(array("title" => "Edit Student Info | School")); $view = $this->getActionView(); $user = User::first(array("id = ?" => $user_id)); $scholar = Scholar::first(array("user_id = ?" => $user->id)); if (!$scholar || $scholar->organization_id != $this->organization->id) { self::redirect("/404"); } $location = Location::first(array("user_id = ?" => $user->id)); if (RequestMethods::post("action") == "updateInfo") { $user->name = RequestMethods::post("name"); $user->email = RequestMethods::post("email"); $user->phone = RequestMethods::post("phone"); $user->save(); $location->address = RequestMethods::post("address"); $location->city = RequestMethods::post("city"); if ($location->validate()) { $location->save(); } $scholar->dob = RequestMethods::post("dob"); $scholar->roll_no = RequestMethods::post("roll_no"); if ($scholar->validate()) { $scholar->save(); } $view->set("success", "Saved successfully!!"); } $view->set("usr", $user); $view->set("scholar", $scholar); $view->set("location", $location); }
/** * @before _secure, _vendor */ public function display($id) { $this->seo(array("title" => "Display Appointments", "view" => $this->getLayoutView())); $view = $this->getActionView(); $apptmt = Appointment::first(array("id = ?" => $id), array("service_id", "id", "start", "centre_id", "user_id", "location_id")); $usr = User::first(array("id = ?" => $apptmt->user_id), array("id", "name", "email", "phone")); $job = Job::first(array("appointment_id = ?" => $apptmt->id), array("user_id", "id")); $location = Location::first(array("id = ?" => $apptmt->location_id), array("street", "area_id", "city_id")); $area = Area::first(array("id = ?" => $location->area_id), array("name")); $city = City::first(array("id = ?" => $location->city_id), array("name")); if (!$apptmt) { $view->set("err", "Invalid ID"); } else { $view->set("usr", $usr); $view->set("job", $job); $view->set("e", $apptmt); $view->set("address", $location->street . ", " . $area->name . ", " . $city->name); } }
public function details($title, $id = '') { $organization = Organization::first(array("id = ?" => $id)); $this->seo(array("title" => $organization->name, "keywords" => $organization->name, "description" => substr(strip_tags($organization->details), 0, 150), "view" => $this->getLayoutView())); $view = $this->getActionView(); $centre = Centre::first(array("organization_id = ?" => $id), array("*"), "created", "desc"); $services = Service::all(array("centre_id = ?" => $centre->id), array("property", "property_id", "charge")); $location = Location::first(array("id = ?" => $centre->location_id), array("street", "area_id", "city_id")); $area = Area::first(array("id = ?" => $location->area_id), array("name")); $city = City::first(array("id = ?" => $location->city_id), array("name")); $view->set("centre", $centre); $view->set("area", $area); $view->set("city", $city); $view->set("location", $location); $view->set("services", $services); $view->set("organization", $organization); }
/** * @before _secure, _vendor */ public function download() { $this->noview(); $tests = Test::all(array("live = ?" => true), array("title")); $centres = Centre::all(array("organization_id = ?" => $this->organization->id), array("location_id")); $locations = array(); foreach ($centres as $centre) { $loc = Location::first(array("id = ?" => $centre->location_id), array("city")); array_push($locations, $loc->city); } header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=medicaltests.csv'); // create a file pointer connected to the output stream $output = fopen('php://output', 'w'); $first = array("Medical Test"); $locations = array_unique($locations); foreach ($locations as $location) { array_push($first, "Price at " . $location); } fputcsv($output, $first); foreach ($tests as $test) { $data = array(); array_push($data, $test->title); foreach ($locations as $location) { array_push($data, ""); } fputcsv($output, $data); } }