protected function afterDisplay(&$response, &$model, &$params) { \GO::debug(get_class($this)); $response['data']['photo_url'] = $model->photoThumbURL; $response['data']['original_photo_url'] = $model->photoURL; $response['data']['addressbook_name'] = $model->addressbook->name; $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country); $response['data']['formatted_address'] = nl2br($model->getFormattedAddress()); $response['data']['post_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->post_address, $model->post_address_no, $model->post_city, $model->post_country); $response['data']['post_formatted_address'] = nl2br($model->getFormattedPostAddress()); $response['data']['employees'] = array(); $sortAlias = \GO::user()->sort_name == "first_name" ? array('first_name', 'last_name') : array('last_name', 'first_name'); $stmt = $model->contacts(\GO\Base\Db\FindParams::newInstance()->order($sortAlias)); while ($contact = $stmt->fetch()) { $response['data']['employees'][] = array('id' => $contact->id, 'name' => $contact->getName(\GO::user()->sort_name), 'function' => $contact->function, 'email' => $contact->email); } if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Company", $model->addressbook_id)) { $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Company", $model->addressbook_id); $enabled = array(); foreach ($response['data']['customfields'] as $cat) { if (in_array($cat['id'], $ids)) { $enabled[] = $cat; } } $response['data']['customfields'] = $enabled; } if (\GO::modules()->isInstalled('customfields')) { $response['data']['items_under_blocks'] = array(); $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className()); foreach ($enabledBlocksStmt as $i => $enabledBlockModel) { $items = $enabledBlockModel->block->getItemNames($model->id, $model->name); if (!empty($items)) { $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items); $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : ''; $modelNameArr = explode('_', $blockedItemsEl['model_name']); $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : ''; $response['data']['items_under_blocks'][] = $blockedItemsEl; } } } return parent::afterDisplay($response, $model, $params); }
/** * Constructor of a file or folder * * @param string $path The absolute path must be suplied * @throws Exception */ public function __construct($path) { // \GO::debug("FS construct $path"); if (empty($path)) { throw new \Exception("Path may not be empty in Base"); } //normalize path slashes if (\GO\Base\Util\Common::isWindows()) { $path = str_replace('\\', '/', $path); } if (!self::checkPathInput($path)) { throw new \Exception("The supplied path '{$path}' was invalid"); } $parent = dirname($path); if ($parent != '/') { $this->path = $parent; } else { $this->path = ''; } $this->path .= '/' . self::utf8Basename($path); }
public function encode($xml, $output = false) { file_put_contents($this->_xmlFile, $xml); if (\GO\Base\Util\Common::isWindows()) { $cmd = \GO::config()->cmd_xml2wbxml . ' -o ' . $this->_wbxmlFile . ' ' . $this->_xmlFile; } else { $cmd = \GO::config()->cmd_xml2wbxml . ' -o ' . $this->_wbxmlFile . ' ' . $this->_xmlFile . ' 2>/dev/null'; } exec($cmd); if (!file_exists($this->_wbxmlFile)) { throw new \Exception('xml2wbxml conversion failed'); } if ($output) { readfile($this->_wbxmlFile); } else { $wbxml = trim(file_get_contents($this->_wbxmlFile)); } //remove temp files unlink($this->_wbxmlFile); unlink($this->_xmlFile); return $output ? true : $wbxml; }
/** * Create a ZIP archive encoded in CP850 so that Windows will understand * foreign characters * * @param File $archiveFile * @param Folder $workingFolder * @param Base[] $sources * @param boolean $utf8 Set to true to use UTF8 encoding. This is not supported by Windows explorer. * @throws Exception */ public static function create(File $archiveFile, Folder $workingFolder, $sources, $utf8 = false) { if (class_exists("\\ZipArchive") && !$utf8) { \GO::debug("Using PHP ZipArchive"); $zip = new \ZipArchive(); $zip->open($archiveFile->path(), \ZipArchive::CREATE); for ($i = 0; $i < count($sources); $i++) { if ($sources[$i]->isFolder()) { self::_zipDir($sources[$i], $zip, str_replace($workingFolder->path() . '/', '', $sources[$i]->path()) . '/'); } else { $name = str_replace($workingFolder->path() . '/', '', $sources[$i]->path()); $name = @iconv('UTF-8', 'CP850//TRANSLIT', $name); \GO::debug("Add file: " . $sources[$i]->path()); $zip->addFile($sources[$i]->path(), $name); } } if (!$zip->close() || !$archiveFile->exists()) { throw new \Exception($zip->getStatusString()); } else { return true; } } else { \GO::debug("Using zip exec"); if (!\GO\Base\Util\Common::isWindows()) { putenv('LANG=en_US.UTF-8'); } chdir($workingFolder->path()); $cmdSources = array(); for ($i = 0; $i < count($sources); $i++) { $cmdSources[$i] = escapeshellarg(str_replace($workingFolder->path() . '/', '', $sources[$i]->path())); } $cmd = \GO::config()->cmd_zip . ' -r ' . escapeshellarg($archiveFile->path()) . ' ' . implode(' ', $cmdSources); exec($cmd, $output, $ret); if ($ret != 0 || !$archiveFile->exists()) { throw new \Exception('Command failed: ' . $cmd . "<br /><br />" . implode("<br />", $output)); } return true; } }
private function _launchBatchSend($mailing_id) { $mailing = \GO\Addressbook\Model\SentMailing::model()->findByPk($mailing_id); if (!$mailing) { throw new \Exception("Mailing not found!\n"); } $joinCriteria = \GO\Base\Db\FindCriteria::newInstance()->addRawCondition('t.id', 'a.account_id'); $findParams = \GO\Base\Db\FindParams::newInstance()->single()->join(\GO\Email\Model\Alias::model()->tableName(), $joinCriteria, 'a')->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('id', $mailing->alias_id, '=', 'a')); $account = \GO\Email\Model\Account::model()->find($findParams); $pwdParam = ''; if ($account && !empty(\GO::session()->values['emailModule']['smtpPasswords'][$account->id])) { $mailing->temp_pass = \GO::session()->values['emailModule']['smtpPasswords'][$account->id]; $mailing->save(); $pwdParam = '--smtp_password='******'emailModule']['smtpPasswords'][$account->id]; } $log = \GO::config()->file_storage_path . 'log/mailings/'; if (!is_dir($log)) { mkdir($log, 0755, true); } $log .= $mailing_id . '.log'; $cmd = \GO::config()->cmd_php . ' ' . \GO::config()->root_path . 'groupofficecli.php -r=addressbook/sentMailing/batchSend -c="' . \GO::config()->get_config_file() . '" --mailing_id=' . $mailing_id . ' ' . $pwdParam . ' >> ' . $log; if (!\GO\Base\Util\Common::isWindows()) { $cmd .= ' 2>&1 &'; } file_put_contents($log, \GO\Base\Util\Date::get_timestamp(time()) . "\r\n" . $cmd . "\r\n\r\n", FILE_APPEND); if (\GO\Base\Util\Common::isWindows()) { pclose(popen("start /B " . $cmd, "r")); } else { exec($cmd, $outputarr, $returnvar); \GO::debug('===== CMD ====='); \GO::debug($cmd); \GO::debug('===== OUTPUT ARR ====='); \GO::debug(var_export($outputarr, true)); \GO::debug('===== RETURN VAR ====='); \GO::debug(var_export($returnvar, true)); } }
/** * Constructor. Initialises all public variables. * * @access public * @return void */ function __construct() { $config = array(); $this->root_path = str_replace('\\', '/', dirname(dirname(dirname(__FILE__)))) . '/'; //suppress error for open_basedir warnings etc if (@file_exists('/etc/groupoffice/globalconfig.inc.php')) { require '/etc/groupoffice/globalconfig.inc.php'; } $config_file = $this->get_config_file(); if ($config_file) { include $config_file; } foreach ($config as $key => $value) { $this->{$key} = $value; } // if($this->info_log=="") // $this->info_log =$this->file_storage_path.'log/info.log'; //this can be used in some cases where you don't want the dynamically //determined full URL. This is done in set_full_url below. $this->orig_full_url = $this->full_url; $this->orig_tmpdir = $this->tmpdir; if (empty($this->db_user)) { //Detect some default values for installation if root_path is not set yet $this->host = dirname($_SERVER['PHP_SELF']); if (basename($this->host) == 'install') { $this->host = dirname($this->host); } if (substr($this->host, -1) != '/') { $this->host .= '/'; } $this->db_host = 'localhost'; if (Util\Common::isWindows()) { $this->file_storage_path = substr($this->root_path, 0, 3) . 'groupoffice/'; $this->tmpdir = substr($this->root_path, 0, 3) . 'temp'; $this->cmd_zip = $this->root_path . 'controls/win32/zip.exe'; $this->cmd_unzip = $this->root_path . 'controls/win32/unzip.exe'; $this->cmd_xml2wbxml = $this->root_path . 'controls/win32/libwbxml/xml2wbxml.exe'; $this->cmd_wbxml2xml = $this->root_path . 'controls/win32/libwbxml/wbxml2xml.exe'; $this->convert_utf8_filenames_to_ascii = true; } if (empty($config['tmpdir']) && function_exists('sys_get_temp_dir')) { $this->tmpdir = rtrim(str_replace('\\', '/', sys_get_temp_dir()), '/') . '/groupoffice/'; } $this->default_timezone = @date_default_timezone_get(); //suppress warning if using system tz $lc = localeconv(); $this->default_currency = empty($lc['currency_symbol']) ? '€' : $lc['currency_symbol']; $this->default_decimal_separator = empty($lc['decimal_point']) ? '.' : $lc['decimal_point']; $this->default_thousands_separator = $this->default_decimal_separator == '.' ? ',' : '.'; //$lc['thousands_sep']; } // // path to classes // $this->class_path = $this->root_path.$this->class_path.'/'; // // // path to themes // $this->theme_path = $this->root_path.$this->theme_path.'/'; // // // URL to themes // $this->theme_url = $this->host.$this->theme_url.'/'; // // // path to controls // $this->control_path = $this->root_path.$this->control_path.'/'; // // // url to controls // $this->control_url = $this->host.$this->control_url.'/'; // // // path to modules // $this->module_path = $this->root_path.$this->module_path.'/'; // // // url to user configuration apps // $this->configuration_url = $this->host.$this->configuration_url.'/'; if ($this->debug) { $this->debug_log = true; } // if($this->debug_log){// || $this->log_slow_requests) { // // list ($usec, $sec) = explode(" ", microtime()); // $this->loadstart = ((float) $usec + (float) $sec); // //// $dat = getrusage(); //// define('PHP_TUSAGE', microtime(true)); //// define('PHP_RUSAGE', $dat["ru_utime.tv_sec"]*1e6+$dat["ru_utime.tv_usec"]); // } // if(is_string($this->file_create_mode)) { // $this->file_create_mode=octdec($this->file_create_mode); // } // // if(is_string($this->folder_create_mode)) { // $this->folder_create_mode=octdec($this->folder_create_mode); // } if ($this->debug_log) { $this->log = true; } $this->set_full_url(); if (!$this->support_link && $this->isProVersion()) { $this->support_link = "https://www.group-office.com/support"; } /* * Check if the noreply_email variable is set in the config.php file. * If it is not set, then use noreply@ {webmaster_email domain name} * When the webmaster email is not set, then this will be noreply@example.com */ if (empty($this->noreply_email)) { $wmdomain = 'example.com'; if (!empty($this->webmaster_email)) { $extractedEmail = explode('@', $this->webmaster_email); if (isset($extractedEmail[1])) { $wmdomain = $extractedEmail[1]; } } $this->noreply_email = 'noreply@' . $wmdomain; } }
protected function afterDisplay(&$response, &$model, &$params) { $response['data']['name'] = $model->name; $response['data']['photo_url'] = $model->photoThumbURL; $response['data']['original_photo_url'] = $model->photoURL; $response['data']['addressbook_name'] = $model->addressbook->name; $company = $model->company(); if ($company) { $response['data']['company_name'] = $company->name; $response['data']['company_name2'] = $company->name2; $response['data']['company_formatted_address'] = nl2br($company->getFormattedAddress()); $response['data']['company_google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($company->address, $company->address_no, $company->city, $company->country); $response['data']['company_formatted_post_address'] = nl2br($company->getFormattedPostAddress()); $response['data']['company_google_maps_post_link'] = \GO\Base\Util\Common::googleMapsLink($company->post_address, $company->post_address_no, $company->post_city, $company->post_country); $response['data']['company_email'] = $company->email; $response['data']['company_phone'] = $company->phone; } else { $response['data']['company_name'] = ''; $response['data']['company_name2'] = ''; $response['data']['company_formatted_address'] = ''; $response['data']['company_google_maps_link'] = ''; $response['data']['company_formatted_post_address'] = ''; $response['data']['company_google_maps_post_link'] = ''; $response['data']['company_email'] = ''; $response['data']['company_phone'] = ''; } $response['data']['google_maps_link'] = \GO\Base\Util\Common::googleMapsLink($model->address, $model->address_no, $model->city, $model->country); $response['data']['formatted_address'] = nl2br($model->getFormattedAddress()); $response['data']['action_date'] = \GO\Base\Util\Date::get_timestamp($model->action_date, false); if (\GO::modules()->customfields && isset($response['data']['customfields']) && \GO\Customfields\Model\DisableCategories::isEnabled("GO\\Addressbook\\Model\\Contact", $model->addressbook_id)) { $ids = \GO\Customfields\Model\EnabledCategory::model()->getEnabledIds("GO\\Addressbook\\Model\\Contact", $model->addressbook_id); $enabled = array(); foreach ($response['data']['customfields'] as $cat) { if (in_array($cat['id'], $ids)) { $enabled[] = $cat; } } $response['data']['customfields'] = $enabled; } if (\GO::modules()->isInstalled('customfields')) { $response['data']['items_under_blocks'] = array(); $enabledBlocksStmt = \GO\Customfields\Model\EnabledBlock::getEnabledBlocks($model->addressbook_id, 'GO\\Addressbook\\Model\\Addressbook', $model->className()); foreach ($enabledBlocksStmt as $i => $enabledBlockModel) { $items = $enabledBlockModel->block->getItemNames($model->id, $model->name); if (!empty($items)) { $blockedItemsEl = array('id' => $i, 'block_name' => $enabledBlockModel->block->name, 'items' => $items); $blockedItemsEl['model_name'] = !empty($items[0]) ? $items[0]['model_name'] : ''; $modelNameArr = explode('_', $blockedItemsEl['model_name']); $blockedItemsEl['type'] = !empty($modelNameArr[3]) ? $modelNameArr[3] : ''; $response['data']['items_under_blocks'][] = $blockedItemsEl; } } } return parent::afterDisplay($response, $model, $params); }
foreach ($requiredArgs as $ra) { if (empty($args[$ra])) { throw new Exception($ra . " must be supplied.\n\nExample usage:\n\n" . $exampleUsage . "\n\n"); } } chdir(dirname(__FILE__)); require '../GO.php'; \GO::setIgnoreAclPermissions(); $stmt = \GO::getDbConnection()->query("SHOW TABLES"); if ($stmt->rowCount()) { throw new Exception("Automatic installation of Group-Office aborted because database is not empty"); } else { echo "Database connection established. Database is empty\n"; } \GO\Base\Util\SQL::executeSqlFile('install.sql'); $dbVersion = \GO\Base\Util\Common::countUpgradeQueries("updates.php"); \GO::config()->save_setting('version', $dbVersion); \GO::config()->save_setting('upgrade_mtime', \GO::config()->mtime); $adminGroup = new \GO\Base\Model\Group(); $adminGroup->id = 1; $adminGroup->name = \GO::t('group_admins'); $adminGroup->save(); $everyoneGroup = new \GO\Base\Model\Group(); $everyoneGroup->id = 2; $everyoneGroup->name = \GO::t('group_everyone'); $everyoneGroup->save(); $internalGroup = new \GO\Base\Model\Group(); $internalGroup->id = 3; $internalGroup->name = \GO::t('group_internal'); $internalGroup->save(); //\GO::config()->register_user_groups = \GO::t('group_internal');
/** * Get the full post address formatted according to the country standards. * * @return string */ public function getFormattedPostAddress() { return \GO\Base\Util\Common::formatAddress($this->post_country, $this->post_address, $this->post_address_no, $this->post_zip, $this->post_city, $this->post_state); }
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); } } }
protected function actionDecompress($params) { if (!\GO\Base\Util\Common::isWindows()) { putenv('LANG=en_US.UTF-8'); } $sources = json_decode($params['decompress_sources'], true); $workingFolder = \GO\Files\Model\Folder::model()->findByPk($params['working_folder_id']); $workingPath = \GO::config()->file_storage_path . $workingFolder->path; chdir($workingPath); while ($filePath = array_shift($sources)) { $file = new \GO\Base\Fs\File(\GO::config()->file_storage_path . $filePath); switch (strtolower($file->extension())) { case 'zip': $folder = \GO\Base\Fs\Folder::tempFolder(uniqid()); if (class_exists("\\ZipArchive")) { $zip = new \ZipArchive(); $zip->open($file->path()); $zip->extractTo($folder->path()); $this->_convertZipEncoding($folder); } else { chdir($folder->path()); $cmd = \GO::config()->cmd_unzip . ' -n ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } } $items = $folder->ls(); foreach ($items as $item) { $item->move(new \GO\Base\Fs\Folder($workingPath)); } $folder->delete(); break; case 'gz': case 'tgz': $cmd = \GO::config()->cmd_tar . ' zxf ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } break; case 'tar': $cmd = \GO::config()->cmd_tar . ' xf ' . escapeshellarg($file->path()); exec($cmd, $output, $ret); if ($ret != 0) { throw new \Exception("Could not decompress\n" . implode("\n", $output)); } break; } } $workingFolder->syncFilesystem(true); return array('success' => true); }
<?php /****************************************************************************/ /* */ /* YOU MAY WISH TO MODIFY OR REMOVE THE FOLLOWING LINES WHICH SET DEFAULTS */ /* */ /****************************************************************************/ $preferences = Swift_Preferences::getInstance(); // Sets the default charset so that setCharset() is not needed elsewhere $preferences->setCharset('utf-8'); if (\GO\Base\Util\Common::isWindows()) { $preferences->setTempDir(GO::config()->tmpdir)->setCacheType('array'); } else { $preferences->setTempDir(GO::config()->tmpdir)->setCacheType('disk'); } // this should only be done when Swiftmailer won't use the native QP content encoder // see mime_deps.php if (version_compare(phpversion(), '5.4.7', '<')) { $preferences->setQPDotEscape(\GO::config()->swift_qp_dot_escape); }
/** * Get the full address formatted according to the country standards. * * @return string */ public function getFormattedAddress() { return \GO\Base\Util\Common::formatAddress($this->country, $this->address, $this->address_no, $this->zip, $this->city, $this->state); }