Index: branches/unlabeled/unlabeled-1.1.2/category_update.php =================================================================== diff -u -N --- branches/unlabeled/unlabeled-1.1.2/category_update.php (revision 0) +++ branches/unlabeled/unlabeled-1.1.2/category_update.php (revision 4123) @@ -0,0 +1,67 @@ +Init(); + +$conn =& $application->GetADODBConnection(); + +$sql = 'SELECT CategoryId, ResourceId FROM '.$application->getUnitOption('c', 'TableName'); +$cat_ids = $conn->Query($sql); +if($cat_ids) +{ + $product_list =& $application->recallObject('p', 'p_List', Array('autoload' => false, 'per_page' => 1)); + foreach($cat_ids as $category_data) + { + $application->SetVar('m_cat_id', $category_data['CategoryId']); + $application->SetVar('c_id', $category_data['CategoryId']); + $product_list->addFilter('category_filter', TABLE_PREFIX.'CategoryItems.CategoryId = '.$category_data['CategoryId'] ); + $product_list->Query(true); + $product_list->GoFirst(); + + $image = $product_list->GetDBField('LocalPath'); + if($image) + { + $sql = 'SELECT ImageId + FROM '.$application->getUnitOption('catimg', 'TableName').' + WHERE ResourceId = '.$category_data['ResourceId'].' + AND DefaultImg = 1'; + $image_id = $conn->GetOne($sql); + if($image_id) + { + $sql = 'UPDATE '.$application->getUnitOption('catimg', 'TableName').' + SET LocalImage = '.$conn->qstr($image).' + WHERE ImageId = '.$image_id; + } + else + { + $sql = 'INSERT INTO '.$application->getUnitOption('catimg', 'TableName').' + VALUES (\'\', '.$category_data['ResourceId'].', \'\', \'Main\', \'Main\', 1, 1, '.$conn->qstr($image).', 1, 1, \'\', 0, '.$conn->qstr($image).', 1, 0)'; + } + + $conn->ChangeQuery($sql); + } + } +} + +$end = getmicrotime(); + +if ( $application->isDebugMode() ) +{ + echo '

Memory used: '.round(memory_get_usage()/1024/1024, 1).' Mb
'; + echo 'Time used: '.round(($end - $start), 5).' Sec
'; +} + +//print_pre(get_included_files()); + +function getmicrotime() +{ + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} +?> \ No newline at end of file