<?php	    	
class upsqlAction extends FirstendAction {
       public function _initialize() {
        parent::_initialize(); 				
    }
	public function jumpshow($url,$msg){		    
		    $delaySeconds = 2; 
		    echo '<!DOCTYPE html>';
		    echo '<html>';
		    echo '<head>';
			echo '<title>系统提示</title>';
		    echo '<meta http-equiv="refresh" content="'.$delaySeconds.';url='.$url.'">';
		    echo '</head>';
		    echo '<body>';
		    echo '<center><p>'.$msg.'</p></center>';
		    echo '</body>';
		    echo '</html>';
	}
	
	public function index(){		
	        $p = I('p');  			
	        if(!$p){			
		    $data['name'] = '排序设置';			
			$data['pid'] = 114;
			$data['module_name'] = 'paixu';
			$data['action_name'] = 'index';
			$data['often'] = 0;
			$data['ordid'] = 255;
			$data['display'] = 1;
			if(!D('menu')->where($data)->find()){
			D('menu')->add($data);
			}
			$msg = '添加后台管理导航菜单<br><br>导航菜单创建成功!<br>开始导入默认配置...<br>';	
			$url = '/?m=upsql&a=index&p=1';
			$this->jumpshow($url,$msg);	
			}			
	        if($p == 1){
			$setting['px_or'] = 'id desc';			
			foreach ($setting as $key => $val) {
            $val = is_array($val) ? serialize($val) : $val;           
		    if(D('setting')->where(array('name' => $key))->count()){
              D('setting')->where(array('name' => $key))->save(array('data' => $val));  
            }else{
              D('setting')->add(array('name' => $key,'data' => $val));
            }		    
            }
			$msg = '默认配置导入成功!<br>';
			$url = '/?m=upsql&a=finish';
			$this->jumpshow($url,$msg);	
			}			
			
	}  
	public function del(){
		$sqldir = 'app/Lib/Action/index/upsqlAction.class.php';	
		unlink($sqldir);
		header("Content-type: text/html; charset=utf-8");             
		die('<script language="javascript">alert("删除成功！");this.location.href="'.C('ftx_site_url').'";</script>');				
	}
	public function finish(){
		echo '<!DOCTYPE html>';
		echo '<html>';
		echo '<head>';
		echo '<title>系统提示</title>';
		echo '</head>';
		echo '<body>';
		echo '<center><p>本次数据库升级完成！<br><br><br>安全起见，<a href="/?m=upsql&a=del" style="color:red">点此删除</a>数据库升级文件</p></center>';
		echo '</body>';
		echo '</html>';		
		exit();
	}	
	
}