Ejemplo n.º 1
0
 public function UpdateBusiness($dataForm, $businessId)
 {
     global $mySession;
     $db = new Db();
     $chkQry = $db->runQuery("select * from " . SERVICE_BUSINESS . " where business_title='" . mysql_escape_string($dataForm['business_title']) . "' and business_id!='" . $businessId . "'");
     if ($chkQry != "" and count($chkQry) > 0) {
         return 0;
     } else {
         $BusinessImagesPath = "";
         for ($counter = 1; $counter <= 10; $counter++) {
             $businessImage = $dataForm['old_business_image' . $counter];
             if ($dataForm['business_image' . $counter] != "") {
                 if ($businessImage != "" && file_exists(SITE_ROOT . 'images/events/' . $businessImage)) {
                     unlink(SITE_ROOT . 'images/events/' . $businessImage);
                 }
                 $businessImage = time() . "_" . $dataForm['business_image' . $counter];
                 @rename(SITE_ROOT . 'images/businesses/' . $dataForm['business_image' . $counter], SITE_ROOT . 'images/businesses/' . $businessImage);
             }
             if ($businessImage != "") {
                 $BusinessImagesPath .= $businessImage . ",";
             }
         }
         if ($BusinessImagesPath != "") {
             $BusinessImagesPath = substr($BusinessImagesPath, 0, strlen($BusinessImagesPath) - 1);
         }
         $myLatLongData = getLatLongFromAddress($dataForm['country_id'], $dataForm['state_id'], $dataForm['city_name'], $dataForm['address']);
         $explode = explode("::", $myLatLongData);
         $Lat = $explode[0];
         $Long = $explode[1];
         $dataUpdate['business_title'] = $dataForm['business_title'];
         $dataUpdate['business_category_id'] = $dataForm['business_category_id'];
         $dataUpdate['description'] = $dataForm['description'];
         $dataUpdate['search_keywords'] = $dataForm['search_keywords'];
         $dataUpdate['address'] = $dataForm['address'];
         $dataUpdate['city_name'] = $dataForm['city_name'];
         $dataUpdate['zipcode'] = $dataForm['zipcode'];
         $dataUpdate['state_id'] = $dataForm['state_id'];
         $dataUpdate['country_id'] = $dataForm['country_id'];
         $dataUpdate['phone_number'] = $dataForm['phone_number'];
         $dataUpdate['email_address'] = $dataForm['email_address'];
         $dataUpdate['website'] = $dataForm['website'];
         $dataUpdate['business_image'] = $BusinessImagesPath;
         $dataUpdate['business_lat'] = $Lat;
         $dataUpdate['business_long'] = $Long;
         $dataUpdate['business_status'] = '1';
         $conditionUpdate = "business_id='" . $businessId . "'";
         $db->modify(SERVICE_BUSINESS, $dataUpdate, $conditionUpdate);
         return 1;
     }
 }
