Beispiel #1
0
 public static function loadSettings(&$settingsController, &$params, &$response, $user)
 {
     $startModule = \GO\Base\Model\Module::model()->findByPk($user->start_module);
     $response['data']['start_module_name'] = $startModule ? $startModule->moduleManager->name() : '';
     $company = \GO\Addressbook\Model\Company::model()->findByPk($response['data']['company_id'], false, true);
     if ($company) {
         $response['data']['company_name'] = $company->name;
     }
     $response['remoteComboTexts']['holidayset'] = \GO::t($user->holidayset);
     return parent::loadSettings($settingsController, $params, $response, $user);
 }
Beispiel #2
0
 protected function actionSelectCompany($params)
 {
     $response = array('total' => 0, 'results' => array());
     $query = !empty($params['query']) ? $params['query'] : '';
     $query = '%' . preg_replace('/[\\s*]+/', '%', $query) . '%';
     $findParams = \GO\Base\Db\FindParams::newInstance()->ignoreAcl()->select('t.*, a.name AS ab_name')->searchQuery($query, array("CONCAT(t.name,' ',t.name2,' ',' ',a.name)", 't.email'))->joinModel(array('model' => 'GO\\Addressbook\\Model\\Addressbook', 'foreignField' => 'id', 'localField' => 'addressbook_id', 'tableAlias' => 'a', 'type' => 'INNER'))->limit(10)->order('t.name');
     //		}
     if (!empty($params['addressbook_id'])) {
         $abs = array($params['addressbook_id']);
     } else {
         if (GO::modules()->customfields && !empty($params['customfield_id'])) {
             $colId = preg_replace('/[\\D]/', '', $params['customfield_id']);
             $customfieldModel = \GO\Customfields\Model\Field::model()->findByPk($colId);
             $abs = !empty($customfieldModel->addressbook_ids) ? explode(',', $customfieldModel->addressbook_ids) : \GO\Addressbook\Model\Addressbook::model()->getAllReadableAddressbookIds();
             $readableAddressbookIds = \GO\Addressbook\Model\Addressbook::model()->getAllReadableAddressbookIds();
             foreach ($abs as $k => $abId) {
                 if (!in_array($abId, $readableAddressbookIds)) {
                     unset($abs[$k]);
                 }
             }
         } else {
             $abs = \GO\Addressbook\Model\Addressbook::model()->getAllReadableAddressbookIds();
         }
     }
     if (!empty($abs)) {
         $findParams->getCriteria()->addInTemporaryTableCondition('addressbooks', 'addressbook_id', $abs);
         $stmt = \GO\Addressbook\Model\Company::model()->find($findParams);
         //				$user_ids=array();
         foreach ($stmt as $company) {
             $record = $company->getAttributes();
             $record['addressbook_name'] = $company->addressbook ? $company->addressbook->name : '';
             $record['name_and_name2'] = !empty($company->name2) ? $company->name . ' ' . $company->name2 : $company->name;
             //$record['name']=$contact->name;
             $record['cf'] = $company->id . ":" . $company->name;
             $response['results'][] = $record;
             $response['total']++;
             //					if($contact->go_user_id)
             //						$user_ids[]=$contact->go_user_id;
         }
     }
     return $response;
 }
Beispiel #3
0
 public function loadTemplate($params)
 {
     if (GO::modules()->addressbook && !empty($params['template_id'])) {
         try {
             $template = \GO\Addressbook\Model\Template::model()->findByPk($params['template_id']);
             $templateContent = $template ? $template->content : '';
         } catch (\GO\Base\Exception\AccessDenied $e) {
             $templateContent = "";
         }
         $message = \GO\Email\Model\SavedMessage::model()->createFromMimeData($templateContent);
         $response['data'] = $message->toOutputArray(true, true);
         $presetbody = isset($params['body']) ? $params['body'] : '';
         if (!empty($presetbody) && strpos($response['data']['htmlbody'], '{body}') == false) {
             $response['data']['htmlbody'] = $params['body'] . '<br />' . $response['data']['htmlbody'];
         } else {
             $response['data']['htmlbody'] = str_replace('{body}', $presetbody, $response['data']['htmlbody']);
         }
         unset($response['data']['to'], $response['data']['cc'], $response['data']['bcc']);
         //			unset($response['data']['cc'], $response['data']['bcc'], $response['data']['subject']);
         $defaultTags = array('contact:salutation' => GO::t('default_salutation_unknown'));
         // Parse the link tag
         $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceLinkTag($response['data']['htmlbody'], $message);
         //keep template tags for mailings to addresslists
         if (empty($params['addresslist_id'])) {
             //if contact_id is not set but email is check if there's contact info available
             if (!empty($params['to']) || !empty($params['contact_id']) || !empty($params['company_id'])) {
                 if (!empty($params['contact_id'])) {
                     $contact = \GO\Addressbook\Model\Contact::model()->findByPk($params['contact_id']);
                 } else {
                     $email = \GO\Base\Util\String::get_email_from_string($params['to']);
                     $contact = \GO\Addressbook\Model\Contact::model()->findSingleByEmail($email);
                 }
                 $company = false;
                 if (!empty($params['company_id'])) {
                     $company = \GO\Addressbook\Model\Company::model()->findByPk($params['company_id']);
                 }
                 if ($company) {
                     $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceModelTags($response['data']['htmlbody'], $company, 'company:', true);
                 }
                 if ($contact) {
                     $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceContactTags($response['data']['htmlbody'], $contact);
                 } else {
                     $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceCustomTags($response['data']['htmlbody'], $defaultTags, true);
                     $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceUserTags($response['data']['htmlbody']);
                 }
             } else {
                 $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceCustomTags($response['data']['htmlbody'], $defaultTags, true);
                 $response['data']['htmlbody'] = \GO\Addressbook\Model\Template::model()->replaceUserTags($response['data']['htmlbody']);
             }
         }
         if ($params['content_type'] == 'plain') {
             $response['data']['plainbody'] = \GO\Base\Util\String::html_to_text($response['data']['htmlbody'], false);
             unset($response['data']['htmlbody']);
         }
     } else {
         $response['data'] = array();
         if ($params['content_type'] == 'plain') {
             $response['data']['plainbody'] = '';
         } else {
             $response['data']['htmlbody'] = '';
         }
     }
     $response['success'] = true;
     return $response;
 }
 public function actionUnsubscribe($params)
 {
     if (!isset($params['contact_id'])) {
         $params['contact_id'] = 0;
     }
     if (!isset($params['company_id'])) {
         $params['company_id'] = 0;
     }
     if (!empty($params['sure'])) {
         if ($params['contact_id']) {
             $contact = \GO\Addressbook\Model\Contact::model()->findByPk($params['contact_id']);
             if (md5($contact->ctime . $contact->addressbook_id . $contact->firstEmail) != $params['token']) {
                 throw new \Exception("Invalid token!");
             }
             $contact->email_allowed = 0;
             $contact->save();
             \GO\Base\Mail\AdminNotifier::sendMail("Unsubscribe: " . $contact->email, "Contact " . $contact->email . " unsubscribed from receiving newsletters");
         } else {
             if ($params['contact_id']) {
                 $company = \GO\Addressbook\Model\Company::model()->findByPk($params['company_id']);
                 if (md5($company->ctime . $company->addressbook_id . $company->email) != $params['token']) {
                     throw new \Exception("Invalid token!");
                 }
                 $company->email_allowed = 0;
                 $company->save();
                 \GO\Base\Mail\AdminNotifier::sendMail("Unsubscribe: " . $company->email, "Company " . $contact->email . " unsubscribed from receiving newsletters");
             }
         }
         $this->render('unsubscribed', $params);
     } else {
         $this->render('unsubscribe', $params);
     }
 }
