"; $sqlQry=mysqli_query($dbcon2,$sql) OR die(mysqli_error($dbcon2)); return $sqlQry; } // db_query: Updated 10 oct 2006 function db_fetch_array($rs) { $array = mysqli_fetch_array($rs,MYSQLI_ASSOC); return $array; } // db_scalar: Updated 31 may 2006 function db_scalar($sql, $dbcon2 = null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $result = db_query($sql, $dbcon2); if ($line = mysqli_fetch_array($result,MYSQLI_ASSOC)) { $response = $line[0]; } return $response; } // db_scalar: Updated 31 may 2006 function getSingleresult($sql, $dbcon2 = null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $result = db_query($sql, $dbcon2); if ($line = mysqli_fetch_array($result,MYSQLI_NUM)) { $response = $line[0]; } return $response; } // db_error: Updated 2 sep 2006 // Now it redirects to a file to show sql error. function db_error($sql) { echo "

".mysql_error()."
"; print_error(); if(LOCAL_MODE) { echo "
sql: $sql"; } echo "
"; } function print_error() { $debug_backtrace = debug_backtrace(); for ($i = 1; $i < count($debug_backtrace); $i++) { $error = $debug_backtrace[$i]; echo "
"; echo "
"; echo "File: ".str_replace(SITE_FS_PATH, '',$error['file'])."
"; echo "Line: ".$error['line']."
"; echo "Function: ".$error['function']."
"; //echo "Args: "; //foreach($error['args'] as $arg) { // echo "$arg
"; //} echo "
"; } } // mysql_time: Updated 31 may 2006 function mysql_time($hour, $minute, $ampm) { if ($ampm == 'PM' && $hour != '12') { $hour += 12; } if ($ampm == 'AM' && $hour == '12') { $hour = '00'; } $mysql_time = $hour . ':' . $minute . ':00'; return $mysql_time; } // price_format: Updated 31 may 2006 function price_format($price) { if ($price != '' && $price != '0') { $price = number_format($price, 2); return '$'.$price; } } // date_format: Updated 31 may 2006 function opin_date_format($date) { if (strlen($date) >= 10) { if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00') { return ''; } $mktime = mktime(0, 0, 0, substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4)); return date("M j, Y", $mktime); } else { return $s; } } // datetime_format: Updated 31 may 2006 function datetime_format($date) { global $arr_month_short; if (strlen($date) >= 10) { if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00') { return ''; } $mktime = mktime(substr($date, 11, 2), substr($date, 14, 2), substr($date, 17, 2),substr($date, 5, 2), substr($date, 8, 2), substr($date, 0, 4)); return date("M j, Y h:i A ", $mktime); } else { return $s; } } // time_format: Updated 31 may 2006 function time_format($time) { if (strlen($time) >= 5) { $hour = substr($time, 0, 2); $hour = str_pad($hour, 2, "0", STR_PAD_LEFT); return $hour . ':' . substr($time, 3, 2) . ' ' . $ampm; } else { return $s; } } // ms_print_r: Updated 31 may 2006 function ms_print_r($var) { //if(LOCAL_MODE || $_SESSION['debug']){ echo ""; //} } // ms_form_value: Updated 31 may 2006 function ms_form_value($var) { return is_array($var) ? array_map('ms_form_value', $var) : htmlspecialchars(stripslashes(trim($var))); } // ms_display_value: Updated 31 may 2006 function ms_display_value($var) { return is_array($var) ? array_map('ms_display_value', $var) : nl2br(htmlspecialchars(stripslashes(trim($var)))); } function ms_adds($var) { return trim(addslashes(stripslashes($var))); } // ms_stripslashes: Updated 31 may 2006 function ms_stripslashes($var) { return is_array($var) ? array_map('ms_stripslashes', $var) : stripslashes(trim($var)); } // ms_addslashes: Updated 31 may 2006 function ms_addslashes($var) { return is_array($var) ? array_map('ms_addslashes', $var) : addslashes(stripslashes(trim($var))); } // ms_trim: Updated 31 may 2006 function ms_trim($var) { return is_array($var) ? array_map('ms_trim', $var) : trim($var); } // is_image_valid: Updated 31 may 2006 function is_image_valid($file_name) { global $ARR_VALID_IMG_EXTS; $ext = file_ext($file_name); if (in_array($ext, $ARR_VALID_IMG_EXTS)) { return true; } else { return false; } } // getmicrotime: Updated 31 may 2006 function getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } // file_ext: Updated 31 may 2006 function file_ext($file_name) { $path_parts = pathinfo($file_name); $ext = strtolower($path_parts["extension"]); return $ext; } // blank_filter: Updated 31 may 2006 function blank_filter($var) { $var = trim($var); return ($var != '' && $var != ' '); } // apply_filter: Updated 25 sep 2006 function apply_filter($sql, $field, $field_filter, $column) { if (!empty($field)) { if ($field_filter == "=" || $field_filter == "") { $sql = $sql . " and $column = '$field' "; } else if ($field_filter == "like") { $sql = $sql . " and $column like '%$field%' "; } else if ($field_filter == "starts_with") { $sql = $sql . " and $column like '$field%' "; } else if ($field_filter == "ends_with") { $sql = $sql . " and $column like '%$field' "; } else if ($field_filter == "not_contains") { $sql = $sql . " and $column not like '%$field%' "; } else if ($field_filter == ">") { $sql = $sql . " and $column > '$field' "; } else if ($field_filter == "<") { $sql = $sql . " and $column < '$field' "; } else if ($field_filter == "!=") { $sql = $sql . " and $column != '$field' "; } } return $sql; } // filter_dropdown: Updated 17 July 2006 // Should replace older version function function filter_dropdown($name = 'filter', $sel_value) { $arr = array( "like" => 'Contains', '=' => 'Is', "starts_with" => 'Starts with', "ends_with" => 'Ends with', "!=" => 'Is not' , "not_contains" => 'Not contains'); return array_dropdown($arr, $sel_value, $name); } // move_up: Updated 31 may 2006 function move_up($table_name, $where_clause_all, $where_clause_item, $sort_order, $move_by) { $dest_order = $sort_order - $move_by; // $arr_ids_to_move=Array(); // echo "
$movie_artist_id, $movie_id, $artistcate_id, $sort_order, $move_by, $dest_order
"; for($i = $sort_order-1; $i > $dest_order-1; $i--) { $sql = " update $table_name set sort_order=sort_order+1 where $where_clause_all and sort_order='$i'"; // echo "
$sql
"; db_query($sql); } $sql = " update $table_name set sort_order=sort_order-$move_by where $where_clause_item"; // echo "
$sql
"; db_query($sql); } // move_down: Updated 31 may 2006 function move_down($table_name, $where_clause_all, $where_clause_item, $sort_order, $move_by) { $dest_order = $sort_order + $move_by; // $arr_ids_to_move=Array(); // echo "
$movie_artist_id, $movie_id, $artistcate_id, $sort_order, $move_by, $dest_order
"; for($i = $sort_order + 1; $i < $dest_order + 1; $i++) { $sql = " update $table_name set sort_order=sort_order-1 where $where_clause_all and sort_order='$i' "; // echo "
$sql
"; db_query($sql); } $sql = " update $table_name set sort_order=sort_order+$move_by where $where_clause_item"; // echo "
$sql
"; db_query($sql); } // refine_list: Updated 31 may 2006 function refine_list($id_column, $table_name, $where_clause) { $sql = " select $id_column, sort_order from $table_name where $where_clause order by sort_order"; // echo "
$sql
"; $result = db_query($sql); $i = 1; while ($line = mysql_fetch_array($result)) { $sql = " update $table_name set sort_order='$i' where $id_column='$line[0]'"; // echo "
$sql
"; db_query($sql); $i++; } } // make_url: Updated 31 may 2006 function make_url($url) { $parsed_url = parse_url($url); if ($parsed_url['scheme'] == '') { return 'http://' . $url; } else { return $url; } } // ms_mail: Updated 31 may 2006 function ms_mail($to, $subject, $message, $arr_headers= array()) { $str_headers = ''; foreach($arr_headers as $name=>$value){ $str_headers .= "$name: $value\n"; } @mail($to, $subject, $message, $str_headers); return true; } // make_thumb_im: Updated 31 may 2006 function make_thumb_im($file_path, $arr_options) { $width = $arr_options['width']; $height = $arr_options['height']; $prefix = $arr_options['prefix']; $target_dir = $arr_options['target_dir']; $quality = $arr_options['quality']; $path_parts = pathinfo($file_path); if($width==''){ $width = '120'; } if($prefix=='') { $prefix = 'thumb_'; } if($target_dir=='') { $target_dir = $path_parts["dirname"]; } if($quality=='') { $quality = '70'; } $size = @getimagesize($file_path); if($size=='') { return false; } /* $ratio = round($width/$height, 2); $img_width = $size[0]; $img_height = $size[1]; */ $path_parts = pathinfo($file_path); $thumb_path="$target_dir/".$prefix.$path_parts["basename"]; $cmd ="convert -resize ".$width.'x'." -quality $quality \"$file_path\" \"$thumb_path\" "; system($cmd); //echo("
$cmd"); return $prefix.$path_parts["basename"]; } // date_to_mysql: Updated 31 may 2006 function date_to_mysql($date) { list($month, $day, $year) = explode('/', $date); return "$year-$month-$day"; } // export_delimited_file: Updated 31 may 2006 function export_delimited_file($sql, $arr_columns, $file_name='', $arr_substitutes='', $arr_tpls='' ){ //session_cache_limiter('public'); //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Content-Type: application/force-download"); if($file_name=='') { $file_name = time().'.txt'; } header("Content-type: application/txt"); header("Content-Disposition: attachment; filename=$file_name"); $arr_db_cols= array_keys($arr_columns); $arr_headers= array_values($arr_columns); //ms_print_r($arr_columns); //ms_print_r($arr_db_cols); //ms_print_r($arr_headers); //ms_print_r($arr_headers); //ms_print_r($arr_headers); $str_columns = implode(',', $arr_db_cols); $sql= "select ".$str_columns." $sql" ; $result= db_query($sql); $num_cols = count($arr_columns); //$i=0; foreach($arr_headers as $header){ //$i++; echo $header."\t"; //if($i!=$num_cols){ // echo "\t"; //} } while($line=mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\r\n"; //echo("
"); foreach($line as $key => $value){ $value=str_replace("\n","",$value); $value=str_replace("\r","",$value); $value=str_replace("\t","",$value); if(is_array($arr_substitutes[$key])){ $value = $arr_substitutes[$key][$value]; } if(isset($arr_tpls[$key])){ $code = str_replace('{1}', $value, $arr_tpls[$key]); //echo ("\$value = $code;"); //echo("
"); eval ("\$value = $code;"); } echo $value."\t"; } } } // checkpoint: Updated 2 sep 2006 // to check how much time is lapsed before first call of this function function checkpoint($from_start = false) { global $PREV_CHECKPOINT; if($PREV_CHECKPOINT==''){ $PREV_CHECKPOINT = SCRIPT_START_TIME; } $cur_microtime = getmicrotime(); if($from_start) { return $cur_microtime - SCRIPT_START_TIME; } else { $time_taken = $cur_microtime - $PREV_CHECKPOINT; $PREV_CHECKPOINT = $cur_microtime; return $time_taken; } } // readable_col_name: Updated 31 may 2006 function readable_col_name($str) { return ucwords( str_replace('_', ' ', strtolower($str) ) ); } // ms_echo: Updated 31 may 2006 function ms_echo($str) { if(LOCAL_MODE){ echo($str); } } // make_dropdown: Updated 1 aug 2006 function make_dropdown($sql, $sel_value = '', $combo_name, $extra = '', $choose_one = '') { $result = db_query($sql); if (mysql_num_rows($result) > 0) { $str_dropdown = ""; } return $str_dropdown; } // array_dropdown: Updated 31 may 2006 function array_dropdown( $arr, $sel_value='', $name='', $extra='', $choose_one='', $arr_skip= array()) { $combo=" $value \n"; $j++; } } } $j--; // echo "$cols-($j%$cols)=".$cols-($j%$cols); // echo "
($j%$cols)=".($j%$cols); for($x = $j % $cols;$x < 4;$x++) { if ($x != 3) { $checkstr .= " \n"; } else { $checkstr .= " \n"; } } $checkstr .= ""; } return $checkstr; } // make_radios: Updated 31 may 2006 function make_radios($arr_tmp, $checkname, $checksel = '', $cols, $missit, $style = '', $tableattr = '') { if ($style != "") { $style = "class='" . $style . "'"; } $colwidth = 100 / $cols; $colwidth = round($colwidth, 2); $j = 1; /* $arr_tmp['Any']="Any"; if($checksel==''){ $checksel=Array("Any"); } */ foreach($arr_tmp as $key => $value) { $tochecked = ""; if ($checksel == $key) { $tochecked = "checked"; } if ($key != $missit) { if ($value != "") { if ($j == 1) { $checkstr .= "\n"; } else if (($j % $cols) == 1) { $checkstr .= "\n"; } $checkstr .= "\n"; $j++; } } } $j--; // echo "$cols-($j%$cols)=".$cols-($j%$cols); // echo "
($j%$cols)=".($j%$cols); for($x = $j % $cols;$x < 4;$x++) { if ($x != 3) { $checkstr .= "\n"; } else { $checkstr .= "\n"; } } $checkstr .= "
$value   
"; return $checkstr; } // date_dropdown: Updated 31 may 2006 function date_dropdown($pre, $selected_date = '', $start_year='', $end_year = '', $sort = 'asc') { $cur_date = date("Y-m-d"); $cur_date_day = substr($cur_date, 8, 2); $cur_date_month = substr($cur_date, 5, 2); $cur_date_year = substr($cur_date, 0, 4); if ($selected_date != '') { $selected_date_day = substr($selected_date, 8, 2); $selected_date_month = substr($selected_date, 5, 2); $selected_date_year = substr($selected_date, 0, 4); } $date_dropdown .= month_dropdown($pre . "month", $selected_date_month); $date_dropdown .= day_dropdown($pre . "day", $selected_date_day); // echo($pre . "year: ". $selected_date_year); $date_dropdown .= year_dropdown($pre . "year", $selected_date_year, $start_year, $end_year, $sort); return $date_dropdown; } // month_dropdown: Updated 31 may 2006 function month_dropdown($name, $selected_date_month = '', $extra='') { global $ARR_MONTHS; $date_dropdown = " "; return $date_dropdown; } // day_dropdown: Updated 31 may 2006 function day_dropdown($name, $selected_date_day = '', $extra='') { $date_dropdown .= ""; return $date_dropdown; } // year_dropdown: Updated 31 may 2006 function year_dropdown($name, $selected_date_year = '', $start_year = '', $end_year = '', $extra='') { if ($start_year == '') { $start_year = DEFAULT_START_YEAR; } if ($end_year == '') { $end_year = DEFAULT_END_YEAR; } $date_dropdown .= ""; return $date_dropdown; } // time_dropdown: Updated 31 may 2006 function time_dropdown($pre, $selected_time = '') { // echo("
selected_time:$selected_time"); if ($selected_time != '' && $selected_time != ':') { $selected_hour = substr($selected_time, 0, 2); $selected_minute = substr($selected_time, 3, 2); /* if($selected_hour >11){ $selected_ampm = "PM"; $selected_hour -= 12; }else{ $selected_ampm = "AM"; } if($selected_hour==0){ $selected_hour = 12; } */ } $str .= hour_dropdown($pre, $selected_hour); $str .= ':'; $str .= minute_dropdown($pre, $selected_minute); return $str; // echo "
$selected_hour, $selected_minute $selected_ampm
"; } // hour_dropdown: Updated 31 may 2006 function hour_dropdown($pre, $selected_hour ) { $str .= ""; return $str; } // minute_dropdown: Updated 31 may 2006 function minute_dropdown($pre, $selected_minute ) { $str .= ""; return $str; } // ampm_dropdown: Updated 31 may 2006 function ampm_dropdown($pre, $selected_ampm) { $str .= "'."\n"; } return $s; } // sql_to_array_file: Updated 31 may 2006 function sql_to_array_file($arr_name, $sql, $file, $full_table=false) { $str = "$value) { if(!is_numeric($name)) { $str .= '$'.$arr_name."['".$key."']['".$name."'] = '".$value."';\n"; } } $str .= "\n"; } else { $str .= '$'.$arr_name."['".$line[0]."'] = '".$line[1]."';\n"; } } $str .= "\n?>"; $fh = fopen($file, 'w'); fwrite($fh, $str); fclose($fh); return true; } // array_radios: Updated 31 may 2006 function array_radios($arr, $sel_value = '', $name = '', $cols = 3, $extra = '') { if ($style != "") { $style = "class='" . $style . "'"; } $colwidth = 100 / $cols; $colwidth = round($colwidth, 2); $j = 1; /* $arr_tmp['Any']="Any"; if($checksel==''){ $checksel=Array("Any"); } */ foreach($arr as $key => $value) { $tochecked = ""; if (is_array($sel_value) && in_array($key, $sel_value)) { $tochecked = "checked"; } if ($key != $missit) { if ($value != "") { if ($j == 1) { $checkstr .= "\n"; } else if (($j % $cols) == 1 || $cols==1) { $checkstr .= "\n"; } $checkstr .= "\n"; $j++; } } } $j--; // echo "$cols-($j%$cols)=".$cols-($j%$cols); // echo "
($j%$cols)=".($j%$cols); for($x = $j % $cols;$x < 4;$x++) { if ($x != 3) { $checkstr .= "\n"; } else { $checkstr .= "\n"; } } $checkstr .= "
$value   
"; return $checkstr; } // Updated 24 aug 2006 function make_thumb_gd($imgPath, $destPath, $newWidth, $newHeight, $ratio_type = 'width', $quality = 70, $verbose = false) { // options for ratio type = width|height|width_height|distort|crop // get image info (0 width and 1 height, 2 is (1 = GIF, 2 = JPG, 3 = PNG) $size = getimagesize($imgPath); // break and return false if failed to read image infos if (!$size) { if ($verbose) { echo "Unable to read image info."; } return false; } $curWidth = $size[0]; $curHeight = $size[1]; $fileType = $size[2]; // width/height ratio $ratio = $curWidth / $curHeight; $thumbRatio = $newWidth / $newHeight; $srcX = 0; $srcY = 0; $srcWidth = $curWidth; $srcHeight = $curHeight; if($ratio_type=='width_height') { $tmpWidth = $newHeight * $ratio; if($tmpWidth > $newWidth) { $ratio_type='width'; } else { $ratio_type='height'; } } if($ratio_type=='width') { // If the dimensions for thumbnails are greater than original image do not enlarge if($newWidth > $curWidth) { $newWidth = $curWidth; } $newHeight = $newWidth / $ratio; } else if($ratio_type=='height') { // If the dimensions for thumbnails are greater than original image do not enlarge if($newHeight > $curHeight) { $newHeight = $curHeight; } $newWidth = $newHeight * $ratio; } else if($ratio_type=='crop') { if($ratio < $thumbRatio) { $srcHeight = round($curHeight*$ratio/$thumbRatio); $srcY = round(($curHeight-$srcHeight)/2); } else { $srcWidth = round($curWidth*$thumbRatio/$ratio); $srcX = round(($curWidth-$srcWidth)/2); } /*echo "
curWidth: $curWidth"; echo "
curHeight: $curHeight"; echo "
newWidth: $newWidth"; echo "
newHeight: $newHeight"; echo "
ratio: $ratio"; echo "
thumbRatio: $thumbRatio"; echo "
srcWidth: $srcWidth"; echo "
srcX: $srcX"; echo "
srcHeight: $srcHeight"; echo "
srcY: $srcY";*/ } else if($ratio_type=='distort') { } // create image switch ($fileType) { case 1: if (function_exists("imagecreatefromgif")) { $originalImage = imagecreatefromgif($imgPath); } else { if ($verbose) { echo "GIF images are not support in this php installation."; return false; } } $fileExt = 'gif'; break; case 2: $originalImage = imagecreatefromjpeg($imgPath); $fileExt = 'jpg'; break; case 3: $originalImage = imagecreatefrompng($imgPath); $fileExt = 'png'; break; default: if ($verbose) { echo "Not a valid image type."; } return false; } // create new image $resizedImage = imagecreatetruecolor($newWidth, $newHeight); //echo "$srcX, $srcY, $newWidth, $newHeight, $curWidth, $curHeight"; //echo "
$srcX, $srcY, $newWidth, $newHeight, $srcWidth, $srcHeight
"; imagecopyresampled($resizedImage, $originalImage, 0, 0, $srcX, $srcY, $newWidth, $newHeight, $srcWidth, $srcHeight); imageinterlace($resizedImage, 1); switch ($fileExt) { case 'gif': imagegif($resizedImage, $destPath, $quality); break; case 'jpg': imagejpeg($resizedImage, $destPath, $quality); break; case 'png': imagepng($resizedImage, $destPath, $quality); break; } // return true if successfull return true; } // show_thumb: Updated 14 apr 2007 function show_thumbOld($file_org, $width, $height, $ratio_type = 'width') { $path_parts = pathinfo($file_org); /*$file_name = str_replace(SITE_WS_PATH."/", "", $file_org); $file_name = str_replace("/", "^", $file_name); $cache_file = $width."x".$height.'__'.$ratio_type .'__'.$file_name; $file_fs_path = str_replace(SITE_WS_PATH, SITE_FS_PATH, $file_org);*/ //$file_fs_path = str_replace(SITE_WS_PATH, SITE_FS_PATH, $file_org); $file_name = $path_parts['basename']; $file_name = str_replace("/", "^", $file_name); $cache_file = $width."x".$height.'__'.$ratio_type .'__'.$file_name; if(!is_file($path_parts['dirname']."/".$cache_file)) { make_thumb_gd($file_org, $path_parts['dirname']."/".$cache_file, $width, $height, $ratio_type ); } return $path_parts['dirname']."/".$cache_file; } function show_thumb($file_org, $width, $height, $ratio_type = 'width') { $file_name = str_replace(SITE_WS_PATH."/", "", $file_org); $file_name = str_replace("/", "^", $file_name); $cache_file = $width."x".$height.'__'.$ratio_type .'__'.$file_name; $file_fs_path = str_replace(SITE_WS_PATH, SITE_FS_PATH, $file_org); if(!is_file(SITE_FS_PATH."/".THUMB_CACHE_DIR."/".$cache_file)) { make_thumb_gd($file_fs_path, SITE_FS_PATH."/".THUMB_CACHE_DIR."/".$cache_file, $width, $height, $ratio_type ); } return SITE_WS_PATH.THUMB_CACHE_DIR."/".$cache_file; } // ms_parse_keywords: Updated 31 may 2006 // Temporary function. Need to be made more elegant or replace with regular expression function ms_parse_keywords($keywords) { $arr_keywords = array(); $dq_end =true; $sp_end = true; for ($i=0;$icur_token:$cur_token, cur_keyword:$cur_keyword, dq_start:$dq_start, dq_end:$dq_end, sp_start:$sp_start, sp_end:$sp_end,"; $cur_token = $keywords[$i]; if($cur_token=='"') { if($dq_start) { $dq_end = true; $dq_start = false; $arr_keywords[] = $cur_keyword; $cur_keyword = ''; } else if($dq_end) { $dq_end = false; $dq_start = true; $sp_start = false; } else { $dq_end = false; $dq_start = true; } } else if($cur_token==' ') { if($sp_start || $dq_end) { $sp_end = true; $sp_start = false; $arr_keywords[] = $cur_keyword; $cur_keyword = ''; } else if($sp_end && !$dq_start) { $sp_end = false; $sp_start = true; } else if($dq_start) { $cur_keyword .= $cur_token; } } else { $cur_keyword .= $cur_token; } } $arr_keywords[] =$cur_keyword; return $arr_keywords; } // pagesize_dropdown: Updated 31 may 2006 function pagesize_dropdown($name, $value) { $arr = array('1'=>'1','10'=>'10','25'=>'25','50'=>'50','100'=>'100'); $m = $_GET; unset($m['pagesize']); return array_dropdown($arr, $value , $name, ' onchange="location.href=\''.$_SERVER['PHP_SELF'].qry_str($m).'&pagesize=\'+this.value" '); } // sql_to_assoc_array: Updated 1 aug 2006 function sql_to_assoc_array($sql) { $arr = array(); $result = db_query($sql); while ($line = mysql_fetch_array($result)) { $line = ms_form_value($line); $arr[$line[0]] = $line[1]; } return $arr; } // sql_to_index_array: Updated 1 aug 2006 function sql_to_index_array($sql) { $arr = array(); $result = db_query($sql); while ($line = mysql_fetch_array($result)) { $line = ms_form_value($line); $arr[] = $line[0]; } return $arr; } // sql_to_array: Updated 1 aug 2006 function sql_to_array($sql) { $arr = array(); $result = db_query($sql); while ($line = mysql_fetch_array($result)) { $line = ms_form_value($line); array_push($arr, $line); } return $arr; } function qry_str_to_hidden($str) { $fields=''; if(substr($str,0,1)=='?') { $str = substr($str,1); } $arr = explode('&', $str); foreach($arr as $pair) { list($name, $value) = explode('=',$pair); if($name!='') { $fields.=''; } } return $fields; } // enum_to_array: Updated 14 sep 2006 function enum_to_array($table, $column) { $result = db_query("show fields from $table"); while ($line_raw = mysql_fetch_assoc($result)) { $line = ms_display_value($line_raw); if($line['Field']==$column) { $Type = $line['Type']; $Type = substr($Type,6,-2); $arr_tmp = explode("','", $Type); foreach($arr_tmp as $val) { $arr[$val]=$val; } return $arr; } } } function redir($url,$inpage=0) { if($inpage==0) { header('location: '.$url) or die("Cannot Send to next page"); exit; } else { echo ' ' ; exit; } } function sqlquery($rs='exe',$tablename,$arr,$update='',$id='',$update2='',$id2='') { $sql = db_query("DESC ".tb_Prefix."$tablename"); $row = mysqli_fetch_array($sql,MYSQLI_ASSOC); if($update == '') $makesql = "insert into "; else $makesql = "update " ; $makesql .= tb_Prefix."$tablename set "; $i = 1; while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) { if(array_key_exists($row['Field'], $arr)) { if($i != 1) $makesql .= ", "; $makesql .= $row['Field']."='".ms_addslashes((is_array($arr[$row['Field']]))?implode(":",$arr[$row['Field']]):$arr[$row['Field']])."'"; $i++; } } if($update) $makesql .= " where ".$update."='".$id."'".(($update2 && $id2)?" and ".$update2."='".$id2."'":""); if($rs == 'show') { echo $makesql; exit; } else {db_query($makesql); } $dbcon2 = $GLOBALS['dbcon']; return ($update)?$id:mysqli_insert_id($dbcon2); } function filequery($rs='exe',$tablename,$foldername,$arr,$update='',$id='',$update2='',$id2='') { $sp = array_keys($arr); $aa = ""; for($c=0;$c<=(count($sp)-1);$c++) { if($arr[$sp[$c]]['name']) { $path = bannerup($foldername); $sql = db_query("DESC ".tb_Prefix."$tablename"); $row = mysqli_fetch_array($sql,MYSQLI_ASSOC); if($update == '') $makesql = "insert into "; else $makesql = "update " ; $makesql .= tb_Prefix."$tablename set "; $i = 1; while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) { if($row['Field'] == $sp[$c]) { $filename = uploadFile1($path,$arr[$row['Field']]['name'],$row['Field']); if($i != 1) $makesql .= ", "; $makesql .= $row['Field']."='".ms_addslashes($filename)."'"; $i++; } } if($update) $makesql .= " where ".$update."='".$id."'".(($update2 && $id2)?" and ".$update2."='".$id2."'":""); if($rs == 'show') { echo $makesql; exit; } else {db_query($makesql); } $dbcon2 = $GLOBALS['dbcon']; return ($update)?$id:mysqli_insert_id($dbcon2); } } } function getFilename($filename) { $uniq = uniqid(""); $arr=explode('.',$filename); $ext = $arr[count($arr)-1]; $allowed = "/[^a-z0-9\\_]/i"; $arr[0] = preg_replace($allowed,"",$arr[0]); $filename=$uniq.$arr[0]."_.".$ext; return $filename; } /*function storeImage($tmp_name, $filename, $path, $type, $typeid, $name='Main') { $filename = getFilename($filename); $PATH = $path.'/'; list($wi,$hi)=getimagesize($tmp_name); $image = new SimpleImage(); $image->load($tmp_name); if($wi > 1600 || $hi > 1600) { $image->resizeToWidth(1600,1600); } $image->save($PATH.$filename); db_query("insert into ".tb_Prefix."images set id='', name='$name', type='$type', type_id='$typeid', path= '$filename', status='Active'"); }*/ function storeImage($tmp_name, $filename, $path, $type, $typeid, $name='Main') { $filename = getFilename($filename); $PATH = $path.'/'; list($wi,$hi)=getimagesize($tmp_name); $image = new SimpleImage(); $image->load($tmp_name); if($wi > 1600 || $hi > 1600) { $image->resizeToWidth(1600,1600); } $image->save($PATH.$filename); sqlquery("rs","pages",array($name=>$filename),'page_id',$typeid); //db_query("update into ".tb_Prefix."products set id='', name='$name', type='$type', typeid='$typeid', path= '$filename', status='Active'"); } function showimg($type,$id,$fol,$imgid='') { $nn = uploadpath($fol); if($imgid) $wh = " and id='".$imgid."'"; $img = getSingleresult("select path from ".tb_Prefix."images where type='".$type."' and type_id='".$id."'".$wh); if($img != '' && file_exists($nn.'/'.$img)) { return $nn.'/'.$img; } else { return "images/noimgbig.gif"; } } //--------------------------------------------------------------------------------------------------------------------- function checkImage($pic,$newname) { $im_extn_explode=explode(".",$pic); $maxkey=max(array_keys($im_extn_explode)); $im_extn=$im_extn_explode[$maxkey]; if(strtolower($im_extn)!="jpg" && strtolower($im_extn)!="gif" && strtolower($im_extn)!="png") $err='1'; else { $im_uid=time(); $im_unum=rand(100,1000); $im_new_name=$im_uid."_".$im_unum.".".$im_extn; $newnamee=$im_new_name; $err='0'; } if($err!='1' && $newname=="yes") return $newnamee; else return $err; } function checkPDFfile($pic,$newname) { $im_extn_explode=explode(".",$pic); $maxkey=max(array_keys($im_extn_explode)); $im_extn=$im_extn_explode[$maxkey]; if(strtolower($im_extn)!="pdf" && strtolower($im_extn) != 'jpg' && strtolower($im_extn) != 'jpeg' && strtolower($im_extn) != 'gif' && strtolower($im_extn) != 'png' && strtolower($im_extn) != 'doc' && strtolower($im_extn) != 'docx' && strtolower($im_extn) != 'xls' && strtolower($im_extn) != 'xlsx' && strtolower($im_extn) != 'ppt' && strtolower($im_extn) != 'pptx') $err='1'; else { $im_uid=time(); $im_unum=rand(100,1000); $im_new_name=$im_uid."_".$im_unum.".".$im_extn; $newnamee=$im_new_name; $err='0'; } if($err!='1' && $newname=="yes") return $newnamee; else return $err; } function checkFileType($filename) { $im_extn_explode=explode(".",$filename); $maxkey=max(array_keys($im_extn_explode)); $im_extn=$im_extn_explode[$maxkey]; return strtolower($im_extn); } function checkBioDataFile($filename) { $file_extn_explode=explode(".",$filename); $maxKey=max(array_keys($file_extn_explode)); $file_extn=$file_extn_explode[$maxKey]; if(strtolower($file_extn)=="doc" || strtolower($file_extn)=="docx") { $file_uid=md5(rand(0,9999)); $file_new_name=$file_uid."_".str_replace(" ","_",$filename); $err='0'; } else $err='1'; if($err!='1') return $file_new_name; else return $err; } function dbTableGenerator($tablename,$fields,$regen="no") { //check for table exists or not.. } function imageUploader($path,$oldimage,$newimage,$tempfile) { if($newimage!='') { if($oldimage!='' && file_exists($path.$oldimage)) unlink($path.$oldimage); if(move_uploaded_file($tempfile,$path.$newimage)) echo "1"; else echo "0"; } } function checkDuplicacy($table,$field,$value,$dbcon2=null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $select="select * from ".tb_Prefix.$table." WHERE ".$field."='$value' "; $query=db_query($select); return mysqli_num_rows($query); } function oneResultDb($sql,$dbcon2=null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $qry=db_query($sql); $fet=mysqli_fetch_array($qry,MYSQLI_NUM); return $fet[0]; } function processQuery($sql,$dbcon=null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $sqlQry=mysqli_query($dbcon2,$sql) or die(mysqli_error($dbcon2)); return $sqlQry; } function insertQuery($getArray,$table,$editId,$matchField) { //insert $ins=''; foreach($getArray as $key => $value) { $col=oneResultDb("SHOW COLUMNS FROM ".tb_Prefix."$table LIKE '$key' "); if($col!='' && $col!='0') { if($ins=='') $ins.=" $key = '$value' "; else $ins.=" ,$key = '$value' "; } } if($editId=='') $sql="insert into ".tb_Prefix.$table." SET ".$ins; else $sql="update ".tb_Prefix.$table." SET ".$ins." WHERE $matchField = '$editId' "; processQuery($sql); } function generateNewPage($path,$page,$header,$sample,$footer) { $npname=$path.$page; $inc1=""; $inc2=""; $inc3=""; $new_page=fopen($npname,'w+'); $data=$inc1; $data.=$inc2; $data.=$inc3; fwrite($new_page,$data); fclose($new_page); $p=1; return $p; } function fetchResultDb($sql,$sessionmsg="no",$dbcon2=null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } $query=processQuery($sql); if(mysqli_num_rows($query)>0) { $fetch=mysqli_fetch_array($query,MYSQLI_ASSOC); return $fetch; } else { if($sessionmsg=="yes") { $_SESSION['sessionMsg']="Record Not Found!"; } $fetch=array(); return $fetch; } } function createUrl($str) { $array_specialchars=array(" ","&","?","/","*","^","%","$","#","@","'",","); $array_replacechars=array("-","and","-","-","-","-","-","-","-","-","-","-"); $len=max(array_keys($array_specialchars)); $newstr=$str; for($i=0;$i<=$len;$i++) { $newstr=str_replace($array_specialchars[$i],$array_replacechars[$i],$newstr); } //before sending newstr check if there more than one - if yes then convert them to one only... $strlen=strlen($newstr); for($i=0;$i<$strlen;$i++) { $newstr=str_replace("--","-",$newstr); } return $newstr; } function generatePageUrl($linkinfo) { $exp_linkinfo=explode(":",$linkinfo); $path=SITE_PATH; for($i=0;$i 0) { while (list($cat_id, $cat_name) = mysqli_fetch_array($get_options,MYSQLI_ASSOC)) { if ($current_cat_id!=0) { $indent_flag = '--'; for ($x=2; $x<=$count; $x++) { $indent_flag .= ' >'; } } $cat_name = $indent_flag.$cat_name; $option_results[$cat_id] = $cat_name; get_cat_selectlistt($cat_id, $count, $tablename, $fetchField1, $fetchField2, $matchField, $statusField ); } } return $option_results; } function getChilds($parentID,$tablename,$fieldname,$matchField,$count=0,$dbcon2=null) { if($dbcon2==''){ if(!isset($GLOBALS['dbcon'])) { connect_db(); } $dbcon2 = $GLOBALS['dbcon']; } static $strArr=array(); $sql = "select $fieldname, $matchField from ".tb_Prefix.$tablename." where "; if ( is_null($parentID) ) { $sql .= "$matchField is null"; } elseif ( is_array($parentID) ) { $parentID =implode(',', $parentID); $sql .= "$matchField in ({$parentID})"; } else { $sql .= "$matchField = {$parentID}"; } $strArr[$count]=$parentID; $count++; $tree = array(); $idList = array(); $res = db_query($sql); while ( $row = mysqli_fetch_array($res,MYSQLI_ASSOC) ) { $row['children'] = array(); $tree[$row[$fieldname]] = $row; $idList[] = $row[$fieldname]; } mysqli_free_result($res); if ( $idList ) { getChilds($idList,$tablename,$fieldname,$matchField,$count); } return implode(",",$strArr); } function TimeConverter($t,$format,$ampmSeperator) //format must be 12hrs to convert 24 to 12 hrs format or 24hrs to convert 12 to 24 hrs format... { if($format=="24hrs") { if($ampmSeperator==":") { $timeSplit=explode(":",$t); $ampm=$timeSplit[2]; } if($ampmSeperator==" ") { $timeSplit1=explode(" ",$t); $ampm=$timeSplit1[1]; $timeSplit=explode(":",$timeSplit1[0]); } $hh=$timeSplit[0]; $mm=$timeSplit[1]; if($ampm=="am" || $ampm=="Am" || $ampm=="AM") { if($hh!=12) $h=$hh; else $h='00'; $convertedTime=$h.":".$mm; } if($ampm=="pm" || $ampm=="Pm" || $ampm=="PM") { if($hh!=12) $h=$hh+12; else $h=$hh; $convertedTime=$h.":".$mm; } } if($format=="12hrs") { $timeSplit=explode(":",$t); $hh=$timeSplit[0]; $mm=$timeSplit[1]; if($hh<12) { $h=$hh; $convertedTime=$h.":".$mm.$ampmSeperator."Am"; } if($hh>12) { $h=$hh-12; $convertedTime=$h.":".$mm.$ampmSeperator."Pm"; } if($hh==12) { $h=$hh; $convertedTime=$h.":".$mm.$ampmSeperator."Pm"; } } return $convertedTime; } function checkLogin() { $pagename=basename($_SERVER['PHP_SELF'],".php"); if(!isset($_SESSION['loginId'])) header("location:login.php"); } function generateVCode($type) { if($type==1) $vcode=rand(100,999)."_".chr(rand(65,90)).chr(rand(65,90)).chr(rand(65,90))."_".rand(10,99)."_".chr(rand(97,122)).chr(rand(97,122))."_".rand(1000,9999); else $vcode=rand(1000,9999)."_".chr(rand(97,90)).chr(rand(97,122)).chr(rand(97,122))."_".rand(10,99)."_".chr(rand(65,90)).chr(rand(65,90))."_".rand(100,999); return $vcode; } //------------------------------------------------function for emails -----------------------------------------------// function sendEmail($to,$from,$subject,$message) { $headers = "From: ".$from."\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; @mail($to,$subject,$message,$headers); } //-------------------------------------------------------------------------------------------------------------------// //--------------------------------------------------function for images ----------------------------------------------// function thumb1($size,$img,$alt,$class='') { $newimg="".$alt.""; return $newimg; } function thumb2($w,$h,$img) { $newimg=""; return $newimg; } function thumb5($w,$h,$img) { $newimg=""; return $newimg; } //------------------------------------------------------------------------------------------------------------------// //-----------------------------------------------shopcart functions ------------------------------------------------// function countShopCartItems() { $sid=$_SESSION['loginId']; $q=processQuery("select quantity from ".tb_Prefix."temporder WHERE clientid = '$sid' AND status = 'Active' "); $quant=0; while($f=mysql_fetch_array($q)) { $quant+=$f['quantity']; } return $quant; } //------------------------------------------------------------------------------------------------------------------// function getCategoryProductsArray($catname,$orderformat) { if($orderformat=='') $order_str=" ORDER BY productid DESC "; else if($orderformat=="productprice") $order_str=" ORDER BY productprice ASC, productsaleprice ASC "; else if($orderformat=="productname") $order_str=" ORDER BY productname ASC "; $arr=array(); if($catname=='all') { $q=processQuery("select * from ".tb_Prefix."products WHERE productstatus = 'Active' $order_str "); while($f=mysql_fetch_array($q)) { $arr[]=$f['productid']; } } else { $catid = oneResultDb("select categoryid from ".tb_Prefix."categories WHERE category_url = '$catname' "); $q=processQuery("select * from ".tb_Prefix."products WHERE productstatus = 'Active' $order_str "); while($f=mysql_fetch_array($q)) { $expcats=explode(",",$f['categoryid']); if(in_array($catid,$expcats)) $arr[]=$f['productid']; } } return implode(",",$arr); } function getCatsNames($cats,$getWhat='categoryname') { if($cats!="all") $q=processQuery("select $getWhat from ".tb_Prefix."categories WHERE categoryid IN ($cats) AND categorystatus = 'Active' "); else $q=processQuery("select $getWhat from ".tb_Prefix."categories WHERE categorystatus = 'Active' "); $arr=array(); while($f=mysql_fetch_array($q)) { $arr[]=$f[0]; } return implode(",",$arr); } function in_cat_ids($arrCatid,$cats) { for($i=0;$i 1) { $pagination .= "
    "; $pagination .= "
  • Page $page of $lastpage
  • "; if ($lastpage < 7 + ($adjacents * 2)) { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "
  • $counter
  • "; else $pagination.= "
  • $counter
  • "; } } elseif($lastpage > 5 + ($adjacents * 2)) { if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "
  • $counter
  • "; else $pagination.= "
  • $counter
  • "; } $pagination.= "
  • ...
  • "; $pagination.= "
  • $lpm1
  • "; $pagination.= "
  • $lastpage
  • "; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "
  • 1
  • "; $pagination.= "
  • 2
  • "; $pagination.= "
  • ...
  • "; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "
  • $counter
  • "; else $pagination.= "
  • $counter
  • "; } $pagination.= "
  • ..
  • "; $pagination.= "
  • $lpm1
  • "; $pagination.= "
  • $lastpage
  • "; } else { $pagination.= "
  • 1
  • "; $pagination.= "
  • 2
  • "; $pagination.= "
  • ..
  • "; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "
  • $counter
  • "; else $pagination.= "
  • $counter
  • "; } } } if ($page < $counter - 1){ $pagination.= "
  • Next
  • "; // $pagination.= "
  • Last
  • "; }else{ //$pagination.= "
  • Next
  • "; // $pagination.= "
  • Last
  • "; } $pagination.= "
