Index: /pro-violet-viettel/docs/db/tblcollaborator.sql
===================================================================
--- /pro-violet-viettel/docs/db/tblcollaborator.sql	(revision 688)
+++ /pro-violet-viettel/docs/db/tblcollaborator.sql	(revision 688)
@@ -0,0 +1,62 @@
+-- phpMyAdmin SQL Dump
+-- version 4.1.14
+-- http://www.phpmyadmin.net
+--
+-- Host: 127.0.0.1
+-- Generation Time: Jan 06, 2015 at 05:51 AM
+-- Server version: 5.6.17
+-- PHP Version: 5.5.12
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8 */;
+
+--
+-- Database: `violet-viettel`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `tblcollaborator`
+--
+
+CREATE TABLE IF NOT EXISTS `tblcollaborator` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `full_name` varchar(45) NOT NULL,
+  `login_name` varchar(45) NOT NULL,
+  `cellphone` varchar(15) NOT NULL,
+  `passwd` varchar(65) NOT NULL,
+  `activated` tinyint(4) NOT NULL DEFAULT '1',
+  `created_time` datetime DEFAULT NULL,
+  `updated_time` datetime DEFAULT NULL,
+  `author` int(11) DEFAULT NULL,
+  `address` varchar(255) NOT NULL,
+  `code` varchar(255) NOT NULL,
+  `district` varchar(15) NOT NULL,
+  `email` varchar(255) NOT NULL,
+  `precinct` varchar(15) NOT NULL,
+  `province` varchar(15) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=20536706 ;
+
+--
+-- Dumping data for table `tblcollaborator`
+--
+
+INSERT INTO `tblcollaborator` (`id`, `full_name`, `login_name`, `cellphone`, `passwd`, `activated`, `created_time`, `updated_time`, `author`, `address`, `code`, `district`, `email`, `precinct`, `province`) VALUES
+(1, 'Truong Hoang Anh', '0982124899', '0982124899', '', 1, NULL, NULL, NULL, '', '', '', '', '', ''),
+(2, 'Namta', '01689925260', '01689925260', 'c4ca4238a0b923820dcc509a6f75849b', 1, '2014-11-19 10:21:15', '2014-11-19 10:21:15', NULL, '', '', '', '', '', ''),
+(5, 'dungnv', '0988568786', '0988568786', 'c4ca4238a0b923820dcc509a6f75849b', 1, '2014-11-19 18:45:27', '2014-11-19 18:45:27', NULL, '', '', '', '', '', ''),
+(20513478, 'V? Th? Luy?n', '', '', '', 1, NULL, '2015-01-06 11:49:31', NULL, 'S? nhï¿œ null ???ng Null Khu?i Thu?m Huy?n T?ng B?c K?n B?c K?n', '1000004001_00001_CTVTMDT', '001', '', '004', 'B281'),
+(20519414, 'Hoï¿œng Cï¿œng Minh', '', '0983532981', '', 1, NULL, '2015-01-06 11:49:32', NULL, 'S? nhï¿œ 186 ???ng Nguy?n Th? Minh Khai T? 8 Nguy?n Th? Minh Khai B?c K?n B?c K?n', '1000004001_00003_CTVTMDT', '001', '', '004', 'B281'),
+(20536705, 'Chu ?ï¿œnh Anh', '', '962143096', '', 1, NULL, '2015-01-06 11:49:32', NULL, 'S? nhï¿œ 01 ???ng 01  ??c Xuï¿œn B?c K?n B?c K?n', '1000004001_00002_GPKHDN', '001', '', '004', 'B281');
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Index: /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php	(revision 687)
+++ /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php	(revision 688)
@@ -214,5 +214,5 @@
 	public function collaborator () 
 	{
-/* 		error_reporting(E_ALL);
+ 		error_reporting(E_ALL);
 		$this->load->model('Services_model');
 		
@@ -220,40 +220,83 @@
 		
 		$result = $this->Services_model->getCollaborator(2,1,1);
-		$this->xml->parse($result);
-		$xml = $this->xml;
-		var_dump($xml); */
-		
-		$xml = '<?xml version="1.0" ?>
-				<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
-					<S:Body>
-						<ns2:getListShopAndStaftInfoResponse xmlns:ns2="http://process.wsim.viettel.com/">
-							<return>
-								<description>Thï¿œnh cï¿œng</description>
-								<responseCode>0</responseCode>
-								<lst>
-									<address>S? nhï¿œ null ???ng Null Khu?i Thu?m Huy?n T?ng B?c K?n B?c K?n</address>
-									<code>1000004001_00001_CTVTMDT</code>
-									<district>001</district>
-									<email></email>
-									<id>20513478</id>
-									<name>V? Th? Luy?n</name>
-									<phone></phone>
-									<precinct>004</precinct>
-									<province>B281</province>
-								</lst>
-								<page>1</page>
-								<totalpage>102123</totalpage>
-							</return>
-						</ns2:getListShopAndStaftInfoResponse>
-					</S:Body>
-				</S:Envelope>';
-		
-		$xml = simplexml_load_string($xml);
-		$xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
-		$xml = $xml->xpath('//S:Body')[0];
-		$xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
-		$lst = (array)$xml->xpath('//return//lst')[0];
-		$totalpage = (int)$xml->xpath('//return//totalpage')[0];
-		echo json_encode(array('lst'=>$lst, 'totalpage'=>$totalpage));
+		if ($result){
+			//$this->xml->parse($result);
+			//$xml = $this->xml;
+			//var_dump($xml);
+			/*
+			$xml = '<?xml version="1.0" ?>
+					<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+						<S:Body>
+							<ns2:getListShopAndStaftInfoResponse xmlns:ns2="http://process.wsim.viettel.com/">
+								<return>
+									<description>Thï¿œnh cï¿œng</description>
+									<responseCode>0</responseCode>
+									<lst>
+										<address>S? nhï¿œ null ???ng Null Khu?i Thu?m Huy?n T?ng B?c K?n B?c K?n</address>
+										<code>1000004001_00001_CTVTMDT</code>
+										<district>001</district>
+										<email></email>
+										<id>20513478</id>
+										<name>V? Th? Luy?n</name>
+										<phone></phone>
+										<precinct>004</precinct>
+										<province>B281</province>
+									</lst>
+									<lst>
+										<address>S? nhï¿œ 01 ???ng 01  ??c Xuï¿œn B?c K?n B?c K?n</address>
+										<code>1000004001_00002_GPKHDN</code>
+										<district>001</district>
+										<email></email>
+										<id>20536705</id>
+										<name>Chu ?ï¿œnh Anh</name>
+										<phone>962143096</phone>
+										<precinct>004</precinct>
+										<province>B281</province>
+									</lst>
+									<lst>
+										<address>S? nhï¿œ 186 ???ng Nguy?n Th? Minh Khai T? 8 Nguy?n Th? Minh Khai B?c K?n B?c K?n</address>
+										<code>1000004001_00003_CTVTMDT</code>
+										<district>001</district>
+										<email></email>
+										<id>20519414</id>
+										<name>Hoï¿œng Cï¿œng Minh</name>
+										<phone>0983532981</phone>
+										<precinct>004</precinct>
+										<province>B281</province>
+									</lst>
+									<page>1</page>
+									<totalpage>102123</totalpage>
+								</return>
+							</ns2:getListShopAndStaftInfoResponse>
+						</S:Body>
+					</S:Envelope>';
+			*/
+			$xml = $result['result']['original'];
+			$xml = simplexml_load_string($xml);
+			$xml->registerXPathNamespace("S", "http://schemas.xmlsoap.org/soap/envelope/");
+			$xml = $xml->xpath('//S:Body')[0];
+			$xml->registerXPathNamespace("ns2", "http://process.wsim.viettel.com/");
+			$lst = $xml->xpath('//return//lst');
+			foreach($lst as $item){
+				$item = (array)$item;
+				$data = array(
+						'address'=> (string)$item['address'],
+						'code'=>(string)$item['code'],
+						'district'=>(string)$item['district'],
+						'email'=>(string)$item['email'],
+						'id'=>(int)$item['id'],
+						'full_name'=>(string)$item['name'],
+						'cellphone'=>(string)$item['phone'],
+						'precinct'=>(string)$item['precinct'],
+						'province'=>(string)$item['province'],
+						'updated_time'=>date('Y-m-d H:i:s')
+					);
+				$this->Services_model->syncCollaborator($data);
+			}
+			$totalpage = (int)$xml->xpath('//return//totalpage')[0];
+			//var_dump($totalpage);
+		}else{
+			var_dump($result);
+		}
 	}
 }
Index: /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 687)
+++ /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 688)
@@ -420,3 +420,27 @@
 		return $result;
 	}
+	
+	
+	public function syncCollaborator($data){
+		if ($data){
+			$sql = $this->db->insert_string('tblcollaborator', $data) . ' ON DUPLICATE KEY UPDATE address = "'.$data['address'].'", 
+																								code = "'.$data['code'].'", 
+																								district = "'.$data['district'].'", 
+																								email = "'.$data['email'].'", 
+																								full_name = "'.$data['full_name'].'", 
+																								cellphone = "'.$data['cellphone'].'", 
+																								precinct = "'.$data['precinct'].'", 
+																								province = "'.$data['province'].'",
+																								updated_time = "'.$data['updated_time'].'"';
+			$this->db->query($sql);
+			$id = $this->db->insert_id();
+			if ($this->db->affected_rows()){
+				echo "Collaborator ID: ".$id.". Sync Success !<br/>";
+			}else{
+				echo "Collaborator ID: ".$id.". Sync fail!. Sql = ".$sql."<br/>";
+			}
+		}else {
+			var_dump($data);
+		}
+	}
 }
