diff --git a/local/config/finna/Quria.ini.sample b/local/config/finna/Quria.ini.sample index f61b6cea6bc..844273c42f7 100644 --- a/local/config/finna/Quria.ini.sample +++ b/local/config/finna/Quria.ini.sample @@ -118,15 +118,13 @@ fields[] = Address:address1 fields[] = Zip:zip fields[] = City:city fields[] = Country:country -fields[] = Email:extraEmails -fields[] = Phone:extraPhones -;fields[] = Phone:phone -;fields[] = Email:email +fields[] = Email:email +fields[] = Phone:phone ;fields[] = Additional info:info ; Array of fields that can be set active/inactive -contactInfoActivation[] = extraPhones -contactInfoActivation[] = extraEmails +contactInfoActivation[] = phone +contactInfoActivation[] = email ; url is required for the url method. url can be a single address or an array of ; language-specific addresses. First example is a single one: ;url = http://address.of.change.form diff --git a/local/languages/finna/en-gb.ini b/local/languages/finna/en-gb.ini index b5f36746093..054a4ee3200 100644 --- a/local/languages/finna/en-gb.ini +++ b/local/languages/finna/en-gb.ini @@ -308,6 +308,7 @@ Educational Level = "Educational Level" Educational Role = "Educational Role" Educational Subject = "Educational Subject" Educational Use = "Educational Use" +email_active = "Active" email_from = "Sender's address" email_info = "Your email address is needed for the following Finna features: due date reminders, scheduled alerts, send records by email, recovery of a forgotten password" email_info_without_ddr = "Your email address is needed for the following Finna features: scheduled alerts, send records by email, recovery of a forgotten password" @@ -349,8 +350,6 @@ external_link_kyppi_rpr = "Record in Built Heritage Register" external_online_link = "External link to material" external_rating_link_html = 'You can evaluate the materials in the online service of the organisation that provides it (external link).' external_rating_link_aoe_html = 'You can evaluate educational resources on the Library of Open Educational Resources website (aoe.fi).' -extraEmails_active = "Active" -extraPhones_active = "Use for SMS" facet_list_empty = "No data available" Feedback = "Feedback" feedback_captcha_answer = "55" @@ -884,6 +883,7 @@ Performers = "Performers" Performing Ensembles = "Performing Ensembles" Personal details maintained by the library = "Personal details maintained by the library" Phone = "Phone" +phone_active = "Use for SMS" Photo Info = "Photo Info" pick_up_location = "Pickup Location" pickup_location_home_address = "Delivery to home address" diff --git a/local/languages/finna/fi.ini b/local/languages/finna/fi.ini index 9f5ee31f1df..152888d67a4 100644 --- a/local/languages/finna/fi.ini +++ b/local/languages/finna/fi.ini @@ -300,6 +300,7 @@ Educational Level = "Koulutusaste" Educational Role = "Kohderyhmä" Educational Subject = "Oppiaine / tutkinto / tieteenala" Educational Use = "Pääasiallinen käyttötarkoitus" +email_active = "Aktiivinen" email_from = "Lähettäjän sähköpostiosoite" email_info = "Tarvitset sähköpostiosoitetta seuraaviin Finna-toimintoihin: eräpäivämuistutukset, uutuusvahti, aineiston tietojen lähettäminen sähköpostilla, unohtuneen salasanan palauttaminen" email_info_without_ddr = "Tarvitset sähköpostiosoitetta seuraaviin Finna-toimintoihin: uutuusvahti, aineiston tietojen lähettäminen sähköpostilla, unohtuneen salasanan palauttaminen" @@ -343,8 +344,6 @@ external_link_kyppi_rpr = "Kohde rakennusperintörekisterissä" external_online_link = "Ulkoinen linkki aineistoon" external_rating_link_html = 'Voit arvioida oppimateriaaleja aineistontarjoajan omassa verkkopalvelussa (ulkoinen linkki).' external_rating_link_aoe_html = 'Voit arvioida oppimateriaaleja Avointen oppimateriaalien kirjaston sivustolla (aoe.fi).' -extraEmails_active = "Aktiivinen" -extraPhones_active = "Käytä tekstiviesteille" facet_list_empty = "Ei tietoja" Feedback = "Palaute" feedback_captcha_answer = "55" @@ -877,6 +876,7 @@ Performers = "Esiintyjät" Performing Ensembles = "Esiintyjäkokoonpanot" Personal details maintained by the library = "Kirjaston ylläpitämät henkilötiedot" Phone = "Puhelin" +phone_active = "Käytä tekstiviesteille" Photo Info = "Kuvaustiedot" pickup_location_home_address = "Toimitus kotiosoitteeseen" pickup_location_work_address = "Toimitus työosoitteeseen" diff --git a/local/languages/finna/sv.ini b/local/languages/finna/sv.ini index 130bd76ddf0..41d980bfae0 100644 --- a/local/languages/finna/sv.ini +++ b/local/languages/finna/sv.ini @@ -299,6 +299,7 @@ Educational Level = "Utbildningsstadium" Educational Role = "Målgrupp" Educational Subject = "Undervisningsämne" Educational Use = "Användningsområde" +email_active = "Aktiv" email_from = "Avsändarens e-postadress" email_info = "Du behöver en e-postadress för att kunna använda följande funktioner i Finna: förfallodagspåminnelser, sökbevakningen, att skicka uppgifter om material per e-post, att återställa ditt lösenord" email_info_without_ddr = "Du behöver en e-postadress för att kunna använda följande funktioner i Finna: sökbevakningen, att skicka uppgifter om material per e-post, att återställa ditt lösenord" @@ -341,8 +342,6 @@ external_link_kyppi_rpr = "Posten i byggnadsminnesregistret" external_online_link = "Extern länk till materialet" external_rating_link_html = 'Du kan utvärdera materialen i leverantörens egen nättjänst (extern länk).' external_rating_link_aoe_html = 'Du kan utvärdera lärresurser på webbplatsen för Biblioteket för öppna lärresurser (aoe.fi).' -extraEmails_active = "Aktiv" -extraPhones_active = "Använd för SMS" Feedback = "Respons" feedback_captcha_answer = "55" feedback_captcha_error = "Kontrollera svaret på säkerhetsfrågan." @@ -874,6 +873,7 @@ Performers = "Uppträdare" Performing Ensembles = "Uppträdande ensembler" Personal details maintained by the library = "Personuppgifter som biblioteket upprätthåller" Phone = "Telefonnummer" +phone_active = "Använd för SMS" Photo Info = "Bildinformation" pick_up_location = "Hämtas från" pickup_location_home_address = "Leverans till hemadress" diff --git a/module/Finna/src/Finna/Controller/MyResearchController.php b/module/Finna/src/Finna/Controller/MyResearchController.php index 12e25ea303f..b5e9fa9fca0 100644 --- a/module/Finna/src/Finna/Controller/MyResearchController.php +++ b/module/Finna/src/Finna/Controller/MyResearchController.php @@ -904,12 +904,6 @@ public function changeProfileAddressAction() $fieldNames[strtok($field, '[')] = true; } - // Add contact info activation fields to accepted field names - if (!empty($updateConfig['contactInfoActivation'])) { - foreach ($updateConfig['contactInfoActivation'] as $contactField) { - $fieldNames['active_' . $contactField] = true; - } - } // Filter any undefined fields and bad values from the request: $data = array_intersect_key( filter_input_array(INPUT_POST), diff --git a/module/Finna/src/Finna/ILS/Driver/Quria.php b/module/Finna/src/Finna/ILS/Driver/Quria.php index cdb129143ed..c55097e23b1 100644 --- a/module/Finna/src/Finna/ILS/Driver/Quria.php +++ b/module/Finna/src/Finna/ILS/Driver/Quria.php @@ -667,13 +667,10 @@ public function patronLogin($username, $password) if (!empty($info->emailAddresses->emailAddress)) { $emailAddresses = $this->objectToArray($info->emailAddresses->emailAddress); - foreach ($emailAddresses as $emailAddress) { - $userCached['extraEmails'][] - = [ - 'email' => $emailAddress->address ?? null, - 'emailId' => $emailAddress->id ?? null, - 'active' => $emailAddress->isActive == 'yes', - ]; + foreach ($emailAddresses as $i => $emailAddress) { + $userCached['email_' . $i] = $emailAddress->address ?? null; + $userCached['email_' . $i . '_id'] = $emailAddress->id ?? null; + $userCached['email_' . $i . '_active'] = $emailAddress->isActive == 'yes'; } } if (isset($info->addresses->address)) { @@ -691,13 +688,10 @@ public function patronLogin($username, $password) } if (isset($info->phoneNumbers->phoneNumber)) { $phoneNumbers = $this->objectToArray($info->phoneNumbers->phoneNumber); - foreach ($phoneNumbers as $phoneNumber) { - $userCached['extraPhones'][] - = [ - 'phone' => ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null, - 'phoneId' => $phoneNumber->id ?? null, - 'active' => ($phoneNumber->sms->useForSms ?? '') == 'yes', - ]; + foreach ($phoneNumbers as $i => $phoneNumber) { + $userCached['phone_' . $i] = ($phoneNumber->areaCode ?? '') . $phoneNumber->localCode ?? null; + $userCached['phone_' . $i . '_id'] = $phoneNumber->id ?? null; + $userCached['phone_' . $i . '_active'] = ($phoneNumber->sms->useForSms ?? '') == 'yes'; } } @@ -1131,53 +1125,28 @@ public function updateAddress($patron, $details) { $user = $this->getMyProfile($patron); - if (isset($details['email'])) { - $result = $this->updateEmail($patron, $details['email']); - if (!$result['success']) { - return $result; - } - } - if (!empty($details['extraEmails'])) { - foreach ($details['extraEmails'] as $i => $extraEmail) { - if (!empty($extraEmail)) { - $active = isset($details['active_extraEmails'][$i]); - if ( - ($user['extraEmails'][$i]['email'] !== $extraEmail) - || ($active !== $user['extraEmails'][$i]['active']) - ) { - $result = $this->updateEmail($patron, $extraEmail, $i, $active); - if (!$result['success']) { - return $result; - } - } - } - } - } - - if (!empty($details['extraPhones'])) { - foreach ($details['extraPhones'] as $i => $extraPhone) { - if (!empty($extraPhone)) { - $active = isset($details['active_extraPhones'][$i]); - if ( - ($user['extraPhones'][$i]['phone'] !== $extraPhone) - || ($active !== $user['extraPhones'][$i]['active']) - ) { - $result = $this->updatePhone($patron, $extraPhone, $i, $active); - if (!$result['success']) { - return $result; - } + // Handle phones and emails + foreach ($details as $field => $detail) { + $parts = explode('_', $field); + $fieldName = $parts[0]; + $ind = $parts[1] ?? null; + $activeSuffix = $parts[2] ?? null; + if (in_array($fieldName, ['email', 'phone']) && $activeSuffix === null) { + $active = isset($details[$field . '_active']); + if ( + $user[$field] !== $detail + || $user[$field . '_active'] !== $active + ) { + $result = $fieldName === 'email' + ? $this->updateEmail($patron, $detail, $ind, $active) + : $this->updatePhone($patron, $detail, $ind, $active); + if (!$result['success']) { + return $result; } } } } - if (isset($details['phone'])) { - $result = $this->updatePhone($patron, $details['phone']); - if (!$result['success']) { - return $result; - } - } - $username = $patron['cat_username']; $password = $patron['cat_password']; @@ -1645,13 +1614,22 @@ public function placeHold($holdDetails) */ public function updateEmail($patron, $email, $emailId = null, $active = false) { - if (empty($email) || empty($emailId)) { + if (empty($email) || $emailId === null) { return [ 'success' => true, 'status' => 'No data to update', 'sys_message' => '', ]; } + $validator = new \Laminas\Validator\EmailAddress(); + if (!$validator->isValid($email)) { + return [ + 'success' => false, + 'status' => 'Invalid email', + 'sys_message' => '', + ]; + } + $username = $patron['cat_username']; $password = $patron['cat_password']; @@ -1675,8 +1653,8 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) 'address' => $email, 'isActive' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraEmails'])) { - $conf['id'] = $user['extraEmails'][$emailId]['emailId']; + if (!empty($user['email_0'])) { + $conf['id'] = $user['email_' . $emailId . '_id'] ?? ''; $function = 'changeEmail'; $functionResult = 'changeEmailAddressResult'; $functionParam = 'changeEmailAddressParam'; @@ -1731,7 +1709,7 @@ public function updateEmail($patron, $email, $emailId = null, $active = false) */ public function updatePhone($patron, $phone, $phoneId = null, $active = false) { - if (empty($phone) || empty($phoneId)) { + if (empty($phone) || $phoneId === null) { return [ 'success' => true, 'status' => 'No data to update', @@ -1758,8 +1736,8 @@ public function updatePhone($patron, $phone, $phoneId = null, $active = false) 'useForSms' => $active ? 'yes' : 'no', ]; - if (!empty($user['extraPhones'])) { - $conf['id'] = $user['extraPhones'][$phoneId]['phoneId']; + if (!empty($user['phone_0'])) { + $conf['id'] = $user['phone_' . $phoneId . '_id'] ?? ''; $function = 'changePhone'; $functionResult = 'changePhoneNumberResult'; $functionParam = 'changePhoneNumberParam'; @@ -1938,4 +1916,58 @@ public function renewMyItems($renewDetails) } return $results; } + + /** + * Public Function which retrieves renew, hold and cancel settings from the + * driver ini file. + * + * @param string $function The name of the feature to be checked + * @param array $params Optional feature-specific parameters (array) + * + * @return array An array with key-value pairs. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function getConfig($function, $params = null) + { + $config = parent::getConfig($function, $params); + if ('updateAddress' === $function && isset($config['fields'])) { + if (isset($params['patron'])) { + $profile = $this->getMyProfile($params['patron']); + $extraFields = []; + foreach ($config['fields'] as $i => $field) { + [$label, $fieldId] = explode(':', $field); + if (in_array($fieldId, ['email', 'phone'])) { + // Create a new field for every email/phone the user has + foreach ($profile as $profileField => $value) { + $pattern = "/^{$fieldId}_\d+$/"; + if (preg_match($pattern, $profileField)) { + $activation = in_array( + $fieldId, + $this->config['updateAddress']['contactInfoActivation'] ?? [] + ); + $extraField = [ + 'field' => $profileField, + 'label' => $label, + 'type' => 'text', + ]; + $extraFields[] = $extraField; + if ($activation) { + $extraActiveField = [ + 'field' => $profileField . '_active', + 'label' => $fieldId . '_active', + 'type' => 'boolean', + ]; + $extraFields[] = $extraActiveField; + } + } + } + unset($config['fields'][$i]); + } + } + $config['fields'] = array_merge($config['fields'], $extraFields); + } + return $config; + } + } } diff --git a/themes/finna2/templates/myresearch/change-address-settings.phtml b/themes/finna2/templates/myresearch/change-address-settings.phtml index 39e641223dc..d0c4196c88a 100644 --- a/themes/finna2/templates/myresearch/change-address-settings.phtml +++ b/themes/finna2/templates/myresearch/change-address-settings.phtml @@ -95,61 +95,23 @@ >