Location: PHPKode > projects > Skills Evaluator - Free HR evaluation software > skills-evaluator_1.3/http/functions.php
<?php


$db_id = mysql_connect($db_host, $db_user, $db_pass)
 or die("Could not connect to DB.");
mysql_select_db($db_name, $db_id)
 or die("Database not found.");
 //time difference; gets for how much the mysql server time is ahead, compared to the http server time;
 $query="SELECT timediff(now(), '".date("Y-m-d H:i:s")."')";
 $result=mysql_query($query, $db_id);
 $tdif=mysql_fetch_row($result); $tdif=explode(":", $tdif[0]);
 if ($tdif[0][0]=="-") {$tdif[0]=abs($tdif[0]); $tdif[3]="-";}
 else $tdif[3]="+"; $tdif=" ".$tdif[3]." interval ".$tdif[0]." hour ".$tdif[3]." interval ".$tdif[1]." minute ".$tdif[3]." interval ".$tdif[2]." second";

if($include_functions_php_sw!=1) {
session_start();

if (!isset($_SESSION['initiated']))
{

    session_regenerate_id();
    $_SESSION['initiated'] = true;
}//just a security tip
}//end of check if this file is included from install.php

//check to see if this file is called from root or from a subfolder e.g. custom_modules up to 2 levels supported
			 if(is_file(customfc('login.php'))) $filepath=""; 
			 if(is_file("../".customfc('login.php')."")) $filepath="../"; 
			 if(is_file("../../".customfc('login.php')."")) $filepath="../../"; 
			 
if (isset($_SESSION["user"][0])) {include $filepath.$_SESSION["user"][14]; $lang_file=$filepath.$_SESSION["user"][14];}
else if (isset($_SESSION["lang"])) {include $filepath.$_SESSION["lang"]; $lang_file=$filepath.$_SESSION["lang"];}
else {$_SESSION["lang"]=$default_language_file; include $filepath.$default_language_file; $lang_file=$filepath.$default_language_file;}

$title=$lang['title'];

 
  if (isset($_SESSION["user"][0])) {$template=$_SESSION["user"][11];}
 else {$template=$default_template_folder;}

if (isset($_SESSION["user"][0]))
{
 	$query="select * from users where id='".$_SESSION["user"][0]."' and timediff(now(), lastVisit)>'00:03:58'";
	$usr=user($_SESSION["user"][0]);
	$credits=$usr[17];
 $result=mysql_query($query, $db_id);
 $num_rows = mysql_num_rows($result);
 if ( $num_rows>0) {
$update_visit=update_lastVisit($_SESSION["user"][0]);
}
 
 
function Sec2Time($time_sec){
  if(is_numeric($time_sec)){
    $value = array(
     "hours" => 0,
      "minutes" => 0, "seconds" => 0,
    );
    if($time_sec >= 3600){
      $value["hours"] = floor($time_sec/3600);
      $time_sec = ($time_sec%3600);
    }
    if($time_sec >= 60){
      $value["minutes"] = floor($time_sec/60);
      $time_sec = ($time_sec%60);
    }
    $value["seconds"] = floor($time_sec);
    return (array) $value;
  }else{
    return (bool) FALSE;
  }
}

}

function current_file()
{
    $currentFile = $_SERVER["SCRIPT_NAME"]; 
    $parts = Explode('/', $currentFile); 
    $currentFile = $parts[count($parts) - 1]; 
return $currentFile;
}

function dfcms_version()
{
$version='2.2';
return $version;
}

function version_check()
{
global $lang;

if (@fopen('http://www.tecorange.com/tecorange_software_info.htm','r')) {

$version=dfcms_version();
$chunk= file_get_contents('http://www.tecorange.com/tecorange_software_info.htm');
$pattern = "/#DFCMS-Latest Version#<strong>(.*?)<\/strong>#Latest Version#/i";
preg_match($pattern, $chunk, $match);
$latest_version=$match[1];

$chunk1= file_get_contents('http://www.tecorange.com/tecorange_software_info.htm');
$pattern1 = "/#DFCMS-Info URL#<strong>(.*?)<\/strong>#Info URL#/i";
preg_match($pattern1, $chunk1, $match1);
$info_url=$match1[1];

$output=$version."--".$lang['version_of_dfcms']."<b> ".$version." </b>";

if($version==$match[1]) $output=$output."<br>".$lang['you_have_the_latest_version'];
if($version<$match[1]) $output=$output."<br>".$lang['there_is_a_newer_version']."<br><a href='".$info_url."'>".$info_url."</a>";

return $output;
}else return '0--No version info at the momment';
}


// Return URL-Friendly string based on title

