contact.class.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219
  1. <?php
  2. /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  4. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
  7. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  8. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  9. * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
  10. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  11. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  12. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  13. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/contact/class/contact.class.php
  30. * \ingroup societe
  31. * \brief File of contacts class
  32. */
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/commonsocialnetworks.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php';
  36. /**
  37. * Class to manage contact/addresses
  38. */
  39. class Contact extends CommonObject
  40. {
  41. use CommonSocialNetworks;
  42. use CommonPeople;
  43. /**
  44. * @var string ID to identify managed object
  45. */
  46. public $element = 'contact';
  47. /**
  48. * @var string Name of table without prefix where object is stored
  49. */
  50. public $table_element = 'socpeople';
  51. /**
  52. * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
  53. * @var int
  54. */
  55. public $ismultientitymanaged = 1;
  56. /**
  57. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  58. */
  59. public $picto = 'contact';
  60. /**
  61. * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
  62. * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
  63. * 'label' the translation key.
  64. * 'enabled' is a condition when the field must be managed.
  65. * 'position' is the sort order of field.
  66. * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
  67. * '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, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing)
  68. * 'noteditable' says if field is not editable (1 or 0)
  69. * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created.
  70. * 'index' if we want an index in database.
  71. * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
  72. * 'searchall' is 1 if we want to search in this field when making a search from the quick search button.
  73. * '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).
  74. * 'css' is the CSS style to use on field. For example: 'maxwidth200'
  75. * 'help' is a string visible as a tooltip on field
  76. * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
  77. * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code.
  78. * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel")
  79. * 'comment' is not used. You can store here any text of your choice. It is not used by application.
  80. *
  81. * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor.
  82. */
  83. // BEGIN MODULEBUILDER PROPERTIES
  84. /**
  85. * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
  86. */
  87. public $fields = array(
  88. 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
  89. 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>3, 'notnull'=>1, 'position'=>30, 'index'=>1),
  90. 'ref_ext' =>array('type'=>'varchar(255)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>3, 'position'=>35),
  91. 'civility' =>array('type'=>'varchar(6)', 'label'=>'Civility', 'enabled'=>1, 'visible'=>3, 'position'=>40),
  92. 'lastname' =>array('type'=>'varchar(50)', 'label'=>'Lastname', 'enabled'=>1, 'visible'=>1, 'position'=>45, 'showoncombobox'=>1, 'searchall'=>1),
  93. 'firstname' =>array('type'=>'varchar(50)', 'label'=>'Firstname', 'enabled'=>1, 'visible'=>1, 'position'=>50, 'showoncombobox'=>1, 'searchall'=>1),
  94. 'poste' =>array('type'=>'varchar(80)', 'label'=>'PostOrFunction', 'enabled'=>1, 'visible'=>-1, 'position'=>52),
  95. 'address' =>array('type'=>'varchar(255)', 'label'=>'Address', 'enabled'=>1, 'visible'=>-1, 'position'=>55),
  96. 'zip' =>array('type'=>'varchar(25)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>1, 'position'=>60),
  97. 'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-1, 'position'=>65),
  98. 'fk_departement' =>array('type'=>'integer', 'label'=>'Fk departement', 'enabled'=>1, 'visible'=>3, 'position'=>70),
  99. 'fk_pays' =>array('type'=>'integer', 'label'=>'Fk pays', 'enabled'=>1, 'visible'=>3, 'position'=>75),
  100. 'fk_soc' =>array('type'=>'integer', 'label'=>'ThirdParty', 'enabled'=>1, 'visible'=>1, 'position'=>77, 'searchall'=>1),
  101. 'birthday' =>array('type'=>'date', 'label'=>'Birthday', 'enabled'=>1, 'visible'=>3, 'position'=>80),
  102. 'phone' =>array('type'=>'varchar(30)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>1, 'position'=>90, 'searchall'=>1),
  103. 'phone_perso' =>array('type'=>'varchar(30)', 'label'=>'PhonePerso', 'enabled'=>1, 'visible'=>-1, 'position'=>95, 'searchall'=>1),
  104. 'phone_mobile' =>array('type'=>'varchar(30)', 'label'=>'PhoneMobile', 'enabled'=>1, 'visible'=>1, 'position'=>100, 'searchall'=>1),
  105. 'fax' =>array('type'=>'varchar(30)', 'label'=>'Fax', 'enabled'=>1, 'visible'=>-1, 'position'=>105, 'searchall'=>1),
  106. 'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>1, 'position'=>110, 'searchall'=>1),
  107. 'socialnetworks' =>array('type'=>'text', 'label'=>'SocialNetworks', 'enabled'=>1, 'visible'=>3, 'position'=>115),
  108. 'photo' =>array('type'=>'varchar(255)', 'label'=>'Photo', 'enabled'=>1, 'visible'=>3, 'position'=>170),
  109. 'priv' =>array('type'=>'smallint(6)', 'label'=>'ContactVisibility', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>175),
  110. 'fk_stcommcontact' =>array('type'=>'integer', 'label'=>'ProspectStatus', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>220),
  111. 'fk_prospectlevel' =>array('type'=>'varchar(12)', 'label'=>'ProspectLevel', 'enabled'=>1, 'visible'=>-1, 'position'=>255),
  112. 'no_email' =>array('type'=>'smallint(6)', 'label'=>'No_Email', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>180),
  113. 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>3, 'position'=>195, 'searchall'=>1),
  114. 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>3, 'position'=>200, 'searchall'=>1),
  115. 'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>3, 'position'=>205),
  116. 'canvas' =>array('type'=>'varchar(32)', 'label'=>'Canvas', 'enabled'=>1, 'visible'=>3, 'position'=>210),
  117. 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>300),
  118. 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>305),
  119. 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>3, 'position'=>310),
  120. 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>3, 'position'=>315),
  121. 'statut' =>array('type'=>'tinyint(4)', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>500),
  122. 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>1000),
  123. );
  124. public $civility_id; // In fact we store civility_code
  125. public $civility_code;
  126. public $civility;
  127. /**
  128. * @var string gender
  129. */
  130. public $gender;
  131. /**
  132. * @var int egroupware_id
  133. */
  134. public $egroupware_id;
  135. /**
  136. * @var int birthday_alert
  137. */
  138. public $birthday_alert;
  139. /**
  140. * @var string The civilite code, not an integer
  141. * @deprecated
  142. * @see $civility_code
  143. */
  144. public $civilite;
  145. /**
  146. * @var string fullname
  147. */
  148. public $fullname;
  149. /**
  150. * @var string Address
  151. */
  152. public $address;
  153. /**
  154. * @var string zip code
  155. */
  156. public $zip;
  157. /**
  158. * @var string Town
  159. */
  160. public $town;
  161. /**
  162. * @var int // Id of department
  163. */
  164. public $state_id;
  165. /**
  166. * @var string // Code of department
  167. */
  168. public $state_code;
  169. /**
  170. * @var string // Label of department
  171. */
  172. public $state;
  173. public $poste; // Position
  174. /**
  175. * @var int Thirdparty ID
  176. */
  177. public $socid; // both socid and fk_soc are used
  178. public $fk_soc; // both socid and fk_soc are used
  179. /**
  180. * @var string thirdparty name
  181. */
  182. public $socname;
  183. /**
  184. * @var int 0=inactive, 1=active
  185. */
  186. public $statut;
  187. public $code;
  188. /**
  189. * Email
  190. * @var string
  191. */
  192. public $email;
  193. /**
  194. * Email
  195. * @var string
  196. * @deprecated
  197. * @see $email
  198. */
  199. public $mail;
  200. /**
  201. * URL
  202. * @var string
  203. */
  204. public $url;
  205. /**
  206. * Unsuscribe all : 1 = contact has globaly unsubscribe of all mass emailings
  207. * @var int
  208. */
  209. public $no_email;
  210. /**
  211. * @var array array of socialnetworks
  212. */
  213. public $socialnetworks;
  214. /**
  215. * Skype username
  216. * @var string
  217. * @deprecated
  218. */
  219. public $skype;
  220. /**
  221. * Twitter username
  222. * @var string
  223. * @deprecated
  224. */
  225. public $twitter;
  226. /**
  227. * Facebook username
  228. * @var string
  229. * @deprecated
  230. */
  231. public $facebook;
  232. /**
  233. * Linkedin username
  234. * @var string
  235. * @deprecated
  236. */
  237. public $linkedin;
  238. /**
  239. * Jabber username
  240. * @var string
  241. * @deprecated
  242. */
  243. public $jabberid;
  244. /**
  245. * @var string filename for photo
  246. */
  247. public $photo;
  248. /**
  249. * @var string phone pro
  250. */
  251. public $phone_pro;
  252. /**
  253. * @var string phone perso
  254. */
  255. public $phone_perso;
  256. /**
  257. * @var string phone mobile
  258. */
  259. public $phone_mobile;
  260. /**
  261. * @var string fax
  262. */
  263. public $fax;
  264. /**
  265. * Private or public
  266. * @var int
  267. */
  268. public $priv;
  269. public $birthday;
  270. public $default_lang;
  271. /**
  272. * @var int Number of invoices for which he is contact
  273. */
  274. public $ref_facturation;
  275. /**
  276. * @var int Number of contracts for which he is contact
  277. */
  278. public $ref_contrat;
  279. /**
  280. * @var int Number of orders for which he is contact
  281. */
  282. public $ref_commande;
  283. /**
  284. * @var int Number of proposals for which he is contact
  285. */
  286. public $ref_propal;
  287. /**
  288. * @var int user ID
  289. */
  290. public $user_id;
  291. /**
  292. * @var string user login
  293. */
  294. public $user_login;
  295. // END MODULEBUILDER PROPERTIES
  296. /**
  297. * Old copy
  298. * @var Contact
  299. */
  300. public $oldcopy; // To contains a clone of this when we need to save old properties of object
  301. /**
  302. * @var array roles
  303. */
  304. public $roles;
  305. public $cacheprospectstatus = array();
  306. public $fk_prospectlevel;
  307. public $stcomm_id;
  308. public $statut_commercial;
  309. /**
  310. * @var string picto
  311. */
  312. public $stcomm_picto;
  313. /**
  314. * Constructor
  315. *
  316. * @param DoliDB $db Database handler
  317. */
  318. public function __construct($db)
  319. {
  320. global $conf, $langs;
  321. $this->db = $db;
  322. $this->statut = 1; // By default, status is enabled
  323. if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  324. $this->fields['rowid']['visible'] = 0;
  325. }
  326. if (!isModEnabled('mailing')) {
  327. $this->fields['no_email']['enabled'] = 0;
  328. }
  329. // typical ['s.nom'] is used for third-parties
  330. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  331. $this->fields['fk_soc']['enabled'] = 0;
  332. $this->fields['fk_soc']['searchall'] = 0;
  333. }
  334. if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) { // Default behaviour
  335. $this->fields['fk_stcommcontact']['enabled'] = 0;
  336. $this->fields['fk_prospectlevel']['enabled'] = 0;
  337. }
  338. // Unset fields that are disabled
  339. foreach ($this->fields as $key => $val) {
  340. if (isset($val['enabled']) && empty($val['enabled'])) {
  341. unset($this->fields[$key]);
  342. }
  343. }
  344. // Translate some data of arrayofkeyval
  345. /*if (is_object($langs))
  346. {
  347. foreach($this->fields as $key => $val)
  348. {
  349. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval']))
  350. {
  351. foreach($val['arrayofkeyval'] as $key2 => $val2)
  352. {
  353. $this->fields[$key]['arrayofkeyval'][$key2]=$langs->trans($val2);
  354. }
  355. }
  356. }
  357. }*/
  358. }
  359. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  360. /**
  361. * Load indicators into this->nb for board
  362. *
  363. * @return int <0 if KO, >0 if OK
  364. */
  365. public function load_state_board()
  366. {
  367. // phpcs:enable
  368. global $user, $hookmanager;
  369. $this->nb = array();
  370. $clause = "WHERE";
  371. $sql = "SELECT count(sp.rowid) as nb";
  372. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp";
  373. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  374. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  375. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  376. $sql .= " WHERE sp.fk_soc = s.rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  377. $clause = "AND";
  378. }
  379. $sql .= " ".$clause." sp.entity IN (".getEntity($this->element).")";
  380. $sql .= " AND (sp.priv='0' OR (sp.priv='1' AND sp.fk_user_creat = ".((int) $user->id)."))";
  381. if ($user->socid > 0) {
  382. $sql .= " AND sp.fk_soc = ".((int) $user->socid);
  383. }
  384. // Add where from hooks
  385. if (is_object($hookmanager)) {
  386. $parameters = array();
  387. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
  388. $sql .= $hookmanager->resPrint;
  389. }
  390. $resql = $this->db->query($sql);
  391. if ($resql) {
  392. while ($obj = $this->db->fetch_object($resql)) {
  393. $this->nb["contacts"] = $obj->nb;
  394. }
  395. $this->db->free($resql);
  396. return 1;
  397. } else {
  398. dol_print_error($this->db);
  399. $this->error = $this->db->lasterror();
  400. return -1;
  401. }
  402. }
  403. /**
  404. * Add a contact into database
  405. *
  406. * @param User $user Object user that create
  407. * @return int <0 if KO, >0 if OK
  408. */
  409. public function create($user)
  410. {
  411. global $conf, $langs;
  412. $error = 0;
  413. $now = dol_now();
  414. $this->db->begin();
  415. // Clean parameters
  416. $this->lastname = $this->lastname ?trim($this->lastname) : trim($this->name);
  417. $this->firstname = trim($this->firstname);
  418. $this->setUpperOrLowerCase();
  419. if (empty($this->socid)) {
  420. $this->socid = 0;
  421. }
  422. if (empty($this->priv)) {
  423. $this->priv = 0;
  424. }
  425. if (empty($this->statut)) {
  426. $this->statut = 0; // This is to convert '' into '0' to avoid bad sql request
  427. }
  428. $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
  429. $sql = "INSERT INTO ".MAIN_DB_PREFIX."socpeople (";
  430. $sql .= " datec";
  431. $sql .= ", fk_soc";
  432. $sql .= ", lastname";
  433. $sql .= ", firstname";
  434. $sql .= ", fk_user_creat";
  435. $sql .= ", priv";
  436. $sql .= ", fk_stcommcontact";
  437. $sql .= ", statut";
  438. $sql .= ", canvas";
  439. $sql .= ", entity";
  440. $sql .= ", ref_ext";
  441. $sql .= ", import_key";
  442. $sql .= ") VALUES (";
  443. $sql .= "'".$this->db->idate($now)."',";
  444. if ($this->socid > 0) {
  445. $sql .= " ".((int) $this->socid).",";
  446. } else {
  447. $sql .= "null,";
  448. }
  449. $sql .= "'".$this->db->escape($this->lastname)."',";
  450. $sql .= "'".$this->db->escape($this->firstname)."',";
  451. $sql .= " ".($user->id > 0 ? ((int) $user->id) : "null").",";
  452. $sql .= " ".((int) $this->priv).",";
  453. $sql .= " 0,";
  454. $sql .= " ".((int) $this->statut).",";
  455. $sql .= " ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null").",";
  456. $sql .= " ".((int) $this->entity).",";
  457. $sql .= "'".$this->db->escape($this->ref_ext)."',";
  458. $sql .= " ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
  459. $sql .= ")";
  460. dol_syslog(get_class($this)."::create", LOG_DEBUG);
  461. $resql = $this->db->query($sql);
  462. if ($resql) {
  463. $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."socpeople");
  464. if (!$error) {
  465. $result = $this->update($this->id, $user, 1, 'add'); // This include updateRoles(), ...
  466. if ($result < 0) {
  467. $error++;
  468. $this->error = $this->db->lasterror();
  469. }
  470. }
  471. if (!$error) {
  472. $result = $this->update_perso($this->id, $user, 1); // TODO Remove function update_perso, should be same than update
  473. if ($result < 0) {
  474. $error++;
  475. $this->error = $this->db->lasterror();
  476. }
  477. }
  478. if (!$error) {
  479. // Call trigger
  480. $result = $this->call_trigger('CONTACT_CREATE', $user);
  481. if ($result < 0) {
  482. $error++;
  483. }
  484. // End call triggers
  485. }
  486. if (!$error) {
  487. $this->db->commit();
  488. return $this->id;
  489. } else {
  490. $this->db->rollback();
  491. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  492. return -2;
  493. }
  494. } else {
  495. $this->error = $this->db->lasterror();
  496. $this->db->rollback();
  497. dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
  498. return -1;
  499. }
  500. }
  501. /**
  502. * Update informations into database
  503. *
  504. * @param int $id Id of contact/address to update
  505. * @param User $user Objet user making change
  506. * @param int $notrigger 0=no, 1=yes
  507. * @param string $action Current action for hookmanager
  508. * @param int $nosyncuser No sync linked user (external users and contacts are linked)
  509. * @return int <0 if KO, >0 if OK
  510. */
  511. public function update($id, $user = null, $notrigger = 0, $action = 'update', $nosyncuser = 0)
  512. {
  513. global $conf, $langs, $hookmanager;
  514. $error = 0;
  515. $this->id = $id;
  516. $this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
  517. // Clean parameters
  518. $this->ref_ext = trim($this->ref_ext);
  519. $this->lastname = trim($this->lastname) ?trim($this->lastname) : trim($this->lastname);
  520. $this->firstname = trim($this->firstname);
  521. $this->email = trim($this->email);
  522. $this->phone_pro = trim($this->phone_pro);
  523. $this->phone_perso = trim($this->phone_perso);
  524. $this->phone_mobile = trim($this->phone_mobile);
  525. $this->photo = trim($this->photo);
  526. $this->fax = trim($this->fax);
  527. $this->zip = (empty($this->zip) ? '' : trim($this->zip));
  528. $this->town = (empty($this->town) ? '' : trim($this->town));
  529. $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id);
  530. if (empty($this->statut)) {
  531. $this->statut = 0;
  532. }
  533. if (empty($this->civility_code) && !is_numeric($this->civility_id)) {
  534. $this->civility_code = $this->civility_id; // For backward compatibility
  535. }
  536. $this->setUpperOrLowerCase();
  537. $this->db->begin();
  538. $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
  539. if ($this->socid > 0) {
  540. $sql .= " fk_soc = ".((int) $this->socid).",";
  541. } elseif ($this->socid == -1) {
  542. $sql .= " fk_soc = NULL,";
  543. }
  544. $sql .= " civility='".$this->db->escape($this->civility_code)."'";
  545. $sql .= ", lastname='".$this->db->escape($this->lastname)."'";
  546. $sql .= ", firstname='".$this->db->escape($this->firstname)."'";
  547. $sql .= ", address='".$this->db->escape($this->address)."'";
  548. $sql .= ", zip='".$this->db->escape($this->zip)."'";
  549. $sql .= ", town='".$this->db->escape($this->town)."'";
  550. $sql .= ", ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "NULL");
  551. $sql .= ", fk_pays=".($this->country_id > 0 ? $this->country_id : 'NULL');
  552. $sql .= ", fk_departement=".($this->state_id > 0 ? $this->state_id : 'NULL');
  553. $sql .= ", poste='".$this->db->escape($this->poste)."'";
  554. $sql .= ", fax='".$this->db->escape($this->fax)."'";
  555. $sql .= ", email='".$this->db->escape($this->email)."'";
  556. $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'";
  557. $sql .= ", photo='".$this->db->escape($this->photo)."'";
  558. $sql .= ", birthday=".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
  559. $sql .= ", note_private = ".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "NULL");
  560. $sql .= ", note_public = ".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "NULL");
  561. $sql .= ", phone = ".(isset($this->phone_pro) ? "'".$this->db->escape($this->phone_pro)."'" : "NULL");
  562. $sql .= ", phone_perso = ".(isset($this->phone_perso) ? "'".$this->db->escape($this->phone_perso)."'" : "NULL");
  563. $sql .= ", phone_mobile = ".(isset($this->phone_mobile) ? "'".$this->db->escape($this->phone_mobile)."'" : "NULL");
  564. $sql .= ", priv = '".$this->db->escape($this->priv)."'";
  565. $sql .= ", fk_prospectlevel = '".$this->db->escape($this->fk_prospectlevel)."'";
  566. if (isset($this->stcomm_id)) {
  567. $sql .= ", fk_stcommcontact = ".($this->stcomm_id > 0 || $this->stcomm_id == -1 ? $this->stcomm_id : "0");
  568. }
  569. $sql .= ", statut = ".((int) $this->statut);
  570. $sql .= ", fk_user_modif=".($user->id > 0 ? "'".$this->db->escape($user->id)."'" : "NULL");
  571. $sql .= ", default_lang=".($this->default_lang ? "'".$this->db->escape($this->default_lang)."'" : "NULL");
  572. $sql .= ", entity = ".((int) $this->entity);
  573. $sql .= " WHERE rowid = ".((int) $id);
  574. dol_syslog(get_class($this)."::update", LOG_DEBUG);
  575. $result = $this->db->query($sql);
  576. if ($result) {
  577. unset($this->country_code);
  578. unset($this->country);
  579. unset($this->state_code);
  580. unset($this->state);
  581. $action = 'update';
  582. // Actions on extra fields
  583. if (!$error) {
  584. $result = $this->insertExtraFields();
  585. if ($result < 0) {
  586. $error++;
  587. }
  588. }
  589. if (!$error) {
  590. $result = $this->updateRoles();
  591. if ($result < 0) {
  592. $error++;
  593. }
  594. }
  595. if (!$error && $this->user_id > 0) {
  596. // If contact is linked to a user
  597. $tmpobj = new User($this->db);
  598. $tmpobj->fetch($this->user_id);
  599. $usermustbemodified = 0;
  600. if ($tmpobj->office_phone != $this->phone_pro) {
  601. $tmpobj->office_phone = $this->phone_pro;
  602. $usermustbemodified++;
  603. }
  604. if ($tmpobj->office_fax != $this->fax) {
  605. $tmpobj->office_fax = $this->fax;
  606. $usermustbemodified++;
  607. }
  608. if ($tmpobj->address != $this->address) {
  609. $tmpobj->address = $this->address;
  610. $usermustbemodified++;
  611. }
  612. if ($tmpobj->town != $this->town) {
  613. $tmpobj->town = $this->town;
  614. $usermustbemodified++;
  615. }
  616. if ($tmpobj->zip != $this->zip) {
  617. $tmpobj->zip = $this->zip;
  618. $usermustbemodified++;
  619. }
  620. if ($tmpobj->zip != $this->zip) {
  621. $tmpobj->state_id = $this->state_id;
  622. $usermustbemodified++;
  623. }
  624. if ($tmpobj->country_id != $this->country_id) {
  625. $tmpobj->country_id = $this->country_id;
  626. $usermustbemodified++;
  627. }
  628. if ($tmpobj->email != $this->email) {
  629. $tmpobj->email = $this->email;
  630. $usermustbemodified++;
  631. }
  632. if (!empty(array_diff($tmpobj->socialnetworks, $this->socialnetworks))) {
  633. $tmpobj->socialnetworks = $this->socialnetworks;
  634. $usermustbemodified++;
  635. }
  636. if ($usermustbemodified) {
  637. $result = $tmpobj->update($user, 0, 1, 1, 1);
  638. if ($result < 0) {
  639. $error++;
  640. }
  641. }
  642. }
  643. if (!$error && !$notrigger) {
  644. // Call trigger
  645. $result = $this->call_trigger('CONTACT_MODIFY', $user);
  646. if ($result < 0) {
  647. $error++;
  648. }
  649. // End call triggers
  650. }
  651. if (!$error) {
  652. $this->db->commit();
  653. return 1;
  654. } else {
  655. dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
  656. $this->db->rollback();
  657. return -$error;
  658. }
  659. } else {
  660. $this->error = $this->db->lasterror().' sql='.$sql;
  661. $this->db->rollback();
  662. return -1;
  663. }
  664. }
  665. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  666. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  667. /**
  668. * Retourne chaine DN complete dans l'annuaire LDAP pour l'objet
  669. *
  670. * @param array $info Info string loaded by _load_ldap_info
  671. * @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb)
  672. * 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb)
  673. * 2=Return key only (uid=qqq)
  674. * @return string DN
  675. */
  676. public function _load_ldap_dn($info, $mode = 0)
  677. {
  678. // phpcs:enable
  679. global $conf;
  680. $dn = '';
  681. if ($mode == 0) {
  682. $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS].",".$conf->global->LDAP_CONTACT_DN;
  683. } elseif ($mode == 1) {
  684. $dn = $conf->global->LDAP_CONTACT_DN;
  685. } elseif ($mode == 2) {
  686. $dn = $conf->global->LDAP_KEY_CONTACTS."=".$info[$conf->global->LDAP_KEY_CONTACTS];
  687. }
  688. return $dn;
  689. }
  690. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  691. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  692. /**
  693. * Initialise tableau info (tableau des attributs LDAP)
  694. *
  695. * @return array Tableau info des attributs
  696. */
  697. public function _load_ldap_info()
  698. {
  699. // phpcs:enable
  700. global $conf, $langs;
  701. $info = array();
  702. // Object classes
  703. $info["objectclass"] = explode(',', $conf->global->LDAP_CONTACT_OBJECT_CLASS);
  704. $this->fullname = $this->getFullName($langs);
  705. // Fields
  706. if ($this->fullname && !empty($conf->global->LDAP_CONTACT_FIELD_FULLNAME)) {
  707. $info[$conf->global->LDAP_CONTACT_FIELD_FULLNAME] = $this->fullname;
  708. }
  709. if ($this->lastname && !empty($conf->global->LDAP_CONTACT_FIELD_NAME)) {
  710. $info[$conf->global->LDAP_CONTACT_FIELD_NAME] = $this->lastname;
  711. }
  712. if ($this->firstname && !empty($conf->global->LDAP_CONTACT_FIELD_FIRSTNAME)) {
  713. $info[$conf->global->LDAP_CONTACT_FIELD_FIRSTNAME] = $this->firstname;
  714. }
  715. if ($this->poste) {
  716. $info["title"] = $this->poste;
  717. }
  718. if ($this->socid > 0) {
  719. $soc = new Societe($this->db);
  720. $soc->fetch($this->socid);
  721. $info[$conf->global->LDAP_CONTACT_FIELD_COMPANY] = $soc->name;
  722. if ($soc->client == 1) {
  723. $info["businessCategory"] = "Customers";
  724. }
  725. if ($soc->client == 2) {
  726. $info["businessCategory"] = "Prospects";
  727. }
  728. if ($soc->fournisseur == 1) {
  729. $info["businessCategory"] = "Suppliers";
  730. }
  731. }
  732. if ($this->address && !empty($conf->global->LDAP_CONTACT_FIELD_ADDRESS)) {
  733. $info[$conf->global->LDAP_CONTACT_FIELD_ADDRESS] = $this->address;
  734. }
  735. if ($this->zip && !empty($conf->global->LDAP_CONTACT_FIELD_ZIP)) {
  736. $info[$conf->global->LDAP_CONTACT_FIELD_ZIP] = $this->zip;
  737. }
  738. if ($this->town && !empty($conf->global->LDAP_CONTACT_FIELD_TOWN)) {
  739. $info[$conf->global->LDAP_CONTACT_FIELD_TOWN] = $this->town;
  740. }
  741. if ($this->country_code && !empty($conf->global->LDAP_CONTACT_FIELD_COUNTRY)) {
  742. $info[$conf->global->LDAP_CONTACT_FIELD_COUNTRY] = $this->country_code;
  743. }
  744. if ($this->phone_pro && !empty($conf->global->LDAP_CONTACT_FIELD_PHONE)) {
  745. $info[$conf->global->LDAP_CONTACT_FIELD_PHONE] = $this->phone_pro;
  746. }
  747. if ($this->phone_perso && !empty($conf->global->LDAP_CONTACT_FIELD_HOMEPHONE)) {
  748. $info[$conf->global->LDAP_CONTACT_FIELD_HOMEPHONE] = $this->phone_perso;
  749. }
  750. if ($this->phone_mobile && !empty($conf->global->LDAP_CONTACT_FIELD_MOBILE)) {
  751. $info[$conf->global->LDAP_CONTACT_FIELD_MOBILE] = $this->phone_mobile;
  752. }
  753. if ($this->fax && !empty($conf->global->LDAP_CONTACT_FIELD_FAX)) {
  754. $info[$conf->global->LDAP_CONTACT_FIELD_FAX] = $this->fax;
  755. }
  756. if ($this->note_private && !empty($conf->global->LDAP_CONTACT_FIELD_DESCRIPTION)) {
  757. $info[$conf->global->LDAP_CONTACT_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2);
  758. }
  759. if ($this->email && !empty($conf->global->LDAP_CONTACT_FIELD_MAIL)) {
  760. $info[$conf->global->LDAP_CONTACT_FIELD_MAIL] = $this->email;
  761. }
  762. if ($conf->global->LDAP_SERVER_TYPE == 'egroupware') {
  763. $info["objectclass"][4] = "phpgwContact"; // compatibilite egroupware
  764. $info['uidnumber'] = $this->id;
  765. $info['phpgwTz'] = 0;
  766. $info['phpgwMailType'] = 'INTERNET';
  767. $info['phpgwMailHomeType'] = 'INTERNET';
  768. $info["phpgwContactTypeId"] = 'n';
  769. $info["phpgwContactCatId"] = 0;
  770. $info["phpgwContactAccess"] = "public";
  771. if (dol_strlen($this->egroupware_id) == 0) {
  772. $this->egroupware_id = 1;
  773. }
  774. $info["phpgwContactOwner"] = $this->egroupware_id;
  775. if ($this->email) {
  776. $info["rfc822Mailbox"] = $this->email;
  777. }
  778. if ($this->phone_mobile) {
  779. $info["phpgwCellTelephoneNumber"] = $this->phone_mobile;
  780. }
  781. }
  782. return $info;
  783. }
  784. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  785. /**
  786. * Update field alert birthday
  787. *
  788. * @param int $id Id of contact
  789. * @param User $user User asking to change alert or birthday
  790. * @param int $notrigger 0=no, 1=yes
  791. * @return int <0 if KO, >=0 if OK
  792. */
  793. public function update_perso($id, $user = null, $notrigger = 0)
  794. {
  795. // phpcs:enable
  796. $error = 0;
  797. $result = false;
  798. $this->db->begin();
  799. // Mis a jour contact
  800. $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET";
  801. $sql .= " birthday = ".($this->birthday ? "'".$this->db->idate($this->birthday)."'" : "null");
  802. $sql .= ", photo = ".($this->photo ? "'".$this->db->escape($this->photo)."'" : "null");
  803. if ($user) {
  804. $sql .= ", fk_user_modif = ".((int) $user->id);
  805. }
  806. $sql .= " WHERE rowid = ".((int) $id);
  807. dol_syslog(get_class($this)."::update_perso this->birthday=".$this->birthday." -", LOG_DEBUG);
  808. $resql = $this->db->query($sql);
  809. if (!$resql) {
  810. $error++;
  811. $this->error = $this->db->lasterror();
  812. }
  813. if ($user) {
  814. // Update birthday alert
  815. if (!empty($this->birthday_alert)) {
  816. //check existing
  817. $sql_check = "SELECT rowid FROM " . MAIN_DB_PREFIX . "user_alert WHERE type = 1 AND fk_contact = " . ((int) $id) . " AND fk_user = " . ((int) $user->id);
  818. $result_check = $this->db->query($sql_check);
  819. if (!$result_check || ($this->db->num_rows($result_check) < 1)) {
  820. //insert
  821. $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_alert(type, fk_contact, fk_user) ";
  822. $sql .= "VALUES (1," . ((int) $id) . "," . ((int) $user->id) . ")";
  823. $result = $this->db->query($sql);
  824. if (!$result) {
  825. $error++;
  826. $this->error = $this->db->lasterror();
  827. }
  828. } else {
  829. $result = true;
  830. }
  831. } else {
  832. $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_alert ";
  833. $sql .= "WHERE type=1 AND fk_contact=" . ((int) $id) . " AND fk_user=" . ((int) $user->id);
  834. $result = $this->db->query($sql);
  835. if (!$result) {
  836. $error++;
  837. $this->error = $this->db->lasterror();
  838. }
  839. }
  840. }
  841. if (!$error && !$notrigger) {
  842. // Call trigger
  843. $result = $this->call_trigger('CONTACT_MODIFY', $user);
  844. if ($result < 0) {
  845. $error++;
  846. }
  847. // End call triggers
  848. }
  849. if (!$error) {
  850. $this->db->commit();
  851. return 1;
  852. } else {
  853. dol_syslog(get_class($this)."::update Error ".$this->error, LOG_ERR);
  854. $this->db->rollback();
  855. return -$error;
  856. }
  857. }
  858. /**
  859. * Load object contact.
  860. *
  861. * @param int $id Id of contact
  862. * @param User $user Load also alerts of this user (subscribing to alerts) that want alerts about this contact
  863. * @param string $ref_ext External reference, not given by Dolibarr
  864. * @param string $email Email
  865. * @param int $loadalsoroles Load also roles. Try to always 0 here and load roles with a separate call of fetchRoles().
  866. * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
  867. */
  868. public function fetch($id, $user = null, $ref_ext = '', $email = '', $loadalsoroles = 0)
  869. {
  870. global $langs;
  871. dol_syslog(get_class($this)."::fetch id=".$id." ref_ext=".$ref_ext." email=".$email, LOG_DEBUG);
  872. if (empty($id) && empty($ref_ext) && empty($email)) {
  873. $this->error = 'BadParameter';
  874. return -1;
  875. }
  876. $langs->loadLangs(array("dict", "companies"));
  877. $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,";
  878. $sql .= " c.address, c.statut, c.zip, c.town,";
  879. $sql .= " c.fk_pays as country_id,";
  880. $sql .= " c.fk_departement as state_id,";
  881. $sql .= " c.birthday,";
  882. $sql .= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email,";
  883. $sql .= " c.socialnetworks,";
  884. $sql .= " c.photo,";
  885. $sql .= " c.priv, c.note_private, c.note_public, c.default_lang, c.canvas,";
  886. $sql .= " c.fk_prospectlevel, c.fk_stcommcontact, st.libelle as stcomm, st.picto as stcomm_picto,";
  887. $sql .= " c.import_key,";
  888. $sql .= " c.datec as date_creation, c.tms as date_modification,";
  889. $sql .= " co.label as country, co.code as country_code,";
  890. $sql .= " d.nom as state, d.code_departement as state_code,";
  891. $sql .= " u.rowid as user_id, u.login as user_login,";
  892. $sql .= " s.nom as socname, s.address as socaddress, s.zip as soccp, s.town as soccity, s.default_lang as socdefault_lang";
  893. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
  894. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON c.fk_pays = co.rowid";
  895. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
  896. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
  897. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
  898. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcommcontact as st ON c.fk_stcommcontact = st.id';
  899. if ($id) {
  900. $sql .= " WHERE c.rowid = ".((int) $id);
  901. } else {
  902. $sql .= " WHERE c.entity IN (".getEntity($this->element).")";
  903. if ($ref_ext) {
  904. $sql .= " AND c.ref_ext = '".$this->db->escape($ref_ext)."'";
  905. }
  906. if ($email) {
  907. $sql .= " AND c.email = '".$this->db->escape($email)."'";
  908. }
  909. }
  910. $resql = $this->db->query($sql);
  911. if ($resql) {
  912. $num = $this->db->num_rows($resql);
  913. if ($num > 1) {
  914. $this->error = 'Fetch found several records. Rename one of contact to avoid duplicate.';
  915. dol_syslog($this->error, LOG_ERR);
  916. return 2;
  917. } elseif ($num) { // $num = 1
  918. $obj = $this->db->fetch_object($resql);
  919. $this->id = $obj->rowid;
  920. $this->entity = $obj->entity;
  921. $this->ref = $obj->rowid;
  922. $this->ref_ext = $obj->ref_ext;
  923. $this->civility_code = $obj->civility_code;
  924. $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : '';
  925. $this->lastname = $obj->lastname;
  926. $this->firstname = $obj->firstname;
  927. $this->address = $obj->address;
  928. $this->zip = $obj->zip;
  929. $this->town = $obj->town;
  930. $this->date_creation = $this->db->jdate($obj->date_creation);
  931. $this->date_modification = $this->db->jdate($obj->date_modification);
  932. $this->state_id = $obj->state_id;
  933. $this->state_code = $obj->state_code;
  934. $this->state = $obj->state;
  935. $this->country_id = $obj->country_id;
  936. $this->country_code = $obj->country_id ? $obj->country_code : '';
  937. $this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
  938. $this->fk_soc = $obj->fk_soc; // Both fk_soc and socid are used
  939. $this->socid = $obj->fk_soc; // Both fk_soc and socid are used
  940. $this->socname = $obj->socname;
  941. $this->poste = $obj->poste;
  942. $this->statut = $obj->statut;
  943. $this->fk_prospectlevel = $obj->fk_prospectlevel;
  944. $transcode = $langs->trans('StatusProspect'.$obj->fk_stcommcontact);
  945. $libelle = ($transcode != 'StatusProspect'.$obj->fk_stcommcontact ? $transcode : $obj->stcomm);
  946. $this->stcomm_id = $obj->fk_stcommcontact; // id statut commercial
  947. $this->statut_commercial = $libelle; // libelle statut commercial
  948. $this->stcomm_picto = $obj->stcomm_picto; // Picto statut commercial
  949. $this->phone_pro = trim($obj->phone);
  950. $this->fax = trim($obj->fax);
  951. $this->phone_perso = trim($obj->phone_perso);
  952. $this->phone_mobile = trim($obj->phone_mobile);
  953. $this->email = $obj->email;
  954. $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array());
  955. $this->photo = $obj->photo;
  956. $this->priv = $obj->priv;
  957. $this->mail = $obj->email;
  958. $this->birthday = $this->db->jdate($obj->birthday);
  959. $this->note = $obj->note_private; // deprecated
  960. $this->note_private = $obj->note_private;
  961. $this->note_public = $obj->note_public;
  962. $this->default_lang = $obj->default_lang;
  963. $this->user_id = $obj->user_id;
  964. $this->user_login = $obj->user_login;
  965. $this->canvas = $obj->canvas;
  966. $this->import_key = $obj->import_key;
  967. // Define gender according to civility
  968. $this->setGenderFromCivility();
  969. // Search Dolibarr user linked to this contact
  970. $sql = "SELECT u.rowid ";
  971. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  972. $sql .= " WHERE u.fk_socpeople = ".((int) $this->id);
  973. $resql = $this->db->query($sql);
  974. if ($resql) {
  975. if ($this->db->num_rows($resql)) {
  976. $uobj = $this->db->fetch_object($resql);
  977. $this->user_id = $uobj->rowid;
  978. }
  979. $this->db->free($resql);
  980. } else {
  981. $this->error = $this->db->error();
  982. return -1;
  983. }
  984. // Retrieve all extrafield
  985. // fetch optionals attributes and labels
  986. $this->fetch_optionals();
  987. // Load also alerts of this user
  988. if ($user) {
  989. $sql = "SELECT fk_user";
  990. $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
  991. $sql .= " WHERE fk_user = ".((int) $user->id)." AND fk_contact = ".((int) $id);
  992. $resql = $this->db->query($sql);
  993. if ($resql) {
  994. if ($this->db->num_rows($resql)) {
  995. $obj = $this->db->fetch_object($resql);
  996. $this->birthday_alert = 1;
  997. }
  998. $this->db->free($resql);
  999. } else {
  1000. $this->error = $this->db->error();
  1001. return -1;
  1002. }
  1003. }
  1004. // Load also roles of this address
  1005. if ($loadalsoroles) {
  1006. $resultRole = $this->fetchRoles();
  1007. if ($resultRole < 0) {
  1008. return $resultRole;
  1009. }
  1010. }
  1011. return 1;
  1012. } else {
  1013. $this->error = $langs->trans("RecordNotFound");
  1014. return 0;
  1015. }
  1016. } else {
  1017. $this->error = $this->db->error();
  1018. return -1;
  1019. }
  1020. }
  1021. /**
  1022. * Set the property "gender" of this class, based on the property "civility_id"
  1023. * or use property "civility_code" as fallback, when "civility_id" is not available.
  1024. *
  1025. * @return void
  1026. */
  1027. public function setGenderFromCivility()
  1028. {
  1029. unset($this->gender);
  1030. if (in_array($this->civility_id, array('MR')) || in_array($this->civility_code, array('MR'))) {
  1031. $this->gender = 'man';
  1032. } elseif (in_array($this->civility_id, array('MME', 'MLE')) || in_array($this->civility_code, array('MME', 'MLE'))) {
  1033. $this->gender = 'woman';
  1034. }
  1035. }
  1036. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1037. /**
  1038. * Load number of elements the contact is used as a link for
  1039. * ref_facturation
  1040. * ref_contrat
  1041. * ref_commande (for order and/or shipments)
  1042. * ref_propale
  1043. *
  1044. * @return int <0 if KO, >=0 if OK
  1045. */
  1046. public function load_ref_elements()
  1047. {
  1048. // phpcs:enable
  1049. // Compte les elements pour lesquels il est contact
  1050. $sql = "SELECT tc.element, count(ec.rowid) as nb";
  1051. $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc";
  1052. $sql .= " WHERE ec.fk_c_type_contact = tc.rowid";
  1053. $sql .= " AND fk_socpeople = ".((int) $this->id);
  1054. $sql .= " AND tc.source = 'external'";
  1055. $sql .= " GROUP BY tc.element";
  1056. dol_syslog(get_class($this)."::load_ref_elements", LOG_DEBUG);
  1057. $resql = $this->db->query($sql);
  1058. if ($resql) {
  1059. while ($obj = $this->db->fetch_object($resql)) {
  1060. if ($obj->nb) {
  1061. if ($obj->element == 'facture') {
  1062. $this->ref_facturation = $obj->nb;
  1063. } elseif ($obj->element == 'contrat') {
  1064. $this->ref_contrat = $obj->nb;
  1065. } elseif ($obj->element == 'commande') {
  1066. $this->ref_commande = $obj->nb;
  1067. } elseif ($obj->element == 'propal') {
  1068. $this->ref_propal = $obj->nb;
  1069. }
  1070. }
  1071. }
  1072. $this->db->free($resql);
  1073. return 0;
  1074. } else {
  1075. $this->error = $this->db->lasterror();
  1076. return -1;
  1077. }
  1078. }
  1079. /**
  1080. * Delete a contact from database
  1081. * // TODO Add $user as first param
  1082. *
  1083. * @param int $notrigger Disable all trigger
  1084. * @return int <0 if KO, >0 if OK
  1085. */
  1086. public function delete($notrigger = 0)
  1087. {
  1088. global $conf, $langs, $user;
  1089. $error = 0;
  1090. $this->db->begin();
  1091. if (!$error && !$notrigger) {
  1092. // Call trigger
  1093. $result = $this->call_trigger('CONTACT_DELETE', $user);
  1094. if ($result < 0) {
  1095. $error++;
  1096. }
  1097. // End call triggers
  1098. }
  1099. if (!$error) {
  1100. // Get all rowid of element_contact linked to a type that is link to llx_socpeople
  1101. $sql = "SELECT ec.rowid";
  1102. $sql .= " FROM ".MAIN_DB_PREFIX."element_contact ec,";
  1103. $sql .= " ".MAIN_DB_PREFIX."c_type_contact tc";
  1104. $sql .= " WHERE ec.fk_socpeople=".((int) $this->id);
  1105. $sql .= " AND ec.fk_c_type_contact=tc.rowid";
  1106. $sql .= " AND tc.source='external'";
  1107. dol_syslog(__METHOD__, LOG_DEBUG);
  1108. $resql = $this->db->query($sql);
  1109. if ($resql) {
  1110. $num = $this->db->num_rows($resql);
  1111. $i = 0;
  1112. while ($i < $num && !$error) {
  1113. $obj = $this->db->fetch_object($resql);
  1114. $sqldel = "DELETE FROM ".MAIN_DB_PREFIX."element_contact";
  1115. $sqldel .= " WHERE rowid = ".((int) $obj->rowid);
  1116. dol_syslog(__METHOD__, LOG_DEBUG);
  1117. $result = $this->db->query($sqldel);
  1118. if (!$result) {
  1119. $error++;
  1120. $this->error = $this->db->error().' sql='.$sqldel;
  1121. }
  1122. $i++;
  1123. }
  1124. } else {
  1125. $error++;
  1126. $this->error = $this->db->error().' sql='.$sql;
  1127. }
  1128. }
  1129. if (!$error) {
  1130. // Remove Roles
  1131. $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".((int) $this->id);
  1132. dol_syslog(__METHOD__, LOG_DEBUG);
  1133. $resql = $this->db->query($sql);
  1134. if (!$resql) {
  1135. $error++;
  1136. $this->error .= $this->db->lasterror();
  1137. $errorflag = -1;
  1138. }
  1139. }
  1140. if (!$error) {
  1141. // Remove Roles
  1142. $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople = ".((int) $this->id);
  1143. dol_syslog(__METHOD__, LOG_DEBUG);
  1144. $resql = $this->db->query($sql);
  1145. if (!$resql) {
  1146. $error++;
  1147. $this->error .= $this->db->lasterror();
  1148. $errorflag = -1;
  1149. }
  1150. }
  1151. if (!$error) {
  1152. // Remove category
  1153. $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_contact WHERE fk_socpeople = ".((int) $this->id);
  1154. dol_syslog(__METHOD__, LOG_DEBUG);
  1155. $resql = $this->db->query($sql);
  1156. if (!$resql) {
  1157. $error++;
  1158. $this->error .= $this->db->lasterror();
  1159. $errorflag = -1;
  1160. }
  1161. }
  1162. if (!$error) {
  1163. $sql = "DELETE FROM ".MAIN_DB_PREFIX."socpeople";
  1164. $sql .= " WHERE rowid = ".((int) $this->id);
  1165. dol_syslog(__METHOD__, LOG_DEBUG);
  1166. $result = $this->db->query($sql);
  1167. if (!$result) {
  1168. $error++;
  1169. $this->error = $this->db->error().' sql='.$sql;
  1170. }
  1171. }
  1172. // Removed extrafields
  1173. if (!$error) {
  1174. // For avoid conflicts if trigger used
  1175. $result = $this->deleteExtraFields();
  1176. if ($result < 0) {
  1177. $error++;
  1178. }
  1179. }
  1180. if (!$error) {
  1181. $this->db->commit();
  1182. return 1;
  1183. } else {
  1184. $this->db->rollback();
  1185. dol_syslog("Error ".$this->error, LOG_ERR);
  1186. return -1;
  1187. }
  1188. }
  1189. /**
  1190. * Charge les informations sur le contact, depuis la base
  1191. *
  1192. * @param int $id Id du contact a charger
  1193. * @return void
  1194. */
  1195. public function info($id)
  1196. {
  1197. $sql = "SELECT c.rowid, c.datec as datec, c.fk_user_creat,";
  1198. $sql .= " c.tms as tms, c.fk_user_modif";
  1199. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c";
  1200. $sql .= " WHERE c.rowid = ".((int) $id);
  1201. $resql = $this->db->query($sql);
  1202. if ($resql) {
  1203. if ($this->db->num_rows($resql)) {
  1204. $obj = $this->db->fetch_object($resql);
  1205. $this->id = $obj->rowid;
  1206. if ($obj->fk_user_creat) {
  1207. $cuser = new User($this->db);
  1208. $cuser->fetch($obj->fk_user_creat);
  1209. $this->user_creation = $cuser;
  1210. }
  1211. if ($obj->fk_user_modif) {
  1212. $muser = new User($this->db);
  1213. $muser->fetch($obj->fk_user_modif);
  1214. $this->user_modification = $muser;
  1215. }
  1216. $this->date_creation = $this->db->jdate($obj->datec);
  1217. $this->date_modification = $this->db->jdate($obj->tms);
  1218. }
  1219. $this->db->free($resql);
  1220. } else {
  1221. print $this->db->error();
  1222. }
  1223. }
  1224. /**
  1225. * Return number of mass Emailing received by this contacts with its email
  1226. *
  1227. * @return int Number of EMailings
  1228. */
  1229. public function getNbOfEMailings()
  1230. {
  1231. $sql = "SELECT count(mc.email) as nb";
  1232. $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m";
  1233. $sql .= " WHERE mc.fk_mailing=m.rowid AND mc.email = '".$this->db->escape($this->email)."' ";
  1234. $sql .= " AND m.entity IN (".getEntity($this->element).") AND mc.statut NOT IN (-1,0)"; // -1 error, 0 not sent, 1 sent with success
  1235. $resql = $this->db->query($sql);
  1236. if ($resql) {
  1237. $obj = $this->db->fetch_object($resql);
  1238. $nb = $obj->nb;
  1239. $this->db->free($resql);
  1240. return $nb;
  1241. } else {
  1242. $this->error = $this->db->error();
  1243. return -1;
  1244. }
  1245. }
  1246. /**
  1247. * getTooltipContentArray
  1248. * @param array $params params to construct tooltip data
  1249. * @since v18
  1250. * @return array
  1251. */
  1252. public function getTooltipContentArray($params)
  1253. {
  1254. global $conf, $langs, $user;
  1255. $datas = [];
  1256. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1257. return ['optimize' => $langs->trans("ShowContact")];
  1258. }
  1259. if (!empty($this->photo) && class_exists('Form')) {
  1260. $photo = '<div class="photointooltip floatright">';
  1261. $photo .= Form::showphoto('contact', $this, 0, 40, 0, 'photoref', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
  1262. $photo .= '</div>';
  1263. $datas['photo'] = $photo;
  1264. }
  1265. $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Contact").'</u> ' . $this->getLibStatut(4);
  1266. $datas['name'] = '<br><b>'.$langs->trans("Name").':</b> '.$this->getFullName($langs);
  1267. // if ($this->civility_id) $datas['civility'] = '<br><b>' . $langs->trans("Civility") . ':</b> '.$this->civility_id; // TODO Translate civilty_id code
  1268. if (!empty($this->poste)) {
  1269. $datas['job'] = '<br><b>'.$langs->trans("Poste").':</b> '.$this->poste;
  1270. }
  1271. $datas['email'] = '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
  1272. $phonelist = array();
  1273. $country_code = empty($this->country_code) ? '': $this->country_code;
  1274. if ($this->phone_pro) {
  1275. $phonelist[] = dol_print_phone($this->phone_pro, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
  1276. }
  1277. if ($this->phone_mobile) {
  1278. $phonelist[] = dol_print_phone($this->phone_mobile, $country_code, $this->id, 0, '', '&nbsp;', 'mobile');
  1279. }
  1280. if ($this->phone_perso) {
  1281. $phonelist[] = dol_print_phone($this->phone_perso, $country_code, $this->id, 0, '', '&nbsp;', 'phone');
  1282. }
  1283. $datas['phonelist'] = '<br><b>'.$langs->trans("Phone").':</b> '.implode('&nbsp;', $phonelist);
  1284. $datas['address'] = '<br><b>'.$langs->trans("Address").':</b> '.dol_format_address($this, 1, ' ', $langs);
  1285. return $datas;
  1286. }
  1287. /**
  1288. * Return name of contact with link (and eventually picto)
  1289. * Use $this->id, $this->lastname, $this->firstname, this->civility_id
  1290. *
  1291. * @param int $withpicto Include picto with link (1=picto + name, 2=picto only, -1=photo+name, -2=photo only)
  1292. * @param string $option Where the link point to
  1293. * @param int $maxlen Max length of
  1294. * @param string $moreparam Add more param into URL
  1295. * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
  1296. * @param int $notooltip 1=Disable tooltip
  1297. * @param string $morecss Add more css on link
  1298. * @return string String with URL
  1299. */
  1300. public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '')
  1301. {
  1302. global $conf, $langs, $hookmanager;
  1303. $result = '';
  1304. $params = [
  1305. 'id' => $this->id,
  1306. 'objecttype' => $this->element,
  1307. 'option' => $option,
  1308. ];
  1309. $classfortooltip = 'classfortooltip';
  1310. $dataparams = '';
  1311. if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
  1312. $classfortooltip = 'classforajaxtooltip';
  1313. $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
  1314. $label = '';
  1315. } else {
  1316. $label = implode($this->getTooltipContentArray($params));
  1317. }
  1318. $url = DOL_URL_ROOT.'/contact/card.php?id='.$this->id;
  1319. if ($option !== 'nolink') {
  1320. // Add param to save lastsearch_values or not
  1321. $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
  1322. if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
  1323. $add_save_lastsearch_values = 1;
  1324. }
  1325. if ($add_save_lastsearch_values) {
  1326. $url .= '&save_lastsearch_values=1';
  1327. }
  1328. }
  1329. $url .= $moreparam;
  1330. $linkclose = "";
  1331. if (empty($notooltip)) {
  1332. if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
  1333. $label = $langs->trans("ShowContact");
  1334. $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
  1335. }
  1336. $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
  1337. $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
  1338. }
  1339. $linkstart = '<a href="'.$url.'"';
  1340. $linkstart .= $linkclose.'>';
  1341. $linkend = '</a>';
  1342. if ($option == 'xxx') {
  1343. $linkstart = '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$this->id.$moreparam.'"'.$dataparams.' title="'.dol_escape_htmltag($label, 1).'" class="'.$classfortooltip.'">';
  1344. $linkend = '</a>';
  1345. }
  1346. $result .= (($option == 'nolink') ? '' : $linkstart);
  1347. if ($withpicto) {
  1348. if ($withpicto < 0) {
  1349. $result .= '<!-- picto photo user --><span class="nopadding userimg'.($morecss ? ' '.$morecss : '').'">'.Form::showphoto('contact', $this, 0, 0, 0, 'userphoto'.($withpicto == -3 ? 'small' : ''), 'mini', 0, 1).'</span>';
  1350. } else {
  1351. $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);
  1352. }
  1353. }
  1354. if ($withpicto != 2 && $withpicto != -2) {
  1355. $result .= '<span class="valigmiddle">'.($maxlen ? dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)).'</span>';
  1356. }
  1357. $result .= (($option == 'nolink') ? '' : $linkend);
  1358. global $action;
  1359. $hookmanager->initHooks(array('contactdao'));
  1360. $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
  1361. $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  1362. if ($reshook > 0) {
  1363. $result = $hookmanager->resPrint;
  1364. } else {
  1365. $result .= $hookmanager->resPrint;
  1366. }
  1367. return $result;
  1368. }
  1369. /**
  1370. * Return civility label of contact
  1371. *
  1372. * @return string Translated name of civility
  1373. */
  1374. public function getCivilityLabel()
  1375. {
  1376. global $langs;
  1377. $code = ($this->civility_code ? $this->civility_code : (!empty($this->civility_id) ? $this->civility : (!empty($this->civilite) ? $this->civilite : '')));
  1378. if (empty($code)) {
  1379. return '';
  1380. }
  1381. $langs->load("dict");
  1382. return $langs->getLabelFromKey($this->db, "Civility".$code, "c_civility", "code", "label", $code);
  1383. }
  1384. /**
  1385. * Return the label of the status
  1386. *
  1387. * @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
  1388. * @return string Label of status
  1389. */
  1390. public function getLibStatut($mode)
  1391. {
  1392. return $this->LibStatut($this->statut, $mode);
  1393. }
  1394. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1395. /**
  1396. * Return the label of a given status
  1397. *
  1398. * @param int $status Id status
  1399. * @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
  1400. * @return string Label of status
  1401. */
  1402. public function LibStatut($status, $mode)
  1403. {
  1404. // phpcs:enable
  1405. global $langs;
  1406. $labelStatus = array(
  1407. 0 => 'ActivityCeased',
  1408. 1 => 'InActivity',
  1409. 4 => 'InActivity',
  1410. 5 => 'ActivityCeased',
  1411. );
  1412. $labelStatusShort = array(
  1413. 0 => 'ActivityCeased',
  1414. 1 => 'InActivity',
  1415. 4 => 'InActivity',
  1416. 5 => 'ActivityCeased',
  1417. );
  1418. $statusType = 'status4';
  1419. if ($status == 0 || $status == 5) {
  1420. $statusType = 'status5';
  1421. }
  1422. $label = $langs->transnoentitiesnoconv($labelStatus[$status]);
  1423. $labelshort = $langs->transnoentitiesnoconv($labelStatusShort[$status]);
  1424. return dolGetStatus($label, $labelshort, '', $statusType, $mode);
  1425. }
  1426. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1427. /**
  1428. * Return translated label of Public or Private
  1429. *
  1430. * @param int $status Type (0 = public, 1 = private)
  1431. * @return string Label translated
  1432. */
  1433. public function LibPubPriv($status)
  1434. {
  1435. // phpcs:enable
  1436. global $langs;
  1437. if ($status == '1') {
  1438. return $langs->trans('ContactPrivate');
  1439. } else {
  1440. return $langs->trans('ContactPublic');
  1441. }
  1442. }
  1443. /**
  1444. * Initialise an instance with random values.
  1445. * Used to build previews or test instances.
  1446. * id must be 0 if object instance is a specimen.
  1447. *
  1448. * @return int >0 if ok
  1449. */
  1450. public function initAsSpecimen()
  1451. {
  1452. // Get first id of existing company and save it into $socid
  1453. $socid = 0;
  1454. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe ORDER BY rowid LIMIT 1";
  1455. $resql = $this->db->query($sql);
  1456. if ($resql) {
  1457. $obj = $this->db->fetch_object($resql);
  1458. if ($obj) {
  1459. $socid = $obj->rowid;
  1460. }
  1461. }
  1462. // Initialise parameters
  1463. $this->id = 0;
  1464. $this->entity = 1;
  1465. $this->specimen = 1;
  1466. $this->lastname = 'DOLIBARR';
  1467. $this->firstname = 'SPECIMEN';
  1468. $this->address = '21 jump street';
  1469. $this->zip = '99999';
  1470. $this->town = 'MyTown';
  1471. $this->country_id = 1;
  1472. $this->country_code = 'FR';
  1473. $this->country = 'France';
  1474. $this->email = 'specimen@specimen.com';
  1475. $this->socialnetworks = array(
  1476. 'skype' => 'tom.hanson',
  1477. );
  1478. $this->phone_pro = '0909090901';
  1479. $this->phone_perso = '0909090902';
  1480. $this->phone_mobile = '0909090903';
  1481. $this->fax = '0909090909';
  1482. $this->note_public = 'This is a comment (public)';
  1483. $this->note_private = 'This is a comment (private)';
  1484. $this->socid = $socid;
  1485. $this->statut = 1;
  1486. return 1;
  1487. }
  1488. /**
  1489. * Change status of a user
  1490. *
  1491. * @param int $status Status to set
  1492. * @return int <0 if KO, 0 if nothing is done, >0 if OK
  1493. */
  1494. public function setstatus($status)
  1495. {
  1496. global $conf, $langs, $user;
  1497. $error = 0;
  1498. // Check parameters
  1499. if ($this->statut == $status) {
  1500. return 0;
  1501. } else {
  1502. $this->statut = $status;
  1503. }
  1504. $this->db->begin();
  1505. // Desactive utilisateur
  1506. $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople";
  1507. $sql .= " SET statut = ".((int) $this->statut);
  1508. $sql .= " WHERE rowid = ".((int) $this->id);
  1509. $result = $this->db->query($sql);
  1510. dol_syslog(get_class($this)."::setstatus", LOG_DEBUG);
  1511. if ($result) {
  1512. // Call trigger
  1513. $result = $this->call_trigger('CONTACT_ENABLEDISABLE', $user);
  1514. if ($result < 0) {
  1515. $error++;
  1516. }
  1517. // End call triggers
  1518. }
  1519. if ($error) {
  1520. $this->db->rollback();
  1521. return -$error;
  1522. } else {
  1523. $this->db->commit();
  1524. return 1;
  1525. }
  1526. }
  1527. /**
  1528. * Sets object to supplied categories.
  1529. *
  1530. * Deletes object from existing categories not supplied.
  1531. * Adds it to non existing supplied categories.
  1532. * Existing categories are left untouch.
  1533. *
  1534. * @param int[]|int $categories Category or categories IDs
  1535. * @return int <0 if KO, >0 if OK
  1536. */
  1537. public function setCategories($categories)
  1538. {
  1539. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1540. return parent::setCategoriesCommon($categories, Categorie::TYPE_CONTACT);
  1541. }
  1542. /**
  1543. * Function used to replace a thirdparty id with another one.
  1544. *
  1545. * @param DoliDB $dbs Database handler, because function is static we name it $dbs not $db to avoid breaking coding test
  1546. * @param int $origin_id Old thirdparty id
  1547. * @param int $dest_id New thirdparty id
  1548. * @return bool
  1549. */
  1550. public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
  1551. {
  1552. $tables = array(
  1553. 'socpeople', 'societe_contacts'
  1554. );
  1555. return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
  1556. }
  1557. /**
  1558. * Fetch roles (default contact of some companies) for the current contact.
  1559. * This load the array ->roles.
  1560. *
  1561. * @return int <0 if KO, Nb of roles found if OK
  1562. * @see updateRoles()
  1563. */
  1564. public function fetchRoles()
  1565. {
  1566. global $langs;
  1567. $error = 0;
  1568. $num = 0;
  1569. $sql = "SELECT tc.rowid, tc.element, tc.source, tc.code, tc.libelle as label, sc.rowid as contactroleid, sc.fk_soc as socid";
  1570. $sql .= " FROM ".MAIN_DB_PREFIX."societe_contacts as sc, ".MAIN_DB_PREFIX."c_type_contact as tc";
  1571. $sql .= " WHERE tc.rowid = sc.fk_c_type_contact";
  1572. $sql .= " AND tc.source = 'external' AND tc.active=1";
  1573. $sql .= " AND sc.fk_socpeople = ".((int) $this->id);
  1574. $sql .= " AND sc.entity IN (".getEntity('societe').')';
  1575. $resql = $this->db->query($sql);
  1576. if ($resql) {
  1577. $this->roles = array();
  1578. $num = $this->db->num_rows($resql);
  1579. if ($num > 0) {
  1580. while ($obj = $this->db->fetch_object($resql)) {
  1581. $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
  1582. $libelle_element = $langs->trans('ContactDefault_'.$obj->element);
  1583. $this->roles[$obj->contactroleid] = array('id'=>$obj->rowid, 'socid'=>$obj->socid, 'element'=>$obj->element, 'source'=>$obj->source, 'code'=>$obj->code, 'label'=>$libelle_element.' - '.($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->label));
  1584. }
  1585. }
  1586. } else {
  1587. $error++;
  1588. $this->error = $this->db->lasterror();
  1589. $this->errors[] = $this->db->lasterror();
  1590. }
  1591. if (empty($error)) {
  1592. return $num;
  1593. } else {
  1594. return $error * -1;
  1595. }
  1596. }
  1597. /**
  1598. * Get thirdparty contact roles of a given contact
  1599. *
  1600. * @param string $element Element type
  1601. * @return array|int Array of contact roles or -1
  1602. * @throws Exception
  1603. */
  1604. public function getContactRoles($element = '')
  1605. {
  1606. $tab = array();
  1607. if ($element == 'action') {
  1608. $element = 'agenda';
  1609. }
  1610. $sql = "SELECT sc.fk_socpeople as id, sc.fk_c_type_contact";
  1611. $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
  1612. $sql .= ", ".MAIN_DB_PREFIX."societe_contacts sc";
  1613. $sql .= " INNER JOIN ".MAIN_DB_PREFIX."socpeople sp";
  1614. $sql .= " ON sc.fk_socpeople = sp.rowid AND sp.statut = 1";
  1615. $sql .= " WHERE sc.fk_soc =".((int) $this->socid);
  1616. $sql .= " AND sc.fk_c_type_contact=tc.rowid";
  1617. $sql .= " AND tc.element = '".$this->db->escape($element)."'";
  1618. $sql .= " AND tc.active = 1";
  1619. dol_syslog(__METHOD__, LOG_DEBUG);
  1620. $resql = $this->db->query($sql);
  1621. if ($resql) {
  1622. $num = $this->db->num_rows($resql);
  1623. $i = 0;
  1624. while ($i < $num) {
  1625. $obj = $this->db->fetch_object($resql);
  1626. $tab[] = array('fk_socpeople'=>$obj->id, 'type_contact'=>$obj->fk_c_type_contact);
  1627. $i++;
  1628. }
  1629. return $tab;
  1630. } else {
  1631. $this->error = $this->db->error();
  1632. dol_print_error($this->db);
  1633. return -1;
  1634. }
  1635. }
  1636. /**
  1637. * Updates all roles (default contact for companies) according to values inside the ->roles array.
  1638. * This is called by update of contact.
  1639. *
  1640. * @return int
  1641. * @see fetchRoles()
  1642. */
  1643. public function updateRoles()
  1644. {
  1645. global $conf;
  1646. $error = 0;
  1647. if (!isset($this->roles)) {
  1648. return 0; // Avoid to loose roles when property not set
  1649. }
  1650. $this->db->begin();
  1651. $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_contacts WHERE fk_socpeople=".((int) $this->id)." AND entity IN (".getEntity("contact").")";
  1652. $result = $this->db->query($sql);
  1653. if (!$result) {
  1654. $this->errors[] = $this->db->lasterror().' sql='.$sql;
  1655. $error++;
  1656. } else {
  1657. if (count($this->roles) > 0) {
  1658. foreach ($this->roles as $keyRoles => $valRoles) {
  1659. $idrole = 0;
  1660. if (is_array($valRoles)) {
  1661. $idrole = $valRoles['id'];
  1662. } else {
  1663. $idrole = $valRoles;
  1664. }
  1665. $socid = 0;
  1666. if (is_array($valRoles)) {
  1667. $socid = $valRoles['socid'];
  1668. } else {
  1669. $socid = $this->socid;
  1670. }
  1671. if ($socid > 0) {
  1672. $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_contacts";
  1673. $sql .= " (entity,";
  1674. $sql .= "date_creation,";
  1675. $sql .= "fk_soc,";
  1676. $sql .= "fk_c_type_contact,";
  1677. $sql .= "fk_socpeople) ";
  1678. $sql .= " VALUES (".$conf->entity.",";
  1679. $sql .= "'".$this->db->idate(dol_now())."',";
  1680. $sql .= $socid.", ";
  1681. $sql .= $idrole." , ";
  1682. $sql .= $this->id;
  1683. $sql .= ")";
  1684. $result = $this->db->query($sql);
  1685. if (!$result) {
  1686. $this->errors[] = $this->db->lasterror().' sql='.$sql;
  1687. $error++;
  1688. }
  1689. }
  1690. }
  1691. }
  1692. }
  1693. if (empty($error)) {
  1694. $this->db->commit();
  1695. return 1;
  1696. } else {
  1697. $this->error = implode(' ', $this->errors);
  1698. $this->db->rollback();
  1699. return $error * -1;
  1700. }
  1701. }
  1702. /**
  1703. * Load array of prospect status
  1704. *
  1705. * @param int $active 1=Active only, 0=Not active only, -1=All
  1706. * @return int <0 if KO, >0 if OK
  1707. */
  1708. public function loadCacheOfProspStatus($active = 1)
  1709. {
  1710. global $langs;
  1711. $sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcommcontact";
  1712. if ($active >= 0) {
  1713. $sql .= " WHERE active = ".((int) $active);
  1714. }
  1715. $resql = $this->db->query($sql);
  1716. $num = $this->db->num_rows($resql);
  1717. $i = 0;
  1718. while ($i < $num) {
  1719. $obj = $this->db->fetch_object($resql);
  1720. $this->cacheprospectstatus[$obj->id] = array('id' => $obj->id, 'code' => $obj->code, 'label' => ($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto' => $obj->picto);
  1721. $i++;
  1722. }
  1723. return 1;
  1724. }
  1725. /**
  1726. * Return prostect level
  1727. *
  1728. * @return string Libelle
  1729. */
  1730. public function getLibProspLevel()
  1731. {
  1732. return $this->libProspLevel($this->fk_prospectlevel);
  1733. }
  1734. /**
  1735. * Return label of prospect level
  1736. *
  1737. * @param int $fk_prospectlevel Prospect level
  1738. * @return string label of level
  1739. */
  1740. public function libProspLevel($fk_prospectlevel)
  1741. {
  1742. global $langs;
  1743. $lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
  1744. // If lib not found in language file, we get label from cache/databse
  1745. if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel)) {
  1746. $lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
  1747. }
  1748. return $lib;
  1749. }
  1750. /**
  1751. * Set prospect level
  1752. *
  1753. * @param User $user Utilisateur qui definie la remise
  1754. * @return int <0 if KO, >0 if OK
  1755. * @deprecated Use update function instead
  1756. */
  1757. public function setProspectLevel(User $user)
  1758. {
  1759. return $this->update($this->id, $user);
  1760. }
  1761. /**
  1762. * Return status of prospect
  1763. *
  1764. * @param int $mode 0=label long, 1=label short, 2=Picto + Label short, 3=Picto, 4=Picto + Label long
  1765. * @param string $label Label to use for status for added status
  1766. * @return string Label
  1767. */
  1768. public function getLibProspCommStatut($mode = 0, $label = '')
  1769. {
  1770. return $this->libProspCommStatut($this->stcomm_id, $mode, $label, $this->stcomm_picto);
  1771. }
  1772. /**
  1773. * Return label of a given status
  1774. *
  1775. * @param int|string $statut Id or code for prospection status
  1776. * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
  1777. * @param string $label Label to use for status for added status
  1778. * @param string $picto Name of image file to show ('filenew', ...)
  1779. * If no extension provided, we use '.png'. Image must be stored into theme/xxx/img directory.
  1780. * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img
  1781. * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img
  1782. * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1)
  1783. * @return string Label of status
  1784. */
  1785. public function libProspCommStatut($statut, $mode = 0, $label = '', $picto = '')
  1786. {
  1787. global $langs;
  1788. $langs->load('customers');
  1789. if ($mode == 2) {
  1790. if ($statut == '-1' || $statut == 'ST_NO') {
  1791. return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
  1792. } elseif ($statut == '0' || $statut == 'ST_NEVER') {
  1793. return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
  1794. } elseif ($statut == '1' || $statut == 'ST_TODO') {
  1795. return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
  1796. } elseif ($statut == '2' || $statut == 'ST_PEND') {
  1797. return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
  1798. } elseif ($statut == '3' || $statut == 'ST_DONE') {
  1799. return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
  1800. } else {
  1801. return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
  1802. }
  1803. }
  1804. if ($mode == 3) {
  1805. if ($statut == '-1' || $statut == 'ST_NO') {
  1806. return img_action($langs->trans("StatusProspect-1"), -1, $picto);
  1807. } elseif ($statut == '0' || $statut == 'ST_NEVER') {
  1808. return img_action($langs->trans("StatusProspect0"), 0, $picto);
  1809. } elseif ($statut == '1' || $statut == 'ST_TODO') {
  1810. return img_action($langs->trans("StatusProspect1"), 1, $picto);
  1811. } elseif ($statut == '2' || $statut == 'ST_PEND') {
  1812. return img_action($langs->trans("StatusProspect2"), 2, $picto);
  1813. } elseif ($statut == '3' || $statut == 'ST_DONE') {
  1814. return img_action($langs->trans("StatusProspect3"), 3, $picto);
  1815. } else {
  1816. return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto);
  1817. }
  1818. }
  1819. if ($mode == 4) {
  1820. if ($statut == '-1' || $statut == 'ST_NO') {
  1821. return img_action($langs->trans("StatusProspect-1"), -1, $picto).' '.$langs->trans("StatusProspect-1");
  1822. } elseif ($statut == '0' || $statut == 'ST_NEVER') {
  1823. return img_action($langs->trans("StatusProspect0"), 0, $picto).' '.$langs->trans("StatusProspect0");
  1824. } elseif ($statut == '1' || $statut == 'ST_TODO') {
  1825. return img_action($langs->trans("StatusProspect1"), 1, $picto).' '.$langs->trans("StatusProspect1");
  1826. } elseif ($statut == '2' || $statut == 'ST_PEND') {
  1827. return img_action($langs->trans("StatusProspect2"), 2, $picto).' '.$langs->trans("StatusProspect2");
  1828. } elseif ($statut == '3' || $statut == 'ST_DONE') {
  1829. return img_action($langs->trans("StatusProspect3"), 3, $picto).' '.$langs->trans("StatusProspect3");
  1830. } else {
  1831. return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0, $picto).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
  1832. }
  1833. }
  1834. return "Error, mode/status not found";
  1835. }
  1836. /**
  1837. * Set "blacklist" mailing status
  1838. *
  1839. * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling
  1840. * @return int <0 if KO, >0 if OK
  1841. */
  1842. public function setNoEmail($no_email)
  1843. {
  1844. $error = 0;
  1845. // Update mass emailing flag into table mailing_unsubscribe
  1846. if ($this->email) {
  1847. $this->db->begin();
  1848. if ($no_email) {
  1849. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing', 0).") AND email = '".$this->db->escape($this->email)."'";
  1850. $resql = $this->db->query($sql);
  1851. if ($resql) {
  1852. $obj = $this->db->fetch_object($resql);
  1853. $noemail = $obj->nb;
  1854. if (empty($noemail)) {
  1855. $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe(email, entity, date_creat) VALUES ('".$this->db->escape($this->email)."', ".getEntity('mailing', 0).", '".$this->db->idate(dol_now())."')";
  1856. $resql = $this->db->query($sql);
  1857. if (!$resql) {
  1858. $error++;
  1859. $this->error = $this->db->lasterror();
  1860. $this->errors[] = $this->error;
  1861. }
  1862. }
  1863. } else {
  1864. $error++;
  1865. $this->error = $this->db->lasterror();
  1866. $this->errors[] = $this->error;
  1867. }
  1868. } else {
  1869. $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = '".$this->db->escape($this->email)."' AND entity IN (".getEntity('mailing', 0).")";
  1870. $resql = $this->db->query($sql);
  1871. if (!$resql) {
  1872. $error++;
  1873. $this->error = $this->db->lasterror();
  1874. $this->errors[] = $this->error;
  1875. }
  1876. }
  1877. if (empty($error)) {
  1878. $this->no_email = $no_email;
  1879. $this->db->commit();
  1880. return 1;
  1881. } else {
  1882. $this->db->rollback();
  1883. return $error * -1;
  1884. }
  1885. }
  1886. return 0;
  1887. }
  1888. /**
  1889. * get "blacklist" mailing status
  1890. * set no_email attribut to 1 or 0
  1891. *
  1892. * @return int <0 if KO, >0 if OK
  1893. */
  1894. public function getNoEmail()
  1895. {
  1896. if ($this->email) {
  1897. $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE entity IN (".getEntity('mailing').") AND email = '".$this->db->escape($this->email)."'";
  1898. $resql = $this->db->query($sql);
  1899. if ($resql) {
  1900. $obj = $this->db->fetch_object($resql);
  1901. $this->no_email = $obj->nb;
  1902. return 1;
  1903. } else {
  1904. $this->error = $this->db->lasterror();
  1905. $this->errors[] = $this->error;
  1906. return -1;
  1907. }
  1908. }
  1909. return 0;
  1910. }
  1911. /**
  1912. * Return clicable link of object (with eventually picto)
  1913. *
  1914. * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link)
  1915. * @param array $arraydata Array of data
  1916. * @return string HTML Code for Kanban thumb.
  1917. */
  1918. public function getKanbanView($option = '', $arraydata = null)
  1919. {
  1920. global $langs;
  1921. $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
  1922. $return = '<div class="box-flex-item box-flex-grow-zero">';
  1923. $return .= '<div class="info-box info-box-sm">';
  1924. $return .= '<span class="info-box-icon bg-infobox-action">';
  1925. //var_dump($this->photo);exit;
  1926. if (property_exists($this, 'photo') && !is_null($this->photo)) {
  1927. $return.= Form::showphoto('contact', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1);
  1928. } else {
  1929. $return .= img_picto('', $this->picto);
  1930. }
  1931. $return .= '</span>';
  1932. $return .= '<div class="info-box-content">';
  1933. $return .= '<div class="info-box-ref">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</div>';
  1934. $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1935. if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) {
  1936. $return .= '<div class="info-box-ref opacitymedium tdoverflowmax150">'.$this->thirdparty->getNomUrl(1).'</div>';
  1937. }
  1938. /*if (property_exists($this, 'phone_pro') && !empty($this->phone_pro)) {
  1939. $return .= '<br>'.img_picto($langs->trans("Phone"), 'phone');
  1940. $return .= ' <span class="info-box-label">'.$this->phone_pro.'</span>';
  1941. }*/
  1942. /*if (method_exists($this, 'LibPubPriv')) {
  1943. $return .= '<br><span class="info-box-label opacitymedium">'.$langs->trans("Visibility").'</span>';
  1944. $return .= '<span> : '.$this->LibPubPriv($this->priv).'</span>';
  1945. }*/
  1946. if (method_exists($this, 'getLibStatut')) {
  1947. $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
  1948. }
  1949. $return .= '</div>';
  1950. $return .= '</div>';
  1951. $return .= '</div>';
  1952. return $return;
  1953. }
  1954. }