$res=$DBc->sendSQL("SELECT at_id FROM ach_task WHERE NOT EXISTS (SELECT * FROM ach_player_task WHERE apt_player='".$cid."' AND apt_task=at_id)","ARRAY");
$res2=$DBc->sendSQL("SELECT ach_atom.* FROM ach_atom,ach_objective,ach_achievement WHERE ao_task='".$task['at_id']."' AND ao_id=atom_objective AND ap_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_player='".$cid."' AND apo_objective=ao_id)","ARRAY");
$res=$DBc->sendSQL("SELECT ao_id FROM ach_objective WHERE ao_condition='all' AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."') AND NOT EXISTS (SELECT * FROM ach_atom WHERE atom_objective=ao_id AND NOT EXISTS (SELECT * FROM ach_player_atom WHERE apa_atom=atom_id AND apa_state='GRANT' AND apa_player='".$cid."')) AND EXISTS (SELECT * FROM ach_atom WHERE atom_objective=ao_id)","ARRAY");
$res=$DBc->sendSQL("SELECT ao_id FROM ach_objective WHERE ao_condition='value' AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."') AND ao_value<=(SELECT sum(apa_value) FROM ach_atom,ach_player_atom WHERE atom_objective=ao_id AND apa_atom=atom_id AND apa_state='GRANT' AND apa_player='".$cid."') AND EXISTS (SELECT * FROM ach_atom WHERE atom_objective=ao_id)","ARRAY");
$res=$DBc->sendSQL("SELECT ao_id FROM ach_objective WHERE ao_condition='any' AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."') AND EXISTS (SELECT * FROM ach_atom WHERE atom_objective=ao_id AND EXISTS (SELECT * FROM ach_player_atom WHERE apa_atom=atom_id AND apa_state='GRANT' AND apa_player='".$cid."')) AND EXISTS (SELECT * FROM ach_atom WHERE atom_objective=ao_id)","ARRAY");
$res=$DBc->sendSQL("SELECT ao_id FROM ach_objective,ach_task as t1,ach_achievement WHERE ao_display='meta' ao_task=t1.at_id AND t1.at_achievement=aa_id AND NOT EXISTS (SELECT * FROM ach_task as t2 WHERE t2.at_achievement=aa_metalink AND NOT EXISTS (SELECT * FROM ach_player_task WHERE apt_task=t2.at_id AND apt_player='".$cid."'))");
$sz=sizeof($res);
for($i=0;$i<$sz;$i++){
$DBc->sendSQL("INSERT INTO ach_player_objective (apo_objective,apo_player,apo_date) VALUES ('".$res[$i]['ao_id']."','".$cid."','".time()."')","NONE");
$DBc->sendSQL("DELETE FROM ach_player_atom WHERE EXISTS (SELECT * FROM ach_player_objective,ach_atom WHERE atom_id=apa_atom AND apa_player='".$cid."' AND atom_objective=ao_id)");
$res=$DBc->sendSQL("SELECT at_id FROM ach_task WHERE at_condition='all' AND NOT EXISTS (SELECT * FROM ach_player_task WHERE apt_task=at_id AND aptp_player='".$cid."') AND NOT EXISTS (SELECT * FROM ach_objective WHERE ao_task=ap_id AND NOT EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."')) AND EXISTS (SELECT * FROM ach_objective WHERE ao_task=ap_id) AND at_dev='0'","ARRAY");
$res=$DBc->sendSQL("SELECT ap_id FROM ach_task WHERE at_condition='value' AND NOT EXISTS (SELECT * FROM ach_player_task WHERE apt_task=at_id AND apt_player='".$cid."') AND at_value<=(SELECT count(*) FROM ach_objective WHERE ao_task=at_id AND EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."')) AND EXISTS (SELECT * FROM ach_objective WHERE ao_task=at_id) AND at_dev='0'","ARRAY");
$res=$DBc->sendSQL("SELECT at_id FROM ach_task WHERE ap_condition='any' AND NOT EXISTS (SELECT * FROM ach_player_task WHERE apt_task=at_id AND apt_player='".$cid."') AND EXISTS (SELECT * FROM ach_objective WHERE ao_task=at_id AND EXISTS (SELECT * FROM ach_player_objective WHERE apo_objective=ao_id AND apo_player='".$cid."')) AND EXISTS (SELECT * FROM ach_objective WHERE ao_task=at_id) AND at_dev='0'","ARRAY");