Example #1
0
    function get_form_element($element, $viewing_revision = false, $data_record = array())
    {
        $has_write_access = !$viewing_revision;
        // convert our data field to an element.
        $element['name'] = isset($element['name']) && !empty($element['name']) ? $element['name'] : 'data_field[' . $element['data_field_id'] . ']';
        $element['id'] = 'data_field_' . $element['data_field_id'] . '';
        $element['type'] = $element['field_type'];
        if (!isset($element['value'])) {
            $element['value'] = '';
        }
        if (!$has_write_access) {
            //$element['disabled'] = 'disabled';
            $element['class'] = 'data_field_view';
        }
        $highlight = false;
        $this->ajax_edit = false;
        $input_name = $element['name'];
        if (!$input_name) {
            return false;
        }
        if (isset($element['id']) && $element['id']) {
            $input_id = $element['id'];
        } else {
            $element['id'] = $input_name;
            $input_id = $input_name;
        }
        //if(!$value && isset($_REQUEST[$input_name]))$value = $_REQUEST[$input_name];
        if (!$element['value']) {
            $element['value'] = $element['default'];
        }
        if (!is_array($element['value'])) {
            //$value=htmlspecialchars($value);
        }
        if (!isset($element['class'])) {
            $element['class'] = '';
        }
        $attr = $attr_other = '';
        if ($has_write_access) {
            if ($element['type'] == 'radio' || $element['type'] == 'checkbox_list') {
                // hacky!
                if ($element['required']) {
                    $attr_other .= ' class="form_field form_field_required"';
                } else {
                    $attr_other .= ' class="form_field"';
                }
            } else {
                $element['class'] .= " form_field";
                if ($element['required']) {
                    $element['class'] .= " form_field_required";
                }
            }
            switch ($element['type']) {
                case 'date':
                    $element['class'] .= " date_field";
                    if (!isset($element['size']) || !$element['size']) {
                        $element['size'] = 8;
                    }
                    if (strtolower($element['value']) == 'now') {
                        $element['value'] = print_date(time());
                    }
                    break;
                case 'datetime':
                    $element['class'] .= " date_time_field";
                    if (!isset($element['size']) || !$element['size']) {
                        $element['size'] = 12;
                    }
                    if (strtolower($element['value']) == 'now') {
                        $element['value'] = print_date(time(), true);
                    }
                    break;
            }
        }
        switch ($element['type']) {
            case 'checkbox_list':
            case 'radio':
                $element['attributes'] = array();
                foreach (explode("\n", trim($element['field_data'])) as $line) {
                    $line = trim($line);
                    if (preg_match('/^attributes=/', $line)) {
                        $line = preg_replace('/^attributes=/', '', $line);
                        $element['attributes'] = explode("|", $line);
                        break;
                    }
                }
                break;
            case 'select':
                if (!isset($element['attributes']) || !is_array($element['attributes']) || !count($element['attributes'])) {
                    $element['attributes'] = array();
                    foreach (explode("\n", trim($element['field_data'])) as $line) {
                        $line = trim($line);
                        if (preg_match('/^attributes=/', $line)) {
                            $line = preg_replace('/^attributes=/', '', $line);
                            if (preg_match('#hook:([\\w_]+)$#', $line, $matches)) {
                                // see if we get anything back from this hook.
                                $attributes = array();
                                $attributes = hook_filter_var($matches[1], $attributes, $element);
                                if (is_array($attributes)) {
                                    $element['attributes'] = $attributes;
                                } else {
                                    $element['attributes'] = array('Unable to call hook: ' . $matches[1]);
                                }
                            } else {
                                $element['attributes'] = explode("|", $line);
                            }
                            break;
                        }
                    }
                }
                break;
        }
        if (!isset($element['style'])) {
            $element['style'] = '';
        }
        // we have to apply some custom width/height styles if they exist.
        $width = $height = false;
        foreach (explode("\n", trim($element['field_data'])) as $line) {
            $line = trim($line);
            if (preg_match('/^width=/', $line)) {
                $line = preg_replace('/^width=/', '', $line);
                $width = (int) $line;
            }
            if (preg_match('/^height=/', $line)) {
                $line = preg_replace('/^height=/', '', $line);
                $height = (int) $line;
            }
        }
        if (!$height && $height < _MIN_INPUT_HEIGHT) {
            $height = _MIN_INPUT_HEIGHT;
        }
        switch ($element['type']) {
            case 'text':
            case 'date':
            case 'datetime':
                if ($width) {
                    $element['style'] .= 'width:' . $width . 'px; ';
                }
                break;
            case 'radio':
                if ($width) {
                    $attr_other .= ' style="width:' . $width . 'px; "';
                }
                break;
            case 'textarea':
            case 'textbox':
                if ($width) {
                    $element['style'] .= 'width:' . $width . 'px; ';
                }
                if ($has_write_access && $height) {
                    $element['style'] .= 'height:' . $height . 'px; ';
                }
                break;
        }
        if (isset($element['width'])) {
            unset($element['width']);
        }
        if (isset($element['height'])) {
            unset($element['height']);
        }
        if (isset($element['multiple']) && $element['multiple']) {
            $element['multiple'] = true;
            // pass 'multiple' through to the UCM form builder which should handle everything
            $value_unserialize = @unserialize($element['value']);
            if (is_array($value_unserialize)) {
                $element['values'] = $value_unserialize;
                // 'values' is used in the UCM field generation tool
            }
            $element['name'] = $element['name'] . '[]';
        } else {
            $element['multiple'] = false;
        }
        if (!$has_write_access && $element['multiple'] && isset($element['values']) && is_array($element['values'])) {
            $element['value'] = $element['values'];
        }
        if (is_array($element['value']) && count($element['value'])) {
            $all_values = $element['value'];
        } else {
            $all_values = array($element['value']);
        }
        if ($element['type'] == 'checkbox_list') {
            $test = @unserialize($element['value']);
            if (is_array($test) && count($test)) {
                $all_values = array($test);
            } else {
                $all_values = array($element['value']);
            }
        }
        if ($element['type'] == "cancel" && !isset($element['onclick'])) {
            $element['onclick'] = "history.go(-1);";
        }
        if ($highlight) {
            $element['class'] .= " form_field_highlight";
        }
        /*if(!$has_write_access){
        			$element['class'] .= ' form_disabled';
        		}*/
        $attribute_keys = array('class', 'disabled', 'onclick', 'onfocus', 'onmouseup', 'onmousedown', 'onchange', 'size', 'cols', 'rows', 'width', 'style');
        foreach ($element as $key => $val) {
            if (!is_array($val) && !trim($val)) {
                continue;
            }
            if (in_array(strtolower($key), $attribute_keys)) {
                if (in_array(strtolower($key), array('size', 'cols', 'rows', 'width', 'height')) && (int) $val == 0) {
                    continue;
                }
                $attr .= ' ' . $key . '="' . $val . '"';
            }
        }
        // check for default values, these are cleared when submitting the form
        if ($element['default']) {
            $has_default = true;
        }
        $real_input_id = $input_id;
        $real_input_name = $input_name;
        ob_start();
        foreach ($all_values as $value_key => $value) {
            if (!$has_write_access) {
                // disabled.
                if (isset($width) && $width && $element['type'] != 'encrypted') {
                    echo '<span ' . $attr;
                    echo ' style="width:' . $width . 'px;"';
                    echo '>&nbsp;';
                }
                // display value differently depending on value type.
                switch ($element['type']) {
                    case 'checkbox_list':
                        $other = '';
                        if (is_array($value)) {
                            if (isset($value['other_val'])) {
                                $other = $value['other_val'];
                                unset($value['other_val']);
                            }
                            echo implode(', ', array_keys($value));
                        }
                        echo ' ' . $other;
                        break;
                    case 'select':
                        if (isset($element['attributes'])) {
                            $attributes = $element['attributes'];
                        } else {
                            $attributes = array();
                        }
                        if (isset($attributes[0])) {
                            $new_attributes = array();
                            foreach ($attributes as $aid => $a) {
                                $new_attributes[$aid + 1] = $a;
                            }
                            $attributes = $new_attributes;
                        }
                        if (isset($attributes[$value])) {
                            echo $attributes[$value];
                        }
                        break;
                    case 'textarea':
                    case 'textbox':
                        echo nl2br(htmlspecialchars($value));
                        break;
                    case 'file':
                        if ($value) {
                            $file_data = @unserialize($value);
                            $file_link = 'includes/plugin_data/upload/' . $file_data['file'];
                            if (is_file($file_link)) {
                                $download_link = self::link_public_file_download($data_record['data_record_id'], $data_record['data_type_id'], $element['data_field_group_id'], $element['data_field_id']);
                                echo '<a href="' . $download_link . '" target="_blank">' . $file_data['name'] . '</a>';
                            } else {
                                echo 'File Not Found';
                            }
                        }
                        break;
                    case 'wysiwyg':
                        echo module_security::purify_html($value);
                        break;
                    case 'encrypted':
                        if (class_exists('module_encrypt', false)) {
                            ob_start();
                            $element['type'] = 'text';
                            module_form::generate_form_element($element);
                            $enc_html = ob_get_clean();
                            echo module_encrypt::parse_html_input('custom_data', $enc_html, false);
                        }
                        break;
                    case 'created_date_time':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A');
                        break;
                    case 'created_date':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A');
                        break;
                    case 'created_time':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A');
                        break;
                    case 'updated_date_time':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'));
                        break;
                    case 'updated_date':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'));
                        break;
                    case 'updated_time':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'));
                        break;
                    case 'created_by':
                        echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A');
                        break;
                    case 'updated_by':
                        echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'));
                        break;
                    case 'url':
                        echo '<a href="' . htmlspecialchars($value) . '" target="_blank">' . htmlspecialchars($value) . '</a>';
                        break;
                    default:
                        echo htmlspecialchars($value);
                        break;
                }
                if (isset($width) && $width && $element['type'] != 'encrypted') {
                    echo '&nbsp;</span>';
                }
            } else {
                // update for UCM: use the ucm form generator
                if (isset($element['default']) && $element['default'] && !$element['value']) {
                    $element['value'] = $element['default'];
                }
                switch ($element['type']) {
                    case 'wysiwyg':
                        $element['options']['inline'] = false;
                        module_form::generate_form_element($element);
                        break;
                    case "radio":
                        $has_val = false;
                        foreach ($element['attributes'] as $attribute) {
                            $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute);
                            ?>

                            <span class="field_radio">
                            <input type="radio" name="<?php 
                            echo $input_name;
                            ?>
" id="<?php 
                            echo $this_input_id;
                            ?>
" value="<?php 
                            echo htmlspecialchars($attribute);
                            ?>
"<?php 
                            if ($attribute == $value || strtolower($attribute) == 'other' && !$has_val) {
                                // assumes "OTHER" is always last... fix with a separate loop before hand checking all vals
                                if (strtolower($attribute) != 'other') {
                                    $has_val = true;
                                }
                                echo " checked";
                            }
                            echo ' ' . $attr;
                            if (strtolower($attribute) == 'other') {
                                echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"';
                                echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"';
                            }
                            ?>
>
                                <label for="<?php 
                            echo $this_input_id;
                            ?>
"><?php 
                            echo $attribute;
                            ?>
</label>
                                <?php 
                            if (strtolower($attribute) == 'other') {
                                ?>

                                    <span class="data_field_input">
                                    <input type="text" name="other_<?php 
                                echo $input_name;
                                ?>
" id="other_<?php 
                                echo $this_input_id;
                                ?>
" value="<?php 
                                if (!$has_val) {
                                    echo htmlspecialchars($value);
                                }
                                ?>
" onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php 
                                echo $attr . $attr_other;
                                ?>
>
                                    </span>
                                <?php 
                            }
                            ?>

                            </span>
                            <?php 
                        }
                        break;
                    case "checkbox_list":
                        $has_val = false;
                        if (!is_array($value)) {
                            $value = array();
                        }
                        foreach ($element['attributes'] as $attribute) {
                            $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute);
                            ?>

                            <span class="field_radio">
                            <input type="checkbox" name="<?php 
                            echo $input_name;
                            ?>
[<?php 
                            echo htmlspecialchars($attribute);
                            ?>
]" id="<?php 
                            echo $this_input_id;
                            ?>
" value="1"<?php 
                            if (isset($value[$attribute])) {
                                if (strtolower($attribute) != 'other') {
                                    $has_val = true;
                                }
                                echo " checked";
                            }
                            echo ' ' . $attr;
                            if (strtolower($attribute) == 'other') {
                                echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"';
                                echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"';
                            }
                            ?>
>
                                <label for="<?php 
                            echo $this_input_id;
                            ?>
"><?php 
                            echo $attribute;
                            ?>
</label>
                                <?php 
                            if (strtolower($attribute) == 'other') {
                                ?>

                                    <span class="data_field_input">
                                        <input type="text" name="<?php 
                                echo $input_name;
                                ?>
[other_val]" id="other_<?php 
                                echo $this_input_id;
                                ?>
" value="<?php 
                                echo isset($value['other_val']) ? htmlspecialchars($value['other_val']) : '';
                                ?>
" onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php 
                                echo $attr . $attr_other;
                                ?>
>
                                    </span>
                                <?php 
                            }
                            ?>

                            </span>
                            <?php 
                        }
                        break;
                    case "file":
                        $this->has_files = true;
                        ?>

                        <input type="file" name="<?php 
                        echo $input_name;
                        ?>
" id="<?php 
                        echo $input_id;
                        ?>
" value="<?php 
                        echo $value;
                        ?>
"<?php 
                        echo $attr;
                        ?>
>
                        <?php 
                        break;
                    case 'select':
                        $attributes = isset($element['attributes']) ? $element['attributes'] : array();
                        if (isset($attributes[0])) {
                            $new_attributes = array();
                            foreach ($attributes as $aid => $a) {
                                $new_attributes[$aid + 1] = $a;
                            }
                            $attributes = $new_attributes;
                        }
                        $element['options'] = $attributes;
                        module_form::generate_form_element($element);
                        break;
                    case 'encrypted':
                        if (class_exists('module_encrypt', false)) {
                            ob_start();
                            $element['type'] = 'text';
                            module_form::generate_form_element($element);
                            $enc_html = ob_get_clean();
                            echo module_encrypt::parse_html_input('custom_data', $enc_html);
                        }
                        break;
                    case 'created_date_time':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A');
                        break;
                    case 'created_date':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A');
                        break;
                    case 'created_time':
                        echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A');
                        break;
                    case 'updated_date_time':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'));
                        break;
                    case 'updated_date':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'));
                        break;
                    case 'updated_time':
                        echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'));
                        break;
                    case 'created_by':
                        echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A');
                        break;
                    case 'updated_by':
                        echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'));
                        break;
                    case 'url':
                        $element['type'] = 'text';
                        module_form::generate_form_element($element);
                        break;
                    default:
                        module_form::generate_form_element($element);
                }
                if (isset($element['after_link']) && $element['after_link']) {
                    if (preg_match('/^https?:\\/\\//', $value) || ($have_www = preg_match('/^www\\./', $value) || ($have_www = preg_match('/\\.com/', $value) && !preg_match('/\\w@\\w/', $value)))) {
                        // we have a url
                        if ($have_www) {
                            $value = "http://" . $value;
                        }
                        ?>

						<a href="<?php 
                        echo $value;
                        ?>
" target="_blank">&raquo;</a>
						<?php 
                    }
                    if (preg_match('/\\w@\\w/', $value)) {
                        ?>

						<a href="mailto:<?php 
                        echo $value;
                        ?>
">&raquo;</a>
					<?php 
                    }
                }
            }
            // editable
            echo '&nbsp;';
        }
        // foreach all values
        //${$element_id} = ob_get_clean();
        // we just print the html for now
        return ob_get_clean();
    }
