/**
  * Edit
  *
  * @access public
  */
 public function display_edit()
 {
     $template = Template::get();
     $object = Type::get_by_id($_GET['id']);
     $template->assign('object', $object);
     if (isset($_POST['object'])) {
         $object->load_array($_POST['object']);
         $object->save();
         Session::set_sticky('updated', true);
         Session::redirect($this->get_module_path() . '?action=edit&id=' . $object->id);
     }
     $interface = \Skeleton\I18n\Config::$language_interface;
     $languages = $interface::get_all();
     $template->assign('languages', $languages);
 }
 /**
  * Add packet
  *
  * @access public
  */
 public function display_add_shipment()
 {
     $delivery = \Skeleton\Package\Delivery\Delivery::get_by_id($_GET['id']);
     $shipment = new Shipment();
     $shipment->delivery_id = $delivery->id;
     if ($_POST['address_input'] == 'manual') {
         unset($_POST['shipment']['street']);
         unset($_POST['shipment']['housenumber']);
     } else {
         unset($_POST['shipment']['line1']);
         unset($_POST['shipment']['line2']);
         unset($_POST['shipment']['line3']);
     }
     if (isset($_POST['shipment']['courier'])) {
         list($courier_object_classname, $courier_object_id) = explode('/', $_POST['shipment']['courier']);
         $_POST['shipment']['courier_object_classname'] = $courier_object_classname;
         $_POST['shipment']['courier_object_id'] = $courier_object_id;
         unset($_POST['shipment']['courier']);
     }
     $shipment->load_array($_POST['shipment']);
     $shipment->save();
     foreach ($_POST['shipment_item'] as $deliverable_object_classname => $array) {
         foreach ($array as $deliverable_object_id => $values) {
             $deliverable = $deliverable_object_classname::get_by_id($deliverable_object_id);
             $delivery_items = \Skeleton\Package\Delivery\Item::get_by_delivery_deliverable($delivery, $deliverable);
             // Remove the delivery_items that are already shipped
             foreach ($delivery_items as $key => $delivery_item) {
                 if ($delivery_item->shipment_item_id != 0) {
                     unset($delivery_items[$key]);
                 }
             }
             if (count($delivery_items) < $values['to_ship']) {
                 throw new \Exception('This should not happen, more items are requested for shipment than allowed');
             }
             for ($i = 1; $i <= $values['to_ship']; $i++) {
                 $delivery_item = array_shift($delivery_items);
                 $shipment_item = new \Skeleton\Package\Delivery\Shipment\Item();
                 $shipment_item->delivery_item_id = $delivery_item->id;
                 $shipment_item->shipment_id = $shipment->id;
                 $shipment_item->weight = $values['weight'];
                 $shipment_item->save();
                 $delivery_item->shipment_item_id = $shipment_item->id;
                 $delivery_item->save();
             }
         }
     }
     $shipment->handle();
     $delivery->check_shipped();
     Session::Redirect($this->get_module_path() . '?action=edit&id=' . $delivery->id);
 }
