/** * Initializing i18n * * @param array $options */ public static function init($options = []) { do { self::$language_code = $options['language_code']; $where = " AND lc_translation_language_code = '{$options['language_code']}'"; // retrive data from cache $cache_id_file = $cache_id = 'numbers_backend_i18n_basic_base_' . $options['language_code']; // if we are including js translations if (strpos($_SERVER['REQUEST_URI'] ?? '', $cache_id_file . '.js') !== false) { $where .= " AND lc_translation_javascript = 1"; $cache_id .= '_js'; } $cache = new cache(); $data = $cache->get($cache_id); if ($data !== false) { self::$data = !empty($data) ? $data : ['ids' => [], 'hashes' => []]; break; } // load data from database $sql = <<<TTT \t\t\t\tSELECT \t\t\t\t\tlc_translation_id id, \t\t\t\t\tlc_translation_text_sys sys, \t\t\t\t\tlc_translation_text_new new \t\t\t\tFROM lc_translations \t\t\t\tWHERE 1=1 \t\t\t\t\t{$where} TTT; $query_result = factory::model('numbers_backend_i18n_basic_model_translations')->db_object->query($sql); foreach ($query_result['rows'] as $k => $v) { if (strlen($v['sys']) > 40) { $v['sys'] = sha1($v['sys']); } self::$data['hashes'][$v['sys']] = $v['new']; self::$data['ids'][$v['id']] = $v['sys']; } // set the cache $cache->set($cache_id, self::$data, ['translations']); } while (0); // load js numbers_frontend_media_libraries_jssha_base::add(); layout::add_js('/numbers/media_submodules/numbers_backend_i18n_basic_media_js_i18n.js', 5001); layout::add_js('/numbers/backend/i18n/basic/controller/javascript/_js/' . $cache_id_file . '.js', 50000); // load data into cache return ['success' => 1, 'error' => []]; }
/** * Render form * * @return mixed */ public function render() { // ajax requests from another form if ($this->flag_another_ajax_call) { return null; } $this->tabindex = 1; // css & js numbers_frontend_media_libraries_jssha_base::add(); layout::add_js('/numbers/media_submodules/numbers_frontend_html_form_media_js_base.js', -10000); // include master js if (!empty($this->master_object) && method_exists($this->master_object, 'add_js')) { $this->master_object->add_js(); } // include js $filename = str_replace('_model_', '_media_js_', $this->form_class) . '.js'; if (file_exists('./../libraries/vendor/' . str_replace('_', '/', $filename))) { layout::add_js('/numbers/media_submodules/' . $filename); } $this->misc_settings['extended_js_class'] = 'numbers.' . $this->form_class; // include css $filename = str_replace('_model_', '_media_css_', $this->form_class) . '.css'; if (file_exists('./../libraries/vendor/' . str_replace('_', '/', $filename))) { layout::add_css('/numbers/media_submodules/' . $filename); } // load mask numbers_frontend_media_libraries_loadmask_base::add(); // new record action $mvc = application::get('mvc'); if (object_controller::can('record_new')) { $onclick = 'return confirm(\'' . strip_tags(i18n(null, object_content_messages::confirm_blank)) . '\');'; $this->actions['form_new'] = ['value' => 'New', 'sort' => -31000, 'icon' => 'file-o', 'href' => $mvc['full'] . '?' . $this::button_submit_blank . '=1', 'onclick' => $onclick, 'internal_action' => true]; } // back to list if (object_controller::can('list_view')) { $this->actions['form_back'] = ['value' => 'Back', 'sort' => -32000, 'icon' => 'arrow-left', 'href' => $mvc['controller'] . '/_index', 'internal_action' => true]; } // reload button if ($this->values_loaded) { $url = $mvc['full'] . '?' . http_build_query2($this->pk); $this->actions['form_refresh'] = ['value' => 'Refresh', 'sort' => 32000, 'icon' => 'refresh', 'href' => $url, 'internal_action' => true]; } // handling override_field_value method if (!empty($this->wrapper_methods['pre_render']['main'])) { call_user_func_array($this->wrapper_methods['pre_render']['main'], [&$this]); } // assembling everything into result variable $result = []; // order containers based on order column array_key_sort($this->data, ['order' => SORT_ASC]); foreach ($this->data as $k => $v) { if (!$v['flag_child']) { if ($v['type'] == 'fields' || $v['type'] == 'details') { // reset tabs $this->current_tab = []; $temp = $this->render_container($k); if ($temp['success']) { $result[$k] = $temp['data']; } } else { if ($v['type'] == 'tabs') { // tabs $tab_id = "form_tabs_{$this->form_link}_{$k}"; $tab_header = []; $tab_values = []; $tab_options = []; $have_tabs = false; // sort rows array_key_sort($v['rows'], ['order' => SORT_ASC]); foreach ($v['rows'] as $k2 => $v2) { $this->current_tab[] = "{$tab_id}_{$k2}"; $labels = ''; foreach (['records', 'danger', 'warning', 'success', 'info'] as $v78) { $labels .= html::label2(['type' => $v78 == 'records' ? 'primary' : $v78, 'style' => 'display: none;', 'value' => 0, 'id' => implode('__', $this->current_tab) . '__' . $v78]); } $tab_header[$k2] = i18n(null, $v2['options']['label_name']) . $labels; $tab_values[$k2] = ''; // handling override_tabs method if (!empty($this->wrapper_methods['override_tabs']['main'])) { $tab_options[$k2] = call_user_func_array($this->wrapper_methods['override_tabs']['main'], [&$this, &$v2, &$k2, &$this->values]); if (empty($tab_options[$k2]['hidden'])) { $have_tabs = true; } } else { $have_tabs = true; } // tab index for not hidden tabs if (empty($tab_options[$k2]['hidden'])) { $tab_options[$k2]['tabindex'] = $this->tabindex; $this->tabindex++; } // render containers array_key_sort($v2['elements'], ['order' => SORT_ASC]); foreach ($v2['elements'] as $k3 => $v3) { $temp = $this->render_container($v3['options']['container']); if ($temp['success']) { $tab_values[$k2] .= $temp['data']['html']; } } // remove last element from an array array_pop($this->current_tab); } // if we do not have tabs if ($have_tabs) { $result[$k]['html'] = html::tabs(['id' => $tab_id, 'class' => 'form-tabs', 'header' => $tab_header, 'options' => $tab_values, 'tab_options' => $tab_options]); } } } } } // formatting data $temp = []; foreach ($result as $k => $v) { $temp[] = $v['html']; } $result = implode('', $temp); // we need to skip internal actions if (!empty($this->options['no_actions'])) { foreach ($this->actions as $k0 => $v0) { if (!empty($v0['internal_action'])) { unset($this->actions[$k0]); } } } // rendering actions if (!empty($this->actions)) { $value = '<div style="text-align: right;">' . $this->render_actions() . '</div>'; $value .= '<hr class="simple" />'; $result = $value . $result; } // messages if (!empty($this->errors['general'])) { $messages = ''; foreach ($this->errors['general'] as $k => $v) { $messages .= html::message(['options' => $v, 'type' => $k]); } $result = '<div class="form_message_container">' . $messages . '</div>' . $result; } // couple hidden fields $result .= html::hidden(['name' => '__form_link', 'value' => $this->form_link]); $result .= html::hidden(['name' => '__form_values_loaded', 'value' => $this->values_loaded]); $result .= html::hidden(['name' => '__form_onchange_field_values_key', 'value' => '']); if (!empty($this->options['bypass_hidden_values'])) { foreach ($this->options['bypass_hidden_values'] as $k => $v) { $result .= html::hidden(['name' => $k, 'value' => $v]); } } // js to update counters in tabs if (!empty($this->errors['tabs'])) { foreach ($this->errors['tabs'] as $k => $v) { layout::onload("\$('#{$k}').html({$v}); \$('#{$k}').show();"); } } // if we have form if (empty($this->options['skip_form'])) { $mvc = application::get('mvc'); $result = html::form(['action' => $mvc['full'], 'name' => "form_{$this->form_link}_form", 'id' => "form_{$this->form_link}_form", 'value' => $result, 'onsubmit' => empty($this->options['no_ajax_form_reload']) ? 'return numbers.form.on_form_submit(this);' : null]); } // if we came from ajax we return as json object if (!empty($this->options['input']['__ajax'])) { $result = ['success' => true, 'error' => [], 'html' => $result, 'js' => layout::$onload]; layout::render_as($result, 'application/json'); } $result = "<div id=\"form_{$this->form_link}_form_mask\"><div id=\"form_{$this->form_link}_form_wrapper\">" . $result . '</div></div>'; // if we have segment if (isset($this->options['segment'])) { $temp = is_array($this->options['segment']) ? $this->options['segment'] : []; $temp['value'] = $result; $result = html::segment($temp); } return $result; }