Пример #1
0
 /**
  * Return Contact object by email
  *
  * @param string $email
  * @return Contact
  */
 static function getByEmailCheck($email, $id_contact = 0)
 {
     $contact_email = Contacts::findOne(array('conditions' => array("`email_address` = ? AND `contact_id` <> ?", $email, $id_contact), 'join' => array('table' => ContactEmails::instance()->getTableName(), 'jt_field' => 'contact_id', 'e_field' => 'object_id')));
     if (!is_null($contact_email)) {
         return self::findById($contact_email->getObjectId());
     }
     return null;
 }
Пример #2
0
	function getFromContact(){
		$contacts = Contacts::findAll(array(
			'conditions' => " jt.email_address = '".clean($this->getFrom())."'",
			'join' => array(
				'jt_table' => ContactEmails::instance()->getTableName(),
				'jt_field' => 'contact_id',
				'e_field' => 'object_id',
			),
		));
		
		if (is_array($contacts) && count($contacts) > 0){
			return $contacts[0];
		}
		return null;
	}
	function import_from_vcard() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		@set_time_limit(0);
		ini_set('auto_detect_line_endings', '1');
		if (isset($_GET['from_menu']) && $_GET['from_menu'] == 1) unset($_SESSION['go_back']);
		if (isset($_SESSION['go_back'])) {
			unset($_SESSION['go_back']);
			ajx_current("start");
		} else {
                
                    if(!Contact::canAdd(logged_user(), active_context())) {
                            flash_error(lang('no access permissions'));
                            ajx_current("empty");
                            return;
                    } 

                    $this->setTemplate('vcard_import');
                    tpl_assign('import_type', 'contact');                

                    $filedata = array_var($_FILES, 'vcard_file');
                    if (is_array($filedata)) {
                            $filename = ROOT.'/tmp/'.logged_user()->getId().'temp.vcf';
                            copy($filedata['tmp_name'], $filename);
                            $result = $this->read_vcard_file($filename);
                            unlink($filename);
                            $import_result = array('import_ok' => array(), 'import_fail' => array());

                            foreach ($result as $contact_data) {
                                    try {
                                            DB::beginWork();
                                            if (isset($contact_data['photo_tmp_filename'])) {
                                                $file_id = FileRepository::addFile($contact_data['photo_tmp_filename'], array('public' => true));
                                                $contact_data['picture_file'] = $file_id;
                                                unlink($contact_data['photo_tmp_filename']);
                                                unset($contact_data['photo_tmp_filename']);
                                            }
                                            if (isset($contact_data['company_name'])) {
                                                $company = Contacts::findOne(array("conditions" => "`first_name` = '".mysql_real_escape_string($contact_data['company_name'])."'"));
                                                if ($company == null) {                                                        
                                                        $company = new Contact();
                                                        $company->setObjectName($contact_data['company_name']);
                                                        $company->setIsCompany(1);
                                                        $company->save();                                                        
                                                        ApplicationLogs::createLog($company, null, ApplicationLogs::ACTION_ADD);
                                                }
                                                $contact_data['company_id'] = $company->getObjectId();
                                                unset($contact_data['company_name']);
                                            }

                                            $contact_data['import_status'] = '('.lang('updated').')';
                                            $fname = DB::escape(array_var($contact_data, "first_name"));
                                            $lname = DB::escape(array_var($contact_data, "surname"));
                                            $email_cond = array_var($contact_data, "email") != '' ? " OR email_address = '".array_var($contact_data, "email")."'" : "";
                                            $contact = Contacts::findOne(array(
                                                "conditions" => "first_name = ".$fname." AND surname = ".$lname." $email_cond",
                                                'join' => array(
                                                        'table' => ContactEmails::instance()->getTableName(),
                                                        'jt_field' => 'contact_id',
                                                        'e_field' => 'object_id',
                                                )));                                                        
                                            $log_action = ApplicationLogs::ACTION_EDIT;
                                            if (!$contact) {
                                                    $contact = new Contact();
                                                    $contact_data['import_status'] = '('.lang('new').')';
                                                    $log_action = ApplicationLogs::ACTION_ADD;
                                                    $can_import = active_project() != null ? $contact->canAdd(logged_user(), active_project()) : can_manage_contacts(logged_user());
                                            } else {
                                                    $can_import = $contact->canEdit(logged_user());
                                            }

                                            if ($can_import) {
                                                    $comp_name = DB::escape(array_var($contact_data, "company_id"));
                                                    if ($comp_name != '') {
                                                            $company = Contacts::findOne(array("conditions" => "first_name = $comp_name AND is_company = 1"));
                                                            if ($company) {
                                                                    $contact_data['company_id'] = $company->getId();
                                                            } 
                                                            $contact_data['import_status'] .= " " . lang("company") . " $comp_name";
                                                    } else {
                                                            $contact_data['company_id'] = 0;
                                                    }
                                                    $contact_data['birthday'] = $contact_data["o_birthday"];
                                                    $contact_data['name'] = $contact_data['first_name']." ".$contact_data['surname'];
                                                    $contact->setFromAttributes($contact_data);
                                                    $contact->save();

                                                    //Home form
                                                    if($contact_data['h_address'] != "")
                                                        $contact->addAddress($contact_data['h_address'], $contact_data['h_city'], $contact_data['h_state'], $contact_data['h_country'], $contact_data['h_zipcode'], 'home');
                                                    if($contact_data['h_phone_number'] != "") $contact->addPhone($contact_data['h_phone_number'], 'home', true);
                                                    if($contact_data['h_phone_number2'] != "") $contact->addPhone($contact_data['h_phone_number2'], 'home');
                                                    if($contact_data['h_mobile_number'] != "") $contact->addPhone($contact_data['h_mobile_number'], 'mobile');
                                                    if($contact_data['h_fax_number'] != "") $contact->addPhone($contact_data['h_fax_number'], 'fax');
                                                    if($contact_data['h_pager_number'] != "") $contact->addPhone($contact_data['h_pager_number'], 'pager');
                                                    if($contact_data['h_web_page'] != "") $contact->addWebpage($contact_data['h_web_page'], 'personal');

                                                    //Work form
                                                    if($contact_data['w_address'] != "")
                                                        $contact->addAddress($contact_data['w_address'], $contact_data['w_city'], $contact_data['w_state'], $contact_data['w_country'], $contact_data['w_zipcode'], 'work');
                                                    if($contact_data['w_phone_number'] != "") $contact->addPhone($contact_data['w_phone_number'], 'work', true);
                                                    if($contact_data['w_phone_number2'] != "") $contact->addPhone($contact_data['w_phone_number2'], 'work');
                                                    if($contact_data['w_assistant_number'] != "") $contact->addPhone($contact_data['w_assistant_number'], 'assistant');
                                                    if($contact_data['w_callback_number'] != "") $contact->addPhone($contact_data['w_callback_number'], 'callback');
                                                    if($contact_data['w_fax_number'] != "") $contact->addPhone($contact_data['w_fax_number'], 'fax', true);
                                                    if($contact_data['w_web_page'] != "") $contact->addWebpage($contact_data['w_web_page'], 'work');

                                                    //Other form
                                                    if($contact_data['o_address'] != "")
                                                        $contact->addAddress($contact_data['o_address'], $contact_data['o_city'], $contact_data['o_state'], $contact_data['o_country'], $contact_data['o_zipcode'], 'other');
                                                    if($contact_data['o_phone_number'] != "") $contact->addPhone($contact_data['o_phone_number'], 'other', true);
                                                    if($contact_data['o_phone_number2'] != "") $contact->addPhone($contact_data['o_phone_number2'], 'other');
                                                    if($contact_data['o_web_page'] != "") $contact->addWebpage($contact_data['o_web_page'], 'other');

                                                    //Emails and instant messaging form
                                                    if($contact_data['email'] != "") $contact->addEmail($contact_data['email'], 'personal', true);
                                                    if($contact_data['email2'] != "") $contact->addEmail($contact_data['email2'], 'personal');
                                                    if($contact_data['email3'] != "") $contact->addEmail($contact_data['email3'], 'personal');

                                                    ApplicationLogs::createLog($contact, null, $log_action);
                                                    $import_result['import_ok'][] = $contact_data;
                                            } else {
                                                    throw new Exception(lang('no access permissions'));
                                            }
                                            DB::commit();					
                                    } catch (Exception $e) {
                                            DB::rollback();
                                            $fail_msg = substr_utf($e->getMessage(), strpos_utf($e->getMessage(), "\r\n"));
                                            $import_result['import_fail'][] = array('first_name' => $fname, 'surname' => $lname, 'email' => $contact_data['email'], 'import_status' => $contact_data['import_status'], 'fail_message' => $fail_msg);
                                    }
                            }
                            $_SESSION['go_back'] = true;
                            tpl_assign('import_result', $import_result);
                        }
                    }
                        
	}
