Generate a link in file download php that changes color when clicked

0

Good morning. My intention with my code is to send you a list of hyperlinks to download to a user. The idea is to change the background of the hyperlink when a person clicks and is marked (either with the font color changed or the link has a different background color). The conditions of the if are irrelevant (they are what I put in my code) and the only line that is below each one, leaves me the variable $ data- > link as a clickable link. So far everything is normal, but I need $ data- > link to be a clickable link with the features I mentioned.

        <?php
                        if ($fd->componente == 'mod_resource'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i','<a href="$1" target="_blank">$1</a>',"$CFG->wwwroot/mod/resource/view.php?id=".$fd->idmodulocurso);
                            }


                            else if ($fd->componente == 'mod_folder'){
$data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/pluginfile.php/". $fd->idcontexto . "/mod_folder/content/0/". rawurlencode($fd->nombrearchivo)) ;
                            }
            ?>

All this is in the context of a code page, I leave it to you if it helps to understand the context (a query in moodle format to a database)

<?php 
require (dirname(dirname(__FILE__)) . '/config.php');
global $DB;

        global $DB;
        $query =        "SELECT     f.id AS id, 
                                    c.fullname AS nombrecurso, 
                                    c.shortname AS nombrecortocurso, 
                                    cx.contextlevel AS nivelcontexto, 
                                    f.contextid AS idcontexto, 
                                    f.filename AS nombrearchivo, 
                                    f.component AS componente, 
                                    cm.course AS idcurso,
                                    cm.id AS idmodulocurso
                        FROM            {files} f
                        INNER JOIN      {context} cx        ON (f.contextid = cx.id)
                        INNER JOIN      {course_modules} cm ON (cx.instanceid=cm.id)
                        INNER JOIN      {course} c          ON (cm.course=c.id) AND f.filename <> ? AND f.component <> ? AND f.timecreated > ?";
        $files_data=$DB->get_records_sql($query,array('.','user','0'));

        $table = new html_table();
        $table->head = array('File_name','Course_name','Link');
        foreach ($files_data as $fd) {
            $data = new stdClass();
            $data->nombre = $fd->nombrearchivo;
            $data->nombrecurso = $fd->nombrecurso;
                if ($fd->componente == 'mod_resource'){
                    $data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/mod/resource/view.php?id=".$fd->idmodulocurso);
                }   
                else if ($fd->componente == 'mod_folder'){
                    $data->link= preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;//=]+)!i', '<a href="$1" target="_blank">$1</a>', "$CFG->wwwroot/pluginfile.php/". $fd->idcontexto . "/mod_folder/content/0/". rawurlencode($fd->nombrearchivo)) ;
                }
        $table->data[] = array($data->nombre, $data->nombrecurso,$data->link);
        }
    echo html_writer::table($table);    




?>
    
asked by Juan Luis Cordova 06.01.2017 в 21:12
source

1 answer

1

Well, given the information you provide, the answer I can give you is to use CSS 3; I leave the following example for consideration:

a:link div{
    color: blue;
    background-color: lightblue;
    padding:5px;
}
a:visited div {
    color: green;    background-color: blue;
}
a:hover div {
    color: hotpink;     background-color: pink;
}
<a href="http://google.com" targe="_blank"><div>Link a google</div></a><br />
<a href="http://referi.com" targe="_blank"><div>Link a referi</div></a><br />
<a href="http://random.com" targe="_blank"><div>Link a random</div></a>

What happens here is that when you visit a link the browser remembers this, you can apply a CSS rule to this situation and if you include a <div> in your tag <a> this rule is applied to the child element; the <div> tag

    
answered by 07.01.2017 в 00:41