function import($frm) { /* @var $frm cForm */ if ($frm->validate("import")) { return view($frm); } /* get field indexes */ $stkcod = false; $price = false; foreach ($_REQUEST["fld"] as $fi => $ft) { if ($ft != "ignore") { ${$ft} = $fi; } } /* import file if all field types specified */ if ($stkcod === false || $price === false) { $frm->setmsg("<li class='err'>Not all field types satisfied</li>"); } else { $qry = new dbSelect("spricelist", "exten", grp(m("cols", "listid"), m("where", "suppid='{$_REQUEST['supid']}'"))); $qry->run(); if ($qry->num_rows() <= 0) { $suppinfo = qrySupplier($_REQUEST["supid"]); $cols = grp(m("suppid", $_REQUEST["supid"]), m("listname", $suppinfo["supname"]), m("div", USER_DIV)); $upd = new dbUpdate("spricelist", "exten", $cols); $upd->run(DB_INSERT); $listid = $upd->lastid("listid"); } else { $listid = $qry->fetch_result(); } $upd = new dbDelete("splist_prices", "exten", "listid='{$listid}'"); $upd->run(); $upd = new dbUpdate("splist_prices", "exten"); $invalid_fields = array(); $nosuch_fields = array(); $file = ucfs::file("supplist"); foreach ($file as $rd) { $ri = explode(",", $rd); $ri[$stkcod] = trim($ri[$stkcod]); $ri[$price] = trim($ri[$price]); if (cForm::validateValue($ri[$stkcod], "string", 1, 250) || cForm::validateValue($ri[$price], "float", 1, 40)) { $invalid_fields[] = $ri[$stkcod]; continue; } $stkid = suppStkid($_REQUEST["supid"], $ri[$stkcod]); if ($stkid === false) { $stkinfo = array("stkid" => "0", "catid" => "0", "prdcls" => "0"); } else { $stkinfo = qryStock($stkid, "stkid, catid, prdcls"); } if (!isset($_REQUEST["vatinc"])) { $ri[$price] += $ri[$price] * TAX_VAT / 100; } $cols = grp(m("listid", $listid), m("stkid", $stkinfo["stkid"]), m("catid", $stkinfo["catid"]), m("clasid", $stkinfo["prdcls"]), m("price", $ri[$price]), m("div", USER_DIV), m("supstkcod", $ri[$stkcod])); $upd->setCols($cols); $upd->run(); } if (count($invalid_fields) > 0) { $msg = "<br />The following items weren't imported because they contain\n\t\t\t\tinvalid values for either the stock code or the price:<br />"; foreach ($invalid_fields as $v) { $msg .= " - {$v}<br />"; } } else { $msg = ""; } $frm->setmsg("<li class='err'>Successfully imported new pricelist.{$msg}</li>"); } return view($frm); }