20require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
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"]
94 public function execute(
string $name, array $args)
99 $langs->load(
"companies");
100 $langs->load(
"bills");
101 $langs->load(
"orders");
102 $langs->load(
"propal");
103 $langs->load(
"projects");
104 $langs->load(
"sendings");
106 if ($name !==
'navigate_to_page') {
110 if (empty($this->
user->id)) {
111 return [
"error" =>
"Permission Denied: User not logged in."];
114 $rawType = $args[
'object_type'] ??
'';
115 $view = $args[
'view'] ??
'list';
116 $id = (int) ($args[
'id'] ?? 0);
117 $ref = $args[
'ref'] ??
'';
118 $statusFilter = $args[
'status_filter'] ??
'';
119 $params = $args[
'params'] ?? [];
124 if (empty($pathInfo)) {
125 return [
"error" =>
"Unknown object type: '$rawType'. Try 'invoice', 'order', or 'thirdparty'."];
128 $relativePath = $pathInfo[
'path'];
129 $elementType = $pathInfo[
'type'];
133 return [
"error" =>
"Permission Denied: You don't have permission to access this resource."];
141 $queryParams[
'id'] =
$id;
142 } elseif (!empty($ref)) {
143 $queryParams[
'ref'] = $ref;
147 if ($view ===
'create') {
148 $queryParams[
'action'] =
'create';
152 if ($view ===
'list' && !empty($statusFilter)) {
155 $queryParams = array_merge($queryParams, $statusParam);
157 return [
"error" =>
"Unknown status filter '$statusFilter' for object type '$rawType'."];
159 } elseif (!empty($statusFilter)) {
160 return [
"error" =>
"The 'status_filter' parameter can only be used with the 'list' view."];
164 if (!empty($params) && is_array($params)) {
165 $queryParams = array_merge($queryParams, $params);
171 $finalUrl = $baseUrl;
172 if (!empty($queryParams)) {
173 $finalUrl .=
'?' . http_build_query($queryParams);
180 "resolved_type" => $elementType,
181 "path" => $relativePath
196 $statusFilter = strtolower(trim($statusFilter));
200 'invoice_customer' => [
201 'draft' => [
'statut' => 0],
202 'unpaid' => [
'statut' => 1],
203 'paid' => [
'statut' => 2],
205 'invoice_supplier' => [
206 'draft' => [
'statut' => 0],
207 'unpaid' => [
'statut' => 1],
208 'paid' => [
'statut' => 2],
211 'draft' => [
'statut' => 0],
212 'validated' => [
'statut' => 1],
213 'shipped' => [
'statut' => 2],
214 'closed' => [
'statut' => 3],
215 'canceled' => [
'statut' => -1],
217 'order_supplier' => [
218 'draft' => [
'statut' => 0],
219 'validated' => [
'statut' => 1],
220 'approved' => [
'statut' => 2],
221 'received' => [
'statut' => 3],
222 'canceled' => [
'statut' => -1],
225 'draft' => [
'statut' => 0],
226 'open' => [
'statut' => 1],
227 'signed' => [
'statut' => 2],
228 'billed' => [
'statut' => 3],
229 'refused' => [
'statut' => 4],
230 'canceled' => [
'statut' => 5],
233 'draft' => [
'status' => 0],
234 'open' => [
'status' => 1],
235 'closed' => [
'status' => 2],
238 'draft' => [
'status' => 0],
239 'validated' => [
'status' => 1],
240 'shipped' => [
'status' => 2],
241 'canceled' => [
'status' => -1],
244 'draft' => [
'statut' => 0],
245 'active' => [
'statut' => 1],
246 'closed' => [
'statut' => 2],
247 'resiliated' => [
'statut' => 3],
250 'draft' => [
'statut' => 0],
251 'validated' => [
'statut' => 1],
252 'billed' => [
'statut' => 2],
253 'closed' => [
'statut' => 3],
258 return $statusMap[$elementType][$statusFilter] ??
null;
270 $input = strtolower(trim($input));
275 'invoice' =>
'invoice_customer',
276 'bill' =>
'invoice_customer',
277 'facture' =>
'invoice_customer',
278 'supplier_invoice' =>
'invoice_supplier',
279 'vendor_bill' =>
'invoice_supplier',
281 'company' =>
'thirdparty',
282 'societe' =>
'thirdparty',
283 'customer' =>
'thirdparty',
284 'client' =>
'thirdparty',
285 'supplier' =>
'thirdparty',
286 'vendor' =>
'thirdparty',
288 'propal' =>
'proposal',
289 'quote' =>
'proposal',
290 'command' =>
'order',
291 'customer_order' =>
'order',
292 'supplier_order' =>
'order_supplier',
294 'product' =>
'product',
295 'service' =>
'product',
297 'project' =>
'project',
298 'task' =>
'project_task',
300 'shipment' =>
'expedition',
301 'shipping' =>
'expedition',
302 'delivery' =>
'expedition',
304 'payment' =>
'payment',
305 'payment_customer' =>
'payment',
306 'payment_supplier' =>
'payment_supplier',
308 'transaction' =>
'bank',
310 'bank_account' =>
'bank',
313 'agenda' =>
'agenda',
314 'appointment' =>
'agenda',
316 'contract' =>
'contract',
318 'intervention' =>
'fichinter',
320 'member' =>
'adherent',
321 'membership' =>
'adherent',
323 'category' =>
'categories',
326 $type = $aliases[$input] ?? $input;
330 'thirdparty' =>
'/societe/',
331 'contact' =>
'/contact/',
332 'product' =>
'/product/',
333 'project' =>
'/projet/',
334 'project_task' =>
'/projet/tasks/',
335 'invoice_customer' =>
'/compta/facture/',
336 'invoice_supplier' =>
'/fourn/facture/',
337 'order' =>
'/commande/',
338 'order_supplier' =>
'/fourn/commande/',
339 'proposal' =>
'/comm/propal/',
340 'expedition' =>
'/expedition/',
341 'payment' =>
'/compta/paiement.php',
342 'payment_supplier' =>
'/fourn/paiement.php',
343 'bank' =>
'/compta/bank/',
344 'agenda' =>
'/comm/action/',
345 'contract' =>
'/contrat/',
346 'fichinter' =>
'/fichinter/',
347 'adherent' =>
'/adherents/',
348 'categories' =>
'/categories/',
351 if (!isset($map[$type])) {
359 if (strpos($dir,
'.php') !==
false) {
366 $script =
'list.php';
368 if ($view ===
'card' || $view ===
'create') {
369 $script =
'card.php';
374 'path' => $dir . $script
392 switch ($elementType) {
394 $permitted = $this->
user->hasRight(
'societe',
'lire') ||
395 ($view ===
'create' && $this->
user->hasRight(
'societe',
'creer'));
399 $permitted = $this->
user->hasRight(
'societe',
'contact->lire') ||
400 ($view ===
'create' && $this->
user->hasRight(
'societe',
'contact->creer'));
404 $permitted = $this->
user->hasRight(
'produit',
'lire') ||
405 ($view ===
'create' && $this->
user->hasRight(
'produit',
'creer'));
409 $permitted = $this->
user->hasRight(
'projet',
'lire') ||
410 ($view ===
'create' && $this->
user->hasRight(
'projet',
'creer'));
414 $permitted = $this->
user->hasRight(
'projet',
'lire');
417 case 'invoice_customer':
418 $permitted = $this->
user->hasRight(
'facture',
'lire') ||
419 ($view ===
'create' && $this->
user->hasRight(
'facture',
'creer'));
422 case 'invoice_supplier':
423 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->lire') ||
424 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'facture->creer'));
428 $permitted = $this->
user->hasRight(
'commande',
'lire') ||
429 ($view ===
'create' && $this->
user->hasRight(
'commande',
'creer'));
432 case 'order_supplier':
433 $permitted = $this->
user->hasRight(
'fournisseur',
'commande->lire') ||
434 ($view ===
'create' && $this->
user->hasRight(
'fournisseur',
'commande->creer'));
438 $permitted = $this->
user->hasRight(
'propal',
'lire') ||
439 ($view ===
'create' && $this->
user->hasRight(
'propal',
'creer'));
443 $permitted = $this->
user->hasRight(
'expedition',
'lire') ||
444 ($view ===
'create' && $this->
user->hasRight(
'expedition',
'creer'));
448 $permitted = $this->
user->hasRight(
'facture',
'paiement');
451 case 'payment_supplier':
452 $permitted = $this->
user->hasRight(
'fournisseur',
'facture->paiement');
456 $permitted = $this->
user->hasRight(
'banque',
'lire') ||
457 ($view ===
'create' && $this->
user->hasRight(
'banque',
'creer'));
461 $permitted = $this->
user->hasRight(
'agenda',
'myactions->read') ||
462 $this->
user->hasRight(
'agenda',
'allactions->read');
466 $permitted = $this->
user->hasRight(
'contrat',
'lire') ||
467 ($view ===
'create' && $this->
user->hasRight(
'contrat',
'creer'));
471 $permitted = $this->
user->hasRight(
'ficheinter',
'lire') ||
472 ($view ===
'create' && $this->
user->hasRight(
'ficheinter',
'creer'));
476 $permitted = $this->
user->hasRight(
'adherent',
'lire') ||
477 ($view ===
'create' && $this->
user->hasRight(
'adherent',
'creer'));
481 $permitted = $this->
user->hasRight(
'categorie',
'lire') ||
482 ($view ===
'create' && $this->
user->hasRight(
'categorie',
'creer'));
492 if ($permitted &&
$id > 0) {
511 if ($elementType ===
'thirdparty') {
512 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
514 if ($soc->fetch(
$id) > 0) {
515 return $soc->isInEEC() || $soc->isCustomer() || $soc->isSupplier();
521 if ($elementType ===
'project') {
522 require_once DOL_DOCUMENT_ROOT .
'/projet/class/project.class.php';
524 if ($project->fetch(
$id) > 0) {
525 return $project->restrictedProjectArea($this->
user) == 0;
549 $langs->load(
"companies");
550 $langs->load(
"bills");
551 $langs->load(
"orders");
552 $langs->load(
"propal");
553 $langs->load(
"projects");
559 $label = $langs->trans(
"ThirdParty");
562 $label = $langs->trans(
"Contact");
565 $label = $langs->trans(
"ProductService");
568 $label = $langs->trans(
"Project");
571 $label = $langs->trans(
"Task");
573 case 'invoice_customer':
574 $label = $langs->trans(
"CustomerInvoice");
576 case 'invoice_supplier':
577 $label = $langs->trans(
"SupplierInvoice");
580 $label = $langs->trans(
"CustomerOrder");
582 case 'order_supplier':
583 $label = $langs->trans(
"SupplierOrder");
586 $label = $langs->trans(
"Proposal");
589 $label = $langs->trans(
"Shipment");
592 $label = $langs->trans(
"Payment");
594 case 'payment_supplier':
595 $label = $langs->trans(
"SupplierPayment");
598 $label = $langs->trans(
"BankAccount");
601 $label = $langs->trans(
"Event");
604 $label = $langs->trans(
"Contract");
607 $label = $langs->trans(
"Intervention");
610 $label = $langs->trans(
"Member");
613 $label = $langs->trans(
"Category");
616 $label = ucfirst($type);
621 if ($view ===
'list') {
622 $baseDesc = $langs->trans(
"ListOf") .
" " . $label;
623 if (!empty($statusFilter)) {
624 return $baseDesc .
" (" . ucfirst($statusFilter) .
")";
627 } elseif ($view ===
'create') {
628 return $langs->trans(
"New") .
" " . $label;
630 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.