/application/controllers/tester3.php
PHP | 1136 lines | 692 code | 77 blank | 367 comment | 87 complexity | ed6a0123bab1ea465a35906620df04d3 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0, LGPL-2.1, GPL-3.0
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- class tester3 extends CI_Controller {
- private $modul;
- public $ftp;
-
- public function __construct() {
- parent::__construct();
- $webserverpath= "/www/crm_test/assets/restricted";
- $serverpath= "./assets/restricted";
- $params= array("webserverpath"=>$webserverpath,"serverpath"=>$serverpath);
- $this->load->library("ftplib", $params);
- #$ftp= new ftplib("test","testing");
- #$this->ftp("test","testing");
- #ini_set("max_execution_time", "60000");
- }
- /*
- $cart= array();
- foreach( $getcart as $key=>$value ){
- $IdProduk= $value['IdProduk'];
- $cart[$IdProduk][]= $value;
- }
-
- foreach( $cart as $key=>$value ){
- $qty= count($cart[$key]);
- foreach( $value as $subkey=>$subvalue ){
- echo $subvalue['NamaCategory'] . "->";
- echo $subvalue['Vendor'] . "->";
- echo $subvalue['Model'] . "->";
- echo $subvalue['NoSerial'] . "->";
- echo $qty . "->";
- echo $subvalue['SubTotal'] . "<br/>";
- $subvalue['Qty']= $qty;
- $cartnew[$key]= $subvalue;
- }
- }
- */
-
- function sapaan(){
- echo $this->Gmodel->getInvoiceID('01001');
- exit;
- $insdata['AddUser']= "ADMIN";
- $insdata['AddDate']= date("Y-m-d");
- $this->db->select('MediaType');
- $media= array('OUTDOOR','PRINT','SOCIAL MEDIA');
- $this->db->where_in('MediaType', $media);
- $newdata= $this->db->get('m_media_type')->result_array();
- foreach( $newdata as $key=>$value ){
- $insdata['NamaSource']= ucfirst(strtolower($value['MediaType']));
- $this->db->insert('konsumen_source', $insdata);
- }
- exit;
-
- $this->db->select('NamaSource');
- $cust_source= $this->db->get('konsumen_source')->result_array();
-
- $sql= "SELECT MediaType AS NamaSource FROM m_media_type
- GROUP BY MediaType";
- $media= $this->db->query($sql)->result_array();
-
- $lastsource= count($cust_source);
- $all= array();
- foreach( $cust_source as $value ){
- $all[]= $value;
- }
- foreach( $media as $value ){
- $all[]= $value;
- }
- array_multisort($all);
- foreach( $all as $value ){
- echo $value['NamaSource'] . "<br/>";
- }
- print_r($all);
-
- exit;
- $cond_negara= array('ID','KR','MY','SG');
- $this->db->where_in('IdNegara',$cond_negara);
- $stnegara= $this->db->get('m_negara')->result_array();
- foreach( $stnegara as $key=>$value ){
- echo "<option value=\"" . $value['IdNegara'] . "\">" . $value['NamaNegara'] . "</option>";
- }
- exit;
- $IdNegara= strtolower($this->uri->segment(1));
- $sql= "SELECT IdSapaan, " . $IdNegara . "_NamaSapaan FROM m_sapaan";
- $data= $this->db->query($sql)->result_array();
- print_r($data);
- exit;
- }
-
- function insertdata(){
- $clinic= array('02003', '02001');
- $nilai= 02001;
- settype($nilai, "string");
- $test= "'" . $nilai . "'";
- echo $nilai;
- #settype($nilai, "string");
- #var_dump($nilai);
- #echo array_search($nilai, $clinic);
- #echo array_search($nilai, $clinic);
- /*
- if( array_search($nilai, $clinic) ){
- echo "ada";
- }
- */
- exit;
- $this->db->select("NoSerial");
- $result= $this->db->get_where("penjualan_detail_sn")->result_array();
- $group= "'";
- foreach( $result as $value ){
- $group.= $value['NoSerial'] . ",";
- }
- $group.= "'";
- echo $group;
- #print_r($result);
- exit;
-
- echo sha1("admin");
- exit;
- $dtupdate= array("Status"=>1);
- $wheresn= array("NoSerial"=>'0079206');
- $this->db->where($wheresn);
- $this->db->update("produk_sn", $dtupdate);
- echo $this->db->last_query();
- exit;
-
- $sale= array('Id'=>'34','IdKonsumen'=>'02001000000025','AddUser'=>'joko','IdProduk'=>'020002','Qty'=>'',
- 'MataUang'=>'IDR','AddDate'=>'2011-09-28 00:00:00','Left'=>'0','Right'=>'0');
- $allsn= array(0=>array('IdSale'=>'34','IdProduk'=>'020002','NoSerial'=>'0079206','Type'=>'',
- 'AddUser'=>'joko','AddDate'=>'2011-09-28'), 1=>array('IdSale'=>'34',
- 'IdProduk'=>'020002','NoSerial'=>'8039046','Type'=>'','AddUser'=>'joko','AddDate'=>'2011-09-28'));
- $this->db->insert("penjualan_temp", $sale);
- foreach( $allsn as $value ){
- $this->db->insert("penjualan_sn_temp", $value);
- }
- exit;
- #$getwhere= array("IdSale"=>"34");
- $getwhere= array("Id"=>"34");
- $result= $this->db->get_where("penjualan_temp", $getwhere)->result_array();
- $data= "array(";
- foreach( $result as $key=>$value ){
- $data.= "$key=>array(";
- foreach( $value as $subkey=>$subvalue ){
- $data.= "'" . $subkey . "'=>'" . $subvalue . "',";
- }
- }
-
- print_r($data);
- exit;
-
- $sale= array('Id'=>'34','IdKonsumen'=>'02001000000025','AddUser'=>'joko','IdProduk'=>'020002','Qty'=>'',
- 'MataUang'=>'IDR','AddDate'=>'2011-09-28 00:00:00','Left'=>'0','Right'=>'0');
- $allsn= array(0=>array('IdSale'=>'34','IdProduk'=>'020002','NoSerial'=>'0079206','Type'=>'',
- 'AddUser'=>'joko','AddDate'=>'2011-09-28'), 1=>array('IdSale'=>'34',
- 'IdProduk'=>'020002','NoSerial'=>'8039046','Type'=>'','AddUser'=>'joko','AddDate'=>'2011-09-28'));
- $this->db->insert($sale);
- $this->db->insert($allsn);
-
- $sql= "SELECT SUM(b.Harga) AS RealPrice, BesarDiskon AS Diskon,
- (SUM(b.Harga) - (SUM(b.Harga) * BesarDiskon/100)) AS SubTotal FROM penjualan_sn_temp a
- INNER JOIN produk_harga b ON a.IdProduk= b.IdProduk
- WHERE a.IdSale='34' AND b.IdMataUang='IDR'";
- $row= $this->db->query($sql)->row_array();
-
- print_r($row);
- exit;
-
- $fields= $this->db->list_fields('penjualan_detail_sn');
- $str= 'array(';
- $strout= "";
- foreach($fields as $field){
- $strout.= $field . "<br/>";
- $str.= "'$field',";
- }
- echo $strout;
- exit;
- /*
- $produk= array('IdProduk'=>'CI-8500DX','IdCategory'=>'CHI','IdVendor'=>'ABI',
- 'NamaProduk'=>'Auria Duluxe Kit','Model'=>'Auria Duluxe Kit','Garansi'=>12,
- 'Type'=>'P','AddUser'=>'ADMIN','AddDate'=>'2011-09-27');
- if( ! $this->Gmodel->isExist("produk",array('IdProduk'=>'CI-8500DX')) ){
- $this->db->insert("produk",$produk);
- }else{
- $this->db->where('IdProduk','CI-8500DX');
- $this->db->update("produk",$produk);
- }
- exit;
- */
- #CI-8500DX Auria Duluxe Kit 36428S
-
- /*
- $fields = $this->db->list_fields('produk_harga');
- $str= 'array(';
- foreach($fields as $field){
- $str.= "'$field',";
- }
- echo $str;
- */
- $data= array('IdProduk'=>'050-0032-01','IdMataUang'=>'SGD','Harga'=>600,
- 'AddUser'=>'ADMIN','AddDate'=>'2011-09-26');
- $this->db->insert('produk_harga', $data);
- /*
- $data= array(
- 'IdProduk'=>'00043237',
- 'IdMataUang'=>'SGD',
- 'Harga'=>'50'
- );
- $this->db->insert('produk_harga', $data);
- */
- }
- // Import Data Cara 2 dengan Double Primary Key
- public function import(){
- $path= "./assets/restricted/";
- $fp= fopen($path.'m_media_kategori.csv', 'r');
- #$fp= fopen($path.'02001-joko.csv', 'r');
-
- $tblname= "";
- $pmkey= "";
- while(!feof($fp)) {
- $buffer= fgets($fp);
- if( !empty($buffer) ){
- if( preg_match('#^\-.+$#', $buffer) ){
- $tblname= preg_replace(array("/-/","/;/","/ /"),array("","",""),$buffer);
- }elseif( preg_match('#^\*.+$#', $buffer) ){
- #$pmkey= preg_replace(array("/\*/","/;/"),array("",""),$buffer);
- }else{
- /*
- echo $tblname . "<br />";
- echo $pmkey . "<br />";
- echo $buffer . "<br />";
- */
- #$newstr = str_replace("<br/>", "\r\n", $value);
- echo $buffer . "<br />";
-
- $tblname= trim($tblname);
- $fields= $this->db->field_data(trim($tblname));
- $arrfield= array();
- $fieldname= "";
- $pmkey= "";
- foreach( $fields as $field ){
- if( $field->primary_key == 1 && $field->type != 'int'){
- $pmkey.= $field->name . ",";
- $fieldtype= $field->type;
- $fieldname= $field->name;
- $arrfield[]= $fieldname;
- }
- if( $field->primary_key != 1 ){
- $fieldname= $field->name;
- $arrfield[]= $fieldname;
- }
- }
- $pmkey= substr($pmkey, 0, -1);
- $arrpm= explode(",", $pmkey); // Array Primary Key
- $piedata= explode(";", $buffer); // Array Data
-
- $insdata= array();
- foreach( $piedata as $key=>$value ){
- $value= trim($value);
- if( !empty($value) ){
- $nmfield= $arrfield[$key];
- $newstr = str_replace("<br/>", "\r\n", $value);
- $insdata[$nmfield]= $newstr;
- }
- }
-
- /*
- print_r($pmkey);
- echo "<br/>";
- */
- if( !empty($pmkey) ){
- // Jika Primary key lebih dari 1
- $where= array();
- foreach( $arrpm as $key=>$value ){
- $where[$value]= $insdata[$value];
- }
-
- if( $tblname == "shipping_db" ){
- $stwhere= "";
- foreach( $where as $key=>$value ){
- $stwhere.= $key . "='" . $value . "' AND ";
- }
- $stwhere= substr($stwhere, 0, -5);
- $stwhere.= " OR ";
- $endwhere= "";
- $endwhere.= "Source='" . $where['Destination'] . "' AND Destination='" . $where['Source'] . "'";
- $where= "";
- $where= "" . $stwhere . $endwhere . "";
- $this->db->where($where, NULL, FALSE);
- }else{
- $this->db->where($where);
- }
- /*
- print_r($where);
- echo "<br/>";
- */
- $jml= $this->db->get($tblname)->num_rows();
- #echo $this->db->last_query() . "<br/>";
- #echo $jml . "<br/>";
- if( empty($jml) ){
- $this->db->insert($tblname, $insdata);
- echo "insert" . "<br/>";
- }else{
- if( $tblname == "shipping_db" ){
- $this->db->where($where, NULL, FALSE);
- }else{
- $this->db->where($where);
- }
- $this->db->update($tblname, $insdata);
- echo "update" . "<br/>";
- }
- }else{
- $this->db->insert($tblname, $insdata);
- echo "insert" . "<br/>";
- }
- /*
- print_r($insdata);
- echo "<br /><br />";
- */
- }
- }
- }
-
- fclose($fp);
-
- exit;
-
- }
- function submisi(){
- $fields= $this->db->list_fields('m_media');
- foreach($fields as $field){
- echo $field . "<br/>";
- }
- exit;
- #echo "test";
- $fields= $this->db->list_fields('produk_harga');
- foreach($fields as $field){
- echo $field . "<br/>";
- }
- exit;
- }
-
- function allupload(){
- #$this->ftplib= new ftplib("test","testing");
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- $this->ftplib->ftp_params($ftp_server, $username, $pass);
- $this->ftplib->upload_all();
- }
-
- function ftp_dirtree($path){
- $localpath= "C:/customerfile/";
- if( is_array($path) ){
- foreach( $path as $value ){
- $serverpath= $value;
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath);
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^.+\/\.svn$#", $value) ){
- $extensi= pathinfo($value, PATHINFO_EXTENSION);
- if( empty($extensi) ){
- $allDirectory[]= $value;
- }else{
- $files[]= $value;
- }
- }
- }
-
- if( count($allDirectory) ){
- $tree= ftp_tree($allDirectory);
- $files= array_merge($files, $tree);
- }
- }
- }
- }
- return $files;
- }
-
- function testme(){
- $repstr= "/www/crm_test/assets/restricted";
- $getstr= "www/crm_test/assets/restricted/employee/100";
- echo str_replace($repstr, "", $getstr);
- }
-
- function readyviaftp(){
- function get_webserverfile($path="", $infopathfl=""){
- if( is_array($infopathfl) ){
- $infopathfl= $infopathfl[0];
- }
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- $path_gro= pathinfo($value);
- $filename= $path_gro['basename'];
- $dirname= $path_gro['dirname'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
- $allDirectory[]= $getdir;
- }else{
- $value= $spec_path . "/" . $value;
- $files[]= $value;
- }
- }
- }
- if( count($allDirectory) ){
- $tree= get_webserverfile($allDirectory, $infopathfl);
- if( ! empty($tree) ){
- $files= array_merge($files, $tree);
- }
- }
- }
- }
- }
- if( !isset($files) ){
- $files= array();
- }
- return $files;
- }
-
- $path= array("/www/crm_test/assets/restricted");
- $serverfiles= array();
- $serverfiles= get_webserverfile($path, $path);
-
- function getuploadfile($path="", $infopathfl=""){
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- if( file_exists($spec_path) ){
- $linkfile= opendir($spec_path); // Open Directory
- $allDirectory= array();
- while( false !== ($file = readdir($linkfile)) ){ // Read Directory
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $file) ){ // Cek folder yang tidak termasuk
- $path_gro= pathinfo($file);
- $filename= $path_gro['basename'];
- $dirname= $path_gro['dirname'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $fullpath= $spec_path . "/" . $file;
- $allDirectory[]= $fullpath;
- }else{
- $fullpath= "/www/crm_test/assets/restricted" . $spec_path . "/" . $file;
- $fullpath= str_replace($infopathfl, "", $fullpath);
- $allfile[]= $fullpath;
- }
- }
- }
-
- if( count($allDirectory) ){
- $tree= getuploadfile($allDirectory, $infopathfl);
- $allfile= array_merge($allfile, $tree);
- }
- }
- }
- }
- return $allfile;
- }
-
- $localpath= array('./assets/restricted');
- $files= getuploadfile($localpath, $localpath);
-
- // Store Data Directory Server
- $dirserverfiles= array();
- foreach( $serverfiles as $file ){
- $fileinfo= pathinfo($file);
- $dirname= $fileinfo['dirname'];
- $dirserverfiles[]= $dirname;
- }
- $dirserverfiles= array_unique($dirserverfiles);
-
- $upload_path= "/www/crm_test/assets/restricted";
- $localpath= "./assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- print_r($files);
- echo "<br/>";
- print_r($serverfiles);
- echo "<br/>";
- foreach( $files as $file ){
- if( ! preg_match("#^.+\/\.(svn)$#", $file) ){
- $fileinfo= pathinfo($file);
- $filename= $fileinfo['basename'];
- $dirname= $fileinfo['dirname'];
- if( ! in_array($file, $serverfiles) ){
- $ftp_conn= ftp_connect($ftp_server);
- if( @ftp_login($ftp_conn, $username, $pass) ){
- ftp_chdir($ftp_conn, ".");
- if( ! in_array($dirname, $dirserverfiles) ){
- @ftp_mkdir($ftp_conn, $dirname);
- ftp_chdir($ftp_conn, $dirname);
- }else{
- ftp_chdir($ftp_conn, $dirname);
- }
- $pathnow= str_replace($upload_path, "", $dirname);
- $sourcefile= $localpath . $pathnow . "/" . $filename;
- echo $file . "->" . $sourcefile . "<br/>";
- ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
- }
- }else{
- echo $file . " is FILE EXIST<br/>";
- }
- }
- }
- }
-
- function uploadviaftp(){
-
- function ftp_tree($path="", $infopathfl=""){
- if( is_array($infopathfl) ){
- $infopathfl= $infopathfl[0];
- }
- #$localpath= "C:/customerfile/";
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- /*
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- $serverpath= $spec_path;
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
- */
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- #print_r($dir_tree);
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- #echo $value . "<br/>";
- $path_gro= pathinfo($value);
- $filename= $path_gro['basename'];
- $dirname= $path_gro['dirname'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
- $allDirectory[]= $getdir;
- }else{
- $value= $spec_path . "/" . $value;
- $files[]= $value;
- }
- }
- }
- /*
- print_r($allDirectory);
- echo "<br/>";
- */
- if( count($allDirectory) ){
- $tree= ftp_tree($allDirectory, $infopathfl);
- if( ! empty($tree) ){
- $files= array_merge($files, $tree);
- }
- /*
- print_r($tree);
- echo "<br/>";
- */
- #$files= array_merge($files, $tree);
- }
- }
- }
- }
- if( !isset($files) ){
- $files= array();
- }
- return $files;
- }
-
- #$path= array("crm/assets/restricted");
- $path= array("/www/crm_test/assets/restricted");
- $serverfiles= array();
- $serverfiles= ftp_tree($path, $path);
- /*
- print_r($serverfiles);
- echo "<br/>";
- */
-
- function uploadfile($path="", $infopathfl=""){
- /*
- if( ! isset($allfile) ){
- $allfile= array();
- }
- */
-
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- if( file_exists($spec_path) ){
- $linkfile= opendir($spec_path); // Open Directory
- $allDirectory= array();
- while( false !== ($file = readdir($linkfile)) ){ // Read Directory
- #$file= "./assets/restricted/.svn";
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $file) ){ // Cek folder yang tidak termasuk
- $path_gro= pathinfo($file);
- $filename= $path_gro['basename'];
- $dirname= $path_gro['dirname'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $fullpath= $spec_path . "/" . $file;
- #echo $fullpath . "<br/>";
- $allDirectory[]= $fullpath;
- }else{
- #echo $spec_path . "/" . $filename . "<br/>";
- #echo $spec_path . "/" . $file . "<br/>";
- #echo $ct . ". " . $spec_path . "/" . $file . "<br/>";
- $fullpath= "/www/crm_test/assets/restricted" . $spec_path . "/" . $file;
- $fullpath= str_replace($infopathfl, "", $fullpath);
- #echo $fullpath . "<br/>";
- $allfile[]= $fullpath;
- }
- /*
- print_r($allDirectory);
- echo "<br/>";
- */
- /*
- if( count($allDirectory) ){
- $tree= uploadfile($allDirectory);
- $allfile= array_merge($allfile, $tree);
- }
- */
- }
- }
-
- if( count($allDirectory) ){
- $tree= uploadfile($allDirectory, $infopathfl);
- $allfile= array_merge($allfile, $tree);
- #$allfile[]= uploadfile($allDirectory, $infopathfl);
- /*
- $tree= uploadfile($allDirectory);
- $allfile= array_merge($allfile, $tree);
- */
- }
- }else{
- #echo "File tidak Ada";
- }
- #print_r($allDirectory);
- }
- }
-
- return $allfile;
- }
-
-
- #$localpath= array('C:/customerfile/');
- $localpath= array('./assets/restricted');
- #$sourcepath= 'C:/customerfile/';
- $files= uploadfile($localpath, $localpath);
- /*
- print_r($files);
- echo "<br/>";
- */
- // Store Data Directory Server
- $dirserverfiles= array();
- foreach( $serverfiles as $file ){
- $fileinfo= pathinfo($file);
- $dirname= $fileinfo['dirname'];
- #echo $dirname . "->" . $file . "<br/>";
- $dirserverfiles[]= $dirname;
- }
- #print_r($dirserverfiles);
- $dirserverfiles= array_unique($dirserverfiles);
- /*
- print_r($dirserverfiles);
- echo "<br/>";
- */
-
- /*
- print_r($files);
- exit;
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
- $upload_path= "crm/assets/restricted";
- */
- /*
- $upload_path= "/www/crm_test/assets/restricted";
- $localpath= "./assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- $upload_path= "/www/crm_test/assets/restricted";
- $localpath= "./assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- //$destinationfile= "ftp://root:root@localhost/crm/assets/restricted/file.csv";
- #$server_files= ftp_nlist($ftp_conn, $upload_path);
- print_r($files);
- echo "<br/>";
- print_r($serverfiles);
- echo "<br/>";
- foreach( $files as $file ){
- if( ! preg_match("#^.+\/\.(svn)$#", $file) ){
- $fileinfo= pathinfo($file);
- $filename= $fileinfo['basename'];
- $dirname= $fileinfo['dirname'];
-
- #echo $filename . "<br/>";
- if( ! in_array($file, $serverfiles) ){
- $ftp_conn= ftp_connect($ftp_server);
- if( @ftp_login($ftp_conn, $username, $pass) ){
- ftp_chdir($ftp_conn, ".");
- if( ! in_array($dirname, $dirserverfiles) ){
- @ftp_mkdir($ftp_conn, $dirname);
- ftp_chdir($ftp_conn, $dirname);
- #echo $file . "<br/>";
- }else{
- #echo $file . " is DIRECTORY EXIST<br/>";
- #echo $dirname . "<br/>";
- ftp_chdir($ftp_conn, $dirname);
- }
- $pathnow= str_replace($upload_path, "", $dirname);
- $sourcefile= $localpath . $pathnow . "/" . $filename;
- /*
- echo $upload_path . "->";
- echo ftp_pwd($ftp_conn) . "->" . $sourcefile . "<br/>";
- */
- echo $file . "->" . $sourcefile . "<br/>";
- ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
- #echo $sourcefile. "<br/>";
- }
- #}
- /*
- $pathparts= pathinfo($file);
- $filename= $pathparts['basename'];
- $dirname= $pathparts['dirname'];
- $fullpath= $upload_path . $file;
- #echo $dirname . "=>" . $filename . "<br/>";
- #$sourcefile= $sourcepath . $file;
- $destinationfile= $upload_path . $dirname;
-
- $exists_dir= is_dir('ftp://thsgcrmi:tHsc3900173!@localhost/' . $destinationfile);
- if( $exists_dir ){
- echo $exists_dir . "->" . $file . "<br/>";
- #ftp_chdir($ftp_conn, $destinationfile);
- }
- */
- /*
- if( ! @ftp_chdir($ftp_conn, $destinationfile) ){
- ftp_mkdir($ftp_conn, $destinationfile);
- ftp_chdir($ftp_conn, $destinationfile);
- }
- */
- #ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
- }else{
- echo $file . " is FILE EXIST<br/>";
- }
- }
- }
- #print_r($files);
- }
-
- function gsdataviaftp(){
- // Get Data from server via FTP
- function ftp_tree($path="", $infopathfl=""){
- if( is_array($infopathfl) ){
- $infopathfl= $infopathfl[0];
- }
- $localpath= "C:/customerfile/";
- /*
- $serverpath= "www/crm_test/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- #echo $spec_path . "<br/>";
- /*
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- $serverpath= $spec_path;
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- #print_r($dir_tree);
-
- #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- #$value= "employee";
- $path_gro= pathinfo($value);
- $filename= $path_gro['basename'];
- $dirname= $path_gro['dirname'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
- #echo $getdir . "<br/>";
- $allDirectory[]= $getdir;
- }else{
- $filelink= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
- $relfile= str_replace($infopathfl, "", $filelink);
- $localfile= $localpath . $relfile;
- $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
- $serverfile= $filelink;
- #echo $serverfile . "<br/>";
- #echo $infopathfl . "->" . $relfile . "<br/>";
-
- #echo $localdir . "->" . $serverfile . "<br/>";
- #echo $relfile . "<br/>";
- $files[]= $value;
- if( ! file_exists($localdir) ){
- mkdir($localdir);
- }
-
- #ftp_chdir($ftp_conn, $destinationfile);
- if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
- #echo $relfile . "<br/>";
- #$files[]= $value;
- }
- }
- }
- }
-
- #print_r($allDirectory);
- if( count($allDirectory) ){
- ftp_tree($allDirectory, $infopathfl);
- #$tree= ftp_tree($allDirectory, $infopathfl);
- #$files= array_merge($files, $tree);
- }
- }
- }
- }
- if( !isset($files) ){
- $files= "";
- }
- return $files;
- }
-
- $path= array("crm/assets/restricted");
- #$path= array("www/crm_test/assets/restricted");
- $FTP_file= ftp_tree($path, $path);
- /*
- $serverpath= "crm/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- echo "connect";
- }else{
- echo "no connect";
- }
- exit;
- */
- }
-
- function ftpme(){
- function ftp_tree($path="", $infopathfl=""){
- if( is_array($infopathfl) ){
- $infopathfl= $infopathfl[0];
- }
- $localpath= "C:/customerfile/";
- /*
- $serverpath= "www/crm_test/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- #echo $spec_path . "<br/>";
- /*
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- $serverpath= $spec_path;
- #echo $serverpath . "<br/>";
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- $path_gro= pathinfo($value);
- $filename= $path_gro['basename'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $allDirectory[]= $value;
- }else{
- #$filelink= $spec_path . "/" . $value;
- $relfile= str_replace($infopathfl, "", $value);
- $localfile= $localpath . $relfile;
- $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
- $serverfile= $value;
- #$serverfile= $spec_path . "/" . $value;
- #echo $infopathfl . "<br/>";
- #echo $infopathfl . "->" . $relfile . "<br/>";
-
- #echo $localdir . "->" . $serverfile . "<br/>";
- #echo $relfile . "<br/>";
- $files[]= $value;
- if( ! file_exists($localdir) ){
- mkdir($localdir);
- }
-
- #ftp_chdir($ftp_conn, $destinationfile);
- if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
- echo $serverfile . "<br/>";
- #$files[]= $value;
- }
- }
- }
- }
-
- #print_r($allDirectory);
- if( count($allDirectory) ){
- ftp_tree($allDirectory, $infopathfl);
- #$tree= ftp_tree($allDirectory, $infopathfl);
- #$files= array_merge($files, $tree);
- }
- }
- }
- }
- if( !isset($files) ){
- $files= "";
- }
- return $files;
- }
-
- $path= array("crm/assets/restricted");
- #$path= array("www/crm_test/assets/restricted");
- $FTP_file= ftp_tree($path, $path);
- /*
- $serverpath= "www/crm_test/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- /*
- $serverpath= "crm/assets/restricted";
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- echo $value . "<br/>";
- #print_r($dir_tree);
- }
- }
- }
- */
- #print_r($FTP_file);
- }
-
- function index(){
-
- function ftp_tree($path="", $infopathfl=""){
- $localpath= "C:/customerfile/";
- /*
- $serverpath= "www/crm_test/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- if( is_array($path) ){
- foreach( $path as $spec_path ){
- #echo $spec_path . "<br/>";
- $serverpath= $spec_path;
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- /*
- $serverpath= $value;
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
- */
-
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
- #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
- $allDirectory= array();
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
- #echo $value . "<br/>";
- $path_gro= pathinfo($value);
- $filename= $path_gro['basename'];
- $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
- if( empty($extensi) ){
- $allDirectory[]= $spec_path . "/" . $value;
- }else{
- $relfile= str_replace($infopathfl, "", $value);
- $localfile= $localpath . $relfile;
- $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
- $serverfile= $spec_path . "/" . $value;
- #echo $localfile . "->" . $serverfile . "<br/>";
- #echo $relfile . "<br/>";
- $files[]= $value;
- if( ! file_exists($localdir) ){
- mkdir($localdir);
- }
-
- #ftp_chdir($ftp_conn, $destinationfile);
- if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
- echo $relfile . "<br/>";
- #$files[]= $value;
- }
- }
- }
- }
-
- #print_r($allDirectory);
- if( count($allDirectory) ){
- ftp_tree($allDirectory, $infopathfl);
- #$tree= ftp_tree($allDirectory, $infopathfl);
- #$files= array_merge($files, $tree);
- }
- }
- }
- }
- if( !isset($files) ){
- $files= "";
- }
- return $files;
- }
-
- #$path= array("crm/assets/restricted");
- $path= array("www/crm_test/assets/restricted");
- $FTP_file= ftp_tree($path, $path);
-
- function ftp_all($addpath=""){
- $localpath= "C:/customerfile/";
- /*
- $serverpath= "www/crm_test/assets/restricted";
- $ftp_server= "ftp.thsgcrmid.com";
- $username= "thsgcrmi";
- $pass= "tHsc3900173!";
- */
- $serverpath= "crm/assets/restricted";
- $ftp_server= "localhost";
- $username= "root";
- $pass= "root";
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- #echo "Connect" . "<br/>";
- $dir_tree= ftp_rawlist($ftp_conn, $serverpath, TRUE);
- #$dir_tree= ftp_nlist($ftp_conn, $serverpath);
- #print_r($groupdt);
- $allDirectory[]= $serverpath;
- foreach( $dir_tree as $value ){
- if( preg_match("#^.+:$#", $value) ){
- #echo $value . "<br/>";
- $dirname= substr($value, 0, -1);
- $allDirectory[]= $dirname;
- }
- echo $value . "<br/>";
- }
- }
- #print_r($dir_tree);
- exit;
-
- /*
- foreach( $allDirectory as $dirname ){
- $ftp_conn= ftp_connect($ftp_server);
- if( ftp_login($ftp_conn, $username, $pass) ){
- $dir_tree= ftp_nlist($ftp_conn, $dirname);
- ftp_chdir($ftp_conn, $dirname);
- $current_dir= ftp_pwd($ftp_conn);
- echo $current_dir . "<br/>";
- echo "===================================" . "<br/>";
- #print_r($dir_tree);
- foreach( $dir_tree as $value ){
- if( ! preg_match("#^[ |\.][.+]?$#", $value) ){
- $extensi= pathinfo($value, PATHINFO_EXTENSION);
- if( ! empty($extensi) ){
- $additional_path= str_replace($serverpath, "", $dirname);
- echo $additional_path . "<br/>";
- $nowpath= $localpath . $additional_path;
- if( ! file_exists($nowpath) ){
- mkdir($nowpath);
- }
- ftp_get($ftp_conn, $nowpath, $value, FTP_BINARY);
- #echo $value . "<br/>";
- }
- }
- }
- }else{
- echo "Don't Connect";
- }
- }
- */
- }
-
- ftp_tree();
- }
- }
- ?>