Example #2
0
    public static function generate_form_element($setting)
    {
        if (isset($setting['ignore']) && $setting['ignore']) {
            return;
        }
        // type defaults
        if ($setting['type'] == 'currency') {
            $setting['class'] = (isset($setting['class']) ? $setting['class'] . ' ' : '') . 'currency';
        }
        if ($setting['type'] == 'date') {
            $setting['class'] = (isset($setting['class']) ? $setting['class'] . ' ' : '') . 'date_field';
            $setting['type'] = 'text';
        }
        if ($setting['type'] == 'time') {
            $setting['class'] = (isset($setting['class']) ? $setting['class'] . ' ' : '') . 'time_field';
            $setting['type'] = 'text';
        }
        if ($setting['type'] == 'select' || $setting['type'] == 'wysiwyg') {
            if (!isset($setting['id']) || !$setting['id']) {
                $setting['id'] = $setting['name'];
            }
        }
        if ($setting['type'] == 'save_button') {
            $setting['type'] = 'submit';
            $setting['class'] = (isset($setting['class']) ? $setting['class'] . ' ' : '') . 'submit_button save_button';
        }
        if ($setting['type'] == 'delete_button') {
            $setting['type'] = 'submit';
            $setting['class'] = (isset($setting['class']) ? $setting['class'] . ' ' : '') . 'submit_button delete_button';
        }
        if (isset($setting['label']) && (!isset($setting['id']) || !$setting['id'])) {
            // labels need ids
            $setting['id'] = md5($setting['name']);
        }
        $attributes = '';
        foreach (array('size', 'style', 'autocomplete', 'placeholder', 'class', 'id', 'onclick') as $attr) {
            if (isset($setting[$attr])) {
                $attributes .= ' ' . $attr . '="' . $setting[$attr] . '"';
            }
        }
        if (!isset($setting['value'])) {
            $setting['value'] = '';
        }
        ob_start();
        // handle multiple options
        $loop_count = 1;
        if (isset($setting['multiple']) && $setting['multiple']) {
            // has to have at least 1 value
            if ($setting['multiple'] === true) {
                // create our wrapper id.
                $multiple_id = md5(serialize($setting));
                echo '<div id="' . $multiple_id . '">';
            } else {
                $multiple_id = $setting['multiple'];
            }
            if (!isset($setting['values'])) {
                $setting['values'] = array($setting['value']);
            }
            $loop_count = count($setting['values']);
        }
        for ($x = 0; $x < $loop_count; $x++) {
            if (isset($setting['multiple']) && $setting['multiple']) {
                $setting['value'] = isset($setting['values'][$x]) ? $setting['values'][$x] : false;
                echo '<div class="dynamic_block">';
            }
            switch ($setting['type']) {
                case 'currency':
                    echo currency('<input type="text" name="' . $setting['name'] . '" value="' . htmlspecialchars($setting['value']) . '"' . $attributes . '>', true, isset($setting['currency_id']) ? $setting['currency_id'] : false);
                    break;
                case 'number':
                    ?>

                    <input type="number" name="<?php 
                    echo $setting['name'];
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
"<?php 
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'text':
                    ?>

                    <input type="text" name="<?php 
                    echo $setting['name'];
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
"<?php 
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'password':
                    ?>

                    <input type="password" name="<?php 
                    echo $setting['name'];
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
"<?php 
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'hidden':
                    ?>

                    <input type="hidden" name="<?php 
                    echo $setting['name'];
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
"<?php 
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'textarea':
                    ?>

                    <textarea name="<?php 
                    echo $setting['name'];
                    ?>
" rows="6" cols="50"<?php 
                    echo $attributes;
                    ?>
><?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
</textarea>
                    <?php 
                    break;
                case 'wysiwyg':
                    self::load_wysiwyg();
                    ?>

                    <?php 
                    if (!isset($setting['options']) || !isset($setting['options']['inline']) || $setting['options']['inline']) {
                        ?>

	                    <div style="border:1px solid #EFEFEF;" data-name="<?php 
                        echo $setting['name'];
                        ?>
" <?php 
                        echo $attributes;
                        ?>
><?php 
                        echo module_security::purify_html($setting['value']);
                        ?>
</div>
		                <?php 
                        if ($setting['name'] != $setting['id']) {
                            ?>

		                <!-- we update this on change, needed because tinymce jquery has issues with name[] form elements -->
		                <input type="hidden" name="<?php 
                            echo $setting['name'];
                            ?>
" id="<?php 
                            echo $setting['id'];
                            ?>
_postback" value="<?php 
                            echo htmlspecialchars(module_security::purify_html($setting['value']));
                            ?>
">
		                <?php 
                        }
                        ?>

                    <?php 
                    } else {
                        ?>

                    <textarea name="<?php 
                        echo $setting['name'];
                        ?>
" rows="6" cols="50"<?php 
                        echo $attributes;
                        ?>
><?php 
                        echo htmlspecialchars($setting['value']);
                        ?>
</textarea>
                    <?php 
                    }
                    ?>


                    <script type="text/javascript">

                        $(function() {
                            $('#<?php 
                    echo $setting['id'];
                    ?>
').tinymce({
                                // Location of TinyMCE script
                                <?php 
                    if (!isset($setting['options']) || !isset($setting['options']['inline']) || $setting['options']['inline']) {
                        ?>

                                inline: true,
                                <?php 
                    }
                    ?>

                                script_url : '<?php 
                    echo _BASE_HREF;
                    ?>
includes/plugin_form/js/tinymce4.0.11/tinymce.min.js',
                                relative_urls : false,
                                convert_urls : false,
                                // General options
                                theme : "modern",
                                statusbar: false,
                                /*plugins: [
                                    "advlist autolink lists link image charmap print preview anchor",
                                    "searchreplace visualblocks code fullscreen",
                                    "insertdatetime media table contextmenu paste"
                                ],
                                toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",*/

                                plugins: [
                                    "advlist autolink autoresize link image lists charmap print preview hr anchor pagebreak",
                                    "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                                    "table directionality emoticons template textcolor paste textcolor"
                                ],

                                toolbar1: "bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | formatselect fontselect fontsizeselect",
                                toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
                                toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | visualchars visualblocks nonbreaking",

                                menubar: false,
                                toolbar_items_size: 'small',
                                width : '100%',

                                browser_spellcheck: true,
                                contextmenu: false,

                                setup : function(ed) {
                                    ed.on("init", function() {
                                        if(typeof tinymce_focus != 'undefined'){
                                            $(ed.getDoc()).contents().find('body').focus(function(){tinymce_focus();});
                                        }
                                        if(typeof tinymce_blur != 'undefined'){
                                            $(ed.getDoc()).contents().find('body').blur(function(){tinymce_blur();});
                                        }
                                    });
	                                <?php 
                    if (!isset($setting['options']) || !isset($setting['options']['inline']) || $setting['options']['inline']) {
                        if ($setting['name'] != $setting['id']) {
                            ?>

		                                ed.on("change", function() {
			                                $('#<?php 
                            echo $setting['id'];
                            ?>
_postback').val(ed.getContent());
								          });
	                                <?php 
                        }
                    }
                    ?>

                                }
                            });
                        });
                    </script>
                    <?php 
                    break;
                case 'select':
                    // copied from print_select_box()
                    if (isset($setting['allow_new']) && $setting['allow_new']) {
                        $attributes .= ' onchange="dynamic_select_box(this);"';
                    }
                    ?>

                    <select name="<?php 
                    echo $setting['name'];
                    ?>
"<?php 
                    echo $attributes;
                    ?>
>
                        <?php 
                    if (!isset($setting['blank']) || $setting['blank']) {
                        ?>

                        <option value=""><?php 
                        echo !isset($setting['blank']) || $setting['blank'] === true ? _l('- Select -') : htmlspecialchars($setting['blank']);
                        ?>
</option>
                        <?php 
                    }
                    $found_selected = false;
                    $current_val = 'Enter new value here';
                    $sel = '';
                    foreach ($setting['options'] as $key => $val) {
                        if (is_array($val)) {
                            if (!$setting['options_array_id']) {
                                if (isset($val[$setting['id']])) {
                                    $setting['options_array_id'] = $setting['id'];
                                } else {
                                    $setting['options_array_id'] = key($val);
                                }
                            }
                            $printval = $val[$setting['options_array_id']];
                        } else {
                            $printval = $val;
                        }
                        if (strlen($printval) == 0) {
                            continue;
                        }
                        $sel .= '<option value="' . htmlspecialchars($key) . '"';
                        // to handle 0 elements:
                        if ($setting['value'] !== false && $setting['value'] !== '' && $key == $setting['value']) {
                            $current_val = $printval;
                            $sel .= ' selected';
                            $found_selected = true;
                        }
                        $sel .= '>' . htmlspecialchars($printval) . '</option>';
                    }
                    if ($setting['value'] && !$found_selected) {
                        $sel .= '<option value="' . htmlspecialchars($setting['value']) . '" selected>' . htmlspecialchars($setting['value']) . '</option>';
                    }
                    if (isset($setting['allow_new']) && $setting['allow_new'] && get_display_mode() != 'mobile') {
                        $sel .= '<option value="create_new_item">' . _l(' - Create New - ') . '</option>';
                    }
                    if (isset($setting['allow_new']) && $setting['allow_new']) {
                        //$sel .= '<input type="text" name="new_'.$id.'" style="display:none;" value="'.$current_val.'">';
                    }
                    echo $sel;
                    ?>

                        <?php 
                    /*foreach($setting['options'] as $key=>$val){ ?>
                      <option value="<?php echo $key;?>"<?php echo $setting['value'] == $key ? ' selected':'' ?>><?php echo htmlspecialchars($val);?></option>
                      <?php }*/
                    ?>

                    </select>
                    <?php 
                    break;
                case 'checkbox':
                    ?>

                    <input type="hidden" name="default_<?php 
                    echo $setting['name'];
                    ?>
" value="1">
                    <input type="checkbox" name="<?php 
                    echo $setting['name'];
                    ?>
" value="1" <?php 
                    if ($setting['value']) {
                        echo ' checked';
                    }
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'check':
                    ?>

                    <input type="checkbox" name="<?php 
                    echo $setting['name'];
                    ?>
" value="<?php 
                    echo $setting['value'];
                    ?>
" <?php 
                    if ($setting['checked']) {
                        echo ' checked';
                    }
                    echo $attributes;
                    ?>
>
                    <?php 
                    break;
                case 'submit':
                    ?>

                    <input type="submit" name="<?php 
                    echo htmlspecialchars($setting['name']);
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
" <?php 
                    echo $attributes;
                    ?>
/>
                    <?php 
                    break;
                case 'button':
                    ?>

                    <input type="button" name="<?php 
                    echo htmlspecialchars($setting['name']);
                    ?>
" value="<?php 
                    echo htmlspecialchars($setting['value']);
                    ?>
" <?php 
                    echo $attributes;
                    ?>
/>
                    <?php 
                    break;
                case 'html':
                    ?>
 <div<?php 
                    echo $attributes;
                    ?>
><?php 
                    echo $setting['value'];
                    ?>
</div>
					<?php 
                    break;
            }
            if (isset($setting['multiple']) && $setting['multiple']) {
                echo '<a href="#" class="add_addit" onclick="return seladd(this);">+</a> <a href="#" class="remove_addit" onclick="return selrem(this);">-</a>';
                echo '</div>';
            }
        }
        if (isset($setting['multiple']) && $setting['multiple']) {
            if ($setting['multiple'] === true) {
                echo '</div>';
            }
            echo '<script type="text/javascript"> set_add_del("' . $multiple_id . '"); </script>';
        }
        $html = ob_get_clean();
        if (isset($setting['encrypt']) && $setting['encrypt'] && class_exists('module_encrypt', false)) {
            $html = module_encrypt::parse_html_input($setting['page_name'], $html);
        }
        echo $html;
        if (isset($setting['label']) && strlen($setting['label'])) {
            echo '<label for="' . htmlspecialchars($setting['id']) . '">' . _l($setting['label']) . '</label>';
        }
        if (isset($setting['help']) && (count($setting['help']) || strlen($setting['help']))) {
            _h($setting['help']);
        }
    }