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');
     // use-res logics
     // accept inquiry
     if ($params->getParam('action') == 'wait_res_accept') {
         $wait_res = new resWait();
         $wait_res->get($params->getParam('wait_id'));
         $wait_res->fetchRes();
         // no item
         if ($wait_res->res->type == 0) {
             // delete all interessants
             $wait_res->res->deleteWaiting($wait_res->user_id);
             $wait_res->fetchUser();
             $wait_res->res->fetchUser();
             $mail->send('nogood_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_request_success');
         }
         // give
         if ($wait_res->res->type == 1) {
             // res is given to the new owner
             $wait_res->res->changeOwner($wait_res->user_id);
             $wait_res->fetchUser();
             // delete pool affiliations
             $wait_res->res->deletePools();
             // delete all interessants
             $wait_res->res->deleteWaiting();
             $wait_res->res->fetchUser();
             $mail->send('give_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_give_success');
         }
         // borrow
         if ($wait_res->res->type == 2) {
             // res is borrowed
             $wait_res->res->isBorrowed($wait_res->user_id);
             $wait_res->fetchUser();
             // delete all interessants
             $wait_res->res->deleteWaiting();
             $wait_res->res->fetchUser();
             $mail->send('borrow_accepted', $wait_res->user, $wait_res->res, $wait_res->res->user);
             $this->switchPage('resmanager&msg=msg_borrow_success');
         }
         $this->toDoList();
     }
     // refuse inquiry
     if ($params->getParam('action') == 'wait_res_refuse') {
         $wait_res = new resWait();
         $wait_res->id = $params->getParam('wait_id');
         $wait_res->find(true);
         $waiter = new user();
         $waiter->get($wait_res->user_id);
         $wait_res->fetchRes();
         $wait_res->res->fetchUser();
         $mail->send('refused', $waiter, $wait_res->res, $wait_res->res->user);
         $wait_res->delete();
         $this->toDoList();
         $this->switchPage('resmanager&');
     }
     // res is given back
     if ($params->getParam('action') == 'res_back') {
         $bow_res = new resBorrowed();
         $bow_res->res_id = $params->getParam('res_id');
         if ($bow_res->delete()) {
             $this->switchPage('resmanager&msg=msg_res_back');
         }
     }
     // delete resources
     if ($params->getParam('resdata_del_submit')) {
         foreach ($_POST as $res_id => $doesnmatter) {
             $del_res = new resources();
             // delete res
             $del_res->id = $res_id;
             if ($del_res->deleteAll()) {
                 $deleted = true;
             }
         }
         // set $msg
         if ($deleted) {
             $this->switchPage('resmanager&msg=msg_delres_success');
         }
     }
     $userres = new resFetcher();
     $userres->_order = "name";
     $userres->_user = $this->user->id;
     $userres->search();
     $this->userres = $userres->getAsArray();
     // function is set
     if ($this->res_offers) {
         $this->function = 'offers';
     } else {
         if ($this->borrowed_res) {
             $this->function = 'borrowed';
         } else {
             $this->function = 'all';
         }
     }
     if ($params->getParam('function')) {
         $this->function = $params->getParam('function');
     }
     if (!$this->res_offers && $this->function == 'offers') {
         $this->function = 'borrowed';
     }
     if (!$this->borrowed_res && $this->function == 'borrowed') {
         $this->function = 'all';
     }
 }
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     // process form
     $this->processForm();
     // if a pool is chosen, it is intanciated
     $is_one_pool = false;
     if (!(count(explode("a", $params->getParam('searchwhere'))) > 1)) {
         $pool = new pools();
         $pool->id = $params->getParam('searchwhere');
         $pool->find(true);
         $is_one_pool = true;
     }
     if (!$params->getParam('show_page')) {
         $params->addParam('show_page', 1, 'now');
     }
     // get Attributes
     $attr = new attributes();
     $attr->category_id = $params->getParam('cat');
     if ($attr->find()) {
         while ($attr->fetch()) {
             $this->attributes[] = clone $attr;
         }
     }
     // tabledata is fetched and ordered
     $tabledata = array();
     $res_fetcher = new resFetcher();
     $res_fetcher->_cat = $params->getParam('cat');
     $res_fetcher->_search_string = $params->getParam('searchstring');
     $get_add .= "&searchstring=" . $params->getParam('searchstring');
     $get_add .= "&searchwhere=" . $params->getParam('searchwhere');
     if ($is_one_pool) {
         $res_fetcher->_pools = array($pool->id);
     } else {
         $res_fetcher->_pools = explode("a", $params->getParam('searchwhere'));
     }
     // fetch users pools
     $my_pools_ids = $this->user->getPoolIDs();
     foreach ($my_pools_ids as $pool_id) {
         $userpool = new pools();
         $userpool->id = $pool_id;
         $userpool->find(true);
         $this->pools_get .= $pool_id . 'a';
         $this->pools[] = array($pool_id, $userpool->name);
     }
     if ($params->getParam('order')) {
         $res_fetcher->_order = $params->getParam('order');
     } else {
         $res_fetcher->_order = 'name';
     }
     $res_fetcher->search();
     $showres = $res_fetcher->getAsArray();
     // presets for attributes
     foreach ($this->attributes as $attr_obj) {
         if ($params->getParam('attribute' . $attr_obj->id)) {
             $this->attribute_presets[$attr_obj->id] = $params->getParam('attribute' . $attr_obj->id);
             $get_add .= "&attribute" . $attr_obj->id . "=" . $params->getParam('attribute' . $attr_obj->id);
         }
     }
     // contact and action-colums are build
     $count = 1;
     $page = $params->getParam('show_page');
     foreach ($showres as $show_res) {
         $fitsattr = true;
         foreach ($this->attributes as $attr_obj) {
             // string-type
             if ($params->getParam('attribute' . $attr_obj->id)) {
                 if ($attr_obj->type == "string") {
                     $resattr = new attributesString();
                     $resattr->attribute_id = $attr_obj->id;
                     $resattr->res_id = $show_res->id;
                     if (!$resattr->isLike($params->getParam('attribute' . $attr_obj->id))) {
                         $fitsattr = false;
                     }
                 }
                 if ($attr_obj->type == "select") {
                     $resattr = new attributesSelect();
                     $resattr->attribute_id = $attr_obj->id;
                     $resattr->res_id = $show_res->id;
                     if ($resattr->find()) {
                         $fitsattr = false;
                         while ($resattr->fetch()) {
                             $select_keys = new attributesSelectKeys();
                             $select_keys->key = $resattr->value;
                             $select_keys->find(true);
                             if (stripos($lang->getMsg('resdata_form_select_' . $select_keys->value), $params->getParam('attribute' . $attr_obj->id)) !== false) {
                                 $fitsattr = true;
                             }
                         }
                     } else {
                         $fitsattr = false;
                     }
                 }
             }
         }
         if ($fitsattr) {
             if ($count >= $page * 20 - 19 && $count <= $page * 20) {
                 $contact = "";
                 $action = "";
                 $show_res->fetchUser();
                 // if the pool is browsed or a search is shown, the *_public-variables are proofed, if another pool
                 // is browsed, all userdata ist shown. If only my pools are looked up by a search, all userdata is shown too.
                 // data in the conta	ct-column
                 // userdata is only shown, if he's in at least one of the pools
                 // the logged-in user is a member of
                 // show detalis if ressource id passed
                 $detail = $show_res->id == $params->getParam('res_id');
                 $email = $show_res->user->email;
                 $street = $show_res->user->street;
                 $house = $show_res->user->house;
                 $country = $show_res->user->country;
                 $plz = $show_res->user->plz;
                 $city = $show_res->user->city;
                 $phone = $show_res->user->phone;
                 $user_desc = $show_res->user->description;
                 // show detail: resource
                 if ($detail) {
                     // attributes for detail-article are fetched
                     $attributes = new attributes();
                     $attributes->category_id = $show_res->cat;
                     $attributes->find();
                     $res_attr_array = array();
                     while ($attributes->fetch()) {
                         // string-attributes
                         if ($attributes->type == "string") {
                             $res_attr = new attributesString();
                             $res_attr->res_id = $show_res->id;
                             $res_attr->attribute_id = $attributes->id;
                             if ($res_attr->find(true)) {
                                 $res_attr_array[] = array("value" => $res_attr->value, "name" => 'resdata_form_' . $attributes->name);
                             }
                         }
                         // select-attributes
                         if ($attributes->type == "select") {
                             $res_attr = new attributesSelect();
                             $res_attr->res_id = $show_res->id;
                             $res_attr->attribute_id = $attributes->id;
                             if ($res_attr->find()) {
                                 $value = "";
                                 while ($res_attr->fetch()) {
                                     $keys = new attributesSelectKeys();
                                     $keys->key = $res_attr->value;
                                     $keys->attribute_id = $res_attr->attribute_id;
                                     $keys->find(true);
                                     $value = $value . $lang->getMsg('resdata_form_select_' . $keys->value) . '&nbsp;';
                                 }
                                 $res_attr_array[] = array("value" => $value, "name" => 'resdata_form_' . $attributes->name);
                             }
                         }
                     }
                     if ($this->user->inMine($show_res->user->id)) {
                         if ($show_res->user->id == $this->user->id) {
                             $prove_public = 2;
                         } else {
                             $prove_public = false;
                         }
                     } else {
                         $prove_public = true;
                     }
                 } else {
                     $prove_public = false;
                 }
                 $is_waiting = new resWait();
                 $is_waiting->user_id = $this->user->id;
                 $is_waiting->res_id = $show_res->id;
                 if (strlen($show_res->name) > 60) {
                     $show_res->name = substr($show_res->name, 0, 60) . '...';
                 }
                 $act_row = array('res_id' => $show_res->id, 'name' => $show_res->name, 'description' => $show_res->description, 'type' => $show_res->type, 'resolvetype' => $this->resolveType($show_res->type), 'user_id' => $show_res->user->id, 'user_name' => $show_res->user->name, 'own_ressource' => $show_res->user->id == $this->user->id, 'available' => $show_res->isAvailable(), 'is_waiting' => $is_waiting->find(), 'prove_public' => $prove_public, 'detail' => $detail, 'user_email' => $email, 'user_street' => $street, 'user_house' => $house, 'user_country' => $country, 'user_plz' => $plz, 'user_city' => $city, 'user_phone' => $phone, 'user_user_desc' => $user_desc, 'user_email_public' => $show_res->user->email_public, 'user_phone_public' => $show_res->user->phone_public, 'user_plz_city_public' => $show_res->user->plz_city_public);
                 if ($detail) {
                     $act_row = array_merge($act_row, array('attributes' => $res_attr_array));
                     $this->resdata = $act_row;
                 }
                 $tabledata[] = $act_row;
             }
             ++$count;
         }
     }
     --$count;
     $count2 = 1;
     while ($count2 < $count / 20) {
         $this->res_count[] = $count2;
         ++$count2;
     }
     $this->res_count[] = $count2;
     $this->get_add_cat = $get_add;
     $get_add .= "&cat=" . $params->getParam('cat');
     // categories to refine search
     $showcats = $categories->getChildren($params->getParam('cat'));
     if (is_array($showcats)) {
         foreach ($showcats as $cat_id => $cat_name) {
             $show_res = new resFetcher();
             $show_res->_cat = $cat_id;
             $show_res->_search_string = $params->getParam('searchstring');
             if (!$is_one_pool) {
                 $show_res->_pools = explode("a", $params->getParam('searchwhere'));
             } else {
                 $show_res->_pools = array($pool->id);
             }
             $rescounter = $show_res->count();
             if ($rescounter > 0) {
                 $this->cats[] = array("id" => $cat_id, "name" => $cat_name, "count" => $rescounter);
             }
         }
         // order categories after rescount
         $c = 0;
         foreach ($this->cats as $cat) {
             if ($c == 0) {
                 $ocats = array($cat);
             } else {
                 $c2 = 0;
                 while ($c2 <= $c) {
                     if ($cat["count"] <= $ocats[$c2]["count"]) {
                         $before = array_slice($ocats, 0, $c2);
                         $after = array_slice($ocats, $c2);
                         if (is_array($before[0])) {
                             $ocats = array_merge($before, array($cat));
                             if (is_array($after[0])) {
                                 $ocats = array_merge($ocats, $after);
                             }
                         } else {
                             $ocats = array_merge(array($cat), $after);
                         }
                         $c2 = $c + 1;
                     } else {
                         if ($cat["count"] > $ocats[$c2]["count"] && ($cat["count"] <= $ocats[$c2 + 1]["count"] || !$ocats[$c2 + 1]["count"])) {
                             $before = array_slice($ocats, 0, $c2 + 1);
                             $after = array_slice($ocats, $c2 + 1);
                             if (is_array($after[0])) {
                                 $ocats = array_merge(array($cat), $after);
                                 if (is_array($before[0])) {
                                     $ocats = array_merge($before, $ocats);
                                 }
                             } else {
                                 $ocats = array_merge($before, array($cat));
                             }
                             $c2 = $c + 1;
                         }
                     }
                     ++$c2;
                 }
             }
             ++$c;
         }
         if (is_array($ocats)) {
             $this->cats = array_reverse($ocats);
         }
         // add subcategories to the most counting category
         $lowercats = $categories->getChildren($this->cats[0]["id"]);
         if (is_array($lowercats)) {
             foreach ($lowercats as $cat_id => $cat_name) {
                 $show_res = new resFetcher();
                 $show_res->_cat = $cat_id;
                 $show_res->_search_string = $params->getParam('searchstring');
                 if (!$is_one_pool) {
                     $show_res->_pools = explode("a", $params->getParam('searchwhere'));
                 } else {
                     $show_res->_pools = array($pool->id);
                 }
                 $rescounter = $show_res->count();
                 if ($rescounter > 0) {
                     $this->lowercats[] = array("id" => $cat_id, "name" => $cat_name, "count" => $rescounter);
                 }
             }
         }
     }
     $this->get_add = $get_add;
     // table itself
     $table = new tableResBrowser($tabledata, $get_add);
     // page-header
     $this->header = $lang->getMsg('resbrowser_header_search');
     // hierarchie-links
     $parent = $categories->getParent($params->getParam('cat'));
     if ($parent) {
         $hierarchie = array();
         $hierarchie[] = array('id' => $parent, 'name' => $categories->getName($parent));
         $parent = $categories->getParent($parent);
         if ($parent) {
             $hierarchie[] = array('id' => $parent, 'name' => $categories->getName($parent));
         }
         $this->hierarchie = array_reverse($hierarchie);
     } else {
         if ($params->getParam('cat') != 0) {
             $this->hierarchie = array(array('id' => 0, 'name' => $lang->getMsg('cat_all')));
         }
     }
     if ($this->resdata) {
         $this->hierarchie[] = array('id' => $params->getParam('cat'), 'name' => $categories->getName($params->getParam('cat')));
     }
     $this->table = $table;
     $this->pool = $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');
                 }
             }
         }
     }
 }