PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/review.php

https://bitbucket.org/prat_h/rakbuku
PHP | 1355 lines | 950 code | 239 blank | 166 comment | 114 complexity | 212e228ebea31b5ef99d6d52d761032b MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. require_once(APPPATH.'controllers/project.php');
  3. class Review extends Project {
  4. public $names = array();
  5. public $dataproj = array();
  6. public $reviewers = array();
  7. public $currreviewers = array();
  8. public $invitation = array();
  9. function __construct() {
  10. parent::__construct();
  11. $this->load->model('reviews_model', 'review');
  12. $this->data['types'] = $this->types->get_types();
  13. $this->data['title'] = 'Invite Reviewer';
  14. $this->data["users"] = $this->user->get_users();
  15. $url = $this->uri->segment(2);
  16. $this->get_project_data($url);
  17. $this->data["jurusan"] = $this->jurusan->get_jurusan();
  18. //echo "nepi ";
  19. $this->laststate = $this->cek_state($this->dataproj[0]["project_id"]);
  20. $match = array_search($this->laststate, $this->defstates);
  21. if( $this->laststate !== "review" && $match ){
  22. $this->redirect_to_state_url($this->laststate, $url);
  23. }
  24. $this->get_project_reviewers($url);
  25. $this->data["current_reviewers"] = $this->currreviewers;
  26. $this->check_invitations($this->dataproj[0]["project_id"]);
  27. $this->data["user_names"] = get_user_names($this->data["users"]);
  28. $this->data['current_project_id'] = $this->dataproj[0]["project_id"];
  29. /* print_r( $this->currreviewers); */
  30. $this->data["self_project"] = is_self_project( $this->dataproj[0]["user_id"], $this->data['current_user_id'] );
  31. if( !is_contributor( $this->dataproj[0]["user_id"], $this->currreviewers, $this->data['current_user_id']) ) {
  32. //echo "dieu";
  33. show_404();
  34. }
  35. }
  36. //print_r($this->names);
  37. /**
  38. * ---------======@[ INDEX ]@======---------
  39. */
  40. public function index() {
  41. if( !is_login($this->data['login']) || ( $this->input->post("project_state") == "" && ($this->laststate != $this->uri->segment( 1 )) ) ){
  42. show_404();
  43. }
  44. //$this->load->view("project/invite_reviewer", $this->data);
  45. }
  46. /**
  47. * ---------======@[ REMAP ROUTE ]@======---------
  48. */
  49. public function _remap( $judul, $bab ) {
  50. if( !is_login( $this->data['login'] ) ){
  51. show_404();
  52. }
  53. //print_r($bab);
  54. $totalsegs = $this->uri->total_segments();
  55. if( !$bab ) {
  56. $this->cek_url_and_dest( $judul );
  57. $this->get_current_type( $this->data["project_data"][0]["type_id"] );
  58. $this->get_author( $this->data["project_data"][0]["user_id"] );
  59. $this->data["author_name"] = get_user_name( $this->data["author"] );
  60. $this->data["author_url"] = get_user_url( $this->data["author"] );
  61. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  62. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  63. $this->get_attachment($this->data["project_data"][0]["project_id"]);
  64. $this->get_reviews($this->data["project_data"][0]["project_id"]);
  65. $this->check_approve_bab( $this->data["project_data"][0]["project_id"] );
  66. if( is_array($this->data["project_data"]) ) {
  67. $this->load->view("project/review", $this->data);
  68. } else {
  69. $method = str_replace(" ", "_", $judul);
  70. if( method_exists($this, $method) ) {
  71. call_user_func_array( array( $this,$method ), array());
  72. } else {
  73. if( $judul == "" ){
  74. call_user_func_array( array( $this,"index" ), array());
  75. }
  76. }
  77. }
  78. } else {
  79. $this->cek_url_and_dest( $bab[0], $judul );
  80. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  81. $this->get_current_type( $this->data["project_parent"][0]["type_id"] );
  82. $this->get_author( $this->data["project_data"][0]["user_id"] );
  83. $this->data["author_name"] = get_user_name( $this->data["author"] );
  84. $this->data["author_url"] = get_user_url( $this->data["author"] );
  85. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  86. $this->get_reviewers( $this->data["project_parent"][0]["project_reviewer"] );
  87. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  88. $this->get_reviews($this->data["project_data"][0]["project_id"]);
  89. if( is_array($this->data["project_data"]) ) {
  90. $this->get_attachment($this->data["project_data"][0]["project_id"]);
  91. $this->load->view("project/review_bab", $this->data);
  92. } else {
  93. $method = str_replace(" ", "_", $bab[0]);
  94. if( $totalsegs >= 3) {
  95. $counter = $totalsegs - 3;
  96. }
  97. $arrarg = array();
  98. for( $i = 0; $i < $counter; $i++ ) {
  99. $arrarg[$i] = $this->uri->segment($i+4);
  100. }
  101. if( method_exists($this, $method) ) {
  102. call_user_func_array( array( $this,$method ), $arrarg);
  103. } else {
  104. if( $bab[0] == "" ){
  105. call_user_func_array( array( $this,"index" ), array());
  106. }
  107. }
  108. }
  109. }
  110. }
  111. /**
  112. * ---------======@[ EDIT PROJECT ]@======---------
  113. */
  114. public function edit_project(){
  115. if (!$this->data["self_project"]) {
  116. show_404();
  117. }
  118. $this->cek_url_and_dest( $this->uri->segment(2) );
  119. $this->get_current_type( $this->data["project_data"][0]["type_id"] );
  120. $this->get_author( $this->data["project_data"][0]["user_id"] );
  121. $this->data["author_name"] = get_user_name( $this->data["author"] );
  122. $this->data["author_url"] = get_user_url( $this->data["author"] );
  123. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  124. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  125. $this->load->view("project/form_edit", $this->data);
  126. }
  127. /**
  128. * ---------======@[ EDIT BAB ]@======---------
  129. */
  130. public function edit_bab(){
  131. if (!$this->data["self_project"]) {
  132. show_404();
  133. }
  134. $this->cek_url_and_dest( $this->uri->segment(4), $this->uri->segment(2) );
  135. $this->get_current_type( $this->data["project_data"][0]["type_id"] );
  136. $this->get_author( $this->data["project_data"][0]["user_id"] );
  137. $this->data["author_name"] = get_user_name( $this->data["author"] );
  138. $this->data["author_url"] = get_user_url( $this->data["author"] );
  139. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  140. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  141. $this->load->view("project/form_edit_bab", $this->data);
  142. }
  143. /**
  144. * ---------======@[ UPLOAD FILE ]@======---------
  145. */
  146. public function upload_file(){
  147. if (!$this->data["self_project"]) {
  148. show_404();
  149. }
  150. if( $this->uri->segment(4) == "" ){
  151. $this->cek_url_and_dest( $this->uri->segment(2) );
  152. } else {
  153. $this->cek_url_and_dest( $this->uri->segment(4), $this->uri->segment(2) );
  154. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  155. }
  156. $this->load->view("project/form_upload", $this->data);
  157. }
  158. /**
  159. * ---------======@[ UPLOAD REVISI ]@======---------
  160. */
  161. public function upload_rev(){
  162. if (!$this->data["self_project"]) {
  163. show_404();
  164. }
  165. if( $this->uri->segment(4) == "" ){
  166. $this->cek_url_and_dest( $this->uri->segment(2) );
  167. } else {
  168. $this->cek_url_and_dest( $this->uri->segment(4), $this->uri->segment(2) );
  169. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  170. }
  171. $this->load->view("project/form_upload", $this->data);
  172. }
  173. /**
  174. * ---------======@[ DELETE FILE ]@======---------
  175. */
  176. public function delete_file($id){
  177. if (!$this->data["self_project"]) {
  178. show_404();
  179. }
  180. $this->get_single_attachment($id);
  181. $this->load->view("project/form_delete", $this->data);
  182. }
  183. /**
  184. * ---------======@[ ADD BAB ]@======---------
  185. */
  186. public function add_bab(){
  187. if (!$this->data["self_project"]) {
  188. show_404();
  189. }
  190. $this->cek_url_and_dest( $this->uri->segment(2) );
  191. $this->get_current_type( $this->data["project_data"][0]["type_id"] );
  192. $this->get_author( $this->data["project_data"][0]["user_id"] );
  193. $this->data["author_name"] = get_user_name( $this->data["author"] );
  194. $this->data["author_url"] = get_user_url( $this->data["author"] );
  195. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  196. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  197. $this->load->view("project/form_add_bab", $this->data);
  198. }
  199. /**
  200. * ---------======@[ ADD BAB ]@======---------
  201. */
  202. public function save_add_bab(){
  203. if (!$this->data["self_project"]) {
  204. show_404();
  205. }
  206. $parpar = array(
  207. "rb_projects" => array(
  208. "project_id" => $this->input->post("project_id")
  209. )
  210. );
  211. $parent = $this->projects_model->get_projects($parpar);
  212. $chap_title = $this->input->post("project_title");
  213. $urlc = spliturl($chap_title, 50);
  214. $par = array(
  215. "rb_projects" => array(
  216. "project_title" => $this->input->post("project_title"),
  217. "project_parent" => $parent[0]["project_id"]
  218. )
  219. );
  220. $proj = $this->projects_model->get_projects($par);
  221. //print_r($proj);
  222. if( !empty($proj) ) {
  223. $this->cek_url_and_dest( $this->uri->segment(2) );
  224. $this->get_current_type( $this->data["project_data"][0]["type_id"] );
  225. $this->get_author( $this->data["project_data"][0]["user_id"] );
  226. $this->data["author_name"] = get_user_name( $this->data["author"] );
  227. $this->data["author_url"] = get_user_url( $this->data["author"] );
  228. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  229. $this->get_chapters( $this->data["project_data"][0]["project_id"] );
  230. $this->data["error_msg"] = '<div class="alert alert-warning">Judul bab yang anda masukan telah ada</div>';
  231. $this->load->view("project/form_add_bab", $this->data);
  232. } else {
  233. $data_project2 = array(
  234. "project_id" => NULL,
  235. "project_chapters" => NULL,
  236. "project_chapter_num" => NULL,
  237. "project_title" => $this->input->post("project_title"),
  238. "project_content" => $parent[0]["project_content"],//parent
  239. "project_is_parent" => "no",
  240. "project_parent" => $this->input->post("project_id"),
  241. "project_made" => $parent[0]["project_made"],//parent
  242. "project_published" => NULL,
  243. "project_status" => "review",
  244. "project_attachment_count" => 0,
  245. "project_downloadable" => "yes",
  246. "project_year" => $parent[0]["project_year"],//parent
  247. "type_id" => NULL,
  248. "user_id" => $parent[0]["user_id"],//parent
  249. "project_author" => $parent[0]["project_author"],//parent
  250. "project_reviewer" => $parent[0]["project_reviewer"],//parent
  251. "project_jurusan" => $parent[0]["project_jurusan"],//parent
  252. "project_fakultas" => $parent[0]["project_fakultas"],//parent
  253. "project_strata" => $parent[0]["project_strata"],//parent
  254. "project_url" => $urlc
  255. );
  256. $insert_project2 = $this->projects_model->add_new_project($data_project2);
  257. $upd_project = array(
  258. "project_chapters" => $parent[0]["project_chapters"]+1,
  259. "project_chapter_num" => $parent[0]["project_chapter_num"]+1
  260. );
  261. $clause = array(
  262. "project_id" => $this->input->post("project_id")
  263. );
  264. $update_project = $this->projects_model->update_project($upd_project, $clause);
  265. redirect("review/".$this->uri->segment(2), "refresh");
  266. }
  267. }
  268. /**
  269. * ---------======@[ DELETE BAB ]@======---------
  270. */
  271. public function delete_bab($id){
  272. if (!$this->data["self_project"]) {
  273. show_404();
  274. }
  275. $this->get_attachment($id);
  276. /*
  277. echo "<pre>";
  278. print_r($this->data["versions"]);
  279. echo "</pre>";
  280. echo "<pre>";
  281. print_r($this->data["att_vers"]);
  282. echo "</pre>";
  283. echo "<pre>";
  284. print_r($this->data["attachments"]);
  285. echo "</pre>";
  286. */
  287. $par = array(
  288. "rb_projects" => array(
  289. "project_id" => $id
  290. )
  291. );
  292. $bab = $this->projects_model->get_projects($par);
  293. foreach( $this->data["versions"] as $k => $v) {
  294. //del attach
  295. unlink($this->data["attachments"][$k][0]["attachment_file_path"]);
  296. $delparatt = array( "attachment_id" => $this->data["attachments"][$k][0]["attachment_id"] );
  297. $delatt = $this->attach->del_attachment($delparatt);
  298. //del attach vers
  299. $delparver = array( "version_id" => $v["version_id"] );
  300. $delattver = $this->attach->del_attachment_version($delparver);
  301. //del vers
  302. $delver = $this->versions->del_version($delparver);
  303. $parpar = array(
  304. "rb_projects" => array(
  305. "project_id" => $bab[0]["project_parent"]
  306. )
  307. );
  308. $parent = $this->projects_model->get_projects($parpar);
  309. $data_project = array(
  310. "project_attachment_count" => $parent[0]["project_attachment_count"]-1
  311. );
  312. $clause = array(
  313. "project_id" => $parent[0]["project_id"]
  314. );
  315. $update_project = $this->projects_model->update_project($data_project, $clause);
  316. }
  317. $delbab = array( "project_id" => $id );
  318. $this->projects_model->del_project($delbab);
  319. $data_project2 = array(
  320. "project_chapters" => $parent[0]["project_chapters"]-1,
  321. "project_chapter_num" => $parent[0]["project_chapter_num"]-1
  322. );
  323. $clause2 = array(
  324. "project_id" => $parent[0]["project_id"]
  325. );
  326. $update_project2 = $this->projects_model->update_project($data_project2, $clause2);
  327. redirect("review/".$this->uri->segment(2), "refresh");
  328. }
  329. /**
  330. * ---------======@[ DELETE REVISIONs ]@======---------
  331. */
  332. public function del_rev($verid){
  333. if (!$this->data["self_project"]) {
  334. show_404();
  335. }
  336. //print_r($this->input->post() );
  337. //get attach id form ver_att
  338. $attver = array(
  339. "rb_attachment_versions" => array(
  340. "version_id" => $verid
  341. )
  342. );
  343. $this->data["att_vers"] = $this->attach->get_attachment_version($attver);
  344. if( isset($this->data["att_vers"]) ) {
  345. $att = array(
  346. "rb_attachment" => array(
  347. "attachment_id" => $this->data["att_vers"][0]["attachment_id"]
  348. )
  349. );
  350. $this->data["att"] = $this->attach->get_attachments($att);
  351. $delparatt = array( "attachment_id" => $this->data["att_vers"][0]["attachment_id"] );
  352. $delparver = array( "version_id" => $verid );
  353. //delete attach
  354. unlink($this->data["att"][0]["attachment_file_path"]);
  355. $delatt = $this->attach->del_attachment($delparatt);
  356. //delete version
  357. $delver = $this->versions->del_version($delparver);
  358. //delete version_attach
  359. $delattver = $this->attach->del_attachment_version($delparatt);
  360. }
  361. //update project - kurangi attach-count
  362. $data_project = array(
  363. "project_attachment_count" => $this->input->post("project_attachment_count")-1
  364. );
  365. $clause = array(
  366. "project_id" => $this->input->post("project_id")
  367. );
  368. $update_project = $this->projects_model->update_project($data_project, $clause);
  369. //if ada project parent, update project parent - kurangi attach-count
  370. if( $this->input->post("project_parent_id") !== "" ) {
  371. $data_project2 = array(
  372. "project_attachment_count" => $this->input->post("project_attachment_count_parent")-1
  373. );
  374. $clause2 = array(
  375. "project_id" => $this->input->post("project_parent_id")
  376. );
  377. $update_project2 = $this->projects_model->update_project($data_project2, $clause2);
  378. }
  379. redirect($this->input->post("redirect_dest"), "refresh");
  380. }
  381. /**
  382. * ---------======@[ SAVE EDIT PROJECT ]@======---------
  383. */
  384. public function save_edit(){
  385. if (!$this->data["self_project"]) {
  386. show_404();
  387. }
  388. $datestring = "%Y-%m-%d %H:%i:%s";
  389. $time = time();
  390. $now = mdate($datestring, $time);
  391. $exp = explode( "|", $this->input->post("project_reviewer") );
  392. $reviewer = serialize($exp);
  393. $url = spliturl($this->input->post("project_title"), 50);
  394. $project_keywords_temp = $this->input->post( "project_keywords" );
  395. $project_keywords_exp = explode( ',', $project_keywords_temp );
  396. $project_keywordstrim = array();
  397. foreach( $project_keywords_exp as $k => $v ) {
  398. array_push($project_keywordstrim, trim($v));
  399. }
  400. $project_keywords = serialize($project_keywordstrim);
  401. $data_project = array(
  402. "project_title" => $this->input->post("project_title"),
  403. "project_content" => $this->input->post("project_content"),
  404. "project_year" => $this->input->post("project_year"),
  405. "project_author" => $this->input->post("project_author"),
  406. "project_reviewer" => $reviewer,
  407. "project_jurusan" => $this->input->post("project_jurusan"),
  408. "project_fakultas" => $this->input->post("project_fakultas"),
  409. "project_strata" => $this->input->post("project_strata"),
  410. "project_keywords" => $project_keywords,
  411. "project_link" => $this->input->post("project_link")
  412. /* "project_url" => $url, */
  413. /* "project_url_edited" => $this->uri->segment(2), */
  414. );
  415. $clause = array(
  416. "project_id" => $this->input->post("project_id")
  417. );
  418. $update_project = $this->projects_model->update_project($data_project, $clause);
  419. if( $update_project ){
  420. redirect("review/".$this->uri->segment(2), "refresh");
  421. }
  422. }
  423. /**
  424. * ---------======@[ SAVE EDIT BAB ]@======---------
  425. */
  426. public function save_edit_bab(){
  427. if (!$this->data["self_project"]) {
  428. show_404();
  429. }
  430. $url = spliturl($this->input->post("project_title"), 50);
  431. $data_project = array(
  432. "project_title" => $this->input->post("project_title"),
  433. /* "project_url" => $url, */
  434. );
  435. $clause = array(
  436. "project_id" => $this->input->post("project_id")
  437. );
  438. $update_project = $this->projects_model->update_project($data_project, $clause);
  439. if( $update_project ){
  440. redirect("review/".$this->input->post("project_parent_url").'/'.$this->uri->segment(4), "refresh");
  441. }
  442. }
  443. /**
  444. * ---------======@[ SAVE UPLOAD MASTER ]@======---------
  445. */
  446. public function save_upload(){
  447. if (!$this->data["self_project"]) {
  448. show_404();
  449. }
  450. // upload file ke directory 'uploads'
  451. if ( $this->upload->do_upload( "project_file" ) ) {
  452. $dataup = array('upload_data' => $this->upload->data());
  453. // update project_attachment_count di table rb_projects
  454. $data_project = array(
  455. "project_attachment_count" => 1
  456. );
  457. $clause = array(
  458. "project_id" => $this->input->post("project_id")
  459. );
  460. $update_project = $this->projects_model->update_project($data_project, $clause);
  461. // update project_attachment_count di table rb_projects untuk parent bab ini
  462. if( $this->input->post("project_parent_id") !== "" ) {
  463. $proj_parent_attach = $this->input->post("project_attachment_count_parent")+1;
  464. $data_project2 = array(
  465. "project_attachment_count" => $proj_parent_attach
  466. );
  467. $clause2 = array(
  468. "project_id" => $this->input->post("project_parent_id")
  469. );
  470. $update_project2 = $this->projects_model->update_project($data_project2, $clause2);
  471. }
  472. // insert data ke table rb_versions, data : version_id, version_number, project_id
  473. $ver = array(
  474. "version_id" => NULL,
  475. "version_number" => 1,
  476. "project_id" => $this->input->post("project_id")
  477. );
  478. $insert_version = $this->versions->add_new_version($ver);
  479. // insert data ke table rb_attachment, data : attachment_id, attachment_url, attachment_file, attachment_file_ext, attachment_file_path
  480. if( isset($insert_version) && $insert_version ) {
  481. $att = array(
  482. "attachment_id" => NULL,
  483. "attachment_url" => $dataup["upload_data"]["file_name"],
  484. "attachment_file" => $dataup["upload_data"]["file_name"],
  485. "attachment_file_ext" => $dataup["upload_data"]["file_ext"],
  486. "attachment_file_path" => $dataup["upload_data"]["full_path"]
  487. );
  488. $insert_attachment = $this->attach->add_new_attachment($att);
  489. // insert data ke table rb_attachment_versions, data : attachment_id, version_id
  490. if( isset($insert_attachment) && $insert_attachment ){
  491. $attachvers = array(
  492. "attachment_id" => $insert_attachment,
  493. "version_id" => $insert_version
  494. );
  495. $insert_attachvers = $this->attach->add_new_attachment_version($attachvers);
  496. }
  497. }
  498. }
  499. //if succeeded redirect to project page
  500. if( isset($insert_attachvers) && $insert_attachvers ){
  501. redirect("review/".$this->uri->segment(2), "refresh");
  502. }
  503. }
  504. /**
  505. * ---------======@[ SAVE UPLOAD REVISI ]@======---------
  506. */
  507. public function save_rev(){
  508. if (!$this->data["self_project"]) {
  509. show_404();
  510. }
  511. // upload file ke directory 'uploads'
  512. if ( $this->upload->do_upload( "project_file" ) ) {
  513. $dataup = array('upload_data' => $this->upload->data());
  514. // update project_attachment_count di table rb_projects
  515. $parget = array(
  516. "rb_projects" => array(
  517. "project_id" => $this->input->post("project_id")
  518. )
  519. );
  520. $get_project = $this->projects_model->get_projects($parget);
  521. $data_project = array(
  522. "project_attachment_count" => $get_project[0]["project_attachment_count"]+1
  523. );
  524. $clause = array(
  525. "project_id" => $this->input->post("project_id")
  526. );
  527. $update_project = $this->projects_model->update_project($data_project, $clause);
  528. // update project_attachment_count di table rb_projects untuk parent bab ini
  529. if( $this->input->post("project_parent_id") !== "" ) {
  530. $proj_parent_attach = $this->input->post("project_attachment_count_parent")+1;
  531. $data_project2 = array(
  532. "project_attachment_count" => $proj_parent_attach
  533. );
  534. $clause2 = array(
  535. "project_id" => $this->input->post("project_parent_id")
  536. );
  537. $update_project2 = $this->projects_model->update_project($data_project2, $clause2);
  538. }
  539. $getver = array(
  540. "rb_versions" => array(
  541. "project_id" => $this->input->post("project_id")
  542. )
  543. );
  544. $get_max = $this->versions->get_versions($getver, '', NULL, NULL, "MAX(version_number) as last_ver");
  545. // insert data ke table rb_versions, data : version_id, version_number, project_id
  546. $ver = array(
  547. "version_id" => NULL,
  548. "version_number" => $get_max[0]["last_ver"]+1,
  549. "project_id" => $this->input->post("project_id")
  550. );
  551. $insert_version = $this->versions->add_new_version($ver);
  552. // insert data ke table rb_attachment, data : attachment_id, attachment_url, attachment_file, attachment_file_ext, attachment_file_path
  553. if( isset($insert_version) && $insert_version ) {
  554. $att = array(
  555. "attachment_id" => NULL,
  556. "attachment_url" => $dataup["upload_data"]["file_name"],
  557. "attachment_file" => $dataup["upload_data"]["file_name"],
  558. "attachment_file_ext" => $dataup["upload_data"]["file_ext"],
  559. "attachment_file_path" => $dataup["upload_data"]["full_path"]
  560. );
  561. $insert_attachment = $this->attach->add_new_attachment($att);
  562. // insert data ke table rb_attachment_versions, data : attachment_id, version_id
  563. if( isset($insert_attachment) && $insert_attachment ){
  564. $attachvers = array(
  565. "attachment_id" => $insert_attachment,
  566. "version_id" => $insert_version
  567. );
  568. $insert_attachvers = $this->attach->add_new_attachment_version($attachvers);
  569. }
  570. }
  571. }
  572. //if succeeded redirect to project page
  573. if( isset($insert_attachvers) && $insert_attachvers ){
  574. redirect("review/".$this->uri->segment(2), "refresh");
  575. }
  576. }
  577. public function up_project($arg, $par){
  578. if (!$this->data["self_project"]) {
  579. show_404();
  580. }
  581. echo "edited";
  582. }
  583. /**
  584. * ---------======@[ SEND COMMENT ]@======---------
  585. */
  586. public function send_comment(){
  587. $datestring = "%Y-%m-%d %h:%i:%s";
  588. $time = time();
  589. $review_date = mdate($datestring, $time);
  590. //print_r($this->input->post());
  591. $par = array(
  592. "user_id" => $this->input->post("userid"),
  593. "review_date" => $review_date,
  594. "review_content" => $this->input->post("comment_content"),
  595. "project_id" => $this->input->post("projid"),
  596. );
  597. $sendreview = $this->review->add_review($par);
  598. if( $sendreview ) {
  599. redirect("review/".$this->input->post("projurl"), "refresh");
  600. }
  601. }
  602. /**
  603. * ---------======@[ CEK URL AND NEXT DESTINATION ]@======---------
  604. */
  605. private function cek_url_and_dest($judul, $parent = ""){
  606. if( $parent !== "" ){
  607. $parp = array(
  608. "rb_projects" => array(
  609. "project_url" => $parent
  610. )
  611. );
  612. $parentdata = $this->projects_model->get_projects($parp, "", NULL, NULL, "project_id");
  613. $par = array(
  614. "rb_projects" => array(
  615. "project_url" => $judul,
  616. "project_parent" => $parentdata[0]["project_id"]
  617. )
  618. );
  619. } else {
  620. $par = array(
  621. "rb_projects" => array(
  622. "project_url" => $judul
  623. )
  624. );
  625. }
  626. $this->data["project_data"] = $this->projects_model->get_projects($par);
  627. //print_r( $this->data["project_data"] );
  628. $this->data["project_data"][0]["project_id"];
  629. if( $this->data["project_data"] ) {
  630. $state = array(
  631. "rb_projects_state" => array(
  632. "project_id" => $this->data["project_data"][0]["project_id"]
  633. )
  634. );
  635. $this->data["state"] = $this->projects_model->get_projects_state($state);
  636. if( $this->data["project_data"][0]["project_parent"] > 0 ) {
  637. $this->get_parent_data( $this->data["project_data"][0]["project_parent"] );
  638. $prevstate_process = $this->data["project_state"][0]["project_state"];
  639. $this->data["type"] = $this->data["project_parent"][0]["type_id"];
  640. } else {
  641. $prevstate_process = $this->data["state"][0]["project_state"];
  642. $this->data["type"] = $this->data["project_data"][0]["type_id"];
  643. }
  644. $this->set_destination($this->data["type"], $prevstate_process);
  645. }
  646. }
  647. /**
  648. * ---------======@[ GET CURRENT PROJECT TYPES ]@======---------
  649. */
  650. private function get_parent_data($proj_id){
  651. $par = array(
  652. "rb_projects" => array(
  653. "project_id" => $proj_id
  654. )
  655. );
  656. $this->data["project_parent"] = $this->projects_model->get_projects($par);
  657. $st = array(
  658. "rb_projects_state" => array(
  659. "project_id" => $proj_id
  660. )
  661. );
  662. $this->data["project_state"] = $this->projects_model->get_projects_state($st);
  663. }
  664. /**
  665. * ---------======@[ GET CURRENT PROJECT TYPES ]@======---------
  666. */
  667. private function get_current_type($type_id){
  668. $par = array(
  669. "type_id" => $type_id
  670. );
  671. $this->data["type_name"] = $this->types->get_types($par);
  672. }
  673. /**
  674. * ---------======@[ GET AUTHOR ]@======---------
  675. */
  676. private function get_author($user_id){
  677. $par = array(
  678. "rb_user" => array(
  679. "user_id" => $user_id
  680. )
  681. );
  682. $this->data["author"] = $this->user->get_users($par);
  683. }
  684. /**
  685. * ---------======@[ GET REWIEWER ]@======---------
  686. */
  687. private function get_reviewers($reviewers){
  688. $this->data["reviewers"] = $unseri = unserialize($reviewers);
  689. }
  690. /**
  691. * ---------======@[ GET CHAPTERS ]@======---------
  692. */
  693. private function get_chapters($parent){
  694. $par = array(
  695. "rb_projects" => array(
  696. "project_parent" => $parent
  697. )
  698. );
  699. $this->data["project_chapters"] = $this->projects_model->get_projects($par);
  700. }
  701. /**
  702. * ---------======@[ REORDER VERSION ]@======---------
  703. */
  704. public function reorder_version() {
  705. $oldversid = $this->input->post("oldversid");
  706. $oldvers = $this->input->post("oldvers");
  707. $latestvers = $this->input->post("latestvers");
  708. $newvers = $latestvers+1;
  709. $clause = array(
  710. "version_id" => $oldversid
  711. );
  712. $arg = array(
  713. "version_number" => $newvers
  714. );
  715. $update = $this->versions->update_versions($arg, $clause);
  716. if( $update ) {
  717. $return["result"] = "success";
  718. }
  719. echo json_encode($return);
  720. }
  721. /**
  722. * ---------======@[ GET ATTACHMENT ]@======---------
  723. */
  724. private function get_attachment($proj_id){
  725. $order = array(
  726. "version_number" => "ASC"
  727. );
  728. $ver = array(
  729. "rb_versions" => array(
  730. "project_id" => $proj_id
  731. )
  732. );
  733. $this->data["versions"] = $this->versions->get_versions($ver, $order);
  734. if( isset($this->data["versions"]) ){
  735. foreach($this->data["versions"] as $k => $v) {
  736. $attver = array(
  737. "rb_attachment_versions" => array(
  738. "version_id" => $v["version_id"]
  739. )
  740. );
  741. $this->data["att_vers"][$k] = $this->attach->get_attachment_version($attver);
  742. }
  743. }
  744. if( isset($this->data["att_vers"]) ){
  745. foreach($this->data["att_vers"] as $k => $v) {
  746. $att = array(
  747. "rb_attachment" => array(
  748. "attachment_id" => $v[0]["attachment_id"]
  749. )
  750. );
  751. $this->data["attachments"][$k] = $this->attach->get_attachments($att);
  752. }
  753. }
  754. }
  755. /**
  756. * ---------======@[ GET SINGLE ATTACHMENT ]@======---------
  757. */
  758. private function get_single_attachment($verid){
  759. $order = array(
  760. "version_number" => "ASC"
  761. );
  762. $ver = array(
  763. "rb_versions" => array(
  764. "version_id" => $verid
  765. )
  766. );
  767. $this->data["versions"] = $this->versions->get_versions($ver, $order);
  768. if( isset($this->data["versions"]) ){
  769. $pro = array(
  770. "rb_projects" => array(
  771. "project_id" => $this->data["versions"][0]["project_id"]
  772. )
  773. );
  774. $this->data["project_data"] = $this->projects_model->get_projects($pro);
  775. if( isset($this->data["project_data"]) ){
  776. $propar = array(
  777. "rb_projects" => array(
  778. "project_id" => $this->data["project_data"][0]["project_parent"]
  779. )
  780. );
  781. $this->data["project_parent"] = $this->projects_model->get_projects($propar);
  782. }
  783. $attver = array(
  784. "rb_attachment_versions" => array(
  785. "version_id" => $this->data["versions"][0]["version_id"]
  786. )
  787. );
  788. $this->data["att_vers"] = $this->attach->get_attachment_version($attver);
  789. }
  790. if( isset($this->data["att_vers"]) ){
  791. $att = array(
  792. "rb_attachment" => array(
  793. "attachment_id" => $this->data["att_vers"][0]["attachment_id"]
  794. )
  795. );
  796. $this->data["attachments"] = $this->attach->get_attachments($att);
  797. }
  798. }
  799. /**
  800. * ---------======@[ GET REVIEWS ]@======---------
  801. */
  802. private function get_reviews($projid){
  803. $par = array(
  804. "rb_review" => array(
  805. "project_id" => $projid
  806. )
  807. );
  808. $this->data["reviews"] = $this->review->get_reviews($par);
  809. if( isset($this->data["reviews"]) ){
  810. foreach($this->data["reviews"] as $k => $v) {
  811. $par2 = array(
  812. "rb_user" => array(
  813. "user_id" => $v["user_id"]
  814. )
  815. );
  816. $this->data["commentor"][$k] = $this->user_model->get_users($par2);
  817. $name = get_user_name($this->data["commentor"][$k]);
  818. $this->data["commentor"][$k][0]["fullname"] = $name;
  819. if( isset($this->data["project_parent"][0]["project_id"]) && $this->data["project_parent"][0]["project_id"]){
  820. $projid = $this->data["project_parent"][0]["project_id"];
  821. }
  822. $par3 = array(
  823. "rb_reviewer" => array(
  824. "user_id" => $v["user_id"],
  825. "project_id" => $projid
  826. )
  827. );
  828. $this->data["is_reviewer"][$k] = $this->reviewer->get_reviewers($par3, '', NULL, NULL, "user_id");
  829. if($this->data["is_reviewer"][$k]) {
  830. $this->data["commentor"][$k][0]["role"] = "reviewer";
  831. } else {
  832. $this->data["commentor"][$k][0]["role"] = "author";
  833. }
  834. }
  835. }
  836. //print_r($this->data["reviews"]);
  837. }
  838. /**
  839. * ---------======@[ GET PROJECT DATA ]@======---------
  840. */
  841. public function get_project_data($url){
  842. //echo $url;
  843. $par = array(
  844. "rb_projects" => array(
  845. "project_url" => $url
  846. )
  847. );
  848. $this->dataproj = $this->projects_model->get_projects($par);
  849. }
  850. /**
  851. * ---------======@[ GET PROJECT DATA REVIEWER ]@======---------
  852. */
  853. public function get_project_reviewers($url){
  854. $this->get_project_data($url);
  855. $rev = array(
  856. "rb_reviewer" => array(
  857. "project_id" => $this->dataproj[0]["project_id"],
  858. //"reviewer_status" => "active"
  859. )
  860. );
  861. $this->currreviewers = $this->reviewer->get_reviewers($rev);
  862. //print_r($this->currreviewers);
  863. }
  864. ////////////////////////////////////INVITATIONS & REVIEWERS////////////////////////////////////////////////////
  865. /**
  866. * ---------======@[ CHECK INVITATIONS ]@======---------
  867. */
  868. public function check_invitations($id){
  869. $inv = array(
  870. "rb_invitation" => array(
  871. "invitation_project" => $id
  872. )
  873. );
  874. $invitation = $this->user->get_invitations($inv);
  875. if( $invitation ) {
  876. foreach( $invitation as $k => $v ) {
  877. if( $v["invitation_status"] == "pending" ) {
  878. array_push( $this->reviewers, $v );
  879. }
  880. }
  881. }
  882. $rev = array(
  883. "rb_reviewer" => array(
  884. "project_id" => $id
  885. )
  886. );
  887. $reviewer = $this->reviewer->get_reviewers($rev);
  888. if( $reviewer ) {
  889. foreach( $reviewer as $k => $v ) {
  890. if( $v["reviewer_status"] == "invited" ) {
  891. array_push( $this->reviewers, $v );
  892. }
  893. }
  894. }
  895. $this->data["reviewers_invite"] = $this->reviewers;
  896. }
  897. public function invite_new() {
  898. $invitee_email = $this->input->post('invitee_email');
  899. $invite_by = $this->input->post('invite_by');
  900. $invitation_project = $this->input->post('invitation_project');
  901. $this->form_validation->set_rules('invitee_email', 'Email', 'required|valid_emails');
  902. if($this->form_validation->run() == FALSE)
  903. {
  904. $return['errors'] = validation_errors('<div class="alert alert-warning">', '</div>');
  905. echo json_encode($return);
  906. die();
  907. }
  908. $userpar = array(
  909. "rb_user" => array(
  910. "user_email" => $invitee_email
  911. )
  912. );
  913. $user_email = $this->user->get_users($userpar, '', NULL, NULL, "user_id");
  914. if( !$user_email ) {
  915. $ss = array(
  916. "rb_site_settings" => array(
  917. "site_settings_key" => "Email Admin"
  918. )
  919. );
  920. $site_mail = $this->site_settings_model->get_site_settings($ss);
  921. $user_data = array(
  922. "rb_user" => array(
  923. "user_id" => $invite_by
  924. )
  925. );
  926. $dataus = $this->user->get_users($user_data);
  927. $name = get_user_name($dataus);
  928. $invitationurl = urlencode($dataus[0]["user_email"]);
  929. $invitation_code = md5(uniqid($invitationurl));
  930. $time = time();
  931. $datestring = "%Y-%m-%d %h:%i:%s";
  932. $invitation_date = mdate($datestring, $time);
  933. $mailmsg = "Hello, $name mengundang Anda untuk menjadi pembimbingnya di situs Rakbuku. \r\n click invitation url berikut untuk manjadi member dan reviewer di website kami \r\n invitation url : ".base_url()."invitations/$invitation_code";
  934. $mailsent = send_email($invitee_email, $site_mail[0]["site_settings_value"], "Undangan untuk menjadi Pembimbing di situs Rakbuku", $mailmsg);
  935. if( $mailsent ) {
  936. $inv = array(
  937. "invitation_code" => $invitation_code,
  938. "invitation_email" => $invitee_email,
  939. "invitation_date" => $invitation_date,
  940. "invite_by" => $invite_by,
  941. "invitation_for" => "reviewer",
  942. "invitation_project" => $invitation_project,
  943. "invitation_url" => base_url()."invitations/".$invitation_code,
  944. );
  945. $datainv = $this->user->add_new_invitation($inv);
  946. $return['result'] = '<div class="alert alert-info">Sukses</div>';
  947. } else {
  948. $return['result'] = '<div class="alert alert-warning">gagal menginvite, silahkan kirim ulang</div>';
  949. }
  950. } else {
  951. $user_data = array(
  952. "reviewer_id" => NULL,
  953. "user_id" => $user_email[0]["user_id"],
  954. "reviewer_status" => "invited",
  955. "project_id" => $invitation_project
  956. );
  957. $data_reviewer = $this->reviewer->add_reviewer_project($user_data);
  958. if( $data_reviewer ) {
  959. $return['result'] = '<div class="alert alert-info">Sukses</div>';
  960. }
  961. }
  962. echo json_encode($return);
  963. }
  964. /**
  965. * ---------======@[ RESEND INVITATION ]@======---------
  966. */
  967. public function resend_email_invite($id){
  968. $inv = array(
  969. "rb_invitation" => array(
  970. "invitation_id" => $id,
  971. "invitation_project" => $this->dataproj[0]["project_id"]
  972. )
  973. );
  974. $inva = $this->user_model->get_invitations($inv);
  975. $us = array(
  976. "rb_user" => array(
  977. "user_id" => $this->dataproj[0]["user_id"]
  978. )
  979. );
  980. $user = $this->user_model->get_users($us);
  981. $name = get_user_name($user);
  982. $ss = array(
  983. "rb_site_settings" => array(
  984. "site_settings_key" => "Email Admin"
  985. )
  986. );
  987. $site_mail = $this->site_settings_model->get_site_settings($ss);
  988. $mailmsg = "Hello, $name mengundang Anda untuk menjadi pembimbingnya di situs Rakbuku. \r\n click invitation url berikut untuk manjadi member dan reviewer di website kami \r\n invitation url : ".base_url()."invitations/".$inva[0]["invitation_code"]."";
  989. $send = send_email($inva[0]["invitation_email"], $site_mail[0]["site_settings_value"], "Undangan untuk menjadi Pembimbing di situs Rakbuku", $mailmsg);
  990. if( $send ) {
  991. redirect("review/".$this->uri->segment(2), "refresh");
  992. }
  993. }
  994. /**
  995. * ---------======@[ CHECK APPROVED BAB ]@======---------
  996. */
  997. public function check_approve_bab($projid){
  998. $par = array(
  999. "rb_projects" => array(
  1000. "project_parent" => $projid
  1001. )
  1002. );
  1003. $babstatus = $this->projects_model->get_projects($par, "", NULL, NULL, "project_status");
  1004. $this->data["bab_approved_all"] = true;
  1005. if(isset($babstatus)) {
  1006. foreach( $babstatus as $k => $v ) {
  1007. if( $v["project_status"] == "review" ) {
  1008. $this->data["bab_approved_all"] = false;
  1009. }
  1010. }
  1011. }
  1012. }
  1013. /**
  1014. * ---------======@[ approve bab ]@======---------
  1015. */
  1016. public function approve_bab(){
  1017. if( $this->uri->segment(4) == "" ){
  1018. $this->cek_url_and_dest( $this->uri->segment(2) );
  1019. } else {
  1020. $this->cek_url_and_dest( $this->uri->segment(4), $this->uri->segment(2) );
  1021. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  1022. }
  1023. $this->load->view("project/reviewer_approval_bab", $this->data);
  1024. }
  1025. /**
  1026. * ---------======@[ approve project ]@======---------
  1027. */
  1028. public function approve_project(){
  1029. if( $this->uri->segment(4) == "" ){
  1030. $this->cek_url_and_dest( $this->uri->segment(2) );
  1031. } else {
  1032. $this->cek_url_and_dest( $this->uri->segment(4), $this->uri->segment(2) );
  1033. $this->get_parent_data($this->data["project_data"][0]["project_parent"]);
  1034. }
  1035. $this->load->view("project/reviewer_approval_project", $this->data);
  1036. }
  1037. /**
  1038. * ---------======@[ SAVE APPROVAL BAB ]@======---------
  1039. */
  1040. public function save_approval(){
  1041. //print_r($this->input->post());
  1042. $data_project = array(
  1043. "project_status" => "approved"
  1044. );
  1045. $clause = array(
  1046. "project_id" => $this->input->post("project_id")
  1047. );
  1048. $update_project = $this->projects_model->update_project($data_project, $clause);
  1049. $parent_url = $this->input->post("project_parent_url");
  1050. if( $update_project ){
  1051. if( !empty($parent_url) ) {
  1052. redirect("review/".$this->input->post("project_parent_url").'/'.$this->uri->segment(4), "refresh");
  1053. } else {
  1054. redirect("review/".$this->input->post("project_url"), "refresh");
  1055. }
  1056. }
  1057. }
  1058. /**
  1059. * ---------======@[ SAVE APPROVAL BAB ]@======---------
  1060. */
  1061. public function open_project(){
  1062. //echo "tes";
  1063. $urlbab = $this->uri->segment(4);
  1064. if( !empty($urlbab) ) {
  1065. $data_project1 = array(
  1066. "project_status" => "review"
  1067. );
  1068. $clause1 = array(
  1069. "project_url" => $this->uri->segment(4)
  1070. );
  1071. $update_project1 = $this->projects_model->update_project($data_project1, $clause1);
  1072. }
  1073. $data_project = array(
  1074. "project_status" => "review"
  1075. );
  1076. $clause = array(
  1077. "project_url" => $this->uri->segment(2)
  1078. );
  1079. $update_project = $this->projects_model->update_project($data_project, $clause);
  1080. if( !empty($urlbab) ) {
  1081. redirect("review/".$this->uri->segment(2).'/'.$this->uri->segment(4), "refresh");
  1082. } else {
  1083. redirect("review/".$this->uri->segment(2), "refresh");
  1084. }
  1085. }
  1086. /**
  1087. * ---------======@[ publish form ]@======---------
  1088. */
  1089. public function publish_project(){
  1090. $this->cek_url_and_dest( $this->uri->segment(2) );
  1091. $this->load->view("project/publish_project", $this->data);
  1092. }
  1093. /**
  1094. * ---------======@[ go_publish ]@======---------
  1095. */
  1096. public function go_publish(){
  1097. $data_project1 = array(
  1098. "project_status" => "approved"
  1099. );
  1100. $clause1 = array(
  1101. "project_url" => $this->uri->segment(2)
  1102. );
  1103. $update_project1 = $this->projects_model->update_project($data_project1, $clause1);
  1104. //print_r($this->input->post());
  1105. $parstate = array(
  1106. "project_state" => $this->input->post( "project_state" ),
  1107. "project_state_next_state" => $this->input->post( "nextstate" ),
  1108. "project_state_next_url" => $this->input->post( "nexturl" )
  1109. );
  1110. $clausestate = array(
  1111. "project_id" => $this->input->post( "project_id" )
  1112. );
  1113. $update_project_state = $this->projects_model->update_project_state($parstate, $clausestate);
  1114. redirect($this->input->post( "currenturl" ).'/'.$this->input->post( "project_url" ), "refresh");
  1115. }
  1116. }