|
From: Jon O. <jon...@us...> - 2005-12-08 15:06:55
|
Update of /cvsroot/mxbb/mx_kb/kb/includes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4009/modules/mx_kb/kb/includes Added Files: functions.php functions_auth.php functions_cache.php functions_comment.php functions_field.php functions_kb.php functions_mx.php kb_constants.php kb_defs.php kb_pages.php Log Message: in progress commit for mx_kb --- NEW FILE: functions.php --- (This appears to be a binary file; contents omitted.) --- NEW FILE: kb_constants.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: kb_constants.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ if ( !MXBB_MODULE ) { $server_protocol = ($board_config['cookie_secure']) ? 'https://' : 'http://'; $server_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['server_name'])); $server_port = ($board_config['server_port'] <> 80) ? ':' . trim($board_config['server_port']) : ''; $script_name = preg_replace('#^\/?(.*?)\/?$#', '\1', trim($board_config['script_path'])); $script_name = ($script_name == '') ? $script_name : '/' . $script_name; define( 'PORTAL_URL', $server_protocol . $server_name . $server_port . $script_name . '/' ); define( 'PHPBB_URL', PORTAL_URL ); $reader_mode = false; $kb_config['news_operate_mode'] = false; $mx_table_prefix = $table_prefix; $is_block = false; } // ---------------------------------------------------------------------START // This file defines specific constants for the module // ------------------------------------------------------------------------- define( 'PAGE_KB', -501 ); define( 'KB_ARTICLES_TABLE', $mx_table_prefix . 'kb_articles' ); define( 'KB_CATEGORIES_TABLE', $mx_table_prefix . 'kb_categories' ); define( 'KB_CONFIG_TABLE', $mx_table_prefix . 'kb_config' ); define( 'KB_TYPES_TABLE', $mx_table_prefix . 'kb_types' ); define( 'KB_WORD_TABLE', $mx_table_prefix . 'kb_wordlist' ); define( 'KB_SEARCH_TABLE', $mx_table_prefix . 'kb_results' ); define( 'KB_MATCH_TABLE', $mx_table_prefix . 'kb_wordmatch' ); define( 'KB_VOTES_TABLE', $mx_table_prefix . 'kb_votes' ); define( 'KB_COMMENTS_TABLE', $mx_table_prefix . 'kb_comments' ); define( 'KB_CUSTOM_TABLE', $mx_table_prefix . 'kb_custom' ); define( 'KB_CUSTOM_DATA_TABLE', $mx_table_prefix . 'kb_customdata' ); // Field Types define( 'INPUT', 0 ); define( 'TEXTAREA', 1 ); define( 'RADIO', 2 ); define( 'SELECT', 3 ); define( 'SELECT_MULTIPLE', 4 ); define( 'CHECKBOX', 5 ); // ********************************************************************** // Read language definition // ********************************************************************** if ( !file_exists( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx ) ) { include( $module_root_path . 'language/lang_english/lang_main.' . $phpEx ); $link_language = 'lang_english'; } else { include( $module_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.' . $phpEx ); $link_language = 'lang_' . $board_config['default_lang']; } // ********************************************************************** // Read theme definition // ********************************************************************** if ( file_exists( $module_root_path . "templates/" . $theme['template_name'] . "/images" ) ) { // ---------- $current_template_images = $module_root_path . "templates/" . $theme['template_name'] . "/images" ; // ---------- } else { // ---------- $current_template_images = $module_root_path . "templates/" . "subSilver" . "/images" ; // ---------- } // ********************************************************************** // Read image language in theme definition // ********************************************************************** $link_language = file_exists( "$current_template_images/$link_language/kb.gif" ) ? $link_language : 'lang_english'; $images['icon_approve'] = "$current_template_images/icon_approve.gif"; $images['icon_unapprove'] = "$current_template_images/icon_unapprove.gif"; $images['kb_title'] = "$current_template_images/$link_language/kb.gif"; $images['kb_search'] = "$current_template_images/" . $link_language . "/icon_kb_search.gif"; $images['kb_stats'] = "$current_template_images/" . $link_language . "/icon_kb_stats.gif"; $images['kb_toplist'] = "$current_template_images/" . $link_language . "/icon_kb_toplist.gif"; $images['kb_upload'] = "$current_template_images/" . $link_language . "/icon_kb_post.gif"; $images['kb_rate'] = "$current_template_images/" . $link_language . "/icon_kb_rate.gif"; $images['kb_comment_post'] = "$current_template_images/" . $link_language . "/icon_kb_post_comment.gif"; if ( !MXBB_MODULE || MXBB_27x ) { $kb_module_version = "Knowledge Base MOD v. 2.0.x"; $kb_module_author = "Haplo/Jon"; $kb_module_orig_author = "wGEric"; } else { $mxbb_footer_addup[] = 'mxBB Knowledge Base Module'; } ?> --- NEW FILE: functions_cache.php --- (This appears to be a binary file; contents omitted.) --- NEW FILE: functions_mx.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: functions_mx.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ if ( !function_exists( mx_smilies_pass ) ) { function mx_smilies_pass($message) { global $board_config; $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; $message = smilies_pass($message); $board_config['smilies_path'] = $smilies_path; return $message; } } if ( !function_exists( mx_generate_smilies ) ) { function mx_generate_smilies($mode, $page_id) { global $board_config, $template, $phpEx; $smilies_path = $board_config['smilies_path']; $board_config['smilies_path'] = PHPBB_URL . $board_config['smilies_path']; generate_smilies($mode, $page_id); $board_config['smilies_path'] = $smilies_path; $template->assign_vars(array( 'U_MORE_SMILIES' => append_sid(PHPBB_URL . "posting.$phpEx?mode=smilies")) ); } } if ( !function_exists( mx_message_die ) ) { function mx_message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '') { global $db, $template, $board_config, $theme, $lang, $phpEx, $phpbb_root_path, $nav_links, $gen_simple_header, $images; global $userdata, $user_ip, $session_length; global $starttime; message_die($msg_code, $msg_text, $msg_title, $err_line, $err_file, $sql); } } if ( !function_exists( mx_is_group_member ) ) { // Validates if user belongs to group included in group_ids list // Also, adds all usergroups to userdata array function mx_is_group_member( $group_ids = '', $group_mod_mode = false ) { global $userdata, $db; if ( $group_ids == '' ) { return false; } $group_ids_array = explode(",", $group_ids); // Try to reuse usergroups result. if ( $group_mod_mode ) { $userdata_key = 'mx_usergroups_mod' . $userdata['user_id']; if ( empty( $userdata[$userdata_key] ) ) { // Check if user is group moderator.. $sql = "SELECT gr.group_id FROM " . GROUPS_TABLE . " gr, " . USER_GROUP_TABLE . " ugr WHERE gr.group_id = ugr.group_id AND gr.group_moderator = '" . $userdata['user_id'] . "' AND ugr.user_pending = '0' "; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); } $group_row = $db->sql_fetchrowset( $result ); $userdata[$userdata_key_mod] = $group_row; } } else { $userdata_key = 'mx_usergroups' . $userdata['user_id']; if ( empty( $userdata[$userdata_key] ) ) { // Check if user is member of the proper group.. $sql = "SELECT group_id FROM " . USER_GROUP_TABLE . " WHERE user_id='" . $userdata['user_id'] . "' AND user_pending = 0"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, "Could not query group rights information", '', '', '', '' ); } $group_row = $db->sql_fetchrowset( $result ); $userdata[$userdata_key] = $group_row; } } for ( $i = 0; $i < count( $userdata[$userdata_key] ); $i++ ) { if ( in_array( $userdata[$userdata_key][$i]['group_id'], $group_ids_array ) ) { $is_member = true; return $is_member; } } return false; } } if ( !function_exists( mx_add_search_words ) ) { // Add search words for blocks function mx_add_search_words($mode, $post_id, $post_text, $post_title = '', $mx_mode = 'mx') { global $db, $phpbb_root_path, $board_config, $lang; // $search_match_table = SEARCH_MATCH_TABLE; // $search_word_table = SEARCH_WORD_TABLE; switch ( $mx_mode ) { case 'mx': $search_match_table = MX_MATCH_TABLE; $search_word_table = MX_WORD_TABLE; $db_key = 'block_id'; break; case 'kb': $search_match_table = KB_MATCH_TABLE; $search_word_table = KB_WORD_TABLE; $db_key = 'article_id'; break; } $stopword_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_stopwords.txt"); $synonym_array = @file($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . "/search_synonyms.txt"); $search_raw_words = array(); $search_raw_words['text'] = split_words(clean_words('post', $post_text, $stopword_array, $synonym_array)); $search_raw_words['title'] = split_words(clean_words('post', $post_title, $stopword_array, $synonym_array)); @set_time_limit(0); $word = array(); $word_insert_sql = array(); while ( list($word_in, $search_matches) = @each($search_raw_words) ) { $word_insert_sql[$word_in] = ''; if ( !empty($search_matches) ) { for ($i = 0; $i < count($search_matches); $i++) { $search_matches[$i] = trim($search_matches[$i]); if( $search_matches[$i] != '' ) { $word[] = $search_matches[$i]; if ( !strstr($word_insert_sql[$word_in], "'" . $search_matches[$i] . "'") ) { $word_insert_sql[$word_in] .= ( $word_insert_sql[$word_in] != "" ) ? ", '" . $search_matches[$i] . "'" : "'" . $search_matches[$i] . "'"; } } } } } if ( count($word) ) { sort($word); $prev_word = ''; $word_text_sql = ''; $temp_word = array(); for($i = 0; $i < count($word); $i++) { if ( $word[$i] != $prev_word ) { $temp_word[] = $word[$i]; $word_text_sql .= ( ( $word_text_sql != '' ) ? ', ' : '' ) . "'" . $word[$i] . "'"; } $prev_word = $word[$i]; } $word = $temp_word; $check_words = array(); switch( SQL_LAYER ) { case 'postgresql': case 'msaccess': case 'mssql-odbc': case 'oracle': case 'db2': $sql = "SELECT word_id, word_text FROM " . $search_word_table . " WHERE word_text IN ($word_text_sql)"; if ( !($result = $db->sql_query($sql)) ) { mx_message_die(GENERAL_ERROR, 'Could not select words', '', __LINE__, __FILE__, $sql); } while ( $row = $db->sql_fetchrow($result) ) { $check_words[$row['word_text']] = $row['word_id']; } break; } $value_sql = ''; $match_word = array(); for ($i = 0; $i < count($word); $i++) { $new_match = true; if ( isset($check_words[$word[$i]]) ) { $new_match = false; } if ( $new_match ) { switch( SQL_LAYER ) { case 'mysql': case 'mysql4': $value_sql .= ( ( $value_sql != '' ) ? ', ' : '' ) . '(\'' . $word[$i] . '\', 0)'; break; case 'mssql': case 'mssql-odbc': $value_sql .= ( ( $value_sql != '' ) ? ' UNION ALL ' : '' ) . "SELECT '" . $word[$i] . "', 0"; break; default: $sql = "INSERT INTO " . $search_word_table . " (word_text, word_common) VALUES ('" . $word[$i] . "', 0)"; if( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql); } break; } } } if ( $value_sql != '' ) { switch ( SQL_LAYER ) { case 'mysql': case 'mysql4': $sql = "INSERT IGNORE INTO " . $search_word_table . " (word_text, word_common) VALUES $value_sql"; break; case 'mssql': case 'mssql-odbc': $sql = "INSERT INTO " . $search_word_table . " (word_text, word_common) $value_sql"; break; } if ( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Could not insert new word', '', __LINE__, __FILE__, $sql); } } } while( list($word_in, $match_sql) = @each($word_insert_sql) ) { $title_match = ( $word_in == 'title' ) ? 1 : 0; if ( $match_sql != '' ) { $sql = "INSERT INTO " . $search_match_table . " ($db_key, word_id, title_match) SELECT $post_id, word_id, $title_match FROM " . $search_word_table . " WHERE word_text IN ($match_sql)"; if ( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Could not insert new word matches', '', __LINE__, __FILE__, $sql); } } } if ($mode == 'single') { // remove_common('single', 4/10, $word); } return; } function mx_remove_search_post($post_id_sql, $mx_mode = 'mx') { global $db; // $search_match_table = SEARCH_MATCH_TABLE; // $search_word_table = SEARCH_WORD_TABLE; switch ( $mx_mode ) { case 'mx': $search_match_table = MX_MATCH_TABLE; $search_word_table = MX_WORD_TABLE; $db_key = 'block_id'; break; case 'kb': $search_match_table = KB_MATCH_TABLE; $search_word_table = KB_WORD_TABLE; $db_key = 'article_id'; break; } $words_removed = false; switch ( SQL_LAYER ) { case 'mysql': case 'mysql4': $sql = "SELECT word_id FROM " . $search_match_table . " WHERE $db_key IN ($post_id_sql) GROUP BY word_id"; if ( $result = $db->sql_query($sql) ) { $word_id_sql = ''; while ( $row = $db->sql_fetchrow($result) ) { $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id']; } $sql = "SELECT word_id FROM " . $search_match_table . " WHERE word_id IN ($word_id_sql) GROUP BY word_id HAVING COUNT(word_id) = 1"; if ( $result = $db->sql_query($sql) ) { $word_id_sql = ''; while ( $row = $db->sql_fetchrow($result) ) { $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id']; } if ( $word_id_sql != '' ) { $sql = "DELETE FROM " . $search_word_table . " WHERE word_id IN ($word_id_sql)"; if ( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Could not delete word list entry', '', __LINE__, __FILE__, $sql); } $words_removed = $db->sql_affectedrows(); } } } break; default: $sql = "DELETE FROM " . $search_word_table . " WHERE word_id IN ( SELECT word_id FROM " . $search_match_table . " WHERE word_id IN ( SELECT word_id FROM " . $search_match_table . " WHERE $db_key IN ($post_id_sql) GROUP BY word_id ) GROUP BY word_id HAVING COUNT(word_id) = 1 )"; if ( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Could not delete old words from word table', '', __LINE__, __FILE__, $sql); } $words_removed = $db->sql_affectedrows(); break; } $sql = "DELETE FROM " . $search_match_table . " WHERE $db_key IN ($post_id_sql)"; if ( !$db->sql_query($sql) ) { mx_message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql); } return $words_removed; } } if ( !function_exists(mx_do_install_upgrade) ) { // Generating output function mx_do_install_upgrade( $sql = '', $main_install = false ) { global $table_prefix, $mx_table_prefix, $userdata, $phpEx, $template, $lang, $db, $board_config, $HTTP_POST_VARS; $inst_error = false; $n = 0; $message = "<b>This is the result list of the SQL queries needed for the install/upgrade</b><br /><br />"; while ( $sql[$n] ) { if ( !$result = $db->sql_query( $sql[$n] ) ) { $message .= '<b><font color=#FF0000>[Error or Already added]</font></b> line: ' . ( $n + 1 ) . ' , ' . $sql[$n] . '<br />'; $inst_error = true; } else { $message .= '<b><font color=#0000fF>[Added/Updated]</font></b> line: ' . ( $n + 1 ) . ' , ' . $sql[$n] . '<br />'; } $n++; } $message .= '<br /> If you get some Errors, Already Added or Updated messages, relax, this is normal when updating modules'; if ( $main_install ) { if ( !$inst_error ) { $message .= '-> no db errors :-)<br /><br /><b>Portal installed successfully! </b><hr><br /><br />'; $message .= '1) Now, delete the /install and /contrib folders!!!<br /><br />'; $message .= '2) If you haven\'t already done a db backup, now is the time ;)<br /><br />'; $message .= '3) Then (after step 1), you HAVE to configure MX core and its modules from within the adminCP, simply \'upgrade\' MX portal Core and all modules in use!!!<br /><br />'; $message .= 'Click <a href=../admin/admin_mx_module.php>Here</a> to administer/upgrade the portal/modules. You will be promted for an admin username and pass. The upgrade process provide informative output...'; } else { $message .= '<br /><br /><b>Portal installed successfully (with some warnings)! </b><hr><br /><br />'; $message .= '1) Now, delete the /install and /contrib folders!!!<br /><br />'; $message .= '2) If you haven\'t already done a db backup, now is the time ;)<br /><br />'; $message .= '3) Now (after step 1), you HAVE to configure MX core and its modules from within the adminCP, simply \'upgrade\' MX portal Core and all modules in use!!!<br /><br />'; $message .= 'Click <a href=../admin/admin_mx_module.php>Here</a> to administer/upgrade the portal/modules. You will be promted for an admin username and pass. The upgrade process provide informative output...'; } } return $message; } } ?> --- NEW FILE: functions_comment.php --- (This appears to be a binary file; contents omitted.) --- NEW FILE: functions_auth.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: functions_auth.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ if ( !defined( 'IN_PORTAL' ) ) { die( 'Hacking attempt' ); } class mx_kb_auth { var $auth_user = array(); function auth( $type, $cat_id, $userdata, $f_access = '', $f_access_group = '' ) { global $db, $lang; switch ( $type ) { case AUTH_ALL: $a_sql = 'a.auth_view, a.auth_post, a.auth_rate, a.auth_comment, a.auth_edit, a.auth_delete, a.auth_approval, a.auth_approval_edit'; $a_sql_groups = 'a.auth_view_groups, a.auth_post_groups, a.auth_rate_groups, a.auth_comment_groups, a.auth_edit_groups, a.auth_delete_groups, a.auth_approval_groups, a.auth_approval_edit_groups'; $auth_fields = array( 'auth_view', 'auth_post', 'auth_rate', 'auth_comment', 'auth_edit', 'auth_delete', 'auth_approval', 'auth_approval_edit' ); $auth_fields_groups = array( 'auth_view_groups', 'auth_post_groups', 'auth_rate_groups', 'auth_comment_groups', 'auth_edit_groups', 'auth_delete_groups', 'auth_approval_groups', 'auth_approval_edit_groups' ); break; case AUTH_VIEW: $a_sql = 'a.auth_view'; $a_sql_groups = 'a.auth_view_groups'; $auth_fields = array( 'auth_view' ); $auth_fields_groups = array( 'auth_view_groups' ); break; case AUTH_POST: $a_sql = 'a.auth_post'; $a_sql_groups = 'a.auth_post_groups'; $auth_fields = array( 'auth_post' ); $auth_fields_groups = array( 'auth_post_groups' ); break; case AUTH_RATE: $a_sql = 'a.auth_rate'; $a_sql_groups = 'a.auth_rate_groups'; $auth_fields = array( 'auth_rate' ); $auth_fields_groups = array( 'auth_rate_groups' ); break; case AUTH_COMMENT: $a_sql = 'a.auth_comment'; $a_sql_groups = 'a.auth_comment_groups'; $auth_fields = array( 'auth_comment' ); $auth_fields_groups = array( 'auth_comment_groups' ); break; case AUTH_EDIT: $a_sql = 'a.auth_edit'; $a_sql_groups = 'a.auth_edit_groups'; $auth_fields = array( 'auth_edit' ); $auth_fields_groups = array( 'auth_edit_groups' ); break; case AUTH_DELETE: $a_sql = 'a.auth_delete'; $a_sql_groups = 'a.auth_delete_groups'; $auth_fields = array( 'auth_delete' ); $auth_fields_groups = array( 'auth_delete_groups' ); break; case AUTH_APPROVAL: $a_sql = 'a.auth_approval'; $a_sql_groups = 'a.auth_approval_groups'; $auth_fields = array( 'auth_approval' ); $auth_fields_groups = array( 'auth_approval_groups' ); break; case AUTH_APPROVAL_EDIT: $a_sql = 'a.auth_approval_edit'; $a_sql_groups = 'a.auth_approval_edit_groups'; $auth_fields = array( 'auth_approval_edit' ); $auth_fields_groups = array( 'auth_approval_edit_groups' ); break; default: break; } $is_admin = ( $userdata['user_level'] == ADMIN && $userdata['session_logged_in'] ) ? true : 0; // // If f_access has not been passed, or auth is needed to return an array of forums // then we need to pull the auth information on the given forum (or all forums) // if ( empty($f_access) ) { $forum_match_sql = ( $cat_id != AUTH_LIST_ALL ) ? "WHERE a.category_id = $cat_id" : ''; $sql = "SELECT a.category_id, $a_sql FROM " . KB_CATEGORIES_TABLE . " a $forum_match_sql"; if ( !($result = $db->sql_query($sql)) ) { mx_message_die(GENERAL_ERROR, 'Failed obtaining forum access control lists', '', __LINE__, __FILE__, $sql); } $sql_fetchrow = ( $cat_id != AUTH_LIST_ALL ) ? 'sql_fetchrow' : 'sql_fetchrowset'; if ( !($f_access = $db->$sql_fetchrow($result)) ) { $db->sql_freeresult($result); return array(); } $db->sql_freeresult($result); } // // If f_access_group has not been passed, or auth is needed to return an array of forums // then we need to pull the auth information on the given forum (or all forums) // if ( empty($f_access_group) ) { $forum_match_sql = ( $cat_id != AUTH_LIST_ALL ) ? "WHERE a.category_id = $cat_id" : ''; $sql = "SELECT a.category_id, $a_sql_groups, a.auth_moderator_groups FROM " . KB_CATEGORIES_TABLE . " a $forum_match_sql"; if ( !($result = $db->sql_query($sql)) ) { mx_message_die(GENERAL_ERROR, 'Failed obtaining forum access control lists', '', __LINE__, __FILE__, $sql); } $sql_fetchrow = ( $cat_id != AUTH_LIST_ALL ) ? 'sql_fetchrow' : 'sql_fetchrowset'; if ( !($f_access_group = $db->$sql_fetchrow($result)) ) { $db->sql_freeresult($result); return array(); } $db->sql_freeresult($result); } $auth_user = array(); for( $i = 0; $i < count( $auth_fields ); $i++ ) { $key = $auth_fields[$i]; $key_groups = $auth_fields_groups[$i]; // If the user is logged on and the module type is either ALL or REG then the user has access // If the type if ACL, MOD or ADMIN then we need to see if the user has specific permissions // to do whatever it is they want to do ... to do this we pull relevant information for the // user (and any groups they belong to) // Now we compare the users access level against the modules. We assume here that a moderator // and admin automatically have access to an ACL module, similarly we assume admins meet an // auth requirement of MOD if ( $cat_id != AUTH_LIST_ALL ) { $value = $f_access[$key]; $value_groups = $f_access_group[$key_groups]; switch ( $value ) { case AUTH_ALL: $this->auth_user[$key] = true; $this->auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: $this->auth_user[$key] = ( $userdata['session_logged_in'] ) ? true : 0; $this->auth_user[$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: $this->auth_user[$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; $this->auth_user[$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: // PRIVATE $this->auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $value_groups ) || $is_admin : 0; $this->auth_user[$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: $this->auth_user[$key] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $f_access_group['auth_moderator_groups'] ) || $is_admin : 0; $this->auth_user[$key . '_type'] = $lang['Auth_Moderators']; break; case AUTH_ADMIN: $this->auth_user[$key] = $is_admin; $this->auth_user[$key . '_type'] = $lang['Auth_Administrators']; break; default: $this->auth_user[$key] = 0; break; } } else { for($k = 0; $k < count($f_access); $k++) { $value = $f_access[$k][$key]; $value_groups = $f_access_group[$k][$key_groups]; $f_cat_id = $f_access[$k]['category_id']; switch ( $value ) { case AUTH_ALL: $this->auth_user[$f_cat_id][$key] = true; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_REG: $this->auth_user[$f_cat_id][$key] = ( $userdata['session_logged_in'] ) ? true : 0; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Registered_Users']; break; case AUTH_ANONYMOUS: $this->auth_user[$f_cat_id][$key] = ( ! $userdata['session_logged_in'] ) ? true : 0; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Anonymous_users']; break; case AUTH_ACL: // PRIVATE $this->auth_user[$f_cat_id][$key] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $value_groups ) || $is_admin : 0; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Users_granted_access']; break; case AUTH_MOD: $this->auth_user[$f_cat_id][$key] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $f_access_group[$k]['auth_moderator_groups'] ) || $is_admin : 0; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Moderators']; break; case AUTH_ADMIN: $this->auth_user[$f_cat_id][$key] = $is_admin; $this->auth_user[$f_cat_id][$key . '_type'] = $lang['Auth_Administrators']; break; default: $this->auth_user[$f_cat_id][$key] = 0; break; } } } } // // Is user a moderator? // if ( $cat_id != AUTH_LIST_ALL ) { $this->auth_user['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $f_access_group['auth_moderator_groups'] ) || $is_admin : 0; } else { for($k = 0; $k < count($f_access); $k++) { $f_cat_id = $f_access[$k]['category_id']; $this->auth_user[$f_cat_id]['auth_mod'] = ( $userdata['session_logged_in'] ) ? mx_is_group_member( $f_access_group[$k]['auth_moderator_groups'] ) || $is_admin : 0; } } return $this->auth_user; } // =================================================== // // =================================================== function ns_auth_cat( $cat_id ) { global $kb_type_select_data, $kb_config; if ( !MXBB_MODULE || MXBB_27x ) { return true; } $tmp_kb = $kb_type_select_data[$cat_id] == 1; return $tmp_kb; } } ?> --- NEW FILE: kb_defs.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: kb_defs.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ define( 'NEWS_CAT_TABLE', $mx_table_prefix . 'kb_categories' ); define( 'KB_ARTICLES_TABLE', $mx_table_prefix . 'kb_articles' ); define( 'KB_CATEGORIES_TABLE', $mx_table_prefix . 'kb_categories' ); define( 'KB_TYPES_TABLE', $mx_table_prefix . 'kb_types' ); $sql = "SELECT * FROM " . KB_TYPES_TABLE; if ( !( $type_result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, "Could not obtain types information", '', __LINE__, __FILE__, $sql ); } $item_types_array = array(); $item_types_id_array = array(); $item_types_name_array = array(); while ( $type = $db->sql_fetchrow( $type_result ) ) { $item_types_array[] = 'type_' . $type['id']; $item_types_id_array[] = $type['id']; $item_types_name_array[] = $type['type']; } $cat_extract_order = 'parent, cat_order'; $cool_array_category_id = 'category_id'; $cat_table_category_id = 'f.category_id'; $item_table_category_id = 't.article_category_id'; $item_table_item_id = 't.article_id'; $item_table_item_type = 't.article_type'; $item_table_item_time = 't.article_date'; $item_table_item_last_time = 'tt.topic_last_post_id'; $item_table_item_title = 't.article_title'; $item_id = 'article_id'; $item_type = 'article_type'; $item_cat_id = 'article_category_id'; $item_text = 'article_body'; $item_bbcode_uid = 'bbcode_uid'; $item_time = 'article_date'; $item_views = 'views'; $item_title = 'article_title'; $catt_id = 'category_id'; $catt_name = 'category_name'; $catt_desc = 'category_details'; $item_types_all = 'forum_news'; ?> --- NEW FILE: kb_pages.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: kb_pages.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ if ( MXBB_27x ) { $page_id = get_page_id( 'kb_article_reader.php', true ); if ( !$page_id ) { $page_id = get_page_id( 'kb.php', true ); } if ( !empty( $page_id ) ) { $kb_pages = $page_id; $kb_error = false; } else { $kb_error = true; } // Start initial var setup $cat_id = $article_id = ''; if ( isset( $HTTP_GET_VARS['cat'] ) || isset( $HTTP_POST_VARS['cat'] ) ) { $cat_id = ( isset( $HTTP_GET_VARS['cat'] ) ) ? intval( $HTTP_GET_VARS['cat'] ) : intval( $HTTP_POST_VARS['cat'] ); } else if ( isset( $HTTP_GET_VARS['k'] ) || isset( $HTTP_POST_VARS['k'] ) ) { $article_id = ( isset( $HTTP_GET_VARS['k'] ) ) ? intval( $HTTP_GET_VARS['k'] ) : intval( $HTTP_POST_VARS['k'] ); } } else { // Note: This piece of code snippet is somewhat ugly and needs cleaning up...still it works... // What it does? // Well if given a direct kb article link, it finds on what portal page the kb block is located. // Since we can have different kb blocks on different portal pages displaying different kb categories/articles, this check is needed ;) // Oh, do not blame markus for this code ;) if ( empty( $_SESSION['kb_setup'] ) ) { $news_setup = array(); $sql = "SELECT col.page_id, blk.block_id, sys.parameter_value, fnc.function_file FROM " . COLUMN_BLOCK_TABLE . " bct, " . COLUMN_TABLE . " col, " . BLOCK_TABLE . " blk, " . BLOCK_SYSTEM_PARAMETER_TABLE . " sys, " . FUNCTION_TABLE . " fnc, " . PARAMETER_TABLE . " par WHERE col.column_id = bct.column_id AND blk.function_id = fnc.function_id AND par.function_id = fnc.function_id AND blk.block_id = bct.block_id AND blk.block_id = sys.block_id AND par.parameter_name = 'kb_type_select' ORDER BY page_id, block_id"; if ( !$kb_result = $db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, "Could not query modules information", "", __LINE__, __FILE__, $sql ); } while ( $kb_rows = $db->sql_fetchrow( $kb_result ) ) { $page_id = $kb_rows['page_id']; $block_id = $kb_rows['block_id']; $kb_select_par = $kb_rows['parameter_value']; // Extract 'what posts to view info', the cool Array ;) $kb_type_select_data = ( !empty( $kb_select_par ) ) ? unserialize($kb_select_par) : array(); $kb_config['news_mode_operate'] = true; if ( is_array($kb_type_select_data) ) { $news_setup[$page_id] = $kb_type_select_data; $news_mode[$page_id] = $kb_rows['function_file']; } } $page_to_kb = array(); while ( list( $page_idd, $news_setup_roww ) = each( $news_setup ) ) { while ( list( $cat_idd, $news_forum_roww ) = each( $news_setup_roww ) ) { if ( $news_forum_roww['forum_news'] == 1 ) { $page_to_kb[$cat_idd] = ( empty( $page_to_kb[$cat_idd] ) || $news_mode[$page_idd] == 'kb_article_reader.php' ) ? $page_idd : $page_to_kb[$cat_idd]; } } } $_SESSION['kb_setup'] = $page_to_kb; } // Start initial var setup $cat_id = $article_id = $sql = ''; if ( isset( $HTTP_GET_VARS['cat'] ) || isset( $HTTP_POST_VARS['cat'] ) ) { $cat_id = ( isset( $HTTP_GET_VARS['cat'] ) ) ? intval( $HTTP_GET_VARS['cat'] ) : intval( $HTTP_POST_VARS['cat'] ); } else if ( isset( $HTTP_GET_VARS['k'] ) || isset( $HTTP_POST_VARS['k'] ) ) { $article_id = ( isset( $HTTP_GET_VARS['k'] ) ) ? intval( $HTTP_GET_VARS['k'] ) : intval( $HTTP_POST_VARS['k'] ); $sql = "SELECT article_category_id FROM " . KB_ARTICLES_TABLE . " WHERE article_id = $article_id"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, "no info - error", '', __LINE__, __FILE__, $sql ); } if ( !( $row = $db->sql_fetchrow( $result ) ) ) { //mx_message_die( GENERAL_MESSAGE, 'article_not_exist' ); } $cat_id = $row['article_category_id']; } if ( !empty($cat_id) ) { $kb_pages = $_SESSION['kb_setup'][$cat_id]; $kb_error = false; } else { $kb_error = true; } } ?> --- NEW FILE: functions_kb.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: functions_kb.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ [...1227 lines suppressed...] if ( !( $opt &2 ) ) { // Not translating double quotes // Remove double quote from translation table unset( $trans_tbl["""] ); } return strtr ( $string, $trans_tbl ); } } // // Just to be safe ;o) // if ( !defined( "ENT_COMPAT" ) ) define( "ENT_COMPAT", 2 ); if ( !defined( "ENT_NOQUOTES" ) ) define( "ENT_NOQUOTES", 0 ); if ( !defined( "ENT_QUOTES" ) ) define( "ENT_QUOTES", 3 ); ?> --- NEW FILE: functions_field.php --- <?php /** ------------------------------------------------------------------------ * Subject : mxBB - a fully modular portal and CMS (for phpBB) * Author : Jon Ohlsson and the mxBB Team * Credits : The phpBB Group & Marc Morisette, wGeric * Copyright : (C) 2002-2005 mxBB Portal * Email : jo...@mx... * Project site : www.mxbb-portal.com * ------------------------------------------------------------------------- * * $Id: functions_field.php,v 1.1 2005/12/08 15:06:46 jonohlsson Exp $ */ /** * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ if ( !defined( 'IN_PORTAL' ) ) { die( "Hacking attempt" ); } class mx_kb_custom_field { var $field_rowset = array(); var $field_data_rowset = array(); // =================================================== // prepare data // =================================================== function init() { global $db; $sql = "SELECT * FROM " . KB_CUSTOM_TABLE . " ORDER BY field_order ASC"; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Couldnt Query Custom field', '', __LINE__, __FILE__, $sql ); } while ( $row = $db->sql_fetchrow( $result ) ) { $this->field_rowset[$row['custom_id']] = $row; } unset( $row ); $db->sql_freeresult( $result ); $sql = "SELECT * FROM " . KB_CUSTOM_DATA_TABLE; if ( !( $result = $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Couldnt Query Custom field', '', __LINE__, __FILE__, $sql ); } while ( $row = $db->sql_fetchrow( $result ) ) { $this->field_data_rowset[$row['customdata_file']][$row['customdata_custom']] = $row; } unset( $row ); $db->sql_freeresult( $result ); } // =================================================== // check if there is a data in the database // =================================================== function field_data_exist() { if ( !empty( $this->field_data_rowset ) ) { return true; } return false; } function field_exist() { if ( !empty( $this->field_rowset ) ) { return true; } return false; } // =================================================== // display data in the comment // =================================================== function add_comment( $file_id ) { global $template; if ( $this->field_data_exist() ) { if ( isset( $this->field_data_rowset[$file_id] ) ) { $message = ''; foreach( $this->field_data_rowset[$file_id] as $field_id => $data ) { if ( !empty( $data['data'] ) ) { switch ( $this->field_rowset[$field_id]['field_type'] ) { case INPUT: case TEXTAREA: case RADIO: case SELECT: $field_data = $data['data']; break; case SELECT_MULTIPLE: case CHECKBOX: $field_data = @implode( ', ', unserialize( $data['data'] ) ); break; } $message .= "\n" . "[b]" . $this->field_rowset[$field_id]['custom_name'] . ":[/b] " . $field_data . "\n"; } else { global $db; $sql = "DELETE FROM " . KB_CUSTOM_DATA_TABLE . " WHERE customdata_file = '$file_id' AND customdata_custom = '$field_id'"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not delete custom data', '', __LINE__, __FILE__, $sql ); } } } return $message; } else { return false; } } else { return false; } } // =================================================== // display data in the file page // =================================================== function display_data( $file_id ) { global $template; if ( $this->field_data_exist() ) { if ( isset( $this->field_data_rowset[$file_id] ) ) { foreach( $this->field_data_rowset[$file_id] as $field_id => $data ) { if ( !empty( $data['data'] ) ) { switch ( $this->field_rowset[$field_id]['field_type'] ) { case INPUT: case TEXTAREA: case RADIO: case SELECT: $field_data = $data['data']; break; case SELECT_MULTIPLE: case CHECKBOX: $field_data = @implode( ', ', unserialize( $data['data'] ) ); break; } $template->assign_block_vars( 'custom_field', array( 'CUSTOM_NAME' => $this->field_rowset[$field_id]['custom_name'], 'DATA' => $field_data ) ); } else { global $db; $sql = "DELETE FROM " . KB_CUSTOM_DATA_TABLE . " WHERE customdata_file = '$file_id' AND customdata_custom = '$field_id'"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not delete custom data', '', __LINE__, __FILE__, $sql ); } } } } else { return false; } } else { return false; } } // =================================================== // display custom field and data in the add/edit page // =================================================== function display_edit( $file_id = false ) { global $template; $return = false; if ( $this->field_exist() ) { foreach( $this->field_rowset as $field_id => $field_data ) { switch ( $field_data['field_type'] ) { case INPUT: $this->display_edit_input( $file_id, $field_id, $field_data ); break; case TEXTAREA: $this->display_edit_textarea( $file_id, $field_id, $field_data ); break; case RADIO: $this->display_edit_radio( $file_id, $field_id, $field_data ); break; case SELECT: $this->display_edit_select( $file_id, $field_id, $field_data ); break; case SELECT_MULTIPLE: $this->display_edit_select_multiple( $file_id, $field_id, $field_data ); break; case CHECKBOX: $this->display_edit_checkbox( $file_id, $field_id, $field_data ); break; } $return = true; } } return $return; } function display_edit_input( $file_id, $field_id, $field_data ) { global $template, $_POST; $field_value_temp = (!empty( $this->field_data_rowset[$file_id][$field_id]['data'] )) ? $this->field_data_rowset[$file_id][$field_id]['data'] : ''; $field_value = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $field_value_temp ; $template->assign_block_vars( 'input', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'], 'FIELD_VALUE' => $field_value ) ); } function display_edit_textarea( $file_id, $field_id, $field_data ) { global $template; $field_value_temp = ( !empty( $this->field_data_rowset[$file_id][$field_id]['data'] ) ) ? $this->field_data_rowset[$file_id][$field_id]['data'] : ''; $field_value = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $field_value_temp ; $template->assign_block_vars( 'textarea', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'], 'FIELD_VALUE' => $field_value ) ); } function display_edit_radio( $file_id, $field_id, $field_data ) { global $template; $template->assign_block_vars( 'radio', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'] ) ); $data_temp = ( !empty( $this->field_data_rowset[$file_id][$field_id]['data'] ) ) ? $this->field_data_rowset[$file_id][$field_id]['data'] : array(); $data = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $data_temp ; $field_datas = ( !empty( $field_data['data'] ) ) ? unserialize( stripslashes( $field_data['data'] ) ) : array(); if ( !empty( $field_datas ) ) { foreach( $field_datas as $key => $value ) { $template->assign_block_vars( 'radio.row', array( 'FIELD_VALUE' => $value, 'FIELD_SELECTED' => ( $data == $value ) ? ' checked="checked"' : '' ) ); } } } function display_edit_select( $file_id, $field_id, $field_data ) { global $template; $template->assign_block_vars( 'select', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'] ) ); $data_temp = ( !empty( $this->field_data_rowset[$file_id][$field_id]['data'] ) ) ? $this->field_data_rowset[$file_id][$field_id]['data'] : ''; $data = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $data_temp ; $field_datas = ( !empty( $field_data['data'] ) ) ? unserialize( stripslashes( $field_data['data'] ) ) : array(); if ( !empty( $field_datas ) ) { foreach( $field_datas as $key => $value ) { $template->assign_block_vars( 'select.row', array( 'FIELD_VALUE' => $value, 'FIELD_SELECTED' => ( $data == $value ) ? ' selected="selected"' : '' ) ); } } } function display_edit_select_multiple( $file_id, $field_id, $field_data ) { global $template; $template->assign_block_vars( 'select_multiple', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'] ) ); $data_temp = ( !empty( $this->field_data_rowset[$file_id][$field_id]['data'] ) ) ? unserialize( $this->field_data_rowset[$file_id][$field_id]['data'] ) : array(); $data = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $data_temp ; $field_datas = ( !empty( $field_data['data'] ) ) ? unserialize( stripslashes( $field_data['data'] ) ) : array(); if ( !empty( $field_datas ) ) { foreach( $field_datas as $key => $value ) { $selected = ''; foreach( $data as $field_value ) { if ( $field_value == $value ) { $selected = ' selected="selected"'; break; } } $template->assign_block_vars( 'select_multiple.row', array( 'FIELD_VALUE' => $value, 'FIELD_SELECTED' => $selected ) ); } } } function display_edit_checkbox( $file_id, $field_id, $field_data ) { global $template; $template->assign_block_vars( 'checkbox', array( 'FIELD_NAME' => $field_data['custom_name'], 'FIELD_ID' => $field_data['custom_id'], 'FIELD_DESCRIPTION' => $field_data['custom_description'] ) ); $data_temp = ( !empty( $this->field_data_rowset[$file_id][$field_id]['data'] ) ) ? unserialize( $this->field_data_rowset[$file_id][$field_id]['data'] ) : array(); $data = !empty( $_POST['field'][$field_data['custom_id']] ) ? $_POST['field'][$field_data['custom_id']] : $data_temp ; $field_datas = ( !empty( $field_data['data'] ) ) ? unserialize( stripslashes( $field_data['data'] ) ) : array(); if ( !empty( $field_datas ) ) { foreach( $field_datas as $key => $value ) { $checked = ''; foreach( $data as $field_value ) { if ( $field_value == $value ) { $checked = ' checked'; break; } } $template->assign_block_vars( 'checkbox.row', array( 'FIELD_VALUE' => $value, 'FIELD_CHECKED' => $checked ) ); } } } function update_add_field( $field_type, $field_id = false ) { global $db, $db, $_POST, $lang; $field_name = ( isset( $_POST['field_name'] ) ) ? htmlspecialchars( $_POST['field_name'] ) : ''; $field_desc = ( isset( $_POST['field_desc'] ) ) ? htmlspecialchars( $_POST['field_desc'] ) : ''; $regex = ( isset( $_POST['regex'] ) ) ? $_POST['regex'] : ''; $data = ( isset( $_POST['data'] ) ) ? $_POST['data'] : ''; $field_order = ( isset( $_POST['field_order'] ) ) ? $_POST['field_order'] : ''; if ( $field_id ) { $field_order = ( isset( $_POST['field_order'] ) ) ? intval( $_POST['field_order'] ) : ''; } if ( !empty( $data ) ) { $data = explode( "\n", htmlspecialchars( trim( $data ) ) ); foreach( $data as $key => $value ) { $data[$key] = trim( $value ); } $data = addslashes( serialize( $data ) ); } if ( empty( $field_name ) ) { mx_message_die( GENERAL_ERROR, $lang['Missing_field'] ); } if ( ( ( $field_type != INPUT && $field_type != TEXTAREA ) && empty( $data ) ) ) { mx_message_die( GENERAL_ERROR, $lang['Missing_field'] ); } if ( !$field_id ) { $sql = "INSERT INTO " . KB_CUSTOM_TABLE . " (custom_name, custom_description, data, regex, field_type) VALUES('" . $field_name . "', '" . $field_desc . "', '" . $data . "', '" . $regex . "', '" . $field_type . "')"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not add the new fields', '', __LINE__, __FILE__, $sql ); } $field_id = $db->sql_nextid(); $sql = "UPDATE " . KB_CUSTOM_TABLE . " SET field_order = '$field_id' WHERE custom_id = $field_id"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not set the order for the giving field', '', __LINE__, __FILE__, $sql ); } } else { $sql = "UPDATE " . KB_CUSTOM_TABLE . " SET custom_name = '$field_name', custom_description = '$field_desc', data = '$data', regex = '$regex', field_order='$field_order' WHERE custom_id = $field_id"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not update information for the giving field', '', __LINE__, __FILE__, $sql ); } } } function delete_field( $field_id ) { global $db; $sql = "DELETE FROM " . KB_CUSTOM_DATA_TABLE . " WHERE customdata_custom = '$field_id'"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not delete custom data', '', __LINE__, __FILE__, $sql ); } $sql = "DELETE FROM " . KB_CUSTOM_TABLE . " WHERE custom_id = '$field_id'"; if ( !( $db->sql_query( $sql ) ) ) { mx_message_die( GENERAL_ERROR, 'Could not delete the selected field', '', __LINE__, __FILE__, $sql ); } } function get_field_data( $field_id ) { $return_array = $this->field_rowset[$field_id]; $return_array['data'] = !empty( $return_array['data'] ) ? implode( "\n", unserialize( stripslashes( $return_array['data'] ) ) ) : ''; return $return_array; } // =================================================== // file data in custom field operations // =================================================== function file_update_data( $file_id ) { global $_POST, $db; $field = ( isset( $_POST['field'] ) ) ? $_POST['field'] : ''; if ( !empty( $field ) ) { foreach( $field as $field_id => $field_data ) { if ( !empty( $this->field_rowset[$field_id]['regex'] ) ) { if ( !preg_match( '#' . $this->field_rowset[$field_id]['regex'] . '#siU', $field_data ) ) { $field_data = ''; } } switch ( $this->field_rowset[$field_id]['field_type'] ) { case INPUT: case TEXTAREA: case RADIO: case SELECT: $data = htmlspecialchars( $field_data ); break; case SELECT_MULTIPLE: case CHECKBOX: $data = addslashes( serialize( $field_data ) ); break; } $sql = "DELETE FROM " . KB_CUSTOM_DATA_TABLE . " WHERE customdata_file = '$file_id' AND customdata_custom = '$field_id'"; if ( !$db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, 'Could not delete data from custom data table', '', __LINE__, __FILE__, $sql ); } if ( !empty( $data ) ) { $sql = "INSERT INTO " . KB_CUSTOM_DATA_TABLE . " (customdata_file, customdata_custom, data) VALUES('$file_id', '$field_id', '$data')"; if ( !$db->sql_query( $sql ) ) { mx_message_die( GENERAL_ERROR, 'Could not add additional data', '', __LINE__, __FILE__, $sql ); } } } } } } ?> |