21require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
22require_once DOL_DOCUMENT_ROOT .
'/core/class/extrafields.class.php';
40 "name" =>
"navigate_to_page",
41 "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.",
47 "description" =>
"The object type. Examples: 'invoice', 'thirdparty', 'order', 'proposal', 'project', 'supplier_invoice'.",
51 "description" =>
"The type of view needed: 'list', 'card', 'create'.",
52 "enum" => [
"list",
"card",
"create"]
56 "description" =>
"The ID of the record (optional)."
60 "description" =>
"The Reference of the record (optional)."
64 "description" =>
"A human-readable status to filter the list. Only applies to 'list' view. Examples: 'draft', 'open', 'paid', 'shipped', 'closed', 'canceled'."
68 "description" =>
"Additional URL parameters (e.g. {'search_thirdparty': 'MyCompany'}). These will be combined with the status filter."
71 "required" => [
"object_type",
"view"]
95 public function execute(
string $name, array $args)
100 $langs->load(
"companies");
101 $langs->load(
"bills");
102 $langs->load(
"orders");
103 $langs->load(
"propal");
104 $langs->load(
"projects");
105 $langs->load(
"sendings");
107 if ($name !==
'navigate_to_page') {
111 if (empty($this->
user->id)) {
112 return [
"error" =>
"Permission Denied: User not logged in."];
115 $rawType = $args[
'object_type'] ??
'';
116 $view = $args[
'view'] ??
'list';
117 $id = (int) ($args[
'id'] ?? 0);
118 $ref = $args[
'ref'] ??
'';
119 $statusFilter = $args[
'status_filter'] ??
'';
120 $params = $args[
'params'] ?? [];
125 if (empty($pathInfo)) {
126 return [
"error" =>
"Unknown object type: '$rawType'. Try 'invoice', 'order', or 'thirdparty'."];
129 $relativePath = $pathInfo[
'path'];
130 $elementType = $pathInfo[
'type'];
134 return [
"error" =>
"Permission Denied: You don't have permission to access this resource."];
138 $getQueryParams = [];
142 $getQueryParams[
'id'] =
$id;
143 } elseif (!empty($ref)) {
144 $getQueryParams[
'ref'] = $ref;
148 if ($view ===
'create') {
149 $getQueryParams[
'action'] =
'create';
153 if ($view ===
'list' && !empty($statusFilter)) {
156 $getQueryParams = array_merge($getQueryParams, $statusParam);
158 return [
"error" =>
"Unknown status filter '$statusFilter' for object type '$rawType'."];
160 } elseif (!empty($statusFilter)) {
161 return [
"error" =>
"The 'status_filter' parameter can only be used with the 'list' view."];
165 if (!empty($params) && is_array($params)) {
166 $getQueryParams = array_merge($getQueryParams, $params);
172 $finalUrl = $baseUrl;
173 if (!empty($getQueryParams)) {
174 $finalUrl .=
'?' . http_build_query($getQueryParams);
181 "resolved_type" => $elementType,
182 "path" => $relativePath
197 $statusFilter = strtolower(trim($statusFilter));
201 'invoice_customer' => [
202 'draft' => [
'statut' => 0],
203 'unpaid' => [
'statut' => 1],
204 'paid' => [
'statut' => 2],
206 'invoice_supplier' => [
207 'draft' => [
'statut' => 0],
208 'unpaid' => [
'statut' => 1],
209 'paid' => [
'statut' => 2],
212 'draft' => [
'statut' => 0],
213 'validated' => [
'statut' => 1],
214 'shipped' => [
'statut' => 2],
215 'closed' => [
'statut' => 3],
216 'canceled' => [
'statut' => -1],
218 'order_supplier' => [
219 'draft' => [
'statut' => 0],
220 'validated' => [
'statut' => 1],
221 'approved' => [
'statut' => 2],
222 'received' => [
'statut' => 3],
223 'canceled' => [
'statut' => -1],
226 'draft' => [
'statut' => 0],
227 'open' => [
'statut' => 1],
228 'signed' => [
'statut' => 2],
229 'billed' => [
'statut' => 3],
230 'refused' => [
'statut' => 4],
231 'canceled' => [
'statut' => 5],
234 'draft' => [
'status' => 0],
235 'open' => [
'status' => 1],
236 'closed' => [
'status' => 2],
239 'draft' => [
'status' => 0],
240 'validated' => [
'status' => 1],
241 'shipped' => [
'status' => 2],
242 'canceled' => [
'status' => -1],
245 'draft' => [
'statut' => 0],
246 'active' => [
'statut' => 1],
247 'closed' => [
'statut' => 2],
248 'resiliated' => [
'statut' => 3],
251 'draft' => [
'statut' => 0],
252 'validated' => [
'statut' => 1],
253 'billed' => [
'statut' => 2],
254 'closed' => [
'statut' => 3],
259 return $statusMap[$elementType][$statusFilter] ??
null;
271 $input = strtolower(trim($input));
276 'invoice' =>
'invoice_customer',
277 'bill' =>
'invoice_customer',
278 'facture' =>
'invoice_customer',
279 'supplier_invoice' =>
'invoice_supplier',
280 'vendor_bill' =>
'invoice_supplier',
282 'company' =>
'thirdparty',
283 'societe' =>
'thirdparty',
284 'customer' =>
'thirdparty',
285 'client' =>
'thirdparty',
286 'supplier' =>
'thirdparty',
287 'vendor' =>
'thirdparty',
289 'propal' =>
'proposal',
290 'quote' =>
'proposal',
291 'command' =>
'order',
292 'customer_order' =>
'order',
293 'supplier_order' =>
'order_supplier',
295 'product' =>
'product',
296 'service' =>
'product',
298 'project' =>
'project',
299 'task' =>
'project_task',
301 'shipment' =>
'expedition',
302 'shipping' =>
'expedition',
303 'delivery' =>
'expedition',
305 'payment' =>
'payment',
306 'payment_customer' =>
'payment',
307 'payment_supplier' =>
'payment_supplier',
309 'transaction' =>
'bank',
311 'bank_account' =>
'bank',
314 'agenda' =>
'agenda',
315 'appointment' =>
'agenda',
317 'contract' =>
'contract',
319 'intervention' =>
'fichinter',
321 'member' =>
'adherent',
322 'membership' =>
'adherent',
324 'category' =>
'categories',
327 $type = $aliases[$input] ?? $input;
331 'thirdparty' =>
'/societe/',
332 'contact' =>
'/contact/',
333 'product' =>
'/product/',
334 'project' =>
'/projet/',
335 'project_task' =>
'/projet/tasks/',
336 'invoice_customer' =>
'/compta/facture/',
337 'invoice_supplier' =>
'/fourn/facture/',
338 'order' =>
'/commande/',
339 'order_supplier' =>
'/fourn/commande/',
340 'proposal' =>
'/comm/propal/',
341 'expedition' =>
'/expedition/',
342 'payment' =>
'/compta/paiement.php',
343 'payment_supplier' =>
'/fourn/paiement.php',
344 'bank' =>
'/compta/bank/',
345 'agenda' =>
'/comm/action/',
346 'contract' =>
'/contrat/',
347 'fichinter' =>
'/fichinter/',
348 'adherent' =>
'/adherents/',
349 'categories' =>
'/categories/',
352 if (!isset($map[$type])) {
360 if (strpos($dir,
'.php') !==
false) {
367 $script =
'list.php';
369 if ($view ===
'card' || $view ===
'create') {
370 $script =
'card.php';
375 'path' => $dir . $script
393 switch ($elementType) {
395 $permitted = $this->
user->hasRight(
'societe',
'lire') ||
396 ($view ===
'create' && $this->
user->hasRight(
'societe',
'creer'));
400 $permitted = $this->
user->hasRight(
'societe',
'contact->lire') ||
401 ($view ===
'create' && $this->
user->hasRight(
'societe',
'contact->creer'));
405 $permitted = $this->
user->hasRight(
'produit',
'lire') ||
406 ($view ===
'create' && $this->
user->hasRight(
'produit',
'creer'));
410 $permitted = $this->
user->hasRight(
'projet',
'lire') ||
411 ($view ===
'create' && $this->
user->hasRight(
'projet',
'creer'));
415 $permitted = $this->
user->hasRight(
'projet',
'lire');
418 case 'invoice_customer':
419 $permitted = $this->
user->hasRight(
'facture',
'lire') ||
420 ($view ===
'create' && $this->
user->hasRight(
'facture',
'creer'));
423 case 'invoice_supplier':
424 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->lire') ||
425 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'facture->creer'));
429 $permitted = $this->
user->hasRight(
'commande',
'lire') ||
430 ($view ===
'create' && $this->
user->hasRight(
'commande',
'creer'));
433 case 'order_supplier':
434 $permitted = $this->
user->hasRight(
'fournisseur',
'commande->lire') ||
435 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'commande->creer'));
439 $permitted = $this->
user->hasRight(
'propal',
'lire') ||
440 ($view ===
'create' && $this->
user->hasRight(
'propal',
'creer'));
444 $permitted = $this->
user->hasRight(
'expedition',
'lire') ||
445 ($view ===
'create' && $this->
user->hasRight(
'expedition',
'creer'));
449 $permitted = $this->
user->hasRight(
'facture',
'paiement');
452 case 'payment_supplier':
453 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->paiement');
457 $permitted = $this->
user->hasRight(
'banque',
'lire') ||
458 ($view ===
'create' && $this->
user->hasRight(
'banque',
'creer'));
462 $permitted = $this->
user->hasRight(
'agenda',
'myactions->read') ||
463 $this->
user->hasRight(
'agenda',
'allactions->read');
467 $permitted = $this->
user->hasRight(
'contrat',
'lire') ||
468 ($view ===
'create' && $this->
user->hasRight(
'contrat',
'creer'));
472 $permitted = $this->
user->hasRight(
'ficheinter',
'lire') ||
473 ($view ===
'create' && $this->
user->hasRight(
'ficheinter',
'creer'));
477 $permitted = $this->
user->hasRight(
'adherent',
'lire') ||
478 ($view ===
'create' && $this->
user->hasRight(
'adherent',
'creer'));
482 $permitted = $this->
user->hasRight(
'categorie',
'lire') ||
483 ($view ===
'create' && $this->
user->hasRight(
'categorie',
'creer'));
493 if ($permitted &&
$id > 0) {
512 if ($elementType ===
'thirdparty') {
513 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
515 if ($soc->fetch(
$id) > 0) {
516 return $soc->isInEEC() || $soc->isCustomer() || $soc->isSupplier();
522 if ($elementType ===
'project') {
523 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
525 if ($project->fetch(
$id) > 0) {
526 return $project->restrictedProjectArea($this->
user) == 0;
550 $langs->load(
"companies");
551 $langs->load(
"bills");
552 $langs->load(
"orders");
553 $langs->load(
"propal");
554 $langs->load(
"projects");
560 $label = $langs->trans(
"ThirdParty");
563 $label = $langs->trans(
"Contact");
566 $label = $langs->trans(
"ProductService");
569 $label = $langs->trans(
"Project");
572 $label = $langs->trans(
"Task");
574 case 'invoice_customer':
575 $label = $langs->trans(
"CustomerInvoice");
577 case 'invoice_supplier':
578 $label = $langs->trans(
"SupplierInvoice");
581 $label = $langs->trans(
"CustomerOrder");
583 case 'order_supplier':
584 $label = $langs->trans(
"SupplierOrder");
587 $label = $langs->trans(
"Proposal");
590 $label = $langs->trans(
"Shipment");
593 $label = $langs->trans(
"Payment");
595 case 'payment_supplier':
596 $label = $langs->trans(
"SupplierPayment");
599 $label = $langs->trans(
"BankAccount");
602 $label = $langs->trans(
"Event");
605 $label = $langs->trans(
"Contract");
608 $label = $langs->trans(
"Intervention");
611 $label = $langs->trans(
"Member");
614 $label = $langs->trans(
"Category");
617 $label = ucfirst($type);
622 if ($view ===
'list') {
623 $baseDesc = $langs->trans(
"ListOf") .
" " . $label;
624 if (!empty($statusFilter)) {
625 return $baseDesc .
" (" . ucfirst($statusFilter) .
")";
628 } elseif ($view ===
'create') {
629 return $langs->trans(
"New") .
" " . $label;
631 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.