Пример #4
0
 function hasEmail($value, $email_type, $isMain = false)
 {
     $type_id = EmailTypes::getEmailTypeId($email_type);
     $obj = ContactEmails::instance()->findOne(array('conditions' => array('contact_id=? AND email_type_id=? AND email_address=?', $this->getId(), $type_id, $value)));
     return $obj instanceof ContactEmail;
 }
Пример #5
0
 /**
 * Return manager instance
 *
 * @access protected
 * @param void
 * @return ContactEmails 
 */
 function manager() {
   if(!($this->manager instanceof ContactEmails)) $this->manager = ContactEmails::instance();
   return $this->manager;
 } // manager
 /**
 * 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, 'ContactEmails')) {
     return parent::paginate($arguments, $items_per_page, $current_page);
   } else {
     return ContactEmails::instance()->paginate($arguments, $items_per_page, $current_page);
   } // if
 } // paginate
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ContactEmails 
  */
 function manager()
 {
     if (!$this->manager instanceof ContactEmails) {
         $this->manager = ContactEmails::instance();
     }
     return $this->manager;
 }
Пример #8
0
 function do_delete()
 {
     $id = $this->getId();
     ContactAddresses::instance()->delete("`contact_id` = {$id}");
     ContactImValues::instance()->delete("`contact_id` = {$id}");
     ContactEmails::instance()->delete("`contact_id` = {$id}");
     ContactTelephones::instance()->delete("`contact_id` = {$id}");
     ContactWebpages::instance()->delete("`contact_id` = {$id}");
     ContactConfigOptionValues::instance()->delete("`contact_id` = {$id}");
     ContactPasswords::instance()->delete("`contact_id` = {$id}");
     ObjectSubscriptions::instance()->delete("`contact_id` = {$id}");
     ObjectReminders::instance()->delete("`contact_id` = {$id}");
     ContactPermissionGroups::instance()->delete("`contact_id` = {$id}");
     ContactMemberPermissions::instance()->delete("`permission_group_id` = " . $this->getPermissionGroupId());
     ContactDimensionPermissions::instance()->delete("`permission_group_id` = " . $this->getPermissionGroupId());
     SystemPermissions::instance()->delete("`permission_group_id` = " . $this->getPermissionGroupId());
     TabPanelPermissions::instance()->delete("`permission_group_id` = " . $this->getPermissionGroupId());
     $this->delete();
     $ret = null;
     Hook::fire("after_user_deleted", $this, $ret);
 }
Пример #9
0
 /**
  * Return Contact object by email
  *
  * @param string $email
  * @return Contact
  */
 static function getByEmailCheck($email, $id_contact = 0, $contact_type = '')
 {
     if (is_null($email) || $email == '') {
         return null;
     }
     $contact_type_str = "";
     if ($contact_type == 'contact') {
         $contact_type_str = " AND is_company=0";
     } else {
         if ($contact_type == 'company') {
             $contact_type_str = " AND is_company=1";
         }
     }
     $contact_email = Contacts::findOne(array('conditions' => array("`email_address` = ? AND `contact_id` <> ? {$contact_type_str}", $email, $id_contact), 'join' => array('table' => ContactEmails::instance()->getTableName(), 'jt_field' => 'contact_id', 'e_field' => 'object_id')));
     if (!is_null($contact_email)) {
         return self::findById($contact_email->getObjectId());
     }
     return null;
 }