Portions created by the Initial Developer are Copyright (C) 2018 - 2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; //check permissions require_once "resources/check_auth.php"; if (permission_exists('message_add') || permission_exists('message_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (is_uuid($_REQUEST["id"])) { $action = "update"; $message_uuid = $_REQUEST["id"]; } else { $action = "add"; } //get http post variables and set them to php variables if (is_array($_POST)) { $message_uuid = $_POST["message_uuid"]; //$user_uuid = $_POST["user_uuid"]; $message_type = $_POST["message_type"]; $message_direction = $_POST["message_direction"]; $message_date = $_POST["message_date"]; $message_from = $_POST["message_from"]; $message_to = $_POST["message_to"]; $message_text = $_POST["message_text"]; $message_media_type = $_POST["message_media_type"]; $message_media_url = $_POST["message_media_url"]; $message_media_content = $_POST["message_media_content"]; $message_json = $_POST["message_json"]; } //process the user data and save it to the database if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the uuid from the POST if ($action == "update") { $message_uuid = $_POST["message_uuid"]; } //check for all required data $msg = ''; //if (strlen($user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-user_uuid']."
\n"; } if (strlen($message_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_type']."
\n"; } if (strlen($message_direction) == 0) { $msg .= $text['message-required']." ".$text['label-message_direction']."
\n"; } if (strlen($message_date) == 0) { $msg .= $text['message-required']." ".$text['label-message_date']."
\n"; } if (strlen($message_from) == 0) { $msg .= $text['message-required']." ".$text['label-message_from']."
\n"; } if (strlen($message_to) == 0) { $msg .= $text['message-required']." ".$text['label-message_to']."
\n"; } //if (strlen($message_text) == 0) { $msg .= $text['message-required']." ".$text['label-message_text']."
\n"; } //if (strlen($message_media_type) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_type']."
\n"; } //if (strlen($message_media_url) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_url']."
\n"; } //if (strlen($message_media_content) == 0) { $msg .= $text['message-required']." ".$text['label-message_media_content']."
\n"; } //if (strlen($message_json) == 0) { $msg .= $text['message-required']." ".$text['label-message_json']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add the message_uuid if (!is_uuid($_POST["message_uuid"])) { $message_uuid = uuid(); } //prepare the array $array['messages'][0]['domain_uuid'] = $_SESSION["domain_uuid"];; $array['messages'][0]['user_uuid'] = $user_uuid; $array['messages'][0]['message_uuid'] = $message_uuid; $array['messages'][0]['message_type'] = $message_type; $array['messages'][0]['message_direction'] = $message_direction; $array['messages'][0]['message_date'] = $message_date; $array['messages'][0]['message_from'] = $message_from; $array['messages'][0]['message_to'] = $message_to; $array['messages'][0]['message_text'] = $message_text; $array['messages'][0]['message_uuid'] = $message_uuid; //save to the data $database = new database; $database->app_name = 'messages'; $database->app_uuid = '4a20815d-042c-47c8-85df-085333e79b87'; $database->save($array); //redirect the user if (isset($action)) { if ($action == "add") { message::add($text['message-add']); } if ($action == "update") { message::add($text['message-update']); } header('Location: message_edit.php?id='.$message_uuid); exit; } } //pre-populate the form if (is_array($_GET) && $_POST["persistformvar"] != "true") { $message_uuid = $_GET["id"]; $sql = "select * from v_messages "; $sql .= "where message_uuid = :message_uuid "; $parameters['message_uuid'] = $message_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $user_uuid = $row["user_uuid"]; $message_type = $row["message_type"]; $message_direction = $row["message_direction"]; $message_date = $row["message_date"]; $message_from = $row["message_from"]; $message_to = $row["message_to"]; $message_text = $row["message_text"]; $message_media_type = $row["message_media_type"]; $message_media_url = $row["message_media_url"]; $message_media_content = $row["message_media_content"]; $message_json = $row["message_json"]; } unset($sql, $parameters); } //show the header require_once "resources/header.php"; //get the users $sql = "select user_uuid, username from v_users "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and user_enabled = 'true' "; $sql .= "order by username asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $users = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //show the content echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (strlen($message_media_type) > 0) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; } if ($_GET['debug'] == 'true') { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } echo " \n"; echo " \n"; echo " "; echo "
".$text['title-message']."

\n"; echo " "; echo " "; echo "
\n"; echo " ".$text['label-username']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-username']."\n"; echo "
\n"; echo " ".$text['label-message_type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_type']."\n"; echo "
\n"; echo " ".$text['label-message_direction']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_direction']."\n"; echo "
\n"; echo " ".$text['label-message_date']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_date']."\n"; echo "
\n"; echo " ".$text['label-message_from']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_from']."\n"; echo "
\n"; echo " ".$text['label-message_to']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_to']."\n"; echo "
\n"; echo " ".$text['label-message_text']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_text']."\n"; echo "
\n"; echo "  \n"; echo "\n"; $image_source = 'data: '.mime_content_type($message_media_type).';base64,'.$message_media_content; echo ""; echo "
\n"; echo "
\n"; echo " ".$text['label-message_media_type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_media_type']."\n"; echo "
\n"; echo " ".$text['label-message_media_url']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_media_url']."\n"; echo "
\n"; echo " ".$text['label-message_media_content']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_media_content']."\n"; echo "
\n"; echo " ".$text['label-message_json']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-message_json']."\n"; echo "
\n"; echo " \n"; echo " \n"; echo "
"; echo "
"; echo "

"; //include the footer require_once "resources/footer.php"; ?>