Passed
Push — 1.7 ( 1d01aa...315bf1 )
by Greg
05:37
created
edituser.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
 $form_pass2          = Filter::post('form_pass2', WT_REGEX_PASSWORD);
45 45
 $form_email          = Filter::postEmail('form_email');
46 46
 $form_rootid         = Filter::post('form_rootid', WT_REGEX_XREF);
47
-$form_theme          = Filter::post('form_theme', implode('|', array_keys(Theme::themeNames())), '');;
47
+$form_theme          = Filter::post('form_theme', implode('|', array_keys(Theme::themeNames())), ''); ;
48 48
 $form_language       = Filter::post('form_language');
49 49
 $form_timezone       = Filter::post('form_timezone');
50 50
 $form_contact_method = Filter::post('form_contact_method');
Please login to merge, or discard this patch.
admin_site_logs.php 1 patch
Switch Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -98,52 +98,52 @@
 block discarded – undo
98 98
 }
99 99
 
100 100
 switch ($action) {
101
-    case 'delete':
102
-        $sql_delete =
103
-        "DELETE `##log` FROM `##log`" .
104
-        " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
105
-        " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
106
-
107
-        Database::prepare($sql_delete . $where)->execute($args);
108
-        break;
109
-
110
-    case 'export':
111
-        header('Content-Type: text/csv');
112
-        header('Content-Disposition: attachment; filename="webtrees-logs.csv"');
113
-        $rows = Database::prepare($sql_select . $where . ' ORDER BY log_id')->execute($args)->fetchAll();
114
-        foreach ($rows as $row) {
115
-            echo
116
-            '"', $row->log_time, '",',
117
-            '"', $row->log_type, '",',
118
-            '"', str_replace('"', '""', $row->log_message), '",',
119
-            '"', $row->ip_address, '",',
120
-            '"', str_replace('"', '""', $row->user_name), '",',
121
-            '"', str_replace('"', '""', $row->gedcom_name), '"',
122
-            "\n";
123
-        }
101
+        case 'delete':
102
+            $sql_delete =
103
+            "DELETE `##log` FROM `##log`" .
104
+            " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
105
+            " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
106
+
107
+            Database::prepare($sql_delete . $where)->execute($args);
108
+            break;
109
+
110
+        case 'export':
111
+            header('Content-Type: text/csv');
112
+            header('Content-Disposition: attachment; filename="webtrees-logs.csv"');
113
+            $rows = Database::prepare($sql_select . $where . ' ORDER BY log_id')->execute($args)->fetchAll();
114
+            foreach ($rows as $row) {
115
+                echo
116
+                '"', $row->log_time, '",',
117
+                '"', $row->log_type, '",',
118
+                '"', str_replace('"', '""', $row->log_message), '",',
119
+                '"', $row->ip_address, '",',
120
+                '"', str_replace('"', '""', $row->user_name), '",',
121
+                '"', str_replace('"', '""', $row->gedcom_name), '"',
122
+                "\n";
123
+            }
124 124
 
125
-        return;
126
-    case 'load_json':
127
-        $start  = Filter::getInteger('start');
128
-        $length = Filter::getInteger('length');
129
-        $order  = Filter::getArray('order');
130
-
131
-        if ($order) {
132
-            $order_by = " ORDER BY ";
133
-            foreach ($order as $key => $value) {
134
-                if ($key > 0) {
135
-                    $order_by .= ',';
136
-                }
137
-                // Datatables numbers columns 0, 1, 2
138
-                // MySQL numbers columns 1, 2, 3
139
-                switch ($value['dir']) {
125
+            return;
126
+        case 'load_json':
127
+            $start  = Filter::getInteger('start');
128
+            $length = Filter::getInteger('length');
129
+            $order  = Filter::getArray('order');
130
+
131
+            if ($order) {
132
+                $order_by = " ORDER BY ";
133
+                foreach ($order as $key => $value) {
134
+                    if ($key > 0) {
135
+                        $order_by .= ',';
136
+                    }
137
+                    // Datatables numbers columns 0, 1, 2
138
+                    // MySQL numbers columns 1, 2, 3
139
+                    switch ($value['dir']) {
140 140
                     case 'asc':
141 141
                         $order_by .= (1 + $value['column']) . " ASC ";
142 142
                         break;
143 143
                     case 'desc':
144 144
                         $order_by .= (1 + $value['column']) . " DESC ";
145 145
                     break;
146
-                }
146
+                    }
147 147
             }
148 148
         } else {
149 149
             $order_by = " ORDER BY 1 ASC";
Please login to merge, or discard this patch.
app/GedcomCode/GedcomCodeTemp.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,14 +60,14 @@
 block discarded – undo
60 60
             'MADRI', 'MANAU', 'MANHA', 'MANIL', 'MANTI', 'MEDFO', 'MELBO', 'MEMPH',
61 61
             'MERID', 'MEXIC', 'MNTVD', 'MONTE', 'MONTI', 'MONTR', 'MTIMP', 'NASHV',
62 62
             'NAUV2', 'NAUVO', 'NBEAC', 'NUKUA', 'NYORK', 'NZEAL', 'OAKLA', 'OAXAC',
63
-            'OGDEN', 'OKLAH',   'OQUIR', 'ORLAN', 'PALEG', 'PALMY', 'PANAM', 'PAPEE',
64
-            'PAYSO', 'PERTH',   'PHOEN', 'POFFI', 'PORTL', 'PREST', 'PROCC', 'PROVO',
63
+            'OGDEN', 'OKLAH', 'OQUIR', 'ORLAN', 'PALEG', 'PALMY', 'PANAM', 'PAPEE',
64
+            'PAYSO', 'PERTH', 'PHOEN', 'POFFI', 'PORTL', 'PREST', 'PROCC', 'PROVO',
65 65
             'QUETZ', 'RALEI', 'RECIF', 'REDLA', 'REGIN', 'RENO', 'REXBU', 'SACRA',
66
-            'SAMOA', 'SANTI',   'SANSA', 'SANTO', 'SDIEG', 'SDOMI', 'SEATT', 'SEOUL',
67
-            'SGEOR', 'SJOSE',   'SLAKE', 'SLOUI', 'SNOWF','SPAUL', 'SPMIN', 'SPOKA',
66
+            'SAMOA', 'SANTI', 'SANSA', 'SANTO', 'SDIEG', 'SDOMI', 'SEATT', 'SEOUL',
67
+            'SGEOR', 'SJOSE', 'SLAKE', 'SLOUI', 'SNOWF', 'SPAUL', 'SPMIN', 'SPOKA',
68 68
             'STOCK', 'SUVA', 'SWISS', 'SYDNE', 'TAIPE', 'TAMPI', 'TEGUC', 'TGUTI',
69
-            'TIHUA', 'TOKYO',   'TORNO', 'TRUJI', 'TWINF', 'VANCO', 'VERAC', 'VERNA',
70
-            'VILLA', 'WASHI',   'WINTE',
69
+            'TIHUA', 'TOKYO', 'TORNO', 'TRUJI', 'TWINF', 'VANCO', 'VERAC', 'VERNA',
70
+            'VILLA', 'WASHI', 'WINTE',
71 71
         );
72 72
     }
73 73
 
Please login to merge, or discard this patch.
app/Database.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,7 @@
 block discarded – undo
91 91
         // Create the underlying PDO object
92 92
         self::$pdo = new PDO(
93 93
             (substr($DBHOST, 0, 1) === '/' ?
94
-                "mysql:unix_socket={$DBHOST};dbname={$DBNAME}" :
95
-                "mysql:host={$DBHOST};dbname={$DBNAME};port={$DBPORT}"
94
+                "mysql:unix_socket={$DBHOST};dbname={$DBNAME}" : "mysql:host={$DBHOST};dbname={$DBNAME};port={$DBPORT}"
96 95
             ),
97 96
             $DBUSER, $DBPASS,
98 97
             array(
Please login to merge, or discard this patch.
app/Functions/FunctionsPrintLists.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1714,24 +1714,24 @@
 block discarded – undo
1714 1714
             if ($endjd === WT_CLIENT_JD) {
1715 1715
                 // We're dealing with the Today’s Events block
1716 1716
                 if ($filter === 0) {
1717
-                    $html .=  I18N::translate('No events exist for today.');
1717
+                    $html .= I18N::translate('No events exist for today.');
1718 1718
                 } else {
1719
-                    $html .=  I18N::translate('No events for living individuals exist for today.');
1719
+                    $html .= I18N::translate('No events for living individuals exist for today.');
1720 1720
                 }
1721 1721
             } else {
1722 1722
                 // We're dealing with the Upcoming Events block
1723 1723
                 if ($filter === 0) {
1724 1724
                     if ($endjd === $startjd) {
1725
-                        $html .=  I18N::translate('No events exist for tomorrow.');
1725
+                        $html .= I18N::translate('No events exist for tomorrow.');
1726 1726
                     } else {
1727
-                        $html .=  /* I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” */ I18N::plural('No events exist for the next %s day.', 'No events exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
1727
+                        $html .= /* I18N: translation for %s==1 is unused; it is translated separately as “tomorrow” */ I18N::plural('No events exist for the next %s day.', 'No events exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
1728 1728
                     }
1729 1729
                 } else {
1730 1730
                     if ($endjd === $startjd) {
1731
-                        $html .=  I18N::translate('No events for living individuals exist for tomorrow.');
1731
+                        $html .= I18N::translate('No events for living individuals exist for tomorrow.');
1732 1732
                     } else {
1733 1733
                         // I18N: translation for %s==1 is unused; it is translated separately as “tomorrow”
1734
-                        $html .=  I18N::plural('No events for living people exist for the next %s day.', 'No events for living people exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
1734
+                        $html .= I18N::plural('No events for living people exist for the next %s day.', 'No events for living people exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
1735 1735
                     }
1736 1736
                 }
1737 1737
             }
Please login to merge, or discard this patch.
admin_site_config.php 1 patch
Switch Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -137,25 +137,25 @@
 block discarded – undo
137 137
 }
138 138
 
139 139
 switch (Filter::get('action')) {
140
-    case 'site':
141
-        $controller->setPageTitle(I18N::translate('Website preferences'));
142
-        break;
143
-    case 'email':
144
-        $controller->setPageTitle(I18N::translate('Sending email'));
145
-        break;
146
-    case 'login':
147
-        $controller->setPageTitle(I18N::translate('Sign-in and registration'));
148
-        break;
149
-    case 'tracking':
150
-        $controller->setPageTitle(/* I18N: e.g. http://www.google.com/analytics */ I18N::translate('Tracking and analytics'));
151
-        break;
152
-    case 'languages':
153
-        $controller->setPageTitle(I18N::translate('Languages'));
154
-        break;
155
-    default:
156
-        header('Location: ' . WT_BASE_URL . 'admin.php');
157
-
158
-        return;
140
+        case 'site':
141
+            $controller->setPageTitle(I18N::translate('Website preferences'));
142
+            break;
143
+        case 'email':
144
+            $controller->setPageTitle(I18N::translate('Sending email'));
145
+            break;
146
+        case 'login':
147
+            $controller->setPageTitle(I18N::translate('Sign-in and registration'));
148
+            break;
149
+        case 'tracking':
150
+            $controller->setPageTitle(/* I18N: e.g. http://www.google.com/analytics */ I18N::translate('Tracking and analytics'));
151
+            break;
152
+        case 'languages':
153
+            $controller->setPageTitle(I18N::translate('Languages'));
154
+            break;
155
+        default:
156
+            header('Location: ' . WT_BASE_URL . 'admin.php');
157
+
158
+            return;
159 159
 }
160 160
 
161 161
 $controller->pageHeader();
Please login to merge, or discard this patch.
ancestry.php 1 patch
Switch Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -129,46 +129,46 @@
 block discarded – undo
129 129
     return;
130 130
 }
131 131
 switch ($controller->chart_style) {
132
-    case 0:
133
-        // List
134
-        echo '<ul id="ancestry_chart" class="chart_common">';
135
-        $controller->printChildAscendancy($controller->root, 1, $controller->generations - 1);
136
-        echo '</ul>';
137
-        echo '<br>';
138
-        break;
139
-    case 1:
140
-        echo '<div id="ancestry_booklet">';
141
-        // Booklet
142
-        // first page : show indi facts
143
-        FunctionsPrint::printPedigreePerson($controller->root, $controller->showFull());
144
-        // process the tree
145
-        $ancestors = $controller->sosaAncestors($controller->generations - 1);
146
-        $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
132
+        case 0:
133
+            // List
134
+            echo '<ul id="ancestry_chart" class="chart_common">';
135
+            $controller->printChildAscendancy($controller->root, 1, $controller->generations - 1);
136
+            echo '</ul>';
137
+            echo '<br>';
138
+            break;
139
+        case 1:
140
+            echo '<div id="ancestry_booklet">';
141
+            // Booklet
142
+            // first page : show indi facts
143
+            FunctionsPrint::printPedigreePerson($controller->root, $controller->showFull());
144
+            // process the tree
145
+            $ancestors = $controller->sosaAncestors($controller->generations - 1);
146
+            $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
147 147
 
148
-        foreach ($ancestors as $sosa => $individual) {
149
-            foreach ($individual->getChildFamilies() as $family) {
150
-                FunctionsCharts::printSosaFamily($family->getXref(), $individual->getXref(), $sosa, '', '', '', $controller->show_cousins, $controller->showFull());
148
+            foreach ($ancestors as $sosa => $individual) {
149
+                foreach ($individual->getChildFamilies() as $family) {
150
+                    FunctionsCharts::printSosaFamily($family->getXref(), $individual->getXref(), $sosa, '', '', '', $controller->show_cousins, $controller->showFull());
151
+                }
151 152
             }
152
-        }
153
-        echo '</div>';
154
-        break;
155
-    case 2:
156
-        // Individual list
157
-        $ancestors = $controller->sosaAncestors($controller->generations);
158
-        $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
159
-        echo '<div id="ancestry-list">', FunctionsPrintLists::individualTable($ancestors, 'sosa'), '</div>';
160
-        break;
161
-    case 3:
162
-        // Family list
163
-        $ancestors = $controller->sosaAncestors($controller->generations - 1);
164
-        $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
165
-        $families  = array();
166
-        foreach ($ancestors as $individual) {
167
-            foreach ($individual->getChildFamilies() as $family) {
168
-                $families[$family->getXref()] = $family;
153
+            echo '</div>';
154
+            break;
155
+        case 2:
156
+            // Individual list
157
+            $ancestors = $controller->sosaAncestors($controller->generations);
158
+            $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
159
+            echo '<div id="ancestry-list">', FunctionsPrintLists::individualTable($ancestors, 'sosa'), '</div>';
160
+            break;
161
+        case 3:
162
+            // Family list
163
+            $ancestors = $controller->sosaAncestors($controller->generations - 1);
164
+            $ancestors = array_filter($ancestors); // The SOSA array includes empty placeholders
165
+            $families  = array();
166
+            foreach ($ancestors as $individual) {
167
+                foreach ($individual->getChildFamilies() as $family) {
168
+                    $families[$family->getXref()] = $family;
169
+                }
169 170
             }
170
-        }
171
-        echo '<div id="ancestry-list">', FunctionsPrintLists::familyTable($families), '</div>';
172
-        break;
171
+            echo '<div id="ancestry-list">', FunctionsPrintLists::familyTable($families), '</div>';
172
+            break;
173 173
 }
174 174
 echo '</div>';
Please login to merge, or discard this patch.
action.php 1 patch
Switch Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -38,34 +38,34 @@  discard block
 block discarded – undo
38 38
 }
39 39
 
40 40
 switch (Filter::post('action')) {
41
-    case 'accept-changes':
42
-        // Accept all the pending changes for a record
43
-        $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
44
-        if ($record && Auth::isModerator($record->getTree()) && $record->canShow() && $record->canEdit()) {
45
-            if ($record->isPendingDeletion()) {
46
-                FlashMessages::addMessage(/* I18N: %s is the name of a genealogy record */
47
-                I18N::translate('“%s” has been deleted.', $record->getFullName()));
41
+        case 'accept-changes':
42
+            // Accept all the pending changes for a record
43
+            $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
44
+            if ($record && Auth::isModerator($record->getTree()) && $record->canShow() && $record->canEdit()) {
45
+                if ($record->isPendingDeletion()) {
46
+                    FlashMessages::addMessage(/* I18N: %s is the name of a genealogy record */
47
+                    I18N::translate('“%s” has been deleted.', $record->getFullName()));
48
+                } else {
49
+                    FlashMessages::addMessage(/* I18N: %s is the name of a genealogy record */
50
+                    I18N::translate('The changes to “%s” have been accepted.', $record->getFullName()));
51
+                }
52
+                FunctionsImport::acceptAllChanges($record->getXref(), $record->getTree()->getTreeId());
48 53
             } else {
49
-                FlashMessages::addMessage(/* I18N: %s is the name of a genealogy record */
50
-                I18N::translate('The changes to “%s” have been accepted.', $record->getFullName()));
54
+                http_response_code(406);
51 55
             }
52
-            FunctionsImport::acceptAllChanges($record->getXref(), $record->getTree()->getTreeId());
53
-        } else {
54
-            http_response_code(406);
55
-        }
56
-        break;
56
+            break;
57 57
 
58
-    case 'copy-fact':
59
-        // Copy a fact to the clipboard
60
-        $xref    = Filter::post('xref', WT_REGEX_XREF);
61
-        $fact_id = Filter::post('fact_id');
58
+        case 'copy-fact':
59
+            // Copy a fact to the clipboard
60
+            $xref    = Filter::post('xref', WT_REGEX_XREF);
61
+            $fact_id = Filter::post('fact_id');
62 62
 
63
-        $record = GedcomRecord::getInstance($xref, $WT_TREE);
63
+            $record = GedcomRecord::getInstance($xref, $WT_TREE);
64 64
 
65
-        if ($record && $record->canEdit()) {
66
-            foreach ($record->getFacts() as $fact) {
67
-                if ($fact->getFactId() == $fact_id) {
68
-                    switch ($fact->getTag()) {
65
+            if ($record && $record->canEdit()) {
66
+                foreach ($record->getFacts() as $fact) {
67
+                    if ($fact->getFactId() == $fact_id) {
68
+                        switch ($fact->getTag()) {
69 69
                         case 'NOTE':
70 70
                         case 'SOUR':
71 71
                         case 'OBJE':
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                         default:
75 75
                             $type = $record::RECORD_TYPE; // paste only to the same record type
76 76
                         break;
77
-                    }
77
+                        }
78 78
                     $clipboard = Session::get('clipboard');
79 79
                     if (!is_array($clipboard)) {
80 80
                         $clipboard = array();
@@ -96,158 +96,158 @@  discard block
 block discarded – undo
96 96
         }
97 97
         break;
98 98
 
99
-    case 'paste-fact':
100
-        // Paste a fact from the clipboard
101
-        $xref      = Filter::post('xref', WT_REGEX_XREF);
102
-        $fact_id   = Filter::post('fact_id');
103
-        $record    = GedcomRecord::getInstance($xref, $WT_TREE);
104
-        $clipboard = Session::get('clipboard');
99
+        case 'paste-fact':
100
+            // Paste a fact from the clipboard
101
+            $xref      = Filter::post('xref', WT_REGEX_XREF);
102
+            $fact_id   = Filter::post('fact_id');
103
+            $record    = GedcomRecord::getInstance($xref, $WT_TREE);
104
+            $clipboard = Session::get('clipboard');
105 105
 
106
-        if ($record && $record->canEdit() && isset($clipboard[$fact_id])) {
107
-            $record->createFact($clipboard[$fact_id]['factrec'], true);
108
-        }
109
-        break;
110
-
111
-    case 'delete-fact':
112
-        $xref    = Filter::post('xref', WT_REGEX_XREF);
113
-        $fact_id = Filter::post('fact_id');
114
-
115
-        $record = GedcomRecord::getInstance($xref, $WT_TREE);
116
-        if ($record && $record->canShow() && $record->canEdit()) {
117
-            foreach ($record->getFacts() as $fact) {
118
-                if ($fact->getFactId() == $fact_id && $fact->canShow() && $fact->canEdit()) {
119
-                    $record->deleteFact($fact_id, true);
120
-                    break 2;
106
+            if ($record && $record->canEdit() && isset($clipboard[$fact_id])) {
107
+                $record->createFact($clipboard[$fact_id]['factrec'], true);
108
+            }
109
+            break;
110
+
111
+        case 'delete-fact':
112
+            $xref    = Filter::post('xref', WT_REGEX_XREF);
113
+            $fact_id = Filter::post('fact_id');
114
+
115
+            $record = GedcomRecord::getInstance($xref, $WT_TREE);
116
+            if ($record && $record->canShow() && $record->canEdit()) {
117
+                foreach ($record->getFacts() as $fact) {
118
+                    if ($fact->getFactId() == $fact_id && $fact->canShow() && $fact->canEdit()) {
119
+                        $record->deleteFact($fact_id, true);
120
+                        break 2;
121
+                    }
121 122
                 }
122 123
             }
123
-        }
124
-
125
-        // Can’t find the record/fact, or don’t have permission to delete it.
126
-        http_response_code(406);
127
-        break;
128 124
 
129
-    case 'delete-record':
130
-        $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
131
-        if ($record && Auth::isEditor($record->getTree()) && $record->canShow() && $record->canEdit()) {
132
-            // Delete links to this record
133
-            foreach (FunctionsDb::fetchAllLinks($record->getXref(), $record->getTree()->getTreeId()) as $xref) {
134
-                $linker     = GedcomRecord::getInstance($xref, $WT_TREE);
135
-                $old_gedcom = $linker->getGedcom();
136
-                $new_gedcom = FunctionsEdit::removeLinks($old_gedcom, $record->getXref());
137
-                // FunctionsDb::fetch_all_links() does not take account of pending changes. The links (or even the
138
-                // record itself) may have already been deleted.
139
-                if ($old_gedcom !== $new_gedcom) {
140
-                    // If we have removed a link from a family to an individual, and it has only one member
141
-                    if (preg_match('/^0 @' . WT_REGEX_XREF . '@ FAM/', $new_gedcom) && preg_match_all('/\n1 (HUSB|WIFE|CHIL) @(' . WT_REGEX_XREF . ')@/', $new_gedcom, $match) == 1) {
142
-                        // Delete the family
143
-                        $family = GedcomRecord::getInstance($xref, $WT_TREE);
144
-                        FlashMessages::addMessage(/* I18N: %s is the name of a family group, e.g. “Husband name + Wife name” */ I18N::translate('The family “%s” has been deleted because it only has one member.', $family->getFullName()));
145
-                        $family->deleteRecord();
146
-                        // Delete any remaining link to this family
147
-                        if ($match) {
148
-                            $relict     = GedcomRecord::getInstance($match[2][0], $WT_TREE);
149
-                            $new_gedcom = $relict->getGedcom();
150
-                            $new_gedcom = FunctionsEdit::removeLinks($new_gedcom, $linker->getXref());
151
-                            $relict->updateRecord($new_gedcom, false);
152
-                            FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $relict->getFullName(), $family->getFullName()));
125
+            // Can’t find the record/fact, or don’t have permission to delete it.
126
+            http_response_code(406);
127
+            break;
128
+
129
+        case 'delete-record':
130
+            $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
131
+            if ($record && Auth::isEditor($record->getTree()) && $record->canShow() && $record->canEdit()) {
132
+                // Delete links to this record
133
+                foreach (FunctionsDb::fetchAllLinks($record->getXref(), $record->getTree()->getTreeId()) as $xref) {
134
+                    $linker     = GedcomRecord::getInstance($xref, $WT_TREE);
135
+                    $old_gedcom = $linker->getGedcom();
136
+                    $new_gedcom = FunctionsEdit::removeLinks($old_gedcom, $record->getXref());
137
+                    // FunctionsDb::fetch_all_links() does not take account of pending changes. The links (or even the
138
+                    // record itself) may have already been deleted.
139
+                    if ($old_gedcom !== $new_gedcom) {
140
+                        // If we have removed a link from a family to an individual, and it has only one member
141
+                        if (preg_match('/^0 @' . WT_REGEX_XREF . '@ FAM/', $new_gedcom) && preg_match_all('/\n1 (HUSB|WIFE|CHIL) @(' . WT_REGEX_XREF . ')@/', $new_gedcom, $match) == 1) {
142
+                            // Delete the family
143
+                            $family = GedcomRecord::getInstance($xref, $WT_TREE);
144
+                            FlashMessages::addMessage(/* I18N: %s is the name of a family group, e.g. “Husband name + Wife name” */ I18N::translate('The family “%s” has been deleted because it only has one member.', $family->getFullName()));
145
+                            $family->deleteRecord();
146
+                            // Delete any remaining link to this family
147
+                            if ($match) {
148
+                                $relict     = GedcomRecord::getInstance($match[2][0], $WT_TREE);
149
+                                $new_gedcom = $relict->getGedcom();
150
+                                $new_gedcom = FunctionsEdit::removeLinks($new_gedcom, $linker->getXref());
151
+                                $relict->updateRecord($new_gedcom, false);
152
+                                FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $relict->getFullName(), $family->getFullName()));
153
+                            }
154
+                        } else {
155
+                            // Remove links from $linker to $record
156
+                            FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $linker->getFullName(), $record->getFullName()));
157
+                            $linker->updateRecord($new_gedcom, false);
153 158
                         }
154
-                    } else {
155
-                        // Remove links from $linker to $record
156
-                        FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from “%1$s” to “%2$s” has been deleted.', $linker->getFullName(), $record->getFullName()));
157
-                        $linker->updateRecord($new_gedcom, false);
158 159
                     }
159 160
                 }
161
+                // Delete the record itself
162
+                $record->deleteRecord();
163
+            } else {
164
+                http_response_code(406);
160 165
             }
161
-            // Delete the record itself
162
-            $record->deleteRecord();
163
-        } else {
164
-            http_response_code(406);
165
-        }
166
-        break;
167
-
168
-    case 'delete-user':
169
-        $user = User::find(Filter::postInteger('user_id'));
166
+            break;
170 167
 
171
-        if ($user && Auth::isAdmin() && Auth::user() !== $user) {
172
-            Log::addAuthenticationLog('Deleted user: ' . $user->getUserName());
173
-            $user->delete();
174
-        }
175
-        break;
168
+        case 'delete-user':
169
+            $user = User::find(Filter::postInteger('user_id'));
176 170
 
177
-    case 'language':
178
-        // Change the current language
179
-        $language = Filter::post('language');
180
-        try {
181
-            I18N::init($language);
182
-            Session::put('locale', $language);
183
-            // Remember our selection
184
-            Auth::user()->setPreference('language', $language);
185
-        } catch (\Exception $ex) {
186
-            // Request for a non-existant language.
187
-            http_response_code(406);
188
-        }
189
-        break;
190
-
191
-    case 'masquerade':
192
-        $user = User::find(Filter::postInteger('user_id'));
171
+            if ($user && Auth::isAdmin() && Auth::user() !== $user) {
172
+                Log::addAuthenticationLog('Deleted user: ' . $user->getUserName());
173
+                $user->delete();
174
+            }
175
+            break;
176
+
177
+        case 'language':
178
+            // Change the current language
179
+            $language = Filter::post('language');
180
+            try {
181
+                I18N::init($language);
182
+                Session::put('locale', $language);
183
+                // Remember our selection
184
+                Auth::user()->setPreference('language', $language);
185
+            } catch (\Exception $ex) {
186
+                // Request for a non-existant language.
187
+                http_response_code(406);
188
+            }
189
+            break;
193 190
 
194
-        if ($user && Auth::isAdmin() && Auth::user() !== $user) {
195
-            Log::addAuthenticationLog('Masquerade as user: ' . $user->getUserName());
196
-            Auth::login($user);
197
-            Session::put('masquerade', '1');
198
-        } else {
199
-            http_response_code(406);
200
-        }
201
-        break;
191
+        case 'masquerade':
192
+            $user = User::find(Filter::postInteger('user_id'));
202 193
 
203
-    case 'unlink-media':
204
-        // Remove links from an individual and their spouse-family records to a media object.
205
-        // Used by the "unlink" option on the album (lightbox) tab.
206
-        $source = Individual::getInstance(Filter::post('source', WT_REGEX_XREF), $WT_TREE);
207
-        $target = Filter::post('target', WT_REGEX_XREF);
208
-        if ($source && $source->canShow() && $source->canEdit() && $target) {
209
-            // Consider the individual and their spouse-family records
210
-            $sources   = $source->getSpouseFamilies();
211
-            $sources[] = $source;
212
-            foreach ($sources as $source) {
213
-                foreach ($source->getFacts() as $fact) {
214
-                    if (!$fact->isPendingDeletion()) {
215
-                        if ($fact->getValue() == '@' . $target . '@') {
216
-                            // Level 1 links
217
-                            $source->deleteFact($fact->getFactId(), true);
218
-                        } elseif (strpos($fact->getGedcom(), ' @' . $target . '@')) {
219
-                            // Level 2-3 links
220
-                            $source->updateFact($fact->getFactId(), preg_replace(array('/\n2 OBJE @' . $target . '@(\n[3-9].*)*/', '/\n3 OBJE @' . $target . '@(\n[4-9].*)*/'), '', $fact->getGedcom()), true);
194
+            if ($user && Auth::isAdmin() && Auth::user() !== $user) {
195
+                Log::addAuthenticationLog('Masquerade as user: ' . $user->getUserName());
196
+                Auth::login($user);
197
+                Session::put('masquerade', '1');
198
+            } else {
199
+                http_response_code(406);
200
+            }
201
+            break;
202
+
203
+        case 'unlink-media':
204
+            // Remove links from an individual and their spouse-family records to a media object.
205
+            // Used by the "unlink" option on the album (lightbox) tab.
206
+            $source = Individual::getInstance(Filter::post('source', WT_REGEX_XREF), $WT_TREE);
207
+            $target = Filter::post('target', WT_REGEX_XREF);
208
+            if ($source && $source->canShow() && $source->canEdit() && $target) {
209
+                // Consider the individual and their spouse-family records
210
+                $sources   = $source->getSpouseFamilies();
211
+                $sources[] = $source;
212
+                foreach ($sources as $source) {
213
+                    foreach ($source->getFacts() as $fact) {
214
+                        if (!$fact->isPendingDeletion()) {
215
+                            if ($fact->getValue() == '@' . $target . '@') {
216
+                                // Level 1 links
217
+                                $source->deleteFact($fact->getFactId(), true);
218
+                            } elseif (strpos($fact->getGedcom(), ' @' . $target . '@')) {
219
+                                // Level 2-3 links
220
+                                $source->updateFact($fact->getFactId(), preg_replace(array('/\n2 OBJE @' . $target . '@(\n[3-9].*)*/', '/\n3 OBJE @' . $target . '@(\n[4-9].*)*/'), '', $fact->getGedcom()), true);
221
+                            }
221 222
                         }
222 223
                     }
223 224
                 }
225
+            } else {
226
+                http_response_code(406);
224 227
             }
225
-        } else {
226
-            http_response_code(406);
227
-        }
228
-        break;
229
-
230
-    case 'reject-changes':
231
-        // Reject all the pending changes for a record
232
-        $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
233
-        if ($record && $record->canEdit() && Auth::isModerator($record->getTree())) {
234
-            FlashMessages::addMessage(/* I18N: %s is the name of an individual, source or other record */ I18N::translate('The changes to “%s” have been rejected.', $record->getFullName()));
235
-            FunctionsImport::rejectAllChanges($record);
236
-        } else {
237
-            http_response_code(406);
238
-        }
239
-        break;
240
-
241
-    case 'theme':
242
-        // Change the current theme
243
-        $theme = Filter::post('theme');
244
-        if (Site::getPreference('ALLOW_USER_THEMES') && array_key_exists($theme, Theme::themeNames())) {
245
-            Session::put('theme_id', $theme);
246
-            // Remember our selection
247
-            Auth::user()->setPreference('theme', $theme);
248
-        } else {
249
-            // Request for a non-existant theme.
250
-            http_response_code(406);
251
-        }
252
-        break;
228
+            break;
229
+
230
+        case 'reject-changes':
231
+            // Reject all the pending changes for a record
232
+            $record = GedcomRecord::getInstance(Filter::post('xref', WT_REGEX_XREF), $WT_TREE);
233
+            if ($record && $record->canEdit() && Auth::isModerator($record->getTree())) {
234
+                FlashMessages::addMessage(/* I18N: %s is the name of an individual, source or other record */ I18N::translate('The changes to “%s” have been rejected.', $record->getFullName()));
235
+                FunctionsImport::rejectAllChanges($record);
236
+            } else {
237
+                http_response_code(406);
238
+            }
239
+            break;
240
+
241
+        case 'theme':
242
+            // Change the current theme
243
+            $theme = Filter::post('theme');
244
+            if (Site::getPreference('ALLOW_USER_THEMES') && array_key_exists($theme, Theme::themeNames())) {
245
+                Session::put('theme_id', $theme);
246
+                // Remember our selection
247
+                Auth::user()->setPreference('theme', $theme);
248
+            } else {
249
+                // Request for a non-existant theme.
250
+                http_response_code(406);
251
+            }
252
+            break;
253 253
 }
Please login to merge, or discard this patch.
admin_site_change.php 1 patch
Switch Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -111,53 +111,53 @@
 block discarded – undo
111 111
 }
112 112
 
113 113
 switch ($action) {
114
-    case 'delete':
115
-        $sql_delete =
116
-        "DELETE `##change` FROM `##change`" .
117
-        " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
118
-        " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
119
-
120
-        Database::prepare($sql_delete . $where)->execute($args);
121
-        break;
122
-
123
-    case 'export':
124
-        header('Content-Type: text/csv');
125
-        header('Content-Disposition: attachment; filename="webtrees-changes.csv"');
126
-        $rows = Database::prepare($sql_select . $where . ' ORDER BY change_id')->execute($args)->fetchAll();
127
-        foreach ($rows as $row) {
128
-            echo
129
-            '"', $row->change_time, '",',
130
-            '"', $row->status, '",',
131
-            '"', $row->xref, '",',
132
-            '"', str_replace('"', '""', $row->old_gedcom), '",',
133
-            '"', str_replace('"', '""', $row->new_gedcom), '",',
134
-            '"', str_replace('"', '""', $row->user_name), '",',
135
-            '"', str_replace('"', '""', $row->gedcom_name), '"',
136
-            "\n";
137
-        }
114
+        case 'delete':
115
+            $sql_delete =
116
+            "DELETE `##change` FROM `##change`" .
117
+            " LEFT JOIN `##user` USING (user_id)" . // user may be deleted
118
+            " LEFT JOIN `##gedcom` USING (gedcom_id)"; // gedcom may be deleted
119
+
120
+            Database::prepare($sql_delete . $where)->execute($args);
121
+            break;
122
+
123
+        case 'export':
124
+            header('Content-Type: text/csv');
125
+            header('Content-Disposition: attachment; filename="webtrees-changes.csv"');
126
+            $rows = Database::prepare($sql_select . $where . ' ORDER BY change_id')->execute($args)->fetchAll();
127
+            foreach ($rows as $row) {
128
+                echo
129
+                '"', $row->change_time, '",',
130
+                '"', $row->status, '",',
131
+                '"', $row->xref, '",',
132
+                '"', str_replace('"', '""', $row->old_gedcom), '",',
133
+                '"', str_replace('"', '""', $row->new_gedcom), '",',
134
+                '"', str_replace('"', '""', $row->user_name), '",',
135
+                '"', str_replace('"', '""', $row->gedcom_name), '"',
136
+                "\n";
137
+            }
138 138
 
139
-        return;
140
-    case 'load_json':
141
-        $start  = Filter::getInteger('start');
142
-        $length = Filter::getInteger('length');
143
-        $order  = Filter::getArray('order');
144
-
145
-        if ($order) {
146
-            $order_by = " ORDER BY ";
147
-            foreach ($order as $key => $value) {
148
-                if ($key > 0) {
149
-                    $order_by .= ',';
150
-                }
151
-                // Datatables numbers columns 0, 1, 2
152
-                // MySQL numbers columns 1, 2, 3
153
-                switch ($value['dir']) {
139
+            return;
140
+        case 'load_json':
141
+            $start  = Filter::getInteger('start');
142
+            $length = Filter::getInteger('length');
143
+            $order  = Filter::getArray('order');
144
+
145
+            if ($order) {
146
+                $order_by = " ORDER BY ";
147
+                foreach ($order as $key => $value) {
148
+                    if ($key > 0) {
149
+                        $order_by .= ',';
150
+                    }
151
+                    // Datatables numbers columns 0, 1, 2
152
+                    // MySQL numbers columns 1, 2, 3
153
+                    switch ($value['dir']) {
154 154
                     case 'asc':
155 155
                         $order_by .= (1 + $value['column']) . " ASC ";
156 156
                         break;
157 157
                     case 'desc':
158 158
                         $order_by .= (1 + $value['column']) . " DESC ";
159 159
                     break;
160
-                }
160
+                    }
161 161
             }
162 162
         } else {
163 163
             $order_by = " ORDER BY 1 DESC";
Please login to merge, or discard this patch.