Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * @before _secure, _vendor
  */
 public function update($id)
 {
     $this->seo(array("title" => "Edit Lab", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $centre = Centre::first(array("id = ?" => $id));
     if (RequestMethods::get("live")) {
         $centre->live = RequestMethods::get("live", 0);
         $centre->save();
         $this->redirect("/lab/manage");
     }
     $location = Location::first(array("id = ?" => $centre->location_id));
     $areas = Area::all(array("city_id = ?" => $location->city_id), array("name", "id"));
     $manager = User::first(array("id = ?" => $this->member->user_id));
     if (RequestMethods::post("action") == "medicallab") {
         $message = null;
         $location->street = RequestMethods::post("street");
         $location->area_id = RequestMethods::post("area_id");
         $location->city_id = RequestMethods::post("city_id");
         if ($location->validate()) {
             $location->save();
         } else {
             $message = "Center location was not saved!!";
         }
         $phone = RequestMethods::post("phone");
         if ($phone != $centre->phone) {
             $exist = Center::first(array("phone = ?" => $phone));
             if ($exist) {
                 $message = "Phone number already exists";
             } else {
                 $centre->phone = $phone;
                 $centre->save();
             }
         }
         if (!$message) {
             $message = "Lab 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("manager", $manager);
     $view->set("location", $location);
     $view->set("areas", $areas);
     $view->set("opa", $opa);
 }