forked from ricsistemas/dolibarr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxes.php
434 lines (379 loc) · 12.1 KB
/
boxes.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
183
184
185
186
187
188
189
190
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<?php
/* Copyright (C) 2003 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2004-2010 Laurent Destailleur <[email protected]>
* Copyright (C) 2005-2010 Regis Houssin <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/boxes.php
* \brief Fichier de la classe boxes
* \author Rodolphe Qiedeville
* \author Laurent Destailleur
* \version $Id: boxes.php,v 1.49 2010/12/19 02:42:53 eldy Exp $
*/
/**
* \brief Show a HTML Tab with boxes of a particular area including personalized choices of user
* \param user User
* \param areacode Code of area for pages (0=value for Home page)
* \return int <0 if KO, Nb of boxes shown of OK (0 to n)
*/
function printBoxesArea($user,$areacode)
{
global $conf,$langs,$db;
$infobox=new InfoBox($db);
$boxarray=$infobox->listboxes($areacode,$user);
//$boxid_left = array();
//$boxid_right = array();
if (sizeof($boxarray))
{
print_fiche_titre($langs->trans("OtherInformationsBoxes"),'','','','otherboxes');
print '<table width="100%" class="notopnoleftnoright">';
print '<tr><td class="notopnoleftnoright">'."\n";
print '<table width="100%" style="border-collapse: collapse; border: 0px; margin: 0px; padding: 0px;"><tr>';
// Affichage colonne gauche
print '<td width="50%" valign="top" style="padding-right: 4px;">'."\n";
print "\n<!-- Box left container -->\n";
print '<div id="left" class="connectedSortable">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^A/i',$box->box_order)) // column A
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_left[$key] = $box->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on left, we add an invisible empty box
// if ($ii==0)
// {
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='A';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
// }
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>\n";
// Affichage colonne droite
print '<td width="50%" valign="top" style="padding-right: 2px;">';
print "\n<!-- Box right container -->\n";
print '<div id="right" class="connectedSortable">'."\n";
$ii=0;
foreach ($boxarray as $key => $box)
{
if (preg_match('/^B/i',$box->box_order)) // colonne B
{
$ii++;
//print 'box_id '.$boxarray[$ii]->box_id.' ';
//print 'box_order '.$boxarray[$ii]->box_order.'<br>';
//$boxid_right[$key] = $boxarray[$key]->box_id;
// Affichage boite key
$box->loadBox($conf->box_max_lines);
$box->showBox();
}
}
// If no box on right, we show add an invisible empty box
// if ($ii==0)
// {
$emptybox=new ModeleBoxes($db);
$emptybox->box_id='B';
$emptybox->info_box_head=array();
$emptybox->info_box_contents=array();
$emptybox->showBox(array(),array());
// }
print "</div>\n";
print "<!-- End box container -->\n";
print "</td>";
print "</tr></table>\n";
print "\n";
print "</td></tr>";
print "</table>";
if ($conf->use_javascript_ajax)
{
print "\n";
print '<script type="text/javascript" language="javascript">';
print 'jQuery(function() {
jQuery("#left, #right").sortable({
/* placeholder: \'ui-state-highlight\', */
handle: \'.boxhandle\',
revert: \'invalid\',
items: \'.box\',
containment: \'.fiche\',
connectWith: \'.connectedSortable\',
stop: function(event, ui) {
updateOrder();
}
});
});
';
print "\n";
print 'function updateOrder(){'."\n";
print 'var left_list = cleanSerialize(jQuery("#left").sortable( "serialize" ));'."\n";
print 'var right_list = cleanSerialize(jQuery("#right").sortable( "serialize" ));'."\n";
print 'var boxorder = \'A:\' + left_list + \'-B:\' + right_list;'."\n";
//print 'alert( \'boxorder=\' + boxorder );';
print 'var userid = \''.$user->id.'\';'."\n";
print 'jQuery.get(\'core/ajaxbox.php?boxorder=\'+boxorder+\'&userid=\'+'.$user->id.');'."\n";
print '}'."\n";
print '</script>'."\n";
}
}
return sizeof($boxarray);
}
/**
* \class InfoBox
* \brief Classe permettant la gestion des boxes sur une page
*/
class InfoBox
{
var $db;
/**
* \brief Constructeur de la classe
* \param $DB Handler d'acc�s base
*/
function InfoBox($DB)
{
$this->db=$DB;
}
/**
* \brief Retourne tableau des boites elligibles pour la zone et le user
* \param $zone ID de la zone (0 pour la Homepage, ...)
* \param $user Objet user
* \return array Tableau d'objet box
*/
function listBoxes($zone,$user)
{
global $conf;
$boxes=array();
$confuserzone='MAIN_BOXES_'.$zone;
if ($user->id && $user->conf->$confuserzone)
{
// Get list of boxes of a particular user (if this one has its own list)
$sql = "SELECT b.rowid, b.box_id, b.position, b.box_order, b.fk_user,";
$sql.= " d.file, d.note";
$sql.= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d";
$sql.= " WHERE b.box_id = d.rowid";
$sql.= " AND d.entity = ".$conf->entity;
$sql.= " AND b.position = ".$zone;
$sql.= " AND b.fk_user = ".$user->id;
$sql.= " ORDER BY b.box_order";
dol_syslog("InfoBox::listBoxes get user box list sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$j = 0;
while ($j < $num)
{
$obj = $this->db->fetch_object($result);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$boxname = $regs[1];
$module = $regs[2];
dol_include_once("/".$module."/inc/boxes/".$boxname.".php");
}
else
{
$boxname=preg_replace('/.php$/i','',$obj->file);
$sourcefile = DOL_DOCUMENT_ROOT."/includes/boxes/".$boxname.".php";
}
include_once($sourcefile);
$box=new $boxname($db,$obj->note);
$box->rowid=$obj->rowid;
$box->box_id=$obj->box_id;
$box->position=$obj->position;
$box->box_order=$obj->box_order;
$box->fk_user=$obj->fk_user;
$enabled=true;
if ($box->depends && sizeof($box->depends) > 0)
{
foreach($box->depends as $module)
{
// print $module.'<br>';
if (empty($conf->$module->enabled)) $enabled=false;
}
}
if ($enabled) $boxes[]=$box;
$j++;
}
}
else {
$this->error=$this->db->error();
dol_syslog("InfoBox::listBoxes Error ".$this->error, LOG_ERR);
return array();
}
}
else
{
// Recupere liste des boites active par defaut pour tous
$sql = "SELECT b.rowid, b.box_id, b.position, b.box_order, b.fk_user,";
$sql.= " d.file, d.note";
$sql.= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d";
$sql.= " WHERE b.box_id = d.rowid";
$sql.= " AND d.entity = ".$conf->entity;
$sql.= " AND b.position = ".$zone;
$sql.= " AND b.fk_user = 0";
$sql.= " ORDER BY b.box_order";
dol_syslog("InfoBox::listBoxes get default box list sql=".$sql, LOG_DEBUG);
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$j = 0;
while ($j < $num)
{
$obj = $this->db->fetch_object($result);
if (preg_match('/^([^@]+)@([^@]+)$/i',$obj->file,$regs))
{
$boxname = $regs[1];
$module = $regs[2];
$sourcefile = "/".$module."/inc/boxes/".$boxname.".php";
}
else
{
$boxname=preg_replace('/.php$/i','',$obj->file);
$sourcefile = "/includes/boxes/".$boxname.".php";
}
dol_include_once($sourcefile);
$box=new $boxname($db,$obj->note);
$box->rowid=$obj->rowid;
$box->box_id=$obj->box_id;
$box->position=$obj->position;
$box->box_order=$obj->box_order;
if (is_numeric($box->box_order))
{
if ($box->box_order % 2 == 1) $box->box_order='A'.$box->box_order;
elseif ($box->box_order % 2 == 0) $box->box_order='B'.$box->box_order;
}
$box->fk_user=$obj->fk_user;
$enabled=true;
if ($box->depends && sizeof($box->depends) > 0)
{
foreach($box->depends as $module)
{
//print $boxname.'-'.$module.'<br>';
if (empty($conf->$module->enabled)) $enabled=false;
}
}
if ($enabled) $boxes[]=$box;
$j++;
}
}
else {
$this->error=$this->db->error();
dol_syslog("InfoBox::listBoxes Error ".$this->error, LOG_ERR);
return array();
}
}
return $boxes;
}
/**
* \brief Sauvegarde sequencement des boites pour la zone et le user
* \param $zone ID de la zone (0 pour la Homepage, ...)
* \param $boxorder Liste des boites dans le bon ordre 'A:123,456,...-B:789,321...'
* \param $userid Id du user
* \return int <0 si ko, >= 0 si ok
*/
function saveboxorder($zone,$boxorder,$userid=0)
{
global $conf;
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
dol_syslog("InfoBoxes::saveboxorder zone=".$zone." user=".$userid);
if (! $userid || $userid == 0) return 0;
$user = new User($this->db);
$user->id=$userid;
$this->db->begin();
// Sauve parametre indiquant que le user a une
$confuserzone='MAIN_BOXES_'.$zone;
$tab[$confuserzone]=1;
if (dol_set_user_param($this->db, $conf, $user, $tab) < 0)
{
$this->error=$this->db->lasterror();
$this->db->rollback();
return -3;
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes";
$sql.= " USING ".MAIN_DB_PREFIX."boxes, ".MAIN_DB_PREFIX."boxes_def";
$sql.= " WHERE ".MAIN_DB_PREFIX."boxes.box_id = ".MAIN_DB_PREFIX."boxes_def.rowid";
$sql.= " AND ".MAIN_DB_PREFIX."boxes_def.entity = ".$conf->entity;
$sql.= " AND ".MAIN_DB_PREFIX."boxes.fk_user = ".$userid;
$sql.= " AND ".MAIN_DB_PREFIX."boxes.position = ".$zone;
dol_syslog("InfoBox::saveboxorder sql=".$sql);
$result = $this->db->query($sql);
if ($result)
{
$colonnes=explode('-',$boxorder);
foreach ($colonnes as $collist)
{
$part=explode(':',$collist);
$colonne=$part[0];
$list=$part[1];
dol_syslog('InfoBox::saveboxorder column='.$colonne.' list='.$list);
$i=0;
$listarray=explode(',',$list);
foreach ($listarray as $id)
{
if (is_numeric($id))
{
//dol_syslog("aaaaa".sizeof($listarray));
$i++;
$ii=sprintf('%02d',$i);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes";
$sql.= "(box_id, position, box_order, fk_user)";
$sql.= " values (";
$sql.= " ".$id.",";
$sql.= " ".$zone.",";
$sql.= " '".$colonne.$ii."',";
$sql.= " ".$userid;
$sql.= ")";
dol_syslog("InfoBox::saveboxorder sql=".$sql);
$result = $this->db->query($sql);
if ($result < 0)
{
$error++;
break;
}
}
}
}
if ($error)
{
$this->error=$this->db->error();
$this->db->rollback();
return -2;
}
else
{
$this->db->commit();
return 1;
}
}
else
{
$this->error=$this->db->lasterror();
$this->db->rollback();
dol_syslog("InfoBox::saveboxorder ".$this->error);
return -1;
}
}
}
?>