132 lines
4.0 KiB
PHP
132 lines
4.0 KiB
PHP
<?php
|
|
require_once("include/globals.php");
|
|
|
|
if (SessionActive() != 1 || ! UserLoggedIn()) {
|
|
header("Location: /");
|
|
exit();
|
|
}
|
|
|
|
// Start the template and output buffering
|
|
startTemplate();
|
|
$templatePageTitle = "Language Text Entry and Administration";
|
|
|
|
|
|
// Ensure that only valid user types have access to this module
|
|
$AllowedUserTypes = array('SuperUser');
|
|
if (checkPermission($AllowedUserTypes) != 1) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
include "form.messages.php";
|
|
endTemplate();
|
|
exit();
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Process all actions to list and edit records
|
|
//
|
|
$naction = "";
|
|
|
|
|
|
|
|
if (array_key_exists('naction',$_GET)) $naction = $_GET['naction'];
|
|
if (array_key_exists('naction',$_POST)) $naction = $_POST['naction'];
|
|
|
|
$maxEntries = 1000;
|
|
|
|
switch (strtolower($naction)) {
|
|
case "update":
|
|
|
|
$table = new Table("language_text");
|
|
$error_message = "";
|
|
|
|
// Loop through the fields and update the database
|
|
for ($i = 0; $i < $maxEntries; $i++) {
|
|
$english = $_POST["english$i"];
|
|
$french = $_POST["french$i"];
|
|
$message_id = str_replace(' ','-',strtoupper($_POST["message_id$i"]));
|
|
$record_num = intval($_POST["record_num$i"]);
|
|
|
|
if (preg_match("/MENUTAB/",$message_id)) $french = strtoupper($french);
|
|
|
|
// If data has been entered save it to the database
|
|
if (strlen($message_id)) {
|
|
if (strlen($english) > 0) {
|
|
if ($record_num > 0 && is_numeric($record_num)) {
|
|
$query = $table->BuildUpdate();
|
|
db_query($query);
|
|
}
|
|
else {
|
|
// Check if this id is in use already
|
|
$results = db_query("SELECT * FROM language_text WHERE message_id = '$message_id'");
|
|
if (db_num_rows($results) == 0) {
|
|
$access_count = 0;
|
|
$query = $table->BuildInsert();
|
|
db_query($query);
|
|
}
|
|
else {
|
|
if (strlen($error_message)) $message_id .= "<br>\n";
|
|
$error_message .= "Duplicate: $message_id";
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
db_query("DELETE FROM language_text WHERE message_id = '$message_id'");
|
|
}
|
|
}
|
|
}
|
|
|
|
break;
|
|
|
|
case "fetch":
|
|
$s_english = db_escape_string($_POST['s_english']);
|
|
$s_french = db_escape_string($_POST['s_french']);
|
|
$s_message_id = $_POST['s_message_id'];
|
|
|
|
$where = "";
|
|
|
|
// Search by English text
|
|
if (strlen($s_english) > 0) {
|
|
$s_english = preg_replace("/\*/","%",$s_english);
|
|
if (strlen($where) > 0) $where .= "AND ";
|
|
$where .= "english LIKE '$s_english' ";
|
|
}
|
|
|
|
// Search by French text
|
|
if (strlen($s_french) > 0) {
|
|
$s_french = preg_replace("/\*/","%",$s_french);
|
|
if (strlen($where) > 0) $where .= "AND ";
|
|
$where .= "french LIKE '$s_french' ";
|
|
}
|
|
|
|
// Search by message_id
|
|
if (strlen($s_message_id) > 0) {
|
|
$s_message_id = preg_replace("/\*/","%",$s_message_id);
|
|
if (strlen($where) > 0) $where .= "AND ";
|
|
$where .= "message_id LIKE '$s_message_id' ";
|
|
}
|
|
|
|
// Search for entries with no French text
|
|
if (array_key_exists('no_french',$_POST) && $_POST['no_french'] == 'Y') {
|
|
if (strlen($where) > 0) $where .= "AND ";
|
|
$where .= "(french IS NULL OR french = '') ";
|
|
}
|
|
|
|
if (strlen($where) > 0) $where = "WHERE $where";
|
|
$results = db_query("SELECT * FROM language_text $where ORDER BY english,message_id");
|
|
|
|
if (db_num_rows($results) > 0) {
|
|
$languageData = array();
|
|
while ($row = db_fetch_array($results)) {
|
|
$languageData[] = $row;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
|
|
// Display the selected menu form
|
|
include "language.text.form.php";
|
|
|
|
endTemplate();
|
|
?>
|