Hello:
I'm building an internal messaging system for small biz companies and I
can't really go longer!!!!
Problem is, I use some fields to make the message form and one of them must
be a <select multiple form element wich refers to messaging persons. This is
my form:
<table>
<tr>
<td height="15" valign="top"><P class="P1">Para:</P></td>
<td>
<SELECT NAME=receptor[] size=6 multiple>
<?
//Legenda: eu - significa eusers || pu - significa preparar lista de
utilizadores
$eu_pu_result = mysql_query("SELECT u.name, u.email FROM users u");
while ($eu_pu = mysql_fetch_row($eu_pu_result)) {
for ($i=0;$i<1;$i++) {
echo"<option>$eu_pu[0]";
}
}
?>
</select>
</td>
</tr>
<tr>
<td height="15" valign="top"><P class="P1">Prioridade:</P></td>
<td>
<select name="priority">
<option value="M�nima">M�nima</option>
<option SELECTED value="Normal">Normal</option>
<option value="Priorit�ria">Priorit�ria</option>
<option value="Urgente">Urgente</option>
</select>
</td>
</tr>
<tr>
<td height="15" valign="top"><P class="P1">Assunto:</P></td>
<td><input type="text" name="title" size=66 value="<? pv($frm["title"])
?>"></td>
</tr>
<tr>
<td height="15" valign="top"><P class="P1">Descri��o:</P></td>
<td><textarea name="description" cols=50 rows=8><?
pv($frm["description"]) ?></textarea></td>
</tr>
<tr>
<td> <!--EmptyCellContent--></td>
<td><input type="submit" value="<?=$frm["submit_caption"] ?>"></td>
</tr>
</table>
After this, the page should reload on submit, but I keep getting the
warning:
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: 1 in c:/apache/htdocs/sites/mail/admin/eusers.php
on line 110
Warning: Undefined index: categories in
c:/apache/htdocs/sites/mail/admin/eusers.php on line 120
All but the last, I think they appear because then page reloaded can't see
any more the array of people (<select form>).
But... How can I solve the problem?
This is the file that is the page itself, as above in the warnings, called
by:"eusers.php":
<?
/***************************************************************************
***
* FUNCTIONS
****************************************************************************
*/
function print_add_product_form($category_id = 0) {
/* print a blank product form so we can add a new product */
global $mfi, $ME;
/* set default values for the reset of the fields */
$frm["categories"] = array($category_id);
$frm["newmode"] = "insert";
$frm["receptor"] = "";
$frm["recipient"] = "";
$frm["priority"] = "";
$frm["title"] = "";
$frm["description"] = "";
$frm["on_special"] = "";
$frm["submit_caption"] = "Enviar";
/* build the categories listbox options, preselect the top item */
build_category_tree($category_options, $frm["categories"]);
include("templates/eusers_form.php");
}
function print_edit_product_form($id) {
/* print a product form so we can edit the selected product */
global $mfi, $ME;
/* load up the information for the product */
$qid = db_query("
SELECT receptor, recipient, priority, title, description, stage, on_special
FROM products
WHERE id = $id
");
$frm = db_fetch_array($qid);
/* load up the categories for the product */
$qid = db_query("
SELECT category_id
FROM products_categories
WHERE product_id = $id
");
$frm["categories"] = array();
while ($cat = db_fetch_object($qid)) {
$frm["categories"][] = $cat->category_id;
}
/* set values for the form */
$frm["newmode"] = "update";
$frm["submit_caption"] = "Enviar";
/* build the categories listbox options, preselect the selected item */
build_category_tree($category_options, $frm["categories"]);
include("templates/eusers_edit_form.php");
}
function delete_product($id) {
/* delete the product specified by $id, we have to delete the product and
then
* the appropriate entries from the products_categories table. this should
be
* wrapped inside a transaction, unfortunately MySQL currently does not
support
* transactions. */
global $mfi, $ME;
/* load up the information for the product */
$qid = db_query("
SELECT title
FROM products
WHERE id = $id
");
$prod = db_fetch_object($qid);
/* delete this product */
$qid = db_query("
DELETE FROM products
WHERE id = $id
");
/* delete this product from the products_categories table */
$qid = db_query("
DELETE FROM products_categories
WHERE product_id = $id
");
include("templates/eusers_deleted.php");
}
function insert_product($id, $frm) {
/* add a new subproduct under the parent $id. all the fields that we want
are
* going to in the variable $frm */
global $mfi, $ME;
$on_special = checked($frm["on_special"]);
/* add the product into the products table */
if (!isset ($receptor[])) {
$receptor[] = "{0,0,0,0,0,0}";
} else {
}
for ($i=0;$i<6;$i++) {
$qid = db_query("
INSERT INTO products (receptor, recipient, priority, title, description,
date_added, on_special)
VALUES ('$receptor[1]', '$mfi->email', '$frm[priority]', '$frm[title]',
'$frm[description]', now(), '$on_special')
");
}
//mail('$frm[receptor]','$frm[title]','$frm[description]','$frm[recipient]')
;
/* get the product id that was just created */
$product_id = db_insert_id();
/* add this product under the specified categories */
for ($i = 0; $i < count($frm["categories"]); $i++) {
$qid = db_query("
INSERT INTO products_categories (category_id, product_id)
VALUES ('{$frm["categories"][$i]}', '$product_id')
");
}
}
function update_product($id, $frm) {
/* update the product $id with new values. all the fields that we want are
* going to in the variable $frm */
global $mfi, $ME;
checked($frm["on_special"]);
/* update the products table with the new information */
$qid = db_query("
UPDATE products SET
receptor = '$frm[receptor]'
,recipient = '$frm[recipient]'
,priority = '$frm[priority]'
,title = '$frm[title]'
,description = '$frm[description]'
,date_added = 'now()'
,on_special = '$frm[on_special]'
WHERE id = $id
");
/* delete all the categories this product was associated with */
$qid = db_query("
DELETE FROM products_categories
WHERE product_id = $id
");
/* add associations for all the categories this product belongs to, if
* no categories were selected, we will make it belong to the top
* category */
if (count($frm["categories"]) == 0) {
$frm["categories"][] = 0;
}
for ($i = 0; $i < count($frm["categories"]); $i++) {
$qid = db_query("
INSERT INTO products_categories (category_id, product_id)
VALUES ('{$frm["categories"][$i]}', '$id')
");
}
}
function print_product_list() {
/* read all the categories from the database and print them into a table.
we
* will use a template to display the listings to keep this main script
clean */
global $mfi, $ME;
$qid = db_query("
SELECT DISTINCT p.id, p.receptor, p.recipient, p.priority, p.title,
p.description, p.date_added, c.name AS category, u.name, u.email, u.username
FROM products p, products_categories pc, categories c, users u
WHERE p.id = pc.product_id AND c.id = pc.category_id AND p.receptor =
u.email AND u.username = '$mfi->suser'
");
$num_rows=mysql_num_rows($qid);
if ($num_rows == "0") {
echo"Nenhuma mensagem nesta caixa!";
} else {
include("templates/eusers_list.php");
}
}
/***************************************************************************
***
* MAIN
****************************************************************************
*/
include("../startup.php");
require_login();
if ((has_priv("clien")) || (has_priv("admin"))) {
$mfi->suser = $SESSION['user']['username'];
$mfi->email = $SESSION['user']['email'];
$DOC_TITLE = "MMS - Administra��o";
include("head_rec.php");
switch (nvl($mode)) {
case "add" :
print_add_product_form(nvl($category_id, 0));
break;
case "edit" :
print_edit_product_form($id);
break;
case "del" :
delete_product($id);
print_product_list();
break;
case "insert" :
insert_product($id, $HTTP_POST_VARS);
print_product_list();
break;
case "update" :
update_product($id, $HTTP_POST_VARS);
print_product_list();
break;
default :
print_product_list();
break;
}
include("foot_rec.php");
?>
<? } else { ?>
<? header ("Location: ../logout_now.php"); ?>
<? } ?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php