Beispiel #5
0
 private function _setUserContact($user)
 {
     $contact = $user->createContact();
     $company = \GO\Addressbook\Model\Company::model()->findSingleByAttribute('name', 'ACME Rocket Powered Products');
     if (!$company) {
         $company = new \GO\Addressbook\Model\Company();
         $company->setAttributes(array('addressbook_id' => $contact->addressbook_id, 'name' => 'ACME Rocket Powered Products', 'address' => '1111 Broadway', 'address_no' => '', 'zip' => '10019', 'city' => 'New York', 'state' => 'NY', 'country' => 'US', 'post_address' => '1111 Broadway', 'post_address_no' => '', 'post_zip' => '10019', 'post_city' => 'New York', 'post_state' => 'NY', 'post_country' => 'US', 'phone' => '(555) 123-4567', 'fax' => '(555) 123-4567', 'email' => '*****@*****.**', 'homepage' => 'http://www.acmerpp.demo', 'bank_no' => '', 'vat_no' => 'US 1234.56.789.B01', 'user_id' => 1, 'comment' => 'The name Acme became popular for businesses by the 1920s, when alphabetized business telephone directories such as the Yellow Pages began to be widespread. There were a flood of businesses named Acme (some of these still survive[1]). For example, early Sears catalogues contained a number of products with the "Acme" trademark, including anvils, which are frequently used in Warner Bros. cartoons.[2]'));
         $company->save();
     }
     $contact->company_id = $company->id;
     $contact->function = 'CEO';
     $contact->cellular = '06-12345678';
     $contact->address = '1111 Broadway';
     $contact->address_no = '';
     $contact->zip = '10019';
     $contact->city = 'New York';
     $contact->state = 'NY';
     $contact->country = 'US';
     $contact->save();
 }
