noalyss Version-9
export_follow_up_contact_csv.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2020) Author Dany De Bontridder <danydb@noalyss.eu>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
26$ag_id=$http->get("ag_id", "number");
27
28if ( $g_user->can_read_action($ag_id) == false ) return;
29
30
31/**
32 * @file
33 * @brief export a follow up in CSV
34 */
35$csv=new Noalyss_CSV("followup".$ag_id);
36$csv->send_header();
37
38$document_type=$cn->get_value("select ag_type from action_gestion where ag_id=$1",[$ag_id]);
39
40$aRow=$cn->get_array("select a.f_id,ap_id,ag_id,f.ad_value,f.ad_id,fd.fd_id,jfa.jnt_order
41from action_person a
42join fiche f1 on (a.f_id=f1.f_id)
43join fiche_detail f on (a.f_id=f.f_id)
44join fiche_def fd on (fd.fd_id=f1.fd_id)
45join jnt_fic_attr jfa on (fd.fd_id=jfa.fd_id and jfa.ad_id=f.ad_id)
46where ag_id=$1
47order by f1.fd_id, a.f_id,jnt_order",[$ag_id]);
48
49$nb=count($aRow);
51for ($i=0;$i< $nb;$i++)
52{
53
54 // for each card we sent all info
55 if ($lastcard != $aRow[$i]['f_id']) {
56 // Write contact option
57 $aOption=$cn->get_array(" select ap_value
58from
59action_person a
60join action_person_option apo on (a.ap_id=apo.action_person_id)
61join contact_option_ref cor on (cor.cor_id=apo.contact_option_ref_id)
62where ag_id=$1 and f_id=$2 order by cor_id",array($ag_id,$lastcard));
63 $nb_option=count($aOption);
64 for ($h=0;$h < $nb_option;$h++) {
65 $csv->add($aOption[$h]['ap_value']);
66 }
67 $csv->write();
68 $lastcard=$aRow[$i]['f_id'];
69 }
70 // For each category we send the column header
71 if ( $lastcat != $aRow[$i]['fd_id']) {
72 // Get attribut fd
73 $aColHeader = $cn->get_array("select jnt_order,
74 ad_text,
75 ad_type
76 from fiche_def f
77 join jnt_fic_attr jfa using (fd_id)
78 join attr_def ad using (ad_id)
79 where
80 f.fd_id=$1
81 order by jnt_order",[$aRow[$i]['fd_id']]);
82 $aCol=array();
83 $nb_col=count($aColHeader);
84 for ( $j = 0;$j < $nb_col;$j++) {
85 $aCol[]=$aColHeader[$j]['ad_text'];
86 }
87
88 // Add contact header option
89 $aOptionCat=$cn->get_array("select
90 cor.cor_label
91 from
92 public.jnt_document_option_contact jdoc
93 join contact_option_ref cor on
94 (jdoc.contact_option_ref_id = cor_id )
95 where
96 document_type_id = $1
97 and jdoc_enable = 1 order by cor_id",array($document_type));
98 $nb_col=count($aOptionCat);
99 for ( $j = 0;$j < $nb_col;$j++) {
100 $aCol[]=$aOptionCat[$j]['cor_label'];
101 }
102 $csv->write_header($aCol);
103 $lastcat=$aRow[$i]['fd_id'];
104 }
105 $csv->add($aRow[$i]['ad_value']);
106
107}
108$aOption=$cn->get_array(" select ap_value
109from
110action_person a
111join action_person_option apo on (a.ap_id=apo.action_person_id)
112join contact_option_ref cor on (cor.cor_id=apo.contact_option_ref_id)
113where ag_id=$1 and f_id=$2 order by cor_id",array($ag_id,$lastcard));
115for ($h=0;$h < $nb_option;$h++) {
116 $csv->add($aOption[$h]['ap_value']);
117}
118$csv->write();
global $g_user
if no group available , then stop
manage the http input (get , post, request) and extract from an array
for($i=0;$i< $nb;$i++) $aOption