<?php

?>
<form name="frmins" method="post" action="<? echo $action ?>" >

<div class="spessore" style="height:20px"></div>
                        <div class="testo">
                            Cerca per email o nominativo: <input type="text" name="searchstr" value="<?= $searchstr ?>" />
            <img src="main/contents/icone/magnifier.png" class="ico24 imgcliccabile" onclick="refresh()" align="absmiddle" />
        <? if ($searchstr != "") { ?>
                                <img src="main/contents/icone/magnifier-r.png" class="ico24 imgcliccabile" onclick="document.frmins.searchstr.value = '';refresh()" align="absmiddle" />
            <? } ?>
        <div class="spessore" style="height:20px"></div>
       
<div style="text-align: left">
                                Visualizza <input type="text" name="nxpage" value="<?= $nxpage ?>" class="lite mini" /> righe per pagina <img src="main/contents/icone/right-arrow-1.png" class="ico24 cliccabile rounded" align="absmiddle" onclick="document.frmins.submit()" />
</div>    
<div class="spessore"></div> 

<div class="spessore" style="height:10px"></div>
   <div class="admtitolo" align="left">
   <? 
                            $pagmode = '1';
                            $frm = "document.frmins";
   $href0 = "?MSID=$MSID&sz=utenti";
   
                            if ($ntot > 0)
    include "paginazione.php"; 
   ?>	
   <div class="spessore" style="height:10px"></div>

   </div>       

   <table class="tablegrid3 tableresp" cellpadding="6" cellspacing="0">
            <thead>
                <tr>
                    <th></th>
                    <th  onclick="setOrd('nome')"><span class="underlined cliccabile">Nominativo</span></th>
                    <th  onclick="setOrd('email')"><span class="underlined cliccabile">Email</span></th>
                    <th>UserID</th>
                    <th  onclick="setOrd('data_reg')"><span class="underlined cliccabile">Data registrazione</span></th>
                    <th >Surveys</th>
                    <th></th>
                </tr>
            </thead>
            
            <tbody>
                
            
        <?
                                $i = 0;
        
                                foreach ($a_utenti as $k => $r) {
                                    $i++;
                                    $nome = mydecodeTxt($r['nome']);
                                    $cognome = mydecodeTxt($r['cognome']) . " " . $nome;
                                    $email = mydecodeTxt($r['email']);
                                    $data_reg = Date_fromdbX($r['data_ins']);
                                    $idu = $r['id_utenti'];
                                    /*
                                      $stato=$r['stato'];
                                      $icostato = "verified.png";
                                      $altstato = "Attivo";
                                      if($stato=='0') {
                                      $icostato = "notaccept.png";
                                      $altstato = "Non attivo";
                                      }
                                     
                                    if($r['data_confermato']=="")  $icoemail = "notaccept.png";
                                    else $icoemail = "verified.png";
                                    $profilo = "";
                                    */
                                    $nsurveys = 0;
                                    $sql = "SELECT count(*) as nsurveys FROM survey_users WHERE id_utente='$idu' AND data_invio IS NOT NULL AND data_invio != ''  AND id_survey > 0"; 
                                    $mydb->DoSelect($sql);
                                    $r2 = $mydb->GetRow();
                                    $nsurveys = $r2['nsurveys'];
                                    ?>
                                    <tr>
                                        <td data-label="" style="min-height:32px">
                                            <div class="fleft"><?= $i + $nn ?></div>
                                            <div class="tdToolbar1 fright">
                                                <a href="javascript:editUser(<?= $idu ?>)"><img src="main/contents/icone/edit-icon.png" class="imgcliccabile ico20 fleft" /></a>
                                                <a href="javascript:delUser(<?= $idu ?>)"><img src="main/contents/icone/cancel.png" class="imgcliccabile ico20 fright" /></a>
                                            </div>
                                        </td>
                                        <td data-label="Cognome"><?= $cognome ?></td>
                                        <td data-label="Email"><?= $email ?></td>
                                        <td><?=$r['username']?></td>
                                        <td data-label="Data registrazione"><?= $data_reg ?></td>
                                        <td>
                                            <?if($nsurveys > 0) {?>
                                            <a href="javascript:openSurveys(<?= $idu ?>)"><img src="main/contents/icone/book.png" class="ico18 imgcliccabile" /></a>
                                            <?} else {?>
                                            <img src="main/contents/icone/book.png" class="ico18" style="opacity:0.8" />
                                            <?}?>
                                        </td>
                                        <td class="tdToolbar" style="min-width:260px">
                                            <a href="javascript:editUser(<?= $idu ?>)"><img src="main/contents/icone/edit-icon.png?t=0" class="imgcliccabile ico20 fleft" /></a>
                                            <a href="javascript:delUser(<?= $idu ?>)"><img src="main/contents/icone/cancel.png" class="imgcliccabile ico20 fright" /></a>
                                        </td>
                                    </tr>
                                    <?
                                    $html .= '<tr>'
                                            . '<td>'.$cognome.'</td>'
                                            . '<td>'.$email.'</td>'
                                            . '<td>'.$data_reg.'</td>'
                                            . '<td></td>'
                                            . '</tr>
                                            ';
                                    $csv .= "$cognome;$email;$data_reg;;\n";        
                                           
                                }
                                ?>
                            </tbody>
                        </table>

                        <?
                        $html .= '</tbody>
                        </table>
                        ';
                        ?>

                        <input type="hidden" name="MSID" value="<?= $MSID ?>" />
                        <input type="hidden" name="sz" value="<?= $sezione ?>" />
                        <input type="hidden" name="azione" value="" />
                        <input type="hidden" name="id" value="" />

                        <input type="hidden" name="tab" value="<?= $tab ?>" />
                        <input type="hidden" name="tab2" value="<?= $tab2 ?>" />

                        <input type="hidden" name="ord" value="<?= $ord ?>" />
                    </form>


<script>

    function openSurveys(idu) {
        var url = "<?= $href0 ?>&sz=survey&MSID=<?=$MSID?>&id_utente=" + idu;
        window.location.href = url;
    }

</script>