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;
 }
 /**
  * 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, 'ContactAddresses')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ContactAddresses::instance()->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ContactAddresses 
 */
 function manager() {
   if(!($this->manager instanceof ContactAddresses)) $this->manager = ContactAddresses::instance();
   return $this->manager;
 } // manager
 /**
  * Edit company
  *
  * @param void
  * @return null
  */
 function edit_company()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $this->setTemplate('add_company');
     $company = Contacts::findById(get_id());
     if (!$company instanceof Contact) {
         flash_error(lang('client dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if (!$company->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $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);
         }
         $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;
         $null = null;
         Hook::fire('before_edit_contact_form', array('object' => $company), $null);
     }
     // if
     tpl_assign('company', $company);
     tpl_assign('company_data', $company_data);
     if (is_array(array_var($_POST, 'company'))) {
         foreach ($company_data as $k => &$v) {
             $v = remove_scripts($v);
         }
         try {
             $company_data['contact_type'] = 'company';
             Contacts::validate($company_data, $_REQUEST['id']);
             DB::beginWork();
             $company->setFromAttributes($company_data);
             $main_emails = $company->getMainEmails();
             $more_main_emails = array();
             $main_mail = null;
             foreach ($main_emails as $me) {
                 if ($main_mail == null) {
                     $main_mail = $me;
                 } else {
                     $more_main_emails[] = $me;
                 }
             }
             if ($main_mail) {
                 $main_mail->editEmailAddress($company_data['email']);
             } else {
                 if ($company_data['email'] != "") {
                     $company->addEmail($company_data['email'], 'work', true);
                 }
             }
             foreach ($more_main_emails as $mme) {
                 $mme->setIsMain(false);
                 $mme->save();
             }
             $company->setObjectName();
             $company->save();
             // save phones, addresses and webpages
             $this->save_phones_addresses_webpages($company_data, $company);
             // save additional emails
             $this->save_non_main_emails($company_data, $company);
             $member_ids = json_decode(array_var($_POST, 'members'));
             $object_controller = new ObjectController();
             $object_controller->add_to_members($company, $member_ids);
             $object_controller->link_to_new_object($company);
             $object_controller->add_subscribers($company);
             $object_controller->add_custom_properties($company);
             DB::commit();
             ApplicationLogs::createLog($company, ApplicationLogs::ACTION_EDIT);
             flash_success(lang('success edit client', $company->getObjectName()));
             ajx_current("back");
             if (array_var($_REQUEST, 'modal')) {
                 evt_add("reload current panel");
             }
         } catch (Exception $e) {
             DB::rollback();
             ajx_current("empty");
             flash_error($e->getMessage());
         }
         // try
     }
 }
示例#6
0
<?php

$genid = gen_id();
$contact = $object;
$hasEmailAddrs = false;
$main_email = $contact->getEmailAddress('personal');
$personal_emails = $contact->getContactEmails('personal');
$all_phones = ContactTelephones::findAll(array('conditions' => 'contact_id = ' . $contact->getId()));
$all_addresses = ContactAddresses::findAll(array('conditions' => 'contact_id = ' . $contact->getId()));
$all_webpages = ContactWebpages::findAll(array('conditions' => 'contact_id = ' . $contact->getId()));
$all_other_emails = ContactEmails::findAll(array('conditions' => 'is_main=0 AND contact_id = ' . $contact->getId()));
$all_telephone_types = TelephoneTypes::getAllTelephoneTypesInfo();
$all_address_types = AddressTypes::getAllAddressTypesInfo();
$all_webpage_types = WebpageTypes::getAllWebpageTypesInfo();
$all_email_types = EmailTypes::getAllEmailTypesInfo();
// types ordered
$all_type_codes = array('work', 'mobile', 'home', 'personal', 'other', 'assistant', 'callback', 'pager', 'fax');
$all_types_by_code = array();
foreach ($all_type_codes as $code) {
    $t = null;
    foreach ($all_telephone_types as $type) {
        if ($type['code'] == $code) {
            $t = $type;
        }
    }
    if (!$t) {
        foreach ($all_address_types as $type) {
            if ($type['code'] == $code) {
                $t = $type;
            }
        }
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ContactAddresses 
  */
 function manager()
 {
     if (!$this->manager instanceof ContactAddresses) {
         $this->manager = ContactAddresses::instance();
     }
     return $this->manager;
 }
示例#8
0
 /**
  * Delete this object
  *
  * @param void
  * @return boolean
  */
 function delete()
 {
     // dont delete owner company and account owner
     if ($this->isOwnerCompany() || $this->isAccountOwner()) {
         return false;
     }
     if ($this->isUser() && logged_user() instanceof Contact && !can_manage_security(logged_user())) {
         return false;
     }
     $this->deletePicture();
     ContactEmails::clearByContact($this);
     ContactAddresses::clearByContact($this);
     ContactTelephones::clearByContact($this);
     ContactWebpages::clearByContact($this);
     ContactImValues::clearByContact($this);
     return parent::delete();
 }