Portions created by the Initial Developer are Copyright (C) 2018 - 2022
the Initial Developer. All Rights Reserved.
*/
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('contact_add') || permission_exists('contact_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";
$contact_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (is_array($_POST)) {
$contact_organization = $_POST["contact_organization"];
$contact_name_prefix = $_POST["contact_name_prefix"];
$contact_name_given = $_POST["contact_name_given"];
$contact_name_middle = $_POST["contact_name_middle"];
$contact_name_family = $_POST["contact_name_family"];
$contact_name_suffix = $_POST["contact_name_suffix"];
$contact_nickname = $_POST["contact_nickname"];
$contact_type = $_POST["contact_type"];
$contact_title = $_POST["contact_title"];
$contact_role = $_POST["contact_role"];
$contact_category = $_POST["contact_category"];
$contact_time_zone = $_POST["contact_time_zone"];
$contact_note = $_POST["contact_note"];
$last_mod_date = $_POST["last_mod_date"];
$last_mod_user = $_POST["last_mod_user"];
//$contact_users = $_POST["contact_users"];
//$contact_groups = $_POST["contact_groups"];
$contact_user_uuid = $_POST["contact_user_uuid"];
$contact_group_uuid = $_POST["contact_group_uuid"];
$contact_phones = $_POST["contact_phones"];
$contact_addresses = $_POST["contact_addresses"];
$contact_emails = $_POST["contact_emails"];
$contact_urls = $_POST["contact_urls"];
$contact_relations = $_POST["contact_relations"];
$contact_settings = $_POST["contact_settings"];
$contact_attachments = $_POST["contact_attachments"];
$contact_times = $_POST["contact_times"];
$contact_notes = $_POST["contact_notes"];
}
//process the user data and save it to the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//debug info
//view_array($_POST, true);
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: contacts.php');
exit;
}
//process the http post data by submitted action
if ($_POST['action'] != '' && strlen($_POST['action']) > 0) {
//prepare the array(s)
$x = 0;
foreach ($_POST['contact_users'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_users'][]['contact_user_uuid'] = $row['contact_user_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_groups'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_groups'][]['contact_group_uuid'] = $row['contact_group_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_phones'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_phones'][]['contact_phone_uuid'] = $row['contact_phone_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_addresses'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_addresses'][]['contact_address_uuid'] = $row['contact_address_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_emails'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_emails'][]['contact_email_uuid'] = $row['contact_email_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_urls'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_urls'][]['contact_url_uuid'] = $row['contact_url_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_relations'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_relations'][]['contact_relation_uuid'] = $row['contact_relation_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_settings'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_settings'][]['contact_setting_uuid'] = $row['contact_setting_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_attachments'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_attachments'][]['contact_attachment_uuid'] = $row['contact_attachment_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_times'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_times'][]['contact_time_uuid'] = $row['contact_time_uuid'];
$x++;
}
}
$x = 0;
foreach ($_POST['contact_notes'] as $row) {
if (is_uuid($row['contact_uuid']) && $row['checked'] === 'true') {
$array['contacts'][$x]['checked'] = $row['checked'];
$array['contacts'][$x]['contact_notes'][]['contact_note_uuid'] = $row['contact_note_uuid'];
$x++;
}
}
//send the array to the database class
switch ($_POST['action']) {
case 'copy':
if (permission_exists('contact_add')) {
$obj = new database;
$obj->copy($array);
}
break;
case 'delete':
if (permission_exists('contact_delete')) {
$obj = new database;
$obj->delete($array);
}
break;
case 'toggle':
if (permission_exists('contact_update')) {
$obj = new database;
$obj->toggle($array);
}
break;
}
//redirect the user
if (in_array($_POST['action'], array('copy', 'delete', 'toggle'))) {
header('Location: contact_edit.php?id='.$id);
exit;
}
}
//check for all required data
$msg = '';
//if (strlen($contact_type) == 0) { $msg .= $text['message-required']." ".$text['label-contact_type']."
\n"; }
//if (strlen($contact_title) == 0) { $msg .= $text['message-required']." ".$text['label-contact_title']."
\n"; }
//if (strlen($contact_role) == 0) { $msg .= $text['message-required']." ".$text['label-contact_role']."
\n"; }
//if (strlen($contact_category) == 0) { $msg .= $text['message-required']." ".$text['label-contact_category']."
\n"; }
//if (strlen($contact_organization) == 0) { $msg .= $text['message-required']." ".$text['label-contact_organization']."
\n"; }
//if (strlen($contact_name_prefix) == 0) { $msg .= $text['message-required']." ".$text['label-contact_name_prefix']."
\n"; }
//if (strlen($contact_name_given) == 0) { $msg .= $text['message-required']." ".$text['label-contact_name_given']."
\n"; }
//if (strlen($contact_name_middle) == 0) { $msg .= $text['message-required']." ".$text['label-contact_name_middle']."
\n"; }
//if (strlen($contact_name_family) == 0) { $msg .= $text['message-required']." ".$text['label-contact_name_family']."
\n"; }
//if (strlen($contact_name_suffix) == 0) { $msg .= $text['message-required']." ".$text['label-contact_name_suffix']."
\n"; }
//if (strlen($contact_nickname) == 0) { $msg .= $text['message-required']." ".$text['label-contact_nickname']."
\n"; }
//if (strlen($contact_time_zone) == 0) { $msg .= $text['message-required']." ".$text['label-contact_time_zone']."
\n"; }
//if (strlen($last_mod_date) == 0) { $msg .= $text['message-required']." ".$text['label-last_mod_date']."
\n"; }
//if (strlen($last_mod_user) == 0) { $msg .= $text['message-required']." ".$text['label-last_mod_user']."
\n"; }
//if (strlen($contact_phones) == 0) { $msg .= $text['message-required']." ".$text['label-contact_phones']."
\n"; }
//if (strlen($contact_addresses) == 0) { $msg .= $text['message-required']." ".$text['label-contact_addresses']."
\n"; }
//if (strlen($contact_emails) == 0) { $msg .= $text['message-required']." ".$text['label-contact_emails']."
\n"; }
//if (strlen($contact_urls) == 0) { $msg .= $text['message-required']." ".$text['label-contact_urls']."
\n"; }
//if (strlen($contact_settings) == 0) { $msg .= $text['message-required']." ".$text['label-contact_settings']."
\n"; }
//if (strlen($contact_user_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-contact_user_uuid']."
\n"; }
//if (strlen($contact_group_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-contact_group_uuid']."
\n"; }
//if (strlen($contact_note) == 0) { $msg .= $text['message-required']." ".$text['label-contact_note']."
\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
\n";
echo $msg." "; echo " |