BxBaseFormView.php 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseFormView extends BxDolForm
  10. {
  11. protected static $_isToggleJsAdded = false;
  12. protected static $_isCssJsAdded = false;
  13. protected static $_isCssJsUiAdded = false;
  14. protected static $_isCssJsUiSortableAdded = false;
  15. protected static $_isCssJsMinicolorsAdded = false;
  16. protected static $_isCssJsLabelsAdded = false;
  17. protected static $_isCssJsTimepickerAdded = false;
  18. protected static $_isCssJsAddedViewMode = false;
  19. /**
  20. * Enable or disable error message displaying
  21. */
  22. protected $bEnableErrorIcon = true;
  23. /**
  24. * HTML Code of this form
  25. */
  26. protected $sCode;
  27. /**
  28. * Code which will be added to the beginning of the form.
  29. * For example, hidden inputs.
  30. * For internal use only
  31. */
  32. protected $_sCodeAdd = '';
  33. /**
  34. * for internal use only
  35. */
  36. protected $_isSectionOpened = false;
  37. /**
  38. * Default divider for several inputs
  39. */
  40. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  41. /**
  42. * Alternative divider for several inputs
  43. */
  44. protected $_sDividerAlt = '<div class="bx-form-input-dv-nl"></div>';
  45. /**
  46. * Form is added dynamically.
  47. */
  48. protected $_bDynamicMode = false;
  49. /**
  50. * Form is submitted dynamically (using Ajax Submit).
  51. */
  52. protected $_bAjaxMode = false;
  53. /**
  54. * Use absolute Action URL which is needed in Ajax Mode.
  55. */
  56. protected $_bAbsoluteActionUrl = false;
  57. /**
  58. * Form is displayed in view mode.
  59. */
  60. protected $_bViewMode = false;
  61. /**
  62. * Show or not sections which have no fileds
  63. */
  64. protected $_bShowEmptySections = false;
  65. /**
  66. * Function name for generation close form section HTML.
  67. */
  68. protected $_sSectionClose = 'getCloseSection';
  69. /**
  70. * Function name for generation open form section HTML.
  71. */
  72. protected $_sSectionOpen = 'getOpenSection';
  73. /**
  74. * JS files list for form
  75. */
  76. protected $_aJs = array();
  77. /**
  78. * CSS files list for form
  79. */
  80. protected $_aCss = array();
  81. protected $_sJsClassName;
  82. protected $_sJsObjectName;
  83. protected $_aHtmlIds;
  84. /**
  85. * Constructor
  86. *
  87. * @param array $aInfo Form contents
  88. *
  89. * $aInfo['params'] = array(
  90. * 'remove_form' => true|false,
  91. * );
  92. *
  93. * @return BxBaseFormView
  94. */
  95. function __construct($aInfo, $oTemplate)
  96. {
  97. parent::__construct($aInfo, $oTemplate);
  98. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  99. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  100. if($this->_bViewMode) {
  101. $this->_sSectionClose = 'getCloseSectionViewMode';
  102. $this->_sSectionOpen = 'getOpenSectionViewMode';
  103. }
  104. $this->_sJsClassName = 'BxDolForm';
  105. $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : '';
  106. if(empty($sName) && !empty($aInfo['params']['object']))
  107. $sName = $aInfo['params']['object'];
  108. $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-'));
  109. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName);
  110. $this->_aHtmlIds = array(
  111. 'help_popup' => $sHtmlId . '-help-popup-',
  112. 'pgc' => $sHtmlId . '-pgc-',
  113. 'pgc_popup' => $sHtmlId . '-pgc-popup-',
  114. 'pgc_form' => $sHtmlId . '-pgc-form-',
  115. );
  116. }
  117. public function performActionGetHelp()
  118. {
  119. $sInput = bx_process_input(bx_get('input'));
  120. if(empty($sInput) || empty($this->aInputs[$sInput]['help']))
  121. return;
  122. echo $this->oTemplate->parseHtmlByName('form_field_help_popup.html', array(
  123. 'content' => _t($this->aInputs[$sInput]['help']),
  124. 'bx_if:show_edit' => array(
  125. 'condition' => isAdmin(),
  126. 'content' => array(
  127. 'link' => BX_DOL_URL_STUDIO . bx_append_url_params('builder_forms.php', array(
  128. 'page' => 'fields',
  129. 'module' => $this->aParams['module'],
  130. 'object' => $this->aParams['object'],
  131. 'display' => $this->aParams['display']
  132. ))
  133. )
  134. )
  135. ));
  136. }
  137. public function performActionChangePrivacyGroup()
  138. {
  139. $iAuthorId = (int)bx_get_logged_profile_id();
  140. if(empty($iAuthorId))
  141. return echoJson(array());
  142. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  143. if(empty($iInputId))
  144. return echoJson(array());
  145. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  146. $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject);
  147. if(empty($sPrivacyField))
  148. return echoJson(array());
  149. $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField));
  150. if(empty($sPrivacyField))
  151. return echoJson(array());
  152. if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup))
  153. return echoJson(array());
  154. return echoJson(array(
  155. 'code' => 0,
  156. 'form_id' => $this->getId(),
  157. 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  158. 'icon' => $this->_getPrivacyIcon($sPrivacyGroup),
  159. 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);'
  160. ));
  161. }
  162. public function performActionGetPrivacyGroupChooser()
  163. {
  164. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  165. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  166. if(empty($iInputId) || empty($sPrivacyObject))
  167. return '';
  168. $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId;
  169. $aFormActionParams = array();
  170. if(!empty($this->aParams['object']) && !empty($this->aParams['display']))
  171. $aFormActionParams = array(
  172. 'o' => $this->aParams['object'],
  173. 'd' => $this->aParams['display']
  174. );
  175. $aFormActionParams['a'] = 'change_privacy_group';
  176. $iAuthorId = bx_get_logged_profile_id();
  177. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  178. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  179. $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId);
  180. $aInputPgc['value'] = $mixedPrivacyGroup;
  181. if(!isset($aInputPgc['content']))
  182. $aInputPgc['content'] = '';
  183. $aInputPgc['content'] .= $oPrivacy->addCssJs(true);
  184. $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array(
  185. 'content_id' => $iInputId,
  186. 'group_id' => $mixedPrivacyGroup,
  187. 'html_ids' => array(
  188. 'form' => $sFormId
  189. )
  190. ));
  191. $aFormInfo = array(
  192. 'form_attrs' => array(
  193. 'id' => $sFormId,
  194. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams),
  195. 'method' => 'post'
  196. ),
  197. 'inputs' => array (
  198. 'input_id' => array(
  199. 'type' => 'hidden',
  200. 'name' => 'input_id',
  201. 'value' => $iInputId,
  202. 'db' => array (
  203. 'pass' => 'Int',
  204. ),
  205. ),
  206. 'privacy_object' => array(
  207. 'type' => 'hidden',
  208. 'name' => 'privacy_object',
  209. 'value' => $sPrivacyObject,
  210. 'db' => array (
  211. 'pass' => 'Xss',
  212. ),
  213. ),
  214. 'privacy_group_chooser' => $aInputPgc,
  215. 'controls' => array(
  216. 'name' => 'controls',
  217. 'type' => 'input_set',
  218. array(
  219. 'type' => 'button',
  220. 'name' => 'do_submit',
  221. 'value' => _t('_sys_submit'),
  222. 'attrs' => array(
  223. 'onclick' => "$('#" . $sFormId . "').submit()",
  224. ),
  225. ),
  226. array (
  227. 'type' => 'reset',
  228. 'name' => 'do_cancel',
  229. 'value' => _t('_Cancel'),
  230. 'attrs' => array(
  231. 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()",
  232. 'class' => 'bx-def-margin-sec-left',
  233. ),
  234. )
  235. )
  236. )
  237. );
  238. $oForm = new BxTemplFormView($aFormInfo);
  239. echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array(
  240. 'form_id' => $oForm->getId(),
  241. 'form' => $oForm->getCode(true),
  242. ));
  243. }
  244. function setShowEmptySections($b)
  245. {
  246. $this->_bShowEmptySections = $b;
  247. }
  248. function setAjaxMode($bAjaxMode)
  249. {
  250. $this->_bAjaxMode = (bool)$bAjaxMode;
  251. }
  252. function isAjaxMode()
  253. {
  254. return $this->_bAjaxMode;
  255. }
  256. function setAbsoluteActionUrl($sUrl)
  257. {
  258. if(empty($sUrl))
  259. return;
  260. $this->aFormAttrs['action'] = $sUrl;
  261. $this->_bAbsoluteActionUrl = true;
  262. }
  263. /**
  264. * Return Form code
  265. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  266. * @return string
  267. */
  268. function getCode($bDynamicMode = false)
  269. {
  270. if(!$bDynamicMode && bx_is_dynamic_request())
  271. $bDynamicMode = true;
  272. $this->_bDynamicMode = $bDynamicMode;
  273. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  274. $sInclude = '';
  275. $this->sCode = false;
  276. /**
  277. * @hooks
  278. * @hookdef hook-system-form_output 'system', 'form_output' - hook to override form object and/or code to be output
  279. * - $unit_name - equals `system`
  280. * - $action - equals `form_output`
  281. * - $object_id - not used
  282. * - $sender_id - not used
  283. * - $extra_params - array of additional params with the following array keys:
  284. * - `dynamic` - [boolean] is dynamic mode
  285. * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing
  286. * - `code` - [boolean] or [string] by ref, when false the default generation mechanism will be used, can be overridden in hook processing
  287. * - `include` - [string] by ref, additional data to be attached to output, can be overridden in hook processing
  288. * @hook @ref hook-system-form_output
  289. */
  290. bx_alert('system', 'form_output', 0, 0, [
  291. 'dynamic' => $this->_bDynamicMode,
  292. 'object' => &$this,
  293. 'code' => &$this->sCode,
  294. 'include' => &$sInclude
  295. ]);
  296. if($this->sCode === false)
  297. $this->sCode = $this->genForm();
  298. $this->addCssJs();
  299. $sDynamicCssJs = $this->_processCssJs();
  300. return $sInclude . $sDynamicCssJs . $this->sCode;
  301. }
  302. function getCodeAPI()
  303. {
  304. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  305. $this->sCode = false;
  306. /**
  307. * @hooks
  308. * @hookdef hook-system-form_output_api 'system', 'form_output_api' - hook to override form object and/or code to be output. Is used in API calls.
  309. * - $unit_name - equals `system`
  310. * - $action - equals `form_output_api`
  311. * - $object_id - not used
  312. * - $sender_id - not used
  313. * - $extra_params - array of additional params with the following array keys:
  314. * - `dynamic` - [boolean] is dynamic mode
  315. * - `object` - [object] by ref, an instance of form class, @see BxDolForm, can be overridden in hook processing
  316. * - `code` - [boolean] by ref, when false the default generation mechanism will be used, can be overridden in hook processing
  317. * @hook @ref hook-system-form_output_api
  318. */
  319. bx_alert('system', 'form_output_api', 0, 0, [
  320. 'dynamic' => $this->_bDynamicMode,
  321. 'object' => &$this,
  322. 'code' => &$this->sCode,
  323. ]);
  324. if($this->sCode === false)
  325. $this->genForm();
  326. // TODO: process inputs to translate titles, alerts, etc
  327. $keysToRemove = [];
  328. foreach ($this->aInputs as $key => &$aInput) {
  329. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  330. if (isset($aInput['type']) && 'files' == $aInput['type']){
  331. $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']);
  332. $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow'];
  333. $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny'];
  334. $aInput['ghost_template'] = '';
  335. $aInput['value'] = '';
  336. $aInput['values'] = '';
  337. $aInput['values_src'] = '';
  338. }
  339. if (isset($aInput['type']) && 'custom' == $aInput['type']){
  340. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  341. if (method_exists($this, $sCustomMethod))
  342. $aInput = $this->$sCustomMethod($aInput);
  343. }
  344. if (isset($aInput['type']) && 'block_header' == $aInput['type']){
  345. $aInput['name'] = $key;
  346. }
  347. if (isset($aInput['type']) && 'block_header' == $aInput['type']){
  348. $aInput['name'] = $key;
  349. }
  350. if (isset($aInput['type']) && 'location' == $aInput['type']){
  351. $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;
  352. $aVars = [];
  353. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  354. foreach ($aLocationIndexes as $sKey)
  355. $aVars[$sKey] = $o->getLocationVal($aInput, $sKey, $this);
  356. if ($aVars['country']) {
  357. $aCountries = BxDolFormQuery::getDataItems('Country');
  358. $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  359. $aVars['location_string'] = $sLocationString;
  360. }
  361. $aInput['value'] = $aVars;
  362. }
  363. if (isset($aInput['type']) && 'textarea' == $aInput['type']){
  364. if (isset($aInput['value'], $aInput['html']) && (int)$aInput['html'] == 0)
  365. $aInput['value'] = strip_tags($aInput['value']);
  366. }
  367. if (isset($aInput['type'], $aInput['values_src']) && in_array($aInput['type'], ['select', 'select_multiple', 'checkbox_set', 'radio_set']) && strncmp(BX_DATA_LISTS_KEY_PREFIX, $aInput['values_src'], 2) === 0) {
  368. $aInput['values'] = array_map(function($sKey) use($aInput) {
  369. return ['key' => $sKey, 'value' => $aInput['values'][$sKey]];
  370. }, array_keys($aInput['values']));
  371. }
  372. if(isset($aInput['name']) && in_array($aInput['name'], ['allow_view_to', 'object_privacy_view'])) {
  373. $aParams = bx_get('params');
  374. if(empty($aParams) || !is_array($aParams))
  375. $aParams = [];
  376. if(!isset($aParams['context_id']) || ($iContextId = (int)$aParams['context_id']) >= 0) {
  377. $oProfile = BxDolProfile::getInstance();
  378. foreach($aInput['values'] as $aValue) {
  379. //--- Selected friends
  380. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_FRIENDS_SELECTED) {
  381. $aIds = BxDolConnection::getObjectInstance('sys_profiles_friends')->getConnectedContent($oProfile->id(), true, 0, 20);
  382. if(!empty($aIds) && is_array($aIds)) {
  383. $aInput['values_friends'] = [];
  384. foreach($aIds as $iId)
  385. $aInput['values_friends'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)];
  386. }
  387. }
  388. //--- Selected relations
  389. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_RELATIONS_SELECTED) {
  390. $aIds = BxDolConnection::getObjectInstance('sys_profiles_relations')->getConnectedContent($oProfile->id(), true, 0, 20);
  391. if(!empty($aIds) && is_array($aIds)) {
  392. $aInput['values_relations'] = [];
  393. foreach($aIds as $iId)
  394. $aInput['values_relations'][] = ['key' => $iId, 'value' => BxDolProfile::getData($iId)];
  395. }
  396. }
  397. //--- Selected memberships
  398. if(isset($aValue['key']) && (int)$aValue['key'] == BX_DOL_PG_MEMBERSHIPS_SELECTED) {
  399. $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
  400. if(!empty($aLevels) && is_array($aLevels)) {
  401. $aInput['values_memberships'] = [];
  402. foreach($aLevels as $iId => $sTitle)
  403. $aInput['values_memberships'][] = ['key' => $iId, 'value' => $sTitle];
  404. }
  405. }
  406. }
  407. }
  408. else
  409. $aInput = array_merge($aInput, [
  410. 'type' => 'hidden',
  411. 'value' => $iContextId,
  412. 'owner_info' => BxDolProfile::getData(abs($iContextId))
  413. ]);
  414. }
  415. }
  416. else{
  417. $keysToRemove[] = $key;
  418. }
  419. }
  420. foreach ($keysToRemove as $key) {
  421. unset($this->aInputs[$key]);
  422. }
  423. return ['inputs' => $this->aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams];
  424. }
  425. public function getJsClassName()
  426. {
  427. return $this->_sJsClassName;
  428. }
  429. public function getJsObjectName()
  430. {
  431. return $this->_sJsObjectName;
  432. }
  433. public function getJsScript($bWrap = false)
  434. {
  435. $sJsObjName = $this->getJsObjectName();
  436. $sJsObjClass = $this->getJsClassName();
  437. $sCode = "if(window['" . $sJsObjName . "'] == undefined) window['" . $sJsObjName . "'] = new " . $sJsObjClass . "(" . json_encode(array(
  438. 'sObjName' => $sJsObjName,
  439. 'sName' => $this->getName(),
  440. 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '',
  441. 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '',
  442. 'sRootUrl' => BX_DOL_URL_ROOT,
  443. 'aHtmlIds' => $this->_aHtmlIds,
  444. 'bLeavePageConfirmation' => getParam('sys_form_lpc_enable') == 'on',
  445. 'sTxtLeavePageConfirmation' => _t('_sys_leave_page_confirmation')
  446. )) . ");";
  447. return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode;
  448. }
  449. /**
  450. * Generate the whole form
  451. *
  452. * @return string
  453. */
  454. function genForm()
  455. {
  456. $this->_sCodeAdd = '';
  457. $sTable = $this->genRows();
  458. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  459. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  460. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  461. $sForm = <<<BLAH
  462. $sHtmlBefore
  463. {$this->_sCodeAdd}
  464. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  465. $sTable
  466. </div>
  467. $sHtmlAfter
  468. BLAH;
  469. } else {
  470. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  471. $sAjaxFormJs = '';
  472. if($this->_bAjaxMode)
  473. $sAjaxFormJs = <<<BLAH
  474. $("form#{$this->id}").ajaxForm({
  475. dataType: "json",
  476. beforeSubmit: function (formData, jqForm, options) {
  477. bx_loading($("form#{$this->id}"), true);
  478. },
  479. success: function (oData) {
  480. bx_loading($("form#{$this->id}"), false);
  481. processJsonData(oData);
  482. }
  483. });
  484. BLAH;
  485. $sJsCodeDynamic = '';
  486. if($this->_bDynamicMode)
  487. $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}';
  488. $sForm = <<<BLAH
  489. $sHtmlBefore
  490. <form $sFormAttrs>
  491. {$this->_sCodeAdd}
  492. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  493. $sTable
  494. </div>
  495. </form>
  496. <script>
  497. $(document).ready(function() {
  498. $(this).addWebForms($sJsCodeDynamic);
  499. });
  500. $sAjaxFormJs
  501. </script>
  502. $sHtmlAfter
  503. BLAH;
  504. }
  505. if(!$this->_bDynamicMode)
  506. $sForm = $sForm . $this->getJsScript(true);
  507. return $sForm;
  508. }
  509. /**
  510. * Generate Table HTML code
  511. *
  512. * @return string
  513. */
  514. function genRows()
  515. {
  516. // add CSRF token if it's needed.
  517. if (!(isset($this->aParams['view_mode']) && $this->aParams['view_mode']) && getParam('sys_security_form_token_enable') == 'on' && (!isset($this->aParams['csrf']['disable']) || (isset($this->aParams['csrf']['disable']) && $this->aParams['csrf']['disable'] !== true)) && ($mixedCsrfToken = BxDolForm::getCsrfToken()) !== false) {
  518. $this->aInputs['csrf_token'] = array(
  519. 'type' => 'hidden',
  520. 'name' => 'csrf_token',
  521. 'value' => $mixedCsrfToken,
  522. 'db' => array ('pass' => 'Xss'),
  523. 'visible_for_levels' => PHP_INT_MAX,
  524. );
  525. }
  526. // add 'Ajax Mode' flag
  527. if($this->_bAjaxMode)
  528. $this->aInputs['ajax_mode'] = array(
  529. 'type' => 'hidden',
  530. 'name' => 'ajax_mode',
  531. 'value' => 1,
  532. 'db' => array ('pass' => 'Int'),
  533. 'visible_for_levels' => PHP_INT_MAX,
  534. );
  535. // add 'Absolute Action Url' flag
  536. if($this->_bAbsoluteActionUrl)
  537. $this->aInputs['absolute_action_url'] = array(
  538. 'type' => 'hidden',
  539. 'name' => 'absolute_action_url',
  540. 'value' => 1,
  541. 'db' => array ('pass' => 'Int'),
  542. 'visible_for_levels' => PHP_INT_MAX,
  543. );
  544. // check if we need to generate open section clause
  545. $sOpenSection = '';
  546. foreach ($this->aInputs as $aInput) {
  547. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  548. continue;
  549. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  550. $sOpenSection = $this->{$this->_sSectionOpen}();
  551. break;
  552. }
  553. // generate rows contents
  554. $sCont = '';
  555. $sContHeader = '';
  556. $sContFields = '';
  557. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  558. foreach ($this->aInputs as &$aInput) {
  559. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  560. if ('block_header' == $aInput['type'] && !$this->_bShowEmptySections) {
  561. // don't show section with no fields or with empty fields
  562. if ($sContHeader) {
  563. if ($sContFields)
  564. $sCont .= $sContHeader . $sContFields;
  565. else
  566. $sContHeader = '';
  567. $sContFields = '';
  568. }
  569. else {
  570. $sCont .= $sContFields;
  571. $sContFields = '';
  572. }
  573. $sContHeader = $this->$sFuncGenRow($aInput);
  574. } else {
  575. $sContFields .= $this->$sFuncGenRow($aInput);
  576. }
  577. }
  578. }
  579. $sCont .= $sContHeader . $sContFields;
  580. $sCloseSection = $this->{$this->_sSectionClose}();
  581. return $sOpenSection . $sCont . $sCloseSection;
  582. }
  583. /**
  584. * Generate single Table Row
  585. *
  586. * @param array $aInput
  587. * @return string
  588. */
  589. function genRow(&$aInput)
  590. {
  591. if (!isset($aInput['type']))
  592. $aInput['type'] = false;
  593. if (!empty($aInput['name'])) {
  594. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  595. if (method_exists($this, $sCustomMethod))
  596. return $this->$sCustomMethod($aInput);
  597. }
  598. switch ($aInput['type']) {
  599. case 'block_header':
  600. $sRow = $this->genRowBlockHeader($aInput);
  601. break;
  602. case 'block_end':
  603. $sRow = $this->genBlockEnd($aInput);
  604. break;
  605. case 'hidden':
  606. // do not generate row for hidden inputs
  607. $sRow = '';
  608. $this->_sCodeAdd .= $this->genInput($aInput);
  609. break;
  610. case 'select_box':
  611. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  612. break;
  613. case 'files':
  614. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  615. break;
  616. case 'switcher':
  617. case 'checkbox':
  618. $sRow = $this->genRowStandard($aInput, true);
  619. break;
  620. default:
  621. $sRow = $this->genRowStandard($aInput);
  622. }
  623. return $sRow;
  624. }
  625. public function isInputVisible($mixedInput)
  626. {
  627. if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput]))
  628. $mixedInput = $this->aInputs[$mixedInput];
  629. if(empty($mixedInput) || !is_array($mixedInput))
  630. $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput);
  631. if(empty($mixedInput) || !is_array($mixedInput))
  632. return false;
  633. if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput))
  634. return false;
  635. return true;
  636. }
  637. protected function _isInputVisibleByPrivacy($aInput)
  638. {
  639. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  640. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  641. return true;
  642. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  643. if(empty($aInputPrivacy) || !is_array($aInputPrivacy))
  644. if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault))
  645. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  646. if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL)
  647. return false;
  648. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  649. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  650. return false;
  651. return true;
  652. }
  653. /**
  654. * Generate single Table Row for view mode
  655. *
  656. * @param array $aInput
  657. * @return string
  658. */
  659. function genViewRow(&$aInput)
  660. {
  661. if (!isset($aInput['type']))
  662. $aInput['type'] = false;
  663. if(!$this->isInputVisible($aInput))
  664. return '';
  665. if (!empty($aInput['name'])) {
  666. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  667. if (method_exists($this, $sCustomMethod))
  668. return $this->$sCustomMethod($aInput);
  669. }
  670. switch ($aInput['type']) {
  671. case 'block_header':
  672. $sRow = $this->genRowBlockHeader($aInput);
  673. break;
  674. case 'block_end':
  675. $sRow = $this->genBlockEnd($aInput);
  676. break;
  677. case 'nested_form':
  678. $sRow = $this->genNestedForm($aInput);
  679. break;
  680. case 'textarea':
  681. $sRow = $this->{'genViewRowWrapped' . ($aInput['html'] != 0 ? 'Html' : '')}($aInput);
  682. break;
  683. default:
  684. $sRow = $this->genViewRowWrapped($aInput);
  685. }
  686. return $sRow;
  687. }
  688. /**
  689. * Generate complete wrapped row for view mode form
  690. *
  691. * @param array $aInput
  692. * @return string
  693. */
  694. function genViewRowWrapped(&$aInput)
  695. {
  696. return $this->_genViewRowWrapped($aInput);
  697. }
  698. function genViewRowWrappedHtml(&$aInput)
  699. {
  700. return $this->_genViewRowWrapped($aInput, [
  701. 'class_value' => 'bx-def-vanilla-html max-w-none'
  702. ]);
  703. }
  704. protected function _genViewRowWrapped(&$aInput, $aParams = [])
  705. {
  706. $sValue = $this->genViewRowValue($aInput);
  707. if (null === $sValue)
  708. return '';
  709. $sClass = !empty($aParams['class']) ? $aParams['class'] : '';
  710. $sClassValue = !empty($aParams['class_value']) ? $aParams['class_value'] : '';
  711. $aTmplVarsIcon = [];
  712. if(!empty($aInput['icon'])) {
  713. list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = BxTemplFunctions::getInstanceWithTemplate($this->oTemplate)->getIcon($aInput['icon']);
  714. $aTmplVarsIcon = [
  715. 'bx_if:icon' => [
  716. 'condition' => (bool)$sIcon,
  717. 'content' => ['icon' => $sIcon],
  718. ],
  719. 'bx_if:icon-html' => [
  720. 'condition' => (bool)$sIconHtml,
  721. 'content' => ['icon' => $sIconHtml],
  722. ],
  723. 'bx_if:image_inline' => [
  724. 'condition' => false,
  725. 'content' => ['image' => ''],
  726. ]
  727. ];
  728. }
  729. return $this->oTemplate->parseHtmlByName('form_view_row.html', [
  730. 'type' => $aInput['type'],
  731. 'class' => $sClass,
  732. 'bx_if:show_icon' => [
  733. 'condition' => !empty($aTmplVarsIcon),
  734. 'content' => $aTmplVarsIcon
  735. ],
  736. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  737. 'class_value' => $sClassValue,
  738. 'value' => $sValue
  739. ]);
  740. }
  741. /**
  742. * Generate value for view mode row
  743. *
  744. * @param array $aInput
  745. * @return string
  746. */
  747. function genViewRowValue(&$aInput)
  748. {
  749. if (!empty($aInput['name'])) {
  750. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  751. if (method_exists($this, $sCustomMethod))
  752. return $this->$sCustomMethod($aInput);
  753. }
  754. switch ($aInput['type']) {
  755. case 'hidden':
  756. $sValue = null;
  757. break;
  758. case 'select':
  759. case 'radio_set':
  760. $sValue = $this->genViewRowValueForSelect($aInput);
  761. break;
  762. case 'dateselect':
  763. case 'datepicker':
  764. $sValue = null;
  765. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  766. break;
  767. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  768. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format']: BX_FORMAT_DATE, true, true);
  769. else
  770. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  771. break;
  772. case 'date_time':
  773. case 'datetime':
  774. $sValue = null;
  775. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  776. break;
  777. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  778. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true, true);
  779. else
  780. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  781. break;
  782. case 'checkbox_set':
  783. case 'select_multiple':
  784. $sValue = null;
  785. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  786. $sValue = '';
  787. foreach ($aInput['value'] as $sVal)
  788. $sValue .= $aInput['values'][$sVal] . ', ';
  789. $sValue = trim ($sValue, ', ');
  790. }
  791. break;
  792. case 'checkbox':
  793. case 'switcher':
  794. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  795. break;
  796. case 'textarea':
  797. if (isset($aInput['value']) && '' !== $aInput['value'])
  798. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  799. else
  800. $sValue = null;
  801. break;
  802. case 'text':
  803. if(isset($aInput['value']) && '' !== $aInput['value'])
  804. $sValue = bx_linkify(bx_process_output($aInput['value']));
  805. else
  806. $sValue = null;
  807. break;
  808. case 'price':
  809. if(isset($aInput['value']) && $aInput['value'] !== '')
  810. $sValue = _t_format_currency(bx_process_output($aInput['value']));
  811. else
  812. $sValue = null;
  813. break;
  814. default:
  815. if(isset($aInput['value']) && '' !== $aInput['value']) {
  816. $sValue = $aInput['value'];
  817. if(get_mb_substr($sValue, 0, 1) == '_')
  818. $sValue = _t($sValue);
  819. $sValue = bx_process_output($sValue);
  820. }
  821. else
  822. $sValue = null;
  823. }
  824. return $sValue;
  825. }
  826. function genViewRowValueForSelect(&$aInput)
  827. {
  828. if (!isset($aInput['value']) || !$aInput['value'])
  829. return null;
  830. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  831. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false)
  832. return $oCategory->getCategoryLink($s, $aInput['value']);
  833. return $s;
  834. }
  835. protected function genCustomRowBirthday(&$aInput)
  836. {
  837. if(!$this->_bViewMode)
  838. return $this->genRowStandard($aInput);
  839. $sTxtAge = '_sys_form_input_age';
  840. $aInput = array_merge($aInput, [
  841. 'caption_src' => $sTxtAge,
  842. 'caption' => _t($sTxtAge),
  843. ]);
  844. if(bx_is_api())
  845. $aInput = array_merge($aInput, [
  846. 'type' => 'text',
  847. 'value' => bx_birthday2age($aInput['value'])
  848. ]);
  849. return $this->genViewRowWrapped($aInput);
  850. }
  851. protected function genCustomRowCf(&$aInput)
  852. {
  853. $aInput = BxDolContentFilter::getInstance()->getInput($aInput);
  854. if($aInput['type'] == 'hidden') {
  855. $this->_sCodeAdd .= $this->genInput($aInput);
  856. return '';
  857. }
  858. return $this->genRowStandard($aInput);
  859. }
  860. protected function genCustomViewRowValueBirthday(&$aInput)
  861. {
  862. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00', '0000-00-00Z', '0000-00-00 00:00:00Z')))
  863. return null;
  864. return bx_birthday2age($aInput['value']);
  865. }
  866. /**
  867. * Generate standard row
  868. *
  869. * @param array $aInput
  870. * @return string
  871. */
  872. function genRowStandard(&$aInput, $isOneLine = false)
  873. {
  874. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  875. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  876. $sHelp = !empty($aInput['help']) ? ' <a href="javascript:void(0)" onclick="javascript:' . $this->getJsObjectName() . '.showHelp(this, \'' . $aInput['name'] . '\')"><i class="sys-icon question-circle"></i></a> ' : '';
  877. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  878. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  879. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  880. $sClassWrapper = 'bx-form-element-wrapper';
  881. if($isOneLine)
  882. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  883. $sClassWrapper .= ' bx-def-margin-top-auto';
  884. if (isset($aInput['name'])) {
  885. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  886. $aInput['tr_attrs'] = [];
  887. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  888. }
  889. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  890. $sClassOneLineCaption = '';
  891. $sClassOneLineValue = '';
  892. if ($isOneLine) {
  893. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' ltr:ml-4 rtl:mr-4';
  894. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  895. if (!isset($aInput['attrs']) || !is_array($aInput['attrs']))
  896. $aInput['attrs'] = [];
  897. $aInput['attrs']['id'] = $this->getInputId($aInput);
  898. if ($sCaption)
  899. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  900. }
  901. $sInput = $this->genInput($aInput);
  902. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  903. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  904. if(empty($sErrorIcon))
  905. $sErrorIcon = '';
  906. $aTmplVarsRow = array(
  907. 'bx_if:show_caption' => array(
  908. 'condition' => !empty($sCaption),
  909. 'content' => array(
  910. 'class_caption' => $sClassOneLineCaption,
  911. 'caption' => $sCaption,
  912. 'required' => $sRequired,
  913. 'help' => $sHelp,
  914. )
  915. ),
  916. 'class_value' => $sClassAdd . $sClassOneLineValue,
  917. 'value' => $this->genWrapperInput($aInput, $sInput),
  918. 'info' => $sInfoIcon,
  919. 'error' => $sErrorIcon,
  920. );
  921. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  922. 'tr_attrs' => $sTrAttrs,
  923. 'bx_if:show_one_line' => array(
  924. 'condition' => $isOneLine,
  925. 'content' => $aTmplVarsRow
  926. ),
  927. 'bx_if:show_lined' => array(
  928. 'condition' => !$isOneLine,
  929. 'content' => $aTmplVarsRow
  930. ),
  931. 'info' => $sInfoIcon,
  932. 'error' => $sErrorIcon
  933. ));
  934. }
  935. function genWrapperInput($aInput, $sContent)
  936. {
  937. $aAttrs = $this->_genWrapperInputAttrs($aInput);
  938. $sClass = "bx-form-input-wrapper bx-form-input-wrapper-{$aInput['type']}";
  939. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  940. $sClass .= ' bx-form-input-wrapper-html';
  941. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  942. 'attrs' => bx_convert_array2attrs($aAttrs, $sClass),
  943. 'content' => $sContent
  944. ));
  945. }
  946. protected function _genWrapperInputAttrs(&$aInput)
  947. {
  948. return isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper']) ? $aInput['attrs_wrapper'] : [];
  949. }
  950. /**
  951. * Generate custom row
  952. *
  953. * @param array $aInput
  954. * @param string $sCustomMethod custom method to generate code for input
  955. * @return string
  956. */
  957. function genRowCustom(&$aInput, $sCustomMethod)
  958. {
  959. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  960. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  961. $sHelp = !empty($aInput['help']) ? ' <a href="javascript:void(0)" onclick="javascript:' . $this->getJsObjectName() . '.showHelp(this, \'' . $aInput['name'] . '\')"><i class="sys-icon question-circle"></i></a> ' : '';
  962. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  963. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  964. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  965. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  966. if (isset($aInput['name'])) {
  967. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  968. $aInput['tr_attrs'] = [];
  969. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  970. }
  971. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  972. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  973. 'tr_attrs' => $sTrAttrs,
  974. 'bx_if:show_caption' => array(
  975. 'condition' => !empty($sCaption),
  976. 'content' => array(
  977. 'class_caption' => '',
  978. 'caption' => $sCaption,
  979. 'required' => $sRequired,
  980. 'help' => $sHelp
  981. )
  982. ),
  983. 'class_value' => $sClassAdd,
  984. 'value' => $sInput,
  985. ));
  986. }
  987. /**
  988. * Generate Block Headers row
  989. *
  990. * @param array $aInput
  991. * @return string
  992. */
  993. function genRowBlockHeader(&$aInput)
  994. {
  995. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  996. // if there is no caption - show divider only
  997. if (empty($aInput['caption']))
  998. return $this->{$this->_sSectionOpen}($aAttrs);
  999. // if section is collapsed by default, add necessary code
  1000. $sClassAddCollapsable = 'bx-form-collapsable';
  1001. if(isset($aInput['collapsed']) && $aInput['collapsed'])
  1002. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  1003. // display section with caption
  1004. if(empty($aAttrs))
  1005. $aAttrs = ['class' => $sClassAddCollapsable];
  1006. else
  1007. $aAttrs['class'] .= ' ' . $sClassAddCollapsable;
  1008. $bViewMode = !empty($this->aParams['view_mode']);
  1009. $sCaption = bx_process_output($aInput['caption'], BX_DATA_HTML);
  1010. $sInfo = !empty($aInput['info']) ? bx_process_output($aInput['info']) : '';
  1011. $bInfo = !empty($sInfo);
  1012. $sTitle = $this->oTemplate->parseHtmlByName('form_field_section_title.html', [
  1013. 'bx_if:show_view' => [
  1014. 'condition' => $bViewMode,
  1015. 'content' => [
  1016. 'caption' => $sCaption,
  1017. 'bx_if:show_view_info' => [
  1018. 'condition' => $bInfo,
  1019. 'content' => [
  1020. 'info' => $sInfo
  1021. ]
  1022. ]
  1023. ]
  1024. ],
  1025. 'bx_if:show_default' => [
  1026. 'condition' => !$bViewMode,
  1027. 'content' => [
  1028. 'caption' => $sCaption,
  1029. 'bx_if:show_default_info' => [
  1030. 'condition' => $bInfo,
  1031. 'content' => [
  1032. 'info' => $sInfo
  1033. ]
  1034. ]
  1035. ]
  1036. ]
  1037. ]);
  1038. if (isset($aInput['name'])) {
  1039. if (!isset($aInput['tr_attrs']) || !is_array($aInput['tr_attrs']))
  1040. $aInput['tr_attrs'] = [];
  1041. $aInput['tr_attrs']['id'] = "bx-form-section-" . $aInput['name'];
  1042. }
  1043. return $this->{$this->_sSectionOpen}($aAttrs, $sTitle, !empty($aInput['tr_attrs']) ? $aInput['tr_attrs'] : []);
  1044. }
  1045. function genBlockEnd()
  1046. {
  1047. return $this->{$this->_sSectionClose}();
  1048. }
  1049. /**
  1050. * Generate HTML Input Element
  1051. *
  1052. * @param array $aInput
  1053. * @return string Output HTML Code
  1054. */
  1055. function genInput(&$aInput)
  1056. {
  1057. if (!empty($aInput['name'])) {
  1058. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  1059. if (method_exists($this, $sCustomMethod))
  1060. return $this->$sCustomMethod($aInput);
  1061. }
  1062. switch ($aInput['type']) {
  1063. case 'datepicker':
  1064. if (!isset($aInput['attrs']))
  1065. $aInput['attrs'] = array();
  1066. $aInput['attrs']['autosuggestion'] = 'off';
  1067. $sInput = $this->genInputStandard($aInput);
  1068. break;
  1069. // standard inputs (and non-standard, interpreted as standard)
  1070. case 'text':
  1071. case 'datepicker':
  1072. case 'dateselect':
  1073. case 'date_time':
  1074. case 'datetime':
  1075. case 'number':
  1076. case 'time':
  1077. case 'checkbox':
  1078. case 'radio':
  1079. case 'image':
  1080. case 'slider':
  1081. case 'doublerange':
  1082. case 'hidden':
  1083. $sInput = $this->genInputStandard($aInput);
  1084. break;
  1085. case 'password':
  1086. $sInput = $this->genInputPassword($aInput);
  1087. break;
  1088. case 'price':
  1089. $sInput = $this->genInputPrice($aInput);
  1090. break;
  1091. case 'file':
  1092. $sInput = $this->genInputFile($aInput);
  1093. break;
  1094. case 'rgb':
  1095. case 'rgba':
  1096. $sClass = 'bx-form-input-' . $aInput['type'];
  1097. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  1098. $aInput['type'] = 'text';
  1099. $sInput = $this->genInputStandard($aInput);
  1100. break;
  1101. case 'rgb-list':
  1102. $sInput = $this->genInputSelectRgb($aInput);
  1103. break;
  1104. case 'switcher':
  1105. $sInput = $this->genInputSwitcher($aInput);
  1106. break;
  1107. case 'button':
  1108. case 'reset':
  1109. case 'submit':
  1110. $sInput = $this->genInputButton($aInput);
  1111. break;
  1112. case 'textarea':
  1113. $sInput = $this->genInputTextarea($aInput);
  1114. break;
  1115. case 'select':
  1116. $sInput = $this->genInputSelect($aInput);
  1117. break;
  1118. case 'select_multiple':
  1119. $sInput = $this->genInputSelectMultiple($aInput);
  1120. break;
  1121. case 'checkbox_set':
  1122. $sInput = $this->genInputCheckboxSet($aInput);
  1123. break;
  1124. case 'radio_set':
  1125. $sInput = $this->genInputRadioSet($aInput);
  1126. break;
  1127. case 'input_set': // numeric array of inputs
  1128. $sInput = '';
  1129. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  1130. foreach ($aInput as $iKey => $aSubInput) {
  1131. if (!is_int($iKey) or !$aSubInput)
  1132. continue; // parse only integer keys and existing values
  1133. $sInput .= $this->genInput($aSubInput); // recursive call
  1134. $sInput .= $sDivider;
  1135. }
  1136. $sInput .= '<div class="bx-clear"></div>';
  1137. break;
  1138. case 'custom':
  1139. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  1140. break;
  1141. case 'captcha':
  1142. $sInput = $this->genInputCaptcha($aInput);
  1143. break;
  1144. case 'location':
  1145. $sInput = $this->genInputLocation($aInput);
  1146. break;
  1147. case 'nested_form':
  1148. $sInput = $this->genInputNestedForm($aInput);
  1149. break;
  1150. case 'value':
  1151. $sInput = '';
  1152. if(!isset($aInput['value']))
  1153. break;
  1154. $sInput = $aInput['value'];
  1155. if(get_mb_substr($sInput, 0, 1) == '_')
  1156. $sInput = _t($sInput);
  1157. break;
  1158. default:
  1159. //unknown control type
  1160. $sInput = 'Unknown control type';
  1161. }
  1162. // create input label
  1163. $sInput .= $this->genLabel($aInput);
  1164. // create input privacy group chooser
  1165. $sInput .= $this->genPrivacyGroupChooser($aInput);
  1166. return $sInput;
  1167. }
  1168. /**
  1169. * Generate new Input Element id
  1170. *
  1171. * @param array $aInput
  1172. * @return string
  1173. */
  1174. function getInputId(&$aInput)
  1175. {
  1176. if (isset($aInput['id']))
  1177. return $aInput['id'];
  1178. $sName = md5($aInput['name']);
  1179. $sID = $this->id . '_input_' . $sName;
  1180. if ( // multiple elements cause identical id's
  1181. (
  1182. (
  1183. $aInput['type'] == 'checkbox' and
  1184. substr($aInput['name'], -2) == '[]' // it is multiple element
  1185. ) or
  1186. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  1187. ) and
  1188. isset($aInput['value']) // if we can make difference
  1189. ) {
  1190. $sValue = md5($aInput['value']);
  1191. // add value
  1192. $sID .= '_' . $sValue;
  1193. }
  1194. $sID = trim($sID, '_');
  1195. $aInput['id'] = $sID; // just for repeated calls
  1196. return $sID;
  1197. }
  1198. /**
  1199. * Generate standard Input Element
  1200. *
  1201. * @param array $aInput
  1202. * @return string
  1203. */
  1204. function genInputStandard(&$aInput)
  1205. {
  1206. $aAttrs = $this->_genInputStandardAttrs($aInput);
  1207. return $this->oTemplate->parseHtmlByName('form_field_standard.html', [
  1208. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}")
  1209. ]);
  1210. }
  1211. protected function _genInputStandardAttrs(&$aInput)
  1212. {
  1213. // clone attributes for system use ;)
  1214. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1215. // add default className to attributes
  1216. $aAttrs['type'] = $aInput['type'];
  1217. if ('datetime' == $aAttrs['type'])
  1218. $aAttrs['type'] = 'date_time';
  1219. switch($aAttrs['type']) {
  1220. case 'datepicker':
  1221. case 'date_time':
  1222. $this->addCssJsTimepicker ();
  1223. break;
  1224. case 'slider':
  1225. case 'doublerange':
  1226. $this->addCssJsUi ();
  1227. break;
  1228. case 'dateselect':
  1229. if(!empty($aInput['value']) && strpos($aInput['value'], ' ') !== false)
  1230. list($aInput['value']) = explode(' ', $aInput['value']);
  1231. $this->_addJs(array(
  1232. 'combodate/combodate.js',
  1233. ), "'undefined' === typeof($.combodate)");
  1234. break;
  1235. case 'text':
  1236. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  1237. $this->addCssJsMinicolors ();
  1238. break;
  1239. }
  1240. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  1241. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  1242. }
  1243. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1244. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  1245. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  1246. if (!isset($aAttrs['data-format-24h']))
  1247. $aAttrs['data-frmt-24h'] = getParam('sys_format_input_24h');
  1248. if (!isset($aAttrs['data-format-date']))
  1249. $aAttrs['data-frmt-date'] = getParam('sys_format_date');
  1250. if (!isset($aAttrs['data-format-datetime']))
  1251. $aAttrs['data-frmt-datetime'] = getParam('sys_format_datetime');
  1252. // for inputs with labels generate id
  1253. if (isset($aInput['label']))
  1254. $aAttrs['id'] = $this->getInputId($aInput);
  1255. // for checkboxes
  1256. if (isset($aInput['checked']) and $aInput['checked'])
  1257. $aAttrs['checked'] = 'checked';
  1258. return $aAttrs;
  1259. }
  1260. /**
  1261. * Generate Switcher Input Element (based on checkbox)
  1262. *
  1263. * @param array $aInput
  1264. * @return string
  1265. */
  1266. function genInputSwitcher(&$aInput)
  1267. {
  1268. $aInput['type'] = 'checkbox';
  1269. $sCheckbox = $this->genInputStandard($aInput);
  1270. $aInput['type'] = 'switcher';
  1271. $sClass = 'off';
  1272. if(isset($aInput['checked']) && $aInput['checked'])
  1273. $sClass = 'on';
  1274. return $this->oTemplate->parseHtmlByName('form_field_switcher.html', [
  1275. 'class' => $sClass,
  1276. 'checkbox' => $sCheckbox
  1277. ]);
  1278. }
  1279. function genInputCheckbox(&$aInput, $bWrapped = false)
  1280. {
  1281. $sInput = $this->genInputStandard($aInput);
  1282. return $bWrapped ? $this->genWrapperInput($aInput, $sInput) : $sInput;
  1283. }
  1284. /**
  1285. * Generate Button Input Element
  1286. *
  1287. * @param array $aInput
  1288. * @return string
  1289. */
  1290. function genInputButton(&$aInput)
  1291. {
  1292. $aAttrs = $this->_genInputButtonAttrs($aInput);
  1293. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn";
  1294. if($aInput['type'] == 'submit')
  1295. $sClassAdd .= ' bx-btn-primary';
  1296. return $this->oTemplate->parseHtmlByName('form_field_button.html', [
  1297. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1298. 'value' => $aInput['value']
  1299. ]);
  1300. }
  1301. protected function _genInputButtonAttrs(&$aInput)
  1302. {
  1303. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1304. // add default className to attributes
  1305. $aAttrs['type'] = $aInput['type'];
  1306. if(isset($aInput['value']))
  1307. $aAttrs['value'] = $aInput['value'];
  1308. if(isset($aInput['name']))
  1309. $aAttrs['name'] = $aInput['name'];
  1310. return $aAttrs;
  1311. }
  1312. /**
  1313. * Generate Textarea Element
  1314. *
  1315. * @param array $aInput
  1316. * @return string
  1317. */
  1318. function genInputTextarea(&$aInput)
  1319. {
  1320. $aAttrs = $this->_genInputTextareaAttrs($aInput);
  1321. $sUniq = genRndPwd(10, false);
  1322. $sClassAdd = "bx-def-font-inputs bx-form-input-{$aInput['type']}";
  1323. if(isset($aInput['html']) && $aInput['html'] && $this->addHtmlEditor($aInput['html'], $aInput, $sUniq)){
  1324. $sClassAdd .= ' bx-form-input-html ' . $sUniq;
  1325. }
  1326. $sValue = isset($aInput['value']) ? bx_process_output((isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : strip_tags($aInput['value']), BX_DATA_TEXT, array('no_process_macros')) : '';
  1327. return $this->oTemplate->parseHtmlByName('form_field_textarea.html', [
  1328. 'attrs' => bx_convert_array2attrs($aAttrs, $sClassAdd),
  1329. 'value' => $sValue
  1330. ]);
  1331. }
  1332. protected function _genInputTextareaAttrs(&$aInput)
  1333. {
  1334. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1335. $aAttrs['name'] = $aInput['name'];
  1336. // for inputs with labels generate id
  1337. if (isset($aInput['label']))
  1338. $aAttrs['id'] = $this->getInputId($aInput);
  1339. return $aAttrs;
  1340. }
  1341. function isHtmlEditor($iViewMode, &$aInput)
  1342. {
  1343. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1344. }
  1345. function addHtmlEditor($iViewMode, &$aInput, $sUniq)
  1346. {
  1347. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1348. if (!$oEditor)
  1349. return false;
  1350. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name=' . $aInput['name'] . ']', $iViewMode, $this->_bDynamicMode, ['form_id' => $this->aFormAttrs['id'], 'element_name' => $aInput['name'], 'query_params' => $this->getHtmlEditorQueryParams($aInput), 'uniq' => $sUniq]);
  1351. return true;
  1352. }
  1353. function getHtmlEditorQueryParams($aInput)
  1354. {
  1355. $aQueryParams = ['i' => $aInput['name'], 'f' => $this->aFormAttrs['id'], 'fi' => ''];
  1356. /**
  1357. * @hooks
  1358. * @hookdef hook-system-editor_query_params 'system', 'editor_query_params' - hook to override http(s) request's query params, which is used in HTML editor
  1359. * - $unit_name - equals `system`
  1360. * - $action - equals `editor_query_params`
  1361. * - $object_id - not used
  1362. * - $sender_id - not used
  1363. * - $extra_params - array of additional params with the following array keys:
  1364. * - `form` - [object] an instance of form, @see BxDolForm
  1365. * - `override_result` - [array] by ref, query string params, can be overridden in hook processing
  1366. * @hook @ref hook-system-editor_query_params
  1367. */
  1368. bx_alert('system', 'editor_query_params', 0, 0, [
  1369. 'form' => $this,
  1370. 'override_result' => &$aQueryParams
  1371. ]);
  1372. return $aQueryParams;
  1373. }
  1374. /**
  1375. * Generate Select Box Element
  1376. *
  1377. * @param array $aInput
  1378. * @return string
  1379. */
  1380. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1381. {
  1382. $aNewInput = $aInput;
  1383. $aNewInput['type'] = 'select';
  1384. $aNewInput['name'] .= '[]';
  1385. $sInput = $this->genInput($aNewInput);
  1386. return <<<BLAH
  1387. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1388. $sInput
  1389. </div>
  1390. $sInfo
  1391. $sError
  1392. BLAH;
  1393. }
  1394. /**
  1395. * Generate Browse File Element
  1396. *
  1397. * @param array $aInput
  1398. * @return string
  1399. */
  1400. function genInputFile(&$aInput)
  1401. {
  1402. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1403. if(!empty($aInput['attrs']['onchange']))
  1404. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1405. else
  1406. $aInput['attrs']['onchange'] = $sOnChange;
  1407. $sInput = $this->genInputStandard($aInput);
  1408. return '<label class="bx-btn">' . $sInput . '<span class="bx-fif-label">' . _t('_sys_form_txt_select_file') . '</span></label><span class="bx-fif-value bx-def-margin-thd-left"></span>';
  1409. }
  1410. /**
  1411. * Generate Select Box Element
  1412. *
  1413. * @param array $aInput
  1414. * @return string
  1415. */
  1416. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1417. {
  1418. if(empty($aInput['uploaders']) || !is_array($aInput['uploaders']))
  1419. return '';
  1420. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1421. $bInitGhosts = isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1;
  1422. $bInitReordering = empty($aInput['init_reordering']) ? 0 : 1;
  1423. $oUploader = null;
  1424. $sUploadersButtons = $sUploadersJs = '';
  1425. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1426. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1427. if(!$oUploader)
  1428. continue;
  1429. //--- Get Button code.
  1430. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1431. if(empty($aInput['attrs']['disabled']))
  1432. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1433. $aParamsButtons = [
  1434. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1435. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1436. 'attrs' => bx_convert_array2attrs($aAttrs),
  1437. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1438. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1439. ];
  1440. $sUploadersButtons .= $oUploader->getUploaderButton($aParamsButtons);
  1441. //--- Get JS code.
  1442. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1443. $aParamsJs = array_merge($oUploader->getUploaderJsParams(),
  1444. [
  1445. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1446. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1447. 'is_init_ghosts' => $bInitGhosts,
  1448. 'is_init_reordering' => $bInitReordering
  1449. ]
  1450. );
  1451. if(isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1452. $aParamsJs['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1453. $sUploadersJs .= $oUploader->getUploaderJs($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParamsJs, $this->_bDynamicMode);
  1454. }
  1455. if(!$oUploader)
  1456. return '';
  1457. if($bInitReordering) {
  1458. $this->addCssJsUi();
  1459. $this->addCssJsUiSortable();
  1460. }
  1461. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1462. 'uploaders_buttons' => $sUploadersButtons,
  1463. 'info' => $sInfo,
  1464. 'error' => $sError,
  1465. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1466. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1467. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1468. 'uploaders_js' => $sUploadersJs,
  1469. ));
  1470. }
  1471. protected function genGhostTemplate(&$aInput)
  1472. {
  1473. $sGhostTemplate = false;
  1474. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1475. $oFormNested = $aInput['ghost_template'];
  1476. if ($oFormNested instanceof BxDolFormNestedGhost)
  1477. $sGhostTemplate = $oFormNested->genForm();
  1478. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) { // form is not submitted and ghost template is form array
  1479. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1480. $sGhostTemplate = $oFormNested->getCode();
  1481. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1482. $sGhostTemplate = array ();
  1483. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1484. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1485. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1486. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1487. $sGhostTemplate = $aInput['ghost_template'];
  1488. }
  1489. return $sGhostTemplate;
  1490. }
  1491. protected function genCustomInputUsernamesSuggestions ($aInput)
  1492. {
  1493. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1494. $aAttrs = $this->_genCustomInputUsernamesSuggestionsAttrs($aInput, $bDisabled);
  1495. $aTmplVarsVals = [];
  1496. $sValue = '';
  1497. if(!empty($aInput['value'])) {
  1498. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']) . 'Value';
  1499. if(method_exists($this, $sCustomMethod))
  1500. $aTmplVarsVals = $this->$sCustomMethod($aInput);
  1501. else if(is_array($aInput['value']) || (is_numeric($aInput['value']))) {
  1502. if (!is_array($aInput['value']))
  1503. $aInput['value'] = [$aInput['value']];
  1504. foreach($aInput['value'] as $sVal) {
  1505. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1506. continue;
  1507. $aTmplVarsVals[] = [
  1508. 'item_unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']]),
  1509. 'item_name' => $oProfile->getDisplayName(),
  1510. 'name' => $aInput['name'] . (isset($aInput['custom']['only_once']) && $aInput['custom']['only_once'] == 1 ? '' : '[]'),
  1511. 'value' => $sVal
  1512. ];
  1513. }
  1514. }
  1515. else if(is_string($aInput['value']))
  1516. $sValue = $aInput['value'];
  1517. }
  1518. $aTmplVarsInputText = [];
  1519. if(!$bDisabled) {
  1520. $aInputText = $aInput;
  1521. $aInputText['type'] = 'text';
  1522. $aInputText['value'] = '';
  1523. $aInputText['attrs'] = $this->_genCustomInputUsernamesSuggestionsTextAttrs($aInputText, $bDisabled);
  1524. unset($aInputText['name']);
  1525. $aTmplVarsInputText['input'] = $this->genInputStandard($aInputText);
  1526. }
  1527. if (bx_is_api()){
  1528. $aInput['type'] = 'initial_members';
  1529. return $aInput;
  1530. }
  1531. $this->addCssJsUi();
  1532. $sJsCode = '';
  1533. if(!$bDisabled) {
  1534. $sJsCode = $this->oTemplate->parseHtmlByName('form_field_custom_suggestions_js.html', [
  1535. 'id' => $aAttrs['id'],
  1536. 'name' => $aInput['name'],
  1537. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1538. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1539. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1540. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1541. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1542. ]);
  1543. if($this->_bDynamicMode)
  1544. $sJsCode = $this->oTemplate->addJsPreloadedWrapped([
  1545. 'jquery-ui/jquery-ui.min.js'
  1546. ], $sJsCode);
  1547. else
  1548. $sJsCode = $this->oTemplate->addJsCodeOnLoadWrapped($sJsCode);
  1549. }
  1550. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1551. 'name' => $aInput['name'],
  1552. 'attrs' => bx_convert_array2attrs($aAttrs),
  1553. 'bx_repeat:vals' => $aTmplVarsVals,
  1554. 'value' => $sValue,
  1555. 'bx_if:input' => array(
  1556. 'condition' => !$bDisabled,
  1557. 'content' => $aTmplVarsInputText
  1558. ),
  1559. 'js_code' => $sJsCode
  1560. ));
  1561. }
  1562. protected function _genCustomInputUsernamesSuggestionsAttrs (&$aInput, $bDisabled = false)
  1563. {
  1564. $aAttrs = ['id' => $aInput['name'] . time() . mt_rand(0, 100)];
  1565. $aAttrs['class'] = 'bx-form-input-autotoken bx-form-input-text bx-def-font-inputs';
  1566. if($bDisabled)
  1567. $aAttrs['class'] .= ' bx-form-input-disabled';
  1568. if(!empty($aInput['attrs']['class']))
  1569. $aAttrs['class'] .= ' ' . $aInput['attrs']['class'];
  1570. return $aAttrs;
  1571. }
  1572. protected function _genCustomInputUsernamesSuggestionsTextAttrs (&$aInput, $bDisabled = false)
  1573. {
  1574. $aAttrs = ['value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off'];
  1575. if(!empty($aInput['attrs']) && is_array($aInput['attrs'])) {
  1576. if(isset($aInput['attrs']['class']))
  1577. unset($aInput['attrs']['class']);
  1578. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1579. }
  1580. return $aAttrs;
  1581. }
  1582. protected function genCustomViewRowValueLabels ($aInput)
  1583. {
  1584. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1585. return null;
  1586. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1587. $aInput['value'] = unserialize($aInput['value']);
  1588. $s = '';
  1589. foreach ($aInput['value'] as $sLabel)
  1590. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="bx-def-label val">' . trim($sLabel) . '</b></a>';
  1591. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1592. 'values' => $s,
  1593. ));
  1594. }
  1595. protected function genCustomInputLabels (&$aInput)
  1596. {
  1597. $oLabel = BxDolLabel::getInstance();
  1598. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1599. $sValue = '';
  1600. if(!empty($aInput['value'])) {
  1601. if(!is_array($aInput['value']))
  1602. $aInput['value'] = unserialize($aInput['value']);
  1603. if(is_array($aInput['value']))
  1604. foreach($aInput['value'] as $sLabel)
  1605. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1606. }
  1607. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1608. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1609. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1610. $aInputLabels = array(
  1611. 'type' => 'custom',
  1612. 'name' => $sName,
  1613. 'caption' => '',
  1614. 'value' => $sValue,
  1615. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1616. 'action' => 'labels_list',
  1617. )),
  1618. 'attrs' => array(
  1619. 'class' => 'bx-form-input-labels',
  1620. 'disabled' => 'disabled'
  1621. )
  1622. );
  1623. if (bx_is_api()) {
  1624. return array_merge($aInput, [
  1625. 'type' => 'labels',
  1626. 'values' => bx_srv('system', 'get_labels', [], 'TemplLabelsServices')
  1627. ]);
  1628. }
  1629. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1630. 'js_object' => $oLabel->getJsObjectName(),
  1631. 'js_code' => $oLabel->getJsCodeForm(),
  1632. 'html_id' => $oLabel->getFormFieldId($aInput),
  1633. 'name' => $sName,
  1634. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1635. ));
  1636. }
  1637. /**
  1638. * Generate Select Element
  1639. *
  1640. * @param array $aInput
  1641. * @return string
  1642. */
  1643. function genInputSelect(&$aInput)
  1644. {
  1645. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1646. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1647. }
  1648. /**
  1649. * Generate Select RGB Element
  1650. *
  1651. * @param array $aInput
  1652. * @return string
  1653. */
  1654. function genInputSelectRgb(&$aInput)
  1655. {
  1656. $aInput['type'] = 'select';
  1657. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1658. $aInput['values_list_name'] = 'sys_colors';
  1659. $aInput['values'] = self::getDataItems('sys_colors', isset(self::$TYPES_SET[$aInput['type']]));
  1660. $aInput['attrs'] = ['class' => 'bx-form-input-rgb-list'];
  1661. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1662. $aInput['values'][$sOptValue] = ['key' => $sOptValue, 'value' => $sOptTitle, 'class' => 'bg-' . $sOptValue, 'style' => 'color:#fff'];
  1663. }
  1664. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1665. }
  1666. /**
  1667. * Generate Multiple Select Element
  1668. *
  1669. * @param array $aInput
  1670. * @return string
  1671. */
  1672. function genInputSelectMultiple(&$aInput)
  1673. {
  1674. $aCurValues = array();
  1675. if (isset($aInput['value']) && $aInput['value'])
  1676. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1677. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1678. }
  1679. /**
  1680. * Generate Checkbox Set Element
  1681. *
  1682. * @param array $aInput
  1683. * @return string
  1684. */
  1685. function genInputCheckboxSet(&$aInput)
  1686. {
  1687. $aCurValues = array();
  1688. if (isset($aInput['value']) && $aInput['value'])
  1689. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1690. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1691. }
  1692. /**
  1693. * Generate Radiobuttons Set Element
  1694. *
  1695. * @param array $aInput
  1696. * @return string
  1697. */
  1698. function genInputRadioSet(&$aInput)
  1699. {
  1700. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1701. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1702. }
  1703. function _isSelected ($sValue, $sCurValue)
  1704. {
  1705. return ((string)$sValue === (string)$sCurValue);
  1706. }
  1707. function _isSelectedMultiple ($sValue, $aCurValues)
  1708. {
  1709. return in_array($sValue, $aCurValues);
  1710. }
  1711. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1712. {
  1713. $aOptions = [];
  1714. if(isset($aInput['values']) && is_array($aInput['values'])) {
  1715. foreach ($aInput['values'] as $sOptValue => $sOptTitle) {
  1716. $aOption = array(
  1717. 'bx_if:show_option_group_begin' => [
  1718. 'condition' => false,
  1719. 'content' => []
  1720. ],
  1721. 'bx_if:show_option_group_end' => [
  1722. 'condition' => false,
  1723. 'content' => []
  1724. ],
  1725. 'bx_if:show_option' => [
  1726. 'condition' => false,
  1727. 'content' => []
  1728. ]
  1729. );
  1730. $sOptAttrs = "";
  1731. if(is_array($sOptTitle)) {
  1732. if(isset($sOptTitle['type'])) {
  1733. switch($sOptTitle['type']) {
  1734. case 'group_header':
  1735. $aOption = array_merge($aOption, [
  1736. 'bx_if:show_option_group_begin' => [
  1737. 'condition' => true,
  1738. 'content' => [
  1739. 'opt_label' => bx_process_output($sOptTitle['value'])
  1740. ]
  1741. ]
  1742. ]);
  1743. $aOptions[] = $aOption;
  1744. break;
  1745. case 'group_end':
  1746. $aOption = array_merge($aOption, [
  1747. 'bx_if:show_option_group_end' => [
  1748. 'condition' => true,
  1749. 'content' => []
  1750. ]
  1751. ]);
  1752. $aOptions[] = $aOption;
  1753. break;
  1754. }
  1755. continue;
  1756. }
  1757. $aOptAttrs = $this->_genInputSelectOptionAttrs($sOptTitle);
  1758. if(!empty($aOptAttrs))
  1759. $sOptAttrs = bx_convert_array2attrs($aOptAttrs);
  1760. $sOptValue = $sOptTitle['key'];
  1761. $sOptTitle = $sOptTitle['value'];
  1762. }
  1763. $aOption = array_merge($aOption, [
  1764. 'bx_if:show_option' => [
  1765. 'condition' => true,
  1766. 'content' => [
  1767. 'opt_title' => bx_process_output($sOptTitle),
  1768. 'opt_value' => !empty($sOptValue) ? bx_html_attribute($sOptValue) : '',
  1769. 'opt_attrs' => $sOptAttrs,
  1770. 'bx_if:show_selected' => [
  1771. 'condition' => $this->$sIsSelectedFunc($sOptValue, $mixedCurrentVal),
  1772. 'content' => []
  1773. ]
  1774. ]
  1775. ]
  1776. ]);
  1777. $aOptions[] = $aOption;
  1778. }
  1779. }
  1780. $aAttrs = $this->_genInputSelectAttrs($aInput, $isMultiple);
  1781. return $this->_parseInputSelect('form_field_select.html', [
  1782. 'attrs' => bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}"),
  1783. 'bx_repeat:options' => $aOptions,
  1784. 'content' => !empty($aInput['content']) ? $aInput['content'] : ''
  1785. ]);
  1786. }
  1787. protected function _genInputSelectAttrs(&$aInput, $isMultiple)
  1788. {
  1789. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : [];
  1790. $aAttrs['name'] = $aInput['name'];
  1791. if ($isMultiple) {
  1792. $aAttrs['name'] .= '[]';
  1793. $aAttrs['multiple'] = 'multiple';
  1794. }
  1795. // for inputs with labels generate id
  1796. if (isset($aInput['label']))
  1797. $aAttrs['id'] = $this->getInputId($aInput);
  1798. return $aAttrs;
  1799. }
  1800. protected function _genInputSelectOptionAttrs(&$aOption)
  1801. {
  1802. $aAttrs = [];
  1803. if(!empty($aOption['attrs']) && is_array($aOption['attrs']))
  1804. $aAttrs = $aOption['attrs'];
  1805. if(isset($aOption['class']))
  1806. $aAttrs['class'] = !empty($aAttrs['class']) ? $aAttrs['class'] . ' ' . $aOption['class'] : $aOption['class'];
  1807. if(isset($aOption['style']))
  1808. $aAttrs['style'] = !empty($aAttrs['style']) ? $aAttrs['style'] . ' ' . $aOption['style'] : $aOption['style'];
  1809. return $aAttrs;
  1810. }
  1811. protected function _parseInputSelect($sTmplName, $aTmplVars)
  1812. {
  1813. return $this->oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
  1814. }
  1815. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1816. {
  1817. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1818. $aAttrs['name'] = $aInput['name'];
  1819. // for inputs with labels generate id
  1820. if (isset($aInput['label']))
  1821. $aAttrs['id'] = $this->getInputId($aInput);
  1822. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1823. // generate options
  1824. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1825. $iDividerThreshold = !empty($aInput['dv_thd']) ? (int)$aInput['dv_thd'] : 3;
  1826. $sOptions = '';
  1827. $aAdditionalFieldInfo = [];
  1828. if (in_array($aInput['type'], ['radio_set', 'checkbox_set']) && !empty($aInput['values_list_name']))
  1829. $aAdditionalFieldInfo = BxDolFormQuery::getDataItems($aInput['values_list_name'], false, BX_DATA_VALUES_ALL);
  1830. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1831. if (count($aInput['values']) > $iDividerThreshold && $sDivider == $this->_sDivider)
  1832. $sDivider = $this->_sDividerAlt;
  1833. // generate complex input using simple standard inputs
  1834. foreach ($aInput['values'] as $sValue => $sLabel) {
  1835. if(is_array($sLabel)) {
  1836. $sValue = $sLabel['key'];
  1837. $sLabel = $sLabel['value'];
  1838. }
  1839. // create new simple input
  1840. $aNewInput = array(
  1841. 'type' => $sType,
  1842. 'name' => $aInput['name'] . $sNameAppend,
  1843. 'value' => $sValue,
  1844. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1845. 'label' => $sLabel,
  1846. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1847. );
  1848. if (isset($aInput['label_as_html']))
  1849. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  1850. $sNewInput = $this->genInputCheckbox($aNewInput, true) . $this->genLabel($aNewInput);
  1851. // add additional info for the field
  1852. if (isset($aAdditionalFieldInfo[$sValue]) && !empty($aAdditionalFieldInfo[$sValue]['LKey2']))
  1853. $sNewInput = $this->genFiledItemInfoWrapper($sNewInput, _t($aAdditionalFieldInfo[$sValue]['LKey2']));
  1854. // attach new input to complex
  1855. $sOptions .= ($sNewInput . $sDivider);
  1856. }
  1857. }
  1858. // generate element
  1859. $sCode = <<<BLAH
  1860. <div $sAttrs>
  1861. $sOptions
  1862. </div>
  1863. BLAH;
  1864. return $sCode;
  1865. }
  1866. function genInputLocation(&$aInput)
  1867. {
  1868. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1869. if (!$o)
  1870. return _t('_sys_txt_error_occured');
  1871. return $o->genInputLocation($aInput, $this);
  1872. }
  1873. public function setLocationVals ($aInput, $aVals)
  1874. {
  1875. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1876. if (!$o)
  1877. return false;
  1878. return $o->setLocationVals ($aInput, $aVals, $this);
  1879. }
  1880. public function setLocationVal ($aInput, $sIndex, $sVal)
  1881. {
  1882. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1883. if (!$o)
  1884. return false;
  1885. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  1886. }
  1887. protected function getLocationVal ($aInput, $sIndex)
  1888. {
  1889. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1890. if (!$o)
  1891. return false;
  1892. return $o->getLocationVal ($aInput, $sIndex, $this);
  1893. }
  1894. function genInputPassword(&$aInput)
  1895. {
  1896. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1897. }
  1898. function genInputPrice(&$aInput)
  1899. {
  1900. $sCurrency = '';
  1901. if(!isset($aInput['value_currency'])) {
  1902. $sCurrency = BxDolPayments::getInstance()->getOption('default_currency_code');
  1903. if(empty($sCurrency))
  1904. $sCurrency = getParam('currency_code');
  1905. }
  1906. else
  1907. $sCurrency = $aInput['value_currency'];
  1908. return $this->oTemplate->parseHtmlByName('form_field_price.html', array(
  1909. 'bx_if:show_currency' => [
  1910. 'condition' => !empty($sCurrency),
  1911. 'content' => [
  1912. 'currency' => $sCurrency,
  1913. ]
  1914. ],
  1915. 'input' => $this->genInputStandard($aInput)
  1916. ));
  1917. }
  1918. function genInputNestedForm(&$aInput)
  1919. {
  1920. return '';
  1921. }
  1922. function genNestedForm(&$aInput)
  1923. {
  1924. return '';
  1925. }
  1926. function genInputCaptcha(&$aInput)
  1927. {
  1928. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1929. // for inputs with labels generate id
  1930. if (isset($aInput['label']))
  1931. $aAttrs['id'] = $this->getInputId($aInput);
  1932. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1933. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1934. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1935. }
  1936. /**
  1937. * Generate Label Element
  1938. *
  1939. * @param string $aInput input array
  1940. * @return string HTML code
  1941. */
  1942. function genLabel(&$aInput)
  1943. {
  1944. if (!isset($aInput['label']) || empty($aInput['label']))
  1945. return '';
  1946. $sInputID = $this->getInputId($aInput);
  1947. $sLabel = bx_process_output($aInput['label']);
  1948. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  1949. $sLabel = $aInput['label'];
  1950. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  1951. }
  1952. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1953. {
  1954. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1955. return '';
  1956. $iAuthorId = bx_get_logged_profile_id();
  1957. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1958. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1959. return '';
  1960. if(empty($sPrivacyObject))
  1961. $sPrivacyObject = $this->_sPrivacyObjectView;
  1962. $iInputId = (int)$aInput['id'];
  1963. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1964. if(!isset($aInput['attrs_wrapper']['class']))
  1965. $aInput['attrs_wrapper']['class'] = '';
  1966. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1967. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1968. 'js_object' => $this->getJsObjectName(),
  1969. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1970. 'id' => $iInputId,
  1971. 'privacy_object' => $sPrivacyObject,
  1972. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1973. ));
  1974. }
  1975. function genFiledItemInfoWrapper($sInput, $sInfoValue)
  1976. {
  1977. $sInfo = $this->genInfoIcon($sInfoValue) ;
  1978. return $this->oTemplate->parseHtmlByName('form_field_option_info.html', [
  1979. 'input' => $sInput,
  1980. 'info' => $sInfo
  1981. ]);
  1982. }
  1983. function genInfoIcon($sInfo)
  1984. {
  1985. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small mt-1">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1986. }
  1987. function genErrorIcon( $sError = '' )
  1988. {
  1989. if ($this->bEnableErrorIcon) {
  1990. $sStyle = '';
  1991. if (!$sError)
  1992. $sStyle = 'style="display:none;"';
  1993. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1994. }
  1995. }
  1996. function getOpenSection($aAttrs = [], $sTitle = '', $aWrapperAttrs = [])
  1997. {
  1998. $sClose = '';
  1999. if($this->_isSectionOpened)
  2000. $sClose = $this->{$this->_sSectionClose}();
  2001. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper my-4");
  2002. if(!$aAttrs || !is_array($aAttrs))
  2003. $aAttrs = [];
  2004. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-section-" . ($sTitle ? "header" : "divider"));
  2005. $this->_isSectionOpened = true;
  2006. return $sClose . "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content pt-4 pb-6" . ($sTitle ? ' px-6' : '') . "\">\n";
  2007. }
  2008. function getCloseSection()
  2009. {
  2010. if(!$this->_isSectionOpened)
  2011. return '';
  2012. $this->_isSectionOpened = false;
  2013. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  2014. }
  2015. function getOpenSectionViewMode($aAttrs = array(), $sTitle = '', $aWrapperAttrs = [])
  2016. {
  2017. if (!$this->_isSectionOpened) {
  2018. if (!$aAttrs || !is_array($aAttrs))
  2019. $aAttrs = array();
  2020. if ($sTitle)
  2021. $sClassesAdd = "bx-form-section-header";
  2022. else
  2023. $sClassesAdd = "bx-form-section-divider";
  2024. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  2025. $sWrapperAttrs = bx_convert_array2attrs($aWrapperAttrs, "bx-form-section-wrapper bx-def-margin-top");
  2026. $this->_isSectionOpened = true;
  2027. return "<!-- form header content begins -->\n <div $sWrapperAttrs> <div $sAttrs> $sTitle <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  2028. } else {
  2029. return '';
  2030. }
  2031. }
  2032. function getCloseSectionViewMode()
  2033. {
  2034. if ($this->_isSectionOpened) {
  2035. $this->_isSectionOpened = false;
  2036. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  2037. } else {
  2038. return '';
  2039. }
  2040. }
  2041. public static function getJsCalendarLangs ()
  2042. {
  2043. return array ('ar-dz' => 1, 'ar' => 1, 'at' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bn' => 1, 'bs' => 1, 'cat' => 1, 'ckb' => 1, 'cs' => 1, 'cy' => 1, 'da' => 1, 'de' => 1, 'default' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr' => 1, 'ga' => 1, 'gr' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'index' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'km' => 1, 'ko' => 1, 'kz' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'mn' => 1, 'ms' => 1, 'my' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pa' => 1, 'pl' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'si' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-cyr' => 1, 'sr' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'uz' => 1, 'uz_latn' => 1, 'vn' => 1, 'zh-tw' => 1, 'zh' => 1);
  2044. }
  2045. public static function getCssJsCalendar()
  2046. {
  2047. $aLangs = self::getJsCalendarLangs();
  2048. $sLang = BxDolLanguages::getInstance()->detectLanguageFromArray($aLangs);
  2049. return [[
  2050. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flatpickr/dist/|flatpickr.min.css'
  2051. ], [
  2052. 'flatpickr/dist/flatpickr.min.js',
  2053. 'flatpickr/dist/l10n/' . $sLang . '.js',
  2054. ]
  2055. ];
  2056. }
  2057. function addCssJsUi ()
  2058. {
  2059. if (self::$_isCssJsUiAdded)
  2060. return;
  2061. $this->_addJs(array(
  2062. 'jquery-ui/jquery-ui.min.js',
  2063. ), "'undefined' === typeof(jQuery.ui.position)");
  2064. $this->_addCss('jquery-ui/jquery-ui.min.css');
  2065. self::$_isCssJsUiAdded = true;
  2066. }
  2067. function addCssJsUiSortable ()
  2068. {
  2069. if (self::$_isCssJsUiSortableAdded)
  2070. return;
  2071. $this->_addJs(array(
  2072. 'jquery-ui/jquery-ui.min.js'
  2073. ), "'undefined' === typeof(jQuery.ui.position)");
  2074. self::$_isCssJsUiSortableAdded = true;
  2075. }
  2076. function addCssJsTimepicker ()
  2077. {
  2078. if (self::$_isCssJsTimepickerAdded)
  2079. return;
  2080. list($aCss, $aJs) = self::getCssJsCalendar();
  2081. $this->_addCss($aCss);
  2082. $this->_addJs($aJs, "'undefined' === typeof(flatpickr)");
  2083. self::$_isCssJsTimepickerAdded = true;
  2084. }
  2085. function addCssJsMinicolors ()
  2086. {
  2087. if (self::$_isCssJsMinicolorsAdded)
  2088. return;
  2089. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  2090. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  2091. self::$_isCssJsMinicolorsAdded = true;
  2092. }
  2093. function addCssJsViewMode ()
  2094. {
  2095. if (self::$_isCssJsAddedViewMode)
  2096. return;
  2097. $this->_addCss('forms.css');
  2098. self::$_isCssJsAddedViewMode = true;
  2099. }
  2100. function addCssJsCore ()
  2101. {
  2102. if (self::$_isCssJsAdded)
  2103. return;
  2104. $this->_addCss('forms.css');
  2105. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  2106. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  2107. self::$_isCssJsAdded = true;
  2108. }
  2109. function addCssJs ()
  2110. {
  2111. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  2112. $this->addCssJsViewMode ();
  2113. } else {
  2114. $this->addCssJsCore();
  2115. }
  2116. }
  2117. protected function _processCssJs()
  2118. {
  2119. $sRet = '';
  2120. if ($this->_bDynamicMode) {
  2121. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  2122. $sRet .= "\n<script>\n";
  2123. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  2124. foreach ($this->_aJs as $sCondition => $aJs) {
  2125. $sJs = $this->oTemplate->addJs($aJs, true);
  2126. if (!$sJs)
  2127. continue;
  2128. $sRet .= "if ($sCondition)\n";
  2129. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  2130. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  2131. }
  2132. $sRet .= "\n</script>\n";
  2133. }
  2134. else {
  2135. $this->oTemplate->addCss($this->_aCss);
  2136. $aJs = array();
  2137. foreach ($this->_aJs as $sCondition => $a)
  2138. $aJs = array_merge($aJs, $a);
  2139. $this->oTemplate->addJs($aJs);
  2140. }
  2141. return $sRet;
  2142. }
  2143. protected function _addJs($mixed, $sJsCondition)
  2144. {
  2145. if (!is_array($mixed))
  2146. $mixed = array($mixed);
  2147. $this->_aJs[$sJsCondition] = $mixed;
  2148. }
  2149. protected function _addCss($mixed)
  2150. {
  2151. if (!is_array($mixed))
  2152. $mixed = array($mixed);
  2153. foreach ($mixed as $s)
  2154. $this->_aCss[$s] = $s;
  2155. }
  2156. }
  2157. /** @} */