/**
 * Main driver for running system check 
 * @since 1.2.4
 * @param $registry
 * @param $mode ('log', 'return') 
 * @return array
 *
 * Note: This is English text only. Can be call before database and languges are loaded
 */
function run_system_check($registry, $mode = 'log')
{
    $mlog = $counts = array();
    $mlog[] = check_install_directory($registry);
    $mlog = array_merge($mlog, check_file_permissions($registry));
    $mlog = array_merge($mlog, check_php_configuraion($registry));
    $mlog = array_merge($mlog, check_server_configuration($registry));
    $counts['error_count'] = $counts['warning_count'] = $counts['notice_count'] = 0;
    foreach ($mlog as $message) {
        if ($message['type'] == 'E') {
            if ($mode == 'log') {
                //only save errors to the log
                $error = new AError($message['body']);
                $error->toLog()->toDebug();
                $registry->get('messages')->saveError($message['title'], $message['body']);
            }
            $counts['error_count']++;
        } else {
            if ($message['type'] == 'W') {
                if ($mode == 'log') {
                    $registry->get('messages')->saveWarning($message['title'], $message['body']);
                }
                $counts['warning_count']++;
            } else {
                if ($message['type'] == 'N') {
                    if ($mode == 'log') {
                        $registry->get('messages')->saveNotice($message['title'], $message['body']);
                    }
                    $counts['notice_count']++;
                }
            }
        }
    }
    return array($mlog, $counts);
}
Example #2
0
 public function save()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $output = array();
     $this->loadLanguage('tool/rl_manager');
     $this->document->setTitle($this->language->get('heading_title'));
     if ($this->request->is_POST() && $this->_validateRLTypeForm($this->request->post)) {
         $post_data = $this->request->post;
         $rm = new AResourceManager();
         if ($rm->updateResourceType($post_data)) {
             $output['result_text'] = $this->language->get('text_success');
             $this->load->library('json');
             $this->response->addJSONHeader();
             $this->response->setOutput(AJson::encode($output));
         } else {
             $error = new AError('');
             $err_data = array('error_text' => 'Unable to save resource type');
             return $error->toJSONResponse('VALIDATION_ERROR_406', $err_data);
         }
     } else {
         $error = new AError('');
         $err_data = array('error_text' => $this->error);
         return $error->toJSONResponse('VALIDATION_ERROR_406', $err_data);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function update()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/location_zones')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/location_zones'), 'reset_value' => true));
     }
     $this->loadModel('localisation/zone');
     $this->loadLanguage('localisation/zone');
     switch ($this->request->post['oper']) {
         case 'del':
             $this->loadModel('localisation/location');
             $ids = explode(',', $this->request->post['id']);
             if (!empty($ids)) {
                 foreach ($ids as $id) {
                     $this->model_localisation_location->deleteLocationZone($id);
                 }
             }
             break;
         default:
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #4
0
 /**
  * update only one field
  *
  * @return void
  */
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/store')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/store'), 'reset_value' => true));
     }
     $this->loadLanguage('setting/store');
     $this->loadModel('setting/store');
     if (isset($this->request->get['id'])) {
         //request sent from edit form. ID in url
         foreach ($this->request->post as $key => $value) {
             $err = $this->_validateField($key, $value);
             if (!empty($err)) {
                 $dd = new ADispatcher('responses/error/ajaxerror/validation', array('error_text' => $err));
                 return $dd->dispatch();
             }
             $data = array($key => $value);
             $this->model_setting_store->editStore($this->request->get['id'], $data);
         }
         return;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function update()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify($this->rt)) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), $this->rt), 'reset_value' => true));
     }
     $this->loadModel('localisation/language_definitions');
     $this->loadLanguage('localisation/language_definitions');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $this->document->setTitle($this->language->get('heading_title'));
     if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validateForm()) {
         foreach ($this->request->post['language_definition_id'] as $lang_id => $id) {
             $data = array('language_id' => $lang_id, 'section' => $this->request->post['section'], 'block' => $this->request->post['block'], 'language_key' => $this->request->post['language_key'], 'language_value' => $this->request->post['language_value'][$lang_id]);
             if ($id) {
                 $this->model_localisation_language_definitions->editLanguageDefinition($id, $data);
             } else {
                 $this->model_localisation_language_definitions->addLanguageDefinition($data);
             }
         }
         $this->view->assign('success', $this->language->get('text_success'));
     }
     $this->_getForm();
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #6
0
 public function not_found()
 {
     //build not_found responce
     $this->loadLanguage('error/not_found');
     $error = new AError('');
     $err_data = array('error_title' => $this->language->get('heading_title'), 'error_text' => $this->language->get('text_not_found'));
     return $error->toJSONResponse('NOT_FOUND_404', $err_data);
 }
