load->model('AdminModel', 'madmin', true);
}
public function index() {
$data['title'] = 'List Repository';
$data['repos'] = $this->madmin->getAllRepo();
$data['script'] = 'datatables';
$this->load->template('repos', $data);
}
public function insert() {
$getDraft = $this->madmin->getLastDraft();
$repo_id = !empty($getDraft->repo_id) ? $getDraft->repo_id : $this->madmin->insertDraft();
redirect('admin/draft/' . $repo_id);
}
public function draft($id) {
$data['title'] = 'Repository';
$data['repo_id'] = $id;
$data['types'] = $this->madmin->getAllType();
$data['subjects'] = $this->madmin->getAllSubject();
$this->load->template('repo_admin', $data);
}
public function update($id) {
$data['title'] = 'Repository';
$data['repo_id'] = $id;
$data['types'] = $this->madmin->getAllType();
$data['subjects'] = $this->madmin->getAllSubject();
$data['repo'] = $this->madmin->getRepo($id);
$data['files'] = $this->madmin->getFiles($id);
$this->load->template('repo_admin', $data);
}
public function save($repo_id) {
$data = $this->input->post();
$data['user_id'] = 1;
$this->madmin->updateRepo($data, $repo_id);
redirect('admin/index');
}
public function delete($repo_id) {
$this->madmin->delete($repo_id);
redirect('admin/index/');
}
public function delete_file($file_id, $repo_id) {
$this->madmin->deleteFile($file_id);
redirect('admin/update/' . $repo_id);
}
public function batch_new() {
$handle = fopen(FCPATH . 'assets/text/repofh.txt', 'r');
if ($handle) {
while (($line = fgets($handle)) !== false) {
$directory = FCPATH . 'assets/judul';
$dir = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
$line_text = explode(',', $line);
// $line_number_text = explode("#", $line);
$line_number_text = explode(',', $line);
// print_r($line_number_text);exit;
$i =1;
foreach ($dir as $fileinfo) {
// echo getFileName($line).'
';
$indir = new RecursiveDirectoryIterator($directory . '/' . $fileinfo->getFilename(), RecursiveDirectoryIterator::SKIP_DOTS);
$repo_folder = clear_numbers($fileinfo->getFilename());
// print_r($repo_folder);exit;
if ($line_number_text[0] == $repo_folder) {
$subject_id = $this->madmin->getSubject($line_text[3]);
echo 'line number' . $line_number_text[0] . ' repo_folder name' . $repo_folder . ' judul ' . $repo_folder . 'subject '. $line_text[3].'subject_id' . $subject_id->subject_id.'
';
// print_r($line_text[1]);exit;
$data['author'] = $repo_folder;
$data['title'] = $line_text[2];
$data['subject_id'] = $subject_id->subject_id;
$data['type_id'] = 9;
$data['user_id'] = 1;
$data['date'] = $line_text[1]. '-01-01';
print_r($data);
$repo_id = $this->madmin->insertRepo($data);
echo '
';
// echo "- ini repo nya". $repo_folder[0]. $repo_folder[1].'
';
echo '- betul' . $line_text[2] . '
';
foreach ($indir as $in) {
// echo "- betul". $fileinfo->getFilename() . '
';
$url = str_replace(' ', '%20', base_url() . 'assets/judul/' . $fileinfo->getFilename() . '/' . $in->getFilename());
$suff = '_' . uniqeID();
$filename = str_replace('%20', ' ', substr($url, strrpos($url, '/') + 1));
$ext = getFileExt($filename);
$newname = getFileName($filename) . $suff . $ext;
$files = ['filename' => $newname, 'full_path' => filePath(), 'original_name' => $filename, 'file_ext' => $ext, 'repo_id' => $repo_id];
print_r($files);
$this->madmin->insertFile($files);
copy($url, FCPATH . 'assets/files/' . filePath() . $newname);
echo '- ' . $url . '
';
}
echo '
';
}
}
$i++;
// process the line read.
}
fclose($handle);
} else {
ini_set('display_errors', 1);
error_reporting(E_ALL);
print_r($handle);
// error opening the file.
}
}
public function batch_text_new() {
$handle = fopen(FCPATH . 'assets/text/repofh.txt', 'r');
if ($handle) {
$i = 0;
while (($line = fgets($handle)) !== false) {
$line_text = explode(",", $line);
$subject_id = $this->madmin->getSubject($line_text[3]);
foreach ($line_text as $l) {
echo $l . "
";
}
}
}
}
public function batch_text() {
$handle = fopen(FCPATH . 'assets/text/repofh.txt', 'r');
if ($handle) {
$i = 1;
while (($line = fgets($handle)) !== false) {
// echo $i. ' judul '. $line. '
';
$line_text = explode(",", $line);
// print_r($line_text);
// echo $i. $line_text[3] . '
';
$subject_id = $this->madmin->getSubject($line_text[3]);
echo $i. ' judul ' . $subject_id->subject_id;
// print_r($subject_id);
// switch ($line_text[3]) {
// case "SKRIPSI":
// echo 1;
// break;
// case "STUDI KASUS":
// echo 11;
// break;
// case "LEGAL MEMORANDUM":
// echo 12;
// break;
// default:
// echo 1;
// break;
// }
$i++;
// echo $line . '
';
// echo $subject_id . '
';
}
}
}
public function batch_old_() {
$directory = FCPATH . 'assets/files';
$dir = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
foreach ($dir as $fileinfo) {
$indir = new RecursiveDirectoryIterator($directory . '/' . $fileinfo->getFilename(), RecursiveDirectoryIterator::SKIP_DOTS);
$repo_folder = explode(',', $fileinfo->getFilename());
$data['author'] = $repo_folder[0];
$data['title'] = $repo_folder[2];
$data['subject_id'] = 1;
$data['type_id'] = 1;
$data['user_id'] = 1;
$data['date'] = '2019-10-10';
// $repo_id = $this->madmin->insertRepo($data);
echo '';
echo '- ' . $fileinfo->getFilename() . '
';
foreach ($indir as $in) {
$url = str_replace(' ', '%20', base_url() . 'assets/judul/' . $fileinfo->getFilename() . '/' . $in->getFilename());
$suff = '_' . uniqeID();
$filename = str_replace('%20', ' ', substr($url, strrpos($url, '/') + 1));
$ext = getFileExt($filename);
$newname = getFileName($filename) . $suff . $ext;
// $files = ['filename' => $newname, 'full_path' => filePath(), 'original_name' => $filename, 'file_ext' => $ext, 'repo_id' => $repo_id];
// $this->madmin->insertFile($files);
// copy( $url, FCPATH.'/assets/files/'. filePath() . $newname);
echo '- ' . $url . '
';
}
echo '
';
}
}
public function copyf() {
$url = 'http://repo.test/assets/judul/ARYA ANDRIAN NUGROHO, PENGAWASAN MESIN PARKIR OTOMATIS/10. BAB I.docx';
$suff = '_' . uniqeID();
$filename = substr($url, strrpos($url, '/') + 1);
$ext = getFileExt($filename);
copy($url, FCPATH . '/assets/test/' . getFileName($filename) . $suff . $ext);
}
public function upload($id) {
$config['upload_path'] = fileFullPath();
$config['allowed_types'] = '*';
$config['max_size'] = 100000;
$config['max_width'] = 9024;
$config['max_height'] = 9000;
$config['file_name'] = getFileName($_FILES['files']['name']) . '_' . uniqeID();
// $config['url'] = 'testing';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('files')) {
$error = ['error' => $this->upload->display_errors()];
echo fileFullPath();
print_r($error);
print_r($this->input->post());
} else {
$data['post_id'] = $id;
$data = ['upload_data' => $this->upload->data()];
$data_ori = [
'repo_id' => $id,
'full_path' => filePath(),
'filename' => $data['upload_data']['file_name'],
'original_name' => $data['upload_data']['client_name'],
'file_ext' => $data['upload_data']['file_ext'],
'file_size' => $data['upload_data']['file_size'],
'file_type' => $data['upload_data']['file_type'],
];
// check if tb img feature not exits post id
$this->madmin->insertFile($data_ori);
$data['success'] = true;
$data['status'] = 200;
// print_r($data);
echo json_encode($data);
// return $data;
}
}
}