function sef_name($title) {
    
      $str=$title;
	  //greek characters convertions for search engine friendly urls
	  $str = str_replace(array("α","Α","ά","Ά"),'a',$str); 
      $str = str_replace(array("β","Β"),'b',$str); 
      $str = str_replace(array("γ","Γ"),'g',$str); 
      $str = str_replace(array("δ","Δ"),'d',$str); 
      $str = str_replace(array("ε","Ε","έ","Έ"),'e',$str); 
      $str = str_replace(array("ζ","Ζ"),'z',$str); 
      $str = str_replace(array("η","Η","ή","Ή"),'i',$str); 
      $str = str_replace(array("θ","Θ"),'th',$str); 
      $str = str_replace(array("ι","Ι","ϊ","ί","Ί","Ϊ","ΐ"),'i',$str); 
      $str = str_replace(array("κ","Κ"),'k',$str); 
      $str = str_replace(array("λ","Λ"),'l',$str); 
      $str = str_replace(array("μ","Μ"),'m',$str); 
      $str = str_replace(array("ν","Ν"),'n',$str); 
      $str = str_replace(array("ξ","Ξ"),'ks',$str); 
      $str = str_replace(array("ο","Ο","ό","Ό"),'o',$str); 
      $str = str_replace(array("π","Π"),'p',$str); 
      $str = str_replace(array("ρ","Ρ"),'r',$str); 
      $str = str_replace(array("σ","ς","Σ"),'s',$str); 
      $str = str_replace(array("τ","Τ"),'t',$str); 
      $str = str_replace(array("υ","Υ","ϋ","ύ","Ύ","Ϋ","ΰ"),'u',$str); 
      $str = str_replace(array("φ","Φ"),'f',$str); 
      $str = str_replace(array("χ","Χ"),'x',$str); 
      $str = str_replace(array("ψ","Ψ"),'ps',$str); 
      $str = str_replace(array("ω","Ω","ώ","Ώ"),'w',$str); 
	  //end of greek chars convertion

      $str = strtolower($str);
	
	//Strip any unwanted characters
    $str = preg_replace("/[^a-z0-9_\s-]/", "", $str);
    //Clean multiple dashes or whitespaces
    $str = preg_replace("/[\s-]+/", " ", $str);
    //Convert whitespaces and underscore to dash
    $str = preg_replace("/[\s_]/", "-", $str);

    return $str;
}

function menu_rear()
{

global $lang,$template,$filepath;
$config=config();

echo "<font class='q_text_sm'>language:</font> ";
			
						 //check custom_language folder for custom languages
			 
			 //check below used in case functions.php is called from a folder inside root. up to 2 levels are supported. we just check foi ch_lang file location
			 if(is_file("ch_lang.php")) $dir=dir("language/"); 
			 if(is_file("../ch_lang.php")) $dir=dir("../language/"); 
			 if(is_file("../../ch_lang.php")) $dir=dir("../../language/");

             while($filename=$dir->read()) {
			 $show_lang_letters=explode(".",$filename);
			  if ($filename[0]!=".")   echo "<a class='q_link' href='".$filepath.customfc('ch_lang.php')."?lang=".$filename."'> ".$show_lang_letters[0]." ";

			  }
             $dir->close();
			 
			 //check custom_language folder for custom languages
			 //check below used in case functions.php is called from a folder inside root. up to 2 levels are supported
			 if(is_dir("custom_language")) $dir1=dir("custom_language/"); 
			 if(is_dir("../custom_language")) $dir1=dir("../custom_language/"); 
			 if(is_dir("../../custom_language")) $dir1=dir("../../custom_language/"); 
			 
             while($filename=$dir1->read()) {
			 $show_lang_letters=explode(".",$filename);
			  if ($filename[0]!=".")   echo "<a class='q_link' href='".$filepath.customfc('ch_lang.php')."?lang=".$filename."'> ".$show_lang_letters[0]." ";

			  }
             $dir1->close();

			 

echo "<br><a class='q_link' href='".$filepath.customfc('index.php')."'>".$lang['home']."</a><br>";
if (!isset($_SESSION["user"][1]) && $config[2][1]==1) echo "<a class='q_link' href='".$filepath.customfc('login.php')."'>".$lang['login']."</a><br>";
if (!isset($_SESSION["user"][1]) && $config[3][1]==1) echo "<a class='q_link' href='".$filepath.customfc('register.php')."'>".$lang['register']."</a>";
if (isset($_SESSION["user"][1])) echo "<a class='q_link' href='".$filepath.customfc('logout.php')."'>".$lang['logout']."</a> ";
if (isset($_SESSION["user"][1])) echo "<br><a class='q_link' href='".$filepath.customfc('profile_view.php')."?id=".$_SESSION["user"][0]."'>".$lang['profile']."</a> ";

 if (isset($_SESSION["user"][0])) $alert=msg_rep_alert($_SESSION["user"][0]);
 if (isset($alert[1][0])) $alert[1]="<font color='red'>".$alert[1][0]."</font> "; else $alert[1]="";
 if (isset($_SESSION["user"][1])) echo "<br><a class='q_link' href='".$filepath.customfc('messages.php')."?page=0'>".$alert[1].$lang['messages']."</a> ";

}

function menu_admin()
{
global $lang,$template,$filepath;
 
 if (isset($_SESSION["user"][0])){
 $usr=user($_SESSION["user"][0]);
 
 if ((isset($_SESSION["user"][5]))&&($_SESSION["user"][5]>3)) echo "<hr><font class='q_text_sm'>Admin Links: </font><a class='q_link_sm' href='".$filepath.customfc('a_panel.php')."'>".$lang['adminPanel']."</a><hr>";
 }
}





