PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/admin_review.php

https://bitbucket.org/prat_h/rakbuku
PHP | 501 lines | 370 code | 97 blank | 34 comment | 42 complexity | caf501e64a441b04b495892754ac6d13 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 Admin_review extends Project {
  4. public $names = array();
  5. function __construct() {
  6. parent::__construct();
  7. $this->load->model('reviews_model', 'review');
  8. $this->data['types'] = $this->types->get_types();
  9. $this->data['title'] = 'Invite Reviewer';
  10. $this->data["users"] = $this->user->get_users();
  11. $this->data["jurusan"] = $this->jurusan->get_jurusan();
  12. $url = $this->uri->segment(2);
  13. $this->get_project_data($url);
  14. $this->laststate = $this->cek_state($this->dataproj[0]["project_id"]);
  15. $match = array_search($this->laststate, $this->defstates);
  16. if( $this->laststate !== "admin_review" && $match !== false ){
  17. $this->redirect_to_state_url($this->laststate, $url);
  18. }
  19. $this->data["self_project"] = is_self_project( $this->dataproj[0]["user_id"], $this->data['current_user_id'] );
  20. $par = array(
  21. "rb_role" => array(
  22. "role_name" => "admin"
  23. )
  24. );
  25. $admins = $this->user_model->get_users_w_roles($par, '', NULL, NULL, "rb_user.user_id");
  26. $admin_review_ids = array();
  27. foreach( $admins as $k => $v ) {
  28. array_push($admin_review_ids, $v["user_id"]);
  29. };
  30. $this->data["is_admin"] = is_admin($this->data['role_name']);
  31. if( !is_in_admin_review( $this->dataproj[0]["user_id"], $admin_review_ids, $this->data['current_user_id']) ) {
  32. show_404();
  33. }
  34. }
  35. //print_r($this->names);
  36. /**
  37. * ---------======@[ INDEX ]@======---------
  38. */
  39. public function index() {
  40. if( !is_login($this->data['login']) || ( $this->input->post("project_state") == "" && ($this->laststate != $this->uri->segment( 1 )) ) ){
  41. show_404();
  42. }
  43. //$this->load->view("project/invite_reviewer", $this->data);
  44. }
  45. public function _remap($judul, $act) {
  46. if( !is_login( $this->data['login'] ) ){
  47. show_404();
  48. }
  49. $par = array(
  50. "rb_projects" => array(
  51. "project_url" => $judul
  52. )
  53. );
  54. $this->data["project_data"] = $this->projects_model->get_projects($par);
  55. if(!empty($act)){
  56. $method = str_replace(" ", "_", $act[0]);
  57. if( method_exists($this, $method) ) {
  58. call_user_func_array( array( $this,$method ), array());
  59. } else {
  60. if( $judul == "" ){
  61. call_user_func_array( array( $this,"index" ), array());
  62. }
  63. }
  64. } else {
  65. if( $this->data["project_data"] ) {
  66. $state = array(
  67. "rb_projects_state" => array(
  68. "project_id" => $this->data["project_data"][0]["project_id"]
  69. )
  70. );
  71. $this->data["state"] = $this->projects_model->get_projects_state($state);
  72. $prevstate_process = $this->data["state"][0]["project_state"];
  73. $this->data["type"] = $this->data["project_data"][0]["type_id"];
  74. $this->set_destination($this->data["type"], $prevstate_process);
  75. }
  76. if( is_array($this->data["project_data"]) ) {
  77. $this->get_type($this->data["project_data"][0]["type_id"]);
  78. $usr = array(
  79. "rb_user" => array(
  80. "user_id" => $this->data["project_data"][0]["user_id"]
  81. )
  82. );
  83. $this->data["author"] = $this->user->get_users($usr);
  84. $this->data["author_name"] = get_user_name($this->data["author"]);
  85. $this->data["author_url"] = get_user_url( $this->data["author"] );
  86. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  87. $this->get_chapters_file( $this->data["project_data"][0]["project_id"] );
  88. $this->get_reviews( $this->data["project_data"][0]["project_id"] );
  89. //$this->get_chapters_file()
  90. $this->load->view("project/admin_review", $this->data);
  91. } else {
  92. $method = str_replace(" ", "_", $judul);
  93. if( method_exists($this, $method) ) {
  94. call_user_func_array( array( $this,$method ), array());
  95. } else {
  96. if( $judul == "" ){
  97. call_user_func_array( array( $this,"index" ), array());
  98. }
  99. }
  100. }
  101. }
  102. }
  103. public function send_comment(){
  104. $datestring = "%Y-%m-%d %h:%i:%s";
  105. $time = time();
  106. $review_date = mdate($datestring, $time);
  107. //print_r($this->input->post());
  108. $par = array(
  109. "user_id" => $this->input->post("userid"),
  110. "admin_review_date" => $review_date,
  111. "admin_review_content" => $this->input->post("comment_content"),
  112. "project_id" => $this->input->post("projid"),
  113. );
  114. $sendreview = $this->review->add_admin_review($par);
  115. if( $sendreview ) {
  116. redirect("admin_review/".$this->input->post("projurl"), "refresh");
  117. }
  118. }
  119. /**
  120. * ---------======@[ GET REVIEWS ]@======---------
  121. */
  122. private function get_reviews($projid){
  123. $par = array(
  124. "rb_admin_review" => array(
  125. "project_id" => $projid
  126. )
  127. );
  128. $this->data["admin_reviews"] = $this->review->get_admin_reviews($par);
  129. if( isset($this->data["admin_reviews"]) ){
  130. foreach($this->data["admin_reviews"] as $k => $v) {
  131. $par2 = array(
  132. "rb_user" => array(
  133. "user_id" => $v["user_id"]
  134. )
  135. );
  136. $this->data["commentor"][$k] = $this->user_model->get_users($par2);
  137. $name = get_user_name($this->data["commentor"][$k]);
  138. $this->data["commentor"][$k][0]["fullname"] = $name;
  139. if( isset($this->data["project_parent"][0]["project_id"]) && $this->data["project_parent"][0]["project_id"]){
  140. $projid = $this->data["project_parent"][0]["project_id"];
  141. }
  142. }
  143. }
  144. }
  145. public function get_type($projid) {
  146. $par = array(
  147. "type_id" => $projid
  148. );
  149. $this->data["types"] = $this->types->get_types($par);
  150. }
  151. /**
  152. * ---------======@[ GET REWIEWER ]@======---------
  153. */
  154. private function get_reviewers($reviewers){
  155. $this->data["reviewers"] = $unseri = unserialize($reviewers);
  156. }
  157. /**
  158. * ---------======@[ GET CHAPTERS ]@======---------
  159. */
  160. private function get_chapters($parent){
  161. $par = array(
  162. "rb_projects" => array(
  163. "project_parent" => $parent
  164. )
  165. );
  166. $this->data["project_chapters"] = $this->projects_model->get_projects($par);
  167. }
  168. /**
  169. * ---------======@[ GET CHAPTERS FILE ]@======---------
  170. */
  171. private function get_chapters_file($parent){
  172. $par = array(
  173. "rb_projects" => array(
  174. "project_parent" => $parent
  175. )
  176. );
  177. $this->data["project_chapters"] = $this->projects_model->get_projects($par);
  178. if( !empty($this->data["project_chapters"]) ) {
  179. foreach( $this->data["project_chapters"] as $k => $v ) {
  180. $ver = array(
  181. "rb_versions" => array(
  182. "project_id" => $v["project_id"]
  183. )
  184. );
  185. $this->data["versionsmax"][$k] = $this->versions->get_versions($ver, "", NULL, NULL, 'MAX(version_number) as finalversion');
  186. }
  187. }
  188. if( !empty($this->data["versionsmax"]) ){
  189. foreach($this->data["versionsmax"] as $k => $v) {
  190. $ver2 = array(
  191. "rb_versions" => array(
  192. "version_number" => $v[0]["finalversion"],
  193. "project_id" => $this->data["project_chapters"][$k]["project_id"]
  194. )
  195. );
  196. $this->data["versions"][$k] = $this->versions->get_versions($ver2);
  197. }
  198. }
  199. if( !empty($this->data["versions"]) ){
  200. foreach($this->data["versions"] as $k => $v) {
  201. $attver = array(
  202. "rb_attachment_versions" => array(
  203. "version_id" => $v[0]["version_id"]
  204. )
  205. );
  206. $this->data["att_vers"][$k] = $this->attach->get_attachment_version($attver);
  207. }
  208. }
  209. if( !empty($this->data["att_vers"]) ){
  210. foreach($this->data["att_vers"] as $k => $v) {
  211. $att = array(
  212. "rb_attachment" => array(
  213. "attachment_id" => $v[0]["attachment_id"]
  214. )
  215. );
  216. $this->data["attachments"][$k] = $this->attach->get_attachments($att);
  217. }
  218. }
  219. }
  220. /**
  221. * ---------======@[ publish form ]@======---------
  222. */
  223. public function publish_project(){
  224. if (!$this->data["is_admin"]) {
  225. show_404();
  226. }
  227. $state = array(
  228. "rb_projects_state" => array(
  229. "project_id" => $this->data["project_data"][0]["project_id"]
  230. )
  231. );
  232. $this->data["state"] = $this->projects_model->get_projects_state($state);
  233. $prevstate_process = $this->data["state"][0]["project_state"];
  234. $this->data["type"] = $this->data["project_data"][0]["type_id"];
  235. $this->set_destination($this->data["type"], $prevstate_process);
  236. $this->load->view("project/publish_project_admin", $this->data);
  237. }
  238. /**
  239. * ---------======@[ go_publish ]@======---------
  240. */
  241. public function go_publish(){
  242. //print_r($this->input->post());
  243. $parstate = array(
  244. "project_state" => $this->input->post( "project_state" ),
  245. "project_state_next_state" => NULL,
  246. "project_state_next_url" => NULL
  247. );
  248. $clausestate = array(
  249. "project_id" => $this->input->post( "project_id" )
  250. );
  251. $update_project_state = $this->projects_model->update_project_state($parstate, $clausestate);
  252. $upd_project = array(
  253. "project_status" => "publish"
  254. );
  255. $clause = array(
  256. "project_id" => $this->input->post("project_id")
  257. );
  258. $update_project = $this->projects_model->update_project($upd_project, $clause);
  259. redirect('karya_tulis/'.$this->input->post( "project_url" ), "refresh");
  260. }
  261. /**
  262. * ---------======@[ UPLOAD ]@======---------
  263. */
  264. public function upload_other(){
  265. if (!$this->data["self_project"]) {
  266. show_404();
  267. }
  268. $this->get_chapters_file( $this->data["project_data"][0]["project_id"] );
  269. $this->load->view("project/form_upload_admin", $this->data);
  270. }
  271. public function save_upload(){
  272. if (!$this->data["self_project"]) {
  273. show_404();
  274. }
  275. $project_chaps_id = $this->input->post("project_chapter_id");
  276. $project_id = $this->input->post("project_id");
  277. print_r($project_chaps_id);
  278. $arrcountatt = 0;
  279. $file = 0;
  280. foreach( $_FILES as $k => $v ) {
  281. if($v["name"] !== "") {
  282. $file++;
  283. if ( $this->upload->do_upload( $k ) ) {
  284. $chapid = $this->input->post("project_chapter_id_".$k);
  285. $dataup = array('upload_data' => $this->upload->data());
  286. $parget = array(
  287. "rb_projects" => array(
  288. "project_id" => $chapid
  289. )
  290. );
  291. $get_project = $this->projects_model->get_projects($parget);
  292. $data_project = array(
  293. "project_attachment_count" => $get_project[0]["project_attachment_count"]+1
  294. );
  295. $clause = array(
  296. "project_id" => $chapid
  297. );
  298. $update_project = $this->projects_model->update_project($data_project, $clause);
  299. $parparent = array(
  300. "rb_projects" => array(
  301. "project_id" => $project_id
  302. )
  303. );
  304. $get_project2 = $this->projects_model->get_projects($parparent);
  305. $data_project2 = array(
  306. "project_attachment_count" => $get_project2[0]["project_attachment_count"]+1
  307. );
  308. $clause2 = array(
  309. "project_id" => $project_id
  310. );
  311. $update_project2 = $this->projects_model->update_project($data_project2, $clause2);
  312. $getver = array(
  313. "rb_versions" => array(
  314. "project_id" => $chapid
  315. )
  316. );
  317. $get_max = $this->versions->get_versions($getver, '', NULL, NULL, "MAX(version_number) as last_ver");
  318. $ver = array(
  319. "version_id" => NULL,
  320. "version_number" => $get_max[0]["last_ver"]+1,
  321. "project_id" => $chapid
  322. );
  323. $insert_version = $this->versions->add_new_version($ver);
  324. if( isset($insert_version) && $insert_version ) {
  325. $att = array(
  326. "attachment_id" => NULL,
  327. "attachment_url" => $dataup["upload_data"]["file_name"],
  328. "attachment_file" => $dataup["upload_data"]["file_name"],
  329. "attachment_file_ext" => $dataup["upload_data"]["file_ext"],
  330. "attachment_file_path" => $dataup["upload_data"]["full_path"]
  331. );
  332. $insert_attachment = $this->attach->add_new_attachment($att);
  333. // insert data ke table rb_attachment_versions, data : attachment_id, version_id
  334. if( isset($insert_attachment) && $insert_attachment ){
  335. $attachvers = array(
  336. "attachment_id" => $insert_attachment,
  337. "version_id" => $insert_version
  338. );
  339. $insert_attachvers = $this->attach->add_new_attachment_version($attachvers);
  340. }
  341. }
  342. $arrcountatt++;
  343. }
  344. }
  345. }
  346. redirect($this->input->post("project_url"));
  347. }
  348. public function go_back_edit() {
  349. if (!$this->data["self_project"]) {
  350. show_404();
  351. }
  352. $this->get_type($this->data["project_data"][0]["type_id"]);
  353. $usr = array(
  354. "rb_user" => array(
  355. "user_id" => $this->data["project_data"][0]["user_id"]
  356. )
  357. );
  358. $this->data["author"] = $this->user->get_users($usr);
  359. $this->data["author_name"] = get_user_name($this->data["author"]);
  360. $this->data["author_url"] = get_user_url( $this->data["author"] );
  361. $this->get_reviewers( $this->data["project_data"][0]["project_reviewer"] );
  362. $this->get_chapters_file( $this->data["project_data"][0]["project_id"] );
  363. $this->get_reviews( $this->data["project_data"][0]["project_id"] );
  364. $this->load->view("project/form_edit_admin", $this->data);
  365. }
  366. /**
  367. * ---------======@[ SAVE EDIT PROJECT ]@======---------
  368. */
  369. public function save_edit(){
  370. $datestring = "%Y-%m-%d %H:%i:%s";
  371. $time = time();
  372. $now = mdate($datestring, $time);
  373. $exp = explode( "|", $this->input->post("project_reviewer") );
  374. $reviewer = serialize($exp);
  375. $url = spliturl($this->input->post("project_title"), 50);
  376. $project_keywords_temp = $this->input->post( "project_keywords" );
  377. $project_keywords_exp = explode( ',', $project_keywords_temp );
  378. $project_keywordstrim = array();
  379. foreach( $project_keywords_exp as $k => $v ) {
  380. array_push($project_keywordstrim, trim($v));
  381. }
  382. $project_keywords = serialize($project_keywordstrim);
  383. $data_project = array(
  384. "project_title" => $this->input->post("project_title"),
  385. "project_content" => $this->input->post("project_content"),
  386. "project_year" => $this->input->post("project_year"),
  387. "project_author" => $this->input->post("project_author"),
  388. "project_reviewer" => $reviewer,
  389. "project_jurusan" => $this->input->post("project_jurusan"),
  390. "project_fakultas" => $this->input->post("project_fakultas"),
  391. "project_strata" => $this->input->post("project_strata"),
  392. "project_keywords" => $project_keywords,
  393. "project_link" => $this->input->post("project_link")
  394. /* "project_url" => $url, */
  395. );
  396. $clause = array(
  397. "project_id" => $this->input->post("project_id")
  398. );
  399. $update_project = $this->projects_model->update_project($data_project, $clause);
  400. if( $update_project ){
  401. redirect("admin_review/".$this->uri->segment(2), "refresh");
  402. }
  403. }
  404. }