Ejemplo n.º 2
0
 public function saveAction()
 {
     global $mySession;
     $db = new Db();
     $this->view->pageHeading = "Save Business Listing";
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest();
         $myform = new Form_Test();
         if ($myform->isValid($request->getPost())) {
             $dataForm = $myform->getValues();
             $xlsfile = $dataForm['excelfile'];
             $zipfile = $dataForm['zipfile'];
             if ($zipfile != "") {
                 $zip = new ZipArchive();
                 $res = $zip->open(SITE_ROOT . "test/" . $zipfile);
                 if ($res === TRUE) {
                     $zip->extractTo(SITE_ROOT . 'test/temp');
                     $zip->close();
                     $mySession->errorMsg = 'Data uploaded successfully';
                 } else {
                     $mySession->errorMsg = 'Error in uploading';
                 }
             }
             //error_reporting(1);
             //ini_set("memory_limit","2048M");
             require_once SITE_ROOT . 'Excel/reader.php';
             $data = new Spreadsheet_Excel_Reader();
             $data->read(SITE_ROOT . "test/" . $xlsfile);
             error_reporting(E_ALL ^ E_NOTICE);
             $SheetNo = 0;
             $numRows = $data->sheets[$SheetNo]['numRows'];
             $numCols = $data->sheets[$SheetNo]['numCols'];
             for ($i = 2; $i <= $numRows; $i++) {
                 $busidata['business_title'] = $data->sheets[$SheetNo]['cells'][$i][1];
                 $catename = $data->sheets[$SheetNo]['cells'][$i][2];
                 $sql = "select * from " . SERVICE_CATEGORIES . " where category_name='" . $catename . "'";
                 $result = $db->runQuery($sql);
                 if (count($result) > 0) {
                     $busidata['business_category_id'] = $result[0]['cat_id'];
                 }
                 $sql = "select * from " . COUNTRIES . " where country_name='" . $data->sheets[$SheetNo]['cells'][$i][4] . "'";
                 $result = $db->runQuery($sql);
                 if (count($result) > 0) {
                     $busidata['country_id'] = $result[0]['country_id'];
                 }
                 $sql = "select * from " . STATE . " where country_id= " . $busidata['country_id'] . " and state_name='" . $data->sheets[$SheetNo]['cells'][$i][5] . "'";
                 $result = $db->runQuery($sql);
                 if (count($result) > 0) {
                     $busidata['state_id'] = $result[0]['state_id'];
                 }
                 $busidata['date_business_added'] = date('Y-m-d H:i:s');
                 $busidata['city_name'] = $data->sheets[$SheetNo]['cells'][$i][6];
                 $businessImage = time() . "_" . $data->sheets[$SheetNo]['cells'][$i][3];
                 copy(SITE_ROOT . "test/temp/" . $data->sheets[$SheetNo]['cells'][$i][3], SITE_ROOT . 'images/businesses/' . $businessImage);
                 $busidata['zipcode'] = $data->sheets[$SheetNo]['cells'][$i][7];
                 $busidata['description'] = $data->sheets[$SheetNo]['cells'][$i][8];
                 $busidata['search_keywords'] = $data->sheets[$SheetNo]['cells'][$i][9];
                 $busidata['address'] = $data->sheets[$SheetNo]['cells'][$i][10];
                 $busidata['phone_number'] = $data->sheets[$SheetNo]['cells'][$i][11];
                 $busidata['email_address'] = $data->sheets[$SheetNo]['cells'][$i][12];
                 $busidata['Website'] = $data->sheets[$SheetNo]['cells'][$i][13];
                 $busidata['Business_image'] = $businessImage;
                 $myLatLongData = getLatLongFromAddress($busidata['country_id'], $busidata['state_id'], $busidata['city_name'], $busidata['address']);
                 $explode = explode("::", $myLatLongData);
                 $Lat = $explode[0];
                 $Long = $explode[1];
                 $busidata['business_lat'] = $Lat;
                 $busidata['business_long'] = $Long;
                 $busidata['business_status'] = 1;
                 $db->save(SERVICE_BUSINESS, $busidata);
                 $counter++;
             }
             $this->_redirect('test/index');
         } else {
             $this->view->myform = $myform;
             $this->render('index');
         }
     } else {
         $this->_redirect('test/index');
     }
 }
/**
 * object event_check_latlong(object $node);
 * object event_check_latlong(int $nid, bool $doNodeSave);
 *
 * Given a node or node-id, will check to see if the given node has latitude/longitude information, if 
 * it does not, and has a [valid] address associated, the lat/long values will be populated.
 */
