@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | * @param DoliDB $db Database handler |
38 | 38 | * @param string $key Google key |
39 | 39 | */ |
40 | - function __construct($db,$key) |
|
40 | + function __construct($db, $key) |
|
41 | 41 | { |
42 | - $this->db=$db; |
|
43 | - $this->key=$key; |
|
42 | + $this->db = $db; |
|
43 | + $this->key = $key; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | global $conf; |
58 | 58 | |
59 | - $i=0; |
|
59 | + $i = 0; |
|
60 | 60 | |
61 | 61 | // Desired address |
62 | 62 | $urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key; |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | |
67 | 67 | $code = strstr($page, '<coordinates>'); |
68 | 68 | $code = strstr($code, '>'); |
69 | - $val=strpos($code, "<"); |
|
70 | - $code = substr($code, 1, $val-1); |
|
69 | + $val = strpos($code, "<"); |
|
70 | + $code = substr($code, 1, $val - 1); |
|
71 | 71 | //print $code; |
72 | 72 | //print "<br>"; |
73 | 73 | $latitude = substr($code, 0, strpos($code, ",")); |
74 | - $longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3); |
|
74 | + $longitude = substr($code, strpos($code, ",") + 1, dol_strlen(strpos($code, ",")) - 3); |
|
75 | 75 | |
76 | 76 | // Output the coordinates |
77 | 77 | //echo "Longitude: $longitude ',' Latitude: $latitude"; |
@@ -96,10 +96,14 @@ discard block |
||
96 | 96 | $this->enabled=trim($this->enabled); |
97 | 97 | $this->user=trim($this->user); |
98 | 98 | $this->position=trim($this->position); |
99 | - if (! $this->level) $this->level=0; |
|
99 | + if (! $this->level) { |
|
100 | + $this->level=0; |
|
101 | + } |
|
100 | 102 | |
101 | 103 | // Check parameters |
102 | - if (empty($this->menu_handler)) return -1; |
|
104 | + if (empty($this->menu_handler)) { |
|
105 | + return -1; |
|
106 | + } |
|
103 | 107 | |
104 | 108 | // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql |
105 | 109 | // may use an already used value because its internal cursor does not increase when we do |
@@ -114,14 +118,19 @@ discard block |
||
114 | 118 | $maxrowid=$obj->maxrowid; |
115 | 119 | |
116 | 120 | // Max rowid can be empty if there is no record yet |
117 | - if(empty($maxrowid)) $maxrowid=1; |
|
121 | + if(empty($maxrowid)) { |
|
122 | + $maxrowid=1; |
|
123 | + } |
|
118 | 124 | |
119 | 125 | $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")"; |
120 | 126 | //print $sql; exit; |
121 | 127 | $resqlrowidset=$this->db->query($sql); |
122 | - if (! $resqlrowidset) dol_print_error($this->db); |
|
128 | + if (! $resqlrowidset) { |
|
129 | + dol_print_error($this->db); |
|
130 | + } |
|
131 | + } else { |
|
132 | + dol_print_error($this->db); |
|
123 | 133 | } |
124 | - else dol_print_error($this->db); |
|
125 | 134 | } |
126 | 135 | |
127 | 136 | // Insert request |
@@ -171,8 +180,7 @@ discard block |
||
171 | 180 | dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); |
172 | 181 | |
173 | 182 | return $this->id; |
174 | - } |
|
175 | - else |
|
183 | + } else |
|
176 | 184 | { |
177 | 185 | $this->error="Error ".$this->db->lasterror(); |
178 | 186 | return -1; |
@@ -310,8 +318,7 @@ discard block |
||
310 | 318 | $this->db->free($resql); |
311 | 319 | |
312 | 320 | return 1; |
313 | - } |
|
314 | - else |
|
321 | + } else |
|
315 | 322 | { |
316 | 323 | $this->error="Error ".$this->db->lasterror(); |
317 | 324 | return -1; |
@@ -395,7 +402,9 @@ discard block |
||
395 | 402 | $newTabMenu=array(); |
396 | 403 | foreach($tabMenu as $val) |
397 | 404 | { |
398 | - if ($val['type']=='top') $newTabMenu[]=$val; |
|
405 | + if ($val['type']=='top') { |
|
406 | + $newTabMenu[]=$val; |
|
407 | + } |
|
399 | 408 | } |
400 | 409 | |
401 | 410 | return $newTabMenu; |
@@ -443,7 +452,8 @@ discard block |
||
443 | 452 | foreach($tabMenu as $key => $val) |
444 | 453 | { |
445 | 454 | //var_dump($tabMenu); |
446 | - if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) // We found a menu entry not linked to parent with good mainmenu |
|
455 | + if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) { |
|
456 | + // We found a menu entry not linked to parent with good mainmenu |
|
447 | 457 | { |
448 | 458 | //print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>'; |
449 | 459 | //var_dump($this->newmenu->liste);exit; |
@@ -451,18 +461,20 @@ discard block |
||
451 | 461 | if (empty($val['fk_leftmenu'])) |
452 | 462 | { |
453 | 463 | $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
464 | + } |
|
454 | 465 | //var_dump($this->newmenu->liste); |
455 | - } |
|
456 | - else |
|
466 | + } else |
|
457 | 467 | { |
458 | 468 | // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu) |
459 | 469 | $searchlastsub=0;$lastid=0;$nextid=0;$found=0; |
460 | 470 | foreach($this->newmenu->liste as $keyparent => $valparent) |
461 | 471 | { |
462 | 472 | //var_dump($valparent); |
463 | - if ($searchlastsub) // If we started to search for last submenu |
|
473 | + if ($searchlastsub) { |
|
474 | + // If we started to search for last submenu |
|
464 | 475 | { |
465 | 476 | if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent; |
477 | + } |
|
466 | 478 | if ($valparent['level'] < $searchlastsub) |
467 | 479 | { |
468 | 480 | $nextid=$keyparent; |
@@ -479,8 +491,9 @@ discard block |
||
479 | 491 | } |
480 | 492 | } |
481 | 493 | //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>'; |
482 | - if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
483 | - else { |
|
494 | + if ($found) { |
|
495 | + $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
496 | + } else { |
|
484 | 497 | dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING); |
485 | 498 | //print "Parent menu not found !!<br>"; |
486 | 499 | } |
@@ -515,8 +528,12 @@ discard block |
||
515 | 528 | $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; |
516 | 529 | $sql.= " WHERE m.entity IN (0,".$conf->entity.")"; |
517 | 530 | $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')"; |
518 | - if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)"; |
|
519 | - if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)"; |
|
531 | + if ($type_user == 0) { |
|
532 | + $sql.= " AND m.usertype IN (0,2)"; |
|
533 | + } |
|
534 | + if ($type_user == 1) { |
|
535 | + $sql.= " AND m.usertype IN (1,2)"; |
|
536 | + } |
|
520 | 537 | $sql.= " ORDER BY m.position, m.rowid"; |
521 | 538 | //print $sql; |
522 | 539 | |
@@ -541,7 +558,10 @@ discard block |
||
541 | 558 | if ($menu['perms']) |
542 | 559 | { |
543 | 560 | $tmpcond=$menu['perms']; |
544 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
561 | + if ($leftmenu == 'all') { |
|
562 | + $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); |
|
563 | + } |
|
564 | + // Force part of condition to true |
|
545 | 565 | $perms = verifCond($tmpcond); |
546 | 566 | //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n"; |
547 | 567 | } |
@@ -551,7 +571,10 @@ discard block |
||
551 | 571 | if ($menu['enabled']) |
552 | 572 | { |
553 | 573 | $tmpcond=$menu['enabled']; |
554 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
574 | + if ($leftmenu == 'all') { |
|
575 | + $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); |
|
576 | + } |
|
577 | + // Force part of condition to true |
|
555 | 578 | $enabled = verifCond($tmpcond); |
556 | 579 | } |
557 | 580 | |
@@ -559,27 +582,31 @@ discard block |
||
559 | 582 | if ($enabled) |
560 | 583 | { |
561 | 584 | $title = $langs->trans($menu['titre']); |
562 | - if ($title == $menu['titre']) // Translation not found |
|
585 | + if ($title == $menu['titre']) { |
|
586 | + // Translation not found |
|
563 | 587 | { |
564 | 588 | if (! empty($menu['langs'])) // If there is a dedicated translation file |
565 | 589 | { |
566 | 590 | //print 'Load file '.$menu['langs'].'<br>'; |
567 | 591 | $langs->load($menu['langs']); |
592 | + } |
|
568 | 593 | } |
569 | 594 | |
570 | - if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 |
|
595 | + if (preg_match("/\//",$menu['titre'])) { |
|
596 | + // To manage translation when title is string1/string2 |
|
571 | 597 | { |
572 | 598 | $tab_titre = explode("/",$menu['titre']); |
573 | - $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); |
|
574 | 599 | } |
575 | - else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
600 | + $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); |
|
601 | + } else if (preg_match('/\|\|/',$menu['titre'])) { |
|
602 | + // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
576 | 603 | { |
577 | 604 | $tab_title = explode("||",$menu['titre']); |
605 | + } |
|
578 | 606 | $alt_title = explode("@",$tab_title[1]); |
579 | 607 | $title_enabled = verifCond($alt_title[1]); |
580 | 608 | $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0])); |
581 | - } |
|
582 | - else |
|
609 | + } else |
|
583 | 610 | { |
584 | 611 | $title = $langs->trans($menu['titre']); |
585 | 612 | } |
@@ -594,8 +621,11 @@ discard block |
||
594 | 621 | $tabMenu[$b]['url'] = $menu['url']; |
595 | 622 | if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url'])) |
596 | 623 | { |
597 | - if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; |
|
598 | - else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; |
|
624 | + if (preg_match('/\?/',$tabMenu[$b]['url'])) { |
|
625 | + $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; |
|
626 | + } else { |
|
627 | + $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; |
|
628 | + } |
|
599 | 629 | } |
600 | 630 | $tabMenu[$b]['titre'] = $title; |
601 | 631 | $tabMenu[$b]['target'] = $menu['target']; |
@@ -621,8 +651,7 @@ discard block |
||
621 | 651 | // into the leftMenuCharger later to avoid useless operations. |
622 | 652 | |
623 | 653 | return 1; |
624 | - } |
|
625 | - else |
|
654 | + } else |
|
626 | 655 | { |
627 | 656 | dol_print_error($this->db); |
628 | 657 | return -1; |
@@ -28,628 +28,628 @@ |
||
28 | 28 | */ |
29 | 29 | class Menubase |
30 | 30 | { |
31 | - public $db; // To store db handler |
|
32 | - public $error; // To return error code (or message) |
|
33 | - public $errors=array(); // To return several error codes (or messages) |
|
34 | - |
|
35 | - public $id; |
|
36 | - |
|
37 | - public $menu_handler; |
|
38 | - public $module; |
|
39 | - public $type; |
|
40 | - public $mainmenu; |
|
41 | - public $fk_menu; |
|
42 | - public $fk_mainmenu; |
|
43 | - public $fk_leftmenu; |
|
44 | - public $position; |
|
45 | - public $url; |
|
46 | - public $target; |
|
47 | - public $titre; |
|
48 | - public $langs; |
|
49 | - public $level; |
|
50 | - public $leftmenu; //<! Not used |
|
51 | - public $perms; |
|
52 | - public $enabled; |
|
53 | - public $user; |
|
54 | - public $tms; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
31 | + public $db; // To store db handler |
|
32 | + public $error; // To return error code (or message) |
|
33 | + public $errors=array(); // To return several error codes (or messages) |
|
34 | + |
|
35 | + public $id; |
|
36 | + |
|
37 | + public $menu_handler; |
|
38 | + public $module; |
|
39 | + public $type; |
|
40 | + public $mainmenu; |
|
41 | + public $fk_menu; |
|
42 | + public $fk_mainmenu; |
|
43 | + public $fk_leftmenu; |
|
44 | + public $position; |
|
45 | + public $url; |
|
46 | + public $target; |
|
47 | + public $titre; |
|
48 | + public $langs; |
|
49 | + public $level; |
|
50 | + public $leftmenu; //<! Not used |
|
51 | + public $perms; |
|
52 | + public $enabled; |
|
53 | + public $user; |
|
54 | + public $tms; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | 58 | * Constructor |
59 | 59 | * |
60 | 60 | * @param DoliDB $db Database handler |
61 | - * @param string $menu_handler Menu handler |
|
62 | - */ |
|
63 | - function __construct($db,$menu_handler='') |
|
64 | - { |
|
65 | - $this->db = $db; |
|
66 | - $this->menu_handler = $menu_handler; |
|
67 | - return 1; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Create menu entry into database |
|
73 | - * |
|
74 | - * @param User $user User that create |
|
75 | - * @return int <0 if KO, Id of record if OK |
|
76 | - */ |
|
77 | - function create($user=null) |
|
78 | - { |
|
79 | - global $conf, $langs; |
|
80 | - |
|
81 | - // Clean parameters |
|
82 | - $this->menu_handler=trim($this->menu_handler); |
|
83 | - $this->module=trim($this->module); |
|
84 | - $this->type=trim($this->type); |
|
85 | - $this->mainmenu=trim($this->mainmenu); |
|
86 | - $this->leftmenu=trim($this->leftmenu); |
|
87 | - $this->fk_menu=trim($this->fk_menu); // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
88 | - $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
89 | - $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
90 | - $this->position=trim($this->position); |
|
91 | - $this->url=trim($this->url); |
|
92 | - $this->target=trim($this->target); |
|
93 | - $this->titre=trim($this->titre); |
|
94 | - $this->langs=trim($this->langs); |
|
95 | - $this->perms=trim($this->perms); |
|
96 | - $this->enabled=trim($this->enabled); |
|
97 | - $this->user=trim($this->user); |
|
98 | - $this->position=trim($this->position); |
|
99 | - if (! $this->level) $this->level=0; |
|
100 | - |
|
101 | - // Check parameters |
|
102 | - if (empty($this->menu_handler)) return -1; |
|
103 | - |
|
104 | - // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql |
|
105 | - // may use an already used value because its internal cursor does not increase when we do |
|
106 | - // an insert with a forced id. |
|
107 | - if (in_array($this->db->type,array('pgsql'))) |
|
108 | - { |
|
109 | - $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu"; |
|
110 | - $resqlrowid=$this->db->query($sql); |
|
111 | - if ($resqlrowid) |
|
112 | - { |
|
113 | - $obj=$this->db->fetch_object($resqlrowid); |
|
114 | - $maxrowid=$obj->maxrowid; |
|
115 | - |
|
116 | - // Max rowid can be empty if there is no record yet |
|
117 | - if(empty($maxrowid)) $maxrowid=1; |
|
118 | - |
|
119 | - $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")"; |
|
120 | - //print $sql; exit; |
|
121 | - $resqlrowidset=$this->db->query($sql); |
|
122 | - if (! $resqlrowidset) dol_print_error($this->db); |
|
123 | - } |
|
124 | - else dol_print_error($this->db); |
|
125 | - } |
|
126 | - |
|
127 | - // Insert request |
|
128 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; |
|
129 | - $sql.= "menu_handler,"; |
|
130 | - $sql.= "entity,"; |
|
131 | - $sql.= "module,"; |
|
132 | - $sql.= "type,"; |
|
133 | - $sql.= "mainmenu,"; |
|
134 | - $sql.= "leftmenu,"; |
|
135 | - $sql.= "fk_menu,"; |
|
136 | - $sql.= "fk_mainmenu,"; |
|
137 | - $sql.= "fk_leftmenu,"; |
|
138 | - $sql.= "position,"; |
|
139 | - $sql.= "url,"; |
|
140 | - $sql.= "target,"; |
|
141 | - $sql.= "titre,"; |
|
142 | - $sql.= "langs,"; |
|
143 | - $sql.= "perms,"; |
|
144 | - $sql.= "enabled,"; |
|
145 | - $sql.= "usertype"; |
|
146 | - $sql.= ") VALUES ("; |
|
147 | - $sql.= " '".$this->db->escape($this->menu_handler)."',"; |
|
148 | - $sql.= " '".$this->db->escape($conf->entity)."',"; |
|
149 | - $sql.= " '".$this->db->escape($this->module)."',"; |
|
150 | - $sql.= " '".$this->db->escape($this->type)."',"; |
|
151 | - $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").","; // Can't be null |
|
152 | - $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").","; |
|
153 | - $sql.= " '".$this->db->escape($this->fk_menu)."',"; |
|
154 | - $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
155 | - $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
156 | - $sql.= " '".(int) $this->position."',"; |
|
157 | - $sql.= " '".$this->db->escape($this->url)."',"; |
|
158 | - $sql.= " '".$this->db->escape($this->target)."',"; |
|
159 | - $sql.= " '".$this->db->escape($this->titre)."',"; |
|
160 | - $sql.= " '".$this->db->escape($this->langs)."',"; |
|
161 | - $sql.= " '".$this->db->escape($this->perms)."',"; |
|
162 | - $sql.= " '".$this->db->escape($this->enabled)."',"; |
|
163 | - $sql.= " '".$this->db->escape($this->user)."'"; |
|
164 | - $sql.= ")"; |
|
165 | - |
|
166 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
167 | - $resql=$this->db->query($sql); |
|
168 | - if ($resql) |
|
169 | - { |
|
170 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); |
|
171 | - dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); |
|
172 | - |
|
173 | - return $this->id; |
|
174 | - } |
|
175 | - else |
|
176 | - { |
|
177 | - $this->error="Error ".$this->db->lasterror(); |
|
178 | - return -1; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Update menu entry into database. |
|
184 | - * |
|
185 | - * @param User $user User that modify |
|
186 | - * @param int $notrigger 0=no, 1=yes (no update trigger) |
|
187 | - * @return int <0 if KO, >0 if OK |
|
188 | - */ |
|
189 | - function update($user=null, $notrigger=0) |
|
190 | - { |
|
191 | - global $conf, $langs; |
|
192 | - |
|
193 | - // Clean parameters |
|
194 | - $this->rowid=trim($this->rowid); |
|
195 | - $this->menu_handler=trim($this->menu_handler); |
|
196 | - $this->module=trim($this->module); |
|
197 | - $this->type=trim($this->type); |
|
198 | - $this->mainmenu=trim($this->mainmenu); |
|
199 | - $this->leftmenu=trim($this->leftmenu); |
|
200 | - $this->fk_menu=trim($this->fk_menu); |
|
201 | - $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
202 | - $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
203 | - $this->position=trim($this->position); |
|
204 | - $this->url=trim($this->url); |
|
205 | - $this->target=trim($this->target); |
|
206 | - $this->titre=trim($this->titre); |
|
207 | - $this->langs=trim($this->langs); |
|
208 | - $this->perms=trim($this->perms); |
|
209 | - $this->enabled=trim($this->enabled); |
|
210 | - $this->user=trim($this->user); |
|
211 | - |
|
212 | - // Check parameters |
|
213 | - // Put here code to add control on parameters values |
|
214 | - |
|
215 | - // Update request |
|
216 | - $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; |
|
217 | - $sql.= " menu_handler='".$this->db->escape($this->menu_handler)."',"; |
|
218 | - $sql.= " module='".$this->db->escape($this->module)."',"; |
|
219 | - $sql.= " type='".$this->db->escape($this->type)."',"; |
|
220 | - $sql.= " mainmenu='".$this->db->escape($this->mainmenu)."',"; |
|
221 | - $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',"; |
|
222 | - $sql.= " fk_menu='".$this->db->escape($this->fk_menu)."',"; |
|
223 | - $sql.= " fk_mainmenu=".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
224 | - $sql.= " fk_leftmenu=".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
225 | - $sql.= " position=".($this->position > 0 ? $this->position : 0).","; |
|
226 | - $sql.= " url='".$this->db->escape($this->url)."',"; |
|
227 | - $sql.= " target='".$this->db->escape($this->target)."',"; |
|
228 | - $sql.= " titre='".$this->db->escape($this->titre)."',"; |
|
229 | - $sql.= " langs='".$this->db->escape($this->langs)."',"; |
|
230 | - $sql.= " perms='".$this->db->escape($this->perms)."',"; |
|
231 | - $sql.= " enabled='".$this->db->escape($this->enabled)."',"; |
|
232 | - $sql.= " usertype='".$this->db->escape($this->user)."'"; |
|
233 | - $sql.= " WHERE rowid=".$this->id; |
|
234 | - |
|
235 | - dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
236 | - $resql = $this->db->query($sql); |
|
237 | - if (! $resql) |
|
238 | - { |
|
239 | - $this->error="Error ".$this->db->lasterror(); |
|
240 | - return -1; |
|
241 | - } |
|
242 | - |
|
243 | - return 1; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Load object in memory from database |
|
249 | - * |
|
250 | - * @param int $id Id object |
|
251 | - * @param User $user User that load |
|
252 | - * @return int <0 if KO, >0 if OK |
|
253 | - */ |
|
254 | - function fetch($id, $user=null) |
|
255 | - { |
|
256 | - global $langs; |
|
257 | - |
|
258 | - $sql = "SELECT"; |
|
259 | - $sql.= " t.rowid,"; |
|
260 | - $sql.= " t.menu_handler,"; |
|
261 | - $sql.= " t.entity,"; |
|
262 | - $sql.= " t.module,"; |
|
263 | - $sql.= " t.type,"; |
|
264 | - $sql.= " t.mainmenu,"; |
|
265 | - $sql.= " t.leftmenu,"; |
|
266 | - $sql.= " t.fk_menu,"; |
|
267 | - $sql.= " t.fk_mainmenu,"; |
|
268 | - $sql.= " t.fk_leftmenu,"; |
|
269 | - $sql.= " t.position,"; |
|
270 | - $sql.= " t.url,"; |
|
271 | - $sql.= " t.target,"; |
|
272 | - $sql.= " t.titre,"; |
|
273 | - $sql.= " t.langs,"; |
|
274 | - $sql.= " t.perms,"; |
|
275 | - $sql.= " t.enabled,"; |
|
276 | - $sql.= " t.usertype as user,"; |
|
277 | - $sql.= " t.tms"; |
|
278 | - $sql.= " FROM ".MAIN_DB_PREFIX."menu as t"; |
|
279 | - $sql.= " WHERE t.rowid = ".$id; |
|
280 | - |
|
281 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
282 | - $resql=$this->db->query($sql); |
|
283 | - if ($resql) |
|
284 | - { |
|
285 | - if ($this->db->num_rows($resql)) |
|
286 | - { |
|
287 | - $obj = $this->db->fetch_object($resql); |
|
288 | - |
|
289 | - $this->id = $obj->rowid; |
|
290 | - |
|
291 | - $this->menu_handler = $obj->menu_handler; |
|
292 | - $this->entity = $obj->entity; |
|
293 | - $this->module = $obj->module; |
|
294 | - $this->type = $obj->type; |
|
295 | - $this->mainmenu = $obj->mainmenu; |
|
296 | - $this->leftmenu = $obj->leftmenu; |
|
297 | - $this->fk_menu = $obj->fk_menu; |
|
298 | - $this->fk_mainmenu = $obj->fk_mainmenu; |
|
299 | - $this->fk_leftmenu = $obj->fk_leftmenu; |
|
300 | - $this->position = $obj->position; |
|
301 | - $this->url = $obj->url; |
|
302 | - $this->target = $obj->target; |
|
303 | - $this->titre = $obj->titre; |
|
304 | - $this->langs = $obj->langs; |
|
305 | - $this->perms = $obj->perms; |
|
306 | - $this->enabled = str_replace("\"","'",$obj->enabled); |
|
307 | - $this->user = $obj->user; |
|
308 | - $this->tms = $this->db->jdate($obj->tms); |
|
309 | - } |
|
310 | - $this->db->free($resql); |
|
311 | - |
|
312 | - return 1; |
|
313 | - } |
|
314 | - else |
|
315 | - { |
|
316 | - $this->error="Error ".$this->db->lasterror(); |
|
317 | - return -1; |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Delete object in database |
|
324 | - * |
|
325 | - * @param User $user User that delete |
|
326 | - * @return int <0 if KO, >0 if OK |
|
327 | - */ |
|
328 | - function delete($user) |
|
329 | - { |
|
330 | - global $conf, $langs; |
|
331 | - |
|
332 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; |
|
333 | - $sql.= " WHERE rowid=".$this->id; |
|
334 | - |
|
335 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
336 | - $resql = $this->db->query($sql); |
|
337 | - if (! $resql) |
|
338 | - { |
|
339 | - $this->error="Error ".$this->db->lasterror(); |
|
340 | - return -1; |
|
341 | - } |
|
342 | - |
|
343 | - return 1; |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Initialise an instance with random values. |
|
349 | - * Used to build previews or test instances. |
|
350 | - * id must be 0 if object instance is a specimen. |
|
351 | - * |
|
352 | - * @return void |
|
353 | - */ |
|
354 | - function initAsSpecimen() |
|
355 | - { |
|
356 | - $this->id=0; |
|
357 | - |
|
358 | - $this->menu_handler='all'; |
|
359 | - $this->module='specimen'; |
|
360 | - $this->type='top'; |
|
361 | - $this->mainmenu=''; |
|
362 | - $this->fk_menu='0'; |
|
363 | - $this->position=''; |
|
364 | - $this->url='http://dummy'; |
|
365 | - $this->target=''; |
|
366 | - $this->titre='Specimen menu'; |
|
367 | - $this->langs=''; |
|
368 | - $this->level=''; |
|
369 | - $this->leftmenu=''; |
|
370 | - $this->perms=''; |
|
371 | - $this->enabled=''; |
|
372 | - $this->user=''; |
|
373 | - $this->tms=''; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Load tabMenu array with top menu entries found into database. |
|
379 | - * |
|
380 | - * @param string $mymainmenu Value for mainmenu to filter menu to load (always '') |
|
381 | - * @param string $myleftmenu Value for leftmenu to filter menu to load (always '') |
|
382 | - * @param int $type_user 0=Menu for backoffice, 1=Menu for front office |
|
383 | - * @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...) |
|
384 | - * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) |
|
385 | - * @return array Return array with menu entries for top menu |
|
386 | - */ |
|
387 | - function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
388 | - { |
|
389 | - global $langs, $user, $conf; // To export to dol_eval function |
|
390 | - global $mainmenu,$leftmenu; // To export to dol_eval function |
|
391 | - |
|
392 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
393 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
394 | - |
|
395 | - $newTabMenu=array(); |
|
396 | - foreach($tabMenu as $val) |
|
397 | - { |
|
398 | - if ($val['type']=='top') $newTabMenu[]=$val; |
|
399 | - } |
|
400 | - |
|
401 | - return $newTabMenu; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Load entries found from database (and stored into $tabMenu) in $this->newmenu array. |
|
406 | - * Warning: Entries in $tabMenu must have child after parent |
|
407 | - * |
|
408 | - * @param Menu $newmenu Menu array to complete (in most cases, it's empty, may be already initialized with some menu manager like eldy) |
|
409 | - * @param string $mymainmenu Value for mainmenu to filter menu to load (often $_SESSION["mainmenu"]) |
|
410 | - * @param string $myleftmenu Value for leftmenu to filter menu to load (always '') |
|
411 | - * @param int $type_user 0=Menu for backoffice, 1=Menu for front office |
|
412 | - * @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...) |
|
413 | - * @param array $tabMenu Array with menu entries already loaded |
|
414 | - * @return Menu Menu array for particular mainmenu value or full tabArray |
|
415 | - */ |
|
416 | - function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
417 | - { |
|
418 | - global $langs, $user, $conf; // To export to dol_eval function |
|
419 | - global $mainmenu,$leftmenu; // To export to dol_eval function |
|
420 | - |
|
421 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
422 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
61 | + * @param string $menu_handler Menu handler |
|
62 | + */ |
|
63 | + function __construct($db,$menu_handler='') |
|
64 | + { |
|
65 | + $this->db = $db; |
|
66 | + $this->menu_handler = $menu_handler; |
|
67 | + return 1; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Create menu entry into database |
|
73 | + * |
|
74 | + * @param User $user User that create |
|
75 | + * @return int <0 if KO, Id of record if OK |
|
76 | + */ |
|
77 | + function create($user=null) |
|
78 | + { |
|
79 | + global $conf, $langs; |
|
80 | + |
|
81 | + // Clean parameters |
|
82 | + $this->menu_handler=trim($this->menu_handler); |
|
83 | + $this->module=trim($this->module); |
|
84 | + $this->type=trim($this->type); |
|
85 | + $this->mainmenu=trim($this->mainmenu); |
|
86 | + $this->leftmenu=trim($this->leftmenu); |
|
87 | + $this->fk_menu=trim($this->fk_menu); // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
88 | + $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
89 | + $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
90 | + $this->position=trim($this->position); |
|
91 | + $this->url=trim($this->url); |
|
92 | + $this->target=trim($this->target); |
|
93 | + $this->titre=trim($this->titre); |
|
94 | + $this->langs=trim($this->langs); |
|
95 | + $this->perms=trim($this->perms); |
|
96 | + $this->enabled=trim($this->enabled); |
|
97 | + $this->user=trim($this->user); |
|
98 | + $this->position=trim($this->position); |
|
99 | + if (! $this->level) $this->level=0; |
|
100 | + |
|
101 | + // Check parameters |
|
102 | + if (empty($this->menu_handler)) return -1; |
|
103 | + |
|
104 | + // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql |
|
105 | + // may use an already used value because its internal cursor does not increase when we do |
|
106 | + // an insert with a forced id. |
|
107 | + if (in_array($this->db->type,array('pgsql'))) |
|
108 | + { |
|
109 | + $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu"; |
|
110 | + $resqlrowid=$this->db->query($sql); |
|
111 | + if ($resqlrowid) |
|
112 | + { |
|
113 | + $obj=$this->db->fetch_object($resqlrowid); |
|
114 | + $maxrowid=$obj->maxrowid; |
|
115 | + |
|
116 | + // Max rowid can be empty if there is no record yet |
|
117 | + if(empty($maxrowid)) $maxrowid=1; |
|
118 | + |
|
119 | + $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")"; |
|
120 | + //print $sql; exit; |
|
121 | + $resqlrowidset=$this->db->query($sql); |
|
122 | + if (! $resqlrowidset) dol_print_error($this->db); |
|
123 | + } |
|
124 | + else dol_print_error($this->db); |
|
125 | + } |
|
126 | + |
|
127 | + // Insert request |
|
128 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; |
|
129 | + $sql.= "menu_handler,"; |
|
130 | + $sql.= "entity,"; |
|
131 | + $sql.= "module,"; |
|
132 | + $sql.= "type,"; |
|
133 | + $sql.= "mainmenu,"; |
|
134 | + $sql.= "leftmenu,"; |
|
135 | + $sql.= "fk_menu,"; |
|
136 | + $sql.= "fk_mainmenu,"; |
|
137 | + $sql.= "fk_leftmenu,"; |
|
138 | + $sql.= "position,"; |
|
139 | + $sql.= "url,"; |
|
140 | + $sql.= "target,"; |
|
141 | + $sql.= "titre,"; |
|
142 | + $sql.= "langs,"; |
|
143 | + $sql.= "perms,"; |
|
144 | + $sql.= "enabled,"; |
|
145 | + $sql.= "usertype"; |
|
146 | + $sql.= ") VALUES ("; |
|
147 | + $sql.= " '".$this->db->escape($this->menu_handler)."',"; |
|
148 | + $sql.= " '".$this->db->escape($conf->entity)."',"; |
|
149 | + $sql.= " '".$this->db->escape($this->module)."',"; |
|
150 | + $sql.= " '".$this->db->escape($this->type)."',"; |
|
151 | + $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").","; // Can't be null |
|
152 | + $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").","; |
|
153 | + $sql.= " '".$this->db->escape($this->fk_menu)."',"; |
|
154 | + $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
155 | + $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
156 | + $sql.= " '".(int) $this->position."',"; |
|
157 | + $sql.= " '".$this->db->escape($this->url)."',"; |
|
158 | + $sql.= " '".$this->db->escape($this->target)."',"; |
|
159 | + $sql.= " '".$this->db->escape($this->titre)."',"; |
|
160 | + $sql.= " '".$this->db->escape($this->langs)."',"; |
|
161 | + $sql.= " '".$this->db->escape($this->perms)."',"; |
|
162 | + $sql.= " '".$this->db->escape($this->enabled)."',"; |
|
163 | + $sql.= " '".$this->db->escape($this->user)."'"; |
|
164 | + $sql.= ")"; |
|
165 | + |
|
166 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
167 | + $resql=$this->db->query($sql); |
|
168 | + if ($resql) |
|
169 | + { |
|
170 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); |
|
171 | + dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); |
|
172 | + |
|
173 | + return $this->id; |
|
174 | + } |
|
175 | + else |
|
176 | + { |
|
177 | + $this->error="Error ".$this->db->lasterror(); |
|
178 | + return -1; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Update menu entry into database. |
|
184 | + * |
|
185 | + * @param User $user User that modify |
|
186 | + * @param int $notrigger 0=no, 1=yes (no update trigger) |
|
187 | + * @return int <0 if KO, >0 if OK |
|
188 | + */ |
|
189 | + function update($user=null, $notrigger=0) |
|
190 | + { |
|
191 | + global $conf, $langs; |
|
192 | + |
|
193 | + // Clean parameters |
|
194 | + $this->rowid=trim($this->rowid); |
|
195 | + $this->menu_handler=trim($this->menu_handler); |
|
196 | + $this->module=trim($this->module); |
|
197 | + $this->type=trim($this->type); |
|
198 | + $this->mainmenu=trim($this->mainmenu); |
|
199 | + $this->leftmenu=trim($this->leftmenu); |
|
200 | + $this->fk_menu=trim($this->fk_menu); |
|
201 | + $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
202 | + $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
203 | + $this->position=trim($this->position); |
|
204 | + $this->url=trim($this->url); |
|
205 | + $this->target=trim($this->target); |
|
206 | + $this->titre=trim($this->titre); |
|
207 | + $this->langs=trim($this->langs); |
|
208 | + $this->perms=trim($this->perms); |
|
209 | + $this->enabled=trim($this->enabled); |
|
210 | + $this->user=trim($this->user); |
|
211 | + |
|
212 | + // Check parameters |
|
213 | + // Put here code to add control on parameters values |
|
214 | + |
|
215 | + // Update request |
|
216 | + $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; |
|
217 | + $sql.= " menu_handler='".$this->db->escape($this->menu_handler)."',"; |
|
218 | + $sql.= " module='".$this->db->escape($this->module)."',"; |
|
219 | + $sql.= " type='".$this->db->escape($this->type)."',"; |
|
220 | + $sql.= " mainmenu='".$this->db->escape($this->mainmenu)."',"; |
|
221 | + $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',"; |
|
222 | + $sql.= " fk_menu='".$this->db->escape($this->fk_menu)."',"; |
|
223 | + $sql.= " fk_mainmenu=".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
224 | + $sql.= " fk_leftmenu=".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
225 | + $sql.= " position=".($this->position > 0 ? $this->position : 0).","; |
|
226 | + $sql.= " url='".$this->db->escape($this->url)."',"; |
|
227 | + $sql.= " target='".$this->db->escape($this->target)."',"; |
|
228 | + $sql.= " titre='".$this->db->escape($this->titre)."',"; |
|
229 | + $sql.= " langs='".$this->db->escape($this->langs)."',"; |
|
230 | + $sql.= " perms='".$this->db->escape($this->perms)."',"; |
|
231 | + $sql.= " enabled='".$this->db->escape($this->enabled)."',"; |
|
232 | + $sql.= " usertype='".$this->db->escape($this->user)."'"; |
|
233 | + $sql.= " WHERE rowid=".$this->id; |
|
234 | + |
|
235 | + dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
236 | + $resql = $this->db->query($sql); |
|
237 | + if (! $resql) |
|
238 | + { |
|
239 | + $this->error="Error ".$this->db->lasterror(); |
|
240 | + return -1; |
|
241 | + } |
|
242 | + |
|
243 | + return 1; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Load object in memory from database |
|
249 | + * |
|
250 | + * @param int $id Id object |
|
251 | + * @param User $user User that load |
|
252 | + * @return int <0 if KO, >0 if OK |
|
253 | + */ |
|
254 | + function fetch($id, $user=null) |
|
255 | + { |
|
256 | + global $langs; |
|
257 | + |
|
258 | + $sql = "SELECT"; |
|
259 | + $sql.= " t.rowid,"; |
|
260 | + $sql.= " t.menu_handler,"; |
|
261 | + $sql.= " t.entity,"; |
|
262 | + $sql.= " t.module,"; |
|
263 | + $sql.= " t.type,"; |
|
264 | + $sql.= " t.mainmenu,"; |
|
265 | + $sql.= " t.leftmenu,"; |
|
266 | + $sql.= " t.fk_menu,"; |
|
267 | + $sql.= " t.fk_mainmenu,"; |
|
268 | + $sql.= " t.fk_leftmenu,"; |
|
269 | + $sql.= " t.position,"; |
|
270 | + $sql.= " t.url,"; |
|
271 | + $sql.= " t.target,"; |
|
272 | + $sql.= " t.titre,"; |
|
273 | + $sql.= " t.langs,"; |
|
274 | + $sql.= " t.perms,"; |
|
275 | + $sql.= " t.enabled,"; |
|
276 | + $sql.= " t.usertype as user,"; |
|
277 | + $sql.= " t.tms"; |
|
278 | + $sql.= " FROM ".MAIN_DB_PREFIX."menu as t"; |
|
279 | + $sql.= " WHERE t.rowid = ".$id; |
|
280 | + |
|
281 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
282 | + $resql=$this->db->query($sql); |
|
283 | + if ($resql) |
|
284 | + { |
|
285 | + if ($this->db->num_rows($resql)) |
|
286 | + { |
|
287 | + $obj = $this->db->fetch_object($resql); |
|
288 | + |
|
289 | + $this->id = $obj->rowid; |
|
290 | + |
|
291 | + $this->menu_handler = $obj->menu_handler; |
|
292 | + $this->entity = $obj->entity; |
|
293 | + $this->module = $obj->module; |
|
294 | + $this->type = $obj->type; |
|
295 | + $this->mainmenu = $obj->mainmenu; |
|
296 | + $this->leftmenu = $obj->leftmenu; |
|
297 | + $this->fk_menu = $obj->fk_menu; |
|
298 | + $this->fk_mainmenu = $obj->fk_mainmenu; |
|
299 | + $this->fk_leftmenu = $obj->fk_leftmenu; |
|
300 | + $this->position = $obj->position; |
|
301 | + $this->url = $obj->url; |
|
302 | + $this->target = $obj->target; |
|
303 | + $this->titre = $obj->titre; |
|
304 | + $this->langs = $obj->langs; |
|
305 | + $this->perms = $obj->perms; |
|
306 | + $this->enabled = str_replace("\"","'",$obj->enabled); |
|
307 | + $this->user = $obj->user; |
|
308 | + $this->tms = $this->db->jdate($obj->tms); |
|
309 | + } |
|
310 | + $this->db->free($resql); |
|
311 | + |
|
312 | + return 1; |
|
313 | + } |
|
314 | + else |
|
315 | + { |
|
316 | + $this->error="Error ".$this->db->lasterror(); |
|
317 | + return -1; |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Delete object in database |
|
324 | + * |
|
325 | + * @param User $user User that delete |
|
326 | + * @return int <0 if KO, >0 if OK |
|
327 | + */ |
|
328 | + function delete($user) |
|
329 | + { |
|
330 | + global $conf, $langs; |
|
331 | + |
|
332 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; |
|
333 | + $sql.= " WHERE rowid=".$this->id; |
|
334 | + |
|
335 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
336 | + $resql = $this->db->query($sql); |
|
337 | + if (! $resql) |
|
338 | + { |
|
339 | + $this->error="Error ".$this->db->lasterror(); |
|
340 | + return -1; |
|
341 | + } |
|
342 | + |
|
343 | + return 1; |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Initialise an instance with random values. |
|
349 | + * Used to build previews or test instances. |
|
350 | + * id must be 0 if object instance is a specimen. |
|
351 | + * |
|
352 | + * @return void |
|
353 | + */ |
|
354 | + function initAsSpecimen() |
|
355 | + { |
|
356 | + $this->id=0; |
|
357 | + |
|
358 | + $this->menu_handler='all'; |
|
359 | + $this->module='specimen'; |
|
360 | + $this->type='top'; |
|
361 | + $this->mainmenu=''; |
|
362 | + $this->fk_menu='0'; |
|
363 | + $this->position=''; |
|
364 | + $this->url='http://dummy'; |
|
365 | + $this->target=''; |
|
366 | + $this->titre='Specimen menu'; |
|
367 | + $this->langs=''; |
|
368 | + $this->level=''; |
|
369 | + $this->leftmenu=''; |
|
370 | + $this->perms=''; |
|
371 | + $this->enabled=''; |
|
372 | + $this->user=''; |
|
373 | + $this->tms=''; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Load tabMenu array with top menu entries found into database. |
|
379 | + * |
|
380 | + * @param string $mymainmenu Value for mainmenu to filter menu to load (always '') |
|
381 | + * @param string $myleftmenu Value for leftmenu to filter menu to load (always '') |
|
382 | + * @param int $type_user 0=Menu for backoffice, 1=Menu for front office |
|
383 | + * @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...) |
|
384 | + * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) |
|
385 | + * @return array Return array with menu entries for top menu |
|
386 | + */ |
|
387 | + function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
388 | + { |
|
389 | + global $langs, $user, $conf; // To export to dol_eval function |
|
390 | + global $mainmenu,$leftmenu; // To export to dol_eval function |
|
391 | + |
|
392 | + $mainmenu=$mymainmenu; // To export to dol_eval function |
|
393 | + $leftmenu=$myleftmenu; // To export to dol_eval function |
|
394 | + |
|
395 | + $newTabMenu=array(); |
|
396 | + foreach($tabMenu as $val) |
|
397 | + { |
|
398 | + if ($val['type']=='top') $newTabMenu[]=$val; |
|
399 | + } |
|
400 | + |
|
401 | + return $newTabMenu; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Load entries found from database (and stored into $tabMenu) in $this->newmenu array. |
|
406 | + * Warning: Entries in $tabMenu must have child after parent |
|
407 | + * |
|
408 | + * @param Menu $newmenu Menu array to complete (in most cases, it's empty, may be already initialized with some menu manager like eldy) |
|
409 | + * @param string $mymainmenu Value for mainmenu to filter menu to load (often $_SESSION["mainmenu"]) |
|
410 | + * @param string $myleftmenu Value for leftmenu to filter menu to load (always '') |
|
411 | + * @param int $type_user 0=Menu for backoffice, 1=Menu for front office |
|
412 | + * @param string $menu_handler Filter on name of menu_handler used (auguria, eldy...) |
|
413 | + * @param array $tabMenu Array with menu entries already loaded |
|
414 | + * @return Menu Menu array for particular mainmenu value or full tabArray |
|
415 | + */ |
|
416 | + function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
417 | + { |
|
418 | + global $langs, $user, $conf; // To export to dol_eval function |
|
419 | + global $mainmenu,$leftmenu; // To export to dol_eval function |
|
420 | + |
|
421 | + $mainmenu=$mymainmenu; // To export to dol_eval function |
|
422 | + $leftmenu=$myleftmenu; // To export to dol_eval function |
|
423 | 423 | |
424 | 424 | // Detect what is top mainmenu id |
425 | - $menutopid=''; |
|
426 | - foreach($tabMenu as $key => $val) |
|
427 | - { |
|
428 | - // Define menutopid of mainmenu |
|
429 | - if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) |
|
430 | - { |
|
431 | - $menutopid=$val['rowid']; |
|
432 | - break; |
|
433 | - } |
|
434 | - } |
|
435 | - |
|
436 | - // We initialize newmenu with first already found menu entries |
|
437 | - $this->newmenu = $newmenu; |
|
438 | - |
|
439 | - // Now complete $this->newmenu->list to add entries found into $tabMenu that are childs of mainmenu=$menutopid, using the fk_menu link that is int (old method) |
|
440 | - $this->recur($tabMenu, $menutopid, 1); |
|
441 | - |
|
442 | - // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu) |
|
443 | - foreach($tabMenu as $key => $val) |
|
444 | - { |
|
445 | - //var_dump($tabMenu); |
|
446 | - if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) // We found a menu entry not linked to parent with good mainmenu |
|
447 | - { |
|
448 | - //print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>'; |
|
449 | - //var_dump($this->newmenu->liste);exit; |
|
450 | - |
|
451 | - if (empty($val['fk_leftmenu'])) |
|
452 | - { |
|
453 | - $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
454 | - //var_dump($this->newmenu->liste); |
|
455 | - } |
|
456 | - else |
|
457 | - { |
|
458 | - // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu) |
|
459 | - $searchlastsub=0;$lastid=0;$nextid=0;$found=0; |
|
460 | - foreach($this->newmenu->liste as $keyparent => $valparent) |
|
461 | - { |
|
462 | - //var_dump($valparent); |
|
463 | - if ($searchlastsub) // If we started to search for last submenu |
|
464 | - { |
|
465 | - if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent; |
|
466 | - if ($valparent['level'] < $searchlastsub) |
|
467 | - { |
|
468 | - $nextid=$keyparent; |
|
469 | - break; |
|
470 | - } |
|
471 | - } |
|
472 | - if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) |
|
473 | - { |
|
474 | - //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>'; |
|
475 | - // Now we look to find last subelement of this parent (we add at end) |
|
476 | - $searchlastsub=($valparent['level']+1); |
|
477 | - $lastid=$keyparent; |
|
478 | - $found=1; |
|
479 | - } |
|
480 | - } |
|
481 | - //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>'; |
|
482 | - if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
483 | - else { |
|
484 | - dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING); |
|
485 | - //print "Parent menu not found !!<br>"; |
|
486 | - } |
|
487 | - } |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - return $this->newmenu; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * Load entries found in database into variable $tabMenu. Note that only "database menu entries" are loaded here, hardcoded will not be present into output. |
|
497 | - * |
|
498 | - * @param string $mymainmenu Value for mainmenu that defined mainmenu |
|
499 | - * @param string $myleftmenu Value for left that defined leftmenu |
|
500 | - * @param int $type_user Looks for menu entry for 0=Internal users, 1=External users |
|
501 | - * @param string $menu_handler Name of menu_handler used ('auguria', 'eldy'...) |
|
502 | - * @param array $tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) |
|
503 | - * @return int >0 if OK, <0 if KO |
|
504 | - */ |
|
505 | - function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
506 | - { |
|
507 | - global $langs, $user, $conf; // To export to dol_eval function |
|
508 | - global $mainmenu, $leftmenu; // To export to dol_eval function |
|
509 | - |
|
510 | - $menutopid=0; |
|
511 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
512 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
513 | - |
|
514 | - $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position"; |
|
515 | - $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; |
|
516 | - $sql.= " WHERE m.entity IN (0,".$conf->entity.")"; |
|
517 | - $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')"; |
|
518 | - if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)"; |
|
519 | - if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)"; |
|
520 | - $sql.= " ORDER BY m.position, m.rowid"; |
|
425 | + $menutopid=''; |
|
426 | + foreach($tabMenu as $key => $val) |
|
427 | + { |
|
428 | + // Define menutopid of mainmenu |
|
429 | + if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) |
|
430 | + { |
|
431 | + $menutopid=$val['rowid']; |
|
432 | + break; |
|
433 | + } |
|
434 | + } |
|
435 | + |
|
436 | + // We initialize newmenu with first already found menu entries |
|
437 | + $this->newmenu = $newmenu; |
|
438 | + |
|
439 | + // Now complete $this->newmenu->list to add entries found into $tabMenu that are childs of mainmenu=$menutopid, using the fk_menu link that is int (old method) |
|
440 | + $this->recur($tabMenu, $menutopid, 1); |
|
441 | + |
|
442 | + // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu) |
|
443 | + foreach($tabMenu as $key => $val) |
|
444 | + { |
|
445 | + //var_dump($tabMenu); |
|
446 | + if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) // We found a menu entry not linked to parent with good mainmenu |
|
447 | + { |
|
448 | + //print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>'; |
|
449 | + //var_dump($this->newmenu->liste);exit; |
|
450 | + |
|
451 | + if (empty($val['fk_leftmenu'])) |
|
452 | + { |
|
453 | + $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
454 | + //var_dump($this->newmenu->liste); |
|
455 | + } |
|
456 | + else |
|
457 | + { |
|
458 | + // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu) |
|
459 | + $searchlastsub=0;$lastid=0;$nextid=0;$found=0; |
|
460 | + foreach($this->newmenu->liste as $keyparent => $valparent) |
|
461 | + { |
|
462 | + //var_dump($valparent); |
|
463 | + if ($searchlastsub) // If we started to search for last submenu |
|
464 | + { |
|
465 | + if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent; |
|
466 | + if ($valparent['level'] < $searchlastsub) |
|
467 | + { |
|
468 | + $nextid=$keyparent; |
|
469 | + break; |
|
470 | + } |
|
471 | + } |
|
472 | + if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu']) |
|
473 | + { |
|
474 | + //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>'; |
|
475 | + // Now we look to find last subelement of this parent (we add at end) |
|
476 | + $searchlastsub=($valparent['level']+1); |
|
477 | + $lastid=$keyparent; |
|
478 | + $found=1; |
|
479 | + } |
|
480 | + } |
|
481 | + //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>'; |
|
482 | + if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
|
483 | + else { |
|
484 | + dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING); |
|
485 | + //print "Parent menu not found !!<br>"; |
|
486 | + } |
|
487 | + } |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + return $this->newmenu; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * Load entries found in database into variable $tabMenu. Note that only "database menu entries" are loaded here, hardcoded will not be present into output. |
|
497 | + * |
|
498 | + * @param string $mymainmenu Value for mainmenu that defined mainmenu |
|
499 | + * @param string $myleftmenu Value for left that defined leftmenu |
|
500 | + * @param int $type_user Looks for menu entry for 0=Internal users, 1=External users |
|
501 | + * @param string $menu_handler Name of menu_handler used ('auguria', 'eldy'...) |
|
502 | + * @param array $tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) |
|
503 | + * @return int >0 if OK, <0 if KO |
|
504 | + */ |
|
505 | + function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
|
506 | + { |
|
507 | + global $langs, $user, $conf; // To export to dol_eval function |
|
508 | + global $mainmenu, $leftmenu; // To export to dol_eval function |
|
509 | + |
|
510 | + $menutopid=0; |
|
511 | + $mainmenu=$mymainmenu; // To export to dol_eval function |
|
512 | + $leftmenu=$myleftmenu; // To export to dol_eval function |
|
513 | + |
|
514 | + $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position"; |
|
515 | + $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; |
|
516 | + $sql.= " WHERE m.entity IN (0,".$conf->entity.")"; |
|
517 | + $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')"; |
|
518 | + if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)"; |
|
519 | + if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)"; |
|
520 | + $sql.= " ORDER BY m.position, m.rowid"; |
|
521 | 521 | //print $sql; |
522 | 522 | |
523 | 523 | //$tmp1=microtime(true); |
524 | 524 | //print '>>> 1 0<br>'; |
525 | - dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG); |
|
526 | - $resql = $this->db->query($sql); |
|
527 | - if ($resql) |
|
528 | - { |
|
529 | - $numa = $this->db->num_rows($resql); |
|
530 | - |
|
531 | - $a = 0; |
|
532 | - $b = 0; |
|
533 | - $oldrowid=0; |
|
534 | - while ($a < $numa) |
|
535 | - { |
|
536 | - //$objm = $this->db->fetch_object($resql); |
|
537 | - $menu = $this->db->fetch_array($resql); |
|
538 | - |
|
539 | - // Define $right |
|
540 | - $perms = true; |
|
541 | - if ($menu['perms']) |
|
542 | - { |
|
543 | - $tmpcond=$menu['perms']; |
|
544 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
545 | - $perms = verifCond($tmpcond); |
|
546 | - //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n"; |
|
547 | - } |
|
548 | - |
|
549 | - // Define $enabled |
|
550 | - $enabled = true; |
|
551 | - if ($menu['enabled']) |
|
552 | - { |
|
553 | - $tmpcond=$menu['enabled']; |
|
554 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
555 | - $enabled = verifCond($tmpcond); |
|
556 | - } |
|
557 | - |
|
558 | - // Define $title |
|
559 | - if ($enabled) |
|
560 | - { |
|
561 | - $title = $langs->trans($menu['titre']); |
|
562 | - if ($title == $menu['titre']) // Translation not found |
|
563 | - { |
|
564 | - if (! empty($menu['langs'])) // If there is a dedicated translation file |
|
565 | - { |
|
566 | - //print 'Load file '.$menu['langs'].'<br>'; |
|
567 | - $langs->load($menu['langs']); |
|
568 | - } |
|
569 | - |
|
570 | - if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 |
|
571 | - { |
|
572 | - $tab_titre = explode("/",$menu['titre']); |
|
573 | - $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); |
|
574 | - } |
|
575 | - else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
576 | - { |
|
577 | - $tab_title = explode("||",$menu['titre']); |
|
578 | - $alt_title = explode("@",$tab_title[1]); |
|
579 | - $title_enabled = verifCond($alt_title[1]); |
|
580 | - $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0])); |
|
581 | - } |
|
582 | - else |
|
583 | - { |
|
584 | - $title = $langs->trans($menu['titre']); |
|
585 | - } |
|
586 | - } |
|
525 | + dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG); |
|
526 | + $resql = $this->db->query($sql); |
|
527 | + if ($resql) |
|
528 | + { |
|
529 | + $numa = $this->db->num_rows($resql); |
|
530 | + |
|
531 | + $a = 0; |
|
532 | + $b = 0; |
|
533 | + $oldrowid=0; |
|
534 | + while ($a < $numa) |
|
535 | + { |
|
536 | + //$objm = $this->db->fetch_object($resql); |
|
537 | + $menu = $this->db->fetch_array($resql); |
|
538 | + |
|
539 | + // Define $right |
|
540 | + $perms = true; |
|
541 | + if ($menu['perms']) |
|
542 | + { |
|
543 | + $tmpcond=$menu['perms']; |
|
544 | + if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
545 | + $perms = verifCond($tmpcond); |
|
546 | + //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n"; |
|
547 | + } |
|
548 | + |
|
549 | + // Define $enabled |
|
550 | + $enabled = true; |
|
551 | + if ($menu['enabled']) |
|
552 | + { |
|
553 | + $tmpcond=$menu['enabled']; |
|
554 | + if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
555 | + $enabled = verifCond($tmpcond); |
|
556 | + } |
|
557 | + |
|
558 | + // Define $title |
|
559 | + if ($enabled) |
|
560 | + { |
|
561 | + $title = $langs->trans($menu['titre']); |
|
562 | + if ($title == $menu['titre']) // Translation not found |
|
563 | + { |
|
564 | + if (! empty($menu['langs'])) // If there is a dedicated translation file |
|
565 | + { |
|
566 | + //print 'Load file '.$menu['langs'].'<br>'; |
|
567 | + $langs->load($menu['langs']); |
|
568 | + } |
|
569 | + |
|
570 | + if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 |
|
571 | + { |
|
572 | + $tab_titre = explode("/",$menu['titre']); |
|
573 | + $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); |
|
574 | + } |
|
575 | + else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
576 | + { |
|
577 | + $tab_title = explode("||",$menu['titre']); |
|
578 | + $alt_title = explode("@",$tab_title[1]); |
|
579 | + $title_enabled = verifCond($alt_title[1]); |
|
580 | + $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0])); |
|
581 | + } |
|
582 | + else |
|
583 | + { |
|
584 | + $title = $langs->trans($menu['titre']); |
|
585 | + } |
|
586 | + } |
|
587 | 587 | //$tmp4=microtime(true); |
588 | 588 | //print '>>> 3 '.($tmp4 - $tmp3).'<br>'; |
589 | 589 | |
590 | - // We complete tabMenu |
|
591 | - $tabMenu[$b]['rowid'] = $menu['rowid']; |
|
592 | - $tabMenu[$b]['module'] = $menu['module']; |
|
593 | - $tabMenu[$b]['fk_menu'] = $menu['fk_menu']; |
|
594 | - $tabMenu[$b]['url'] = $menu['url']; |
|
595 | - if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url'])) |
|
596 | - { |
|
597 | - if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; |
|
598 | - else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; |
|
599 | - } |
|
600 | - $tabMenu[$b]['titre'] = $title; |
|
601 | - $tabMenu[$b]['target'] = $menu['target']; |
|
602 | - $tabMenu[$b]['mainmenu'] = $menu['mainmenu']; |
|
603 | - $tabMenu[$b]['leftmenu'] = $menu['leftmenu']; |
|
604 | - $tabMenu[$b]['perms'] = $perms; |
|
605 | - $tabMenu[$b]['enabled'] = $enabled; |
|
606 | - $tabMenu[$b]['type'] = $menu['type']; |
|
607 | - //$tabMenu[$b]['langs'] = $menu['langs']; |
|
608 | - $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu']; |
|
609 | - $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu']; |
|
610 | - $tabMenu[$b]['position'] = (int) $menu['position']; |
|
611 | - |
|
612 | - $b++; |
|
613 | - } |
|
614 | - |
|
615 | - $a++; |
|
616 | - } |
|
617 | - $this->db->free($resql); |
|
618 | - |
|
619 | - // Currently $tabMenu is sorted on position. |
|
620 | - // If a child have a position lower that its parent, we can make a loop to fix this here, but we prefer to show a warning |
|
621 | - // into the leftMenuCharger later to avoid useless operations. |
|
622 | - |
|
623 | - return 1; |
|
624 | - } |
|
625 | - else |
|
626 | - { |
|
627 | - dol_print_error($this->db); |
|
628 | - return -1; |
|
629 | - } |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Complete this->newmenu with menu entry found in $tab |
|
634 | - * |
|
635 | - * @param array $tab Tab array with all menu entries |
|
636 | - * @param int $pere Id of parent |
|
637 | - * @param int $level Level |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - private function recur($tab, $pere, $level) |
|
641 | - { |
|
642 | - // Loop on tab array |
|
643 | - $num = count($tab); |
|
644 | - for ($x = 0; $x < $num; $x++) |
|
645 | - { |
|
646 | - //si un element a pour pere : $pere |
|
647 | - if ( (($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) |
|
648 | - { |
|
649 | - $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level-1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']); |
|
650 | - $this->recur($tab, $tab[$x]['rowid'], ($level+1)); |
|
651 | - } |
|
652 | - } |
|
590 | + // We complete tabMenu |
|
591 | + $tabMenu[$b]['rowid'] = $menu['rowid']; |
|
592 | + $tabMenu[$b]['module'] = $menu['module']; |
|
593 | + $tabMenu[$b]['fk_menu'] = $menu['fk_menu']; |
|
594 | + $tabMenu[$b]['url'] = $menu['url']; |
|
595 | + if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url'])) |
|
596 | + { |
|
597 | + if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; |
|
598 | + else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; |
|
599 | + } |
|
600 | + $tabMenu[$b]['titre'] = $title; |
|
601 | + $tabMenu[$b]['target'] = $menu['target']; |
|
602 | + $tabMenu[$b]['mainmenu'] = $menu['mainmenu']; |
|
603 | + $tabMenu[$b]['leftmenu'] = $menu['leftmenu']; |
|
604 | + $tabMenu[$b]['perms'] = $perms; |
|
605 | + $tabMenu[$b]['enabled'] = $enabled; |
|
606 | + $tabMenu[$b]['type'] = $menu['type']; |
|
607 | + //$tabMenu[$b]['langs'] = $menu['langs']; |
|
608 | + $tabMenu[$b]['fk_mainmenu'] = $menu['fk_mainmenu']; |
|
609 | + $tabMenu[$b]['fk_leftmenu'] = $menu['fk_leftmenu']; |
|
610 | + $tabMenu[$b]['position'] = (int) $menu['position']; |
|
611 | + |
|
612 | + $b++; |
|
613 | + } |
|
614 | + |
|
615 | + $a++; |
|
616 | + } |
|
617 | + $this->db->free($resql); |
|
618 | + |
|
619 | + // Currently $tabMenu is sorted on position. |
|
620 | + // If a child have a position lower that its parent, we can make a loop to fix this here, but we prefer to show a warning |
|
621 | + // into the leftMenuCharger later to avoid useless operations. |
|
622 | + |
|
623 | + return 1; |
|
624 | + } |
|
625 | + else |
|
626 | + { |
|
627 | + dol_print_error($this->db); |
|
628 | + return -1; |
|
629 | + } |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Complete this->newmenu with menu entry found in $tab |
|
634 | + * |
|
635 | + * @param array $tab Tab array with all menu entries |
|
636 | + * @param int $pere Id of parent |
|
637 | + * @param int $level Level |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + private function recur($tab, $pere, $level) |
|
641 | + { |
|
642 | + // Loop on tab array |
|
643 | + $num = count($tab); |
|
644 | + for ($x = 0; $x < $num; $x++) |
|
645 | + { |
|
646 | + //si un element a pour pere : $pere |
|
647 | + if ( (($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) |
|
648 | + { |
|
649 | + $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level-1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']); |
|
650 | + $this->recur($tab, $tab[$x]['rowid'], ($level+1)); |
|
651 | + } |
|
652 | + } |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | } |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class Menubase |
30 | 30 | { |
31 | - public $db; // To store db handler |
|
32 | - public $error; // To return error code (or message) |
|
33 | - public $errors=array(); // To return several error codes (or messages) |
|
31 | + public $db; // To store db handler |
|
32 | + public $error; // To return error code (or message) |
|
33 | + public $errors = array(); // To return several error codes (or messages) |
|
34 | 34 | |
35 | 35 | public $id; |
36 | 36 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public $titre; |
48 | 48 | public $langs; |
49 | 49 | public $level; |
50 | - public $leftmenu; //<! Not used |
|
50 | + public $leftmenu; //<! Not used |
|
51 | 51 | public $perms; |
52 | 52 | public $enabled; |
53 | 53 | public $user; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param DoliDB $db Database handler |
61 | 61 | * @param string $menu_handler Menu handler |
62 | 62 | */ |
63 | - function __construct($db,$menu_handler='') |
|
63 | + function __construct($db, $menu_handler = '') |
|
64 | 64 | { |
65 | 65 | $this->db = $db; |
66 | 66 | $this->menu_handler = $menu_handler; |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | * @param User $user User that create |
75 | 75 | * @return int <0 if KO, Id of record if OK |
76 | 76 | */ |
77 | - function create($user=null) |
|
77 | + function create($user = null) |
|
78 | 78 | { |
79 | 79 | global $conf, $langs; |
80 | 80 | |
81 | 81 | // Clean parameters |
82 | - $this->menu_handler=trim($this->menu_handler); |
|
83 | - $this->module=trim($this->module); |
|
84 | - $this->type=trim($this->type); |
|
85 | - $this->mainmenu=trim($this->mainmenu); |
|
86 | - $this->leftmenu=trim($this->leftmenu); |
|
87 | - $this->fk_menu=trim($this->fk_menu); // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
88 | - $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
89 | - $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
90 | - $this->position=trim($this->position); |
|
91 | - $this->url=trim($this->url); |
|
92 | - $this->target=trim($this->target); |
|
93 | - $this->titre=trim($this->titre); |
|
94 | - $this->langs=trim($this->langs); |
|
95 | - $this->perms=trim($this->perms); |
|
96 | - $this->enabled=trim($this->enabled); |
|
97 | - $this->user=trim($this->user); |
|
98 | - $this->position=trim($this->position); |
|
99 | - if (! $this->level) $this->level=0; |
|
82 | + $this->menu_handler = trim($this->menu_handler); |
|
83 | + $this->module = trim($this->module); |
|
84 | + $this->type = trim($this->type); |
|
85 | + $this->mainmenu = trim($this->mainmenu); |
|
86 | + $this->leftmenu = trim($this->leftmenu); |
|
87 | + $this->fk_menu = trim($this->fk_menu); // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
88 | + $this->fk_mainmenu = trim($this->fk_mainmenu); |
|
89 | + $this->fk_leftmenu = trim($this->fk_leftmenu); |
|
90 | + $this->position = trim($this->position); |
|
91 | + $this->url = trim($this->url); |
|
92 | + $this->target = trim($this->target); |
|
93 | + $this->titre = trim($this->titre); |
|
94 | + $this->langs = trim($this->langs); |
|
95 | + $this->perms = trim($this->perms); |
|
96 | + $this->enabled = trim($this->enabled); |
|
97 | + $this->user = trim($this->user); |
|
98 | + $this->position = trim($this->position); |
|
99 | + if (!$this->level) $this->level = 0; |
|
100 | 100 | |
101 | 101 | // Check parameters |
102 | 102 | if (empty($this->menu_handler)) return -1; |
@@ -104,67 +104,67 @@ discard block |
||
104 | 104 | // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql |
105 | 105 | // may use an already used value because its internal cursor does not increase when we do |
106 | 106 | // an insert with a forced id. |
107 | - if (in_array($this->db->type,array('pgsql'))) |
|
107 | + if (in_array($this->db->type, array('pgsql'))) |
|
108 | 108 | { |
109 | 109 | $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu"; |
110 | - $resqlrowid=$this->db->query($sql); |
|
110 | + $resqlrowid = $this->db->query($sql); |
|
111 | 111 | if ($resqlrowid) |
112 | 112 | { |
113 | - $obj=$this->db->fetch_object($resqlrowid); |
|
114 | - $maxrowid=$obj->maxrowid; |
|
113 | + $obj = $this->db->fetch_object($resqlrowid); |
|
114 | + $maxrowid = $obj->maxrowid; |
|
115 | 115 | |
116 | 116 | // Max rowid can be empty if there is no record yet |
117 | - if(empty($maxrowid)) $maxrowid=1; |
|
117 | + if (empty($maxrowid)) $maxrowid = 1; |
|
118 | 118 | |
119 | 119 | $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")"; |
120 | 120 | //print $sql; exit; |
121 | - $resqlrowidset=$this->db->query($sql); |
|
122 | - if (! $resqlrowidset) dol_print_error($this->db); |
|
121 | + $resqlrowidset = $this->db->query($sql); |
|
122 | + if (!$resqlrowidset) dol_print_error($this->db); |
|
123 | 123 | } |
124 | 124 | else dol_print_error($this->db); |
125 | 125 | } |
126 | 126 | |
127 | 127 | // Insert request |
128 | 128 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; |
129 | - $sql.= "menu_handler,"; |
|
130 | - $sql.= "entity,"; |
|
131 | - $sql.= "module,"; |
|
132 | - $sql.= "type,"; |
|
133 | - $sql.= "mainmenu,"; |
|
134 | - $sql.= "leftmenu,"; |
|
135 | - $sql.= "fk_menu,"; |
|
136 | - $sql.= "fk_mainmenu,"; |
|
137 | - $sql.= "fk_leftmenu,"; |
|
138 | - $sql.= "position,"; |
|
139 | - $sql.= "url,"; |
|
140 | - $sql.= "target,"; |
|
141 | - $sql.= "titre,"; |
|
142 | - $sql.= "langs,"; |
|
143 | - $sql.= "perms,"; |
|
144 | - $sql.= "enabled,"; |
|
145 | - $sql.= "usertype"; |
|
146 | - $sql.= ") VALUES ("; |
|
147 | - $sql.= " '".$this->db->escape($this->menu_handler)."',"; |
|
148 | - $sql.= " '".$this->db->escape($conf->entity)."',"; |
|
149 | - $sql.= " '".$this->db->escape($this->module)."',"; |
|
150 | - $sql.= " '".$this->db->escape($this->type)."',"; |
|
151 | - $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").","; // Can't be null |
|
152 | - $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").","; |
|
153 | - $sql.= " '".$this->db->escape($this->fk_menu)."',"; |
|
154 | - $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
155 | - $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
156 | - $sql.= " '".(int) $this->position."',"; |
|
157 | - $sql.= " '".$this->db->escape($this->url)."',"; |
|
158 | - $sql.= " '".$this->db->escape($this->target)."',"; |
|
159 | - $sql.= " '".$this->db->escape($this->titre)."',"; |
|
160 | - $sql.= " '".$this->db->escape($this->langs)."',"; |
|
161 | - $sql.= " '".$this->db->escape($this->perms)."',"; |
|
162 | - $sql.= " '".$this->db->escape($this->enabled)."',"; |
|
163 | - $sql.= " '".$this->db->escape($this->user)."'"; |
|
164 | - $sql.= ")"; |
|
129 | + $sql .= "menu_handler,"; |
|
130 | + $sql .= "entity,"; |
|
131 | + $sql .= "module,"; |
|
132 | + $sql .= "type,"; |
|
133 | + $sql .= "mainmenu,"; |
|
134 | + $sql .= "leftmenu,"; |
|
135 | + $sql .= "fk_menu,"; |
|
136 | + $sql .= "fk_mainmenu,"; |
|
137 | + $sql .= "fk_leftmenu,"; |
|
138 | + $sql .= "position,"; |
|
139 | + $sql .= "url,"; |
|
140 | + $sql .= "target,"; |
|
141 | + $sql .= "titre,"; |
|
142 | + $sql .= "langs,"; |
|
143 | + $sql .= "perms,"; |
|
144 | + $sql .= "enabled,"; |
|
145 | + $sql .= "usertype"; |
|
146 | + $sql .= ") VALUES ("; |
|
147 | + $sql .= " '".$this->db->escape($this->menu_handler)."',"; |
|
148 | + $sql .= " '".$this->db->escape($conf->entity)."',"; |
|
149 | + $sql .= " '".$this->db->escape($this->module)."',"; |
|
150 | + $sql .= " '".$this->db->escape($this->type)."',"; |
|
151 | + $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null |
|
152 | + $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").","; |
|
153 | + $sql .= " '".$this->db->escape($this->fk_menu)."',"; |
|
154 | + $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").","; |
|
155 | + $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").","; |
|
156 | + $sql .= " '".(int) $this->position."',"; |
|
157 | + $sql .= " '".$this->db->escape($this->url)."',"; |
|
158 | + $sql .= " '".$this->db->escape($this->target)."',"; |
|
159 | + $sql .= " '".$this->db->escape($this->titre)."',"; |
|
160 | + $sql .= " '".$this->db->escape($this->langs)."',"; |
|
161 | + $sql .= " '".$this->db->escape($this->perms)."',"; |
|
162 | + $sql .= " '".$this->db->escape($this->enabled)."',"; |
|
163 | + $sql .= " '".$this->db->escape($this->user)."'"; |
|
164 | + $sql .= ")"; |
|
165 | 165 | |
166 | 166 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
167 | - $resql=$this->db->query($sql); |
|
167 | + $resql = $this->db->query($sql); |
|
168 | 168 | if ($resql) |
169 | 169 | { |
170 | 170 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | else |
176 | 176 | { |
177 | - $this->error="Error ".$this->db->lasterror(); |
|
177 | + $this->error = "Error ".$this->db->lasterror(); |
|
178 | 178 | return -1; |
179 | 179 | } |
180 | 180 | } |
@@ -186,57 +186,57 @@ discard block |
||
186 | 186 | * @param int $notrigger 0=no, 1=yes (no update trigger) |
187 | 187 | * @return int <0 if KO, >0 if OK |
188 | 188 | */ |
189 | - function update($user=null, $notrigger=0) |
|
189 | + function update($user = null, $notrigger = 0) |
|
190 | 190 | { |
191 | 191 | global $conf, $langs; |
192 | 192 | |
193 | 193 | // Clean parameters |
194 | - $this->rowid=trim($this->rowid); |
|
195 | - $this->menu_handler=trim($this->menu_handler); |
|
196 | - $this->module=trim($this->module); |
|
197 | - $this->type=trim($this->type); |
|
198 | - $this->mainmenu=trim($this->mainmenu); |
|
199 | - $this->leftmenu=trim($this->leftmenu); |
|
200 | - $this->fk_menu=trim($this->fk_menu); |
|
201 | - $this->fk_mainmenu=trim($this->fk_mainmenu); |
|
202 | - $this->fk_leftmenu=trim($this->fk_leftmenu); |
|
203 | - $this->position=trim($this->position); |
|
204 | - $this->url=trim($this->url); |
|
205 | - $this->target=trim($this->target); |
|
206 | - $this->titre=trim($this->titre); |
|
207 | - $this->langs=trim($this->langs); |
|
208 | - $this->perms=trim($this->perms); |
|
209 | - $this->enabled=trim($this->enabled); |
|
210 | - $this->user=trim($this->user); |
|
194 | + $this->rowid = trim($this->rowid); |
|
195 | + $this->menu_handler = trim($this->menu_handler); |
|
196 | + $this->module = trim($this->module); |
|
197 | + $this->type = trim($this->type); |
|
198 | + $this->mainmenu = trim($this->mainmenu); |
|
199 | + $this->leftmenu = trim($this->leftmenu); |
|
200 | + $this->fk_menu = trim($this->fk_menu); |
|
201 | + $this->fk_mainmenu = trim($this->fk_mainmenu); |
|
202 | + $this->fk_leftmenu = trim($this->fk_leftmenu); |
|
203 | + $this->position = trim($this->position); |
|
204 | + $this->url = trim($this->url); |
|
205 | + $this->target = trim($this->target); |
|
206 | + $this->titre = trim($this->titre); |
|
207 | + $this->langs = trim($this->langs); |
|
208 | + $this->perms = trim($this->perms); |
|
209 | + $this->enabled = trim($this->enabled); |
|
210 | + $this->user = trim($this->user); |
|
211 | 211 | |
212 | 212 | // Check parameters |
213 | 213 | // Put here code to add control on parameters values |
214 | 214 | |
215 | 215 | // Update request |
216 | 216 | $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; |
217 | - $sql.= " menu_handler='".$this->db->escape($this->menu_handler)."',"; |
|
218 | - $sql.= " module='".$this->db->escape($this->module)."',"; |
|
219 | - $sql.= " type='".$this->db->escape($this->type)."',"; |
|
220 | - $sql.= " mainmenu='".$this->db->escape($this->mainmenu)."',"; |
|
221 | - $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',"; |
|
222 | - $sql.= " fk_menu='".$this->db->escape($this->fk_menu)."',"; |
|
223 | - $sql.= " fk_mainmenu=".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").","; |
|
224 | - $sql.= " fk_leftmenu=".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").","; |
|
225 | - $sql.= " position=".($this->position > 0 ? $this->position : 0).","; |
|
226 | - $sql.= " url='".$this->db->escape($this->url)."',"; |
|
227 | - $sql.= " target='".$this->db->escape($this->target)."',"; |
|
228 | - $sql.= " titre='".$this->db->escape($this->titre)."',"; |
|
229 | - $sql.= " langs='".$this->db->escape($this->langs)."',"; |
|
230 | - $sql.= " perms='".$this->db->escape($this->perms)."',"; |
|
231 | - $sql.= " enabled='".$this->db->escape($this->enabled)."',"; |
|
232 | - $sql.= " usertype='".$this->db->escape($this->user)."'"; |
|
233 | - $sql.= " WHERE rowid=".$this->id; |
|
217 | + $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',"; |
|
218 | + $sql .= " module='".$this->db->escape($this->module)."',"; |
|
219 | + $sql .= " type='".$this->db->escape($this->type)."',"; |
|
220 | + $sql .= " mainmenu='".$this->db->escape($this->mainmenu)."',"; |
|
221 | + $sql .= " leftmenu='".$this->db->escape($this->leftmenu)."',"; |
|
222 | + $sql .= " fk_menu='".$this->db->escape($this->fk_menu)."',"; |
|
223 | + $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").","; |
|
224 | + $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").","; |
|
225 | + $sql .= " position=".($this->position > 0 ? $this->position : 0).","; |
|
226 | + $sql .= " url='".$this->db->escape($this->url)."',"; |
|
227 | + $sql .= " target='".$this->db->escape($this->target)."',"; |
|
228 | + $sql .= " titre='".$this->db->escape($this->titre)."',"; |
|
229 | + $sql .= " langs='".$this->db->escape($this->langs)."',"; |
|
230 | + $sql .= " perms='".$this->db->escape($this->perms)."',"; |
|
231 | + $sql .= " enabled='".$this->db->escape($this->enabled)."',"; |
|
232 | + $sql .= " usertype='".$this->db->escape($this->user)."'"; |
|
233 | + $sql .= " WHERE rowid=".$this->id; |
|
234 | 234 | |
235 | 235 | dol_syslog(get_class($this)."::update", LOG_DEBUG); |
236 | 236 | $resql = $this->db->query($sql); |
237 | - if (! $resql) |
|
237 | + if (!$resql) |
|
238 | 238 | { |
239 | - $this->error="Error ".$this->db->lasterror(); |
|
239 | + $this->error = "Error ".$this->db->lasterror(); |
|
240 | 240 | return -1; |
241 | 241 | } |
242 | 242 | |
@@ -251,42 +251,42 @@ discard block |
||
251 | 251 | * @param User $user User that load |
252 | 252 | * @return int <0 if KO, >0 if OK |
253 | 253 | */ |
254 | - function fetch($id, $user=null) |
|
254 | + function fetch($id, $user = null) |
|
255 | 255 | { |
256 | 256 | global $langs; |
257 | 257 | |
258 | 258 | $sql = "SELECT"; |
259 | - $sql.= " t.rowid,"; |
|
260 | - $sql.= " t.menu_handler,"; |
|
261 | - $sql.= " t.entity,"; |
|
262 | - $sql.= " t.module,"; |
|
263 | - $sql.= " t.type,"; |
|
264 | - $sql.= " t.mainmenu,"; |
|
265 | - $sql.= " t.leftmenu,"; |
|
266 | - $sql.= " t.fk_menu,"; |
|
267 | - $sql.= " t.fk_mainmenu,"; |
|
268 | - $sql.= " t.fk_leftmenu,"; |
|
269 | - $sql.= " t.position,"; |
|
270 | - $sql.= " t.url,"; |
|
271 | - $sql.= " t.target,"; |
|
272 | - $sql.= " t.titre,"; |
|
273 | - $sql.= " t.langs,"; |
|
274 | - $sql.= " t.perms,"; |
|
275 | - $sql.= " t.enabled,"; |
|
276 | - $sql.= " t.usertype as user,"; |
|
277 | - $sql.= " t.tms"; |
|
278 | - $sql.= " FROM ".MAIN_DB_PREFIX."menu as t"; |
|
279 | - $sql.= " WHERE t.rowid = ".$id; |
|
259 | + $sql .= " t.rowid,"; |
|
260 | + $sql .= " t.menu_handler,"; |
|
261 | + $sql .= " t.entity,"; |
|
262 | + $sql .= " t.module,"; |
|
263 | + $sql .= " t.type,"; |
|
264 | + $sql .= " t.mainmenu,"; |
|
265 | + $sql .= " t.leftmenu,"; |
|
266 | + $sql .= " t.fk_menu,"; |
|
267 | + $sql .= " t.fk_mainmenu,"; |
|
268 | + $sql .= " t.fk_leftmenu,"; |
|
269 | + $sql .= " t.position,"; |
|
270 | + $sql .= " t.url,"; |
|
271 | + $sql .= " t.target,"; |
|
272 | + $sql .= " t.titre,"; |
|
273 | + $sql .= " t.langs,"; |
|
274 | + $sql .= " t.perms,"; |
|
275 | + $sql .= " t.enabled,"; |
|
276 | + $sql .= " t.usertype as user,"; |
|
277 | + $sql .= " t.tms"; |
|
278 | + $sql .= " FROM ".MAIN_DB_PREFIX."menu as t"; |
|
279 | + $sql .= " WHERE t.rowid = ".$id; |
|
280 | 280 | |
281 | 281 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
282 | - $resql=$this->db->query($sql); |
|
282 | + $resql = $this->db->query($sql); |
|
283 | 283 | if ($resql) |
284 | 284 | { |
285 | 285 | if ($this->db->num_rows($resql)) |
286 | 286 | { |
287 | 287 | $obj = $this->db->fetch_object($resql); |
288 | 288 | |
289 | - $this->id = $obj->rowid; |
|
289 | + $this->id = $obj->rowid; |
|
290 | 290 | |
291 | 291 | $this->menu_handler = $obj->menu_handler; |
292 | 292 | $this->entity = $obj->entity; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $this->titre = $obj->titre; |
304 | 304 | $this->langs = $obj->langs; |
305 | 305 | $this->perms = $obj->perms; |
306 | - $this->enabled = str_replace("\"","'",$obj->enabled); |
|
306 | + $this->enabled = str_replace("\"", "'", $obj->enabled); |
|
307 | 307 | $this->user = $obj->user; |
308 | 308 | $this->tms = $this->db->jdate($obj->tms); |
309 | 309 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | } |
314 | 314 | else |
315 | 315 | { |
316 | - $this->error="Error ".$this->db->lasterror(); |
|
316 | + $this->error = "Error ".$this->db->lasterror(); |
|
317 | 317 | return -1; |
318 | 318 | } |
319 | 319 | } |
@@ -330,13 +330,13 @@ discard block |
||
330 | 330 | global $conf, $langs; |
331 | 331 | |
332 | 332 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; |
333 | - $sql.= " WHERE rowid=".$this->id; |
|
333 | + $sql .= " WHERE rowid=".$this->id; |
|
334 | 334 | |
335 | 335 | dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
336 | 336 | $resql = $this->db->query($sql); |
337 | - if (! $resql) |
|
337 | + if (!$resql) |
|
338 | 338 | { |
339 | - $this->error="Error ".$this->db->lasterror(); |
|
339 | + $this->error = "Error ".$this->db->lasterror(); |
|
340 | 340 | return -1; |
341 | 341 | } |
342 | 342 | |
@@ -353,24 +353,24 @@ discard block |
||
353 | 353 | */ |
354 | 354 | function initAsSpecimen() |
355 | 355 | { |
356 | - $this->id=0; |
|
357 | - |
|
358 | - $this->menu_handler='all'; |
|
359 | - $this->module='specimen'; |
|
360 | - $this->type='top'; |
|
361 | - $this->mainmenu=''; |
|
362 | - $this->fk_menu='0'; |
|
363 | - $this->position=''; |
|
364 | - $this->url='http://dummy'; |
|
365 | - $this->target=''; |
|
366 | - $this->titre='Specimen menu'; |
|
367 | - $this->langs=''; |
|
368 | - $this->level=''; |
|
369 | - $this->leftmenu=''; |
|
370 | - $this->perms=''; |
|
371 | - $this->enabled=''; |
|
372 | - $this->user=''; |
|
373 | - $this->tms=''; |
|
356 | + $this->id = 0; |
|
357 | + |
|
358 | + $this->menu_handler = 'all'; |
|
359 | + $this->module = 'specimen'; |
|
360 | + $this->type = 'top'; |
|
361 | + $this->mainmenu = ''; |
|
362 | + $this->fk_menu = '0'; |
|
363 | + $this->position = ''; |
|
364 | + $this->url = 'http://dummy'; |
|
365 | + $this->target = ''; |
|
366 | + $this->titre = 'Specimen menu'; |
|
367 | + $this->langs = ''; |
|
368 | + $this->level = ''; |
|
369 | + $this->leftmenu = ''; |
|
370 | + $this->perms = ''; |
|
371 | + $this->enabled = ''; |
|
372 | + $this->user = ''; |
|
373 | + $this->tms = ''; |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | |
@@ -386,16 +386,16 @@ discard block |
||
386 | 386 | */ |
387 | 387 | function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
388 | 388 | { |
389 | - global $langs, $user, $conf; // To export to dol_eval function |
|
390 | - global $mainmenu,$leftmenu; // To export to dol_eval function |
|
389 | + global $langs, $user, $conf; // To export to dol_eval function |
|
390 | + global $mainmenu, $leftmenu; // To export to dol_eval function |
|
391 | 391 | |
392 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
393 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
392 | + $mainmenu = $mymainmenu; // To export to dol_eval function |
|
393 | + $leftmenu = $myleftmenu; // To export to dol_eval function |
|
394 | 394 | |
395 | - $newTabMenu=array(); |
|
396 | - foreach($tabMenu as $val) |
|
395 | + $newTabMenu = array(); |
|
396 | + foreach ($tabMenu as $val) |
|
397 | 397 | { |
398 | - if ($val['type']=='top') $newTabMenu[]=$val; |
|
398 | + if ($val['type'] == 'top') $newTabMenu[] = $val; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | return $newTabMenu; |
@@ -415,20 +415,20 @@ discard block |
||
415 | 415 | */ |
416 | 416 | function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) |
417 | 417 | { |
418 | - global $langs, $user, $conf; // To export to dol_eval function |
|
419 | - global $mainmenu,$leftmenu; // To export to dol_eval function |
|
418 | + global $langs, $user, $conf; // To export to dol_eval function |
|
419 | + global $mainmenu, $leftmenu; // To export to dol_eval function |
|
420 | 420 | |
421 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
422 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
421 | + $mainmenu = $mymainmenu; // To export to dol_eval function |
|
422 | + $leftmenu = $myleftmenu; // To export to dol_eval function |
|
423 | 423 | |
424 | 424 | // Detect what is top mainmenu id |
425 | - $menutopid=''; |
|
426 | - foreach($tabMenu as $key => $val) |
|
425 | + $menutopid = ''; |
|
426 | + foreach ($tabMenu as $key => $val) |
|
427 | 427 | { |
428 | 428 | // Define menutopid of mainmenu |
429 | 429 | if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) |
430 | 430 | { |
431 | - $menutopid=$val['rowid']; |
|
431 | + $menutopid = $val['rowid']; |
|
432 | 432 | break; |
433 | 433 | } |
434 | 434 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | $this->recur($tabMenu, $menutopid, 1); |
441 | 441 | |
442 | 442 | // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu) |
443 | - foreach($tabMenu as $key => $val) |
|
443 | + foreach ($tabMenu as $key => $val) |
|
444 | 444 | { |
445 | 445 | //var_dump($tabMenu); |
446 | 446 | if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) // We found a menu entry not linked to parent with good mainmenu |
@@ -456,16 +456,16 @@ discard block |
||
456 | 456 | else |
457 | 457 | { |
458 | 458 | // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu) |
459 | - $searchlastsub=0;$lastid=0;$nextid=0;$found=0; |
|
460 | - foreach($this->newmenu->liste as $keyparent => $valparent) |
|
459 | + $searchlastsub = 0; $lastid = 0; $nextid = 0; $found = 0; |
|
460 | + foreach ($this->newmenu->liste as $keyparent => $valparent) |
|
461 | 461 | { |
462 | 462 | //var_dump($valparent); |
463 | 463 | if ($searchlastsub) // If we started to search for last submenu |
464 | 464 | { |
465 | - if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent; |
|
465 | + if ($valparent['level'] >= $searchlastsub) $lastid = $keyparent; |
|
466 | 466 | if ($valparent['level'] < $searchlastsub) |
467 | 467 | { |
468 | - $nextid=$keyparent; |
|
468 | + $nextid = $keyparent; |
|
469 | 469 | break; |
470 | 470 | } |
471 | 471 | } |
@@ -473,9 +473,9 @@ discard block |
||
473 | 473 | { |
474 | 474 | //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>'; |
475 | 475 | // Now we look to find last subelement of this parent (we add at end) |
476 | - $searchlastsub=($valparent['level']+1); |
|
477 | - $lastid=$keyparent; |
|
478 | - $found=1; |
|
476 | + $searchlastsub = ($valparent['level'] + 1); |
|
477 | + $lastid = $keyparent; |
|
478 | + $found = 1; |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>'; |
@@ -507,17 +507,17 @@ discard block |
||
507 | 507 | global $langs, $user, $conf; // To export to dol_eval function |
508 | 508 | global $mainmenu, $leftmenu; // To export to dol_eval function |
509 | 509 | |
510 | - $menutopid=0; |
|
511 | - $mainmenu=$mymainmenu; // To export to dol_eval function |
|
512 | - $leftmenu=$myleftmenu; // To export to dol_eval function |
|
510 | + $menutopid = 0; |
|
511 | + $mainmenu = $mymainmenu; // To export to dol_eval function |
|
512 | + $leftmenu = $myleftmenu; // To export to dol_eval function |
|
513 | 513 | |
514 | 514 | $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position"; |
515 | - $sql.= " FROM ".MAIN_DB_PREFIX."menu as m"; |
|
516 | - $sql.= " WHERE m.entity IN (0,".$conf->entity.")"; |
|
517 | - $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')"; |
|
518 | - if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)"; |
|
519 | - if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)"; |
|
520 | - $sql.= " ORDER BY m.position, m.rowid"; |
|
515 | + $sql .= " FROM ".MAIN_DB_PREFIX."menu as m"; |
|
516 | + $sql .= " WHERE m.entity IN (0,".$conf->entity.")"; |
|
517 | + $sql .= " AND m.menu_handler IN ('".$menu_handler."','all')"; |
|
518 | + if ($type_user == 0) $sql .= " AND m.usertype IN (0,2)"; |
|
519 | + if ($type_user == 1) $sql .= " AND m.usertype IN (1,2)"; |
|
520 | + $sql .= " ORDER BY m.position, m.rowid"; |
|
521 | 521 | //print $sql; |
522 | 522 | |
523 | 523 | //$tmp1=microtime(true); |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | |
531 | 531 | $a = 0; |
532 | 532 | $b = 0; |
533 | - $oldrowid=0; |
|
533 | + $oldrowid = 0; |
|
534 | 534 | while ($a < $numa) |
535 | 535 | { |
536 | 536 | //$objm = $this->db->fetch_object($resql); |
@@ -540,8 +540,8 @@ discard block |
||
540 | 540 | $perms = true; |
541 | 541 | if ($menu['perms']) |
542 | 542 | { |
543 | - $tmpcond=$menu['perms']; |
|
544 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
543 | + $tmpcond = $menu['perms']; |
|
544 | + if ($leftmenu == 'all') $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true |
|
545 | 545 | $perms = verifCond($tmpcond); |
546 | 546 | //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n"; |
547 | 547 | } |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | $enabled = true; |
551 | 551 | if ($menu['enabled']) |
552 | 552 | { |
553 | - $tmpcond=$menu['enabled']; |
|
554 | - if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond); // Force part of condition to true |
|
553 | + $tmpcond = $menu['enabled']; |
|
554 | + if ($leftmenu == 'all') $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true |
|
555 | 555 | $enabled = verifCond($tmpcond); |
556 | 556 | } |
557 | 557 | |
@@ -561,21 +561,21 @@ discard block |
||
561 | 561 | $title = $langs->trans($menu['titre']); |
562 | 562 | if ($title == $menu['titre']) // Translation not found |
563 | 563 | { |
564 | - if (! empty($menu['langs'])) // If there is a dedicated translation file |
|
564 | + if (!empty($menu['langs'])) // If there is a dedicated translation file |
|
565 | 565 | { |
566 | 566 | //print 'Load file '.$menu['langs'].'<br>'; |
567 | 567 | $langs->load($menu['langs']); |
568 | 568 | } |
569 | 569 | |
570 | - if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 |
|
570 | + if (preg_match("/\//", $menu['titre'])) // To manage translation when title is string1/string2 |
|
571 | 571 | { |
572 | - $tab_titre = explode("/",$menu['titre']); |
|
572 | + $tab_titre = explode("/", $menu['titre']); |
|
573 | 573 | $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]); |
574 | 574 | } |
575 | - else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
575 | + else if (preg_match('/\|\|/', $menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle) |
|
576 | 576 | { |
577 | - $tab_title = explode("||",$menu['titre']); |
|
578 | - $alt_title = explode("@",$tab_title[1]); |
|
577 | + $tab_title = explode("||", $menu['titre']); |
|
578 | + $alt_title = explode("@", $tab_title[1]); |
|
579 | 579 | $title_enabled = verifCond($alt_title[1]); |
580 | 580 | $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0])); |
581 | 581 | } |
@@ -592,10 +592,10 @@ discard block |
||
592 | 592 | $tabMenu[$b]['module'] = $menu['module']; |
593 | 593 | $tabMenu[$b]['fk_menu'] = $menu['fk_menu']; |
594 | 594 | $tabMenu[$b]['url'] = $menu['url']; |
595 | - if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url'])) |
|
595 | + if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) |
|
596 | 596 | { |
597 | - if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&idmenu='.$menu['rowid']; |
|
598 | - else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid']; |
|
597 | + if (preg_match('/\?/', $tabMenu[$b]['url'])) $tabMenu[$b]['url'] .= '&idmenu='.$menu['rowid']; |
|
598 | + else $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid']; |
|
599 | 599 | } |
600 | 600 | $tabMenu[$b]['titre'] = $title; |
601 | 601 | $tabMenu[$b]['target'] = $menu['target']; |
@@ -644,10 +644,10 @@ discard block |
||
644 | 644 | for ($x = 0; $x < $num; $x++) |
645 | 645 | { |
646 | 646 | //si un element a pour pere : $pere |
647 | - if ( (($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) |
|
647 | + if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled']) |
|
648 | 648 | { |
649 | - $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level-1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']); |
|
650 | - $this->recur($tab, $tab[$x]['rowid'], ($level+1)); |
|
649 | + $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level - 1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']); |
|
650 | + $this->recur($tab, $tab[$x]['rowid'], ($level + 1)); |
|
651 | 651 | } |
652 | 652 | } |
653 | 653 | } |
@@ -84,8 +84,12 @@ discard block |
||
84 | 84 | $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; |
85 | 85 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; |
86 | 86 | $sql.= " WHERE sr.entity = " . $conf->entity; |
87 | - if ($rowid) $sql.= " AND sr.rowid=".$rowid; |
|
88 | - if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; |
|
87 | + if ($rowid) { |
|
88 | + $sql.= " AND sr.rowid=".$rowid; |
|
89 | + } |
|
90 | + if ($fk_facture_source) { |
|
91 | + $sql.= " AND sr.fk_facture_source=".$fk_facture_source; |
|
92 | + } |
|
89 | 93 | |
90 | 94 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
91 | 95 | $resql = $this->db->query($sql); |
@@ -111,14 +115,12 @@ discard block |
||
111 | 115 | |
112 | 116 | $this->db->free($resql); |
113 | 117 | return 1; |
114 | - } |
|
115 | - else |
|
118 | + } else |
|
116 | 119 | { |
117 | 120 | $this->db->free($resql); |
118 | 121 | return 0; |
119 | 122 | } |
120 | - } |
|
121 | - else |
|
123 | + } else |
|
122 | 124 | { |
123 | 125 | $this->error=$this->db->error(); |
124 | 126 | return -1; |
@@ -167,8 +169,7 @@ discard block |
||
167 | 169 | { |
168 | 170 | $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); |
169 | 171 | return $this->id; |
170 | - } |
|
171 | - else |
|
172 | + } else |
|
172 | 173 | { |
173 | 174 | $this->error=$this->db->lasterror().' - sql='.$sql; |
174 | 175 | return -1; |
@@ -206,8 +207,7 @@ discard block |
||
206 | 207 | $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved'; |
207 | 208 | return -2; |
208 | 209 | } |
209 | - } |
|
210 | - else |
|
210 | + } else |
|
211 | 211 | { |
212 | 212 | dol_print_error($this->db); |
213 | 213 | return -1; |
@@ -218,8 +218,14 @@ discard block |
||
218 | 218 | |
219 | 219 | // Delete but only if not used |
220 | 220 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; |
221 | - if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie |
|
222 | - else $sql.= " WHERE rowid = ".$this->id; // Delete only line |
|
221 | + if ($this->fk_facture_source) { |
|
222 | + $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; |
|
223 | + } |
|
224 | + // Delete all lines of same serie |
|
225 | + else { |
|
226 | + $sql.= " WHERE rowid = ".$this->id; |
|
227 | + } |
|
228 | + // Delete only line |
|
223 | 229 | $sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount |
224 | 230 | $sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit |
225 | 231 | |
@@ -240,21 +246,18 @@ discard block |
||
240 | 246 | { |
241 | 247 | $this->db->commit(); |
242 | 248 | return 1; |
243 | - } |
|
244 | - else |
|
249 | + } else |
|
245 | 250 | { |
246 | 251 | $this->error=$this->db->lasterror(); |
247 | 252 | $this->db->rollback(); |
248 | 253 | return -1; |
249 | 254 | } |
250 | - } |
|
251 | - else |
|
255 | + } else |
|
252 | 256 | { |
253 | 257 | $this->db->commit(); |
254 | 258 | return 1; |
255 | 259 | } |
256 | - } |
|
257 | - else |
|
260 | + } else |
|
258 | 261 | { |
259 | 262 | $this->error=$this->db->lasterror(); |
260 | 263 | $this->db->rollback(); |
@@ -288,8 +291,12 @@ discard block |
||
288 | 291 | } |
289 | 292 | |
290 | 293 | $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
291 | - if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline; |
|
292 | - if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice; |
|
294 | + if ($rowidline) { |
|
295 | + $sql.=" SET fk_facture_line = ".$rowidline; |
|
296 | + } |
|
297 | + if ($rowidinvoice) { |
|
298 | + $sql.=" SET fk_facture = ".$rowidinvoice; |
|
299 | + } |
|
293 | 300 | $sql.=" WHERE rowid = ".$this->id; |
294 | 301 | |
295 | 302 | dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG); |
@@ -299,8 +306,7 @@ discard block |
||
299 | 306 | $this->fk_facture_line=$rowidline; |
300 | 307 | $this->fk_facture=$rowidinvoice; |
301 | 308 | return 1; |
302 | - } |
|
303 | - else |
|
309 | + } else |
|
304 | 310 | { |
305 | 311 | $this->error=$this->db->error(); |
306 | 312 | return -3; |
@@ -325,8 +331,7 @@ discard block |
||
325 | 331 | if ($resql) |
326 | 332 | { |
327 | 333 | return 1; |
328 | - } |
|
329 | - else |
|
334 | + } else |
|
330 | 335 | { |
331 | 336 | $this->error=$this->db->error(); |
332 | 337 | return -3; |
@@ -352,12 +357,26 @@ discard block |
||
352 | 357 | //$sql = "SELECT rc.amount_ttc as amount"; |
353 | 358 | $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; |
354 | 359 | $sql.= " WHERE rc.entity = " . $conf->entity; |
355 | - if ($mode != 'supplier') $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available |
|
356 | - else $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available |
|
357 | - if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; |
|
358 | - if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; |
|
359 | - if ($filter) $sql.=' AND ('.$filter.')'; |
|
360 | - if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
360 | + if ($mode != 'supplier') { |
|
361 | + $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; |
|
362 | + } |
|
363 | + // Available |
|
364 | + else { |
|
365 | + $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; |
|
366 | + } |
|
367 | + // Available |
|
368 | + if (is_object($company)) { |
|
369 | + $sql.= " AND rc.fk_soc = ".$company->id; |
|
370 | + } |
|
371 | + if (is_object($user)) { |
|
372 | + $sql.= " AND rc.fk_user = ".$user->id; |
|
373 | + } |
|
374 | + if ($filter) { |
|
375 | + $sql.=' AND ('.$filter.')'; |
|
376 | + } |
|
377 | + if ($maxvalue) { |
|
378 | + $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
379 | + } |
|
361 | 380 | |
362 | 381 | dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG); |
363 | 382 | $resql=$this->db->query($sql); |
@@ -393,15 +412,13 @@ discard block |
||
393 | 412 | $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
394 | 413 | $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
395 | 414 | $sql.= ' AND f.type = 3'; |
396 | - } |
|
397 | - else if ($invoice->element == 'invoice_supplier') |
|
415 | + } else if ($invoice->element == 'invoice_supplier') |
|
398 | 416 | { |
399 | 417 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
400 | 418 | $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
401 | 419 | $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
402 | 420 | $sql.= ' AND f.type = 3'; |
403 | - } |
|
404 | - else |
|
421 | + } else |
|
405 | 422 | { |
406 | 423 | $this->error=get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; |
407 | 424 | dol_print_error($this->error); |
@@ -412,10 +429,12 @@ discard block |
||
412 | 429 | if ($resql) |
413 | 430 | { |
414 | 431 | $obj = $this->db->fetch_object($resql); |
415 | - if ($multicurrency) return $obj->multicurrency_amount; |
|
416 | - else return $obj->amount; |
|
417 | - } |
|
418 | - else |
|
432 | + if ($multicurrency) { |
|
433 | + return $obj->multicurrency_amount; |
|
434 | + } else { |
|
435 | + return $obj->amount; |
|
436 | + } |
|
437 | + } else |
|
419 | 438 | { |
420 | 439 | $this->error = $this->db->lasterror(); |
421 | 440 | return -1; |
@@ -439,15 +458,13 @@ discard block |
||
439 | 458 | $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
440 | 459 | $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
441 | 460 | $sql.= ' AND f.type = 2'; |
442 | - } |
|
443 | - else if ($invoice->element == 'invoice_supplier') |
|
461 | + } else if ($invoice->element == 'invoice_supplier') |
|
444 | 462 | { |
445 | 463 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
446 | 464 | $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
447 | 465 | $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
448 | 466 | $sql.= ' AND f.type = 2'; |
449 | - } |
|
450 | - else |
|
467 | + } else |
|
451 | 468 | { |
452 | 469 | $this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; |
453 | 470 | dol_print_error($this->error); |
@@ -458,10 +475,12 @@ discard block |
||
458 | 475 | if ($resql) |
459 | 476 | { |
460 | 477 | $obj = $this->db->fetch_object($resql); |
461 | - if ($multicurrency) return $obj->multicurrency_amount; |
|
462 | - else return $obj->amount; |
|
463 | - } |
|
464 | - else |
|
478 | + if ($multicurrency) { |
|
479 | + return $obj->multicurrency_amount; |
|
480 | + } else { |
|
481 | + return $obj->amount; |
|
482 | + } |
|
483 | + } else |
|
465 | 484 | { |
466 | 485 | $this->error = $this->db->lasterror(); |
467 | 486 | return -1; |
@@ -497,8 +516,12 @@ discard block |
||
497 | 516 | } |
498 | 517 | |
499 | 518 | |
500 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
501 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
519 | + if ($withpicto) { |
|
520 | + $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
521 | + } |
|
522 | + if ($withpicto && $withpicto != 2) { |
|
523 | + $result.=' '; |
|
524 | + } |
|
502 | 525 | $result.=$link.$ref.$linkend; |
503 | 526 | return $result; |
504 | 527 | } |
@@ -29,494 +29,494 @@ |
||
29 | 29 | */ |
30 | 30 | class DiscountAbsolute |
31 | 31 | { |
32 | - public $db; |
|
33 | - public $error; |
|
34 | - |
|
35 | - public $id; // Id discount |
|
36 | - public $fk_soc; |
|
37 | - public $amount_ht; // |
|
38 | - public $amount_tva; // |
|
39 | - public $amount_ttc; // |
|
40 | - public $tva_tx; // Vat rate |
|
41 | - public $fk_user; // Id utilisateur qui accorde la remise |
|
42 | - public $description; // Description libre |
|
43 | - public $datec; // Date creation |
|
44 | - public $fk_facture_line; // Id invoice line when a discount is used into an invoice line (for absolute discounts) |
|
45 | - public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note) |
|
46 | - public $fk_facture_source; // Id facture avoir a l'origine de la remise |
|
47 | - public $ref_facture_source; // Ref facture avoir a l'origine de la remise |
|
48 | - |
|
49 | - /** |
|
50 | - * Constructor |
|
51 | - * |
|
52 | - * @param DoliDB $db Database handler |
|
53 | - */ |
|
54 | - function __construct($db) |
|
55 | - { |
|
56 | - $this->db = $db; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Load object from database into memory |
|
62 | - * |
|
63 | - * @param int $rowid id discount to load |
|
64 | - * @param int $fk_facture_source fk_facture_source |
|
65 | - * @return int <0 if KO, =0 if not found, >0 if OK |
|
66 | - */ |
|
67 | - function fetch($rowid, $fk_facture_source=0) |
|
68 | - { |
|
69 | - global $conf; |
|
70 | - |
|
71 | - // Check parameters |
|
72 | - if (! $rowid && ! $fk_facture_source) |
|
73 | - { |
|
74 | - $this->error='ErrorBadParameters'; |
|
75 | - return -1; |
|
76 | - } |
|
77 | - |
|
78 | - $sql = "SELECT sr.rowid, sr.fk_soc,"; |
|
79 | - $sql.= " sr.fk_user,"; |
|
80 | - $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; |
|
81 | - $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; |
|
82 | - $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,"; |
|
83 | - $sql.= " sr.datec,"; |
|
84 | - $sql.= " f.facnumber as ref_facture_source"; |
|
85 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; |
|
86 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; |
|
87 | - $sql.= " WHERE sr.entity = " . $conf->entity; |
|
88 | - if ($rowid) $sql.= " AND sr.rowid=".$rowid; |
|
89 | - if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; |
|
90 | - |
|
91 | - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
92 | - $resql = $this->db->query($sql); |
|
93 | - if ($resql) |
|
94 | - { |
|
95 | - if ($this->db->num_rows($resql)) |
|
96 | - { |
|
97 | - $obj = $this->db->fetch_object($resql); |
|
98 | - |
|
99 | - $this->id = $obj->rowid; |
|
100 | - $this->fk_soc = $obj->fk_soc; |
|
101 | - |
|
102 | - $this->amount_ht = $obj->amount_ht; |
|
103 | - $this->amount_tva = $obj->amount_tva; |
|
104 | - $this->amount_ttc = $obj->amount_ttc; |
|
105 | - |
|
106 | - $this->multicurrency_amount_ht = $obj->multicurrency_amount_ht; |
|
107 | - $this->multicurrency_amount_tva = $obj->multicurrency_amount_tva; |
|
108 | - $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc; |
|
109 | - |
|
110 | - $this->tva_tx = $obj->tva_tx; |
|
111 | - $this->fk_user = $obj->fk_user; |
|
112 | - $this->fk_facture_line = $obj->fk_facture_line; |
|
113 | - $this->fk_facture = $obj->fk_facture; |
|
114 | - $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source |
|
115 | - $this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source |
|
116 | - $this->description = $obj->description; |
|
117 | - $this->datec = $this->db->jdate($obj->datec); |
|
118 | - |
|
119 | - $this->db->free($resql); |
|
120 | - return 1; |
|
121 | - } |
|
122 | - else |
|
123 | - { |
|
124 | - $this->db->free($resql); |
|
125 | - return 0; |
|
126 | - } |
|
127 | - } |
|
128 | - else |
|
129 | - { |
|
130 | - $this->error=$this->db->error(); |
|
131 | - return -1; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * Create a discount into database |
|
138 | - * |
|
139 | - * @param User $user User that create |
|
140 | - * @return int <0 if KO, >0 if OK |
|
141 | - */ |
|
142 | - function create($user) |
|
143 | - { |
|
144 | - global $conf, $langs; |
|
145 | - |
|
146 | - // Clean parameters |
|
147 | - $this->amount_ht=price2num($this->amount_ht); |
|
148 | - $this->amount_tva=price2num($this->amount_tva); |
|
149 | - $this->amount_ttc=price2num($this->amount_ttc); |
|
150 | - $this->tva_tx=price2num($this->tva_tx); |
|
151 | - |
|
152 | - // Check parameters |
|
153 | - if (empty($this->description)) |
|
154 | - { |
|
155 | - $this->error='BadValueForPropertyDescription'; |
|
156 | - dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); |
|
157 | - return -1; |
|
158 | - } |
|
159 | - |
|
160 | - // Insert request |
|
161 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; |
|
162 | - $sql.= " (entity, datec, fk_soc, fk_user, description,"; |
|
163 | - $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; |
|
164 | - $sql.= " fk_facture_source"; |
|
165 | - $sql.= ")"; |
|
166 | - $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; |
|
167 | - $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; |
|
168 | - $sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null"); |
|
169 | - $sql.= ")"; |
|
170 | - |
|
171 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
172 | - $resql=$this->db->query($sql); |
|
173 | - if ($resql) |
|
174 | - { |
|
175 | - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); |
|
176 | - return $this->id; |
|
177 | - } |
|
178 | - else |
|
179 | - { |
|
180 | - $this->error=$this->db->lasterror().' - sql='.$sql; |
|
181 | - return -1; |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Delete object in database. If fk_facture_source is defined, we delete all familiy with same fk_facture_source. If not, only with id is removed |
|
188 | - * |
|
189 | - * @param User $user Object of user asking to delete |
|
190 | - * @return int <0 if KO, >0 if OK |
|
191 | - */ |
|
192 | - function delete($user) |
|
193 | - { |
|
194 | - global $conf, $langs; |
|
195 | - |
|
196 | - // Check if we can remove the discount |
|
197 | - if ($this->fk_facture_source) |
|
198 | - { |
|
199 | - $sql="SELECT COUNT(rowid) as nb"; |
|
200 | - $sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except"; |
|
201 | - $sql.=" WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount |
|
202 | - $sql.=" OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit |
|
203 | - $sql.=" AND fk_facture_source = ".$this->fk_facture_source; |
|
204 | - //$sql.=" AND rowid != ".$this->id; |
|
205 | - |
|
206 | - dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG); |
|
207 | - $resql=$this->db->query($sql); |
|
208 | - if ($resql) |
|
209 | - { |
|
210 | - $obj = $this->db->fetch_object($resql); |
|
211 | - if ($obj->nb > 0) |
|
212 | - { |
|
213 | - $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved'; |
|
214 | - return -2; |
|
215 | - } |
|
216 | - } |
|
217 | - else |
|
218 | - { |
|
219 | - dol_print_error($this->db); |
|
220 | - return -1; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - $this->db->begin(); |
|
225 | - |
|
226 | - // Delete but only if not used |
|
227 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; |
|
228 | - if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie |
|
229 | - else $sql.= " WHERE rowid = ".$this->id; // Delete only line |
|
230 | - $sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount |
|
231 | - $sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit |
|
232 | - |
|
233 | - dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG); |
|
234 | - $result=$this->db->query($sql); |
|
235 | - if ($result) |
|
236 | - { |
|
237 | - // If source of discount was a credit note or deposit, we change source statut. |
|
238 | - if ($this->fk_facture_source) |
|
239 | - { |
|
240 | - $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; |
|
241 | - $sql.=" set paye=0, fk_statut=1"; |
|
242 | - $sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source; |
|
243 | - |
|
244 | - dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG); |
|
245 | - $result=$this->db->query($sql); |
|
246 | - if ($result) |
|
247 | - { |
|
248 | - $this->db->commit(); |
|
249 | - return 1; |
|
250 | - } |
|
251 | - else |
|
252 | - { |
|
253 | - $this->error=$this->db->lasterror(); |
|
254 | - $this->db->rollback(); |
|
255 | - return -1; |
|
256 | - } |
|
257 | - } |
|
258 | - else |
|
259 | - { |
|
260 | - $this->db->commit(); |
|
261 | - return 1; |
|
262 | - } |
|
263 | - } |
|
264 | - else |
|
265 | - { |
|
266 | - $this->error=$this->db->lasterror(); |
|
267 | - $this->db->rollback(); |
|
268 | - return -1; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Link the discount to a particular invoice line or a particular invoice. |
|
276 | - * When discount is a global discount used as an invoice line, we link using rowidline. |
|
277 | - * When discount is from a credit note used to reduce payment of an invoice, we link using rowidinvoice |
|
278 | - * |
|
279 | - * @param int $rowidline Invoice line id (To use discount into invoice lines) |
|
280 | - * @param int $rowidinvoice Invoice id (To use discount as a credit note to reduc payment of invoice) |
|
281 | - * @return int <0 if KO, >0 if OK |
|
282 | - */ |
|
283 | - function link_to_invoice($rowidline,$rowidinvoice) |
|
284 | - { |
|
285 | - // Check parameters |
|
286 | - if (! $rowidline && ! $rowidinvoice) |
|
287 | - { |
|
288 | - $this->error='ErrorBadParameters'; |
|
289 | - return -1; |
|
290 | - } |
|
291 | - if ($rowidline && $rowidinvoice) |
|
292 | - { |
|
293 | - $this->error='ErrorBadParameters'; |
|
294 | - return -2; |
|
295 | - } |
|
296 | - |
|
297 | - $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
298 | - if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline; |
|
299 | - if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice; |
|
300 | - $sql.=" WHERE rowid = ".$this->id; |
|
301 | - |
|
302 | - dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG); |
|
303 | - $resql = $this->db->query($sql); |
|
304 | - if ($resql) |
|
305 | - { |
|
306 | - $this->fk_facture_line=$rowidline; |
|
307 | - $this->fk_facture=$rowidinvoice; |
|
308 | - return 1; |
|
309 | - } |
|
310 | - else |
|
311 | - { |
|
312 | - $this->error=$this->db->error(); |
|
313 | - return -3; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Link the discount to a particular invoice line or a particular invoice. |
|
320 | - * Do not call this if discount is linked to a reconcialiated invoice |
|
321 | - * |
|
322 | - * @return int <0 if KO, >0 if OK |
|
323 | - */ |
|
324 | - function unlink_invoice() |
|
325 | - { |
|
326 | - $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
327 | - $sql.=" SET fk_facture_line = NULL, fk_facture = NULL"; |
|
328 | - $sql.=" WHERE rowid = ".$this->id; |
|
329 | - |
|
330 | - dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG); |
|
331 | - $resql = $this->db->query($sql); |
|
332 | - if ($resql) |
|
333 | - { |
|
334 | - return 1; |
|
335 | - } |
|
336 | - else |
|
337 | - { |
|
338 | - $this->error=$this->db->error(); |
|
339 | - return -3; |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Return amount (with tax) of discounts currently available for a company, user or other criteria |
|
346 | - * |
|
347 | - * @param Societe $company Object third party for filter |
|
348 | - * @param User $user Filtre sur un user auteur des remises |
|
349 | - * @param string $filter Filtre autre |
|
350 | - * @param int $maxvalue Filter on max value for discount |
|
351 | - * @param string $mode 'customer' = discounts the customer has, 'supplier' = discount i have at this supplier |
|
352 | - * @return int <0 if KO, amount otherwise |
|
353 | - */ |
|
354 | - function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $mode='customer') |
|
355 | - { |
|
356 | - global $conf; |
|
357 | - |
|
358 | - $sql = "SELECT SUM(rc.amount_ttc) as amount"; |
|
359 | - //$sql = "SELECT rc.amount_ttc as amount"; |
|
360 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; |
|
361 | - $sql.= " WHERE rc.entity = " . $conf->entity; |
|
362 | - if ($mode != 'supplier') $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available |
|
363 | - else $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available |
|
364 | - if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; |
|
365 | - if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; |
|
366 | - if ($filter) $sql.=' AND ('.$filter.')'; |
|
367 | - if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
368 | - |
|
369 | - dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG); |
|
370 | - $resql=$this->db->query($sql); |
|
371 | - if ($resql) |
|
372 | - { |
|
373 | - $obj = $this->db->fetch_object($resql); |
|
374 | - //while ($obj) |
|
375 | - //{ |
|
376 | - //print 'zz'.$obj->amount; |
|
377 | - //$obj = $this->db->fetch_object($resql); |
|
378 | - //} |
|
379 | - return $obj->amount; |
|
380 | - } |
|
381 | - return -1; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Return amount (with tax) of all deposits invoices used by invoice as a payment. |
|
387 | - * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended). |
|
388 | - * |
|
389 | - * @param CommonInvoice $invoice Object invoice (customer of supplier) |
|
32 | + public $db; |
|
33 | + public $error; |
|
34 | + |
|
35 | + public $id; // Id discount |
|
36 | + public $fk_soc; |
|
37 | + public $amount_ht; // |
|
38 | + public $amount_tva; // |
|
39 | + public $amount_ttc; // |
|
40 | + public $tva_tx; // Vat rate |
|
41 | + public $fk_user; // Id utilisateur qui accorde la remise |
|
42 | + public $description; // Description libre |
|
43 | + public $datec; // Date creation |
|
44 | + public $fk_facture_line; // Id invoice line when a discount is used into an invoice line (for absolute discounts) |
|
45 | + public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note) |
|
46 | + public $fk_facture_source; // Id facture avoir a l'origine de la remise |
|
47 | + public $ref_facture_source; // Ref facture avoir a l'origine de la remise |
|
48 | + |
|
49 | + /** |
|
50 | + * Constructor |
|
51 | + * |
|
52 | + * @param DoliDB $db Database handler |
|
53 | + */ |
|
54 | + function __construct($db) |
|
55 | + { |
|
56 | + $this->db = $db; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Load object from database into memory |
|
62 | + * |
|
63 | + * @param int $rowid id discount to load |
|
64 | + * @param int $fk_facture_source fk_facture_source |
|
65 | + * @return int <0 if KO, =0 if not found, >0 if OK |
|
66 | + */ |
|
67 | + function fetch($rowid, $fk_facture_source=0) |
|
68 | + { |
|
69 | + global $conf; |
|
70 | + |
|
71 | + // Check parameters |
|
72 | + if (! $rowid && ! $fk_facture_source) |
|
73 | + { |
|
74 | + $this->error='ErrorBadParameters'; |
|
75 | + return -1; |
|
76 | + } |
|
77 | + |
|
78 | + $sql = "SELECT sr.rowid, sr.fk_soc,"; |
|
79 | + $sql.= " sr.fk_user,"; |
|
80 | + $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; |
|
81 | + $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; |
|
82 | + $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,"; |
|
83 | + $sql.= " sr.datec,"; |
|
84 | + $sql.= " f.facnumber as ref_facture_source"; |
|
85 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; |
|
86 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; |
|
87 | + $sql.= " WHERE sr.entity = " . $conf->entity; |
|
88 | + if ($rowid) $sql.= " AND sr.rowid=".$rowid; |
|
89 | + if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; |
|
90 | + |
|
91 | + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
92 | + $resql = $this->db->query($sql); |
|
93 | + if ($resql) |
|
94 | + { |
|
95 | + if ($this->db->num_rows($resql)) |
|
96 | + { |
|
97 | + $obj = $this->db->fetch_object($resql); |
|
98 | + |
|
99 | + $this->id = $obj->rowid; |
|
100 | + $this->fk_soc = $obj->fk_soc; |
|
101 | + |
|
102 | + $this->amount_ht = $obj->amount_ht; |
|
103 | + $this->amount_tva = $obj->amount_tva; |
|
104 | + $this->amount_ttc = $obj->amount_ttc; |
|
105 | + |
|
106 | + $this->multicurrency_amount_ht = $obj->multicurrency_amount_ht; |
|
107 | + $this->multicurrency_amount_tva = $obj->multicurrency_amount_tva; |
|
108 | + $this->multicurrency_amount_ttc = $obj->multicurrency_amount_ttc; |
|
109 | + |
|
110 | + $this->tva_tx = $obj->tva_tx; |
|
111 | + $this->fk_user = $obj->fk_user; |
|
112 | + $this->fk_facture_line = $obj->fk_facture_line; |
|
113 | + $this->fk_facture = $obj->fk_facture; |
|
114 | + $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source |
|
115 | + $this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source |
|
116 | + $this->description = $obj->description; |
|
117 | + $this->datec = $this->db->jdate($obj->datec); |
|
118 | + |
|
119 | + $this->db->free($resql); |
|
120 | + return 1; |
|
121 | + } |
|
122 | + else |
|
123 | + { |
|
124 | + $this->db->free($resql); |
|
125 | + return 0; |
|
126 | + } |
|
127 | + } |
|
128 | + else |
|
129 | + { |
|
130 | + $this->error=$this->db->error(); |
|
131 | + return -1; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * Create a discount into database |
|
138 | + * |
|
139 | + * @param User $user User that create |
|
140 | + * @return int <0 if KO, >0 if OK |
|
141 | + */ |
|
142 | + function create($user) |
|
143 | + { |
|
144 | + global $conf, $langs; |
|
145 | + |
|
146 | + // Clean parameters |
|
147 | + $this->amount_ht=price2num($this->amount_ht); |
|
148 | + $this->amount_tva=price2num($this->amount_tva); |
|
149 | + $this->amount_ttc=price2num($this->amount_ttc); |
|
150 | + $this->tva_tx=price2num($this->tva_tx); |
|
151 | + |
|
152 | + // Check parameters |
|
153 | + if (empty($this->description)) |
|
154 | + { |
|
155 | + $this->error='BadValueForPropertyDescription'; |
|
156 | + dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); |
|
157 | + return -1; |
|
158 | + } |
|
159 | + |
|
160 | + // Insert request |
|
161 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; |
|
162 | + $sql.= " (entity, datec, fk_soc, fk_user, description,"; |
|
163 | + $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; |
|
164 | + $sql.= " fk_facture_source"; |
|
165 | + $sql.= ")"; |
|
166 | + $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; |
|
167 | + $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; |
|
168 | + $sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null"); |
|
169 | + $sql.= ")"; |
|
170 | + |
|
171 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
172 | + $resql=$this->db->query($sql); |
|
173 | + if ($resql) |
|
174 | + { |
|
175 | + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); |
|
176 | + return $this->id; |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
180 | + $this->error=$this->db->lasterror().' - sql='.$sql; |
|
181 | + return -1; |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Delete object in database. If fk_facture_source is defined, we delete all familiy with same fk_facture_source. If not, only with id is removed |
|
188 | + * |
|
189 | + * @param User $user Object of user asking to delete |
|
190 | + * @return int <0 if KO, >0 if OK |
|
191 | + */ |
|
192 | + function delete($user) |
|
193 | + { |
|
194 | + global $conf, $langs; |
|
195 | + |
|
196 | + // Check if we can remove the discount |
|
197 | + if ($this->fk_facture_source) |
|
198 | + { |
|
199 | + $sql="SELECT COUNT(rowid) as nb"; |
|
200 | + $sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except"; |
|
201 | + $sql.=" WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount |
|
202 | + $sql.=" OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit |
|
203 | + $sql.=" AND fk_facture_source = ".$this->fk_facture_source; |
|
204 | + //$sql.=" AND rowid != ".$this->id; |
|
205 | + |
|
206 | + dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG); |
|
207 | + $resql=$this->db->query($sql); |
|
208 | + if ($resql) |
|
209 | + { |
|
210 | + $obj = $this->db->fetch_object($resql); |
|
211 | + if ($obj->nb > 0) |
|
212 | + { |
|
213 | + $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved'; |
|
214 | + return -2; |
|
215 | + } |
|
216 | + } |
|
217 | + else |
|
218 | + { |
|
219 | + dol_print_error($this->db); |
|
220 | + return -1; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + $this->db->begin(); |
|
225 | + |
|
226 | + // Delete but only if not used |
|
227 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; |
|
228 | + if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie |
|
229 | + else $sql.= " WHERE rowid = ".$this->id; // Delete only line |
|
230 | + $sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount |
|
231 | + $sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit |
|
232 | + |
|
233 | + dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG); |
|
234 | + $result=$this->db->query($sql); |
|
235 | + if ($result) |
|
236 | + { |
|
237 | + // If source of discount was a credit note or deposit, we change source statut. |
|
238 | + if ($this->fk_facture_source) |
|
239 | + { |
|
240 | + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; |
|
241 | + $sql.=" set paye=0, fk_statut=1"; |
|
242 | + $sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source; |
|
243 | + |
|
244 | + dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG); |
|
245 | + $result=$this->db->query($sql); |
|
246 | + if ($result) |
|
247 | + { |
|
248 | + $this->db->commit(); |
|
249 | + return 1; |
|
250 | + } |
|
251 | + else |
|
252 | + { |
|
253 | + $this->error=$this->db->lasterror(); |
|
254 | + $this->db->rollback(); |
|
255 | + return -1; |
|
256 | + } |
|
257 | + } |
|
258 | + else |
|
259 | + { |
|
260 | + $this->db->commit(); |
|
261 | + return 1; |
|
262 | + } |
|
263 | + } |
|
264 | + else |
|
265 | + { |
|
266 | + $this->error=$this->db->lasterror(); |
|
267 | + $this->db->rollback(); |
|
268 | + return -1; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Link the discount to a particular invoice line or a particular invoice. |
|
276 | + * When discount is a global discount used as an invoice line, we link using rowidline. |
|
277 | + * When discount is from a credit note used to reduce payment of an invoice, we link using rowidinvoice |
|
278 | + * |
|
279 | + * @param int $rowidline Invoice line id (To use discount into invoice lines) |
|
280 | + * @param int $rowidinvoice Invoice id (To use discount as a credit note to reduc payment of invoice) |
|
281 | + * @return int <0 if KO, >0 if OK |
|
282 | + */ |
|
283 | + function link_to_invoice($rowidline,$rowidinvoice) |
|
284 | + { |
|
285 | + // Check parameters |
|
286 | + if (! $rowidline && ! $rowidinvoice) |
|
287 | + { |
|
288 | + $this->error='ErrorBadParameters'; |
|
289 | + return -1; |
|
290 | + } |
|
291 | + if ($rowidline && $rowidinvoice) |
|
292 | + { |
|
293 | + $this->error='ErrorBadParameters'; |
|
294 | + return -2; |
|
295 | + } |
|
296 | + |
|
297 | + $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
298 | + if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline; |
|
299 | + if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice; |
|
300 | + $sql.=" WHERE rowid = ".$this->id; |
|
301 | + |
|
302 | + dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG); |
|
303 | + $resql = $this->db->query($sql); |
|
304 | + if ($resql) |
|
305 | + { |
|
306 | + $this->fk_facture_line=$rowidline; |
|
307 | + $this->fk_facture=$rowidinvoice; |
|
308 | + return 1; |
|
309 | + } |
|
310 | + else |
|
311 | + { |
|
312 | + $this->error=$this->db->error(); |
|
313 | + return -3; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Link the discount to a particular invoice line or a particular invoice. |
|
320 | + * Do not call this if discount is linked to a reconcialiated invoice |
|
321 | + * |
|
322 | + * @return int <0 if KO, >0 if OK |
|
323 | + */ |
|
324 | + function unlink_invoice() |
|
325 | + { |
|
326 | + $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
327 | + $sql.=" SET fk_facture_line = NULL, fk_facture = NULL"; |
|
328 | + $sql.=" WHERE rowid = ".$this->id; |
|
329 | + |
|
330 | + dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG); |
|
331 | + $resql = $this->db->query($sql); |
|
332 | + if ($resql) |
|
333 | + { |
|
334 | + return 1; |
|
335 | + } |
|
336 | + else |
|
337 | + { |
|
338 | + $this->error=$this->db->error(); |
|
339 | + return -3; |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Return amount (with tax) of discounts currently available for a company, user or other criteria |
|
346 | + * |
|
347 | + * @param Societe $company Object third party for filter |
|
348 | + * @param User $user Filtre sur un user auteur des remises |
|
349 | + * @param string $filter Filtre autre |
|
350 | + * @param int $maxvalue Filter on max value for discount |
|
351 | + * @param string $mode 'customer' = discounts the customer has, 'supplier' = discount i have at this supplier |
|
352 | + * @return int <0 if KO, amount otherwise |
|
353 | + */ |
|
354 | + function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $mode='customer') |
|
355 | + { |
|
356 | + global $conf; |
|
357 | + |
|
358 | + $sql = "SELECT SUM(rc.amount_ttc) as amount"; |
|
359 | + //$sql = "SELECT rc.amount_ttc as amount"; |
|
360 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; |
|
361 | + $sql.= " WHERE rc.entity = " . $conf->entity; |
|
362 | + if ($mode != 'supplier') $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available |
|
363 | + else $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available |
|
364 | + if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; |
|
365 | + if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; |
|
366 | + if ($filter) $sql.=' AND ('.$filter.')'; |
|
367 | + if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
368 | + |
|
369 | + dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG); |
|
370 | + $resql=$this->db->query($sql); |
|
371 | + if ($resql) |
|
372 | + { |
|
373 | + $obj = $this->db->fetch_object($resql); |
|
374 | + //while ($obj) |
|
375 | + //{ |
|
376 | + //print 'zz'.$obj->amount; |
|
377 | + //$obj = $this->db->fetch_object($resql); |
|
378 | + //} |
|
379 | + return $obj->amount; |
|
380 | + } |
|
381 | + return -1; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Return amount (with tax) of all deposits invoices used by invoice as a payment. |
|
387 | + * Should always be empty, except if option FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is on (not recommended). |
|
388 | + * |
|
389 | + * @param CommonInvoice $invoice Object invoice (customer of supplier) |
|
390 | 390 | * @param int $multicurrency Return multicurrency_amount instead of amount |
391 | - * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
392 | - */ |
|
393 | - function getSumDepositsUsed($invoice, $multicurrency=0) |
|
394 | - { |
|
395 | - dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG); |
|
396 | - |
|
397 | - if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
|
398 | - { |
|
399 | - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
400 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
401 | - $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
402 | - $sql.= ' AND f.type = 3'; |
|
403 | - } |
|
404 | - else if ($invoice->element == 'invoice_supplier') |
|
405 | - { |
|
406 | - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
407 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
408 | - $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
409 | - $sql.= ' AND f.type = 3'; |
|
410 | - } |
|
411 | - else |
|
412 | - { |
|
413 | - $this->error=get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; |
|
414 | - dol_print_error($this->error); |
|
415 | - return -1; |
|
416 | - } |
|
417 | - |
|
418 | - $resql=$this->db->query($sql); |
|
419 | - if ($resql) |
|
420 | - { |
|
421 | - $obj = $this->db->fetch_object($resql); |
|
422 | - if ($multicurrency) return $obj->multicurrency_amount; |
|
391 | + * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
392 | + */ |
|
393 | + function getSumDepositsUsed($invoice, $multicurrency=0) |
|
394 | + { |
|
395 | + dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG); |
|
396 | + |
|
397 | + if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
|
398 | + { |
|
399 | + $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
400 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
401 | + $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
402 | + $sql.= ' AND f.type = 3'; |
|
403 | + } |
|
404 | + else if ($invoice->element == 'invoice_supplier') |
|
405 | + { |
|
406 | + $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
407 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
408 | + $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
409 | + $sql.= ' AND f.type = 3'; |
|
410 | + } |
|
411 | + else |
|
412 | + { |
|
413 | + $this->error=get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; |
|
414 | + dol_print_error($this->error); |
|
415 | + return -1; |
|
416 | + } |
|
417 | + |
|
418 | + $resql=$this->db->query($sql); |
|
419 | + if ($resql) |
|
420 | + { |
|
421 | + $obj = $this->db->fetch_object($resql); |
|
422 | + if ($multicurrency) return $obj->multicurrency_amount; |
|
423 | 423 | else return $obj->amount; |
424 | - } |
|
425 | - else |
|
426 | - { |
|
427 | - $this->error = $this->db->lasterror(); |
|
428 | - return -1; |
|
429 | - } |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Return amount (with tax) of all credit notes and deposits invoices used by invoice as a payment |
|
434 | - * |
|
435 | - * @param CommonInvoice $invoice Object invoice |
|
424 | + } |
|
425 | + else |
|
426 | + { |
|
427 | + $this->error = $this->db->lasterror(); |
|
428 | + return -1; |
|
429 | + } |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Return amount (with tax) of all credit notes and deposits invoices used by invoice as a payment |
|
434 | + * |
|
435 | + * @param CommonInvoice $invoice Object invoice |
|
436 | 436 | * @param int $multicurrency Return multicurrency_amount instead of amount |
437 | - * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
438 | - */ |
|
439 | - function getSumCreditNotesUsed($invoice, $multicurrency=0) |
|
440 | - { |
|
441 | - dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); |
|
442 | - |
|
443 | - if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
|
444 | - { |
|
445 | - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
446 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
447 | - $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
448 | - $sql.= ' AND f.type = 2'; |
|
449 | - } |
|
450 | - else if ($invoice->element == 'invoice_supplier') |
|
451 | - { |
|
452 | - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
453 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
454 | - $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
455 | - $sql.= ' AND f.type = 2'; |
|
456 | - } |
|
457 | - else |
|
458 | - { |
|
459 | - $this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; |
|
460 | - dol_print_error($this->error); |
|
461 | - return -1; |
|
462 | - } |
|
463 | - |
|
464 | - $resql=$this->db->query($sql); |
|
465 | - if ($resql) |
|
466 | - { |
|
467 | - $obj = $this->db->fetch_object($resql); |
|
468 | - if ($multicurrency) return $obj->multicurrency_amount; |
|
437 | + * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
|
438 | + */ |
|
439 | + function getSumCreditNotesUsed($invoice, $multicurrency=0) |
|
440 | + { |
|
441 | + dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); |
|
442 | + |
|
443 | + if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
|
444 | + { |
|
445 | + $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
446 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
447 | + $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
448 | + $sql.= ' AND f.type = 2'; |
|
449 | + } |
|
450 | + else if ($invoice->element == 'invoice_supplier') |
|
451 | + { |
|
452 | + $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
|
453 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
454 | + $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
455 | + $sql.= ' AND f.type = 2'; |
|
456 | + } |
|
457 | + else |
|
458 | + { |
|
459 | + $this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; |
|
460 | + dol_print_error($this->error); |
|
461 | + return -1; |
|
462 | + } |
|
463 | + |
|
464 | + $resql=$this->db->query($sql); |
|
465 | + if ($resql) |
|
466 | + { |
|
467 | + $obj = $this->db->fetch_object($resql); |
|
468 | + if ($multicurrency) return $obj->multicurrency_amount; |
|
469 | 469 | else return $obj->amount; |
470 | - } |
|
471 | - else |
|
472 | - { |
|
473 | - $this->error = $this->db->lasterror(); |
|
474 | - return -1; |
|
475 | - } |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Return clickable ref of object (with picto or not) |
|
480 | - * |
|
481 | - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Picto only |
|
482 | - * @param string $option Where to link to ('invoice' or 'discount') |
|
483 | - * @return string String with URL |
|
484 | - */ |
|
485 | - function getNomUrl($withpicto,$option='invoice') |
|
486 | - { |
|
487 | - global $langs; |
|
488 | - |
|
489 | - $result=''; |
|
490 | - |
|
491 | - if ($option == 'invoice') { |
|
492 | - $label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source; |
|
493 | - $link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->fk_facture_source.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
494 | - $linkend='</a>'; |
|
495 | - $ref=$this->ref_facture_source; |
|
496 | - $picto='bill'; |
|
497 | - } |
|
498 | - if ($option == 'discount') { |
|
499 | - $label=$langs->trans("Discount"); |
|
500 | - $link = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->fk_soc.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
501 | - $linkend='</a>'; |
|
502 | - $ref=$langs->trans("Discount"); |
|
503 | - $picto='generic'; |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
508 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
509 | - $result.=$link.$ref.$linkend; |
|
510 | - return $result; |
|
511 | - } |
|
470 | + } |
|
471 | + else |
|
472 | + { |
|
473 | + $this->error = $this->db->lasterror(); |
|
474 | + return -1; |
|
475 | + } |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Return clickable ref of object (with picto or not) |
|
480 | + * |
|
481 | + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Picto only |
|
482 | + * @param string $option Where to link to ('invoice' or 'discount') |
|
483 | + * @return string String with URL |
|
484 | + */ |
|
485 | + function getNomUrl($withpicto,$option='invoice') |
|
486 | + { |
|
487 | + global $langs; |
|
488 | + |
|
489 | + $result=''; |
|
490 | + |
|
491 | + if ($option == 'invoice') { |
|
492 | + $label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source; |
|
493 | + $link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->fk_facture_source.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
494 | + $linkend='</a>'; |
|
495 | + $ref=$this->ref_facture_source; |
|
496 | + $picto='bill'; |
|
497 | + } |
|
498 | + if ($option == 'discount') { |
|
499 | + $label=$langs->trans("Discount"); |
|
500 | + $link = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->fk_soc.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
|
501 | + $linkend='</a>'; |
|
502 | + $ref=$langs->trans("Discount"); |
|
503 | + $picto='generic'; |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
508 | + if ($withpicto && $withpicto != 2) $result.=' '; |
|
509 | + $result.=$link.$ref.$linkend; |
|
510 | + return $result; |
|
511 | + } |
|
512 | 512 | |
513 | 513 | |
514 | 514 | /** |
515 | - * Initialise an instance with random values. |
|
516 | - * Used to build previews or test instances. |
|
517 | - * id must be 0 if object instance is a specimen. |
|
518 | - * |
|
519 | - * @return void |
|
515 | + * Initialise an instance with random values. |
|
516 | + * Used to build previews or test instances. |
|
517 | + * id must be 0 if object instance is a specimen. |
|
518 | + * |
|
519 | + * @return void |
|
520 | 520 | */ |
521 | 521 | function initAsSpecimen() |
522 | 522 | { |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | public $db; |
33 | 33 | public $error; |
34 | 34 | |
35 | - public $id; // Id discount |
|
35 | + public $id; // Id discount |
|
36 | 36 | public $fk_soc; |
37 | - public $amount_ht; // |
|
38 | - public $amount_tva; // |
|
39 | - public $amount_ttc; // |
|
40 | - public $tva_tx; // Vat rate |
|
41 | - public $fk_user; // Id utilisateur qui accorde la remise |
|
42 | - public $description; // Description libre |
|
43 | - public $datec; // Date creation |
|
44 | - public $fk_facture_line; // Id invoice line when a discount is used into an invoice line (for absolute discounts) |
|
45 | - public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note) |
|
46 | - public $fk_facture_source; // Id facture avoir a l'origine de la remise |
|
47 | - public $ref_facture_source; // Ref facture avoir a l'origine de la remise |
|
37 | + public $amount_ht; // |
|
38 | + public $amount_tva; // |
|
39 | + public $amount_ttc; // |
|
40 | + public $tva_tx; // Vat rate |
|
41 | + public $fk_user; // Id utilisateur qui accorde la remise |
|
42 | + public $description; // Description libre |
|
43 | + public $datec; // Date creation |
|
44 | + public $fk_facture_line; // Id invoice line when a discount is used into an invoice line (for absolute discounts) |
|
45 | + public $fk_facture; // Id invoice when a discount line is used into an invoice (for credit note) |
|
46 | + public $fk_facture_source; // Id facture avoir a l'origine de la remise |
|
47 | + public $ref_facture_source; // Ref facture avoir a l'origine de la remise |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Constructor |
@@ -64,29 +64,29 @@ discard block |
||
64 | 64 | * @param int $fk_facture_source fk_facture_source |
65 | 65 | * @return int <0 if KO, =0 if not found, >0 if OK |
66 | 66 | */ |
67 | - function fetch($rowid, $fk_facture_source=0) |
|
67 | + function fetch($rowid, $fk_facture_source = 0) |
|
68 | 68 | { |
69 | 69 | global $conf; |
70 | 70 | |
71 | 71 | // Check parameters |
72 | - if (! $rowid && ! $fk_facture_source) |
|
72 | + if (!$rowid && !$fk_facture_source) |
|
73 | 73 | { |
74 | - $this->error='ErrorBadParameters'; |
|
74 | + $this->error = 'ErrorBadParameters'; |
|
75 | 75 | return -1; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $sql = "SELECT sr.rowid, sr.fk_soc,"; |
79 | - $sql.= " sr.fk_user,"; |
|
80 | - $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; |
|
81 | - $sql.= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; |
|
82 | - $sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,"; |
|
83 | - $sql.= " sr.datec,"; |
|
84 | - $sql.= " f.facnumber as ref_facture_source"; |
|
85 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; |
|
86 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; |
|
87 | - $sql.= " WHERE sr.entity = " . $conf->entity; |
|
88 | - if ($rowid) $sql.= " AND sr.rowid=".$rowid; |
|
89 | - if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; |
|
79 | + $sql .= " sr.fk_user,"; |
|
80 | + $sql .= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; |
|
81 | + $sql .= " sr.multicurrency_amount_ht, sr.multicurrency_amount_tva, sr.multicurrency_amount_ttc,"; |
|
82 | + $sql .= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,"; |
|
83 | + $sql .= " sr.datec,"; |
|
84 | + $sql .= " f.facnumber as ref_facture_source"; |
|
85 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; |
|
86 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; |
|
87 | + $sql .= " WHERE sr.entity = ".$conf->entity; |
|
88 | + if ($rowid) $sql .= " AND sr.rowid=".$rowid; |
|
89 | + if ($fk_facture_source) $sql .= " AND sr.fk_facture_source=".$fk_facture_source; |
|
90 | 90 | |
91 | 91 | dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
92 | 92 | $resql = $this->db->query($sql); |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | $this->fk_user = $obj->fk_user; |
112 | 112 | $this->fk_facture_line = $obj->fk_facture_line; |
113 | 113 | $this->fk_facture = $obj->fk_facture; |
114 | - $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source |
|
115 | - $this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source |
|
114 | + $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source |
|
115 | + $this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source |
|
116 | 116 | $this->description = $obj->description; |
117 | 117 | $this->datec = $this->db->jdate($obj->datec); |
118 | 118 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - $this->error=$this->db->error(); |
|
130 | + $this->error = $this->db->error(); |
|
131 | 131 | return -1; |
132 | 132 | } |
133 | 133 | } |
@@ -144,40 +144,40 @@ discard block |
||
144 | 144 | global $conf, $langs; |
145 | 145 | |
146 | 146 | // Clean parameters |
147 | - $this->amount_ht=price2num($this->amount_ht); |
|
148 | - $this->amount_tva=price2num($this->amount_tva); |
|
149 | - $this->amount_ttc=price2num($this->amount_ttc); |
|
150 | - $this->tva_tx=price2num($this->tva_tx); |
|
147 | + $this->amount_ht = price2num($this->amount_ht); |
|
148 | + $this->amount_tva = price2num($this->amount_tva); |
|
149 | + $this->amount_ttc = price2num($this->amount_ttc); |
|
150 | + $this->tva_tx = price2num($this->tva_tx); |
|
151 | 151 | |
152 | 152 | // Check parameters |
153 | 153 | if (empty($this->description)) |
154 | 154 | { |
155 | - $this->error='BadValueForPropertyDescription'; |
|
155 | + $this->error = 'BadValueForPropertyDescription'; |
|
156 | 156 | dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); |
157 | 157 | return -1; |
158 | 158 | } |
159 | 159 | |
160 | 160 | // Insert request |
161 | 161 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; |
162 | - $sql.= " (entity, datec, fk_soc, fk_user, description,"; |
|
163 | - $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; |
|
164 | - $sql.= " fk_facture_source"; |
|
165 | - $sql.= ")"; |
|
166 | - $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; |
|
167 | - $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; |
|
168 | - $sql.= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'":"null"); |
|
169 | - $sql.= ")"; |
|
162 | + $sql .= " (entity, datec, fk_soc, fk_user, description,"; |
|
163 | + $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx,"; |
|
164 | + $sql .= " fk_facture_source"; |
|
165 | + $sql .= ")"; |
|
166 | + $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec != '' ? $this->datec : dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; |
|
167 | + $sql .= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; |
|
168 | + $sql .= " ".($this->fk_facture_source ? "'".$this->db->escape($this->fk_facture_source)."'" : "null"); |
|
169 | + $sql .= ")"; |
|
170 | 170 | |
171 | 171 | dol_syslog(get_class($this)."::create", LOG_DEBUG); |
172 | - $resql=$this->db->query($sql); |
|
172 | + $resql = $this->db->query($sql); |
|
173 | 173 | if ($resql) |
174 | 174 | { |
175 | - $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); |
|
175 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); |
|
176 | 176 | return $this->id; |
177 | 177 | } |
178 | 178 | else |
179 | 179 | { |
180 | - $this->error=$this->db->lasterror().' - sql='.$sql; |
|
180 | + $this->error = $this->db->lasterror().' - sql='.$sql; |
|
181 | 181 | return -1; |
182 | 182 | } |
183 | 183 | } |
@@ -196,21 +196,21 @@ discard block |
||
196 | 196 | // Check if we can remove the discount |
197 | 197 | if ($this->fk_facture_source) |
198 | 198 | { |
199 | - $sql="SELECT COUNT(rowid) as nb"; |
|
200 | - $sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except"; |
|
201 | - $sql.=" WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount |
|
202 | - $sql.=" OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit |
|
203 | - $sql.=" AND fk_facture_source = ".$this->fk_facture_source; |
|
199 | + $sql = "SELECT COUNT(rowid) as nb"; |
|
200 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; |
|
201 | + $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount |
|
202 | + $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit |
|
203 | + $sql .= " AND fk_facture_source = ".$this->fk_facture_source; |
|
204 | 204 | //$sql.=" AND rowid != ".$this->id; |
205 | 205 | |
206 | 206 | dol_syslog(get_class($this)."::delete Check if we can remove discount", LOG_DEBUG); |
207 | - $resql=$this->db->query($sql); |
|
207 | + $resql = $this->db->query($sql); |
|
208 | 208 | if ($resql) |
209 | 209 | { |
210 | 210 | $obj = $this->db->fetch_object($resql); |
211 | 211 | if ($obj->nb > 0) |
212 | 212 | { |
213 | - $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved'; |
|
213 | + $this->error = 'ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved'; |
|
214 | 214 | return -2; |
215 | 215 | } |
216 | 216 | } |
@@ -225,24 +225,24 @@ discard block |
||
225 | 225 | |
226 | 226 | // Delete but only if not used |
227 | 227 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; |
228 | - if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie |
|
229 | - else $sql.= " WHERE rowid = ".$this->id; // Delete only line |
|
230 | - $sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount |
|
231 | - $sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit |
|
228 | + if ($this->fk_facture_source) $sql .= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie |
|
229 | + else $sql .= " WHERE rowid = ".$this->id; // Delete only line |
|
230 | + $sql .= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount |
|
231 | + $sql .= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit |
|
232 | 232 | |
233 | 233 | dol_syslog(get_class($this)."::delete Delete discount", LOG_DEBUG); |
234 | - $result=$this->db->query($sql); |
|
234 | + $result = $this->db->query($sql); |
|
235 | 235 | if ($result) |
236 | 236 | { |
237 | 237 | // If source of discount was a credit note or deposit, we change source statut. |
238 | 238 | if ($this->fk_facture_source) |
239 | 239 | { |
240 | 240 | $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; |
241 | - $sql.=" set paye=0, fk_statut=1"; |
|
242 | - $sql.=" WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source; |
|
241 | + $sql .= " set paye=0, fk_statut=1"; |
|
242 | + $sql .= " WHERE (type = 2 or type = 3) AND rowid=".$this->fk_facture_source; |
|
243 | 243 | |
244 | 244 | dol_syslog(get_class($this)."::delete Update credit note or deposit invoice statut", LOG_DEBUG); |
245 | - $result=$this->db->query($sql); |
|
245 | + $result = $this->db->query($sql); |
|
246 | 246 | if ($result) |
247 | 247 | { |
248 | 248 | $this->db->commit(); |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | } |
251 | 251 | else |
252 | 252 | { |
253 | - $this->error=$this->db->lasterror(); |
|
253 | + $this->error = $this->db->lasterror(); |
|
254 | 254 | $this->db->rollback(); |
255 | 255 | return -1; |
256 | 256 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | else |
265 | 265 | { |
266 | - $this->error=$this->db->lasterror(); |
|
266 | + $this->error = $this->db->lasterror(); |
|
267 | 267 | $this->db->rollback(); |
268 | 268 | return -1; |
269 | 269 | } |
@@ -280,36 +280,36 @@ discard block |
||
280 | 280 | * @param int $rowidinvoice Invoice id (To use discount as a credit note to reduc payment of invoice) |
281 | 281 | * @return int <0 if KO, >0 if OK |
282 | 282 | */ |
283 | - function link_to_invoice($rowidline,$rowidinvoice) |
|
283 | + function link_to_invoice($rowidline, $rowidinvoice) |
|
284 | 284 | { |
285 | 285 | // Check parameters |
286 | - if (! $rowidline && ! $rowidinvoice) |
|
286 | + if (!$rowidline && !$rowidinvoice) |
|
287 | 287 | { |
288 | - $this->error='ErrorBadParameters'; |
|
288 | + $this->error = 'ErrorBadParameters'; |
|
289 | 289 | return -1; |
290 | 290 | } |
291 | 291 | if ($rowidline && $rowidinvoice) |
292 | 292 | { |
293 | - $this->error='ErrorBadParameters'; |
|
293 | + $this->error = 'ErrorBadParameters'; |
|
294 | 294 | return -2; |
295 | 295 | } |
296 | 296 | |
297 | - $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
298 | - if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline; |
|
299 | - if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice; |
|
300 | - $sql.=" WHERE rowid = ".$this->id; |
|
297 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
298 | + if ($rowidline) $sql .= " SET fk_facture_line = ".$rowidline; |
|
299 | + if ($rowidinvoice) $sql .= " SET fk_facture = ".$rowidinvoice; |
|
300 | + $sql .= " WHERE rowid = ".$this->id; |
|
301 | 301 | |
302 | 302 | dol_syslog(get_class($this)."::link_to_invoice", LOG_DEBUG); |
303 | 303 | $resql = $this->db->query($sql); |
304 | 304 | if ($resql) |
305 | 305 | { |
306 | - $this->fk_facture_line=$rowidline; |
|
307 | - $this->fk_facture=$rowidinvoice; |
|
306 | + $this->fk_facture_line = $rowidline; |
|
307 | + $this->fk_facture = $rowidinvoice; |
|
308 | 308 | return 1; |
309 | 309 | } |
310 | 310 | else |
311 | 311 | { |
312 | - $this->error=$this->db->error(); |
|
312 | + $this->error = $this->db->error(); |
|
313 | 313 | return -3; |
314 | 314 | } |
315 | 315 | } |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | */ |
324 | 324 | function unlink_invoice() |
325 | 325 | { |
326 | - $sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
327 | - $sql.=" SET fk_facture_line = NULL, fk_facture = NULL"; |
|
328 | - $sql.=" WHERE rowid = ".$this->id; |
|
326 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; |
|
327 | + $sql .= " SET fk_facture_line = NULL, fk_facture = NULL"; |
|
328 | + $sql .= " WHERE rowid = ".$this->id; |
|
329 | 329 | |
330 | 330 | dol_syslog(get_class($this)."::unlink_invoice", LOG_DEBUG); |
331 | 331 | $resql = $this->db->query($sql); |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | } |
336 | 336 | else |
337 | 337 | { |
338 | - $this->error=$this->db->error(); |
|
338 | + $this->error = $this->db->error(); |
|
339 | 339 | return -3; |
340 | 340 | } |
341 | 341 | } |
@@ -351,23 +351,23 @@ discard block |
||
351 | 351 | * @param string $mode 'customer' = discounts the customer has, 'supplier' = discount i have at this supplier |
352 | 352 | * @return int <0 if KO, amount otherwise |
353 | 353 | */ |
354 | - function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0, $mode='customer') |
|
354 | + function getAvailableDiscounts($company = '', $user = '', $filter = '', $maxvalue = 0, $mode = 'customer') |
|
355 | 355 | { |
356 | 356 | global $conf; |
357 | 357 | |
358 | - $sql = "SELECT SUM(rc.amount_ttc) as amount"; |
|
358 | + $sql = "SELECT SUM(rc.amount_ttc) as amount"; |
|
359 | 359 | //$sql = "SELECT rc.amount_ttc as amount"; |
360 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; |
|
361 | - $sql.= " WHERE rc.entity = " . $conf->entity; |
|
362 | - if ($mode != 'supplier') $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available |
|
363 | - else $sql.= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available |
|
364 | - if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; |
|
365 | - if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; |
|
366 | - if ($filter) $sql.=' AND ('.$filter.')'; |
|
367 | - if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
360 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; |
|
361 | + $sql .= " WHERE rc.entity = ".$conf->entity; |
|
362 | + if ($mode != 'supplier') $sql .= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available |
|
363 | + else $sql .= " AND (rc.fk_suppler_invoice IS NULL AND rc.fk_supplier_invoice IS NULL)"; // Available |
|
364 | + if (is_object($company)) $sql .= " AND rc.fk_soc = ".$company->id; |
|
365 | + if (is_object($user)) $sql .= " AND rc.fk_user = ".$user->id; |
|
366 | + if ($filter) $sql .= ' AND ('.$filter.')'; |
|
367 | + if ($maxvalue) $sql .= ' AND rc.amount_ttc <= '.price2num($maxvalue); |
|
368 | 368 | |
369 | 369 | dol_syslog(get_class($this)."::getAvailableDiscounts", LOG_DEBUG); |
370 | - $resql=$this->db->query($sql); |
|
370 | + $resql = $this->db->query($sql); |
|
371 | 371 | if ($resql) |
372 | 372 | { |
373 | 373 | $obj = $this->db->fetch_object($resql); |
@@ -390,32 +390,32 @@ discard block |
||
390 | 390 | * @param int $multicurrency Return multicurrency_amount instead of amount |
391 | 391 | * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
392 | 392 | */ |
393 | - function getSumDepositsUsed($invoice, $multicurrency=0) |
|
393 | + function getSumDepositsUsed($invoice, $multicurrency = 0) |
|
394 | 394 | { |
395 | 395 | dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG); |
396 | 396 | |
397 | 397 | if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
398 | 398 | { |
399 | 399 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
400 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
401 | - $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
402 | - $sql.= ' AND f.type = 3'; |
|
400 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
401 | + $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
402 | + $sql .= ' AND f.type = 3'; |
|
403 | 403 | } |
404 | 404 | else if ($invoice->element == 'invoice_supplier') |
405 | 405 | { |
406 | 406 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
407 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
408 | - $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
409 | - $sql.= ' AND f.type = 3'; |
|
407 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
408 | + $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
409 | + $sql .= ' AND f.type = 3'; |
|
410 | 410 | } |
411 | 411 | else |
412 | 412 | { |
413 | - $this->error=get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; |
|
413 | + $this->error = get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; |
|
414 | 414 | dol_print_error($this->error); |
415 | 415 | return -1; |
416 | 416 | } |
417 | 417 | |
418 | - $resql=$this->db->query($sql); |
|
418 | + $resql = $this->db->query($sql); |
|
419 | 419 | if ($resql) |
420 | 420 | { |
421 | 421 | $obj = $this->db->fetch_object($resql); |
@@ -436,32 +436,32 @@ discard block |
||
436 | 436 | * @param int $multicurrency Return multicurrency_amount instead of amount |
437 | 437 | * @return int <0 if KO, Sum of credit notes and deposits amount otherwise |
438 | 438 | */ |
439 | - function getSumCreditNotesUsed($invoice, $multicurrency=0) |
|
439 | + function getSumCreditNotesUsed($invoice, $multicurrency = 0) |
|
440 | 440 | { |
441 | 441 | dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); |
442 | 442 | |
443 | 443 | if ($invoice->element == 'facture' || $invoice->element == 'invoice') |
444 | 444 | { |
445 | 445 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
446 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
447 | - $sql.= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
448 | - $sql.= ' AND f.type = 2'; |
|
446 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; |
|
447 | + $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.$invoice->id; |
|
448 | + $sql .= ' AND f.type = 2'; |
|
449 | 449 | } |
450 | 450 | else if ($invoice->element == 'invoice_supplier') |
451 | 451 | { |
452 | 452 | $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; |
453 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
454 | - $sql.= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
455 | - $sql.= ' AND f.type = 2'; |
|
453 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; |
|
454 | + $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.$invoice->id; |
|
455 | + $sql .= ' AND f.type = 2'; |
|
456 | 456 | } |
457 | 457 | else |
458 | 458 | { |
459 | - $this->error=get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; |
|
459 | + $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; |
|
460 | 460 | dol_print_error($this->error); |
461 | 461 | return -1; |
462 | 462 | } |
463 | 463 | |
464 | - $resql=$this->db->query($sql); |
|
464 | + $resql = $this->db->query($sql); |
|
465 | 465 | if ($resql) |
466 | 466 | { |
467 | 467 | $obj = $this->db->fetch_object($resql); |
@@ -482,31 +482,31 @@ discard block |
||
482 | 482 | * @param string $option Where to link to ('invoice' or 'discount') |
483 | 483 | * @return string String with URL |
484 | 484 | */ |
485 | - function getNomUrl($withpicto,$option='invoice') |
|
485 | + function getNomUrl($withpicto, $option = 'invoice') |
|
486 | 486 | { |
487 | 487 | global $langs; |
488 | 488 | |
489 | - $result=''; |
|
489 | + $result = ''; |
|
490 | 490 | |
491 | 491 | if ($option == 'invoice') { |
492 | - $label=$langs->trans("ShowDiscount").': '.$this->ref_facture_source; |
|
492 | + $label = $langs->trans("ShowDiscount").': '.$this->ref_facture_source; |
|
493 | 493 | $link = '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$this->fk_facture_source.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
494 | - $linkend='</a>'; |
|
495 | - $ref=$this->ref_facture_source; |
|
496 | - $picto='bill'; |
|
494 | + $linkend = '</a>'; |
|
495 | + $ref = $this->ref_facture_source; |
|
496 | + $picto = 'bill'; |
|
497 | 497 | } |
498 | 498 | if ($option == 'discount') { |
499 | - $label=$langs->trans("Discount"); |
|
499 | + $label = $langs->trans("Discount"); |
|
500 | 500 | $link = '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$this->fk_soc.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
501 | - $linkend='</a>'; |
|
502 | - $ref=$langs->trans("Discount"); |
|
503 | - $picto='generic'; |
|
501 | + $linkend = '</a>'; |
|
502 | + $ref = $langs->trans("Discount"); |
|
503 | + $picto = 'generic'; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
507 | - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
508 | - if ($withpicto && $withpicto != 2) $result.=' '; |
|
509 | - $result.=$link.$ref.$linkend; |
|
507 | + if ($withpicto) $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); |
|
508 | + if ($withpicto && $withpicto != 2) $result .= ' '; |
|
509 | + $result .= $link.$ref.$linkend; |
|
510 | 510 | return $result; |
511 | 511 | } |
512 | 512 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | */ |
521 | 521 | function initAsSpecimen() |
522 | 522 | { |
523 | - global $user,$langs,$conf; |
|
523 | + global $user, $langs, $conf; |
|
524 | 524 | |
525 | 525 | $this->fk_soc = 1; |
526 | 526 | $this->amount_ht = 10; |
@@ -36,7 +36,7 @@ |
||
36 | 36 | */ |
37 | 37 | function __construct($db) |
38 | 38 | { |
39 | - $this->db=$db; |
|
39 | + $this->db=$db; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * \ingroup core |
21 | 21 | * \brief File of class of generic business class |
22 | 22 | */ |
23 | -require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; |
|
23 | +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | function __construct($db) |
38 | 38 | { |
39 | - $this->db=$db; |
|
39 | + $this->db = $db; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | } |
@@ -28,156 +28,156 @@ |
||
28 | 28 | */ |
29 | 29 | class FormBarCode |
30 | 30 | { |
31 | - var $db; |
|
32 | - var $error; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructor |
|
37 | - * |
|
38 | - * @param DoliDB $db Database handler |
|
39 | - */ |
|
40 | - function __construct($db) |
|
41 | - { |
|
42 | - $this->db = $db; |
|
43 | - return 1; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Return HTML select with list of bar code generators |
|
49 | - * |
|
50 | - * @param int $selected Id code pre-selected |
|
51 | - * @param array $barcodelist Array of barcodes generators |
|
52 | - * @param int $code_id Id du code barre |
|
53 | - * @param int $idForm Id du formulaire |
|
54 | - * @return string HTML select string |
|
55 | - */ |
|
56 | - function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode') |
|
57 | - { |
|
58 | - global $conf, $langs; |
|
59 | - |
|
60 | - $disable = ''; |
|
61 | - |
|
62 | - if ($conf->use_javascript_ajax) |
|
63 | - { |
|
64 | - print "\n".'<script type="text/javascript" language="javascript">'; |
|
65 | - print 'jQuery(document).ready(function () { |
|
31 | + var $db; |
|
32 | + var $error; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructor |
|
37 | + * |
|
38 | + * @param DoliDB $db Database handler |
|
39 | + */ |
|
40 | + function __construct($db) |
|
41 | + { |
|
42 | + $this->db = $db; |
|
43 | + return 1; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Return HTML select with list of bar code generators |
|
49 | + * |
|
50 | + * @param int $selected Id code pre-selected |
|
51 | + * @param array $barcodelist Array of barcodes generators |
|
52 | + * @param int $code_id Id du code barre |
|
53 | + * @param int $idForm Id du formulaire |
|
54 | + * @return string HTML select string |
|
55 | + */ |
|
56 | + function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode') |
|
57 | + { |
|
58 | + global $conf, $langs; |
|
59 | + |
|
60 | + $disable = ''; |
|
61 | + |
|
62 | + if ($conf->use_javascript_ajax) |
|
63 | + { |
|
64 | + print "\n".'<script type="text/javascript" language="javascript">'; |
|
65 | + print 'jQuery(document).ready(function () { |
|
66 | 66 | jQuery("#select'.$idForm.'").change(function() { |
67 | 67 | var formName = document.getElementById("form'.$idForm.'"); |
68 | 68 | formName.action.value="setcoder"; |
69 | 69 | formName.submit(); |
70 | 70 | }); |
71 | 71 | });'; |
72 | - print '</script>'."\n"; |
|
73 | - //onChange="barcode_coder_save(\''.$idForm.'\') |
|
74 | - } |
|
75 | - |
|
76 | - // We check if barcode is already selected by default |
|
77 | - if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
78 | - (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
79 | - { |
|
80 | - $disable = 'disabled'; |
|
81 | - } |
|
82 | - |
|
83 | - $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="post" id="form'.$idForm.'">'; |
|
84 | - $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
85 | - $select_encoder.= '<input type="hidden" name="action" value="update">'; |
|
86 | - $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
87 | - $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="coder">'; |
|
88 | - $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
89 | - $select_encoder.= '<option value="-1" disabled>--------------------</option>'; |
|
90 | - foreach($barcodelist as $key => $value) |
|
91 | - { |
|
92 | - $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>'; |
|
93 | - } |
|
94 | - $select_encoder.= '</select></form>'; |
|
95 | - |
|
96 | - return $select_encoder; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Return form to select type of barcode |
|
101 | - * |
|
102 | - * @param int $selected Id code pre-selected |
|
103 | - * @param string $htmlname Name of HTML select field |
|
104 | - * @param int $useempty Affiche valeur vide dans liste |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0) |
|
108 | - { |
|
109 | - global $langs,$conf; |
|
110 | - |
|
111 | - $sql = "SELECT rowid, code, libelle"; |
|
112 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
113 | - $sql.= " WHERE coder <> '0'"; |
|
114 | - $sql.= " AND entity = ".$conf->entity; |
|
115 | - $sql.= " ORDER BY code"; |
|
116 | - |
|
117 | - $result = $this->db->query($sql); |
|
118 | - if ($result) |
|
119 | - { |
|
120 | - $num = $this->db->num_rows($result); |
|
121 | - $i = 0; |
|
122 | - |
|
123 | - if ($useempty && $num > 0) |
|
124 | - { |
|
125 | - print '<select class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
126 | - print '<option value="0"> </option>'; |
|
127 | - } |
|
128 | - else |
|
129 | - { |
|
130 | - $langs->load("errors"); |
|
131 | - print '<select disabled class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
132 | - print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>'; |
|
133 | - } |
|
134 | - |
|
135 | - while ($i < $num) |
|
136 | - { |
|
137 | - $obj = $this->db->fetch_object($result); |
|
138 | - if ($selected == $obj->rowid) |
|
139 | - { |
|
140 | - print '<option value="'.$obj->rowid.'" selected>'; |
|
141 | - } |
|
142 | - else |
|
143 | - { |
|
144 | - print '<option value="'.$obj->rowid.'">'; |
|
145 | - } |
|
146 | - print $obj->libelle; |
|
147 | - print '</option>'; |
|
148 | - $i++; |
|
149 | - } |
|
150 | - print "</select>"; |
|
151 | - } |
|
152 | - else { |
|
153 | - dol_print_error($this->db); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Show form to select type of barcode |
|
159 | - * |
|
160 | - * @param string $page Page |
|
161 | - * @param int $selected Id condition preselected |
|
162 | - * @param string $htmlname Nom du formulaire select |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') |
|
166 | - { |
|
167 | - global $langs,$conf; |
|
168 | - if ($htmlname != "none") |
|
169 | - { |
|
170 | - print '<form method="post" action="'.$page.'">'; |
|
171 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
172 | - print '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
|
173 | - print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
|
174 | - print '<tr><td>'; |
|
175 | - $this->select_barcode_type($selected, $htmlname, 1); |
|
176 | - print '</td>'; |
|
177 | - print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
|
178 | - print '</td></tr></table></form>'; |
|
179 | - } |
|
180 | - } |
|
72 | + print '</script>'."\n"; |
|
73 | + //onChange="barcode_coder_save(\''.$idForm.'\') |
|
74 | + } |
|
75 | + |
|
76 | + // We check if barcode is already selected by default |
|
77 | + if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
78 | + (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
79 | + { |
|
80 | + $disable = 'disabled'; |
|
81 | + } |
|
82 | + |
|
83 | + $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="post" id="form'.$idForm.'">'; |
|
84 | + $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
85 | + $select_encoder.= '<input type="hidden" name="action" value="update">'; |
|
86 | + $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
87 | + $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="coder">'; |
|
88 | + $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
89 | + $select_encoder.= '<option value="-1" disabled>--------------------</option>'; |
|
90 | + foreach($barcodelist as $key => $value) |
|
91 | + { |
|
92 | + $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>'; |
|
93 | + } |
|
94 | + $select_encoder.= '</select></form>'; |
|
95 | + |
|
96 | + return $select_encoder; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Return form to select type of barcode |
|
101 | + * |
|
102 | + * @param int $selected Id code pre-selected |
|
103 | + * @param string $htmlname Name of HTML select field |
|
104 | + * @param int $useempty Affiche valeur vide dans liste |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0) |
|
108 | + { |
|
109 | + global $langs,$conf; |
|
110 | + |
|
111 | + $sql = "SELECT rowid, code, libelle"; |
|
112 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
113 | + $sql.= " WHERE coder <> '0'"; |
|
114 | + $sql.= " AND entity = ".$conf->entity; |
|
115 | + $sql.= " ORDER BY code"; |
|
116 | + |
|
117 | + $result = $this->db->query($sql); |
|
118 | + if ($result) |
|
119 | + { |
|
120 | + $num = $this->db->num_rows($result); |
|
121 | + $i = 0; |
|
122 | + |
|
123 | + if ($useempty && $num > 0) |
|
124 | + { |
|
125 | + print '<select class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
126 | + print '<option value="0"> </option>'; |
|
127 | + } |
|
128 | + else |
|
129 | + { |
|
130 | + $langs->load("errors"); |
|
131 | + print '<select disabled class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
|
132 | + print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>'; |
|
133 | + } |
|
134 | + |
|
135 | + while ($i < $num) |
|
136 | + { |
|
137 | + $obj = $this->db->fetch_object($result); |
|
138 | + if ($selected == $obj->rowid) |
|
139 | + { |
|
140 | + print '<option value="'.$obj->rowid.'" selected>'; |
|
141 | + } |
|
142 | + else |
|
143 | + { |
|
144 | + print '<option value="'.$obj->rowid.'">'; |
|
145 | + } |
|
146 | + print $obj->libelle; |
|
147 | + print '</option>'; |
|
148 | + $i++; |
|
149 | + } |
|
150 | + print "</select>"; |
|
151 | + } |
|
152 | + else { |
|
153 | + dol_print_error($this->db); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Show form to select type of barcode |
|
159 | + * |
|
160 | + * @param string $page Page |
|
161 | + * @param int $selected Id condition preselected |
|
162 | + * @param string $htmlname Nom du formulaire select |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') |
|
166 | + { |
|
167 | + global $langs,$conf; |
|
168 | + if ($htmlname != "none") |
|
169 | + { |
|
170 | + print '<form method="post" action="'.$page.'">'; |
|
171 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
172 | + print '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
|
173 | + print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
|
174 | + print '<tr><td>'; |
|
175 | + $this->select_barcode_type($selected, $htmlname, 1); |
|
176 | + print '</td>'; |
|
177 | + print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">'; |
|
178 | + print '</td></tr></table></form>'; |
|
179 | + } |
|
180 | + } |
|
181 | 181 | |
182 | 182 | } |
183 | 183 |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param int $idForm Id du formulaire |
54 | 54 | * @return string HTML select string |
55 | 55 | */ |
56 | - function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode') |
|
56 | + function setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm = 'formbarcode') |
|
57 | 57 | { |
58 | 58 | global $conf, $langs; |
59 | 59 | |
@@ -74,24 +74,24 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | // We check if barcode is already selected by default |
77 | - if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
78 | - (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
77 | + if (((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) || |
|
78 | + (!empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id)) |
|
79 | 79 | { |
80 | 80 | $disable = 'disabled'; |
81 | 81 | } |
82 | 82 | |
83 | 83 | $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="post" id="form'.$idForm.'">'; |
84 | - $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
85 | - $select_encoder.= '<input type="hidden" name="action" value="update">'; |
|
86 | - $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
87 | - $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="coder">'; |
|
88 | - $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
89 | - $select_encoder.= '<option value="-1" disabled>--------------------</option>'; |
|
90 | - foreach($barcodelist as $key => $value) |
|
84 | + $select_encoder .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
85 | + $select_encoder .= '<input type="hidden" name="action" value="update">'; |
|
86 | + $select_encoder .= '<input type="hidden" name="code_id" value="'.$code_id.'">'; |
|
87 | + $select_encoder .= '<select id="select'.$idForm.'" class="flat" name="coder">'; |
|
88 | + $select_encoder .= '<option value="0"'.($selected == 0 ? ' selected' : '').' '.$disable.'>'.$langs->trans('Disable').'</option>'; |
|
89 | + $select_encoder .= '<option value="-1" disabled>--------------------</option>'; |
|
90 | + foreach ($barcodelist as $key => $value) |
|
91 | 91 | { |
92 | - $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>'; |
|
92 | + $select_encoder .= '<option value="'.$key.'"'.($selected == $key ? ' selected' : '').'>'.$value.'</option>'; |
|
93 | 93 | } |
94 | - $select_encoder.= '</select></form>'; |
|
94 | + $select_encoder .= '</select></form>'; |
|
95 | 95 | |
96 | 96 | return $select_encoder; |
97 | 97 | } |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | * @param int $useempty Affiche valeur vide dans liste |
105 | 105 | * @return void |
106 | 106 | */ |
107 | - function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0) |
|
107 | + function select_barcode_type($selected = '', $htmlname = 'barcodetype_id', $useempty = 0) |
|
108 | 108 | { |
109 | - global $langs,$conf; |
|
109 | + global $langs, $conf; |
|
110 | 110 | |
111 | 111 | $sql = "SELECT rowid, code, libelle"; |
112 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
113 | - $sql.= " WHERE coder <> '0'"; |
|
114 | - $sql.= " AND entity = ".$conf->entity; |
|
115 | - $sql.= " ORDER BY code"; |
|
112 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
113 | + $sql .= " WHERE coder <> '0'"; |
|
114 | + $sql .= " AND entity = ".$conf->entity; |
|
115 | + $sql .= " ORDER BY code"; |
|
116 | 116 | |
117 | 117 | $result = $this->db->query($sql); |
118 | 118 | if ($result) |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | * @param string $htmlname Nom du formulaire select |
163 | 163 | * @return void |
164 | 164 | */ |
165 | - function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') |
|
165 | + function form_barcode_type($page, $selected = '', $htmlname = 'barcodetype_id') |
|
166 | 166 | { |
167 | - global $langs,$conf; |
|
167 | + global $langs, $conf; |
|
168 | 168 | if ($htmlname != "none") |
169 | 169 | { |
170 | 170 | print '<form method="post" action="'.$page.'">'; |
@@ -124,8 +124,7 @@ discard block |
||
124 | 124 | { |
125 | 125 | print '<select class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
126 | 126 | print '<option value="0"> </option>'; |
127 | - } |
|
128 | - else |
|
127 | + } else |
|
129 | 128 | { |
130 | 129 | $langs->load("errors"); |
131 | 130 | print '<select disabled class="flat" name="'.$htmlname.'" id="select_'.$htmlname.'">'; |
@@ -138,8 +137,7 @@ discard block |
||
138 | 137 | if ($selected == $obj->rowid) |
139 | 138 | { |
140 | 139 | print '<option value="'.$obj->rowid.'" selected>'; |
141 | - } |
|
142 | - else |
|
140 | + } else |
|
143 | 141 | { |
144 | 142 | print '<option value="'.$obj->rowid.'">'; |
145 | 143 | } |
@@ -148,8 +146,7 @@ discard block |
||
148 | 146 | $i++; |
149 | 147 | } |
150 | 148 | print "</select>"; |
151 | - } |
|
152 | - else { |
|
149 | + } else { |
|
153 | 150 | dol_print_error($this->db); |
154 | 151 | } |
155 | 152 | } |
@@ -504,26 +504,26 @@ |
||
504 | 504 | // param_name is an array identifier like "files[]", |
505 | 505 | // $_FILES is a multi-dimensional array: |
506 | 506 | foreach ($upload['tmp_name'] as $index => $value) { |
507 | - $info[] = $this->handleFileUpload( |
|
508 | - $upload['tmp_name'][$index], |
|
509 | - isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], |
|
510 | - isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], |
|
511 | - isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], |
|
512 | - $upload['error'][$index], |
|
513 | - $index |
|
514 | - ); |
|
507 | + $info[] = $this->handleFileUpload( |
|
508 | + $upload['tmp_name'][$index], |
|
509 | + isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index], |
|
510 | + isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index], |
|
511 | + isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index], |
|
512 | + $upload['error'][$index], |
|
513 | + $index |
|
514 | + ); |
|
515 | 515 | } |
516 | 516 | } elseif ($upload || isset($_SERVER['HTTP_X_FILE_NAME'])) { |
517 | 517 | // param_name is a single object identifier like "file", |
518 | 518 | // $_FILES is a one-dimensional array: |
519 | - $info[] = $this->handleFileUpload( |
|
520 | - isset($upload['tmp_name']) ? $upload['tmp_name'] : null, |
|
521 | - isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : (isset($upload['name']) ? $upload['name'] : null), |
|
522 | - isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : (isset($upload['size']) ? $upload['size'] : null), |
|
523 | - isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : (isset($upload['type']) ? $upload['type'] : null), |
|
524 | - isset($upload['error']) ? $upload['error'] : null, |
|
525 | - 0 |
|
526 | - ); |
|
519 | + $info[] = $this->handleFileUpload( |
|
520 | + isset($upload['tmp_name']) ? $upload['tmp_name'] : null, |
|
521 | + isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : (isset($upload['name']) ? $upload['name'] : null), |
|
522 | + isset($_SERVER['HTTP_X_FILE_SIZE']) ? $_SERVER['HTTP_X_FILE_SIZE'] : (isset($upload['size']) ? $upload['size'] : null), |
|
523 | + isset($_SERVER['HTTP_X_FILE_TYPE']) ? $_SERVER['HTTP_X_FILE_TYPE'] : (isset($upload['type']) ? $upload['type'] : null), |
|
524 | + isset($upload['error']) ? $upload['error'] : null, |
|
525 | + 0 |
|
526 | + ); |
|
527 | 527 | } |
528 | 528 | header('Vary: Accept'); |
529 | 529 | $json = json_encode($info); |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | * @param int $fk_element fk_element |
42 | 42 | * @param string $element element |
43 | 43 | */ |
44 | - function __construct($options=null,$fk_element=null,$element=null) |
|
44 | + function __construct($options = null, $fk_element = null, $element = null) |
|
45 | 45 | { |
46 | 46 | global $db, $conf; |
47 | 47 | global $object; |
48 | 48 | |
49 | - $this->fk_element=$fk_element; |
|
50 | - $this->element=$element; |
|
49 | + $this->fk_element = $fk_element; |
|
50 | + $this->element = $element; |
|
51 | 51 | |
52 | - $pathname=$filename=$element; |
|
53 | - if (preg_match('/^([^_]+)_([^_]+)/i',$element,$regs)) |
|
52 | + $pathname = $filename = $element; |
|
53 | + if (preg_match('/^([^_]+)_([^_]+)/i', $element, $regs)) |
|
54 | 54 | { |
55 | 55 | $pathname = $regs[1]; |
56 | 56 | $filename = $regs[2]; |
@@ -61,48 +61,48 @@ discard block |
||
61 | 61 | // For compatibility |
62 | 62 | if ($element == 'propal') { |
63 | 63 | $pathname = 'comm/propal'; |
64 | - $dir_output=$conf->$element->dir_output; |
|
64 | + $dir_output = $conf->$element->dir_output; |
|
65 | 65 | } |
66 | 66 | elseif ($element == 'facture') { |
67 | 67 | $pathname = 'compta/facture'; |
68 | - $dir_output=$conf->$element->dir_output; |
|
68 | + $dir_output = $conf->$element->dir_output; |
|
69 | 69 | } |
70 | 70 | elseif ($element == 'project') { |
71 | 71 | $element = $pathname = 'projet'; |
72 | - $dir_output=$conf->$element->dir_output; |
|
72 | + $dir_output = $conf->$element->dir_output; |
|
73 | 73 | } |
74 | 74 | elseif ($element == 'project_task') { |
75 | - $pathname = 'projet'; $filename='task'; |
|
76 | - $dir_output=$conf->projet->dir_output; |
|
75 | + $pathname = 'projet'; $filename = 'task'; |
|
76 | + $dir_output = $conf->projet->dir_output; |
|
77 | 77 | $parentForeignKey = 'fk_project'; |
78 | 78 | $parentClass = 'Project'; |
79 | 79 | $parentElement = 'projet'; |
80 | 80 | $parentObject = 'project'; |
81 | 81 | } |
82 | 82 | elseif ($element == 'fichinter') { |
83 | - $element='ficheinter'; |
|
84 | - $dir_output=$conf->$element->dir_output; |
|
83 | + $element = 'ficheinter'; |
|
84 | + $dir_output = $conf->$element->dir_output; |
|
85 | 85 | } |
86 | 86 | elseif ($element == 'order_supplier') { |
87 | - $pathname = 'fourn'; $filename='fournisseur.commande'; |
|
88 | - $dir_output=$conf->fournisseur->commande->dir_output; |
|
87 | + $pathname = 'fourn'; $filename = 'fournisseur.commande'; |
|
88 | + $dir_output = $conf->fournisseur->commande->dir_output; |
|
89 | 89 | } |
90 | 90 | elseif ($element == 'invoice_supplier') { |
91 | - $pathname = 'fourn'; $filename='fournisseur.facture'; |
|
92 | - $dir_output=$conf->fournisseur->facture->dir_output; |
|
91 | + $pathname = 'fourn'; $filename = 'fournisseur.facture'; |
|
92 | + $dir_output = $conf->fournisseur->facture->dir_output; |
|
93 | 93 | } |
94 | 94 | elseif ($element == 'product') { |
95 | 95 | $dir_output = $conf->product->multidir_output[$conf->entity]; |
96 | 96 | } |
97 | 97 | elseif ($element == 'action') { |
98 | - $pathname = 'comm/action'; $filename='actioncomm'; |
|
99 | - $dir_output=$conf->agenda->dir_output; |
|
98 | + $pathname = 'comm/action'; $filename = 'actioncomm'; |
|
99 | + $dir_output = $conf->agenda->dir_output; |
|
100 | 100 | } |
101 | 101 | elseif ($element == 'chargesociales') { |
102 | - $pathname = 'compta/sociales'; $filename='chargesociales'; |
|
103 | - $dir_output=$conf->tax->dir_output; |
|
102 | + $pathname = 'compta/sociales'; $filename = 'chargesociales'; |
|
103 | + $dir_output = $conf->tax->dir_output; |
|
104 | 104 | } else { |
105 | - $dir_output=$conf->$element->dir_output; |
|
105 | + $dir_output = $conf->$element->dir_output; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | dol_include_once('/'.$pathname.'/class/'.$filename.'.class.php'); |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | |
133 | 133 | $object_ref = dol_sanitizeFileName($object->ref); |
134 | 134 | if ($element == 'invoice_supplier') { |
135 | - $object_ref = get_exdir($object->id,2,0,0,$object,'invoice_supplier') . $object_ref; |
|
135 | + $object_ref = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object_ref; |
|
136 | 136 | } else if ($element == 'project_task') { |
137 | - $object_ref = $object->project->ref . '/' . $object_ref; |
|
137 | + $object_ref = $object->project->ref.'/'.$object_ref; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | $this->options = array( |
141 | 141 | 'script_url' => $_SERVER['PHP_SELF'], |
142 | - 'upload_dir' => $dir_output . '/' . $object_ref . '/', |
|
142 | + 'upload_dir' => $dir_output.'/'.$object_ref.'/', |
|
143 | 143 | 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/', |
144 | 144 | 'param_name' => 'files', |
145 | 145 | // Set the following option to 'POST', if your server does not support |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | ), |
174 | 174 | */ |
175 | 175 | 'thumbnail' => array( |
176 | - 'upload_dir' => $dir_output . '/' . $object_ref . '/thumbs/', |
|
176 | + 'upload_dir' => $dir_output.'/'.$object_ref.'/thumbs/', |
|
177 | 177 | 'upload_url' => DOL_URL_ROOT.'/document.php?modulepart='.$element.'&attachment=1&file=/'.$object_ref.'/thumbs/', |
178 | 178 | 'max_width' => 80, |
179 | 179 | 'max_height' => 80 |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
200 | 200 | ($https && $_SERVER['SERVER_PORT'] === 443 || |
201 | 201 | $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
202 | - substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
202 | + substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -231,12 +231,12 @@ discard block |
||
231 | 231 | { |
232 | 232 | $file = new stdClass(); |
233 | 233 | $file->name = $file_name; |
234 | - $file->mime = dol_mimetype($file_name,'',2); |
|
234 | + $file->mime = dol_mimetype($file_name, '', 2); |
|
235 | 235 | $file->size = filesize($file_path); |
236 | 236 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
237 | - foreach($this->options['image_versions'] as $version => $options) { |
|
237 | + foreach ($this->options['image_versions'] as $version => $options) { |
|
238 | 238 | if (is_file($options['upload_dir'].$file_name)) { |
239 | - $tmp=explode('.',$file->name); |
|
239 | + $tmp = explode('.', $file->name); |
|
240 | 240 | $file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]); |
241 | 241 | } |
242 | 242 | } |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | |
280 | - $res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini'); // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini". |
|
280 | + $res = vignette($file_path, $maxwidthmini, $maxheightmini, '_mini'); // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini". |
|
281 | 281 | |
282 | - if (preg_match('/error/i',$res)) return false; |
|
282 | + if (preg_match('/error/i', $res)) return false; |
|
283 | 283 | return true; |
284 | 284 | } |
285 | 285 | else |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | } |
396 | 396 | if ($this->options['discard_aborted_uploads']) |
397 | 397 | { |
398 | - while(is_file($this->options['upload_dir'].$file_name)) |
|
398 | + while (is_file($this->options['upload_dir'].$file_name)) |
|
399 | 399 | { |
400 | 400 | $file_name = $this->upcountName($file_name); |
401 | 401 | } |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | { |
419 | 419 | $file = new stdClass(); |
420 | 420 | $file->name = $this->trimFileName($name, $type, $index); |
421 | - $file->mime = dol_mimetype($file->name,'',2); |
|
421 | + $file->mime = dol_mimetype($file->name, '', 2); |
|
422 | 422 | $file->size = intval($size); |
423 | 423 | $file->type = $type; |
424 | 424 | if ($this->validate($uploaded_file, $file, $error, $index) && dol_mkdir($this->options['upload_dir']) >= 0) |
@@ -444,11 +444,11 @@ discard block |
||
444 | 444 | if ($file_size === $file->size) |
445 | 445 | { |
446 | 446 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
447 | - foreach($this->options['image_versions'] as $version => $options) |
|
447 | + foreach ($this->options['image_versions'] as $version => $options) |
|
448 | 448 | { |
449 | 449 | if ($this->createScaledImage($file->name, $options)) |
450 | 450 | { |
451 | - $tmp=explode('.',$file->name); |
|
451 | + $tmp = explode('.', $file->name); |
|
452 | 452 | $file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]); |
453 | 453 | } |
454 | 454 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); |
556 | 556 | if ($success) |
557 | 557 | { |
558 | - foreach($this->options['image_versions'] as $version => $options) |
|
558 | + foreach ($this->options['image_versions'] as $version => $options) |
|
559 | 559 | { |
560 | 560 | $file = $options['upload_dir'].$file_name; |
561 | 561 | if (is_file($file)) |
@@ -62,43 +62,34 @@ discard block |
||
62 | 62 | if ($element == 'propal') { |
63 | 63 | $pathname = 'comm/propal'; |
64 | 64 | $dir_output=$conf->$element->dir_output; |
65 | - } |
|
66 | - elseif ($element == 'facture') { |
|
65 | + } elseif ($element == 'facture') { |
|
67 | 66 | $pathname = 'compta/facture'; |
68 | 67 | $dir_output=$conf->$element->dir_output; |
69 | - } |
|
70 | - elseif ($element == 'project') { |
|
68 | + } elseif ($element == 'project') { |
|
71 | 69 | $element = $pathname = 'projet'; |
72 | 70 | $dir_output=$conf->$element->dir_output; |
73 | - } |
|
74 | - elseif ($element == 'project_task') { |
|
71 | + } elseif ($element == 'project_task') { |
|
75 | 72 | $pathname = 'projet'; $filename='task'; |
76 | 73 | $dir_output=$conf->projet->dir_output; |
77 | 74 | $parentForeignKey = 'fk_project'; |
78 | 75 | $parentClass = 'Project'; |
79 | 76 | $parentElement = 'projet'; |
80 | 77 | $parentObject = 'project'; |
81 | - } |
|
82 | - elseif ($element == 'fichinter') { |
|
78 | + } elseif ($element == 'fichinter') { |
|
83 | 79 | $element='ficheinter'; |
84 | 80 | $dir_output=$conf->$element->dir_output; |
85 | - } |
|
86 | - elseif ($element == 'order_supplier') { |
|
81 | + } elseif ($element == 'order_supplier') { |
|
87 | 82 | $pathname = 'fourn'; $filename='fournisseur.commande'; |
88 | 83 | $dir_output=$conf->fournisseur->commande->dir_output; |
89 | - } |
|
90 | - elseif ($element == 'invoice_supplier') { |
|
84 | + } elseif ($element == 'invoice_supplier') { |
|
91 | 85 | $pathname = 'fourn'; $filename='fournisseur.facture'; |
92 | 86 | $dir_output=$conf->fournisseur->facture->dir_output; |
93 | - } |
|
94 | - elseif ($element == 'product') { |
|
87 | + } elseif ($element == 'product') { |
|
95 | 88 | $dir_output = $conf->product->multidir_output[$conf->entity]; |
96 | - } |
|
97 | - elseif ($element == 'action') { |
|
89 | + } elseif ($element == 'action') { |
|
98 | 90 | $pathname = 'comm/action'; $filename='actioncomm'; |
99 | 91 | $dir_output=$conf->agenda->dir_output; |
100 | - } |
|
101 | - elseif ($element == 'chargesociales') { |
|
92 | + } elseif ($element == 'chargesociales') { |
|
102 | 93 | $pathname = 'compta/sociales'; $filename='chargesociales'; |
103 | 94 | $dir_output=$conf->tax->dir_output; |
104 | 95 | } else { |
@@ -279,10 +270,11 @@ discard block |
||
279 | 270 | |
280 | 271 | $res=vignette($file_path,$maxwidthmini,$maxheightmini,'_mini'); // We don't use ->addThumbs here because there is no object and we don't need all thumbs, only the "mini". |
281 | 272 | |
282 | - if (preg_match('/error/i',$res)) return false; |
|
273 | + if (preg_match('/error/i',$res)) { |
|
274 | + return false; |
|
275 | + } |
|
283 | 276 | return true; |
284 | - } |
|
285 | - else |
|
277 | + } else |
|
286 | 278 | { |
287 | 279 | return false; |
288 | 280 | } |
@@ -434,8 +426,7 @@ discard block |
||
434 | 426 | } else { |
435 | 427 | dol_move_uploaded_file($uploaded_file, $file_path, 1, 0, 0, 0, 'userfile'); |
436 | 428 | } |
437 | - } |
|
438 | - else |
|
429 | + } else |
|
439 | 430 | { |
440 | 431 | // Non-multipart uploads (PUT method support) |
441 | 432 | file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); |
@@ -452,8 +443,7 @@ discard block |
||
452 | 443 | $file->{$version.'_url'} = $options['upload_url'].rawurlencode($tmp[0].'_mini.'.$tmp[1]); |
453 | 444 | } |
454 | 445 | } |
455 | - } |
|
456 | - else if ($this->options['discard_aborted_uploads']) |
|
446 | + } else if ($this->options['discard_aborted_uploads']) |
|
457 | 447 | { |
458 | 448 | unlink($file_path); |
459 | 449 | $file->error = 'abort'; |
@@ -476,8 +466,7 @@ discard block |
||
476 | 466 | if ($file_name) |
477 | 467 | { |
478 | 468 | $info = $this->getFileObject($file_name); |
479 | - } |
|
480 | - else |
|
469 | + } else |
|
481 | 470 | { |
482 | 471 | $info = $this->getFileObjects(); |
483 | 472 | } |
@@ -109,7 +109,7 @@ |
||
109 | 109 | * @param int $secure 0 or 1 |
110 | 110 | * @return void |
111 | 111 | */ |
112 | - public function setCookie($cookie, $value, $expire=0, $path="/", $domain="", $secure=0) |
|
112 | + public function setCookie($cookie, $value, $expire = 0, $path = "/", $domain = "", $secure = 0) |
|
113 | 113 | { |
114 | 114 | $this->myCookie = $cookie; |
115 | 115 | $this->myValue = $value; |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | $valuecrypt = base64_encode($this->myValue); |
71 | 71 | $this->cookie = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->_myKey, $valuecrypt, MCRYPT_MODE_CBC, $this->_iv)); |
72 | - } |
|
73 | - else |
|
72 | + } else |
|
74 | 73 | { |
75 | 74 | $this->cookie = $this->myValue; |
76 | 75 | } |
@@ -91,8 +90,7 @@ discard block |
||
91 | 90 | $this->myValue = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->_myKey, base64_decode($this->cookie), MCRYPT_MODE_CBC, $this->_iv)); |
92 | 91 | |
93 | 92 | return(base64_decode($this->myValue)); |
94 | - } |
|
95 | - else |
|
93 | + } else |
|
96 | 94 | { |
97 | 95 | return($_COOKIE[$this->myCookie]); |
98 | 96 | } |
@@ -27,10 +27,10 @@ |
||
27 | 27 | */ |
28 | 28 | class DolException extends Exception |
29 | 29 | { |
30 | - /** |
|
31 | - * Constructor |
|
32 | - */ |
|
33 | - function __construct() |
|
34 | - { |
|
35 | - } |
|
30 | + /** |
|
31 | + * Constructor |
|
32 | + */ |
|
33 | + function __construct() |
|
34 | + { |
|
35 | + } |
|
36 | 36 | } |
@@ -30,55 +30,55 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class Notify |
32 | 32 | { |
33 | - var $id; |
|
34 | - var $db; |
|
35 | - var $error; |
|
36 | - var $errors=array(); |
|
37 | - |
|
38 | - var $author; |
|
39 | - var $ref; |
|
40 | - var $date; |
|
41 | - var $duree; |
|
42 | - var $note; |
|
43 | - var $fk_project; |
|
33 | + var $id; |
|
34 | + var $db; |
|
35 | + var $error; |
|
36 | + var $errors=array(); |
|
37 | + |
|
38 | + var $author; |
|
39 | + var $ref; |
|
40 | + var $date; |
|
41 | + var $duree; |
|
42 | + var $note; |
|
43 | + var $fk_project; |
|
44 | 44 | |
45 | 45 | // Les codes actions sont definis dans la table llx_notify_def |
46 | 46 | |
47 | - // codes actions supported are |
|
48 | - public $arrayofnotifsupported = array( |
|
49 | - 'BILL_VALIDATE', |
|
50 | - 'BILL_PAYED', |
|
51 | - 'ORDER_VALIDATE', |
|
52 | - 'PROPAL_VALIDATE', |
|
53 | - 'FICHINTER_VALIDATE', |
|
54 | - 'FICHINTER_ADD_CONTACT', |
|
55 | - 'ORDER_SUPPLIER_VALIDATE', |
|
56 | - 'ORDER_SUPPLIER_APPROVE', |
|
57 | - 'ORDER_SUPPLIER_REFUSE', |
|
58 | - 'SHIPPING_VALIDATE' |
|
59 | - ); |
|
47 | + // codes actions supported are |
|
48 | + public $arrayofnotifsupported = array( |
|
49 | + 'BILL_VALIDATE', |
|
50 | + 'BILL_PAYED', |
|
51 | + 'ORDER_VALIDATE', |
|
52 | + 'PROPAL_VALIDATE', |
|
53 | + 'FICHINTER_VALIDATE', |
|
54 | + 'FICHINTER_ADD_CONTACT', |
|
55 | + 'ORDER_SUPPLIER_VALIDATE', |
|
56 | + 'ORDER_SUPPLIER_APPROVE', |
|
57 | + 'ORDER_SUPPLIER_REFUSE', |
|
58 | + 'SHIPPING_VALIDATE' |
|
59 | + ); |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
62 | + /** |
|
63 | 63 | * Constructor |
64 | 64 | * |
65 | 65 | * @param DoliDB $db Database handler |
66 | - */ |
|
67 | - function __construct($db) |
|
68 | - { |
|
69 | - $this->db = $db; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Return message that say how many notification (and to which email) will occurs on requested event. |
|
75 | - * This is to show confirmation messages before event is recorded. |
|
76 | - * |
|
77 | - * @param string $action Id of action in llx_c_action_trigger |
|
78 | - * @param int $socid Id of third party |
|
79 | - * @param Object $object Object the notification is about |
|
80 | - * @return string Message |
|
81 | - */ |
|
66 | + */ |
|
67 | + function __construct($db) |
|
68 | + { |
|
69 | + $this->db = $db; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Return message that say how many notification (and to which email) will occurs on requested event. |
|
75 | + * This is to show confirmation messages before event is recorded. |
|
76 | + * |
|
77 | + * @param string $action Id of action in llx_c_action_trigger |
|
78 | + * @param int $socid Id of third party |
|
79 | + * @param Object $object Object the notification is about |
|
80 | + * @return string Message |
|
81 | + */ |
|
82 | 82 | function confirmMessage($action,$socid,$object) |
83 | 83 | { |
84 | 84 | global $langs; |
@@ -95,175 +95,175 @@ discard block |
||
95 | 95 | |
96 | 96 | if (is_array($listofnotiftodo)) |
97 | 97 | { |
98 | - $i=0; |
|
99 | - foreach ($listofnotiftodo as $key => $val) |
|
100 | - { |
|
101 | - if ($i) $texte.=', '; |
|
102 | - else $texte.=' ('; |
|
103 | - if ($val['isemailvalid']) $texte.=$val['email']; |
|
104 | - else $texte.=$val['emaildesc']; |
|
105 | - $i++; |
|
106 | - } |
|
107 | - if ($i) $texte.=')'; |
|
98 | + $i=0; |
|
99 | + foreach ($listofnotiftodo as $key => $val) |
|
100 | + { |
|
101 | + if ($i) $texte.=', '; |
|
102 | + else $texte.=' ('; |
|
103 | + if ($val['isemailvalid']) $texte.=$val['email']; |
|
104 | + else $texte.=$val['emaildesc']; |
|
105 | + $i++; |
|
106 | + } |
|
107 | + if ($i) $texte.=')'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $texte; |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Return number of notifications activated for action code (and third party) |
|
115 | - * |
|
116 | - * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
117 | - * @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties |
|
118 | - * @param Object $object Object the notification is about (need it to check threshold value of some notifications) |
|
119 | - * @param int $userid Id of user or 0 for all users or -1 for no users |
|
120 | - * @param array $scope Scope where to search |
|
121 | - * @return array|int <0 if KO, array of notifications to send if OK |
|
122 | - */ |
|
113 | + /** |
|
114 | + * Return number of notifications activated for action code (and third party) |
|
115 | + * |
|
116 | + * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
117 | + * @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties |
|
118 | + * @param Object $object Object the notification is about (need it to check threshold value of some notifications) |
|
119 | + * @param int $userid Id of user or 0 for all users or -1 for no users |
|
120 | + * @param array $scope Scope where to search |
|
121 | + * @return array|int <0 if KO, array of notifications to send if OK |
|
122 | + */ |
|
123 | 123 | function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global')) |
124 | 124 | { |
125 | 125 | global $conf, $user; |
126 | 126 | |
127 | 127 | $error=0; |
128 | - $resarray=array(); |
|
129 | - |
|
130 | - $valueforthreshold = 0; |
|
131 | - if (is_object($object)) $valueforthreshold = $object->total_ht; |
|
132 | - |
|
133 | - if (! $error) |
|
134 | - { |
|
135 | - if ($socid >= 0 && in_array('thirdparty', $scope)) |
|
136 | - { |
|
137 | - $sql = "SELECT a.code, c.email, c.rowid"; |
|
138 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
139 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
140 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
141 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
142 | - $sql.= " WHERE n.fk_contact = c.rowid"; |
|
143 | - $sql.= " AND a.rowid = n.fk_action"; |
|
144 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
145 | - if ($notifcode) |
|
146 | - { |
|
147 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
148 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
149 | - } |
|
150 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
151 | - if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
128 | + $resarray=array(); |
|
129 | + |
|
130 | + $valueforthreshold = 0; |
|
131 | + if (is_object($object)) $valueforthreshold = $object->total_ht; |
|
132 | + |
|
133 | + if (! $error) |
|
134 | + { |
|
135 | + if ($socid >= 0 && in_array('thirdparty', $scope)) |
|
136 | + { |
|
137 | + $sql = "SELECT a.code, c.email, c.rowid"; |
|
138 | + $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
139 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
140 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
141 | + $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
142 | + $sql.= " WHERE n.fk_contact = c.rowid"; |
|
143 | + $sql.= " AND a.rowid = n.fk_action"; |
|
144 | + $sql.= " AND n.fk_soc = s.rowid"; |
|
145 | + if ($notifcode) |
|
146 | + { |
|
147 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
148 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
149 | + } |
|
150 | + $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
151 | + if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
152 | 152 | |
153 | - dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
153 | + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
154 | 154 | |
155 | - $resql = $this->db->query($sql); |
|
156 | - if ($resql) |
|
157 | - { |
|
158 | - $num = $this->db->num_rows($resql); |
|
159 | - $i=0; |
|
160 | - while ($i < $num) |
|
161 | - { |
|
162 | - $obj = $this->db->fetch_object($resql); |
|
163 | - if ($obj) |
|
164 | - { |
|
165 | - $newval2=trim($obj->email); |
|
166 | - $isvalid=isValidEmail($newval2); |
|
167 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
168 | - } |
|
169 | - $i++; |
|
170 | - } |
|
171 | - } |
|
172 | - else |
|
173 | - { |
|
174 | - $error++; |
|
175 | - $this->error=$this->db->lasterror(); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
155 | + $resql = $this->db->query($sql); |
|
156 | + if ($resql) |
|
157 | + { |
|
158 | + $num = $this->db->num_rows($resql); |
|
159 | + $i=0; |
|
160 | + while ($i < $num) |
|
161 | + { |
|
162 | + $obj = $this->db->fetch_object($resql); |
|
163 | + if ($obj) |
|
164 | + { |
|
165 | + $newval2=trim($obj->email); |
|
166 | + $isvalid=isValidEmail($newval2); |
|
167 | + if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
168 | + } |
|
169 | + $i++; |
|
170 | + } |
|
171 | + } |
|
172 | + else |
|
173 | + { |
|
174 | + $error++; |
|
175 | + $this->error=$this->db->lasterror(); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | 179 | |
180 | - if (! $error) |
|
181 | - { |
|
182 | - if ($userid >= 0 && in_array('user', $scope)) |
|
183 | - { |
|
184 | - $sql = "SELECT a.code, c.email, c.rowid"; |
|
185 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
186 | - $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
187 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
188 | - $sql.= " WHERE n.fk_user = c.rowid"; |
|
189 | - $sql.= " AND a.rowid = n.fk_action"; |
|
190 | - if ($notifcode) |
|
191 | - { |
|
192 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
193 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
194 | - } |
|
195 | - $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
196 | - if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
180 | + if (! $error) |
|
181 | + { |
|
182 | + if ($userid >= 0 && in_array('user', $scope)) |
|
183 | + { |
|
184 | + $sql = "SELECT a.code, c.email, c.rowid"; |
|
185 | + $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
186 | + $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
187 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
188 | + $sql.= " WHERE n.fk_user = c.rowid"; |
|
189 | + $sql.= " AND a.rowid = n.fk_action"; |
|
190 | + if ($notifcode) |
|
191 | + { |
|
192 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
193 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
194 | + } |
|
195 | + $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
196 | + if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
197 | 197 | |
198 | - dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
198 | + dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
|
199 | 199 | |
200 | - $resql = $this->db->query($sql); |
|
201 | - if ($resql) |
|
202 | - { |
|
203 | - $num = $this->db->num_rows($resql); |
|
204 | - $i=0; |
|
205 | - while ($i < $num) |
|
206 | - { |
|
207 | - $obj = $this->db->fetch_object($resql); |
|
208 | - if ($obj) |
|
209 | - { |
|
210 | - $newval2=trim($obj->email); |
|
211 | - $isvalid=isValidEmail($newval2); |
|
212 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
213 | - } |
|
214 | - $i++; |
|
215 | - } |
|
216 | - } |
|
217 | - else |
|
218 | - { |
|
219 | - $error++; |
|
220 | - $this->error=$this->db->lasterror(); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
200 | + $resql = $this->db->query($sql); |
|
201 | + if ($resql) |
|
202 | + { |
|
203 | + $num = $this->db->num_rows($resql); |
|
204 | + $i=0; |
|
205 | + while ($i < $num) |
|
206 | + { |
|
207 | + $obj = $this->db->fetch_object($resql); |
|
208 | + if ($obj) |
|
209 | + { |
|
210 | + $newval2=trim($obj->email); |
|
211 | + $isvalid=isValidEmail($newval2); |
|
212 | + if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
213 | + } |
|
214 | + $i++; |
|
215 | + } |
|
216 | + } |
|
217 | + else |
|
218 | + { |
|
219 | + $error++; |
|
220 | + $this->error=$this->db->lasterror(); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | 225 | if (! $error) |
226 | 226 | { |
227 | - if (in_array('global', $scope)) |
|
228 | - { |
|
229 | - // List of notifications enabled for fixed email |
|
230 | - foreach($conf->global as $key => $val) |
|
231 | - { |
|
232 | - if ($notifcode) |
|
233 | - { |
|
234 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
235 | - } |
|
236 | - else |
|
237 | - { |
|
238 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
239 | - } |
|
227 | + if (in_array('global', $scope)) |
|
228 | + { |
|
229 | + // List of notifications enabled for fixed email |
|
230 | + foreach($conf->global as $key => $val) |
|
231 | + { |
|
232 | + if ($notifcode) |
|
233 | + { |
|
234 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
235 | + } |
|
236 | + else |
|
237 | + { |
|
238 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
239 | + } |
|
240 | 240 | |
241 | - $threshold = (float) $reg[1]; |
|
242 | - if ($valueforthreshold < $threshold) continue; |
|
241 | + $threshold = (float) $reg[1]; |
|
242 | + if ($valueforthreshold < $threshold) continue; |
|
243 | 243 | |
244 | - $tmpemail=explode(',',$val); |
|
245 | - foreach($tmpemail as $key2 => $val2) |
|
246 | - { |
|
247 | - $newval2=trim($val2); |
|
248 | - if ($newval2 == '__SUPERVISOREMAIL__') |
|
249 | - { |
|
250 | - if ($user->fk_user > 0) |
|
251 | - { |
|
252 | - $tmpuser=new User($this->db); |
|
253 | - $tmpuser->fetch($user->fk_user); |
|
254 | - if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
255 | - else $newval2=''; |
|
256 | - } |
|
257 | - else $newval2=''; |
|
258 | - } |
|
259 | - if ($newval2) |
|
260 | - { |
|
261 | - $isvalid=isValidEmail($newval2, 0); |
|
262 | - if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
263 | - } |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
244 | + $tmpemail=explode(',',$val); |
|
245 | + foreach($tmpemail as $key2 => $val2) |
|
246 | + { |
|
247 | + $newval2=trim($val2); |
|
248 | + if ($newval2 == '__SUPERVISOREMAIL__') |
|
249 | + { |
|
250 | + if ($user->fk_user > 0) |
|
251 | + { |
|
252 | + $tmpuser=new User($this->db); |
|
253 | + $tmpuser->fetch($user->fk_user); |
|
254 | + if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
255 | + else $newval2=''; |
|
256 | + } |
|
257 | + else $newval2=''; |
|
258 | + } |
|
259 | + if ($newval2) |
|
260 | + { |
|
261 | + $isvalid=isValidEmail($newval2, 0); |
|
262 | + if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
263 | + } |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | if ($error) return -1; |
@@ -272,47 +272,47 @@ discard block |
||
272 | 272 | return $resarray; |
273 | 273 | } |
274 | 274 | |
275 | - /** |
|
276 | - * Check if notification are active for couple action/company. |
|
277 | - * If yes, send mail and save trace into llx_notify. |
|
278 | - * |
|
279 | - * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
280 | - * @param Object $object Object the notification deals on |
|
281 | - * @return int <0 if KO, or number of changes if OK |
|
282 | - */ |
|
283 | - function send($notifcode, $object) |
|
284 | - { |
|
285 | - global $user,$conf,$langs,$mysoc; |
|
286 | - global $hookmanager; |
|
287 | - global $dolibarr_main_url_root; |
|
275 | + /** |
|
276 | + * Check if notification are active for couple action/company. |
|
277 | + * If yes, send mail and save trace into llx_notify. |
|
278 | + * |
|
279 | + * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) |
|
280 | + * @param Object $object Object the notification deals on |
|
281 | + * @return int <0 if KO, or number of changes if OK |
|
282 | + */ |
|
283 | + function send($notifcode, $object) |
|
284 | + { |
|
285 | + global $user,$conf,$langs,$mysoc; |
|
286 | + global $hookmanager; |
|
287 | + global $dolibarr_main_url_root; |
|
288 | 288 | |
289 | 289 | if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
290 | 290 | |
291 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
292 | - if (! is_object($hookmanager)) |
|
293 | - { |
|
294 | - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
295 | - $hookmanager=new HookManager($this->db); |
|
296 | - } |
|
297 | - $hookmanager->initHooks(array('notification')); |
|
291 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
292 | + if (! is_object($hookmanager)) |
|
293 | + { |
|
294 | + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
295 | + $hookmanager=new HookManager($this->db); |
|
296 | + } |
|
297 | + $hookmanager->initHooks(array('notification')); |
|
298 | 298 | |
299 | - dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); |
|
299 | + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); |
|
300 | 300 | |
301 | - $langs->load("other"); |
|
301 | + $langs->load("other"); |
|
302 | 302 | |
303 | 303 | // Define $urlwithroot |
304 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
304 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
305 | 305 | $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
306 | 306 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
307 | 307 | |
308 | 308 | // Define some vars |
309 | - $application = 'Dolibarr'; |
|
310 | - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
311 | - $replyto = $conf->notification->email_from; |
|
312 | - $filename = basename($file); |
|
313 | - $mimefile = dol_mimetype($file); |
|
309 | + $application = 'Dolibarr'; |
|
310 | + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
311 | + $replyto = $conf->notification->email_from; |
|
312 | + $filename = basename($file); |
|
313 | + $mimefile = dol_mimetype($file); |
|
314 | 314 | $object_type = ''; |
315 | - $link = ''; |
|
315 | + $link = ''; |
|
316 | 316 | $num = 0; |
317 | 317 | |
318 | 318 | $oldref=(empty($object->oldref)?$object->ref:$object->oldref); |
@@ -321,56 +321,56 @@ discard block |
||
321 | 321 | // Check notification per third party |
322 | 322 | $sql = "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; |
323 | 323 | $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
324 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
325 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
326 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
327 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
328 | - $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
329 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
330 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
331 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
332 | - $sql .= " AND s.rowid = ".$object->socid; |
|
324 | + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
325 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
326 | + $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
327 | + $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
328 | + $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
329 | + $sql.= " AND n.fk_soc = s.rowid"; |
|
330 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
331 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
332 | + $sql .= " AND s.rowid = ".$object->socid; |
|
333 | 333 | |
334 | 334 | // Check notification per user |
335 | - $sql.= "\nUNION\n"; |
|
336 | - |
|
337 | - $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
338 | - $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
339 | - $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
340 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
341 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
342 | - $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
343 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
344 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
335 | + $sql.= "\nUNION\n"; |
|
336 | + |
|
337 | + $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
338 | + $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
339 | + $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
340 | + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
341 | + $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
342 | + $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
343 | + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
344 | + else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
345 | 345 | |
346 | - $result = $this->db->query($sql); |
|
347 | - if ($result) |
|
348 | - { |
|
349 | - $num = $this->db->num_rows($result); |
|
350 | - |
|
351 | - if ($num > 0) |
|
352 | - { |
|
353 | - $i = 0; |
|
354 | - while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
355 | - { |
|
356 | - $obj = $this->db->fetch_object($result); |
|
357 | - |
|
358 | - $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
|
346 | + $result = $this->db->query($sql); |
|
347 | + if ($result) |
|
348 | + { |
|
349 | + $num = $this->db->num_rows($result); |
|
350 | + |
|
351 | + if ($num > 0) |
|
352 | + { |
|
353 | + $i = 0; |
|
354 | + while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
355 | + { |
|
356 | + $obj = $this->db->fetch_object($result); |
|
357 | + |
|
358 | + $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
|
359 | 359 | $notifcodedefid = $obj->adid; |
360 | 360 | |
361 | - if (dol_strlen($obj->email)) |
|
362 | - { |
|
363 | - // Set output language |
|
364 | - $outputlangs = $langs; |
|
365 | - if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) |
|
366 | - { |
|
367 | - $outputlangs = new Translate('', $conf); |
|
368 | - $outputlangs->setDefaultLang($obj->default_lang); |
|
369 | - } |
|
370 | - |
|
371 | - $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification"); |
|
361 | + if (dol_strlen($obj->email)) |
|
362 | + { |
|
363 | + // Set output language |
|
364 | + $outputlangs = $langs; |
|
365 | + if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) |
|
366 | + { |
|
367 | + $outputlangs = new Translate('', $conf); |
|
368 | + $outputlangs->setDefaultLang($obj->default_lang); |
|
369 | + } |
|
370 | + |
|
371 | + $subject = '['.$mysoc->name.'] '.$outputlangs->transnoentitiesnoconv("DolibarrNotification"); |
|
372 | 372 | |
373 | - switch ($notifcode) { |
|
373 | + switch ($notifcode) { |
|
374 | 374 | case 'BILL_VALIDATE': |
375 | 375 | $link='/compta/facture/card.php?facid='.$object->id; |
376 | 376 | $dir_output = $conf->facture->dir_output; |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
438 | 438 | break; |
439 | 439 | } |
440 | - $ref = dol_sanitizeFileName($newref); |
|
440 | + $ref = dol_sanitizeFileName($newref); |
|
441 | 441 | $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
442 | 442 | if (! dol_is_file($pdf_path)) |
443 | 443 | { |
@@ -449,104 +449,104 @@ discard block |
||
449 | 449 | $filepdf = $pdf_path; |
450 | 450 | } |
451 | 451 | |
452 | - $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
453 | - $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
454 | - $message.= "\n"; |
|
455 | - $message.= $mesg; |
|
456 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
457 | - |
|
458 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
459 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
460 | - if (empty($reshook)) |
|
461 | - { |
|
462 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
463 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
464 | - } |
|
452 | + $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
453 | + $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
454 | + $message.= "\n"; |
|
455 | + $message.= $mesg; |
|
456 | + if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
457 | + |
|
458 | + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
459 | + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
460 | + if (empty($reshook)) |
|
461 | + { |
|
462 | + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
463 | + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
464 | + } |
|
465 | 465 | |
466 | - $mailfile = new CMailFile( |
|
467 | - $subject, |
|
468 | - $sendto, |
|
469 | - $replyto, |
|
470 | - $message, |
|
471 | - array($file), |
|
472 | - array($mimefile), |
|
473 | - array($filename[count($filename)-1]), |
|
474 | - '', |
|
475 | - '', |
|
476 | - 0, |
|
477 | - -1 |
|
478 | - ); |
|
479 | - |
|
480 | - if ($mailfile->sendfile()) |
|
481 | - { |
|
482 | - if ($obj->type_target == 'touserid') { |
|
483 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
|
484 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
466 | + $mailfile = new CMailFile( |
|
467 | + $subject, |
|
468 | + $sendto, |
|
469 | + $replyto, |
|
470 | + $message, |
|
471 | + array($file), |
|
472 | + array($mimefile), |
|
473 | + array($filename[count($filename)-1]), |
|
474 | + '', |
|
475 | + '', |
|
476 | + 0, |
|
477 | + -1 |
|
478 | + ); |
|
479 | + |
|
480 | + if ($mailfile->sendfile()) |
|
481 | + { |
|
482 | + if ($obj->type_target == 'touserid') { |
|
483 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
|
484 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
485 | 485 | |
486 | - } |
|
487 | - else { |
|
488 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
|
489 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
486 | + } |
|
487 | + else { |
|
488 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
|
489 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
490 | 490 | |
491 | - } |
|
492 | - if (! $this->db->query($sql)) |
|
493 | - { |
|
494 | - dol_print_error($this->db); |
|
495 | - } |
|
496 | - } |
|
497 | - else |
|
491 | + } |
|
492 | + if (! $this->db->query($sql)) |
|
493 | + { |
|
494 | + dol_print_error($this->db); |
|
495 | + } |
|
496 | + } |
|
497 | + else |
|
498 | 498 | { |
499 | 499 | $error++; |
500 | - $this->errors[]=$mailfile->error; |
|
501 | - } |
|
502 | - } |
|
503 | - else |
|
504 | - { |
|
505 | - dol_syslog("No notification sent for ".$sendto." because email is empty"); |
|
506 | - } |
|
507 | - $i++; |
|
508 | - } |
|
509 | - } |
|
510 | - else |
|
500 | + $this->errors[]=$mailfile->error; |
|
501 | + } |
|
502 | + } |
|
503 | + else |
|
504 | + { |
|
505 | + dol_syslog("No notification sent for ".$sendto." because email is empty"); |
|
506 | + } |
|
507 | + $i++; |
|
508 | + } |
|
509 | + } |
|
510 | + else |
|
511 | 511 | { |
512 | - dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid); |
|
512 | + dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid); |
|
513 | 513 | } |
514 | - } |
|
515 | - else |
|
516 | - { |
|
517 | - $error++; |
|
518 | - $this->errors[]=$this->db->lasterror(); |
|
519 | - dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR); |
|
520 | - return -1; |
|
521 | - } |
|
522 | - |
|
523 | - // Check notification using fixed email |
|
524 | - if (! $error) |
|
525 | - { |
|
526 | - foreach($conf->global as $key => $val) |
|
527 | - { |
|
528 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
529 | - |
|
530 | - $threshold = (float) $reg[1]; |
|
531 | - if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
|
532 | - { |
|
533 | - dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification"); |
|
534 | - continue; |
|
535 | - } |
|
536 | - |
|
537 | - $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
538 | - |
|
539 | - $sendto = $conf->global->$param; |
|
540 | - $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
|
541 | - if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); |
|
542 | - |
|
543 | - $object_type = ''; |
|
544 | - $link = ''; |
|
545 | - $num++; |
|
546 | - |
|
547 | - $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification"); |
|
548 | - |
|
549 | - switch ($notifcode) { |
|
514 | + } |
|
515 | + else |
|
516 | + { |
|
517 | + $error++; |
|
518 | + $this->errors[]=$this->db->lasterror(); |
|
519 | + dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR); |
|
520 | + return -1; |
|
521 | + } |
|
522 | + |
|
523 | + // Check notification using fixed email |
|
524 | + if (! $error) |
|
525 | + { |
|
526 | + foreach($conf->global as $key => $val) |
|
527 | + { |
|
528 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
529 | + |
|
530 | + $threshold = (float) $reg[1]; |
|
531 | + if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
|
532 | + { |
|
533 | + dol_syslog("A notification is requested for notifcode = ".$notifcode." but amount = ".$object->total_ht." so lower than threshold = ".$threshold.". We discard this notification"); |
|
534 | + continue; |
|
535 | + } |
|
536 | + |
|
537 | + $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
538 | + |
|
539 | + $sendto = $conf->global->$param; |
|
540 | + $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
|
541 | + if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); |
|
542 | + |
|
543 | + $object_type = ''; |
|
544 | + $link = ''; |
|
545 | + $num++; |
|
546 | + |
|
547 | + $subject = '['.$mysoc->name.'] '.$langs->transnoentitiesnoconv("DolibarrNotification"); |
|
548 | + |
|
549 | + switch ($notifcode) { |
|
550 | 550 | case 'BILL_VALIDATE': |
551 | 551 | $link='/compta/facture/card.php?facid='.$object->id; |
552 | 552 | $dir_output = $conf->facture->dir_output; |
@@ -571,26 +571,26 @@ discard block |
||
571 | 571 | $object_type = 'propal'; |
572 | 572 | $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref); |
573 | 573 | break; |
574 | - case 'FICHINTER_ADD_CONTACT': |
|
575 | - $link='/fichinter/card.php?id='.$object->id; |
|
576 | - $dir_output = $conf->facture->dir_output; |
|
577 | - $object_type = 'ficheinter'; |
|
578 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref); |
|
579 | - break; |
|
574 | + case 'FICHINTER_ADD_CONTACT': |
|
575 | + $link='/fichinter/card.php?id='.$object->id; |
|
576 | + $dir_output = $conf->facture->dir_output; |
|
577 | + $object_type = 'ficheinter'; |
|
578 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref); |
|
579 | + break; |
|
580 | 580 | case 'FICHINTER_VALIDATE': |
581 | 581 | $link='/fichinter/card.php?id='.$object->id; |
582 | 582 | $dir_output = $conf->facture->dir_output; |
583 | 583 | $object_type = 'ficheinter'; |
584 | 584 | $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref); |
585 | 585 | break; |
586 | - case 'ORDER_SUPPLIER_VALIDATE': |
|
587 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
588 | - $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
|
589 | - $object_type = 'order_supplier'; |
|
590 | - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
591 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs)); |
|
592 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
593 | - break; |
|
586 | + case 'ORDER_SUPPLIER_VALIDATE': |
|
587 | + $link='/fourn/commande/card.php?id='.$object->id; |
|
588 | + $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
|
589 | + $object_type = 'order_supplier'; |
|
590 | + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
|
591 | + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs)); |
|
592 | + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
593 | + break; |
|
594 | 594 | case 'ORDER_SUPPLIER_APPROVE': |
595 | 595 | $link='/fourn/commande/card.php?id='.$object->id; |
596 | 596 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
@@ -633,73 +633,73 @@ discard block |
||
633 | 633 | $filepdf = $pdf_path; |
634 | 634 | } |
635 | 635 | |
636 | - $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
637 | - $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
638 | - $message.= "\n"; |
|
639 | - $message.= $mesg; |
|
640 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
641 | - |
|
642 | - // Replace keyword __SUPERVISOREMAIL__ |
|
643 | - if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
|
644 | - { |
|
645 | - $newval=''; |
|
646 | - if ($user->fk_user > 0) |
|
647 | - { |
|
648 | - $supervisoruser=new User($this->db); |
|
649 | - $supervisoruser->fetch($user->fk_user); |
|
650 | - if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
651 | - } |
|
652 | - dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
|
653 | - $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
|
654 | - $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string |
|
655 | - $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string |
|
656 | - } |
|
657 | - |
|
658 | - if ($sendto) |
|
659 | - { |
|
660 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
661 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
662 | - if (empty($reshook)) |
|
663 | - { |
|
664 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
665 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
666 | - } |
|
636 | + $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
637 | + $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
638 | + $message.= "\n"; |
|
639 | + $message.= $mesg; |
|
640 | + if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
641 | + |
|
642 | + // Replace keyword __SUPERVISOREMAIL__ |
|
643 | + if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
|
644 | + { |
|
645 | + $newval=''; |
|
646 | + if ($user->fk_user > 0) |
|
647 | + { |
|
648 | + $supervisoruser=new User($this->db); |
|
649 | + $supervisoruser->fetch($user->fk_user); |
|
650 | + if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
651 | + } |
|
652 | + dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
|
653 | + $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
|
654 | + $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string |
|
655 | + $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string |
|
656 | + } |
|
657 | + |
|
658 | + if ($sendto) |
|
659 | + { |
|
660 | + $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
661 | + $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
662 | + if (empty($reshook)) |
|
663 | + { |
|
664 | + if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
665 | + if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
666 | + } |
|
667 | 667 | |
668 | - $mailfile = new CMailFile( |
|
669 | - $subject, |
|
670 | - $sendto, |
|
671 | - $replyto, |
|
672 | - $message, |
|
673 | - array($file), |
|
674 | - array($mimefile), |
|
675 | - array($filename[count($filename)-1]), |
|
676 | - '', |
|
677 | - '', |
|
678 | - 0, |
|
679 | - -1 |
|
680 | - ); |
|
681 | - |
|
682 | - if ($mailfile->sendfile()) |
|
683 | - { |
|
684 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
|
685 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
686 | - if (! $this->db->query($sql)) |
|
687 | - { |
|
688 | - dol_print_error($this->db); |
|
689 | - } |
|
690 | - } |
|
691 | - else |
|
692 | - { |
|
693 | - $error++; |
|
694 | - $this->errors[]=$mailfile->error; |
|
695 | - } |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
668 | + $mailfile = new CMailFile( |
|
669 | + $subject, |
|
670 | + $sendto, |
|
671 | + $replyto, |
|
672 | + $message, |
|
673 | + array($file), |
|
674 | + array($mimefile), |
|
675 | + array($filename[count($filename)-1]), |
|
676 | + '', |
|
677 | + '', |
|
678 | + 0, |
|
679 | + -1 |
|
680 | + ); |
|
681 | + |
|
682 | + if ($mailfile->sendfile()) |
|
683 | + { |
|
684 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
|
685 | + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
686 | + if (! $this->db->query($sql)) |
|
687 | + { |
|
688 | + dol_print_error($this->db); |
|
689 | + } |
|
690 | + } |
|
691 | + else |
|
692 | + { |
|
693 | + $error++; |
|
694 | + $this->errors[]=$mailfile->error; |
|
695 | + } |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | 699 | |
700 | 700 | if (! $error) return $num; |
701 | 701 | else return -1 * $error; |
702 | - } |
|
702 | + } |
|
703 | 703 | |
704 | 704 | } |
705 | 705 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * \ingroup notification |
23 | 23 | * \brief File of class to manage notifications |
24 | 24 | */ |
25 | -require_once DOL_DOCUMENT_ROOT .'/core/class/CMailFile.class.php'; |
|
25 | +require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
26 | 26 | |
27 | 27 | |
28 | 28 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | var $id; |
34 | 34 | var $db; |
35 | 35 | var $error; |
36 | - var $errors=array(); |
|
36 | + var $errors = array(); |
|
37 | 37 | |
38 | 38 | var $author; |
39 | 39 | var $ref; |
@@ -79,32 +79,32 @@ discard block |
||
79 | 79 | * @param Object $object Object the notification is about |
80 | 80 | * @return string Message |
81 | 81 | */ |
82 | - function confirmMessage($action,$socid,$object) |
|
82 | + function confirmMessage($action, $socid, $object) |
|
83 | 83 | { |
84 | 84 | global $langs; |
85 | 85 | $langs->load("mails"); |
86 | 86 | |
87 | - $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); |
|
87 | + $listofnotiftodo = $this->getNotificationsArray($action, $socid, $object, 0); |
|
88 | 88 | |
89 | - $nb=-1; |
|
90 | - if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); |
|
91 | - if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
92 | - if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
93 | - if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
94 | - if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); |
|
89 | + $nb = -1; |
|
90 | + if (is_array($listofnotiftodo)) $nb = count($listofnotiftodo); |
|
91 | + if ($nb < 0) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
92 | + if ($nb == 0) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
93 | + if ($nb == 1) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
94 | + if ($nb >= 2) $texte = img_object($langs->trans("Notifications"), 'email').' '.$langs->trans("SomeNotificationsWillBeSent", $nb); |
|
95 | 95 | |
96 | 96 | if (is_array($listofnotiftodo)) |
97 | 97 | { |
98 | - $i=0; |
|
98 | + $i = 0; |
|
99 | 99 | foreach ($listofnotiftodo as $key => $val) |
100 | 100 | { |
101 | - if ($i) $texte.=', '; |
|
102 | - else $texte.=' ('; |
|
103 | - if ($val['isemailvalid']) $texte.=$val['email']; |
|
104 | - else $texte.=$val['emaildesc']; |
|
101 | + if ($i) $texte .= ', '; |
|
102 | + else $texte .= ' ('; |
|
103 | + if ($val['isemailvalid']) $texte .= $val['email']; |
|
104 | + else $texte .= $val['emaildesc']; |
|
105 | 105 | $i++; |
106 | 106 | } |
107 | - if ($i) $texte.=')'; |
|
107 | + if ($i) $texte .= ')'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return $texte; |
@@ -120,35 +120,35 @@ discard block |
||
120 | 120 | * @param array $scope Scope where to search |
121 | 121 | * @return array|int <0 if KO, array of notifications to send if OK |
122 | 122 | */ |
123 | - function getNotificationsArray($notifcode, $socid=0, $object=null, $userid=0, $scope=array('thirdparty', 'user', 'global')) |
|
123 | + function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global')) |
|
124 | 124 | { |
125 | 125 | global $conf, $user; |
126 | 126 | |
127 | - $error=0; |
|
128 | - $resarray=array(); |
|
127 | + $error = 0; |
|
128 | + $resarray = array(); |
|
129 | 129 | |
130 | 130 | $valueforthreshold = 0; |
131 | 131 | if (is_object($object)) $valueforthreshold = $object->total_ht; |
132 | 132 | |
133 | - if (! $error) |
|
133 | + if (!$error) |
|
134 | 134 | { |
135 | 135 | if ($socid >= 0 && in_array('thirdparty', $scope)) |
136 | 136 | { |
137 | 137 | $sql = "SELECT a.code, c.email, c.rowid"; |
138 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
139 | - $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
140 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
141 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
142 | - $sql.= " WHERE n.fk_contact = c.rowid"; |
|
143 | - $sql.= " AND a.rowid = n.fk_action"; |
|
144 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
138 | + $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
139 | + $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
140 | + $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
141 | + $sql .= " ".MAIN_DB_PREFIX."societe as s"; |
|
142 | + $sql .= " WHERE n.fk_contact = c.rowid"; |
|
143 | + $sql .= " AND a.rowid = n.fk_action"; |
|
144 | + $sql .= " AND n.fk_soc = s.rowid"; |
|
145 | 145 | if ($notifcode) |
146 | 146 | { |
147 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
148 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
147 | + if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage |
|
148 | + else $sql .= " AND a.code = '".$notifcode."'"; // New usage |
|
149 | 149 | } |
150 | - $sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
151 | - if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
150 | + $sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
151 | + if ($socid > 0) $sql .= " AND s.rowid = ".$socid; |
|
152 | 152 | |
153 | 153 | dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
154 | 154 | |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | if ($resql) |
157 | 157 | { |
158 | 158 | $num = $this->db->num_rows($resql); |
159 | - $i=0; |
|
159 | + $i = 0; |
|
160 | 160 | while ($i < $num) |
161 | 161 | { |
162 | 162 | $obj = $this->db->fetch_object($resql); |
163 | 163 | if ($obj) |
164 | 164 | { |
165 | - $newval2=trim($obj->email); |
|
166 | - $isvalid=isValidEmail($newval2); |
|
165 | + $newval2 = trim($obj->email); |
|
166 | + $isvalid = isValidEmail($newval2); |
|
167 | 167 | if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
168 | 168 | } |
169 | 169 | $i++; |
@@ -172,28 +172,28 @@ discard block |
||
172 | 172 | else |
173 | 173 | { |
174 | 174 | $error++; |
175 | - $this->error=$this->db->lasterror(); |
|
175 | + $this->error = $this->db->lasterror(); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | - if (! $error) |
|
180 | + if (!$error) |
|
181 | 181 | { |
182 | 182 | if ($userid >= 0 && in_array('user', $scope)) |
183 | 183 | { |
184 | 184 | $sql = "SELECT a.code, c.email, c.rowid"; |
185 | - $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
186 | - $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
187 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
188 | - $sql.= " WHERE n.fk_user = c.rowid"; |
|
189 | - $sql.= " AND a.rowid = n.fk_action"; |
|
185 | + $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; |
|
186 | + $sql .= " ".MAIN_DB_PREFIX."user as c,"; |
|
187 | + $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a"; |
|
188 | + $sql .= " WHERE n.fk_user = c.rowid"; |
|
189 | + $sql .= " AND a.rowid = n.fk_action"; |
|
190 | 190 | if ($notifcode) |
191 | 191 | { |
192 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
193 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
192 | + if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage |
|
193 | + else $sql .= " AND a.code = '".$notifcode."'"; // New usage |
|
194 | 194 | } |
195 | - $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
196 | - if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
195 | + $sql .= " AND c.entity IN (".getEntity('user').")"; |
|
196 | + if ($userid > 0) $sql .= " AND c.rowid = ".$userid; |
|
197 | 197 | |
198 | 198 | dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
199 | 199 | |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | if ($resql) |
202 | 202 | { |
203 | 203 | $num = $this->db->num_rows($resql); |
204 | - $i=0; |
|
204 | + $i = 0; |
|
205 | 205 | while ($i < $num) |
206 | 206 | { |
207 | 207 | $obj = $this->db->fetch_object($resql); |
208 | 208 | if ($obj) |
209 | 209 | { |
210 | - $newval2=trim($obj->email); |
|
211 | - $isvalid=isValidEmail($newval2); |
|
210 | + $newval2 = trim($obj->email); |
|
211 | + $isvalid = isValidEmail($newval2); |
|
212 | 212 | if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
213 | 213 | } |
214 | 214 | $i++; |
@@ -217,49 +217,49 @@ discard block |
||
217 | 217 | else |
218 | 218 | { |
219 | 219 | $error++; |
220 | - $this->error=$this->db->lasterror(); |
|
220 | + $this->error = $this->db->lasterror(); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | - if (! $error) |
|
225 | + if (!$error) |
|
226 | 226 | { |
227 | 227 | if (in_array('global', $scope)) |
228 | 228 | { |
229 | 229 | // List of notifications enabled for fixed email |
230 | - foreach($conf->global as $key => $val) |
|
230 | + foreach ($conf->global as $key => $val) |
|
231 | 231 | { |
232 | 232 | if ($notifcode) |
233 | 233 | { |
234 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
234 | + if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
235 | 235 | } |
236 | 236 | else |
237 | 237 | { |
238 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
238 | + if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | $threshold = (float) $reg[1]; |
242 | 242 | if ($valueforthreshold < $threshold) continue; |
243 | 243 | |
244 | - $tmpemail=explode(',',$val); |
|
245 | - foreach($tmpemail as $key2 => $val2) |
|
244 | + $tmpemail = explode(',', $val); |
|
245 | + foreach ($tmpemail as $key2 => $val2) |
|
246 | 246 | { |
247 | - $newval2=trim($val2); |
|
247 | + $newval2 = trim($val2); |
|
248 | 248 | if ($newval2 == '__SUPERVISOREMAIL__') |
249 | 249 | { |
250 | 250 | if ($user->fk_user > 0) |
251 | 251 | { |
252 | - $tmpuser=new User($this->db); |
|
252 | + $tmpuser = new User($this->db); |
|
253 | 253 | $tmpuser->fetch($user->fk_user); |
254 | - if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
255 | - else $newval2=''; |
|
254 | + if ($tmpuser->email) $newval2 = trim($tmpuser->email); |
|
255 | + else $newval2 = ''; |
|
256 | 256 | } |
257 | - else $newval2=''; |
|
257 | + else $newval2 = ''; |
|
258 | 258 | } |
259 | 259 | if ($newval2) |
260 | 260 | { |
261 | - $isvalid=isValidEmail($newval2, 0); |
|
262 | - if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
261 | + $isvalid = isValidEmail($newval2, 0); |
|
262 | + if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 | } |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | */ |
283 | 283 | function send($notifcode, $object) |
284 | 284 | { |
285 | - global $user,$conf,$langs,$mysoc; |
|
285 | + global $user, $conf, $langs, $mysoc; |
|
286 | 286 | global $hookmanager; |
287 | 287 | global $dolibarr_main_url_root; |
288 | 288 | |
289 | - if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
|
289 | + if (!in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
|
290 | 290 | |
291 | 291 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
292 | - if (! is_object($hookmanager)) |
|
292 | + if (!is_object($hookmanager)) |
|
293 | 293 | { |
294 | 294 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
295 | - $hookmanager=new HookManager($this->db); |
|
295 | + $hookmanager = new HookManager($this->db); |
|
296 | 296 | } |
297 | 297 | $hookmanager->initHooks(array('notification')); |
298 | 298 | |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | $langs->load("other"); |
302 | 302 | |
303 | 303 | // Define $urlwithroot |
304 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
305 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
304 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
305 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
306 | 306 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
307 | 307 | |
308 | 308 | // Define some vars |
309 | 309 | $application = 'Dolibarr'; |
310 | - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
310 | + if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
311 | 311 | $replyto = $conf->notification->email_from; |
312 | 312 | $filename = basename($file); |
313 | 313 | $mimefile = dol_mimetype($file); |
@@ -315,33 +315,33 @@ discard block |
||
315 | 315 | $link = ''; |
316 | 316 | $num = 0; |
317 | 317 | |
318 | - $oldref=(empty($object->oldref)?$object->ref:$object->oldref); |
|
319 | - $newref=(empty($object->newref)?$object->ref:$object->newref); |
|
318 | + $oldref = (empty($object->oldref) ? $object->ref : $object->oldref); |
|
319 | + $newref = (empty($object->newref) ? $object->ref : $object->newref); |
|
320 | 320 | |
321 | 321 | // Check notification per third party |
322 | 322 | $sql = "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; |
323 | - $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
324 | - $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
325 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
326 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
327 | - $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
328 | - $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
329 | - $sql.= " AND n.fk_soc = s.rowid"; |
|
330 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
331 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
323 | + $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
324 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
325 | + $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
326 | + $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
327 | + $sql .= " ".MAIN_DB_PREFIX."societe as s"; |
|
328 | + $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
|
329 | + $sql .= " AND n.fk_soc = s.rowid"; |
|
330 | + if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage |
|
331 | + else $sql .= " AND a.code = '".$notifcode."'"; // New usage |
|
332 | 332 | $sql .= " AND s.rowid = ".$object->socid; |
333 | 333 | |
334 | 334 | // Check notification per user |
335 | - $sql.= "\nUNION\n"; |
|
336 | - |
|
337 | - $sql.= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
338 | - $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
339 | - $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
340 | - $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
341 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
342 | - $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
343 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
344 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
335 | + $sql .= "\nUNION\n"; |
|
336 | + |
|
337 | + $sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
|
338 | + $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; |
|
339 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as c,"; |
|
340 | + $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
341 | + $sql .= " ".MAIN_DB_PREFIX."notify_def as n"; |
|
342 | + $sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
|
343 | + if (is_numeric($notifcode)) $sql .= " AND n.fk_action = ".$notifcode; // Old usage |
|
344 | + else $sql .= " AND a.code = '".$notifcode."'"; // New usage |
|
345 | 345 | |
346 | 346 | $result = $this->db->query($sql); |
347 | 347 | if ($result) |
@@ -351,11 +351,11 @@ discard block |
||
351 | 351 | if ($num > 0) |
352 | 352 | { |
353 | 353 | $i = 0; |
354 | - while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
354 | + while ($i < $num && !$error) // For each notification couple defined (third party/actioncode) |
|
355 | 355 | { |
356 | 356 | $obj = $this->db->fetch_object($result); |
357 | 357 | |
358 | - $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
|
358 | + $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">"; |
|
359 | 359 | $notifcodedefid = $obj->adid; |
360 | 360 | |
361 | 361 | if (dol_strlen($obj->email)) |
@@ -372,74 +372,74 @@ discard block |
||
372 | 372 | |
373 | 373 | switch ($notifcode) { |
374 | 374 | case 'BILL_VALIDATE': |
375 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
375 | + $link = '/compta/facture/card.php?facid='.$object->id; |
|
376 | 376 | $dir_output = $conf->facture->dir_output; |
377 | 377 | $object_type = 'facture'; |
378 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref); |
|
378 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); |
|
379 | 379 | break; |
380 | 380 | case 'BILL_PAYED': |
381 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
381 | + $link = '/compta/facture/card.php?facid='.$object->id; |
|
382 | 382 | $dir_output = $conf->facture->dir_output; |
383 | 383 | $object_type = 'facture'; |
384 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref); |
|
384 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $newref); |
|
385 | 385 | break; |
386 | 386 | case 'ORDER_VALIDATE': |
387 | - $link='/commande/card.php?id='.$object->id; |
|
387 | + $link = '/commande/card.php?id='.$object->id; |
|
388 | 388 | $dir_output = $conf->commande->dir_output; |
389 | 389 | $object_type = 'order'; |
390 | - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref); |
|
390 | + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); |
|
391 | 391 | break; |
392 | 392 | case 'PROPAL_VALIDATE': |
393 | - $link='/comm/propal/card.php?id='.$object->id; |
|
393 | + $link = '/comm/propal/card.php?id='.$object->id; |
|
394 | 394 | $dir_output = $conf->propal->dir_output; |
395 | 395 | $object_type = 'propal'; |
396 | - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref); |
|
396 | + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); |
|
397 | 397 | break; |
398 | 398 | case 'FICHINTER_ADD_CONTACT': |
399 | - $link='/fichinter/card.php?id='.$object->id; |
|
399 | + $link = '/fichinter/card.php?id='.$object->id; |
|
400 | 400 | $dir_output = $conf->facture->dir_output; |
401 | 401 | $object_type = 'ficheinter'; |
402 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$object->ref); |
|
402 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $object->ref); |
|
403 | 403 | break; |
404 | 404 | case 'FICHINTER_VALIDATE': |
405 | - $link='/fichinter/card.php?id='.$object->id; |
|
405 | + $link = '/fichinter/card.php?id='.$object->id; |
|
406 | 406 | $dir_output = $conf->facture->dir_output; |
407 | 407 | $object_type = 'ficheinter'; |
408 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); |
|
408 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $object->ref); |
|
409 | 409 | break; |
410 | 410 | case 'ORDER_SUPPLIER_VALIDATE': |
411 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
411 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
412 | 412 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
413 | 413 | $object_type = 'order_supplier'; |
414 | 414 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
415 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$object->ref,$user->getFullName($langs)); |
|
416 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
415 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $object->ref, $user->getFullName($langs)); |
|
416 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
417 | 417 | break; |
418 | 418 | case 'ORDER_SUPPLIER_APPROVE': |
419 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
419 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
420 | 420 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
421 | 421 | $object_type = 'order_supplier'; |
422 | 422 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
423 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs)); |
|
424 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
423 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); |
|
424 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
425 | 425 | break; |
426 | 426 | case 'ORDER_SUPPLIER_REFUSE': |
427 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
427 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
428 | 428 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
429 | 429 | $object_type = 'order_supplier'; |
430 | 430 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
431 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs)); |
|
432 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
431 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); |
|
432 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
433 | 433 | break; |
434 | 434 | case 'SHIPPING_VALIDATE': |
435 | 435 | $dir_output = $conf->expedition->dir_output.'/sending/'; |
436 | 436 | $object_type = 'order_supplier'; |
437 | - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
437 | + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); |
|
438 | 438 | break; |
439 | 439 | } |
440 | 440 | $ref = dol_sanitizeFileName($newref); |
441 | 441 | $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
442 | - if (! dol_is_file($pdf_path)) |
|
442 | + if (!dol_is_file($pdf_path)) |
|
443 | 443 | { |
444 | 444 | // We can't add PDF as it is not generated yet. |
445 | 445 | $filepdf = ''; |
@@ -449,18 +449,18 @@ discard block |
||
449 | 449 | $filepdf = $pdf_path; |
450 | 450 | } |
451 | 451 | |
452 | - $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
453 | - $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
454 | - $message.= "\n"; |
|
455 | - $message.= $mesg; |
|
456 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
452 | + $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n"; |
|
453 | + $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n"; |
|
454 | + $message .= "\n"; |
|
455 | + $message .= $mesg; |
|
456 | + if ($link) $message = dol_concatdesc($message, $urlwithroot.$link); |
|
457 | 457 | |
458 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
459 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
458 | + $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
459 | + $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
460 | 460 | if (empty($reshook)) |
461 | 461 | { |
462 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
463 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
462 | + if (!empty($hookmanager->resArray['subject'])) $subject .= $hookmanager->resArray['subject']; |
|
463 | + if (!empty($hookmanager->resArray['message'])) $message .= $hookmanager->resArray['message']; |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | $mailfile = new CMailFile( |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | $message, |
471 | 471 | array($file), |
472 | 472 | array($mimefile), |
473 | - array($filename[count($filename)-1]), |
|
473 | + array($filename[count($filename) - 1]), |
|
474 | 474 | '', |
475 | 475 | '', |
476 | 476 | 0, |
@@ -481,15 +481,15 @@ discard block |
||
481 | 481 | { |
482 | 482 | if ($obj->type_target == 'touserid') { |
483 | 483 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
484 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
484 | + $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
485 | 485 | |
486 | 486 | } |
487 | 487 | else { |
488 | 488 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
489 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
489 | + $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
|
490 | 490 | |
491 | 491 | } |
492 | - if (! $this->db->query($sql)) |
|
492 | + if (!$this->db->query($sql)) |
|
493 | 493 | { |
494 | 494 | dol_print_error($this->db); |
495 | 495 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | else |
498 | 498 | { |
499 | 499 | $error++; |
500 | - $this->errors[]=$mailfile->error; |
|
500 | + $this->errors[] = $mailfile->error; |
|
501 | 501 | } |
502 | 502 | } |
503 | 503 | else |
@@ -515,17 +515,17 @@ discard block |
||
515 | 515 | else |
516 | 516 | { |
517 | 517 | $error++; |
518 | - $this->errors[]=$this->db->lasterror(); |
|
518 | + $this->errors[] = $this->db->lasterror(); |
|
519 | 519 | dol_syslog("Failed to get list of notification to send ".$this->db->lasterror(), LOG_ERR); |
520 | 520 | return -1; |
521 | 521 | } |
522 | 522 | |
523 | 523 | // Check notification using fixed email |
524 | - if (! $error) |
|
524 | + if (!$error) |
|
525 | 525 | { |
526 | - foreach($conf->global as $key => $val) |
|
526 | + foreach ($conf->global as $key => $val) |
|
527 | 527 | { |
528 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
528 | + if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
529 | 529 | |
530 | 530 | $threshold = (float) $reg[1]; |
531 | 531 | if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | continue; |
535 | 535 | } |
536 | 536 | |
537 | - $param='NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
537 | + $param = 'NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_'.$reg[1]; |
|
538 | 538 | |
539 | 539 | $sendto = $conf->global->$param; |
540 | 540 | $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
@@ -548,82 +548,82 @@ discard block |
||
548 | 548 | |
549 | 549 | switch ($notifcode) { |
550 | 550 | case 'BILL_VALIDATE': |
551 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
551 | + $link = '/compta/facture/card.php?facid='.$object->id; |
|
552 | 552 | $dir_output = $conf->facture->dir_output; |
553 | 553 | $object_type = 'facture'; |
554 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$newref); |
|
554 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $newref); |
|
555 | 555 | break; |
556 | 556 | case 'BILL_PAYED': |
557 | - $link='/compta/facture/card.php?facid='.$object->id; |
|
557 | + $link = '/compta/facture/card.php?facid='.$object->id; |
|
558 | 558 | $dir_output = $conf->facture->dir_output; |
559 | 559 | $object_type = 'facture'; |
560 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed",$newref); |
|
560 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $newref); |
|
561 | 561 | break; |
562 | 562 | case 'ORDER_VALIDATE': |
563 | - $link='/commande/card.php?id='.$object->id; |
|
563 | + $link = '/commande/card.php?id='.$object->id; |
|
564 | 564 | $dir_output = $conf->commande->dir_output; |
565 | 565 | $object_type = 'order'; |
566 | - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$newref); |
|
566 | + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $newref); |
|
567 | 567 | break; |
568 | 568 | case 'PROPAL_VALIDATE': |
569 | - $link='/comm/propal/card.php?id='.$object->id; |
|
569 | + $link = '/comm/propal/card.php?id='.$object->id; |
|
570 | 570 | $dir_output = $conf->propal->dir_output; |
571 | 571 | $object_type = 'propal'; |
572 | - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$newref); |
|
572 | + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $newref); |
|
573 | 573 | break; |
574 | 574 | case 'FICHINTER_ADD_CONTACT': |
575 | - $link='/fichinter/card.php?id='.$object->id; |
|
575 | + $link = '/fichinter/card.php?id='.$object->id; |
|
576 | 576 | $dir_output = $conf->facture->dir_output; |
577 | 577 | $object_type = 'ficheinter'; |
578 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact",$newref); |
|
578 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $newref); |
|
579 | 579 | break; |
580 | 580 | case 'FICHINTER_VALIDATE': |
581 | - $link='/fichinter/card.php?id='.$object->id; |
|
581 | + $link = '/fichinter/card.php?id='.$object->id; |
|
582 | 582 | $dir_output = $conf->facture->dir_output; |
583 | 583 | $object_type = 'ficheinter'; |
584 | - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$newref); |
|
584 | + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $newref); |
|
585 | 585 | break; |
586 | 586 | case 'ORDER_SUPPLIER_VALIDATE': |
587 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
587 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
588 | 588 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
589 | 589 | $object_type = 'order_supplier'; |
590 | 590 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
591 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy",$newref,$user->getFullName($langs)); |
|
592 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
591 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderValidatedBy", $newref, $user->getFullName($langs)); |
|
592 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
593 | 593 | break; |
594 | 594 | case 'ORDER_SUPPLIER_APPROVE': |
595 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
595 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
596 | 596 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
597 | 597 | $object_type = 'order_supplier'; |
598 | 598 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
599 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs)); |
|
600 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
599 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); |
|
600 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
601 | 601 | break; |
602 | 602 | case 'ORDER_SUPPLIER_APPROVE2': |
603 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
603 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
604 | 604 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
605 | 605 | $object_type = 'order_supplier'; |
606 | 606 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
607 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$newref,$user->getFullName($langs)); |
|
608 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
607 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy", $newref, $user->getFullName($langs)); |
|
608 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
609 | 609 | break; |
610 | 610 | case 'ORDER_SUPPLIER_REFUSE': |
611 | - $link='/fourn/commande/card.php?id='.$object->id; |
|
611 | + $link = '/fourn/commande/card.php?id='.$object->id; |
|
612 | 612 | $dir_output = $conf->fournisseur->dir_output.'/commande/'; |
613 | 613 | $object_type = 'order_supplier'; |
614 | 614 | $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; |
615 | - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$newref,$user->getFullName($langs)); |
|
616 | - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
615 | + $mesg .= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy", $newref, $user->getFullName($langs)); |
|
616 | + $mesg .= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; |
|
617 | 617 | break; |
618 | 618 | case 'SHIPPING_VALIDATE': |
619 | 619 | $dir_output = $conf->expedition->dir_output.'/sending/'; |
620 | 620 | $object_type = 'order_supplier'; |
621 | - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$newref); |
|
621 | + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $newref); |
|
622 | 622 | break; |
623 | 623 | } |
624 | 624 | $ref = dol_sanitizeFileName($newref); |
625 | 625 | $pdf_path = $dir_output."/".$ref."/".$ref.".pdf"; |
626 | - if (! dol_is_file($pdf_path)) |
|
626 | + if (!dol_is_file($pdf_path)) |
|
627 | 627 | { |
628 | 628 | // We can't add PDF as it is not generated yet. |
629 | 629 | $filepdf = ''; |
@@ -633,36 +633,36 @@ discard block |
||
633 | 633 | $filepdf = $pdf_path; |
634 | 634 | } |
635 | 635 | |
636 | - $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification",$application,$mysoc->name)."\n"; |
|
637 | - $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
|
638 | - $message.= "\n"; |
|
639 | - $message.= $mesg; |
|
640 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
636 | + $message = $langs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name)."\n"; |
|
637 | + $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n"; |
|
638 | + $message .= "\n"; |
|
639 | + $message .= $mesg; |
|
640 | + if ($link) $message = dol_concatdesc($message, $urlwithroot.$link); |
|
641 | 641 | |
642 | 642 | // Replace keyword __SUPERVISOREMAIL__ |
643 | 643 | if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
644 | 644 | { |
645 | - $newval=''; |
|
645 | + $newval = ''; |
|
646 | 646 | if ($user->fk_user > 0) |
647 | 647 | { |
648 | - $supervisoruser=new User($this->db); |
|
648 | + $supervisoruser = new User($this->db); |
|
649 | 649 | $supervisoruser->fetch($user->fk_user); |
650 | - if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
650 | + if ($supervisoruser->email) $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
651 | 651 | } |
652 | 652 | dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
653 | 653 | $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
654 | - $sendto = preg_replace('/^[\s,]+/','',$sendto); // Clean start of string |
|
655 | - $sendto = preg_replace('/[\s,]+$/','',$sendto); // Clean end of string |
|
654 | + $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string |
|
655 | + $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string |
|
656 | 656 | } |
657 | 657 | |
658 | 658 | if ($sendto) |
659 | 659 | { |
660 | - $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
661 | - $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
660 | + $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
|
661 | + $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
662 | 662 | if (empty($reshook)) |
663 | 663 | { |
664 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
665 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
664 | + if (!empty($hookmanager->resArray['subject'])) $subject .= $hookmanager->resArray['subject']; |
|
665 | + if (!empty($hookmanager->resArray['message'])) $message .= $hookmanager->resArray['message']; |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | $mailfile = new CMailFile( |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $message, |
673 | 673 | array($file), |
674 | 674 | array($mimefile), |
675 | - array($filename[count($filename)-1]), |
|
675 | + array($filename[count($filename) - 1]), |
|
676 | 676 | '', |
677 | 677 | '', |
678 | 678 | 0, |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | if ($mailfile->sendfile()) |
683 | 683 | { |
684 | 684 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
685 | - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
686 | - if (! $this->db->query($sql)) |
|
685 | + $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid ? $object->socid : 'null').", null, 'email', 'tofixedemail', '".$object_type."', ".$object->id.", '".$this->db->escape($conf->global->$param)."')"; |
|
686 | + if (!$this->db->query($sql)) |
|
687 | 687 | { |
688 | 688 | dol_print_error($this->db); |
689 | 689 | } |
@@ -691,13 +691,13 @@ discard block |
||
691 | 691 | else |
692 | 692 | { |
693 | 693 | $error++; |
694 | - $this->errors[]=$mailfile->error; |
|
694 | + $this->errors[] = $mailfile->error; |
|
695 | 695 | } |
696 | 696 | } |
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - if (! $error) return $num; |
|
700 | + if (!$error) return $num; |
|
701 | 701 | else return -1 * $error; |
702 | 702 | } |
703 | 703 |
@@ -87,24 +87,42 @@ discard block |
||
87 | 87 | $listofnotiftodo=$this->getNotificationsArray($action,$socid,$object,0); |
88 | 88 | |
89 | 89 | $nb=-1; |
90 | - if (is_array($listofnotiftodo)) $nb=count($listofnotiftodo); |
|
91 | - if ($nb < 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
92 | - if ($nb == 0) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
93 | - if ($nb == 1) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
94 | - if ($nb >= 2) $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); |
|
90 | + if (is_array($listofnotiftodo)) { |
|
91 | + $nb=count($listofnotiftodo); |
|
92 | + } |
|
93 | + if ($nb < 0) { |
|
94 | + $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ErrorFailedToGetListOfNotificationsToSend"); |
|
95 | + } |
|
96 | + if ($nb == 0) { |
|
97 | + $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("NoNotificationsWillBeSent"); |
|
98 | + } |
|
99 | + if ($nb == 1) { |
|
100 | + $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("ANotificationsWillBeSent"); |
|
101 | + } |
|
102 | + if ($nb >= 2) { |
|
103 | + $texte=img_object($langs->trans("Notifications"),'email').' '.$langs->trans("SomeNotificationsWillBeSent",$nb); |
|
104 | + } |
|
95 | 105 | |
96 | 106 | if (is_array($listofnotiftodo)) |
97 | 107 | { |
98 | 108 | $i=0; |
99 | 109 | foreach ($listofnotiftodo as $key => $val) |
100 | 110 | { |
101 | - if ($i) $texte.=', '; |
|
102 | - else $texte.=' ('; |
|
103 | - if ($val['isemailvalid']) $texte.=$val['email']; |
|
104 | - else $texte.=$val['emaildesc']; |
|
111 | + if ($i) { |
|
112 | + $texte.=', '; |
|
113 | + } else { |
|
114 | + $texte.=' ('; |
|
115 | + } |
|
116 | + if ($val['isemailvalid']) { |
|
117 | + $texte.=$val['email']; |
|
118 | + } else { |
|
119 | + $texte.=$val['emaildesc']; |
|
120 | + } |
|
105 | 121 | $i++; |
106 | 122 | } |
107 | - if ($i) $texte.=')'; |
|
123 | + if ($i) { |
|
124 | + $texte.=')'; |
|
125 | + } |
|
108 | 126 | } |
109 | 127 | |
110 | 128 | return $texte; |
@@ -128,7 +146,9 @@ discard block |
||
128 | 146 | $resarray=array(); |
129 | 147 | |
130 | 148 | $valueforthreshold = 0; |
131 | - if (is_object($object)) $valueforthreshold = $object->total_ht; |
|
149 | + if (is_object($object)) { |
|
150 | + $valueforthreshold = $object->total_ht; |
|
151 | + } |
|
132 | 152 | |
133 | 153 | if (! $error) |
134 | 154 | { |
@@ -144,11 +164,19 @@ discard block |
||
144 | 164 | $sql.= " AND n.fk_soc = s.rowid"; |
145 | 165 | if ($notifcode) |
146 | 166 | { |
147 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
148 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
167 | + if (is_numeric($notifcode)) { |
|
168 | + $sql.= " AND n.fk_action = ".$notifcode; |
|
169 | + } |
|
170 | + // Old usage |
|
171 | + else { |
|
172 | + $sql.= " AND a.code = '".$notifcode."'"; |
|
173 | + } |
|
174 | + // New usage |
|
149 | 175 | } |
150 | 176 | $sql.= " AND s.entity IN (".getEntity('societe').")"; |
151 | - if ($socid > 0) $sql.= " AND s.rowid = ".$socid; |
|
177 | + if ($socid > 0) { |
|
178 | + $sql.= " AND s.rowid = ".$socid; |
|
179 | + } |
|
152 | 180 | |
153 | 181 | dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
154 | 182 | |
@@ -164,12 +192,13 @@ discard block |
||
164 | 192 | { |
165 | 193 | $newval2=trim($obj->email); |
166 | 194 | $isvalid=isValidEmail($newval2); |
167 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
195 | + if (empty($resarray[$newval2])) { |
|
196 | + $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
197 | + } |
|
168 | 198 | } |
169 | 199 | $i++; |
170 | 200 | } |
171 | - } |
|
172 | - else |
|
201 | + } else |
|
173 | 202 | { |
174 | 203 | $error++; |
175 | 204 | $this->error=$this->db->lasterror(); |
@@ -189,11 +218,19 @@ discard block |
||
189 | 218 | $sql.= " AND a.rowid = n.fk_action"; |
190 | 219 | if ($notifcode) |
191 | 220 | { |
192 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
193 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
221 | + if (is_numeric($notifcode)) { |
|
222 | + $sql.= " AND n.fk_action = ".$notifcode; |
|
223 | + } |
|
224 | + // Old usage |
|
225 | + else { |
|
226 | + $sql.= " AND a.code = '".$notifcode."'"; |
|
227 | + } |
|
228 | + // New usage |
|
194 | 229 | } |
195 | 230 | $sql.= " AND c.entity IN (".getEntity('user').")"; |
196 | - if ($userid > 0) $sql.= " AND c.rowid = ".$userid; |
|
231 | + if ($userid > 0) { |
|
232 | + $sql.= " AND c.rowid = ".$userid; |
|
233 | + } |
|
197 | 234 | |
198 | 235 | dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); |
199 | 236 | |
@@ -209,12 +246,13 @@ discard block |
||
209 | 246 | { |
210 | 247 | $newval2=trim($obj->email); |
211 | 248 | $isvalid=isValidEmail($newval2); |
212 | - if (empty($resarray[$newval2])) $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
249 | + if (empty($resarray[$newval2])) { |
|
250 | + $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); |
|
251 | + } |
|
213 | 252 | } |
214 | 253 | $i++; |
215 | 254 | } |
216 | - } |
|
217 | - else |
|
255 | + } else |
|
218 | 256 | { |
219 | 257 | $error++; |
220 | 258 | $this->error=$this->db->lasterror(); |
@@ -231,15 +269,20 @@ discard block |
||
231 | 269 | { |
232 | 270 | if ($notifcode) |
233 | 271 | { |
234 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
235 | - } |
|
236 | - else |
|
272 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { |
|
273 | + continue; |
|
274 | + } |
|
275 | + } else |
|
237 | 276 | { |
238 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
277 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_.*_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { |
|
278 | + continue; |
|
279 | + } |
|
239 | 280 | } |
240 | 281 | |
241 | 282 | $threshold = (float) $reg[1]; |
242 | - if ($valueforthreshold < $threshold) continue; |
|
283 | + if ($valueforthreshold < $threshold) { |
|
284 | + continue; |
|
285 | + } |
|
243 | 286 | |
244 | 287 | $tmpemail=explode(',',$val); |
245 | 288 | foreach($tmpemail as $key2 => $val2) |
@@ -251,22 +294,30 @@ discard block |
||
251 | 294 | { |
252 | 295 | $tmpuser=new User($this->db); |
253 | 296 | $tmpuser->fetch($user->fk_user); |
254 | - if ($tmpuser->email) $newval2=trim($tmpuser->email); |
|
255 | - else $newval2=''; |
|
297 | + if ($tmpuser->email) { |
|
298 | + $newval2=trim($tmpuser->email); |
|
299 | + } else { |
|
300 | + $newval2=''; |
|
301 | + } |
|
302 | + } else { |
|
303 | + $newval2=''; |
|
256 | 304 | } |
257 | - else $newval2=''; |
|
258 | 305 | } |
259 | 306 | if ($newval2) |
260 | 307 | { |
261 | 308 | $isvalid=isValidEmail($newval2, 0); |
262 | - if (empty($resarray[$newval2])) $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
309 | + if (empty($resarray[$newval2])) { |
|
310 | + $resarray[$newval2]=array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); |
|
311 | + } |
|
263 | 312 | } |
264 | 313 | } |
265 | 314 | } |
266 | 315 | } |
267 | 316 | } |
268 | 317 | |
269 | - if ($error) return -1; |
|
318 | + if ($error) { |
|
319 | + return -1; |
|
320 | + } |
|
270 | 321 | |
271 | 322 | //var_dump($resarray); |
272 | 323 | return $resarray; |
@@ -286,7 +337,9 @@ discard block |
||
286 | 337 | global $hookmanager; |
287 | 338 | global $dolibarr_main_url_root; |
288 | 339 | |
289 | - if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; |
|
340 | + if (! in_array($notifcode, $this->arrayofnotifsupported)) { |
|
341 | + return 0; |
|
342 | + } |
|
290 | 343 | |
291 | 344 | include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
292 | 345 | if (! is_object($hookmanager)) |
@@ -307,7 +360,9 @@ discard block |
||
307 | 360 | |
308 | 361 | // Define some vars |
309 | 362 | $application = 'Dolibarr'; |
310 | - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
363 | + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) { |
|
364 | + $application = $conf->global->MAIN_APPLICATION_TITLE; |
|
365 | + } |
|
311 | 366 | $replyto = $conf->notification->email_from; |
312 | 367 | $filename = basename($file); |
313 | 368 | $mimefile = dol_mimetype($file); |
@@ -327,8 +382,14 @@ discard block |
||
327 | 382 | $sql.= " ".MAIN_DB_PREFIX."societe as s"; |
328 | 383 | $sql.= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
329 | 384 | $sql.= " AND n.fk_soc = s.rowid"; |
330 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
331 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
385 | + if (is_numeric($notifcode)) { |
|
386 | + $sql.= " AND n.fk_action = ".$notifcode; |
|
387 | + } |
|
388 | + // Old usage |
|
389 | + else { |
|
390 | + $sql.= " AND a.code = '".$notifcode."'"; |
|
391 | + } |
|
392 | + // New usage |
|
332 | 393 | $sql .= " AND s.rowid = ".$object->socid; |
333 | 394 | |
334 | 395 | // Check notification per user |
@@ -340,8 +401,14 @@ discard block |
||
340 | 401 | $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
341 | 402 | $sql.= " ".MAIN_DB_PREFIX."notify_def as n"; |
342 | 403 | $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
343 | - if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage |
|
344 | - else $sql.= " AND a.code = '".$notifcode."'"; // New usage |
|
404 | + if (is_numeric($notifcode)) { |
|
405 | + $sql.= " AND n.fk_action = ".$notifcode; |
|
406 | + } |
|
407 | + // Old usage |
|
408 | + else { |
|
409 | + $sql.= " AND a.code = '".$notifcode."'"; |
|
410 | + } |
|
411 | + // New usage |
|
345 | 412 | |
346 | 413 | $result = $this->db->query($sql); |
347 | 414 | if ($result) |
@@ -351,9 +418,11 @@ discard block |
||
351 | 418 | if ($num > 0) |
352 | 419 | { |
353 | 420 | $i = 0; |
354 | - while ($i < $num && ! $error) // For each notification couple defined (third party/actioncode) |
|
421 | + while ($i < $num && ! $error) { |
|
422 | + // For each notification couple defined (third party/actioncode) |
|
355 | 423 | { |
356 | 424 | $obj = $this->db->fetch_object($result); |
425 | + } |
|
357 | 426 | |
358 | 427 | $sendto = dolGetFirstLastname($obj->firstname,$obj->lastname) . " <".$obj->email.">"; |
359 | 428 | $notifcodedefid = $obj->adid; |
@@ -443,8 +512,7 @@ discard block |
||
443 | 512 | { |
444 | 513 | // We can't add PDF as it is not generated yet. |
445 | 514 | $filepdf = ''; |
446 | - } |
|
447 | - else |
|
515 | + } else |
|
448 | 516 | { |
449 | 517 | $filepdf = $pdf_path; |
450 | 518 | } |
@@ -453,14 +521,20 @@ discard block |
||
453 | 521 | $message.= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
454 | 522 | $message.= "\n"; |
455 | 523 | $message.= $mesg; |
456 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
524 | + if ($link) { |
|
525 | + $message=dol_concatdesc($message,$urlwithroot.$link); |
|
526 | + } |
|
457 | 527 | |
458 | 528 | $parameters=array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$file, 'mimefile'=>$mimefile, 'filename'=>$filename); |
459 | 529 | $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
460 | 530 | if (empty($reshook)) |
461 | 531 | { |
462 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
463 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
532 | + if (! empty($hookmanager->resArray['subject'])) { |
|
533 | + $subject.=$hookmanager->resArray['subject']; |
|
534 | + } |
|
535 | + if (! empty($hookmanager->resArray['message'])) { |
|
536 | + $message.=$hookmanager->resArray['message']; |
|
537 | + } |
|
464 | 538 | } |
465 | 539 | |
466 | 540 | $mailfile = new CMailFile( |
@@ -483,8 +557,7 @@ discard block |
||
483 | 557 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
484 | 558 | $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
485 | 559 | |
486 | - } |
|
487 | - else { |
|
560 | + } else { |
|
488 | 561 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
489 | 562 | $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".($object->socid?$object->socid:'null').", ".$obj->cid.", '".$obj->type."', '".$object_type."', '".$obj->type_target."', ".$object->id.", '".$this->db->escape($obj->email)."')"; |
490 | 563 | |
@@ -493,26 +566,22 @@ discard block |
||
493 | 566 | { |
494 | 567 | dol_print_error($this->db); |
495 | 568 | } |
496 | - } |
|
497 | - else |
|
569 | + } else |
|
498 | 570 | { |
499 | 571 | $error++; |
500 | 572 | $this->errors[]=$mailfile->error; |
501 | 573 | } |
502 | - } |
|
503 | - else |
|
574 | + } else |
|
504 | 575 | { |
505 | 576 | dol_syslog("No notification sent for ".$sendto." because email is empty"); |
506 | 577 | } |
507 | 578 | $i++; |
508 | 579 | } |
509 | - } |
|
510 | - else |
|
580 | + } else |
|
511 | 581 | { |
512 | 582 | dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = ".$object->socid); |
513 | 583 | } |
514 | - } |
|
515 | - else |
|
584 | + } else |
|
516 | 585 | { |
517 | 586 | $error++; |
518 | 587 | $this->errors[]=$this->db->lasterror(); |
@@ -525,7 +594,9 @@ discard block |
||
525 | 594 | { |
526 | 595 | foreach($conf->global as $key => $val) |
527 | 596 | { |
528 | - if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) continue; |
|
597 | + if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifcode.'_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { |
|
598 | + continue; |
|
599 | + } |
|
529 | 600 | |
530 | 601 | $threshold = (float) $reg[1]; |
531 | 602 | if (!empty($object->total_ht) && $object->total_ht <= $threshold) |
@@ -538,7 +609,9 @@ discard block |
||
538 | 609 | |
539 | 610 | $sendto = $conf->global->$param; |
540 | 611 | $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
541 | - if ($notifcodedefid <= 0) dol_print_error($this->db, 'Failed to get id from code'); |
|
612 | + if ($notifcodedefid <= 0) { |
|
613 | + dol_print_error($this->db, 'Failed to get id from code'); |
|
614 | + } |
|
542 | 615 | |
543 | 616 | $object_type = ''; |
544 | 617 | $link = ''; |
@@ -627,8 +700,7 @@ discard block |
||
627 | 700 | { |
628 | 701 | // We can't add PDF as it is not generated yet. |
629 | 702 | $filepdf = ''; |
630 | - } |
|
631 | - else |
|
703 | + } else |
|
632 | 704 | { |
633 | 705 | $filepdf = $pdf_path; |
634 | 706 | } |
@@ -637,7 +709,9 @@ discard block |
||
637 | 709 | $message.= $langs->transnoentities("YouReceiveMailBecauseOfNotification2",$application,$mysoc->name)."\n"; |
638 | 710 | $message.= "\n"; |
639 | 711 | $message.= $mesg; |
640 | - if ($link) $message=dol_concatdesc($message,$urlwithroot.$link); |
|
712 | + if ($link) { |
|
713 | + $message=dol_concatdesc($message,$urlwithroot.$link); |
|
714 | + } |
|
641 | 715 | |
642 | 716 | // Replace keyword __SUPERVISOREMAIL__ |
643 | 717 | if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) |
@@ -647,7 +721,9 @@ discard block |
||
647 | 721 | { |
648 | 722 | $supervisoruser=new User($this->db); |
649 | 723 | $supervisoruser->fetch($user->fk_user); |
650 | - if ($supervisoruser->email) $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
724 | + if ($supervisoruser->email) { |
|
725 | + $newval=trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname).' <'.$supervisoruser->email.'>'); |
|
726 | + } |
|
651 | 727 | } |
652 | 728 | dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with ".$newval); |
653 | 729 | $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
@@ -661,8 +737,12 @@ discard block |
||
661 | 737 | $reshook=$hookmanager->executeHooks('formatNotificationMessage',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
662 | 738 | if (empty($reshook)) |
663 | 739 | { |
664 | - if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; |
|
665 | - if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; |
|
740 | + if (! empty($hookmanager->resArray['subject'])) { |
|
741 | + $subject.=$hookmanager->resArray['subject']; |
|
742 | + } |
|
743 | + if (! empty($hookmanager->resArray['message'])) { |
|
744 | + $message.=$hookmanager->resArray['message']; |
|
745 | + } |
|
666 | 746 | } |
667 | 747 | |
668 | 748 | $mailfile = new CMailFile( |
@@ -687,8 +767,7 @@ discard block |
||
687 | 767 | { |
688 | 768 | dol_print_error($this->db); |
689 | 769 | } |
690 | - } |
|
691 | - else |
|
770 | + } else |
|
692 | 771 | { |
693 | 772 | $error++; |
694 | 773 | $this->errors[]=$mailfile->error; |
@@ -697,8 +776,11 @@ discard block |
||
697 | 776 | } |
698 | 777 | } |
699 | 778 | |
700 | - if (! $error) return $num; |
|
701 | - else return -1 * $error; |
|
779 | + if (! $error) { |
|
780 | + return $num; |
|
781 | + } else { |
|
782 | + return -1 * $error; |
|
783 | + } |
|
702 | 784 | } |
703 | 785 | |
704 | 786 | } |