last_send_out."' WHERE `kpi_settings`.`id` =1;"; $result = execute_sql($db, $sql); $db->sql_close(); } function load_settings() { $settings = new settings(); $db=connect_to_datebase(); $sql = "SELECT * FROM kpi_settings where id='1'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $settings->last_send_out = $row2['last_send_out']; $db->sql_close(); return $settings; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class site_stats { var $total_kpi = ""; var $total_comments = ""; var $last_month_kpi = ""; var $last_month_comments = ""; var $total_categories=""; var $total_authors=""; function get_stats() { $stat = new site_stats(); $filter_month = date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")-30, date("Y")) ); $db = connect_to_datebase(); $sql = "SELECT kpi_id FROM `kpi_request` where kpi_status='1' " ; $result = execute_sql($db, $sql); $stat->total_kpi = mysql_num_rows($result); $sql = "SELECT cmt_id FROM `kpi_comments` where cmt_status='1' " ; $result = execute_sql($db, $sql); $stat->total_comments = mysql_num_rows($result); $sql = "SELECT kpi_id FROM `kpi_request` where kpi_status='1' and kpi_publish_date > '".$filter_month."' " ; $result = execute_sql($db, $sql); $stat->last_month_kpi = mysql_num_rows($result); $sql = "SELECT cmt_id FROM `kpi_comments` where cmt_status='1' and cmt_date_time > '".$filter_month."' " ; $result = execute_sql($db, $sql); $stat->last_month_comments = mysql_num_rows($result); $sql = "SELECT COUNT( kpi_category ) FROM `kpi_request` GROUP BY kpi_category " ; $result = execute_sql($db, $sql); $stat->total_categories = mysql_num_rows($result); $sql = "SELECT user_id FROM `kpi_users` where user_status ='1' " ; $result = execute_sql($db, $sql); $stat->total_authors = mysql_num_rows($result); return $stat; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class log_record { var $log_id=""; var $log_type=""; // 0 - starting credit, 1 - score for post; 2 - score for first comment; 3 - score for comment; 4 - score for profile fill in, 5 - deleted comment, 6 - flag comment for moderator, 7 - flag post for moderation var $log_text=""; var $log_score=""; var $log_parent_id=""; var $log_date=""; var $log_user_id=""; function count_flags_for($id, $type) { if ($type=="comment") {$lg_type='6';} if ($type=="post") {$lg_type='7';} $db=connect_to_datebase(); $sql = "SELECT *, COUNT(DISTINCT log_user_id) as cnt_records FROM kpi_log WHERE log_type='".$lg_type."' and log_parent_id='".$id."' group by log_parent_id"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $cmt_count = $row2['cnt_records']; if ($cmt_count=='') {$cmt_count = 0; } $db->sql_close(); return $cmt_count; } function add_new_log_record($new_record) { $dateTime = new DateTime("now"); $new_record->log_date = $dateTime->format("Y-m-d H:i:s"); $db=connect_to_datebase(); $sql = "INSERT INTO kpi_log ( `log_type` , `log_user_id`, `log_text` , `log_score` , `log_parent_id` , `log_date` ) VALUES ( '$new_record->log_type', '$new_record->log_user_id', '$new_record->log_text', '$new_record->log_score', '$new_record->log_parent_id', '$new_record->log_date' ); "; $result = execute_sql($db, $sql); $db->sql_close(); } } class comment_filter { var $by_post_id = ""; var $by_status = ""; } class post_filter { var $by_page = ""; var $by_user = ""; var $by_answers = ""; var $by_date = ""; var $by_status = ""; var $random = ""; var $limit_number=""; var $limit_description_text=""; var $by_category=""; var $starting_date=""; var $limit_by_comments_count=""; var $list_for_email=""; } class info_message { var $message_type = "-1"; // -1 - do not display; 0 - info, 1 - success, 2 - warning, 3 - error\ var $message_title = ""; var $message_text = ""; var $message_html_code = ""; var $redirect_to=""; } class post_comment { var $cmt_id = ""; var $cmt_author_id = ""; var $cmt_parent_post = ""; var $cmt_date_time = ""; var $cmt_text = ""; var $cmt_status = ""; // 1 - published, visible, 3 - looks like spam function check_if_duplicated_comment($comment_text) { $db=connect_to_datebase(); $sql = "SELECT * FROM kpi_comments WHERE cmt_text ='".$comment_text."'; "; $result = execute_sql($db, $sql); $num_rows = mysql_num_rows($result); $db->sql_close(); if ($num_rows == 0) {return 0;} else {return 1;} } //////////////////////////////////////////////////////////////////////////////// function delete_comment($comment_id) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); $sql = "DELETE FROM kpi_comments WHERE `cmt_id` ='".$comment_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////// function update_comment($comment) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); // insert $sql = "UPDATE kpi_comments SET cmt_text = '$comment->cmt_text', cmt_status = '$comment->cmt_status' WHERE `cmt_id` ='".$comment->cmt_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// function load_comment($cmt_id) { $db = connect_to_datebase(); $sql = "select * from kpi_comments where cmt_id = '".$cmt_id."'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $comment = post_comment::load_comment_data_from_row($row2); return $comment; } function load_comment_data_from_row($row) { $comment = new post_comment(); $comment->cmt_id = $row['cmt_id']; $comment->cmt_author_id = $row['cmt_author_id']; $comment->cmt_parent_post = $row['cmt_parent_post']; $comment->cmt_date_time = $row['cmt_date_time']; $comment->cmt_text = $row['cmt_text']; $comment->cmt_status = $row['cmt_status']; return $comment; } function prepare_comment_for_display($comment, $author_full_name, $google_plus_id) { $dateTime = new DateTime($comment->cmt_date_time); $post_date = $dateTime->format("F j, Y") .' at ' . $dateTime->format("g:i a"); if ($_COOKIE['username'] != '') { $control_params = ' | Flag for moderation'; } if (is_admin()==1) { $admin_edit = ' | Edit'. ' | Delete'. ' | author id: '.$comment->cmt_author_id;} else {$admin_edit="";} $gplus_url = ' | +'; if ($google_plus_id=='') {$gplus_url='';} $author_url = ''.$author_full_name.''.$gplus_url; // .''; $photo_url = get_user_photo_file_by_id($comment->cmt_author_id); $one_comment = '

KPI Expert '.$current_user->user_fullname.''. sanize_text_to_display_kpi_special($comment->cmt_text).'

'. $author_url .' | ' .$post_date.$control_params.$admin_edit.'
'; return $one_comment; } } class page_content { var $java_scripts = ""; var $page_html_title = ""; var $page_title=""; var $page_tagline = ""; var $page_main_content = ""; var $load_status=""; // 1 - published visible , 2 - published - waiting for confirm , 3 - looks like spam var $sidebar_content=""; var $no_sidebar=""; var $cat_ad_widebar=""; var $cat_ad_sidebar=""; } class kpi_user { var $user_id = ""; var $user_password = ""; var $user_email = ""; var $user_joindate =""; var $user_fullname =""; var $user_location =""; var $user_expert_in =""; var $user_status =""; var $user_score =""; var $user_send_mails =""; var $user_website=""; var $user_info=""; var $user_googleplus = ""; function get_profile_fillin_progress($expert_id) { $current_user = kpi_user::load_current_user_by_id($expert_id); $tc=0; $c=0; // initial $c = $c+1; $tc=$tc+1; if ($current_user->user_fullname != "") {$c = $c+1; } $tc=$tc+1; if ($current_user->user_location != "") {$c = $c+1; } $tc=$tc+1; if ($current_user->user_expert_in != "") {$c = $c+1; } $tc=$tc+1; if ($current_user->user_website != "") {$c = $c+1; } $tc=$tc+1; if ($current_user->user_googleplus != "") {$c = $c+1; } $tc=$tc+1; if ($current_user->user_info != "") {$c = $c+1; } $tc=$tc+1; if (get_user_photo_file_by_id($expert_id) != "http://www.winningkpi.com/photos/0.png") {$c = $c+1; } $tc=$tc+1; return round($c*100/$tc); } function get_kpi_home_page_url_by_id($expert_id) { return WEB_ROOT.'experts/'.$expert_id.'.htm'; } //////////////////////////////////////////////////////////////////////////////// function update_user_score($user_email, $score_to_add, $parent_id, $type_of_update, $log_text) { $user = new kpi_user(); $user=kpi_user::load_current_user($user_email); $cur_user_id = $user->user_id; $user->user_score = $user->user_score + $score_to_add; $user=kpi_user::update_user($user); $log = new log_record(); $log->log_type= $type_of_update; // 0 - unknown, 1 - score for post; 2 - score for first comment; 3 - score for comment; 4 - score for profile fill in $log->log_text= $log_text; $log->log_score= $score_to_add; $log->log_parent_id= $parent_id; $log->log_user_id= $cur_user_id; log_record::add_new_log_record($log); } //////////////////////////////////////////////////////////////////////////////// function user_has_scorecard_for_profile($new_user) { $db = connect_to_datebase(); $sql=" SELECT * FROM kpi_log where log_user_id='$new_user->user_id' and log_type ='4' "; $result = execute_sql($db, $sql); if (mysql_num_rows($result) == 0 ) {return 0;} else {return 1;} } function check_if_profile_is_full($new_user) { $res = 1; if ($new_user->user_fullname == "") {$res = 0;} if ($new_user->user_location == "") {$res = 0;} if ($new_user->user_expert_in == "") {$res = 0;} return $res; } //////////////////////////////////////////////////////////////////////////////// function update_user($new_user) { if (is_user_logged_adv() != 1) {return '';} $db = connect_to_datebase(); $sql=" UPDATE `savkin_kpi`.`kpi_users` SET "; if ($new_user->user_password != '') { $sql=$sql."user_password= '".$new_user->user_password."',"; } if ($new_user->user_joindate != '') { $sql=$sql."user_joindate= '". $new_user->user_joindate."',"; } if ($new_user->user_score != '') { $sql=$sql."user_score= '". $new_user->user_score."', "; } $sql=$sql."user_location= '". $new_user->user_location."', "; $sql=$sql."user_expert_in= '". $new_user->user_expert_in."', "; $sql=$sql."user_send_mails= '". $new_user->user_send_mails."', "; $sql=$sql."user_website= '". $new_user->user_website."', "; $sql=$sql."user_googleplus= '". $new_user->user_googleplus."', "; $sql=$sql."user_info= '". $new_user->user_info."', "; if ($new_user->user_status != '') { $sql=$sql."user_status= '". $new_user->user_status."',"; } $sql=$sql." user_email= '". $new_user->user_email."', user_fullname= '". $new_user->user_fullname."' WHERE `kpi_users`.`user_email` ='".$new_user->user_email."' "; $result = execute_sql($db, $sql); } //////////////////////////////////////////////////////////////////////////////// function load_current_user_by_id($user_id) { //if (is_user_logged_adv() != 1) {return '';} $new_user = new kpi_user(); $db = connect_to_datebase(); $sql = "select * from kpi_users where user_id = '".$user_id."'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $new_user->user_id = $row2['user_id']; $new_user->user_password = $row2['user_password']; $new_user->user_email = $row2['user_email']; $new_user->user_joindate =$row2['user_joindate']; $new_user->user_fullname =$row2['user_fullname']; $new_user->user_location =$row2['user_location']; $new_user->user_expert_in =$row2['user_expert_in']; $new_user->user_send_mails =$row2['user_send_mails']; $new_user->user_status =$row2['user_status']; $new_user->user_score =$row2['user_score']; $new_user->user_website =$row2['user_website']; $new_user->user_googleplus =$row2['user_googleplus']; $new_user->user_info =$row2['user_info']; return $new_user; } //////////////////////////////////////////////////////////////////////////////// function load_current_user($user_email) { if (is_user_logged_adv() != 1) {return '';} $new_user = new kpi_user(); $db = connect_to_datebase(); $sql = "select * from kpi_users where user_email = '".$user_email."'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $new_user->user_id = $row2['user_id']; $new_user->user_password = $row2['user_password']; $new_user->user_email = $row2['user_email']; $new_user->user_joindate =$row2['user_joindate']; $new_user->user_fullname =$row2['user_fullname']; $new_user->user_location =$row2['user_location']; $new_user->user_expert_in =$row2['user_expert_in']; $new_user->user_send_mails =$row2['user_send_mails']; $new_user->user_status =$row2['user_status']; $new_user->user_score =$row2['user_score']; $new_user->user_website =$row2['user_website']; $new_user->user_googleplus =$row2['user_googleplus']; $new_user->user_info =$row2['user_info']; return $new_user; } } ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// class article { var $article_id = ""; var $article_name = ""; var $article_category = ""; var $article_body = ""; var $article_permalink = ""; var $article_author = ""; //////////////////////////////////////////////////////////////////////////////// function delete_article($article_id) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); // insert $sql = "DELETE FROM kpi_articles WHERE `article_id` ='".$article_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////// function update_article($new_article) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); // insert $sql = "UPDATE kpi_articles SET article_name = '$new_article->article_name', article_category = '$new_article->article_category', article_body = '$new_article->article_body', article_permalink = '$new_article->article_permalink', article_author = '$new_article->article_author' WHERE `article_id` ='".$new_article->article_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function get_articles_list($article_category) { $db = connect_to_datebase(); if ($article_category !='') { $sql = "select * from kpi_articles where article_category = '".$article_category."'"; } else {$sql = "select * from kpi_articles"; } $result = execute_sql($db, $sql); $res_str = ''; if ($article_category=="general") {$res_str = '

Relevant articles:

'; } else {$res_str = '

Articles in '.$article_category.' category:

'; } if (is_admin()==1) { $admin_str = 'Article admin: New Article | Article Manager'; if (has_advanced_rights()==1) {$admin_str = $admin_str . ' | Edit Categories';} $res_str = $res_str . $admin_str; } $res_str =$res_str. ''; if ($i==0) {$res_str='';} return $res_str; } //////////////////////////////////////////////////////////////////////////////// function load_article($article_id) { $db = connect_to_datebase(); $sql = "select * from kpi_articles where article_id = '".$article_id."'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $article = article::get_article_from_row($row2); return $article; } //////////////////////////////////////////////////////////////////////////////// function get_article_from_row($row) { $article = new article(); $article->article_id = $row['article_id']; $article->article_name = $row['article_name']; $article->article_category = $row['article_category']; $article->article_body = $row['article_body']; $article->article_permalink = $row['article_permalink']; $article->article_author = $row['article_author']; return $article; } //////////////////////////////////////////////////////////////////////////////// } class kpi_request { var $kpi_id = ""; var $kpi_author_id = ""; var $kpi_is_for = ""; var $kpi_category = ""; var $kpi_category_permalink = ""; var $kpi_description = ""; var $kpi_publish_date = ""; var $kpi_permalink = ""; var $kpi_status = ""; // 2 - published, but not confirmed email 1 - confirmed and live 3- spam var $read_comments_num = ""; var $kpi_post_image = ""; var $kpi_post_image_caption = ""; var $kpi_post_image_link = ""; var $kpi_youtube_link = ""; //////////////////////////////////////////////////////////////////////////////// function delete_kpi($kpi_id) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); // insert $sql = "DELETE FROM kpi_request WHERE `kpi_id` ='".$kpi_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////// function update_kpi($new_kpi_request) { $msg = new info_message(); $msg->message_type=0; $db=connect_to_datebase(); // insert $sql = "UPDATE kpi_request SET kpi_is_for = '$new_kpi_request->kpi_is_for', kpi_category = '$new_kpi_request->kpi_category', kpi_category_permalink = '$new_kpi_request->kpi_category_permalink', kpi_description = '$new_kpi_request->kpi_description', kpi_permalink = '$new_kpi_request->kpi_permalink', kpi_status = '$new_kpi_request->kpi_status', kpi_post_image = '$new_kpi_request->kpi_post_image', kpi_post_image_caption = '$new_kpi_request->kpi_post_image_caption', kpi_post_image_link = '$new_kpi_request->kpi_post_image_link', kpi_youtube_link = '$new_kpi_request->kpi_youtube_link' WHERE `kpi_id` ='".$new_kpi_request->kpi_id."'; "; $result = execute_sql($db, $sql); $db->sql_close(); return $msg; } //////////////////////////////////////////////////////////////////////////////// function load_kpi($kpi_id) { $db = connect_to_datebase(); $sql = "select * from kpi_request where kpi_id = '".$kpi_id."'"; $result = execute_sql($db, $sql); $row2 = get_result_raw($db, $result); $kpi = kpi_request::get_kpi_request_from_row($row2); return $kpi; } //////////////////////////////////////////////////////////////////////////////// function get_kpi_request_from_row($row) { $kpi_req = new kpi_request(); $kpi_req->kpi_id = $row['kpi_id']; $kpi_req->kpi_is_for = $row['kpi_is_for']; $kpi_req->kpi_category = $row['kpi_category']; $kpi_req->kpi_category_permalink = $row['kpi_category_permalink']; $kpi_req->kpi_description = $row['kpi_description']; $kpi_req->kpi_publish_date = $row['kpi_publish_date']; $kpi_req->kpi_permalink = $row['kpi_permalink']; $kpi_req->kpi_post_image = $row['kpi_post_image']; $kpi_req->kpi_post_image_caption = $row['kpi_post_image_caption']; $kpi_req->kpi_post_image_link = $row['kpi_post_image_link']; $kpi_req->kpi_youtube_link = $row['kpi_youtube_link']; $kpi_req->kpi_status = $row['kpi_status']; $kpi_req->kpi_author_id = $row['kpi_author_id']; $kpi_req->read_comments_num = $row['comments_cnt']; return $kpi_req; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// function get_post_comments_count($kpi_id) { // find and sort all comments with parent kpi_id with status = 1 $db=connect_to_datebase(); $sql = "SELECT * FROM kpi_comments where cmt_parent_post = '".$kpi_id."' and cmt_status='1'" ; $result = execute_sql($db, $sql); $num_rows = mysql_num_rows($result); return $num_rows; } //////////////////////////////////////////////////////////////////////////////// } ?>