Ejemplo n.º 1
0
 /**
  * @param string $sql
  * @param bool $noexcept
  * @return bool|stdClass
  * @throws AException
  */
 public function query($sql, $noexcept = false)
 {
     //echo $this->database_name;
     $time_start = microtime(true);
     $sql = $this->_sql_prepare($sql);
     $resource = pg_query($this->connection, $sql);
     $this->result = $resource;
     $time_exec = microtime(true) - $time_start;
     // to avoid debug class init while setting was not yet loaded
     if ($this->registry->get('config')) {
         if ($this->registry->get('config')->has('config_debug')) {
             $backtrace = debug_backtrace();
             ADebug::set_query($sql, $time_exec, $backtrace[2]);
         }
     }
     if ($resource) {
         if (is_resource($resource)) {
             //get last id for inserts
             if (is_int(strpos($sql, 'INSERT INTO'))) {
                 $insert_query = pg_query("SELECT lastval();");
                 $insert_row = pg_fetch_row($insert_query);
                 $this->last_id = $insert_row[0];
             }
             $i = 0;
             $data = array();
             while ($result = pg_fetch_assoc($resource)) {
                 $data[$i] = $result;
                 $i++;
             }
             pg_free_result($resource);
             $query = new stdClass();
             $query->row = isset($data[0]) ? $data[0] : array();
             $query->rows = $data;
             $query->num_rows = $i;
             unset($data);
             return $query;
         } else {
             return TRUE;
         }
     } else {
         if ($noexcept) {
             $this->error = 'AbanteCart Error: ' . pg_result_error($resource) . '<br />' . $sql;
             return FALSE;
         } else {
             throw new AException(AC_ERR_MYSQL, 'Error: ' . pg_result_error($resource) . '<br />' . $sql);
         }
     }
 }
