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', 'website'.",
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 ($elementType ===
'website') {
164 $getQueryParams = [];
166 $getQueryParams[
'websiteid'] =
$id;
167 } elseif (!empty($ref)) {
168 $getQueryParams[
'website'] = $ref;
170 if ($view ===
'create') {
171 $getQueryParams[
'action'] =
'createsite';
176 if ($view ===
'list' && !empty($statusFilter)) {
179 $getQueryParams = array_merge($getQueryParams, $statusParam);
181 return [
"error" =>
"Unknown status filter '$statusFilter' for object type '$rawType'."];
183 } elseif (!empty($statusFilter)) {
184 return [
"error" =>
"The 'status_filter' parameter can only be used with the 'list' view."];
188 if (!empty($params) && is_array($params)) {
189 $getQueryParams = array_merge($getQueryParams, $params);
195 $finalUrl = $baseUrl;
196 if (!empty($getQueryParams)) {
197 $finalUrl .=
'?' . http_build_query($getQueryParams);
204 "resolved_type" => $elementType,
205 "path" => $relativePath
220 $statusFilter = strtolower(trim($statusFilter));
224 'invoice_customer' => [
225 'draft' => [
'statut' => 0],
226 'unpaid' => [
'statut' => 1],
227 'paid' => [
'statut' => 2],
229 'invoice_supplier' => [
230 'draft' => [
'statut' => 0],
231 'unpaid' => [
'statut' => 1],
232 'paid' => [
'statut' => 2],
235 'draft' => [
'statut' => 0],
236 'validated' => [
'statut' => 1],
237 'shipped' => [
'statut' => 2],
238 'closed' => [
'statut' => 3],
239 'canceled' => [
'statut' => -1],
241 'order_supplier' => [
242 'draft' => [
'statut' => 0],
243 'validated' => [
'statut' => 1],
244 'approved' => [
'statut' => 2],
245 'received' => [
'statut' => 3],
246 'canceled' => [
'statut' => -1],
249 'draft' => [
'statut' => 0],
250 'open' => [
'statut' => 1],
251 'signed' => [
'statut' => 2],
252 'billed' => [
'statut' => 3],
253 'refused' => [
'statut' => 4],
254 'canceled' => [
'statut' => 5],
257 'draft' => [
'status' => 0],
258 'open' => [
'status' => 1],
259 'closed' => [
'status' => 2],
262 'draft' => [
'status' => 0],
263 'validated' => [
'status' => 1],
264 'shipped' => [
'status' => 2],
265 'canceled' => [
'status' => -1],
268 'draft' => [
'statut' => 0],
269 'active' => [
'statut' => 1],
270 'closed' => [
'statut' => 2],
271 'resiliated' => [
'statut' => 3],
274 'draft' => [
'statut' => 0],
275 'validated' => [
'statut' => 1],
276 'billed' => [
'statut' => 2],
277 'closed' => [
'statut' => 3],
282 return $statusMap[$elementType][$statusFilter] ??
null;
294 $input = strtolower(trim($input));
299 'invoice' =>
'invoice_customer',
300 'bill' =>
'invoice_customer',
301 'facture' =>
'invoice_customer',
302 'supplier_invoice' =>
'invoice_supplier',
303 'vendor_bill' =>
'invoice_supplier',
305 'company' =>
'thirdparty',
306 'societe' =>
'thirdparty',
307 'customer' =>
'thirdparty',
308 'client' =>
'thirdparty',
309 'supplier' =>
'thirdparty',
310 'vendor' =>
'thirdparty',
312 'propal' =>
'proposal',
313 'quote' =>
'proposal',
314 'command' =>
'order',
315 'customer_order' =>
'order',
316 'supplier_order' =>
'order_supplier',
318 'product' =>
'product',
319 'service' =>
'product',
321 'project' =>
'project',
322 'task' =>
'project_task',
324 'shipment' =>
'expedition',
325 'shipping' =>
'expedition',
326 'delivery' =>
'expedition',
328 'payment' =>
'payment',
329 'payment_customer' =>
'payment',
330 'payment_supplier' =>
'payment_supplier',
332 'transaction' =>
'bank',
334 'bank_account' =>
'bank',
337 'agenda' =>
'agenda',
338 'appointment' =>
'agenda',
340 'contract' =>
'contract',
342 'intervention' =>
'fichinter',
344 'member' =>
'adherent',
345 'membership' =>
'adherent',
347 'category' =>
'categories',
350 'web_site' =>
'website',
353 $type = $aliases[$input] ?? $input;
357 'thirdparty' =>
'/societe/',
358 'contact' =>
'/contact/',
359 'product' =>
'/product/',
360 'project' =>
'/projet/',
361 'project_task' =>
'/projet/tasks/',
362 'invoice_customer' =>
'/compta/facture/',
363 'invoice_supplier' =>
'/fourn/facture/',
364 'order' =>
'/commande/',
365 'order_supplier' =>
'/fourn/commande/',
366 'proposal' =>
'/comm/propal/',
367 'expedition' =>
'/expedition/',
368 'payment' =>
'/compta/paiement.php',
369 'payment_supplier' =>
'/fourn/paiement.php',
370 'bank' =>
'/compta/bank/',
371 'agenda' =>
'/comm/action/',
372 'contract' =>
'/contrat/',
373 'fichinter' =>
'/fichinter/',
374 'adherent' =>
'/adherents/',
375 'categories' =>
'/categories/',
376 'website' =>
'/website/index.php',
379 if (!isset($map[$type])) {
387 if (strpos($dir,
'.php') !==
false) {
394 $script =
'list.php';
396 if ($view ===
'card' || $view ===
'create') {
397 $script =
'card.php';
402 'path' => $dir . $script
420 switch ($elementType) {
422 $permitted = $this->
user->hasRight(
'societe',
'lire') ||
423 ($view ===
'create' && $this->
user->hasRight(
'societe',
'creer'));
427 $permitted = $this->
user->hasRight(
'societe',
'contact->lire') ||
428 ($view ===
'create' && $this->
user->hasRight(
'societe',
'contact->creer'));
432 $permitted = $this->
user->hasRight(
'produit',
'lire') ||
433 ($view ===
'create' && $this->
user->hasRight(
'produit',
'creer'));
437 $permitted = $this->
user->hasRight(
'projet',
'lire') ||
438 ($view ===
'create' && $this->
user->hasRight(
'projet',
'creer'));
442 $permitted = $this->
user->hasRight(
'projet',
'lire');
445 case 'invoice_customer':
446 $permitted = $this->
user->hasRight(
'facture',
'lire') ||
447 ($view ===
'create' && $this->
user->hasRight(
'facture',
'creer'));
450 case 'invoice_supplier':
451 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->lire') ||
452 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'facture->creer'));
456 $permitted = $this->
user->hasRight(
'commande',
'lire') ||
457 ($view ===
'create' && $this->
user->hasRight(
'commande',
'creer'));
460 case 'order_supplier':
461 $permitted = $this->
user->hasRight(
'fournisseur',
'commande->lire') ||
462 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'commande->creer'));
466 $permitted = $this->
user->hasRight(
'propal',
'lire') ||
467 ($view ===
'create' && $this->
user->hasRight(
'propal',
'creer'));
471 $permitted = $this->
user->hasRight(
'expedition',
'lire') ||
472 ($view ===
'create' && $this->
user->hasRight(
'expedition',
'creer'));
476 $permitted = $this->
user->hasRight(
'facture',
'paiement');
479 case 'payment_supplier':
480 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->paiement');
484 $permitted = $this->
user->hasRight(
'banque',
'lire') ||
485 ($view ===
'create' && $this->
user->hasRight(
'banque',
'creer'));
489 $permitted = $this->
user->hasRight(
'agenda',
'myactions->read') ||
490 $this->
user->hasRight(
'agenda',
'allactions->read');
494 $permitted = $this->
user->hasRight(
'contrat',
'lire') ||
495 ($view ===
'create' && $this->
user->hasRight(
'contrat',
'creer'));
499 $permitted = $this->
user->hasRight(
'ficheinter',
'lire') ||
500 ($view ===
'create' && $this->
user->hasRight(
'ficheinter',
'creer'));
504 $permitted = $this->
user->hasRight(
'adherent',
'lire') ||
505 ($view ===
'create' && $this->
user->hasRight(
'adherent',
'creer'));
509 $permitted = $this->
user->hasRight(
'categorie',
'lire') ||
510 ($view ===
'create' && $this->
user->hasRight(
'categorie',
'creer'));
514 $permitted =
isModEnabled(
'website') && $this->
user->hasRight(
'website',
'read') &&
515 ($view !==
'create' || $this->
user->hasRight(
'website',
'write'));
525 if ($permitted &&
$id > 0) {
544 if ($elementType ===
'thirdparty') {
545 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
547 if ($soc->fetch(
$id) > 0) {
548 return $soc->isInEEC() || $soc->isCustomer() || $soc->isSupplier();
554 if ($elementType ===
'project') {
555 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
557 if ($project->fetch(
$id) > 0) {
558 return $project->restrictedProjectArea($this->
user) == 0;
582 $langs->load(
"companies");
583 $langs->load(
"bills");
584 $langs->load(
"orders");
585 $langs->load(
"propal");
586 $langs->load(
"projects");
592 $label = $langs->trans(
"ThirdParty");
595 $label = $langs->trans(
"Contact");
598 $label = $langs->trans(
"ProductService");
601 $label = $langs->trans(
"Project");
604 $label = $langs->trans(
"Task");
606 case 'invoice_customer':
607 $label = $langs->trans(
"CustomerInvoice");
609 case 'invoice_supplier':
610 $label = $langs->trans(
"SupplierInvoice");
613 $label = $langs->trans(
"CustomerOrder");
615 case 'order_supplier':
616 $label = $langs->trans(
"SupplierOrder");
619 $label = $langs->trans(
"Proposal");
622 $label = $langs->trans(
"Shipment");
625 $label = $langs->trans(
"Payment");
627 case 'payment_supplier':
628 $label = $langs->trans(
"SupplierPayment");
631 $label = $langs->trans(
"BankAccount");
634 $label = $langs->trans(
"Event");
637 $label = $langs->trans(
"Contract");
640 $label = $langs->trans(
"Intervention");
643 $label = $langs->trans(
"Member");
646 $label = $langs->trans(
"Category");
649 $label = $langs->trans(
"WebSite");
652 $label = ucfirst($type);
657 if ($view ===
'list') {
658 $baseDesc = $langs->trans(
"ListOf") .
" " . $label;
659 if (!empty($statusFilter)) {
660 return $baseDesc .
" (" . ucfirst($statusFilter) .
")";
663 } elseif ($view ===
'create') {
664 return $langs->trans(
"New") .
" " . $label;
666 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.
isModEnabled($module)
Is Dolibarr module enabled.
$conf db user
Active Directory does not allow anonymous connections.