45 public $errors = array();
76 public $table_element =
"c_price_global_variable_updater";
96 public function create($user, $notrigger = 0)
103 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
104 $sql .=
"type, description, parameters, fk_variable, update_interval, next_update, last_status";
105 $sql .=
") VALUES (";
106 $sql .=
" ".$this->type.
",";
108 $sql .=
" ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
109 $sql .=
" ".$this->fk_variable.
",";
110 $sql .=
" ".$this->update_interval.
",";
111 $sql .=
" ".$this->next_update.
",";
112 $sql .=
" ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
119 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
123 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
140 foreach ($this->errors as $errmsg)
143 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
145 $this->
db->rollback();
162 $sql =
"SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status";
163 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
164 $sql .=
" WHERE rowid = ".$id;
170 $obj = $this->
db->fetch_object(
$resql);
174 $this->
type = $obj->type;
176 $this->parameters = $obj->parameters;
177 $this->fk_variable = $obj->fk_variable;
178 $this->update_interval = $obj->update_interval;
179 $this->next_update = $obj->next_update;
180 $this->last_status = $obj->last_status;
187 $this->error =
"Error ".$this->db->lasterror();
199 public function update($user = 0, $notrigger = 0)
206 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
207 $sql .=
" type = ".$this->type.
",";
208 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"''").
",";
209 $sql .=
" parameters = ".(isset($this->parameters) ?
"'".$this->db->escape($this->parameters).
"'" :
"''").
",";
210 $sql .=
" fk_variable = ".$this->fk_variable.
",";
211 $sql .=
" update_interval = ".$this->update_interval.
",";
212 $sql .=
" next_update = ".$this->next_update.
",";
213 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
214 $sql .=
" WHERE rowid = ".$this->id;
220 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
239 foreach ($this->errors as $errmsg)
241 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
242 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
244 $this->
db->rollback();
260 public function delete($rowid, $user, $notrigger = 0)
282 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
283 $sql .=
" WHERE rowid = ".$rowid;
287 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
293 foreach ($this->errors as $errmsg)
296 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
298 $this->
db->rollback();
317 $this->parameters =
'';
318 $this->fk_variable = 0;
319 $this->update_interval = 0;
320 $this->next_update = 0;
321 $this->last_status =
'';
332 $last = $this->next_update - ($this->update_interval * 60);
334 return $langs->trans(
"Never");
336 $status = empty($this->last_status) ? $langs->trans(
"CorrectlyUpdated") : $this->last_status;
349 if (isset($this->parameters)) $this->parameters = trim($this->parameters);
350 else $this->parameters =
"";
351 if (isset($this->last_status)) $this->last_status = trim($this->last_status);
354 if (empty($this->
type) || !is_numeric($this->
type) || !in_array($this->
type, $this->types)) $this->
type = 0;
355 if (empty($this->update_interval) || !is_numeric($this->update_interval) || $this->update_interval < 1) $this->update_interval =
$this->update_min;
356 if (empty($this->next_update) || !is_numeric($this->next_update) || $this->next_update < 0) $this->next_update = 0;
366 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
367 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
375 while ($record = $this->
db->fetch_array(
$resql))
378 $updater_obj->id = $record[
"rowid"];
379 $updater_obj->type = $record[
"type"];
380 $updater_obj->description = $record[
"description"];
381 $updater_obj->parameters = $record[
"parameters"];
382 $updater_obj->fk_variable = $record[
"fk_variable"];
383 $updater_obj->update_interval = $record[
"update_interval"];
384 $updater_obj->next_update = $record[
"next_update"];
385 $updater_obj->last_status = $record[
"last_status"];
386 $updater_obj->checkParameters();
387 $retarray[] = $updater_obj;
393 $this->error = $this->
db->error();
405 $sql =
"SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status";
406 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
407 $sql .=
" WHERE next_update < ".dol_now();
415 while ($record = $this->
db->fetch_array(
$resql))
418 $updater_obj->id = $record[
"rowid"];
419 $updater_obj->type = $record[
"type"];
420 $updater_obj->description = $record[
"description"];
421 $updater_obj->parameters = $record[
"parameters"];
422 $updater_obj->fk_variable = $record[
"fk_variable"];
423 $updater_obj->update_interval = $record[
"update_interval"];
424 $updater_obj->next_update = $record[
"next_update"];
425 $updater_obj->last_status = $record[
"last_status"];
426 $updater_obj->checkParameters();
427 $retarray[] = $updater_obj;
433 $this->error = $this->
db->error();
445 global $langs, $user;
446 $langs->load(
"errors");
453 if ($this->fk_variable < 1) {
454 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
458 $res = $price_globals->fetch($this->fk_variable);
460 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater5");
465 if ($this->
type == 0 || $this->
type == 1) {
467 $parameters = json_decode($this->parameters,
true);
468 if (!isset($parameters)) {
469 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater1", $this->parameters);
472 $url = $parameters[
'URL'];
474 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'URL');
477 $value = $parameters[
'VALUE'];
478 if (!isset($value)) {
479 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'VALUE');
483 if ($this->
type == 0) {
485 include_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
487 $code = $tmpresult[
'http_code'];
488 $result = $tmpresult[
'content'];
490 if (!isset($result)) {
491 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0",
"empty response");
495 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater0", $code.
' '.$tmpresult[
'curl_error_msg']);
500 $result = json_decode($result,
true);
501 } elseif ($this->
type == 1) {
502 $ns = $parameters[
'NS'];
504 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'NS');
507 $method = $parameters[
'METHOD'];
508 if (!isset($method)) {
509 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'METHOD');
512 $data = $parameters[
'DATA'];
514 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater2",
'DATA');
519 require_once NUSOAP_PATH.
'/nusoap.php';
520 $soap_client =
new nusoap_client($url);
521 $soap_client->soap_defencoding =
'UTF-8';
522 $soap_client->decodeUTF8(
false);
523 $result = $soap_client->call($method, $data, $ns,
'');
526 if ($result ===
false) {
527 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater4", $soap_client->error_str);
533 $value = explode(
',', $value);
534 foreach ($value as $key) {
535 $result = $result[$key];
537 if (!isset($result)) {
538 $this->error = $langs->trans(
"ErrorGlobalVariableUpdater3");
543 $price_globals->value = $result;
544 $price_globals->update($user);
567 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
568 $sql .=
" next_update = ".$this->next_update;
569 $sql .=
" WHERE rowid = ".$this->id;
575 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
580 foreach ($this->errors as $errmsg)
583 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
585 $this->
db->rollback();
607 $this->last_status = $last_status;
611 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
612 $sql .=
" last_status = ".(isset($this->last_status) ?
"'".$this->db->escape($this->last_status).
"'" :
"''");
613 $sql .=
" WHERE rowid = ".$this->id;
619 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
624 foreach ($this->errors as $errmsg)
627 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
629 $this->
db->rollback();
update($user=0, $notrigger=0)
Update object into database.
update_status($last_status, $user=0, $notrigger=0)
Update last_status into database.
fetch($id)
Load object in memory from the database.
checkParameters()
Checks if all parameters are in order.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
process()
Handles the processing of this updater.
create($user, $notrigger=0)
Create object into database.
getURLContent($url, $postorget= 'GET', $param= '', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0)
Function to get a content from an URL (use proxy if proxy defined).
$conf db
API class for accounts.
$update_min
Minimal update rate.
$next_update
Next update timestamp.
getLastUpdated()
Returns the last updated time in string html format, returns "never" if its less than 1...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
update_next_update($next_update, $user=0, $notrigger=0)
Update next_update into database.
__construct($db)
Constructor.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Class for accesing price global variables table.
$update_interval
Interval in mins.
listUpdaters()
List all price global variables.
listPendingUpdaters()
List all updaters which need to be processed.
Class for price global variable updaters table.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type