BxBaseStudioFormsField.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioFormsField extends BxDolStudioFormsField
  11. {
  12. protected $aForm;
  13. protected $sTypeTitlePrefix = '_adm_form_txt_field_type_';
  14. function __construct($aParams = array(), $aField = array())
  15. {
  16. parent::__construct($aParams, $aField);
  17. }
  18. public function init()
  19. {
  20. parent::init();
  21. $sJsObject = $this->getJsObject();
  22. bx_import('BxTemplStudioFormView');
  23. $this->aForm = array(
  24. 'form_attrs' => array(
  25. 'id' => '',
  26. 'action' => '',
  27. 'method' => BX_DOL_STUDIO_METHOD_DEFAULT
  28. ),
  29. 'params' => array (
  30. 'db' => array(
  31. 'table' => 'sys_form_inputs',
  32. 'key' => 'id',
  33. 'uri' => '',
  34. 'uri_title' => '',
  35. 'submit_name' => 'do_submit'
  36. ),
  37. ),
  38. 'inputs' => array (
  39. 'type' => array(
  40. 'type' => 'custom',
  41. 'name' => 'type',
  42. 'content' => '',
  43. 'attrs' => array(
  44. 'id' => 'bx-form-field-type',
  45. 'class' => 'bx-form-field-type',
  46. 'onchange' => $sJsObject . '.onSelectType()'
  47. ),
  48. ),
  49. 'reset' => array (
  50. 'type' => 'reset',
  51. 'name' => 'close',
  52. 'value' => _t('_adm_form_btn_field_cancel'),
  53. 'attrs' => array(
  54. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  55. 'class' => 'bx-def-margin-sec-left',
  56. ),
  57. )
  58. )
  59. );
  60. $aTypes = array();
  61. foreach($this->aTypes as $sType => $aParams)
  62. if(isset($aParams['add']) && (int)$aParams['add'] == 1)
  63. $aTypes[$sType] = _t($this->sTypeTitlePrefix . $sType);
  64. asort($aTypes);
  65. $aMenu = array();
  66. foreach($aTypes as $sName => $sTitle)
  67. $aMenu[] = array(
  68. 'name' => $sName,
  69. 'icon' => 'ui-' . $sName . '.png',
  70. 'onclick' => $sJsObject . ".onSelectType('" . $sName . "', this)",
  71. 'title' => $sTitle
  72. );
  73. $oMenu = new BxTemplStudioMenu(array('template' => 'menu_vertical.html', 'menu_items' => $aMenu));
  74. $this->aForm['inputs']['type']['content'] = $oMenu->getCode();
  75. }
  76. public function getJsObject()
  77. {
  78. return BX_DOL_STUDIO_FORMS_FIELDS_JS_OBJECT;
  79. }
  80. public function getCode($sAction, $sObject)
  81. {
  82. $sFunction = 'getCode' . $this->getClassName($sAction);
  83. if(method_exists($this, $sFunction))
  84. return $this->$sFunction($sAction, $sObject);
  85. return false;
  86. }
  87. protected function getCodeAdd($sAction, $sObject)
  88. {
  89. $aForm = $this->getFormAdd($sAction, $sObject);
  90. $oForm = new BxTemplStudioFormView($aForm);
  91. if($oForm->isSubmitted())
  92. $this->onCheckField('add', $oForm);
  93. $oForm->initChecker();
  94. if($oForm->isSubmittedAndValid()) {
  95. //--- Process field name.
  96. $sInputName = $oForm->getCleanValue('name');
  97. if(empty($sInputName)) {
  98. $sInputObject = $oForm->getCleanValue('object');
  99. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  100. $sInputCaption = BxDolForm::getSubmittedValue('caption-' . $sLanguage, $aForm['form_attrs']['method']);
  101. if(empty($sInputCaption))
  102. $sInputCaption = BxDolForm::getSubmittedValue('caption_system-' . $sLanguage, $aForm['form_attrs']['method']);
  103. $sInputName = $this->getFieldName($sInputObject, $sInputCaption);
  104. BxDolForm::setSubmittedValue('name', $sInputName, $oForm->aFormAttrs['method']);
  105. }
  106. $sFieldName = strmaxtextlen($sInputName, $this->iFieldNameMaxLen, '');
  107. if(strcmp($sInputName, $sFieldName) !== 0) {
  108. if($this->oDb->isInput($sInputObject, $sFieldName))
  109. return array('msg' => _t('_adm_form_err_field_add_already_exists'));
  110. BxDolForm::setSubmittedValue('name', $sFieldName, $oForm->aFormAttrs['method']);
  111. }
  112. if($this->isField($sFieldName))
  113. return array('msg' => _t('_adm_form_err_field_add_already_exists'));
  114. $this->onSubmitField($oForm);
  115. if(($iId = $oForm->insert()) === false)
  116. return false;
  117. if ($oForm->getCleanValue('rateable') != '')
  118. $this->checkRateableFiledValue($sInputName, $oForm->getCleanValue('module'), $oForm->getCleanValue('object'), $oForm->getCleanValue('value'));
  119. $this->alterAdd($sFieldName);
  120. return true;
  121. }
  122. else
  123. return BxTemplStudioFunctions::getInstance()->popupBox('adm-form-field-add-' . $this->aParams['display'] . '-popup', _t('_adm_form_txt_field_add_popup'), BxDolStudioTemplate::getInstance()->parseHtmlByName('form_add_field.html', array(
  124. 'form_id' => $aForm['form_attrs']['id'],
  125. 'form' => $oForm->getCode(true),
  126. 'object' => $sObject,
  127. 'action' => $sAction
  128. )));
  129. }
  130. protected function getCodeEdit($sAction, $sObject)
  131. {
  132. $aForm = $this->getFormEdit($sAction, $sObject);
  133. $oForm = new BxTemplStudioFormView($aForm);
  134. $bAlter = false;
  135. if($oForm->isSubmitted())
  136. $bAlter = $this->onCheckField('edit', $oForm);
  137. $oForm->initChecker();
  138. if($oForm->isSubmittedAndValid()) {
  139. $sInputName = $oForm->getCleanValue('name');
  140. $sFieldName = strmaxtextlen($sInputName, $this->iFieldNameMaxLen, '');
  141. if(strcmp($sInputName, $sFieldName) !== 0)
  142. BxDolForm::setSubmittedValue('name', $sFieldName, $oForm->aFormAttrs['method']);
  143. $this->onSubmitField($oForm);
  144. if($oForm->update((int)$this->aField['id']) === false)
  145. return false;
  146. if ($oForm->getCleanValue('rateable') != '')
  147. $this->checkRateableFiledValue($sInputName, $oForm->getCleanValue('module'), $oForm->getCleanValue('object'), $oForm->getCleanValue('value'));
  148. $sFieldNameOld = $this->aField['name'];
  149. if($bAlter || strcmp($sFieldNameOld, $sFieldName) !== 0)
  150. $this->alterChange($sFieldNameOld, $sFieldName);
  151. return true;
  152. }
  153. else {
  154. $sCaption = _t($this->aField['caption_system']);
  155. if(empty($sCaption))
  156. $sCaption = _t($this->aField['caption']);
  157. return BxTemplStudioFunctions::getInstance()->popupBox('adm-form-field-edit-' . $this->aField['type'] . '-popup', _t('_adm_form_txt_field_edit_popup', $sCaption), BxDolStudioTemplate::getInstance()->parseHtmlByName('form_add_field.html', array(
  158. 'form_id' => $aForm['form_attrs']['id'],
  159. 'form' => $oForm->getCode(true),
  160. 'object' => $sObject,
  161. 'action' => $sAction
  162. )));
  163. }
  164. }
  165. protected function getFormAdd($sAction, $sObject)
  166. {
  167. $aForm = $this->aForm;
  168. $aForm['form_attrs']['id'] = 'adm-form-field-add-' . $this->aParams['display'];
  169. $aForm['form_attrs']['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $sObject . '&a=' . $sAction . '&object=' . $this->aParams['object'] . '&display=' . $this->aParams['display'];
  170. if(isset($aForm['inputs']['object']))
  171. $aForm['inputs']['object']['value'] = $this->aParams['object'];
  172. return $aForm;
  173. }
  174. protected function getFormEdit($sAction, $sObject)
  175. {
  176. $aForm = $this->aForm;
  177. $aForm['form_attrs']['id'] = 'adm-form-field-edit-' . $this->aParams['display'];
  178. $aForm['form_attrs']['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $sObject . '&a=' . $sAction . '&object=' . $this->aParams['object'] . '&display=' . $this->aParams['display'] . '&di_id=' . (int)$this->aField['di_id'];
  179. foreach($aForm['inputs'] as $sKey => $aInput)
  180. if(!in_array($sKey, array('type_display', 'controls')))
  181. switch($sKey) {
  182. case 'value':
  183. $aForm['inputs'][$sKey]['value'] = $this->aField[$sKey];
  184. //--- Date and DateTime
  185. if(in_array($aForm['inputs']['type']['value'], array('datepicker', 'datetime', 'date_time')))
  186. $aForm['inputs'][$sKey]['db']['pass'] = $this->aField['db_pass'];
  187. //--- Select, Multi Select, Radio Set and Checkbox Set
  188. if(in_array($aForm['inputs']['type']['value'], array('select', 'select_multiple', 'radio_set', 'checkbox_set'))) {
  189. $sList = trim($this->getFieldValues($this->aField), BX_DATA_LISTS_KEY_PREFIX . ' ');
  190. $bUseForSets = false;
  191. if(in_array($aForm['inputs']['type']['value'], array('select_multiple', 'checkbox_set'))) {
  192. $aList = array();
  193. $this->oDb->getLists(array('type' => 'by_key', 'value' => $sList), $aList, false);
  194. $bUseForSets = (int)$aList['use_for_sets'] == 1;
  195. }
  196. $aPreValues = BxDolForm::getDataItems($sList, $bUseForSets);
  197. foreach($aPreValues as $mixedValue => $sTitle)
  198. $aForm['inputs'][$sKey]['values'][] = array('key' => $mixedValue, 'value' => $sTitle);
  199. }
  200. //--- Files
  201. if(in_array($aForm['inputs']['type']['value'], array('files'))) {
  202. if(!empty($aForm['inputs'][$sKey]['value']))
  203. $aForm['inputs'][$sKey]['value'] = unserialize($aForm['inputs'][$sKey]['value']);
  204. $aValues = unserialize($this->getFieldValues($this->aField));
  205. if(!empty($aValues) && is_array($aValues)) {
  206. $aForm['inputs'][$sKey]['values'] = array();
  207. foreach($aValues as $mixedValue => $sTitle)
  208. $aForm['inputs'][$sKey]['values'][$mixedValue] = _t($sTitle);
  209. }
  210. }
  211. break;
  212. case 'values':
  213. if(!empty($this->aField[$sKey]))
  214. $aForm['inputs'][$sKey]['value'] = $this->getFieldValues($this->aField);
  215. if(in_array($aForm['inputs']['type']['value'], array('select', 'select_multiple', 'radio_set', 'checkbox_set'))) {
  216. $aForm['inputs'][$sKey]['type'] = 'value';
  217. foreach($aForm['inputs'][$sKey]['values'] as $aValue)
  218. if($aValue['key'] == $aForm['inputs'][$sKey]['value']) {
  219. $sLink = BX_DOL_URL_STUDIO . 'builder_forms.php?page=pre_values&list=' . trim($aValue['key'], BX_DATA_LISTS_KEY_PREFIX . ' ');
  220. $aForm['inputs'][$sKey]['value'] = BxDolStudioTemplate::getInstance()->parseLink($sLink, $aValue['value'], array(
  221. 'title' => _t('_adm_form_txt_field_values_manage')
  222. ));
  223. break;
  224. }
  225. unset($aForm['inputs'][$sKey]['values'], $aForm['inputs'][$sKey]['db']);
  226. }
  227. break;
  228. case 'checked':
  229. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  230. break;
  231. case 'collapsed':
  232. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  233. break;
  234. case 'required':
  235. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  236. if($aForm['inputs'][$sKey]['checked'] == 1 && isset($aForm['inputs']['checker_func'])) {
  237. unset($aForm['inputs']['checker_func']['tr_attrs']['style'], $aForm['inputs']['checker_error']['tr_attrs']['style']);
  238. unset($aForm['inputs']['checker_func']['attrs']['disabled'], $aForm['inputs']['checker_error']['attrs']['disabled']);
  239. }
  240. break;
  241. case 'unique':
  242. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  243. break;
  244. case 'privacy':
  245. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  246. break;
  247. case 'checker_func':
  248. $sCfValue = strtolower($this->aField[$sKey]);
  249. $aForm['inputs'][$sKey]['value'] = $sCfValue;
  250. $bHidden = isset($aForm['inputs'][$sKey]['attrs']['disabled']) && !empty($sCfValue);
  251. if($bHidden) {
  252. unset($aForm['inputs'][$sKey]['attrs']['disabled']);
  253. unset($aForm['inputs']['checker_error']['attrs']['disabled']);
  254. }
  255. switch($sCfValue) {
  256. case 'length':
  257. if(!$bHidden)
  258. unset($aForm['inputs']['checker_params_length_min']['tr_attrs']['style'], $aForm['inputs']['checker_params_length_max']['tr_attrs']['style']);
  259. unset($aForm['inputs']['checker_params_length_min']['attrs']['disabled'], $aForm['inputs']['checker_params_length_max']['attrs']['disabled']);
  260. break;
  261. case 'date_range':
  262. if(!$bHidden)
  263. unset($aForm['inputs']['checker_params_length_min']['tr_attrs']['style'], $aForm['inputs']['checker_params_length_max']['tr_attrs']['style'], $aForm['inputs']['checker_params_required']['tr_attrs']['style']);
  264. unset($aForm['inputs']['checker_params_length_min']['attrs']['disabled'], $aForm['inputs']['checker_params_length_max']['attrs']['disabled'], $aForm['inputs']['checker_params_required']['attrs']['disabled']);
  265. break;
  266. case 'preg':
  267. if(!$bHidden)
  268. unset($aForm['inputs']['checker_params_preg']['tr_attrs']['style']);
  269. unset($aForm['inputs']['checker_params_preg']['attrs']['disabled']);
  270. break;
  271. }
  272. if(!empty($sCfValue) && !in_array($sCfValue, $this->aCheckFunctions)) {
  273. $aForm['inputs'][$sKey]['info'] = _t('_adm_form_txt_field_checker_func_info_custom');
  274. $aForm['inputs'][$sKey]['values'][] = array(
  275. 'key' => $sCfValue,
  276. 'value' => _t('_adm_form_txt_field_checker_custom')
  277. );
  278. }
  279. break;
  280. case 'checker_params_length_min':
  281. $aParams = unserialize($this->aField['checker_params']);
  282. $aForm['inputs'][$sKey]['value'] = isset($aParams['min']) ? (int)$aParams['min'] : 0;
  283. break;
  284. case 'checker_params_length_max':
  285. $aParams = unserialize($this->aField['checker_params']);
  286. $aForm['inputs'][$sKey]['value'] = isset($aParams['max']) ? (int)$aParams['max'] : 0;
  287. break;
  288. case 'checker_params_required':
  289. $aParams = unserialize($this->aField['checker_params']);
  290. $aForm['inputs'][$sKey]['checked'] = isset($aParams['required']) ? (int)$aParams['required'] : 0;
  291. break;
  292. case 'checker_params_preg':
  293. $aParams = unserialize($this->aField['checker_params']);
  294. $aForm['inputs'][$sKey]['value'] = isset($aParams['preg']) ? $aParams['preg'] : '';
  295. break;
  296. case 'attrs_min':
  297. $aParams = unserialize($this->aField['attrs']);
  298. $aForm['inputs'][$sKey]['value'] = isset($aParams['min']) ? (int)$aParams['min'] : 0;
  299. break;
  300. case 'attrs_max':
  301. $aParams = unserialize($this->aField['attrs']);
  302. $aForm['inputs'][$sKey]['value'] = isset($aParams['max']) ? (int)$aParams['max'] : 100;
  303. break;
  304. case 'attrs_step':
  305. $aParams = unserialize($this->aField['attrs']);
  306. $aForm['inputs'][$sKey]['value'] = isset($aParams['step']) ? (int)$aParams['step'] : 1;
  307. break;
  308. case 'attrs_src':
  309. $aParams = unserialize($this->aField['attrs']);
  310. $aForm['inputs'][$sKey]['value'] = isset($aParams['src']) ? $aParams['src'] : '';
  311. break;
  312. case 'editable':
  313. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  314. break;
  315. case 'deletable':
  316. $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
  317. break;
  318. default:
  319. $aForm['inputs'][$sKey]['value'] = $this->aField[$sKey];
  320. }
  321. if(array_key_exists($aForm['inputs']['type']['value'], $this->aTypesRelated)) {
  322. $aForm['inputs']['type'] = $this->getFieldTypesSelector('type', $aForm['inputs']['type']['value'], true);
  323. unset($aForm['inputs']['type_display']);
  324. }
  325. $aForm['inputs']['controls'][0]['value'] = _t('_adm_form_btn_field_save');
  326. return $aForm;
  327. }
  328. //--- If field is rateable, check presence in 'sys_form_fields_ids' table, insertation, if not.
  329. protected function checkRateableFiledValue($sInputName, $sModuleName, $sFormObject, $sNestedForm)
  330. {
  331. $oModule = BxDolModule::getInstance($sModuleName);
  332. $CNF = $oModule->_oConfig->CNF;
  333. $aData = bx_srv($sModuleName, 'get_all');
  334. foreach($aData as $aContentInfo){
  335. $iContentId = $aContentInfo[$CNF['FIELD_ID']];
  336. if ($sNestedForm == ''){
  337. $mixedId = BxDolFormQuery::getFormField($sFormObject, $sInputName, $iContentId);
  338. if (!$mixedId){
  339. BxDolFormQuery::addFormField($sFormObject, $sInputName, $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $sModuleName);
  340. }
  341. }
  342. else{
  343. $aNestedForm = BxDolFormQuery::getFormObject ($sNestedForm);
  344. $aNestedValues = $oModule->_oDb->getNestedBy(array('type' => 'content_id', 'id' => $iContentId, 'key_name' => $aNestedForm['key']), $aNestedForm['table']);
  345. foreach($aNestedValues as $aNestedValue){
  346. $mixedId = BxDolFormQuery::getFormField($sFormObject, $sInputName, $iContentId, $aNestedValue[$aNestedForm['key']]);
  347. if (!$mixedId){
  348. BxDolFormQuery::addFormField($sFormObject, $sInputName, $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $sModuleName, $aNestedValue[$aNestedForm['key']]);
  349. }
  350. }
  351. }
  352. }
  353. }
  354. protected function getFieldTypes($sRelatedTo = '')
  355. {
  356. $oTemplate = BxDolStudioTemplate::getInstance();
  357. $aTypesList = $sRelatedTo != '' && isset($this->aTypesRelated[$sRelatedTo]) ? $this->aTypesRelated[$sRelatedTo]['types'] : array_keys($this->aTypes);
  358. $aTypes = array();
  359. foreach($aTypesList as $sType)
  360. $aTypes[$sType] = _t($this->sTypeTitlePrefix . $sType);
  361. asort($aTypes);
  362. $aResult = array();
  363. foreach($aTypes as $sName => $sTitle)
  364. $aResult[] = array(
  365. 'key' => $sName,
  366. 'value' => $sTitle,
  367. 'style' => 'background-image:url(' . $oTemplate->getIconUrl('ui-' . $sName . '.png') . ')'
  368. );
  369. return $aResult;
  370. }
  371. protected function getFieldTypesSelector($sName, $sValue, $bRelated = false)
  372. {
  373. $bRelated = $bRelated && $sValue != '' && isset($this->aTypesRelated[$sValue]);
  374. $aField = array(
  375. 'type' => 'select',
  376. 'name' => $sName,
  377. 'caption' => _t('_adm_form_txt_field_type_display'),
  378. 'info' => '',
  379. 'value' => $sValue,
  380. 'values' => $this->getFieldTypes($bRelated ? $sValue : ''),
  381. 'required' => '',
  382. 'attrs' => array(
  383. 'id' => 'bx-form-field-type',
  384. 'class' => 'bx-form-field-type',
  385. 'disabled' => 'disabled'
  386. )
  387. );
  388. if($bRelated) {
  389. $aField['db'] = array('pass' => 'Xss');
  390. if((int)$this->aTypesRelated[$sValue]['reload_on_change'] == 1)
  391. $aField['attrs']['onchange'] = $this->getJsObject() . '.onChangeType(' . $this->aField['di_id'] . ')';
  392. unset($aField['attrs']['disabled']);
  393. }
  394. return $aField;
  395. }
  396. protected function getFieldName($sObject, $mixedCaption)
  397. {
  398. if($mixedCaption === false)
  399. return $this->genFieldName($sObject);
  400. $sName = get_mb_replace('/([^\d^\w]+)/u', '', $mixedCaption);
  401. if(empty($sName))
  402. return $this->genFieldName($sObject);
  403. $sName = get_mb_replace('/([^\d^\w^\s]+)/u', '', $mixedCaption);
  404. $sName = $this->getSystemName(trim($sName));
  405. if($this->oDb->isInput($sObject, $sName))
  406. $sName = $this->genFieldName($sObject, $sName);
  407. return $sName;
  408. }
  409. protected function getFieldValues($aField)
  410. {
  411. $mixedResult = null;
  412. switch($aField['type']) {
  413. case 'select':
  414. case 'select_multiple':
  415. case 'checkbox_set':
  416. case 'radio_set':
  417. $mixedResult = $this->aField['values'];
  418. break;
  419. case 'input_set':
  420. $mixedResult = $this->aField['values'];
  421. break;
  422. case 'files':
  423. $mixedResult = $this->aField['values'];
  424. break;
  425. }
  426. return $mixedResult;
  427. }
  428. protected function getCheckerFields($bMandatory = false)
  429. {
  430. $aResult = array(
  431. 'checker_func' => array(
  432. 'type' => 'select',
  433. 'name' => 'checker_func',
  434. 'caption' => _t('_adm_form_txt_field_checker_func'),
  435. 'info' => '',
  436. 'value' => '',
  437. 'values' => array(
  438. array('key' => '', 'value' => _t('_adm_form_txt_field_checker_empty'))
  439. ),
  440. 'required' => $bMandatory ? '1' : '0',
  441. 'attrs' => array(
  442. 'id' => 'bx-form-field-type',
  443. 'onchange' => $this->getJsObject() . ".onSelectChecker(this)",
  444. 'disabled' => 'disabled'
  445. ),
  446. 'tr_attrs' => array(
  447. 'style' => 'display:none'
  448. ),
  449. 'db' => array (
  450. 'pass' => 'Xss',
  451. )
  452. ),
  453. 'checker_params' => array(
  454. 'type' => 'hidden',
  455. 'name' => 'checker_params',
  456. 'value' => '',
  457. 'db' => array (
  458. 'pass' => 'Xss',
  459. )
  460. ),
  461. 'checker_params_length_min' => array(
  462. 'type' => 'text',
  463. 'name' => 'checker_params_length_min',
  464. 'caption' => _t('_adm_form_txt_field_checker_params_length_min'),
  465. 'info' => '',
  466. 'value' => '',
  467. 'required' => $bMandatory ? '1' : '0',
  468. 'attrs' => array(
  469. 'disabled' => 'disabled'
  470. ),
  471. 'tr_attrs' => array(
  472. 'style' => 'display:none'
  473. ),
  474. 'db' => array (
  475. 'pass' => 'Int',
  476. )
  477. ),
  478. 'checker_params_length_max' => array(
  479. 'type' => 'text',
  480. 'name' => 'checker_params_length_max',
  481. 'caption' => _t('_adm_form_txt_field_checker_params_length_max'),
  482. 'info' => '',
  483. 'value' => '',
  484. 'required' => $bMandatory ? '1' : '0',
  485. 'attrs' => array(
  486. 'disabled' => 'disabled'
  487. ),
  488. 'tr_attrs' => array(
  489. 'style' => 'display:none'
  490. ),
  491. 'db' => array (
  492. 'pass' => 'Int',
  493. )
  494. ),
  495. 'checker_params_required' => array(
  496. 'type' => 'checkbox',
  497. 'name' => 'checker_params_required',
  498. 'caption' => _t('_adm_form_txt_field_checker_params_required'),
  499. 'info' => '',
  500. 'value' => '1',
  501. 'required' => $bMandatory ? '1' : '0',
  502. 'attrs' => array(
  503. 'disabled' => 'disabled'
  504. ),
  505. 'tr_attrs' => array(
  506. 'style' => 'display:none'
  507. ),
  508. 'db' => array (
  509. 'pass' => 'Int',
  510. )
  511. ),
  512. 'checker_params_preg' => array(
  513. 'type' => 'text',
  514. 'name' => 'checker_params_preg',
  515. 'caption' => _t('_adm_form_txt_field_checker_params_preg'),
  516. 'info' => _t('_adm_form_dsc_field_checker_params_preg'),
  517. 'value' => '',
  518. 'required' => $bMandatory ? '1' : '0',
  519. 'attrs' => array(
  520. 'disabled' => 'disabled'
  521. ),
  522. 'tr_attrs' => array(
  523. 'style' => 'display:none'
  524. ),
  525. 'db' => array (
  526. 'pass' => 'Xss',
  527. )
  528. ),
  529. 'checker_error' => array(
  530. 'type' => 'text_translatable',
  531. 'name' => 'checker_error',
  532. 'caption' => _t('_adm_form_txt_field_checker_error'),
  533. 'info' => '',
  534. 'value' => '_sys_form_txt_field_checker_error',
  535. 'required' => $bMandatory ? '1' : '0',
  536. 'attrs' => array(
  537. 'disabled' => 'disabled'
  538. ),
  539. 'tr_attrs' => array(
  540. 'style' => 'display:none'
  541. ),
  542. 'db' => array (
  543. 'pass' => 'Xss',
  544. )
  545. ),
  546. );
  547. foreach($this->aCheckFunctions as $sCheckFunction)
  548. $aResult['checker_func']['values'][] = array('key' => $sCheckFunction, 'value' => _t('_adm_form_txt_field_checker_' . $sCheckFunction));
  549. if($bMandatory)
  550. $aResult = array_merge_recursive($aResult, array(
  551. 'checker_func' => array(
  552. 'checker' => array (
  553. 'func' => 'avail',
  554. 'params' => array(),
  555. 'error' => _t('_adm_form_err_field_checker_func'),
  556. )
  557. ),
  558. 'checker_params_length_min' => array(
  559. 'checker' => array (
  560. 'func' => 'preg',
  561. 'params' => array('/^[0-9]+$/'),
  562. 'error' => _t('_adm_form_err_field_checker_params_length_min'),
  563. )
  564. ),
  565. 'checker_params_length_max' => array(
  566. 'checker' => array (
  567. 'func' => 'preg',
  568. 'params' => array('/^[0-9]+$/'),
  569. 'error' => _t('_adm_form_err_field_checker_params_length_max'),
  570. )
  571. ),
  572. 'checker_params_preg' => array(
  573. 'checker' => array (
  574. 'func' => 'avail',
  575. 'params' => array(),
  576. 'error' => _t('_adm_form_err_field_checker_params_preg'),
  577. ),
  578. ),
  579. 'checker_error' => array(
  580. 'checker' => array (
  581. 'func' => 'availTranslatable',
  582. 'params' => array('checker_error'),
  583. 'error' => _t('_adm_form_err_field_checker_error'),
  584. )
  585. )
  586. ));
  587. return $aResult;
  588. }
  589. protected function updateCheckerFields($sType, &$oForm)
  590. {
  591. if((int)$oForm->getCleanValue('required') == 0)
  592. switch($sType) {
  593. case 'add':
  594. $this->unsetCheckerFields($oForm);
  595. break;
  596. case 'edit':
  597. $this->clearCheckerFields($oForm);
  598. break;
  599. }
  600. else {
  601. unset($oForm->aInputs['checker_func']['tr_attrs']['style'], $oForm->aInputs['checker_error']['tr_attrs']['style']);
  602. unset($oForm->aInputs['checker_func']['attrs']['disabled'], $oForm->aInputs['checker_error']['attrs']['disabled']);
  603. switch($oForm->getCleanValue('checker_func')) {
  604. case 'length':
  605. unset($oForm->aInputs['checker_params_length_min']['tr_attrs']['style'], $oForm->aInputs['checker_params_length_max']['tr_attrs']['style']);
  606. unset($oForm->aInputs['checker_params_length_min']['attrs']['disabled'], $oForm->aInputs['checker_params_length_max']['attrs']['disabled']);
  607. $this->unsetCheckerFields($oForm, 'required');
  608. $this->unsetCheckerFields($oForm, 'preg');
  609. break;
  610. case 'date_range':
  611. unset($oForm->aInputs['checker_params_length_min']['tr_attrs']['style'], $oForm->aInputs['checker_params_length_max']['tr_attrs']['style'], $oForm->aInputs['checker_params_required']['tr_attrs']['style']);
  612. unset($oForm->aInputs['checker_params_length_min']['attrs']['disabled'], $oForm->aInputs['checker_params_length_max']['attrs']['disabled'], $oForm->aInputs['checker_params_required']['attrs']['disabled']);
  613. $this->unsetCheckerFields($oForm, 'preg');
  614. break;
  615. case 'preg':
  616. unset($oForm->aInputs['checker_params_preg']['tr_attrs']['style']);
  617. unset($oForm->aInputs['checker_params_preg']['attrs']['disabled']);
  618. $this->unsetCheckerFields($oForm, 'date_range');
  619. break;
  620. default:
  621. $this->unsetCheckerFields($oForm, 'params');
  622. }
  623. }
  624. }
  625. protected function clearCheckerFields(&$oForm, $sCheckerFunc = 'all')
  626. {
  627. switch($sCheckerFunc) {
  628. case 'length':
  629. $oForm->aInputs['checker_params_length_min']['value'] = '';
  630. $oForm->aInputs['checker_params_length_max']['value'] = '';
  631. break;
  632. case 'date_range':
  633. $oForm->aInputs['checker_params_length_min']['value'] = '';
  634. $oForm->aInputs['checker_params_length_max']['value'] = '';
  635. $oForm->aInputs['checker_params_required']['value'] = '';
  636. break;
  637. case 'required':
  638. $oForm->aInputs['checker_params_required']['value'] = '';
  639. break;
  640. case 'preg':
  641. $oForm->aInputs['checker_params_preg']['value'] = '';
  642. break;
  643. case 'params':
  644. $oForm->aInputs['checker_params_length_min']['value'] = '';
  645. $oForm->aInputs['checker_params_length_max']['value'] = '';
  646. $oForm->aInputs['checker_params_required']['value'] = '';
  647. $oForm->aInputs['checker_params_preg']['value'] = '';
  648. break;
  649. case 'all':
  650. $oForm->aInputs['checker_func']['value'] = '';
  651. $oForm->aInputs['checker_params']['value'] = '';
  652. $oForm->aInputs['checker_params_length_min']['value'] = '';
  653. $oForm->aInputs['checker_params_length_max']['value'] = '';
  654. $oForm->aInputs['checker_params_required']['value'] = '';
  655. $oForm->aInputs['checker_params_preg']['value'] = '';
  656. $oForm->aInputs['checker_error']['value'] = '';
  657. }
  658. }
  659. protected function unsetCheckerFields(&$oForm, $sCheckerFunc = 'all')
  660. {
  661. switch($sCheckerFunc) {
  662. case 'length':
  663. unset(
  664. $oForm->aInputs['checker_params_length_min'],
  665. $oForm->aInputs['checker_params_length_max']
  666. );
  667. break;
  668. case 'date_range':
  669. unset(
  670. $oForm->aInputs['checker_params_length_min'],
  671. $oForm->aInputs['checker_params_length_max'],
  672. $oForm->aInputs['checker_params_required']
  673. );
  674. break;
  675. case 'required':
  676. unset(
  677. $oForm->aInputs['checker_params_required']
  678. );
  679. break;
  680. case 'preg':
  681. unset($oForm->aInputs['checker_params_preg']);
  682. break;
  683. case 'params':
  684. unset(
  685. $oForm->aInputs['checker_params_length_min'],
  686. $oForm->aInputs['checker_params_length_max'],
  687. $oForm->aInputs['checker_params_required'],
  688. $oForm->aInputs['checker_params_preg']
  689. );
  690. break;
  691. case 'all':
  692. unset(
  693. $oForm->aInputs['checker_func'],
  694. $oForm->aInputs['checker_params'],
  695. $oForm->aInputs['checker_params_length_min'],
  696. $oForm->aInputs['checker_params_length_max'],
  697. $oForm->aInputs['checker_params_required'],
  698. $oForm->aInputs['checker_params_preg'],
  699. $oForm->aInputs['checker_error']
  700. );
  701. }
  702. }
  703. protected function genFieldName($sObject, $sPrefix = 'field')
  704. {
  705. $aFields = array();
  706. $this->oDb->getInputs(array('type' => 'by_object_name_filter', 'object' => $sObject, 'name_filter' => $sPrefix . '%'), $aFields, false);
  707. for($iIndex = 1; true; $iIndex++)
  708. if(!in_array($sPrefix . $iIndex, $aFields))
  709. break;
  710. return $sPrefix . $iIndex;
  711. }
  712. protected function onCheckField($sType, &$oForm)
  713. {
  714. $bAlter = false;
  715. //--- Process field 'required' and related 'checker' fields.
  716. if(isset($oForm->aInputs['required']))
  717. $this->updateCheckerFields($sType, $oForm);
  718. //--- Process field 'db_pass' and related dependencies.
  719. if(isset($oForm->aInputs['db_pass']) && $oForm->aInputs['db_pass']['type'] == 'select') {
  720. $sDbPass = $oForm->getCleanValue('db_pass');
  721. $this->aForm['inputs']['value']['db']['pass'] = $sDbPass;
  722. if(!empty($this->aDbPassDependency[$sDbPass])) {
  723. $this->aParams['table_field_type'] = $this->aDbPassDependency[$sDbPass]['alter'];
  724. $bAlter = true;
  725. }
  726. }
  727. return $bAlter;
  728. }
  729. protected function onSubmitField(&$oForm)
  730. {
  731. //--- Process field value.
  732. if(isset($oForm->aInputs['value']['db']))
  733. $oForm->aInputs['value']['db']['pass'] = $oForm->getCleanValue('db_pass');
  734. //--- Process field values.
  735. if(isset($oForm->aInputs['values']['db']))
  736. $this->onSubmitFieldValues($oForm);
  737. //--- Process field 'html' flag.
  738. if(isset($oForm->aInputs['html'])) {
  739. $iHtml = (int)$oForm->getCleanValue('html');
  740. BxDolForm::setSubmittedValue('db_pass', $iHtml == 0 ? 'XssMultiline' : 'XssHtml', $oForm->aFormAttrs['method']);
  741. }
  742. //--- Process field checker.
  743. $sCheckerFunc = $oForm->getCleanValue('checker_func');
  744. $aCheckerParams = array();
  745. if(!empty($sCheckerFunc)) {
  746. if(isset($oForm->aInputs['checker_params_length_min'], $oForm->aInputs['checker_params_length_max'])) {
  747. $aCheckerParams['min'] = $oForm->getCleanValue('checker_params_length_min');
  748. $aCheckerParams['max'] = $oForm->getCleanValue('checker_params_length_max');
  749. }
  750. if(isset($oForm->aInputs['checker_params_preg']))
  751. $aCheckerParams['preg'] = $oForm->getCleanValue('checker_params_preg');
  752. if(isset($oForm->aInputs['checker_params_required']))
  753. $aCheckerParams['required'] = $oForm->getCleanValue('checker_params_required');
  754. switch($sCheckerFunc) {
  755. case 'location':
  756. $aCheckerParams['name'] = $oForm->getCleanValue('name');
  757. break;
  758. }
  759. }
  760. unset($oForm->aInputs['checker_params_length_min'], $oForm->aInputs['checker_params_length_max'], $oForm->aInputs['checker_params_preg'], $oForm->aInputs['checker_params_required']);
  761. BxDolForm::setSubmittedValue('checker_params', !empty($aCheckerParams) ? serialize($aCheckerParams) : '', $oForm->aFormAttrs['method']);
  762. //--- Process field attrs.
  763. $aAttrs = array();
  764. if(isset($oForm->aInputs['attrs_min'], $oForm->aInputs['attrs_max'], $oForm->aInputs['attrs_step'])) {
  765. $aAttrs['min'] = $oForm->getCleanValue('attrs_min');
  766. $aAttrs['max'] = $oForm->getCleanValue('attrs_max');
  767. $aAttrs['step'] = $oForm->getCleanValue('attrs_step');
  768. } else if(isset($oForm->aInputs['attrs_src']))
  769. $aAttrs['src'] = $oForm->getCleanValue('attrs_src');
  770. unset($oForm->aInputs['attrs_min'], $oForm->aInputs['attrs_max'], $oForm->aInputs['attrs_step'], $oForm->aInputs['attrs_src']);
  771. BxDolForm::setSubmittedValue('attrs', serialize($aAttrs), $oForm->aFormAttrs['method']);
  772. }
  773. protected function onSubmitFieldValues(&$oForm)
  774. {
  775. $sValues = $oForm->getCleanValue('values');
  776. if(is_string($sValues) && strpos($sValues, BX_DATA_LISTS_KEY_PREFIX) === false)
  777. BxDolForm::setSubmittedValue('values', serialize(explode("\n", $sValues)), $oForm->aFormAttrs['method']);
  778. }
  779. }
  780. class BxBaseStudioFormsFieldBlockHeader extends BxBaseStudioFormsField
  781. {
  782. protected $sType = 'block_header';
  783. public function init()
  784. {
  785. parent::init();
  786. $this->aForm = array(
  787. 'form_attrs' => array(
  788. 'id' => '',
  789. 'action' => '',
  790. 'method' => 'post'
  791. ),
  792. 'params' => array (
  793. 'db' => array(
  794. 'table' => 'sys_form_inputs',
  795. 'key' => 'id',
  796. 'uri' => '',
  797. 'uri_title' => '',
  798. 'submit_name' => 'do_submit'
  799. ),
  800. ),
  801. 'inputs' => array (
  802. 'module' => array(
  803. 'type' => 'hidden',
  804. 'name' => 'module',
  805. 'caption' => _t('_adm_form_txt_field_module'),
  806. 'value' => 'custom',
  807. 'db' => array (
  808. 'pass' => 'Xss',
  809. ),
  810. ),
  811. 'object' => array(
  812. 'type' => 'hidden',
  813. 'name' => 'object',
  814. 'caption' => _t('_adm_form_txt_field_object'),
  815. 'value' => '',
  816. 'db' => array (
  817. 'pass' => 'Xss',
  818. ),
  819. ),
  820. 'name' => array(
  821. 'type' => 'hidden',
  822. 'name' => 'name',
  823. 'caption' => _t('_adm_form_txt_field_name'),
  824. 'value' => '',
  825. 'db' => array (
  826. 'pass' => 'Xss',
  827. )
  828. ),
  829. 'type' => array(
  830. 'type' => 'hidden',
  831. 'name' => 'type',
  832. 'value' => $this->sType,
  833. 'db' => array (
  834. 'pass' => 'Xss',
  835. )
  836. ),
  837. 'db_pass' => array(
  838. 'type' => 'hidden',
  839. 'name' => 'db_pass',
  840. 'value' => $this->sDbPass,
  841. 'db' => array (
  842. 'pass' => 'Xss',
  843. )
  844. ),
  845. 'type_display' => $this->getFieldTypesSelector('type_display', $this->sType),
  846. 'caption_system' => array(
  847. 'type' => 'text_translatable',
  848. 'name' => 'caption_system',
  849. 'caption' => _t('_adm_form_txt_field_caption_system'),
  850. 'info' => _t('_adm_form_dsc_field_caption_system'),
  851. 'value' => '_sys_form_txt_field',
  852. 'required' => '0',
  853. 'db' => array (
  854. 'pass' => 'Xss',
  855. ),
  856. ),
  857. 'caption' => array(
  858. 'type' => 'text_translatable',
  859. 'name' => 'caption',
  860. 'caption' => _t('_adm_form_txt_field_caption'),
  861. 'info' => _t('_adm_form_dsc_field_caption_block_header'),
  862. 'value' => '_sys_form_txt_field',
  863. 'required' => '1',
  864. 'db' => array (
  865. 'pass' => 'Xss',
  866. ),
  867. 'checker' => array (
  868. 'func' => 'LengthTranslatable',
  869. 'params' => array(3, 100, 'caption'),
  870. 'error' => _t('_adm_form_err_field_caption'),
  871. ),
  872. ),
  873. 'collapsed' => array(
  874. 'type' => 'checkbox',
  875. 'name' => 'collapsed',
  876. 'caption' => _t('_adm_form_txt_field_collapsed'),
  877. 'info' => _t('_adm_form_dsc_field_collapsed'),
  878. 'value' => '1',
  879. 'required' => '0',
  880. 'db' => array (
  881. 'pass' => 'Int',
  882. )
  883. ),
  884. 'privacy' => array(
  885. 'type' => 'switcher',
  886. 'name' => 'privacy',
  887. 'caption' => _t('_adm_form_txt_field_privacy'),
  888. 'info' => _t('_adm_form_dsc_field_privacy'),
  889. 'value' => '1',
  890. 'required' => '0',
  891. 'attrs' => array(
  892. 'id' => 'bx-form-field-privacy'
  893. ),
  894. 'db' => array (
  895. 'pass' => 'Int',
  896. )
  897. ),
  898. 'rateable' => array(
  899. 'type' => 'select',
  900. 'name' => 'rateable',
  901. 'caption' => _t('_adm_form_txt_field_rateable'),
  902. 'info' => _t('_adm_form_dsc_field_rateable'),
  903. 'values' => array(
  904. array('key' => '', 'value' => _t('_adm_form_txt_field_rateable_value_non')),
  905. array('key' => 'sys_form_fields_votes', 'value' => _t('_adm_form_txt_field_rateable_value_votes')),
  906. array('key' => 'sys_form_fields_reaction', 'value' => _t('_adm_form_txt_field_rateable_value_reactions'))
  907. ),
  908. 'required' => '0',
  909. 'attrs' => array(
  910. 'id' => 'bx-form-field-rateable'
  911. ),
  912. 'db' => array (
  913. 'pass' => 'Xss',
  914. )
  915. ),
  916. 'controls' => array(
  917. 'name' => 'controls',
  918. 'type' => 'input_set',
  919. array(
  920. 'type' => 'submit',
  921. 'name' => 'do_submit',
  922. 'value' => _t('_adm_form_btn_field_add'),
  923. ),
  924. array (
  925. 'type' => 'reset',
  926. 'name' => 'close',
  927. 'value' => _t('_adm_form_btn_field_cancel'),
  928. 'attrs' => array(
  929. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  930. 'class' => 'bx-def-margin-sec-left',
  931. ),
  932. )
  933. )
  934. )
  935. );
  936. if ($this->isNested()){
  937. unset($this->aForm['inputs']['rateable']);
  938. }
  939. }
  940. }
  941. class BxBaseStudioFormsFieldBlockEnd extends BxBaseStudioFormsField
  942. {
  943. protected $sType = 'block_end';
  944. public function init()
  945. {
  946. parent::init();
  947. $this->aForm = array(
  948. 'form_attrs' => array(
  949. 'id' => '',
  950. 'action' => '',
  951. 'method' => 'post'
  952. ),
  953. 'params' => array (
  954. 'db' => array(
  955. 'table' => 'sys_form_inputs',
  956. 'key' => 'id',
  957. 'uri' => '',
  958. 'uri_title' => '',
  959. 'submit_name' => 'do_submit'
  960. ),
  961. ),
  962. 'inputs' => array (
  963. 'module' => array(
  964. 'type' => 'hidden',
  965. 'name' => 'module',
  966. 'caption' => _t('_adm_form_txt_field_module'),
  967. 'value' => 'custom',
  968. 'db' => array (
  969. 'pass' => 'Xss',
  970. ),
  971. ),
  972. 'object' => array(
  973. 'type' => 'hidden',
  974. 'name' => 'object',
  975. 'caption' => _t('_adm_form_txt_field_object'),
  976. 'value' => '',
  977. 'db' => array (
  978. 'pass' => 'Xss',
  979. ),
  980. ),
  981. 'name' => array(
  982. 'type' => 'hidden',
  983. 'name' => 'name',
  984. 'caption' => _t('_adm_form_txt_field_name'),
  985. 'value' => '',
  986. 'db' => array (
  987. 'pass' => 'Xss',
  988. )
  989. ),
  990. 'type' => array(
  991. 'type' => 'hidden',
  992. 'name' => 'type',
  993. 'value' => $this->sType,
  994. 'db' => array (
  995. 'pass' => 'Xss',
  996. )
  997. ),
  998. 'db_pass' => array(
  999. 'type' => 'hidden',
  1000. 'name' => 'db_pass',
  1001. 'value' => $this->sDbPass,
  1002. 'db' => array (
  1003. 'pass' => 'Xss',
  1004. )
  1005. ),
  1006. 'type_display' => $this->getFieldTypesSelector('type_display', $this->sType),
  1007. 'caption_system' => array(
  1008. 'type' => 'text_translatable',
  1009. 'name' => 'caption_system',
  1010. 'caption' => _t('_adm_form_txt_field_caption_system'),
  1011. 'info' => _t('_adm_form_dsc_field_caption_system'),
  1012. 'value' => '_sys_form_txt_field',
  1013. 'required' => '1',
  1014. 'db' => array (
  1015. 'pass' => 'Xss',
  1016. ),
  1017. 'checker' => array (
  1018. 'func' => 'LengthTranslatable',
  1019. 'params' => array(3,100, 'caption_system'),
  1020. 'error' => _t('_adm_form_err_field_caption_system'),
  1021. ),
  1022. ),
  1023. 'controls' => array(
  1024. 'name' => 'controls',
  1025. 'type' => 'input_set',
  1026. array(
  1027. 'type' => 'submit',
  1028. 'name' => 'do_submit',
  1029. 'value' => _t('_adm_form_btn_field_add'),
  1030. ),
  1031. array (
  1032. 'type' => 'reset',
  1033. 'name' => 'close',
  1034. 'value' => _t('_adm_form_btn_field_cancel'),
  1035. 'attrs' => array(
  1036. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1037. 'class' => 'bx-def-margin-sec-left',
  1038. ),
  1039. )
  1040. )
  1041. )
  1042. );
  1043. }
  1044. }
  1045. class BxBaseStudioFormsFieldValue extends BxBaseStudioFormsFieldBlockHeader
  1046. {
  1047. protected $sType = 'value';
  1048. public function init()
  1049. {
  1050. parent::init();
  1051. $this->aForm['inputs']['caption']['info'] = _t('_adm_form_dsc_field_caption');
  1052. $aFields = array(
  1053. 'value' => array(
  1054. 'type' => 'text',
  1055. 'name' => 'value',
  1056. 'caption' => _t('_adm_form_txt_field_value_custom_text'),
  1057. 'info' => '',
  1058. 'value' => '',
  1059. 'required' => '0',
  1060. 'db' => array (
  1061. 'pass' => 'Xss',
  1062. )
  1063. ),
  1064. );
  1065. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'caption', $aFields);
  1066. unset(
  1067. $this->aForm['inputs']['collapsed']
  1068. );
  1069. }
  1070. }
  1071. class BxBaseStudioFormsFieldText extends BxBaseStudioFormsFieldBlockHeader
  1072. {
  1073. protected $sType = 'text';
  1074. protected $aCheckFunctions = array('avail', 'length', 'preg', 'email');
  1075. protected $sDbPass = 'Xss';
  1076. protected $aFieldUnique;
  1077. public function init()
  1078. {
  1079. parent::init();
  1080. $this->aParams['table_alter'] = true;
  1081. $this->aParams['table_field_type'] = 'varchar(255)';
  1082. $this->aForm['inputs']['caption']['info'] = _t('_adm_form_dsc_field_caption');
  1083. $this->aFieldUnique = array(
  1084. 'type' => 'switcher',
  1085. 'name' => 'unique',
  1086. 'caption' => _t('_adm_form_txt_field_unique'),
  1087. 'info' => _t('_adm_form_dsc_field_unique'),
  1088. 'value' => '1',
  1089. 'required' => '0',
  1090. 'attrs' => array(
  1091. 'id' => 'bx-form-field-unique'
  1092. ),
  1093. 'db' => array (
  1094. 'pass' => 'Int',
  1095. )
  1096. );
  1097. $aFields = array(
  1098. 'value' => array(
  1099. 'type' => 'text',
  1100. 'name' => 'value',
  1101. 'caption' => _t('_adm_form_txt_field_value_default'),
  1102. 'info' => '',
  1103. 'value' => '',
  1104. 'required' => '0',
  1105. 'db' => array (
  1106. 'pass' => 'Xss',
  1107. )
  1108. ),
  1109. 'info' => array(
  1110. 'type' => 'textarea_translatable',
  1111. 'name' => 'info',
  1112. 'caption' => _t('_adm_form_txt_field_info'),
  1113. 'info' => _t('_adm_form_dsc_field_info'),
  1114. 'value' => '_sys_form_txt_field',
  1115. 'required' => '0',
  1116. 'code' => 1,
  1117. 'db' => array (
  1118. 'pass' => 'Xss',
  1119. )
  1120. ),
  1121. 'help' => array(
  1122. 'type' => 'textarea_translatable',
  1123. 'name' => 'help',
  1124. 'caption' => _t('_adm_form_txt_field_help'),
  1125. 'info' => _t('_adm_form_dsc_field_help'),
  1126. 'value' => '_sys_form_txt_field',
  1127. 'required' => '0',
  1128. 'html' => 2,
  1129. 'db' => array (
  1130. 'pass' => 'Xss',
  1131. )
  1132. ),
  1133. 'required' => array(
  1134. 'type' => 'switcher',
  1135. 'name' => 'required',
  1136. 'caption' => _t('_adm_form_txt_field_required'),
  1137. 'info' => _t('_adm_form_dsc_field_required'),
  1138. 'value' => '1',
  1139. 'required' => '0',
  1140. 'attrs' => array(
  1141. 'id' => 'bx-form-field-required',
  1142. 'onchange' => $this->getJsObject() . ".onCheckRequired(this)"
  1143. ),
  1144. 'db' => array (
  1145. 'pass' => 'Int',
  1146. )
  1147. ),
  1148. 'unique' => $this->aFieldUnique
  1149. );
  1150. $aFields = array_merge($aFields, $this->getCheckerFields());
  1151. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'caption', $aFields);
  1152. unset($this->aForm['inputs']['collapsed']);
  1153. }
  1154. }
  1155. class BxBaseStudioFormsFieldPassword extends BxBaseStudioFormsFieldText
  1156. {
  1157. protected $sType = 'password';
  1158. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1159. public function init()
  1160. {
  1161. parent::init();
  1162. unset($this->aForm['inputs']['unique']);
  1163. }
  1164. }
  1165. class BxBaseStudioFormsFieldTextarea extends BxBaseStudioFormsFieldText
  1166. {
  1167. protected $sType = 'textarea';
  1168. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1169. public function init()
  1170. {
  1171. parent::init();
  1172. $this->aParams['table_field_type'] = 'text';
  1173. $this->aForm['inputs']['value']['type'] = $this->sType;
  1174. $aFields = array(
  1175. 'html' => array(
  1176. 'type' => 'select',
  1177. 'name' => 'html',
  1178. 'caption' => _t('_adm_form_txt_field_html'),
  1179. 'info' => _t('_adm_form_dsc_field_html'),
  1180. 'value' => '0',
  1181. 'values' => array(
  1182. array('key' => '0', 'value' => _t('_adm_form_txt_field_html_none')),
  1183. array('key' => '1', 'value' => _t('_adm_form_txt_field_html_standard')),
  1184. array('key' => '2', 'value' => _t('_adm_form_txt_field_html_full')),
  1185. array('key' => '3', 'value' => _t('_adm_form_txt_field_html_mini')),
  1186. ),
  1187. 'required' => '0',
  1188. 'db' => array (
  1189. 'pass' => 'Int',
  1190. )
  1191. ),
  1192. );
  1193. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'help', $aFields);
  1194. unset($this->aForm['inputs']['unique']);
  1195. }
  1196. }
  1197. class BxBaseStudioFormsFieldDatepicker extends BxBaseStudioFormsFieldText
  1198. {
  1199. protected $sType = 'datepicker';
  1200. protected $aCheckFunctions = array('date','date_range');
  1201. protected $sDbPass = 'DateTs';
  1202. protected $aDbPassDependency = array(
  1203. 'Date' => array('alter' => 'date'),
  1204. 'DateTs' => array('alter' => 'int(11)'),
  1205. 'DateUtc' => array('alter' => 'int(11)'),
  1206. );
  1207. public function init()
  1208. {
  1209. parent::init();
  1210. $this->aParams['table_field_type'] = 'int(11)';
  1211. $this->aForm['inputs']['value']['type'] = $this->sType;
  1212. $this->aForm['inputs']['value']['db']['pass'] = $this->sDbPass;
  1213. $aFields = array(
  1214. 'db_pass' => array(
  1215. 'type' => 'select',
  1216. 'name' => 'db_pass',
  1217. 'caption' => _t('_adm_form_txt_field_db_pass'),
  1218. 'info' => _t('_adm_form_dsc_field_db_pass'),
  1219. 'value' => $this->sDbPass,
  1220. 'values' => array(
  1221. array('key' => '', 'value' => _t('_adm_form_txt_field_db_pass_select_value')),
  1222. array('key' => 'Date', 'value' => _t('_adm_form_txt_field_db_pass_date')),
  1223. array('key' => 'DateTs', 'value' => _t('_adm_form_txt_field_db_pass_date_ts')),
  1224. array('key' => 'DateUtc', 'value' => _t('_adm_form_txt_field_db_pass_date_utc')),
  1225. ),
  1226. 'required' => '0',
  1227. 'db' => array (
  1228. 'pass' => 'Xss',
  1229. )
  1230. ),
  1231. );
  1232. unset($this->aForm['inputs']['db_pass']);
  1233. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'controls', $aFields, false);
  1234. }
  1235. }
  1236. class BxBaseStudioFormsFieldDateselect extends BxBaseStudioFormsFieldText
  1237. {
  1238. protected $sType = 'dateselect';
  1239. protected $aCheckFunctions = array('date','date_range');
  1240. protected $sDbPass = 'DateTs';
  1241. protected $aDbPassDependency = array(
  1242. 'Date' => array('alter' => 'date'),
  1243. 'DateTs' => array('alter' => 'int(11)'),
  1244. 'DateUtc' => array('alter' => 'int(11)'),
  1245. );
  1246. public function init()
  1247. {
  1248. parent::init();
  1249. $this->aParams['table_field_type'] = 'int(11)';
  1250. $this->aForm['inputs']['value']['type'] = $this->sType;
  1251. $this->aForm['inputs']['value']['db']['pass'] = $this->sDbPass;
  1252. $aFields = array(
  1253. 'db_pass' => array(
  1254. 'type' => 'select',
  1255. 'name' => 'db_pass',
  1256. 'caption' => _t('_adm_form_txt_field_db_pass'),
  1257. 'info' => _t('_adm_form_dsc_field_db_pass'),
  1258. 'value' => $this->sDbPass,
  1259. 'values' => array(
  1260. array('key' => '', 'value' => _t('_adm_form_txt_field_db_pass_select_value')),
  1261. array('key' => 'Date', 'value' => _t('_adm_form_txt_field_db_pass_date')),
  1262. array('key' => 'DateTs', 'value' => _t('_adm_form_txt_field_db_pass_date_ts')),
  1263. array('key' => 'DateUtc', 'value' => _t('_adm_form_txt_field_db_pass_date_utc')),
  1264. ),
  1265. 'required' => '0',
  1266. 'db' => array (
  1267. 'pass' => 'Xss',
  1268. )
  1269. ),
  1270. );
  1271. unset($this->aForm['inputs']['db_pass']);
  1272. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'controls', $aFields, false);
  1273. }
  1274. }
  1275. class BxBaseStudioFormsFieldDatetime extends BxBaseStudioFormsFieldDatepicker
  1276. {
  1277. protected $sType = 'datetime';
  1278. protected $aCheckFunctions = array('date_time');
  1279. protected $sDbPass = 'DateTimeTs';
  1280. protected $aDbPassDependency = array(
  1281. 'DateTime' => array('alter' => 'datetime'),
  1282. 'DateTimeTs' => array('alter' => 'int(11)'),
  1283. 'DateTimeUtc' => array('alter' => 'int(11)'),
  1284. );
  1285. public function init()
  1286. {
  1287. parent::init();
  1288. $this->aForm['inputs']['value']['db']['pass'] = $this->sDbPass;
  1289. $this->aForm['inputs']['db_pass']['values'] = array(
  1290. array('key' => '', 'value' => _t('_adm_form_txt_field_db_pass_select_value')),
  1291. array('key' => 'DateTime', 'value' => _t('_adm_form_txt_field_db_pass_date_time')),
  1292. array('key' => 'DateTimeTs', 'value' => _t('_adm_form_txt_field_db_pass_date_time_ts')),
  1293. array('key' => 'DateTimeUtc', 'value' => _t('_adm_form_txt_field_db_pass_date_time_utc')),
  1294. );
  1295. }
  1296. }
  1297. class BxBaseStudioFormsFieldCheckbox extends BxBaseStudioFormsFieldText
  1298. {
  1299. protected $sType = 'checkbox';
  1300. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1301. public function init()
  1302. {
  1303. parent::init();
  1304. $this->aForm['inputs']['value']['type'] = 'hidden';
  1305. $this->aForm['inputs']['value']['caption'] = _t('_adm_form_txt_field_value_checkbox');
  1306. $this->aForm['inputs']['value']['value'] = '1';
  1307. $this->aForm['inputs']['value']['info'] = _t('_adm_form_dsc_field_value_checkbox');
  1308. $aFields = array(
  1309. 'checked' => array(
  1310. 'type' => 'checkbox',
  1311. 'name' => 'checked',
  1312. 'caption' => _t('_adm_form_txt_field_checked'),
  1313. 'value' => '1',
  1314. 'required' => '0',
  1315. 'db' => array (
  1316. 'pass' => 'Int',
  1317. )
  1318. )
  1319. );
  1320. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'value', $aFields);
  1321. unset($this->aForm['inputs']['unique']);
  1322. }
  1323. }
  1324. class BxBaseStudioFormsFieldSwitcher extends BxBaseStudioFormsFieldCheckbox
  1325. {
  1326. protected $sType = 'switcher';
  1327. public function init()
  1328. {
  1329. parent::init();
  1330. $this->aForm['inputs']['checked']['caption'] = _t('_adm_form_txt_field_checked_switcher');
  1331. }
  1332. }
  1333. class BxBaseStudioFormsFieldFile extends BxBaseStudioFormsFieldText
  1334. {
  1335. protected $sType = 'file';
  1336. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1337. protected $sDbPass = '';
  1338. public function init()
  1339. {
  1340. parent::init();
  1341. unset(
  1342. $this->aForm['inputs']['value'],
  1343. $this->aForm['inputs']['unique']
  1344. );
  1345. }
  1346. }
  1347. class BxBaseStudioFormsFieldFiles extends BxBaseStudioFormsFieldFile
  1348. {
  1349. protected $sType = 'files';
  1350. public function init()
  1351. {
  1352. parent::init();
  1353. $aFields = array(
  1354. 'values' => array(
  1355. 'type' => 'hidden',
  1356. 'name' => 'values',
  1357. 'value' => array(),
  1358. 'db' => array (
  1359. 'pass' => 'Xss',
  1360. )
  1361. ),
  1362. 'value' => array(
  1363. 'type' => 'checkbox_set',
  1364. 'name' => 'value',
  1365. 'caption' => _t('_adm_form_txt_field_value_files'),
  1366. 'info' => '',
  1367. 'value' => array(),
  1368. 'values' => array(),
  1369. 'required' => '0',
  1370. 'db' => array (
  1371. 'pass' => 'Xss',
  1372. )
  1373. )
  1374. );
  1375. $aUploaders = array(
  1376. 'sys_simple' => '_sys_uploader_simple_title',
  1377. 'sys_html5' => '_sys_uploader_html5_title'
  1378. );
  1379. foreach($aUploaders as $sObject => $sTitle) {
  1380. $aUploader = BxDolUploaderQuery::getUploaderObject($sObject);
  1381. if(empty($aUploader) || !is_array($aUploader) || (int)$aUploader['active'] == 0)
  1382. continue;
  1383. $aFields['values']['value'][$sObject] = $sTitle;
  1384. $aFields['value']['values'][$sObject] = _t($sTitle);
  1385. }
  1386. $aFields['values']['value'] = !empty($aFields['values']['value']) && is_array($aFields['values']['value']) ? serialize($aFields['values']['value']) : '';
  1387. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'required', $aFields);
  1388. }
  1389. protected function onSubmitField(&$oForm)
  1390. {
  1391. //--- Process field value.
  1392. if(isset($oForm->aInputs['value']['db']))
  1393. $this->onSubmitFieldValue($oForm);
  1394. parent::onSubmitField($oForm);
  1395. }
  1396. protected function onSubmitFieldValue(&$oForm)
  1397. {
  1398. $mixedValue = $oForm->getCleanValue('value');
  1399. if(is_array($mixedValue))
  1400. BxDolForm::setSubmittedValue('value', serialize($mixedValue), $oForm->aFormAttrs['method']);
  1401. }
  1402. /*
  1403. * Note. Value of Values should be saved as is in case of 'Files' field.
  1404. */
  1405. protected function onSubmitFieldValues(&$oForm)
  1406. {
  1407. return;
  1408. }
  1409. }
  1410. class BxBaseStudioFormsFieldNumber extends BxBaseStudioFormsFieldText
  1411. {
  1412. protected $sType = 'number';
  1413. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1414. protected $sDbPass = 'Int';
  1415. public function init()
  1416. {
  1417. parent::init();
  1418. $this->aParams['table_field_type'] = 'int(11)';
  1419. $this->aForm['inputs']['value']['db']['pass'] = 'Int';
  1420. $this->aForm['inputs']['value']['checker'] = array (
  1421. 'func' => 'preg',
  1422. 'params' => array('/^\d*?$/'),
  1423. 'error' => _t('_adm_form_err_field_value_number'),
  1424. );
  1425. }
  1426. }
  1427. class BxBaseStudioFormsFieldNestedForm extends BxBaseStudioFormsField
  1428. {
  1429. protected $sType = 'nested_form';
  1430. public function init()
  1431. {
  1432. parent::init();
  1433. $aFormsData = array();
  1434. $aParams = array('type' => 'nested', 'parent_form' => $this->aParams['object']);
  1435. if (bx_get('ids'))
  1436. $aParams['ids'] = implode(',', bx_get('ids'));
  1437. $this->oDb->getForms($aParams, $aFormsData, false);
  1438. foreach($aFormsData as $sKey => $sValue){
  1439. $aFormsData[$sKey] = _t($sValue);
  1440. }
  1441. $this->aForm = array(
  1442. 'form_attrs' => array(
  1443. 'id' => '',
  1444. 'action' => '',
  1445. 'method' => 'post'
  1446. ),
  1447. 'params' => array (
  1448. 'db' => array(
  1449. 'table' => 'sys_form_inputs',
  1450. 'key' => 'id',
  1451. 'uri' => '',
  1452. 'uri_title' => '',
  1453. 'submit_name' => 'do_submit'
  1454. ),
  1455. ),
  1456. 'inputs' => array (
  1457. 'module' => array(
  1458. 'type' => 'hidden',
  1459. 'name' => 'module',
  1460. 'caption' => _t('_adm_form_txt_field_module'),
  1461. 'value' => 'custom',
  1462. 'db' => array (
  1463. 'pass' => 'Xss',
  1464. ),
  1465. ),
  1466. 'object' => array(
  1467. 'type' => 'hidden',
  1468. 'name' => 'object',
  1469. 'caption' => _t('_adm_form_txt_field_object'),
  1470. 'value' => '',
  1471. 'db' => array (
  1472. 'pass' => 'Xss',
  1473. ),
  1474. ),
  1475. 'name' => array(
  1476. 'type' => 'hidden',
  1477. 'name' => 'name',
  1478. 'caption' => _t('_adm_form_txt_field_name'),
  1479. 'value' => '',
  1480. 'db' => array (
  1481. 'pass' => 'Xss',
  1482. )
  1483. ),
  1484. 'type' => array(
  1485. 'type' => 'hidden',
  1486. 'name' => 'type',
  1487. 'value' => $this->sType,
  1488. 'db' => array (
  1489. 'pass' => 'Xss',
  1490. )
  1491. ),
  1492. 'db_pass' => array(
  1493. 'type' => 'hidden',
  1494. 'name' => 'db_pass',
  1495. 'value' => $this->sDbPass,
  1496. 'db' => array (
  1497. 'pass' => 'Xss',
  1498. )
  1499. ),
  1500. 'type_display' => $this->getFieldTypesSelector('type_display', $this->sType),
  1501. 'caption_system' => array(
  1502. 'type' => 'text_translatable',
  1503. 'name' => 'caption_system',
  1504. 'caption' => _t('_adm_form_txt_field_caption_system'),
  1505. 'info' => _t('_adm_form_dsc_field_caption_system'),
  1506. 'value' => '_sys_form_txt_field',
  1507. 'required' => '0',
  1508. 'db' => array (
  1509. 'pass' => 'Xss',
  1510. ),
  1511. ),
  1512. 'caption' => array(
  1513. 'type' => 'text_translatable',
  1514. 'name' => 'caption',
  1515. 'caption' => _t('_adm_form_txt_field_caption'),
  1516. 'info' => _t('_adm_form_dsc_field_caption_block_header'),
  1517. 'value' => '_sys_form_txt_field',
  1518. 'required' => '1',
  1519. 'db' => array (
  1520. 'pass' => 'Xss',
  1521. ),
  1522. 'checker' => array (
  1523. 'func' => 'LengthTranslatable',
  1524. 'params' => array(3, 100, 'caption'),
  1525. 'error' => _t('_adm_form_err_field_caption'),
  1526. ),
  1527. ),
  1528. 'value' => array(
  1529. 'type' => 'select',
  1530. 'name' => 'value',
  1531. 'caption' => _t('_adm_form_txt_field_select_nested_form'),
  1532. 'values' => $aFormsData,
  1533. 'required' => '1',
  1534. 'db' => array (
  1535. 'pass' => 'Xss',
  1536. ),
  1537. 'checker' => array (
  1538. 'func' => 'avail',
  1539. 'error' => _t('_adm_form_err_field_select_nested_form'),
  1540. ),
  1541. ),
  1542. 'privacy' => array(
  1543. 'type' => 'switcher',
  1544. 'name' => 'privacy',
  1545. 'caption' => _t('_adm_form_txt_field_privacy'),
  1546. 'info' => _t('_adm_form_dsc_field_privacy'),
  1547. 'value' => '1',
  1548. 'required' => '0',
  1549. 'attrs' => array(
  1550. 'id' => 'bx-form-field-privacy'
  1551. ),
  1552. 'db' => array (
  1553. 'pass' => 'Int',
  1554. )
  1555. ),
  1556. 'rateable' => array(
  1557. 'type' => 'select',
  1558. 'name' => 'rateable',
  1559. 'caption' => _t('_adm_form_txt_field_rateable'),
  1560. 'info' => _t('_adm_form_dsc_field_rateable'),
  1561. 'values' => array(
  1562. array('key' => '', 'value' => _t('_adm_form_txt_field_rateable_value_non')),
  1563. array('key' => 'sys_form_fields_votes', 'value' => _t('_adm_form_txt_field_rateable_value_votes')),
  1564. array('key' => 'sys_form_fields_reaction', 'value' => _t('_adm_form_txt_field_rateable_value_reactions'))
  1565. ),
  1566. 'required' => '0',
  1567. 'attrs' => array(
  1568. 'id' => 'bx-form-field-rateable'
  1569. ),
  1570. 'db' => array (
  1571. 'pass' => 'Xss',
  1572. )
  1573. ),
  1574. 'controls' => array(
  1575. 'name' => 'controls',
  1576. 'type' => 'input_set',
  1577. array(
  1578. 'type' => 'submit',
  1579. 'name' => 'do_submit',
  1580. 'value' => _t('_adm_form_btn_field_add'),
  1581. ),
  1582. array (
  1583. 'type' => 'reset',
  1584. 'name' => 'close',
  1585. 'value' => _t('_adm_form_btn_field_cancel'),
  1586. 'attrs' => array(
  1587. 'onclick' => "$('.bx-popup-applied:visible').dolPopupHide()",
  1588. 'class' => 'bx-def-margin-sec-left',
  1589. ),
  1590. )
  1591. )
  1592. )
  1593. );
  1594. }
  1595. }
  1596. class BxBaseStudioFormsFieldTime extends BxBaseStudioFormsFieldText
  1597. {
  1598. protected $sType = 'time';
  1599. protected $aCheckFunctions = array('avail');
  1600. protected $sDbPass = 'Xss';
  1601. public function init()
  1602. {
  1603. parent::init();
  1604. $this->aParams['table_field_type'] = 'time';
  1605. $this->aForm['inputs']['value']['db']['pass'] = 'Xss';
  1606. }
  1607. }
  1608. class BxBaseStudioFormsFieldSlider extends BxBaseStudioFormsFieldNumber
  1609. {
  1610. protected $sType = 'slider';
  1611. protected $aCheckFunctions = array('avail', 'length');
  1612. public function init()
  1613. {
  1614. parent::init();
  1615. $aFields = array(
  1616. 'attrs' => array(
  1617. 'type' => 'hidden',
  1618. 'name' => 'attrs',
  1619. 'value' => '',
  1620. 'db' => array (
  1621. 'pass' => 'Xss',
  1622. ),
  1623. ),
  1624. 'attrs_min' => array(
  1625. 'type' => 'text',
  1626. 'name' => 'attrs_min',
  1627. 'caption' => _t('_adm_form_txt_field_attrs_min'),
  1628. 'info' => _t('_adm_form_dsc_field_attrs_min'),
  1629. 'value' => '1',
  1630. 'required' => '0',
  1631. 'db' => array (
  1632. 'pass' => 'Int',
  1633. )
  1634. ),
  1635. 'attrs_max' => array(
  1636. 'type' => 'text',
  1637. 'name' => 'attrs_max',
  1638. 'caption' => _t('_adm_form_txt_field_attrs_max'),
  1639. 'info' => _t('_adm_form_dsc_field_attrs_max'),
  1640. 'value' => '100',
  1641. 'required' => '0',
  1642. 'db' => array (
  1643. 'pass' => 'Int',
  1644. )
  1645. ),
  1646. 'attrs_step' => array(
  1647. 'type' => 'text',
  1648. 'name' => 'attrs_step',
  1649. 'caption' => _t('_adm_form_txt_field_attrs_step'),
  1650. 'info' => _t('_adm_form_dsc_field_attrs_step'),
  1651. 'value' => '1',
  1652. 'required' => '0',
  1653. 'db' => array (
  1654. 'pass' => 'Int',
  1655. )
  1656. ),
  1657. );
  1658. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'value', $aFields);
  1659. unset($this->aForm['inputs']['unique']);
  1660. }
  1661. }
  1662. class BxBaseStudioFormsFieldDoublerange extends BxBaseStudioFormsFieldSlider
  1663. {
  1664. protected $sType = 'doublerange';
  1665. protected $aCheckFunctions = array('avail', 'length');
  1666. protected $sDbPass = 'Xss';
  1667. public function init()
  1668. {
  1669. parent::init();
  1670. $this->aParams['table_field_type'] = 'varchar(255)';
  1671. $this->aForm['inputs']['value']['db']['pass'] = 'Xss';
  1672. $this->aForm['inputs']['value']['checker'] = array (
  1673. 'func' => 'preg',
  1674. 'params' => array('/^(\d+-\d+)?$/'),
  1675. 'error' => _t('_adm_form_err_field_value_doublerange'),
  1676. );
  1677. }
  1678. }
  1679. class BxBaseStudioFormsFieldHidden extends BxBaseStudioFormsFieldText
  1680. {
  1681. protected $sType = 'hidden';
  1682. protected $aCheckFunctions = array('avail', 'length', 'preg', 'date', 'date_time', 'email');
  1683. protected $sDbPass = '';
  1684. public function init()
  1685. {
  1686. parent::init();
  1687. unset(
  1688. $this->aForm['inputs']['caption'],
  1689. $this->aForm['inputs']['info'],
  1690. $this->aForm['inputs']['required'],
  1691. $this->aForm['inputs']['unique'],
  1692. $this->aForm['inputs']['checker_func'],
  1693. $this->aForm['inputs']['checker_params'],
  1694. $this->aForm['inputs']['checker_params_length_min'],
  1695. $this->aForm['inputs']['checker_params_length_max'],
  1696. $this->aForm['inputs']['checker_params_required'],
  1697. $this->aForm['inputs']['checker_params_preg'],
  1698. $this->aForm['inputs']['checker_error']
  1699. );
  1700. }
  1701. }
  1702. class BxBaseStudioFormsFieldButton extends BxBaseStudioFormsFieldText
  1703. {
  1704. protected $sType = 'button';
  1705. protected $sDbPass = '';
  1706. public function init()
  1707. {
  1708. parent::init();
  1709. $this->aParams['table_alter'] = false;
  1710. $this->aForm['inputs']['value']['type'] = 'text_translatable';
  1711. $this->aForm['inputs']['value']['caption'] = _t('_adm_form_txt_field_value_button');
  1712. $this->aForm['inputs']['value']['info'] = _t('_adm_form_dsc_field_value_button');
  1713. $this->aForm['inputs']['value']['value'] = '_sys_form_txt_field';
  1714. unset(
  1715. $this->aForm['inputs']['caption'],
  1716. $this->aForm['inputs']['info'],
  1717. $this->aForm['inputs']['required'],
  1718. $this->aForm['inputs']['unique'],
  1719. $this->aForm['inputs']['checker_func'],
  1720. $this->aForm['inputs']['checker_params'],
  1721. $this->aForm['inputs']['checker_params_length_min'],
  1722. $this->aForm['inputs']['checker_params_length_max'],
  1723. $this->aForm['inputs']['checker_params_required'],
  1724. $this->aForm['inputs']['checker_params_preg'],
  1725. $this->aForm['inputs']['checker_error']
  1726. );
  1727. }
  1728. }
  1729. class BxBaseStudioFormsFieldReset extends BxBaseStudioFormsFieldButton
  1730. {
  1731. protected $sType = 'reset';
  1732. public function init()
  1733. {
  1734. parent::init();
  1735. $this->aForm['inputs']['value']['info'] = _t('_adm_form_dsc_field_value_reset');
  1736. }
  1737. }
  1738. class BxBaseStudioFormsFieldSubmit extends BxBaseStudioFormsFieldButton
  1739. {
  1740. protected $sType = 'submit';
  1741. public function init()
  1742. {
  1743. parent::init();
  1744. $this->aForm['inputs']['value']['info'] = _t('_adm_form_dsc_field_value_submit');
  1745. }
  1746. }
  1747. class BxBaseStudioFormsFieldImage extends BxBaseStudioFormsFieldButton
  1748. {
  1749. protected $sType = 'image';
  1750. public function init()
  1751. {
  1752. parent::init();
  1753. $aFields = array(
  1754. 'attrs' => array(
  1755. 'type' => 'hidden',
  1756. 'name' => 'attrs',
  1757. 'value' => '',
  1758. 'db' => array (
  1759. 'pass' => 'Xss',
  1760. ),
  1761. ),
  1762. 'attrs_src' => array(
  1763. 'type' => 'text',
  1764. 'name' => 'attrs_src',
  1765. 'caption' => _t('_adm_form_txt_field_attrs_src'),
  1766. 'info' => _t('_adm_form_dsc_field_attrs_src'),
  1767. 'value' => '',
  1768. 'required' => '0',
  1769. 'db' => array (
  1770. 'pass' => 'Xss',
  1771. )
  1772. ),
  1773. );
  1774. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'value', $aFields);
  1775. unset(
  1776. $this->aForm['inputs']['value']
  1777. );
  1778. }
  1779. }
  1780. class BxBaseStudioFormsFieldSelect extends BxBaseStudioFormsFieldText
  1781. {
  1782. protected $sType = 'select';
  1783. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1784. public function init()
  1785. {
  1786. parent::init();
  1787. $this->aForm['inputs']['value']['type'] = 'select';
  1788. $this->aForm['inputs']['value']['values'] = array(
  1789. array('key' => '', 'value' => _t('_adm_form_txt_field_value_select_value'))
  1790. );
  1791. $this->aForm['inputs']['value']['attrs'] = array(
  1792. 'id' => 'adm-form-field-add-value'
  1793. );
  1794. $aFields = array(
  1795. 'values' => array(
  1796. 'type' => 'select',
  1797. 'name' => 'values',
  1798. 'caption' => _t('_adm_form_txt_field_values'),
  1799. 'info' => '',
  1800. 'value' => '',
  1801. 'values' => array(
  1802. array('key' => '', 'value' => _t('_adm_form_txt_field_values_select_list'))
  1803. ),
  1804. 'required' => '1',
  1805. 'attrs' => array(
  1806. 'onChange' => $this->getJsObject() . ".onChangeValues(0, this)"
  1807. ),
  1808. 'db' => array (
  1809. 'pass' => 'Xss',
  1810. ),
  1811. 'checker' => array (
  1812. 'func' => 'avail',
  1813. 'params' => array(),
  1814. 'error' => _t('_adm_form_err_field_values'),
  1815. ),
  1816. )
  1817. );
  1818. $aLists = array();
  1819. $this->oDb->getLists(array('type' => 'all'), $aLists, false);
  1820. foreach($aLists as $aList)
  1821. $aFields['values']['values'][] = array('key' => BX_DATA_LISTS_KEY_PREFIX . $aList['key'], 'value' => _t($aList['title']));
  1822. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'caption', $aFields);
  1823. unset($this->aForm['inputs']['unique']);
  1824. }
  1825. }
  1826. class BxBaseStudioFormsFieldRadioSet extends BxBaseStudioFormsFieldSelect
  1827. {
  1828. protected $sType = 'radio_set';
  1829. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1830. }
  1831. class BxBaseStudioFormsFieldSelectMultiple extends BxBaseStudioFormsFieldSelect
  1832. {
  1833. protected $sType = 'select_multiple';
  1834. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1835. protected $sDbPass = 'Set';
  1836. public function init()
  1837. {
  1838. parent::init();
  1839. $this->aParams['table_field_type'] = 'bigint(20)';
  1840. $this->aForm['inputs']['value']['type'] = 'select_multiple';
  1841. $this->aForm['inputs']['value']['values'] = array();
  1842. $this->aForm['inputs']['value']['db']['pass'] = 'Set';
  1843. $this->aForm['inputs']['values']['values'] = array(
  1844. array('key' => '', 'value' => _t('_adm_form_txt_field_values_select_list'))
  1845. );
  1846. $this->aForm['inputs']['values']['attrs']['onChange'] = $this->getJsObject() . ".onChangeValues(1, this)";
  1847. $aLists = array();
  1848. $this->oDb->getLists(array('type' => 'all_for_sets'), $aLists, false);
  1849. foreach($aLists as $aList)
  1850. $this->aForm['inputs']['values']['values'][] = array('key' => BX_DATA_LISTS_KEY_PREFIX . $aList['key'], 'value' => _t($aList['title']));
  1851. }
  1852. }
  1853. class BxBaseStudioFormsFieldCheckboxSet extends BxBaseStudioFormsFieldSelectMultiple
  1854. {
  1855. protected $sType = 'checkbox_set';
  1856. protected $aCheckFunctions = array('avail', 'length', 'preg');
  1857. }
  1858. class BxBaseStudioFormsFieldCustom extends BxBaseStudioFormsFieldText
  1859. {
  1860. protected $sType = 'custom';
  1861. protected $sDbPass = '';
  1862. public function init()
  1863. {
  1864. parent::init();
  1865. unset(
  1866. $this->aForm['inputs']['required'],
  1867. $this->aForm['inputs']['unique'],
  1868. $this->aForm['inputs']['checker_func'],
  1869. $this->aForm['inputs']['checker_params'],
  1870. $this->aForm['inputs']['checker_params_length_min'],
  1871. $this->aForm['inputs']['checker_params_length_max'],
  1872. $this->aForm['inputs']['checker_params_required'],
  1873. $this->aForm['inputs']['checker_params_preg'],
  1874. $this->aForm['inputs']['checker_error']
  1875. );
  1876. }
  1877. }
  1878. class BxBaseStudioFormsFieldInputSet extends BxBaseStudioFormsFieldCustom
  1879. {
  1880. protected $sType = 'input_set';
  1881. public function init()
  1882. {
  1883. parent::init();
  1884. $this->aParams['table_alter'] = false;
  1885. $aFields = array(
  1886. 'values' => array(
  1887. 'type' => 'value',
  1888. 'name' => 'values',
  1889. 'caption' => _t('_adm_form_txt_field_values'),
  1890. 'value' => ''
  1891. )
  1892. );
  1893. $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'value', $aFields);
  1894. unset(
  1895. $this->aForm['inputs']['value']
  1896. );
  1897. }
  1898. }
  1899. class BxBaseStudioFormsFieldCaptcha extends BxBaseStudioFormsFieldText
  1900. {
  1901. protected $sType = 'captcha';
  1902. protected $aCheckFunctions = array('captcha');
  1903. protected $sDbPass = '';
  1904. public function init()
  1905. {
  1906. parent::init();
  1907. $this->aParams['table_alter'] = false;
  1908. $this->aForm['inputs']['required'] = array(
  1909. 'type' => 'hidden',
  1910. 'name' => 'required',
  1911. 'value' => '1',
  1912. 'db' => array (
  1913. 'pass' => 'Int',
  1914. )
  1915. );
  1916. $this->aForm['inputs']['checker_func']['type'] = 'hidden';
  1917. $this->aForm['inputs']['checker_func']['value'] = 'captcha';
  1918. $this->aForm['inputs']['checker_error']['info'] = _t('_adm_form_dsc_field_checker_error_captcha');
  1919. unset(
  1920. $this->aForm['inputs']['value'],
  1921. $this->aForm['inputs']['unique'],
  1922. $this->aForm['inputs']['checker_func']['tr_attrs']['style'], $this->aForm['inputs']['checker_error']['tr_attrs']['style'],
  1923. $this->aForm['inputs']['checker_func']['attrs']['disabled'], $this->aForm['inputs']['checker_error']['attrs']['disabled']
  1924. );
  1925. }
  1926. }
  1927. class BxBaseStudioFormsFieldLocation extends BxBaseStudioFormsFieldText
  1928. {
  1929. protected $sType = 'location';
  1930. protected $aCheckFunctions = array('location');
  1931. protected $sDbPass = '';
  1932. public function init()
  1933. {
  1934. parent::init();
  1935. $this->aParams['table_alter'] = false;
  1936. unset(
  1937. $this->aForm['inputs']['unique']
  1938. );
  1939. }
  1940. }
  1941. /** @} */