BxBaseFormView.php 73 KB

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