function msg($msg)
{
 header("Location: ".customfc('msg.php')."?msg=".$msg);
}

function label($msg)
{
 echo "<font face=\"Fixedsys\" color=\"red\">".$msg."</font>";}
 
function clean($str)
{
 if (is_numeric($str)) $str=floor($str);
 $cleaned=strip_tags($str);
 $cleaned=htmlspecialchars($cleaned);
 $cleaned=mysql_real_escape_string($cleaned);
 $to_clean=array("%20", "\"", "'", "\\", "=", ";", ":");
 $cleaned=str_replace($to_clean, "", $cleaned);
 return $cleaned;
}




function sanitizeVariables(&$item, $key) 
{ 
    if (!is_array($item)) 
    { 
        // undoing 'magic_quotes_gpc = On' directive 
        if (get_magic_quotes_gpc()) 
            $item = stripcslashes($item); 
        
        $item = sanitizeText($item); 
    } 
} 

//below added sho to sanitiza all post and get
array_walk_recursive($_POST, 'sanitizeVariables'); 
array_walk_recursive($_GET, 'sanitizeVariables'); 
// does the actual 'html' and 'sql' sanitization. customize if you want. 
function sanitizeText($text) 
{ 
    $text = str_replace("<", "&lt;", $text); 
    $text = str_replace(">", "&gt;", $text); 
    $text = str_replace("\"", "&quot;", $text); 
    $text = str_replace("'", "&#039;", $text); 
    
    // it is recommended to replace 'addslashes' with 'mysql_real_escape_string' or whatever db specific fucntion used for escaping. However 'mysql_real_escape_string' is slower because it has to connect to mysql. 
    $text = mysql_real_escape_string($text); 

    return $text; 
} 

// the reverse function of 'sanitizeText'. you may use it in pages which need the original data (e.g. for an HTML editor) 
function unsanitizeText($text) 
{ 
    $text =  stripcslashes($text); 

    $text = str_replace("&#039;", "'", $text); 
    $text = str_replace("&gt;", ">", $text); 
    $text = str_replace("&quot;", "\"", $text);    
    $text = str_replace("&lt;", "<", $text); 
    
    return $text; 
} 


function gen_stats($dur)
{
 global $db_id;

 $query="SELECT count(*) FROM users";
 $result=mysql_query($query, $db_id);
 $row[0]=mysql_fetch_row($result);
print (mysql_error());
 $query="SELECT count(*) FROM users where hour(timediff(now(), lastVisit))<".$dur;
 $result=mysql_query($query, $db_id);
 $row[1]=mysql_fetch_row($result);
 
 return $row;
}

function clean_u($dur)
{
 global $db_id,$server_name,$charset_m,$server_domain,$admin_u_name;

 $query="SELECT id,email FROM users where name!='".$admin_u_name."' AND hour(timediff(now(), lastVisit))/24>".$dur;
 $result=mysql_query($query, $db_id); $nr=0;
 for (; $row=mysql_fetch_row($result); $nr++){
 	$headers = 'From: noreply@'.$server_domain . "\r\n" .
    'Reply-To: noreply@'.$server_domain .'; charset='.$charset_m . "\r\n" .
	'Content-Type: text/html "\r\n" 
    X-Mailer: PHP/' . phpversion();

	mail($row[1], "Removed from ".$server_name, "Your account has been deleted becouse you were idle (inactive) or becouse you show inappropriate behavior. Do not reply to this address. Use site contatc page instead. Thank you.", $headers );
  del_u($row[0]);
 }
 return $nr;
}




function is_user($name, $email, $ip)
{
 global $db_id;

 $query="select count(*) from users where name='".$name."' or email='".$email."' or ip='".$ip."'";
 $result=mysql_query($query, $db_id);
 
 $row=mysql_fetch_row($result);
 return $row[0];
}

function is_user_temp($name, $email, $ip)
{
 global $db_id;

 $query="select count(*) from users_temp where name='".$name."' or email='".$email."' or ip='".$ip."'";
 $result=mysql_query($query, $db_id);
 
 $row=mysql_fetch_row($result);
 return $row[0];
}

function login($name, $pass)
{
 global $db_id;

 $query="select * from users where name='".$name."' and pass='".$pass."' and level>0";
 $result=mysql_query($query, $db_id);
 
 $row=mysql_fetch_row($result);
 return $row;
}


function user($id)
{
 global $db_id;
 
 $query="select * from users where id=".preg_replace("/[^0-9]/","", $id);
 $result=mysql_query($query, $db_id);
 if($result) $numrows=mysql_num_rows($result); else $numrows=0;

 if ($numrows>0)
 {
  $row=mysql_fetch_row($result);
  $row[1]=stripslashes($row[1]); $row[9]=stripslashes($row[9]);
  return $row;
 } else return 0;
}

