Exemple #1
0
 function show()
 {
     no_graphics(true);
     header('X-Robots-Tag: noindex,nofollow,noarchive,nosnippet');
     header(($_SERVER['SERVER_PROTOCOL'] ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' 404 Not Found');
     echo 'Page not found';
     exit;
 }
Exemple #2
0
 /**
  * Output sample placeholder image, useful for designing wireframes and prototypes
  */
 function placeholder()
 {
     no_graphics(true);
     list($id, $ext) = explode('.', $_GET['id']);
     list($w, $h) = explode('x', $id);
     $w = (int) $w ?: 100;
     $h = (int) $h ?: 100;
     $params['color_bg'] = $_GET['page'] ? preg_replace('[^a-z0-9]', '', $_GET['page']) : '';
     require_once YF_PATH . 'share/functions/yf_placeholder_img.php';
     echo yf_placeholder_img($w, $h, $params);
     exit;
 }
Exemple #3
0
 /**
  * Execute selected php func
  */
 function php_func()
 {
     no_graphics(true);
     if (!main()->CONSOLE_MODE) {
         exit('No direct access to method allowed');
     }
     $params = common()->get_console_params();
     $func = preg_replace('#[^a-z0-9\\_]+#', '', substr(trim($params['func']), 0, 32));
     if (function_exists($func)) {
         echo $func($params['name']);
     } else {
         echo 'Error: no such func: ' . $func;
     }
     exit;
 }
Exemple #4
0
 /**
  */
 function active()
 {
     if (!empty($_GET['id'])) {
         $user_info = user($_GET['id']);
     }
     if (!empty($user_info)) {
         db()->update(self::table, ['active' => (int) (!$user_info['active'])], $user_info['id']);
     }
     cache_del(self::table);
     if (is_ajax()) {
         no_graphics(true);
         echo $user_info['active'] ? 0 : 1;
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #5
0
 /**
  * Display dynamic|on-the-fly asset content (CSS|JS)
  */
 function asset($type = '')
 {
     session_write_close();
     no_graphics(true);
     $name = strtolower(preg_replace('~[^a-z0-9_-]+~ims', '', trim($_GET['id'])));
     $type = strtolower(preg_replace('~[^a-z0-9_-]+~ims', '', trim($type ?: $_GET['page'])));
     if (!strlen($name) || !strlen($type) || !in_array($type, ['css', 'js', 'jquery', 'ng'])) {
         _404();
         exit;
     }
     $class_assets = _class('assets');
     $content_types = ['js' => 'text/javascript', 'css' => 'text/css'];
     $content_types['jquery'] = $content_types['js'];
     $content_types['ng'] = $content_types['js'];
     if (in_array($type, ['css', 'js'])) {
         $content = $class_assets->get_asset($name, $type);
         foreach ($content as $v) {
             $ctype = $class_assets->detect_content_type($type, $v);
             $_out = '';
             if ($ctype === 'inline') {
                 $_out = $v;
             } elseif ($ctype === 'file') {
                 $_out = file_get_contents($v);
             } elseif ($ctype === 'url') {
                 $_out = file_get_contents($v);
             }
             if (DEBUG_MODE) {
                 $out[] = '/* DEBUG: asset: ' . $name . ', type: ' . $type . ', ctype: ' . $ctype . ', length: ' . strlen($_out) . ', src: ' . $v . ' */';
             }
             $out[] = $_out;
         }
     }
     $out = implode(PHP_EOL . PHP_EOL, $out);
     $now = time();
     $max_age = 3600;
     header('Content-Type: ' . $content_types[$type]);
     header('Content-Length: ' . strlen($out));
     header('Cache-Control: max-age=3600, must-revalidate');
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $now + $max_age));
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $now));
     header('X-Robots-Tag: noindex,nofollow,noarchive,nosnippet');
     header_remove('Pragma');
     header_remove('Set-Cookie');
     print $out;
     exit;
 }
