if( ($found_item_id != $item_id) || $has_page ) // other category has same filename as ours OR we have filename, that ends with _number
{
$append = $found_item_id ? 'a' : '';
if($has_page)
{
$filename = $rets[1].'_'.$rets[2];
$append = $rets[3] ? $rets[3] : 'a';
}
$sql = 'SELECT '.$item_info['id_field'].' FROM '.$prefix.$item_info['table'].' WHERE (Filename = %s) AND ('.$item_info['id_field'].' != '.$item_id.')';
while ( $db->GetOne( sprintf($sql, $db->qstr($filename.$append)) ) > 0 )
function moveItemTemplatesToCustom($module_name, $prefix)
{
$application =& kApplication::Instance();
$root_parent_path = $application->Conn->GetOne(
'SELECT ParentPath FROM '.TABLE_PREFIX.'Category
WHERE CategoryId = '.$application->ModuleInfo[$module_name]['RootCat']);
$item_t_customfield = $application->Conn->GetOne('SELECT CustomFieldId FROM '.TABLE_PREFIX.'CustomField WHERE FieldName = \''.$prefix.'_ItemTemplate\'');