21require_once DOL_DOCUMENT_ROOT .
'/core/class/extrafields.class.php';
39 "name" =>
"navigate_to_page",
40 "description" =>
"Generates a valid Dolibarr URL. Handles generic names (e.g., 'invoice' maps to customer invoices) and directory structures automatically. Can filter lists by status.",
46 "description" =>
"The object type. Examples: 'invoice', 'thirdparty', 'order', 'proposal', 'project', 'supplier_invoice'.",
50 "description" =>
"The type of view needed: 'list', 'card', 'create'.",
51 "enum" => [
"list",
"card",
"create"]
55 "description" =>
"The ID of the record (optional)."
59 "description" =>
"The Reference of the record (optional)."
63 "description" =>
"A human-readable status to filter the list. Only applies to 'list' view. Examples: 'draft', 'open', 'paid', 'shipped', 'closed', 'canceled'."
67 "description" =>
"Additional URL parameters (e.g. {'search_thirdparty': 'MyCompany'}). These will be combined with the status filter."
70 "required" => [
"object_type",
"view"]
84 return self::RIGHTS_ENFORCED_DOWNSTREAM;
105 public function execute(
string $name, array $args)
110 $langs->load(
"companies");
111 $langs->load(
"bills");
112 $langs->load(
"orders");
113 $langs->load(
"propal");
114 $langs->load(
"projects");
115 $langs->load(
"sendings");
117 if ($name !==
'navigate_to_page') {
121 if (empty($this->
user->id)) {
122 return [
"error" =>
"Permission Denied: User not logged in."];
125 $rawType = $args[
'object_type'] ??
'';
126 $view = $args[
'view'] ??
'list';
127 $id = (int) ($args[
'id'] ?? 0);
128 $ref = $args[
'ref'] ??
'';
129 $statusFilter = $args[
'status_filter'] ??
'';
130 $params = $args[
'params'] ?? [];
135 if (empty($pathInfo)) {
136 return [
"error" =>
"Unknown object type: '$rawType'. Try 'invoice', 'order', or 'thirdparty'."];
139 $relativePath = $pathInfo[
'path'];
140 $elementType = $pathInfo[
'type'];
144 return [
"error" =>
"Permission Denied: You don't have permission to access this resource."];
148 $getQueryParams = [];
152 $getQueryParams[
'id'] =
$id;
153 } elseif (!empty($ref)) {
154 $getQueryParams[
'ref'] = $ref;
158 if ($view ===
'create') {
159 $getQueryParams[
'action'] =
'create';
163 if ($view ===
'list' && !empty($statusFilter)) {
166 $getQueryParams = array_merge($getQueryParams, $statusParam);
168 return [
"error" =>
"Unknown status filter '$statusFilter' for object type '$rawType'."];
170 } elseif (!empty($statusFilter)) {
171 return [
"error" =>
"The 'status_filter' parameter can only be used with the 'list' view."];
175 if (!empty($params) && is_array($params)) {
176 $getQueryParams = array_merge($getQueryParams, $params);
182 $finalUrl = $baseUrl;
183 if (!empty($getQueryParams)) {
184 $finalUrl .=
'?' . http_build_query($getQueryParams);
191 "resolved_type" => $elementType,
192 "path" => $relativePath
207 $statusFilter = strtolower(trim($statusFilter));
211 'invoice_customer' => [
212 'draft' => [
'statut' => 0],
213 'unpaid' => [
'statut' => 1],
214 'paid' => [
'statut' => 2],
216 'invoice_supplier' => [
217 'draft' => [
'statut' => 0],
218 'unpaid' => [
'statut' => 1],
219 'paid' => [
'statut' => 2],
222 'draft' => [
'statut' => 0],
223 'validated' => [
'statut' => 1],
224 'shipped' => [
'statut' => 2],
225 'closed' => [
'statut' => 3],
226 'canceled' => [
'statut' => -1],
228 'order_supplier' => [
229 'draft' => [
'statut' => 0],
230 'validated' => [
'statut' => 1],
231 'approved' => [
'statut' => 2],
232 'received' => [
'statut' => 3],
233 'canceled' => [
'statut' => -1],
236 'draft' => [
'statut' => 0],
237 'open' => [
'statut' => 1],
238 'signed' => [
'statut' => 2],
239 'billed' => [
'statut' => 3],
240 'refused' => [
'statut' => 4],
241 'canceled' => [
'statut' => 5],
244 'draft' => [
'status' => 0],
245 'open' => [
'status' => 1],
246 'closed' => [
'status' => 2],
249 'draft' => [
'status' => 0],
250 'validated' => [
'status' => 1],
251 'shipped' => [
'status' => 2],
252 'canceled' => [
'status' => -1],
255 'draft' => [
'statut' => 0],
256 'active' => [
'statut' => 1],
257 'closed' => [
'statut' => 2],
258 'resiliated' => [
'statut' => 3],
261 'draft' => [
'statut' => 0],
262 'validated' => [
'statut' => 1],
263 'billed' => [
'statut' => 2],
264 'closed' => [
'statut' => 3],
269 return $statusMap[$elementType][$statusFilter] ??
null;
281 $input = strtolower(trim($input));
286 'invoice' =>
'invoice_customer',
287 'bill' =>
'invoice_customer',
288 'facture' =>
'invoice_customer',
289 'supplier_invoice' =>
'invoice_supplier',
290 'vendor_bill' =>
'invoice_supplier',
292 'company' =>
'thirdparty',
293 'societe' =>
'thirdparty',
294 'customer' =>
'thirdparty',
295 'client' =>
'thirdparty',
296 'supplier' =>
'thirdparty',
297 'vendor' =>
'thirdparty',
299 'propal' =>
'proposal',
300 'quote' =>
'proposal',
301 'command' =>
'order',
302 'customer_order' =>
'order',
303 'supplier_order' =>
'order_supplier',
305 'product' =>
'product',
306 'service' =>
'product',
308 'project' =>
'project',
309 'task' =>
'project_task',
311 'shipment' =>
'expedition',
312 'shipping' =>
'expedition',
313 'delivery' =>
'expedition',
315 'payment' =>
'payment',
316 'payment_customer' =>
'payment',
317 'payment_supplier' =>
'payment_supplier',
319 'transaction' =>
'bank',
321 'bank_account' =>
'bank',
324 'agenda' =>
'agenda',
325 'appointment' =>
'agenda',
327 'contract' =>
'contract',
329 'intervention' =>
'fichinter',
331 'member' =>
'adherent',
332 'membership' =>
'adherent',
334 'category' =>
'categories',
337 $type = $aliases[$input] ?? $input;
341 'thirdparty' =>
'/societe/',
342 'contact' =>
'/contact/',
343 'product' =>
'/product/',
344 'project' =>
'/projet/',
345 'project_task' =>
'/projet/tasks/',
346 'invoice_customer' =>
'/compta/facture/',
347 'invoice_supplier' =>
'/fourn/facture/',
348 'order' =>
'/commande/',
349 'order_supplier' =>
'/fourn/commande/',
350 'proposal' =>
'/comm/propal/',
351 'expedition' =>
'/expedition/',
352 'payment' =>
'/compta/paiement.php',
353 'payment_supplier' =>
'/fourn/paiement.php',
354 'bank' =>
'/compta/bank/',
355 'agenda' =>
'/comm/action/',
356 'contract' =>
'/contrat/',
357 'fichinter' =>
'/fichinter/',
358 'adherent' =>
'/adherents/',
359 'categories' =>
'/categories/',
362 if (!isset($map[$type])) {
370 if (strpos($dir,
'.php') !==
false) {
377 $script =
'list.php';
379 if ($view ===
'card' || $view ===
'create') {
380 $script =
'card.php';
385 'path' => $dir . $script
403 switch ($elementType) {
405 $permitted = $this->
user->hasRight(
'societe',
'lire') ||
406 ($view ===
'create' && $this->
user->hasRight(
'societe',
'creer'));
410 $permitted = $this->
user->hasRight(
'societe',
'contact->lire') ||
411 ($view ===
'create' && $this->
user->hasRight(
'societe',
'contact->creer'));
415 $permitted = $this->
user->hasRight(
'produit',
'lire') ||
416 ($view ===
'create' && $this->
user->hasRight(
'produit',
'creer'));
420 $permitted = $this->
user->hasRight(
'projet',
'lire') ||
421 ($view ===
'create' && $this->
user->hasRight(
'projet',
'creer'));
425 $permitted = $this->
user->hasRight(
'projet',
'lire');
428 case 'invoice_customer':
429 $permitted = $this->
user->hasRight(
'facture',
'lire') ||
430 ($view ===
'create' && $this->
user->hasRight(
'facture',
'creer'));
433 case 'invoice_supplier':
434 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->lire') ||
435 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'facture->creer'));
439 $permitted = $this->
user->hasRight(
'commande',
'lire') ||
440 ($view ===
'create' && $this->
user->hasRight(
'commande',
'creer'));
443 case 'order_supplier':
444 $permitted = $this->
user->hasRight(
'fournisseur',
'commande->lire') ||
445 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'commande->creer'));
449 $permitted = $this->
user->hasRight(
'propal',
'lire') ||
450 ($view ===
'create' && $this->
user->hasRight(
'propal',
'creer'));
454 $permitted = $this->
user->hasRight(
'expedition',
'lire') ||
455 ($view ===
'create' && $this->
user->hasRight(
'expedition',
'creer'));
459 $permitted = $this->
user->hasRight(
'facture',
'paiement');
462 case 'payment_supplier':
463 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->paiement');
467 $permitted = $this->
user->hasRight(
'banque',
'lire') ||
468 ($view ===
'create' && $this->
user->hasRight(
'banque',
'creer'));
472 $permitted = $this->
user->hasRight(
'agenda',
'myactions->read') ||
473 $this->
user->hasRight(
'agenda',
'allactions->read');
477 $permitted = $this->
user->hasRight(
'contrat',
'lire') ||
478 ($view ===
'create' && $this->
user->hasRight(
'contrat',
'creer'));
482 $permitted = $this->
user->hasRight(
'ficheinter',
'lire') ||
483 ($view ===
'create' && $this->
user->hasRight(
'ficheinter',
'creer'));
487 $permitted = $this->
user->hasRight(
'adherent',
'lire') ||
488 ($view ===
'create' && $this->
user->hasRight(
'adherent',
'creer'));
492 $permitted = $this->
user->hasRight(
'categorie',
'lire') ||
493 ($view ===
'create' && $this->
user->hasRight(
'categorie',
'creer'));
503 if ($permitted &&
$id > 0) {
522 if ($elementType ===
'thirdparty') {
523 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
525 if ($soc->fetch(
$id) > 0) {
526 return $soc->isInEEC() || $soc->isCustomer() || $soc->isSupplier();
532 if ($elementType ===
'project') {
533 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
535 if ($project->fetch(
$id) > 0) {
536 return $project->restrictedProjectArea($this->
user) == 0;
560 $langs->load(
"companies");
561 $langs->load(
"bills");
562 $langs->load(
"orders");
563 $langs->load(
"propal");
564 $langs->load(
"projects");
570 $label = $langs->trans(
"ThirdParty");
573 $label = $langs->trans(
"Contact");
576 $label = $langs->trans(
"ProductService");
579 $label = $langs->trans(
"Project");
582 $label = $langs->trans(
"Task");
584 case 'invoice_customer':
585 $label = $langs->trans(
"CustomerInvoice");
587 case 'invoice_supplier':
588 $label = $langs->trans(
"SupplierInvoice");
591 $label = $langs->trans(
"CustomerOrder");
593 case 'order_supplier':
594 $label = $langs->trans(
"SupplierOrder");
597 $label = $langs->trans(
"Proposal");
600 $label = $langs->trans(
"Shipment");
603 $label = $langs->trans(
"Payment");
605 case 'payment_supplier':
606 $label = $langs->trans(
"SupplierPayment");
609 $label = $langs->trans(
"BankAccount");
612 $label = $langs->trans(
"Event");
615 $label = $langs->trans(
"Contract");
618 $label = $langs->trans(
"Intervention");
621 $label = $langs->trans(
"Member");
624 $label = $langs->trans(
"Category");
627 $label = ucfirst($type);
632 if ($view ===
'list') {
633 $baseDesc = $langs->trans(
"ListOf") .
" " . $label;
634 if (!empty($statusFilter)) {
635 return $baseDesc .
" (" . ucfirst($statusFilter) .
")";
638 } elseif ($view ===
'create') {
639 return $langs->trans(
"New") .
" " . $label;
641 return $label .
" #" .
$id;
$id
Support class for third parties, contacts, members, users or resources.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db user
Active Directory does not allow anonymous connections.