PageRenderTime 61ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/fyadmin/products.php

https://gitlab.com/saalmanhussain/scayle_repo
PHP | 362 lines | 296 code | 66 blank | 0 comment | 51 complexity | dabc5e27f41f03ba7e1c5774b1d815a9 MD5 | raw file
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. class Products extends CI_Controller {
  5. function __construct() {
  6. parent::__construct();
  7. $this->load->database();
  8. $this->load->library('session');
  9. $this->load->helper('url');
  10. $this->load->model('fyadmin/query');
  11. $this->load->library('Custom');
  12. }
  13. public function get_view() {
  14. $total_segments = $this->uri->total_segments();
  15. $segments = $this->uri->segment($total_segments);
  16. return $segments;
  17. }
  18. public function index() {
  19. }
  20. public function add_product() {
  21. if ($this->session->userdata('Is_Login') == true) {
  22. $data["msg"] = "";
  23. if (isset($_POST['add_product'])) {
  24. if ($_FILES['pro_image']['tmp_name']) {
  25. $config['file_name'] = $_FILES['pro_image']['name'];
  26. $config['upload_path'] = 'assets/upload/';
  27. $config['allowed_types'] = 'jpg|jpeg|png';
  28. $this->load->library('upload', $config);
  29. $this->upload->do_upload('pro_image');
  30. $Image1 = $this->upload->data();
  31. $pro_image = $Image1['file_name'];
  32. } else {
  33. $pro_image = '';
  34. }
  35. $data = array(
  36. 'title' => $this->input->post('title'),
  37. 'SubText' => $this->input->post('SubText'),
  38. 'Price' => $this->input->post('Price'),
  39. 'OldPrice' => $this->input->post('OldPrice'),
  40. 'seo' => $this->custom->seo_Url($this->input->post('title')),
  41. 'description' => $this->input->post('description'),
  42. 'image' => $pro_image,
  43. 'cat_id' => $this->input->post('category'),
  44. 'status' => 1,
  45. 'created' => date("Y-m-d"),
  46. 'accountId_created' => $this->input->post('AccountId')
  47. );
  48. $table = 'product';
  49. $query = $this->query->insert_query($table, $data);
  50. if ($query['query'] == 1) {
  51. $this->session->set_userdata('Success', "Record Has Been Successfully Added...");
  52. redirect('fyadmin/products/add_product');
  53. } else {
  54. $this->session->set_userdata('Error', "Please Try Again");
  55. redirect('fyadmin/products/add_product');
  56. }
  57. }
  58. $id = $this->session->userdata('AccountId');
  59. $type = $this->session->userdata('Account_Type');
  60. $data['site_Info'] = $this->custom->site_Info();
  61. $data['profile_Info'] = $this->custom->profile_Info($id);
  62. $data['page_active'] = $this->get_view();
  63. $data['cat'] = $this->query->get_all_active_categories();
  64. $data['partner'] = $this->query->get_all_partner();
  65. $this->load->view('fyadmin/add_product', $data);
  66. } else {
  67. redirect('fyadmin/');
  68. }
  69. }
  70. public function view_product_sold() {
  71. if ($this->session->userdata('Is_Login') == true) {
  72. $id = $this->session->userdata('AccountId');
  73. $type = $this->session->userdata('Account_Type');
  74. $data['site_Info'] = $this->custom->site_Info();
  75. $data['profile_Info'] = $this->custom->profile_Info($id);
  76. $data['msg'] = "";
  77. $data['page_active'] = $this->get_view();
  78. $this->load->view('fyadmin/view_product_sold', $data);
  79. } else {
  80. redirect('fyadmin/');
  81. }
  82. }
  83. public function view_product_Json_sold() {
  84. $status = "";
  85. if($this->session->userdata('Account_Type') == 1)
  86. {
  87. $product = $this->query->get_all_products_sold();
  88. }
  89. else
  90. {
  91. $product = $this->query->get_all_products_users_sold($this->session->userdata('AccountId'));
  92. }
  93. $count=1;
  94. foreach ($product as $row) {
  95. $status .= "<a class='waves-effect waves-dark btn purple' title='Edit' href='" . base_url() . "fyadmin/products/edit_product?id=" . base64_encode($row->proID) . "'>
  96. <i class='mdi-editor-mode-edit'></i></a>";
  97. if ($row->status == 0) {
  98. $status .= "<a class='waves-effect waves-dark btn red' title='Enable' href='" . base_url() . "fyadmin/products/activate_product?id=" . base64_encode($row->proID) . "'>
  99. <i class='mdi-action-thumb-up'></i></a>";
  100. } else {
  101. $status .= "<a class='waves-effect waves-dark btn red' title='Disable' href='" . base_url() . "fyadmin/products/delete_product?id=" . base64_encode($row->proID) . "'>
  102. <i class='mdi-action-thumb-down'></i></a>";
  103. }
  104. $rows[0] = $count++;
  105. $rows[1] = $row->title;
  106. $rows[2] = $row->username;
  107. $rows[3] = $row->product_url;
  108. $rows[4] = $row->cat_name;
  109. $rows[5] = "<img src='" . PATH . "upload/$row->image' height='100' />";
  110. $rows[6] = $row->dealer;
  111. $rows[7] = "$".$row->price;
  112. $rows[8] = date('Y-M-d', strtotime($row->created));
  113. $response['aaData'][] = $rows;
  114. $status = "";
  115. }
  116. if(count($product) == 0)
  117. {
  118. $rows[0] = "";
  119. $rows[1] = "";
  120. $rows[2] = "";
  121. $rows[3] = "";
  122. $rows[4] = "";
  123. $rows[5] = "";
  124. $rows[6] = "";
  125. $rows[7] = "";
  126. $rows[8] = "";
  127. $response['aaData'][] = $rows;
  128. }
  129. echo json_encode($response, true);
  130. }
  131. public function view_product() {
  132. if ($this->session->userdata('Is_Login') == true) {
  133. $id = $this->session->userdata('AccountId');
  134. $type = $this->session->userdata('Account_Type');
  135. $data['site_Info'] = $this->custom->site_Info();
  136. $data['profile_Info'] = $this->custom->profile_Info($id);
  137. $data['msg'] = "";
  138. $data['page_active'] = $this->get_view();
  139. $this->load->view('fyadmin/view_product', $data);
  140. } else {
  141. redirect('fyadmin/');
  142. }
  143. }
  144. public function view_product_Json() {
  145. $status = "";
  146. if($this->session->userdata('Account_Type') == 1)
  147. {
  148. $product = $this->query->get_all_products();
  149. }
  150. else
  151. {
  152. $product = $this->query->get_all_products_users($this->session->userdata('AccountId'));
  153. }
  154. $count=1;
  155. foreach ($product as $row) {
  156. $status .= "<a class='waves-effect waves-dark btn purple' title='Edit' href='" . base_url() . "fyadmin/products/edit_product?id=" . base64_encode($row->proID) . "'>
  157. <i class='mdi-editor-mode-edit'></i></a>";
  158. if ($row->status == 0) {
  159. $status .= "<a class='waves-effect waves-dark btn red' title='Enable' href='" . base_url() . "fyadmin/products/activate_product?id=" . base64_encode($row->proID) . "'>
  160. <i class='mdi-action-thumb-up'></i></a>";
  161. } else {
  162. $status .= "<a class='waves-effect waves-dark btn red' title='Disable' href='" . base_url() . "fyadmin/products/delete_product?id=" . base64_encode($row->proID) . "'>
  163. <i class='mdi-action-thumb-down'></i></a>";
  164. }
  165. $rows[0] = $count++;
  166. $rows[1] = $row->title;
  167. $rows[2] = $row->SubText;
  168. $rows[3] = $row->cat_name;
  169. $rows[4] = $row->dealer;
  170. $rows[5] = date('Y-M-d', strtotime($row->created));
  171. $rows[6] = $status;
  172. $response['aaData'][] = $rows;
  173. $status = "";
  174. }
  175. if(count($product) == 0)
  176. {
  177. $rows[0] = "";
  178. $rows[1] = "";
  179. $rows[2] = "";
  180. $rows[3] = "";
  181. $rows[4] = "";
  182. $rows[5] = "";
  183. $rows[6] = "";
  184. $response['aaData'][] = $rows;
  185. }
  186. echo json_encode($response, true);
  187. }
  188. public function delete_product() {
  189. if ($this->session->userdata('Is_Login') == true) {
  190. $id = base64_decode($_GET['id']);
  191. $data = array(
  192. 'status' => 0
  193. );
  194. $query = $this->query->update_query('product', $data, 'proID', $id);
  195. if ($query == 1) {
  196. $this->session->set_userdata('Success', "Product Disabled Successfully");
  197. } else {
  198. $this->session->set_userdata('Error', "Please Try Again");
  199. }
  200. redirect(base_url().'fyadmin/products/view_product');
  201. $id = $this->session->userdata('AccountId');
  202. $type = $this->session->userdata('Account_Type');
  203. $data['site_Info'] = $this->custom->site_Info();
  204. $data['page_active'] = $this->get_view();
  205. $data['profile_Info'] = $this->custom->profile_Info($id);
  206. $this->load->view('fyadmin/view_product', $data);
  207. } else {
  208. redirect('fyadmin/');
  209. }
  210. }
  211. public function activate_product() {
  212. if ($this->session->userdata('Is_Login') == true) {
  213. $id = base64_decode($_GET['id']);
  214. $data = array(
  215. 'status' => 1
  216. );
  217. $query = $this->query->update_query('product', $data, 'proID', $id);
  218. if ($query == 1) {
  219. $this->session->set_userdata('Success', "Product Enabled Successfully");
  220. } else {
  221. $this->session->set_userdata('Error', "Please Try Again");
  222. }
  223. redirect(base_url().'fyadmin/products/view_product');
  224. $id = $this->session->userdata('AccountId');
  225. $type = $this->session->userdata('Account_Type');
  226. $data['site_Info'] = $this->custom->site_Info();
  227. $data['page_active'] = $this->get_view();
  228. $data['profile_Info'] = $this->custom->profile_Info($id);
  229. $this->load->view('fyadmin/view_product', $data);
  230. } else {
  231. redirect('fyadmin/');
  232. }
  233. }
  234. public function edit_product() {
  235. if ($this->session->userdata('Is_Login') == true) {
  236. $id = base64_decode($_GET['id']);
  237. $data['msg'] = "";
  238. if (isset($_POST['edit_product'])) {
  239. if ($_FILES['pro_image']['tmp_name']) {
  240. $config['file_name'] = $_FILES['pro_image']['name'];
  241. $config['upload_path'] = 'assets/upload/';
  242. $config['allowed_types'] = 'jpg|jpeg|png';
  243. $this->load->library('upload', $config);
  244. $this->upload->do_upload('pro_image');
  245. $Image1 = $this->upload->data();
  246. $pro_image = $Image1['file_name'];
  247. } else {
  248. $pro_image = $this->input->post('pro_old_image');
  249. }
  250. $data = array(
  251. 'title' => $this->input->post('title'),
  252. 'SubText' => $this->input->post('SubText'),
  253. 'Price' => $this->input->post('Price'),
  254. 'OldPrice' => $this->input->post('OldPrice'),
  255. 'seo' => $this->custom->seo_Url($this->input->post('title')),
  256. 'description' => $this->input->post('description'),
  257. 'image' => $pro_image,
  258. 'cat_id' => $this->input->post('category'),
  259. 'status' => 1,
  260. 'updated' => date("Y-m-d"),
  261. 'accountId_created' => $this->input->post('AccountId'),
  262. 'accountId_updated' => $this->input->post('AccountId')
  263. );
  264. $table = 'product';
  265. $pro_id = $this->input->post('proID');
  266. $query = $this->query->update_query($table, $data, 'proID', $pro_id);
  267. if ($query == 1){
  268. $this->session->set_userdata('Success', "Record Has Been Successfully Updated...");
  269. redirect('fyadmin/products/edit_product?id='.base64_encode($pro_id));
  270. } else {
  271. $this->session->set_userdata('Error', "Please Try Again");
  272. redirect('fyadmin/products/edit_product?id='.base64_encode($pro_id));
  273. }
  274. }
  275. $a_id = $this->session->userdata('AccountId');
  276. $type = $this->session->userdata('Account_Type');
  277. $data['site_Info'] = $this->custom->site_Info();
  278. $data['profile_Info'] = $this->custom->profile_Info($a_id);
  279. $data['cat'] = $this->query->get_all_active_categories();
  280. $data['pro'] = $this->query->get_pro_detail($id);
  281. $data['proID'] = $id;
  282. $data['page_active'] = $this->get_view();
  283. $data['partner'] = $this->query->get_all_partner();
  284. $this->load->view('fyadmin/edit_product', $data);
  285. } else {
  286. redirect('fyadmin/');
  287. }
  288. }
  289. public function delete_images()
  290. {
  291. $id = $_GET['id'];
  292. $img_id = $_GET['img_id'];
  293. $query = $this->query->delete('product_images','image_id',base64_encode($img_id));
  294. redirect(base_url().'fyadmin/products/edit_product?id='. base64_encode($id));
  295. }
  296. }