diff --git a/app/contacts/app_config.php b/app/contacts/app_config.php index 77a88b7b0e..674cf4e00a 100644 --- a/app/contacts/app_config.php +++ b/app/contacts/app_config.php @@ -393,7 +393,7 @@ $y = 4; //table array index $apps[$x]['db'][$y]['table'] = "v_contact_groups"; - $apps[$x]['db'][$y]['fields'][$z]['name'] = "contact_groups_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "contact_group_uuid"; $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; @@ -418,7 +418,12 @@ $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "contact_uuid"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; $z++; - $apps[$x]['db'][$y]['fields'][$z]['name'] = "group_name"; - $apps[$x]['db'][$y]['fields'][$z]['type'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['name'] = "group_uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['pgsql'] = "uuid"; + $apps[$x]['db'][$y]['fields'][$z]['type']['sqlite'] = "text"; + $apps[$x]['db'][$y]['fields'][$z]['type']['mysql'] = "char(36)"; + $apps[$x]['db'][$y]['fields'][$z]['key']['type'] = "foreign"; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['table'] = "v_groups"; + $apps[$x]['db'][$y]['fields'][$z]['key']['reference']['field'] = "group_uuid"; $apps[$x]['db'][$y]['fields'][$z]['description']['en-us'] = ""; ?> diff --git a/app/contacts/app_languages.php b/app/contacts/app_languages.php index 167c4167a8..ebced4445b 100644 --- a/app/contacts/app_languages.php +++ b/app/contacts/app_languages.php @@ -183,6 +183,16 @@ $text['description-contact_note']['pt-pt'] = "Introduza uma nota."; $text['description-contact_note']['fr-fr'] = ""; + $text['label-groups']['en-us'] = "Groups"; + $text['label-groups']['es-cl'] = "Grupos"; + $text['label-groups']['pt-pt'] = "Grupos"; + $text['label-groups']['fr-fr'] = "Groupes"; + + $text['description-groups']['en-us'] = "Contacts assigned to a Group will be visible to all Users in the Group."; + $text['description-groups']['es-cl'] = "Contactos asignados a un grupo serán visibles por todos los usuarios del grupo."; + $text['description-groups']['pt-pt'] = "Contatos atribuídos a um grupo será visível por todos os usuários do grupo."; + $text['description-groups']['fr-fr'] = "Contacts affectés à un groupe seront visibles par tous les utilisateurs du groupe."; + $text['button-qr_code']['en-us'] = "QR Code"; $text['button-qr_code']['es-cl'] = "Código QR"; $text['button-qr_code']['pt-pt'] = "Código QR."; diff --git a/app/contacts/contact_edit.php b/app/contacts/contact_edit.php index d54171d408..9b88415d35 100644 --- a/app/contacts/contact_edit.php +++ b/app/contacts/contact_edit.php @@ -40,6 +40,21 @@ else { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } +//handle removal of contact group + if ($_GET['a'] == 'delete') { + $contact_uuid = $_GET["id"]; + $contact_group_uuid = $_GET["cgid"]; + $sql = "delete from v_contact_groups "; + $sql .= "where contact_uuid = '".$contact_uuid."' "; + $sql .= "and contact_group_uuid = '".$contact_group_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + + $_SESSION["message"] = $text['message-update']; + header("Location: contact_edit.php?id=".$contact_uuid); + exit; + } + //action add or update if (isset($_REQUEST["id"])) { $action = "update"; @@ -99,10 +114,11 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { //add or update the database if ($_POST["persistformvar"] != "true") { + if ($action == "add") { $contact_uuid = uuid(); $sql = "insert into v_contacts "; - $sql .= "("; + $sql .= "( "; $sql .= "domain_uuid, "; $sql .= "contact_uuid, "; $sql .= "contact_type, "; @@ -117,55 +133,85 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $sql .= "contact_url, "; $sql .= "contact_time_zone, "; $sql .= "contact_note "; - $sql .= ")"; + $sql .= ") "; $sql .= "values "; - $sql .= "("; + $sql .= "( "; $sql .= "'".$_SESSION['domain_uuid']."', "; - $sql .= "'$contact_uuid', "; - $sql .= "'$contact_type', "; - $sql .= "'$contact_organization', "; - $sql .= "'$contact_name_given', "; - $sql .= "'$contact_name_family', "; - $sql .= "'$contact_nickname', "; - $sql .= "'$contact_title', "; - $sql .= "'$contact_category', "; - $sql .= "'$contact_role', "; - $sql .= "'$contact_email', "; - $sql .= "'$contact_url', "; - $sql .= "'$contact_time_zone', "; - $sql .= "'$contact_note' "; + $sql .= "'".$contact_uuid."', "; + $sql .= "'".$contact_type."', "; + $sql .= "'".$contact_organization."', "; + $sql .= "'".$contact_name_given."', "; + $sql .= "'".$contact_name_family."', "; + $sql .= "'".$contact_nickname."', "; + $sql .= "'".$contact_title."', "; + $sql .= "'".$contact_category."', "; + $sql .= "'".$contact_role."', "; + $sql .= "'".$contact_email."', "; + $sql .= "'".$contact_url."', "; + $sql .= "'".$contact_time_zone."', "; + $sql .= "'".$contact_note."' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-add']; - header("Location: contacts.php"); - return; + $location = "contacts.php"; } //if ($action == "add") + //handle insertion of contact group + if ($_POST['group_uuid'] != '') { + $group_uuid = $_POST["group_uuid"]; + $sql = "insert into v_contact_groups "; + $sql .= "( "; + $sql .= "contact_group_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "contact_uuid, "; + $sql .= "group_uuid "; + $sql .= ") "; + $sql .= "values "; + $sql .= "( "; + $sql .= "'".uuid()."', "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$contact_uuid."', "; + $sql .= "'".$group_uuid."' "; + $sql .= ") "; + $db->exec(check_sql($sql)); + unset($sql); + } + if ($action == "update") { $sql = "update v_contacts set "; - $sql .= "contact_type = '$contact_type', "; - $sql .= "contact_organization = '$contact_organization', "; - $sql .= "contact_name_given = '$contact_name_given', "; - $sql .= "contact_name_family = '$contact_name_family', "; - $sql .= "contact_nickname = '$contact_nickname', "; - $sql .= "contact_title = '$contact_title', "; - $sql .= "contact_category = '$contact_category', "; - $sql .= "contact_role = '$contact_role', "; - $sql .= "contact_email = '$contact_email', "; - $sql .= "contact_url = '$contact_url', "; - $sql .= "contact_time_zone = '$contact_time_zone', "; - $sql .= "contact_note = '$contact_note' "; - $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; - $sql .= "and contact_uuid = '$contact_uuid' "; + $sql .= "contact_type = '".$contact_type."', "; + $sql .= "contact_organization = '".$contact_organization."', "; + $sql .= "contact_name_given = '".$contact_name_given."', "; + $sql .= "contact_name_family = '".$contact_name_family."', "; + $sql .= "contact_nickname = '".$contact_nickname."', "; + $sql .= "contact_title = '".$contact_title."', "; + $sql .= "contact_category = '".$contact_category."', "; + $sql .= "contact_role = '".$contact_role."', "; + $sql .= "contact_email = '".$contact_email."', "; + $sql .= "contact_url = '".$contact_url."', "; + $sql .= "contact_time_zone = '".$contact_time_zone."', "; + $sql .= "contact_note = '".$contact_note."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and contact_uuid = '".$contact_uuid."' "; $db->exec(check_sql($sql)); unset($sql); $_SESSION["message"] = $text['message-update']; - header("Location: contacts.php"); - return; + $location = "contacts.php"; } //if ($action == "update") + + //handle redirect + if ($_POST['submit'] == $text['button-add']) { + $group_uuid = $_POST['group_uuid']; + //insert + $location = "contact_edit.php?id=".$contact_uuid; + } + + header("Location: ".$location); + return; + } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -256,15 +302,8 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo ""; //show the content - echo "
"; echo "
\n"; echo "\n"; - echo "\n"; - echo " "; - echo " "; - echo "
\n"; - echo "
"; - - echo "
\n"; - echo "\n"; echo "\n"; echo "\n"; echo "\n"; + if (permission_exists('contact_group_view')) { + echo ""; + echo " "; + echo " "; + echo ""; + } + echo "\n"; echo "\n"; echo "
"; switch ($action) { @@ -563,6 +602,82 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "
".$text['label-groups'].":"; + + $sql = "select "; + $sql .= "g.*, "; + $sql .= "cg.contact_group_uuid "; + $sql .= "from "; + $sql .= "v_groups as g, "; + $sql .= "v_contact_groups as cg "; + $sql .= "where "; + $sql .= "cg.group_uuid = g.group_uuid "; + $sql .= "and g.domain_uuid = '".$domain_uuid."' "; + $sql .= "and cg.domain_uuid = '".$domain_uuid."' "; + $sql .= "and cg.contact_uuid = '".$contact_uuid."' "; + $sql .= "order by g.group_name asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + if ($result_count > 0) { + echo " \n"; + foreach($result as $field) { + if (strlen($field['group_name']) > 0) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; + $assigned_groups[] = $field['group_uuid']; + } + } + echo "
".$field['group_name']."\n"; + if (permission_exists('contact_group_delete') || if_group("superadmin")) { + echo " $v_link_label_delete\n"; + } + echo "
\n"; + echo "
\n"; + } + unset($sql, $prep_statement, $result, $field); + + if (permission_exists('contact_group_add') || if_group("superadmin")) { + $sql = "select * from v_groups "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + if (sizeof($assigned_groups) > 0) { + $sql .= "and group_uuid not in ('".implode("','",$assigned_groups)."') "; + } + $sql .= "order by group_name asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + if ($result_count > 0) { + echo " "; + + if ($action == "update") { + echo " \n"; + } + echo "
"; + } + unset($sql, $prep_statement, $result, $field); + } + + echo " ".$text['description-groups']."\n"; + + echo "
\n"; echo " ".$text['label-contact_note'].":\n"; @@ -599,17 +714,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { echo "
\n"; - - if ($action == "update") { - echo "
\n"; - - } - - echo "
"; echo "
"; - echo "
"; //include the footer require_once "resources/footer.php";