Пример #1
0
 /**
  * Adding Crm Contact and link it with crm company if possible
  *
  * @param Array $arrFormData form data's
  * @param int $userAccountId
  * @param int $frontendLanguage
  * @global <object> $objDatabase
  * @global int $_LANGID
  *
  */
 function setContactPersonProfile($arrFormData = array(), $userAccountId = 0, $frontendLanguage)
 {
     global $objDatabase, $_LANGID;
     $this->contact = new \Cx\Modules\Crm\Model\Entity\CrmContact();
     if (!empty($userAccountId)) {
         $userExists = $objDatabase->Execute("SELECT id FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_contacts` WHERE user_account = {$userAccountId}");
         if ($userExists && $userExists->RecordCount()) {
             $id = (int) $userExists->fields['id'];
             $this->contact->load($id);
             $this->contact->customerName = !empty($arrFormData['firstname'][0]) ? contrexx_input2raw($arrFormData['firstname'][0]) : '';
             $this->contact->family_name = !empty($arrFormData['lastname'][0]) ? contrexx_input2raw($arrFormData['lastname'][0]) : '';
             $this->contact->contact_language = !empty($frontendLanguage) ? (int) $frontendLanguage : $_LANGID;
             $this->contact->contact_gender = !empty($arrFormData['gender'][0]) ? $arrFormData['gender'][0] == 'gender_female' ? 1 : ($arrFormData['gender'][0] == 'gender_male' ? 2 : '') : '';
             $this->contact->contactType = 2;
             $this->contact->datasource = 2;
             $this->contact->account_id = $userAccountId;
             //set profile picture
             if (!empty($arrFormData['picture'][0])) {
                 $picture = $arrFormData['picture'][0];
                 $cx = \Cx\Core\Core\Controller\Cx::instanciate();
                 if (!file_exists($cx->getWebsiteImagesCrmProfilePath() . '/' . $picture)) {
                     $file = $cx->getWebsiteImagesAccessProfilePath() . '/';
                     $newFile = $cx->getWebsiteImagesCrmProfilePath() . '/';
                     if (copy($file . $picture, $newFile . $picture)) {
                         if ($this->createThumbnailOfPicture($picture)) {
                             $this->contact->profile_picture = $picture;
                         }
                     }
                 }
             } else {
                 $this->contact->profile_picture = 'profile_person_big.png';
             }
             // save current setting values, so we can switch back to them after we got our used settings out of database
             $prevSection = \Cx\Core\Setting\Controller\Setting::getCurrentSection();
             $prevGroup = \Cx\Core\Setting\Controller\Setting::getCurrentGroup();
             $prevEngine = \Cx\Core\Setting\Controller\Setting::getCurrentEngine();
             \Cx\Core\Setting\Controller\Setting::init('Crm', 'config');
             if ($arrFormData["company"][0] != "") {
                 $crmCompany = new \Cx\Modules\Crm\Model\Entity\CrmContact();
                 if ($this->contact->contact_customer != 0) {
                     $crmCompany->load($this->contact->contact_customer);
                 }
                 $crmCompany->customerName = $arrFormData["company"][0];
                 $crmCompany->contactType = 1;
                 $customerType = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_customer_type', 'Crm')][0];
                 if ($customerType !== false) {
                     $crmCompany->customerType = $customerType;
                 }
                 $companySize = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_company_size', 'Crm')][0];
                 if ($companySize !== false) {
                     $crmCompany->companySize = $companySize;
                 }
                 $industryType = $arrFormData[\Cx\Core\Setting\Controller\Setting::getValue('user_profile_attribute_industry_type', 'Crm')][0];
                 if ($industryType !== false) {
                     $crmCompany->industryType = $industryType;
                 }
                 if (isset($arrFormData["phone_office"])) {
                     $crmCompany->phone = $arrFormData["phone_office"];
                 }
                 // store/update the company profile
                 $crmCompany->save();
                 // setting & storing the primary email address must be done after
                 // the company has been saved for the case where the company is
                 // being added as a new object without having an ID yet
                 if (empty($crmCompany->email)) {
                     $crmCompany->email = $this->contact->email;
                     $crmCompany->storeEMail();
                 }
                 $this->contact->contact_customer = $crmCompany->id;
             }
             if ($this->contact->save()) {
                 // insert website
                 if (!empty($arrFormData['website'][0])) {
                     $webExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_websites` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'");
                     $fields = array('url' => $arrFormData['website'][0], 'url_profile' => '1', 'is_primary' => '1', 'contact_id' => $this->contact->id);
                     if ($webExists) {
                         $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true)) . " WHERE is_primary = '1' AND `contact_id` = {$this->contact->id}";
                     } else {
                         $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_websites", $fields, array('escape' => true));
                     }
                     $db = $objDatabase->Execute($query);
                 }
                 //insert address
                 if (!empty($arrFormData['address'][0]) || !empty($arrFormData['city'][0]) || !empty($arrFormData['zip'][0]) || !empty($arrFormData['country'][0])) {
                     $addressExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'");
                     $country = \Cx\Core\Country\Controller\Country::getById($arrFormData['country'][0]);
                     if ($addressExists && $addressExists->RecordCount()) {
                         $query = "UPDATE `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` SET\n                                    address      = '" . contrexx_input2db($arrFormData['address'][0]) . "',\n                                    city         = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n                                    zip          = '" . contrexx_input2db($arrFormData['zip'][0]) . "',\n                                    country      = '" . $country['name'] . "',\n                                    Address_Type = '2'\n                                 WHERE is_primary   = '1' AND contact_id   = '{$this->contact->id}'";
                     } else {
                         $query = "INSERT INTO `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_address` SET\n                                    address      = '" . contrexx_input2db($arrFormData['address'][0]) . "',\n                                    city         = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n                                    state        = '" . contrexx_input2db($arrFormData['city'][0]) . "',\n                                    zip          = '" . contrexx_input2db($arrFormData['zip'][0]) . "',\n                                    country      = '" . $country['name'] . "',\n                                    Address_Type = '2',\n                                    is_primary   = '1',\n                                    contact_id   = '{$this->contact->id}'";
                     }
                     $objDatabase->Execute($query);
                 }
                 // insert Phone
                 $contactPhone = array();
                 if (!empty($arrFormData['phone_office'][0])) {
                     $phoneExists = $objDatabase->SelectLimit("SELECT 1 FROM `" . DBPREFIX . "module_{$this->moduleNameLC}_customer_contact_phone` WHERE is_primary = '1' AND contact_id = '{$this->contact->id}'");
                     $fields = array('phone' => $arrFormData['phone_office'][0], 'phone_type' => '1', 'is_primary' => '1', 'contact_id' => $this->contact->id);
                     if ($phoneExists && $phoneExists->RecordCount()) {
                         $query = \SQL::update("module_{$this->moduleNameLC}_customer_contact_phone", $fields, array('escape' => true)) . " WHERE is_primary = '1' AND `contact_id` = {$this->contact->id}";
                     } else {
                         $query = \SQL::insert("module_{$this->moduleNameLC}_customer_contact_phone", $fields, array('escape' => true));
                     }
                     $objDatabase->Execute($query);
                 }
             }
             \Cx\Core\Setting\Controller\Setting::init($prevSection, $prevGroup, $prevEngine);
         }
     }
 }
Пример #2
0
 /**
  * delete customer related details
  *
  * @global array $_ARRAYLANG
  * @global object $objDatabase
  * @return true
  */
 function deleteCustomers()
 {
     global $_ARRAYLANG, $objDatabase;
     $id = intval($_GET['id']);
     $contact = new \Cx\Modules\Crm\Model\Entity\CrmContact();
     if (!empty($id)) {
         if ($contact->delete($id)) {
             $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_DELETED_SUCCESSFULLY'];
         }
     } else {
         $deleteIds = $_POST['selectedEntriesId'];
         foreach ($deleteIds as $id) {
             if ($contact->delete($id)) {
                 $this->_strOkMessage = $_ARRAYLANG['TXT_CRM_DELETED_SUCCESSFULLY'];
             }
         }
     }
     if (isset($_GET['ajax'])) {
         exit;
     }
     $message = base64_encode("deleted");
     $redirect = isset($_GET['redirect']) ? base64_decode($_GET['redirect']) : '';
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     \Cx\Core\Csrf\Controller\Csrf::header("location:" . $cx->getCodeBaseOffsetPath() . $cx->getBackendFolderName() . "/index.php?cmd=" . $this->moduleName . "&act=customers{$redirect}&mes={$message}");
     exit;
 }