|
181 | 181 |
|
182 | 182 | $labourdDoctorSociety = $allLinks['LabourDoctorSociety']; |
183 | 183 |
|
184 | | - // * Third party concerned - Tiers concerné * |
| 184 | + // * Third party concerned - Tiers concerné * |
185 | 185 |
|
186 | 186 | if ($labourdDoctorSociety->ref == 'LabourDoctorSociety') { |
187 | 187 | $events = array(); |
188 | 188 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
189 | 189 | $societe->fetch($labourdDoctorSociety->id[0]); |
190 | 190 |
|
191 | | - print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); |
| 191 | + if ($action == 'createdoctorcontact') { |
| 192 | + $lastDoctorContact = $societe->contact_array(); |
| 193 | + $lastDoctorContactId = array_key_last($lastDoctorContact); |
| 194 | + } |
| 195 | + |
| 196 | + if ($action == 'createdoctorsoc') { |
| 197 | + $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); |
| 198 | + $labourdDoctorSociety->id[0] = array_key_first($lastSocieteCreated); |
| 199 | + } |
| 200 | + |
| 201 | + print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); |
192 | 202 | } else { |
193 | 203 | $events = array(); |
194 | 204 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
|
201 | 211 | } |
202 | 212 | } |
203 | 213 | if (!GETPOSTISSET('backtopage')) { |
204 | | - print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
| 214 | + print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=createdoctorsoc') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
205 | 215 | } |
206 | 216 | print '</td></tr>'; |
207 | 217 |
|
208 | 218 | // * Related contacts - Contacts associés * |
209 | 219 | print '<tr class="oddeven"><td class="nowrap">' . $langs->trans("ActionOnContact") . '</td><td>'; |
210 | 220 |
|
211 | | - $labourdDoctorContact = $allLinks['LabourDoctorContact']; |
212 | | - $labourDoctorPreselectedIds = $labourdDoctorContact->id; |
| 221 | + $labourdDoctorContact = $allLinks['LabourDoctorContact']; |
| 222 | + $labourDoctorPreselectedIds = $labourdDoctorContact->id ?: []; |
| 223 | + |
| 224 | + if (!empty($labourdDoctorSociety)) { |
| 225 | + $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastDoctorContactId]); |
| 226 | + } |
213 | 227 |
|
214 | | - if ($labourdDoctorContact->id) { |
215 | | - print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourdDoctorContact->id, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); |
| 228 | + if ($labourdDoctorContact->id) { |
| 229 | + print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); |
216 | 230 | } else { |
217 | | - $labourDoctorPreselectedIds = GETPOST('labourdoctor_contactid', 'array'); |
| 231 | + $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, GETPOST('labourdoctor_contactid', 'array')); |
218 | 232 | if (GETPOST('labourdoctor_contactid', 'array')) { |
219 | 233 | $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array'); |
220 | 234 | } |
221 | | - print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? -1 : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); |
| 235 | + print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? $labourdDoctorSociety->id[0] : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourdoctor_contactid'); |
222 | 236 | } |
223 | 237 | if (!GETPOSTISSET('backtopage')) { |
224 | | - print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdDoctorSociety->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
| 238 | + print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdDoctorSociety->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=createdoctorcontact') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
225 | 239 | } |
226 | 240 | print '</td></tr>'; |
227 | 241 |
|
|
241 | 255 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourinspector_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
242 | 256 | $societe->fetch($labourdInspectorSociete->id[0]); |
243 | 257 |
|
| 258 | + if ($action == 'createinspectorcontact') { |
| 259 | + $lastInspectorContact = $societe->contact_array(); |
| 260 | + $lastInspectorContactId = array_key_last($lastInspectorContact); |
| 261 | + } |
| 262 | + |
| 263 | + if ($action == 'createinspectorsoc') { |
| 264 | + $lastSocieteCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); |
| 265 | + $labourdInspectorSociete->id[0] = array_key_first($lastSocieteCreated); |
| 266 | + } |
| 267 | + |
244 | 268 | print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300'); |
245 | 269 | } else { |
246 | 270 | $events = array(); |
|
253 | 277 | } |
254 | 278 | } |
255 | 279 | if (!GETPOSTISSET('backtopage')) { |
256 | | - print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
| 280 | + print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=createinspectorsoc') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
257 | 281 | } |
258 | 282 | print '</td></tr>'; |
259 | 283 |
|
|
262 | 286 | print '<tr class="oddeven"><td class="nowrap">' . $langs->trans("ActionOnContact") . '</td><td>'; |
263 | 287 |
|
264 | 288 | $labourInspectorContacts = $allLinks['LabourInspectorContact']; |
265 | | - $labourInspectorPreselectedIds = $labourInspectorContacts->id; |
| 289 | + $labourInspectorPreselectedIds = $labourInspectorContacts->id ?: []; |
| 290 | + |
| 291 | + if (!empty($labourdInspectorSociete)) { |
| 292 | + $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastInspectorContactId]); |
| 293 | + } |
266 | 294 |
|
267 | 295 | if ($labourInspectorContacts->id) { |
268 | | - print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorContacts->id, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); |
| 296 | + print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); |
269 | 297 | } else { |
270 | | - $labourInspectorPreselectedIds = GETPOST('labourinspector_contactid', 'array'); |
| 298 | + $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, GETPOST('labourinspector_contactid', 'array')); |
271 | 299 | if (GETPOST('labourinspector_contactid', 'array')) { |
272 | 300 | $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array'); |
273 | 301 | } |
274 | | - print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? -1 : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); |
| 302 | + print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? $labourdInspectorSociete->id[0] : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, array(), false, 'multiple', 'labourinspector_contactid'); |
275 | 303 | } |
276 | 304 | if (!GETPOSTISSET('backtopage')) { |
277 | | - print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdInspectorSociete->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
| 305 | + print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdInspectorSociete->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=createinspectorcontact') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
278 | 306 | } |
279 | 307 | print '</td></tr>'; |
280 | 308 |
|
|
0 commit comments