1<?php
2/**
3 * Shows the list of records ordered by categories.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public License,
6 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
7 * obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * @package phpMyFAQ
10 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
11 * @author Minoru TODA <todam@netjapan.co.jp>
12 * @copyright 2003-2020 phpMyFAQ Team
13 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link https://www.phpmyfaq.de
15 * @since 2003-02-23
16 */
17
18use phpMyFAQ\Category;
19use phpMyFAQ\Category\CategoryRelation;
20use phpMyFAQ\Comments;
21use phpMyFAQ\Date;
22use phpMyFAQ\Database;
23use phpMyFAQ\Faq;
24use phpMyFAQ\Filter;
25use phpMyFAQ\Helper\CategoryHelper;
26use phpMyFAQ\Helper\FaqHelper;
27use phpMyFAQ\Language;
28use phpMyFAQ\LinkVerifier;
29use phpMyFAQ\Search\SearchFactory;
30use phpMyFAQ\Visits;
31
32if (!defined('IS_VALID_PHPMYFAQ')) {
33    http_response_code(400);
34    exit();
35}
36?>
37        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
38          <h1 class="h2">
39            <i aria-hidden="true" class="fa fa-list-alt"></i>
40              <?= $PMF_LANG['ad_entry_aor'] ?>
41          </h1>
42        </div>
43
44        <div class="row">
45            <div class="col-lg-12">
46<?php
47if ($user->perm->checkRight($user->getUserId(), 'edit_faq') || $user->perm->checkRight($user->getUserId(), 'delete_faq')) {
48    $category = new Category($faqConfig, [], false);
49    $category->setUser($currentAdminUser);
50    $category->setGroups($currentAdminGroups);
51    $category->transform(0);
52    $category->buildTree();
53
54    $categoryHelper = new CategoryHelper();
55    $categoryHelper->setCategory($category);
56
57    $categoryRelation = new CategoryRelation($faqConfig);
58    $categoryRelation->setGroups($currentAdminGroups);
59
60    $faqHelper = new FaqHelper($faqConfig);
61
62
63    $linkVerifier = new LinkVerifier($faqConfig, $user->getLogin());
64    if ($linkVerifier->isReady()) {
65?>
66    <script>
67        function getImageElement(id, lang) {
68            return $('#imgurl_' + lang + '_' + id);
69        }
70
71        function getSpanElement(id, lang) {
72            return $('#spanurl_' + lang + '_' + id);
73        }
74
75        function getDivElement(id, lang) {
76            return $('#divurl_' + lang + '_' + id);
77        }
78
79        function onDemandVerifyURL(id, lang, target) {
80            var target = getSpanElement(id, lang),
81                widthPx  = 780,
82                heigthPx = 450,
83                leftPx   = (screen.width  - widthPx) / 2,
84                topPx    = (screen.height - heigthPx) / 2,
85                pmfWindow = window.open('index.php?action=ajax&ajax=onDemandURL&id=' + id + '&artlang=' + lang, 'onDemandURLVerification', 'toolbar=no, location=no, status=no, menubar=no, width=' + widthPx + ', height=' + heigthPx + ', left=' + leftPx + ', top=' + topPx + ', resizable=yes, scrollbars=yes');
86                pmfWindow.focus();
87
88            verifyEntryURL(id, lang);
89        }
90
91        function verifyEntryURL(id, lang) {
92            const target = getSpanElement(id, lang);
93
94            // !!IMPORTANT!! DISABLE ONLOAD. If you do not do this, you will get infinite loop!
95            getImageElement(id, lang).onload = '';
96
97            //target.src = "images/url-checking.png";
98            getDivElement(id, lang).className = "url-checking";
99            target.innerHTML = "<?= $PMF_LANG['ad_linkcheck_feedback_url-checking'] ?>";
100
101            const url = 'index.php';
102            const pars = 'action=ajax&ajax=verifyURL&id=' + id + '&artlang=' + lang;
103            const myAjax = new jQuery.ajax({url: url,
104                type: 'get',
105                data: pars,
106                complete: verifyEntryURL_success,
107                error: verifyEntryURL_failure});
108
109            function verifyEntryURL_success(XmlRequest)
110            {
111                let allResponses = new [];
112                allResponses['batch1'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-batch1'] ?>";
113                allResponses['batch2'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-batch2'] ?>";
114                allResponses['batch3'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-batch3'] ?>";
115                allResponses['checking'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-checking'] ?>";
116                allResponses['disabled'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-disabled'] ?>";
117                allResponses['linkbad'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-linkbad'] ?>";
118                allResponses['linkok'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-linkok'] ?>";
119                allResponses['noaccess'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-noaccess'] ?>";
120                allResponses['noajax'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-noajax'] ?>";
121                allResponses['nolinks'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-nolinks'] ?>";
122                allResponses['noscript'] = "<?= $PMF_LANG['ad_linkcheck_feedback_url-noscript'] ?>";
123                getDivElement(id, lang).className = "url-" + XmlRequest.responseText;
124                if (typeof(allResponses[XmlRequest.responseText]) === "undefined") {
125                    getDivElement(id, lang).className = "url-noajax ";
126                    target.html(allResponses['noajax']);
127                } else {
128                    target.html(allResponses[XmlRequest.responseText]);
129                }
130            }
131
132            function verifyEntryURL_failure(XmlRequest)
133            {
134                getDivElement(id, lang).className = "url-noaccess";
135                target.html("<?= $PMF_LANG['ad_linkcheck_feedback_url-noaccess'] ?>");
136            }
137
138        }
139    </script>
140<?php
141
142    }
143
144    $faq = new Faq($faqConfig);
145    $faq->setUser($currentAdminUser);
146    $faq->setGroups($currentAdminGroups);
147    $date = new Date($faqConfig);
148
149    $internalSearch = '';
150    $linkState = Filter::filterInput(INPUT_POST, 'linkstate', FILTER_SANITIZE_STRING);
151    $searchCat = Filter::filterInput(INPUT_POST, 'searchcat', FILTER_VALIDATE_INT);
152    $searchTerm = Filter::filterInput(INPUT_POST, 'searchterm', FILTER_SANITIZE_STRIPPED);
153
154    if (!is_null($linkState)) {
155        $cond[Database::getTablePrefix().'faqdata.links_state'] = 'linkbad';
156        $linkState = ' checked ';
157        $internalSearch .= '&linkstate=linkbad';
158    }
159    if (!is_null($searchCat)) {
160        $internalSearch .= '&searchcat='.$searchCat;
161        $cond[Database::getTablePrefix().'faqcategoryrelations.category_id'] = array_merge(
162            [$searchCat],
163            $category->getChildNodes($searchCat)
164        );
165    }
166
167    $selectedCategory = Filter::filterInput(INPUT_GET, 'category', FILTER_VALIDATE_INT, 0);
168    $orderBy = Filter::filterInput(INPUT_GET, 'orderby', FILTER_SANITIZE_STRING, 1);
169    $sortBy = Filter::filterInput(INPUT_GET, 'sortby', FILTER_SANITIZE_STRING);
170    if (1 !== $orderBy) {
171        switch ($orderBy) {
172            case 'id':
173                $orderBy = 1;
174                break;
175            case 'title':
176                $orderBy = 2;
177                break;
178            case 'date':
179                $orderBy = 3;
180                break;
181        }
182    }
183    ?>
184    <form id="recordSelection" name="recordSelection" method="post" accept-charset="utf-8">
185        <div class="accordion" id="accordion" role="tablist" aria-multiselectable="true">
186<?php
187    $comment = new Comments($faqConfig);
188    $numCommentsByFaq = $comment->getNumberOfComments();
189    $numCommentsByCat = [];
190    $numRecordsByCat = $categoryRelation->getNumberOfFaqsPerCategory(
191        $faqConfig->get('main.enableCategoryRestrictions')
192    );
193    $numActiveByCat = [];
194
195    $matrix = $categoryRelation->getCategoryFaqsMatrix();
196    foreach ($matrix as $categoryKey => $value) {
197        $numCommentsByCat[$categoryKey] = 0;
198        foreach ($value as $faqKey => $value) {
199            if (isset($numCommentsByFaq[$faqKey])) {
200                $numCommentsByCat[$categoryKey] += $numCommentsByFaq[$faqKey];
201            }
202        }
203    }
204
205    if (is_null($searchTerm)) {
206        if ($faqConfig->get('main.enableCategoryRestrictions')) {
207            $Language = new Language($faqConfig);
208            $language = $Language->setLanguage($faqConfig->get('main.languageDetection'), $faqConfig->get('main.language'));
209            $faq->getAllRecords($orderBy, ['lang' => $language], $sortBy);
210        } else {
211            $faq->getAllRecords($orderBy, null, $sortBy);
212        }
213
214        foreach ($faq->faqRecords as $record) {
215            if (!isset($numActiveByCat[$record['category_id']])) {
216                $numActiveByCat[$record['category_id']] = 0;
217            }
218            $numActiveByCat[$record['category_id']] += $record['active'] == 'yes' ? 1 : 0;
219        }
220    } else {
221        $fdTable = Database::getTablePrefix().'faqdata';
222        $fcrTable = Database::getTablePrefix().'faqcategoryrelations';
223        $search = SearchFactory::create($faqConfig, ['database' => Database::getType()]);
224
225        $search->setTable($fdTable)
226            ->setResultColumns(
227                [
228                    $fdTable.'.id AS id',
229                    $fdTable.'.lang AS lang',
230                    $fdTable.'.solution_id AS solution_id',
231                    $fcrTable.'.category_id AS category_id',
232                    $fdTable.'.sticky AS sticky',
233                    $fdTable.'.active AS active',
234                    $fdTable.'.thema AS thema',
235                    $fdTable.'.content AS content',
236                    $fdTable.'.updated AS updated',
237                ]
238            )
239            ->setJoinedTable($fcrTable)
240            ->setJoinedColumns(
241                [
242                    $fdTable.'.id = '.$fcrTable.'.record_id',
243                    $fdTable.'.lang = '.$fcrTable.'.record_lang',
244                ]
245            );
246
247        if (is_numeric($searchTerm)) {
248            $search->setMatchingColumns([$fdTable.'.solution_id']);
249        } else {
250            $search->setMatchingColumns([$fdTable.'.thema', $fdTable.'.content', $fdTable.'.keywords']);
251        }
252
253        $result = $search->search($searchTerm);
254        $laction = 'view';
255        $internalSearch = '&search='.$searchTerm;
256        $wasSearch = true;
257        $idsFound = [];
258        $faqsFound = [];
259
260        while ($row = $faqConfig->getDb()->fetchObject($result)) {
261            if ($searchCat != 0 && $searchCat != (int)$row->category_id) {
262                continue;
263            }
264
265            if (in_array($row->id, $idsFound)) {
266                continue; // only show one entry if FAQ is in multiple categories
267            }
268
269            $faqsFound[$row->category_id][$row->id] = [
270                'id' => $row->id,
271                'category_id' => $row->category_id,
272                'solution_id' => $row->solution_id,
273                'lang' => $row->lang,
274                'active' => $row->active,
275                'sticky' => $row->sticky,
276                'title' => $row->thema,
277                'content' => $row->content,
278                'updated' => Date::createIsoDate($row->updated),
279            ];
280
281            if (!isset($numActiveByCat[$row->category_id])) {
282                $numActiveByCat[$row->category_id] = 0;
283            }
284
285            $numActiveByCat[$row->category_id] += $row->active ? 1 : 0;
286
287            $idsFound[] = $row->id;
288        }
289
290        // Sort search result ordered by category ID
291        ksort($faqsFound);
292        foreach ($faqsFound as $categoryId => $faqFound) {
293            foreach ($faqFound as $singleFaq) {
294                $faq->faqRecords[] = $singleFaq;
295            }
296        }
297    }
298
299    if (count($faq->faqRecords) > 0) {
300        $old = 0;
301        $faqIds = [];
302
303        $visits = new Visits($faqConfig);
304        $numVisits = [];
305        foreach ($visits->getAllData() as $visit) {
306            $numVisits[$visit['id']] = $visit['lang'];
307        }
308
309        foreach ($faq->faqRecords as $record) {
310
311            $catInfo = '';
312            $cid = $record['category_id'];
313
314            if (isset($numRecordsByCat[$cid])) {
315                $catInfo .= sprintf(
316                    '<span class="badge badge-info" id="category_%d_item_count">%d %s</span> ',
317                    $cid,
318                    $numRecordsByCat[$cid],
319                    $PMF_LANG['msgEntries']
320                );
321            }
322
323            if (isset($numRecordsByCat[$cid]) && $numRecordsByCat[$cid] > $numActiveByCat[$cid]) {
324                $catInfo .= sprintf(
325                    '<span class="badge badge-danger"><span id="js-active-records-%d">%d</span> %s</span> ',
326                    $cid,
327                    $numRecordsByCat[$cid] - $numActiveByCat[$cid],
328                    $PMF_LANG['ad_record_inactive']
329                );
330            }
331
332            if (isset($numCommentsByCat[$cid]) && ($numCommentsByCat[$cid] > 0)) {
333                $catInfo .= sprintf('<span class="badge badge-info">%d %s</span>',
334                    $numCommentsByCat[$cid],
335                    $PMF_LANG['ad_start_comments']
336                );
337            }
338            $catInfo .= '';
339
340            if ($cid != $old) {
341                if ($old == 0) {
342                    printf('<a name="cat_%d"></a>', $cid);
343                } else {
344                    echo '</tbody></table></div></div></div>';
345                }
346                ?>
347          <div class="card card-default">
348            <div class="card-header" role="tab" id="category-heading-<?= $cid ?>">
349              <span class="float-right"><?= $catInfo ?></span>
350              <h5>
351                <a role="button" data-toggle="collapse" data-parent="#accordion" href="#category-<?= $cid ?>"
352                   aria-expanded="true" aria-controls="collapseOne">
353                  <i class="icon fa fa-chevron-circle-right "></i>
354                    <?= $category->getPath($cid) ?>
355                </a>
356              </h5>
357            </div>
358            <div id="category-<?= $cid ?>" class="card-collapse collapse" role="tabcard"
359                 aria-labelledby="category-heading-<?= $cid ?>">
360              <div class="card-body">
361                <table class="table table-hover table-sm">
362                  <thead class="thead-light">
363                  <tr>
364                    <th colspan="2" style="width: 24px;">
365                      <a href="?action=view&category=<?= $cid ?>&orderby=id&sortby=desc">
366                        &uarr;
367                      </a>
368                      <a href="?action=view&category=<?= $cid ?>&orderby=id&sortby=asc">
369                        &darr;
370                      </a>
371                    </th>
372                    <th>
373                      #
374                    </th>
375                    <th>
376                      <a href="?action=view&category=<?= $cid ?>&orderby=title&sortby=desc">
377                        &uarr;
378                      </a>
379                      <a href="?action=view&category=<?= $cid ?>&orderby=title&sortby=asc">
380                        &darr;
381                      </a>
382                    </th>
383                    <th style="width: 100px;">
384                      <a href="?action=view&category=<?= $cid ?>&orderby=date&sortby=desc">
385                        &uarr;
386                      </a>
387                      <a href="?action=view&category=<?= $cid ?>&orderby=date&sortby=asc">
388                        &darr;
389                      </a>
390                    </th>
391                    <th colspan="2">
392                      &nbsp;
393                    </th>
394
395                    <th style="width: 120px;">
396                      <label>
397                        <input type="checkbox" id="sticky_category_block_<?= $cid ?>"
398                               onclick="saveStatusForCategory(<?= $cid ?>, 'sticky', '<?= $user->getCsrfTokenFromSession() ?>')"/>
399                          <?= $PMF_LANG['ad_record_sticky'] ?>
400                      </label>
401                    </th>
402                    <th style="width: 120px;">
403                        <?php if ($user->perm->checkRight($user->getUserId(), 'approverec')) { ?>
404                          <label>
405                            <input type="checkbox" id="active_category_block_<?= $cid ?>"
406                                   onclick="saveStatusForCategory(<?= $cid ?>, 'active', '<?= $user->getCsrfTokenFromSession() ?>')"
407                                <?= $numRecordsByCat[$cid] == $numActiveByCat[$cid] ? 'checked' : '' ?>>
408                              <?= $PMF_LANG['ad_record_active'] ?>
409                          </label>
410                        <?php } else { ?>
411                          <span class="fa-stack">
412                              <i class="fa fa-check fa-stack-1x"></i>
413                              <i class="fa fa-ban fa-stack-2x text-danger"></i>
414                            </span>
415                        <?php } ?>
416                    </th>
417                    <th colspan="2">
418                      &nbsp;
419                    </th>
420                  </tr>
421                  </thead>
422                  <tbody>
423<?php
424            }
425            ?>
426                    <tr id="record_<?= $record['id'].'_'.$record['lang'] ?>">
427                      <td style="width: 24px; text-align: right;">
428                        <a href="?action=editentry&id=<?= $record['id'] ?>&lang=<?= $record['lang'] ?>">
429                            <?= $record['id'] ?>
430                        </a>
431                      </td>
432                      <td style="width: 16px;">
433                          <?= $record['lang'] ?>
434                      </td>
435                      <td style="width: 24px;">
436                        <a href="?action=editentry&id=<?= $record['id'] ?>&lang=<?= $record['lang'] ?>"
437                           title="<?= $PMF_LANG['ad_user_edit'] ?> '<?= str_replace('"', '´', $record['title']) ?>'">
438                            <?= $record['solution_id'] ?>
439                        </a>
440                      </td>
441                      <td>
442                        <a href="?action=editentry&id=<?= $record['id'] ?>&lang=<?= $record['lang'] ?>"
443                           title="<?= $PMF_LANG['ad_user_edit'] ?> '<?= str_replace('"', '´', $record['title']) ?>'">
444                            <?= $record['title'] ?>
445                        </a>
446<?php
447        if (isset($numCommentsByFaq[$record['id']])) {
448            printf(
449                '<br><a class="badge badge-primary" href="?action=comments#record_id_%d">%d %s</a>',
450                $record['id'],
451                $numCommentsByFaq[$record['id']],
452                $PMF_LANG['ad_start_comments']
453                );
454        }
455            ?></td>
456                      <td>
457                          <?= $date->format($record['updated']) ?>
458                      </td>
459                      <td style="width: 96px;">
460                          <?= $linkVerifier->getEntryStateHTML($record['id'], $record['lang']) ?>
461                      </td>
462                      <td>
463                        <div class="dropdown">
464                          <a class="btn btn-primary dropdown-toggle" href="#" role="button"
465                             id="dropdownAddNewTranslation" data-toggle="dropdown" aria-haspopup="true"
466                             aria-expanded="false">
467                            <i aria-hidden="true" class="fa fa-globe"
468                               title="<?= $PMF_LANG['msgTransToolAddNewTranslation'] ?>"></i>
469                          </a>
470                          <div class="dropdown-menu" aria-labelledby="dropdownAddNewTranslation">
471                              <?= $faqHelper->createFaqTranslationLinkList($record['id'], $record['lang']) ?>
472                          </div>
473                        </div>
474                      </td>
475                      <td style="width: 56px;">
476                        <label>
477                          <input type="checkbox" lang="<?= $record['lang'] ?>"
478                                 onclick="saveStatus(<?= $cid.', ['.$record['id'].']' ?>, 'sticky', '<?= $user->getCsrfTokenFromSession() ?>');"
479                                 id="sticky_record_<?= $cid.'_'.$record['id'] ?>"
480                              <?= $record['sticky'] ? 'checked' : '    ' ?>>
481                        </label>
482                      </td>
483                      <td>
484                          <?php if ($user->perm->checkRight($user->getUserId(), 'approverec')) { ?>
485                            <label>
486                              <input type="checkbox" lang="<?= $record['lang'] ?>" class="active-records-category-<?= $cid ?>"
487                                     onclick="saveStatus(<?= $cid.', ['.$record['id'].']' ?>, 'active', '<?= $user->getCsrfTokenFromSession() ?>');"
488                                     id="active_record_<?= $cid.'_'.$record['id'] ?>"
489                                  <?= 'yes' == $record['active'] ? 'checked' : '    ' ?>>
490                            </label>
491                          <?php } else { ?>
492                            <span class="fa-stack">
493                              <i class="fa fa-check fa-stack-1x"></i>
494                              <i class="fa fa-ban fa-stack-2x text-danger"></i>
495                            </span>
496                          <?php } ?>
497                      </td>
498                      <td style="width: 16px;">
499                        <a class="btn btn-info"
500                           href="?action=copyentry&id=<?= $record['id'] ?>&lang=<?= $record['lang']; ?>"
501                           title="<?= $PMF_LANG['ad_categ_copy'] ?>">
502                          <i aria-hidden="true" class="fa fa-copy"></i>
503                        </a>
504                      </td>
505                      <td style="width: 16px;">
506                        <a class="btn btn-danger" href="javascript:void(0);"
507                           onclick="deleteRecord(<?= $record['id'] ?>, '<?= $record['lang'] ?>', '<?= $user->getCsrfTokenFromSession() ?>');"
508                           title="<?= $PMF_LANG['ad_user_delete'] ?>">
509                          <i aria-hidden="true" class="fa fa-trash"></i>
510                        </a>
511                      </td>
512                    </tr>
513<?php
514            $old = $cid;
515
516            $faqIds[$cid][] = $record['id'];
517            ?>
518<?php
519        }
520        ?>
521                  </tbody>
522                </table>
523              </div>
524            </div>
525          </div>
526        </div>
527    </form>
528
529    <script src="assets/js/record.js"></script>
530    <script>
531    /**
532     * Saves the sticky record status for the whole category
533     *
534     * @param id
535     * @param type
536     * @param csrf
537     *
538     * @return void
539     */
540    function saveStatusForCategory(id, type, csrf) {
541      let id_map = [];
542        <?php
543        foreach ($faqIds as $categoryId => $recordIds) {
544            if ('' === $categoryId) {
545                $categoryId = 0;
546            }
547            echo '                id_map['.$categoryId.'] = ['.implode(',', $recordIds)."];\n";
548        }
549        ?>
550      for (let i = 0; i < id_map[id].length; i++) {
551        const status = $('#' + type + '_category_block_' + id).prop('checked');
552        $('#' + type + '_record_' + id + '_' + id_map[id][i]).prop('checked', status);
553      }
554
555      saveStatus(id, id_map[id], type, csrf);
556    }
557
558    /**
559     * Ajax call for saving the sticky record status
560     *
561     * @param cid  category id
562     * @param ids  ids
563     * @param type status type
564     * @param csrf CSRF Token
565     *
566     * @return void
567     */
568    function saveStatus(cid, ids, type, csrf) {
569      const indicator = $('#pmf-admin-saving-data-indicator'),
570        data = {
571          action: 'ajax',
572          ajax: 'records',
573          ajaxaction: 'save_' + type + '_records',
574          csrf: csrf
575        };
576
577      indicator.html('<i class="fa fa-cog fa-spin"></i> Saving ...');
578
579      for (let i = 0; i < ids.length; i++) {
580        const statusId = '#' + type + '_record_' + cid + '_' + ids[i];
581        const status = $(statusId).attr('checked') ? '' : 'checked';
582        const langId = '#' + type + '_record_' + cid + '_' + ids[i];
583        const lang = $(langId).attr('lang');
584
585        data['items[' + i + '][]'] = [ids[i], lang, status];
586
587        // Updating the current record if it's also contained in another category
588        const sameRecords = $('input').filter(function () {
589          return this.id.match(new RegExp(type + '_record_(\\d+)_' + ids[i]));
590        });
591
592        if ('active' === type) {
593          for (let j = 0; j < sameRecords.length; j++) {
594            $('#' + sameRecords[j].id).attr('checked', status);
595            const catid = sameRecords[j].id.match(/active_record_(\d+)_\d+/)[1];
596            $('#js-active-records-' + catid).html($('.active-records-category-' + cid + ':not(:checked)').length);
597          }
598        } else {
599          for (let j = 0; j < sameRecords.length; j++) {
600            $('#' + sameRecords[j].id).attr('checked', status);
601            const catid = sameRecords[j].id.match(/active_record_(\d+)_\d+/)[1];
602            $('#js-active-records-' + catid).html($('.active-records-category-' + cid + ':not(:checked)').length);
603          }
604        }
605      }
606
607      $.get('index.php', data, null);
608      indicator.html('<?= $PMF_LANG['ad_entry_savedsuc'] ?>');
609    }
610
611    /**
612     * Ajax call for deleting records
613     *
614     * @param record_id   Record id
615     * @param record_lang Record language
616     * @param csrf_token  CSRF Token
617     *
618     * @return void
619     */
620    function deleteRecord(record_id, record_lang, csrf_token)
621    {
622        if (confirm('<?= addslashes($PMF_LANG['ad_entry_del_1'].' '.$PMF_LANG['ad_entry_del_3']);
623        ?>')) {
624            $('#pmf-admin-saving-data-indicator').html('<i class="fa fa-cog fa-spin fa-fw"></i><span class="sr-only">Deleting ...</span>');
625            $.ajax({
626                type:    "POST",
627                url:     "index.php?action=ajax&ajax=records&ajaxaction=delete_record",
628                data:    "record_id=" + record_id + "&record_lang=" + record_lang + "&csrf=" + csrf_token,
629                success: function() {
630                    $("#record_" + record_id + "_" + record_lang).fadeOut("slow");
631                    $('#pmf-admin-saving-data-indicator').html('<?= $PMF_LANG['ad_entry_delsuc'];
632        ?>');
633                }
634            });
635        }
636    }
637    </script>
638<?php
639
640    } else {
641        echo $PMF_LANG['err_nothingFound'];
642    }
643} else {
644    echo $PMF_LANG['err_NotAuth'];
645}
646?>
647    </div>
648</div>
649