Exemple #1
0
 private function onEdit()
 {
     if ($this->_accessLevel < ACCESS_LEVEL_EDIT) {
         $this->listByView('Invalid user level for action.');
         return;
     }
     $companies = new Companies($this->_siteID);
     /* Bail out if we don't have a valid company ID. */
     if (!$this->isRequiredIDValid('companyID', $_POST)) {
         $this->listByView('Invalid company ID.');
         return;
     }
     /* Bail out if we don't have a valid owner user ID. */
     if (!$this->isOptionalIDValid('owner', $_POST)) {
         $this->listByView('Invalid owner user ID.');
         return;
     }
     /* Bail out if we don't have a valid billing contact ID. */
     if (!$this->isOptionalIDValid('billingContact', $_POST)) {
         $this->listByView('Invalid billing contact ID.');
         return;
     }
     $formattedPhone1 = StringUtility::extractPhoneNumber($this->getTrimmedInput('phone1', $_POST));
     if (!empty($formattedPhone1)) {
         $phone1 = $formattedPhone1;
     } else {
         $phone1 = $this->getTrimmedInput('phone1', $_POST);
     }
     $formattedPhone2 = StringUtility::extractPhoneNumber($this->getTrimmedInput('phone2', $_POST));
     if (!empty($formattedPhone2)) {
         $phone2 = $formattedPhone2;
     } else {
         $phone2 = $this->getTrimmedInput('phone2', $_POST);
     }
     $formattedFaxNumber = StringUtility::extractPhoneNumber($this->getTrimmedInput('faxNumber', $_POST));
     if (!empty($formattedFaxNumber)) {
         $faxNumber = $formattedFaxNumber;
     } else {
         $faxNumber = $this->getTrimmedInput('faxNumber', $_POST);
     }
     $url = $this->getTrimmedInput('url', $_POST);
     if (!empty($url)) {
         $formattedURL = StringUtility::extractURL($url);
         if (!empty($formattedURL)) {
             $url = $formattedURL;
         }
     }
     /* Hot company? */
     $isHot = $this->isChecked('isHot', $_POST);
     $companyID = $_POST['companyID'];
     $owner = $_POST['owner'];
     $billingContact = $_POST['billingContact'];
     /* Change ownership email? */
     if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) {
         $companyDetails = $companies->get($companyID);
         $users = new Users($this->_siteID);
         $ownerDetails = $users->get($_POST['owner']);
         if (!empty($ownerDetails)) {
             $emailAddress = $ownerDetails['email'];
             /* Get the change status email template. */
             $emailTemplates = new EmailTemplates($this->_siteID);
             $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNCLIENT');
             if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) {
                 $statusChangeTemplate = '';
             } else {
                 $statusChangeTemplate = $statusChangeTemplateRS['textReplaced'];
             }
             /* Replace e-mail template variables. */
             $stringsToFind = array('%CLNTOWNER%', '%CLNTNAME%', '%CLNTCATSURL%');
             $replacementStrings = array($ownerDetails['fullName'], $companyDetails['name'], '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=companies&amp;a=show&amp;companyID=' . $companyID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=companies&amp;a=show&amp;companyID=' . $companyID . '</a>');
             $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate);
             $email = $statusChangeTemplate;
         } else {
             $email = '';
             $emailAddress = '';
         }
     } else {
         $email = '';
         $emailAddress = '';
     }
     $name = $this->getTrimmedInput('name', $_POST);
     $address = $this->getTrimmedInput('address', $_POST);
     $city = $this->getTrimmedInput('city', $_POST);
     $state = $this->getTrimmedInput('state', $_POST);
     $zip = $this->getTrimmedInput('zip', $_POST);
     $keyTechnologies = $this->getTrimmedInput('keyTechnologies', $_POST);
     $notes = $this->getTrimmedInput('notes', $_POST);
     /* Departments list editor. */
     $departmentsCSV = $this->getTrimmedInput('departmentsCSV', $_POST);
     /* Bail out if any of the required fields are empty. */
     if (empty($name)) {
         $this->listByView('Required fields are missing.');
         return;
     }
     if (!eval(Hooks::get('CLIENTS_ON_EDIT_PRE'))) {
         return;
     }
     $departments = $companies->getDepartments($companyID);
     $departmentsDifferences = ListEditor::getDifferencesFromList($departments, 'name', 'departmentID', $departmentsCSV);
     $companies->updateDepartments($companyID, $departmentsDifferences);
     if (!$companies->update($companyID, $name, $address, $city, $state, $zip, $phone1, $phone2, $faxNumber, $url, $keyTechnologies, $isHot, $notes, $owner, $billingContact, $email, $emailAddress)) {
         CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update company.');
     }
     if (!eval(Hooks::get('CLIENTS_ON_EDIT_POST'))) {
         return;
     }
     /* Update extra fields. */
     $companies->extraFields->setValuesOnEdit($companyID);
     /* Update contacts? */
     if (isset($_POST['updateContacts'])) {
         if ($_POST['updateContacts'] == 'yes') {
             $contacts = new Contacts($this->_siteID);
             $contacts->updateByCompany($companyID, $address, $city, $state, $zip);
         }
     }
     CATSUtility::transferRelativeURI('m=companies&a=show&companyID=' . $companyID);
 }
