1
0

BxBaseFormView.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  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 $_isCssJsMinicolorsAdded = false;
  15. protected static $_isCssJsLabelsAdded = false;
  16. protected static $_isCssJsTimepickerAdded = false;
  17. protected static $_isCssJsAddedViewMode = false;
  18. /**
  19. * Enable or disable error message displaying
  20. */
  21. protected $bEnableErrorIcon = true;
  22. /**
  23. * HTML Code of this form
  24. */
  25. protected $sCode;
  26. /**
  27. * Code which will be added to the beginning of the form.
  28. * For example, hidden inputs.
  29. * For internal use only
  30. */
  31. protected $_sCodeAdd = '';
  32. /**
  33. * for internal use only
  34. */
  35. protected $_isSectionOpened = false;
  36. /**
  37. * Default divider for several inputs
  38. */
  39. protected $_sDivider = '<span class="bx-def-margin-left"></span>';
  40. /**
  41. * Alternative divider for several inputs
  42. */
  43. protected $_sDividerAlt = '<br />';
  44. /**
  45. * Form is added dynamically.
  46. */
  47. protected $_bDynamicMode = false;
  48. /**
  49. * Form is submitted dynamically (using Ajax Submit).
  50. */
  51. protected $_bAjaxMode = false;
  52. /**
  53. * Use absolute Action URL which is needed in Ajax Mode.
  54. */
  55. protected $_bAbsoluteActionUrl = false;
  56. /**
  57. * Form is displayed in view mode.
  58. */
  59. protected $_bViewMode = false;
  60. /**
  61. * Show or not sections which have no fileds
  62. */
  63. protected $_bShowEmptySections = false;
  64. /**
  65. * Function name for generation close form section HTML.
  66. */
  67. protected $_sSectionClose = 'getCloseSection';
  68. /**
  69. * Function name for generation open form section HTML.
  70. */
  71. protected $_sSectionOpen = 'getOpenSection';
  72. /**
  73. * JS files list for form
  74. */
  75. protected $_aJs = array();
  76. /**
  77. * CSS files list for form
  78. */
  79. protected $_aCss = array();
  80. protected $_sJsClassName;
  81. protected $_sJsObjectName;
  82. protected $_aHtmlIds;
  83. /**
  84. * Constructor
  85. *
  86. * @param array $aInfo Form contents
  87. *
  88. * $aInfo['params'] = array(
  89. * 'remove_form' => true|false,
  90. * );
  91. *
  92. * @return BxBaseFormView
  93. */
  94. function __construct($aInfo, $oTemplate)
  95. {
  96. parent::__construct($aInfo, $oTemplate);
  97. $this->_bAjaxMode = isset($this->aParams['ajax_mode']) && $this->aParams['ajax_mode'];
  98. $this->_bViewMode = isset($this->aParams['view_mode']) && $this->aParams['view_mode'];
  99. if($this->_bViewMode) {
  100. $this->_sSectionClose = 'getCloseSectionViewMode';
  101. $this->_sSectionOpen = 'getOpenSectionViewMode';
  102. }
  103. $this->_sJsClassName = 'BxDolForm';
  104. $sName = !empty($aInfo['params']['display']) ? $aInfo['params']['display'] : '';
  105. if(empty($sName) && !empty($aInfo['params']['object']))
  106. $sName = $aInfo['params']['object'];
  107. $this->_sJsObjectName = 'oForm' . bx_gen_method_name($sName, array('_' , '-'));
  108. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $sName);
  109. $this->_aHtmlIds = array(
  110. 'help_popup' => $sHtmlId . '-help-popup-',
  111. 'pgc' => $sHtmlId . '-pgc-',
  112. 'pgc_popup' => $sHtmlId . '-pgc-popup-',
  113. 'pgc_form' => $sHtmlId . '-pgc-form-',
  114. );
  115. }
  116. public function performActionGetHelp()
  117. {
  118. $sInput = bx_process_input(bx_get('input'));
  119. if(empty($sInput) || empty($this->aInputs[$sInput]['help']))
  120. return;
  121. echo $this->oTemplate->parseHtmlByName('form_field_help_popup.html', array(
  122. 'content' => _t($this->aInputs[$sInput]['help']),
  123. 'bx_if:show_edit' => array(
  124. 'condition' => isAdmin(),
  125. 'content' => array(
  126. 'link' => BX_DOL_URL_STUDIO . bx_append_url_params('builder_forms.php', array(
  127. 'page' => 'fields',
  128. 'module' => $this->aParams['module'],
  129. 'object' => $this->aParams['object'],
  130. 'display' => $this->aParams['display']
  131. ))
  132. )
  133. )
  134. ));
  135. }
  136. public function performActionChangePrivacyGroup()
  137. {
  138. $iAuthorId = (int)bx_get_logged_profile_id();
  139. if(empty($iAuthorId))
  140. return echoJson(array());
  141. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  142. if(empty($iInputId))
  143. return echoJson(array());
  144. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  145. $sPrivacyField = BxDolPrivacy::getFieldName($sPrivacyObject);
  146. if(empty($sPrivacyField))
  147. return echoJson(array());
  148. $sPrivacyGroup = bx_process_input(bx_get($sPrivacyField));
  149. if(empty($sPrivacyField))
  150. return echoJson(array());
  151. if(!BxDolFormQuery::setInputPrivacy($iInputId, $iAuthorId, $sPrivacyField, $sPrivacyGroup))
  152. return echoJson(array());
  153. return echoJson(array(
  154. 'code' => 0,
  155. 'form_id' => $this->getId(),
  156. 'chooser_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  157. 'icon' => $this->_getPrivacyIcon($sPrivacyGroup),
  158. 'eval' => $this->getJsObjectName() . '.pgcOnSelectGroup(oData);'
  159. ));
  160. }
  161. public function performActionGetPrivacyGroupChooser()
  162. {
  163. $iInputId = bx_process_input(bx_get('input_id'), BX_DATA_INT);
  164. $sPrivacyObject = bx_process_input(bx_get('privacy_object'));
  165. if(empty($iInputId) || empty($sPrivacyObject))
  166. return '';
  167. $sFormId = $this->_aHtmlIds['pgc_form'] . $iInputId;
  168. $aFormActionParams = array();
  169. if(!empty($this->aParams['object']) && !empty($this->aParams['display']))
  170. $aFormActionParams = array(
  171. 'o' => $this->aParams['object'],
  172. 'd' => $this->aParams['display']
  173. );
  174. $aFormActionParams['a'] = 'change_privacy_group';
  175. $iAuthorId = bx_get_logged_profile_id();
  176. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  177. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacyObject);
  178. $aInputPgc = $oPrivacy->getGroupChooser($sPrivacyObject, $iAuthorId);
  179. $aInputPgc['value'] = $mixedPrivacyGroup;
  180. if(!isset($aInputPgc['content']))
  181. $aInputPgc['content'] = '';
  182. $aInputPgc['content'] .= $oPrivacy->addCssJs(true);
  183. $aInputPgc['content'] .= $oPrivacy->initGroupChooser($sPrivacyObject, $iAuthorId, array(
  184. 'content_id' => $iInputId,
  185. 'group_id' => $mixedPrivacyGroup,
  186. 'html_ids' => array(
  187. 'form' => $sFormId
  188. )
  189. ));
  190. $aFormInfo = array(
  191. 'form_attrs' => array(
  192. 'id' => $sFormId,
  193. 'action' => BX_DOL_URL_ROOT . bx_append_url_params('form.php', $aFormActionParams),
  194. 'method' => 'post'
  195. ),
  196. 'inputs' => array (
  197. 'input_id' => array(
  198. 'type' => 'hidden',
  199. 'name' => 'input_id',
  200. 'value' => $iInputId,
  201. 'db' => array (
  202. 'pass' => 'Int',
  203. ),
  204. ),
  205. 'privacy_object' => array(
  206. 'type' => 'hidden',
  207. 'name' => 'privacy_object',
  208. 'value' => $sPrivacyObject,
  209. 'db' => array (
  210. 'pass' => 'Xss',
  211. ),
  212. ),
  213. 'privacy_group_chooser' => $aInputPgc,
  214. 'controls' => array(
  215. 'name' => 'controls',
  216. 'type' => 'input_set',
  217. array(
  218. 'type' => 'button',
  219. 'name' => 'do_submit',
  220. 'value' => _t('_sys_submit'),
  221. 'attrs' => array(
  222. 'onclick' => "$('#" . $sFormId . "').submit()",
  223. ),
  224. ),
  225. array (
  226. 'type' => 'reset',
  227. 'name' => 'do_cancel',
  228. 'value' => _t('_Cancel'),
  229. 'attrs' => array(
  230. 'onclick' => "$(this).parents('.bx-popup-applied:visible:first').dolPopupHide()",
  231. 'class' => 'bx-def-margin-sec-left',
  232. ),
  233. )
  234. )
  235. )
  236. );
  237. $oForm = new BxTemplFormView($aFormInfo);
  238. echo $this->oTemplate->parseHtmlByName('form_field_privacy_popup.html', array(
  239. 'form_id' => $oForm->getId(),
  240. 'form' => $oForm->getCode(true),
  241. ));
  242. }
  243. function setShowEmptySections($b)
  244. {
  245. $this->_bShowEmptySections = $b;
  246. }
  247. function setAjaxMode($bAjaxMode)
  248. {
  249. $this->_bAjaxMode = (bool)$bAjaxMode;
  250. }
  251. function isAjaxMode()
  252. {
  253. return $this->_bAjaxMode;
  254. }
  255. function setAbsoluteActionUrl($sUrl)
  256. {
  257. if(empty($sUrl))
  258. return;
  259. $this->aFormAttrs['action'] = $sUrl;
  260. $this->_bAbsoluteActionUrl = true;
  261. }
  262. /**
  263. * Return Form code
  264. * @param $bDynamicMode - set it to true if form is added via JS/AJAX call, for example form in AJAX popup.
  265. * @return string
  266. */
  267. function getCode($bDynamicMode = false)
  268. {
  269. if(!$bDynamicMode && bx_is_dynamic_request())
  270. $bDynamicMode = true;
  271. $this->_bDynamicMode = $bDynamicMode;
  272. $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs);
  273. $sInclude = '';
  274. $this->sCode = false;
  275. bx_alert('system', 'form_output', 0, 0, array(
  276. 'dynamic' => $this->_bDynamicMode,
  277. 'object' => &$this,
  278. 'code' => &$this->sCode,
  279. 'include' => &$sInclude
  280. ));
  281. if($this->sCode === false)
  282. $this->sCode = $this->genForm();
  283. $this->addCssJs();
  284. $sDynamicCssJs = $this->_processCssJs();
  285. return $sInclude . $sDynamicCssJs . $this->sCode;
  286. }
  287. public function getJsClassName()
  288. {
  289. return $this->_sJsClassName;
  290. }
  291. public function getJsObjectName()
  292. {
  293. return $this->_sJsObjectName;
  294. }
  295. public function getJsScript($bWrap = false)
  296. {
  297. $sJsObjName = $this->getJsObjectName();
  298. $sJsObjClass = $this->getJsClassName();
  299. $sCode = "if(window['" . $sJsObjName . "'] == undefined) window['" . $sJsObjName . "'] = new " . $sJsObjClass . "(" . json_encode(array(
  300. 'sObjName' => $sJsObjName,
  301. 'sObject' => isset($this->aParams['object']) ? $this->aParams['object'] : '',
  302. 'sDisplay' => isset($this->aParams['display']) ? $this->aParams['display'] : '',
  303. 'sRootUrl' => BX_DOL_URL_ROOT,
  304. 'aHtmlIds' => $this->_aHtmlIds,
  305. )) . ");";
  306. return $bWrap ? $this->oTemplate->_wrapInTagJsCode($sCode) : $sCode;
  307. }
  308. /**
  309. * Generate the whole form
  310. *
  311. * @return string
  312. */
  313. function genForm()
  314. {
  315. $this->_sCodeAdd = '';
  316. $sTable = $this->genRows();
  317. $sHtmlBefore = isset($this->aParams['html_before']) ? $this->aParams['html_before'] : '';
  318. $sHtmlAfter = isset($this->aParams['html_after']) ? $this->aParams['html_after'] : '';
  319. if (!empty($this->aParams['remove_form']) || (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])) {
  320. $sForm = <<<BLAH
  321. $sHtmlBefore
  322. {$this->_sCodeAdd}
  323. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  324. $sTable
  325. </div>
  326. $sHtmlAfter
  327. BLAH;
  328. } else {
  329. $sFormAttrs = bx_convert_array2attrs($this->aFormAttrs, 'bx-form-advanced');
  330. $sAjaxFormJs = '';
  331. if($this->_bAjaxMode)
  332. $sAjaxFormJs = <<<BLAH
  333. $("form#{$this->id}").ajaxForm({
  334. dataType: "json",
  335. beforeSubmit: function (formData, jqForm, options) {
  336. bx_loading($("form#{$this->id}"), true);
  337. },
  338. success: function (oData) {
  339. bx_loading($("form#{$this->id}"), false);
  340. processJsonData(oData);
  341. }
  342. });
  343. BLAH;
  344. $sJsCodeDynamic = '';
  345. if($this->_bDynamicMode)
  346. $sJsCodeDynamic = 'function() {' . $this->getJsScript() . '}';
  347. $sForm = <<<BLAH
  348. $sHtmlBefore
  349. <form $sFormAttrs>
  350. {$this->_sCodeAdd}
  351. <div class="bx-form-advanced-wrapper {$this->id}_wrapper">
  352. $sTable
  353. </div>
  354. </form>
  355. <script>
  356. $(document).ready(function() {
  357. $(this).addWebForms($sJsCodeDynamic);
  358. });
  359. $sAjaxFormJs
  360. </script>
  361. $sHtmlAfter
  362. BLAH;
  363. }
  364. if(!$this->_bDynamicMode)
  365. $sForm = $this->getJsScript(true) . $sForm;
  366. return $sForm;
  367. }
  368. /**
  369. * Generate Table HTML code
  370. *
  371. * @return string
  372. */
  373. function genRows()
  374. {
  375. // add CSRF token if it's needed.
  376. 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) {
  377. $this->aInputs['csrf_token'] = array(
  378. 'type' => 'hidden',
  379. 'name' => 'csrf_token',
  380. 'value' => $mixedCsrfToken,
  381. 'db' => array ('pass' => 'Xss'),
  382. 'visible_for_levels' => PHP_INT_MAX,
  383. );
  384. }
  385. // add 'Ajax Mode' flag
  386. if($this->_bAjaxMode)
  387. $this->aInputs['ajax_mode'] = array(
  388. 'type' => 'hidden',
  389. 'name' => 'ajax_mode',
  390. 'value' => 1,
  391. 'db' => array ('pass' => 'Int'),
  392. 'visible_for_levels' => PHP_INT_MAX,
  393. );
  394. // add 'Absolute Action Url' flag
  395. if($this->_bAbsoluteActionUrl)
  396. $this->aInputs['absolute_action_url'] = array(
  397. 'type' => 'hidden',
  398. 'name' => 'absolute_action_url',
  399. 'value' => 1,
  400. 'db' => array ('pass' => 'Int'),
  401. 'visible_for_levels' => PHP_INT_MAX,
  402. );
  403. // check if we need to generate open section clause
  404. $sOpenSection = '';
  405. foreach ($this->aInputs as $aInput) {
  406. if (isset($aInput['type']) && 'hidden' == $aInput['type'])
  407. continue;
  408. if (isset($aInput['type']) && 'block_header' != $aInput['type'])
  409. $sOpenSection = $this->{$this->_sSectionOpen}();
  410. break;
  411. }
  412. // generate rows contents
  413. $sCont = '';
  414. $sContHeader = '';
  415. $sContFields = '';
  416. $sFuncGenRow = isset($this->aParams['view_mode']) && $this->aParams['view_mode'] ? 'genViewRow' : 'genRow';
  417. foreach ($this->aInputs as $aInput) {
  418. if (!isset($aInput['visible_for_levels']) || self::isVisible($aInput)) {
  419. if ('block_header' == $aInput['type'] && !$this->_bShowEmptySections) {
  420. // don't show section with no fields or with empty fields
  421. if ($sContHeader) {
  422. if ($sContFields)
  423. $sCont .= $sContHeader . $sContFields;
  424. else
  425. $sContHeader = '';
  426. $sContFields = '';
  427. }
  428. else {
  429. $sCont .= $sContFields;
  430. $sContFields = '';
  431. }
  432. $sContHeader = $this->$sFuncGenRow($aInput);
  433. } else {
  434. $sContFields .= $this->$sFuncGenRow($aInput);
  435. }
  436. }
  437. }
  438. $sCont .= $sContHeader . $sContFields;
  439. $sCloseSection = $this->{$this->_sSectionClose}();
  440. return $sOpenSection . $sCont . $sCloseSection;
  441. }
  442. /**
  443. * Generate single Table Row
  444. *
  445. * @param array $aInput
  446. * @return string
  447. */
  448. function genRow(&$aInput)
  449. {
  450. if (!isset($aInput['type']))
  451. $aInput['type'] = false;
  452. if (!empty($aInput['name'])) {
  453. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  454. if (method_exists($this, $sCustomMethod))
  455. return $this->$sCustomMethod($aInput);
  456. }
  457. switch ($aInput['type']) {
  458. case 'block_header':
  459. $sRow = $this->genRowBlockHeader($aInput);
  460. break;
  461. case 'block_end':
  462. $sRow = $this->genBlockEnd($aInput);
  463. break;
  464. case 'hidden':
  465. // do not generate row for hidden inputs
  466. $sRow = '';
  467. $this->_sCodeAdd .= $this->genInput($aInput);
  468. break;
  469. case 'select_box':
  470. $sRow = $this->genRowCustom($aInput, 'genInputSelectBox');
  471. break;
  472. case 'files':
  473. $sRow = $this->genRowCustom($aInput, 'genInputFiles');
  474. break;
  475. case 'switcher':
  476. case 'checkbox':
  477. $sRow = $this->genRowStandard($aInput, true);
  478. break;
  479. default:
  480. $sRow = $this->genRowStandard($aInput);
  481. }
  482. return $sRow;
  483. }
  484. public function isInputVisible($mixedInput)
  485. {
  486. if(!is_array($mixedInput) && isset($this->aInputs[$mixedInput]))
  487. $mixedInput = $this->aInputs[$mixedInput];
  488. if(empty($mixedInput) || !is_array($mixedInput))
  489. $mixedInput = BxDolFormQuery::getInputByName($this->aParams['object'], $mixedInput);
  490. if(empty($mixedInput) || !is_array($mixedInput))
  491. return false;
  492. if(!empty($mixedInput['privacy']) && !empty($this->_iAuthorId) && !$this->_isInputVisibleByPrivacy($mixedInput))
  493. return false;
  494. return true;
  495. }
  496. protected function _isInputVisibleByPrivacy($aInput)
  497. {
  498. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  499. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  500. return true;
  501. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  502. if(empty($aInputPrivacy) || !is_array($aInputPrivacy))
  503. if(BxDolFormQuery::setInputPrivacy($aInput['id'], $this->_iAuthorId, BxDolPrivacy::getFieldName($this->_sPrivacyObjectView), $this->_sPrivacyGroupDefault))
  504. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($aInput['id'], $this->_iAuthorId);
  505. if((empty($aInputPrivacy) || !is_array($aInputPrivacy)) && $this->_sPrivacyGroupDefault != BX_DOL_PG_ALL)
  506. return false;
  507. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  508. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  509. return false;
  510. return true;
  511. }
  512. /**
  513. * Generate single Table Row for view mode
  514. *
  515. * @param array $aInput
  516. * @return string
  517. */
  518. function genViewRow(&$aInput)
  519. {
  520. if (!isset($aInput['type']))
  521. $aInput['type'] = false;
  522. if(!$this->isInputVisible($aInput))
  523. return '';
  524. if (!empty($aInput['name'])) {
  525. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  526. if (method_exists($this, $sCustomMethod))
  527. return $this->$sCustomMethod($aInput);
  528. }
  529. switch ($aInput['type']) {
  530. case 'block_header':
  531. $sRow = $this->genRowBlockHeader($aInput);
  532. break;
  533. case 'block_end':
  534. $sRow = $this->genBlockEnd($aInput);
  535. break;
  536. case 'nested_form':
  537. $sRow = $this->genNestedForm($aInput);
  538. break;
  539. default:
  540. $sRow = $this->genViewRowWrapped($aInput);
  541. }
  542. return $sRow;
  543. }
  544. /**
  545. * Generate complete wrapped row for view mode form
  546. *
  547. * @param array $aInput
  548. * @return string
  549. */
  550. function genViewRowWrapped(&$aInput)
  551. {
  552. $sValue = $this->genViewRowValue($aInput);
  553. if (null === $sValue)
  554. return '';
  555. return $this->oTemplate->parseHtmlByName('form_view_row.html', array(
  556. 'type' => $aInput['type'],
  557. 'caption' => isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '',
  558. 'value' => $sValue
  559. ));
  560. }
  561. /**
  562. * Generate value for view mode row
  563. *
  564. * @param array $aInput
  565. * @return string
  566. */
  567. function genViewRowValue(&$aInput)
  568. {
  569. if (!empty($aInput['name'])) {
  570. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  571. if (method_exists($this, $sCustomMethod))
  572. return $this->$sCustomMethod($aInput);
  573. }
  574. switch ($aInput['type']) {
  575. case 'hidden':
  576. $sValue = null;
  577. break;
  578. case 'select':
  579. case 'radio_set':
  580. $sValue = $this->genViewRowValueForSelect($aInput);
  581. break;
  582. case 'datepicker':
  583. $sValue = null;
  584. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  585. break;
  586. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  587. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'] . " Z", isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  588. else
  589. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  590. break;
  591. case 'date_time':
  592. case 'datetime':
  593. $sValue = null;
  594. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  595. break;
  596. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass']) && !is_numeric($aInput['value']))
  597. $sValue = BxTemplFunctions::getInstance()->timeForJsFullDate($aInput['value'] . " Z", isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  598. else
  599. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  600. break;
  601. case 'checkbox_set':
  602. case 'select_multiple':
  603. $sValue = null;
  604. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  605. $sValue = '';
  606. foreach ($aInput['value'] as $sVal)
  607. $sValue .= $aInput['values'][$sVal] . ', ';
  608. $sValue = trim ($sValue, ', ');
  609. }
  610. break;
  611. case 'checkbox':
  612. case 'switcher':
  613. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  614. break;
  615. case 'textarea':
  616. if (isset($aInput['value']) && '' !== $aInput['value'])
  617. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  618. else
  619. $sValue = null;
  620. break;
  621. case 'text':
  622. if(isset($aInput['value']) && '' !== $aInput['value'])
  623. $sValue = bx_linkify(bx_process_output($aInput['value']));
  624. else
  625. $sValue = null;
  626. break;
  627. default:
  628. if(isset($aInput['value']) && '' !== $aInput['value']) {
  629. $sValue = $aInput['value'];
  630. if(get_mb_substr($sValue, 0, 1) == '_')
  631. $sValue = _t($sValue);
  632. $sValue = bx_process_output($sValue);
  633. }
  634. else
  635. $sValue = null;
  636. }
  637. return $sValue;
  638. }
  639. function genViewRowValueForSelect(&$aInput)
  640. {
  641. if (!isset($aInput['value']) || !$aInput['value'])
  642. return null;
  643. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  644. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])) !== false)
  645. return $oCategory->getCategoryLink($s, $aInput['value']);
  646. return $s;
  647. }
  648. protected function genCustomRowBirthday(&$aInput)
  649. {
  650. if(!$this->_bViewMode)
  651. return $this->genRowStandard($aInput);
  652. $aInput['caption_src'] = '_sys_form_input_age';
  653. $aInput['caption'] = _t($aInput['caption_src']);
  654. return $this->genViewRowWrapped($aInput);
  655. }
  656. protected function genCustomViewRowValueBirthday(&$aInput)
  657. {
  658. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00')))
  659. return null;
  660. $sValue = $aInput['value'];
  661. $iPosSpace = strpos($sValue, ' ');
  662. if($iPosSpace !== false)
  663. $sValue = trim(substr($sValue, 0, $iPosSpace));
  664. $aDate = explode('-', $sValue);
  665. $iCdYear = (int)date('Y');
  666. $iCdMonth = (int)date('n');
  667. $iCdDay = (int)date('j');
  668. $iResult = $iCdYear - (int)$aDate[0];
  669. if($iCdMonth < (int)$aDate[1] || ($iCdMonth == (int)$aDate[1] && $iCdDay < (int)$aDate[2]))
  670. $iResult -= 1;
  671. return $iResult;
  672. }
  673. /**
  674. * Generate standard row
  675. *
  676. * @param array $aInput
  677. * @return string
  678. */
  679. function genRowStandard(&$aInput, $isOneLine = false)
  680. {
  681. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  682. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  683. $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> ' : '';
  684. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  685. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  686. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  687. $sClassWrapper = 'bx-form-element-wrapper';
  688. if($isOneLine)
  689. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  690. $sClassWrapper .= ' bx-def-margin-top';
  691. if (isset($aInput['name']))
  692. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  693. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  694. $sClassOneLineCaption = '';
  695. $sClassOneLineValue = '';
  696. if ($isOneLine) {
  697. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  698. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  699. $aInput['attrs']['id'] = $this->getInputId($aInput);
  700. if ($sCaption)
  701. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  702. }
  703. $sInput = $this->genInput($aInput);
  704. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  705. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  706. if(empty($sErrorIcon))
  707. $sErrorIcon = '';
  708. $aTmplVarsRow = array(
  709. 'bx_if:show_caption' => array(
  710. 'condition' => !empty($sCaption),
  711. 'content' => array(
  712. 'class_caption' => $sClassOneLineCaption,
  713. 'caption' => $sCaption,
  714. 'required' => $sRequired,
  715. 'help' => $sHelp,
  716. )
  717. ),
  718. 'class_value' => $sClassAdd . $sClassOneLineValue,
  719. 'value' => $this->genWrapperInput($aInput, $sInput),
  720. 'info' => $sInfoIcon,
  721. 'error' => $sErrorIcon,
  722. );
  723. return $this->oTemplate->parseHtmlByName('form_row_standard.html', array(
  724. 'tr_attrs' => $sTrAttrs,
  725. 'bx_if:show_one_line' => array(
  726. 'condition' => $isOneLine,
  727. 'content' => $aTmplVarsRow
  728. ),
  729. 'bx_if:show_lined' => array(
  730. 'condition' => !$isOneLine,
  731. 'content' => $aTmplVarsRow
  732. ),
  733. 'info' => $sInfoIcon,
  734. 'error' => $sErrorIcon
  735. ));
  736. }
  737. function genWrapperInput($aInput, $sContent)
  738. {
  739. $sClass = "";
  740. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  741. $sClass .= ' bx-form-input-wrapper-html';
  742. $sAttrs = "";
  743. if(isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper'])) {
  744. if(!empty($aInput['attrs_wrapper']['class'])) {
  745. $sClass .= ' ' . trim($aInput['attrs_wrapper']['class']);
  746. unset($aInput['attrs_wrapper']['class']);
  747. }
  748. $sAttrs = bx_convert_array2attrs($aInput['attrs_wrapper']);
  749. }
  750. return $this->oTemplate->parseHtmlByName('form_input_wrapper.html', array(
  751. 'type' => $aInput['type'],
  752. 'class' => $sClass,
  753. 'attrs' => $sAttrs,
  754. 'content' => $sContent
  755. ));
  756. }
  757. /**
  758. * Generate custom row
  759. *
  760. * @param array $aInput
  761. * @param string $sCustomMethod custom method to generate code for input
  762. * @return string
  763. */
  764. function genRowCustom(&$aInput, $sCustomMethod)
  765. {
  766. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  767. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span>' : '';
  768. $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> ' : '';
  769. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  770. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  771. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  772. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  773. if (isset($aInput['name']))
  774. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  775. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  776. return $this->oTemplate->parseHtmlByName('form_row_custom.html', array(
  777. 'tr_attrs' => $sTrAttrs,
  778. 'bx_if:show_caption' => array(
  779. 'condition' => !empty($sCaption),
  780. 'content' => array(
  781. 'caption' => $sCaption,
  782. 'required' => $sRequired,
  783. 'help' => $sHelp
  784. )
  785. ),
  786. 'class_value' => $sClassAdd,
  787. 'value' => $sInput,
  788. ));
  789. }
  790. /**
  791. * Generate Block Headers row
  792. *
  793. * @param array $aInput
  794. * @return string
  795. */
  796. function genRowBlockHeader(&$aInput)
  797. {
  798. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  799. // if there is no caption - show divider only
  800. if (empty($aInput['caption'])) {
  801. $sCode = $this->{$this->_sSectionClose}();
  802. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  803. return $sCode;
  804. }
  805. // if section is collapsed by default, add necessary code
  806. $sClassAddCollapsable = 'bx-form-collapsable';
  807. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  808. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  809. // display section with caption
  810. $sCode = $this->{$this->_sSectionClose}();
  811. if (empty($aAttrs))
  812. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  813. else
  814. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  815. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  816. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-large">' . bx_process_output($aInput['caption']) . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  817. else
  818. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-large"><a href="javascript:void(0);">' . bx_process_output($aInput['caption']) . '</a>' . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  819. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sLegend);
  820. return $sCode;
  821. }
  822. function genBlockEnd()
  823. {
  824. $aNextTbodyAdd = false; // need to have some default
  825. $sCode = '';
  826. $sCode .= $this->{$this->_sSectionClose}();
  827. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  828. return $sCode;
  829. }
  830. /**
  831. * Generate HTML Input Element
  832. *
  833. * @param array $aInput
  834. * @return string Output HTML Code
  835. */
  836. function genInput(&$aInput)
  837. {
  838. if (!empty($aInput['name'])) {
  839. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  840. if (method_exists($this, $sCustomMethod))
  841. return $this->$sCustomMethod($aInput);
  842. }
  843. switch ($aInput['type']) {
  844. case 'datepicker':
  845. if (!isset($aInput['attrs']))
  846. $aInput['attrs'] = array();
  847. $aInput['attrs']['autosuggestion'] = 'off';
  848. $sInput = $this->genInputStandard($aInput);
  849. break;
  850. // standard inputs (and non-standard, interpreted as standard)
  851. case 'text':
  852. case 'datepicker':
  853. case 'date_time':
  854. case 'datetime':
  855. case 'number':
  856. case 'time':
  857. case 'checkbox':
  858. case 'radio':
  859. case 'image':
  860. case 'slider':
  861. case 'doublerange':
  862. case 'hidden':
  863. $sInput = $this->genInputStandard($aInput);
  864. break;
  865. case 'password':
  866. $sInput = $this->genInputPassword($aInput);
  867. break;
  868. case 'file':
  869. $sInput = $this->genInputFile($aInput);
  870. break;
  871. case 'rgb':
  872. case 'rgba':
  873. $sClass = 'bx-form-input-' . $aInput['type'];
  874. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  875. $aInput['type'] = 'text';
  876. $sInput = $this->genInputStandard($aInput);
  877. break;
  878. case 'switcher':
  879. $sInput = $this->genInputSwitcher($aInput);
  880. break;
  881. case 'button':
  882. case 'reset':
  883. case 'submit':
  884. $sInput = $this->genInputButton($aInput);
  885. break;
  886. case 'textarea':
  887. $sInput = $this->genInputTextarea($aInput);
  888. break;
  889. case 'select':
  890. $sInput = $this->genInputSelect($aInput);
  891. break;
  892. case 'select_multiple':
  893. $sInput = $this->genInputSelectMultiple($aInput);
  894. break;
  895. case 'checkbox_set':
  896. $sInput = $this->genInputCheckboxSet($aInput);
  897. break;
  898. case 'radio_set':
  899. $sInput = $this->genInputRadioSet($aInput);
  900. break;
  901. case 'input_set': // numeric array of inputs
  902. $sInput = '';
  903. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  904. foreach ($aInput as $iKey => $aSubInput) {
  905. if (!is_int($iKey) or !$aSubInput)
  906. continue; // parse only integer keys and existing values
  907. $sInput .= $this->genInput($aSubInput); // recursive call
  908. $sInput .= $sDivider;
  909. }
  910. $sInput .= '<div class="bx-clear"></div>';
  911. break;
  912. case 'custom':
  913. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  914. break;
  915. case 'captcha':
  916. $sInput = $this->genInputCaptcha($aInput);
  917. break;
  918. case 'location':
  919. $sInput = $this->genInputLocation($aInput);
  920. break;
  921. case 'nested_form':
  922. $sInput = $this->genInputNestedForm($aInput);
  923. break;
  924. case 'value':
  925. $sInput = '';
  926. if(!isset($aInput['value']))
  927. break;
  928. $sInput = $aInput['value'];
  929. if(get_mb_substr($sInput, 0, 1) == '_')
  930. $sInput = _t($sInput);
  931. break;
  932. default:
  933. //unknown control type
  934. $sInput = 'Unknown control type';
  935. }
  936. // create input label
  937. $sInput .= $this->genLabel($aInput);
  938. // create input privacy group chooser
  939. $sInput .= $this->genPrivacyGroupChooser($aInput);
  940. return $sInput;
  941. }
  942. /**
  943. * Generate new Input Element id
  944. *
  945. * @param array $aInput
  946. * @return string
  947. */
  948. function getInputId(&$aInput)
  949. {
  950. if (isset($aInput['id']))
  951. return $aInput['id'];
  952. $sName = md5($aInput['name']);
  953. $sID = $this->id . '_input_' . $sName;
  954. if ( // multiple elements cause identical id's
  955. (
  956. (
  957. $aInput['type'] == 'checkbox' and
  958. substr($aInput['name'], -2) == '[]' // it is multiple element
  959. ) or
  960. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  961. ) and
  962. isset($aInput['value']) // if we can make difference
  963. ) {
  964. $sValue = md5($aInput['value']);
  965. // add value
  966. $sID .= '_' . $sValue;
  967. }
  968. $sID = trim($sID, '_');
  969. $aInput['id'] = $sID; // just for repeated calls
  970. return $sID;
  971. }
  972. /**
  973. * Generate standard Input Element
  974. *
  975. * @param array $aInput
  976. * @return string
  977. */
  978. function genInputStandard(&$aInput)
  979. {
  980. // clone attributes for system use ;)
  981. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  982. // add default className to attributes
  983. $aAttrs['type'] = $aInput['type'];
  984. if ('datetime' == $aAttrs['type'])
  985. $aAttrs['type'] = 'date_time';
  986. switch($aAttrs['type']) {
  987. case 'date_time':
  988. $this->addCssJsUi ();
  989. $this->addCssJsTimepicker ();
  990. break;
  991. case 'slider':
  992. case 'doublerange':
  993. case 'datepicker':
  994. $this->addCssJsUi ();
  995. break;
  996. case 'text':
  997. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  998. $this->addCssJsMinicolors ();
  999. break;
  1000. }
  1001. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  1002. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  1003. }
  1004. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1005. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  1006. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  1007. // for inputs with labels generate id
  1008. if (isset($aInput['label']))
  1009. $aAttrs['id'] = $this->getInputId($aInput);
  1010. // for checkboxes
  1011. if (isset($aInput['checked']) and $aInput['checked'])
  1012. $aAttrs['checked'] = 'checked';
  1013. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  1014. return "<input $sAttrs />\n";
  1015. }
  1016. /**
  1017. * Generate Switcher Input Element (based on checkbox)
  1018. *
  1019. * @param array $aInput
  1020. * @return string
  1021. */
  1022. function genInputSwitcher(&$aInput)
  1023. {
  1024. $aInput['type'] = 'checkbox';
  1025. $sCheckbox = $this->genInputStandard($aInput);
  1026. $aInput['type'] = 'switcher';
  1027. $sClass = 'off';
  1028. if (isset($aInput['checked']) and $aInput['checked'])
  1029. $sClass = 'on';
  1030. return '
  1031. <div class="bx-switcher-cont ' . $sClass . '">' . $sCheckbox . '
  1032. <div class="bx-switcher-canvas">
  1033. <div class="bx-switcher-on"><i class="sys-icon check"></i></div>
  1034. <div class="bx-switcher-off"><i class="sys-icon times"></i></div>
  1035. <div class="bx-switcher-handler">&nbsp;</div>
  1036. </div>
  1037. </div>';
  1038. }
  1039. /**
  1040. * Generate Button Input Element
  1041. *
  1042. * @param array $aInput
  1043. * @return string
  1044. */
  1045. function genInputButton(&$aInput)
  1046. {
  1047. // clone attributes for system use ;)
  1048. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1049. // add default className to attributes
  1050. $aAttrs['type'] = $aInput['type'];
  1051. if (isset($aInput['value']))
  1052. $aAttrs['value'] = $aInput['value'];
  1053. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  1054. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn" . ('submit' == $aInput['type'] ? ' bx-btn-primary' : ''));
  1055. return "<button $sAttrs>" . $aInput['value'] . "</button>\n";
  1056. }
  1057. /**
  1058. * Generate Textarea Element
  1059. *
  1060. * @param array $aInput
  1061. * @return string
  1062. */
  1063. function genInputTextarea(&$aInput)
  1064. {
  1065. // clone attributes for system use ;)
  1066. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1067. $aAttrs['name'] = $aInput['name'];
  1068. // for inputs with labels generate id
  1069. if (isset($aInput['label']))
  1070. $aAttrs['id'] = $this->getInputId($aInput);
  1071. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}" . ((isset($aInput['html']) and $aInput['html'] and $this->addHtmlEditor($aInput['html'], $aInput)) ? ' bx-form-input-html' : ''));
  1072. $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')) : '';
  1073. return "<textarea $sAttrs>$sValue</textarea>";
  1074. }
  1075. function isHtmlEditor($iViewMode, &$aInput)
  1076. {
  1077. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  1078. }
  1079. function addHtmlEditor($iViewMode, &$aInput)
  1080. {
  1081. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  1082. if (!$oEditor)
  1083. return false;
  1084. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  1085. return true;
  1086. }
  1087. /**
  1088. * Generate Select Box Element
  1089. *
  1090. * @param array $aInput
  1091. * @return string
  1092. */
  1093. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1094. {
  1095. $aNewInput = $aInput;
  1096. $aNewInput['type'] = 'select';
  1097. $aNewInput['name'] .= '[]';
  1098. $sInput = $this->genInput($aNewInput);
  1099. return <<<BLAH
  1100. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1101. $sInput
  1102. </div>
  1103. $sInfo
  1104. $sError
  1105. BLAH;
  1106. }
  1107. /**
  1108. * Generate Browse File Element
  1109. *
  1110. * @param array $aInput
  1111. * @return string
  1112. */
  1113. function genInputFile(&$aInput)
  1114. {
  1115. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1116. if(!empty($aInput['attrs']['onchange']))
  1117. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1118. else
  1119. $aInput['attrs']['onchange'] = $sOnChange;
  1120. $sInput = $this->genInputStandard($aInput);
  1121. 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>';
  1122. }
  1123. /**
  1124. * Generate Select Box Element
  1125. *
  1126. * @param array $aInput
  1127. * @return string
  1128. */
  1129. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1130. {
  1131. $sUniqId = !empty($aInput['uploaders_id']) ? $aInput['uploaders_id'] : genRndPwd (8, false);
  1132. $sUploaders = '';
  1133. $oUploader = null;
  1134. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1135. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1136. if (!$oUploader)
  1137. continue;
  1138. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1139. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1140. if (empty($aInput['attrs']['disabled']))
  1141. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1142. $aParams = array(
  1143. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1144. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1145. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1146. 'attrs' => bx_convert_array2attrs($aAttrs),
  1147. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1148. );
  1149. if (isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1150. $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1151. $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams, $this->_bDynamicMode);
  1152. }
  1153. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1154. 'uploaders_buttons' => $sUploaders,
  1155. 'info' => $sInfo,
  1156. 'error' => $sError,
  1157. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1158. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1159. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1160. 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1,
  1161. ));
  1162. }
  1163. protected function genGhostTemplate(&$aInput)
  1164. {
  1165. $sGhostTemplate = false;
  1166. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1167. $oFormNested = $aInput['ghost_template'];
  1168. if ($oFormNested instanceof BxDolFormNestedGhost)
  1169. $sGhostTemplate = $oFormNested->genForm();
  1170. } 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
  1171. $oFormNested = new BxDolFormNestedGhost($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1172. $sGhostTemplate = $oFormNested->getCode();
  1173. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1174. $sGhostTemplate = array ();
  1175. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1176. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNestedGhost)
  1177. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1178. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1179. $sGhostTemplate = $aInput['ghost_template'];
  1180. }
  1181. return $sGhostTemplate;
  1182. }
  1183. protected function genCustomInputUsernamesSuggestions ($aInput)
  1184. {
  1185. $this->addCssJsUi();
  1186. $sVals = '';
  1187. if(!empty($aInput['value'])) {
  1188. if(is_array($aInput['value'])) {
  1189. foreach($aInput['value'] as $sVal) {
  1190. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1191. continue;
  1192. $sVals .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . $oProfile->getUnit(0, array('template' => 'unit_wo_info')) . $oProfile->getDisplayName() . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . $sVal . '" /></b>';
  1193. }
  1194. $sVals = trim($sVals, ',');
  1195. }
  1196. else if(is_string($aInput['value']))
  1197. $sVals = $aInput['value'];
  1198. }
  1199. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1200. $sId = $aInput['name'] . time() . mt_rand(0, 100);
  1201. $sClass = 'bx-form-input-autotoken bx-def-font-inputs bx-form-input-text';
  1202. if($bDisabled)
  1203. $sClass .= ' bx-form-input-disabled';
  1204. if(!empty($aInput['attrs']['class'])) {
  1205. $sClass .= ' ' . $aInput['attrs']['class'];
  1206. unset($aInput['attrs']['class']);
  1207. }
  1208. $aAttrs = array('value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off');
  1209. if(isset($aInput['attrs']) && is_array($aInput['attrs']))
  1210. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1211. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1212. 'id' => $sId,
  1213. 'name' => $aInput['name'],
  1214. 'class' => $sClass,
  1215. 'vals' => $sVals,
  1216. 'bx_if:input' => array(
  1217. 'condition' => !$bDisabled,
  1218. 'content' => array(
  1219. 'attrs' => bx_convert_array2attrs($aAttrs),
  1220. )
  1221. ),
  1222. 'bx_if:init' => array(
  1223. 'condition' => !$bDisabled,
  1224. 'content' => array(
  1225. 'id' => $sId,
  1226. 'name' => $aInput['name'],
  1227. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1228. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1229. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1230. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1231. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1232. )
  1233. )
  1234. ));
  1235. }
  1236. protected function genCustomViewRowValueLabels ($aInput)
  1237. {
  1238. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1239. return null;
  1240. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1241. $aInput['value'] = unserialize($aInput['value']);
  1242. $s = '';
  1243. foreach ($aInput['value'] as $sLabel)
  1244. $s .= '<a href="' . $oMetatags->keywordsGetHashTagUrl($sLabel, $aInput['content_id']) . '"><b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sLabel) . '</b></a>';
  1245. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1246. 'values' => $s,
  1247. ));
  1248. }
  1249. protected function genCustomInputLabels ($aInput)
  1250. {
  1251. $oLabel = BxDolLabel::getInstance();
  1252. $sName = !empty($aInput['name']) ? $aInput['name'] : 'labels';
  1253. $sValue = '';
  1254. if(!empty($aInput['value'])) {
  1255. if(!is_array($aInput['value']))
  1256. $aInput['value'] = unserialize($aInput['value']);
  1257. if(is_array($aInput['value']))
  1258. foreach($aInput['value'] as $sLabel)
  1259. $sValue .= $oLabel->getLabel($sName, $sLabel);
  1260. }
  1261. $sKeyPlaceholder = $aInput['caption_src'] . '_placeholder';
  1262. if(strcmp($sKeyPlaceholder, _t($sKeyPlaceholder)) != 0)
  1263. $sValue .= $oLabel->getLabelPlaceholder($sKeyPlaceholder);
  1264. $aInputLabels = array(
  1265. 'type' => 'custom',
  1266. 'name' => $sName,
  1267. 'caption' => '',
  1268. 'value' => $sValue,
  1269. 'ajax_get_suggestions' => BX_DOL_URL_ROOT . bx_append_url_params('label.php', array(
  1270. 'action' => 'labels_list',
  1271. )),
  1272. 'attrs' => array(
  1273. 'class' => 'bx-form-input-labels',
  1274. 'disabled' => 'disabled'
  1275. )
  1276. );
  1277. return $this->oTemplate->parseHtmlByName('label_select_field.html', array(
  1278. 'js_object' => $oLabel->getJsObjectName(),
  1279. 'js_code' => $oLabel->getJsCodeForm(),
  1280. 'html_id' => $oLabel->getFormFieldId($aInput),
  1281. 'name' => $sName,
  1282. 'input_labels' => $this->genCustomInputUsernamesSuggestions($aInputLabels)
  1283. ));
  1284. }
  1285. /**
  1286. * Generate Select Element
  1287. *
  1288. * @param array $aInput
  1289. * @return string
  1290. */
  1291. function genInputSelect(&$aInput)
  1292. {
  1293. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1294. return $this->_genInputSelect($aInput, false, $sCurValue, '_isSelected');
  1295. }
  1296. /**
  1297. * Generate Multiple Select Element
  1298. *
  1299. * @param array $aInput
  1300. * @return string
  1301. */
  1302. function genInputSelectMultiple(&$aInput)
  1303. {
  1304. $aCurValues = array();
  1305. if (isset($aInput['value']) && $aInput['value'])
  1306. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1307. return $this->_genInputSelect($aInput, true, $aCurValues, '_isSelectedMultiple');
  1308. }
  1309. /**
  1310. * Generate Checkbox Set Element
  1311. *
  1312. * @param array $aInput
  1313. * @return string
  1314. */
  1315. function genInputCheckboxSet(&$aInput)
  1316. {
  1317. $aCurValues = array();
  1318. if (isset($aInput['value']) && $aInput['value'])
  1319. $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
  1320. return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
  1321. }
  1322. /**
  1323. * Generate Radiobuttons Set Element
  1324. *
  1325. * @param array $aInput
  1326. * @return string
  1327. */
  1328. function genInputRadioSet(&$aInput)
  1329. {
  1330. $sCurValue = isset($aInput['value']) ? $aInput['value'] : '';
  1331. return $this->_genInputsSet($aInput, 'radio', $sCurValue, '_isSelected');
  1332. }
  1333. function _isSelected ($sValue, $sCurValue)
  1334. {
  1335. return ((string)$sValue === (string)$sCurValue);
  1336. }
  1337. function _isSelectedMultiple ($sValue, $aCurValues)
  1338. {
  1339. return in_array($sValue, $aCurValues);
  1340. }
  1341. function _genInputSelect(&$aInput, $isMultiple, $mixedCurrentVal, $sIsSelectedFunc)
  1342. {
  1343. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1344. $aAttrs['name'] = $aInput['name'];
  1345. if ($isMultiple) {
  1346. $aAttrs['name'] .= '[]';
  1347. $aAttrs['multiple'] = 'multiple';
  1348. }
  1349. // for inputs with labels generate id
  1350. if (isset($aInput['label']))
  1351. $aAttrs['id'] = $this->getInputId($aInput);
  1352. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  1353. // generate options
  1354. $sOptions = '';
  1355. if (isset($aInput['values']) and is_array($aInput['values'])) {
  1356. foreach ($aInput['values'] as $sValue => $sTitle) {
  1357. $sAttrsOpt = "";
  1358. if(is_array($sTitle)) {
  1359. if(isset($sTitle['type'])) {
  1360. switch($sTitle['type']) {
  1361. case 'group_header':
  1362. $sTitle = bx_process_output($sTitle['value']);
  1363. $sOptions .= <<<BLAH
  1364. <optgroup label="$sTitle">
  1365. BLAH;
  1366. break;
  1367. case 'group_end':
  1368. $sOptions .= <<<BLAH
  1369. </optgroup>
  1370. BLAH;
  1371. break;
  1372. }
  1373. continue;
  1374. }
  1375. $aAttrsOpt = array();
  1376. if(!empty($sTitle['attrs']) && is_array($sTitle['attrs']))
  1377. $aAttrsOpt = $sTitle['attrs'];
  1378. if(isset($sTitle['class']))
  1379. $aAttrsOpt['class'] = !empty($aAttrsOpt['class']) ? $aAttrsOpt['class'] . ' ' . $sTitle['class'] : $sTitle['class'];
  1380. if(isset($sTitle['style']))
  1381. $aAttrsOpt['style'] = !empty($aAttrsOpt['style']) ? $aAttrsOpt['style'] . ' ' . $sTitle['style'] : $sTitle['style'];
  1382. $sAttrsOpt = !empty($aAttrsOpt) ? bx_convert_array2attrs($aAttrsOpt) : '';
  1383. $sValue = $sTitle['key'];
  1384. $sTitle = $sTitle['value'];
  1385. }
  1386. $sValueC = bx_html_attribute($sValue);
  1387. $sTitleC = bx_process_output($sTitle);
  1388. $sSelected = $this->$sIsSelectedFunc($sValue, $mixedCurrentVal) ? 'selected="selected"' : '';
  1389. $sOptions .= <<<BLAH
  1390. <option value="$sValueC" $sAttrsOpt $sSelected>$sTitleC</option>
  1391. BLAH;
  1392. }
  1393. }
  1394. // generate element
  1395. $sCode = <<<BLAH
  1396. <select $sAttrs>
  1397. $sOptions
  1398. </select>
  1399. BLAH;
  1400. if(!empty($aInput['content']))
  1401. $sCode .= $aInput['content'];
  1402. return $sCode;
  1403. }
  1404. function _genInputsSet(&$aInput, $sType, $mixedCurrentVal, $sIsCheckedFunc, $sNameAppend = '')
  1405. {
  1406. $aAttrs = empty($aInput['attrs']) || 'radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type'] ? array() : $aInput['attrs'];
  1407. $aAttrs['name'] = $aInput['name'];
  1408. // for inputs with labels generate id
  1409. if (isset($aInput['label']))
  1410. $aAttrs['id'] = $this->getInputId($aInput);
  1411. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1412. // generate options
  1413. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : $this->_sDivider;
  1414. $sOptions = '';
  1415. if (isset($aInput['values']) && is_array($aInput['values'])) {
  1416. if (count($aInput['values']) > 3 && $sDivider == $this->_sDivider)
  1417. $sDivider = $this->_sDividerAlt;
  1418. // generate complex input using simple standard inputs
  1419. foreach ($aInput['values'] as $sValue => $sLabel) {
  1420. if(is_array($sLabel)) {
  1421. $sValue = $sLabel['key'];
  1422. $sLabel = $sLabel['value'];
  1423. }
  1424. // create new simple input
  1425. $aNewInput = array(
  1426. 'type' => $sType,
  1427. 'name' => $aInput['name'] . $sNameAppend,
  1428. 'value' => $sValue,
  1429. 'checked' => $this->$sIsCheckedFunc($sValue, $mixedCurrentVal),
  1430. 'label' => $sLabel,
  1431. 'attrs' => !empty($aInput['attrs']) && ('radio_set' == $aInput['type'] || 'checkbox_set' == $aInput['type']) ? $aInput['attrs'] : false,
  1432. );
  1433. if (isset($aInput['label_as_html']))
  1434. $aNewInput['label_as_html'] = $aInput['label_as_html'];
  1435. $sNewInput = $this->genInput($aNewInput);
  1436. // attach new input to complex
  1437. $sOptions .= ($sNewInput . $sDivider);
  1438. }
  1439. }
  1440. // generate element
  1441. $sCode = <<<BLAH
  1442. <div $sAttrs>
  1443. $sOptions
  1444. </div>
  1445. BLAH;
  1446. return $sCode;
  1447. }
  1448. function genInputLocation(&$aInput)
  1449. {
  1450. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1451. if (!$o)
  1452. return _t('_sys_txt_error_occured');
  1453. return $o->genInputLocation($aInput, $this);
  1454. }
  1455. public function setLocationVals ($aInput, $aVals)
  1456. {
  1457. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1458. if (!$o)
  1459. return false;
  1460. return $o->setLocationVals ($aInput, $aVals, $this);
  1461. }
  1462. public function setLocationVal ($aInput, $sIndex, $sVal)
  1463. {
  1464. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1465. if (!$o)
  1466. return false;
  1467. return $o->setLocationVal ($aInput, $sIndex, $sVal, $this);
  1468. }
  1469. protected function getLocationVal ($aInput, $sIndex)
  1470. {
  1471. $o = BxDolLocationField::getObjectInstance(getParam('sys_location_field_default'));
  1472. if (!$o)
  1473. return false;
  1474. return $o->getLocationVal ($aInput, $sIndex, $this);
  1475. }
  1476. function genInputPassword(&$aInput)
  1477. {
  1478. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1479. }
  1480. function genInputNestedForm(&$aInput)
  1481. {
  1482. return '';
  1483. }
  1484. function genNestedForm(&$aInput)
  1485. {
  1486. return '';
  1487. }
  1488. function genInputCaptcha(&$aInput)
  1489. {
  1490. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1491. // for inputs with labels generate id
  1492. if (isset($aInput['label']))
  1493. $aAttrs['id'] = $this->getInputId($aInput);
  1494. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1495. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1496. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1497. }
  1498. /**
  1499. * Generate Label Element
  1500. *
  1501. * @param string $aInput input array
  1502. * @return string HTML code
  1503. */
  1504. function genLabel(&$aInput)
  1505. {
  1506. if (!isset($aInput['label']) || empty($aInput['label']))
  1507. return '';
  1508. $sInputID = $this->getInputId($aInput);
  1509. $sLabel = bx_process_output($aInput['label']);
  1510. if (isset($aInput['label_as_html']) && $aInput['label_as_html'] == true)
  1511. $sLabel = $aInput['label'];
  1512. return '<label for="' . $sInputID . '">' . $sLabel . '</label>';
  1513. }
  1514. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1515. {
  1516. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1517. return '';
  1518. $iAuthorId = bx_get_logged_profile_id();
  1519. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1520. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1521. return '';
  1522. if(empty($sPrivacyObject))
  1523. $sPrivacyObject = $this->_sPrivacyObjectView;
  1524. $iInputId = (int)$aInput['id'];
  1525. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1526. if(!isset($aInput['attrs_wrapper']['class']))
  1527. $aInput['attrs_wrapper']['class'] = '';
  1528. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1529. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1530. 'js_object' => $this->getJsObjectName(),
  1531. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1532. 'id' => $iInputId,
  1533. 'privacy_object' => $sPrivacyObject,
  1534. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1535. ));
  1536. }
  1537. function genInfoIcon($sInfo)
  1538. {
  1539. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1540. }
  1541. function genErrorIcon( $sError = '' )
  1542. {
  1543. if ($this->bEnableErrorIcon) {
  1544. $sStyle = '';
  1545. if (!$sError)
  1546. $sStyle = 'style="display:none;"';
  1547. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1548. }
  1549. }
  1550. function getOpenSection($aAttrs = array(), $sLegend = '')
  1551. {
  1552. if (!$this->_isSectionOpened) {
  1553. if (!$aAttrs || !is_array($aAttrs))
  1554. $aAttrs = array();
  1555. if ($sLegend)
  1556. $sClassesAdd = "bx-form-section-header";
  1557. else
  1558. $sClassesAdd = "bx-form-section-divider";
  1559. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1560. $this->_isSectionOpened = true;
  1561. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top bx-def-padding-bottom" . ($sLegend ? ' bx-def-padding-left bx-def-padding-right' : '') . "\">\n";
  1562. } else {
  1563. return '';
  1564. }
  1565. }
  1566. function getCloseSection()
  1567. {
  1568. if ($this->_isSectionOpened) {
  1569. $this->_isSectionOpened = false;
  1570. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1571. } else {
  1572. return '';
  1573. }
  1574. }
  1575. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1576. {
  1577. if (!$this->_isSectionOpened) {
  1578. if (!$aAttrs || !is_array($aAttrs))
  1579. $aAttrs = array();
  1580. if ($sLegend)
  1581. $sClassesAdd = "bx-form-section-header";
  1582. else
  1583. $sClassesAdd = "bx-form-section-divider";
  1584. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1585. $this->_isSectionOpened = true;
  1586. return "<!-- form header content begins -->\n <div class=\"bx-form-section-wrapper bx-def-margin-top\"> <div $sAttrs> $sLegend <div class=\"bx-form-section-content bx-def-padding-top\">\n";
  1587. } else {
  1588. return '';
  1589. }
  1590. }
  1591. function getCloseSectionViewMode()
  1592. {
  1593. if ($this->_isSectionOpened) {
  1594. $this->_isSectionOpened = false;
  1595. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1596. } else {
  1597. return '';
  1598. }
  1599. }
  1600. static function getJsUiLangs ()
  1601. {
  1602. return array ('af' => 1, 'ar-DZ' => 1, 'ar' => 1, 'az' => 1, 'be' => 1, 'bg' => 1, 'bs' => 1, 'ca' => 1, 'cs' => 1, 'cy-GB' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'en-AU' => 1, 'en-GB' => 1, 'en-NZ' => 1, 'en' => 1, 'eo' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fo' => 1, 'fr-CA' => 1, 'fr-CH' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hi' => 1, 'hr' => 1, 'hu' => 1, 'hy' => 1, 'id' => 1, 'is' => 1, 'it' => 1, 'ja' => 1, 'ka' => 1, 'kk' => 1, 'km' => 1, 'ko' => 1, 'ky' => 1, 'lb' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'ml' => 1, 'ms' => 1, 'nb' => 1, 'nl-BE' => 1, 'nl' => 1, 'nn' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'rm' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sq' => 1, 'sr-SR' => 1, 'sr' => 1, 'sv' => 1, 'ta' => 1, 'th' => 1, 'tj' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-HK' => 1, 'zh-TW' => 1);
  1603. }
  1604. function addCssJsUi ()
  1605. {
  1606. if (self::$_isCssJsUiAdded)
  1607. return;
  1608. $aUiLangs = $this->getJsUiLangs ();
  1609. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1610. $this->_addJs(array(
  1611. 'jquery-ui/jquery-ui.custom.min.js',
  1612. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.min.js',
  1613. ), "'undefined' === typeof($.datepicker)");
  1614. $this->_addCss('jquery-ui/jquery-ui.css');
  1615. self::$_isCssJsUiAdded = true;
  1616. }
  1617. function addCssJsTimepicker ()
  1618. {
  1619. if (self::$_isCssJsTimepickerAdded)
  1620. return;
  1621. $aCalendarLangs = array ('af' => 1, 'am' => 1, 'bg' => 1, 'ca' => 1, 'cs' => 1, 'da' => 1, 'de' => 1, 'el' => 1, 'es' => 1, 'et' => 1, 'eu' => 1, 'fa' => 1, 'fi' => 1, 'fr' => 1, 'gl' => 1, 'he' => 1, 'hr' => 1, 'hu' => 1, 'id' => 1, 'it' => 1, 'ja' => 1, 'ko' => 1, 'lt' => 1, 'lv' => 1, 'mk' => 1, 'nl' => 1, 'no' => 1, 'pl' => 1, 'pt-BR' => 1, 'pt' => 1, 'ro' => 1, 'ru' => 1, 'sk' => 1, 'sl' => 1, 'sr-RS' => 1, 'sr-YU' => 1, 'sv' => 1, 'th' => 1, 'tr' => 1, 'uk' => 1, 'vi' => 1, 'zh-CN' => 1, 'zh-TW' => 1);
  1622. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1623. $this->_addCss('timepicker-addon/jquery-ui-timepicker-addon.css');
  1624. $this->_addJs(array(
  1625. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1626. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1627. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1628. 'jquery.ui.touch-punch.min.js',
  1629. ), "'undefined' === typeof($.fn.datetimepicker)");
  1630. self::$_isCssJsTimepickerAdded = true;
  1631. }
  1632. function addCssJsMinicolors ()
  1633. {
  1634. if (self::$_isCssJsMinicolorsAdded)
  1635. return;
  1636. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1637. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1638. self::$_isCssJsMinicolorsAdded = true;
  1639. }
  1640. function addCssJsViewMode ()
  1641. {
  1642. if (self::$_isCssJsAddedViewMode)
  1643. return;
  1644. $this->_addCss('forms.css');
  1645. self::$_isCssJsAddedViewMode = true;
  1646. }
  1647. function addCssJsCore ()
  1648. {
  1649. if (self::$_isCssJsAdded)
  1650. return;
  1651. $this->_addCss('forms.css');
  1652. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1653. $this->_addJs(array('BxDolForm.js', 'BxDolNestedForm.js'), "true");
  1654. self::$_isCssJsAdded = true;
  1655. }
  1656. function addCssJs ()
  1657. {
  1658. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1659. $this->addCssJsViewMode ();
  1660. } else {
  1661. $this->addCssJsCore();
  1662. }
  1663. }
  1664. protected function _processCssJs()
  1665. {
  1666. $sRet = '';
  1667. if ($this->_bDynamicMode) {
  1668. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1669. $sRet .= "\n<script>\n";
  1670. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1671. foreach ($this->_aJs as $sCondition => $aJs) {
  1672. $sJs = $this->oTemplate->addJs($aJs, true);
  1673. if (!$sJs)
  1674. continue;
  1675. $sRet .= "if ($sCondition)\n";
  1676. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1677. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1678. }
  1679. $sRet .= "\n</script>\n";
  1680. }
  1681. else {
  1682. $this->oTemplate->addCss($this->_aCss);
  1683. $aJs = array();
  1684. foreach ($this->_aJs as $sCondition => $a)
  1685. $aJs = array_merge($aJs, $a);
  1686. $this->oTemplate->addJs($aJs);
  1687. }
  1688. return $sRet;
  1689. }
  1690. protected function _addJs($mixed, $sJsCondition)
  1691. {
  1692. if (!is_array($mixed))
  1693. $mixed = array($mixed);
  1694. $this->_aJs[$sJsCondition] = $mixed;
  1695. }
  1696. protected function _addCss($mixed)
  1697. {
  1698. if (!is_array($mixed))
  1699. $mixed = array($mixed);
  1700. foreach ($mixed as $s)
  1701. $this->_aCss[$s] = $s;
  1702. }
  1703. }
  1704. /** @} */