diff --git a/core/users/app_languages.php b/core/users/app_languages.php index d5791dd40d..b2d3fba6a2 100644 --- a/core/users/app_languages.php +++ b/core/users/app_languages.php @@ -2918,3 +2918,138 @@ $text['button-permissions']['tr-tr'] = "İzinler"; $text['button-permissions']['zh-cn'] = "权限"; $text['button-permissions']['ja-jp'] = "パーミッション"; $text['button-permissions']['ko-kr'] = "권한"; + +$text['label-phone']['en-us'] = "Phone"; +$text['label-phone']['en-gb'] = "Phone"; +$text['label-phone']['ar-eg'] = "رقم التليفون"; +$text['label-phone']['de-at'] = "Nummer"; +$text['label-phone']['de-ch'] = "Nummer"; +$text['label-phone']['de-de'] = "Nummer"; +$text['label-phone']['el-gr'] = "Αριθμός τηλεφώνου"; +$text['label-phone']['es-cl'] = "Número"; +$text['label-phone']['es-mx'] = "Número"; +$text['label-phone']['fr-ca'] = "Numéro"; +$text['label-phone']['fr-fr'] = "Numéro"; +$text['label-phone']['he-il'] = "מספר טלפון"; +$text['label-phone']['it-it'] = "Numero"; +$text['label-phone']['ka-ge'] = "ტელეფონის ნომერი"; +$text['label-phone']['nl-nl'] = "Telefoonnummer"; +$text['label-phone']['pl-pl'] = "Numer"; +$text['label-phone']['pt-br'] = "Número"; +$text['label-phone']['pt-pt'] = "Número"; +$text['label-phone']['ro-ro'] = "Număr de telefon"; +$text['label-phone']['ru-ru'] = "Номер"; +$text['label-phone']['sv-se'] = "Nummer"; +$text['label-phone']['uk-ua'] = "Номер"; +$text['label-phone']['tr-tr'] = "Telefon Numarası"; +$text['label-phone']['zh-cn'] = "电话号码"; +$text['label-phone']['ja-jp'] = "電話番号"; +$text['label-phone']['ko-kr'] = "전화 번호"; + +$text['label-address_locality']['en-us'] = "City"; +$text['label-address_locality']['en-gb'] = "City"; +$text['label-address_locality']['ar-eg'] = "مدينة"; +$text['label-address_locality']['de-at'] = "Stadt"; +$text['label-address_locality']['de-ch'] = "Stadt"; +$text['label-address_locality']['de-de'] = "Stadt"; +$text['label-address_locality']['el-gr'] = "Πόλη"; +$text['label-address_locality']['es-cl'] = "Ciudad"; +$text['label-address_locality']['es-mx'] = "Ciudad"; +$text['label-address_locality']['fr-ca'] = "Ville"; +$text['label-address_locality']['fr-fr'] = "Ville"; +$text['label-address_locality']['he-il'] = "עִיר"; +$text['label-address_locality']['it-it'] = "Città"; +$text['label-address_locality']['ka-ge'] = "ქალაქი"; +$text['label-address_locality']['nl-nl'] = "Stad"; +$text['label-address_locality']['pl-pl'] = "Miasto"; +$text['label-address_locality']['pt-br'] = "Cidade"; +$text['label-address_locality']['pt-pt'] = "Cidade"; +$text['label-address_locality']['ro-ro'] = "Oraş"; +$text['label-address_locality']['ru-ru'] = "Город"; +$text['label-address_locality']['sv-se'] = "Stad"; +$text['label-address_locality']['uk-ua'] = "Місто"; +$text['label-address_locality']['tr-tr'] = "Şehir"; +$text['label-address_locality']['zh-cn'] = "城市"; +$text['label-address_locality']['ja-jp'] = "市"; +$text['label-address_locality']['ko-kr'] = "도시"; + +$text['label-region']['en-us'] = "Region"; +$text['label-region']['en-gb'] = "Region"; +$text['label-region']['ar-eg'] = "منطقة"; +$text['label-region']['de-at'] = "Region"; +$text['label-region']['de-ch'] = "Region"; +$text['label-region']['de-de'] = "Region"; +$text['label-region']['el-gr'] = "Περιοχή"; +$text['label-region']['es-cl'] = "Región"; +$text['label-region']['es-mx'] = "Región"; +$text['label-region']['fr-ca'] = "Région"; +$text['label-region']['fr-fr'] = "Région"; +$text['label-region']['he-il'] = "אזור"; +$text['label-region']['it-it'] = "Regione"; +$text['label-region']['ka-ge'] = "რეგიონი"; +$text['label-region']['nl-nl'] = "Regio"; +$text['label-region']['pl-pl'] = "Region"; +$text['label-region']['pt-br'] = "Região"; +$text['label-region']['pt-pt'] = "Região"; +$text['label-region']['ro-ro'] = "Regiune"; +$text['label-region']['ru-ru'] = "Область"; +$text['label-region']['sv-se'] = "Område"; +$text['label-region']['tr-tr'] = "Bölge"; +$text['label-region']['uk-ua'] = "Регіон"; +$text['label-region']['zh-cn'] = "地區"; +$text['label-region']['ja-jp'] = "領域"; +$text['label-region']['ko-kr'] = "지역"; + +$text['label-address_country']['en-us'] = "Country"; +$text['label-address_country']['en-gb'] = "Country"; +$text['label-address_country']['ar-eg'] = "دولة"; +$text['label-address_country']['de-at'] = "Land"; +$text['label-address_country']['de-ch'] = "Land"; +$text['label-address_country']['de-de'] = "Land"; +$text['label-address_country']['el-gr'] = "Χώρα"; +$text['label-address_country']['es-cl'] = "País"; +$text['label-address_country']['es-mx'] = "País"; +$text['label-address_country']['fr-ca'] = "Pays"; +$text['label-address_country']['fr-fr'] = "Pays"; +$text['label-address_country']['he-il'] = "מְדִינָה"; +$text['label-address_country']['it-it'] = "Paese"; +$text['label-address_country']['ka-ge'] = "ქვეყანა"; +$text['label-address_country']['nl-nl'] = "Land"; +$text['label-address_country']['pl-pl'] = "Kraj"; +$text['label-address_country']['pt-br'] = "País"; +$text['label-address_country']['pt-pt'] = "País"; +$text['label-address_country']['ro-ro'] = "Ţară"; +$text['label-address_country']['ru-ru'] = "Страна"; +$text['label-address_country']['sv-se'] = "Land"; +$text['label-address_country']['uk-ua'] = "Країна"; +$text['label-address_country']['tr-tr'] = "Ülke"; +$text['label-address_country']['zh-cn'] = "国家"; +$text['label-address_country']['ja-jp'] = "国"; +$text['label-address_country']['ko-kr'] = "국가"; + +$text['label-photo']['en-us'] = "Photo"; +$text['label-photo']['en-gb'] = "Photo"; +$text['label-photo']['ar-eg'] = "صورة"; +$text['label-photo']['de-at'] = "Foto"; +$text['label-photo']['de-ch'] = "Foto"; +$text['label-photo']['de-de'] = "Foto"; +$text['label-photo']['el-gr'] = "Foto"; +$text['label-photo']['es-cl'] = "Foto"; +$text['label-photo']['es-mx'] = "Foto"; +$text['label-photo']['fr-ca'] = "Photo"; +$text['label-photo']['fr-fr'] = "Photo"; +$text['label-photo']['he-il'] = "תַצלוּם"; +$text['label-photo']['it-it'] = "Foto"; +$text['label-photo']['ka-ge'] = "ფოტო"; +$text['label-photo']['nl-nl'] = "Foto"; +$text['label-photo']['pl-pl'] = "Zdjęcie"; +$text['label-photo']['pt-br'] = "Foto"; +$text['label-photo']['pt-pt'] = "Fotografia"; +$text['label-photo']['ro-ro'] = "Fotografie"; +$text['label-photo']['ru-ru'] = "Фото"; +$text['label-photo']['sv-se'] = "Bild"; +$text['label-photo']['uk-ua'] = "Фото"; +$text['label-photo']['tr-tr'] = "Fotoğraf"; +$text['label-photo']['zh-cn'] = "照片"; +$text['label-photo']['ja-jp'] = "写真"; +$text['label-photo']['ko-kr'] = "사진"; diff --git a/core/users/user_profile.php b/core/users/user_profile.php index de6537d8ab..87c75b588b 100644 --- a/core/users/user_profile.php +++ b/core/users/user_profile.php @@ -50,17 +50,29 @@ //get the HTTP values and set as variables $password = $_POST["password"]; $password_confirm = $_POST["password_confirm"]; + $contact_name_given = $_POST['contact_name_given']; + $contact_name_family = $_POST['contact_name_family']; + $contact_email_uuid = $_POST['contact_email_uuid']; $user_email = $_POST["user_email"]; + $contact_phone_uuid = $_POST['contact_phone_uuid']; + $phone_number = $_POST['phone_number']; + $contact_address_uuid = $_POST['contact_address_uuid']; + $address_locality = $_POST['address_locality']; + $address_region = $_POST['address_region']; + $address_country = $_POST['address_country']; $user_status = $_POST["user_status"] ?? ''; $user_language = $_POST["user_language"]; $user_time_zone = $_POST["user_time_zone"]; - //if (permission_exists('api_key')) { - // $api_key = $_POST["api_key"]; - //} + $contact_attachment_uuid = $_POST['contact_attachment_uuid']; + $contact_attachment = $_FILES['contact_attachment']; + if (!empty($_SESSION['authentication']['methods']) && in_array('totp', $_SESSION['authentication']['methods'])) { $user_totp_secret = strtoupper($_POST["user_totp_secret"]); } + //remove any phone number formatting + $phone_number = preg_replace('{(?!^\+)[\D]}', '', $phone_number); + //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { @@ -135,6 +147,130 @@ } } + //save contact + $array['contacts'][$c]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array['contacts'][$c]['domain_uuid'] = $domain_uuid; + $array['contacts'][$c]['contact_type'] = 'user'; + $array['contacts'][$c]['contact_name_given'] = $contact_name_given ?? null; + $array['contacts'][$c]['contact_name_family'] = $contact_name_family ?? null; + $array['contacts'][$c]['contact_nickname'] = $_SESSION['username']; + $c++; + + //save email + $array['contact_emails'][$n]['contact_email_uuid'] = is_uuid($contact_email_uuid) ? $contact_email_uuid : uuid(); + $array['contact_emails'][$n]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array['contact_emails'][$n]['domain_uuid'] = $domain_uuid; + $array['contact_emails'][$n]['email_address'] = $user_email; + $array['contact_emails'][$n]['email_primary'] = 'true'; + $n++; + + //save phone + if (!empty($phone_number)) { + $array['contact_phones'][$y]['contact_phone_uuid'] = is_uuid($contact_phone_uuid) ? $contact_phone_uuid : uuid(); + $array['contact_phones'][$y]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array['contact_phones'][$y]['domain_uuid'] = $domain_uuid; + $array['contact_phones'][$y]['phone_number'] = $phone_number; + $array['contact_phones'][$y]['phone_primary'] = 'true'; + $y++; + } + + //save address + if (!empty($address_locality) || !empty($address_region) || !empty($address_country)) { + $array['contact_addresses'][$y]['contact_address_uuid'] = is_uuid($contact_address_uuid) ? $contact_address_uuid : uuid(); + $array['contact_addresses'][$y]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array['contact_addresses'][$y]['domain_uuid'] = $domain_uuid; + $array['contact_addresses'][$y]['address_locality'] = $address_locality ?? null; + $array['contact_addresses'][$y]['address_region'] = $address_region ?? null; + $array['contact_addresses'][$y]['address_country'] = $address_country ?? null; + $array['contact_addresses'][$y]['address_primary'] = 'true'; + $y++; + } + + //delete current profile photo (contact attachment) + if (!empty($contact_attachment_uuid) && is_uuid($contact_attachment_uuid)) { + $p = permissions::new(); + $p->add('contact_attachment_delete', 'temp'); + + $array_delete['contact_attachments'][0]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array_delete['contact_attachments'][0]['domain_uuid'] = $domain_uuid; + $array_delete['contact_attachments'][0]['contact_attachment_uuid'] = $contact_attachment_uuid; + $database = new database; + $database->app_name = 'contacts'; + $database->app_uuid = '04481e0e-a478-c559-adad-52bd4174574c'; + $database->delete($array_delete); + unset($array_delete); + + $p->delete('contact_attachment_delete', 'temp'); + } + //handle new profile photo + else if (is_array($contact_attachment) && sizeof($contact_attachment) != 0 && $contact_attachment['error'] === 0) { + $contact_attachment_extension = strtolower(pathinfo($contact_attachment['name'], PATHINFO_EXTENSION)); + if (in_array($contact_attachment_extension, ['jpg','jpeg','gif','png','webp'])) { + + //unflag others as primary + $sql = "update v_contact_attachments set attachment_primary = false "; + $sql .= "where domain_uuid = :domain_uuid "; + $sql .= "and contact_uuid = :contact_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $parameters['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $database->execute($sql, $parameters); + unset($sql, $parameters); + + //get the attachment content + $contact_attachment_content = file_get_contents($contact_attachment['tmp_name']); + + //create the image object from the content string + $image = imagecreatefromstring($contact_attachment_content); + + //start output buffering to capture the image data + ob_start(); + + //output the image without the EXIF data + switch ($contact_attachment_extension) { + case 'png': + imagealphablending($image, false); + imagesavealpha($image, true); + imagepng($image); + break; + case 'jpg': + case 'jpeg': + imagejpeg($image); + break; + case 'gif': + imagesavealpha($image, true); + imagegif($image); + break; + case 'webp': + imagewebp($image); + break; + } + + //get the image from the buffer + $contact_attachment_content = ob_get_contents(); + + //end the buffering + ob_end_clean(); + + //free up the memory + imagedestroy($image); + + //prepare the array + $array['contact_attachments'][0]['contact_attachment_uuid'] = is_uuid($contact_attachment_uuid) ? $contact_attachment_uuid : uuid(); + $array['contact_attachments'][0]['domain_uuid'] = $domain_uuid; + $array['contact_attachments'][0]['contact_uuid'] = $_SESSION['user']['contact_uuid']; + $array['contact_attachments'][0]['attachment_primary'] = 'true'; + $array['contact_attachments'][0]['attachment_filename'] = $contact_attachment['name']; + $array['contact_attachments'][0]['attachment_content'] = base64_encode($contact_attachment_content); + if ($action == 'add') { + $array['contact_attachments'][0]['attachment_uploaded_date'] = 'now()'; + $array['contact_attachments'][0]['attachment_uploaded_user_uuid'] = $_SESSION['user_uuid']; + } + } + } + else { + unset($contact_attachment); + } + //return if error if (message::count() != 0 || !empty($invalid)) { if ($invalid) { message::add($text['message-required'].implode(', ', $invalid), 'negative', 7500); } @@ -287,6 +423,9 @@ $p->add("user_setting_edit", "temp"); $p->add("user_edit", "temp"); $p->add('user_group_add', 'temp'); + $p->add("contact_attachment_add", "temp"); + $p->add("contact_attachment_edit", "temp"); + $p->add("contact_attachment_delete", "temp"); //save the data $database->save($array); @@ -297,6 +436,9 @@ $p->delete("user_setting_edit", "temp"); $p->delete("user_edit", "temp"); $p->delete('user_group_add', 'temp'); + $p->delete("contact_attachment_add", "temp"); + $p->delete("contact_attachment_edit", "temp"); + $p->delete("contact_attachment_delete", "temp"); //if call center installed if ($action == 'edit' && permission_exists('user_edit') && file_exists($_SERVER["PROJECT_ROOT"]."/app/call_centers/app_config.php")) { @@ -325,12 +467,12 @@ } //response message - if ($action == 'edit') { - message::add($text['message-update'],'positive'); - } - else { - message::add($text['message-add'],'positive'); - } + message::add($text['message-update'],'positive'); + + //redirect + header('Location: user_profile.php'); + exit; + } //populate form @@ -341,30 +483,67 @@ persistent_form_values('clear'); } else { + //populate the form with values from db - $sql = "select domain_uuid, user_uuid, username, user_email, api_key, user_totp_secret, "; - $sql .= "user_type, contact_uuid, user_enabled, user_status "; - $sql .= "from v_users "; - $sql .= "where user_uuid = :user_uuid "; + $sql = "select "; + $sql .= "u.domain_uuid, "; + $sql .= "u.user_uuid, "; + $sql .= "u.username, "; + $sql .= "u.user_email, "; + $sql .= "u.user_totp_secret, "; + $sql .= "u.user_type, "; + $sql .= "u.contact_uuid, "; + $sql .= "u.user_enabled, "; + $sql .= "u.user_status, "; + $sql .= "c.contact_name_given, "; + $sql .= "c.contact_name_family, "; + $sql .= "ce.contact_email_uuid, "; + $sql .= "cp.contact_phone_uuid, "; + $sql .= "cp.phone_number, "; + $sql .= "ca1.contact_address_uuid, "; + $sql .= "ca1.address_locality, "; + $sql .= "ca1.address_region, "; + $sql .= "ca1.address_country, "; + $sql .= "ca2.contact_attachment_uuid, "; + $sql .= "ca2.attachment_filename, "; + $sql .= "ca2.attachment_content "; + $sql .= "from "; + $sql .= "v_users as u "; + $sql .= "left join v_contacts as c on u.contact_uuid = c.contact_uuid "; + $sql .= "left join v_contact_emails as ce on u.contact_uuid = ce.contact_uuid and ce.email_primary = true "; + $sql .= "left join v_contact_phones as cp on u.contact_uuid = cp.contact_uuid and cp.phone_primary = true "; + $sql .= "left join v_contact_addresses as ca1 on u.contact_uuid = ca1.contact_uuid and ca1.address_primary = true "; + $sql .= "left join v_contact_attachments as ca2 on u.contact_uuid = ca2.contact_uuid and ca2.attachment_primary = true "; + $sql .= "where u.user_uuid = :user_uuid "; if (!permission_exists('user_all')) { $sql .= "and domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; } $parameters['user_uuid'] = $user_uuid; + // echo $sql; view_array($parameters); $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && sizeof($row) > 0) { $domain_uuid = $row["domain_uuid"]; $user_uuid = $row["user_uuid"]; $username = $row["username"]; $user_email = $row["user_email"]; - $api_key = $row["api_key"]; $user_totp_secret = $row["user_totp_secret"]; $user_type = $row["user_type"]; $user_enabled = $row["user_enabled"]; - if (permission_exists('contact_view')) { - $contact_uuid = $row["contact_uuid"]; - } $user_status = $row["user_status"]; + $contact_uuid = $row["contact_uuid"]; + $contact_name_given = $row["contact_name_given"]; + $contact_name_family = $row["contact_name_family"]; + $contact_email_uuid = $row["contact_email_uuid"]; + $contact_phone_uuid = $row["contact_phone_uuid"]; + $phone_number = $row["phone_number"]; + $contact_address_uuid = $row["contact_address_uuid"]; + $address_locality = $row["address_locality"]; + $address_region = $row["address_region"]; + $address_country = $row["address_country"]; + $contact_attachment_uuid = $row["contact_attachment_uuid"]; + $attachment_filename = $row["attachment_filename"]; + $attachment_content = $row["attachment_content"]; } else { message::add($text['message-invalid_user'], 'negative', 7500); @@ -409,7 +588,7 @@ //include the header require_once "resources/header.php"; - $document['title'] = $text['title-user_edit']; + $document['title'] = $text['title-user_profile']; //show the content if (permission_exists('user_password')) { @@ -444,7 +623,10 @@ echo "\n"; } - echo "