function setMotives()
 {
     global $objDatabase, $_ARRAYLANG;
     \JS::activate('shadowbox');
     $this->_objTpl->loadTemplateFile('module_ecard_overview.html', true, true);
     $this->_pageTitle = $_ARRAYLANG['TXT_MOTIVE_SELECTION'];
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setCallback('mbCallback');
     $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => 'filebrowser', 'id' => 'mediabrowser_button', 'style' => 'display: none;'));
     /* Update progress */
     if (!empty($_POST['saveMotives'])) {
         $i = 0;
         $motiveInputArray = $_POST['motiveInputArray'];
         while ($i < 9) {
             $filepath = $motiveInputArray[$i];
             $filename = basename($filepath);
             $query = "\n                    UPDATE " . DBPREFIX . "module_ecard_settings\n                       SET setting_value='" . contrexx_addslashes($filename) . "'\n                     WHERE setting_name='motive_{$i}'";
             $objResult = $objDatabase->Execute($query);
             /* Create optimized picture for e-card dispatch */
             if ($filepath != '' && file_exists(\Env::get('cx')->getWebsitePath() . $filepath)) {
                 $this->resizeMotive(2, \Env::get('cx')->getWebsitePath() . $filepath, ASCMS_ECARD_OPTIMIZED_PATH . '/');
                 $this->resizeMotive(1, \Env::get('cx')->getWebsitePath() . $filepath, ASCMS_ECARD_THUMBNAIL_PATH . '/');
             }
             ++$i;
         }
         $this->_objTpl->setVariable(array('CONTENT_OK_MESSAGE' => $this->strOkMessage = $_ARRAYLANG['TXT_DATA_SAVED']));
     }
     $this->_objTpl->setGlobalVariable(array('TXT_SAVE' => $_ARRAYLANG['TXT_SAVE'], 'TXT_DELETE_MOTIVE' => $_ARRAYLANG['TXT_DELETE_MOTIVE'], 'TXT_PICTURE' => $_ARRAYLANG['TXT_PICTURE'], 'TXT_PATH' => $_ARRAYLANG['TXT_PATH'], 'TXT_BROWSE' => $_ARRAYLANG['TXT_BROWSE'], 'TXT_CHOOSE' => $_ARRAYLANG['TXT_CHOOSE'], 'TXT_DELETE' => $_ARRAYLANG['TXT_DELETE'], 'TXT_ECARD_IMAGES' => $_ARRAYLANG['TXT_ECARD_IMAGES'], 'MEDIABROWSER_BUTTON' => $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE'])));
     /* Display progress */
     $query = "\n            SELECT `setting_value`\n              FROM " . DBPREFIX . "module_ecard_settings\n             WHERE setting_name LIKE 'motive_%'\n             ORDER BY setting_name ASC";
     $objResult = $objDatabase->Execute($query);
     $i = 0;
     /* Create thumbnails */
     while (!$objResult->EOF) {
         $motiveFilename = $objResult->fields['setting_value'];
         $thumbnail = ASCMS_ECARD_THUMBNAIL_WEB_PATH . '/' . "no_picture.gif";
         $sourcePath = '';
         if ($motiveFilename != '') {
             $sourcePath = ASCMS_ECARD_OPTIMIZED_WEB_PATH . '/' . $motiveFilename;
             $thumbnail = ASCMS_ECARD_THUMBNAIL_WEB_PATH . '/' . $motiveFilename;
         }
         /* Initialize DATA placeholder */
         $this->_objTpl->setVariable(array('MOTIVE_PATH' => $sourcePath, 'MOTIVE_THUMB_PATH' => $thumbnail, 'MOTIVE_ID' => $i++));
         $this->_objTpl->parse('motiveBlock');
         $objResult->MoveNext();
     }
     $this->_objTpl->replaceBlock('motiveBlock', '', true);
 }
    /**
     * This function returns the DataElement
     *
     * @param string $name name of the DataElement
     * @param string $type type of the DataElement
     * @param int $length length of the DataElement
     * @param mixed $value value of the DataElement
     * @param array $options options for the DataElement
     * @param int $entityId id of the DataElement
     * @return \Cx\Core\Html\Model\Entity\DataElement
     */
    public function getDataElement($name, $type, $length, $value, &$options, $entityId)
    {
        global $_ARRAYLANG, $_CORELANG;
        if (isset($options['formfield'])) {
            $formFieldGenerator = $options['formfield'];
            $formField = '';
            /* We use json to do the callback. The 'else if' is for backwards compatibility so you can declare
             * the function directly without using json. This is not recommended and not working over session */
            if (is_array($formFieldGenerator) && isset($formFieldGenerator['adapter']) && isset($formFieldGenerator['method'])) {
                $json = new \Cx\Core\Json\JsonData();
                $jsonResult = $json->data($formFieldGenerator['adapter'], $formFieldGenerator['method'], array('name' => $name, 'type' => $type, 'length' => $length, 'value' => $value, 'options' => $options));
                if ($jsonResult['status'] == 'success') {
                    $formField = $jsonResult["data"];
                }
            } else {
                if (is_callable($formFieldGenerator)) {
                    $formField = $formFieldGenerator($name, $type, $length, $value, $options);
                }
            }
            if (is_a($formField, 'Cx\\Core\\Html\\Model\\Entity\\HtmlElement')) {
                return $formField;
            } else {
                $value = $formField;
            }
        }
        if (isset($options['showDetail']) && $options['showDetail'] === false) {
            return '';
        }
        switch ($type) {
            case 'bool':
            case 'boolean':
                // yes/no checkboxes
                $fieldset = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $inputYes = new \Cx\Core\Html\Model\Entity\DataElement($name, 'yes');
                $inputYes->setAttribute('type', 'radio');
                $inputYes->setAttribute('value', '1');
                $inputYes->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_yes');
                if (isset($options['attributes'])) {
                    $inputYes->setAttributes($options['attributes']);
                }
                $fieldset->addChild($inputYes);
                $labelYes = new \Cx\Core\Html\Model\Entity\HtmlElement('label');
                $labelYes->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_yes');
                $labelYes->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_YES']));
                $fieldset->addChild($labelYes);
                $inputNo = new \Cx\Core\Html\Model\Entity\DataElement($name, 'no');
                $inputNo->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_no');
                $inputNo->setAttribute('type', 'radio');
                $inputNo->setAttribute('value', '0');
                if (isset($options['attributes'])) {
                    $inputNo->setAttributes($options['attributes']);
                }
                $fieldset->addChild($inputNo);
                $labelNo = new \Cx\Core\Html\Model\Entity\HtmlElement('label');
                $labelNo->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_no');
                $labelNo->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_NO']));
                $fieldset->addChild($labelNo);
                if ($value) {
                    $inputYes->setAttribute('checked');
                } else {
                    $inputNo->setAttribute('checked');
                }
                return $fieldset;
                break;
            case 'int':
            case 'integer':
                // input field with type number
                $inputNumber = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT, new \Cx\Core\Validate\Model\Entity\RegexValidator('/-?[0-9]*/'));
                if (isset($options['attributes'])) {
                    $inputNumber->setAttributes($options['attributes']);
                }
                $inputNumber->setAttribute('type', 'number');
                return $inputNumber;
                break;
            case 'Cx\\Model\\Base\\EntityBase':
                $associatedClass = get_class($value);
                \JS::registerJS('core/Html/View/Script/Backend.js');
                \ContrexxJavascript::getInstance()->setVariable('Form/Error', $_ARRAYLANG['TXT_CORE_HTML_FORM_VALIDATION_ERROR'], 'core/Html/lang');
                if (\Env::get('em')->getClassMetadata($this->entityClass)->isSingleValuedAssociation($name)) {
                    // this case is used to create a select field for 1 to 1 associations
                    $entities = \Env::get('em')->getRepository($associatedClass)->findAll();
                    $foreignMetaData = \Env::get('em')->getClassMetadata($associatedClass);
                    $primaryKeyName = $foreignMetaData->getSingleIdentifierFieldName();
                    $selected = $foreignMetaData->getFieldValue($value, $primaryKeyName);
                    $arrEntities = array();
                    $closeMetaData = \Env::get('em')->getClassMetadata($this->entityClass);
                    $assocMapping = $closeMetaData->getAssociationMapping($name);
                    $validator = null;
                    if (!isset($assocMapping['joinColumns'][0]['nullable']) || $assocMapping['joinColumns'][0]['nullable']) {
                        $arrEntities['NULL'] = $_ARRAYLANG['TXT_CORE_NONE'];
                    } else {
                        $validator = new \Cx\Core\Validate\Model\Entity\RegexValidator('/^(?!null$|$)/');
                    }
                    foreach ($entities as $entity) {
                        $arrEntities[\Env::get('em')->getClassMetadata($associatedClass)->getFieldValue($entity, $primaryKeyName)] = $entity;
                    }
                    $select = new \Cx\Core\Html\Model\Entity\DataElement($name, \Html::getOptions($arrEntities, $selected), \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT, $validator);
                    if (isset($options['attributes'])) {
                        $select->setAttributes($options['attributes']);
                    }
                    return $select;
                } else {
                    // this case is used to list all existing values and show an add button for 1 to many associations
                    $closeMetaData = \Env::get('em')->getClassMetadata($this->entityClass);
                    $assocMapping = $closeMetaData->getAssociationMapping($name);
                    $mainDiv = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                    $mainDiv->setAttribute('class', 'entityList');
                    $addButton = new \Cx\Core\Html\Model\Entity\HtmlElement('input');
                    $addButton->setAttribute('type', 'button');
                    $addButton->setClass(array('form-control', 'add_' . $this->createCssClassNameFromEntity($associatedClass), 'mappedAssocciationButton'));
                    $addButton->setAttribute('value', $_CORELANG['TXT_ADD']);
                    $addButton->setAttribute('data-params', 'entityClass:' . $associatedClass . ';' . 'mappedBy:' . $assocMapping['mappedBy'] . ';' . 'cssName:' . $this->createCssClassNameFromEntity($associatedClass) . ';' . 'sessionKey:' . $this->entityClass);
                    if (!isset($_SESSION['vgOptions'])) {
                        $_SESSION['vgOptions'] = array();
                    }
                    $_SESSION['vgOptions'][$this->entityClass] = $this->componentOptions;
                    if ($entityId != 0) {
                        // if we edit the main form, we also want to show the existing associated values we already have
                        $existingValues = $this->getIdentifyingDisplayValue($assocMapping, $associatedClass, $entityId);
                    }
                    if (!empty($existingValues)) {
                        foreach ($existingValues as $existingValue) {
                            $mainDiv->addChild($existingValue);
                        }
                    }
                    $mainDiv->addChild($addButton);
                    // if standard tooltip is not disabled, we load the one to n association text
                    if (!isset($options['showstanardtooltip']) || $options['showstanardtooltip']) {
                        if (!empty($options['tooltip'])) {
                            $options['tooltip'] = $options['tooltip'] . '<br /><br /> ' . $_ARRAYLANG['TXT_CORE_RECORD_ONE_TO_N_ASSOCIATION'];
                        } else {
                            $options['tooltip'] = $_ARRAYLANG['TXT_CORE_RECORD_ONE_TO_N_ASSOCIATION'];
                        }
                    }
                    $cxjs = \ContrexxJavascript::getInstance();
                    $cxjs->setVariable('TXT_CANCEL', $_CORELANG['TXT_CANCEL'], 'Html/lang');
                    $cxjs->setVariable('TXT_SUBMIT', $_CORELANG['TXT_SUBMIT'], 'Html/lang');
                    $cxjs->setVariable('TXT_EDIT', $_CORELANG['TXT_EDIT'], 'Html/lang');
                    $cxjs->setVariable('TXT_DELETE', $_CORELANG['TXT_DELETE'], 'Html/lang');
                    return $mainDiv;
                }
                break;
            case 'Country':
                // this is for customizing only:
                $data = \Cx\Core\Country\Controller\Country::getNameById($value);
                if (empty($data)) {
                    $value = 204;
                }
                $options = \Cx\Core\Country\Controller\Country::getMenuoptions($value);
                $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $options, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
                if (isset($options['attributes'])) {
                    $select->setAttributes($options['attributes']);
                }
                return $select;
                break;
            case 'DateTime':
            case 'datetime':
            case 'date':
                // input field with type text and class datepicker
                if ($value instanceof \DateTime) {
                    $value = $value->format(ASCMS_DATE_FORMAT);
                }
                if (is_null($value)) {
                    $value = '';
                }
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'text');
                $input->setAttribute('class', 'datepicker');
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                \DateTimeTools::addDatepickerJs();
                \JS::registerCode('
                        cx.jQuery(function() {
                          cx.jQuery(".datepicker").datetimepicker();
                        });
                        ');
                return $input;
                break;
            case 'multiselect':
            case 'select':
                $values = array();
                if (isset($options['validValues'])) {
                    if (is_array($options['validValues'])) {
                        $values = $options['validValues'];
                    } else {
                        $values = explode(',', $options['validValues']);
                        $values = array_combine($values, $values);
                    }
                }
                if ($type == 'multiselect') {
                    $value = explode(',', $value);
                    $value = array_combine($value, $value);
                }
                $selectOptions = \Html::getOptions($values, $value);
                $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $selectOptions, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
                if ($type == 'multiselect') {
                    $select->setAttribute('multiple');
                }
                if (isset($options['attributes'])) {
                    $select->setAttributes($options['attributes']);
                }
                return $select;
                break;
            case 'slider':
                // this code should not be here
                // create sorrounding div
                $element = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                // create div for slider
                $slider = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $slider->setAttribute('class', 'slider');
                $element->addChild($slider);
                // create hidden input for slider value
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value + 0, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT);
                $input->setAttribute('type', 'hidden');
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                $element->addChild($input);
                // add javascript to update input value
                $min = 0;
                $max = 10;
                if (isset($options['validValues'])) {
                    $values = explode(',', $options['validValues']);
                    $min = $values[0];
                    if (isset($values[1])) {
                        $max = $values[1];
                    }
                }
                if (!isset($value)) {
                    $value = 0;
                }
                $script = new \Cx\Core\Html\Model\Entity\HtmlElement('script');
                $script->addChild(new \Cx\Core\Html\Model\Entity\TextElement('
                    cx.jQuery("#form-' . $this->formId . '-' . $name . ' .slider").slider({
                        value: ' . ($value + 0) . ',
                        min: ' . ($min + 0) . ',
                        max: ' . ($max + 0) . ',
                        slide: function( event, ui ) {
                            cx.jQuery("input[name=' . $name . ']").val(ui.value);
                            cx.jQuery("input[name=' . $name . ']").change();
                        }
                    });
                '));
                $element->addChild($script);
                return $element;
                break;
            case 'checkboxes':
                $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_CHECKBOX;
            case 'radio':
                $values = array();
                if (isset($options['validValues'])) {
                    $values = explode(',', $options['validValues']);
                    $values = array_combine($values, $values);
                }
                if (!isset($dataElementGroupType)) {
                    $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_RADIO;
                }
                $radio = new \Cx\Core\Html\Model\Entity\DataElementGroup($name, $values, $value, $dataElementGroupType);
                if (isset($options['attributes'])) {
                    $radio->setAttributes($options['attributes']);
                }
                return $radio;
                break;
            case 'text':
                // textarea
                $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea');
                $textarea->setAttribute('name', $name);
                if (isset($options['readonly']) && $options['readonly']) {
                    $textarea->setAttribute('disabled');
                }
                $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value));
                if (isset($options['attributes'])) {
                    $textarea->setAttributes($options['attributes']);
                }
                return $textarea;
                break;
            case 'phone':
                // input field with type phone
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'phone');
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                return $input;
                break;
            case 'mail':
                // input field with type mail
                $emailValidator = new \Cx\Core\Validate\Model\Entity\EmailValidator();
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, 'input', $emailValidator);
                $input->setAttribute('onkeyup', $emailValidator->getJavaScriptCode());
                $input->setAttribute('type', 'mail');
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                return $input;
                break;
            case 'uploader':
                \JS::registerCode('
                    function javascript_callback_function(data) {
                        if(data.type=="file") {
                                cx.jQuery("#' . $name . '").val(data.data[0].datainfo.filepath);
                        }
                    }

                ');
                $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
                $mediaBrowser->setOptions(array('type' => 'button'));
                $mediaBrowser->setCallback('javascript_callback_function');
                $mediaBrowser->setOptions(array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList'));
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'text');
                $input->setAttribute('id', $name);
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $div->addChild($input);
                $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mb = $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE'])));
                return $div;
                break;
            case 'image':
                \JS::registerCode('
                    function javascript_callback_function(data) {
                        if ( data.data[0].datainfo.extension=="Jpg"
                            || data.data[0].datainfo.extension=="Gif"
                            || data.data[0].datainfo.extension=="Png"
                        ) {
                            cx.jQuery("#' . $name . '").attr(\'value\', data.data[0].datainfo.filepath);
                            cx.jQuery("#' . $name . '").prevAll(\'.deletePreviewImage\').first().css(\'display\', \'inline-block\');
                            cx.jQuery("#' . $name . '").prevAll(\'.previewImage\').first().attr(\'src\', data.data[0].datainfo.filepath);
                        }
                    }

                    jQuery(document).ready(function(){
                        jQuery(\'.deletePreviewImage\').click(function(){
                            cx.jQuery("#' . $name . '").attr(\'value\', \'\');
                            cx.jQuery(this).prev(\'img\').attr(\'src\', \'/images/Downloads/no_picture.gif\');
                            cx.jQuery(this).css(\'display\', \'none\');
                            cx.jQuery(this).nextAll(\'input\').first().attr(\'value\', \'\');
                        });
                    });

                ');
                $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
                $mediaBrowser->setOptions(array('type' => 'button'));
                $mediaBrowser->setCallback('javascript_callback_function');
                $defaultOptions = array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList');
                $mediaBrowser->setOptions(is_array($options['options']) ? array_merge($defaultOptions, $options['options']) : $defaultOptions);
                // create hidden input to save image
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'hidden');
                $input->setAttribute('id', $name);
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                if (isset($value) && in_array(pathinfo($value, PATHINFO_EXTENSION), array('gif', 'jpg', 'png')) || $name == 'imagePath') {
                    // this image is meant to be a preview of the selected image
                    $previewImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img');
                    $previewImage->setAttribute('class', 'previewImage');
                    $previewImage->setAttribute('src', $value != '' ? $value : '/images/Downloads/no_picture.gif');
                    // this image is uesd as delete function for the selected image over javascript
                    $deleteImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img');
                    $deleteImage->setAttribute('class', 'deletePreviewImage');
                    $deleteImage->setAttribute('src', '/core/Core/View/Media/icons/delete.gif');
                    $div->addChild($previewImage);
                    $div->addChild($deleteImage);
                    $div->addChild(new \Cx\Core\Html\Model\Entity\HtmlElement('br'));
                }
                $div->addChild($input);
                $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE'])));
                return $div;
                break;
            case 'sourcecode':
                //set mode
                $mode = 'html';
                if (isset($options['options']['mode'])) {
                    switch ($options['options']['mode']) {
                        case 'js':
                            $mode = 'javascript';
                            break;
                        case 'yml':
                        case 'yaml':
                            $mode = 'yaml';
                            break;
                    }
                }
                //define textarea
                $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea');
                $textarea->setAttribute('name', $name);
                $textarea->setAttribute('id', $name);
                $textarea->setAttribute('style', 'display:none;');
                $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value));
                //define pre
                $pre = new \Cx\Core\Html\Model\Entity\HtmlElement('pre');
                $pre->setAttribute('id', 'editor-' . $name);
                $pre->addChild(new \Cx\Core\Html\Model\Entity\TextElement(contrexx_raw2xhtml($value)));
                //set readonly if necessary
                $readonly = '';
                if (isset($options['readonly']) && $options['readonly']) {
                    $readonly = 'editor.setReadOnly(true);';
                    $textarea->setAttribute('disabled');
                }
                //create div and add all stuff
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                //     required for the Ace editor to work. Otherwise
                //     it won't be visible as the DIV does have a width of 0px.
                $div->setAttribute('style', 'display:block;');
                $div->addChild($textarea);
                $div->addChild($pre);
                //register js
                $jsCode = <<<CODE
var editor;
\$J(function(){
if (\$J("#editor-{$name}").length) {
    editor = ace.edit("editor-{$name}");
    editor.getSession().setMode("ace/mode/{$mode}");
    editor.setShowPrintMargin(false);
    editor.focus();
    editor.gotoLine(1);
    {$readonly}
}

\$J('form').submit(function(){
    \$J('#{$name}').val(editor.getSession().getValue());
});

});
CODE;
                \JS::activate('ace');
                \JS::registerCode($jsCode);
                return $div;
                break;
            case 'string':
            case 'hidden':
            default:
                // convert NULL to empty string
                if (is_null($value)) {
                    $value = '';
                }
                // input field with type text
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                if (isset($options['validValues'])) {
                    $input->setValidator(new \Cx\Core\Validate\Model\Entity\RegexValidator('/^' . $options['validValues'] . '$/'));
                }
                if ($type == 'hidden') {
                    $input->setAttribute('type', 'hidden');
                } else {
                    $input->setAttribute('type', 'text');
                    $input->setClass('form-control');
                }
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                return $input;
                break;
        }
    }
 /**
  * Get mediabrowser button
  * 
  * @param string $buttonValue Value of the button
  * @param string $options     Input button options 
  * @param string $callback    Media browser callback function
  * 
  * @return string html element of browse button
  */
 public function getMediaBrowserButton($buttonValue, $options = array(), $callback = '')
 {
     // Mediabrowser
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions($options);
     if ($callback) {
         $mediaBrowser->setCallback($callback);
     }
     return $mediaBrowser->getXHtml($buttonValue);
 }
 function _editMail($copy = false)
 {
     global $objDatabase, $_ARRAYLANG, $_CONFIG;
     $mailId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
     $arrAttachment = array();
     $attachmentNr = 0;
     $arrAssociatedLists = array();
     $arrAssociatedGroups = array();
     $status = true;
     $mailSubject = isset($_POST['newsletter_mail_subject']) ? contrexx_stripslashes($_POST['newsletter_mail_subject']) : '';
     $objMailSentDate = $objDatabase->Execute("SELECT `date_sent` FROM " . DBPREFIX . "module_newsletter WHERE id=" . $mailId);
     $mailSendDate = $objMailSentDate ? $objMailSentDate->fields['date_sent'] : 0;
     $arrTemplates = $this->_getTemplates();
     $mailTemplate = isset($_POST['newsletter_mail_template']) ? intval($_POST['newsletter_mail_template']) : key($arrTemplates);
     if (isset($_POST['newsletter_import_template'])) {
         $importTemplate = intval($_POST['newsletter_import_template']);
     }
     if (isset($_POST['newsletter_mail_html_content'])) {
         $mailHtmlContent = $this->_getBodyContent(contrexx_input2raw($_POST['newsletter_mail_html_content']));
     } elseif (isset($_POST['selected'])) {
         $selectedNews = contrexx_input2db($_POST['selected']);
         $HTML_TemplateSource_Import = $this->_getBodyContent($this->_prepareNewsPreview($this->GetTemplateSource($importTemplate, 'html')));
         $_REQUEST['standalone'] = true;
         $this->_impTpl = new \Cx\Core\Html\Sigma();
         \Cx\Core\Csrf\Controller\Csrf::add_placeholder($this->_impTpl);
         $this->_impTpl->setTemplate($HTML_TemplateSource_Import);
         $query = '  SELECT  n.id                AS newsid,
                             n.userid            AS newsuid,
                             n.date              AS newsdate,
                             n.teaser_image_path,
                             n.teaser_image_thumbnail_path,
                             n.redirect,
                             n.publisher,
                             n.publisher_id,
                             n.author,
                             n.author_id,
                             n.catid,
                             nl.title            AS newstitle,
                             nl.text             AS newscontent,
                             nl.teaser_text,
                             nc.name             AS name
                 FROM        ' . DBPREFIX . 'module_news AS n
                 INNER JOIN  ' . DBPREFIX . 'module_news_locale AS nl ON nl.news_id = n.id
                 INNER JOIN  ' . DBPREFIX . 'module_news_categories_locale AS nc ON nc.category_id=n.catid
                 WHERE       status = 1
                             AND nl.is_active=1
                             AND nl.lang_id=' . FRONTEND_LANG_ID . '
                             AND nc.lang_id=' . FRONTEND_LANG_ID . '
                             AND n.id IN (' . $selectedNews . ')
                 ORDER BY nc.name ASC, n.date DESC';
         $objFWUser = \FWUser::getFWUserObject();
         $objNews = $objDatabase->Execute($query);
         $current_category = '';
         if ($this->_impTpl->blockExists('news_list')) {
             if ($objNews !== false) {
                 while (!$objNews->EOF) {
                     $this->_impTpl->setVariable(array('NEWS_CATEGORY_NAME' => $objNews->fields['name']));
                     if ($current_category == $objNews->fields['catid']) {
                         $this->_impTpl->hideBlock("news_category");
                     }
                     $current_category = $objNews->fields['catid'];
                     $newsid = $objNews->fields['newsid'];
                     $newstitle = $objNews->fields['newstitle'];
                     $newsUrl = empty($objNews->fields['redirect']) ? empty($objNews->fields['newscontent']) ? '' : 'index.php?section=News&cmd=details&newsid=' . $newsid : $objNews->fields['redirect'];
                     $newstext = ltrim(strip_tags($objNews->fields['newscontent']));
                     $newsteasertext = ltrim(strip_tags($objNews->fields['teaser_text']));
                     $newslink = "[[" . \Cx\Core\ContentManager\Model\Entity\Page::PLACEHOLDER_PREFIX . "NEWS_DETAILS]]?newsid=" . $newsid;
                     if ($objNews->fields['newsuid'] && ($objUser = $objFWUser->objUser->getUser($objNews->fields['newsuid']))) {
                         $author = htmlentities($objUser->getUsername(), ENT_QUOTES, CONTREXX_CHARSET);
                     } else {
                         $author = $_ARRAYLANG['TXT_ANONYMOUS'];
                     }
                     list($image, $htmlLinkImage, $imageSource) = \Cx\Core_Modules\News\Controller\NewsLibrary::parseImageThumbnail($objNews->fields['teaser_image_path'], $objNews->fields['teaser_image_thumbnail_path'], $newstitle, $newsUrl);
                     $this->_impTpl->setVariable(array('NEWS_CATEGORY_NAME' => $objNews->fields['name'], 'NEWS_DATE' => date(ASCMS_DATE_FORMAT_DATE, $objNews->fields['newsdate']), 'NEWS_LONG_DATE' => date(ASCMS_DATE_FORMAT_DATETIME, $objNews->fields['newsdate']), 'NEWS_TITLE' => contrexx_raw2xhtml($newstitle), 'NEWS_URL' => $newslink, 'NEWS_TEASER_TEXT' => $newsteasertext, 'NEWS_TEXT' => $newstext, 'NEWS_AUTHOR' => $author));
                     $imageTemplateBlock = "news_image";
                     if (!empty($image)) {
                         $this->_impTpl->setVariable(array('NEWS_IMAGE' => $image, 'NEWS_IMAGE_SRC' => contrexx_raw2xhtml($imageSource), 'NEWS_IMAGE_ALT' => contrexx_raw2xhtml($newstitle), 'NEWS_IMAGE_LINK' => $htmlLinkImage));
                         if ($this->_impTpl->blockExists($imageTemplateBlock)) {
                             $this->_impTpl->parse($imageTemplateBlock);
                         }
                     } else {
                         if ($this->_impTpl->blockExists($imageTemplateBlock)) {
                             $this->_impTpl->hideBlock($imageTemplateBlock);
                         }
                     }
                     $this->_impTpl->parse("news_list");
                     $objNews->MoveNext();
                 }
             }
             $mailHtmlContent = $this->_impTpl->get();
         } else {
             if ($objNews !== false) {
                 $mailHtmlContent = '';
                 while (!$objNews->EOF) {
                     $content = $this->_getBodyContent($this->GetTemplateSource($importTemplate, 'html'));
                     $newstext = ltrim(strip_tags($objNews->fields['newscontent']));
                     $newsteasertext = ltrim(strip_tags($objNews->fields['teaser_text']));
                     $newslink = \Cx\Core\Routing\Url::fromModuleAndCmd('News', 'details', '', array('newsid' => $objNews->fields['newsid']));
                     if ($objNews->fields['newsuid'] && ($objUser = $objFWUser->objUser->getUser($objNews->fields['newsuid']))) {
                         $author = htmlentities($objUser->getUsername(), ENT_QUOTES, CONTREXX_CHARSET);
                     } else {
                         $author = $_ARRAYLANG['TXT_ANONYMOUS'];
                     }
                     $search = array('[[NEWS_DATE]]', '[[NEWS_LONG_DATE]]', '[[NEWS_TITLE]]', '[[NEWS_URL]]', '[[NEWS_IMAGE_PATH]]', '[[NEWS_TEASER_TEXT]]', '[[NEWS_TEXT]]', '[[NEWS_AUTHOR]]', '[[NEWS_TYPE_NAME]]', '[[NEWS_CATEGORY_NAME]]');
                     $replace = array(date(ASCMS_DATE_FORMAT_DATE, $objNews->fields['newsdate']), date(ASCMS_DATE_FORMAT_DATETIME, $objNews->fields['newsdate']), $objNews->fields['newstitle'], $newslink, htmlentities($objNews->fields['teaser_image_thumbnail_path'], ENT_QUOTES, CONTREXX_CHARSET), $newsteasertext, $newstext, $author, $objNews->fields['typename'], $objNews->fields['name']);
                     $content = str_replace($search, $replace, $content);
                     if ($mailHtmlContent != '') {
                         $mailHtmlContent .= "<br/>" . $content;
                     } else {
                         $mailHtmlContent = $content;
                     }
                     $objNews->MoveNext();
                 }
             }
         }
         unset($_REQUEST['standalone']);
     } else {
         $mailHtmlContent = '';
     }
     if (isset($_POST['newsletter_mail_attachment']) && is_array($_POST['newsletter_mail_attachment'])) {
         foreach ($_POST['newsletter_mail_attachment'] as $attachment) {
             array_push($arrAttachment, contrexx_addslashes($attachment));
         }
     }
     if (isset($_POST['newsletter_mail_priority'])) {
         $mailPriority = intval($_POST['newsletter_mail_priority']);
         if ($mailPriority < 1 || $mailPriority > 5) {
             $mailPriority = $this->_stdMailPriority;
         }
     } else {
         $mailPriority = $this->_stdMailPriority;
     }
     if (isset($_POST['newsletter_mail_associated_list'])) {
         foreach ($_POST['newsletter_mail_associated_list'] as $listId => $status) {
             if (intval($status) == 1) {
                 array_push($arrAssociatedLists, intval($listId));
             }
         }
     }
     // get the associated groups from the post variables in case the form was already sent
     if (isset($_POST['newsletter_mail_associated_group'])) {
         foreach ($_POST['newsletter_mail_associated_group'] as $groupID => $status) {
             if ($status) {
                 $arrAssociatedGroups[] = intval($groupID);
             }
         }
     }
     $arrSettings = $this->_getSettings();
     $mailSenderMail = isset($_POST['newsletter_mail_sender_mail']) ? contrexx_stripslashes($_POST['newsletter_mail_sender_mail']) : $arrSettings['sender_mail']['setvalue'];
     $mailSenderName = isset($_POST['newsletter_mail_sender_name']) ? contrexx_stripslashes($_POST['newsletter_mail_sender_name']) : $arrSettings['sender_name']['setvalue'];
     $mailReply = isset($_POST['newsletter_mail_sender_reply']) ? contrexx_stripslashes($_POST['newsletter_mail_sender_reply']) : $arrSettings['reply_mail']['setvalue'];
     $mailSmtpServer = isset($_POST['newsletter_mail_smtp_account']) ? intval($_POST['newsletter_mail_smtp_account']) : $_CONFIG['coreSmtpServer'];
     $this->_objTpl->loadTemplateFile('module_newsletter_mail_edit.html');
     $this->_pageTitle = $mailId > 0 ? $copy ? $_ARRAYLANG['TXT_NEWSLETTER_COPY_EMAIL'] : $_ARRAYLANG['TXT_NEWSLETTER_MODIFY_EMAIL'] : $_ARRAYLANG['TXT_NEWSLETTER_CREATE_NEW_EMAIL'];
     $this->_objTpl->setVariable(array('NEWSLETTER_MAIL_EDIT_TITLE' => $mailId > 0 ? $copy ? $_ARRAYLANG['TXT_NEWSLETTER_COPY_EMAIL'] : $_ARRAYLANG['TXT_NEWSLETTER_MODIFY_EMAIL'] : $_ARRAYLANG['TXT_NEWSLETTER_CREATE_NEW_EMAIL']));
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     if (isset($_POST['newsletter_mail_save'])) {
         $objAttachment = $objDatabase->Execute("SELECT file_name FROM " . DBPREFIX . "module_newsletter_attachment WHERE newsletter=" . $mailId);
         if ($objAttachment !== false) {
             $arrCurrentAttachments = array();
             while (!$objAttachment->EOF) {
                 array_push($arrCurrentAttachments, $cx->getWebsiteImagesAttachWebPath() . '/' . $objAttachment->fields['file_name']);
                 $objAttachment->MoveNext();
             }
             $arrNewAttachments = array_diff($arrAttachment, $arrCurrentAttachments);
             $arrRemovedAttachments = array_diff($arrCurrentAttachments, $arrAttachment);
         }
         $mailHtmlContentReplaced = preg_replace('/\\[\\[([A-Z0-9_]*?)\\]\\]/', '{\\1}', $mailHtmlContent);
         $mailHtmlContentReplaced = $this->_getBodyContent($mailHtmlContentReplaced);
         if ($mailId > 0) {
             $status = $this->_updateMail($mailId, $mailSubject, $mailTemplate, $mailSenderMail, $mailSenderName, $mailReply, $mailSmtpServer, $mailPriority, $arrAttachment, $mailHtmlContentReplaced);
         } else {
             $mailId = $this->_addMail($mailSubject, $mailTemplate, $mailSenderMail, $mailSenderName, $mailReply, $mailSmtpServer, $mailPriority, $arrAttachment, $mailHtmlContentReplaced);
             if ($mailId === false) {
                 $status = false;
             }
         }
         if ($status) {
             // prepare every link of HTML body for tracking function
             $this->_prepareNewsletterLinksForStore($mailId);
             $this->_setMailLists($mailId, $arrAssociatedLists, $mailSendDate);
             $this->setMailGroups($mailId, $arrAssociatedGroups, $mailSendDate);
             foreach ($arrNewAttachments as $attachment) {
                 $this->_addMailAttachment($attachment, $mailId);
             }
             foreach ($arrRemovedAttachments as $attachment) {
                 $this->_removeMailAttachment($attachment, $mailId);
             }
             self::$strOkMessage .= $_ARRAYLANG['TXT_DATA_RECORD_STORED_SUCCESSFUL'];
             if (isset($_GET['sendMail']) && $_GET['sendMail'] == '1') {
                 return $this->_sendMailPage();
             } else {
                 return $this->_mails();
             }
         }
     } elseif ((!isset($_GET['setFormat']) || $_GET['setFormat'] != '1') && $mailId > 0) {
         $objResult = $objDatabase->SelectLimit("SELECT\n                subject,\n                template,\n                content,\n                attachment,\n                priority,\n                sender_email,\n                sender_name,\n                return_path,\n                smtp_server\n                FROM " . DBPREFIX . "module_newsletter\n                WHERE id=" . $mailId, 1);
         if ($objResult !== false) {
             if ($objResult->RecordCount() == 1) {
                 $mailSubject = $objResult->fields['subject'];
                 $mailTemplate = $objResult->fields['template'];
                 $mailHtmlContent = preg_replace('/\\{([A-Z0-9_-]+)\\}/', '[[\\1]]', $objResult->fields['content']);
                 $mailPriority = $objResult->fields['priority'];
                 $mailSenderMail = $objResult->fields['sender_email'];
                 $mailSenderName = $objResult->fields['sender_name'];
                 $mailReply = $objResult->fields['return_path'];
                 $mailSmtpServer = $objResult->fields['smtp_server'];
                 $objList = $objDatabase->Execute("SELECT category FROM " . DBPREFIX . "module_newsletter_rel_cat_news WHERE newsletter=" . $mailId);
                 if ($objList !== false) {
                     while (!$objList->EOF) {
                         array_push($arrAssociatedLists, $objList->fields['category']);
                         $objList->MoveNext();
                     }
                 }
                 $arrAssociatedGroups = $this->emailEditGetAssociatedGroups($mailId);
                 if ($objResult->fields['attachment'] == '1') {
                     $objAttachment = $objDatabase->Execute("SELECT file_name FROM " . DBPREFIX . "module_newsletter_attachment WHERE newsletter=" . $mailId);
                     if ($objAttachment !== false) {
                         while (!$objAttachment->EOF) {
                             array_push($arrAttachment, $cx->getWebsiteImagesAttachWebPath() . '/' . $objAttachment->fields['file_name']);
                             $objAttachment->MoveNext();
                         }
                     }
                 }
             } else {
                 return $this->_mails();
             }
         }
     } else {
         $arrSettings = $this->_getSettings();
         $mailSenderMail = $arrSettings['sender_mail']['setvalue'];
         $mailSenderName = $arrSettings['sender_name']['setvalue'];
         $mailReply = $arrSettings['reply_mail']['setvalue'];
         $mailSmtpServer = $_CONFIG['coreSmtpServer'];
         if (!empty($_POST['textfield'])) {
             $mailHtmlContent = nl2br($_POST['textfield']);
         }
     }
     $act = $copy ? 'copyMail' : 'editMail';
     // remove newsletter_link_N value from rel attribute of the links
     if ($copy) {
         $mailHtmlContent = $this->_prepareNewsletterLinksForCopy($mailHtmlContent);
     }
     $this->_objTpl->setVariable(array('NEWSLETTER_MAIL_ID' => $copy ? 0 : $mailId, 'NEWSLETTER_MAIL_SUBJECT' => htmlentities($mailSubject, ENT_QUOTES, CONTREXX_CHARSET), 'NEWSLETTER_MAIL_HTML_CONTENT' => new \Cx\Core\Wysiwyg\Wysiwyg('newsletter_mail_html_content', contrexx_raw2xhtml($mailHtmlContent), 'fullpage'), 'NEWSLETTER_MAIL_PRIORITY_MENU' => $this->_getMailPriorityMenu($mailPriority, 'name="newsletter_mail_priority" style="width:300px;"'), 'NEWSLETTER_MAIL_TEMPLATE_MENU' => $this->_getTemplateMenu($mailTemplate, 'name="newsletter_mail_template" style="width:300px;" onchange="document.getElementById(\'newsletter_mail_form\').action=\'index.php?cmd=Newsletter&amp;act=' . $act . '&amp;id=' . $mailId . '&amp;setFormat=1\';document.getElementById(\'newsletter_mail_form\').submit()"'), 'NEWSLETTER_MAIL_SENDER_MAIL' => htmlentities($mailSenderMail, ENT_QUOTES, CONTREXX_CHARSET), 'NEWSLETTER_MAIL_SENDER_NAME' => htmlentities($mailSenderName, ENT_QUOTES, CONTREXX_CHARSET), 'NEWSLETTER_MAIL_REPLY' => htmlentities($mailReply, ENT_QUOTES, CONTREXX_CHARSET), 'NEWSLETTER_MAIL_SMTP_SERVER' => \SmtpSettings::getSmtpAccountMenu($mailSmtpServer, 'name="newsletter_mail_smtp_account" style="width:300px;"'), 'NEWSLETTER_MAIL_SEND' => $_GET['act'] == 'sendMail' ? 1 : 0));
     $this->_objTpl->setVariable('TXT_NEWSLETTER_HTML_UC', $_ARRAYLANG['TXT_NEWSLETTER_HTML_UC']);
     $this->_objTpl->touchBlock('newsletter_mail_html_content');
     $this->emailEditParseLists($arrAssociatedLists);
     $this->emailEditParseGroups($arrAssociatedGroups);
     if (count($arrAttachment) > 0) {
         foreach ($arrAttachment as $attachment) {
             $this->_objTpl->setVariable(array('NEWSLETTER_MAIL_ATTACHMENT_NR' => $attachmentNr, 'NEWSLETTER_MAIL_ATTACHMENT_NAME' => substr($attachment, strrpos($attachment, '/') + 1), 'NEWSLETTER_MAIL_ATTACHMENT_URL' => $attachment));
             $this->_objTpl->parse('newsletter_mail_attachment_list');
             $attachmentNr++;
         }
     } else {
         $this->_objTpl->hideBlock('newsletter_mail_attachment_list');
     }
     $this->_objTpl->setVariable(array('NEWSLETTER_MAIL_ATTACHMENT_NR' => $attachmentNr, 'NEWSLETTER_MAIL_ATTACHMENT_BOX' => $attachmentNr > 0 ? 'block' : 'none'));
     if (!$copy && $mailId > 0 && $mailSendDate > 0) {
         $this->_objTpl->touchBlock('associatedListToolTip');
         $this->_objTpl->touchBlock('associatedGroupToolTipAfterSent');
         $this->_objTpl->hideBlock('associatedGroupToolTipBeforeSend');
         $this->_objTpl->setVariable(array('TXT_NEWSLETTER_INFO_ABOUT_ASSOCIATED_LISTS' => $_ARRAYLANG['TXT_NEWSLETTER_INFO_ABOUT_ASSOCIATED_LISTS'], 'NEWSLETTER_LIST_DISABLED' => 'disabled="disabled"'));
     } else {
         $this->_objTpl->setVariable(array('TXT_NEWSLETTER_INFO_ABOUT_ASSOCIATED_LISTS_SEND' => $_ARRAYLANG['TXT_NEWSLETTER_INFO_ABOUT_ASSOCIATED_LISTS_SEND']));
         $this->_objTpl->hideBlock('associatedListToolTip');
         $this->_objTpl->hideBlock('associatedGroupToolTipAfterSent');
         $this->_objTpl->touchBlock('associatedGroupToolTipBeforeSend');
     }
     // Mediabrowser
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions(array('data-cx-mb-views' => 'filebrowser', 'type' => 'button'));
     $mediaBrowser->setCallback('mediaBrowserCallback');
     $this->_objTpl->setVariable(array('NEWSLETTER_ATTACH_FILE' => $mediaBrowser->getXHtml($_ARRAYLANG['TXT_NEWSLETTER_ATTACH_FILE'])));
     $this->_objTpl->setVariable(array('TXT_NEWSLETTER_EMAIL_ACCOUNT' => $_ARRAYLANG['TXT_NEWSLETTER_EMAIL_ACCOUNT'], 'TXT_NEWSLETTER_SUBJECT' => $_ARRAYLANG['TXT_NEWSLETTER_SUBJECT'], 'TXT_NEWSLETTER_SEND_AS' => $_ARRAYLANG['TXT_NEWSLETTER_SEND_AS'], 'TXT_NEWSLETTER_TEMPLATE' => $_ARRAYLANG['TXT_NEWSLETTER_TEMPLATE'], 'TXT_NEWSLETTER_SENDER' => $_ARRAYLANG['TXT_NEWSLETTER_SENDER'], 'TXT_NEWSLETTER_EMAIL' => $_ARRAYLANG['TXT_NEWSLETTER_EMAIL'], 'TXT_NEWSLETTER_URI' => $_ARRAYLANG['TXT_NEWSLETTER_URI'], 'TXT_NEWSLETTER_NAME' => $_ARRAYLANG['TXT_NEWSLETTER_NAME'], 'TXT_NEWSLETTER_REPLY_ADDRESS' => $_ARRAYLANG['TXT_NEWSLETTER_REPLY_ADDRESS'], 'TXT_NEWSLETTER_PRIORITY' => $_ARRAYLANG['TXT_NEWSLETTER_PRIORITY'], 'TXT_NEWSLETTER_PRIORITY' => $_ARRAYLANG['TXT_NEWSLETTER_PRIORITY'], 'TXT_NEWSLETTER_ATTACH' => $_ARRAYLANG['TXT_NEWSLETTER_ATTACH'], 'TXT_NEWSLETTER_DISPLAY_FILE' => $_ARRAYLANG['TXT_NEWSLETTER_DISPLAY_FILE'], 'TXT_NEWSLETTER_REMOVE_FILE' => $_ARRAYLANG['TXT_NEWSLETTER_REMOVE_FILE'], 'TXT_NEWSLETTER_HTML_CONTENT' => $_ARRAYLANG['TXT_NEWSLETTER_HTML_CONTENT'], 'TXT_NEWSLETTER_PLACEHOLDER_DIRECTORY' => $_ARRAYLANG['TXT_NEWSLETTER_PLACEHOLDER_DIRECTORY'], 'TXT_NEWSLETTER_USER_DATA' => $_ARRAYLANG['TXT_NEWSLETTER_USER_DATA'], 'TXT_NEWSLETTER_EMAIL_ADDRESS' => $_ARRAYLANG['TXT_NEWSLETTER_EMAIL_ADDRESS'], 'TXT_NEWSLETTER_SEX' => $_ARRAYLANG['TXT_NEWSLETTER_SEX'], 'TXT_NEWSLETTER_SALUTATION' => $_ARRAYLANG['TXT_NEWSLETTER_SALUTATION'], 'TXT_NEWSLETTER_TITLE' => $_ARRAYLANG['TXT_NEWSLETTER_TITLE'], 'TXT_NEWSLETTER_POSITION' => $_ARRAYLANG['TXT_NEWSLETTER_POSITION'], 'TXT_NEWSLETTER_COMPANY' => $_ARRAYLANG['TXT_NEWSLETTER_COMPANY'], 'TXT_NEWSLETTER_INDUSTRY_SECTOR' => $_ARRAYLANG['TXT_NEWSLETTER_INDUSTRY_SECTOR'], 'TXT_NEWSLETTER_ADDRESS' => $_ARRAYLANG['TXT_NEWSLETTER_ADDRESS'], 'TXT_NEWSLETTER_PHONE_PRIVATE' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE_PRIVATE'], 'TXT_NEWSLETTER_PHONE_MOBILE' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE_MOBILE'], 'TXT_NEWSLETTER_FAX' => $_ARRAYLANG['TXT_NEWSLETTER_FAX'], 'TXT_NEWSLETTER_WEBSITE' => $_ARRAYLANG['TXT_NEWSLETTER_WEBSITE'], 'TXT_NEWSLETTER_LASTNAME' => $_ARRAYLANG['TXT_NEWSLETTER_LASTNAME'], 'TXT_NEWSLETTER_FIRSTNAME' => $_ARRAYLANG['TXT_NEWSLETTER_FIRSTNAME'], 'TXT_NEWSLETTER_ADDRESS' => $_ARRAYLANG['TXT_NEWSLETTER_ADDRESS'], 'TXT_NEWSLETTER_ZIP' => $_ARRAYLANG['TXT_NEWSLETTER_ZIP'], 'TXT_NEWSLETTER_CITY' => $_ARRAYLANG['TXT_NEWSLETTER_CITY'], 'TXT_NEWSLETTER_COUNTRY' => $_ARRAYLANG['TXT_NEWSLETTER_COUNTRY'], 'TXT_NEWSLETTER_PHONE' => $_ARRAYLANG['TXT_NEWSLETTER_PHONE'], 'TXT_NEWSLETTER_BIRTHDAY' => $_ARRAYLANG['TXT_NEWSLETTER_BIRTHDAY'], 'TXT_NEWSLETTER_GENERAL' => $_ARRAYLANG['TXT_NEWSLETTER_GENERAL'], 'TXT_NEWSLETTER_MODIFY_PROFILE' => $_ARRAYLANG['TXT_NEWSLETTER_MODIFY_PROFILE'], 'TXT_NEWSLETTER_UNSUBSCRIBE' => $_ARRAYLANG['TXT_NEWSLETTER_UNSUBSCRIBE'], 'TXT_NEWSLETTER_PLACEHOLDER_NOT_ON_BROWSER_VIEW' => $_ARRAYLANG['TXT_NEWSLETTER_PLACEHOLDER_NOT_ON_BROWSER_VIEW'], 'TXT_NEWSLETTER_DATE' => $_ARRAYLANG['TXT_NEWSLETTER_DATE'], 'TXT_NEWSLETTER_DISPLAY_IN_BROWSER_LINK' => $_ARRAYLANG['TXT_NEWSLETTER_DISPLAY_IN_BROWSER_LINK'], 'TXT_NEWSLETTER_SUBJECT' => $_ARRAYLANG['TXT_NEWSLETTER_SUBJECT'], 'TXT_NEWSLETTER_SAVE' => $_ARRAYLANG['TXT_NEWSLETTER_SAVE'], 'TXT_NEWSLETTER_BACK' => $_ARRAYLANG['TXT_NEWSLETTER_BACK'], 'TXT_NEWSLETTER_CONFIRM_EMPTY_TEXT' => $_ARRAYLANG['TXT_NEWSLETTER_CONFIRM_EMPTY_TEXT']));
     return true;
 }
 /**
  * Get the MediaBrowser button
  * 
  * @global array $_ARRAYLANG
  * 
  * @param string $options      mediabrowser options
  * @param string $callBackName callback javascript function name
  * 
  * @return mixed boolean|string
  */
 public static function getMediaBrowserButton($options, $callBackName = '')
 {
     if (empty($options)) {
         return false;
     }
     global $_ARRAYLANG;
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions($options);
     if (!empty($callBackName)) {
         $mediaBrowser->setCallback($callBackName);
     }
     return $mediaBrowser->getXHtml($_ARRAYLANG['TXT_BROWSE']);
 }
    public function getDataElement($name, $type, $length, $value, $options)
    {
        global $_ARRAYLANG;
        if (isset($options['formfield']) && is_callable($options['formfield'])) {
            $formFieldGenerator = $options['formfield'];
            $formField = $formFieldGenerator($name, $type, $length, $value, $options);
            if (is_a($formField, 'Cx\\Core\\Html\\Model\\Entity\\HtmlElement')) {
                return $formField;
            } else {
                $value = $formField;
            }
        }
        if (isset($options['showDetail']) && $options['showDetail'] === false) {
            return '';
        }
        switch ($type) {
            case 'bool':
            case 'boolean':
                // yes/no checkboxes
                $fieldset = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $inputYes = new \Cx\Core\Html\Model\Entity\DataElement($name, 'yes');
                $inputYes->setAttribute('type', 'radio');
                $inputYes->setAttribute('value', '1');
                $inputYes->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_yes');
                if (isset($options['attributes'])) {
                    $inputYes->setAttributes($options['attributes']);
                }
                $fieldset->addChild($inputYes);
                $labelYes = new \Cx\Core\Html\Model\Entity\HtmlElement('label');
                $labelYes->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_yes');
                $labelYes->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_YES']));
                $fieldset->addChild($labelYes);
                $inputNo = new \Cx\Core\Html\Model\Entity\DataElement($name, 'no');
                $inputNo->setAttribute('id', 'form-' . $this->formId . '-' . $name . '_no');
                $inputNo->setAttribute('type', 'radio');
                $inputNo->setAttribute('value', '0');
                if (isset($options['attributes'])) {
                    $inputNo->setAttributes($options['attributes']);
                }
                $fieldset->addChild($inputNo);
                $labelNo = new \Cx\Core\Html\Model\Entity\HtmlElement('label');
                $labelNo->setAttribute('for', 'form-' . $this->formId . '-' . $name . '_no');
                $labelNo->addChild(new \Cx\Core\Html\Model\Entity\TextElement($_ARRAYLANG['TXT_NO']));
                $fieldset->addChild($labelNo);
                if ($value) {
                    $inputYes->setAttribute('checked');
                } else {
                    $inputNo->setAttribute('checked');
                }
                return $fieldset;
                break;
            case 'int':
            case 'integer':
                // input field with type number
                $inputNumber = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT, new \Cx\Core\Validate\Model\Entity\RegexValidator('/-?[0-9]*/'));
                if (isset($options['attributes'])) {
                    $inputNumber->setAttributes($options['attributes']);
                }
                $inputNumber->setAttribute('type', 'number');
                return $inputNumber;
                break;
            case 'Cx\\Model\\Base\\EntityBase':
                $entityClass = get_class($value);
                $entities = \Env::get('em')->getRepository($entityClass)->findAll();
                $foreignMetaData = \Env::get('em')->getClassMetadata($entityClass);
                $primaryKeyName = $foreignMetaData->getSingleIdentifierFieldName();
                $selected = $foreignMetaData->getFieldValue($value, $primaryKeyName);
                $arrEntities = array();
                $closeMetaData = \Env::get('em')->getClassMetadata($this->entityClass);
                $assocMapping = $closeMetaData->getAssociationMapping($name);
                if (!isset($assocMapping['joinColumns'][0]['nullable']) || $assocMapping['joinColumns'][0]['nullable']) {
                    $arrEntities['NULL'] = $_ARRAYLANG['TXT_CORE_NONE'];
                }
                foreach ($entities as $entity) {
                    $arrEntities[\Env::get('em')->getClassMetadata($entityClass)->getFieldValue($entity, $primaryKeyName)] = $entity;
                }
                $select = new \Cx\Core\Html\Model\Entity\DataElement($name, \Html::getOptions($arrEntities, $selected), \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
                if (isset($options['attributes'])) {
                    $select->setAttributes($options['attributes']);
                }
                return $select;
                break;
            case 'Country':
                // this is for customizing only:
                $data = \Cx\Core\Country\Controller\Country::getNameById($value);
                if (empty($data)) {
                    $value = 204;
                }
                $options = \Cx\Core\Country\Controller\Country::getMenuoptions($value);
                $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $options, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
                if (isset($options['attributes'])) {
                    $select->setAttributes($options['attributes']);
                }
                return $select;
                break;
            case 'DateTime':
            case 'datetime':
            case 'date':
                // input field with type text and class datepicker
                if ($value instanceof \DateTime) {
                    $value = $value->format(ASCMS_DATE_FORMAT);
                }
                if (is_null($value)) {
                    $value = '';
                }
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'text');
                $input->setAttribute('class', 'datepicker');
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                \DateTimeTools::addDatepickerJs();
                \JS::registerCode('
                        cx.jQuery(function() {
                          cx.jQuery(".datepicker").datetimepicker();
                        });
                        ');
                return $input;
                break;
            case 'multiselect':
            case 'select':
                $values = array();
                if (isset($options['validValues'])) {
                    if (is_array($options['validValues'])) {
                        $values = $options['validValues'];
                    } else {
                        $values = explode(',', $options['validValues']);
                        $values = array_combine($values, $values);
                    }
                }
                if ($type == 'multiselect') {
                    $value = explode(',', $value);
                    $value = array_combine($value, $value);
                }
                $selectOptions = \Html::getOptions($values, $value);
                $select = new \Cx\Core\Html\Model\Entity\DataElement($name, $selectOptions, \Cx\Core\Html\Model\Entity\DataElement::TYPE_SELECT);
                if ($type == 'multiselect') {
                    $select->setAttribute('multiple');
                }
                if (isset($options['attributes'])) {
                    $select->setAttributes($options['attributes']);
                }
                return $select;
                break;
            case 'slider':
                // this code should not be here
                // create sorrounding div
                $element = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                // create div for slider
                $slider = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $slider->setAttribute('class', 'slider');
                $element->addChild($slider);
                // create hidden input for slider value
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value + 0, \Cx\Core\Html\Model\Entity\DataElement::TYPE_INPUT);
                $input->setAttribute('type', 'hidden');
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                $element->addChild($input);
                // add javascript to update input value
                $min = 0;
                $max = 10;
                if (isset($options['validValues'])) {
                    $values = explode(',', $options['validValues']);
                    $min = $values[0];
                    if (isset($values[1])) {
                        $max = $values[1];
                    }
                }
                if (!isset($value)) {
                    $value = 0;
                }
                $script = new \Cx\Core\Html\Model\Entity\HtmlElement('script');
                $script->addChild(new \Cx\Core\Html\Model\Entity\TextElement('
                    cx.jQuery("#form-' . $this->formId . '-' . $name . ' .slider").slider({
                        value: ' . ($value + 0) . ',
                        min: ' . ($min + 0) . ',
                        max: ' . ($max + 0) . ',
                        slide: function( event, ui ) {
                            cx.jQuery("input[name=' . $name . ']").val(ui.value);
                            cx.jQuery("input[name=' . $name . ']").change();
                        }
                    });
                '));
                $element->addChild($script);
                return $element;
                break;
            case 'checkboxes':
                $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_CHECKBOX;
            case 'radio':
                $values = array();
                if (isset($options['validValues'])) {
                    $values = explode(',', $options['validValues']);
                    $values = array_combine($values, $values);
                }
                if (!isset($dataElementGroupType)) {
                    $dataElementGroupType = \Cx\Core\Html\Model\Entity\DataElementGroup::TYPE_RADIO;
                }
                $radio = new \Cx\Core\Html\Model\Entity\DataElementGroup($name, $values, $value, $dataElementGroupType);
                if (isset($options['attributes'])) {
                    $radio->setAttributes($options['attributes']);
                }
                return $radio;
                break;
            case 'text':
                // textarea
                $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea');
                $textarea->setAttribute('name', $name);
                if (isset($options['readonly']) && $options['readonly']) {
                    $textarea->setAttribute('disabled');
                }
                $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value));
                if (isset($options['attributes'])) {
                    $textarea->setAttributes($options['attributes']);
                }
                return $textarea;
                break;
            case 'phone':
                // input field with type phone
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'phone');
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                return $input;
                break;
            case 'mail':
                // input field with type mail
                $emailValidator = new \Cx\Core\Validate\Model\Entity\EmailValidator();
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value, 'input', $emailValidator);
                $input->setAttribute('onkeyup', $emailValidator->getJavaScriptCode());
                $input->setAttribute('type', 'mail');
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                return $input;
                break;
            case 'uploader':
                \JS::registerCode('
                    function javascript_callback_function(data) {
                        if(data.type=="file") {
                                cx.jQuery("#' . $name . '").val(data.data[0].datainfo.filepath);
                        }
                    }

                ');
                $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
                $mediaBrowser->setOptions(array('type' => 'button'));
                $mediaBrowser->setCallback('javascript_callback_function');
                $mediaBrowser->setOptions(array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList'));
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'text');
                $input->setAttribute('id', $name);
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $div->addChild($input);
                $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mb = $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE'])));
                return $div;
                break;
            case 'image':
                \JS::registerCode('
                    function javascript_callback_function(data) {
                        if ( data.data[0].datainfo.extension=="Jpg"
                            || data.data[0].datainfo.extension=="Gif"
                            || data.data[0].datainfo.extension=="Png"
                        ) {
                            cx.jQuery("#' . $name . '").attr(\'value\', data.data[0].datainfo.filepath);
                            cx.jQuery("#' . $name . '").prevAll(\'.deletePreviewImage\').first().css(\'display\', \'inline-block\');
                            cx.jQuery("#' . $name . '").prevAll(\'.previewImage\').first().attr(\'src\', data.data[0].datainfo.filepath);
                        }
                    }

                    jQuery(document).ready(function(){
                        jQuery(\'.deletePreviewImage\').click(function(){
                            cx.jQuery("#' . $name . '").attr(\'value\', \'\');
                            cx.jQuery(this).prev(\'img\').attr(\'src\', \'/images/Downloads/no_picture.gif\');
                            cx.jQuery(this).css(\'display\', \'none\');
                            cx.jQuery(this).nextAll(\'input\').first().attr(\'value\', \'\');
                        });
                    });

                ');
                $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
                $mediaBrowser->setOptions(array('type' => 'button'));
                $mediaBrowser->setCallback('javascript_callback_function');
                $defaultOptions = array('data-cx-mb-views' => 'filebrowser,uploader', 'id' => 'page_target_browse', 'cxMbStartview' => 'MediaBrowserList');
                $mediaBrowser->setOptions(is_array($options['options']) ? array_merge($defaultOptions, $options['options']) : $defaultOptions);
                // create hidden input to save image
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                $input->setAttribute('type', 'hidden');
                $input->setAttribute('id', $name);
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                if (isset($value) && in_array(pathinfo($value, PATHINFO_EXTENSION), array('gif', 'jpg', 'png')) || $name == 'imagePath') {
                    // this image is meant to be a preview of the selected image
                    $previewImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img');
                    $previewImage->setAttribute('class', 'previewImage');
                    $previewImage->setAttribute('src', $value != '' ? $value : '/images/Downloads/no_picture.gif');
                    // this image is uesd as delete function for the selected image over javascript
                    $deleteImage = new \Cx\Core\Html\Model\Entity\HtmlElement('img');
                    $deleteImage->setAttribute('class', 'deletePreviewImage');
                    $deleteImage->setAttribute('src', '/core/Core/View/Media/icons/delete.gif');
                    $div->addChild($previewImage);
                    $div->addChild($deleteImage);
                    $div->addChild(new \Cx\Core\Html\Model\Entity\HtmlElement('br'));
                }
                $div->addChild($input);
                $div->addChild(new \Cx\Core\Html\Model\Entity\TextElement($mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE'])));
                return $div;
                break;
            case 'sourcecode':
                //set mode
                $mode = 'html';
                if (isset($options['options']['mode'])) {
                    switch ($options['options']['mode']) {
                        case 'js':
                            $mode = 'javascript';
                            break;
                        case 'yml':
                        case 'yaml':
                            $mode = 'yaml';
                            break;
                    }
                }
                //define textarea
                $textarea = new \Cx\Core\Html\Model\Entity\HtmlElement('textarea');
                $textarea->setAttribute('name', $name);
                $textarea->setAttribute('id', $name);
                $textarea->setAttribute('style', 'display:none;');
                $textarea->addChild(new \Cx\Core\Html\Model\Entity\TextElement($value));
                //define pre
                $pre = new \Cx\Core\Html\Model\Entity\HtmlElement('pre');
                $pre->setAttribute('id', 'editor-' . $name);
                $pre->addChild(new \Cx\Core\Html\Model\Entity\TextElement(contrexx_raw2xhtml($value)));
                //set readonly if necessary
                $readonly = '';
                if (isset($options['readonly']) && $options['readonly']) {
                    $readonly = 'editor.setReadOnly(true);';
                    $textarea->setAttribute('disabled');
                }
                //create div and add all stuff
                $div = new \Cx\Core\Html\Model\Entity\HtmlElement('div');
                $div->addChild($textarea);
                $div->addChild($pre);
                //register js
                $jsCode = <<<CODE
var editor;                        
\$J(function(){
if (\$J("#editor-{$name}").length) {
    editor = ace.edit("editor-{$name}");
    editor.getSession().setMode("ace/mode/{$mode}");
    editor.setShowPrintMargin(false);
    editor.focus();
    editor.gotoLine(1);
    {$readonly}
}

\$J('form').submit(function(){
    \$J('#{$name}').val(editor.getSession().getValue());
});

});
CODE;
                \JS::activate('ace');
                \JS::registerCode($jsCode);
                return $div;
                break;
            case 'string':
            case 'hidden':
            default:
                // convert NULL to empty string
                if (is_null($value)) {
                    $value = '';
                }
                // input field with type text
                $input = new \Cx\Core\Html\Model\Entity\DataElement($name, $value);
                if (isset($options['validValues'])) {
                    $input->setValidator(new \Cx\Core\Validate\Model\Entity\RegexValidator('/^' . $options['validValues'] . '$/'));
                }
                if ($type == 'hidden') {
                    $input->setAttribute('type', 'hidden');
                } else {
                    $input->setAttribute('type', 'text');
                    $input->setClass('form-control');
                }
                if (isset($options['readonly']) && $options['readonly']) {
                    $input->setAttribute('disabled');
                }
                if (isset($options['attributes'])) {
                    $input->setAttributes($options['attributes']);
                }
                return $input;
                break;
        }
    }
 /**
  * Modify Group Page
  *
  * This page shows the dialog to modify a group.
  *
  * @return unknown
  */
 function _modifyGroup()
 {
     global $_ARRAYLANG, $_CORELANG, $objDatabase;
     $arrAreas = array();
     $associatedUsers = '';
     $arrContentAccessIds = array();
     $arrSelectedAccessIds = array();
     $notAssociatedUsers = '';
     $objFWUser = \FWUser::getFWUserObject();
     $objGroup = $objFWUser->objGroup->getGroup(isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
     if (isset($_POST['access_save_group'])) {
         // only administrators are allowed to modify a group
         if (!\Permission::hasAllAccess()) {
             \Permission::noAccess();
         }
         $objGroup->setName(!empty($_POST['access_group_name']) ? trim(contrexx_input2raw($_POST['access_group_name'])) : '');
         $objGroup->setDescription(!empty($_POST['access_group_description']) ? trim(contrexx_input2raw($_POST['access_group_description'])) : '');
         $objGroup->setActiveStatus(isset($_POST['access_group_status']) ? (bool) $_POST['access_group_status'] : false);
         $objGroup->setType(!empty($_POST['access_group_type']) ? $_POST['access_group_type'] : '');
         $objGroup->setHomepage(!empty($_POST['access_group_homepage']) ? trim(contrexx_input2raw($_POST['access_group_homepage'])) : '');
         $objGroup->setUsers(isset($_POST['access_group_associated_users']) && is_array($_POST['access_group_associated_users']) ? $_POST['access_group_associated_users'] : array());
         $objGroup->setStaticPermissionIds(isset($_POST['access_area_id']) && is_array($_POST['access_area_id']) ? $_POST['access_area_id'] : array());
         // set dynamic access ids
         $arrSelectedPageIds = isset($_POST['access_page_id']) && is_array($_POST['access_page_id']) ? $_POST['access_page_id'] : array();
         $objJsonData = new \Cx\Core\Json\JsonData();
         $jsonData = $objJsonData->data('node', 'getTree', array('get' => array('recursive' => 'true')));
         $nodeStack = $jsonData['data']['tree'];
         while (count($nodeStack)) {
             $node = array_pop($nodeStack);
             foreach ($node['data'] as $page) {
                 if ($page['attr']['id'] == 'broken') {
                     continue;
                 }
                 if (empty($page['attr'][$objGroup->getType() . '_access_id'])) {
                     continue;
                 }
                 $arrContentAccessIds[] = $page['attr'][$objGroup->getType() . '_access_id'];
                 if (in_array($page['attr']['id'], $arrSelectedPageIds)) {
                     $arrSelectedAccessIds[] = $page['attr'][$objGroup->getType() . '_access_id'];
                 }
             }
             $children = $node['children'];
             $hasChilds = count($children) > 0;
             if ($hasChilds) {
                 foreach ($children as $child) {
                     array_push($nodeStack, $child);
                 }
             }
         }
         $arrCurrentAccessIds = $objGroup->getDynamicPermissionIds();
         foreach ($arrContentAccessIds as $accessId) {
             // add new access ids
             if (in_array($accessId, $arrSelectedAccessIds) && !in_array($accessId, $arrCurrentAccessIds)) {
                 $arrCurrentAccessIds[] = $accessId;
             }
             // delete access ids
             if (!in_array($accessId, $arrSelectedAccessIds) && in_array($accessId, $arrCurrentAccessIds)) {
                 unset($arrCurrentAccessIds[array_search($accessId, $arrCurrentAccessIds)]);
             }
         }
         $objGroup->setDynamicPermissionIds($arrCurrentAccessIds);
         if (isset($_POST['access_save_group'])) {
             if ($objGroup->store()) {
                 self::$arrStatusMsg['ok'][] = $_ARRAYLANG['TXT_ACCESS_GROUP_STORED_SUCCESSFULLY'];
                 $objFWUser->objUser->getDynamicPermissionIds(true);
                 $objFWUser->objUser->getStaticPermissionIds(true);
                 $this->_groupList();
                 return;
             } else {
                 self::$arrStatusMsg['error'][] = $objGroup->getErrorMsg();
             }
         }
     } elseif (isset($_POST['access_create_group'])) {
         $objGroup->setType(isset($_POST['access_group_type']) ? $_POST['access_group_type'] : '');
     }
     $this->_objTpl->addBlockfile('ACCESS_GROUP_TEMPLATE', 'module_access_group_modify', 'module_access_group_modify.html');
     $this->_pageTitle = $objGroup->getId() ? $_ARRAYLANG['TXT_ACCESS_MODIFY_GROUP'] : $_ARRAYLANG['TXT_ACCESS_CREATE_NEW_USER_GROUP'];
     $objUser = $objFWUser->objUser->getUsers(null, null, array('username' => 'asc', 'email' => 'asc'), array('id', 'username', 'email', 'firstname', 'lastname'));
     if ($objUser) {
         $arrGroupUsers = $objGroup->getAssociatedUserIds();
         while (!$objUser->EOF) {
             $arrUsers[] = $objUser->getId();
             $objUser->next();
         }
         $arrOtherUsers = array_diff($arrUsers, $arrGroupUsers);
         foreach ($arrGroupUsers as $uId) {
             $objUser = $objFWUser->objUser->getUser($uId);
             if ($objUser) {
                 $associatedUsers .= "<option value=\"" . $objUser->getId() . "\">" . htmlentities($objUser->getUsername(), ENT_QUOTES, CONTREXX_CHARSET) . ($objUser->getProfileAttribute('lastname') != '' || $objUser->getProfileAttribute('firstname') != '' ? " (" . htmlentities($objUser->getProfileAttribute('firstname'), ENT_QUOTES, CONTREXX_CHARSET) . " " . htmlentities($objUser->getProfileAttribute('lastname'), ENT_QUOTES, CONTREXX_CHARSET) . ")" : '') . "</option>\n";
             }
         }
         foreach ($arrOtherUsers as $uId) {
             $objUser = $objFWUser->objUser->getUser($uId);
             if ($objUser) {
                 $notAssociatedUsers .= "<option value=\"" . $objUser->getId() . "\">" . htmlentities($objUser->getUsername(), ENT_QUOTES, CONTREXX_CHARSET) . ($objUser->getProfileAttribute('lastname') != '' || $objUser->getProfileAttribute('firstname') != '' ? " (" . htmlentities($objUser->getProfileAttribute('firstname'), ENT_QUOTES, CONTREXX_CHARSET) . " " . htmlentities($objUser->getProfileAttribute('lastname'), ENT_QUOTES, CONTREXX_CHARSET) . ")" : '') . "</option>\n";
             }
         }
     }
     $this->_objTpl->setVariable('ACCESS_WEBSITE_TAB_NAME', 'Webseiten');
     $arrModules = array();
     $objResult = $objDatabase->Execute("SELECT id, name FROM " . DBPREFIX . "modules");
     if ($objResult !== false) {
         while (!$objResult->EOF) {
             $arrModules[$objResult->fields['id']] = $objResult->fields['name'];
             $objResult->MoveNext();
         }
     }
     $this->_objTpl->setGlobalVariable(array('TXT_ACCESS_SHOW_PAGE_IN_NEW_DOCUMENT' => $_ARRAYLANG['TXT_ACCESS_SHOW_PAGE_IN_NEW_DOCUMENT'], 'TXT_ACCESS_MODIFY_PAGE_IN_NEW_DOCUMENT' => $_ARRAYLANG['TXT_ACCESS_MODIFY_PAGE_IN_NEW_DOCUMENT'], 'TXT_ACCESS_CHECK_ALL' => $_ARRAYLANG['TXT_ACCESS_CHECK_ALL'], 'TXT_ACCESS_UNCHECK_ALL' => $_ARRAYLANG['TXT_ACCESS_UNCHECK_ALL']));
     \JS::registerCSS('core/ContentManager/View/Style/Main.css');
     $objJsonData = new \Cx\Core\Json\JsonData();
     $jsonData = $objJsonData->data('node', 'getTree', array('get' => array('recursive' => 'true')));
     $nodeTree = $jsonData['data']['tree'];
     $this->parseContentTree($nodeTree, $objGroup->getType(), $objGroup->getDynamicPermissionIds());
     $objResult = $objDatabase->Execute("\n            SELECT\n                `areas`.`area_id`,\n                `areas`.`area_name`,\n                `areas`.`access_id`,\n                `areas`.`module_id`,\n                `areas`.`is_active`,\n                `areas`.`type`,\n                `areas`.`scope`,\n                `areas`.`parent_area_id`,\n                `modules`.`name` AS `module_name`\n            FROM\n                `" . DBPREFIX . "backend_areas` AS `areas`\n            INNER JOIN\n                `" . DBPREFIX . "modules` AS `modules`\n            ON\n                `modules`.`id` = `areas`.`module_id`\n            WHERE\n                `areas`.`is_active` = 1 AND\n                `areas`.`access_id` != '0'\n            ORDER BY\n                `areas`.`parent_area_id`,\n                `areas`.`order_id`\n        ");
     if ($objResult) {
         while (!$objResult->EOF) {
             if (isset($_CORELANG[$objResult->fields['area_name']])) {
                 $areaName = $_CORELANG[$objResult->fields['area_name']];
             } else {
                 // load language file
                 $objInit = \Env::get('init');
                 $moduleLanguageData = $objInit->getComponentSpecificLanguageData($objResult->fields['module_name'], false, $objInit->backendLangId);
                 if (isset($moduleLanguageData[$objResult->fields['area_name']])) {
                     $areaName = $moduleLanguageData[$objResult->fields['area_name']];
                 } else {
                     $areaName = $objResult->fields['area_name'];
                 }
             }
             $arrAreas[$objResult->fields['area_id']] = array('name' => $areaName, 'access_id' => $objResult->fields['access_id'], 'status' => $objResult->fields['is_active'], 'type' => $objResult->fields['type'], 'module_id' => $objResult->fields['module_id'], 'scope' => $objResult->fields['scope'], 'group_id' => $objResult->fields['parent_area_id'], 'allowed' => in_array($objResult->fields['access_id'], $objGroup->getStaticPermissionIds()) ? 1 : 0);
             $objResult->MoveNext();
         }
     }
     $tabNr = 1;
     foreach ($arrAreas as $groupId => $arrAreaGroup) {
         if ($arrAreaGroup['type'] == 'group') {
             $arrAreaTree = array();
             if ($arrAreaGroup['scope'] == $objGroup->getType() || $arrAreaGroup['scope'] == 'global') {
                 $arrAreaTree[] = array($groupId, $objGroup->getType());
                 $groupParsed = true;
             } else {
                 $groupParsed = false;
             }
             foreach ($arrAreas as $navigationId => $arrAreaNavigation) {
                 if ($groupId == $arrAreaNavigation['group_id'] && $arrAreaNavigation['type'] == 'navigation') {
                     if ($arrAreaNavigation['scope'] == $objGroup->getType() || $arrAreaNavigation['scope'] == 'global') {
                         if (!$groupParsed) {
                             $arrAreaTree[] = array($groupId, $objGroup->getType());
                             $groupParsed = true;
                         }
                         $arrAreaTree[] = array($navigationId, $objGroup->getType());
                         $navigationParsed = true;
                     } else {
                         $navigationParsed = false;
                     }
                     foreach ($arrAreas as $functionId => $arrAreaFunction) {
                         if ($navigationId == $arrAreaFunction['group_id'] && $arrAreaFunction['type'] == 'function') {
                             if ($arrAreaFunction['scope'] == $objGroup->getType() || $arrAreaFunction['scope'] == 'global') {
                                 if (!$navigationParsed) {
                                     if (!$groupParsed) {
                                         $arrAreaTree[] = array($groupId, $objGroup->getType());
                                         $groupParsed = true;
                                     }
                                     $arrAreaTree[] = array($navigationId, $objGroup->getType());
                                     $navigationParsed = true;
                                 }
                                 $arrAreaTree[] = array($functionId, $objGroup->getType());
                             }
                         }
                     }
                 }
             }
             if ($groupParsed) {
                 foreach ($arrAreaTree as $arrArea) {
                     $this->_parsePermissionAreas($arrAreas, $arrArea[0], $arrArea[1]);
                 }
                 $this->_objTpl->setGlobalVariable('ACCESS_TAB_NR', $tabNr);
                 $this->_objTpl->setVariable('ACCESS_TAB_NAME', isset($_CORELANG[$arrAreaGroup['name']]) ? htmlentities($_CORELANG[$arrAreaGroup['name']], ENT_QUOTES, CONTREXX_CHARSET) : $arrAreaGroup['name']);
                 $this->_objTpl->parse('access_permission_tab_menu');
                 $this->_objTpl->parse('access_permission_tabs');
                 $tabNr++;
             }
         }
     }
     if ($tabNr > 1) {
         $this->_objTpl->parse('access_permission_tabs_menu');
     } else {
         $this->_objTpl->hideBlock('access_permission_tabs_menu');
     }
     //Display MediaBrowser for selecting webpage
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => 'sitestructure', 'id' => 'media-browser-button', 'style' => 'display: none;'));
     $mediaBrowser->setCallback('SetUrl');
     $this->attachJavaScriptFunction('accessSetWebpage');
     $this->attachJavaScriptFunction('accessSelectAllGroups');
     $this->attachJavaScriptFunction('accessDeselectAllGroups');
     $this->attachJavaScriptFunction('accessAddGroupToList');
     $this->attachJavaScriptFunction('accessRemoveGroupFromList');
     $this->_objTpl->setVariable(array('ACCESS_MEDIA_BROWSER_BUTTON' => $mediaBrowser->getXHtml($_ARRAYLANG['TXT_ACCESS_BROWSE']), 'TXT_ACCESS_GENERAL' => $_ARRAYLANG['TXT_ACCESS_GENERAL'], 'TXT_ACCESS_PERMISSIONS' => $_ARRAYLANG['TXT_ACCESS_PERMISSIONS'], 'TXT_ACCESS_NAME' => $_ARRAYLANG['TXT_ACCESS_NAME'], 'TXT_ACCESS_DESCRIPTION' => $_ARRAYLANG['TXT_ACCESS_DESCRIPTION'], 'TXT_ACCESS_STATUS' => $_ARRAYLANG['TXT_ACCESS_STATUS'], 'TXT_ACCESS_ACTIVE' => $_ARRAYLANG['TXT_ACCESS_ACTIVE'], 'TXT_ACCESS_CANCEL' => $_ARRAYLANG['TXT_ACCESS_CANCEL'], 'TXT_ACCESS_SAVE' => $_ARRAYLANG['TXT_ACCESS_SAVE'], 'TXT_ACCESS_USERS' => $_ARRAYLANG['TXT_ACCESS_USERS'], 'TXT_ACCESS_AVAILABLE_USERS' => $_ARRAYLANG['TXT_ACCESS_AVAILABLE_USERS'], 'TXT_ACCESS_CHECK_ALL' => $_ARRAYLANG['TXT_ACCESS_CHECK_ALL'], 'TXT_ACCESS_UNCHECK_ALL' => $_ARRAYLANG['TXT_ACCESS_UNCHECK_ALL'], 'TXT_ACCESS_ASSOCIATED_USERS' => $_ARRAYLANG['TXT_ACCESS_ASSOCIATED_USERS'], 'TXT_ACCESS_UNPROTECT_PAGE' => $_ARRAYLANG['TXT_ACCESS_UNPROTECT_PAGE'], 'TXT_ACCESS_PROTECT_PAGE' => $_ARRAYLANG['TXT_ACCESS_PROTECT_PAGE'], 'TXT_ACCESS_PROMT_EXEC_WARNING' => $_ARRAYLANG['TXT_ACCESS_PROMT_EXEC_WARNING'], 'TXT_ACCESS_HOMEPAGE' => $_ARRAYLANG['TXT_ACCESS_HOMEPAGE'], 'TXT_ACCESS_HOMEPAGE_DESC' => $_ARRAYLANG['TXT_ACCESS_HOMEPAGE_DESC'], 'TXT_ACCESS_BROWSE' => $_ARRAYLANG['TXT_ACCESS_BROWSE']));
     $this->_objTpl->setVariable(array('ACCESS_GROUP_ID' => $objGroup->getId(), 'ACCESS_GROUP_NAME' => contrexx_raw2xhtml($objGroup->getName()), 'ACCESS_GROUP_DESCRIPTION' => contrexx_raw2xhtml($objGroup->getDescription()), 'ACCESS_GROUP_STATUS' => $objGroup->getActiveStatus() ? 'checked="checked"' : '', 'ACCESS_GROUP_TYPE' => $objGroup->getType(), 'ACCESS_GROUP_HOMEPAGE' => $objGroup->getHomepage(), 'ACCESS_GROUP_NOT_ASSOCIATED_USERS' => $notAssociatedUsers, 'ACCESS_GROUP_ASSOCIATED_USERS' => $associatedUsers, 'ACCESS_PROTECT_PAGE_TXT' => $objGroup->getType() == 'backend' ? $_ARRAYLANG['TXT_ACCESS_CONFIRM_LOCK_PAGE'] : $_ARRAYLANG['TXT_ACCESS_CONFIRM_PROTECT_PAGE'], 'ACCESS_UNPROTECT_PAGE_TXT' => $objGroup->getType() == 'backend' ? $_ARRAYLANG['TXT_ACCESS_CONFIRM_UNLOCK_PAGE'] : $_ARRAYLANG['TXT_ACCESS_CONFIRM_UNPROTECT_PAGE'], 'ACCESS_JAVASCRIPT_FUNCTIONS' => $this->getJavaScriptCode()));
     $this->_objTpl->parse('module_access_group_modify');
 }
 /**
  * Display the MediaBrowser button
  *
  * @global array $_ARRAYLANG
  *
  * @param string $name callback function name
  * @param string $type mediabrowser type
  *
  * @return string
  */
 public static function showMediaBrowserButton($name, $type = 'filebrowser')
 {
     if (empty($name)) {
         return;
     }
     global $_ARRAYLANG;
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => $type));
     $mediaBrowser->setCallback('setSelected' . ucfirst($name));
     return $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CALENDAR_BROWSE']);
 }
 /**
  * Mediabrowser integrated into the downloads modules.
  * 
  * @global array $_ARRAYLANG
  * @param string $view optional argument
  */
 public static function getMediaBrowserButton($id, $type = 'filebrowser')
 {
     global $_ARRAYLANG;
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setCallback('mbCallback');
     $options = array('type' => 'button', 'data-cx-mb-views' => $type);
     if (!empty($id)) {
         $options['id'] = $id;
         $options['style'] = 'display:none;';
     }
     $mediaBrowser->setOptions($options);
     return $mediaBrowser->getXHtml($_ARRAYLANG['TXT_DOWNLOADS_BROWSE']);
 }
 /**
  * Get the MediaBrowser button
  *
  * @global array $_ARRAYLANG
  * @return string
  */
 public static function getMediaBrowserButton()
 {
     global $_ARRAYLANG;
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setCallback('mbCallback');
     $mediaBrowser->setOptions(array('type' => 'button', 'id' => 'mediabrowser_button', 'style' => 'display: none;'));
     return $mediaBrowser->getXHtml($_ARRAYLANG['TXT_CORE_CM_BROWSE']);
 }
 /**
  * @todo Use param $page (to update a page without prividing an id per GET)
  */
 function _modifyAlias($array, $page = null)
 {
     global $_ARRAYLANG, $_CONFIG;
     $objCx = \ContrexxJavascript::getInstance();
     $objCx->setVariable(array('regExpUriProtocol' => \FWValidator::REGEX_URI_PROTO, 'contrexxPathOffset' => ASCMS_PATH_OFFSET, 'contrexxBaseUrl' => ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET), 'alias');
     $aliasId = !empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
     // search for existing alias
     if (!($alias = $this->_getAlias($aliasId))) {
         $alias = $this->_createTemporaryAlias();
         $aliasId = 0;
     }
     // handle form submit
     if (isset($array['alias_save'])) {
         if (!empty($array['alias_target']) && !empty($array['alias_target_protocol'])) {
             $array['alias_target'] = $array['alias_target_protocol'] . $array['alias_target'];
         }
         // set target and -type
         $newtype = preg_match('/\\[\\[' . \Cx\Core\ContentManager\Model\Entity\Page::NODE_URL_PCRE . '\\]\\](\\S*)?/ix', $array['alias_target']) ? 'local' : 'url';
         $newtarget = !empty($array['alias_target']) ? trim(contrexx_stripslashes($array['alias_target'])) : '';
         // handle existing slugs pointing to the target
         $aliases = array();
         if (!empty($array['alias_aliases']) && is_array($array['alias_aliases'])) {
             $nr = 0;
             foreach ($array['alias_aliases'] as $sourceId => $aliasSource) {
                 if (!empty($aliasSource)) {
                     $aliases[intval($sourceId)] = $aliasSource;
                 }
                 $nr++;
             }
         }
         // delete removed
         $sources = $this->_getAliasesWithSameTarget($alias);
         foreach ($sources as $sourceAlias) {
             if (!isset($aliases[$sourceAlias->getNode()->getId()])) {
                 // alias is no longer listet in POST: delete it
                 $this->_delete($sourceAlias->getNode()->getId());
             }
         }
         // handle enw slugs pointing to the target
         $newaliases = array();
         if (!empty($array['alias_aliases_new']) && is_array($array['alias_aliases_new'])) {
             foreach ($array['alias_aliases_new'] as $id => $newAliasSource) {
                 if (!empty($newAliasSource)) {
                     $newaliases[] = $newAliasSource;
                 }
             }
         }
         // save information
         if (!empty($newtarget)) {
             if (count($aliases) || count($newaliases)) {
                 $error = false;
                 if ($newtype == 'local') {
                     $placeholder = \Cx\Core\Routing\NodePlaceholder::fromPlaceholder($newtarget);
                     // when creating a new alias
                     //if (($aliasId === 0) && !$placeholder->hasLang()) {
                     // make sure language is specified in placeholder
                     $placeholder->setLang(FRONTEND_LANG_ID);
                     //}
                     // force usage of node ID
                     $newtarget = $placeholder->getPlaceholder(true);
                 }
                 foreach ($aliases as $id => $slug) {
                     if (($message = $this->_saveAlias($slug, $newtarget, $newtype == 'local', $id)) !== true) {
                         $error = true;
                         if ($message !== false) {
                             $this->arrStatusMsg['error'][] = $message;
                         } else {
                             $this->arrStatusMsg['error'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_UPDATE_FAILED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_ADD_FAILED'];
                             $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_RETRY_OPERATION'];
                         }
                         break;
                     }
                 }
                 if (!$error) {
                     foreach ($newaliases as $id => $slug) {
                         if (($message = $this->_saveAlias($slug, $newtarget, $newtype == 'local')) !== true) {
                             $error = true;
                             if ($message !== false) {
                                 $this->arrStatusMsg['error'][] = $message;
                             } else {
                                 $this->arrStatusMsg['error'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_UPDATE_FAILED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_ADD_FAILED'];
                                 $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_RETRY_OPERATION'];
                             }
                             break;
                         }
                     }
                 }
                 if (!$error) {
                     $this->arrStatusMsg['ok'][] = $aliasId ? $_ARRAYLANG['TXT_ALIAS_ALIAS_SUCCESSFULLY_UPDATED'] : $_ARRAYLANG['TXT_ALIAS_ALIAS_SUCCESSFULLY_ADDED'];
                 }
                 $_REQUEST['act'] = '';
                 // For the navigation
                 return $this->_list();
             } else {
                 $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_ONE_ALIAS_REQUIRED_MSG'];
             }
         } else {
             if ($newtype == 'local') {
                 $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_PAGE_REQUIRED_MSG'];
             } else {
                 $this->arrStatusMsg['error'][] = $_ARRAYLANG['TXT_ALIAS_URL_REQUIRED_MSG'];
             }
         }
     }
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => 'sitestructure'));
     $mediaBrowser->setCallback('aliasSetUrl');
     // prepare template
     $this->_objTpl->loadTemplateFile('module_alias_modify.html');
     $this->_pageTitle = $aliasId ? $_ARRAYLANG['TXT_ALIAS_MODIFY_ALIAS'] : $_ARRAYLANG['TXT_ALIAS_ADD_ALIAS'];
     $this->_objTpl->setVariable(array('TXT_ALIAS_TARGET_PAGE' => $_ARRAYLANG['TXT_ALIAS_TARGET_PAGE'], 'ALIAS_MEDIABROWSER_BUTTON' => $mediaBrowser->getXHtml($_ARRAYLANG['TXT_ALIAS_BROWSE']), 'TXT_ALIAS_ALIAS_ES' => $_ARRAYLANG['TXT_ALIAS_ALIAS_ES'], 'TXT_ALIAS_DELETE' => $_ARRAYLANG['TXT_ALIAS_DELETE'], 'TXT_ALIAS_CONFIRM_REMOVE_ALIAS' => $_ARRAYLANG['TXT_ALIAS_CONFIRM_REMOVE_ALIAS'], 'TXT_ALIAS_ADD_ANOTHER_ALIAS' => $_ARRAYLANG['TXT_ALIAS_ADD_ANOTHER_ALIAS'], 'TXT_ALIAS_CANCEL' => $_ARRAYLANG['TXT_ALIAS_CANCEL'], 'TXT_ALIAS_SAVE' => $_ARRAYLANG['TXT_ALIAS_SAVE'], 'TXT_ALIAS_STANDARD_RADIOBUTTON' => $_ARRAYLANG['TXT_ALIAS_STANDARD_RADIOBUTTON'], 'TXT_ALIAS_INTERNAL' => $_ARRAYLANG['TXT_INTERNAL']));
     $this->_objTpl->setGlobalVariable(array('TXT_ALIAS_DELETE' => $_ARRAYLANG['TXT_ALIAS_DELETE'], 'ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'TXT_ALIAS_STANDARD_RADIOBUTTON' => $_ARRAYLANG['TXT_ALIAS_STANDARD_RADIOBUTTON']));
     $target = $alias->getTarget();
     $targetURL = '';
     $is_local = $this->_isLocalAliasTarget($alias);
     if ($is_local) {
         // alias points to a local webpage
         $targetPage = $this->_fetchTarget($alias);
         if ($targetPage) {
             preg_match('/\\[\\[' . \Cx\Core\ContentManager\Model\Entity\Page::NODE_URL_PCRE . '\\]\\](\\S*)?/ix', $target, $matches);
             $targetURL = ASCMS_PROTOCOL . '://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . $this->_getURL($targetPage) . $matches[6];
         }
     } else {
         $targetURL = $target;
     }
     $this->_objTpl->setVariable(array('ALIAS_ID' => $aliasId, 'ALIAS_TITLE_TXT' => $this->_pageTitle, 'ALIAS_TARGET' => htmlentities($target, ENT_QUOTES, CONTREXX_CHARSET), 'ALIAS_TARGET_TEXT' => htmlentities($targetURL, ENT_QUOTES, CONTREXX_CHARSET)));
     $nr = 0;
     $sources = $this->_getAliasesWithSameTarget($alias);
     if (is_array($sources) && count($sources)) {
         foreach ($sources as $sourceAlias) {
             $url = $sourceAlias->getSlug();
             $this->_objTpl->setVariable(array('ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'ALIAS_ALIAS_ID' => $sourceAlias->getNode()->getId(), 'ALIAS_ALIAS_NR' => $nr++, 'ALIAS_ALIAS_PREFIX' => '', 'ALIAS_ALIAS_URL' => stripslashes(htmlentities($url, ENT_QUOTES, CONTREXX_CHARSET))));
             $this->_objTpl->parse('alias_list');
         }
     }
     $this->_objTpl->setVariable(array('ALIAS_DOMAIN_URL' => 'http://' . $_CONFIG['domainUrl'] . ASCMS_PATH_OFFSET . '/', 'ALIAS_ALIAS_PREFIX' => '_new'));
     $this->_objTpl->parse('alias_list');
 }
Exemple #12
0
 /**
  * Get Media Browser
  * 
  * @param object $objTpl            Template object 
  * @param string $placeholderKey    Place holder name
  * @param string $placeholderValue  Display name
  * @param array  $options           options Ex:type, id.. etc
  * @param string $callback          callback function name
  * 
  * @return null
  */
 public static function getMediaBrowserButton($options = array(), $callback = '')
 {
     global $_ARRAYLANG;
     if (empty($options)) {
         return;
     }
     // Mediabrowser
     $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
     $mediaBrowser->setOptions($options);
     if ($callback) {
         $mediaBrowser->setCallback($callback);
     }
     return $mediaBrowser->getXHtml($_ARRAYLANG['TXT_SHOP_EDIT_OR_ADD_IMAGE']);
 }
Exemple #13
0
 /**
  * Display a section of settings present in the $arrSettings class array
  *
  * See the description of {@see show()} for details.
  * @param   \Cx\Core\Html\Sigma $objTemplateLocal   The Template object,
  *                                                  by reference
  * @param   string              $section      The optional section header
  *                                            text to add
  * @param   string              $prefix       The optional prefix for
  *                                            language variables.
  *                                            Defaults to 'TXT_'
  * @return  boolean                           True on success, false otherwise
  */
 static function show_section(&$objTemplateLocal, $section = '', $prefix = 'TXT_', $readOnly = false)
 {
     global $_ARRAYLANG, $_CORELANG;
     $arrSettings = self::getCurrentSettings();
     self::verify_template($objTemplateLocal);
     // This is set to multipart if necessary
     $enctype = '';
     $i = 0;
     if ($objTemplateLocal->blockExists('core_setting_row')) {
         $objTemplateLocal->setCurrentBlock('core_setting_row');
     }
     foreach ($arrSettings as $name => $arrSetting) {
         // Determine HTML element for type and apply values and selected
         $element = '';
         $value = $arrSetting['value'];
         $values = self::splitValues($arrSetting['values']);
         $type = $arrSetting['type'];
         // Not implemented yet:
         // Warn if some mandatory value is empty
         if (empty($value) && preg_match('/_mandatory$/', $type)) {
             \Message::warning(sprintf($_CORELANG['TXT_CORE_SETTING_WARNING_EMPTY'], $_ARRAYLANG[$prefix . strtoupper($name)], $name));
         }
         // Warn if some language variable is not defined
         if (empty($_ARRAYLANG[$prefix . strtoupper($name)])) {
             \Message::warning(sprintf($_CORELANG['TXT_CORE_SETTING_WARNING_MISSING_LANGUAGE'], $prefix . strtoupper($name), $name));
         }
         //DBG::log("Value: $value -> align $value_align");
         $isMultiSelect = false;
         switch ($type) {
             //Multiselect dropdown/Dropdown menu
             case self::TYPE_DROPDOWN_MULTISELECT:
                 $isMultiSelect = true;
             case self::TYPE_DROPDOWN:
                 $matches = null;
                 $arrValues = $arrSetting['values'];
                 if (preg_match('/^\\{src:([a-z0-9_\\\\:]+)\\(\\)\\}$/i', $arrSetting['values'], $matches)) {
                     $arrValues = call_user_func($matches[1]);
                 }
                 if (is_string($arrValues)) {
                     $arrValues = self::splitValues($arrValues);
                 }
                 $elementName = $isMultiSelect ? $name . '[]' : $name;
                 $value = $isMultiSelect ? self::splitValues($value) : $value;
                 $elementValue = is_array($value) ? array_flip($value) : $value;
                 $elementAttr = $isMultiSelect ? ' multiple class="chzn-select"' : '';
                 $element = \Html::getSelect($elementName, $arrValues, $elementValue, '', '', 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;' . (!$isMultiSelect && isset($arrValues[$value]) && is_numeric($arrValues[$value]) ? 'text-align: right;' : '') . '"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : '') . $elementAttr);
                 break;
             case self::TYPE_DROPDOWN_USER_CUSTOM_ATTRIBUTE:
                 $element = \Html::getSelect($name, User_Profile_Attribute::getCustomAttributeNameArray(), $arrSetting['value'], '', '', 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : ''));
                 break;
             case self::TYPE_DROPDOWN_USERGROUP:
                 $element = \Html::getSelect($name, UserGroup::getNameArray(), $arrSetting['value'], '', '', 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : ''));
                 break;
             case self::TYPE_WYSIWYG:
                 // These must be treated differently, as wysiwyg editors
                 // claim the full width
                 if ($readOnly) {
                     // TODO: this might be dangerous! should be rewritten probably
                     $element = $value;
                 } else {
                     $element = new \Cx\Core\Wysiwyg\Wysiwyg($name, $value);
                 }
                 $objTemplateLocal->setVariable(array('CORE_SETTING_ROW' => $_ARRAYLANG[$prefix . strtoupper($name)], 'CORE_SETTING_ROWCLASS1' => ++$i % 2 ? '1' : '2'));
                 $objTemplateLocal->parseCurrentBlock();
                 $objTemplateLocal->setVariable(array('CORE_SETTING_ROW' => $element . '<br /><br />', 'CORE_SETTING_ROWCLASS1' => ++$i % 2 ? '1' : '2'));
                 $objTemplateLocal->parseCurrentBlock();
                 // Skip the part below, all is done already
                 continue 2;
             case self::TYPE_FILEUPLOAD:
                 //echo("\Cx\Core\Setting\Controller\Setting::show_section(): Setting up upload for $name, $value<br />");
                 $element = \Html::getInputFileupload($name, $value ? $name : false, Filetype::MAXIMUM_UPLOAD_FILE_SIZE, $arrSetting['values'], 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : ''), true, $value ? $value : 'media/' . (isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : 'other'));
                 // File uploads must be multipart encoded
                 $enctype = 'enctype="multipart/form-data"';
                 break;
             case self::TYPE_BUTTON:
                 // The button is only available to trigger some event.
                 $event = 'onclick=\'' . 'if (confirm("' . $_ARRAYLANG[$prefix . strtoupper($name) . '_CONFIRM'] . '")) {' . 'document.getElementById("' . $name . '").value=1;' . 'document.formSettings_' . self::$tab_index . '.submit();' . '}\'';
                 //DBG::log("\Cx\Core\Setting\Controller\Setting::show_section(): Event: $event");
                 $element = \Html::getInputButton('__' . $name, $_ARRAYLANG[strtoupper($prefix . $name) . '_LABEL'], 'button', false, $event . ($readOnly ? \Html::ATTRIBUTE_DISABLED : '')) . \Html::getHidden($name, 0, '');
                 //DBG::log("\Cx\Core\Setting\Controller\Setting::show_section(): Element: $element");
                 break;
             case self::TYPE_TEXTAREA:
                 $element = \Html::getTextarea($name, $value, 80, 8, $readOnly ? \Html::ATTRIBUTE_DISABLED : '');
                 //                        'style="width: '.self::DEFAULT_INPUT_WIDTH.'px;'.$value_align.'"');
                 break;
             case self::TYPE_CHECKBOX:
                 $arrValues = self::splitValues($arrSetting['values']);
                 $value_true = current($arrValues);
                 $element = \Html::getCheckbox($name, $value_true, false, in_array($value, $arrValues), '', $readOnly ? \Html::ATTRIBUTE_DISABLED : '');
                 break;
             case self::TYPE_CHECKBOXGROUP:
                 $checked = self::splitValues($value);
                 $element = \Html::getCheckboxGroup($name, $values, $values, $checked, '', '', '<br />', $readOnly ? \Html::ATTRIBUTE_DISABLED : '', '');
                 break;
                 // 20120508 UNTESTED!
             // 20120508 UNTESTED!
             case self::TYPE_RADIO:
                 $checked = $value;
                 $element = \Html::getRadioGroup($name, $values, $checked, '', $readOnly ? \Html::ATTRIBUTE_DISABLED : '');
                 break;
             case self::TYPE_PASSWORD:
                 $element = \Html::getInputPassword($name, $value, 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : ''));
                 break;
                 //datepicker
             //datepicker
             case self::TYPE_DATE:
                 $element = \Html::getDatepicker($name, array('defaultDate' => $value), 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"');
                 break;
                 //datetimepicker
             //datetimepicker
             case self::TYPE_DATETIME:
                 $element = \Html::getDatetimepicker($name, array('defaultDate' => $value), 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;"');
                 break;
             case self::TYPE_IMAGE:
                 $cx = \Cx\Core\Core\Controller\Cx::instanciate();
                 if (!empty($arrSetting['value']) && \Cx\Lib\FileSystem\FileSystem::exists($cx->getWebsitePath() . '/' . $arrSetting['value'])) {
                     $element .= \Html::getImageByPath($cx->getWebsitePath() . '/' . $arrSetting['value'], 'id="' . $name . 'Image" ') . '&nbsp;&nbsp;';
                 }
                 $element .= \Html::getHidden($name, $arrSetting['value'], $name);
                 $mediaBrowser = new \Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser();
                 $mediaBrowser->setCallback($name . 'Callback');
                 $mediaBrowser->setOptions(array('type' => 'button', 'data-cx-mb-views' => 'filebrowser'));
                 $element .= $mediaBrowser->getXHtml($_ARRAYLANG['TXT_BROWSE']);
                 \JS::registerCode('
                     function ' . $name . 'Callback(data) {
                         if (data.type === "file" && data.data[0]) {
                             var filePath = data.data[0].datainfo.filepath;
                             jQuery("#' . $name . '").val(filePath);
                             jQuery("#' . $name . 'Image").attr("src", filePath);
                         }
                     }
                     jQuery(document).ready(function(){
                         var imgSrc = jQuery("#' . $name . 'Image").attr("src");
                         jQuery("#' . $name . 'Image").attr("src", imgSrc + "?t=" + new Date().getTime());
                     });
                 ');
                 break;
                 // Default to text input fields
             // Default to text input fields
             case self::TYPE_TEXT:
             case self::TYPE_EMAIL:
             default:
                 $element = \Html::getInputText($name, $value, false, 'style="width: ' . self::DEFAULT_INPUT_WIDTH . 'px;' . (is_numeric($value) ? 'text-align: right;' : '') . '"' . ($readOnly ? \Html::ATTRIBUTE_DISABLED : ''));
         }
         //add Tooltip
         $toolTips = '';
         $toolTipsHelp = '';
         if (isset($_ARRAYLANG[$prefix . strtoupper($name) . '_TOOLTIP'])) {
             // generate tooltip for configuration option
             $toolTips = '  <span class="icon-info tooltip-trigger"></span><span class="tooltip-message">' . $_ARRAYLANG[$prefix . strtoupper($name) . '_TOOLTIP'] . '</span>';
         }
         if (isset($_ARRAYLANG[$prefix . strtoupper($name) . '_TOOLTIP_HELP'])) {
             // generate tooltip for configuration option
             $toolTipsHelp = '  <span class="icon-info tooltip-trigger"></span><span class="tooltip-message">' . $_ARRAYLANG[$prefix . strtoupper($name) . '_TOOLTIP_HELP'] . '</span>';
         }
         $objTemplateLocal->setVariable(array('CORE_SETTING_NAME' => (isset($_ARRAYLANG[$prefix . strtoupper($name)]) ? $_ARRAYLANG[$prefix . strtoupper($name)] : $name) . $toolTips, 'CORE_SETTING_VALUE' => $element . $toolTipsHelp, 'CORE_SETTING_ROWCLASS2' => ++$i % 2 ? '1' : '2'));
         $objTemplateLocal->parseCurrentBlock();
         //echo("\Cx\Core\Setting\Controller\Setting::show(objTemplateLocal, $prefix): shown $name => $value<br />");
     }
     // Set form encoding to multipart if necessary
     if (!empty($enctype)) {
         $objTemplateLocal->setVariable('CORE_SETTING_ENCTYPE', $enctype);
     }
     if (!empty($section) && $objTemplateLocal->blockExists('core_setting_section')) {
         //echo("\Cx\Core\Setting\Controller\Setting::show(objTemplateLocal, $header, $prefix): creating section $header<br />");
         $objTemplateLocal->setVariable(array('CORE_SETTING_SECTION' => $section));
         //$objTemplateLocal->parse('core_setting_section');
     }
     return true;
 }