function event_check_latlong($node, $doNodeSave = false)
{
    $thisFunct = __FUNCTION__;
    // If we are given a node-id instead of a node object, node the node
    if (!is_object($node) && is_numeric($node)) {
        $node = node_load($node);
        $doNodeSave = true;
    }
    // Validation, the given node must be under the Event content-type
    if ($node->type !== 'event') {
        return $node;
    }
    // Detect if the latitude is missing
    $isMissingLatLong = false;
    if (empty($node->field_event_latitude)) {
        $isMissingLatLong = true;
    } else {
        if (empty($node->field_event_latitude['und']) || !is_array($node->field_event_latitude['und']) || count($node->field_event_latitude['und']) === 0) {
            $isMissingLatLong = true;
        } else {
            if (empty($node->field_event_latitude['und'][0]) || !is_array($node->field_event_latitude['und'][0]) || count($node->field_event_latitude['und'][0]) === 0) {
                $isMissingLatLong = true;
            } else {
                if (empty($node->field_event_latitude['und'][0]['value']) || intval($node->field_event_latitude['und'][0]['value']) === 0) {
                    $isMissingLatLong = true;
                } else {
                    // then this node has a latitude value
                }
            }
        }
    }
    // Detect if the longitude is missing
    $isMissingLatLong = false;
    if (empty($node->field_event_longitude)) {
        $isMissingLatLong = true;
    } else {
        if (empty($node->field_event_longitude['und']) || !is_array($node->field_event_longitude['und']) || count($node->field_event_longitude['und']) === 0) {
            $isMissingLatLong = true;
        } else {
            if (empty($node->field_event_longitude['und'][0]) || !is_array($node->field_event_longitude['und'][0]) || count($node->field_event_longitude['und'][0]) === 0) {
                $isMissingLatLong = true;
            } else {
                if (empty($node->field_event_longitude['und'][0]['value']) || intval($node->field_event_longitude['und'][0]['value']) === 0) {
                    $isMissingLatLong = true;
                } else {
                    // then this node has a longitude value
                }
            }
        }
    }
    if ($isMissingLatLong) {
        $address = '';
        if (!empty($node->field_event_address_1['und'][0]['value'])) {
            $address .= $node->field_event_address_1['und'][0]['value'];
        }
        if (!empty($node->field_event_address_2['und'][0]['value'])) {
            if ($address !== '') {
                $address .= ', ';
            }
            $address .= $node->field_event_address_2['und'][0]['value'];
        }
        if (!empty($node->field_event_city['und'][0]['value'])) {
            if ($address !== '') {
                $address .= ', ';
            }
            $address .= $node->field_event_city['und'][0]['value'];
        }
        if (!empty($node->field_event_state['und'][0]['value'])) {
            if ($address !== '') {
                $address .= ', ';
            }
            $address .= $node->field_event_state['und'][0]['value'];
        }
        if (!empty($node->field_event_zip['und'][0]['value'])) {
            if ($address !== '') {
                $address .= ' ';
            }
            $address .= $node->field_event_zip['und'][0]['value'];
        }
        if (trim($address) === '' || empty($node->field_event_city['und'][0]['value'])) {
            drupal_set_message('Notice: This even will not be able to shown on a map or included in proximity-searches because no address information was supplied.', 'warning');
            error_log("{$thisFunct}() could not even try to auto-populated the latitude/longitude values for the event {$node->nid} (\"{$node->title}\") because there was no address information given");
            return $node;
        }
        $locInfo = getLatLongFromAddress($address);
        // This function is defined in ZipCodeGeolocation.php
        if (empty($locInfo['lat']) || empty($locInfo['lng'])) {
            drupal_set_message("Error - Could not geolocate the address: \"{$address}\", is this a valid address?", 'error');
            error_log("{$thisFunct}() failed to auto-populated the latitude/longitude values for event-node {$node->nid} (\"{$node->title}\"). The given address was {$address}.");
            return $node;
        } else {
            $node->field_event_latitude = array('und' => array(0 => array('value' => strval($locInfo['lat']), 'format' => '', 'safe_value' => strval($locInfo['lat']))));
            $node->field_event_longitude = array('und' => array(0 => array('value' => strval($locInfo['lng']), 'format' => '', 'safe_value' => strval($locInfo['lng']))));
            error_log("{$thisFunct}() has auto-populated the latitude/longitude values for event-node {$node->nid} (\"{$node->title}\") ");
        }
    }
    if ($doNodeSave) {
        node_save($node);
    }
    return $node;
}