| Server IP : 162.214.74.102 / Your IP : 216.73.217.103 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_apps/leve/application/plugins/module_helpdesk/ |
Upload File : |
<?php
//if(!defined('APP_RUN')) exit('No direct access allowed');
/*
* FUNÇÃO PARA ACESSO AOS DADOS DO PLUGIN VIA CONSOLE
* Utilizar o caminho: /?ng=index.php a=CLI ng=console/{CHAVE-DE-ACESSO}/module_helpdesk/method
* Enviar os dados via POST
* @key: chave de acesso à API
* @plugin: nome do plugin ou módulo
* @params
*/
$pl_data = false;
//// PATCH para rodar o Crawler via Console
header('Content-type: application/json');
$routes = $GLOBALS['routes_console'];
if (isset($routes[3])) {
$method = $routes[3];
// switch method
switch ($method) {
case 'saveSerialClient' :
//BUSCA todos os clientes camops adicionais, fieldId serial_numbers
//que não tenha registro no histórico em aberto para o registro
$return = ORM::for_table('crm_customfields')
->table_alias('c')
->select('r.fvalue')
->select('r.relid')
->select('r.fieldid')
->join('crm_customfieldsvalues', 'r.fieldid = c.id', 'r')
->where('c.fieldname', 'serial_numbers')
->where_raw('NOT EXISTS(select id from crm_customfieldsvalues_history sub'
. ' WHERE sub.relid=r.relid'
. ' AND r.fieldid=sub.fieldid'
. ' AND r.fvalue=sub.fvalue'
. ' AND sub.date_end IS NULL)')
->find_many();
if (count($return) > 0) {
foreach ($return as $r) {
$histo = ORM::for_table('crm_customfieldsvalues_history')
->table_alias('h')
->where('h.fieldid', $r->fieldid)
->where('h.relid', $r->relid)
->where_raw('h.date_end IS NULL')
->find_many();
if (count($histo) == 0) {
//INSERE NORMAL USANDO A DATA DE CADATRO DO CLIENTE
$d = ORM::for_table('crm_customfieldsvalues_history')->create();
$d->relid = $r->relid;
$d->fieldid = $r->fieldid;
$d->fvalue = $r->fvalue;
$d->date_start = '2020-01-01'; //data inicial para o históric quando cadastrado
$d->count_fvalue = count(explode(",", $r->fvalue));
$d->save();
} else {
if (strtotime($histo[0]->date_start) == strtotime(date("Y-m-d"))) {
$histo->fvalue = $r->fvalue;
$histo->date_start = date("Y-m-d");
$histo->count_fvalue = count(explode(",", $r->fvalue));
$histo->save();
} else {
$dold = ORM::for_table('crm_customfieldsvalues_history')->find_one($histo[0]->id);
$dold->date_end = date("Y-m-d", strtotime("- 1 day", strtotime(date("Y-m-d"))));
$dold->save(); // FIM do HISTÓRICO
$d = ORM::for_table('crm_customfieldsvalues_history')->create();
$d->relid = $r->relid;
$d->fieldid = $r->fieldid;
$d->fvalue = $r->fvalue;
$d->date_start = date("Y-m-d");
$d->count_fvalue = count(explode(",", $r->fvalue));
$d->save();
}
}
}
}
$info = array(
'success' => true,
'plugin_msg' => 'Sucesso');
break;
}
} else {
$info = array(
'success' => false,
'plugin_msg' => 'Invalid plugin method');
}
echo json_encode($info);
// Return
$data['return'] = array('info' => $info,
'data' => $pl_data);