PageRenderTime 69ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/tester3.php

https://bitbucket.org/remobius/crm
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
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. class tester3 extends CI_Controller {
  3. private $modul;
  4. public $ftp;
  5. public function __construct() {
  6. parent::__construct();
  7. $webserverpath= "/www/crm_test/assets/restricted";
  8. $serverpath= "./assets/restricted";
  9. $params= array("webserverpath"=>$webserverpath,"serverpath"=>$serverpath);
  10. $this->load->library("ftplib", $params);
  11. #$ftp= new ftplib("test","testing");
  12. #$this->ftp("test","testing");
  13. #ini_set("max_execution_time", "60000");
  14. }
  15. /*
  16. $cart= array();
  17. foreach( $getcart as $key=>$value ){
  18. $IdProduk= $value['IdProduk'];
  19. $cart[$IdProduk][]= $value;
  20. }
  21. foreach( $cart as $key=>$value ){
  22. $qty= count($cart[$key]);
  23. foreach( $value as $subkey=>$subvalue ){
  24. echo $subvalue['NamaCategory'] . "->";
  25. echo $subvalue['Vendor'] . "->";
  26. echo $subvalue['Model'] . "->";
  27. echo $subvalue['NoSerial'] . "->";
  28. echo $qty . "->";
  29. echo $subvalue['SubTotal'] . "<br/>";
  30. $subvalue['Qty']= $qty;
  31. $cartnew[$key]= $subvalue;
  32. }
  33. }
  34. */
  35. function sapaan(){
  36. echo $this->Gmodel->getInvoiceID('01001');
  37. exit;
  38. $insdata['AddUser']= "ADMIN";
  39. $insdata['AddDate']= date("Y-m-d");
  40. $this->db->select('MediaType');
  41. $media= array('OUTDOOR','PRINT','SOCIAL MEDIA');
  42. $this->db->where_in('MediaType', $media);
  43. $newdata= $this->db->get('m_media_type')->result_array();
  44. foreach( $newdata as $key=>$value ){
  45. $insdata['NamaSource']= ucfirst(strtolower($value['MediaType']));
  46. $this->db->insert('konsumen_source', $insdata);
  47. }
  48. exit;
  49. $this->db->select('NamaSource');
  50. $cust_source= $this->db->get('konsumen_source')->result_array();
  51. $sql= "SELECT MediaType AS NamaSource FROM m_media_type
  52. GROUP BY MediaType";
  53. $media= $this->db->query($sql)->result_array();
  54. $lastsource= count($cust_source);
  55. $all= array();
  56. foreach( $cust_source as $value ){
  57. $all[]= $value;
  58. }
  59. foreach( $media as $value ){
  60. $all[]= $value;
  61. }
  62. array_multisort($all);
  63. foreach( $all as $value ){
  64. echo $value['NamaSource'] . "<br/>";
  65. }
  66. print_r($all);
  67. exit;
  68. $cond_negara= array('ID','KR','MY','SG');
  69. $this->db->where_in('IdNegara',$cond_negara);
  70. $stnegara= $this->db->get('m_negara')->result_array();
  71. foreach( $stnegara as $key=>$value ){
  72. echo "<option value=\"" . $value['IdNegara'] . "\">" . $value['NamaNegara'] . "</option>";
  73. }
  74. exit;
  75. $IdNegara= strtolower($this->uri->segment(1));
  76. $sql= "SELECT IdSapaan, " . $IdNegara . "_NamaSapaan FROM m_sapaan";
  77. $data= $this->db->query($sql)->result_array();
  78. print_r($data);
  79. exit;
  80. }
  81. function insertdata(){
  82. $clinic= array('02003', '02001');
  83. $nilai= 02001;
  84. settype($nilai, "string");
  85. $test= "'" . $nilai . "'";
  86. echo $nilai;
  87. #settype($nilai, "string");
  88. #var_dump($nilai);
  89. #echo array_search($nilai, $clinic);
  90. #echo array_search($nilai, $clinic);
  91. /*
  92. if( array_search($nilai, $clinic) ){
  93. echo "ada";
  94. }
  95. */
  96. exit;
  97. $this->db->select("NoSerial");
  98. $result= $this->db->get_where("penjualan_detail_sn")->result_array();
  99. $group= "'";
  100. foreach( $result as $value ){
  101. $group.= $value['NoSerial'] . ",";
  102. }
  103. $group.= "'";
  104. echo $group;
  105. #print_r($result);
  106. exit;
  107. echo sha1("admin");
  108. exit;
  109. $dtupdate= array("Status"=>1);
  110. $wheresn= array("NoSerial"=>'0079206');
  111. $this->db->where($wheresn);
  112. $this->db->update("produk_sn", $dtupdate);
  113. echo $this->db->last_query();
  114. exit;
  115. $sale= array('Id'=>'34','IdKonsumen'=>'02001000000025','AddUser'=>'joko','IdProduk'=>'020002','Qty'=>'',
  116. 'MataUang'=>'IDR','AddDate'=>'2011-09-28 00:00:00','Left'=>'0','Right'=>'0');
  117. $allsn= array(0=>array('IdSale'=>'34','IdProduk'=>'020002','NoSerial'=>'0079206','Type'=>'',
  118. 'AddUser'=>'joko','AddDate'=>'2011-09-28'), 1=>array('IdSale'=>'34',
  119. 'IdProduk'=>'020002','NoSerial'=>'8039046','Type'=>'','AddUser'=>'joko','AddDate'=>'2011-09-28'));
  120. $this->db->insert("penjualan_temp", $sale);
  121. foreach( $allsn as $value ){
  122. $this->db->insert("penjualan_sn_temp", $value);
  123. }
  124. exit;
  125. #$getwhere= array("IdSale"=>"34");
  126. $getwhere= array("Id"=>"34");
  127. $result= $this->db->get_where("penjualan_temp", $getwhere)->result_array();
  128. $data= "array(";
  129. foreach( $result as $key=>$value ){
  130. $data.= "$key=>array(";
  131. foreach( $value as $subkey=>$subvalue ){
  132. $data.= "'" . $subkey . "'=>'" . $subvalue . "',";
  133. }
  134. }
  135. print_r($data);
  136. exit;
  137. $sale= array('Id'=>'34','IdKonsumen'=>'02001000000025','AddUser'=>'joko','IdProduk'=>'020002','Qty'=>'',
  138. 'MataUang'=>'IDR','AddDate'=>'2011-09-28 00:00:00','Left'=>'0','Right'=>'0');
  139. $allsn= array(0=>array('IdSale'=>'34','IdProduk'=>'020002','NoSerial'=>'0079206','Type'=>'',
  140. 'AddUser'=>'joko','AddDate'=>'2011-09-28'), 1=>array('IdSale'=>'34',
  141. 'IdProduk'=>'020002','NoSerial'=>'8039046','Type'=>'','AddUser'=>'joko','AddDate'=>'2011-09-28'));
  142. $this->db->insert($sale);
  143. $this->db->insert($allsn);
  144. $sql= "SELECT SUM(b.Harga) AS RealPrice, BesarDiskon AS Diskon,
  145. (SUM(b.Harga) - (SUM(b.Harga) * BesarDiskon/100)) AS SubTotal FROM penjualan_sn_temp a
  146. INNER JOIN produk_harga b ON a.IdProduk= b.IdProduk
  147. WHERE a.IdSale='34' AND b.IdMataUang='IDR'";
  148. $row= $this->db->query($sql)->row_array();
  149. print_r($row);
  150. exit;
  151. $fields= $this->db->list_fields('penjualan_detail_sn');
  152. $str= 'array(';
  153. $strout= "";
  154. foreach($fields as $field){
  155. $strout.= $field . "<br/>";
  156. $str.= "'$field',";
  157. }
  158. echo $strout;
  159. exit;
  160. /*
  161. $produk= array('IdProduk'=>'CI-8500DX','IdCategory'=>'CHI','IdVendor'=>'ABI',
  162. 'NamaProduk'=>'Auria Duluxe Kit','Model'=>'Auria Duluxe Kit','Garansi'=>12,
  163. 'Type'=>'P','AddUser'=>'ADMIN','AddDate'=>'2011-09-27');
  164. if( ! $this->Gmodel->isExist("produk",array('IdProduk'=>'CI-8500DX')) ){
  165. $this->db->insert("produk",$produk);
  166. }else{
  167. $this->db->where('IdProduk','CI-8500DX');
  168. $this->db->update("produk",$produk);
  169. }
  170. exit;
  171. */
  172. #CI-8500DX Auria Duluxe Kit 36428S
  173. /*
  174. $fields = $this->db->list_fields('produk_harga');
  175. $str= 'array(';
  176. foreach($fields as $field){
  177. $str.= "'$field',";
  178. }
  179. echo $str;
  180. */
  181. $data= array('IdProduk'=>'050-0032-01','IdMataUang'=>'SGD','Harga'=>600,
  182. 'AddUser'=>'ADMIN','AddDate'=>'2011-09-26');
  183. $this->db->insert('produk_harga', $data);
  184. /*
  185. $data= array(
  186. 'IdProduk'=>'00043237',
  187. 'IdMataUang'=>'SGD',
  188. 'Harga'=>'50'
  189. );
  190. $this->db->insert('produk_harga', $data);
  191. */
  192. }
  193. // Import Data Cara 2 dengan Double Primary Key
  194. public function import(){
  195. $path= "./assets/restricted/";
  196. $fp= fopen($path.'m_media_kategori.csv', 'r');
  197. #$fp= fopen($path.'02001-joko.csv', 'r');
  198. $tblname= "";
  199. $pmkey= "";
  200. while(!feof($fp)) {
  201. $buffer= fgets($fp);
  202. if( !empty($buffer) ){
  203. if( preg_match('#^\-.+$#', $buffer) ){
  204. $tblname= preg_replace(array("/-/","/;/","/ /"),array("","",""),$buffer);
  205. }elseif( preg_match('#^\*.+$#', $buffer) ){
  206. #$pmkey= preg_replace(array("/\*/","/;/"),array("",""),$buffer);
  207. }else{
  208. /*
  209. echo $tblname . "<br />";
  210. echo $pmkey . "<br />";
  211. echo $buffer . "<br />";
  212. */
  213. #$newstr = str_replace("<br/>", "\r\n", $value);
  214. echo $buffer . "<br />";
  215. $tblname= trim($tblname);
  216. $fields= $this->db->field_data(trim($tblname));
  217. $arrfield= array();
  218. $fieldname= "";
  219. $pmkey= "";
  220. foreach( $fields as $field ){
  221. if( $field->primary_key == 1 && $field->type != 'int'){
  222. $pmkey.= $field->name . ",";
  223. $fieldtype= $field->type;
  224. $fieldname= $field->name;
  225. $arrfield[]= $fieldname;
  226. }
  227. if( $field->primary_key != 1 ){
  228. $fieldname= $field->name;
  229. $arrfield[]= $fieldname;
  230. }
  231. }
  232. $pmkey= substr($pmkey, 0, -1);
  233. $arrpm= explode(",", $pmkey); // Array Primary Key
  234. $piedata= explode(";", $buffer); // Array Data
  235. $insdata= array();
  236. foreach( $piedata as $key=>$value ){
  237. $value= trim($value);
  238. if( !empty($value) ){
  239. $nmfield= $arrfield[$key];
  240. $newstr = str_replace("<br/>", "\r\n", $value);
  241. $insdata[$nmfield]= $newstr;
  242. }
  243. }
  244. /*
  245. print_r($pmkey);
  246. echo "<br/>";
  247. */
  248. if( !empty($pmkey) ){
  249. // Jika Primary key lebih dari 1
  250. $where= array();
  251. foreach( $arrpm as $key=>$value ){
  252. $where[$value]= $insdata[$value];
  253. }
  254. if( $tblname == "shipping_db" ){
  255. $stwhere= "";
  256. foreach( $where as $key=>$value ){
  257. $stwhere.= $key . "='" . $value . "' AND ";
  258. }
  259. $stwhere= substr($stwhere, 0, -5);
  260. $stwhere.= " OR ";
  261. $endwhere= "";
  262. $endwhere.= "Source='" . $where['Destination'] . "' AND Destination='" . $where['Source'] . "'";
  263. $where= "";
  264. $where= "" . $stwhere . $endwhere . "";
  265. $this->db->where($where, NULL, FALSE);
  266. }else{
  267. $this->db->where($where);
  268. }
  269. /*
  270. print_r($where);
  271. echo "<br/>";
  272. */
  273. $jml= $this->db->get($tblname)->num_rows();
  274. #echo $this->db->last_query() . "<br/>";
  275. #echo $jml . "<br/>";
  276. if( empty($jml) ){
  277. $this->db->insert($tblname, $insdata);
  278. echo "insert" . "<br/>";
  279. }else{
  280. if( $tblname == "shipping_db" ){
  281. $this->db->where($where, NULL, FALSE);
  282. }else{
  283. $this->db->where($where);
  284. }
  285. $this->db->update($tblname, $insdata);
  286. echo "update" . "<br/>";
  287. }
  288. }else{
  289. $this->db->insert($tblname, $insdata);
  290. echo "insert" . "<br/>";
  291. }
  292. /*
  293. print_r($insdata);
  294. echo "<br /><br />";
  295. */
  296. }
  297. }
  298. }
  299. fclose($fp);
  300. exit;
  301. }
  302. function submisi(){
  303. $fields= $this->db->list_fields('m_media');
  304. foreach($fields as $field){
  305. echo $field . "<br/>";
  306. }
  307. exit;
  308. #echo "test";
  309. $fields= $this->db->list_fields('produk_harga');
  310. foreach($fields as $field){
  311. echo $field . "<br/>";
  312. }
  313. exit;
  314. }
  315. function allupload(){
  316. #$this->ftplib= new ftplib("test","testing");
  317. $ftp_server= "ftp.thsgcrmid.com";
  318. $username= "thsgcrmi";
  319. $pass= "tHsc3900173!";
  320. $this->ftplib->ftp_params($ftp_server, $username, $pass);
  321. $this->ftplib->upload_all();
  322. }
  323. function ftp_dirtree($path){
  324. $localpath= "C:/customerfile/";
  325. if( is_array($path) ){
  326. foreach( $path as $value ){
  327. $serverpath= $value;
  328. $ftp_server= "localhost";
  329. $username= "root";
  330. $pass= "root";
  331. $ftp_conn= ftp_connect($ftp_server);
  332. if( ftp_login($ftp_conn, $username, $pass) ){
  333. $dir_tree= ftp_nlist($ftp_conn, $serverpath);
  334. $allDirectory= array();
  335. foreach( $dir_tree as $value ){
  336. if( ! preg_match("#^.+\/\.svn$#", $value) ){
  337. $extensi= pathinfo($value, PATHINFO_EXTENSION);
  338. if( empty($extensi) ){
  339. $allDirectory[]= $value;
  340. }else{
  341. $files[]= $value;
  342. }
  343. }
  344. }
  345. if( count($allDirectory) ){
  346. $tree= ftp_tree($allDirectory);
  347. $files= array_merge($files, $tree);
  348. }
  349. }
  350. }
  351. }
  352. return $files;
  353. }
  354. function testme(){
  355. $repstr= "/www/crm_test/assets/restricted";
  356. $getstr= "www/crm_test/assets/restricted/employee/100";
  357. echo str_replace($repstr, "", $getstr);
  358. }
  359. function readyviaftp(){
  360. function get_webserverfile($path="", $infopathfl=""){
  361. if( is_array($infopathfl) ){
  362. $infopathfl= $infopathfl[0];
  363. }
  364. if( is_array($path) ){
  365. foreach( $path as $spec_path ){
  366. $serverpath= $spec_path;
  367. $ftp_server= "ftp.thsgcrmid.com";
  368. $username= "thsgcrmi";
  369. $pass= "tHsc3900173!";
  370. $ftp_conn= ftp_connect($ftp_server);
  371. if( ftp_login($ftp_conn, $username, $pass) ){
  372. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  373. $allDirectory= array();
  374. foreach( $dir_tree as $value ){
  375. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  376. $path_gro= pathinfo($value);
  377. $filename= $path_gro['basename'];
  378. $dirname= $path_gro['dirname'];
  379. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  380. if( empty($extensi) ){
  381. $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
  382. $allDirectory[]= $getdir;
  383. }else{
  384. $value= $spec_path . "/" . $value;
  385. $files[]= $value;
  386. }
  387. }
  388. }
  389. if( count($allDirectory) ){
  390. $tree= get_webserverfile($allDirectory, $infopathfl);
  391. if( ! empty($tree) ){
  392. $files= array_merge($files, $tree);
  393. }
  394. }
  395. }
  396. }
  397. }
  398. if( !isset($files) ){
  399. $files= array();
  400. }
  401. return $files;
  402. }
  403. $path= array("/www/crm_test/assets/restricted");
  404. $serverfiles= array();
  405. $serverfiles= get_webserverfile($path, $path);
  406. function getuploadfile($path="", $infopathfl=""){
  407. if( is_array($path) ){
  408. foreach( $path as $spec_path ){
  409. if( file_exists($spec_path) ){
  410. $linkfile= opendir($spec_path); // Open Directory
  411. $allDirectory= array();
  412. while( false !== ($file = readdir($linkfile)) ){ // Read Directory
  413. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $file) ){ // Cek folder yang tidak termasuk
  414. $path_gro= pathinfo($file);
  415. $filename= $path_gro['basename'];
  416. $dirname= $path_gro['dirname'];
  417. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  418. if( empty($extensi) ){
  419. $fullpath= $spec_path . "/" . $file;
  420. $allDirectory[]= $fullpath;
  421. }else{
  422. $fullpath= "/www/crm_test/assets/restricted" . $spec_path . "/" . $file;
  423. $fullpath= str_replace($infopathfl, "", $fullpath);
  424. $allfile[]= $fullpath;
  425. }
  426. }
  427. }
  428. if( count($allDirectory) ){
  429. $tree= getuploadfile($allDirectory, $infopathfl);
  430. $allfile= array_merge($allfile, $tree);
  431. }
  432. }
  433. }
  434. }
  435. return $allfile;
  436. }
  437. $localpath= array('./assets/restricted');
  438. $files= getuploadfile($localpath, $localpath);
  439. // Store Data Directory Server
  440. $dirserverfiles= array();
  441. foreach( $serverfiles as $file ){
  442. $fileinfo= pathinfo($file);
  443. $dirname= $fileinfo['dirname'];
  444. $dirserverfiles[]= $dirname;
  445. }
  446. $dirserverfiles= array_unique($dirserverfiles);
  447. $upload_path= "/www/crm_test/assets/restricted";
  448. $localpath= "./assets/restricted";
  449. $ftp_server= "ftp.thsgcrmid.com";
  450. $username= "thsgcrmi";
  451. $pass= "tHsc3900173!";
  452. print_r($files);
  453. echo "<br/>";
  454. print_r($serverfiles);
  455. echo "<br/>";
  456. foreach( $files as $file ){
  457. if( ! preg_match("#^.+\/\.(svn)$#", $file) ){
  458. $fileinfo= pathinfo($file);
  459. $filename= $fileinfo['basename'];
  460. $dirname= $fileinfo['dirname'];
  461. if( ! in_array($file, $serverfiles) ){
  462. $ftp_conn= ftp_connect($ftp_server);
  463. if( @ftp_login($ftp_conn, $username, $pass) ){
  464. ftp_chdir($ftp_conn, ".");
  465. if( ! in_array($dirname, $dirserverfiles) ){
  466. @ftp_mkdir($ftp_conn, $dirname);
  467. ftp_chdir($ftp_conn, $dirname);
  468. }else{
  469. ftp_chdir($ftp_conn, $dirname);
  470. }
  471. $pathnow= str_replace($upload_path, "", $dirname);
  472. $sourcefile= $localpath . $pathnow . "/" . $filename;
  473. echo $file . "->" . $sourcefile . "<br/>";
  474. ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
  475. }
  476. }else{
  477. echo $file . " is FILE EXIST<br/>";
  478. }
  479. }
  480. }
  481. }
  482. function uploadviaftp(){
  483. function ftp_tree($path="", $infopathfl=""){
  484. if( is_array($infopathfl) ){
  485. $infopathfl= $infopathfl[0];
  486. }
  487. #$localpath= "C:/customerfile/";
  488. if( is_array($path) ){
  489. foreach( $path as $spec_path ){
  490. /*
  491. $serverpath= $spec_path;
  492. $ftp_server= "ftp.thsgcrmid.com";
  493. $username= "thsgcrmi";
  494. $pass= "tHsc3900173!";
  495. $serverpath= $spec_path;
  496. $ftp_server= "localhost";
  497. $username= "root";
  498. $pass= "root";
  499. */
  500. $serverpath= $spec_path;
  501. $ftp_server= "ftp.thsgcrmid.com";
  502. $username= "thsgcrmi";
  503. $pass= "tHsc3900173!";
  504. $ftp_conn= ftp_connect($ftp_server);
  505. if( ftp_login($ftp_conn, $username, $pass) ){
  506. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  507. #print_r($dir_tree);
  508. $allDirectory= array();
  509. foreach( $dir_tree as $value ){
  510. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  511. #echo $value . "<br/>";
  512. $path_gro= pathinfo($value);
  513. $filename= $path_gro['basename'];
  514. $dirname= $path_gro['dirname'];
  515. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  516. if( empty($extensi) ){
  517. $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
  518. $allDirectory[]= $getdir;
  519. }else{
  520. $value= $spec_path . "/" . $value;
  521. $files[]= $value;
  522. }
  523. }
  524. }
  525. /*
  526. print_r($allDirectory);
  527. echo "<br/>";
  528. */
  529. if( count($allDirectory) ){
  530. $tree= ftp_tree($allDirectory, $infopathfl);
  531. if( ! empty($tree) ){
  532. $files= array_merge($files, $tree);
  533. }
  534. /*
  535. print_r($tree);
  536. echo "<br/>";
  537. */
  538. #$files= array_merge($files, $tree);
  539. }
  540. }
  541. }
  542. }
  543. if( !isset($files) ){
  544. $files= array();
  545. }
  546. return $files;
  547. }
  548. #$path= array("crm/assets/restricted");
  549. $path= array("/www/crm_test/assets/restricted");
  550. $serverfiles= array();
  551. $serverfiles= ftp_tree($path, $path);
  552. /*
  553. print_r($serverfiles);
  554. echo "<br/>";
  555. */
  556. function uploadfile($path="", $infopathfl=""){
  557. /*
  558. if( ! isset($allfile) ){
  559. $allfile= array();
  560. }
  561. */
  562. if( is_array($path) ){
  563. foreach( $path as $spec_path ){
  564. if( file_exists($spec_path) ){
  565. $linkfile= opendir($spec_path); // Open Directory
  566. $allDirectory= array();
  567. while( false !== ($file = readdir($linkfile)) ){ // Read Directory
  568. #$file= "./assets/restricted/.svn";
  569. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $file) ){ // Cek folder yang tidak termasuk
  570. $path_gro= pathinfo($file);
  571. $filename= $path_gro['basename'];
  572. $dirname= $path_gro['dirname'];
  573. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  574. if( empty($extensi) ){
  575. $fullpath= $spec_path . "/" . $file;
  576. #echo $fullpath . "<br/>";
  577. $allDirectory[]= $fullpath;
  578. }else{
  579. #echo $spec_path . "/" . $filename . "<br/>";
  580. #echo $spec_path . "/" . $file . "<br/>";
  581. #echo $ct . ". " . $spec_path . "/" . $file . "<br/>";
  582. $fullpath= "/www/crm_test/assets/restricted" . $spec_path . "/" . $file;
  583. $fullpath= str_replace($infopathfl, "", $fullpath);
  584. #echo $fullpath . "<br/>";
  585. $allfile[]= $fullpath;
  586. }
  587. /*
  588. print_r($allDirectory);
  589. echo "<br/>";
  590. */
  591. /*
  592. if( count($allDirectory) ){
  593. $tree= uploadfile($allDirectory);
  594. $allfile= array_merge($allfile, $tree);
  595. }
  596. */
  597. }
  598. }
  599. if( count($allDirectory) ){
  600. $tree= uploadfile($allDirectory, $infopathfl);
  601. $allfile= array_merge($allfile, $tree);
  602. #$allfile[]= uploadfile($allDirectory, $infopathfl);
  603. /*
  604. $tree= uploadfile($allDirectory);
  605. $allfile= array_merge($allfile, $tree);
  606. */
  607. }
  608. }else{
  609. #echo "File tidak Ada";
  610. }
  611. #print_r($allDirectory);
  612. }
  613. }
  614. return $allfile;
  615. }
  616. #$localpath= array('C:/customerfile/');
  617. $localpath= array('./assets/restricted');
  618. #$sourcepath= 'C:/customerfile/';
  619. $files= uploadfile($localpath, $localpath);
  620. /*
  621. print_r($files);
  622. echo "<br/>";
  623. */
  624. // Store Data Directory Server
  625. $dirserverfiles= array();
  626. foreach( $serverfiles as $file ){
  627. $fileinfo= pathinfo($file);
  628. $dirname= $fileinfo['dirname'];
  629. #echo $dirname . "->" . $file . "<br/>";
  630. $dirserverfiles[]= $dirname;
  631. }
  632. #print_r($dirserverfiles);
  633. $dirserverfiles= array_unique($dirserverfiles);
  634. /*
  635. print_r($dirserverfiles);
  636. echo "<br/>";
  637. */
  638. /*
  639. print_r($files);
  640. exit;
  641. $ftp_server= "localhost";
  642. $username= "root";
  643. $pass= "root";
  644. $upload_path= "crm/assets/restricted";
  645. */
  646. /*
  647. $upload_path= "/www/crm_test/assets/restricted";
  648. $localpath= "./assets/restricted";
  649. $ftp_server= "ftp.thsgcrmid.com";
  650. $username= "thsgcrmi";
  651. $pass= "tHsc3900173!";
  652. */
  653. $upload_path= "/www/crm_test/assets/restricted";
  654. $localpath= "./assets/restricted";
  655. $ftp_server= "ftp.thsgcrmid.com";
  656. $username= "thsgcrmi";
  657. $pass= "tHsc3900173!";
  658. //$destinationfile= "ftp://root:root@localhost/crm/assets/restricted/file.csv";
  659. #$server_files= ftp_nlist($ftp_conn, $upload_path);
  660. print_r($files);
  661. echo "<br/>";
  662. print_r($serverfiles);
  663. echo "<br/>";
  664. foreach( $files as $file ){
  665. if( ! preg_match("#^.+\/\.(svn)$#", $file) ){
  666. $fileinfo= pathinfo($file);
  667. $filename= $fileinfo['basename'];
  668. $dirname= $fileinfo['dirname'];
  669. #echo $filename . "<br/>";
  670. if( ! in_array($file, $serverfiles) ){
  671. $ftp_conn= ftp_connect($ftp_server);
  672. if( @ftp_login($ftp_conn, $username, $pass) ){
  673. ftp_chdir($ftp_conn, ".");
  674. if( ! in_array($dirname, $dirserverfiles) ){
  675. @ftp_mkdir($ftp_conn, $dirname);
  676. ftp_chdir($ftp_conn, $dirname);
  677. #echo $file . "<br/>";
  678. }else{
  679. #echo $file . " is DIRECTORY EXIST<br/>";
  680. #echo $dirname . "<br/>";
  681. ftp_chdir($ftp_conn, $dirname);
  682. }
  683. $pathnow= str_replace($upload_path, "", $dirname);
  684. $sourcefile= $localpath . $pathnow . "/" . $filename;
  685. /*
  686. echo $upload_path . "->";
  687. echo ftp_pwd($ftp_conn) . "->" . $sourcefile . "<br/>";
  688. */
  689. echo $file . "->" . $sourcefile . "<br/>";
  690. ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
  691. #echo $sourcefile. "<br/>";
  692. }
  693. #}
  694. /*
  695. $pathparts= pathinfo($file);
  696. $filename= $pathparts['basename'];
  697. $dirname= $pathparts['dirname'];
  698. $fullpath= $upload_path . $file;
  699. #echo $dirname . "=>" . $filename . "<br/>";
  700. #$sourcefile= $sourcepath . $file;
  701. $destinationfile= $upload_path . $dirname;
  702. $exists_dir= is_dir('ftp://thsgcrmi:tHsc3900173!@localhost/' . $destinationfile);
  703. if( $exists_dir ){
  704. echo $exists_dir . "->" . $file . "<br/>";
  705. #ftp_chdir($ftp_conn, $destinationfile);
  706. }
  707. */
  708. /*
  709. if( ! @ftp_chdir($ftp_conn, $destinationfile) ){
  710. ftp_mkdir($ftp_conn, $destinationfile);
  711. ftp_chdir($ftp_conn, $destinationfile);
  712. }
  713. */
  714. #ftp_put($ftp_conn, $filename, $sourcefile, FTP_BINARY);
  715. }else{
  716. echo $file . " is FILE EXIST<br/>";
  717. }
  718. }
  719. }
  720. #print_r($files);
  721. }
  722. function gsdataviaftp(){
  723. // Get Data from server via FTP
  724. function ftp_tree($path="", $infopathfl=""){
  725. if( is_array($infopathfl) ){
  726. $infopathfl= $infopathfl[0];
  727. }
  728. $localpath= "C:/customerfile/";
  729. /*
  730. $serverpath= "www/crm_test/assets/restricted";
  731. $ftp_server= "ftp.thsgcrmid.com";
  732. $username= "thsgcrmi";
  733. $pass= "tHsc3900173!";
  734. */
  735. if( is_array($path) ){
  736. foreach( $path as $spec_path ){
  737. #echo $spec_path . "<br/>";
  738. /*
  739. $serverpath= $spec_path;
  740. $ftp_server= "ftp.thsgcrmid.com";
  741. $username= "thsgcrmi";
  742. $pass= "tHsc3900173!";
  743. */
  744. $serverpath= $spec_path;
  745. $ftp_server= "localhost";
  746. $username= "root";
  747. $pass= "root";
  748. $ftp_conn= ftp_connect($ftp_server);
  749. if( ftp_login($ftp_conn, $username, $pass) ){
  750. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  751. #print_r($dir_tree);
  752. #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
  753. $allDirectory= array();
  754. foreach( $dir_tree as $value ){
  755. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  756. #$value= "employee";
  757. $path_gro= pathinfo($value);
  758. $filename= $path_gro['basename'];
  759. $dirname= $path_gro['dirname'];
  760. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  761. if( empty($extensi) ){
  762. $getdir= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
  763. #echo $getdir . "<br/>";
  764. $allDirectory[]= $getdir;
  765. }else{
  766. $filelink= ( $dirname != "." ) ? $value : $spec_path . "/" . $value;
  767. $relfile= str_replace($infopathfl, "", $filelink);
  768. $localfile= $localpath . $relfile;
  769. $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
  770. $serverfile= $filelink;
  771. #echo $serverfile . "<br/>";
  772. #echo $infopathfl . "->" . $relfile . "<br/>";
  773. #echo $localdir . "->" . $serverfile . "<br/>";
  774. #echo $relfile . "<br/>";
  775. $files[]= $value;
  776. if( ! file_exists($localdir) ){
  777. mkdir($localdir);
  778. }
  779. #ftp_chdir($ftp_conn, $destinationfile);
  780. if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
  781. #echo $relfile . "<br/>";
  782. #$files[]= $value;
  783. }
  784. }
  785. }
  786. }
  787. #print_r($allDirectory);
  788. if( count($allDirectory) ){
  789. ftp_tree($allDirectory, $infopathfl);
  790. #$tree= ftp_tree($allDirectory, $infopathfl);
  791. #$files= array_merge($files, $tree);
  792. }
  793. }
  794. }
  795. }
  796. if( !isset($files) ){
  797. $files= "";
  798. }
  799. return $files;
  800. }
  801. $path= array("crm/assets/restricted");
  802. #$path= array("www/crm_test/assets/restricted");
  803. $FTP_file= ftp_tree($path, $path);
  804. /*
  805. $serverpath= "crm/assets/restricted";
  806. $ftp_server= "ftp.thsgcrmid.com";
  807. $username= "thsgcrmi";
  808. $pass= "tHsc3900173!";
  809. $ftp_conn= ftp_connect($ftp_server);
  810. if( ftp_login($ftp_conn, $username, $pass) ){
  811. echo "connect";
  812. }else{
  813. echo "no connect";
  814. }
  815. exit;
  816. */
  817. }
  818. function ftpme(){
  819. function ftp_tree($path="", $infopathfl=""){
  820. if( is_array($infopathfl) ){
  821. $infopathfl= $infopathfl[0];
  822. }
  823. $localpath= "C:/customerfile/";
  824. /*
  825. $serverpath= "www/crm_test/assets/restricted";
  826. $ftp_server= "ftp.thsgcrmid.com";
  827. $username= "thsgcrmi";
  828. $pass= "tHsc3900173!";
  829. */
  830. if( is_array($path) ){
  831. foreach( $path as $spec_path ){
  832. #echo $spec_path . "<br/>";
  833. /*
  834. $serverpath= $spec_path;
  835. $ftp_server= "ftp.thsgcrmid.com";
  836. $username= "thsgcrmi";
  837. $pass= "tHsc3900173!";
  838. */
  839. $serverpath= $spec_path;
  840. #echo $serverpath . "<br/>";
  841. $ftp_server= "localhost";
  842. $username= "root";
  843. $pass= "root";
  844. $ftp_conn= ftp_connect($ftp_server);
  845. if( ftp_login($ftp_conn, $username, $pass) ){
  846. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  847. #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
  848. $allDirectory= array();
  849. foreach( $dir_tree as $value ){
  850. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  851. $path_gro= pathinfo($value);
  852. $filename= $path_gro['basename'];
  853. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  854. if( empty($extensi) ){
  855. $allDirectory[]= $value;
  856. }else{
  857. #$filelink= $spec_path . "/" . $value;
  858. $relfile= str_replace($infopathfl, "", $value);
  859. $localfile= $localpath . $relfile;
  860. $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
  861. $serverfile= $value;
  862. #$serverfile= $spec_path . "/" . $value;
  863. #echo $infopathfl . "<br/>";
  864. #echo $infopathfl . "->" . $relfile . "<br/>";
  865. #echo $localdir . "->" . $serverfile . "<br/>";
  866. #echo $relfile . "<br/>";
  867. $files[]= $value;
  868. if( ! file_exists($localdir) ){
  869. mkdir($localdir);
  870. }
  871. #ftp_chdir($ftp_conn, $destinationfile);
  872. if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
  873. echo $serverfile . "<br/>";
  874. #$files[]= $value;
  875. }
  876. }
  877. }
  878. }
  879. #print_r($allDirectory);
  880. if( count($allDirectory) ){
  881. ftp_tree($allDirectory, $infopathfl);
  882. #$tree= ftp_tree($allDirectory, $infopathfl);
  883. #$files= array_merge($files, $tree);
  884. }
  885. }
  886. }
  887. }
  888. if( !isset($files) ){
  889. $files= "";
  890. }
  891. return $files;
  892. }
  893. $path= array("crm/assets/restricted");
  894. #$path= array("www/crm_test/assets/restricted");
  895. $FTP_file= ftp_tree($path, $path);
  896. /*
  897. $serverpath= "www/crm_test/assets/restricted";
  898. $ftp_server= "ftp.thsgcrmid.com";
  899. $username= "thsgcrmi";
  900. $pass= "tHsc3900173!";
  901. */
  902. /*
  903. $serverpath= "crm/assets/restricted";
  904. $ftp_server= "localhost";
  905. $username= "root";
  906. $pass= "root";
  907. $ftp_conn= ftp_connect($ftp_server);
  908. if( ftp_login($ftp_conn, $username, $pass) ){
  909. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  910. foreach( $dir_tree as $value ){
  911. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  912. echo $value . "<br/>";
  913. #print_r($dir_tree);
  914. }
  915. }
  916. }
  917. */
  918. #print_r($FTP_file);
  919. }
  920. function index(){
  921. function ftp_tree($path="", $infopathfl=""){
  922. $localpath= "C:/customerfile/";
  923. /*
  924. $serverpath= "www/crm_test/assets/restricted";
  925. $ftp_server= "ftp.thsgcrmid.com";
  926. $username= "thsgcrmi";
  927. $pass= "tHsc3900173!";
  928. */
  929. if( is_array($path) ){
  930. foreach( $path as $spec_path ){
  931. #echo $spec_path . "<br/>";
  932. $serverpath= $spec_path;
  933. $ftp_server= "ftp.thsgcrmid.com";
  934. $username= "thsgcrmi";
  935. $pass= "tHsc3900173!";
  936. /*
  937. $serverpath= $value;
  938. $ftp_server= "localhost";
  939. $username= "root";
  940. $pass= "root";
  941. */
  942. $ftp_conn= ftp_connect($ftp_server);
  943. if( ftp_login($ftp_conn, $username, $pass) ){
  944. $dir_tree= ftp_nlist($ftp_conn, $serverpath); // Get All data from directory
  945. #$dir_tree= ftp_rawlist($ftp_conn, $serverpath); // Get All data from directory
  946. $allDirectory= array();
  947. foreach( $dir_tree as $value ){
  948. if( ! preg_match("#^(.+\/\.svn|[ |\.][.+]?)$#", $value) ){ // Cek folder yang tidak termasuk
  949. #echo $value . "<br/>";
  950. $path_gro= pathinfo($value);
  951. $filename= $path_gro['basename'];
  952. $extensi= ( ! isset($path_gro['extension']) ) ? "" : $path_gro['extension'];
  953. if( empty($extensi) ){
  954. $allDirectory[]= $spec_path . "/" . $value;
  955. }else{
  956. $relfile= str_replace($infopathfl, "", $value);
  957. $localfile= $localpath . $relfile;
  958. $localdir= pathinfo($localfile, PATHINFO_DIRNAME);
  959. $serverfile= $spec_path . "/" . $value;
  960. #echo $localfile . "->" . $serverfile . "<br/>";
  961. #echo $relfile . "<br/>";
  962. $files[]= $value;
  963. if( ! file_exists($localdir) ){
  964. mkdir($localdir);
  965. }
  966. #ftp_chdir($ftp_conn, $destinationfile);
  967. if( ftp_get($ftp_conn, $localfile, $serverfile, FTP_BINARY) ){ // Download file FTP
  968. echo $relfile . "<br/>";
  969. #$files[]= $value;
  970. }
  971. }
  972. }
  973. }
  974. #print_r($allDirectory);
  975. if( count($allDirectory) ){
  976. ftp_tree($allDirectory, $infopathfl);
  977. #$tree= ftp_tree($allDirectory, $infopathfl);
  978. #$files= array_merge($files, $tree);
  979. }
  980. }
  981. }
  982. }
  983. if( !isset($files) ){
  984. $files= "";
  985. }
  986. return $files;
  987. }
  988. #$path= array("crm/assets/restricted");
  989. $path= array("www/crm_test/assets/restricted");
  990. $FTP_file= ftp_tree($path, $path);
  991. function ftp_all($addpath=""){
  992. $localpath= "C:/customerfile/";
  993. /*
  994. $serverpath= "www/crm_test/assets/restricted";
  995. $ftp_server= "ftp.thsgcrmid.com";
  996. $username= "thsgcrmi";
  997. $pass= "tHsc3900173!";
  998. */
  999. $serverpath= "crm/assets/restricted";
  1000. $ftp_server= "localhost";
  1001. $username= "root";
  1002. $pass= "root";
  1003. $ftp_conn= ftp_connect($ftp_server);
  1004. if( ftp_login($ftp_conn, $username, $pass) ){
  1005. #echo "Connect" . "<br/>";
  1006. $dir_tree= ftp_rawlist($ftp_conn, $serverpath, TRUE);
  1007. #$dir_tree= ftp_nlist($ftp_conn, $serverpath);
  1008. #print_r($groupdt);
  1009. $allDirectory[]= $serverpath;
  1010. foreach( $dir_tree as $value ){
  1011. if( preg_match("#^.+:$#", $value) ){
  1012. #echo $value . "<br/>";
  1013. $dirname= substr($value, 0, -1);
  1014. $allDirectory[]= $dirname;
  1015. }
  1016. echo $value . "<br/>";
  1017. }
  1018. }
  1019. #print_r($dir_tree);
  1020. exit;
  1021. /*
  1022. foreach( $allDirectory as $dirname ){
  1023. $ftp_conn= ftp_connect($ftp_server);
  1024. if( ftp_login($ftp_conn, $username, $pass) ){
  1025. $dir_tree= ftp_nlist($ftp_conn, $dirname);
  1026. ftp_chdir($ftp_conn, $dirname);
  1027. $current_dir= ftp_pwd($ftp_conn);
  1028. echo $current_dir . "<br/>";
  1029. echo "===================================" . "<br/>";
  1030. #print_r($dir_tree);
  1031. foreach( $dir_tree as $value ){
  1032. if( ! preg_match("#^[ |\.][.+]?$#", $value) ){
  1033. $extensi= pathinfo($value, PATHINFO_EXTENSION);
  1034. if( ! empty($extensi) ){
  1035. $additional_path= str_replace($serverpath, "", $dirname);
  1036. echo $additional_path . "<br/>";
  1037. $nowpath= $localpath . $additional_path;
  1038. if( ! file_exists($nowpath) ){
  1039. mkdir($nowpath);
  1040. }
  1041. ftp_get($ftp_conn, $nowpath, $value, FTP_BINARY);
  1042. #echo $value . "<br/>";
  1043. }
  1044. }
  1045. }
  1046. }else{
  1047. echo "Don't Connect";
  1048. }
  1049. }
  1050. */
  1051. }
  1052. ftp_tree();
  1053. }
  1054. }
  1055. ?>