Location: PHPKode > projects > Bradabra > bradabra/home.php
<?php
//****************************************************************************
//
// Copyright (C) 2001 Eric SEIGNE <hide@address.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//****************************************************************************
//
// For more informations, get to the project's main source file.
//
//****************************************************************************

$include_path = "include/";
include $include_path."includes.php";


//----------------------------------------------------------------------------
// StockAlertThresholds_Send
//----------------------------------------------------------------------------
function StockAlertThresholds_Send ($text)
{
  $n = count($GLOBALS["config_mails_alertthresholds"]);
  for($i=0 ; $i<$n ; $i++)
    SendEMail($GLOBALS["config_mails_alertthresholds"][$i], "", $text);
}

//----------------------------------------------------------------------------
// StockAlertThresholds_Show
//----------------------------------------------------------------------------
function StockAlertThresholds_Show ()
{
  global $lang;

  $col_row = COL_LISTROW1;
  $text = "";
  $text_mail = "";
  $status_msg = "";

  $text .=
    "  <tr>\n".
    "    <td>\n".
    "      <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n";

  // get items table content
  $rows_items = DB_Select(DBTN_ITEM, "*", "WHERE (alert_threshold > 0) AND (quantity <= alert_threshold) ORDER BY ref");
  if(!$rows_items) // nothing ? so we don't care ! return.
    return;

  // get items table informations
  $cols_names = DB_GetColNames(DBTN_ITEM);
  $cols_types = DB_GetColTypes(DBTN_ITEM);
  $cols_captions = DB_GetColCaptions(DBTN_ITEM);
  $n = count($rows_items);
  $n_cols = DB_GetColNbr(DBTN_ITEM);

  // mail text
  $text_mail .=
    "Subject : ".$lang["Stock's alert thresholds"]."\n".
    "Number of alerts : ".$n."\n".
    "\n".
    "\n".
    "-- Items descriptions --\n";

  // table header
  $text .=
    "        <tr bgcolor=\"".COL_LISTHEADER."\">\n".
    "          <td align=\"left\"><b>".$lang[$cols_captions["ref"]]."&nbsp;</b></td>\n".
    "          <td align=\"left\"><b>".$lang[$cols_captions["quantity"]]."&nbsp;</b></td>\n".
    "          <td align=\"left\"><b>".$lang[$cols_captions["alert_threshold"]]."&nbsp;</b></td>\n".
    "        </tr>\n";

  // table content
  for($i=0 ; $i<$n ; $i++)
  {
    // get category title
    $rows_itemcat = DB_Select(DBTN_ITEMCATEGORY, "description", "WHERE id='".$rows_items[$i]["category"]."'");
    if(!$rows_itemcat)
      $rows_itemcat = "Error !";

    // let the reference to be a link to the modif_form
    $rows_items[$i]["ref"] = trim($rows_items[$i]["ref"]);
    if($rows_items[$i]["ref"] == "")
      $rows_items[$i]["ref"] = "-";
    $rows_items[$i]["ref"] = "<a href=\"javascript:PopupItem('modify', ".$rows_items[$i]["id"].")\">".$rows_items[$i]["ref"]."</a>";

    // line content
    $text .=
      "        <tr bgcolor=\"".$col_row."\">\n".
      "          <td align=\"left\" valign=\"top\">".$rows_items[$i]["ref"]."&nbsp;</b></font></td>\n".
      "          <td align=\"left\" valign=\"top\"><font color=\"".COL_HARDTEXT."\"><b>".$rows_items[$i]["quantity"]."&nbsp;</b></font></td>\n".
      "          <td align=\"left\" valign=\"top\">".$rows_items[$i]["alert_threshold"]."&nbsp;</td>\n".
      "        </tr>\n";

    // mail text
    $text_mail .=
      "Reference : ".$rows_items[$i]["ref"]."\n".
      "Quantity : ".$rows_items[$i]["quantity"]."\n".
      "Alert threshold : ".$rows_items[$i]["alert_threshold"]."\n".
      "\n";

    // color
    $col_row = InvertListRowColor($col_row);
  }

  $text_mail .=
    "\n".
    "--\n".
    "This mail was sent by the ".PROG_NAME." robot.\n".
    PROG_WEB."\n";

  $text .=
    "      </table>\n".
    "    </td>\n".
    "  </tr>\n";

  // print content
  print("<center>\n");
  Style_TypicalTableHeader($lang["Stock's alert thresholds"], "");
  print($text);
  Style_TypicalTableBottom();
  print("</center>\n");

  // send alert mail(s)
  //StockAlertThresholds_Send($text_mail);
}

//----------------------------------------------------------------------------
// MAIN
//----------------------------------------------------------------------------
HTML_Header(PROG_TITLE, "", "", "", "", "", "");
IncludeJS(
  $js_OpenPopupWindow.
  $js_PopupItem);
MenuBar();
print(
  "<br>\n".
  "<center><img src=\"".DIR_IMAGES."/".IMG_PROGLOGO."\" border=\"0\" alt=\"".PROG_NAME."\"></center>\n".
  "<br>\n".
  "<br>\n");
StockAlertThresholds_Show();
FooterBar();
HTML_Bottom();
?>
Return current item: Bradabra