@@ -31,113 +31,113 @@ |
||
| 31 | 31 | // Request set_id |
| 32 | 32 | $setId = Request::getInt('set_id'); |
| 33 | 33 | switch ($op) { |
| 34 | - case 'list': |
|
| 35 | - default: |
|
| 36 | - // Define Stylesheet |
|
| 37 | - $GLOBALS['xoTheme']->addStylesheet($style, null); |
|
| 38 | - $start = Request::getInt('start', 0); |
|
| 39 | - $limit = Request::getInt('limit', $helper->getConfig('adminpager')); |
|
| 40 | - $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 41 | - $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 42 | - $adminObject->addItemButton(_AM_WGGITHUB_ADD_SETTING, 'settings.php?op=new', 'add'); |
|
| 43 | - $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 44 | - $settingsCount = $settingsHandler->getCountSettings(); |
|
| 45 | - $settingsAll = $settingsHandler->getAllSettings($start, $limit); |
|
| 46 | - $GLOBALS['xoopsTpl']->assign('settings_count', $settingsCount); |
|
| 47 | - $GLOBALS['xoopsTpl']->assign('wggithub_url', WGGITHUB_URL); |
|
| 48 | - $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', WGGITHUB_UPLOAD_URL); |
|
| 49 | - // Table view settings |
|
| 50 | - if ($settingsCount > 0) { |
|
| 51 | - foreach (\array_keys($settingsAll) as $i) { |
|
| 52 | - $setting = $settingsAll[$i]->getValuesSettings(); |
|
| 53 | - $GLOBALS['xoopsTpl']->append('settings_list', $setting); |
|
| 54 | - unset($setting); |
|
| 55 | - } |
|
| 56 | - // Display Navigation |
|
| 57 | - if ($settingsCount > $limit) { |
|
| 58 | - include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 59 | - $pagenav = new \XoopsPageNav($settingsCount, $limit, $start, 'start', 'op=list&limit=' . $limit); |
|
| 60 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
|
| 61 | - } |
|
| 62 | - } else { |
|
| 63 | - $GLOBALS['xoopsTpl']->assign('error', _AM_WGGITHUB_THEREARENT_SETTINGS); |
|
| 64 | - } |
|
| 65 | - break; |
|
| 66 | - case 'new': |
|
| 67 | - $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 68 | - $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 69 | - $adminObject->addItemButton(_AM_WGGITHUB_SETTINGS_LIST, 'settings.php', 'list'); |
|
| 70 | - $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 71 | - // Form Create |
|
| 72 | - $settingsObj = $settingsHandler->create(); |
|
| 73 | - $form = $settingsObj->getFormSettings(); |
|
| 74 | - $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 75 | - break; |
|
| 76 | - case 'save': |
|
| 77 | - // Security Check |
|
| 78 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 79 | - \redirect_header('settings.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 80 | - } |
|
| 81 | - if ($setId > 0) { |
|
| 82 | - $settingsObj = $settingsHandler->get($setId); |
|
| 83 | - } else { |
|
| 84 | - $settingsObj = $settingsHandler->create(); |
|
| 85 | - } |
|
| 86 | - // Set Vars |
|
| 87 | - $settingsObj->setVar('set_username', Request::getString('set_username', '')); |
|
| 88 | - $settingsObj->setVar('set_token', Request::getString('set_token', '')); |
|
| 89 | - $settingsObj->setVar('set_options', Request::getString('set_options', '')); |
|
| 90 | - $settingsObj->setVar('set_primary', Request::getInt('set_primary', 0)); |
|
| 91 | - $settingDateObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('set_date')); |
|
| 92 | - $settingsObj->setVar('set_date', $settingDateObj->getTimestamp()); |
|
| 93 | - $settingsObj->setVar('set_submitter', Request::getInt('set_submitter', 0)); |
|
| 94 | - // Insert Data |
|
| 95 | - if ($settingsHandler->insert($settingsObj)) { |
|
| 34 | + case 'list': |
|
| 35 | + default: |
|
| 36 | + // Define Stylesheet |
|
| 37 | + $GLOBALS['xoTheme']->addStylesheet($style, null); |
|
| 38 | + $start = Request::getInt('start', 0); |
|
| 39 | + $limit = Request::getInt('limit', $helper->getConfig('adminpager')); |
|
| 40 | + $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 41 | + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 42 | + $adminObject->addItemButton(_AM_WGGITHUB_ADD_SETTING, 'settings.php?op=new', 'add'); |
|
| 43 | + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 44 | + $settingsCount = $settingsHandler->getCountSettings(); |
|
| 45 | + $settingsAll = $settingsHandler->getAllSettings($start, $limit); |
|
| 46 | + $GLOBALS['xoopsTpl']->assign('settings_count', $settingsCount); |
|
| 47 | + $GLOBALS['xoopsTpl']->assign('wggithub_url', WGGITHUB_URL); |
|
| 48 | + $GLOBALS['xoopsTpl']->assign('wggithub_upload_url', WGGITHUB_UPLOAD_URL); |
|
| 49 | + // Table view settings |
|
| 50 | + if ($settingsCount > 0) { |
|
| 51 | + foreach (\array_keys($settingsAll) as $i) { |
|
| 52 | + $setting = $settingsAll[$i]->getValuesSettings(); |
|
| 53 | + $GLOBALS['xoopsTpl']->append('settings_list', $setting); |
|
| 54 | + unset($setting); |
|
| 55 | + } |
|
| 56 | + // Display Navigation |
|
| 57 | + if ($settingsCount > $limit) { |
|
| 58 | + include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 59 | + $pagenav = new \XoopsPageNav($settingsCount, $limit, $start, 'start', 'op=list&limit=' . $limit); |
|
| 60 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
|
| 61 | + } |
|
| 62 | + } else { |
|
| 63 | + $GLOBALS['xoopsTpl']->assign('error', _AM_WGGITHUB_THEREARENT_SETTINGS); |
|
| 64 | + } |
|
| 65 | + break; |
|
| 66 | + case 'new': |
|
| 67 | + $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 68 | + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 69 | + $adminObject->addItemButton(_AM_WGGITHUB_SETTINGS_LIST, 'settings.php', 'list'); |
|
| 70 | + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 71 | + // Form Create |
|
| 72 | + $settingsObj = $settingsHandler->create(); |
|
| 73 | + $form = $settingsObj->getFormSettings(); |
|
| 74 | + $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 75 | + break; |
|
| 76 | + case 'save': |
|
| 77 | + // Security Check |
|
| 78 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 79 | + \redirect_header('settings.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 80 | + } |
|
| 81 | + if ($setId > 0) { |
|
| 82 | + $settingsObj = $settingsHandler->get($setId); |
|
| 83 | + } else { |
|
| 84 | + $settingsObj = $settingsHandler->create(); |
|
| 85 | + } |
|
| 86 | + // Set Vars |
|
| 87 | + $settingsObj->setVar('set_username', Request::getString('set_username', '')); |
|
| 88 | + $settingsObj->setVar('set_token', Request::getString('set_token', '')); |
|
| 89 | + $settingsObj->setVar('set_options', Request::getString('set_options', '')); |
|
| 90 | + $settingsObj->setVar('set_primary', Request::getInt('set_primary', 0)); |
|
| 91 | + $settingDateObj = \DateTime::createFromFormat(_SHORTDATESTRING, Request::getString('set_date')); |
|
| 92 | + $settingsObj->setVar('set_date', $settingDateObj->getTimestamp()); |
|
| 93 | + $settingsObj->setVar('set_submitter', Request::getInt('set_submitter', 0)); |
|
| 94 | + // Insert Data |
|
| 95 | + if ($settingsHandler->insert($settingsObj)) { |
|
| 96 | 96 | if (Request::getInt('set_primary', 0) > 0) { |
| 97 | 97 | $newSetId = $settingsObj->getNewInsertedIdSettings(); |
| 98 | 98 | $setId = $setId > 0 ? $setId : $newSetId; |
| 99 | 99 | $settingsHandler->setPrimarySetting($setId); |
| 100 | 100 | } |
| 101 | - \redirect_header('settings.php?op=list', 2, _AM_WGGITHUB_FORM_OK); |
|
| 102 | - } |
|
| 103 | - // Get Form |
|
| 104 | - $GLOBALS['xoopsTpl']->assign('error', $settingsObj->getHtmlErrors()); |
|
| 105 | - $form = $settingsObj->getFormSettings(); |
|
| 106 | - $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 107 | - break; |
|
| 108 | - case 'edit': |
|
| 109 | - $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 110 | - $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 111 | - $adminObject->addItemButton(_AM_WGGITHUB_ADD_SETTING, 'settings.php?op=new', 'add'); |
|
| 112 | - $adminObject->addItemButton(_AM_WGGITHUB_SETTINGS_LIST, 'settings.php', 'list'); |
|
| 113 | - $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 114 | - // Get Form |
|
| 115 | - $settingsObj = $settingsHandler->get($setId); |
|
| 116 | - $form = $settingsObj->getFormSettings(); |
|
| 117 | - $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 118 | - break; |
|
| 119 | - case 'delete': |
|
| 120 | - $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 121 | - $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 122 | - $settingsObj = $settingsHandler->get($setId); |
|
| 123 | - $setToken = $settingsObj->getVar('set_token'); |
|
| 124 | - if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) { |
|
| 125 | - if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 126 | - \redirect_header('settings.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 127 | - } |
|
| 128 | - if ($settingsHandler->delete($settingsObj)) { |
|
| 129 | - \redirect_header('settings.php', 3, _AM_WGGITHUB_FORM_DELETE_OK); |
|
| 130 | - } else { |
|
| 131 | - $GLOBALS['xoopsTpl']->assign('error', $settingsObj->getHtmlErrors()); |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - $xoopsconfirm = new Common\XoopsConfirm( |
|
| 135 | - ['ok' => 1, 'set_id' => $setId, 'op' => 'delete'], |
|
| 136 | - $_SERVER['REQUEST_URI'], |
|
| 137 | - \sprintf(_AM_WGGITHUB_FORM_SURE_DELETE, $settingsObj->getVar('set_token'))); |
|
| 138 | - $form = $xoopsconfirm->getFormXoopsConfirm(); |
|
| 139 | - $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 140 | - } |
|
| 141 | - break; |
|
| 101 | + \redirect_header('settings.php?op=list', 2, _AM_WGGITHUB_FORM_OK); |
|
| 102 | + } |
|
| 103 | + // Get Form |
|
| 104 | + $GLOBALS['xoopsTpl']->assign('error', $settingsObj->getHtmlErrors()); |
|
| 105 | + $form = $settingsObj->getFormSettings(); |
|
| 106 | + $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 107 | + break; |
|
| 108 | + case 'edit': |
|
| 109 | + $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 110 | + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 111 | + $adminObject->addItemButton(_AM_WGGITHUB_ADD_SETTING, 'settings.php?op=new', 'add'); |
|
| 112 | + $adminObject->addItemButton(_AM_WGGITHUB_SETTINGS_LIST, 'settings.php', 'list'); |
|
| 113 | + $GLOBALS['xoopsTpl']->assign('buttons', $adminObject->displayButton('left')); |
|
| 114 | + // Get Form |
|
| 115 | + $settingsObj = $settingsHandler->get($setId); |
|
| 116 | + $form = $settingsObj->getFormSettings(); |
|
| 117 | + $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 118 | + break; |
|
| 119 | + case 'delete': |
|
| 120 | + $templateMain = 'wggithub_admin_settings.tpl'; |
|
| 121 | + $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('settings.php')); |
|
| 122 | + $settingsObj = $settingsHandler->get($setId); |
|
| 123 | + $setToken = $settingsObj->getVar('set_token'); |
|
| 124 | + if (isset($_REQUEST['ok']) && 1 == $_REQUEST['ok']) { |
|
| 125 | + if (!$GLOBALS['xoopsSecurity']->check()) { |
|
| 126 | + \redirect_header('settings.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
|
| 127 | + } |
|
| 128 | + if ($settingsHandler->delete($settingsObj)) { |
|
| 129 | + \redirect_header('settings.php', 3, _AM_WGGITHUB_FORM_DELETE_OK); |
|
| 130 | + } else { |
|
| 131 | + $GLOBALS['xoopsTpl']->assign('error', $settingsObj->getHtmlErrors()); |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + $xoopsconfirm = new Common\XoopsConfirm( |
|
| 135 | + ['ok' => 1, 'set_id' => $setId, 'op' => 'delete'], |
|
| 136 | + $_SERVER['REQUEST_URI'], |
|
| 137 | + \sprintf(_AM_WGGITHUB_FORM_SURE_DELETE, $settingsObj->getVar('set_token'))); |
|
| 138 | + $form = $xoopsconfirm->getFormXoopsConfirm(); |
|
| 139 | + $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
|
| 140 | + } |
|
| 141 | + break; |
|
| 142 | 142 | } |
| 143 | 143 | require __DIR__ . '/footer.php'; |
@@ -31,96 +31,96 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SettingsHandler extends \XoopsPersistableObjectHandler |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * Constructor |
|
| 36 | - * |
|
| 37 | - * @param \XoopsDatabase $db |
|
| 38 | - */ |
|
| 39 | - public function __construct(\XoopsDatabase $db) |
|
| 40 | - { |
|
| 41 | - parent::__construct($db, 'wggithub_settings', Settings::class, 'set_id', 'set_token'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param bool $isNew |
|
| 46 | - * |
|
| 47 | - * @return object |
|
| 48 | - */ |
|
| 49 | - public function create($isNew = true) |
|
| 50 | - { |
|
| 51 | - return parent::create($isNew); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * retrieve a field |
|
| 56 | - * |
|
| 57 | - * @param int $i field id |
|
| 58 | - * @param null fields |
|
| 59 | - * @return mixed reference to the {@link Get} object |
|
| 60 | - */ |
|
| 61 | - public function get($i = null, $fields = null) |
|
| 62 | - { |
|
| 63 | - return parent::get($i, $fields); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * get inserted id |
|
| 68 | - * |
|
| 69 | - * @param null |
|
| 70 | - * @return int reference to the {@link Get} object |
|
| 71 | - */ |
|
| 72 | - public function getInsertId() |
|
| 73 | - { |
|
| 74 | - return $this->db->getInsertId(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Get Count Settings in the database |
|
| 79 | - * @param int $start |
|
| 80 | - * @param int $limit |
|
| 81 | - * @param string $sort |
|
| 82 | - * @param string $order |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function getCountSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_token', $order = 'ASC') |
|
| 86 | - { |
|
| 87 | - $crCountSettings = new \CriteriaCompo(); |
|
| 88 | - $crCountSettings = $this->getSettingsCriteria($crCountSettings, $start, $limit, $sort, $order); |
|
| 89 | - return $this->getCount($crCountSettings); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Get All Settings in the database |
|
| 94 | - * @param int $start |
|
| 95 | - * @param int $limit |
|
| 96 | - * @param string $sort |
|
| 97 | - * @param string $order |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getAllSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_token', $order = 'ASC') |
|
| 101 | - { |
|
| 102 | - $crAllSettings = new \CriteriaCompo(); |
|
| 103 | - $crAllSettings = $this->getSettingsCriteria($crAllSettings, $start, $limit, $sort, $order); |
|
| 104 | - return $this->getAll($crAllSettings); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get Criteria Settings |
|
| 109 | - * @param $crSettings |
|
| 110 | - * @param int $start |
|
| 111 | - * @param int $limit |
|
| 112 | - * @param string $sort |
|
| 113 | - * @param string $order |
|
| 114 | - * @return int |
|
| 115 | - */ |
|
| 116 | - private function getSettingsCriteria($crSettings, $start, $limit, $sort, $order) |
|
| 117 | - { |
|
| 118 | - $crSettings->setStart($start); |
|
| 119 | - $crSettings->setLimit($limit); |
|
| 120 | - $crSettings->setSort($sort); |
|
| 121 | - $crSettings->setOrder($order); |
|
| 122 | - return $crSettings; |
|
| 123 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor |
|
| 36 | + * |
|
| 37 | + * @param \XoopsDatabase $db |
|
| 38 | + */ |
|
| 39 | + public function __construct(\XoopsDatabase $db) |
|
| 40 | + { |
|
| 41 | + parent::__construct($db, 'wggithub_settings', Settings::class, 'set_id', 'set_token'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param bool $isNew |
|
| 46 | + * |
|
| 47 | + * @return object |
|
| 48 | + */ |
|
| 49 | + public function create($isNew = true) |
|
| 50 | + { |
|
| 51 | + return parent::create($isNew); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * retrieve a field |
|
| 56 | + * |
|
| 57 | + * @param int $i field id |
|
| 58 | + * @param null fields |
|
| 59 | + * @return mixed reference to the {@link Get} object |
|
| 60 | + */ |
|
| 61 | + public function get($i = null, $fields = null) |
|
| 62 | + { |
|
| 63 | + return parent::get($i, $fields); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * get inserted id |
|
| 68 | + * |
|
| 69 | + * @param null |
|
| 70 | + * @return int reference to the {@link Get} object |
|
| 71 | + */ |
|
| 72 | + public function getInsertId() |
|
| 73 | + { |
|
| 74 | + return $this->db->getInsertId(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Get Count Settings in the database |
|
| 79 | + * @param int $start |
|
| 80 | + * @param int $limit |
|
| 81 | + * @param string $sort |
|
| 82 | + * @param string $order |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function getCountSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_token', $order = 'ASC') |
|
| 86 | + { |
|
| 87 | + $crCountSettings = new \CriteriaCompo(); |
|
| 88 | + $crCountSettings = $this->getSettingsCriteria($crCountSettings, $start, $limit, $sort, $order); |
|
| 89 | + return $this->getCount($crCountSettings); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Get All Settings in the database |
|
| 94 | + * @param int $start |
|
| 95 | + * @param int $limit |
|
| 96 | + * @param string $sort |
|
| 97 | + * @param string $order |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getAllSettings($start = 0, $limit = 0, $sort = 'set_id ASC, set_token', $order = 'ASC') |
|
| 101 | + { |
|
| 102 | + $crAllSettings = new \CriteriaCompo(); |
|
| 103 | + $crAllSettings = $this->getSettingsCriteria($crAllSettings, $start, $limit, $sort, $order); |
|
| 104 | + return $this->getAll($crAllSettings); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get Criteria Settings |
|
| 109 | + * @param $crSettings |
|
| 110 | + * @param int $start |
|
| 111 | + * @param int $limit |
|
| 112 | + * @param string $sort |
|
| 113 | + * @param string $order |
|
| 114 | + * @return int |
|
| 115 | + */ |
|
| 116 | + private function getSettingsCriteria($crSettings, $start, $limit, $sort, $order) |
|
| 117 | + { |
|
| 118 | + $crSettings->setStart($start); |
|
| 119 | + $crSettings->setLimit($limit); |
|
| 120 | + $crSettings->setSort($sort); |
|
| 121 | + $crSettings->setOrder($order); |
|
| 122 | + return $crSettings; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * Get Primary Setting |