From 35deb3da569c263854529853242689e4cd61e015 Mon Sep 17 00:00:00 2001 From: David Siegfried Date: Wed, 9 Nov 2022 10:08:12 +0000 Subject: Prevent PHP-Warnings, closes #1764 Closes #1764 Merge request studip/studip!1140 --- app/controllers/admin/datafields.php | 2 +- app/controllers/admin/sem_classes.php | 2 ++ app/controllers/calendar/schedule.php | 2 +- app/controllers/calendar/single.php | 3 ++- app/controllers/contents/courseware.php | 2 +- app/controllers/oer/mymaterial.php | 8 ++++---- app/controllers/terms.php | 2 +- app/views/calendar/contentbox/_termin.php | 2 +- app/views/calendar/schedule/index.php | 2 +- app/views/calendar/single/year.php | 5 ++++- .../wizard/steps/basicdata/index_studygroup.php | 4 ++-- app/views/course/wizard/steps/studyareas/index.php | 4 ++-- app/views/my_studygroups/_course.php | 2 +- app/views/oer/market/index.php | 6 +++--- app/views/oer/mymaterial/edit.php | 24 ++++++++++++---------- lib/classes/StudipRangeTree.class.php | 4 ++-- lib/classes/StudipRangeTreeViewAdmin.class.php | 6 +++++- lib/classes/calendar/SingleCalendar.php | 4 ++-- .../coursewizardsteps/StudyAreasWizardStep.php | 7 +++---- lib/classes/sidebar/RoomSearchWidget.class.php | 4 ++-- lib/models/CourseEvent.class.php | 2 +- lib/models/OERHost.php | 11 ++++++---- public/admin_evaluation.php | 1 + public/assets.php | 2 +- templates/calendar/calendar_view.php | 4 +++- templates/calendar/entries/entry.php | 12 +++++------ templates/calendar/entries/icons.php | 2 +- 27 files changed, 73 insertions(+), 56 deletions(-) diff --git a/app/controllers/admin/datafields.php b/app/controllers/admin/datafields.php index d301791..bf390c9 100644 --- a/app/controllers/admin/datafields.php +++ b/app/controllers/admin/datafields.php @@ -181,7 +181,7 @@ class Admin_DatafieldsController extends AuthenticatedController $type = $type ?: Request::get('datafield_typ'); - $this->type_name = $this->allclasses[$type]; + $this->type_name = $this->allclasses[$type] ?? ''; $this->object_typ = $type; $this->institutes = Institute::getMyInstitutes(); if (!$this->object_typ) { diff --git a/app/controllers/admin/sem_classes.php b/app/controllers/admin/sem_classes.php index 4251685..aef3e84 100644 --- a/app/controllers/admin/sem_classes.php +++ b/app/controllers/admin/sem_classes.php @@ -136,6 +136,8 @@ class Admin_SemClassesController extends AuthenticatedController } if (!count($sem_class->getSemTypes())) { $notice = "
"._("Beachten Sie, dass es noch keine Veranstaltungstypen gibt!"); + } else { + $notice = ''; } $output = [ 'html' => (string) MessageBox::success(_("Änderungen wurden gespeichert."." ".''._("Zurück zur Übersichtsseite.").'').$notice) diff --git a/app/controllers/calendar/schedule.php b/app/controllers/calendar/schedule.php index 9b106bd..7787813 100644 --- a/app/controllers/calendar/schedule.php +++ b/app/controllers/calendar/schedule.php @@ -91,7 +91,7 @@ class Calendar_ScheduleController extends AuthenticatedController UserConfig::get($GLOBALS['user']->id)->store('SCHEDULE_SETTINGS', $schedule_settings); } else { - $this->current_semester = $schedule_settings['semester_id'] ? + $this->current_semester = !empty(schedule_settings['semester_id']) ? Semester::find($schedule_settings['semester_id']) : Semester::findCurrent(); } diff --git a/app/controllers/calendar/single.php b/app/controllers/calendar/single.php index 2067e39..0d4fcac 100644 --- a/app/controllers/calendar/single.php +++ b/app/controllers/calendar/single.php @@ -502,6 +502,8 @@ class Calendar_SingleController extends Calendar_CalendarController Request::set('sem_select', $sem); } $this->group_field = 'sem_number'; + $this->order_by = $order_by; + $this->config_sem_number = Config::get()->IMPORTANT_SEMNUMBER; // Needed parameters for selecting courses $params = [ 'group_field' => $this->group_field, @@ -512,7 +514,6 @@ class Calendar_SingleController extends Calendar_CalendarController ]; $this->sem_courses = MyRealmModel::getPreparedCourses($sem, $params); - $semesters = new SimpleCollection(Semester::getAll()); $this->sem = $sem; $this->semesters = $semesters->orderBy('beginn desc'); diff --git a/app/controllers/contents/courseware.php b/app/controllers/contents/courseware.php index 860fdc6..a91569c 100644 --- a/app/controllers/contents/courseware.php +++ b/app/controllers/contents/courseware.php @@ -78,7 +78,7 @@ class Contents_CoursewareController extends AuthenticatedController $last = UserConfig::get($this->user_id)->getValue('COURSEWARE_LAST_ELEMENT'); - if ($last[$this->user_id]) { + if (!empty($last[$this->user_id])) { $this->entry_element_id = $last['global']; $struct = \Courseware\StructuralElement::findOneBySQL( "id = ? AND range_id = ? AND range_type = 'user'", diff --git a/app/controllers/oer/mymaterial.php b/app/controllers/oer/mymaterial.php index b1015fd..93b0cd4 100644 --- a/app/controllers/oer/mymaterial.php +++ b/app/controllers/oer/mymaterial.php @@ -39,7 +39,7 @@ class Oer_MymaterialController extends AuthenticatedController $material->setData(Request::getArray('data')); $material['host_id'] = null; $material['license_identifier'] = Request::get('license', 'CC-BY-SA-4.0'); - if ($_FILES['file']['tmp_name']) { + if (!empty($_FILES['file']['tmp_name'])) { $material['content_type'] = $_FILES['file']['type']; if (in_array($material['content_type'], $content_types)) { mkdir($tmp_folder); @@ -51,7 +51,7 @@ class Oer_MymaterialController extends AuthenticatedController } $material['filename'] = $_FILES['file']['name']; move_uploaded_file($_FILES['file']['tmp_name'], $material->getFilePath()); - } elseif($_SESSION['NEW_OER']['tmp_name']) { + } elseif (!empty($_SESSION['NEW_OER']['tmp_name'])) { $material['content_type'] = $_SESSION['NEW_OER']['content_type'] ?: get_mime_type($_SESSION['NEW_OER']['tmp_name']); if (in_array($material['content_type'], $content_types)) { mkdir($tmp_folder); @@ -66,10 +66,10 @@ class Oer_MymaterialController extends AuthenticatedController } - if ($_FILES['image']['tmp_name']) { + if (!empty($_FILES['image']['tmp_name'])) { $material['front_image_content_type'] = $_FILES['image']['type']; move_uploaded_file($_FILES['image']['tmp_name'], $material->getFrontImageFilePath()); - } elseif($_SESSION['NEW_OER']['image_tmp_name']) { + } elseif (!empty($_SESSION['NEW_OER']['image_tmp_name'])) { $material['front_image_content_type'] = get_mime_type($_SESSION['NEW_OER']['image_tmp_name']); copy($_SESSION['NEW_OER']['image_tmp_name'], $material->getFrontImageFilePath()); } diff --git a/app/controllers/terms.php b/app/controllers/terms.php index bf98df0..ef59395 100644 --- a/app/controllers/terms.php +++ b/app/controllers/terms.php @@ -25,7 +25,7 @@ class TermsController extends AuthenticatedController $this->redirect_token = Request::get('redirect_token'); $this->compulsory = Config::get()->TERMS_CONFIG['compulsory']; - + $this->denial_message = ''; if (Request::isPost()) { CSRFProtection::verifyUnsafeRequest(); if (Request::submitted('accept')) { diff --git a/app/views/calendar/contentbox/_termin.php b/app/views/calendar/contentbox/_termin.php index 188ec3e..3c3fcff 100644 --- a/app/views/calendar/contentbox/_termin.php +++ b/app/views/calendar/contentbox/_termin.php @@ -18,7 +18,7 @@
- +

