<?php

require_once('inc/conn.php');
$opendb = new mydb();
require_once('inc/char_set.php');
require_once('inc/ls_syscode.php');

$action=$_GET['action'];

$config_sql="select * from ls_config ";
$config_query=$opendb->query($config_sql);
$config_rows=mysql_fetch_assoc($config_query);
$key = false;
if(substr_count($config_rows['siteKeywords'],",") > 0){
	$keywords = explode(",",$config_rows['siteKeywords']);
	$key = false;
}elseif(substr_count($config_rows['siteKeywords'],"|") > 0){
	$keywords = explode("|",$config_rows['siteKeywords']);
	$key = false;
}elseif(strlen($config_rows['siteKeywords']) > 0){
	$keywords[] = $config_rows['siteKeywords'];
	$key = true;
}

switch($action){
	case "clear":
		//清空数据表
		$sql = "TRUNCATE TABLE ls_internal";
		$opendb->query($sql);
		//$code = "update  ls_functioncode  set code='' where codeID='internal' ";
		//$opendb->query($code);
		
	break;
	
	case "add":
		
		array_push($keywords, $config_rows['companyName'], mb_substr(strip_tags($config_rows['companyName']),0,5, 'utf-8'));

		for($index = 0; $index < count($keywords); $index++){
			
			$keyw = trim($keywords[$index]);
			
			$select_sql2="select * from ls_internal where title='".$keyw."' ";
			$select_query2=$opendb->query($select_sql2);
			$select_rows2=mysql_num_rows($select_query2); //总数
			if($select_rows2>0 || trim($keywords[$index])=="" ){ //有相同值
				//echo "repeat";
			}
			else{
				$select_sql2="select * from ls_internal ";
				$select_query2=$opendb->query($select_sql2);
				$select_rows2=mysql_num_rows($select_query2); //总数
				$insert_sql="insert into ls_internal(title,Num,enable) values ('".$keyw."',".($select_rows2+1).",1)";
		
				if ($opendb->query($insert_sql)){
					//echo "success";
				}else{
					//echo "fail";
				}
			}
		}
		
	break;
}

$opendb->close();

?>