Location: PHPKode > projects > RepMan > repman/inc/cljous.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title>Mailing list</title>
  <link rel="stylesheet" href="sc/style.css" type="text/css">
</head>
<body>

<div id="menu">
  <?
    require ('inc/menu.php');
  ?>
</div>
<br>
<h1>Mailing list</h1>

<?
  ConnectIt();
  $view = 1;
  $us_id = 0;
  if ($udata=Query("SELECT name,email,id FROM user;")) {
    // *********** zpracovani ***********
    if (isset($_GET["add"]) && isLoggedIn()) {
      if (isset($_GET["user"])) {
        $jm_ok = 0;
        $user=strtolower($_GET["user"]);
        foreach ($udata as $ulist) {
        	if ($user==$ulist[0]) {
            $jm_ok = 1;
            $us_id = $ulist[2];
          }
        }
        if ($jm_ok) {
          $view = 0;
?>
  <form action="mailing.php" method="post" accept="text/html" class="frm">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="usid" value="<? echo $us_id; ?>">
    
    <div class="item">
      <label for="user">User:     </label>
      <input type="text" name="user" readonly="readonly" class="ro_input" value="<? echo $user; ?>"><br>
    </div>
      
    <div class="item">
      <label for="client">Client:   </label>
      <select name="client" size="1">
        <option value="0">&lt;Every&gt;</option>
        <?
          if ($clodata = Query("SELECT * FROM client ORDER BY name;")) {
            foreach ($clodata as $clolist) {
              echo "\n        <option value=\"$clolist[0]\">$clolist[1]</option>";
            }
          }
        ?>
      </select>
    </div>
      
    <div class="item">
      <label for="jobt">Job-type: </label>
      <select name="jobt" size="1">
        <option value="0">&lt;Anything&gt;</option>
        <?
          if ($joodata = Query("SELECT * FROM job ORDER BY job;")) {
            foreach ($joodata as $joolist) {
              echo "\n        <option value=\"$joolist[0]\">$joolist[1]</option>";
            }
          }
        ?>
      </select>
    </div>
    
    <input type="submit" value="Send" class="item">

  </form>
<?        
        }
      }
    } elseif (isset($_GET["del"]) && isLoggedIn()) {                                 // deeeeeeeeleeeeeeeeeeeeeeeeteeeeeeeeeeeeeeeeee
    
      $delwhat = split("\.", $_GET["del"]);  // rozdeli parametr ss mezi teckama do pole
      if (count($delwhat) == 3) {
        $delwhat[0] += 0;   // bezpecnostni opatreni
        $delwhat[1] += 0;
        $delwhat[2] += 0;
        
        $us_ok = 0;
        foreach (Query("SELECT id FROM user;") as $us) {      // test existence uzivatele
          if ($us[0] == $delwhat[0]) { $us_ok = 1;}
        }
        
        if ($delwhat[1]!= 0) {
          $cl_ok = 0;
          foreach (Query("SELECT id FROM client;") as $cl) {    // test existence klienta
            if ($cl[0] == $delwhat[1]) { $cl_ok = 1;}
          }
        } else {
          $cl_ok = 1;
        }
        
        if ($delwhat[2]!= 0) {
          $jo_ok = 0;
          foreach (Query("SELECT id FROM job;") as $jo) {       // test existence jobu
            if ($jo[0] == $delwhat[2]) { $jo_ok = 1;}
          }
        } else {
          $jo_ok = 1;
        }
        
        
        echo "<div class=\"info\"><p>";        // zpracovani smazani. ano ci ne?
        if ($cl_ok && $jo_ok && $us_ok) {
          if (Query("SELECT * FROM mailing WHERE us_id=".$delwhat[0]." AND cl_id=".$delwhat[1]." AND jo_id=".$delwhat[2].";")) {
            if(Query("DELETE FROM mailing WHERE us_id=".$delwhat[0]." AND cl_id=".$delwhat[1]." AND jo_id=".$delwhat[2].";")) {   // vlozeni session
              echo "Record us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." was succefully removed.\n";
              logdebug("Zaznam mailing us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." uspesne z tabulky mailing smazan.");
            } else {
              echo "Record us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." can not be removed.\n";                    // oznam prip. neuspech
              logdebug("Zaznam us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." nelze odstranit.");
            }
          } else {
            echo "Record us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." from table mailing doesn't exist!\n";
            logdebug("Zaznam us_id=".$delwhat[0].",cl_id=".$delwhat[1].",jo_id=".$delwhat[2]." nebyl v tabulce mailing nalezen.");
          }
        } else {
          if (!$us_ok) {
            echo "User us_id=".$delwhat[0]." doesn't exist.\n";       // oznam nesouhlas uzivatele
            logdebug("Zadany uzivatel us_id=".$delwhat[0]." neexistuje.");
          }
          if (!$cl_ok) {
            echo "Client cl_id=".$delwhat[1]." doesn't exist.\n";       // oznam nesouhlas klienta
            logdebug("Zadany klient cl_id=".$delwhat[1]." neexistuje.");
          }
          if (!$jo_ok) {
            echo "Job jo_id=".$delwhat[2]." doesn't exist.\n";       // oznam nesouhlas jobu
            logdebug("Zadany job jo_id=".$delwhat[2]." neexistuje.");
          }
        }
        echo "<p></div>\n";
      } else {
        echo "<div class=\"info\"><p>Count of parameters is not valid.</p></div>\n";      // oznam nesouhlas parametru
        logdebug("Count of parameters for deleting item from mailing list is not valid. Pocet == ".count($delwhat));
      }
    
    
    } else {

      // ---- zpracovani noveho zaznamu ----
      if (isset($_POST["add"]) && $_POST["add"]=="1" && isLoggedIn()) {
        if ($_POST["client"] == 0 && $_POST["jobt"] == 0) {
            echo "<div class=\"info\"><p>Can not add record with CLIENT == Every and JOB-T == Anything together.</p></div>\n";
        } elseif(isset($_GET["del"]) && !isLoggedIn()) {
            echo "<div class=\"info\"><p>For deleting mailing list items you must log in as admin.</p></div>\n";
        } else {
          if (Query("INSERT INTO mailing(us_id,cl_id,jo_id) VALUES('".$_POST["usid"]."','".$_POST["client"]."','".$_POST["jobt"]."');")) {
            echo "<div class=\"info\"><p>Successfully added user_id == ".$_POST["usid"].", client_id == ".$_POST["client"].", job-type_id == ".$_POST["jobt"].".</p></div>\n";
          }
        }
      }
    }
    if ($view) {
?>

<div id="vision">

<?   
      
      // *********** vypis *************
      echo "<ul style=\"padding-left: 0px;\">\n";
      foreach ($udata as $ulist) {
      	echo "  <li class=\"li_head\"><b>".$ulist[0]."&nbsp;($ulist[1])</b><br>&nbsp;&nbsp;&nbsp;<small>\n";
      	  echo "All";    // pocet vsech
      	  if ($ucdata=Query("SELECT mailing.us_id FROM mailing LEFT JOIN(user) ON(user.id=mailing.us_id) WHERE user.name='".$ulist[0]."';")) {
            echo "(".count($ucdata).")&nbsp;";
          } else {
            echo "(0)&nbsp;";
          }
          echo "Specific"; // pocet konkretizovanych
          if ($adata=Query("SELECT client.name,job.job,client.id,job.id FROM mailing LEFT JOIN(client,job,user) ON(client.id=mailing.cl_id AND job.id=mailing.jo_id AND user.id=mailing.us_id) WHERE user.name='".$ulist[0]."' AND mailing.cl_id<>0 AND mailing.jo_id<>0 ORDER BY client.name;")) {
            echo "(".count($adata).")&nbsp;";
          } else {
            echo "(0)&nbsp;";
          }
          echo "Clients"; // pocet konkretizovanych
          if ($cdata=Query("SELECT client.name,client.id FROM mailing LEFT JOIN(client,user) ON(client.id=mailing.cl_id AND user.id=mailing.us_id) WHERE mailing.jo_id=0 AND user.name='".$ulist[0]."' ORDER BY client.name;")) {
            echo "(".count($cdata).")&nbsp;";
          } else {
            echo "(0)&nbsp;";
          }
          echo "Job-types"; // pocet konkretizovanych
          if ($jdata=Query("SELECT job.job,job.id FROM mailing LEFT JOIN(user,job) ON(user.id=mailing.us_id AND job.id=mailing.jo_id) WHERE mailing.cl_id=0 AND user.name='".$ulist[0]."' ORDER BY job.job;")) {
            echo "(".count($jdata).")&nbsp;";
          } else {
            echo "(0)&nbsp;";
          }
          echo "</small></li>\n<li style=\"background-color: #FFFFFF; list-style: none;\"></li>";
          
          // konkretni klient a job
          if ($adata) {
            echo "<ul class=\"no_dec\">\n";
            foreach ($adata as $alist) {
              echo "<li>".sayifadmin("<a href=\"?del=".$ulist[2].".".$alist[2].".".$alist[3]."\" title=\"Remove\">-</a>&nbsp;&nbsp;",0)."$alist[0]&nbsp;&nbsp;$alist[1]</li>\n";
            }
            echo "</ul>\n";        
          }
          
          // vse na klientu
          if ($cdata) {
            echo "<ul class=\"no_dec\">\n";
            foreach ($cdata as $clist) {
              echo "<li>".sayifadmin("<a href=\"?del=".$ulist[2].".".$clist[1].".0\" title=\"Remove\">-</a>&nbsp;&nbsp;",0)."$clist[0]&nbsp;&nbsp;<span class=\"not_imp\">Anything</span></li>\n";
            }
            echo "</ul>\n";        
          }
          
          // kazdy vyskyt jobu
          if ($jdata) {
            echo "<ul class=\"no_dec\">\n";
            foreach ($jdata as $jlist) {
              echo "<li>".sayifadmin("<a href=\"?del=".$ulist[2].".0.".$jlist[1]."\" title=\"Remove\">-</a>&nbsp;&nbsp;",0)."<span class=\"not_imp\">Every</span>&nbsp;&nbsp;$jlist[0]</li>\n";
            }
            echo "</ul>\n";        
          }
          
          echo sayifadmin("<ul class=\"no_dec\"><li>&nbsp;&nbsp;&nbsp;<a href=\"mailing.php?add=1&user=".$ulist[0]."\" title=\"Add new\">+</a></li></ul>\n",0);
      }
      echo "</ul>\n";
    }
  } else {
    if (isLoggedIn()) {
      echo "<div class=\"info\"><p>No users. For adding records there, you must <a href=\"users.php?new=1\">add new user</a> first.</p></div><br>\n";
    } else {
      echo "<div class=\"info\"><p>No users. For adding records there, you must add new user first.<br>\nIf you want to this you must <a href=\"?admin=1\" title=\"Log in as administrator\">log in as Repman's administrator</a>.</p></div><br>\n";
    }
  }
?>
</div>
</body>
</html>
Return current item: RepMan