<?php
# ID: 21
# callacc_edit_filtetr_module ver.1.2
# last modification 19.4.2010
# Formulář pro vytváření volacích účtů
#
  
if (!IsSet($_POST['idTECHNOLOGY'])){ 
    $query="SELECT table_name
            FROM technology
          WHERE idTECHNOLOGY=1";
    $result = mysql_query($query);        
    if (!$result) {
        die('Problém s načtením technologie :' . mysql_error());
    }
    list($table)=mysql_fetch_row($result);
    $idTECHNOLOGY=1;
}else{
    $query="SELECT table_name
            FROM technology
            WHERE idTECHNOLOGY=".$_POST['idTECHNOLOGY']."";
    $result = mysql_query($query);        
    if (!$result) {
        die('Problém s načtením technologie :' . mysql_error());
    }
    list($table)=mysql_fetch_row($result);
    $idTECHNOLOGY=$_POST['idTECHNOLOGY'];
}        
        
        
$query="SELECT TAB.id,TAB.name,TAB.context,U.login
        FROM ".$table." TAB
        LEFT JOIN user_account UA ON UA.id=TAB.id AND idTECHNOLOGY=".$idTECHNOLOGY."
        LEFT JOIN user U ON U.idUSER=UA.idUSER   
        WHERE 1=1";
    
      
      
      
      
if(IsSet($_POST['CEF_ID']) )
      {
        $_SESSION['CEF_TEMP'][CEF_ID]= $_POST['CEF_ID'];
      }
      if ($_SESSION['CEF_TEMP'][CEF_ID]!=''){
          $query=$query." AND TAB.id=\"".$_SESSION['CEF_TEMP'][CEF_ID]."\""   ;
      }
      
      
if(IsSet($_POST['CEF_NAME']) )
      {
        $_SESSION['CEF_TEMP'][CEF_NAME]= $_POST['CEF_NAME'];
      }
      if ($_SESSION['CEF_TEMP'][CEF_NAME]!=''){
          $query=$query." AND TAB.name like \"".$_SESSION['CEF_TEMP'][CEF_NAME]."%\""   ;
      }
      
if(IsSet($_POST['CEF_KONTEXT']) )
      {
        $_SESSION['CEF_TEMP'][CEF_KONTEXT]= $_POST['CEF_KONTEXT'];
      }
      if ($_SESSION['CEF_TEMP'][CEF_KONTEXT]!=''){
          $query=$query." AND TAB.context like \"".$_SESSION['CEF_TEMP'][CEF_KONTEXT]."%\""   ;
          
          
      }
if(IsSet($_POST['CEF_USEROWN']) )
      {
        $_SESSION['CEF_TEMP'][CEF_USEROWN]= $_POST['CEF_USEROWN'];
      }
        
if(IsSet($_POST['CEF_ASSIGNED']) || IsSet($_GET['CEF_ASSIGNED']) )
      {
        $_SESSION['CEF_TEMP'][CEF_ASSIGNED]= $_POST['CEF_ASSIGNED'];
      }
      else $_SESSION['CEF_TEMP'][CEF_ASSIGNED]=0;
      if ($_SESSION['CEF_TEMP'][CEF_ASSIGNED]!=''){
          $query=$query." AND U.login like \"".$_SESSION['CEF_TEMP'][CEF_USEROWN]."%\""   ;
      }
       $query.=" ORDER BY TAB.name ASC";
      ##########################################################################
      #zjisteni poctu stran
        $itemperpage=15;
        $result = mysql_query($query);
        $remainder= (mysql_num_rows($result) % $itemperpage);
        $pages=(mysql_num_rows($result)-$remainder)/$itemperpage ;
        if(IsSet($_GET['PAGE']))
        {
          $query=$query." LIMIT ".($_GET['PAGE']*$itemperpage).",".$itemperpage.""   ;
        
        }
        else
        {
          $query=$query." LIMIT ".(0*$itemperpage).",".$itemperpage.""  ;
        }
      
        $result = mysql_query($query);
        if (!$result) {
            die('Could not query:' . mysql_error());
        }    
      #kod pro vypocet počtu stran
        if ($remainder!=0) $pages++;


?>
<script language="JavaScript">
  
  function RefreshForm(theForm){
      document.forms.form1.submit();
  
  } 
</script>
<center>
<div class="forms">
<h3>Účty Asterisk</h3>
 <div class="userlist">
