61686ea4a495d5a26ac41d907ba7ca8297b23c0e
[mailer.git] / mt_konverter / mt_mxchange_converter.php
1 <?php
2 /************************************************************************
3  * mt_konverter 0.1                                   Start: 07/18/2004 *
4  * ================                             Last change: 09/05/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : mxchange.php                                     *
8  * -------------------------------------------------------------------- *
9  * Short description : Data converter for Danny Bubolz mail exchange    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Datenkonverter fuer Danny Bubolz's Mailtausch    *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Verbindung oeffnen...
35 require("config/config.php");
36
37 // Header ausgeben
38 echo "<DIV align=\"center\"><STRONG>Datenkonverter nach MXChange-Datenbank</STRONG></DIV><BR>\n";
39
40 // Umgebung testen
41 echo "Teste Umgebung.... ";
42 if (!file_exists("tmp"))        exit("Verzeichnis tmp mit CHMOD 777 bitte anlegen!");
43 @touch("tmp/test.sql") or exit("Bitte CHMOD 777 auf tmp setzen!");
44 unlink("tmp/test.sql");
45 echo "<B>OKAY</B><BR>\n";
46
47 echo "Konvertiere Daten... ";
48 @touch("tmp/mxchange-db.sql");
49 $fp = @fopen("tmp/mxchange-db.sql", 'w');
50
51 // Daten geht's mit den Userdaten los!
52 $result = mysql_query("SELECT ID,user,vorname,nachname,land,plz,strasse,ort,email,pwd,session,guthaben,refpunkte,bonuspunkte,extrapunkte,mailpunkte,mailsamtag,punkteabzug,geworbenvon,popuppunkte,jackpotpunkte,refpunkte1,refpunkte2,refpunkte3,refpunkte4,refpunkte5,refpunkte6,refpunkte7,refpunkte8,refpunkte9,refpunkte10,lastaction FROM mt_user ORDER BY ID")
53         or exit(__FILE__." (".__LINE__."): ".mysql_error());
54 while ($DATA = mysql_fetch_array($result)) {
55         $data_k   = array(); $data_v   = array();
56         $points_k = array(); $points_v = array();
57         foreach ($DATA as $key=>$value) {
58                 if ((intval($key) == "0") && ($key != "0")) {
59                         switch ($key) {
60                                 case "ID":
61                                         echo "User <B>".$value."</B>...\n";
62                                         $data_k[] = "userid"; $data_v[] = $value;
63                                         $ID = $value;
64                                         break;
65
66                                 case "user":
67                                         $data_k[] = "nickname"; $data_v[] = $value;
68                                         $NICK = $value;
69                                         break;
70
71                                 case "vorname":
72                                         $data_k[] = "surname"; $data_v[] = $value;
73                                         break;
74
75                                 case "nachname":
76                                         $data_k[] = "family"; $data_v[] = $value;
77                                         break;
78
79                                 case "land":
80                                         $data_k[] = "country"; $data_v[] = $value;
81                                         break;
82
83                                 case "plz":
84                                         $data_k[] = "zip"; $data_v[] = $value;
85                                         break;
86
87                                 case "strasse":
88                                         $data_k[] = "street_nr"; $data_v[] = $value;
89                                         break;
90
91                                 case "ort":
92                                         $data_k[] = "city"; $data_v[] = $value;
93                                         break;
94
95                                 case "email":
96                                         $data_k[] = "email"; $data_v[] = $value;
97                                         break;
98
99                                 case "pwd":
100                                         $data_k[] = "password"; $data_v[] = md5($value);
101                                         break;
102
103                                 case "mailsamtag":
104                                         $data_k[] = "max_mails"; $data_v[] = $value;
105                                         $data_k[] = "receive_mails"; $data_v[] = $value;
106                                         break;
107
108                                 case "lastaction":
109                                         $data_k[] = "joined";      $data_v[] = $value;
110                                         $data_k[] = "last_online"; $data_v[] = $value;
111                                         $data_k[] = "last_module"; $data_v[] = "login";
112                                         $data_k[] = "last_update"; $data_v[] = $value;
113                                         break;
114
115                                 case "session":
116                                         $data_k[] = "user_hash"; $data_v[] = $value;
117                                         break;
118
119                                 case "geworbenvon":
120                                         $ref_res = mysql_query("SELECT ID FROM mt_user WHERE user='".$value."' LIMIT 1")
121                                  or exit(__FILE__." (".__LINE__."): ".mysql_error());
122                                  list($value) = mysql_fetch_row($ref_res);
123                                  if ($value == "") $value = "0";
124                                  $data_k[] = "refid"; $data_v[] = $value;
125                                  break;
126
127                                  /********* Ab hier Punkte! *********/
128                                 case "punkteabzug":
129                                         $data_k[] = "used_points"; $data_v[] = abs($value);
130                                         break;
131
132                                 case "guthaben":
133                                         $points_k['check'] = "check"; $points_v['check'] = $value;
134                                         break;
135
136                                 case "refpunkte":
137                                 case "bonuspunkte":
138                                 case "extrapunkte":
139                                 case "mailpunkte":
140                                 case "jackpotpunkte":
141                                 case "popuppunkte":
142                                         if (!in_array("points0", $points_k))
143                                         {
144                                                 $points_k[] = "points0";
145                                         }
146                                         $pos = array_search("points0", $points_k);
147                                         $points_v[$pos] += $value;
148                                         break;
149
150                                 case "refpunkte1":
151                                 case "refpunkte2":
152                                 case "refpunkte3":
153                                 case "refpunkte4":
154                                 case "refpunkte5":
155                                 case "refpunkte6":
156                                 case "refpunkte7":
157                                 case "refpunkte8":
158                                 case "refpunkte9":
159                                 case "refpunkte10":
160                                         $ref = substr($key, 9);
161                                         $points_k[$ref] = "points".$ref.""; $points_v[$ref] = $value;
162                                         break;
163
164                                 default:
165                                         echo "Spalte <B>".$key."</B> mit Wert ".$value." konnte nicht konvertiert werden!<BR>\n";
166                         }
167                 }
168         }
169         $SQL = "INSERT INTO mxchange_user_data (";
170         foreach ($data_k as $key=>$value) {
171                 $SQL .= $value.",";
172         }
173         $SQL .= "status) VALUES ('";
174         foreach ($data_v as $key=>$value) {
175                 $SQL .= $value."','";
176         }
177         $SQL .= "CONFIRMED');\n";
178         fwrite($fp, $SQL); $lvl0 = false;
179         $lvl0_points = "0";
180         foreach ($points_v as $level=>$points) {
181                 if ($level != "check") {
182                         // Refs pruefen
183                         $result_ref = mysql_query("SELECT user FROM mt_refs WHERE ref".$level."='".$NICK."'")
184                                 or exit(__FILE__." (".__LINE__."): ".mysql_error());
185                         if ($points != "0.00") {
186                                 $SQL1 = "INSERT INTO mxchange_user_points (userid,ref_depth,points) VALUES ('".$ID."','".$level."','".$points."');\n";
187                                 $SQL2 = "INSERT INTO mxchange_refsystem (userid,level,counter) VALUES('".$ID."','".$level."','".mysql_num_rows($result_ref)."');\n";
188                                 fwrite($fp, $SQL1);
189                                 fwrite($fp, $SQL2);
190                         }
191                 } else {
192                         if (!$lvl0) {
193                                 $lvl0_points = $points;
194                                 $lvl0 = true;
195                         } else {
196                                 $lvl0_points = $lvl0_points + $points;
197                                 fwrite($fp, "INSERT INTO mxchange_user_points (userid,ref_depth,points) VALUES ('".$ID."','0','".$lvl0_points."');\n");
198                                 $lvl0_points = "0"; $lvl0 = false;
199                         }
200                 }
201         }
202 }
203
204 // Alles klar! (hoffentlich?)
205 echo "<B>OKAY</B><BR>\n";
206 fclose($fp);
207
208 // Und wieder zu damit...
209 mysql_close($db);
210
211 echo "<BR>\n";
212 echo "Datei <B>tmp/mxchange-db.sql</B> mit <B>".filesize("tmp/mxchange-db.sql")." Bytes</B> erzeugt.<BR><BR>Datenkonvertierung abgeschlossen...<BR>
213 <BR>
214 Bevor Sie jedoch den Dump einspielen, m&uuml;ssen Sie unbedingt die <A href=\"http://www.mxchange.org\">nickname-Erweiterung</A> meines Scriptes eingerichtet haben! Anderfalls kommt es zu Fehlermeldungen und die User-Daten konnten nicht importiert werden.\n";
215
216 //
217 ?>