예제 #1
0
 public function isLoggedIn($redirect = false, $defaultRedirect = true)
 {
     //var_dump(CI::session()->userdata('session_id'));
     //$redirect allows us to choose where a customer will get redirected to after they login
     //$defaultRedirect points is to the login page, if you do not want this, you can set it to false and then redirect wherever you wish.
     $admin = CI::session()->userdata('admin');
     if (!$admin) {
         //check the cookie
         if (isset($_COOKIE['GoCartAdmin'])) {
             //the cookie is there, lets log the customer back in.
             if ($_COOKIE['GoCartAdmin']) {
                 $result = CI::db()->select('*, sha1(username+password) as hash')->get('admin')->row_array();
                 if ($result) {
                     //unset these 2 fields
                     unset($result['password']);
                     unset($result['hash']);
                     CI::session()->set_userdata(['admin' => $result]);
                     if ($redirect) {
                         CI::session()->set_flashdata('redirect', $redirect);
                     }
                     if ($defaultRedirect) {
                         redirect(CI::uri()->uri_string());
                     }
                 }
             }
         }
         if ($redirect && $defaultRedirect) {
             redirect('admin/login');
         }
         return false;
     } else {
         return true;
     }
 }
예제 #2
0
 public function generate()
 {
     $type = CI::uri()->segment(1);
     $slug = CI::uri()->segment(2);
     if (!$type || !$slug) {
         return;
         //return blank
     }
     if ($type == 'category') {
         $category = CI::Categories()->slug($slug);
         if (!$category) {
             return;
         }
         $this->trace_categories($category->id);
     } elseif ($type == 'product') {
         $product = CI::Products()->slug($slug);
         if (!$product) {
             return;
         }
         array_unshift($this->breadcrumbs, ['link' => site_url('product/' . $product->slug), 'name' => $product->name]);
         $this->trace_categories($product->primary_category);
     } elseif ($type == 'page') {
         $page = CI::Pages()->slug($slug);
         if (!$page) {
             return;
         }
         $this->trace_pages($page->id);
     }
     echo GoCart\Libraries\View::getInstance()->get('breadcrumbs', ['breadcrumbs' => $this->breadcrumbs]);
 }
예제 #3
0
function page_loop($parent = 0, $ulattribs = false, $ul = true)
{
    $pages = CI::Pages()->get_pages_tiered();
    $items = false;
    if (isset($pages[$parent])) {
        $items = $pages[$parent];
    }
    if ($items) {
        echo $ul ? '<ul ' . $ulattribs . '>' : '';
        foreach ($items as $item) {
            echo '<li>';
            $chevron = ' <i class="icon-chevron-down dropdown"></i>';
            if ($item->slug == '') {
                //add the chevron if this has a drop menu
                $name = $item->title;
                if (isset($pages[$item->id])) {
                    $name .= $chevron;
                }
                $target = $item->new_window ? ' target="_blank"' : '';
                $anchor = '<a href="' . $item->url . '"' . $target . '>' . $name . '</a>';
            } else {
                //add the chevron if this has a drop menu
                $name = $item->menu_title;
                if (isset($pages[$item->id])) {
                    $name .= $chevron;
                }
                $selected = CI::uri()->segment(2) == $item->slug ? 'class="selected"' : '';
                $anchor = anchor('page/' . $item->slug, $name, $selected);
            }
            echo $anchor;
            page_loop($item->id);
            echo '</li>';
        }
        echo $ul ? '</ul>' : '';
    }
}
예제 #4
0
" class="img-thumbnail" width="137" height="183"/>
                    </a>
            </td>
            <td class="text-center">
                    <a href="<?php 
    echo site_url('/product/' . $product->slug);
    ?>
"><?php 
    echo $product->name;
    ?>
