PageRenderTime 79ms CodeModel.GetById 28ms RepoModel.GetById 2ms app.codeStats 0ms

/application/controllers/webcontent_.php

https://gitlab.com/wildanoo/E-procurement
PHP | 387 lines | 260 code | 101 blank | 26 comment | 36 complexity | 77dd910ec9cadda84b30a5f99c7a8d30 MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. class Webcontent extends CI_Controller
  3. {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. $this->load->helper('url');
  8. $this->load->library('security');
  9. if (!$this->session->userdata('lang')) {
  10. $this->session->set_userdata('lang','eng');
  11. }
  12. }
  13. function index()
  14. {
  15. $this->load->view('content_public/page');
  16. }
  17. function page()
  18. {
  19. $param = $this->uri->segment(3);
  20. if ($this->session->userdata('lang') == 'eng') {
  21. $title = "title_eng";
  22. $detail = "detail_eng";
  23. }elseif ($this->session->userdata('lang') == 'ind') {
  24. $title = "title_ind";
  25. $detail = "detail_ind";
  26. }
  27. $joins[0][0] = 'subcontent_type';
  28. $joins[0][1] = 'subcontent_type.id = announce.subcontent_type';
  29. $joins[0][2] = 'left';
  30. $where = "status = '3' AND announce.id = '".$param."'";
  31. // $where = "status = '3' AND (CURDATE() BETWEEN DATE_FORMAT(publish_date, '%Y-%m-%d') AND DATE_FORMAT(end_valdate, '%Y-%m-%d')) AND announce.id = ".$param;
  32. $select = "announce.id,file,id_cat,id_subcat,code,content_type,subcontent_type,subcontent_type.subtype_name,".$title." AS title,".$detail." AS detail,first_valdate,end_valdate,publish_date,subcontent_type.behavior_id,status,announce.created_date";
  33. $browse_temp = $this->crud->browse_join("","announce","","","false",$select,$joins,$where);
  34. foreach ($browse_temp as $browse) {}
  35. if ($browse_temp) {
  36. $curdatetime = date('Y-m-d H:i:s');
  37. $startdate = $browse->first_valdate;
  38. $endate = $browse->end_valdate;
  39. if ($curdatetime<=$endate && $curdatetime>=$startdate) {
  40. $data['btn_join'] = true;
  41. }else{
  42. $data['btn_join'] = false;
  43. }
  44. $data['browse'] = $browse;
  45. if($browse->file){
  46. if ($this->session->userdata('lang') == 'eng') {
  47. $ctpath = "./uploads/contents/".$browse->file."_eng.txt";
  48. }elseif ($this->session->userdata('lang') == 'ind') {
  49. $ctpath = "./uploads/contents/".$browse->file."_ind.txt";
  50. }
  51. $attpath = "./uploads/attach/".$browse->file.".pdf";
  52. $data['contents'] = file_exists($ctpath) ? file_get_contents($ctpath) : "-";
  53. $data['attachment'] = file_exists($attpath) ? true : false;
  54. }
  55. $data['category'] = globalGetCategory();
  56. $data['subcategory'] = globalGetSubcategory();
  57. $data['subcontent'] = globalGetSubtype();
  58. $data['recent_post'] = globalRecentPost();
  59. $data['status'] = $this->getStatusCondition();
  60. if ($browse->content_type) {
  61. $data['articles'] = $this->getPrevNextArticle($param,$browse->content_type);
  62. }else{
  63. $data['articles'] = array();
  64. }
  65. $data['view'] = 'main/page';
  66. $this->load->view('layout/template_public',$data);
  67. }else{
  68. echo "not-found-richo";
  69. // redirect('page/error');
  70. }
  71. }
  72. function download(){
  73. $param = $this->uri->segment(3);
  74. $file = 'uploads/attach/'.$param;
  75. if (file_exists($file)) {
  76. header('Content-Description: File Transfer');
  77. header('Content-Type: application/octet-stream');
  78. header('Content-Disposition: attachment; filename="'.basename($file).'"');
  79. header('Expires: 0');
  80. header('Cache-Control: must-revalidate');
  81. header('Pragma: public');
  82. header('Content-Length: ' . filesize($file));
  83. readfile($file);
  84. exit;
  85. }
  86. }
  87. function login()
  88. {
  89. if ($this->tank_auth->is_logged_in()) { // logged in
  90. redirect('home/');
  91. } else {
  92. $data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND $this->config->item('use_username', 'tank_auth'));
  93. $data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');
  94. if ($this->session->userdata('lang') == 'eng') {
  95. $title = "title_eng";
  96. }elseif ($this->session->userdata('lang') == 'ind') {
  97. $title = "title_ind";
  98. }
  99. $joins[0][0] = 'subcontent_type';
  100. $joins[0][1] = 'subcontent_type.id = announce.subcontent_type';
  101. $joins[0][2] = 'left';
  102. $order = array('field'=>'created_date','order'=>'DESC');
  103. $select = "announce.id,code,content_type,subcontent_type,subcontent_type.subtype_name,".$title." AS title,detail,first_valdate,end_valdate,publish_date,status,announce.created_date";
  104. $contents = $this->crud->browse("","content_type","","","true","id");
  105. $data['browse'] = array();
  106. foreach ($contents as $content) {
  107. $where = "status = '3' AND (CURDATE() BETWEEN DATE_FORMAT(publish_date, '%Y-%m-%d') AND DATE_FORMAT(end_valdate, '%Y-%m-%d')) AND subcontent_type.content_id = ".$content->id;
  108. $browse_temp[$content->id] = $this->crud->browse_join_with_paging("","announce","","","true",$select,$joins,$where,$order,"5");
  109. }
  110. $data['browse'] = $browse_temp;
  111. $data['archived'] = $this->crud->browse("","announce","","","true");
  112. $data['type'] = array('1'=>'News','2'=>'Open Sourcing','3'=>'Open Bidding');
  113. $homepath = file_get_contents("./uploads/cms/home.txt");
  114. $data['content'] = $homepath;
  115. $dbcategory = $this->crud->browse("","category","","","true","id,category");
  116. $option = array(''=>'-- Category --');
  117. foreach($dbcategory as $val){ $category[$val->id] = $val->category; }
  118. $data['category'] = $option + $category;
  119. $this->load->view('auth/login', $data);
  120. }
  121. }
  122. function archive()
  123. {
  124. $indicator = $this->uri->segment(3);
  125. if ($indicator == 'news') {
  126. $extract = $this->getNewsArchive(10);
  127. $browse = $extract['getData'];
  128. $data['pagination'] = $extract['pagination'];
  129. $data['num'] = $extract['num'];
  130. $data['view'] = 'main/news_archive';
  131. }elseif ($indicator == 'announcement') {
  132. $extract = $this->getAnnouncementArchive(10);
  133. $browse = $extract['getData'];
  134. $data['pagination'] = $extract['pagination'];
  135. $data['num'] = $extract['num'];
  136. $data['status'] = $this->getStatusCondition();
  137. $data['view'] = 'main/announcement_archive';
  138. $data['category'] = globalGetCategory();
  139. $data['subcategory'] = globalGetSubcategory();
  140. $data['subcontent'] = globalGetSubtype();
  141. // $data['status'] = globalGetSubtype();
  142. }
  143. $data['browse'] = $browse;
  144. $data['recent_post'] = globalRecentPost();
  145. $data['title'] = ucfirst($indicator);
  146. $this->load->view('layout/template_public',$data);
  147. }
  148. private function getNewsArchive($limit = NULL){
  149. /* check vendor currently login */
  150. $sess_vendor = $this->session->userdata('cek_vendor_auth');
  151. /* ===== */
  152. /* check title based on 'lang' session */
  153. if ($this->session->userdata('lang') == 'eng') {
  154. $title = "title_eng";
  155. $detail = "detail_eng";
  156. }elseif ($this->session->userdata('lang') == 'ind') {
  157. $title = "title_ind";
  158. $detail = "detail_ind";
  159. }
  160. /* ===== */
  161. /* get news data from database with pagination */
  162. $select = "announce.id,code,content_type,subcontent_type,subcontent_type.subtype_name,".$title." AS title,".$detail." AS detail,first_valdate,end_valdate,publish_date,status,announce.created_date";
  163. $joins[0][0] = 'subcontent_type';
  164. $joins[0][1] = 'subcontent_type.id = announce.subcontent_type';
  165. $joins[0][2] = 'left';
  166. $order = array('field'=>'announce.publish_date','order'=>'DESC');
  167. $page = $this->uri->segment(4);
  168. $per_page = $limit;
  169. $offset = $this->crud->set_offset($page,$per_page);
  170. $where = "status = '3' AND content_type = '1' AND subcontent_type != '2' AND (CURDATE() >= DATE_FORMAT(publish_date, '%Y-%m-%d'))";
  171. $count_rows = $this->crud->browse_join('',"announce",'','','false',"COUNT(announce.id) AS COUNT",$joins,$where);
  172. $getData = $this->crud->browse_join_with_paging('',"announce",'','','true',$select,$joins,$where,$order,$per_page, $offset);
  173. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  174. $set_config = array('base_url'=> base_url().'webcontent/archive/news/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>4);
  175. $config = $this->crud->set_config($set_config);
  176. /** setup for pagination **/
  177. $this->load->library('pagination');
  178. $this->pagination->initialize($config);
  179. $paging = $this->pagination->create_links();
  180. /** ===== **/
  181. /* ===== */
  182. /* setup variable to used in another functions */
  183. $data['getData'] = $getData;
  184. $data['pagination'] = $paging;
  185. $data['num'] = $offset;
  186. /* ===== */
  187. return $data;
  188. }
  189. private function getAnnouncementArchive($limit = NULL){
  190. /* check vendor currently login */
  191. $sess_vendor = $this->session->userdata('cek_vendor_auth');
  192. /* ===== */
  193. /* check title based on 'lang' session */
  194. if ($this->session->userdata('lang') == 'eng') {
  195. $title = "title_eng";
  196. $detail = "detail_eng";
  197. }elseif ($this->session->userdata('lang') == 'ind') {
  198. $title = "title_ind";
  199. $detail = "detail_ind";
  200. }
  201. /* ===== */
  202. /* get news data from database with pagination */
  203. $select = "announce.id,id_cat,id_subcat,code,content_type,subcontent_type,subcontent_type.subtype_name,".$title." AS title,".$detail." AS detail,first_valdate,end_valdate,publish_date,status,announce.created_date";
  204. $joins[0][0] = 'subcontent_type';
  205. $joins[0][1] = 'subcontent_type.id = announce.subcontent_type';
  206. $joins[0][2] = 'left';
  207. $order = array('field'=>'announce.publish_date','order'=>'DESC');
  208. $page = $this->uri->segment(4);
  209. $per_page = $limit;
  210. $offset = $this->crud->set_offset($page,$per_page);
  211. $where = "status = '3' AND content_type = '2'";
  212. // $where = "status = '3' AND content_type = '2' AND (NOW() BETWEEN DATE_FORMAT(publish_date, '%Y-%m-%d %H:%i:%s') AND DATE_FORMAT(end_valdate, '%Y-%m-%d %H:%i:%s'))";
  213. $count_rows = $this->crud->browse_join('',"announce",'','','false',"COUNT(announce.id) AS COUNT",$joins,$where);
  214. $getData = $this->crud->browse_join_with_paging('',"announce",'','','true',$select,$joins,$where,$order,$per_page, $offset);
  215. $total_rows = count($count_rows)>0?$count_rows[0]->COUNT:0;
  216. $set_config = array('base_url'=> base_url().'webcontent/archive/announcement/','total_rows'=>$total_rows,'per_page'=>$per_page,'uri_segment'=>4);
  217. $config = $this->crud->set_config($set_config);
  218. /** setup for pagination **/
  219. $this->load->library('pagination');
  220. $this->pagination->initialize($config);
  221. $paging = $this->pagination->create_links();
  222. /** ===== **/
  223. /* ===== */
  224. /* setup variable to used in another functions */
  225. $data['getData'] = $getData;
  226. $data['pagination'] = $paging;
  227. $data['num'] = $offset;
  228. /* ===== */
  229. return $data;
  230. }
  231. private function getStatusCondition(){
  232. $data = array();
  233. $data = array(
  234. 0 => 'New',
  235. 1 => 'Published',
  236. 2 => 'Open for Joining',
  237. 3 => 'Ongoing',
  238. 4 => 'Closed',
  239. 99 => 'Canceled'
  240. );
  241. return $data;
  242. }
  243. private function getPrevNextArticle($id,$flag){
  244. $data['string1'] = '';
  245. $data['string2'] = '';
  246. $data['title1'] = '';
  247. $data['title2'] = '';
  248. $data['separator'] = '';
  249. if ($this->session->userdata('lang') == 'eng') {
  250. $title = "title_eng";
  251. }elseif ($this->session->userdata('lang') == 'ind') {
  252. $title = "title_ind";
  253. }
  254. $where = "(
  255. id = IFNULL((SELECT min(id) FROM announce WHERE id > ".$id." AND content_type = ".$flag."),0)
  256. OR id = IFNULL((SELECT max(id) FROM announce WHERE id < ".$id." AND content_type = ".$flag."),0)
  257. )";
  258. $select = "id,".$title." AS title";
  259. $order = array('field'=>'id','order'=>'ASC');
  260. $getData = $this->crud->browse('',"announce",'','','true',$select,$where,$order);
  261. if (count($getData) == 2) {
  262. $data['string1'] = $this->lang->line('page_detail_prev_article');
  263. $data['string2'] = $this->lang->line('page_detail_next_article');
  264. $data['title1'] = $getData[0]->title;
  265. $data['title2'] = $getData[1]->title;
  266. $data['separator'] = '<div class="next-prev-separator"></div>';
  267. }elseif (count($getData) == 1) {
  268. if ($getData[0]->id<$browse->id) {
  269. $data['string1'] = $this->lang->line('page_detail_prev_article');
  270. $data['string2'] = '';
  271. $data['title1'] = $getData[0]->title;
  272. $data['title2'] = '';
  273. $data['separator'] = '';
  274. }else{
  275. $data['string1'] = '';
  276. $data['string2'] = $this->lang->line('page_detail_next_article');
  277. $data['title1'] = '';
  278. $data['title2'] = $getData[0]->title;
  279. $data['separator'] = '';
  280. }
  281. }
  282. return $data;
  283. }
  284. }
  285. /* End of file auth.php */
  286. /* Location: ./application/controllers/auth.php */