static function getAllAddressTypesInfo() { $types = AddressTypes::findAll(); $result = array(); foreach ($types as $type) { $result[] = array('id' => $type->getId(), 'code' => $type->getName(), 'name' => lang($type->getName())); } return $result; }
/** * Return default contact Address type * * @access public * @param Contact $contact * @return AddressType */ function getContactMainAddressType(Contact $contact) { $contact_address_values_table = ContactAddresss::instance()->getTableName(true); $address_types_table = AddressTypes::instance()->getTableName(true); $sql = "SELECT {$address_types_table}.* FROM {$address_types_table}, {$contact_address_values_table} WHERE {$address_types_table}.`id` = {$contact_address_values_table}.`address_type_id` AND {$contact_address_values_table}.`is_main` = '1' AND {$contact_address_values_table}.`contact_id` = ?"; $row = DB::executeOne($sql, $contact->getId()); if (is_array($row)) { return ImTypes::instance()->loadFromRow($row); } // if return null; }
function render_company_data_tab($genid, $company, $renderContext, $company_data) { $object = $company; if ($company instanceof Contact && !$company->isNew()) { $address = $company->getAddress('work'); $street = ""; $city = ""; $state = ""; $zipcode = ""; if ($address) { $street = $address->getStreet(); $city = $address->getCity(); $state = $address->getState(); $zipcode = $address->getZipCode(); $country = $address->getCountry(); } $company_data = array('first_name' => $company->getFirstName(), 'timezone' => $company->getTimezone(), 'email' => $company->getEmailAddress(), 'comments' => $company->getCommentsField()); // array // telephone types $all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo(); tpl_assign('all_telephone_types', $all_telephone_types); // address types $all_address_types = AddressTypes::getAllAddressTypesInfo(); tpl_assign('all_address_types', $all_address_types); // webpage types $all_webpage_types = WebpageTypes::getAllWebpageTypesInfo(); tpl_assign('all_webpage_types', $all_webpage_types); // email types $all_email_types = EmailTypes::getAllEmailTypesInfo(); tpl_assign('all_email_types', $all_email_types); $all_phones = ContactTelephones::findAll(array('conditions' => 'contact_id = ' . $company->getId())); $company_data['all_phones'] = $all_phones; $all_addresses = ContactAddresses::findAll(array('conditions' => 'contact_id = ' . $company->getId())); $company_data['all_addresses'] = $all_addresses; $all_webpages = ContactWebpages::findAll(array('conditions' => 'contact_id = ' . $company->getId())); $company_data['all_webpages'] = $all_webpages; $all_emails = $company->getNonMainEmails(); $company_data['all_emails'] = $all_emails; } // telephone types $all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo(); // address types $all_address_types = AddressTypes::getAllAddressTypesInfo(); // webpage types $all_webpage_types = WebpageTypes::getAllWebpageTypesInfo(); // email types $all_email_types = EmailTypes::getAllEmailTypesInfo(); include get_template_path("tabs/company_data", "contact"); }
function hasAddress($street, $city, $state, $country, $zipCode, $address_type, $isMain = false) { $type_id = AddressTypes::getAddressTypeId($address_type); $obj = ContactAddresses::instance()->findOne(array('conditions' => array('contact_id=? AND address_type_id=? AND street=? AND city=? AND state=? AND zip_code=? AND country=?', $this->getId(), $type_id, $street, $city, $state, $zipCode, $country))); return $obj instanceof ContactAddress; }
<?php // telephone types $all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo(); // address types $all_address_types = AddressTypes::getAllAddressTypesInfo(); // webpage types $all_webpage_types = WebpageTypes::getAllWebpageTypesInfo(); // email types $all_email_types = EmailTypes::getAllEmailTypesInfo(); // instant messenger types $im_types = ImTypes::findAll(array('order' => '`id`')); if (!isset($id_prefix)) { $id_prefix = ''; } ?> <div id="<?php echo $genid; ?> _additional_data" class="additional-data"> <div class="information-block no-border-bottom"> <div class="input-container"> <?php echo label_tag(lang('birthday'), $genid . 'profileFormBirthday'); ?> <span style="float:left;"><?php echo pick_date_widget2('contact[birthday]', array_var($contact_data, 'birthday'), $genid, 265); ?> </span> </div>
/** * Return manager instance * * @access protected * @param void * @return AddressTypes */ function manager() { if(!($this->manager instanceof AddressTypes)) $this->manager = AddressTypes::instance(); return $this->manager; } // manager
/** * Return Address type * * @access public * @param void * @return AddressType */ function getAddressType() { return AddressTypes::findById($this->getAddressTypeId()); } // getAddressType
/** * Add company * * @param void * @return null */ function add_company() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $notAllowedMember = ''; if (!Contact::canAdd(logged_user(), active_context(), $notAllowedMember)) { if (str_starts_with($notAllowedMember, '-- req dim --')) { flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in))); } else { trim($notAllowedMember) == "" ? flash_error(lang('you must select where to keep', lang('the contact'))) : flash_error(lang('no context permissions to add', lang("contacts"), $notAllowedMember)); } ajx_current("empty"); return; } // if $company = new Contact(); $company->setIsCompany(1); $company_data = array_var($_POST, 'company'); if (!is_array($company_data)) { // set layout for modal form if (array_var($_REQUEST, 'modal')) { $this->setLayout("json"); tpl_assign('modal', true); } $company_data = array('timezone' => logged_user()->getTimezone()); // array } // if tpl_assign('company', $company); tpl_assign('company_data', $company_data); // telephone types $all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo(); tpl_assign('all_telephone_types', $all_telephone_types); // address types $all_address_types = AddressTypes::getAllAddressTypesInfo(); tpl_assign('all_address_types', $all_address_types); // webpage types $all_webpage_types = WebpageTypes::getAllWebpageTypesInfo(); tpl_assign('all_webpage_types', $all_webpage_types); // email types $all_email_types = EmailTypes::getAllEmailTypesInfo(); tpl_assign('all_email_types', $all_email_types); $company_data['all_phones'] = array(); $company_data['all_addresses'] = array(); $company_data['all_webpages'] = array(); if (is_array(array_var($_POST, 'company'))) { foreach ($company_data as $k => &$v) { $v = remove_scripts($v); } $company->setFromAttributes($company_data); $company->setObjectName(); try { $company_data['contact_type'] = 'company'; Contacts::validate($company_data); DB::beginWork(); if (isset($_SESSION['new_contact_picture']) && $_SESSION['new_contact_picture']) { $company->setPictureFile($_SESSION['new_contact_picture']); $_SESSION['new_contact_picture'] = null; } $company->save(); // save phones, addresses and webpages $this->save_phones_addresses_webpages($company_data, $company); if ($company_data['email'] != "") { $company->addEmail($company_data['email'], 'work', true); } // save additional emails $this->save_non_main_emails($company_data, $company); $object_controller = new ObjectController(); $object_controller->add_subscribers($company); $member_ids = json_decode(array_var($_POST, 'members')); if (!is_null($member_ids)) { $object_controller->add_to_members($company, $member_ids); } $object_controller->link_to_new_object($company); $object_controller->add_custom_properties($company); DB::commit(); ApplicationLogs::createLog($company, ApplicationLogs::ACTION_ADD); flash_success(lang('success add client', $company->getObjectName())); evt_add("company added", array("id" => $company->getObjectId(), "name" => $company->getObjectName())); ajx_current("back"); if (array_var($_REQUEST, 'modal')) { evt_add("reload current panel"); } } catch (Exception $e) { DB::rollback(); ajx_current("empty"); if (array_var($_REQUEST, 'modal')) { ajx_extra_data(array('error' => $e->getMessage())); } else { flash_error($e->getMessage()); } } // try } // if }
static function getTypeId($type){ $address_type = AddressTypes::findOne(array('conditions' => array("`name` = ?",$type))); if (!is_null($address_type)) return $address_type->getId(); else return null; }
/** * * Add address to the contact * @param string $street * @param string $city * @param string $state * @param string $country * @param string $zipCode * @param int $email_type * @param boolean $isMain * @author Seba */ function addAddress($street, $city, $state, $country, $zipCode, $address_type, $isMain = false) { $address = new ContactAddress(); $address->setAddressTypeId(AddressTypes::getAddressTypeId($address_type)); $address->setStreet($street); $address->setCity($city); $address->setState($state); $address->setCountry($country); $address->setZipCode($zipCode); $address->setContactId($this->getId()); $address->setIsMain($isMain); $address->save(); }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if(isset($this) && instance_of($this, 'AddressTypes')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return AddressTypes::instance()->paginate($arguments, $items_per_page, $current_page); } // if } // paginate
/** * Return manager instance * * @access protected * @param void * @return AddressTypes */ function manager() { if (!$this->manager instanceof AddressTypes) { $this->manager = AddressTypes::instance(); } return $this->manager; }