documents_list_copies.php 27.4 KB
Newer Older
1
2
<?php
/**
3
4
5
6
7
8
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.

* @brief   documents_list_copies
* @author  dev <dev@maarch.org>
Alex ORLUC's avatar
Alex ORLUC committed
9
* @ingroup apps
10
*/
11

Alex ORLUC's avatar
Alex ORLUC committed
12
13
14
15
16
require_once 'core/class/class_request.php';
require_once 'core/class/class_security.php';
require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_contacts_v2.php';
require_once 'core/class/class_manage_status.php';
require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_lists.php';
Alex ORLUC's avatar
Alex ORLUC committed
17
            
18
19
20
21
$status_obj = new manage_status();
$security   = new security();
$core_tools = new core_tools();
$request    = new request();
22
$contact    = new contacts_v2();
23
24
25
$list       = new lists();

//Include definition fields
26
require_once 'apps/' . $_SESSION['config']['app_id'] . '/definition_mail_categories.php';
Alex ORLUC's avatar
Alex ORLUC committed
27
28

//Order
29
30
31
32
33
34
35
36
37
38
39
40
41
$order = $order_field = '';
$order = $list->getOrder();
$order_field = $list->getOrderField();
$_SESSION['save_list']['order'] = $order;
$_SESSION['save_list']['order_field'] = $order_field;
//URL extra Parameters  
$parameters = '';
$start = $list->getStart();
if (!empty($order_field) && !empty($order)) $parameters .= '&order='.$order.'&order_field='.$order_field;
if (!empty($what)) $parameters .= '&what='.$what;
if (!empty($selectedTemplate)) $parameters .= '&template='.$selectedTemplate;
if (!empty($start)) $parameters .= '&start='.$start;
$_SESSION['save_list']['start'] = $start; 
Alex ORLUC's avatar
Alex ORLUC committed
42
43


44

45
46
47
//Keep some parameters
$parameters = '';
if (isset($_REQUEST['order']) && !empty($_REQUEST['order'])) {
Alex ORLUC's avatar
Alex ORLUC committed
48

49
    $parameters .= '&order='.$_REQUEST['order'];
Alex ORLUC's avatar
Alex ORLUC committed
50
51
    $_SESSION['save_list']['order'] = $_REQUEST['order'];

52
    if (isset($_REQUEST['order_field']) && !empty($_REQUEST['order_field'])) {
Alex ORLUC's avatar
Alex ORLUC committed
53
54
55
56
        $parameters .= '&order_field='.$_REQUEST['order_field'];
        $_SESSION['save_list']['order_field'] = $_REQUEST['order_field'];
    } 
}
57
if (isset($_REQUEST['what']) && !empty($_REQUEST['what'])) {
Alex ORLUC's avatar
Alex ORLUC committed
58
59
    $parameters .= '&what='.$_REQUEST['what'];
}
60
if (isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
Alex ORLUC's avatar
Alex ORLUC committed
61
62
    $parameters .= '&template='.$_REQUEST['template'];
}
63
if (isset($_REQUEST['start']) && !empty($_REQUEST['start'])) {
Alex ORLUC's avatar
Alex ORLUC committed
64
65
    $parameters .= '&start='.$_REQUEST['start'];
    $_SESSION['save_list']['start'] = $_REQUEST['start'];
66
67
}

68
69
70
71
72
//URL extra parameters
$urlParameters = '';
//origin
if ($_REQUEST['origin'] == 'searching') $urlParameters .= '&origin=searching';

Alex ORLUC's avatar
Alex ORLUC committed
73

Alex ORLUC's avatar
Alex ORLUC committed
74
//Basket information
75
if (!empty($_SESSION['current_basket']['view'])) {
Alex ORLUC's avatar
Alex ORLUC committed
76
    $table = $_SESSION['current_basket']['view'];
77
} else {
Alex ORLUC's avatar
Alex ORLUC committed
78
    $table = $_SESSION['current_basket']['table'];
79
80
81
82
}
$_SESSION['origin'] = 'basket';
$_SESSION['collection_id_choice'] = $_SESSION['current_basket']['coll_id'];//Collection

