host = $host; $this->user = $user; $this->pswd = $pswd; $this->db = $db; } // Connects to the MySQL database server. function connect() { try { $this->linkid = @mysqli_connect($this->host, $this->user, $this->pswd); if (!$this->linkid) throw new Exception("Could not connect to the MySQL server."); } catch (Exception $e) { die($e->getMessage()); } } // Selects the MySQL database function select() { try { if (!@mysqli_select_db($this->linkid, $this->db)) throw new Exception("Could not connect to the MySQL database."); } catch (Exception $e) { die($e->getMessage()); } } // Closes the MySQL database function close() { try { if (!@mysqli_close($this->linkid)) throw new Exception("Could not close the MySQL database connection."); } catch (Exception $e) { die($e->getMessage()); } } // Execute database query function query($query) { try { $this->result = @mysqli_query($this->linkid, $query); if (!$this->result) throw new Exception("The database query failed."); } catch (Exception $e) { echo($e->getMessage); } $this->querycount++; return $this->result; } // Get information about the most recent query function queryInfo() { return @mysqli_info($this->linkid); } function getLinkID() { return $this->linkid; } // Determine total rows affected by query. function affectedRows() { $count = @mysqli_affected_rows($this->linkid); return $count; } // Determine total rows affected by the query. function numRows() { $count = @mysqli_num_rows($this->result); return $count; } // Return query reslut row as an object. function fetchObject() { $row = @mysqli_fetch_object($this->result); return $row; } // Return query result row as an indexed array. function fetchRow() { $row = @mysqli_fetch_row($this->result); return $row; } // return query result row as an associative array. function fetchArray() { $row = @mysqli_fetch_array($this->result); return $row; } // Return the total number of queries executed during the lifetime of this object. function numQueries() { return $this->querycount; } // Return the number of fields in a result set function numberFields() { //return @mysqli_num_fields($this->result); return $this->result->field_count; } // Return a field name given and integer offset function fieldName($offset) { //return @mysqli_field_name($this->result, $offset); return $this->result->fetch_field_direct($offset)->name; } // Return a field length given and integer offset function fieldLength($offset) { //return @mysqli_field_len($this->result, $offset); return $this->result->fetch_field_direct($offset)->length; } // Return a field type given and integer offset function fieldType($offset) { //return @mysqli_field_type($this->result, $offset); return $this->result->fetch_field_direct($offset)->type; } function cut($text, $limit) { if (strlen($text) > $limit) { $text = substr($text, 0, $limit).'...'; } return $text; } // TABLE RENDERER function displayRecords($table='', $width='', $sort='id', $record_start=0, $variables='', $url='') { $counter = 0; if ($this->numRows() > 0) { $resultHTML .= ''."\n"; $resultHTML .= ''."\n"; // HEADER ROW $fieldCount = $this->numberFields(); $resultHTML .= ''."\n"; $resultHTML .= ''."\n"; if ($table != 'user') { $resultHTML .= ''."\n"; } for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); if ($rowName == $sort) { $resultHTML .= ''."\n"; } else { $resultHTML .= ''."\n"; } } $resultHTML .= ''."\n"; // CLOSE HEADER ROW while ($row = $this->fetchRow()) { $resultHTML .= ''."\n"; // OPEN RECORD ROW if ($counter % 2 != 0) { } else { } $resultHTML .= ''."\n"; $resultHTML .= ''."\n"; if ($table != 'user') { $resultHTML .= ''."\n"; } for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); if (strlen($row[$i]) != 0) { switch ($rowName) { case 'status': if ($row[$i] == 'enabled') { $resultHTML .= ''."\n"; } else { $resultHTML .= ''."\n"; } break; case 'price': $resultHTML .= ""."\n"; break; case 'stock': $resultHTML .= ""."\n"; break; case 'discount': $resultHTML .= ""."\n"; break; case 'weight': $resultHTML .= ""."\n"; break; case 'featured': $resultHTML .= ""."\n"; break; default: $resultHTML .= ''."\n"; break; } } else { $resultHTML .= ''."\n"; } } $resultHTML .= ''."\n"; // CLOSE RECORD ROW $counter++; } $resultHTML .= '
editdeletecopy'.$rowName.''.$rowName.'
edit'."deleteduplicatedisabledenabled'.$row[$i].'empty
'."\n"; } else { $resultHTML = "Sorry, no results were found."; } return $resultHTML; } // TABLE RENDERER function displayBasic($table='', $width='', $sort='id', $record_start=0, $variables='', $url='') { $counter = 0; if ($this->numRows() > 0) { $resultHTML .= ''."\n"; $resultHTML .= ''."\n"; // HEADER ROW $fieldCount = $this->numberFields(); for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); if ($rowName == $sort) { $resultHTML .= ''."\n"; } else { $resultHTML .= ''."\n"; } } $resultHTML .= ''."\n"; // CLOSE HEADER ROW while ($row = $this->fetchRow()) { $resultHTML .= ''."\n"; // OPEN RECORD ROW if ($counter % 2 != 0) { } else { } for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); if (strlen($row[$i]) != 0) { $resultHTML .= ''."\n"; } else { $resultHTML .= ''."\n"; } } $resultHTML .= ''."\n"; // CLOSE RECORD ROW $counter++; } $resultHTML .= '
'.$rowName.''.$rowName.'
'.$row[$i].'empty
'."\n"; } else { $resultHTML = "Sorry, no results were found."; } return $resultHTML; } // TABLE RENDERER function displayVeryBasic($sort='id') { $counter = 0; if ($this->numRows() > 0) { $resultHTML .= ''."\n"; $resultHTML .= ''."\n"; // HEADER ROW $fieldCount = $this->numberFields(); for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); $resultHTML .= ''."\n"; } $resultHTML .= ''."\n"; // CLOSE HEADER ROW while ($row = $this->fetchRow()) { $resultHTML .= ''."\n"; // OPEN RECORD ROW if ($counter % 2 != 0) { } else { } for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); if (strlen($row[$i]) != 0) { $resultHTML .= ''."\n"; } else { $resultHTML .= ''."\n"; } } $resultHTML .= ''."\n"; // CLOSE RECORD ROW $counter++; } $resultHTML .= '
'.$rowName.'
'.$row[$i].'empty
'."\n"; } else { $resultHTML = "Sorry, no results were found."; } return $resultHTML; } // TABLE RENDERER function displayVeryBasicRows($sort='id') { $counter = 0; if ($this->numRows() > 0) { $resultHTML .= ''."\n"; $fieldCount = $this->numberFields(); for ($i = 0; $i < $fieldCount; $i++) { $rowName = $this->fieldName($i); $resultHTML .= ''."\n"; } $resultHTML .= '
'.$rowName.'
'."\n"; } else { $resultHTML = "Sorry, no results were found."; } return $resultHTML; } } ?>'."\n"; if (is_array($options)) { foreach ($options as $option) { if ($option == $current) { $selected = 'selected'; } else { $selected = ''; } $menu .= ''."\n"; } } $menu .= ''."\n"; return $menu; } function cleanFileName($fileName) { $problemChars = array(" ", "/", "\\", "&", "'", '"', "�", "#", "%", "-", "+", "?", "=", "(", ")", "^", "$", "@", "!", "~", "`", "*", ":", ";", ">", "<", ",", "{", "}", "[", "]", "|", "™", "®"); $cleanedFileName = $fileName; foreach ($problemChars as $char) { switch ($char) { case "&": $replaceChar = "and"; break; case " ": $replaceChar = "_"; break; default: $replaceChar = ""; } $cleanedFileName = str_replace($char, $replaceChar, $cleanedFileName); } $cleanedFileName = str_replace('__', '_', $cleanedFileName); $cleanedFileName = ltrim($cleanedFileName, "_"); $cleanedFileName = rtrim($cleanedFileName, "_"); return strtolower($cleanedFileName); } function cleanSpecialChars($pageURL) { $problemChars = array(" ", ".", "/", "\\", "&", "'", '"', "�", "#", "%", "-", "+", "?", "=", "(", ")", "^", "$", "@", "!", "~", "`", "*", ":", ";", ">", "<", ",", "{", "}", "[", "]", "|", "™", "®"); $cleanedPageURL = $pageURL; foreach ($problemChars as $char) { switch ($char) { case "&": $replaceChar = "and"; break; case " ": $replaceChar = "_"; break; default: $replaceChar = ""; } $cleanedPageURL = str_replace($char, $replaceChar, $cleanedPageURL); } $cleanedPageURL = str_replace('__', '_', $cleanedPageURL); $cleanedPageURL = ltrim($cleanedPageURL, "_"); $cleanedPageURL = rtrim($cleanedPageURL, "_"); return strtolower($cleanedPageURL); } function clean($string) { return htmlentities(stripslashes(trim($string)), ENT_COMPAT, 'UTF-8', true); } function cleanInput($string) { return trim(stripslashes($string)); } function copyright($image, $overlay_path) { imagealphablending($image, true); $image_x = imagesx($image); $image_y = imagesy($image); //imagefilter($image, IMG_FILTER_GRAYSCALE); $overlay = imagecreatefrompng($overlay_path); imagealphablending($overlay, true); $overlay_x = imagesx($overlay); $overlay_y = imagesy($overlay); //imagecolortransparent($overlay, imagecolorat($overlay, 0, 0)); imagecopymerge($image, $overlay, (($image_x - $overlay_x) / 2), (($image_y - $overlay_y) / 2), 0, 0, $overlay_x, $overlay_y, 25); //imagejpeg($image, $image_dir.'_'.$img_url, 90); imagedestroy($overlay); return $image; } function is_image($img_path) { $image_types = array("image/jpeg", "image/jpg", "image/pjpg", "image/pjpeg", "image/gif", "image/pgif", "image/png", "image/ppng"); $image = getimagesize($img_path); if (in_array($image['mime'], $image_types)) { return true; } else { return false; } } function encrypt($string, $key) { $result = ''; for ($i = 0; $i < strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key)) - 1, 1); $char = chr(ord($char) + ord($keychar)); $result .= $char; } return base64_encode($result); } function decrypt($string, $key) { $result = ''; $string = base64_decode($string); for ($i = 0; $i < strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key)) - 1, 1); $char = chr(ord($char) - ord($keychar)); $result .= $char; } return $result; } function safe($text) { $value = 'value="'.$text.'"'; $pos = strpos($text, '"'); if ($pos === false) { } else { $value = "value='".$text."'"; } return $value; } function get_month($month, $day, $year) { $timestamp = mktime(0, 0, 0, $month, $day, $year); return date('F', $timestamp); } function get_day($month, $day, $year) { $timestamp = mktime(0, 0, 0, $month, $day, $year); return date('l', $timestamp); } # PHP Calendar (version 2.3), written by Keith Devens # https://keithdevens.com/software/php_calendar # see example at https://keithdevens.com/weblog # License: https://keithdevens.com/software/license function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()) { $first_of_month = gmmktime(0, 0, 0, $month, 1, $year); #remember that mktime will automatically correct if invalid dates are entered # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998 # this provides a built in "rounding" feature to generate_calendar() $day_names = array(); #generate all the day names according to the current locale for ($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t+=86400) #January 4, 1970 was a Sunday $day_names[$n] = ucfirst(gmstrftime('%A', $t)); #%A means full textual day name list($month, $year, $month_name, $weekday) = explode(',', gmstrftime('%m,%Y,%B,%w', $first_of_month)); $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day $title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names #Begin calendar. Uses a real . See https://diveintomark.org/archives/2002/07/03 @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable if ($p) $p = ($pl ? ''.$p.'' : $p); if ($n) $n = ($nl ? ''.$n.'' : $n); $calendar = ''."\n". '\n"; if ($day_name_length) { #if the day names should be shown ($day_name_length > 0) #if day_name_length is >3, the full name of the day will be printed foreach ($day_names as $d) //$calendar .= ''; $calendar .= ''; $calendar .= "\n"; } if ($weekday > 0) $calendar .= '';#initial 'empty' days for ($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++) { if ($weekday == 7) { $weekday = 0; #start a new week $calendar .= "\n"; } if (isset($days[$day]) and is_array($days[$day])) { @list($link, $classes, $content) = $days[$day]; if (is_null($content)) $content = $day; $calendar .= '' : '>'). ($link ? ''.$content.'' : $content).''; } else $calendar .= ''; } if ($weekday != 7) $calendar .= '';#remaining "empty" days return $calendar."\n
'.$p.''.($month_href ? ''.$title.'' : $title).''.$n."
'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).''.htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d).'
 
'.$day.' 
\n"; } function generate_booking_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()) { $first_of_month = gmmktime(0, 0, 0, $month, 1, $year); # remember that mktime will automatically correct if invalid dates are entered # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998 # this provides a built in "rounding" feature to generate_booking_calendar() $day_names = array(); #generate all the day names according to the current locale for ($n = 0, $t = (3 + $first_day) * 86400; $n < 7; $n++, $t+=86400) { #January 4, 1970 was a Sunday $day_names[$n] = ucfirst(gmstrftime('%A', $t)); #%A means full textual day name } list($month, $year, $month_name, $weekday) = explode(',', gmstrftime('%m,%Y,%B,%w', $first_of_month)); $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day $title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names #Begin calendar. Uses a real . See https://diveintomark.org/archives/2002/07/03 @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable if ($p) { $p = ($pl ? ''.$p.'' : $p); } if ($n) { $n = ($nl ? ''.$n.'' : $n); } $calendar = ''."\n". ''."\n". ''."\n". ''."\n". ''."\n". ''."\n". ''."\n"; if ($day_name_length) { #i f the day names should be shown ($day_name_length > 0) # if day_name_length is >3, the full name of the day will be printed foreach ($day_names as $d) { //$calendar .= ''; $calendar .= ''."\n"; } $calendar .= ''."\n". ''."\n"; } if ($weekday > 0) { $calendar .= ''."\n"; # initial 'empty' days } for ($day = 1, $days_in_month = gmdate('t', $first_of_month); $day <= $days_in_month; $day++, $weekday++) { if ($weekday == 7) { $weekday = 0; # start a new week $calendar .= ''."\n". ''."\n"; } if (isset($days[$day]) and is_array($days[$day])) { @list($link, $classes, $content) = $days[$day]; if (is_null($content)) { $content = $day; } $calendar .= '' : '>').($link ? ''.$content.'' : $content).''."\n"; } else { $calendar .= ''."\n"; } } if ($weekday != 7) { $calendar .= ''."\n"; # remaining "empty" days } return $calendar.''."\n".'
'.$p.''.($month_href ? ''.$title.'' : $title).''.$n.'
'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).''.htmlentities($day_name_length < 4 ? substr($d, 0, $day_name_length) : $d).'
 
'.$day.' 
'."\n"; } function pipe($array, $pipe='|') { $string = ''; if (is_array($array)) { foreach ($array as $item) { $string .= $pipe.$item; $pipe = '|'; } $string .= $pipe; } return $string; } function overlay($image_dir, $img_url, $overlay_path) { $image_path = $image_dir.$img_url; $image = imagecreatefromjpeg($image_path); $image_x = imagesx($image); $image_y = imagesy($image); imagefilter($image, IMG_FILTER_GRAYSCALE); $overlay = imagecreatefrompng($overlay_path); $overlay_x = imagesx($overlay); $overlay_y = imagesy($overlay); imagecolortransparent($overlay, imagecolorat($overlay, 0, 0)); imagecopymerge($image, $overlay, (($image_x - $overlay_x) / 2), (($image_y - $overlay_y) / 2), 0, 0, $overlay_x, $overlay_y, 100); imagejpeg($image, $image_dir.'_'.$img_url, 90); imagedestroy($image); return $image_dir.'_'.$img_url; } function page_name() { return substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1); } function curPageName() { return substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1); } function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } function cssPageLinks($total_pages, $current_page, $page_size, $parameter, $vars) { $page = 1; $record_start = 0; $page_links = ''; while ($page <= $total_pages) { if ($page != $current_page) { $page_links .= ''.$page.' '; } else { $page_links .= ''.$page.' '; } $record_start += $page_size; $page++; } return $page_links; } function pageLinks($total_pages, $current_page, $page_size, $parameter, $vars) { $page = 1; $record_start = 0; $page_links = ''; while ($page <= $total_pages) { if ($page != $current_page) { $page_links .= ''.$page.' '; } else { $page_links .= $page.' '; } $record_start += $page_size; $page++; } return $page_links; } function ajaxPageLinks($total_pages, $current_page, $page_size, $variables) { $page = 1; $record_start = 0; $page_links = ''; while ($page <= $total_pages) { if ($page != $current_page) { $page_links .= ''.$page.' '; } else { $page_links .= ''.$page.' '; } $record_start += $page_size; $page++; } return $page_links; } function _is_valid_email($email = "") { return preg_match('/^[.\w-]+@([\w-]+\.)+[a-zA-Z]{2,6}$/', $email); } function shorten($text, $limit) { $text = str_replace('

', ' ', str_replace('

', '', $text)); $text = str_replace('
', ' ', $text); $text = str_replace('
', ' ', $text); $text = str_replace('', '', str_replace('', '', $text)); $text = str_replace('', '', str_replace('', '', $text)); if (strlen($text) > $limit) { $text = substr($text, 0, strrpos(substr($text, 0, $limit), ' ')).'...'; } return $text; } function cut($text, $limit) { if (strlen($text) > $limit) { $text = substr($text, 0, $limit).'...'; } return $text; } function paragraph($text) { $count = 0; $text_array = split("[.]", $text); foreach ($text_array as $sentence) { if (strlen($sentence) > 10) { if ($count % 2 != 0) { $formatted_text .= ucfirst($sentence).".
"."\n"; $count++; } else { $formatted_text .= ucfirst($sentence).".

"."\n"; $count++; } } } return $formatted_text; } function unparagraph($text) { $text = rtrim(str_replace('

', '

', str_replace('

', '', $text)), '

'); return $text; } function deleteFile($filename) { $file_deleted = false; if (file_exists($filename)) { unlink($filename); $file_deleted = true; } return $file_deleted; } function gen_drop_menu($menu_name, $option_list, $current_option, $function='') { $menu = ''."\n"; return $menu; } function gen_drop_menu_extra($menu_name, $select='Please Select', $option_list, $current_option, $function='') { $menu = ''."\n"; return $menu; } function integerDrop($menu_name, $select='', $option_list, $current_option, $function='') { $menu = ''."\n"; return $menu; } ?>