45 public $results = array();
70 require_once DOL_DOCUMENT_ROOT.
'/ai/class/emailcleaner.class.php';
75 $arrayoftypes = (!empty($parameters[
'arrayoftypes']) && is_array($parameters[
'arrayoftypes'])) ? $parameters[
'arrayoftypes'] : array();
77 $arrayoftypes[
'hook_ai_emailcleaner'] = $langs->trans(
'AIEmailCleanerOperation');
78 $this->results = $arrayoftypes;
94 require_once DOL_DOCUMENT_ROOT.
'/ai/class/emailcleaner.class.php';
101 $result = $emailCleaner->processEmailCollectorMessage($parameters,
$object);
102 if (!empty($result[
'file'])) {
103 $this->results[
'ai_emailcleaner_file'] = (string) $result[
'file'];
112 public $errors = array();
117 public $resprints =
'';
122 private $listRowIds = array();
128 private $listPageSeen =
false;
145 $this->listPageSeen =
true;
146 if (count($this->listRowIds) < 100 && isset($parameters[
'obj']) && is_object($parameters[
'obj'])) {
149 $rowid = (int) ($parameters[
'obj']->rowid ?? $parameters[
'obj']->
id ?? 0);
151 $this->listRowIds[] = $rowid;
191 if (empty($user->id) || !$user->hasRight(
'ai',
'assistant',
'use')) {
197 if (!is_object($pageObject) || empty($pageObject->id)) {
198 $pageObject = isset($GLOBALS[
'object']) ? $GLOBALS[
'object'] :
null;
205 $urlIds = array((
int) ($_GET[
'id'] ?? $_POST[
'id'] ?? 0), (
int) ($_GET[
'facid'] ?? $_POST[
'facid'] ?? 0), (
int) ($_GET[
'socid'] ?? $_POST[
'socid'] ?? 0));
207 $looksLikeCard = is_object($pageObject) && !empty($pageObject->id)
208 && (in_array((
int) $pageObject->id, $urlIds,
true) || ($urlRef !==
'' && $urlRef == ($pageObject->ref ??
'')));
209 if ($this->listPageSeen || !empty($this->listRowIds) || !$looksLikeCard || empty($pageObject->element)) {
217 foreach (array_merge($_POST, $_GET) as $k => $v) {
218 if (!is_string($v) || $v ===
'' || strlen($v) > 200) {
221 if (preg_match(
'/^(search_[a-z0-9_]+|sall|search_all|sortfield|sortorder|contextpage)$/', $k)) {
225 $listElement = (is_object($pageObject) && !empty($pageObject->element)) ? (
string) $pageObject->element :
'';
231 if (!$this->listPageSeen && empty($filters)) {
233 '/index.php' =>
'main home',
234 '/societe/index.php' =>
'thirdparties',
235 '/compta/facture/index.php' =>
'customer invoices',
236 '/fourn/facture/index.php' =>
'supplier invoices',
237 '/commande/index.php' =>
'sales orders',
238 '/fourn/commande/index.php' =>
'supplier orders',
239 '/comm/propal/index.php' =>
'commercial proposals',
240 '/supplier_proposal/index.php' =>
'supplier proposals',
241 '/product/index.php' =>
'products and services',
242 '/product/stock/index.php' =>
'stock and warehouses',
243 '/projet/index.php' =>
'projects',
244 '/contrat/index.php' =>
'contracts',
245 '/fichinter/index.php' =>
'interventions',
246 '/ticket/index.php' =>
'tickets',
247 '/expedition/index.php' =>
'shipments',
248 '/reception/index.php' =>
'receptions',
249 '/adherents/index.php' =>
'members',
250 '/don/index.php' =>
'donations',
251 '/expensereport/index.php' =>
'expense reports',
252 '/comm/action/index.php' =>
'agenda',
253 '/mrp/index.php' =>
'manufacturing',
254 '/recruitment/index.php' =>
'recruitment'
259 $self = (string) ($_SERVER[
'PHP_SELF'] ??
'');
260 $urlRoot = (string) constant(
'DOL_URL_ROOT');
261 $rel = ($urlRoot !==
'' && strpos($self, $urlRoot) === 0) ? substr($self, strlen($urlRoot)) : $self;
262 if (isset($dashboards[$rel])) {
263 print
"\n".
'<script nonce="'.
getNonce().
'">window.aiPageContext = '.json_encode(array(
'dashboard' => $dashboards[$rel])).
';</script>'.
"\n";
268 if (($this->listPageSeen || !empty($filters) || !empty($this->listRowIds)) && !empty($listElement)) {
269 $ctx = array(
'element' => $listElement,
'list' => 1,
'filters' => $filters);
270 if (!empty($this->listRowIds)) {
271 $ctx[
'ids'] = $this->listRowIds;
273 print
"\n".
'<script nonce="'.
getNonce().
'">window.aiPageContext = '.json_encode($ctx).
';</script>'.
"\n";
280 'element' => (
string) $pageObject->element,
281 'id' => (
int) $pageObject->id,
282 'ref' => (
string) ($pageObject->ref ??
''),
283 'socid' => (
int) (get_object_vars($pageObject)[
'socid'] ?? 0)
288 print
"\n".
'<script nonce="'.
getNonce().
'">window.aiPageContext = '.json_encode(
$context).
';</script>'.
"\n";
if(! $sortfield) if(! $sortorder) $object
addMoreActionsEmailCollector($parameters, &$object, &$action, $hookmanager)
Add AI Email Cleaner action in EmailCollector operations.
__construct($db=null)
Constructor.
doCollectImapOneCollector($parameters, &$object, &$action, $hookmanager)
Execute AI cleaner when EmailCollector operation type is "hook_ai_emailcleaner".
printFieldListValue($parameters, &$object, &$action)
Collect the id of each rendered list row.
printCommonFooter($parameters, &$object, &$action)
Emit the current page context for the assistant popover.
static isRuntimeAvailable()
Check if the runtime dependencies for EmailCleaner are available.
static isEmailCollectorHookAction($action)
Check if the EmailCollector hook action targets EmailCleaner.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getNonce()
Return a random string to be used as a nonce value for js.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
$context
@method int call_trigger(string $triggerName, ?User $user)