<?php
//administration interface
//for use with dotgo class ver 0.1 beta
session_start();
include('dotgo.class.php');
include('dotgo.admin.php');
$dotgo = new dotgoAdmin();
if( empty($_REQUEST['key']) ){
if( !empty($_SESSION['dotgo_key']) ){
if( $dotgo->authenticateAdmin($_SESSION['dotgo_key']) === false ){
die('did not authenticate');
}
}else{
die('admin key required!');
}
}elseif( $dotgo->authenticateAdmin($_REQUEST['key']) === true ){
$_SESSION['dotgo_key'] = $_REQUEST['key'];
header('location: '.$_SERVER['PHP_SELF']);
exit;
}else{
die('did not authenticate');
}
$dbConnected = $dotgo->dbConnect();
if( empty($dbConnected) ){
die('problem connecting to database: '.mysqli_connect_error());
}
$id = ( empty($_GET['id']) ) ? 0 : (int) $_GET['id'];
if( !empty($_REQUEST['formPosted']) ){
$newKeyword = ( !empty($_REQUEST['newKeyword']) ) ? $_REQUEST['newKeyword'] : '';
$content = ( !empty($_REQUEST['content']) ) ? $_REQUEST['content'] : '';
$type = ( !empty($_REQUEST['type']) ) ? $_REQUEST['type'] : '';
if( !empty($_REQUEST['remove']) ){
$dotgo->deleteKeyword($id);
header('location: '.$_SERVER['PHP_SELF']);
exit;
}
if( !empty($newKeyword) ){
$dotgo->addKeyword($newKeyword,$id);
}
if( empty($id) ){
if( empty($dotgo->helper) ){
header('location: '.$_SERVER['PHP_SELF']);
exit;
}
}else{
$dotgo->updateKeyword($id,$content,$type);
if( empty($dotgo->helper) ){
header('location: '.$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
}else{
}
$keywords = $dotgo->keywordList($id);
if( empty($id) ){
$dotgo->helper .= 'List of primary keywords, add a new keyword or select one already added.<br>';
}else{
$dotgo->helper .= 'List of child keywords, add new children if required.<br>';
$keyword = $dotgo->keywordDetail($id);
if( empty($keyword['id']) ){
header('location: '.$_SERVER['PHP_SELF']);
exit;
}elseif( empty($keyword['content']) ){
$dotgo->helper .= 'You need to add content for the selected response type.<br>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>dotgo administration</title>
<style>
a {
color: black;
text-decoration: underline;
}
a:hover {
color: red;
}
</style>
</head>
<body>
<h3>dotgo Administration</h3>
<div id="breadcrumb"><?PHP echo $dotgo->showBreadcrumb($id);?></div>
<div id="keywords" style="margin-top: 10px; margin-bottom: 10px;">
<strong>keywords...</strong><br>
<?php
if( !empty($keywords) ){
for($x=0;$x<count($keywords);$x++){
?>
<a href="?id=<?PHP echo $keywords[$x]['id'];?>"><?PHP echo $keywords[$x]['keyword'];?></a><br>
<?php
}
}else{
?>
none
<?php
}
?>
</div>
<form method="POST">
<label for="newKeyword">Add new keyword:</label> <input type="text" name="newKeyword"><br><br>
<?php
if( !empty($id) ){
?>
This is a
<input type="radio" name="type" value="msg"<?PHP echo ( $keyword['responseType'] == 'msg' ) ? ' checked' : '';?>> message
<input type="radio" name="type" value="qry"<?PHP echo ( $keyword['responseType'] == 'qry' ) ? ' checked' : '';?>> query
<input type="radio" name="type" value="ctm"<?PHP echo ( $keyword['responseType'] == 'ctm' ) ? ' checked' : '';?>> custom content
<input type="radio" name="type" value="rss"<?PHP echo ( $keyword['responseType'] == 'rss' ) ? ' checked' : '';?>> rss feed
<input type="radio" name="type" value="eng"<?PHP echo ( $keyword['responseType'] == 'eng' ) ? ' checked' : '';?>> engine<br>
<textarea name="content" style="width: 480px; height: 120px;"><?PHP echo $keyword['content'];?></textarea><br>
<?php
if( empty($keywords) ){
?>
<input type="checkbox" name="remove" value="1"> remove this keyword<br><br>
<?php
}
}
?>
<input type="hidden" name="formPosted" value="1"><input type="submit" name="formSubmit" value="Submit">
</form>
<hr>
<div id="helper"><strong>Notes...</strong><br><?PHP echo $dotgo->helper;?></div>
<?php
if( !empty($id) ){
?>
<div id="dotgoQuery" style="margin-top: 10px;"><strong>Text request: </strong><?PHP echo $dotgo->dotgoQuery;?> <strong>to</strong> <?PHP echo $dotgo->channel;?></div>
<div id="dotgoResponse" style="margin-top: 10px;"><strong>Response...</strong><br><?PHP echo str_replace('<','<',$dotgo->showResponse($keyword));?></div>
<?php
}
?>
</body>
</html>
|