Advertisement
toorr2p

Untitled

Apr 18th, 2024
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.21 KB | None | 0 0
  1. <?php require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  2.  
  3. use Bitrix\Main;
  4. use Bitrix\Main\Loader;
  5. use Bitrix\Main\Localization\Loc;
  6. use Bitrix\Main\Config\Option;
  7. use Bitrix\Main\Application;
  8. use Itscript\Question\QuestionTable;
  9. use Bitrix\Main\UI\PageNavigation;
  10.  
  11. $module_id = "itscript.question";
  12.  
  13. IncludeModuleLangFile(__FILE__);
  14.  
  15. // Check access
  16. $FORM_RIGHT = $APPLICATION->GetGroupRight($module_id);
  17. if($FORM_RIGHT<="D") $APPLICATION->AuthForm(Loc::getMessage("ACCESS_DENIED"));
  18.  
  19. if(!Loader::includeModule($module_id)){
  20.     CAdminMessage::ShowMessage(Loc::getMessage("ITSCRIPT_QUESTION_INCLUDE_MODULE_ERROR", ['#MODULE_ID#' => $module_id]));
  21. }
  22.  
  23. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  24.  
  25. CUtil::InitJSCore(array($module_id));
  26.  
  27. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  28. require_once(dirname(__FILE__)."/../include.php");
  29. require_once(dirname(__FILE__)."/../prolog.php");
  30.  
  31. global $APPLICATION;
  32.  
  33. $adminListTableID = 'b_itscript_question';
  34.  
  35. $adminSort = new CAdminSorting($adminListTableID, 'ID', 'ASC');
  36. $adminList = new CAdminUiList($adminListTableID, $adminSort);
  37.  
  38. $filterFields = array(
  39.     array(
  40.         "id" => "ID",
  41.         "name" => 'ID',
  42.         "filterable" => "=",
  43.         "default" => true
  44.     ),
  45.     array(
  46.         "id" => "",
  47.         "name" => Loc::getMessage("ITSCRIPT_QUESTION_ENTITY_ID_ADMIN_FILTER"),
  48.         "type" => "int",
  49.         "filterable" => "="
  50.     ),
  51. );
  52.  
  53. $filter = array();
  54.  
  55. $adminList->AddFilter($filterFields, $filter);
  56.  
  57. if ($listID = $adminList->GroupAction()) {
  58.  
  59.     $action = $_REQUEST['action'];
  60.  
  61.     if (!empty($_REQUEST['action_button'])) {
  62.         $action = $_REQUEST['action_button'];
  63.     }
  64.  
  65.     $checkUseCoupons = ($action == 'delete');
  66.     $discountList = array();
  67.  
  68.     if ($_REQUEST['action_target'] == 'selected') {
  69.         $listID = array();
  70.         $formIterator = QuestionTable::getList(array(
  71.             'select' => array('ID'),
  72.             'filter' => $filter
  73.         ));
  74.         while ($form = $formIterator->fetch()) {
  75.             $listID[] = $form['ID'];
  76.         }
  77.         unset($form, $formIterator);
  78.     }
  79.  
  80.     if ($adminList->IsGroupActionToAll()) {
  81.         $arID = array();
  82.         $formIterator = QuestionTable::getList(array(
  83.             'select' => array('ID'),
  84.             'filter' => $filter
  85.         ));
  86.         while ($arRes = $formIterator->fetch()) {
  87.             $listID[] = $arRes['ID'];
  88.         }
  89.         unset($arRes, $rsData);
  90.     }
  91.  
  92.     $listID = array_filter($listID);
  93.  
  94.     if (!empty($listID)) {
  95.         switch ($action) {
  96.             case 'delete':
  97.                 foreach ($listID as &$recordId) {
  98.                     $result = QuestionTable::delete($recordId);
  99.                     if (!$result->isSuccess()) {
  100.                         $adminList->AddGroupError(implode('<br>', $result->getErrorMessages()), $recordId);
  101.                     }
  102.                     unset($result);
  103.                 }
  104.                 unset($recordId);
  105.                 break;
  106.         }
  107.     }
  108.     unset($discountList, $action, $listID);
  109.  
  110.     if ($adminList->hasGroupErrors()) {
  111.         $adminSidePanelHelper->sendJsonErrorResponse($adminList->getGroupErrors());
  112.     } else {
  113.         $adminSidePanelHelper->sendSuccessResponse();
  114.     }
  115. }
  116.  
  117. $headerList = array();
  118. $headerList['ID'] = array(
  119.     'id' => 'ID',
  120.     'content' => 'ID',
  121.     'sort' => 'ID',
  122.     'default' => true
  123. );
  124. $headerList['PUBLISH_DATE'] = array(
  125.     'id' => 'PUBLISH_DATE',
  126.     'content' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_PUBLISH_DATE'),
  127.     'title' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_PUBLISH_DATE'),
  128.     'sort' => 'CREATED',
  129.     'default' => true
  130. );
  131. $headerList['QUESTION'] = array(
  132.     'id' => 'QUESTION',
  133.     'content' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_QUESTION'),
  134.     'title' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_QUESTION'),
  135.     'sort' => 'QUESTION',
  136.     'default' => false
  137. );
  138. $headerList['ACTIVE'] = array(
  139.     'id' => 'ACTIVE',
  140.     'content' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_ACTIVE'),
  141.     'title' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_ACTIVE'),
  142.     'sort' => 'ACTIVE',
  143.     'default' => false
  144. );
  145. $headerList['URL'] = array(
  146.     'id' => 'URL',
  147.     'content' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_URL'),
  148.     'title' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_URL'),
  149.     'sort' => 'URL',
  150.     'default' => true
  151. );
  152. $headerList['ENTITY_ID'] = array(
  153.     'id' => 'ENTITY_ID',
  154.     'content' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_ENTITY_ID'),
  155.     'title' => Loc::getMessage('ITSCRIPT_QUESTION_TITLE_ENTITY_ID'),
  156.     'sort' => 'ENTITY_ID',
  157.     'default' => true
  158. );
  159.  
  160. $listHeader = array_keys($headerList);
  161.  
  162. $adminList->AddHeaders($headerList);
  163.  
  164. $selectFields = array_fill_keys($adminList->GetVisibleHeaderColumns(), true);
  165. $selectFields['ID'] = true;
  166. $selectFieldsMap = array_fill_keys(array_keys($headerList), false);
  167. $selectFieldsMap = array_merge($selectFieldsMap, $selectFields);
  168.  
  169. if (!isset($by)) {
  170.     $by = 'ID';
  171. }
  172. if (!isset($order)) {
  173.     $order = 'ASC';
  174. }
  175.  
  176. $rowList = array();
  177. $usePageNavigation = true;
  178. $navyParams = array();
  179.  
  180. $navyParams = \CDBResult::GetNavParams(CAdminUiResult::GetNavSize($adminListTableID));
  181. if ($navyParams['SHOW_ALL']) {
  182.     $usePageNavigation = false;
  183. } else {
  184.     $navyParams['PAGEN'] = (int)$navyParams['PAGEN'];
  185.     $navyParams['SIZEN'] = (int)$navyParams['SIZEN'];
  186. }
  187.  
  188. global $by, $order;
  189.  
  190. $getListParams = array(
  191.     'select' => $selectFields,
  192.     'filter' => $filter,
  193.     'order' => array($by => $order)
  194. );
  195.  
  196. if ($usePageNavigation) {
  197.     $getListParams['limit'] = $navyParams['SIZEN'];
  198.     $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1);
  199. }
  200. $totalPages = 0;
  201. if ($usePageNavigation) {
  202.     $totalCount = QuestionTable::getCount($getListParams['filter']);
  203.     if ($totalCount > 0) {
  204.         $totalPages = ceil($totalCount / $navyParams['SIZEN']);
  205.         if ($navyParams['PAGEN'] > $totalPages)
  206.             $navyParams['PAGEN'] = $totalPages;
  207.         $getListParams['limit'] = $navyParams['SIZEN'];
  208.         $getListParams['offset'] = $navyParams['SIZEN'] * ($navyParams['PAGEN'] - 1);
  209.     } else {
  210.         $navyParams['PAGEN'] = 1;
  211.         $getListParams['limit'] = $navyParams['SIZEN'];
  212.         $getListParams['offset'] = 0;
  213.     }
  214. }
  215.  
  216. $getListParams['select'] = array_keys($getListParams['select']);
  217.  
  218. echo '<pre>';
  219. print_r([
  220.     $totalCount,
  221.     $navyParams,
  222.     $selectFieldsMap,
  223.     $adminListTableID,
  224.     'getListParams' => $getListParams,
  225.     LANGUAGE_ID
  226. ]);
  227. //print_r([$getListParams, $adminListTableID]);
  228. echo '</pre>';
  229.  
  230.  
  231. $formIterator = new CAdminUiResult(QuestionTable::getList($getListParams), $adminListTableID);
  232. if ($usePageNavigation) {
  233.     $formIterator->NavStart($getListParams['limit'], $navyParams['SHOW_ALL'], $navyParams['PAGEN']);
  234.     $formIterator->NavRecordCount = $totalCount;
  235.     $formIterator->NavPageCount = $totalPages;
  236.     $formIterator->NavPageNomer = $navyParams['PAGEN'];
  237. } else {
  238.     $formIterator->NavStart();
  239. }
  240. $onlyDel = false;
  241. $yesNo = [
  242.     Loc::getMessage("ITSCRIPT_QUESTION_TITLE_NO"),
  243.     Loc::getMessage("ITSCRIPT_QUESTION_TITLE_YES"),
  244. ];
  245. CTimeZone::Disable();
  246. $adminList->SetNavigationParams($formIterator, array("BASE_LINK" => $selfFolderUrl . "itscript_question_list.php"));
  247. while($form = $formIterator->fetch()) {
  248.     $result[]=$form;
  249. }
  250. $prm['SELECT'] = $getListParams['select'];
  251. //TenderComp::reflection($result, $prm);
  252.  
  253. foreach($result as $form)
  254. {
  255.     $form['ID'] = (int)$form['ID'];
  256.     $urlEdit = $selfFolderUrl . 'itscript_question_edit.php?ID=' . $form['ID'] . '&lang=' . LANGUAGE_ID;
  257.     $urlEdit = $adminSidePanelHelper->editUrlToPublicPage($urlEdit);
  258.  
  259.     $rowList[$form['ID']] = $row = &$adminList->AddRow(
  260.         $form['ID'],
  261.         $form,
  262.         $urlEdit,
  263.         Loc::getMessage("ITSCRIPT_QUESTION_EDIT")
  264.     );
  265.  
  266.     if ($onlyDel) {
  267.         $row->AddViewField('ID', $form['ID']);
  268.     } else {
  269.         $row->AddViewField('ID', '<a href="' . $urlEdit . '">' . $form['ID'] . '</a>');
  270.     }
  271.  
  272.     if ($selectFieldsMap['URL']) {
  273.         $row->AddViewField('URL', '<a href="' . $form['URL'] . '">' . $form['URL'] . '</a>');
  274.     }
  275.  
  276.     if ($selectFieldsMap['QUESTION']) {
  277.         $row->AddViewField('QUESTION', $form['QUESTION']);
  278.     }
  279.    
  280.     if ($selectFieldsMap['PUBLISH_DATE']) {
  281.         $row->AddViewField('PUBLISH_DATE', $form['PUBLISH_DATE']->format('d.m.Y H:i:s'));
  282.     }
  283.  
  284.     if ($selectFieldsMap['ACTIVE']) {
  285.         $row->AddViewField('ACTIVE', $yesNo[$form['ACTIVE']]);
  286.     }
  287.  
  288.     $actions = array();
  289.     if (!$onlyDel) {
  290.         $actions[] = array(
  291.             'ICON' => 'edit',
  292.             'TEXT' => Loc::getMessage("ITSCRIPT_QUESTION_EDIT"),
  293.             'LINK' => $urlEdit,
  294.             'DEFAULT' => true
  295.         );
  296.     }
  297.     if (!$readOnly) {
  298.         $actions[] = array(
  299.             'ICON' => 'delete',
  300.             'TEXT' => Loc::getMessage("ITSCRIPT_QUESTION_DELETE"),
  301.             'ACTION' => "if (confirm('" . Loc::getMessage("ITSCRIPT_QUESTION_DELETE_ALERT") . "')) " . $adminList->ActionDoGroup($form['ID'], 'delete')
  302.         );
  303.     }
  304.     $row->AddActions($actions);
  305.     unset($actions, $row);
  306. }
  307. CTimeZone::Enable();
  308.  
  309. $adminList->AddGroupActionTable([
  310.     'delete' => true,
  311.     'for_all'=>true,
  312.  
  313. ]);
  314.  
  315. $contextMenu = array();
  316.  
  317. if (!$readOnly) {
  318.     $addUrl = $selfFolderUrl . "itscript_question_edit.php?lang=" . LANGUAGE_ID;
  319.     $addUrl = $adminSidePanelHelper->editUrlToPublicPage($addUrl);
  320.     $contextMenu[] = array(
  321.         'ICON' => 'btn_new',
  322.         'TEXT' => Loc::getMessage('ITSCRIPT_QUESTION_ADD'),
  323.         'TITLE' => Loc::getMessage('ITSCRIPT_QUESTION_ADD'),
  324.         'LINK' => $addUrl
  325.     );
  326. }
  327.  
  328. if (!empty($contextMenu)) {
  329.     $adminList->setContextSettings(array("pagePath" => $selfFolderUrl . "itscript_question_list.php"));
  330.     $adminList->AddAdminContextMenu($contextMenu);
  331. }
  332.  
  333.  
  334. $adminList->CheckListMode();
  335.  
  336. $APPLICATION->SetTitle(Loc::getMessage("ITSCRIPT_QUESTION_PAGE_TITLE"));
  337.  
  338. $adminList->DisplayFilter($filterFields);
  339. $adminList->DisplayList();
  340.  
  341. require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_admin.php');
  342.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement