function main($school = null, $sex = null, $sale = null, $product = null, $expired = false)
 {
     //can be submitted from no javascript find school form or landing form
     if (isset($_POST['school-id'])) {
         $school = $_POST['school-id'];
         $this->Session->write('Anonymous.school', $school);
     }
     if (isset($_POST['sex'])) {
         $sex = $_POST['sex'];
         $this->Session->write('Anonymous.sex', $sex);
     }
     //$this->layout = 'default';
     $imageIndex = 0;
     //fix data if needed
     $this->fixVars($product, $school, $sex, $sale, $expired);
     $products = $this->getProductsDetails($sale);
     //get left and right products
     $productRight = array();
     $this->getPagination($products, $product, $productRight, $index);
     $this->Saleuser->addUserSaleEndDate($this->myuser, $sale['Sale']['id']);
     $this->addSaleEnds($this->myuser, $sale);
     //check the found sale has not expired for the user
     //$sale['Sale']['UserSaleEnds']  is added to $sale in addSaleEnds call
     if ($sale['Sale']['UserSaleEnds'] < time() && !Configure::read('config.testing')) {
         $this->redirect(array('action' => 'expiredsale/' . $sale['Sale']['id'] . '/' . $this->myuser['User']['id'] . '/' . $school['id'] . '/' . $sex));
     }
     $mfgs = $this->Product->Manufacturer->find('list', array('fields' => array('id', 'image')));
     $products = array_merge(array($product['Product']), $productRight);
     //lets remove the first time here stuff
     $this->User->Prompt->removeFirstTimePrompt($this->myuser['User']['id']);
     //determine the color for the current school
     $sql = 'SELECT school_id, color_id FROM `schools_colors` WHERE school_id = ' . $school['id'] . ' ORDER BY `id` ASC';
     $schoolColors = $this->Product->query($sql);
     //build navigation links for no-javascript
     $currentLink = "/shop/main/{$school['id']}/{$sex}/{$sale['Sale']['id']}/{$products[0]['id']}";
     if (!$this->Session->check('shop.nav.sale') || $this->Session->read('shop.nav.sale') != $sale['Sale']['id']) {
         $temp = array();
         foreach ($products as $p) {
             $link = "/shop/main/{$school['id']}/{$sex}/{$sale['Sale']['id']}/{$p['id']}";
             array_push($temp, $link);
         }
         $this->Session->write('shop.nav.links', $temp);
         $this->Session->write('shop.nav.sale', $sale['Sale']['id']);
     }
     $found = false;
     $prev = $next = array();
     foreach ($this->Session->read('shop.nav.links') as $link) {
         if ($link == $currentLink) {
             $found = true;
         } else {
             if (!$found) {
                 array_push($prev, $link);
             } else {
                 array_push($next, $link);
             }
         }
     }
     $nextLink = isset($next[0]) ? $next[0] : "/accessories/index/{$school['id']}/{$sex}";
     $prevLink = isset($prev[0]) ? $prev[0] : '#';
     $this->Session->write('shop.nav.next', $nextLink);
     $this->Session->write('shop.nav.prev', $prevLink);
     $this->Session->write('shop.nav.curr', $currentLink);
     $this->set(compact('nextLink', 'prevLink', 'currentLink'));
     foreach ($products as $k => $p) {
         $products[$k]['mfgimage'] = $mfgs[$products[$k]['manufacturer_id']];
         foreach ($p as $key => $entry) {
             if (!in_array($key, array('id', 'pricetag'))) {
                 unset($products[$k][$key]);
             }
         }
     }
     //$schools = $this->School->find('all',array('recursive'=>0));
     $schools = $this->School->getSchoolsWithSale();
     $fbcommentId = "{$school['id']}-{$sex}-{$sale['Sale']['id']}-{$product['Product']['id']}";
     $shareImage = null;
     foreach ($product['Pimage'] as $entry) {
         if (preg_match('/front/i', $entry['name'])) {
             $shareImage = $entry['image'];
             //$shareImage = 'http://www.flyfoenix.com/img/referral.jpg';
             break;
         }
     }
     $this->set(compact('school', 'schools', 'sex', 'sale', 'product', 'products', 'productRight', 'imageIndex', 'fbcommentId', 'schoolColors', 'shareImage'));
     //accessories
     $adata = !empty($schoolColors) ? $this->getAccessories($sex, $schoolColors[0]['schools_colors']['color_id']) : array();
     //add any flash messages
     $flash = strlen($this->Session->read('Message.flash.message')) > 0 ? $this->Session->read('Message.flash.message') : '';
     //delete the flash message
     $this->Session->delete('Message.flash');
     //if the user is not logged in, then prompt them with the login
     $showFirstTime = false;
     if (!$this->Auth->user() && !$this->Session->check('Anonymous.firstpage')) {
         App::import('Component', 'Cfacebook');
         $Cfacebook = new CfacebookComponent();
         $this->Cfacebook = $Cfacebook->initialize(&$this);
         $showFirstTime = true;
         $this->Session->write('Anonymous.firstpage', true);
         $email = '';
         $registering = false;
         if ($this->Session->check('registerData')) {
             $registering = true;
             $postdata = $this->Session->read('registerData');
             $email = isset($postdata['User']['email']) ? $postdata['User']['email'] : '';
             $sex = isset($postdata['User']['sex']) ? $postdata['User']['sex'] : $sex;
             $school['id'] = isset($postdata['School']['School']['id']) ? $postdata['School']['School']['id'] : $school['id'];
         }
         $register = "\r\n\t\t\t\r\n\t\t\t<div class='big title' style='color:#333'>Pernsonalized Shopping</div>\r\n\t\t\t<p>FlyFoenix can remember your preferences for when your return.\r\n\t\t\t</p>\r\n\t\t\t\r\n\t\t\t<form id='register-pop' method='post' action='/users/register'>\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\t<div id='fb1' style='float:right;text-align:right;'>\r\n          \t\t\t<span style='font-size:12px;padding-right:4px'>Save w/ Facebook</span><br />\r\n          \t\t\t\r\n\t\t\t        <input id='fb-reg' style='padding-left:45px;background-position: left -60px;' type='button' value='Save ' class='big green btn fb_button' />\r\n\t\t\t        \r\n          \t\t</div><!-- End fb1 -->\r\n\t\t\t\t\r\n          \t\t <div style='float:right;font-size:12px;padding:25px 10px 0px 10px'><i>- OR -</i></div>\r\n          \t\t\r\n          \t\t<div style='float:right'>\r\n\t\t\t\t<span style='font-size:12px'>&nbsp;</span><br />\r\n\t\t\t\t<input type='submit' class='big green btn' value='Save' />\r\n\t\t\t\t</div>\r\n          \t\t\r\n\t\t\t\t<input id='reg-sale' type='hidden' value='{$sale}' name='data[Sale][Sale][id]' />\r\n\t\t\t\t<input id='reg-school' type='hidden' value='{$school['id']}' name='data[School][School][id]' />\r\n\t\t\t\t<input id='reg-sex' type='hidden' value='{$sex}' name='data[User][sex]' />\r\n\t\t\t\t\r\n\t\t\t\t<div style='display:inline-block;position:relative;top:5px'>\r\n\t\t\t\t<span style='font-size:12px;'>Email</span><br/>\r\n\t\t\t\t<input id='email' type='text' style='width:150px;background-color:#FFF' class='input' name='data[User][email]' value='{$email}' />\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t</form>\r\n\t\t\t\r\n\t\t\t";
         if (!$this->Session->check('Anonymous.school')) {
             $mselected = strtolower($sex) == 'm' ? 'checked' : '';
             $fselected = strtolower($sex) != 'm' ? 'checked' : '';
             $html = "\r\n\t\t\t\t<div id='reg-wrapper' style='position:relative;width:400px;height:140px;overflow:hidden;'>\r\n\t\t\t\t\t<div id='reg-inner-wrapper' style='position:relative;left:0px;width:900px'>\r\n\t\t\t\t\t\t<div id='reg-school-wrapper' style='width:400px;position:absolute;left:0px;top:0px;'>\r\n\t\t\t\t\t\t<div class='big title' style='color:#333'>Your preferred School and Gender?</div>\r\n\t\t\t\t\t\t<p>\r\n\t\t\t\t\t\t<span class='six'>Gender&nbsp;&nbsp;</span><br />\r\n\t\t\t\t\t\t<label for='reg-male'><input name='sex' id='reg-male' type='radio' value='M' {$mselected} />&nbsp;&nbsp;Male</label>&nbsp;&nbsp;&nbsp;&nbsp; \r\n\t\t\t\t\t\t<label for='reg-female'><input name='sex' id='reg-female' type='radio' value='F' {$fselected} />&nbsp;&nbsp;Female</label>\r\n\t\t\t\t\t\t</p>\r\n\t\t\t\t\t\t<!-- The onclick is set in shop layout //-->\r\n\t\t\t\t\t\t<input id='reg-cont' type='button' value='Continue' class='big green btn' style='float:right;margin-top:10px' />\r\n\t\t\t\t\t\t<p>\r\n\t\t\t\t\t\t\t<span class='six'>School&nbsp;&nbsp;</span><br />\r\n\t\t\t        \t\t<select class='' name='school-id'  style='width:200px;background-color:#FFF'>\r\n\t\t\t\t\t\t\t\t";
             //make school select options
             foreach ($schools as $s) {
                 $selected = $s['School']['id'] == $school['id'] ? 'selected' : '';
                 $html .= "<option value='{$s['School']['id']}' {$selected} >{$s['School']['long']}</option>";
             }
             $html .= "</select>\r\n\t\t\t\t\t\t</p>\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t\r\n\t\t\t\t\t\t<div id='reg-user-wrapper' style='width:400px;position:absolute;left:410px;top:0px;padding:0px;'>\r\n\t\t\t\t\t\t{$register}\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t";
             $flash .= $html;
         } else {
             $flash .= $register;
         }
     }
     $breaks = array("\r\n", "\n", "\r", "\t");
     $flash = str_replace($breaks, '', $flash);
     $flash = str_replace('\'', '\\\'', $flash);
     //set the data
     $this->set(compact('adata', 'colors', 'swatches', 'images', 'pdetails', 'flash', 'showFirstTime'));
 }
 function landing($sex = null, $err = null)
 {
     //force logged-in users to shop
     if ($this->Auth->user()) {
         $this->redirect(array('controller' => 'shop', 'action' => 'main'));
     }
     $this->layout = 'dynamic_with_school';
     //$this->layout = 'default';
     $this->set('classWidth', 'width-custom');
     $this->set('bgImg', '/img/schools/background/flyfoenix_landingpage_background_03.jpg');
     $this->set('shareImage', 'http://www.flyfoenix.com/img/referral.jpg');
     $this->set('jsFilesBottom', array('/js/miocarousel.js'));
     $this->set('cssFiles', array('/css/landing.css'));
     App::import('Component', 'Cfacebook');
     $Cfacebook = new CfacebookComponent();
     $this->Cfacebook = $Cfacebook->initialize(&$this);
     //template needs some vars at a minimum
     $sex = empty($sex) || !preg_match('/MF/i', $sex) ? 'F' : $sex;
     $schools = $this->School->find('all');
     $this->set(compact('sex', 'schools'));
     $this->addCarouselImages();
     //if there was a login error from register or login
     if (!empty($err)) {
         $error = new MyError($err);
         $this->set('error', $error->getJson());
         $errors[$error->getDOMid()] = $error;
         $this->set('errors', $errors);
         return;
     }
     //AuthComponent does not encrypt password by default if the you are not
     //using "username" as the identifier.
     if (!empty($this->data)) {
         //look for user
         if (!$this->User->checkEmailExists($this->data)) {
             $error = new MyError('no_user');
             $this->set('error', $error->getJson());
             $errors[$error->getDOMid()] = $error;
             $this->set('errors', $errors);
             return;
         }
         //encrypt password
         $this->data['User']['password'] = AuthComponent::password($this->data['User']['email']);
         //login the user
         if ($this->Auth->login($this->data)) {
             //user is logged in, forward to the shop
             $this->redirect('/shop/main');
             return;
         } else {
             $error = new MyError('emailerror');
             $this->set('error', $error->getJson());
             $errors[$error->getDOMid()] = $error;
             $this->set('errors', $errors);
             return;
         }
     }
     $error = new MyError('no_error');
     $this->set('error', $error->getJson());
 }