</a>
            </td>							
            <td class="text-center">
                <div class="input-group btn-block">
                    <?php 
    if (CI::uri()->segment(1) == 'cart' && !$product->fixed_quantity) {
        ?>
                        <input class="form-control"  <?php 
        echo $product->fixed_quantity ? 'disabled' : '';
        ?>
 data-product-id="<?php 
        echo $product->id;
        ?>
" data-orig-val="<?php 
        echo $product->quantity;
        ?>
" id="qtyInput<?php 
        echo $product->id;
        ?>
" value="<?php 
        echo $product->quantity;
예제 #5
0
 function print_order()
 {
     $order_id = \CI::uri()->segment(3);
     $action = \CI::uri()->segment(4);
     $data['order'] = \CI::Orders()->getOrder($order_id);
     //echo '<pre>';print_r($data);exit;
     if (empty($action)) {
         $html = \CI::load()->view('print_order_details', $data, true);
         \CI::load()->helper('html_to_pdf');
         convert2pdf($html, $order_id . '.pdf');
         exit;
         echo 'aaa';
         exit;
     } else {
     }
 }
예제 #6
0
 public function get_categories_tiered($admin = false)
 {
     if (!$admin && !empty($this->tiered)) {
         return $this->tiered;
     }
     if (!$admin) {
         CI::db()->where('enabled_' . $this->customer->group_id, 1);
     }
     CI::db()->order_by('sequence');
     CI::db()->order_by('name', 'ASC');
     $categories = CI::db()->get('categories')->result();
     $results = [];
     $results['all'] = [];
     foreach ($categories as $category) {
         // Set a class to active, so we can highlight our current category
         if (CI::uri()->segment(2) == $category->slug && CI::uri()->segment(1) == 'category') {
             $category->active = true;
         } else {
             $category->active = false;
         }
         $results['all'][$category->id] = $category;
         $results[$category->parent_id][$category->id] = $category;
     }
     if (!$admin) {
         $this->tiered = $results;
     }
     return $results;
 }
예제 #7
0
 public function generator($eng, $alt, $can, $con, $hz = 50, $phase = 3)
 {
     /* \CI::load()->library('Setup');
     		\CI::Setup()->set(120);
     		echo (\CI::Setup()->bon_dung(5000, 2, 3));
     		exit;*/
     if ($eng == '' || $alt == '') {
         redirect(site_url());
     }
     $power_factor = 0.8;
     $con = \CI::uri()->segment(5);
     $can = \CI::uri()->segment(6);
     $hz = \CI::uri()->segment(7);
     $phase = \CI::uri()->segment(8);
     $other = \CI::uri()->segment(9);
     if (!empty($this->gen_compare)) {
         $con = $this->gen_compare['con'];
         $can = $this->gen_compare['can'];
         $hz = $this->gen_compare['hz'];
         $phase = $this->gen_compare['phase'];
         $other = $this->gen_compare['other'];
     }
     $engine = \CI::Products()->getProduct($eng);
     $alternator = \CI::Products()->getProduct($alt);
     if (empty($engine) || empty($alternator)) {
         redirect(site_url());
     }
     $engine->manufacturer = \CI::Products()->getManufacturers($engine->manufacturers);
     $alternator->manufacturer = \CI::Products()->getManufacturers($alternator->manufacturers);
     $engine_parameters = \CI::Products()->getParameters($engine->id, 'engines');
     $engine_alternator = \CI::Products()->getParameters($alternator->id, 'alternators', $hz);
     //echo '<pre>';print_r($alternator);exit;
     $data['page_title'] = $engine->name;
     $data['meta'] = $engine->meta;
     $data['seo_title'] = !empty($engine->seo_title) ? $engine->seo_title : $engine->name;
     $data['product'] = $engine;
     $data['engine_parameters'] = $engine_parameters;
     $data['alt'] = $alternator;
     $data['eng'] = $engine;
     $data['engine_alternator'] = $engine_alternator;
     $data['hz'] = $hz;
     $data['phase'] = $phase;
     $generators = array();
     $generators['kVA'] = $generators['kVA_standby'] = $engine_parameters->standby / $power_factor * ($engine_alternator->efficiency * 0.01);
     $generators['kVA_prime'] = $engine_parameters->prime / $power_factor * ($engine_alternator->efficiency * 0.01);
     $generators['price'] = $engine->price_1 + $alternator->price_1;
     if ($engine_alternator->power < $generators['kVA']) {
         $generators['kVA'] = $engine_alternator->power;
     }
     if ($engine->days > $alternator->days) {
         $generators['days'] = $engine->days;
     } else {
         $generators['days'] = $alternator->days;
     }
     $generators['name'] = 'G' . (int) ($hz / 10) . '-' . round($generators['kVA']) . $engine->manufacturer->code . $alternator->manufacturer->code . 'BA';
     //echo '<pre>';print_r($generators);exit;
     $data['generators'] = $generators;
     $data['engine_manufacturer'] = $engine->manufacturer->name;
     $data['alternator_manufacturer'] = $alternator->manufacturer->name;
     //$data['segment_array'] = \CI::uri()->segment_array();
     if (!empty($this->gen_compare)) {
         return $data;
     }
     $this->view('generator', $data);
 }
예제 #8
-1
 public function init()
 {
     $this->load->helper('url');
     if (!file_exists(APPPATH . '/config/database.php')) {
         redirect('install');
         exit;
     }
     session_start();
     //set the session userdata if non-existant
     if (!isset($_SESSION['userdata'])) {
         $_SESSION['userdata'] = [];
     }
     //set newFlashdata if non-existent
     if (!isset($_SESSION['newFlashdata'])) {
         $_SESSION['newFlashdata'] = [];
     }
     //empty out the "oldFlashdata" field
     $_SESSION['oldFlashdata'] = [];
     //shift newFlashdata over to oldFlashdata
     $_SESSION['oldFlashdata'] = $_SESSION['newFlashdata'];
     $_SESSION['newFlashdata'] = [];
     //module list
     $GLOBALS['modules'] = [];
     if (!file_exists(APPPATH . 'config/manifest.php')) {
         $this->load->helper('file');
         $manifest = "<?php defined('BASEPATH') OR exit('No direct script access allowed');\n//DO NOT EDIT THIS FILE\n\n";
         $this->classMap = [];
         $paths = [FCPATH . 'addons', APPPATH . 'modules', APPPATH . 'libraries', APPPATH . 'core'];
         $paymentModules = [];
         $shippingModules = [];
         $themeShortcodes = [];
         $routes = [];
         $modules = [];
         //just modules
         $moduleDirectories = [APPPATH . 'modules', FCPATH . 'addons'];
         foreach ($moduleDirectories as $moduleDirectory) {
             foreach (array_diff(scandir($moduleDirectory), ['..', '.']) as $availableModule) {
                 if (is_dir($moduleDirectory . '/' . $availableModule)) {
                     //create a codeigniter package path to the module.
                     //$this->load->add_package_path($moduleDirectory.'/'.$availableModule);
                     $modules[] = $moduleDirectory . '/' . $availableModule;
                 }
             }
         }
         foreach ($paths as $path) {
             $dir_iterator = new RecursiveDirectoryIterator($path);
             $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
             foreach ($iterator as $file) {
                 if (!is_dir($file)) {
                     $ext = pathinfo($file, PATHINFO_EXTENSION);
                     $filename = pathinfo($file, PATHINFO_FILENAME);
                     if ($ext == 'php') {
                         if ($filename == 'manifest') {
                             include $file;
                         }
                         $this->getPhpClasses((string) $file);
                     }
                 }
             }
         }
         $manifest .= '//ClassMap for autoloader' . "\n" . '$classes = ' . var_export($this->classMap, true) . ';';
         $manifest .= "\n\n" . '//Available Payment Modules' . "\n" . '$GLOBALS[\'paymentModules\'] =' . var_export($paymentModules, true) . ';';
         $manifest .= "\n\n" . '//Available Shipping Modules' . "\n" . '$GLOBALS[\'shippingModules\'] = ' . var_export($shippingModules, true) . ';';
         $manifest .= "\n\n" . '//Theme Shortcodes' . "\n" . '$GLOBALS[\'themeShortcodes\'] = ' . var_export($themeShortcodes, true) . ';';
         $manifest .= "\n\n" . '//Complete Module List' . "\n" . '$GLOBALS[\'modules\'] = ' . var_export($modules, true) . ';';
         $manifest .= "\n\n" . '//Defined Routes' . "\n" . '$routes = ' . var_export($routes, true) . ';';
         //generate the autoload file
         write_file(APPPATH . 'config/manifest.php', $manifest);
     }
     require APPPATH . 'config/manifest.php';
     //load in the database.
     $this->load->database();
     //set up routing...
     $router = new \AltoRouter();
     $base = trim($_SERVER['BASE'], '/');
     if ($base != '') {
         $router->setBasePath('/' . $base);
     }
     //set the homepage route
     $router->map('GET|POST', '/', 'GoCart\\Controller\\Page#homepage');
     //map the routes from the manifest.
     foreach ($routes as $route) {
         $router->map($route[0], $route[1], $route[2]);
     }
     foreach ($GLOBALS['modules'] as $module) {
         $this->load->add_package_path($module);
     }
     //autoloader for Modules
     spl_autoload_register(function ($class) use($classes) {
         if (isset($classes[$class])) {
             include $classes[$class];
         }
     });
     //autoload some libraries here.
     $this->load->model('Settings');
     $this->load->library(['session', 'auth', 'form_validation']);
     $this->load->helper(['file', 'string', 'html', 'language', 'form', 'formatting']);
     //get settings from the DB
     $settings = $this->Settings->get_settings('gocart');
     //loop through the settings and set them in the config library
     foreach ($settings as $key => $setting) {
         //special for the order status settings
         if ($key == 'order_statuses') {
             $setting = json_decode($setting, true);
         }
         //other config items get set directly to the config class
         $this->config->set_item($key, $setting);
     }
     date_default_timezone_set(config_item('timezone'));
     //if SSL is enabled in config force it here.
     if (config_item('ssl_support') && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off')) {
         $this->config->set_item('base_url', str_replace('http://', 'https://', config_item('base_url')));
         redirect(\CI::uri()->uri_string());
     }
     //do we have a dev username & password in place?
     //if there is a username and password for dev, require them
     if (config_item('stage_username') != '' && config_item('stage_password') != '') {
         if (!isset($_SERVER['PHP_AUTH_USER'])) {
             header('WWW-Authenticate: Basic realm="Login to restricted area"');
             header('HTTP/1.0 401 Unauthorized');
             echo config_item('company_name') . ' Restricted Location';
             exit;
         } else {
             if (config_item('stage_username') != $_SERVER['PHP_AUTH_USER'] || config_item('stage_password') != $_SERVER['PHP_AUTH_PW']) {
                 header('WWW-Authenticate: Basic realm="Login to restricted area"');
                 header('HTTP/1.0 401 Unauthorized');
                 echo 'Restricted Location';
                 exit;
             }
         }
     }
     // lets run the routes
     $match = $router->match();
     // call a closure
     if ($match && is_callable($match['target'])) {
         call_user_func_array($match['target'], $match['params']);
     } elseif ($match && is_string($match['target'])) {
         $target = explode('#', $match['target']);
         try {
             $class = new $target[0]();
             call_user_func_array([$class, $target[1]], $match['params']);
         } catch (Exception $e) {
             var_dump($e);
             throw_404();
         }
     } else {
         throw_404();
     }
 }