Ejemplo n.º 2
0
 public function query($sql, $noexcept = false, $params = array())
 {
     if (!$noexcept) {
         $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
     }
     $this->statement = $this->connection->prepare($sql);
     $result = false;
     $time_start = microtime(true);
     try {
         if ($this->statement && $this->statement->execute($params)) {
             $data = array();
             if ($this->statement->columnCount()) {
                 while ($row = $this->statement->fetch(PDO::FETCH_ASSOC)) {
                     $data[] = $row;
                 }
                 $result = new stdClass();
                 $result->row = isset($data[0]) ? $data[0] : array();
                 $result->rows = $data;
                 $result->num_rows = $this->statement->rowCount();
             }
         }
     } catch (PDOException $e) {
         $this->error = 'SQL Error: ' . $e->getMessage() . '<br />Error No: ' . $e->getCode() . '<br />SQL:' . $sql;
         if ($noexcept) {
             return false;
         } else {
             throw new AException(AC_ERR_MYSQL, $this->error);
         }
     }
     $time_exec = microtime(true) - $time_start;
     // to avoid debug class init while setting was not yet loaded
     if ($this->registry->get('config')) {
         if ($this->registry->get('config')->has('config_debug')) {
             $backtrace = debug_backtrace();
             ADebug::set_query($sql, $time_exec, $backtrace[2]);
         }
     }
     if ($result) {
         return $result;
     } else {
         $result = new stdClass();
         $result->row = array();
         $result->rows = array();
         $result->num_rows = 0;
         return $result;
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $sql
  * @param bool $noexcept
  * @return bool|stdClass
  * @throws AException
  */
 public function query($sql, $noexcept = false)
 {
     //echo $this->database_name;
     $time_start = microtime(true);
     $resource = mysql_query($sql, $this->connection);
     $time_exec = microtime(true) - $time_start;
     // to avoid debug class init while setting was not yet loaded
     if ($this->registry->get('config')) {
         if ($this->registry->get('config')->has('config_debug')) {
             $backtrace = debug_backtrace();
             ADebug::set_query($sql, $time_exec, $backtrace[2]);
         }
     }
     if ($resource) {
         if (is_resource($resource)) {
             $i = 0;
             $data = array();
             while ($result = mysql_fetch_assoc($resource)) {
                 $data[$i] = $result;
                 $i++;
             }
             mysql_free_result($resource);
             $query = new stdClass();
             $query->row = isset($data[0]) ? $data[0] : array();
             $query->rows = $data;
             $query->num_rows = $i;
             unset($data);
             return $query;
         } else {
             return TRUE;
         }
     } else {
         if ($noexcept) {
             $this->error = 'AbanteCart Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql;
             return FALSE;
         } else {
             throw new AException(AC_ERR_MYSQL, 'Error: ' . mysql_error($this->connection) . '<br />Error No: ' . mysql_errno($this->connection) . '<br />' . $sql);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param string $sql
  * @param bool $noexcept
  * @return bool|stdClass
  * @throws AException
  */
 public function query($sql, $noexcept = false)
 {
     //echo $this->database_name;
     $time_start = microtime(true);
     $result = $this->connection->query($sql);
     $time_exec = microtime(true) - $time_start;
     // to avoid debug class init while setting was not yet loaded
     if ($this->registry->get('config')) {
         if ($this->registry->get('config')->has('config_debug')) {
             $backtrace = debug_backtrace();
             ADebug::set_query($sql, $time_exec, $backtrace[2]);
         }
     }
     if ($result) {
         if (!is_bool($result)) {
             $i = 0;
             $data = array();
             while ($row = $result->fetch_object()) {
                 $data[$i] = (array) $row;
                 $i++;
             }
             $query = new stdClass();
             $query->row = isset($data[0]) ? $data[0] : array();
             $query->rows = $data;
             $query->num_rows = (int) $result->num_rows;
             unset($data);
             return $query;
         } else {
             return TRUE;
         }
     } else {
         if ($noexcept) {
             $this->error = 'AbanteCart Error: ' . $result->error . '<br />' . $sql;
             return FALSE;
         } else {
             throw new AException(AC_ERR_MYSQL, 'Error: ' . $result->error . '<br />' . $sql);
         }
     }
 }
Ejemplo n.º 5
0
 static function warning($name, $code, $msg)
 {
     self::$checkpoints[] = array('name' => $name, 'time' => self::microtime(), 'memory' => memory_get_usage(), 'included_files' => count(get_included_files()), 'queries' => count(self::$queries), 'msg' => $msg, 'code' => $code, 'type' => 'warning');
     self::$_is_error = true;
 }
Ejemplo n.º 6
0
} else {
    unset($session->data['finish']);
}
if ($data_exist && empty($session->data['finish'])) {
    header('Location: ../');
}
if (!empty($session->data['finish']) && $session->data['finish'] == 'true') {
    $request->get['rt'] = 'finish';
}
try {
    // Document
    $document = new ADocument();
    $document->setBase(HTTP_SERVER);
    $registry->set('document', $document);
    // Page Controller
    $page_controller = new APage($registry);
    // Router
    if (!empty($request->get['rt'])) {
        $dispatch = $request->get['rt'];
    } else {
        $dispatch = 'license';
    }
    $page_controller->build('pages/' . $dispatch);
    // Output
    $response->output();
} catch (AException $e) {
    ac_exception_handler($e);
}
//display debug info
ADebug::display();
Ejemplo n.º 7
0
    public function edit()
    {
        //init controller data
        $this->extensions->hk_InitData($this, __FUNCTION__);
        $this->document->addScript($this->view->templateResource('/javascript/jquery/thickbox/thickbox-compressed.js'));
        $this->document->addStyle(array('href' => $this->view->templateResource('/javascript/jquery/thickbox/thickbox.css'), 'rel' => 'stylesheet', 'media' => 'screen'));
        $this->document->resetBreadcrumbs();
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
        $extension = $this->request->get['extension'];
        $this->loadLanguage('extension/extensions');
        $this->loadLanguage($extension . '/' . $extension);
        $store_id = (int) $this->config->get('config_store_id');
        if ($this->request->get_or_post('store_id')) {
            $store_id = $this->request->get_or_post('store_id');
        }
        $ext = new ExtensionUtils($extension, $store_id);
        $settings = $ext->getSettings();
        $extension_info = $this->extensions->getExtensionInfo($extension);
        if (!$extension_info) {
            // if extension is not installed yet - redirect to list
            $this->redirect($this->html->getSecureURL('extension/extensions'));
        }
        /** build aform with settings**/
        $result = array('resource_field_list' => array());
        // store switcher for default store Cntrol Panel only
        if (!$this->config->get('config_store_id')) {
            $stores = array();
            $stores[0] = $this->language->get('text_default');
            $this->loadModel('setting/store');
            $stores_arr = $this->model_setting_store->getStores();
            if (count($stores_arr) > 1) {
                foreach ($stores_arr as $res) {
                    $stores[$res['store_id']] = $res['alias'];
                }
                $switcher = array('name' => 'store_id', 'type' => 'selectbox', 'options' => $stores, 'value' => $store_id, 'note' => $this->language->get('tab_store'), 'style' => 'no-save');
            } else {
                $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => 0);
            }
        } else {
            $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => $store_id);
        }
        array_unshift($settings, $switcher);
        foreach ($settings as $item) {
            $data = array();
            if ($item['name'] == $extension . '_status') {
                $status = $item['value'];
            }
            $data['name'] = $item['name'];
            $data['type'] = $item['type'];
            $data['value'] = $item['value'];
            $data['required'] = (bool) $item['required'];
            if ($item['note']) {
                $data['note'] = $item['note'];
            } else {
                $note_text = $this->language->get($data['name']);
                // if text definition not found - seek it in default settings definitions
                if ($note_text == $data['name']) {
                    $new_text_key = str_replace($extension . '_', 'text_', $data['name']);
                    $note_text = $this->language->get($new_text_key);
                    if ($note_text == $new_text_key) {
                        $note_text = $this->language->get($new_text_key . '_' . $extension_info['type']);
                    }
                }
                $data['note'] = $note_text;
            }
            if ($item['style']) {
                $data['style'] = $item['style'];
            }
            if ($item['attr']) {
                $data['attr'] = $item['attr'];
            }
            if ($item['readonly']) {
                $data['readonly'] = $item['readonly'];
            }
            switch ($data['type']) {
                case 'selectbox':
                case 'multiselectbox':
                case 'checkboxgroup':
                    // if options need to extract from db
                    $data['options'] = $item['options'];
                    if ($item['model_rt'] != '') {
                        //force to load models even before extension is enabled
                        $this->loadModel($item['model_rt'], 'force');
                        $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                        $method_name = $item['method'];
                        if (method_exists($model, $method_name)) {
                            $res = call_user_func(array($model, $method_name));
                            if ($res) {
                                $field1 = $item['field1'];
                                $field2 = $item['field2'];
                                foreach ($res as $opt) {
                                    $data['options'][$opt[$field1]] = $opt[$field2];
                                }
                            }
                        }
                    }
                    if ($data['type'] == 'checkboxgroup' || $data['type'] == 'multiselectbox') {
                        #custom settings for multivalue
                        $data['scrollbox'] = 'true';
                        if (substr($item['name'], -2) != '[]') {
                            $data['name'] = $item['name'] . "[]";
                        }
                    }
                    break;
                case 'resource':
                    $item['resource_type'] = (string) $item['resource_type'];
                    if (!$result['rl_scripts']) {
                        $scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => '', 'object_id' => '', 'types' => $item['resource_type'], 'mode' => 'url'));
                        $result['rl_scripts'] = $scripts->dispatchGetOutput();
                        unset($scripts);
                    }
                    //preview of resource
                    $resource = new AResource($item['resource_type']);
                    $resource_id = $resource->getIdFromHexPath(str_replace($item['resource_type'] . '/', '', $item['value']));
                    $preview = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => $item['name'], 'resource_id' => $resource_id, 'field' => $item['name']));
                    $item['value'] = $preview->dispatchGetOutput();
                    if ($data['value']) {
                        $data = array('note' => $data['note'], 'name' => $item['name'], 'type' => 'hidden');
                        if ($resource_id) {
                            $resource_info = $resource->getResource($resource_id);
                            $data['value'] = $item['resource_type'] . '/' . $resource_info['resource_path'];
                        }
                    }
                    $result['resource_field_list'][$item['name']]['value'] = $item['value'];
                    $result['resource_field_list'][$item['name']]['resource_type'] = $item['resource_type'];
                    $result['resource_field_list'][$item['name']]['resource_id'] = $resource_id;
                    break;
                default:
            }
            $item = HtmlElementFactory::create($data);
            $result['html'][$data['name']] = array('note' => $data['note'], 'value' => $item->getHtml());
        }
        // end building aform
        $this->data['settings'] = $result['html'];
        $this->data['resource_field_list'] = $result['resource_field_list'];
        $this->data['resource_edit_link'] = $this->data['resources_scripts'] = $result['rl_scripts'];
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&store_id=' . $store_id);
        if (isset($this->request->get['restore']) && $this->request->get['restore']) {
            $this->extension_manager->editSetting($extension, $ext->getDefaultSettings());
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_restore_success');
            $this->redirect($this->data['target_url']);
        }
        if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validateSettings($extension, $store_id)) {
            foreach ($settings as $item) {
                if (!isset($this->request->post[$item['name']])) {
                    $this->request->post[$item['name']] = 0;
                }
            }
            $this->extension_manager->editSetting($extension, $this->request->post);
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_success');
            $this->redirect($this->data['target_url']);
        }
        $conflict_resources = $ext->validateResources();
        if (!empty($conflict_resources)) {
            ob_start();
            print_r($conflict_resources);
            $err = ob_get_clean();
            ADebug::warning('resources conflict', AC_ERR_USER_WARNING, $extension . ' Extension resources conflict detected.<br/><pre>' . $err . '</pre>');
        }
        $this->document->setTitle($this->language->get($extension . '_name'));
        $this->document->addBreadcrumb(array('href' => $this->data['target_url'], 'text' => $this->language->get($extension . '_name'), 'separator' => ' :: '));
        $this->data['heading_title'] = $this->language->get($extension . '_name');
        $this->data['text_version'] = $this->language->get('text_version');
        $this->data['text_installed_on'] = $this->language->get('text_installed_on');
        $this->data['text_date_added'] = $this->language->get('text_date_added');
        $this->data['text_license'] = $this->language->get('text_license');
        $this->data['text_dependency'] = $this->language->get('text_dependency');
        $this->data['text_configuration_settings'] = $this->language->get('text_configuration_settings');
        $this->data['button_back'] = $this->html->buildButton(array('name' => 'btn_back', 'text' => $this->language->get('text_back'), 'style' => 'button2'));
        $this->data['button_reload'] = $this->html->buildButton(array('name' => 'btn_reload', 'text' => $this->language->get('text_reload'), 'style' => 'button2'));
        $this->data['button_restore_defaults'] = $this->html->buildButton(array('name' => 'button_restore_defaults', 'text' => $this->language->get('button_restore_defaults'), 'style' => 'button2'));
        $this->data['button_save'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
        $this->data['button_save_green'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button3'));
        $this->data['button_reset'] = $this->html->buildButton(array('name' => 'btn_reset', 'text' => $this->language->get('text_reset'), 'style' => 'button2'));
        $this->data['reload'] = $this->html->getSecureURL('extension/extensions/edit/', '&extension=' . $extension);
        $this->data['back'] = $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']);
        $this->data['update'] = $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id);
        $this->data['dependants_url'] = $this->html->getSecureURL('listing_grid/extension/dependants');
        $form = new AForm();
        $form->setForm(array('form_name' => 'editSettings'));
        $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editSettings', 'attr' => 'confirm-exit="true"', 'action' => $this->html->getSecureURL('extension/extensions/edit/', '&action=save&extension=' . $extension . '&store_id=' . $store_id)));
        if (!$this->extension_manager->validateDependencies($extension, getExtensionConfigXml($extension))) {
            $this->error['warning'] = 'This extension cannot be enabled because required dependency missing or not enabled.';
        }
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }
        if (isset($this->session->data['success'])) {
            $this->data['success'] = $this->session->data['success'];
            unset($this->session->data['success']);
        } else {
            $this->data['success'] = '';
        }
        if (isset($this->session->data['error'])) {
            $this->data['error_warning'] = $this->session->data['error'];
            unset($this->session->data['error']);
        } else {
            $this->data['error'] = '';
        }
        $icon_ext_img_url = HTTP_CATALOG . 'extensions/' . $extension . '/image/icon.png';
        $icon_ext_dir = DIR_EXT . $extension . '/image/icon.png';
        $icon = is_file($icon_ext_dir) ? $icon_ext_img_url : RDIR_TEMPLATE . 'image/default_extension.png';
        $extension_data = array('id' => $extension);
        $missing_extensions = $this->extensions->getMissingExtensions();
        if (!in_array($extension, $missing_extensions)) {
            $extension_data['icon'] = $icon;
            $extension_data['name'] = $this->language->get($extension . '_name');
            $extension_data['version'] = $extension_info['version'];
            $long_datetime_format = $this->language->get('date_format_long') . ' ' . $this->language->get('time_format');
            if ($extension_info['date_installed']) {
                $extension_data['installed'] = dateISO2Display($extension_info['date_installed'], $long_datetime_format);
            }
            if ($extension_info['create_date']) {
                $extension_data['create_date'] = dateISO2Display($extension_info['create_date'], $long_datetime_format);
            }
            $extension_data['license'] = $extension_info['license_key'];
            $extension_data['note'] = $ext->getConfig('note') ? $this->html->convertLinks($this->language->get($extension . '_note')) : '';
            $config = $ext->getConfig();
            if (!empty($config->preview->item)) {
                foreach ($config->preview->item as $item) {
                    if (!is_file(DIR_EXT . $extension . DIR_EXT_IMAGE . (string) $item)) {
                        continue;
                    }
                    $extension_data['preview'][] = HTTPS_EXT . $extension . DIR_EXT_IMAGE . (string) $item;
                }
            }
            if (isset($this->session->data['extension_updates'][$extension])) {
                $extension_data['upgrade'] = array('text' => $this->html->buildButton(array('id' => 'upgradenow', 'name' => 'btn_upgrade', 'text' => $this->language->get('button_upgrade'), 'style' => 'button1')), 'link' => AEncryption::addEncoded_stid($this->session->data['extension_updates'][$extension]['url']));
            }
            $extension_data['help'] = array('text' => $this->html->buildButton(array('name' => 'btn_help', 'text' => $this->language->get('text_help'), 'style' => 'button2')), 'ext_link' => $ext->getConfig('help_link'));
            if ($ext->getConfig('help_file')) {
                $extension_data['help']['file'] = true;
                $extension_data['help']['file_link'] = $this->html->getSecureURL('extension/extension/help', '&extension=' . $this->request->get['extension']);
                $this->data['text_more_help'] = $this->language->get('text_more_help');
            }
            $extension_data['dependencies'] = array();
            $extension_data['extensions'] = $this->extensions->getEnabledExtensions();
            $missing_extensions = $this->extensions->getMissingExtensions();
            $db_extensions = $this->extensions->getDbExtensions();
            if (isset($config->dependencies->item)) {
                foreach ($config->dependencies->item as $item) {
                    $id = (string) $item;
                    if (in_array($id, $db_extensions)) {
                        if (in_array($id, $missing_extensions)) {
                            $class = 'warning';
                            $action = str_replace('%EXT%', $id, $this->language->get('text_missing_extension')) . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
										onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                        } else {
                            if (!$this->config->has($id . '_status')) {
                                $class = 'attention';
                                $action = '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/install', '&extension=' . $id) . '"
								title="' . $this->language->get('text_install') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_install.png" alt="' . $this->language->get('text_install') . '" />' . '</a>' . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                            } else {
                                $action = '<a id="action_edit_' . $id . '" target="_blank" class="btn_action"
												href="' . $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $id) . '"
												title="' . $this->language->get('text_edit') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_edit.png" alt="' . $this->language->get('text_edit') . '" /></a>';
                                if (!(bool) $item['required']) {
                                    $action .= '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/uninstall', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . str_replace('%extension%', $id, $this->language->get('text_uninstall_confirm')) . '\')"
									  title="' . $this->language->get('text_uninstall') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_uninstall.png" alt="' . $this->language->get('text_uninstall') . '" />' . '</a>';
                                }
                            }
                        }
                    } else {
                        $action = '<a href="' . $this->html->getSecureURL('extension/extensions_store', '&extension=' . $id) . '" target="_blank">';
                        $action = str_replace('%extensions_store%', $action, $this->language->get('text_visit_repository'));
                    }
                    $extension_data['dependencies'][] = array('required' => (bool) $item['required'], 'id' => $id, 'status' => ($this->config->has($id . '_status') ? $this->language->get('text_installed') : $this->language->get('text_not_installed')) . ' (' . ($this->config->get($id . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')) . ' )', 'action' => $action, 'class' => $class);
                    unset($class);
                }
            }
        } else {
            // if extension missing
            $extension_data['icon'] = $icon;
            $extension_data['name'] = str_replace('%EXT%', $extension, $this->language->get('text_missing_extension'));
        }
        // additional settings page
        if ($ext->getConfig('additional_settings') && $status) {
            $btn_param = array('name' => 'btn_addsett', 'text' => $this->language->get('text_additional_settings'), 'style' => 'button1');
            $this->data['add_sett']['link'] = $this->html->getSecureURL($ext->getConfig('additional_settings'));
            if ($store_id) {
                $this->loadModel('setting/store');
                $store_info = $this->model_setting_store->getStore($store_id);
                $this->data['add_sett']['link'] = $store_info['config_url'] . '?s=' . ADMIN_PATH . '&rt=' . $ext->getConfig('additional_settings');
                $this->data['add_sett']['onclick'] = 'onclick="return confirm(\'' . $this->language->get('additional_settings_confirm') . '\');"';
            }
            $this->data['add_sett']['text'] = $this->html->buildButton($btn_param);
        }
        $this->data['extension'] = $extension_data;
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
        $this->view->assign('help_url', $this->gen_help_url('extension_edit'));
        $template = 'pages/extension/extensions_edit.tpl';
        //#PR set custom templates for extension settings page.
        if (has_value((string) $config->custom_settings_template)) {
            //build path to template directory.
            $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/";
            $dir_template .= (string) $config->custom_settings_template;
            //validate template and report issue
            if (!file_exists($dir_template)) {
                $warning = new AWarning("Cannot load override template {$dir_template} in extension {$extension}!");
                $warning->toLog()->toDebug();
            } else {
                $template = $dir_template;
            }
        }
        $this->view->batchAssign($this->data);
        $this->processTemplate($template);
        //update controller data
        $this->extensions->hk_UpdateData($this, __FUNCTION__);
    }
 /**
  * load all enabled extensions. 
  * If force parameter provided,load all installed (for admin)
  *
  * @param bool $force_enabled_off
  * @void
  */
 public function loadEnabledExtensions($force_enabled_off = false)
 {
     /**
      * @var Registry
      */
     $registry = Registry::getInstance();
     $ext_controllers = $ext_models = $ext_languages = $ext_templates = array();
     $enabled_extensions = $extensions = array();
     foreach ($this->db_extensions as $ext) {
         //check if extension is enabled and not already in the picked list
         if (($force_enabled_off && has_value($registry->get('config')->get($ext . '_status')) || $registry->get('config')->get($ext . '_status')) && !in_array($ext, $enabled_extensions) && has_value($ext)) {
             $priority = (int) $registry->get('config')->get($ext . '_priority');
             $enabled_extensions[$priority][] = $ext;
             $controllers = $languages = $models = $templates = array('storefront' => array(), 'admin' => array());
             if (is_file(DIR_EXT . $ext . '/main.php')) {
                 /** @noinspection PhpIncludeInspection */
                 include DIR_EXT . $ext . '/main.php';
             }
             $ext_controllers[$ext] = $controllers;
             $ext_models[$ext] = $models;
             $ext_languages[$ext] = $languages;
             $ext_templates[$ext] = $templates;
             $class = 'Extension' . preg_replace('/[^a-zA-Z0-9]/', '', $ext);
             if (class_exists($class)) {
                 $extensions[] = $class;
             }
         }
     }
     $this->setExtensionCollection(new ExtensionCollection($extensions));
     $this->enabled_extensions = array();
     ksort($enabled_extensions);
     foreach ($enabled_extensions as $exts) {
         $this->enabled_extensions = array_merge($this->enabled_extensions, $exts);
     }
     ADebug::variable('List of loaded extensions', $enabled_extensions);
     $this->setExtensionControllers($ext_controllers);
     ADebug::variable('List of controllers used by extensions', $ext_controllers);
     $this->setExtensionModels($ext_models);
     ADebug::variable('List of models used by extensions', $ext_models);
     $this->setExtensionLanguages($ext_languages);
     ADebug::variable('List of languages used by extensions', $ext_languages);
     $this->setExtensionTemplates($ext_templates);
     ADebug::variable('List of templates used by extensions', $ext_templates);
 }
