\n"; echo "
Please specify the database admin user at Admin
\n"; echo "\n"; die(""); } if(!mysql_select_db(Settings::value("DBNAME"))){ echo "
\n"; echo "
Could not select the specified database ". Settings::value("DBNAME") .".
\n"; echo "
\n"; mysql_close($connId); die(""); } if($manu > 0){ if($hasmins > 0){ if(!empty($action)){ $manu_queueId = 0; $manuId = 0; $mintypes_queueId = 0; $mintypesId = 0; # start transaction if(!mysql_query("BEGIN")){ mysql_close($connId); echo "Could not store the selected prefix (Could not start transaction).
\n"; echo "\n"; echo ""; mysql_close($connId); exit; } # fetch the related data to $hasmins entry $res = mysql_query("SELECT prefixes.characteristic, prefixes.manufacturersId AS manu_queueId, manus.manufacturersId AS manuId, prefixes.mintypesId AS mintypes_queueId, mintypes.mintypesId AS mintypesId FROM manufacturerhasmins_queue prefixes, manufacturers_queue manus, mintypes_queue mintypes WHERE prefixes.id=". $hasmins ." AND prefixes.manufacturersId=manus.id AND prefixes.mintypesId=mintypes.id" ); if(mysql_num_rows($res) != 1){ echo "Could not store the selected prefix (Could not fetch prefix row).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } $row = mysql_fetch_object($res); $manu_queueId = $row->manu_queueId; $manuId = $row->manuId; $mintypes_queueId = $row->mintypes_queueId; $mintypesId = $row->mintypesId; if(($manu_queueId < 1) || ($manuId < 1) || ($mintypes_queueId < 1) || ($mintypesId < 1)){ echo "Could not store the selected prefix (Could not fetch some queued items).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } if($action == "store"){ # transfer prefix from queue to existing if(!mysql_query("INSERT INTO manufacturerhasmins (manufacturersId, mintypesId, characteristic) VALUES(". $manuId .", ". $mintypesId .", '". $row->characteristic ."')")){ echo "Could not store the selected prefix (Could not insert it).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } } if($action == "replace"){ # replace the existing row $rowId = $_GET["replace"]; if(!is_numeric($rowId) || $rowId < 1){ echo "Could not store the selected prefix (No id of the replaced row).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } if(!mysql_query("UPDATE manufacturerhasmins SET characteristic='". $row->characteristic ."' WHERE id=". $rowId)){ echo "Could not store the selected prefix (Could not replace ". $rowId ." with ". $row->characteristic .").
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } } # action delete needs only this and all other actions needs this to # remove the queued min from the queue if(!mysql_query("DELETE FROM manufacturerhasmins_queue WHERE id=". $hasmins)){ echo "Could not store the selected prefix (Could remove queued entry).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } # cleanup mintypes_queue and manufacturers_queue # remove not needed queued mintypes $res = mysql_query("SELECT id FROM manufacturerhasmins_queue WHERE mintypesId=". $mintypes_queueId); if(mysql_num_rows($res) == 0){ if(!mysql_query("DELETE FROM mintypes_queue WHERE id=". $mintypes_queueId)){ echo "Could not store the selected prefix (Could remove queued MIN-Type).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } } # remove not needed queued manufacturers $res = mysql_query("SELECT id FROM manufacturerhasmins_queue WHERE manufacturersId=". $manu_queueId); if(mysql_num_rows($res) == 0){ if(!mysql_query("DELETE FROM manufacturers_queue WHERE id=". $manu_queueId)){ echo "Could not store the selected prefix (Could remove queued manufacturer).
\n"; echo "\n"; echo ""; mysql_query("ROLLBACK"); mysql_close($connId); exit; } } mysql_query("COMMIT"); echo "\n"; echo "\n"; echo ""; mysql_close($connId); exit; } } $res = mysql_query("SELECT name FROM manufacturers_queue WHERE manufacturersId=". $manu); $row = mysql_fetch_object($res); $manuname = $row->name; $res = mysql_query("SELECT DISTINCT queuedtypes.id AS queuedId, mintypes.id, mintypes.name FROM manufacturerhasmins_queue prefixes, mintypes_queue queuedtypes, mintypes WHERE prefixes.mintypesId = queuedtypes.id AND queuedtypes.mintypesId = mintypes.id AND prefixes.manufacturersId IN(SELECT id FROM manufacturers_queue WHERE manufacturersId=". $manu .") ORDER BY mintypes.name"); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; while($mintype = mysql_fetch_object($res)){ echo "\n"; echo " \n"; echo "\n"; # fetch prefixes for manufacturer and mintype combination $prefixesQueued = array(); $orClause = array(); $res2 = mysql_query("SELECT id, characteristic FROM manufacturerhasmins_queue WHERE manufacturersId IN(SELECT id FROM manufacturers_queue WHERE manufacturersId=". $manu .") AND mintypesId=". $mintype->queuedId); while($prefix = mysql_fetch_object($res2)){ $prefixesQueued[] = $prefix; $orClause[] = "mins.characteristic LIKE '%". $prefix->characteristic ."%'"; } # fetch existing prefixes for this manufacturer $prefixesExisting = array(); $res2 = mysql_query("SELECT mins.id, mins.characteristic, manus.name, manus.id AS manuId FROM manufacturerhasmins mins, manufacturers manus WHERE mins.manufacturersId = manus.id AND (mins.manufacturersId=". $manu ." OR ". join(" OR ", $orClause) .") AND mins.mintypesId=". $mintype->id); while($prefix = mysql_fetch_object($res2)) $prefixesExisting[] = $prefix; $max = max(count($prefixesQueued), count($prefixesExisting)); for($i = 0; $i < $max; $i++){ echo "\n"; # add a possible queued prefix to this row if($i >= count($prefixesQueued)) echo " \n"; else{ # test whether it may already exist # and create replace link $highlight = false; $replaceMINs = array(); foreach($prefixesExisting as $existing){ if(strpos($existing->characteristic, $prefixesQueued[$i]->characteristic) !== false){ $highlight = true; # replacements are only allowed for the same manufacturer if($existing->manuId == $manu) $replaceMINs[] = $existing; } } echo " \n"; } # add a possible existing prefix to this row if($i < count($prefixesExisting)) echo " \n"; else echo " \n"; # finish the row echo "\n"; echo "\n"; } } echo "
". $manuname ."
". _("Queued") ."". _("Existing") ."
". $mintype->name ."
\n"; if($highlight) echo " \n"; echo " ". $prefixesQueued[$i]->characteristic ."\n"; if($highlight) echo " \n"; echo " (Store,\n"; echo " Delete\n"; $replaceLinks = array(); foreach($replaceMINs as $min){ $replaceLinks[] = " ". $min->characteristic ."\n"; } if(count($replaceLinks) > 0){ echo ", Use instead ". implode(" or ", $replaceLinks); } echo ")\n"; echo " ". $prefixesExisting[$i]->characteristic ."(". $prefixesExisting[$i]->name .")
\n"; mysql_close($connId); die(""); } $res = mysql_query("SELECT DISTINCT manu.id, manu.name FROM manufacturerhasmins_queue prefixes, manufacturers_queue queuedmanu, manufacturers manu, mintypes_queue mins WHERE prefixes.manufacturersId = queuedmanu.id AND queuedmanu.manufacturersId = manu.id AND queuedmanu.manufacturersId IS NOT NULL AND prefixes.mintypesId=mins.id AND mins.mintypesId IS NOT NULL ORDER BY manu.name"); if(mysql_num_rows($res) < 1){ echo _("Either there are no queued prefixes, or you must process all queued manufacturers and MIN-Types before"); } else{ echo "\n"; } ?>