Beispiel #1
0
 protected function actionProfile()
 {
     $user = \GO::user();
     $contact = $user->contact;
     //set additional required fields
     $contact->setValidationRule('address', 'required', true);
     $contact->setValidationRule('zip', 'required', true);
     $contact->setValidationRule('city', 'required', true);
     //		$user->setValidationRule('passwordConfirm', 'required', false);
     $user->setValidationRule('password', 'required', false);
     \GO::config()->password_validate = false;
     if ($contact->company) {
         $company = $contact->company;
     } else {
         $company = new \GO\Addressbook\Model\Company();
         $company->addressbook_id = $contact->addressbook_id;
     }
     if (\GO\Base\Util\Http::isPostRequest()) {
         if (!empty($_POST['currentPassword']) && !empty($_POST['User']['password'])) {
             if (!$user->checkPassword($_POST['currentPassword'])) {
                 GOS::site()->notifier->setMessage('error', "Huidig wachtwoord onjuist");
                 unset($_POST['User']['password']);
                 unset($_POST['User']['passwordConfirm']);
             }
         } else {
             unset($_POST['User']['password']);
             unset($_POST['User']['passwordConfirm']);
         }
         $user->setAttributes($_POST['User']);
         $contact->setAttributes($_POST['Contact']);
         $company->setAttributes($_POST['Company']);
         $company->checkVatNumber = true;
         if (!empty($_POST['Company']['postAddressIsEqual'])) {
             $company->setPostAddressFromVisitAddress();
         }
         if (!GOS::site()->notifier->hasMessage('error') && $user->validate() && $contact->validate() && $company->validate()) {
             \GO::setIgnoreAclPermissions();
             //allow guest to create user
             $user->save();
             $company->save();
             $contact->company_id = $company->id;
             $contact->save();
             GOS::site()->notifier->setMessage('success', GOS::t('formEditSuccess'));
         } else {
             GOS::site()->notifier->setMessage('error', "Please check the form for errors");
         }
     }
     $company->post_address_is_address = false;
     if ($company->address == $company->post_address && $company->address_no == $company->post_address_no && $company->city == $company->post_city) {
         $company->post_address_is_address = true;
     }
     //clear values for form
     $user->password = "";
     $user->passwordConfirm = "";
     echo $this->render('profile', array('user' => $user, 'contact' => $contact, 'company' => $company));
 }
 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);
         }
     }
 }
Beispiel #3
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 #4
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));
     }
 }