BxBaseModGeneralFormEntry.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplFormView');
  12. /**
  13. * Create/edit entry form
  14. */
  15. class BxBaseModGeneralFormEntry extends BxTemplFormView
  16. {
  17. protected $MODULE;
  18. protected $_oModule;
  19. public function __construct($aInfo, $oTemplate = false)
  20. {
  21. parent::__construct($aInfo, $oTemplate);
  22. $this->_oModule = BxDolModule::getInstance($this->MODULE);
  23. }
  24. public function insert ($aValsToAdd = array(), $isIgnore = false)
  25. {
  26. $CNF = &$this->_oModule->_oConfig->CNF;
  27. if (isset($CNF['FIELD_AUTHOR']) && empty($aValsToAdd[$CNF['FIELD_AUTHOR']]))
  28. $aValsToAdd[$CNF['FIELD_AUTHOR']] = bx_get_logged_profile_id ();
  29. if (isset($CNF['FIELD_ADDED']) && empty($aValsToAdd[$CNF['FIELD_ADDED']]))
  30. $aValsToAdd[$CNF['FIELD_ADDED']] = time();
  31. if (isset($CNF['FIELD_CHANGED']) && empty($aValsToAdd[$CNF['FIELD_CHANGED']]))
  32. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  33. return parent::insert ($aValsToAdd, $isIgnore);
  34. }
  35. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  36. {
  37. $CNF = &$this->_oModule->_oConfig->CNF;
  38. if (isset($CNF['FIELD_CHANGED']))
  39. $aValsToAdd[$CNF['FIELD_CHANGED']] = time();
  40. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  41. }
  42. protected function genCustomInputLocation ($aInput)
  43. {
  44. $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
  45. $this->oTemplate->addJs($sProto . '://maps.google.com/maps/api/js?sensor=false');
  46. $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  47. $aVars = array (
  48. 'name' => $aInput['name'],
  49. 'id_status' => $this->getInputId($aInput) . '_status',
  50. 'location_string' => _t('_sys_location_undefined'),
  51. );
  52. $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip');
  53. foreach ($aLocationIndexes as $sKey)
  54. $aVars[$sKey] = $this->getLoctionVal($aInput, $sKey);
  55. if ($aVars['country']) {
  56. $aCountries = BxDolFormQuery::getDataItems('Country');
  57. $aVars['location_string'] = ($aVars['city'] ? $aVars['city'] . ', ' : '') . $aCountries[$aVars['country']];
  58. }
  59. if ($this->getLoctionVal($aInput, 'lat') && $this->getLoctionVal($aInput, 'lng'))
  60. $aInput['checked'] = true;
  61. $aVars['input'] = $this->genInputSwitcher($aInput);
  62. return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
  63. }
  64. protected function getLoctionVal ($aInput, $sIndex)
  65. {
  66. $s = $aInput['name'] . '_' . $sIndex;
  67. if (isset($this->_aSpecificValues[$s]))
  68. return $this->_aSpecificValues[$s];
  69. return $this->getCleanValue($s);
  70. }
  71. function addCssJs ()
  72. {
  73. if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {
  74. if (self::$_isCssJsAdded)
  75. return;
  76. $this->_oModule->_oTemplate->addCss('forms.css');
  77. }
  78. return parent::addCssJs ();
  79. }
  80. }
  81. /** @} */