function users()
{
 global $db_id;
 
 $query="select * from users";
 $result=mysql_query($query, $db_id); $users=array();
 for ($i=0; $row=mysql_fetch_row($result); $i++)
 {
  $users[$i]=$row;
  $users[$i][1]=stripslashes($users[$i][1]); $users[$i][9]=stripslashes($users[$i][9]);
 }
 return $users;
}

function user_($name)
{
 global $db_id;

 $query="select * from users where name='".$name."'";
 $result=mysql_query($query, $db_id);
 
 if ($result)
 {
  $row=mysql_fetch_row($result);
  $row[1]=stripslashes($row[1]); $row[9]=stripslashes($row[9]);
  return $row;
 } else return 0;
}

function config()
{
 global $db_id;

 $config=array();
 $query="select * from config order by ord asc";
 $result=mysql_query($query, $db_id);
 for ($i=0; $row=mysql_fetch_row($result); $i++) $config[$i]=$row;
 return $config;
}

function get_search_term($id)
{
 global $db_id;

 $get_search_term=array();
 $query="select * from search_terms where id=".$id;
 $result=mysql_query($query, $db_id);
 $get_search_term=mysql_fetch_row($result);
 return $get_search_term;
}

function config_display()
{
 global $db_id;

 $config_display=array();
 $query="select * from config order by settings_group ASC, ABS(display_order) ASC";
 $result=mysql_query($query, $db_id);
 for ($i=0; $row=mysql_fetch_row($result); $i++) $config_display[$i]=$row;
 return $config_display;
}

function config_($var, $val)
{
 global $db_id;

 $query="update config set value='".$val."' where name='".$var."'";
 $result=mysql_query($query, $db_id);
 if ($result) return 1;
 else return 0;
}

function g_points($id, $q, $reason)
{
 global $db_id;

   $query="insert into points_to_add (user_id, points, time_earned, reason) values (".$id.", ".$q.", '".time()."', '".$reason."')";
 $result=mysql_query($query, $db_id);
 if ($result) return 1;
 else return 0;
}



function update_lastVisit($id)
{
 global $db_id;
 $query="select count(*) from messages where recipient=".$id." and timediff((select lastVisit from users where id=".$id."), sent)<'00:00:01'";
 $result=mysql_query($query, $db_id);
 $row[1]=mysql_fetch_row($result); $row[1]=$row[1][0];
 $query="update users set lastVisit=now(), ip='".$_SERVER["REMOTE_ADDR"]."' where id=".$id;
 mysql_query($query, $db_id);
 
 return $row;
}

function check_d($id)
{
 global $db_id;

 $query="select timediff(dueTime, now()) from d_queue where user=".$id;
 $result=mysql_query($query, $db_id);
 $row=mysql_fetch_row($result);
 if ($row[0][0]){
  if ($row[0][0]=="-")
  {
  	$query="delete from users where id=".$id; 
    mysql_query($query, $db_id);
   return 0;
 }
  }
  return 1;
 
}



function del_u($id)
{
 global $db_id;


   $query="delete from messages where recipient=".$id;
   mysql_query($query, $db_id);
   $query="delete from users where id=".$id;
   mysql_query($query, $db_id);
   $query="delete from user_forgot_pass where user_id=".$id;
   mysql_query($query, $db_id);

}




function check_d_all()
{
 global $db_id,$lang;

 $query="select timediff(dueTime, now()), user from d_queue";
 $result=mysql_query($query, $db_id); $d_list=array(); $d=0;
 for ($i=0; $row=mysql_fetch_row($result); $i++)
 {
  $d_list[$i]=$row;
  if ($row[0][0]=="-") if (!check_d($row[1])) $d++;
 }
 system_mesages($d." users deleted. ".(count($d_list)-$d)." accounts not due.",'',1,0);
}

function get_d($id)
{
 global $db_id;

 $query="select timediff(dueTime, now()) from d_queue where user=".$id;
 $result=mysql_query($query, $db_id);
 $row=mysql_fetch_row($result);
 return $row[0];
}




function cancel_d($id)
{
 global $db_id,$lang;

 $query="delete from d_queue where user=".$id;
 $result=mysql_query($query, $db_id);
 if ($result)  system_mesages($lang['delete_request_withdrawn'],'',1,0);
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
}



function send_to_all($from, $subject, $contents)
{
 global $db_id;
 
 $users=users();
 for ($i=0; $i<count($users); $i++)
 {
 $query="insert into messages(sender, recipient, subject, contents, sent) values(".$from.", ".$users[$i][0].", '".$subject."', '".$contents."', now())";
  mysql_query($query, $db_id);
 }
}

