PageRenderTime 40ms CodeModel.GetById 44ms RepoModel.GetById 12ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full file

  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, $

Large files files are truncated, but you can click here to view the full file