/application/controllers/project_rev.php
PHP | 2319 lines | 1447 code | 218 blank | 654 comment | 142 complexity | 665bcb9868821fc44222c8dd06415bd5 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
- }
-
- public function server_var(){
- foreach( $_SERVER as $key=>$value ){
- echo $key . "->" . $value . "<br/>";
- }
- /* echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "<br/>";
- echo site_url();*/
- }
-
- // 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"));
- }
-
- // 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(){
- /* echo "<pre>";
- print_r($late_todos);
- echo "</pre>";
- exit;*/
- $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=""){
- /* echo "<pre>";
- print_r($jml);
- echo "</pre>";
- exit;*/
- // Get Seluruh Data Employees
- $jml= $this->Jmodel->getEmployees(TRUE);
-
- $nopage= ( empty($nopage) ) ? 1 : $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 Negatif Value
- if( $nopage >= $jml_page || $nopage < 0 ){
- redirect("employees/1"); // Redirect ke First Page
- }
-
- // Pagination Config
- $config['base_url'] = site_url() . 'employees';
- $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);
-
- // Get Data Project from DB sesuai dengan current Page
- $employees= $this->Jmodel->getEmployees("", $perpage, $offset);
- $description= array("Name", "Description");
-
- $config= $this->config;
- $data= array();
- $data['bar_path']= $config->item('loading');
- $data['jscript']= "";
- $data['img_path']= $config->item('img_path');
- $data['employees']= $employees;
- $data['description']= $description;
- $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.IdDetail
- 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.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;
- }
- /* echo "<pre>";
- print_r($user_detail);
- 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{
- /*sleep(3);*/
- $POST= $this->input->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']));*/
-
- $sql= "SELECT * FROM user a
- INNER JOIN user_detail b ON b.Id= a.IdDetail
- 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'], $ins_detail['Id']);
- $insert_id= $this->Jmodel->insert('user_detail', $POST, TRUE);
-
- $ins_user= array('IdDetail'=>$insert_id);
- $where= array('Id'=>$POST['Id']);
- $this->Jmodel->update('user', $ins_user, $where);
- }else{
- // Insert Data to user_detail
- $upd_detail= $POST;
- unset($upd_detail['Id']);
- $where= array('Id'=>$POST['Id']);
- $insert_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
- $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) ) ? "Name=ASC" : urldecode($sorting);
- $sort= explode("=", $sorting);
- /* echo "<pre>";
- print_r($filter);
- echo "</pre>";*/
- // 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
- // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
- // dan tidak Ada $POST Searching
- if( ( $numpage > $jml_page || $numpage < 1 ) && ! isset($POST['btnSubmit']) ){
- /*if( $numpage < 1 ){*/
- 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);
-
- // 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) . "'";
-
- // 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 . ") {condition}
- ORDER BY {sorting}, b.Urutan";
- $rows= $this->Jmodel->getData("", $perpage, $offset, $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
-
- /* 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['menu']= $this->load->view("inc/menu.php", $data, TRUE);
- $data['rows']= $list;
- $data['pagination']= $this->pagination->create_links();
- $data['hrefNewProject']= site_url() . "project/template";
- $data['baseurl_sort']= site_url() . "project/template_all";
- $data['searching_fields']= $fields;
- $data['operator']= $operator;
- $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= ""){
- if( $action == "edit" ){
- // Get Data Template
- $where= array('Name'=>urldecode($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");
- }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();
- echo "<pre>";
- print_r($POST);
- echo "</pre>";
- exit;
- if( $action == "edit" ){
- // Menambah Field Urutan Pada Process POST yang dikirim
- $urutan= 1;
- foreach( $POST['process'] as $key=>$process ){
- $updatePost= array();
- if( is_array($process) ){
- $updatePost= $process;
- $updatePost['Urutan']= $urutan;
- $POST['process'][$key]= $updatePost;
- }else{
- $updatePost['Name']= $process;
- $updatePost['Urutan']= $urutan;
- $POST['process'][$key]= $updatePost;
- }
- $urutan++;
- }
-
- // Get Existing Process Step
- $process= array();
- $prevProcess= array();
- $newProcess= array();
- foreach( $POST['process'] as $key=>$list ){
- if( isset($list['Id']) ){
- $prevProcess[$key]= $list;
- }else{
- $newProcess[]= $list;
- }
- }
-
- // 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;
- }
- /* if( array_key_exists($process['Id'], $prevProcess) ){
- echo "ex-" . $process['Process_Name'] . "\n";
- }else{
- $delProcess[]= $process;
- echo "del-" . $process['Process_Name'] . "\n";
- }*/
- }
-
- $process= array();
- foreach( $newProcess as $key=>$list ){
- $dtproc= array();
- $dtproc['Process_Name']= $list['Name'];
- $dtproc['Urutan']= $list['Urutan'];
- $dtproc['Score_Completion']= $POST['score'][$key];
- $dtproc['IdTemplate']= $POST['template']['Id'];
- $process[]= $dtproc;
- }
-
- // 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( $process 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();
- echo "<pre>";
- print_r($POST);
- echo "</pre>";
- exit;
-
- // 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');
- }
- }
-
- // Gabungkan Array Process dan Score
- $posmenu= array();
- $urut= 1;
- foreach( $POST['process'] as $key=>$value ){
- $posmenu[$key]= array('Process_Name'=>$value, 'Score_Completion'=>$POST['score'][$key], 'Urutan'=>$urut);
- $urut++;
- }
-
- // 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
- $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);
-
- /* if( empty($jml) ){
- redirect("project");
- }*/
-
- // 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
- if( ( $numpage > $jml_page || $numpage < 1 ) && ! empty($jml_page) && ! isset($POST['btnSubmit']) ){
- redirect("project/daftar"); // Redirect ke First Page
- }
-
- // 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);
-
- // 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();
- /*echo "<pre>";*/
- 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 ){
- /*print_r($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/>";*/
- }
- }
- $values[$row['Project_ID']][$summary['Posmenu_ID']]= $formValue;
- }
- // Modify Summary Data sesuai Dengan Template Yang Dipilih Untuk Project
- $summaries[$row['IdTemplate']][$summary['Posmenu_ID']]= unserialize($summary['summaryFields']);
- }
- }
- }
- /* print_r($file);
- echo "</pre>";*/
-
- // Remove unnecessary Fields / Get Fields sesuai Summary
- foreach( $values as $key=>$value ){
- foreach( $value as $subkey=>$subvalue ){
- foreach( $subvalue as $fieldkey=>$field ){
- $IdTemplate= $rows[$key]['IdTemplate'];
- /*echo $IdTemplate . "<br/>";*/
- if( ! in_array($fieldkey, $summaries[$IdTemplate][$subkey]) ){
- unset($values[$key][$subkey][$fieldkey]);
- }
- }
- }
- }
-
- // Get Score u/ Setiap Project
- $dbscore= $statScore;
- $score= array();
- /* foreach( $dbscore as $value ){
- if( $value[0] ){
- $score= $this->getScore("", $rows);
- }
- }*/
- $score= $this->getScore("", $rows);
-
- // Get Description Untuk Setiap Fields
- $description= array();
- foreach( $summaries as $templatekey=>$list ){
- foreach( $list as $key=>$summary ){
- $sql= "SELECT b.Label, b.Name FROM pos_menu a
- LEFT JOIN form_fields b ON b.FormID= a.FormID
- WHERE a.Id= '" . $key . "' AND a.IdTemplate= '" . $templatekey . "' AND b.Name != 'Project_ID'";
- $getfields= $this->db->query($sql)->result_array();
- foreach( $getfields as $fieldkey=>$field ){
- $description[$key][$field['Name']]= $field['Label'];
- }
- }
- }
-
- // Get Available Tags
- $dbTags= $this->db->get('tag')->result_array();
- $tags= array();
- foreach( $dbTags as $tag ){
- $tags[$tag['tagName']]= $tag;
- }
-
- // Fields for Searching Filter
- $fields= array(
- 'Project_Name'=>'Project Name',
- 'Identitas_Perusahaan'=>'Identitas Perusahaan'
- );
-
- $operator= $this->themelib->operator_search; // Get Operator Searching
-
- /* echo "<pre>";
- print_r($summaries);
- print_r($description);
- print_r($values);
- 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["list"]= $rows;
- $data["summaries"]= $summaries;
- $data["description"]= $description;
- $data["file"]= $file; // Description About File Upload / Document
- $data["tags"]= $tags;
- $data["formValues"]= $values;
- $data["statScore"]= $statScore;
- $data["score"]= $score;
- $data['baseurl_sort']= site_url() . "project/daftar";
- $data["pagination"]= $this->pagination->create_links();
- $data['searching_fields']= $fields;
- $data['operator']= $operator;
- $this->themelib->getpage("project/view", $data, "inc/theme_main");
- }
-
- // Get Score Completion Untuk satu atau Beberapa Project
- // @access private
- // @param1 String, @param2 Array
- // @return Array
- private function getScore($IdProject="", $rows=""){
- $dtscore= array();
- $jml= 0;
- foreach( $rows as $row ){
- if( is_array($row) ){
- $getscore= $this->calcScore($row);
- $key= array_keys($getscore);
- $value= array_values($getscore);
- $dtscore[$key[0]]= $value[0];
- }else{
- $jml= 1;
- }
- }
- // Calculate Score Per Data using Method calcScore
- if( $jml ){
- $dtscore= $this->calcScore($rows);
- }
-
- return $dtscore;
- }
-
- // Calculate Score for each project
- // @access private
- // @param Array
- // @return Array
- private function calcScore($row=""){
- // Get Seluruh Project Process
- $posMenu= $this->db->get('pos_menu')->result_array();
-
- $dtscore= array();
- $score= 0;
- foreach( $posMenu as $pos ){
- $IdProject= $row['Project_ID'];
- $Posmenu_ID= $pos['Id'];
- $FormID= $pos['FormID'];
-
- // Get Seluruh Field Dari Form Yang di-select
- $sql= "SELECT * FROM form_fields WHERE FormID= '" . $FormID . "' AND Name != 'Project_ID'";
- $fields= $this->db->query($sql)->result_array();
- if( !empty($fields) ){
- $comfields= array();
- foreach( $fields as $field ){
- $comfields[$field["Name"]]= "";
- }
- }
-
- // Get Data Form Dari Tabel project_process
- $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
- $query= $this->db->get_where("project_process", $where);
- $jml= $query->num_rows();
-
- $dtscore[$IdProject]= $score;
- if( $jml ){
- $dtform= $query->row_array();
- $formValue= unserialize($dtform["formValue"]);
- $formValue= array_merge($comfields, $formValue); // Merge Data Array FormValue dengan All Fields
-
- // Cek Empty Field Pada Process
- $emptystat= 0;
- foreach( $formValue as $key=>$value ){
- if( empty($value) ){
- $emptystat= 1;
- }
- }
-
- // Jika data sudah terisi semua tambahkan score Untuk masing2x Project
- if( ! $emptystat ){
- $score+= $pos["Score_Completion"];
- $dtscore[$IdProject]= $score;
- }
- }
- }
- return $dtscore;
- }
-
- // Display PopUp Share
- // Normal Display, Searching
- public function shares($nopage=""){
- $POST= $this->input->post();
- $Username= $this->session->userdata('Username');
- /*$Username= "posix";*/
-
- $IdShares= array();
- if( isset($POST['IdProject']) ){
- $where= array('Project_ID'=>$POST['IdProject']);
- $project= $this->db->get_where('project', $where)->row_array();
- $IdShares= explode(",", $project['IdShare']);
- }
- /* print_r($IdShares);
- exit;*/
-
- // Get Jumlah Record
- if( isset($POST['search']) ){
- // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
- // dan Username sesuai dengan Key yang di-Inputs
- $sql= "SELECT * FROM user
- WHERE IdUsertype= '5' AND Username LIKE '%" .
- $POST['search'] . "%' AND Username != '" . $Username . "'";
- $jml= $this->db->query($sql)->num_rows();
- }else{
- // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
- $jml= $this->db->get_where('user', array('IdUsertype'=>'5', 'Username !='=>$Username))->num_rows();
- }
-
- /*$jml= $this->db->get_where('user', array('IdUsertype'=>'5'))->num_rows();*/
-
- // Set Offset, PerPage, dan Jumlah Page
- $nopage= ( empty($nopage) ) ? 1 : $nopage;
- $nopage= (int)$nopage-1;
- $perpage= 2;
- $offset= $nopage * $perpage; // Nilai Offset u/ Query
- $jml_page= ceil($jml / $perpage); // Jumlah Halaman
-
- // Jika Halaman lebih dari Jumlah Halaman atau Negatif Value
- if( $nopage >= $jml_page || $nopage < 0 ){
- $nopage= 1;
- }
-
- // Pagination Config
- $base_url= base_url() . 'project/shares/';
- $config['base_url'] = $base_url;
- $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;
- $config['num_links']= $jml_page;
- $config['next_link']= FALSE;
- $this->pagination->initialize($config);
-
- // Create Pagination jika user load untuk First Page
- $pagination= "";
- $data['IdShares']= $IdShares;
- if( isset($POST['search']) ){
- // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
- // dan Username sesuai dengan Key yang di-Inputs
- $sql= "SELECT * FROM user
- WHERE IdUsertype= '5' AND Username LIKE '%" .
- $POST['search'] . "%' AND Username != '" . $Username . "'
- ORDER BY Username ASC
- LIMIT " . $offset . "," . $perpage;
- $sales= $this->db->query($sql)->result_array();
- }else{
- // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
- $this->db->order_by('Username','ASC');
- $sales= $this->db->get_where('user',
- array('IdUsertype'=>'5', 'Username !='=>$Username), $perpage, $offset)->result_array();
- /* echo $this->db->last_query();
- exit;*/
- }
-
- // Display Data
- if( ! isset($POST['type']) ){
- // Ketika PopUp pertama kali dibuka
- $pagination= $this->pagination->create_links();
- $data['pagination']= $pagination;
- $data['sales']= $sales;
- $data['base_url'] = $base_url;
- $popUp= $this->load->view("dialog/shares_project", $data, true);
- echo $popUp;
- }else{
- $html= "";
- foreach( $sales as $sale ){
- $extraAttr= array();
- if( in_array($sale['Username'], $IdShares) ){
- $extraAttr= array('checked'=>'checked');
- }
- $attr_box= array('name'=>'sales_id[]', 'value'=>$sale['Username'], 'class'=>'salesBox');
- $attr_box= array_merge($attr_box, $…
Large files files are truncated, but you can click here to view the full file