User.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ 1Qeh3xzMW2NC6NPKe63pm407X7W6ifuoOD53vDSNyZk=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.02]
  11. */
  12. /**
  13. * we have the following sub-forms:
  14. *
  15. * basic - username, password, email address
  16. * advanced - date of birth, custom fields
  17. * address - address related fields (address book table)
  18. * user - user account details (gateway settings, bank details, etc)
  19. */
  20. namespace Ppb\Model\Elements;
  21. use Cube\Validate,
  22. Cube\Controller\Front,
  23. Ppb\Db\Table\Row\User as UserModel,
  24. Ppb\Db\Table,
  25. Ppb\Service\Users as UsersService,
  26. Ppb\Service\Table\PaymentGateways as PaymentGatewaysService,
  27. Ppb\Service\Table\StoresSubscriptions as StoresSubscriptionsService;
  28. class User extends AbstractElements
  29. {
  30. /**
  31. *
  32. * form id
  33. *
  34. * @var array
  35. */
  36. protected $_formId = array();
  37. /**
  38. *
  39. * user object
  40. *
  41. * @var \Ppb\Db\Table\Row\User
  42. */
  43. protected $_user;
  44. /**
  45. *
  46. * class constructor
  47. */
  48. public function __construct($formId = null)
  49. {
  50. parent::__construct();
  51. $this->setUser();
  52. $this->_formId = (array)$formId;
  53. }
  54. /**
  55. *
  56. * get user
  57. *
  58. * @return \Ppb\Db\Table\Row\User
  59. */
  60. public function getUser()
  61. {
  62. return $this->_user;
  63. }
  64. /**
  65. *
  66. * set user
  67. *
  68. * @param \Ppb\Db\Table\Row\User $user
  69. *
  70. * @return \Ppb\Model\Elements\User
  71. */
  72. public function setUser(UserModel $user = null)
  73. {
  74. if ($user === null) {
  75. $user = Front::getInstance()->getBootstrap()->getResource('user');
  76. if (!$user instanceof UserModel) {
  77. $user = null;
  78. }
  79. }
  80. $this->_user = $user;
  81. return $this;
  82. }
  83. /**
  84. *
  85. * get form elements
  86. *
  87. * @return array
  88. */
  89. public function getElements()
  90. {
  91. $settings = $this->getSettings();
  92. $translate = $this->getTranslate();
  93. if (($user = $this->getUser()) instanceof UserModel) {
  94. $userId = $user->getData('id');
  95. $storeActive = $user->getData('store_active');
  96. $isSeller = $user->isSeller();
  97. }
  98. else {
  99. $userId = null;
  100. $storeActive = false;
  101. $isSeller = false;
  102. }
  103. $countries = $this->getLocations()->getMultiOptions();
  104. $states = null;
  105. if ($this->getData('country') !== null) {
  106. $states = $this->getLocations()->getMultiOptions(
  107. $this->getData('country'));
  108. }
  109. $customFields = $this->getCustomFields()->getFields(
  110. array(
  111. 'type' => 'user',
  112. 'active' => 1,
  113. ))->toArray();
  114. /* create validators */
  115. $usernameAlpha = new Validate\Alphanumeric();
  116. $usernameAlpha->setMessage("'%s' contains prohibited characters.");
  117. $usernameNoRecordExists = new Validate\Db\NoRecordExists(array(
  118. 'table' => new Table\Users(),
  119. 'field' => 'username',
  120. ));
  121. $usernameNoRecordExists->setMessage($translate->_("The %s '%value%' is not available."));
  122. $emailNoRecordExists = new Validate\Db\NoRecordExists(array(
  123. 'table' => new Table\Users(),
  124. 'field' => 'email',
  125. ));
  126. $emailNoRecordExists->setMessage($translate->_("The %s '%value%' has already been registered."));
  127. $agreeTermsValidator = new Validate\NotEmpty();
  128. $agreeTermsValidator->setMessage('You must agree to our terms and conditions in order to complete the registration.');
  129. $birthDateValidator = new Validate\LessThan();
  130. $birthDateValidator->setMaxValue(date('Y-m-d', time() - ($settings['min_reg_age'] * 365 * 86400)))
  131. ->setMessage(sprintf($translate->_('You must be at least %s years old in order to be able to register.'),
  132. $settings['min_reg_age']));
  133. $paymentGatewaysService = new PaymentGatewaysService();
  134. $gatewayUserId = ($userId === null) ? true : $userId;
  135. $gateways = $paymentGatewaysService->getData($gatewayUserId, null, true);
  136. $gatewayFields = array();
  137. foreach ($gateways as $gateway) {
  138. $className = '\\Ppb\\Model\\PaymentGateway\\' . $gateway['name'];
  139. if (class_exists($className)) {
  140. /** @var \Ppb\Model\PaymentGateway\AbstractPaymentGateway $gatewayModel */
  141. $gatewayModel = new $className();
  142. foreach ((array)$gatewayModel->getElements() as $element) {
  143. if ($userId && isset($gateway[$element['id']])) {
  144. $element['value'] = $gateway[$element['id']];
  145. }
  146. $gatewayFields[] = $element;
  147. }
  148. }
  149. }
  150. $storesSubscriptions = new StoresSubscriptionsService();
  151. $categoriesSelect = $this->getCategories()->getTable()->select()
  152. ->where('parent_id is null');
  153. if ($userId) {
  154. $categoriesSelect->where('user_id is null OR user_id = ?', $userId);
  155. }
  156. else {
  157. $categoriesSelect->where('user_id is null');
  158. }
  159. $array = array(
  160. array(
  161. 'form_id' => 'global',
  162. 'id' => 'id',
  163. 'element' => 'hidden',
  164. 'bodyCode' => "
  165. <script type=\"text/javascript\">
  166. function checkFormFields() {
  167. if ($('input:radio[name=\"business_account\"]:checked').val() == '1') {
  168. $('input:text[name=\"company_name\"]').closest('.form-group').show();
  169. }
  170. else {
  171. $('input:text[name=\"company_name\"]').val('').closest('.form-group').hide();
  172. }
  173. if ($('input:radio[name=\"quantity_description\"]:checked').val() == '1') {
  174. $('input:text[name=\"quantity_low_stock\"]').closest('.form-group').show();
  175. }
  176. else {
  177. $('input:text[name=\"quantity_low_stock\"]').val('').closest('.form-group').hide();
  178. }
  179. if ($('input:checkbox[name=\"vacation_mode\"]').is(':checked')) {
  180. $('input[name=\"vacation_mode_return_date\"]').closest('.form-group').show();
  181. }
  182. else {
  183. $('input[name=\"vacation_mode_return_date\"]').val('').closest('.form-group').hide();
  184. }
  185. if ($('input:radio[name=\"disable_emails\"]:checked').val() == '1') {
  186. $('[name=\"disable_seller_notifications\"]').closest('.form-group').hide();
  187. $('[name=\"disable_offers_notifications\"]').closest('.form-group').hide();
  188. $('[name=\"disable_messaging_notifications\"]').closest('.form-group').hide();
  189. }
  190. else {
  191. $('[name=\"disable_seller_notifications\"]').closest('.form-group').show();
  192. $('[name=\"disable_offers_notifications\"]').closest('.form-group').show();
  193. $('[name=\"disable_messaging_notifications\"]').closest('.form-group').show();
  194. }
  195. }
  196. $(document).ready(function() {
  197. checkFormFields();
  198. });
  199. $(document).on('change', '.field-changeable', function() {
  200. checkFormFields();
  201. });
  202. </script>"
  203. ),
  204. array(
  205. 'form_id' => 'user',
  206. 'id' => 'business_account',
  207. 'element' => 'radio',
  208. 'label' => $this->_('Account Type'),
  209. 'multiOptions' => array(
  210. 0 => $translate->_('Personal'),
  211. 1 => $translate->_('Business'),
  212. ),
  213. 'attributes' => array(
  214. 'class' => 'field-changeable',
  215. ),
  216. ),
  217. array(
  218. 'form_id' => 'address',
  219. 'id' => 'address_id',
  220. 'element' => 'hidden',
  221. ),
  222. array(
  223. 'form_id' => 'address',
  224. 'subtitle' => $this->_('Address'),
  225. 'id' => 'name',
  226. 'element' => '\\Ppb\\Form\\Element\\FullName',
  227. 'label' => $this->_('Name'),
  228. 'required' => true,
  229. 'description' => $this->_('Enter your full name.'),
  230. 'attributes' => array(
  231. 'class' => 'form-control input-default',
  232. 'placeholder' => array(
  233. 'first' => $translate->_('First Name'),
  234. 'last' => $translate->_('Last Name'),
  235. ),
  236. ),
  237. 'fieldLabels' => array(
  238. 'first' => $translate->_('First Name'),
  239. 'last' => $translate->_('Last Name'),
  240. ),
  241. 'validators' => array(
  242. 'NoHtml',
  243. ),
  244. ),
  245. array(
  246. 'form_id' => 'address',
  247. 'id' => 'address',
  248. 'element' => 'text',
  249. 'label' => $this->_('Address'),
  250. 'required' => true,
  251. 'description' => $this->_('Enter your address.'),
  252. 'attributes' => array(
  253. 'class' => 'form-control input-medium',
  254. ),
  255. ),
  256. array(
  257. 'form_id' => 'address',
  258. 'id' => 'city',
  259. 'element' => 'text',
  260. 'label' => $this->_('City'),
  261. 'required' => true,
  262. 'description' => $this->_('Enter the city you live in.'),
  263. 'attributes' => array(
  264. 'class' => 'form-control input-medium',
  265. ),
  266. ),
  267. array(
  268. 'form_id' => 'address',
  269. 'id' => 'country',
  270. 'element' => 'select',
  271. 'label' => $this->_('Country'),
  272. 'multiOptions' => $countries,
  273. 'required' => true,
  274. 'description' => $this->_('Enter the country you live in.'),
  275. 'attributes' => array(
  276. 'class' => 'form-control input-medium',
  277. ),
  278. 'bodyCode' => "
  279. <script type=\"text/javascript\">
  280. function ChangeState() {
  281. var countryId = $('[name=\"country\"]').val();
  282. $.post(
  283. '" . $this->getView()->url(array('module' => 'app', 'controller' => 'async', 'action' => 'select-location')) . "',
  284. {
  285. id: $('[name=\"country\"]').val(),
  286. name: 'state'
  287. },
  288. function (data) {
  289. var div = $('[name=\"state\"]').closest('div');
  290. $('[name=\"state\"]').remove();
  291. div.prepend(data);
  292. }
  293. );
  294. }
  295. $(document).on('change', '[name=\"country\"]', function() {
  296. ChangeState();
  297. });
  298. </script>"
  299. ),
  300. array(
  301. 'form_id' => 'address',
  302. 'id' => 'state',
  303. 'element' => (count($states) > 0) ? 'select' : 'text',
  304. 'label' => $this->_('State/County'),
  305. 'multiOptions' => $states,
  306. 'required' => true,
  307. 'description' => $this->_('Enter the state/county you live in.'),
  308. 'attributes' => array(
  309. 'class' => 'form-control input-medium',
  310. ),
  311. ),
  312. array(
  313. 'form_id' => 'address',
  314. 'id' => 'zip_code',
  315. 'element' => 'text',
  316. 'label' => $this->_('Zip/Post Code'),
  317. 'required' => true,
  318. 'description' => $this->_('Enter your zip/post code.'),
  319. 'attributes' => array(
  320. 'class' => 'form-control input-medium',
  321. ),
  322. ),
  323. array(
  324. 'form_id' => 'address',
  325. 'id' => 'phone',
  326. 'element' => 'text',
  327. 'label' => $this->_('Phone'),
  328. 'description' => $this->_('Enter your phone number.'),
  329. 'attributes' => array(
  330. 'class' => 'form-control input-medium',
  331. ),
  332. 'required' => true,
  333. 'validators' => array(
  334. 'Phone',
  335. ),
  336. ),
  337. array(
  338. 'form_id' => 'advanced',
  339. 'id' => 'birthdate',
  340. 'element' => ($settings['min_reg_age'] > 0) ? '\\Ppb\\Form\\Element\\DateTime' : false,
  341. 'label' => $this->_('Date of Birth'),
  342. 'description' => $this->_('Enter your birthdate.'),
  343. 'attributes' => array(
  344. 'class' => 'form-control input-medium',
  345. ),
  346. 'required' => true,
  347. 'validators' => array(
  348. $birthDateValidator,
  349. ),
  350. 'customData' => array(
  351. 'formData' => array(
  352. 'format' => '"YYYY-MM-DD"',
  353. 'maxDate' => 'new Date()',
  354. 'useCurrent' => 'false',
  355. 'viewMode' => '"decades"',
  356. ),
  357. ),
  358. ),
  359. array(
  360. 'form_id' => 'user',
  361. 'subtitle' => $this->_('Additional Information'),
  362. 'id' => 'company_name',
  363. 'element' => 'text',
  364. 'label' => $this->_('Company Name'),
  365. 'description' => $this->_('Enter your company\'s name.'),
  366. 'attributes' => array(
  367. 'class' => 'form-control input-medium',
  368. ),
  369. 'required' => ($this->getData('business_account') == 1) ? true : false,
  370. ),
  371. array(
  372. 'form_id' => 'user',
  373. 'id' => 'bank_details',
  374. 'element' => 'textarea',
  375. 'label' => $this->_('Bank Details'),
  376. 'description' => $this->_('Enter your bank account details (optional).'),
  377. 'attributes' => array(
  378. 'rows' => 6,
  379. 'class' => 'form-control',
  380. ),
  381. ),
  382. array(
  383. 'form_id' => 'user',
  384. 'id' => 'sale_invoices_content',
  385. 'element' => 'textarea',
  386. 'label' => $this->_('Sales Invoices Custom Content'),
  387. 'description' => $this->_('Enter any custom content you might want to add on your sale invoices.'),
  388. 'attributes' => array(
  389. 'rows' => 4,
  390. 'class' => 'form-control',
  391. ),
  392. 'validators' => array(
  393. 'NoHtml',
  394. ),
  395. ),
  396. array(
  397. 'form_id' => array('basic', 'admin'),
  398. 'subtitle' => $this->_('Account Details'),
  399. 'id' => 'username',
  400. 'element' => 'text',
  401. 'label' => $this->_('Username'),
  402. 'description' => $this->_('Choose a username for your account.'),
  403. 'attributes' => array(
  404. 'class' => 'form-control input-medium',
  405. ),
  406. 'required' => true,
  407. 'validators' => array(
  408. $usernameAlpha,
  409. $usernameNoRecordExists,
  410. ),
  411. ),
  412. array(
  413. 'form_id' => 'admin',
  414. 'id' => 'role',
  415. 'element' => 'select',
  416. 'label' => 'Role',
  417. 'description' => $this->_('Choose a role for the account.'),
  418. 'attributes' => array(
  419. 'class' => 'form-control input-medium',
  420. ),
  421. 'multiOptions' => UsersService::getAdminRoles(),
  422. ),
  423. array(
  424. 'form_id' => array('basic', 'admin'),
  425. 'id' => 'email',
  426. 'element' => 'text',
  427. 'label' => $this->_('Email'),
  428. 'description' => $this->_('Enter your email address.'),
  429. 'attributes' => array(
  430. 'class' => 'form-control input-medium',
  431. ),
  432. 'required' => true,
  433. 'validators' => array(
  434. 'Email',
  435. $emailNoRecordExists,
  436. ),
  437. ),
  438. array(
  439. 'form_id' => array('basic', 'admin'),
  440. 'id' => 'password',
  441. 'element' => 'password',
  442. 'label' => $this->_('Password'),
  443. 'description' => $this->_('Create a password for your account.'),
  444. 'suffix' => $this->_('(minimum 6 characters)'),
  445. 'attributes' => array(
  446. 'class' => 'form-control input-medium',
  447. ),
  448. 'required' => true,
  449. 'validators' => array(
  450. array('StringLength', array(6, null)),
  451. ),
  452. ),
  453. array(
  454. 'form_id' => array('basic', 'admin'),
  455. 'id' => 'password_confirm',
  456. 'element' => 'password',
  457. 'label' => $this->_('Confirm Password'),
  458. 'description' => $this->_('Type your password again to confirm.'),
  459. 'attributes' => array(
  460. 'class' => 'form-control input-medium',
  461. ),
  462. ),
  463. array(
  464. 'form_id' => array('basic'),
  465. 'id' => 'recaptcha',
  466. 'element' => ($settings['enable_recaptcha'] && $settings['recaptcha_registration']) ? '\\Ppb\\Form\\Element\\ReCaptcha' : false,
  467. 'label' => 'Captcha Code',
  468. ),
  469. array(
  470. 'form_id' => 'basic',
  471. 'id' => 'newsletter_subscription',
  472. 'element' => 'checkbox',
  473. 'multiOptions' => array(
  474. 1 => $translate->_('Subscribe To Newsletter'),
  475. ),
  476. ),
  477. array(
  478. 'form_id' => 'basic',
  479. 'id' => 'agree_terms',
  480. 'element' => ($settings['enable_registration_terms']) ? 'checkbox' : false,
  481. 'label' => $this->_('Terms and Conditions'),
  482. 'multiOptions' => array(
  483. 1 => sprintf(
  484. $translate->_('I have read and agree to the site\'s '
  485. . '<a href="%s" target="_blank">Terms and Conditions</a> and <a href="%s" target="_blank">Privacy Policy</a>.'),
  486. $this->getView()->url($settings['registration_terms_link']),
  487. $this->getView()->url($settings['registration_privacy_link'])),
  488. ),
  489. 'validators' => array(
  490. $agreeTermsValidator,
  491. ),
  492. ),
  493. /**
  494. * --------------
  495. * STORE SETUP
  496. * --------------
  497. */
  498. array(
  499. 'form_id' => 'store_setup',
  500. 'subtitle' => $this->_('Store Subscription'),
  501. 'id' => 'store_subscription_id',
  502. 'element' => (!$storeActive || $this->getData('store_subscription_id')) ? 'radio' : 'hidden',
  503. 'label' => $this->_('Choose Subscription'),
  504. 'description' => $this->_('Choose a subscription for your store.'),
  505. 'multiOptions' => $storesSubscriptions->getMultiOptions(),
  506. 'required' => (!$storeActive || $this->getData('store_subscription_id')) ? true : false,
  507. 'attributes' => ($storeActive ?
  508. array('onchange' => 'javascript:storeSubscriptionChangeAlert();') : array()),
  509. 'bodyCode' => "
  510. <script type=\"text/javascript\">
  511. function storeSubscriptionChangeAlert() {
  512. bootbox.alert('" . $translate->_('Warning: changing your store subscription type will disable your current active subscription!') . "')
  513. }
  514. </script > ",
  515. ),
  516. array(
  517. 'form_id' => 'store_setup',
  518. 'subtitle' => $this->_('Store Settings'),
  519. 'id' => 'store_name',
  520. 'element' => 'text',
  521. 'label' => $this->_('Store Name'),
  522. 'description' => $this->_('Enter the name of your store.'),
  523. 'required' => true,
  524. 'validators' => array(
  525. 'NoHtml',
  526. array('StringLength', array(null, 255)),
  527. ),
  528. 'attributes' => array(
  529. 'class' => 'form-control input-xlarge',
  530. ),
  531. ),
  532. array(
  533. 'form_id' => 'store_setup',
  534. 'id' => 'store_description',
  535. 'element' => '\\Ppb\\Form\\Element\\Wysiwyg',
  536. 'label' => $this->_('Store Description'),
  537. 'description' => $this->_('Enter a description for your store.'),
  538. 'required' => true,
  539. 'attributes' => array(
  540. 'class' => 'form-control',
  541. ),
  542. ),
  543. array(
  544. 'form_id' => 'store_setup',
  545. 'id' => 'store_logo_path',
  546. 'element' => '\\Ppb\\Form\\Element\\MultiUpload',
  547. 'label' => $this->_('Store Logo'),
  548. 'description' => $this->_('Upload a logo for your store.'),
  549. 'required' => true,
  550. 'customData' => array(
  551. 'buttonText' => $translate->_('Select Logo'),
  552. 'acceptFileTypes' => '/(\.|\/)(gif|jpe?g|png)$/i',
  553. 'formData' => array(
  554. 'fileSizeLimit' => 2000000,
  555. 'uploadLimit' => 1,
  556. ),
  557. ),
  558. ),
  559. array(
  560. 'form_id' => 'store_setup',
  561. 'id' => 'store_category_id',
  562. 'element' => '\\Ppb\\Form\\Element\\Category',
  563. 'label' => $this->_('Store Category'),
  564. 'description' => $this->_('Select a category where your store would be best included in.'),
  565. 'attributes' => array(
  566. 'data-no-refresh' => 'true'
  567. ),
  568. 'required' => true,
  569. ),
  570. array(
  571. 'form_id' => 'store_setup',
  572. 'id' => 'store_meta_description',
  573. 'element' => 'textarea',
  574. 'label' => $this->_('Store Meta Description'),
  575. 'description' => $this->_('(Recommended) This meta description will tell search engine details about your store. '
  576. . 'Your description should be no longer than 155 characters (including spaces).'),
  577. 'validators' => array(
  578. 'NoHtml',
  579. ),
  580. 'attributes' => array(
  581. 'rows' => '4',
  582. 'class' => 'form-control',
  583. ),
  584. ),
  585. array(
  586. 'form_id' => 'store_setup',
  587. 'id' => 'store_categories',
  588. 'subtitle' => $this->_('Custom Categories'),
  589. 'element' => '\\Ppb\\Form\\Element\\ChznSelect',
  590. 'label' => $this->_('Select Categories'),
  591. 'description' => $this->_('Choose which categories you want to use for your store, or leave empty to use the site\'s default categories.'),
  592. 'multiOptions' => $this->getCategories()->getMultiOptions($categoriesSelect),
  593. 'attributes' => array(
  594. 'style' => 'width: 350px;',
  595. 'data-placeholder' => $translate->_('Choose Categories...'),
  596. ),
  597. 'multiple' => true,
  598. ),
  599. /**
  600. * --------------
  601. * STORE PAGES
  602. * --------------
  603. */
  604. array(
  605. 'form_id' => 'store_pages',
  606. 'subtitle' => 'Store Pages',
  607. 'id' => 'store_about',
  608. 'element' => '\\Ppb\\Form\\Element\\Wysiwyg',
  609. 'label' => $this->_('About Page'),
  610. 'description' => $this->_('(optional) Enter content for the store about page.'),
  611. 'attributes' => array(
  612. 'class' => 'form-control',
  613. ),
  614. ),
  615. array(
  616. 'form_id' => 'store_pages',
  617. 'id' => 'store_shipping_information',
  618. 'element' => '\\Ppb\\Form\\Element\\Wysiwyg',
  619. 'label' => $this->_('Shipping Information'),
  620. 'description' => $this->_('(optional) Enter content for the store shipping information page.'),
  621. 'attributes' => array(
  622. 'class' => 'form-control',
  623. ),
  624. ),
  625. array(
  626. 'form_id' => 'store_pages',
  627. 'id' => 'store_company_policies',
  628. 'element' => '\\Ppb\\Form\\Element\\Wysiwyg',
  629. 'label' => $this->_('Company Policies'),
  630. 'description' => $this->_('(optional) Enter content for the store company policies page.'),
  631. 'attributes' => array(
  632. 'class' => 'form-control',
  633. ),
  634. ),
  635. /**
  636. * --------------
  637. * GLOBAL SETTINGS
  638. * --------------
  639. */
  640. array(
  641. 'form_id' => 'global_settings',
  642. 'id' => 'enable_public_questions',
  643. 'element' => ($settings['enable_public_questions']) ? 'checkbox' : false,
  644. 'label' => $this->_('Accept Public Questions'),
  645. 'description' => $this->_('Check the above checkbox to allow site users to post public questions on your listings.'),
  646. 'multiOptions' => array(
  647. 1 => null,
  648. ),
  649. ),
  650. array(
  651. 'form_id' => 'global_settings',
  652. 'id' => 'enable_force_payment',
  653. 'element' => ($settings['enable_force_payment']) ? 'checkbox' : false,
  654. 'label' => $this->_('Enable Force Payment'),
  655. 'multiOptions' => array(
  656. 1 => null,
  657. ),
  658. 'description' => sprintf(
  659. $translate->_('If this option is enabled, sales will automatically cancelled unless marked as paid within %s.'),
  660. $this->_secondsToTime($settings['force_payment_limit'] * 60)),
  661. ),
  662. array(
  663. 'form_id' => 'global_settings',
  664. 'id' => 'quantity_description',
  665. 'element' => ($settings['enable_products']) ? 'radio' : false,
  666. 'label' => $this->_('Products Quantity Display'),
  667. 'multiOptions' => array(
  668. 0 => $translate->_('Numbers'),
  669. 1 => $translate->_('Text (In Stock, Low Stock, Out of Stock)'),
  670. ),
  671. 'attributes' => array(
  672. 'class' => 'field-changeable',
  673. ),
  674. 'description' => $this->_('Select how to display the quantity field for products.'),
  675. ),
  676. array(
  677. 'form_id' => 'global_settings',
  678. 'id' => 'quantity_low_stock',
  679. 'element' => 'text',
  680. 'label' => $this->_('Low Stock Threshold'),
  681. 'description' => $this->_('If the quantity of an item is lower than this value, the "low stock" message will be displayed.'),
  682. 'required' => ($this->getData('quantity_description') == 1) ? true : false,
  683. 'attributes' => array(
  684. 'class' => 'form-control input-mini',
  685. ),
  686. 'validators' => array(
  687. 'Digits',
  688. array('GreaterThan', array(1, true)),
  689. ),
  690. ),
  691. array(
  692. 'form_id' => 'global_settings',
  693. 'id' => 'enable_tax',
  694. 'element' => ($settings['enable_tax_listings']) ? 'checkbox' : false,
  695. 'label' => $this->_('Enable Tax on Listings'),
  696. 'multiOptions' => array(
  697. 1 => null,
  698. ),
  699. 'description' => $this->_('Check the above checkbox if you wish to be able to apply tax for your listings.'),
  700. ),
  701. array(
  702. 'form_id' => 'global_settings',
  703. 'id' => 'tax_type',
  704. 'element' => ($settings['enable_tax_listings']) ? 'select' : false,
  705. 'label' => $this->_('Tax Type'),
  706. 'description' => $this->_('Select the tax that will be applied for your listings.'),
  707. 'multiOptions' => $this->getTaxTypes()->getMultiOptions(),
  708. 'attributes' => array(
  709. 'class' => 'form-control input-large',
  710. ),
  711. ),
  712. array(
  713. 'form_id' => 'global_settings',
  714. 'id' => 'visitors_counter',
  715. 'element' => 'checkbox',
  716. 'label' => $this->_('Visitors Counter'),
  717. 'multiOptions' => array(
  718. 1 => null,
  719. ),
  720. 'description' => $this->_('Check the above checkbox to display the "Item Viewed" box on the listings details pages'),
  721. ),
  722. array(
  723. 'form_id' => 'global_settings',
  724. 'id' => 'listing_watched_by_box',
  725. 'element' => 'checkbox',
  726. 'label' => $this->_('Display "Listing watched by" Box'),
  727. 'multiOptions' => array(
  728. 1 => null,
  729. ),
  730. 'description' => $this->_('Check the above checkbox to display the "Listing watched by" box on the listing details pages.'),
  731. ),
  732. array(
  733. 'form_id' => 'global_settings',
  734. 'id' => 'limit_bids_per_user',
  735. 'element' => ($settings['enable_auctions'] && $settings['enable_limit_bids']) ? 'text' : false,
  736. 'label' => $this->_('Limit Number of Bids / Offers per User'),
  737. 'description' => $this->_('Enter a positive value if you want to limit the number of bids (without proxy bids) and offers a user can make on an auction, '
  738. . 'or leave empty to disable this feature.'),
  739. 'attributes' => array(
  740. 'class' => 'form-control input-mini',
  741. ),
  742. 'validators' => array(
  743. 'Digits',
  744. ),
  745. ),
  746. array(
  747. 'form_id' => 'global_settings',
  748. 'id' => 'show_make_offer_ranges',
  749. 'element' => ($settings['enable_make_offer'] && $settings['show_make_offer_ranges']) ? 'checkbox' : false,
  750. 'label' => $this->_('Show Offer Ranges'),
  751. 'multiOptions' => array(
  752. 1 => null,
  753. ),
  754. 'description' => $this->_('With this option enabled, the accepted offer ranges you set on listings that have "Make Offer" enabled will be displayed.'),
  755. ),
  756. array(
  757. 'form_id' => 'global_settings',
  758. 'id' => 'automatic_digital_downloads',
  759. 'element' => ($settings['digital_downloads_max']) ? 'radio' : false,
  760. 'label' => $this->_('Automatic Download Links Activation'),
  761. 'multiOptions' => array(
  762. 0 => $translate->_('Yes'),
  763. -1 => $translate->_('No'),
  764. ),
  765. 'description' => $this->_('Select if you wish to automatically activate download links when sales are paid for using direct payment methods.<br>'
  766. . 'Links can also be activated manually from the "My Sales" page.'),
  767. ),
  768. array(
  769. 'form_id' => 'global_settings',
  770. 'id' => 'vacation_mode',
  771. 'element' => 'checkbox',
  772. 'label' => $this->_('Vacation Mode'),
  773. 'multiOptions' => array(
  774. 1 => null,
  775. ),
  776. 'attributes' => array(
  777. 'class' => 'field-changeable',
  778. ),
  779. 'description' => $this->_('If the checkbox above is checked, a message will appear on all your listings which will let visitors know that you are currently on vacation.'),
  780. ),
  781. array(
  782. 'form_id' => 'global_settings',
  783. 'id' => 'vacation_mode_return_date',
  784. 'element' => '\\Ppb\\Form\\Element\\DateTime',
  785. 'label' => $this->_('Return Date'),
  786. 'description' => $this->_('(Optional) Enter a vacation return date.'),
  787. 'attributes' => array(
  788. 'class' => 'form-control input-medium',
  789. ),
  790. 'customData' => array(
  791. 'formData' => array(
  792. 'format' => '"YYYY-MM-DD"',
  793. 'minDate' => 'new Date()',
  794. 'useCurrent' => 'false',
  795. 'showClear' => 'true',
  796. ),
  797. ),
  798. ),
  799. /**
  800. * --------------
  801. * EMAIL NOTIFICATIONS
  802. * --------------
  803. */
  804. array(
  805. 'form_id' => 'email_notifications',
  806. 'id' => 'disable_emails',
  807. 'element' => 'radio',
  808. 'label' => $this->_('Email Notifications'),
  809. 'description' => $this->_('Choose whether to receive email notifications from the website.<br>'
  810. . 'Important emails regarding account status and sale/purchase notifications would still be sent.'),
  811. 'attributes' => array(
  812. 'class' => 'field-changeable',
  813. ),
  814. 'multiOptions' => array(
  815. 0 => $translate->_('Enabled'),
  816. 1 => $translate->_('Disabled'),
  817. ),
  818. ),
  819. array(
  820. 'form_id' => 'email_notifications',
  821. 'id' => 'disable_seller_notifications',
  822. 'element' => ($isSeller) ? 'radio' : false,
  823. 'label' => $this->_('Seller Notifications'),
  824. 'description' => $this->_('These notifications include closed, relisted, no sale, '
  825. . 'as well as approved and suspended listings notifications.'),
  826. 'multiOptions' => array(
  827. 0 => $translate->_('Enabled'),
  828. 1 => $translate->_('Disabled'),
  829. ),
  830. ),
  831. array(
  832. 'form_id' => 'email_notifications',
  833. 'id' => 'disable_offers_notifications',
  834. 'element' => ($settings['enable_make_offer']) ? 'radio' : false,
  835. 'label' => $this->_('Offers Notifications'),
  836. 'description' => $this->_('These notifications include offers module related email notifications: '
  837. . 'new offer, counter offer, offer accepted, offer declined, offer withdrawn.'),
  838. 'multiOptions' => array(
  839. 0 => $translate->_('Enabled'),
  840. 1 => $translate->_('Disabled'),
  841. ),
  842. ),
  843. array(
  844. 'form_id' => 'email_notifications',
  845. 'id' => 'disable_messaging_notifications',
  846. 'element' => 'radio',
  847. 'label' => $this->_('Messaging Notifications'),
  848. 'description' => $this->_('These notifications include emails sent to notify users on new messages '
  849. . 'received on the website.'),
  850. 'multiOptions' => array(
  851. 0 => $translate->_('Enabled'),
  852. 1 => $translate->_('Disabled'),
  853. ),
  854. ),
  855. /**
  856. * --------------
  857. * FORGOT USERNAME / PASSWORD FORMS
  858. * --------------
  859. */
  860. array(
  861. 'form_id' => 'forgot-password',
  862. 'id' => 'username',
  863. 'element' => 'text',
  864. 'label' => $this->_('Username'),
  865. 'description' => $this->_('Enter your username.'),
  866. 'attributes' => array(
  867. 'class' => 'form-control input-medium',
  868. ),
  869. 'required' => true,
  870. 'validators' => array(
  871. $usernameAlpha,
  872. ),
  873. ),
  874. array(
  875. 'form_id' => array('forgot-username', 'forgot-password'),
  876. 'id' => 'email',
  877. 'element' => 'text',
  878. 'label' => $this->_('Email'),
  879. 'description' => $this->_('Enter the email address you have used for registering your account.'),
  880. 'attributes' => array(
  881. 'class' => 'form-control input-medium',
  882. ),
  883. 'required' => true,
  884. 'validators' => array(
  885. 'Email',
  886. ),
  887. ),
  888. );
  889. // add custom registration fields
  890. foreach ($customFields as $key => $customField) {
  891. $customFields[$key]['form_id'] = 'advanced';
  892. $customFields[$key]['id'] = 'custom_field_' . $customField['id'];
  893. if (in_array($customField['element'], array('text', 'select', 'textarea'))) {
  894. $attributes = unserialize($customField['attributes']);
  895. $customFields[$key]['attributes'] = serialize($attributes);
  896. }
  897. }
  898. array_splice($array, 10, 0, $customFields);
  899. // add payment gateways related fields (direct payment)
  900. foreach ($gatewayFields as $key => $gatewayField) {
  901. $gatewayFields[$key]['form_id'] = 'payment-gateways';
  902. if (empty($gatewayField)) {
  903. unset($gatewayFields[$key]);
  904. }
  905. }
  906. array_splice($array, (19 + count($customFields)), 0, $gatewayFields);
  907. return $array;
  908. }
  909. protected function _secondsToTime($seconds)
  910. {
  911. $translate = $this->getTranslate();
  912. $output = array();
  913. $date = new \DateTime("@$seconds");
  914. $interval = $date->diff(new \DateTime('@0'));
  915. $days = $interval->d;
  916. $hours = $interval->h;
  917. $minutes = $interval->m;
  918. if ($days > 0) {
  919. $output[] = $days . ' ' . (($days > 1) ? $translate->_('days') : $translate->_('day'));
  920. }
  921. if ($hours > 0) {
  922. $output[] = $hours . ' ' . (($hours > 1) ? $translate->_('hours') : $translate->_('hour'));
  923. }
  924. if ($minutes > 0) {
  925. $output[] = $minutes . ' ' . (($minutes > 1) ? $translate->_('minutes') : $translate->_('minute'));
  926. }
  927. return implode(', ', $output);
  928. }
  929. }