Creation of a ticket (not the content yet though) seems to work
--HG-- branch : quitta-gsoc-2013hg/feature/sse2
parent
a81b2dc9b3
commit
56fa0bf238
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
function create_ticket(){
|
||||
try{
|
||||
//if logged in
|
||||
if(WebUsers::isLoggedIn() && isset($_SESSION['ticket_user'])){
|
||||
|
||||
if(isset($_POST['target_id'])){
|
||||
|
||||
//if target_id is the same as session id or is admin
|
||||
if( ($_POST['target_id'] == $_SESSION['id']) || WebUsers::isAdmin() ){
|
||||
|
||||
global $cfg;
|
||||
$category = filter_var($_POST['Category'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$title = filter_var($_POST['Title'], FILTER_SANITIZE_STRING);
|
||||
$content = filter_var($_POST['Content'], FILTER_SANITIZE_STRING);
|
||||
if($_POST['target_id'] == $_SESSION['id']){
|
||||
$author = $_SESSION['ticket_user']->getTUserId();
|
||||
}else{
|
||||
$author= Ticket_User::constr_ExternId($_POST['target_id'], $cfg['db']['lib'])->getTUserId();
|
||||
}
|
||||
$ticket = new Ticket($cfg['db']['lib']);
|
||||
$ticket->setTicket($title,0,0,$category,$author);
|
||||
$ticket->create();
|
||||
|
||||
}else{
|
||||
//ERROR: permission denied!
|
||||
$_SESSION['error_code'] = "403";
|
||||
header("Location: index.php?page=error");
|
||||
exit;
|
||||
}
|
||||
|
||||
}else{
|
||||
//ERROR: The form was not filled in correclty
|
||||
header("Location: index.php?page=settings");
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
//ERROR: user is not logged in
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
}catch (PDOException $e) {
|
||||
//go to error page or something, because can't access website db
|
||||
print_r($e);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,45 @@
|
||||
<?php
|
||||
|
||||
function createticket(){
|
||||
|
||||
//if logged in
|
||||
if(WebUsers::isLoggedIn()){
|
||||
//in case user_id-GET param set it's value as target_id, if no user_id-param is given, use the session id.
|
||||
if(isset($_GET['user_id'])){
|
||||
|
||||
if(($_GET['user_id'] != $_SESSION['id']) && (!WebUsers::isAdmin()) ){
|
||||
|
||||
//ERROR: No access!
|
||||
$_SESSION['error_code'] = "403";
|
||||
header("Location: index.php?page=error");
|
||||
exit;
|
||||
|
||||
}else{
|
||||
//if user_id is given, then set it as the target_id
|
||||
$result['target_id'] = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
|
||||
}
|
||||
|
||||
}else{
|
||||
//set session_id as target_id
|
||||
$result['target_id'] = $_SESSION['id'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
//create array of category id & names
|
||||
global $cfg;
|
||||
$catArray = Ticket_Category::getAllCategories($cfg['db']['lib']);
|
||||
$result['category'] = Array();
|
||||
foreach($catArray as $catObj){
|
||||
$result['category'][$catObj->getTCategoryId()] = $catObj->getName();
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
//create array of category id & names
|
||||
global $cfg;
|
||||
$catArray = Ticket_Category::getAllCategories($cfg['db']['lib']);
|
||||
$result['category'] = Array();
|
||||
foreach($catArray as $catObj){
|
||||
$result['category'][$catObj->getTCategoryId()] = $catObj->getName();
|
||||
}else{
|
||||
//ERROR: not logged in!
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
//print_r($result);
|
||||
return $result;
|
||||
|
||||
}
|
Loading…
Reference in New Issue