/**
  * Returns the the email's subject line and will pull from the form's config file if no value is set.
  *
  * @access	protected
  * @return	string
  */
 protected function get_email_message()
 {
     $this->CI->load->helper('inflector');
     $output = '';
     $fields = $this->fields;
     $posted = $this->clean_posted();
     $posted['URL'] = site_url(uri_string());
     if (!empty($posted)) {
         if (!empty($this->email_message)) {
             $msg = $this->email_message;
             // if it's callable, then we execute it
             if (is_callable($this->email_message)) {
                 $msg = call_user_func($this->email_message, $this, $posted);
             }
             // used to escape the placeholder issues with for example the "name" property
             $msg = str_replace(array('{{', '}}'), array('{', '}'), $msg);
             $output = parse_template_syntax($msg, $posted, TRUE);
         } else {
             foreach ($posted as $key => $val) {
                 $output .= humanize($key) . ": {$val}\n";
             }
             $output = lang('forms_email_message', $this->name, $output);
         }
     }
     return $output;
 }
Example #2
0
<?php

$preview_body = parse_template_syntax(auto_typography($body));
// $vars['body'] = '<div class="preview_body">'.markdown(strip_javascript($preview_body)).'</div>';
$vars['body'] = '<div class="preview_body">' . $preview_body . '</div>';
$this->load->view('_layouts/main', $vars);
//echo $preview_body;
Example #3
0
    /**
     * Creates a a template field type... This baby has a ton of options including repeatable and sortable fields. Get's stored as JSON string
     *
     * @access	public
     * @param	array Fields parameters
     * @return	string
     */
    public function template($params, $return_fields = FALSE)
    {
        $this->CI->load->library('parser');
        $form_builder =& $params['instance'];
        if (!empty($params['module']) && empty($params['fields'])) {
            $adv_module = '';
            $module = $params['module'];
            if (is_array($module)) {
                // Advanced Module
                $adv_module = key($module);
                $module = current($module);
                $module_url = "{$adv_module}/{$module}";
            }
            $module_model = "{$module}_model";
            $this->CI->load->module_model($adv_module, $module_model);
            $module_form_fields = $this->CI->{$module_model}->form_fields();
            if (!empty($module_form_fields)) {
                $params['fields'] = $module_form_fields;
            }
            $module_data = $this->CI->{$module_model}->find_all_array(array('module_id' => $params['module_id']));
            if (!empty($module_data)) {
                $params['value'] = $module_data;
            }
        }
        $str = '';
        if (empty($params['fields']) and empty($params['view'])) {
            return $str;
        }
        // set the ID to have a placehoder that the js can handle
        $repeatable = (isset($params['repeatable']) and $params['repeatable'] === TRUE) ? TRUE : FALSE;
        $add_extra = (isset($params['add_extra']) and $params['add_extra'] === TRUE) ? TRUE : FALSE;
        $fields = array();
        $i = 0;
        if (!isset($params['depth'])) {
            $params['depth'] = 0;
        }
        // set the value
        if (is_string($params['value']) and is_json_str($params['value'])) {
            $params['value'] = json_decode($params['value'], TRUE);
        }
        // set maximum limit
        if (!isset($params['max'])) {
            $params['max'] = NULL;
        }
        // set minimum limit
        if (!isset($params['min'])) {
            $params['min'] = NULL;
        }
        if (!is_array($params['value'])) {
            $params['value'] = array();
        }
        if ($params['value'] == '') {
            $params['value'] = array();
        }
        $num = $add_extra ? count($params['value']) + 1 : count($params['value']);
        if (isset($params['min']) and $num < $params['min']) {
            $num = $params['min'];
        }
        if (!isset($params['display_sub_label'])) {
            $params['display_sub_label'] = TRUE;
        }
        if (!isset($params['removeable'])) {
            $params['removeable'] = TRUE;
        }
        if ($num == 0) {
            $num = 1;
        }
        $_f = array();
        if (empty($params['fields'])) {
            $params['fields'] = array();
        }
        for ($i = 0; $i < $num; $i++) {
            $value = isset($params['value'][$i]) ? $params['value'][$i] : $params['value'];
            foreach ($params['fields'] as $key => $field) {
                if (!empty($value[$key])) {
                    $field['value'] = $value[$key];
                } else {
                    if (empty($field['value'])) {
                        $field['value'] = '';
                    }
                }
                // Sorry... template can only be nested once... which should be all you need
                if (isset($field['type']) and $field['type'] == 'template' and $params['depth'] > 1) {
                    continue;
                }
                if (empty($field['label'])) {
                    if ($lang = $form_builder->label_lang($key)) {
                        $field['label'] = $lang;
                    } else {
                        $field['label'] = ucfirst(str_replace('_', ' ', $key));
                    }
                }
                if ($repeatable) {
                    $field_name_key = !empty($form_builder->name_array) ? 'name' : 'orig_name';
                    $index = !isset($params['index']) ? $i : $params['index'];
                    // set file name field types to not use array syntax for name so they can be processed automagically
                    // if (isset($field['type']) AND $field['type'] == 'file')
                    // {
                    // 	$field['name'] = $params[$field_name_key].'_'.$index.'_'.$key;
                    // }
                    // else
                    // {
                    // 	$field['name'] = $params[$field_name_key].'['.$index.']['.$key.']';
                    // }
                    $field['name'] = $params[$field_name_key] . '[' . $index . '][' . $key . ']';
                    // set the key to be the same of the parent... so post processing will work
                    $field['key'] = $params['key'];
                    $field['subkey'] = $key;
                    $field['depth'] = $params['depth'] + 1;
                    $depth_css_class = ' field_depth_' . $params['depth'];
                    $field['class'] = !empty($field['class']) ? $field['class'] . ' ' . $depth_css_class : $depth_css_class;
                    // set placeholders in field ids for javascript to translate... must be last occurence of the digit
                    $field['id'] = preg_replace('#([-_a-zA-Z0-9\\[\\]]+)\\[\\d+\\](\\[[-_a-zA-Z0-9]+\\])$#U', '$1[{index}]$2', $field['name']);
                    $field['id'] = $field['name'];
                    $field['id'] = Form::create_id($field['id']);
                    $field['display_label'] = $params['display_sub_label'];
                    $field['data']['orig_name'] = $params['name'];
                    $field['data']['index'] = $index;
                    $field['data']['key'] = $key;
                    $field['data']['field_name'] = $params['key'];
                    // need IDS for some plugins like CKEditor... not sure yet how to clone an element with a different ID
                    //$field['id'] = FALSE;
                    $_f[$i][$key] = $field;
                    $fields[$i][$key] = $form_builder->create_field($field);
                    $fields[$i]['__index__'] = $i;
                    $fields[$i]['__num__'] = $i + 1;
                    $fields[$i]['__title__'] = (isset($params['title_field']) and !empty($value[$params['title_field']]) and is_string($value[$params['title_field']])) ? strip_tags($value[$params['title_field']]) : '';
                } else {
                    if (!empty($form_builder->name_array)) {
                        $field['name'] = $params['name'] . '[' . $key . ']';
                    } else {
                        $field['name'] = $params['orig_name'] . '[' . $key . ']';
                    }
                    $field['display_label'] = $params['display_sub_label'];
                    $_f[$key] = $field;
                    $fields[$key] = $form_builder->create_field($field);
                }
            }
        }
        // if just return FIELDs then do it...
        if ($return_fields or !empty($params['return_fields'])) {
            return $fields;
        }
        $vars = !empty($params['vars']) ? $params['vars'] : array();
        $vars['values'] = $params['value'];
        $vars['fields_config'] = $params['fields'];
        if ($repeatable) {
            $vars['fields'] = $fields;
        } else {
            $vars = array_merge($vars, $fields);
        }
        // must set $_POST parameter below or else the post_process won't run the serialization'
        if (!isset($_POST[$params['key']])) {
            $_POST[$params['key']] = '';
        }
        if (!empty($params['serialize'])) {
            $func_str = '$CI =& get_instance();
			$val = $CI->input->post("' . $params['key'] . '");
			if (isset($_POST["' . $params['key'] . '"]) AND is_array($val))
			{
				//return serialize($val); // issues with multibyte characters
				// foreach($_POST["' . $params['key'] . '"] as $key => $val)
				// {
				// 	$CI->form_builder->post_process_field_values($val);
				// }
				return json_encode($val);
			}
			else
			{
				$_POST["' . $params['key'] . '"] = "";
				return "";
			}
			';
            $func = create_function('$value', $func_str);
            $form_builder->set_post_process($params['key'], $func);
        }
        if (empty($params['template']) and !empty($params['view'])) {
            $module = 'app';
            if (is_array($params['view'])) {
                $module = key($params['view']);
                $view = current($params['view']);
            } else {
                $view = $params['view'];
            }
            $str = $this->CI->load->module_view($module, $view, $vars, TRUE, '__TEMPLATE_FIELD__');
        } else {
            if (!empty($params['template'])) {
                $str = $params['template'];
            } else {
                $form_params['init'] = !empty($params['form_builder_params']) ? $params['form_builder_params'] : array();
                // auto fill properties from parent form builder
                $init = array('name_array', 'name_prefix');
                foreach ($init as $in) {
                    if (!isset($form_params['init'][$in])) {
                        $form_params['init'][$in] = $form_builder->{$in};
                    }
                }
                if ($repeatable) {
                    $container_class = array('repeatable_container');
                    $container_class[] = !empty($params['depth']) ? ' child' : '';
                    if (!empty($params['container_class'])) {
                        if (is_array($params['container_class'])) {
                            $container_class = $container_class + $params['container_class'];
                        } else {
                            $container_class[] = $params['container_class'];
                        }
                    }
                    $container_class[] = (!empty($params['condensed']) and $params['condensed']) ? 'repeatable_container_condensed' : '';
                    $container_class[] = (!empty($params['non_sortable']) and $params['non_sortable']) ? 'non_sortable' : '';
                    $dblclick = !empty($params['dblclick']) ? $params['dblclick'] : 0;
                    $init_display = !empty($params['init_display']) ? $params['init_display'] : '';
                    $title_field = !empty($params['title_field']) ? $params['title_field'] : '';
                    $str .= '<div class="' . implode(' ', $container_class) . '" data-depth="' . $params['depth'] . '" data-max="' . $params['max'] . '" data-min="' . $params['min'] . '" data-dblclick="' . $dblclick . '" data-init_display="' . $init_display . '" data-title_field="' . $title_field . '" data-removeable="' . $params['removeable'] . '">';
                    $i = 0;
                    foreach ($_f as $k => $f) {
                        $heading_tag = 'h3';
                        foreach ($f as $kk => $ff) {
                            if (isset($ff['type']) and $ff['type'] == 'section') {
                                if (!empty($ff['tag'])) {
                                    $heading_tag = $ff['tag'];
                                }
                                $value = $form_builder->simple_field_value($ff);
                                if (isset($params['title_field'], $f[$params['title_field']])) {
                                    if (is_array($f[$params['title_field']]['value'])) {
                                        // specific to block field types
                                        if (isset($f[$params['title_field']]['value']['block_name'])) {
                                            $header_value = $f[$params['title_field']]['value']['block_name'];
                                        } else {
                                            $header_value = current($f[$params['title_field']]['value']);
                                        }
                                    } else {
                                        $header_value = $f[$params['title_field']]['value'];
                                    }
                                    if (is_string($header_value)) {
                                        $heading = str_replace('{__title__}', $header_value, $value);
                                    }
                                } else {
                                    $heading = $value;
                                }
                                unset($f[$kk]);
                                //$f[$kk]['label'] = $heading;
                            }
                        }
                        $form_params['fields'] = $f;
                        $form_params['value'] = '';
                        if (!empty($params['value'][$k])) {
                            $form_params['value'] = $params['value'][$k];
                        }
                        $form_obj = $form_builder->create_nested($form_params, TRUE);
                        $form = $form_obj->render();
                        $css_class = $i > 0 ? ' noclone' : '';
                        if (!empty($params['float']) and $params['depth'] == 0) {
                            $css_class = ' float_left';
                        }
                        $depth_suffix = $params['depth'] > 0 ? '_' . $params['depth'] : '';
                        $style = !empty($params['style']) ? ' style="' . $params['style'] . '"' : '';
                        $str .= '<div class="repeatable' . $css_class . '" data-index="' . $i . '"' . $style . '>';
                        $sortable_class = !empty($params['non_sortable']) ? 'nonsortable' : 'grabber';
                        $str .= '<' . $heading_tag . ' class="' . $sortable_class . '" title="' . lang('tooltip_dbl_click_to_open') . '">';
                        if (!empty($heading)) {
                            $str .= '<span class="title' . $depth_suffix . '">' . $heading . '</span>';
                        }
                        $str .= '</' . $heading_tag . '>';
                        $str .= '<div class="repeatable_content">';
                        $str .= $form;
                        $str .= '</div>';
                        $str .= '</div>';
                        $i++;
                    }
                    if (empty($params['float'])) {
                        $str .= '<div class="clear"></div></div>';
                    }
                } else {
                    $form_params['fields'] = $_f;
                    $form = $form_builder->create_nested($form_params);
                    $str .= $form;
                    $str .= '</div></div>';
                }
                return $str;
            }
        }
        // parse the string
        if (!isset($params['parse']) or $params['parse'] === TRUE) {
            if ($vars['fields_config'] instanceof Base_model_fields) {
                $vars['fields_config'] = $vars['fields_config']->get_fields();
            }
            $str = parse_template_syntax($str, $vars, 'ci');
        }
        return $str;
    }
