BxBaseFormView.php 71 KB

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