html.form.class.php 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662
  1. <?php
  2. /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  7. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  9. * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
  10. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
  11. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  12. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  13. * Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
  14. * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/core/class/html.form.class.php
  31. * \ingroup core
  32. * \brief File of class with all html predefined components
  33. */
  34. /**
  35. * \class Form
  36. * \brief Class to manage generation of HTML components
  37. * \remarks Only common components must be here.
  38. */
  39. class Form
  40. {
  41. var $db;
  42. var $error;
  43. // Cache arrays
  44. var $cache_types_paiements=array();
  45. var $cache_conditions_paiements=array();
  46. var $cache_availability=array();
  47. var $cache_demand_reason=array();
  48. var $tva_taux_value;
  49. var $tva_taux_libelle;
  50. /**
  51. * Constructor
  52. *
  53. * @param DoliDB $DB Database handler
  54. */
  55. function Form($DB)
  56. {
  57. $this->db = $DB;
  58. }
  59. /**
  60. * Output key field for an editable field
  61. *
  62. * @param string $text Text of label
  63. * @param string $htmlname Name of select field
  64. * @param string $preselected Preselected value for parameter
  65. * @param string $paramkey Key of parameter (unique if there is several parameter to show)
  66. * @param string $paramvalue Value of parameter
  67. * @param boolean $perm Permission to allow button to edit parameter
  68. * @param string $typeofdata Type of data (string by default, email, ...)
  69. * @return string HTML edit field
  70. * TODO no GET or POST in class file, use a param
  71. */
  72. function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
  73. {
  74. global $langs;
  75. $ret='';
  76. $ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
  77. $ret.=$langs->trans($text);
  78. $ret.='</td>';
  79. if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
  80. $ret.='</tr></table>';
  81. return $ret;
  82. }
  83. /**
  84. * Output val field for an editable field
  85. *
  86. * @param string $text Text of label (not used in this function)
  87. * @param string $htmlname Name of select field
  88. * @param string $preselected Preselected value for parameter
  89. * @param string $paramkey Key of parameter (unique if there is several parameter to show)
  90. * @param boolean $perm Permission to allow button to edit parameter
  91. * @param string $typeofdata Type of data ('string' by default, 'email', 'text', 'day', ...)
  92. * @param string $editvalue Use this value instead $preselected
  93. * @return string HTML edit field
  94. * TODO no GET or POST in class file, use a param
  95. */
  96. function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
  97. {
  98. global $langs,$db;
  99. $ret='';
  100. if (GETPOST('action') == 'edit'.$htmlname)
  101. {
  102. $ret.="\n";
  103. $ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  104. $ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
  105. $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  106. $ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
  107. $ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  108. $ret.='<tr><td>';
  109. if (in_array($typeofdata,array('string','email')))
  110. {
  111. $ret.='<input type="text" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$preselected).'">';
  112. }
  113. else if ($typeofdata == 'text')
  114. {
  115. $ret.='<textarea name="'.$htmlname.'">'.($editvalue?$editvalue:$preselected).'</textarea>';
  116. }
  117. else if ($typeofdata == 'day')
  118. {
  119. $html=new Form($db);
  120. $ret.=$html->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$preselected,$htmlname);
  121. }
  122. $ret.='</td>';
  123. if ($typeofdata != 'day') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  124. $ret.='</tr></table>'."\n";
  125. $ret.='</form>'."\n";
  126. }
  127. else
  128. {
  129. if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
  130. if ($typeofdata == 'day') $ret.=dol_print_date($preselected,'day');
  131. else $ret.=$preselected;
  132. }
  133. return $ret;
  134. }
  135. /**
  136. * Show a text and picto with tooltip on text or picto
  137. *
  138. * @param text Text to show
  139. * @param htmltext Content html of tooltip. Must be HTML/UTF8 encoded.
  140. * @param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2
  141. * @param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apres
  142. * @param img Code img du picto (use img_xxx() function to get it)
  143. * @param extracss Add a CSS style to td tags
  144. * @param notabs Do not include table and tr tags
  145. * @param incbefore Include code before the text
  146. * @param noencodehtmltext Do not encode into html entity the htmltext
  147. * @return string Code html du tooltip (texte+picto)
  148. * @see Use function textwithpicto if you can.
  149. */
  150. function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$extracss='',$notabs=0,$incbefore='',$noencodehtmltext=0)
  151. {
  152. global $conf;
  153. if ($incbefore) $text = $incbefore.$text;
  154. if (! $htmltext) return $text;
  155. // Sanitize tooltip
  156. $htmltext=str_replace("\\","\\\\",$htmltext);
  157. $htmltext=str_replace("\r","",$htmltext);
  158. $htmltext=str_replace("\n","",$htmltext);
  159. $htmltext=str_replace('"',"&quot;",$htmltext);
  160. if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip
  161. else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
  162. if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip
  163. else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
  164. $s="";
  165. if (empty($notabs)) $s.='<table class="nobordernopadding" summary=""><tr>';
  166. if ($direction > 0)
  167. {
  168. if ($text != '')
  169. {
  170. $s.='<td'.$paramfortooltiptd.'>'.$text;
  171. if ($direction) $s.='&nbsp;';
  172. $s.='</td>';
  173. }
  174. if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
  175. }
  176. else
  177. {
  178. if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
  179. if ($text != '')
  180. {
  181. $s.='<td'.$paramfortooltiptd.'>';
  182. if ($direction) $s.='&nbsp;';
  183. $s.=$text.'</td>';
  184. }
  185. }
  186. if (empty($notabs)) $s.='</tr></table>';
  187. return $s;
  188. }
  189. /**
  190. * Show a text with a picto and a tooltip on picto
  191. *
  192. * @param text Text to show
  193. * @param htmltooltip Content of tooltip
  194. * @param direction 1=Icon is after text, -1=Icon is before text, 0=no icon
  195. * @param type Type of picto (info, help, warning, superadmin...)
  196. * @param extracss Add a CSS style to td tags
  197. * @param noencodehtmltext Do not encode into html entity the htmltext
  198. * @return string HTML code of text, picto, tooltip
  199. */
  200. function textwithpicto($text,$htmltext,$direction=1,$type='help',$extracss='',$noencodehtmltext=0)
  201. {
  202. global $conf;
  203. if ("$type" == "0") $type='info'; // For backward compatibility
  204. $alt='';
  205. // If info or help with no javascript, show only text
  206. if (empty($conf->use_javascript_ajax))
  207. {
  208. if ($type == 'info' || $type == 'help') return $text;
  209. else { $alt=$htmltext; $htmltext=''; }
  210. }
  211. // If info or help with smartphone, show only text
  212. if (! empty($conf->browser->phone))
  213. {
  214. if ($type == 'info' || $type == 'help') return $text;
  215. }
  216. // Info or help
  217. if ($type == 'info') $img=img_help(0,$alt);
  218. if ($type == 'help' || $type ==1) $img=img_help(1,$alt);
  219. if ($type == 'superadmin') $img=img_picto($alt,"redstar");
  220. if ($type == 'admin') $img=img_picto($alt,"star");
  221. // Warnings
  222. if ($type == 'warning') $img=img_warning($alt);
  223. return $this->textwithtooltip($text,$htmltext,2,$direction,$img,$extracss,0,'',$noencodehtmltext);
  224. }
  225. /**
  226. * Return combo list of activated countries, into language of user
  227. *
  228. * @param selected Id or Code or Label of preselected country
  229. * @param htmlname Name of html select object
  230. * @param htmloption Options html on select object
  231. */
  232. function select_pays($selected='',$htmlname='pays_id',$htmloption='')
  233. {
  234. print $this->select_country($selected,$htmlname,$htmloption);
  235. }
  236. /**
  237. * Return combo list of activated countries, into language of user
  238. *
  239. * @param selected Id or Code or Label of preselected country
  240. * @param htmlname Name of html select object
  241. * @param htmloption Options html on select object
  242. * @return string HTML string with select
  243. */
  244. function select_country($selected='',$htmlname='pays_id',$htmloption='')
  245. {
  246. global $conf,$langs;
  247. $langs->load("dict");
  248. $out='';
  249. $countryArray=array();
  250. $label=array();
  251. $sql = "SELECT rowid, code as code_iso, libelle as label";
  252. $sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
  253. $sql.= " WHERE active = 1";
  254. $sql.= " ORDER BY code ASC";
  255. dol_syslog("Form::select_country sql=".$sql);
  256. $resql=$this->db->query($sql);
  257. if ($resql)
  258. {
  259. $out.= '<select id="select'.$htmlname.'" class="flat selectpays" name="'.$htmlname.'" '.$htmloption.'>';
  260. $num = $this->db->num_rows($resql);
  261. $i = 0;
  262. if ($num)
  263. {
  264. $foundselected=false;
  265. while ($i < $num)
  266. {
  267. $obj = $this->db->fetch_object($resql);
  268. $countryArray[$i]['rowid'] = $obj->rowid;
  269. $countryArray[$i]['code_iso'] = $obj->code_iso;
  270. $countryArray[$i]['label'] = ($obj->code_iso && $langs->trans("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->trans("Country".$obj->code_iso):($obj->label!='-'?$obj->label:''));
  271. $label[$i] = $countryArray[$i]['label'];
  272. $i++;
  273. }
  274. array_multisort($label, SORT_ASC, $countryArray);
  275. foreach ($countryArray as $row)
  276. {
  277. if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) ) {
  278. $foundselected=true;
  279. $out.= '<option value="'.$row['rowid'].'" selected="selected">';
  280. } else {
  281. $out.= '<option value="'.$row['rowid'].'">';
  282. }
  283. $out.= $row['label'];
  284. if ($row['code_iso']) $out.= ' ('.$row['code_iso'] . ')';
  285. $out.= '</option>';
  286. }
  287. }
  288. $out.= '</select>';
  289. }
  290. else
  291. {
  292. dol_print_error($this->db);
  293. }
  294. return $out;
  295. }
  296. /**
  297. * Retourne la liste des types de comptes financiers
  298. *
  299. * @param selected Type pre-selectionne
  300. * @param htmlname Nom champ formulaire
  301. */
  302. function select_type_comptes_financiers($selected=1,$htmlname='type')
  303. {
  304. global $langs;
  305. $langs->load("banks");
  306. $type_available=array(0,1,2);
  307. print '<select class="flat" name="'.$htmlname.'">';
  308. $num = count($type_available);
  309. $i = 0;
  310. if ($num)
  311. {
  312. while ($i < $num)
  313. {
  314. if ($selected == $type_available[$i])
  315. {
  316. print '<option value="'.$type_available[$i].'" selected="selected">'.$langs->trans("BankType".$type_available[$i]).'</option>';
  317. }
  318. else
  319. {
  320. print '<option value="'.$type_available[$i].'">'.$langs->trans("BankType".$type_available[$i]).'</option>';
  321. }
  322. $i++;
  323. }
  324. }
  325. print '</select>';
  326. }
  327. /**
  328. * Return list of social contributions.
  329. * Use mysoc->pays_id or mysoc->pays_code so they must be defined.
  330. *
  331. * @param selected Preselected type
  332. * @param htmlname Name of field in form
  333. * @param useempty Set to 1 if we want an empty value
  334. * @param maxlen Max length of text in combo box
  335. * @param help Add or not the admin help picto
  336. */
  337. function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
  338. {
  339. global $db,$langs,$user,$mysoc;
  340. if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
  341. {
  342. dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
  343. exit;
  344. }
  345. if (! empty($mysoc->pays_id))
  346. {
  347. $sql = "SELECT c.id, c.libelle as type";
  348. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
  349. $sql.= " WHERE c.active = 1";
  350. $sql.= " AND c.fk_pays = ".$mysoc->pays_id;
  351. $sql.= " ORDER BY c.libelle ASC";
  352. }
  353. else
  354. {
  355. $sql = "SELECT c.id, c.libelle as type";
  356. $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
  357. $sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
  358. $sql.= " AND p.code = '".$mysoc->pays_code."'";
  359. $sql.= " ORDER BY c.libelle ASC";
  360. }
  361. dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
  362. $resql=$db->query($sql);
  363. if ($resql)
  364. {
  365. $num = $db->num_rows($resql);
  366. if ($num)
  367. {
  368. print '<select class="flat" name="'.$htmlname.'">';
  369. $i = 0;
  370. if ($useempty) print '<option value="0">&nbsp;</option>';
  371. while ($i < $num)
  372. {
  373. $obj = $db->fetch_object($resql);
  374. print '<option value="'.$obj->id.'"';
  375. if ($obj->id == $selected) print ' selected="selected"';
  376. print '>'.dol_trunc($obj->type,$maxlen);
  377. $i++;
  378. }
  379. print '</select>';
  380. if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  381. }
  382. else
  383. {
  384. print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->pays_code);
  385. }
  386. }
  387. else
  388. {
  389. dol_print_error($db,$db->lasterror());
  390. }
  391. }
  392. /**
  393. * Return list of types of lines (product or service)
  394. * Example: 0=product, 1=service, 9=other (for external module)
  395. *
  396. * @param selected Preselected type
  397. * @param htmlname Name of field in html form
  398. * @param showempty Add an empty field
  399. * @param hidetext Do not show label before combo box
  400. * @param forceall Force to show products and services in combo list, whatever are activated modules
  401. */
  402. function select_type_of_lines($selected='',$htmlname='type',$showempty=0,$hidetext=0,$forceall=0)
  403. {
  404. global $db,$langs,$user,$conf;
  405. // If product & services are enabled or both disabled.
  406. if ($forceall || ($conf->product->enabled && $conf->service->enabled)
  407. || (empty($conf->product->enabled) && empty($conf->service->enabled)))
  408. {
  409. if (empty($hidetext)) print $langs->trans("Type").': ';
  410. print '<select class="flat" name="'.$htmlname.'">';
  411. if ($showempty)
  412. {
  413. print '<option value="-1"';
  414. if ($selected == -1) print ' selected="selected"';
  415. print '>&nbsp;</option>';
  416. }
  417. print '<option value="0"';
  418. if (0 == $selected) print ' selected="selected"';
  419. print '>'.$langs->trans("Product");
  420. print '<option value="1"';
  421. if (1 == $selected) print ' selected="selected"';
  422. print '>'.$langs->trans("Service");
  423. print '</select>';
  424. //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  425. }
  426. if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled)
  427. {
  428. print '<input type="hidden" name="'.$htmlname.'" value="1">';
  429. }
  430. if (! $forceall && $conf->product->enabled && empty($conf->service->enabled))
  431. {
  432. print '<input type="hidden" name="'.$htmlname.'" value="0">';
  433. }
  434. }
  435. /**
  436. * Return list of types of notes
  437. *
  438. * @param selected Preselected type
  439. * @param htmlname Name of field in form
  440. * @param showempty Add an empty field
  441. */
  442. function select_type_fees($selected='',$htmlname='type',$showempty=0)
  443. {
  444. global $db,$langs,$user;
  445. $langs->load("trips");
  446. print '<select class="flat" name="'.$htmlname.'">';
  447. if ($showempty)
  448. {
  449. print '<option value="-1"';
  450. if ($selected == -1) print ' selected="selected"';
  451. print '>&nbsp;</option>';
  452. }
  453. $sql = "SELECT c.code, c.libelle as type FROM ".MAIN_DB_PREFIX."c_type_fees as c";
  454. $sql.= " ORDER BY lower(c.libelle) ASC";
  455. $resql=$db->query($sql);
  456. if ($resql)
  457. {
  458. $num = $db->num_rows($resql);
  459. $i = 0;
  460. while ($i < $num)
  461. {
  462. $obj = $db->fetch_object($resql);
  463. print '<option value="'.$obj->code.'"';
  464. if ($obj->code == $selected) print ' selected="selected"';
  465. print '>';
  466. if ($obj->code != $langs->trans($obj->code)) print $langs->trans($obj->code);
  467. else print $langs->trans($obj->type);
  468. $i++;
  469. }
  470. }
  471. print '</select>';
  472. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  473. }
  474. /**
  475. * Output html form to select a third party
  476. *
  477. * @param selected Preselected type
  478. * @param htmlname Name of field in form
  479. * @param filter Optionnal filters criteras
  480. * @param showempty Add an empty field
  481. * @param showtype Show third party type in combolist (customer, prospect or supplier)
  482. * @param forcecombo Force to use combo box
  483. */
  484. function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
  485. {
  486. print $this->select_company($selected,$htmlname,$filter,$showempty,$showtype,$forcecombo);
  487. }
  488. /**
  489. * Output html form to select a third party
  490. *
  491. * @param selected Preselected type
  492. * @param htmlname Name of field in form
  493. * @param filter Optionnal filters criteras
  494. * @param showempty Add an empty field
  495. * @param showtype Show third party type in combolist (customer, prospect or supplier)
  496. * @param forcecombo Force to use combo box
  497. */
  498. function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
  499. {
  500. global $conf,$user,$langs;
  501. $out='';
  502. // On recherche les societes
  503. $sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
  504. $sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
  505. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  506. $sql.= " WHERE s.entity = ".$conf->entity;
  507. if ($filter) $sql.= " AND ".$filter;
  508. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  509. $sql.= " ORDER BY nom ASC";
  510. dol_syslog("Form::select_societes sql=".$sql);
  511. $resql=$this->db->query($sql);
  512. if ($resql)
  513. {
  514. if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
  515. {
  516. //$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
  517. $out.= ajax_combobox($htmlname);
  518. }
  519. $out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
  520. if ($showempty) $out.= '<option value="-1">&nbsp;</option>';
  521. $num = $this->db->num_rows($resql);
  522. $i = 0;
  523. if ($num)
  524. {
  525. while ($i < $num)
  526. {
  527. $obj = $this->db->fetch_object($resql);
  528. $label=$obj->nom;
  529. if ($showtype)
  530. {
  531. if ($obj->client || $obj->fournisseur) $label.=' (';
  532. if ($obj->client == 1 || $obj->client == 3) $label.=$langs->trans("Customer");
  533. if ($obj->client == 2 || $obj->client == 3) $label.=($obj->client==3?', ':'').$langs->trans("Prospect");
  534. if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
  535. if ($obj->client || $obj->fournisseur) $label.=')';
  536. }
  537. if ($selected > 0 && $selected == $obj->rowid)
  538. {
  539. $out.= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
  540. }
  541. else
  542. {
  543. $out.= '<option value="'.$obj->rowid.'">'.$label.'</option>';
  544. }
  545. $i++;
  546. }
  547. }
  548. $out.= '</select>';
  549. }
  550. else
  551. {
  552. dol_print_error($this->db);
  553. }
  554. return $out;
  555. }
  556. /**
  557. * Return HTML combo list of absolute discounts
  558. *
  559. * @param selected Id remise fixe pre-selectionnee
  560. * @param htmlname Nom champ formulaire
  561. * @param filter Criteres optionnels de filtre
  562. * @param maxvalue Max value for lines that can be selected
  563. * @return int Return number of qualifed lines in list
  564. */
  565. function select_remises($selected='',$htmlname='remise_id',$filter='',$socid, $maxvalue=0)
  566. {
  567. global $langs,$conf;
  568. // On recherche les remises
  569. $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
  570. $sql.= " re.description, re.fk_facture_source";
  571. $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
  572. $sql.= " WHERE fk_soc = ".$socid;
  573. if ($filter) $sql.= " AND ".$filter;
  574. $sql.= " ORDER BY re.description ASC";
  575. dol_syslog("Form::select_remises sql=".$sql);
  576. $resql=$this->db->query($sql);
  577. if ($resql)
  578. {
  579. print '<select class="flat" name="'.$htmlname.'">';
  580. $num = $this->db->num_rows($resql);
  581. $qualifiedlines=$num;
  582. $i = 0;
  583. if ($num)
  584. {
  585. print '<option value="0">&nbsp;</option>';
  586. while ($i < $num)
  587. {
  588. $obj = $this->db->fetch_object($resql);
  589. $desc=dol_trunc($obj->description,40);
  590. if ($desc=='(CREDIT_NOTE)') $desc=$langs->trans("CreditNote");
  591. if ($desc=='(DEPOSIT)') $desc=$langs->trans("Deposit");
  592. $selectstring='';
  593. if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected="selected"';
  594. $disabled='';
  595. if ($maxvalue && $obj->amount_ttc > $maxvalue)
  596. {
  597. $qualifiedlines--;
  598. $disabled=' disabled="disabled"';
  599. }
  600. print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
  601. $i++;
  602. }
  603. }
  604. print '</select>';
  605. return $qualifiedlines;
  606. }
  607. else
  608. {
  609. dol_print_error($this->db);
  610. return -1;
  611. }
  612. }
  613. /**
  614. * Return list of all contacts (for a third party or all)
  615. *
  616. * @param socid Id ot third party or 0 for all
  617. * @param selected Id contact pre-selectionne
  618. * @param htmlname Name of HTML field ('none' for a not editable field)
  619. * @param show_empty 0=no empty value, 1=add an empty value
  620. * @param exclude List of contacts id to exclude
  621. * @param limitto Disable answers that are not id in this array list
  622. * @param showfunction Add function into label
  623. * @param moreclass Add more class to class style
  624. * @return int <0 if KO, Nb of contact in list if OK
  625. */
  626. function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='')
  627. {
  628. global $conf,$langs;
  629. // On recherche les societes
  630. $sql = "SELECT s.rowid, s.name, s.firstname, s.poste FROM";
  631. $sql.= " ".MAIN_DB_PREFIX ."socpeople as s";
  632. $sql.= " WHERE entity = ".$conf->entity;
  633. if ($socid > 0) $sql.= " AND fk_soc=".$socid;
  634. $sql.= " ORDER BY s.name ASC";
  635. dol_syslog("Form::select_contacts sql=".$sql);
  636. $resql=$this->db->query($sql);
  637. if ($resql)
  638. {
  639. $num=$this->db->num_rows($resql);
  640. if ($num == 0) return 0;
  641. if ($htmlname != 'none') print '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
  642. if ($showempty) print '<option value="0"></option>';
  643. $num = $this->db->num_rows($resql);
  644. $i = 0;
  645. if ($num)
  646. {
  647. include_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');
  648. $contactstatic=new Contact($this->db);
  649. while ($i < $num)
  650. {
  651. $obj = $this->db->fetch_object($resql);
  652. $contactstatic->id=$obj->rowid;
  653. $contactstatic->name=$obj->name;
  654. $contactstatic->firstname=$obj->firstname;
  655. if ($htmlname != 'none')
  656. {
  657. $disabled=0;
  658. if (is_array($exclude) && count($exclude) && in_array($obj->rowid,$exclude)) $disabled=1;
  659. if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
  660. if ($selected && $selected == $obj->rowid)
  661. {
  662. print '<option value="'.$obj->rowid.'"';
  663. if ($disabled) print ' disabled="disabled"';
  664. print ' selected="selected">';
  665. print $contactstatic->getFullName($langs);
  666. if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
  667. print '</option>';
  668. }
  669. else
  670. {
  671. print '<option value="'.$obj->rowid.'"';
  672. if ($disabled) print ' disabled="disabled"';
  673. print '>';
  674. print $contactstatic->getFullName($langs);
  675. if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
  676. print '</option>';
  677. }
  678. }
  679. else
  680. {
  681. if ($selected == $obj->rowid)
  682. {
  683. print $contactstatic->getFullName($langs);
  684. if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
  685. }
  686. }
  687. $i++;
  688. }
  689. }
  690. if ($htmlname != 'none')
  691. {
  692. print '</select>';
  693. }
  694. return $num;
  695. }
  696. else
  697. {
  698. dol_print_error($this->db);
  699. return -1;
  700. }
  701. }
  702. /**
  703. * Return select list of users
  704. *
  705. * @param selected Id user preselected
  706. * @param htmlname Field name in form
  707. * @param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
  708. * @param exclude Array list of users id to exclude
  709. * @param disabled If select list must be disabled
  710. * @param include Array list of users id to include
  711. * @param enableonly Array list of users id to be enabled. All other must be disabled
  712. * @param force_entity Possibility to force entity
  713. */
  714. function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
  715. {
  716. print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity);
  717. }
  718. /**
  719. * Return select list of users
  720. *
  721. * @param selected User id or user object of user preselected. If -1, we use id of current user.
  722. * @param htmlname Field name in form
  723. * @param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
  724. * @param exclude Array list of users id to exclude
  725. * @param disabled If select list must be disabled
  726. * @param include Array list of users id to include
  727. * @param enableonly Array list of users id to be enabled. All other must be disabled
  728. * @param force_entity Possibility to force entity
  729. */
  730. function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
  731. {
  732. global $conf,$user,$langs;
  733. // If no preselected user defined, we take current user
  734. if ($selected < -1 && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id;
  735. // Permettre l'exclusion d'utilisateurs
  736. if (is_array($exclude)) $excludeUsers = implode("','",$exclude);
  737. // Permettre l'inclusion d'utilisateurs
  738. if (is_array($include)) $includeUsers = implode("','",$include);
  739. $out='';
  740. // On recherche les utilisateurs
  741. $sql = "SELECT u.rowid, u.name, u.firstname, u.login, u.admin, u.entity";
  742. if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
  743. {
  744. $sql.= ", e.label";
  745. }
  746. $sql.= " FROM ".MAIN_DB_PREFIX ."user as u";
  747. if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
  748. {
  749. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."entity as e on e.rowid=u.entity";
  750. if ($force_entity) $sql.= " WHERE u.entity IN (0,".$force_entity.")";
  751. else $sql.= " WHERE u.entity IS NOT NULL";
  752. }
  753. else
  754. {
  755. $sql.= " WHERE u.entity IN (0,".$conf->entity.")";
  756. }
  757. if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')";
  758. if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')";
  759. $sql.= " ORDER BY u.name ASC";
  760. dol_syslog("Form::select_dolusers sql=".$sql);
  761. $resql=$this->db->query($sql);
  762. if ($resql)
  763. {
  764. $num = $this->db->num_rows($resql);
  765. $i = 0;
  766. if ($num)
  767. {
  768. $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>';
  769. if ($show_empty) $out.= '<option value="-1"'.($id==-1?' selected="selected"':'').'>&nbsp;</option>'."\n";
  770. $userstatic=new User($this->db);
  771. while ($i < $num)
  772. {
  773. $obj = $this->db->fetch_object($resql);
  774. $userstatic->id=$obj->rowid;
  775. $userstatic->nom=$obj->name;
  776. $userstatic->prenom=$obj->firstname;
  777. $disableline=0;
  778. if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
  779. if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
  780. {
  781. $out.= '<option value="'.$obj->rowid.'"';
  782. if ($disableline) $out.= ' disabled="disabled"';
  783. $out.= ' selected="selected">';
  784. }
  785. else
  786. {
  787. $out.= '<option value="'.$obj->rowid.'"';
  788. if ($disableline) $out.= ' disabled="disabled"';
  789. $out.= '>';
  790. }
  791. $out.= $userstatic->getFullName($langs);
  792. if(! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && ! $user->entity)
  793. {
  794. if ($obj->admin && ! $obj->entity) $out.=" (".$langs->trans("AllEntities").")";
  795. else $out.=" (".$obj->label.")";
  796. }
  797. //if ($obj->admin) $out.= ' *';
  798. if ($conf->global->MAIN_SHOW_LOGIN) $out.= ' ('.$obj->login.')';
  799. $out.= '</option>';
  800. $i++;
  801. }
  802. }
  803. else
  804. {
  805. $out.= '<select class="flat" name="'.$htmlname.'" disabled="disabled">';
  806. $out.= '<option value="">'.$langs->trans("EmptyList").'</option>';
  807. }
  808. $out.= '</select>';
  809. }
  810. else
  811. {
  812. dol_print_error($this->db);
  813. }
  814. return $out;
  815. }
  816. /**
  817. * Return list of products for customer in Ajax if Ajax activated or go to select_produits_do
  818. *
  819. * @param int $selected Preselected products
  820. * @param string $htmlname Name of HTML seletc field (must be unique in page)
  821. * @param int $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
  822. * @param int $limit Limit on number of returned lines
  823. * @param int $price_level Level of price to show
  824. * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
  825. * @param int $finished 2=all, 1=finished, 0=raw material
  826. * @param string $selected_input_value Value of preselected input text (with ajax)
  827. * @return void
  828. */
  829. function select_produits($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$status=1,$finished=2,$selected_input_value='',$hidelabel=0)
  830. {
  831. global $langs,$conf;
  832. $price_level = (! empty($price_level) ? $price_level : 0);
  833. if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
  834. {
  835. if ($selected && empty($selected_input_value))
  836. {
  837. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  838. $product = new Product($this->db);
  839. $product->fetch($selected);
  840. $selected_input_value=$product->ref;
  841. }
  842. // mode=1 means customers products
  843. print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajaxproducts.php', 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT);
  844. if (! $hidelabel) print $langs->trans("RefOrLabel").' : ';
  845. print '<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'" />';
  846. }
  847. else
  848. {
  849. $this->select_produits_do($selected,$htmlname,$filtertype,$limit,$price_level,'',$status,$finished,0);
  850. }
  851. print '<br>';
  852. }
  853. /**
  854. * Return list of products for a customer
  855. *
  856. * @param int $selected Preselected product
  857. * @param string $htmlname Name of select html
  858. * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
  859. * @param int $limit Limite sur le nombre de lignes retournees
  860. * @param int $price_level Level of price to show
  861. * @param string $filterkey Filter on product
  862. * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
  863. * @param int $finished Filter on finished field: 2=No filter
  864. * @param int $disableout Disable print output
  865. * @return array Array of keys for json
  866. */
  867. function select_produits_do($selected='',$htmlname='productid',$filtertype='',$limit=20,$price_level=0,$filterkey='',$status=1,$finished=2,$disableout=0)
  868. {
  869. global $langs,$conf,$user,$db;
  870. $sql = "SELECT ";
  871. $sql.= " p.rowid, p.label, p.ref, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.duration, p.stock";
  872. // Multilang : we add translation
  873. if ($conf->global->MAIN_MULTILANGS)
  874. {
  875. $sql.= ", pl.label as label_translated";
  876. }
  877. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  878. // Multilang : we add translation
  879. if ($conf->global->MAIN_MULTILANGS)
  880. {
  881. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='". $langs->getDefaultLang() ."'";
  882. }
  883. $sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
  884. if ($finished == 0)
  885. {
  886. $sql.= " AND p.finished = ".$finished;
  887. }
  888. elseif ($finished == 1)
  889. {
  890. $sql.= " AND p.finished = ".$finished;
  891. if ($status >= 0) $sql.= " AND p.tosell = ".$status;
  892. }
  893. elseif ($status >= 0)
  894. {
  895. $sql.= " AND p.tosell = ".$status;
  896. }
  897. if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
  898. // Add criteria on ref/label
  899. if ($filterkey && $filterkey != '')
  900. {
  901. if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) // Can use index
  902. {
  903. $sql.=" AND (p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%'";
  904. if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '".$filterkey."%'";
  905. $sql.=")";
  906. }
  907. else
  908. {
  909. $sql.=" AND (p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%'";
  910. if ($conf->global->MAIN_MULTILANGS) $sql.=" OR pl.label LIKE '%".$filterkey."%'";
  911. $sql.=")";
  912. }
  913. }
  914. $sql.= $db->order("p.ref");
  915. $sql.= $db->plimit($limit);
  916. // Build output string
  917. $outselect='';
  918. $outjson=array();
  919. dol_syslog("Form::select_produits_do search product sql=".$sql, LOG_DEBUG);
  920. $result=$this->db->query($sql);
  921. if ($result)
  922. {
  923. $num = $this->db->num_rows($result);
  924. $outselect.='<select class="flat" name="'.$htmlname.'">';
  925. $outselect.='<option value="0" selected="selected">&nbsp;</option>';
  926. $i = 0;
  927. while ($num && $i < $num)
  928. {
  929. $outkey='';
  930. $outval='';
  931. $outref='';
  932. $objp = $this->db->fetch_object($result);
  933. $label=$objp->label;
  934. if (! empty($objp->label_translated)) $label=$objp->label_translated;
  935. if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
  936. $outkey=$objp->rowid;
  937. $outref=$objp->ref;
  938. $opt = '<option value="'.$objp->rowid.'"';
  939. $opt.= ($objp->rowid == $selected)?' selected="selected"':'';
  940. if ($conf->stock->enabled && $objp->fk_product_type == 0 && isset($objp->stock))
  941. {
  942. if ($objp->stock > 0)
  943. {
  944. $opt.= ' style="background-color:#32CD32; color:#F5F5F5;"';
  945. }
  946. else if ($objp->stock <= 0)
  947. {
  948. $opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
  949. }
  950. }
  951. $opt.= '>';
  952. $opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - ';
  953. $objRef = $objp->ref;
  954. if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
  955. $outval.=$objRef.' - '.dol_trunc($label,32).' - ';
  956. $found=0;
  957. $currencytext=$langs->trans("Currency".$conf->monnaie);
  958. $currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
  959. if (dol_strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
  960. if (dol_strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
  961. // Multiprice
  962. if ($price_level >= 1) // If we need a particular price level (from 1 to 6)
  963. {
  964. $sql= "SELECT price, price_ttc, price_base_type ";
  965. $sql.= "FROM ".MAIN_DB_PREFIX."product_price ";
  966. $sql.= "WHERE fk_product='".$objp->rowid."'";
  967. $sql.= " AND price_level=".$price_level;
  968. $sql.= " ORDER BY date_price";
  969. $sql.= " DESC limit 1";
  970. dol_syslog("Form::select_produits_do search price for level '.$price_level.' sql=".$sql);
  971. $result2 = $this->db->query($sql);
  972. if ($result2)
  973. {
  974. $objp2 = $this->db->fetch_object($result2);
  975. if ($objp2)
  976. {
  977. $found=1;
  978. if ($objp2->price_base_type == 'HT')
  979. {
  980. $opt.= price($objp2->price,1).' '.$currencytext.' '.$langs->trans("HT");
  981. $outval.= price($objp2->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
  982. }
  983. else
  984. {
  985. $opt.= price($objp2->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
  986. $outval.= price($objp2->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
  987. }
  988. }
  989. }
  990. else
  991. {
  992. dol_print_error($this->db);
  993. }
  994. }
  995. // If level no defined or multiprice not found, we used the default price
  996. if (! $found)
  997. {
  998. if ($objp->price_base_type == 'HT')
  999. {
  1000. $opt.= price($objp->price,1).' '.$currencytext.' '.$langs->trans("HT");
  1001. $outval.= price($objp->price,1).' '.$currencytextnoent.' '.$langs->transnoentities("HT");
  1002. }
  1003. else
  1004. {
  1005. $opt.= price($objp->price_ttc,1).' '.$currencytext.' '.$langs->trans("TTC");
  1006. $outval.= price($objp->price_ttc,1).' '.$currencytextnoent.' '.$langs->transnoentities("TTC");
  1007. }
  1008. }
  1009. if ($conf->stock->enabled && isset($objp->stock) && $objp->fk_product_type == 0)
  1010. {
  1011. $opt.= ' - '.$langs->trans("Stock").':'.$objp->stock;
  1012. $outval.=' - '.$langs->transnoentities("Stock").':'.$objp->stock;
  1013. }
  1014. if ($objp->duration)
  1015. {
  1016. $duration_value = substr($objp->duration,0,dol_strlen($objp->duration)-1);
  1017. $duration_unit = substr($objp->duration,-1);
  1018. if ($duration_value > 1)
  1019. {
  1020. $dur=array("h"=>$langs->trans("Hours"),"d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years"));
  1021. }
  1022. else
  1023. {
  1024. $dur=array("h"=>$langs->trans("Hour"),"d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year"));
  1025. }
  1026. $opt.= ' - '.$duration_value.' '.$langs->trans($dur[$duration_unit]);
  1027. $outval.=' - '.$duration_value.' '.$langs->transnoentities($dur[$duration_unit]);
  1028. }
  1029. $opt.= "</option>\n";
  1030. // Add new entry
  1031. // "key" value of json key array is used by jQuery automatically as selected value
  1032. // "label" value of json key array is used by jQuery automatically as text for combo box
  1033. $outselect.=$opt;
  1034. array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
  1035. $i++;
  1036. }
  1037. $outselect.='</select>';
  1038. $this->db->free($result);
  1039. if (empty($disableout)) print $outselect;
  1040. return $outjson;
  1041. }
  1042. else
  1043. {
  1044. dol_print_error($db);
  1045. }
  1046. }
  1047. /**
  1048. * Return list of products for customer in Ajax if Ajax activated or go to select_produits_fournisseurs_do
  1049. *
  1050. * @param socid Id third party
  1051. * @param selected Preselected product
  1052. * @param htmlname Name of HTML Select
  1053. * @param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
  1054. * @param filtre For a SQL filter
  1055. */
  1056. function select_produits_fournisseurs($socid,$selected='',$htmlname='productid',$filtertype='',$filtre)
  1057. {
  1058. global $langs,$conf;
  1059. if ($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)
  1060. {
  1061. // mode=2 means suppliers products
  1062. print ajax_autocompleter('', $htmlname, DOL_URL_ROOT.'/product/ajaxproducts.php', 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT);
  1063. print $langs->trans("RefOrLabel").' : <input type="text" size="16" name="search_'.$htmlname.'" id="search_'.$htmlname.'">';
  1064. print '<br>';
  1065. }
  1066. else
  1067. {
  1068. $this->select_produits_fournisseurs_do($socid,$selected,$htmlname,$filtertype,$filtre,'',-1,0);
  1069. }
  1070. }
  1071. /**
  1072. * Retourne la liste des produits de fournisseurs
  1073. *
  1074. * @param socid Id societe fournisseur (0 pour aucun filtre)
  1075. * @param selected Produit pre-selectionne
  1076. * @param htmlname Nom de la zone select
  1077. * @param filtertype Filter on product type (''=nofilter, 0=product, 1=service)
  1078. * @param filtre Pour filtre sql
  1079. * @param filterkey Filtre des produits
  1080. * @param status -1=Return all products, 0=Products not on sell, 1=Products on sell
  1081. * @param disableout Disable print output
  1082. * @return array Array of keys for json
  1083. */
  1084. function select_produits_fournisseurs_do($socid,$selected='',$htmlname='productid',$filtertype='',$filtre='',$filterkey='',$statut=-1,$disableout=0)
  1085. {
  1086. global $langs,$conf;
  1087. $langs->load('stocks');
  1088. $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
  1089. $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
  1090. $sql.= " s.nom";
  1091. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  1092. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
  1093. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
  1094. $sql.= " WHERE p.entity = ".$conf->entity;
  1095. $sql.= " AND p.tobuy = 1";
  1096. if ($socid) $sql.= " AND pfp.fk_soc = ".$socid;
  1097. if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
  1098. if (! empty($filtre)) $sql.=" ".$filtre;
  1099. // Add criteria on ref/label
  1100. if ($filterkey && $filterkey != '')
  1101. {
  1102. if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
  1103. {
  1104. $sql.=" AND (pfp.ref_fourn LIKE '".$filterkey."%' OR p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%')";
  1105. }
  1106. else
  1107. {
  1108. $sql.=" AND (pfp.ref_fourn LIKE '%".$filterkey."%' OR p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%')";
  1109. }
  1110. }
  1111. $sql.= " ORDER BY pfp.ref_fourn DESC";
  1112. // Build output string
  1113. $outselect='';
  1114. $outjson=array();
  1115. dol_syslog("Form::select_produits_fournisseurs_do sql=".$sql,LOG_DEBUG);
  1116. $result=$this->db->query($sql);
  1117. if ($result)
  1118. {
  1119. $num = $this->db->num_rows($result);
  1120. $outselect.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">';
  1121. if (! $selected) $outselect.='<option value="0" selected="selected">&nbsp;</option>';
  1122. else $outselect.='<option value="0">&nbsp;</option>';
  1123. $i = 0;
  1124. while ($i < $num)
  1125. {
  1126. $outkey='';
  1127. $outval='';
  1128. $outref='';
  1129. $objp = $this->db->fetch_object($result);
  1130. $outkey=$objp->idprodfournprice;
  1131. $outref=$objp->ref;
  1132. $opt = '<option value="'.$objp->idprodfournprice.'"';
  1133. if ($selected == $objp->idprodfournprice) $opt.= ' selected="selected"';
  1134. if ($objp->fprice == '') $opt.=' disabled="disabled"';
  1135. $opt.= '>';
  1136. $objRef = $objp->ref;
  1137. if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRef,1);
  1138. $objRefFourn = $objp->ref_fourn;
  1139. if ($filterkey && $filterkey != '') $objRefFourn=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$objRefFourn,1);
  1140. $label = $objp->label;
  1141. if ($filterkey && $filterkey != '') $label=preg_replace('/('.preg_quote($filterkey).')/i','<strong>$1</strong>',$label,1);
  1142. $opt.=$langs->convToOutputCharset($objp->ref).' ('.$langs->convToOutputCharset($objp->ref_fourn).') - ';
  1143. $outval.=$objRef.' ('.$objRefFourn.') - ';
  1144. $opt.=$langs->convToOutputCharset(dol_trunc($objp->label,18)).' - ';
  1145. $outval.=dol_trunc($label,18).' - ';
  1146. if ($objp->fprice != '') // Keep != ''
  1147. {
  1148. $currencytext=$langs->trans("Currency".$conf->monnaie);
  1149. $currencytextnoent=$langs->transnoentities("Currency".$conf->monnaie);
  1150. if (dol_strlen($currencytext) > 10) $currencytext=$conf->monnaie; // If text is too long, we use the short code
  1151. if (dol_strlen($currencytextnoent) > 10) $currencytextnoent=$conf->monnaie; // If text is too long, we use the short code
  1152. $opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity;
  1153. $outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity;
  1154. if ($objp->quantity == 1)
  1155. {
  1156. $opt.= strtolower($langs->trans("Unit"));
  1157. $outval.=strtolower($langs->transnoentities("Unit"));
  1158. }
  1159. else
  1160. {
  1161. $opt.= strtolower($langs->trans("Units"));
  1162. $outval.=strtolower($langs->transnoentities("Units"));
  1163. }
  1164. if ($objp->quantity >= 1)
  1165. {
  1166. $opt.=" (".price($objp->unitprice).' '.$currencytext."/".strtolower($langs->trans("Unit")).")";
  1167. $outval.=" (".price($objp->unitprice).' '.$currencytextnoent."/".strtolower($langs->transnoentities("Unit")).")";
  1168. }
  1169. if ($objp->duration)
  1170. {
  1171. $opt .= " - ".$objp->duration;
  1172. $outval.=" - ".$objp->duration;
  1173. }
  1174. if (! $socid)
  1175. {
  1176. $opt .= " - ".dol_trunc($objp->nom,8);
  1177. $outval.=" - ".dol_trunc($objp->nom,8);
  1178. }
  1179. }
  1180. else
  1181. {
  1182. $opt.= $langs->trans("NoPriceDefinedForThisSupplier");
  1183. $outval.=$langs->transnoentities("NoPriceDefinedForThisSupplier");
  1184. }
  1185. $opt .= "</option>\n";
  1186. // Add new entry
  1187. // "key" value of json key array is used by jQuery automatically as selected value
  1188. // "label" value of json key array is used by jQuery automatically as text for combo box
  1189. $outselect.=$opt;
  1190. array_push($outjson,array('key'=>$outkey,'value'=>$outref,'label'=>$outval));
  1191. $i++;
  1192. }
  1193. $outselect.='</select>';
  1194. $this->db->free($result);
  1195. if (empty($disableout)) print $outselect;
  1196. return $outjson;
  1197. }
  1198. else
  1199. {
  1200. dol_print_error($db);
  1201. }
  1202. }
  1203. /**
  1204. * Return list of suppliers prices for a product
  1205. *
  1206. * @param int $productid Id of product
  1207. * @param string $htmlname Name of HTML field
  1208. * @return void
  1209. */
  1210. function select_product_fourn_price($productid,$htmlname='productfournpriceid')
  1211. {
  1212. global $langs,$conf;
  1213. $langs->load('stocks');
  1214. $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
  1215. $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
  1216. $sql.= " s.nom";
  1217. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  1218. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
  1219. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
  1220. $sql.= " WHERE p.entity = ".$conf->entity;
  1221. $sql.= " AND p.tobuy = 1";
  1222. $sql.= " AND s.fournisseur = 1";
  1223. $sql.= " AND p.rowid = ".$productid;
  1224. $sql.= " ORDER BY s.nom, pfp.ref_fourn DESC";
  1225. dol_syslog("Form::select_product_fourn_price sql=".$sql,LOG_DEBUG);
  1226. $result=$this->db->query($sql);
  1227. if ($result)
  1228. {
  1229. $num = $this->db->num_rows($result);
  1230. $form = '<select class="flat" name="'.$htmlname.'">';
  1231. if (! $num)
  1232. {
  1233. $form.= '<option value="0">-- '.$langs->trans("NoSupplierPriceDefinedForThisProduct").' --</option>';
  1234. }
  1235. else
  1236. {
  1237. $form.= '<option value="0">&nbsp;</option>';
  1238. $i = 0;
  1239. while ($i < $num)
  1240. {
  1241. $objp = $this->db->fetch_object($result);
  1242. $opt = '<option value="'.$objp->idprodfournprice.'"';
  1243. $opt.= '>'.$objp->nom.' - '.$objp->ref_fourn.' - ';
  1244. if ($objp->quantity == 1)
  1245. {
  1246. $opt.= price($objp->fprice);
  1247. $opt.= $langs->trans("Currency".$conf->monnaie)."/";
  1248. }
  1249. $opt.= $objp->quantity.' ';
  1250. if ($objp->quantity == 1)
  1251. {
  1252. $opt.= strtolower($langs->trans("Unit"));
  1253. }
  1254. else
  1255. {
  1256. $opt.= strtolower($langs->trans("Units"));
  1257. }
  1258. if ($objp->quantity > 1)
  1259. {
  1260. $opt.=" - ";
  1261. $opt.= price($objp->unitprice).$langs->trans("Currency".$conf->monnaie)."/".strtolower($langs->trans("Unit"));
  1262. }
  1263. if ($objp->duration) $opt .= " - ".$objp->duration;
  1264. $opt .= "</option>\n";
  1265. $form.= $opt;
  1266. $i++;
  1267. }
  1268. $form.= '</select>';
  1269. $this->db->free($result);
  1270. }
  1271. return $form;
  1272. }
  1273. else
  1274. {
  1275. dol_print_error($db);
  1276. }
  1277. }
  1278. /**
  1279. * Return list of delivery address
  1280. *
  1281. * @param string $selected Id contact pre-selectionn
  1282. * @param int $socid Id of company
  1283. * @param string $htmlname Name of HTML field
  1284. * @param int $showempty Add an empty field
  1285. * @return void
  1286. */
  1287. function select_address($selected='', $socid, $htmlname='address_id',$showempty=0)
  1288. {
  1289. // On recherche les utilisateurs
  1290. $sql = "SELECT a.rowid, a.label";
  1291. $sql .= " FROM ".MAIN_DB_PREFIX ."societe_address as a";
  1292. $sql .= " WHERE a.fk_soc = ".$socid;
  1293. $sql .= " ORDER BY a.label ASC";
  1294. dol_syslog("Form::select_address sql=".$sql);
  1295. $resql=$this->db->query($sql);
  1296. if ($resql)
  1297. {
  1298. print '<select class="flat" name="'.$htmlname.'">';
  1299. if ($showempty) print '<option value="0">&nbsp;</option>';
  1300. $num = $this->db->num_rows($resql);
  1301. $i = 0;
  1302. if ($num)
  1303. {
  1304. while ($i < $num)
  1305. {
  1306. $obj = $this->db->fetch_object($resql);
  1307. if ($selected && $selected == $obj->rowid)
  1308. {
  1309. print '<option value="'.$obj->rowid.'" selected="selected">'.$obj->label.'</option>';
  1310. }
  1311. else
  1312. {
  1313. print '<option value="'.$obj->rowid.'">'.$obj->label.'</option>';
  1314. }
  1315. $i++;
  1316. }
  1317. }
  1318. print '</select>';
  1319. return $num;
  1320. }
  1321. else
  1322. {
  1323. dol_print_error($this->db);
  1324. }
  1325. }
  1326. /**
  1327. * Charge dans cache la liste des conditions de paiements possibles
  1328. *
  1329. * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko
  1330. */
  1331. function load_cache_conditions_paiements()
  1332. {
  1333. global $langs;
  1334. if (count($this->cache_conditions_paiements)) return 0; // Cache deja charge
  1335. $sql = "SELECT rowid, code, libelle";
  1336. $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term';
  1337. $sql.= " WHERE active=1";
  1338. $sql.= " ORDER BY sortorder";
  1339. dol_syslog('Form::load_cache_conditions_paiements sql='.$sql,LOG_DEBUG);
  1340. $resql = $this->db->query($sql);
  1341. if ($resql)
  1342. {
  1343. $num = $this->db->num_rows($resql);
  1344. $i = 0;
  1345. while ($i < $num)
  1346. {
  1347. $obj = $this->db->fetch_object($resql);
  1348. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  1349. $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
  1350. $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code;
  1351. $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle;
  1352. $i++;
  1353. }
  1354. return 1;
  1355. }
  1356. else {
  1357. dol_print_error($this->db);
  1358. return -1;
  1359. }
  1360. }
  1361. /**
  1362. * Charge dans cache la liste des délais de livraison possibles
  1363. *
  1364. * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko
  1365. */
  1366. function load_cache_availability()
  1367. {
  1368. global $langs;
  1369. if (count($this->cache_availability)) return 0; // Cache deja charge
  1370. $sql = "SELECT rowid, code, label";
  1371. $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability';
  1372. $sql.= " WHERE active=1";
  1373. $sql.= " ORDER BY rowid";
  1374. dol_syslog('Form::load_cache_availability sql='.$sql,LOG_DEBUG);
  1375. $resql = $this->db->query($sql);
  1376. if ($resql)
  1377. {
  1378. $num = $this->db->num_rows($resql);
  1379. $i = 0;
  1380. while ($i < $num)
  1381. {
  1382. $obj = $this->db->fetch_object($resql);
  1383. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  1384. $label=($langs->trans("AvailabilityType".$obj->code)!=("AvailabilityType".$obj->code)?$langs->trans("AvailabilityType".$obj->code):($obj->label!='-'?$obj->label:''));
  1385. $this->cache_availability[$obj->rowid]['code'] =$obj->code;
  1386. $this->cache_availability[$obj->rowid]['label']=$label;
  1387. $i++;
  1388. }
  1389. return 1;
  1390. }
  1391. else {
  1392. dol_print_error($this->db);
  1393. return -1;
  1394. }
  1395. }
  1396. /**
  1397. * Retourne la liste des types de delais de livraison possibles
  1398. *
  1399. * @param selected Id du type de delais pre-selectionne
  1400. * @param htmlname Nom de la zone select
  1401. * @param filtertype To add a filter
  1402. * @param addempty Add empty entry
  1403. */
  1404. function select_availability($selected='',$htmlname='availid',$filtertype='',$addempty=0)
  1405. {
  1406. global $langs,$user;
  1407. $this->load_cache_availability();
  1408. print '<select class="flat" name="'.$htmlname.'">';
  1409. if ($addempty) print '<option value="0">&nbsp;</option>';
  1410. foreach($this->cache_availability as $id => $arrayavailability)
  1411. {
  1412. if ($selected == $id)
  1413. {
  1414. print '<option value="'.$id.'" selected="selected">';
  1415. }
  1416. else
  1417. {
  1418. print '<option value="'.$id.'">';
  1419. }
  1420. print $arrayavailability['label'];
  1421. print '</option>';
  1422. }
  1423. print '</select>';
  1424. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  1425. }
  1426. /**
  1427. * Load into cache cache_demand_reason, array of input reasons
  1428. *
  1429. * @return int Nb of lines loaded, 0 if already loaded, <0 if ko
  1430. */
  1431. function load_cache_demand_reason()
  1432. {
  1433. global $langs;
  1434. if (count($this->cache_demand_reason)) return 0; // Cache already loaded
  1435. $sql = "SELECT rowid, code, label";
  1436. $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason';
  1437. $sql.= " WHERE active=1";
  1438. $sql.= " ORDER BY rowid";
  1439. dol_syslog('Form::load_cache_demand_reason sql='.$sql,LOG_DEBUG);
  1440. $resql = $this->db->query($sql);
  1441. if ($resql)
  1442. {
  1443. $num = $this->db->num_rows($resql);
  1444. $i = 0;
  1445. $tmparray=array();
  1446. while ($i < $num)
  1447. {
  1448. $obj = $this->db->fetch_object($resql);
  1449. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  1450. $label=($langs->trans("DemandReasonType".$obj->code)!=("DemandReasonType".$obj->code)?$langs->trans("DemandReasonType".$obj->code):($obj->label!='-'?$obj->label:''));
  1451. $tmparray[$obj->rowid]['id'] =$obj->rowid;
  1452. $tmparray[$obj->rowid]['code'] =$obj->code;
  1453. $tmparray[$obj->rowid]['label']=$label;
  1454. $i++;
  1455. }
  1456. $this->cache_demand_reason=dol_sort_array($tmparray,'label', $order='asc', $natsort, $case_sensitive);
  1457. unset($tmparray);
  1458. return 1;
  1459. }
  1460. else {
  1461. dol_print_error($this->db);
  1462. return -1;
  1463. }
  1464. }
  1465. /**
  1466. * Return list of events that triggered an object creation
  1467. *
  1468. * @param selected Id du type d'origine pre-selectionne
  1469. * @param htmlname Nom de la zone select
  1470. * @param exclude To exclude a code value (Example: SRC_PROP)
  1471. * @param addempty Add an empty entry
  1472. */
  1473. function select_demand_reason($selected='',$htmlname='demandreasonid',$exclude='',$addempty=0)
  1474. {
  1475. global $langs,$user;
  1476. $this->load_cache_demand_reason();
  1477. print '<select class="flat" name="'.$htmlname.'">';
  1478. if ($addempty) print '<option value="0"'.(empty($selected)?' selected="selected"':'').'>&nbsp;</option>';
  1479. foreach($this->cache_demand_reason as $id => $arraydemandreason)
  1480. {
  1481. if ($arraydemandreason['code']==$exclude) continue;
  1482. if ($selected == $arraydemandreason['id'])
  1483. {
  1484. print '<option value="'.$arraydemandreason['id'].'" selected="selected">';
  1485. }
  1486. else
  1487. {
  1488. print '<option value="'.$arraydemandreason['id'].'">';
  1489. }
  1490. print $arraydemandreason['label'];
  1491. print '</option>';
  1492. }
  1493. print '</select>';
  1494. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  1495. }
  1496. /**
  1497. * Charge dans cache la liste des types de paiements possibles
  1498. *
  1499. * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko
  1500. */
  1501. function load_cache_types_paiements()
  1502. {
  1503. global $langs;
  1504. if (count($this->cache_types_paiements)) return 0; // Cache deja charge
  1505. $sql = "SELECT id, code, libelle, type";
  1506. $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement";
  1507. $sql.= " WHERE active > 0";
  1508. $sql.= " ORDER BY id";
  1509. dol_syslog('Form::load_cache_types_paiements sql='.$sql,LOG_DEBUG);
  1510. $resql = $this->db->query($sql);
  1511. if ($resql)
  1512. {
  1513. $num = $this->db->num_rows($resql);
  1514. $i = 0;
  1515. while ($i < $num)
  1516. {
  1517. $obj = $this->db->fetch_object($resql);
  1518. // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
  1519. $libelle=($langs->trans("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->trans("PaymentTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
  1520. $this->cache_types_paiements[$obj->id]['code'] =$obj->code;
  1521. $this->cache_types_paiements[$obj->id]['label']=$libelle;
  1522. $this->cache_types_paiements[$obj->id]['type'] =$obj->type;
  1523. $i++;
  1524. }
  1525. return $num;
  1526. }
  1527. else {
  1528. dol_print_error($this->db);
  1529. return -1;
  1530. }
  1531. }
  1532. /**
  1533. * Retourne la liste des types de paiements possibles
  1534. *
  1535. * @param selected Id du type de paiement pre-selectionne
  1536. * @param htmlname Nom de la zone select
  1537. * @param filtertype Pour filtre
  1538. * @param addempty Ajoute entree vide
  1539. */
  1540. function select_conditions_paiements($selected='',$htmlname='condid',$filtertype=-1,$addempty=0)
  1541. {
  1542. global $langs,$user;
  1543. $this->load_cache_conditions_paiements();
  1544. print '<select class="flat" name="'.$htmlname.'">';
  1545. if ($addempty) print '<option value="0">&nbsp;</option>';
  1546. foreach($this->cache_conditions_paiements as $id => $arrayconditions)
  1547. {
  1548. if ($selected == $id)
  1549. {
  1550. print '<option value="'.$id.'" selected="selected">';
  1551. }
  1552. else
  1553. {
  1554. print '<option value="'.$id.'">';
  1555. }
  1556. print $arrayconditions['label'];
  1557. print '</option>';
  1558. }
  1559. print '</select>';
  1560. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  1561. }
  1562. /**
  1563. * Return list of payment methods
  1564. *
  1565. * @param selected Id du mode de paiement pre-selectionne
  1566. * @param htmlname Nom de la zone select
  1567. * @param filtertype To filter on field type in llx_c_paiement (array('code'=>xx,'label'=>zz))
  1568. * @param format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code
  1569. * @param empty 1=peut etre vide, 0 sinon
  1570. * @param noadmininfo 0=Add admin info, 1=Disable admin info
  1571. * @param maxlength Max length of label
  1572. */
  1573. function select_types_paiements($selected='',$htmlname='paiementtype',$filtertype='',$format=0, $empty=0, $noadmininfo=0,$maxlength=0)
  1574. {
  1575. global $langs,$user;
  1576. dol_syslog("Form::select_type_paiements $selected, $htmlname, $filtertype, $format",LOG_DEBUG);
  1577. $filterarray=array();
  1578. if ($filtertype == 'CRDT') $filterarray=array(0,2);
  1579. elseif ($filtertype == 'DBIT') $filterarray=array(1,2);
  1580. elseif ($filtertype != '' && $filtertype != '-1') $filterarray=explode(',',$filtertype);
  1581. $this->load_cache_types_paiements();
  1582. print '<select id="select'.$htmlname.'" class="flat selectpaymenttypes" name="'.$htmlname.'">';
  1583. if ($empty) print '<option value="">&nbsp;</option>';
  1584. foreach($this->cache_types_paiements as $id => $arraytypes)
  1585. {
  1586. // On passe si on a demande de filtrer sur des modes de paiments particuliers
  1587. if (count($filterarray) && ! in_array($arraytypes['type'],$filterarray)) continue;
  1588. // We discard empty line if showempty is on because an empty line has already been output.
  1589. if ($empty && empty($arraytypes['code'])) continue;
  1590. if ($format == 0) print '<option value="'.$id.'"';
  1591. if ($format == 1) print '<option value="'.$arraytypes['code'].'"';
  1592. if ($format == 2) print '<option value="'.$arraytypes['code'].'"';
  1593. if ($format == 3) print '<option value="'.$id.'"';
  1594. // Si selected est text, on compare avec code, sinon avec id
  1595. if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) print ' selected="selected"';
  1596. elseif ($selected == $id) print ' selected="selected"';
  1597. print '>';
  1598. if ($format == 0) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
  1599. if ($format == 1) $value=$arraytypes['code'];
  1600. if ($format == 2) $value=($maxlength?dol_trunc($arraytypes['label'],$maxlength):$arraytypes['label']);
  1601. if ($format == 3) $value=$arraytypes['code'];
  1602. print $value?$value:'&nbsp;';
  1603. print '</option>';
  1604. }
  1605. print '</select>';
  1606. if ($user->admin && ! $noadmininfo) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  1607. }
  1608. /**
  1609. * Selection HT or TTC
  1610. *
  1611. * @param selected Id pre-selectionne
  1612. * @param htmlname Nom de la zone select
  1613. */
  1614. function select_PriceBaseType($selected='',$htmlname='price_base_type')
  1615. {
  1616. print $this->load_PriceBaseType($selected,$htmlname);
  1617. }
  1618. /**
  1619. * Selection HT or TTC
  1620. *
  1621. * @param selected Id pre-selectionne
  1622. * @param htmlname Nom de la zone select
  1623. */
  1624. function load_PriceBaseType($selected='',$htmlname='price_base_type')
  1625. {
  1626. global $langs;
  1627. $return='';
  1628. $return.= '<select class="flat" name="'.$htmlname.'">';
  1629. $options = array(
  1630. 'HT'=>$langs->trans("HT"),
  1631. 'TTC'=>$langs->trans("TTC")
  1632. );
  1633. foreach($options as $id => $value)
  1634. {
  1635. if ($selected == $id)
  1636. {
  1637. $return.= '<option value="'.$id.'" selected="selected">'.$value;
  1638. }
  1639. else
  1640. {
  1641. $return.= '<option value="'.$id.'">'.$value;
  1642. }
  1643. $return.= '</option>';
  1644. }
  1645. $return.= '</select>';
  1646. return $return;
  1647. }
  1648. /**
  1649. * Return combo list of differents status of a proposal
  1650. * Values are id of table c_propalst
  1651. *
  1652. * @param selected etat pre-selectionne
  1653. * @param short Use short labels
  1654. */
  1655. function select_propal_statut($selected='',$short=0)
  1656. {
  1657. global $langs;
  1658. $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst";
  1659. $sql .= " WHERE active = 1";
  1660. dol_syslog("Form::select_propal_statut sql=".$sql);
  1661. $resql=$this->db->query($sql);
  1662. if ($resql)
  1663. {
  1664. print '<select class="flat" name="propal_statut">';
  1665. print '<option value="">&nbsp;</option>';
  1666. $num = $this->db->num_rows($resql);
  1667. $i = 0;
  1668. if ($num)
  1669. {
  1670. while ($i < $num)
  1671. {
  1672. $obj = $this->db->fetch_object($resql);
  1673. if ($selected == $obj->id)
  1674. {
  1675. print '<option value="'.$obj->id.'" selected="selected">';
  1676. }
  1677. else
  1678. {
  1679. print '<option value="'.$obj->id.'">';
  1680. }
  1681. $key=$obj->code;
  1682. if ($langs->trans("PropalStatus".$key.($short?'Short':'')) != "PropalStatus".$key.($short?'Short':''))
  1683. {
  1684. print $langs->trans("PropalStatus".$key.($short?'Short':''));
  1685. }
  1686. else
  1687. {
  1688. $conv_to_new_code=array('PR_DRAFT'=>'Draft','PR_OPEN'=>'Opened','PR_CLOSED'=>'Closed','PR_SIGNED'=>'Signed','PR_NOTSIGNED'=>'NotSigned','PR_FAC'=>'Billed');
  1689. if (! empty($conv_to_new_code[$obj->code])) $key=$conv_to_new_code[$obj->code];
  1690. print ($langs->trans("PropalStatus".$key.($short?'Short':''))!="PropalStatus".$key.($short?'Short':''))?$langs->trans("PropalStatus".$key.($short?'Short':'')):$obj->label;
  1691. }
  1692. print '</option>';
  1693. $i++;
  1694. }
  1695. }
  1696. print '</select>';
  1697. }
  1698. else
  1699. {
  1700. dol_print_error($this->db);
  1701. }
  1702. }
  1703. /**
  1704. * Return a HTML select list of bank accounts
  1705. *
  1706. * @param selected Id account pre-selected
  1707. * @param htmlname Name of select zone
  1708. * @param statut Status of searched accounts (0=open, 1=closed)
  1709. * @param filtre To filter list
  1710. * @param useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
  1711. * @param moreattrib To add more attribute on select
  1712. */
  1713. function select_comptes($selected='',$htmlname='accountid',$statut=0,$filtre='',$useempty=0,$moreattrib='')
  1714. {
  1715. global $langs, $conf;
  1716. $langs->load("admin");
  1717. $sql = "SELECT rowid, label, bank";
  1718. $sql.= " FROM ".MAIN_DB_PREFIX."bank_account";
  1719. $sql.= " WHERE clos = '".$statut."'";
  1720. $sql.= " AND entity = ".$conf->entity;
  1721. if ($filtre) $sql.=" AND ".$filtre;
  1722. $sql.= " ORDER BY label";
  1723. dol_syslog("Form::select_comptes sql=".$sql);
  1724. $result = $this->db->query($sql);
  1725. if ($result)
  1726. {
  1727. $num = $this->db->num_rows($result);
  1728. $i = 0;
  1729. if ($num)
  1730. {
  1731. print '<select id="select'.$htmlname.'" class="flat selectbankaccount" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
  1732. if ($useempty == 1 || ($useempty == 2 && $num > 1))
  1733. {
  1734. print '<option value="'.$obj->rowid.'">&nbsp;</option>';
  1735. }
  1736. while ($i < $num)
  1737. {
  1738. $obj = $this->db->fetch_object($result);
  1739. if ($selected == $obj->rowid)
  1740. {
  1741. print '<option value="'.$obj->rowid.'" selected="selected">';
  1742. }
  1743. else
  1744. {
  1745. print '<option value="'.$obj->rowid.'">';
  1746. }
  1747. print $obj->label;
  1748. print '</option>';
  1749. $i++;
  1750. }
  1751. print "</select>";
  1752. }
  1753. else
  1754. {
  1755. print $langs->trans("NoActiveBankAccountDefined");
  1756. }
  1757. }
  1758. else {
  1759. dol_print_error($this->db);
  1760. }
  1761. }
  1762. /**
  1763. * Return list of categories having choosed type
  1764. *
  1765. * @param type Type de categories (0=product, 1=supplier, 2=customer, 3=member)
  1766. * @param selected Id of category preselected
  1767. * @param select_name HTML field name
  1768. * @param maxlength Maximum length for labels
  1769. * @param excludeafterid Exclude all categories after this leaf in category tree.
  1770. */
  1771. function select_all_categories($type, $selected='', $select_name="", $maxlength=64, $excludeafterid=0)
  1772. {
  1773. global $langs;
  1774. $langs->load("categories");
  1775. if ($select_name=="") $select_name="catMere";
  1776. $cat = new Categorie($this->db);
  1777. $cate_arbo = $cat->get_full_arbo($type,$excludeafterid);
  1778. $output = '<select class="flat" name="'.$select_name.'">';
  1779. if (is_array($cate_arbo))
  1780. {
  1781. if (! count($cate_arbo)) $output.= '<option value="-1" disabled="disabled">'.$langs->trans("NoCategoriesDefined").'</option>';
  1782. else
  1783. {
  1784. $output.= '<option value="-1">&nbsp;</option>';
  1785. foreach($cate_arbo as $key => $value)
  1786. {
  1787. if ($cate_arbo[$key]['id'] == $selected)
  1788. {
  1789. $add = 'selected="selected" ';
  1790. }
  1791. else
  1792. {
  1793. $add = '';
  1794. }
  1795. $output.= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'">'.dol_trunc($cate_arbo[$key]['fulllabel'],$maxlength,'middle').'</option>';
  1796. }
  1797. }
  1798. }
  1799. $output.= '</select>';
  1800. $output.= "\n";
  1801. return $output;
  1802. }
  1803. /**
  1804. * Show a confirmation HTML form or AJAX popup
  1805. *
  1806. * @param page Url of page to call if confirmation is OK
  1807. * @param title title
  1808. * @param question question
  1809. * @param action action
  1810. * @param formquestion an array with forms complementary inputs
  1811. * @param selectedchoice "" or "no" or "yes"
  1812. * @param useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No
  1813. * @param height Force height of box
  1814. * @return string 'ajax' if a confirm ajax popup is shown, 'html' if it's an html form
  1815. */
  1816. function form_confirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500)
  1817. {
  1818. print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width);
  1819. }
  1820. /**
  1821. * Show a confirmation HTML form or AJAX popup
  1822. *
  1823. * @param page Url of page to call if confirmation is OK
  1824. * @param title title
  1825. * @param question question
  1826. * @param action action
  1827. * @param formquestion an array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , ))
  1828. * @param selectedchoice "" or "no" or "yes"
  1829. * @param useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No
  1830. * @param height Force height of box
  1831. * @return string 'ajax' if a confirm ajax popup is shown, 'html' if it's an html form
  1832. */
  1833. function formconfirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500)
  1834. {
  1835. global $langs,$conf;
  1836. $more='';
  1837. $formconfirm='';
  1838. $inputarray=array();
  1839. if ($formquestion)
  1840. {
  1841. $more.='<table class="nobordernopadding" width="100%">'."\n";
  1842. $more.='<tr><td colspan="3" valign="top">'.$formquestion['text'].'</td></tr>'."\n";
  1843. foreach ($formquestion as $key => $input)
  1844. {
  1845. if (is_array($input))
  1846. {
  1847. if ($input['type'] == 'text')
  1848. {
  1849. $more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="text" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'" /></td></tr>'."\n";
  1850. }
  1851. else if ($input['type'] == 'password')
  1852. {
  1853. $more.='<tr><td valign="top">'.$input['label'].'</td><td valign="top" colspan="2" align="left"><input type="password" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" size="'.$input['size'].'" value="'.$input['value'].'" /></td></tr>'."\n";
  1854. }
  1855. else if ($input['type'] == 'select')
  1856. {
  1857. $more.='<tr><td valign="top">';
  1858. if (! empty($input['label'])) $more.=$input['label'].'</td><td valign="top" colspan="2" align="left">';
  1859. $more.=$this->selectarray($input['name'],$input['values'],$input['default'],1);
  1860. $more.='</td></tr>'."\n";
  1861. }
  1862. else if ($input['type'] == 'checkbox')
  1863. {
  1864. $more.='<tr>';
  1865. $more.='<td valign="top">'.$input['label'].' </td><td valign="top" align="left">';
  1866. $more.='<input type="checkbox" class="flat" id="'.$input['name'].'" name="'.$input['name'].'"';
  1867. if (! is_bool($input['value']) && $input['value'] != 'false') $more.=' checked="checked"';
  1868. if (is_bool($input['value']) && $input['value']) $more.=' checked="checked"';
  1869. if ($input['disabled']) $more.=' disabled="disabled"';
  1870. $more.=' /></td>';
  1871. $more.='<td valign="top" align="left">&nbsp;</td>';
  1872. $more.='</tr>'."\n";
  1873. }
  1874. else if ($input['type'] == 'radio')
  1875. {
  1876. $i=0;
  1877. foreach($input['values'] as $selkey => $selval)
  1878. {
  1879. $more.='<tr>';
  1880. if ($i==0) $more.='<td valign="top">'.$input['label'].'</td>';
  1881. else $more.='<td>&nbsp;</td>';
  1882. $more.='<td valign="top" width="20"><input type="radio" class="flat" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$selkey.'"';
  1883. if ($input['disabled']) $more.=' disabled="disabled"';
  1884. $more.=' /></td>';
  1885. $more.='<td valign="top" align="left">';
  1886. $more.=$selval;
  1887. $more.='</td></tr>'."\n";
  1888. $i++;
  1889. }
  1890. }
  1891. else if ($input['type'] == 'other')
  1892. {
  1893. $more.='<tr><td valign="top">';
  1894. if (! empty($input['label'])) $more.=$input['label'].'</td><td valign="top" colspan="2" align="left">';
  1895. $more.=$input['value'];
  1896. $more.='</td></tr>'."\n";
  1897. }
  1898. array_push($inputarray,$input['name']);
  1899. }
  1900. }
  1901. $more.='</table>'."\n";
  1902. }
  1903. $formconfirm.= "\n<!-- begin form_confirm -->\n";
  1904. if ($useajax && $conf->use_javascript_ajax)
  1905. {
  1906. $autoOpen=true;
  1907. $dialogconfirm='dialog-confirm';
  1908. if (! is_int($useajax)) {
  1909. $button=$useajax;
  1910. $useajax=1;
  1911. $autoOpen=false;
  1912. $dialogconfirm.='-'.$button;
  1913. }
  1914. $pageyes=$page.'&action='.$action.'&confirm=yes';
  1915. $pageno=($useajax == 2?$page.'&confirm=no':'');
  1916. // New code using jQuery only
  1917. $formconfirm.= '<div id="'.$dialogconfirm.'" title="'.dol_escape_htmltag($title).'" style="display: none;">';
  1918. if (! empty($more)) $formconfirm.= '<p>'.$more.'</p>';
  1919. $formconfirm.= img_help('','').' '.$question;
  1920. $formconfirm.= '</div>'."\n";
  1921. $formconfirm.= '<script type="text/javascript">
  1922. $(function() {
  1923. var choice=\'ko\';
  1924. var $inputarray='.json_encode($inputarray).';
  1925. var button=\''.$button.'\';
  1926. var dialogconfirm=\''.$dialogconfirm.'\';
  1927. $( "#" + dialogconfirm ).dialog({
  1928. autoOpen: '.($autoOpen?'true':'false').',
  1929. resizable: false,
  1930. height:'.$height.',
  1931. width:'.$width.',
  1932. modal: true,
  1933. closeOnEscape: false,
  1934. close: function(event, ui) {
  1935. if (choice == \'ok\') {
  1936. var options="";
  1937. if ($inputarray.length>0) {
  1938. $.each($inputarray, function() {
  1939. var inputname = this;
  1940. var inputvalue = $("#" + this).val();
  1941. options += \'&\' + inputname + \'=\' + inputvalue;
  1942. });
  1943. //alert(options);
  1944. }
  1945. location.href=\''.$pageyes.'\' + options;
  1946. }
  1947. '.($pageno?'if (choice == \'ko\') location.href=\''.$pageno.'\';':'').'
  1948. },
  1949. buttons: {
  1950. \''.dol_escape_js($langs->transnoentities("Yes")).'\': function() {
  1951. choice=\'ok\';
  1952. $(this).dialog(\'close\');
  1953. },
  1954. \''.dol_escape_js($langs->transnoentities("No")).'\': function() {
  1955. choice=\'ko\';
  1956. $(this).dialog(\'close\');
  1957. }
  1958. }
  1959. });
  1960. if (button.length > 0) {
  1961. $( "#" + button ).click(function() {
  1962. $("#" + dialogconfirm ).dialog(\'open\');
  1963. });
  1964. }
  1965. });
  1966. </script>';
  1967. $formconfirm.= "\n";
  1968. }
  1969. else
  1970. {
  1971. $formconfirm.= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n";
  1972. $formconfirm.= '<input type="hidden" name="action" value="'.$action.'">';
  1973. $formconfirm.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
  1974. $formconfirm.= '<table width="100%" class="valid">'."\n";
  1975. // Ligne titre
  1976. $formconfirm.= '<tr class="validtitre"><td class="validtitre" colspan="3">'.img_picto('','recent').' '.$title.'</td></tr>'."\n";
  1977. // Ligne formulaire
  1978. if ($more)
  1979. {
  1980. $formconfirm.='<tr class="valid"><td class="valid" colspan="3">'."\n";
  1981. $formconfirm.=$more;
  1982. $formconfirm.='</td></tr>'."\n";
  1983. }
  1984. // Ligne message
  1985. $formconfirm.= '<tr class="valid">';
  1986. $formconfirm.= '<td class="valid">'.$question.'</td>';
  1987. $formconfirm.= '<td class="valid">';
  1988. $newselectedchoice=empty($selectedchoice)?"no":$selectedchoice;
  1989. $formconfirm.= $this->selectyesno("confirm",$newselectedchoice);
  1990. $formconfirm.= '</td>';
  1991. $formconfirm.= '<td class="valid" align="center"><input class="button" type="submit" value="'.$langs->trans("Validate").'"></td>';
  1992. $formconfirm.= '</tr>'."\n";
  1993. $formconfirm.= '</table>'."\n";
  1994. if (is_array($formquestion))
  1995. {
  1996. foreach ($formquestion as $key => $input)
  1997. {
  1998. if ($input['type'] == 'hidden') $formconfirm.= '<input type="hidden" name="'.$input['name'].'" value="'.$input['value'].'">';
  1999. }
  2000. }
  2001. $formconfirm.= "</form>\n";
  2002. $formconfirm.= '<br>';
  2003. }
  2004. $formconfirm.= "<!-- end form_confirm -->\n";
  2005. return $formconfirm;
  2006. }
  2007. /**
  2008. * Show a form to select a project
  2009. *
  2010. * @param page Page
  2011. * @param socid Id societe
  2012. * @param selected Id projet pre-selectionne
  2013. * @param htmlname Nom du formulaire select
  2014. * @return void
  2015. */
  2016. function form_project($page, $socid, $selected='', $htmlname='projectid')
  2017. {
  2018. global $langs;
  2019. require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
  2020. $langs->load("project");
  2021. if ($htmlname != "none")
  2022. {
  2023. print '<form method="post" action="'.$page.'">';
  2024. print '<input type="hidden" name="action" value="classin">';
  2025. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2026. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2027. print '<tr><td>';
  2028. //print "$socid,$selected,$htmlname";
  2029. select_projects($socid,$selected,$htmlname);
  2030. print '</td>';
  2031. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2032. print '</tr></table></form>';
  2033. }
  2034. else
  2035. {
  2036. if ($selected) {
  2037. $projet = new Project($this->db);
  2038. $projet->fetch($selected);
  2039. //print '<a href="'.DOL_URL_ROOT.'/projet/fiche.php?id='.$selected.'">'.$projet->title.'</a>';
  2040. print $projet->getNomUrl(0);
  2041. } else {
  2042. print "&nbsp;";
  2043. }
  2044. }
  2045. }
  2046. /**
  2047. * Show a form to select payment conditions
  2048. *
  2049. * @param page Page
  2050. * @param selected Id condition pre-selectionne
  2051. * @param htmlname Name of select html field
  2052. * @param addempty Ajoute entree vide
  2053. * @return void
  2054. */
  2055. function form_conditions_reglement($page, $selected='', $htmlname='cond_reglement_id', $addempty=0)
  2056. {
  2057. global $langs;
  2058. if ($htmlname != "none")
  2059. {
  2060. print '<form method="post" action="'.$page.'">';
  2061. print '<input type="hidden" name="action" value="setconditions">';
  2062. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2063. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2064. print '<tr><td>';
  2065. $this->select_conditions_paiements($selected,$htmlname,-1,$addempty);
  2066. print '</td>';
  2067. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2068. print '</tr></table></form>';
  2069. }
  2070. else
  2071. {
  2072. if ($selected)
  2073. {
  2074. $this->load_cache_conditions_paiements();
  2075. print $this->cache_conditions_paiements[$selected]['label'];
  2076. } else {
  2077. print "&nbsp;";
  2078. }
  2079. }
  2080. }
  2081. /**
  2082. * Show a form to select a delivery delay
  2083. *
  2084. * @param page Page
  2085. * @param selected Id condition pre-selectionne
  2086. * @param htmlname Name of select html field
  2087. * @param addempty Ajoute entree vide
  2088. * @return void
  2089. */
  2090. function form_availability($page, $selected='', $htmlname='availability', $addempty=0)
  2091. {
  2092. global $langs;
  2093. if ($htmlname != "none")
  2094. {
  2095. print '<form method="post" action="'.$page.'">';
  2096. print '<input type="hidden" name="action" value="setavailability">';
  2097. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2098. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2099. print '<tr><td>';
  2100. $this->select_availability($selected,$htmlname,-1,$addempty);
  2101. print '</td>';
  2102. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2103. print '</tr></table></form>';
  2104. }
  2105. else
  2106. {
  2107. if ($selected)
  2108. {
  2109. $this->load_cache_availability();
  2110. print $this->cache_availability[$selected]['label'];
  2111. } else {
  2112. print "&nbsp;";
  2113. }
  2114. }
  2115. }
  2116. /**
  2117. * Show a select form to select origin
  2118. *
  2119. * @param page Page
  2120. * @param selected Id condition pre-selectionne
  2121. * @param htmlname Name of select html field
  2122. * @param addempty Add empty entry
  2123. * @return void
  2124. */
  2125. function form_demand_reason($page, $selected='', $htmlname='demandreason', $addempty=0)
  2126. {
  2127. global $langs;
  2128. if ($htmlname != "none")
  2129. {
  2130. print '<form method="post" action="'.$page.'">';
  2131. print '<input type="hidden" name="action" value="setdemandreason">';
  2132. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2133. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2134. print '<tr><td>';
  2135. $this->select_demand_reason($selected,$htmlname,-1,$addempty);
  2136. print '</td>';
  2137. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2138. print '</tr></table></form>';
  2139. }
  2140. else
  2141. {
  2142. if ($selected)
  2143. {
  2144. $this->load_cache_demand_reason();
  2145. foreach ($this->cache_demand_reason as $key => $val)
  2146. {
  2147. if ($val['id'] == $selected)
  2148. {
  2149. print $val['label'];
  2150. break;
  2151. }
  2152. }
  2153. } else {
  2154. print "&nbsp;";
  2155. }
  2156. }
  2157. }
  2158. /**
  2159. * Show a form to select a date
  2160. *
  2161. * @param page Page
  2162. * @param selected Date preselected
  2163. * @param htmlname Name of input html field
  2164. * @return void
  2165. */
  2166. function form_date($page, $selected='', $htmlname)
  2167. {
  2168. global $langs;
  2169. if ($htmlname != "none")
  2170. {
  2171. print '<form method="post" action="'.$page.'" name="form'.$htmlname.'">';
  2172. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  2173. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2174. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2175. print '<tr><td>';
  2176. print $this->select_date($selected,$htmlname,0,0,1,'form'.$htmlname);
  2177. print '</td>';
  2178. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2179. print '</tr></table></form>';
  2180. }
  2181. else
  2182. {
  2183. if ($selected)
  2184. {
  2185. $this->load_cache_types_paiements();
  2186. print $this->cache_types_paiements[$selected]['label'];
  2187. } else {
  2188. print "&nbsp;";
  2189. }
  2190. }
  2191. }
  2192. /**
  2193. * Show a select form to choose a user
  2194. *
  2195. * @param page Page
  2196. * @param selected Id of user preselected
  2197. * @param htmlname Name of input html field
  2198. * @param exclude List of users id to exclude
  2199. * @param include List of users id to include
  2200. * @return void
  2201. */
  2202. function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='')
  2203. {
  2204. global $langs;
  2205. if ($htmlname != "none")
  2206. {
  2207. print '<form method="POST" action="'.$page.'" name="form'.$htmlname.'">';
  2208. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  2209. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2210. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2211. print '<tr><td>';
  2212. print $this->select_users($selected,$htmlname,1,$exclude,0,$include);
  2213. print '</td>';
  2214. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2215. print '</tr></table></form>';
  2216. }
  2217. else
  2218. {
  2219. if ($selected)
  2220. {
  2221. require_once(DOL_DOCUMENT_ROOT ."/user/class/user.class.php");
  2222. //$this->load_cache_contacts();
  2223. //print $this->cache_contacts[$selected];
  2224. $theuser=new User($this->db);
  2225. $theuser->fetch($selected);
  2226. print $theuser->getNomUrl(1);
  2227. } else {
  2228. print "&nbsp;";
  2229. }
  2230. }
  2231. }
  2232. /**
  2233. * Affiche formulaire de selection des modes de reglement
  2234. *
  2235. * @param page Page
  2236. * @param selected Id mode pre-selectionne
  2237. * @param htmlname Name of select html field
  2238. * @return void
  2239. */
  2240. function form_modes_reglement($page, $selected='', $htmlname='mode_reglement_id')
  2241. {
  2242. global $langs;
  2243. if ($htmlname != "none")
  2244. {
  2245. print '<form method="POST" action="'.$page.'">';
  2246. print '<input type="hidden" name="action" value="setmode">';
  2247. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2248. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2249. print '<tr><td>';
  2250. $this->select_types_paiements($selected,$htmlname);
  2251. print '</td>';
  2252. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2253. print '</tr></table></form>';
  2254. }
  2255. else
  2256. {
  2257. if ($selected)
  2258. {
  2259. $this->load_cache_types_paiements();
  2260. print $this->cache_types_paiements[$selected]['label'];
  2261. } else {
  2262. print "&nbsp;";
  2263. }
  2264. }
  2265. }
  2266. /**
  2267. * Show a select box with available absolute discounts
  2268. *
  2269. * @param page Page URL where form is shown
  2270. * @param selected Value pre-selected
  2271. * @param htmlname Nom du formulaire select. Si none, non modifiable
  2272. * @param socid Third party id
  2273. * @param amount Total amount available
  2274. * @param filter SQL filter on discounts
  2275. * @param maxvalue Max value for lines that can be selected
  2276. * @param more More string to add
  2277. * @return void
  2278. */
  2279. function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0, $more='')
  2280. {
  2281. global $conf,$langs;
  2282. if ($htmlname != "none")
  2283. {
  2284. print '<form method="post" action="'.$page.'">';
  2285. print '<input type="hidden" name="action" value="setabsolutediscount">';
  2286. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2287. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2288. print '<tr><td nowrap="nowrap">';
  2289. if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
  2290. else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
  2291. // print $langs->trans("AvailableGlobalDiscounts").': ';
  2292. $newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles
  2293. if ($filter) $newfilter.=' AND '.$filter;
  2294. $nbqualifiedlines=$this->select_remises('',$htmlname,$newfilter,$socid,$maxvalue);
  2295. print '</td>';
  2296. print '<td>';
  2297. if ($nbqualifiedlines > 0)
  2298. {
  2299. print ' &nbsp; <input type="submit" class="button" value="';
  2300. if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("UseDiscount");
  2301. else print $langs->trans("UseCredit");
  2302. print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">';
  2303. }
  2304. if ($more) print $more;
  2305. print '</td>';
  2306. print '</tr></table></form>';
  2307. }
  2308. else
  2309. {
  2310. if ($selected)
  2311. {
  2312. print $selected;
  2313. }
  2314. else
  2315. {
  2316. print "0";
  2317. }
  2318. }
  2319. }
  2320. /**
  2321. * Affiche formulaire de selection des contacts
  2322. *
  2323. * @param page Page
  2324. * @param selected Id contact pre-selectionne
  2325. * @param htmlname Nom du formulaire select
  2326. * @return void
  2327. */
  2328. function form_contacts($page, $societe, $selected='', $htmlname='contactidp')
  2329. {
  2330. global $langs;
  2331. if ($htmlname != "none")
  2332. {
  2333. print '<form method="post" action="'.$page.'">';
  2334. print '<input type="hidden" name="action" value="set_contact">';
  2335. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2336. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2337. print '<tr><td>';
  2338. $num=$this->select_contacts($societe->id, $selected, $htmlname);
  2339. if ($num==0)
  2340. {
  2341. print '<font class="error">Cette societe n\'a pas de contact, veuillez en cr�er un avant de faire votre proposition commerciale</font><br>';
  2342. print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$societe->id.'&amp;action=create&amp;backtoreferer=1">'.$langs->trans('AddContact').'</a>';
  2343. }
  2344. print '</td>';
  2345. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2346. print '</tr></table></form>';
  2347. }
  2348. else
  2349. {
  2350. if ($selected)
  2351. {
  2352. require_once(DOL_DOCUMENT_ROOT ."/contact/class/contact.class.php");
  2353. //$this->load_cache_contacts();
  2354. //print $this->cache_contacts[$selected];
  2355. $contact=new Contact($this->db);
  2356. $contact->fetch($selected);
  2357. print $contact->getFullName($langs);
  2358. } else {
  2359. print "&nbsp;";
  2360. }
  2361. }
  2362. }
  2363. /**
  2364. * Affiche formulaire de selection des tiers
  2365. *
  2366. * @param page Page
  2367. * @param selected Id contact pre-selectionne
  2368. * @param htmlname Nom du formulaire select
  2369. * @return void
  2370. */
  2371. function form_thirdparty($page, $selected='', $htmlname='socid')
  2372. {
  2373. global $langs;
  2374. if ($htmlname != "none")
  2375. {
  2376. print '<form method="post" action="'.$page.'">';
  2377. print '<input type="hidden" name="action" value="set_thirdparty">';
  2378. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2379. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2380. print '<tr><td>';
  2381. $num=$this->select_societes($selected , $htmlname);
  2382. print '</td>';
  2383. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  2384. print '</tr></table></form>';
  2385. }
  2386. else
  2387. {
  2388. if ($selected)
  2389. {
  2390. require_once(DOL_DOCUMENT_ROOT ."/societe/class/societe.class.php");
  2391. $soc = new Societe($this->db);
  2392. $soc->fetch($selected);
  2393. print $soc->getNomUrl($langs);
  2394. } else {
  2395. print "&nbsp;";
  2396. }
  2397. }
  2398. }
  2399. /**
  2400. * Affiche formulaire de selection de l'adresse
  2401. *
  2402. * @param page Page
  2403. * @param selected Id condition pre-selectionne
  2404. * @param htmlname Nom du formulaire select
  2405. * @param origin Origine de l'appel pour pouvoir creer un retour
  2406. * @param originid Id de l'origine
  2407. * @return void
  2408. */
  2409. function form_address($page, $selected='', $socid, $htmlname='address_id', $origin='', $originid='')
  2410. {
  2411. global $langs,$conf;
  2412. if ($htmlname != "none")
  2413. {
  2414. print '<form method="post" action="'.$page.'">';
  2415. print '<input type="hidden" name="action" value="setaddress">';
  2416. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  2417. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  2418. print '<tr><td>';
  2419. $this->select_address($selected, $socid, $htmlname, 1);
  2420. print '</td>';
  2421. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  2422. $langs->load("companies");
  2423. print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
  2424. print '</td></tr></table></form>';
  2425. }
  2426. else
  2427. {
  2428. if ($selected)
  2429. {
  2430. require_once(DOL_DOCUMENT_ROOT ."/societe/class/address.class.php");
  2431. $address=new Address($this->db);
  2432. $result=$address->fetch_address($selected);
  2433. print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
  2434. }
  2435. else
  2436. {
  2437. print "&nbsp;";
  2438. }
  2439. }
  2440. }
  2441. /**
  2442. * Retourne la liste des devises, dans la langue de l'utilisateur
  2443. *
  2444. * @param selected code devise pre-selectionne
  2445. * @param htmlname nom de la liste deroulante
  2446. * @return void
  2447. */
  2448. function select_currency($selected='',$htmlname='currency_id')
  2449. {
  2450. print $this->selectcurrency($selected,$htmlname);
  2451. }
  2452. /**
  2453. * Retourne la liste des devises, dans la langue de l'utilisateur
  2454. *
  2455. * @param selected code devise pre-selectionne
  2456. * @param htmlname nom de la liste deroulante
  2457. */
  2458. function selectcurrency($selected='',$htmlname='currency_id')
  2459. {
  2460. global $conf,$langs,$user;
  2461. $langs->load("dict");
  2462. $out='';
  2463. $currencyArray=array();
  2464. $label=array();
  2465. if ($selected=='euro' || $selected=='euros') $selected='EUR'; // Pour compatibilite
  2466. $sql = "SELECT code_iso, label";
  2467. $sql.= " FROM ".MAIN_DB_PREFIX."c_currencies";
  2468. $sql.= " WHERE active = 1";
  2469. $sql.= " ORDER BY code_iso ASC";
  2470. $resql=$this->db->query($sql);
  2471. if ($resql)
  2472. {
  2473. $out.= '<select class="flat" name="'.$htmlname.'">';
  2474. $num = $this->db->num_rows($resql);
  2475. $i = 0;
  2476. if ($num)
  2477. {
  2478. $foundselected=false;
  2479. while ($i < $num) {
  2480. $obj = $this->db->fetch_object($resql);
  2481. $currencyArray[$i]['code_iso'] = $obj->code_iso;
  2482. $currencyArray[$i]['label'] = ($obj->code_iso && $langs->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$langs->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:''));
  2483. $label[$i] = $currencyArray[$i]['label'];
  2484. $i++;
  2485. }
  2486. array_multisort($label, SORT_ASC, $currencyArray);
  2487. foreach ($currencyArray as $row) {
  2488. if ($selected && $selected == $row['code_iso']) {
  2489. $foundselected=true;
  2490. $out.= '<option value="'.$row['code_iso'].'" selected="selected">';
  2491. } else {
  2492. $out.= '<option value="'.$row['code_iso'].'">';
  2493. }
  2494. $out.= $row['label'];
  2495. if ($row['code_iso']) $out.= ' ('.$row['code_iso'] . ')';
  2496. $out.= '</option>';
  2497. }
  2498. }
  2499. $out.= '</select>';
  2500. if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
  2501. return $out;
  2502. }
  2503. else
  2504. {
  2505. dol_print_error($this->db);
  2506. }
  2507. }
  2508. /**
  2509. * Output an HTML select vat rate
  2510. *
  2511. * @param htmlname Nom champ html
  2512. * @param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
  2513. * @param societe_vendeuse Objet societe vendeuse
  2514. * @param societe_acheteuse Objet societe acheteuse
  2515. * @param idprod Id product
  2516. * @param info_bits Miscellaneous information on line
  2517. * @param type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
  2518. * Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
  2519. * Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  2520. * Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
  2521. * Si (vendeur et acheteur dans Communaute europeenne) et bien vendu autre que transport neuf alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  2522. * Sinon la TVA proposee par defaut=0. Fin de regle.
  2523. * @deprecated
  2524. * @return void
  2525. */
  2526. function select_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='')
  2527. {
  2528. print $this->load_tva($htmlname, $selectedrate, $societe_vendeuse, $societe_acheteuse, $idprod, $info_bits, $type);
  2529. }
  2530. /**
  2531. * Output an HTML select vat rate
  2532. *
  2533. * @param htmlname Nom champ html
  2534. * @param selectedrate Forcage du taux tva pre-selectionne. Mettre '' pour aucun forcage.
  2535. * @param societe_vendeuse Objet societe vendeuse
  2536. * @param societe_acheteuse Objet societe acheteuse
  2537. * @param idprod Id product
  2538. * @param info_bits Miscellaneous information on line (1 for NPR)
  2539. * @param type ''=Unknown, 0=Product, 1=Service (Used if idprod not defined)
  2540. * Si vendeur non assujeti a TVA, TVA par defaut=0. Fin de regle.
  2541. * Si le (pays vendeur = pays acheteur) alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  2542. * Si (vendeur et acheteur dans Communaute europeenne) et bien vendu = moyen de transports neuf (auto, bateau, avion), TVA par defaut=0 (La TVA doit etre paye par l'acheteur au centre d'impots de son pays et non au vendeur). Fin de regle.
  2543. * Si (vendeur et acheteur dans Communaute europeenne) et bien vendu autre que transport neuf alors la TVA par defaut=TVA du produit vendu. Fin de regle.
  2544. * Sinon la TVA proposee par defaut=0. Fin de regle.
  2545. * @return void
  2546. */
  2547. function load_tva($htmlname='tauxtva', $selectedrate='', $societe_vendeuse='', $societe_acheteuse='', $idprod=0, $info_bits=0, $type='')
  2548. {
  2549. global $langs,$conf,$mysoc;
  2550. $return='';
  2551. $txtva=array();
  2552. $libtva=array();
  2553. $nprtva=array();
  2554. // Define defaultnpr and defaultttx
  2555. $defaultnpr=($info_bits & 0x01);
  2556. $defaultnpr=(preg_match('/\*/',$selectedrate) ? 1 : $defaultnpr);
  2557. $defaulttx=str_replace('*','',$selectedrate);
  2558. // Check parameters
  2559. if (is_object($societe_vendeuse) && ! $societe_vendeuse->pays_code)
  2560. {
  2561. if ($societe_vendeuse->id == $mysoc->id)
  2562. {
  2563. $return.= '<font class="error">'.$langs->trans("ErrorYourCountryIsNotDefined").'</div>';
  2564. }
  2565. else
  2566. {
  2567. $return.= '<font class="error">'.$langs->trans("ErrorSupplierCountryIsNotDefined").'</div>';
  2568. }
  2569. return $return;
  2570. }
  2571. //var_dump($societe_acheteuse);
  2572. //print "name=$name, selectedrate=$selectedrate, seller=".$societe_vendeuse->pays_code." buyer=".$societe_acheteuse->pays_code." buyer is company=".$societe_acheteuse->isACompany()." idprod=$idprod, info_bits=$info_bits type=$type";
  2573. //exit;
  2574. // Get list of all VAT rates to show
  2575. // First we defined code_pays to use to find list
  2576. if (is_object($societe_vendeuse))
  2577. {
  2578. $code_pays="'".$societe_vendeuse->pays_code."'";
  2579. }
  2580. else
  2581. {
  2582. $code_pays="'".$mysoc->pays_code."'"; // Pour compatibilite ascendente
  2583. }
  2584. if (! empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) // If option to have vat for end customer for services is on
  2585. {
  2586. if (! $societe_vendeuse->isInEEC() && $societe_acheteuse->isInEEC() && ! $societe_acheteuse->isACompany())
  2587. {
  2588. // We also add the buyer
  2589. if (is_numeric($type))
  2590. {
  2591. if ($type == 1) // We know product is a service
  2592. {
  2593. $code_pays.=",'".$societe_acheteuse->pays_code."'";
  2594. }
  2595. }
  2596. else if (! $idprod) // We don't know type of product
  2597. {
  2598. $code_pays.=",'".$societe_acheteuse->pays_code."'";
  2599. }
  2600. else
  2601. {
  2602. $prodstatic=new Product($this->db);
  2603. $prodstatic->fetch($idprod);
  2604. if ($prodstatic->type == 1) // We know product is a service
  2605. {
  2606. $code_pays.=",'".$societe_acheteuse->pays_code."'";
  2607. }
  2608. }
  2609. }
  2610. }
  2611. // Now we get list
  2612. $sql = "SELECT DISTINCT t.taux, t.recuperableonly";
  2613. $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p";
  2614. $sql.= " WHERE t.fk_pays = p.rowid";
  2615. $sql.= " AND t.active = 1";
  2616. $sql.= " AND p.code in (".$code_pays.")";
  2617. $sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC";
  2618. $resql=$this->db->query($sql);
  2619. if ($resql)
  2620. {
  2621. $num = $this->db->num_rows($resql);
  2622. if ($num)
  2623. {
  2624. for ($i = 0; $i < $num; $i++)
  2625. {
  2626. $obj = $this->db->fetch_object($resql);
  2627. $txtva[$i] = $obj->taux;
  2628. $libtva[$i] = $obj->taux.'%';
  2629. $nprtva[$i] = $obj->recuperableonly;
  2630. }
  2631. }
  2632. else
  2633. {
  2634. $return.= '<font class="error">'.$langs->trans("ErrorNoVATRateDefinedForSellerCountry",$code_pays).'</font>';
  2635. }
  2636. }
  2637. else
  2638. {
  2639. $return.= '<font class="error">'.$this->db->error().'</font>';
  2640. }
  2641. // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '')
  2642. if ($defaulttx < 0 || dol_strlen($defaulttx) == 0)
  2643. {
  2644. $defaulttx=get_default_tva($societe_vendeuse,$societe_acheteuse,$idprod);
  2645. $defaultnpr=get_default_npr($societe_vendeuse,$societe_acheteuse,$idprod);
  2646. }
  2647. // Si taux par defaut n'a pu etre determine, on prend dernier de la liste.
  2648. // Comme ils sont tries par ordre croissant, dernier = plus eleve = taux courant
  2649. if ($defaulttx < 0 || dol_strlen($defaulttx) == 0)
  2650. {
  2651. $defaulttx = $txtva[count($txtva)-1];
  2652. }
  2653. $nbdetaux = count($txtva);
  2654. if ($nbdetaux > 0)
  2655. {
  2656. $return.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  2657. for ($i = 0 ; $i < $nbdetaux ; $i++)
  2658. {
  2659. //print "xxxxx".$txtva[$i]."-".$nprtva[$i];
  2660. $return.= '<option value="'.$txtva[$i];
  2661. $return.= $nprtva[$i] ? '*': '';
  2662. $return.= '"';
  2663. if ($txtva[$i] == $defaulttx && $nprtva[$i] == $defaultnpr)
  2664. {
  2665. $return.= ' selected="selected"';
  2666. }
  2667. $return.= '>'.vatrate($libtva[$i]);
  2668. $return.= $nprtva[$i] ? ' *': '';
  2669. $return.= '</option>';
  2670. $this->tva_taux_value[$i] = $txtva[$i];
  2671. $this->tva_taux_libelle[$i] = $libtva[$i];
  2672. $this->tva_taux_npr[$i] = $nprtva[$i];
  2673. }
  2674. $return.= '</select>';
  2675. }
  2676. return $return;
  2677. }
  2678. /**
  2679. * Show a HTML widget to input a date or combo list for day, month, years and optionnaly hours and minutes
  2680. * Fields are preselected with :
  2681. * - set_time date (Local PHP server timestamps or date format YYYY-MM-DD or YYYY-MM-DD HH:MM)
  2682. * - local date of PHP server if set_time is ''
  2683. * - Empty (fields empty) if set_time is -1 (in this case, parameter empty must also have value 1)
  2684. *
  2685. * @param set_time Pre-selected date (must be a local PHP server timestamp)
  2686. * @param prefix Prefix for fields name
  2687. * @param h 1=Show also hours
  2688. * @param m 1=Show also minutes
  2689. * @param empty 0=Fields required, 1=Empty input is allowed
  2690. * @param form_name Form name. Used by popup dates.
  2691. * @param d 1=Show days, month, years
  2692. * @param addnowbutton Add a button "Now"
  2693. * @param nooutput Do not output html string but return it
  2694. * @param disabled Disable input fields
  2695. * @param fullday When a checkbox with this html name is on, hour and day are set with 00:00 or 23:59
  2696. * @return nothing or string if nooutput is 1
  2697. */
  2698. function select_date($set_time='', $prefix='re', $h=0, $m=0, $empty=0, $form_name="", $d=1, $addnowbutton=0, $nooutput=0, $disabled=0, $fullday='')
  2699. {
  2700. global $conf,$langs;
  2701. $retstring='';
  2702. if($prefix=='') $prefix='re';
  2703. if($h == '') $h=0;
  2704. if($m == '') $m=0;
  2705. if($empty == '') $empty=0;
  2706. if (! $set_time && $empty == 0) $set_time = dol_now('tzuser');
  2707. // Analysis of the pre-selection date
  2708. if (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+)\s?([0-9]+)?:?([0-9]+)?/',$set_time,$reg))
  2709. {
  2710. // Date format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'
  2711. $syear = $reg[1];
  2712. $smonth = $reg[2];
  2713. $sday = $reg[3];
  2714. $shour = $reg[4];
  2715. $smin = $reg[5];
  2716. }
  2717. elseif (strval($set_time) != '' && $set_time != -1)
  2718. {
  2719. // set_time est un timestamps (0 possible)
  2720. $syear = dol_print_date($set_time, "%Y");
  2721. $smonth = dol_print_date($set_time, "%m");
  2722. $sday = dol_print_date($set_time, "%d");
  2723. $shour = dol_print_date($set_time, "%H");
  2724. $smin = dol_print_date($set_time, "%M");
  2725. }
  2726. else
  2727. {
  2728. // Date est '' ou vaut -1
  2729. $syear = '';
  2730. $smonth = '';
  2731. $sday = '';
  2732. $shour = '';
  2733. $smin = '';
  2734. }
  2735. if ($d)
  2736. {
  2737. // Show date with popup
  2738. if ($conf->use_javascript_ajax && (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR != "none"))
  2739. {
  2740. //print "e".$set_time." t ".$conf->format_date_short;
  2741. if (strval($set_time) != '' && $set_time != -1)
  2742. {
  2743. //$formated_date=dol_print_date($set_time,$conf->format_date_short);
  2744. $formated_date=dol_print_date($set_time,$langs->trans("FormatDateShort")); // FormatDateShort for dol_print_date/FormatDateShortJava that is same for javascript
  2745. }
  2746. // Calendrier popup version eldy
  2747. if (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == "eldy")
  2748. {
  2749. // Zone de saisie manuelle de la date
  2750. $retstring.='<input id="'.$prefix.'" name="'.$prefix.'" type="text" size="9" maxlength="11" value="'.$formated_date.'"';
  2751. $retstring.=($disabled?' disabled="disabled"':'');
  2752. $retstring.=' onChange="dpChangeDay(\''.$prefix.'\',\''.$langs->trans("FormatDateShortJava").'\'); "'; // FormatDateShort for dol_print_date/FormatDateShortJava that is same for javascript
  2753. $retstring.='>';
  2754. // Icone calendrier
  2755. if (! $disabled)
  2756. {
  2757. $retstring.='<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons"';
  2758. $base=DOL_URL_ROOT.'/lib/';
  2759. $retstring.=' onClick="showDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJava").'\',\''.$langs->defaultlang.'\');">'.img_object($langs->trans("SelectDate"),'calendarday').'</button>';
  2760. }
  2761. $retstring.='<input type="hidden" id="'.$prefix.'day" name="'.$prefix.'day" value="'.$sday.'">'."\n";
  2762. $retstring.='<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n";
  2763. $retstring.='<input type="hidden" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">'."\n";
  2764. }
  2765. else
  2766. {
  2767. print "Bad value of calendar";
  2768. }
  2769. }
  2770. // Show date with combo selects
  2771. if (empty($conf->use_javascript_ajax) || $conf->global->MAIN_POPUP_CALENDAR == "none")
  2772. {
  2773. // Day
  2774. $retstring.='<select'.($disabled?' disabled="disabled"':'').' class="flat" name="'.$prefix.'day">';
  2775. if ($empty || $set_time == -1)
  2776. {
  2777. $retstring.='<option value="0" selected="selected">&nbsp;</option>';
  2778. }
  2779. for ($day = 1 ; $day <= 31; $day++)
  2780. {
  2781. if ($day == $sday)
  2782. {
  2783. $retstring.="<option value=\"$day\" selected=\"selected\">$day";
  2784. }
  2785. else
  2786. {
  2787. $retstring.="<option value=\"$day\">$day";
  2788. }
  2789. $retstring.="</option>";
  2790. }
  2791. $retstring.="</select>";
  2792. $retstring.='<select'.($disabled?' disabled="disabled"':'').' class="flat" name="'.$prefix.'month">';
  2793. if ($empty || $set_time == -1)
  2794. {
  2795. $retstring.='<option value="0" selected="selected">&nbsp;</option>';
  2796. }
  2797. // Month
  2798. for ($month = 1 ; $month <= 12 ; $month++)
  2799. {
  2800. $retstring.='<option value="'.$month.'"'.($month == $smonth?' selected="selected"':'').'>';
  2801. $retstring.=dol_print_date(mktime(12,0,0,$month,1,2000),"%b");
  2802. $retstring.="</option>";
  2803. }
  2804. $retstring.="</select>";
  2805. // Year
  2806. if ($empty || $set_time == -1)
  2807. {
  2808. $retstring.='<input'.($disabled?' disabled="disabled"':'').' class="flat" type="text" size="3" maxlength="4" name="'.$prefix.'year" value="'.$syear.'">';
  2809. }
  2810. else
  2811. {
  2812. $retstring.='<select'.($disabled?' disabled="disabled"':'').' class="flat" name="'.$prefix.'year">';
  2813. for ($year = $syear - 5; $year < $syear + 10 ; $year++)
  2814. {
  2815. if ($year == $syear)
  2816. {
  2817. $retstring.="<option value=\"$year\" selected=\"true\">".$year;
  2818. }
  2819. else
  2820. {
  2821. $retstring.="<option value=\"$year\">".$year;
  2822. }
  2823. $retstring.="</option>";
  2824. }
  2825. $retstring.="</select>\n";
  2826. }
  2827. }
  2828. }
  2829. if ($d && $h) $retstring.='&nbsp;';
  2830. if ($h)
  2831. {
  2832. // Show hour
  2833. $retstring.='<select'.($disabled?' disabled="disabled"':'').' class="flat '.($fullday?$fullday.'hour':'').'" name="'.$prefix.'hour">';
  2834. if ($empty) $retstring.='<option value="-1">&nbsp;</option>';
  2835. for ($hour = 0; $hour < 24; $hour++)
  2836. {
  2837. if (dol_strlen($hour) < 2)
  2838. {
  2839. $hour = "0" . $hour;
  2840. }
  2841. if ($hour == $shour)
  2842. {
  2843. $retstring.="<option value=\"$hour\" selected=\"true\">$hour</option>";
  2844. }
  2845. else
  2846. {
  2847. $retstring.="<option value=\"$hour\">$hour</option>";
  2848. }
  2849. }
  2850. $retstring.="</select>";
  2851. $retstring.="H\n";
  2852. }
  2853. if ($m)
  2854. {
  2855. // Show minutes
  2856. $retstring.='<select'.($disabled?' disabled="disabled"':'').' class="flat '.($fullday?$fullday.'min':'').'" name="'.$prefix.'min">';
  2857. if ($empty) $retstring.='<option value="-1">&nbsp;</option>';
  2858. for ($min = 0; $min < 60 ; $min++)
  2859. {
  2860. if (dol_strlen($min) < 2)
  2861. {
  2862. $min = "0" . $min;
  2863. }
  2864. if ($min == $smin)
  2865. {
  2866. $retstring.="<option value=\"$min\" selected=\"true\">$min</option>";
  2867. }
  2868. else
  2869. {
  2870. $retstring.="<option value=\"$min\">$min</option>";
  2871. }
  2872. }
  2873. $retstring.="</select>";
  2874. $retstring.="M\n";
  2875. }
  2876. // Add a "Now" button
  2877. if ($conf->use_javascript_ajax && $addnowbutton)
  2878. {
  2879. // Script which will be inserted in the OnClick of the "Now" button
  2880. $reset_scripts = "";
  2881. // Generate the date part, depending on the use or not of the javascript calendar
  2882. if (empty($conf->global->MAIN_POPUP_CALENDAR) || $conf->global->MAIN_POPUP_CALENDAR == "eldy")
  2883. {
  2884. $base=DOL_URL_ROOT.'/lib/';
  2885. $reset_scripts .= 'resetDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJava").'\',\''.$langs->defaultlang.'\');';
  2886. }
  2887. else
  2888. {
  2889. $reset_scripts .= 'this.form.elements[\''.$prefix.'day\'].value=formatDate(new Date(), \'d\'); ';
  2890. $reset_scripts .= 'this.form.elements[\''.$prefix.'month\'].value=formatDate(new Date(), \'M\'); ';
  2891. $reset_scripts .= 'this.form.elements[\''.$prefix.'year\'].value=formatDate(new Date(), \'yyyy\'); ';
  2892. }
  2893. // Generate the hour part
  2894. if ($h)
  2895. {
  2896. if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
  2897. $reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); ';
  2898. if ($fullday) $reset_scripts .= ' } ';
  2899. }
  2900. // Generate the minute part
  2901. if ($m)
  2902. {
  2903. if ($fullday) $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
  2904. $reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); ';
  2905. if ($fullday) $reset_scripts .= ' } ';
  2906. }
  2907. // If reset_scripts is not empty, print the button with the reset_scripts in OnClick
  2908. if ($reset_scripts)
  2909. {
  2910. $retstring.='<button class="dpInvisibleButtons" id="'.$prefix.'ButtonNow" type="button" name="_useless" value="Now" onClick="'.$reset_scripts.'">';
  2911. $retstring.=$langs->trans("Now");
  2912. $retstring.='</button> ';
  2913. }
  2914. }
  2915. if (! empty($nooutput)) return $retstring;
  2916. print $retstring;
  2917. return;
  2918. }
  2919. /**
  2920. * Function to show a form to select a duration on a page
  2921. *
  2922. * @param string $prefix prefix
  2923. * @param int $iSecond Default preselected duration (number of seconds)
  2924. * @param int $disabled Disable the combo box
  2925. * @return void
  2926. */
  2927. function select_duration($prefix,$iSecond='',$disabled=0)
  2928. {
  2929. if ($iSecond)
  2930. {
  2931. require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
  2932. $hourSelected = ConvertSecondToTime($iSecond,'hour');
  2933. $minSelected = ConvertSecondToTime($iSecond,'min');
  2934. }
  2935. print '<select class="flat" name="'.$prefix.'hour"'.($disabled?' disabled="disabled"':'').'>';
  2936. for ($hour = 0; $hour < 24; $hour++)
  2937. {
  2938. print '<option value="'.$hour.'"';
  2939. if ($hourSelected == $hour)
  2940. {
  2941. print " selected=\"true\"";
  2942. }
  2943. print ">".$hour."</option>";
  2944. }
  2945. print "</select>";
  2946. print "H &nbsp;";
  2947. print '<select class="flat" name="'.$prefix.'min"'.($disabled?' disabled="disabled"':'').'>';
  2948. for ($min = 0; $min <= 55; $min=$min+5)
  2949. {
  2950. print '<option value="'.$min.'"';
  2951. if ($minSelected == $min) print ' selected="selected"';
  2952. print '>'.$min.'</option>';
  2953. }
  2954. print "</select>";
  2955. print "M&nbsp;";
  2956. }
  2957. /**
  2958. * Show a select form from an array
  2959. *
  2960. * @param htmlname Name of html select area
  2961. * @param array Array with key+value
  2962. * @param id Preselected key
  2963. * @param show_empty 1 si il faut ajouter une valeur vide dans la liste, 0 sinon
  2964. * @param key_in_label 1 pour afficher la key dans la valeur "[key] value"
  2965. * @param value_as_key 1 to use value as key
  2966. * @param option Valeur de l'option en fonction du type choisi
  2967. * @param translate Translate and encode value
  2968. * @param maxlen Length maximum for labels
  2969. * @param disabled Html select box is disabled
  2970. * @return string HTML select string
  2971. */
  2972. function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0, $disabled=0)
  2973. {
  2974. global $langs;
  2975. $out='<select id="'.$htmlname.'" '.($disabled?'disabled="disabled" ':'').'class="flat" name="'.$htmlname.'" '.($option != ''?$option:'').'>';
  2976. if ($show_empty)
  2977. {
  2978. $out.='<option value="-1"'.($id==-1?' selected="selected"':'').'>&nbsp;</option>'."\n";
  2979. }
  2980. if (is_array($array))
  2981. {
  2982. foreach($array as $key => $value)
  2983. {
  2984. $out.='<option value="'.($value_as_key?$value:$key).'"';
  2985. // Si il faut pre-selectionner une valeur
  2986. if ($id != '' && ($id == $key || $id == $value))
  2987. {
  2988. $out.=' selected="selected"';
  2989. }
  2990. $out.='>';
  2991. if ($key_in_label)
  2992. {
  2993. $newval=($translate?$langs->trans($value):$value);
  2994. $selectOptionValue = dol_htmlentitiesbr($key.' - '.($maxlen?dol_trunc($newval,$maxlen):$newval));
  2995. $out.=$selectOptionValue;
  2996. }
  2997. else
  2998. {
  2999. $newval=($translate?$langs->trans($value):$value);
  3000. $selectOptionValue = dol_htmlentitiesbr($maxlen?dol_trunc($newval,$maxlen):$newval);
  3001. if ($value == '' || $value == '-') { $selectOptionValue='&nbsp;'; }
  3002. $out.=$selectOptionValue;
  3003. }
  3004. $out.="</option>\n";
  3005. }
  3006. }
  3007. $out.="</select>";
  3008. return $out;
  3009. }
  3010. /**
  3011. * Show a select form from an array
  3012. *
  3013. * @deprecated Use selectarray instead
  3014. * @return void
  3015. */
  3016. function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $option='', $translate=0, $maxlen=0)
  3017. {
  3018. print $this->selectarray($htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, $option, $translate, $maxlen);
  3019. }
  3020. /**
  3021. * Return an html string with a select combo box to choose yes or no
  3022. *
  3023. * @param name Name of html select field
  3024. * @param value Pre-selected value
  3025. * @param option 0 return yes/no, 1 return 1/0
  3026. * @return int or string See option
  3027. */
  3028. function selectyesno($htmlname,$value='',$option=0)
  3029. {
  3030. global $langs;
  3031. $yes="yes"; $no="no";
  3032. if ($option)
  3033. {
  3034. $yes="1";
  3035. $no="0";
  3036. }
  3037. $resultyesno = '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'."\n";
  3038. if (("$value" == 'yes') || ($value == 1))
  3039. {
  3040. $resultyesno .= '<option value="'.$yes.'" selected="selected">'.$langs->trans("Yes").'</option>'."\n";
  3041. $resultyesno .= '<option value="'.$no.'">'.$langs->trans("No").'</option>'."\n";
  3042. }
  3043. else
  3044. {
  3045. $resultyesno .= '<option value="'.$yes.'">'.$langs->trans("Yes").'</option>'."\n";
  3046. $resultyesno .= '<option value="'.$no.'" selected="selected">'.$langs->trans("No").'</option>'."\n";
  3047. }
  3048. $resultyesno .= '</select>'."\n";
  3049. return $resultyesno;
  3050. }
  3051. /**
  3052. * Return list of export templates
  3053. *
  3054. * @param selected Id modele pre-selectionne
  3055. * @param htmlname Nom de la zone select
  3056. * @param type Type des modeles recherches
  3057. * @param useempty Affiche valeur vide dans liste
  3058. * @return void
  3059. */
  3060. function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
  3061. {
  3062. $sql = "SELECT rowid, label";
  3063. $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
  3064. $sql.= " WHERE type = '".$type."'";
  3065. $sql.= " ORDER BY rowid";
  3066. $result = $this->db->query($sql);
  3067. if ($result)
  3068. {
  3069. print '<select class="flat" name="'.$htmlname.'">';
  3070. if ($useempty)
  3071. {
  3072. print '<option value="-1">&nbsp;</option>';
  3073. }
  3074. $num = $this->db->num_rows($result);
  3075. $i = 0;
  3076. while ($i < $num)
  3077. {
  3078. $obj = $this->db->fetch_object($result);
  3079. if ($selected == $obj->rowid)
  3080. {
  3081. print '<option value="'.$obj->rowid.'" selected="selected">';
  3082. }
  3083. else
  3084. {
  3085. print '<option value="'.$obj->rowid.'">';
  3086. }
  3087. print $obj->label;
  3088. print '</option>';
  3089. $i++;
  3090. }
  3091. print "</select>";
  3092. }
  3093. else {
  3094. dol_print_error($this->db);
  3095. }
  3096. }
  3097. /**
  3098. * Return a HTML area with the reference of object and a navigation bar for a business object
  3099. * To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria.
  3100. *
  3101. * @param object Object to show
  3102. * @param paramid Name of parameter to use to name the id into the URL link
  3103. * @param morehtml More html content to output just before the nav bar
  3104. * @param shownav Show Condition (navigation is shown if value is 1)
  3105. * @param fieldid Nom du champ en base a utiliser pour select next et previous
  3106. * @param fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous
  3107. * @param morehtmlref Code html supplementaire a afficher apres ref
  3108. * @param moreparam More param to add in nav link url.
  3109. * @return string Portion HTML avec ref + boutons nav
  3110. */
  3111. function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='')
  3112. {
  3113. $ret='';
  3114. //print "$paramid,$morehtml,$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam";
  3115. $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid);
  3116. $previous_ref = $object->ref_previous?'<a href="'.$_SERVER["PHP_SELF"].'?'.$paramid.'='.urlencode($object->ref_previous).$moreparam.'">'.img_previous().'</a>':'';
  3117. $next_ref = $object->ref_next?'<a href="'.$_SERVER["PHP_SELF"].'?'.$paramid.'='.urlencode($object->ref_next).$moreparam.'">'.img_next().'</a>':'';
  3118. //print "xx".$previous_ref."x".$next_ref;
  3119. if ($previous_ref || $next_ref || $morehtml) {
  3120. $ret.='<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">';
  3121. }
  3122. $ret.=$object->$fieldref;
  3123. if ($morehtmlref) {
  3124. $ret.=' '.$morehtmlref;
  3125. }
  3126. if ($morehtml) {
  3127. $ret.='</td><td class="nobordernopadding" align="right">'.$morehtml;
  3128. }
  3129. if ($shownav && ($previous_ref || $next_ref)) {
  3130. $ret.='</td><td class="nobordernopadding" align="center" width="20">'.$previous_ref.'</td>';
  3131. $ret.='<td class="nobordernopadding" align="center" width="20">'.$next_ref;
  3132. }
  3133. if ($previous_ref || $next_ref || $morehtml)
  3134. {
  3135. $ret.='</td></tr></table>';
  3136. }
  3137. return $ret;
  3138. }
  3139. /**
  3140. * Return HTML code to output a photo
  3141. *
  3142. * @param modulepart Key to define module concerned ('societe', 'userphoto', 'memberphoto')
  3143. * @param object Object containing data to retrieve file name
  3144. * @param width Width of photo
  3145. * @return string HTML code to output photo
  3146. */
  3147. function showphoto($modulepart,$object,$width=100)
  3148. {
  3149. global $conf;
  3150. $ret='';$dir='';$file='';$altfile='';$email='';
  3151. if ($modulepart=='societe')
  3152. {
  3153. $dir=$conf->societe->dir_output;
  3154. $smallfile=$object->logo;
  3155. $smallfile=preg_replace('/(\.png|\.gif|\.jpg|\.jpeg|\.bmp)/i','_small\\1',$smallfile);
  3156. if ($object->logo) $file=$object->id.'/logos/thumbs/'.$smallfile;
  3157. }
  3158. else if ($modulepart=='userphoto')
  3159. {
  3160. $dir=$conf->user->dir_output;
  3161. if ($object->photo) $file=get_exdir($object->id,2).$object->photo;
  3162. if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
  3163. $email=$object->email;
  3164. }
  3165. else if ($modulepart=='memberphoto')
  3166. {
  3167. $dir=$conf->adherent->dir_output;
  3168. if ($object->photo) $file=get_exdir($object->id,2).'photos/'.$object->photo;
  3169. if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility
  3170. $email=$object->email;
  3171. }
  3172. if ($dir)
  3173. {
  3174. $cache='0';
  3175. if ($file && file_exists($dir."/".$file))
  3176. {
  3177. // TODO Link to large image
  3178. $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
  3179. $ret.='<img alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
  3180. $ret.='</a>';
  3181. }
  3182. else if ($altfile && file_exists($dir."/".$altfile))
  3183. {
  3184. $ret.='<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($file).'&cache='.$cache.'">';
  3185. $ret.='<img alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i','_',$file)).'" class="photologo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&file='.urlencode($altfile).'&cache='.$cache.'">';
  3186. $ret.='</a>';
  3187. }
  3188. else
  3189. {
  3190. if ($conf->gravatar->enabled && $email)
  3191. {
  3192. global $dolibarr_main_url_root;
  3193. $ret.='<!-- Put link to gravatar -->';
  3194. $ret.='<img alt="Photo found on Gravatar" title="Photo Gravatar.com - email '.$email.'" border="0" width="'.$width.'" src="http://www.gravatar.com/avatar/'.dol_hash($email).'?s='.$width.'&d='.urlencode( dol_buildpath('/theme/common/nophoto.jpg',2) ).'">';
  3195. }
  3196. else
  3197. {
  3198. $ret.='<img alt="No photo" border="0" width="'.$width.'" src="'.DOL_URL_ROOT.'/theme/common/nophoto.jpg">';
  3199. }
  3200. }
  3201. }
  3202. else dol_print_error('','Call of showphoto with wrong parameters');
  3203. /* Disabled. lightbox seems to not work. I don't know why.
  3204. $ret.="\n<script type=\"text/javascript\">
  3205. jQuery(function() {
  3206. jQuery('.photologo').lightBox();
  3207. });
  3208. </script>\n";
  3209. $ret.="\n<script type=\"text/javascript\">
  3210. jQuery(function() {
  3211. jQuery('.photologo').lightBox({
  3212. overlayBgColor: '#FFF',
  3213. overlayOpacity: 0.6,
  3214. imageLoading: '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-ico-loading.gif',
  3215. imageBtnClose: '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-close.gif',
  3216. imageBtnPrev: '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-prev.gif',
  3217. imageBtnNext: '".DOL_URL_ROOT."/includes/jquery/plugins/lightbox/images/lightbox-btn-next.gif',
  3218. containerResizeSpeed: 350,
  3219. txtImage: 'Imagem',
  3220. txtOf: 'de'
  3221. });
  3222. });
  3223. </script>\n";
  3224. */
  3225. return $ret;
  3226. }
  3227. /**
  3228. * Return select list of groups
  3229. *
  3230. * @param string $selected Id group preselected
  3231. * @param string $htmlname Field name in form
  3232. * @param int $show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
  3233. * @param string $exclude Array list of groups id to exclude
  3234. * @param int $disabled If select list must be disabled
  3235. * @param string $include Array list of groups id to include
  3236. * @param int $enableonly Array list of groups id to be enabled. All other must be disabled
  3237. * @param int $force_entity Possibility to force entity
  3238. * @return void
  3239. */
  3240. function select_dolgroups($selected='',$htmlname='groupid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity='')
  3241. {
  3242. global $conf,$user,$langs;
  3243. // Permettre l'exclusion de groupes
  3244. if (is_array($exclude)) $excludeGroups = implode("','",$exclude);
  3245. // Permettre l'inclusion de groupes
  3246. if (is_array($include)) $includeGroups = implode("','",$include);
  3247. $out='';
  3248. // On recherche les groupes
  3249. $sql = "SELECT ug.rowid, ug.nom ";
  3250. if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
  3251. {
  3252. $sql.= ", e.label";
  3253. }
  3254. $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug ";
  3255. if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
  3256. {
  3257. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e on e.rowid=ug.entity";
  3258. if ($force_entity) $sql.= " WHERE ug.entity IN (0,".$force_entity.")";
  3259. else $sql.= " WHERE ug.entity IS NOT NULL";
  3260. }
  3261. else
  3262. {
  3263. $sql.= " WHERE ug.entity IN (0,".$conf->entity.")";
  3264. }
  3265. if (is_array($exclude) && $excludeGroups) $sql.= " AND ug.rowid NOT IN ('".$excludeGroups."')";
  3266. if (is_array($include) && $includeGroups) $sql.= " AND ug.rowid IN ('".$includeGroups."')";
  3267. $sql.= " ORDER BY ug.nom ASC";
  3268. dol_syslog("Form::select_dolgroups sql=".$sql);
  3269. $resql=$this->db->query($sql);
  3270. if ($resql)
  3271. {
  3272. $num = $this->db->num_rows($resql);
  3273. $i = 0;
  3274. if ($num)
  3275. {
  3276. $out.= '<select class="flat" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>';
  3277. if ($show_empty) $out.= '<option value="-1"'.($id==-1?' selected="selected"':'').'>&nbsp;</option>'."\n";
  3278. while ($i < $num)
  3279. {
  3280. $obj = $this->db->fetch_object($resql);
  3281. $disableline=0;
  3282. if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
  3283. $out.= '<option value="'.$obj->rowid.'"';
  3284. if ($disableline) $out.= ' disabled="disabled"';
  3285. if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
  3286. {
  3287. $out.= ' selected="selected"';
  3288. }
  3289. $out.= '>';
  3290. $out.= $obj->nom;
  3291. if(! empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1)
  3292. {
  3293. $out.= " (".$obj->label.")";
  3294. }
  3295. $out.= '</option>';
  3296. $i++;
  3297. }
  3298. }
  3299. else
  3300. {
  3301. $out.= '<select class="flat" name="'.$htmlname.'" disabled="disabled">';
  3302. $out.= '<option value="">'.$langs->trans("EmptyList").'</option>';
  3303. }
  3304. $out.= '</select>';
  3305. }
  3306. else
  3307. {
  3308. dol_print_error($this->db);
  3309. }
  3310. return $out;
  3311. }
  3312. }
  3313. ?>