示例#1
0
 function read_request()
 {
     global $_REQUEST;
     $this->setupRegion();
     // CHECK FOR SEARCH CRITERIA
     //ByDate
     //searches for future events only if no start date is specified.
     if (isset($_REQUEST['bydate']) && $_REQUEST['bydate']) {
         $sql_criteria[] = '((`date` >= ' . $this->dbcon->qstr($_REQUEST['bydate']) . ' AND `recurring_options`=0) OR (`enddate`>=' . $this->dbcon->qstr($_REQUEST['bydate']) . ' AND `recurring_options`>0))';
     } elseif ($exact_date = $this->_makeExactDate()) {
         $sql_criteria[] = '( `date` = ' . $this->dbcon->qstr($exact_date) . ')';
     } else {
         if (!(isset($_REQUEST['old']) && $_REQUEST['old'] == 1)) {
             $sql_criteria[] = '((`date` >= CURDATE() AND `recurring_options`=0) || (`recurring_options`>0 AND `enddate`>= CURDATE() ))';
         }
     }
     //Zip Code Search Request
     if (isset($_REQUEST['zip']) && isset($_REQUEST['distance']) && $_REQUEST['zip'] && $_REQUEST['distance']) {
         $srch_options['zip'] = $_REQUEST['zip'];
         $srch_options['distance'] = $_REQUEST['distance'];
         $srch_loc = new Geo($this->dbcon, NULL, NULL, NULL, $_REQUEST['zip']);
         if ($ziplist = $srch_loc->zip_radius($_REQUEST['distance'])) {
             $zipset = "(" . $_REQUEST['zip'];
             foreach ($ziplist as $zindex => $zinfo) {
                 if (strlen($zindex) == 4) {
                     $zindex = '0' . $zindex;
                 }
                 $zipset .= "," . $this->dbcon->qstr($zindex);
             }
             $zipset .= ")";
             $sql_criteria[] = "lzip IN {$zipset}";
         } else {
             $this->calendar->error = "Sorry, US zip codes only";
         }
     }
     //State Request from event index page
     if (isset($_REQUEST['state']) && $_REQUEST['state']) {
         $sql_criteria[] = "lstate=" . $this->dbcon->qstr($_REQUEST['state']);
         $this->lookups['lcity']['LookupWhere'] = " lstate=" . $this->dbcon->qstr($_REQUEST['state']);
         $this->setupLookup('lcity');
         $this->fields_def['city'] = array('type' => 'select', 'label' => 'Select City', 'values' => $this->lookups['lcity']['Set'], 'value' => $_REQUEST['city']);
     }
     //city Request from event index page
     if (isset($_REQUEST['city']) && $_REQUEST['city']) {
         $sql_criteria[] = "lcity=" . $this->dbcon->qstr($_REQUEST['city']);
     }
     //Area Request from pulldown
     if (isset($_REQUEST['area']) && $_REQUEST['area']) {
         $this->setupLookup('area');
         if ($state_name = $this->lookups['area']['Set'][$_REQUEST['area']]) {
             $state_code = array_search($state_name, $this->lookups['lstate']['Set']);
             if ($state_code) {
                 $sql_criteria[] = "lstate=" . $this->dbcon->qstr($state_code);
             }
         }
     }
     //Event Type
     if (isset($_REQUEST['caltype']) && $_REQUEST['caltype']) {
         $this->setupLookup('caltype');
         $sql_criteria[] = "typeid=" . $this->dbcon->qstr($_REQUEST['caltype']);
     }
     //Country
     if (isset($_REQUEST['lcountry']) && $_REQUEST['lcountry']) {
         //check to see if the search is by code
         if (strlen($_REQUEST['lcountry']) == 3 && ($country_name = $this->lookups['lcountry']['Set'][$_REQUEST['lcountry']])) {
             $sql_criteria[] = "lcountry=" . $this->dbcon->qstr($_REQUEST['lcountry']);
         } else {
             if ($country_code = array_search($_REQUEST['lcountry'], $this->regionset->regions['WORLD'])) {
                 $sql_criteria[] = "lcountry=" . $this->dbcon->qstr($country_code);
             }
         }
     }
     //Modin
     if (isset($_REQUEST['modin']) && $_REQUEST['modin']) {
         $this->setupLookup('modin');
         $sql_criteria[] = "modin=" . $this->dbcon->qstr($_REQUEST['modin']);
     }
     //Student events
     if (isset($_REQUEST['student']) && $_REQUEST['student']) {
         $sql_criteria[] = "student=1";
     }
     //Old events (legacy compatibility)
     if (isset($_REQUEST['old']) && $_REQUEST['old']) {
         $sql_criteria[] = '((`date` < CURDATE() AND `recurring_options`=0) || (`recurring_options`>0 AND `enddate`< CURDATE() ))';
     }
     //Uid or Creator_id
     if (isset($_REQUEST['uid']) && $_REQUEST['uid']) {
         $sql_criteria[] = "uid=" . $this->dbcon->qstr($_REQUEST['uid']);
     }
     //Publish status
     if (isset($_REQUEST['publish']) && is_numeric($_REQUEST['publish'])) {
         if ($_REQUEST['publish']) {
             $sql_criteria[] = "publish=1";
         } else {
             $sql_criteria[] = "publish!=1";
         }
     }
     //Repeating Event
     if (isset($_REQUEST['recurring_options']) && $_REQUEST['recurring_options'] == 1) {
         $sql_criteria[] = "recurring_options>0";
     } elseif (isset($_REQUEST['recurring_options']) && $_REQUEST['recurring_options'] === '0') {
         $sql_criteria[] = "(recurring_options=0 or isnull(recurring_options))";
     }
     //Grab valid URL data
     $this->calendar->url_criteria = array();
     foreach ($this->fields_def as $field => $fdef) {
         if (isset($_REQUEST[$field]) && ($_REQUEST[$field] || $_REQUEST[$field] === '0')) {
             $this->calendar->url_criteria[] = $field . '=' . $_REQUEST[$field];
         }
     }
     return $sql_criteria;
 }
