Pass ID in URL PHP - php

Here's where I'm trying to get the ID
function addCliente($tipo_pessoa, $popup=null, $dados = null) {
$tipo_login = $this->session->userdata('tipo_login');
if ($this->session->userdata('logado') == true && $tipo_login == '1') {
$this->load->library('form_validation');
if ($tipo_pessoa == 1) {
$this->form_validation->set_rules('cpf', 'CPF', 'required|callback_verifica_cpf');
} else if ($tipo_pessoa == 2) {
$this->form_validation->set_rules('cnpj', 'CNPJ', 'required|callback_verifica_cnpj');
}
if ($this->form_validation->run() == FALSE) {
$this->returnCadCliente($tipo_pessoa);
} else {
$id_endereco = $this->cadEndereco($tipo_pessoa);
if ($tipo_pessoa == '1') {
$id_pessoa = $this->cadPessoaFisica();
$id_banco = $this->cadastroDadosBancarios();
$id_contato = $this->cadastroContato();
$id_cadastroAnexo = $this->cadastroAnexo();
$id_cadastroAtendimento = $this->cadastroAtendimento();
} else if ($tipo_pessoa == '2') {
$id_pessoa = $this->cadPessoaJuridica();
$id_banco = $this->cadastroDadosBancarios();
$id_contato = $this->cadastroContato();
$id_cadastroAnexo = $this->cadastroAnexo();
$id_cadastroAtendimento = $this->cadastroAtendimento();
}
$limite_credito = null;
if ($this->input->post('limite_credito')) {
$limite_credito = $this->input->post('limite_credito');
}
$id_cliente = $this->cadCliente($tipo_pessoa);
$data_cad = date("d/m/Y");
$hora_cad = date("H:i:s");
if ($id_cadastro = $this->cadastroComum($limite_credito, (int) $tipo_pessoa, $id_pessoa, 1, $id_cliente, $id_endereco, $data_cad, $hora_cad)) {
$this->cadastroHistorico('Cliente cadastrado', $id_cadastro, $data_cad, $hora_cad);
if ($popup == '1') {
$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/cadastroOrcamentoVenda/" . $this->input->post('matricula'), (int) $tipo_pessoa);
} else {
//$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/cadastroCliente/", (int) $tipo_pessoa);
I call alteraçãoClientePf here
$this->mensagemAlerta("Cliente cadastrado com sucesso!", 1, "home/alteracaoClientePf/" . $this->input->post('id_cadastro'), (int) $tipo_pessoa);
}
} else {
$this->mensagemAlerta("Erro ao cadastrar cliente, tente novamente!", 0, "cadastro/returnCadCliente/", (int) $tipo_pessoa);
}
}
} else {
$dados['mensagem'] = null;
$this->load->view('login/head');
$this->load->view('login/formLogin', $dados);
$this->load->view('login/footer');
}
}
This is the function I call when requesting the ID
function alteracaoClientePf($id_cadastro, $dados = null) {
$tipo_login = $this->session->userdata('tipo_login');
if ($this->session->userdata('logado') == true && $tipo_login == '1') {
$dadosCliente['dados'] = $this->lista->retornaDadosClientePf($id_cadastro);
$dadosCliente['banco'] = $this->adm->returnBancos();
$dadosCliente['contas_bancarias'] = $this->lista->retornaContas($id_cadastro);
$dadosCliente['contatos'] = $this->lista->retornaContatos($id_cadastro);
$dadosCliente['anexos'] = $this->lista->retornaAnexos($id_cadastro);
$dadosCliente['atendimentos'] = $this->lista->retornaAtendimentos($id_cadastro);
$dadosCliente['historico'] = $this->lista->retornaHistorico($id_cadastro);
$this->load->view('admin/head');
$dadosBarra['dadosB'] = $this->financeiro->listaContas();
$this->load->view('admin/barraSuperior', $dadosBarra);
$dadosLogo['logo'] = $this->adm->retornaLogo();
$this->load->view('admin/menu', $dadosLogo);
$this->load->view('admin/alteracoes/alterar_cliente_pf', $dadosCliente);
$this->load->view('admin/footer');
} else {
$dados['mensagem'] = null;
$this->paginas($dados);
}
}
That's the error I'm getting
Message: Too few arguments to function Home::alteracaoClientePf(), 0 passed in C:\xampp\htdocs\sistema_financas_old_atual\system\core\CodeIgniter.php on line 532 and at least 1 expected
Filename: C:\xampp\htdocs\sistema_financas_old_atual\application\controllers\Home.php
Line Number: 1184

Related

Adding a 0 at the end of the input when it is less than 9 digits

