public function display($connection, $area = 'front', $rows = array()) { $doc = \GCore\Libs\Document::getInstance(); //display header $custom_headers = array(); if (!empty(\GCore\Helpers\DataPresenter::$headers)) { foreach (\GCore\Helpers\DataPresenter::$headers as $k => $header) { $custom_headers[$k] = \GCore\Helpers\Html::container($header['tag'], $header['text'], $header['atts']); } } ob_start(); eval('?>' . $connection['Connection']['extras'][$area]['blocks']['custom']['header']); $header = ob_get_clean(); $header = $this->view->Lister->prepare($connection, $header); $header = \GCore\Libs\Str::replacer($header, $custom_headers, array('exploder' => '*')); echo $this->view->Lister->translate($connection, \GCore\Libs\Str::replacer($header, $rows)); //display rows foreach ($rows as $c_r_k => $row) { ob_start(); eval('?>' . $connection['Connection']['extras'][$area]['blocks']['custom']['body']); $body = ob_get_clean(); if (isset(\GCore\Helpers\DataPresenter::$cells_data[$c_r_k])) { $body = \GCore\Libs\Str::replacer($body, \GCore\Helpers\DataPresenter::$cells_data[$c_r_k], array('exploder' => '*')); } echo $this->view->Lister->translate($connection, \GCore\Libs\Str::replacer($body, $row)); } //display footer ob_start(); eval('?>' . $connection['Connection']['extras'][$area]['blocks']['custom']['footer']); $footer = ob_get_clean(); $footer = $this->view->Lister->prepare($connection, $footer); $footer = \GCore\Libs\Str::replacer($footer, $custom_headers, array('exploder' => '*')); echo $this->view->Lister->translate($connection, \GCore\Libs\Str::replacer($footer, $rows)); }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $message = $config->get('message', ''); echo \GCore\Libs\Str::replacer($message, $form->data, array('repeater' => 'repeater')); }
public static function trs($depth = 0) { $trs = array(); foreach (\GCore\Helpers\DataPresenter::$cells_data as $k => $column_data) { $tds = array(); $row = \GCore\Helpers\DataPresenter::$cells_rows[$k]; foreach (\GCore\Helpers\DataPresenter::$columns as $column) { $data = $column_data[$column]; $info = !empty(\GCore\Helpers\DataPresenter::$columns_info[$column]) ? \GCore\Helpers\DataPresenter::$columns_info[$column] : array(); $indent_class = ''; /*if(!empty(\GCore\Helpers\DataPresenter::$config['children']) AND \GCore\Helpers\DataPresenter::$config['indent_column'] == $column){ $indent_class = " depth-".$depth; }*/ $class = !empty($info['class']) ? \GCore\Helpers\Html::addClass($info['class'], "td-" . $column . $indent_class) : "td-" . $column . $indent_class; $tds[] = \GCore\Helpers\Html::container('td', $data, array("class" => $class, "style" => empty($info['style']) ? '' : \GCore\Helpers\Html::styles($info['style']))); } self::$count = 1 - self::$count; $row['k'] = $k; $tr_contents = \GCore\Libs\Str::replacer(implode("\n", $tds), $row, array('escape' => true)); //$tr_contents = \GCore\Helpers\DataLoader::load($tr_contents, $row); $trs[] = \GCore\Helpers\Html::container('tr', $tr_contents, array("class" => "row" . self::$count . " tr-list-" . self::$count)); //check children /*if(!empty(\GCore\Helpers\DataPresenter::$config['children'])){ $children = \GCore\Libs\Arr::getVal($row, array(\GCore\Helpers\DataPresenter::$config['model_alias'], 'children')); if(!empty($children)){ $trs = array_merge($trs, self::trs($children, $depth + 1)); } }*/ } return $trs; }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $content = $config->get('content', ''); ob_start(); eval('?>' . $content); $output = ob_get_clean(); echo \GCore\Libs\Str::replacer($output, $form->data); }
public function display($connection, $area = 'front', $rows = array()) { $doc = \GCore\Libs\Document::getInstance(); $tds = array(); $trs = array(); $ths = array(); //display header ob_start(); eval('?>' . $connection['Connection']['extras'][$area]['blocks']['table']['header']); $header = ob_get_clean(); $header = $this->view->Lister->translate($connection, $this->view->Lister->prepare($connection, $header)); echo \GCore\Libs\Str::replacer($header, $rows); $thead = \GCore\Helpers\Html::container('thead', implode("\n", $ths), array()); $tbody = \GCore\Helpers\Html::container('tbody', implode("\n", $trs), array()); if (!empty(\GCore\Helpers\DataPresenter::$columns)) { //\GCore\Helpers\DataPresenter::set_cells_data(); $trs = \GCore\Helpers\DataTable::trs(); $tbody = \GCore\Helpers\Html::container('tbody', implode("\n", $trs), array()); foreach (\GCore\Helpers\DataPresenter::$headers as $k => $header) { $th_tag = \GCore\Helpers\Html::container($header['tag'], $header['text'], $header['atts']); $ths[] = \GCore\Helpers\Html::container('th', $th_tag, array('class' => 'th-' . $k)); } $thead = \GCore\Helpers\Html::container('thead', \GCore\Helpers\Html::container('tr', implode("\n", $ths)), array()); } $table = \GCore\Helpers\Html::container('table', $thead . $tbody, array('class' => 'table table-hover table-censored', 'id' => 'gcore_table_list__#')); $table = \GCore\Helpers\DataLoader::load($table, \GCore\Helpers\DataPresenter::$cells_data); \GCore\Helpers\DataPresenter::_flush(); //show table echo $this->view->Lister->translate($connection, $table); //display footer ob_start(); eval('?>' . $connection['Connection']['extras'][$area]['blocks']['table']['footer']); $footer = ob_get_clean(); $footer = $this->view->Lister->translate($connection, $this->view->Lister->prepare($connection, $footer)); echo \GCore\Libs\Str::replacer($footer, $rows); //echo '</div>'; }
function render_field_config() { if (!empty($this->data['form_id']) and !empty($this->data['field_id'])) { $k = $this->data['field_id']; $this->Form->id = $this->data['form_id']; $this->data = $this->Form->load(); $wizard_field = $this->data['Form']['extras']['fields'][$k]; $type = isset($wizard_field['render_type']) ? $wizard_field['render_type'] : $wizard_field['type']; $class = '\\GCore\\Admin\\Extensions\\Chronoforms\\Fields\\' . \GCore\Libs\Str::camilize($type) . '\\' . \GCore\Libs\Str::camilize($type); ob_start(); $class::config($wizard_field, $k); $element_config = ob_get_clean(); $contents = str_replace('{N}', $k, $element_config); $contents = \GCore\Libs\Str::replacer($contents, \GCore\Libs\Request::raw(), array('escape' => true)); $contents = \GCore\Helpers\DataLoader::load($contents, \GCore\Libs\Request::raw()); echo $contents; } }
/* $pattern = '/<form([^>]*?)([^>]*?)>/is'; preg_match_all($pattern, $output, $matches); if(!empty($matches[0][0])){ $form_tag = $matches[0][0]; $form_tag = preg_replace('/ action=("|\')(.*?)("|\')/i', ' action="'.r_('index.php?ext=chronoconnectivity&cont=lists&ccname='.$connection['Connection']['title']).'"', $form_tag); $form_tag = preg_replace('/ name=("|\')(.*?)("|\')/i', ' name="admin_form"', $form_tag); $form_tag = preg_replace('/ id=("|\')(.*?)("|\')/i', ' id="admin_form"', $form_tag); } $output = str_replace($matches[0][0], $form_tag, $output); */ echo $output; } else { $code = $connection['Connection']['extras'][$area]['actions'][$act_name]['code']; ob_start(); eval('?>' . $code); $code = ob_get_clean(); $code = $this->Lister->prepare($connection, $code); $code = $this->Lister->translate($connection, $code); $code = \GCore\Libs\Str::replacer($code, $this->data); ?> <form action="<?php echo r_('index.php?ext=chronoconnectivity&cont=lists&ccname=' . $connection['Connection']['title']); ?> " method="post" name="admin_form" id="admin_form"> <?php echo $code; ?> </form> <?php }
function execute(&$form, $action_id) { $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array(); $config = new \GCore\Libs\Parameter($config); $doc = \GCore\Libs\Document::getInstance(); $form_id = 'chronoform-' . $form->form['Form']['title']; //$doc->_('forms'); //check fields validation /* if(!empty($form->form['Form']['extras']['fields'])){ $validations = array(); foreach($form->form['Form']['extras']['fields'] as $k => $field){ if(!empty($field['validation'])){ foreach($field['validation'] as $rule => $rule_data){ $validations[$rule][] = $field['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':'); } } if(!empty($field['inputs'])){ foreach($field['inputs'] as $fn => $field_input){ if(!empty($field_input['validation'])){ foreach($field_input['validation'] as $rule => $rule_data){ $validations[$rule][] = $field_input['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':'); } } } } } foreach($validations as $rule => &$fields){ $fields = implode("\n", $fields); } $form->execute('client_validation', array('rules' => $validations)); } */ $theme = $form->params->get('theme', 'bootstrap3'); /*if($form->params->get('theme', 'bootstrap3') == 'bootstrap3'){ $theme = 'bootstrap3'; }else if($form->params->get('theme', 'bootstrap3') == 'bootstrap3_pure'){ $theme = 'bootstrap3_pure'; }else if($form->params->get('theme', 'bootstrap3') == 'semantic1'){ $theme = 'semantic1'; }else if($form->params->get('theme', 'bootstrap3') == 'gcoreui'){ $theme = 'gcoreui'; }else if($form->params->get('theme', 'bootstrap3') == 'none'){ $theme = 'none'; }*/ $doc->theme = $theme; \GCore\Helpers\Theme::getInstance(); if ($form->params->get('tight_layout', 0)) { $doc->addCssCode(' .gbs3 .gcore-form-row{margin-bottom:5px;} .gcore-form-row .gcore-line-td{margin:0;} '); } if ($form->params->get('rtl_support', 0)) { $doc->addCssCode(' #' . $form_id . '.chronoform{direction:rtl;} '); if ($form->params->get('theme', 'bootstrap3') == 'bootstrap3') { $doc->addCssCode(' #' . $form_id . ' .gcore-label-left{ float:right !important; min-width:160px; max-width:160px; padding-left:7px; text-align:right !important; } #' . $form_id . ' .gcore-label-top{ display:block; text-align:right !important; float:none !important; width:auto !important; } #' . $form_id . ' .gcore-form-row > .gcore-label-checkbox{ float:right !important; min-width:160px; padding-right:7px; padding-top: 1px !important; text-align:right !important; } #' . $form_id . ' .gcore-subinput-container{ float:right; } #' . $form_id . ' .gcore-multiple-column .gcore-checkbox-item, .gcore-multiple-column .gcore-radio-item{ float: right; } #' . $form_id . ' .gcore-multiple-column .gcore-checkbox-item:not(:first-child), .gcore-multiple-column .gcore-radio-item:not(:first-child){ padding-right: 5px; } '); } if ($form->params->get('theme', 'bootstrap3') == 'gcoreui') { $doc->addCssCode(' #' . $form_id . ' .gcore-label-left { min-width: 150px !important; max-width: 150px !important; display: inline-block; white-space: normal; float: right !important; padding: 1px; padding-right: 10px !important; font-weight: bold; } #' . $form_id . ' .gcore-input-container { float: right; overflow: auto; display: inline-block; white-space: normal; } #' . $form_id . ' .gcore-line-tr .gcore-input{ float:right; } #' . $form_id . ' .gcore-subinput-container { margin-bottom: 3px; overflow: auto; float: right; } #' . $form_id . ' .gcore-subinput-container:not(:first-child) { padding-right: 4px; } #' . $form_id . ' .gcore-subinput-container-wide { display: inline-block; margin: 0px 3px 3px 0px; float: right; overflow: auto; } #' . $form_id . ' .gcore-radio-item, #' . $form_id . ' .gcore-checkbox-item { float: right; margin: 0px 6px 6px 0px; white-space: nowrap; } #' . $form_id . ' .gcore-single-column .gcore-radio-item, #' . $form_id . ' .gcore-single-column .gcore-checkbox-item { clear: right; } '); } } if ($form->params->get('labels_right_aligned', 0)) { $doc->addCssCode(' #' . $form_id . ' .gcore-label-left{ text-align:' . ($form->params->get('rtl_support', 0) ? 'left' : 'right') . ' !important; } '); } if ($form->params->get('labels_auto_width', 0)) { $doc->addCssCode(' #' . $form_id . ' .gcore-label-left{ min-width: 0px !important; max-width: none !important; width: auto !important; } '); } if ($form->params->get('js_validation_language', '') == '') { $lang = strtolower(\GCore\Libs\Base::getConfig('site_language')); $js_lang_tag = explode('-', $lang); $form->params->set('js_validation_language', $js_lang_tag[0]); } $events_codes = array(); //check fields events if (!empty($form->form['Form']['extras']['fields'])) { //$events_codes = array(); $pageload_events_codes = array(); //$events_codes[] = 'jQuery(document).ready(function($){'; $events_codes[] = 'function chronoforms_fields_events(){'; foreach ($form->form['Form']['extras']['fields'] as $k => $field) { if (!empty($field['id']) and !empty($field['events'])) { if ($field['type'] == 'dropdown') { $change_event = 'change'; } else { $change_event = 'click'; } $_f = '$("[name=\'' . $field['name'] . '\']").on("' . $change_event . '", function(){'; $_l = '});'; $_m = array(); foreach ($field['events'] as $k => $event_data) { if (strlen($event_data['action']) and strlen($event_data['target'])) { $_m[] = $this->create_event($field, $event_data, $form); } } if (!empty($_m)) { $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l; $pageload_events_codes[] = implode("\n", $_m); } } if (!empty($field['inputs'])) { foreach ($field['inputs'] as $fn => $field_input) { if (!empty($field_input['id']) and !empty($field_input['events'])) { if ($field_input['type'] == 'dropdown') { $change_event = 'change'; } else { $change_event = 'click'; } $_f = '$("[name=\'' . $field_input['name'] . '\']").on("' . $change_event . '", function(){'; $_l = '});'; $_m = array(); foreach ($field_input['events'] as $k => $event_data) { if (strlen($event_data['action']) and strlen($event_data['target'])) { $_m[] = $this->create_event($field_input, $event_data, $form); } } if (!empty($_m)) { $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l; $pageload_events_codes[] = implode("\n", $_m); } } } } } //check new fields events if (!empty($form->form['Form']['extras']['jsevents'])) { $jsevents_codes = array(); foreach ($form->form['Form']['extras']['jsevents'] as $k => $jsevent_info) { if (empty($jsevent_info['source'])) { continue; } //$source = $this->get_field_selector($jsevent_info['source'], $form); $target = !empty($jsevent_info['target']) ? $this->get_field_selector($jsevent_info['target'], $form) : ''; $event_trigger = $this->get_event_trigger($jsevent_info, $form); $type = $jsevent_info['type']; $jsevent_class = '\\GCore\\Admin\\Extensions\\Chronoforms\\Events\\' . \GCore\Libs\Str::camilize($type) . '\\' . \GCore\Libs\Str::camilize($type); $jsevents_codes[] = str_replace('__FUNCTION__', $jsevent_class::output($target, $jsevent_info, $form), $event_trigger); } $events_codes = array_merge($events_codes, $jsevents_codes); } $events_codes[] = '}'; $events_codes[] = 'chronoforms_fields_events();'; $events_codes[] = 'function chronoforms_pageload_fields_events(){'; $events_codes[] = implode("\n", $pageload_events_codes); $events_codes[] = '}'; $events_codes[] = 'chronoforms_pageload_fields_events();'; //$form->execute('js', array('content' => implode("\n", $events_codes))); } ob_start(); eval('?>' . $form->form['Form']['content']); $output = ob_get_clean(); $form_content = $output; //select the page to display $form_pages = explode('<!--_CHRONOFORMS_PAGE_BREAK_-->', $output); $active_page_index = (int) $config->get('page', 1) - 1; $output = $form_pages[$active_page_index]; //get current url $current_url = \GCore\Libs\Url::current(); if ((bool) $config->get('relative_url', 1) === false) { $current_url = r_('index.php?ext=chronoforms'); } //generate <form tag $form_tag = '<form'; $form_action = strlen($config->get('action_url', '')) > 0 ? $config->get('action_url', '') : \GCore\Libs\Url::buildQuery($current_url, array('chronoform' => $form->form['Form']['title'], 'event' => $config->get('submit_event', 'submit'))); $form_tag .= ' action="' . r_($form_action, (bool) $config->get('xhtml_url', 0)) . '"'; //get method $form_method = $config->get('form_method', 'post'); if ($config->get('form_method', 'post') == 'file') { $form_tag .= ' enctype="multipart/form-data"'; $form_method = 'post'; } $form_tag .= ' method="' . $form_method . '"'; $form_tag .= ' name="' . $form->form['Form']['title'] . '"'; //$form_id = 'chronoform-'.$form->form['Form']['title']; $form_tag .= ' id="' . $form_id . '"'; $form_tag .= ' class="' . $config->get('form_class', 'chronoform') . ($theme == 'bootstrap3' ? ' form-horizontal' : '') . '"'; if ($config->get('form_tag_attach', '')) { $form_tag .= ' ' . trim($config->get('form_tag_attach', '')); } $form_tag .= '>'; if (empty($theme)) { $doc->_('forms'); } /* if($theme == 'bootstrap3'){ $doc->_('jquery'); $doc->_('bootstrap'); //echo '<div class="gcore chronoform-container">'; } */ $js_scripts = array(); if (strpos($output, 'data-wysiwyg="1"') !== false) { $doc->_('jquery'); $doc->_('editor'); $js_scripts[] = '$(\'*[data-wysiwyg="1"]\').each(function(){ tinymce.init({"selector":"#"+$(this).attr("id")}); });'; } if (strpos($form_content, 'validate[') !== false) { $doc->_('jquery'); $doc->_('gtooltip'); $doc->_('gvalidation', array('lang' => $form->params->get('js_validation_language', 'en'))); $js_scripts[] = '$("#' . $form_id . '").gvalidate();'; $js_scripts[] = ' $("#' . $form_id . '").find(":input").on("invalid.gvalidation", function(){ var field = $(this); if(field.is(":hidden")){ if(field.closest(".tab-pane").length > 0){ var tab_id = field.closest(".tab-pane").attr("id"); $(\'a[href="#\'+tab_id+\'"]\').closest(".nav").gtabs("get").show($(\'a[href="#\'+tab_id+\'"]\')); } if(field.closest(".panel-collapse").length > 0){ var slider_id = field.closest(".panel-collapse").attr("id"); $(\'a[href="#\'+slider_id+\'"]\').closest(".panel-group").gsliders("get").show($(\'a[href="#\'+slider_id+\'"]\')); } } if(field.data("wysiwyg") == "1"){ field.data("gvalidation-target", field.parent()); } }); $("#' . $form_id . '").on("success.gvalidation", function(e){ if($("#' . $form_id . '").data("gvalidate_success")){ var gvalidate_success = $("#' . $form_id . '").data("gvalidate_success"); if(gvalidate_success in window){ window[gvalidate_success](e, $("#' . $form_id . '")); } } }); $("#' . $form_id . '").on("fail.gvalidation", function(e){ if($("#' . $form_id . '").data("gvalidate_fail")){ var gvalidate_fail = $("#' . $form_id . '").data("gvalidate_fail"); if(gvalidate_fail in window){ window[gvalidate_fail](e, $("#' . $form_id . '")); } } }); '; if ($config->get('required_labels_identify', 1)) { if (strpos($form->params->get('theme', 'bootstrap3'), 'bootstrap3') !== false) { $required_icon = '<i class=\'fa fa-asterisk\' style=\'color:#ff0000; font-size:9px; vertical-align:top;\'></i>'; } else { $required_icon = '<span style=\'color:#ff0000; font-size:12px; vertical-align:top;\'>*</span>'; } $js_scripts[] = ' function chronoforms_validation_signs(formObj){ formObj.find(":input[class*=validate]").each(function(){ if($(this).attr("class").indexOf("required") >= 0 || $(this).attr("class").indexOf("group") >= 0){ var required_parent = []; if($(this).closest(".gcore-subinput-container").length > 0){ var required_parent = $(this).closest(".gcore-subinput-container"); }else if($(this).closest(".gcore-form-row, .form-group").length > 0){ var required_parent = $(this).closest(".gcore-form-row, .form-group"); } if(required_parent.length > 0){ var required_label = required_parent.find("label"); if(required_label.length > 0 && !required_label.first().hasClass("required_label")){ required_label.first().addClass("required_label"); required_label.first().html(required_label.first().html() + " ' . $required_icon . '"); } } } }); } chronoforms_validation_signs($("#chronoform-' . $form->form['Form']['title'] . '")); '; } } if (strpos($form_content, 'data-tooltip') !== false) { $doc->_('jquery'); $doc->_('gtooltip'); if (strpos($form->params->get('theme', 'bootstrap3'), 'bootstrap3') !== false) { $tip_icon = '<i class=\'fa fa-exclamation-circle input-tooltip\' style=\'color:#2693FF; padding-left:5px;\'></i>'; } else { $tip_icon = '<span style=\'color:#ff0000; font-size:12px; vertical-align:top;\'>!</span>'; } $js_scripts[] = ' function chronoforms_data_tooltip(formObj){ formObj.find(":input").each(function(){ if($(this).data("tooltip") && $(this).closest(".gcore-input, .gcore-input-wide").length > 0){ var tipped_parent = []; if($(this).closest(".gcore-subinput-container").length > 0){ var tipped_parent = $(this).closest(".gcore-subinput-container"); }else if($(this).closest(".gcore-form-row, .form-group").length > 0){ var tipped_parent = $(this).closest(".gcore-form-row, .form-group"); } if(tipped_parent.length > 0){ var tipped_label = tipped_parent.find("label"); if(tipped_label.length > 0 && !tipped_label.first().hasClass("tipped_label")){ tipped_label.first().addClass("tipped_label"); var $tip = $("' . $tip_icon . '"); $tip.data("content", $(this).data("tooltip")); tipped_label.first().append($tip); } } } }); formObj.find(".input-tooltip").gtooltip(); } chronoforms_data_tooltip($("#chronoform-' . $form->form['Form']['title'] . '")); '; } if (strpos($form_content, 'data-load-state') !== false) { $doc->_('jquery'); $js_scripts[] = ' function chronoforms_data_loadstate(formObj){ formObj.find(\':input[data-load-state="disabled"]\').prop("disabled", true); formObj.find(\'*[data-load-state="hidden"]\').css("display", "none"); formObj.find(\':input[data-load-state="hidden_parent"]\').each(function(){ if($(this).closest(".gcore-subinput-container").length > 0){ $(this).closest(".gcore-subinput-container").css("display", "none"); }else if($(this).closest(".gcore-form-row").length > 0){ $(this).closest(".gcore-form-row").css("display", "none"); } }); } chronoforms_data_loadstate($("#chronoform-' . $form->form['Form']['title'] . '")); '; } if (strpos($output, 'data-inputmask=') !== false) { $doc->_('jquery'); $doc->_('jquery.inputmask'); $js_scripts[] = '$(":input").inputmask();'; } if (strpos($output, 'data-gdatetimepicker') !== false or strpos($output, 'data-fieldtype="gdatetimepicker"') !== false) { $doc->_('jquery'); $doc->_('gdatetimepicker'); $js_scripts[] = ' $(\'*[data-gdatetimepicker-format]\').each(function(){ $(this).data("format", $(this).data("gdatetimepicker-format")); }); '; //for old data attributes $js_scripts[] = '$(\'*[data-gdatetimepicker="1"]\').gdatetimepicker();'; //for old data attributes $js_scripts[] = '$(\'*[data-fieldtype="gdatetimepicker"]\').gdatetimepicker();'; $js_scripts[] = ' $(":input").on("select_date.gdatetimepicker", function(){ if($(this).data("on_date_selected")){ var on_date_selected = $(this).data("on_date_selected"); if(on_date_selected in window){ window[on_date_selected]($(this)); } } }); '; } if (strpos($output, 'multiplier-container') !== false) { $doc->_('jquery'); $js_scripts[] = ' $(".multiplier-container").each(function(){ if(typeof($(this).data("hide_first")) != "undefined"){ $(this).find(".multiplier-contents").first().hide(); } if(typeof($(this).data("disable_first")) != "undefined"){ $(this).find(".multiplier-contents").first().find(":input").prop("disabled", true); } if($(this).find(".multiplier-contents").length > 1){ var counter = $(this).find(".multiplier-contents").length; $(this).data("count", counter); } }); $(".multiplier-container").find(".multiplier-add-button").on("click", function(){ var multiplier_container = $(this).closest(".multiplier-container"); var multiplier_clone = multiplier_container.find(".multiplier-contents").first().clone(); multiplier_clone.find(".multiplier-remove-button").first().css("display", ""); multiplier_clone.show(); multiplier_clone.find(":input").prop("disabled", false); if(typeof(multiplier_container.data("replacer")) != "undefined"){ var counter = parseInt(multiplier_container.data("count")); var multiplier_clone = multiplier_clone.wrap("<p>").parent().html().replace(new RegExp(multiplier_container.data("replacer"), "g"), counter); multiplier_container.data("count", counter + 1); } multiplier_container.find(".multiplier-contents").last().after(multiplier_clone); }); $(document).on("click", ".multiplier-remove-button", function(){ $(this).closest(".multiplier-contents").remove(); }); '; } if ((bool) $config->get('ajax_submit', 0) === true) { $doc->_('jquery'); $doc->_('gtooltip'); $doc->_('gvalidation', array('lang' => $form->params->get('js_validation_language', 'en'))); $ajax_url = \GCore\Libs\Url::buildQuery($form_action, array('tvout' => 'ajax')); $js_scripts[] = ' function chrono_ajax_submit(){ $(document).on("click", "#' . $form_id . ' :input[type=submit]", function(event){ $("#' . $form_id . '").append("<input type=\'hidden\' name=\'"+$(this).attr("name")+"\' value=\'"+$(this).val()+"\' />"); }); var files; $("input[type=file]").on("change", function(event){ files = event.target.files; }); $(document).on("submit", "#' . $form_id . '", function(event){ var overlay = $("<div/>").css({ "position": "fixed", "top": "0", "left": "0", "width": "100%", "height": "100%", "background-color": "#000", "filter": "alpha(opacity=50)", "-moz-opacity": "0.5", "-khtml-opacity": "0.5", "opacity": "0.5", "z-index": "10000", "background-image":"url(\\"' . \GCore\Helpers\Assets::image('loading-small.gif') . '\\")", "background-position":"center center", "background-repeat":"no-repeat", }); if(!$("#' . $form_id . '").hasClass("form-overlayed")){ $("#' . $form_id . '").append(overlay); $("#' . $form_id . '").addClass("form-overlayed"); } var form_action = $("#' . $form_id . '").prop("action"); var sep = (form_action.indexOf("?") > -1) ? "&" : "?"; var ajax_url = form_action + sep + "tvout=ajax"; //data processing $.ajax({ "type" : "POST", "url" : ajax_url, "data" : $("#' . $form_id . '").serialize(), "success" : function(res){ $("#' . $form_id . '").replaceWith(res); $("#' . $form_id . '").gvalidate(); chronoforms_fields_events(); chronoforms_validation_signs($("#' . $form_id . '")); chronoforms_data_tooltip($("#' . $form_id . '")); chronoforms_data_loadstate($("#' . $form_id . '")); if(typeof chronoforms_pageload_fields_events == "function"){ chronoforms_pageload_fields_events(); } //chrono_ajax_submit();//this line duplicates submissions, should be removed }, }); return false; }); } chrono_ajax_submit(); '; } $js_scripts[] = implode("\n", $events_codes); if (!empty($js_scripts)) { $doc->addJsCode('jQuery(document).ready(function($){ ' . implode("\n", $js_scripts) . ' });'); } if ((bool) $config->get('add_form_tags', 1) === true) { echo $form_tag; } //if ajax then display system messages inside the form if ((bool) $config->get('ajax_submit', 0) === true) { $doc = \GCore\Libs\Document::getInstance(); $doc->addCssFile('system_messages'); $session = \GCore\Libs\Base::getSession(); $types = $session->getFlash(); echo \GCore\Helpers\Message::render($types); } //add fields values $output = \GCore\Helpers\DataLoader::load($output, $form->data); $output = \GCore\Libs\Str::replacer($output, $form->data, array('repeater' => 'repeater')); //show output echo $output; if ((bool) $config->get('add_form_tags', 1) === true) { echo '</form>'; } }
function processUpload(&$form, $file_post = array(), $field_name, $file_extensions) { //check valid file if (!\GCore\Libs\Upload::valid($file_post)) { return false; } //check not empty file upload if (!\GCore\Libs\Upload::not_empty($file_post)) { return false; } //check errors if (!isset($file_post['tmp_name']) or !is_uploaded_file($file_post['tmp_name'])) { if (!empty($file_post['error']) and $file_post['error'] !== UPLOAD_ERR_OK) { $form->debug[$this->action_id][self::$title][] = 'PHP returned this error for file upload by : ' . $field_name . ', PHP error is: ' . $file_post['error']; $form->errors[$field_name] = $file_post['error']; } $this->events['fail'] = 1; return false; } else { $form->debug[$this->action_id][self::$title][] = 'Upload routine started for file upload by : ' . $field_name; } if ((bool) $this->config->get('safe_file_name', 1) === true) { $file_name = \GCore\Libs\File::makeSafe($file_post['name']); } else { $file_name = utf8_decode($file_post['name']); } $real_file_name = $file_name; $file_tmp_name = $file_post['tmp_name']; $file_info = pathinfo($file_name); //mask the file name if (strlen($this->config->get('forced_file_name', '')) > 0) { // acrescentando replacer, permitindo nomes de arquivo com // dados do formulario, no seguinte formato: // [forced_file_name]_campo.extensão $temp_file_name = \GCore\Libs\Str::replacer($this->config->get('forced_file_name', ''), $form->data) . "_" . $field_name . "." . strtolower($file_info['extension']); $file_name = str_replace('FILE_NAME', $file_name, $temp_file_name); if ($this->config->get('prepend_date', 1)) { $datefmt = $this->config->get('prepend_date_format', 'YmdHis'); $temp_file_name = date($datefmt) . '_' . $temp_file_name; } } else { if ($this->config->get('prepend_date', 1)) { $datefmt = $this->config->get('prepend_date_format', 'YmdHis'); $temp_file_name = date($datefmt) . '_' . $temp_file_name; } } //check the file size if ($file_tmp_name) { //check max size if ($file_post['error'] === UPLOAD_ERR_INI_SIZE) { $form->debug[$this->action_id][self::$title][] = 'File : ' . $field_name . ' size is over the max PHP configured limit.'; $form->errors[$field_name] = $this->config->get('max_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) exceeds the allowed limit.'); $this->events['fail'] = 1; return false; } elseif ($file_post["size"] / 1024 > (int) $this->config->get('max_size', 100)) { $form->debug[$this->action_id][self::$title][] = 'File : ' . $field_name . ' size is over the max limit.'; $form->errors[$field_name] = $this->config->get('max_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) exceeds the allowed limit.'); $this->events['fail'] = 1; return false; } elseif ($file_post["size"] / 1024 < (int) $this->config->get('min_size', 0)) { $form->debug[$this->action_id][self::$title][] = 'File : ' . $field_name . ' size is less than the minimum limit.'; $form->errors[$field_name] = $this->config->get('min_error', 'Sorry, Your uploaded file size (' . $file_post["size"] / 1024 . ' KB) is less than the minimum limit.'); $this->events['fail'] = 1; return false; } elseif (!in_array(strtolower($file_info['extension']), $file_extensions)) { $form->debug[$this->action_id][self::$title][] = 'File : ' . $field_name . ' extension is not allowed.'; $form->errors[$field_name] = $this->config->get('type_error', 'Sorry, Your uploaded file type is not allowed.'); $this->events['fail'] = 1; return false; } else { $uploaded_file = \GCore\Libs\Upload::save($file_tmp_name, $this->upload_path . $file_name); if ($uploaded_file) { $uploaded_file_data = array(); $uploaded_file_data = array('name' => $file_name, 'original_name' => $real_file_name, 'path' => $this->upload_path . $file_name, 'size' => $file_post["size"]); //Try to generate an auto file link $site_link = \GCore\C::get('GCORE_FRONT_URL'); if (substr($site_link, -1) == "/") { $site_link = substr_replace($site_link, '', -1); } $uploaded_file_data['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $this->upload_path . $file_name); //$form->data[$field_name] = $file_name; $form->debug[$this->action_id][self::$title][] = $this->upload_path . $file_name . ' has been uploaded successfully.'; $this->events['success'] = 1; return $uploaded_file_data; } else { $form->debug[$this->action_id][self::$title][] = $this->upload_path . $file_name . ' could not be uploaded!!'; $this->events['fail'] = 1; return false; } } } }
function execute(&$form, $action_id){ $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $content = $config->get('content', ""); ob_start(); eval('?>'.$content); $output = ob_get_clean(); //if the content box was empty, display the form output if(empty($output)){ $output = $form->form_output; } $output = \GCore\Libs\Str::replacer($output, $form->data); //begin tcpdf code require_once('tcpdf/config/lang/eng.php'); require_once('tcpdf/tcpdf.php'); // create new PDF document $pdf = new \TCPDF($config->get('pdf_page_orientation', 'P'), PDF_UNIT, $config->get('pdf_page_format', 'A4'), true, 'UTF-8', false); //set protection if enabled if((bool)$config->get('enable_protection', 0) === true){ $owner_pass = ($config->get('owner_pass', "") ? $config->get('owner_pass', "") : null); $perms = (strlen($config->get('permissions', "")) > 0) ? explode(",", $config->get('permissions', "")) : array(); $pdf->SetProtection($perms, $config->get('user_pass', ""), $owner_pass, $config->get('sec_mode', ""), $pubkeys=null); } // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor($config->get('pdf_author', 'PDF Author.')); $pdf->SetTitle($config->get('pdf_title', 'PDF Title Goes Here.')); $pdf->SetSubject($config->get('pdf_subject', 'Powered by Chronoforms + TCPDF')); $pdf->SetKeywords($config->get('pdf_keywords', 'Chronoforms, PDF Plugin, TCPDF, PDF, '.$form->form['Form']['title'])); // Willian // set header data, font and margins if((bool)$config->get((bool)$config->get('pdf_header_show', 1))){ if(strlen($config->get('pdf_title')) OR strlen($config->get('pdf_header'))){ $pdf->SetHeaderData(false, 0, $config->get('pdf_title', 'PDF Title Goes Here.'), $config->get('pdf_header', 'Powered by Chronoforms + TCPDF')); } $pdf->setHeaderFont(Array($config->get('pdf_header_font', 'helvetica'), '', (int)$config->get('pdf_header_font_size', 10))); $pdf->SetHeaderMargin($config->get('pdf_margin_header', 5)); $pdf->setPrintHeader(true); } else { $pdf->setPrintHeader(false); } // set footer font and margins if((bool)$config->get((bool)$config->get('pdf_footer_show', 1))){ $pdf->setFooterFont(Array($config->get('pdf_footer_font', 'helvetica'), '', (int)$config->get('pdf_footer_font_size', 8))); $pdf->SetFooterMargin($config->get('pdf_margin_footer', 10)); $pdf->setPrintFooter(true); } else { $pdf->setPrintFooter(false); } // set default monospaced font $pdf->SetDefaultMonospacedFont($config->get('pdf_monospaced_font', 'courier')); //set margins $pdf->SetMargins($config->get('pdf_margin_left', 15), $config->get('pdf_margin_top', 27), $config->get('pdf_margin_right', 15)); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, $config->get('pdf_margin_bottom', 25)); //set image scale factor $pdf->setImageScale($config->get('pdf_image_scale_ratio', 1.25)); //set some language-dependent strings $pdf->setLanguageArray($l); // Willian // Mostrar/Esconder Cabeçalho $pdf->setPrintHeader((bool)$config->get('pdf_header_show', 1)); // Mostrar/Esconder Rodapé $pdf->setPrintHeader((bool)$config->get('pdf_footer_show', 1)); // --------------------------------------------------------- // set font $pdf->SetFont($config->get('pdf_body_font', 'courier'), '', (int)$config->get('pdf_body_font_size', 14)); // add a page $pdf->AddPage(); // create some HTML content $css = ""; $output = $css.$output; $html = $output; // output the HTML content $pdf->writeHTML($html, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); //Close and output PDF document if(isset($form->data['pdf_file_name']) && !empty($form->data['pdf_file_name'])){ $PDF_file_name = $form->data['pdf_file_name']; }else{ if(strlen(trim($config->get('pdf_file_name', ''))) > 0){ $PDF_file_name = trim($config->get('pdf_file_name', ''))."_".date('YmdHis'); }else{ $PDF_file_name = $form->form['Form']['title']."_".date('YmdHis'); } } $PDF_view = $config->get('pdf_view', 'I'); if(($PDF_view == 'F') || ($PDF_view == 'FI') || ($PDF_view == 'FD')){ jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $upload_path = $config->get('pdf_save_path'); if(!empty($upload_path)){ $upload_path = str_replace(array("/", "\\"), DS, $upload_path); if(substr($upload_path, -1) == DS){ $upload_path = substr_replace($upload_path, '', -1); } $upload_path = $upload_path.DS; $config->set('pdf_save_path', $upload_path); }else{ $upload_path = \GCore\C::ext_path('chronoforms', 'front').'pdfs'.DS.$form->form['Form']['title'].DS; } //check the save files path is ok if(!file_exists($upload_path.DS.'index.html')){ if(!\GCore\Libs\Folder::create($upload_path)){ $form->errors[] = "Couldn't create upload directory: ".$upload_path; $this->events['fail'] = 1; return; } $dummy_c = '<html><body bgcolor="#ffffff"></body></html>'; if(!\GCore\Libs\File::write($upload_path.DS.'index.html', $dummy_c)){ $form->errors[] = "Couldn't create upload directory index file."; $this->events['fail'] = 1; return; } } $PDF_file_path = $upload_path.$PDF_file_name.".pdf"; $pdf->Output($PDF_file_path, $PDF_view); //Try to generate an auto file link $site_link = \GCore\C::get('GCORE_FRONT_URL'); if(substr($site_link, -1) == "/"){ $site_link = substr_replace($site_link, '', -1); } if(strlen(trim($config->get('pdf_post_name', ''))) > 0){ $form->files[trim($config->get('pdf_post_name', ''))] = array('name' => $PDF_file_name.".pdf", 'path' => $PDF_file_path, 'size' => 0); $form->files[trim($config->get('pdf_post_name', ''))]['link'] = str_replace(array(\GCore\C::get('GCORE_FRONT_PATH'), DS), array($site_link, "/"), $upload_path.$PDF_file_name.".pdf"); $form->data[trim($config->get('pdf_post_name', ''))] = $PDF_file_name.".pdf"; $form->debug[$action_id][self::$title][] = $PDF_file_path.' has been saved correctly.'; } }else{ $pdf->Output($PDF_file_name.".pdf", $PDF_view); } if($PDF_view != 'F'){ @flush(); @ob_flush(); exit; } }
function field_replacer($data, $action_id) { $htmlcode = $data['content']; $email_template_header = trim($data['extras']['actions_config'][$action_id]['template_header']) ? $data['extras']['actions_config'][$action_id]['template_header'] : '<table>'; $email_template_body = trim($data['extras']['actions_config'][$action_id]['template_body']) ? $data['extras']['actions_config'][$action_id]['template_body'] : '<tr><td>{label}</td><td>{{name}}</td></tr>' . "\n"; $email_template_footer = trim($data['extras']['actions_config'][$action_id]['template_footer']) ? $data['extras']['actions_config'][$action_id]['template_footer'] : '</table>'; if (!empty($data['form_type'])) { $html_string = $email_template_header; $html_string .= "\n"; foreach ($data['extras']['fields'] as $k => $field) { if (!in_array($field['type'], array('button', 'submit', 'reset', 'captcha', 'multi', 'container'))) { $field['label'] = isset($field['label']['text']) ? $field['label']['text'] : $field['label']; $field['name'] = implode('.', explode('[', str_replace(']', '', str_replace('[]', '', $field['name'])))); /*$html_string .= '<tr>'; $html_string .= '<td>'.(!empty($field['label']['text']) ? $field['label']['text'] : $field['label']).'</td>'; $html_string .= '<td>{'.str_replace('[]', '', $field['name']).'}</td>'; $html_string .= '</tr>'; $html_string .= "\n";*/ $html_string .= \GCore\Libs\Str::replacer($email_template_body, $field); } if (!empty($field['inputs'])) { foreach ($field['inputs'] as $fn => $field_input) { if (!in_array($field_input['type'], array('button', 'submit', 'reset', 'captcha', 'multi'))) { $field_input['label'] = isset($field_input['label']['text']) ? $field_input['label']['text'] : $field_input['label']; $field_input['name'] = implode('.', explode('[', str_replace(']', '', str_replace('[]', '', $field_input['name'])))); /*$html_string .= '<tr>'; $html_string .= '<td>'.(!empty($field_input['label']['text']) ? $field_input['label']['text'] : $field_input['label']).'</td>'; $html_string .= '<td>{'.str_replace('[]', '', $field_input['name']).'}</td>'; $html_string .= '</tr>'; $html_string .= "\n";*/ $html_string .= \GCore\Libs\Str::replacer($email_template_body, $field_input); } } } } $html_string .= $email_template_footer; return $html_string; } //find any style code in the email template and get it here preg_match_all('/<style(.*?)<\\/style>/is', $htmlcode, $style_matches); if (isset($style_matches[0]) && !empty($style_matches[0])) { foreach ($style_matches[0] as $style_code) { $htmlcode = str_replace($style_code, '', $htmlcode); } } //ob_start(); /*eval( "?>".$htmlcode);*/ $html_string = $htmlcode; //ob_get_clean(); $usednames = array(); //end fields names //text fields $pattern_input = '/<input([^>]*?)type=("|\')(text|password|hidden|file)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (isset($matches_name[2]) && trim(str_replace('[]', '', $matches_name[2]))) { $email_data_name = "{" . str_replace('[]', '', $matches_name[2]) . "}"; $email_data_name = str_replace(array('[', ']'), array('.', ''), $email_data_name); if (!in_array($email_data_name, $usednames)) { $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; } else { $html_string = str_replace($match, "", $html_string); } } else { //$html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); $html_string = str_replace($match, "", $html_string); } } //buttons $pattern_input = '/<input([^>]*?)type=("|\')(submit|button|reset|image)("|\')([^>]*?)>/is'; $matches = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (isset($matches_name[2]) && trim(str_replace('[]', '', $matches_name[2]))) { $email_data_name = ""; if (!in_array($email_data_name, $usednames)) { $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; } else { $html_string = str_replace($match, "", $html_string); } } else { //$html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); $html_string = str_replace($match, "", $html_string); } } //checkboxes or radios fields $pattern_input = '/<input([^>]*?)type=("|\')(checkbox|radio)("|\')([^>]*?)>/is'; $matches = array(); $check_radio_idslist = array(); preg_match_all($pattern_input, $html_string, $matches); foreach ($matches[0] as $match) { $pattern_id = '/id=("|\')([^(>|"|\')]*?)("|\')/i'; $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); preg_match($pattern_id, $match, $matches_id); if (isset($matches_name[2]) && trim(str_replace('[]', '', $matches_name[2]))) { $check_radio_idslist[] = $matches_id[2]; $email_data_name = "{" . str_replace('[]', '', $matches_name[2]) . "}"; $email_data_name = str_replace(array('[', ']'), array('.', ''), $email_data_name); if (!in_array($email_data_name, $usednames)) { $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; } else { $html_string = str_replace($match, "", $html_string); } } else { //$html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); $html_string = str_replace($match, "", $html_string); } } //radios-checks labels $pattern_label = '/<label([^>]*?)for=("|\')(' . implode("|", $check_radio_idslist) . ')("|\')([^>]*?)>(.*?)<\\/label>/is'; $matches = array(); preg_match_all($pattern_label, $html_string, $matches); foreach ($matches[0] as $match) { $html_string = str_replace($match, "", $html_string); } //textarea fields $pattern_textarea = '/<textarea([^>]*?)>(.*?)<\\/textarea>/is'; $matches = array(); preg_match_all($pattern_textarea, $html_string, $matches); $namematch = ''; foreach ($matches[0] as $match) { $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $match, $matches_name); if (isset($matches_name[2]) && trim(str_replace('[]', '', $matches_name[2]))) { $email_data_name = "{" . str_replace('[]', '', $matches_name[2]) . "}"; $email_data_name = str_replace(array('[', ']'), array('.', ''), $email_data_name); if (!in_array($email_data_name, $usednames)) { $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; } else { $html_string = str_replace($match, "", $html_string); } } else { //$html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); $html_string = str_replace($match, "", $html_string); } } //select boxes $pattern_select = '/<select(.*?)select>/is'; $matches = array(); preg_match_all($pattern_select, $html_string, $matches); foreach ($matches[0] as $match) { $selectmatch = $match; $pattern_select2 = '/<select([^>]*?)>/is'; preg_match_all($pattern_select2, $match, $matches2); $pattern_name = '/name=("|\')([^(>|"|\')]*?)("|\')/i'; preg_match($pattern_name, $matches2[0][0], $matches_name); if (isset($matches_name[2]) && trim(str_replace('[]', '', $matches_name[2]))) { $email_data_name = "{" . str_replace('[]', '', $matches_name[2]) . "}"; $email_data_name = str_replace(array('[', ']'), array('.', ''), $email_data_name); if (!in_array($email_data_name, $usednames)) { $html_string = str_replace($match, $email_data_name, $html_string); $usednames[] = $email_data_name; } else { $html_string = str_replace($match, "", $html_string); } } else { //$html_string = str_replace($match, "{This_element_has_no_name_attribute}", $html_string); $html_string = str_replace($match, "", $html_string); } } return $html_string; }