|
50 | 50 |
|
51 | 51 | // Parameters |
52 | 52 | $action = GETPOST('action', 'aZ09'); |
| 53 | +$type = GETPOST('type'); |
53 | 54 | $error = 0; |
54 | 55 |
|
55 | 56 | // Initialize technical objects |
|
70 | 71 | * Actions |
71 | 72 | */ |
72 | 73 |
|
73 | | -$parameters = array(); |
| 74 | +$parameters = []; |
74 | 75 | $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
75 | 76 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
76 | 77 |
|
77 | 78 | if (($action == 'update' && ! GETPOST("cancel", 'alpha')) || ($action == 'updateedit')) { |
78 | 79 | $labourDoctorId[0] = GETPOST('labourdoctor_socid', 'int') > 0 ? GETPOST('labourdoctor_socid', 'int') : 0 ; |
79 | 80 | $labourInspectorId[0] = GETPOST('labourinspector_socid', 'int') > 0 ? GETPOST('labourinspector_socid', 'int') : 0; |
80 | 81 |
|
81 | | - $labourDoctorSocpeopleAssigned = ! empty(GETPOST('labourdoctor_contactid', 'array')) ? GETPOST('labourdoctor_contactid', 'array') : (GETPOST('labourdoctor_contactid', 'int') > 0 ? array(GETPOST('labourdoctor_contactid', 'int')) : array()); |
82 | | - $labourInspectorSocpeopleAssigned = ! empty(GETPOST('labourinspector_contactid', 'array')) ? GETPOST('labourinspector_contactid', 'array') : (GETPOST('labourinspector_contactid', 'int') > 0 ? array(GETPOST('labourinspector_contactid', 'int')) : array()); |
| 82 | + $labourDoctorSocpeopleAssigned = !empty(GETPOST('labourdoctor_contactid', 'array')) ? GETPOST('labourdoctor_contactid', 'array') : (GETPOST('labourdoctor_contactid', 'int') > 0 ? array(GETPOST('labourdoctor_contactid', 'int')) : []); |
| 83 | + $labourInspectorSocpeopleAssigned = !empty(GETPOST('labourinspector_contactid', 'array')) ? GETPOST('labourinspector_contactid', 'array') : (GETPOST('labourinspector_contactid', 'int') > 0 ? array(GETPOST('labourinspector_contactid', 'int')) : []); |
83 | 84 |
|
84 | 85 | $resources->setDigiriskResources($db, $user->id, 'LabourDoctorSociety', 'societe', $labourDoctorId, $conf->entity); |
85 | 86 | $resources->setDigiriskResources($db, $user->id, 'LabourInspectorSociety', 'societe', $labourInspectorId, $conf->entity); |
|
171 | 172 |
|
172 | 173 | <?php print '<table class="noborder centpercent editmode">'; |
173 | 174 |
|
| 175 | +if ($action == 'create_contact') { |
| 176 | + $lastContactCreated = saturne_fetch_all_object_type('contact', 'DESC', 'rowid', 1); |
| 177 | + $lastContactId = array_key_first($lastContactCreated); |
| 178 | + $contact->fetch($lastContactId); |
| 179 | +} |
| 180 | + |
| 181 | +if ($action == 'create_soc') { |
| 182 | + $lastSocietyCreated = saturne_fetch_all_object_type('societe', 'DESC', 'rowid', 1); |
| 183 | +} |
| 184 | + |
174 | 185 | if (isModEnabled('societe')) { |
175 | 186 | /* |
176 | 187 | *** Labour Doctor -- Médecin du travail *** |
|
184 | 195 | // * Third party concerned - Tiers concerné * |
185 | 196 |
|
186 | 197 | if ($labourdDoctorSociety->ref == 'LabourDoctorSociety') { |
187 | | - $events = array(); |
| 198 | + $events = []; |
188 | 199 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
189 | 200 | $societe->fetch($labourdDoctorSociety->id[0]); |
190 | 201 |
|
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); |
| 202 | + if ($action == 'create_soc' && $type == $labourdDoctorSociety->ref) { |
| 203 | + $labourdDoctorSociety->id[0] = array_key_first($lastSocietyCreated); |
199 | 204 | } |
200 | 205 |
|
201 | 206 | print $form->select_company($labourdDoctorSociety->id[0], 'labourdoctor_socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); |
202 | 207 | } else { |
203 | | - $events = array(); |
| 208 | + $events = []; |
204 | 209 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourdoctor_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
205 | 210 |
|
206 | 211 | //For external user force the company to user company |
|
211 | 216 | } |
212 | 217 | } |
213 | 218 | if (!GETPOSTISSET('backtopage')) { |
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>'; |
| 219 | + print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create_soc&type=' . $labourdDoctorSociety->ref) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
215 | 220 | } |
216 | 221 | print '</td></tr>'; |
217 | 222 |
|
|
221 | 226 | $labourdDoctorContact = $allLinks['LabourDoctorContact']; |
222 | 227 | $labourDoctorPreselectedIds = $labourdDoctorContact->id ?: []; |
223 | 228 |
|
224 | | - if (!empty($labourdDoctorSociety)) { |
225 | | - $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastDoctorContactId]); |
| 229 | + if ($action == 'create_contact' && $contact->fk_soc == $societe->id) { |
| 230 | + $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, [$lastContactId]); |
226 | 231 | } |
227 | 232 |
|
228 | 233 | 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'); |
| 234 | + print $form->selectcontacts(empty($labourdDoctorSociety->id[0]) ? -1 : $labourdDoctorSociety->id[0], $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourdoctor_contactid'); |
230 | 235 | } else { |
231 | 236 | $labourDoctorPreselectedIds = array_merge($labourDoctorPreselectedIds, GETPOST('labourdoctor_contactid', 'array')); |
232 | 237 | if (GETPOST('labourdoctor_contactid', 'array')) { |
233 | 238 | $labourDoctorPreselectedIds[GETPOST('labourdoctor_contactid', 'array')] = GETPOST('labourdoctor_contactid', 'array'); |
234 | 239 | } |
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'); |
| 240 | + print $form->selectcontacts(empty(GETPOST('labourdoctor_socid', 'int')) ? $labourdDoctorSociety->id[0] : GETPOST('labourdoctor_socid', 'int'), $labourDoctorPreselectedIds, 'labourdoctor_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourdoctor_contactid'); |
236 | 241 | } |
237 | 242 | if (!GETPOSTISSET('backtopage')) { |
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>'; |
| 243 | + print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdDoctorSociety->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create_contact') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
239 | 244 | } |
240 | 245 | print '</td></tr>'; |
241 | 246 |
|
|
251 | 256 | // * Third party concerned - Tiers concerné * |
252 | 257 |
|
253 | 258 | if ($labourdInspectorSociete->ref == 'LabourInspectorSociety') { |
254 | | - $events = array(); |
| 259 | + $events = []; |
255 | 260 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourinspector_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
256 | 261 | $societe->fetch($labourdInspectorSociete->id[0]); |
257 | 262 |
|
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); |
| 263 | + if ($action == 'create_soc' && $type == $labourdInspectorSociete->ref) { |
| 264 | + $labourdInspectorSociete->id[0] = array_key_first($lastSocietyCreated); |
266 | 265 | } |
267 | 266 |
|
268 | 267 | print $form->select_company($labourdInspectorSociete->id[0], 'labourinspector_socid', '', 0, 1, 0, $events, 0, 'minwidth300'); |
269 | 268 | } else { |
270 | | - $events = array(); |
| 269 | + $events = []; |
271 | 270 | $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1', 1), 'htmlname' => 'labourinspector_contactid', 'params' => array('add-customer-contact' => 'disabled')); |
272 | 271 | //For external user force the company to user company |
273 | 272 | if ( ! empty($user->socid)) { |
|
277 | 276 | } |
278 | 277 | } |
279 | 278 | if (!GETPOSTISSET('backtopage')) { |
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>'; |
| 279 | + print ' <a href="' . DOL_URL_ROOT . '/societe/card.php?action=create&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create_soc&type=' . $labourdInspectorSociete->ref) . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddThirdParty") . '"></span></a>'; |
281 | 280 | } |
282 | 281 | print '</td></tr>'; |
283 | 282 |
|
|
288 | 287 | $labourInspectorContacts = $allLinks['LabourInspectorContact']; |
289 | 288 | $labourInspectorPreselectedIds = $labourInspectorContacts->id ?: []; |
290 | 289 |
|
291 | | - if (!empty($labourdInspectorSociete)) { |
292 | | - $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastInspectorContactId]); |
| 290 | + if ($action == 'create_contact' && $contact->fk_soc == $societe->id) { |
| 291 | + $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, [$lastContactId]); |
293 | 292 | } |
294 | 293 |
|
295 | 294 | if ($labourInspectorContacts->id) { |
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'); |
| 295 | + print $form->selectcontacts(empty($labourdInspectorSociete->id[0]) ? -1 : $labourdInspectorSociete->id[0], $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourinspector_contactid'); |
297 | 296 | } else { |
298 | 297 | $labourInspectorPreselectedIds = array_merge($labourInspectorPreselectedIds, GETPOST('labourinspector_contactid', 'array')); |
299 | 298 | if (GETPOST('labourinspector_contactid', 'array')) { |
300 | 299 | $labourInspectorPreselectedIds[GETPOST('labourinspector_contactid', 'array')] = GETPOST('labourinspector_contactid', 'array'); |
301 | 300 | } |
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'); |
| 301 | + print $form->selectcontacts(empty(GETPOST('labourinspector_socid', 'int')) ? $labourdInspectorSociete->id[0] : GETPOST('labourinspector_socid', 'int'), $labourInspectorPreselectedIds, 'labourinspector_contactid[]', 0, '', '', 0, 'minwidth500', false, 0, [], false, 'multiple', 'labourinspector_contactid'); |
303 | 302 | } |
304 | 303 | if (!GETPOSTISSET('backtopage')) { |
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>'; |
| 304 | + print ' <a href="' . DOL_URL_ROOT . '/contact/card.php?action=create&socid='. $labourdInspectorSociete->id[0] .'&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create_contact') . '"><span class="fa fa-plus-circle valignmiddle paddingleft" title="' . $langs->trans("AddContact") . '"></span></a>'; |
306 | 305 | } |
307 | 306 | print '</td></tr>'; |
308 | 307 |
|
|
0 commit comments