redirect('/'); header( 'Location: ' . MAIN_SITE_URL ); } else{ $this->set("id", $id); $this->data=$this->User->findById($this->_salt_decode($id)); } if(!empty($this->data)){ $this->data['User']['height']=$this->data['User']['height_ft']*12+$this->data['User']['height_in']; $this->User->save($this->data); $this->data['User']['id']=$this->_salt_encode($this->User->id); $_results=$this->_getResults($this->data); $_results=$this->_sorter($_results); $_results=$this->_removeDupes($_results); $this->set("results", $_results); $this->set("ski_size", $this->_lookupSize($this->data['User']['height'], $this->data['User']['weight'])); $this->set("id", $id); $this->set("ski_types", $this->Ski_type->find("list")); $this->render('results2'); } else{ // $this->redirect('/'); header( 'Location: ' . MAIN_SITE_URL ); } } function single($id, $rank=0, $pick=0){ $this->layout=false; $result=$this->Item->findById($id); $result['Quality']=$rank; if($pick==1) $pick="First"; if($pick==2) $pick="Second"; if($pick==3) $pick="Third"; if($pick==4) $pick="Fourth"; if($pick==5) $pick="Fifth"; $result['Pick']=$pick; $this->set('result', $result); } function getinfo($id=0){ if(!empty($this->data)){ $this->data['User']['height']=($this->data['User']['height_ft']*12)+$this->data['User']['height_in']; $this->User->save($this->data); // $this->redirect('/ski/search/'.$id); header( 'Location: ' . MAIN_SITE_URL . '/ski/search/'.$this->_salt_encode($this->User->id)); } if($id){ $this->data=$this->User->findById($this->_salt_decode($id)); } $this->render('search1'); } function search($id=0){ if(!empty($this->data)){ $this->User->save($this->data); //$this->redirect('/ski/results/'.$this->User->id); $this->data["User"]["id"]=$this->_salt_encode($this->data["User"]["id"]); $this->render('interstitial'); return; } if($id) { $this->data=$this->User->findById($this->_salt_decode($id)); } else { // $this->redirect('/ski/getinfo'); header( 'Location: ' . MAIN_SITE_URL . '/ski/getinfo' ); } $this->set('ski_types', array('0'=>'Select Type')+$this->Ski_type->find('list')); $this->set('race_types', array('0'=>'Select Event')+$this->Ski2_type->find('list', array('conditions'=>array('ski_type_id'=>3)))); $this->set('level', array('Level 1
Beginner', 'Level 2
Capable', 'Level 3
Intermediate', 'Level 4
Advanced', 'Level 5
Shredder')); $this->set('countries', array('NA'=>"North America", "SA"=>"South America", "EU"=>"Europe", "AS"=>"Asia", "AU"=>"Australia")); $this->set('coasts', array('0'=>'Select Area', "EastCoast"=>"East Coast", "Midwest"=>"Mid-West", "Rockies"=>"Rockies", "Far-west"=>"Far West", "Pac-northwest"=>"Pacific Northwest", "Alaska"=>"Alaska")); } //slug is not really used -- just for SEO function view($id=null, $slug=null) { //debug($id); //debug($slug); if ($id) { $ski = $this->Item->findById($id); $sizes = $this->Item->find('all', array('conditions'=> array( 'Item.Name'=> $ski['Item']['Name'], 'company_id'=> $ski['Item']['company_id'], 'Style'=> $ski['Item']['Style'] ), 'order'=>'Size', 'fields'=>'DISTINCT Size', 'group'=>'size')); $this->set(compact('ski', 'sizes')); $this->pageTitle = $ski['Item']['Name'] . ' ski reviews and ski deals'; } else { $this->redirect('/'); } } function browse_results() { $this->layout = false; if (isset($this->params['named']) && ! empty($this->params['named'])) { foreach($this->params['named'] as $key => $param) { $this->data[$key] = explode(',', $param); } } //debug($this->data); if( ! empty($this->data)){ if ( ! empty($this->data['company_id'])) { $conditions['company_id'] = $this->data['company_id']; } if ( ! empty($this->data['item_type_id'])) { $conditions['item_type_id'] = $this->data['item_type_id']; } if ( ! empty($this->data['ski_type'])) { $conditions['ski2_type_id'] = $this->data['ski_type']; } if ( ! empty($this->data['age'])) { if (count($this->data['age'])==2) { // both options selected - no filtering } else { if (in_array('Junior', $this->data['age'])) { $conditions['Junior'] = 1; } elseif ((in_array('Adult', $this->data['age']))) { $conditions['Adult'] = 1; } } } if ( ! empty($this->data['gender'])) { if (count($this->data['gender'])==2) { // both options selected - no filtering } else { if (in_array('Female', $this->data['gender'])) { $conditions['Female'] = 1; } elseif ((in_array('Male', $this->data['gender']))) { $conditions['Male'] = 1; } } } if ( ! empty($this->data['frontside_powder'])) { if (count($this->data['frontside_powder'])==2) { // both options selected - no filtering } else { if (in_array('Frontside >= 50%', $this->data['frontside_powder'])) { $conditions['Frontside >='] = 0.5; } elseif ((in_array('Powder >= 50%', $this->data['frontside_powder']))) { $conditions['Frontside <='] = 0.5; } } } if ( ! empty($this->data['level'])) { $max = max($this->data['level']); $min = min($this->data['level']); $conditions['LevelLow <='] = $max; $conditions['LevelHigh >='] = $min; } if ( ! empty($this->data['accolades'])) { if (count($this->data['accolades'])==2) { // both options selected - no filtering } else { if (in_array(1, $this->data['accolades'])) { $conditions['TotalAccolades >='] = 1; } elseif (in_array(2, $this->data['accolades'])) { $conditions['TotalAccolades >'] = 1; } } } } //debug($conditions); $order = array('Item.Name' => 'asc'); $limit = 25; $fields = 'DISTINCT Item.Name, Item.*,ItemType.*, Company.*, Ski2_type.*'; $group = 'Item.Name'; $this->paginate = compact('conditions', 'order', 'limit', 'fields', 'group'); $results = $this->Paginate('Item'); //debug($results); $names = Set::extract($results, '{n}.Item.Name'); //debug($names); $sizes = $this->Item->find('all', array('conditions'=> array('Item.Name'=>$names), 'order'=>'Item.Name, Item.size', 'fields'=>array('DISTINCT Size', 'Name'), 'group'=>'Size')); $size_array = array(); foreach($sizes as $size) { //if (isset($size_array[$size['Item']['Name']])) { $size_array[$size['Item']['Name']][] = $size['Item']['Size']; //} } //debug($size_array); foreach ($size_array as $name => $sizes) { foreach($results as &$ski) { if ($ski['Item']['Name']==$name) { $ski['Sizes'] = $sizes; break; } } } //debug($results); $this->set('items', $results); } function browse($item_type_name=null) { ////$this->layout = 'browse'; $this->set('layout_type', 'browse'); if(!$item_type_name ){ $item_type_name = 'Skis'; $this->set('item_type_actual', 'browse'); } $this->pageTitle = "Browse $item_type_name"; $item = $this->ItemType->find('first', array('conditions' => array('name'=>$item_type_name))); $item_id = $item['ItemType']['id']; $this->data['item_type_id'] = array($item_id); $company_ids = $this->Item->find('all', array('recursive' => -1, 'group' => array('Item.company_id'), 'order' => array('Item.company_id' => 'asc'), 'conditions' => array('Item.item_type_id' => $this->data['item_type_id']))); $company_ids = Set::extract($company_ids, '/Item/company_id'); $accolades = $this->Item->find('all', array('recursive' => -1, 'group' => array('Item.TotalAccolades'), 'conditions' => array('Item.item_type_id' => $this->data['item_type_id']))); $accolades = Set::extract($accolades, '/Item/TotalAccolades'); $this->loadModel('Company'); $this->Company->Behaviors->attach('Containable'); $this->Company->contain(); $companies = $this->Company->find('all', array('order' => array('Name'=>'asc'), 'conditions' => array('id' => $company_ids))); $this->set('companies', $companies); $this->ItemType->Behaviors->attach('Containable'); $this->ItemType->contain(); $item_types = $this->ItemType->find('all', array('order' => array('Name'=>'asc'))); $this->set('item_types', $item_types); $this->set('item_type_name', $item_type_name); $this->Ski2_type->Behaviors->attach('Containable'); $this->Ski2_type->contain(); $ski_type_ids = $this->Item->find('all', array('recursive' => -1, 'group' => array('Item.ski2_type_id'), 'conditions' => array('Item.item_type_id' => $this->data['item_type_id']))); $ski_type_ids = Set::extract($ski_type_ids, '/Item/ski2_type_id'); $ski_types = $this->Ski2_type->find('all', array('order' => array('name'=>'asc'), 'conditions' => array('id' => $ski_type_ids) ) ); //debug($ski_types); $this->set('ski_types', $ski_types); if($item_type_name == 'Skis'){ $this->set('frontside_powder', array('Frontside >= 50%', 'Powder >= 50%')); } $this->set('ages', array('Adult', 'Junior')); $this->set('genders', array('Male', 'Female')); $this->set('levels', array(1 => 'Beginner', 2 => 'Capable', 3 => 'Intermediate', 4 => 'Advanced', 5 => 'Shredder')); if(count($accolades) > 1){ $this->set('accolades', array(1 => '1 or more', 2 => '2 or more')); } } function _getResults($data){ if($data['User']['ski_type_id']==3){ $data['User']['ski_type_id']=$data['User']['ski2_type_id']; } else{ $data['User']['ski_type_id']=$this->Ski2_type->findBySki_type_id($data['User']['ski_type_id']); $data['User']['ski_type_id']=$data['User']['ski_type_id']['Ski2_type']['id']; } $data['User']['Frontside']*=.01; return $this->_getSkis($data['User']['height'], $data['User']['weight'], $data['User']['ski_type_id'], $data['User']['gender'], $data['User']['age'], $data['User']['coast'], $data['User']['Frontside'], $data['User']['level'], $data['User']['technicals'], $data['User']['park'], $data['User']['telemark'], $data['User']['touring']); } /* function rotate_images() { // REMOVE AFTER RUNNING $this->autoRender = false; ini_set('max_execution_time', "240"); $skis = $this->Item->find('all', array('fields'=> array('distinct("Item.PictureLink"), Item.PictureLink'))); //debug($skis); foreach ($skis as $ski) { $file_path = $ski['Item']['PictureLink']; $file_parts = explode('/', $file_path); $filename = end($file_parts); $new_file = WWW_ROOT . "img/rotated_images/" . $filename; if(!file_exists($new_file)){ // rotate image 90 degrees $degrees = 90; // Content type //header('Content-type: image/jpeg'); // Load $source = imagecreatefromjpeg($file_path); if(!$source){ $source = imagecreatefrompng($file_path); } // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagejpeg($rotate, $new_file); debug($new_file); }else{ echo "WOOO
"; } } } function generateNames(){ $this->autoRender = false; $this->loadModel('Company'); //$this->Company->Behaviors->attach('Containable'); $this->Company->contain(); $skis = $this->Item->find('all', array('contain' => array('Company'))); foreach ($skis as $ski){ $ski['Item']['Name'] = $ski['Company']['name'] . ' ' . $ski['Item']['Model']; $this->Item->save($ski); } print 'all done!'; } */ function _getSkis($height, $weight, $type, $gender, $age, $coast, $frontside, $level, $tech, $park, $telemark, $touring){ //$this->render(false); $size=$this->_lookupSize($height, $weight); $min=$this->Item->_getSize($type, $gender, 'min'); $max=$this->Item->_getSize($type, $gender, 'max'); $primer=$this->_getPrimer($type); $adj=$this->_getAdjSize($size, $primer, $min, $max); $this->data['adj_size']=$adj; $this->data['min']=$min; $this->data['max']=$max; $this->data['primer']=$primer; $this->data['size']=$size; return $this->_rankSkis($adj, $frontside, $this->_lookupSkis($adj, $type, $gender, $age, $level, $coast, $tech, $park, $telemark, $touring)); } //returns size from sizing matrix given height (inches) and weight (pounds), false if not found function _lookupSize($height, $weight){ $result=$this->Size->find('all', array( 'conditions'=>array('height'=>$height, 'weight'=>$weight))); return $result ? $result[0]['Size']['size'] : false; } //returns minimum size based on $type2, $dim (min/max) and gender(M/F) //looksup primer function _getPrimer($type2){ $params=array('conditions'=>array('ski2_type_id'=>$type2)); $result=$this->Primer->find('all', $params); return $result ? $result[0]['Primer']['primer'] : false; } //calculates adjusted size function _getAdjSize($size, $primer, $min, $max){ $adjust=($size/$max) * $primer; $adjust+=$size; if($adjust < $min){ return $min; } else if($adjust > $max){ return $max; } else{ return round($adjust); } } // $gender giver as M/F, $age given as A/J, $coast given as W/E function _lookupSkis($adj_size, $type, $gender, $age, $level, $coast=false, $tech=false, $park=false, $telemark=false, $touring=false, $mfg=false, $price=false){ switch($gender){ case 'M': $gender="Male"; break; case 'F': $gender="Female"; break; default: return false; } switch($age){ case 'A': $age="Adult"; break; case 'J': $age="Junior"; break; default: return false; } $item_type = $this->ItemType->find('first', array('conditions' => array('name'=>'Skis'))); $conditions=array( 'ski2_type_id'=>$type, 'size >='=>$adj_size-10, 'size <='=>$adj_size+10, $gender=>1, $age=>1, 'LevelLow <='=>$level, 'LevelHigh >='=>$level, 'item_type_id' => $item_type['ItemType']['id']); if ($coast){ $conditions+=array($coast=>1); } if($tech){ $conditions+=array('Technicals'=>1); } if($park){ $conditions+=array('Park'=>1); } if($telemark){ $conditions+=array('Telemark'=>1); } if($touring){ $conditions+=array('Touring'=>1); } if($mfg){ $conditions+=array('company_id'=>$mfg); } if($price){ $conditions+=array('PriceRange <'=>$price); } $params=array('conditions'=>$conditions, 'recursive'=>1); $skis=$this->Item->find('all', $params); return $skis; } //reorders the $skis array according to rank function _rankSkis($adj, $frontside, $skis){ //$mag=$this->Magnitude->find('all'); foreach ($skis as &$ski){ $delta_size=abs($adj-$ski['Item']['Size']); $delta_fs=abs($frontside-$ski['Item']['Frontside'])*100; $pt1 = 20-(2*$delta_size); //1/$delta_size*$mag[0]['Magnitude']['value']; $pt2 = 20-$delta_fs; //1/$delta_fs*$mag[1]['Magnitude']['value']; $pt3 = 4*$ski['Item']['TotalAccolades']; //($ski['Item']['TotalAccolades']/3)*$mag[2]['Magnitude']['value']; $quality=($pt1+$pt2+$pt3)+50; if(!empty($ski['Item']['scoreadj'])){ $quality+=$ski['Item']['scoreadj']; } $ski['Quality']=$quality; //$ski['Ranking']=50+($quality/($mag[0]['Magnitude']['value']+$mag[1]['Magnitude']['value']+$mag[2]['Magnitude']['value'])*.5); } return $skis; } function _sorter($results){ $size=sizeof($results); do{ $tmp=array(); $swap_flag=false; for($i=0; $i<$size-1; $i++){ if( $results[$i]['Quality'] < $results[$i+1]['Quality']){ //swap $tmp=$results[$i]; $results[$i]=$results[$i+1]; $results[$i+1]=$tmp; $swap_flag=true; } } }while($swap_flag); return $results; } function _removeDupes($results){ $exist=array(); $size=sizeof($results); for($i=0; $i<$size; $i++){ if(!in_array($results[$i]['Item']['Model'], $exist)){ array_push($exist, $results[$i]['Item']['Model']); } else{ unset($results[$i]); } } return $results; } function _salt_encode($id){ //echo SALT.$id; return base64_encode(SALT.$id); } function _salt_decode($str){ $str=base64_decode($str); return substr($str, strlen(SALT)); } } ?> SkiGenie: Errors

Not Found

Error: The requested address '/' was not found on this server.

"SkiGenie is reading my mind: 2 of my skis were listed in its top 5 powder/backcountry skis for 'me'"

"Ride the right pair, with help from SkiGenie.com"

"SkiGenie, a website that's poised to do for skis what Amazon did for... everything but skis"