Exemple #1
0
/**
* @desc Visualiza  todas las figuras existentes de una publicación
**/
function Figures()
{
    global $rmc_messages, $xoopsTpl, $xoopsSecurity;
    define('DF_LOCATION', 'list');
    $id = rmc_server_var($_GET, 'id', 0);
    $search = rmc_server_var($_GET, 'search', '');
    $rmc_config = RMFunctions::configs();
    //Navegador de páginas
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_figures') . " WHERE id_res={$id}";
    $sql1 = '';
    if ($search) {
        //Separamos la frase en palabras para realizar la búsqueda
        $words = explode(" ", $search);
        foreach ($words as $k) {
            //Verificamos el tamaño de la palabra
            if (strlen($k) <= 2) {
                continue;
            }
            $sql1 .= ($sql1 == '' ? ' AND ' : " OR ") . " `desc` LIKE '%{$k}%' ";
        }
    }
    list($num) = $db->fetchRow($db->queryF($sql . $sql1));
    $page = rmc_server_var($_REQUEST, 'page', 1);
    $page = $page <= 0 ? 1 : $page;
    $limit = 13;
    $tpages = ceil($num / $limit);
    $page = $page > $tpages ? $tpages : $page;
    $start = $num <= 0 ? 0 : ($page - 1) * $limit;
    $nav = new RMPageNav($num, $limit, $page, 4);
    $nav->target_url("?id={$id}&amp;page={PAGE_NUM}&amp;search={$search}");
    $ruta = '?id=' . $id . '&page=' . $page . '&search=' . $search;
    //Fin navegador de páginas
    $sql = "SELECT * FROM " . $db->prefix('rd_figures') . " WHERE id_res={$id}";
    $sql1 = '';
    if ($search) {
        //Separamos la frase en palabras para realizar la búsqueda
        $words = explode(" ", $search);
        foreach ($words as $k) {
            //Verificamos el tamaño de la palabra
            if (strlen($k) <= 2) {
                continue;
            }
            $sql1 .= ($sql1 == '' ? ' AND ' : " OR ") . " `desc` LIKE '%{$k}%' ";
        }
    }
    $sql2 = " ORDER BY id_fig DESC LIMIT {$start},{$limit} ";
    $result = $db->queryF($sql . $sql1 . $sql2);
    $figures = array();
    while ($rows = $db->fetchArray($result)) {
        $fig = new RDFigure();
        $fig->assignVars($rows);
        $figures[] = array('id' => $fig->id(), 'desc' => $fig->getVar('desc'));
    }
    RMTemplate::get()->add_script(RMCURL . '/include/js/jquery.min.js');
    RMTemplate::get()->add_script(RMCURL . '/include/js/jquery-ui.min.js');
    RMTemplate::get()->add_script(RMCURL . '/include/js/jquery.checkboxes.js');
    RMTemplate::get()->add_script('include/js/scripts.php?file=ajax.js');
    RMTemplate::get()->add_script('include/js/editor-' . $rmc_config['editor_type'] . '.js');
    $theme_css = xoops_getcss();
    $vars = $xoopsTpl->get_template_vars();
    extract($vars);
    if ($rmc_config['editor_type'] == 'tiny') {
        RMTemplate::get()->add_script(XOOPS_URL . '/modules/rmcommon/api/editors/tinymce/tiny_mce_popup.js');
    } elseif ($rmc_config['editor_type'] == 'xoops') {
        RMTemplate::get()->add_script(XOOPS_URL . '/modules/rmcommon/api/editors/exmcode/editor-popups.js');
    }
    RMTemplate::get()->add_style('refs.css', 'docs');
    RMTemplate::get()->add_style('jquery.css', 'rmcommon');
    // Options for table header
    $options[] = array('title' => __('Select Document', 'docs'), 'href' => 'javascript:;', 'attrs' => 'id="option-resource" onclick="docsAjax.getSectionsList(1);"', 'tip' => __('Select another Document to show the figures that belong to this.', 'docs'));
    $options[] = array('title' => __('Create Figure', 'docs'), 'href' => "?action=new&amp;id={$id}&amp;search={$search}&amp;page={$page}", 'attrs' => 'id="option-new-fig"', 'tip' => __('Create a new figure', 'docs'));
    // Get additional options from other modules or plugins
    $options = RMEvents::get()->run_event('docs.figures.options', $options, $id);
    // Insert adtional content in template
    $other_content = '';
    $other_content = RMEvents::get()->run_event('docs.additional.figures.content', $other_content, $id);
    include RMTemplate::get()->get_template('rd_figures.php', 'module', 'docs');
}
 /**
  * Get all figures list according to given parameters
  * @param int Resource ID
  * @param Referenced var to return results count
  * @param string Search keyword
  * @param int Start results
  * @param int Results number limit
  * @return array
  */
 public function figures($res = 0, &$count, $search = '', $start = 0, $limit = 15)
 {
     $db = XoopsDatabaseFactory::getDatabaseConnection();
     $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_figures') . ($res > 0 ? " WHERE id_res='{$res}'" : '');
     if ($search != '') {
         $sql .= ($res > 0 ? " AND " : " WHERE ") . " (desc LIKE '%{$k}%' OR content LIKE '%{$k}%')";
     }
     if ($res > 0) {
         $res = new RDResource($res);
     }
     list($num) = $db->fetchRow($db->query($sql));
     $limit = $limit <= 0 ? 15 : $limit;
     $count = $num;
     //Fin de navegador de páginas
     $sql = str_replace("COUNT(*)", "*", $sql);
     $sql .= " ORDER BY id_fig DESC LIMIT {$start},{$limit}";
     $result = $db->query($sql);
     $figures = array();
     while ($rows = $db->fetchArray($result)) {
         $ref = new RDFigure();
         $ref->assignVars($rows);
         if ($res->isNew()) {
             $res = new RDResource($ref->resource());
         }
         $figures[] = array('id' => $ref->id(), 'title' => $ref->getVar('title'), 'desc' => $ref->getVar('desc'), 'content' => substr(TextCleaner::getInstance()->clean_disabled_tags($ref->getVar('content')), 0, 50) . "...", 'resource' => $res->getVar('title'));
     }
     return $figures;
 }
Exemple #3
0
/**
* @desc Almacena información perteneciente a la figura
**/
function rd_save_figures($edit = 0)
{
    global $xoopsSecurity;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "?res={$res}";
    if (!$xoopsSecurity->validateToken()) {
        redirectMsg('./figures.php' . $ruta, __('Session token expired!', 'docs'), 1);
        die;
    }
    if ($edit) {
        //Verifica que referencia sea válida
        if ($id <= 0) {
            redirectMsg('./figures.php' . $ruta, __('Figure id not specified!', 'docs'), 1);
            die;
        }
        //Verifica que referencia exista
        $fig = new RDFigure($id);
        if ($fig->isNew()) {
            redirectMsg('./figures.php' . $ruta, __('Specified figure does not exists!', 'docs'), 1);
            die;
        }
    } else {
        $fig = new RDFigure();
    }
    $fig->setVar('title', $title);
    $fig->setVar('desc', $desc);
    $fig->setVar('content', $figure);
    $fig->setVar('id_res', $res);
    $fig->setVar('attrs', $attrs);
    if ($fig->save()) {
        redirectMsg('./figures.php?action=locate&res=' . $res . '&id=' . $fig->id(), __('Figure saved successfully!', 'docs'), 0);
        die;
    } else {
        redirectMsg('./figures.php?action=locate&id=' . $fig->id() . '&res=' . $res, __('Figure could not be saved!', 'docs') . '<br />' . $fig->errors(), 1);
        die;
    }
}