Ejemplo n.º 1
0
 /**
  * Add new fieldGmpGmp for children table (@see class field)
  * @param string $name name of a field
  * @param string $html html type of field (text, textarea, etc. @see html class)
  * @param string $type database type (int, varcahr, etc.)
  * @param mixed $default default value for this field
  * @return object $this - pointer to current object
  */
 protected function _addField($name, $html = 'text', $type = 'other', $default = '', $label = '', $maxlen = 0, $dbAdapt = '', $htmlAdapt = '', $description = '')
 {
     $this->_fields[$name] = toeCreateObjGmp('fieldGmp', array($name, $html, $type, $default, $label, $maxlen, $dbAdapt, $htmlAdapt, $description));
     return $this;
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     $this->_res = toeCreateObjGmp('response', array());
     load_theme_textdomain('gmp', GMP_DIR . 'lang');
 }
Ejemplo n.º 3
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();
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     $this->_res = toeCreateObjGmp('response', array());
 }
Ejemplo n.º 5
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();
 }