From 792057b4d052df210ecb5207710c9fefa253eaa8 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 16 Nov 2023 15:21:44 +0000
Subject: [PATCH] fixes #3474

Closes #3474

Merge request studip/studip!2370
---
 app/controllers/institute/basicdata.php   |  2 +-
 app/views/institute/basicdata/index.php   | 18 +++++++++++++++---
 lib/classes/JsonApi/Schemas/Institute.php |  2 +-
 lib/models/Institute.class.php            |  4 ++--
 4 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/app/controllers/institute/basicdata.php b/app/controllers/institute/basicdata.php
index 2f13d9b15ac..030749fbb69 100644
--- a/app/controllers/institute/basicdata.php
+++ b/app/controllers/institute/basicdata.php
@@ -184,7 +184,7 @@ class Institute_BasicdataController extends AuthenticatedController
         $institute->strasse         = Request::get('strasse', $institute->strasse);
         // Beware: Despite the name, this contains both zip code AND city name
         $institute->plz             = Request::get('plz', $institute->plz);
-        $institute->url             = Request::get('home', $institute->url);
+        $institute->url             = Request::i18n('url', $institute->url)->trim();
         $institute->telefon         = Request::get('telefon', $institute->telefon);
         $institute->email           = Request::get('email', $institute->email);
         $institute->fax             = Request::get('fax', $institute->fax);
diff --git a/app/views/institute/basicdata/index.php b/app/views/institute/basicdata/index.php
index 8e697c1e011..5d29572085a 100644
--- a/app/views/institute/basicdata/index.php
+++ b/app/views/institute/basicdata/index.php
@@ -1,3 +1,16 @@
+<?php
+/**
+ * @var Institute_BasicdataController $controller
+ * @var string $i_view
+ * @var string|null $question
+ * @var Institute $institute
+ * @var bool $may_edit_faculty
+ * @var bool $may_delete
+ * @var Institute[] $faculties
+ * @var array $datafields
+ * @var string $reason_txt
+ */
+?>
 <?= $question ?? '' ?>
 <form method="post" name="edit" action="<?= $controller->url_for('institute/basicdata/store/' . $i_view) ?>" class="default">
     <?= CSRFProtection::tokenTag() ?>
@@ -7,7 +20,7 @@
 
         <label class="col-6">
             <span class="required"><?= _('Name') ?></span>
-            <?= I18N::input('Name', $institute->Name, LockRules::Check($institute->id, 'name') ? ['readonly' => true, 'disabled' => true] : ['required' => true]); ?>
+            <?= I18N::input('Name', $institute->name, LockRules::Check($institute->id, 'name') ? ['readonly' => true, 'disabled' => true] : ['required' => true]); ?>
         </label>
 
         <label class="col-3">
@@ -89,8 +102,7 @@
 
         <label class="col-3">
             <?= _('Homepage') ?>
-            <input type="text" <?= LockRules::Check($institute->id, 'url') ? 'readonly disabled' : '' ?> id="home" name="home"
-                   value="<?= htmlReady(Request::get('home', $institute->url)) ?>">
+            <?= I18N::input('url', $institute->url, LockRules::Check($institute->id, 'url') ? ['readonly' => true, 'disabled' => true] : ['required' => true]); ?>
         </label>
 
     <? if ($GLOBALS['perm']->have_perm('root')): // Select lockrule to apply ?>
diff --git a/lib/classes/JsonApi/Schemas/Institute.php b/lib/classes/JsonApi/Schemas/Institute.php
index 13e061a2d11..0084ca6baa0 100644
--- a/lib/classes/JsonApi/Schemas/Institute.php
+++ b/lib/classes/JsonApi/Schemas/Institute.php
@@ -36,7 +36,7 @@ class Institute extends SchemaProvider
             'street'     => $institute->strasse,
             'phone'      => $institute->telefon,
             'fax'        => $institute->fax,
-            'url'        => $institute->url,
+            'url'        => (string) $institute->url,
             'is-faculty' => $institute->is_fak,
             'mkdate'     => date('c', $institute->mkdate),
             'chdate'     => date('c', $institute->chdate),
diff --git a/lib/models/Institute.class.php b/lib/models/Institute.class.php
index 5a5a1d0b3c7..ece1e13ec8b 100644
--- a/lib/models/Institute.class.php
+++ b/lib/models/Institute.class.php
@@ -19,7 +19,7 @@
  * @property string $fakultaets_id database column
  * @property string $strasse database column
  * @property string $plz database column
- * @property string $url database column
+ * @property I18NString $url database column
  * @property string $telefon database column
  * @property string $email database column
  * @property string $fax database column
@@ -133,7 +133,7 @@ class Institute extends SimpleORMap implements Range
             return Statusgruppen::findAllByRangeId($institute->id, true);
         };
 
-        $config['i18n_fields']['name'] = true;
+        $config['i18n_fields'] = ['name', 'url'];
         $config['registered_callbacks']['after_create'][] = 'setDefaultTools';
 
         parent::configure($config);
-- 
GitLab