source: trunk/custom/import_centrala.php

Last change on this file was 33, checked in by george, 16 years ago
  • Přidáno: Vlastní obsluha chyb.
  • Přidáno: Import dat z databáze centrály.
  • Opraveno: Řazení řádků v tabulkách při přepínání stránek.
File size: 8.7 KB
Line 
1<?php
2
3chdir('..');
4$SessionDisable = true;
5include('global.php');
6
7$Database2 = new Database($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], 'is');
8$Database2->charset($Config['Database']['Charset']);
9
10/*
11$SQL = 'ALTER TABLE `TableName`
12 DROP `ItemId`,
13 DROP `Author`,
14 DROP `ValidTimeFrom`,
15 DROP `ValidTimeTo`,
16 DROP `CreationTime`,
17 DROP `DeletionTime`;';
18$SystemList = new ListSystemList();
19$SystemList->ApplySQLToItems($SQL);
20die();
21*/
22
23echo("Import users to Subject\n");
24$Database->query('TRUNCATE TABLE Subject');
25$DbResult = $Database2->select(array('Database' => 'is', 'Table' => 'old_users'));
26while($DbRow = $DbResult->fetch_array())
27{
28 {
29 $Database->insert(array('Table' => 'Subject'), array('Id' => $DbRow['id'], 'Name' => $DbRow['subject_name'], 'AddressStreet' => $DbRow['street'], 'AddressTown' => $DbRow['town'], 'AddressZIP' => $DbRow['psc'], 'IC' => $DbRow['ico'], 'DIC' => $DbRow['dic']));
30 //echo($Database->LastQuery."\n");
31 }
32}
33
34echo("Import users to Users\n");
35$Database->query('TRUNCATE TABLE User');
36$DbResult = $Database2->select(array('Table' => 'old_users'));
37while($DbRow = $DbResult->fetch_array())
38{
39 {
40 $PermissionGroup = 0;
41 if($DbRow['nick'] == 'chronos') $PermissionGroup = 1;
42 $Database->insert(array('Table' => 'User'), array('Id' => $DbRow['id'], 'UserName' => $DbRow['nick'], 'Password' => sha1($DbRow['password']), 'FirstName' => $DbRow['first_name'], 'SecondName' => $DbRow['second_name'], 'Email' => $DbRow['email'], 'Phone' => $DbRow['phone'], 'ICQ' => $DbRow['icq'], 'Member' => $DbRow['id'], 'RegistrationTime' => $DbRow['membership_date'], 'LastLoginTime' => $DbRow['lastlogin'], 'PermissionGroup' => $PermissionGroup));
43 //echo($Database->LastQuery."\n");
44 }
45}
46
47echo("Import hosts to Host\n");
48$Database->query('TRUNCATE TABLE Host');
49$DbResult = $Database2->select(array('Table' => 'hosts'));
50while($DbRow = $DbResult->fetch_array())
51{
52 $Database->insert(array('Table' => 'Host'), array('Id' => $DbRow['id'], 'DomainName' => strtolower($DbRow['name']), 'LocalIPAddress' => $DbRow['IP'], 'PublicIPAddress' => $DbRow['external_ip'], 'ParentHost' => $DbRow['parent']));
53}
54
55echo("Import users to Member\n");
56$Database->query('TRUNCATE TABLE Member');
57$DbResult = $Database2->select(array('Table' => 'old_users'));
58while($DbRow = $DbResult->fetch_array())
59{
60 if($DbRow['role'] == 2)
61 {
62 $Database->insert(array('Table' => 'Member'), array('Id' => $DbRow['id'], 'Subject' => $DbRow['id'], 'ResponsibleUser' => $DbRow['id'], 'FamilyMemberCount' => $DbRow['family'], 'MembershipDate' => $DbRow['membership_date'], 'Tariff' => $DbRow['inet_tarif_now'], 'MemberState' => 2));
63 //echo($Database->LastQuery."\n");
64 }
65}
66
67echo("Import network_segments to NetworkSegment\n");
68$Database->query('TRUNCATE TABLE NetworkSegment');
69$DbResult = $Database2->select(array('Table' => 'network_segments'));
70while($DbRow = $DbResult->fetch_array())
71{
72 {
73 $Database->insert(array('Table' => 'NetworkSegment'), array('Id' => $DbRow['id'], 'Name' => $DbRow['name'], 'TotalAssetCost' => $DbRow['price'], 'MemberCount' => $DbRow['users'], 'ParentSegment' => $DbRow['parent']));
74 //echo($Database->LastQuery."\n");
75 }
76}
77
78echo("Import network_devices to StockCard\n");
79$Database->query('TRUNCATE TABLE StockCard');
80$DbResult = $Database2->query('SELECT consumption,name FROM `network_devices` GROUP BY name');
81//echo($Database2->LastQuery."\n");
82while($DbRow = $DbResult->fetch_array())
83{
84 {
85 $Database->insert(array('Table' => 'StockCard'), array('Name' => $DbRow['name'], 'Consumption' => $DbRow['consumption']));
86 //echo($Database->LastQuery."\n");
87 }
88}
89
90echo("Import network_devices to Asset\n");
91$Database->query('TRUNCATE TABLE Asset');
92$DbResult = $Database2->query('SELECT `is`.`network_devices`.*, (SELECT `webis_centrala`.`StockCard`.`Id` FROM `webis_centrala`.`StockCard` WHERE `webis_centrala`.`StockCard`.`Name` LIKE `network_devices`.`name`) AS `StockCard` FROM `is`.`network_devices`');
93//echo($Database2->LastQuery."\n");
94while($DbRow = $DbResult->fetch_array())
95{
96 if($DbRow['used'] == 0) $State = 4;
97 else if($DbRow['used'] == 1) $State = 2;
98 else if($DbRow['used'] == 2) $State = 1;
99 $Database->insert(array('Table' => 'Asset'), array('Id' => $DbRow['id'], 'StockCard' => $DbRow['StockCard'], 'Price' => $DbRow['price'], 'SerialNumber' => $DbRow['device_id'], 'PurcheasedFrom' => $DbRow['shop'], 'TimeEnlistment' => $DbRow['TimeEnlistment'], 'TimeElimination' => $DbRow['TimeElimination'], 'State' => $State, 'MemberLocation' => $DbRow['user']));
100 //echo($Database->LastQuery."\n");
101}
102
103echo("Import news_category to NewsGroup\n");
104$Database->query('TRUNCATE TABLE NewsGroup');
105$DbResult = $Database2->select(array('Table' => 'news_category'));
106while($DbRow = $DbResult->fetch_array())
107{
108 {
109 $Database->insert(array('Table' => 'NewsGroup'), array('Id' => $DbRow['id'], 'Name' => $DbRow['caption']));
110 //echo($Database->LastQuery."\n");
111 }
112}
113
114echo("Import news to NewsItem\n");
115$Database->query('TRUNCATE TABLE NewsItem');
116$DbResult = $Database2->select(array('Table' => 'news'));
117while($DbRow = $DbResult->fetch_array())
118{
119 {
120 $Database->insert(array('Table' => 'NewsItem'), array('Id' => $DbRow['id'], 'Title' => $Database->real_escape_string($DbRow['title']), 'Content' => $Database->real_escape_string($DbRow['content']), 'NewsGroup' => $DbRow['category'], 'TargetTime' => $DbRow['date']));
121 //echo($Database->LastQuery."\n");
122 }
123}
124
125echo("Import Meals to EatingPlaceMenu\n");
126$Database->query('TRUNCATE TABLE EatingPlaceMenu');
127$DbResult = $Database2->select(array('Table' => 'Meals'), '*');
128while($DbRow = $DbResult->fetch_array())
129{
130 {
131 $Database->insert(array('Table' => 'EatingPlaceMenu'), array('Day' => $DbRow['Date'], 'Soup' => $DbRow['Soup'], 'Meal' => $DbRow['Meal'], 'Status' => $DbRow['Status']));
132 //echo($Database->LastQuery."\n");
133 }
134}
135
136echo("Import network_dns_alias to DNSAlias\n");
137$Database->query('TRUNCATE TABLE DNSAlias');
138$DbResult = $Database2->query('SELECT *, (SELECT id FROM hosts WHERE lower(hosts.name) = network_dns_alias.target) as host FROM network_dns_alias');
139while($DbRow = $DbResult->fetch_array())
140{
141 {
142 $Database->insert(array('Table' => 'DNSAlias'), array('Name' => $DbRow['name'], 'Host' => $DbRow['host']));
143 //echo($Database->LastQuery."\n");
144 }
145}
146
147/*echo("Import ChatHistory to ChatHistory\n");
148$Database->query('TRUNCATE TABLE ChatHistory');
149$DbResult = $Database2->select(array('Table' => 'ChatHistory'));
150while($DbRow = $DbResult->fetch_array())
151{
152 {
153 $Database->insert(array('Table' => 'ChatHistory'), array('Id' => $DbRow['Id'], 'Nick' => $Database->real_escape_string($DbRow['Nick']), 'Message' => $Database->real_escape_string($DbRow['Text']), 'RoomName' => $DbRow['RoomName'], 'RoomType' => $DbRow['RoomType'], 'Color' => $DbRow['Color'], 'HostAddress' => $DbRow['Host']));
154 //echo($Database->LastQuery."\n");
155 }
156}*/
157
158echo("Import finance_monthly_overall to FinanceMonthlyOverall\n");
159$Database->query('TRUNCATE TABLE FinanceMonthlyOverall');
160$DbResult = $Database2->select(array('Table' => 'finance_monthly_overall'));
161while($DbRow = $DbResult->fetch_array())
162{
163 {
164 $Database->insert(array('Table' => 'FinanceMonthlyOverall'), array('TotalPaid' => $DbRow['total_paid'], 'MemberCount' => $DbRow['member_count'], 'TotalConsumption' => $DbRow['consumption_total'], 'TotalAdministration' => $DbRow['administration_total'], 'PricePerKWh' => $DbRow['kWh'], 'Date' => $DbRow['date'], 'Administration' => $DbRow['administration'], 'Internet' => $DbRow['money']));
165 //echo($Database->LastQuery."\n");
166 }
167}
168
169echo("Import finance_tariffs to Tariff\n");
170$Database->query('TRUNCATE TABLE Tariff');
171$DbResult = $Database2->select(array('Table' => 'finance_tariffs'));
172while($DbRow = $DbResult->fetch_array())
173{
174 {
175 if($DbRow['group_id'] != 2) $DbRow['price'] = 50 + 140 * $DbRow['price_units'];
176 if($DbRow['group_id'] == 1)
177 {
178 $DbRow['min_speed'] = 32 * $DbRow['speed_factor'];
179 $DbRow['max_speed'] = 512 * $DbRow['speed_factor'];
180 }
181 $Database->insert(array('Table' => 'Tariff'), array('Name' => $DbRow['name'], 'Price' => $DbRow['price'], 'MinUploadSpeed' => $DbRow['min_speed'], 'MaxUploadSpeed' => $DbRow['max_speed'], 'MinDownloadSpeed' => $DbRow['min_speed'], 'MaxDownloadSpeed' => $DbRow['max_speed'], 'MonthPeriod' => $DbRow['period']));
182 //echo($Database->LastQuery."\n");
183 }
184}
185
186echo("Import SubjectOpenTimeInterval to SubjectOpenTime\n");
187$Database->query('TRUNCATE TABLE SubjectOpenTime');
188$DbResult = $Database2->select(array('Table' => 'SubjectOpenTimeInterval'));
189while($DbRow = $DbResult->fetch_array())
190{
191 {
192 $Database->insert(array('Table' => 'SubjectOpenTime'), array('Subject' => $DbRow['Subject'], 'Id' => $DbRow['Id'], 'OpenTime' => $DbRow['OpenTime'], 'CloseTime' => $DbRow['CloseTime']));
193 //echo($Database->LastQuery."\n");
194 }
195}
196
197
198?>
Note: See TracBrowser for help on using the repository browser.