Ejemplo n.º 9
0
 public function callback()
 {
     if (has_value($this->request->get['token']) && has_value($this->request->get['PayerID'])) {
         $this->loadLanguage('default_pp_express/default_pp_express');
         $this->session->data['pp_express_checkout']['token'] = $this->request->get['token'];
         $this->session->data['pp_express_checkout']['PayerID'] = $this->request->get['PayerID'];
         $this->session->data['pp_express_checkout']['currency'] = $this->currency->getCode();
         $this->session->data['payment_method'] = array('id' => 'default_pp_express', 'title' => $this->language->get('text_title'), 'sort_order' => $this->config->get('default_pp_express_sort_order'));
         if (!$this->config->get('default_pp_express_test')) {
             $api_endpoint = 'https://api-3t.paypal.com/nvp';
         } else {
             $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
         }
         $payment_data = array('METHOD' => 'GetExpressCheckoutDetails', 'VERSION' => '98.0', 'USER' => html_entity_decode($this->config->get('default_pp_express_username'), ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($this->config->get('default_pp_express_password'), ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($this->config->get('default_pp_express_signature'), ENT_QUOTES, 'UTF-8'), 'TOKEN' => $this->session->data['pp_express_checkout']['token']);
         ADebug::variable('Paypal Express Debug Log sent callback:', var_export($payment_data, true));
         $curl = curl_init($api_endpoint);
         curl_setopt($curl, CURLOPT_PORT, 443);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
         curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
         $response = curl_exec($curl);
         curl_close($curl);
         $ec_details = $this->_parse_http_query($response);
         ADebug::variable('Paypal Express Debug Log Received callback:', var_export($ec_details, true));
         $this->loadModel('extension/default_pp_express');
         if ($this->customer->isLogged()) {
             $country_id = $this->model_extension_default_pp_express->getCountryIdByCode2($ec_details['SHIPTOCOUNTRYCODE']);
             if (mb_strlen($ec_details['SHIPTOSTATE']) == 2) {
                 $zone_id = $this->model_extension_default_pp_express->getZoneId($country_id, $ec_details['SHIPTOSTATE']);
             } else {
                 $zone_id = $this->model_extension_default_pp_express->getZoneIdByName($country_id, $ec_details['SHIPTOSTATE']);
             }
             $this->tax->setZone($country_id, $zone_id);
             $pp_shipping_data = array('firstname' => $ec_details['FIRSTNAME'], 'lastname' => $ec_details['LASTNAME'], 'address_1' => $ec_details['SHIPTOSTREET'], 'address_2' => has_value($ec_details['SHIPTOSTREET2']) ? $ec_details['SHIPTOSTREET2'] : '', 'city' => $ec_details['SHIPTOCITY'], 'zone_code' => $ec_details['SHIPTOSTATE'], 'zone_id' => $zone_id, 'iso_code_2' => $ec_details['SHIPTOCOUNTRYCODE'], 'country' => $ec_details['SHIPTOCOUNTRYNAME'], 'country_id' => $country_id, 'postcode' => $ec_details['SHIPTOZIP']);
             $this->loadModel('account/address');
             $addresses = $this->model_account_address->getAddresses();
             if (has_value($addresses)) {
                 $pp_str = strtolower(str_replace(' ', '', implode('', $pp_shipping_data)));
                 foreach ($addresses as $addr) {
                     $check_arr = array('firstname' => $addr['firstname'], 'lastname' => $addr['lastname'], 'address_1' => $addr['address_1'], 'address_2' => $addr['address_2'], 'city' => $addr['city'], 'zone_code' => $addr['zone_code'], 'iso_code_2' => $addr['iso_code_2'], 'country' => $addr['country'], 'postcode' => $addr['postcode']);
                     $check_str = strtolower(str_replace(' ', '', implode('', $check_arr)));
                     if ($pp_str == $check_str) {
                         $this->session->data['shipping_address_id'] = $addr['address_id'];
                         break;
                     }
                 }
             }
             if (!has_value($this->session->data['shipping_address_id'])) {
                 $this->session->data['shipping_address_id'] = $this->model_extension_default_pp_express->addShippingAddress($pp_shipping_data);
             }
             $this->session->data['payment_address_id'] = $this->session->data['shipping_address_id'];
             $this->redirect($this->html->getSecureURL('checkout/confirm'));
         } else {
             $country_id = $this->model_extension_default_pp_express->getCountryIdByCode2($ec_details['SHIPTOCOUNTRYCODE']);
             $this->loadModel('localisation/country');
             $country = $this->model_localisation_country->getCountry($country_id);
             $country = $country['name'];
             if (mb_strlen($ec_details['SHIPTOSTATE']) == 2) {
                 $zone_id = $this->model_extension_default_pp_express->getZoneId($country_id, $ec_details['SHIPTOSTATE']);
             } else {
                 $zone_id = $this->model_extension_default_pp_express->getZoneIdByName($country_id, $ec_details['SHIPTOSTATE']);
             }
             $this->session->data['guest']['firstname'] = $ec_details['FIRSTNAME'];
             $this->session->data['guest']['lastname'] = $ec_details['LASTNAME'];
             $this->session->data['guest']['email'] = $ec_details['EMAIL'];
             $this->session->data['guest']['address_1'] = $ec_details['SHIPTOSTREET'];
             $this->session->data['guest']['address_2'] = has_value($ec_details['SHIPTOSTREET2']) ? $ec_details['SHIPTOSTREET2'] : '';
             $this->session->data['guest']['postcode'] = $ec_details['SHIPTOZIP'];
             $this->session->data['guest']['city'] = $ec_details['SHIPTOCITY'];
             $this->session->data['guest']['country'] = $country;
             $this->session->data['guest']['country_id'] = $country_id;
             $this->session->data['guest']['zone'] = $ec_details['SHIPTOSTATE'];
             $this->session->data['guest']['zone_id'] = $zone_id;
             $this->tax->setZone($country_id, $zone_id);
             if ($this->request->get['to_confirm'] == 1) {
                 $this->redirect($this->html->getSecureURL('checkout/guest_step_3'));
             } else {
                 $this->redirect($this->html->getSecureURL('checkout/guest_step_2'));
             }
         }
     }
 }
 public function processPayment($pd, $customer_stripe_id = '')
 {
     $response = '';
     $this->load->model('checkout/order');
     $this->load->language('default_stripe/default_stripe');
     $order_info = $this->model_checkout_order->getOrder($pd['order_id']);
     try {
         require_once DIR_EXT . 'default_stripe/core/stripe_modules.php';
         grantStripeAccess($this->config);
         //build charge data array
         $charge_data = array();
         $charge_data['amount'] = $pd['amount'];
         $charge_data['currency'] = $pd['currency'];
         $charge_data['description'] = $this->config->get('store_name') . ' Order #' . $pd['order_id'];
         $charge_data['statement_descriptor'] = 'Order #' . $pd['order_id'];
         $charge_data['receipt_email'] = $order_info['email'];
         if ($this->config->get('default_stripe_settlement') == 'delayed') {
             $charge_data['capture'] = false;
         } else {
             $charge_data['capture'] = true;
         }
         //build cc details
         $cc_details = array('number' => $pd['cc_number'], 'exp_month' => $pd['cc_expire_month'], 'exp_year' => $pd['cc_expire_year'], 'cvc' => $pd['cc_cvv2'], 'name' => $pd['cc_owner']);
         $cc_details = array_merge($cc_details, array('address_line1' => $order_info['payment_address_1'], 'address_line2' => $order_info['payment_address_2'], 'address_city' => $order_info['payment_city'], 'address_zip' => $order_info['payment_postcode'], 'address_state' => $order_info['payment_zone'], 'address_country' => $order_info['payment_iso_code_2']));
         //we need get the token for the card first
         $token = array();
         $token = Stripe_Token::create(array('card' => $cc_details));
         if (!$token || !$token['id']) {
             $msg = new AMessage();
             $msg->saveError('Stripe failed to get card token for order_id ' . $pd['order_id'], 'Unable to use card for customer' . $customer_stripe_id);
             $response['error'] = $this->language->get('error_system');
             return $response;
         }
         $charge_data['card'] = $token['id'];
         if ($order_info['shipping_method']) {
             $charge_data['shipping'] = array('name' => $order_info['firstname'] . ' ' . $order_info['lastname'], 'phone' => $order_info['telephone'], 'address' => array('line1' => $order_info['shipping_address_1'], 'line2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postal_code' => $order_info['shipping_postcode'], 'state' => $order_info['shipping_zone'], 'country' => $order_info['shipping_iso_code_2']));
         }
         $charge_data['metadata'] = array();
         $charge_data['metadata']['order_id'] = $pd['order_id'];
         if ($this->customer->getId() > 0) {
             $charge_data['metadata']['customer_id'] = (int) $this->customer->getId();
         }
         ADebug::variable('Processing stripe payment request: ', $charge_data);
         $response = Stripe_Charge::create($charge_data);
     } catch (Stripe_CardError $e) {
         // card errors
         $body = $e->getJsonBody();
         $response['error'] = $body['error']['message'];
         $response['code'] = $body['error']['code'];
         return $response;
     } catch (Stripe_InvalidRequestError $e) {
         // Invalid parameters were supplied to Stripe's API
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed with invalid parameters!', 'Stripe payment failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_AuthenticationError $e) {
         // Authentication with Stripe's API failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed to authenticate!', 'Stripe payment failed to authenticate to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_ApiConnectionError $e) {
         // Network communication with Stripe failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment connection has failed!', 'Stripe payment failed connecting to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_Error $e) {
         // Display a very generic error to the user, and maybe send
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment has failed!', 'Stripe processing failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Exception $e) {
         // Something else happened, completely unrelated to Stripe
         $msg = new AMessage();
         $msg->saveError('Unexpected error in stripe payment!', 'Stripe processing failed. ' . $e->getMessage() . "(" . $e->getCode() . ")");
         $response['error'] = $this->language->get('error_system');
         //log in AException
         $ae = new AException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
         ac_exception_handler($ae);
         return $response;
     }
     //we still have no result. something unexpected happend
     if (empty($response)) {
         $response['error'] = $this->language->get('error_system');
         return $response;
     }
     ADebug::variable('Processing stripe payment response: ', $response);
     //Do we have an error? exit with no records
     if ($response['failure_message'] || $response['failure_code']) {
         $response['error'] = $response['failure_message'];
         $response['code'] = $response['failure_code'];
         return $response;
     }
     $message .= 'Order id: ' . (string) $pd['order_id'] . "\n";
     $message .= 'Charge id: ' . (string) $response['id'] . "\n";
     $message .= 'Transaction Timestamp: ' . (string) date('m/d/Y H:i:s', $response['created']);
     if ($response['paid']) {
         //finalize order only if payment is a success
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('config_order_status_id'), $message);
         if ($this->config->get('default_stripe_settlement') == 'auto') {
             //auto complete the order in sattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_settled'));
         } else {
             //complete the order in unsattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_unsettled'));
         }
     } else {
         // Some other error, assume payment declined
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('default_stripe_status_decline'), $message);
         $response['error'] = "Payment has failed! " . $response['failure_message'];
         $response['code'] = $response['failure_code'];
     }
     return $response;
 }
