<?php

/*function zisti_id($nick,$mail) {
  if ($link = spoj_s_db()) {
    $sql = "SELECT * FROM forum_pouzivatelia WHERE nick=" .$nick. " AND mail=" .$mail. "";
    $result1 = mysql_query($sql, $link);
    while ($row = mysql_fetch_assoc($result1)) {
      echo $row['id'];
    }
  }
}*/

function vypis_nazov_fora($idcko) {
  if ($link = spoj_s_db()) {
    /*$sql = "SELECT meno_fora FROM forum_forum WHERE id_fora=" .$idcko. "";*/
    $sql = "SELECT nazov_fora FROM forum_pouzivatelia WHERE id=$idcko";
    $result1 = mysql_query($sql, $link);
    while ($row = mysql_fetch_assoc($result1)) {
      echo '<a href="home.php?f='.$idcko.'" class="odkaz_3">'.$row['nazov_fora'].'</a>';
    }
  }  
}

function vypis_temy() {        /*////////////////  Vypíše temy z databázy  ////////////////*/
  if ($link = spoj_s_db()) {
    $sql = "SELECT * FROM forum_temy WHERE id_fora=" .$_GET['f']. " ORDER BY tema ASC";
    $result1 = mysql_query($sql, $link);
    $farba = 0;
    while ($row = mysql_fetch_assoc($result1)) {
      $farba = $farba+1;
      if ($farba%2==1){$farba = 1;} else {$farba = 2;}
      echo '<tr>
              <td class="temy_'.$farba.'">';
                if ($row['pristupnost']==2) {echo 'P ';}
                elseif ($row['pristupnost']==3) {echo 'H ';}
                else {echo 'V ';}
      echo     '<a href="tema.php?f='.$row['id_fora'].'&t='.$row['id_temy'].'" class="odkaz_2"><strong>'.$row['tema'].'</strong></a>';
                if ($row['autor']==$_SESSION['nick'] || $_GET['f']==$_SESSION['id']) {echo '<a href="tema_uprav.php?f='.$_GET['f'].'&t='.$row['id_temy'].'" class="odkaz"> Edit</a>';}
      echo     '<br/>'.$row['popis'].'
              </td>
              <td class="odp_prez_autor_'.$farba.'">';
                pocet5(forum_prispevky,$row['id_temy']);
      echo   '</td>
              <td class="odp_prez_autor_'.$farba.'">
                '.$row['prezrete'].'
              </td>
              <td class="odp_prez_autor_'.$farba.'">
                '.$row['autor'].'
              </td>
              <td class="posledny_'.$farba.'">
                '.$row['posledny'].'
              </td>
            </tr>';
    }
  }
}

/*function pristupnost_temy($forum,$tema) {
  if ($link = spoj_s_db()) {
    $sql = "SELECT T.pristupnost, P.moje_id, P.tvoje_id
            FROM forum_temy T, forum_priatelia P
            WHERE T.id_fora=$forum AND T.id_temy=$tema AND P.moje_id=".$_SESSION['id'];
    $result1 = mysql_query($sql, $link);
    while ($row = mysql_fetch_assoc($result1)) {
      if ($row['pristupnost']==2) {}
      elseif ($row['pristupnost']==2) {}
    }
  }
}*/

function vypis_prispevky() {        /*////////////////  Vypíše prispevky z databázy  ////////////////*/
  if ($link = spoj_s_db()) {
    $sql = "SELECT * 
            FROM forum_prispevky PR, forum_pouzivatelia P 
            WHERE id_fora=" .$_GET['f']. " AND id_temy=" .$_GET['t']. " AND P.nick=PR.autor ORDER BY id_prispevku ASC";
    $result1 = mysql_query($sql, $link);
    $farba=0;
    while ($row = mysql_fetch_assoc($result1)) {
      $farba = $farba+1;
      if ($farba%2==1){$farba = 1;} else {$farba = 2;}
      echo '<tr>
              <td class="sprava'.$farba.'">
                <div class="prispevok">'.$row['sprava'].'</div>
                <div class="sprava_edit">';
                if ($row['autor']==$_SESSION['nick'] || $_GET['f']==$_SESSION['id']) {echo '<a href="prispevok_uprav.php?f='.$_GET['f'].'&t='.$_GET['t'].'&p='.$row['id_prispevku'].'" class="odkaz_2">Edit</a>';}
      echo     '</div>
              </td>
              <td class="autor_prispevku'.$farba.'">
                '.$row['autor'].'<br/><img src="obrazky/users/'.$row['foto'].'" alt="nophoto" width="80"/>
              </td>
            <tr>';
    }
  }
}

