/application/controllers/project.php
PHP | 2589 lines | 1635 code | 249 blank | 705 comment | 177 complexity | 6eda6d3735eae286632370966388d743 MD5 | raw file
Possible License(s): CC-BY-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Project extends CI_Controller {
-
- function __construct(){
- parent::__construct();
- $this->load->database();
- $this->load->helper(array('url', 'captcha', 'download'));
- $this->load->library(array('form_validation', 'Themelib', 'Captchalib', 'pagination'));
- checkAuth(); // Check Authentikasi User
- }
-
- function testpage(){
- $config= $this->config;
- $data= array();
- $data['title']= "Testing Page";
- $data['jscript']= "";
-
- /*$this->load->view('test', $data);*/
- $this->themelib->getpage("test", $data, "inc/theme_main");
- }
- public function server_var(){
- /*echo urlencode("~!@#$%^&*()_+-:");*/
- echo urlencode("Aplikasi CMS | CMS");
- /* foreach( $_SERVER as $key=>$value ){
- echo $key . "->" . $value . "<br/>";
- }*/
- /* echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "<br/>";
- echo site_url();*/
- }
-
- function newpage(){
- echo "abc";
- }
-
- // Setting PO ID format
- public function setting_po_id($process=""){
- if( empty($process) ){
- $config= $this->config;
- $data= array();
- $data['poid']= $this->db->limit('1')->get('poid_format')->row_array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view('js/po_id', $data, true);
- $this->themelib->getpage("project/po_id", $data, "inc/theme_main");
- }else{
- $POST= $this->input->post();
-
- // Set Rules Validasi
- $config= array(
- array(
- 'field'=> 'Prefix',
- 'label'=> 'Prefix',
- 'rules'=> 'required'
- ),
- array(
- 'field'=> 'Digit',
- 'label'=> 'Digit Number',
- 'rules'=> 'required|integer'
- )
- );
- $this->form_validation->set_rules($config);
-
- if( $this->form_validation->run() == TRUE ){ // Cek Validasi
- if( isset($POST['submit']) || $POST['type'] == "ajax" ){
- extract($POST);
-
- // Get PO_ID Format
- $poid_format= $this->db->get_where('poid_format')->row_array();
-
- // Remove Data pada Tabel poid_format
- $this->db->truncate('poid_format');
-
- // Insert Data
- unset($POST['submit'], $POST['type']);
- if( $this->Jmodel->insert('poid_format', $POST) ){
- // Get PO_ID Data
- $poid_dt= $this->db->get('po_id')->result_array();
- foreach( $poid_dt as $key=>$value ){
- $jml= strlen($poid_format['Prefix']);
- $poid_val= substr($value['PO_ID'], $jml);
- $poid_val= $POST['Prefix'] . sprintf('%0' . $POST['Digit'] . 's', $poid_val+1);
- /*echo $poid_val . "<br/>";*/
-
- // Update PO_ID
- $update_poid= array('PO_ID'=>$poid_val);
- $where= array('Project_ID'=>$value['Project_ID']);
- $this->Jmodel->update('po_id', $update_poid, $where);
- }
- /*exit;*/
- $feedback= array('type'=>'success', 'response'=>'PO ID has been set.');
- $feedback= json_encode($feedback);
- if( $type == "ajax" ){
- echo $feedback;
- exit;
- }else{
- $this->session->set_userdata('feedback', $feedback);
- redirect("project/setting_po_id");
- }
- }
- }
- }else{
- $config= $this->config;
- $data= array();
- $data['poid']= $this->db->limit('1')->get('poid_format')->row_array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view('js/po_id', $data, true);
- $this->themelib->getpage("project/po_id", $data, "inc/theme_main");
- }
- }
- }
-
- // MD5 Function
- public function md5(){
- echo md5("sales");
- exit;
- echo 'administrator' . date("Y-m-d H:i:s") . "->" . md5('administrator' . date("Y-m-d H:i:s")) . "<br/>";
- echo 'administrator2' . date("Y-m-d H:i:s") . "->" . md5('administrator2' . date("Y-m-d H:i:s"));
- }
- // Struktur Organisasi
- public function structure($process=""){
- $config= $this->config;
- $js_path= $config->item('js_path');
-
- // Create Structure List Using jwMenu Class
- $data= $this->db->get('structure')->result_array();
- $this->jwmenu->baseUrl= base_url();
- $this->jwmenu->setStyle("org", "");
- $this->jwmenu->setClassLink("structure-link");
- /*$this->jwmenu->setIcon();*/
- $structure= $this->jwmenu->create_tree($data);
-
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= '';
- $data['css_files']= array($js_path . "/jOrgChart/css/jquery.jOrgChart.css");
- $data['js_files']= array($js_path . "/jOrgChart/js/jquery.jOrgChart.js");
- $data['structure']= $structure;
- $this->themelib->getpage("structure", $data, "inc/theme_main");
- }
-
- // Change Password User
- public function change_password($process=""){
- if( $process == "process" ){
- $POST= $this->input->post();
- /* echo "<pre>";
- print_r($POST);
- echo "</pre>";*/
-
- // Set Rules Validasi
- $config= array(
- array(
- 'field'=> 'OldPassword',
- 'label'=> 'Old Password',
- 'rules'=> 'required'
- ),
- array(
- 'field'=> 'NewPassword',
- 'label'=> 'New Password',
- 'rules'=> 'required'
- ),
- array(
- 'field'=> 'PasswordConf',
- 'label'=> 'Password Confirmation',
- 'rules'=> 'required'
- )
- );
- $this->form_validation->set_rules($config);
-
- if( $this->form_validation->run() == TRUE ){ // Cek Validasi
- if( isset($POST['submit']) || $POST['type'] == "ajax" ){
- extract($POST);
-
- // Cek Old Password sesuai
- $Username= $this->session->userdata('Username');
- $where= array('Password'=>md5($OldPassword), 'Username'=>$Username);
- $jml= $this->db->get_where('user', $where)->num_rows();
- /* echo $this->db->last_query();
- exit;*/
- if( ! $jml ){
- $feedback= array('type'=>'error', 'response'=>'Old Password tidak sesuai !');
- $feedback= json_encode($feedback);
- if( $type == "ajax" ){
- echo $feedback;
- exit;
- }else{
- $this->session->set_userdata('feedback', $feedback);
- redirect("change_password");
- }
- }
-
- // Change Password
- $where= array('Username'=>$Username);
- $data= array('Password'=>md5($NewPassword));
- if( $this->Jmodel->update('user', $data, $where) ){
- $feedback= array('type'=>'success', 'response'=>'Password has been changed !');
- $feedback= json_encode($feedback);
- if( $type == "ajax" ){
- echo $feedback;
- exit;
- }else{
- $this->session->set_userdata('feedback', $feedback);
- redirect("change_password");
- }
- }
- }
- }else{
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view('js/change_password', $data, TRUE);
- $this->themelib->getpage("user/change_password", $data, "inc/theme_main");
- }
- }else{
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view('js/change_password', $data, TRUE);
- $this->themelib->getpage("user/change_password", $data, "inc/theme_main");
- }
- }
-
- // Dashboard Page
- public function dashboard(){
- $config= $this->config;
-
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $this->themelib->getpage("", $data, "inc/theme_new");
- }
-
- public function new_menu(){
- $config= $this->config;
-
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- /*$data['menu']= $this->load->view("inc/menu.php", $data, TRUE);*/
- $this->themelib->getpage("testing", $data, "inc/theme_new");
- /*$this->themelib->getpage("testing", $data, "inc/theme_main");*/
- }
-
- // Dashboard Page
- /* public function sticky_test(){
- $config= $this->config;
-
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $this->themelib->getpage("sticky_test", $data, "inc/theme_main");
- }*/
-
- // Notify ToDo ( User Login ) setiap 5 menit
- public function notify_todo(){
- $Username= $this->session->userdata('Username');
- $today= date("Y-m-d H:i:s");
- $cur_date= explode(" ", $today);
- $date= explode("-", $cur_date[0]);;
- $time= explode(":", $cur_date[1]);
-
- list($year, $month, $day)= $date;
- list($hour, $minute, $second)= $time;
- $last_time= date("Y-m-d H:i:s", mktime($hour, $minute-5, 0, $month, $day, $year));
- $now_time= date("Y-m-d H:i:s", mktime($hour, $minute, 0, $month, $day, $year));
-
- $sql= "SELECT * FROM todo
- WHERE DueDate BETWEEN '" . $last_time . "' AND '" . $now_time.
- "' AND Username='" . $Username . "' AND Status != 'yes'";
- $todo= array();
- $todo= $this->db->query($sql)->row_array();
- /* echo "<pre>";
- echo $sql;
- echo "</pre>";
- exit;*/
- if( count($todo) ){
- $notifyId= $todo['Id'];
- $notify_dt= '<p><a href="' . site_url() . 'project/detail/' . $todo['IdProject'] . '">' . $todo['Task'] .
- '</a></p>';
- $notify= array(
- 'Id'=>$notifyId,
- 'Element'=>$notify_dt
- );
- echo json_encode($notify);
- }
- exit;
- }
-
- // Process Untuk Set Status Complete or Not
- public function process_todo(){
- $POST= $this->input->post();
-
- $where= array('Id'=>$POST['Id']);
- unset($POST['Id']);
- if( $this->Jmodel->update('todo', $POST, $where) ){
- echo "success";
- }
- }
-
- // PopUp for Todo pada Halaman Project Detail ( Add, Edit )
- // Serta Processing u/ Delete ToDo
- public function todo($IdProject="", $action="", $IdTodo= ""){
- $config= $this->config;
- if( $action == "edit" ) { // PopUp Edit ToDo
- $where= array('Id'=>$IdTodo);
- $todo= $this->db->get_where('todo', $where)->row_array();
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- $data['IdProject']= $IdProject;
- $data['hrefElement']= site_url() . $this->uri->uri_string();
- $data['todo']= $todo;
- $html= $this->load->view('todo/edit', $data, TRUE);
- echo $html;
- exit;
- }elseif( $action == "delete" ){ // Delete ToDo
- $where= array("Id"=>$IdTodo);
- if( $this->db->delete('todo', $where) ){
- echo "success";
- exit;
- }
- }else{ // PopUp Add ToDo
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- $data['IdProject']= $IdProject;
- $html= $this->load->view('todo/todo', $data, TRUE);
- echo $html;
- exit;
- }
- }
-
- // Display All ToDos dari Login User
- public function todo_list(){
- $Username= $this->session->userdata('Username');
-
- $todos= array();
- $sql= "SELECT a.*, b.Project_Name FROM todo a
- LEFT JOIN project b ON b.Project_ID= a.IdProject
- WHERE a.Username= '" . $Username . "' AND a.Status= 'no'
- ORDER BY a.DueDate DESC";
- $todos= $this->db->query($sql)->result_array();
-
- $today= date("d-m-Y");
- $today= explode("-", $today);
- list($day, $month, $year)= $today;
- $today= mktime(0, 0, 0, $month, $day, $year);
- $tomorrow= mktime(0, 0, 0, $month, $day+1, $year);
-
- // Grouping ToDos ( Late, Today, Upcoming)
- $late_todos= array();
- $today_todos= array();
- $upcoming_todos= array();
- foreach( $todos as $todo ){
- $DueDate= strtotime($todo['DueDate']);
- if( $DueDate < $today ){
- $late_todos[]= $todo;
- }elseif( $DueDate >= $tomorrow ){
- $upcoming_todos[]= $todo;
- }else{
- $today_todos[]= $todo;
- }
- }
- $todos['late']= $late_todos;
- $todos['today']= $today_todos;
- $todos['upcoming']= $upcoming_todos;
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view('js/todo_list', $data, TRUE);
- $data['todos']= $todos;
- $this->themelib->getpage("todo/todo_list", $data, "inc/theme_main");
- }
-
- // Processing Save, Edit and Delete Todo Data Into Database
- public function todo_save($action=""){
- $POST= $this->input->post();
- // Set Data for inserting to DBase
- $POST['Username']= $this->session->userdata('Username');
- $POST['DueDate'].= " " . $POST['Hour'] . ":" . $POST['Minutes'] . " " . $POST['IdTime'];
- $POST['DueDate']= date("Y-m-d H:i:s", strtotime($POST['DueDate']));
- unset($POST['Hour'], $POST['Minutes'], $POST['IdTime'], $POST['submit']);
-
- if( $action == "edit" ){ // Edit ToDo
- $POST['ModifyDate']= date("Y-m-d H:i:s");
- $IdTodo= $POST['Id'];
- $IdProject= $POST['IdProject'];
- unset($POST['Id'], $POST['IdProject']);
- $where= array('Id'=>$IdTodo);
- if( $this->Jmodel->update('todo', $POST, $where) ){
- $element= $this->getElementTodo($IdTodo, $IdProject);
- $html= array(
- 'type'=>'success',
- 'html'=>$element
- );
- echo json_encode($html);
- }
- }else{ // Save ToDo
- $POST['AddDate']= date("Y-m-d H:i:s");
- $insertId= $this->Jmodel->insert('todo', $POST, TRUE);
- if( $insertId ){
- $element= $this->getElementTodo($insertId, $POST['IdProject']);
- $html= array(
- 'type'=>'success',
- 'html'=>$element
- );
- echo json_encode($html);
- }
- }
- }
-
- // Get Element HTML dari Todo berdasarkan IdTodo
- public function getElementTodo($idTodo="", $IdProject=""){
- $where= array('Id'=>$idTodo);
- $todo= $this->db->get_where('todo', $where)->row_array();
- $extraAttr= array();
- $labelClass= "";
- if( $todo['Status'] == "yes" ){
- $extraAttr['checked']= 'checked';
- $labelClass= " complete-todos";
- }
- $attr_checkbox= array(
- 'name'=>'todo'.$todo['Id'],
- 'value'=>$todo['Id'],
- 'class'=>'todos'
- );
- $attr_checkbox= array_merge($attr_checkbox, $extraAttr);
- $html= '
- <div class="todos-row">
- <span class="btnactions">
- <a class="btn todos-btn todos-edit" href="' . site_url("project/todo") . "/" . $IdProject .
- '/edit/' . $idTodo . '">
- <i class="icon-pencil"></i>
- </a>
- <a class="btn todos-btn todos-delete" href="' . site_url("project/todo") . "/" . $IdProject .
- '/delete/' . $idTodo . '">
- <i class="icon-trash"></i>
- </a>
- </span>
- <label class="checkbox checkbox-tags' . $labelClass . '">' .
- form_checkbox($attr_checkbox) .
- '<span>' . $todo['Task'] . '</span>
- <span class="label label-warning">' . date("l, d F Y h:i A", strtotime($todo['DueDate'])) . '</span>' .
- '</label>' .
- '</div>';
-
- return $html;
- }
-
- // Show Employee Detail
- public function employee_detail($Username=""){
- $Username= urldecode($Username);
- // Get Data User Detail
- $sql= "SELECT * FROM user a
- LEFT JOIN user_detail b ON b.Id= a.IdDetail
- WHERE a.Username= '" . $Username . "'";
- $user= $this->db->query($sql)->row_array();
-
- // Table Description
- $description_user= array('Name'=>'Name', 'Address'=>'Address',
- 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
-
- foreach( $description_user as $key=>$value ){
- $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
- $user[$key]= $userdt;
- }
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['jscript']= $this->load->view('js/profile', $data, TRUE);
- $data['img_path']= $config->item('img_path');
- $data['description_user']= $description_user;
- $data['user']= $user;
- $this->themelib->getpage("user/profile", $data, "inc/theme_main");
- }
-
- // Show List of Employees
- public function employees($nopage="", $sorting=""){
- $POST= $this->input->post();
- $url= explode("&", $sorting);
-
- // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
- // Set Filter Searching
- $filter_params= $this->themelib->get_filter_params($url, $POST);
- extract($filter_params); // Variable Extact( sorting, filter_str, filter )
-
- // Set Default / Sorting
- $sorting= ( empty($sorting) ) ? "a.Username=ASC" : urldecode($sorting);
- $sort= explode("=", $sorting);
-
- // Get Seluruh Data Employees
- $employees= $this->Jmodel->getEmployees("", "", $sort, $filter);
- $jml= count($employees);
-
- $nopage= ( empty($nopage) ) ? 1 : $nopage;
- $numpage= $nopage;
- $nopage= (int)$nopage-1;
- $perpage= 12;
- $offset= $nopage * $perpage; // Nilai Offset u/ Query
- $jml_page= ceil($jml / $perpage); // Jumlah Halaman
-
- // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
- // dan tidak Ada $POST Searching
- if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
- redirect("employees/1"); // Redirect ke First Page
- }
-
- // Pagination Config
- $config['base_url'] = site_url() . 'employees';
- $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
- $config['total_rows'] = $jml;
- $config['per_page'] = $perpage;
- $config['use_page_numbers'] = FALSE;
- $config['uri_segment']= 2; // Pengenal URI Active Page
- $config['first_url']= 1;
- $this->pagination->initialize($config);
-
- // Jika User Melakukan Searching tidak dari Halaman 1
- if( ! empty($POST) && ! empty($nopage) ){
- redirect('employees/1/' . urlencode($sorting) . "&" . $filter_str);
- }
-
- // Get Data Project from DB sesuai dengan current Page
- $employees= $this->Jmodel->getEmployees($perpage, $offset, $sort, $filter);
- $description= array("Name", "Description");
-
- // Fields for Searching Filter
- $fields= array(
- 'a.Username'=>'Username',
- 'b.Name'=>'Name',
- 'c.Description'=>'Usertype'
- );
-
- $operator= $this->themelib->operator_search; // Get Operator Searching
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['jscript']= $this->load->view('js/filter', $data, TRUE);
- $data['img_path']= $config->item('img_path');
- $data['employees']= $employees;
- $data['description']= $description;
- $data['searching_fields']= $fields;
- $data['operator']= $operator;
- $data['pagination']= $this->pagination->create_links();
- $this->themelib->getpage("employees", $data, "inc/theme_main");
- }
-
- // Halaman Edit Profile Detail
- public function edit_profile($Username=""){
- if( ! empty($Username) ){
- $Username= urldecode($Username);
- }else{
- $Username= $this->session->userdata('Username');
- }
- $Id= $this->session->userdata('Id');
-
- // Get Data User Detail
- $sql= "SELECT * FROM user a
- LEFT JOIN user_detail b ON b.Id= a.Id
- WHERE a.Username= '" . $Username . "'";
- $user= $this->db->query($sql)->row_array();
-
- // Table Description
- $labels= array('Name'=>'Nama', 'Address'=>'Alamat', 'Gender'=>'Jenis Kelamin',
- 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak', 'Image'=>'Gambar');
-
- $feedback= "";
- if( empty($user) ){
- $feedback= "User " . $Username . " tidak ada.";
- }
-
- /* echo "<pre>";
- print_r($user);
- echo "</pre>";
- exit;*/
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['jscript']= "";
- $data['img_path']= $config->item('img_path');
- $data['user']= $user;
- $data['labels']= $labels;
- $data['feedback']= $feedback;
- $data['userId']= $Id;
- echo $this->load->view("user/edit_profile", $data, TRUE);
- /*$this->themelib->getpage("user/edit_profile", $data, "inc/theme_main");*/
- }
-
- // Halaman View Profile Detail
- public function profile($type=""){
- if( empty($type) ){
- $Username= $this->session->userdata('Username');
-
- // Get Data User Detail
- $sql= "SELECT * FROM user a
- LEFT JOIN user_detail b ON b.Id= a.Id
- WHERE a.Username= '" . $Username . "'";
- $user= $this->db->query($sql)->row_array();
-
- // Table Description
- $description_user= array('Name'=>'Name', 'Address'=>'Address',
- 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
-
- foreach( $description_user as $key=>$value ){
- $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
- $user[$key]= $userdt;
- }
- /* echo "<pre>";
- print_r($user);
- echo "</pre>";
- exit;*/
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['jscript']= $this->load->view('js/profile', $data, TRUE);
- $data['img_path']= $config->item('img_path');
- $data['description_user']= $description_user;
- $data['user']= $user;
- $this->themelib->getpage("user/profile", $data, "inc/theme_main");
- }else{
- $POST= $this->input->post();
-
- /* print_r($POST);
- print_r($_FILES);
- exit;*/
- foreach( $_FILES as $key=>$value ){
- $$key= $value;
- }
-
- $act_image= FALSE;
- if( !empty($Image['name']) ){
- // File Image tidak boleh lebih dari 2MB
- $maxsize= 2000000;
- if( $Image['size'] > $maxsize ){
- echo "File tidak boleh lebih dari 2MB !";
- exit;
- }
-
- // Cek Extension
- $image_ext= pathinfo($Image['name'], PATHINFO_EXTENSION);
- $reg_image= "#^(jpeg|jpg|png)$#";
- if( ! preg_match($reg_image, $image_ext) ){
- echo "File harus gambar ( jpeg|jpg|png ) !";
- exit;
- }
-
- $Username= $this->session->userdata('Username');
- $filename= $Username . "_avatar." . $image_ext;
- $tmp_file= $Image['tmp_name'];
- $fullpath= $this->config->item('assets_img') . "user/" . $filename;
-
- if( move_uploaded_file($tmp_file, $fullpath) ){
- $config['image_library'] = 'gd2';
- $config['source_image'] = $fullpath;
- $config['create_thumb'] = FALSE;
- $config['maintain_ratio'] = FALSE;
- $config['width'] = 200;
- $config['height'] = 200;
- $this->load->library('image_lib', $config);
-
- // Resize Image
- if( ! $this->image_lib->resize() ){
- echo "Resize File tidak berhasil. Silakan Coba Lagi !";
- exit;
- }else{
- $act_image= TRUE;
- }
- }else{
- echo "Error terjadi, Silakan coba lagi !";
- exit;
- }
- }
-
- if( $act_image ){
- $POST['Image']= $filename;
- }
- /*$POST['Id']= '10';*/
- $POST['DateOfBirth']= ( empty($POST['DateOfBirth']) ) ? "" : date('Y-m-d', strtotime($POST['DateOfBirth']));
- /*$POST['DateOfBirth']= date('Y-m-d', strtotime($POST['DateOfBirth']));*/
- /* echo $POST['DateOfBirth'];
- exit;*/
-
- /* print_r($POST);
- exit;*/
- $sql= "SELECT * FROM user a
- INNER JOIN user_detail b ON b.Id= a.Id
- WHERE a.Id= '" . $POST['Id'] . "'";
- $row= $this->db->query($sql)->row_array();
-
- if( empty($row) ){
- // Insert Data to user_detail
- $ins_detail= $POST;
- unset($ins_detail['Username']);
- $this->Jmodel->insert('user_detail', $ins_detail);
-
- /* $ins_user= array('IdDetail'=>$insert_id);
- $where= array('Id'=>$POST['Id']);
- $this->Jmodel->update('user', $ins_user, $where);*/
- }else{
- /* print_r($upd_detail);
- exit; */
- // Update Data user_detail
- $upd_detail= $POST;
- unset($upd_detail['Id']);
- $where= array('Id'=>$POST['Id']);
- $this->Jmodel->update('user_detail', $upd_detail, $where);
- }
- echo "success";
- exit;
- }
- }
-
- // Remove Tag / Untag
- public function untag(){
- $POST= $this->input->post();
-
- // Cek Apa Tag tsb di-tag pada Project
- $where= array('Project_ID'=>$POST['IdProject']);
- $sql= "SELECT * FROM project
- WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag LIKE '%" . $POST['IdTag'] . "%'";
- $query= $this->db->query($sql);
- $row= $query->row_array();
-
- // Remove Tag
- $IdTag= array();
- $IdTag= $row['IdTag'];
- $IdTag= array_flip(explode(",", $IdTag));
- unset($IdTag[$POST['IdTag']]);
- $IdTag= array_flip($IdTag);
-
- // Update DBase
- $data= array('IdTag'=>implode(",",$IdTag));
- if( $this->Jmodel->update('project', $data, $where) ){
- echo "success";
- exit;
- };
- /* echo "<pre>";
- print_r($IdTag);
- echo "</pre>";
- exit; */
- }
-
- // Add Tag to Project
- public function tag(){
- $POST= $this->input->post();
- // Get Data IdTag Field Sebelumnya
- /*$POST['IdProject']= '46';*/
- $where= array('Project_ID'=>$POST['IdProject']);
- $sql= "SELECT * FROM project
- WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag NOT LIKE '%" . $POST['IdTag'] . "%'";
- $query= $this->db->query($sql);
- $row= $query->row_array();
-
- // Jika tidak kosong tambahkan dengan data sebelumnya
- if( ! empty($row['IdTag']) ){
- $POST['IdTag']= $row['IdTag'] . "," . $POST['IdTag'];
- }
-
- // Update
- unset($POST['IdProject']);
- if( $this->Jmodel->update('project', $POST, $where) ){
- echo "success";
- exit;
- }
-
- /* echo "<pre>";
- print_r($POST);
- echo "</pre>";
- exit;*/
- }
-
- // View Untuk Add New Tag ( ColorPicker )
- public function addtag(){
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $html= $this->load->view("tag/create", $data, TRUE);
- echo $html;
- /*$this->themelib->getpage("tag/create", $data, "inc/theme_main");*/
- }
-
- // Get Current Tag yang baru di-create
- public function get_tag(){
- $POST= $this->input->post();
- $POST['tagName']= strtoupper($POST['tagName']);
-
- // Get Current Tag yang baru di-create
- $where= array('tagName'=>$POST['tagName']);
- $tag= $this->db->get_where('tag', $where)->row_array();
-
- // Create Group Checkbox Tag
- $attr_checkbox= array(
- 'name'=>$tag['tagName'].'[name]',
- 'value'=>$tag['tagName'],
- 'class'=>'tags'
- );
- $prev_tags= '<label class="checkbox">';
- $prev_tags.= form_checkbox($attr_checkbox);
- $prev_tags.= form_hidden($tag['tagName'].'[color]', $tag['tagColor']);
- $prev_tags.= $tag['tagName'];
- $prev_tags.= '</label>';
- echo $prev_tags;
- /* $tags= $this->db->get("tag")->result_array();
- $prev_tags= "";
- foreach( $tags as $tag ){
- $prev_tags.= '<label class="checkbox">' .
- '<input type="checkbox" name="tagName" value="' . $tag['tagName'] . '">' . $tag['tagName'] .
- '</label>';
- }*/
- /*echo json_encode($tags);*/
- }
-
- // Save / Process to Database
- public function savetag(){
- $POST= $this->input->post();
- $POST['tagName']= strtoupper($POST['tagName']);
- /* echo "<pre>";
- print_r($POST);
- echo "</pre>";
- exit;*/
-
- // Check Apakah Tag Name sudah digunakan
- $where= array('tagName'=>$POST['tagName']);
- if( $this->db->get_where('tag', $where)->num_rows() ){
- echo "Tag dengan nama tersebut sudah ada.";
- exit;
- }
-
- // Insert to Database
- if( $this->Jmodel->insert('tag', $POST) ){
- echo "success";
- exit;
- }
- }
-
- // Add New Tag ( ColorPicker )
- public function colorPicker(){
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $this->themelib->getpage("test", $data, "inc/theme_main");
- }
-
- // Get List Of Template
- public function template_all($param="page", $nopage="", $sorting=""){
- $POST= $this->input->post();
- $url= explode("&", $sorting);
-
- // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
- // Set Filter Searching
- $filter_params= $this->themelib->get_filter_params($url, $POST);
- extract($filter_params); // Variable Extact( sorting, filter_str, filter )
-
- // Set Default / Sorting
- $sorting= ( empty($sorting) ) ? "Name=ASC" : urldecode($sorting);
- $sort= explode("=", $sorting);
-
- // Get Jumlah Project List
- $jml= $this->Jmodel->getData("project_template", "", "", $sort, $filter, true);
-
- // Process Per-page dan Offset
- $nopage= ( empty($nopage) ) ? 1 : $nopage;
- $numpage= $nopage;
- $nopage= (int)$nopage-1;
- $perpage= 5;
- $offset= $nopage * $perpage; // Nilai Offset u/ Query
- $jml_page= ceil($jml / $perpage); // Jumlah Halaman
-
- // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
- // dan tidak Ada $POST Searching
- if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
- redirect("project/template_all");
- }
-
- // Pagination Config
- $config['base_url'] = base_url() . 'project/template_all/page';
- $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
- $config['total_rows'] = $jml;
- $config['per_page'] = $perpage;
- $config['use_page_numbers'] = FALSE;
- $config['uri_segment']= 4; // Pengenal URI Active Page
- $config['first_url']= 1;
- $this->pagination->initialize($config);
-
- // Jika User Melakukan Searching tidak dari Halaman 1
- if( ! empty($POST) && !empty($nopage) ){
- redirect('project/template_all/page/1/' . urlencode($sorting) . "&" . $filter_str);
- }
-
- // Get Data Project from DB sesuai dengan current Page
- $rows= $this->Jmodel->getData("project_template", $perpage, $offset, $sort, $filter);
- $list= array();
- if( ! empty($rows) ){
- // Get IdTemplate Untuk SQL Condition
- $data_in= array();
- foreach( $rows as $row ){
- $data_in[]= $row['Id'];
- }
- $IdTemplate= "'" . implode("','", $data_in) . "'";
-
- $operand= "";
- if( ! empty($filter) ){
- $operand= "AND";
- }
- // Get Seluruh Data template dan project process
- $sql= "SELECT * FROM project_template a
- LEFT JOIN pos_menu b ON b.IdTemplate= a.Id
- WHERE a.Id IN(" . $IdTemplate . ") " . $operand . " {condition}
- ORDER BY {sorting}, b.Urutan";
- $rows= $this->Jmodel->getData("", "", "", $sort, $filter, false, $sql);
-
- // Modify List untuk dipakai pada Perulangan
- foreach( $rows as $row ){
- $list[$row['Name']][]= $row;
- }
- }
-
- // Fields for Searching Filter
- $fields= array(
- 'Name'=>'Template Name'
- );
-
- $operator= $this->themelib->operator_search; // Get Operator Searching
-
- // Current Page
- $curpage= $this->uri->segment(4);
- /* echo "<pre>";
- print_r($list);
- echo "</pre>";
- exit;*/
- $rows= array();
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- /*$data['jscript']= '';*/
- $data['jscript']= $this->load->view('js/filter', $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['rows']= $list;
- $data['pagination']= $this->pagination->create_links();
- $data['hrefNewProject']= site_url() . "project/template";
- /* Searching Data */
- $data['baseurl_sort']= site_url() . "project/template_all";
- $data['searching_fields']= $fields;
- $data['operator']= $operator;
- $data['filter_str']= $filter_str;
- $data['nopage']= ( ! empty($curpage) ) ? $curpage : 1;
- $this->themelib->getpage("project/template_all", $data, "inc/theme_main");
- }
-
- // Create New / Edit Project Template
- // Halaman Ini Mengirimkan POST serta Pengeditan pada Halaman dengan Javascript Enabled
- public function template($action="", $templateName= ""){
- $templateName= urldecode($templateName);
- if( $action == "edit" ){
- // Get Data Template
- $where= array('Name'=>$templateName);
- $template= $this->db->get_where("project_template", $where)->row_array();
-
- // Get Data Step Process
- $where= array('IdTemplate'=>$template['Id']);
- $this->db->order_by('Urutan ASC');
- $process= $this->db->get_where("pos_menu", $where)->result_array();
-
- /* echo "<pre>";
- print_r($template);
- print_r($process);
- echo "</pre>";
- exit; */
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['template']= $template;
- $data['process']= $process;
- $this->themelib->getpage("project/template_edit", $data, "inc/theme_main");
- }elseif( $action == "delete" ){
- // Get Id Template
- $where= array('Name'=>$templateName);
- $template= $this->db->get_where('project_template', $where)->row_array();
-
- $where= array('IdTemplate'=>$template['Id']);
- $jml= $this->db->get_where('project', $where)->num_rows();
- if( $jml ){
- echo json_encode(array('type'=>'error',
- 'msg'=>"Template tidak bisa di-hapus !\nTemplate sudah digunakan pada Project."));
- }else{
- // Delete Data pada Tabel project_template dan pos_menu
- $where_project_template= array('Id'=>$template['Id']);
- if( $this->db->delete('project_template', $where_project_template) ){
- echo json_encode(array('type'=>'success',
- 'msg'=>"Data has been delete"));
- }
- }
- }else{
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $this->themelib->getpage("project/template", $data, "inc/theme_main");
- }
- }
-
- // Edit And Delete Template
- public function action_template($action){
- $POST= $this->input->post();
- /* print_r($POST);
- exit;*/
- if( $action == "edit" ){
-
- // Group Data New Process yang akan ditambahkan
- $newProcess= array();
- if( isset($POST['process']) ){
- extract($POST['process']);
- foreach( $Name as $key=>$value ){
- $data= array();
- $data['Process_Name']= $value;
- $data['Score_Completion']= $Score[$key];
- $data['Urutan']= $Urutan[$key];
- $data['IdTemplate']= $POST['template']['Id'];
- $newProcess[]= $data;
- }
- }
-
- // Get Previous Process POST
- $prevProcess= $POST['prev_process'];
-
- // Get Previous Process di DBase
- $where= array('IdTemplate'=>$POST['template']['Id']);
- $dbProcess= $this->db->get_where('pos_menu', $where)->result_array();
-
- // Get Data Process yang Harus di-Delete
- $delProcess= array();
- foreach( $dbProcess as $process ){
- if( ! array_key_exists($process['Id'], $prevProcess) ){
- $this->db->delete('pos_menu', array('Id'=>$process['Id']));
- $delProcess[]= $process;
- }
- }
-
- // Update Previous Process
- $dtUpdate= array();
- foreach( $prevProcess as $list ){
- $dtUpdate['Process_Name']= $list['Name'];
- $dtUpdate['Score_Completion']= $list['Score'];
- $dtUpdate['Urutan']= $list['Urutan'];
- $where= array('Id'=>$list['Id']);
- $this->Jmodel->update('pos_menu', $dtUpdate, $where);
- }
-
- // Insert New Process
- foreach( $newProcess as $list ){
- $this->Jmodel->insert('pos_menu', $list);
- }
-
- if( $POST['type'] == "ajax" ){
- echo "success";
- exit;
- }
- /* echo "<pre>";
- print_r($process);
- print_r($prevProcess);
- print_r($newProcess);
- print_r($delProcess);
- echo "</pre>";
- exit;*/
- }else{
-
- }
- }
-
- // Create New Project Template
- public function create_template(){
- $POST= $this->input->post();
-
- // Cek Jika Template dengan Nama tsb tidak Ada
- $template= array('Name'=>$POST['template_name']);
- if( $this->db->get_where('project_template', $template)->num_rows() ){
- if( $POST['type'] == "ajax" ){
- echo "Template dengan nama tersebut sudah Ada !";
- exit;
- }else{
- $this->session->set_userdata('error', 'Template dengan nama tersebut sudah Ada !');
- redirect('project/template_all');
- }
- }
-
- // Extract process dari parameter POST
- extract($POST['process']);
-
- // Gabungkan Array Process dan Score
- $posmenu= array();
- $urut= 1;
- foreach( $Name as $key=>$value ){
- $posmenu[$key]= array('Process_Name'=>$value, 'Score_Completion'=>$Score[$key],
- 'Urutan'=>$Urutan[$key]);
- $urut++;
- }
-
- /* echo "<pre>";
- print_r($posmenu);
- echo "</pre>";
- exit;*/
- // Insert Template to Database
- $template= array('Name'=>$POST['template_name']);
- $insert_id= $this->Jmodel->insert("project_template", $template, true);
- if( $insert_id ){
- foreach( $posmenu as $row ){
- $row['IdTemplate']= $insert_id;
- $this->Jmodel->insert('pos_menu', $row);
- }
- }
-
- if( $POST['type'] == "ajax" ){
- echo "success";
- exit;
- }else{
- redirect('project/template_all');
- }
- }
-
- public function getPassword(){
- $this->load->view("");
- echo md5('sales_admin');
- }
-
- public function select_template(){
- $rows= $this->db->get('project_template')->result_array();
- $template= array();
- $template[""]= "-- Select --";
- foreach( $rows as $row ){
- $template[$row['Id']]= $row['Name'];
- }
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/select_template.php", $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['template']= $template;
- $data['hrefAction']= base_url() . "setting/summary";
- $this->themelib->getpage("project/select_template", $data, "inc/theme_main");
- }
-
- // Create And Edit Setting Summary
- // @param1 string berisi 'summary',
- // @param2 int berisi IdTemplate u/ ByPass Ketika User klik Save Redirect Langsung ke halaman Ini
- public function setting($param="", $IdTemplate=""){
- $POST= $this->input->post();
- if( ! empty($POST) ){
- extract($POST);
- }
-
- // Jika Tidak Ada IdTemplate Redirect untuk select Template
- if( ! isset($IdTemplate) || empty($IdTemplate) ){
- redirect("project/select_template");
- }
-
- // Get Previous Setting Summary
- $Username= $this->session->userdata("Username");
- $where= array("Username"=>$Username, "IdTemplate"=>$IdTemplate);
- $rows= $this->db->get_where("summary", $where)->result_array();
-
- if( count($rows) ){
- $summaries= array();
- foreach( $rows as $row ){
- $summaryFields= unserialize($row['summaryFields']);
- $summaries[$row['Posmenu_ID']]= $summaryFields;
- }
- }
-
- // Get Seluruh Field pada setiap Process berdasarkan Template Yang di-Select
- $sql= "SELECT a.Id AS IdProcess, a.Process_Name, a.Table, b.* FROM pos_menu a
- LEFT JOIN form_fields b ON b.FormID= a.FormID
- WHERE ( b.Name!= 'Project_ID' OR b.Name IS NULL ) AND a.IdTemplate= '" . $IdTemplate . "'
- ORDER BY a.Id";
- $rows= $this->db->query($sql)->result_array();
-
- $process= array();
- $description= array();
- foreach( $rows as $row ){
- if( !empty($row["Name"]) ){
- $process[$row["IdProcess"]][]= $row;
- $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
- $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
- }else{
- $process[$row["IdProcess"]]= array();
- $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
- $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
- }
- }
-
- /* echo "<pre>";
- print_r($POST);
- print_r($description);
- echo "</pre>";
- exit;*/
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= "";
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data["process"]= $process;
- $data["description"]= $description;
- $data['summaries']= ( isset($summaries) ) ? $summaries : "";
- $data['IdTemplate']= $IdTemplate;
- $this->themelib->getpage("project/setting_summary", $data, "inc/theme_main");
- }
-
- // Processing Summary
- public function set_summary(){
- /* echo "<pre>";
- print_r($jml);
- echo "</pre>";
- exit;*/
- $POST= $this->input->post();
- $Username= $this->session->userdata("Username");
- $IdTemplate= $POST['IdTemplate'];
-
- // Check If Data is exist remove it first
- $jml= $this->db->get_where('summary', array('Username'=>$Username, 'IdTemplate'=>$IdTemplate))->num_rows();
- if( $jml ){
- $this->db->where(array('Username'=>$Username, 'IdTemplate'=>$IdTemplate));
- $this->db->delete('summary');
- }
-
- // Insert Score
- $scoreData= array();
- $scoreData['Username']= $Username;
- $scoreData['summaryFields']= serialize($POST['score']);
- $scoreData['Posmenu_ID']= '0';
- $scoreData['IdTemplate']= $IdTemplate;
- $this->Jmodel->insert("summary", $scoreData);
-
- // Insert Semua Data Summary ke Tabel summary
- foreach( $POST['Process'] as $key=>$process ){
- $insData= array();
- $insData['Username']= $Username;
- $insData['summaryFields']= serialize($process);
- $insData['Posmenu_ID']= $key;
- $insData['IdTemplate']= $IdTemplate;
- $this->Jmodel->insert("summary", $insData);
- }
-
- // Set Feedback and Redirect
- $this->session->set_userdata('feedback','The changes has been saved !');
- redirect("project/setting/summary/" . $IdTemplate);
- }
-
- public function getdata(){
- $data= $this->db->get_where("project_process", array("Id"=>"3"))->row_array();
- $row= unserialize($data["formValue"]);
- echo "<pre>";
- print_r($row);
- echo "</pre>";
- }
-
- // Create Project
- public function index($params=""){
- $rows= $this->db->get('project_template')->result_array();
- $template= array();
- $template[""]= "-- Select --";
- foreach( $rows as $row ){
- $template[$row['Id']]= $row['Name'];
- }
-
- /* echo "<pre>";
- print_r($template);
- echo "</pre>";
- exit;*/
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['template']= $template;
-
- $POST= $this->input->post();
- if( isset($POST["submit"]) || $POST["type"] == "ajax" ){
- // Set Rules Validasi
- $config= array(
- array(
- 'field'=> 'Project_Name',
- 'label'=> 'Project Name',
- 'rules'=> 'required'
- ),
- array(
- 'field'=> 'Identitas_Perusahaan',
- 'label'=> 'Identitas Perusahaan',
- 'rules'=> 'required'
- )
- );
- $this->form_validation->set_rules($config);
-
- if( $this->form_validation->run() == TRUE ){ // Cek Validasi
- $type= isset($POST["type"]) ? $POST["type"] : "";
- // Set Data
- $POST["Username"]= $this->session->userdata("Username");
-
- // Cek Project Name ada atau tidak dengan GroupName tsb
- // karena ada 2 User Type yaitu Admin dan Sales yang bisa mengakses project yg sama
- $where= array("Username"=>$POST["Username"], "Project_Name"=>$POST["Project_Name"]);
- $exist= $this->db->get_where("project", $where)->num_rows();
- if( ! $exist ){
- unset($POST["submit"], $POST["type"]); // Unset Data
-
- // Insert Data to DB
- if( $this->db->insert("project", $POST) ){
- if( $type == "ajax" ){
- echo "success";
- exit;
- }else{
- $this->session->set_userdata("error_ot","Data has been saved.");
- $this->themelib->getpage("project/create", $data, "inc/theme_main");
- }
- }
- }else{
- if( $type == "ajax" ){
- echo "Project Name is already exist.";
- exit;
- }else{
- $this->session->set_userdata("error_ot","Project Name is already exist.");
- $this->themelib->getpage("project/create", $data, "inc/theme_main");
- }
- }
- }else{
- $this->themelib->getpage("project/create", $data, "inc/theme_main");
- }
- }else{
- $this->themelib->getpage("project/create", $data, "inc/theme_main");
- }
- }
-
- /* public function formBuilder(){
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/formbuilder.php", $data, TRUE);
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $this->themelib->getpage("formbuilder", $data);
- }
-
- public function formBuilder_create(){
- $POST= $this->input->post();
- $config= $this->config;
- $data= array();
-
- // Cek Data pada Tabel masterform
- $where= array("FormID"=>$POST["FormID"]);
- $jml= $this->db->get_where("masterform", $where)->num_rows();
- if( ! $jml ){ // Jika Data tidak Ada Insert data tsb
- // Insert Data ke Tabel masterform
- $form= array("FormID"=>$POST["FormID"], "ActionUrl"=>"#");
- $this->db->insert("masterform", $form);
-
- // Insert Data ke Tabel form_fields
- $fields= $POST;
- unset($fields["submit"], $fields["FormID"]);
- foreach( $fields as $key=>$field ){
- $insfield= array();
- $insfield["FormID"]= $POST["FormID"];
- $insfield["Name"]= $key;
- if( $key == "Project_ID" ){
- $insfield["FieldType"]= $field;
- }else{
- $data= explode("~", $field);
- $insfield["FieldType"]= $data[0];
- $insfield["Label"]= $data[1];
- }
- $this->db->insert("form_fields", $insfield);
- }
- redirect("project/formBuilder");
- }else{ // Jika Data Ada Redirect dan display error
- $this->session->set_userdata("error", "Form dengan ID tersebut sudah Ada.");
- redirect("project/formBuilder");
- }
- }
- */
-
- // Create Project
- public function edit($IdProject=""){
- // Check Project
- $where= array("Project_ID"=>$IdProject);
- $query= $this->db->get_where("project", $where);
- $jml= $query->num_rows();
-
- if( empty($jml) ){
- redirect("project/daftar");
- }else{
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['main_url']= base_url();
- $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
- /*$data['jscript']= "";*/
- $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['row']= $query->row_array();
- $this->db->flush_cache();
- $this->themelib->getpage("project/edit", $data, "inc/theme_main");
- }
- }
-
- public function daftar($param="page", $nopage="", $sorting=""){
- // Get Jumlah Baris dari tabel Project dengan GroupName yang sama
- $Username= $this->session->userdata("Username");
- /*$Username= "sales";*/
- $POST= $this->input->post();
- $url= explode("&", $sorting);
-
- // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
- // Set Filter Searching
- $filter_params= $this->themelib->get_filter_params($url, $POST);
- extract($filter_params); // Variable Extact( sorting, filter_str, filter )
- /* echo "<pre>";
- print_r($filter_params);
- echo "</pre>";*/
-
- /*exit;*/
- /* $sorting= $url[0];
- $filter_url= ( isset($url[1]) ) ? $url[1] : "";
- $filter_str= ""; //
- if( isset($POST['btnSubmit']) ){
- // Set Limit to default
- $nopage= 1;
- // Set Filter properties dan set $filter_str untuk dimasukan ke url pagination
- $filter= array('field'=>$POST['search'], 'op'=>$POST['op_search'], 'key'=>$POST['search_key']);
- foreach( $filter as $key=>$value ){
- $filter[$key]= urlencode($value);
- }
- $filter_str= implode(":", $filter);
- }else{
- // Set Filter dari Pagination Url
- $filter= "";
- if( ! empty($filter_url) ){
- $filter_str= $filter_url;
- $filter_url= explode(":", $filter_url);
- $filter= array('field'=>$filter_url[0], 'op'=>$filter_url[1], 'key'=>$filter_url[2]);
- }
- }*/
-
- // Set Default / Sorting
- $sorting= ( empty($sorting) ) ? "Project_Name=ASC" : urldecode($sorting);
- $sort= explode("=", $sorting);
-
- // Get Jumlah Project List
- $rows= $this->Jmodel->getProjectByUsertype($Username, "", "", "", $filter, TRUE);
- $jml= count($rows);
-
- // Get Offset, Jumlah Page
- $nopage= ( empty($nopage) ) ? 1 : $nopage;
- $numpage= $nopage; // Get Number Page from URL
- $nopage= (int)$nopage-1;
- $perpage= 5;
- $offset= $nopage * $perpage; // Nilai Offset u/ Query
- $jml_page= ceil($jml / $perpage); // Jumlah Halaman
-
- // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
- // dan tidak Ada $POST Searching
- /* echo "<pre>";
- if( ! $numpage < 1 ){
- echo $numpage . "->" . $jml_page . "<br/>";
- }
- print_r($POST);
- echo "</pre>";*/
- if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
- redirect("project/daftar"); // Redirect ke First Page
- }
-
- /* echo $filter_str;
- exit;*/
- // Pagination Config
- $config['base_url'] = site_url('project/daftar/page');
- $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
- $config['total_rows'] = $jml;
- $config['per_page'] = $perpage;
- $config['use_page_numbers'] = FALSE;
- $config['uri_segment']= 4; // Pengenal URI Active Page
- $config['first_url']= 1;
- $this->pagination->initialize($config);
-
- // Jika User Melakukan Searching tidak dari Halaman 1
- if( ! empty($POST) && !empty($nopage) ){
- redirect('project/daftar/page/1/' . urlencode($sorting) . "&" . $filter_str);
- }
-
- // Get Data Project from DB sesuai dengan current Page
- $getRows= $this->Jmodel->getProjectByUsertype($Username, $perpage, $offset, $sort, $filter);
- // Set Project_Id sebagai Key
- $rows= array();
- foreach( $getRows as $list ){
- $rows[$list['Project_ID']]= $list;
- }
-
- // Get Summary untuk setiap Project dan di Group Berdasarkan IdTemplate
- // Group Score Berdasarkan IdTemplate
- $dtsummaries= $this->db->get_where('summary', array('Username'=>$Username))->result_array();
- $getsummaries= array();
- $statScore= array();
- foreach( $dtsummaries as $summary ){
- if( $summary['Posmenu_ID'] == "0" ){
- $statScore[$summary['IdTemplate']][]= unserialize($summary['summaryFields']);
- continue;
- }
- $getsummaries[$summary['IdTemplate']][]= $summary;
- }
-
- // Get summaries and formValue
- $values= array();
- $summaries= array();
- $file= array();
- foreach( $rows as $row ){
- if( isset($getsummaries[$row['IdTemplate']]) ){
- foreach( $getsummaries[$row['IdTemplate']] as $summary ){
- $where= array('Posmenu_ID'=>$summary['Posmenu_ID'], 'Project_ID'=>$row['Project_ID']);
- $getdt= $this->db->get_where('project_process', $where)->row_array();
- $formValue= ( isset($getdt['formValue']) ) ? unserialize($getdt['formValue']) : "";
- // Add formValue Data sesuai Project_ID -> Posmenu_ID
- if( $formValue ){
- // Get Description Type Upload File
- $regfile= "#^.+\..{3,4}$#";
- foreach( $formValue as $formKey=>$form ){
- if( preg_match($regfile, $form) ){
- $where= array('Filename'=>$form);
- $dtfile= $this->db->get_where('upload', $where)->row_array();
- $file[$dtfile['Filename']]= $dtfile;
- /*echo $formKey . "->" . $form . "<br/>";*/
- }elseif($formKey == "PO_ID" ){
- $where= array('Project_ID'=>$row['Project_ID']);
- $poid= $this->db->get_where('po_id', $where)->row_array();
-
- $formValue[$formKey]= ( isset($poid['PO_ID']) ) ? $poid['PO_ID'] : "";
- }
- }
- $values[$row['Project_ID']][$summary['Posmenu_ID']]= $formValue;
- }
- // Modify Summary Data sesuai Dengan Template Yang Dipilih Untuk Project
- $summary_field= unserialize($summary['summaryFields']);
- $summaries[$row['IdTemplate']][$summary['Posmenu_ID']]= $summary_field;
- }
- }
- }
-
- // Remove unnecessary Fields / Get Fields sesuai Summary
- foreach( $values as $key=>$value ){
- foreach( $value as $subkey…
Large files files are truncated, but you can click here to view the full file