Advertisement
xeon9

Sample codes for Mr. Raul

Jul 25th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.46 KB | None | 0 0
  1. <?php if (! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Admin2 extends CI_Controller
  4. {
  5. public $data = array();
  6. public $data2 = array();
  7. public $data3 = array();
  8.  
  9. function __construct ()
  10. {
  11. parent::__construct();
  12.  
  13. $this->load->helper('url');
  14. $this->load->helper('form');
  15. $this->load->model('folio_model');
  16. $this->load->library('form_validation');
  17. $this->load->library('pagination');
  18. //$this->load->spark('markdown-extra/0.0.0');
  19.  
  20. $this->data['message'] = '';
  21. $this->data['error'] = '';
  22. $this->data['title'] = 'Control Panel';
  23. $this->data['body_title'] = '';
  24. $this->data['body_content'] = '';
  25.  
  26. $this->data['records'][0]['title'] = '';
  27. $this->data['records'][0]['title_url'] = '';
  28. $this->data['records'][0]['description'] = '';
  29. $this->data['records'][0]['version'] = 0;
  30. $this->data['records'][0]['stage'] = '';
  31. $this->data['records'][0]['last_update_yr'] = 0;
  32. $this->data['records'][0]['last_update_mo'] = '';
  33. $this->data['records'][0]['last_update_dy'] = 0;
  34. $this->data['records'][0]['date_started_yr'] = 0;
  35. $this->data['records'][0]['date_started_mo'] = '';
  36. $this->data['records'][0]['date_started_dy'] = 0;
  37. $this->data['records'][0]['date_finished_yr'] = 0;
  38. $this->data['records'][0]['date_finished_mo'] = '';
  39. $this->data['records'][0]['date_finished_dy'] = 0;
  40. $this->data['records'][0]['photo_url'] = '';
  41. $this->data['records'][0]['video_url'] = '';
  42. $this->data['records'][0]['technology'] = '';
  43. $this->data['records'][0]['buy'] = '';
  44. $this->data['records'][0]['document'] = '';
  45. $this->data['records'][0]['demo'] = '';
  46. $this->data['records'][0]['download'] = '';
  47. $this->data['records'][0]['changelog'] = '';
  48. }
  49.  
  50. //Display Admin Login form page
  51. function index()
  52. {
  53. //$this->data['body_title'] = '';
  54. //$this->data['body_content'] = '<br><br><br><br><br><center><h2>jazPortfolio</h2></center><br><br><br><br><br><br><br><br>';
  55. //$this->load->view('admin2/cpanel', $this->data);
  56.  
  57. $this->data['password_header'] = $this->load->view('admin2/password_header', $this->data, TRUE);
  58. $this->load->view('admin2/password', $this->data);
  59. }
  60.  
  61. function about_admin()
  62. {
  63. if($this->compare_user_pass())
  64. {
  65. $this->data['body_title'] = 'About';
  66. $this->data['body_content'] = $this->load->view('admin2/about', $this->data, TRUE);
  67. $this->load->view('admin2/cpanel', $this->data);
  68. }
  69. else
  70. {
  71. //Display error message
  72. $this->error_access();
  73. }
  74. }
  75.  
  76. //main page
  77. function login_page()
  78. {
  79. $this->data['message'] = $this->session->flashdata('message');
  80. $this->data['password_header'] = $this->load->view('admin2/password_header', $this->data, TRUE);
  81.  
  82. $this->load->view('admin2/password', $this->data);
  83. }
  84.  
  85. function login(){
  86. //Capture data and validate
  87. $this->form_validation->set_rules('username', 'Username', 'required');
  88. $this->form_validation->set_rules('password', 'Password', 'required');
  89.  
  90. if ($this->form_validation->run() == FALSE)
  91. {
  92. //If validation has error display form again with error messages.
  93. $this->index();
  94. }
  95. else
  96. {
  97. //If form validation has no error catch $username and $password
  98. //Call login method
  99. $user = $this->input->post('username', TRUE);
  100. $pass = $this->input->post('password', TRUE);
  101.  
  102. //store username and password to session.
  103. $this->session->set_userdata('username', $user);
  104. $this->session->set_userdata('password', $pass);
  105.  
  106. if($this->folio_model->login($user, $pass))
  107. {
  108. //If everything is okay redirect to Admin Conrol Panel.
  109. $this->data['body_title'] = '';
  110. $this->data['body_content'] = '<br><br><br><br><br><center><h2>jazPortfolio</h2></center><br><br><br><br><br><br><br><br>';
  111.  
  112. $this->data['cpanel_header'] = $this->load->view('admin2/cpanel_header', $this->data, TRUE);
  113. //$this->load->view('admin/admincpanel', $this->data);
  114. $this->load->view('admin2/cpanel', $this->data);
  115. }
  116. else
  117. {
  118. //If login failed display error message.
  119. $this->session->set_flashdata('message', 'Invalid username or password.');
  120. redirect('admin/admin2/login_page');
  121. }
  122.  
  123. }
  124. }
  125.  
  126.  
  127.  
  128. /***********************************************************************************
  129. * Settings methods
  130. ***********************************************************************************/
  131. function follow_links()
  132. {
  133. if($this->compare_user_pass())
  134. {
  135. $this->data['error'] = ' ';
  136. $this->data['body_title'] = 'Follow Links';
  137. $this->load->view('admin2/follow_links_form', $this->data);
  138. }
  139. else
  140. {
  141. //Display error message
  142. $this->error_access();
  143. }
  144. }
  145.  
  146. function follow_links_proc()
  147. {
  148. //Capture data and validate
  149. $this->form_validation->set_rules('home', 'Home', '');
  150. $this->form_validation->set_rules('about', 'About', '');
  151. $this->form_validation->set_rules('blog', 'Blog', '');
  152. $this->form_validation->set_rules('linkedin', 'Linkedin', '');
  153. $this->form_validation->set_rules('facebook', 'FaceBook', '');
  154. $this->form_validation->set_rules('twitter', 'Twitter', '');
  155. $this->form_validation->set_rules('googleplus', 'Google+', '');
  156. $this->form_validation->set_rules('rss', 'RSS', '');
  157. $this->form_validation->set_rules('youtube', 'YouTube', '');
  158. $this->form_validation->set_rules('contact', 'Contact Us', '');
  159.  
  160. if ($this->form_validation->run() == FALSE)
  161. {
  162. //If validation has error display form again with error messages.
  163. $this->follow_links();
  164. }
  165. else
  166. {
  167. //If form validation has no error catch $username and $new_username data
  168. $home = $this->input->post('home', TRUE);
  169. $about = $this->input->post('about', TRUE);
  170. $blog = $this->input->post('blog', TRUE);
  171. $linkedin = $this->input->post('linkedin', TRUE);
  172. $facebook = $this->input->post('facebook', TRUE);
  173. $twitter = $this->input->post('twitter', TRUE);
  174. $googleplus = $this->input->post('googleplus', TRUE);
  175. $rss = $this->input->post('rss', TRUE);
  176. $youtube = $this->input->post('youtube', TRUE);
  177. $contact = $this->input->post('contact', TRUE);
  178.  
  179. if($home == 'yes')
  180. {
  181. $home = base_url();
  182. }
  183.  
  184. if($about == 'yes')
  185. {
  186. $about = base_url('front/about/');
  187. }
  188.  
  189. if($contact == 'yes')
  190. {
  191. $contact = base_url('front/contact/');
  192. }
  193.  
  194. if($this->folio_model->save_follow_links($home, $facebook, $twitter, $rss, $youtube, $contact, $about, $blog, $linkedin, $googleplus))
  195. {
  196. //If everything is okay, display success message
  197. $this->data['error_msg'] = '<b>Follow Links successfully saved</b><br>';
  198. $this->load->view('admin2/error_page', $this->data);
  199. }
  200. else
  201. {
  202. //Else display fail message.
  203. $this->data['error_msg'] = '<b>Saving Follow Links failed</b><br><b>Or you submitted all the fields empty.</b>';
  204. $this->load->view('admin2/error_page', $this->data);
  205. }
  206. }
  207. }
  208.  
  209. function follow_links_reset()
  210. {
  211. if($this->folio_model->reset_follow_links())
  212. {
  213. //If everything is okay, display success message
  214. $this->data['error_msg'] = '<b>Reset successful.</b><br>';
  215. $this->load->view('admin2/error_page', $this->data);
  216. }
  217. else
  218. {
  219. //Else display fail message.
  220. $this->data['error_msg'] = '<b>Reset failed</b><br>';
  221. $this->load->view('admin2/error_page', $this->data);
  222. }
  223. }
  224.  
  225. //Not in use, just for future reference
  226. function change_banner_mark_down()
  227. {
  228. $this->data['body_title'] = 'Change Banner';
  229. $md = file_get_contents(APPPATH . 'views/admin2/change_banner_form.php');
  230. $this->data['body_content'] = parse_markdown_extra($md);
  231. $this->load->view('admin2/cpanel', $this->data);
  232. }
  233.  
  234. function change_banner()
  235. {
  236. if($this->compare_user_pass())
  237. {
  238. $this->data['body_title'] = 'Change Banner';
  239. $this->data['error'] = $this->session->userdata('error_msg');
  240. $this->load->view('admin2/change_banner_form', $this->data);
  241. }
  242. else
  243. {
  244. //Display error message
  245. $this->error_access();
  246. }
  247. }
  248.  
  249. function change_banner_proc()
  250. {
  251. $config['upload_path'] = './images/';
  252. $config['allowed_types'] = 'gif|jpg|png';
  253. $config['max_size'] = '2048';
  254. $config['max_width'] = '1170';
  255. $config['max_height'] = '200';
  256.  
  257. $this->load->library('upload', $config);
  258.  
  259. if (!$this->upload->do_upload())
  260. {
  261. //If file upload fail display form again with error message.
  262. $this->data['error_msg'] = $this->upload->display_errors();
  263. $this->load->view('admin2/error_upload', $this->data);
  264. }
  265. else
  266. {
  267. //If file upload is successful dispaly success message
  268. $data = array('upload_data' => $this->upload->data());
  269. //catch uploaded filename.
  270. $uploaded_filename = $data['upload_data']['file_name'];
  271. //Delete banner.jpg
  272. unlink('./images/banner.jpg');
  273. //rename uploaded file to banner.jpg
  274. $uploaded_filename_inside_images = './images/'.$uploaded_filename;
  275. rename($uploaded_filename_inside_images, "./images/banner.jpg");
  276. //Display success page
  277. $this->data['error_msg'] = 'File Upload successful.';
  278. //$this->load->view('admin2/error_upload', $this->data);
  279. }
  280. }
  281.  
  282. //Set banner to default
  283. function banner_default()
  284. {
  285. if($this->compare_user_pass())
  286. {
  287. //Delete current banner.jpg
  288. unlink('./images/banner.jpg');
  289. //rename banner_default.jpg to banner.jpg
  290. if(copy("./images/banner_default.jpg", "./images/banner.jpg"))
  291. {
  292. $this->data['error_msg'] = 'Banner photo successfully set to default.';
  293. $this->load->view('admin2/error_page', $this->data);
  294. }
  295. }
  296. else
  297. {
  298. //Display error message
  299. $this->error_access();
  300. }
  301. }
  302.  
  303. function change_skin()
  304. {
  305. $this->data['msg'] = '<h3>Coming soon...</h3>';
  306. $this->load->view('admin/message', $this->data);
  307. }
  308.  
  309.  
  310. function footer()
  311. {
  312. if($this->compare_user_pass())
  313. {
  314. $this->data['body_title'] = 'Change Footer';
  315. $this->data['error'] = ' ';
  316. $this->data['content'] = ' ';
  317. $this->load->view('admin2/change_footer_form', $this->data);
  318. }
  319. else
  320. {
  321. //Display error message
  322. $this->error_access();
  323. }
  324. }
  325.  
  326. function footer_edit()
  327. {
  328. if($this->compare_user_pass())
  329. {
  330. $this->data['body_title'] = 'Edit About';
  331. $this->data['error'] = ' ';
  332. $this->data['content'] = $this->folio_model->get_footer_content();
  333. $this->load->view('admin2/change_footer_form', $this->data);
  334. }
  335. else
  336. {
  337. //Display error message
  338. $this->error_access();
  339. }
  340. }
  341.  
  342. function footer_proc()
  343. {
  344. //Capture data and validate
  345. $this->form_validation->set_rules('content', 'Footer Texts', 'required');
  346.  
  347. if ($this->form_validation->run() == FALSE)
  348. {
  349. //If validation has error display form again with error messages.
  350. $this->change_footer();
  351. }
  352. else
  353. {
  354. //If form validation has no error catch $footer_text
  355. $texts = $this->input->post('content', TRUE);
  356.  
  357. if($this->folio_model->change_footer($texts))
  358. {
  359. //If everything is okay, display success message
  360. $this->data['error_msg'] = 'Success changing footer texts';
  361. $this->load->view('admin2/error_page', $this->data);
  362. }
  363. else
  364. {
  365. //Else display fail message.
  366. $this->data['error_msg'] = 'Changing footer texts failed';
  367. $this->load->view('admin2/error_page', $this->data);
  368. }
  369. }
  370. }
  371.  
  372. function number_records()
  373. {
  374. if($this->compare_user_pass())
  375. {
  376. $this->data['body_title'] = 'Number of Records';
  377. $this->data['error'] = ' ';
  378. $this->data['content'] = '';
  379. $this->load->view('admin2/number_records_form', $this->data);
  380. }
  381. else
  382. {
  383. //Display error message
  384. $this->error_access();
  385. }
  386. }
  387.  
  388. function number_records_proc()
  389. {
  390. $this->form_validation->set_rules('numrec', 'Number of Records', 'required');
  391.  
  392. if ($this->form_validation->run() == FALSE)
  393. {
  394. //If validation has error display form again with error messages.
  395. $this->number_records();
  396. }
  397. else
  398. {
  399. //If form validation has no error catch $content
  400. $numrec = $this->input->post('numrec', TRUE);
  401.  
  402. $data = array(
  403. 'number' => $numrec
  404. );
  405.  
  406. if($this->folio_model->save_number($data))
  407. {
  408. //If everything is okay, display success message
  409. $this->data['error_msg'] = '<b>Number per page successfully saved.</b><br>';
  410. $this->load->view('admin2/error_page', $this->data);
  411. }
  412. else
  413. {
  414. //Else display fail message.
  415. $this->data['error_msg'] = '<b>Saving number per page failed</b><br>';
  416. $this->load->view('admin2/error_page', $this->data);
  417. }
  418. }
  419. }
  420.  
  421. function about()
  422. {
  423. if($this->compare_user_pass())
  424. {
  425. $this->data['body_title'] = 'About';
  426. $this->data['error'] = ' ';
  427. $this->data['content'] = '';
  428. $this->load->view('admin2/about_form', $this->data);
  429. }
  430. else
  431. {
  432. //Display error message
  433. $this->error_access();
  434. }
  435. }
  436.  
  437. function about_edit()
  438. {
  439. if($this->compare_user_pass())
  440. {
  441. $this->data['body_title'] = 'Edit About';
  442. $this->data['error'] = ' ';
  443. $this->data['content'] = $this->folio_model->get_about_content();
  444. $this->load->view('admin2/about_form', $this->data);
  445. }
  446. else
  447. {
  448. //Display error message
  449. $this->error_access();
  450. }
  451. }
  452.  
  453. function about_proc()
  454. {
  455. //Capture data and validate
  456. $this->form_validation->set_rules('content', 'Content', 'required');
  457.  
  458. if ($this->form_validation->run() == FALSE)
  459. {
  460. //If validation has error display form again with error messages.
  461. $this->about();
  462. }
  463. else
  464. {
  465. //If form validation has no error catch $content
  466. $texts = $this->input->post('content', TRUE);
  467.  
  468. $data = array(
  469. 'content' => $texts
  470. );
  471.  
  472. if($this->folio_model->save_content($data))
  473. {
  474. //If everything is okay, display success message
  475. $this->data['error_msg'] = '<b>Content texts successfully saved.</b><br>';
  476. $this->load->view('admin2/error_page', $this->data);
  477. }
  478. else
  479. {
  480. //Else display fail message.
  481. $this->data['error_msg'] = '<b>Saving content message failed</b><br>';
  482. $this->load->view('admin2/error_page', $this->data);
  483. }
  484. }
  485. }
  486.  
  487.  
  488. function skin()
  489. {
  490. if($this->compare_user_pass())
  491. {
  492. $this->data['body_title'] = 'Skin';
  493. $this->data['error'] = ' ';
  494. $this->data['content'] = '';
  495. $this->load->view('admin2/skin_form', $this->data);
  496. }
  497. else
  498. {
  499. //Display error message
  500. $this->error_access();
  501. }
  502. }
  503.  
  504. function skin_proc()
  505. {
  506. //Capture data and validate
  507. $this->form_validation->set_rules('skin', 'Skin', '');
  508.  
  509. if ($this->form_validation->run() == FALSE)
  510. {
  511. //If validation has error display form again with error messages.
  512. $this->skin();
  513. }
  514. else
  515. {
  516. //If form validation has no error catch $content
  517. $skin = 'template/'. $this->input->post('skin', TRUE);
  518. $skin2 = $skin. '2';
  519.  
  520. $data = array(
  521. 'skin1' => $skin,
  522. 'skin2' => $skin2,
  523. );
  524.  
  525. if($this->folio_model->save_skin($data))
  526. {
  527. //If everything is okay, display success message
  528. $this->data['error_msg'] = '<b>Skin successfully saved.</b><br>';
  529. $this->load->view('admin2/error_page', $this->data);
  530. }
  531. else
  532. {
  533. //Else display fail message.
  534. $this->data['error_msg'] = '<b>Saving skin failed</b><br>';
  535. $this->load->view('admin2/error_page', $this->data);
  536. }
  537. }
  538. }
  539.  
  540. /***********************************************************************************
  541. * Manage Portfolio Methods
  542. ***********************************************************************************/
  543. function document()
  544. {
  545. if($this->compare_user_pass())
  546. {
  547. $this->data['body_title'] = 'Document';
  548. $this->data['error'] = ' ';
  549. $this->load->view('admin2/document_form', $this->data);
  550. }
  551. else
  552. {
  553. //Display error message
  554. $this->error_access();
  555. }
  556. }
  557.  
  558. function document_proc()
  559. {
  560. //Capture data and validate
  561. $this->form_validation->set_rules('document', 'Document', 'required');
  562.  
  563. if ($this->form_validation->run() == FALSE)
  564. {
  565. //If validation has error display form again with error messages.
  566. $this->document();
  567. }
  568. else
  569. {
  570. //If form validation has no error catch $footer_text
  571. $texts = $this->input->post('document', TRUE);
  572.  
  573. if($this->folio_model->save_document_url($texts))
  574. {
  575. //If everything is okay, display success message
  576. $this->data['error_msg'] = 'Success saving document URL.';
  577. $this->load->view('admin2/error_page', $this->data);
  578. }
  579. else
  580. {
  581. //Else display fail message.
  582. $this->data['error_msg'] = 'Saving failed';
  583. $this->load->view('admin2/error_page', $this->data);
  584. }
  585. }
  586. }
  587.  
  588. function changelog()
  589. {
  590. if($this->compare_user_pass())
  591. {
  592. $this->data['body_title'] = 'Change Log';
  593. $this->data['error'] = ' ';
  594. $this->load->view('admin2/document_form', $this->data);
  595. }
  596. else
  597. {
  598. //Display error message
  599. $this->error_access();
  600. }
  601. }
  602.  
  603. function changelog_proc()
  604. {
  605.  
  606. }
  607.  
  608. function download()
  609. {
  610. $this->data['body_title'] = 'Download';
  611. $this->data['error'] = ' ';
  612. $this->load->view('admin2/document_form', $this->data);
  613. }
  614.  
  615. function download_proc()
  616. {
  617.  
  618. }
  619.  
  620. function add_record()
  621. {
  622. if($this->compare_user_pass())
  623. {
  624. $this->session->set_userdata('action', 'add');
  625. $this->data['body_title'] = 'Add Record';
  626. $this->data['error'] = ' ';
  627. $this->load->view('admin2/add_record_form', $this->data);
  628. }
  629. else
  630. {
  631. //Display error message
  632. $this->error_access();
  633. }
  634. }
  635.  
  636. function edit_record()
  637. {
  638. //store to session
  639. //fetch id segment
  640. $rec_id = $this->uri->segment(4, 0);
  641. $this->session->set_userdata('rec_id', $rec_id);
  642. $this->session->set_userdata('action', 'edit');
  643.  
  644. $this->data['body_title'] = 'Edit Record';
  645.  
  646. //fech record by id segment
  647. $this->data['records'] = $this->folio_model->get_record_by_id($rec_id);
  648.  
  649. if($this->compare_user_pass())
  650. {
  651. //Display Edit form
  652. //$this->load->view('admin2/edit_record_form', $this->data);
  653. $this->load->view('admin2/add_record_form', $this->data);
  654. }
  655. else
  656. {
  657. //Display error message
  658. $this->error_access();
  659. }
  660. }
  661.  
  662. function add_record_proc()
  663. {
  664. //Capture session data
  665. $rec_id = $this->session->userdata('rec_id');
  666. $action = $this->session->userdata('action');
  667.  
  668. //Capture data and validate
  669. if($action == 'add') {
  670. $this->form_validation->set_rules('title', 'Title', 'trim|required|is_unique[portfolio.title]');
  671. }
  672.  
  673. if($action == 'edit') {
  674. $this->form_validation->set_rules('title', 'Title', 'trim|required');
  675. }
  676.  
  677. $this->form_validation->set_rules('url', 'Site URL', 'trim|required');
  678. //$this->form_validation->set_rules('description', 'Description', 'required');
  679. $this->form_validation->set_rules('photo_url', 'Photo', 'trim');
  680. $this->form_validation->set_rules('video_url', 'Video', 'trim');
  681. $this->form_validation->set_rules('technology', 'Technology', 'trim');
  682. $this->form_validation->set_rules('buy', 'Buy', 'trim');
  683. $this->form_validation->set_rules('document', 'Document', 'trim');
  684. $this->form_validation->set_rules('demo', 'Demo', 'trim');
  685. $this->form_validation->set_rules('download', 'Download', 'trim');
  686.  
  687. if(isset($_POST['submit'])) {
  688. //if($userfile != '' || $userfile != 0) {
  689. //Copy filename to photo_url column into DB
  690. $this->data3['photo_url'] = $this->input->post('userfile', TRUE);
  691.  
  692. //Upload file config
  693. $config['upload_path'] = './images/';
  694. $config['allowed_types'] = 'gif|jpg|png';
  695. $config['max_size'] = '2048';
  696. $config['max_width'] = '1000';
  697. $config['max_height'] = '700';
  698. $this->load->library('upload', $config);
  699.  
  700. //Process upload file
  701. if (!$this->upload->do_upload())
  702. {
  703. //If file upload fail just do nothing.
  704. //$error = array('error' => $this->upload->display_errors());
  705. //echo $error;
  706. //$this->data['error_msg'] = $this->upload->display_errors();
  707. //$this->load->view('admin2/error_upload', $this->data);
  708. }
  709. else
  710. {
  711. //If file upload is successful capture data
  712. $data_file = array('upload_data' => $this->upload->data());
  713. $this->data3['photo_url'] = $data_file['upload_data']['file_name'];
  714. }
  715. }
  716.  
  717. if ($this->form_validation->run() == FALSE)
  718. {
  719. //If validation has error display form again with error messages.
  720. if($action == 'add') {
  721. $this->add_record();
  722. //redirect('admin/admin2/add_record/', 'refresh');
  723. }
  724.  
  725. if($action == 'edit') {
  726. //fech record by id segment
  727. $this->data['records'] = $this->folio_model->get_record_by_id($rec_id);
  728. $this->load->view('admin2/add_record_form', $this->data);
  729. }
  730. }
  731. else
  732. {
  733. //If form validation has no error catch data
  734. //date('Y-m-d H:i:s');
  735. $this->data3['title'] = $this->input->post('title', TRUE);
  736. $this->data3['title_url'] = $this->input->post('url', TRUE);
  737. $this->data3['description'] = $this->input->post('description', TRUE);
  738. $this->data3['version'] = $this->input->post('version', TRUE);
  739. $this->data3['stage'] = $this->input->post('stage', TRUE);
  740.  
  741. $this->data3['date_started_yr'] = $this->input->post('date_started_yr', TRUE);
  742. $this->data3['date_started_mo'] = $this->input->post('date_started_mo', TRUE);
  743. $this->data3['date_started_dy'] = $this->input->post('date_started_dy', TRUE);
  744.  
  745. $this->data3['last_update_yr'] = $this->input->post('last_update_yr', TRUE);
  746. $this->data3['last_update_mo'] = $this->input->post('last_update_mo', TRUE);
  747. $this->data3['last_update_dy'] = $this->input->post('last_update_dy', TRUE);
  748.  
  749. $this->data3['date_finished_yr'] = $this->input->post('date_finished_yr', TRUE);
  750. $this->data3['date_finished_mo'] = $this->input->post('date_finished_mo', TRUE);
  751. $this->data3['date_finished_dy'] = $this->input->post('date_finished_dy', TRUE);
  752.  
  753. $this->data3['video_url'] = $this->input->post('video_url', TRUE);
  754. $this->data3['technology'] = $this->input->post('technology', TRUE);
  755.  
  756. $this->data3['buy'] = $this->input->post('buy', TRUE);
  757. $this->data3['document'] = $this->input->post('document', TRUE);
  758. $this->data3['demo'] = $this->input->post('demo', TRUE);
  759. $this->data3['download'] = $this->input->post('download', TRUE);
  760. $this->data3['changelog'] = $this->input->post('changelog', TRUE);
  761.  
  762. if($action == 'add') {
  763. if($this->folio_model->save_record($this->data3))
  764. {
  765. //If everything is okay, display success message
  766. $this->data['error_msg'] = '<b>Portfolio successfully saved.</b><br>';
  767. $this->load->view('admin2/error_page', $this->data);
  768. }
  769. else
  770. {
  771. //Else display fail message.
  772. $this->data['error_msg'] = '<b>Saving Portfolio failed</b><br>';
  773. $this->load->view('admin2/error_page', $this->data);
  774. }
  775. }
  776.  
  777. if($action == 'edit') {
  778. $this->data3['id'] = $rec_id;
  779.  
  780. //check photo_upload if empty insert current filename;
  781. if($this->data3['photo_url'] == '' || $this->data3['photo_url'] == '0') {
  782. $this->data3['photo_url'] = $this->folio_model->get_image_name($rec_id);
  783. }
  784.  
  785. if($this->folio_model->update_record($this->data3))
  786. {
  787. //If everything is okay, display success message
  788. $this->data['error_msg'] = '<b>Portfolio successfully updated.</b><br>';
  789. $this->load->view('admin2/error_page', $this->data);
  790. }
  791. else
  792. {
  793. //Else display fail message.
  794. $this->data['error_msg'] = '<b>Updating Portfolio failed</b><br>';
  795. $this->load->view('admin2/error_page', $this->data);
  796. }
  797. }
  798. }
  799. }
  800.  
  801. function ed_record()
  802. {
  803. if($this->compare_user_pass())
  804. {
  805. $this->data['records'] = $this->folio_model->get_records2();
  806. $this->data['body_title'] = 'Edit and Delete Record';
  807. $this->data['error'] = ' ';
  808. $this->load->view('admin2/ed_record_page', $this->data);
  809. }
  810. else
  811. {
  812. //Display error message
  813. $this->error_access();
  814. }
  815. }
  816.  
  817. function delete_record()
  818. {
  819. //fetch id segment
  820. $rec_id = $this->uri->segment(4, 0);
  821.  
  822. //get image name
  823. $image_name = $this->folio_model->get_image_name($rec_id);
  824.  
  825. //delete image filename
  826. if($image_name != '') {
  827. $this->delete_image_name($image_name);
  828. }
  829.  
  830. //Delete record
  831. if($this->folio_model->del_rec($rec_id))
  832. {
  833. //If everything is okay.
  834. //$this->data['error_msg'] = '<b>The record successfully deleted.</b>';
  835. //$this->load->view('admin2/error_page', $this->data);
  836. redirect('/admin/admin2/ed_record/', 'refresh');
  837. }
  838. else
  839. {
  840. //If somehting goes wrong.
  841. $this->data['error_msg'] = '<b>Record Deletion failed.</b>';
  842. $this->load->view('admin2/error_page', $this->data);
  843. }
  844.  
  845. }
  846.  
  847. function delete_image_name($image_name){
  848. $path_of_image = './images/' . $image_name;
  849.  
  850. if (file_exists($path_of_image)) {
  851. unlink($path_of_image);
  852. }
  853. else
  854. {
  855. return false;
  856. }
  857. }
  858.  
  859. /***********************************************************************************
  860. * Admin Login methods
  861. ***********************************************************************************/
  862. function change_user()
  863. {
  864. if($this->compare_user_pass())
  865. {
  866. $this->data['body_title'] = 'Change Username';
  867. $this->data['error'] = ' ';
  868. $this->load->view('admin2/change_user_form', $this->data);
  869. }
  870. else
  871. {
  872. //Display error message
  873. $this->error_access();
  874. }
  875. }
  876.  
  877. function change_user_proc()
  878. {
  879. //Capture data and validate
  880. $this->form_validation->set_rules('username', 'Username', 'required');
  881. $this->form_validation->set_rules('new_username', 'New username', 'required');
  882.  
  883. if ($this->form_validation->run() == FALSE)
  884. {
  885. //If validation has error display form again with error messages.
  886. $this->change_user();
  887. }
  888. else
  889. {
  890. //If form validation has no error catch $username and $new_username data
  891. $user = $this->input->post('username', TRUE);
  892. $new_user = $this->input->post('new_username', TRUE);
  893.  
  894. if($this->folio_model->change_username($user, $new_user))
  895. {
  896. //If everything is okay, display success message
  897. $this->data['error_msg'] = '<b>Username successfully changed</b><br> New username: ' . $new_user;
  898. $this->load->view('admin2/error_page', $this->data);
  899. }
  900. else
  901. {
  902. //Else display fail message.
  903. $this->data['error_msg'] = '<b>Changing username failed</b><br><b>Or username doesn\'t exist.</b>';
  904. $this->load->view('admin2/error_page', $this->data);
  905. }
  906.  
  907. }
  908. }
  909.  
  910. function change_pass()
  911. {
  912. if($this->compare_user_pass())
  913. {
  914. $this->data['body_title'] = 'Change Password';
  915. $this->data['error'] = ' ';
  916. $this->load->view('admin2/change_pass_form', $this->data);
  917. }
  918. else
  919. {
  920. //Display error message
  921. $this->error_access();
  922. }
  923. }
  924.  
  925. function change_pass_proc()
  926. {
  927. //Capture data and validate
  928. $this->form_validation->set_rules('username', 'Username', 'required');
  929. $this->form_validation->set_rules('new_password', 'New password', 'required');
  930.  
  931. if ($this->form_validation->run() == FALSE)
  932. {
  933. //If validation has error display form again with error messages.
  934. $this->change_pass();
  935. }
  936. else
  937. {
  938. //If form validation has no error catch $username and $new_username data
  939. $user = $this->input->post('username', TRUE);
  940. $new_pass = $this->input->post('new_password', TRUE);
  941. $salted_pass = $this->folio_model->encrypt_pass($new_pass);
  942.  
  943. if($this->folio_model->change_password($user, $salted_pass))
  944. {
  945. $this->data['error_msg'] = '<b>Password successfully changed</b><br>';
  946. $this->load->view('admin2/error_page', $this->data);
  947. }
  948. else
  949. {
  950. $this->data['error_msg'] = '<b>Changing password failed</b><br><b>Or username doesn\'t exist.</b>';
  951. $this->load->view('admin2/error_page', $this->data);
  952. }
  953. }
  954. }
  955.  
  956. function change_email()
  957. {
  958. if($this->compare_user_pass())
  959. {
  960. $this->data['body_title'] = 'Change Email';
  961. $this->data['error'] = ' ';
  962. $this->load->view('admin2/change_email_form', $this->data);
  963. }
  964. else
  965. {
  966. //Display error message
  967. $this->error_access();
  968. }
  969. }
  970.  
  971. function change_email_proc()
  972. {
  973. //Capture data and validate
  974. $this->form_validation->set_rules('username', 'Username', 'required');
  975. $this->form_validation->set_rules('new_email', 'New Email', 'required');
  976.  
  977. if ($this->form_validation->run() == FALSE)
  978. {
  979. //If validation has error display form again with error messages.
  980. $this->change_email();
  981. }
  982. else
  983. {
  984. //If form validation has no error catch $username and $new_username data
  985. $user = $this->input->post('username', TRUE);
  986. $new_email = $this->input->post('new_email', TRUE);
  987.  
  988. if($this->folio_model->change_email($user, $new_email))
  989. {
  990. //If everything is okay, display success message
  991. $this->data['error_msg'] = '<b>Email successfully changed</b><br>';
  992. $this->load->view('admin2/error_page', $this->data);
  993. }
  994. else
  995. {
  996. //Else display fail message.
  997. $this->data['error_msg'] = '<b>Changing Email failed</b><br><b>Or username doesn\'t exist.</b>';
  998. $this->load->view('admin2/error_page', $this->data);
  999. }
  1000. }
  1001. }
  1002.  
  1003. //This method will set the username and password to default.
  1004. function set_default_up()
  1005. {
  1006. if($this->compare_user_pass())
  1007. {
  1008. if($this->folio_model->set_default_user_pass())
  1009. {
  1010. //If everything is okay, display success message
  1011. $this->data['error_msg'] = 'Username and Password is successfully changed to default.<br>Username: admin <br>Password: pass <br>';
  1012. $this->load->view('admin2/error_page', $this->data);
  1013. }
  1014. else
  1015. {
  1016. //If failed display fail message
  1017. $this->data['error_msg'] = 'Setting username and password to default failed. <br>Or the username and password is already set to default. <br>';
  1018. $this->load->view('admin2/error_page', $this->data);
  1019. }
  1020. }
  1021. else
  1022. {
  1023. //Display error message
  1024. $this->error_access();
  1025. }
  1026. }
  1027.  
  1028.  
  1029. /********************************************************************
  1030. * Utility Methods. *
  1031. ********************************************************************/
  1032. function getprogress() {
  1033. if (isset($_GET['uid'])) {
  1034.  
  1035. // Fetch the upload progress data
  1036. $status = uploadprogress_get_info($_GET['uid']);
  1037.  
  1038. if ($status) {
  1039.  
  1040. // Calculate the current percentage
  1041. echo round($status['bytes_uploaded']/$status['bytes_total']*100);
  1042.  
  1043. }
  1044. else {
  1045.  
  1046. // If there is no data, assume it's done
  1047. echo 100;
  1048.  
  1049. }
  1050. }
  1051. }
  1052.  
  1053. function logout() {
  1054. if($this->compare_user_pass())
  1055. {
  1056. $this->session->sess_destroy();
  1057. $this->index();
  1058. }
  1059. else
  1060. {
  1061. //Display error message
  1062. $this->error_access();
  1063. }
  1064. }
  1065.  
  1066. function error_access() {
  1067. $this->data['error_msg'] = 'Sorry no direct access.';
  1068. $this->load->view('admin2/error_access', $this->data);
  1069. }
  1070.  
  1071. function compare_user_pass() {
  1072. //retrieve username and password from session
  1073. $user_ses = $this->session->userdata('username');
  1074. $pass_ses = $this->session->userdata('password');
  1075.  
  1076. //add salt to $pass_ses
  1077. $pass_ses = $this->folio_model->encrypt_pass($pass_ses);
  1078.  
  1079. //retrieve username and password from database
  1080. $user_pass = $this->folio_model->get_user_pass();
  1081. $user_db = $user_pass[0]['username'];
  1082. $pass_db = $user_pass[0]['password'];
  1083.  
  1084. //compare username and password from session versus database
  1085. if($user_ses == $user_db && $pass_ses == $pass_db)
  1086. {
  1087. return TRUE;
  1088. }
  1089. else
  1090. {
  1091. return FALSE;
  1092. }
  1093. }
  1094.  
  1095. /********************************************************************
  1096. * Methods for testings. *
  1097. ********************************************************************/
  1098. function show_user_pass()
  1099. {
  1100. $user_pass = $this->folio_model->get_user_pass();
  1101.  
  1102. //echo 'user: ' .$user_pass[0]['username']. '<br>';
  1103. //echo 'pass: ' .$user_pass[0]['password'];
  1104. }
  1105.  
  1106. //Testing of ultramegatech.com uploadprogress
  1107. function uploadprogress()
  1108. {
  1109. /*
  1110. $this->data['body_title'] = 'File Upload Test';
  1111. $this->data['error'] = $this->session->userdata('error_msg');
  1112. $this->load->view('admin2/change_banner_form2', $this->data);
  1113. */
  1114. }
  1115.  
  1116. function uploadprogress_proc()
  1117. {
  1118. $config['upload_path'] = './images/';
  1119. $config['allowed_types'] = 'gif|jpg|png';
  1120. $config['max_size'] = '2048';
  1121. $config['max_width'] = '1200';
  1122. $config['max_height'] = '1000';
  1123.  
  1124. $this->load->library('upload', $config);
  1125.  
  1126. if (!$this->upload->do_upload())
  1127. {
  1128. //If file upload fail display form again with error message.
  1129. $this->data['error_msg'] = $this->upload->display_errors();
  1130. $this->load->view('admin2/error_upload', $this->data);
  1131. }
  1132. else
  1133. {
  1134. //If file upload is successful dispaly success message
  1135. $this->data['error_msg'] = 'File Upload successful.';
  1136. $this->load->view('admin2/error_upload', $this->data);
  1137. }
  1138. }
  1139.  
  1140. function saraan_test($userfile) {
  1141. $data = array(
  1142. 'username' => 'XXXXX',
  1143. 'location' => 'XXXXX',
  1144. 'filename' => $userfile,
  1145. );
  1146. $this->folio_model->save_saraan($data);
  1147. }
  1148.  
  1149. function show_cpanel()
  1150. {
  1151. $this->data['cpanel_header'] = $this->load->view('admin/cpanel_header', $this->data, TRUE);
  1152. $this->load->view('admin/admincpanel', $this->data);
  1153. }
  1154.  
  1155.  
  1156. }
  1157.  
  1158. //End of Admin class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement