Beispiel #1
0
 /**
  * @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);
 }
Beispiel #2
0
 /**
  * @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);
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 /**
  * @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);
     }
 }
Beispiel #5
0
 public function search()
 {
     $this->seo(array("title" => "Search", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $diff = 65;
     $test_ids = RequestMethods::get("test", array());
     $city = RequestMethods::get("city", "");
     $area = RequestMethods::get("area", "");
     if (strlen($city) > 0 && strlen($area) > 0) {
         if (!isset($_COOKIE["cityId"])) {
             setcookie("cityId", $city, time() + 86400 * 30, "/");
         }
         if (!isset($_COOKIE["areaId"])) {
             setcookie("areaId", $area, time() + 86400 * 30, "/");
             $a = Area::first(array("id = ?" => $area), array("name"));
             setcookie("areaName", $a->name, time() + 86400 * 30, "/");
         }
     }
     $in = implode(",", $test_ids);
     $size = sizeof($test_ids);
     $database = Registry::get("database");
     $result = $database->execute("SELECT centre_id FROM services WHERE city_id={$city} AND area_id={$area} AND property='test' AND property_id IN ({$in}) GROUP BY centre_id HAVING count(distinct property_id) = {$size}");
     $centres = array();
     if ($result) {
         for ($i = 0; $i < $result->num_rows; $i++) {
             $data = $result->fetch_array(MYSQLI_ASSOC);
             $centres[] = $data["centre_id"];
         }
     }
     //echo "<pre>", print_r($centres), "</pre>";
     $alltests = Test::all(array("live = ?" => true), array("id", "title"));
     $view->set("area", $area);
     $view->set("city", $city);
     $view->set("centres", $centres);
     $view->set("alltests", $alltests);
     $view->set("test_ids", $test_ids);
 }