PageRenderTime 55ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/project_rev.php

https://bitbucket.org/remobius/coding
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
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Project extends CI_Controller {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->database();
  6. $this->load->helper(array('url', 'captcha', 'download'));
  7. $this->load->library(array('form_validation', 'Themelib', 'Captchalib', 'pagination'));
  8. checkAuth(); // Check Authentikasi User
  9. }
  10. public function server_var(){
  11. foreach( $_SERVER as $key=>$value ){
  12. echo $key . "->" . $value . "<br/>";
  13. }
  14. /* echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "<br/>";
  15. echo site_url();*/
  16. }
  17. // MD5 Function
  18. public function md5(){
  19. echo md5("sales");
  20. exit;
  21. echo 'administrator' . date("Y-m-d H:i:s") . "->" . md5('administrator' . date("Y-m-d H:i:s")) . "<br/>";
  22. echo 'administrator2' . date("Y-m-d H:i:s") . "->" . md5('administrator2' . date("Y-m-d H:i:s"));
  23. }
  24. // Dashboard Page
  25. public function dashboard(){
  26. $config= $this->config;
  27. $data= array();
  28. $data['bar_path']= $config->item('loading');
  29. $data['main_url']= base_url();
  30. $data['jscript']= "";
  31. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  32. $this->themelib->getpage("", $data, "inc/theme_new");
  33. }
  34. public function new_menu(){
  35. $config= $this->config;
  36. $data= array();
  37. $data['bar_path']= $config->item('loading');
  38. $data['main_url']= base_url();
  39. $data['jscript']= "";
  40. /*$data['menu']= $this->load->view("inc/menu.php", $data, TRUE);*/
  41. $this->themelib->getpage("testing", $data, "inc/theme_new");
  42. /*$this->themelib->getpage("testing", $data, "inc/theme_main");*/
  43. }
  44. // Dashboard Page
  45. /* public function sticky_test(){
  46. $config= $this->config;
  47. $data= array();
  48. $data['bar_path']= $config->item('loading');
  49. $data['main_url']= base_url();
  50. $data['jscript']= "";
  51. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  52. $this->themelib->getpage("sticky_test", $data, "inc/theme_main");
  53. }*/
  54. // Notify ToDo ( User Login ) setiap 5 menit
  55. public function notify_todo(){
  56. $Username= $this->session->userdata('Username');
  57. $today= date("Y-m-d H:i:s");
  58. $cur_date= explode(" ", $today);
  59. $date= explode("-", $cur_date[0]);;
  60. $time= explode(":", $cur_date[1]);
  61. list($year, $month, $day)= $date;
  62. list($hour, $minute, $second)= $time;
  63. $last_time= date("Y-m-d H:i:s", mktime($hour, $minute-5, 0, $month, $day, $year));
  64. $now_time= date("Y-m-d H:i:s", mktime($hour, $minute, 0, $month, $day, $year));
  65. $sql= "SELECT * FROM todo
  66. WHERE DueDate BETWEEN '" . $last_time . "' AND '" . $now_time.
  67. "' AND Username='" . $Username . "' AND Status != 'yes'";
  68. $todo= array();
  69. $todo= $this->db->query($sql)->row_array();
  70. /* echo "<pre>";
  71. echo $sql;
  72. echo "</pre>";
  73. exit;*/
  74. if( count($todo) ){
  75. $notifyId= $todo['Id'];
  76. $notify_dt= '<p><a href="' . site_url() . 'project/detail/' . $todo['IdProject'] . '">' . $todo['Task'] .
  77. '</a></p>';
  78. $notify= array(
  79. 'Id'=>$notifyId,
  80. 'Element'=>$notify_dt
  81. );
  82. echo json_encode($notify);
  83. }
  84. exit;
  85. }
  86. // Process Untuk Set Status Complete or Not
  87. public function process_todo(){
  88. $POST= $this->input->post();
  89. $where= array('Id'=>$POST['Id']);
  90. unset($POST['Id']);
  91. if( $this->Jmodel->update('todo', $POST, $where) ){
  92. echo "success";
  93. }
  94. }
  95. // PopUp for Todo pada Halaman Project Detail ( Add, Edit )
  96. // Serta Processing u/ Delete ToDo
  97. public function todo($IdProject="", $action="", $IdTodo= ""){
  98. $config= $this->config;
  99. if( $action == "edit" ) { // PopUp Edit ToDo
  100. $where= array('Id'=>$IdTodo);
  101. $todo= $this->db->get_where('todo', $where)->row_array();
  102. $data= array();
  103. $data['bar_path']= $config->item('loading');
  104. $data['main_url']= base_url();
  105. $data['jscript']= "";
  106. $data['IdProject']= $IdProject;
  107. $data['hrefElement']= site_url() . $this->uri->uri_string();
  108. $data['todo']= $todo;
  109. $html= $this->load->view('todo/edit', $data, TRUE);
  110. echo $html;
  111. exit;
  112. }elseif( $action == "delete" ){ // Delete ToDo
  113. $where= array("Id"=>$IdTodo);
  114. if( $this->db->delete('todo', $where) ){
  115. echo "success";
  116. exit;
  117. }
  118. }else{ // PopUp Add ToDo
  119. $data= array();
  120. $data['bar_path']= $config->item('loading');
  121. $data['main_url']= base_url();
  122. $data['jscript']= "";
  123. $data['IdProject']= $IdProject;
  124. $html= $this->load->view('todo/todo', $data, TRUE);
  125. echo $html;
  126. exit;
  127. }
  128. }
  129. // Display All ToDos dari Login User
  130. public function todo_list(){
  131. /* echo "<pre>";
  132. print_r($late_todos);
  133. echo "</pre>";
  134. exit;*/
  135. $Username= $this->session->userdata('Username');
  136. $todos= array();
  137. $sql= "SELECT a.*, b.Project_Name FROM todo a
  138. LEFT JOIN project b ON b.Project_ID= a.IdProject
  139. WHERE a.Username= '" . $Username . "' AND a.Status= 'no'
  140. ORDER BY a.DueDate DESC";
  141. $todos= $this->db->query($sql)->result_array();
  142. $today= date("d-m-Y");
  143. $today= explode("-", $today);
  144. list($day, $month, $year)= $today;
  145. $today= mktime(0, 0, 0, $month, $day, $year);
  146. $tomorrow= mktime(0, 0, 0, $month, $day+1, $year);
  147. // Grouping ToDos ( Late, Today, Upcoming)
  148. $late_todos= array();
  149. $today_todos= array();
  150. $upcoming_todos= array();
  151. foreach( $todos as $todo ){
  152. $DueDate= strtotime($todo['DueDate']);
  153. if( $DueDate < $today ){
  154. $late_todos[]= $todo;
  155. }elseif( $DueDate >= $tomorrow ){
  156. $upcoming_todos[]= $todo;
  157. }else{
  158. $today_todos[]= $todo;
  159. }
  160. }
  161. $todos['late']= $late_todos;
  162. $todos['today']= $today_todos;
  163. $todos['upcoming']= $upcoming_todos;
  164. $config= $this->config;
  165. $data= array();
  166. $data['bar_path']= $config->item('loading');
  167. $data['main_url']= base_url();
  168. $data['jscript']= $this->load->view('js/todo_list', $data, TRUE);
  169. $data['todos']= $todos;
  170. $this->themelib->getpage("todo/todo_list", $data, "inc/theme_main");
  171. }
  172. // Processing Save, Edit and Delete Todo Data Into Database
  173. public function todo_save($action=""){
  174. $POST= $this->input->post();
  175. // Set Data for inserting to DBase
  176. $POST['Username']= $this->session->userdata('Username');
  177. $POST['DueDate'].= " " . $POST['Hour'] . ":" . $POST['Minutes'] . " " . $POST['IdTime'];
  178. $POST['DueDate']= date("Y-m-d H:i:s", strtotime($POST['DueDate']));
  179. unset($POST['Hour'], $POST['Minutes'], $POST['IdTime'], $POST['submit']);
  180. if( $action == "edit" ){ // Edit ToDo
  181. $POST['ModifyDate']= date("Y-m-d H:i:s");
  182. $IdTodo= $POST['Id'];
  183. $IdProject= $POST['IdProject'];
  184. unset($POST['Id'], $POST['IdProject']);
  185. $where= array('Id'=>$IdTodo);
  186. if( $this->Jmodel->update('todo', $POST, $where) ){
  187. $element= $this->getElementTodo($IdTodo, $IdProject);
  188. $html= array(
  189. 'type'=>'success',
  190. 'html'=>$element
  191. );
  192. echo json_encode($html);
  193. }
  194. }else{ // Save ToDo
  195. $POST['AddDate']= date("Y-m-d H:i:s");
  196. $insertId= $this->Jmodel->insert('todo', $POST, TRUE);
  197. if( $insertId ){
  198. $element= $this->getElementTodo($insertId, $POST['IdProject']);
  199. $html= array(
  200. 'type'=>'success',
  201. 'html'=>$element
  202. );
  203. echo json_encode($html);
  204. }
  205. }
  206. }
  207. // Get Element HTML dari Todo berdasarkan IdTodo
  208. public function getElementTodo($idTodo="", $IdProject=""){
  209. $where= array('Id'=>$idTodo);
  210. $todo= $this->db->get_where('todo', $where)->row_array();
  211. $extraAttr= array();
  212. $labelClass= "";
  213. if( $todo['Status'] == "yes" ){
  214. $extraAttr['checked']= 'checked';
  215. $labelClass= " complete-todos";
  216. }
  217. $attr_checkbox= array(
  218. 'name'=>'todo'.$todo['Id'],
  219. 'value'=>$todo['Id'],
  220. 'class'=>'todos'
  221. );
  222. $attr_checkbox= array_merge($attr_checkbox, $extraAttr);
  223. $html= '
  224. <div class="todos-row">
  225. <span class="btnactions">
  226. <a class="btn todos-btn todos-edit" href="' . site_url("project/todo") . "/" . $IdProject .
  227. '/edit/' . $idTodo . '">
  228. <i class="icon-pencil"></i>
  229. </a>
  230. <a class="btn todos-btn todos-delete" href="' . site_url("project/todo") . "/" . $IdProject .
  231. '/delete/' . $idTodo . '">
  232. <i class="icon-trash"></i>
  233. </a>
  234. </span>
  235. <label class="checkbox checkbox-tags' . $labelClass . '">' .
  236. form_checkbox($attr_checkbox) .
  237. '<span>' . $todo['Task'] . '</span>
  238. <span class="label label-warning">' . date("l, d F Y h:i A", strtotime($todo['DueDate'])) . '</span>' .
  239. '</label>' .
  240. '</div>';
  241. return $html;
  242. }
  243. // Show Employee Detail
  244. public function employee_detail($Username=""){
  245. $Username= urldecode($Username);
  246. // Get Data User Detail
  247. $sql= "SELECT * FROM user a
  248. LEFT JOIN user_detail b ON b.Id= a.IdDetail
  249. WHERE a.Username= '" . $Username . "'";
  250. $user= $this->db->query($sql)->row_array();
  251. // Table Description
  252. $description_user= array('Name'=>'Name', 'Address'=>'Address',
  253. 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
  254. foreach( $description_user as $key=>$value ){
  255. $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
  256. $user[$key]= $userdt;
  257. }
  258. $config= $this->config;
  259. $data= array();
  260. $data['bar_path']= $config->item('loading');
  261. $data['jscript']= $this->load->view('js/profile', $data, TRUE);
  262. $data['img_path']= $config->item('img_path');
  263. $data['description_user']= $description_user;
  264. $data['user']= $user;
  265. $this->themelib->getpage("user/profile", $data, "inc/theme_main");
  266. }
  267. // Show List of Employees
  268. public function employees($nopage=""){
  269. /* echo "<pre>";
  270. print_r($jml);
  271. echo "</pre>";
  272. exit;*/
  273. // Get Seluruh Data Employees
  274. $jml= $this->Jmodel->getEmployees(TRUE);
  275. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  276. $nopage= (int)$nopage-1;
  277. $perpage= 12;
  278. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  279. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  280. // Jika Halaman lebih dari Jumlah Halaman atau Negatif Value
  281. if( $nopage >= $jml_page || $nopage < 0 ){
  282. redirect("employees/1"); // Redirect ke First Page
  283. }
  284. // Pagination Config
  285. $config['base_url'] = site_url() . 'employees';
  286. $config['total_rows'] = $jml;
  287. $config['per_page'] = $perpage;
  288. $config['use_page_numbers'] = FALSE;
  289. $config['uri_segment']= 2; // Pengenal URI Active Page
  290. $config['first_url']= 1;
  291. $this->pagination->initialize($config);
  292. // Get Data Project from DB sesuai dengan current Page
  293. $employees= $this->Jmodel->getEmployees("", $perpage, $offset);
  294. $description= array("Name", "Description");
  295. $config= $this->config;
  296. $data= array();
  297. $data['bar_path']= $config->item('loading');
  298. $data['jscript']= "";
  299. $data['img_path']= $config->item('img_path');
  300. $data['employees']= $employees;
  301. $data['description']= $description;
  302. $data['pagination']= $this->pagination->create_links();
  303. $this->themelib->getpage("employees", $data, "inc/theme_main");
  304. }
  305. // Halaman Edit Profile Detail
  306. public function edit_profile($Username=""){
  307. if( ! empty($Username) ){
  308. $Username= urldecode($Username);
  309. }else{
  310. $Username= $this->session->userdata('Username');
  311. }
  312. $Id= $this->session->userdata('Id');
  313. // Get Data User Detail
  314. $sql= "SELECT * FROM user a
  315. LEFT JOIN user_detail b ON b.Id= a.IdDetail
  316. WHERE a.Username= '" . $Username . "'";
  317. $user= $this->db->query($sql)->row_array();
  318. // Table Description
  319. $labels= array('Name'=>'Nama', 'Address'=>'Alamat', 'Gender'=>'Jenis Kelamin',
  320. 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak', 'Image'=>'Gambar');
  321. $feedback= "";
  322. if( empty($user) ){
  323. $feedback= "User " . $Username . " tidak ada.";
  324. }
  325. /* echo "<pre>";
  326. print_r($user);
  327. echo "</pre>";
  328. exit;*/
  329. $config= $this->config;
  330. $data= array();
  331. $data['bar_path']= $config->item('loading');
  332. $data['jscript']= "";
  333. $data['img_path']= $config->item('img_path');
  334. $data['user']= $user;
  335. $data['labels']= $labels;
  336. $data['feedback']= $feedback;
  337. $data['userId']= $Id;
  338. echo $this->load->view("user/edit_profile", $data, TRUE);
  339. /*$this->themelib->getpage("user/edit_profile", $data, "inc/theme_main");*/
  340. }
  341. // Halaman View Profile Detail
  342. public function profile($type=""){
  343. if( empty($type) ){
  344. $Username= $this->session->userdata('Username');
  345. // Get Data User Detail
  346. $sql= "SELECT * FROM user a
  347. LEFT JOIN user_detail b ON b.Id= a.IdDetail
  348. WHERE a.Username= '" . $Username . "'";
  349. $user= $this->db->query($sql)->row_array();
  350. // Table Description
  351. $description_user= array('Name'=>'Name', 'Address'=>'Address',
  352. 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
  353. foreach( $description_user as $key=>$value ){
  354. $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
  355. $user[$key]= $userdt;
  356. }
  357. /* echo "<pre>";
  358. print_r($user_detail);
  359. echo "</pre>";
  360. exit;*/
  361. $config= $this->config;
  362. $data= array();
  363. $data['bar_path']= $config->item('loading');
  364. $data['jscript']= $this->load->view('js/profile', $data, TRUE);
  365. $data['img_path']= $config->item('img_path');
  366. $data['description_user']= $description_user;
  367. $data['user']= $user;
  368. $this->themelib->getpage("user/profile", $data, "inc/theme_main");
  369. }else{
  370. /*sleep(3);*/
  371. $POST= $this->input->post();
  372. /* print_r($_FILES);
  373. exit;*/
  374. foreach( $_FILES as $key=>$value ){
  375. $$key= $value;
  376. }
  377. $act_image= FALSE;
  378. if( !empty($Image['name']) ){
  379. // File Image tidak boleh lebih dari 2MB
  380. $maxsize= 2000000;
  381. if( $Image['size'] > $maxsize ){
  382. echo "File tidak boleh lebih dari 2MB !";
  383. exit;
  384. }
  385. // Cek Extension
  386. $image_ext= pathinfo($Image['name'], PATHINFO_EXTENSION);
  387. $reg_image= "#^(jpeg|jpg|png)$#";
  388. if( ! preg_match($reg_image, $image_ext) ){
  389. echo "File harus gambar ( jpeg|jpg|png ) !";
  390. exit;
  391. }
  392. $Username= $this->session->userdata('Username');
  393. $filename= $Username . "_avatar." . $image_ext;
  394. $tmp_file= $Image['tmp_name'];
  395. $fullpath= $this->config->item('assets_img') . "user/" . $filename;
  396. if( move_uploaded_file($tmp_file, $fullpath) ){
  397. $config['image_library'] = 'gd2';
  398. $config['source_image'] = $fullpath;
  399. $config['create_thumb'] = FALSE;
  400. $config['maintain_ratio'] = FALSE;
  401. $config['width'] = 200;
  402. $config['height'] = 200;
  403. $this->load->library('image_lib', $config);
  404. // Resize Image
  405. if( ! $this->image_lib->resize() ){
  406. echo "Resize File tidak berhasil. Silakan Coba Lagi !";
  407. exit;
  408. }else{
  409. $act_image= TRUE;
  410. }
  411. }else{
  412. echo "Error terjadi, Silakan coba lagi !";
  413. exit;
  414. }
  415. }
  416. if( $act_image ){
  417. $POST['Image']= $filename;
  418. }
  419. /*$POST['Id']= '10';*/
  420. $POST['DateOfBirth']= ( empty($POST['DateOfBirth']) ) ? "" : date('Y-m-d', strtotime($POST['DateOfBirth']));
  421. /*$POST['DateOfBirth']= date('Y-m-d', strtotime($POST['DateOfBirth']));*/
  422. $sql= "SELECT * FROM user a
  423. INNER JOIN user_detail b ON b.Id= a.IdDetail
  424. WHERE a.Id= '" . $POST['Id'] . "'";
  425. $row= $this->db->query($sql)->row_array();
  426. if( empty($row) ){
  427. // Insert Data to user_detail
  428. $ins_detail= $POST;
  429. unset($ins_detail['Username'], $ins_detail['Id']);
  430. $insert_id= $this->Jmodel->insert('user_detail', $POST, TRUE);
  431. $ins_user= array('IdDetail'=>$insert_id);
  432. $where= array('Id'=>$POST['Id']);
  433. $this->Jmodel->update('user', $ins_user, $where);
  434. }else{
  435. // Insert Data to user_detail
  436. $upd_detail= $POST;
  437. unset($upd_detail['Id']);
  438. $where= array('Id'=>$POST['Id']);
  439. $insert_id= $this->Jmodel->update('user_detail', $upd_detail, $where);
  440. }
  441. echo "success";
  442. exit;
  443. }
  444. }
  445. // Remove Tag / Untag
  446. public function untag(){
  447. $POST= $this->input->post();
  448. // Cek Apa Tag tsb di-tag pada Project
  449. $where= array('Project_ID'=>$POST['IdProject']);
  450. $sql= "SELECT * FROM project
  451. WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag LIKE '%" . $POST['IdTag'] . "%'";
  452. $query= $this->db->query($sql);
  453. $row= $query->row_array();
  454. // Remove Tag
  455. $IdTag= array();
  456. $IdTag= $row['IdTag'];
  457. $IdTag= array_flip(explode(",", $IdTag));
  458. unset($IdTag[$POST['IdTag']]);
  459. $IdTag= array_flip($IdTag);
  460. // Update DBase
  461. $data= array('IdTag'=>implode(",",$IdTag));
  462. if( $this->Jmodel->update('project', $data, $where) ){
  463. echo "success";
  464. exit;
  465. };
  466. /* echo "<pre>";
  467. print_r($IdTag);
  468. echo "</pre>";
  469. exit; */
  470. }
  471. // Add Tag to Project
  472. public function tag(){
  473. $POST= $this->input->post();
  474. // Get Data IdTag Field Sebelumnya
  475. /*$POST['IdProject']= '46';*/
  476. $where= array('Project_ID'=>$POST['IdProject']);
  477. $sql= "SELECT * FROM project
  478. WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag NOT LIKE '%" . $POST['IdTag'] . "%'";
  479. $query= $this->db->query($sql);
  480. $row= $query->row_array();
  481. // Jika tidak kosong tambahkan dengan data sebelumnya
  482. if( ! empty($row['IdTag']) ){
  483. $POST['IdTag']= $row['IdTag'] . "," . $POST['IdTag'];
  484. }
  485. // Update
  486. unset($POST['IdProject']);
  487. if( $this->Jmodel->update('project', $POST, $where) ){
  488. echo "success";
  489. exit;
  490. }
  491. /* echo "<pre>";
  492. print_r($POST);
  493. echo "</pre>";
  494. exit;*/
  495. }
  496. // View Untuk Add New Tag ( ColorPicker )
  497. public function addtag(){
  498. $config= $this->config;
  499. $data= array();
  500. $data['bar_path']= $config->item('loading');
  501. $data['main_url']= base_url();
  502. $html= $this->load->view("tag/create", $data, TRUE);
  503. echo $html;
  504. /*$this->themelib->getpage("tag/create", $data, "inc/theme_main");*/
  505. }
  506. // Get Current Tag yang baru di-create
  507. public function get_tag(){
  508. $POST= $this->input->post();
  509. $POST['tagName']= strtoupper($POST['tagName']);
  510. // Get Current Tag yang baru di-create
  511. $where= array('tagName'=>$POST['tagName']);
  512. $tag= $this->db->get_where('tag', $where)->row_array();
  513. // Create Group Checkbox Tag
  514. $attr_checkbox= array(
  515. 'name'=>$tag['tagName'].'[name]',
  516. 'value'=>$tag['tagName'],
  517. 'class'=>'tags'
  518. );
  519. $prev_tags= '<label class="checkbox">';
  520. $prev_tags.= form_checkbox($attr_checkbox);
  521. $prev_tags.= form_hidden($tag['tagName'].'[color]', $tag['tagColor']);
  522. $prev_tags.= $tag['tagName'];
  523. $prev_tags.= '</label>';
  524. echo $prev_tags;
  525. /* $tags= $this->db->get("tag")->result_array();
  526. $prev_tags= "";
  527. foreach( $tags as $tag ){
  528. $prev_tags.= '<label class="checkbox">' .
  529. '<input type="checkbox" name="tagName" value="' . $tag['tagName'] . '">' . $tag['tagName'] .
  530. '</label>';
  531. }*/
  532. /*echo json_encode($tags);*/
  533. }
  534. // Save / Process to Database
  535. public function savetag(){
  536. $POST= $this->input->post();
  537. $POST['tagName']= strtoupper($POST['tagName']);
  538. /* echo "<pre>";
  539. print_r($POST);
  540. echo "</pre>";
  541. exit;*/
  542. // Check Apakah Tag Name sudah digunakan
  543. $where= array('tagName'=>$POST['tagName']);
  544. if( $this->db->get_where('tag', $where)->num_rows() ){
  545. echo "Tag dengan nama tersebut sudah ada.";
  546. exit;
  547. }
  548. // Insert to Database
  549. if( $this->Jmodel->insert('tag', $POST) ){
  550. echo "success";
  551. exit;
  552. }
  553. }
  554. // Add New Tag ( ColorPicker )
  555. public function colorPicker(){
  556. $config= $this->config;
  557. $data= array();
  558. $data['bar_path']= $config->item('loading');
  559. $data['main_url']= base_url();
  560. $this->themelib->getpage("test", $data, "inc/theme_main");
  561. }
  562. // Get List Of Template
  563. public function template_all($param="page", $nopage="", $sorting=""){
  564. $POST= $this->input->post();
  565. $url= explode("&", $sorting);
  566. // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
  567. // Set Filter Searching
  568. $sorting= $url[0];
  569. $filter_url= ( isset($url[1]) ) ? $url[1] : "";
  570. $filter_str= ""; //
  571. if( isset($POST['btnSubmit']) ){
  572. // Set Limit to default
  573. $nopage= 1;
  574. // Set Filter properties dan set $filter_str untuk dimasukan ke url pagination
  575. $filter= array('field'=>$POST['search'], 'op'=>$POST['op_search'], 'key'=>$POST['search_key']);
  576. foreach( $filter as $key=>$value ){
  577. $filter[$key]= urlencode($value);
  578. }
  579. $filter_str= implode("+", $filter);
  580. }else{
  581. // Set Filter dari Pagination Url
  582. $filter= "";
  583. if( ! empty($filter_url) ){
  584. $filter_str= $filter_url;
  585. $filter_url= explode("+", $filter_url);
  586. $filter= array('field'=>$filter_url[0], 'op'=>$filter_url[1], 'key'=>$filter_url[2]);
  587. }
  588. }
  589. // Set Default / Sorting
  590. $sorting= ( empty($sorting) ) ? "Name=ASC" : urldecode($sorting);
  591. $sort= explode("=", $sorting);
  592. /* echo "<pre>";
  593. print_r($filter);
  594. echo "</pre>";*/
  595. // Get Jumlah Project List
  596. $jml= $this->Jmodel->getData("project_template", "", "", $sort, $filter, true);
  597. // Process Per-page dan Offset
  598. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  599. $numpage= $nopage;
  600. $nopage= (int)$nopage-1;
  601. $perpage= 5;
  602. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  603. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  604. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  605. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  606. // dan tidak Ada $POST Searching
  607. if( ( $numpage > $jml_page || $numpage < 1 ) && ! isset($POST['btnSubmit']) ){
  608. /*if( $numpage < 1 ){*/
  609. redirect("project/template_all");
  610. }
  611. // Pagination Config
  612. $config['base_url'] = base_url() . 'project/template_all/page';
  613. $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
  614. $config['total_rows'] = $jml;
  615. $config['per_page'] = $perpage;
  616. $config['use_page_numbers'] = FALSE;
  617. $config['uri_segment']= 4; // Pengenal URI Active Page
  618. $config['first_url']= 1;
  619. $this->pagination->initialize($config);
  620. // Get Data Project from DB sesuai dengan current Page
  621. $rows= $this->Jmodel->getData("project_template", $perpage, $offset, $sort, $filter);
  622. $list= array();
  623. if( ! empty($rows) ){
  624. // Get IdTemplate Untuk SQL Condition
  625. $data_in= array();
  626. foreach( $rows as $row ){
  627. $data_in[]= $row['Id'];
  628. }
  629. $IdTemplate= "'" . implode("','", $data_in) . "'";
  630. // Get Seluruh Data template dan project process
  631. $sql= "SELECT * FROM project_template a
  632. LEFT JOIN pos_menu b ON b.IdTemplate= a.Id
  633. WHERE a.Id IN(" . $IdTemplate . ") {condition}
  634. ORDER BY {sorting}, b.Urutan";
  635. $rows= $this->Jmodel->getData("", $perpage, $offset, $sort, $filter, false, $sql);
  636. // Modify List untuk dipakai pada Perulangan
  637. foreach( $rows as $row ){
  638. $list[$row['Name']][]= $row;
  639. }
  640. }
  641. // Fields for Searching Filter
  642. $fields= array(
  643. 'Name'=>'Template Name'
  644. );
  645. $operator= $this->themelib->operator_search; // Get Operator Searching
  646. /* echo "<pre>";
  647. print_r($list);
  648. echo "</pre>";
  649. exit;*/
  650. $rows= array();
  651. $config= $this->config;
  652. $data= array();
  653. $data['bar_path']= $config->item('loading');
  654. $data['main_url']= base_url();
  655. $data['jscript']= '';
  656. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  657. $data['rows']= $list;
  658. $data['pagination']= $this->pagination->create_links();
  659. $data['hrefNewProject']= site_url() . "project/template";
  660. $data['baseurl_sort']= site_url() . "project/template_all";
  661. $data['searching_fields']= $fields;
  662. $data['operator']= $operator;
  663. $this->themelib->getpage("project/template_all", $data, "inc/theme_main");
  664. }
  665. // Create New / Edit Project Template
  666. // Halaman Ini Mengirimkan POST serta Pengeditan pada Halaman dengan Javascript Enabled
  667. public function template($action="", $templateName= ""){
  668. if( $action == "edit" ){
  669. // Get Data Template
  670. $where= array('Name'=>urldecode($templateName));
  671. $template= $this->db->get_where("project_template", $where)->row_array();
  672. // Get Data Step Process
  673. $where= array('IdTemplate'=>$template['Id']);
  674. $this->db->order_by('Urutan ASC');
  675. $process= $this->db->get_where("pos_menu", $where)->result_array();
  676. /* echo "<pre>";
  677. print_r($template);
  678. print_r($process);
  679. echo "</pre>";
  680. exit; */
  681. $config= $this->config;
  682. $data= array();
  683. $data['bar_path']= $config->item('loading');
  684. $data['main_url']= base_url();
  685. $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
  686. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  687. $data['template']= $template;
  688. $data['process']= $process;
  689. $this->themelib->getpage("project/template_edit", $data, "inc/theme_main");
  690. }else{
  691. $config= $this->config;
  692. $data= array();
  693. $data['bar_path']= $config->item('loading');
  694. $data['main_url']= base_url();
  695. $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
  696. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  697. $this->themelib->getpage("project/template", $data, "inc/theme_main");
  698. }
  699. }
  700. // Edit And Delete Template
  701. public function action_template($action){
  702. $POST= $this->input->post();
  703. echo "<pre>";
  704. print_r($POST);
  705. echo "</pre>";
  706. exit;
  707. if( $action == "edit" ){
  708. // Menambah Field Urutan Pada Process POST yang dikirim
  709. $urutan= 1;
  710. foreach( $POST['process'] as $key=>$process ){
  711. $updatePost= array();
  712. if( is_array($process) ){
  713. $updatePost= $process;
  714. $updatePost['Urutan']= $urutan;
  715. $POST['process'][$key]= $updatePost;
  716. }else{
  717. $updatePost['Name']= $process;
  718. $updatePost['Urutan']= $urutan;
  719. $POST['process'][$key]= $updatePost;
  720. }
  721. $urutan++;
  722. }
  723. // Get Existing Process Step
  724. $process= array();
  725. $prevProcess= array();
  726. $newProcess= array();
  727. foreach( $POST['process'] as $key=>$list ){
  728. if( isset($list['Id']) ){
  729. $prevProcess[$key]= $list;
  730. }else{
  731. $newProcess[]= $list;
  732. }
  733. }
  734. // Get Previous Process di DBase
  735. $where= array('IdTemplate'=>$POST['template']['Id']);
  736. $dbProcess= $this->db->get_where('pos_menu', $where)->result_array();
  737. // Get Data Process yang Harus di-Delete
  738. $delProcess= array();
  739. foreach( $dbProcess as $process ){
  740. if( ! array_key_exists($process['Id'], $prevProcess) ){
  741. $this->db->delete('pos_menu', array('Id'=>$process['Id']));
  742. $delProcess[]= $process;
  743. }
  744. /* if( array_key_exists($process['Id'], $prevProcess) ){
  745. echo "ex-" . $process['Process_Name'] . "\n";
  746. }else{
  747. $delProcess[]= $process;
  748. echo "del-" . $process['Process_Name'] . "\n";
  749. }*/
  750. }
  751. $process= array();
  752. foreach( $newProcess as $key=>$list ){
  753. $dtproc= array();
  754. $dtproc['Process_Name']= $list['Name'];
  755. $dtproc['Urutan']= $list['Urutan'];
  756. $dtproc['Score_Completion']= $POST['score'][$key];
  757. $dtproc['IdTemplate']= $POST['template']['Id'];
  758. $process[]= $dtproc;
  759. }
  760. // Update Previous Process
  761. $dtUpdate= array();
  762. foreach( $prevProcess as $list ){
  763. $dtUpdate['Process_Name']= $list['Name'];
  764. $dtUpdate['Score_Completion']= $list['Score'];
  765. $dtUpdate['Urutan']= $list['Urutan'];
  766. $where= array('Id'=>$list['Id']);
  767. $this->Jmodel->update('pos_menu', $dtUpdate, $where);
  768. }
  769. // Insert New Process
  770. foreach( $process as $list ){
  771. $this->Jmodel->insert('pos_menu', $list);
  772. }
  773. if( $POST['type'] == "ajax" ){
  774. echo "success";
  775. exit;
  776. }
  777. /* echo "<pre>";
  778. print_r($process);
  779. print_r($prevProcess);
  780. print_r($newProcess);
  781. print_r($delProcess);
  782. echo "</pre>";
  783. exit;*/
  784. }else{
  785. }
  786. }
  787. // Create New Project Template
  788. public function create_template(){
  789. $POST= $this->input->post();
  790. echo "<pre>";
  791. print_r($POST);
  792. echo "</pre>";
  793. exit;
  794. // Cek Jika Template dengan Nama tsb tidak Ada
  795. $template= array('Name'=>$POST['template_name']);
  796. if( $this->db->get_where('project_template', $template)->num_rows() ){
  797. if( $POST['type'] == "ajax" ){
  798. echo "Template dengan nama tersebut sudah Ada !";
  799. exit;
  800. }else{
  801. $this->session->set_userdata('error', 'Template dengan nama tersebut sudah Ada !');
  802. redirect('project/template_all');
  803. }
  804. }
  805. // Gabungkan Array Process dan Score
  806. $posmenu= array();
  807. $urut= 1;
  808. foreach( $POST['process'] as $key=>$value ){
  809. $posmenu[$key]= array('Process_Name'=>$value, 'Score_Completion'=>$POST['score'][$key], 'Urutan'=>$urut);
  810. $urut++;
  811. }
  812. // Insert Template to Database
  813. $template= array('Name'=>$POST['template_name']);
  814. $insert_id= $this->Jmodel->insert("project_template", $template, true);
  815. if( $insert_id ){
  816. foreach( $posmenu as $row ){
  817. $row['IdTemplate']= $insert_id;
  818. $this->Jmodel->insert('pos_menu', $row);
  819. }
  820. }
  821. if( $POST['type'] == "ajax" ){
  822. echo "success";
  823. exit;
  824. }else{
  825. redirect('project/template_all');
  826. }
  827. }
  828. public function getPassword(){
  829. $this->load->view("");
  830. echo md5('sales_admin');
  831. }
  832. public function select_template(){
  833. $rows= $this->db->get('project_template')->result_array();
  834. $template= array();
  835. $template[""]= "-- Select --";
  836. foreach( $rows as $row ){
  837. $template[$row['Id']]= $row['Name'];
  838. }
  839. $config= $this->config;
  840. $data= array();
  841. $data['bar_path']= $config->item('loading');
  842. $data['main_url']= base_url();
  843. $data['jscript']= $this->load->view("js/select_template.php", $data, TRUE);
  844. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  845. $data['template']= $template;
  846. $data['hrefAction']= base_url() . "setting/summary";
  847. $this->themelib->getpage("project/select_template", $data, "inc/theme_main");
  848. }
  849. // Create And Edit Setting Summary
  850. // @param1 string berisi 'summary',
  851. // @param2 int berisi IdTemplate u/ ByPass Ketika User klik Save Redirect Langsung ke halaman Ini
  852. public function setting($param="", $IdTemplate=""){
  853. $POST= $this->input->post();
  854. if( ! empty($POST) ){
  855. extract($POST);
  856. }
  857. // Jika Tidak Ada IdTemplate Redirect untuk select Template
  858. if( ! isset($IdTemplate) || empty($IdTemplate) ){
  859. redirect("project/select_template");
  860. }
  861. // Get Previous Setting Summary
  862. $Username= $this->session->userdata("Username");
  863. $where= array("Username"=>$Username, "IdTemplate"=>$IdTemplate);
  864. $rows= $this->db->get_where("summary", $where)->result_array();
  865. if( count($rows) ){
  866. $summaries= array();
  867. foreach( $rows as $row ){
  868. $summaryFields= unserialize($row['summaryFields']);
  869. $summaries[$row['Posmenu_ID']]= $summaryFields;
  870. }
  871. }
  872. // Get Seluruh Field pada setiap Process berdasarkan Template Yang di-Select
  873. $sql= "SELECT a.Id AS IdProcess, a.Process_Name, a.Table, b.* FROM pos_menu a
  874. LEFT JOIN form_fields b ON b.FormID= a.FormID
  875. WHERE ( b.Name!= 'Project_ID' OR b.Name IS NULL ) AND a.IdTemplate= '" . $IdTemplate . "'
  876. ORDER BY a.Id";
  877. $rows= $this->db->query($sql)->result_array();
  878. $process= array();
  879. $description= array();
  880. foreach( $rows as $row ){
  881. if( !empty($row["Name"]) ){
  882. $process[$row["IdProcess"]][]= $row;
  883. $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
  884. $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
  885. }else{
  886. $process[$row["IdProcess"]]= array();
  887. $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
  888. $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
  889. }
  890. }
  891. /* echo "<pre>";
  892. print_r($POST);
  893. print_r($description);
  894. echo "</pre>";
  895. exit;*/
  896. $config= $this->config;
  897. $data= array();
  898. $data['bar_path']= $config->item('loading');
  899. $data['main_url']= base_url();
  900. $data['jscript']= "";
  901. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  902. $data["process"]= $process;
  903. $data["description"]= $description;
  904. $data['summaries']= ( isset($summaries) ) ? $summaries : "";
  905. $data['IdTemplate']= $IdTemplate;
  906. $this->themelib->getpage("project/setting_summary", $data, "inc/theme_main");
  907. }
  908. // Processing Summary
  909. public function set_summary(){
  910. /* echo "<pre>";
  911. print_r($jml);
  912. echo "</pre>";
  913. exit;*/
  914. $POST= $this->input->post();
  915. $Username= $this->session->userdata("Username");
  916. $IdTemplate= $POST['IdTemplate'];
  917. // Check If Data is exist remove it first
  918. $jml= $this->db->get_where('summary', array('Username'=>$Username, 'IdTemplate'=>$IdTemplate))->num_rows();
  919. if( $jml ){
  920. $this->db->where(array('Username'=>$Username, 'IdTemplate'=>$IdTemplate));
  921. $this->db->delete('summary');
  922. }
  923. // Insert Score
  924. $scoreData= array();
  925. $scoreData['Username']= $Username;
  926. $scoreData['summaryFields']= serialize($POST['score']);
  927. $scoreData['Posmenu_ID']= '0';
  928. $scoreData['IdTemplate']= $IdTemplate;
  929. $this->Jmodel->insert("summary", $scoreData);
  930. // Insert Semua Data Summary ke Tabel summary
  931. foreach( $POST['Process'] as $key=>$process ){
  932. $insData= array();
  933. $insData['Username']= $Username;
  934. $insData['summaryFields']= serialize($process);
  935. $insData['Posmenu_ID']= $key;
  936. $insData['IdTemplate']= $IdTemplate;
  937. $this->Jmodel->insert("summary", $insData);
  938. }
  939. // Set Feedback and Redirect
  940. $this->session->set_userdata('feedback','The changes has been saved !');
  941. redirect("project/setting/summary/" . $IdTemplate);
  942. }
  943. public function getdata(){
  944. $data= $this->db->get_where("project_process", array("Id"=>"3"))->row_array();
  945. $row= unserialize($data["formValue"]);
  946. echo "<pre>";
  947. print_r($row);
  948. echo "</pre>";
  949. }
  950. // Create Project
  951. public function index($params=""){
  952. $rows= $this->db->get('project_template')->result_array();
  953. $template= array();
  954. $template[""]= "-- Select --";
  955. foreach( $rows as $row ){
  956. $template[$row['Id']]= $row['Name'];
  957. }
  958. /* echo "<pre>";
  959. print_r($template);
  960. echo "</pre>";
  961. exit;*/
  962. $config= $this->config;
  963. $data= array();
  964. $data['bar_path']= $config->item('loading');
  965. $data['main_url']= base_url();
  966. $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
  967. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  968. $data['template']= $template;
  969. $POST= $this->input->post();
  970. if( isset($POST["submit"]) || $POST["type"] == "ajax" ){
  971. // Set Rules Validasi
  972. $config= array(
  973. array(
  974. 'field'=> 'Project_Name',
  975. 'label'=> 'Project Name',
  976. 'rules'=> 'required'
  977. ),
  978. array(
  979. 'field'=> 'Identitas_Perusahaan',
  980. 'label'=> 'Identitas Perusahaan',
  981. 'rules'=> 'required'
  982. )
  983. );
  984. $this->form_validation->set_rules($config);
  985. if( $this->form_validation->run() == TRUE ){ // Cek Validasi
  986. $type= isset($POST["type"]) ? $POST["type"] : "";
  987. // Set Data
  988. $POST["Username"]= $this->session->userdata("Username");
  989. // Cek Project Name ada atau tidak dengan GroupName tsb
  990. // karena ada 2 User Type yaitu Admin dan Sales yang bisa mengakses project yg sama
  991. $where= array("Username"=>$POST["Username"], "Project_Name"=>$POST["Project_Name"]);
  992. $exist= $this->db->get_where("project", $where)->num_rows();
  993. if( ! $exist ){
  994. unset($POST["submit"], $POST["type"]); // Unset Data
  995. // Insert Data to DB
  996. if( $this->db->insert("project", $POST) ){
  997. if( $type == "ajax" ){
  998. echo "success";
  999. exit;
  1000. }else{
  1001. $this->session->set_userdata("error_ot","Data has been saved.");
  1002. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1003. }
  1004. }
  1005. }else{
  1006. if( $type == "ajax" ){
  1007. echo "Project Name is already exist.";
  1008. exit;
  1009. }else{
  1010. $this->session->set_userdata("error_ot","Project Name is already exist.");
  1011. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1012. }
  1013. }
  1014. }else{
  1015. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1016. }
  1017. }
  1018. else{
  1019. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1020. }
  1021. }
  1022. /* public function formBuilder(){
  1023. $config= $this->config;
  1024. $data= array();
  1025. $data['bar_path']= $config->item('loading');
  1026. $data['main_url']= base_url();
  1027. $data['jscript']= $this->load->view("js/formbuilder.php", $data, TRUE);
  1028. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1029. $this->themelib->getpage("formbuilder", $data);
  1030. }
  1031. public function formBuilder_create(){
  1032. $POST= $this->input->post();
  1033. $config= $this->config;
  1034. $data= array();
  1035. // Cek Data pada Tabel masterform
  1036. $where= array("FormID"=>$POST["FormID"]);
  1037. $jml= $this->db->get_where("masterform", $where)->num_rows();
  1038. if( ! $jml ){ // Jika Data tidak Ada Insert data tsb
  1039. // Insert Data ke Tabel masterform
  1040. $form= array("FormID"=>$POST["FormID"], "ActionUrl"=>"#");
  1041. $this->db->insert("masterform", $form);
  1042. // Insert Data ke Tabel form_fields
  1043. $fields= $POST;
  1044. unset($fields["submit"], $fields["FormID"]);
  1045. foreach( $fields as $key=>$field ){
  1046. $insfield= array();
  1047. $insfield["FormID"]= $POST["FormID"];
  1048. $insfield["Name"]= $key;
  1049. if( $key == "Project_ID" ){
  1050. $insfield["FieldType"]= $field;
  1051. }else{
  1052. $data= explode("~", $field);
  1053. $insfield["FieldType"]= $data[0];
  1054. $insfield["Label"]= $data[1];
  1055. }
  1056. $this->db->insert("form_fields", $insfield);
  1057. }
  1058. redirect("project/formBuilder");
  1059. }else{ // Jika Data Ada Redirect dan display error
  1060. $this->session->set_userdata("error", "Form dengan ID tersebut sudah Ada.");
  1061. redirect("project/formBuilder");
  1062. }
  1063. }
  1064. */
  1065. // Create Project
  1066. public function edit($IdProject=""){
  1067. // Check Project
  1068. $where= array("Project_ID"=>$IdProject);
  1069. $query= $this->db->get_where("project", $where);
  1070. $jml= $query->num_rows();
  1071. if( empty($jml) ){
  1072. redirect("project/daftar");
  1073. }else{
  1074. $config= $this->config;
  1075. $data= array();
  1076. $data['bar_path']= $config->item('loading');
  1077. $data['main_url']= base_url();
  1078. $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
  1079. /*$data['jscript']= "";*/
  1080. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1081. $data['row']= $query->row_array();
  1082. $this->db->flush_cache();
  1083. $this->themelib->getpage("project/edit", $data, "inc/theme_main");
  1084. }
  1085. }
  1086. public function daftar($param="page", $nopage="", $sorting=""){
  1087. // Get Jumlah Baris dari tabel Project dengan GroupName yang sama
  1088. $Username= $this->session->userdata("Username");
  1089. /*$Username= "sales";*/
  1090. $POST= $this->input->post();
  1091. $url= explode("&", $sorting);
  1092. // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
  1093. // Set Filter Searching
  1094. $sorting= $url[0];
  1095. $filter_url= ( isset($url[1]) ) ? $url[1] : "";
  1096. $filter_str= ""; //
  1097. if( isset($POST['btnSubmit']) ){
  1098. // Set Limit to default
  1099. $nopage= 1;
  1100. // Set Filter properties dan set $filter_str untuk dimasukan ke url pagination
  1101. $filter= array('field'=>$POST['search'], 'op'=>$POST['op_search'], 'key'=>$POST['search_key']);
  1102. foreach( $filter as $key=>$value ){
  1103. $filter[$key]= urlencode($value);
  1104. }
  1105. $filter_str= implode(":", $filter);
  1106. }else{
  1107. // Set Filter dari Pagination Url
  1108. $filter= "";
  1109. if( ! empty($filter_url) ){
  1110. $filter_str= $filter_url;
  1111. $filter_url= explode(":", $filter_url);
  1112. $filter= array('field'=>$filter_url[0], 'op'=>$filter_url[1], 'key'=>$filter_url[2]);
  1113. }
  1114. }
  1115. // Set Default / Sorting
  1116. $sorting= ( empty($sorting) ) ? "Project_Name=ASC" : urldecode($sorting);
  1117. $sort= explode("=", $sorting);
  1118. // Get Jumlah Project List
  1119. $rows= $this->Jmodel->getProjectByUsertype($Username, "", "", "", $filter, TRUE);
  1120. $jml= count($rows);
  1121. /* if( empty($jml) ){
  1122. redirect("project");
  1123. }*/
  1124. // Get Offset, Jumlah Page
  1125. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  1126. $numpage= $nopage; // Get Number Page from URL
  1127. $nopage= (int)$nopage-1;
  1128. $perpage= 5;
  1129. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  1130. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  1131. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  1132. // dan tidak Ada $POST Searching
  1133. if( ( $numpage > $jml_page || $numpage < 1 ) && ! empty($jml_page) && ! isset($POST['btnSubmit']) ){
  1134. redirect("project/daftar"); // Redirect ke First Page
  1135. }
  1136. // Pagination Config
  1137. $config['base_url'] = site_url('project/daftar/page');
  1138. $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
  1139. $config['total_rows'] = $jml;
  1140. $config['per_page'] = $perpage;
  1141. $config['use_page_numbers'] = FALSE;
  1142. $config['uri_segment']= 4; // Pengenal URI Active Page
  1143. $config['first_url']= 1;
  1144. $this->pagination->initialize($config);
  1145. // Get Data Project from DB sesuai dengan current Page
  1146. $getRows= $this->Jmodel->getProjectByUsertype($Username, $perpage, $offset, $sort, $filter);
  1147. // Set Project_Id sebagai Key
  1148. $rows= array();
  1149. foreach( $getRows as $list ){
  1150. $rows[$list['Project_ID']]= $list;
  1151. }
  1152. // Get Summary untuk setiap Project dan di Group Berdasarkan IdTemplate
  1153. // Group Score Berdasarkan IdTemplate
  1154. $dtsummaries= $this->db->get_where('summary', array('Username'=>$Username))->result_array();
  1155. $getsummaries= array();
  1156. $statScore= array();
  1157. foreach( $dtsummaries as $summary ){
  1158. if( $summary['Posmenu_ID'] == "0" ){
  1159. $statScore[$summary['IdTemplate']][]= unserialize($summary['summaryFields']);
  1160. continue;
  1161. }
  1162. $getsummaries[$summary['IdTemplate']][]= $summary;
  1163. }
  1164. // Get summaries and formValue
  1165. $values= array();
  1166. $summaries= array();
  1167. $file= array();
  1168. /*echo "<pre>";*/
  1169. foreach( $rows as $row ){
  1170. if( isset($getsummaries[$row['IdTemplate']]) ){
  1171. foreach( $getsummaries[$row['IdTemplate']] as $summary ){
  1172. $where= array('Posmenu_ID'=>$summary['Posmenu_ID'], 'Project_ID'=>$row['Project_ID']);
  1173. $getdt= $this->db->get_where('project_process', $where)->row_array();
  1174. $formValue= ( isset($getdt['formValue']) ) ? unserialize($getdt['formValue']) : "";
  1175. // Add formValue Data sesuai Project_ID -> Posmenu_ID
  1176. if( $formValue ){
  1177. /*print_r($formValue);*/
  1178. // Get Description Type Upload File
  1179. $regfile= "#^.+\..{3,4}$#";
  1180. foreach( $formValue as $formKey=>$form ){
  1181. if( preg_match($regfile, $form) ){
  1182. $where= array('Filename'=>$form);
  1183. $dtfile= $this->db->get_where('upload', $where)->row_array();
  1184. $file[$dtfile['Filename']]= $dtfile;
  1185. /*echo $formKey . "->" . $form . "<br/>";*/
  1186. }
  1187. }
  1188. $values[$row['Project_ID']][$summary['Posmenu_ID']]= $formValue;
  1189. }
  1190. // Modify Summary Data sesuai Dengan Template Yang Dipilih Untuk Project
  1191. $summaries[$row['IdTemplate']][$summary['Posmenu_ID']]= unserialize($summary['summaryFields']);
  1192. }
  1193. }
  1194. }
  1195. /* print_r($file);
  1196. echo "</pre>";*/
  1197. // Remove unnecessary Fields / Get Fields sesuai Summary
  1198. foreach( $values as $key=>$value ){
  1199. foreach( $value as $subkey=>$subvalue ){
  1200. foreach( $subvalue as $fieldkey=>$field ){
  1201. $IdTemplate= $rows[$key]['IdTemplate'];
  1202. /*echo $IdTemplate . "<br/>";*/
  1203. if( ! in_array($fieldkey, $summaries[$IdTemplate][$subkey]) ){
  1204. unset($values[$key][$subkey][$fieldkey]);
  1205. }
  1206. }
  1207. }
  1208. }
  1209. // Get Score u/ Setiap Project
  1210. $dbscore= $statScore;
  1211. $score= array();
  1212. /* foreach( $dbscore as $value ){
  1213. if( $value[0] ){
  1214. $score= $this->getScore("", $rows);
  1215. }
  1216. }*/
  1217. $score= $this->getScore("", $rows);
  1218. // Get Description Untuk Setiap Fields
  1219. $description= array();
  1220. foreach( $summaries as $templatekey=>$list ){
  1221. foreach( $list as $key=>$summary ){
  1222. $sql= "SELECT b.Label, b.Name FROM pos_menu a
  1223. LEFT JOIN form_fields b ON b.FormID= a.FormID
  1224. WHERE a.Id= '" . $key . "' AND a.IdTemplate= '" . $templatekey . "' AND b.Name != 'Project_ID'";
  1225. $getfields= $this->db->query($sql)->result_array();
  1226. foreach( $getfields as $fieldkey=>$field ){
  1227. $description[$key][$field['Name']]= $field['Label'];
  1228. }
  1229. }
  1230. }
  1231. // Get Available Tags
  1232. $dbTags= $this->db->get('tag')->result_array();
  1233. $tags= array();
  1234. foreach( $dbTags as $tag ){
  1235. $tags[$tag['tagName']]= $tag;
  1236. }
  1237. // Fields for Searching Filter
  1238. $fields= array(
  1239. 'Project_Name'=>'Project Name',
  1240. 'Identitas_Perusahaan'=>'Identitas Perusahaan'
  1241. );
  1242. $operator= $this->themelib->operator_search; // Get Operator Searching
  1243. /* echo "<pre>";
  1244. print_r($summaries);
  1245. print_r($description);
  1246. print_r($values);
  1247. echo "</pre>";
  1248. exit;*/
  1249. $config= $this->config;
  1250. $data= array();
  1251. $data['bar_path']= $config->item('loading');
  1252. $data['main_url']= base_url();
  1253. $data['jscript']= "";
  1254. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1255. $data["list"]= $rows;
  1256. $data["summaries"]= $summaries;
  1257. $data["description"]= $description;
  1258. $data["file"]= $file; // Description About File Upload / Document
  1259. $data["tags"]= $tags;
  1260. $data["formValues"]= $values;
  1261. $data["statScore"]= $statScore;
  1262. $data["score"]= $score;
  1263. $data['baseurl_sort']= site_url() . "project/daftar";
  1264. $data["pagination"]= $this->pagination->create_links();
  1265. $data['searching_fields']= $fields;
  1266. $data['operator']= $operator;
  1267. $this->themelib->getpage("project/view", $data, "inc/theme_main");
  1268. }
  1269. // Get Score Completion Untuk satu atau Beberapa Project
  1270. // @access private
  1271. // @param1 String, @param2 Array
  1272. // @return Array
  1273. private function getScore($IdProject="", $rows=""){
  1274. $dtscore= array();
  1275. $jml= 0;
  1276. foreach( $rows as $row ){
  1277. if( is_array($row) ){
  1278. $getscore= $this->calcScore($row);
  1279. $key= array_keys($getscore);
  1280. $value= array_values($getscore);
  1281. $dtscore[$key[0]]= $value[0];
  1282. }else{
  1283. $jml= 1;
  1284. }
  1285. }
  1286. // Calculate Score Per Data using Method calcScore
  1287. if( $jml ){
  1288. $dtscore= $this->calcScore($rows);
  1289. }
  1290. return $dtscore;
  1291. }
  1292. // Calculate Score for each project
  1293. // @access private
  1294. // @param Array
  1295. // @return Array
  1296. private function calcScore($row=""){
  1297. // Get Seluruh Project Process
  1298. $posMenu= $this->db->get('pos_menu')->result_array();
  1299. $dtscore= array();
  1300. $score= 0;
  1301. foreach( $posMenu as $pos ){
  1302. $IdProject= $row['Project_ID'];
  1303. $Posmenu_ID= $pos['Id'];
  1304. $FormID= $pos['FormID'];
  1305. // Get Seluruh Field Dari Form Yang di-select
  1306. $sql= "SELECT * FROM form_fields WHERE FormID= '" . $FormID . "' AND Name != 'Project_ID'";
  1307. $fields= $this->db->query($sql)->result_array();
  1308. if( !empty($fields) ){
  1309. $comfields= array();
  1310. foreach( $fields as $field ){
  1311. $comfields[$field["Name"]]= "";
  1312. }
  1313. }
  1314. // Get Data Form Dari Tabel project_process
  1315. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1316. $query= $this->db->get_where("project_process", $where);
  1317. $jml= $query->num_rows();
  1318. $dtscore[$IdProject]= $score;
  1319. if( $jml ){
  1320. $dtform= $query->row_array();
  1321. $formValue= unserialize($dtform["formValue"]);
  1322. $formValue= array_merge($comfields, $formValue); // Merge Data Array FormValue dengan All Fields
  1323. // Cek Empty Field Pada Process
  1324. $emptystat= 0;
  1325. foreach( $formValue as $key=>$value ){
  1326. if( empty($value) ){
  1327. $emptystat= 1;
  1328. }
  1329. }
  1330. // Jika data sudah terisi semua tambahkan score Untuk masing2x Project
  1331. if( ! $emptystat ){
  1332. $score+= $pos["Score_Completion"];
  1333. $dtscore[$IdProject]= $score;
  1334. }
  1335. }
  1336. }
  1337. return $dtscore;
  1338. }
  1339. // Display PopUp Share
  1340. // Normal Display, Searching
  1341. public function shares($nopage=""){
  1342. $POST= $this->input->post();
  1343. $Username= $this->session->userdata('Username');
  1344. /*$Username= "posix";*/
  1345. $IdShares= array();
  1346. if( isset($POST['IdProject']) ){
  1347. $where= array('Project_ID'=>$POST['IdProject']);
  1348. $project= $this->db->get_where('project', $where)->row_array();
  1349. $IdShares= explode(",", $project['IdShare']);
  1350. }
  1351. /* print_r($IdShares);
  1352. exit;*/
  1353. // Get Jumlah Record
  1354. if( isset($POST['search']) ){
  1355. // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
  1356. // dan Username sesuai dengan Key yang di-Inputs
  1357. $sql= "SELECT * FROM user
  1358. WHERE IdUsertype= '5' AND Username LIKE '%" .
  1359. $POST['search'] . "%' AND Username != '" . $Username . "'";
  1360. $jml= $this->db->query($sql)->num_rows();
  1361. }else{
  1362. // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
  1363. $jml= $this->db->get_where('user', array('IdUsertype'=>'5', 'Username !='=>$Username))->num_rows();
  1364. }
  1365. /*$jml= $this->db->get_where('user', array('IdUsertype'=>'5'))->num_rows();*/
  1366. // Set Offset, PerPage, dan Jumlah Page
  1367. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  1368. $nopage= (int)$nopage-1;
  1369. $perpage= 2;
  1370. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  1371. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  1372. // Jika Halaman lebih dari Jumlah Halaman atau Negatif Value
  1373. if( $nopage >= $jml_page || $nopage < 0 ){
  1374. $nopage= 1;
  1375. }
  1376. // Pagination Config
  1377. $base_url= base_url() . 'project/shares/';
  1378. $config['base_url'] = $base_url;
  1379. $config['total_rows'] = $jml;
  1380. $config['per_page'] = $perpage;
  1381. $config['use_page_numbers'] = FALSE;
  1382. $config['uri_segment']= 4; // Pengenal URI Active Page
  1383. $config['first_url']= 1;
  1384. $config['num_links']= $jml_page;
  1385. $config['next_link']= FALSE;
  1386. $this->pagination->initialize($config);
  1387. // Create Pagination jika user load untuk First Page
  1388. $pagination= "";
  1389. $data['IdShares']= $IdShares;
  1390. if( isset($POST['search']) ){
  1391. // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
  1392. // dan Username sesuai dengan Key yang di-Inputs
  1393. $sql= "SELECT * FROM user
  1394. WHERE IdUsertype= '5' AND Username LIKE '%" .
  1395. $POST['search'] . "%' AND Username != '" . $Username . "'
  1396. ORDER BY Username ASC
  1397. LIMIT " . $offset . "," . $perpage;
  1398. $sales= $this->db->query($sql)->result_array();
  1399. }else{
  1400. // Get Jumlah Record Sales dengan Username != dengan Current User / Sales
  1401. $this->db->order_by('Username','ASC');
  1402. $sales= $this->db->get_where('user',
  1403. array('IdUsertype'=>'5', 'Username !='=>$Username), $perpage, $offset)->result_array();
  1404. /* echo $this->db->last_query();
  1405. exit;*/
  1406. }
  1407. // Display Data
  1408. if( ! isset($POST['type']) ){
  1409. // Ketika PopUp pertama kali dibuka
  1410. $pagination= $this->pagination->create_links();
  1411. $data['pagination']= $pagination;
  1412. $data['sales']= $sales;
  1413. $data['base_url'] = $base_url;
  1414. $popUp= $this->load->view("dialog/shares_project", $data, true);
  1415. echo $popUp;
  1416. }else{
  1417. $html= "";
  1418. foreach( $sales as $sale ){
  1419. $extraAttr= array();
  1420. if( in_array($sale['Username'], $IdShares) ){
  1421. $extraAttr= array('checked'=>'checked');
  1422. }
  1423. $attr_box= array('name'=>'sales_id[]', 'value'=>$sale['Username'], 'class'=>'salesBox');
  1424. $attr_box= array_merge($attr_box, $extraAttr);
  1425. $html.= '<tr class="page' . ($nopage+1) . '">' .
  1426. '<td>' .
  1427. '<label class="checkbox">' .
  1428. form_checkbox($attr_box) .
  1429. '<span>' . ucwords($sale['Username']) . '</span>' .
  1430. '</label>' .
  1431. '</td>' .
  1432. '</tr>';
  1433. }
  1434. if( isset($POST['search']) && $POST['type'] == "search" ){
  1435. // Ketika Button Search di-Klik
  1436. $pagination= $this->pagination->create_links();
  1437. $html= array('dataTable'=>$html, 'pagination'=>$pagination);
  1438. echo json_encode($html);
  1439. }else{
  1440. // Ketika Button Navigate di-Klik
  1441. echo $html;
  1442. }
  1443. }
  1444. /* echo "<pre>";
  1445. print_r($data);
  1446. echo "</pre>";
  1447. exit;*/
  1448. }
  1449. public function process_share(){
  1450. $POST= $this->input->post();
  1451. $where= array("Project_ID"=>$POST['IdProject']);
  1452. unset($POST['IdProject']);
  1453. if( $this->Jmodel->update('project', $POST, $where) ){
  1454. echo "success";
  1455. exit;
  1456. }
  1457. /* echo "<pre>";
  1458. print_r($POST);
  1459. echo "</pre>";
  1460. exit;*/
  1461. }
  1462. // Download File pada Project Detail
  1463. public function download($IdProject="", $IdProcess="", $filename=""){
  1464. $where= array('Filename'=>$filename);
  1465. $file= $this->db->get_where('upload', $where)->row_array();
  1466. $config= $this->config;
  1467. $fullpath= $config->item('assets_img') . "project/" . $IdProject. "/" . $IdProcess . "/" . $filename;
  1468. $data= file_get_contents($fullpath);
  1469. force_download($file['Description'], $data);
  1470. }
  1471. public function detail($IdProject){
  1472. // Get Data Project Name
  1473. $where= array("Project_ID"=>$IdProject);
  1474. $project= $this->db->get_where("project", $where)->row_array();
  1475. // Get Data Step Completion
  1476. $where= array("IdTemplate"=>$project['IdTemplate']);
  1477. $rows= $this->db->get_where("pos_menu", $where)->result_array();
  1478. $this->db->flush_cache();
  1479. $score= 0;
  1480. $ct= 0;
  1481. $barisId= 1;
  1482. $jml_steps= count($rows);
  1483. $view= array();
  1484. $file= array(); // Store Data about File Upload
  1485. // Hitung Score Completion Dan Get Form Value / Isian
  1486. foreach( $rows as $row ){
  1487. $tabel= $row["Table"];
  1488. $Posmenu_ID= $row["Id"];
  1489. $FormID= $row["FormID"];
  1490. // Get Seluruh Field Dari Form Yang di-select
  1491. $sql= "SELECT * FROM form_fields WHERE FormID= '" . $FormID . "' AND Name != 'Project_ID'";
  1492. $fields= $this->db->query($sql)->result_array();
  1493. if( !empty($fields) ){
  1494. $comfields= array();
  1495. foreach( $fields as $field ){
  1496. $comfields[$field["Name"]]= "";
  1497. }
  1498. }
  1499. // Get Data Form Dari Tabel project_process
  1500. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1501. $query= $this->db->get_where("project_process", $where);
  1502. $jml= $query->num_rows();
  1503. if( $jml ){ // Jika Data Form ada
  1504. $dtform= $query->row_array();
  1505. $formValue= unserialize($dtform["formValue"]);
  1506. $formValue= array_merge($comfields, $formValue); // Merge Data Array FormValue dengan All Fields
  1507. // Cek Empty Field Pada Process
  1508. $emptystat= 0;
  1509. foreach( $formValue as $key=>$value ){
  1510. if( empty($value) ){
  1511. $emptystat= 1;
  1512. }
  1513. }
  1514. // Jika data sudah terisi semua tambahkan ke score dan aktifkan next process
  1515. $Aktif= 0;
  1516. if( ! $emptystat ){
  1517. $score+= $row["Score_Completion"];
  1518. $Aktif= 1;
  1519. $rows[$ct]['Status']= 2; // Complete
  1520. $barisId+= 1; // Digunakan untuk pengenal barisId yang Aktif
  1521. }else{
  1522. $rows[$ct]['Status']= 2; // Aktif
  1523. }
  1524. $view[$Posmenu_ID]= $formValue; // Data untuk tampilan Edit
  1525. /*echo $Aktif . "<br/>";*/
  1526. // Jika Counter sama dengan Jumlah Baris Jangan Tambahkan Aktif Process
  1527. /* if( $jml_steps == $ct ){
  1528. $rows[$ct+1]['Aktif']= $Aktif;
  1529. }*/
  1530. // Get Description Type Upload File
  1531. $regfile= "#^.+\..{3,4}$#";
  1532. foreach( $formValue as $formKey=>$form ){
  1533. if( preg_match($regfile, $form) ){
  1534. $where= array('Filename'=>$form);
  1535. $dtfile= $this->db->get_where('upload', $where)->row_array();
  1536. $file[$Posmenu_ID][$dtfile['Filename']]= $dtfile;
  1537. /*echo $formKey . "->" . $form . "<br/>";*/
  1538. }
  1539. }
  1540. // Jika Ada field yang kosong pada process tertentu hentikan perulangan
  1541. if( ! $Aktif ){
  1542. break;
  1543. }
  1544. }else{ // Jika Data Form tidak ada
  1545. break; // Hentikan Perulangan
  1546. }
  1547. $ct++;
  1548. }
  1549. $Username= $this->session->userdata('Username'); // Get Username from Session
  1550. $IdUsertype= $this->session->userdata('IdUsertype'); // Get Username from Session
  1551. $where= array('Id'=>$IdUsertype);
  1552. $usertype= $this->db->get_where('usertype', $where)->row_array();
  1553. $boxShare= "";
  1554. $share= array();
  1555. if( $usertype['Usertype'] == "sales" ){
  1556. if( $project['Username'] == $Username ){
  1557. // Jika Username Login sama dengan Username yg create project
  1558. // Munculkan Box Share ( ngeShare )
  1559. $boxShare= "yes";
  1560. }else{
  1561. // Jika Username Login tidak sama dengan Username yg create project
  1562. // Ganti Dengan BoxShare ( diShare )
  1563. $boxShare= "no";
  1564. }
  1565. // Bagi IdShare menjadi Username masing2x atau terpisah
  1566. // $share berisi data jika Username yang create project adalah username yg Login
  1567. if( ! empty($project['IdShare']) ){
  1568. $UsernameSales= explode(",", $project['IdShare']);
  1569. foreach( $UsernameSales as $sales ){
  1570. $where= array('Username'=>$sales);
  1571. $share[]= $this->db->get_where('user', $where)->row_array();
  1572. }
  1573. }
  1574. }
  1575. // Get Data Tag yg di-select
  1576. $selectedTags= "";
  1577. if( ! empty($project['IdTag']) ){
  1578. $selectedTags= explode(",", $project['IdTag']);
  1579. }
  1580. // Get Available Tags from DBase
  1581. $tags= $this->db->get("tag")->result_array();
  1582. // Get ToDo List dari User Login
  1583. $todos= array();
  1584. $where= array("IdProject"=>$IdProject, "Username"=>$Username);
  1585. $todos= $this->db->get_where("todo", $where)->result_array();
  1586. /* echo "<pre>";
  1587. print_r($rows);
  1588. print_r($barisId);
  1589. echo "</pre>";*/
  1590. /*exit;*/
  1591. /* print_r($view);
  1592. print_r($file);
  1593. print_r($project);*/
  1594. $usertype['Usertype']= "sales";
  1595. $config= $this->config;
  1596. $data= array();
  1597. $data['bar_path']= $config->item('loading');
  1598. $data['main_url']= base_url();
  1599. $data['hrefAction']= base_url() . "project/process_share";
  1600. $data['jscript']= $this->load->view("js/pro_detail.php", $data, TRUE);
  1601. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1602. $data["rows"]= $rows;
  1603. $data["score"]= $score;
  1604. $data["barisId"]= $barisId;
  1605. $data["IdProject"]= $IdProject;
  1606. $data["view"]= $view;
  1607. $data["file"]= $file; // Store File Upload Description
  1608. $data["share"]= $share;
  1609. $data["boxShare"]= $boxShare;
  1610. $data["tags"]= $tags;
  1611. $data["todos"]= $todos; // Todo List
  1612. $data["selectedTags"]= $selectedTags;
  1613. $data["Project_Name"]= $project["Project_Name"];
  1614. $data['project']= $project;
  1615. $data['Usertype']= $usertype['Usertype'];
  1616. $data['hrefDialog']= "project/dialog/";
  1617. $data['hrefShare']= "project/shares";
  1618. $data['hrefAction']= "project/process_share";
  1619. $this->themelib->getpage("project/detail", $data, "inc/theme_main");
  1620. }
  1621. /*public function detail($IdProject){
  1622. // Get Data Project Name
  1623. $where= array("Project_ID"=>$IdProject);
  1624. $project= $this->db->get_where("project", $where)->row_array();
  1625. // Get Data Step Completion
  1626. $rows= $this->db->get("pos_menu")->result_array();
  1627. $this->db->flush_cache();
  1628. // Hitung Score Completion
  1629. $score= 0;
  1630. $ct= 0;
  1631. $barisId= 1;
  1632. $view= array();
  1633. foreach( $rows as $row ){
  1634. $tabel= $row["Table"];
  1635. $Posmenu_ID= $row["Id"];
  1636. $FormID= $row["FormID"];
  1637. // Get Seluruh Field Dari Form Yang di-select
  1638. $sql= "SELECT * FROM form_fields WHERE FormID= '" . $FormID . "' AND Name != 'Project_ID'";
  1639. $fields= $this->db->query($sql)->result_array();
  1640. if( !empty($fields) ){
  1641. $comfields= array();
  1642. foreach( $fields as $field ){
  1643. $comfields[$field["Name"]]= "";
  1644. }
  1645. }
  1646. // Get Data Form Dari Tabel project_process
  1647. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1648. $query= $this->db->get_where("project_process", $where);
  1649. $jml= $query->num_rows();
  1650. if( $jml ){
  1651. $dtform= $query->row_array();
  1652. $formValue= unserialize($dtform["formValue"]);
  1653. $formValue= array_merge($comfields, $formValue); // Merge Data Array FormValue dengan All Fields
  1654. // Cek Empty Field Pada Process
  1655. $emptystat= 0;
  1656. foreach( $formValue as $key=>$value ){
  1657. if( empty($value) ){
  1658. $emptystat= 1;
  1659. }
  1660. }
  1661. // Jika data sudah terisi semua tambahkan ke score dan aktifkan next process
  1662. $Aktif= 0;
  1663. if( ! $emptystat ){
  1664. $score+= $row["Score_Completion"];
  1665. $rows[$ct]['Status']= "Complete";
  1666. }else{
  1667. $rows[$ct]['Status']= "Aktif";
  1668. }
  1669. $view[$tabel]= $formValue; // Data untuk tampilan Edit
  1670. }else{
  1671. $rows[$ct]['Status']= "Aktif";
  1672. }
  1673. $ct++;
  1674. }
  1675. $config= $this->config;
  1676. $data= array();
  1677. $data['bar_path']= $config->item('loading');
  1678. $data['main_url']= base_url();
  1679. $data['jscript']= $this->load->view("js/pro_detail.php", $data, TRUE);
  1680. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1681. $data["rows"]= $rows;
  1682. $data["score"]= $score;
  1683. $data["barisId"]= $barisId;
  1684. $data["IdProject"]= $IdProject;
  1685. $data["view"]= $view;
  1686. $data["Project_Name"]= $project["Project_Name"];
  1687. $this->themelib->getpage("project/detail", $data, "inc/theme_main");
  1688. }*/
  1689. public function action($type="", $IdProject=""){
  1690. if( $type == "edit" ){
  1691. $POST= $this->input->post();
  1692. $IdProject= $POST["Project_ID"];
  1693. unset($POST["submit"], $POST["type"], $POST["Project_ID"]);
  1694. $this->db->where("Project_ID", $IdProject);
  1695. $this->db->update("project", $POST);
  1696. echo "success";
  1697. exit;
  1698. }else if( $type == "delete" ){
  1699. $this->db->where('Project_ID', $IdProject);
  1700. $hasil= $this->db->delete('project');
  1701. redirect("project/daftar");
  1702. }
  1703. }
  1704. /* // Method untuk render page ( refactor code aja )
  1705. private function getpage($page, $data="", $theme=""){
  1706. $POST= $this->input->post();
  1707. $config= $this->config;
  1708. $profile= array(
  1709. 'Profile'=> site_url("profile"),
  1710. 'LogOut'=> site_url("login/dologout")
  1711. );
  1712. // Set Parameter Data
  1713. $data['imgpath']= $config->item('img_path');
  1714. $data['csspath']= $config->item('css_path');
  1715. $data['jspath']= $config->item('js_path');
  1716. $data['bar_path']= $config->item('loading');
  1717. $data['captcha']= base_url() . strtolower(__CLASS__) . "/captcha";
  1718. $data['main_url']= base_url();
  1719. $data['logOutHref']= base_url() . "login/dologout";
  1720. $data['profile']= $profile;
  1721. $data['Username']= $this->session->userdata("Username");
  1722. if( isset($POST['type']) && $POST['type'] == "ajax" ){
  1723. $data['type']= $POST['type'];
  1724. echo $this->load->view($page, $data, TRUE);
  1725. }else{
  1726. // Set Path Parameters
  1727. $data['page']= $page;
  1728. $data['LeftNavigation']= $this->themelib->make_menu();
  1729. $data['Content']= $this->themelib->getData($page, $data);
  1730. $this->themelib->create($theme, $data);
  1731. }
  1732. }*/
  1733. public function dialog($IdProcess, $IdProject, $action){
  1734. /* $IdProcess= 56;
  1735. $IdProject= 47;
  1736. $action= 'add';*/
  1737. // Get ID dari Process / pos_menu
  1738. $where= array("Id"=>$IdProcess);
  1739. $process= $this->db->get_where("pos_menu", $where)->row_array();
  1740. $FormID= $process["FormID"];
  1741. /* $IdUsertype= "3"; // Sales
  1742. $IdUsertype= "2"; // Supervisor*/
  1743. $IdUsertype= $this->session->userdata("IdUsertype");
  1744. if( ! empty($FormID) ){
  1745. // Check Privilege Setting Pada Form
  1746. $where= array('FormID'=>$FormID, 'IdUsertype'=>$IdUsertype);
  1747. if( ! $this->db->get_where('config_fields', $where)->num_rows() ){
  1748. echo "Set Privilege Form terlebih dahulu !";
  1749. exit;
  1750. }
  1751. $sql= "SELECT b.FieldType, b.Label, b.Name, c.Privilege FROM masterform a
  1752. LEFT JOIN form_fields b ON b.FormID= a.FormID
  1753. LEFT JOIN config_fields c ON c.IdField= b.Id
  1754. WHERE a.FormID= '" . $FormID . "' AND c.IdUsertype= '" . $IdUsertype . "'";
  1755. $fields= $this->db->query($sql)->result_array();
  1756. /* echo "<pre>";
  1757. echo $this->db->last_query();
  1758. echo "<pre>";
  1759. exit;*/
  1760. }else{
  1761. echo "Process ini belum memiliki Form yang di-set !";
  1762. exit;
  1763. }
  1764. $pos= $this->db->get_where('pos_menu', array('Id'=>$IdProcess))->row_array();
  1765. /* print_r($pos);
  1766. exit;*/
  1767. $config= $this->config;
  1768. $IdProcess= strtolower($IdProcess);
  1769. $data= array();
  1770. $data['bar_path']= $config->item('loading');
  1771. $data['main_url']= base_url();
  1772. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1773. $data['jscript']= $this->load->view("js/dialog.php", $data, TRUE);
  1774. /*$data['jscript']= $this->load->view("js/" . $IdProcess. ".php", $data, TRUE);*/
  1775. $data["caller"]= "dialog";
  1776. $data["fields"]= $fields;
  1777. $data["Title"]= ucwords(str_replace("_", " ", $pos['Process_Name']));
  1778. $data["action"]= $IdProcess . "/" . $IdProject;
  1779. if( $action == "add" ){ // Add
  1780. /* $this->themelib->notify_js= FALSE;
  1781. $this->themelib->getpage("dialog/add", $data, "inc/theme_main");*/
  1782. echo $this->load->view("dialog/add", $data, TRUE);
  1783. }else{ // Edit
  1784. $where= array("Id"=>$IdProcess);
  1785. $row= $this->db->get_where("pos_menu", $where)->row_array();
  1786. // Get Data Value Pada Form Process
  1787. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$row["Id"]);
  1788. $form= $this->db->get_where("project_process", $where)->row_array();
  1789. $formValue= unserialize($form["formValue"]); // Unserialize Data
  1790. /* echo "<pre>";
  1791. print_r($row);
  1792. print_r($formValue);
  1793. echo "</pre>";
  1794. exit;*/
  1795. // Add Value to $fields Array
  1796. $ct= 0;
  1797. foreach( $fields as $field ){
  1798. $fieldName= $field["Name"];
  1799. $fields[$ct]["Value"]= ( isset($formValue[$fieldName]) ) ? $formValue[$fieldName] : "";
  1800. $ct++;
  1801. }
  1802. // Hidden Field Data
  1803. $data["hiddenFields"]= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$row["Id"]);
  1804. $data["fields"]= $fields;
  1805. echo $this->load->view("dialog/edit", $data, TRUE);
  1806. }
  1807. }
  1808. public function process($IdProcess, $IdProject, $action){
  1809. if( $action == "add" ){
  1810. $POST= $this->input->post();
  1811. /* echo "<pre>";
  1812. print_r($POST);
  1813. print_r($_FILES);
  1814. echo "</pre>";
  1815. exit;*/
  1816. unset($POST["submit"], $POST["type"]);
  1817. foreach( $_FILES as $key=>$Image ){
  1818. if( !empty($Image['name']) ){
  1819. // Create Directory
  1820. $image_path= $this->config->item('assets_img');
  1821. $image_path.= "project/" . $IdProject . "/" . $IdProcess;
  1822. if( ! file_exists($image_path) ){
  1823. if( ! mkdir($image_path, 0, TRUE) ){
  1824. echo "Error terjadi, Silakan coba lagi !";
  1825. exit;
  1826. }
  1827. }
  1828. $extension= pathinfo($Image['name'], PATHINFO_EXTENSION); // Get Extension
  1829. // Set Filename
  1830. $filename= md5(random_string('unique') . date("Y-m-d H:i:s"));
  1831. $filename.= "." . $extension;
  1832. $tmp_file= $Image['tmp_name'];
  1833. $fullpath= $image_path . "/" . $filename;
  1834. // Upload File
  1835. if( move_uploaded_file($tmp_file, $fullpath) ){
  1836. // Insert Data Upload File Ke DBase
  1837. $Upload= array(
  1838. 'Filename'=>$filename,
  1839. 'Description'=>$Image['name'],
  1840. 'AddDate'=>date('Y-m-d H:i:s'),
  1841. );
  1842. if( ! $this->Jmodel->insert('upload', $Upload) ){
  1843. echo "Error terjadi, Silakan coba lagi !";
  1844. exit;
  1845. }
  1846. $POST[$key]= $filename; // Add Filename to Post u/ insert data ke Tabel project_process
  1847. }else{
  1848. echo "Error terjadi, Silakan coba lagi !";
  1849. exit;
  1850. }
  1851. }
  1852. }
  1853. // Get ID Pos Menu
  1854. $where= array("Id"=>$IdProcess);
  1855. $posmenu= $this->db->get_where("pos_menu", $where)->row_array();
  1856. // Set Data Yang akan Di-insert
  1857. $data= array();
  1858. $data["formValue"]= serialize($POST);
  1859. // Cek Apa Data ada pada Tabel project_process
  1860. $Posmenu_ID= $IdProcess;
  1861. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1862. if( $this->db->get_where("project_process", $where)->num_rows() ){
  1863. // Update
  1864. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1865. $this->Jmodel->update("project_process", $data, $where);
  1866. // Send Feedback
  1867. $score= "";
  1868. $msg= array("response"=>"success","score"=>$score);
  1869. $msg= json_encode($msg);
  1870. echo $msg;
  1871. exit;
  1872. }else{
  1873. // Set Data
  1874. $data["Project_ID"]= $IdProject;
  1875. $data["Posmenu_ID"]= $Posmenu_ID;
  1876. // Insert Data, Update Score
  1877. if( $this->Jmodel->insert("project_process", $data) ){
  1878. /*$score= $this->updateScore($IdProject);*/
  1879. $score= "";
  1880. $msg= array("response"=>"success","score"=>$score);
  1881. $msg= json_encode($msg);
  1882. echo $msg;
  1883. exit;
  1884. }
  1885. }
  1886. }else{
  1887. $POST= $this->input->post();
  1888. unset($POST["submit"], $POST["type"], $POST["Project_ID"], $POST["Posmenu_ID"]);
  1889. extract($POST);
  1890. foreach( $_FILES as $key=>$Image ){
  1891. if( !empty($Image['name']) ){
  1892. // Create Directory
  1893. $image_path= $this->config->item('assets_img');
  1894. $image_path.= "project/" . $IdProject . "/" . $IdProcess;
  1895. if( ! file_exists($image_path) ){
  1896. if( ! mkdir($image_path, 0, TRUE) ){
  1897. echo "Error terjadi, Silakan coba lagi !";
  1898. exit;
  1899. }
  1900. }
  1901. $extension= pathinfo($Image['name'], PATHINFO_EXTENSION); // Get Extension
  1902. // Set Filename
  1903. $filename= md5(random_string('unique') . date("Y-m-d H:i:s"));
  1904. $filename.= "." . $extension;
  1905. $tmp_file= $Image['tmp_name'];
  1906. $fullpath= $image_path . "/" . $filename;
  1907. // Upload File
  1908. if( move_uploaded_file($tmp_file, $fullpath) ){
  1909. // Insert Data Upload File Ke DBase
  1910. $Upload= array(
  1911. 'Filename'=>$filename,
  1912. 'Description'=>$Image['name'],
  1913. 'AddDate'=>date('Y-m-d H:i:s'),
  1914. );
  1915. if( ! $this->Jmodel->insert('upload', $Upload) ){
  1916. echo "Error terjadi, Silakan coba lagi !";
  1917. exit;
  1918. }
  1919. $POST[$key]= $filename;
  1920. }else{
  1921. echo "Error terjadi, Silakan coba lagi !";
  1922. exit;
  1923. }
  1924. }
  1925. }
  1926. // Get ID Pos Menu
  1927. $where= array("Id"=>$IdProcess);
  1928. $pos_row= $this->db->get_where("pos_menu", $where)->row_array();
  1929. $Posmenu_ID= $pos_row["Id"];
  1930. // Get Previous Value dari Form Process
  1931. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1932. $form= $this->db->get_where("project_process", $where)->row_array();
  1933. $formValue= unserialize($form["formValue"]);
  1934. $fileField= array();
  1935. $regfile= "#^.+\..{3,4}$#";
  1936. foreach( $POST as $key=>$value ){
  1937. if( preg_match($regfile, $value) ){
  1938. // Delete Data pada Tabel upload
  1939. $where= array('Filename'=>$formValue[$key]);
  1940. $this->db->delete('upload', $where);
  1941. // Delete File Pada Direktori
  1942. $imgpath= $this->config->item('assets_img');
  1943. $fullpath= $imgpath . "project/" . $IdProject . "/" . $IdProcess . "/" . $formValue[$key];
  1944. unlink($fullpath);
  1945. }
  1946. }
  1947. // Merge Existing Data dengan New Input Lalu di-serialize
  1948. $formValue= array_merge($formValue, $POST);
  1949. $data= array("formValue"=>serialize($formValue));
  1950. /* echo "<pre>";
  1951. print_r($data);
  1952. echo json_encode($data);
  1953. echo "</pre>";
  1954. exit;*/
  1955. // Update Data dan Kirim Feedback
  1956. $where= array("Project_ID"=>$IdProject, "Posmenu_ID"=>$Posmenu_ID);
  1957. $jml= $this->Jmodel->update("project_process", $data, $where);
  1958. if( $jml != -1 ){
  1959. $msg= array("response"=>"success","score"=>0);
  1960. $msg= json_encode($msg);
  1961. echo $msg;
  1962. exit;
  1963. }
  1964. }
  1965. }
  1966. /* public function dialog($IdProcess, $IdProject, $action){
  1967. // Get ID dari Process / pos_menu
  1968. $where= array("Table"=>$IdProcess);
  1969. $process= $this->db->get_where("pos_menu", $where)->row_array();
  1970. // Get active Field sesuai Pos Menu dan Usertype
  1971. $where= array("IdPosMenu"=>$process["Id"], "IdUsertype"=>$this->session->userdata("IdUsertype"));
  1972. $rows_field= $this->db->get_where("setting_fields", $where)->row_array();
  1973. $active_field= explode(",", $rows_field["Fields"]);
  1974. $rows= $this->db->list_fields(strtolower($IdProcess));
  1975. $fields= array(); // Simpan Data seluruh fields
  1976. $ct= 1;
  1977. foreach( $rows as $key=>$value ){
  1978. if( $value != "Project_ID" ){ // Simpan Data selain Project_ID field
  1979. $fields[$ct]= $value;
  1980. $ct++;
  1981. }
  1982. }
  1983. // Hapus data Fields yang aktif, Simpan disable Fields
  1984. $disable_fields= array();
  1985. foreach( $fields as $key=>$field ){
  1986. if( ! in_array($key, $active_field)){
  1987. $disable_field[]= $field;
  1988. }
  1989. }
  1990. $disable_fields= "";
  1991. if( ! empty($disable_field) ){
  1992. $disable_fields= implode(",", $disable_field); // String dg separate comma untuk ke JS
  1993. }
  1994. $config= $this->config;
  1995. $IdProcess= strtolower($IdProcess);
  1996. $data= array();
  1997. $data['bar_path']= $config->item('loading');
  1998. $data['main_url']= base_url();
  1999. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  2000. $data['disable_fields']= $disable_fields;
  2001. $data['jscript']= $this->load->view("js/" . $IdProcess. ".php", $data, TRUE);
  2002. $data["caller"]= "dialog";
  2003. $data["action"]= $IdProcess . "/" . $IdProject;
  2004. if( $action == "add" ){
  2005. echo $this->load->view($IdProcess . "/add", $data, TRUE);
  2006. }else{
  2007. $where= array("Project_ID"=>$IdProject);
  2008. $data["row"]= $this->db->get_where($IdProcess, $where)->row_array();
  2009. $this->db->flush_cache();
  2010. echo $this->load->view($IdProcess . "/edit", $data, TRUE);
  2011. }
  2012. }
  2013. public function process($IdProcess, $IdProject, $action){
  2014. if( $action == "add" ){
  2015. $POST= $this->input->post();
  2016. echo "<pre>";
  2017. print_r($POST);
  2018. echo "</pre>";
  2019. exit;
  2020. $POST["Project_ID"]= $IdProject;
  2021. unset($POST["submit"], $POST["type"]);
  2022. // Pengecekan untuk HALAMAN IDENTIFIED PROJECT
  2023. if( isset($POST["Identitas_Perusahaan"]) ){
  2024. $where= array("Identitas_Perusahaan"=>$POST["Identitas_Perusahaan"]);
  2025. $jml= $this->db->get_where($IdProcess, $where)->num_rows();
  2026. if( $jml ){
  2027. $msg= array("response"=>"Identitas Perusahaan is already exists", "score"=>0);
  2028. $msg= json_encode($msg);
  2029. echo $msg;
  2030. exit;
  2031. }
  2032. }
  2033. // Check u/ memastikan jika Kedua Usertype sudah membuka Dialog add bersamaan
  2034. // Jika Id Project sudah ada update data sebelumnya
  2035. $where= array("Project_ID"=>$IdProject);
  2036. if( $this->db->get_where($IdProcess, $where)->num_rows() ){
  2037. // Update
  2038. $where= array("Project_ID"=>$IdProject);
  2039. $this->Jmodel->update($IdProcess, $POST, $where);
  2040. // Send Feedback
  2041. $score= "";
  2042. $msg= array("response"=>"success","score"=>$score);
  2043. $msg= json_encode($msg);
  2044. echo $msg;
  2045. exit;
  2046. }
  2047. // Insert Data, Update Score
  2048. if( $this->Jmodel->insert($IdProcess, $POST) ){
  2049. $score= $this->updateScore($IdProject);
  2050. $msg= array("response"=>"success","score"=>$score);
  2051. $msg= json_encode($msg);
  2052. echo $msg;
  2053. exit;
  2054. }
  2055. }else{
  2056. $POST= $this->input->post();
  2057. unset($POST["submit"], $POST["type"]);
  2058. extract($POST);
  2059. // Update Data dan Kirim Feedback
  2060. $where= array("Project_ID"=>$IdProject);
  2061. $jml= $this->Jmodel->update($IdProcess, $POST, $where);
  2062. if( $jml != -1 ){
  2063. $msg= array("response"=>"success","score"=>0);
  2064. $msg= json_encode($msg);
  2065. echo $msg;
  2066. exit;
  2067. }
  2068. }
  2069. }
  2070. */
  2071. }
  2072. ?>