Beispiel #6
0
 protected function actionEmail($params)
 {
     $response['success'] = true;
     $response['results'] = array();
     if (empty($params['query'])) {
         return $response;
     }
     $query = '%' . preg_replace('/[\\s*]+/', '%', $params['query']) . '%';
     if (\GO::modules()->addressbook) {
         $response = array('total' => 0, 'results' => array());
         $userContactIds = array();
         $findParams = FindParams::newInstance()->searchQuery($query, array("CONCAT(t.first_name,' ',t.middle_name,' ',t.last_name)", 't.email', 't.email2', 't.email3'))->select('t.*, "' . addslashes(\GO::t('strUser')) . '" AS ab_name,c.name AS company_name')->limit(10)->joinModel(array('model' => 'GO\\Addressbook\\Model\\Company', 'foreignField' => 'id', 'localField' => 'company_id', 'tableAlias' => 'c', 'type' => 'LEFT'));
         //			if (!empty($params['requireEmail'])) {
         $criteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition("email", "", "!=")->addCondition("email2", "", "!=", 't', false)->addCondition("email3", "", "!=", 't', false);
         $findParams->getCriteria()->mergeWith($criteria);
         //			}
         if (\GO::user()->sort_email_addresses_by_time == 1 && \GO::modules()->addressbook) {
             $findParams->joinModel(array('model' => 'GO\\Email\\Model\\ContactMailTime', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'contact_id', 'tableAlias' => 'cmt', 'type' => 'LEFT', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', \GO::user()->id, '=', 'cmt')))->order('cmt.last_mail_time', 'DESC');
         }
         $stmt = \GO\Addressbook\Model\Contact::model()->findUsers(\GO::user()->id, $findParams);
         $userContactIds = array();
         foreach ($stmt as $contact) {
             $this->_formatContact($response, $contact);
             $userContactIds[] = $contact->id;
         }
         if (count($response['results']) < 10) {
             $findParams = FindParams::newInstance()->ignoreAcl()->select('t.*,c.name AS company_name, a.name AS ab_name')->searchQuery($query, array("CONCAT(t.first_name,' ',t.middle_name,' ',t.last_name)", 't.email', 't.email2', 't.email3'))->joinModel(array('model' => 'GO\\Addressbook\\Model\\Addressbook', 'foreignField' => 'id', 'localField' => 'addressbook_id', 'tableAlias' => 'a', 'type' => 'INNER'))->limit(10 - count($response['results']));
             //		if(!empty($params['joinCompany'])){
             $findParams->joinModel(array('model' => 'GO\\Addressbook\\Model\\Company', 'foreignField' => 'id', 'localField' => 'company_id', 'tableAlias' => 'c', 'type' => 'LEFT'));
             //		}
             $findParams->getCriteria()->addInTemporaryTableCondition('usercontacts', 'id', $userContactIds, 't', true, true);
             if (!empty($params['addressbook_id'])) {
                 $abs = array($params['addressbook_id']);
             } else {
                 $abs = \GO\Addressbook\Model\Addressbook::model()->getAllReadableAddressbookIds();
             }
             if (!empty($abs)) {
                 $findParams->getCriteria()->addInTemporaryTableCondition('readableaddressbooks', 'addressbook_id', $abs);
                 //					if (!empty($params['requireEmail'])) {
                 $criteria = \GO\Base\Db\FindCriteria::newInstance()->addCondition("email", "", "!=")->addCondition("email2", "", "!=", 't', false)->addCondition("email3", "", "!=", 't', false);
                 $findParams->getCriteria()->mergeWith($criteria);
                 //					}
                 $stmt = \GO\Addressbook\Model\Contact::model()->find($findParams);
                 if (\GO::user()->sort_email_addresses_by_time == 1 && GO::modules()->addressbook) {
                     $findParams->joinModel(array('model' => 'GO\\Email\\Model\\ContactMailTime', 'localTableAlias' => 't', 'localField' => 'id', 'foreignField' => 'contact_id', 'tableAlias' => 'cmt', 'type' => 'LEFT', 'criteria' => \GO\Base\Db\FindCriteria::newInstance()->addCondition('user_id', GO::user()->id, '=', 'cmt')))->order('cmt.last_mail_time', 'DESC');
                 }
                 $stmt = \GO\Addressbook\Model\Contact::model()->find($findParams);
                 $user_ids = array();
                 foreach ($stmt as $contact) {
                     $this->_formatContact($response, $contact);
                     if ($contact->go_user_id) {
                         $user_ids[] = $contact->go_user_id;
                     }
                 }
                 if (count($response['results']) < 10) {
                     $findParams = FindParams::newInstance()->ignoreAcl()->searchQuery($query)->limit(10 - count($response['results']));
                     $findParams->getCriteria()->addInTemporaryTableCondition('readableaddressbooks', 'addressbook_id', $abs);
                     //						if (!empty($params['requireEmail'])) {
                     $criteria = $findParams->getCriteria()->addCondition("email", "", "!=");
                     //						}
                     $stmt = \GO\Addressbook\Model\Company::model()->find($findParams);
                     foreach ($stmt as $company) {
                         $record = array();
                         $record['name'] = $company->name;
                         $l = new \GO\Base\Mail\EmailRecipients();
                         $l->addRecipient($company->email, $record['name']);
                         $record['info'] = htmlspecialchars((string) $l . ' (' . sprintf(\GO::t('companyFromAddressbook', 'addressbook'), $company->addressbook->name) . ')', ENT_COMPAT, 'UTF-8');
                         $record['full_email'] = htmlspecialchars((string) $l, ENT_COMPAT, 'UTF-8');
                         $response['results'][] = $record;
                     }
                 }
             }
         }
     } else {
         //no addressbook module for this user. Fall back to user search.
         $findParams = FindParams::newInstance()->searchQuery($query)->select('t.*')->limit(10 - count($response['results']));
         $findParams->getCriteria()->addCondition('enabled', true);
         $stmt = \GO\Base\Model\User::model()->find($findParams);
         while ($user = $stmt->fetch()) {
             $record['name'] = $user->name;
             $record['user_id'] = $user->id;
             $l = new \GO\Base\Mail\EmailRecipients();
             $l->addRecipient($user->email, $record['name']);
             $record['info'] = htmlspecialchars((string) $l . ' (' . \GO::t('strUser') . ')', ENT_COMPAT, 'UTF-8');
             $record['full_email'] = htmlspecialchars((string) $l, ENT_COMPAT, 'UTF-8');
             $response['results'][] = $record;
         }
     }
     return $response;
 }
 public function actionAdd($params)
 {
     $response = array('success' => true);
     $listId = $params['addresslistId'];
     $contactIds = json_decode($params['contacts'], true);
     $companyIds = json_decode($params['companies'], true);
     $removeOther = isset($params['move']) && $params['move'] == 'true';
     $targetAddresslistModel = \GO\Addressbook\Model\Addresslist::model()->findByPk($listId);
     if (!$targetAddresslistModel->checkPermissionLevel(\GO\Base\Model\Acl::CREATE_PERMISSION)) {
         throw new \GO\Base\Exception\AccessDenied();
     }
     if (!empty($removeOther)) {
         foreach ($contactIds as $contactId) {
             $contactModel = \GO\Addressbook\Model\Contact::model()->findByPk($contactId);
             $contactModel->removeAllManyMany('addresslists');
         }
         foreach ($companyIds as $companyId) {
             $companyModel = \GO\Addressbook\Model\Company::model()->findByPk($companyId);
             $companyModel->removeAllManyMany('addresslists');
         }
     }
     $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findByPk($listId);
     foreach ($contactIds as $contactId) {
         $addresslistModel->addManyMany('contacts', $contactId);
     }
     foreach ($companyIds as $companyId) {
         $addresslistModel->addManyMany('companies', $companyId);
     }
     return $response;
 }
Beispiel #8
0
 /**
  * Before importing a contact in the database first check if the company name of this contact
  * Is a company that excists in the database. If not create a company. After this set the id
  * of the create company to the contact we insert.
  * 
  * If the email addres set to a contact does not validate. Remove it so import wont fail
  */
 protected function beforeImport($params, &$model, &$attributes, $record)
 {
     $impBasParams = json_decode($params['importBaseParams'], true);
     $addressbookId = $impBasParams['addressbook_id'];
     if (!empty($attributes['Company'])) {
         $companyName = $attributes['Company'];
     } else {
         if (!empty($attributes['company'])) {
             $companyName = $attributes['company'];
         } else {
             if (!empty($attributes['company_name'])) {
                 $companyName = $attributes['company_name'];
             } else {
                 if (!empty($attributes['companyName'])) {
                     $companyName = $attributes['companyName'];
                 } else {
                     if (!empty($attributes['name'])) {
                         $companyName = $attributes['name'];
                     }
                 }
             }
         }
     }
     if (!empty($companyName)) {
         $companyModel = \GO\Addressbook\Model\Company::model()->find(\GO\Base\Db\FindParams::newInstance()->single()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('name', $companyName)->addCondition('addressbook_id', $addressbookId)));
         if (empty($companyModel)) {
             $companyModel = new \GO\Addressbook\Model\Company();
             $companyModel->setAttributes(array('name' => $companyName, 'addressbook_id' => $addressbookId));
             $companyModel->save();
         }
         $model->company_id = $companyModel->id;
     }
     if (isset($attributes['email']) && !\GO\Base\Util\String::validate_email($attributes['email'])) {
         unset($attributes['email']);
     }
     if (isset($attributes['email2']) && !\GO\Base\Util\String::validate_email($attributes['email2'])) {
         unset($attributes['email2']);
     }
     if (isset($attributes['email3']) && !\GO\Base\Util\String::validate_email($attributes['email3'])) {
         unset($attributes['email3']);
     }
     return parent::beforeImport($params, $model, $attributes, $record);
 }
 function process_form()
 {
     \GO::$ignoreAclPermissions = true;
     $this->check_required();
     if (!isset($_POST['salutation'])) {
         $_POST['salutation'] = isset($_POST['sex']) ? \GO::t('default_salutation_' . $_POST['sex']) : \GO::t('default_salutation_unknown');
     }
     //user registation
     //		if(!empty($_POST['username'])){
     //			$credentials = array ('username','first_name','middle_name','last_name','title','initials','sex','email',
     //			'home_phone','fax','cellular','address','address_no',
     //			'zip','city','state','country','company','department','function','work_phone',
     //			'work_fax');
     //
     //			if($_POST['password1'] != $_POST['password2'])
     //			{
     //				throw new Exception(\GO::t('error_match_pass','users'));
     //			}
     //
     //			foreach($credentials as $key)
     //			{
     //				if(!empty($_REQUEST[$key]))
     //				{
     //					$userCredentials[$key] = $_REQUEST[$key];
     //				}
     //			}
     //			$userCredentials['password']=$_POST['password1'];
     //
     //			$userModel = new \GO\Base\Model\User();
     //			$userModel->setAttributes($userCredentials);
     //			$userModel->save();
     //			foreach($this->user_groups as $groupId) {
     //				$currentGroupModel = \GO\Base\Model\Group::model()->findByPk($groupId);
     //				if($groupId>0 && $groupId!=\GO::config()->group_everyone && !$currentGroupModel->hasUser($userModel->id)) {
     //					$currentGroupModel->addUser($userModel->id);
     //				}
     //			}
     //			foreach($this->visible_user_groups as $groupId) {
     //				$userAclModel = \GO\Base\Model\Acl::model()->findByPk($userModel->acl_id);
     //				if($groupId>0 && !empty($userAclModel) && $userAclModel->hasGroup($groupId)) {
     //					$userAclModel->addGroup($groupId);
     //				}
     //			}
     //
     //			\GO::session()->login($userCredentials['username'], $userCredentials['password']);
     //		}
     if (!empty($_POST['email']) && !\GO\Base\Util\String::validate_email($_POST['email'])) {
         throw new Exception(\GO::t('invalidEmailError'));
     }
     if (!empty($_REQUEST['addressbook'])) {
         //			require($GO_LANGUAGE->get_language_file('addressbook'));
         //			require_once($GO_MODULES->modules['addressbook']['class_path'].'addressbook.class.inc.php');
         //			$ab = new addressbook();
         //
         //			$addressbook = $ab->get_addressbook_by_name($_REQUEST['addressbook']);
         $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('name', $_REQUEST['addressbook']);
         if (!$addressbookModel) {
             throw new Exception('Addressbook not found!');
         }
         $credentials = array('first_name', 'middle_name', 'last_name', 'title', 'initials', 'sex', 'email', 'email2', 'email3', 'home_phone', 'fax', 'cellular', 'comment', 'address', 'address_no', 'zip', 'city', 'state', 'country', 'company', 'department', 'function', 'work_phone', 'work_fax', 'salutation', 'url_linkedin', 'url_facebook', 'url_twitter', 'skype_name');
         foreach ($credentials as $key) {
             if (!empty($_REQUEST[$key])) {
                 $contactCredentials[$key] = $_REQUEST[$key];
             }
         }
         if (isset($contactCredentials['comment']) && is_array($contactCredentials['comment'])) {
             $comments = '';
             foreach ($contactCredentials['comment'] as $key => $value) {
                 if ($value == 'date') {
                     $value = date($_SESSION['GO_SESSION']['date_format'] . ' ' . $_SESSION['GO_SESSION']['time_format']);
                 }
                 if (!empty($value)) {
                     $comments .= trim($key) . ":\n" . trim($value) . "\n\n";
                 }
             }
             $contactCredentials['comment'] = $comments;
         }
         if ($this->no_urls && isset($contactCredentials['comment']) && stripos($contactCredentials['comment'], 'http')) {
             throw new Exception('Sorry, but to prevent spamming we don\'t allow URL\'s in the message');
         }
         $contactCredentials['addressbook_id'] = $addressbookModel->id;
         $contactCredentials['email_allowed'] = isset($_POST['email_allowed']) ? '1' : '0';
         if (!empty($contactCredentials['company']) && empty($contactCredentials['company_id'])) {
             $companyModel = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('name' => $contactCredentials['company'], 'addressbook_id' => $contactCredentials['addressbook_id']));
             if (empty($companyModel)) {
                 $companyModel = new \GO\Addressbook\Model\Company();
                 $companyModel->addressbook_id = $contactCredentials['addressbook_id'];
                 $companyModel->name = $contactCredentials['company'];
                 // bedrijfsnaam
                 $companyModel->user_id = \GO::user()->id;
                 $companyModel->save();
                 $contactCredentials['company_id'] = $companyModel->id;
             }
         }
         if (isset($_POST['birthday'])) {
             try {
                 $contactCredentials['birthday'] = \GO\Base\Util\Date::to_db_date($_POST['birthday'], false);
             } catch (Exception $e) {
                 throw new Exception(\GO::t('birthdayFormatMustBe') . ': ' . $_SESSION['GO_SESSION']['date_format'] . '.');
             }
             if (!empty($_POST['birthday']) && $contactCredentials['birthday'] == '0000-00-00') {
                 throw new Exception(\GO::t('invalidDateError'));
             }
         }
         unset($contactCredentials['company']);
         $existingContactModel = false;
         if (!empty($_POST['contact_id'])) {
             $existingContactModel = \GO\Addressbook\Model\Contact::model()->findByPk($_POST['contact_id']);
         } elseif (!empty($contactCredentials['email'])) {
             $existingContactModel = \GO\Addressbook\Model\Contact::model()->findSingleByAttributes(array('email' => $contactCredentials['email'], 'addressbook_id' => $contactCredentials['addressbook_id']));
         }
         if ($existingContactModel) {
             $this->contact_id = $contactId = $existingContactModel->id;
             $filesFolderId = $existingContactModel->files_folder_id = $existingContactModel->getFilesFolder()->id;
             /*
              * Only update empty fields
              */
             if (empty($_POST['contact_id'])) {
                 foreach ($contactCredentials as $key => $value) {
                     if ($key != 'comment') {
                         if (!empty($existingContactModel->{$key})) {
                             unset($contactCredentials[$key]);
                         }
                     }
                 }
             }
             $contactCredentials['id'] = $contactId;
             if (!empty($existingContactModel->comment) && !empty($contactCredentials['comment'])) {
                 $contactCredentials['comment'] = $existingContactModel->comment . "\n\n----\n\n" . $contactCredentials['comment'];
             }
             if (empty($contactCredentials['comment'])) {
                 unset($contactCredentials['comment']);
             }
             $existingContactModel->setAttributes($contactCredentials);
             $existingContactModel->save();
         } else {
             $newContactModel = new \GO\Addressbook\Model\Contact();
             $newContactModel->setAttributes($contactCredentials);
             $newContactModel->save();
             $this->contact_id = $contactId = $newContactModel->id;
             $filesFolderId = $newContactModel->files_folder_id = $newContactModel->getFilesFolder()->id;
             $newContactModel->save();
             if (isset($_POST['contact_id']) && empty($userId) && \GO::user()->id > 0) {
                 $userId = $this->user_id = \GO::user()->id;
             }
             if (!empty($userId)) {
                 $userModel = \GO\Base\Model\User::model()->findByPk($userId);
                 $userModel->contact_id = $contactId;
                 $userModel->save();
             }
         }
         if (!$contactId) {
             throw new Exception(\GO::t('saveError'));
         }
         if (\GO::modules()->isInstalled('files')) {
             $folderModel = \GO\Files\Model\Folder::model()->findByPk($filesFolderId);
             $path = $folderModel->path;
             $response['files_folder_id'] = $filesFolderId;
             $full_path = \GO::config()->file_storage_path . $path;
             foreach ($_FILES as $key => $file) {
                 if ($key != 'photo') {
                     //photo is handled later
                     if (is_uploaded_file($file['tmp_name'])) {
                         $fsFile = new \GO\Base\Fs\File($file['tmp_name']);
                         $fsFile->move(new \GO\Base\Fs\Folder($full_path), $file['name'], false, true);
                         $fsFile->setDefaultPermissions();
                         \GO\Files\Model\File::importFromFilesystem($fsFile);
                     }
                 }
             }
         }
         if (\GO::modules()->isInstalled('customfields')) {
             $cfFields = array();
             foreach ($_POST as $k => $v) {
                 if (strpos($k, 'col_') === 0) {
                     $cfFields[$k] = $v;
                 }
             }
             $contactCfModel = \GO\Addressbook\Customfields\Model\Contact::model()->findByPk($contactId);
             if (!$contactCfModel) {
                 $contactCfModel = new \GO\Addressbook\Customfields\Model\Contact();
                 $contactCfModel->model_id = $contactId;
             }
             $contactCfModel->setAttributes($cfFields);
             $contactCfModel->save();
         }
         if (isset($_POST['mailings'])) {
             foreach ($_POST['mailings'] as $mailingName) {
                 if (!empty($mailingName)) {
                     $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findSingleByAttribute('name', $mailingName);
                     if (empty($addresslistModel)) {
                         throw new Exception('Addresslist not found!');
                     }
                     $addresslistModel->addManyMany('contacts', $contactId);
                 }
             }
         }
         if ($this->contact_id > 0) {
             if (isset($_FILES['photo']['tmp_name']) && is_uploaded_file($_FILES['photo']['tmp_name'])) {
                 $fsFile = new \GO\Base\Fs\File($_FILES['photo']['tmp_name']);
                 $fsFile->move(new \GO\Base\Fs\Folder(\GO::config()->tmpdir), $_FILES['photo']['name'], false, false);
                 $contactModel = \GO\Addressbook\Model\Contact::model()->findByPk($contactId);
                 $contactModel->setPhoto(\GO::config()->tmpdir . $_FILES['photo']['name']);
             }
         }
         if (!isset($_POST['contact_id'])) {
             /**
              * Send notification of new contact to (1) users specified by 'notify_users'
              * in the form itself and to (2) the addressbook owner if so specified. 
              */
             // Send the email to the admin users in the language of the addressbook owner.
             $oldLanguage = \GO::language()->getLanguage();
             \GO::language()->setLanguage($addressbookModel->user->language);
             $usersToNotify = isset($_POST['notify_users']) ? explode(',', $_POST['notify_users']) : array();
             if (!empty($_POST['notify_addressbook_owner'])) {
                 $usersToNotify[] = $addressbookModel->user_id;
             }
             $mailTo = array();
             foreach ($usersToNotify as $userToNotifyId) {
                 $userModel = \GO\Base\Model\User::model()->findByPk($userToNotifyId);
                 $mailTo[] = $userModel->email;
             }
             if (count($mailTo)) {
                 $viewContactUrl = \GO::createExternalUrl('addressbook', 'showContact', array($contactId));
                 $contactModel = \GO\Addressbook\Model\Contact::model()->findByPk($contactId);
                 $companyModel = \GO\Addressbook\Model\Company::model()->findByPk($contactModel->company_id);
                 if (!empty($companyModel)) {
                     $companyName = $companyModel->name;
                 } else {
                     $companyName = '';
                 }
                 $values = array('address_no', 'address', 'zip', 'city', 'state', 'country');
                 $formatted_address = nl2br(\GO\Base\Util\Common::formatAddress('{country}', '{address}', '{address_no}', '{zip}', '{city}', '{state}'));
                 foreach ($values as $val) {
                     $formatted_address = str_replace('{' . $val . '}', $contactModel->{$val}, $formatted_address);
                 }
                 $body = \GO::t('newContactFromSite', 'addressbook') . ':<br />';
                 $body .= \GO::t('name', 'addressbook') . ': ' . $contactModel->addressbook->name . '<br />';
                 $body .= "<br />" . $contactModel->name;
                 $body .= "<br />" . $formatted_address;
                 if (!empty($contactModel->home_phone)) {
                     $body .= "<br />" . \GO::t('phone') . ': ' . $contactModel->home_phone;
                 }
                 if (!empty($contactModel->cellular)) {
                     $body .= "<br />" . \GO::t('cellular') . ': ' . $contactModel->cellular;
                 }
                 if (!empty($companyName)) {
                     $body .= "<br /><br />" . $companyName;
                 }
                 if (!empty($contactModel->work_phone)) {
                     $body .= "<br />" . \GO::t('workphone') . ': ' . $contactModel->work_phone;
                 }
                 $body .= '<br /><a href="' . $viewContactUrl . '">' . \GO::t('clickHereToView', 'addressbook') . '</a>' . "<br />";
                 $mailFrom = !empty($_POST['mail_from']) ? $_POST['mail_from'] : \GO::config()->webmaster_email;
                 $mailMessage = \GO\Base\Mail\Message::newInstance(\GO::t('newContactAdded', 'addressbook'), $body, 'text/html')->setFrom($mailFrom, \GO::config()->title);
                 foreach ($mailTo as $v) {
                     $mailMessage->addTo($v);
                 }
                 \GO\Base\Mail\Mailer::newGoInstance()->send($mailMessage);
             }
             // Restore the language
             \GO::language()->setLanguage($oldLanguage);
         }
         //
         //
         //	Maybe make this workable with GO 4.0 later....
         //
         //
         //			if(isset($_POST['confirmation_template']))
         //			{
         //				if(empty($_POST['email']))
         //				{
         //					throw new Exception('Fatal error: No email given for confirmation e-mail!');
         //				}
         //
         //				$url = create_direct_url('addressbook', 'showContact', array($contactId));
         //				$body = $lang['addressbook']['newContactFromSite'].'<br /><a href="'.$url.'">'.$lang['addressbook']['clickHereToView'].'</a>';
         //
         //				global $smarty;
         //				$email = $smarty->fetch($_POST['confirmation_template']);
         //
         //				$pos = strpos($email,"\n");
         //
         //				$subject = trim(substr($email, 0, $pos));
         //				$body = trim(substr($email,$pos));
         //
         //				require_once(\GO::config()->class_path.'mail/GoSwift.class.inc.php');
         //				$swift = new GoSwift($_POST['email'], $subject);
         //				$swift->set_body($body);
         //				$swift->set_from(\GO::config()->webmaster_email, \GO::config()->title);
         //				$swift->sendmail();
         //			}
         if (isset($_POST['confirmation_email']) && !empty($_POST['email'])) {
             if (strpos($_POST['confirmation_email'], '../') !== false || strpos($_POST['confirmation_email'], '..\\') !== false) {
                 throw new Exception('Invalid path');
             }
             $path = \GO::config()->file_storage_path . $_POST['confirmation_email'];
             if (!file_exists($path)) {
                 $path = dirname(\GO::config()->get_config_file()) . '/' . $_POST['confirmation_email'];
             }
             //$email = file_get_contents($path);
             //$messageModel = \GO\Email\Model\SavedMessage::model()->createFromMimeFile($path);
             //				$htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceUserTags($messageModel->getHtmlBody());
             //				$htmlBodyString = \GO\Addressbook\Model\Template::model()
             //								->replaceContactTags(
             //												$htmlBodyString,
             //												\GO\Addressbook\Model\Contact::model()->findByPk($contactId),
             //												false);
             //				$messageModel->body =
             $mailMessage = \GO\Base\Mail\Message::newInstance()->loadMimeMessage(file_get_contents($path));
             $htmlBodyString = $mailMessage->getBody();
             foreach ($this->confirmation_replacements as $tag => $replacement) {
                 $htmlBodyString = str_replace('{' . $tag . '}', $replacement, $htmlBodyString);
             }
             $htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceUserTags($htmlBodyString, true);
             $htmlBodyString = \GO\Addressbook\Model\Template::model()->replaceContactTags($htmlBodyString, \GO\Addressbook\Model\Contact::model()->findByPk($contactId), false);
             $mailMessage->setBody($htmlBodyString);
             $mailMessage->setFrom($mailMessage->getFrom(), $mailMessage->getSender());
             $mailMessage->addTo($_POST['email']);
             \GO\Base\Mail\Mailer::newGoInstance()->send($mailMessage);
         }
     }
 }
 public function actionGetCompanies($params)
 {
     $ids = json_decode($params['companies']);
     $store = new \GO\Base\Data\ArrayStore();
     foreach ($ids as $company_id) {
         $company = \GO\Addressbook\Model\Company::model()->findByPk($company_id);
         $participant = new \GO\Calendar\Model\Participant();
         $participant->name = $company->name;
         $participant->email = $company->email;
         $store->addRecord($participant->toJsonArray($params['start_time'], $params['end_time']));
     }
     return $store->getData();
 }
