-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from Gnouc/master
Add gift controller
- Loading branch information
Showing
7 changed files
with
532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
if (!defined('BASEPATH')) | ||
exit('No direct script access allowed'); | ||
session_start(); | ||
|
||
class Gift extends CI_Controller { | ||
|
||
function __construct() { | ||
parent::__construct(); | ||
$this->load->library('session'); | ||
$this->load->helper('url'); | ||
$this->load->library('upload'); | ||
$this->load->library('pagination'); | ||
$this->load->library('parser'); | ||
$this->load->helper('cookie'); | ||
$this->load->helper(array('form', 'url')); | ||
$this->load->library('ImageClass'); | ||
$this->load->helper('text'); | ||
@session_start(); | ||
} | ||
|
||
public function index() { | ||
if ($this->session->userdata('adminid') == null) { | ||
redirect('admincp/login'); | ||
} else { | ||
$this->load->model('gift_model'); | ||
$data['listgift'] = $this->gift_model->get_all(); | ||
$this->load->view('admin/dashboard', $data); | ||
} | ||
} | ||
|
||
public function create() { | ||
if ($this->session->userdata('adminid') == null) { | ||
redirect('admincp/login'); | ||
} else { | ||
$this->load->model('gift_model'); | ||
if (isset($_REQUEST['submit_gift'])) { | ||
|
||
$gift_title = $this->input->post('title', true); | ||
$gift_link = $this->input->post('link', true); | ||
$gift_content = $this->input->post('content', true); | ||
$gift_video = $this->input->post('video', true); | ||
|
||
|
||
$object = array( | ||
'gift_title' => $gift_title, | ||
'gift_link' => $gift_link, | ||
'gift_video' => $gift_video, | ||
'gift_content' => $gift_content, | ||
); | ||
$this->gift_model->add_gift($object); | ||
redirect(site_url('admincp/gift/')); | ||
} | ||
$this->load->view('admin/dashboard'); | ||
} | ||
} | ||
|
||
public function delete($id) { | ||
if ($this->session->userdata('adminid') == null) { | ||
redirect('admincp/login'); | ||
} else { | ||
if ($this->input->is_ajax_request()) { | ||
$this->load->model('gift_model'); | ||
$delete = $this->gift_model->delete($id); | ||
} | ||
} | ||
} | ||
|
||
public function edit($id = null) { | ||
if ($this->session->userdata('adminid') == null) { | ||
redirect('admincp/login'); | ||
} else { | ||
$this->load->model('gift_model'); | ||
if (isset($_REQUEST['update_gift'])) { | ||
$gift_title = $this->input->post('title', true); | ||
$gift_link = $this->input->post('link', true); | ||
$gift_content = $this->input->post('content', true); | ||
$gift_video = $this->input->post('video', true); | ||
|
||
|
||
$object = array( | ||
'gift_title' => $gift_title, | ||
'gift_link' => $gift_link, | ||
'gift_video' => $gift_video, | ||
'gift_content' => $gift_content, | ||
); | ||
$this->gift_model->update_gift($id,$object); | ||
redirect(site_url('admincp/gift/')); | ||
} | ||
$data['gift'] = $this->gift_model->get_gift_by_id($id); | ||
$this->load->view('admin/dashboard', $data); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
if (!defined('BASEPATH')) | ||
exit('No direct script access allowed'); | ||
|
||
class Gift_model extends CI_Model { | ||
|
||
function __construct() { | ||
// Call the Model constructor | ||
parent::__construct(); | ||
$this->load->database(); | ||
} | ||
|
||
function get_all() { | ||
$query = $this->db->get('tbl_gift'); | ||
if ($query <> null) { | ||
return $query->result(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
function get_gift_by_id($id) { | ||
$this->db->where('id', $id); | ||
$query = $this->db->get('tbl_gift'); | ||
if ($query <> null) { | ||
return $query->result(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
function delete($id=null) { | ||
$delete = $this->db->delete('tbl_gift', array('id' => $id)); | ||
return $delete; | ||
} | ||
|
||
function add_gift($object) { | ||
$this->db->insert('tbl_gift', $object); | ||
return $this->db->insert_id(); | ||
} | ||
|
||
function update_gift($id, $object) { | ||
$this->db->where('id', $id); | ||
$this->db->update('tbl_gift', $object); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<script src="http://tinymce.cachefly.net/4.0/tinymce.min.js"></script> | ||
<script type="text/javascript"> | ||
tinymce.init({ | ||
selector: "textarea", | ||
plugins: [ | ||
"advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker", | ||
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking", | ||
"table contextmenu directionality emoticons template textcolor paste fullpage textcolor" | ||
], | ||
|
||
toolbar1: "newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect", | ||
toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor", | ||
toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft", | ||
|
||
menubar: false, | ||
toolbar_items_size: 'small', | ||
|
||
style_formats: [ | ||
{title: 'Bold text', inline: 'b'}, | ||
{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}}, | ||
{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}}, | ||
{title: 'Example 1', inline: 'span', classes: 'example1'}, | ||
{title: 'Example 2', inline: 'span', classes: 'example2'}, | ||
{title: 'Table styles'}, | ||
{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'} | ||
], | ||
|
||
templates: [ | ||
{title: 'Test template 1', content: 'Test 1'}, | ||
{title: 'Test template 2', content: 'Test 2'} | ||
] | ||
});</script> | ||
|
||
|
||
<div class="row-fluid"> | ||
<div class="span12"> | ||
<div class="box dark"> | ||
<header> | ||
<div class="icons"><i class="icon-edit"></i></div> | ||
<h5>Tạo mới quà tặng</h5> | ||
<div class="toolbar"> | ||
<ul class="nav"> | ||
<li class="dropdown"> | ||
<a data-toggle="dropdown" class="dropdown-toggle" href="#"> | ||
<i class="icon-th-large"></i> | ||
</a> | ||
<ul class="dropdown-menu"> | ||
<li><a href="">q</a></li> | ||
<li><a href="">a</a></li> | ||
<li><a href="">b</a></li> | ||
</ul> | ||
</li> | ||
<li> | ||
<a class="accordion-toggle minimize-box" data-toggle="collapse" href="#div-1"> | ||
<i class="icon-chevron-up"></i> | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
<!-- /.toolbar --> | ||
</header> | ||
<div id="div-1" class="accordion-body collapse in body"> | ||
<?php echo form_open_multipart('admincp/gift/create',array('class'=>'form-horizontal','id'=>'gift-create')); ?> | ||
|
||
<div class="control-group"> | ||
<label for="text1" class="control-label">Tiêu đề<span class="require">*</span></label> | ||
|
||
<div class="controls with-tooltip"> | ||
<input type="text" id="title" class="span6 input-tooltip" data-original-title="Please use gift title" data-placement="bottom" name="title"/> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label for="text1" class="control-label">Link</label> | ||
|
||
<div class="controls with-tooltip"> | ||
<input type="text" id="link" class="span6 input-tooltip" name="link"/> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label for="text1" class="control-label">Video</label> | ||
|
||
<div class="controls with-tooltip"> | ||
<input type="text" id="video" class="span6 input-tooltip" name="video"/> | ||
</div> | ||
</div> | ||
|
||
<div class="control-group"> | ||
<label for="text1" class="control-label">Nội dung</label> | ||
|
||
<div class="controls with-tooltip"> | ||
<textarea id="description" name="content" class="span6"></textarea> | ||
</div> | ||
</div> | ||
|
||
<div class="form-actions"> | ||
<input type="reset" value="Reset" id="back" class="navigation_button btn"> | ||
<input type="submit" value="Tạo mới" id="next" name="submit_gift" class="navigation_button btn btn-primary"> | ||
<!-- onclick="create()" --> | ||
</div> | ||
<?php echo form_close(); ?> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
function create (argument) { | ||
var name = $("#title").val(); | ||
|
||
editor.post(); | ||
var description = editor.t.value; | ||
if(name != '' && description != '') { | ||
$("#gift-create").submit(); | ||
}else{ | ||
alert("Hãy điền tiêu đề cho gift!"); | ||
} | ||
} | ||
</script> | ||
<script> | ||
new TINY.editor.edit('editor',{ | ||
id: 'description', | ||
width: '584', | ||
height: 175, | ||
cssclass: 'tinyeditor', | ||
controlclass: 'tinyeditor-control', | ||
rowclass: 'tinyeditor-header', | ||
dividerclass: 'tinyeditor-divider', | ||
controls: ['bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|', | ||
'orderedlist', 'unorderedlist', '|', 'outdent', 'indent', '|', 'leftalign', | ||
'centeralign', 'rightalign', 'blockjustify', '|', 'unformat', '|', 'undo', 'redo', 'n', | ||
'font', 'size', 'style', '|', 'image', 'hr', 'link', 'unlink', '|', 'print'], | ||
footer: true, | ||
fonts: ['Verdana','Arial','Georgia','Trebuchet MS'], | ||
xhtml: true, | ||
cssfile: 'custom.css', | ||
bodyid: 'editor', | ||
footerclass: 'tinyeditor-footer', | ||
toggle: {text: 'source', activetext: 'wysiwyg', cssclass: 'toggle'}, | ||
resize: {cssclass: 'resize'} | ||
}); | ||
</script> | ||
<script type="text/javascript"> | ||
|
||
</script> |
Oops, something went wrong.