-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_csv.inc.php
182 lines (154 loc) · 4.83 KB
/
generate_csv.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
function compileFieldAsTxt($row,$field,$value)
{
if($value == "") return "";
global $id_rapport_to_label;
global $dont_export_doc_fields;
global $fieldsTypes;
global $fieldsAll;
global $tous_avis;
global $export_doc_fields;
$title = compute_title($row, $field);
if(isset($fieldsTypes[$field]) && $fieldsTypes[$field] == "avis" && isset($tous_avis[$value]))
{
$value = $tous_avis[$value];
}
if(isset($fieldsTypes[$field]) && $fieldsTypes[$field] == "treslong")
{
return "<B>".$title."</B><br/><table border=\"1\"><tr><td>".html_entity_decode($value)."</td></tr></table><br/><br/>";
}
else
{
return "<p><B>".$title."</B>:".html_entity_decode($value)."</p>";
}
}
function compileObjectAsTXT($row)
{
return "hello";
}
function compileObjectsAsTXT($rows)
{
$result = "";
$first = true;
$result .= "<head> <meta charset=\"UTF-8\"> </head><br/>";
$result .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
/*
$result .= "****************************************************\n";
$result .= "Pour un bon affichage des accents: sélectionner 'UTF-8' n";
$result .= "****************************************************\n";
*/
global $id_rapport_to_label;
global $dont_export_doc_fields;
global $fieldsTypes;
global $fieldsAll;
global $tous_avis;
global $export_doc_fields;
foreach($rows as $row)
{
$result .= "<h2>".$id_rapport_to_label[$row->type]."</h2>";
if(is_rapport_chercheur($row) || is_rapport_concours($row))
$result .= "<h3>".$row->nom." ".$row->prenom."</h3>";
foreach( $export_doc_fields as $field)
if(isset($row->$field))
$result .= compileFieldAsTxt($row,$field,$row->$field);
if(is_rapport_chercheur($row))
{
$candidat = get_or_create_candidate($row);
foreach($candidat as $field => $value)
if(is_field_visible($row, $field) && !in_array($field, $dont_export_doc_fields) && !in_array($field,$export_doc_fields))
$result .=
compileFieldAsTxt($row, $field,$candidat->$field);
}
else if(is_rapport_concours($row))
{
$candidat = get_candidate_from_concoursid($row->concoursid);
foreach($candidat as $field => $value)
if(is_field_visible($row, $field) && !in_array($field, $dont_export_doc_fields) && !in_array($field,$export_doc_fields))
$result .=
compileFieldAsTxt($row, $field,$candidat->$field);
}
foreach($row as $field => $value)
if(is_field_visible($row, $field) && !in_array($field, $dont_export_doc_fields) && !in_array($field,$export_doc_fields))
$result .= compileFieldAsTxt($row, $field,$value);
$result.="<br/>\f";
}
return $result;
}
function compileObjectsAsCSV($fields, $rows, $text=array(), $sep =";" , $enc='"', $del="\n")
{
global $csv_composite_fields;
global $typesRapportsAll;
$result = "";
$first = true;
foreach($text as $mots)
{
foreach($mots as $mot)
$result.=$sep.$enc.$mot.$enc;
$result.=$del;
}
foreach($fields as $field)
{
$result.= ($first ? "" : $sep) .$enc.$field.$enc;
$first = false;
}
global $fieldsTypes;
global $tous_avis;
$result.=$del;
$users = simpleListUsers();
foreach($rows as $row)
{
$first = true;
foreach($fields as $field)
{
if(isset($csv_composite_fields[$field]))
{
$subfields = $csv_composite_fields[$field];
$result.= ($first ? "" : $sep).$enc;
foreach($subfields as $subfield)
$result.=(isset($row->$subfield) ? str_replace($enc, '#', html_entity_decode($row->$subfield)) :"")." ";
$result.= $enc;
}
else if(isset($row->$field) && $row->$field != "")
{
if(substr($field,0,4)=="rapp" && isset($users[$row->$field]))
$row->$field = $users[$row->$field];
$data = str_replace(array($sep,$enc,"<br />"), array('#','#',""), html_entity_decode($row->$field));
if($field == "type" && isset($row->$field) && isset($typesRapportsAll[$data]))
$data = $typesRapportsAll[$data];
else if(isset($fieldsTypes[$field]) && $fieldsTypes[$field] == "avis" && isset($tous_avis[$data]))
$data = $tous_avis[$data];
$result .= ($first ? "" : $sep).$enc.$data.$enc;
}
else
$result .= ($first ? "" : $sep).$enc.$enc;
$first = false;
}
$result.=$del;
}
return $result;
}
function compileReportsAsCSV($rows, $fields = null)
{
global $mandatory_export_fields;
$activefields = $fields;
if($activefields == null)
$activefields = array_unique(array_merge($mandatory_export_fields, get_editable_fields($rows[0])));
if(count($rows) < 1)
{
$fakerow = (object) array();
foreach($fields as $field)
$fakerow->$field = "à remplacer par ".$field;
$fakerow->type = "EvalVague";
$rows[] = $fakerow;
}
return compileObjectsAsCSV($activefields, $rows);
}
function compileUnitsAsCSV($rows)
{
global $fieldsUnitsDB;
$fields = array();
foreach($fieldsUnitsDB as $field => $value)
$fields[] = $field;
return compileObjectsAsCSV($fields, $rows);
}
?>