Alex ORLUC's avatar
Alex ORLUC committed
83
84
//Table
$select[$table]= array(); 
85

Alex ORLUC's avatar
Alex ORLUC committed
86
//Fields
87
88
89
90
91
array_push(
    $select[$table], "res_id", "status", "category_id as category_img", 
    "contact_firstname", "contact_lastname", "contact_society", "user_lastname", 
    "user_firstname", "priority", "creation_date", "admission_date", "subject", 
    "process_limit_date", "entity_label", "dest_user", "category_id", "type_label", 
Giovannoni Laurent's avatar
Giovannoni Laurent committed
92
93
    "address_id", "exp_user_id", "doc_custom_n1 as count_attachment", "alt_identifier", 
    "is_multicontacts", "locker_user_id", "locker_time", "doc_custom_n2 as viewed"
94
);
Alex ORLUC's avatar
Alex ORLUC committed
95
                        
96
if ($core_tools->is_module_loaded("cases") == true) {
Alex ORLUC's avatar
Alex ORLUC committed
97
98
    array_push($select[$table], "case_id", "case_label", "case_description");
}
99

Florian Azizian's avatar
Florian Azizian committed
100
$arrayPDO = array();
101
//Where clause
Alex ORLUC's avatar
Alex ORLUC committed
102
$where_tab = array();
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//From basket
if (!empty($_SESSION['current_basket']['clause'])) $where_tab[] = '('.stripslashes($_SESSION['current_basket']['clause']).')'; //Basket clause
//From filters
$filterClause = $list->getFilters(); 
if (!empty($filterClause)) $where_tab[] = $filterClause;//Filter clause
//From search
if ((isset($_REQUEST['origin']) && $_REQUEST['origin'] == 'searching') 
    && !empty($_SESSION['searching']['where_request'])
) {
    $where_tab[] = $_SESSION['searching']['where_request']. '(1=1)';
    $arrayPDO = array_merge($arrayPDO, $_SESSION['searching']['where_request_parameters']);
}
//Build where
$where = implode(' and ', $where_tab);
Alex ORLUC's avatar
Alex ORLUC committed
117

118
//Order
Alex ORLUC's avatar
Alex ORLUC committed
119

Alex ORLUC's avatar
Alex ORLUC committed
120
121
122
123
$order = $order_field = '';
$order = $list->getOrder();
$order_field = $list->getOrderField();
if (!empty($order_field) && !empty($order)) {
124
    if ($_REQUEST['order_field'] == 'alt_identifier') {
Alex ORLUC's avatar
Alex ORLUC committed
125
        $orderstr = "order by order_alphanum(alt_identifier)"." ".$order;
126
    } else {
127
        $orderstr = "order by ".$order_field." ".$order;
Alex ORLUC's avatar
Alex ORLUC committed
128
    }
129
130
131
    $_SESSION['last_order_basket'] = $orderstr;
} else if (!empty($_SESSION['save_list']['order']) && !empty($_SESSION['save_list']['order_field'])) {
    if ($_SESSION['save_list']['order_field'] == 'alt_identifier') {
Alex ORLUC's avatar
Alex ORLUC committed
132
        $orderstr = "order by order_alphanum(alt_identifier)"." ".$_SESSION['save_list']['order'];
133
    } else {
Alex ORLUC's avatar
Alex ORLUC committed
134
        $orderstr = "order by ".$_SESSION['save_list']['order_field']." ".$_SESSION['save_list']['order'];
135
    }
Alex ORLUC's avatar
Alex ORLUC committed
136
    $_SESSION['last_order_basket'] = $orderstr;
137
} else {
Alex ORLUC's avatar
Alex ORLUC committed
138
    $list->setOrder();
139
140
    $list->setOrderField('res_id');
    $orderstr = "order by res_id desc";
141
    $_SESSION['last_order_basket'] = $orderstr;
Alex ORLUC's avatar
Alex ORLUC committed
142
143
144
}

