0, 'panel_name' => '', 'panel_filename' => '', 'panel_content' => '', 'panel_type' => 'php', 'panel_side' => TRUE, 'panel_order' => 0, 'panel_access' => 0, 'panel_display' => 0, 'panel_status' => 0, 'panel_url_list' => '', 'panel_restriction' => 3, 'panel_languages' => '' ]; /** * @var string */ private $formaction = ''; /** * @var array */ private $panel_data = []; /** * Sanitization Globals Vars */ public function __construct() { $aidlink = fusion_get_aidlink(); $this->set_locale(); $this->data['panel_languages'] = LANGUAGE; $this->data['panel_content'] = stripslashes($this->data['panel_content']); $_GET['panel_side'] = isset($_GET['panel_side']) && in_array($_GET['panel_side'], array_flip(self::get_panel_grid())) ? $_GET['panel_side'] : 0; $_GET['action'] = isset($_GET['action']) ? $_GET['action'] : ''; $_GET['status'] = isset($_GET['status']) ? $_GET['status'] : ''; $_GET['panel_status'] = isset($_GET['panel_status']) ? $_GET['panel_status'] : 0; $this->panel_data = self::load_all_panels(); switch ($_GET['action']) { case 'edit': if (isset($_GET['panel_id'])) { $this->data = self::load_panel($_GET['panel_id']); $this->formaction = FUSION_SELF.$aidlink."§ion=panelform&action=edit&panel_id=".$_GET['panel_id']; } else { redirect(FUSION_SELF.$aidlink); } break; case 'setstatus' : self::set_panel_status(); break; case 'delete': self::delete_panel($_GET['panel_id']); break; default: $this->formaction = FUSION_SELF.$aidlink."§ion=panelform"; } \PHPFusion\BreadCrumbs::getInstance()->addBreadCrumb(['link' => ADMIN.'panels.php'.$aidlink, 'title' => self::$locale['600']]); self::set_paneldb(); } private static function set_locale() { self::$locale = fusion_get_locale("", LOCALE.LOCALESET."admin/panels.php"); } /** * Return panel positions array * * @return array */ private static function get_panel_grid() { return [ 1 => self::$locale['420'], 2 => self::$locale['421'], 3 => self::$locale['425'], 4 => self::$locale['422'], 5 => self::$locale['426'], 6 => self::$locale['427'], 7 => self::$locale['428a'], 8 => self::$locale['428b'], 9 => self::$locale['428c'], 10 => self::$locale['428d'] ]; } /** * Load entire DB_PANELS table * * @return array */ private function load_all_panels() { $list = []; $result = dbquery("SELECT * FROM ".DB_PANELS." ORDER BY panel_side ASC, panel_order ASC"); if (dbrows($result) > 0) { while ($data = dbarray($result)) { $list[$data['panel_side']][] = $data; } } return $list; } /** * Fetch data for one panel * * @param $id * * @return array|bool */ static function load_panel($id) { if (isnum($id)) { $result = dbquery("SELECT * FROM ".DB_PANELS." WHERE panel_id='".intval($id)."'"); if (dbrows($result) > 0) { return dbarray($result); } } return []; } /** * MYSQL actions set active or inactive */ private static function set_panel_status() { $id = $_GET['panel_id']; if (self::verify_panel($id) && isnum($_GET['panel_status'])) { dbquery("UPDATE ".DB_PANELS." SET panel_status='".intval($_GET['panel_status'])."' WHERE panel_id='".intval($id)."'"); redirect(FUSION_SELF.fusion_get_aidlink()); } } /** * Checks if a panel id is valid * * @param $id * * @return bool|string */ static function verify_panel($id) { if (isnum($id)) { return dbcount("(panel_id)", DB_PANELS, "panel_id='".intval($id)."'"); } return FALSE; } /** * MYSQL actions delete panel * * @param $id */ private static function delete_panel($id) { if (self::verify_panel($id)) { $data = dbarray(dbquery("SELECT panel_side, panel_order FROM ".DB_PANELS." WHERE panel_id='".intval($_GET['panel_id'])."'")); dbquery("DELETE FROM ".DB_PANELS." WHERE panel_id='".intval($_GET['panel_id'])."'"); dbquery("UPDATE ".DB_PANELS." SET panel_order=panel_order-1 WHERE panel_side='".intval($data['panel_side'])."' AND panel_order>='".intval($data['panel_order'])."'"); addNotice('warning', self::$locale['489']); redirect(FUSION_SELF.fusion_get_aidlink()); } } /** * MYSQL save/update panels */ private function set_paneldb() { $aidlink = fusion_get_aidlink(); $locale = fusion_get_locale(); if (isset($_POST['panel_save'])) { $this->data['panel_id'] = isset($_POST['panel_id']) ? form_sanitizer($_POST['panel_id'], '0', 'panel_id') : 0; $this->data['panel_name'] = isset($_POST['panel_name']) ? form_sanitizer($_POST['panel_name'], '', 'panel_name') : ''; $this->data['panel_side'] = isset($_POST['panel_side']) ? form_sanitizer($_POST['panel_side'], 1, 'panel_side') : 1; $this->data['panel_access'] = isset($_POST['panel_access']) ? form_sanitizer($_POST['panel_access'], '0', 'panel_access') : 0; // panel name is unique $result = dbcount("(panel_id)", DB_PANELS, "panel_name='".$this->data['panel_name']."' AND panel_id !='".$this->data['panel_id']."'"); if ($result) { \defender::stop(); addNotice('danger', self::$locale['471']); } $this->data['panel_filename'] = isset($_POST['panel_filename']) ? form_sanitizer($_POST['panel_filename'], '', 'panel_filename') : ''; // panel content formatting if ($this->data['panel_filename'] == 'none') { $this->data['panel_type'] = "php"; $this->data['panel_content'] = isset($_POST['panel_content']) ? addslashes($_POST['panel_content']) : ''; if (!$this->data['panel_content']) { $this->data['panel_content'] = "opentable(\"name\");\n"."echo \"".$locale['469a']."\";\n"."closetable();"; if ($this->data['panel_side'] == 1 || $this->data['panel_side'] == 4) { $this->data['panel_content'] = "openside(\"name\");\n"."echo \"".$locale['469a']."\";\n"."closeside();"; } } } else { $this->data['panel_content'] = ''; $this->data['panel_type'] = "file"; } // need to add fourth option. only show in front page. $this->data['panel_restriction'] = isset($_POST['panel_restriction']) ? form_sanitizer($_POST['panel_restriction'], '', 'panel_restriction') : 0; // 3, show on all, 2 = show on home page. 1 = exclude , 0 = include // post 0 to include all , 1 to exclude all, show all. if ($this->data['panel_restriction'] == '3') { // show on all $this->data['panel_display'] = ($this->data['panel_side'] !== 1 && $this->data['panel_side'] !== 4) ? 1 : 0; $this->data['panel_url_list'] = ''; } else if ($this->data['panel_restriction'] == '2') { // show on homepage only $this->data['panel_display'] = 0; $this->data['panel_url_list'] = ''; if ($this->data['panel_side'] == 1 || $this->data['panel_side'] == 4) { $this->data['panel_url_list'] = fusion_get_settings('opening_page'); // because 1 and 4 directly overide panel_display. } } else { // require panel_url_list in this case $this->data['panel_url_list'] = isset($_POST['panel_url_list']) ? form_sanitizer($_POST['panel_url_list'], '', 'panel_url_list') : ''; if ($this->data['panel_url_list']) { $this->data['panel_url_list'] = str_replace(",", "\r\n", $this->data['panel_url_list']); if ($this->data['panel_restriction'] == 1) { // exclude mode $this->data['panel_display'] = ($this->data['panel_side'] !== 1 && $this->data['panel_side'] !== 4) ? 1 : 0; } else { // include mode $this->data['panel_display'] = ($this->data['panel_side'] !== 1 && $this->data['panel_side'] !== 4) ? 1 : 0; } } else { \defender::stop(); addNotice('danger', self::$locale['475']); } } $panel_languages = isset($_POST['panel_languages']) ? \defender::sanitize_array($_POST['panel_languages']) : []; if (!empty($panel_languages)) { $this->data['panel_languages'] = implode('.', $panel_languages); } if ($this->data['panel_id'] && self::verify_panel($this->data['panel_id'])) { // Panel Update dbquery_insert(DB_PANELS, $this->data, 'update'); addNotice('success', self::$locale['482']); } else { // Panel Save $result = dbquery("SELECT panel_order FROM ".DB_PANELS." WHERE panel_side='".intval($this->data['panel_side'])."' ORDER BY panel_order DESC LIMIT 1"); if (dbrows($result) != 0) { $data = dbarray($result); $this->data['panel_order'] = $data['panel_order'] + 1; } else { $this->data['panel_order'] = 1; } dbquery_insert(DB_PANELS, $this->data, 'save'); addNotice('success', self::$locale['485']); } // Regulate Panel Ordering $result = dbquery("SELECT panel_id, panel_side FROM ".DB_PANELS." ORDER BY panel_side ASC, panel_order ASC"); if (dbrows($result)) { $current_side = 0; $order = ''; while ($data = dbarray($result)) { $panel_id = $data['panel_id']; $panel_side = $data['panel_side']; if ($panel_side !== $current_side) { $order = 0; } $order = $order + 1; dbquery("UPDATE ".DB_PANELS." SET panel_order=:order WHERE panel_id=:panel_id", [':order' => $order, ':panel_id' => $panel_id]); $current_side = $panel_side; } } if (\defender::safe()) { redirect(FUSION_SELF.$aidlink."§ion=listpanel"); } } } public function display_admin() { // do the table opentable(self::$locale['600']); $edit = (isset($_GET['action']) && $_GET['action'] == 'edit') ? $this->verify_panel($_GET['panel_id']) : 0; // build a new interface $tab_title['title'][] = self::$locale['407']; $tab_title['id'][] = 'listpanel'; $tab_title['icon'][] = ''; $tab_title['title'][] = $edit ? self::$locale['409'] : self::$locale['408']; $tab_title['id'][] = 'panelform'; $tab_title['icon'][] = $edit ? "fa fa-pencil m-r-10" : 'fa fa-plus-square m-r-10'; $tab_active = tab_active($tab_title, $edit ? 1 : 0, 'section'); echo opentab($tab_title, $tab_active, 'id', TRUE); echo opentabbody($tab_title['title'][0], 'listpanel', $tab_active, 1); $this->panel_listing(); echo closetabbody(); if (isset($_GET['section']) && $_GET['section'] == 'panelform') { echo opentabbody($tab_title['title'][1], 'panelform', $tab_active, 1); $this->add_panel_form(); echo closetabbody(); } echo closetab(); closetable(); } /** * Current Panel Template */ public function panel_listing() { $aidlink = fusion_get_aidlink(); add_to_head(""); add_to_jquery(" $('.panels-list').sortable({ handle : '.handle', placeholder: 'state-highlight', connectWith: '.connected', scroll: true, axis: 'auto', update: function () { var ul = $(this), order = ul.sortable('serialize'), i = 0; $('#info').load('panels_updater.php".$aidlink."&'+order); ul.find('.num').each(function(i) { $(this).text(i+1); }); ul.find('li').removeClass('tbl2').removeClass('tbl1'); ul.find('li:odd').addClass('tbl2'); ul.find('li:even').addClass('tbl1'); window.setTimeout('closeDiv();',2500); }, receive: function () { var ul = $(this), order = ul.sortable('serialize'), pdata = ul.attr('data-side'); if (pdata == 1) { var psidetext = '".self::$locale['420']."'; } if (pdata == 2) { var psidetext = '".self::$locale['421']."'; } if (pdata == 3) { var psidetext = '".self::$locale['425']."'; } if (pdata == 4) { var psidetext = '".self::$locale['422']."'; } ul.find('.pside').each(function() { $(this).text(psidetext); }); $('#info').load('panels_updater.php".$aidlink."&panel_side='+pdata+'&'+order); } }); "); echo "