Ejemplo n.º 11
0
 /**
  * @param $file string - full path of file
  * @return string
  */
 public function _fetch($file)
 {
     if (!file_exists($file)) {
         return '';
     }
     ADebug::checkpoint('_fetch ' . $file . ' start');
     extract($this->data);
     ob_start();
     /** @noinspection PhpIncludeInspection */
     require $file;
     $content = ob_get_contents();
     ob_end_clean();
     ADebug::checkpoint('_fetch ' . $file . ' end');
     return $content;
 }
Ejemplo n.º 12
0
 /**
  *  Layout Manager Class to handle layout in the admin
  *  NOTES: Object can be constructed with specific template, page or layout id provided
  * Possible to create an object with no specifics to access layout methods.
  * @param string $tmpl_id
  * @param string $page_id
  * @param string $layout_id
  * @throws AException
  */
 public function __construct($tmpl_id = '', $page_id = '', $layout_id = '')
 {
     if (!IS_ADMIN) {
         // forbid for non admin calls
         throw new AException(AC_ERR_LOAD, 'Error: permission denied to change page layout');
     }
     $this->registry = Registry::getInstance();
     $this->tmpl_id = !empty($tmpl_id) ? $tmpl_id : $this->config->get('config_storefront_template');
     //do check for existance of storefront template in case when $tmpl_id not set
     if (empty($tmpl_id)) {
         //check is template an extension
         $template = $this->config->get('config_storefront_template');
         $dir = $template . DIR_EXT_STORE . DIR_EXT_TEMPLATE . $template;
         $enabled_extensions = $this->extensions->getEnabledExtensions();
         if (in_array($template, $enabled_extensions) && is_dir(DIR_EXT . $dir)) {
             $is_valid = true;
         } else {
             $is_valid = false;
         }
         //check if this is template from core
         if (!$is_valid && is_dir(DIR_ROOT . '/storefront/view/' . $template)) {
             $is_valid = true;
         }
         if (!$is_valid) {
             $this->tmpl_id = 'default';
         } else {
             $this->tmpl_id = $template;
         }
     } else {
         $this->tmpl_id = $tmpl_id;
     }
     //load all pages specific to set template. No cross template page/layouts
     $this->pages = $this->getPages();
     //set current page for this object instance
     $this->_set_current_page($page_id, $layout_id);
     $this->page_id = $this->page['page_id'];
     //preload all layouts for this page and template
     //NOTE: layout_type: 0 Default, 1 Active layout, 2 draft layout, 3 template layout
     $this->layouts = $this->getLayouts();
     //locate layout for the page instance. If not specified for this instance fist active layout is used
     foreach ($this->layouts as $layout) {
         if (!empty($layout_id)) {
             if ($layout['layout_id'] == $layout_id) {
                 $this->active_layout = $layout;
                 break;
             }
         } else {
             if ($layout['layout_type'] == 1) {
                 $this->active_layout = $layout;
                 break;
             }
         }
     }
     //if not layout set, use default (layout_type=0) layout
     if (count($this->active_layout) == 0) {
         $this->active_layout = $this->getLayouts(0);
         if (count($this->active_layout) == 0) {
             $message_text = 'No template layout found for page_id/controller ' . $this->page_id . '::' . $this->page['controller'] . '!';
             $message_text .= ' Requested data: template: ' . $tmpl_id . ', page_id: ' . $page_id . ', layout_id: ' . $layout_id;
             $message_text .= '  ' . genExecTrace('full');
             throw new AException(AC_ERR_LOAD_LAYOUT, $message_text);
         }
     }
     $this->layout_id = $this->active_layout['layout_id'];
     ADebug::variable('Template id', $this->tmpl_id);
     ADebug::variable('Page id', $this->page_id);
     ADebug::variable('Layout id', $this->layout_id);
     // Get blocks
     $this->all_blocks = $this->getAllBlocks();
     $this->blocks = $this->_getLayoutBlocks();
 }