//Request
Florian Azizian's avatar
Florian Azizian committed
145
$tab=$request->PDOselect($select, $where, $arrayPDO, $orderstr, $_SESSION['config']['databasetype'], $_SESSION['config']['databasesearchlimit'], false, "", "", "", false, false, 'distinct');
Alex ORLUC's avatar
Alex ORLUC committed
146
147
148
149
150
151
152
153

$_SESSION['current_basket']['last_query'] = array();
$_SESSION['current_basket']['last_query']['select'] = $select;
$_SESSION['current_basket']['last_query']['where'] = $where;
$_SESSION['current_basket']['last_query']['arrayPDO'] = $arrayPDO;
$_SESSION['current_basket']['last_query']['orderstr'] = $orderstr;

//$request->show(); exit;
154
//Templates
Alex ORLUC's avatar
Alex ORLUC committed
155
156
$defaultTemplate = 'documents_list_copies';
$selectedTemplate = $list->getTemplate();
157
if (empty($selectedTemplate)) {
Alex ORLUC's avatar
Alex ORLUC committed
158
159
160
    if (!empty($defaultTemplate)) {
        $list->setTemplate($defaultTemplate);
        $selectedTemplate = $list->getTemplate();
161
    }
Alex ORLUC's avatar
Alex ORLUC committed
162
163
164
165
}
$template_list = array();
array_push($template_list, 'documents_list_copies');
if($core_tools->is_module_loaded('cases')) array_push($template_list, 'cases_list');
166

Alex ORLUC's avatar
Alex ORLUC committed
167
168
169
170
//For status icon
$extension_icon = '';
if($selectedTemplate <> 'none') $extension_icon = "_big"; 