Exemple #6
0
 /**
  */
 function active()
 {
     $id = intval($_GET['id']);
     if (!empty($id)) {
         $a = db()->from('admin')->whereid($id)->get();
     }
     if (!empty($a['id']) && $id != 1 && $id != main()->ADMIN_ID) {
         db()->update_safe('admin', ['active' => (int) (!$a['active'])], $id);
         common()->admin_wall_add(['admin account ' . ($a['active'] ? 'inactivated' : 'activated'), $id]);
     }
     if (is_ajax()) {
         no_graphics(true);
         echo (int) (!$a['active']);
     } else {
         return js_redirect(url('/@object'));
     }
 }
 /**
  */
 function active()
 {
     $_GET['id'] = intval($_GET['id']);
     if (!empty($_GET['id'])) {
         $ds_info = db()->get('SELECT * FROM ' . db('dashboards') . ' WHERE id=' . intval($_GET['id']));
     }
     if (!empty($ds_info['id'])) {
         db()->update('dashboards', ['active' => (int) (!$ds_info['active'])], 'id=' . intval($_GET['id']));
         common()->admin_wall_add(['dashboard ' . $ds_info['name'] . ' ' . ($ds_info['active'] ? 'inactivated' : 'activated'), $_GET['id']]);
     }
     if (is_ajax()) {
         no_graphics(true);
         echo $ds_info['active'] ? 0 : 1;
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #8
0
 /**
  */
 function active()
 {
     $_GET['id'] = intval($_GET['id']);
     if (!empty($_GET['id'])) {
         $group_info = db()->query_fetch('SELECT * FROM ' . db('user_groups') . ' WHERE id=' . intval($_GET['id']));
     }
     if (!empty($group_info)) {
         db()->UPDATE('user_groups', ['active' => intval(!$group_info['active'])], 'id=' . intval($_GET['id']));
         common()->admin_wall_add(['user group: ' . $group_info['name'] . ' ' . ($group_info['active'] ? 'inactivated' : 'activated'), $group_info['id']]);
     }
     cache_del(['user_groups', 'user_groups_details']);
     if (is_ajax()) {
         no_graphics(true);
         echo $group_info['active'] ? 0 : 1;
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #9
0
 /**
  */
 function preview($extra = [])
 {
     conf('ROBOTS_NO_INDEX', true);
     no_graphics(true);
     if (main()->USER_ID != 1) {
         return print _403('You should be logged as user 1');
     }
     // Example of url: /dynamic/preview/static_pages/29/
     $object = preg_replace('~[^a-z0-9_]+~ims', '', $_GET['id']);
     $id = preg_replace('~[^a-z0-9_]+~ims', '', $_GET['page']);
     if (!strlen($object)) {
         return print _403('Object is required');
     }
     $ref = $_SERVER['HTTP_REFERER'];
     $body = '';
     if (is_post() && isset($_POST['text'])) {
         $u_ref = parse_url($ref);
         $u_self = parse_url(WEB_PATH);
         $u_adm = parse_url(ADMIN_WEB_PATH);
         if ($u_ref['host'] && $u_ref['host'] == $u_self['host'] && $u_ref['host'] == $u_adm['host'] && $u_ref['path'] == $u_adm['path']) {
             $body = $_POST['text'];
         } else {
             return print _403('Preview security check not passed');
         }
     }
     if (!$body) {
         $q = from($object)->whereid($id);
         if ($object == 'static_pages') {
             $body = $q->one('text');
         } elseif ($object == 'tips') {
             $body = $q->one('text');
         } elseif ($object == 'faq') {
             $body = $q->one('text');
         } elseif ($object == 'news') {
             $body = $q->one('full_text');
         }
     }
     $body = '<div class="container">' . $body . '</div>';
     return print common()->show_empty_page($body);
 }
Exemple #10
0
 /**
  * find users over nick or email
  */
 function find_ids()
 {
     no_graphics(true);
     if (!$_POST || !main()->USER_ID || IS_ADMIN != 1) {
         echo '';
         exit;
     }
     // Continue execution
     if ($_POST['search_table'] == 'user') {
         // Find account ids of this user
         $Q = db()->query("SELECT a.id\n\t\t\t\t\t\t, a.account_name\n\t\t\t\t\t\t, a.user_id\n\t\t\t\t\t\t, u.nick\n\t\t\t\t\t\t, u.id AS 'uid' \n\t\t\t\tFROM " . db('host_accounts') . " AS a, " . db('user') . " AS u \n\t\t\t\tWHERE a.user_id=u.id \n\t\t\t\t\tAND u.id IN( \n\t\t\t\t\t\tSELECT id \n\t\t\t\t\t\tFROM " . db('user') . " \n\t\t\t\t\t\tWHERE " . _es($_POST["search_field"]) . " LIKE '" . _es($_POST["param"]) . "%'\n\t\t\t\t\t) \n\t\t\t\tLIMIT " . intval($this->_parent->USER_RESULTS_LIMIT));
         while ($A = db()->fetch_assoc($Q)) {
             $finded_ids[$A['nick']][$A['id']] = $A['account_name'];
         }
     } elseif ($_POST['search_table'] == 'host_accounts') {
         $Q = db()->query("SELECT a.id\n\t\t\t\t\t\t, a.account_name\n\t\t\t\t\t\t, a.user_id\n\t\t\t\t\t\t, u.nick\n\t\t\t\t\t\t, u.id AS 'uid' \n\t\t\t\tFROM " . db('host_accounts') . " AS a\n\t\t\t\t\t, " . db('user') . " AS u \n\t\t\t\tWHERE a." . _es($_POST['search_field']) . " LIKE '" . _es($_POST['param']) . "%' \n\t\t\t\t\tAND a.user_id=u.id \n\t\t\t\tLIMIT " . intval($this->_parent->USER_RESULTS_LIMIT));
         while ($A = db()->fetch_assoc($Q)) {
             $finded_ids[$A['nick']][$A['id']] = $A['account_name'];
         }
     }
     echo $finded_ids ? json_encode($finded_ids) : '*';
 }
Exemple #11
0
 /**
  * AJAX-based method edit selected tooltip
  */
 function edit_tip()
 {
     no_graphics(true);
     if (!DEBUG_MODE || !tpl()->ALLOW_INLINE_DEBUG) {
         return print 'Access denied';
     }
     $CUR_LOCALE = conf('language');
     if (isset($_POST['text']) && isset($_POST['name'])) {
         $A = db()->query_fetch('SELECT * FROM ' . db('tips') . " WHERE name='" . $_POST["name"] . "' AND locale='" . $CUR_LOCALE . "'");
         if (!$A) {
             db()->INSERT('tips', ['name' => _es($_POST['name']), 'locale' => _es($CUR_LOCALE), 'text' => _es($_POST['text']), 'type' => 1, 'active' => 1]);
         } else {
             db()->UPDATE('tips', ['text' => _es($_POST['text'])], "name='" . $_POST["name"] . "' AND locale='" . $CUR_LOCALE . "'");
         }
     }
     cache_del('tips');
     echo 'Saved successfully';
 }
Exemple #12
0
 /**
  * Initialization of the main content
  * Throws one 'echo' at the end
  */
 function init_graphics()
 {
     $init_type = MAIN_TYPE;
     // Do not remove this!
     $this->_init_global_tags();
     // Default user group
     if ($init_type == 'user' && empty($_SESSION['user_group'])) {
         $_SESSION['user_group'] = 1;
     }
     if (main()->OUTPUT_CACHING && $init_type == 'user' && $_SERVER['REQUEST_METHOD'] == 'GET') {
         _class('output_cache')->_process_output_cache();
     }
     if (!main()->no_graphics()) {
         if ($this->OB_CATCH_CONTENT) {
             ob_start();
         }
         // Trying to get default task
         if ($init_type == 'user' && !empty($_SESSION['user_id']) && !empty($_SESSION['user_group'])) {
             $go = conf('default_page_user');
         } elseif ($init_type == 'admin') {
             $go = conf('default_page_admin');
         }
         // If setting exists - assign it to the location
         if (!empty($go) && empty($_GET['object'])) {
             $go = str_replace(['./?', './'], '', $go);
             $tmp_array = [];
             parse_str($go, $tmp_array);
             foreach ((array) $tmp_array as $k => $v) {
                 $_GET[$k] = $v;
             }
         }
         $skip_prefetch = false;
         // Determine what template need to be loaded in the center area
         $tpl_name = 'main';
         if ($init_type == 'admin' && (empty($_SESSION['admin_id']) || empty($_SESSION['admin_group']))) {
             $tpl_name = 'login';
             if (main()->is_ajax()) {
                 no_graphics(true);
                 main()->IS_403 = true;
                 header(($_SERVER['SERVER_PROTOCOL'] ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' 403 Forbidden');
                 $skip_prefetch = true;
             }
             if (!main()->is_console()) {
                 $skip_prefetch = true;
             }
         }
         if ($this->GET_STPLS_FROM_DB && $this->FROM_DB_GET_ALL) {
             $Q = db()->query('SELECT name,text FROM ' . db('templates') . ' WHERE theme_name="' . conf('theme') . '" AND active="1"');
             while ($A = db()->fetch_assoc($Q)) {
                 $this->_TMP_FROM_DB[$A['name']] = stripslashes($A['text']);
             }
         }
         if (!$skip_prefetch) {
             if (main()->is_console()) {
                 // Skip security checks for console mode
                 _class('core_blocks')->tasks(false);
             } else {
                 _class('core_blocks')->prefetch_center();
             }
         }
     }
     if (!main()->no_graphics()) {
         $body['content'] = $this->_init_main_stpl($tpl_name);
         $this->_CENTER_RESULT = '';
         if ($this->CUSTOM_META_INFO && $init_type == 'user') {
             $this->register_output_filter([$this, '_custom_replace_callback'], 'custom_replace');
         }
         if ($init_type == 'user' && _class('graphics')->IFRAME_CENTER && false === strpos($_SERVER['QUERY_STRING'], 'center_area=1')) {
             $this->register_output_filter([$this, '_replace_for_iframe_callback'], 'replace_for_iframe');
         }
     }
     if (!main()->no_graphics()) {
         // Replace images paths with their absolute ones
         if ($this->REWRITE_MODE && $init_type != 'admin') {
             $this->register_output_filter([$this, '_rewrite_links_callback'], 'rewrite_links');
         }
         if ($this->TIDY_OUTPUT && $init_type != 'admin') {
             $this->register_output_filter([$this, '_tidy_cleanup_callback'], 'tidy_cleanup');
         }
         $body['content'] = $this->_apply_output_filters($body['content']);
         if (main()->OUTPUT_CACHING && $init_type == 'user' && $_SERVER['REQUEST_METHOD'] == 'GET') {
             _class('output_cache')->_put_page_to_output_cache($body);
         }
         if (!main()->is_console() && !main()->is_ajax()) {
             if (DEBUG_MODE) {
                 $body['debug_info'] = common()->show_debug_info();
             }
             $_last_pos = strpos($body['content'], '</body>');
             if ($_last_pos) {
                 $body['content'] = substr($body['content'], 0, $_last_pos) . $body['debug_info'] . '</body></html>';
                 $body['debug_info'] = '';
             }
             if ($this->ADD_QUICK_PAGE_INFO) {
                 $body['exec_time'] = $this->_get_quick_page_info();
             }
         }
         $output = implode('', $body);
         $this->_output_body_length = strlen($output);
         main()->_send_main_headers($this->_output_body_length);
         // Throw generated output to user
         echo $output;
     }
     if (DEBUG_MODE && main()->no_graphics() && !main()->is_console() && !main()->is_ajax()) {
         echo common()->show_debug_info();
     }
     // Output cache for 'no graphics' content
     if (main()->no_graphics() && main()->OUTPUT_CACHING && $init_type == 'user' && $_SERVER['REQUEST_METHOD'] == 'GET') {
         _class('output_cache')->_put_page_to_output_cache(ob_get_clean());
     }
     if (main()->LOG_EXEC || $this->LOG_EXEC_INFO) {
         _class('logs')->log_exec();
     }
     // End sending main output
     ob_end_flush();
     if ($this->EXIT_AFTER_ECHO) {
         exit;
     }
 }
Exemple #13
0
 /**
  */
 function activate_rule()
 {
     $_GET['id'] = intval($_GET['id']);
     if (!empty($_GET['id'])) {
         $rule_info = db()->query_fetch('SELECT * FROM ' . db('block_rules') . ' WHERE id=' . intval($_GET['id']));
     }
     if (!empty($rule_info['id'])) {
         $block_info = db()->query_fetch('SELECT * FROM ' . db('blocks') . ' WHERE id=' . intval($rule_info['block_id']));
     }
     if (!empty($block_info['id'])) {
         db()->UPDATE('block_rules', ['active' => (int) (!$rule_info['active'])], 'id=' . intval($_GET['id']));
         common()->admin_wall_add(['block rule for ' . $block_info['name'] . ' ' . ($rule_info['active'] ? 'inactivated' : 'activated'), $_GET['id']]);
         module('blocks')->_cache_purge();
     }
     if (is_ajax()) {
         no_graphics(true);
         echo $rule_info['active'] ? 0 : 1;
     } else {
         return js_redirect('./?object=' . $_GET['object'] . '&action=show_rules&id=' . $block_info['id']);
     }
 }
Exemple #14
0
 /**
  */
 function active()
 {
     $id = (int) $_GET['id'];
     if ($a = $this->_get_info()) {
         $n = $a;
         $n['active'] = (int) (!$a['active']);
         module_safe('manage_revisions')->add(['object_name' => self::table, 'object_id' => $a['id'], 'old' => $a, 'new' => $n, 'action' => 'active']);
         db()->update_safe(self::table, ['active' => (int) (!$a['active'])], 'id=' . intval($a['id']));
         common()->admin_wall_add(['Email template: ' . $a['name'] . ' ' . ($a['active'] ? 'inactivated' : 'activated'), $a['id']]);
     }
     if (is_ajax()) {
         no_graphics(true);
         return print intval(!$a['active']);
     }
     return js_redirect(url('/@object'));
 }
Exemple #15
0
 function database_show_ajax()
 {
     no_graphics(true);
     $db_name = $this->_database_name($_GET['id']);
     if (!$db_name) {
         return false;
     }
     $db = $this->_db_custom_connection($db_name);
     $data = ['indexes' => (array) $db->utils()->list_all_indexes($db_name), 'foreign_keys' => (array) $db->utils()->list_all_foreign_keys($db_name), 'triggers' => (array) $db->utils()->list_all_triggers($db_name)];
     foreach ((array) $data as $k => $v) {
         foreach ((array) $v as $table => $info) {
             $data[$k][$table] = count($info);
         }
         if (empty($data[$k])) {
             unset($data[$k]);
         }
     }
     header('Content-type: text/json', $replace = true);
     print json_encode($data);
     exit;
 }
Exemple #16
0
 /**
  */
 function active()
 {
     $a = $this->_get_info();
     if (!empty($a['id'])) {
         $n = $a;
         $n['active'] = (int) (!$a['active']);
         module_safe('manage_revisions')->add(['object_name' => self::table, 'object_id' => $a['id'], 'old' => $a, 'new' => $n, 'action' => 'active']);
         db()->update(self::table, ['active' => (int) (!$a['active'])], (int) $a['id']);
         common()->admin_wall_add(['static page: ' . $a['name'] . ' ' . ($a['active'] ? 'inactivated' : 'activated'), $a['id']]);
         cache_del('static_pages_names');
     }
     if (is_ajax()) {
         no_graphics(true);
         echo intval(!$a['active']);
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #17
0
 /**
  */
 function active()
 {
     if (!empty($_GET['id'])) {
         $module_info = db()->query_fetch('SELECT * FROM ' . db('admin_modules') . ' WHERE name="' . _es($_GET['id']) . '" LIMIT 1');
     }
     if (!empty($module_info)) {
         db()->UPDATE('admin_modules', ['active' => (int) (!$module_info['active'])], 'id=' . intval($module_info['id']));
     }
     cache_del('admin_modules');
     if (is_ajax()) {
         no_graphics(true);
         echo $module_info['active'] ? 0 : 1;
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #18
0
 /**
  * Show error and set response header to "403 Forbidden"
  */
 function error_403($msg = '')
 {
     if (MAIN_TYPE_ADMIN && is_logged_in() || DEBUG_MODE) {
         // Do not override status header for logged in admin, just display error inlined
         !$msg && ($msg = t('403 Forbidden'));
     } else {
         // All other cases
         header(($_SERVER['SERVER_PROTOCOL'] ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' 403 Forbidden');
         main()->IS_403 = true;
     }
     if (DEBUG_MODE) {
         no_graphics(true);
         $body .= '<b>404 Not found</b><br />' . PHP_EOL . '<i>' . $msg . '</i>';
         $body .= '<pre><small>' . htmlspecialchars(main()->trace_string()) . '</small></pre>';
         return print common()->show_empty_page($body, ['full_width' => 1]);
     }
     return $this->_show_error_message($msg);
 }
Exemple #19
0
 /**
  * Export backup
  */
 function export_backup()
 {
     $fname = urldecode($_GET['id']);
     $fpath = INCLUDE_PATH . $this->BACKUP_PATH . $fname;
     if (file_exists($fpath)) {
         $body = file_get_contents($fpath);
         no_graphics(true);
         // Throw headers
         header('Content-Type: application/force-download; name=\'' . $fname . '\'');
         header('Content-Transfer-Encoding: binary');
         header('Content-Length: ' . strlen($body));
         header('Content-Disposition: attachment; filename=\'' . $fname . '\'');
         // Throw content
         echo $body;
     }
     exit;
 }
Exemple #20
0
 /**
  * Collect vars from source files, no framework, just project and given module name (internal use only method)
  */
 function collect_vars_for_module()
 {
     // TODO: move out into submodule
     no_graphics(true);
     $module_name = preg_replace('/[^a-z0-9\\_]/i', '', strtolower(trim($_GET['id'])));
     if (!$module_name) {
         return print 'Error, no module name';
     }
     $vars = $this->_parse_source_code_for_vars(['only_project' => 1, 'only_module' => $module_name]);
     echo '<pre>';
     foreach ((array) $vars as $var => $paths) {
         echo $var . PHP_EOL;
     }
     echo '</pre>';
 }
Exemple #21
0
 /**
  */
 function ajax_validate()
 {
     no_graphics(true);
     header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet');
     $allowed_params = $this->_parent->AJAX_VALIDATE_ALLOWED;
     $rules = [];
     $errors = [];
     if (isset($_POST['rules']) && is_array($_POST['rules'])) {
         $rules = $_POST['rules'];
     } elseif (isset($_GET['rules']) && is_array($_GET['rules'])) {
         $rules = $_GET['rules'];
     } else {
         $rules[] = ['func' => preg_replace('~[^a-z0-9_]+~ims', '', isset($_POST['func']) ? $_POST['func'] : (isset($_GET['func']) ? $_GET['func'] : $_GET['id'])), 'data' => isset($_POST['data']) ? $_POST['data'] : $_GET['data'], 'param' => isset($_POST['param']) ? $_POST['param'] : $_GET['param'], 'field' => isset($_POST['field']) ? $_POST['field'] : $_GET['field']];
     }
     $class_validate = _class('validate');
     $is_valid = false;
     foreach ((array) $rules as $rule) {
         if (is_null($rule['data'])) {
             $errors[] = 'empty data';
         }
         if (strlen($rule['param'])) {
             $not_allowed_param = true;
             if (in_array($rule['param'], $allowed_params)) {
                 $not_allowed_param = false;
             } else {
                 foreach ((array) $allowed_params as $aparam) {
                     // is_unique_without[user.login.1]
                     if ($rule['param'] && strpos($rule['param'], $aparam . '.') === 0) {
                         $not_allowed_param = false;
                         break;
                     }
                 }
             }
             if ($not_allowed_param) {
                 $errors[] = 'not allowed param';
             }
         }
         if (!preg_match('~^[a-z][a-z0-9_]+$~ims', $rule['func'])) {
             $errors[] = 'wrong func name';
         } elseif (!method_exists($class_validate, $rule['func'])) {
             $errors[] = 'no such func';
         }
         if ($errors) {
             break;
         }
         if ($rule['param'] == 'user.email') {
             $email_valid = $class_validate->valid_email($rule['data'], [], [], $error_msg);
             if (!$email_valid) {
                 break;
             }
         }
         $fname = (string) $rule['func'];
         $is_valid = $class_validate->{$fname}($rule['data'], ['param' => $rule['param']], [], $error_msg);
         if (!$is_valid) {
             if (!$error_msg) {
                 $error_msg = t('form_validate_' . $rule['func'], ['%field' => $rule['field'], '%param' => $rule['param']]);
             }
             break;
         }
     }
     if ($errors) {
         $out = ['error' => $errors];
     } else {
         if ($is_valid) {
             $out = ['ok' => 1];
         } else {
             $out = ['ko' => 1];
         }
     }
     if ($error_msg) {
         $out['error_msg'] = $error_msg;
     }
     $is_ajax = conf('IS_AJAX');
     if ($is_ajax) {
         header('Content-type: application/json');
     }
     print json_encode($out);
     if ($is_ajax) {
         exit;
     }
 }
Exemple #22
0
 /**
  */
 function active()
 {
     $id = (int) $_GET['id'];
     if ($id) {
         $a = from(self::table)->whereid($id)->get();
     }
     if ($a) {
         $n = $a;
         $n['active'] = (int) (!$a['active']);
         module_safe('manage_revisions')->add(['object_name' => self::table, 'object_id' => $a['id'], 'old' => $a, 'new' => $n, 'action' => 'active']);
         db()->update_safe(self::table, ['active' => (int) (!$a['active'])], $id);
     }
     if (is_ajax()) {
         no_graphics(true);
         echo (int) (!$a['active']);
     } else {
         return js_redirect(url('/@object'));
     }
 }
Exemple #23
0
 /**
  */
 function delete_item()
 {
     $_GET['id'] = intval($_GET['id']);
     if (!empty($_GET['id'])) {
         $item_info = db()->query_fetch('SELECT * FROM ' . db('menu_items') . ' WHERE id=' . intval($_GET['id']));
     }
     if (!empty($item_info)) {
         db()->query('DELETE FROM ' . db('menu_items') . ' WHERE id=' . intval($_GET['id']));
         db()->update('menu_items', ['parent_id' => 0], 'parent_id=' . intval($_GET['id']));
         common()->admin_wall_add(['menu item deleted: ' . $item_info['name'] . '', $item_info['id']]);
     }
     module('menus_editor')->_purge_caches();
     if (is_ajax()) {
         no_graphics(true);
         echo $_GET['id'];
     } else {
         return js_redirect('./?object=' . $_GET['object'] . '&action=show_items&id=' . $item_info['menu_id']);
     }
 }
Exemple #24
0
 /**
  */
 function delete_item()
 {
     $id = (int) $_GET['id'];
     $_GET['id'] = $id;
     $object = $_GET['object'];
     $action = $_GET['action'];
     if ($id < 1) {
         return js_redirect(url('/' . $object), 'item id < 1');
     }
     $db_item = db('category_items');
     $item_info = db()->query_fetch('SELECT * FROM ' . $db_item . ' WHERE id = ' . $id);
     if (!empty($item_info)) {
         $db = db('categories');
         $cats_id = $item_info['cat_id'];
         $cat_info = db()->query_fetch('SELECT * FROM ' . $db . ' WHERE id = ' . (int) $cats_id);
         _class('core_events')->fire('category_editor.delete_item.before', [$id, $cats_id]);
         db()->query('DELETE FROM ' . db('category_items') . ' WHERE id=' . intval($_GET['id']));
         common()->admin_wall_add(['category item deleted: ' . $item_info['id'], $_GET['id']]);
         $this->_purge_category_caches($cat_info);
         _class('core_events')->fire('category_editor.delete_item.after', [$id, $cats_id]);
     }
     if (is_ajax()) {
         no_graphics(true);
         echo $_GET['id'];
     } else {
         return js_redirect(url('/@object/show_items/' . $item_info['cat_id']));
     }
 }
Exemple #25
0
 /**
  * https://cliff.ecommpay.com/download/%D0%98%D0%BD%D1%81%D1%82%D1%80%D1%83%D0%BA%D1%86%D0%B8%D1%8F%20%D0%BF%D0%BE%20%D0%B2%D1%8B%D0%BF%D0%BB%D0%B0%D1%82%D0%B0%D0%BC%20%D1%87%D0%B5%D1%80%D0%B5%D0%B7%20%D1%84%D0%B0%D0%B9%D0%BB.pdf
  */
 function csv()
 {
     // class
     $payment_api =& $this->payment_api;
     $provider_class = $payment_api->provider_class(['provider_name' => 'ecommpay']);
     // var
     $operation_id = intval($_GET['operation_id']);
     $info = db()->from('payment_operation')->where('operation_id', $operation_id)->get();
     if (!$info) {
         return _404();
     }
     $info['options'] = json_decode($info['options'], true);
     $options = $info['options']['request'][0]['options'];
     $opt_data = $info['options']['request'][0]['data'];
     $data = [];
     $data['payment_group_id'] = 1;
     // Bank cards
     $data['site_id'] = $provider_class->key();
     // EcommPay site id
     $data['external_id'] = $operation_id;
     $data['comment'] = 'Payments out request. Date: ' . date('Y-m-d_H-i-s') . ' OID: ' . $operation_id;
     $data['phone'] = preg_replace('~[^0-9]~ims', '', $options['sender_phone']);
     $data['customer_purse'] = $options['card'];
     #		$data['transaction_id'] = ''; // [обязательный, если customer_purse не используется; пустой, если используется customer_purse]
     // Номер транзакции в Клиентском интерфейсе, по которой ранее был осуществлен прием средств.
     // Обычно используется для выплат на банковские карты при отсутствии сертификата PCI DSS.
     // Валюта, в которой была указана сумма платежа. Если валюта запроса не соответствует валюте счета, с которого будет осуществлен платеж,
     // то система автоматически осуществит пересчет суммы по курсу ЦБ РФ.
     #		$data['amount']				= intval($opt_data['amount'] * 100);
     #		$data['currency']			= $opt_data['currency_id'];
     $data['amount'] = intval($options['amount'] * 100);
     $data['currency'] = 'USD';
     $data = [$data];
     $csv = $this->_array2csv($data);
     // Ecommpay wants ";" everywhere
     $csv = explode(PHP_EOL, $csv);
     $csv[0] = str_replace(',', ';', $csv[0]);
     $csv = trim(implode(PHP_EOL, $csv));
     no_graphics(true);
     if (DEBUG_MODE) {
         echo '<pre>';
         print_r($csv);
         print_r($opt);
         print_r($info);
         print_r($data);
     } else {
         header('Content-disposition: attachment; filename=Ecommpay_out_' . intval($operation_id) . '_' . date('Ymd_His') . '.csv');
         header('Content-type: text/csv');
         echo $csv;
     }
     exit;
 }