dolibarr 24.0.0-beta
ajaxstatusprospect.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2010 Cyrille de Lambert <info@auguria.net>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29if (!defined('NOTOKENRENEWAL')) {
30 define('NOTOKENRENEWAL', 1);
31} // Disables token renewal
32if (!defined('NOREQUIREMENU')) {
33 define('NOREQUIREMENU', '1');
34}
35if (!defined('NOREQUIREHTML')) {
36 define('NOREQUIREHTML', '1');
37}
38if (!defined('NOREQUIREAJAX')) {
39 define('NOREQUIREAJAX', '1');
40}
41if (!defined('NOREQUIRESOC')) {
42 define('NOREQUIRESOC', '1');
43}
44
45// Load Dolibarr environment
46require '../../main.inc.php';
54require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
55
56$idstatus = GETPOSTINT('id');
57$idprospect = GETPOSTINT('prospectid');
58$action = GETPOST('action', 'aZ09');
59
60$prospectstatic = new Client($db);
61
62
63// Security check
64if ($user->socid > 0) {
65 if ($idprospect != $user->socid) {
66 accessforbidden('Not allowed on this thirdparty');
67 }
68}
69
70// var_dump( $user, 'societe', $idprospect, '&societe');
71$result = restrictedArea($user, 'societe', $idprospect, '&societe');
72
73$permisstiontoupdate = $user->hasRight('societe', 'creer');
74
75
76/*
77 * View
78 */
79
80top_httphead('application/json');
81
82
83if ($action === "updatestatusprospect" && $permisstiontoupdate) {
84 $prospectstatic->client = 2;
85 $prospectstatic->loadCacheOfProspStatus();
86
87 $response = "";
88
89 // Load thirdparty
90 $prospect = new Societe($db);
91 $result = $prospect->fetch($idprospect);
92
93 if ($result >= 0) {
94 // Apply new status
95 $prospect->stcomm_id = $idstatus;
96
97 // Update using business logic (fires COMPANY_MODIFY)
98 $updateResult = $prospect->update($prospect->id, $user);
99
100 if ($updateResult >= 0) {
101 $response = img_action('', $prospectstatic->cacheprospectstatus[$idstatus]['code'], $prospectstatic->cacheprospectstatus[$idstatus]['picto'], 'class="inline-block valignmiddle paddingright pictoprospectstatus"');
102 } else {
103 dol_syslog('Failed to update prospect via update() method', LOG_ERR);
105 }
106 } else {
108 }
109 echo json_encode(array('img' => $response));
110}
Class to manage customers or prospects.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_action($titlealt, $numaction, $picto='', $moreatt='')
Show logo action.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.