private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $mail = services::getService('mail');
     $categories = services::getService('cats');
     $pool = new pools();
     if ($pool->get($params->getParam('pool_id'))) {
         // become member
         if ($params->getParam('action') == 'become_member') {
             if ($params->getParam('become_member_submit') || $pool->is_public) {
                 $new_membership = new poolsUser();
                 $new_membership->user_id = $this->user->id;
                 $new_membership->pool_id = $pool->id;
                 if (!$pool->is_public) {
                     $new_membership->wait = 1;
                 } else {
                     $new_membership->res_to_free = 1;
                     $new_membership->wait = 0;
                 }
                 if ($params->getParam('become_member_comments')) {
                     $new_membership->comments = $params->getParam('become_member_comments');
                 }
                 $new_membership->insert();
                 // compose E-Mails
                 if (!$pool->is_public) {
                     $tos = $pool->getAdmins();
                     foreach ($tos as $to) {
                         $mail->send('new_member', $to, $pool, $this->user, $new_membership->comments);
                     }
                 } else {
                     $this->switchPage('mysite&new_pool=' . $pool->id);
                 }
             } else {
                 $this->become_member_form = true;
             }
         }
         // are you waiting?
         if ($pool->isWaiting($this->user->id)) {
             $this->user_is_waiting = true;
         }
         // loose membership
         if ($params->getParam('action') == 'no_member') {
             // the last admin can't leave the pool
             if (!$pool->isLastAdmin($this->user->id)) {
                 $pool->removeMember($this->user->id);
                 $this->addMsg('msg_leave_pool');
             } else {
                 $this->addMsg('msg_leave_pool_last_admin');
             }
         }
         // build tabledata
         if ($pool->isMember($this->user->id)) {
             $showcats = $categories->getChildren(0);
             foreach ($showcats as $cat_id => $cat_name) {
                 $show_res = new resFetcher();
                 $show_res->_cat = $cat_id;
                 $show_res->_pools = array($pool->id);
                 $rescounter = $show_res->count();
                 if ($rescounter > 0) {
                     $this->cats[$cat_id] = array("name" => $cat_name, "count" => $rescounter);
                 }
             }
             $allcount = 0;
             foreach ($this->cats as $cat) {
                 $allcount += $cat['count'];
             }
             $this->cats[0] = array("name" => $lang->getMsg('cat_all'), "count" => $allcount);
         } else {
             if (!$pool->isMember($this->user->id, true)) {
                 $this->not_member = true;
             }
             $res_counter = new poolsResources();
             $res_counter->pool_id = $pool->id;
             $this->res_counter = 0;
             $res_counter->find();
             while ($res_counter->fetch()) {
                 ++$this->res_counter;
             }
         }
         // build forum-tabledata
         if ($pool->isMember($this->user->id)) {
             // new/change entry
             if ($params->getParam('action') == 'new_entry') {
                 // formular
                 $form = new form('forum_entry');
                 $form->addElement('text', 'entryheader', $lang->getMsg('showpool_forum_headline'), array('size' => 30, 'maxlength' => 100));
                 $form->addElement('textarea', 'entrytext', $lang->getMsg('home_news_text'), array('rows' => 15, 'cols' => 70));
                 $form->addElement('hidden', 'action', 'new_entry');
                 $form->addElement('hidden', 'pool_id', $pool->id);
                 $form->addElement('hidden', 'thread', $thread->id);
                 $form->addElement('submit', 'entrysubmit', $lang->getMsg('home_news_submit'));
                 $form->addRule('entryheader', $lang->getMsg('showpool_forum_headline_required'), 'required');
                 $form->addRule('entrytext', $lang->getMsg('showpool_forum_text_required'), 'required');
                 // write entry
                 if ($form->validate()) {
                     $new_thread = new forumThreads();
                     $new_thread->pool_id = $pool->id;
                     $new_thread->title = $form->exportValue('entryheader');
                     $new_thread->act_date = time();
                     $new_thread->insert();
                     $new_thread->find(true);
                     $new_entry = new forumEntries();
                     $new_entry->thread_id = $new_thread->id;
                     $new_entry->text = $form->exportValue('entrytext');
                     $new_entry->user_id = $this->user->id;
                     $new_entry->date = $new_thread->act_date;
                     $new_entry->insert();
                     $this->switchPage('showpool&pool_id=' . $pool->id . '&msg=msg_forum_entry_made');
                 }
                 $this->form = $form;
             }
             $showthreads = new forumThreads();
             $showthreads->pool_id = $pool->id;
             $showthreads->find();
             while ($showthreads->fetch()) {
                 $showthreads->fetchLastEntry();
                 $showthreads->last_entry->fetchUser();
                 $this->threads[] = array("id" => $showthreads->id, "title" => $showthreads->title, "act_date" => date('j. n. y, H:i', $showthreads->last_entry->date) . ' ' . $lang->getMsg('showpool_forum_lastentry_by') . ' ' . '<a href="./index.php?page=showmember&pool_id=' . $pool->id . '&showmember=' . $showthreads->last_entry->user->id . '">' . $showthreads->last_entry->user->name . '</a>');
             }
         }
         // build userlist
         if ($pool->id != 1) {
             // assotiativ array with object and detail-flag
             if ($pool->isMember($this->user->id)) {
                 $members = array();
                 $pool_users = new poolsUser();
                 $pool_users->pool_id = $pool->id;
                 $pool_users->wait = 0;
                 if ($pool_users->find()) {
                     $detail_id = $params->getParam('showmember');
                     $count = 1;
                     while ($pool_users->fetch()) {
                         if ($pool_users->user_id != $this->user->id) {
                             $pool_users->fetchUser();
                             $member = array("obj" => $pool_users->user, "detail" => $pool_users->user->id == $detail_id, "count" => $count, "admin" => $pool->isAdmin($pool_users->user->id));
                             if ($pool_users->user->name != "") {
                                 $members[] = $member;
                             }
                             ++$count;
                         }
                     }
                     $this->members = $members;
                 }
             }
         }
         $this->pool = $pool;
     } else {
         $this->switchPage('mysite');
     }
 }
 function addMembership($pool_id)
 {
     $mail = services::getService('mail');
     // add to relations-table
     $new_membership = new poolsUser();
     $new_membership->user_id = $this->id;
     $new_membership->pool_id = $pool_id;
     if ($pool_id != 1) {
         $new_membership->wait = 1;
     } else {
         $new_membership->wait = 0;
     }
     $new_membership->insert();
     // compose E-Mails, if it wasn't the pool to be added
     $new_apply_pool = new pools();
     $new_apply_pool->get($pool_id);
     $tos = $new_apply_pool->getAdmins();
     foreach ($tos as $to) {
         $mail->send('new_member', $to, $new_apply_pool);
     }
 }
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     $mail = services::getService('mail');
     $form = new formPoolData('FoundForm');
     if ($params->getParam('pool_id')) {
         $pool = new pools();
         $pool->get($params->getParam('pool_id'));
         if (!$pool->isAdmin($this->user->id)) {
             $this->switchPage('mysite');
         }
         // defaults
         $form->setDefaults(array('poolname' => $pool->name, 'pooldesc' => $pool->description, 'poolarea' => $pool->area, 'poolcountry' => $pool->country, 'pooladress' => array('plz1' => substr($pool->plz, 0, 2), 'plz2' => substr($pool->plz, 2, 3), 'city' => $pool->city), 'is_public' => $pool->is_public));
         $this->pool = $pool;
         $this->header = $pool->name . $lang->getMsg('pooldata_header_change');
     } else {
         $this->header = $pool->name . $lang->getMsg('pooldata_header_found');
     }
     // Try to validate a form
     if ($form->validate()) {
         if (!isset($pool)) {
             $pool = new pools();
         }
         $pool->name = $form->exportValue('poolname');
         $pool->description = $form->exportValue('pooldesc');
         $pool->area = $form->exportValue('poolarea');
         $pool->country = $form->exportValue('poolcountry');
         $adress2 = $form->getElementValue('pooladress');
         $pool->plz = $adress2['plz1'] . $adress2['plz2'];
         $pool->city = $adress2['city'];
         $pool->is_public = $form->exportValue('is_public');
         //$pool->is_located = $form->exportValue('is_located');
         if (isset($pool->id)) {
             $pool->update();
             $this->addMsg('msg_data_change_success');
             $form->freezeForm();
             $this->change_success_link = true;
         } else {
             $pool->wait = 1;
             $pool->insert();
             $new_user = new poolsUser();
             $new_user->user_id = $this->user->id;
             $new_user->pool_id = $pool->id;
             $new_user->wait = 0;
             $new_user->insert();
             $new_admin = new poolsAdmin();
             $new_admin->user_id = $this->user->id;
             $new_admin->pool_id = $pool->id;
             $new_admin->insert();
             $params->addParam('msg', 'msg_found_success', 'page');
             $mail->send('found_pool_admin', $config->getSetting('email'), $pool);
             $mail->send('found_pool_founder', $this->user, $pool);
             $this->switchPage('mysite');
         }
     }
     $this->form = $form;
 }
 function addMember($user_id)
 {
     $add_member = new poolsUser();
     $add_member->user_id = $user_id;
     $add_member->pool_id = $this->id;
     $add_member->wait = 0;
     $add_member->insert();
 }