public function __construct($options = null, $users = array())
 {
     parent::__construct($options);
     $this->addElementPrefixPath('FM', 'FM/');
     $states = FM_Components_Util_State::getAll();
     $towns = FM_Components_Util_Town::getAll();
     $allRegions = FM_Components_Util_Region::getAll();
     $allUsers = new Zend_Form_Element_Select(array('label' => 'Administrator :', 'name' => 'admin', 'required' => 1));
     $allUsers->addMultiOption(35, ' Carmine (minodef@aol.com)');
     foreach ($users as $user) {
         if ($user->getId() != 35) {
             $allUsers->addMultiOption($user->getId(), $user->getUserName() . ' (' . $user->getEmail() . ')');
         }
     }
     $allUsers->setDecorators(array(array('ViewScript', array('viewScript' => 'form/users.phtml', 'class' => 'form element'))));
     $allUsers->setRegisterInArrayValidator(false);
     $this->addElement($allUsers);
     $this->addElement('text', 'name', array('label' => 'name :', 'name' => 'name', 'required' => 1));
     $this->addElement('text', 'website', array('label' => 'website :', 'name' => 'website', 'required' => 0));
     $this->addElement('text', 'address1', array('label' => 'address 1 :', 'name' => 'address1', 'required' => 0));
     $this->addElement('text', 'address2', array('label' => 'address 2 :', 'name' => 'address2'));
     $this->addElement('text', 'city', array('label' => 'city :', 'name' => 'city', 'required' => 0));
     $state = new Zend_Form_Element_Select(array('label' => 'state :', 'name' => 'state', 'required' => 1));
     foreach ($states as $key => $stateObj) {
         $state->addMultiOption($stateObj->getAbbr(), $stateObj->getState());
     }
     $state->setValue('NJ');
     $this->addElement($state);
     $town = new Zend_Form_Element_Multiselect(array('label' => 'town :', 'name' => 'town', 'required' => 1, 'onchange' => "FM.Utilities.setRegion(this.value)"));
     foreach ($towns as $key => $townObj) {
         $town->addMultiOption($townObj->getId(), $townObj->getName());
     }
     $this->addElement($town);
     $regions = new Zend_Form_Element_Select(array('label' => 'Region :', 'name' => 'region'));
     //foreach($users as $user) {
     //$regions->addMultiOption($user->getId(), $user->getUserName() . ' (' . $user->getEmail() . ')');
     //}
     $regions->setDecorators(array(array('ViewScript', array('viewScript' => 'form/regions.phtml', 'class' => 'form element', 'regions' => $allRegions))));
     $regions->setRegisterInArrayValidator(false);
     $this->addElement($regions);
     $this->addElement('text', 'zip', array('label' => 'zip :', 'name' => 'zip', 'required' => 0));
     $this->addElement('text', 'phone', array('label' => 'phone :', 'name' => 'phone'));
     $this->addElement('text', 'email', array('label' => 'email :', 'name' => 'email', 'required' => 0));
     $maillist = new Zend_Form_Element_Select(array('label' => 'mailing list? :', 'name' => 'maillist'));
     $maillist->addMultiOption('1', ' Yes! ');
     $maillist->addMultiOption('0', ' No ');
     $this->addElement($maillist);
     $limeCard = new Zend_Form_Element_Select(array('label' => 'lime card? :', 'name' => 'limeCard'));
     $limeCard->addMultiOption('0', ' No ');
     $limeCard->addMultiOption('1', ' Yes! ');
     $this->addElement($limeCard);
     $this->addElement('text', 'slug', array('label' => 'direct link : ', 'name' => 'slug', 'onblur' => 'FM.Client.checkSlug(this)'));
     $this->addElement('textarea', 'description', array('label' => 'description :', 'name' => 'description', 'id' => 'descriptionr', 'rows' => 3));
     $this->addDisplayGroup(array('admin', 'slug', 'limeCard'), 'admingroup');
     $this->addDisplayGroup(array('name', 'website', 'address1', 'address2'), 'bizinfo');
     $this->addDisplayGroup(array('city', 'state', 'town', 'region', 'zip'), 'locationinfo');
     $this->addDisplayGroup(array('phone', 'email', 'maillist'), 'contactinfo');
     $admingroup = $this->getDisplayGroup('admingroup');
     $bizinfo = $this->getDisplayGroup('bizinfo');
     $locationinfo = $this->getDisplayGroup('locationinfo');
     $contactinfo = $this->getDisplayGroup('contactinfo');
     $admingroup->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'h4', 'placement' => 'prepend')), 'Fieldset'));
     $bizinfo->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'h4', 'placement' => 'prepend')), 'Fieldset'));
     $contactinfo->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'h4', 'placement' => 'prepend')), 'Fieldset'));
     $locationinfo->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'h4', 'placement' => 'prepend')), 'Fieldset'));
 }
 public function buildFromNpSearchObj($searchComponent)
 {
     if (count($regions = $searchComponent->getRegions())) {
         foreach ($regions as $key => $regionId) {
             $towns = FM_Components_Util_Region::getTownIdsByRegion($regionId);
             foreach ($towns as $index => $town) {
                 $searchComponent->addTown($town);
             }
         }
     }
     switch ($searchComponent->getType()) {
         case 3:
             $table = ' FM.orgdata ';
             break;
     }
     $query = "SELECT o.* FROM FM.orgdata o ";
     if (count($towns = $searchComponent->getTowns())) {
         $query .= " JOIN FM.org_town ot ON ot.orgId = o.id ";
     }
     if (count($categories = $searchComponent->getCategories())) {
         $query .= " LEFT OUTER JOIN FM.nporg_cat bc ON bc.orgId = o.id ";
     }
     if ($sports = count($categories = $searchComponent->getCategories()) && in_array(12, $categories)) {
         $query .= " LEFT OUTER JOIN FM.orgdata_sports sc ON sc.orgId = o.id ";
     }
     $query .= "WHERE ";
     $i = 0;
     if (count($towns)) {
         $i++;
         $query .= " ot.townId IN (" . implode(' , ', $towns) . ") AND ";
     }
     if (count($categories) && !$sports) {
         $i++;
         $query .= " bc.catId IN (" . implode(' , ', $categories) . ") AND ";
     } else {
         if (count($categories)) {
             $i++;
             $query .= " (bc.catId IN (" . implode(' , ', $categories) . ") OR sc.category > 0 ) AND ";
         }
     }
     if (count($keywords = $searchComponent->getkeywords())) {
         $i++;
         $query .= '(';
         foreach ($keywords as $index => $value) {
             $query .= " o.description LIKE ('%" . $value . "%') OR  o.keywords LIKE ('%" . $value . "%') OR o.name LIKE ('%" . $value . "%') OR ";
         }
         $query = substr($query, 0, -4) . ') AND ';
     }
     if ($zip = $searchComponent->getZipcode()) {
         $i++;
         $query .= " o.zip = {$zip} AND ";
     }
     if (($type = $searchComponent->getType()) && !$sports && count($categories)) {
         $i++;
         $query .= " o.type = 3 AND ";
     } else {
         if (($type = $searchComponent->getType()) && $sports || !count($categories)) {
             $i++;
             $query .= " o.type IN (3 , 4)  AND ";
         }
     }
     if ($i > 0) {
         $query = substr($query, 0, -4);
     } else {
         $query = substr($query, 0, -6);
     }
     $query .= "GROUP BY o.id ORDER BY o.active DESC, o.name ASC ";
     //print $query;exit;
     return $this->getMultipleRows($query);
 }
 public static function regionSearch($searchTerm)
 {
     if ($searchTerm == 25) {
         return FM_Components_Util_LimeCard::statenIslandSearch();
     }
     if ($searchTerm == 26) {
         return FM_Components_Util_LimeCard::oceanCountySearch();
     }
     $regions = array();
     $towns = FM_Components_Util_Region::getTownIdsByRegion($searchTerm);
     foreach ($towns as $index => $town) {
         $regions[] = $town['id'];
     }
     $model = new FM_Models_FM_LimeCard();
     $nonOrg = $model->regionSearch($searchTerm);
     $orgDataModel = new FM_Models_FM_Orgdata();
     $orgs = $orgDataModel->regionSearch($regions);
     $orgArray = array();
     foreach (array_merge($orgs, $nonOrg) as $index => $org) {
         if (array_key_exists($org['name'], $orgArray)) {
             $orgArray[$org['name']]['categories'][] = $org['catName'];
         } else {
             $orgArray[$org['name']]['record'] = $org;
             $orgArray[$org['name']]['categories'][] = $org['catName'];
         }
     }
     return $orgArray;
 }
 public function limecardAction()
 {
     $this->view->form = new FM_Forms_LimeCard();
     $this->view->regionsForm = new FM_Forms_LimeCardRegion();
     $this->view->results = false;
     if ($this->_getParam('var') === '0') {
         $this->view->searchTerm = 'ALL';
         $orgs = FM_Components_Util_LimeCard::alphaSearch('');
         //print_r($orgs);
         $this->view->selected = '0';
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
     } elseif ($this->_getParam('do') == 'alph') {
         $this->view->searchTerm = $this->_getParam('var');
         $orgs = FM_Components_Util_LimeCard::alphaSearch($this->_getParam('var'));
         $this->view->selected = $this->_getParam('var');
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
     } elseif ($this->_getParam('do') == 'cat') {
         $orgs = FM_Components_Util_LimeCard::catSearch($this->_getParam('var'));
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
         $this->view->searchTerm = ucwords(strtolower(FM_Components_Util_Category::getCategoryName($this->_getParam('var'), false)));
     } elseif ($this->_getParam('do') == 'region') {
         $orgs = FM_Components_Util_LimeCard::regionSearch($this->_getParam('var'));
         $this->view->results = $final = FM_Components_Util_LimeCard::sort($orgs, 'name');
         $region = new FM_Components_Util_Region(array('id' => $this->_getParam('var')));
         $this->view->searchTerm = ucwords(strtolower($region->getName()));
         if ($this->_getParam('var') == 25) {
             $this->view->searchTerm = 'Staten Island';
         }
         if ($this->_getParam('var') == 26) {
             $this->view->searchTerm = 'Ocean County';
         }
     } else {
         if ($_POST['limecardsearch']) {
             $this->view->searchTerm = $_POST['limecardsearch'];
             $bzOrgsModel = new FM_Models_FM_SearchPrimaryCategories();
             $npOrgsModel = new FM_Models_FM_SearchPrimaryCategoriesOrgs();
             $bzResults = $bzOrgsModel->searchByCat($_POST['limecardsearch']);
             $npResults = $npOrgsModel->searchByCat($_POST['limecardsearch']);
             $orgIds = array();
             foreach (array_merge($bzResults, $npResults) as $key => $value) {
                 $orgIds[] = $value['orgId'];
             }
             $orgDataModel = new FM_Models_FM_Orgdata();
             $orgs = $orgDataModel->limecardSearch(array_values($orgIds), $_POST['limecardsearch']);
             $orgDataModel->alphabeticalSearch();
             $nonOrgs = FM_Components_Util_LimeCard::search($_POST['limecardsearch']);
             $this->view->results = $final = FM_Components_Util_LimeCard::sort(array_merge($orgs, $nonOrgs), 'name');
         }
     }
 }