@@ -35,61 +35,61 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function tree_showpad(&$fulltree,$key,$silent=0) |
37 | 37 | { |
38 | - $pos=1; |
|
39 | - |
|
40 | - // Loop on each pos, because we will output an img for each pos |
|
41 | - while ($pos <= $fulltree[$key]['level'] && $fulltree[$key]['level'] > 0) |
|
42 | - { |
|
43 | - // Process for column $pos |
|
44 | - |
|
45 | - $atleastoneofthislevelafter=0; |
|
46 | - $nbofdirinsub=0; |
|
47 | - $nbofdocinsub=0; |
|
48 | - $found=0; |
|
49 | - //print 'x'.$key; |
|
50 | - foreach($fulltree as $key2 => $val2) |
|
51 | - { |
|
38 | + $pos=1; |
|
39 | + |
|
40 | + // Loop on each pos, because we will output an img for each pos |
|
41 | + while ($pos <= $fulltree[$key]['level'] && $fulltree[$key]['level'] > 0) |
|
42 | + { |
|
43 | + // Process for column $pos |
|
44 | + |
|
45 | + $atleastoneofthislevelafter=0; |
|
46 | + $nbofdirinsub=0; |
|
47 | + $nbofdocinsub=0; |
|
48 | + $found=0; |
|
49 | + //print 'x'.$key; |
|
50 | + foreach($fulltree as $key2 => $val2) |
|
51 | + { |
|
52 | 52 | //print "x".$pos." ".$key2." ".$found." ".$fulltree[$key2]['level']; |
53 | - if ($found == 1) // We are after the entry to show |
|
54 | - { |
|
55 | - if ($fulltree[$key2]['level'] > $pos) |
|
56 | - { |
|
57 | - $nbofdirinsub++; |
|
58 | - if (isset($fulltree[$key2]['cachenbofdoc']) && $fulltree[$key2]['cachenbofdoc'] > 0) $nbofdocinsub+=$fulltree[$key2]['cachenbofdoc']; |
|
59 | - } |
|
60 | - if ($fulltree[$key2]['level'] == $pos) |
|
61 | - { |
|
62 | - $atleastoneofthislevelafter=1; |
|
63 | - } |
|
64 | - if ($fulltree[$key2]['level'] <= $pos) |
|
65 | - { |
|
66 | - break; |
|
67 | - } |
|
68 | - } |
|
69 | - if ($key2 == $key) // We found ourself, so now every lower level will be counted |
|
70 | - { |
|
71 | - $found=1; |
|
72 | - } |
|
73 | - } |
|
74 | - //print $atleastoneofthislevelafter; |
|
75 | - |
|
76 | - if (! $silent) |
|
77 | - { |
|
78 | - if ($atleastoneofthislevelafter) |
|
79 | - { |
|
80 | - if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branch.gif'); |
|
81 | - else print img_picto_common('','treemenu/line.gif'); |
|
82 | - } |
|
83 | - else |
|
84 | - { |
|
85 | - if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branchbottom.gif'); |
|
86 | - else print img_picto_common('','treemenu/linebottom.gif'); |
|
87 | - } |
|
88 | - } |
|
89 | - $pos++; |
|
90 | - } |
|
91 | - |
|
92 | - return array($atleastoneofthislevelafter,$nbofdirinsub,$nbofdocinsub); |
|
53 | + if ($found == 1) // We are after the entry to show |
|
54 | + { |
|
55 | + if ($fulltree[$key2]['level'] > $pos) |
|
56 | + { |
|
57 | + $nbofdirinsub++; |
|
58 | + if (isset($fulltree[$key2]['cachenbofdoc']) && $fulltree[$key2]['cachenbofdoc'] > 0) $nbofdocinsub+=$fulltree[$key2]['cachenbofdoc']; |
|
59 | + } |
|
60 | + if ($fulltree[$key2]['level'] == $pos) |
|
61 | + { |
|
62 | + $atleastoneofthislevelafter=1; |
|
63 | + } |
|
64 | + if ($fulltree[$key2]['level'] <= $pos) |
|
65 | + { |
|
66 | + break; |
|
67 | + } |
|
68 | + } |
|
69 | + if ($key2 == $key) // We found ourself, so now every lower level will be counted |
|
70 | + { |
|
71 | + $found=1; |
|
72 | + } |
|
73 | + } |
|
74 | + //print $atleastoneofthislevelafter; |
|
75 | + |
|
76 | + if (! $silent) |
|
77 | + { |
|
78 | + if ($atleastoneofthislevelafter) |
|
79 | + { |
|
80 | + if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branch.gif'); |
|
81 | + else print img_picto_common('','treemenu/line.gif'); |
|
82 | + } |
|
83 | + else |
|
84 | + { |
|
85 | + if ($fulltree[$key]['level'] == $pos) print img_picto_common('','treemenu/branchbottom.gif'); |
|
86 | + else print img_picto_common('','treemenu/linebottom.gif'); |
|
87 | + } |
|
88 | + } |
|
89 | + $pos++; |
|
90 | + } |
|
91 | + |
|
92 | + return array($atleastoneofthislevelafter,$nbofdirinsub,$nbofdocinsub); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | if ($rang == 0 && empty($donoresetalreadyloaded)) $tree_recur_alreadyadded=array(); |
121 | 121 | |
122 | 122 | if ($rang == 0) |
123 | - { |
|
124 | - // Test also done with jstree and dynatree (not able to have <a> inside label) |
|
125 | - print '<script type="text/javascript" language="javascript"> |
|
123 | + { |
|
124 | + // Test also done with jstree and dynatree (not able to have <a> inside label) |
|
125 | + print '<script type="text/javascript" language="javascript"> |
|
126 | 126 | $(document).ready(function(){ |
127 | 127 | $("#'.$iddivjstree.'").treeview({ |
128 | 128 | collapsed: true, |
@@ -136,94 +136,94 @@ discard block |
||
136 | 136 | }) |
137 | 137 | </script>'; |
138 | 138 | |
139 | - print '<ul id="'.$iddivjstree.'">'; |
|
140 | - } |
|
141 | - |
|
142 | - if ($rang > 50) |
|
143 | - { |
|
144 | - return; // Protect against infinite loop. Max 50 depth |
|
145 | - } |
|
146 | - |
|
147 | - //ballayage du tableau |
|
148 | - $sizeoftab=count($tab); |
|
149 | - $ulprinted=0; |
|
150 | - for ($x=0; $x < $sizeoftab; $x++) |
|
151 | - { |
|
152 | - //var_dump($tab[$x]);exit; |
|
153 | - // If an element has $pere for parent |
|
154 | - if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid']) |
|
155 | - { |
|
156 | - //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n"; |
|
157 | - if (empty($ulprinted) && ! empty($pere['rowid'])) |
|
158 | - { |
|
159 | - if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) |
|
160 | - { |
|
161 | - dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING); |
|
162 | - continue; |
|
163 | - } |
|
139 | + print '<ul id="'.$iddivjstree.'">'; |
|
140 | + } |
|
141 | + |
|
142 | + if ($rang > 50) |
|
143 | + { |
|
144 | + return; // Protect against infinite loop. Max 50 depth |
|
145 | + } |
|
146 | + |
|
147 | + //ballayage du tableau |
|
148 | + $sizeoftab=count($tab); |
|
149 | + $ulprinted=0; |
|
150 | + for ($x=0; $x < $sizeoftab; $x++) |
|
151 | + { |
|
152 | + //var_dump($tab[$x]);exit; |
|
153 | + // If an element has $pere for parent |
|
154 | + if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid']) |
|
155 | + { |
|
156 | + //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n"; |
|
157 | + if (empty($ulprinted) && ! empty($pere['rowid'])) |
|
158 | + { |
|
159 | + if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) |
|
160 | + { |
|
161 | + dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING); |
|
162 | + continue; |
|
163 | + } |
|
164 | 164 | |
165 | 165 | print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++; |
166 | - } |
|
167 | - print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>'; |
|
168 | - if ($showfk) |
|
169 | - { |
|
170 | - print '<table class="nobordernopadding centpercent"><tr><td>'; |
|
171 | - print '<strong> '; |
|
172 | - print $tab[$x]['title']; |
|
173 | - print ' (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; |
|
174 | - print '</td><td align="right">'; |
|
175 | - print $tab[$x]['buttons']; |
|
176 | - print '</td></tr></table>'; |
|
177 | - } |
|
178 | - else |
|
179 | - { |
|
180 | - print $tab[$x]['entry']; |
|
181 | - } |
|
182 | - //print ' -> A '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n"; |
|
183 | - $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); |
|
184 | - // And now we search all its sons of lower level |
|
185 | - tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk); |
|
186 | - print '</li>'; |
|
187 | - } |
|
188 | - elseif (! empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu']) |
|
189 | - { |
|
190 | - //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n"; |
|
191 | - if (empty($ulprinted) && ! empty($pere['rowid'])) |
|
192 | - { |
|
193 | - if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) |
|
194 | - { |
|
195 | - dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING); |
|
196 | - //print 'Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.'; |
|
166 | + } |
|
167 | + print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>'; |
|
168 | + if ($showfk) |
|
169 | + { |
|
170 | + print '<table class="nobordernopadding centpercent"><tr><td>'; |
|
171 | + print '<strong> '; |
|
172 | + print $tab[$x]['title']; |
|
173 | + print ' (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; |
|
174 | + print '</td><td align="right">'; |
|
175 | + print $tab[$x]['buttons']; |
|
176 | + print '</td></tr></table>'; |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
180 | + print $tab[$x]['entry']; |
|
181 | + } |
|
182 | + //print ' -> A '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n"; |
|
183 | + $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); |
|
184 | + // And now we search all its sons of lower level |
|
185 | + tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk); |
|
186 | + print '</li>'; |
|
187 | + } |
|
188 | + elseif (! empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu']) |
|
189 | + { |
|
190 | + //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."<br>\n"; |
|
191 | + if (empty($ulprinted) && ! empty($pere['rowid'])) |
|
192 | + { |
|
193 | + if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) |
|
194 | + { |
|
195 | + dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING); |
|
196 | + //print 'Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.'; |
|
197 | 197 | continue; |
198 | - } |
|
199 | - |
|
200 | - print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++; |
|
201 | - } |
|
202 | - print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>'; |
|
203 | - if ($showfk) |
|
204 | - { |
|
205 | - print '<table class="nobordernopadding centpercent"><tr><td>'; |
|
206 | - print '<strong> <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">'; |
|
207 | - print $tab[$x]['title']; |
|
208 | - print '</a></strong>'; |
|
209 | - print ' (mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' - fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; |
|
210 | - print '</td><td align="right">'; |
|
211 | - print $tab[$x]['buttons']; |
|
212 | - print '</td></tr></table>'; |
|
213 | - } |
|
214 | - else |
|
215 | - { |
|
216 | - print $tab[$x]['entry']; |
|
217 | - } |
|
218 | - //print ' -> B '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n"; |
|
219 | - $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); |
|
220 | - // And now we search all its sons of lower level |
|
221 | - //print 'Call tree_recur for x='.$x.' rowid='.$tab[$x]['rowid']." fk_mainmenu pere = ".$tab[$x]['fk_mainmenu']." fk_leftmenu pere = ".$tab[$x]['fk_leftmenu']."<br>\n"; |
|
222 | - tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk); |
|
223 | - print '</li>'; |
|
224 | - } |
|
225 | - } |
|
226 | - if (! empty($ulprinted) && ! empty($pere['rowid'])) { print '</ul>'."\n"; } |
|
198 | + } |
|
199 | + |
|
200 | + print '<ul'.(empty($pere['rowid'])?' id="treeData"':'').'>'; $ulprinted++; |
|
201 | + } |
|
202 | + print "\n".'<li '.($tab[$x]['statut']?' class="liuseractive"':'class="liuserdisabled"').'>'; |
|
203 | + if ($showfk) |
|
204 | + { |
|
205 | + print '<table class="nobordernopadding centpercent"><tr><td>'; |
|
206 | + print '<strong> <a href="edit.php?menu_handler='.$menu_handler_to_search.'&action=edit&menuId='.$menu['rowid'].'">'; |
|
207 | + print $tab[$x]['title']; |
|
208 | + print '</a></strong>'; |
|
209 | + print ' (mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' - fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; |
|
210 | + print '</td><td align="right">'; |
|
211 | + print $tab[$x]['buttons']; |
|
212 | + print '</td></tr></table>'; |
|
213 | + } |
|
214 | + else |
|
215 | + { |
|
216 | + print $tab[$x]['entry']; |
|
217 | + } |
|
218 | + //print ' -> B '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'<br>'."\n"; |
|
219 | + $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); |
|
220 | + // And now we search all its sons of lower level |
|
221 | + //print 'Call tree_recur for x='.$x.' rowid='.$tab[$x]['rowid']." fk_mainmenu pere = ".$tab[$x]['fk_mainmenu']." fk_leftmenu pere = ".$tab[$x]['fk_leftmenu']."<br>\n"; |
|
222 | + tree_recur($tab, $tab[$x], $rang+1, 'iddivjstree', 0, $showfk); |
|
223 | + print '</li>'; |
|
224 | + } |
|
225 | + } |
|
226 | + if (! empty($ulprinted) && ! empty($pere['rowid'])) { print '</ul>'."\n"; } |
|
227 | 227 | |
228 | 228 | if ($rang == 0) print '</ul>'; |
229 | 229 | } |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | global $shmkeys,$shmoffset; |
25 | 25 | |
26 | 26 | $shmkeys=array('main'=>1,'admin'=>2,'dict'=>3,'companies'=>4,'suppliers'=>5,'products'=>6, |
27 | - 'commercial'=>7,'compta'=>8,'projects'=>9,'cashdesk'=>10,'agenda'=>11,'bills'=>12, |
|
28 | - 'propal'=>13,'boxes'=>14,'banks'=>15,'other'=>16,'errors'=>17,'members'=>18,'ecm'=>19, |
|
29 | - 'orders'=>20,'users'=>21,'help'=>22,'stocks'=>23,'interventions'=>24, |
|
30 | - 'donations'=>25,'contracts'=>26); |
|
27 | + 'commercial'=>7,'compta'=>8,'projects'=>9,'cashdesk'=>10,'agenda'=>11,'bills'=>12, |
|
28 | + 'propal'=>13,'boxes'=>14,'banks'=>15,'other'=>16,'errors'=>17,'members'=>18,'ecm'=>19, |
|
29 | + 'orders'=>20,'users'=>21,'help'=>22,'stocks'=>23,'interventions'=>24, |
|
30 | + 'donations'=>25,'contracts'=>26); |
|
31 | 31 | $shmoffset=1000; // Max number of entries found into a language file. If too low, some entries will be overwritten. |
32 | 32 | |
33 | 33 | |
@@ -41,64 +41,64 @@ discard block |
||
41 | 41 | */ |
42 | 42 | function dol_setcache($memoryid,$data) |
43 | 43 | { |
44 | - global $conf; |
|
45 | - $result=0; |
|
44 | + global $conf; |
|
45 | + $result=0; |
|
46 | 46 | |
47 | - // Using a memcached server |
|
48 | - if (! empty($conf->memcached->enabled) && class_exists('Memcached')) |
|
49 | - { |
|
50 | - global $dolmemcache; |
|
51 | - if (empty($dolmemcache) || ! is_object($dolmemcache)) |
|
52 | - { |
|
53 | - $dolmemcache=new Memcached(); |
|
54 | - $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
55 | - $result=$dolmemcache->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
56 | - if (! $result) return -1; |
|
57 | - } |
|
47 | + // Using a memcached server |
|
48 | + if (! empty($conf->memcached->enabled) && class_exists('Memcached')) |
|
49 | + { |
|
50 | + global $dolmemcache; |
|
51 | + if (empty($dolmemcache) || ! is_object($dolmemcache)) |
|
52 | + { |
|
53 | + $dolmemcache=new Memcached(); |
|
54 | + $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
55 | + $result=$dolmemcache->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
56 | + if (! $result) return -1; |
|
57 | + } |
|
58 | 58 | |
59 | - $memoryid=session_name().'_'.$memoryid; |
|
60 | - //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); |
|
61 | - $dolmemcache->add($memoryid,$data); // This fails if key already exists |
|
62 | - $rescode=$dolmemcache->getResultCode(); |
|
63 | - if ($rescode == 0) |
|
64 | - { |
|
65 | - return count($data); |
|
66 | - } |
|
67 | - else |
|
68 | - { |
|
69 | - return -$rescode; |
|
70 | - } |
|
71 | - } |
|
72 | - else if (! empty($conf->memcached->enabled) && class_exists('Memcache')) |
|
73 | - { |
|
74 | - global $dolmemcache; |
|
75 | - if (empty($dolmemcache) || ! is_object($dolmemcache)) |
|
76 | - { |
|
77 | - $dolmemcache=new Memcache(); |
|
78 | - $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
79 | - $result=$dolmemcache->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
80 | - if (! $result) return -1; |
|
81 | - } |
|
59 | + $memoryid=session_name().'_'.$memoryid; |
|
60 | + //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); |
|
61 | + $dolmemcache->add($memoryid,$data); // This fails if key already exists |
|
62 | + $rescode=$dolmemcache->getResultCode(); |
|
63 | + if ($rescode == 0) |
|
64 | + { |
|
65 | + return count($data); |
|
66 | + } |
|
67 | + else |
|
68 | + { |
|
69 | + return -$rescode; |
|
70 | + } |
|
71 | + } |
|
72 | + else if (! empty($conf->memcached->enabled) && class_exists('Memcache')) |
|
73 | + { |
|
74 | + global $dolmemcache; |
|
75 | + if (empty($dolmemcache) || ! is_object($dolmemcache)) |
|
76 | + { |
|
77 | + $dolmemcache=new Memcache(); |
|
78 | + $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
79 | + $result=$dolmemcache->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
80 | + if (! $result) return -1; |
|
81 | + } |
|
82 | 82 | |
83 | - $memoryid=session_name().'_'.$memoryid; |
|
84 | - //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); |
|
85 | - $result=$dolmemcache->add($memoryid,$data); // This fails if key already exists |
|
86 | - if ($result) |
|
87 | - { |
|
88 | - return count($data); |
|
89 | - } |
|
90 | - else |
|
91 | - { |
|
92 | - return -1; |
|
93 | - } |
|
94 | - } |
|
95 | - // Using shmop |
|
96 | - else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
|
97 | - { |
|
98 | - $result=dol_setshmop($memoryid,$data); |
|
99 | - } |
|
83 | + $memoryid=session_name().'_'.$memoryid; |
|
84 | + //$dolmemcache->setOption(Memcached::OPT_COMPRESSION, false); |
|
85 | + $result=$dolmemcache->add($memoryid,$data); // This fails if key already exists |
|
86 | + if ($result) |
|
87 | + { |
|
88 | + return count($data); |
|
89 | + } |
|
90 | + else |
|
91 | + { |
|
92 | + return -1; |
|
93 | + } |
|
94 | + } |
|
95 | + // Using shmop |
|
96 | + else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
|
97 | + { |
|
98 | + $result=dol_setshmop($memoryid,$data); |
|
99 | + } |
|
100 | 100 | |
101 | - return $result; |
|
101 | + return $result; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,69 +109,69 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function dol_getcache($memoryid) |
111 | 111 | { |
112 | - global $conf; |
|
112 | + global $conf; |
|
113 | 113 | |
114 | - // Using a memcached server |
|
115 | - if (! empty($conf->memcached->enabled) && class_exists('Memcached')) |
|
116 | - { |
|
117 | - global $m; |
|
118 | - if (empty($m) || ! is_object($m)) |
|
119 | - { |
|
114 | + // Using a memcached server |
|
115 | + if (! empty($conf->memcached->enabled) && class_exists('Memcached')) |
|
116 | + { |
|
117 | + global $m; |
|
118 | + if (empty($m) || ! is_object($m)) |
|
119 | + { |
|
120 | 120 | $m=new Memcached(); |
121 | - $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
122 | - $result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
123 | - if (! $result) return -1; |
|
124 | - } |
|
121 | + $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
122 | + $result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
123 | + if (! $result) return -1; |
|
124 | + } |
|
125 | 125 | |
126 | - $memoryid=session_name().'_'.$memoryid; |
|
127 | - //$m->setOption(Memcached::OPT_COMPRESSION, false); |
|
128 | - //print "Get memoryid=".$memoryid; |
|
129 | - $data=$m->get($memoryid); |
|
130 | - $rescode=$m->getResultCode(); |
|
131 | - //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>"; |
|
132 | - //var_dump($data); |
|
133 | - if ($rescode == 0) |
|
134 | - { |
|
135 | - return $data; |
|
136 | - } |
|
137 | - else |
|
138 | - { |
|
139 | - return -$rescode; |
|
140 | - } |
|
141 | - } |
|
142 | - else if (! empty($conf->memcached->enabled) && class_exists('Memcache')) |
|
143 | - { |
|
144 | - global $m; |
|
145 | - if (empty($m) || ! is_object($m)) |
|
146 | - { |
|
147 | - $m=new Memcache(); |
|
148 | - $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
149 | - $result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
150 | - if (! $result) return -1; |
|
151 | - } |
|
126 | + $memoryid=session_name().'_'.$memoryid; |
|
127 | + //$m->setOption(Memcached::OPT_COMPRESSION, false); |
|
128 | + //print "Get memoryid=".$memoryid; |
|
129 | + $data=$m->get($memoryid); |
|
130 | + $rescode=$m->getResultCode(); |
|
131 | + //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>"; |
|
132 | + //var_dump($data); |
|
133 | + if ($rescode == 0) |
|
134 | + { |
|
135 | + return $data; |
|
136 | + } |
|
137 | + else |
|
138 | + { |
|
139 | + return -$rescode; |
|
140 | + } |
|
141 | + } |
|
142 | + else if (! empty($conf->memcached->enabled) && class_exists('Memcache')) |
|
143 | + { |
|
144 | + global $m; |
|
145 | + if (empty($m) || ! is_object($m)) |
|
146 | + { |
|
147 | + $m=new Memcache(); |
|
148 | + $tmparray=explode(':',$conf->global->MEMCACHED_SERVER); |
|
149 | + $result=$m->addServer($tmparray[0], $tmparray[1]?$tmparray[1]:11211); |
|
150 | + if (! $result) return -1; |
|
151 | + } |
|
152 | 152 | |
153 | - $memoryid=session_name().'_'.$memoryid; |
|
154 | - //$m->setOption(Memcached::OPT_COMPRESSION, false); |
|
155 | - $data=$m->get($memoryid); |
|
156 | - //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>"; |
|
157 | - //var_dump($data); |
|
158 | - if ($data) |
|
159 | - { |
|
160 | - return $data; |
|
161 | - } |
|
162 | - else |
|
163 | - { |
|
164 | - return -1; |
|
165 | - } |
|
166 | - } |
|
167 | - // Using shmop |
|
168 | - else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
|
169 | - { |
|
170 | - $data=dol_getshmop($memoryid); |
|
171 | - return $data; |
|
172 | - } |
|
153 | + $memoryid=session_name().'_'.$memoryid; |
|
154 | + //$m->setOption(Memcached::OPT_COMPRESSION, false); |
|
155 | + $data=$m->get($memoryid); |
|
156 | + //print "memoryid=".$memoryid." - rescode=".$rescode." - data=".count($data)."\n<br>"; |
|
157 | + //var_dump($data); |
|
158 | + if ($data) |
|
159 | + { |
|
160 | + return $data; |
|
161 | + } |
|
162 | + else |
|
163 | + { |
|
164 | + return -1; |
|
165 | + } |
|
166 | + } |
|
167 | + // Using shmop |
|
168 | + else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
|
169 | + { |
|
170 | + $data=dol_getshmop($memoryid); |
|
171 | + return $data; |
|
172 | + } |
|
173 | 173 | |
174 | - return 0; |
|
174 | + return 0; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | */ |
185 | 185 | function dol_getshmopaddress($memoryid) |
186 | 186 | { |
187 | - global $shmkeys,$shmoffset; |
|
188 | - if (empty($shmkeys[$memoryid])) return 0; |
|
189 | - return $shmkeys[$memoryid]+$shmoffset; |
|
187 | + global $shmkeys,$shmoffset; |
|
188 | + if (empty($shmkeys[$memoryid])) return 0; |
|
189 | + return $shmkeys[$memoryid]+$shmoffset; |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -196,15 +196,15 @@ discard block |
||
196 | 196 | */ |
197 | 197 | function dol_listshmop() |
198 | 198 | { |
199 | - global $shmkeys,$shmoffset; |
|
199 | + global $shmkeys,$shmoffset; |
|
200 | 200 | |
201 | - $resarray=array(); |
|
202 | - foreach($shmkeys as $key => $val) |
|
203 | - { |
|
204 | - $result=dol_getshmop($key); |
|
205 | - if (! is_numeric($result) || $result > 0) $resarray[$key]=$result; |
|
206 | - } |
|
207 | - return $resarray; |
|
201 | + $resarray=array(); |
|
202 | + foreach($shmkeys as $key => $val) |
|
203 | + { |
|
204 | + $result=dol_getshmop($key); |
|
205 | + if (! is_numeric($result) || $result > 0) $resarray[$key]=$result; |
|
206 | + } |
|
207 | + return $resarray; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -216,31 +216,31 @@ discard block |
||
216 | 216 | */ |
217 | 217 | function dol_setshmop($memoryid,$data) |
218 | 218 | { |
219 | - global $shmkeys,$shmoffset; |
|
219 | + global $shmkeys,$shmoffset; |
|
220 | 220 | |
221 | - //print 'dol_setshmop memoryid='.$memoryid."<br>\n"; |
|
222 | - if (empty($shmkeys[$memoryid]) || ! function_exists("shmop_write")) return 0; |
|
223 | - $shmkey=dol_getshmopaddress($memoryid); |
|
224 | - $newdata=serialize($data); |
|
225 | - $size=strlen($newdata); |
|
226 | - //print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes<br>\n"; |
|
227 | - $handle=shmop_open($shmkey,'c',0644,6+$size); |
|
228 | - if ($handle) |
|
229 | - { |
|
230 | - $shm_bytes_written1=shmop_write($handle,str_pad($size,6),0); |
|
231 | - $shm_bytes_written2=shmop_write($handle,$newdata,6); |
|
232 | - if (($shm_bytes_written1 + $shm_bytes_written2) != (6+dol_strlen($newdata))) |
|
233 | - { |
|
234 | - print "Couldn't write the entire length of data\n"; |
|
235 | - } |
|
236 | - shmop_close($handle); |
|
237 | - return ($shm_bytes_written1+$shm_bytes_written2); |
|
238 | - } |
|
239 | - else |
|
240 | - { |
|
241 | - print 'Error in shmop_open for memoryid='.$memoryid.' shmkey='.$shmkey.' 6+size=6+'.$size; |
|
242 | - return -1; |
|
243 | - } |
|
221 | + //print 'dol_setshmop memoryid='.$memoryid."<br>\n"; |
|
222 | + if (empty($shmkeys[$memoryid]) || ! function_exists("shmop_write")) return 0; |
|
223 | + $shmkey=dol_getshmopaddress($memoryid); |
|
224 | + $newdata=serialize($data); |
|
225 | + $size=strlen($newdata); |
|
226 | + //print 'dol_setshmop memoryid='.$memoryid." shmkey=".$shmkey." newdata=".$size."bytes<br>\n"; |
|
227 | + $handle=shmop_open($shmkey,'c',0644,6+$size); |
|
228 | + if ($handle) |
|
229 | + { |
|
230 | + $shm_bytes_written1=shmop_write($handle,str_pad($size,6),0); |
|
231 | + $shm_bytes_written2=shmop_write($handle,$newdata,6); |
|
232 | + if (($shm_bytes_written1 + $shm_bytes_written2) != (6+dol_strlen($newdata))) |
|
233 | + { |
|
234 | + print "Couldn't write the entire length of data\n"; |
|
235 | + } |
|
236 | + shmop_close($handle); |
|
237 | + return ($shm_bytes_written1+$shm_bytes_written2); |
|
238 | + } |
|
239 | + else |
|
240 | + { |
|
241 | + print 'Error in shmop_open for memoryid='.$memoryid.' shmkey='.$shmkey.' 6+size=6+'.$size; |
|
242 | + return -1; |
|
243 | + } |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -251,23 +251,23 @@ discard block |
||
251 | 251 | */ |
252 | 252 | function dol_getshmop($memoryid) |
253 | 253 | { |
254 | - global $shmkeys,$shmoffset; |
|
254 | + global $shmkeys,$shmoffset; |
|
255 | 255 | |
256 | - if (empty($shmkeys[$memoryid]) || ! function_exists("shmop_open")) return 0; |
|
257 | - $shmkey=dol_getshmopaddress($memoryid); |
|
258 | - //print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."<br>\n"; |
|
259 | - $handle=@shmop_open($shmkey,'a',0,0); |
|
260 | - if ($handle) |
|
261 | - { |
|
262 | - $size=trim(shmop_read($handle,0,6)); |
|
263 | - if ($size) $data=unserialize(shmop_read($handle,6,$size)); |
|
264 | - else return -1; |
|
265 | - shmop_close($handle); |
|
266 | - } |
|
267 | - else |
|
268 | - { |
|
269 | - return -2; |
|
270 | - } |
|
271 | - return $data; |
|
256 | + if (empty($shmkeys[$memoryid]) || ! function_exists("shmop_open")) return 0; |
|
257 | + $shmkey=dol_getshmopaddress($memoryid); |
|
258 | + //print 'dol_getshmop memoryid='.$memoryid." shmkey=".$shmkey."<br>\n"; |
|
259 | + $handle=@shmop_open($shmkey,'a',0,0); |
|
260 | + if ($handle) |
|
261 | + { |
|
262 | + $size=trim(shmop_read($handle,0,6)); |
|
263 | + if ($size) $data=unserialize(shmop_read($handle,6,$size)); |
|
264 | + else return -1; |
|
265 | + shmop_close($handle); |
|
266 | + } |
|
267 | + else |
|
268 | + { |
|
269 | + return -2; |
|
270 | + } |
|
271 | + return $data; |
|
272 | 272 | } |
273 | 273 |
@@ -34,78 +34,78 @@ discard block |
||
34 | 34 | */ |
35 | 35 | function build_calfile($format,$title,$desc,$events_array,$outputfile) |
36 | 36 | { |
37 | - global $conf,$langs; |
|
37 | + global $conf,$langs; |
|
38 | 38 | |
39 | - dol_syslog("xcal.lib.php::build_calfile Build cal file ".$outputfile." to format ".$format); |
|
39 | + dol_syslog("xcal.lib.php::build_calfile Build cal file ".$outputfile." to format ".$format); |
|
40 | 40 | |
41 | - if (empty($outputfile)) return -1; |
|
41 | + if (empty($outputfile)) return -1; |
|
42 | 42 | |
43 | 43 | // Note: A cal file is an UTF8 encoded file |
44 | - $calfileh=fopen($outputfile,'w'); |
|
45 | - if ($calfileh) |
|
46 | - { |
|
47 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
48 | - $now=dol_now(); |
|
49 | - |
|
50 | - $encoding=''; |
|
51 | - if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:'; |
|
52 | - |
|
53 | - // Print header |
|
54 | - fwrite($calfileh,"BEGIN:VCALENDAR\n"); |
|
55 | - fwrite($calfileh,"VERSION:2.0\n"); |
|
56 | - fwrite($calfileh,"METHOD:PUBLISH\n"); |
|
57 | - //fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."//EN\n"); |
|
58 | - fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."\n"); |
|
59 | - fwrite($calfileh,"CALSCALE:GREGORIAN\n"); |
|
60 | - fwrite($calfileh,"X-WR-CALNAME:".$encoding.format_cal($format,$title)."\n"); |
|
44 | + $calfileh=fopen($outputfile,'w'); |
|
45 | + if ($calfileh) |
|
46 | + { |
|
47 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
48 | + $now=dol_now(); |
|
49 | + |
|
50 | + $encoding=''; |
|
51 | + if ($format == 'vcal') $encoding='ENCODING=QUOTED-PRINTABLE:'; |
|
52 | + |
|
53 | + // Print header |
|
54 | + fwrite($calfileh,"BEGIN:VCALENDAR\n"); |
|
55 | + fwrite($calfileh,"VERSION:2.0\n"); |
|
56 | + fwrite($calfileh,"METHOD:PUBLISH\n"); |
|
57 | + //fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."//EN\n"); |
|
58 | + fwrite($calfileh,"PRODID:-//DOLIBARR ".DOL_VERSION."\n"); |
|
59 | + fwrite($calfileh,"CALSCALE:GREGORIAN\n"); |
|
60 | + fwrite($calfileh,"X-WR-CALNAME:".$encoding.format_cal($format,$title)."\n"); |
|
61 | 61 | fwrite($calfileh,"X-WR-CALDESC:".$encoding.format_cal($format,$desc)."\n"); |
62 | 62 | //fwrite($calfileh,"X-WR-TIMEZONE:Europe/Paris\n"); |
63 | 63 | if (! empty($conf->global->MAIN_AGENDA_EXPORT_CACHE) |
64 | 64 | && $conf->global->MAIN_AGENDA_EXPORT_CACHE > 60){ |
65 | - $hh=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'hour'); |
|
66 | - $mm=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'min'); |
|
67 | - $ss=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'sec'); |
|
68 | - fwrite($calfileh,"X-PUBLISHED-TTL: P".$hh."H".$mm."M".$ss."S\n"); |
|
65 | + $hh=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'hour'); |
|
66 | + $mm=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'min'); |
|
67 | + $ss=convertSecondToTime($conf->global->MAIN_AGENDA_EXPORT_CACHE,'sec'); |
|
68 | + fwrite($calfileh,"X-PUBLISHED-TTL: P".$hh."H".$mm."M".$ss."S\n"); |
|
69 | 69 | } |
70 | 70 | |
71 | - foreach ($events_array as $key => $event) |
|
72 | - { |
|
73 | - $eventqualified=true; |
|
74 | - if ($eventqualified) |
|
75 | - { |
|
76 | - // See http://fr.wikipedia.org/wiki/ICalendar for format |
|
77 | - // See http://www.ietf.org/rfc/rfc2445.txt for RFC |
|
78 | - $uid = $event['uid']; |
|
79 | - $type = $event['type']; |
|
71 | + foreach ($events_array as $key => $event) |
|
72 | + { |
|
73 | + $eventqualified=true; |
|
74 | + if ($eventqualified) |
|
75 | + { |
|
76 | + // See http://fr.wikipedia.org/wiki/ICalendar for format |
|
77 | + // See http://www.ietf.org/rfc/rfc2445.txt for RFC |
|
78 | + $uid = $event['uid']; |
|
79 | + $type = $event['type']; |
|
80 | 80 | $startdate = $event['startdate']; |
81 | - $duration = $event['duration']; |
|
82 | - $enddate = $event['enddate']; |
|
83 | - $summary = $event['summary']; |
|
84 | - $category = $event['category']; |
|
81 | + $duration = $event['duration']; |
|
82 | + $enddate = $event['enddate']; |
|
83 | + $summary = $event['summary']; |
|
84 | + $category = $event['category']; |
|
85 | 85 | $priority = $event['priority']; |
86 | 86 | $fulldayevent = $event['fulldayevent']; |
87 | - $location = $event['location']; |
|
88 | - $email = $event['email']; |
|
89 | - $url = $event['url']; |
|
90 | - $transparency = $event['transparency']; // OPAQUE (busy) or TRANSPARENT (not busy) |
|
91 | - $description=preg_replace('/<br[\s\/]?>/i',"\n",$event['desc']); |
|
92 | - $description=dol_string_nohtmltag($description,0); // Remove html tags |
|
87 | + $location = $event['location']; |
|
88 | + $email = $event['email']; |
|
89 | + $url = $event['url']; |
|
90 | + $transparency = $event['transparency']; // OPAQUE (busy) or TRANSPARENT (not busy) |
|
91 | + $description=preg_replace('/<br[\s\/]?>/i',"\n",$event['desc']); |
|
92 | + $description=dol_string_nohtmltag($description,0); // Remove html tags |
|
93 | 93 | $created = $event['created']; |
94 | - $modified = $event['modified']; |
|
94 | + $modified = $event['modified']; |
|
95 | 95 | |
96 | - // Uncomment for tests |
|
97 | - //$summary="Resume"; |
|
98 | - //$description="Description"; |
|
99 | - //$description="MemberValidatedInDolibarr gd gdf gd gdff\nNom: tgdf g dfgdf gfd r ter\nType: gdfgfdf dfg fd gfd gd gdf gdf gfd gdfg dfg ddf\nAuteur: AD01fg dgdgdfg df gdf gd"; |
|
96 | + // Uncomment for tests |
|
97 | + //$summary="Resume"; |
|
98 | + //$description="Description"; |
|
99 | + //$description="MemberValidatedInDolibarr gd gdf gd gdff\nNom: tgdf g dfgdf gfd r ter\nType: gdfgfdf dfg fd gfd gd gdf gdf gfd gdfg dfg ddf\nAuteur: AD01fg dgdgdfg df gdf gd"; |
|
100 | 100 | |
101 | - // Format |
|
102 | - $summary=format_cal($format,$summary); |
|
103 | - $description=format_cal($format,$description); |
|
104 | - $category=format_cal($format,$category); |
|
105 | - $location=format_cal($format,$location); |
|
101 | + // Format |
|
102 | + $summary=format_cal($format,$summary); |
|
103 | + $description=format_cal($format,$description); |
|
104 | + $category=format_cal($format,$category); |
|
105 | + $location=format_cal($format,$location); |
|
106 | 106 | |
107 | - // Output the vCard/iCal VEVENT object |
|
108 | - /* |
|
107 | + // Output the vCard/iCal VEVENT object |
|
108 | + /* |
|
109 | 109 | Example from Google ical export for a 1 hour event: |
110 | 110 | BEGIN:VEVENT |
111 | 111 | DTSTART:20101103T120000Z |
@@ -138,26 +138,26 @@ discard block |
||
138 | 138 | TRANSP:TRANSPARENT |
139 | 139 | END:VEVENT |
140 | 140 | */ |
141 | - if ($type == 'event') |
|
142 | - { |
|
143 | - fwrite($calfileh,"BEGIN:VEVENT\n"); |
|
144 | - fwrite($calfileh,"UID:".$uid."\n"); |
|
145 | - if (! empty($email)) |
|
146 | - { |
|
147 | - fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); |
|
148 | - fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); |
|
149 | - } |
|
150 | - if (! empty($url)) |
|
151 | - { |
|
152 | - fwrite($calfileh,"URL:".$url."\n"); |
|
153 | - }; |
|
141 | + if ($type == 'event') |
|
142 | + { |
|
143 | + fwrite($calfileh,"BEGIN:VEVENT\n"); |
|
144 | + fwrite($calfileh,"UID:".$uid."\n"); |
|
145 | + if (! empty($email)) |
|
146 | + { |
|
147 | + fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); |
|
148 | + fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); |
|
149 | + } |
|
150 | + if (! empty($url)) |
|
151 | + { |
|
152 | + fwrite($calfileh,"URL:".$url."\n"); |
|
153 | + }; |
|
154 | 154 | |
155 | 155 | if ($created) fwrite($calfileh,"CREATED:".dol_print_date($created,'dayhourxcard',true)."\n"); |
156 | 156 | if ($modified) fwrite($calfileh,"LAST-MODIFIED:".dol_print_date($modified,'dayhourxcard',true)."\n"); |
157 | 157 | fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n"); |
158 | - fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); |
|
158 | + fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); |
|
159 | 159 | |
160 | - /* Other keys: |
|
160 | + /* Other keys: |
|
161 | 161 | // Status values for a "VEVENT" |
162 | 162 | statvalue = "TENTATIVE" ;Indicates event is |
163 | 163 | ;tentative. |
@@ -174,86 +174,86 @@ discard block |
||
174 | 174 | / "FINAL" ;Indicates journal is final. |
175 | 175 | / "CANCELLED" ;Indicates journal is removed. |
176 | 176 | */ |
177 | - //fwrite($calfileh,"CLASS:PUBLIC\n"); // PUBLIC, PRIVATE, CONFIDENTIAL |
|
177 | + //fwrite($calfileh,"CLASS:PUBLIC\n"); // PUBLIC, PRIVATE, CONFIDENTIAL |
|
178 | 178 | //fwrite($calfileh,"X-MICROSOFT-CDO-BUSYSTATUS:1\n"); |
179 | 179 | //ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=Laurent Destailleur;X-NUM-GUESTS=0:mailto:[email protected] |
180 | 180 | |
181 | 181 | if (! empty($location)) fwrite($calfileh,"LOCATION:".$encoding.$location."\n"); |
182 | - if ($fulldayevent) fwrite($calfileh,"X-FUNAMBOL-ALLDAY:1\n"); |
|
182 | + if ($fulldayevent) fwrite($calfileh,"X-FUNAMBOL-ALLDAY:1\n"); |
|
183 | 183 | if ($fulldayevent) fwrite($calfileh,"X-MICROSOFT-CDO-ALLDAYEVENT:1\n"); |
184 | 184 | |
185 | - // Date must be GMT dates |
|
186 | - // Current date |
|
187 | - fwrite($calfileh,"DTSTAMP:".dol_print_date($now,'dayhourxcard',true)."\n"); |
|
188 | - // Start date |
|
185 | + // Date must be GMT dates |
|
186 | + // Current date |
|
187 | + fwrite($calfileh,"DTSTAMP:".dol_print_date($now,'dayhourxcard',true)."\n"); |
|
188 | + // Start date |
|
189 | 189 | $prefix=''; |
190 | 190 | $startdatef = dol_print_date($startdate,'dayhourxcard',true); |
191 | 191 | if ($fulldayevent) |
192 | - { |
|
192 | + { |
|
193 | 193 | $prefix=';VALUE=DATE'; |
194 | - $startdatef = dol_print_date($startdate,'dayxcard',false); // Local time |
|
195 | - } |
|
196 | - fwrite($calfileh,"DTSTART".$prefix.":".$startdatef."\n"); |
|
194 | + $startdatef = dol_print_date($startdate,'dayxcard',false); // Local time |
|
195 | + } |
|
196 | + fwrite($calfileh,"DTSTART".$prefix.":".$startdatef."\n"); |
|
197 | 197 | // End date |
198 | - if ($fulldayevent) |
|
199 | - { |
|
200 | - if (empty($enddate)) $enddate=dol_time_plus_duree($startdate,1,'d'); |
|
201 | - } |
|
202 | - else |
|
203 | - { |
|
198 | + if ($fulldayevent) |
|
199 | + { |
|
200 | + if (empty($enddate)) $enddate=dol_time_plus_duree($startdate,1,'d'); |
|
201 | + } |
|
202 | + else |
|
203 | + { |
|
204 | 204 | if (empty($enddate)) $enddate=$startdate+$duration; |
205 | - } |
|
205 | + } |
|
206 | 206 | $prefix=''; |
207 | - $enddatef = dol_print_date($enddate,'dayhourxcard',true); |
|
208 | - if ($fulldayevent) |
|
209 | - { |
|
207 | + $enddatef = dol_print_date($enddate,'dayhourxcard',true); |
|
208 | + if ($fulldayevent) |
|
209 | + { |
|
210 | 210 | $prefix=';VALUE=DATE'; |
211 | - $enddatef = dol_print_date($enddate+1,'dayxcard',false); |
|
212 | - //$enddatef .= dol_print_date($enddate+1,'dayhourxcard',false); // Local time |
|
213 | - } |
|
211 | + $enddatef = dol_print_date($enddate+1,'dayxcard',false); |
|
212 | + //$enddatef .= dol_print_date($enddate+1,'dayhourxcard',false); // Local time |
|
213 | + } |
|
214 | 214 | fwrite($calfileh,"DTEND".$prefix.":".$enddatef."\n"); |
215 | - fwrite($calfileh,'STATUS:CONFIRMED'."\n"); |
|
216 | - if (! empty($transparency)) fwrite($calfileh,"TRANSP:".$transparency."\n"); |
|
217 | - if (! empty($category)) fwrite($calfileh,"CATEGORIES:".$encoding.$category."\n"); |
|
218 | - fwrite($calfileh,"END:VEVENT\n"); |
|
219 | - } |
|
220 | - |
|
221 | - // Output the vCard/iCal VTODO object |
|
222 | - // ... |
|
223 | - //PERCENT-COMPLETE:39 |
|
224 | - |
|
225 | - // Output the vCard/iCal VJOURNAL object |
|
226 | - if ($type == 'journal') |
|
227 | - { |
|
228 | - fwrite($calfileh,"BEGIN:VJOURNAL\n"); |
|
229 | - fwrite($calfileh,"UID:".$uid."\n"); |
|
230 | - if (! empty($email)) |
|
231 | - { |
|
232 | - fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); |
|
233 | - fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); |
|
234 | - } |
|
235 | - if (! empty($url)) |
|
236 | - { |
|
237 | - fwrite($calfileh,"URL:".$url."\n"); |
|
238 | - }; |
|
215 | + fwrite($calfileh,'STATUS:CONFIRMED'."\n"); |
|
216 | + if (! empty($transparency)) fwrite($calfileh,"TRANSP:".$transparency."\n"); |
|
217 | + if (! empty($category)) fwrite($calfileh,"CATEGORIES:".$encoding.$category."\n"); |
|
218 | + fwrite($calfileh,"END:VEVENT\n"); |
|
219 | + } |
|
220 | + |
|
221 | + // Output the vCard/iCal VTODO object |
|
222 | + // ... |
|
223 | + //PERCENT-COMPLETE:39 |
|
224 | + |
|
225 | + // Output the vCard/iCal VJOURNAL object |
|
226 | + if ($type == 'journal') |
|
227 | + { |
|
228 | + fwrite($calfileh,"BEGIN:VJOURNAL\n"); |
|
229 | + fwrite($calfileh,"UID:".$uid."\n"); |
|
230 | + if (! empty($email)) |
|
231 | + { |
|
232 | + fwrite($calfileh,"ORGANIZER:MAILTO:".$email."\n"); |
|
233 | + fwrite($calfileh,"CONTACT:MAILTO:".$email."\n"); |
|
234 | + } |
|
235 | + if (! empty($url)) |
|
236 | + { |
|
237 | + fwrite($calfileh,"URL:".$url."\n"); |
|
238 | + }; |
|
239 | 239 | |
240 | 240 | if ($created) fwrite($calfileh,"CREATED:".dol_print_date($created,'dayhourxcard',true)."\n"); |
241 | 241 | if ($modified) fwrite($calfileh,"LAST-MODIFIED:".dol_print_date($modified,'dayhourxcard',true)."\n"); |
242 | - fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n"); |
|
243 | - fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); |
|
244 | - fwrite($calfileh,'STATUS:CONFIRMED'."\n"); |
|
245 | - fwrite($calfileh,"CATEGORIES:".$category."\n"); |
|
246 | - fwrite($calfileh,"LOCATION:".$location."\n"); |
|
247 | - fwrite($calfileh,"TRANSP:OPAQUE\n"); |
|
248 | - fwrite($calfileh,"CLASS:CONFIDENTIAL\n"); |
|
249 | - fwrite($calfileh,"DTSTAMP:".dol_print_date($startdatef,'dayhourxcard',true)."\n"); |
|
242 | + fwrite($calfileh,"SUMMARY:".$encoding.$summary."\n"); |
|
243 | + fwrite($calfileh,"DESCRIPTION:".$encoding.$description."\n"); |
|
244 | + fwrite($calfileh,'STATUS:CONFIRMED'."\n"); |
|
245 | + fwrite($calfileh,"CATEGORIES:".$category."\n"); |
|
246 | + fwrite($calfileh,"LOCATION:".$location."\n"); |
|
247 | + fwrite($calfileh,"TRANSP:OPAQUE\n"); |
|
248 | + fwrite($calfileh,"CLASS:CONFIDENTIAL\n"); |
|
249 | + fwrite($calfileh,"DTSTAMP:".dol_print_date($startdatef,'dayhourxcard',true)."\n"); |
|
250 | 250 | |
251 | - fwrite($calfileh,"END:VJOURNAL\n"); |
|
252 | - } |
|
251 | + fwrite($calfileh,"END:VJOURNAL\n"); |
|
252 | + } |
|
253 | 253 | |
254 | 254 | |
255 | - // Put other info in comment |
|
256 | - /* |
|
255 | + // Put other info in comment |
|
256 | + /* |
|
257 | 257 | $comment=array(); |
258 | 258 | $comment ['eid'] = $eid; |
259 | 259 | $comment ['url'] = $linktoevent; |
@@ -263,21 +263,21 @@ discard block |
||
263 | 263 | $comment ['enddate'] = $enddate; |
264 | 264 | fwrite($calfileh,"COMMENT:" . serialize ($comment) . "\n"); |
265 | 265 | */ |
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - // Footer |
|
270 | - fwrite($calfileh,"END:VCALENDAR"); |
|
271 | - |
|
272 | - fclose($calfileh); |
|
273 | - if (! empty($conf->global->MAIN_UMASK)) |
|
274 | - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
275 | - } |
|
276 | - else |
|
277 | - { |
|
278 | - dol_syslog("xcal.lib.php::build_calfile Failed to open file ".$outputfile." for writing"); |
|
279 | - return -2; |
|
280 | - } |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + // Footer |
|
270 | + fwrite($calfileh,"END:VCALENDAR"); |
|
271 | + |
|
272 | + fclose($calfileh); |
|
273 | + if (! empty($conf->global->MAIN_UMASK)) |
|
274 | + @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
275 | + } |
|
276 | + else |
|
277 | + { |
|
278 | + dol_syslog("xcal.lib.php::build_calfile Failed to open file ".$outputfile." for writing"); |
|
279 | + return -2; |
|
280 | + } |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | /** |
@@ -294,97 +294,97 @@ discard block |
||
294 | 294 | */ |
295 | 295 | function build_rssfile($format,$title,$desc,$events_array,$outputfile,$filter='') |
296 | 296 | { |
297 | - global $user,$conf,$langs; |
|
298 | - global $dolibarr_main_url_root; |
|
297 | + global $user,$conf,$langs; |
|
298 | + global $dolibarr_main_url_root; |
|
299 | 299 | |
300 | - dol_syslog("xcal.lib.php::build_rssfile Build rss file ".$outputfile." to format ".$format); |
|
300 | + dol_syslog("xcal.lib.php::build_rssfile Build rss file ".$outputfile." to format ".$format); |
|
301 | 301 | |
302 | - if (empty($outputfile)) return -1; |
|
302 | + if (empty($outputfile)) return -1; |
|
303 | 303 | |
304 | - $fichier=fopen($outputfile,'w'); |
|
305 | - if ($fichier) |
|
306 | - { |
|
307 | - $date=date("r"); |
|
304 | + $fichier=fopen($outputfile,'w'); |
|
305 | + if ($fichier) |
|
306 | + { |
|
307 | + $date=date("r"); |
|
308 | 308 | |
309 | - // Print header |
|
310 | - $form='<?xml version="1.0" encoding="'.$langs->charset_output.'"?>'; |
|
311 | - fwrite($fichier, $form); |
|
312 | - fwrite($fichier, "\n"); |
|
313 | - $form='<rss version="2.0">'; |
|
314 | - fwrite($fichier, $form); |
|
315 | - fwrite($fichier, "\n"); |
|
309 | + // Print header |
|
310 | + $form='<?xml version="1.0" encoding="'.$langs->charset_output.'"?>'; |
|
311 | + fwrite($fichier, $form); |
|
312 | + fwrite($fichier, "\n"); |
|
313 | + $form='<rss version="2.0">'; |
|
314 | + fwrite($fichier, $form); |
|
315 | + fwrite($fichier, "\n"); |
|
316 | 316 | |
317 | - $form="<channel>\n<title>".$title."</title>\n"; |
|
318 | - fwrite($fichier, $form); |
|
317 | + $form="<channel>\n<title>".$title."</title>\n"; |
|
318 | + fwrite($fichier, $form); |
|
319 | 319 | |
320 | - $form='<description><![CDATA['.$desc.'.]]></description>'."\n". |
|
320 | + $form='<description><![CDATA['.$desc.'.]]></description>'."\n". |
|
321 | 321 | // '<language>fr</language>'."\n". |
322 | - '<copyright>Dolibarr</copyright>'."\n". |
|
323 | - '<lastBuildDate>'.$date.'</lastBuildDate>'."\n". |
|
324 | - '<generator>Dolibarr</generator>'."\n"; |
|
325 | - |
|
326 | - // Define $urlwithroot |
|
327 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
328 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
329 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
330 | - $url=$urlwithroot.'/public/agenda/agendaexport.php?format=rss&exportkey='.urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY); |
|
331 | - $form.='<link><![CDATA['.$url.']]></link>'."\n"; |
|
332 | - |
|
333 | - //print $form; |
|
334 | - fwrite($fichier, $form); |
|
335 | - |
|
336 | - |
|
337 | - foreach ($events_array as $key => $event) |
|
338 | - { |
|
339 | - $eventqualified=true; |
|
340 | - if ($filter) |
|
341 | - { |
|
342 | - // TODO Add a filter |
|
343 | - |
|
344 | - $eventqualified=false; |
|
345 | - } |
|
346 | - |
|
347 | - if ($eventqualified) |
|
348 | - { |
|
349 | - $uid = $event['uid']; |
|
350 | - $startdate = $event['startdate']; |
|
351 | - $summary = $event['summary']; |
|
352 | - $url = $event['url']; |
|
353 | - $author = $event['author']; |
|
354 | - $category = $event['category']; |
|
355 | - /* No place inside a RSS |
|
322 | + '<copyright>Dolibarr</copyright>'."\n". |
|
323 | + '<lastBuildDate>'.$date.'</lastBuildDate>'."\n". |
|
324 | + '<generator>Dolibarr</generator>'."\n"; |
|
325 | + |
|
326 | + // Define $urlwithroot |
|
327 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
328 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
329 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
330 | + $url=$urlwithroot.'/public/agenda/agendaexport.php?format=rss&exportkey='.urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY); |
|
331 | + $form.='<link><![CDATA['.$url.']]></link>'."\n"; |
|
332 | + |
|
333 | + //print $form; |
|
334 | + fwrite($fichier, $form); |
|
335 | + |
|
336 | + |
|
337 | + foreach ($events_array as $key => $event) |
|
338 | + { |
|
339 | + $eventqualified=true; |
|
340 | + if ($filter) |
|
341 | + { |
|
342 | + // TODO Add a filter |
|
343 | + |
|
344 | + $eventqualified=false; |
|
345 | + } |
|
346 | + |
|
347 | + if ($eventqualified) |
|
348 | + { |
|
349 | + $uid = $event['uid']; |
|
350 | + $startdate = $event['startdate']; |
|
351 | + $summary = $event['summary']; |
|
352 | + $url = $event['url']; |
|
353 | + $author = $event['author']; |
|
354 | + $category = $event['category']; |
|
355 | + /* No place inside a RSS |
|
356 | 356 | $priority = $event['priority']; |
357 | 357 | $fulldayevent = $event['fulldayevent']; |
358 | 358 | $location = $event['location']; |
359 | 359 | $email = $event['email']; |
360 | 360 | */ |
361 | - $description=preg_replace('/<br[\s\/]?>/i',"\n",$event['desc']); |
|
362 | - $description=dol_string_nohtmltag($description,0); // Remove html tags |
|
363 | - |
|
364 | - fwrite($fichier, "<item>\n"); |
|
365 | - fwrite($fichier, "<title><![CDATA[".$summary."]]></title>\n"); |
|
366 | - fwrite($fichier, "<link><![CDATA[".$url."]]></link>\n"); |
|
367 | - fwrite($fichier, "<author><![CDATA[".$author."]]></author>\n"); |
|
368 | - fwrite($fichier, "<category><![CDATA[".$category."]]></category>\n"); |
|
369 | - fwrite($fichier, "<description><![CDATA["); |
|
370 | - if ($description) fwrite($fichier, $description); |
|
371 | - //else fwrite($fichier, 'NoDesc'); |
|
372 | - fwrite($fichier, "]]></description>\n"); |
|
373 | - fwrite($fichier, "<pubDate>".date("r", $startdate)."</pubDate>\n"); |
|
374 | - fwrite($fichier, "<guid isPermaLink=\"true\"><![CDATA[".$uid."]]></guid>\n"); |
|
375 | - fwrite($fichier, "<source><![CDATA[Dolibarr]]></source>\n"); |
|
376 | - fwrite($fichier, "</item>\n"); |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - fwrite($fichier, '</channel>'); |
|
381 | - fwrite($fichier, "\n"); |
|
382 | - fwrite($fichier, '</rss>'); |
|
383 | - |
|
384 | - fclose($fichier); |
|
385 | - if (! empty($conf->global->MAIN_UMASK)) |
|
386 | - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
387 | - } |
|
361 | + $description=preg_replace('/<br[\s\/]?>/i',"\n",$event['desc']); |
|
362 | + $description=dol_string_nohtmltag($description,0); // Remove html tags |
|
363 | + |
|
364 | + fwrite($fichier, "<item>\n"); |
|
365 | + fwrite($fichier, "<title><![CDATA[".$summary."]]></title>\n"); |
|
366 | + fwrite($fichier, "<link><![CDATA[".$url."]]></link>\n"); |
|
367 | + fwrite($fichier, "<author><![CDATA[".$author."]]></author>\n"); |
|
368 | + fwrite($fichier, "<category><![CDATA[".$category."]]></category>\n"); |
|
369 | + fwrite($fichier, "<description><![CDATA["); |
|
370 | + if ($description) fwrite($fichier, $description); |
|
371 | + //else fwrite($fichier, 'NoDesc'); |
|
372 | + fwrite($fichier, "]]></description>\n"); |
|
373 | + fwrite($fichier, "<pubDate>".date("r", $startdate)."</pubDate>\n"); |
|
374 | + fwrite($fichier, "<guid isPermaLink=\"true\"><![CDATA[".$uid."]]></guid>\n"); |
|
375 | + fwrite($fichier, "<source><![CDATA[Dolibarr]]></source>\n"); |
|
376 | + fwrite($fichier, "</item>\n"); |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + fwrite($fichier, '</channel>'); |
|
381 | + fwrite($fichier, "\n"); |
|
382 | + fwrite($fichier, '</rss>'); |
|
383 | + |
|
384 | + fclose($fichier); |
|
385 | + if (! empty($conf->global->MAIN_UMASK)) |
|
386 | + @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
387 | + } |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
@@ -397,25 +397,25 @@ discard block |
||
397 | 397 | */ |
398 | 398 | function format_cal($format,$string) |
399 | 399 | { |
400 | - global $conf; |
|
401 | - |
|
402 | - $newstring=$string; |
|
403 | - |
|
404 | - if ($format == 'vcal') |
|
405 | - { |
|
406 | - $newstring=quotedPrintEncode($newstring); |
|
407 | - } |
|
408 | - if ($format == 'ical') |
|
409 | - { |
|
410 | - // Replace new lines chars by '\n' |
|
411 | - $newstring=preg_replace('/'."\r\n".'/i',"\n",$newstring); |
|
412 | - $newstring=preg_replace('/'."\n\r".'/i',"\n",$newstring); |
|
413 | - $newstring=preg_replace('/'."\n".'/i','\n',$newstring); |
|
414 | - // Must not exceed 75 char. Cut with "\r\n"+Space |
|
415 | - $newstring=calEncode($newstring); |
|
416 | - } |
|
417 | - |
|
418 | - return $newstring; |
|
400 | + global $conf; |
|
401 | + |
|
402 | + $newstring=$string; |
|
403 | + |
|
404 | + if ($format == 'vcal') |
|
405 | + { |
|
406 | + $newstring=quotedPrintEncode($newstring); |
|
407 | + } |
|
408 | + if ($format == 'ical') |
|
409 | + { |
|
410 | + // Replace new lines chars by '\n' |
|
411 | + $newstring=preg_replace('/'."\r\n".'/i',"\n",$newstring); |
|
412 | + $newstring=preg_replace('/'."\n\r".'/i',"\n",$newstring); |
|
413 | + $newstring=preg_replace('/'."\n".'/i','\n',$newstring); |
|
414 | + // Must not exceed 75 char. Cut with "\r\n"+Space |
|
415 | + $newstring=calEncode($newstring); |
|
416 | + } |
|
417 | + |
|
418 | + return $newstring; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -427,45 +427,45 @@ discard block |
||
427 | 427 | */ |
428 | 428 | function calEncode($line) |
429 | 429 | { |
430 | - $out = ''; |
|
431 | - |
|
432 | - $newpara = ''; |
|
433 | - |
|
434 | - // If mb_ functions exists, it's better to use them |
|
435 | - if (function_exists('mb_strlen')) |
|
436 | - { |
|
437 | - $strlength=mb_strlen($line, 'UTF-8'); |
|
438 | - for ($j = 0; $j <= ($strlength - 1); $j++) |
|
439 | - { |
|
440 | - $char = mb_substr($line, $j, 1, 'UTF-8'); // Take char at position $j |
|
441 | - |
|
442 | - if ((mb_strlen($newpara, 'UTF-8') + mb_strlen($char, 'UTF-8')) >= 75) |
|
443 | - { |
|
444 | - $out .= $newpara . "\r\n "; // CRLF + Space for cal |
|
445 | - $newpara = ''; |
|
446 | - } |
|
447 | - $newpara .= $char; |
|
448 | - } |
|
449 | - $out .= $newpara; |
|
450 | - } |
|
451 | - else |
|
452 | - { |
|
453 | - $strlength=dol_strlen($line); |
|
454 | - for ($j = 0; $j <= ($strlength - 1); $j++) |
|
455 | - { |
|
456 | - $char = substr($line, $j, 1); // Take char at position $j |
|
457 | - |
|
458 | - if ((dol_strlen($newpara) + dol_strlen($char)) >= 75 ) |
|
459 | - { |
|
460 | - $out .= $newpara . "\r\n "; // CRLF + Space for cal |
|
461 | - $newpara = ''; |
|
462 | - } |
|
463 | - $newpara .= $char; |
|
464 | - } |
|
465 | - $out .= $newpara; |
|
466 | - } |
|
467 | - |
|
468 | - return trim($out); |
|
430 | + $out = ''; |
|
431 | + |
|
432 | + $newpara = ''; |
|
433 | + |
|
434 | + // If mb_ functions exists, it's better to use them |
|
435 | + if (function_exists('mb_strlen')) |
|
436 | + { |
|
437 | + $strlength=mb_strlen($line, 'UTF-8'); |
|
438 | + for ($j = 0; $j <= ($strlength - 1); $j++) |
|
439 | + { |
|
440 | + $char = mb_substr($line, $j, 1, 'UTF-8'); // Take char at position $j |
|
441 | + |
|
442 | + if ((mb_strlen($newpara, 'UTF-8') + mb_strlen($char, 'UTF-8')) >= 75) |
|
443 | + { |
|
444 | + $out .= $newpara . "\r\n "; // CRLF + Space for cal |
|
445 | + $newpara = ''; |
|
446 | + } |
|
447 | + $newpara .= $char; |
|
448 | + } |
|
449 | + $out .= $newpara; |
|
450 | + } |
|
451 | + else |
|
452 | + { |
|
453 | + $strlength=dol_strlen($line); |
|
454 | + for ($j = 0; $j <= ($strlength - 1); $j++) |
|
455 | + { |
|
456 | + $char = substr($line, $j, 1); // Take char at position $j |
|
457 | + |
|
458 | + if ((dol_strlen($newpara) + dol_strlen($char)) >= 75 ) |
|
459 | + { |
|
460 | + $out .= $newpara . "\r\n "; // CRLF + Space for cal |
|
461 | + $newpara = ''; |
|
462 | + } |
|
463 | + $newpara .= $char; |
|
464 | + } |
|
465 | + $out .= $newpara; |
|
466 | + } |
|
467 | + |
|
468 | + return trim($out); |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | |
@@ -478,33 +478,33 @@ discard block |
||
478 | 478 | */ |
479 | 479 | function quotedPrintEncode($str,$forcal=0) |
480 | 480 | { |
481 | - $lines = preg_split("/\r\n/", $str); |
|
482 | - $out = ''; |
|
483 | - |
|
484 | - foreach ($lines as $line) |
|
485 | - { |
|
486 | - $newpara = ''; |
|
487 | - |
|
488 | - $strlength=strlen($line); // Do not use dol_strlen here, we need number of bytes |
|
489 | - for ($j = 0; $j <= ($strlength - 1); $j++) |
|
490 | - { |
|
491 | - $char = substr($line, $j, 1); |
|
492 | - $ascii = ord($char); |
|
493 | - |
|
494 | - if ( $ascii < 32 || $ascii == 61 || $ascii > 126 ) |
|
495 | - $char = '=' . strtoupper(sprintf("%02X", $ascii)); |
|
496 | - |
|
497 | - if ((strlen($newpara) + strlen($char)) >= 76 ) // Do not use dol_strlen here, we need number of bytes |
|
498 | - { |
|
499 | - $out .= $newpara . '=' . "\r\n"; // CRLF |
|
500 | - if ($forcal) $out .= " "; // + Space for cal |
|
501 | - $newpara = ''; |
|
502 | - } |
|
503 | - $newpara .= $char; |
|
504 | - } |
|
505 | - $out .= $newpara; |
|
506 | - } |
|
507 | - return trim($out); |
|
481 | + $lines = preg_split("/\r\n/", $str); |
|
482 | + $out = ''; |
|
483 | + |
|
484 | + foreach ($lines as $line) |
|
485 | + { |
|
486 | + $newpara = ''; |
|
487 | + |
|
488 | + $strlength=strlen($line); // Do not use dol_strlen here, we need number of bytes |
|
489 | + for ($j = 0; $j <= ($strlength - 1); $j++) |
|
490 | + { |
|
491 | + $char = substr($line, $j, 1); |
|
492 | + $ascii = ord($char); |
|
493 | + |
|
494 | + if ( $ascii < 32 || $ascii == 61 || $ascii > 126 ) |
|
495 | + $char = '=' . strtoupper(sprintf("%02X", $ascii)); |
|
496 | + |
|
497 | + if ((strlen($newpara) + strlen($char)) >= 76 ) // Do not use dol_strlen here, we need number of bytes |
|
498 | + { |
|
499 | + $out .= $newpara . '=' . "\r\n"; // CRLF |
|
500 | + if ($forcal) $out .= " "; // + Space for cal |
|
501 | + $newpara = ''; |
|
502 | + } |
|
503 | + $newpara .= $char; |
|
504 | + } |
|
505 | + $out .= $newpara; |
|
506 | + } |
|
507 | + return trim($out); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | /** |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | */ |
516 | 516 | function quotedPrintDecode($str) |
517 | 517 | { |
518 | - $out = preg_replace('/=\r?\n/', '', $str); |
|
519 | - $out = quoted_printable_decode($out); // Available with PHP 4+ |
|
520 | - return trim($out); |
|
518 | + $out = preg_replace('/=\r?\n/', '', $str); |
|
519 | + $out = quoted_printable_decode($out); // Available with PHP 4+ |
|
520 | + return trim($out); |
|
521 | 521 | } |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | */ |
56 | 56 | function cron_prepare_head(Cronjob $object) |
57 | 57 | { |
58 | - global $langs, $conf, $user; |
|
59 | - $h = 0; |
|
60 | - $head = array(); |
|
58 | + global $langs, $conf, $user; |
|
59 | + $h = 0; |
|
60 | + $head = array(); |
|
61 | 61 | |
62 | - $head[$h][0] = dol_buildpath('/cron/card.php', 1).'?id='.$object->id; |
|
63 | - $head[$h][1] = $langs->trans("CronTask"); |
|
64 | - $head[$h][2] = 'card'; |
|
65 | - $h++; |
|
62 | + $head[$h][0] = dol_buildpath('/cron/card.php', 1).'?id='.$object->id; |
|
63 | + $head[$h][1] = $langs->trans("CronTask"); |
|
64 | + $head[$h][2] = 'card'; |
|
65 | + $h++; |
|
66 | 66 | |
67 | - $head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id; |
|
68 | - $head[$h][1] = $langs->trans("Info"); |
|
69 | - $head[$h][2] = 'info'; |
|
70 | - $h++; |
|
67 | + $head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id; |
|
68 | + $head[$h][1] = $langs->trans("Info"); |
|
69 | + $head[$h][2] = 'info'; |
|
70 | + $h++; |
|
71 | 71 | |
72 | - complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron'); |
|
72 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron'); |
|
73 | 73 | |
74 | - complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove'); |
|
74 | + complete_head_from_modules($conf, $langs, $object, $head, $h, 'cron', 'remove'); |
|
75 | 75 | |
76 | - return $head; |
|
76 | + return $head; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,54 +83,54 @@ discard block |
||
83 | 83 | */ |
84 | 84 | function dol_print_cron_urls() |
85 | 85 | { |
86 | - global $conf, $langs, $user; |
|
87 | - global $dolibarr_main_url_root; |
|
88 | - |
|
89 | - // Define $urlwithroot |
|
90 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
91 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
92 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
93 | - |
|
94 | - // Cron launch |
|
95 | - print '<div class="div-table-responsive-no-min">'; |
|
96 | - print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>'; |
|
97 | - $url=$urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY)?'':'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login; |
|
98 | - print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
99 | - print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>'; |
|
100 | - $url=$urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY)?'':'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; |
|
101 | - print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
86 | + global $conf, $langs, $user; |
|
87 | + global $dolibarr_main_url_root; |
|
88 | + |
|
89 | + // Define $urlwithroot |
|
90 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
91 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
92 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
93 | + |
|
94 | + // Cron launch |
|
95 | + print '<div class="div-table-responsive-no-min">'; |
|
96 | + print '<u>'.$langs->trans("URLToLaunchCronJobs").':</u><br>'; |
|
97 | + $url=$urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY)?'':'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login; |
|
98 | + print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
99 | + print ' '.$langs->trans("OrToLaunchASpecificJob").'<br>'; |
|
100 | + $url=$urlwithroot.'/public/cron/cron_run_jobs.php?'.(empty($conf->global->CRON_KEY)?'':'securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; |
|
101 | + print img_picto('','object_globe.png').' <a href="'.$url.'" target="_blank">'.$url."</a><br>\n"; |
|
102 | 102 | print '</div>'; |
103 | 103 | print '<br>'; |
104 | 104 | |
105 | - $logintouse = 'firstadmin'; |
|
106 | - if ($user->admin) $logintouse = $user->login; |
|
105 | + $logintouse = 'firstadmin'; |
|
106 | + if ($user->admin) $logintouse = $user->login; |
|
107 | 107 | |
108 | - print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>'; |
|
109 | - |
|
110 | - $file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$logintouse.' [cronjobid]'; |
|
111 | - print '<textarea class="quatrevingtpercent">..'.$file."</textarea><br>\n"; |
|
112 | - print '<br>'; |
|
113 | - |
|
114 | - // Add note |
|
115 | - if (empty($conf->global->CRON_DISABLE_TUTORIAL_CRON)) |
|
116 | - { |
|
117 | - $linuxlike=1; |
|
118 | - if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
119 | - if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
120 | - print $langs->trans("Note").': '; |
|
121 | - if ($linuxlike) |
|
122 | - { |
|
123 | - print $langs->trans("CronExplainHowToRunUnix"); |
|
124 | - print '<br>'; |
|
125 | - print '<textarea class="quatrevingtpercent">*/5 * * * * pathtoscript/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$logintouse.' > '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>'; |
|
126 | - } |
|
127 | - else |
|
128 | - { |
|
129 | - print $langs->trans("CronExplainHowToRunWin"); |
|
130 | - } |
|
131 | - } |
|
108 | + print '<u>'.$langs->trans("FileToLaunchCronJobs").':</u><br>'; |
|
109 | + |
|
110 | + $file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$logintouse.' [cronjobid]'; |
|
111 | + print '<textarea class="quatrevingtpercent">..'.$file."</textarea><br>\n"; |
|
112 | + print '<br>'; |
|
113 | + |
|
114 | + // Add note |
|
115 | + if (empty($conf->global->CRON_DISABLE_TUTORIAL_CRON)) |
|
116 | + { |
|
117 | + $linuxlike=1; |
|
118 | + if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
119 | + if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
120 | + print $langs->trans("Note").': '; |
|
121 | + if ($linuxlike) |
|
122 | + { |
|
123 | + print $langs->trans("CronExplainHowToRunUnix"); |
|
124 | + print '<br>'; |
|
125 | + print '<textarea class="quatrevingtpercent">*/5 * * * * pathtoscript/scripts/cron/cron_run_jobs.php '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$logintouse.' > '.DOL_DATA_ROOT.'/cron_run_jobs.php.log</textarea><br>'; |
|
126 | + } |
|
127 | + else |
|
128 | + { |
|
129 | + print $langs->trans("CronExplainHowToRunWin"); |
|
130 | + } |
|
131 | + } |
|
132 | 132 | |
133 | - return 0; |
|
133 | + return 0; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 |
@@ -40,86 +40,86 @@ |
||
40 | 40 | */ |
41 | 41 | function report_header($reportname,$notused,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='') |
42 | 42 | { |
43 | - global $langs; |
|
44 | - |
|
45 | - if (empty($hselected)) $hselected='report'; |
|
46 | - |
|
47 | - print "\n\n<!-- start banner of report -->\n"; |
|
48 | - |
|
49 | - if(! empty($varlink)) $varlink = '?'.$varlink; |
|
50 | - |
|
51 | - $h=0; |
|
52 | - $head[$h][0] = $_SERVER["PHP_SELF"].$varlink; |
|
53 | - $head[$h][1] = $langs->trans("Report"); |
|
54 | - $head[$h][2] = 'report'; |
|
55 | - |
|
56 | - print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">'; |
|
57 | - |
|
58 | - dol_fiche_head($head, 'report'); |
|
59 | - |
|
60 | - foreach($moreparam as $key => $value) |
|
61 | - { |
|
62 | - print '<input type="hidden" name="'.$key.'" value="'.$value.'">'; |
|
63 | - } |
|
64 | - print '<table width="100%" class="border">'; |
|
65 | - |
|
66 | - $variante = ($periodlink || $exportlink); |
|
67 | - |
|
68 | - // Ligne de titre |
|
69 | - print '<tr>'; |
|
70 | - print '<td width="110">'.$langs->trans("ReportName").'</td>'; |
|
71 | - print '<td>'; |
|
72 | - print $reportname; |
|
73 | - print '</td>'; |
|
74 | - if ($variante) print '<td></td>'; |
|
75 | - print '</tr>'; |
|
76 | - |
|
77 | - // Calculation mode |
|
78 | - if ($calcmode) |
|
79 | - { |
|
80 | - print '<tr>'; |
|
81 | - print '<td width="110">'.$langs->trans("CalculationMode").'</td>'; |
|
82 | - print '<td>'; |
|
83 | - print $calcmode; |
|
84 | - if ($variante) print '<td></td>'; |
|
85 | - print '</td>'; |
|
86 | - print '</tr>'; |
|
87 | - } |
|
88 | - |
|
89 | - // Ligne de la periode d'analyse du rapport |
|
90 | - print '<tr>'; |
|
91 | - print '<td>'.$langs->trans("ReportPeriod").'</td>'; |
|
92 | - print '<td>'; |
|
93 | - if ($period) print $period; |
|
94 | - if ($variante) print '<td class="nowraponall">'.$periodlink.'</td>'; |
|
95 | - print '</td>'; |
|
96 | - print '</tr>'; |
|
97 | - |
|
98 | - // Ligne de description |
|
99 | - print '<tr>'; |
|
100 | - print '<td>'.$langs->trans("ReportDescription").'</td>'; |
|
101 | - print '<td>'.$description.'</td>'; |
|
102 | - if ($variante) print '<td></td>'; |
|
103 | - print '</tr>'; |
|
104 | - |
|
105 | - // Ligne d'export |
|
106 | - print '<tr>'; |
|
107 | - print '<td>'.$langs->trans("GeneratedOn").'</td>'; |
|
108 | - print '<td>'; |
|
109 | - print dol_print_date($builddate, 'dayhour'); |
|
110 | - print '</td>'; |
|
111 | - if ($variante) print '<td>'.($exportlink ? $langs->trans("Export").': '.$exportlink : '').'</td>'; |
|
112 | - print '</tr>'; |
|
113 | - |
|
114 | - print '</table>'; |
|
115 | - |
|
116 | - dol_fiche_end(); |
|
117 | - |
|
118 | - print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>'; |
|
119 | - |
|
120 | - print '</form>'; |
|
121 | - print '<br>'; |
|
122 | - |
|
123 | - print "\n<!-- end banner of report -->\n\n"; |
|
43 | + global $langs; |
|
44 | + |
|
45 | + if (empty($hselected)) $hselected='report'; |
|
46 | + |
|
47 | + print "\n\n<!-- start banner of report -->\n"; |
|
48 | + |
|
49 | + if(! empty($varlink)) $varlink = '?'.$varlink; |
|
50 | + |
|
51 | + $h=0; |
|
52 | + $head[$h][0] = $_SERVER["PHP_SELF"].$varlink; |
|
53 | + $head[$h][1] = $langs->trans("Report"); |
|
54 | + $head[$h][2] = 'report'; |
|
55 | + |
|
56 | + print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">'; |
|
57 | + |
|
58 | + dol_fiche_head($head, 'report'); |
|
59 | + |
|
60 | + foreach($moreparam as $key => $value) |
|
61 | + { |
|
62 | + print '<input type="hidden" name="'.$key.'" value="'.$value.'">'; |
|
63 | + } |
|
64 | + print '<table width="100%" class="border">'; |
|
65 | + |
|
66 | + $variante = ($periodlink || $exportlink); |
|
67 | + |
|
68 | + // Ligne de titre |
|
69 | + print '<tr>'; |
|
70 | + print '<td width="110">'.$langs->trans("ReportName").'</td>'; |
|
71 | + print '<td>'; |
|
72 | + print $reportname; |
|
73 | + print '</td>'; |
|
74 | + if ($variante) print '<td></td>'; |
|
75 | + print '</tr>'; |
|
76 | + |
|
77 | + // Calculation mode |
|
78 | + if ($calcmode) |
|
79 | + { |
|
80 | + print '<tr>'; |
|
81 | + print '<td width="110">'.$langs->trans("CalculationMode").'</td>'; |
|
82 | + print '<td>'; |
|
83 | + print $calcmode; |
|
84 | + if ($variante) print '<td></td>'; |
|
85 | + print '</td>'; |
|
86 | + print '</tr>'; |
|
87 | + } |
|
88 | + |
|
89 | + // Ligne de la periode d'analyse du rapport |
|
90 | + print '<tr>'; |
|
91 | + print '<td>'.$langs->trans("ReportPeriod").'</td>'; |
|
92 | + print '<td>'; |
|
93 | + if ($period) print $period; |
|
94 | + if ($variante) print '<td class="nowraponall">'.$periodlink.'</td>'; |
|
95 | + print '</td>'; |
|
96 | + print '</tr>'; |
|
97 | + |
|
98 | + // Ligne de description |
|
99 | + print '<tr>'; |
|
100 | + print '<td>'.$langs->trans("ReportDescription").'</td>'; |
|
101 | + print '<td>'.$description.'</td>'; |
|
102 | + if ($variante) print '<td></td>'; |
|
103 | + print '</tr>'; |
|
104 | + |
|
105 | + // Ligne d'export |
|
106 | + print '<tr>'; |
|
107 | + print '<td>'.$langs->trans("GeneratedOn").'</td>'; |
|
108 | + print '<td>'; |
|
109 | + print dol_print_date($builddate, 'dayhour'); |
|
110 | + print '</td>'; |
|
111 | + if ($variante) print '<td>'.($exportlink ? $langs->trans("Export").': '.$exportlink : '').'</td>'; |
|
112 | + print '</tr>'; |
|
113 | + |
|
114 | + print '</table>'; |
|
115 | + |
|
116 | + dol_fiche_end(); |
|
117 | + |
|
118 | + print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>'; |
|
119 | + |
|
120 | + print '</form>'; |
|
121 | + print '<br>'; |
|
122 | + |
|
123 | + print "\n<!-- end banner of report -->\n\n"; |
|
124 | 124 | } |
125 | 125 |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | */ |
35 | 35 | if (GETPOST('addfile','alpha')) |
36 | 36 | { |
37 | - $trackid = GETPOST('trackid','aZ09'); |
|
37 | + $trackid = GETPOST('trackid','aZ09'); |
|
38 | 38 | |
39 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
39 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
40 | 40 | |
41 | - // Set tmp user directory |
|
42 | - $vardir=$conf->user->dir_output."/".$user->id; |
|
43 | - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path |
|
41 | + // Set tmp user directory |
|
42 | + $vardir=$conf->user->dir_output."/".$user->id; |
|
43 | + $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path |
|
44 | 44 | |
45 | - dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', '', null, $trackid, 0); |
|
46 | - $action='presend'; |
|
45 | + dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', '', null, $trackid, 0); |
|
46 | + $action='presend'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /* |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | */ |
52 | 52 | if (! empty($_POST['removedfile']) && empty($_POST['removAll'])) |
53 | 53 | { |
54 | - $trackid = GETPOST('trackid','aZ09'); |
|
54 | + $trackid = GETPOST('trackid','aZ09'); |
|
55 | 55 | |
56 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
56 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
57 | 57 | |
58 | - // Set tmp user directory |
|
59 | - $vardir=$conf->user->dir_output."/".$user->id; |
|
60 | - $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path |
|
58 | + // Set tmp user directory |
|
59 | + $vardir=$conf->user->dir_output."/".$user->id; |
|
60 | + $upload_dir_tmp = $vardir.'/temp'; // TODO Add $keytoavoidconflict in upload_dir path |
|
61 | 61 | |
62 | - // TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir" |
|
63 | - // GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array. |
|
64 | - dol_remove_file_process(GETPOST('removedfile','alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically |
|
65 | - $action='presend'; |
|
62 | + // TODO Delete only files that was uploaded from email form. This can be addressed by adding the trackid into the temp path then changing donotdeletefile to 2 instead of 1 to say "delete only if into temp dir" |
|
63 | + // GETPOST('removedfile','alpha') is position of file into $_SESSION["listofpaths"...] array. |
|
64 | + dol_remove_file_process(GETPOST('removedfile','alpha'), 0, 1, $trackid); // We do not delete because if file is the official PDF of doc, we don't want to remove it physically |
|
65 | + $action='presend'; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /* |
@@ -70,31 +70,31 @@ discard block |
||
70 | 70 | */ |
71 | 71 | if (GETPOST('removAll','alpha')) |
72 | 72 | { |
73 | - $trackid = GETPOST('trackid','aZ09'); |
|
74 | - |
|
75 | - $listofpaths=array(); |
|
76 | - $listofnames=array(); |
|
77 | - $listofmimes=array(); |
|
78 | - $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
79 | - if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
80 | - if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
81 | - if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
82 | - |
|
83 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
84 | - $formmail = new FormMail($db); |
|
85 | - $formmail->trackid = $trackid; |
|
86 | - |
|
87 | - foreach($listofpaths as $key => $value) |
|
88 | - { |
|
89 | - $pathtodelete = $value; |
|
90 | - $filetodelete = $listofnames[$key]; |
|
91 | - $result = dol_delete_file($pathtodelete,1); // Delete uploded Files |
|
92 | - |
|
93 | - $langs->load("other"); |
|
94 | - setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs'); |
|
95 | - |
|
96 | - $formmail->remove_attached_files($key); // Update Session |
|
97 | - } |
|
73 | + $trackid = GETPOST('trackid','aZ09'); |
|
74 | + |
|
75 | + $listofpaths=array(); |
|
76 | + $listofnames=array(); |
|
77 | + $listofmimes=array(); |
|
78 | + $keytoavoidconflict = empty($trackid)?'':'-'.$trackid; |
|
79 | + if (! empty($_SESSION["listofpaths".$keytoavoidconflict])) $listofpaths=explode(';',$_SESSION["listofpaths".$keytoavoidconflict]); |
|
80 | + if (! empty($_SESSION["listofnames".$keytoavoidconflict])) $listofnames=explode(';',$_SESSION["listofnames".$keytoavoidconflict]); |
|
81 | + if (! empty($_SESSION["listofmimes".$keytoavoidconflict])) $listofmimes=explode(';',$_SESSION["listofmimes".$keytoavoidconflict]); |
|
82 | + |
|
83 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
84 | + $formmail = new FormMail($db); |
|
85 | + $formmail->trackid = $trackid; |
|
86 | + |
|
87 | + foreach($listofpaths as $key => $value) |
|
88 | + { |
|
89 | + $pathtodelete = $value; |
|
90 | + $filetodelete = $listofnames[$key]; |
|
91 | + $result = dol_delete_file($pathtodelete,1); // Delete uploded Files |
|
92 | + |
|
93 | + $langs->load("other"); |
|
94 | + setEventMessages($langs->trans("FileWasRemoved",$filetodelete), null, 'mesgs'); |
|
95 | + |
|
96 | + $formmail->remove_attached_files($key); // Update Session |
|
97 | + } |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /* |
@@ -102,244 +102,244 @@ discard block |
||
102 | 102 | */ |
103 | 103 | if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removAll'] && ! $_POST['removedfile'] && ! $_POST['cancel'] && !$_POST['modelselected']) |
104 | 104 | { |
105 | - if (empty($trackid)) $trackid = GETPOST('trackid','aZ09'); |
|
106 | - |
|
107 | - $subject='';$actionmsg='';$actionmsg2=''; |
|
108 | - |
|
109 | - $langs->load('mails'); |
|
110 | - |
|
111 | - if (is_object($object)) |
|
112 | - { |
|
113 | - $result=$object->fetch($id); |
|
114 | - |
|
115 | - $sendtosocid=0; // Thirdparty on object |
|
116 | - if (method_exists($object,"fetch_thirdparty") && ! in_array($object->element, array('societe','member','user','expensereport', 'contact'))) |
|
117 | - { |
|
118 | - $result=$object->fetch_thirdparty(); |
|
119 | - if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok |
|
120 | - $thirdparty=$object->thirdparty; |
|
121 | - $sendtosocid=$thirdparty->id; |
|
122 | - } |
|
123 | - else if ($object->element == 'member' || $object->element == 'user') |
|
124 | - { |
|
125 | - $thirdparty=$object; |
|
126 | - if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; |
|
127 | - } |
|
128 | - else if ($object->element == 'societe') |
|
129 | - { |
|
130 | - $thirdparty=$object; |
|
131 | - if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; |
|
132 | - } |
|
133 | - else if ($object->element == 'contact') |
|
134 | - { |
|
135 | - $contact=$object; |
|
136 | - if ($contact->id > 0) $sendtosocid=$contact->fetch_thirdparty()->id; |
|
137 | - } |
|
138 | - else dol_print_error('','Use actions_sendmails.in.php for an element/object that is not supported'); |
|
139 | - |
|
140 | - if (is_object($hookmanager)) |
|
141 | - { |
|
142 | - $parameters=array(); |
|
143 | - $reshook=$hookmanager->executeHooks('initSendToSocid',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
144 | - } |
|
145 | - } |
|
146 | - else $thirdparty = $mysoc; |
|
147 | - |
|
148 | - if ($result > 0) |
|
149 | - { |
|
150 | - $sendto=''; |
|
151 | - $sendtocc=''; |
|
152 | - $sendtobcc=''; |
|
153 | - $sendtoid = array(); |
|
154 | - $sendtouserid=array(); |
|
155 | - $sendtoccuserid=array(); |
|
156 | - |
|
157 | - // Define $sendto |
|
158 | - $receiver=$_POST['receiver']; |
|
159 | - if (! is_array($receiver)) |
|
160 | - { |
|
161 | - if ($receiver == '-1') $receiver=array(); |
|
162 | - else $receiver=array($receiver); |
|
163 | - } |
|
164 | - $tmparray=array(); |
|
165 | - if (trim($_POST['sendto'])) |
|
166 | - { |
|
167 | - // Recipients are provided into free text |
|
168 | - $tmparray[] = trim($_POST['sendto']); |
|
169 | - } |
|
170 | - if (count($receiver)>0) |
|
171 | - { |
|
172 | - foreach($receiver as $key=>$val) |
|
173 | - { |
|
174 | - // Recipient was provided from combo list |
|
175 | - if ($val == 'thirdparty') // Id of third party |
|
176 | - { |
|
177 | - $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; |
|
178 | - } |
|
179 | - // Recipient was provided from combo list |
|
180 | - elseif ($val == 'contact') // Id of contact |
|
181 | - { |
|
182 | - $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; |
|
183 | - } |
|
184 | - elseif ($val) // Id du contact |
|
185 | - { |
|
186 | - $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
|
187 | - $sendtoid[] = $val; |
|
188 | - } |
|
189 | - } |
|
190 | - } |
|
191 | - if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) |
|
192 | - { |
|
193 | - $receiveruser=$_POST['receiveruser']; |
|
194 | - if (is_array($receiveruser) && count($receiveruser)>0) |
|
195 | - { |
|
196 | - $fuserdest = new User($db); |
|
197 | - foreach($receiveruser as $key=>$val) |
|
198 | - { |
|
199 | - $tmparray[] = $fuserdest->user_get_property($val,'email'); |
|
200 | - $sendtouserid[] = $val; |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - $sendto=implode(',',$tmparray); |
|
206 | - |
|
207 | - // Define $sendtocc |
|
208 | - $receivercc=$_POST['receivercc']; |
|
209 | - if (! is_array($receivercc)) |
|
210 | - { |
|
211 | - if ($receivercc == '-1') $receivercc=array(); |
|
212 | - else $receivercc=array($receivercc); |
|
213 | - } |
|
214 | - $tmparray=array(); |
|
215 | - if (trim($_POST['sendtocc'])) |
|
216 | - { |
|
217 | - $tmparray[] = trim($_POST['sendtocc']); |
|
218 | - } |
|
219 | - if (count($receivercc) > 0) |
|
220 | - { |
|
221 | - foreach($receivercc as $key=>$val) |
|
222 | - { |
|
223 | - // Recipient was provided from combo list |
|
224 | - if ($val == 'thirdparty') // Id of third party |
|
225 | - { |
|
226 | - $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; |
|
227 | - } |
|
228 | - // Recipient was provided from combo list |
|
229 | - elseif ($val == 'contact') // Id of contact |
|
230 | - { |
|
231 | - $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; |
|
232 | - } |
|
233 | - elseif ($val) // Id du contact |
|
234 | - { |
|
235 | - $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
|
236 | - //$sendtoid[] = $val; TODO Add also id of contact in CC ? |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
|
241 | - $receiverccuser=$_POST['receiverccuser']; |
|
242 | - |
|
243 | - if (is_array($receiverccuser) && count($receiverccuser)>0) |
|
244 | - { |
|
245 | - $fuserdest = new User($db); |
|
246 | - foreach($receiverccuser as $key=>$val) |
|
247 | - { |
|
248 | - $tmparray[] = $fuserdest->user_get_property($val,'email'); |
|
249 | - $sendtoccuserid[] = $val; |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - $sendtocc=implode(',',$tmparray); |
|
254 | - |
|
255 | - if (dol_strlen($sendto)) |
|
256 | - { |
|
105 | + if (empty($trackid)) $trackid = GETPOST('trackid','aZ09'); |
|
106 | + |
|
107 | + $subject='';$actionmsg='';$actionmsg2=''; |
|
108 | + |
|
109 | + $langs->load('mails'); |
|
110 | + |
|
111 | + if (is_object($object)) |
|
112 | + { |
|
113 | + $result=$object->fetch($id); |
|
114 | + |
|
115 | + $sendtosocid=0; // Thirdparty on object |
|
116 | + if (method_exists($object,"fetch_thirdparty") && ! in_array($object->element, array('societe','member','user','expensereport', 'contact'))) |
|
117 | + { |
|
118 | + $result=$object->fetch_thirdparty(); |
|
119 | + if ($object->element == 'user' && $result == 0) $result=1; // Even if not found, we consider ok |
|
120 | + $thirdparty=$object->thirdparty; |
|
121 | + $sendtosocid=$thirdparty->id; |
|
122 | + } |
|
123 | + else if ($object->element == 'member' || $object->element == 'user') |
|
124 | + { |
|
125 | + $thirdparty=$object; |
|
126 | + if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; |
|
127 | + } |
|
128 | + else if ($object->element == 'societe') |
|
129 | + { |
|
130 | + $thirdparty=$object; |
|
131 | + if ($thirdparty->id > 0) $sendtosocid=$thirdparty->id; |
|
132 | + } |
|
133 | + else if ($object->element == 'contact') |
|
134 | + { |
|
135 | + $contact=$object; |
|
136 | + if ($contact->id > 0) $sendtosocid=$contact->fetch_thirdparty()->id; |
|
137 | + } |
|
138 | + else dol_print_error('','Use actions_sendmails.in.php for an element/object that is not supported'); |
|
139 | + |
|
140 | + if (is_object($hookmanager)) |
|
141 | + { |
|
142 | + $parameters=array(); |
|
143 | + $reshook=$hookmanager->executeHooks('initSendToSocid',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
144 | + } |
|
145 | + } |
|
146 | + else $thirdparty = $mysoc; |
|
147 | + |
|
148 | + if ($result > 0) |
|
149 | + { |
|
150 | + $sendto=''; |
|
151 | + $sendtocc=''; |
|
152 | + $sendtobcc=''; |
|
153 | + $sendtoid = array(); |
|
154 | + $sendtouserid=array(); |
|
155 | + $sendtoccuserid=array(); |
|
156 | + |
|
157 | + // Define $sendto |
|
158 | + $receiver=$_POST['receiver']; |
|
159 | + if (! is_array($receiver)) |
|
160 | + { |
|
161 | + if ($receiver == '-1') $receiver=array(); |
|
162 | + else $receiver=array($receiver); |
|
163 | + } |
|
164 | + $tmparray=array(); |
|
165 | + if (trim($_POST['sendto'])) |
|
166 | + { |
|
167 | + // Recipients are provided into free text |
|
168 | + $tmparray[] = trim($_POST['sendto']); |
|
169 | + } |
|
170 | + if (count($receiver)>0) |
|
171 | + { |
|
172 | + foreach($receiver as $key=>$val) |
|
173 | + { |
|
174 | + // Recipient was provided from combo list |
|
175 | + if ($val == 'thirdparty') // Id of third party |
|
176 | + { |
|
177 | + $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; |
|
178 | + } |
|
179 | + // Recipient was provided from combo list |
|
180 | + elseif ($val == 'contact') // Id of contact |
|
181 | + { |
|
182 | + $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; |
|
183 | + } |
|
184 | + elseif ($val) // Id du contact |
|
185 | + { |
|
186 | + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
|
187 | + $sendtoid[] = $val; |
|
188 | + } |
|
189 | + } |
|
190 | + } |
|
191 | + if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) |
|
192 | + { |
|
193 | + $receiveruser=$_POST['receiveruser']; |
|
194 | + if (is_array($receiveruser) && count($receiveruser)>0) |
|
195 | + { |
|
196 | + $fuserdest = new User($db); |
|
197 | + foreach($receiveruser as $key=>$val) |
|
198 | + { |
|
199 | + $tmparray[] = $fuserdest->user_get_property($val,'email'); |
|
200 | + $sendtouserid[] = $val; |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + $sendto=implode(',',$tmparray); |
|
206 | + |
|
207 | + // Define $sendtocc |
|
208 | + $receivercc=$_POST['receivercc']; |
|
209 | + if (! is_array($receivercc)) |
|
210 | + { |
|
211 | + if ($receivercc == '-1') $receivercc=array(); |
|
212 | + else $receivercc=array($receivercc); |
|
213 | + } |
|
214 | + $tmparray=array(); |
|
215 | + if (trim($_POST['sendtocc'])) |
|
216 | + { |
|
217 | + $tmparray[] = trim($_POST['sendtocc']); |
|
218 | + } |
|
219 | + if (count($receivercc) > 0) |
|
220 | + { |
|
221 | + foreach($receivercc as $key=>$val) |
|
222 | + { |
|
223 | + // Recipient was provided from combo list |
|
224 | + if ($val == 'thirdparty') // Id of third party |
|
225 | + { |
|
226 | + $tmparray[] = dol_string_nospecial($thirdparty->name, ' ', array(",")).' <'.$thirdparty->email.'>'; |
|
227 | + } |
|
228 | + // Recipient was provided from combo list |
|
229 | + elseif ($val == 'contact') // Id of contact |
|
230 | + { |
|
231 | + $tmparray[] = dol_string_nospecial($contact->name, ' ', array(",")).' <'.$contact->email.'>'; |
|
232 | + } |
|
233 | + elseif ($val) // Id du contact |
|
234 | + { |
|
235 | + $tmparray[] = $thirdparty->contact_get_property((int) $val,'email'); |
|
236 | + //$sendtoid[] = $val; TODO Add also id of contact in CC ? |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + if (!empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
|
241 | + $receiverccuser=$_POST['receiverccuser']; |
|
242 | + |
|
243 | + if (is_array($receiverccuser) && count($receiverccuser)>0) |
|
244 | + { |
|
245 | + $fuserdest = new User($db); |
|
246 | + foreach($receiverccuser as $key=>$val) |
|
247 | + { |
|
248 | + $tmparray[] = $fuserdest->user_get_property($val,'email'); |
|
249 | + $sendtoccuserid[] = $val; |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + $sendtocc=implode(',',$tmparray); |
|
254 | + |
|
255 | + if (dol_strlen($sendto)) |
|
256 | + { |
|
257 | 257 | // Define $urlwithroot |
258 | 258 | $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
259 | 259 | $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
260 | 260 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
261 | 261 | |
262 | - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
263 | - |
|
264 | - $langs->load("commercial"); |
|
265 | - |
|
266 | - $fromtype = GETPOST('fromtype','alpha'); |
|
267 | - if ($fromtype === 'robot') { |
|
268 | - $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")) .' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; |
|
269 | - } |
|
270 | - elseif ($fromtype === 'user') { |
|
271 | - $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")) .' <'.$user->email.'>'; |
|
272 | - } |
|
273 | - elseif ($fromtype === 'company') { |
|
274 | - $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")) .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; |
|
275 | - } |
|
276 | - elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { |
|
277 | - $tmp=explode(',', $user->email_aliases); |
|
278 | - $from = trim($tmp[($reg[1] - 1)]); |
|
279 | - } |
|
280 | - elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { |
|
281 | - $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); |
|
282 | - $from = trim($tmp[($reg[1] - 1)]); |
|
283 | - } |
|
284 | - elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { |
|
285 | - $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; |
|
286 | - $resql = $db->query($sql); |
|
287 | - $obj = $db->fetch_object($resql); |
|
288 | - if ($obj) |
|
289 | - { |
|
290 | - $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; |
|
291 | - } |
|
292 | - } |
|
293 | - else { |
|
294 | - $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")) . ' <' . $_POST['frommail'] .'>'; |
|
295 | - } |
|
296 | - |
|
297 | - $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")). ' <' . $_POST['replytomail'].'>'; |
|
298 | - $message = GETPOST('message','none'); |
|
299 | - $subject = GETPOST('subject','none'); |
|
300 | - |
|
301 | - // Make a change into HTML code to allow to include images from medias directory with an external reabable URL. |
|
302 | - // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
303 | - // become |
|
304 | - // <img alt="" src="'.$urlwithroot.'viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
305 | - $message=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); |
|
306 | - |
|
307 | - $sendtobcc= GETPOST('sendtoccc'); |
|
308 | - // Autocomplete the $sendtobcc |
|
309 | - // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO... |
|
310 | - if (! empty($autocopy)) |
|
311 | - { |
|
312 | - $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc?", ":"").$conf->global->$autocopy)); |
|
313 | - } |
|
314 | - |
|
315 | - $deliveryreceipt = $_POST['deliveryreceipt']; |
|
316 | - |
|
317 | - if ($action == 'send' || $action == 'relance') |
|
318 | - { |
|
319 | - $actionmsg2=$langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from,4,0,1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto,4,0,1); |
|
320 | - if ($message) |
|
321 | - { |
|
322 | - $actionmsg=$langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); |
|
323 | - $actionmsg=dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); |
|
324 | - if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . dol_escape_htmltag($sendtocc)); |
|
325 | - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); |
|
326 | - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); |
|
327 | - $actionmsg = dol_concatdesc($actionmsg, $message); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - // Create form object |
|
332 | - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
333 | - $formmail = new FormMail($db); |
|
334 | - $formmail->trackid = $trackid; // $trackid must be defined |
|
335 | - |
|
336 | - $attachedfiles=$formmail->get_attached_files(); |
|
337 | - $filepath = $attachedfiles['paths']; |
|
338 | - $filename = $attachedfiles['names']; |
|
339 | - $mimetype = $attachedfiles['mimes']; |
|
340 | - |
|
341 | - // Feature to push mail sent into Sent folder |
|
342 | - /* This code must be now included into the hook mail, method sendMailAfter |
|
262 | + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
263 | + |
|
264 | + $langs->load("commercial"); |
|
265 | + |
|
266 | + $fromtype = GETPOST('fromtype','alpha'); |
|
267 | + if ($fromtype === 'robot') { |
|
268 | + $from = dol_string_nospecial($conf->global->MAIN_MAIL_EMAIL_FROM, ' ', array(",")) .' <'.$conf->global->MAIN_MAIL_EMAIL_FROM.'>'; |
|
269 | + } |
|
270 | + elseif ($fromtype === 'user') { |
|
271 | + $from = dol_string_nospecial($user->getFullName($langs), ' ', array(",")) .' <'.$user->email.'>'; |
|
272 | + } |
|
273 | + elseif ($fromtype === 'company') { |
|
274 | + $from = dol_string_nospecial($conf->global->MAIN_INFO_SOCIETE_NOM, ' ', array(",")) .' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.'>'; |
|
275 | + } |
|
276 | + elseif (preg_match('/user_aliases_(\d+)/', $fromtype, $reg)) { |
|
277 | + $tmp=explode(',', $user->email_aliases); |
|
278 | + $from = trim($tmp[($reg[1] - 1)]); |
|
279 | + } |
|
280 | + elseif (preg_match('/global_aliases_(\d+)/', $fromtype, $reg)) { |
|
281 | + $tmp=explode(',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES); |
|
282 | + $from = trim($tmp[($reg[1] - 1)]); |
|
283 | + } |
|
284 | + elseif (preg_match('/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) { |
|
285 | + $sql='SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.'c_email_senderprofile WHERE rowid = '.(int) $reg[1]; |
|
286 | + $resql = $db->query($sql); |
|
287 | + $obj = $db->fetch_object($resql); |
|
288 | + if ($obj) |
|
289 | + { |
|
290 | + $from = dol_string_nospecial($obj->label, ' ', array(",")).' <'.$obj->email.'>'; |
|
291 | + } |
|
292 | + } |
|
293 | + else { |
|
294 | + $from = dol_string_nospecial($_POST['fromname'], ' ', array(",")) . ' <' . $_POST['frommail'] .'>'; |
|
295 | + } |
|
296 | + |
|
297 | + $replyto = dol_string_nospecial($_POST['replytoname'], ' ', array(",")). ' <' . $_POST['replytomail'].'>'; |
|
298 | + $message = GETPOST('message','none'); |
|
299 | + $subject = GETPOST('subject','none'); |
|
300 | + |
|
301 | + // Make a change into HTML code to allow to include images from medias directory with an external reabable URL. |
|
302 | + // <img alt="" src="/dolibarr_dev/htdocs/viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
303 | + // become |
|
304 | + // <img alt="" src="'.$urlwithroot.'viewimage.php?modulepart=medias&entity=1&file=image/ldestailleur_166x166.jpg" style="height:166px; width:166px" /> |
|
305 | + $message=preg_replace('/(<img.*src=")[^\"]*viewimage\.php([^\"]*)modulepart=medias([^\"]*)file=([^\"]*)("[^\/]*\/>)/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); |
|
306 | + |
|
307 | + $sendtobcc= GETPOST('sendtoccc'); |
|
308 | + // Autocomplete the $sendtobcc |
|
309 | + // $autocopy can be MAIN_MAIL_AUTOCOPY_PROPOSAL_TO, MAIN_MAIL_AUTOCOPY_ORDER_TO, MAIN_MAIL_AUTOCOPY_INVOICE_TO, MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO... |
|
310 | + if (! empty($autocopy)) |
|
311 | + { |
|
312 | + $sendtobcc .= (empty($conf->global->$autocopy) ? '' : (($sendtobcc?", ":"").$conf->global->$autocopy)); |
|
313 | + } |
|
314 | + |
|
315 | + $deliveryreceipt = $_POST['deliveryreceipt']; |
|
316 | + |
|
317 | + if ($action == 'send' || $action == 'relance') |
|
318 | + { |
|
319 | + $actionmsg2=$langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from,4,0,1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto,4,0,1); |
|
320 | + if ($message) |
|
321 | + { |
|
322 | + $actionmsg=$langs->transnoentities('MailFrom').': '.dol_escape_htmltag($from); |
|
323 | + $actionmsg=dol_concatdesc($actionmsg, $langs->transnoentities('MailTo').': '.dol_escape_htmltag($sendto)); |
|
324 | + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . dol_escape_htmltag($sendtocc)); |
|
325 | + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject); |
|
326 | + $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":"); |
|
327 | + $actionmsg = dol_concatdesc($actionmsg, $message); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + // Create form object |
|
332 | + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; |
|
333 | + $formmail = new FormMail($db); |
|
334 | + $formmail->trackid = $trackid; // $trackid must be defined |
|
335 | + |
|
336 | + $attachedfiles=$formmail->get_attached_files(); |
|
337 | + $filepath = $attachedfiles['paths']; |
|
338 | + $filename = $attachedfiles['names']; |
|
339 | + $mimetype = $attachedfiles['mimes']; |
|
340 | + |
|
341 | + // Feature to push mail sent into Sent folder |
|
342 | + /* This code must be now included into the hook mail, method sendMailAfter |
|
343 | 343 | if (! empty($conf->dolimail->enabled)) |
344 | 344 | { |
345 | 345 | $mailfromid = explode("#", $_POST['frommail'],3); // $_POST['frommail'] = 'aaa#Sent# <[email protected]>' // TODO Use a better way to define Sent dir. |
@@ -382,39 +382,39 @@ discard block |
||
382 | 382 | } |
383 | 383 | */ |
384 | 384 | |
385 | - // Make substitution in email content |
|
386 | - $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $object); |
|
387 | - $substitutionarray['__EMAIL__'] = $sendto; |
|
388 | - $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty))?'<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>':''; |
|
389 | - |
|
390 | - $parameters=array('mode'=>'formemail'); |
|
391 | - complete_substitutions_array($substitutionarray, $langs, $object, $parameters); |
|
392 | - |
|
393 | - $subject=make_substitutions($subject, $substitutionarray); |
|
394 | - $message=make_substitutions($message, $substitutionarray); |
|
395 | - |
|
396 | - if (method_exists($object, 'makeSubstitution')) |
|
397 | - { |
|
398 | - $subject = $object->makeSubstitution($subject); |
|
399 | - $message = $object->makeSubstitution($message); |
|
400 | - } |
|
401 | - |
|
402 | - // Send mail (substitutionarray must be done just before this) |
|
403 | - if (empty($sendcontext)) $sendcontext = 'standard'; |
|
404 | - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid,'', $sendcontext); |
|
405 | - |
|
406 | - if ($mailfile->error) |
|
407 | - { |
|
408 | - setEventMessages($mailfile->error, $mailfile->errors, 'errors'); |
|
409 | - $action='presend'; |
|
410 | - } |
|
411 | - else |
|
412 | - { |
|
413 | - $result=$mailfile->sendfile(); |
|
414 | - if ($result) |
|
415 | - { |
|
416 | - // Two hooks are available into method $mailfile->sendfile, so dedicated code is no more required |
|
417 | - /* |
|
385 | + // Make substitution in email content |
|
386 | + $substitutionarray=getCommonSubstitutionArray($langs, 0, null, $object); |
|
387 | + $substitutionarray['__EMAIL__'] = $sendto; |
|
388 | + $substitutionarray['__CHECK_READ__'] = (is_object($object) && is_object($object->thirdparty))?'<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$object->thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>':''; |
|
389 | + |
|
390 | + $parameters=array('mode'=>'formemail'); |
|
391 | + complete_substitutions_array($substitutionarray, $langs, $object, $parameters); |
|
392 | + |
|
393 | + $subject=make_substitutions($subject, $substitutionarray); |
|
394 | + $message=make_substitutions($message, $substitutionarray); |
|
395 | + |
|
396 | + if (method_exists($object, 'makeSubstitution')) |
|
397 | + { |
|
398 | + $subject = $object->makeSubstitution($subject); |
|
399 | + $message = $object->makeSubstitution($message); |
|
400 | + } |
|
401 | + |
|
402 | + // Send mail (substitutionarray must be done just before this) |
|
403 | + if (empty($sendcontext)) $sendcontext = 'standard'; |
|
404 | + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1,'','',$trackid,'', $sendcontext); |
|
405 | + |
|
406 | + if ($mailfile->error) |
|
407 | + { |
|
408 | + setEventMessages($mailfile->error, $mailfile->errors, 'errors'); |
|
409 | + $action='presend'; |
|
410 | + } |
|
411 | + else |
|
412 | + { |
|
413 | + $result=$mailfile->sendfile(); |
|
414 | + if ($result) |
|
415 | + { |
|
416 | + // Two hooks are available into method $mailfile->sendfile, so dedicated code is no more required |
|
417 | + /* |
|
418 | 418 | if (! empty($conf->dolimail->enabled)) |
419 | 419 | { |
420 | 420 | $mid = (GETPOST('mid','int') ? GETPOST('mid','int') : 0); // Original mail id is set ? |
@@ -434,91 +434,91 @@ discard block |
||
434 | 434 | } |
435 | 435 | }*/ |
436 | 436 | |
437 | - // Initialisation of datas of object to call trigger |
|
438 | - if (is_object($object)) |
|
439 | - { |
|
440 | - if (empty($actiontypecode)) $actiontypecode='AC_OTH_AUTO'; // Event insert into agenda automatically |
|
441 | - |
|
442 | - $object->socid = $sendtosocid; // To link to a company |
|
443 | - $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. |
|
444 | - $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
445 | - $object->actionmsg = $actionmsg; // Long text (@TODO Replace this with $message, we already have details of email in dedicated properties) |
|
446 | - $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); |
|
447 | - |
|
448 | - $object->trackid = $trackid; |
|
449 | - $object->fk_element = $object->id; |
|
450 | - $object->elementtype = $object->element; |
|
451 | - if (is_array($attachedfiles) && count($attachedfiles)>0) { |
|
452 | - $object->attachedfiles = $attachedfiles; |
|
453 | - } |
|
454 | - if (is_array($sendtouserid) && count($sendtouserid)>0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
|
455 | - $object->sendtouserid = $sendtouserid; |
|
456 | - } |
|
457 | - |
|
458 | - $object->email_msgid = $mailfile->msgid; // @TODO Set msgid into $mailfile after sending |
|
459 | - $object->email_from = $from; |
|
460 | - $object->email_subject = $subject; |
|
461 | - $object->email_to = $sendto; |
|
462 | - $object->email_tocc = $sendtocc; |
|
463 | - $object->email_tobcc = $sendtobcc; |
|
464 | - $object->email_subject = $subject; |
|
465 | - $object->email_msgid = $mailfile->msgid; |
|
466 | - |
|
467 | - // Call of triggers |
|
468 | - if (! empty($trigger_name)) |
|
469 | - { |
|
470 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
471 | - $interface=new Interfaces($db); |
|
472 | - $result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf); |
|
473 | - if ($result < 0) { |
|
474 | - setEventMessages($interface->error, $interface->errors, 'errors'); |
|
475 | - } |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - // Redirect here |
|
480 | - // This avoid sending mail twice if going out and then back to page |
|
481 | - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); |
|
482 | - setEventMessages($mesg, null, 'mesgs'); |
|
483 | - |
|
484 | - $moreparam=''; |
|
485 | - if (isset($paramname2) || isset($paramval2)) $moreparam.= '&'.($paramname2?$paramname2:'mid').'='.$paramval2; |
|
486 | - header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').$moreparam); |
|
487 | - exit; |
|
488 | - } |
|
489 | - else |
|
490 | - { |
|
491 | - $langs->load("other"); |
|
492 | - $mesg='<div class="error">'; |
|
493 | - if ($mailfile->error) |
|
494 | - { |
|
495 | - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); |
|
496 | - $mesg.='<br>'.$mailfile->error; |
|
497 | - } |
|
498 | - else |
|
499 | - { |
|
500 | - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
501 | - } |
|
502 | - $mesg.='</div>'; |
|
503 | - |
|
504 | - setEventMessages($mesg, null, 'warnings'); |
|
505 | - $action = 'presend'; |
|
506 | - } |
|
507 | - } |
|
508 | - } |
|
509 | - else |
|
510 | - { |
|
511 | - $langs->load("errors"); |
|
512 | - setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("MailTo")), null, 'warnings'); |
|
513 | - dol_syslog('Try to send email with no recipient defined', LOG_WARNING); |
|
514 | - $action = 'presend'; |
|
515 | - } |
|
516 | - } |
|
517 | - else |
|
518 | - { |
|
519 | - $langs->load("other"); |
|
520 | - setEventMessages($langs->trans('ErrorFailedToReadObject',$object->element), null, 'errors'); |
|
521 | - dol_syslog('Failed to read data of object id='.$object->id.' element='.$object->element); |
|
522 | - $action = 'presend'; |
|
523 | - } |
|
437 | + // Initialisation of datas of object to call trigger |
|
438 | + if (is_object($object)) |
|
439 | + { |
|
440 | + if (empty($actiontypecode)) $actiontypecode='AC_OTH_AUTO'; // Event insert into agenda automatically |
|
441 | + |
|
442 | + $object->socid = $sendtosocid; // To link to a company |
|
443 | + $object->sendtoid = $sendtoid; // To link to contact addresses. This is an array. |
|
444 | + $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) |
|
445 | + $object->actionmsg = $actionmsg; // Long text (@TODO Replace this with $message, we already have details of email in dedicated properties) |
|
446 | + $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); |
|
447 | + |
|
448 | + $object->trackid = $trackid; |
|
449 | + $object->fk_element = $object->id; |
|
450 | + $object->elementtype = $object->element; |
|
451 | + if (is_array($attachedfiles) && count($attachedfiles)>0) { |
|
452 | + $object->attachedfiles = $attachedfiles; |
|
453 | + } |
|
454 | + if (is_array($sendtouserid) && count($sendtouserid)>0 && !empty($conf->global->MAIN_MAIL_ENABLED_USER_DEST_SELECT)) { |
|
455 | + $object->sendtouserid = $sendtouserid; |
|
456 | + } |
|
457 | + |
|
458 | + $object->email_msgid = $mailfile->msgid; // @TODO Set msgid into $mailfile after sending |
|
459 | + $object->email_from = $from; |
|
460 | + $object->email_subject = $subject; |
|
461 | + $object->email_to = $sendto; |
|
462 | + $object->email_tocc = $sendtocc; |
|
463 | + $object->email_tobcc = $sendtobcc; |
|
464 | + $object->email_subject = $subject; |
|
465 | + $object->email_msgid = $mailfile->msgid; |
|
466 | + |
|
467 | + // Call of triggers |
|
468 | + if (! empty($trigger_name)) |
|
469 | + { |
|
470 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
471 | + $interface=new Interfaces($db); |
|
472 | + $result=$interface->run_triggers($trigger_name,$object,$user,$langs,$conf); |
|
473 | + if ($result < 0) { |
|
474 | + setEventMessages($interface->error, $interface->errors, 'errors'); |
|
475 | + } |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + // Redirect here |
|
480 | + // This avoid sending mail twice if going out and then back to page |
|
481 | + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); |
|
482 | + setEventMessages($mesg, null, 'mesgs'); |
|
483 | + |
|
484 | + $moreparam=''; |
|
485 | + if (isset($paramname2) || isset($paramval2)) $moreparam.= '&'.($paramname2?$paramname2:'mid').'='.$paramval2; |
|
486 | + header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').$moreparam); |
|
487 | + exit; |
|
488 | + } |
|
489 | + else |
|
490 | + { |
|
491 | + $langs->load("other"); |
|
492 | + $mesg='<div class="error">'; |
|
493 | + if ($mailfile->error) |
|
494 | + { |
|
495 | + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); |
|
496 | + $mesg.='<br>'.$mailfile->error; |
|
497 | + } |
|
498 | + else |
|
499 | + { |
|
500 | + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
|
501 | + } |
|
502 | + $mesg.='</div>'; |
|
503 | + |
|
504 | + setEventMessages($mesg, null, 'warnings'); |
|
505 | + $action = 'presend'; |
|
506 | + } |
|
507 | + } |
|
508 | + } |
|
509 | + else |
|
510 | + { |
|
511 | + $langs->load("errors"); |
|
512 | + setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("MailTo")), null, 'warnings'); |
|
513 | + dol_syslog('Try to send email with no recipient defined', LOG_WARNING); |
|
514 | + $action = 'presend'; |
|
515 | + } |
|
516 | + } |
|
517 | + else |
|
518 | + { |
|
519 | + $langs->load("other"); |
|
520 | + setEventMessages($langs->trans('ErrorFailedToReadObject',$object->element), null, 'errors'); |
|
521 | + dol_syslog('Failed to read data of object id='.$object->id.' element='.$object->element); |
|
522 | + $action = 'presend'; |
|
523 | + } |
|
524 | 524 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | // Protection to avoid direct call of template |
4 | 4 | if (empty($conf) || ! is_object($conf)) |
5 | 5 | { |
6 | - print "Error, template page can't be called as URL"; |
|
7 | - exit; |
|
6 | + print "Error, template page can't be called as URL"; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -37,76 +37,76 @@ discard block |
||
37 | 37 | if( (array) $linked_resources && count($linked_resources) > 0) |
38 | 38 | { |
39 | 39 | |
40 | - foreach ($linked_resources as $linked_resource) |
|
41 | - { |
|
42 | - |
|
43 | - $object_resource = fetchObjectByElement($linked_resource['resource_id'],$linked_resource['resource_type']); |
|
44 | - |
|
45 | - //$element_id = $linked_resource['rowid']; |
|
46 | - |
|
47 | - if ($mode == 'edit' && $linked_resource['rowid'] == GETPOST('lineid')) |
|
48 | - { |
|
49 | - |
|
50 | - print '<form class="tagtr oddeven" action="'.$_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id.'" method="POST">'; |
|
51 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />'; |
|
52 | - print '<input type="hidden" name="id" value="'.$object->id.'" />'; |
|
53 | - print '<input type="hidden" name="action" value="update_linked_resource" />'; |
|
54 | - print '<input type="hidden" name="resource_type" value="'.$resource_type.'" />'; |
|
55 | - print '<input type="hidden" name="lineid" value="'.$linked_resource['rowid'].'" />'; |
|
56 | - |
|
57 | - print '<div class="tagtd">'.$object_resource->getNomUrl(1).'</div>'; |
|
58 | - print '<div class="tagtd">'.$object_resource->type_label.'</div>'; |
|
59 | - print '<div class="tagtd" align="center">'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>'; |
|
60 | - print '<div class="tagtd" align="center">'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>'; |
|
61 | - print '<div class="tagtd" align="right"><input type="submit" class="button" value="'.$langs->trans("Update").'"></div>'; |
|
62 | - print '</form>'; |
|
63 | - } |
|
64 | - else |
|
65 | - { |
|
66 | - $style=''; |
|
67 | - if ($linked_resource['rowid'] == GETPOST('lineid')) |
|
68 | - $style='style="background: orange;"'; |
|
69 | - |
|
70 | - print '<form class="tagtr oddeven" '.$style.'>'; |
|
71 | - |
|
72 | - print '<div class="tagtd">'; |
|
73 | - print $object_resource->getNomUrl(1); |
|
74 | - print '</div>'; |
|
75 | - |
|
76 | - print '<div class="tagtd">'; |
|
77 | - print $object_resource->type_label; |
|
78 | - print '</div>'; |
|
79 | - |
|
80 | - print '<div class="tagtd" align="center">'; |
|
81 | - print yn($linked_resource['busy']); |
|
82 | - print '</div>'; |
|
83 | - |
|
84 | - print '<div class="tagtd" align="center">'; |
|
85 | - print yn($linked_resource['mandatory']); |
|
86 | - print '</div>'; |
|
87 | - |
|
88 | - print '<div class="tagtd" align="right">'; |
|
89 | - print '<a href="'.$_SERVER['PHP_SELF'].'?mode=edit&resource_type='.$linked_resource['resource_type'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'; |
|
90 | - print img_edit(); |
|
91 | - print '</a>'; |
|
92 | - print ' '; |
|
93 | - print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete_resource&id='.$linked_resource['resource_id'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'; |
|
94 | - print img_delete(); |
|
95 | - print '</a>'; |
|
96 | - print '</div>'; |
|
97 | - |
|
98 | - print '</form>'; |
|
99 | - } |
|
100 | - } |
|
40 | + foreach ($linked_resources as $linked_resource) |
|
41 | + { |
|
42 | + |
|
43 | + $object_resource = fetchObjectByElement($linked_resource['resource_id'],$linked_resource['resource_type']); |
|
44 | + |
|
45 | + //$element_id = $linked_resource['rowid']; |
|
46 | + |
|
47 | + if ($mode == 'edit' && $linked_resource['rowid'] == GETPOST('lineid')) |
|
48 | + { |
|
49 | + |
|
50 | + print '<form class="tagtr oddeven" action="'.$_SERVER["PHP_SELF"].'?element='.$element.'&element_id='.$element_id.'" method="POST">'; |
|
51 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />'; |
|
52 | + print '<input type="hidden" name="id" value="'.$object->id.'" />'; |
|
53 | + print '<input type="hidden" name="action" value="update_linked_resource" />'; |
|
54 | + print '<input type="hidden" name="resource_type" value="'.$resource_type.'" />'; |
|
55 | + print '<input type="hidden" name="lineid" value="'.$linked_resource['rowid'].'" />'; |
|
56 | + |
|
57 | + print '<div class="tagtd">'.$object_resource->getNomUrl(1).'</div>'; |
|
58 | + print '<div class="tagtd">'.$object_resource->type_label.'</div>'; |
|
59 | + print '<div class="tagtd" align="center">'.$form->selectyesno('busy',$linked_resource['busy']?1:0,1).'</div>'; |
|
60 | + print '<div class="tagtd" align="center">'.$form->selectyesno('mandatory',$linked_resource['mandatory']?1:0,1).'</div>'; |
|
61 | + print '<div class="tagtd" align="right"><input type="submit" class="button" value="'.$langs->trans("Update").'"></div>'; |
|
62 | + print '</form>'; |
|
63 | + } |
|
64 | + else |
|
65 | + { |
|
66 | + $style=''; |
|
67 | + if ($linked_resource['rowid'] == GETPOST('lineid')) |
|
68 | + $style='style="background: orange;"'; |
|
69 | + |
|
70 | + print '<form class="tagtr oddeven" '.$style.'>'; |
|
71 | + |
|
72 | + print '<div class="tagtd">'; |
|
73 | + print $object_resource->getNomUrl(1); |
|
74 | + print '</div>'; |
|
75 | + |
|
76 | + print '<div class="tagtd">'; |
|
77 | + print $object_resource->type_label; |
|
78 | + print '</div>'; |
|
79 | + |
|
80 | + print '<div class="tagtd" align="center">'; |
|
81 | + print yn($linked_resource['busy']); |
|
82 | + print '</div>'; |
|
83 | + |
|
84 | + print '<div class="tagtd" align="center">'; |
|
85 | + print yn($linked_resource['mandatory']); |
|
86 | + print '</div>'; |
|
87 | + |
|
88 | + print '<div class="tagtd" align="right">'; |
|
89 | + print '<a href="'.$_SERVER['PHP_SELF'].'?mode=edit&resource_type='.$linked_resource['resource_type'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'; |
|
90 | + print img_edit(); |
|
91 | + print '</a>'; |
|
92 | + print ' '; |
|
93 | + print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete_resource&id='.$linked_resource['resource_id'].'&element='.$element.'&element_id='.$element_id.'&lineid='.$linked_resource['rowid'].'">'; |
|
94 | + print img_delete(); |
|
95 | + print '</a>'; |
|
96 | + print '</div>'; |
|
97 | + |
|
98 | + print '</form>'; |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | else { |
103 | - print '<form class="tagtr oddeven">'; |
|
104 | - print '<div class="tagtd opacitymedium">'.$langs->trans('NoResourceLinked').'</div>'; |
|
105 | - print '<div class="tagtd opacitymedium"></div>'; |
|
106 | - print '<div class="tagtd opacitymedium"></div>'; |
|
107 | - print '<div class="tagtd opacitymedium"></div>'; |
|
108 | - print '<div class="tagtd opacitymedium"></div>'; |
|
109 | - print '</form>'; |
|
103 | + print '<form class="tagtr oddeven">'; |
|
104 | + print '<div class="tagtd opacitymedium">'.$langs->trans('NoResourceLinked').'</div>'; |
|
105 | + print '<div class="tagtd opacitymedium"></div>'; |
|
106 | + print '<div class="tagtd opacitymedium"></div>'; |
|
107 | + print '<div class="tagtd opacitymedium"></div>'; |
|
108 | + print '<div class="tagtd opacitymedium"></div>'; |
|
109 | + print '</form>'; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | print '</div>'; |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | // Protection to avoid direct call of template |
25 | 25 | if (empty($conf) || ! is_object($conf)) |
26 | 26 | { |
27 | - print "Error, template page can't be called as URL"; |
|
28 | - exit; |
|
27 | + print "Error, template page can't be called as URL"; |
|
28 | + exit; |
|
29 | 29 | } |
30 | 30 | if (! is_object($form)) $form=new Form($db); |
31 | 31 | |
@@ -37,27 +37,27 @@ discard block |
||
37 | 37 | |
38 | 38 | foreach($object->fields as $key => $val) |
39 | 39 | { |
40 | - // Discard if extrafield is a hidden field on form |
|
41 | - if (abs($val['visible']) != 1) continue; |
|
40 | + // Discard if extrafield is a hidden field on form |
|
41 | + if (abs($val['visible']) != 1) continue; |
|
42 | 42 | |
43 | - if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! verifCond($val['enabled'])) continue; // We don't want this field |
|
43 | + if (array_key_exists('enabled', $val) && isset($val['enabled']) && ! verifCond($val['enabled'])) continue; // We don't want this field |
|
44 | 44 | |
45 | - print '<tr><td'; |
|
46 | - print ' class="titlefieldcreate'; |
|
47 | - if ($val['notnull'] > 0) print ' fieldrequired'; |
|
48 | - if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop'; |
|
49 | - print '">'; |
|
50 | - if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $val['help']); |
|
51 | - else print $langs->trans($val['label']); |
|
52 | - print '</td>'; |
|
53 | - print '<td>'; |
|
54 | - if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key; |
|
55 | - elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key; |
|
56 | - else $value = GETPOSTISSET($key)?GETPOST($key, 'alpha'):$object->$key; |
|
57 | - //var_dump($val.' '.$key.' '.$value); |
|
58 | - print $object->showInputField($val, $key, $value, '', '', '', 0); |
|
59 | - print '</td>'; |
|
60 | - print '</tr>'; |
|
45 | + print '<tr><td'; |
|
46 | + print ' class="titlefieldcreate'; |
|
47 | + if ($val['notnull'] > 0) print ' fieldrequired'; |
|
48 | + if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop'; |
|
49 | + print '">'; |
|
50 | + if (! empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $val['help']); |
|
51 | + else print $langs->trans($val['label']); |
|
52 | + print '</td>'; |
|
53 | + print '<td>'; |
|
54 | + if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key)?GETPOST($key, 'int'):$object->$key; |
|
55 | + elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOSTISSET($key)?GETPOST($key,'none'):$object->$key; |
|
56 | + else $value = GETPOSTISSET($key)?GETPOST($key, 'alpha'):$object->$key; |
|
57 | + //var_dump($val.' '.$key.' '.$value); |
|
58 | + print $object->showInputField($val, $key, $value, '', '', '', 0); |
|
59 | + print '</td>'; |
|
60 | + print '</tr>'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | ?> |
@@ -35,74 +35,74 @@ |
||
35 | 35 | |
36 | 36 | $fixedDiscount = $thirdparty->remise_percent; |
37 | 37 | if(! empty($discount_type)) { |
38 | - $fixedDiscount = $thirdparty->remise_supplier_percent; |
|
38 | + $fixedDiscount = $thirdparty->remise_supplier_percent; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | if ($fixedDiscount > 0) |
42 | 42 | { |
43 | - $translationKey = (! empty($discount_type)) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount'; |
|
44 | - print $langs->trans($translationKey, $fixedDiscount).'.'; |
|
43 | + $translationKey = (! empty($discount_type)) ? 'HasRelativeDiscountFromSupplier' : 'CompanyHasRelativeDiscount'; |
|
44 | + print $langs->trans($translationKey, $fixedDiscount).'.'; |
|
45 | 45 | } |
46 | 46 | else |
47 | 47 | { |
48 | - $translationKey = (! empty($discount_type)) ? 'HasNoRelativeDiscountFromSupplier' : 'CompanyHasNoRelativeDiscount'; |
|
49 | - print $langs->trans($translationKey).'.'; |
|
48 | + $translationKey = (! empty($discount_type)) ? 'HasNoRelativeDiscountFromSupplier' : 'CompanyHasNoRelativeDiscount'; |
|
49 | + print $langs->trans($translationKey).'.'; |
|
50 | 50 | } |
51 | 51 | if($isNewObject) print ' ('.$addrelativediscount.')'; |
52 | 52 | |
53 | 53 | // Is there is commercial discount or down payment available ? |
54 | 54 | if ($absolute_discount > 0) { |
55 | 55 | |
56 | - if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut > $classname::STATUS_DRAFT || $object->type == $classname::TYPE_CREDIT_NOTE || $object->type == $classname::TYPE_DEPOSIT) { |
|
57 | - $translationKey = ! empty($discount_type) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount'; |
|
58 | - $text = $langs->trans($translationKey, price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)).'.'; |
|
56 | + if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut > $classname::STATUS_DRAFT || $object->type == $classname::TYPE_CREDIT_NOTE || $object->type == $classname::TYPE_DEPOSIT) { |
|
57 | + $translationKey = ! empty($discount_type) ? 'HasAbsoluteDiscountFromSupplier' : 'CompanyHasAbsoluteDiscount'; |
|
58 | + $text = $langs->trans($translationKey, price($absolute_discount), $langs->transnoentities("Currency" . $conf->currency)).'.'; |
|
59 | 59 | |
60 | - if ($isInvoice && ! $isNewObject && $object->statut > $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) { |
|
61 | - $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse')); |
|
62 | - } |
|
60 | + if ($isInvoice && ! $isNewObject && $object->statut > $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) { |
|
61 | + $text = $form->textwithpicto($text, $langs->trans('AbsoluteDiscountUse')); |
|
62 | + } |
|
63 | 63 | |
64 | - if ($isNewObject) { |
|
65 | - $text.= ' ('.$addabsolutediscount.')'; |
|
66 | - } |
|
64 | + if ($isNewObject) { |
|
65 | + $text.= ' ('.$addabsolutediscount.')'; |
|
66 | + } |
|
67 | 67 | |
68 | - print '<br>'.$text; |
|
69 | - } else { |
|
70 | - // Discount available of type fixed amount (not credit note) |
|
71 | - $more = '(' . $addabsolutediscount . ')'; |
|
72 | - $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type); |
|
73 | - } |
|
68 | + print '<br>'.$text; |
|
69 | + } else { |
|
70 | + // Discount available of type fixed amount (not credit note) |
|
71 | + $more = '(' . $addabsolutediscount . ')'; |
|
72 | + $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, GETPOST('discountid'), 'remise_id', $thirdparty->id, $absolute_discount, $filterabsolutediscount, $resteapayer, $more, 0, $discount_type); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | // Is there credit notes availables ? |
77 | 77 | if ($absolute_creditnote > 0) { |
78 | 78 | |
79 | - // If validated, we show link "add credit note to payment" |
|
80 | - if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut != $classname::STATUS_VALIDATED || $object->type == $classname::TYPE_CREDIT_NOTE) { |
|
81 | - $translationKey = ! empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote'; |
|
82 | - $text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '.'; |
|
83 | - |
|
84 | - if ($isInvoice && ! $isNewObject && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_DEPOSIT) { |
|
85 | - $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse')); |
|
86 | - } |
|
87 | - |
|
88 | - if ($absolute_discount <= 0 || $isNewObject) { |
|
89 | - $text.= '('.$addabsolutediscount.')'; |
|
90 | - } |
|
91 | - |
|
92 | - print '<br>'.$text; |
|
93 | - } else { // We can add a credit note on a down payment or standard invoice or situation invoice |
|
94 | - // There is credit notes discounts available |
|
95 | - $more = $isInvoice && ! $isNewObject ? ' (' . $viewabsolutediscount . ')' : ''; |
|
96 | - $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $thirdparty->id, $absolute_creditnote, $filtercreditnote, 0, $more, 0, $discount_type); // We allow credit note even if amount is higher |
|
97 | - } |
|
79 | + // If validated, we show link "add credit note to payment" |
|
80 | + if ($cannotApplyDiscount || ! $isInvoice || $isNewObject || $object->statut != $classname::STATUS_VALIDATED || $object->type == $classname::TYPE_CREDIT_NOTE) { |
|
81 | + $translationKey = ! empty($discount_type) ? 'HasCreditNoteFromSupplier' : 'CompanyHasCreditNote'; |
|
82 | + $text = $langs->trans($translationKey, price($absolute_creditnote), $langs->transnoentities("Currency" . $conf->currency)) . '.'; |
|
83 | + |
|
84 | + if ($isInvoice && ! $isNewObject && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_DEPOSIT) { |
|
85 | + $text = $form->textwithpicto($text, $langs->trans('CreditNoteDepositUse')); |
|
86 | + } |
|
87 | + |
|
88 | + if ($absolute_discount <= 0 || $isNewObject) { |
|
89 | + $text.= '('.$addabsolutediscount.')'; |
|
90 | + } |
|
91 | + |
|
92 | + print '<br>'.$text; |
|
93 | + } else { // We can add a credit note on a down payment or standard invoice or situation invoice |
|
94 | + // There is credit notes discounts available |
|
95 | + $more = $isInvoice && ! $isNewObject ? ' (' . $viewabsolutediscount . ')' : ''; |
|
96 | + $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $thirdparty->id, $absolute_creditnote, $filtercreditnote, 0, $more, 0, $discount_type); // We allow credit note even if amount is higher |
|
97 | + } |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | if($absolute_discount <= 0 && $absolute_creditnote <= 0) { |
101 | - $translationKey = ! empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount'; |
|
102 | - print '<br>'.$langs->trans($translationKey).'.'; |
|
101 | + $translationKey = ! empty($discount_type) ? 'HasNoAbsoluteDiscountFromSupplier' : 'CompanyHasNoAbsoluteDiscount'; |
|
102 | + print '<br>'.$langs->trans($translationKey).'.'; |
|
103 | 103 | |
104 | - if ($isInvoice && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) { |
|
105 | - print ' (' . $addabsolutediscount . ')'; |
|
106 | - } |
|
104 | + if ($isInvoice && $object->statut == $classname::STATUS_DRAFT && $object->type != $classname::TYPE_CREDIT_NOTE && $object->type != $classname::TYPE_DEPOSIT) { |
|
105 | + print ' (' . $addabsolutediscount . ')'; |
|
106 | + } |
|
107 | 107 | } |
108 | 108 |