<fieldset>
  <legend>Filtr</legend>
  <form name="form1" action="admin_page.php" method="post">
        <table align="center">
          <tr>
             <td class="tableculombhead" colspan=4 style="text-align:left;">
                    <?php
                    for ($i=0 ;$i!=$pages;$i++) {
                  if ($i==$_GET['PAGE'])
                  {
                      $styl="<span class=\"pagelistselected\">";
                  }else{
                      $styl="<span class=\"pagelist\">";
                  }
                  echo $styl;
                  unset ($styl);
                      
                      echo ("<a href=\"".selfURL()."?CEF_ASSIGNED=".$_SESSION['CEF_TEMP'][CEF_ASSIGNED]."&PAGE=".$i."\">".($i+1)." </a>");
                      echo "</span>";   
                
            }
                  ?>
             </td>
             <td class="tableculombhead">Přiřazen uživateli<input type="checkbox" onChange="RefreshForm()" <?php if ($_SESSION['CEF_TEMP'][CEF_ASSIGNED]==1) echo "checked"; ?> name="CEF_ASSIGNED" value="1"</td>
          </tr><tr>
             <td class="tablehead" colspan=2>Hledání v technologii:</td><td class="tableculombhead" colspan=3 style="text-align:left">
                                        <select name="CEF_TECH" onChange="RefreshForm()">
                                          <?php
                                              include "build/db_connect.inc.php"  ;
                                              $subquery="SELECT idTECHNOLOGY,technology
                                                      FROM technology
                                                      WHERE validity=1 
                                                      ORDER BY technology ";                                                    
                                              $subresult = mysql_query($subquery);        
                                              if (!$subresult) {
                                                die('Problém s načtením technologie :' . mysql_error());
                                              }
                                              while (list($idtechnology, $technology ) = mysql_fetch_row($subresult)){
                                              #podmínka pro nastavení defaultní hodnoty skupiny na User
                                                    if ($_GET['CEF_TECH']==$idtechnology){
                                                        echo("<option value=\"".$idtechnology."\" selected>".$technology."</option>"); 
                                                    }else{
                                                        echo("<option value=\"".$idtechnology."\">".$technology."</option>");
                                                    }
                                              }         
                                          ?>
                                        </select>
                                            </td>
                                           
          </tr><tr>
             <td class="tablehead"></td>
             <td class="tablehead">ID </td>
             <td class="tablehead">Název </td>
             <td class="tablehead">Kontext </td>
             <td class="tablehead">Patří uživateli(login)</td>
          </tr><tr>
             <td class="tablehead"></td>
             <td class="tableculombhead"><input type="text" size=2 name="CEF_ID" onBlur="RefreshForm()" value="<?php echo($_SESSION['CEF_TEMP'][CEF_ID]);?>"></td>
             <td class="tableculombhead"><input type="text" size=8 name="CEF_NAME" onBlur="RefreshForm()" value="<?php echo($_SESSION['CEF_TEMP'][CEF_NAME]);?>"></td>
            <td class="tableculombhead"><input type="text" size=8 name="CEF_KONTEXT" onBlur="RefreshForm()" value="<?php echo($_SESSION['CEF_TEMP'][CEF_KONTEXT]);?>"></td> 
            <td class="tableculombhead"><input type="text" size=8 onBlur="RefreshForm()"  <?php if ($_POST['CEF_ASSIGNED']!=1) echo "disabled"; ?> name="CEF_USEROWN" value="<?php if ($_POST['CEF_ASSIGNED']!=1){echo "";}else{echo($_SESSION['CEF_TEMP'][CEF_USEROWN]);}?>"></td>
          </tr><tr>
            <input type="hidden" name="CEF_SUBMITED" value="TRUE">
            
          </tr><tr>
            
          </tr><tr>
            <input type="hidden" name="NEXTFORM" value="21">
          </tr>
      
  </form>

  <?php
              while (list($id,$name,$kontext,$iduser) = mysql_fetch_row($result)){
              #Stridani barev řádků tabulky
              if($a==1){$a=0; $barva="white";}else{$a=1;$barva="lightgrey"; }
              #####################################################################
              echo "<tr bgcolor=$barva>";
              if ($iduser=='') $iduser="N/A"  ;
              if ($kontext=='') $iduser="N/A"  ;
              echo "<td><a href=\"".selfURL()."?NEXTFORM=22&PARENT=".$_SESSION['ACTUALFORM']."&idCALLACC=".$id."&idTECHNOLOGY=".$idTECHNOLOGY."\"><img src=\"files/pictures/vyber.gif\"></a></td><td>".$id."</td><td>".$name."</td><td>".$kontext."</td><td>".$iduser."</td>";
              echo "</tr>";
          }
      
      
      echo "</table>";
     
  


  
  
  ?>
</fieldset>
</div>
</div>
</center>