function vypis_pouzivatelov2() {        /*////////////////  Vypíše pouzivatelov z databázy  ////////////////*/
  if ($link = spoj_s_db()) {
    $sql = "SELECT *
            FROM forum_pouzivatelia
            ORDER BY meno";
    $result1 = mysql_query($sql, $link);
    while ($row = mysql_fetch_assoc($result1)) {
      
      $sql2 = "SELECT COUNT(*)
            FROM forum_priatelia 
            WHERE moje_id=".$_SESSION['id']." AND tvoje_id=".$row['id']; 
      $je_priatel=mysql_result(mysql_query($sql2),0); //echo $je_priatel;
      
      echo '<table class="pouzivatel_'.$row['sex'].'">
              <tr>
                <td class="pouz_foto">
                  <img src="obrazky/users/'.$row['foto'].'" alt="nophoto" width="60"/>
                </td>
                <td class="pouz_info">
                  <a href="profil.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz">'.$row['nick'].'</a><br/>'
                  .$row['meno'].'<br/>'
                  .$row['nar'].'<br/>
                  <a href="home.php?f='.$row['id'].'" class="odkaz_4">'.$row['nazov_fora'].'</a><br/><br/>';
                  if ($je_priatel==0) { 
                    echo '<a href="priatel_pridaj.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz_4">Pridaj</a> priateľa';
                  }
                  else {
                    echo '<a href="priatel_odober.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz_4">Odober</a> priateľa';
                  }                
       echo    '</td>
              </tr>
            </table>';
    }
  }
}

function vypis_priatelov($moje) {        /*////////////////  Vypíše pouzivatelov z databázy  ////////////////*/
  if ($link = spoj_s_db()) {
    $sql = "SELECT *
            FROM forum_priatelia F, forum_pouzivatelia P
            WHERE F.moje_id = ".$moje." AND F.tvoje_id = P.id
            ORDER BY P.meno";
    $result1 = mysql_query($sql, $link);
    while ($row = mysql_fetch_assoc($result1)) {
    
      $sql2 = "SELECT COUNT(*)
               FROM forum_priatelia 
               WHERE moje_id=".$_SESSION['id']." AND tvoje_id=".$row['id']; 
      $je_priatel=mysql_result(mysql_query($sql2),0); //echo $je_priatel;
    
      echo '<table class="pouzivatel_'.$row['sex'].'">
              <tr>
                <td class="pouz_foto">
                  <img src="obrazky/users/'.$row['foto'].'" alt="nophoto" width="60"/>
                </td>
                <td class="pouz_info">
                  <a href="profil.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz">'.$row['nick'].'</a><br/>'
                  .$row['meno'].'<br/>'
                  .$row['nar'].'<br/>
                  <a href="home.php?f='.$row['id'].'" class="odkaz_4">'.$row['nazov_fora'].'</a><br/><br/>';
                  if ($je_priatel==0) { 
                    echo '<a href="priatel_pridaj.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz_4">Pridaj</a> priateľa';
                  }
                  else {
                    echo '<a href="priatel_odober.php?f='.$_GET['f'].'&pr='.$row['id'].'" class="odkaz_4">Odober</a> priateľa';
                  }                
       echo    '</td>
              </tr>
            </table>';
    }
  }
}

function edit($profil,$edit){   /*FUNKCIA NA UPRAVU JEDNOTLIVYCH ZLOZIEK PROFILU*/
  if ($profil==$_SESSION['id']) {
    if (isset($_GET['e']) && $_GET['e']==$edit) { 
      ?>
        <td class="profil_2">
          <form action="<?php echo 'profil.php?f='.$_GET['f'].'&pr='.$_GET['pr'].'&u='.$edit; ?>" method="post" name="form"> 
            <input name="edit" type="text" value="<?php echo $_SESSION[$edit]; ?>" class="formular1"/>
        </td>
        <td class="profil_3">
            <input type="submit" name="uprav" class="formular_submit" value="Edit" />
          </form>
        </td> <?php
      
    }
    else {
      echo '<td class="profil_2">'.$_SESSION[$edit].'</td>';
      echo '<td class="profil_3">
              <a href="profil.php?f='.$_GET['f'].'&pr='.$_GET['pr'].'&e='.$edit.'" class="odkaz" alt="edit">edit</a>
            </td>';
    }
  }
  else  {
    if ($link = spoj_s_db()) {
      $sql = "SELECT * FROM forum_pouzivatelia WHERE id=$profil";
      $result1 = mysql_query($sql, $link);
      while ($row = mysql_fetch_assoc($result1)) {
        echo '<td colspan="2" class="profil_2">'.$row[$edit].'</td>';
      }
    }
  }
}

function foto($profil) {
  if ($link = spoj_s_db()) {
      $sql = "SELECT * FROM forum_pouzivatelia WHERE id=$profil";
      $result1 = mysql_query($sql, $link);
      while ($row = mysql_fetch_assoc($result1)) {
        echo $row['foto'];
      }
    }
}

function bbcode($data) {
  if ($link = spoj_s_db()) {
    $sql = "SELECT * FROM forum_bbcode";
    $result = mysql_query($sql);
      if (mysql_num_rows($result)>0) {
        while ($row = mysql_fetch_array($result)) {
          $kod_bb['tpl'][] = "/" . html_entity_decode($row['template'], ENT_QUOTES, "UTF-8") . "/i";
          $kod_bb['rep'][] = html_entity_decode($row['replacement'], ENT_QUOTES, "UTF-8");
          $data1 = preg_replace($kod_bb['tpl'],$kod_bb['rep'],$data);
          $pocet = 1;
          while (($data1 != $data) && ($pocet < 4)) {
            $pocet++;
            $data = $data1;
            $data1 = preg_replace($kod_bb['tpl'],$kod_bb['rep'],$data);
          }
        }
        return $data;
      }
  }
}

?>