\n"; } return $pagination; } function chkDevice() { $iphone = strpos($_SERVER['HTTP_USER_AGENT'],"iPhone"); $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android"); $palmpre = strpos($_SERVER['HTTP_USER_AGENT'],"webOS"); $berry = strpos($_SERVER['HTTP_USER_AGENT'],"BlackBerry"); $ipod = strpos($_SERVER['HTTP_USER_AGENT'],"iPod"); if ($iphone || $android || $palmpre || $ipod || $berry == true) { header('Location: https://m.reticonsultancyservices.com/'); exit; } else { return false; } } chkDevice(); ?>0) { while ($rw = mysql_fetch_array($rs)) { $page = getSingleresult("select page_name from ".tb_Prefix."pages where page_meta_type = '1' and page_id = '".$rw['page_id']."' "); $page =str_replace(' ','-',$page); unlink("../".$page.".php"); db_query("DELETE FROM ".tb_Prefix."pages WHERE page_meta_type = '1' and page_id='".$rw['page_id']."'"); } } $page =getSingleresult("select page_name from ".tb_Prefix."pages where page_meta_type = '1' and page_id = '".$page_id."' "); $page =str_replace(' ','-',$page); unlink("../".$page.".php"); db_query("DELETE FROM ".tb_Prefix."pages WHERE page_meta_type = '1' and page_id='".$page_id."'"); } function get_static_name($page_id) { $sql="select page_name from ".tb_Prefix."pages where page_id = '$page_id'"; return $rs=db_scalar($sql); } function protect_admin_page() { $cur_page = basename($_SERVER['PHP_SELF']); if ($_SESSION['sess_admin_login_id']=='' || $_SESSION['userId']=='') { header('Location: index.php'); exit; } } function validate_user() { if($_SESSION['userId']=='') { redir(curl('login')); } } function ms_redirect($file, $exit=true, $sess_msg='') { header("Location: $file"); exit(); } function status_dropdown($name, $sel_value) { $arr = array( "Active" => 'Active', 'Inactive' => 'Inactive'); return array_dropdown($arr, $sel_value, $name); } function yes_no_dropdown($name, $sel_value) { $arr = array( "Yes" => 'Yes', 'No' => 'No'); return array_dropdown($arr, $sel_value, $name); } function display_session_msg() { echo "

". $_SESSION['sessionMsg'] . "

"; unset($_SESSION['sessionMsg']); } function display_msg() { if(isset($_SESSION['msg']) && $_SESSION['msg'] != '') { echo "". $_SESSION['msg'] . ""; unset($_SESSION['msg']); } } function myadds($text) { } function display_session($session_msg) { if(isset($_SESSION[$session_msg]) && $_SESSION[$session_msg] != '') { $arr = explode("
",$_SESSION[$session_msg]); echo "
    "; for($i=0;$i<=(count($arr)-1);$i++) { if($arr[$i]) echo "
  • ". $arr[$i] . "
  • "; } echo "
"; unset($_SESSION[$session_msg]); } } function readmyfile($path) { $text=''; $fp = @fopen($path,"r"); while (!@feof($fp)) { $buffer = @fgets($fp, 4096); $text.= $buffer; } @fclose($fp); return $text; } if(!function_exists("send_mail")) { function send_mail($email_to,$subject,$message,$from_email,$from_name='',$html=false) { if($from_name == '') $from_name=$from_email; if($html==true) { $headers = "Content-type: text/html; charset=iso-8859-1\r\n"; } else { $headers = "Content-type: text/plain; charset=iso-8859-1\r\n"; } $headers .= "From: $from_email \r\n"; @mail($email_to,$subject,$message,$headers); } } function get_config_value($config_id) { $sql_config="select config_value from sp_config where config_id='$config_id'"; return db_scalar($sql_config); } function num_sub_categories($catid) { $rtmp = db_query("select count(*) from ".tb_Prefix."categories where cat_parent_id='$catid'"); $rwtmp = mysql_fetch_row($rtmp); return $rwtmp[0]; } function check_item_in_cat($catId) { $sqlCat="select * from ".tb_Prefix."categories where cat_parent_id='".$catId."'"; $rsCat=db_query($sqlCat); $tempId=""; while($arrCat=mysql_fetch_array($rsCat)) { $tempId.=$arrCat[cat_id].","; } $tempId=substr($tempId,0,strlen($tempId)-1); if($tempId!='') { /*$sqlItem="select * from ".tb_Prefix."banner where banner_catid in ($tempId)"; $rsItem=db_query($sqlItem); if(mysql_num_rows($rsItem)>0) { return true; } else { return false; }*/ } } function check_item_cat($catId) { if($catId!='') { /*$sqlItem="select * from ".tb_Prefix."banner where banner_catid ='".$catId."' and status='Active'"; $rsItem=db_query($sqlItem); if(mysql_num_rows($rsItem)>0) { return true; } else { return false; }*/ } } function delete_sub_categories($catid) { $rs = db_query("SELECT * FROM ".tb_Prefix."categories WHERE cat_parent_id='".$catid."'"); if (mysql_num_rows($rs)>0) { while ($rw = mysql_fetch_array($rs)) { delete_sub_categories($rw["cat_id"]); db_query("DELETE FROM ".tb_Prefix."categories WHERE cat_id='".$rw["cat_id"]."'"); } } db_query("DELETE FROM ".tb_Prefix."categories WHERE cat_id='".$catid."'"); } function item_count_cat($catId,$subCat='') { if($subCat=='') { $sqlCat="select * from ".tb_Prefix."categories where cat_parent_id='".$catId."'"; $rsCat=db_query($sqlCat); $tempId=""; while($arrCat=mysql_fetch_array($rsCat)) { $tempId.=$arrCat[cat_id].","; } $tempId=substr($tempId,0,strlen($tempId)-1); if($tempId!='') { $sqlCat="select count(*) as cnt from ".tb_Prefix."banner where banner_catid in($tempId)"; $rsCat=db_query($sqlCat); $arrCat=mysql_fetch_array($rsCat); $varreturn=$arrCat["cnt"]; } else { $varreturn=0; } } else { $sqlCat="select count(*) as cnt from ".tb_Prefix."banner where banner_catid='".$catId."'"; $rsCat=db_query($sqlCat); $arrCat=mysql_fetch_array($rsCat); $varreturn=$arrCat["cnt"]; } return $varreturn; } function category_breadcrumbs($cat_id) { $linkclass = 'bread1'; $normalclass = 'bread2'; $self = $_SERVER['PHP_SELF']; $break = " » "; $root = "Main Categories"; if ($cat_id == '0') { $str = $root; } else { $rs1 = db_query("SELECT cat_name,cat_parent_id from ".tb_Prefix."categories where cat_id = '$cat_id' "); $rw1 = mysql_fetch_array($rs1); $lk1 = "$rw1[cat_name]"; $parent = $rw1[cat_parent_id]; if ($parent != '0') { while ($parent != 0) { $rs2 = db_query("SELECT cat_name,cat_parent_id,cat_id from ".tb_Prefix."categories where cat_id = '$parent' "); $rw2 = mysql_fetch_array($rs2); $lk2 = "$rw2[cat_name]".$break.$lk2; $parent = $rw2[cat_parent_id]; } } $str = $root.$break.$lk2.$lk1; } echo "

$str

"; } function get_cat_combo($name,$sel_value) { $sql="select * from tf_category where cat_status='Active'"; $rs=db_query($sql); $num=mysql_num_rows($rs); $combo=""; if($num>0) { $combo.=""; } return $combo; } function get_user_combo($name,$sel_value) { $sql="select * from fa_users where user_status='Active'"; $rs=db_query($sql); $num=mysql_num_rows($rs); $combo=""; if($num>0) { $combo.=""; } return $combo; } function get_country_combo($name,$sel_value,$extra = '') { $sql="select * from ".tb_Prefix."country order by country asc"; $rs=db_query($sql); $num=mysql_num_rows($rs); $combo=""; if($num>0) { $combo.=""; } return $combo; } function get_state_combo($name,$sel_value,$extra) { $sql="select * from tf_state order by name asc"; $rs=db_query($sql); $num=mysql_num_rows($rs); $combo=""; if($num>0) { $combo.=""; } return $combo; } function get_state_combo_short($name,$sel_value,$extra) { $sql="select * from fa_state order by name asc"; $rs=db_query($sql); $num=mysql_num_rows($rs); $combo=""; if($num>0) { $combo.=""; } return $combo; } function randomString($length) { $key_chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'; $rand_max = strlen($key_chars) - 1; for ($i = 0; $i < $length; $i++) { $rand_pass .= substr($key_chars, rand($i, $rand_max), 1); } return $rand_pass; } function get_static_content($key,$pagename) { $pppname=str_replace("-"," ",$pagename); $sql="select ".$key." from ".tb_Prefix."pages where (page_name='$pagename' || page_menu='$pagename' || page_menu='$pppname')"; return $rs=db_scalar($sql); } function get_state_content($val) { $sql="select state_ab from ".tb_Prefix."state where (state_name='$val')"; return $rs=db_scalar($sql); } function convert_flv($srcFile,$destFile) { //echo $srcFile = dirname(__FILE__)."/".$srcFile; $srcFile = $srcFile; //$destFile = dirname(__FILE__)."/".$destFile; $destFile = $destFile; $ffmpegPath = "/usr/bin/ffmpeg"; //$ffmpegPath = "C:/ffmpeg1/ffmpeg"; //$flvtool2Path = "/usr/local/bin/ffmpeg"; $info = execOutput($ffmpegPath . " -i " . $srcFile); // Create our FFMPEG-PHP class //$ffmpegObj = new ffmpeg_movie($srcFile); // Save our needed variables $srcWidth = $info['video']['dimensions']['width']; $srcWidth -= $srcWidth % 2; // output frame width must be even number $srcHeight = $info['video']['dimensions']['height']; $srcHeight -= $srcHeight % 2; // output frame height must be even number $srcFPS = $info['video']['frame_rate']; //$srcAB = intval($ffmpegObj->getAudioBitRate()/1000); $srcAB = 64; // use 64kbps for FLV, doesn't matter what the original video had, it will downsample //$srcAR = $ffmpegObj->getAudioSampleRate(); $srcAR = 22050; // same for audio sample rate. // Call our convert using exec() $srcAC = 2; // output FLV should have two audio channels $out = array(); exec($ffmpegPath . " -i " . $srcFile . " -ac " . $srcAC . " -ar " . $srcAR . " -ab " . $srcAB . " -f flv -s " . $srcWidth . "x" . $srcHeight . " " . $destFile.' 2>&1', $out, $error); return implode("
", $out); } function execOutput($command) { $output = array(); //echo $command; exec($command.' 2>&1', $output); $data = array(); $buffer = implode("\r\n", $output); /*preg_match_all('/Duration: (.*)/', $buffer, $matches); if(count($matches) > 0) { $parts = explode(', ', trim($matches[1][0])); $data['duration'] = array(); $timecode = $parts[0]; //$data['duration']['seconds'] = $this->timecodeToSeconds($timecode); $data['bitrate'] = intval(ltrim($parts[2], 'bitrate: ')); $data['duration']['start'] = ltrim($parts[1], 'start: '); $data['duration']['timecode'] = array(); $data['duration']['timecode']['rounded'] = substr($timecode, 0, 8); $data['duration']['timecode']['seconds'] = array(); $data['duration']['timecode']['seconds']['exact'] = $timecode; $data['duration']['timecode']['seconds']['excess'] = intval(substr($timecode, 9)); }*/ preg_match('/Stream(.*): Video: (.*)/', $buffer, $matches); if(count($matches) > 0) { $data['video'] = array(); // get the dimension parts // print_r($matches); preg_match('/([0-9]{1,5})x([0-9]{1,5})/', $matches[2], $dimensions_matches); // print_r($dimensions_matches); $dimensions_value = $dimensions_matches[0]; $data['video']['dimensions'] = array( 'width' => floatval($dimensions_matches[1]), 'height' => floatval($dimensions_matches[2]) ); // get the framerate preg_match('/([0-9\.]+) (fps|tb)\(r\)/', $matches[0], $fps_matches); $data['video']['frame_rate'] = floatval($fps_matches[1]); $fps_value = $fps_matches[0]; // get the ratios preg_match('/\[PAR ([0-9\:\.]+) DAR ([0-9\:\.]+)\]/', $matches[0], $ratio_matches); if(count($ratio_matches)) { $data['video']['pixel_aspect_ratio'] = $ratio_matches[1]; $data['video']['display_aspect_ratio'] = $ratio_matches[2]; } // work out the number of frames if(isset($data['duration']) && isset($data['video'])) { // set the total frame count for the video $data['video']['frame_count'] = ceil($data['duration']['seconds'] * $data['video']['frame_rate']); // set the framecode $frames = ceil($data['video']['frame_rate']*($data['duration']['timecode']['seconds']['excess']/10)); $data['duration']['timecode']['frames'] = array(); $data['duration']['timecode']['frames']['exact'] = $data['duration']['timecode']['rounded'].'.'.$frames; $data['duration']['timecode']['frames']['excess'] = $frames; $data['duration']['timecode']['frames']['total'] = $data['video']['frame_count']; } // formats should be anything left over, let me know if anything else exists $parts = explode(',', $matches[2]); $other_parts = array($dimensions_value, $fps_value); $formats = array(); foreach($parts as $key=>$part) { $part = trim($part); if(!in_array($part, $other_parts)) { array_push($formats, $part); } } $data['video']['pixel_format'] = $formats[1]; $data['video']['codec'] = $formats[0]; } // match the audio stream info preg_match('/Stream(.*): Audio: (.*)/', $buffer, $matches); if(count($matches) > 0) { // setup audio values $data['audio'] = array( 'stereo' => -1, 'sample_rate' => -1, 'sample_rate' => -1 ); $other_parts = array(); // get the stereo value preg_match('/(stereo|mono)/i', $matches[0], $stereo_matches); if(count($stereo_matches)) { $data['audio']['stereo'] = $stereo_matches[0]; array_push($other_parts, $stereo_matches[0]); } // get the sample_rate preg_match('/([0-9]{3,6}) Hz/', $matches[0], $sample_matches); if(count($sample_matches)) { $data['audio']['sample_rate'] = count($sample_matches) ? floatval($sample_matches[1]) : -1; array_push($other_parts, $sample_matches[0]); } // get the bit rate preg_match('/([0-9]{1,3}) kb\/s/', $matches[0], $bitrate_matches); if(count($bitrate_matches)) { $data['audio']['bitrate'] = count($bitrate_matches) ? floatval($bitrate_matches[1]) : -1; array_push($other_parts, $bitrate_matches[0]); } // formats should be anything left over, let me know if anything else exists $parts = explode(',', $matches[2]); $formats = array(); foreach($parts as $key=>$part) { $part = trim($part); if(!in_array($part, $other_parts)) { array_push($formats, $part); } } $data['audio']['codec'] = $formats[0]; } return $data; } function get_order($type) { if($type=="drop") { $sql="select max(cat_drop_order)+1 as MaxOrder from ".tb_Prefix."categories where cat_parent_id!='0'"; } else { $sql="select max(cat_order)+1 as MaxOrder from ".tb_Prefix."categories where cat_parent_id!='0'"; } $rs=db_query($sql); $arr=mysql_fetch_array($rs); return $arr["MaxOrder"]; } function option_categories1($match=0,$type,$parent=0,$space='',$matcharr=0,$optlabel=1) { // displays only "; echo ""; } else { echo ""; } } else { echo ""; } $space_new = $space.' - '; option_categories($match,$type,$rw[cat_id],$space_new,$matcharr,$just); } } function main_option_categories($match=0,$domainid,$parent=0,$space='',$matcharr=0,$optlabel=1) { // displays only