require('./include/init.php');
$js = array('report.js');
$ebook=null; // this array contains all data about the ebook
//so that jquery loads for forced login
define('FORCE_JQUERY',1);
if(User::isLogged()){
if(isset($_POST['id']) && isset($_POST['data'])){
$id = (int) $_POST['id'];
if(!($ebook = Book::getDetails($id, 'id', 'title, url_tag, id, name')))
show404();
$ebook = $ebook[0];
insertReport($id, $user_c->email, $ebook['title'], $_POST['data'], $_POST['category']);
$page_title= 'Thank you for reporting problem with ' . $ebook['title'] ;
$page_desc = $page_title;
Msg::$success[] ='Thank you for taking the time to submit feedback. Please be patient while our staff reviews your feedback and fixes the problem. To go back to the home page, click here.';
} elseif(isset($_GET['slug'])){
$slug = DB::esc($_GET['slug']);
if(!($ebook = Book::getDetails($slug, 'url_tag', 'title, category, url_tag, id, name')))
show404();
$ebook = $ebook[0];
$cat_slug = Category::getSlug($ebook['category']);
checkAndRedirectCatSlug($cat_slug);
$page_title= 'Please report a problem with ' . secureHTML($ebook['title']) ;
$page_desc = $page_title;
} else
show404();
} else{
$page_title= 'Please login to report a problem' ;
$page_desc = $page_title;
Msg::$warning[] ='In order to report a problem, please login or register first.';
}
require ROOT .'templates/main.php';
/*
*************************************
END OF LOGICAL FLOW
BELOW ARE FUNCTIONS USED ON THIS PAGE
*************************************
*/
function insertReport($id, $email, $title, $data, $category){
$entry_date=date("d M Y", time());
$title= str_replace("'","\\'",$title);
$id = (int) $id;
$data = DB::esc($data);
$category = DB::esc($category);
$sql = "INSERT INTO `broken` ( `id` , `ebook` , `submitter` , `problem` , `category`, `when` , `checked` ) VALUES (".$id.", '".$title."', '".$email."', '".$data."', '$category', '".$entry_date."', 0);";
DB::insert($sql);
}
?>