image uploading fixes involving database filepaths, with no filename.
[phpns.git] / install / upgrade.php
blob6ade3f707891d05a301ce69c88145909da3193cd
1 <?php
3 /* Copyright (c) 2007-08 Kyle Osborn, Alec Henriksen
4 * phpns is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public Licence (GPL) as published by the Free
6 * Software Foundation; either version 2 of the Licence, or (at your option) any
7 * later version.
8 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
9 * understanding of what this license means and how to abide by it.
12 //phpns version 1 => version 2 upgrade script, courtasy of our good friend "Kyle Osborn", a
13 //contributing developer of phpns. Thanks a lot! :D
16 if(!$_GET[step]){ header("location: ?step=1");}
18 define("DEBUG",$_GET[debug]);
20 $step = $_GET['step'];
23 // V1 CONNECTION
24 if(DEBUG){ echo $host ."<br />\n". $user ."<br />\n". $password ."<br />\n". $database ."<br /><br />";}
26 function v1connect()
28 $user = $_POST['db_user'];
29 $password = $_POST['db_password'];
30 $host = $_POST['db_host'];
31 $database = $_POST['db_name'];
32 $connection = mysql_connect($host, $user, $password) or die ("Connection to the phpns version 1 mysql server failed.");
33 $db = mysql_select_db($database,$connection) or die (mysql_error());
41 // V2 CONNECTION
42 if(DEBUG){ echo $databaseinfo['host'] ."<br />\n". $databaseinfo['user'] ."<br />\n". $databaseinfo['password'] ."<br />\n". $databaseinfo['dbname'] ."<br /><br />";}
44 function v2connect()
46 include("../inc/config.php");
47 $mysql['connection'] = mysql_connect($databaseinfo['host'], $databaseinfo['user'], $databaseinfo['password']) or die ($error['connection']);
48 $mysql['db'] = mysql_select_db($databaseinfo['dbname'],$mysql['connection']) or die ($error['database']);
55 if($_POST){
58 //From v1 userinfo
59 v1connect();
60 $user = "SELECT * FROM userinfo";
61 $userresult = mysql_query($user);
62 $num = mysql_numrows($userresult);
63 $i = 0;
64 while ($i < $num) {
66 $id = mysql_result($userresult,$i,"id");
67 $username = mysql_result($userresult,$i,"username");
68 $email = mysql_result($userresult,$i,"email");
69 $timestamp = mysql_result($userresult,$i,"date");
70 $rank = mysql_result($userresult,$i,"rank");
71 if(DEBUG) echo $id ."<br />\n". $username ."<br />\n". $email ."<br />\n". $timestamp ."<br />\n". $rank;
73 //to v2 users
74 v2connect();
75 $insert = "INSERT INTO `users` (`user_name`, `email`, `password`, `timestamp`, `rank_id`) VALUES ('$username', 'CHANGEME', '$email', '$timestamp', '$rank');";
76 @mysql_query($insert) or die (mysql_error());
78 $i++;
82 //From v1 news
83 v1connect();
84 $news = "SELECT * FROM news";
85 $newsresult = mysql_query($news);
86 $num = mysql_numrows($newsresult);
87 $i = 0;
88 while ($i < $num) {
90 $title = mysql_result($newsresult,$i,"title");
91 $subtitle = mysql_result($newsresult,$i,"subtitle");
92 $content = mysql_result($newsresult,$i,"content");
93 $extcontent = mysql_result($newsresult,$i,"extcontent");
94 $author = mysql_result($newsresult,$i,"author");
95 $date = mysql_result($newsresult,$i,"date");
96 $cat = mysql_result($newsresult,$i,"cat");
97 if(DEBUG) echo $id ."<br />\n". $title ."<br />\n". $subtitle ."<br />\n". $content ."<br />\n". $extcontent ."<br />\n". $author ."<br />\n". $date ."<br />\n". $cat;
99 //to v2 articles
100 v2connect();
101 $insert = "INSERT INTO `articles` (`article_title`, `article_subtitle`, `article_author`, `article_cat`, `article_text`, `article_exptext`, `article_imgid`, `allow_comments`, `start_date`, `end_date`, `active`, `approved`, `timestamp`, `ip`) VALUES ('$title', '$subtitle', '$author', '$cat', '$content', '$extcontent', '', '0', '', '', '0', '0', '$date', '127.0.0.1');";
102 @mysql_query($insert) or die (mysql_error());
104 $i++;
110 if($step == 1){
111 $content = '
112 <div class="warning"><strong>You need to have phpns 2 already installed</strong> for this to work.</div>
113 <h3>1.x database information</h3>
114 '.$error_message.'
115 <p>Phpns can upgrade from the version 1.x series, provided the database information from the 1.x version. You can find the database information in "/panel/inc/mysql.php" of the installation.</p>
116 <form action="?step=2" method="post">
117 <label for="db_host">Database host</label>
118 <input type="text" name="db_host" value="" /> (Usually "localhost")
119 </label>
120 <br />
123 <label for="db_user">Database user</label>
124 <input type="text" name="db_user" value="" />
125 </label>
126 <br />
128 <label for="db_password">DB password</label>
129 <input type="password" name="db_password" value="" />
130 </label>
131 <br />
134 <label for="db_name">Database name</label>
135 <input type="text" name="db_name" value="" />
136 <br />
138 <div class="alignr">
139 <input type="submit" id="submit" value="Continue" />
140 </div>
141 </form>
143 } else if($step == 2){
144 $content = '
146 <h3>Upgrade has been completed!</h3>
147 <br />
148 <h2>It is now <strong>STRONGLY</strong> suggest you remove the /install directory!</h2>';
152 include("install.tmp.php");