Esempio n. 1
0
function fn_vendor_data_premoderation_update_company_pre(&$company_data, &$company_id, &$lang_code)
{
    if (fn_allowed_for('MULTIVENDOR') && Registry::get('runtime.company_id')) {
        $orig_company_data = fn_get_company_data($company_id, $lang_code);
        $vendor_profile_updates_approval = Registry::get('addons.vendor_data_premoderation.vendor_profile_updates_approval');
        if ($orig_company_data['status'] == 'A' && ($vendor_profile_updates_approval == 'all' || $vendor_profile_updates_approval == 'custom' && !empty($orig_company_data['pre_moderation_edit_vendors']) && $orig_company_data['pre_moderation_edit_vendors'] == 'Y')) {
            $logotypes = fn_filter_uploaded_data('logotypes_image_icon');
            // FIXME: dirty comparison
            // check that some data is changed
            if (array_diff_assoc($company_data, $orig_company_data) || !empty($logotypes)) {
                $company_data['status'] = 'P';
            }
        }
    }
}
Esempio n. 2
0
function fn_update_attachments($attachment_data, $attachment_id, $object_type, $object_id, $type = 'M', $files = null, $lang_code = DESCR_SL)
{
    $object_id = intval($object_id);
    $directory = $object_type . '/' . $object_id;
    if ($files != null) {
        $uploaded_data = $files;
    } else {
        $uploaded_data = fn_filter_uploaded_data('attachment_files');
    }
    if (!empty($attachment_id)) {
        $rec = array('usergroup_ids' => empty($attachment_data['usergroup_ids']) ? '0' : implode(',', $attachment_data['usergroup_ids']), 'position' => $attachment_data['position']);
        db_query("UPDATE ?:attachment_descriptions SET description = ?s WHERE attachment_id = ?i AND lang_code = ?s", $attachment_data['description'], $attachment_id, $lang_code);
        db_query("UPDATE ?:attachments SET ?u WHERE attachment_id = ?i AND object_type = ?s AND object_id = ?i AND type = ?s", $rec, $attachment_id, $object_type, $object_id, $type);
        fn_set_hook('attachment_update_file', $attachment_data, $attachment_id, $object_type, $object_id, $type, $files, $lang_code, $uploaded_data);
    } elseif (!empty($uploaded_data)) {
        $rec = array('object_type' => $object_type, 'object_id' => $object_id, 'usergroup_ids' => empty($attachment_data['usergroup_ids']) ? '0' : implode(',', $attachment_data['usergroup_ids']), 'position' => $attachment_data['position']);
        if ($type !== null) {
            $rec['type'] = $type;
        } elseif (!empty($attachment_data['type'])) {
            $rec['type'] = $attachment_data['type'];
        }
        $attachment_id = db_query("INSERT INTO ?:attachments ?e", $rec);
        if ($attachment_id) {
            // Add file description
            foreach (fn_get_translation_languages() as $lang_code => $v) {
                $rec = array('attachment_id' => $attachment_id, 'lang_code' => $lang_code, 'description' => is_array($attachment_data['description']) ? $attachment_data['description'][$lang_code] : $attachment_data['description']);
                db_query("INSERT INTO ?:attachment_descriptions ?e", $rec);
            }
            $uploaded_data[$attachment_id] = $uploaded_data[0];
            unset($uploaded_data[0]);
        }
        fn_set_hook('attachment_add_file', $attachment_data, $object_type, $object_id, $type, $files, $attachment_id, $uploaded_data);
    }
    if ($attachment_id && !empty($uploaded_data[$attachment_id]) && $uploaded_data[$attachment_id]['size']) {
        $filename = $uploaded_data[$attachment_id]['name'];
        $old_filename = db_get_field("SELECT filename FROM ?:attachments WHERE attachment_id = ?i", $attachment_id);
        if ($old_filename) {
            Storage::instance('attachments')->delete($directory . '/' . $old_filename);
        }
        list($filesize, $filename) = Storage::instance('attachments')->put($directory . '/' . $filename, array('file' => $uploaded_data[$attachment_id]['path']));
        if ($filesize) {
            $filename = fn_basename($filename);
            db_query("UPDATE ?:attachments SET filename = ?s, filesize = ?i WHERE attachment_id = ?i", $filename, $filesize, $attachment_id);
        }
    }
    return $attachment_id;
}
Esempio n. 3
0
function fn_companies_update_logos($company_id, $old_logos)
{
    $logotypes = fn_filter_uploaded_data('logotypes');
    $areas = fn_companies_get_manifest_definition();
    // Update company logotypes
    if (!empty($logotypes)) {
        $logos = $old_logos;
        foreach ($logotypes as $type => $logo) {
            $area = $areas[$type];
            $short_name = "company/{$company_id}/{$type}_{$logo['name']}";
            $filename = DIR_IMAGES . $short_name;
            fn_mkdir(dirname($filename));
            if (fn_copy($logo['path'], $filename)) {
                list($w, $h, ) = fn_get_image_size($filename);
                $logos[$area['name']] = array('vendor' => 1, 'filename' => $short_name, 'width' => $w, 'height' => $h);
            } else {
                $text = fn_get_lang_var('text_cannot_create_file');
                $text = str_replace('[file]', $filename, $text);
                fn_set_notification('E', fn_get_lang_var('error'), $text);
            }
            @unlink($logo['path']);
        }
        $logos = serialize($logos);
        db_query("UPDATE ?:companies SET logos = ?s WHERE company_id = ?i", $logos, $company_id);
    }
    fn_save_logo_alt($areas, $company_id);
}
Esempio n. 4
0
             $url = empty($url) ? fn_url('exim.export?section=' . $_REQUEST['section']) : $url;
             return array(CONTROLLER_STATUS_OK, $url);
         } else {
             $delete_range_url = fn_url("exim.delete_range?section={$pattern['section']}&pattern_id={$pattern['pattern_id']}");
             fn_set_notification('E', __('error'), __('error_exim_no_data_exported_new', array("[url]" => $delete_range_url)));
         }
     } else {
         fn_set_notification('E', __('error'), __('error_exim_fields_not_selected'));
     }
     exit;
 }
 //
 // Perform import
 //
 if ($mode == 'import') {
     $file = fn_filter_uploaded_data('csv_file');
     if (!empty($file)) {
         if (empty($_REQUEST['pattern_id'])) {
             fn_set_notification('E', __('error'), __('error_exim_pattern_not_found'));
         } else {
             $pattern = fn_get_pattern_definition($_REQUEST['pattern_id'], 'import');
             if (($data = fn_get_csv($pattern, $file[0]['path'], $_REQUEST['import_options'])) != false) {
                 fn_import($pattern, $data, $_REQUEST['import_options']);
             }
         }
     } else {
         fn_set_notification('E', __('error'), __('error_exim_no_file_uploaded'));
     }
     return array(CONTROLLER_STATUS_OK, 'exim.import?section=' . $_REQUEST['section'] . '&pattern_id=' . $_REQUEST['pattern_id']);
 }
 if ($mode == 'delete_file' && !empty($_REQUEST['filename'])) {
Esempio n. 5
0
                 }
             }
         }
         if (!$errors) {
             $lc = Languages::update($lang_data, $_REQUEST['lang_id']);
         }
         if ($lc !== false) {
             fn_save_languages_integrity();
         }
     }
     if ($lc == false) {
         fn_delete_notification('changes_saved');
     }
 }
 if ($mode == 'install_from_po') {
     $uploaded_data = fn_filter_uploaded_data('language_data', array('po', 'zip'));
     if (!empty($uploaded_data['po_file']['path'])) {
         $ext = fn_get_file_ext($uploaded_data['po_file']['name']);
         if ($ext == 'po') {
             $result = Languages::installLanguagePack($uploaded_data['po_file']['path']);
         } else {
             $result = Languages::installZipPack($uploaded_data['po_file']['path']);
         }
         if (!$result) {
             fn_delete_notification('changes_saved');
         }
     }
 }
 if ($mode == 'install' && !empty($_REQUEST['pack'])) {
     $pack_path = Registry::get('config.dir.lang_packs') . fn_basename($_REQUEST['pack']);
     if (Languages::installCrowdinPack($pack_path, array())) {
Esempio n. 6
0
 // Restore
 if ($mode == 'restore') {
     if (!empty($_REQUEST['backup_files'])) {
         fn_restore_dump($_REQUEST['backup_files']);
     }
     fn_set_notification('N', __('notice'), __('done'));
 }
 if ($mode == 'm_delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(Registry::get('config.dir.database') . fn_basename($file));
         }
     }
 }
 if ($mode == 'upload') {
     $sql_dump = fn_filter_uploaded_data('sql_dump', array('sql', 'tgz'));
     if (!empty($sql_dump)) {
         $sql_dump = array_shift($sql_dump);
         if (fn_copy($sql_dump['path'], Registry::get('config.dir.database') . $sql_dump['name'])) {
             fn_set_notification('N', __('notice'), __('done'));
         } else {
             fn_set_notification('N', __('notice'), __('dump_cant_create_file'));
         }
     } else {
         fn_set_notification('N', __('notice'), __('cant_upload_file'));
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
Esempio n. 7
0
         if ($restore_result === true) {
             fn_set_notification('N', __('notice'), __('done'));
         } else {
             fn_set_notification('E', __('error'), $restore_result);
         }
     }
 }
 if ($mode == 'm_delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(Registry::get('config.dir.backups') . fn_basename($file));
         }
     }
 }
 if ($mode == 'upload') {
     $dump = fn_filter_uploaded_data('dump', array('sql', 'tgz', 'zip'));
     if (!empty($dump)) {
         $dump = array_shift($dump);
         // Check if backups folder exists. If not - create it
         if (!is_dir(Registry::get('config.dir.backups'))) {
             fn_mkdir(Registry::get('config.dir.backups'));
         }
         if (fn_copy($dump['path'], Registry::get('config.dir.backups') . $dump['name'])) {
             fn_set_notification('N', __('notice'), __('done'));
         } else {
             fn_set_notification('E', __('error'), __('cant_create_backup_file'));
         }
     } else {
         fn_set_notification('E', __('error'), __('cant_upload_file'));
     }
 }
 private static function _getUploadedLogos()
 {
     $logos = fn_filter_uploaded_data('tw_settings');
     $logo_names = array('logo', 'favicon');
     $options = array();
     foreach ($logo_names as $logo_name) {
         if ($logos and !empty($logos[$logo_name])) {
             $logo = $logos[$logo_name];
             $filename = fn_twg_get_images_path() . $logo['name'];
             // On some hosts files copy buggy
             touch($filename);
             if (!fn_copy($logo['path'], $filename)) {
                 $_text = __('text_cannot_create_file');
                 $text = str_replace('[file]', $filename, $_text);
                 fn_set_notification('E', __('error'), $text);
             } else {
                 $options[$logo_name . '_url'] = $filename;
             }
             @unlink($logo['path']);
         }
     }
     return $options;
 }
