Esempio n. 1
0
 /**
  * Display method
  *
  * @access public
  */
 public function display()
 {
     $application = \Skeleton\Core\Application::get();
     $module_path = $application->module_path;
     $files = $this->recursive_scan($module_path);
     $modules = [];
     foreach ($files as $file) {
         require_once $file;
         $module_name = str_replace($module_path, '', $file);
         $module_name = str_replace('.php', '', $module_name);
         if ($module_name[0] == '/') {
             $module_name = substr($module_name, 1);
         }
         $module_name = str_replace('/', '_', $module_name);
         $classname = '\\Web_Module_' . $module_name;
         if (class_exists($classname)) {
             $module = new $classname();
             if (is_a($module, '\\Skeleton\\Package\\Api\\Web\\Module\\Call')) {
                 $modules[] = $module;
             }
         }
     }
     $template = \Skeleton\Core\Web\Template::get();
     $template->assign('modules', $modules);
 }
Esempio n. 2
0
 /**
  * Display method
  *
  * @access public
  */
 public function display()
 {
     if (isset($_POST['username']) and isset($_POST['password'])) {
         try {
             $user = \User::authenticate($_POST['username'], $_POST['password']);
             $_SESSION['user'] = $user;
             Session::redirect('/');
         } catch (\Exception $e) {
             Template::get()->assign('error', true);
         }
     }
 }
Esempio n. 3
0
 /**
  * Edit stock for product
  *
  * @access public
  */
 public function display_edit()
 {
     parent::display_edit();
     $template = Template::get();
     $classname = \Skeleton\Package\Stock\Config::$object_stock_interface;
     $product = $classname::get_by_id($_GET['id']);
     if (isset($_POST['product_supplier_id'])) {
         try {
             $product_supplier = \Skeleton\Package\Stock\Supplier::get_by_id($_POST['product_supplier_id']);
             \Skeleton\Package\Stock\Supplier::set_for_object($product, $product_supplier);
         } catch (\Exception $e) {
             $product_supplier = null;
             \Skeleton\Package\Stock\Supplier::set_for_object($product);
         }
         Session::set_sticky('updated', true);
         Session::redirect($this->get_module_path() . '?action=edit&id=' . $product->id);
     }
     $suppliers = \Skeleton\Package\Stock\Supplier::get_all();
     $template->assign('suppliers', $suppliers);
     $supplier = \Skeleton\Package\Stock\Supplier::get_for_object($product);
     $template->assign('product_supplier', $supplier);
     try {
         $stock = \Skeleton\Package\Stock\Stock::get_last_by_object($product);
         $template->assign('stock', $stock->total);
     } catch (\Exception $e) {
         $template->assign('stock', 0);
     }
     $backorder = \Skeleton\Package\Stock\Purchase\Order\Item::get_backorder($product);
     $template->assign('backorder', $backorder);
     $count_backorder = \Skeleton\Package\Stock\Purchase\Order\Item::count_backorder($product);
     $template->assign('count_backorder', $count_backorder);
     if (class_exists('\\Skeleton\\Package\\Delivery\\Item')) {
         $to_deliver = \Skeleton\Package\Delivery\Item::get_undelivered_by_deliverable($product);
         $to_deliver_overview = [];
         foreach ($to_deliver as $delivery_item) {
             if (!isset($to_deliver_overview[$delivery_item->delivery_id])) {
                 $to_deliver_overview[$delivery_item->delivery_id] = 0;
             }
             $to_deliver_overview[$delivery_item->delivery_id]++;
         }
         $template->assign('to_deliver_overview', $to_deliver_overview);
         $template->assign('to_deliver', $to_deliver);
     }
     $pager = new Pager('\\Skeleton\\Package\\Stock\\Stock');
     $pager->add_sort_permission('created');
     $pager->add_sort_permission('id');
     $pager->add_condition('stock_object_id', $product->id);
     $pager->set_sort('id');
     $pager->set_direction('desc');
     $pager->page();
     $template->assign('pager', $pager);
 }
Esempio n. 4
0
 /**
  * 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);
 }
 /**
  * Print label
  *
  * @access public
  */
 public function display_label()
 {
     $this->template = false;
     $shipment = Shipment::get_by_id($_GET['id']);
     $template = Template::Get();
     $file = $shipment->get_courier()->get_label($shipment);
     $file->client_download();
 }