Exemple #3
0
 /**
  * Handle the request and send it to the correct module
  *
  * @access public
  */
 public static function run()
 {
     /**
      * Record the start time in microseconds
      */
     $start = microtime(true);
     mb_internal_encoding('utf-8');
     /**
      * Hide PHP powered by
      */
     header('X-Powered-By: Me');
     /**
      * Parse the requested URL
      */
     $components = parse_url($_SERVER['REQUEST_URI']);
     if (isset($components['query'])) {
         $query_string = $components['query'];
     } else {
         $query_string = '';
     }
     if (isset($components['path']) and $components['path'] !== '/') {
         $request_uri_parts = explode('/', $components['path']);
         array_shift($request_uri_parts);
     } else {
         $request_uri_parts = [];
     }
     $request_uri = '/' . implode('/', $request_uri_parts) . '/';
     // Find out what the hostname is, if none was found, bail out
     if (!empty($_SERVER['SERVER_NAME'])) {
         $hostname = $_SERVER['SERVER_NAME'];
     } elseif (!empty($_SERVER['HTTP_HOST'])) {
         $hostname = $_SERVER['HTTP_HOST'];
     } else {
         throw new \Exception('Not a web request');
     }
     /**
      * Define the application
      */
     try {
         $application = Application::detect($hostname, $request_uri);
     } catch (Exception $e) {
         HTTP\Status::code_404('application');
     }
     /**
      * Handle the media
      */
     if (isset($application->config->detect_media) and $application->config->detect_media === true or !isset($application->config->detect_media)) {
         Media::detect($application->request_relative_uri);
     }
     /**
      * Start the session
      */
     Session::start();
     /**
      * Find the module to load
      *
      * FIXME: this nested try/catch is not the prettiest of things
      */
     $module = null;
     try {
         // Attempt to find the module by matching defined routes
         $module = $application->route($request_uri);
     } catch (\Exception $e) {
         try {
             // Attempt to find a module by matching paths
             $module = Module::get($application->request_relative_uri);
         } catch (\Exception $e) {
             if (Hook::exists('module_not_found')) {
                 Hook::call('module_not_found');
             } else {
                 HTTP\Status::code_404('module');
             }
         }
     }
     /**
      * Set language
      */
     // Set the language to something sensible if it isn't set yet
     if (class_exists('\\Skeleton\\I18n\\Config') and isset(\Skeleton\I18n\Config::$language_interface)) {
         $language_interface = \Skeleton\I18n\Config::$language_interface;
         if (!class_exists($language_interface)) {
             throw new \Exception('The language interface does not exists: ' . $language_interface);
         }
         if (!isset($_SESSION['language'])) {
             if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                 $languages = $language_interface::get_all();
                 foreach ($languages as $language) {
                     if (strpos($_SERVER['HTTP_ACCEPT_LANGUAGE'], $language->name_short) !== false) {
                         $language = $language;
                         $_SESSION['language'] = $language;
                     }
                 }
             }
             if (!isset($_SESSION['language'])) {
                 $language = $language_interface::get_by_name_short($application->config->default_language);
                 $_SESSION['language'] = $language;
             }
         }
         if (isset($_GET['language'])) {
             try {
                 $language = $language_interface::get_by_name_short($_GET['language']);
                 $_SESSION['language'] = $language;
             } catch (\Exception $e) {
                 $_SESSION['language'] = $language_interface::get_by_name_short($application->config->default_language);
             }
         }
         $application->language = $_SESSION['language'];
     }
     if ($module !== null) {
         $module->accept_request();
     }
 }
 /**
  * add_delivery
  *
  * @access public
  */
 public function display_add_delivery()
 {
     $purchase_order = \Skeleton\Package\Stock\Purchase\Order::get_by_id($_GET['id']);
     if (isset($_POST['purchase_order'])) {
         $purchase_order->load_array($_POST['purchase_order']);
         $purchase_order->save();
     }
     if (isset($_POST['delivery'])) {
         foreach ($_POST['delivery'] as $purchase_order_item_id => $amount) {
             $purchase_order_item = \Skeleton\Package\Stock\Purchase\Order\Item::get_by_id($purchase_order_item_id);
             $purchase_order_item->deliver($amount, $purchase_order, 'Delivery for PO' . $purchase_order->id);
         }
     }
     Session::redirect($this->get_module_path() . '?action=edit&id=' . $purchase_order->id);
 }
 /**
  * Logout
  *
  * @access public
  */
 public function display_logout()
 {
     Session::destroy();
     Session::redirect('/');
 }
 /**
  * Delete
  *
  * @access public
  */
 public function display_delete()
 {
     /**
      * Get the pager
      */
     $pager = $this->get_pager();
     $classname = $pager->get_classname();
     $object = $classname::get_by_id($_GET['id']);
     $object->delete();
     Session::redirect($this->get_module_path());
 }
 /**
  * Add a movement
  *
  * @access public
  */
 public function display_add_movement()
 {
     $classname = \Skeleton\Package\Stock\Config::$object_stock_interface;
     $product = $classname::get_by_id($_GET['id']);
     \Skeleton\Package\Stock\Stock::change($product, $_POST['stock_movement']['movement'], $_SESSION['user'], $_POST['stock_movement']['comment']);
     Session::redirect('/' . $this->get_module_path() . '?action=edit&id=' . $product->id);
 }