Example #1
0
 /**
  * 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 Almacena los datos de un anuncio
*/
function saveAnnouncement($edit = 0)
{
    global $xoopsUser, $xoopsSecurity;
    $q = 'action=' . ($edit ? 'edit' : 'new');
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'action') {
            continue;
        }
        $q .= '&' . $k . '=' . $v;
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('announcements.php?' . $q, __('Session token expired!', 'bxpress'), 1);
        die;
    }
    if ($edit) {
        $id = rmc_server_var($_POST, '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 no exists!', 'bxpress'), 1);
            die;
        }
    } else {
        $an = new bXAnnouncement();
    }
    if ($expire <= time()) {
        redirectMsg('announcements.php?' . $q, __('The expiration time can not be minor than current time!', 'bxpress'), 1);
        die;
    }
    $an->setBy($xoopsUser->uid());
    $an->setByName($xoopsUser->uname());
    if (!$edit) {
        $an->setDate(time());
    }
    $an->setExpire($expire);
    $an->setForum($forum);
    $an->setText($text);
    $an->setWhere($where);
    $an = RMEvents::get()->run_event("bxpress.before.save.announcement", $an);
    if ($an->save()) {
        $an = RMEvents::get()->run_event("bxpress.announcement.saved", $an);
        redirectMsg('announcements.php', __('Announcement saved successfully!', 'bxpress'), 0);
    } else {
        $an = RMEvents::get()->run_event("bxpress.announcement.save.error", $an);
        redirectMsg('announcements.php?' . $q, __('Announcement could not be saved!', 'bxpress') . '<br />' . $an->errors(), 1);
    }
}