1 <?php
2
3 namespace rpf\extension\module;
4 use rpf\api\module\bbDomain_readEntry;
5 use rpf\extension\extensionModule;
6 use rpf\system\module\log;
7
8 9 10 11 12 13 14 15 16 17 18 19 20 21
22 class domainExport extends extensionModule
23 {
24 protected $domainList = array();
25
26 27 28 29 30 31 32 33
34 public function buildDomainList()
35 {
36
37 $domains = $this->getApi()->getDomainReadEntry();
38
39 $result = $domains
40 ->addSettings()
41 ->addSubdomain()
42 ->get();
43
44 if (!is_array($result))
45 {
46 log::warning('There are no domains you could export?!', __METHOD__);
47 }
48 else
49 {
50 foreach ($result as $domain)
51 {
52 $phpVersion = &$domain['settings']['php_version'];
53 if (isset($domain['subdomain']) && is_array($domain['subdomain']))
54 foreach ($domain['subdomain'] as $subdomain)
55 {
56 $this->domainList[$subdomain['name']] =
57 [
58 'name' => $subdomain['name'],
59 'orderNr' => $subdomain['ordnr'],
60 'phpVersion' => $phpVersion,
61 'target' => $subdomain['target']
62 ];
63 }
64 }
65 }
66 return $this;
67 }
68
69 protected function getCsv()
70 {
71 if (empty($this->domainList)) $this->buildDomainList();
72 $csv = "(Sub-)Domain;RP2-Order;PHP-Version;Target\n";
73 foreach($this->domainList as $domain => $fields)
74 {
75 foreach ($fields as $row) $csv .= "$row;";
76 $csv .= "\n";
77 }
78 return $csv;
79 }
80
81 82 83 84 85 86 87
88 public function sendDownloadCsv($filename = NULL)
89 {
90 $filename = $filename !== NULL ? $filename : 'DomainExport_'.date('ymd').'_1SRV.csv';
91 log::info("Download started: $filename", __METHOD__);
92 header('Content-Type: text/html; charset=iso-8859-15');
93 header('Content-Type: application/csv');
94 header("Content-Disposition: attachment; filename=\"$filename\";");
95 echo utf8_decode($this->getCsv());
96 return $this;
97 }
98
99 }