Florian Azizian's avatar
Florian Azizian committed
171
$db = new Database();
172
$addressId = 0;
Alex ORLUC's avatar
Alex ORLUC committed
173
//Result Array
174
175
176
177
178
179
180
181
for ($i=0;$i<count($tab);$i++) {

    for ($j=0;$j<count($tab[$i]);$j++) {

        foreach (array_keys($tab[$i][$j]) as $value) {
            
            if ($tab[$i][$j][$value]=="res_id") {

Alex ORLUC's avatar
Alex ORLUC committed
182
                $tab[$i][$j]["res_id"]=$tab[$i][$j]['value'];
Henri Queneau's avatar
Henri Queneau committed
183
                $tab[$i][$j]["label"]=_GED_NUM;
Alex ORLUC's avatar
Alex ORLUC committed
184
185
186
187
188
189
190
                $tab[$i][$j]["size"]="4";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='res_id';
                $_SESSION['mlb_search_current_res_id'] = $tab[$i][$j]['value'];
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

                // notes
                $query = "SELECT ";
                $query .= "notes.id ";
                $query .= "FROM ";
                $query .= "notes "; 
                $query .= "left join "; 
                $query .= "note_entities "; 
                $query .= "on "; 
                $query .= "notes.id = note_entities.note_id ";
                $query .= "WHERE ";
                $query .= "tablename = 'res_letterbox' ";
                $query .= "AND "; 
                $query .= "coll_id = 'letterbox_coll' ";
                $query .= "AND ";
                $query .= "identifier = ? ";
                $arrayPDOnotes = array($tab[$i][$j]['value']);
                $query .= "AND ";
                $query .= "( ";
                $query .= "( ";
                $query .= "item_id IN (";
 
                foreach ($_SESSION['user']['entities'] as $entitiestmpnote) {
                    $query .= "?, ";
                    $arrayPDOnotes = array_merge($arrayPDOnotes, array($entitiestmpnote['ENTITY_ID']));
                }
                $query = substr($query, 0, -2);

                $query .= ") ";
                $query .= "OR "; 
                $query .= "item_id IS NULL ";
                $query .= ") ";
                $query .= "OR ";
                $query .= "user_id = ? ";
                $arrayPDOnotes = array_merge($arrayPDOnotes, array($_SESSION['user']['UserId']));
                $query .= ") ";
                $stmt = $db->query($query, $arrayPDOnotes);
                $tab[$i][$j]['hasNotes'] = $stmt->fetchObject();
                $tab[$i][$j]['res_multi_contacts'] = $_SESSION['mlb_search_current_res_id'];
Alex ORLUC's avatar
Alex ORLUC committed
230
            }
231
232
233
234
            if ($tab[$i][$j][$value]=="address_id") {
                $addressId = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"] = false;
            }
235
236
            if ($tab[$i][$j][$value]=="creation_date") {

Alex ORLUC's avatar
Alex ORLUC committed
237
                $tab[$i][$j]["value"]=$core_tools->format_date_db($tab[$i][$j]["value"], false, '', true);
238
239
240
241
242
243
244
245
                $tab[$i][$j]["label"]=_CREATION_DATE;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='creation_date';
            }
246
247
            if ($tab[$i][$j][$value]=="admission_date") {

Alex ORLUC's avatar
Alex ORLUC committed
248
249
250
251
252
253
254
255
256
                $tab[$i][$j]["value"]=$core_tools->format_date_db($tab[$i][$j]["value"], false);
                $tab[$i][$j]["label"]=_ADMISSION_DATE;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["order"]='admission_date';
            }
257
258
            if ($tab[$i][$j][$value]=="process_limit_date") {

Alex ORLUC's avatar
Alex ORLUC committed
259
260
                $tab[$i][$j]["value"]=$core_tools->format_date_db($tab[$i][$j]["value"], false);
                $compareDate = "";
261
                if ($tab[$i][$j]["value"] <> "" && ($statusCmp == "NEW" || $statusCmp == "COU" || $statusCmp == "VAL" || $statusCmp == "RET")) {
Alex ORLUC's avatar
Alex ORLUC committed
262
                    $compareDate = $core_tools->compare_date($tab[$i][$j]["value"], date("d-m-Y"));
263
264
                    if ($compareDate == "date2") {

Alex ORLUC's avatar
Alex ORLUC committed
265
                        $tab[$i][$j]["value"] = "<span style='color:red;'><b>".$tab[$i][$j]["value"]."<br><small>(".$core_tools->nbDaysBetween2Dates($tab[$i][$j]["value"], date("d-m-Y"))." "._DAYS.")<small></b></span>";
266
267
268
                    
                    } elseif ($compareDate == "date1") {

Alex ORLUC's avatar
Alex ORLUC committed
269
                        $tab[$i][$j]["value"] = $tab[$i][$j]["value"]."<br><small>(".$core_tools->nbDaysBetween2Dates(date("d-m-Y"), $tab[$i][$j]["value"])." "._DAYS.")<small>";
270
271
272
                    
                    } elseif ($compareDate == "equal") {

Alex ORLUC's avatar
Alex ORLUC committed
273
274
275
276
277
278
279
280
281
282
283
                        $tab[$i][$j]["value"] = "<span style='color:blue;'><b>".$tab[$i][$j]["value"]."<br><small>("._LAST_DAY.")<small></b></span>";
                    }
                }
                $tab[$i][$j]["label"]=_PROCESS_LIMIT_DATE;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='process_limit_date';
            }
284
285
            if ($tab[$i][$j][$value]=="category_id") {

286
                $_SESSION['mlb_search_current_category_id'] = $tab[$i][$j]["value"];
Alex ORLUC's avatar
Alex ORLUC committed
287
                $tab[$i][$j]["value"] = $_SESSION['coll_categories'][$_SESSION['collection_id_choice']][$tab[$i][$j]["value"]];
288
289
290
291
292
293
294
295
                $tab[$i][$j]["label"]=_CATEGORY;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='category_id';
            }
296
297
            if ($tab[$i][$j][$value]=="priority") {

Alex ORLUC's avatar
Alex ORLUC committed
298
299
300
301
302
303
304
305
306
                $tab[$i][$j]["value"] = $_SESSION['mail_priorities'][$tab[$i][$j]["value"]];
                $tab[$i][$j]["label"]=_PRIORITY;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["order"]='priority';
            }
307
308
            if ($tab[$i][$j][$value]=="subject") {

Alex ORLUC's avatar
Alex ORLUC committed
309
                $tab[$i][$j]["value"] = $request->cut_string($request->show_string($tab[$i][$j]["value"], '', '', '', false), 250);
Alex ORLUC's avatar
Alex ORLUC committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
                $tab[$i][$j]["label"]=_SUBJECT;
                $tab[$i][$j]["size"]="12";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='subject';
            }
            /*if($tab[$i][$j][$value]=="category_id")
            {
                $_SESSION['mlb_search_current_category_id'] = $tab[$i][$j]["value"];
                $tab[$i][$j]["value"] = $_SESSION['mail_categories'][$tab[$i][$j]["value"]];
                $tab[$i][$j]["label"]=_CATEGORY;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='category_id';
            }*/
330
331
            if ($tab[$i][$j][$value]=="contact_firstname") {

332
333
334
                $contact_firstname = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"]=false;
            }
335
336
            if ($tab[$i][$j][$value]=="contact_lastname") {

337
338
339
                $contact_lastname = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"]=false;
            }
340
341
            if ($tab[$i][$j][$value]=="contact_society") {

342
343
344
                $contact_society = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"]=false;
            }
345
346
            if ($tab[$i][$j][$value]=="user_firstname") {

347
348
349
                $user_firstname = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"]=false;
            }
350
351
            if ($tab[$i][$j][$value]=="user_lastname") {

352
353
354
                $user_lastname = $tab[$i][$j]["value"];
                $tab[$i][$j]["show"]=false;
            }
355
356
            if ($tab[$i][$j][$value]=="exp_user_id") {

357
                if (empty($contact_lastname) && empty($contact_firstname) && empty($user_lastname) && empty($user_firstname) && !empty($addressId)) {
Alex ORLUC's avatar
Alex ORLUC committed
358
                    $query = "SELECT ca.firstname, ca.lastname FROM contact_addresses ca WHERE ca.id = ?";
359
                    $arrayPDO = array($addressId);
Damien's avatar
Damien committed
360
361
                    $stmt2 = $db->query($query, $arrayPDO);
                    $return_contact = $stmt2->fetchObject();
Alex ORLUC's avatar
Alex ORLUC committed
362
                    
Damien's avatar
Damien committed
363
364
365
366
367
                    if (!empty($return_contact)) {
                        $contact_firstname = $return_contact->firstname;
                        $contact_lastname = $return_contact->lastname;
                    }
                }
Alex ORLUC's avatar
Alex ORLUC committed
368
                
369
370
371
372
373
374
375
376
377
                $tab[$i][$j]["label"]=_CONTACT;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
                $tab[$i][$j]["value"] = $contact->get_contact_information_from_view($_SESSION['mlb_search_current_category_id'], $contact_lastname, $contact_firstname, $contact_society, $user_lastname, $user_firstname);
                $tab[$i][$j]["order"]=false;
378
            }
379
380
            if ($tab[$i][$j][$value]=="dest_user") {

Alex ORLUC's avatar
Alex ORLUC committed
381
382
383
384
385
386
387
                $tab[$i][$j]["label"]="dest_user";
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
388
                if ($tab[$i][15]["value"]=='outgoing') {
Alex ORLUC's avatar
Alex ORLUC committed
389
                    $tab[$i][$j]["value"] = "<b>"._TO_CONTACT_C."</b>".$tab[$i][$j]['value'];
390
391
                } else {
                    $tab[$i][$j]["value"] = "<b>"._FOR_CONTACT_C."</b>".$tab[$i][$j]['value'];
Alex ORLUC's avatar
Alex ORLUC committed
392
393
394
395
 
                }
                $tab[$i][$j]["order"]=false;
            }
396
397
398
399
400
401
402
403
404
405
406
407
408
409
            if ($tab[$i][$j][$value]=="is_multicontacts") {

                if ($tab[$i][$j]['value'] == 'Y') {
                    $tab[$i][$j]["label"]=_CONTACT;
                    $tab[$i][$j]["size"]="10";
                    $tab[$i][$j]["label_align"]="left";
                    $tab[$i][$j]["align"]="left";
                    $tab[$i][$j]["valign"]="bottom";
                    $tab[$i][$j]["show"]=false;
                    $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
                    $tab[$i][$j]["value"] = _MULTI_CONTACT;
                    $tab[$i][$j]["order"]=false;
                    $tab[$i][$j]["is_multi_contacts"] = 'Y';
                }
Alex ORLUC's avatar
Alex ORLUC committed
410
            }
411
412
            if ($tab[$i][$j][$value]=="type_label") {

Alex ORLUC's avatar
Alex ORLUC committed
413
414
415
416
417
418
419
420
421
                $tab[$i][$j]["value"] = $request->show_string($tab[$i][$j]["value"]);
                $tab[$i][$j]["label"]=_TYPE;
                $tab[$i][$j]["size"]="12";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='type_label';
            }
422
423
424
            if ($tab[$i][$j][$value]=="status") {   
                //couleurs des priorités
                if ($tab[$i][8]["value"]=='0') {
425
                    $style="style='color:".$_SESSION['mail_priorities_color'][$tab[$i][8]["value"]].";'";
426
                } else if ($tab[$i][8]["value"]=='1') {
427
                    $style="style='color:".$_SESSION['mail_priorities_color'][$tab[$i][8]["value"]].";'";
428
                } else {
429
                    $style="style='color:".$_SESSION['mail_priorities_color'][$tab[$i][8]["value"]].";'";
Alex ORLUC's avatar
Alex ORLUC committed
430
                }
431
                $res_status = $status_obj->get_status_data($tab[$i][$j]['value'], $extension_icon);
Alex ORLUC's avatar
Alex ORLUC committed
432
                $statusCmp = $tab[$i][$j]['value'];
433
                $img_class = substr($res_status['IMG_SRC'], 0, 2);
434
435
436
437
438
                if (!isset($res_status['IMG_SRC']) ||  empty($res_status['IMG_SRC'])) {
                    $tab[$i][$j]['value'] = "<i  ".$style." class = 'fm fm-letter-status-new fm-3x' alt = '".$res_status['LABEL']."' title = '".$res_status['LABEL']."'></i>";
                } else {
                    $tab[$i][$j]['value'] = "<i ".$style." class = '".$img_class." ".$res_status['IMG_SRC']." ".$img_class."-3x' alt = '".$res_status['LABEL']."' title = '".$res_status['LABEL']."'></i>";
                }
Alex ORLUC's avatar
Alex ORLUC committed
439
440
441
442
443
444
445
446
                $tab[$i][$j]["label"]=_STATUS;
                $tab[$i][$j]["size"]="4";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='status';
            }
447
448
            if ($tab[$i][$j][$value]=="category_img") {

Alex ORLUC's avatar
Alex ORLUC committed
449
450
451
452
453
454
455
                $tab[$i][$j]["label"]=_CATEGORY;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="right";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
456
                $my_imgcat = get_img_cat($tab[$i][$j]['value'], $extension_icon);
Alex ORLUC's avatar
Alex ORLUC committed
457
458
459
                $tab[$i][$j]['value'] = $my_imgcat;
                $tab[$i][$j]["value"] = $tab[$i][$j]['value'];
                $tab[$i][$j]["order"]="category_id";
460
            }
461
462
            if ($tab[$i][$j][$value]=="count_attachment") {

Alex ORLUC's avatar
Alex ORLUC committed
463
464
465
466
467
468
469
                $query = "SELECT count(res_id) as total FROM res_view_attachments
                            WHERE res_id_master = ?
                            AND status NOT IN ('DEL', 'OBS') AND attachment_type NOT IN ('converted_pdf', 'print_folder') AND coll_id = ? AND (status <> 'TMP' or (typist = ? and status = 'TMP'))";
                $arrayPDO = array($tab[$i][0]['res_id'], $_SESSION['collection_id_choice'], $_SESSION['user']['UserId']);
                $stmt2 = $db->query($query, $arrayPDO);
                $return_count = $stmt2->fetchObject();

Alex ORLUC's avatar
Alex ORLUC committed
470
471
472
473
474
475
                $tab[$i][$j]["label"]=_ATTACHMENTS;
                $tab[$i][$j]["size"]="12";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
Alex ORLUC's avatar
Alex ORLUC committed
476
                $tab[$i][$j]['value'] = "$return_count->total";
Alex ORLUC's avatar
Alex ORLUC committed
477
478
                $tab[$i][$j]["order"]='count_attachment';
            }
479
480
            if ($tab[$i][$j][$value]=="case_id" && $core_tools->is_module_loaded("cases") == true) {

481
482
483
484
485
486
487
488
489
490
                $tab[$i][$j]["label"]=_CASE_NUM;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
                $tab[$i][$j]["value"] = "<a href='".$_SESSION['config']['businessappurl']."index.php?page=details_cases&module=cases&id=".$tab[$i][$j]['value']."'>".$tab[$i][$j]['value']."</a>";
                $tab[$i][$j]["order"]="case_id";
            }
491
492
            if ($tab[$i][$j][$value]=="case_label" && $core_tools->is_module_loaded("cases") == true) {

493
494
495
496
497
498
499
500
501
                $tab[$i][$j]["label"]=_CASE_LABEL;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=false;
                $tab[$i][$j]["value_export"] = $tab[$i][$j]['value'];
                $tab[$i][$j]["order"]="case_label";
            }
502
503
            if ($tab[$i][$j][$value]=="viewed") {

504
505
506
507
508
509
510
                $tab[$i][$j]["label"]=_VIEWED;
                $tab[$i][$j]["size"]="10";
                $tab[$i][$j]["label_align"]="left";
                $tab[$i][$j]["align"]="left";
                $tab[$i][$j]["valign"]="bottom";
                $tab[$i][$j]["show"]=true;
                $tab[$i][$j]["order"]='viewed';
511
512
                $stmt = $db->query(
                    "SELECT viewed FROM listinstance WHERE res_id = ? and coll_id = ?"
Florian Azizian's avatar
Florian Azizian committed
513
                    . " and item_id = ?",
514
515
                    array($_SESSION['mlb_search_current_res_id'], $_SESSION['current_basket']['coll_id'], $_SESSION['user']['UserId'])
                );
Florian Azizian's avatar
Florian Azizian committed
516
                $lineViewed = $stmt->fetchObject();
Alex ORLUC's avatar
Alex ORLUC committed
517
                $tab[$i][$j]['value'] = $lineViewed->viewed;
518
            }
Alex ORLUC's avatar
Alex ORLUC committed
519
520
        }
    }
521
}
522
//Cle de la liste
523
524
$listKey = 'res_id';

525
//Initialiser le tableau de parametres
526
527
$paramsTab = array();
$paramsTab['pageTitle'] =  _RESULTS." : ".count($tab).' '._FOUND_DOCS;              //Titre de la page
Florian Azizian's avatar
Florian Azizian committed
528
$paramsTab['listCss'] = 'listing largerList spec';                                  //css
Alex ORLUC's avatar
Alex ORLUC committed
529
$paramsTab['bool_sortColumn'] = true;                                               //Affichage Tri
530
531
532
$paramsTab['bool_bigPageTitle'] = false;                                            //Affichage du titre en grand
$paramsTab['bool_showIconDocument'] = true;                                         //Affichage de l'icone du document
$paramsTab['bool_showIconDetails'] = true;                                          //Affichage de l'icone de la page de details
533
$paramsTab['urlParameters'] = 'baskets='.$_SESSION['current_basket']['id']
Alex ORLUC's avatar
Alex ORLUC committed
534
            .$urlParameters;                                                        //Parametres d'url supplementaires
535
$paramsTab['filters'] = array('entity', 'entity_subentities', 'category', 'priority', 'isViewed', 'identifier');                     //Filtres    
536
if (count($template_list) > 0 ) {                                                   //Templates
537
538
539
    $paramsTab['templates'] = array();
    $paramsTab['templates'] = $template_list;
}
Alex ORLUC's avatar
Alex ORLUC committed
540
$paramsTab['bool_showTemplateDefaultList'] = true;                                  //Default list (no template)
541
542
$paramsTab['defaultTemplate'] = $defaultTemplate;                                   //Default template
$paramsTab['tools'] = array();                                                      //Icones dans la barre d'outils
543
544
//Fileplan
if ($core_tools->test_service('fileplan', 'fileplan', false)) {
545
    include_once "modules" . DIRECTORY_SEPARATOR . "fileplan" . DIRECTORY_SEPARATOR
546
547
        . "class" . DIRECTORY_SEPARATOR . "class_modules_tools.php";
    $fileplan = new fileplan();
548
549
550
551
    if (count($fileplan->getUserFileplan()) > 0 
        || (count($fileplan->getEntitiesFileplan()) > 0 
        && $core_tools->test_service('put_doc_in_fileplan', 'fileplan', false))
    ) {
552
553
554
555
556
557
558
559
        $paramsTab['bool_checkBox'] = true;
        $paramsTab['bool_standaloneForm'] = true;
        $positions = array(
                "script"        =>  "showFileplanList('".$_SESSION['config']['businessappurl']  
                                        . "index.php?display=true&module=fileplan&page=fileplan_ajax_script"
                                        . "&mode=setPosition&origin=basket&coll_id=".$_SESSION['current_basket']['coll_id']
                                        . $parameters."', 'formList', '600px', '510px', '"
                                        . _CHOOSE_ONE_DOC."')",
560
                "icon"          =>  'bookmark',
561
562
563
                "tooltip"       =>  _FILEPLAN,
                "disabledRules" =>  count($tab)." == 0 || ".$selectedTemplate." == 'cases_list_search_adv'"
                );      
564
        array_push($paramsTab['tools'], $positions);
565
566
    }
}
567
if (isset($_REQUEST['origin']) && $_REQUEST['origin'] == 'searching') {
568
569
    $save = array(
            "script"        =>  "createModal(form_txt, 'save_search', '100px', '500px');window.location.href='#top';",
570
            "icon"          =>  'save',
571
572
573
            "tooltip"       =>  _SAVE_QUERY,
            "disabledRules" =>  count($tab)." == 0"
            );      
574
    array_push($paramsTab['tools'], $save); 
575
}
576
577
$export = array(
        "script"        =>  "window.open('".$_SESSION['config']['businessappurl']."index.php?display=true&page=export', '_blank');",
Alex ORLUC's avatar
Alex ORLUC committed
578
        "icon"          =>  'cloud-download',
579
580
581
        "tooltip"       =>  _EXPORT_LIST,
        "disabledRules" =>  count($tab)." == 0"
        );
