admin_simone

TipologiaSnippet
Contenuto

if (!function_exists('get_all_form_fields')) {

function get_all_form_fields($form_id){

 

$form = RGFormsModel::get_form_meta($form_id);

$fields = array();

 

if(is_array($form["fields"])){

foreach($form["fields"] as $field){

if(isset($field["inputs"]) && is_array($field["inputs"])){

 

foreach($field["inputs"] as $input)

if (isset($field['adminLabel']) && $field['adminLabel'] != "" ) $fields[] =  array($input["id"], $field['adminLabel']);

else $fields[] = array($input["id"], GFCommon::get_label($field, $input["id"]));

}

else if(!rgar($field, 'displayOnly')){

if (isset($field['adminLabel']) && $field['adminLabel'] != "" ) $fields[] =  array($field["id"], $field['adminLabel']);

else $fields[] =  array($field["id"], GFCommon::get_label($field));

}

}

}

/*echo "<pre>";

print_r($fields);

echo "</pre>";*/

return $fields;

}

}

 

global $name;

global $myform;

global $entry;

global $sorting_direction;

global $sorting_parameter;

$name = $nome;

$myform = $form_id;

$entry = $entry_id;

$sorting_direction = $sorting_dir;

$sorting_parameter = $sorting_par;

 

 

 

add_filter( 'cs_looper_custom_'.$name, function( $result, $params ) {

 

 

 

$looper = array();

global $name;

global $myform;

global $entry;

global $sorting_direction;

global $sorting_parameter;

 

if ($_GET['entry_id']!='') $entry=$_GET['entry_id'];

 

 

$form_fields = get_all_form_fields($myform);

//echo 'parametro 1: '.$params[0]['parametro'];

//echo 'parametro 2: '.$params[1]['parametro'];

//print_r($params);

 

if ($params[0]['parametro']!='') {

$search_criteria = array(

'status'    => 'active',

);

foreach ($params as $param) {

$search_criteria['field_filters'][] = array( 'key' => $param['parametro'], 'value' => $param['valore'] );

}

//$search_criteria['field_filters'][] = array( 'key' => $params[0]['parametro'], 'value' => $params[0]['valore'] );

//$search_criteria['field_filters'][] = array( 'key' => $params[1]['parametro'], 'value' => $params[1]['valore'] );

}

else {

$search_criteria = array(

'status'    => 'active',

);

}

 

//print_r($search_criteria);

 

if ($_GET['code']!='') $search_criteria['field_filters'][] = array( 'key' => 'fg_easypassthrough_token', 'value' => $_GET['code'] );

if ($sorting_direction!='') $sorting = array( 'key' => $sorting_parameter, 'direction' => $sorting_direction);

else $sorting = array();

$paging = array( 'offset' => 0, 'page_size' => 100000000);

$results = GFAPI::get_entries( $myform, $search_criteria, $sorting, $paging );

 

if ($entry!='') {

foreach ($form_fields as $form_field) {

//echo '*'.gform_get_meta( $entry, $form_field[0] );

$risultato[$form_field[1]] = str_replace('|:||:||:||:|','',gform_get_meta( $entry, $form_field[0] ));

$risultato['is_approved'] = $result['is_approved'];

//print_r($form_field);

}

$risultato['entry_id'] = $entry;

array_push($looper,$risultato);

}

else {

foreach ($results as $result) {

 

foreach ($form_fields as $form_field) {

$risultato[$form_field[1]] = str_replace('|:||:||:||:|','',$result[$form_field[0]]);

}

 

//print_r($form_field);

 

$risultato['entry_id'] = $result['id'];

$risultato['creato_il'] = date('d-m-Y H:i', strtotime($result['date_created']));

$risultato['user_id'] = $result['created_by'];

$risultato['is_approved'] = $result['is_approved'];

if (isset($_GET['fuid'])) {

$entry_id_anagrafica = get_user_meta($_GET['fuid'],'entry_id_anagrafica',true);

$risultato['fuid'] = $entry_id_anagrafica;

}

 

 

 

 

array_push($looper,$risultato);

}

}

//print_r($looper);

return $looper;

}, 10, 2);