示例#2
0
 function read_request()
 {
     $this->setupRegion();
     $options = $this->getOptions();
     // CHECK FOR SEARCH CRITERIA
     //ByDate
     //looks for records changed after the specified date
     if (isset($_REQUEST['bydate']) && $_REQUEST['bydate']) {
         $sql_criteria[] = '`timestamp` >= ' . $this->dbcon->qstr($_REQUEST['bydate']);
     }
     //Zip Code Search Request
     if (isset($_REQUEST['zip']) && isset($_REQUEST['distance']) && $_REQUEST['zip'] && $_REQUEST['distance']) {
         $srch_options['zip'] = $_REQUEST['zip'];
         $srch_options['distance'] = $_REQUEST['distance'];
         $srch_loc = new Geo($this->dbcon, NULL, NULL, NULL, $_REQUEST['zip']);
         if ($ziplist = $srch_loc->zip_radius($_REQUEST['distance'])) {
             $zipset = "(" . $_REQUEST['zip'];
             foreach ($ziplist as $zindex => $zinfo) {
                 if (strlen($zindex) == 4) {
                     $zindex = '0' . $zindex;
                 }
                 $zipset .= "," . $this->dbcon->qstr($zindex);
             }
             $zipset .= ")";
             $sql_criteria[] = "zip IN {$zipset}";
         } else {
             $flash = AMP_System_Flash::instance();
             $flash->add_message("Sorry, no match found for that zip code");
             //$this->udm->errorMessage("Sorry, no match found for that zip code");
         }
     }
     //State Request from index page
     if (isset($_REQUEST['state']) && $_REQUEST['state']) {
         $sql_criteria[] = "State=" . $this->dbcon->qstr($_REQUEST['state']);
         $this->lookups['city']['LookupWhere'] = " modin=" . $this->udm->instance . " AND State=" . $this->dbcon->qstr($_REQUEST['state']);
         $this->setupLookup('city');
         $city_value = isset($_REQUEST['city']) && $_REQUEST['city'] ? $_REQUEST['city'] : null;
         $this->fields_def['city'] = array('type' => 'select', 'label' => 'Select City', 'values' => $this->lookups['city']['Set'], 'value' => $city_value);
     }
     //city Request from index page
     if (isset($_REQUEST['city']) && $_REQUEST['city']) {
         $sql_criteria[] = "city=" . $this->dbcon->qstr($_REQUEST['city']);
     }
     //Area Request from pulldown
     if (isset($_REQUEST['area']) && $_REQUEST['area']) {
         $this->setupLookup('area');
         if ($state_name = $this->lookups['area']['Set'][$_REQUEST['area']]) {
             $state_code = array_search($state_name, $this->lookups['state']['Set']);
             if ($state_code) {
                 $sql_criteria[] = "State=" . $this->dbcon->qstr($state_code);
             }
         }
     }
     //Country
     if (isset($_REQUEST['country']) && $_REQUEST['country']) {
         //check to see if the search is by code
         if (strlen($_REQUEST['country']) == 3 && ($country_name = $this->lookups['country']['Set'][$_REQUEST['country']])) {
             $criteria_code = "Country=" . $this->dbcon->qstr($_REQUEST['country']);
         } else {
             if ($country_code = array_search($_REQUEST['country'], $this->regionset->regions['WORLD'])) {
                 $criteria_code = "Country=" . $this->dbcon->qstr($country_code);
             }
         }
         $sql_criteria[] = "( " . $criteria_code . " OR ( Country=" . $this->dbcon->qstr($_REQUEST['country']) . "))";
     }
     //Keyword - fulltext search
     if (isset($_REQUEST['keyword']) && $_REQUEST['keyword']) {
         //Create a set of phrases to search for
         $kwsearch = $_REQUEST['keyword'];
         if (substr_count($kwsearch, '"') >= 2) {
             //extract quoted phrases
             //method kudos to insipience.com
             preg_match_all("/\"([\\w\\s]+)(\"|\$)/", $kwsearch, $matches, PREG_PATTERN_ORDER);
             $phrases = $matches[1];
             $terms = explode(" ", preg_replace("/\"[\\w\\s]*(\"|\$)/", "", $kwsearch));
             $phrase_set = array_merge($terms, $phrases);
         } else {
             $phrase_set = split(' ', $kwsearch);
         }
         //determine the fields to include in the search
         $db_fields = $this->udm->dbcon->MetaColumnNames('userdata');
         foreach ($this->udm->fields as $fname => $fdef) {
             if ($fdef['type'] == 'text' || $fdef['type'] == 'textarea') {
                 $textfields[] = $fname;
             }
         }
         if (is_array($textfields)) {
             $src_fields = array_intersect($db_fields, $textfields);
             //SQL should be case-insensitive by default
             //but it's acting weird, so let's force the issue.
             foreach ($src_fields as $key => $value) {
                 $src_fields[$key] = "if(isnull(`" . $value . "`),'',`" . $value . "`)";
             }
             $src_name = "Lower(Concat( " . join(',', $src_fields) . "))";
             foreach ($phrase_set as $keyword) {
                 //make sure it's not an empty phrase
                 if ($keyword) {
                     $sql_criteria[] = "{$src_name} LIKE " . $this->dbcon->qstr('%' . strtolower($keyword) . '%');
                 }
             }
         }
     }
     //Company
     if (isset($_REQUEST['Company']) && $_REQUEST['Company']) {
         $sql_criteria[] = "Company LIKE" . $this->dbcon->qstr('%' . $_REQUEST['Company'] . '%');
     }
     //Modin
     if (isset($_REQUEST['modin']) && $_REQUEST['modin']) {
         $sql_criteria['modin'] = "modin=" . $_REQUEST['modin'];
     }
     //Uid or Creator_id
     if (isset($_REQUEST['uid']) && $_REQUEST['uid']) {
         if (is_array($_REQUEST['uid'])) {
             //allow for multiple ids
             $sql_criteria[] = "id in(" . join(",", $_REQUEST['uid']) . ")";
         } else {
             $sql_criteria[] = "id=" . $this->dbcon->qstr($_REQUEST['uid']);
         }
     }
     //Publish status
     if (isset($_REQUEST['publish']) && is_numeric($_REQUEST['publish'])) {
         if ($_REQUEST['publish']) {
             $sql_criteria[] = "publish=1";
         } else {
             $sql_criteria[] = "(isnull(publish) OR publish!=1)";
         }
     }
     //tags
     if (isset($_REQUEST['tag']) && $_REQUEST['tag']) {
         $tagged_forms = AMPSystem_Lookup::instance('formsByTag', $_REQUEST['tag']);
         if (!$tagged_forms || empty($tagged_forms)) {
             $sql_criteria[] = 'FALSE';
         } else {
             $sql_criteria[] = 'id in( ' . join(",", array_keys($tagged_forms)) . ')';
         }
     }
     //name
     if (isset($_REQUEST['name']) && $_REQUEST['name']) {
         $sql_criteria[] = 'Concat( if( isnull( First_Name ), "", First_Name ), if ( isnull( Last_Name ), "", Last_Name ), if ( isnull( Company ), "", Company ))  LIKE ' . $this->dbcon->qstr('%' . str_replace(' ', '%', $_REQUEST['name']) . '%');
     }
     //arbitrary "extra" fields sql
     if (isset($options['search_extra_fields_sql']) && $options['search_extra_fields_sql'] && function_exists($options['search_extra_fields_sql'])) {
         $extra_sql_function = $options['search_extra_fields_sql'];
         $extra_criteria = $extra_sql_function($this);
         if ($extra_criteria) {
             $sql_criteria = array_merge($sql_criteria, $extra_criteria);
         }
     }
     $specified_fields = array('publish', 'search', 'sortby', 'qty', 'offset', 'uid', 'modin', 'country', 'area', 'city', 'state', 'zip', 'distance', 'bydate', 'tag', 'name', 'keyword');
     foreach ($this->_included_fields as $fieldname) {
         if (!isset($this->udm->fields[$fieldname])) {
             continue;
         }
         if (array_search($fieldname, $specified_fields) !== FALSE) {
             continue;
         }
         if (!(isset($_REQUEST[$fieldname]) && $_REQUEST[$fieldname])) {
             continue;
         }
         if (is_int($_REQUEST[$fieldname])) {
             //do precise search for numeric values
             $sql_criteria[] = $fieldname . ' = ' . $this->dbcon->qstr($_REQUEST[$fieldname]);
         } elseif (is_array($_REQUEST[$fieldname]) && $this->udm->fields[$fieldname]['type'] == 'date') {
             $date_preferences = 'form.' . $this->udm->instance . '.date.search.inc.php';
             if (!file_exists_incpath($date_preferences)) {
                 $request_year = isset($_REQUEST[$fieldname]['Y']) && $_REQUEST[$fieldname]['Y'] ? $_REQUEST[$fieldname]['Y'] : false;
                 $request_month = isset($_REQUEST[$fieldname]['M']) && $_REQUEST[$fieldname]['M'] ? $_REQUEST[$fieldname]['M'] : false;
                 //if ( $request_month && $request_year ) {
                 //$sql_criteria[] = $fieldname . ' > ' . $this->dbcon->qstr( $]['Y'] . '-' . str_pad( $_REQUEST[$fieldname]['M'], 2, '0', STR_PAD_LEFT) . '-01' );
                 //$sql_criteria[] = $fieldname . ' < ' . $this->dbcon->qstr( $_REQUEST[$fieldname]['Y'] . '-' . str_pad( $_REQUEST[$fieldname]['M'], 2, '0', STR_PAD_LEFT) . '-32' );
                 //}
                 if ($request_year) {
                     $sql_criteria[] = 'YEAR( ' . $fieldname . ') =  ' . $this->dbcon->qstr($_REQUEST[$fieldname]['Y']);
                 }
                 if ($request_month) {
                     $sql_criteria[] = 'MONTH( ' . $fieldname . ') =  ' . $this->dbcon->qstr($_REQUEST[$fieldname]['M']);
                 }
             } else {
                 $date_crit_method = 'form_' . $this->udm->instance . '_date_search';
                 include_once $date_preferences;
                 $sql_criteria[] = $date_crit_method($fieldname);
             }
         } else {
             //do string 'contains' search
             $sql_criteria[] = $fieldname . ' LIKE ' . $this->dbcon->qstr('%' . $_REQUEST[$fieldname] . '%');
         }
     }
     //Vet valid URL data
     $vetted_set = array();
     $criteria_set = $this->udm->getURLCriteria();
     foreach ($this->fields_def as $field => $fdef) {
         if (!isset($criteria_set[$field])) {
             continue;
         }
         if (!($criteria_set[$field] || $criteria_set[$field] === '0')) {
             continue;
         }
         $vetted_set[$field] = $criteria_set[$field];
     }
     $this->udm->url_criteria = $vetted_set;
     return $sql_criteria;
 }
