From fb4330af7b1c1513bc716214758d1bcfeb2a4fd6 Mon Sep 17 00:00:00 2001 From: Thomas Rupprecht Date: Mon, 7 Nov 2016 20:38:01 +0100 Subject: [PATCH] little code improvements to make it clearer --- adm_program/installation/layout/admidio.css | 2 +- .../modules/announcements/announcements.php | 13 +- .../announcements/announcements_new.php | 5 +- adm_program/system/function.php | 225 +++++++++--------- 4 files changed, 132 insertions(+), 113 deletions(-) diff --git a/adm_program/installation/layout/admidio.css b/adm_program/installation/layout/admidio.css index b027894d78..4c1ef8f3b4 100644 --- a/adm_program/installation/layout/admidio.css +++ b/adm_program/installation/layout/admidio.css @@ -442,7 +442,7 @@ input[data-provide="datepicker"], input[type="number"], input[type="time"] { /* Information block with user and timestamp who created and edited the data */ -.admidio-admidio-info-created-edited { +.admidio-info-created-edited { font-size: 8pt; margin-top: 8px; } diff --git a/adm_program/modules/announcements/announcements.php b/adm_program/modules/announcements/announcements.php index c8bb94d98f..1141aa9659 100644 --- a/adm_program/modules/announcements/announcements.php +++ b/adm_program/modules/announcements/announcements.php @@ -159,13 +159,18 @@
'. $announcement->getValue('ann_description'). - '
'); } // Ende foreach diff --git a/adm_program/modules/announcements/announcements_new.php b/adm_program/modules/announcements/announcements_new.php index daead68dd2..df1c514098 100644 --- a/adm_program/modules/announcements/announcements_new.php +++ b/adm_program/modules/announcements/announcements_new.php @@ -106,7 +106,10 @@ } $form->addEditor('ann_description', $gL10n->get('SYS_TEXT'), $announcement->getValue('ann_description'), array('property' => FIELD_REQUIRED, 'height' => '400')); $form->addSubmitButton('btn_save', $gL10n->get('SYS_SAVE'), array('icon' => THEME_URL.'/icons/disk.png')); -$form->addHtml(admFuncShowCreateChangeInfoById($announcement->getValue('ann_usr_id_create'), $announcement->getValue('ann_timestamp_create'), $announcement->getValue('ann_usr_id_change'), $announcement->getValue('ann_timestamp_change'))); +$form->addHtml(admFuncShowCreateChangeInfoById( + $announcement->getValue('ann_usr_id_create'), $announcement->getValue('ann_timestamp_create'), + $announcement->getValue('ann_usr_id_change'), $announcement->getValue('ann_timestamp_change') +)); // add form to html page and show page $page->addHtml($form->show(false)); diff --git a/adm_program/system/function.php b/adm_program/system/function.php index 67de54cc0d..25622b2724 100644 --- a/adm_program/system/function.php +++ b/adm_program/system/function.php @@ -430,18 +430,18 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o $value = null; // set default value for each datatype if no value is given and no value was required - if(array_key_exists($variableName, $array) && $array[$variableName] !== '') + if (array_key_exists($variableName, $array) && $array[$variableName] !== '') { $value = $array[$variableName]; } else { - if($optionsAll['requireValue']) + if ($optionsAll['requireValue']) { // if value is required an no value is given then show error $errorMessage = $gL10n->get('SYS_INVALID_PAGE_VIEW'); } - elseif($optionsAll['defaultValue'] !== null) + elseif ($optionsAll['defaultValue'] !== null) { // if a default value was set then take this value $value = $optionsAll['defaultValue']; @@ -449,15 +449,15 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o else { // no value set then initialize the parameter - if($datatype === 'bool' || $datatype === 'boolean') + if ($datatype === 'bool' || $datatype === 'boolean') { $value = false; } - elseif($datatype === 'numeric' || $datatype === 'int') + elseif ($datatype === 'numeric' || $datatype === 'int') { $value = 0; } - elseif($datatype === 'float') + elseif ($datatype === 'float') { $value = 0.0; } @@ -472,7 +472,7 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o // check if parameter has a valid value // do a strict check with in_array because the function don't work properly - if($optionsAll['validValues'] !== null + if ($optionsAll['validValues'] !== null && !in_array(admStrToUpper($value), $optionsAll['validValues'], true) && !in_array(admStrToLower($value), $optionsAll['validValues'], true)) { @@ -484,12 +484,12 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o case 'file': try { - if($value !== '') + if ($value !== '') { admStrIsValidFileName($value); } } - catch(AdmException $e) + catch (AdmException $e) { $errorMessage = $e->getText(); } @@ -499,12 +499,12 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o // check if date is a valid Admidio date format $objAdmidioDate = DateTime::createFromFormat($gPreferences['system_date'], $value); - if(!$objAdmidioDate) + if (!$objAdmidioDate) { // check if date has english format $objEnglishDate = DateTime::createFromFormat('Y-m-d', $value); - if(!$objEnglishDate) + if (!$objEnglishDate) { $errorMessage = $gL10n->get('LST_NOT_VALID_DATE_FORMAT', $variableName); } @@ -564,14 +564,14 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o } // wurde kein Fehler entdeckt, dann den Inhalt der Variablen zurueckgeben - if($errorMessage === '') + if ($errorMessage === '') { return $value; } - if(isset($gMessage) && $gMessage instanceof \Message) + if (isset($gMessage) && $gMessage instanceof \Message) { - if($optionsAll['directOutput']) + if ($optionsAll['directOutput']) { $gMessage->showTextOnly(true); } @@ -603,64 +603,68 @@ function admFuncShowCreateChangeInfoById($userIdCreated, $timestampCreate, $user global $gDb, $gProfileFields, $gL10n, $gPreferences; // only show info if system setting is activated - if ($gPreferences['system_show_create_edit'] > 0) + if ((int) $gPreferences['system_show_create_edit'] === 0) { - $htmlCreateName = ''; - $htmlEditName = ''; + return ''; + } - // compose name of user who create the recordset - if ($timestampCreate !== '') + // compose name of user who create the recordset + $htmlCreateName = ''; + if ($timestampCreate !== '') + { + if ($userIdCreated > 0) { - if ($userIdCreated > 0) - { - $userCreate = new User($gDb, $gProfileFields, $userIdCreated); + $userCreate = new User($gDb, $gProfileFields, $userIdCreated); - if ($gPreferences['system_show_create_edit'] == 1) - { - $htmlCreateName = $userCreate->getValue('FIRST_NAME'). ' '. $userCreate->getValue('LAST_NAME'); - } - else - { - $htmlCreateName = $userCreate->getValue('usr_login_name'); - } + if ((int) $gPreferences['system_show_create_edit'] === 1) + { + $htmlCreateName = $userCreate->getValue('FIRST_NAME') . ' ' . $userCreate->getValue('LAST_NAME'); } else { - $htmlCreateName = $gL10n->get('SYS_DELETED_USER'); + $htmlCreateName = $userCreate->getValue('usr_login_name'); } } + else + { + $htmlCreateName = $gL10n->get('SYS_DELETED_USER'); + } + } - // compose name of user who edit the recordset - if ($timestampEdited !== '') + // compose name of user who edit the recordset + $htmlEditName = ''; + if ($timestampEdited !== '') + { + if ($userIdEdited > 0) { - if ($userIdEdited > 0) - { - $userEdit = new User($gDb, $gProfileFields, $userIdEdited); + $userEdit = new User($gDb, $gProfileFields, $userIdEdited); - if ($gPreferences['system_show_create_edit'] == 1) - { - $htmlEditName = $userEdit->getValue('FIRST_NAME') . ' ' . $userEdit->getValue('LAST_NAME'); - } - else - { - $htmlEditName = $userEdit->getValue('usr_login_name'); - } + if ((int) $gPreferences['system_show_create_edit'] === 1) + { + $htmlEditName = $userEdit->getValue('FIRST_NAME') . ' ' . $userEdit->getValue('LAST_NAME'); } else { - $htmlEditName = $gL10n->get('SYS_DELETED_USER'); + $htmlEditName = $userEdit->getValue('usr_login_name'); } } - - if ($htmlCreateName !== '' || $htmlEditName !== '') + else { - // get html output from other function - return admFuncShowCreateChangeInfoByName($htmlCreateName, $timestampCreate, $htmlEditName, - $timestampEdited, $userIdCreated, $userIdEdited); + $htmlEditName = $gL10n->get('SYS_DELETED_USER'); } } - return ''; + if ($htmlCreateName === '' && $htmlEditName === '') + { + return ''; + } + + // get html output from other function + return admFuncShowCreateChangeInfoByName( + $htmlCreateName, $timestampCreate, + $htmlEditName, $timestampEdited, + $userIdCreated, $userIdEdited + ); } /** @@ -681,58 +685,60 @@ function admFuncShowCreateChangeInfoByName($userNameCreated, $timestampCreate, $ { global $gL10n, $gValidLogin, $gPreferences; - $html = ''; - // only show info if system setting is activated - if($gPreferences['system_show_create_edit'] > 0) + if ((int) $gPreferences['system_show_create_edit'] === 0) { - // compose name of user who create the recordset - if($timestampCreate !== '') - { - $userNameCreated = trim($userNameCreated); + return ''; + } - if($userNameCreated === '') - { - $userNameCreated = $gL10n->get('SYS_DELETED_USER'); - } + $html = ''; - // if valid login and a user id is given than create a link to the profile of this user - if($gValidLogin && $userIdCreated > 0 && $userNameCreated !== $gL10n->get('SYS_SYSTEM')) - { - $userNameCreated = ''.$userNameCreated.''; - } + // compose name of user who create the recordset + if ($timestampCreate !== '') + { + $userNameCreated = trim($userNameCreated); - $html .= ''.$gL10n->get('SYS_CREATED_BY', $userNameCreated, $timestampCreate).''; + if ($userNameCreated === '') + { + $userNameCreated = $gL10n->get('SYS_DELETED_USER'); } - // compose name of user who edit the recordset - if($timestampEdited !== '') + // if valid login and a user id is given than create a link to the profile of this user + if ($gValidLogin && $userIdCreated > 0 && $userNameCreated !== $gL10n->get('SYS_SYSTEM')) { - $userNameEdited = trim($userNameEdited); + $userNameCreated = '' . $userNameCreated . ''; + } - if($userNameEdited === '') - { - $userNameEdited = $gL10n->get('SYS_DELETED_USER'); - } + $html .= '' . $gL10n->get('SYS_CREATED_BY', $userNameCreated, $timestampCreate) . ''; + } - // if valid login and a user id is given than create a link to the profile of this user - if($gValidLogin && $userIdEdited > 0 && $userNameEdited !== $gL10n->get('SYS_SYSTEM')) - { - $userNameEdited = ''.$userNameEdited.''; - } + // compose name of user who edit the recordset + if ($timestampEdited !== '') + { + $userNameEdited = trim($userNameEdited); - $html .= ''.$gL10n->get('SYS_LAST_EDITED_BY', $userNameEdited, $timestampEdited).''; + if ($userNameEdited === '') + { + $userNameEdited = $gL10n->get('SYS_DELETED_USER'); } - if($html !== '') + // if valid login and a user id is given than create a link to the profile of this user + if ($gValidLogin && $userIdEdited > 0 && $userNameEdited !== $gL10n->get('SYS_SYSTEM')) { - $html = '
'.$html.'
'; + $userNameEdited = '' . $userNameEdited . ''; } + + $html .= '' . $gL10n->get('SYS_LAST_EDITED_BY', $userNameEdited, $timestampEdited) . ''; } - return $html; + if ($html === '') + { + return ''; + } + + return '
' . $html . '
'; } /** @@ -744,37 +750,42 @@ function admFuncShowCreateChangeInfoByName($userNameCreated, $timestampCreate, $ */ function admFuncGetDirectoryEntries($directory, $searchType = 'file') { + if (!is_dir($directory)) + { + return false; + } + $dirHandle = @opendir($directory); - if ($dirHandle) + if ($dirHandle === false) { - $entries = array(); + return false; + } + + $entries = array(); - while (($entry = readdir($dirHandle)) !== false) + while (($entry = readdir($dirHandle)) !== false) + { + if ($searchType === 'all') + { + $entries[$entry] = $entry; // $entries[] = $entry; + } + elseif (strpos($entry, '.') !== 0) { - if ($searchType === 'all') + $resource = $directory . '/' . $entry; + + if ($searchType === 'both' + || ($searchType === 'file' && is_file($resource)) + || ($searchType === 'dir' && is_dir($resource))) { $entries[$entry] = $entry; // $entries[] = $entry; } - elseif (strpos($entry, '.') !== 0) - { - $resource = $directory . '/' . $entry; - - if ($searchType === 'both' - || ($searchType === 'file' && is_file($resource)) - || ($searchType === 'dir' && is_dir($resource))) - { - $entries[$entry] = $entry; // $entries[] = $entry; - } - } } - closedir($dirHandle); - - asort($entries); // sort($entries); - - return $entries; } + closedir($dirHandle); - return false; + asort($entries); // sort($entries); + + return $entries; } /**