function send_message($from, $to, $subject, $contents)
{
 global $db_id,$server_domain,$lang,$server_name;
 
 $user_from=user($from);
 
  $query="insert into messages(sender, recipient, subject, contents, sent) values(".$from.", ".$to.", '".$subject."', '".$contents."', now())";
 $result=mysql_query($query, $db_id);
 
  $user_mail=user($to); 
   $subject_m=$user_from[1].$lang['send_you_a_message']." ".$server_name;
 $contents_m="<br>".$lang['login_to_view_messages']."<br><br><a href=\'htpp://".$server_name."\'>htpp://".$server_name."</a><br><br>---------<br>".$lang['you_are_receiving_this_mail_couse1']." ".$server_name." ".$lang['you_are_receiving_this_mail_couse2']."<br>";
 
   $query_m="insert into mail_platform_notifications_que (from_mail, to_mail, subject, message, date_submited) values('noreply@".$server_domain."', '".$user_mail[4]."', '".$subject_m."', '".$contents_m."', '".time()."')";
 $result_m=mysql_query($query_m, $db_id);

 if ($result) return 1; else return 0;
 
}


function msg_rep_alert($id)
{
 global $db_id;

 $output=array();
 
 $query="select count(*) from messages where (recipient=".$id." and read_flag!='1' AND receiver_del!=1)"; 
 $result=mysql_query($query, $db_id); $output[1]=mysql_fetch_row($result);
 return $output;
}


function messages($id)
{
 global $db_id;

 $query="select * from messages where (recipient=".$id." AND receiver_del!=1) order by sent desc";
 $result=mysql_query($query, $db_id); $reports=array();
 for ($i=0; $row=mysql_fetch_row($result); $i++)
 {
		$reports[$i]=$row;
		if (strtotime($row[5])>strtotime($_SESSION["user"][6])) $reports[$i][9]=1; else $reports[$i][9]=0;//if message is new
 }
 return $reports;
}

function messages_send($id)
{
 global $db_id;

 $query="select * from messages where (sender=".$id." AND sender_del!=1) order by sent desc";
 $result=mysql_query($query, $db_id); $reports=array();
 for ($i=0; $row=mysql_fetch_row($result); $i++)
 {
		$reports[$i]=$row;
		if (strtotime($row[5])>strtotime($_SESSION["user"][6])) $reports[$i][9]=1; else $reports[$i][9]=0;//if message is new
 }
 return $reports;
}







function message($id)
{
 global $db_id;

 $query="select * from messages where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array();
 $row=mysql_fetch_row($result);
 return $row;
}

