societeaccount.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file societe/class/societeaccount.class.php
  22. * \ingroup societe
  23. * \brief This file is a CRUD class file for SocieteAccount (Create/Read/Update/Delete)
  24. */
  25. // Put here all includes required by your class file
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  27. //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
  28. //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
  29. /**
  30. * Class for SocieteAccount
  31. */
  32. class SocieteAccount extends CommonObject
  33. {
  34. /**
  35. * @var string ID to identify managed object
  36. */
  37. public $element = 'societeaccount';
  38. /**
  39. * @var string Name of table without prefix where object is stored
  40. */
  41. public $table_element = 'societe_account';
  42. /**
  43. * @var array Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  44. */
  45. public $ismultientitymanaged = 0;
  46. /**
  47. * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png
  48. */
  49. public $picto = 'lock';
  50. /**
  51. * 'type' if the field format.
  52. * 'label' the translation key.
  53. * 'enabled' is a condition when the field must be managed.
  54. * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
  55. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  56. * 'index' if we want an index in database.
  57. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  58. * 'position' is the sort order of field.
  59. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  60. * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
  61. * 'help' is a string visible as a tooltip on field
  62. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  63. * 'default' is a default value for creation (can still be replaced by the global setup of default values)
  64. * 'showoncombobox' if field must be shown into the label of combobox
  65. */
  66. // BEGIN MODULEBUILDER PROPERTIES
  67. /**
  68. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  69. */
  70. public $fields = array(
  71. 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',),
  72. 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1),
  73. 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'notnull'=>1, 'position'=>10, 'showoncombobox'=>1),
  74. 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30),
  75. 'pass_crypted' => array('type'=>'password', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1),
  76. 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,),
  77. 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1, 'picto'=>'company', 'css'=>'maxwidth300 widthcentpercentminusxx'),
  78. 'site' => array('type'=>'varchar(128)', 'label'=>'WebsiteTypeLabel', 'visible'=>0, 'enabled'=>0, 'position'=>41, 'notnull'=>1, 'default' => '', 'help'=>'Name of the website or service if this is account on an external website or service'),
  79. 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>0, 'enabled'=>0, 'position'=>42, 'notnull'=>-1, 'index'=>1, 'picto'=>'website', 'css'=>'maxwidth300 widthcentpercentminusxx'),
  80. 'site_account' => array('type'=>'varchar(128)', 'label'=>'ExternalSiteAccount', 'visible'=>0, 'enabled'=>1, 'position'=>44, 'help'=>'A key to identify the account on external web site if this is an account on an external website'),
  81. 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>0, 'enabled'=>1, 'position'=>48, 'notnull'=>0, 'index'=>1, 'searchall'=>1, 'comment'=>'The id of third party in the external web site (for site_account if site_account defined)',),
  82. 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,),
  83. 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,),
  84. //'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,),
  85. 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,),
  86. 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  87. 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  88. 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,),
  89. 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,),
  90. 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,),
  91. 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active', '0'=>'Disabled')),
  92. );
  93. /**
  94. * @var int ID
  95. */
  96. public $rowid;
  97. /**
  98. * @var int Entity
  99. */
  100. public $entity;
  101. public $key_account;
  102. public $login;
  103. public $pass_encoding;
  104. public $pass_crypted;
  105. public $pass_temp;
  106. /**
  107. * @var int Thirdparty ID
  108. */
  109. public $fk_soc;
  110. public $site;
  111. public $site_account;
  112. /**
  113. * @var integer|string date_last_login
  114. */
  115. public $date_last_login;
  116. public $date_previous_login;
  117. public $note_private;
  118. /**
  119. * @var integer|string date_creation
  120. */
  121. public $date_creation;
  122. public $tms;
  123. /**
  124. * @var int ID
  125. */
  126. public $fk_user_creat;
  127. /**
  128. * @var int ID
  129. */
  130. public $fk_user_modif;
  131. public $import_key;
  132. /**
  133. * @var int Status
  134. */
  135. public $status;
  136. // END MODULEBUILDER PROPERTIES
  137. const STATUS_ENABLED = 1;
  138. const STATUS_DISABLED = 0;
  139. /**
  140. * Constructor
  141. *
  142. * @param DoliDb $db Database handler
  143. */
  144. public function __construct(DoliDB $db)
  145. {
  146. global $conf, $langs;
  147. $this->db = $db;
  148. if (!getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
  149. $this->fields['rowid']['visible'] = 0;
  150. }
  151. // add site type list and set visible
  152. $site_type_list = array();
  153. if (isModEnabled('website')) {
  154. $this->fields['fk_website']['visible'] = 1;
  155. $this->fields['fk_website']['enabled'] = 1;
  156. $this->fields['site']['visible'] = 1;
  157. $this->fields['site']['enabled'] = 1;
  158. $site_type_list['dolibarr_website'] = $langs->trans('WebsiteTypeDolibarrWebsite');
  159. }
  160. if (isModEnabled('webportal')) {
  161. $this->fields['site']['visible'] = 1;
  162. $this->fields['site']['enabled'] = 1;
  163. $site_type_list['dolibarr_portal'] = $langs->trans('WebsiteTypeDolibarrPortal');
  164. }
  165. $this->fields['site']['arrayofkeyval'] = $site_type_list;
  166. }
  167. /**
  168. * Create object into database
  169. *
  170. * @param User $user User that creates
  171. * @param bool $notrigger false=launch triggers after, true=disable triggers
  172. * @return int Return integer <0 if KO, Id of created object if OK
  173. */
  174. public function create(User $user, $notrigger = false)
  175. {
  176. return $this->createCommon($user, $notrigger);
  177. }
  178. /**
  179. * Clone and object into another one
  180. *
  181. * @param User $user User that creates
  182. * @param int $fromid Id of object to clone
  183. * @return mixed New object created, <0 if KO
  184. */
  185. public function createFromClone(User $user, $fromid)
  186. {
  187. global $hookmanager, $langs;
  188. $error = 0;
  189. dol_syslog(__METHOD__, LOG_DEBUG);
  190. $object = new self($this->db);
  191. $this->db->begin();
  192. // Load source object
  193. $object->fetchCommon($fromid);
  194. // Reset some properties
  195. unset($object->id);
  196. unset($object->fk_user_creat);
  197. unset($object->import_key);
  198. // Clear fields
  199. $object->ref = "copy_of_".$object->ref;
  200. // $object->title = $langs->trans("CopyOf")." ".$object->title;
  201. // Create clone
  202. $object->context['createfromclone'] = 'createfromclone';
  203. $result = $object->createCommon($user);
  204. if ($result < 0) {
  205. $error++;
  206. $this->error = $object->error;
  207. $this->errors = $object->errors;
  208. }
  209. unset($object->context['createfromclone']);
  210. // End
  211. if (!$error) {
  212. $this->db->commit();
  213. return $object;
  214. } else {
  215. $this->db->rollback();
  216. return -1;
  217. }
  218. }
  219. /**
  220. * Load object in memory from the database
  221. *
  222. * @param int $id Id object
  223. * @param string $ref Ref
  224. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  225. */
  226. public function fetch($id, $ref = null)
  227. {
  228. $result = $this->fetchCommon($id, $ref);
  229. if ($result > 0 && !empty($this->table_element_line)) {
  230. $this->fetchLines();
  231. }
  232. return $result;
  233. }
  234. /**
  235. * Load object lines in memory from the database
  236. *
  237. * @return int Return integer <0 if KO, 0 if not found, >0 if OK
  238. */
  239. public function fetchLines()
  240. {
  241. $this->lines = array();
  242. // Load lines with object societeAccountLine
  243. return count($this->lines) ? 1 : 0;
  244. }
  245. /**
  246. * Try to find the external customer id of a thirdparty for another site/system.
  247. *
  248. * @param int $id Id of third party
  249. * @param string $site Site (example: 'stripe', '...')
  250. * @param int $status Status (0=test, 1=live)
  251. * @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service.
  252. * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or ''
  253. * @see getThirdPartyID()
  254. */
  255. public function getCustomerAccount($id, $site, $status = 0, $site_account = '')
  256. {
  257. $sql = "SELECT sa.key_account as key_account, sa.entity";
  258. $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
  259. $sql .= " WHERE sa.fk_soc = ".((int) $id);
  260. $sql .= " AND sa.entity IN (".getEntity('societe').")";
  261. $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
  262. $sql .= " AND sa.key_account IS NOT NULL AND sa.key_account <> ''";
  263. $sql .= " AND (sa.site_account = '' OR sa.site_account IS NULL OR sa.site_account = '".$this->db->escape($site_account)."')";
  264. $sql .= " ORDER BY sa.site_account DESC"; // To get the entry with a site_account defined in priority
  265. dol_syslog(get_class($this)."::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG);
  266. $result = $this->db->query($sql);
  267. if ($result) {
  268. if ($this->db->num_rows($result)) {
  269. $obj = $this->db->fetch_object($result);
  270. $key = $obj->key_account;
  271. } else {
  272. $key = '';
  273. }
  274. } else {
  275. $key = '';
  276. }
  277. return $key;
  278. }
  279. /**
  280. * Try to find the thirdparty id from an another site/system external id.
  281. *
  282. * @param string $id Id of customer in external system (example: 'cu_xxxxxxxxxxxxx', ...)
  283. * @param string $site Site (example: 'stripe', '...')
  284. * @param int $status Status (0=test, 1=live)
  285. * @return int Id of third party
  286. * @see getCustomerAccount()
  287. */
  288. public function getThirdPartyID($id, $site, $status = 0)
  289. {
  290. $socid = 0;
  291. $sql = "SELECT sa.fk_soc as fk_soc, sa.key_account, sa.entity";
  292. $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as sa";
  293. $sql .= " WHERE sa.key_account = '".$this->db->escape($id)."'";
  294. $sql .= " AND sa.entity IN (".getEntity('societe').")";
  295. $sql .= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status);
  296. $sql .= " AND sa.fk_soc > 0";
  297. dol_syslog(get_class($this)."::getCustomerAccount Try to find the first thirdparty id for ".$site." for external id=".$id, LOG_DEBUG);
  298. $result = $this->db->query($sql);
  299. if ($result) {
  300. if ($this->db->num_rows($result)) {
  301. $obj = $this->db->fetch_object($result);
  302. $socid = $obj->fk_soc;
  303. }
  304. }
  305. return $socid;
  306. }
  307. /**
  308. * Update object into database
  309. *
  310. * @param User $user User that modifies
  311. * @param bool $notrigger false=launch triggers after, true=disable triggers
  312. * @return int Return integer <0 if KO, >0 if OK
  313. */
  314. public function update(User $user, $notrigger = false)
  315. {
  316. return $this->updateCommon($user, $notrigger);
  317. }
  318. /**
  319. * Delete object in database
  320. *
  321. * @param User $user User that deletes
  322. * @param bool $notrigger false=launch triggers after, true=disable triggers
  323. * @return int Return integer <0 if KO, >0 if OK
  324. */
  325. public function delete(User $user, $notrigger = false)
  326. {
  327. return $this->deleteCommon($user, $notrigger);
  328. }
  329. /**
  330. * getTooltipContentArray
  331. * @param array $params params to construct tooltip data
  332. * @since v18
  333. * @return array
  334. */
  335. public function getTooltipContentArray($params)
  336. {
  337. global $conf, $langs, $user;
  338. $langs->loadLangs(['companies, commercial']);
  339. $datas = [];
  340. $option = $params['option'] ?? '';
  341. $datas['picto'] = '<u>'.$langs->trans("WebsiteAccount").'</u>';
  342. $datas['login'] = '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
  343. return $datas;
  344. }
  345. /**
  346. * Return a link to the object card (with optionaly the picto)
  347. *
  348. * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
  349. * @param string $option On what the link point to ('nolink', ...)
  350. * @param int $notooltip 1=Disable tooltip
  351. * @param string $morecss Add more css on link
  352. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  353. * @return string String with URL
  354. */
  355. public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
  356. {
  357. global $db, $conf, $langs;
  358. global $dolibarr_main_authentication, $dolibarr_main_demo;
  359. global $menumanager;
  360. if (!empty($conf->dol_no_mouse_hover)) {
  361. $notooltip = 1; // Force disable tooltips
  362. }
  363. $result = '';
  364. $this->ref = $this->login;
  365. $label = '<u>'.$langs->trans("WebsiteAccount").'</u>';
  366. $label .= '<br>';
  367. $label .= '<b>'.$langs->trans('Login').':</b> '.$this->ref;
  368. //$label.= '<b>' . $langs->trans('WebSite') . ':</b> ' . $this->ref;
  369. $url = DOL_URL_ROOT.'/website/websiteaccount_card.php?id='.$this->id;
  370. if ($option != 'nolink') {
  371. // Add param to save lastsearch_values or not
  372. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  373. if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  374. $add_save_lastsearch_values = 1;
  375. }
  376. if ($add_save_lastsearch_values) {
  377. $url .= '&save_lastsearch_values=1';
  378. }
  379. }
  380. $linkclose = '';
  381. $classfortooltip = 'classfortooltip';
  382. $dataparams = '';
  383. if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
  384. $params = [
  385. 'id' => $this->id,
  386. 'objecttype' => $this->element,
  387. 'option' => $option,
  388. ];
  389. $classfortooltip = 'classforajaxtooltip';
  390. $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
  391. $label = '';
  392. }
  393. if (empty($notooltip)) {
  394. if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
  395. $label = $langs->trans("WebsiteAccount");
  396. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  397. }
  398. $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
  399. $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
  400. } else {
  401. $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
  402. }
  403. $linkstart = '<a href="'.$url.'"';
  404. $linkstart .= $linkclose.'>';
  405. $linkend = '</a>';
  406. $result .= $linkstart;
  407. if ($withpicto) {
  408. $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
  409. }
  410. if ($withpicto != 2) {
  411. $result .= $this->ref;
  412. }
  413. $result .= $linkend;
  414. return $result;
  415. }
  416. /**
  417. * Return the label of a given status
  418. *
  419. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  420. * @return string Label of status
  421. */
  422. public function getLibStatut($mode = 0)
  423. {
  424. return $this->LibStatut($this->status, $mode);
  425. }
  426. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  427. /**
  428. * Return the status
  429. *
  430. * @param int $status Id status
  431. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
  432. * @return string Label of status
  433. */
  434. public function LibStatut($status, $mode = 0)
  435. {
  436. // phpcs:enable
  437. if (is_null($status)) {
  438. return '';
  439. }
  440. if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
  441. global $langs;
  442. //$langs->load("mymodule@mymodule");
  443. $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  444. $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
  445. $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled');
  446. $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled');
  447. }
  448. $statusType = 'status4';
  449. //if ($status == self::STATUS_VALIDATED) $statusType = 'status1';
  450. if ($status == self::STATUS_DISABLED) {
  451. $statusType = 'status6';
  452. }
  453. return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
  454. }
  455. /**
  456. * Charge les informations d'ordre info dans l'objet commande
  457. *
  458. * @param int $id Id of order
  459. * @return void
  460. */
  461. public function info($id)
  462. {
  463. $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
  464. $sql .= ' fk_user_creat, fk_user_modif';
  465. $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
  466. $sql .= ' WHERE t.rowid = '.((int) $id);
  467. $result = $this->db->query($sql);
  468. if ($result) {
  469. if ($this->db->num_rows($result)) {
  470. $obj = $this->db->fetch_object($result);
  471. $this->id = $obj->rowid;
  472. $this->user_creation_id = $obj->fk_user_creat;
  473. $this->user_modification_id = $obj->fk_user_modif;
  474. $this->date_creation = $this->db->jdate($obj->datec);
  475. $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
  476. }
  477. $this->db->free($result);
  478. } else {
  479. dol_print_error($this->db);
  480. }
  481. }
  482. /**
  483. * Initialise object with example values
  484. * Id must be 0 if object instance is a specimen
  485. *
  486. * @return void
  487. */
  488. public function initAsSpecimen()
  489. {
  490. $this->initAsSpecimenCommon();
  491. }
  492. }