public function personsListAction() { //get societe/location and serving $reponse = new Reponse(); $societe = $this->societe; $persons = $societe->getPersons(); //we check if we are in the Editor if ($_POST['action']) { //if REMOVE if ($_POST['action'] == "remove") { foreach ($_POST['id'] as $id) { $person = Object_Person::getById($id, 1); if ($person instanceof \Object\Person) { $person->delete(); } } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = ''; } //if EDIT if ($_POST['action'] == "edit") { $person = \Object\Person::getById($_POST['id']); if ($person instanceof Object_Person) { $person->setFirstname($_POST['data']['firstname']); $person->setLastname($_POST['data']['lastname']); $person->setEmail($_POST['data']['email']); $person->setPhone($_POST['data']['phone']); $person->setPermits($_POST['data']['permits']); $location = Object\Location::getById($_POST['data']['locationid'], 1); $person->setLocation($location); $person->setPassword(md5($_POST['data']['password'])); $person->save(); } $data = $_POST['data']; $data['DT_RowId'] = "row_" . $_POST['data']['id']; $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->row = $data; } //if CREATE if ($_POST['action'] == "create") { $row['firstname'] = $_POST['data']['firstname']; $row['lastname'] = $_POST['data']['lastname']; $row['email'] = $_POST['data']['email']; $row['phone'] = $_POST['data']['phone']; $row['permits'] = $_POST['data']['permits']; $location = Object\Location::getById($_POST['data']['locationid'], 1); $row['location'] = $location; $row['password'] = md5($_POST['data']['password']); $current = Object\Person::getByEmail($row['email'], 1); if ($current instanceof Object\Person) { $error['name'] = "email"; $error['status'] = "Email already exists"; $reponse->fieldErrors = array($error); } else { $result = $societe->createPerson($row); if ($result instanceof \Object\Person) { $row['DT_RowId'] = $result->getId(); $row['id'] = $result->getId(); $row['locationid'] = $result->getLocation()->getId(); $row['locationname'] = $result->getLocation()->getName(); $reponse->success = true; $reponse->message = "TXT_CREATE_OK"; $reponse->row = $row; $reponse->debug = $data; } else { $reponse->success = false; $reponse->message = "TXT_CREATE_ERROR"; $reponse->row = $result; $reponse->debug = $result; } } } } else { $data = array(); foreach ($persons as $key => $person) { $i++; $array = array(); $array = $person->toArray(); $array['id'] = $person->getId(); $array['DT_RowId'] = $person->getId(); array_push($data, $array); } $reponse->message = 'TXT_RESERVATION_LIST'; $reponse->success = true; $reponse->data = $data; } $this->render($reponse); }
public function objectFormAction() { $success = false; // getting parameters is very easy ... just call $this->getParam("yorParamKey"); regardless if's POST or GET if ($this->getParam("firstname") && $this->getParam("lastname") && $this->getParam("email") && $this->getParam("terms")) { $success = true; // for this example the class "person" and "inquiry" is used // first we create a person, then we create an inquiry object and link them together // check for an existing person with this name $person = Object\Person::getByEmail($this->getParam("email"), 1); if (!$person) { // if there isn't an existing, ... create one $filename = \Pimcore\File::getValidFilename($this->getParam("email")); // first we need to create a new object, and fill some system-related information $person = new Object\Person(); $person->setParent(Object::getByPath("/crm/inquiries")); // we store all objects in /crm $person->setKey($filename); // the filename of the object $person->setPublished(true); // yep, it should be published :) // of course this needs some validation here in production... $person->setGender($this->getParam("gender")); $person->setFirstname($this->getParam("firstname")); $person->setLastname($this->getParam("lastname")); $person->setEmail($this->getParam("email")); $person->setDateRegister(new \DateTime()); $person->save(); } // now we create the inquiry object and link the person in it $inquiryFilename = \Pimcore\File::getValidFilename(date("Y-m-d") . "~" . $person->getEmail()); $inquiry = new Object\Inquiry(); $inquiry->setParent(Object::getByPath("/inquiries")); // we store all objects in /inquiries $inquiry->setKey($inquiryFilename); // the filename of the object $inquiry->setPublished(true); // yep, it should be published :) // now we fill in the data $inquiry->setMessage($this->getParam("message")); $inquiry->setPerson($person); $inquiry->setDate(new \DateTime()); $inquiry->setTerms((bool) $this->getParam("terms")); $inquiry->save(); } elseif ($this->getRequest()->isPost()) { $this->view->error = true; } // do some validation & assign the parameters to the view foreach (["firstname", "lastname", "email", "message", "terms"] as $key) { if ($this->getParam($key)) { $this->view->{$key} = htmlentities(strip_tags($this->getParam($key))); } } // assign the status to the view $this->view->success = $success; }
public function checkEmailAction() { $reponse = new Reponse(); if ($this->getRequest()->isGet() or $this->getRequest()->isPost()) { $email = $this->getParam('email'); $member = Object\Person::getByEmail($email, 1); if ($member instanceof Object\Person) { $reponse->message = 'TXT_EMAIL_EXIST'; $reponse->success = true; } else { $reponse->message = 'TXT_EMAIL_UNKNOWN'; $reponse->success = false; } } else { $reponse->message = 'TXT_EMAIL_NOTRECEIVED'; $reponse->success = false; } $this->render($reponse, 'success'); }