BxBaseFormView.php 72 KB

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