Esempio n. 6
0
 /**
  * Generate the necessary links to navigate the paged result
  *
  * @access private
  */
 private function generate_links()
 {
     $items_per_page = Config::$items_per_page;
     if ($items_per_page == 0) {
         $pages = 0;
     } else {
         $pages = ceil($this->item_count / $items_per_page);
     }
     // Don't make links if there is only one page
     if ($pages == 1) {
         $this->links = '';
         return;
     }
     $str_links = '';
     $links = [];
     if ($this->options['page'] > 1) {
         $links[] = ['page' => 'previous'];
     }
     for ($i = 1; $i <= $pages; $i++) {
         $print = false;
         // Display the first two pages
         if ($i < 2) {
             $print = true;
         }
         // Display the two pages before and after the current one
         if ($i >= $this->options['page'] - 2 and $i <= $this->options['page'] + 2) {
             $print = true;
         }
         // Make sure at least 9 pages are printed all the time
         if ($this->options['page'] < 5 and $i <= 7 or $this->options['page'] > $pages - 5 and $i >= $pages - 6) {
             $print = true;
         }
         // Display the last two pages
         if ($i > $pages - 1) {
             $print = true;
         }
         if ($print === true) {
             if (end($links)['page'] > 0 and end($links)['page'] + 1 != $i) {
             }
             $links[] = ['page' => $i];
             $previous_print = $i;
         }
     }
     if ($this->options['page'] < $pages) {
         $links[] = ['page' => 'next'];
     }
     foreach ($links as $key => $link) {
         $link['active'] = false;
         $links[$key] = $link;
     }
     $qry_str = '';
     if (isset($_SERVER['QUERY_STRING'])) {
         $qry_str = $_SERVER['QUERY_STRING'];
     }
     parse_str($qry_str, $qry_str_parts);
     foreach ($links as $key => $link) {
         if ($link['page'] === 'previous') {
             $number = $this->options['page'] - 1;
         } elseif ($link['page'] === 'next') {
             $number = $this->options['page'] + 1;
         } elseif ($link['page'] == $this->options['page']) {
             $number = $link['page'];
             $link['active'] = true;
             $links[$key] = $link;
         } else {
             $number = $link['page'];
         }
         $hash = $this->create_options_hash($this->options['conditions'], $number, $this->options['sort'], $this->options['direction'], $this->options['joins']);
         $link['hash'] = $hash;
         $qry_str_parts['q'] = $hash;
         if (isset($qry_str_parts['p'])) {
             unset($qry_str_parts['p']);
         }
         $url = self::find_page_uri() . '?' . http_build_query($qry_str_parts);
         $link['url'] = $url;
         $links[$key] = $link;
     }
     $template = \Skeleton\Core\Web\Template::get();
     $template->assign('links', $links);
     $template->assign('classname', $this->classname);
     $template->assign('options', $this->options);
     $output = $template->render('@skeleton-pager\\links.twig');
     $this->links = $output;
 }
Esempio n. 7
0
 /**
  * Change comments
  *
  * @access public
  */
 public function display_change_comments()
 {
     $template = Template::get();
     $purchase_order = \Skeleton\Package\Stock\Purchase\Order::get_by_id($_GET['id']);
     $purchase_order->load_array($_POST['object']);
     $purchase_order->save();
     Session::redirect($this->get_module_path() . '?action=edit&id=' . $purchase_order->id);
 }
Esempio n. 8
0
 /**
  * Handle the request
  *
  * @access public
  */
 public function handle_request()
 {
     $template = \Skeleton\Core\Web\Template::Get();
     // Find out which method to call, fall back to calling displa()
     if (isset($_REQUEST['action']) and method_exists($this, 'display_' . $_REQUEST['action'])) {
         $template->assign('action', $_REQUEST['action']);
         call_user_func([$this, 'display_' . $_REQUEST['action']]);
     } else {
         $this->display();
     }
     // If the module has defined a template, render it
     if ($this->template !== null and $this->template !== false) {
         $template->display($this->template);
     }
 }
Esempio n. 9
0
 /**
  * Create
  *
  * @access public
  */
 public function display_create()
 {
     if (!$this->is_creatable()) {
         throw new \Exception('Cannot create object. Not allowed');
     }
     $template = Template::get();
     /**
      * Get the object
      */
     $pager = $this->get_pager();
     $classname = $pager->get_classname();
     if (isset($_POST['object'])) {
         $object = new $classname();
         $object->load_array($_POST['object']);
         if (is_callable([$object, 'validate'])) {
             $object->validate($errors);
         } else {
             $errors = [];
         }
         if (count($errors) > 0) {
             $template->assign('errors', $errors);
         } else {
             $object->save();
             if ($this->is_editable($object)) {
                 Session::redirect($this->get_module_path() . '?action=edit&id=' . $object->id);
             } else {
                 Session::redirect($this->get_module_path());
             }
         }
     }
     $template->assign('pager', $pager);
     $fields = $classname::get_object_fields();
     foreach ($fields as $key => $definition) {
         if (substr($definition['field'], -3) == '_id') {
             unset($fields[$key]);
         }
         if ($definition['field'] == 'id') {
             unset($fields[$key]);
         }
     }
     $template->assign('default_fields', $fields);
 }