function formInvite($name, $user)
 {
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $cats = services::getService('cats');
     $this->form($name);
     $this->addElement('textarea', 'emails', $lang->getMsg('invite_form_emails'), array('rows' => 5, 'cols' => 40));
     $this->addElement('textarea', 'message', $lang->getMsg('invite_form_message'), array('rows' => 7, 'cols' => 50));
     $free_pool = new poolsUser();
     $free_pool->user_id = $user->id;
     $free_pool->wait = 0;
     $free_pool->find();
     $free_pools = array();
     while ($free_pool->fetch()) {
         $free_pool->fetchPool();
         $free_pools[] =& HTML_QuickForm::createElement('checkbox', $free_pool->pool->id, null, ' ' . $free_pool->pool->name, $free_pool->pool->id);
     }
     $this->addGroup($free_pools, 'free_pools', $lang->getMsg('resdata_form_pools'), '<br>');
     $this->addElement('submit', 'submit', $lang->getMsg('resdata_form_submit'));
     $this->addRule('emails', $lang->getMsg('resdata_form_namenecessary'), 'required');
 }
 public function toDoList()
 {
     // ToDo-list
     if (isset($this->user)) {
         $newmsgs = 0;
         $msgs = new pm();
         $msgs->recipient_id = $this->user->id;
         $msgs->recipient_delete = 0;
         $msgs->is_read = 0;
         if ($msgs->find()) {
             while ($msgs->fetch()) {
                 ++$newmsgs;
             }
         }
         $wait_res_count = 0;
         $waiting_res = $this->user->getWaitingRes();
         if (is_array($waiting_res)) {
             foreach ($waiting_res as $res) {
                 ++$wait_res_count;
             }
         }
         $waiting_user = new poolsUser();
         $wait_user_count = array();
         $waiting_user->wait = 1;
         $wait_user = false;
         if ($waiting_user->find()) {
             while ($waiting_user->fetch()) {
                 $user_admin = new poolsAdmin();
                 $user_admin->pool_id = $waiting_user->pool_id;
                 $user_admin->user_id = $this->user->id;
                 if ($user_admin->find()) {
                     $wait_user = true;
                     ++$wait_user_count["{$waiting_user->pool_id}"]["count"];
                     $wait_user_count["{$waiting_user->pool_id}"]["pool"] = new pools();
                     $wait_user_count["{$waiting_user->pool_id}"]["pool"]->get($waiting_user->pool_id);
                 }
             }
         }
         if ($wait_user || $wait_res_count > 0 || $newmsgs > 0) {
             $todo = array();
             if ($wait_res_count > 0) {
                 $todo['res'] = $wait_res_count;
             }
             if ($newmsgs > 0) {
                 $todo['msgs'] = $newmsgs;
             }
             if ($wait_user) {
                 $todo['user'] = $wait_user_count;
             }
             $this->todo = $todo;
         } else {
             $this->todo = false;
         }
     }
 }
 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;
 }
 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');
     }
 }
 private function process()
 {
     $this->commonProcess();
     $mail = services::getService('mail');
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     $pool = new pools();
     $pool->get($params->getParam("pool_id"));
     if ($pool->isAdmin($this->user->id)) {
         $this->header = $pool->name . $lang->getMsg('pooladmin_header');
         // build userlist
         // 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);
                         $members[] = $member;
                         ++$count;
                     }
                 }
                 $this->members = $members;
             }
         }
         // build adminlist
         // assotiativ array with object and detail-flag
         if ($pool->isAdmin($this->user->id)) {
             $admins = array();
             $pool_admins = new poolsAdmin();
             $pool_admins->pool_id = $pool->id;
             $pool_admins->wait = 0;
             if ($pool_admins->find()) {
                 $detail_id = $params->getParam('showadmin');
                 $count1 = 1;
                 while ($pool_admins->fetch()) {
                     if ($pool_admins->user_id != $this->user->id) {
                         $pool_admins->fetchUser();
                         $admin = array("obj" => $pool_admins->user, "detail" => $pool_admins->user->id == $detail_id, "count" => $count1);
                         $admins[] = $admin;
                         ++$count1;
                     }
                 }
                 $this->admins = $admins;
             }
         }
         // form processing
         // Waiting User
         $wait_users = new poolsUser();
         $wait_users->pool_id = $pool->id;
         $wait_users->wait = "1";
         if ($wait_users->find()) {
             $waiting_user = array();
             while ($wait_users->fetch()) {
                 $waiting_user[] = $wait_users->user_id;
             }
         }
         // refuse_user-form
         if ($params->getParam('user_refuse_submit') != false) {
             foreach ($waiting_user as $user_id) {
                 if ($params->getParam($user_id) == 1) {
                     $refuse_user = new poolsUser();
                     // user is refused
                     $refuse_user->user_id = $user_id;
                     $refuse_user->pool_id = $pool->id;
                     $refuse_user->find();
                     $refuse_user->delete();
                     $refused = TRUE;
                     $refused_mail = new user();
                     $refused_mail->get($refuse_user->user_id);
                     $mail->send("user_refused", $refused_mail, $pool);
                 }
             }
             // set $msg
             if ($refused) {
                 $this->addMsg('msg_refuse_user_success');
             }
         }
         // accept_user-form
         if ($params->getParam('user_accept_submit') != false) {
             foreach ($waiting_user as $user_id) {
                 if ($params->getParam($user_id) == 1) {
                     $accept_user = new poolsUser();
                     // user is accepted
                     $accept_user->user_id = $user_id;
                     $accept_user->pool_id = $pool->id;
                     $accept_user->find(true);
                     $accept_user->wait = 0;
                     $accept_user->res_to_free = 1;
                     $accept_user->update();
                     $accepted = TRUE;
                     $accepted_mail = new user();
                     $accepted_mail->get($user_id);
                     $mail->send("user_accepted", $accepted_mail, $pool);
                 }
             }
             // set $msg
             if ($accepted) {
                 $this->addMsg('msg_accept_user_success');
             }
         }
         // add Admin
         if ($params->getParam('action') == 'new_admin') {
             if ($params->getParam('really') == 'yes') {
                 $pool->addAdmin($params->getParam('user'));
                 $this->addMsg('msg_add_admin');
                 $new_admin = new user();
                 $new_admin->get($params->getParam('user'));
                 $mail->send('new_admin', $new_admin, $pool);
             } else {
                 $add_admin = new user();
                 $add_admin->get($params->getParam('user'));
                 $this->really_add_admin = $add_admin;
             }
         }
         // kick_member
         if ($params->getParam('action') == 'kick_user') {
             if ($params->getParam('really') == 'yes') {
                 $pool->removeMember($params->getParam('user'));
                 $this->addMsg('msg_kick_member');
                 $kicker = new user();
                 $kicker->get($params->getParam('user'));
                 $mail->send('kick_member', $kicker, $pool);
             } else {
                 $kick_member = new user();
                 $kick_member->get($params->getParam('user'));
                 $this->really_kick_member = $kick_member;
             }
         }
         $pool_new_admins = new poolsUser();
         $pool_new_admins->pool_id = $pool->id;
         $pool_new_admins->wait = 0;
         $pool_new_admins->find();
         $new_admins = array();
         while ($pool_new_admins->fetch()) {
             if (!$pool->isAdmin($pool_new_admins->user_id)) {
                 $pool_new_admin = new user();
                 $pool_new_admin->get($pool_new_admins->user_id);
                 $new_admins[] = clone $pool_new_admin;
             }
         }
         $this->new_admins = $new_admins;
         $pool_kick_nutzis = new poolsUser();
         $pool_kick_nutzis->pool_id = $pool->id;
         $pool_kick_nutzis->wait = 0;
         $pool_kick_nutzis->find();
         $kick_user = array();
         while ($pool_kick_nutzis->fetch()) {
             if (!$pool->isAdmin($pool_kick_nutzis->user_id)) {
                 $pool_kick_nutzi = new user();
                 $pool_kick_nutzi->get($pool_kick_nutzis->user_id);
                 $kick_user[] = clone $pool_kick_nutzi;
             }
         }
         $this->kick_user = $kick_user;
         // Waiting User
         $wait_users = new poolsUser();
         $wait_users->pool_id = $pool->id;
         $wait_users->wait = "1";
         if ($wait_users->find()) {
             $waiting_user = array();
             while ($wait_users->fetch()) {
                 $wait_user = new user();
                 $wait_user->get($wait_users->user_id);
                 $waiting_user[] = array("obj" => clone $wait_user, "comments" => $wait_users->comments);
             }
             $this->waiting_user = $waiting_user;
         }
         // delete pool
         if ($pool->isLastAdmin($this->user->id)) {
             $this->lastadmin = true;
         }
         if ($params->getParam('action') == 'delpool') {
             $this->reallydelpool = true;
             if ($params->getParam('really') == 'yes') {
                 $pool->deleteAll();
                 $this->switchPage('mysite&msg=msg_delpool_success');
             }
         }
         $this->pool = $pool;
     }
 }
 // kick admin-form
 if ($_GET['action'] == 'kick_admin') {
     // add admin if given
     if (isset($_POST['add_admin_submit'])) {
         $pool = new pools();
         $pool->get($_GET['pool_id']);
         $pool->addAdmin($_POST['add_admin_select']);
     }
     $pool_admin_del = new poolsAdmin();
     $pool_admin_del->pool_id = $_GET['pool_id'];
     if ($pool_admin_del->find() > 1) {
         $pool_admin_del->user_id = $_GET['user_id'];
         $pool_admin_del->delete();
         $deleted = true;
     } else {
         $pool_user_new = new poolsUser();
         $pool_user_new->pool_id = $_GET['pool_id'];
         if ($pool_user_new->find() > 1) {
             include './inc/adminHeader.php';
             echo '<p class="headline">Neuen Admin ernennen</p>';
             echo '<p class="standard">Die NutziGem deren Admin gelöscht werden soll, hat nur einen, Du musst einen neuen ernennen.</p>';
             echo '<p class="standard">
     <form action="./admin.php?action=kick_admin&pool_id=' . $_GET['pool_id'] . '&user_id=' . $_GET['user_id'] . '&server_password='******'" method="POST">
       <select name="add_admin_select">';
             while ($pool_user_new->fetch()) {
                 $pool_user_new->fetchUser();
                 if (!$pool_user_new->user->isAdmin($pool_user_new->pool_id)) {
                     echo '<option value="' . $pool_user_new->user->id . '">' . $pool_user_new->user->name . '</option>';
                 }
             }
             echo '  </select>
 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');
     // for redirection
     if ($params->getParam('refer') == 'mysite') {
         $this->refer = 'mysite';
     } else {
         $this->refer = 'showpool';
     }
     // res_free_page
     $userres = new resFetcher();
     $userres->_order = "name";
     $userres->_user = $this->user->id;
     $userres->search();
     $this->userres = $userres->getAsArray();
     $user_new_pool = new pools();
     $user_new_pool->id = $params->getParam('pool_id');
     if ($user_new_pool->find(true)) {
         $this->user_new_pool = $user_new_pool;
         $user_new_pools = new poolsUser();
         $user_new_pools->pool_id = $user_new_pool->id;
         $user_new_pools->user_id = $this->user->id;
         $user_new_pools->find(true);
         if ($user_new_pools->res_to_free == 1) {
             $this->new_pool = true;
         }
         if ($params->getParam('no_free_submit')) {
             $user_new_pools->res_to_free = 0;
             $user_new_pools->update();
             // delete res
             foreach ($this->userres as $res) {
                 $del_res = new poolsResources();
                 $del_res->pool_id = $params->getParam('pool_id');
                 $del_res->res_id = $res->id;
                 $del_res->find();
                 $del_res->delete();
                 $freed = true;
             }
             $this->switchPage($this->refer . '&pool_id=' . $user_new_pools->pool_id . '&msg=msg_freeres_alldeleted');
         } else {
             if ($params->getParam('res_free_submit')) {
                 // delete res
                 foreach ($this->userres as $res) {
                     $del_res = new poolsResources();
                     $del_res->pool_id = $params->getParam('pool_id');
                     $del_res->res_id = $res->id;
                     $del_res->find();
                     $del_res->delete();
                     $freed = true;
                 }
                 foreach ($_POST as $res_id => $doesnmatter) {
                     $free_res = new poolsResources();
                     $free_res->res_id = $res_id;
                     $free_res->pool_id = $params->getParam('pool_id');
                     // insert res
                     if ($doesnmatter == "check") {
                         if (!$free_res->find()) {
                             $free_res->insert();
                             $freed = true;
                         }
                     }
                 }
                 // set $msg
                 if ($freed) {
                     $this->switchPage($this->refer . '&pool_id=' . $user_new_pools->pool_id . '&msg=msg_free_res_success');
                 }
                 $user_new_pools->res_to_free = 0;
                 $user_new_pools->update();
             } else {
                 if (is_array($this->userres)) {
                     $this->free_res = true;
                 } else {
                     $user_new_pools->res_to_free = 0;
                     $user_new_pools->update();
                     // switch page with msg
                     $this->switchPage('showpool&pool_id=' . $user_new_pools->pool_id . '&msg=msg_freeres_nores');
                 }
             }
         }
     }
 }
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     // release resources
     if ($this->user->hasResources()) {
         // release no resources-function
         if ($params->getParam('function') == "freenone") {
             $relnone = new poolsUser();
             $relnone->pool_id = $params->getParam('freenone_pool_id');
             $relnone->user_id = $this->user->id;
             $relnone->find(true);
             $relnone->res_to_free = 0;
             $relnone->update();
         }
         $newpools = new poolsUser();
         $newpools->res_to_free = 1;
         $newpools->user_id = $this->user->id;
         if ($params->getParam('new_pool')) {
             $newpool = new pools();
             $newpool->id = $params->getParam('new_pool');
             $newpool->find(true);
             $this->new_pool = clone $newpool;
         } else {
             if ($newpools->find(true)) {
                 $newpools->fetchPool();
                 $this->new_pool = clone $newpools->pool;
             }
         }
     }
     $this->user->fetchPreferences();
     // registered msg
     if ($params->getParam('function') == "noregistered") {
         $this->user->preferences->delete();
         $this->user->preferences->registered_message = "2";
         $this->user->preferences->insert();
     }
     if ($this->user->preferences->registered_message === "1") {
         $this->registered_msg = true;
     }
     // welcome msg
     if ($params->getParam('function') == "nowelcome") {
         $this->user->preferences->delete();
         $this->user->preferences->welcome_message = "2";
         $this->user->preferences->insert();
     }
     if ($this->user->preferences->welcome_message === "2") {
         $this->welcome_msg = false;
     }
     // the table with users pools is generated
     // fetch "Pool"
     $pools_pool = new pools();
     $pools_pool->id = 1;
     $pools_pool->find(true);
     if ($pools_pool->isAdmin($this->user->id)) {
         $this->mypoolstable_thirdcol = true;
         $this->mypoolstable[] = array("id" => $pools_pool->id, "name" => $pools_pool->name, "area" => $pools_pool->area, "links" => '<a href="./index.php?page=pooldata&pool_id=' . $pools->id . '">' . $lang->getMsg('mysite_poolsadmintable_changedatalink') . '</a> | <a href="./index.php?page=pooladmin&pool_id=' . $pools->id . '">' . $lang->getMsg('mysite_poolsadmintable_adminlink') . '</a>');
     } else {
         $this->mypoolstable[] = array("id" => $pools_pool->id, "name" => $pools_pool->name, "area" => $pools_pool->area);
     }
     // fetch all other pools
     $pools = new poolsFetcher();
     $pools->_user = $this->user->id;
     $pools->_order = "name";
     $pools->search();
     while ($pools->fetch()) {
         if ($pools->id != 1) {
             if ($pools->isAdmin($this->user->id)) {
                 $this->mypoolstable_thirdcol = true;
                 $this->mypoolstable[] = array("id" => $pools->id, "name" => $pools->name, "area" => $pools->area, "links" => '<a href="./index.php?page=pooldata&pool_id=' . $pools->id . '">' . $lang->getMsg('mysite_poolsadmintable_changedatalink') . '</a> | <a href="./index.php?page=pooladmin&pool_id=' . $pools->id . '">' . $lang->getMsg('mysite_poolsadmintable_adminlink') . '</a>');
             } else {
                 $this->mypoolstable[] = array("id" => $pools->id, "name" => $pools->name, "area" => $pools->area);
             }
         }
     }
     // fetch all borrowed resources
     $borrowed = new resBorrowed();
     $borrowed->user_id = $this->user->id;
     if ($borrowed->find()) {
         $this->borrowed = array();
         while ($borrowed->fetch()) {
             $borrowed->fetchRes();
             $borrowed->res->fetchUser();
             $this->borrowed[] = clone $borrowed->res;
         }
     }
 }
 function formResData($name, $res_id = 0, $user)
 {
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $cats = services::getService('cats');
     $this->form($name);
     if ($params->getParam('res_id')) {
         $this->addElement('hidden', 'res_id', $params->getParam('res_id'));
         // Categories
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change(this.value, document.ResDataForm.res_id.value)'));
     } else {
         $this->addElement('select', 'resdata_cat', $lang->getMsg('resdata_form_category'), $cats->getAll(), array('onchange' => 'resdata_cat_change_new(this.value)'));
     }
     $this->addElement('text', 'name', $lang->getMsg('resdata_form_name'), array('size' => 40, 'maxlength' => 255));
     $this->addElement('textarea', 'description', $lang->getMsg('resdata_form_description'), array('rows' => 7, 'cols' => 40));
     // fetch additional attributes e.g. form-fields for chosen category
     if ($params->getParam('cat')) {
         $cat = $params->getParam('cat');
         $this->addElement('hidden', 'cat', $cat);
         $attributes = new attributes();
         $attributes->category_id = $cat;
         if ($attributes->find()) {
             while ($attributes->fetch()) {
                 if ($attributes->type == "string") {
                     if ($attributes->name == "isbn") {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                         $this->addElement('submit', 'resdata_' . $attributes->name . '_submit', $lang->getMsg('resdata_form_' . $attributes->name . '_submit'), "asd");
                     } else {
                         $this->addElement('text', 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), array('size' => 30, 'maxlength' => 255));
                     }
                 }
                 if ($attributes->type == "select") {
                     $keys = new attributesSelectKeys();
                     $keys->attribute_id = $attributes->id;
                     $keys->find();
                     $options = array();
                     $options[0] = "----";
                     while ($keys->fetch()) {
                         $options[$keys->key] = $lang->getMsg('resdata_form_select_' . $keys->value);
                     }
                     sort($options);
                     $select_elements = array();
                     for ($i = 1; $attributes->amount >= $i; ++$i) {
                         $select_elements[] =& HTML_QuickForm::createElement('select', $i, null, $options);
                     }
                     $this->addGroup($select_elements, 'resdata_' . $attributes->name, $lang->getMsg('resdata_form_' . $attributes->name), ' ');
                 }
             }
         }
     }
     $this->addElement('select', 'type', $lang->getMsg('resdata_form_type'), array("2" => $lang->getMsg('resdata_form_type_borrow'), "1" => $lang->getMsg('resdata_form_type_give')));
     $free_pool = new poolsUser();
     $free_pool->user_id = $user->id;
     $free_pool->wait = 0;
     $free_pool->find();
     $free_pools = array();
     while ($free_pool->fetch()) {
         $free_pool->fetchPool();
         $free_pools[] =& HTML_QuickForm::createElement('checkbox', $free_pool->pool->id, null, ' ' . $free_pool->pool->name, $free_pool->pool->id);
     }
     $this->addGroup($free_pools, 'free_pools', $lang->getMsg('resdata_form_pools'), '<br>');
     $this->addElement('submit', 'submit', $lang->getMsg('resdata_form_submit'));
     // rules
     if (!$_POST['resdata_isbn_submit']) {
         $this->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
     // presets
     if ($params->getParam('resdata_isbn_submit') && is_isbn($params->getParam('resdata_isbn'))) {
         $lastletter = 0;
         $isbnfound = 0;
         $firstletter = substr($params->getParam('resdata_isbn'), 0, 1);
         if ($firstletter == 0 || $firstletter == 1) {
             $urlendings = array('com', 'co.uk', 'de', 'jp', 'fr', 'ca');
         } else {
             if ($firstletter == 2) {
                 $urlendings = array('fr', 'de', 'com', 'co.uk', 'jp', 'ca');
             } else {
                 if ($firstletter == 3) {
                     $urlendings = array('de', 'com', 'co.uk', 'jp', 'fr', 'ca');
                 } else {
                     if ($firstletter == 4) {
                         $urlendings = array('jp', 'de', 'com', 'co.uk', 'fr', 'ca');
                     } else {
                         $urlendings = array('com', 'co.uk', 'de', 'fr', 'ca', 'jp');
                     }
                 }
             }
         }
         $lastletters = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'x');
         foreach ($urlendings as $urlending) {
             foreach ($lastletters as $lastletter) {
                 if ($isbnfound == 0) {
                     $url = "http://ecs.amazonaws." . $urlending . "/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=1WFW5KS6EFZ0M8690ZR2&Operation=ItemLookup&ItemId=" . substr($params->getParam('resdata_isbn'), 0, 9) . $lastletter . "&ResponseGroup=Medium&type=lite&f=xml";
                     $xml = file_get_contents($url);
                     if (!strpos($xml, 'is not a valid value for ItemId')) {
                         $isbnfound = true;
                     }
                 }
             }
         }
         $first = strpos($xml, '<Item>') + 6;
         $sec = strpos($xml, '</Item>');
         $newxml = substr($xml, $first, $sec - $first);
         $newxml = unhtmlentities($newxml);
         // title
         $first = strpos($newxml, '<Title>') + 7;
         $sec = strpos($newxml, '</Title>');
         $title = substr($newxml, $first, $sec - $first);
         // binding
         $first = strpos($newxml, '<Binding>') + 9;
         $sec = strpos($newxml, '</Binding>');
         $binding = substr($newxml, $first, $sec - $first);
         // publisher
         $first = strpos($newxml, '<Label>') + 7;
         $sec = strpos($newxml, '</Label>');
         $publisher = substr($newxml, $first, $sec - $first);
         // publication date
         $first = strpos($newxml, '<PublicationDate>') + 17;
         $sec = strpos($newxml, '</PublicationDate>');
         $publicationdate = substr($newxml, $first, $sec - $first);
         // number of pages
         $first = strpos($newxml, '<NumberOfPages>') + 15;
         $sec = strpos($newxml, '</NumberOfPages>');
         $numberofpages = substr($newxml, $first, $sec - $first);
         // author(s)
         $authors = array();
         while (strstr($newxml, '<Author>')) {
             $first = strpos($newxml, '<Author>') + 8;
             $sec = strpos($newxml, '</Author>');
             $authors[] = substr($newxml, $first, $sec - $first);
             $newxml = substr($newxml, $sec + 9);
         }
         foreach ($authors as $key => $author) {
             if ($key != 0) {
                 $authors_field .= "; ";
             }
             $authors_field .= $this->changeAuthor($author);
         }
         // description
         $first = strpos($newxml, '<EditorialReviews><EditorialReview><Source>Aus der Amazon.de-Redaktion</Source><Content>') + 88;
         $sec = strpos($newxml, '</Content></EditorialReview></EditorialReviews>');
         $description = substr($newxml, $first, $sec - $first);
         $description = substr($description, 0, strrpos($description, '--'));
         // name
         if ($authors_field) {
             $name = $authors_field . ": " . $title;
         } else {
             $name = $title;
         }
         $this->setDefaults(array('resdata_title' => $title, 'name' => $name, 'description' => $description, 'resdata_authors' => $authors_field, 'resdata_binding' => $binding, 'resdata_number_of_pages' => $numberofpages, 'resdata_publication_date' => $publicationdate, 'resdata_publisher' => $publisher, 'resdata_isbn' => $params->getParam('resdata_isbn')));
     }
     if ($params->getParam('res_id')) {
         $free_pool = new poolsResources();
         $free_pool->res_id = $params->getParam('res_id');
         $free_pool->find();
         $free_pools_presets = array();
         while ($free_pool->fetch()) {
             $free_pools_presets[$free_pool->pool_id] = 1;
         }
         $changeform_res = new resources();
         $changeform_res->get($params->getParam('res_id'));
         $this->setDefaults(array('name' => $changeform_res->name, 'type' => $changeform_res->type, 'description' => $changeform_res->description, 'resdata_cat' => $changeform_res->cat, 'free_pools' => $free_pools_presets, 'public' => $changeform_res->is_public));
         // presets for additional fields
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $this->setDefaults(array('resdata_cat' => $cat));
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string_presets = new attributesString();
                         $attr_string_presets->res_id = $params->getParam('res_id');
                         $attr_string_presets->attribute_id = $attributes->id;
                         $attr_string_presets->find(true);
                         $this->setDefaults(array('resdata_' . $attributes->name => $attr_string_presets->value));
                     }
                     if ($attributes->type == "select") {
                         $attr_select_presets = new attributesSelect();
                         $attr_select_presets->res_id = $params->getParam('res_id');
                         $attr_select_presets->attribute_id = $attributes->id;
                         $attr_select_presets->find();
                         $i = 1;
                         while ($attr_select_presets->fetch()) {
                             $this->setDefaults(array("resdata_" . $attributes->name . "[" . $i . "]" => $attr_select_presets->value));
                             ++$i;
                         }
                     }
                 }
             }
         }
     } else {
         if (isset($pool)) {
             $free_pools_presets[$pool->id] = 1;
             $this->setDefaults(array('type' => 2, 'public' => 0, 'free_pools' => $free_pools_presets));
         }
     }
     if ($params->getParam('cat')) {
         $this->setDefaults(array('resdata_cat' => $params->getParam('cat')));
     }
 }
 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();
 }