diff --git a/app/views/calendar/schedule/index.php b/app/views/calendar/schedule/index.php index 45a4c32..fe022a2 100644 --- a/app/views/calendar/schedule/index.php +++ b/app/views/calendar/schedule/index.php @@ -1,6 +1,6 @@ - + diff --git a/app/views/course/wizard/steps/basicdata/index_studygroup.php b/app/views/course/wizard/steps/basicdata/index_studygroup.php index a1e1e74..23b87b4 100644 --- a/app/views/course/wizard/steps/basicdata/index_studygroup.php +++ b/app/views/course/wizard/steps/basicdata/index_studygroup.php @@ -4,7 +4,7 @@ 1) : ?> @@ -31,7 +31,7 @@ diff --git a/app/views/course/wizard/steps/studyareas/index.php b/app/views/course/wizard/steps/studyareas/index.php index 1b35237..e8f811e 100644 --- a/app/views/course/wizard/steps/studyareas/index.php +++ b/app/views/course/wizard/steps/studyareas/index.php @@ -19,13 +19,13 @@ - +
- +

diff --git a/app/views/my_studygroups/_course.php b/app/views/my_studygroups/_course.php index 52e3b32..b3f6b6b 100644 --- a/app/views/my_studygroups/_course.php +++ b/app/views/my_studygroups/_course.php @@ -56,7 +56,7 @@ - + _("Die Teilnahme ist bindend. Bitte wenden Sie sich an die Lehrenden.")])->asImg(20) ?> diff --git a/app/views/oer/market/index.php b/app/views/oer/market/index.php index 947eca3..09dfa43 100644 --- a/app/views/oer/market/index.php +++ b/app/views/oer/market/index.php @@ -1,6 +1,6 @@ 0) { - $tags = []; foreach ($best_nine_tags as $tag) { $tags[] = [ 'tag_hash' => $tag['tag_hash'], @@ -8,8 +8,8 @@ if ($best_nine_tags && count($best_nine_tags) > 0) { ]; } } -if ($materialien !== null) { - $material_data = []; +$material_data = []; +if (!empty($materialien)) { foreach ($materialien as $material) { $data = $material->toRawArray(); diff --git a/app/views/oer/mymaterial/edit.php b/app/views/oer/mymaterial/edit.php index e9944f0..bfd7aae 100644 --- a/app/views/oer/mymaterial/edit.php +++ b/app/views/oer/mymaterial/edit.php @@ -15,7 +15,7 @@ name="data[name]" class="oername" required - value="" + value="" @keyup="editName" maxlength="64"> @@ -44,8 +44,8 @@
@@ -186,8 +186,10 @@ foreach ($material->getTopics() as $tag) { $tags[] = $tag['name']; } - foreach ((array) $template['tags'] as $tag) { - $tags[] = $tag; + if (!empty($template['tags'])) { + foreach ((array)$template['tags'] as $tag) { + $tags[] = $tag; + } } ?> @@ -233,7 +235,7 @@
- + @@ -273,7 +275,7 @@ - + diff --git a/lib/classes/StudipRangeTree.class.php b/lib/classes/StudipRangeTree.class.php index 36f7314..cf88d23 100644 --- a/lib/classes/StudipRangeTree.class.php +++ b/lib/classes/StudipRangeTree.class.php @@ -111,10 +111,10 @@ class StudipRangeTree extends TreeAbstract * useful for the user rights management * @access public * @param string $item_id - * @return array of primary keys from table "institute" + * @return bool|array of primary keys from table "institute" */ function getAdminRange($item_id) { - if (!$this->tree_data[$item_id]) { + if (empty($this->tree_data[$item_id])) { return false; } diff --git a/lib/classes/StudipRangeTreeViewAdmin.class.php b/lib/classes/StudipRangeTreeViewAdmin.class.php index 6c5f349..777037a 100644 --- a/lib/classes/StudipRangeTreeViewAdmin.class.php +++ b/lib/classes/StudipRangeTreeViewAdmin.class.php @@ -112,7 +112,11 @@ class StudipRangeTreeViewAdmin extends TreeView{ } } - $tmp = $this->tree->getAdminRange($this->tree->tree_data[$key]['parent_id']); + if (isset($this->tree->tree_data[$key])) { + $tmp = $this->tree->getAdminRange($this->tree->tree_data[$key]['parent_id']); + } else { + $tmp = []; + } if(!empty($tmp)) { foreach($tmp as $i) { diff --git a/lib/classes/calendar/SingleCalendar.php b/lib/classes/calendar/SingleCalendar.php index 2b19de8..bd96826 100644 --- a/lib/classes/calendar/SingleCalendar.php +++ b/lib/classes/calendar/SingleCalendar.php @@ -1234,10 +1234,10 @@ class SingleCalendar $properties = $event->getProperties(); if (is_array($restrictions)) { foreach ($restrictions as $property_name => $restriction) { - if (is_array($restriction)) { + if (is_array($restriction) && isset($properties[mb_strtoupper($property_name)])) { return in_array($properties[mb_strtoupper($property_name)], $restriction); } else if ($restriction != '') { - return $properties[mb_strtoupper($property_name)] == $restriction; + return isset($properties[mb_strtoupper($property_name)]) && $properties[mb_strtoupper($property_name)] === $restriction; } } return true; diff --git a/lib/classes/coursewizardsteps/StudyAreasWizardStep.php b/lib/classes/coursewizardsteps/StudyAreasWizardStep.php index c0edda8..668a54e 100644 --- a/lib/classes/coursewizardsteps/StudyAreasWizardStep.php +++ b/lib/classes/coursewizardsteps/StudyAreasWizardStep.php @@ -32,8 +32,7 @@ class StudyAreasWizardStep implements CourseWizardStep // Load template from step template directory. $factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'].'/app/views/course/wizard/steps'); $tpl = $factory->open('studyareas/index'); - if ($values['studyareas']) - { + if (!empty($values['studyareas'])) { $tree = $this->buildPartialSemTree(StudipStudyArea::backwards(StudipStudyArea::findMany($values['studyareas']))); $tpl->set_attribute('assigned', $tree); } else { @@ -80,8 +79,8 @@ class StudyAreasWizardStep implements CourseWizardStep } } $tpl->set_attribute('tree', $tree); - $tpl->set_attribute('ajax_url', $values['ajax_url'] ?: URLHelper::getLink('dispatch.php/course/wizard/ajax')); - $tpl->set_attribute('no_js_url', $values['no_js_url'] ? : 'dispatch.php/course/wizard/forward/'.$stepnumber.'/'.$temp_id); + $tpl->set_attribute('ajax_url', $values['ajax_url'] ?? URLHelper::getLink('dispatch.php/course/wizard/ajax')); + $tpl->set_attribute('no_js_url', $values['no_js_url'] ?? 'dispatch.php/course/wizard/forward/'.$stepnumber.'/'.$temp_id); $tpl->set_attribute('stepnumber', $stepnumber); $tpl->set_attribute('temp_id', $temp_id); return $tpl->render(); diff --git a/lib/classes/sidebar/RoomSearchWidget.class.php b/lib/classes/sidebar/RoomSearchWidget.class.php index af7a819..5b6aa49 100644 --- a/lib/classes/sidebar/RoomSearchWidget.class.php +++ b/lib/classes/sidebar/RoomSearchWidget.class.php @@ -222,7 +222,7 @@ class RoomSearchWidget extends SidebarWidget Request::get($name . '_semester_id'); } } else { - if ($data['switch']) { + if (!empty($data['switch'])) { if (Request::get($name . '_enabled')) { $data['enabled'] = true; } else { @@ -399,7 +399,7 @@ class RoomSearchWidget extends SidebarWidget //since its begin and end date are set on the client side in //the special__available_range property when a semester is selected. $time_intervals = []; - if ($this->selected_criteria['special__time_range']) { + if (!empty($this->selected_criteria['special__time_range'])) { $time_range_criteria = $this->selected_criteria['special__time_range']; //Get and check day of week: diff --git a/lib/models/CourseEvent.class.php b/lib/models/CourseEvent.class.php index 930c57a..2d564b5 100644 --- a/lib/models/CourseEvent.class.php +++ b/lib/models/CourseEvent.class.php @@ -210,7 +210,7 @@ class CourseEvent extends CourseDate implements Event { $title = _('Keine Berechtigung.'); if ($this->havePermission(Event::PERMISSION_READABLE)) { - $description = trim($this->cycle->description) ?: ''; + $description = $this->cycle ? trim($this->cycle->description) : ''; if (sizeof($this->topics)) { $title = $this->course->name.": ".implode(', ', $this->topics->pluck('title')); } else { diff --git a/lib/models/OERHost.php b/lib/models/OERHost.php index b323602..d0b1f69 100644 --- a/lib/models/OERHost.php +++ b/lib/models/OERHost.php @@ -63,10 +63,13 @@ class OERHost extends OERIdentity public static function find($id) { $host = parent::find($id); - $class = $host['sorm_class']; - if ($class && ($class !== 'OERHost') && is_subclass_of($class, 'OERHost')) { - $data = $host->toRawArray(); - $host = $class::buildExisting($data); + + if ($host) { + $class = $host['sorm_class']; + if ($class && ($class !== 'OERHost') && is_subclass_of($class, 'OERHost')) { + $data = $host->toRawArray(); + $host = $class::buildExisting($data); + } } return $host; } diff --git a/public/admin_evaluation.php b/public/admin_evaluation.php index 144e3f3..f702173 100644 --- a/public/admin_evaluation.php +++ b/public/admin_evaluation.php @@ -76,6 +76,7 @@ if ((Context::getId()) && ($view == "eval_sem") || ($view == "eval_inst")) { $the_range = Request::option('rangeID'); } +$isUserrange = null; if ($the_range) { if (get_Username($the_range)) { $the_range = get_Username($the_range); diff --git a/public/assets.php b/public/assets.php index 8994b40..8e06685 100644 --- a/public/assets.php +++ b/public/assets.php @@ -34,7 +34,7 @@ if (!$type || !$id) { } else { // Load asset $model = PluginAsset::find($id); - if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] && $model->chdate <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $model->chdate <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { // Cached and still valid $response->set_status(304); } else { diff --git a/templates/calendar/calendar_view.php b/templates/calendar/calendar_view.php index a397f0b..db3cb36 100644 --- a/templates/calendar/calendar_view.php +++ b/templates/calendar/calendar_view.php @@ -151,7 +151,9 @@ $cell_steps = $cell_height / 60; $max = 0; $current_matrix = $column->getMatrix(); for ($i = ($calc_entry['start'] + 1 + ($start_hour * 100)); $i < $calc_entry['end'] + ($start_hour * 100); $i++) { - $max = max($max, $current_matrix[$i]); + if (isset($current_matrix[$i])) { + $max = max($max, $current_matrix[$i]); + } } // set height and width diff --git a/templates/calendar/entries/entry.php b/templates/calendar/entries/entry.php index 71d8a8f..1b4242d 100644 --- a/templates/calendar/entries/entry.php +++ b/templates/calendar/entries/entry.php @@ -3,15 +3,15 @@ $element_id = md5(uniqid()); ?> -
" style="top: px; height: px; width: % 0) ? ';left:'. str_replace(',', '.', $col * $width) .'%' : '' ?>" title=""> +
" style="top: px; height: px; width: % 0) ? ';left:'. str_replace(',', '.', $col * $width) .'%' : '' ?>" title=""> - - > + + > -
+
-
+
- '. htmlReady($entry['title']) .'' : '' ?> @@ -22,7 +22,7 @@ $element_id = md5(uniqid()); - '. htmlReady($entry['title']) .'' : '' ?>
-
+
diff --git a/templates/calendar/entries/icons.php b/templates/calendar/entries/icons.php index 2e0f3d2..c9fd74b 100644 --- a/templates/calendar/entries/icons.php +++ b/templates/calendar/entries/icons.php @@ -1,5 +1,5 @@