function action_new() { PermissionHelper::Verification('Editor'); $name = $_POST['inputName']; $price = $_POST['inputPrice']; $Description = $_POST['inputDescription']; $names = explode(',', $_POST['names']); $values = explode(',', $_POST['values']); $catalog = $_POST['catalog']; $product = new Product(); $product->name = $name; $product->price = $price; $product->catalogue_id = CatalogueService::GetByName($catalog)->catalogue_id; $product->description = $Description; ProductService::Create($product); $product_id = ProductService::GetByName($name)->product_id; for ($i = 0; $i < count($names); $i++) { $attribute = AttributeService::GetByName($names[$i]); if ($attribute->type == 1) { $attributeFloat = new AttributeValueFloat(); $attributeFloat->attribute_id = $attribute->attribute_id; $attributeFloat->product_id = $product_id; $attributeFloat->value = $values[$i]; AttributeValueFloatService::Create($attributeFloat); } else { $attributeList = new AttributeValueList(); $attributeList->product_id = $product_id; $attributeList->attribute_id = $attribute->attribute_id; $attributeList->value = AttributeListService::GetByAttributeIdAndName($attribute->attribute_id, $values[$i])->attributelist_id; AttributeValueListService::Create($attributeList); } } $fr = fopen($_FILES['file-0']['tmp_name'], 'r'); $fw = fopen(__ROOT__ . '/images/items/item_' . $product_id . '.jpg', "w"); while (!feof($fr)) { $buff = fread($fr, 1000); fwrite($fw, $buff); } fclose($fr); fclose($fw); header("Location: /Product/itemAdmin"); }