<?php
/*
 * Created on 11.04.2012
 * Oliver Soop(osoop1@ut.ee)
 * Kasutajaliidese UserInteface.php "Kontroller" klass, mis käivitab kasutajaliidesest edastatud käsud
 */

 include_once("../crawler/MainCrawler.php");
 include_once("../utils/CrawlDatabaseFeeds.php");
 include_once("../crawler/RSSUrlCrawler.php");
 include_once("../utils/CrawlDatabaseFeeds.php");
 include_once("../database/URLDatabaseService.php");
 include_once("../utils/CSVFileImporter.php");
if(!isset($_POST['operation'])) {
	echo "Viga, ei valitud tegevust, mida rakendada";
	return;
}

$crawlType = $_POST['operation'];

if(strcasecmp($crawlType,"urlCrawling") == 0) {
	//Sisendi järgi üritame leida RSS-e
	if(isset($_POST['url']) && strlen($_POST['url']) != 0){
		URLDatabaseService::addCrawlableUrl($_POST['url']);
	}else if(isset($_POST['csv']) && strlen($_POST['csv']) != 0) {
		$urlList = CSVFileImporter::getUrls($_POST['csv']);
		foreach($urlList as $url) {
			if(!URLDatabaseService::checkIfUrlIsCrawled($url)) {
				URLDatabaseService::addCrawlableUrl($url);
			}
		}
	} 
} else if(strcasecmp($crawlType,"rssCrawling") == 0) {
	CrawlDatabaseFeeds::start();
	
} else if(strcasecmp($crawlType,"rssUrlCrawling") == 0) {
	if(isset($_POST['rssUrl']) && strlen($_POST['rssUrl']) != 0){
		$mainCrawler = new MainCrawler($_POST['rssUrl'], null);
		$mainCrawler->crawl();
	}
	
	
	
}



?>