$msg] ); } /** * Checks if target method is available to be called using AJAX. * * @param string $method Target method. * * @return boolean True allowed, false not. */ public function ajaxMethod($method) { global $config; // Check access. check_login(); return in_array($method, $this->AJAXMethods); } /** * Constructor. * * @param boolean $must_run Must run or not. * @param string $ajax_controller Controller. * * @return object * @throws Exception On error. */ public function __construct( $ajax_controller='include/ajax/tips_window.ajax' ) { $this->ajaxController = $ajax_controller; return $this; } /** * Main method. * * @return void */ public function run() { ui_require_css_file('tips_window'); ui_require_css_file('jquery.bxslider'); ui_require_javascript_file('tipsWindow'); ui_require_javascript_file('jquery.bxslider.min'); echo '
'; $this->totalTips = $this->getTotalTips(); if ($this->totalTips > 0) { ?> getRandomTip(true); View::render( 'dashboard/tipsWindow', [ 'title' => $initialTip['title'], 'text' => $initialTip['text'], 'url' => $initialTip['url'], 'files' => $initialTip['files'], ] ); } public function getRandomTip($return=false) { $exclude = get_parameter('exclude', ''); $sql = 'SELECT id, title, text, url FROM twelcome_tip'; if (empty($exclude) === false && $exclude !== null) { $exclude = implode(',', json_decode($exclude, true)); if ($exclude !== '') { $sql .= sprintf(' WHERE id NOT IN (%s)', $exclude); } } $sql .= ' ORDER BY RAND()'; $tip = db_get_row_sql($sql); $tip['files'] = $this->getFilesFromTip($tip['id']); if ($return) { if (empty($tip) === false) { return $tip; } else { return false; } } else { if (empty($tip) === false) { echo json_encode(['success' => true, 'data' => $tip]); return; } else { echo json_encode(['success' => false]); return; } } } public function getTotalTips() { return db_get_sql('SELECT count(*) FROM twelcome_tip'); } public function getFilesFromTip($idTip) { if (empty($idTip) === true) { return false; } $sql = sprintf('SELECT filename, path FROM twelcome_tip_file WHERE twelcome_tip_file = %s', $idTip); return db_get_all_rows_sql($sql); } }