Skip to content
Snippets Groups Projects
mysql.class.php 1.64 KiB
Newer Older
Eric Laufer's avatar
Eric Laufer committed
<?php

class mysql{
	private $db;
	private $session = array();
	private $post = array();
	private $error = 0;
	private $meldung;
	private $mysqlTXT;
	
	public function __construct(){
		global $datenbank,$_SESSION;
		$this->db = $datenbank;
		$this->session = $_SESSION;
	}
	
	private function make_array($post,$file){
		foreach($post AS $key => $value){
			if($key != '' && $key != 'run' && $value != ''){
Eric Laufer's avatar
Eric Laufer committed
				$this->post[$key] = $value;
Eric Laufer's avatar
Eric Laufer committed
			}
		}
	}
	
	public function ausfuehren($post,$file){
		$this->make_array($post,$file);
Eric Laufer's avatar
Eric Laufer committed
		if($this->session['admin'] != 1){ die("Nicht genemigter Zugriff");}
Eric Laufer's avatar
Eric Laufer committed
		$this->CheckUpload($file);
		
		if($this->error == 0){
			$this->import();
			$this->meldung = MYSQL_UPLOAD_TRUE;
		}
		
		meldung($this->error,$this->meldung);
	}
	
	private function CheckUpload($file){
		if(isset($this->post['mysqltxt']) || !empty($this->post['mysqltxt']) ){
Eric Laufer's avatar
Eric Laufer committed
			$this->post['mysqltxt'] = str_replace(array("\r\n","\n\r", "\n", "\r"),"",$this->post['mysqltxt']);
Eric Laufer's avatar
Eric Laufer committed
			$this->txt();
		}elseif(isset($file)){
			$this->file($file);
		}
	}
	
	private function txt(){
		$this->mysqlTXT = str_replace("vms_",PREFIX, $this->post['mysqltxt']);
	}
	
	private function file($file){
		$endung = strtolower(pathinfo($file['mysqldatei']['name'], PATHINFO_EXTENSION));
		if(!in_array($endung,array("sql","txt"))){ $this->error = 1; $this->meldung = MYSQL_DATEITYPE_FALSE;}
		if($this->error == 0){
Eric Laufer's avatar
Eric Laufer committed
			$this->mysqlTXT = str_replace("vms_",PREFIX , file_get_contents($file['mysqldatei']['tmp_name'],true));
Eric Laufer's avatar
Eric Laufer committed
		}
	}
	
	private function import(){
Eric Laufer's avatar
Eric Laufer committed
		$explode = explode(";",$this->mysqlTXT);
Eric Laufer's avatar
Eric Laufer committed
		for($i = 0; $i <= count($explode)-1; $i++){
Eric Laufer's avatar
Eric Laufer committed
			$this->db->query($explode[$i]);
Eric Laufer's avatar
Eric Laufer committed
		}
	}
}