Joywork/ajax/getGridTableRaportExport.php

218 lines
7.8 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?php
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
//error_reporting(E_ALL | E_STRICT);
//ini_set('display_errors', 1);
?>
<div id="table-order_export" style="margin-left: 20px; " class="crm__new-client"></div>
<!-- <div class="buttons-toolbar" style="padding-top: 15px">-->
<div id="table-order_export-selection-fixed" class="bootstrap-table bootstrap4" style="display:none; position:absolute;z-index: 999;">
<div class="fixed-table-container fixed-height" style="border-bottom: 0;">
<table style="border-bottom: 0px;" class="table table-bordered table-hover">
<thead style="border-bottom: 0px;"></thead>
</table>
</div>
<div class="fixed-table-body">
<table class="table table-bordered table-hover">
<tbody>
</tbody>
</table>
</div>
</div>
<table class="table"
id="table-order_export-selection"
data-locale="ru-RU"
data-height="530"
data-ajax="ajaxRequestExportRaport"
data-loading-template="loadingTemplate"
>
<thead>
<?php
$pdo = new MysqlPdo(hst, ndb, user, pass);
$sql = "SET NAMES 'utf8'";
$pdo->query($sql);
$agency_id = (int)$_POST['agency_id'];
$user_id = (int)$_POST['user_id'];
$type = $_POST['type'];
$raport_id = (int)$_POST['raport_id'];
$columns = array();
$columnsCastom = array();
$columnsFunnels = array();
$ec = new ExportClass();
$data = (object)array('user_id'=>$user_id, 'type'=>$type, 'raport_id'=>$raport_id);
$columnsTemp = $ec->getSettingsExport($data);
$ec->set_agency($agency_id);
$namesTitle = $ec->get_columns_title();
$rowspan = 1;
if(!empty($columnsTemp['fields_fixes'])){
$columns = $columnsTemp['fields_fixes'];
}
if(!empty($columnsTemp['fields_castom'])){
$columnsCastom = $columnsTemp['fields_castom'];
}
if(!empty($columnsTemp['fields_funnels'])){
$columnsFunnels = $columnsTemp['fields_funnels'];
foreach($columnsFunnels as $cf){
foreach($cf['steps'] as $cfs){
if($cfs['is_active'] == 1){
$rowspan = 2;
} else {
foreach($cfs['fields'] as $cfsf){
if($cfsf['is_active'] == 1){
$rowspan = 2;
break;
}
}
}
}
}
}
$row_header2 = array();
//Список воронок
$sql_funnels = "SELECT * FROM funnel WHERE agency_id = {$agency_id}";
$q_funnels = $pdo->query($sql_funnels);
while($r_funnels = $pdo->fetch_assoc($q_funnels)){
$funnels[$r_funnels['id']] = $r_funnels;
$funnelsIds[] = $r_funnels['id'];
}
//Список этапов
if(!empty($funnelsIds)){
$sql_s_n = "SELECT name, funnel_id, id, next_step, pole_end_list FROM funnel_steps WHERE funnel_id in (".implode(',',$funnelsIds).")";
$q_s_n = $pdo->query($sql_s_n);
while($r_s_n = $pdo->fetch_assoc($q_s_n)){
$r_s_n['fields'] = json_decode(htmlspecialchars_decode($r_s_n['pole_end_list']), true);
$steps[$r_s_n['id']] = $r_s_n;
}
}
?>
<tr>
<?php
foreach($columns as $key => $column){
if($column == 1){
$nameCol = $key;
$title = $namesTitle[$key];
?>
<th data-field="<?=$nameCol?>" data-cell-style="cellStyle" data-class="table_white" data-switchable="false" rowspan="<?=$rowspan?>"><?=$title?></th>
<?php
}
}
foreach($columnsCastom as $key => $column){
if($column['val'] == 1){
$nameCol = $key;
$title = $column['title'];
?>
<th data-field="<?=$nameCol?>" data-cell-style="cellStyle" data-class="table_white" data-switchable="false" rowspan="<?=$rowspan?>"><?=$title?></th>
<?php
}
}
foreach ($columnsFunnels as $key_cf => $cf){
// var_dump($cf);
if($cf['is_active'] == 1 && isset($funnels[$key_cf])){
foreach($cf['steps'] as $key_st => $st){
$step_visible = false;
// if($st['is_active'] == 1){
$nameCol = $key_st;
$colspan = 0;
if($st['is_active'] == 1){
$colspan = 2;
$step_visible = true;
}
$title = $steps[str_replace('step', '', $key_st)]['name'];
if($colspan > 0){
for($i=0; $i<$colspan; $i++){
if($i==0){
$name2 = 'Дата';
} else if($i==1){
$name2 = 'Ответственные';
}
if($i==0){
$row_header2[] = array('name'=>$key_st, 'title'=>$name2);
} else
if($i==1){
$row_header2[] = array('name'=>str_replace('step', 'step_2',$key_st), 'title'=>$name2);
}
}
}
foreach($st['fields'] as $key_f => $sf){
if($sf['is_active'] == 1 && isset($steps[str_replace('step', '', $key_st)]['fields'][$key_f])){
$step_visible = true;
$colspan++;
$name3 = $steps[str_replace('step', '', $key_st)]['fields'][$key_f]['name'];
$row_header2[] = array('name'=>$key_st.'field'.$key_f, 'title'=>$name3);
}
}
if($step_visible){
?>
<th data-field="<?=$nameCol?>" data-cell-style="cellStyle" data-class="table_white" data-switchable="false" colspan="<?=$colspan?>"><?=$title?></th>
<?php
}
}
}
}
?>
</tr>
<?php
if(!empty($row_header2)){
?>
<tr>
<?php
foreach($row_header2 as $row){
?>
<th data-field="<?=$row['name']?>" data-cell-style="cellStyle" data-class="table_white" data-switchable="false" ><?=$row['title']?></th>
<?php
}
?>
</tr>
<?php
}
?>
</thead>
</table>
</div>