Beispiel #11
0
 protected function actionContact()
 {
     //GOS::site()->config->contact_addressbook_id;
     if (\GO\Base\Util\Http::isPostRequest()) {
         if (isset($_POST['Addressbook']['name'])) {
             $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findSingleByAttribute('name', $_POST['Addressbook']['name']);
         } else {
             $addressbookModel = \GO\Addressbook\Model\Addressbook::model()->findByPk($_POST['Addressbook']['id']);
         }
         if (!$addressbookModel) {
             throw new \Exception(sprintf(\GO::t('addressbookNotFound', 'defaultsite'), $_POST['Addressbook']['name']));
         }
         $contactModel = \GO\Addressbook\Model\Contact::model()->findSingleByAttributes(array('email' => $_POST['Contact']['email'], 'addressbook_id' => $addressbookModel->id));
         if (!$contactModel) {
             $contactModel = new \GO\Addressbook\Model\Contact();
             $contactModel->addressbook_id = $addressbookModel->id;
         }
         $contactModel->setValidationRule('first_name', 'required', true);
         $contactModel->setValidationRule('last_name', 'required', true);
         $contactModel->setValidationRule('email', 'required', true);
         $companyModel = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('name' => $_POST['Company']['name'], 'addressbook_id' => $addressbookModel->id));
         if (!$companyModel) {
             $companyModel = new \GO\Addressbook\Model\Company();
             $companyModel->addressbook_id = $addressbookModel->id;
         }
         $companyModel->setValidationRule('name', 'required', true);
         $companyModel->setAttributes($_POST['Company']);
         if ($companyModel->validate()) {
             $companyModel->save();
             $contactModel->company_id = $companyModel->id;
         }
         $contactModel->setAttributes($_POST['Contact']);
         if ($contactModel->validate()) {
             $saveSuccess = $contactModel->save();
             if ($saveSuccess) {
                 // Add to mailings.
                 $addresslists = !empty($_POST['Addresslist']) ? $_POST['Addresslist'] : array();
                 foreach ($addresslists as $addresslistName => $checked) {
                     if (!empty($checked)) {
                         $addresslistModel = \GO\Addressbook\Model\Addresslist::model()->findSingleByAttribute('name', $addresslistName);
                         if ($addresslistModel) {
                             $addresslistContactModel = \GO\Addressbook\Model\AddresslistContact::model()->findSingleByAttributes(array('contact_id' => $contactModel->id, 'addresslist_id' => $addresslistModel->id));
                             if (!$addresslistContactModel) {
                                 $addresslistContactModel = new \GO\Addressbook\Model\AddresslistContact();
                                 $addresslistContactModel->contact_id = $contactModel->id;
                                 $addresslistContactModel->addresslist_id = $addresslistModel->id;
                                 $addresslistContactModel->save();
                             }
                         }
                     }
                 }
                 echo $this->render('contactform_done');
             } else {
                 echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
             }
         } else {
             $validationErrors = $contactModel->getValidationErrors();
             foreach ($validationErrors as $valError) {
                 echo $valError;
             }
             echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
         }
     } else {
         $addressbookModel = new \GO\Addressbook\Model\Addressbook();
         $contactModel = new \GO\Addressbook\Model\Contact();
         $companyModel = new \GO\Addressbook\Model\Company();
         echo $this->render('contactform', array('contact' => $contactModel, 'company' => $companyModel, 'addressbook' => $addressbookModel));
     }
 }
