Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library excell reader untuk broadcast sms dan phonebook #139

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions application/controllers/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,34 @@ function compose_process()
// Import value from file (currently only CSV)
if (isset($_FILES["import_file"]))
{
$this->load->library('csvreader');
$filePath = $_FILES["import_file"]["tmp_name"];
$csvData = $this->csvreader->parse_file($filePath, true);
// $this->load->library('csvreader');
// $filePath = $_FILES["import_file"]["tmp_name"];
// $csvData = $this->csvreader->parse_file($filePath, true);
// Load the spreadsheet reader library
$this->load->library('excel_reader');
//File name
$file = $_FILES["import_file"]["tmp_name"];
//Read data
$this->excel_reader->read($file);
//setting report error
error_reporting(E_ALL ^ E_NOTICE);
// Sheet 1
$data = $this->excel_reader->sheets[0] ;
//baca header
$header=array();
for ($i = 1; $i <= $data['numCols']; $i++) {
$header[$i]=$data['cells'][1][$i];
}
//simpan dalam array
$csvData = array();
for ($i = 2; $i <= $data['numRows']; $i++) {
$isi=array();
for ($j = 1; $j <= $data['numCols']; $j++) {
$isi[$header[$j]] = $data['cells'][$i][$j];
}
$csvData[]=$isi;
}

$csvField = array_keys($csvData[0]);
foreach($csvData as $data)
{
Expand Down
26 changes: 22 additions & 4 deletions application/controllers/phonebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,27 @@ function update_contact_group()
*/
function import_phonebook()
{
$this->load->library('csvreader');
$filePath = $_FILES["csvfile"]["tmp_name"];
$csvData = $this->csvreader->parse_file($filePath, true);
// $this->load->library('csvreader');
// $filePath = $_FILES["csvfile"]["tmp_name"];
// $csvData = $this->csvreader->parse_file($filePath, true);

$this->load->library('excel_reader');
$file = $_FILES["csvfile"]["tmp_name"];
$this->excel_reader->read($file);
error_reporting(E_ALL ^ E_NOTICE);
$data = $this->excel_reader->sheets[0] ;
$header=array();
for ($i = 1; $i <= $data['numCols']; $i++) {
$header[$i]=$data['cells'][1][$i];
}
$csvData = array();
for ($i = 2; $i <= $data['numRows']; $i++) {
$isi=array();
for ($j = 1; $j <= $data['numCols']; $j++) {
$isi[$header[$j]] = $data['cells'][$i][$j];
}
$csvData[]=$isi;
}

$n=0;
foreach($csvData as $field):
Expand Down Expand Up @@ -413,4 +431,4 @@ function get_phonebook($type = NULL)
}

/* End of file phonebook.php */
/* Location: ./application/controllers/phonebook.php */
/* Location: ./application/controllers/phonebook.php */
Loading