database.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * Plugin database installation script. Can only be executed if included
  5. * inside another script loading global.inc.php.
  6. *
  7. * @package chamilo.plugin.buycourses
  8. */
  9. /**
  10. * Check if script can be called.
  11. */
  12. if (!function_exists('api_get_path')) {
  13. die('This script must be loaded through the Chamilo plugin installer sequence');
  14. }
  15. $entityManager = Database::getManager();
  16. $pluginSchema = new \Doctrine\DBAL\Schema\Schema();
  17. $connection = $entityManager->getConnection();
  18. $platform = $connection->getDatabasePlatform();
  19. //Create tables
  20. $paypalTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_PAYPAL);
  21. $paypalTable->addColumn(
  22. 'id',
  23. \Doctrine\DBAL\Types\Type::INTEGER,
  24. ['autoincrement' => true, 'unsigned' => true]
  25. );
  26. $paypalTable->addColumn('username', \Doctrine\DBAL\Types\Type::STRING);
  27. $paypalTable->addColumn('password', \Doctrine\DBAL\Types\Type::STRING);
  28. $paypalTable->addColumn('signature', \Doctrine\DBAL\Types\Type::STRING);
  29. $paypalTable->addColumn('sandbox', \Doctrine\DBAL\Types\Type::BOOLEAN);
  30. $paypalTable->setPrimaryKey(['id']);
  31. $transferTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_TRANSFER);
  32. $transferTable->addColumn(
  33. 'id',
  34. \Doctrine\DBAL\Types\Type::INTEGER,
  35. ['autoincrement' => true, 'unsigned' => true]
  36. );
  37. $transferTable->addColumn('name', \Doctrine\DBAL\Types\Type::STRING);
  38. $transferTable->addColumn('account', \Doctrine\DBAL\Types\Type::STRING);
  39. $transferTable->addColumn('swift', \Doctrine\DBAL\Types\Type::STRING);
  40. $transferTable->setPrimaryKey(['id']);
  41. $currencyTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_CURRENCY);
  42. $currencyTable->addColumn(
  43. 'id',
  44. \Doctrine\DBAL\Types\Type::INTEGER,
  45. ['autoincrement' => true, 'unsigned' => true]
  46. );
  47. $currencyTable->addColumn(
  48. 'country_code',
  49. \Doctrine\DBAL\Types\Type::STRING,
  50. ['length' => 2]
  51. );
  52. $currencyTable->addColumn(
  53. 'country_name',
  54. \Doctrine\DBAL\Types\Type::STRING,
  55. ['length' => 255]
  56. );
  57. $currencyTable->addColumn(
  58. 'iso_code',
  59. \Doctrine\DBAL\Types\Type::STRING,
  60. ['length' => 3]
  61. );
  62. $currencyTable->addColumn('status', \Doctrine\DBAL\Types\Type::BOOLEAN);
  63. $currencyTable->addUniqueIndex(['country_code']);
  64. $currencyTable->addIndex(['iso_code']);
  65. $currencyTable->setPrimaryKey(['id']);
  66. $itemTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_ITEM);
  67. $itemTable->addColumn(
  68. 'id',
  69. \Doctrine\DBAL\Types\Type::INTEGER,
  70. ['autoincrement' => true, 'unsigned' => true]
  71. );
  72. $itemTable->addColumn('product_type', \Doctrine\DBAL\Types\Type::INTEGER);
  73. $itemTable->addColumn(
  74. 'product_id',
  75. \Doctrine\DBAL\Types\Type::INTEGER,
  76. ['unsigned' => true]
  77. );
  78. $itemTable->addColumn(
  79. 'price',
  80. \Doctrine\DBAL\Types\Type::DECIMAL,
  81. ['scale' => 2]
  82. );
  83. $itemTable->addColumn(
  84. 'currency_id',
  85. \Doctrine\DBAL\Types\Type::INTEGER,
  86. ['unsigned' => true]
  87. );
  88. $itemTable->addColumn(
  89. 'tax_perc',
  90. \Doctrine\DBAL\Types\Type::INTEGER,
  91. ['unsigned' => true, 'notnull' => false]
  92. );
  93. $itemTable->setPrimaryKey(['id']);
  94. $itemTable->addForeignKeyConstraint(
  95. $currencyTable,
  96. ['currency_id'],
  97. ['id'],
  98. ['onDelete' => 'CASCADE']
  99. );
  100. $itemBeneficiary = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_ITEM_BENEFICIARY);
  101. $itemBeneficiary->addColumn(
  102. 'id',
  103. \Doctrine\DBAL\Types\Type::INTEGER,
  104. ['autoincrement' => true, 'unsigned' => true]
  105. );
  106. $itemBeneficiary->addColumn(
  107. 'item_id',
  108. \Doctrine\DBAL\Types\Type::INTEGER,
  109. ['unsigned' => true]
  110. );
  111. $itemBeneficiary->addColumn(
  112. 'user_id',
  113. \Doctrine\DBAL\Types\Type::INTEGER,
  114. ['unsigned' => true]
  115. );
  116. $itemBeneficiary->addColumn(
  117. 'commissions',
  118. \Doctrine\DBAL\Types\Type::INTEGER,
  119. ['unsigned' => true]
  120. );
  121. $itemBeneficiary->setPrimaryKey(['id']);
  122. $itemBeneficiary->addForeignKeyConstraint(
  123. $itemTable,
  124. ['item_id'],
  125. ['id'],
  126. ['onDelete' => 'CASCADE']
  127. );
  128. $commissions = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_COMMISSION);
  129. $commissions->addColumn(
  130. 'id',
  131. \Doctrine\DBAL\Types\Type::INTEGER,
  132. ['autoincrement' => true, 'unsigned' => true]
  133. );
  134. $commissions->addColumn(
  135. 'commission',
  136. \Doctrine\DBAL\Types\Type::INTEGER,
  137. ['unsigned' => true]
  138. );
  139. $commissions->setPrimaryKey(['id']);
  140. $saleCommissions = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_PAYPAL_PAYOUTS);
  141. $saleCommissions->addColumn(
  142. 'id',
  143. \Doctrine\DBAL\Types\Type::INTEGER,
  144. ['autoincrement' => true, 'unsigned' => true]
  145. );
  146. $saleCommissions->addColumn('date', \Doctrine\DBAL\Types\Type::DATETIME);
  147. $saleCommissions->addColumn('payout_date', \Doctrine\DBAL\Types\Type::DATETIME);
  148. $saleCommissions->addColumn(
  149. 'sale_id',
  150. \Doctrine\DBAL\Types\Type::INTEGER,
  151. ['unsigned' => true]
  152. );
  153. $saleCommissions->addColumn(
  154. 'user_id',
  155. \Doctrine\DBAL\Types\Type::INTEGER,
  156. ['unsigned' => true]
  157. );
  158. $saleCommissions->addColumn(
  159. 'commission',
  160. \Doctrine\DBAL\Types\Type::DECIMAL,
  161. ['scale' => 2]
  162. );
  163. $saleCommissions->addColumn(
  164. 'status',
  165. \Doctrine\DBAL\Types\Type::INTEGER,
  166. ['unsigned' => true]
  167. );
  168. $saleCommissions->setPrimaryKey(['id']);
  169. $saleTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SALE);
  170. $saleTable->addColumn(
  171. 'id',
  172. \Doctrine\DBAL\Types\Type::INTEGER,
  173. ['autoincrement' => true, 'unsigned' => true]
  174. );
  175. $saleTable->addColumn('reference', \Doctrine\DBAL\Types\Type::STRING);
  176. $saleTable->addColumn('date', \Doctrine\DBAL\Types\Type::DATETIME);
  177. $saleTable->addColumn(
  178. 'user_id',
  179. \Doctrine\DBAL\Types\Type::INTEGER,
  180. ['unsigned' => true]
  181. );
  182. $saleTable->addColumn('product_type', \Doctrine\DBAL\Types\Type::INTEGER);
  183. $saleTable->addColumn('product_name', \Doctrine\DBAL\Types\Type::STRING);
  184. $saleTable->addColumn(
  185. 'product_id',
  186. \Doctrine\DBAL\Types\Type::INTEGER,
  187. ['unsigned' => true]
  188. );
  189. $saleTable->addColumn(
  190. 'price',
  191. \Doctrine\DBAL\Types\Type::DECIMAL,
  192. ['scale' => 2]
  193. );
  194. $saleTable->addColumn(
  195. 'price_without_tax',
  196. \Doctrine\DBAL\Types\Type::DECIMAL,
  197. ['scale' => 2, 'notnull' => false]
  198. );
  199. $saleTable->addColumn(
  200. 'tax_perc',
  201. \Doctrine\DBAL\Types\Type::INTEGER,
  202. ['unsigned' => true, 'notnull' => false]
  203. );
  204. $saleTable->addColumn(
  205. 'tax_amount',
  206. \Doctrine\DBAL\Types\Type::DECIMAL,
  207. ['scale' => 2, 'notnull' => false]
  208. );
  209. $saleTable->addColumn(
  210. 'currency_id',
  211. \Doctrine\DBAL\Types\Type::INTEGER,
  212. ['unsigned' => true]
  213. );
  214. $saleTable->addColumn('status', \Doctrine\DBAL\Types\Type::INTEGER);
  215. $saleTable->addColumn('payment_type', \Doctrine\DBAL\Types\Type::INTEGER);
  216. $saleTable->addColumn('invoice', \Doctrine\DBAL\Types\Type::INTEGER);
  217. $saleTable->setPrimaryKey(['id']);
  218. $saleTable->addForeignKeyConstraint(
  219. $currencyTable,
  220. ['currency_id'],
  221. ['id'],
  222. ['onDelete' => 'CASCADE']
  223. );
  224. $servicesTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SERVICES);
  225. $servicesTable->addColumn(
  226. 'id',
  227. \Doctrine\DBAL\Types\Type::INTEGER,
  228. ['autoincrement' => true, 'unsigned' => true]
  229. );
  230. $servicesTable->addColumn('name', \Doctrine\DBAL\Types\Type::STRING);
  231. $servicesTable->addColumn('description', \Doctrine\DBAL\Types\Type::TEXT);
  232. $servicesTable->addColumn(
  233. 'price',
  234. \Doctrine\DBAL\Types\Type::DECIMAL,
  235. ['scale' => 2]
  236. );
  237. $servicesTable->addColumn('duration_days', \Doctrine\DBAL\Types\Type::INTEGER);
  238. $servicesTable->addColumn('applies_to', \Doctrine\DBAL\Types\Type::INTEGER);
  239. $servicesTable->addColumn('owner_id', \Doctrine\DBAL\Types\Type::INTEGER);
  240. $servicesTable->addColumn('visibility', \Doctrine\DBAL\Types\Type::INTEGER);
  241. $servicesTable->addColumn('video_url', \Doctrine\DBAL\Types\Type::STRING);
  242. $servicesTable->addColumn('image', \Doctrine\DBAL\Types\Type::STRING);
  243. $servicesTable->addColumn('service_information', \Doctrine\DBAL\Types\Type::TEXT);
  244. $servicesTable->setPrimaryKey(['id']);
  245. $servicesNodeTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SERVICES_SALE);
  246. $servicesNodeTable->addColumn(
  247. 'id',
  248. \Doctrine\DBAL\Types\Type::INTEGER,
  249. ['autoincrement' => true, 'unsigned' => true]
  250. );
  251. $servicesNodeTable->addColumn(
  252. 'service_id',
  253. \Doctrine\DBAL\Types\Type::INTEGER,
  254. ['unsigned' => true]
  255. );
  256. $servicesNodeTable->addColumn('reference', \Doctrine\DBAL\Types\Type::STRING);
  257. $servicesNodeTable->addColumn('currency_id', \Doctrine\DBAL\Types\Type::INTEGER);
  258. $servicesNodeTable->addColumn(
  259. 'price',
  260. \Doctrine\DBAL\Types\Type::DECIMAL,
  261. ['scale' => 2]
  262. );
  263. $servicesNodeTable->addColumn(
  264. 'price_without_tax',
  265. \Doctrine\DBAL\Types\Type::DECIMAL,
  266. ['scale' => 2, 'notnull' => false]
  267. );
  268. $servicesNodeTable->addColumn(
  269. 'tax_perc',
  270. \Doctrine\DBAL\Types\Type::INTEGER,
  271. ['unsigned' => true, 'notnull' => false]
  272. );
  273. $servicesNodeTable->addColumn(
  274. 'tax_amount',
  275. \Doctrine\DBAL\Types\Type::DECIMAL,
  276. ['scale' => 2, 'notnull' => false]
  277. );
  278. $servicesNodeTable->addColumn('node_type', \Doctrine\DBAL\Types\Type::INTEGER);
  279. $servicesNodeTable->addColumn('node_id', \Doctrine\DBAL\Types\Type::INTEGER);
  280. $servicesNodeTable->addColumn('buyer_id', \Doctrine\DBAL\Types\Type::INTEGER);
  281. $servicesNodeTable->addColumn('buy_date', \Doctrine\DBAL\Types\Type::DATETIME);
  282. $servicesNodeTable->addColumn(
  283. 'date_start',
  284. \Doctrine\DBAL\Types\Type::DATETIME,
  285. ['notnull' => false]
  286. );
  287. $servicesNodeTable->addColumn(
  288. 'date_end',
  289. \Doctrine\DBAL\Types\Type::DATETIME
  290. );
  291. $servicesNodeTable->addColumn('status', \Doctrine\DBAL\Types\Type::INTEGER);
  292. $servicesNodeTable->addColumn('payment_type', \Doctrine\DBAL\Types\Type::INTEGER);
  293. $servicesNodeTable->addColumn('invoice', \Doctrine\DBAL\Types\Type::INTEGER);
  294. $servicesNodeTable->setPrimaryKey(['id']);
  295. $servicesNodeTable->addForeignKeyConstraint(
  296. $servicesTable,
  297. ['service_id'],
  298. ['id'],
  299. ['onDelete' => 'CASCADE']
  300. );
  301. $culqiTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_CULQI);
  302. $culqiTable->addColumn(
  303. 'id',
  304. \Doctrine\DBAL\Types\Type::INTEGER,
  305. ['autoincrement' => true, 'unsigned' => true]
  306. );
  307. $culqiTable->addColumn('commerce_code', \Doctrine\DBAL\Types\Type::STRING);
  308. $culqiTable->addColumn('api_key', \Doctrine\DBAL\Types\Type::STRING);
  309. $culqiTable->addColumn('integration', \Doctrine\DBAL\Types\Type::INTEGER);
  310. $culqiTable->setPrimaryKey(['id']);
  311. $globalTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_GLOBAL_CONFIG);
  312. $globalTable->addColumn(
  313. 'id',
  314. \Doctrine\DBAL\Types\Type::INTEGER,
  315. ['autoincrement' => true, 'unsigned' => true]
  316. );
  317. $globalTable->addColumn('terms_and_conditions', \Doctrine\DBAL\Types\Type::TEXT);
  318. $globalTable->addColumn('global_tax_perc', \Doctrine\DBAL\Types\Type::INTEGER);
  319. $globalTable->addColumn('tax_applies_to', \Doctrine\DBAL\Types\Type::INTEGER);
  320. $globalTable->addColumn('tax_name', \Doctrine\DBAL\Types\Type::STRING);
  321. $globalTable->addColumn('seller_name', \Doctrine\DBAL\Types\Type::STRING);
  322. $globalTable->addColumn('seller_id', \Doctrine\DBAL\Types\Type::STRING);
  323. $globalTable->addColumn('seller_address', \Doctrine\DBAL\Types\Type::STRING);
  324. $globalTable->addColumn('seller_email', \Doctrine\DBAL\Types\Type::STRING);
  325. $globalTable->addColumn('next_number_invoice', \Doctrine\DBAL\Types\Type::INTEGER);
  326. $globalTable->addColumn('invoice_series', \Doctrine\DBAL\Types\Type::STRING);
  327. $globalTable->addColumn('sale_email', \Doctrine\DBAL\Types\Type::STRING);
  328. $globalTable->setPrimaryKey(['id']);
  329. $invoiceTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_INVOICE);
  330. $invoiceTable->addColumn(
  331. 'id',
  332. \Doctrine\DBAL\Types\Type::INTEGER,
  333. ['autoincrement' => true, 'unsigned' => true]
  334. );
  335. $invoiceTable->addColumn('sale_id', \Doctrine\DBAL\Types\Type::INTEGER);
  336. $invoiceTable->addColumn('is_service', \Doctrine\DBAL\Types\Type::INTEGER);
  337. $invoiceTable->addColumn(
  338. 'num_invoice',
  339. \Doctrine\DBAL\Types\Type::INTEGER,
  340. ['unsigned' => true, 'notnull' => false]
  341. );
  342. $invoiceTable->addColumn(
  343. 'year',
  344. \Doctrine\DBAL\Types\Type::INTEGER,
  345. ['unsigned' => true, 'notnull' => false]
  346. );
  347. $invoiceTable->addColumn('serie', \Doctrine\DBAL\Types\Type::STRING);
  348. $invoiceTable->addColumn('date_invoice', \Doctrine\DBAL\Types\Type::DATETIME);
  349. $invoiceTable->setPrimaryKey(['id']);
  350. $queries = $pluginSchema->toSql($platform);
  351. foreach ($queries as $query) {
  352. Database::query($query);
  353. }
  354. //Insert data
  355. $paypalTable = Database::get_main_table(BuyCoursesPlugin::TABLE_PAYPAL);
  356. $currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
  357. $itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
  358. $saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
  359. $commissionTable = Database::get_main_table(BuyCoursesPlugin::TABLE_COMMISSION);
  360. $extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
  361. $culqiTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CULQI);
  362. $globalTable = Database::get_main_table(BuyCoursesPlugin::TABLE_GLOBAL_CONFIG);
  363. $paypalExtraField = Database::select(
  364. "*",
  365. $extraFieldTable,
  366. [
  367. 'where' => ['variable = ?' => 'paypal'],
  368. ],
  369. 'first'
  370. );
  371. if (!$paypalExtraField) {
  372. Database::insert(
  373. $extraFieldTable,
  374. [
  375. 'extra_field_type' => 1,
  376. 'field_type' => 1,
  377. 'variable' => 'paypal',
  378. 'display_text' => 'Paypal',
  379. 'default_value' => '',
  380. 'field_order' => 0,
  381. 'visible_to_self' => 1,
  382. 'changeable' => 1,
  383. 'filter' => 0,
  384. 'created_at' => api_get_utc_datetime(),
  385. ]
  386. );
  387. }
  388. Database::insert(
  389. $paypalTable,
  390. [
  391. 'username' => '',
  392. 'password' => '',
  393. 'signature' => '',
  394. 'sandbox' => true,
  395. ]
  396. );
  397. Database::insert(
  398. $culqiTable,
  399. [
  400. 'commerce_code' => '',
  401. 'api_key' => '',
  402. 'integration' => 1,
  403. ]
  404. );
  405. Database::insert(
  406. $globalTable,
  407. [
  408. 'terms_and_conditions' => '',
  409. ]
  410. );
  411. Database::insert(
  412. $commissionTable,
  413. [
  414. 'commission' => 0,
  415. ]
  416. );
  417. $currencies = [
  418. ['AD', 'Andorra', 'EUR', 'AND'],
  419. ['AE', 'United Arab Emirates', 'AED', 'ARE'],
  420. ['AF', 'Afghanistan', 'AFN', 'AFG'],
  421. ['AG', 'Antigua and Barbuda', 'XCD', 'ATG'],
  422. ['AI', 'Anguilla', 'XCD', 'AIA'],
  423. ['AL', 'Albania', 'ALL', 'ALB'],
  424. ['AM', 'Armenia', 'AMD', 'ARM'],
  425. ['AO', 'Angola', 'AOA', 'AGO'],
  426. ['AR', 'Argentina', 'ARS', 'ARG'],
  427. ['AS', 'American Samoa', 'USD', 'ASM'],
  428. ['AT', 'Austria', 'EUR', 'AUT'],
  429. ['AU', 'Australia', 'AUD', 'AUS'],
  430. ['AW', 'Aruba', 'AWG', 'ABW'],
  431. ['AX', '&Aring;land', 'EUR', 'ALA'],
  432. ['AZ', 'Azerbaijan', 'AZN', 'AZE'],
  433. ['BA', 'Bosnia and Herzegovina', 'BAM', 'BIH'],
  434. ['BB', 'Barbados', 'BBD', 'BRB'],
  435. ['BD', 'Bangladesh', 'BDT', 'BGD'],
  436. ['BE', 'Belgium', 'EUR', 'BEL'],
  437. ['BF', 'Burkina Faso', 'XOF', 'BFA'],
  438. ['BG', 'Bulgaria', 'BGN', 'BGR'],
  439. ['BH', 'Bahrain', 'BHD', 'BHR'],
  440. ['BI', 'Burundi', 'BIF', 'BDI'],
  441. ['BJ', 'Benin', 'XOF', 'BEN'],
  442. ['BL', 'Saint Barth&eacute;lemy', 'EUR', 'BLM'],
  443. ['BM', 'Bermuda', 'BMD', 'BMU'],
  444. ['BN', 'Brunei', 'BND', 'BRN'],
  445. ['BO', 'Bolivia', 'BOB', 'BOL'],
  446. ['BQ', 'Bonaire', 'USD', 'BES'],
  447. ['BR', 'Brazil', 'BRL', 'BRA'],
  448. ['BS', 'Bahamas', 'BSD', 'BHS'],
  449. ['BT', 'Bhutan', 'BTN', 'BTN'],
  450. ['BV', 'Bouvet Island', 'NOK', 'BVT'],
  451. ['BW', 'Botswana', 'BWP', 'BWA'],
  452. ['BY', 'Belarus', 'BYR', 'BLR'],
  453. ['BZ', 'Belize', 'BZD', 'BLZ'],
  454. ['CA', 'Canada', 'CAD', 'CAN'],
  455. ['CC', 'Cocos [Keeling] Islands', 'AUD', 'CCK'],
  456. ['CD', 'Congo', 'CDF', 'COD'],
  457. ['CF', 'Central African Republic', 'XAF', 'CAF'],
  458. ['CG', 'Republic of the Congo', 'XAF', 'COG'],
  459. ['CH', 'Switzerland', 'CHF', 'CHE'],
  460. ['CI', 'Ivory Coast', 'XOF', 'CIV'],
  461. ['CK', 'Cook Islands', 'NZD', 'COK'],
  462. ['CL', 'Chile', 'CLP', 'CHL'],
  463. ['CM', 'Cameroon', 'XAF', 'CMR'],
  464. ['CN', 'China', 'CNY', 'CHN'],
  465. ['CO', 'Colombia', 'COP', 'COL'],
  466. ['CR', 'Costa Rica', 'CRC', 'CRI'],
  467. ['CU', 'Cuba', 'CUP', 'CUB'],
  468. ['CV', 'Cape Verde', 'CVE', 'CPV'],
  469. ['CW', 'Curacao', 'ANG', 'CUW'],
  470. ['CX', 'Christmas Island', 'AUD', 'CXR'],
  471. ['CY', 'Cyprus', 'EUR', 'CYP'],
  472. ['CZ', 'Czechia', 'CZK', 'CZE'],
  473. ['DE', 'Germany', 'EUR', 'DEU'],
  474. ['DJ', 'Djibouti', 'DJF', 'DJI'],
  475. ['DK', 'Denmark', 'DKK', 'DNK'],
  476. ['DM', 'Dominica', 'XCD', 'DMA'],
  477. ['DO', 'Dominican Republic', 'DOP', 'DOM'],
  478. ['DZ', 'Algeria', 'DZD', 'DZA'],
  479. ['EC', 'Ecuador', 'USD', 'ECU'],
  480. ['EE', 'Estonia', 'EUR', 'EST'],
  481. ['EG', 'Egypt', 'EGP', 'EGY'],
  482. ['EH', 'Western Sahara', 'MAD', 'ESH'],
  483. ['ER', 'Eritrea', 'ERN', 'ERI'],
  484. ['ES', 'Spain', 'EUR', 'ESP'],
  485. ['ET', 'Ethiopia', 'ETB', 'ETH'],
  486. ['FI', 'Finland', 'EUR', 'FIN'],
  487. ['FJ', 'Fiji', 'FJD', 'FJI'],
  488. ['FK', 'Falkland Islands', 'FKP', 'FLK'],
  489. ['FM', 'Micronesia', 'USD', 'FSM'],
  490. ['FO', 'Faroe Islands', 'DKK', 'FRO'],
  491. ['FR', 'France', 'EUR', 'FRA'],
  492. ['GA', 'Gabon', 'XAF', 'GAB'],
  493. ['GB', 'United Kingdom', 'GBP', 'GBR'],
  494. ['GD', 'Grenada', 'XCD', 'GRD'],
  495. ['GE', 'Georgia', 'GEL', 'GEO'],
  496. ['GF', 'French Guiana', 'EUR', 'GUF'],
  497. ['GG', 'Guernsey', 'GBP', 'GGY'],
  498. ['GH', 'Ghana', 'GHS', 'GHA'],
  499. ['GI', 'Gibraltar', 'GIP', 'GIB'],
  500. ['GL', 'Greenland', 'DKK', 'GRL'],
  501. ['GM', 'Gambia', 'GMD', 'GMB'],
  502. ['GN', 'Guinea', 'GNF', 'GIN'],
  503. ['GP', 'Guadeloupe', 'EUR', 'GLP'],
  504. ['GQ', 'Equatorial Guinea', 'XAF', 'GNQ'],
  505. ['GR', 'Greece', 'EUR', 'GRC'],
  506. ['GS', 'South Georgia and the South Sandwich Islands', 'GBP', 'SGS'],
  507. ['GT', 'Guatemala', 'GTQ', 'GTM'],
  508. ['GU', 'Guam', 'USD', 'GUM'],
  509. ['GW', 'Guinea-Bissau', 'XOF', 'GNB'],
  510. ['GY', 'Guyana', 'GYD', 'GUY'],
  511. ['HK', 'Hong Kong', 'HKD', 'HKG'],
  512. ['HM', 'Heard Island and McDonald Islands', 'AUD', 'HMD'],
  513. ['HN', 'Honduras', 'HNL', 'HND'],
  514. ['HR', 'Croatia', 'HRK', 'HRV'],
  515. ['HT', 'Haiti', 'HTG', 'HTI'],
  516. ['HU', 'Hungary', 'HUF', 'HUN'],
  517. ['ID', 'Indonesia', 'IDR', 'IDN'],
  518. ['IE', 'Ireland', 'EUR', 'IRL'],
  519. ['IL', 'Israel', 'ILS', 'ISR'],
  520. ['IM', 'Isle of Man', 'GBP', 'IMN'],
  521. ['IN', 'India', 'INR', 'IND'],
  522. ['IO', 'British Indian Ocean Territory', 'USD', 'IOT'],
  523. ['IQ', 'Iraq', 'IQD', 'IRQ'],
  524. ['IR', 'Iran', 'IRR', 'IRN'],
  525. ['IS', 'Iceland', 'ISK', 'ISL'],
  526. ['IT', 'Italy', 'EUR', 'ITA'],
  527. ['JE', 'Jersey', 'GBP', 'JEY'],
  528. ['JM', 'Jamaica', 'JMD', 'JAM'],
  529. ['JO', 'Jordan', 'JOD', 'JOR'],
  530. ['JP', 'Japan', 'JPY', 'JPN'],
  531. ['KE', 'Kenya', 'KES', 'KEN'],
  532. ['KG', 'Kyrgyzstan', 'KGS', 'KGZ'],
  533. ['KH', 'Cambodia', 'KHR', 'KHM'],
  534. ['KI', 'Kiribati', 'AUD', 'KIR'],
  535. ['KM', 'Comoros', 'KMF', 'COM'],
  536. ['KN', 'Saint Kitts and Nevis', 'XCD', 'KNA'],
  537. ['KP', 'North Korea', 'KPW', 'PRK'],
  538. ['KR', 'South Korea', 'KRW', 'KOR'],
  539. ['KW', 'Kuwait', 'KWD', 'KWT'],
  540. ['KY', 'Cayman Islands', 'KYD', 'CYM'],
  541. ['KZ', 'Kazakhstan', 'KZT', 'KAZ'],
  542. ['LA', 'Laos', 'LAK', 'LAO'],
  543. ['LB', 'Lebanon', 'LBP', 'LBN'],
  544. ['LC', 'Saint Lucia', 'XCD', 'LCA'],
  545. ['LI', 'Liechtenstein', 'CHF', 'LIE'],
  546. ['LK', 'Sri Lanka', 'LKR', 'LKA'],
  547. ['LR', 'Liberia', 'LRD', 'LBR'],
  548. ['LS', 'Lesotho', 'LSL', 'LSO'],
  549. ['LT', 'Lithuania', 'LTL', 'LTU'],
  550. ['LU', 'Luxembourg', 'EUR', 'LUX'],
  551. ['LV', 'Latvia', 'LVL', 'LVA'],
  552. ['LY', 'Libya', 'LYD', 'LBY'],
  553. ['MA', 'Morocco', 'MAD', 'MAR'],
  554. ['MC', 'Monaco', 'EUR', 'MCO'],
  555. ['MD', 'Moldova', 'MDL', 'MDA'],
  556. ['ME', 'Montenegro', 'EUR', 'MNE'],
  557. ['MF', 'Saint Martin', 'EUR', 'MAF'],
  558. ['MG', 'Madagascar', 'MGA', 'MDG'],
  559. ['MH', 'Marshall Islands', 'USD', 'MHL'],
  560. ['MK', 'Macedonia', 'MKD', 'MKD'],
  561. ['ML', 'Mali', 'XOF', 'MLI'],
  562. ['MM', 'Myanmar [Burma]', 'MMK', 'MMR'],
  563. ['MN', 'Mongolia', 'MNT', 'MNG'],
  564. ['MO', 'Macao', 'MOP', 'MAC'],
  565. ['MP', 'Northern Mariana Islands', 'USD', 'MNP'],
  566. ['MQ', 'Martinique', 'EUR', 'MTQ'],
  567. ['MR', 'Mauritania', 'MRO', 'MRT'],
  568. ['MS', 'Montserrat', 'XCD', 'MSR'],
  569. ['MT', 'Malta', 'EUR', 'MLT'],
  570. ['MU', 'Mauritius', 'MUR', 'MUS'],
  571. ['MV', 'Maldives', 'MVR', 'MDV'],
  572. ['MW', 'Malawi', 'MWK', 'MWI'],
  573. ['MX', 'Mexico', 'MXN', 'MEX'],
  574. ['MY', 'Malaysia', 'MYR', 'MYS'],
  575. ['MZ', 'Mozambique', 'MZN', 'MOZ'],
  576. ['NA', 'Namibia', 'NAD', 'NAM'],
  577. ['NC', 'New Caledonia', 'XPF', 'NCL'],
  578. ['NE', 'Niger', 'XOF', 'NER'],
  579. ['NF', 'Norfolk Island', 'AUD', 'NFK'],
  580. ['NG', 'Nigeria', 'NGN', 'NGA'],
  581. ['NI', 'Nicaragua', 'NIO', 'NIC'],
  582. ['NL', 'Netherlands', 'EUR', 'NLD'],
  583. ['NO', 'Norway', 'NOK', 'NOR'],
  584. ['NP', 'Nepal', 'NPR', 'NPL'],
  585. ['NR', 'Nauru', 'AUD', 'NRU'],
  586. ['NU', 'Niue', 'NZD', 'NIU'],
  587. ['NZ', 'New Zealand', 'NZD', 'NZL'],
  588. ['OM', 'Oman', 'OMR', 'OMN'],
  589. ['PA', 'Panama', 'PAB', 'PAN'],
  590. ['PE', 'Peru', 'PEN', 'PER'],
  591. ['PF', 'French Polynesia', 'XPF', 'PYF'],
  592. ['PG', 'Papua New Guinea', 'PGK', 'PNG'],
  593. ['PH', 'Philippines', 'PHP', 'PHL'],
  594. ['PK', 'Pakistan', 'PKR', 'PAK'],
  595. ['PL', 'Poland', 'PLN', 'POL'],
  596. ['PM', 'Saint Pierre and Miquelon', 'EUR', 'SPM'],
  597. ['PN', 'Pitcairn Islands', 'NZD', 'PCN'],
  598. ['PR', 'Puerto Rico', 'USD', 'PRI'],
  599. ['PS', 'Palestine', 'ILS', 'PSE'],
  600. ['PT', 'Portugal', 'EUR', 'PRT'],
  601. ['PW', 'Palau', 'USD', 'PLW'],
  602. ['PY', 'Paraguay', 'PYG', 'PRY'],
  603. ['QA', 'Qatar', 'QAR', 'QAT'],
  604. ['RE', 'R&eacute;union', 'EUR', 'REU'],
  605. ['RO', 'Romania', 'RON', 'ROU'],
  606. ['RS', 'Serbia', 'RSD', 'SRB'],
  607. ['RU', 'Russia', 'RUB', 'RUS'],
  608. ['RW', 'Rwanda', 'RWF', 'RWA'],
  609. ['SA', 'Saudi Arabia', 'SAR', 'SAU'],
  610. ['SB', 'Solomon Islands', 'SBD', 'SLB'],
  611. ['SC', 'Seychelles', 'SCR', 'SYC'],
  612. ['SD', 'Sudan', 'SDG', 'SDN'],
  613. ['SE', 'Sweden', 'SEK', 'SWE'],
  614. ['SG', 'Singapore', 'SGD', 'SGP'],
  615. ['SH', 'Saint Helena', 'SHP', 'SHN'],
  616. ['SI', 'Slovenia', 'EUR', 'SVN'],
  617. ['SJ', 'Svalbard and Jan Mayen', 'NOK', 'SJM'],
  618. ['SK', 'Slovakia', 'EUR', 'SVK'],
  619. ['SL', 'Sierra Leone', 'SLL', 'SLE'],
  620. ['SM', 'San Marino', 'EUR', 'SMR'],
  621. ['SN', 'Senegal', 'XOF', 'SEN'],
  622. ['SO', 'Somalia', 'SOS', 'SOM'],
  623. ['SR', 'Suriname', 'SRD', 'SUR'],
  624. ['SS', 'South Sudan', 'SSP', 'SSD'],
  625. ['ST', 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'STD', 'STP'],
  626. ['SV', 'El Salvador', 'USD', 'SLV'],
  627. ['SX', 'Sint Maarten', 'ANG', 'SXM'],
  628. ['SY', 'Syria', 'SYP', 'SYR'],
  629. ['SZ', 'Swaziland', 'SZL', 'SWZ'],
  630. ['TC', 'Turks and Caicos Islands', 'USD', 'TCA'],
  631. ['TD', 'Chad', 'XAF', 'TCD'],
  632. ['TF', 'French Southern Territories', 'EUR', 'ATF'],
  633. ['TG', 'Togo', 'XOF', 'TGO'],
  634. ['TH', 'Thailand', 'THB', 'THA'],
  635. ['TJ', 'Tajikistan', 'TJS', 'TJK'],
  636. ['TK', 'Tokelau', 'NZD', 'TKL'],
  637. ['TL', 'East Timor', 'USD', 'TLS'],
  638. ['TM', 'Turkmenistan', 'TMT', 'TKM'],
  639. ['TN', 'Tunisia', 'TND', 'TUN'],
  640. ['TO', 'Tonga', 'TOP', 'TON'],
  641. ['TR', 'Turkey', 'TRY', 'TUR'],
  642. ['TT', 'Trinidad and Tobago', 'TTD', 'TTO'],
  643. ['TV', 'Tuvalu', 'AUD', 'TUV'],
  644. ['TW', 'Taiwan', 'TWD', 'TWN'],
  645. ['TZ', 'Tanzania', 'TZS', 'TZA'],
  646. ['UA', 'Ukraine', 'UAH', 'UKR'],
  647. ['UG', 'Uganda', 'UGX', 'UGA'],
  648. ['UM', 'U.S. Minor Outlying Islands', 'USD', 'UMI'],
  649. ['US', 'United States', 'USD', 'USA'],
  650. ['UY', 'Uruguay', 'UYU', 'URY'],
  651. ['UZ', 'Uzbekistan', 'UZS', 'UZB'],
  652. ['VA', 'Vatican City', 'EUR', 'VAT'],
  653. ['VC', 'Saint Vincent and the Grenadines', 'XCD', 'VCT'],
  654. ['VE', 'Venezuela', 'VEF', 'VEN'],
  655. ['VG', 'British Virgin Islands', 'USD', 'VGB'],
  656. ['VI', 'U.S. Virgin Islands', 'USD', 'VIR'],
  657. ['VN', 'Vietnam', 'VND', 'VNM'],
  658. ['VU', 'Vanuatu', 'VUV', 'VUT'],
  659. ['WF', 'Wallis and Futuna', 'XPF', 'WLF'],
  660. ['WS', 'Samoa', 'WST', 'WSM'],
  661. ['XK', 'Kosovo', 'EUR', 'XKX'],
  662. ['YE', 'Yemen', 'YER', 'YEM'],
  663. ['YT', 'Mayotte', 'EUR', 'MYT'],
  664. ['ZA', 'South Africa', 'ZAR', 'ZAF'],
  665. ['ZM', 'Zambia', 'ZMK', 'ZMB'],
  666. ['ZW', 'Zimbabwe', 'ZWL', 'ZWE'],
  667. ];
  668. foreach ($currencies as $currency) {
  669. Database::insert(
  670. $currencyTable,
  671. [
  672. 'country_code' => $currency[0],
  673. 'country_name' => $currency[1],
  674. 'iso_code' => $currency[2],
  675. ]
  676. );
  677. }
  678. $fieldlabel = 'buycourses_company';
  679. $fieldtype = '1';
  680. $fieldtitle = BuyCoursesPlugin::get_lang('Company');
  681. $fielddefault = '';
  682. $field_id = UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault);
  683. $fieldlabel = 'buycourses_vat';
  684. $fieldtype = '1';
  685. $fieldtitle = BuyCoursesPlugin::get_lang('VAT');
  686. $fielddefault = '';
  687. $field_id = UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault);
  688. $fieldlabel = 'buycourses_address';
  689. $fieldtype = '1';
  690. $fieldtitle = BuyCoursesPlugin::get_lang('The address of');
  691. $fielddefault = '';
  692. $field_id = UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault);