Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/install/step7.php
<?
        aff_header("PhpMyPrepaid Setup Wizard", "Creating Database", 8);
                ?>
                <table cellpadding="0" cellspacing="0" border="0" width="80%" class="StyleDottedHr" align="center">
          <tr>
            <th align="left">Component</th>
            <th style="text-align: right;">Status</th>
          </tr>
                 <?

                        $file[0] = "<?\n";
                        $file[1] = "/*\n";
                        $file[2] = "PhpMyPrepaid is developped with GPL Licence 2.0 :\n";
                        $file[3] = "http://www.gnu.org/licenses/gpl.txt or read LICENSE file.\n\n";
                        $file[6] = "We are using Oreon for base code: http://www.oreon-project.org. Dialup Admin for user management and many more things: http://www.freeradius.org. \n";
                        $file[7] = "*/";
                        $file[8] = "\n";
                        $file[9] = "// database\n";
                $file[10] = "\$conf_pra['host'] = \"". $_SESSION["dbLocation"] ."\";\n";
                $file[11] = "\$conf_pra['user'] = \"". $_SESSION["namePraDB"] . "\";\n";
                $file[12] = "\$conf_pra['password'] = \"". $_SESSION["pwdPraDB"] . "\";\n";
                $file[13] = "\$conf_pra['db'] = \"". $_SESSION["namePraDB"] . "\";\n";
                $file[14] = "\$conf_pra['dbtype'] = \"mysql\";\n";
                $file[15] = "\$conf_pra['sqlport'] = \"".$_SESSION["dbPort"] ."\";\n";
                        $file[16] = "\n";
         $file[17] = "// path to classes\n";
                $file[18] = "\$classdir='./class'; \n";
                $file[19] = "?>";

                        if ($fd = fopen("../phpmyprepaid.conf.php", "w+"))      {
                                for ($i = 0; $i <= 20; $i++)
                                        fwrite ($fd, $file[$i]);
                                fclose ($fd);
                        } else {
                                die ("<center><span class='stop'>Can't open configuration file !</span></center><br><br>");
                        }
                        ?>
                        <tr>
                                <td><b>Configuration file </b></td>
                                <td align="right">done</td><td></td>
                        </tr>
<?
                        if (!$_SESSION["pwdroot"])
                                $res = connexion('root', '', $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error());
                        else
                                $res = connexion('root', $_SESSION["pwdroot"], $_SESSION["dbLocation"]) or die ("Can't connect to Mysql Server : ".mysql_error()); //$_SESSION["pwdroot"]
                        $requete = "DROP DATABASE ". $_SESSION["namePraDB"] . ";";
                        if ($DEBUG) print $requete . "<br>";
			mysql_query($requete, $res);
                        $err= mysql_error($res);
?>
			<tr>
				                  <td><b>Old database deletion</b></td>


	<? if ($err=='') 
	 print   '<td align="right">done</td><td></td>';
	 else 
		  print '<td align="right">error</td><td>'.$err.'</td>';
	?> </tr>

	<?
				$err='';
				$requete = "CREATE DATABASE ". $_SESSION["namePraDB"] . ";";
				if ($DEBUG) print $requete . "<br>";
				mysql_query($requete, $res);
				$err= mysql_error($res);
	?>                     <tr>
					<td><b>Database Creation </b></td>

		<? if ($err=='') 
		 print   '<td align="right">done</td><td></td>';
		 else 
		  print '<td align="right">error</td><td>'.$err.'</td>';
	?> </tr>
<?
		    // INSERT TIME TO FINISH PROCEDURE
            if ($_SESSION["pwdroot"]!='') {
                $last_line = system('mysql -u root -p'.$_SESSION["pwdroot"].' '.$_SESSION["namePraDB"].' <TimeToFinish.sql', $retval);
                $last_line = system('mysql -u root -p'.$_SESSION["pwdroot"].' '.$_SESSION["namePraDB"].' <DailyAccounting.sql', $retval);
             }
             else
             {
                $last_line = system('mysql -u root  '.$_SESSION["namePraDB"].' <TimeToFinish.sql', $retval);
                $last_line = system('mysql -u root  '.$_SESSION["namePraDB"].' <DailyAccounting.sql', $retval);
            }
                
				if ($DEBUG) print 'PASSWORD : '.$_SESSION["pwdPraDB"]  . "<br>";
				$err='';
				$requete = "GRANT ALL PRIVILEGES ON `". $_SESSION["namePraDB"] . "` . * TO `". $_SESSION["namePraDB"] . "`@`". $_SESSION["dbLocation"] . "` IDENTIFIED BY '". $_SESSION["pwdPraDB"] . "' WITH GRANT OPTION";
				if ($DEBUG) print $requete. "<br>";
				@mysql_query($requete, $res) or die("Error : ".mysql_error());
				$err.=mysql_error($res);
				$err=mysql_error($res);
				@mysql_select_db($_SESSION["namePraDB"], $res) or die("Error : ".mysql_error());

				$requete2 = "GRANT EXECUTE ON PROCEDURE TimeToFinish  TO `". $_SESSION["namePraDB"] . "`@`". $_SESSION["dbLocation"]."`";
				if ($DEBUG) print $requete2. "<br>";
				@mysql_query($requete2, $res) or die("Error : ".mysql_error());
				$err.=mysql_error($res);

				$requete3 = "GRANT EXECUTE ON PROCEDURE acct_update  TO `". $_SESSION["namePraDB"] . "`@`". $_SESSION["dbLocation"]."`";
				if ($DEBUG) print $requete3. "<br>";
				@mysql_query($requete3, $res) or die("Error : ".mysql_error());
				$err.=mysql_error($res);

				$requete4 = "GRANT EXECUTE ON PROCEDURE acct_stop  TO `". $_SESSION["namePraDB"] . "`@`". $_SESSION["dbLocation"]."`";
				if ($DEBUG) print $requete3. "<br>";
				@mysql_query($requete3, $res) or die("Error : ".mysql_error());
				$err.=mysql_error($res);



				@mysql_select_db($_SESSION["namePraDB"], $res) or die("Error : ".mysql_error());


				?>
				<tr>
					<td><b>Database user phpmyprepaid </b></td>
			<? if ($err=='') 
		 	print   '<td align="right">done</td><td></td>';
		 	else 
		 	print   '<td align="right">error</td><td>'.$err.'</td>';
?></tr>
				<?

				$err='';
				$file_sql = file("./phpmyprepaid.sql");
				$str = NULL;
		    for ($i = 0; $i <= count($file_sql) - 1; $i++)        { 
	      $line = $file_sql[$i];
			    if ($line[0] != '#')    {
				$pos = strrpos($line, ";");
				if ($pos != false)      {
				    $str .= $line;
				    $str = chop ($str);
				    $result = mysql_query($str, $res);
				    $err.=mysql_error($res);
				    $str = NULL;
				}
				else
					$str .= $line;
			    }
		    }

				@mysql_close($res);
		?>
				<tr>
					<td><b>Phpmyprepaid database insertion </b></td>
			<? if ($err=='') 
		 	print   '<td align="right">done</td><td></td>';
		 	else 
		 	print   '<td align="right">error</td><td>'.$err.'</td>';
?></tr>
				<?
