<?php
/**
* Menu-callback PARA JAVASCRIPT PSEUDO-AJAX
*/
function simulador_js()
{
######################################################
$cache =
cache_get('form_'.
$_POST['form_build_id'],
'cache_form');
$node = (object)$_POST;
$form = $cache->data;
######################################################
// DECLARA QUE É UM ARRAY DE ELEMENTOS
$new_obj['arr_prd']['#tree'] = TRUE;
$new_obj['arr_de']['#tree'] = TRUE;
$new_obj['arr_ate']['#tree'] = TRUE;
$new_obj['arr_taxa']['#tree'] = TRUE;
$prod = $_POST['preconf_prod'];
$de = $_POST['preconf_de'];
$ate = $_POST['preconf_ate'];
$taxa = $_POST['preconf_taxa'];
// Validando
{
'status' => FALSE, 'data' =>
'<div class="messages error">
Preencha os campos: "Produto", "De", "Ate" e "Taxa"!
</div>'
)
);
}
// Itens ta tabela
$post_de = '';
$key = '0';
// Pegando os valores ja existentes no form
if (isset($node->
arr_prd))
{
if (count($node->
arr_prd) >
0)
{
foreach ($node->arr_prd as $key=>$post_prod)
{
$post_de = $node->arr_de[$key];
$post_ate = $node->arr_ate[$key];
$post_taxa = $node->arr_taxa[$key];
$post_prod,
$post_de,
$post_ate,
$post_taxa,
'#type' => 'image_button',
'#name' => 'del['.$key.']',
'#id' => 'del_'.$key,
'#submit' => FALSE,
'#src' => $img_del,
'#attributes' =>
array('OnClick'=>
'delLn("'.
$key.
'"); return false'),
)
)
);
$new_obj['arr_prd'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_prd['.$key.']',
'#id' => 'arr_prd_'.$key,
'#value' => $post_prod,
'#default_value'=> $post_prod,
);
$new_obj['arr_de'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_de['.$key.']',
'#id' => 'arr_de_'.$key,
'#value' => $post_de,
'#default_value'=> $post_de,
);
$new_obj['arr_ate'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_ate['.$key.']',
'#id' => 'arr_ate_'.$key,
'#value' => $post_ate,
'#default_value'=> $post_ate,
);
$new_obj['arr_taxa'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_taxa['.$key.']',
'#id' => 'arr_taxa_'.$key,
'#value' => $post_taxa,
'#default_value'=> $post_taxa,
);
}
}
}
$key++;
// Adiciona os novos valores
$prod,
$de,
$ate,
$taxa,
'#type' => 'image_button',
'#name' => 'del['.$key.']',
'#id' => 'del_'.$key,
'#submit' => FALSE,
'#src' => $img_del,
'#attributes' =>
array('OnClick'=>
'delLn("'.
$key.
'"); return false'),
)
)
);
$new_obj['arr_prd'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_prd['.$key.']',
'#id' => 'arr_prd_'.$key,
'#value' => $prod,
'#default_value'=> $prod,
);
$new_obj['arr_de'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_de['.$key.']',
'#id' => 'arr_de_'.$key,
'#value' => $de,
'#default_value'=> $de,
);
$new_obj['arr_ate'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_ate['.$key.']',
'#id' => 'arr_ate_'.$key,
'#value' => $ate,
'#default_value'=> $ate,
);
$new_obj['arr_taxa'][$key] =
array(
'#type' => 'hidden',
'#name' => 'arr_taxa['.$key.']',
'#id' => 'arr_taxa_'.$key,
'#default_value'=> $taxa,
'#value' => $taxa,
);
$cache->data += $new_obj;
$header =
array(t('Produto'), t
('De'), t
('Até'), t
('Taxa'), t
('Del'));
// Não usar drupal_json() pois causa problemas em alguns navegadores.
}
?>
by Romeu Godoi - romeu.godoi@gmail.com