"; } // load css file // ------------- function loadCSS($file = null) { echo ""; } // requires a PHP class // -------------------- function loadClass($file = null) { require_once (CLASSES_DIR . $file); } // loads a helper // -------------- function loadHelper($file = null) { require_once(HELPERS_DIR . $file); } function currentPage() { $url = $_SERVER['REQUEST_URI']; $s = split("\?",$url); return $s[0]; } function redirect($url) { header("Location:" . APP_ROOT . $url); exit(); } function bannerLeft() { if (file_exists(ROOT . IMAGES_DIR . "banners/banner-left.jpg")) { echo ""; }else{ echo " "; } } function bannerRight() { if (file_exists(ROOT . IMAGES_DIR . "banners/banner-right.jpg")) { echo ""; }else{ //require(GOOGLE_ADS); echo " "; } } function googleCode($section = null) { switch($section) { case "community": { echo " "; break; } case "marketing": { echo " "; break; } } } } ?>SQL->quoteSmart($this->tableName) . " WHERE id='" . $this->SQL->quoteSmart($this->id) . "'"; $this->DB->query($sql); $r = $this->DB->getArray(); if ($r) { $this->parseData($r[0]); } $this->postLoad(); return $r[0]; } /**************************************************************** LOAD DATA FROM CURRENT TABLE BY PROVIDED FIELD ****************************************************************/ function loadByField($field = null, $value) { $sql = "SELECT * FROM " . $this->SQL->quoteSmart($this->tableName) . " WHERE " . $this->SQL->quoteSmart($field) . "='" . $this->SQL->quoteSmart($value) . "'"; $this->DB->query($sql); $r = $this->DB->getArray(); if ($r) { $this->parseData($r[0]); } $this->postLoad(); } /**************************************************************** ADD TO DATABASE ****************************************************************/ function add() { $this->presave(); //current class $fields_array = $this->getColumnNames($this->tableName); $sql = "INSERT INTO " . $this->SQL->quoteSmart($this->tableName) . " ("; foreach($fields_array as $fieldName) //field names { //check to see if any fields have to be excluded $match = false; foreach($this->exclude_array as $excluding) { if ($excluding == $fieldName) { $match = true; break; } } // if(isset($this->$fieldName)) { if ($match == false) $sql .= $fieldName . ","; } } $sql = substr($sql,0,strlen($sql)-1); // remove last comma $sql .= ") VALUES ("; foreach($fields_array as $fieldName) //values { //check to see if any fields have to be excluded $match = false; foreach($this->exclude_array as $excluding) { if ($excluding == $fieldName) { $match = true; break; } } // if(isset($this->$fieldName)) { if ($match == false) $sql .= "'" . $this->SQL->quoteSmart($this->$fieldName) . "',"; } } $sql = substr($sql,0,strlen($sql)-1); // remove last comma $sql .= ")"; $this->DB->query($sql); $this->id = $this->DB->lastRow(); $this->postsave(); } function update($idField = "id") { $this->presave(); //create query $fields_array = $this->getColumnNames($this->tableName); $sql = "UPDATE " . $this->SQL->quoteSmart($this->tableName) . " SET "; foreach($fields_array as $fieldName) //field names { //check to see if any fields have to be excluded $match = false; foreach($this->exclude_array as $excluding) { if ($excluding == $fieldName) { $match = true; break; } } // if ($match == false && isset($this->$fieldName)) $sql .= $fieldName . "='" . $this->SQL->quoteSmart($this->$fieldName) ."',"; } $sql = substr($sql,0,strlen($sql)-1); // remove last comma $sql .= " WHERE $idField='" . $this->SQL->quoteSmart($this->$idField) . "'"; $this->DB->query($sql); $this->postsave(); return $this->DB->updatedRows(); } /**************************************************************** DELETE AN ITEM FROM THE DATABASE ****************************************************************/ function delete() { $sql = "DELETE FROM " . $this->SQL->quoteSmart($this->tableName) . " WHERE id='" . $this->SQL->quoteSmart($this->id) . "'"; $this->DB->query($sql); $this->postDelete(); } /**************************************************************** CREATES LOCAL VARIABLES USING AN ARRAY ****************************************************************/ function prepareValues($data) { foreach($data as $name => $value) { $this->$name = $value; } } function parseData($data) { //echo var_dump(debug_backtrace()); if(is_array($data) && !empty($data)) { foreach($data as $name => $value) { $this->$name = $value; } } } //get table names function getColumnNames($table) { $DB = new Database(); $DB->query("show columns from $table"); $cl_array = $DB->getArray(); $tbl = array(); for ($i=0 ;$i < sizeof($cl_array); $i++) { $tbl[] = $cl_array[$i]['Field']; } return($tbl); } //creates a random password for the user function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } //returns the total entries is a table function totalEntries($table = null, $field = null,$value = null) { $t = ($table)? $table : $this->tableName; $sql = "SELECT COUNT(*) AS count FROM " . $this->SQL->quoteSmart($t); if($field) { $sql .= " WHERE " . $this->SQL->quoteSmart($field) . "='" . $this->SQL->quoteSmart($value) . "'"; } $this->DB->query($sql); $r = $this->DB->getArray(); return $r['0']['count']; } // create page links // ----------------- function pages($url = null, $varDivider = "?", $passPage = null, $passPageCount = null) { isset($this->page) ? $page = $this->page : $page = $passPage; isset($this->pageCount) ? $pageCount = $this->pageCount : $pageCount = $passPageCount; echo "
"; for($i = 1; $i <= $pageCount; $i++) { if($i == $page) { echo ""; }else{ echo ""; } } echo "
Page " . $page . " of " . $pageCount . "$i$i
"; } // keep query for pagination links // ------------------------------- function pages_query($value) { if(!$_SERVER['QUERY_STRING']) { $query = "?page=" . $value; } else { $query = $_SERVER['QUERY_STRING']; $query = preg_replace("/(|&)page=([0-9]{1,3})/", "", $query); $query = str_replace("&", "&", $query); ($query == "") ? $amp = "" : $amp = "&"; $query = "?" . $query; $query .= $amp . "page=" . $value; } return $query; } // create pagination links // ----------------------- function pagination($passPage = NULL, $passPageCount = NULL) { $pageBuffer = 7; // how many numbers to show on each side of current page number $i = 0; isset($this->page) ? $page = $this->page : $page = $passPage; isset($this->pageCount) ? $pageCount = $this->pageCount : $pageCount = $passPageCount; if($page <= 1) { $previousBtn = ""; } else { $previous = $this->pages_query($page - 1); $previousBtn = "« previous"; } if($page >= $pageCount) { $nextBtn = ""; } else { $next = $this->pages_query($page + 1); $nextBtn = "next »"; } $pageLinks = "
Pages: " . $previousBtn . "\n"; if($page - $pageBuffer > 1) { $pageLinks .= "pages_query(1) . "\">1..."; } for($j = 0; $j < $pageCount; $j++) { $i++; if($i >= ($page - $pageBuffer) && $i <= ($page + $pageBuffer)) { ($page == $i) ? $code = " class=\"current\"" : $code = ""; $query = $this->pages_query($i); $pageLinks .= "" . $i . " "; } } if($page + $pageBuffer < $pageCount) { $pageLinks .= "...pages_query($pageCount) . "\">" . $pageCount . ""; } $pageLinks .= $nextBtn . "
"; echo $pageLinks; } //changes string values function getDisplayString($file,$data = null, $run_scripts = false) { if($run_scripts) { $newString = $this->_getFileString($file,$data); }else{ $newString = file_get_contents($file); if($data) { foreach($data as $name=>$value) { $newString = str_replace("||$name||", $value,$newString); } } } $newString = str_replace("||app_root||", APP_WEB_ROOT, $newString); $newString = str_replace("||images_dir||", IMAGES_DIR, $newString); $newString = str_replace("||template_top||", file_get_contents(PAGES_DIR . "notifications/template_top.html"), $newString); $newString = str_replace("||goal_template_top||", file_get_contents(PAGES_DIR . "notifications/goal_template_top.html"), $newString); $newString = str_replace("||template_bottom||", file_get_contents(PAGES_DIR . "notifications/template_bottom.html"), $newString); return $newString; } function _getFileString($file_path,$data = null) { extract($data, EXTR_SKIP); ob_start(); include($file_path); return ob_get_clean(); } // create a directory if it does not exists // ---------------------------------------- function makeDirectory( $dirPath ){ if( !is_dir( $dirPath ) ){ if ( mkdir( $dirPath ) ){ return true; }else{ return false; } } } // create a slug out of a string function slug($string,$settings = null) { if(!$settings) { $settings = array( 'separator' => "_", 'length' => "100", ); } $string = strtolower($string); $string = preg_replace('/[^a-z0-9_]/i', $settings['separator'], $string); $string = preg_replace('/' . preg_quote($settings['separator']) . '[' . preg_quote($settings['separator']) . ']*/', $settings['separator'], $string); if (strlen($string) > $settings['length']) { $string = substr($string, 0, $settings['length']); } $string = preg_replace('/' . preg_quote($settings['separator']) . '$/', '', $string); $string = preg_replace('/^' . preg_quote($settings['separator']) . '/', '', $string); return $string; } # get file for a directory # ------------------------ function _parseDirectory($root_dir,$dir,&$fileList) { $files = scandir($dir); //debug($files); $currentDirectory = str_replace($root_dir,"",$dir); foreach($files as $item) { # ignore items if($item == ".." || $item == '.' || $item == ".DS_Store" || $item == ".svn") continue; # if item is a file if(!is_dir($dir.$item)) { $fileList[] = $currentDirectory . $item; }else{ $newPath = $root_dir . $currentDirectory . $item ."/"; $this->_parseDirectory($root_dir,$newPath,$fileList); } } return; } # load all items in a table function loadAll($conditions = null,$fields=null,$options = null) { $fields = ($fields)? implode(',',$fields) : "*"; $sortBy = isset($options['sort'])? $options['sort'] : null; $sortDir = isset($options['direction'])? $options['direction']: null; $sql = "SELECT {$fields} FROM " . $this->SQL->quoteSmart($this->tableName); if($conditions) { $sql .= " WHERE {$conditions}"; } if($sortBy) $sql .= " ORDER BY {$sortBy} {$sortDir}"; $this->DB->query($sql); $r = $this->DB->getArray(); return $r; } # markRecord as deleted function markAsDeleted($id,$user_id) { $sql = "UPDATE {$this->SQL->quoteSmart($this->tableName)} SET is_deleted = 1, deleted_by = '{$this->SQL->quoteSmart($user_id)}' WHERE id='{$this->SQL->quoteSmart($id)}'"; $this->DB->query($sql); return true; } //default function function presave(){} function postsave(){} function postLoad(){} function postDelete(){} }//end class ?> DB = new Database(); $this->SQL = new sqlHelper(); } function submitApplication($email = null) { $receiver = ($email)? $email : "[email protected]"; $body = ""; $altBody = ""; foreach($_POST as $name =>$values) { $c = ""; if(is_array($values)) //if is an array { foreach($values as $index=>$value) { $c .= $value . ", "; } }else{ $c = $values; } $body .= $name . ": " . $c . "
"; $altBody .= $name . ": " . $c . "\r"; } //exit(); $mail = new PHPMailer(); $mail->From = $_POST['Email']; $mail->FromName = "StephenCovey.com Website Submission"; $mail->AddAddress($receiver); //$mail->AddAddress("[email protected]"); $mail->IsHTML(true); // set email format to HTML $mail->Subject = $_POST['origin']; $mail->Body = $body; $mail->AltBody = $altBody; $mail->Send(); } function saveEntry($tableName) { $sql = "INSERT INTO " . $this->SQL->quoteSmart($tableName) . "(email,name,date) VALUES( '" . $this->SQL->quoteSmart($_POST['email']) . "', '" . $this->SQL->quoteSmart($_POST['name']) . "', '" . date("Y-m-d") ."')"; $this->DB->query($sql); } } // end class ?>