public function fullAction($reception = null)
 {
     $this->view->setVar("TopMenuSelected", 'work');
     $this->view->setVar("MenuSelected", 'search');
     $this->view->setVar("MenuItemActive", $reception);
     if (!empty($reception)) {
         switch ($reception) {
             case 'package':
                 $this->view->setVar("StationsAll", Stations::getStations());
                 $this->view->setVar("PackageStatusAll", References::getPackageStatus());
                 $this->view->setVar("CountriesAll", References::getCountries());
                 $this->view->setVar("result_search", Package::getAll());
                 if ($this->request->get('submit')) {
                     $this->view->setVar("result_search", Package::findPackages($this->request->get(), Users::getStationId($this)));
                     $this->view->setVar("post", $this->request->get());
                     $view = 'form_' . $reception;
                 } else {
                     $view = 'form_' . $reception;
                 }
                 View::addJs($this, ['/js/async/jquery.mb.browser.js', '/js/async/jquery.mousewheel.js', '/js/async/calendar_date-time.js']);
                 View::addCss($this, ['/css/calendar_date-time.css']);
                 break;
         }
     }
     $this->view->pick('/search/' . $view);
 }
 public function addAction($reception = null)
 {
     $this->view->setVar("TopMenuSelected", 'work');
     $this->view->setVar("MenuSelected", 'add');
     $this->view->setVar("MenuItemActive", $reception);
     if (!empty($reception)) {
         $this->view->setVar("countries", References::getCountries());
         $this->view->setVar("currency", References::getCurrency());
         $this->view->setVar("units_1", References::getUnits(NULL, array(1))['units']);
         $this->view->setVar("units_34", References::getUnits(NULL, array(3, 4))['units']);
         $this->view->setVar("date_on_reception_default", date('d-m-Y H:i:s'));
         $this->view->pick('/package/' . $reception);
         View::addJs($this, ['/js/async/jquery.tmpl.min.js', '/js/async/scripts_package_add.js', '/js/async/jquery.mb.browser.js', '/js/async/jquery.mousewheel.js', '/js/async/calendar_date-time.js']);
         View::addCss($this, ['/css/calendar_date-time.css']);
     }
     if ($this->request->isPost()) {
         $post = $this->request->getPost();
         $user_id = Users::getId($this);
         $station_id = Users::getStationId($this);
         $package_document = $post['cont_type'];
         if ($package_document == '0') {
             $pcp = $post['pack_cont_pl'];
             $package_contents_places = array();
             for ($i = 0; $i < count($pcp); $i++) {
                 $pcpa = $pcp[$i]['att'];
                 $package_contents_place_attachments = array();
                 for ($j = 0; $j < count($pcpa); $j++) {
                     $package_contents_place_attachments[] = array('description' => $pcpa[$j]['descr'], 'unit_count' => $pcpa[$j]['u_count'], 'units_id' => $pcpa[$j]['units'], 'unit_price' => $pcpa[$j]['price']);
                 }
                 $package_contents_places[] = array('length' => $pcp[$i]['length'], 'width' => $pcp[$i]['width'], 'height' => $pcp[$i]['height'], 'units_id' => $post['pack_cont_pl_units'], 'attachment' => $package_contents_place_attachments);
             }
             $time_arr = explode(' ', $post['date_on_reception']);
             $date_arr = explode('-', $time_arr[0]);
             $date_on_reception = $date_arr[2] . '-' . $date_arr[1] . '-' . $date_arr[0] . ' ' . $time_arr[1];
             for ($i = 0; $i < count($post['package_rec_name']); $i++) {
                 for ($j = 0; $j < count($post['package_send_name']); $j++) {
                     $package_id = Package::addNotDocument($post['package_send_name'][$i], $post['package_send_addr'][$i], $post['package_send_country'][$i], $post['package_rec_name'][$j], $post['package_rec_addr'][$j], $post['package_rec_country'][$j], $station_id, $post['pack_cont_descr_nd'], $post['pack_cont_pl_count_nd'], $post['pack_cont_weight_nd'], $post['pack_cont_curr_nd'], $package_contents_places, $post['pack_cont_comm_nd'], 'null', 'null', $post['package_send_phone'][$i], $post['package_rec_phone'][$j], $post['package_guar'], $date_on_reception);
                     /**/
                     $res = Package::setStatus($package_id[0]['package_add_all_not_document'], 2, 'true', $user_id, 'null');
                     /**/
                 }
             }
         } else {
             for ($i = 0; $i < count($post['package_rec_name']); $i++) {
                 for ($j = 0; $j < count($post['package_send_name']); $j++) {
                     $package_id = Package::addDocument($post['package_send_name'][$i], $post['package_send_addr'][$i], $post['package_send_country'][$i], $post['package_rec_name'][$j], $post['package_rec_addr'][$j], $post['package_rec_country'][$j], $station_id, $post['pack_cont_descr_d'], $post['pack_cont_pl_count_d'], $post['pack_cont_weight_d'], 'null', $post['pack_cont_comm_d'], 'null', 'null', $post['package_send_phone'][$i], $post['package_rec_phone'][$j], $post['package_guar'], $date_on_reception);
                     /**/
                     $res = Package::setStatus($package_id[0]['package_add_all_document'], 2, 'true', $user_id, 'null');
                     /**/
                 }
             }
         }
         //$this->response->redirect('/search/full/package', '/');
         //$this->view->setVar("test", $package_id);
     }
 }
 public function personAction($reception = null, $item_id = null)
 {
     $this->view->setVar("TopMenuSelected", 'work');
     $this->view->setVar("MenuSelected", 'persons');
     $this->view->setVar("MenuItemActive", $reception);
     $messages = array();
     if (!empty($reception)) {
         $view = $reception;
         switch ($reception) {
             case 'add':
                 $this->view->setVar("CountriesAll", References::getCountries());
                 break;
             case 'preview-cache-station':
                 if ($this->request->isPost()) {
                     if ((bool) $this->request->getPost('add')) {
                         View::addMessages($this, [References::addPersonNew($this->request->getPost('full_name'), $this->request->getPost('address'), $this->request->getPost('country_id'), 3, $this->request->getPost('code'), 1, $this->request->getPost('phone'), Users::getStationId($this))]);
                     }
                 }
                 View::addMessages($this, [array('class' => 'alert-info', 'text' => "<p>Перечень записей Адресной книги кэшированных только для этой станции.</p>")]);
                 $this->view->setVar("PersonsCacheAll", References::getPersonsCache(Users::getStationId($this)));
                 break;
             case 'preview-cache':
                 if ($this->request->isPost()) {
                 }
                 View::addMessages($this, [array('class' => 'alert-info', 'text' => "<p>Перечень часто использующихся записей Адресной книги всех станций.</p>")]);
                 $this->view->setVar("PersonsCacheAll", References::getPersonsHot());
                 break;
             case 'preview':
                 if ($this->request->isPost()) {
                     //$messages[] = Users::addUser($this->request->getPost());
                     //$messages[] = Users::deleteUser($this->request->getPost('id'));
                 }
                 View::addMessages($this, [array('class' => 'alert-info', 'text' => "<p>Полный перечень записей Адресной книги всех станций.</p>")]);
                 $this->view->setVar("PersonsCacheAll", References::getPersonsAll());
                 break;
             case 'edit':
                 if (empty($item_id)) {
                     if ($this->request->isPost()) {
                         $this->response->redirect('/administration/user/edit/' . $this->request->getPost('user_id'), '/');
                     }
                     $messages[] = array('class' => 'alert-info', 'text' => "<p><b>Выберите</b> из выпадающего списка <b>профиль пользователя</b>, который нужно изменить.</p>");
                     $this->view->setVar("UsersAll", Users::getUsers());
                 } else {
                     if ($this->request->isPost()) {
                         $messages[] = Users::setUser($this->request->getPost());
                     }
                     $this->view->setVar("User", Users::getUsers($item_id));
                     $this->view->setVar("StationsAll", Stations::getStations());
                     $this->view->setVar("RolesAll", Roles::getRoles());
                     $this->view->setVar("LanguagesAll", References::getLanguages());
                     $this->view->setVar("CurrencyAll", References::getCurrency());
                     $this->view->setVar("Units1", References::getUnits(NULL, array(1))['units']);
                     $this->view->setVar("Units2", References::getUnits(NULL, array(3))['units']);
                     $this->view->setVar("Units3", References::getUnits(NULL, array(4))['units']);
                 }
                 break;
             case 'settings':
                 if ($this->request->isPost()) {
                     $messages[] = Users::addUser($this->request->getPost());
                     //$messages[] = Users::deleteUser($this->request->getPost('id'));
                 }
                 $this->view->setVar("UsersAll", Users::getUsers());
                 break;
         }
         $this->view->pick('/administration/' . "person_" . $view);
     }
     //$this->view->setVar("messages", $messages);
 }
 public static function deleteCountry($id)
 {
     $references = new References();
     $links = References::getCountries($id);
     if (count($links) > 0) {
         if ($links[0]['from_package'] > 0 || $links[0]['from_package_edit'] > 0 || $links[0]['from_stations_list'] > 0) {
             return array('class' => 'alert-warning', 'text' => "<p>Запись <b> " . $links[0]['name'] . " не</b> может быть <b>удалена</b>, так как связана с одной или несколькими записями. Необходимо <b>переопределить</b> или <b>удалить</b> эти связи, после чего повторите попытку.</p>");
         } else {
             $query = "DELETE FROM countries_list WHERE id = {$id}";
             $res = new Phalcon\Mvc\Model\Resultset\Simple(null, $references, $references->getReadConnection()->query($query));
             return array('class' => 'alert-success', 'text' => "<p>Удаление записи <b>" . $links[0]['name'] . "</b> произошло успешно.</p>");
         }
     }
     return array('class' => 'alert-danger', 'text' => "<p>Запись не найдена.</p>");
 }