$err='';

	 $res = connexion($_SESSION["namePraDB"], $_SESSION["pwdPraDB"], $_SESSION["dbLocation"]);
				@mysql_select_db($_SESSION["namePraDB"], $res) or die("Error : ".mysql_error());


				$req = "SELECT * FROM `user` WHERE user_alias = '".$_SESSION["pralogin"]."' ";
				$r = @mysql_query($req, $res);
				$err.=mysql_error($res);
				if (!$r)
				$nb = @mysql_num_rows($r);
				while ($tab = @mysql_fetch_array($r))
					break;
				if (!$tab && !$nb){
				// ADD PhpMyPrepaid admin user info     
					$requete = "INSERT INTO `user` (`user_firstname` , `user_lastname` , `user_alias` , `user_passwd` , `user_lang` , `user_mail` , `user_version` , `user_status` ) VALUES ";
					$requete .= "('".$_SESSION["prafirstname"]."', '".$_SESSION["pralastname"]."', '".$_SESSION["pralogin"]."', '". md5($_SESSION["phpmyprepaidpassword"]) ."', '".$_SESSION["pralang"]."', '".$_SESSION['praemail']."', '".$_SESSION['radius_version']."', '3');";
					$result = @mysql_query($requete, $res);
					$err.=mysql_error($res);
				}
				else
				{
					 $requete = "UPDATE `user` SET `user_firstname` = '".$_SESSION["prafirstname"]."',`user_lastname` = '".$_SESSION["pralastname"]."',`user_alias` = '".$_SESSION["pralogin"]."',`user_passwd` = '". md5($_SESSION["phpmyprepaidpassword"]) ."',`user_mail` = '".$_SESSION['praemail']."',`user_status` = '3',`user_lang` = '".$_SESSION["pralang"]."' WHERE `user_id` =1 LIMIT 1 ;";
                                     	 if ($DEBUG) print "larequete: ". $requete ." larequete2: " . $requete2 ." la requete3: ". $requete3. "<br>";
                                         $result = @mysql_query($requete, $res);
				         $err.=mysql_error($res);

				}
		$requete2 = "INSERT INTO `general_opt` (`cron_path`, `phpmyprepaid_path`, `refresh`, `rrdtool_bin`, `session_expire`,  `cron_bin`, `apache_site_path`,`apache_ssl_dir`, `system_log_path`, `sudo_bin`, `apache_bin`,`snmpget`,`snmpwalk`,`mysqlclient`,`location_id`) VALUES ";
		$requete2 .= "('".$_SESSION["cron_path"]."', '".$_SESSION["phpmyprepaid_path"]."', 60,'".$_SESSION["rrdtool_bin"]."', 0, '".$_SESSION["cron_bin"]."', '".$_SESSION['apache_site_path']."', '".$_SESSION['apache_ssl_dir']."', '".$_SESSION['system_log_path']."', '".$_SESSION['sudo_bin']."', '".$_SESSION['apache_bin']."','".$_SESSION['snmpget']."','".$_SESSION['snmpwalk']."','".$_SESSION['mysqlclient']."','1');";

		$result2 = @mysql_query($requete2, $res);
		$err.= mysql_error($res);
				//ADD radius options   
		$requete3 = "INSERT INTO `radius_config` (`radius_server`,`radius_server_sec`,`radius_server_port`,`radius_server_secret`,`radius_log`,`radius_bin`,`radius_conf`,`radius_version`,`radclient`,`radius_dictionnary`,`radius_startscript`,`location_id`) VALUES ";
		$requete3 .= "('".$_SESSION["radius_server"]."', '".$_SESSION["radius_server_sec"]."','".$_SESSION["radius_port"]."','".$_SESSION["radius_secret"]."', '".$_SESSION['radius_log']."','".$_SESSION['radius_bin']."','".$_SESSION['radius_conf']."','".$_SESSION['radius_version']."','".$_SESSION["radclient"]."', '".$_SESSION["radius_dictionary"]."','". $_SESSION["radius_startscript"] ."','1');";
		
		
		$result3 = @mysql_query($requete3, $res);
		$err.=mysql_error($res);
		include('../class/OreonDatabase.class.php');
		include('../class/Oreon.class.php');
		$od=new OreonDatabase($_SESSION["dbLocation"],'root',$_SESSION["pwdroot"],$_SESSION["namePraDB"] );	
                $user = new User($_SESSION["pralogin"]);
                $user->set_status('3');
                $_SESSION['oreon'] = new oreon($user, $od);
		?>
				<tr>
					<td><b>Database updated </b></td>
		<? if ($err=='') 
		 print   '<td align="right">done</td><td></td>';
		 else 
		 print   '<td align="right">error</td><td>'.$err.'</td>';
		?></tr>
			
<tr>
<?
		$opt=$od->getphpmyprepaid('-1');
		$opt['location_id']='1';
		$od->savephpmyprepaidTab($opt);
	

		$opt=$od->getpdfprintconfigurationObject('-1');
		$opt->location_id='1';		
		$od->savepdfprintconfiguration($opt);

		$opt=$od->getwloginconfigurationObject($locID);
		$opt->location_id='1';		
		$od->savewloginconfiguration($opt);

		$opt=$od->getapconfigurationObject('-1');
		$opt->location_id='1';		
		$od->saveapconfiguration($opt);
	 
		$opt=$od->getchilliconfigurationObject('-1');
		$opt->location_id='1';		
		$od->savechilliconfiguration($opt);
		
		$opt=$od->getcardstemplates('default1','-1');
		$opt['tpl_location']=1;		
		$od->savecardstemplate($opt);
		
		$opt=$od->getcardstemplates('default2','-1');
		$opt['tpl_location']=1;	
		$od->savecardstemplate($opt);

?>
		
		<td><b>Default configuration loaded </b></td>


<?
	 if ($err=='') 
	 print   '<td align="right">done</td><td></td>';
	 else 
	 print   '<td align="right">error</td><td>'.$err.'</td>';
                        @mysql_close($res);
				// end last code
				aff_middle();
                        $str = "<input class='button' type='submit' name='goto' value='Back' /><input class='button' type='submit' name='goto' value='Next' id='button_next' />";
			
                        print "</td>".$str;
                        aff_footer();
?>
Return current item: phpMyPrepaid