I have the following table in the system:
WhenItypetheStatusandclickonupdateitcreatesanotherrecordinthedatabase.
Followtheregistrationinthebd. Iwouldlikeittojustrecordthestatusintherecordwiththeidinquestion!
Code:
<divclass="tabs-vertical-env">
<ul class="nav tabs-vertical">
<?php
$classes = $this->db->get('class')->result_array();
foreach ($classes as $row):
?>
<li class="<?php if ($row['class_id'] == $class_id) echo 'active';?>">
<a href="<?php echo site_url('admin/academic_syllabus/' . $row['class_id']);?>">
<i class="entypo-dot"></i>
<?php echo get_phrase('class');?> <?php echo $row['name'];?>
</a>
</li>
<?php endforeach;?>
</ul>
<div class="tab-content">
<?php
echo form_open(site_url('admin/upload_academic_syllabus/'.$exam_id.'/'.$class_id.'/'.$section_id.'/'.$subject_id));
?>
<div class="tab-pane active">
<table class="table table-bordered responsive">
<thead>
<tr>
<th>#</th>
<th><?php echo get_phrase('title');?></th>
<th><?php echo get_phrase('description');?></th>
<th><?php echo get_phrase('subject');?></th>
<th><?php echo get_phrase('uploader');?></th>
<th><?php echo get_phrase('date');?></th>
<th><?php echo get_phrase('file');?></th>
<th></th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$count = 1;
$syllabus = $this->db->get_where('academic_syllabus' , array(
'class_id' => $class_id , 'year' => $running_year
))->result_array();
foreach ($syllabus as $row):
?>
<tr>
<td><?php echo $count++;?></td>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['description'];?></td>
<td>
<?php
echo $this->db->get_where('subject' , array(
'subject_id' => $row['subject_id']
))->row()->name;
?>
</td>
<td>
<?php
echo $this->db->get_where($row['uploader_type'] , array(
$row['uploader_type'].'_id' => $row['uploader_id']
))->row()->name;
?>
</td>
<td><?php echo date("d/m/Y" , $row['timestamp']);?></td>
<td>
<?php echo substr($row['file_name'], 0, 20);?><?php if(strlen($row['file_name']) > 20) echo '...';?>
</td>
<td align="center">
<a class="btn btn-default btn-xs"
href="<?php echo site_url('admin/download_academic_syllabus/' . $row['academic_syllabus_code']);?>">
<i class="entypo-download"></i>
</a>
<a href="#" class="btn btn-danger btn-xs"
onclick="confirm_modal('<?php echo site_url('admin/delete_academic_syllabus/' . $row['academic_syllabus_code']);?>');">
<i class="entypo-trash"></i>
</a>
</td>
<td>
<input type="text" class="form-control" name="status">
</td>
<td> <center>
<button type="submit" class="btn btn-success" id="submit_button">
<i class="entypo-check"></i> Atualizar status
</button>
</center>
</tr>
<?php endforeach;?>
</tbody>
</table>
<?php echo form_close();?>
</div>
</div>
</div>
</div>
Controller code:
// ACADEMIC SYLLABUS
function academic_syllabus($class_id = '')
{
if ($this->session->userdata('admin_login') != 1)
redirect(site_url('login'), 'refresh');
// detect the first class
if ($class_id == '')
$class_id = $this->db->get('class')->first_row()->class_id;
$page_data['page_name'] = 'academic_syllabus';
$page_data['page_title'] = get_phrase('academic_syllabus');
$page_data['class_id'] = $class_id;
$this->load->view('backend/index', $page_data);
}
function upload_academic_syllabus()
{
$data['academic_syllabus_code'] = substr(md5(rand(0, 1000000)), 0, 7);
if ($this->input->post('description') != null) {
$data['description'] = $this->input->post('description');
}
$data['title'] = $this->input->post('title');
$data['class_id'] = $this->input->post('class_id');
$data['subject_id'] = $this->input->post('subject_id');
$data['uploader_type'] = $this->session->userdata('login_type');
$data['uploader_id'] = $this->session->userdata('login_user_id');
$data['year'] = $this->db->get_where('settings',array('type'=>'running_year'))->row()->description;
$data['timestamp'] = strtotime(date("Y-m-d H:i:s"));
//uploading file using codeigniter upload library
$files = $_FILES['file_name'];
$this->load->library('upload');
$config['upload_path'] = 'uploads/syllabus/';
$config['allowed_types'] = '*';
$_FILES['file_name']['name'] = $files['name'];
$_FILES['file_name']['type'] = $files['type'];
$_FILES['file_name']['tmp_name'] = $files['tmp_name'];
$_FILES['file_name']['size'] = $files['size'];
$this->upload->initialize($config);
$this->upload->do_upload('file_name');
$data['file_name'] = $_FILES['file_name']['name'];
$this->db->insert('academic_syllabus', $data);
$this->session->set_flashdata('flash_message' , get_phrase('syllabus_uploaded'));
redirect(site_url('admin/academic_syllabus/' . $data['class_id']), 'refresh');
}