Exemple #1
0
/**
* @desc Visualiza todas las imágenes existentes
**/
function showImages()
{
    global $xoopsModule, $tpl, $xoopsConfig, $xoopsSecurity, $xoopsUser;
    $db = Database::getInstance();
    $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
    $page = $page <= 0 ? 1 : $page;
    $limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 15;
    $limit = $limit <= 0 ? 15 : $limit;
    $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : '';
    $owner = isset($_REQUEST['owner']) ? $_REQUEST['owner'] : '';
    $mindate = isset($_REQUEST['mindate']) ? $_REQUEST['mindate'] : '';
    $maxdate = isset($_REQUEST['maxdate']) ? $_REQUEST['maxdate'] : '';
    $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'created';
    $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 1;
    $mode = $mode == '' ? 1 : $mode;
    //Barra de Navegación
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_images');
    $sql1 = '';
    $words = array();
    if ($search != '') {
        //Separamos en palabras
        $words = explode(" ", $search);
        foreach ($words as $k) {
            $k = trim($k);
            if (strlen($k) <= 2) {
                continue;
            }
            $sql1 .= $sql1 == '' ? " WHERE (title LIKE '%{$k}%')" : " OR (title LIKE '%{$k}%')";
        }
    }
    if ($owner > 0) {
        $sql1 .= $search != '' ? " AND owner='{$owner}'" : " WHERE owner='{$owner}'";
    }
    if ($mindate != '') {
        $maxdate = $maxdate != '' ? $maxdate : time();
        $sql1 .= $search != '' || $owner > 0 ? " AND " : " WHERE ";
        $sql1 .= "(created>='{$mindate}' AND created<='{$maxdate}')";
    }
    list($num) = $db->fetchRow($db->query($sql . $sql1));
    $start = $num <= 0 ? 0 : ($page - 1) * $limit;
    $tpages = ceil($num / $limit);
    $nav = new RMPageNav($num, $limit, $page, 5);
    $nav->target_url("images.php?page={PAGE_NUM}&amp;limit={$limit}&amp;search={$search}&amp;owner={$owner}&amp;mindate={$mindate}&amp;maxdate={$maxdate}&amp;sort={$sort}&amp;mode={$mode}");
    $showmax = $start + $limit;
    $showmax = $showmax > $num ? $num : $showmax;
    //Fin de barra de navegación
    $sql = "SELECT * FROM " . $db->prefix('gs_images');
    $sql2 = " ORDER BY {$sort} " . ($mode ? "DESC" : "ASC");
    $sql2 .= " LIMIT {$start},{$limit}";
    $result = $db->query($sql . $sql1 . $sql2);
    $users = array();
    $images = array();
    while ($rows = $db->fetchArray($result)) {
        $title = '';
        foreach ($words as $k) {
            $title = eregi_replace("({$k})", "<span class='searchResalte'>\\1</span>", $rows['title']);
        }
        $img = new GSImage();
        $img->assignVars($rows);
        if (!isset($users[$img->owner()])) {
            $users[$img->owner()] = new GSUser($img->owner(), 1);
        }
        $link = $users[$img->owner()]->userURL() . "img/" . $img->id();
        $xu = $users[$img->owner()];
        $images[] = array('id' => $img->id(), 'title' => $title ? $title : $img->title(), 'desc' => substr($img->desc(), 0, 150), 'image' => $users[$img->owner()]->filesURL() . '/ths/' . $img->image(), 'created' => formatTimeStamp($img->created(), 'c'), 'owner' => $xu->uname(), 'public' => $img->isPublic(), 'link' => $link);
    }
    $form = new RMForm('', 'frmNav', '');
    $ele = new RMFormUser('', 'owner', false, $owner > 0 ? array($owner) : array(0), 50, null, null, 1);
    $ele->setForm('frmNav');
    $tpl->assign('user_field', $ele->render());
    $ele = new RMFormDate('', 'mindate', $mindate == null ? null : $mindate, 1);
    $tpl->assign('mindate_field', $ele->render());
    $ele = new RMFormDate('', 'maxdate', $maxdate == null ? null : $maxdate, 1);
    $tpl->assign('maxdate_field', $ele->render());
    GSFunctions::toolbar();
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; " . __('Images Management', 'galleries'));
    RMTemplate::get()->assign('xoops_pagetitle', __('Images', 'galleries'));
    RMTemplate::get()->add_script(RMCURL . '/include/js/jquery.checkboxes.js');
    RMTemplate::get()->add_local_script('images.js', 'galleries');
    RMTemplate::get()->add_local_script('gsscripts.php?file=sets&form=frm-images&p=' . TextCleaner::getInstance()->encrypt($xoopsUser->uid() . '|' . GS_URL . '/admin/images.php' . '|' . $xoopsSecurity->createToken(), true), 'galleries');
    RMTemplate::get()->add_head("<script type='text/javascript'>\nvar delete_warning='" . __('Do you really wish to delete selected images?', 'galleries') . "';\n</script>");
    xoops_cp_header();
    include RMTemplate::get()->get_template("admin/gs_images.php", 'module', 'galleries');
    xoops_cp_footer();
}