public function blockUserEvent($runData)
 {
     $pl = $runData->getParameterList();
     $site = $runData->getTemp("site");
     $userId = $pl->getParameterValue("userId");
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     if ($user == null) {
         $runData->ajaxResponseAdd("status", "no_user");
         $runData->ajaxResponseAdd("message", "No such user.");
         return;
     }
     // check if user is a member or so.
     $c = new Criteria();
     $c->add("site_id", $site->getSiteId());
     $c->add("user_id", $userId);
     $mem = DB_MemberPeer::instance()->selectOne($c);
     if ($mem) {
         $runData->ajaxResponseAdd("status", "user_member");
         $runData->ajaxResponseAdd("message", _("The user you want to block is a member of this site. Please first remove him/her from the site members list."));
         return;
     }
     // check if not already blocked
     $bl = DB_UserBlockPeer::instance()->selectOne($c);
     if ($bl) {
         $runData->ajaxResponseAdd("status", "already_blocked");
         $runData->ajaxResponseAdd("message", _("This user is already blocked."));
         return;
     }
     // ok, now block!
     $db = Database::connection();
     $db->begin();
     $reason = $pl->getParameterValue("reason", "AMODULE");
     $block = new DB_UserBlock();
     $block->setSiteId($site->getSiteId());
     $block->setUserId($userId);
     $block->setDateBlocked(new ODate());
     if ($reason && $reason !== '') {
         $block->setReason(substr($reason, 0, 500));
     }
     $block->save();
     $db->commit();
 }
 public function removeMemberEvent($runData)
 {
     $userId = $runData->getParameterList()->getParameterValue("user_id");
     $ban = $runData->getParameterList()->getParameterValue("ban");
     $user = DB_OzoneUserPeer::instance()->selectByPrimaryKey($userId);
     if ($user == null) {
         throw new ProcessException("Error");
     }
     $site = $runData->getTemp("site");
     $siteId = $site->getSiteId();
     // remember: one can NOT remove the last admin nor himself.
     if ($userId == $runData->getUserId()) {
         throw new ProcessException(_('You can not remove yourself! Use "your account" panel instead.'), "not_yourself");
     }
     $db = Database::connection();
     $db->begin();
     // check if is admin. can not remove last admin.
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->add("site_id", $siteId);
     $admin = DB_AdminPeer::instance()->selectOne($c);
     if ($admin && $admin->getFounder()) {
         throw new ProcessException(_("The founder of the site can not be removed.") . "founder_nonremovable");
     }
     if ($admin) {
         $c2 = new Criteria();
         $c2->add("site_id", $siteId);
         $acount = DB_AdminPeer::instance()->selectCount($c2);
         if ($acount == 1) {
             // BUT this meand "yourself"
             throw new ProcessException(_("You can not remove the last admin."), "last_admin)");
         }
     }
     $c = new Criteria();
     $c->add("user_id", $userId);
     $c->add("site_id", $siteId);
     DB_MemberPeer::instance()->delete($c);
     DB_ModeratorPeer::instance()->delete($c);
     DB_AdminPeer::instance()->delete($c);
     NotificationMaker::instance()->removedFromMembers($site, $user);
     // ban or not?
     if ($ban) {
         $c = new Criteria();
         $c->add("site_id", $site->getSiteId());
         $c->add("user_id", $userId);
         $bl = DB_UserBlockPeer::instance()->selectOne($c);
         if ($bl) {
             throw new ProcessException(_("Error occured."));
         }
         $block = new DB_UserBlock();
         $block->setSiteId($site->getSiteId());
         $block->setUserId($userId);
         $block->setDateBlocked(new ODate());
         $block->save();
     }
     $db->commit();
 }