Example #7
0
/**
 * SOAP request/response logging to a file
 */
function writeToLog($client)
{
    if (!($logfile = fopen(TRANSACTIONS_LOG_FILE, "a"))) {
        $error = new AError("Cannot open " . TRANSACTIONS_LOG_FILE . " file.\n");
        $error->toLog()->toMessages->toDebug();
        exit(1);
    }
    fwrite($logfile, sprintf("\r%s:- %s", date("D M j G:i:s T Y"), $client->__getLastRequest() . "\n\n" . $client->__getLastResponse()));
}
Example #8
0
 public function updateField()
 {
     $this->loadLanguage('forms_manager/forms_manager');
     $this->loadModel('tool/forms_manager');
     if (!$this->_validateFieldForm($this->request->post) || !$this->request->get['form_id']) {
         $error = new AError('');
         return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $this->error));
     }
     $data = $this->request->post;
     $data['form_id'] = $this->request->get['form_id'];
     $this->model_tool_forms_manager->updateFormFieldData($data);
     $this->response->setOutput('');
 }
Example #9
0
 /**
  * @param string $filename
  * @throws AException
  */
 public function __construct($filename)
 {
     if (file_exists($filename) && ($info = getimagesize($filename))) {
         $this->file = $filename;
         $this->info = array('width' => $info[0], 'height' => $info[1], 'bits' => $info['bits'], 'mime' => $info['mime'], 'channels' => $info['channels']);
         $this->registry = Registry::getInstance();
         $this->image = $this->get_gd_resource($filename);
     } else {
         $error = new AError('Error: Cannot load image ' . $filename);
         $error->toMessages()->toDebug()->toLog();
         return false;
     }
     return true;
 }
 /**
  * @param string $type
  */
 public function __construct($type)
 {
     $this->registry = Registry::getInstance();
     //NOTE: Storefront can not access all resource at once. Resource type required
     if ($type) {
         $this->type = $type;
         //get type details
         $this->_loadType();
     }
     if (!$this->type_id) {
         $message = "Error: Incorrect or missing resource type ";
         $error = new AError($message);
         $error->toLog()->toDebug();
     }
 }
 public function update()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify($this->rt)) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), $this->rt), 'reset_value' => true));
     }
     $this->loadModel('localisation/language_definitions');
     $this->loadLanguage('localisation/language_definitions');
     if ($this->request->is_POST()) {
         $output = array('error_text' => '', 'result_text' => '');
         if ($this->_validateForm()) {
             foreach ($this->request->post['language_definition_id'] as $lang_id => $id) {
                 $data = array('language_id' => $lang_id, 'section' => $this->request->post['section'], 'block' => $this->request->post['block'], 'language_key' => $this->request->post['language_key'], 'language_value' => $this->request->post['language_value'][$lang_id]);
                 if ($id) {
                     $this->model_localisation_language_definitions->editLanguageDefinition($id, $data);
                 } else {
                     $this->model_localisation_language_definitions->addLanguageDefinition($data);
                 }
             }
             $output['result_text'] = $this->language->get('text_success');
         } else {
             foreach ($this->error as $err) {
                 if (is_array($err)) {
                     $error_text[] = implode('<br>', $err);
                 } else {
                     $error_text[] = $err;
                 }
             }
             $error = new AError('');
             return $error->toJSONResponse('NO_PERMISSIONS_406', array('error_text' => $error_text, 'reset_value' => true));
         }
         $this->load->library('json');
         $this->response->addJSONHeader();
         $this->response->setOutput(AJson::encode($output));
     } else {
         $this->view->assign('success', $this->session->data['success']);
         if (isset($this->session->data['success'])) {
             unset($this->session->data['success']);
         }
         $this->document->setTitle($this->language->get('heading_title'));
         $this->_getForm();
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function main()
 {
     if (!$this->user->canModify('setting/setting_quick_form')) {
         $this->error['warning'] = $this->language->get('error_permission');
     }
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $output = array('result_text' => '');
     $this->loadModel('setting/setting');
     $this->loadLanguage('setting/setting');
     $this->loadLanguage('common/header');
     $this->view->assign('success', $this->session->data['success']);
     if (isset($this->session->data['success'])) {
         unset($this->session->data['success']);
     }
     $setting = explode('-', $this->request->get['active']);
     $this->data['group'] = $setting[0];
     $this->data['setting_key'] = $setting[1];
     $this->data['store_id'] = !isset($this->session->data['current_store_id']) ? $setting[2] : $this->session->data['current_store_id'];
     if (is_int(strpos($this->data['setting_key'], 'config_description'))) {
         $this->data['setting_key'] = substr($this->data['setting_key'], 0, strrpos($this->data['setting_key'], '_'));
         $this->request->get['active'] = $this->data['group'] . '-' . $setting[1] . '-' . $this->data['store_id'];
     } else {
         $this->request->get['active'] = $this->data['group'] . '-' . $this->data['setting_key'] . '-' . $this->data['store_id'];
     }
     $this->document->setTitle($this->language->get('heading_title'));
     if ($this->request->is_POST()) {
         if ($this->_validateForm($this->data['group'])) {
             $this->model_setting_setting->editSetting($this->data['group'], $this->request->post, $this->data['store_id']);
             $output['result_text'] = $this->language->get('text_success');
             $this->load->library('json');
             $this->response->addJSONHeader();
             $this->response->setOutput(AJson::encode($output));
         } else {
             $error = new AError('');
             return $error->toJSONResponse('NO_PERMISSIONS_406', array('error_text' => $this->error, 'reset_value' => true));
         }
     } else {
         $this->_getForm();
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 public function onControllerResponsesListingGridExtension_InitData()
 {
     if ($this->baseObject_method != 'update') {
         return null;
     }
     $that = $this->baseObject;
     if ($that->request->get['id'] != 'default_pp_express') {
         return false;
     }
     if (!has_value($that->request->post['default_pp_express_custom_bg_color'])) {
         return false;
     }
     $that->request->post['default_pp_express_custom_bg_color'] = ltrim($that->request->post['default_pp_express_custom_bg_color'], '#');
     $is_valid = $this->_check_valid_colorhex($that->request->post['default_pp_express_custom_bg_color']);
     if (!$is_valid) {
         $that->loadLanguage('default_pp_express/default_pp_express');
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => $that->language->get('default_pp_express_error_bg_color'), 'reset_value' => false));
     }
 }
Example #14
0
 public function addStatus($order_status_id, $status_text_id)
 {
     $order_status_id = (int) $order_status_id;
     //preformat text_id at first
     $status_text_id = preformatTextID($status_text_id);
     if (in_array($order_status_id, array_keys($this->statuses)) || in_array($status_text_id, $this->statuses)) {
         $error_text = 'Error: Cannot add new order status with id ' . $order_status_id . ' and text id ' . $status_text_id . ' into AOrderStatus class.';
         $e = new AError($error_text);
         $e->toLog()->toDebug();
         return false;
     }
     if (!$status_text_id) {
         $error_text = 'Error: Cannot add new order status with id ' . $order_status_id . ' and empty text id';
         $e = new AError($error_text);
         $e->toLog()->toDebug();
         return false;
     }
     $this->statuses[$order_status_id] = $status_text_id;
     return true;
 }
Example #15
0
 public function buildTask()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->data['output'] = array();
     if ($this->request->is_POST() && $this->_validate()) {
         $this->loadModel('tool/backup');
         $task_details = $this->model_tool_backup->createBackupTask('manual_backup', $this->request->post);
         if (!$task_details) {
             $this->errors = array_merge($this->errors, $this->model_tool_backup->errors);
             $error = new AError('files backup error');
             return $error->toJSONResponse('APP_ERROR_402', array('error_text' => implode(' ', $this->errors), 'reset_value' => true));
         } else {
             $this->data['output']['task_details'] = $task_details;
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($this->data['output']));
 }
Example #16
0
 public function processDownloadForm()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('product/product')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'product/product'), 'reset_value' => true));
     }
     if (!$this->request->is_POST()) {
         return null;
     }
     $this->loadModel('catalog/download');
     if ($this->_validateDownloadForm($this->request->post)) {
         $post_data = $this->request->post;
         //disable download if file not set
         if (!$post_data['filename']) {
             $post_data['status'] = 0;
         }
         // for shared downloads
         if (!isset($post_data['shared']) && !$this->request->get['product_id']) {
             $post_data['shared'] = 1;
         }
         if ((int) $this->request->get['download_id']) {
             $this->model_catalog_download->editDownload($this->request->get['download_id'], $post_data);
             $download_id = (int) $this->request->get['download_id'];
         } else {
             $post_data['product_id'] = (int) $this->request->get['product_id'];
             $download_id = $this->model_catalog_download->addDownload($post_data);
             $this->session->data['success'] = $this->language->get('text_success_download_save');
         }
         $this->data['output'] = array('download_id' => $download_id, 'success' => true, 'result_text' => $this->language->get('text_success'));
     } else {
         $error = new AError('');
         $err_data = array('error_text' => $this->error);
         return $error->toJSONResponse('VALIDATION_ERROR_406', $err_data);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->response->addJSONHeader();
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($this->data['output']));
 }
 /**
  * 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;
 }
 /**
  * update only one field
  *
  * @return void
  */
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/attribute')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/attribute'), 'reset_value' => true));
     }
     if (isset($this->request->get['id'])) {
         //request sent from edit form. ID in url
         foreach ($this->request->post as $key => $value) {
             $err = $this->_validateField($key, $value);
             if (!empty($err)) {
                 $error = new AError('');
                 return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
             }
             $data = array($key => $value);
             $this->attribute_manager->updateAttribute($this->request->get['id'], $data);
         }
         return null;
     }
     //request sent from jGrid. ID is key of array
     $fields = array('sort_order', 'status');
     foreach ($fields as $f) {
         if (isset($this->request->post[$f])) {
             foreach ($this->request->post[$f] as $k => $v) {
                 $err = $this->_validateField($f, $v);
                 if (!empty($err)) {
                     $error = new AError('');
                     return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
                 }
                 $this->attribute_manager->updateAttribute($k, array($f => $v));
             }
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #19
0
 /**
  * @param string $title
  * @param string $error
  * @param string $level
  * @return string
  */
 private function processError($title, $error, $level = 'warning')
 {
     $this->message->{'save' . ucfirst($level)}($title, $error);
     $wrn = new AError($error);
     $wrn->toDebug()->toLog();
     return $error;
 }
Example #20
0
 /**
  * @param string $value
  * @return string
  */
 public function escape($value)
 {
     if (is_array($value)) {
         $dump = var_export($value, true);
         $backtrace = debug_backtrace();
         $dump .= ' (file: ' . $backtrace[1]['file'] . ' line ' . $backtrace[1]['line'] . ')';
         $message = 'PostreSQL class error: Try to escape non-string value: ' . $dump;
         $error = new AError($message);
         $error->toLog()->toDebug()->toMessages();
         return false;
     }
     return pg_escape_string($this->connection, (string) $value);
 }
Example #21
0
 /**
  * @param string $value
  * @return string
  */
 public function escape($value)
 {
     if (is_array($value)) {
         $dump = var_export($value, true);
         $message = 'MySQL class error: Try to escape non-string value: ' . $dump;
         $error = new AError($message);
         $error->toLog()->toDebug()->toMessages();
         return false;
     }
     return mysql_real_escape_string((string) $value, $this->connection);
 }
Example #22
0
 /**
  * update only one field
  *
  * @return void
  */
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/setting')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/setting'), 'reset_value' => true));
     }
     $this->loadLanguage('setting/setting');
     $this->loadModel('setting/setting');
     if (isset($this->request->get['group'])) {
         $group = $this->request->get['group'];
         //for appearance settings per template
         if ($this->request->get['group'] == 'appearance' && has_value($this->request->get['tmpl_id']) && $this->request->get['tmpl_id'] != 'default') {
             $group = $this->request->get['tmpl_id'];
         }
         //request sent from edit form. ID in url
         foreach ($this->request->post as $key => $value) {
             $err = $this->_validateField($group, $key, $value);
             if (!empty($err)) {
                 $error = new AError('');
                 return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
             }
             $data = array($key => $value);
             //html decode store name
             if (has_value($data['store_name'])) {
                 $data['store_name'] = html_entity_decode($data['store_name'], ENT_COMPAT, 'UTF-8');
             }
             $this->model_setting_setting->editSetting($group, $data, $this->request->get['store_id']);
             startStorefrontSession($this->user->getId());
         }
         return null;
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 /**
  * update only one field
  *
  * @return void
  */
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('localisation/language_definitions');
     if (!$this->user->canModify('listing_grid/language_definitions')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/language_definitions'), 'reset_value' => true));
     }
     $this->loadModel('localisation/language_definitions');
     $allowedFields = array('block', 'language_key', 'language_value', 'section');
     $save_id = $this->request->get['id'];
     if (isset($save_id)) {
         //request sent from edit form. ID in url
         foreach ($this->request->post as $key => $value) {
             if (!in_array($key, $allowedFields)) {
                 continue;
             }
             $data = array($key => $value);
             if ($key == 'language_value') {
                 //load definition values.
                 $def = $this->model_localisation_language_definitions->getLanguageDefinition($save_id);
                 //if defintion does not match lagnuage this means we create new one
                 if ($def['language_id'] != key($value)) {
                     //save new
                     $def['language_id'] = key($value);
                     $def['language_definition_id'] = '';
                     $def['language_value'] = current($value);
                     $this->model_localisation_language_definitions->addLanguageDefinition($def);
                 } else {
                     //edit
                     $def['language_value'] = current($value);
                     $this->model_localisation_language_definitions->editLanguageDefinition($save_id, $def);
                 }
             }
             if (in_array($key, array('block', 'section', 'language_key'))) {
                 $def = $this->model_localisation_language_definitions->getLanguageDefinition($save_id);
                 $def_ids = $this->model_localisation_language_definitions->getAllLanguageDefinitionsIdByKey($def['language_key'], $def['block'], $def['section']);
                 if ($def_ids) {
                     foreach ($def_ids as $item) {
                         $this->model_localisation_language_definitions->editLanguageDefinition($item['language_definition_id'], array($key => $value));
                     }
                 }
             }
         }
         return null;
     }
     //request sent from jGrid. ID is key of array
     foreach ($this->request->post as $key => $value) {
         if (!in_array($key, array('language_value'))) {
             continue;
         }
         foreach ($value as $k => $v) {
             $data = array($key => $v);
             $this->model_localisation_language_definitions->editLanguageDefinition($k, $data);
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
Example #24
0
 private function _send_sms($phone, $data)
 {
     if (!$phone || !$data) {
         $error = new AError('Error: Cannot send sms. Unknown phone number or empty message.');
         $error->toLog()->toMessages();
         return false;
     }
     $driver = null;
     $driver_txt_id = $this->config->get('config_sms_driver');
     //if driver not set - skip protocol
     if (!$driver_txt_id) {
         return false;
     }
     //use safe usage
     try {
         include_once DIR_EXT . $driver_txt_id . '/core/lib/' . $driver_txt_id . '.php';
         //if class of driver
         $classname = preg_replace('/[^a-zA-Z]/', '', $driver_txt_id);
         if (!class_exists($classname)) {
             $error = new AError('IM-driver ' . $driver_txt_id . ' load error.');
             $error->toLog()->toMessages();
             return false;
         }
         $driver = new $classname();
     } catch (AException $e) {
     }
     if ($driver === null) {
         return false;
     }
     $text = $this->config->get('store_name') . ": " . $data['message'];
     $to = $phone;
     $result = true;
     if ($text && $to) {
         //use safe call
         try {
             $result = $driver->send($to, $text);
         } catch (AException $e) {
             return false;
         }
     }
     return $result;
 }
Example #25
0
 /**
  * update only one field
  *
  * @return void
  */
 public function update_field()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('localisation/country');
     if (!$this->user->canModify('listing_grid/country')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/country'), 'reset_value' => true));
     }
     $this->loadModel('localisation/country');
     if (isset($this->request->get['id'])) {
         //request sent from edit form. ID in url
         foreach ($this->request->post as $key => $value) {
             $err = '';
             if ($key == 'country_name') {
                 foreach ($value as $lang => $dvalue) {
                     $err .= $this->_validateField('name', $dvalue['name']);
                 }
             } else {
                 $err = $this->_validateField($key, $value);
             }
             if (!empty($err)) {
                 $error = new AError('');
                 return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
             }
             $data = array($key => $value);
             $this->model_localisation_country->editCountry($this->request->get['id'], $data);
         }
         return null;
     }
     //request sent from jGrid. ID is key of array
     $fields = array('iso_code_2', 'iso_code_3', 'status');
     foreach ($fields as $f) {
         if (isset($this->request->post[$f])) {
             foreach ($this->request->post[$f] as $k => $v) {
                 $err = $this->_validateField($f, $v);
                 if (!empty($err)) {
                     $error = new AError('');
                     return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
                 }
                 $this->model_localisation_country->editCountry($k, array($f => $v));
             }
         }
     }
     if (isset($this->request->post['country_name'])) {
         foreach ($this->request->post['country_name'] as $id => $v) {
             foreach ($v as $lang => $value) {
                 $err = $this->_validateField('name', $value['name']);
                 if (!empty($err)) {
                     $error = new AError('');
                     return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err));
                 }
             }
             $this->model_localisation_country->editCountry($id, array('country_name' => $v));
         }
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 /**
  * @param string $controller
  * @param string $key_param
  * @param string $key_value
  * @return array|null
  */
 public function getPages($controller = '', $key_param = '', $key_value = '')
 {
     $store_id = (int) $this->config->get('config_store_id');
     $cache_name = 'layout.pages' . (!empty($controller) ? '.' . $controller : '') . (!empty($key_param) ? '.' . $key_param : '') . (!empty($key_value) ? '.' . $key_value : '');
     $cache_name = preg_replace('/[^a-zA-Z0-9\\.]/', '', $cache_name);
     $pages = $this->cache->get($cache_name, '', $store_id);
     if (!is_null($pages)) {
         // return cached pages
         return $pages;
     }
     $where = '';
     if (!empty($controller)) {
         $where .= "WHERE controller = '" . $this->db->escape($controller) . "' ";
         if (!empty($key_param)) {
             if (!empty($key_value)) {
                 // so if we have key_param key_value pair we select pages with controller and with or without key_param
                 $where .= " AND ( COALESCE( key_param, '' ) = ''\n\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t( key_param = '" . $this->db->escape($key_param) . "'\n\t\t\t\t\t\t\t\t\t\t\tAND key_value = '" . $this->db->escape($key_value) . "' ) )\n\t\t\t\t\t\t\t\tAND template_id = '" . $this->tmpl_id . "' ";
             } else {
                 //write to log this stuff. it's abnormal situation
                 $message = "Error: Error in data of page with controller: '" . $controller . "'. Please check for key_value present where key_param was set";
                 $this->messages->saveError('Error', $message);
                 $error = new AError($message);
                 $error->toLog()->toDebug();
             }
         }
     }
     $sql = "SELECT p.page_id, controller, key_param, key_value, p.date_added, p.date_modified " . "FROM " . $this->db->table("pages") . " p " . "LEFT JOIN " . $this->db->table("pages_layouts") . " pl ON pl.page_id = p.page_id " . "LEFT JOIN " . $this->db->table("layouts") . " l ON l.layout_id = pl.layout_id " . $where . "ORDER BY key_param DESC, key_value DESC, p.page_id ASC";
     $query = $this->db->query($sql);
     $pages = $query->rows;
     $this->cache->set($cache_name, $pages, '', $store_id);
     return $pages;
 }
Example #27
0
 public function update()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     if (!$this->user->canModify('listing_grid/extension')) {
         $error = new AError('');
         return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/extension'), 'reset_value' => true));
     }
     $this->loadLanguage('extension/extensions');
     $store_id = $this->request->post_or_get('store_id');
     if (empty($this->request->get['id'])) {
         foreach ($this->request->post as $ext => $val) {
             $val['store_id'] = $store_id;
             $this->extension_manager->editSetting($ext, $val);
         }
     } else {
         $val = $this->request->post;
         $val['store_id'] = $store_id;
         $val['one_field'] = true;
         // sign that we change only one setting
         $this->extension_manager->editSetting($this->request->get['id'], $val);
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     if ($this->extension_manager->errors) {
         $error = new AError('');
         return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => '<br>' . implode('<br>', $this->extension_manager->errors), 'reset_value' => true));
     }
 }
 /**
  * @param string $file
  * @return null
  * @void
  */
 private function _remove($file)
 {
     if (empty($file)) {
         return null;
     }
     unlink($file);
     //double check that the cache file to be removed
     if (file_exists($file)) {
         $err_text = sprintf('Error: Cannot delete cache file: %s! Check file or directory permissions.', $file);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
     }
     return null;
 }
