PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/project.php

https://bitbucket.org/remobius/coding
PHP | 2589 lines | 1635 code | 249 blank | 705 comment | 177 complexity | 6eda6d3735eae286632370966388d743 MD5 | raw file
Possible License(s): CC-BY-3.0, GPL-2.0

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

  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. function testpage(){
  11. $config= $this->config;
  12. $data= array();
  13. $data['title']= "Testing Page";
  14. $data['jscript']= "";
  15. /*$this->load->view('test', $data);*/
  16. $this->themelib->getpage("test", $data, "inc/theme_main");
  17. }
  18. public function server_var(){
  19. /*echo urlencode("~!@#$%^&*()_+-:");*/
  20. echo urlencode("Aplikasi CMS | CMS");
  21. /* foreach( $_SERVER as $key=>$value ){
  22. echo $key . "->" . $value . "<br/>";
  23. }*/
  24. /* echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "<br/>";
  25. echo site_url();*/
  26. }
  27. function newpage(){
  28. echo "abc";
  29. }
  30. // Setting PO ID format
  31. public function setting_po_id($process=""){
  32. if( empty($process) ){
  33. $config= $this->config;
  34. $data= array();
  35. $data['poid']= $this->db->limit('1')->get('poid_format')->row_array();
  36. $data['bar_path']= $config->item('loading');
  37. $data['main_url']= base_url();
  38. $data['jscript']= $this->load->view('js/po_id', $data, true);
  39. $this->themelib->getpage("project/po_id", $data, "inc/theme_main");
  40. }else{
  41. $POST= $this->input->post();
  42. // Set Rules Validasi
  43. $config= array(
  44. array(
  45. 'field'=> 'Prefix',
  46. 'label'=> 'Prefix',
  47. 'rules'=> 'required'
  48. ),
  49. array(
  50. 'field'=> 'Digit',
  51. 'label'=> 'Digit Number',
  52. 'rules'=> 'required|integer'
  53. )
  54. );
  55. $this->form_validation->set_rules($config);
  56. if( $this->form_validation->run() == TRUE ){ // Cek Validasi
  57. if( isset($POST['submit']) || $POST['type'] == "ajax" ){
  58. extract($POST);
  59. // Get PO_ID Format
  60. $poid_format= $this->db->get_where('poid_format')->row_array();
  61. // Remove Data pada Tabel poid_format
  62. $this->db->truncate('poid_format');
  63. // Insert Data
  64. unset($POST['submit'], $POST['type']);
  65. if( $this->Jmodel->insert('poid_format', $POST) ){
  66. // Get PO_ID Data
  67. $poid_dt= $this->db->get('po_id')->result_array();
  68. foreach( $poid_dt as $key=>$value ){
  69. $jml= strlen($poid_format['Prefix']);
  70. $poid_val= substr($value['PO_ID'], $jml);
  71. $poid_val= $POST['Prefix'] . sprintf('%0' . $POST['Digit'] . 's', $poid_val+1);
  72. /*echo $poid_val . "<br/>";*/
  73. // Update PO_ID
  74. $update_poid= array('PO_ID'=>$poid_val);
  75. $where= array('Project_ID'=>$value['Project_ID']);
  76. $this->Jmodel->update('po_id', $update_poid, $where);
  77. }
  78. /*exit;*/
  79. $feedback= array('type'=>'success', 'response'=>'PO ID has been set.');
  80. $feedback= json_encode($feedback);
  81. if( $type == "ajax" ){
  82. echo $feedback;
  83. exit;
  84. }else{
  85. $this->session->set_userdata('feedback', $feedback);
  86. redirect("project/setting_po_id");
  87. }
  88. }
  89. }
  90. }else{
  91. $config= $this->config;
  92. $data= array();
  93. $data['poid']= $this->db->limit('1')->get('poid_format')->row_array();
  94. $data['bar_path']= $config->item('loading');
  95. $data['main_url']= base_url();
  96. $data['jscript']= $this->load->view('js/po_id', $data, true);
  97. $this->themelib->getpage("project/po_id", $data, "inc/theme_main");
  98. }
  99. }
  100. }
  101. // MD5 Function
  102. public function md5(){
  103. echo md5("sales");
  104. exit;
  105. echo 'administrator' . date("Y-m-d H:i:s") . "->" . md5('administrator' . date("Y-m-d H:i:s")) . "<br/>";
  106. echo 'administrator2' . date("Y-m-d H:i:s") . "->" . md5('administrator2' . date("Y-m-d H:i:s"));
  107. }
  108. // Struktur Organisasi
  109. public function structure($process=""){
  110. $config= $this->config;
  111. $js_path= $config->item('js_path');
  112. // Create Structure List Using jwMenu Class
  113. $data= $this->db->get('structure')->result_array();
  114. $this->jwmenu->baseUrl= base_url();
  115. $this->jwmenu->setStyle("org", "");
  116. $this->jwmenu->setClassLink("structure-link");
  117. /*$this->jwmenu->setIcon();*/
  118. $structure= $this->jwmenu->create_tree($data);
  119. $data= array();
  120. $data['bar_path']= $config->item('loading');
  121. $data['main_url']= base_url();
  122. $data['jscript']= '';
  123. $data['css_files']= array($js_path . "/jOrgChart/css/jquery.jOrgChart.css");
  124. $data['js_files']= array($js_path . "/jOrgChart/js/jquery.jOrgChart.js");
  125. $data['structure']= $structure;
  126. $this->themelib->getpage("structure", $data, "inc/theme_main");
  127. }
  128. // Change Password User
  129. public function change_password($process=""){
  130. if( $process == "process" ){
  131. $POST= $this->input->post();
  132. /* echo "<pre>";
  133. print_r($POST);
  134. echo "</pre>";*/
  135. // Set Rules Validasi
  136. $config= array(
  137. array(
  138. 'field'=> 'OldPassword',
  139. 'label'=> 'Old Password',
  140. 'rules'=> 'required'
  141. ),
  142. array(
  143. 'field'=> 'NewPassword',
  144. 'label'=> 'New Password',
  145. 'rules'=> 'required'
  146. ),
  147. array(
  148. 'field'=> 'PasswordConf',
  149. 'label'=> 'Password Confirmation',
  150. 'rules'=> 'required'
  151. )
  152. );
  153. $this->form_validation->set_rules($config);
  154. if( $this->form_validation->run() == TRUE ){ // Cek Validasi
  155. if( isset($POST['submit']) || $POST['type'] == "ajax" ){
  156. extract($POST);
  157. // Cek Old Password sesuai
  158. $Username= $this->session->userdata('Username');
  159. $where= array('Password'=>md5($OldPassword), 'Username'=>$Username);
  160. $jml= $this->db->get_where('user', $where)->num_rows();
  161. /* echo $this->db->last_query();
  162. exit;*/
  163. if( ! $jml ){
  164. $feedback= array('type'=>'error', 'response'=>'Old Password tidak sesuai !');
  165. $feedback= json_encode($feedback);
  166. if( $type == "ajax" ){
  167. echo $feedback;
  168. exit;
  169. }else{
  170. $this->session->set_userdata('feedback', $feedback);
  171. redirect("change_password");
  172. }
  173. }
  174. // Change Password
  175. $where= array('Username'=>$Username);
  176. $data= array('Password'=>md5($NewPassword));
  177. if( $this->Jmodel->update('user', $data, $where) ){
  178. $feedback= array('type'=>'success', 'response'=>'Password has been changed !');
  179. $feedback= json_encode($feedback);
  180. if( $type == "ajax" ){
  181. echo $feedback;
  182. exit;
  183. }else{
  184. $this->session->set_userdata('feedback', $feedback);
  185. redirect("change_password");
  186. }
  187. }
  188. }
  189. }else{
  190. $config= $this->config;
  191. $data= array();
  192. $data['bar_path']= $config->item('loading');
  193. $data['main_url']= base_url();
  194. $data['jscript']= $this->load->view('js/change_password', $data, TRUE);
  195. $this->themelib->getpage("user/change_password", $data, "inc/theme_main");
  196. }
  197. }else{
  198. $config= $this->config;
  199. $data= array();
  200. $data['bar_path']= $config->item('loading');
  201. $data['main_url']= base_url();
  202. $data['jscript']= $this->load->view('js/change_password', $data, TRUE);
  203. $this->themelib->getpage("user/change_password", $data, "inc/theme_main");
  204. }
  205. }
  206. // Dashboard Page
  207. public function dashboard(){
  208. $config= $this->config;
  209. $data= array();
  210. $data['bar_path']= $config->item('loading');
  211. $data['main_url']= base_url();
  212. $data['jscript']= "";
  213. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  214. $this->themelib->getpage("", $data, "inc/theme_new");
  215. }
  216. public function new_menu(){
  217. $config= $this->config;
  218. $data= array();
  219. $data['bar_path']= $config->item('loading');
  220. $data['main_url']= base_url();
  221. $data['jscript']= "";
  222. /*$data['menu']= $this->load->view("inc/menu.php", $data, TRUE);*/
  223. $this->themelib->getpage("testing", $data, "inc/theme_new");
  224. /*$this->themelib->getpage("testing", $data, "inc/theme_main");*/
  225. }
  226. // Dashboard Page
  227. /* public function sticky_test(){
  228. $config= $this->config;
  229. $data= array();
  230. $data['bar_path']= $config->item('loading');
  231. $data['main_url']= base_url();
  232. $data['jscript']= "";
  233. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  234. $this->themelib->getpage("sticky_test", $data, "inc/theme_main");
  235. }*/
  236. // Notify ToDo ( User Login ) setiap 5 menit
  237. public function notify_todo(){
  238. $Username= $this->session->userdata('Username');
  239. $today= date("Y-m-d H:i:s");
  240. $cur_date= explode(" ", $today);
  241. $date= explode("-", $cur_date[0]);;
  242. $time= explode(":", $cur_date[1]);
  243. list($year, $month, $day)= $date;
  244. list($hour, $minute, $second)= $time;
  245. $last_time= date("Y-m-d H:i:s", mktime($hour, $minute-5, 0, $month, $day, $year));
  246. $now_time= date("Y-m-d H:i:s", mktime($hour, $minute, 0, $month, $day, $year));
  247. $sql= "SELECT * FROM todo
  248. WHERE DueDate BETWEEN '" . $last_time . "' AND '" . $now_time.
  249. "' AND Username='" . $Username . "' AND Status != 'yes'";
  250. $todo= array();
  251. $todo= $this->db->query($sql)->row_array();
  252. /* echo "<pre>";
  253. echo $sql;
  254. echo "</pre>";
  255. exit;*/
  256. if( count($todo) ){
  257. $notifyId= $todo['Id'];
  258. $notify_dt= '<p><a href="' . site_url() . 'project/detail/' . $todo['IdProject'] . '">' . $todo['Task'] .
  259. '</a></p>';
  260. $notify= array(
  261. 'Id'=>$notifyId,
  262. 'Element'=>$notify_dt
  263. );
  264. echo json_encode($notify);
  265. }
  266. exit;
  267. }
  268. // Process Untuk Set Status Complete or Not
  269. public function process_todo(){
  270. $POST= $this->input->post();
  271. $where= array('Id'=>$POST['Id']);
  272. unset($POST['Id']);
  273. if( $this->Jmodel->update('todo', $POST, $where) ){
  274. echo "success";
  275. }
  276. }
  277. // PopUp for Todo pada Halaman Project Detail ( Add, Edit )
  278. // Serta Processing u/ Delete ToDo
  279. public function todo($IdProject="", $action="", $IdTodo= ""){
  280. $config= $this->config;
  281. if( $action == "edit" ) { // PopUp Edit ToDo
  282. $where= array('Id'=>$IdTodo);
  283. $todo= $this->db->get_where('todo', $where)->row_array();
  284. $data= array();
  285. $data['bar_path']= $config->item('loading');
  286. $data['main_url']= base_url();
  287. $data['jscript']= "";
  288. $data['IdProject']= $IdProject;
  289. $data['hrefElement']= site_url() . $this->uri->uri_string();
  290. $data['todo']= $todo;
  291. $html= $this->load->view('todo/edit', $data, TRUE);
  292. echo $html;
  293. exit;
  294. }elseif( $action == "delete" ){ // Delete ToDo
  295. $where= array("Id"=>$IdTodo);
  296. if( $this->db->delete('todo', $where) ){
  297. echo "success";
  298. exit;
  299. }
  300. }else{ // PopUp Add ToDo
  301. $data= array();
  302. $data['bar_path']= $config->item('loading');
  303. $data['main_url']= base_url();
  304. $data['jscript']= "";
  305. $data['IdProject']= $IdProject;
  306. $html= $this->load->view('todo/todo', $data, TRUE);
  307. echo $html;
  308. exit;
  309. }
  310. }
  311. // Display All ToDos dari Login User
  312. public function todo_list(){
  313. $Username= $this->session->userdata('Username');
  314. $todos= array();
  315. $sql= "SELECT a.*, b.Project_Name FROM todo a
  316. LEFT JOIN project b ON b.Project_ID= a.IdProject
  317. WHERE a.Username= '" . $Username . "' AND a.Status= 'no'
  318. ORDER BY a.DueDate DESC";
  319. $todos= $this->db->query($sql)->result_array();
  320. $today= date("d-m-Y");
  321. $today= explode("-", $today);
  322. list($day, $month, $year)= $today;
  323. $today= mktime(0, 0, 0, $month, $day, $year);
  324. $tomorrow= mktime(0, 0, 0, $month, $day+1, $year);
  325. // Grouping ToDos ( Late, Today, Upcoming)
  326. $late_todos= array();
  327. $today_todos= array();
  328. $upcoming_todos= array();
  329. foreach( $todos as $todo ){
  330. $DueDate= strtotime($todo['DueDate']);
  331. if( $DueDate < $today ){
  332. $late_todos[]= $todo;
  333. }elseif( $DueDate >= $tomorrow ){
  334. $upcoming_todos[]= $todo;
  335. }else{
  336. $today_todos[]= $todo;
  337. }
  338. }
  339. $todos['late']= $late_todos;
  340. $todos['today']= $today_todos;
  341. $todos['upcoming']= $upcoming_todos;
  342. $config= $this->config;
  343. $data= array();
  344. $data['bar_path']= $config->item('loading');
  345. $data['main_url']= base_url();
  346. $data['jscript']= $this->load->view('js/todo_list', $data, TRUE);
  347. $data['todos']= $todos;
  348. $this->themelib->getpage("todo/todo_list", $data, "inc/theme_main");
  349. }
  350. // Processing Save, Edit and Delete Todo Data Into Database
  351. public function todo_save($action=""){
  352. $POST= $this->input->post();
  353. // Set Data for inserting to DBase
  354. $POST['Username']= $this->session->userdata('Username');
  355. $POST['DueDate'].= " " . $POST['Hour'] . ":" . $POST['Minutes'] . " " . $POST['IdTime'];
  356. $POST['DueDate']= date("Y-m-d H:i:s", strtotime($POST['DueDate']));
  357. unset($POST['Hour'], $POST['Minutes'], $POST['IdTime'], $POST['submit']);
  358. if( $action == "edit" ){ // Edit ToDo
  359. $POST['ModifyDate']= date("Y-m-d H:i:s");
  360. $IdTodo= $POST['Id'];
  361. $IdProject= $POST['IdProject'];
  362. unset($POST['Id'], $POST['IdProject']);
  363. $where= array('Id'=>$IdTodo);
  364. if( $this->Jmodel->update('todo', $POST, $where) ){
  365. $element= $this->getElementTodo($IdTodo, $IdProject);
  366. $html= array(
  367. 'type'=>'success',
  368. 'html'=>$element
  369. );
  370. echo json_encode($html);
  371. }
  372. }else{ // Save ToDo
  373. $POST['AddDate']= date("Y-m-d H:i:s");
  374. $insertId= $this->Jmodel->insert('todo', $POST, TRUE);
  375. if( $insertId ){
  376. $element= $this->getElementTodo($insertId, $POST['IdProject']);
  377. $html= array(
  378. 'type'=>'success',
  379. 'html'=>$element
  380. );
  381. echo json_encode($html);
  382. }
  383. }
  384. }
  385. // Get Element HTML dari Todo berdasarkan IdTodo
  386. public function getElementTodo($idTodo="", $IdProject=""){
  387. $where= array('Id'=>$idTodo);
  388. $todo= $this->db->get_where('todo', $where)->row_array();
  389. $extraAttr= array();
  390. $labelClass= "";
  391. if( $todo['Status'] == "yes" ){
  392. $extraAttr['checked']= 'checked';
  393. $labelClass= " complete-todos";
  394. }
  395. $attr_checkbox= array(
  396. 'name'=>'todo'.$todo['Id'],
  397. 'value'=>$todo['Id'],
  398. 'class'=>'todos'
  399. );
  400. $attr_checkbox= array_merge($attr_checkbox, $extraAttr);
  401. $html= '
  402. <div class="todos-row">
  403. <span class="btnactions">
  404. <a class="btn todos-btn todos-edit" href="' . site_url("project/todo") . "/" . $IdProject .
  405. '/edit/' . $idTodo . '">
  406. <i class="icon-pencil"></i>
  407. </a>
  408. <a class="btn todos-btn todos-delete" href="' . site_url("project/todo") . "/" . $IdProject .
  409. '/delete/' . $idTodo . '">
  410. <i class="icon-trash"></i>
  411. </a>
  412. </span>
  413. <label class="checkbox checkbox-tags' . $labelClass . '">' .
  414. form_checkbox($attr_checkbox) .
  415. '<span>' . $todo['Task'] . '</span>
  416. <span class="label label-warning">' . date("l, d F Y h:i A", strtotime($todo['DueDate'])) . '</span>' .
  417. '</label>' .
  418. '</div>';
  419. return $html;
  420. }
  421. // Show Employee Detail
  422. public function employee_detail($Username=""){
  423. $Username= urldecode($Username);
  424. // Get Data User Detail
  425. $sql= "SELECT * FROM user a
  426. LEFT JOIN user_detail b ON b.Id= a.IdDetail
  427. WHERE a.Username= '" . $Username . "'";
  428. $user= $this->db->query($sql)->row_array();
  429. // Table Description
  430. $description_user= array('Name'=>'Name', 'Address'=>'Address',
  431. 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
  432. foreach( $description_user as $key=>$value ){
  433. $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
  434. $user[$key]= $userdt;
  435. }
  436. $config= $this->config;
  437. $data= array();
  438. $data['bar_path']= $config->item('loading');
  439. $data['jscript']= $this->load->view('js/profile', $data, TRUE);
  440. $data['img_path']= $config->item('img_path');
  441. $data['description_user']= $description_user;
  442. $data['user']= $user;
  443. $this->themelib->getpage("user/profile", $data, "inc/theme_main");
  444. }
  445. // Show List of Employees
  446. public function employees($nopage="", $sorting=""){
  447. $POST= $this->input->post();
  448. $url= explode("&", $sorting);
  449. // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
  450. // Set Filter Searching
  451. $filter_params= $this->themelib->get_filter_params($url, $POST);
  452. extract($filter_params); // Variable Extact( sorting, filter_str, filter )
  453. // Set Default / Sorting
  454. $sorting= ( empty($sorting) ) ? "a.Username=ASC" : urldecode($sorting);
  455. $sort= explode("=", $sorting);
  456. // Get Seluruh Data Employees
  457. $employees= $this->Jmodel->getEmployees("", "", $sort, $filter);
  458. $jml= count($employees);
  459. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  460. $numpage= $nopage;
  461. $nopage= (int)$nopage-1;
  462. $perpage= 12;
  463. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  464. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  465. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  466. // dan tidak Ada $POST Searching
  467. if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
  468. redirect("employees/1"); // Redirect ke First Page
  469. }
  470. // Pagination Config
  471. $config['base_url'] = site_url() . 'employees';
  472. $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
  473. $config['total_rows'] = $jml;
  474. $config['per_page'] = $perpage;
  475. $config['use_page_numbers'] = FALSE;
  476. $config['uri_segment']= 2; // Pengenal URI Active Page
  477. $config['first_url']= 1;
  478. $this->pagination->initialize($config);
  479. // Jika User Melakukan Searching tidak dari Halaman 1
  480. if( ! empty($POST) && ! empty($nopage) ){
  481. redirect('employees/1/' . urlencode($sorting) . "&" . $filter_str);
  482. }
  483. // Get Data Project from DB sesuai dengan current Page
  484. $employees= $this->Jmodel->getEmployees($perpage, $offset, $sort, $filter);
  485. $description= array("Name", "Description");
  486. // Fields for Searching Filter
  487. $fields= array(
  488. 'a.Username'=>'Username',
  489. 'b.Name'=>'Name',
  490. 'c.Description'=>'Usertype'
  491. );
  492. $operator= $this->themelib->operator_search; // Get Operator Searching
  493. $config= $this->config;
  494. $data= array();
  495. $data['bar_path']= $config->item('loading');
  496. $data['jscript']= $this->load->view('js/filter', $data, TRUE);
  497. $data['img_path']= $config->item('img_path');
  498. $data['employees']= $employees;
  499. $data['description']= $description;
  500. $data['searching_fields']= $fields;
  501. $data['operator']= $operator;
  502. $data['pagination']= $this->pagination->create_links();
  503. $this->themelib->getpage("employees", $data, "inc/theme_main");
  504. }
  505. // Halaman Edit Profile Detail
  506. public function edit_profile($Username=""){
  507. if( ! empty($Username) ){
  508. $Username= urldecode($Username);
  509. }else{
  510. $Username= $this->session->userdata('Username');
  511. }
  512. $Id= $this->session->userdata('Id');
  513. // Get Data User Detail
  514. $sql= "SELECT * FROM user a
  515. LEFT JOIN user_detail b ON b.Id= a.Id
  516. WHERE a.Username= '" . $Username . "'";
  517. $user= $this->db->query($sql)->row_array();
  518. // Table Description
  519. $labels= array('Name'=>'Nama', 'Address'=>'Alamat', 'Gender'=>'Jenis Kelamin',
  520. 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak', 'Image'=>'Gambar');
  521. $feedback= "";
  522. if( empty($user) ){
  523. $feedback= "User " . $Username . " tidak ada.";
  524. }
  525. /* echo "<pre>";
  526. print_r($user);
  527. echo "</pre>";
  528. exit;*/
  529. $config= $this->config;
  530. $data= array();
  531. $data['bar_path']= $config->item('loading');
  532. $data['jscript']= "";
  533. $data['img_path']= $config->item('img_path');
  534. $data['user']= $user;
  535. $data['labels']= $labels;
  536. $data['feedback']= $feedback;
  537. $data['userId']= $Id;
  538. echo $this->load->view("user/edit_profile", $data, TRUE);
  539. /*$this->themelib->getpage("user/edit_profile", $data, "inc/theme_main");*/
  540. }
  541. // Halaman View Profile Detail
  542. public function profile($type=""){
  543. if( empty($type) ){
  544. $Username= $this->session->userdata('Username');
  545. // Get Data User Detail
  546. $sql= "SELECT * FROM user a
  547. LEFT JOIN user_detail b ON b.Id= a.Id
  548. WHERE a.Username= '" . $Username . "'";
  549. $user= $this->db->query($sql)->row_array();
  550. // Table Description
  551. $description_user= array('Name'=>'Name', 'Address'=>'Address',
  552. 'Gender'=>'Jenis Kelamin', 'DateOfBirth'=>'Tanggal Lahir', 'Contacts'=>'Kontak');
  553. foreach( $description_user as $key=>$value ){
  554. $userdt= ( empty($user[$key]) ) ? "-" : $user[$key];
  555. $user[$key]= $userdt;
  556. }
  557. /* echo "<pre>";
  558. print_r($user);
  559. echo "</pre>";
  560. exit;*/
  561. $config= $this->config;
  562. $data= array();
  563. $data['bar_path']= $config->item('loading');
  564. $data['jscript']= $this->load->view('js/profile', $data, TRUE);
  565. $data['img_path']= $config->item('img_path');
  566. $data['description_user']= $description_user;
  567. $data['user']= $user;
  568. $this->themelib->getpage("user/profile", $data, "inc/theme_main");
  569. }else{
  570. $POST= $this->input->post();
  571. /* print_r($POST);
  572. print_r($_FILES);
  573. exit;*/
  574. foreach( $_FILES as $key=>$value ){
  575. $$key= $value;
  576. }
  577. $act_image= FALSE;
  578. if( !empty($Image['name']) ){
  579. // File Image tidak boleh lebih dari 2MB
  580. $maxsize= 2000000;
  581. if( $Image['size'] > $maxsize ){
  582. echo "File tidak boleh lebih dari 2MB !";
  583. exit;
  584. }
  585. // Cek Extension
  586. $image_ext= pathinfo($Image['name'], PATHINFO_EXTENSION);
  587. $reg_image= "#^(jpeg|jpg|png)$#";
  588. if( ! preg_match($reg_image, $image_ext) ){
  589. echo "File harus gambar ( jpeg|jpg|png ) !";
  590. exit;
  591. }
  592. $Username= $this->session->userdata('Username');
  593. $filename= $Username . "_avatar." . $image_ext;
  594. $tmp_file= $Image['tmp_name'];
  595. $fullpath= $this->config->item('assets_img') . "user/" . $filename;
  596. if( move_uploaded_file($tmp_file, $fullpath) ){
  597. $config['image_library'] = 'gd2';
  598. $config['source_image'] = $fullpath;
  599. $config['create_thumb'] = FALSE;
  600. $config['maintain_ratio'] = FALSE;
  601. $config['width'] = 200;
  602. $config['height'] = 200;
  603. $this->load->library('image_lib', $config);
  604. // Resize Image
  605. if( ! $this->image_lib->resize() ){
  606. echo "Resize File tidak berhasil. Silakan Coba Lagi !";
  607. exit;
  608. }else{
  609. $act_image= TRUE;
  610. }
  611. }else{
  612. echo "Error terjadi, Silakan coba lagi !";
  613. exit;
  614. }
  615. }
  616. if( $act_image ){
  617. $POST['Image']= $filename;
  618. }
  619. /*$POST['Id']= '10';*/
  620. $POST['DateOfBirth']= ( empty($POST['DateOfBirth']) ) ? "" : date('Y-m-d', strtotime($POST['DateOfBirth']));
  621. /*$POST['DateOfBirth']= date('Y-m-d', strtotime($POST['DateOfBirth']));*/
  622. /* echo $POST['DateOfBirth'];
  623. exit;*/
  624. /* print_r($POST);
  625. exit;*/
  626. $sql= "SELECT * FROM user a
  627. INNER JOIN user_detail b ON b.Id= a.Id
  628. WHERE a.Id= '" . $POST['Id'] . "'";
  629. $row= $this->db->query($sql)->row_array();
  630. if( empty($row) ){
  631. // Insert Data to user_detail
  632. $ins_detail= $POST;
  633. unset($ins_detail['Username']);
  634. $this->Jmodel->insert('user_detail', $ins_detail);
  635. /* $ins_user= array('IdDetail'=>$insert_id);
  636. $where= array('Id'=>$POST['Id']);
  637. $this->Jmodel->update('user', $ins_user, $where);*/
  638. }else{
  639. /* print_r($upd_detail);
  640. exit; */
  641. // Update Data user_detail
  642. $upd_detail= $POST;
  643. unset($upd_detail['Id']);
  644. $where= array('Id'=>$POST['Id']);
  645. $this->Jmodel->update('user_detail', $upd_detail, $where);
  646. }
  647. echo "success";
  648. exit;
  649. }
  650. }
  651. // Remove Tag / Untag
  652. public function untag(){
  653. $POST= $this->input->post();
  654. // Cek Apa Tag tsb di-tag pada Project
  655. $where= array('Project_ID'=>$POST['IdProject']);
  656. $sql= "SELECT * FROM project
  657. WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag LIKE '%" . $POST['IdTag'] . "%'";
  658. $query= $this->db->query($sql);
  659. $row= $query->row_array();
  660. // Remove Tag
  661. $IdTag= array();
  662. $IdTag= $row['IdTag'];
  663. $IdTag= array_flip(explode(",", $IdTag));
  664. unset($IdTag[$POST['IdTag']]);
  665. $IdTag= array_flip($IdTag);
  666. // Update DBase
  667. $data= array('IdTag'=>implode(",",$IdTag));
  668. if( $this->Jmodel->update('project', $data, $where) ){
  669. echo "success";
  670. exit;
  671. };
  672. /* echo "<pre>";
  673. print_r($IdTag);
  674. echo "</pre>";
  675. exit; */
  676. }
  677. // Add Tag to Project
  678. public function tag(){
  679. $POST= $this->input->post();
  680. // Get Data IdTag Field Sebelumnya
  681. /*$POST['IdProject']= '46';*/
  682. $where= array('Project_ID'=>$POST['IdProject']);
  683. $sql= "SELECT * FROM project
  684. WHERE Project_ID='" . $POST['IdProject'] . "' AND IdTag NOT LIKE '%" . $POST['IdTag'] . "%'";
  685. $query= $this->db->query($sql);
  686. $row= $query->row_array();
  687. // Jika tidak kosong tambahkan dengan data sebelumnya
  688. if( ! empty($row['IdTag']) ){
  689. $POST['IdTag']= $row['IdTag'] . "," . $POST['IdTag'];
  690. }
  691. // Update
  692. unset($POST['IdProject']);
  693. if( $this->Jmodel->update('project', $POST, $where) ){
  694. echo "success";
  695. exit;
  696. }
  697. /* echo "<pre>";
  698. print_r($POST);
  699. echo "</pre>";
  700. exit;*/
  701. }
  702. // View Untuk Add New Tag ( ColorPicker )
  703. public function addtag(){
  704. $config= $this->config;
  705. $data= array();
  706. $data['bar_path']= $config->item('loading');
  707. $data['main_url']= base_url();
  708. $html= $this->load->view("tag/create", $data, TRUE);
  709. echo $html;
  710. /*$this->themelib->getpage("tag/create", $data, "inc/theme_main");*/
  711. }
  712. // Get Current Tag yang baru di-create
  713. public function get_tag(){
  714. $POST= $this->input->post();
  715. $POST['tagName']= strtoupper($POST['tagName']);
  716. // Get Current Tag yang baru di-create
  717. $where= array('tagName'=>$POST['tagName']);
  718. $tag= $this->db->get_where('tag', $where)->row_array();
  719. // Create Group Checkbox Tag
  720. $attr_checkbox= array(
  721. 'name'=>$tag['tagName'].'[name]',
  722. 'value'=>$tag['tagName'],
  723. 'class'=>'tags'
  724. );
  725. $prev_tags= '<label class="checkbox">';
  726. $prev_tags.= form_checkbox($attr_checkbox);
  727. $prev_tags.= form_hidden($tag['tagName'].'[color]', $tag['tagColor']);
  728. $prev_tags.= $tag['tagName'];
  729. $prev_tags.= '</label>';
  730. echo $prev_tags;
  731. /* $tags= $this->db->get("tag")->result_array();
  732. $prev_tags= "";
  733. foreach( $tags as $tag ){
  734. $prev_tags.= '<label class="checkbox">' .
  735. '<input type="checkbox" name="tagName" value="' . $tag['tagName'] . '">' . $tag['tagName'] .
  736. '</label>';
  737. }*/
  738. /*echo json_encode($tags);*/
  739. }
  740. // Save / Process to Database
  741. public function savetag(){
  742. $POST= $this->input->post();
  743. $POST['tagName']= strtoupper($POST['tagName']);
  744. /* echo "<pre>";
  745. print_r($POST);
  746. echo "</pre>";
  747. exit;*/
  748. // Check Apakah Tag Name sudah digunakan
  749. $where= array('tagName'=>$POST['tagName']);
  750. if( $this->db->get_where('tag', $where)->num_rows() ){
  751. echo "Tag dengan nama tersebut sudah ada.";
  752. exit;
  753. }
  754. // Insert to Database
  755. if( $this->Jmodel->insert('tag', $POST) ){
  756. echo "success";
  757. exit;
  758. }
  759. }
  760. // Add New Tag ( ColorPicker )
  761. public function colorPicker(){
  762. $config= $this->config;
  763. $data= array();
  764. $data['bar_path']= $config->item('loading');
  765. $data['main_url']= base_url();
  766. $this->themelib->getpage("test", $data, "inc/theme_main");
  767. }
  768. // Get List Of Template
  769. public function template_all($param="page", $nopage="", $sorting=""){
  770. $POST= $this->input->post();
  771. $url= explode("&", $sorting);
  772. // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
  773. // Set Filter Searching
  774. $filter_params= $this->themelib->get_filter_params($url, $POST);
  775. extract($filter_params); // Variable Extact( sorting, filter_str, filter )
  776. // Set Default / Sorting
  777. $sorting= ( empty($sorting) ) ? "Name=ASC" : urldecode($sorting);
  778. $sort= explode("=", $sorting);
  779. // Get Jumlah Project List
  780. $jml= $this->Jmodel->getData("project_template", "", "", $sort, $filter, true);
  781. // Process Per-page dan Offset
  782. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  783. $numpage= $nopage;
  784. $nopage= (int)$nopage-1;
  785. $perpage= 5;
  786. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  787. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  788. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  789. // dan tidak Ada $POST Searching
  790. if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
  791. redirect("project/template_all");
  792. }
  793. // Pagination Config
  794. $config['base_url'] = base_url() . 'project/template_all/page';
  795. $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
  796. $config['total_rows'] = $jml;
  797. $config['per_page'] = $perpage;
  798. $config['use_page_numbers'] = FALSE;
  799. $config['uri_segment']= 4; // Pengenal URI Active Page
  800. $config['first_url']= 1;
  801. $this->pagination->initialize($config);
  802. // Jika User Melakukan Searching tidak dari Halaman 1
  803. if( ! empty($POST) && !empty($nopage) ){
  804. redirect('project/template_all/page/1/' . urlencode($sorting) . "&" . $filter_str);
  805. }
  806. // Get Data Project from DB sesuai dengan current Page
  807. $rows= $this->Jmodel->getData("project_template", $perpage, $offset, $sort, $filter);
  808. $list= array();
  809. if( ! empty($rows) ){
  810. // Get IdTemplate Untuk SQL Condition
  811. $data_in= array();
  812. foreach( $rows as $row ){
  813. $data_in[]= $row['Id'];
  814. }
  815. $IdTemplate= "'" . implode("','", $data_in) . "'";
  816. $operand= "";
  817. if( ! empty($filter) ){
  818. $operand= "AND";
  819. }
  820. // Get Seluruh Data template dan project process
  821. $sql= "SELECT * FROM project_template a
  822. LEFT JOIN pos_menu b ON b.IdTemplate= a.Id
  823. WHERE a.Id IN(" . $IdTemplate . ") " . $operand . " {condition}
  824. ORDER BY {sorting}, b.Urutan";
  825. $rows= $this->Jmodel->getData("", "", "", $sort, $filter, false, $sql);
  826. // Modify List untuk dipakai pada Perulangan
  827. foreach( $rows as $row ){
  828. $list[$row['Name']][]= $row;
  829. }
  830. }
  831. // Fields for Searching Filter
  832. $fields= array(
  833. 'Name'=>'Template Name'
  834. );
  835. $operator= $this->themelib->operator_search; // Get Operator Searching
  836. // Current Page
  837. $curpage= $this->uri->segment(4);
  838. /* echo "<pre>";
  839. print_r($list);
  840. echo "</pre>";
  841. exit;*/
  842. $rows= array();
  843. $config= $this->config;
  844. $data= array();
  845. $data['bar_path']= $config->item('loading');
  846. $data['main_url']= base_url();
  847. /*$data['jscript']= '';*/
  848. $data['jscript']= $this->load->view('js/filter', $data, TRUE);
  849. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  850. $data['rows']= $list;
  851. $data['pagination']= $this->pagination->create_links();
  852. $data['hrefNewProject']= site_url() . "project/template";
  853. /* Searching Data */
  854. $data['baseurl_sort']= site_url() . "project/template_all";
  855. $data['searching_fields']= $fields;
  856. $data['operator']= $operator;
  857. $data['filter_str']= $filter_str;
  858. $data['nopage']= ( ! empty($curpage) ) ? $curpage : 1;
  859. $this->themelib->getpage("project/template_all", $data, "inc/theme_main");
  860. }
  861. // Create New / Edit Project Template
  862. // Halaman Ini Mengirimkan POST serta Pengeditan pada Halaman dengan Javascript Enabled
  863. public function template($action="", $templateName= ""){
  864. $templateName= urldecode($templateName);
  865. if( $action == "edit" ){
  866. // Get Data Template
  867. $where= array('Name'=>$templateName);
  868. $template= $this->db->get_where("project_template", $where)->row_array();
  869. // Get Data Step Process
  870. $where= array('IdTemplate'=>$template['Id']);
  871. $this->db->order_by('Urutan ASC');
  872. $process= $this->db->get_where("pos_menu", $where)->result_array();
  873. /* echo "<pre>";
  874. print_r($template);
  875. print_r($process);
  876. echo "</pre>";
  877. exit; */
  878. $config= $this->config;
  879. $data= array();
  880. $data['bar_path']= $config->item('loading');
  881. $data['main_url']= base_url();
  882. $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
  883. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  884. $data['template']= $template;
  885. $data['process']= $process;
  886. $this->themelib->getpage("project/template_edit", $data, "inc/theme_main");
  887. }elseif( $action == "delete" ){
  888. // Get Id Template
  889. $where= array('Name'=>$templateName);
  890. $template= $this->db->get_where('project_template', $where)->row_array();
  891. $where= array('IdTemplate'=>$template['Id']);
  892. $jml= $this->db->get_where('project', $where)->num_rows();
  893. if( $jml ){
  894. echo json_encode(array('type'=>'error',
  895. 'msg'=>"Template tidak bisa di-hapus !\nTemplate sudah digunakan pada Project."));
  896. }else{
  897. // Delete Data pada Tabel project_template dan pos_menu
  898. $where_project_template= array('Id'=>$template['Id']);
  899. if( $this->db->delete('project_template', $where_project_template) ){
  900. echo json_encode(array('type'=>'success',
  901. 'msg'=>"Data has been delete"));
  902. }
  903. }
  904. }else{
  905. $config= $this->config;
  906. $data= array();
  907. $data['bar_path']= $config->item('loading');
  908. $data['main_url']= base_url();
  909. $data['jscript']= $this->load->view("js/project_template.php", $data, TRUE);
  910. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  911. $this->themelib->getpage("project/template", $data, "inc/theme_main");
  912. }
  913. }
  914. // Edit And Delete Template
  915. public function action_template($action){
  916. $POST= $this->input->post();
  917. /* print_r($POST);
  918. exit;*/
  919. if( $action == "edit" ){
  920. // Group Data New Process yang akan ditambahkan
  921. $newProcess= array();
  922. if( isset($POST['process']) ){
  923. extract($POST['process']);
  924. foreach( $Name as $key=>$value ){
  925. $data= array();
  926. $data['Process_Name']= $value;
  927. $data['Score_Completion']= $Score[$key];
  928. $data['Urutan']= $Urutan[$key];
  929. $data['IdTemplate']= $POST['template']['Id'];
  930. $newProcess[]= $data;
  931. }
  932. }
  933. // Get Previous Process POST
  934. $prevProcess= $POST['prev_process'];
  935. // Get Previous Process di DBase
  936. $where= array('IdTemplate'=>$POST['template']['Id']);
  937. $dbProcess= $this->db->get_where('pos_menu', $where)->result_array();
  938. // Get Data Process yang Harus di-Delete
  939. $delProcess= array();
  940. foreach( $dbProcess as $process ){
  941. if( ! array_key_exists($process['Id'], $prevProcess) ){
  942. $this->db->delete('pos_menu', array('Id'=>$process['Id']));
  943. $delProcess[]= $process;
  944. }
  945. }
  946. // Update Previous Process
  947. $dtUpdate= array();
  948. foreach( $prevProcess as $list ){
  949. $dtUpdate['Process_Name']= $list['Name'];
  950. $dtUpdate['Score_Completion']= $list['Score'];
  951. $dtUpdate['Urutan']= $list['Urutan'];
  952. $where= array('Id'=>$list['Id']);
  953. $this->Jmodel->update('pos_menu', $dtUpdate, $where);
  954. }
  955. // Insert New Process
  956. foreach( $newProcess as $list ){
  957. $this->Jmodel->insert('pos_menu', $list);
  958. }
  959. if( $POST['type'] == "ajax" ){
  960. echo "success";
  961. exit;
  962. }
  963. /* echo "<pre>";
  964. print_r($process);
  965. print_r($prevProcess);
  966. print_r($newProcess);
  967. print_r($delProcess);
  968. echo "</pre>";
  969. exit;*/
  970. }else{
  971. }
  972. }
  973. // Create New Project Template
  974. public function create_template(){
  975. $POST= $this->input->post();
  976. // Cek Jika Template dengan Nama tsb tidak Ada
  977. $template= array('Name'=>$POST['template_name']);
  978. if( $this->db->get_where('project_template', $template)->num_rows() ){
  979. if( $POST['type'] == "ajax" ){
  980. echo "Template dengan nama tersebut sudah Ada !";
  981. exit;
  982. }else{
  983. $this->session->set_userdata('error', 'Template dengan nama tersebut sudah Ada !');
  984. redirect('project/template_all');
  985. }
  986. }
  987. // Extract process dari parameter POST
  988. extract($POST['process']);
  989. // Gabungkan Array Process dan Score
  990. $posmenu= array();
  991. $urut= 1;
  992. foreach( $Name as $key=>$value ){
  993. $posmenu[$key]= array('Process_Name'=>$value, 'Score_Completion'=>$Score[$key],
  994. 'Urutan'=>$Urutan[$key]);
  995. $urut++;
  996. }
  997. /* echo "<pre>";
  998. print_r($posmenu);
  999. echo "</pre>";
  1000. exit;*/
  1001. // Insert Template to Database
  1002. $template= array('Name'=>$POST['template_name']);
  1003. $insert_id= $this->Jmodel->insert("project_template", $template, true);
  1004. if( $insert_id ){
  1005. foreach( $posmenu as $row ){
  1006. $row['IdTemplate']= $insert_id;
  1007. $this->Jmodel->insert('pos_menu', $row);
  1008. }
  1009. }
  1010. if( $POST['type'] == "ajax" ){
  1011. echo "success";
  1012. exit;
  1013. }else{
  1014. redirect('project/template_all');
  1015. }
  1016. }
  1017. public function getPassword(){
  1018. $this->load->view("");
  1019. echo md5('sales_admin');
  1020. }
  1021. public function select_template(){
  1022. $rows= $this->db->get('project_template')->result_array();
  1023. $template= array();
  1024. $template[""]= "-- Select --";
  1025. foreach( $rows as $row ){
  1026. $template[$row['Id']]= $row['Name'];
  1027. }
  1028. $config= $this->config;
  1029. $data= array();
  1030. $data['bar_path']= $config->item('loading');
  1031. $data['main_url']= base_url();
  1032. $data['jscript']= $this->load->view("js/select_template.php", $data, TRUE);
  1033. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1034. $data['template']= $template;
  1035. $data['hrefAction']= base_url() . "setting/summary";
  1036. $this->themelib->getpage("project/select_template", $data, "inc/theme_main");
  1037. }
  1038. // Create And Edit Setting Summary
  1039. // @param1 string berisi 'summary',
  1040. // @param2 int berisi IdTemplate u/ ByPass Ketika User klik Save Redirect Langsung ke halaman Ini
  1041. public function setting($param="", $IdTemplate=""){
  1042. $POST= $this->input->post();
  1043. if( ! empty($POST) ){
  1044. extract($POST);
  1045. }
  1046. // Jika Tidak Ada IdTemplate Redirect untuk select Template
  1047. if( ! isset($IdTemplate) || empty($IdTemplate) ){
  1048. redirect("project/select_template");
  1049. }
  1050. // Get Previous Setting Summary
  1051. $Username= $this->session->userdata("Username");
  1052. $where= array("Username"=>$Username, "IdTemplate"=>$IdTemplate);
  1053. $rows= $this->db->get_where("summary", $where)->result_array();
  1054. if( count($rows) ){
  1055. $summaries= array();
  1056. foreach( $rows as $row ){
  1057. $summaryFields= unserialize($row['summaryFields']);
  1058. $summaries[$row['Posmenu_ID']]= $summaryFields;
  1059. }
  1060. }
  1061. // Get Seluruh Field pada setiap Process berdasarkan Template Yang di-Select
  1062. $sql= "SELECT a.Id AS IdProcess, a.Process_Name, a.Table, b.* FROM pos_menu a
  1063. LEFT JOIN form_fields b ON b.FormID= a.FormID
  1064. WHERE ( b.Name!= 'Project_ID' OR b.Name IS NULL ) AND a.IdTemplate= '" . $IdTemplate . "'
  1065. ORDER BY a.Id";
  1066. $rows= $this->db->query($sql)->result_array();
  1067. $process= array();
  1068. $description= array();
  1069. foreach( $rows as $row ){
  1070. if( !empty($row["Name"]) ){
  1071. $process[$row["IdProcess"]][]= $row;
  1072. $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
  1073. $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
  1074. }else{
  1075. $process[$row["IdProcess"]]= array();
  1076. $description[$row["IdProcess"]]["Process_Name"]= $row["Process_Name"];
  1077. $description[$row["IdProcess"]]["Id"]= $row["IdProcess"];
  1078. }
  1079. }
  1080. /* echo "<pre>";
  1081. print_r($POST);
  1082. print_r($description);
  1083. echo "</pre>";
  1084. exit;*/
  1085. $config= $this->config;
  1086. $data= array();
  1087. $data['bar_path']= $config->item('loading');
  1088. $data['main_url']= base_url();
  1089. $data['jscript']= "";
  1090. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1091. $data["process"]= $process;
  1092. $data["description"]= $description;
  1093. $data['summaries']= ( isset($summaries) ) ? $summaries : "";
  1094. $data['IdTemplate']= $IdTemplate;
  1095. $this->themelib->getpage("project/setting_summary", $data, "inc/theme_main");
  1096. }
  1097. // Processing Summary
  1098. public function set_summary(){
  1099. /* echo "<pre>";
  1100. print_r($jml);
  1101. echo "</pre>";
  1102. exit;*/
  1103. $POST= $this->input->post();
  1104. $Username= $this->session->userdata("Username");
  1105. $IdTemplate= $POST['IdTemplate'];
  1106. // Check If Data is exist remove it first
  1107. $jml= $this->db->get_where('summary', array('Username'=>$Username, 'IdTemplate'=>$IdTemplate))->num_rows();
  1108. if( $jml ){
  1109. $this->db->where(array('Username'=>$Username, 'IdTemplate'=>$IdTemplate));
  1110. $this->db->delete('summary');
  1111. }
  1112. // Insert Score
  1113. $scoreData= array();
  1114. $scoreData['Username']= $Username;
  1115. $scoreData['summaryFields']= serialize($POST['score']);
  1116. $scoreData['Posmenu_ID']= '0';
  1117. $scoreData['IdTemplate']= $IdTemplate;
  1118. $this->Jmodel->insert("summary", $scoreData);
  1119. // Insert Semua Data Summary ke Tabel summary
  1120. foreach( $POST['Process'] as $key=>$process ){
  1121. $insData= array();
  1122. $insData['Username']= $Username;
  1123. $insData['summaryFields']= serialize($process);
  1124. $insData['Posmenu_ID']= $key;
  1125. $insData['IdTemplate']= $IdTemplate;
  1126. $this->Jmodel->insert("summary", $insData);
  1127. }
  1128. // Set Feedback and Redirect
  1129. $this->session->set_userdata('feedback','The changes has been saved !');
  1130. redirect("project/setting/summary/" . $IdTemplate);
  1131. }
  1132. public function getdata(){
  1133. $data= $this->db->get_where("project_process", array("Id"=>"3"))->row_array();
  1134. $row= unserialize($data["formValue"]);
  1135. echo "<pre>";
  1136. print_r($row);
  1137. echo "</pre>";
  1138. }
  1139. // Create Project
  1140. public function index($params=""){
  1141. $rows= $this->db->get('project_template')->result_array();
  1142. $template= array();
  1143. $template[""]= "-- Select --";
  1144. foreach( $rows as $row ){
  1145. $template[$row['Id']]= $row['Name'];
  1146. }
  1147. /* echo "<pre>";
  1148. print_r($template);
  1149. echo "</pre>";
  1150. exit;*/
  1151. $config= $this->config;
  1152. $data= array();
  1153. $data['bar_path']= $config->item('loading');
  1154. $data['main_url']= base_url();
  1155. $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
  1156. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1157. $data['template']= $template;
  1158. $POST= $this->input->post();
  1159. if( isset($POST["submit"]) || $POST["type"] == "ajax" ){
  1160. // Set Rules Validasi
  1161. $config= array(
  1162. array(
  1163. 'field'=> 'Project_Name',
  1164. 'label'=> 'Project Name',
  1165. 'rules'=> 'required'
  1166. ),
  1167. array(
  1168. 'field'=> 'Identitas_Perusahaan',
  1169. 'label'=> 'Identitas Perusahaan',
  1170. 'rules'=> 'required'
  1171. )
  1172. );
  1173. $this->form_validation->set_rules($config);
  1174. if( $this->form_validation->run() == TRUE ){ // Cek Validasi
  1175. $type= isset($POST["type"]) ? $POST["type"] : "";
  1176. // Set Data
  1177. $POST["Username"]= $this->session->userdata("Username");
  1178. // Cek Project Name ada atau tidak dengan GroupName tsb
  1179. // karena ada 2 User Type yaitu Admin dan Sales yang bisa mengakses project yg sama
  1180. $where= array("Username"=>$POST["Username"], "Project_Name"=>$POST["Project_Name"]);
  1181. $exist= $this->db->get_where("project", $where)->num_rows();
  1182. if( ! $exist ){
  1183. unset($POST["submit"], $POST["type"]); // Unset Data
  1184. // Insert Data to DB
  1185. if( $this->db->insert("project", $POST) ){
  1186. if( $type == "ajax" ){
  1187. echo "success";
  1188. exit;
  1189. }else{
  1190. $this->session->set_userdata("error_ot","Data has been saved.");
  1191. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1192. }
  1193. }
  1194. }else{
  1195. if( $type == "ajax" ){
  1196. echo "Project Name is already exist.";
  1197. exit;
  1198. }else{
  1199. $this->session->set_userdata("error_ot","Project Name is already exist.");
  1200. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1201. }
  1202. }
  1203. }else{
  1204. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1205. }
  1206. }else{
  1207. $this->themelib->getpage("project/create", $data, "inc/theme_main");
  1208. }
  1209. }
  1210. /* public function formBuilder(){
  1211. $config= $this->config;
  1212. $data= array();
  1213. $data['bar_path']= $config->item('loading');
  1214. $data['main_url']= base_url();
  1215. $data['jscript']= $this->load->view("js/formbuilder.php", $data, TRUE);
  1216. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1217. $this->themelib->getpage("formbuilder", $data);
  1218. }
  1219. public function formBuilder_create(){
  1220. $POST= $this->input->post();
  1221. $config= $this->config;
  1222. $data= array();
  1223. // Cek Data pada Tabel masterform
  1224. $where= array("FormID"=>$POST["FormID"]);
  1225. $jml= $this->db->get_where("masterform", $where)->num_rows();
  1226. if( ! $jml ){ // Jika Data tidak Ada Insert data tsb
  1227. // Insert Data ke Tabel masterform
  1228. $form= array("FormID"=>$POST["FormID"], "ActionUrl"=>"#");
  1229. $this->db->insert("masterform", $form);
  1230. // Insert Data ke Tabel form_fields
  1231. $fields= $POST;
  1232. unset($fields["submit"], $fields["FormID"]);
  1233. foreach( $fields as $key=>$field ){
  1234. $insfield= array();
  1235. $insfield["FormID"]= $POST["FormID"];
  1236. $insfield["Name"]= $key;
  1237. if( $key == "Project_ID" ){
  1238. $insfield["FieldType"]= $field;
  1239. }else{
  1240. $data= explode("~", $field);
  1241. $insfield["FieldType"]= $data[0];
  1242. $insfield["Label"]= $data[1];
  1243. }
  1244. $this->db->insert("form_fields", $insfield);
  1245. }
  1246. redirect("project/formBuilder");
  1247. }else{ // Jika Data Ada Redirect dan display error
  1248. $this->session->set_userdata("error", "Form dengan ID tersebut sudah Ada.");
  1249. redirect("project/formBuilder");
  1250. }
  1251. }
  1252. */
  1253. // Create Project
  1254. public function edit($IdProject=""){
  1255. // Check Project
  1256. $where= array("Project_ID"=>$IdProject);
  1257. $query= $this->db->get_where("project", $where);
  1258. $jml= $query->num_rows();
  1259. if( empty($jml) ){
  1260. redirect("project/daftar");
  1261. }else{
  1262. $config= $this->config;
  1263. $data= array();
  1264. $data['bar_path']= $config->item('loading');
  1265. $data['main_url']= base_url();
  1266. $data['jscript']= $this->load->view("js/create_pro.php", $data, TRUE);
  1267. /*$data['jscript']= "";*/
  1268. $data['menu']= $this->load->view("inc/menu.php", $data, TRUE);
  1269. $data['row']= $query->row_array();
  1270. $this->db->flush_cache();
  1271. $this->themelib->getpage("project/edit", $data, "inc/theme_main");
  1272. }
  1273. }
  1274. public function daftar($param="page", $nopage="", $sorting=""){
  1275. // Get Jumlah Baris dari tabel Project dengan GroupName yang sama
  1276. $Username= $this->session->userdata("Username");
  1277. /*$Username= "sales";*/
  1278. $POST= $this->input->post();
  1279. $url= explode("&", $sorting);
  1280. // Parsing Url Sorting dan Filter ( Jika Sorting dan Filter dimasukan pada URL setelah submit ditekan )
  1281. // Set Filter Searching
  1282. $filter_params= $this->themelib->get_filter_params($url, $POST);
  1283. extract($filter_params); // Variable Extact( sorting, filter_str, filter )
  1284. /* echo "<pre>";
  1285. print_r($filter_params);
  1286. echo "</pre>";*/
  1287. /*exit;*/
  1288. /* $sorting= $url[0];
  1289. $filter_url= ( isset($url[1]) ) ? $url[1] : "";
  1290. $filter_str= ""; //
  1291. if( isset($POST['btnSubmit']) ){
  1292. // Set Limit to default
  1293. $nopage= 1;
  1294. // Set Filter properties dan set $filter_str untuk dimasukan ke url pagination
  1295. $filter= array('field'=>$POST['search'], 'op'=>$POST['op_search'], 'key'=>$POST['search_key']);
  1296. foreach( $filter as $key=>$value ){
  1297. $filter[$key]= urlencode($value);
  1298. }
  1299. $filter_str= implode(":", $filter);
  1300. }else{
  1301. // Set Filter dari Pagination Url
  1302. $filter= "";
  1303. if( ! empty($filter_url) ){
  1304. $filter_str= $filter_url;
  1305. $filter_url= explode(":", $filter_url);
  1306. $filter= array('field'=>$filter_url[0], 'op'=>$filter_url[1], 'key'=>$filter_url[2]);
  1307. }
  1308. }*/
  1309. // Set Default / Sorting
  1310. $sorting= ( empty($sorting) ) ? "Project_Name=ASC" : urldecode($sorting);
  1311. $sort= explode("=", $sorting);
  1312. // Get Jumlah Project List
  1313. $rows= $this->Jmodel->getProjectByUsertype($Username, "", "", "", $filter, TRUE);
  1314. $jml= count($rows);
  1315. // Get Offset, Jumlah Page
  1316. $nopage= ( empty($nopage) ) ? 1 : $nopage;
  1317. $numpage= $nopage; // Get Number Page from URL
  1318. $nopage= (int)$nopage-1;
  1319. $perpage= 5;
  1320. $offset= $nopage * $perpage; // Nilai Offset u/ Query
  1321. $jml_page= ceil($jml / $perpage); // Jumlah Halaman
  1322. // Jika Halaman lebih dari Jumlah Halaman atau Negative Page
  1323. // dan tidak Ada $POST Searching
  1324. /* echo "<pre>";
  1325. if( ! $numpage < 1 ){
  1326. echo $numpage . "->" . $jml_page . "<br/>";
  1327. }
  1328. print_r($POST);
  1329. echo "</pre>";*/
  1330. if( ( $numpage > $jml_page || $numpage < 1 ) && empty($POST) ){
  1331. redirect("project/daftar"); // Redirect ke First Page
  1332. }
  1333. /* echo $filter_str;
  1334. exit;*/
  1335. // Pagination Config
  1336. $config['base_url'] = site_url('project/daftar/page');
  1337. $config['suffix']= "/" . urlencode($sorting) . "&" . $filter_str;
  1338. $config['total_rows'] = $jml;
  1339. $config['per_page'] = $perpage;
  1340. $config['use_page_numbers'] = FALSE;
  1341. $config['uri_segment']= 4; // Pengenal URI Active Page
  1342. $config['first_url']= 1;
  1343. $this->pagination->initialize($config);
  1344. // Jika User Melakukan Searching tidak dari Halaman 1
  1345. if( ! empty($POST) && !empty($nopage) ){
  1346. redirect('project/daftar/page/1/' . urlencode($sorting) . "&" . $filter_str);
  1347. }
  1348. // Get Data Project from DB sesuai dengan current Page
  1349. $getRows= $this->Jmodel->getProjectByUsertype($Username, $perpage, $offset, $sort, $filter);
  1350. // Set Project_Id sebagai Key
  1351. $rows= array();
  1352. foreach( $getRows as $list ){
  1353. $rows[$list['Project_ID']]= $list;
  1354. }
  1355. // Get Summary untuk setiap Project dan di Group Berdasarkan IdTemplate
  1356. // Group Score Berdasarkan IdTemplate
  1357. $dtsummaries= $this->db->get_where('summary', array('Username'=>$Username))->result_array();
  1358. $getsummaries= array();
  1359. $statScore= array();
  1360. foreach( $dtsummaries as $summary ){
  1361. if( $summary['Posmenu_ID'] == "0" ){
  1362. $statScore[$summary['IdTemplate']][]= unserialize($summary['summaryFields']);
  1363. continue;
  1364. }
  1365. $getsummaries[$summary['IdTemplate']][]= $summary;
  1366. }
  1367. // Get summaries and formValue
  1368. $values= array();
  1369. $summaries= array();
  1370. $file= array();
  1371. foreach( $rows as $row ){
  1372. if( isset($getsummaries[$row['IdTemplate']]) ){
  1373. foreach( $getsummaries[$row['IdTemplate']] as $summary ){
  1374. $where= array('Posmenu_ID'=>$summary['Posmenu_ID'], 'Project_ID'=>$row['Project_ID']);
  1375. $getdt= $this->db->get_where('project_process', $where)->row_array();
  1376. $formValue= ( isset($getdt['formValue']) ) ? unserialize($getdt['formValue']) : "";
  1377. // Add formValue Data sesuai Project_ID -> Posmenu_ID
  1378. if( $formValue ){
  1379. // Get Description Type Upload File
  1380. $regfile= "#^.+\..{3,4}$#";
  1381. foreach( $formValue as $formKey=>$form ){
  1382. if( preg_match($regfile, $form) ){
  1383. $where= array('Filename'=>$form);
  1384. $dtfile= $this->db->get_where('upload', $where)->row_array();
  1385. $file[$dtfile['Filename']]= $dtfile;
  1386. /*echo $formKey . "->" . $form . "<br/>";*/
  1387. }elseif($formKey == "PO_ID" ){
  1388. $where= array('Project_ID'=>$row['Project_ID']);
  1389. $poid= $this->db->get_where('po_id', $where)->row_array();
  1390. $formValue[$formKey]= ( isset($poid['PO_ID']) ) ? $poid['PO_ID'] : "";
  1391. }
  1392. }
  1393. $values[$row['Project_ID']][$summary['Posmenu_ID']]= $formValue;
  1394. }
  1395. // Modify Summary Data sesuai Dengan Template Yang Dipilih Untuk Project
  1396. $summary_field= unserialize($summary['summaryFields']);
  1397. $summaries[$row['IdTemplate']][$summary['Posmenu_ID']]= $summary_field;
  1398. }
  1399. }
  1400. }
  1401. // Remove unnecessary Fields / Get Fields sesuai Summary
  1402. foreach( $values as $key=>$value ){
  1403. foreach( $value as $subkey

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