/** * * @param IXP_Form_Contact $form The form object * @param \Entities\Contact $object The Doctrine2 entity (being edited or blank for add) * @param bool $isEdit True of we are editing an object, false otherwise * @param array $options Options passed onto Zend_Form * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked * @return void */ protected function formPostProcess($form, $object, $isEdit, $options = null, $cancelLocation = null) { if ($isEdit) { $form->getElement('custid')->setValue($object->getCustomer()->getId()); $form->getElement('cabinetid')->setValue($object->getCabinet()->getId()); } }
public function getCustomer() { $this->__load(); return parent::getCustomer(); }
/** * Creates/updates/deletes the user for a contact when adding / editing a contact * * @param IXP_Form_Contact $form The form object * @param \Entities\Contact $contact The Doctrine2 entity (being edited or blank for add) * @param bool $isEdit True of we are editing an object, false otherwise */ private function _processUser($form, $contact, $isEdit) { if ($form->getValue("login")) { // the contact has a user already or one needs to be created if (!($user = $contact->getUser())) { $user = new \Entities\User(); $contact->setUser($user); $user->setCreated(new DateTime()); $user->setCreator($this->getUser()->getUsername()); // these should only be updated by CUSTADMIN on creation of a login account if ($this->getUser()->getPrivs() <= \Entities\User::AUTH_CUSTADMIN) { $user->setPrivs(\Entities\User::AUTH_CUSTUSER); $user->setPassword(OSS_Auth_Password::hash(OSS_String::random(16), $this->_options['resources']['auth']['oss'])); $user->setUsername($form->getValue("username")); } else { // if this is an admin user, let them start with no unread notes if ($form->getValue("privs") == \Entities\User::AUTH_SUPERUSER) { $user->setPreference('customer-notes.read_upto', time()); } } $this->getD2EM()->persist($user); $this->_feParams->userStatus = "created"; } $user->setCustomer($contact->getCustomer()); $user->setDisabled($form->getValue("disabled")); $user->setEmail($form->getValue("email")); $user->setLastupdated(new DateTime()); $user->setLastupdatedby($this->getUser()->getId()); // SUPERADMIN can update these always if ($this->getUser()->getPrivs() == \Entities\User::AUTH_SUPERUSER) { if ($form->getValue("password", '') != '') { $user->setPassword(OSS_Auth_Password::hash($form->getValue("password"), $this->_options['resources']['auth']['oss'])); } // ensure the username is not already taken if ($user->getUsername() != $form->getValue("username") && $this->getD2R('\\Entities\\User')->findOneBy(['username' => $form->getValue("username")])) { $this->addMessage('That username is already is use by another user', OSS_Message::ERROR); return false; } $user->setUsername($form->getValue("username")); $user->setPrivs($form->getValue("privs")); } $this->getLogger()->info("{$this->getUser()->getUsername()} created user {$user->getUsername()}"); } else { if ($contact->getUser()) { $this->_deleteUser($contact); } } return true; }