public function update()
 {
     if (isset($_REQUEST['person_id'])) {
         // Load the user for editing
         try {
             $user = new Person($_REQUEST['person_id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
             header('Location: ' . BASE_URL . '/users');
             exit;
         }
     } else {
         $user = new Person();
     }
     // Handle POST data
     if (isset($_POST['username'])) {
         try {
             $user->handleUpdateUserAccount($_POST);
             $user->save();
             header('Location: ' . BASE_URL . '/users');
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     // Display the form
     if ($user->getId()) {
         $this->template->blocks[] = new Block('people/personInfo.inc', array('person' => $user, 'disableButtons' => true));
     }
     $this->template->blocks[] = new Block('users/updateUserForm.inc', array('person' => $user));
 }
Example #2
0
 public function testSaveAndLoad()
 {
     $person = new Person($this->testPersonId);
     $this->assertEquals($this->testPersonId, $person->getId());
     $address = new Address();
     $address->setAddress('test');
     $address->setPerson($person);
     $address->save();
     $id = $address->getId();
     $this->assertNotEmpty($id);
     $address = new Address($id);
     $this->assertEquals('test', $address->getAddress());
     $this->assertEquals(1, $address->getPerson_id());
 }
 /**
  * @param string $fieldname The name of the person field
  * @param Person $person The currently selected Person object
  * @return string
  */
 public function personChooser($fieldname, Person $person = null)
 {
     $this->template->addToAsset('scripts', JQUERY . '/jquery.min.js');
     $this->template->addToAsset('scripts', BASE_URI . '/js/people/personChooser.js');
     $id = '';
     $name = '';
     if ($person) {
         $id = $person->getId();
         $name = View::escape($person->getFullname());
     }
     $return_url = new Url($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     $personChooser = BASE_URI . '/people?return_url=' . $return_url;
     $html = "\n\t\t<input type=\"hidden\" name=\"{$fieldname}_id\" id=\"{$fieldname}_id\" value=\"{$id}\" />\n\t\t<span id=\"{$fieldname}-name\">{$name}</span>\n\t\t<a class=\"btn\"\n\t\t\thref=\"{$personChooser}\"\n\t\t\tonclick=\"PERSON_CHOOSER.open('{$fieldname}');return false;\">\n\t\t\t<span class=\"fa fa-user\"></span>\n\t\t\tChange Person\n\t\t</a>\n\t\t";
     return $html;
 }
 public function update(array $params)
 {
     if (!empty($_REQUEST['id'])) {
         try {
             $person = new Person($_REQUEST['id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     } else {
         $person = new Person();
     }
     if (isset($person)) {
         if (isset($_POST['username'])) {
             try {
                 $person->handleUpdateUserAccount($_POST);
                 // We might have populated this person's information from LDAP
                 // We need to do a new lookup in the system, to see if a person
                 // with their email address already exists.
                 // If they already exist, we should add the account info to that
                 // person record.
                 if (!$person->getId() && $person->getEmail()) {
                     try {
                         $existingPerson = new Person($person->getEmail());
                         $existingPerson->handleUpdateUserAccount($_POST);
                     } catch (\Exception $e) {
                     }
                 }
                 if (isset($existingPerson)) {
                     $existingPerson->save();
                 } else {
                     $person->save();
                 }
                 header('Location: ' . BASE_URL . '/users');
                 exit;
             } catch (\Exception $e) {
                 $_SESSION['errorMessages'][] = $e;
             }
         }
         return new \Application\Views\Users\UpdateView(['user' => $person]);
     } else {
         return new \Applications\Views\NotFoundView();
     }
 }
 public function update()
 {
     $errorURL = isset($_REQUEST['return_url']) ? $_REQUEST['return_url'] : BASE_URL . '/people';
     if (isset($_REQUEST['person_id']) && $_REQUEST['person_id']) {
         try {
             $person = new Person($_REQUEST['person_id']);
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
             header("Location: {$errorURL}");
             exit;
         }
     } else {
         $person = new Person();
     }
     if (isset($_POST['firstname'])) {
         try {
             $newRecord = $person->getId() ? false : true;
             $person->handleUpdate($_POST);
             $person->save();
             if ($newRecord) {
                 if (!empty($_POST['email'])) {
                     $email = new Email();
                     $email->setPerson($person);
                     $email->setEmail($_POST['email']);
                     $email->save();
                 }
                 if (!empty($_POST['phone'])) {
                     $phone = new Phone();
                     $phone->setPerson($person);
                     $phone->setNumber($_POST['phone']);
                     $phone->save();
                 }
             }
             if (isset($_REQUEST['return_url'])) {
                 $return_url = new Url($_REQUEST['return_url']);
                 $return_url->person_id = $person->getId();
             } elseif (isset($_REQUEST['callback'])) {
                 $return_url = new Url(BASE_URL . '/callback');
                 $return_url->callback = $_REQUEST['callback'];
                 $return_url->data = "{$person->getId()}";
             } else {
                 $return_url = $person->getURL();
             }
             header("Location: {$return_url}");
             exit;
         } catch (\Exception $e) {
             $_SESSION['errorMessages'][] = $e;
         }
     }
     $this->template->title = 'Update a person';
     $this->template->blocks[] = new Block('people/updatePersonForm.inc', array('person' => $person));
 }
Example #6
0
 /**
  * Transfers all data from a person, then deletes that person
  *
  * This person will end up containing all information from both people
  * I took care to make sure to update the search index as well
  * as the database.
  *
  * @param Person $person
  */
 public function mergeFrom(Person $person)
 {
     if ($this->getId() && $person->getId()) {
         if ($this->getId() == $person->getId()) {
             // can not merge same person throw exception
             throw new \Exception('mergerNotAllowed');
         }
         $zend_db = Database::getConnection();
         // Look up all the tickets we're about to modify
         // We need to remember them so we can update the search
         // index after we've updated the database
         $id = (int) $person->getId();
         $sql = "select distinct t.id from tickets t\n\t\t\t\t\tleft join ticketHistory th on t.id=th.ticket_id\n\t\t\t\t\tleft join issues         i on t.id= i.ticket_id\n\t\t\t\t\tleft join issueHistory  ih on i.id=ih.issue_id\n\t\t\t\t\tleft join media          m on i.id= m.issue_id\n\t\t\t\t\tleft join responses      r on i.id= r.issue_id\n\t\t\t\t\twhere ( t.enteredByPerson_id={$id} or t.assignedPerson_id={$id} or t.referredPerson_id={$id})\n\t\t\t\t\t   or (th.enteredByPerson_id={$id} or th.actionPerson_id={$id})\n\t\t\t\t\t   or ( i.enteredByPerson_id={$id} or i.reportedByPerson_id={$id})\n\t\t\t\t\t   or (ih.enteredByPerson_id={$id} or ih.actionPerson_id={$id})\n\t\t\t\t\t   or m.person_id={$id} or r.person_id={$id}";
         $result = $zend_db->query($sql)->execute();
         $ticketIds = [];
         foreach ($result as $row) {
             $ticketIds[] = $row['id'];
         }
         $zend_db->getDriver()->getConnection()->beginTransaction();
         try {
             // These are all the database fields that hit the Solr index
             $zend_db->query('update responses     set           person_id=? where           person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update media         set           person_id=? where           person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issueHistory  set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issueHistory  set     actionPerson_id=? where     actionPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issues        set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update issues        set reportedByPerson_id=? where reportedByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update ticketHistory set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update ticketHistory set     actionPerson_id=? where     actionPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set  enteredByPerson_id=? where  enteredByPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set   assignedPerson_id=? where   assignedPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update tickets       set   referredPerson_id=? where   referredPerson_id=?')->execute([$this->getId(), $person->getId()]);
             // Fields that don't hit the Solr index
             $zend_db->query('update clients         set contactPerson_id=? where contactPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update departments     set defaultPerson_id=? where defaultPerson_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peopleAddresses set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peoplePhones    set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('update peopleEmails    set        person_id=? where        person_id=?')->execute([$this->getId(), $person->getId()]);
             $zend_db->query('delete from people where id=?')->execute([$person->getId()]);
         } catch (Exception $e) {
             $zend_db->getDriver()->getConnection()->rollback();
             throw $e;
         }
         $zend_db->getDriver()->getConnection()->commit();
         foreach ($ticketIds as $id) {
             $search = new Search();
             $ticket = new Ticket($id);
             $search->add($ticket);
         }
     }
 }