images = array(
'medium' => array(
'height' => 115,
'quality' => 99,
'web_location' => '/images/designers/featured/'
)
); // the width is variable
$this->img_tag_attr = array();
// -----------------------------------------------------
// set path based on unix or windows
foreach($this->images as $image_size=>$image_info)
{
$this->images[$image_size]['path'] = Config::$path_to_www;
$this->images[$image_size]['path'] .= (Config::$location == 'remote') ? $this->images[$image_size]['web_location'] : str_replace('/', '\\', $this->images[$image_size]['web_location']);
// -----------------------------------------------------
//$this->img_tag_attr[$image_size] = 'width="'.$image_info['width'].'" height="'.$image_info['height'].'"'; // no width
}
$this->upload_images = array();
$this->dbTableName = Config::$db_tables['vendor_designers_featured_images'];
}
function set_fields($Designers, $designer_id, $form_type='insert', $db_default=FALSE, $db_fields='')
{
// db_default var if true sets default field vals to db val
// form type of edit means that form has not yet been submitted
switch($form_type)
{
case 'insert':
$submitname = $this->insert_submit_name;
$submitvalue = "e n t e r f e a t u r e d d e s i g n e r";
break;
case 'edit':
$submitname = $this->edit_submit_name;
$submitvalue = "s u b m i t c h a n g e s";
break;
} // switch
$this->fields = array();
$this->fields['MAX_FILE_SIZE'] = array(
'label' => '',
'label_css' => '',
'type' => array(
'tag'=>'input_hidden'
),
'input_css' => '',
'default' => '10000000',
'required' => FALSE
);
for($i=1;$i<=$this->max_images;++$i)
{
$this->fields['image'.$i] = array(
'label' => 'Image '.$i,
'label_css' => 'black_11_bold',
'type' => array(
'tag'=>'input_file'
)
);
if($form_type == 'add' && $i < 4)
{
$this->fields['image'.$i]['validation'] = array('required');
}
elseif($form_type == 'edit')
{
// show the images
$this->fields['image'.$i]['html_before'] = '
replace: ';
}
// get designer active items as options
$options = array();
$RS = $Designers->get_items_RecordSet($designer_id, 'active');
while($row = $RS->FetchRow())
{
$options[$row['id']] = $row['name'] . ' ('.$row['style_number'].')';
}
if($RS->RecordCount() == 0)
{
echo 'no items'; exit();
}
$this->fields['item_link'.$i] = array(
'label' => 'Item Link '.$i,
'label_css' => 'black_11_bold',
'type' => array(
'tag'=>'select',
'options'=>$options,
'top_option' => array('0'=>'-- (optional) --')
)
);
}
$this->fields['status_featured'] = array(
'label' => 'Featured Status',
'label_css' => 'black_11_bold',
'type' => array(
'tag' => 'select',
'options' => array('yes'=>'active','inactive'=>'inactive'),
),
'validation' => array('required'),
'default' => 'yes'
);
$this->fields[$submitname] = array(
'type' => array(
'tag'=> 'input_submit',
),
'input_css' => 'blue_submit',
'default' => $submitvalue,
);
if($db_default)
{
foreach($this->fields as $fieldName=>$fieldInfo)
{
$exclude_fields = array('MAX_FILE_SIZE');
if(!in_array($fieldName, $exclude_fields) && !strstr($fieldName, 'image') && !strstr($fieldName, 'link') && $fieldInfo['type']['tag'] != 'input_submit' && $fieldInfo['type']['tag'] != 'input_hidden')
{
$default = $db_fields[$fieldName];
$this->fields[$fieldName]['default'] = $default;
}
}
// get link defaults
$i = 1;
$RS = $this->get_RS($designer_id);
while($row = $RS->FetchRow())
{
++$i;
if($row['item_id'] != 0)
{
$this->fields['item_link'.$i]['default'] = $row['item_id'];
}
}
}
}
function get_image_file($which, $designer_id)
{
return(Database::ado_get_one("SELECT image_file FROM $this->dbTableName WHERE image_order=$which AND designer_id=$designer_id"));
}
function _update($DesignerRecord, $Designers, $Form)
{
// determine if images need to be updated or inserted
for($i = 1; $i <= $this->max_images; ++$i)
{
if($Form->get_field_value('image'.$i) != '')
{
if($this->get_image_file($i, $DesignerRecord['id']) != '')
{
// db record exists for this image order so update
$this->update_image($DesignerRecord['id'], $Form->get_field_value('image'.$i), $i, $Form->get_field_value('item_link'.$i));
}
else
{
// insert
$this->insert_image($DesignerRecord['id'], $Form->get_field_value('image'.$i), $i, $Form->get_field_value('item_link'.$i));
}
}
else
{
// test for only link change (no new upload)
if($Form->get_field_value('item_link'.$i) != '')
{
// update link only
Database::ado_execute_query("UPDATE $this->dbTableName SET item_id=".$Form->get_field_value('item_link'.$i)." WHERE designer_id=".$DesignerRecord['id']." AND image_order=$i");
}
}
}
// update status featured if nec
if($Form->get_field_value('status_featured') != $DesignerRecord['status_featured'])
{
$this->update_status_featured($DesignerRecord['id'], $Form->get_field_value('status_featured'), $Designers);
}
return(TRUE);
}
function update_image($designer_id, $image_file, $image_order, $item_id='')
{
$upd = "UPDATE ".$this->dbTableName." SET image_file='$image_file', item_id=$item_id WHERE designer_id= $designer_id AND image_order=$image_order";
return(Database::ado_execute_query($upd, 'FeaturedDesigners::update_image'));
}
function insert_image($designer_id, $image_file, $image_order, $item_id='')
{
$ins = "INSERT INTO $this->dbTableName VALUES(NULL, ".$designer_id.", '".$image_file."', $image_order, ".$item_id.")";
return(Database::ado_execute_query($ins, 'FeaturedDesigners::_insert_image'));
}
function _insert($designer_id, $Designers, $Form)
{
for($i = 1; $i <= $this->max_images; ++$i)
{
if($Form->get_field_value('image'.$i) != '')
{
$this->insert_image($designer_id, $Form->get_field_value('image'.$i), $i, $Form->get_field_value('item_link'.$i));
}
}
$this->update_status_featured($designer_id, $Form->get_field_value('status_featured'), $Designers);
Utilities::notify(Config::$tech_email, 'Featured Designer Inserted', $designer_id);
return(TRUE);
}
function update_status_featured($designer_id, $status_featured, $Designers)
{
return(Database::ado_execute_query("UPDATE $Designers->dbTableName SET status_featured='".$status_featured."' WHERE id=".$designer_id." LIMIT 1", "FeaturedDesigners::update_status_featured"));
}
function get_RS($designer_id)
{
return(Database::ado_execute_query("SELECT * FROM $this->dbTableName WHERE designer_id='$designer_id' ORDER BY image_order", "FeaturedDesigners::get_RS"));
}
function delete_records($designer_id)
{
return(Database::ado_execute_query("DELETE FROM $this->dbTableName WHERE designer_id='$designer_id'", "FeaturedDesigners::_remove"));
}
function _remove($designer_id, $Designers)
{
// remove all images
$image_files_to_delete = array();
// get path to image
foreach($this->images as $image_size=>$image_size_info)
{
$path = $image_size_info['path'];
break;
}
// get each image filename
$RS = $this->get_RS($designer_id);
while($row = $RS->FetchRow())
{
$image_files_to_delete[] = $row['image_file'];
}
foreach($image_files_to_delete as $path_file)
{
Utilities::delete_file($path_file);
}
// delete all vendor_designers_featured_images records
$this->delete_records($designer_id);
$this->update_status_featured($designer_id, 'no', $Designers);
}
function get_random_with_live_items($Designers, $Items, $Sizes, $count=0)
{
// chooses a featured designer at random and returns an array of id and designer if there are live items, FALSE otherwise (after recursively calling itself up to 4 more times)
//echo $count.'
';
$feat = Database::ado_get_row("SELECT a.id, name as designer FROM $Designers->dbTableName a, $this->dbTableName b WHERE a.id=b.designer_id AND a.status_featured='yes' ORDER BY RAND() LIMIT 1", "FeaturedDesigners::_random");
// make sure this designer has live items, otherwise send a notification email and try again
if(!$Designers->has_live_items($feat['id'], $Items, $Sizes, $feat['id']))
{
//echo $feat['designer'];
//Utilities::notify(Config::$tech_email, "hb ERROR: Featured Designer has no Items", $feat['designer'], Config::$site_manager_email);
++$count;
if($count > 5)
{
return(FALSE);
}
else
{
// try another
$feat = $this->get_random_with_live_items($Designers, $Items, $Sizes, $count);
return($feat); // serious shit!
}
}
else
{
return($feat);
}
}
function _html($Items, $Sizes, $featured_arr, $show_text=FALSE)
{
// array passed in contains featured designer id and name
$html = '
| '; if($show_text) { $html .= 'Featured Designer: '; } $html .= ''.$featured_arr['designer'].' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | ';
// get images
$RS = Database::ado_execute_query("SELECT image_file, item_id FROM $this->dbTableName WHERE designer_id='".$featured_arr['id']."' ORDER BY image_order", "FeturedDesigners::_html");
while($row = $RS->FetchRow())
{
// link
if($row['item_id'] != 0)
{
$Item = new Item($row['item_id']);
if($Item->is_live_web($Items))
{
$link_to = '/dressing_room/?id='.$row['item_id'];
$link_title = 'try it!';
}
else
{
$link_to = '/showroom/?des='.$featured_arr['id'];
$link_title = 'see '.$featured_arr['designer'].' items';
}
}
else
{
$link_to = '/showroom/?des='.$featured_arr['id'];
$link_title = 'see '.$featured_arr['designer'].' items';
}
$html .= '![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||