示例#1
0
 public function sendContact()
 {
     $res = new responseGmp();
     $time = time();
     $prevSendTime = (int) get_option(GMP_CODE . '_last__time_contact_send');
     if ($prevSendTime && $time - $prevSendTime < 5 * 60) {
         // Only one message per five minutes
         $res->pushError(__('Please don\'t send contact requests so often - wait for response for your previous requests.'));
         $res->ajaxExec();
     }
     $data = reqGmp::get('post');
     $fields = $this->getModule()->getContactFormFields();
     foreach ($fields as $fName => $fData) {
         $validate = isset($fData['validate']) ? $fData['validate'] : false;
         $data[$fName] = isset($data[$fName]) ? trim($data[$fName]) : '';
         if ($validate) {
             $error = '';
             foreach ($validate as $v) {
                 if (!empty($error)) {
                     break;
                 }
                 switch ($v) {
                     case 'notEmpty':
                         if (empty($data[$fName])) {
                             $error = $fData['html'] == 'selectbox' ? __('Please select %s', GMP_LANG_CODE) : __('Please enter %s', GMP_LANG_CODE);
                             $error = sprintf($error, $fData['label']);
                         }
                         break;
                     case 'email':
                         if (!is_email($data[$fName])) {
                             $error = __('Please enter valid email address', GMP_LANG_CODE);
                         }
                         break;
                 }
                 if (!empty($error)) {
                     $res->pushError($error, $fName);
                 }
             }
         }
     }
     if (!$res->error()) {
         $msg = 'Message from: ' . get_bloginfo('name') . ', Host: ' . $_SERVER['HTTP_HOST'] . '<br />';
         $msg .= 'Plugin: ' . GMP_WP_PLUGIN_NAME . '<br />';
         foreach ($fields as $fName => $fData) {
             if (in_array($fName, array('name', 'email', 'subject'))) {
                 continue;
             }
             if ($fName == 'category') {
                 $data[$fName] = $fData['options'][$data[$fName]];
             }
             $msg .= '<b>' . $fData['label'] . '</b>: ' . nl2br($data[$fName]) . '<br />';
         }
         if (frameGmp::_()->getModule('mail')->send('*****@*****.**', $data['subject'], $msg, $data['name'], $data['email'])) {
             update_option(GMP_CODE . '_last__time_contact_send', $time);
         } else {
             $res->pushError(frameGmp::_()->getModule('mail')->getMailErrors());
         }
     }
     $res->ajaxExec();
 }
示例#2
0
 public function import()
 {
     @ini_set('auto_detect_line_endings', true);
     $res = new responseGmp();
     $this->_connectCsvLib();
     $csvGenerator = toeCreateObjGmp('csvgeneratorGmp', array(''));
     $type = reqGmp::getVar('type');
     $file = $type == 'maps' ? reqGmp::getVar('csv_import_file_maps', 'file') : reqGmp::getVar('csv_import_file_markers', 'file');
     if (empty($file) || empty($file['size'])) {
         $res->pushError(__('Missing File', GMP_LANG_CODE));
     }
     if (!empty($file['error'])) {
         $res->pushError(sprintf(__('File uploaded with error code %s', $file['error'])));
     }
     if (!$res->error()) {
         $fileArray = array();
         $handle = fopen($file['tmp_name'], 'r');
         $csvParams['delimiter'] = $csvGenerator->getDelimiter();
         $csvParams['enclosure'] = $csvGenerator->getEnclosure();
         $csvParams['escape'] = $csvGenerator->getEscape();
         //if(version_compare( phpversion(), '5.3.0' ) == -1) //for PHP lower than 5.3.0 third parameter - escape - is not implemented
         while ($row = @fgetcsv($handle, 0, $csvParams['delimiter'], '"')) {
             $fileArray[] = $row;
         }
         /*else
         		while($row = @fgetcsv( $handle, 0, $csvParams['delimiter'], $csvParams['enclosure'], $csvParams['escape'] )) $fileArray[] = $row;*/
         /*var_dump($fileArray);
         		exit();*/
         if (!empty($fileArray)) {
             if (count($fileArray) > 1) {
                 //$overwriteSameNames = (int) reqGmp::getVar('overwrite_same_names');
                 $keys = array_shift($fileArray);
                 switch ($type) {
                     case 'maps':
                         $mapModel = frameGmp::_()->getModule('gmap')->getModel();
                         foreach ($fileArray as $i => $row) {
                             $map = array();
                             foreach ($keys as $j => $key) {
                                 $value = $this->_prepareValueToImport($row[$j]);
                                 if (strpos($key, '.')) {
                                     $realKeys = explode('.', $key);
                                     $realKey = array_pop($realKeys);
                                     $realPreKey = array_pop($realKeys);
                                     if ($realPreKey == 'map_center') {
                                         $valueMapCenter = isset($map['map_center']) ? $map['map_center'] : array();
                                         $valueMapCenter[$realKey] = $value;
                                         $value = $valueMapCenter;
                                         $realKey = 'map_center';
                                     }
                                 } else {
                                     $realKey = $key;
                                 }
                                 if ($value === '') {
                                     $value = NULL;
                                 }
                                 $map[$realKey] = $value;
                             }
                             if (isset($map['id']) && $mapModel->existsId($map['id'])) {
                                 $mapModel->updateMap($map);
                             } else {
                                 $originalMapId = isset($map['id']) ? isset($map['id']) : 0;
                                 if (isset($map['id'])) {
                                     unset($map['id']);
                                 }
                                 $newMapId = $mapModel->saveNewMap($map);
                                 if ($newMapId && $originalMapId) {
                                     dbGmp::query("UPDATE @__maps SET id = '{$originalMapId}' WHERE id = '{$newMapId}'");
                                     if ($originalMapId > $newMapId) {
                                         dbGmp::setAutoIncrement('@__popup', $originalMapId + 1);
                                     }
                                 }
                             }
                         }
                         break;
                     case 'markers':
                         $markerModel = frameGmp::_()->getModule('marker')->getModel();
                         foreach ($fileArray as $i => $row) {
                             $marker = array();
                             foreach ($keys as $j => $key) {
                                 $this->_setKeyVal($marker, $key, $this->_prepareValueToImport($row[$j]));
                             }
                             if (isset($marker['id']) && !$markerModel->existsId($marker['id'])) {
                                 unset($marker['id']);
                             }
                             $markerModel->save($marker);
                         }
                         break;
                 }
                 /*$importRes = $this->getModel()->import($fileArray, $overwriteSameNames);
                 		if($importRes) {
                 			if($importRes['map']['added'])
                 				$res->addMessage (sprintf(__('Added %s maps', GMP_LANG_CODE), $importRes['map']['added']));
                 			if($importRes['map']['updated'])
                 				$res->addMessage (sprintf(__('Updated %s maps', GMP_LANG_CODE), $importRes['map']['added']));
                 			if($importRes['marker']['added'])
                 				$res->addMessage (sprintf(__('Added %s markers', GMP_LANG_CODE), $importRes['map']['added']));
                 			if($importRes['marker']['updated'])
                 				$res->addMessage (sprintf(__('Updated %s markers', GMP_LANG_CODE), $importRes['map']['added']));
                 		} else
                 			$res->pushError ($this->getModel()->getErrors());*/
             } else {
                 $res->pushError(__('File should contain more then 1 row, at least 1 row should be for headers', GMP_LANG_CODE));
             }
         } else {
             $res->pushError(__('Empty data in file', GMP_LANG_CODE));
         }
     }
     frameGmp::_()->getModule('supsystic_promo')->getModel()->saveUsageStat('csv.import');
     $res->ajaxExec();
 }
