BxBaseFormView.php 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  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)) {
  469. $mixedResult = checkActionModule($this->_iAuthorId, 'set form fields privacy', 'system');
  470. if($mixedResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) {
  471. $aInputPrivacy = BxDolFormQuery::getInputPrivacy($mixedInput['id'], $this->_iAuthorId);
  472. if(!empty($aInputPrivacy) && is_array($aInputPrivacy)) {
  473. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_sPrivacyObjectView);
  474. if($oPrivacy && !$oPrivacy->check($aInputPrivacy['id']))
  475. return false;
  476. }
  477. }
  478. }
  479. return true;
  480. }
  481. /**
  482. * Generate single Table Row for view mode
  483. *
  484. * @param array $aInput
  485. * @return string
  486. */
  487. function genViewRow(&$aInput)
  488. {
  489. if (!isset($aInput['type']))
  490. $aInput['type'] = false;
  491. if(!$this->isInputVisible($aInput))
  492. return '';
  493. if (!empty($aInput['name'])) {
  494. $sCustomMethod = 'genCustomRow' . $this->_genMethodName($aInput['name']);
  495. if (method_exists($this, $sCustomMethod))
  496. return $this->$sCustomMethod($aInput);
  497. }
  498. switch ($aInput['type']) {
  499. case 'block_header':
  500. $sRow = $this->genRowBlockHeader($aInput);
  501. break;
  502. case 'block_end':
  503. $sRow = $this->genBlockEnd($aInput);
  504. break;
  505. default:
  506. $sRow = $this->genViewRowWrapped($aInput);
  507. }
  508. return $sRow;
  509. }
  510. /**
  511. * Generate complete wrapped row for view mode form
  512. *
  513. * @param array $aInput
  514. * @return string
  515. */
  516. function genViewRowWrapped(&$aInput)
  517. {
  518. $sValue = $this->genViewRowValue($aInput);
  519. if (null === $sValue)
  520. return '';
  521. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  522. return <<<EOS
  523. <div class="bx-form-row-view-wrapper bx-form-row-view-wrapper-{$aInput['type']} bx-def-padding-sec-top">
  524. <div class="bx-form-row-view-caption">{$sCaption}:</div>
  525. <div class="bx-form-row-view-value">{$sValue}</div>
  526. </div>
  527. EOS;
  528. }
  529. /**
  530. * Generate value for view mode row
  531. *
  532. * @param array $aInput
  533. * @return string
  534. */
  535. function genViewRowValue(&$aInput)
  536. {
  537. if (!empty($aInput['name'])) {
  538. $sCustomMethod = 'genCustomViewRowValue' . $this->_genMethodName($aInput['name']);
  539. if (method_exists($this, $sCustomMethod))
  540. return $this->$sCustomMethod($aInput);
  541. }
  542. switch ($aInput['type']) {
  543. case 'hidden':
  544. $sValue = null;
  545. break;
  546. case 'select':
  547. case 'radio_set':
  548. $sValue = $this->genViewRowValueForSelect($aInput);
  549. break;
  550. case 'datepicker':
  551. $sValue = null;
  552. if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
  553. break;
  554. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE, true);
  555. break;
  556. case 'date_time':
  557. case 'datetime':
  558. $sValue = null;
  559. if(empty($aInput['value']) || !$aInput['value'] || '0000-00-00 00:00:00' == $aInput['value'] || '0000-00-00 00:00' == $aInput['value'])
  560. break;
  561. $sValue = BxTemplFunctions::getInstance()->{is_numeric($aInput['value']) ? 'timeForJs' : 'timeForJsFullDate'}($aInput['value'], isset($aInput['date_format']) ? $aInput['date_format'] : BX_FORMAT_DATE_TIME, true);
  562. break;
  563. case 'checkbox_set':
  564. case 'select_multiple':
  565. $sValue = null;
  566. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  567. $sValue = '';
  568. foreach ($aInput['value'] as $sVal)
  569. $sValue .= $aInput['values'][$sVal] . ', ';
  570. $sValue = trim ($sValue, ', ');
  571. }
  572. break;
  573. case 'checkbox':
  574. case 'switcher':
  575. $sValue = isset($aInput['checked']) && $aInput['checked'] ? _t('_sys_form_checkbox_value_on') : _t('_sys_form_checkbox_value_off');
  576. break;
  577. case 'textarea':
  578. if (isset($aInput['value']) && '' !== $aInput['value'])
  579. $sValue = (isset($aInput['html']) && $aInput['html']) || (isset($aInput['code']) && $aInput['code']) ? $aInput['value'] : bx_process_output($aInput['value'], BX_DATA_TEXT_MULTILINE);
  580. else
  581. $sValue = null;
  582. break;
  583. case 'text':
  584. if(isset($aInput['value']) && '' !== $aInput['value'])
  585. $sValue = bx_linkify(bx_process_output($aInput['value']));
  586. else
  587. $sValue = null;
  588. break;
  589. default:
  590. $sValue = isset($aInput['value']) && '' !== $aInput['value'] ? bx_process_output($aInput['value']) : null;
  591. }
  592. return $sValue;
  593. }
  594. function genViewRowValueForSelect(&$aInput)
  595. {
  596. if (!isset($aInput['value']) || !$aInput['value'])
  597. return null;
  598. $s = isset($aInput['value']) && isset($aInput['values'][$aInput['value']]) ? $aInput['values'][$aInput['value']] : null;
  599. if (isset($aInput['values_list_name']) && ($oCategory = BxDolCategory::getObjectInstanceByFormAndList($this->aFormAttrs['name'], $aInput['values_list_name'])))
  600. return $oCategory->getCategoryLink($s, $aInput['value']);
  601. return $s;
  602. }
  603. protected function genCustomRowBirthday(&$aInput)
  604. {
  605. if(!$this->_bViewMode)
  606. return $this->genRowStandard($aInput);
  607. $aInput['caption_src'] = '_sys_form_input_age';
  608. $aInput['caption'] = _t($aInput['caption_src']);
  609. return $this->genViewRowWrapped($aInput);
  610. }
  611. protected function genCustomViewRowValueBirthday(&$aInput)
  612. {
  613. if(!isset($aInput['value']) || !$aInput['value'] || in_array($aInput['value'], array('0000-00-00', '0000-00-00 00:00:00')))
  614. return null;
  615. $sValue = $aInput['value'];
  616. $iPosSpace = strpos($sValue, ' ');
  617. if($iPosSpace !== false)
  618. $sValue = trim(substr($sValue, 0, $iPosSpace));
  619. $aDate = explode('-', $sValue);
  620. $iCdYear = (int)date('Y');
  621. $iCdMonth = (int)date('n');
  622. $iCdDay = (int)date('j');
  623. $iResult = $iCdYear - (int)$aDate[0];
  624. if($iCdMonth < (int)$aDate[1] || ($iCdMonth == (int)$aDate[1] && $iCdDay < (int)$aDate[2]))
  625. $iResult -= 1;
  626. return $iResult;
  627. }
  628. /**
  629. * Generate standard row
  630. *
  631. * @param array $aInput
  632. * @return string
  633. */
  634. function genRowStandard(&$aInput, $isOneLine = false)
  635. {
  636. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption'], BX_DATA_HTML) : '';
  637. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  638. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  639. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  640. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  641. $sClassWrapper = 'bx-form-element-wrapper';
  642. if($isOneLine)
  643. $sClassWrapper .= ' ' . $sClassWrapper . '-oneline';
  644. $sClassWrapper .= ' bx-def-margin-top';
  645. if (isset($aInput['name']))
  646. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  647. $sTrAttrs = bx_convert_array2attrs(isset($aInput['tr_attrs']) && is_array($aInput['tr_attrs']) ? $aInput['tr_attrs'] : array(), $sClassWrapper);
  648. $sClassOneLineCaption = '';
  649. $sClassOneLineValue = '';
  650. if ($isOneLine) {
  651. $sClassOneLineCaption = ' bx-form-caption-oneline bx-form-caption-oneline-' . $aInput['type'] . ' bx-def-margin-sec-left';
  652. $sClassOneLineValue = ' bx-form-value-oneline bx-form-value-oneline-' . $aInput['type'];
  653. $aInput['attrs']['id'] = $this->getInputId($aInput);
  654. if ($sCaption)
  655. $sCaption = '<label for="' . $aInput['attrs']['id'] . '">' . $sCaption . '</label>';
  656. }
  657. $sInput = $this->genInput($aInput);
  658. if(isset($aInput['error_updated']) && $aInput['error_updated'] === true)
  659. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  660. $sCaptionCode = $sCaption ? '<div class="bx-form-caption' . $sClassOneLineCaption . '">' . $sCaption . $sRequired . '</div>' : '';
  661. $sInputCode = $this->genWrapperInput($aInput, $sInput);
  662. if (empty($sInfoIcon)) $sInfoIcon = '';
  663. if (empty($sInputCode)) $sInputCode = '';
  664. if (empty($sErrorIcon)) $sErrorIcon = '';
  665. $sValueCode = '<div class="bx-form-value bx-clearfix' . $sClassAdd . $sClassOneLineValue . '">' . $sInputCode . '</div>';
  666. if ($isOneLine)
  667. $sCode = $sValueCode . $sCaptionCode;
  668. else
  669. $sCode = $sCaptionCode . $sValueCode;
  670. return '<div ' . $sTrAttrs . '><div class="bx-form-element">' . $sCode . '</div>' . $sInfoIcon . $sErrorIcon . '</div>';
  671. }
  672. function genWrapperInput($aInput, $sContent)
  673. {
  674. $sClass = "bx-form-input-wrapper bx-form-input-wrapper-" . $aInput['type'];
  675. if(isset($aInput['html']) && $aInput['html'] && $this->isHtmlEditor($aInput['html'], $aInput))
  676. $sClass .= ' bx-form-input-wrapper-html';
  677. $sAttrs = "";
  678. if(isset($aInput['attrs_wrapper']) && is_array($aInput['attrs_wrapper'])) {
  679. if(!empty($aInput['attrs_wrapper']['class'])) {
  680. $sClass .= ' ' . trim($aInput['attrs_wrapper']['class']);
  681. unset($aInput['attrs_wrapper']['class']);
  682. }
  683. $sAttrs = bx_convert_array2attrs($aInput['attrs_wrapper']);
  684. }
  685. return "<div class=\"$sClass\" $sAttrs>$sContent</div>";
  686. }
  687. /**
  688. * Generate custom row
  689. *
  690. * @param array $aInput
  691. * @param string $sCustomMethod custom method to generate code for input
  692. * @return string
  693. */
  694. function genRowCustom(&$aInput, $sCustomMethod)
  695. {
  696. $sCaption = isset($aInput['caption']) ? bx_process_output($aInput['caption']) : '';
  697. $sRequired = !empty($aInput['required']) ? '<span class="bx-form-required">*</span> ' : '';
  698. $sClassAdd = !empty($aInput['error']) ? ' bx-form-error' : '';
  699. $sInfoIcon = !empty($aInput['info']) ? $this->genInfoIcon($aInput['info']) : '';
  700. $sErrorIcon = $this->genErrorIcon(empty($aInput['error']) ? '' : $aInput['error']);
  701. $sInput = $this->$sCustomMethod($aInput, $sInfoIcon, $sErrorIcon);
  702. if (isset($aInput['name']))
  703. $aInput['tr_attrs']['id'] = "bx-form-element-" . $aInput['name'];
  704. $sTrAttrs = bx_convert_array2attrs(empty($aInput['tr_attrs']) ? array() : $aInput['tr_attrs'], "bx-form-element-wrapper bx-def-margin-top");
  705. $sCaptionCode = '';
  706. if ($sCaption)
  707. $sCaptionCode = '<div class="bx-form-caption">' . $sCaption . $sRequired . '</div>';
  708. $sCode = <<<BLAH
  709. <div $sTrAttrs>
  710. $sCaptionCode
  711. <div class="bx-form-value$sClassAdd">
  712. <div class="bx-clear"></div>
  713. $sInput
  714. <div class="bx-clear"></div>
  715. </div>
  716. </div>
  717. BLAH;
  718. return $sCode;
  719. }
  720. /**
  721. * Generate Block Headers row
  722. *
  723. * @param array $aInput
  724. * @return string
  725. */
  726. function genRowBlockHeader(&$aInput)
  727. {
  728. $aAttrs = empty($aInput['attrs']) ? '' : $aInput['attrs'];
  729. // if there is no caption - show divider only
  730. if (empty($aInput['caption'])) {
  731. $sCode = $this->{$this->_sSectionClose}();
  732. $sCode .= $this->{$this->_sSectionOpen}($aAttrs);
  733. return $sCode;
  734. }
  735. // if section is collapsed by default, add necessary code
  736. $sClassAddCollapsable = 'bx-form-collapsable';
  737. if (isset($aInput['collapsed']) and $aInput['collapsed'])
  738. $sClassAddCollapsable .= ' bx-form-collapsed bx-form-section-hidden';
  739. // display section with caption
  740. $sCode = $this->{$this->_sSectionClose}();
  741. if (empty($aAttrs))
  742. $aAttrs = array('class' => 'bx-form-collapsable ' . $sClassAddCollapsable);
  743. else
  744. $aAttrs['class'] .= ' bx-form-collapsable ' . $sClassAddCollapsable;
  745. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode'])
  746. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-h3">' . bx_process_output($aInput['caption']) . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  747. else
  748. $sLegend = '<legend class="bx-def-padding-left bx-def-padding-sec-right bx-def-font-grayed bx-def-font-h3"><a href="javascript:void(0);">' . bx_process_output($aInput['caption']) . '</a>' . (!empty($aInput['info']) ? '<br /><span>' . bx_process_output($aInput['info']) . '</span>' : '') . '</legend>';
  749. $sCode .= $this->{$this->_sSectionOpen}($aAttrs, $sLegend);
  750. return $sCode;
  751. }
  752. function genBlockEnd()
  753. {
  754. $aNextTbodyAdd = false; // need to have some default
  755. $sCode = '';
  756. $sCode .= $this->{$this->_sSectionClose}();
  757. $sCode .= $this->{$this->_sSectionOpen}($aNextTbodyAdd);
  758. return $sCode;
  759. }
  760. /**
  761. * Generate HTML Input Element
  762. *
  763. * @param array $aInput
  764. * @return string Output HTML Code
  765. */
  766. function genInput(&$aInput)
  767. {
  768. if (!empty($aInput['name'])) {
  769. $sCustomMethod = 'genCustomInput' . $this->_genMethodName($aInput['name']);
  770. if (method_exists($this, $sCustomMethod))
  771. return $this->$sCustomMethod($aInput);
  772. }
  773. switch ($aInput['type']) {
  774. // standard inputs (and non-standard, interpreted as standard)
  775. case 'text':
  776. case 'datepicker':
  777. case 'date_time':
  778. case 'datetime':
  779. case 'number':
  780. case 'time':
  781. case 'checkbox':
  782. case 'radio':
  783. case 'image':
  784. case 'slider':
  785. case 'doublerange':
  786. case 'hidden':
  787. $sInput = $this->genInputStandard($aInput);
  788. break;
  789. case 'password':
  790. $sInput = $this->genInputPassword($aInput);
  791. break;
  792. case 'file':
  793. $sInput = $this->genInputFile($aInput);
  794. break;
  795. case 'rgb':
  796. case 'rgba':
  797. $sClass = 'bx-form-input-' . $aInput['type'];
  798. $aInput['attrs']['class'] = !empty($aInput['attrs']['class']) ? $aInput['attrs']['class'] . ' ' . $sClass : $sClass;
  799. $aInput['type'] = 'text';
  800. $sInput = $this->genInputStandard($aInput);
  801. break;
  802. case 'switcher':
  803. $sInput = $this->genInputSwitcher($aInput);
  804. break;
  805. case 'button':
  806. case 'reset':
  807. case 'submit':
  808. $sInput = $this->genInputButton($aInput);
  809. break;
  810. case 'textarea':
  811. $sInput = $this->genInputTextarea($aInput);
  812. break;
  813. case 'select':
  814. $sInput = $this->genInputSelect($aInput);
  815. break;
  816. case 'select_multiple':
  817. $sInput = $this->genInputSelectMultiple($aInput);
  818. break;
  819. case 'checkbox_set':
  820. $sInput = $this->genInputCheckboxSet($aInput);
  821. break;
  822. case 'radio_set':
  823. $sInput = $this->genInputRadioSet($aInput);
  824. break;
  825. case 'input_set': // numeric array of inputs
  826. $sInput = '';
  827. $sDivider = isset($aInput['dv']) ? $aInput['dv'] : ' ';
  828. foreach ($aInput as $iKey => $aSubInput) {
  829. if (!is_int($iKey) or !$aSubInput)
  830. continue; // parse only integer keys and existing values
  831. $sInput .= $this->genInput($aSubInput); // recursive call
  832. $sInput .= $sDivider;
  833. }
  834. $sInput .= '<div class="bx-clear"></div>';
  835. break;
  836. case 'custom':
  837. $sInput = isset($aInput['content']) ? $aInput['content'] : '';
  838. break;
  839. case 'captcha':
  840. $sInput = $this->genInputCaptcha($aInput);
  841. break;
  842. case 'location':
  843. $sInput = $this->genInputLocation($aInput);
  844. break;
  845. case 'value':
  846. $sInput = isset($aInput['value']) ? $aInput['value'] : '';
  847. break;
  848. default:
  849. //unknown control type
  850. $sInput = 'Unknown control type';
  851. }
  852. // create input label
  853. $sInput .= $this->genLabel($aInput);
  854. // create input privacy group chooser
  855. $sInput .= $this->genPrivacyGroupChooser($aInput);
  856. return $sInput;
  857. }
  858. /**
  859. * Generate new Input Element id
  860. *
  861. * @param array $aInput
  862. * @return string
  863. */
  864. function getInputId(&$aInput)
  865. {
  866. if (isset($aInput['id']))
  867. return $aInput['id'];
  868. $sName = md5($aInput['name']);
  869. $sID = $this->id . '_input_' . $sName;
  870. if ( // multiple elements cause identical id's
  871. (
  872. (
  873. $aInput['type'] == 'checkbox' and
  874. substr($aInput['name'], -2) == '[]' // it is multiple element
  875. ) or
  876. $aInput['type'] == 'radio' // it is always multiple (i think so... hm)
  877. ) and
  878. isset($aInput['value']) // if we can make difference
  879. ) {
  880. $sValue = md5($aInput['value']);
  881. // add value
  882. $sID .= '_' . $sValue;
  883. }
  884. $sID = trim($sID, '_');
  885. $aInput['id'] = $sID; // just for repeated calls
  886. return $sID;
  887. }
  888. /**
  889. * Generate standard Input Element
  890. *
  891. * @param array $aInput
  892. * @return string
  893. */
  894. function genInputStandard(&$aInput)
  895. {
  896. // clone attributes for system use ;)
  897. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  898. // add default className to attributes
  899. $aAttrs['type'] = $aInput['type'];
  900. if ('datetime' == $aAttrs['type'])
  901. $aAttrs['type'] = 'date_time';
  902. switch($aAttrs['type']) {
  903. case 'date_time':
  904. $this->addCssJsUi ();
  905. $this->addCssJsTimepicker ();
  906. break;
  907. case 'slider':
  908. case 'doublerange':
  909. case 'datepicker':
  910. $this->addCssJsUi ();
  911. break;
  912. case 'text':
  913. if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
  914. $this->addCssJsMinicolors ();
  915. break;
  916. }
  917. if ('doublerange' == $aAttrs['type'] && (!isset($aInput['value']) || !$aInput['value']) && !empty($aAttrs['min']) && !empty($aAttrs['max'])) {
  918. $aInput['value'] = $aAttrs['min'] . '-' . $aAttrs['max'];
  919. }
  920. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  921. if (isset($aInput['value'])) $aAttrs['value'] = $aInput['value'];
  922. if (isset($aInput['db']['pass']) && ('DateUtc' == $aInput['db']['pass'] || 'DateTimeUtc' == $aInput['db']['pass'])) $aAttrs['data-utc'] = 1;
  923. // for inputs with labels generate id
  924. if (isset($aInput['label']))
  925. $aAttrs['id'] = $this->getInputId($aInput);
  926. // for checkboxes
  927. if (isset($aInput['checked']) and $aInput['checked'])
  928. $aAttrs['checked'] = 'checked';
  929. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']}");
  930. return "<input $sAttrs />\n";
  931. }
  932. /**
  933. * Generate Switcher Input Element (based on checkbox)
  934. *
  935. * @param array $aInput
  936. * @return string
  937. */
  938. function genInputSwitcher(&$aInput)
  939. {
  940. $aInput['type'] = 'checkbox';
  941. $sCheckbox = $this->genInputStandard($aInput);
  942. $aInput['type'] = 'switcher';
  943. $sClass = 'off';
  944. if (isset($aInput['checked']) and $aInput['checked'])
  945. $sClass = 'on';
  946. return '
  947. <div class="bx-switcher-cont ' . $sClass . '">' . $sCheckbox . '
  948. <div class="bx-switcher-canvas">
  949. <div class="bx-switcher-on"><i class="sys-icon check"></i></div>
  950. <div class="bx-switcher-off"><i class="sys-icon times"></i></div>
  951. <div class="bx-switcher-handler">&nbsp;</div>
  952. </div>
  953. </div>';
  954. }
  955. /**
  956. * Generate Button Input Element
  957. *
  958. * @param array $aInput
  959. * @return string
  960. */
  961. function genInputButton(&$aInput)
  962. {
  963. // clone attributes for system use ;)
  964. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  965. // add default className to attributes
  966. $aAttrs['type'] = $aInput['type'];
  967. if (isset($aInput['value']))
  968. $aAttrs['value'] = $aInput['value'];
  969. if (isset($aInput['name'])) $aAttrs['name'] = $aInput['name'];
  970. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-def-font-inputs bx-form-input-{$aInput['type']} bx-btn" . ('submit' == $aInput['type'] ? ' bx-btn-primary' : ''));
  971. return "<button $sAttrs>" . $aInput['value'] . "</button>\n";
  972. }
  973. /**
  974. * Generate Textarea Element
  975. *
  976. * @param array $aInput
  977. * @return string
  978. */
  979. function genInputTextarea(&$aInput)
  980. {
  981. // clone attributes for system use ;)
  982. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  983. $aAttrs['name'] = $aInput['name'];
  984. // for inputs with labels generate id
  985. if (isset($aInput['label']))
  986. $aAttrs['id'] = $this->getInputId($aInput);
  987. $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' : ''));
  988. $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')) : '';
  989. return "<textarea $sAttrs>$sValue</textarea>";
  990. }
  991. function isHtmlEditor($iViewMode, &$aInput)
  992. {
  993. return BxDolEditor::getObjectInstance(false, $this->oTemplate) !== false;
  994. }
  995. function addHtmlEditor($iViewMode, &$aInput)
  996. {
  997. $oEditor = BxDolEditor::getObjectInstance(false, $this->oTemplate);
  998. if (!$oEditor)
  999. return false;
  1000. $this->_sCodeAdd .= $oEditor->attachEditor ('#' . $this->aFormAttrs['id'] . ' [name='.$aInput['name'].']', $iViewMode, $this->_bDynamicMode);
  1001. return true;
  1002. }
  1003. /**
  1004. * Generate Select Box Element
  1005. *
  1006. * @param array $aInput
  1007. * @return string
  1008. */
  1009. function genInputSelectBox(&$aInput, $sInfo = '', $sError = '')
  1010. {
  1011. $aNewInput = $aInput;
  1012. $aNewInput['type'] = 'select';
  1013. $aNewInput['name'] .= '[]';
  1014. $sInput = $this->genInput($aNewInput);
  1015. return <<<BLAH
  1016. <div class="bx-form-input-wrapper input-wrapper-{$aInput['type']}">
  1017. $sInput
  1018. </div>
  1019. $sInfo
  1020. $sError
  1021. BLAH;
  1022. }
  1023. /**
  1024. * Generate Browse File Element
  1025. *
  1026. * @param array $aInput
  1027. * @return string
  1028. */
  1029. function genInputFile(&$aInput)
  1030. {
  1031. $sOnChange = "$(this).parents('.bx-form-input-wrapper-file:first').find('.bx-fif-value').html($(this).val());";
  1032. if(!empty($aInput['attrs']['onchange']))
  1033. $aInput['attrs']['onchange'] = $sOnChange . $aInput['attrs']['onchange'];
  1034. else
  1035. $aInput['attrs']['onchange'] = $sOnChange;
  1036. $sInput = $this->genInputStandard($aInput);
  1037. 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>';
  1038. }
  1039. /**
  1040. * Generate Select Box Element
  1041. *
  1042. * @param array $aInput
  1043. * @return string
  1044. */
  1045. function genInputFiles(&$aInput, $sInfo = '', $sError = '')
  1046. {
  1047. $sUniqId = genRndPwd (8, false);
  1048. $sUploaders = '';
  1049. $oUploader = null;
  1050. foreach ($aInput['uploaders'] as $sUploaderObject) {
  1051. $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId, $this->oTemplate);
  1052. if (!$oUploader)
  1053. continue;
  1054. $sGhostTemplate = $this->genGhostTemplate($aInput);
  1055. $aAttrs = !empty($aInput['attrs']) ? $aInput['attrs'] : array();
  1056. if (empty($aInput['attrs']['disabled']))
  1057. $aAttrs = array_merge($aAttrs, array('onclick' => $oUploader->getNameJsInstanceUploader() . '.showUploaderForm();'));
  1058. $aParams = array(
  1059. 'button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)),
  1060. 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '',
  1061. 'storage_private' => isset($aInput['storage_private']) ? $aInput['storage_private'] : '1',
  1062. 'attrs' => bx_convert_array2attrs($aAttrs),
  1063. 'btn_class' => !empty($aInput['attrs']['disabled']) ? 'bx-btn-disabled' : '',
  1064. );
  1065. if (isset($aInput['images_transcoder']) && $aInput['images_transcoder'])
  1066. $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
  1067. $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams, $this->_bDynamicMode);
  1068. }
  1069. return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array(
  1070. 'uploaders_buttons' => $sUploaders,
  1071. 'info' => $sInfo,
  1072. 'error' => $sError,
  1073. 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '',
  1074. 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '',
  1075. 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '',
  1076. 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1,
  1077. ));
  1078. }
  1079. protected function genGhostTemplate(&$aInput)
  1080. {
  1081. $sGhostTemplate = false;
  1082. if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) { // form is not submitted and ghost template is BxDolFormNested object
  1083. $oFormNested = $aInput['ghost_template'];
  1084. if ($oFormNested instanceof BxDolFormNested)
  1085. $sGhostTemplate = $oFormNested->genForm();
  1086. } 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
  1087. $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
  1088. $sGhostTemplate = $oFormNested->getCode();
  1089. } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) { // form is submitted and ghost template is array of BxDolFormNested objects
  1090. $sGhostTemplate = array ();
  1091. foreach ($aInput['ghost_template'] as $iFileId => $oFormNested)
  1092. if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNested)
  1093. $sGhostTemplate[$iFileId] = $oFormNested->genForm();
  1094. } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) { // ghost template is just string template, without nested form
  1095. $sGhostTemplate = $aInput['ghost_template'];
  1096. }
  1097. return $sGhostTemplate;
  1098. }
  1099. protected function genCustomInputUsernamesSuggestions ($aInput)
  1100. {
  1101. $this->addCssJsUi();
  1102. $sVals = '';
  1103. if(!empty($aInput['value'])) {
  1104. if(is_array($aInput['value'])) {
  1105. foreach($aInput['value'] as $sVal) {
  1106. if(!$sVal || !($oProfile = BxDolProfile::getInstance($sVal)))
  1107. continue;
  1108. $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>';
  1109. }
  1110. $sVals = trim($sVals, ',');
  1111. }
  1112. else if(is_string($aInput['value']))
  1113. $sVals = $aInput['value'];
  1114. }
  1115. $bDisabled = isset($aInput['attrs']['disabled']) && $aInput['attrs']['disabled'] == 'disabled';
  1116. $sId = $aInput['name'] . time() . mt_rand(0, 100);
  1117. $sClass = 'bx-form-input-autotoken bx-def-font-inputs bx-form-input-text';
  1118. if($bDisabled)
  1119. $sClass .= ' bx-form-input-disabled';
  1120. if(!empty($aInput['attrs']['class'])) {
  1121. $sClass .= ' ' . $aInput['attrs']['class'];
  1122. unset($aInput['attrs']['class']);
  1123. }
  1124. $aAttrs = array('value' => '', 'autocomplete' => 'off', 'autocapitalize' => 'off', 'autocorrect' => 'off');
  1125. if(isset($aInput['attrs']) && is_array($aInput['attrs']))
  1126. $aAttrs = array_merge($aAttrs, $aInput['attrs']);
  1127. return $this->oTemplate->parseHtmlByName('form_field_custom_suggestions.html', array(
  1128. 'id' => $sId,
  1129. 'name' => $aInput['name'],
  1130. 'class' => $sClass,
  1131. 'vals' => $sVals,
  1132. 'bx_if:input' => array(
  1133. 'condition' => !$bDisabled,
  1134. 'content' => array(
  1135. 'attrs' => bx_convert_array2attrs($aAttrs),
  1136. )
  1137. ),
  1138. 'bx_if:init' => array(
  1139. 'condition' => !$bDisabled,
  1140. 'content' => array(
  1141. 'id' => $sId,
  1142. 'name' => $aInput['name'],
  1143. 'url_get_recipients' => $aInput['ajax_get_suggestions'],
  1144. 'b_img' => isset($aInput['custom']['b_img']) ? (int)$aInput['custom']['b_img'] : 1,
  1145. 'only_once' => isset($aInput['custom']['only_once']) ? 1 : 0,
  1146. 'on_select' => isset($aInput['custom']['on_select']) ? $aInput['custom']['on_select']: 'null',
  1147. 'placeholder' => bx_html_attribute(isset($aInput['placeholder']) ? $aInput['placeholder'] : _t('_sys_form_paceholder_profiles_suggestions'), BX_ESCAPE_STR_QUOTE),
  1148. )
  1149. )
  1150. ));
  1151. }
  1152. protected function genCustomViewRowValueLabels ($aInput)
  1153. {
  1154. if (empty($aInput['value']) || !($oMetatags = BxDolMetatags::getObjectInstance($aInput['meta_object'])) || !$oMetatags->keywordsIsEnabled())
  1155. return null;
  1156. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1157. $aInput['value'] = unserialize($aInput['value']);
  1158. $s = '';
  1159. foreach ($aInput['value'] as $sLabel)
  1160. $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>';
  1161. return $this->oTemplate->parseHtmlByName('form_field_labels_view.html', array(
  1162. 'values' => $s,
  1163. ));
  1164. }
  1165. protected function genCustomInputLabels ($aInput)
  1166. {
  1167. $this->addCssJsLabels ();
  1168. $aValues = array();
  1169. $oLabel = BxDolLabel::getInstance();
  1170. $this->_getLabelOptions(0, $oLabel, $aValues, 1, '');
  1171. $aInput['type'] = 'select_multiple bx-form-select-labels';
  1172. $aInput['values'] = $aValues;
  1173. if (!empty($aInput['value']) && !is_array($aInput['value']))
  1174. $aInput['value'] = unserialize($aInput['value']);
  1175. return $this->genInputSelectMultiple($aInput);
  1176. }
  1177. protected function _getLabelOptions($iParent, &$oLabel, &$aValues, $iLevel = 1, $sParentValue = '')
  1178. {
  1179. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  1180. foreach($aLabels as $aLabel) {
  1181. $aAttrs = array();
  1182. if ($aLabel['parent'] != 0)
  1183. $aAttrs = array('data-pup' => $sParentValue);
  1184. $sClass = 'l' . $iLevel;
  1185. $aLabels2 = $oLabel->getLabels(array('type' => 'parent', 'parent' => $aLabel['id']));
  1186. if (count($aLabels2) > 0)
  1187. $sClass .= ' non-leaf';
  1188. $aValues[] = array('attrs' => $aAttrs, 'class' => $sClass, 'key' => $aLabel['value'], 'value' => $aLabel['value']);
  1189. $iLevel2 = $iLevel + 1;
  1190. $this->_getLabelOptions($aLabel['id'], $oLabel, $aValues, $iLevel2, $aLabel['value']);
  1191. }
  1192. }
  1193. /*
  1194. protected function genCustomInputLabels ($aInput)
  1195. {
  1196. // generate currently selected labels
  1197. $sValue = '';
  1198. if (!empty($aInput['value']) && is_array($aInput['value'])) {
  1199. sort($aInput['value'], SORT_LOCALE_STRING);
  1200. foreach ($aInput['value'] as $sVal) {
  1201. $sValue .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '<input type="hidden" name="' . $aInput['name'] . '[]" value="' . trim($sVal) . '" /></b>';
  1202. }
  1203. $sValue = trim($sValue, ',');
  1204. }
  1205. // generate "following" labels
  1206. $aFollowingLabels = bx_srv('bx_channels', 'get_following_channels_names', array(bx_get_logged_profile_id()));
  1207. if (!is_array($aFollowingLabels))
  1208. $aFollowingLabels = array();
  1209. $aFollowingLabels = array_intersect($aFollowingLabels, $aInput['values']);
  1210. $aFollowingLabels = array_diff($aFollowingLabels, !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array());
  1211. $aValues = array_diff($aInput['values'],
  1212. !empty($aInput['value']) && is_array($aInput['value']) ? $aInput['value'] : array(),
  1213. !empty($aFollowingLabels) && is_array($aFollowingLabels) ? $aFollowingLabels : array());
  1214. $sValues = '';
  1215. if (!empty($aFollowingLabels)) {
  1216. sort($aFollowingLabels, SORT_LOCALE_STRING);
  1217. foreach ($aFollowingLabels as $sVal) {
  1218. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1219. }
  1220. if (!empty($aValues))
  1221. $sValues .= '<a href="#" class="bx-form-input-autotoken-labels-show-more">' . _t('_sys_show_more') . '</a><i class="bx-form-input-autotoken-labels-more">';
  1222. }
  1223. // generate all possible labels
  1224. if (!empty($aValues)) {
  1225. sort($aValues, SORT_LOCALE_STRING);
  1226. foreach ($aValues as $sVal) {
  1227. $sValues .= '<b class="val bx-def-color-bg-hl bx-def-round-corners">' . trim($sVal) . '</b>';
  1228. }
  1229. $sValues = trim($sValues, ',');
  1230. }
  1231. if (!empty($aFollowingLabels) && !empty($aValues))
  1232. $sValues .= '</i>';
  1233. return $this->oTemplate->parseHtmlByName('form_field_labels.html', array(
  1234. 'id' => $aInput['name'] . time() . mt_rand(0, 100),
  1235. 'name' => $aInput['name'],
  1236. 'value' => $sValue,
  1237. 'values' => $sValues,
  1238. ));
  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. $sNewInput = $this->genInput($aNewInput);
  1390. // attach new input to complex
  1391. $sOptions .= ($sNewInput . $sDivider);
  1392. }
  1393. }
  1394. // generate element
  1395. $sCode = <<<BLAH
  1396. <div $sAttrs>
  1397. $sOptions
  1398. </div>
  1399. BLAH;
  1400. return $sCode;
  1401. }
  1402. function genInputLocation(&$aInput)
  1403. {
  1404. $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
  1405. $sIdStatus = $this->getInputId($aInput) . '_status';
  1406. $sIdInput = $this->getInputId($aInput) . '_location';
  1407. $sProto = (0 === strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  1408. $aVars = array (
  1409. 'key' => trim(getParam('sys_maps_api_key')),
  1410. 'lang' => bx_lang_name(),
  1411. 'name' => $aInput['name'],
  1412. 'id_status' => $sIdStatus,
  1413. 'id_input' => $sIdInput,
  1414. 'manual_input' => $isManualInput,
  1415. 'bx_if:manual_input' => array(
  1416. 'condition' => $isManualInput,
  1417. 'content' => array(),
  1418. ),
  1419. 'bx_if:auto_input' => array(
  1420. 'condition' => !$isManualInput,
  1421. 'content' => array(
  1422. 'id_status' => $sIdStatus,
  1423. 'location_string' => _t('_sys_location_undefined'),
  1424. ),
  1425. ),
  1426. );
  1427. $aLocationIndexes = self::$LOCATION_INDEXES;
  1428. foreach ($aLocationIndexes as $sKey)
  1429. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey);
  1430. if ($aVars['country']) {
  1431. $aCountries = BxDolFormQuery::getDataItems('Country');
  1432. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  1433. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  1434. }
  1435. if ($isManualInput) {
  1436. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1437. $aInput['type'] = 'text';
  1438. $aInput['attrs']['id'] = $sIdInput;
  1439. $aInput['attrs'] = array_merge($aAttrs, $aInput['attrs']);
  1440. $aVars['input'] = $this->genInputStandard($aInput);
  1441. }
  1442. else {
  1443. if ($this->getLocationVal($aInput, 'lat') && $this->getLocationVal($aInput, 'lng'))
  1444. $aInput['checked'] = true;
  1445. else
  1446. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  1447. $aVars['input'] = $this->genInputSwitcher($aInput);
  1448. }
  1449. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  1450. }
  1451. public function setLocationVals ($aInput, $aVals)
  1452. {
  1453. $this->_aSpecificValues[$aInput['name'] . '_lat'] = $aVals['lat'];
  1454. $this->_aSpecificValues[$aInput['name'] . '_lng'] = $aVals['lng'];
  1455. $this->_aSpecificValues[$aInput['name'] . '_country'] = $aVals['country'];
  1456. $this->_aSpecificValues[$aInput['name'] . '_state'] = $aVals['state'];
  1457. $this->_aSpecificValues[$aInput['name'] . '_city'] = $aVals['city'];
  1458. $this->_aSpecificValues[$aInput['name'] . '_zip'] = $aVals['zip'];
  1459. $this->_aSpecificValues[$aInput['name'] . '_street'] = $aVals['street'];
  1460. $this->_aSpecificValues[$aInput['name'] . '_street_number'] = $aVals['street_number'];
  1461. }
  1462. function genInputPassword(&$aInput)
  1463. {
  1464. return $this->oTemplate->parseHtmlByName('form_field_password.html', array('input' => $this->genInputStandard($aInput)));
  1465. }
  1466. public function setLocationVal ($aInput, $sIndex, $sVal)
  1467. {
  1468. $s = $aInput['name'] . '_' . $sIndex;
  1469. $this->_aSpecificValues[$s] = $sVal;
  1470. }
  1471. protected function getLocationVal ($aInput, $sIndex)
  1472. {
  1473. $s = $aInput['name'] . '_' . $sIndex;
  1474. if (isset($this->_aSpecificValues[$s]))
  1475. return $this->_aSpecificValues[$s];
  1476. return $this->getCleanValue($s);
  1477. }
  1478. function genInputCaptcha(&$aInput)
  1479. {
  1480. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  1481. // for inputs with labels generate id
  1482. if (isset($aInput['label']))
  1483. $aAttrs['id'] = $this->getInputId($aInput);
  1484. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-input-{$aInput['type']}");
  1485. $oCaptcha = BxDolCaptcha::getObjectInstance();
  1486. return "<div $sAttrs>" . ($oCaptcha ? $oCaptcha->display($this->_bDynamicMode) : _t('_sys_txt_captcha_not_available')) . "</div>";
  1487. }
  1488. /**
  1489. * Generate Label Element
  1490. *
  1491. * @param string $aInput input array
  1492. * @return string HTML code
  1493. */
  1494. function genLabel(&$aInput)
  1495. {
  1496. if (!isset($aInput['label']) || empty($aInput['label']))
  1497. return '';
  1498. $sInputID = $this->getInputId($aInput);
  1499. return '<label for="' . $sInputID . '">' . bx_process_output($aInput['label']) . '</label>';
  1500. }
  1501. function genPrivacyGroupChooser(&$aInput, $sPrivacyObject = '')
  1502. {
  1503. if(!isset($aInput['privacy']) || empty($aInput['privacy']))
  1504. return '';
  1505. $iAuthorId = bx_get_logged_profile_id();
  1506. $mixedResult = checkActionModule($iAuthorId, 'set form fields privacy', 'system');
  1507. if($mixedResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1508. return '';
  1509. if(empty($sPrivacyObject))
  1510. $sPrivacyObject = $this->_sPrivacyObjectView;
  1511. $iInputId = (int)$aInput['id'];
  1512. $mixedPrivacyGroup = $this->_getPrivacyGroup($sPrivacyObject, $iInputId, $iAuthorId);
  1513. if(!isset($aInput['attrs_wrapper']['class']))
  1514. $aInput['attrs_wrapper']['class'] = '';
  1515. $aInput['attrs_wrapper']['class'] .= ' bx-form-input-wrapper-pgc';
  1516. return $this->oTemplate->parseHtmlByName('form_field_privacy.html', array(
  1517. 'js_object' => $this->getJsObjectName(),
  1518. 'html_id' => $this->_aHtmlIds['pgc'] . $iInputId,
  1519. 'html_id_popup' => $this->_aHtmlIds['pgc_popup'] . $iInputId,
  1520. 'id' => $iInputId,
  1521. 'privacy_object' => $sPrivacyObject,
  1522. 'icon' => $this->_getPrivacyIcon($mixedPrivacyGroup)
  1523. ));
  1524. }
  1525. function genInfoIcon($sInfo)
  1526. {
  1527. return '<div class="bx-form-info bx-def-font-grayed bx-def-font-small">' . bx_process_output($sInfo, BX_DATA_HTML) . '</div>';
  1528. }
  1529. function genErrorIcon( $sError = '' )
  1530. {
  1531. if ($this->bEnableErrorIcon) {
  1532. $sStyle = '';
  1533. if (!$sError)
  1534. $sStyle = 'style="display:none;"';
  1535. return '<div class="bx-form-warn" ' . $sStyle . '>' . $sError . '</div>';
  1536. }
  1537. }
  1538. function getOpenSection($aAttrs = array(), $sLegend = '')
  1539. {
  1540. if (!$this->_isSectionOpened) {
  1541. if (!$aAttrs || !is_array($aAttrs))
  1542. $aAttrs = array();
  1543. if ($sLegend)
  1544. $sClassesAdd = "bx-form-section-header";
  1545. else
  1546. $sClassesAdd = "bx-form-section-divider";
  1547. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1548. $this->_isSectionOpened = true;
  1549. 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";
  1550. } else {
  1551. return '';
  1552. }
  1553. }
  1554. function getCloseSection()
  1555. {
  1556. if ($this->_isSectionOpened) {
  1557. $this->_isSectionOpened = false;
  1558. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1559. } else {
  1560. return '';
  1561. }
  1562. }
  1563. function getOpenSectionViewMode($aAttrs = array(), $sLegend = '')
  1564. {
  1565. if (!$this->_isSectionOpened) {
  1566. if (!$aAttrs || !is_array($aAttrs))
  1567. $aAttrs = array();
  1568. if ($sLegend)
  1569. $sClassesAdd = "bx-form-section-header";
  1570. else
  1571. $sClassesAdd = "bx-form-section-divider";
  1572. $sAttrs = bx_convert_array2attrs($aAttrs, "bx-form-section bx-form-view-section bx-def-padding-sec-top bx-def-border-top " . $sClassesAdd);
  1573. $this->_isSectionOpened = true;
  1574. 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";
  1575. } else {
  1576. return '';
  1577. }
  1578. }
  1579. function getCloseSectionViewMode()
  1580. {
  1581. if ($this->_isSectionOpened) {
  1582. $this->_isSectionOpened = false;
  1583. return "</div> </div> </div> \n<!-- form header content ends -->\n";
  1584. } else {
  1585. return '';
  1586. }
  1587. }
  1588. static function getJsUiLangs ()
  1589. {
  1590. 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);
  1591. }
  1592. function addCssJsUi ()
  1593. {
  1594. if (self::$_isCssJsUiAdded)
  1595. return;
  1596. $aUiLangs = $this->getJsUiLangs ();
  1597. $sUiLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aUiLangs);
  1598. $this->_addJs(array(
  1599. 'jquery-ui/jquery-ui.custom.min.js',
  1600. 'jquery-ui/i18n/jquery.ui.datepicker-' . $sUiLang . '.min.js',
  1601. ), "'undefined' === typeof($.datepicker)");
  1602. $this->_addCss('jquery-ui/jquery-ui.css');
  1603. self::$_isCssJsUiAdded = true;
  1604. }
  1605. function addCssJsTimepicker ()
  1606. {
  1607. if (self::$_isCssJsTimepickerAdded)
  1608. return;
  1609. $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);
  1610. $sCalendarLang = BxDolLanguages::getInstance()->detectLanguageFromArray ($aCalendarLangs);
  1611. $this->_addCss('timepicker-addon/jquery-ui-timepicker-addon.css');
  1612. $this->_addJs(array(
  1613. 'timepicker-addon/jquery-ui-timepicker-addon.min.js',
  1614. 'timepicker-addon/jquery-ui-sliderAccess.js',
  1615. 'timepicker-addon/i18n/jquery-ui-timepicker-' . $sCalendarLang . '.js',
  1616. 'jquery.ui.touch-punch.min.js',
  1617. ), "'undefined' === typeof($.fn.datetimepicker)");
  1618. self::$_isCssJsTimepickerAdded = true;
  1619. }
  1620. function addCssJsMinicolors ()
  1621. {
  1622. if (self::$_isCssJsMinicolorsAdded)
  1623. return;
  1624. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'jquery-minicolors/|jquery.minicolors.css');
  1625. $this->_addJs('jquery-minicolors/jquery.minicolors.min.js', "'undefined' === typeof($.minicolors)");
  1626. self::$_isCssJsMinicolorsAdded = true;
  1627. }
  1628. function addCssJsLabels ()
  1629. {
  1630. if (self::$_isCssJsLabelsAdded)
  1631. return;
  1632. $this->_addJs('select2/js/select2.min.js', "'undefined' === typeof($.fn.select2)");
  1633. $this->_addJs('select2/js/i18n/' . BxDolLanguages::getInstance()->getCurrentLanguage() . '.js', "true");
  1634. $this->_addJs('select2/select2-to-tree/select2totree.js', "'undefined' === typeof($.fn.select2ToTree)");
  1635. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/css/|select2.min.css');
  1636. $this->_addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'select2/select2-to-tree/|select2totree.css');
  1637. self::$_isCssJsLabelsAdded = true;
  1638. }
  1639. function addCssJsViewMode ()
  1640. {
  1641. if (self::$_isCssJsAddedViewMode)
  1642. return;
  1643. $this->_addCss('forms.css');
  1644. self::$_isCssJsAddedViewMode = true;
  1645. }
  1646. function addCssJsCore ()
  1647. {
  1648. if (self::$_isCssJsAdded)
  1649. return;
  1650. $this->_addCss('forms.css');
  1651. $this->_addJs('jquery.webForms.js', "'undefined' === typeof($.fn.addWebForms)");
  1652. $this->_addJs('BxDolForm.js', "true");
  1653. self::$_isCssJsAdded = true;
  1654. }
  1655. function addCssJs ()
  1656. {
  1657. if (isset($this->aParams['view_mode']) && $this->aParams['view_mode']) {
  1658. $this->addCssJsViewMode ();
  1659. } else {
  1660. $this->addCssJsCore();
  1661. }
  1662. }
  1663. protected function _processCssJs()
  1664. {
  1665. $sRet = '';
  1666. if ($this->_bDynamicMode) {
  1667. $sRet .= $this->oTemplate->addCss($this->_aCss, true);
  1668. $sRet .= "\n<script>\n";
  1669. $sRet .= "\nglJsLoadOnaddWebForms = [];\n";
  1670. foreach ($this->_aJs as $sCondition => $aJs) {
  1671. $sJs = $this->oTemplate->addJs($aJs, true);
  1672. if (!$sJs)
  1673. continue;
  1674. $sRet .= "if ($sCondition)\n";
  1675. if (preg_match_all("/src=\"(.*?)\"/", $sJs, $aMatches))
  1676. $sRet .= "\tglJsLoadOnaddWebForms = glJsLoadOnaddWebForms.concat(" . json_encode($aMatches[1]) . ");\n";
  1677. }
  1678. $sRet .= "\n</script>\n";
  1679. }
  1680. else {
  1681. $this->oTemplate->addCss($this->_aCss);
  1682. $aJs = array();
  1683. foreach ($this->_aJs as $sCondition => $a)
  1684. $aJs = array_merge($aJs, $a);
  1685. $this->oTemplate->addJs($aJs);
  1686. }
  1687. return $sRet;
  1688. }
  1689. protected function _addJs($mixed, $sJsCondition)
  1690. {
  1691. if (!is_array($mixed))
  1692. $mixed = array($mixed);
  1693. $this->_aJs[$sJsCondition] = $mixed;
  1694. }
  1695. protected function _addCss($mixed)
  1696. {
  1697. if (!is_array($mixed))
  1698. $mixed = array($mixed);
  1699. foreach ($mixed as $s)
  1700. $this->_aCss[$s] = $s;
  1701. }
  1702. }
  1703. /** @} */