示例#3
0
 function testZipRadius()
 {
     $geo = new Geo($this->dbcon, null, null, null, AMP_CALENDAR_LOCAL_ZIP);
     $zips = $geo->zip_radius(15);
     $this->assertIsA($zips, 'array');
 }
示例#4
0
 function makeCriteriaZipDistance($value, $value_type = 'zip')
 {
     if (!$this->_zip_distance_expected) {
         //a distance alone returns TRUE, a zip alone will be checked vs lzip
         return $value_type == 'zip' ? $this->_makeCriteriaContains('lzip', $value) : 'TRUE';
     }
     $this->_zip_distance[$value_type] = $value;
     //check to make sure both parameters are set
     if (!(isset($this->_zip_distance['distance']) && isset($this->_zip_distance['zip']))) {
         return 'TRUE';
     }
     require_once 'AMP/Geo/Geo.php';
     $geo_search = new Geo($this->dbcon, null, null, null, $this->_zip_distance['zip']);
     $included_zips = $geo_search->zip_radius($this->_zip_distance['distance']);
     $included_zips[$this->_zip_distance['zip']] = "base";
     $included_zips = array_map(array($this, '_zip_crit'), array_keys($included_zips));
     return 'lzip IN ( ' . join(',', $included_zips) . ')';
 }
