BxBaseFormView.php 72 KB

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