Ejemplo n.º 13
0
 public function edit()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $extension = $this->request->get['extension'];
     if (!$extension) {
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->loadLanguage('extension/extensions');
     $this->loadLanguage($extension . '/' . $extension);
     $store_id = (int) $this->session->data['current_store_id'];
     if ($this->request->get_or_post('store_id')) {
         $store_id = $this->request->get_or_post('store_id');
     }
     $ext = new ExtensionUtils($extension, $store_id);
     $settings = $ext->getSettings();
     $this->data['extension_info'] = $this->extensions->getExtensionInfo($extension);
     if (!$this->data['extension_info']) {
         // if extension is not installed yet - redirect to list
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->data['extension_info']['id'] = $extension;
     $this->data['form_store_switch'] = $this->html->getStoreSwitcher();
     /** build aform with settings**/
     $form = new AForm('HS');
     $form->setForm(array('form_name' => 'editSettings', 'update' => $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id)));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editSettings', 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"', 'action' => $this->html->getSecureURL('extension/extensions/edit/', '&action=save&extension=' . $extension . '&store_id=' . $store_id)));
     $result = array('resource_field_list' => array());
     foreach ($settings as $item) {
         $data = array();
         if ($item['name'] == $extension . '_status') {
             $data['attr'] = ' reload_on_save="true"';
             $status = $item['value'];
             //set sign for confirmation modal about dependendants for disable action
             if ($item['value'] == 1) {
                 $children = $this->extension_manager->getChildrenExtensions($extension);
                 if ($children) {
                     foreach ($children as $child) {
                         if ($this->config->get($child['key'] . '_status')) {
                             $this->data['has_dependants'] = true;
                             break;
                         }
                     }
                 }
             }
         }
         $data['name'] = $item['name'];
         $data['type'] = $item['type'];
         $data['value'] = $item['value'];
         $data['required'] = (bool) $item['required'];
         if ($item['note']) {
             $data['note'] = $item['note'];
         } else {
             $note_text = $this->language->get($data['name']);
             // if text definition not found - seek it in default settings definitions
             if ($note_text == $data['name']) {
                 $new_text_key = str_replace($extension . '_', 'text_', $data['name']);
                 $note_text = $this->language->get($new_text_key);
                 if ($note_text == $new_text_key) {
                     $note_text = $this->language->get($new_text_key . '_' . $this->data['extension_info']['type']);
                 }
             }
             $data['note'] = $note_text;
         }
         if ($item['style']) {
             $data['style'] = $item['style'];
         }
         if ($item['attr']) {
             $data['attr'] = $item['attr'];
         }
         if ($item['readonly']) {
             $data['readonly'] = $item['readonly'];
         }
         switch ($data['type']) {
             case 'selectbox':
             case 'multiselectbox':
             case 'checkboxgroup':
                 // if options need to extract from db
                 $data['options'] = $item['options'];
                 if ($item['model_rt'] != '') {
                     //force to load models even before extension is enabled
                     $this->loadModel($item['model_rt'], 'force');
                     $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                     $method_name = $item['method'];
                     if (method_exists($model, $method_name)) {
                         $res = call_user_func(array($model, $method_name));
                         if ($res) {
                             $field1 = $item['field1'];
                             $field2 = $item['field2'];
                             foreach ($res as $opt) {
                                 $data['options'][$opt[$field1]] = $opt[$field2];
                             }
                         }
                     }
                 }
                 if ($data['type'] == 'checkboxgroup' || $data['type'] == 'multiselectbox') {
                     #custom settings for multivalue
                     $data['scrollbox'] = 'true';
                     if (substr($item['name'], -2) != '[]') {
                         $data['name'] = $item['name'] . "[]";
                     }
                     $data['style'] = "chosen";
                 }
                 break;
             case 'html_template':
                 // if options need to extract from db
                 $data['template'] = $item['template'];
                 $data['options'] = $item['options'];
                 if ($item['model_rt'] != '') {
                     //force to load models even before extension is enabled
                     $this->loadModel($item['model_rt'], 'force');
                     $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                     $method_name = $item['method'];
                     if (method_exists($model, $method_name)) {
                         $data['options'][$method_name] = call_user_func(array($model, $method_name));
                     }
                 }
                 break;
             case 'checkbox':
                 $data['style'] = "btn_switch";
                 if ($item['name'] == $extension . '_status') {
                     $data['style'] .= " status_switch";
                 }
                 break;
             case 'resource':
                 $item['resource_type'] = (string) $item['resource_type'];
                 $data['rl_types'] = array($item['resource_type']);
                 $data['rl_type'] = $item['resource_type'];
                 //check if ID for resource is provided or path
                 if (is_numeric($item['value'])) {
                     $data['resource_id'] = $item['value'];
                 } else {
                     $data['resource_path'] = $item['value'];
                 }
                 if (!$result['rl_scripts']) {
                     $scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => '', 'object_id' => '', 'types' => array($item['resource_type']), 'onload' => true, 'mode' => 'single'));
                     $result['rl_scripts'] = $scripts->dispatchGetOutput();
                     unset($scripts);
                 }
                 break;
             default:
         }
         $html = '';
         //if template process diffrently
         if (has_value((string) $data['template'])) {
             //build path to template directory.
             $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/" . $data['template'];
             //validate template and report issue
             if (!file_exists($dir_template)) {
                 $warning = new AWarning(sprintf($this->language->get('error_could_not_load_override'), $dir_template, $extension));
                 $warning->toLog()->toDebug();
             } else {
                 $this->view->batchAssign($data);
                 $html = $this->view->fetch($dir_template);
             }
         } else {
             $html = $form->getFieldHtml($data);
         }
         $result['html'][$data['name']] = array('note' => $data['note'], 'value' => $html);
     }
     // end building aform
     $this->data['settings'] = $result['html'];
     $this->data['resources_scripts'] = $result['rl_scripts'];
     $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&store_id=' . $store_id);
     //check if we restore settings to default values
     if (isset($this->request->get['restore']) && $this->request->get['restore']) {
         $this->extension_manager->editSetting($extension, $ext->getDefaultSettings());
         $this->cache->delete('settings.extension');
         $this->session->data['success'] = $this->language->get('text_restore_success');
         $this->redirect($this->data['target_url']);
     }
     //check if we save settings with the post
     if ($this->request->is_POST() && $this->_validateSettings($extension, $store_id)) {
         $save_data = $this->request->post;
         foreach ($settings as $item) {
             if (!isset($this->request->post[$item['name']])) {
                 $save_data[$item['name']] = 0;
             }
         }
         $save_data['store_id'] = $store_id;
         $this->extension_manager->editSetting($extension, $save_data);
         $this->cache->delete('settings.extension');
         $this->session->data['success'] = $this->language->get('text_save_success');
         $this->redirect($this->data['target_url']);
     }
     $conflict_resources = $ext->validateResources();
     if (!empty($conflict_resources)) {
         ob_start();
         print_r($conflict_resources);
         $err = ob_get_clean();
         ADebug::warning('resources conflict', AC_ERR_USER_WARNING, $extension . ' Extension resources conflict detected.<br/><pre>' . $err . '</pre>');
     }
     $this->document->setTitle($this->language->get($extension . '_name'));
     $this->document->addBreadcrumb(array('href' => $this->data['target_url'], 'text' => $this->language->get($extension . '_name'), 'separator' => ' :: ', 'current' => true));
     $this->data['heading_title'] = $this->language->get($extension . '_name');
     $this->data['text_version'] = $this->language->get('text_version');
     $this->data['text_installed_on'] = $this->language->get('text_installed_on');
     $this->data['text_date_added'] = $this->language->get('text_date_added');
     $this->data['text_license'] = $this->language->get('text_license');
     $this->data['text_dependency'] = $this->language->get('text_dependency');
     $this->data['text_configuration_settings'] = $this->language->get('text_configuration_settings');
     $this->data['button_back'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_back', 'text' => $this->language->get('text_back')));
     $this->data['button_reload'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_reload', 'text' => $this->language->get('text_reload')));
     $this->data['button_restore_defaults'] = $this->html->buildElement(array('type' => 'button', 'name' => 'button_restore_defaults', 'text' => $this->language->get('button_restore_defaults'), 'href' => $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&reload=1')));
     $this->data['button_save'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_save', 'text' => $this->language->get('button_save')));
     $this->data['button_save_green'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_save', 'text' => $this->language->get('button_save')));
     $this->data['button_reset'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_reset', 'text' => $this->language->get('text_reset')));
     $this->data['reload'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
     $this->data['back'] = $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']);
     $this->data['update'] = $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id);
     $this->data['dependants_url'] = $this->html->getSecureURL('listing_grid/extension/dependants', '&extension=' . $extension);
     if (!$this->extension_manager->validateDependencies($extension, getExtensionConfigXml($extension))) {
         $this->error['warning'] = $this->language->get('error_dependencies');
     }
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     if (isset($this->session->data['error'])) {
         $this->data['error_warning'] = $this->session->data['error'];
         unset($this->session->data['error']);
     } else {
         $this->data['error'] = '';
     }
     //info about available updates
     $upd = $this->cache->get('extensions.updates');
     if (is_array($upd) && in_array($extension, array_keys($upd))) {
         $this->data['info'] = sprintf($this->language->get('text_update_available'), $upd[$extension]['version'], $this->html->getSecureURL('tool/package_installer', '&extension_key=' . $upd[$extension]['installation_key']));
     }
     $missing_extensions = $this->extensions->getMissingExtensions();
     //if extension is missing - do redirect on extensions list with alert!
     if (in_array($extension, $missing_extensions)) {
         $this->session->data['error'] = sprintf($this->language->get('text_missing_extension'), $extension);
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->data['extension_info']['note'] = $ext->getConfig('note') ? $this->html->convertLinks($this->language->get($extension . '_note')) : '';
     $config = $ext->getConfig();
     if (!empty($config->preview->item)) {
         foreach ($config->preview->item as $item) {
             if (!is_file(DIR_EXT . $extension . DIR_EXT_IMAGE . (string) $item)) {
                 continue;
             }
             $this->data['extension_info']['preview'][] = HTTPS_EXT . $extension . DIR_EXT_IMAGE . (string) $item;
         }
         //image gallery scripts and css for previews
         $this->document->addStyle(array('href' => RDIR_TEMPLATE . 'javascript/blueimp-gallery/css/bootstrap-image-gallery.css', 'rel' => 'stylesheet'));
         $this->document->addStyle(array('href' => RDIR_TEMPLATE . 'javascript/blueimp-gallery/css/blueimp-gallery.min.css', 'rel' => 'stylesheet'));
         $this->document->addScript(RDIR_TEMPLATE . 'javascript/blueimp-gallery/jquery.blueimp-gallery.min.js');
         $this->document->addScript(RDIR_TEMPLATE . 'javascript/blueimp-gallery/bootstrap-image-gallery.js');
     }
     if ($ext->getConfig('help_link')) {
         $this->data['extension_info']['help'] = array('ext_link' => array('text' => $this->language->get('text_developer_site'), 'link' => $ext->getConfig('help_link')));
     }
     if ($ext->getConfig('help_file')) {
         $this->data['extension_info']['help']['file'] = array('link' => $this->html->getSecureURL('extension/extension/help', '&extension=' . $this->request->get['extension']), 'text' => $this->language->get('button_howto'));
     }
     $this->data['extension_info']['dependencies'] = array();
     $this->data['extension_info']['extensions'] = $this->extensions->getEnabledExtensions();
     $missing_extensions = $this->extensions->getMissingExtensions();
     $db_extensions = $this->extensions->getDbExtensions();
     if (isset($config->dependencies->item)) {
         foreach ($config->dependencies->item as $item) {
             $id = (string) $item;
             $actions = array();
             if ($this->config->has($id . '_status')) {
                 $status = $this->language->get('text_installed') . ' (' . $this->language->get('text_enabled') . ')';
             } else {
                 $status = $this->language->get('text_not_installed') . ' (' . $this->language->get('text_disabled') . ')';
             }
             if (in_array($id, $db_extensions)) {
                 if (in_array($id, $missing_extensions)) {
                     $class = 'warning';
                     $status = sprintf($this->language->get('text_missing_extension'), $id);
                     $actions['delete'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_delete', 'icon' => 'fa fa-trash-o', 'title' => $this->language->get('text_delete')));
                 } else {
                     if (!$this->config->has($id . '_status')) {
                         $actions['install'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/install', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_install', 'icon' => 'fa fa-play', 'title' => $this->language->get('text_install')));
                         $actions['delete'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_delete', 'icon' => 'fa fa-trash-o', 'title' => $this->language->get('text_delete')));
                     } else {
                         $actions['edit'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_edit', 'icon' => 'fa fa-edit', 'title' => $this->language->get('text_edit')));
                         if (!(bool) $item['required']) {
                             $actions['uninstall'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/uninstall', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_uninstall', 'icon' => 'fa fa-times', 'title' => $this->language->get('text_uninstall')));
                         }
                     }
                 }
             } else {
                 $actions['mp'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions_store', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_mp', 'icon' => 'fa fa-play', 'title' => $this->language->get('text_visit_repository')));
             }
             $this->data['extension_info']['dependencies'][] = array('required' => (bool) $item['required'], 'id' => $id, 'status' => $status, 'actions' => $actions, 'class' => $class);
             unset($class);
         }
     }
     // additional settings page
     if ($ext->getConfig('additional_settings')) {
         $btn_param = array('type' => 'button', 'name' => 'btn_addsett', 'href' => $this->html->getSecureURL($ext->getConfig('additional_settings')), 'text' => $this->language->get('text_additional_settings'), 'style' => 'button1');
         if ($store_id) {
             $this->loadModel('setting/store');
             $store_info = $this->model_setting_store->getStore($store_id);
             $btn_param['link'] = $store_info['config_url'] . '?s=' . ADMIN_PATH . '&rt=' . $ext->getConfig('additional_settings');
             $btn_param['target'] = '_blank';
             $btn_param['onclick'] = 'onclick="return confirm(\'' . $this->language->get('additional_settings_confirm') . '\');"';
         }
         $this->data['add_sett'] = $this->html->buildElement($btn_param);
     }
     $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
     $this->view->assign('help_url', $this->gen_help_url('extension_edit'));
     $template = 'pages/extension/extensions_edit.tpl';
     //#PR set custom templates for extension settings page.
     if (has_value((string) $config->custom_settings_template)) {
         //build path to template directory.
         $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/";
         $dir_template .= (string) $config->custom_settings_template;
         //validate template and report issue
         if (!file_exists($dir_template)) {
             $warning = new AWarning(sprintf($this->language->get('error_could_not_load_override'), $dir_template, $extension));
             $warning->toLog()->toDebug();
         } else {
             $template = $dir_template;
         }
     }
     //load tabs controller for addtional settings
     if ($this->data['add_sett']) {
         $this->data['groups'][] = 'additional_settings';
         $this->data['link_additional_settings'] = $this->data['add_sett']->href . '&extension=' . $extension;
     }
     $tabs_obj = $this->dispatch('pages/extension/extension_tabs', array($this->data));
     $this->data['tabs'] = $tabs_obj->dispatchGetOutput();
     unset($tabs_obj);
     $obj = $this->dispatch('pages/extension/extension_summary', array($this->data));
     $this->data['extension_summary'] = $obj->dispatchGetOutput();
     unset($obj);
     $this->view->batchAssign($this->data);
     $this->processTemplate($template);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Ejemplo n.º 14
0
 public function __construct($tmpl_id = '', $page_id = '', $layout_id = '')
 {
     if (!IS_ADMIN) {
         // forbid for non admin calls
         throw new AException(AC_ERR_LOAD, 'Error: permission denied to change page layout');
     }
     $this->registry = Registry::getInstance();
     $this->tmpl_id = !empty($tmpl_id) ? $tmpl_id : $this->config->get('config_storefront_template');
     //load all pages specific to set template. No cross template page/layouts
     $this->pages = $this->getPages();
     //set current page for this object instance
     $this->_set_current_page($page_id, $layout_id);
     $this->page_id = $this->page['page_id'];
     //preload all layouts for this page and template
     //NOTE: layout_type: 0 Default, 1 Active layout, 2 draft layout, 3 template layout
     $this->layouts = $this->getLayouts();
     //locate layout for the page instance. If not specified for this instance fist active layout is used
     foreach ($this->layouts as $layout) {
         if (!empty($layout_id)) {
             if ($layout['layout_id'] == $layout_id) {
                 $this->active_layout = $layout;
                 break;
             }
         } else {
             if ($layout['layout_type'] == 1) {
                 $this->active_layout = $layout;
                 break;
             }
         }
     }
     //if not layout set, use default (layout_type=0) layout
     if (count($this->active_layout) == 0) {
         $this->active_layout = $this->getLayouts(0);
         if (count($this->active_layout) == 0) {
             $message_text = 'No layout found for page_id/controller ' . $this->page_id . '::' . $this->page['controller'] . '!';
             $message_text .= ' Requested data: template: ' . $tmpl_id . ', page_id: ' . $page_id . ', layout_id: ' . $layout_id;
             throw new AException(AC_ERR_LOAD_LAYOUT, $message_text);
         }
     }
     $this->layout_id = $this->active_layout['layout_id'];
     ADebug::variable('Template id', $this->tmpl_id);
     ADebug::variable('Page id', $this->page_id);
     ADebug::variable('Layout id', $this->layout_id);
     // Get blocks
     $this->all_blocks = $this->getAllBlocks();
     $this->blocks = $this->_getLayoutBlocks();
 }
Ejemplo n.º 15
0
 /**
  * add warning message to debug log
  *
  * @return ADebug
  */
 public function toDebug()
 {
     ADebug::warning($this->error_descriptions[$this->code], $this->code, $this->msg);
     return $this;
 }
 public function callback()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $order_id = $this->session->data['order_id'];
     $post = $this->request->post;
     if ($order_id) {
         $this->loadModel('checkout/order');
         $this->loadModel('extension/default_realex');
         $this->loadLanguage('default_realex/default_realex');
         $pd = unserialize($this->encryption->decrypt($post['MD']));
         $signature_result = $this->model_extension_default_realex->verify3DSignature($pd, $post['PaRes']);
         ADebug::checkpoint('Realex 3D processing');
         ADebug::variable('Signature result:' . $signature_result);
         $v3d = array();
         if ($signature_result->result == '00' && (strtoupper($signature_result->threedsecure->status) == 'Y' || strtoupper($signature_result->threedsecure->status) == 'A')) {
             if (strtoupper($signature_result->threedsecure->status) == 'Y') {
                 $v3d['eci_ref'] = 5;
             } else {
                 $v3d['eci_ref'] = 6;
             }
             $v3d['eci'] = (string) $signature_result->threedsecure->eci;
             $v3d['cavv'] = (string) $signature_result->threedsecure->cavv;
             $v3d['xid'] = (string) $signature_result->threedsecure->xid;
         } else {
             if ($pd['cc_type'] == 'mc') {
                 $v3d['eci'] = 0;
             } else {
                 $v3d['eci'] = 7;
             }
             // Enrolled but invalid response from ACS.  No shift in liability. ECI = 7
             if ($signature_result->result == '110' && strtoupper($signature_result->threedsecure->status) == 'Y') {
                 $v3d['eci_ref'] = 4;
                 $v3d['cavv'] = (string) $signature_result->threedsecure->cavv;
                 $v3d['xid'] = (string) $signature_result->threedsecure->xid;
             }
             // Incorrect password entered.  No shift in liability. ECI = 7
             if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'N') {
                 $v3d['eci_ref'] = 7;
                 $v3d['xid'] = (string) $signature_result->threedsecure->xid;
             }
             // Authentication Unavailable.  No shift in liability. ECI = 7
             if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'U') {
                 $v3d['eci_ref'] = 8;
                 $v3d['xid'] = (string) $signature_result->threedsecure->xid;
             }
             // Invalid response from ACS.  No shift in liability. ECI = 7
             if (isset($signature_result->result) && $signature_result->result >= 500 && $signature_result->result < 600) {
                 $v3d['eci_ref'] = 9;
             }
             if (!$this->config->get('default_realex_liability_shift')) {
                 // this is the check for liability shift
                 // Merchant does not want to accept, redirect to checkout with message
                 $error = '3D secure authorization failed';
                 $message = $error;
                 $message .= 'ECI (3D secure) result: (' . $v3d['eci'] . ')';
                 $message .= 'Timestamp: ' . (string) strftime("%Y%m%d%H%M%S");
                 $message .= 'Order Reference: ' . (string) $pd['order_ref'];
                 $this->model_checkout_order->update($order_id, $this->config->get('default_realex_status_decline'), $message, FALSE);
                 $this->session->data['error'] = $error;
                 $this->redirect($this->html->getSecureURL('checkout/checkout'));
             }
         }
         $capture_result = $this->model_extension_default_realex->processPayment($pd, $v3d);
         ADebug::variable('Capture result:' . $capture_result);
         if ($capture_result->result != '00') {
             $this->session->data['error'] = (string) $capture_result->message . ' (' . (int) $capture_result->result . ')';
             $this->redirect($this->html->getSecureURL('checkout/checkout'));
         } else {
             $this->redirect($this->html->getSecureURL('checkout/success'));
         }
     } else {
         $this->redirect($this->html->getSecureURL('account/login'));
     }
 }
Ejemplo n.º 17
0
 public function verify3DSignature($data, $pares)
 {
     $this->load->model('checkout/order');
     $timestamp = strftime("%Y%m%d%H%M%S");
     $merchant_id = $this->config->get('default_realex_merchant_id');
     $secret = $this->config->get('default_realex_secret');
     $tmp = $timestamp . '.' . $merchant_id . '.' . $data['order_ref'] . '.' . $data['amount'] . '.' . $data['currency'] . '.' . $data['cc_number'];
     $hash = sha1($tmp);
     $tmp = $hash . '.' . $secret;
     $hash = sha1($tmp);
     $xml = '';
     $xml .= '<request type="3ds-verifysig" timestamp="' . $timestamp . '">' . "\n";
     $xml .= '<merchantid>' . $merchant_id . '</merchantid>' . "\n";
     $xml .= '<account>' . $data['account'] . '</account>' . "\n";
     $xml .= '<orderid>' . $data['order_ref'] . '</orderid>' . "\n";
     $xml .= '<amount currency="' . $data['currency'] . '">' . (int) $data['amount'] . '</amount>' . "\n";
     $xml .= '<card>' . "\n";
     $xml .= '<number>' . $data['cc_number'] . '</number>' . "\n";
     $xml .= '<expdate>' . $data['cc_expire'] . '</expdate>' . "\n";
     $xml .= '<type>' . $data['cc_type'] . '</type>' . "\n";
     $xml .= '<chname>' . $data['cc_owner'] . '</chname>' . "\n";
     $xml .= '</card>' . "\n";
     $xml .= '<pares>' . $pares . '</pares>' . "\n";
     $xml .= '<sha1hash>' . $hash . '</sha1hash>' . "\n";
     $xml .= '</request>' . "\n";
     ADebug::variable('Running verify3DSignature: ', $xml);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://epage.payandshop.com/epage-3dsecure.cgi");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, "AbanteCart " . VERSION);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $response = curl_exec($ch);
     curl_close($ch);
     ADebug::variable('Response from verify3DSignature: ', $response);
     return simplexml_load_string($response);
 }
Ejemplo n.º 18
0
 /**
  * @param string $parent_controller
  * @return null|string
  */
 public function dispatch($parent_controller = '')
 {
     ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch START');
     //Process the controller, layout and children
     //check if we have missing class or everithing
     if (empty($this->class) && has_value($this->file)) {
         #Build back trace of calling functions to provide more details
         $backtrace = debug_backtrace();
         $function_stack = '';
         if (is_object($parent_controller) && strlen($parent_controller->rt()) > 1) {
             $function_stack = 'Parent Controller: ' . $parent_controller->rt() . ' | ';
         }
         for ($i = 1; $i < count($backtrace); $i++) {
             $function_stack .= ' < ' . $backtrace[$i]['function'];
         }
         $url = $this->request->server['REQUEST_URI'];
         $error = new AError('Error: URL: ' . $url . ' Could not load controller ' . $this->controller . '! Call stack: ' . $function_stack . '', AC_ERR_CLASS_CLASS_NOT_EXIST);
         $error->toLog()->toDebug();
         $error->toMessages();
         return null;
     } else {
         if (empty($this->file) && empty($this->class) || empty($this->method)) {
             $warning_txt = 'ADispatch: skipping unavailable controller …';
             $warning = new AWarning($warning_txt);
             $warning->toDebug();
             return null;
         }
     }
     //check for controller.pre
     $output_pre = $this->dispatchPrePost($this->controller . POSTFIX_PRE);
     /** @noinspection PhpIncludeInspection */
     require_once $this->file;
     /**
      * @var $controller AController
      */
     $controller = null;
     if (class_exists($this->class)) {
         $controller = new $this->class($this->registry, $this->args["instance_id"], $this->controller, $parent_controller);
         $controller->dispatcher = $this;
     } else {
         $error = new AError('Error: controller class not exist ' . $this->class . '!', AC_ERR_CLASS_CLASS_NOT_EXIST);
         $error->toLog()->toDebug();
     }
     if (is_callable(array($controller, $this->method))) {
         /**
          * @var $dispatch ADispatcher
          */
         $dispatch = call_user_func_array(array($controller, $this->method), $this->args);
         //Check if return is a dispatch and need to call new page
         if ($dispatch && is_object($dispatch)) {
             if ($this->args["instance_id"] == 0) {
                 //If main controller come back for new dispatch
                 return $dispatch->getController() . '/' . $dispatch->getMethod();
             } else {
                 // Call new dispatch for new controller and exit
                 //???? need to put limit for recursion to prevent overflow
                 $dispatch->dispatch();
                 return null;
             }
         }
         /**
          * Load layout and process children controllers
          * @method AController getChildren()
          */
         $children = $controller->getChildren();
         ADebug::variable('Processing children of ' . $this->controller, $children);
         $block_uids = array();
         //Process each child controller
         foreach ($children as $child) {
             //???? Add highest Debug level here with backtrace to review this
             ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ', instance_id: ' . $child['instance_id'] . ' ) dispatch START');
             //Process each child and create dispatch to call recurcive
             $dispatch = new ADispatcher($child['controller'], array("instance_id" => $child['instance_id']));
             $dispatch->dispatch($controller);
             // Append output of child controller to current controller
             if ($child['position']) {
                 // maden for recognizing few custom_blocks in the same placeholder
                 $controller->view->assign($child['block_txt_id'] . '_' . $child['instance_id'], $this->response->getOutput());
             } else {
                 $controller->view->assign($child['block_txt_id'], $this->response->getOutput());
             }
             //clean up and remove output
             $this->response->setOutput('');
             ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ' ) dispatch END');
         }
         //Request controller to generate output
         $controller->finalize();
         //check for controller.pre
         $output_post = $this->dispatchPrePost($this->controller . POSTFIX_POST);
         //add pre and post controllers output
         $this->response->setOutput($output_pre . $this->response->getOutput() . $output_post);
         //clean up and destroy the object
         unset($controller);
         unset($dispatch);
     } else {
         $err = new AError('Error: controller method not exist ' . $this->class . '::' . $this->method . '!', AC_ERR_CLASS_METHOD_NOT_EXIST);
         $err->toLog()->toDebug();
     }
     ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch END');
     return null;
 }
Ejemplo n.º 19
0
 /**
  * Process each table level recursively
  * @param string $table_name
  * @param array $table_cfg
  * @param array $data_arr
  * @param array $parent_vals
  * @param bool $action_delete
  * @return array
  */
 private function _process_import_table($table_name, $table_cfg, $data_arr, $parent_vals = array(), $action_delete = false)
 {
     ADebug::checkpoint('AData::importData processing table ' . $table_name);
     if (!isset($data_arr['rows'])) {
         $this->_status2array('error', 'Incorrect structure of ' . $table_name . ' node. Row node is expected');
     }
     $new_vals = array();
     foreach ($data_arr['rows'] as $rnode) {
         $action = '';
         //Set action for the row
         if (!$action_delete) {
             $action = $this->_get_action($table_name, $table_cfg, $rnode);
         } else {
             $action = 'delete';
         }
         //set current scope values
         $new_vals = $parent_vals;
         if (isset($table_cfg['id']) && isset($rnode[$table_cfg['id']])) {
             $new_vals[$table_cfg['id']] = $rnode[$table_cfg['id']];
         }
         if (isset($table_cfg['special_relation'])) {
             foreach ($table_cfg['special_relation'] as $sp_field => $sp_value) {
                 //check if this is relation id to be used for special relation
                 if (in_array($sp_field, $table_cfg['relation_ids'])) {
                     $new_vals[$sp_field] = $new_vals[$sp_value];
                 }
             }
         } else {
             if ($table_cfg['relation_ids']) {
                 foreach ($table_cfg['relation_ids'] as $relation_id) {
                     if (isset($rnode[$relation_id])) {
                         $new_vals[$relation_id] = $rnode[$relation_id];
                     }
                 }
             }
         }
         //Validate required keys if wrong donot bother with children exit.
         if (!$this->_validate_action($action, $table_name, $table_cfg, $new_vals)) {
             continue;
         }
         //Unique case: If this is a resource_map and resource_id is missing we need to create resource library first and get resource_id
         if ($table_name == 'resource_map' && isset($rnode['tables']) && is_array($rnode['tables'])) {
             //only one resource can be mapped at the time.
             $new_table = $rnode['tables'][0];
             $sub_table_cfg = $this->model_tool_table_relationships->find_table_cfg($new_table['name'], $table_cfg);
             if ($sub_table_cfg) {
                 if ($action == 'delete') {
                     $set_action_delete = true;
                 } else {
                     $set_action_delete = false;
                 }
                 $resource_data = $this->_process_import_table($new_table['name'], $sub_table_cfg, $new_table, $new_vals, $set_action_delete);
                 $new_vals['resource_id'] = $resource_data['resource_id'];
                 //Now do the action for the row if any data provided besides keys
                 $new_vals = array_merge($new_vals, $this->_do_fromArray($action, $table_name, $table_cfg, $rnode, $new_vals));
             } else {
                 $this->_status2array('error', 'Unknown table: "' . $new_table['name'] . '" requested in relation to table ' . $table_name . '. Exit this node');
             }
         } else {
             // all other tables
             //Now do the action for the row if any data provided besides keys
             $new_vals = array_merge($new_vals, $this->_do_fromArray($action, $table_name, $table_cfg, $rnode, $new_vals));
             //locate inner table nodes for recursion
             if ($table_name != 'resource_map' && isset($rnode['tables']) && is_array($rnode['tables'])) {
                 foreach ($rnode['tables'] as $new_table) {
                     if ($action == 'delete') {
                         $set_action_delete = true;
                     } else {
                         $set_action_delete = false;
                     }
                     $sub_table_cfg = $this->model_tool_table_relationships->find_table_cfg($new_table['name'], $table_cfg);
                     if ($sub_table_cfg) {
                         $this->_process_import_table($new_table['name'], $sub_table_cfg, $new_table, $new_vals, $set_action_delete);
                     } else {
                         $this->_status2array('error', 'Unknown table: "' . $new_table['name'] . '" requested in relation to table ' . $table_name . '. Exit this node');
                         continue;
                     }
                 }
             }
         }
     }
     //return last row new (updated) values
     return $new_vals;
 }
Ejemplo n.º 20
0
 /**
  * PR: Duplicate row from default language to new and translate if needed
  * @param string $table
  * @param $pkeys
  * @param int $new_language
  * @param int $from_language
  * @param string $specific_sql
  * @param string $translate_method
  * @return null|string
  */
 private function _clone_language_rows($table, $pkeys, $new_language, $from_language = 1, $specific_sql = '', $translate_method = '')
 {
     if (empty($table) || empty($pkeys) || empty($new_language)) {
         return null;
     }
     // Locate autoincrement column
     $autoincrenent_sql = "SHOW COLUMNS FROM " . $table . " where Extra = 'auto_increment'";
     $autoincrement = $this->db->query($autoincrenent_sql);
     $auto_column = $autoincrement->row['Field'];
     //get all fields that are translatable
     $translatable_fields = $this->_get_translatable_fields($table);
     //Build a keys string for select
     $keys_str = '';
     $tcount = 0;
     foreach ($pkeys as $key) {
         if (!empty($keys_str)) {
             $keys_str .= ",";
         }
         $keys_str .= "{$key} ";
     }
     $sql = "SELECT " . $keys_str . " FROM " . $table . " WHERE language_id = " . $from_language . $specific_sql;
     $tables_query = $this->db->query($sql);
     if ($tables_query->num_rows) {
         $langs = array();
         foreach ($this->available_languages as $lang) {
             $langs[$lang['language_id']] = $lang['filename'];
         }
         foreach ($tables_query->rows as $row) {
             #Check if to be saved data exists for new language
             $sql1 = "SELECT * FROM " . $table . " WHERE language_id = " . $new_language;
             $sql2 = "SELECT * FROM " . $table . " WHERE language_id = " . $from_language;
             $where_sql_1 = $where_sql_2 = '';
             foreach ($pkeys as $key) {
                 //Skip language_id and autoincrement from the key. autoincrement is unique by itself.
                 if ($key != 'language_id' && $key != $auto_column) {
                     if (in_array($row[$key], $langs)) {
                         $where_sql_1 .= " AND {$key} = '" . $langs[$new_language] . "'";
                         $where_sql_2 .= " AND {$key} = '" . $langs[$from_language] . "'";
                     } else {
                         $where_sql_1 .= " AND {$key} = '" . $row[$key] . "'";
                         $where_sql_2 .= " AND {$key} = '" . $row[$key] . "'";
                     }
                 }
             }
             $sql1 .= $where_sql_1;
             $sql2 .= $where_sql_2;
             $check_query = $this->db->query($sql1);
             if ($check_query->num_rows <= 0) {
                 ADebug::variable('class ALanguage missing language data: ', $sql1);
                 //we have no data, clone it
                 $insert_data = array();
                 $origin_query = $this->db->query($sql2);
                 foreach ($origin_query->rows as $drow) {
                     foreach ($drow as $fld_name => $value) {
                         if ($fld_name == 'language_id') {
                             $value = $new_language;
                         } else {
                             if ($fld_name == $auto_column) {
                                 $value = '';
                             } else {
                                 if ($fld_name == 'block' && $value == $langs[$from_language]) {
                                     //language specific field for main language block. use destination language
                                     $value = $langs[$new_language];
                                 } else {
                                     if (count($translatable_fields) && in_array($fld_name, $translatable_fields)) {
                                         //we need to translate
                                         $value = $this->translate($this->_get_language_code($from_language), $value, $this->_get_language_code($new_language), $translate_method);
                                     }
                                 }
                             }
                         }
                         $insert_data[$fld_name] = $this->db->escape($value);
                     }
                 }
                 if (!empty($insert_data)) {
                     $insrt_sql = "INSERT INTO " . $table . "(" . implode(',', array_keys($insert_data)) . ") VALUES ('" . implode("','", $insert_data) . "')";
                     ADebug::variable('class ALanguage cloning data: ', $insrt_sql);
                     if ($table == DB_PREFIX . 'language_definitions') {
                         //#PR There are some key condition in definitions that can be duplicate (CASE: block = 'english' main language ) skip
                         //We assume that main language XML need to be present
                         //TODO rename main language file to common.xml
                         if (!$this->_is_definition_in_db($insert_data)) {
                             $this->db->query($insrt_sql);
                         } else {
                             continue;
                         }
                     } else {
                         if ($table == DB_PREFIX . 'product_tags') {
                             // TODO. ac_product_tags still an issue. Will be clonned as duplication on each translation.
                             //		 Issue. Can not check if translation is present because of no IDs present in ac_product_tags
                             // Offset duplicate error for now.
                             if (!$this->db->query($insrt_sql, true)) {
                                 //skip count on error
                                 continue;
                             }
                         } else {
                             $this->db->query($insrt_sql);
                         }
                     }
                     $tcount++;
                 }
             }
         }
         if ($tcount > 0) {
             $this->cache->delete('lan.*');
         }
     }
     return "Total: " . $tcount . " language entries cloned for table " . $table . "<br>";
 }
 /**
  * Load definition values from XML
  * @param string $filename
  * @param string $directory
  * @param string $mode
  * @return array|null
  */
 protected function _load_from_xml($filename, $directory, $mode)
 {
     if (!$filename) {
         return null;
     }
     $definitions = array();
     ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' ' . $filename . ' prepare loading language from XML');
     //get default extension language file
     $default_language_info = $this->getDefaultLanguage();
     if ($filename == $directory) {
         // for common language file (english.xml. russian.xml, etc)
         $file_name = $default_language_info['filename'];
         $mode = 'silent';
     } else {
         $file_name = $filename;
     }
     $default_file_path = $this->_detect_language_xml_file($file_name, $default_language_info['directory']);
     // if default language file path wrong - takes english
     if (!file_exists($default_file_path)) {
         $file_name = $filename == $directory ? 'english' : $file_name;
         $default_file_path = $this->_detect_language_xml_file($file_name, 'english');
     }
     // get path to actual language
     $file_path = $this->_detect_language_xml_file($filename, $this->language_details['directory']);
     if (file_exists($file_path)) {
         ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $file_path);
         $definitions = $this->ReadXmlFile($file_path);
     } else {
         if (file_exists($default_file_path)) {
             ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $default_file_path);
             $definitions = $this->ReadXmlFile($default_file_path);
         } else {
             if ($mode != 'silent') {
                 $error = new AError('Missing default English definition XML file for ' . $filename . ' !');
                 $error->toLog()->toDebug();
             }
         }
     }
     //skip if not required and language file does not exist for silent mode.
     if (empty($definitions) && $mode != 'silent') {
         $error = new AError('Could not load language ' . $filename . ' from file "' . $file_path . '"!');
         $error->toLog()->toDebug();
     }
     return $definitions;
 }
 public function send()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('default_stripe/default_stripe');
     //validate input
     $post = $this->request->post;
     //check if saved cc mode is used
     if (!$post['use_saved_cc']) {
         if (empty($post['cc_number'])) {
             $json['error'] = $this->language->get('error_incorrect_number');
         }
         if (empty($post['cc_owner'])) {
             $json['error'] = $this->language->get('error_incorrect_name');
         }
         if (empty($post['cc_expire_date_month']) || empty($post['cc_expire_date_year'])) {
             $json['error'] = $this->language->get('error_incorrect_expiration');
         }
         if (strlen($post['cc_cvv2']) != 3 && strlen($post['cc_cvv2']) != 4) {
             $json['error'] = $this->language->get('error_incorrect_cvv');
         }
     }
     if (isset($json['error'])) {
         $this->load->library('json');
         $this->response->setOutput(AJson::encode($json));
         return null;
     }
     $this->loadModel('checkout/order');
     $this->loadModel('extension/default_stripe');
     $this->loadLanguage('default_stripe/default_stripe');
     $order_id = $this->session->data['order_id'];
     $order_info = $this->model_checkout_order->getOrder($order_id);
     // currency code
     $currency = $this->currency->getCode();
     // order amount without decimal delimiter
     $amount = round($this->currency->convert($this->cart->getFinalTotal(), $this->config->get('config_currency'), $currency), 2) * 100;
     $cardnumber = preg_replace('/[^0-9]/', '', $post['cc_number']);
     $cvv2 = preg_replace('/[^0-9]/', '', $post['cc_cvv2']);
     // Card owner name
     $cardname = html_entity_decode($post['cc_owner'], ENT_QUOTES, 'UTF-8');
     $cardtype = $post['cc_type'];
     // card expire date mmyy
     $cardissue = $post['cc_issue'];
     ADebug::checkpoint('Stripe Payment: Order ID ' . $order_id);
     $pd = array('amount' => $amount, 'currency' => $currency, 'order_id' => $order_id, 'cc_number' => $cardnumber, 'cc_expire_month' => $post['cc_expire_date_month'], 'cc_expire_year' => $post['cc_expire_date_year'], 'cc_owner' => $cardname, 'cc_cvv2' => $cvv2, 'cc_issue' => $cardissue);
     $p_result = $this->model_extension_default_stripe->processPayment($pd, $customer_stripe_id);
     ADebug::variable('Processing payment result: ', $p_result);
     if ($p_result['error']) {
         // transaction failed
         $json['error'] = (string) $p_result['error'];
         if ($p_result['code']) {
             $json['error'] .= ' (' . $p_result['code'] . ')';
         }
     } else {
         if ($p_result['paid']) {
             $json['success'] = $this->html->getSecureURL('checkout/success');
         } else {
             //Unexpected result
             $json['error'] = $this->language->get('error_system');
         }
     }
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($json));
 }