Normally, when the Torah is read in the synagogue, the first Aliya is given to a Kohen, the second to a Levi, and the rest of the Aliyot are given to Yisraelim. The Gemara establishes in Masechet Gittin that if no Kohen is present, then "Nitpareda Ha’havila" – literally, "the knot is untied," meaning, the normal system is completely unraveled.
We find among the Rishonim several different approaches in explaining what precisely this means. According to Rashi (Rav Shlomo Yitzhak of Troyes, France, 1040-1105) and the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204), this means simply that the Levi loses his position of stature, and does not receive the second Aliya. The Aruch Ha’shulhan (Rav Yechiel Michel Epstein of Nevarduk, 1829-1908) understood this opinion to mean that the Levi does not even receive the first Aliya, and thus only Yisraelim receive Aliyot. Other Rishonim explain "Nitpareda Ha’havila" to mean that the congregation can call up anyone they want; if no Kohen is present, then there are no longer any rules of precedence, and thus the congregation can call up either Yisraelim or Leviyim for all the Aliyot. A variation of this view is that if there is a Yisrael and Levi, and the Yisrael’s stature exceeds that of the Levi, then the Yisrael should receive the first Aliya, before the Levi.
The Shulhan Aruch follows the first opinion, that the Levi does not receive the second Aliya as he does normally. Hacham David Yosef, in his Halacha Berura, rules that the Levi in this case may be given the first Aliya, and may also be given the third Aliya after two Yisraelim, because he is treated as a Yisrael. If the congregation decides to give the Levi the third Aliya after two Yisraelim, the person calling the Aliyot should announce, "Af Al Pi She’hu Levi" ("even though he is a Levi"), to prevent the possible misconception that he is not a Levi.
If a Yisrael was called up for the first Aliya because no Kohen was present, and a Kohen enters the synagogue before the Yisrael began reciting the Beracha, the Kohen is called for the Aliya in place of the Yisrael. However, in order that the Yisrael will not be embarrassed, he remains there at the Teba and is given the third Aliya. Even if the Yisrael recited the word "Baruch" before the Kohen walked in, the Kohen is nevertheless given the Aliya. The Kohen then recites "Barechu" even though the Yisrael had already done so.
If there is one Kohen in the synagogue at the time of the Torah reading, but he had come late and is thus reciting the Shema section during which it is forbidden to interrupt, a Yisrael is called in his place, since a person cannot go to the Sefer Torah while he recites Shema.
If there is only one Kohen in the synagogue on a fast day, and he is not, for whatever reason, observing the fast (such as if he has a medical condition), he does not receive the first Aliya. He should be asked to leave the synagogue, as people might not know that he is not fasting and will thus question whether he is a Kohen, and then a Yisrael should be called in his place.
Summary: If no Kohen is present in the synagogue, the congregation can either call up a Levi or Yisrael for the first Aliya. A Levi may be given the third Aliya, as well. If a Yisrael was called up for the first Aliya because no Kohen was present in the synagogue, and a Kohen walked in before the Yisrael recited the Beracha, the Kohen is called in his place, and the Yisrael receives the third Aliya. If the only Kohen in the synagogue on a fast day is not fasting, he should be asked to leave before the first Aliya and a Yisrael is called in his place.