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;
 }
 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')));
     }
 }
 private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     if ($params->getParam('res_id')) {
         $this->header = $lang->getMsg('resdata_header_change');
         $this->is_change = true;
     } else {
         $this->header = $lang->getMsg('resdata_header_new');
         $this->is_change = false;
     }
     $aItems = $categories->getThisAndBelow(1);
     $sJavaScriptArray = sprintf('new Array(%s)', implode(',', array_keys($aItems)));
     $this->sJavaScriptArray = $sJavaScriptArray;
     if ($_POST['resdata_isbn_submit'] && is_isbn($_POST['resdata_isbn'])) {
         foreach ($_POST as $key => $value) {
             if ($key != 'page' && $key != 'name' && $key != 'description' && $key != 'resdata_authors') {
                 $get .= $key . '=' . $value . '&';
             }
         }
         $this->switchPage('resdata&' . $get);
     }
     // Instantiate the HTML_QuickForm object
     $this->form = new formResData('ResDataForm', $params->getParam($res_id), $this->user);
     $this->new_res_link = false;
     // Try to validate a form
     if ($this->form->validate() && $this->form->exportValue('submit')) {
         $newres = new resources();
         if ($params->getParam('res_id')) {
             $newres->get($params->getParam('res_id'));
         }
         $newres->name = $this->form->exportValue('name');
         $newres->description = $this->form->exportValue('description');
         $newres->cat = $this->form->exportValue('resdata_cat');
         $newres->type = in_array($newres->cat, array_keys($aItems)) ? $this->form->exportValue('type') : 0;
         // insert/update in res-maintable
         if ($params->getParam('res_id')) {
             $newres->update();
         } else {
             $newres->since = time();
             $newres->user_id = $this->user->id;
             $newres->insert();
         }
         $newres->find(true);
         // insert/update in attributes-tables
         $attr_string = new attributesString();
         $attr_string->res_id = $newres->id;
         $attr_string->delete();
         $attr_select = new attributesSelect();
         $attr_select->res_id = $newres->id;
         $attr_select->delete();
         if ($params->getParam('cat')) {
             $cat = $params->getParam('cat');
             $attributes = new attributes();
             $attributes->category_id = $cat;
             if ($attributes->find()) {
                 while ($attributes->fetch()) {
                     if ($attributes->type == "string") {
                         $attr_string = new attributesString();
                         $attr_string->res_id = $newres->id;
                         $attr_string->attribute_id = $attributes->id;
                         // insert
                         $value = $this->form->exportValue('resdata_' . $attributes->name);
                         if ($value != "") {
                             $attr_string->value = $value;
                             $attr_string->insert();
                         }
                     }
                     if ($attributes->type == "select") {
                         $values = $this->form->getElementValue('resdata_' . $attributes->name);
                         if (!is_array($values)) {
                             $values = array($values);
                         }
                         foreach ($values as $value) {
                             if ($value[0] != 0) {
                                 $attr_string = new attributesSelect();
                                 $attr_string->res_id = $newres->id;
                                 $attr_string->attribute_id = $attributes->id;
                                 // insert
                                 $attr_string->value = $value[0];
                                 $attr_string->insert();
                             }
                         }
                     }
                 }
             }
         }
         // add res to pools if given
         $respools = new poolsResources();
         $respools->res_id = $newres->id;
         $respools->delete();
         $res_pools = $this->form->exportValue('free_pools');
         if (is_array($res_pools)) {
             foreach ($res_pools as $pool_id => $bool) {
                 if ($bool) {
                     $newres->addPool($pool_id);
                 }
             }
         }
         if ($params->getParam('res_id')) {
             $params->addParam('msg', 'msg_data_change_success', 'page');
             $this->switchPage('resmanager&function=all');
         } else {
             $this->form->removeElement('resdata_isbn_submit');
             $this->form->freezeForm();
             $this->addMsg('msg_res_insert_success');
             $this->new_res_link = true;
         }
     }
     if ($_POST['resdata_isbn_submit']) {
         $this->form->addRule('name', $lang->getMsg('resdata_form_namenecessary'), 'required');
         $this->form->addRule('resdata_cat', $lang->getMsg('resdata_form_catnecessary'), 'required');
     }
 }
 function deleteAll()
 {
     $aff1 = new resWait();
     $aff2 = new resBorrowed();
     $aff3 = new poolsResources();
     $aff4 = new attributesString();
     $aff5 = new attributesSelect();
     $aff1->res_id = $this->id;
     $aff1->delete();
     $aff2->res_id = $this->id;
     $aff2->delete();
     $aff3->res_id = $this->id;
     $aff3->delete();
     $aff4->res_id = $this->id;
     $aff4->delete();
     $aff5->res_id = $this->id;
     $aff5->delete();
     $this->deletePools();
     return $this->delete();
 }