public function import()
 {
     // Set the script execution settings
     $importSize = String::formatBytes(VISUALIZATION_IMPORT_SIZE, 'mB');
     setExecutionSettings($importSize + 256);
     $result = false;
     $error = null;
     $fileName = File::handleUpload(DIR_TEMP, 'importFile', null, array(), VISUALIZATION_IMPORT_SIZE);
     if ($fileName) {
         $fileInfo = pathinfo($fileName);
         $fileNameNew = str_replace(' ', '_', substr(strtolower($fileInfo['filename']), 0, 22)) . '_' . Date::format('now', 'Ymd_His') . '.' . $fileInfo['extension'];
         $destinationDir = '\\\\db-images\\data.spotzi.com\\import\\' . $this->user['UserName'];
         if (!is_dir($destinationDir)) {
             mkdir($destinationDir);
         }
         $destination = $destinationDir . '\\' . $fileNameNew;
         if (is_dir($destinationDir) && copy(DIR_TEMP . $fileName, $destination)) {
             $importName = $this->getParam('importName');
             if (!$importName) {
                 $importName = ucwords(substr(str_replace('_', ' ', $fileName), 0, strrpos($fileName, '.')));
             }
             $dataUrl = 'http://data.spotzi.com/import/' . $this->user['UserName'] . '/' . $fileNameNew;
             $this->vizDb->insert(self::DB_CONNECTION_VIZ_WRITE, 'VisualizationImport', array('Service' => 'geonovum', 'UserName' => $this->user['UserName'], 'Email' => $this->user['Email'], 'Name' => $importName, 'DataUrl' => $dataUrl, 'DebugImport' => debugMode()));
             $webserviceUrl = String::prepare('%svisualization/wo/import?user=%s&password=%s&userName=%s&userKey=%s&callback=%s&format=application/json', WEBSERVICE_URL, WEBSERVICE_USER, WEBSERVICE_PASSWORD, $this->user['UserName'], $this->user['ApiKey'], Url::buildPlatformURL(false, 'import', 'import', 'finish'));
             Connectivity::runCurlAsync($webserviceUrl);
             $result = true;
         } else {
             $error = __('An error occured while preparing the file');
         }
         File::delete(DIR_TEMP . $fileName);
     } else {
         $error = __('An error occured while uploading the file');
     }
     if ($result === false) {
         ErrorHandler::error(E_NOTICE, "The import failed, file name: %s\nerror: %s", $fileName, $error);
     }
     return array(REQUEST_RESULT => $result, REQUEST_ERROR => $error);
 }
 public function addFeature()
 {
     $this->featureArray = ['visualizationId' => $this->visualization[REQUEST_PARAMETER_VIZ_ID], 'featureAction' => $this->action];
     switch ($this->action) {
         case EDITOR_ACTION_NEW_FEATURE:
             $this->featureArray['the_geom'] = $this->the_geom;
             $this->featureArray['geom_type'] = $this->geom_type;
             $this->featureArray['featureStyle'] = $this->featureStyle;
             break;
         case EDITOR_ACTION_EDIT_DATA:
             $this->featureArray['featureId'] = $this->featureId;
             $this->featureArray['layerId'] = $this->layerId;
             $this->featureArray['geom_type'] = $this->geom_type;
             $this->featureArray['featureStyle'] = $this->featureStyle;
             break;
         case EDITOR_ACTION_EDIT_GEOM:
             $this->featureArray['featureId'] = $this->featureId;
             $this->featureArray['layerId'] = $this->layerId;
             $this->featureArray['the_geom'] = $this->the_geom;
             $this->featureArray['geom_type'] = $this->geom_type;
             break;
         case EDITOR_ACTION_DELETE:
             $this->featureArray['featureId'] = $this->featureId;
             $this->featureArray['layerId'] = $this->layerId;
             break;
     }
     if (in_array($this->action, [EDITOR_ACTION_NEW_FEATURE, EDITOR_ACTION_EDIT_DATA])) {
         $fileName = File::handleUpload(DIR_TEMP, 'imageurl', null, array(), 26214400);
         //25 MB
         $imageurl = '';
         if ($fileName) {
             if (exif_imagetype(DIR_TEMP . $fileName)) {
                 $fileNameNew = Date::format('now', 'YmdHis') . '_' . str_replace(' ', '_', $fileName);
                 $destinationDir = '\\\\db-images\\images.spotzi.com\\mapbuilder\\users\\' . $this->user['UserName'];
                 if (!is_dir($destinationDir)) {
                     mkdir($destinationDir);
                 }
                 $destination = $destinationDir . '\\' . $fileNameNew;
                 if (is_dir($destinationDir) && copy(DIR_TEMP . $fileName, $destination)) {
                     $importName = substr(str_replace('_', ' ', $fileName), 0, strrpos($fileName, '.'));
                     $imageurl = 'http://images.spotzi.com/mapbuilder/users/' . $this->user['UserName'] . '/' . $fileNameNew;
                 }
                 File::delete(DIR_TEMP . $fileName);
             } else {
                 File::delete(DIR_TEMP . $fileName);
                 ErrorHandler::error(E_ERROR, String::prepare('%s is not an image', $fileName));
             }
         } else {
             $imageurl = $this->getParam('image');
         }
         $this->featureArray['name'] = $this->getParam('name') ? $this->getParam('name') : '';
         $this->featureArray['description'] = $this->getParam('description') ? $this->getParam('description') : '';
         $this->featureArray['imageurl'] = $imageurl ? $imageurl : '';
     }
     $this->feature = json_encode($this->featureArray);
     $webserviceUrl = WEBSERVICE_URL . 'visualization/wo/map_feature';
     $webserviceParams = array('user' => WEBSERVICE_USER, 'password' => WEBSERVICE_PASSWORD, 'userName' => $this->user['UserName'], 'userKey' => $this->user['ApiKey'], 'feature' => $this->feature, 'format' => 'application/json');
     $result = false;
     $webserviceResult = Connectivity::runCurl($webserviceUrl, array(CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $webserviceParams));
     if ($webserviceResult) {
         $webserviceContents = json_decode($webserviceResult, true);
         if (isset($webserviceContents['response']['map_feature'])) {
             $result = $webserviceContents['response']['map_feature'];
         }
     }
     return array(REQUEST_RESULT => $result);
 }