1
0

BxBaseFormView.php 70 KB

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