Example #4
0
 /**
  * Render the HTML output using a specified template.
  * 
  * Will provide an array of form fields that can be parsed like so {my_field}
  * 
  * @access	public
  * @param	string the name of the template view file to use
  * @param	array fields values... will overwrite anything done with the set_fields method previously
  * @return	string
  */
 public function render_template($template, $fields = NULL, $parse = TRUE)
 {
     if (!empty($fields)) {
         $this->set_fields($fields);
     }
     // reoarder
     $this->set_field_order();
     // pre process field values
     $this->pre_process_field_values();
     $this->_html = $this->html_prepend;
     $errors = NULL;
     if ($this->display_errors) {
         $func = $this->display_errors_func;
         if (function_exists($func)) {
             $errors = $func();
         }
     }
     $fields = array();
     foreach ($this->_fields as $key => $field) {
         $fields[$key]['field'] = $this->create_field($field);
         $fields[$key]['label'] = $this->create_label($field);
     }
     $vars['fields'] = $fields;
     $vars['errors'] = $errors;
     if (is_array($template)) {
         $module = key($template);
         $view = current($template);
         $str = $this->CI->load->module_view($module, $view, $vars, TRUE);
     } else {
         $str = $this->CI->load->view($template, $vars, TRUE);
     }
     if ($parse === TRUE) {
         $this->CI->load->library('parser');
         $str = parse_template_syntax($str, $vars, 'ci');
     }
     $actions = $this->_render_actions();
     if (!empty($actions)) {
         $str .= '<div class="actions">';
         $str .= $actions;
         $str .= "</div>";
     }
     $this->_html = $this->_close_form($str);
     return $this->_html;
 }
Example #5
0
 /**
  * Protected helper method that parses a template file
  *
  * @access	protected
  * @param	string	The file to parse
  * @param	array	Variables to pass to the parsed template
  * @param	string	The type of generation of model, simple, advanced (optional)
  * @return	string
  */
 protected function _parse_template($file, $vars, $type = 'advanced')
 {
     $template_path = $this->_find_template($file, $vars, $type);
     if (file_exists($template_path)) {
         $contents = file_get_contents($template_path);
         // parse
         $contents = parse_template_syntax($contents, $vars, 'ci');
         return $contents;
     }
     $this->errors[] = lang('error_could_not_create_file', $file) . "\n";
     return '';
 }