Exemple #2
0
 private function onEdit()
 {
     if ($this->_accessLevel < ACCESS_LEVEL_EDIT) {
         CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
     }
     /* Bail out if we don't have a valid contact ID. */
     if (!$this->isRequiredIDValid('contactID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid contact ID.');
     }
     /* Bail out if we don't have a valid company ID. */
     if (!$this->isRequiredIDValid('companyID', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid company ID.');
     }
     /* Bail out if we don't have a valid owner user ID. */
     if (!$this->isOptionalIDValid('owner', $_POST)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid owner user ID.');
     }
     $contactID = $_POST['contactID'];
     $companyID = $_POST['companyID'];
     $owner = $_POST['owner'];
     $formattedPhoneWork = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneWork', $_POST));
     if (!empty($formattedPhoneWork)) {
         $phoneWork = $formattedPhoneWork;
     } else {
         $phoneWork = $this->getTrimmedInput('phoneWork', $_POST);
     }
     $formattedPhoneCell = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneCell', $_POST));
     if (!empty($formattedPhoneCell)) {
         $phoneCell = $formattedPhoneCell;
     } else {
         $phoneCell = $this->getTrimmedInput('phoneCell', $_POST);
     }
     $formattedPhoneOther = StringUtility::extractPhoneNumber($this->getTrimmedInput('phoneOther', $_POST));
     if (!empty($formattedPhoneOther)) {
         $phoneOther = $formattedPhoneOther;
     } else {
         $phoneOther = $this->getTrimmedInput('phoneOther', $_POST);
     }
     $contacts = new Contacts($this->_siteID);
     if ($this->isChecked('ownershipChange', $_POST) && $owner > 0) {
         $contactDetails = $contacts->get($contactID);
         $users = new Users($this->_siteID);
         $ownerDetails = $users->get($owner);
         if (!empty($ownerDetails)) {
             $emailAddress = $ownerDetails['email'];
             /* Get the change status email template. */
             $emailTemplates = new EmailTemplates($this->_siteID);
             $statusChangeTemplateRS = $emailTemplates->getByTag('EMAIL_TEMPLATE_OWNERSHIPASSIGNCONTACT');
             if (empty($statusChangeTemplateRS) || empty($statusChangeTemplateRS['textReplaced'])) {
                 $statusChangeTemplate = '';
             } else {
                 $statusChangeTemplate = $statusChangeTemplateRS['textReplaced'];
             }
             /* Replace e-mail template variables. */
             $stringsToFind = array('%CONTOWNER%', '%CONTFIRSTNAME%', '%CONTFULLNAME%', '%CONTCLIENTNAME%', '%CONTCATSURL%');
             $replacementStrings = array($ownerDetails['fullName'], $contactDetails['firstName'], $contactDetails['firstName'] . ' ' . $contactDetails['lastName'], $contactDetails['companyName'], '<a href="http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&amp;a=show&amp;contactID=' . $contactID . '">' . 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')) . '?m=contacts&amp;a=show&amp;contactID=' . $contactID . '</a>');
             $statusChangeTemplate = str_replace($stringsToFind, $replacementStrings, $statusChangeTemplate);
             $email = $statusChangeTemplate;
         } else {
             $email = '';
             $emailAddress = '';
         }
     } else {
         $email = '';
         $emailAddress = '';
     }
     $firstName = $this->getTrimmedInput('firstName', $_POST);
     $lastName = $this->getTrimmedInput('lastName', $_POST);
     $title = $this->getTrimmedInput('title', $_POST);
     $department = $this->getTrimmedInput('department', $_POST);
     $reportsTo = $this->getTrimmedInput('reportsTo', $_POST);
     $email1 = $this->getTrimmedInput('email1', $_POST);
     $email2 = $this->getTrimmedInput('email2', $_POST);
     $address = $this->getTrimmedInput('address', $_POST);
     $city = $this->getTrimmedInput('city', $_POST);
     $state = $this->getTrimmedInput('state', $_POST);
     $zip = $this->getTrimmedInput('zip', $_POST);
     $notes = $this->getTrimmedInput('notes', $_POST);
     $isHot = $this->isChecked('isHot', $_POST);
     $leftCompany = $this->isChecked('leftCompany', $_POST);
     /* Departments list editor. */
     $departmentsCSV = $this->getTrimmedInput('departmentsCSV', $_POST);
     /* Bail out if any of the required fields are empty. */
     if (empty($firstName) || empty($lastName) || empty($title)) {
         CommonErrors::fatal(COMMONERROR_MISSINGFIELDS, $this, 'Required fields are missing.');
     }
     if (!eval(Hooks::get('CONTACTS_ON_EDIT_PRE'))) {
         return;
     }
     /* Update departments. */
     $companies = new Companies($this->_siteID);
     $departments = $companies->getDepartments($companyID);
     $departmentsDifferences = ListEditor::getDifferencesFromList($departments, 'name', 'departmentID', $departmentsCSV);
     $companies->updateDepartments($companyID, $departmentsDifferences);
     if (!$contacts->update($contactID, $companyID, $firstName, $lastName, $title, $department, $reportsTo, $email1, $email2, $phoneWork, $phoneCell, $phoneOther, $address, $city, $state, $zip, $isHot, $leftCompany, $notes, $owner, $email, $emailAddress)) {
         CommonErrors::fatal(COMMONERROR_RECORDERROR, $this, 'Failed to update contact.');
     }
     /* Update extra fields. */
     $contacts->extraFields->setValuesOnEdit($contactID);
     if (!eval(Hooks::get('CONTACTS_ON_EDIT_POST'))) {
         return;
     }
     CATSUtility::transferRelativeURI('m=contacts&a=show&contactID=' . $contactID);
 }