示例#5
0
 function subscribe($url, $id = null, $publish = null, $name = null)
 {
     $rss = fetch_rss(trim($url));
     if (!$rss->channel && !$rss->items) {
         $this->addError("URL is not RSS or is invalid");
         return false;
     }
     $feed = array('url' => $url, 'title' => $rss->channel['title'], 'link' => $rss->channel['link'], 'description' => $rss->channel['description'], 'last_update' => $this->dbcon->DBTimeStamp());
     if (isset($id) && $id) {
         $feed['id'] = $id;
     }
     if (isset($publish)) {
         $feed['publish'] = $publish;
     }
     if (isset($name)) {
         $feed['name'] = $name;
     }
     $result = $this->dbcon->Replace('calendar_feeds', $feed, 'url', true);
     if (!$result) {
         $this->addError("Could not save feed");
         return false;
     }
     if ($result == ADODB_REPLACE_INSERTED) {
         $id = $this->dbcon->Insert_ID();
     }
     $this->init($this->dbcon, $id);
     $num_events = 0;
     /*XXX: need to check here for:
     get all events that already have this feed_id
     if any events already here have publish=1 and are missing out of the current feed,
     turn them to publish=0;
     */
     foreach ($rss->items as $item) {
         $event = $item['ev'];
         if (!$event) {
             continue;
         }
         $num_events++;
         $vcard = $item['vcard'];
         if ($contact = trim($event['organizer'])) {
         } else {
             $contact = trim($vcard['organizer_fn']);
             $email = trim($vcard['organizer_email']);
             $phone = trim($vcard['organizer_tel']);
             $uid = trim($vcard['organizer_uid']);
         }
         $geo = $item['geo'];
         //if no zip, figure it out if possible
         if (!$vcard['adr_pcode'] && (include_once 'AMP/Geo/Geo.php')) {
             $zip = false;
             if ($geo['lat'] && $geo['long']) {
                 $geo_lookup = new Geo($this->dbcon);
                 $geo_lookup->lat = $geo['lat'];
                 $geo_lookup->long = $geo['long'];
                 $info = $geo_lookup->zip_radius(0);
                 if ($info && is_array($info)) {
                     $zips = array_keys($info);
                     $zip = isset($zips[0]) && $zips[0] ? $zips[0] : false;
                 }
             }
             if (!$zip && $vcard['adr_locality'] && $vcard['adr_region']) {
                 $geo_lookup = new Geo($this->dbcon, trim($vcard['adr_street']), trim($vcard['adr_locality']), trim($vcard['adr_region']), null, array('city_fulltext', 'city_soundex'));
                 $info = $geo_lookup->zip_radius(0);
                 if ($info && is_array($info)) {
                     $zips = array_keys($info);
                     $zip = isset($zips[0]) && $zips[0] ? $zips[0] : false;
                 }
             }
             if ($zip) {
                 $vcard['adr_pcode'] = $zip;
             }
         }
         $typemap = array_flip($this->types);
         $type = $typemap[$event['type']];
         if (!$type) {
             $type = $typemap['Other'];
         }
         $calendar = array('event' => $item['title'], 'shortdesc' => $item['description'], 'url' => $item['link'], 'contact1' => $contact, 'email1' => $email, 'phone1' => $phone, 'date' => $event['startdate'], 'location' => $event['location'], 'enddate' => $event['enddate'], 'typeid' => $type, 'lcity' => trim($vcard['adr_locality']), 'lstate' => trim($vcard['adr_region']), 'lcountry' => trim($vcard['adr_country']), 'laddress' => trim($vcard['adr_street']), 'lzip' => trim($vcard['adr_pcode']), 'lat' => $geo['lat'], 'lon' => $geo['long'], 'feed_id' => $this->getData('id'));
         if (isset($item['content']) && isset($item['content']['encoded'])) {
             $encoded = $item['content']['encoded'];
             $data = $this->decode($encoded);
             if ($data) {
                 $calendar = array_merge($data, $calendar);
             }
         }
         $result = $this->dbcon->Replace('calendar', $calendar, array('feed_id', 'url'), true);
         if (2 == $result && $this->getData('publish')) {
             $this->dbcon->Execute('UPDATE calendar SET publish=1 WHERE feed_id=' . $calendar['feed_id'] . ' AND url=' . $calendar['url']);
         }
         //test for uid in return record, update that,
         //else add new and set it in calendar table
         /* XXX: and what if we don't even have a uid?  what's the big deal?
         			if ($result == ADODB_REPLACE_INSERTED ) {
         				$calendar_id = $this->dbcon->Insert_ID();
         				$calendaruids = AMPSystem_Lookup::instance('CalendarUid');
         				$uid = $calendaruids[$calendar_id];
         
         				$user = array('Last_Name' => $contact,
         							  'Email'		=> $email,
         							  'Phone'		=> $phone
         							 );
         
         				if(isset($uid) && $uid) {
         					$user['id'] = $uid;
         					$this->dbcon->Replace( 'userdata', $user, null, true);
         				} else {
         					$udm = new UserDataInput($this->dbcon,AMP_CALENDAR_ENTRY_FORM_DEFAULT,true);
         					$udm->setData($user);
         //need better error handling here
         					if(!$udm->saveUser()) continue;
         					$local_uid = $udm->uid;
         					$uid_update = array('id' => $calendar_id,
         										'uid' => $local_uid);
         					$result = $this->dbcon->Replace( 'calendar', $uid_update, 'id', true );
         				}
         			}
         			 */
     }
     if (!$num_events) {
         $this->addError("Feed did not contain event information!");
         return false;
     }
     return true;
 }