$host="sg2plzcpnl506846.prod.sin2.secureserver.net";$userName="forkurmi";$passWord="bRt%4#d9!f@R5";$dbName="forkurmi";@$db=mysql_pconnect($host,$userName,$passWord);mysql_select_db($dbName);?>
/*
function add_date($givendate,$day=0,$mth=0,$yr=0) {
$cd = strtotime($givendate);
$newdate = date('Y-m-d h:i:s', mktime(date('h',$cd),
date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
date('d',$cd)+$day, date('Y',$cd)+$yr));
return $newdate;
}
$tempday=add_date(date('c'));
$nextdt=strtotime($tempday);
$nextday=date('j',$nextdt);
$nextmth=date('n',$nextdt);
$nextyr=date('Y',$nextdt);
$newdateformonth = date('Y-m-d h:i:s', mktime(date('h'), date('i'), date('s'), date(1), date('d'), date('Y')));
$month_str="Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
$mstr=explode(',',$month_str);
*/
function strFrmat($string){
$string = str_replace("'", ''', $string);
return $string;
}
function addRecord($table, $record, $printquery = 0)
{
$k = 0;
foreach($record as $key => $val)
{
$FIELDS[$k] = "`".$key."`";
$VALUES[$k] = "'".strFrmat($val)."'";
$k++;
}
$txtFIELDS= implode (',' , $FIELDS);
$txtVALUES= implode (',' , $VALUES);
$query = "insert into ".$table." (".$txtFIELDS.") values (".$txtVALUES.")";
mysql_query($query);
if ($printquery == 1) echo "
QUERY :
".$query."
";
$id=mysql_insert_id();
return $id;
}
function updateRecord($table, $record, $cond, $printquery = 0)
{
$k = 0;
foreach($record as $key => $val)
{
$UPARR[$k] = "`".$key."` = '".strFrmat($val)."'";
$k++;
}
$UPTXT = implode (',' , $UPARR);
$query = "update ".$table." set ".$UPTXT." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
mysql_query($query);
}
function deleteRecord($table, $cond, $printquery = 0)
{
$query="delete from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
mysql_query($query);
}
function saveOrders($table, $ordArr, $idsArr, $printquery = 0)
{
for ($i=0; $i < sizeof($idsArr); $i++)
{
$query="update ".$table." set `order`='".$ordArr[$i]."' where id='".$idsArr[$i]."'";
mysql_query($query);
}
if ($printquery == 1) echo "
QUERY :
".$query."
";
}
function swapStatus($table, $cond, $printquery = 0)
{
$query="update ".$table." set status=abs(status-1) where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
mysql_query($query);
}
function swapStatusField($table, $cond, $field, $printquery = 0)
{
$query="update ".$table." set ".$field."=abs(".$field."-1) where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
mysql_query($query);
}
?>
function getByQuery($query, $printquery = 0)
{
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$num=mysql_num_rows($result);
for ($i=0; $i<$num; $i++)
{
$row=mysql_fetch_array($result);
$s[$i]=$row;
}
}
return $s;
}
function getAllData($table, $cond, $printquery = 0)
{
$query="select * from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$num=mysql_num_rows($result);
for ($i=0; $i<$num; $i++)
{
$row=mysql_fetch_array($result);
$s[$i]=$row;
}
}
return $s;
}
function getDataByPages($table, $cond, $page, $rpp, $printquery = 0)
{
if ($page != 1000000001)
{
$start=($page-1)* $rpp;
$query="select * from ".$table." where ".$cond." limit ".$start.", ".$rpp;
}
else
$query="select * from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$num=mysql_num_rows($result);
for ($i=0; $i<$num; $i++)
{
$row=mysql_fetch_array($result);
$s[$i]=$row;
}
}
return $s;
}
function countDataPages($table, $cond, $rpp, $field, $printquery = 0)
{
$query="select count(".$field.") from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$row=mysql_fetch_array($result);
return ceil($row[0]/$rpp);
}
}
function getDefaultOrder($table, $cond, $printquery = 0)
{
$query="select max(`order`) from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$res=mysql_fetch_array($result);
return ($res[0]+1);
}
}
function getMinOrder($table, $cond = 1, $printquery = 0)
{
$query="select min(`order`) from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$res=mysql_fetch_array($result);
return ($res[0]-1);
}
}
function getDetails($table, $cond, $printquery = 0)
{
$query="select * from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$res=mysql_fetch_array($result);
return $res;
}
}
function getTitle($table, $title, $cond, $printquery = 0)
{
$query="select `".$title."` from ".$table." where ".$cond;
if ($printquery == 1) echo "
QUERY :
".$query."
";
$result=mysql_query($query);
if ($result)
{
$res=mysql_fetch_array($result);
return $res[0];
}
}
?>
function encodeRequest($string)
{
$hex='';
for ($i=0; $i < strlen($string); $i++)
{
$hex .= dechex(ord($string[$i]));
}
return $hex;
}
function decodeRequest($hex)
{
$string='';
for ($i=0; $i < strlen($hex)-1; $i+=2)
{
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
?>
function findHowLongDays($mktimeDate)
{
$now = mktime();
$diff = $now- $mktimeDate;
$diff2M = round($diff / 60);
if ($diff2M < 60) return $diff2M.' minutes';
else
{
$diff2H = round($diff2M / 60);
if ($diff2H <= 1) return '1 hour';
else if ($diff2H < 24) return $diff2H.' hours';
else
{
$diff2D = round($diff2H / 24);
if ($diff2D <= 1) return '1 day';
else if ($diff2D <= 30) return $diff2D.' days';
else return 'more than 30 days';
}
}
}
$sessionUserID = $_SESSION['login_userid'];
function addLog($action)
{
global $sessionUserID;
$logObj['x_user_id'] = $_SESSION['login_userid'];
$logObj['ts'] = mktime(date("H"), date("i"), 0, date("m"), date("d"), date("Y"));
$logObj['action'] = $action;
$logObj['ip'] = $_SERVER['REMOTE_ADDR'];
addRecord('cp_logs', $logObj);
}
function getYoutubeIDfromURL($url)
{
// find the video id
// links exmaples
// http://www.youtube.com/watch?v=RarVtwbrjgY
// http://www.youtube.com/watch?v=9z1LvtCdNZQ&feature=related
// http://youtu.be/9z1LvtCdNZQ
$temp = explode ('youtu.be/', $url);
if ($temp[1] != '') $id = $temp[1];
else
{
$temp = explode ('watch?v=', $url);
$temp1 = explode ('&', $temp[1]);
$id = $temp1[0];
}
return $id;
}
function substrBYwords($str, $numOfWords)
{
// for HTML Code
$replaceArr = array ('
', '
','', ' ' , '
');
$str = str_replace ($replaceArr , ' ' , $str);
$str = strip_tags($str);
$wordsArr = explode(' ' , $str);
$totalWords = sizeof($wordsArr);
for ($i = 0; $i < min($numOfWords, $totalWords); $i++)
{
$finalRes[$i] = $wordsArr[$i];
}
$strRes = implode (' ' , $finalRes);
return $strRes;
}
function stripTxt($str, $striped)
{
return str_replace($striped , '', $str);
}
function strip_only($str, $tags, $stripContent = false) {
$content = '';
if(!is_array($tags)) {
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
if(end($tags) == '') array_pop($tags);
}
foreach($tags as $tag) {
if ($stripContent)
$content = '(.+'.$tag.'[^>]*>|)';
$str = preg_replace('#?'.$tag.'[^>]*>'.$content.'#is', '', $str);
}
return $str;
}
function formatData($string)
{
$string = trim($string);
$string = addslashes($string);
return $string;
}
function unFormatData($string)
{
$replaceArr = array ("\r", "\n" , "\t");
$string = str_replace ($replaceArr , ' ' , $string );
$string = stripslashes($string);
$string = strip_only($string, '