Esempio n. 9
0
            fn_put_contents($file_path, $_REQUEST['file_content']);
            fn_set_notification('N', __('notice'), __('text_file_saved', array('[file]' => fn_basename($file_path))));
            Tygh::$app['ajax']->assign('saved', true);
            // Clear template cache of updated template for the customer front-end
            $view = Tygh::$app['view'];
            $view->setArea('C', '', Registry::get('runtime.company_id'));
            $updated_template_path = str_replace($view->getTemplateDir(0), '', $file_path);
            $view->clearCompiledTemplate($updated_template_path);
            $view->setArea(AREA, '', Registry::get('runtime.company_id'));
        } else {
            fn_set_notification('E', __('error'), __('cannot_write_file', array('[file]' => fn_get_rel_dir($file_path))));
        }
        exit;
    }
    if ($mode == 'upload_file') {
        $uploaded_data = fn_filter_uploaded_data('uploaded_data');
        $pname = fn_normalize_path($root_dir . $_REQUEST['path'] . '/');
        foreach ((array) $uploaded_data as $udata) {
            if (fn_te_check_path($pname)) {
                if (!fn_copy($udata['path'], $pname . $udata['name'])) {
                    fn_set_notification('E', __('error'), __('cannot_write_file', array('[file]' => fn_get_rel_dir($pname . $udata['name']))));
                }
            }
        }
        return array(CONTROLLER_STATUS_OK, "templates.manage");
    }
}
if ($mode == 'manage') {
    if (!empty($_REQUEST['selected_path'])) {
        Tygh::$app['view']->assign('selected_path', '/' . fn_te_form_path($_REQUEST['selected_path']));
    }
Esempio n. 10
0
function fn_add_product_options_files($product_data, &$cart, &$auth, $update = false, $location = 'cart')
{
    // Check if products have cusom images
    if (!$update) {
        $uploaded_data = fn_filter_uploaded_data('product_data');
    } else {
        $uploaded_data = fn_filter_uploaded_data('cart_products');
    }
    // Check for the already uploaded files
    if (!empty($product_data['custom_files']['uploaded'])) {
        foreach ($product_data['custom_files']['uploaded'] as $file_id => $file_data) {
            if (Storage::instance('images')->isExist('sess_data/' . fn_basename($file_data['path']))) {
                $id = $file_data['product_id'] . $file_data['option_id'] . $file_id;
                $uploaded_data[$id] = array('name' => $file_data['name'], 'path' => 'sess_data/' . fn_basename($file_data['path']));
                $product_data['custom_files'][$id] = $file_data['product_id'] . '_' . $file_data['option_id'];
            }
        }
    }
    if (!empty($uploaded_data) && !empty($product_data['custom_files'])) {
        $files_data = array();
        foreach ($uploaded_data as $key => $file) {
            $file_info = fn_pathinfo($file['name']);
            $file['extension'] = empty($file_info['extension']) ? '' : $file_info['extension'];
            $file['is_image'] = fn_get_image_extension($file['type']);
            $_data = explode('_', $product_data['custom_files'][$key]);
            $product_id = empty($_data[0]) ? 0 : $_data[0];
            $option_id = empty($_data[1]) ? 0 : $_data[1];
            $file_id = str_replace($option_id . $product_id, '', $key);
            if (empty($file_id)) {
                $files_data[$product_id][$option_id][] = $file;
            } else {
                $files_data[$product_id][$option_id][$file_id] = $file;
            }
        }
    }
    unset($product_data['custom_files']);
    foreach ($product_data as $key => $data) {
        $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
        // Check if product has cusom images
        if ($update || isset($files_data[$key])) {
            $hash = $key;
        } else {
            $hash = $product_id;
        }
        $_options = fn_get_product_options($product_id);
        if (!empty($files_data[$hash]) && is_array($files_data[$hash])) {
            foreach ($files_data[$hash] as $option_id => $files) {
                foreach ($files as $file_id => $file) {
                    // Check for the allowed extensions
                    if (!empty($_options[$option_id]['allowed_extensions'])) {
                        if (empty($file['extension']) && !empty($_options[$option_id]['allowed_extensions']) || !preg_match("/\\b" . $file['extension'] . "\\b/i", $_options[$option_id]['allowed_extensions'])) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_extension', array('[ext]' => $file['extension'], '[exts]' => $_options[$option_id]['allowed_extensions'])));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    // Check for the max file size
                    if (!empty($_options[$option_id]['max_file_size'])) {
                        if (empty($file['size'])) {
                            $file['size'] = filesize($file['path']);
                        }
                        if ($file['size'] > $_options[$option_id]['max_file_size'] * 1024) {
                            fn_set_notification('E', __('error'), $file['name'] . ': ' . __('text_forbidden_uploaded_file_size', array('[size]' => $_options[$option_id]['max_file_size'] . ' kb')));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    $_file_path = 'sess_data/file_' . uniqid(TIME);
                    list(, $_file_path) = Storage::instance('custom_files')->put($_file_path, array('file' => $file['path']));
                    if (!$_file_path) {
                        fn_set_notification('E', __('error'), __('text_cannot_create_file', array('[file]' => $file['name'])));
                        unset($files_data[$hash][$option_id][$file_id]);
                        continue;
                    }
                    $file['path'] = $_file_path;
                    $file['file'] = fn_basename($file['path']);
                    if ($file['is_image']) {
                        $file['thumbnail'] = 'image.custom_image?image=' . $file['file'] . '&type=T';
                        $file['detailed'] = 'image.custom_image?image=' . $file['file'] . '&type=D';
                    }
                    $file['location'] = $location;
                    if ($update) {
                        $cart['products'][$key]['extra']['custom_files'][$option_id][] = $file;
                    } else {
                        $data['extra']['custom_files'][$option_id][] = $file;
                    }
                }
                if ($update) {
                    if (!empty($cart['products'][$key]['product_options'][$option_id])) {
                        $cart['products'][$key]['product_options'][$option_id] = md5(serialize($cart['products'][$key]['extra']['custom_files'][$option_id]));
                    }
                } else {
                    if (!empty($data['extra']['custom_files'][$option_id])) {
                        $data['product_options'][$option_id] = md5(serialize($data['extra']['custom_files'][$option_id]));
                    }
                }
            }
            // Check the required options
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && !$update) {
                        if (empty($data['product_options'][$option['option_id']])) {
                            fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                            unset($product_data[$key]);
                            return array($product_data, $cart);
                        }
                    }
                }
            }
        } else {
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && empty($cart['products'][$hash]['extra']['custom_files'][$option['option_id']]) && empty($data['extra']['custom_files'][$option['option_id']])) {
                        fn_set_notification('E', __('error'), __('product_cannot_be_added'));
                        unset($product_data[$key]);
                        return array($product_data, $cart);
                    }
                }
            }
        }
        if ($update) {
            foreach ($_options as $option) {
                if ($option['option_type'] == 'F' && empty($cart['products'][$key]['extra']['custom_files'][$option['option_id']])) {
                    unset($cart['products'][$key]['extra']['custom_files'][$option['option_id']]);
                    unset($cart['products'][$key]['product_options'][$option['option_id']]);
                    unset($data['product_options'][$option['option_id']]);
                }
            }
        }
        if (isset($cart['products'][$key]['extra']['custom_files'])) {
            foreach ($cart['products'][$key]['extra']['custom_files'] as $option_id => $files) {
                foreach ($files as $file) {
                    $data['extra']['custom_files'][$option_id][] = $file;
                }
                $data['product_options'][$option_id] = md5(serialize($files));
            }
        }
        $product_data[$key] = $data;
    }
    return array($product_data, $cart);
}
Esempio n. 11
0
function fn_update_attachments($attachment_data, $attachment_id, $object_type, $object_id, $type = 'M', $lang_code = CART_LANGUAGE)
{
    $object_id = intval($object_id);
    if (!fn_mkdir(DIR_ATTACHMENTS)) {
        return false;
    }
    $revision_id = 0;
    if (AREA == 'A' && Registry::is_exist('revisions') && !Registry::get('revisions.working')) {
        $revisions = Registry::get('revisions');
        if (!empty($revisions['objects'][$object_type]) && !empty($revisions['objects'][$object_type]['tables'])) {
            $object_data = $revisions['objects'][$object_type];
            if ($object_data['attachments']) {
                $entry = array($object_data['key'] => $object_id);
                list($revision, $revision_id) = fn_revisions_get_last($object_type, $entry, 0, 'attachments');
            }
        }
    }
    if ($revision_id) {
        $_ = 'rev_';
        $revision_condition = db_quote(" AND revision = ?s AND revision_id = ?i", $revision, $revision_id);
    } else {
        $_ = '';
        $revision_condition = '';
    }
    $directory = DIR_ATTACHMENTS . '/' . $object_type . ($revision_condition ? '_rev' : '') . '/' . $object_id;
    if (!fn_mkdir($directory)) {
        return false;
    }
    $uploaded_data = fn_filter_uploaded_data('attachment_files');
    $rec = array('usergroup_ids' => empty($attachment_data['usergroup_ids']) ? '' : implode(',', $attachment_data['usergroup_ids']), 'position' => $attachment_data['position']);
    db_query("UPDATE ?:{$_}attachment_descriptions SET description = ?s WHERE attachment_id = ?i AND lang_code = ?s ?p", $attachment_data['description'], $attachment_id, $lang_code, $revision_condition);
    db_query("UPDATE ?:{$_}attachments SET ?u WHERE attachment_id = ?i AND object_type = ?s AND object_id = ?i AND type = ?s ?p", $rec, $attachment_id, $object_type, $object_id, $type, $revision_condition);
    if ($attachment_id && !empty($uploaded_data[$attachment_id]) && $uploaded_data[$attachment_id]['size']) {
        $filename = $uploaded_data[$attachment_id]['name'];
        $old_filename = db_get_field("SELECT filename FROM ?:{$_}attachments WHERE attachment_id = ?i ?p", $attachment_id, $revision_condition);
        if (!$revision_id && $old_filename && is_file($directory . '/' . $old_filename)) {
            unlink($directory . '/' . $old_filename);
        }
        $i = 1;
        while (is_file($directory . '/' . $filename)) {
            $filename = substr_replace($uploaded_data[$attachment_id]['name'], sprintf('%03d', $i) . '.', strrpos($uploaded_data[$attachment_id]['name'], '.'), 1);
            $i++;
        }
        fn_copy($uploaded_data[$attachment_id]['path'], $directory . '/' . $filename);
        if (is_file($directory . '/' . $filename)) {
            $filesize = filesize($directory . '/' . $filename);
            db_query("UPDATE ?:{$_}attachments SET filename = ?s, filesize = ?i WHERE attachment_id = ?i ?p", $filename, $filesize, $attachment_id, $revision_condition);
        }
    }
    return true;
}
Esempio n. 12
0
function fn_send_form($page_id, $form_values)
{
    $result = false;
    if (!empty($form_values)) {
        $page_data = fn_get_page_data($page_id);
        if (!empty($page_data['form']['elements'])) {
            $result = true;
            $attachments = array();
            $fb_files = fn_filter_uploaded_data('fb_files');
            if (!empty($fb_files)) {
                foreach ($fb_files as $k => $v) {
                    $attachments[$v['name']] = $v['path'];
                    $form_values[$k] = $v['name'];
                }
            }
            $max_length = 0;
            $sender = '';
            foreach ($page_data['form']['elements'] as $k => $v) {
                if (($l = strlen($v['description'])) > $max_length) {
                    $max_length = $l;
                }
                // Check if sender email exists
                if ($v['element_type'] == FORM_EMAIL) {
                    $sender = $form_values[$k];
                }
                if ($v['element_type'] == FORM_DATE) {
                    $form_values[$k] = fn_parse_date($form_values[$k]);
                }
                if ($v['element_type'] == FORM_REFERER) {
                    $form_values[$k] = $_SESSION['auth']['referer'];
                }
                if ($v['element_type'] == FORM_IP_ADDRESS) {
                    $ip = fn_get_ip();
                    $form_values[$k] = $ip['host'];
                }
            }
            $max_length += 2;
            if ($result == true) {
                $from = 'default_company_support_department';
                $is_html = true;
                fn_set_hook('send_form', $page_data, $form_values, $result, $from, $sender, $attachments, $is_html);
                if ($result == true) {
                    Mailer::sendMail(array('to' => $page_data['form']['general'][FORM_RECIPIENT], 'from' => $from, 'reply_to' => $sender, 'data' => array('max_length' => $max_length, 'elements' => $page_data['form']['elements'], 'form_title' => $page_data['page'], 'form_values' => $form_values), 'attachments' => $attachments, 'tpl' => 'addons/form_builder/form.tpl', 'is_html' => $is_html), 'A');
                }
            }
        }
    }
    return $result;
}
Esempio n. 13
0
function fn_send_form($page_id, $form_values)
{
    if (!empty($form_values)) {
        $page_data = fn_get_page_data($page_id);
        if (empty($page_data['form']['elements'])) {
            return false;
        }
        $attachments = array();
        $fb_files = fn_filter_uploaded_data('fb_files');
        if (!empty($fb_files)) {
            foreach ($fb_files as $k => $v) {
                $attachments[$v['name']] = $v['path'];
                $form_values[$k] = $v['name'];
            }
        }
        $max_length = 0;
        $sender = '';
        foreach ($page_data['form']['elements'] as $k => $v) {
            if (($l = strlen($v['description'])) > $max_length) {
                $max_length = $l;
            }
            if ($v['element_type'] == FORM_EMAIL_CONFIRM) {
                if (!is_array($form_values[$k]) || $form_values[$k][0] != $form_values[$k][1] || empty($form_values[$k][0]) || $form_values[$k][1]) {
                    return false;
                }
                $form_values[$k] = $form_values[$k][0];
            }
            // Check if sender email exists
            if ($v['element_type'] == FORM_EMAIL || $v['element_type'] == FORM_EMAIL_CONFIRM) {
                $sender = $form_values[$k];
            }
            if ($v['element_type'] == FORM_DATE) {
                $form_values[$k] = fn_parse_date($form_values[$k]);
            }
            if ($v['element_type'] == FORM_REFERER) {
                $form_values[$k] = $_SESSION['auth']['referer'];
            }
            if ($v['element_type'] == FORM_IP_ADDRESS) {
                $ip = fn_get_ip();
                $form_values[$k] = $ip['host'];
            }
        }
        $max_length += 2;
        fn_set_hook('send_form', $page_data, $form_values);
        Registry::get('view_mail')->assign('max_length', $max_length);
        Registry::get('view_mail')->assign('elements', $page_data['form']['elements']);
        Registry::get('view_mail')->assign('form_title', $page_data['page']);
        Registry::get('view_mail')->assign('form_values', $form_values);
        fn_send_mail($page_data['form']['general'][FORM_RECIPIENT], Registry::get('settings.Company.company_support_department'), 'addons/form_builder/form_subject.tpl', 'addons/form_builder/form_body.tpl', $attachments, CART_LANGUAGE, $sender);
    }
    return false;
}
Esempio n. 14
0
         }
         fn_stop_scroller();
         fn_rm(DIR_CACHE, false);
         // cleanup cache
     }
     $suffix = '?selected_section=restore';
 }
 if ($mode == 'delete') {
     if (!empty($_REQUEST['backup_files'])) {
         foreach ($_REQUEST['backup_files'] as $file) {
             @unlink(DIR_DATABASE . 'backup/' . $file);
         }
     }
 }
 if ($mode == 'upload') {
     $sql_dump = fn_filter_uploaded_data('sql_dump');
     if (!empty($sql_dump)) {
         $sql_dump = array_shift($sql_dump);
         fn_copy($sql_dump['path'], DIR_DATABASE . 'backup/' . $sql_dump['name']);
     }
 }
 if ($mode == 'optimize') {
     // Log database optimization
     fn_log_event('database', 'optimize');
     $all_tables = db_get_fields("SHOW TABLES");
     fn_start_scroller();
     foreach ($all_tables as $table) {
         fn_echo(fn_get_lang_var('optimizing_table') . "&nbsp;<b>{$table}</b>...<br />");
         db_query("OPTIMIZE TABLE {$table}");
         db_query("ANALYZE TABLE {$table}");
         $fields = db_get_hash_array("SHOW COLUMNS FROM {$table}", 'Field');
Esempio n. 15
0
function fn_add_product_options_files($product_data, &$cart, &$auth, $update = false, $location = 'cart')
{
    // Check if products have cusom images
    if (!$update) {
        $uploaded_data = fn_filter_uploaded_data('product_data');
    } else {
        $uploaded_data = fn_filter_uploaded_data('cart_products');
    }
    $dir_path = DIR_CUSTOM_FILES . 'sess_data';
    // Check for the already uploaded files
    if (!empty($product_data['custom_files']['uploaded'])) {
        foreach ($product_data['custom_files']['uploaded'] as $file_id => $file_data) {
            if (file_exists($dir_path . '/' . basename($file_data['path']))) {
                $id = $file_data['product_id'] . $file_data['option_id'] . $file_id;
                $uploaded_data[$id] = array('name' => $file_data['name'], 'path' => $dir_path . '/' . basename($file_data['path']));
                $product_data['custom_files'][$id] = $file_data['product_id'] . '_' . $file_data['option_id'];
            }
        }
    }
    if (!empty($uploaded_data) && !empty($product_data['custom_files'])) {
        $files_data = array();
        foreach ($uploaded_data as $key => $file) {
            $file_info = pathinfo($file['name']);
            $file['extension'] = empty($file_info['extension']) ? '' : $file_info['extension'];
            $file_info = getimagesize($file['path']);
            $file['type'] = $file_info['mime'];
            $file['is_image'] = fn_get_image_extension($file_info['mime']);
            $_data = explode('_', $product_data['custom_files'][$key]);
            $product_id = empty($_data[0]) ? 0 : $_data[0];
            $option_id = empty($_data[1]) ? 0 : $_data[1];
            $file_id = str_replace($option_id . $product_id, '', $key);
            if (empty($file_id)) {
                $files_data[$product_id][$option_id][] = $file;
            } else {
                $files_data[$product_id][$option_id][$file_id] = $file;
            }
        }
        if (!is_dir($dir_path)) {
            if (!fn_mkdir($dir_path)) {
                // Unable to create a directory
                fn_set_notification('E', fn_get_lang_var('error'), str_replace('[directory]', DIR_CUSTOM_FILES, fn_get_lang_var('text_cannot_write_directory')));
            }
        }
    }
    unset($product_data['custom_files']);
    foreach ($product_data as $key => $data) {
        $product_id = !empty($data['product_id']) ? $data['product_id'] : $key;
        // Check if product has cusom images
        if ($update || isset($files_data[$key])) {
            $hash = $key;
        } else {
            $hash = $product_id;
        }
        if (!empty($files_data[$hash]) && is_array($files_data[$hash])) {
            $_options = fn_get_product_options($product_id);
            foreach ($files_data[$hash] as $option_id => $files) {
                foreach ($files as $file_id => $file) {
                    // Check for the allowed extensions
                    if (!empty($_options[$option_id]['allowed_extensions'])) {
                        if (empty($file['extension']) && !empty($_options[$option_id]['allowed_extensions']) || !preg_match("/\\b" . $file['extension'] . "\\b/i", $_options[$option_id]['allowed_extensions'])) {
                            $message = fn_get_lang_var('text_forbidden_uploaded_file_extension');
                            $message = str_replace('[ext]', $file['extension'], $message);
                            $message = str_replace('[exts]', $_options[$option_id]['allowed_extensions'], $message);
                            fn_set_notification('E', fn_get_lang_var('error'), $file['name'] . ': ' . $message);
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    // Check for the max file size
                    if (!empty($_options[$option_id]['max_file_size'])) {
                        if (empty($file['size'])) {
                            $file['size'] = filesize($file['path']);
                        }
                        if ($file['size'] > $_options[$option_id]['max_file_size'] * 1024) {
                            fn_set_notification('E', fn_get_lang_var('error'), str_replace('[size]', $_options[$option_id]['max_file_size'] . ' kb', $file['name'] . ': ' . fn_get_lang_var('text_forbidden_uploaded_file_size')));
                            unset($files_data[$hash][$option_id][$file_id]);
                            continue;
                        }
                    }
                    $_file_path = tempnam($dir_path, 'file_');
                    if (!fn_copy($file['path'], $_file_path)) {
                        fn_set_notification('E', fn_get_lang_var('error'), str_replace('[file]', $file['name'], fn_get_lang_var('text_cannot_create_file')));
                        unset($files_data[$hash][$option_id][$file_id]);
                        continue;
                    }
                    $file['path'] = $_file_path;
                    $file['file'] = basename($file['path']);
                    if ($file['is_image']) {
                        $file['thumbnail'] = 'image.custom_image&image=' . $file['file'] . '&type=T';
                        $file['detailed'] = 'image.custom_image&image=' . $file['file'] . '&type=D';
                    }
                    $file['location'] = $location;
                    if ($update) {
                        $cart['products'][$key]['extra']['custom_files'][$option_id][] = $file;
                    } else {
                        $data['extra']['custom_files'][$option_id][] = $file;
                    }
                }
                if ($update) {
                    if (!empty($cart['products'][$key]['product_options'][$option_id])) {
                        $cart['products'][$key]['product_options'][$option_id] = md5(serialize($cart['products'][$key]['extra']['custom_files'][$option_id]));
                    }
                } else {
                    if (!empty($data['extra']['custom_files'][$option_id])) {
                        $data['product_options'][$option_id] = md5(serialize($data['extra']['custom_files'][$option_id]));
                    }
                }
            }
            // Check the required options
            if (empty($data['extra']['parent'])) {
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && !$update) {
                        if (empty($data['product_options'][$option['option_id']])) {
                            fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('product_cannot_be_added'));
                            unset($product_data[$key]);
                            return array($product_data, $cart);
                        }
                    }
                }
            }
        } else {
            if (empty($data['extra']['parent'])) {
                $_options = fn_get_product_options($product_id);
                foreach ($_options as $option) {
                    if ($option['option_type'] == 'F' && $option['required'] == 'Y' && empty($cart['products'][$hash]['extra']['custom_files'][$option['option_id']]) && empty($data['extra']['custom_files'][$option['option_id']])) {
                        fn_set_notification('E', fn_get_lang_var('error'), fn_get_lang_var('product_cannot_be_added'));
                        unset($product_data[$key]);
                        return array($product_data, $cart);
                    }
                }
            }
        }
        if (isset($cart['products'][$key]['extra']['custom_files'])) {
            foreach ($cart['products'][$key]['extra']['custom_files'] as $option_id => $files) {
                foreach ($files as $file) {
                    $data['extra']['custom_files'][$option_id][] = $file;
                }
                $data['product_options'][$option_id] = md5(serialize($files));
            }
        }
        $product_data[$key] = $data;
    }
    return array($product_data, $cart);
}
Esempio n. 16
0
 if ($mode == 'store_selection') {
     if (!empty($_REQUEST['product_ids'])) {
         $_SESSION['product_ids'] = $_REQUEST['product_ids'];
         $_SESSION['selected_fields'] = $_REQUEST['selected_fields'];
         unset($_REQUEST['redirect_url']);
         $suffix = ".m_update";
     } else {
         $suffix = ".manage";
     }
 }
 //
 // Add edp files to the product
 //
 if ($mode == 'update_file') {
     $uploaded_data = fn_filter_uploaded_data('base_file');
     $uploaded_preview_data = fn_filter_uploaded_data('file_preview');
     db_query("UPDATE ?:products SET is_edp = 'Y' WHERE product_id = ?i", $_REQUEST['product_id']);
     $revisions = Registry::get('revisions');
     if (!empty($revisions['objects']['product']['tables'])) {
         $revision_subdir = '_rev';
     } else {
         $revision_subdir = '';
     }
     if (!is_dir(substr(DIR_DOWNLOADS, 0, -1) . $revision_subdir . '/' . $_REQUEST['product_id'])) {
         if (fn_mkdir(substr(DIR_DOWNLOADS, 0, -1) . $revision_subdir . '/' . $_REQUEST['product_id']) == false) {
             $msg = str_replace('[directory]', substr(DIR_DOWNLOADS, 0, -1) . $revision_subdir . '/' . $_REQUEST['product_id'], fn_get_lang_var('text_cannot_create_directory'));
             fn_set_notification('E', fn_get_lang_var('error'), $msg);
         }
     }
     $_file_id = empty($_REQUEST['file_id']) ? 0 : $_REQUEST['file_id'];
     $product_file = $_REQUEST['product_file'];
Esempio n. 17
0
function fn_theme_editor_save_style($style_id, $style)
{
    $theme_name = fn_get_theme_path('[theme]', 'C');
    if (empty($style_id) && !empty($style['name'])) {
        $style_id = $style['name'];
        Styles::factory($theme_name)->copy(Registry::get('runtime.layout.style_id'), $style_id);
    }
    if (empty($style) || empty($style['data']) || empty($style_id)) {
        return false;
    }
    // Attach patterns
    $uploaded_data = fn_filter_uploaded_data('backgrounds');
    if (!empty($uploaded_data)) {
        $style = Patterns::instance()->save($style_id, $style, $uploaded_data);
    }
    // Save style data
    if (!Styles::factory($theme_name)->update($style_id, $style)) {
        //FIXME: Presets backward compability
        $path = fn_get_theme_path('[relative]/[theme]/styles');
        if (!is_dir($path)) {
            $path = fn_get_theme_path('[relative]/[theme]/presets');
        }
        fn_set_notification('E', __('error'), __('theme_editor.style_data_cannot_be_saved', array('[theme_dir]' => $path)));
        return false;
    }
    fn_theme_editor_set_style($style_id);
    return $style_id;
}
Esempio n. 18
0
/**
 * Update product file
 *
 * @param array $product_file file data
 * @param int $file_id file ID for update, if empty - new file will be created
 * @param string $lang_code language code to update file description
 * @return boolean true on success, false - otherwise
 */
function fn_update_product_file($product_file, $file_id, $lang_code = DESCR_SL)
{
    if (!fn_company_products_check($product_file['product_id'], true)) {
        return false;
    }
    $uploaded_data = fn_filter_uploaded_data('base_file');
    $uploaded_preview_data = fn_filter_uploaded_data('file_preview');
    if (!empty($file_id) || !empty($uploaded_data[$file_id])) {
        db_query("UPDATE ?:products SET is_edp = 'Y' WHERE product_id = ?i", $product_file['product_id']);
        if (!empty($uploaded_data[$file_id])) {
            $product_file['file_name'] = empty($product_file['file_name']) ? $uploaded_data[$file_id]['name'] : $product_file['file_name'];
        }
        // Remove old file before uploading a new one
        if (!empty($file_id)) {
            $dir = $product_file['product_id'];
            $old_file = db_get_row('SELECT file_path, preview_path FROM ?:product_files WHERE product_id = ?i AND file_id = ?i', $product_file['product_id'], $file_id);
            if (!empty($uploaded_data) && !empty($old_file['file_path'])) {
                Storage::instance('downloads')->delete($dir . '/' . $old_file['file_path']);
            }
            if (!empty($uploaded_preview_data) && !empty($old_file['preview_path'])) {
                Storage::instance('downloads')->delete($dir . '/' . $old_file['preview_path']);
            }
        }
        // Update file data
        if (empty($file_id)) {
            $product_file['file_id'] = $file_id = db_query('INSERT INTO ?:product_files ?e', $product_file);
            foreach (fn_get_translation_languages() as $product_file['lang_code'] => $v) {
                db_query('INSERT INTO ?:product_file_descriptions ?e', $product_file);
            }
            $uploaded_id = 0;
        } else {
            db_query('UPDATE ?:product_files SET ?u WHERE file_id = ?i', $product_file, $file_id);
            db_query('UPDATE ?:product_file_descriptions SET ?u WHERE file_id = ?i AND lang_code = ?s', $product_file, $file_id, $lang_code);
            $uploaded_id = $file_id;
        }
        // Copy base file
        if (!empty($uploaded_data[$uploaded_id])) {
            fn_copy_product_files($file_id, $uploaded_data[$uploaded_id], $product_file['product_id']);
        }
        // Copy preview file
        if (!empty($uploaded_preview_data[$uploaded_id])) {
            fn_copy_product_files($file_id, $uploaded_preview_data[$uploaded_id], $product_file['product_id'], 'preview');
        }
    }
    return $file_id;
}
Esempio n. 19
0
     if (Registry::get('runtime.company_id')) {
         $filename = Registry::get('runtime.company_id') . '/' . $filename;
     }
     fn_mkdir(dirname(Registry::get('config.dir.layouts') . $filename));
     fn_put_contents(Registry::get('config.dir.layouts') . $filename, $content);
     fn_set_notification('N', __('notice'), __('text_exim_data_exported'));
     // Direct download
     if ($_REQUEST['output'] == 'D') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.manage?meta_redirect_url=block_manager.get_file%26filename=' . $_REQUEST['filename']);
         // Output to screen
     } elseif ($_REQUEST['output'] == 'C') {
         return array(CONTROLLER_STATUS_REDIRECT, 'block_manager.get_file?to_screen=Y&filename=' . $_REQUEST['filename']);
     }
 }
 if ($mode == 'import_layout') {
     $data = fn_filter_uploaded_data('filename');
     if (!empty($data[0]['path'])) {
         $result = Exim::instance()->importFromFile($data[0]['path'], $_REQUEST);
         if ($result) {
             fn_set_notification('N', __('notice'), __('text_exim_data_imported_clear'));
         }
     }
 }
 if ($mode == 'update_status') {
     $type = empty($_REQUEST['type']) ? 'block' : $_REQUEST['type'];
     if ($type == 'block') {
         Block::instance()->updateStatus($_REQUEST);
     } elseif ($type == 'grid') {
         Grid::update($_REQUEST);
     } elseif ($type == 'container') {
         Container::update($_REQUEST);
Esempio n. 20
0
function fn_attach_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, $object_ids = array(), $parent_object = '', $parent_object_id = 0)
{
    $icons = fn_filter_uploaded_data($name . '_image_icon');
    $detailed = fn_filter_uploaded_data($name . '_image_detailed');
    $pairs_data = !empty($_REQUEST[$name . '_image_data']) ? $_REQUEST[$name . '_image_data'] : array();
    return fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, $parent_object, $parent_object_id, true, false, $lang_code);
}
Esempio n. 21
0
    return include Registry::get('config.dir.upgrade') . $_SESSION['uc_package'] . '/uc_override.php';
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'update_settings') {
        if (!empty($_REQUEST['settings_data'])) {
            foreach ($_REQUEST['settings_data'] as $setting_name => $setting_value) {
                Settings::instance()->updateValue($setting_name, $setting_value, 'Upgrade_center');
            }
        }
    }
    if ($mode == 'download') {
        $app->downloadPackage($_REQUEST['id']);
        return array(CONTROLLER_STATUS_REDIRECT, 'upgrade_center.manage');
    }
    if ($mode == 'upload') {
        $upgrade_pack = fn_filter_uploaded_data('upgrade_pack', Registry::get('config.allowed_pack_exts'));
        if (empty($upgrade_pack[0])) {
            fn_set_notification('E', __('error'), __('text_allowed_to_upload_file_extension', array('[ext]' => implode(',', Registry::get('config.allowed_pack_exts')))));
        } else {
            $upgrade_pack = $upgrade_pack[0];
            $app->uploadUpgradePack($upgrade_pack);
        }
        return array(CONTROLLER_STATUS_REDIRECT, 'upgrade_center.manage');
    }
    if ($mode == 'install') {
        if (!empty($_REQUEST['change_ftp_settings'])) {
            Log::instance($_REQUEST['id'])->add('Update FTP connection settings');
            foreach ($_REQUEST['change_ftp_settings'] as $setting_name => $value) {
                Settings::instance()->updateValue($setting_name, $value, '', true);
                Registry::set('settings.Upgrade_center.' . $setting_name, $value);
            }
Esempio n. 22
0
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    fn_trusted_vars("lang_data");
    $suffix = '';
    if ($mode == 'update_design_mode') {
        db_query("UPDATE ?:settings SET value = ?s WHERE option_name = ?s AND section_id = ?s", $action == $_REQUEST['design_mode'] ? 'Y' : 'N', $_REQUEST['design_mode'], '');
        if (!empty($_REQUEST['disable_mode'])) {
            db_query("UPDATE ?:settings SET value = 'N' WHERE option_name = ?s AND section_id = ?s", $_REQUEST['disable_mode'], '');
        }
        fn_rm(DIR_COMPILED . 'customer', false);
        fn_rm(DIR_COMPILED . 'admin', false);
        $suffix = '.design_mode';
    }
    if ($mode == 'update_logos') {
        $logos = fn_filter_uploaded_data('logotypes');
        $areas = fn_get_manifest_definition();
        fn_save_logo_alt($areas);
        // Update customer logotype
        if (!empty($logos)) {
            foreach ($logos as $type => $logo) {
                $area = $areas[$type];
                $manifest = parse_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, true);
                $filename = DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . $area['path'] . '/images/' . $logo['name'];
                if (fn_copy($logo['path'], $filename)) {
                    list($w, $h, ) = fn_get_image_size($filename);
                    $manifest[$area['name']]['filename'] = $logo['name'];
                    $manifest[$area['name']]['width'] = $w;
                    $manifest[$area['name']]['height'] = $h;
                    fn_write_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, $manifest);
                } else {
Esempio n. 23
0
function fn_attach_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, $object_ids = array())
{
    $icons = fn_filter_uploaded_data($name . '_image_icon', array('png', 'gif', 'jpg', 'jpeg', 'ico'));
    $detailed = fn_filter_uploaded_data($name . '_image_detailed', array('png', 'gif', 'jpg', 'jpeg', 'ico'));
    $pairs_data = !empty($_REQUEST[$name . '_image_data']) ? $_REQUEST[$name . '_image_data'] : array();
    return fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, $object_ids, true, $lang_code);
}
Esempio n. 24
0
function fn_attach_aditional_image_pairs($name, $object_type, $object_id = 0, $lang_code = CART_LANGUAGE, $object_ids = array())
{
    foreach ($object_ids as $object_id1) {
        $icons = fn_filter_uploaded_data($name . '_image_icon' . $object_id1, array('png', 'gif', 'jpg', 'jpeg', 'ico'));
        $detailed = fn_filter_uploaded_data($name . '_image_detailed' . $object_id1, array('png', 'gif', 'jpg', 'jpeg', 'ico'));
        $pairs_data = !empty($_REQUEST[$name . '_image_data' . $object_id1]) ? $_REQUEST[$name . '_image_data' . $object_id1] : array();
        fn_update_image_pairs($icons, $detailed, $pairs_data, $object_id, $object_type, array(), true, $lang_code, "A");
    }
}