Beispiel #12
0
 private function _updateContact($user, $attributes)
 {
     $contact = $user->createContact();
     if ($contact) {
         \GO::debug('LDAPAUTH: updating user contact');
         $contact->setAttributes($attributes);
         $contact->cutAttributeLengths();
         $contact->skip_user_update = true;
         if (!empty($attributes['company'])) {
             $company = \GO\Addressbook\Model\Company::model()->findSingleByAttributes(array('addressbook_id' => $contact->addressbook_id, 'name' => $attributes['company']));
             if (!$company) {
                 \GO::debug('LDAPAUTH: creating company for contact');
                 $company = new \GO\Addressbook\Model\Company();
                 $company->name = $attributes['company'];
                 $company->addressbook_id = $contact->addressbook_id;
                 $company->cutAttributeLengths();
                 $company->save();
             } else {
                 \GO::debug('LDAPAUTH: found existing company for contact');
             }
             $contact->company_id = $company->id;
         }
         $contact->save();
     }
 }
Beispiel #13
0
 /**
  * Import a contact (with or without company) from a VObject 
  * 
  * @param Sabre\VObject\Component $vobject
  * @param array $attributes Extra attributes to apply to the contact. Raw values should be past. No input formatting is applied.
  * @return Contact
  */
 public function importVObject(Sabre\VObject\Component $vobject, $attributes = array(), $saveToDb = true, $ignoreInvalidProperties = true)
 {
     //$event = new \GO\Calendar\Model\Event();
     $companyAttributes = array();
     //		if (!empty($attributes['addressbook_id'])) {
     //			$companyAttributes['addressbook_id'] = $attributes['addressbook_id'];
     //		}
     $uid = (string) $vobject->uid;
     if (!empty($uid) && empty($attributes['uuid'])) {
         $attributes['uuid'] = $uid;
     }
     $emails = array();
     foreach ($vobject->children as $vobjProp) {
         switch ($vobjProp->name) {
             case 'PHOTO':
                 if ($vobjProp->getValue()) {
                     $photoFile = \GO\Base\Fs\File::tempFile('', 'jpg');
                     $photoFile->putContents($vobjProp->getValue());
                 }
                 break;
             case 'N':
                 $nameArr = explode(';', $vobjProp->getValue());
                 if (isset($nameArr[0])) {
                     $attributes['last_name'] = $nameArr[0];
                 }
                 if (isset($nameArr[1])) {
                     $attributes['first_name'] = $nameArr[1];
                 }
                 $attributes['middle_name'] = !empty($nameArr[2]) ? $nameArr[2] : '';
                 $attributes['suffix'] = !empty($nameArr[4]) ? $nameArr[4] : '';
                 $attributes['title'] = !empty($nameArr[3]) ? $nameArr[3] : '';
                 break;
             case 'ORG':
                 $companyAttributes['name'] = null;
                 if ($vobjProp->getValue()) {
                     $compNameArr = explode(';', $vobjProp->getValue());
                     if (!empty($compNameArr[0])) {
                         $companyAttributes['name'] = $compNameArr[0];
                     }
                     if (!empty($compNameArr[1])) {
                         $attributes['department'] = $compNameArr[1];
                     }
                     if (!empty($compNameArr[2])) {
                         $companyAttributes['name2'] = $compNameArr[2];
                     }
                 }
                 break;
                 //				case 'TITLE':
                 //					$attributes['title'] = $vobjProp->getValue() ? $vobjProp->getValue() : null;
                 //					break;
             //				case 'TITLE':
             //					$attributes['title'] = $vobjProp->getValue() ? $vobjProp->getValue() : null;
             //					break;
             case 'TEL':
                 if ($vobjProp->getValue()) {
                     $types = array();
                     foreach ($vobjProp->parameters as $param) {
                         if ($param->name == 'TYPE') {
                             $types = explode(',', strtolower($param->getValue()));
                         }
                     }
                     if (in_array('work', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         $attributes['work_phone'] = $vobjProp->getValue();
                         $companyAttributes['phone'] = $vobjProp->getValue();
                     }
                     if (in_array('cell', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         if (empty($attributes['cellular'])) {
                             $attributes['cellular'] = $vobjProp->getValue();
                         } elseif (empty($attributes['cellular2'])) {
                             $attributes['cellular2'] = $vobjProp->getValue();
                         }
                     }
                     if (in_array('fax', $types) && in_array('home', $types)) {
                         $attributes['fax'] = $vobjProp->getValue();
                     }
                     if (in_array('fax', $types) && in_array('work', $types)) {
                         $companyAttributes['fax'] = $vobjProp->getValue();
                         $attributes['work_fax'] = $vobjProp->getValue();
                     }
                     if (in_array('home', $types) && (in_array('voice', $types) || count($types) == 1)) {
                         $attributes['home_phone'] = $vobjProp->getValue();
                     }
                 }
                 //					foreach ($vobjProp->parameters as $param) {
                 //						if ($param['name']=='TYPE') {
                 //							switch (susbstr($param['value'],0,4)) {
                 //								case 'work':
                 //									$attributes['work_phone'] = $vobjProp->getValue();
                 //									break;
                 //								default:
                 //									$attributes['home_phone'] = $vobjProp->getValue();
                 //									break;
                 //							}
                 //						}
                 //					}
                 break;
                 //				case 'LABEL':
             //				case 'LABEL':
             case 'ADR':
                 $types = array();
                 foreach ($vobjProp->parameters as $param) {
                     if ($param->name == 'TYPE') {
                         $types = explode(',', strtolower($param->getValue()));
                     }
                 }
                 if (in_array('work', $types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $companyAttributes['address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $companyAttributes['city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $companyAttributes['state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $companyAttributes['zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $companyAttributes['country'] = $addrArr[6];
                     }
                 }
                 if (in_array('home', $types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $attributes['address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $attributes['city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $attributes['state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $attributes['zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $attributes['country'] = $addrArr[6];
                     }
                 }
                 if (empty($types)) {
                     $addrArr = explode(';', $vobjProp->getValue());
                     if (isset($addrArr[2])) {
                         $companyAttributes['post_address'] = $addrArr[2];
                     }
                     if (isset($addrArr[3])) {
                         $companyAttributes['post_city'] = $addrArr[3];
                     }
                     if (isset($addrArr[4])) {
                         $companyAttributes['post_state'] = $addrArr[4];
                     }
                     if (isset($addrArr[5])) {
                         $companyAttributes['post_zip'] = $addrArr[5];
                     }
                     if (isset($addrArr[6])) {
                         $companyAttributes['post_country'] = $addrArr[6];
                     }
                 }
                 break;
             case 'EMAIL':
                 //					foreach ($vobjProp->parameters as $param) {
                 //						if ($param->name=='TYPE')
                 //							$types = explode(',',strtolower($param->getValue()));
                 //						else
                 //							$types = array();
                 //					}
                 //					if(in_array('pref',$types)) {
                 //						$attributes['email'] = $vobjProp->getValue();
                 //					} elseif(in_array('home',$types)) {
                 //						$attributes['email2'] = $vobjProp->getValue();
                 //					} elseif(in_array('work',$types)) {
                 //						$attributes['email3'] = $vobjProp->getValue();
                 //					} else {
                 //						$attributes['email'] = $vobjProp->getValue();
                 //					}
                 if ($vobjProp->getValue()) {
                     $emails[] = $vobjProp->getValue();
                 }
                 break;
             case 'TITLE':
                 $attributes['function'] = $vobjProp->getValue();
                 break;
             case 'BDAY':
                 if ($vobjProp->getValue()) {
                     // is already formatted in GO\Base\VObject\Reader::convertVCard21ToVCard30
                     // $attributes['birthday'] = substr($vobjProp->getValue(),0,4).'-'.substr($vobjProp->getValue(),5,2).'-'.substr($vobjProp->getValue(),8,2);
                     $attributes['birthday'] = $vobjProp->getValue();
                 }
                 break;
             case 'NOTE':
                 $attributes['comment'] = $vobjProp->getValue();
                 break;
             case 'VERSION':
             case 'LAST-MODIFIED':
                 break;
             default:
                 $paramsArr = array();
                 foreach ($vobjProp->parameters as $param) {
                     $paramsArr[] = $param->serialize();
                 }
                 //					$remainingVcardProps[] = array('name' => $vobjProp->name, 'parameters'=>implode(';',$paramsArr), 'value'=>$vobjProp->getValue());
                 break;
         }
     }
     foreach ($emails as $email) {
         if (!isset($attributes['email'])) {
             $attributes['email'] = $email;
         } elseif (!isset($attributes['email2'])) {
             $attributes['email2'] = $email;
         } elseif (!isset($attributes['email3'])) {
             $attributes['email3'] = $email;
         }
     }
     //some attributes can be specified with multiple values like tel and email.
     //We don't know which value is going to map to which exact GO attribute because every client handles this differently.
     //Clear the values if they haven't been found at all.
     //
     // Not clearing them cause some client might not send it and this can cause data loss.
     //		$attributesMultiple=array('home_phone','work_phone','fax', 'work_fax','cellular','email','email2','email3');
     //		foreach($attributesMultiple as $attributeName){
     //			if(!isset($attributes[$attributeName]))
     //				$attributes[$attributeName]="";
     //		}
     $attributes = array_map('trim', $attributes);
     $attributes = $this->_splitAddress($attributes);
     if (empty($attributes['last_name']) && empty($attributes['first_name'])) {
         $attributes['first_name'] = 'unnamed';
     }
     $this->setAttributes($attributes, false);
     if (isset($companyAttributes['name'])) {
         $company = Company::model()->findSingleByAttributes(array('name' => $companyAttributes['name'], 'addressbook_id' => $this->addressbook_id));
         if (!$company) {
             $company = new Company();
             $company->setAttributes($companyAttributes, false);
             $company->addressbook_id = $this->addressbook_id;
         }
         if (!empty($saveToDb)) {
             $company->save();
         }
         $this->setAttribute('company_id', $company->id);
     }
     $this->cutAttributeLengths();
     if ($ignoreInvalidProperties) {
         $this->ignoreInvalidProperties();
     }
     if (!empty($saveToDb)) {
         $this->save();
     }
     if (!empty($photoFile) && $saveToDb) {
         $this->setPhoto($photoFile);
         $this->save();
     }
     //		foreach ($remainingVcardProps as $prop) {
     //			if (!empty($this->id) && substr($prop['name'],0,2)=='X-') {
     //				// Process encounters a custom property name in the VCard.
     //				$arr = explode('-',$prop['name']);
     //				$currentPropName = 'X-'.$arr[1];
     //				if (!in_array($currentPropName,$deletedPropertiesPrefixes_nonGO)) {
     //					// Process encounters a new custom property prefix in the VCard.
     //					// Now deleting all properties with this contact that have this prefix.
     //					// Because of $deletedPropertiesPrefixes_nonGO, this is only done once
     //					// per sync per VCard.
     //					$deletablePropertiesStmt = ContactVcardProperty::model()->find(
     //						\GO\Base\Db\FindParams::newInstance()->criteria(
     //							\GO\Base\Db\FindCriteria::newInstance()
     //								->addCondition('contact_id',$this->id)
     //								->addCondition('name',$currentPropName.'-%','LIKE')
     //						)
     //					);
     //
     //					while ($delPropModel = $deletablePropertiesStmt->fetch())
     //						$delPropModel->delete();
     //
     //					$deletedPropertiesPrefixes_nonGO[] = $currentPropName; // Keep track of prefixes for which we have deleted the properties.
     //				}
     //			}
     //
     //			$propModel = ContactVcardProperty::model()->find(
     //				\GO\Base\Db\FindParams::newInstance()
     //					->single()
     //					->criteria(
     //						\GO\Base\Db\FindCriteria::newInstance()
     //							->addCondition('contact_id',$this->id)
     //							->addCondition('name',$prop['name'])
     //							->addCondition('parameters',$prop['parameters'])
     //					)
     //				);
     //			if (empty($propModel))
     //				$propModel = new ContactVcardProperty();
     //			$propModel->contact_id = $this->id;
     //			$propModel->name = $prop['name'];
     //			$propModel->parameters = $prop['parameters'];
     //			$propModel->value = $prop['value'];
     //			$propModel->cutAttributeLengths();
     //			$propModel->save();
     //		}
     return $this;
 }