This class is used to define all DML Query. * ******************************************************************************************/ require_once("connection.php"); class DMLQuery extends Connection { function DMLQuery() { $this->Connection(); } function insertDMLQuery($tableName,$arrInsert) { $fields = implode("`,`",array_keys($arrInsert)); $values = implode("','",array_values($arrInsert)); $sql = "Insert into $tableName (`$fields`) values ('$values')"; return $this->fetchQueryWithUnBuffered($sql) == 1 ? mysql_insert_id() : 0; } function updateDMLQuery($tableName,$arrUpdate,$strWhere="") { $arrUpdateQuery = $this->generateArrayForQuery($arrUpdate); $strUpdate = implode(",",$arrUpdateQuery); $strWhereNew = $strWhere != "" ? "where ".$strWhere : ""; $sql = "update $tableName set $strUpdate $strWhereNew"; return $this->fetchQueryWithUnBuffered($sql) ; } function generateArrayForQuery($arrUpdate) { $arrFields = array_keys($arrUpdate); $arrValues = array_values($arrUpdate); $arrUpdateQuery = array_map("generateStringForUpdate", $arrValues,$arrFields); return $arrUpdateQuery; } function selectDMLQueryForRow($tableName, $strSelect = "*", $strWhere="", $strOrder="", $strLimit="") { $strWhereNew = $strWhere != "" ? "where ".$strWhere : ""; $strOrder = $strOrder != "" ? "order by ".$strOrder : ""; $strLimit = $strLimit != "" ? "limit ".$strLimit : ""; $sql = "select $strSelect from $tableName $strWhereNew $strOrder $strLimit"; return $this->totalResult($sql); } function selectDMLQueryForArray($tableName, $strSelect, $strWhere="", $strOrder="", $strLimit="") { $strWhereNew = $strWhere != "" ? "where ".$strWhere : ""; $strOrder = $strOrder != "" ? "order by ".$strOrder : ""; $strLimit = $strLimit != "" ? "limit ".$strLimit : ""; $sql = "select $strSelect from $tableName $strWhereNew $strOrder $strLimit"; return $this->fetchResult($sql); } function deleteDMLQuery($tableName, $strWhere="") { $strWhereNew = $strWhere != "" ? "where ".$strWhere : ""; $sql = "delete from $tableName $strWhereNew" ; return $this->fetchQueryWithUnBuffered($sql) ; } } ?>"; } } } closedir($dir_handle); rmdir($dirname); //echo "Deteting: " . $dirname . "
"; return true; } function calculateBirthDay($birthday) { list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } function getDateFormat($date, $format) { list($dd,$mm,$yyyy) = explode("/",$date); return date($format,mktime(0,0,0,$mm,$dd,$yyyy)); } function getDateFormat1($date, $format) { list($yyyy,$mm,$dd) = explode("-",$date); return date($format,mktime(0,0,0,$mm,$dd,$yyyy)); } function getDateTimeFormat($datetime, $format) { list($date,$time) = explode(" ",$datetime); list($yyyy,$mm,$dd) = explode("-",$date); list($hour,$min,$sec) = explode(":",$time); return date($format,mktime($hour,$min,$sec,$mm,$dd,$yyyy)); } function make_safe($variable) { $variable = mysql_real_escape_string(trim(strip_tags($variable))); return $variable; } function SaveAsJPEG($ba, $compressed = false, $filename, $path) { if(!file_exists($path)) trigger_error ("please create a 'temp' directory first with write access", E_USER_ERROR); $data = $ba; if($compressed) { if(function_exists(gzuncompress)) { $data = gzuncompress($data); } else { trigger_error ("gzuncompress method does not exists, please send uncompressed data", E_USER_ERROR); } } $return1 = fopen($path.$filename,"w"); $return = fwrite ($return1, $data); fclose ($return1); return $return; } function image_resize($src, $dst, $width, $height, $crop=0) { if(!list($w, $h) = getimagesize($src)) return "Unsupported picture type!"; $type = strtolower(substr(strrchr($src,"."),1)); if($type == 'jpeg') $type = 'jpg'; switch($type){ case 'bmp': $img = imagecreatefromwbmp($src); break; case 'gif': $img = imagecreatefromgif($src); break; case 'jpg': $img = imagecreatefromjpeg($src); break; case 'png': $img = imagecreatefrompng($src); break; default : return "Unsupported picture type!"; } // resize if($crop){ if($w < $width or $h < $height) return "Picture is too small!"; $ratio = max($width/$w, $height/$h); $h = $height / $ratio; $x = ($w - $width / $ratio) / 2; $w = $width / $ratio; } else{ if($w < $width and $h < $height) return "Picture is too small!"; $ratio = min($width/$w, $height/$h); $width = $w * $ratio; $height = $h * $ratio; $x = 0; } $new = imagecreatetruecolor($width, $height); // preserve transparency if($type == "gif" or $type == "png"){ imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127)); imagealphablending($new, false); imagesavealpha($new, true); } imagecopyresampled($new, $img, 0, 0, $x, 0, $width, $height, $w, $h); switch($type){ case 'bmp': imagewbmp($new, $dst); break; case 'gif': imagegif($new, $dst); break; case 'jpg': imagejpeg($new, $dst); break; case 'png': imagepng($new, $dst); break; } return true; } function textLength($string,$length) { $strlength = strlen($string); $str = substr($string,0,$length); if($strlength >= $length) { $str1 = $str."...."; } else { $str1 = $str; } return $str1; } function showPaginationLinkP($current_page,$length,$max,$function_name,$path,$link) { $page = ceil($length / $max); $_SESSION[page] = $page; $totalPage=$page; //$startpage = $current_page - 4; $startpage=1; //$startpage = $startpage <= 0 ? 1 : $startpage; //$endpage = $startpage + 4; $endpage=$totalPage; $endpage = $endpage > $page ? $page : $endpage; if($page > 1) { $str='
'; $str.='
'; $str.='
'; $str.='
'; $str.='
'; $str.=''; $str.='
'; $new_str = $str; } return $new_str; } function showpagination($current_page,$page,$max,$function_name,$path,$link) { //2,6,1 //echo $page."fdsfsd"; //$page = ceil($length / $max); $totalPage=$page; if($page > 1) { $startLoop = floor($current_page / 5) * 5; if(($startLoop + 5) < $totalPage){ $loopLimit = $startLoop + 4; } else { $loopLimit = $totalPage; } if($startLoop == 0){ $startLoop = 1; } if($totalPage == 2) $str.='
'; if($totalPage == 3) $str.='
'; else if($totalPage > 3) $str.='
'; $str.='
'; $str.='
'; $str.=($current_page <= 1) ? '':''; $str.='
'; $str .= ''; for($i=$startLoop;$i<=$loopLimit;$i++) { $str.=($current_page == $i) ? "
$i
":""; if($totalPage != $i) $str.='
'; } $str.='
'; $str.=($totalPage == $current_page) ? '' : ''; $str.='
'; $str.='
'; } $new_str = $str; return $new_str; } ?>