__constructor($params); } function __constructor($params = ''){ //php5 constructor $this->CI = &get_instance(); $this->CI->load->helper('freakauth_light'); $this->CI->load->model('account/shops/Shops_mod', 'shops_mod'); } /**** START Общие вспомогательные функции ****/ protected function escape_data($data){ // Экранирует переменные global $CI; $data = htmlspecialchars(trim($data)); $data = $CI->input->xss_clean($data); return $CI->db->escape($data); } protected function get_Curl($url, $login, $password, $shop_id) { define('URL_XML', $url); define('HTTP_USER', $login); define('HTTP_PSWD', $password); if($ch = curl_init()) { curl_setopt($ch, CURLOPT_URL, URL_XML); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_USERPWD, HTTP_USER . ':' . HTTP_PSWD); curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].$this->cookie_patch); if($result = curl_exec($ch)) { curl_setopt($ch, CURLOPT_URL, URL_XML); curl_setopt($ch, CURLOPT_COOKIEFILE, $_SERVER['DOCUMENT_ROOT'].$this->cookie_patch); //get cookie from file if($result1 = curl_exec($ch)) { curl_close($ch); $this->CI->load->library('simplexml'); $array = $this->CI->simplexml->xml_load_file($result1); if(!$array['error'] || is_array($array)) { $result = $this->CI->simplexml->search_errors($array); if(!isset($result['error'])) { if($tmpfname = tempnam ("/tmp", "FOO")) { if($fp = fopen($tmpfname, "w")) { fwrite($fp, $result1); fclose($fp); $rand = rand(100000,999999); if (copy($tmpfname, $this->address_from_copy.$this->prefix_file_price.$shop_id.'_'.$rand.'.price')) { unlink($tmpfname); return $this->prefix_file_price.$shop_id.'_'.$rand.'.price'; } else { echo 'Не удалось скопировать файл'; } } else { echo 'Не удалось открыть временный файл'; } } else { echo 'Не удалось создать временный файл'; } } else { foreach($result['error'] as $error) { echo '
' .$error. '
'; } } } else { echo $array; } } else { echo 'Ошибка curl_exec 1'; } } else { echo '

Ошибка авторизации на удаленном сервере, проверьте правильность ввода логина и пароля

'; } } else { echo 'Ошибка инициализации CURL'; } } protected function get_Curl_ftp($url, $login, $password, $shop_id) { define('URL_XML', $url); define('HTTP_USER', $login); define('HTTP_PSWD', $password); if($ch = curl_init()) { $fp = fopen(__FILE__, "r"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); //curl_setopt($ch, CURLOPT_FTPASCII, 1); curl_setopt($ch, CURLOPT_INFILESIZE, filesize(__FILE__)); if($result = curl_exec($ch)) { return 'good !!!'; } else { echo "
";
				print_r(curl_getinfo($ch));  
				echo "\n\ncURL error number:" .curl_errno($ch);  
				echo "\n\ncURL error:" . curl_error($ch); 			
				curl_close($ch); 			
				return '

Ошибка авторизации на удаленном сервере, проверьте правильность ввода логина и пароля

'; } } else { return 'Ошибка инициализации CURL'; } } /**** END Общие вспомогательные функции ****/ /**** START Главная страница раздела /account/ ****/ function all_shops_user($order = 'DESC'){ return $this->CI->shops_mod->get_all_shops_user($order); // ЗАПРОС } /**** END Главная страница раздела /account/ ****/ /**** START Главная страница раздела /account/actions/ ****/ function select_actions($action){ // Проверка и выбор функции при запросе $func = "ACT_".$action; if (method_exists('Shops_lib', $func)) { return $this->$func(); } else { show_404('page'); } } function ACT_add_shop() // Добавить новый магазин в аккаунт { $data = array('view' => 'add_shop', 'step' => ''); if(isset($_POST['finish'])) { $data['step'] = 'finish'; $user_id = getUserProperty('id'); if ($this->CI->shops_mod->check_url_in_base($url)) // ЗАПРОС { if($this->CI->shops_mod->insert_add_shop($user_id)) // ЗАПРОС { $data['finish'] = 'Информация отправлена на провепку и обработку. Ваш прайс-лист будет добавлен после проверки, если не будет выявлено ошибок в представленой информацие'; } } else { $data['finish'] = 'Интернет-магазин с адресом ' . $url . ' уже зарегистрирован.'; } } return $data; } function ACT_add_price(){ $data = array('view' => 'add_price', 'shop_id' => '', 'error' => ''); $shop_id = (int)$this->CI->uri->segment(5); if($shop_id == '' or $shop_id == 0) show_404('page'); $data['shop_id'] = $shop_id; return $data; } function ACT_edit_shop_data() { $data = array('view' => 'edit_shop_data'); $user_id = getUserProperty('id'); $shop_id = (int)$this->CI->uri->segment(5); if($shop_id == '' or $shop_id == 0) show_404('page'); if ($query = $this->CI->shops_mod->select_shop_data_for_edit($user_id, $shop_id)) // ЗАПРОС { $data['data'] = $query; } else { $data['error'] = 'Информации не найдено'; } return $data; } function ACT_edit_shop_contact() { $data['view'] = 'edit_shop_contact'; return $data; } function ACT_edit_shop_price() { $data['view'] = 'edit_shop_price'; return $data; } private function ACT_effect() // функция раздела actions, отвечает только на ajax запросы. { preg_match("/^(http:\/\/)?([^\/]+)/i", base_url(), $host); if ($this->CI->input->server('HTTP_REFERER') == false OR strstr($this->CI->input->server('HTTP_REFERER'), $host[2]) == false) show_404('page'); header('Content-Type: text/html; charset=utf-8'); $shop_id = (int)$_POST['shop_id']; if($this->CI->input->post('action') == 'addPrice') { switch($this->CI->input->post('type')) { case 'url': $result = $this->CI->shops_mod->select_shop_data($shop_id); if ($result == TRUE) // ЗАПРОС { if($result->url_xml_adress == '' and $result->url_xml_adress_file_name == '') { if($_POST['xml_url_adress'] != '') { preg_match("/^(http|https|ftp):\/\/?([^\/]+)/", $_POST['xml_url_adress'], $protocol); $protocol = substr($protocol[1], 0, 4); switch($protocol) { case 'http': if($price_file_name = $this->get_Curl($_POST['xml_url_adress'], $_POST['xml_url_login'], $_POST['xml_url_password'], $shop_id)) { if($this->CI->shops_mod->update_price_url($shop_id, $price_file_name) == TRUE) // ЗАПРОС { if($this->CI->shops_mod->update_status_moderation_shop($shop_id) == TRUE) // ЗАПРОС { echo '

Прайс-лист добавлен
Прайс: '.$price_file_name.'

'; } else { echo '

Произошла ошибка при отправке сайта на модерацию

'; } } else { echo 'При добавлении прайс-листа, во время выполнения запроса произошла ошибка: '; } } break; case 'ftp': /*$this->CI->load->library('ftp'); preg_match("/^(ftp):\/\/?([^\/]+)/", $_POST['xml_url_adress'] , $matches); //echo $matches[2]; $config['hostname'] = $matches[2]; $config['username'] = $_POST['xml_url_login']; $config['password'] = $_POST['xml_url_password']; $config['port'] = 21; $config['passive'] = TRUE; $config['debug'] = TRUE; if($this->CI->ftp->connect($config)) { $tmpfname = $this->CI->ftp->download('/price/shop_id_10_822680.prise'); if($tmpfname != false) { echo $tmpfname; //$rand = rand(10000, 999999); //copy($tmpfname, 'Z:/home/placemarket.ru/www/data/shops/xml/ddd' . '_' . $rand . '.price'); } else { echo "Не удалось скачать удаленный файл"; } $this->CI->ftp->close(); */ if($price_file_name = $this->get_Curl_ftp($_POST['xml_url_adress'], $_POST['xml_url_login'], $_POST['xml_url_password'], $shop_id)) { echo 'good: ' . $price_file_name; } else { echo 'nogood: ' . $price_file_name; } break; default: $out = 'Ошибка'; break; } } else { echo 'Вы не ввели url адрес'; } } else { echo 'Прайс-лист уже был добавлен'; } }else { echo 'Магазин не найден'; } break; case 'file': echo 'Файл'; break; } } elseif($this->CI->input->post('action') == 'update_data_shop') { if($this->CI->shops_mod->update_shop_data($shop_id)) // ЗАПРОС { echo 'Информация обновлена, можете закрыть окно.'; } } } function options() { $data = array('error' => array()); $user_id = getUserProperty('id'); $shop_id = (int)$this->CI->uri->segment(4); if($shop_id == '' or $shop_id == 0) show_404('page'); if ($query = $this->CI->shops_mod->select_shop_options($user_id, $shop_id)) // ЗАПРОС { $data['result_row'] = $query; } else { $data['error'] = 'Информации не найдено'; } return $data; } /**** END Главная страница раздела /account/actions/ ****/ } ?>