示例#3
0
 public function import()
 {
     @ini_set('auto_detect_line_endings', true);
     $res = new responseGmp();
     $this->_connectCsvLib();
     $csvGenerator = toeCreateObjGmp('csvgeneratorGmp', array($fileName));
     $file = reqGmp::getVar('csv_import_file', 'file');
     if (empty($file) || empty($file['size'])) {
         $res->pushError(langGmp::_('Missing File'));
     }
     if (!empty($file['error'])) {
         $res->pushError(langGmp::_(array('File uploaded with error code', $file['error'])));
     }
     if (!$res->error()) {
         $fileArray = array();
         $handle = fopen($file['tmp_name'], 'r');
         $csvParams['delimiter'] = $csvGenerator->getDelimiter();
         $csvParams['enclosure'] = $csvGenerator->getEnclosure();
         $csvParams['escape'] = $csvGenerator->getEscape();
         //if(version_compare( phpversion(), '5.3.0' ) == -1) //for PHP lower than 5.3.0 third parameter - escape - is not implemented
         while ($row = @fgetcsv($handle, 0, $csvParams['delimiter'], '"')) {
             $fileArray[] = $row;
         }
         /*else
         		while($row = @fgetcsv( $handle, 0, $csvParams['delimiter'], $csvParams['enclosure'], $csvParams['escape'] )) $fileArray[] = $row;*/
         /*var_dump($fileArray);
         		exit();*/
         if (!empty($fileArray)) {
             if (count($fileArray) > 1) {
                 $overwriteSameNames = (int) reqGmp::getVar('overwrite_same_names');
                 $importRes = $this->getModel()->import($fileArray, $overwriteSameNames);
                 if ($importRes) {
                     if ($importRes['map']['added']) {
                         $res->addMessage(langGmp::_(array('Added', $importRes['map']['added'], 'maps')));
                     }
                     if ($importRes['map']['updated']) {
                         $res->addMessage(langGmp::_(array('Updated', $importRes['map']['updated'], 'maps')));
                     }
                     if ($importRes['marker']['added']) {
                         $res->addMessage(langGmp::_(array('Added', $importRes['marker']['added'], 'markers')));
                     }
                     if ($importRes['marker']['updated']) {
                         $res->addMessage(langGmp::_(array('Updated', $importRes['marker']['updated'], 'markers')));
                     }
                 } else {
                     $res->pushError($this->getModel()->getErrors());
                 }
             } else {
                 $res->pushError(langGmp::_('File should contain more then 1 row, at least 1 row should be for headers'));
             }
         } else {
             $res->pushError(langGmp::_('Empty data in file'));
         }
     }
     frameGmp::_()->getModule('promo_ready')->getModel()->saveUsageStat('csv.import');
     $res->ajaxExec();
 }