コード例 #1
0
 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');
     }
 }
コード例 #2
0
 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();
 }
コード例 #3
0
 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');
                 }
             }
         }
     }
 }
コード例 #4
0
 function removeAllRes()
 {
     $remove_res = new poolsResources();
     $remove_res->pool_id = $this->id;
     $remove_res->delete();
 }