rendered paste body<?php
// Start session
session_start();
// Includes
require_once('../../../includes/config.inc.php');
require_once($sitePath.'/classes/session/session.class.php');
require_once($sitePath.'/classes/db/database.class.php');
require_once($sitePath.'/classes/system/system.class.php');
require_once($sitePath.'/classes/authentication/authentication.class.php');
require_once($sitePath.'/classes/ecommerce/catalogue.class.php');
// Objects without db
$db = new Database($dbConfig);
$session = new MySession($sessionConfig);
// Connect db
if (!$db->connect()) {
echo "Unable connect to database.";
die();
}
// Object with db
$system = new System($db, $session);
$auth = new Authentication($session, $db);
$catalogue = new Catalogue($db, $catalogueConfig);
// Check if user is logged
if (!$auth->isLogged()) {
header("Location: $siteUrl/amministrazione/index.php");
exit();
}
$system->setLanguage($defaultLanguage);
$itemTranslator['itemName']['it'] = "";
$itemTranslator['itemName']['en'] = "";
$itemTranslator['itemName']['fr'] = "";
$itemTranslator['itemDescription']['it'] = "";
$itemTranslator['itemDescription']['en'] = "";
$itemTranslator['itemDescription']['fr'] = "";
$itemSizeS = false;
$itemSizeM = false;
$itemSizeL = false;
$itemSizeXL = false;
$itemSizeXXL = false;
$itemPrice = "";
$itemImage['name'][0] = "";
$itemImage['name'][1] = "";
$parentCategory = 0;
$error = "";
if (isset($_POST['itemNameIt'])) {
$itemTranslator['itemName']['it'] = $system->validateString($_POST['itemNameIt']);
}
if (isset($_POST['itemNameEn'])) {
$itemTranslator['itemName']['en'] = $system->validateString($_POST['itemNameEn']);
}
if (isset($_POST['itemNameFr'])) {
$itemTranslator['itemName']['fr'] = $system->validateString($_POST['itemNameFr']);
}
if (isset($_POST['itemDescriptionIt'])) {
$itemTranslator['itemDescription']['it'] = $system->validateString($_POST['itemDescriptionIt']);
}
if (isset($_POST['itemNameEn'])) {
$itemTranslator['itemDescription']['en'] = $system->validateString($_POST['itemDescriptionEn']);
}
if (isset($_POST['itemNameFr'])) {
$itemTranslator['itemDescription']['fr'] = $system->validateString($_POST['itemDescriptionFr']);
}
if (isset($_POST['itemSize'])) {
$itemSizeArray = $_POST['itemSize'];
for ($i=0; $i < count($itemSizeArray); $i++) {
switch($itemSizeArray[$i]) {
case "s":
$itemSizeS = true;
break;
case "m":
$itemSizeM = true;
break;
case "l":
$itemSizeL = true;
break;
case "xl":
$itemSizeXL = true;
break;
case "xxl":
$itemSizeXXL = true;
break;
}
}
/*
for ($i=0; $i < count($itemSizeArray); $i++) {
switch($itemSizeArray[$i]) {
case "s":
$itemSizeS = true;
break;
case "m":
$itemSizeM = true;
break;
case "l":
$itemSizeL = true;
break;
case "xl":
$itemSizeXL = true;
break;
case "xxl":
$itemSizeXXL = true;
break;
}
}
*/
}
if (isset($_POST['itemPrice'])) {
$itemPrice = (float)$_POST['itemPrice'];
}
if (isset($_POST['parentCategory'])) {
$parentCategory = $_POST['parentCategory'];
}
if (isset($_FILES['file'])) {
$itemImage = $_FILES['file'];
}
$categoryArray = $catalogue->getCategorySelectArray(false, "it", false);
$categorySelect = $system->makeFormSelect("parentCategory",$categoryArray, $parentCategory);
if (count($_POST)>0 && ($itemTranslator['itemName']['it'] == "" || $itemTranslator['itemName']['en'] == "" || $itemTranslator['itemName']['fr'] == "" || $itemPrice == "" || $itemTranslator['itemDescription']['it'] == "" || $itemTranslator['itemDescription']['en'] == "" || $itemTranslator['itemDescription']['fr'] == "" || $itemImage['name'][0] == "" || $itemImage['name'][1] == "")) {
$error = "Tutti i campi sono obbligatori<br>";
}
if (count($_POST)>0 && $parentCategory == 0) {
$error .= "Manca una categoria a cui aggiungere il prodotto";
}
if (count($_POST)>0 && $error == "") {
$catalogue->addItem($itemTranslator, $parentCategory, $itemPrice, $itemImage);
header("Location: $siteUrl/amministrazione/catalogue/index.php");
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php echo $siteTitle; ?> Amministrazione</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- css -->
<style type="text/css">
@import url("<?php echo $siteUrl; ?>/includes/css/admin.css");
body {
margin-top: 0px;
}
</style>
<script src="<?php echo $siteUrl; ?>/includes/js/helpWindow.js" type="text/javascript"></script>
</head>
<body>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" class="container">
<tr>
<td><table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- Header BEGINNING -->
<td><?php include($sitePath.'/amministrazione/header.php'); ?></td>
<!-- Header END -->
</tr>
<tr>
<!-- Center BEGINNING -->
<td><p>PRODOTTO - aggiungi </p>
<form action="<?php echo $siteUrl;?>/amministrazione/catalogue/item/add.php" method="post" enctype="multipart/form-data" name="addCategory">
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">Nome prodotto<a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/name.php');">?</a></td>
</tr>
<tr>
<td width="22">it</td>
<td width="738" height="30"><input name="itemNameIt" type="text" size="40" value="<?php echo $itemTranslator['itemName']['it']; ?>"></td>
</tr>
<tr>
<td>en</td>
<td height="30"><input name="itemNameEn" type="text" size="40" value="<?php echo $itemTranslator['itemName']['en']; ?>"></td>
</tr>
<tr>
<td>fr</td>
<td height="30"><input name="itemNameFr" type="text" size="40" value="<?php echo $itemTranslator['itemName']['fr']; ?>"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Categoria genitore <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/parent.php');">?</a></td>
</tr>
<tr>
<td colspan="2"><?php echo $categorySelect; ?> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Descrizione prodotto <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/name.php');">?</a></td>
</tr>
<tr>
<td width="22" valign="top">it</td>
<td width="738" height="155" valign="top"><textarea name="itemDescriptionIt" cols="40" rows="8"><?php echo $itemTranslator['itemDescription']['it']; ?></textarea></td>
</tr>
<tr>
<td valign="top">en</td>
<td height="155" valign="top"><textarea name="itemDescriptionEn" cols="40" rows="8"><?php echo $itemTranslator['itemDescription']['en']; ?></textarea></td>
</tr>
<tr>
<td valign="top">fr</td>
<td height="155" valign="top"><textarea name="itemDescriptionFr" cols="40" rows="8"><?php echo $itemTranslator['itemDescription']['fr']; ?></textarea></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Prezzo <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/parent.php');">?</a></td>
</tr>
<tr>
<td colspan="2"><input type="text" name="itemPrice" value="<?php echo $itemPrice; ?>"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Immagine davanti <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/parent.php');">?</a></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="file[]"></td>
</tr>
<tr>
<td colspan="2">Immagine dietro <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/parent.php');">?</a></td>
</tr>
<tr>
<td colspan="2"><input type="file" name="file[]"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2">Taglie disponibili <a href="javascript:helpWindow('<?php echo $siteUrl; ?>/amministrazione/catalogue/category/help/parent.php');">?</a></td>
</tr>
<tr>
<td colspan="2"><input name="itemSize[]" type="checkbox" value="s" <?php if ($itemSizeS) { echo "checked"; } ?>>S <input name="itemSize[]" type="checkbox" value="m" <?php if ($itemSizeM) { echo "checked"; } ?>>M <input name="itemSize[]" type="checkbox" value="l" <?php if ($itemSizeL) { echo "checked"; } ?>>L <input name="itemSize[]" type="checkbox" value="xl" <?php if ($itemSizeXL) { echo "checked"; } ?>>XL <input name="itemSize[]" type="checkbox" value="xxl" <?php if ($itemSizeXXL) { echo "checked"; } ?>>XXL</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Aggiungi"></td>
</tr>
</table>
</form><p><br>
</p>
<?php
if ($error != "") {
echo "<p>$error</p>";
}
?>
</td>
<!-- Center END -->
</tr>
<tr>
<!-- Footer BEGINNING-->
<td> </td>
<!-- Footer END -->
</tr>
</table></td>
</tr>
</table>
</body>
</html>