/** * Sets up the Country settings page * @return string The page content */ static function settings() { global $_CORELANG; $objTemplateCountry = new \Cx\Core\Html\Sigma(\Env::get('cx')->getCodeBaseCorePath() . '/Country/View/Template/Generic'); $objTemplateCountry->loadTemplateFile('Overview.html'); // Adds messages self::storeSettings(); self::storeFromPost(); $uri = \Html::getRelativeUri(); // Let all links in this tab point here again \Html::replaceUriParameter($uri, 'active_tab=' . \Cx\Core\Setting\Controller\Setting::tab_index()); // Create a copy of the URI for the Paging, as this is passed by // reference and modified $uri_paging = $uri; //DBG::log("URI: $uri"); $objSorting = new Sorting($uri, array('id' => $_CORELANG['TXT_CORE_COUNTRY_ID'], 'active' => $_CORELANG['TXT_CORE_COUNTRY_ACTIVE'], 'ord' => $_CORELANG['TXT_CORE_COUNTRY_ORD'], 'name' => $_CORELANG['TXT_CORE_COUNTRY_NAME'], 'alpha2' => $_CORELANG['TXT_CORE_COUNTRY_ISO2'], 'alpha3' => $_CORELANG['TXT_CORE_COUNTRY_ISO3']), true, 'order_country'); \Cx\Core\Setting\Controller\Setting::init('core', 'country'); $limit = \Cx\Core\Setting\Controller\Setting::getValue('numof_countries_per_page_backend', 'core'); $count = 0; $arrCountries = self::getArray($count, null, $limit, \Paging::getPosition(), $objSorting->getOrder()); if ($arrCountries === false) { return \Message::error($_CORELANG['TXT_CORE_COUNTRY_ERROR_INITIALIZING']); } $objTemplateCountry->setGlobalVariable($_CORELANG + array('CORE_COUNTRY' => $_CORELANG['TXT_CORE_COUNTRY'] . ' ' . sprintf($_CORELANG['TXT_CORE_TOTAL'], $count), 'HEAD_SETTINGS_COUNTRY_ID' => $objSorting->getHeaderForField('id'), 'HEAD_SETTINGS_COUNTRY_ACTIVE' => $objSorting->getHeaderForField('active'), 'HEAD_SETTINGS_COUNTRY_ORD' => $objSorting->getHeaderForField('ord'), 'HEAD_SETTINGS_COUNTRY_NAME' => $objSorting->getHeaderForField('name'), 'HEAD_SETTINGS_COUNTRY_ISO2' => $objSorting->getHeaderForField('alpha2'), 'HEAD_SETTINGS_COUNTRY_ISO3' => $objSorting->getHeaderForField('alpha3'), 'CORE_SETTING_TAB_INDEX' => \Cx\Core\Setting\Controller\Setting::tab_index(), 'SETTINGS_COUNTRY_PAGING' => \Paging::get($uri_paging, '', $count, $limit, true))); // Note: Optionally disable the block 'settings_country_submit' // to disable storing changes $i = 0; foreach ($arrCountries as $country_id => $arrCountry) { $objTemplateCountry->setVariable(array('SETTINGS_COUNTRY_ROWCLASS' => ++$i % 2 + 1, 'SETTINGS_COUNTRY_ID' => $country_id, 'SETTINGS_COUNTRY_ACTIVE' => $arrCountry['active'] ? \Html::ATTRIBUTE_CHECKED : '', 'SETTINGS_COUNTRY_ORD' => $arrCountry['ord'], 'SETTINGS_COUNTRY_NAME' => $arrCountry['name'], 'SETTINGS_COUNTRY_ISO2' => $arrCountry['alpha2'], 'SETTINGS_COUNTRY_ISO3' => $arrCountry['alpha3'], 'SETTINGS_FUNCTIONS' => \Html::getBackendFunctions(array('delete' => 'delete_country_id=' . $country_id), array('delete' => $_CORELANG['TXT_CORE_COUNTRY_CONFIRM_DELETE'] . "\\n" . $_CORELANG['TXT_ACTION_IS_IRREVERSIBLE'])))); $objTemplateCountry->parse('settings_country_row'); } $objTemplateSetting = null; \Cx\Core\Setting\Controller\Setting::show_external($objTemplateSetting, $_CORELANG['TXT_CORE_COUNTRY_EDIT'], $objTemplateCountry->get()); \Cx\Core\Setting\Controller\Setting::show($objTemplateSetting, $uri, $_CORELANG['TXT_CORE_COUNTRY_SETTINGS'], $_CORELANG['TXT_CORE_COUNTRY_SETTINGS']); return $objTemplateSetting->get(); }
/** * Show the selected mail template for editing * * Stores the MailTemplate if the 'bsubmit' parameter has been posted. * If the $key argument is empty, tries to pick the value from * $_REQUEST['key']. * @param mixed $section The section of the mail template * to be edited * @param string $key The optional key of the mail template * to be edited * @param string $act The action of the mail template * @return \Cx\Core\Html\Sigma The template object */ static function edit($section, $key = '', $useDefaultActs = true, $act = 'mailtemplate_overview') { global $_CORELANG; // If the $key parameter is empty, check the request if (empty($key)) { if (isset($_REQUEST['key'])) { $key = $_REQUEST['key']; } } // Try to load an existing template for any non-empty key $arrTemplate = null; if ($key != '') { $arrTemplate = self::get($section, $key, FRONTEND_LANG_ID); } // If there is none, get an empty template $new = false; if (!$arrTemplate) { $new = true; $arrTemplate = self::getEmpty($key); } // Copy the template? if (isset($_REQUEST['copy'])) { $arrTemplate['key'] = ''; $new = true; } $objTemplate = new \Cx\Core\Html\Sigma(\Env::get('cx')->getCodeBaseCorePath() . '/MailTemplate/View/Template/Generic'); $objTemplate->setErrorHandling(PEAR_ERROR_DIE); \Cx\Core\Csrf\Controller\Csrf::add_placeholder($objTemplate); if (!$objTemplate->loadTemplateFile('Edit.html')) { die("Failed to load template Edit.html"); } $uri = \Html::getRelativeUri_entities(); \Html::stripUriParam($uri, 'key'); $uriAppendix = ''; if ($useDefaultActs) { \Html::stripUriParam($uri, 'act'); $uriAppendix = '&act=' . $act; } $tab_index = \Cx\Core\Setting\Controller\Setting::tab_index(); \Html::replaceUriParameter($uri, 'active_tab=' . $tab_index); \Html::replaceUriParameter($uri, 'userFrontendLangId=' . FRONTEND_LANG_ID); $objTemplate->setGlobalVariable($_CORELANG + array('CORE_MAILTEMPLATE_EDIT_TITLE' => $new ? $_CORELANG['TXT_CORE_MAILTEMPLATE_ADD'] : $_CORELANG['TXT_CORE_MAILTEMPLATE_EDIT'], 'CORE_MAILTEMPLATE_CMD' => isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : '', 'CORE_MAILTEMPLATE_ACTIVE_TAB' => $tab_index, 'URI_BASE' => $uri . $uriAppendix)); $i = 0; foreach ($arrTemplate as $name => $value) { // See if there is a posted parameter value if (isset($_POST[$name])) { $value = $_POST[$name]; } // IDs are set up as hidden fields. // They *MUST NOT* be edited! if (preg_match('/(?:_id)$/', $name)) { // For copies, IDs *MUST NOT* be reused! if (isset($_REQUEST['copy'])) { $value = 0; } $objTemplate->setVariable('MAILTEMPLATE_HIDDEN', \Html::getHidden($name, $value)); $objTemplate->parse('core_mailtemplate_hidden'); continue; } // Regular inputs of various kinds $input = ''; $attribute = ''; // $arrMimetype = ''; switch ($name) { case 'available': continue 2; /* TODO: WARNING: FCKEditor v2.x f***s up the blocks in the mail template! Use plain text areas instead. See below. */ /* TODO: WARNING: FCKEditor v2.x f***s up the blocks in the mail template! Use plain text areas instead. See below. */ case 'message_html': // Show WYSIWYG only if HTML is enabled if (empty($arrTemplate['html'])) { continue 2; } $objTemplate->setVariable(array('MAILTEMPLATE_ROWCLASS' => ++$i % 2 + 1, 'MAILTEMPLATE_SPECIAL' => $_CORELANG['TXT_CORE_MAILTEMPLATE_' . strtoupper($name)])); $objTemplate->touchBlock('core_mailtemplate_special'); $objTemplate->parse('core_mailtemplate_special'); $objTemplate->setVariable(array('MAILTEMPLATE_ROWCLASS' => ++$i % 2 + 1, 'MAILTEMPLATE_SPECIAL' => new \Cx\Core\Wysiwyg\Wysiwyg($name, $value, 'fullpage'))); $objTemplate->touchBlock('core_mailtemplate_special'); $objTemplate->parse('core_mailtemplate_special'); continue 2; //$objTemplate->replaceBlock('core_mailtemplate_special', '', true); // case 'message_html': //$objTemplate->replaceBlock('core_mailtemplate_special', '', true); // case 'message_html': case 'message': $input = \Html::getTextarea($name, $value, '', 10, 'style="width: 600px;"'); break; case 'protected': $attribute = \Html::ATTRIBUTE_DISABLED; $input = \Html::getCheckbox($name, 1, '', $value, '', $attribute); break; case 'html': $input = \Html::getCheckbox($name, 1, '', $value, '', $attribute) . ' ' . $_CORELANG['TXT_CORE_MAILTEMPLATE_STORE_TO_SWITCH_EDITOR']; break; case 'inline': case 'attachments': continue 2; // TODO: These do not work properly yet /* // These are identical except for the MIME types case 'inline': $arrMimetype = \Filetype::getImageMimetypes(); case 'attachments': $arrAttachments = self::attachmentsToArray($arrTemplate[$name]); // Show at least one empty attachment/inline row if (empty($arrAttachments)) $arrAttachments = array(array('path' => '', ), ); $i = 0; foreach ($arrAttachments as $arrAttachment) { $div_id = $name.'-'.(++$i); $element_name = $name.'['.$i.']'; $input .= '<div id="'.$div_id.'">'. \Html::getHidden( $element_name.'[old]', $arrAttachment['path'], $name.'-hidden-'.$i). $arrAttachment['path'].' '. $_CORELANG['TXT_CORE_MAILTEMPLATE_ATTACHMENT_UPLOAD']. \Html::getInputFileupload( $element_name.'[new]', $name.'-file-'.$i, \Filetype::MAXIMUM_UPLOAD_FILE_SIZE, $arrMimetype). // Links for adding/removing inputs \Html::getRemoveAddLinks($div_id). '</div>'; } //echo("$name => ".htmlentities($input)."<hr />"); break; */ // Once the key is defined, it cannot be changed. // To fix a wrong key, copy the old template and enter a new key, // then delete the old one. // TODO: These do not work properly yet /* // These are identical except for the MIME types case 'inline': $arrMimetype = \Filetype::getImageMimetypes(); case 'attachments': $arrAttachments = self::attachmentsToArray($arrTemplate[$name]); // Show at least one empty attachment/inline row if (empty($arrAttachments)) $arrAttachments = array(array('path' => '', ), ); $i = 0; foreach ($arrAttachments as $arrAttachment) { $div_id = $name.'-'.(++$i); $element_name = $name.'['.$i.']'; $input .= '<div id="'.$div_id.'">'. \Html::getHidden( $element_name.'[old]', $arrAttachment['path'], $name.'-hidden-'.$i). $arrAttachment['path'].' '. $_CORELANG['TXT_CORE_MAILTEMPLATE_ATTACHMENT_UPLOAD']. \Html::getInputFileupload( $element_name.'[new]', $name.'-file-'.$i, \Filetype::MAXIMUM_UPLOAD_FILE_SIZE, $arrMimetype). // Links for adding/removing inputs \Html::getRemoveAddLinks($div_id). '</div>'; } //echo("$name => ".htmlentities($input)."<hr />"); break; */ // Once the key is defined, it cannot be changed. // To fix a wrong key, copy the old template and enter a new key, // then delete the old one. case 'key': $input = $arrTemplate['key'] ? $value . \Html::getHidden($name, $value) : \Html::getInputText($name, $value, '', 'style="width: 300px;"'); //echo("Key /$key/ -> attr $attribute<br />"); break; default: $input = \Html::getInputText($name, $value, '', 'style="width: 300px;"'); } $name_upper = strtoupper($name); $objTemplate->setVariable(array('MAILTEMPLATE_ROWCLASS' => ++$i % 2 + 1, 'MAILTEMPLATE_NAME' => $_CORELANG['TXT_CORE_MAILTEMPLATE_' . $name_upper], 'MAILTEMPLATE_VALUE' => $input)); // Add note with helpful hints, if available if (isset($_CORELANG['TXT_CORE_MAILTEMPLATE_NOTE_' . $name_upper])) { $objTemplate->setVariable('MAILTEMPLATE_VALUE_NOTE', $_CORELANG['TXT_CORE_MAILTEMPLATE_NOTE_' . $name_upper]); } $objTemplate->parse('core_mailtemplate_row'); } // Send the (possibly edited and now stored) mail, if requested if (empty($_POST['to_test'])) { return $objTemplate; } if (empty($key)) { \Message::error($_CORELANG['TXT_CORE_MAILTEMPLATE_ERROR_NO_KEY']); return $objTemplate; } $to_test = contrexx_input2raw($_POST['to_test']); $objTemplate->setVariable('CORE_MAILTEMPLATE_TO_TEST', $to_test); self::sendTestMail($section, $key, $to_test); return $objTemplate; }