If a person praying needs to do something relatively minor during prayer, like opening a door and the like, it is OK as long as his direction does not change from the qibla (direction of prayer). The evidence for this is what Abu Dawood narrated that Aa'isha (may Allah be pleased with her), said, "The Messenger of Allah (peace be upon him), used to pray with the door closed, so I arrived and asked him to open it, so he came and opened it and returned to his prayer" (the narrator mentioned that the door was in the direction of the qibla).1
The same is true if a mother needed, while praying, to save her child from danger or harm and the like—small movement to the right or left, or forward or backward, does not harm the prayer. Similarly if the ridaa’ (upper body cover) falls off, the praying person can pick it up and if the izar (lower body cover) became loose, then he can tighten it up. The sharia (laws of Islam) have allowed for the praying person in some cases excessive movement even if he were to change direction from qibla, as evident in the hadith of Abu Huraira, (may Allah be pleased with him), where he said: "The Messenger of Allah (peace be upon him), said: ‘Kill the two black things while in prayer: the snake and scorpion.’ "2
Also, preventing a person from passing in the place of prostration by pushing (or even fighting him if he insists) is prescribed, as related in Bukhari from hadith Abi Saleh Al-Samman, who said: "I saw Aba Saeed Al-Khudri on Friday praying with something in front of him to protect him from [passing] people, and a young man from Bani Abi Muaet wanted to pass in front of him in the place of prostration. So Abu Saeed pushed the man’s chest, so the man looked [around] and did not find any place from which to walk except in front of him, so he tried to pass in front of him again. Abu Saeed pushed him harsher than the first time, so he cursed Abu Saeed. Then the young man went to Marwan and complained about Abu Saeed’s action and Abu Saeed entered after him at Marwan’s place so Marwan said: ‘What is the matter with you, doing that to your brother’s son oh Abu Saeed.?’ He said: ‘I heard the Prophet (peace be upon him) saying: "If one of you prays with something in front of him protecting him from [passing] people, and someone wants to pass in front of him, then he should push him, and if he refuses to [turn back], then fight him, for he is a shaitan (satan)."’3
From the book What Should You Do in the Following Situations... ?
1 Sunan Abu Dawood, number 922, and Sahih Sunan Abu Dawood 815.
2 Sunan Abu Dawood, number 921, and Sahih Sunan Abu Dawood 814.
3 Narrated al-Bukhari Fath 1/582.