I have an e-commerce site in opencart and I have a problem in the RG field which is as follows, when the user registers it fills all the fields normally but in the RG field there are those users that have one digit less in the RG that they are usually 9 more digits have users with 8 and they usually register on the site more when they are going to make a purchase they can not conclude it because the RG is with a number less would like to know if it is possible to put a code that does the following when the User to enter a RG with one digit less or less than 9 add a 0 at the end of the field so that it is complete.
This is uexatamente the input that I need to change so that when the user clicks on register it will be saved with the longest digit
<Input type = "text" name = "custom_field [account] [2]" value = "" placeholder = "RG" id = "input-custom-field2" class = "form-control">
I do not know if this is where I am going to implement my code but this is one of the controllers responsible for the registration of the form
<?php
class ControllerAccountRegister extends Controller {
private $error = array();
public function index() {
if ($this->customer->isLogged()) {
$this->response->redirect($this->url->link('account/account', '', 'SSL'));
}
$this->load->language('account/register');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment.js');
$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
$this->load->model('account/customer');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$customer_id = $this->model_account_customer->addCustomer($this->request->post);
// Clear any previous login attempts for unregistered accounts.
$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
$this->customer->login($this->request->post['email'], $this->request->post['password']);
unset($this->session->data['guest']);
// Add to activity log
$this->load->model('account/activity');
$activity_data = array(
'customer_id' => $customer_id,
'name' => $this->request->post['firstname']
//'name' => $this->request->post['firstname'] . ' ' . $this->request->post['lastname']
);
$this->model_account_activity->addActivity('register', $activity_data);
$this->response->redirect($this->url->link('account/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_account'),
'href' => $this->url->link('account/account', '', 'SSL')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_register'),
'href' => $this->url->link('account/register', '', 'SSL')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('account/login', '', 'SSL'));
$data['text_your_details'] = $this->language->get('text_your_details');
$data['text_your_address'] = $this->language->get('text_your_address');
$data['text_your_password'] = $this->language->get('text_your_password');
$data['text_newsletter'] = $this->language->get('text_newsletter');
$data['text_yes'] = $this->language->get('text_yes');
$data['text_no'] = $this->language->get('text_no');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
$data['text_loading'] = $this->language->get('text_loading');
$data['entry_customer_group'] = $this->language->get('entry_customer_group');
$data['entry_firstname'] = $this->language->get('entry_firstname');
// $data['entry_lastname'] = $this->language->get('entry_lastname');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_telephone'] = $this->language->get('entry_telephone');
$data['entry_fax'] = $this->language->get('entry_fax');
$data['entry_company'] = $this->language->get('entry_company');
$data['entry_address_1'] = $this->language->get('entry_address_1');
$data['entry_address_2'] = $this->language->get('entry_address_2');
$data['entry_postcode'] = $this->language->get('entry_postcode');
$data['entry_city'] = $this->language->get('entry_city');
$data['entry_country'] = $this->language->get('entry_country');
$data['entry_zone'] = $this->language->get('entry_zone');
$data['entry_newsletter'] = $this->language->get('entry_newsletter');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_confirm'] = $this->language->get('entry_confirm');
$data['button_continue'] = $this->language->get('button_continue');
$data['button_upload'] = $this->language->get('button_upload');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->error['firstname'])) {
$data['error_firstname'] = $this->error['firstname'];
} else {
$data['error_firstname'] = '';
}
// if (isset($this->error['lastname'])) {
// $data['error_lastname'] = $this->error['lastname'];
// } else {
// $data['error_lastname'] = '';
// }
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['telephone'])) {
$data['error_telephone'] = $this->error['telephone'];
} else {
$data['error_telephone'] = '';
}
if (isset($this->error['address_1'])) {
$data['error_address_1'] = $this->error['address_1'];
} else {
$data['error_address_1'] = '';
}
if (isset($this->error['city'])) {
$data['error_city'] = $this->error['city'];
} else {
$data['error_city'] = '';
}
if (isset($this->error['postcode'])) {
$data['error_postcode'] = $this->error['postcode'];
} else {
$data['error_postcode'] = '';
}
if (isset($this->error['country'])) {
$data['error_country'] = $this->error['country'];
} else {
$data['error_country'] = '';
}
if (isset($this->error['zone'])) {
$data['error_zone'] = $this->error['zone'];
} else {
$data['error_zone'] = '';
}
if (isset($this->error['custom_field'])) {
$data['error_custom_field'] = $this->error['custom_field'];
} else {
$data['error_custom_field'] = array();
}
if (isset($this->error['password'])) {
$data['error_password'] = $this->error['password'];
} else {
$data['error_password'] = '';
}
if (isset($this->error['confirm'])) {
$data['error_confirm'] = $this->error['confirm'];
} else {
$data['error_confirm'] = '';
}
$data['action'] = $this->url->link('account/register', '', 'SSL');
$data['customer_groups'] = array();
if (is_array($this->config->get('config_customer_group_display'))) {
$this->load->model('account/customer_group');
$customer_groups = $this->model_account_customer_group->getCustomerGroups();
foreach ($customer_groups as $customer_group) {
if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$data['customer_groups'][] = $customer_group;
}
}
}
if (isset($this->request->post['customer_group_id'])) {
$data['customer_group_id'] = $this->request->post['customer_group_id'];
} else {
$data['customer_group_id'] = $this->config->get('config_customer_group_id');
}
if (isset($this->request->post['firstname'])) {
$data['firstname'] = $this->request->post['firstname'];
} else {
$data['firstname'] = '';
}
// if (isset($this->request->post['lastname'])) {
// $data['lastname'] = $this->request->post['lastname'];
// } else {
// $data['lastname'] = '';
// }
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = '';
}
if (isset($this->request->post['telephone'])) {
$data['telephone'] = $this->request->post['telephone'];
} else {
$data['telephone'] = '';
}
if (isset($this->request->post['fax'])) {
$data['fax'] = $this->request->post['fax'];
} else {
$data['fax'] = '';
}
if (isset($this->request->post['company'])) {
$data['company'] = $this->request->post['company'];
} else {
$data['company'] = '';
}
if (isset($this->request->post['address_1'])) {
$data['address_1'] = $this->request->post['address_1'];
} else {
$data['address_1'] = '';
}
if (isset($this->request->post['address_2'])) {
$data['address_2'] = $this->request->post['address_2'];
} else {
$data['address_2'] = '';
}
if (isset($this->request->post['postcode'])) {
$data['postcode'] = $this->request->post['postcode'];
} elseif (isset($this->session->data['shipping_address']['postcode'])) {
$data['postcode'] = $this->session->data['shipping_address']['postcode'];
} else {
$data['postcode'] = '';
}
if (isset($this->request->post['city'])) {
$data['city'] = $this->request->post['city'];
} else {
$data['city'] = '';
}
if (isset($this->request->post['country_id'])) {
$data['country_id'] = $this->request->post['country_id'];
} elseif (isset($this->session->data['shipping_address']['country_id'])) {
$data['country_id'] = $this->session->data['shipping_address']['country_id'];
} else {
$data['country_id'] = $this->config->get('config_country_id');
}
if (isset($this->request->post['zone_id'])) {
$data['zone_id'] = $this->request->post['zone_id'];
} elseif (isset($this->session->data['shipping_address']['zone_id'])) {
$data['zone_id'] = $this->session->data['shipping_address']['zone_id'];
} else {
$data['zone_id'] = '';
}
$this->load->model('localisation/country');
$data['countries'] = $this->model_localisation_country->getCountries();
// Custom Fields
$this->load->model('account/custom_field');
$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
if (isset($this->request->post['custom_field'])) {
if (isset($this->request->post['custom_field']['account'])) {
$account_custom_field = $this->request->post['custom_field']['account'];
} else {
$account_custom_field = array();
}
if (isset($this->request->post['custom_field']['address'])) {
$address_custom_field = $this->request->post['custom_field']['address'];
} else {
$address_custom_field = array();
}
$data['register_custom_field'] = $account_custom_field + $address_custom_field;
} else {
$data['register_custom_field'] = array();
}
if (isset($this->request->post['password'])) {
$data['password'] = $this->request->post['password'];
} else {
$data['password'] = '';
}
if (isset($this->request->post['confirm'])) {
$data['confirm'] = $this->request->post['confirm'];
} else {
$data['confirm'] = '';
}
if (isset($this->request->post['newsletter'])) {
$data['newsletter'] = $this->request->post['newsletter'];
} else {
$data['newsletter'] = '';
}
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info) {
$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
} else {
$data['text_agree'] = '';
}
} else {
$data['text_agree'] = '';
}
if (isset($this->request->post['agree'])) {
$data['agree'] = $this->request->post['agree'];
} else {
$data['agree'] = false;
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/register.tpl')) {
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/register.tpl', $data));
} else {
$this->response->setOutput($this->load->view('default/template/account/register.tpl', $data));
}
}
public function validate() {
if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
$this->error['firstname'] = $this->language->get('error_firstname');
}
// if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
// $this->error['lastname'] = $this->language->get('error_lastname');
// }
if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\#]+#.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
$this->error['email'] = $this->language->get('error_email');
}
if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->language->get('error_exists');
}
if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) {
$this->error['address_1'] = $this->language->get('error_address_1');
}
if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) {
$this->error['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['country_id'] == '') {
$this->error['country'] = $this->language->get('error_country');
}
if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') {
$this->error['zone'] = $this->language->get('error_zone');
}
// Customer Group
if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->post['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
// Custom field validation
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
}
}
if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
$this->error['password'] = $this->language->get('error_password');
}
if ($this->request->post['confirm'] != $this->request->post['password']) {
$this->error['confirm'] = $this->language->get('error_confirm');
}
// Agree to terms
if ($this->config->get('config_account_id')) {
$this->load->model('catalog/information');
$information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
if ($information_info && !isset($this->request->post['agree'])) {
$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
}
}
return !$this->error;
}
public function customfield() {
$json = array();
$this->load->model('account/custom_field');
// Customer Group
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
foreach ($custom_fields as $custom_field) {
$json[] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'required' => $custom_field['required']
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
may be you can use this script.
function putZeroToLastItem($text) {
$length = strlen($text);
if( $length < 9 ) {
$text .= '0'
}
return $text
}
I hope , this script will solve your porblem.
<?php
$num = 3;
$num_padded = sprintf("%02d", $num);
echo $num_padded; // returns 03
?>
Try this simple snippet
You want to add 0 after the number (9 digit)? Use jquery if you want it in client side.
function addZero (data){
return data+(data <10 ? '0':'');
}
var num =$('#number').val();
var nNum = addZero(num);
Hope it helps.
A reduced way of #mehfatitem:
function putZeroToLastItem($text) {
return (strlen($text) < 9) ? $text . '0' : $text;
}

Illegal string offset 'formId' in repeater gravityform

PLease Help me,
I have this errors
Warning: Illegal string offset 'formId' in
C:\xampp\htdocs\wp-content\plugins\repeater-add-on-for-gravity-forms\class-gf-field-repeater.php
on line 287
Warning: Illegal string offset 'children' in
C:\xampp\htdocs\wp-content\plugins\repeater-add-on-for-gravity-forms\class-gf-field-repeater.php
on line 291
...
if (empty($value)) {
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
...
Hi I solved adding $value = array() in line 287.
if (empty($value)) {
$value = array();
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
That's work for me, I hope it could help you.
<?php
class GF_Field_Repeater extends GF_Field {
public $type = 'repeater';
public static function init_admin() {
$admin_page = rgget('page');
if ($admin_page == 'gf_edit_forms' && !empty($_GET['id'])) {
add_action('gform_field_standard_settings' , array('GF_Field_Repeater', 'gform_standard_settings'), 10, 2);
add_action('gform_field_appearance_settings' , array('GF_Field_Repeater', 'gform_appearance_settings'), 10, 2);
add_action('gform_editor_js_set_default_values', array('GF_Field_Repeater', 'gform_set_defaults'));
add_action('gform_editor_js', array('GF_Field_Repeater', 'gform_editor'));
add_filter('gform_tooltips', array('GF_Field_Repeater', 'gform_tooltips'));
}
if ($admin_page == 'gf_entries') {
add_filter('gform_form_post_get_meta', array('GF_Field_Repeater', 'gform_hide_children'));
}
}
public static function init_frontend() {
add_action('gform_form_args', array('GF_Field_Repeater', 'gform_disable_ajax'));
add_action('gform_enqueue_scripts', array('GF_Field_Repeater', 'gform_enqueue_scripts'), 10, 2);
add_filter('gform_pre_render', array('GF_Field_Repeater', 'gform_unhide_children_validation'));
add_filter('gform_pre_validation', array('GF_Field_Repeater', 'gform_bypass_children_validation'));
}
public static function gform_enqueue_scripts($form, $is_ajax) {
if (!empty($form)) {
if (GF_Field_Repeater::get_field_index($form) !== false) {
wp_enqueue_script('gforms_repeater_postcapture_js', plugins_url('js/jquery.postcapture.min.js', __FILE__), array('jquery'), '0.0.1');
wp_enqueue_script('gforms_repeater_js', plugins_url('js/gf-repeater.min.js', __FILE__), array('jquery'), GF_REPEATER_VERSION);
wp_enqueue_style('gforms_repeater_css', plugins_url('css/gf-repeater.css', __FILE__), array(), GF_REPEATER_VERSION);
}
}
}
public function get_form_editor_field_title() {
return 'Repeater';
}
public function get_form_editor_field_settings() {
return array(
'admin_label_setting',
'css_class_setting',
'description_setting',
'error_message_setting',
'label_setting',
'prepopulate_field_setting'
);
}
public static function gform_set_defaults() {
echo "
case \"repeater\" :
field.label = \"Repeater\";
break;
";
}
public static function gform_standard_settings($position, $form_id) {
if ($position == 1600) {
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_start\">Start ";
gform_tooltip('form_field_repeater_start');
echo " </label>
<input type=\"number\" id=\"field_repeater_start\" min=\"1\" value=\"1\" onchange=\"SetFieldProperty('start', this.value);\">
</li>";
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_min\">Min ";
gform_tooltip('form_field_repeater_min');
echo " </label>
<input type=\"number\" id=\"field_repeater_min\" min=\"1\" value=\"1\" onchange=\"SetFieldProperty('min', this.value);\">
</li>";
echo "<li class=\"repeater_settings field_setting\">
<label for=\"field_repeater_max\">Max ";
gform_tooltip('form_field_repeater_max');
echo " </label>
<input type=\"number\" id=\"field_repeater_max\" min=\"1\" onchange=\"SetFieldProperty('max', this.value);\">
</li>";
}
}
public static function gform_appearance_settings($position, $form_id) {
if ($position == 400) {
echo "<li class=\"repeater_settings field_setting\">
<input type=\"checkbox\" id=\"field_repeater_hideLabel\" onchange=\"SetFieldProperty('hideLabel', this.checked);\">
<label for=\"field_repeater_hideLabel\" class=\"inline\">Hide Label & Description ";
gform_tooltip('form_field_repeater_hideLabel');
echo " </label>
</li>";
}
}
public static function gform_editor() {
echo "<script type=\"text/javascript\">
fieldSettings['repeater'] += ', .repeater_settings';
jQuery(document).bind('gform_load_field_settings', function(event, field, form){
jQuery('#field_repeater_start').val(field['start']);
jQuery('#field_repeater_min').val(field['min']);
jQuery('#field_repeater_max').val(field['max']);
jQuery('#field_repeater_hideLabel').prop('checked', field['hideLabel']);
});
</script>";
}
public static function gform_tooltips($tooltips) {
$tooltips['form_field_repeater_start'] = "The number of times the repeater will be repeated when the form is rendered. Leaving this field blank or setting it to a number higher than the maximum number is the same as setting it to 1.";
$tooltips['form_field_repeater_min'] = "The minimum number of times the repeater is allowed to be repeated. Leaving this field blank or setting it to a number higher than the maximum field is the same as setting it to 1.";
$tooltips['form_field_repeater_max'] = "The maximum number of times the repeater is allowed to be repeated. Leaving this field blank or setting it to a number lower than the minimum field is the same as setting it to unlimited.";
$tooltips['form_field_repeater_hideLabel'] = "If this is checked, the repeater label and description will not be shown to users on the form.";
return $tooltips;
}
function validate($value, $form) {
$repeater_required = $this->repeaterRequiredChildren;
if (!empty($repeater_required)) {
$dataArray = json_decode($value, true);
foreach ($form['fields'] as $key=>$value) {
$fieldKeys[$value['id']] = $key;
if (is_array($value['inputs'])) {
foreach ($value['inputs'] as $inputKey=>$inputValue) {
$inputKeys[$value['id']][$inputValue['id']] = $inputKey;
}
}
}
if ($dataArray['repeatCount'] < $this->min) {
$this->failed_validation = true;
$this->validation_message = "A minimum number of ".$this->min." is required.";
return;
}
if ($this->max && $dataArray['repeatCount'] > $this->max) {
$this->failed_validation = true;
$this->validation_message = "A maximum number of ".$this->max." is allowed.";
return;
}
for ($i = 1; $i < $dataArray['repeatCount'] + 1; $i++) {
foreach ($dataArray['children'] as $field_id=>$field) {
$inputNames = $field['inputs'];
$repeatSkips = $field['conditionalLogic']['skip'];
if (!is_array($inputNames)) { continue; }
if (is_array($repeatSkips)) {
if (in_array($i, $repeatSkips) || in_array('all', $repeatSkips)) { continue; }
}
foreach ($inputNames as $inputName) {
if (is_array($inputName)) { $inputName = reset($inputName); }
if (substr($inputName, -2) == '[]') {
$getInputName = substr($inputName, 0, strlen($inputName) - 2).'-'.$dataArray['repeaterId'].'-'.$i;
} else {
$getInputName = $inputName.'-'.$dataArray['repeaterId'].'-'.$i;
}
$getInputName = str_replace('.', '_', strval($getInputName));
$getInputData = rgpost($getInputName);
$getInputIdNum = preg_split("/(_|-)/", $getInputName);
if (in_array($getInputIdNum[1], $repeater_required)) {
$fieldKey = $fieldKeys[$getInputIdNum[1]];
$fieldType = $form['fields'][$fieldKey]['type'];
$failedValidation = false;
switch($fieldType) {
case 'name':
$requiredIDs = array(3, 6);
if (in_array($getInputIdNum[2], $requiredIDs) && empty($getInputData)) { $failedValidation = true; }
break;
case 'address':
$skipIDs = array(2);
if (!in_array($getInputIdNum[2], $skipIDs) && empty($getInputData)) { $failedValidation = true; }
break;
default:
if (empty($getInputData)) { $failedValidation = true; }
}
if ($failedValidation) {
$this->failed_validation = true;
if ($this->errorMessage) { $this->validation_message = $this->errorMessage; } else { $this->validation_message = "A required field was left blank."; }
return;
}
}
}
}
}
}
}
public function get_field_content($value, $force_frontend_label, $form) {
if (is_admin()) {
$admin_buttons = $this->get_admin_buttons();
$field_content = "{$admin_buttons}
<div class=\"gf-pagebreak-first gf-pagebreak-container gf-repeater gf-repeater-start\">
<div class=\"gf-pagebreak-text-before\">begin repeater</div>
<div class=\"gf-pagebreak-text-main\"><span>REPEATER</span></div>
<div class=\"gf-pagebreak-text-after\">top of repeater</div>
</div>";
} else {
$field_label = $this->get_field_label($force_frontend_label, $value);
$description = $this->get_description($this->description, 'gsection_description gf_repeater_description');
$hide_label = $this->hideLabel;
$validation_message = ( $this->failed_validation && ! empty( $this->validation_message ) ) ? sprintf( "<div class='gfield_description validation_message'>%s</div>", $this->validation_message ) : '';
if (!empty($field_label)) { $field_label = "<h2 class='gf_repeater_title'>{$field_label}</h2>"; } else { $field_label = ''; }
if ($hide_label) { $field_label = ''; $description = ''; }
$field_content = "<div class=\"ginput_container ginput_container_repeater\">{$field_label}{FIELD}</div>{$description}{$validation_message}";
}
return $field_content;
}
public function get_field_input($form, $value = '', $entry = null) {
if (is_admin()) {
return '';
} else {
$form_id = $form['id'];
$is_entry_detail = $this->is_entry_detail();
$is_form_editor = $this->is_form_editor();
$id = (int) $this->id;
$field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id";
$tabindex = $this->get_tabindex();
$repeater_parem = $this->inputName;
$repeater_start = $this->start;
$repeater_min = $this->min;
$repeater_max = $this->max;
$repeater_required = $this->repeaterRequiredChildren;
$repeater_children = $this->repeaterChildren;
if (!empty($repeater_parem)) {
$repeater_parem_value = GFFormsModel::get_parameter_value($repeater_parem, $value, $this);
if (!empty($repeater_parem_value)) { $repeater_start = $repeater_parem_value; }
}
if (!empty($repeater_children)) {
$repeater_children_info = array();
$repeater_parems = GF_Field_Repeater::get_children_parem_values($form, $repeater_children);
foreach($repeater_children as $repeater_child) {
$repeater_children_info[$repeater_child] = array();
$repeater_child_field_index = GF_Field_Repeater::get_field_index($form, 'id', $repeater_child);
if (!empty($repeater_required)) {
if (in_array($repeater_child, $repeater_required)) {
$repeater_children_info[$repeater_child]['required'] = true;
}
}
if (!empty($repeater_parems)) {
if (array_key_exists($repeater_child, $repeater_parems)) {
$repeater_children_info[$repeater_child]['prePopulate'] = $repeater_parems[$repeater_child];
}
}
if ($repeater_child_field_index !== false) {
if ($form['fields'][$repeater_child_field_index]['inputMask']) {
$repeater_children_info[$repeater_child]['inputMask'] = $form['fields'][$repeater_child_field_index]['inputMaskValue'];
} elseif ($form['fields'][$repeater_child_field_index]['type'] == 'phone' && $form['fields'][$repeater_child_field_index]['phoneFormat'] = 'standard') {
$repeater_children_info[$repeater_child]['inputMask'] = "(999) 999-9999";
}
if ($form['fields'][$repeater_child_field_index]['conditionalLogic']) {
$repeater_children_info[$repeater_child]['conditionalLogic'] = $form['fields'][$repeater_child_field_index]['conditionalLogic'];
}
}
}
$repeater_children = $repeater_children_info;
}
if (empty($value)) {
$value['formId'] = $form_id;
if (!empty($repeater_start)) { $value['start'] = $repeater_start; }
if (!empty($repeater_min)) { $value['min'] = $repeater_min; }
if (!empty($repeater_max)) { $value['max'] = $repeater_max; }
if (!empty($repeater_children)) { $value['children'] = $repeater_children; }
$value = json_encode($value);
}
return sprintf("<input name='input_%d' id='%s' type='hidden' class='gform_repeater' value='%s' %s />", $id, $field_id, $value, $tabindex);
}
}
public function get_value_save_entry($value, $form, $input_name, $lead_id, $lead) {
$dataArray = json_decode($value, true);
$value = Array();
for ($i = 1; $i < $dataArray['repeatCount'] + 1; $i++) {
foreach ($dataArray['children'] as $field_id=>$field) {
$inputData = Array();
if (array_key_exists('inputs', $field)) {
$inputNames = $field['inputs'];
$repeatSkips = $field['conditionalLogic']['skip'];
if (is_array($repeatSkips)) {
if (in_array($i, $repeatSkips) || in_array('all', $repeatSkips)) { continue; }
}
if (is_array($inputNames)) {
foreach ($inputNames as $inputName) {
if (substr($inputName, -2) == '[]') {
$getInputName = substr($inputName, 0, strlen($inputName) - 2).'-'.$dataArray['repeaterId'].'-'.$i;
} else {
$getInputName = $inputName.'-'.$dataArray['repeaterId'].'-'.$i;
}
$getInputData = rgpost(str_replace('.', '_', strval($getInputName)));
if (!empty($getInputData)) {
if (is_array($getInputData)) {
foreach ($getInputData as $theInputData) {
$inputData[] = $theInputData;
}
} else {
$inputData[] = $getInputData;
}
}
}
}
} else {
if (GF_Field_Repeater::get_field_type($form, $field_id) == 'section') { $inputData = '[gfRepeater-section]'; }
}
$childValue[$field_id] = $inputData;
}
$value[$i] = $childValue;
}
return maybe_serialize($value);
}
public function get_value_entry_list($value, $entry, $field_id, $columns, $form) {
if (empty($value)) {
return '';
} else {
$dataArray = GFFormsModel::unserialize($value);
$arrayCount = count($dataArray);
if ($arrayCount > 1) { $returnText = $arrayCount.' entries'; } else { $returnText = $arrayCount.' entry'; }
return $returnText;
}
}
public function get_value_entry_detail($value, $currency = '', $use_text = false, $format = 'html', $media = 'screen') {
if (empty($value)) {
return '';
} else {
$dataArray = GFFormsModel::unserialize($value);
$arrayCount = count($dataArray);
$output = "\n";
$count = 0;
$repeatCount = 0;
$display_empty_fields = rgget('gf_display_empty_fields', $_COOKIE);
$form_id = $this->formId;
$get_form = GFFormsModel::get_form_meta_by_id($form_id);
$form = $get_form[0];
foreach ($dataArray as $key=>$value) {
$repeatCount++;
$tableContents = '';
if (!empty($value) && !is_array($value)) {
$save_value = $value;
unset($value);
$value[0] = $save_value;
}
foreach ($value as $childKey=>$childValue) {
$count++;
$childValueOutput = '';
if (empty($display_empty_fields) && count($childValue) == 0) { continue; }
if (is_numeric($childKey)) {
$field_index = GF_Field_Repeater::get_field_index($form, 'id', $childKey);
if ($field_index === false) { continue; }
$entry_title = $form['fields'][$field_index]['label'];
} else {
$entry_title = $childKey;
}
$entry_title = str_replace('[gfRepeater-count]', $repeatCount, $entry_title);
if ($format == 'html') {
if ($childValue == '[gfRepeater-section]') {
if ($media == 'email') {
$tableStyling = ' style="font-size:14px;font-weight:bold;background-color:#eee;border-bottom:1px solid #dfdfdf;padding:7px 7px"';
} else {
$tableStyling = ' class="entry-view-section-break"';
}
} else {
if ($media == 'email') {
$tableStyling = ' style="background-color:#EAF2FA;font-family:sans-serif;font-size:12px;font-weight:bold"';
} else {
$tableStyling = ' class="entry-view-field-name"';
}
}
$tableContents .= "<tr>\n<td colspan=\"2\"".$tableStyling.">".$entry_title."</td>\n</tr>\n";
} else {
$tableContents .= $entry_title.": ";
}
if (is_array($childValue)) {
if (count($childValue) == 1) {
$childValueOutput = $childValue[0];
} elseif (count($childValue) > 1) {
if ($format == 'html') {
if ($media == 'email') {
$childValueOutput = "<ul style=\"list-style:none;margin:0;padding:0;\">\n";
} else {
$childValueOutput = "<ul>\n";
}
}
foreach ($childValue as $childValueData) {
if ($format == 'html') {
$childValueOutput .= "<li>".$childValueData."</li>";
} else {
$childValueOutput .= $childValueData."\n";
}
}
if ($format == 'html') { $childValueOutput .= "</ul>\n"; }
}
if ($media == 'email') { $tableStyling = ''; } else { $tableStyling = ' class=\"entry-view-field-value\"'; }
if ($format == 'html') {
$tableContents .= "<tr>\n<td colspan=\"2\"".$tableStyling.">".$childValueOutput."</td>\n</tr>\n";
} else {
$tableContents .= $childValueOutput."\n";
}
}
}
if (!empty($tableContents)) {
if ($format == 'html') {
if ($media == 'email') { $tableStyling = ' width="100%" border="0" cellpadding="5" bgcolor="#FFFFFF"'; } else { $tableStyling = ' class="widefat fixed entry-detail-view"'; }
$output .= "<table cellspacing=\"0\"".$tableStyling.">\n";
$output .= $tableContents;
$output .= "</table>\n";
} else {
$output .= $tableContents."\n";
}
}
}
}
if ($count !== 0) {
if ($format == 'text') { $output = rtrim($output); }
return $output;
} else { return ''; }
}
public function get_value_merge_tag($value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br) {
$output = GF_Field_Repeater::get_value_entry_detail($raw_value, '', false, $format, 'email');
$output = preg_replace("/[\r\n]+/", "\n", $output);
return trim($output);
}
public function get_value_export($entry, $input_id = '', $use_text = false, $is_csv = false) {
if (empty($input_id)) { $input_id = $this->id; }
$output = rgar($entry, $input_id);
$output = GF_Field_Repeater::get_value_entry_detail($output, '', false, 'text', 'email');
$output = preg_replace("/[\r\n]+/", ", ", trim($output));
return $output;
}
public static function gform_hide_children($form) {
$form_id = $form['id'];
$repeaterChildren = Array();
$grid_modified = false;
$grid_meta = GFFormsModel::get_grid_column_meta($form_id);
foreach($form['fields'] as $key=>$field) {
if ($field->type == 'repeater') {
if (is_array($field->repeaterChildren)) { $repeaterChildren = array_merge($repeaterChildren, $field->repeaterChildren); }
} elseif ($field->type == 'repeater-end') { array_push($repeaterChildren, $field->id); }
if (!empty($repeaterChildren)) {
if (in_array($field->id, $repeaterChildren)) {
unset($form['fields'][$key]);
if (is_array($grid_meta)) {
$grid_pos = array_search($field->id, $grid_meta);
if ($grid_pos) {
$grid_modified = true;
unset($grid_meta[$grid_pos]);
}
}
}
}
}
if ($grid_modified) { GFFormsModel::update_grid_column_meta($form_id, $grid_meta); }
$form['fields'] = array_values($form['fields']);
return $form;
}
public static function gform_disable_ajax($args) {
$get_form = GFFormsModel::get_form_meta_by_id($args['form_id']);
$form = reset($get_form);
if (GF_Field_Repeater::get_field_index($form) !== false) {
$args['ajax'] = false;
}
return $args;
}
public static function gform_bypass_children_validation($form) {
if (GF_Field_Repeater::get_field_index($form) === false) { return $form; }
$repeaterChildren = Array();
foreach($form['fields'] as $key=>$field) {
if ($field->type == 'repeater') {
if (is_array($field->repeaterChildren)) { $repeaterChildren = array_merge($repeaterChildren, $field->repeaterChildren); }
}
if (!empty($repeaterChildren)) {
if (in_array($field->id, $repeaterChildren) && !$field->adminOnly) {
$form['fields'][$key]['adminOnly'] = true;
$form['fields'][$key]['repeaterChildValidationHidden'] = true;
}
}
}
return $form;
}
public static function gform_unhide_children_validation($form) {
if (GF_Field_Repeater::get_field_index($form) === false) { return $form; }
foreach($form['fields'] as $key=>$field) {
if ($field->repeaterChildValidationHidden) {
$form['fields'][$key]['adminOnly'] = false;
$form['fields'][$key]['repeaterChildValidationHidden'] = false;
}
}
return $form;
}
public static function get_field_index($form, $key = 'type', $value = 'repeater') {
if (is_array($form)) {
if (!array_key_exists('fields', $form)) { return false; }
} else { return false; }
foreach ($form['fields'] as $field_key=>$field_value) {
if (is_object($field_value)) {
if (property_exists($field_value, $key)) {
if ($field_value[$key] == $value) { return $field_key; }
}
}
}
return false;
}
public static function get_field_type($form, $id) {
$field_index = GF_Field_Repeater::get_field_index($form, 'id', $id);
if ($field_index !== false) { return $form['fields'][$field_index]['type']; }
return false;
}
public static function get_children_parems($form, $children_ids) {
foreach($form['fields'] as $key=>$value) {
if (in_array($value['id'], $children_ids)) {
if ($value['inputName']) {
$parems[$value['id']] = $value['inputName'];
} elseif ($value['inputs']) {
foreach($value['inputs'] as $key=>$value) {
if ($value['name']) { $parems[$value['id']] = $value['name']; }
}
}
}
}
if (!empty($parems)) { return $parems; } else { return false; }
}
public static function get_children_parem_values($form, $children_ids) {
global $wp_filter;
$children_parems = GF_Field_Repeater::get_children_parems($form, $children_ids);
if (empty($children_parems)) { return false; }
// Check the URL first
foreach($_GET as $url_key=>$url_value) {
$key = array_search($url_key, $children_parems);
if ($key !== false) {
$parems[$key][0] = $url_value;
} else {
$split_key = preg_split('/\D+\K/', $url_key);
$key = array_search($split_key[0], $children_parems);
if ($key !== false) { $parems[$key][$split_key[1]] = $url_value; }
}
}
// Then check the filters
foreach($wp_filter as $key=>$value) {
$split_key = preg_split('/^gform_field_value_+\K/', $key);
if (!empty($split_key[1])) {
$key1 = array_search($split_key[1], $children_parems);
if ($key1 !== false) {
$parems[$key1][0] = apply_filters($key, '');
} else {
$split_key2 = preg_split('/\D+\K/', $split_key[1]);
$key2 = array_search($split_key2[0], $children_parems);
if ($key2 !== false) { $parems[$key2][$split_key2[1]] = apply_filters($key, ''); }
}
}
}
if (!empty($parems)) { return $parems; } else { return false; }
}
}
GF_Fields::register(new GF_Field_Repeater());

Display php array element from a function

Hello I have the following array that is a result form a function that is being called based on (isset)
function: list_activity_details_array() returns:
{"activity_related_to_id":"2","activity_id":"14","activity_type_icon":"fa fa-phone","activity_title":"call","activity_created_by":"User Last","activity_create_date":"03-08-2015","activity_due_date":"04-01-2015","acitvity_url_param":"contact_id","activity_details":"email and call details"})
How can I view the array element in html. for example. if the field is activity_details. How can I only view the activity_details by calling the function and the element?
Here is the code that shows the array:
function list_activity_details_array(){
global $connection;
//$contact_id = $_REQUEST['contact_id'];
$activity_id = $_REQUEST['activity_id'];
$get = "SELECT * FROM activity_base WHERE activity_id = '$activity_id' "
or die("Error: ".mysqli_error($connection));
$query = mysqli_query($connection, $get);
//Get activity base information
$activity_array = array();
while ($activity = mysqli_fetch_array($query)){
$activity_related_to_id = $activity ['activity_related_to_id'];
$activity_id = $activity['activity_id'];
$activity_type_id = $activity['activity_type_id'];
$activity_entity_type_id = $activity['activity_entity_type_id'];
$activity_title = $activity['activity_title'];
$activity_created_by = $activity['activity_created_by'];
$activity_status_code_id = $activity['activity_status_code_id'];
//$activity_type_icon;
//Reverse Date
$activity_create_date = date("m-d-Y", strtotime($activity['activity_created_on']));
$activity_due_date = date("m-d-Y", strtotime($activity['activity_due_date']));
if ($activity_type_id == "1"){
$activity_type_icon = "fa fa-envelope";
}else if ($activity_type_id == "3"){
$activity_type_icon = "fa fa-suitcase";
}else if ($activity_type_id == "2"){
$activity_type_icon = "fa fa-phone";
}
if ($activity_entity_type_id == "1") {
$acitvity_url_param = "acct_id";
$acitivty_is_for ="accounts_base";
//$page_url = "account-profile.php";
}else if ($activity_entity_type_id == "2") {
$acitvity_url_param = "contact_id";
$acitivty_is_for ="contacts";
//$page_url = "contact-profile.php";
}else if ($activity_entity_type_id == "3") {
$acitvity_url_param = "contact_id";
$acitivty_is_for ="contacts";
//$page_url = "contact-profile.php";
}
//Get detailed activity information
//If activity is Email
if ($activity_type_id == "1") {
$email_details = email_activity_details($activity_id);
while ( $email = mysqli_fetch_assoc($email_details)) {
$activity_details = nl2br($email['email_message']);
}
}else if ($activity_type_id == "2") {
$call_details = call_activity_details($activity_id);
while ( $call = mysqli_fetch_assoc($call_details)) {
$activity_details = $call['call_details'];
}
}else if ($activity_type_id == "3") {
$meeting_details = meeting_activity_details($activity_id);
while ( $meeting = mysqli_fetch_assoc($meeting_details)) {
$activity_details = $meeting['meeting_details'];
}
}
//Get creator user info
$user_query = get_user_info($activity_created_by);
while ($user = mysqli_fetch_array($user_query)) {
$activity_created_by = $user['user_full_name'];
}
$activity_array['activity_related_to_id'] = $activity['activity_related_to_id'];
$activity_array['activity_id'] = $activity['activity_id'];
$activity_array['activity_related_to_id'] = $activity['activity_related_to_id'];
$activity_array['activity_type_icon'] = $activity_type_icon;
$activity_array['activity_title'] = $activity['activity_title'];
$activity_array['activity_created_by'] = $activity_created_by;
$activity_array['activity_create_date'] = $activity_create_date;
$activity_array['activity_due_date'] = $activity_due_date;
$activity_array['acitvity_url_param'] = $acitvity_url_param;
$activity_array['activity_details'] = $activity_details;
$activity_array['activity_title'] = $activity['activity_title'];
$encode = json_encode($activity_array);
print_r($encode);
}
}
if (isset($_REQUEST['activity_id'])) {
list_activity_details_array();
}
Looks like JSON to me so you'll need to
$foo = json_decode($output);
Which then should allow you to refer to:
echo $foo['activity_related_to_id'];
// Outputing 2

Pagination can not back to prev number

I have pagination, and my pagination is working fine if I click next number.
View :
1 2 >
if I am clicking on 2 it goes on second page and shows proper result.but if I want to come back on 1 than its not redirect to page 1. here is my controller code:
public function index($date_start = 'all', $date_end = 'all', $title = 'all', $cid = 0, $skpd = 'all', $offset = NULL)
{
if($_POST)
{
$filter = array(
($this->input->post('filter_date_start') == '') ? 'all' : $this->input->post('filter_date_start'),
($this->input->post('filter_date_end') == '') ? 'all' : $this->input->post('filter_date_end'),
($this->input->post('filter_title') == '') ? 'all' : $this->input->post('filter_title'),
($this->input->post('filter_kategori') == 0) ? 0 : $this->input->post('filter_kategori'),
($this->input->post('filter_skpd') == '') ? 'all' : $this->input->post('filter_skpd')
);
$url = implode('/', $filter);
redirect('document/index'.$url);
}
//echo urldecode($title);
$this->load->model('News_model');
$this->load->library('pagination');
$data['title'] = 'Informasi Publik';
$param_document = array('status' => 1);
if(!empty($tid)) $param_document['tid'] = $tid;
if($date_start != 'all') $param_document['date_start'] = $date_start;
if($date_end != 'all') $param_document['date_end'] = $date_end;
if(!empty($cid)) $param_document['cid'] = $cid;
if($title != 'all') $param_document['title'] = urldecode($title);
if($skpd != 'all') $param_document['skpd'] = $skpd;
$params_total = $param_document;
$param_document_berkala = $param_document;
$param_document_serta_merta = $param_document;
$param_document_setiap_saat = $param_document;
$param_document_dikecualikan = $param_document;
$param_document['limit'] = 10;
$param_document['offset'] = $offset;
$data['document'] = $this->Document_model->get($param_document);
//dimodif cara urang
$data['bijilkategori'] = $this->Document_model->tampil();
// get document download count
foreach($data['document'] as $i => $row)
{
$document_transaction = $this->Document_model->get_transaction(array('did' => $row['document_id']));
$data['document'][$i]['download_count'] = empty($document_transaction) ? 0 : $document_transaction[0]['count'];
}
/*
$config['base_url'] = site_url('document/index/'.
(empty($tid) ? 0 : $tid).'/'.$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd
);
*/
$config['base_url'] = site_url('document/index/'.
$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd
);
$config['total_rows'] = count($this->Document_model->get($params_total));
$config['uri_segment'] = 9;
$this->pagination->initialize($config);
$data['main'] = 'document/document_indeks';
$data['kategori'] = $this->get_category();
$data['type'] = $this->get_type(TRUE);
$data['filter_kategori'] = $cid;
//dihidden ku urang
//$data['filter_type'] = $tid;
$data['filter_date_start'] = ($date_start == 'all') ? '' : $date_start;
$data['filter_date_end'] = ($date_end == 'all') ? '' : $date_end;
$data['filter_title'] = ($title == 'all') ? '' : $title;
$data['filter_author'] = ($skpd == 'all') ? '' : $skpd;
$param_document_berkala['tid'] = 1;
$param_document_serta_merta['tid'] = 2;
$param_document_setiap_saat['tid'] = 3;
$param_document_dikecualikan['tid'] = 4;
$data['total_record'] = count($this->Document_model->get($params_total));
$data['total_record_berkala'] = count($this->Document_model->get($param_document_berkala));
$data['total_record_serta_merta'] = count($this->Document_model->get($param_document_serta_merta));
$data['total_record_setiap_saat'] = count($this->Document_model->get($param_document_setiap_saat));
$data['total_record_dikecualikan'] = count($this->Document_model->get($param_document_dikecualikan));
$this->load->view('layout', $data);
}
Model:
public function get($params = array())
{
if(isset($params['fields']))
{
$this->db->select($params['fields']);
}
else
{
$this->db->select('*');
}
if(isset($params['id']))
{
$this->db->where('document.document_id', $params['id']);
}
elseif(isset($params['code']))
{
$this->db->where('document_code', $params['code']);
}
elseif(isset($params['date_start']) AND isset($params['date_end']))
{
$this->db->where('document_date >=', $params['date_start'].' 00:00:00');
$this->db->where('document_date <=', $params['date_end'].' 23:59:59');
}
elseif(isset($params['tid']))
{
$this->db->where('type_id', $params['tid']);
}
elseif(isset($params['cid']))
{
$this->db->where('document.category_id', $params['cid']);
}
elseif(isset($params['uid']))
{
$this->db->where('user_id', $params['uid']);
}
elseif(isset($params['sid']))
{
$this->db->where('document.skpd_id', $params['sid']);
}
if(isset($params['title']))
{
$this->db->like('document_title', $params['title']);
}
if(isset($params['author']))
{
$this->db->like('document_author', $params['author']);
}
elseif(isset($params['date']))
{
$this->db->where('document_date', $params['date']);
}
if(isset($params['dsid']))
{
$this->db->where('document_skpd_id', $params['dsid']);
}
if(isset($params['status']))
{
$this->db->where('document_is_published', $params['status']);
}
if(isset($params['document_sync']))
{
$this->db->where('document_sync', $params['document_sync']);
}
if(isset($params['sync']))
{
$this->db->reset_query();
$this->db->select('document.*');
$this->db->where('document_sync', $params['sync']);
}
if(isset($params['limit']))
{
if(!isset($params['offset']))
{
$params['offset'] = NULL;
}
$this->db->limit($params['limit'], $params['offset']);
}
if(isset($params['order_by']))
{
$this->db->order_by($params['order_by'], 'desc');
}
else
{
$this->db->order_by('document_date', 'desc');
}
$this->db->select('document.document_id');
$this->db->join('user_desktop', 'user_desktop.user_desktop_id = document.operator_id');
$this->db->join('(SELECT document_id, MAX(document_file_id) AS document_file_max_id FROM document_file GROUP BY document_id) AS document_file_max', 'document.document_id = document_file_max.document_id', 'left', FALSE);
$this->db->join('document_file', 'document_file.document_file_id = document_file_max.document_file_max_id', 'left');
$this->db->join('document_type', 'document_type.document_type_id = document.type_id');
$this->db->join('document_form', 'document_form.document_form_id = document.form_id');
$this->db->join('document_category', 'document_category.category_id = document.category_id');
$this->db->join('skpd', 'skpd.skpd_id = document.skpd_id');
$res = $this->db->get('document');
if(isset($params['id']))
{
return $res->row_array();
}
else
{
return $res->result_array();
}
}
Please master how to fix it ? whst is problem on my pagination
Please try this :
$config['base_url'] = site_url('document/index/'.
$date_start.'/'.$date_end.'/'.
$title.'/'.(empty($cid) ? 0 : $cid).'/'.$skpd.'/'
);
$config['uri_segment'] = 8;
in your base_url you missed out / at the end and codeigniter places offset for pagination. Hence, uri_segment would be 8.

How to insert upload images in opencart?

I am beginner to OpenCart eshop. I am trying to create a custom form depending on printing services. I need to insert an uploaded image into MySQL and show it at OpenCart's admin section. How to validate <input type='file'> file type input in OpenCart? In pure PHP there is $_FILES[][] array applicable but how to access submitted files in OpenCart? Please, help me solve it.
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
My custom page controller:
<?php
class ControllerInformationDesign extends Controller {
private $error = array();
public function index() {
/*if (!$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('account/custreview', '', 'SSL');
$this->redirect($this->url->link('account/login', '', 'SSL'));
} */
$this->language->load('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
$this->getForm();
}
public function insert() {
$this->load->language('information/design');
$this->document->setTitle($this->config->get('config_name') . ' - ' . $this->language->get('heading_title'));
$this->load->model('account/custreview');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
$this->model_account_custreview->addReview($this->request->post);
$this->session->data['success'] = $this->language->get('text_success');
$this->redirect($this->url->link('information/design'));
}
$this->getForm();
}
private function getForm() {
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_prefix'] = $this->language->get('entry_prefix');
$this->data['entry_desc'] = $this->language->get('entry_desc');
$this->data['entry_industry'] = $this->language->get('entry_industry');
$this->data['entry_design'] = $this->language->get('entry_design');
$this->data['entry_prefix1'] = $this->language->get('entry_prefix1');
$this->data['entry_other'] = $this->language->get('entry_other');
$this->data['entry_prefix2'] = $this->language->get('entry_prefix2');
$this->data['entry_prefix3'] = $this->language->get('entry_prefix3');
$this->data['entry_prefix4'] = $this->language->get('entry_prefix4');
$this->data['logged'] = $this->customer->getFirstname() . ' ' . $this->customer->getLastName();
$this->data['text_none'] = $this->language->get('text_none');
$this->data['text_select'] = $this->language->get('text_select');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_author'] = $this->language->get('entry_author');
$this->data['entry_rating'] = $this->language->get('entry_rating');
$this->data['entry_review'] = $this->language->get('entry_review');
$this->data['entry_good'] = $this->language->get('entry_good');
$this->data['entry_bad'] = $this->language->get('entry_bad');
$this->data['button_save'] = $this->language->get('continue_shop');
$this->data['button_checkout'] = $this->language->get('check_out');
if (isset($this->error['warning'])) {
$this->data['error_warning'] = $this->error['warning'];
} else {
$this->data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$this->data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$this->data['success'] = '';
}
if (isset($this->error['product'])) {
$this->data['error_product'] = $this->error['product'];
} else {
$this->data['error_product'] = '';
}
if (isset($this->error['product_id'])) {
$this->data['error_product_id'] = $this->error['product_id'];
} else {
$this->data['error_product_id'] = '';
}
if (isset($this->error['author'])) {
$this->data['error_author'] = $this->error['author'];
} else {
$this->data['error_author'] = '';
}
if (isset($this->error['text'])) {
$this->data['error_text'] = $this->error['text'];
} else {
$this->data['error_text'] = '';
}
if (isset($this->error['rating'])) {
$this->data['error_rating'] = $this->error['rating'];
} else {
$this->data['error_rating'] = '';
}
if (isset($this->error['cdesc'])) {
$this->data['error_desc'] = $this->error['cdesc'];
} else {
$this->data['error_desc'] = '';
}
if (isset($this->error['industry'])) {
$this->data['error_industry'] = $this->error['industry'];
} else {
$this->data['error_industry'] = '';
}
if (isset($this->error['design'])) {
$this->data['error_design'] = $this->error['design'];
} else {
$this->data['error_design'] = '';
}
if (isset($this->error['other'])) {
$this->data['error_other'] = $this->error['other'];
} else {
$this->data['error_other'] = '';
}
if (isset($this->error['file'])) {
$this->data['error_file'] = $this->error['file'];
} else {
$this->data['error_file'] = '';
}
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/design','SSL'),
'separator' => ' :: '
);
if (!isset($this->request->get['review_id'])) {
$this->data['action'] = $this->url->link('information/design/insert');
}
$this->data['cancel'] = $this->url->link('information/design','SSL');
if (isset($this->request->get['review_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
$review_info = $this->model_account_custreview->getReview($this->request->get['review_id']);
}
$this->load->model('catalog/category');
$this->data['categories'] = $this->model_catalog_category->getCategories(0);
$this->load->model('catalog/product');
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
$product_info = $this->model_catalog_product->getProduct($this->request->post['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
$product_info = $this->model_catalog_product->getProduct($review_info['product_id']);
if ($product_info) {
$this->data['product'] = $product_info['name'];
} else {
$this->data['product'] = '';
}
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product_id'])) {
$this->data['product_id'] = $this->request->post['product_id'];
} elseif (isset($review_info)) {
$this->data['product_id'] = $review_info['product_id'];
} else {
$this->data['product_id'] = '';
}
if (isset($this->request->post['product'])) {
$this->data['product'] = $this->request->post['product'];
} elseif (isset($review_info)) {
$this->data['product'] = $review_info['product'];
} else {
$this->data['product'] = '';
}
if (isset($this->request->post['author'])) {
$this->data['author'] = $this->request->post['author'];
} elseif (isset($review_info)) {
$this->data['author'] = $review_info['author'];
} else {
$this->data['author'] = '';
}
if (isset($this->request->post['text'])) {
$this->data['text'] = $this->request->post['text'];
} elseif (isset($review_info)) {
$this->data['text'] = $review_info['text'];
} else {
$this->data['text'] = '';
}
if (isset($this->request->post['rating'])) {
$this->data['rating'] = $this->request->post['rating'];
} elseif (isset($review_info)) {
$this->data['rating'] = $review_info['rating'];
} else {
$this->data['rating'] = '';
}
if (isset($this->request->post['cdesc'])) {
$this->data['cdesc'] = $this->request->post['cdesc'];
} elseif (isset($review_info)) {
$this->data['cdesc'] = $review_info['cdesc'];
} else {
$this->data['cdesc'] = '';
}
if (isset($this->request->post['industry'])) {
$this->data['industry'] = $this->request->post['industry'];
} elseif (isset($review_info)) {
$this->data['industry'] = $review_info['industry'];
} else {
$this->data['industry'] = '';
}
if (isset($this->request->post['design'])) {
$this->data['design'] = $this->request->post['design'];
} elseif (isset($review_info)) {
$this->data['design'] = $review_info['design'];
} else {
$this->data['design'] = '';
}
if (isset($this->request->post['other'])) {
$this->data['other'] = $this->request->post['other'];
} elseif (isset($review_info)) {
$this->data['other'] = $review_info['other'];
} else {
$this->data['other'] = '';
}
if (isset($this->request->post['file'])) {
$this->data['file'] = $this->request->post['file'];
} elseif (isset($review_info)) {
$this->data['file'] = $review_info['file'];
} else {
$this->data['file'] = '';
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/design.tpl')) {
$this->template = $this->config->get('config_template') . '/template/information/design.tpl';
} else {
$this->template = 'default/template/information/design.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
private function validateForm() {
/*if (!$this->request->post['product_id']) {
$this->error['product'] = $this->language->get('error_product');
}
if (!$this->request->post['product_id']) {
$this->error['product_id'] = $this->language->get('error_product_id');
}*/
if ((strlen(utf8_decode($this->request->post['author'])) < 3) || (strlen(utf8_decode($this->request->post['author'])) > 64)) {
$this->error['author'] = $this->language->get('error_author');
}
/*
if (strlen(utf8_decode($this->request->post['text'])) < 1) {
$this->error['text'] = $this->language->get('error_text');
}*/
/*if (!isset($this->request->post['rating'])) {
$this->error['rating'] = $this->language->get('error_rating');
}
if (!isset($this->request->post['file'])) {
$this->error['file'] = $this->language->get('error_file');
}*/
if ((strlen(utf8_decode($this->request->post['cdesc'])) < 3) || (strlen(utf8_decode($this->request->post['cdesc'])) > 1000)) {
$this->error['cdesc'] = $this->language->get('error_desc');
}
if ((strlen(utf8_decode($this->request->post['industry'])) < 3) || (strlen(utf8_decode($this->request->post['industry'])) > 1000)) {
$this->error['industry'] = $this->language->get('error_industry');
}
if ((strlen(utf8_decode($this->request->post['design'])) < 3) || (strlen(utf8_decode($this->request->post['design'])) > 1000)) {
$this->error['design'] = $this->language->get('error_design');
}
if ((strlen(utf8_decode($this->request->post['other'])) < 3) || (strlen(utf8_decode($this->request->post['other'])) > 1000)) {
$this->error['other'] = $this->language->get('error_other');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
public function autocomplete() {
$json = array();
if (isset($this->request->post['filter_name'])) {
$this->load->model('catalog/product');
$data = array(
'filter_name' => $this->request->post['filter_name'],
'start' => 0,
'limit' => 20
);
$results = $this->model_catalog_product->getProducts($data);
foreach ($results as $result) {
$json[] = array(
'product_id' => $result['product_id'],
'name' => html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'),
'model' => $result['model'],
'price' => $result['price']
);
}
}
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
}
}
?>
How to handle file upload in OpenCart and how to insert uploaded files into database? How to solve it? Please guide me...

Categories