BxBaseFormView.php 73 KB

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