/** * Load announcements form database * @param int Where to search (0 = home page, 1 = froum, 2 = all module) * @return array */ public function loadAnnouncements($w, $forum = 0) { global $xoopsModuleConfig, $tpl; if (!$xoopsModuleConfig['announcements']) { return; } $db = XoopsDatabaseFactory::getDatabaseConnection(); // Primero purgamos la tabla $db->queryF("DELETE FROM " . $db->prefix("mod_bxpress_announcements") . " WHERE expire<='" . time() . "'"); $mc =& $xoopsModuleConfig; $sql = "SELECT * FROM " . $db->prefix("mod_bxpress_announcements"); switch ($w) { case 0: $sql .= " WHERE `where`=0 OR `where`=2 "; break; case 1: $sql .= " WHERE `where`=2 OR (`where`='1' AND forum='{$forum}') "; break; } if ($mc['announcements_mode']) { $sql .= " ORDER BY RAND() "; } else { $sql .= " ORDER BY `date` DESC "; } $sql .= "LIMIT 0, {$mc['announcements_max']}"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $an = new bXAnnouncement(); $an->assignVars($row); $tpl->append('announcements', array('text' => $an->text('s'))); } return true; }
/** * @desc Presenta el formulario para creación o edición de un anuncio */ function showForm($edit = 0) { global $tpl, $xoopsModule, $db; if ($edit) { $id = rmc_server_var($_GET, 'id', 0); if ($id <= 0) { redirectMsg('announcements.php', __('Provided ID is not valid!', 'bxpress'), 1); die; } $an = new bXAnnouncement($id); if ($an->isNew()) { redirectMsg('announcements.php', __('Specified announcement does not exists!', 'bxpress'), 1); die; } } RMTemplate::get()->set_help('http://www.redmexico.com.mx/docs/bxpress-forums/anuncios/standalone/1/#crear-un-anuncio'); bXFunctions::menu_bar(); xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> » " . ($edit ? __('Edit Announcement', 'bxpress') : __('New Announcement', 'bxpress'))); xoops_cp_header(); $form = new RMForm($edit ? __('Edit Announcement', 'bxpress') : __('New Announcement', 'bxpress'), 'frmAnnouncements', 'announcements.php'); $form->oddClass('oddForm'); $form->addElement(new RMFormEditor(__('Text', 'bxpress'), 'text', '100%', '300px', $edit ? $an->text('e') : ''), true); // Caducidad $ele = new RMFormDate(__('Expire on', 'bxpress'), 'expire', $edit ? $an->expire() : time()); $form->addElement($ele); // Mostran en $ele = new RMFormRadio(__('Show on', 'bxpress'), 'where', 1, 0); $ele->addOption(__('Module home page', 'bxpress'), 0, $edit ? $an->where() == 0 : 1); $ele->addOption(__('Forum', 'bxpress'), 1, $edit ? $an->where() == 1 : 0); $ele->addOption(__('All module', 'bxpress'), 2, $edit ? $an->where() == 2 : 0); $form->addElement($ele); // Foros $ele = new RMFormSelect(__('Forum', 'bxpress'), 'forum', 0, $edit ? array($an->forum()) : array()); $ele->setDescription(__('Please select the forum where this announcement will be shown. This option only is valid when "In Forum" has been selected.', 'bxpress')); $tbl1 = $db->prefix("bxpress_categories"); $tbl2 = $db->prefix("bxpress_forums"); $sql = "SELECT b.*, a.title FROM {$tbl1} a, {$tbl2} b WHERE b.cat=a.id_cat AND b.active='1' ORDER BY a.order, b.order"; $result = $db->query($sql); $categories = array(); while ($row = $db->fetchArray($result)) { $cforum = array('id' => $row['id_forum'], 'name' => $row['name']); if (isset($categores[$row['cat']])) { $categories[$row['cat']]['forums'][] = $cforum; } else { $categories[$row['cat']]['title'] = $row['title']; $categories[$row['cat']]['forums'][] = $cforum; } } foreach ($categories as $cat) { $ele->addOption(0, $cat['title'], 0, true, 'color: #000; font-weight: bold; font-style: italic; border-bottom: 1px solid #c8c8c8;'); foreach ($cat['forums'] as $cforum) { $ele->addOption($cforum['id'], $cforum['name'], 0, false, 'padding-left: 10px;'); } } $form->addElement($ele); $ele = new RMFormButtonGroup(); $ele->addButton('sbt', $edit ? __('Save Changes', 'bxpress') : __('Create Announcement', 'bxpress'), 'submit'); $ele->addButton('cancel', __('Cancel', 'bxpress'), 'button', 'onclick="window.location=\'announcements.php\';"'); $form->addElement($ele); $form->addElement(new RMFormHidden('action', $edit ? 'saveedit' : 'save')); if ($edit) { $form->addElement(new RMFormHidden('id', $id)); } $form = RMEvents::get()->run_event('bxpress.form.announcement', $form); $form->display(); xoops_cp_footer(); }