BxBaseFormView.php 72 KB

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