Files
bobsleighphotos.com/_old/products_enmasse.php
2017-03-02 20:30:40 -06:00

209 lines
6.0 KiB
PHP
Executable File

<?php
$event_name = 'USNationalChampionship2007';
$event_readable_name = 'National Championship 2007';
$dir = opendir("/home/users/web/b2373/pow.fti/htdocs/bobsleighphotos/images/bobsleighphotos/$event_name");
$countries = array(
'AUS' => 'Australia',
'AUT' => 'Austria',
'Awa' => 'Awards Ceremonies',
'awa' => 'Awards Ceremonies',
'BER' => 'Bermuda',
'BIG' => 'Bosnia',
'BUL' => 'Bulgaria',
'BRA' => 'Brazil',
'CAN' => 'Canada',
'CZE' => 'Czech Republic',
'FRA' => 'France',
'GER' => 'Germany',
'GBR' => 'Great Britain',
'GRE' => 'Greece',
'HUN' => 'Hungary',
'IRE' => 'Ireland',
'ITA' => 'Italy',
'JPN' => 'Japan',
'LAT' => 'Latvia',
'MIS' => 'Miscellaneous',
'MON' => 'Monaco',
'NED' => 'Netherlands',
'NZL' => 'New Zealand',
'NOR' => 'Norway',
'POL' => 'Poland',
'ROM' => 'Romania',
'RUS' => 'Russia',
'SRB' => 'Serbia',
'SVK' => 'Slovakia',
'SWE' => 'Sweden',
'SUI' => 'Switzerland',
'ISV' => 'US Virgin Islands',
'USA' => 'USA',
);
while (false !== ($filename = readdir($dir)))
{
if($filename != '.' and $filename != '..')
{ $files[] = $filename; }
}
sort($files);
mysql_connect("mysql09.powweb.com",'fti','friend3');
mysql_select_db("bobsleighphotos");
if(!isset($_POST['doadding']))
{
$cats = array();
$res = mysql_query("SELECT cd.categories_name, cd.categories_id,c.parent_id
FROM zc_categories c, zc_categories_description cd
WHERE cd.categories_id = c.categories_id
ORDER BY cd.categories_name;");
# gather all categories
while($row = mysql_fetch_assoc($res))
{ $cats[] = $row; }
# retrieve all the categories hierarchically
$options = '';
for($idx = 0; $idx < count($cats); $idx++)
{
if($cats[$idx]['parent_id'] != 0)
{
for($c = 0; $c < count($cats); $c++)
{
if($cats[$c]['categories_id'] == $cats[$idx]['parent_id'])
{
$cats[$c]['subcategories'][] = $cats[$idx];
break;
}
}
}
}
print "<form action='products_enmasse.php' method='post'><input type='hidden' name='doadding' value='1' />\n";
foreach($files as $file)
{
$team = explode('.',$file);
$team = explode('-',$team[0]);
// EXTRA PARSING THAT I DON'T ALWAYS NEED
// $number = '';
//
// foreach($parts as $part)
// {
// if(preg_match("/([IV]+)$/",$part,$matches))
// {
// $team[0] = str_replace($matches[1],'',$part);
// $team[1] = "Team {$matches[1]},";
// }
// else if($part == 'W')
// { $team[3] = 'Womens,'; }
// else if(preg_match("/^\d+$/",$part))
// { $number = $part; }
// else if($team[0] !== $part)
// { $team[2] = $part.','; }
// }
$country_code = substr($team[0],0,3);
$country_name = $countries[$country_code];
$team[] = $event_readable_name;
// if(!empty($number))
// { $team[] = "($number)"; }
$title = implode(' ',$team);
list($width,$height) = getimagesize("/home/users/web/b2373/pow.fti/htdocs/bobsleighphotos/download/$event_name/$file");
print "Title: <input type='text' name='title_$file' size='50' value='$title' /> ($file)\n";
print "<input type='hidden' name='width_$file' value='$width' />";
print "<input type='hidden' name='height_$file' value='$height' />";
print "Category: <select name='cat_$file'>\n";
# create options for dropdown list
for($idx = 0; $idx < count($cats); $idx++)
{
$right_country = 0;
if($cats[$idx]['parent_id'] == 0)
{
print "<optgroup label='{$cats[$idx]['categories_name']}'>\n";
if($country_name === $cats[$idx]['categories_name'])
{ $right_country = 1; }
if(isset($cats[$idx]['subcategories']))
{
for($c = 0; $c < count($cats[$idx]['subcategories']); $c++)
{
$found_cat = 0;
$selected = '';
if($event_readable_name === $cats[$idx]['subcategories'][$c]['categories_name']
&& $right_country)
{
$selected = "selected='selected'";
$found_cat = 1;
}
print "<option value='{$cats[$idx]['subcategories'][$c]['categories_id']}' $selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$cats[$idx]['subcategories'][$c]['categories_name']}</option>\n";
}
}
print "</optgroup>\n";
}
}
print "</select>";
if(!$found_cat)
{ print "COULD NOT FIND CATEGORY!!"; }
print "<br /> <br />\n";
}
print "<input type='submit' /></form>";
}
else
{
foreach($files as $file)
{
$name = str_replace('.','_',$file);
$name = str_replace(' ','_',$name);
$width = $_POST['width_'.$name];
$height = $_POST['height_'.$name];
$title = $_POST['title_'.$name];
$cat = $_POST['cat_'.$name];
$desc = "Width: {$width}px<br />\n";
$desc .= "Height: {$height}px<br />\n";
$desc .= "Format: JPEG<br />\n";
$sql = "INSERT INTO zc_products
(products_type,products_quantity,products_image,products_price,
products_virtual,products_date_added,products_weight,products_status,
manufacturers_id,products_ordered,products_quantity_order_min,
products_quantity_order_units,products_priced_by_attribute,product_is_free,product_is_call,
products_quantity_mixed,product_is_always_free_shipping,products_qty_box_status,
products_quantity_order_max,products_sort_order,products_discount_type,products_discount_type_from,
products_price_sorter,master_categories_id,products_tax_class_id)
VALUES(1,10000,'bobsleighphotos/{$event_name}/$file',10.00,
1,NOW(),0,1,
0,0,1,
1,0,0,0,
1,0,1,
0,0,0,0,
10.00,$cat,1);";
mysql_query($sql);
$new_id = mysql_insert_id();
if(mysql_error()) { print "Product $file: ".mysql_error()."<br />"; continue; }
$sql = "INSERT INTO zc_products_description
(products_name,products_description)
VALUES('$title','$desc');";
mysql_query($sql);
if(mysql_error()) { print "Desc $file: ".mysql_error()."<br />"; continue; }
$sql = "INSERT INTO zc_products_to_categories
(products_id,categories_id)
VALUES($new_id,$cat);";
mysql_query($sql);
if(mysql_error()) { print "ProdtoCat $file: ".mysql_error()."<br />"; continue; }
}
print 'Done!';
}
?>