Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists('contact_relation_edit') || permission_exists('contact_relation_add')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $contact_relation_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //get the contact uuid if (strlen($_GET["contact_uuid"]) > 0) { $contact_uuid = check_str($_GET["contact_uuid"]); } //get http post variables and set them to php variables if (count($_POST)>0) { $relation_label = check_str($_POST["relation_label"]); $relation_label_custom = check_str($_POST["relation_label_custom"]); $relation_contact_uuid = check_str($_POST["relation_contact_uuid"]); $relation_reciprocal = check_str($_POST["relation_reciprocal"]); $relation_reciprocal_label = check_str($_POST["relation_reciprocal_label"]); $relation_reciprocal_label_custom = check_str($_POST["relation_reciprocal_label_custom"]); //use custom label(s), if set $relation_label = ($relation_label_custom != '') ? $relation_label_custom : $relation_label; $relation_reciprocal_label = ($relation_reciprocal_label_custom != '') ? $relation_reciprocal_label_custom : $relation_reciprocal_label; } //process the form data if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //set the uuid if ($action == "update") { $contact_relation_uuid = check_str($_POST["contact_relation_uuid"]); } //check for all required data $msg = ''; 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 or update the database if ($_POST["persistformvar"] != "true") { //update last modified $sql = "update v_contacts set "; $sql .= "last_mod_date = now(), "; $sql .= "last_mod_user = '".$_SESSION['username']."' "; $sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "and contact_uuid = '".$contact_uuid."' "; $db->exec(check_sql($sql)); unset($sql); if ($action == "add") { $contact_relation_uuid = uuid(); $sql = "insert into v_contact_relations "; $sql .= "("; $sql .= "contact_relation_uuid, "; $sql .= "domain_uuid, "; $sql .= "contact_uuid, "; $sql .= "relation_label, "; $sql .= "relation_contact_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'".$contact_relation_uuid."', "; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'".$contact_uuid."', "; $sql .= "'".$relation_label."', "; $sql .= "'".$relation_contact_uuid."' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); if ($relation_reciprocal) { $contact_relation_uuid = uuid(); $sql = "insert into v_contact_relations "; $sql .= "("; $sql .= "contact_relation_uuid, "; $sql .= "domain_uuid, "; $sql .= "contact_uuid, "; $sql .= "relation_label, "; $sql .= "relation_contact_uuid "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'".$contact_relation_uuid."', "; $sql .= "'".$_SESSION['domain_uuid']."', "; $sql .= "'".$relation_contact_uuid."', "; $sql .= "'".$relation_reciprocal_label."', "; $sql .= "'".$contact_uuid."' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } $_SESSION["message"] = $text['message-add']; header("Location: contact_edit.php?id=".$contact_uuid); return; } //if ($action == "add") if ($action == "update") { $sql = "update v_contact_relations set "; $sql .= "relation_label = '".$relation_label."', "; $sql .= "relation_contact_uuid = '".$relation_contact_uuid."' "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and contact_relation_uuid = '".$contact_relation_uuid."'"; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-update']; header("Location: contact_edit.php?id=".$contact_uuid); return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $contact_relation_uuid = $_GET["id"]; $sql = "select * from v_contact_relations "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and contact_relation_uuid = '".$contact_relation_uuid."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $relation_label = $row["relation_label"]; $relation_contact_uuid = $row["relation_contact_uuid"]; break; //limit to 1 row } unset ($prep_statement); } //show the header $document['title'] = $text['title-contact_relation']; require_once "resources/header.php"; //javascript to toggle input/select boxes echo ""; //show the content echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
"; echo " ".$text['header-contact_relation'].""; echo ""; echo " "; 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 ($action == 'add') { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-contact_relation_label']."\n"; echo "\n"; if (is_array($_SESSION["contact"]["relation_label"])) { sort($_SESSION["contact"]["relation_label"]); foreach($_SESSION["contact"]["relation_label"] as $row) { $relation_label_options[] = ""; } $relation_label_found = (in_array($relation_label, $_SESSION["contact"]["relation_label"])) ? true : false; } else { $selected[$relation_label] = "selected"; $default_labels[] = $text['label-contact_relation_option_parent']; $default_labels[] = $text['label-contact_relation_option_child']; $default_labels[] = $text['label-contact_relation_option_employee']; $default_labels[] = $text['label-contact_relation_option_member']; $default_labels[] = $text['label-contact_relation_option_associate']; $default_labels[] = $text['label-contact_relation_option_other']; foreach ($default_labels as $default_label) { $relation_label_options[] = ""; } $relation_label_found = (in_array($relation_label, $default_labels)) ? true : false; } echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-relation_label']."\n"; echo "
\n"; echo " ".$text['label-contact_relation_contact']."\n"; echo "\n"; $sql = "select contact_uuid, contact_organization, contact_name_given, contact_name_family from v_contacts "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and contact_uuid <> '".$contact_uuid."' "; $sql .= "order by contact_organization desc, contact_name_given asc, contact_name_family asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset ($prep_statement, $sql); echo "\n"; // echo "
\n"; // echo $text['description-related_contact']."\n"; echo "
\n"; echo " ".$text['label-contact_relation_reciprocal']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-contact_relation_reciprocal']."\n"; echo "
\n"; echo "\n"; echo "\n"; } echo " \n"; echo " \n"; echo " "; echo "
\n"; echo "
\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo "

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