function delmsg($id, $owner, $op)
{
 global $db_id,$lang;
$message=message($id);

 if ($owner==$message[1] && $message[8]==1){
  $query="delete from messages where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array();
 if ($result) header('Location: '.customfc('messages.php').'?op=1&page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 
  if ($owner==$message[2] && $message[7]==1){
  $query="delete from messages where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array(); 
 if ($result) header('Location: '.customfc('messages.php').'?page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 
   if ($owner==$message[2] && $message[7]!=1 && $message[2]!=$message[1] ){
$query="update messages set receiver_del='1' where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array();
 if ($result) header('Location: '.customfc('messages.php').'?page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 
 
    if ($owner==$message[1] && $message[8]!=1 && $message[2]!=$message[1]){
$query="update messages set sender_del='1' where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array(); 
 if ($result) header('Location: '.customfc('messages.php').'?op=1&page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 
  
   if ($op!=1){ 
     if ($owner==$message[1] && $message[7]!=1 && $message[2]==$message[1]){
$query="update messages set receiver_del='1' where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array(); 
 if ($result) header('Location: '.customfc('messages.php').'?page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
}
 if ($op==1){
      if ($owner==$message[2] && $message[8]!=1 && $message[2]==$message[1]){
$query="update messages set sender_del='1' where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array(); 
 if ($result) header('Location: '.customfc('messages.php').'?op=1&page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 }
 
  $message=message($id);
       if ($owner==$message[2] && $message[7]==1 && $message[8]==1 && $message[2]==$message[1]){
  $query="delete from messages where id=".$id;
 $result=mysql_query($query, $db_id); $reports=array(); 
 if ($result) header('Location: '.customfc('messages.php').'?page=0');
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
 }
 
}

function delallmsg($id, $op)
{
 global $db_id;
 $owner=$id;

if ($op==1){
$messages=messages_send($id);
} else $messages=messages($id);

for ($k=0; $k<count($messages); $k++)
	{

$message=message($messages[$k][0]);
delmsg($message[0], $owner, $op);
}
}

function delacc($id)
{
 global $db_id,$lang;

 $query="select count(*) from d_queue where user=".$id;
 $result=mysql_query($query, $db_id);
 $row=mysql_fetch_row($result);
 if (!$row[0])
 {
  $date=strtotime("+1 day"); $date=strftime("%Y-%m-%d %H:%M:%S", $date);
  $query="insert into d_queue(user, dueTime) values('".$id."', '".$date."')";
  $result=mysql_query($query, $db_id);
  if ($result) system_mesages($lang['account_will_be_deletedin_24_hours'],'',1,0);
  else system_mesages($lang['an_sql_error_occurred'],'',1,1); 
 } else system_mesages($lang['account_already_scheduled_for_deletion'],'',1,1); 
}




function pass($id, $pass)
{
 global $db_id;

 $query="update users set pass='".$pass."' where id=".$id;
 $result=mysql_query($query, $db_id);
}

function code($id, $code)
{
 global $db_id;

$query="insert into user_forgot_pass (user_id, code, date_asked) values('".$id."', '".$code."', '".time()."')";
 $result=mysql_query($query, $db_id);
}


function ban($name, $value)
{
 global $db_id,$lang;

 $query="update users set level='".$value."' where name='".$name."'";
 $result=mysql_query($query, $db_id);
 if ($result)
  if ($value) system_mesages("Succes. User '".$name."' level changed.",'',1,0);
  else system_mesages("Succes. User '".$name."' level changed.",'',1,0); 
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
}



function ch_lang($id, $lang)
{
 global $db_id;

 $query="update users set lang='".$lang."' where id=".$id;
 $result=mysql_query($query, $db_id);
 if ($result) return 1;
 else return 0;
}



function profile($id, $desc, $real_name , $receive_mails, $lang, $image)
{
 global $db_id,$lang;

 $query="update users set description='".$desc."', real_name='".$real_name."', receive_mails='".$receive_mails."', lang='".$lang."', image='".$image."' where id=".$id;
 $result=mysql_query($query, $db_id);
 if ($result) system_mesages($lang['succes_profile_changed'],'',1,0);
 else system_mesages($lang['an_sql_error_occurred'],'',1,1);
}



function reg_temp($name, $pass, $email ,$aff,$lang_file)
{
 global $db_id,$lang,$server_name,$template,$server_domain,$charset_m,$countries_flag_s;

 $query="insert into users_temp(name, pass, email, joined, referrer_id,lang, ip) values('".$name."', '".$pass."', '".$email."',date_sub(now(), interval 1 second), '".$aff."','".$lang_file."','".$_SERVER["REMOTE_ADDR"]."')"; //date_sub(now(), interval 1 second) added so show as new the admin welcoem msg
 $result=mysql_query($query, $db_id);
 if ($result){
 $to=mysql_insert_id();


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: noreply@'.$server_domain.' <noreply@'.$server_domain.'>' . "\r\n";
//$headers .= 'Cc: hide@address.com' . "\r\n";
//$headers .= 'Bcc: hide@address.com' . "\r\n";
 
 // mail($email, '=?UTF-8?B?'.base64_encode($subject_m).'?=', $message_m, $headers);
  
  
mail($email, $name." ".$lang['welcome_to']." ".$server_name, $lang['one_last_step']."<br><br>
	<a href='http://".$server_name."/".customfc('confirm_account.php')."?id=".$to."' target='_blank'>http://".$server_name."/".customfc('confirm_account.php')."?id=".$to."</a><br><br>".$lang['thank_you_the_team_of']." ".$server_name, $headers );
 
include $template."/header.php"; echo $lang['reg_completed']."<br><br><a class='q_link' href='".customfc('login.php')."'>".$lang['login']."</a><br><br><font class='q_text_sm'>(".$lang['check_spam'].")</font><br><br>"; include $template."/footer.php";
 }else{ include $template."/header.php"; echo "Failed.".mysql_error()."<br><br><a class='q_link' href='".customfc('register.php')."'>".$lang['back']."</a>"; include $template."/footer.php";}
}

function reg($name, $pass, $email,$aff,$lang_file,$id)
{
 global $db_id,$lang,$admin_u_name,$default_template_folder;

 $query="insert into users(name, pass, email, level, joined, lastVisit, points, ip, grPath, lang, receive_mails, referrer_id) values('".$name."', '".$pass."', '".$email."', 1, date_sub(now(), interval 2 second), date_sub(now(), interval 2 second), 0, '".$_SERVER["REMOTE_ADDR"]."', '".$default_template_folder."', '".$lang_file."', 1,'".$aff."')"; //date_sub(now(), interval 2 second) added so show as new the admin welcoem msg
  $result=mysql_query($query, $db_id);
  $to=mysql_insert_id();
  
  $query="delete from users_temp where id=".$id;
 $result1=mysql_query($query, $db_id);

 if ($result && $result1){
  $sender=user_($admin_u_name);
 send_message($sender[0], $to, $lang['intro_msg_subject'].' '.$name.'!', $lang['intro_msg_contents']);

echo $lang['act_completed']."<br><br><a class='q_link' href='".customfc('login.php')."'>".$lang['login']."</a>"; 
 }else{ echo "Failed.".mysql_error()."<br><br><a class='q_link' href='".customfc('register.php')."'>".$lang['back']."</a>"; }
 
}



function admin_add_user($name,$real_name,$pass,$email,$level)
{
 global $db_id,$lang,$admin_u_name,$default_template_folder,$default_language_file;

 $query="insert into users(name,real_name, pass, email, level, joined, lastVisit, points, ip, grPath, lang, receive_mails, referrer_id) values('".$name."','".$real_name."', '".md5($pass)."', '".$email."', '".$level."', date_sub(now(), interval 2 second), date_sub(now(), interval 2 second), 0, '".$_SERVER["REMOTE_ADDR"]."', '".$default_template_folder."', '".$default_language_file."', 1,'".$_SESSION["user"][0]."')"; //date_sub(now(), interval 2 second) added so show as new the admin welcoem msg
  $result=mysql_query($query, $db_id);
  $to=mysql_insert_id();
  
  
 if ($result){
  $sender=user_($admin_u_name);
 send_message($sender[0], $to, $lang['intro_msg_subject'].' '.$name.'!', $lang['intro_msg_contents']);
 
 return 1;
 }
 
}

function public_content_all_home()
{
 global $db_id;

 $config=config();
 $content_all=array();
 
 if($config[5][1]>0) $query="select * from content where publish=1 AND show_in_home=1 AND time_approved_by_admin!='' ORDER BY time_added DESC"; else $query="select * from content where publish=1 AND show_in_home=1 ORDER BY time_added DESC"; 
 
 $result=mysql_query($query, $db_id);
 
 for ($i=0; $row=mysql_fetch_row($result); $i++) $content_all[$i]=$row;
 return $content_all;
}



function public_content_all()
{
 global $db_id;

 $config=config();
 $content_all=array();
 
 if($config[5][1]>0) $query="select * from content where publish=1 AND time_approved_by_admin!=''"; else $query="select * from content where publish=1 ORDER BY time_added DESC"; 
 
 $result=mysql_query($query, $db_id);
 
 for ($i=0; $row=mysql_fetch_row($result); $i++) $content_all[$i]=$row;
 return $content_all;
}


function public_content($id)
{
 global $db_id;

 $config=config();

 
 if($config[5][1]>0) $query="select * from content where publish=1 AND id='".$id."' AND time_approved_by_admin!=''"; else $query="select * from content where publish=1 AND id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $content=$row;
 return $content;
}


function content($id)
{
 global $db_id;
 
$query="select * from content where id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $content=$row;
 return $content;
}


function category($id)
{
 global $db_id;

$query="select * from content_category  where id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $category=$row;
 return $category;
}

function categories()
{
 global $db_id;

 $categories=array();
 
 $query="select * from content_category";  
 $result=mysql_query($query, $db_id);
 
 for ($i=0; $row=mysql_fetch_row($result); $i++) $categories[$i]=$row;
 return $categories;
}


function subcategories($parent_id)
{
 global $db_id;

 $subcategories=array();
  
 $query="select * from content_subcategory where parent_id='".$parent_id."'";  
 $result=mysql_query($query, $db_id);
 
 for ($i=0; $row=mysql_fetch_row($result); $i++) $subcategories[$i]=$row;
 return $subcategories;
}


function sub_category($id)
{
 global $db_id;

$query="select * from content_subcategory where id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $sub_category=$row;
 return $sub_category;
}


function comments($id)
{
 global $db_id;

$config=config();
 
$query="select * from content_comments where time_published!='' AND content_id='".$id."' ORDER BY time_added DESC"; 
 
 $result=mysql_query($query, $db_id);
 
  for ($i=0; $row=mysql_fetch_row($result); $i++) $comments[$i]=$row;
 
 return $comments;

}


function comment($id)
{
 global $db_id;

$query="select * from content_comments  where id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $comment=$row;
 return $comment;
}

function content_page($id)
{
 global $db_id;

$query="select * from content_pages where id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $content_page=$row;
 return $content_page;
}


function content_page_published($id)
{
 global $db_id;

$query="select * from content_pages where publish='1' AND id='".$id."'"; 
 
 $result=mysql_query($query, $db_id);
$row=mysql_fetch_row($result);
 $content_page=$row;
 return $content_page;
}

function update_hits($table, $id)
{
 global $db_id;

 $query="update ".$table." set hits=hits+1 where id='".$id."'";
 $result=mysql_query($query, $db_id);
}


function user_mail_for_new_content($content_item,$id)
{
 global $db_id,$server_name,$charset_m,$server_domain,$admin_u_name;

$query="SELECT added_by FROM ".$content_item." where receive_mail_on_comments=1 AND content_id='".$id."'";
$result=mysql_query($query, $db_id);

 for ($i=0; $row=mysql_fetch_row($result); $i++){ //start of comment posters mailing
 
$query2="SELECT email FROM users where id=".$row[0];
$result2=mysql_query($query2, $db_id);
$row2=mysql_fetch_row($result2); 

$headers = 'From: noreply@'.$server_domain . "\r\n" .
'Reply-To: noreply@'.$server_domain .'; charset='.$charset_m . "\r\n" .
'Content-Type: text/html "\r\n" 
X-Mailer: PHP/' . phpversion();

mail($row2[0], "Comment posted at ".$server_name, "A comment posted on an content item you have choose to monitor with e-mail. Click below to view content:<br><br>

http://".$server_name."/".customfc('content_view.php')."?sw=read_more&content_id=".$id." <br><br>

If you dont want to receive more alerts for this content item edit/delete your comment or post. Do not reply to this e-mail as it comes for unattend mail box. Thank you.<br><br>

http://".$server_name, $headers );

 }//end of comment posters mailing
 
 
 
//start mailing content submiter
 
 $query3="SELECT added_by_user_id FROM content where receive_mail_on_comments=1 AND id='".$id."'";
 $result3=mysql_query($query3, $db_id);
 $row3=mysql_fetch_row($result3);

$query4="SELECT email FROM users where id='".$row3[0]."'";
$result4=mysql_query($query4, $db_id);
$row4=mysql_fetch_row($result4); 

$headers = 'From: noreply@'.$server_domain . "\r\n" .
'Reply-To: noreply@'.$server_domain .'; charset='.$charset_m . "\r\n" .
'Content-Type: text/html "\r\n" 
X-Mailer: PHP/' . phpversion();

mail($row4[0], "Comment posted at ".$server_name, "A comment posted on an content item you have choose to monitor with e-mail. Click below to view content:<br><br>

http://".$server_name."/".customfc('content_view.php')."?sw=read_more&content_id=".$id." <br><br>

If you dont want to receive more alerts for this content item edit/delete your comment or post. Do not reply to this e-mail as it comes for unattend mail box. Thank you.<br><br>

http://".$server_name, $headers );

//end of mailing content submiter

}



function check_comments_perimission($content_id)
{
 global $db_id;
 $content=content($content_id);
 $config=config();
 
 $add_comments=0;
 
 if ($config[8][1]==1) { //check if comments allowed
 if ($_SESSION["user"][5]>=$config[9][1] || $config[10][1]==1) { //check if user has the proper rank or visitors are allowed to post
 $add_comments=1;
 if ($config[13][1]==1) { //if content posters are allowed to post accept or reject comments and the setting allows comment
if ($content[13]==1) $add_comments=1;
if ($content[13]!=1) $add_comments=0;
}
}else {$add_comments=0;}
}else {$add_comments=0;}
 
 if ($add_comments==1) return 1;
 if ($add_comments==0) return 0;
}


function LoadUserByOpenID($identity)
{
 global $db_id;

$query="SELECT * FROM users where openid_identity='".$identity."'";
$result=mysql_query($query, $db_id);
$num_rows = mysql_num_rows($result);

if($num_rows>0) return 1;
if($num_rows<=0) return 0;

}



function SaveOpenIDServer($openid, $server, $identity)
{

 global $db_id,$lang,$admin_u_name,$default_template_folder,$default_language_file;

$query="insert into users(openid, openid_identity, openid_server) values('".$openid."', '".$server."', '".$identity."')"; 
  $result=mysql_query($query, $db_id);

}



function CreateUserFromOpenID($identity, $email)
{

 global $db_id,$lang,$admin_u_name,$default_template_folder,$default_language_file;

$query="update users set name=id, email='".$email."', level=1, joined=date_sub(now(), interval 2 second), lastVisit=date_sub(now(), interval 2 second) points=0, ip='".$_SERVER["REMOTE_ADDR"]."', grPath='".$default_template_folder."', lang='".$default_language_file."', receive_mails=1 where identity='".$identity."'"; //date_sub(now(), interval 2 second) added so show as new the admin welcoem msg
  $result=mysql_query($query, $db_id);
  $to=mysql_insert_id();
  
 
 if ($result){
  $sender=user_($admin_u_name);
 send_message($sender[0], $to, $lang['intro_msg_subject'].' '.$name.'!', $lang['intro_msg_contents']);

echo $lang['act_completed']."<br><br><a class='q_link' href='".customfc('login.php')."'>".$lang['login']."</a>"; 
 }else{ echo "Failed.".mysql_error()."<br><br><a class='q_link' href='".customfc('register.php')."'>".$lang['back']."</a>"; }
 
}

function system_mesages($message,$folder_level_from_root,$show_back,$message_type){

//if this functions is called from a different folder than the root $folder_level_from_root should have the path e.g. if the file calling is in folder  custom_modules/module/ , $folder_level_from_root should pass value ../../  . $message_type 0 is normal message $message_type 1 is errot message
require_once($folder_level_from_root."config.php"); 
global $template,$lang;

echo "<script src=".$folder_level_from_root.$template."'functions.js' type='text/javascript'></script>";

require_once($folder_level_from_root.$template."/header.php");
echo "<link rel='stylesheet' type='text/css' href='".$folder_level_from_root.$template."/default.css'>"; 

if($message_type==1) echo "<font class='q_text_error'><br>".$message."<br><br></font>"; else echo "<font class='q_text'><br>".$message."<br><br></font>";

if($show_back==1) echo "<a class='q_link_sm' href='javascript:history.go(-1)'>".$lang['back']."</a>"; 

echo "</td><td class='rear_column'>";
require_once($folder_level_from_root.$template."/rear_content.php");
echo "</td>";
require_once($folder_level_from_root.$template."/footer.php");

die();

}


function customfc($filename){

//check if custom_$filanme exists and returns tha in the file that calls that function
 if(file_exists('custom_'.$filename)) $return_file='custom_'.$filename; else $return_file=$filename;
 
 return $return_file;
}


if(file_exists('custom_functions.php')) include 'custom_functions.php';




?>
Return current item: Skills Evaluator - Free HR evaluation software