Example #29
0
 /**
  * Fast delete of a folder with content files
  *
  * @param   string  $path Full path to the folder to delete.
  * @return  boolean
  * @since   1.2.7
  */
 protected function _delete_directory($path)
 {
     if (!$path || !is_dir($path) || empty($this->path)) {
         $err_text = sprintf('Error: Cannot delete cache folder: %s! Specified folder does not exist.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         return false;
     }
     // Check to make sure path is inside cache folder
     $match = strpos($path, $this->path);
     if ($match === false || $match > 0) {
         $err_text = sprintf('Error: Cannot delete cache folder: %s! Specified path in not within cache folder.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         return false;
     }
     // Remove all the files in folder if they exist; disable all filtering
     $files = $this->_get_files($path, false, array(), array());
     if (!empty($files) && !is_array($files)) {
         if (@unlink($files) !== true) {
             return false;
         }
     } else {
         if (!empty($files) && is_array($files)) {
             foreach ($files as $file) {
                 if (@unlink($file) !== true) {
                     //no permissions to delete
                     $filename = basename($file);
                     $err_text = sprintf('Error: Cannot delete cache file: %s! No permissions to delete.', $filename);
                     $error = new AError($err_text);
                     $error->toLog()->toDebug();
                     return false;
                 }
             }
         }
     }
     //one level directories
     $folders = $this->_get_directories($path, false);
     foreach ($folders as $folder) {
         if (is_link($folder)) {
             //Delete links
             if (@unlink($folder) !== true) {
                 return false;
             }
             //Remove inner folders with recursion
         } else {
             if ($this->_delete_directory($folder) !== true) {
                 return false;
             }
         }
     }
     if (@rmdir($path)) {
         $ret = true;
     } else {
         $err_text = sprintf('Error: Cannot delete cache directory: %s! No permissions to delete.', $path);
         $error = new AError($err_text);
         $error->toLog()->toDebug();
         $ret = false;
     }
     return $ret;
 }
Example #30
0
 /**
 * @param string $sendpoint 
 * @param array $msg_details
 * @return null
 
 	$msg_details structure:
 	array(
 		0 => array(
 			message => 'text',
 		)
 		1 => array(
 			message => 'text',
 		)
 	);
 	0 - storefront (customer) and 1 - Admin (user)
 	notes: If message is not provided, message text will be takes from languages based on checkpoint text key.  
 */
 public function send($sendpoint, $msg_details = array())
 {
     $this->load->language('common/im');
     $customer_im_settings = array();
     if (IS_ADMIN !== true) {
         $sendpoints_list = $this->sendpoints;
         //do have storefront sendpoint?
         if (!empty($sendpoints_list[$sendpoint][0])) {
             $this->load->model('account/customer');
             $customer_im_settings = $this->getCustomerNotificationSettings();
         }
         $this->registry->set('force_skip_errors', true);
     } else {
         $sendpoints_list = $this->admin_sendpoints;
         //this method forbid sending notifications to customers from admin-side
         $customer_im_settings = array();
     }
     //check sendpoint
     if (!in_array($sendpoint, array_keys($sendpoints_list))) {
         $error = new AError('IM error: Unrecognized SendPoint ' . $sendpoint . '. Nothing sent.');
         $error->toLog()->toMessages();
         return false;
     }
     $sendpoint_data = $sendpoints_list[$sendpoint];
     foreach ($this->protocols as $protocol) {
         $driver = null;
         //check protocol status
         if ($protocol == 'email') {
             //email notifications always enabled
             $protocol_status = 1;
         } else {
             if ((int) $this->config->get('config_storefront_' . $protocol . '_status') || (int) $this->config->get('config_admin_' . $protocol . '_status')) {
                 $protocol_status = 1;
             } else {
                 $protocol_status = 0;
             }
         }
         if (!$protocol_status) {
             continue;
         }
         if ($protocol == 'email') {
             //see AMailAIM class below
             $driver = new AMailIM();
         } else {
             $driver_txt_id = $this->config->get('config_' . $protocol . '_driver');
             //if driver not set - skip protocol
             if (!$driver_txt_id) {
                 continue;
             }
             if (!$this->config->get($driver_txt_id . '_status')) {
                 $error = new AError('Cannot send notification. Communication driver ' . $driver_txt_id . ' is disabled!');
                 $error->toLog()->toMessages();
                 continue;
             }
             //use safe usage
             $driver_file = DIR_EXT . $driver_txt_id . '/core/lib/' . $driver_txt_id . '.php';
             if (!is_file($driver_file)) {
                 $error = new AError('Cannot find file ' . $driver_file . ' to send notification.');
                 $error->toLog()->toMessages();
                 continue;
             }
             try {
                 /** @noinspection PhpIncludeInspection */
                 include_once $driver_file;
                 //if class of driver
                 $classname = preg_replace('/[^a-zA-Z]/', '', $driver_txt_id);
                 if (!class_exists($classname)) {
                     $error = new AError('IM-driver ' . $driver_txt_id . ' load error.');
                     $error->toLog()->toMessages();
                     continue;
                 }
                 $driver = new $classname();
             } catch (Exception $e) {
             }
         }
         //if driver cannot be initialized - skip protocol
         if ($driver === null) {
             continue;
         }
         $store_name = $this->config->get('store_name') . ": ";
         if (!empty($sendpoint_data[0])) {
             //send notification to customer, check if selected or forced
             $force_arr = $sendpoint_data[0]['force_send'];
             $forced = false;
             if (has_value($force_arr) && in_array($protocol, $force_arr)) {
                 $forced = true;
             }
             if ($customer_im_settings[$sendpoint][$protocol] || $forced) {
                 $message = $msg_details[0]['message'];
                 //check if notification for this protocol and sendpoint are allowed
                 if ($this->config->get('config_storefront_' . $protocol . '_status') || $protocol == 'email') {
                     if (empty($message)) {
                         //send default message. Not recommended
                         $message = $this->language->get($sendpoint_data[0]['text_key']);
                     }
                     $message = $this->_process_message_text($message);
                     $to = $this->_get_customer_im_uri($protocol);
                     if ($message && $to) {
                         //use safe call
                         try {
                             $driver->send($to, $store_name . $message);
                         } catch (Exception $e) {
                         }
                     }
                 }
             }
         }
         if (!empty($sendpoint_data[1])) {
             //send notification to admins
             if ($this->config->get('config_admin_' . $protocol . '_status') || $protocol == 'email') {
                 $message = $msg_details[1]['message'];
                 if (empty($message)) {
                     //send default message. Not recommended
                     $message = $this->language->get($sendpoint_data[1]['text_key']);
                 }
                 $message = $this->_process_message_text($message, true);
                 //NOTE! all admins will receive IMs
                 $to = $this->_get_admin_im_uri($sendpoint, $protocol);
                 if ($message && $to) {
                     //use safe call
                     try {
                         $driver->sendFew($to, $store_name . $message);
                     } catch (Exception $e) {
                     }
                 }
             }
         }
         unset($driver);
     }
     $this->registry->set('force_skip_errors', false);
     return true;
 }