582
array_push($paramsTab['tools'], $export);
Alex ORLUC's avatar
Alex ORLUC committed
583
if ($core_tools->test_service('print_doc_details_from_list', 'apps', false)) {
584
585
586
587
588
589
590
    $print = array(
        "script"        =>  "window.open('".$_SESSION['config']['businessappurl']."index.php?display=true&page=print', '_blank');",
        "icon"          =>  'print',
        "tooltip"       =>  _PRINT_LIST,
        "disabledRules" =>  count($tab)." == 0"
    );
    array_push($paramsTab['tools'], $print);   
Giovannoni Laurent's avatar
Giovannoni Laurent committed
591
}
Alex ORLUC's avatar
Alex ORLUC committed
592

593
594
595
//Afficher la liste
$status = 0;
$content = $list->showList($tab, $paramsTab, $listKey, $_SESSION['current_basket']);
Alex ORLUC's avatar
Alex ORLUC committed
596
// $debug = $list->debug(false);
597

Damien's avatar
Damien committed
598
599
$content .= '<script>$j(\'#container\').attr(\'style\', \'width: 90%; min-width: 1000px\');$j(\'#content\').attr(\'style\', \'width: auto; min-width: 1000px;\');';
$content .= '$j(\'#inner_content\').attr(\'style\', \'width: auto; min-width: 1000px;\');</script>';
600

Giovannoni Laurent's avatar
Giovannoni Laurent committed
601
echo "{'status' : " . $status . ", 'content' : '" . addslashes($debug.$content) . "', 'error' : '" . addslashes(functions::xssafe($error)) . "'}";