PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/manager/application/controllers/core.php

https://bitbucket.org/jerwinse/iagh-cms
PHP | 165 lines | 146 code | 14 blank | 5 comment | 16 complexity | 9fc9e7a9e367239212443334c0afe311 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Core extends CI_Controller{
  3. private $workspaceId;
  4. public function __construct(){
  5. parent::__construct();
  6. $this->tal->title = $this->config->item('title');
  7. $this->tal->base_url = substr(base_url(), 0, -1);
  8. # check if session expires
  9. if(!$this->ion_auth->user()->result()){
  10. exit;
  11. }
  12. $this->user = $this->ion_auth->user()->result();
  13. $this->user[0]->fullname = $this->user[0]->first_name . ' ' . $this->user[0]->last_name;
  14. $config = array('userID' => $this->user[0]->id);
  15. $this->load->library('acl', $config);
  16. if (!$this->acl->userRoles){
  17. exit;
  18. }
  19. else{
  20. $this->workspaceId = $this->acl->userRoles[0];
  21. }
  22. }
  23. public function papiCall($method="GET", $function="", $options=array()){
  24. $papi = array();
  25. $papi['method'] = $method;
  26. $papi['papiCall'] = $function;
  27. $papi['data'] = $options;
  28. $this->curl->PAPIConfig($papi);
  29. $res = $this->curl->execute();
  30. return json_decode($res['message']);
  31. }
  32. public function login(){
  33. $options =array();
  34. $sectionId = 72;
  35. $data = array();
  36. $options = array("WorkspaceID"=>$this->workspaceId, "TypeID"=>3, "SectionID"=>$sectionId);
  37. $papiResult = $this->papiCall("GET", "Content.GetAll", $options);
  38. if($papiResult->Status){
  39. $data['videos'] = $papiResult->Content;
  40. }
  41. $this->load->view('core/login.zpt', $data);
  42. }
  43. public function saveVideoPage(){
  44. $res = array();
  45. $res['status'] = 0;
  46. $options = array();
  47. # edit video
  48. if($_POST['videoId']){
  49. $videoId = $_POST['videoId'];
  50. $options = array(
  51. "ID"=>$videoId,
  52. "TypeID"=>3,
  53. "Name"=>$_POST['title'],
  54. "Description"=>$_POST['description'],
  55. "URL"=>$_POST['url'],
  56. "ThumbnailURL"=>$_POST['thumbnailUrl'],
  57. "WorkspaceID"=>$this->workspaceId
  58. );
  59. $this->papiCall("POST", "Content.Update", $options);
  60. $res['status'] = 1;
  61. }
  62. # add video
  63. else{
  64. $sectionId = $_POST['sectionId'];
  65. $options = array(
  66. "TypeID"=>3,
  67. "Status"=>1,
  68. "Description"=>$_POST['description'],
  69. "Name"=>$_POST['title'],
  70. "URL"=>$_POST['url'],
  71. "ThumbnailURL"=>$_POST['thumbnailUrl'],
  72. "WorkspaceID"=>$this->workspaceId,
  73. "SectionID"=>$sectionId
  74. );
  75. $papiResult = $this->papiCall("POST", "Content.Create", $options);
  76. $res['status'] = 1;
  77. }
  78. print_r(json_encode($res));
  79. }
  80. public function home(){
  81. $options =array();
  82. $sectionId = 71;
  83. $data = array();
  84. $options = array("WorkspaceID"=>$this->workspaceId, "TypeID"=>3, "SectionID"=>$sectionId);
  85. $papiResult = $this->papiCall("GET", "Content.GetAll", $options);
  86. if($papiResult->Status){
  87. $data['videos'] = $papiResult->Content;
  88. }
  89. $this->load->view('core/home.zpt', $data);
  90. }
  91. public function addVideo(){
  92. if(isset($_GET['page'])){
  93. $page = $_GET['page'];
  94. }
  95. $sectionId = $page == "login" ? 72 : 71;
  96. $data['sectionId'] = $sectionId;
  97. $data['callback'] = $page;
  98. $data['isAddRequest'] = true;
  99. $data['workspaceId'] = $this->workspaceId;
  100. $this->load->view('core/videoForm.zpt', $data);
  101. }
  102. public function editVideo(){
  103. $data = array();
  104. $data['isAddRequest'] = false;
  105. $page = isset($_GET['page'])?$_GET['page']:"";
  106. if(isset($_GET['id'])){
  107. $videoId = $_GET['id'];
  108. $options = array();
  109. $options = array("ID"=>$videoId);
  110. $papiResult = $this->papiCall("GET", "Content.Get", $options);
  111. if($papiResult->Status){
  112. $data['video'] = $papiResult->Video;
  113. }
  114. }
  115. $data['callback'] = $page;
  116. $this->load->view('core/videoForm.zpt', $data);
  117. }
  118. public function deleteVideo(){
  119. $res = array();
  120. $res['status'] = 0;
  121. if(isset($_POST['id']) && !empty($_POST['id'])){
  122. $papiCall = $_POST['papiCall'];
  123. $id = explode(",", $_POST['id']);
  124. for($i=0; $i<count($id); $i++){
  125. $this->papiCall("POST", $papiCall, array("ID"=>$id[$i]));
  126. }
  127. $res['status'] = 1;
  128. }
  129. print_r(json_encode($res));
  130. }
  131. public function publishVideo(){
  132. $res = array();
  133. $res['status'] = 0;
  134. $videoId = isset($_POST['videoId'])?$_POST['videoId']:"";
  135. $workspaceId = $this->workspaceId;
  136. if($videoId){
  137. $papiResult = $this->papiCall("GET", "Content.GetAll", array("TypeID"=>3, "WorkspaceID"=>$workspaceId));
  138. if($papiResult->Status){
  139. $content = $papiResult->Content;
  140. # set all status to 0
  141. for($i=0; $i<count($content);$i++){
  142. $this->papiCall("POST", "Content.Update", array("ID"=>$content[$i]->ID, "Status"=>0));
  143. }
  144. }
  145. # set status to 1
  146. $papiResult = $this->papiCall("POST", "Content.Update", array("ID"=>$videoId, "Status"=>1));
  147. $res['status'] = $papiResult->Status;
  148. }
  149. print_r(json_encode($res));
  150. }
  151. }