Contoh Coding Test Logic - Oop - MVC CI PHP
Contoh Coding Test Logic - Oop - MVC CI PHP
$repeated = 0;
for($y=0;$y<$strlenght;$y++){
if($x != $y && $string[$x] == $string[$y]) {
$repeated ++;
//break;
}
}
if($repeated==0){
$charsnonrepeated[] = $string[$x];
if($x===$lastcount){
$stringnonrepeated .= $string[$x];
echo "<br />X = ". $x;
echo "<br />lastcount = ". $lastcount;
echo "<br />stringnonrepeated = ". $stringnonrepeated;
echo "<hr/>";
}
else{
$stringnonrepeated .= $string[$x].",";
echo "<br />X = ". $x;
echo "<br />lastcount = ". $lastcount;
echo "<br />stringnonrepeated = ". $stringnonrepeated;
echo "<hr/>";
}
}
else{
$charsrepeated[] = $string[$x];
if($x===$lastcount){
$stringrepeated .= $string[$x];
echo "<br />lastcount = ". $lastcount;
echo "<br />lastcount = ". $lastcount;
echo "<br />stringnonrepeated = ". $stringnonrepeated;
echo "<hr/>";
}
else{
$stringrepeated .= $string[$x].",";
echo "<br />X = ". $x;
echo "<br />lastcount = ". $lastcount;
echo "<br />stringrepeated = ". $stringrepeated;
echo "<hr/>";
}
}
}
$arraynonrepeated = sizeof($charsnonrepeated);
$arrayrepeated = sizeof($charsrepeated);
if($arraynonrepeated==1){
echo "First non repeated character is : ".$charsnonrepeated[0]."<br/>";
}
elseif($arraynonrepeated>1){
for($a=0;$a<$arraynonrepeated;$a++){
echo "non repeated character is : ".$charsnonrepeated[$a]."<br/>";
}
}
if($arrayrepeated==1){
echo "First repeated character is : ".$charsnonrepeated[0]."<br/>";
}
elseif($arrayrepeated>1){
for($b=0;$b<$arrayrepeated;$b++){
echo "repeated character is : ".$charsrepeated[$b]."<br/>";
}
}
echo "<br/>First non repeated character is : ".$charsnonrepeated[0];
echo "<br/>First repeated character is : ".$charsrepeated[0];
?>
</body>
</html>
OUTPUT RESULT NYA
Soal Logika Looping 1-100 angka yang hanya bisa dibagi 3 diganti menjadi
fizz, yang hanya bisa dibagi 5 diganti menjadi Buzz, yang bisa dibagi 3 dan 5
diganti menjadi FizzBuzz
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
Soal Logika Print berurut seperti tangga dari terkecil paling atas sampai
terbesar paling bawah
*
**
***
****
*****
******
*******
********
*********
**********
Soal Logika Menukar nilai dari 2 variabel tanpa menambahkan/menyisipkan
variable baru/tambahan/temporary
a=5
b=6
perubahan a =6
perubahan b =5
Soal Logika Membalik urutan karakter dalam sebuah string
String awal = selamat pagi
String baru = igap tamales
Soal Logika Mencari Karakter Unik/Tidak Berulang yang paling pertama
dalam sebua string
String = aabdcsbskadsjhkqString Length= 16
X=0
lastcount = 15
stringrepeated = a,
X=1
lastcount = 15
stringrepeated = a,a,
X=2
lastcount = 15
stringrepeated = a,a,b,
X=3
lastcount = 15
stringrepeated = a,a,b,d,
X=4
lastcount = 15
stringnonrepeated = c,
X=5
lastcount = 15
stringrepeated = a,a,b,d,s,
X=6
lastcount = 15
stringrepeated = a,a,b,d,s,b,
X=7
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,
X=8
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,k,
X=9
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,k,a,
X = 10
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,k,a,d,
X = 11
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,k,a,d,s,
X = 12
lastcount = 15
stringnonrepeated = c,j,
X = 13
lastcount = 15
stringnonrepeated = c,j,h,
X = 14
lastcount = 15
stringrepeated = a,a,b,d,s,b,s,k,a,d,s,k,
X = 15
lastcount = 15
stringnonrepeated = c,j,h,q
non repeated character is : c
non repeated character is : j
non repeated character is : h
non repeated character is : q
repeated character is : a
repeated character is : a
repeated character is : b
repeated character is : d
repeated character is : s
repeated character is : b
repeated character is : s
repeated character is : k
repeated character is : a
repeated character is : d
repeated character is : s
repeated character is : k
First non repeated character is : c
First repeated character is : a
CONTOH CODING OOP PHP CRUD
File : koneksi_database.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
}
}
// buat array data anggota dari method tampilAnggota()
$arrayanggota = $db->tampilAnggota();
echo"</table> <br> <a href='?aksi=tambah'>TAMBAH</a>";
echo "<table border='1' cellpadding='5'>
<tr><th>No</th>
<th>Nama Anggota</th>
<th>Alamat</th>
<th>Telpon</th>
<th>Aksi</th>
</tr>";
$i = 1;
foreach ($arrayanggota as $data) {
echo "<tr><td>" . $i . "</td>
<td>" . $data['nama'] . "</td>
<td>" . $data['alamat'] . "</td>
<td>" . $data['telpon'] . "</td>
<td><a href='" . $_SERVER['PHP_SELF'] . "?aksi=edit&id_agt=" .
$data['id_anggota'] . "'>Edit</a> |
<a href='" . $_SERVER['PHP_SELF'] . "?aksi=hapus&id_agt=" .
$data['id_anggota'] . "'>Hapus</a></td>
</tr>";
$i++;
}
echo "</table>";
?>
</body>
</html>
$this->load->model('programs_model');
$this->load->model('program_category_model');
$this->load->model('program_target_model');
$this->load->library(array('ckeditor', 'ckfinder'));
$this->ckeditor->basePath = base_url().'assets/js/ckeditor/';
$this->ckeditor->config['toolbar'] = 'Full';
$this->ckeditor->config['language'] = 'eng';
$this->ckeditor->config['width'] = '730px';
$this->ckeditor->config['height'] = '300px';
//Add Ckfinder to Ckeditor
$this->ckfinder->SetupCKEditor($this->ckeditor,'../../../ckfinder/');
if(!$this->session->userdata('is_logged_in')){
redirect('admin/login');
}
}
/**
* Load the main view with all the current model model's data.
* @return void
*
* DELIMITER $$
* CREATE FUNCTION duration (start datetime, end datetime)
* RETURNS char(255)
* DETERMINISTIC
* BEGIN
* RETURN CONCAT(TIMESTAMPDIFF(HOUR, start, end), "Hours / ",
DATEDIFF(end, start), " Days");
* END$$
* DELIMITER ;
*
*/
public function index()
{
//all the posts sent by the view
$search_string = $this->input->post('search_string', TRUE);
$order = 'post_title';
$order_type = $this->input->post('order_type', TRUE);
//pagination settings
$config['per_page'] = 5;
$config['base_url'] = base_url().'admin/programs';
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 20;
$config['full_tag_open'] = '<ul>';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
//limit end
$page = $this->uri->segment(3);
//math to get the initial record to be select in the database
$limit_end = ($page * $config['per_page']) - $config['per_page'];
if ($limit_end < 0){
$limit_end = 0;
}
//if order type was changed
if($order_type){
$filter_session_data['order_type'] = $order_type;
}
else{
//we have something stored in the session?
if($this->session->userdata('order_type')){
$order_type = $this->session->userdata('order_type');
}else{
//if we have nothing inside session, so it's the default "Asc"
$order_type = 'Desc';
}
}
//make the data type var avaible to our view
$data['order_type_selected'] = $order_type;
//we must avoid a page reload with the previous session data
//if any filter post was sent, then it's the first time we load the content
//in this case we clean the session filter data
//if any filter post was sent but we are in some page, we must load the
session data
//filtered && || paginated
if($search_string !== false && $order !== false || $this->uri->segment(3)
== true){
/*
The comments here are the same for line 79 until 99
if post is not null, we store it in session data array
if is null, we use the session data already stored
we save order into the the var to load the view with the param already
selected
*/
if($search_string){
$filter_session_data['search_string_selected'] = $search_string;
}else{
$search_string = $this->session->userdata('search_string_selected');
}
$data['search_string_selected'] = $search_string;
if($order){
$filter_session_data['order'] = $order;
}
else{
$order = $this->session->userdata('order');
}
$data['order'] = $order;
//save session data into the session
$this->session->set_userdata($filter_session_data);
$data['count_post']= $this->programs_model>count_searchPrograms($search_string, $order);
$config['total_rows'] = $data['count_post'];
//fetch sql data into arrays
if($search_string){
if($order){
$data['programs'] = $this->programs_model>search_programs($search_string, $order, $order_type, $config['per_page'],
$limit_end);
}else{
$data['programs'] = $this->programs_model>search_programs($search_string, '', $order_type, $config['per_page'],
$limit_end);
}
}else{
if($order){
$data['programs'] = $this->programs_model->search_programs('',
$order, $order_type, $config['per_page'],$limit_end);
}else{
$data['programs'] = $this->programs_model->search_programs('',
'', $order_type, $config['per_page'],$limit_end);
}
}
}else{
//clean filter data inside section
$filter_session_data['category_selected'] = null;
$filter_session_data['search_string_selected'] = null;
$filter_session_data['order'] = null;
$filter_session_data['order_type'] = null;
$this->session->set_userdata($filter_session_data);
//pre selected options
$data['search_string_selected'] = '';
$data['category_selected'] = 0;
$data['order'] = 'id';
//fetch sql data into arrays
$data['count_post']= $this->programs_model->count_searchPrograms();
$data['programs'] = $this->programs_model->search_programs('', '',
$order_type, $config['per_page'],$limit_end);
$config['total_rows'] = $data['count_post'];
}//!isset($manufacture_id) && !isset($search_string) && !isset($order)
//initializate the panination helper
$this->pagination->initialize($config);
//load the view
$data['main_content'] = 'admin/programs/list';
$this->load->view('admin/includes/template', $data);
}//index
public function add()
{
$uploadStat = true;
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
//form validation
$this->form_validation->set_rules('title', 'title', 'required');
$this->form_validation->set_error_delimiters('<div class="alert alerterror"><a class="close" data-dismiss="alert"></a><strong>',
'</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$title
= strip_tags($this->input->post('title', TRUE));
$category = strip_tags($this->input->post('category', TRUE));
$target
= strip_tags($this->input->post('target', TRUE));
$show_on_menu
= strip_tags($this->input->post('showonmenu',
TRUE));
$summary = htmlspecialchars($this->input->post('summary', TRUE),
ENT_QUOTES);
$content
= htmlspecialchars($this->input->post('content', TRUE),
ENT_QUOTES);
$metaDesc = strip_tags($this->input->post('meta_desc', TRUE));
$achive
= htmlspecialchars($this->input->post('achievement', TRUE),
ENT_QUOTES);
$img
= '';
$url
= '';
/*
$startDate = date("Y-m-d H:i:s", strtotime(strip_tags($this->input>post('start_date', TRUE))));
$endDate
= date("Y-m-d H:i:s", strtotime(strip_tags($this->input>post('end_date', TRUE))));
$hours_program
= strip_tags($this->input>post('hours_program', TRUE));
$days_program
= strip_tags($this->input->post('days_program',
TRUE));
*/
$date
= date("Y-m-d H:i:s");
//$duration = 'duration("'.$startDate.'", "'.$endDate.'")';
//var_dump($_FILES['userfile']);
//die;
if($_FILES['userfile']['error'] <= 0){
$newFileName = $_FILES['userfile']['name'];
$fileExt = array_pop(explode(".", $newFileName));
$filename = md5(time()).".".$fileExt;
$config = array(
'upload_path' => "./uploads/images/",
'file_name' => $filename,
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2
MB(2048 Kb)
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$uploadStat = false;
}
else
{
$data = array('upload_data' => $this->upload->data());
$uploadStat = true;
$img = base_url().'uploads/images/'.$filename;
}
}
$data_to_store = array(
'prog_category_id'
'prog_target_id'
=> $category,
=> $target,
'show_on_menu_list'
=> $show_on_menu,
'programs_name'
=> $title,
'programs_summary'
=> $summary,
'programs_content'
=> $content,
'programs_advantage' => $achive,
'programs_img'
=> $img,
'programs_meta_desc'
=> $metaDesc,
'programs_created_date' => $date,
'programs_status'
=> 2
);
if($uploadStat){
//if the insert has returned true then we show the flash message
if($this->programs_model->add_programs($data_to_store)){
$data['flash_message'] = TRUE;
redirect('admin/programs');
}else{
$data['flash_message'] = FALSE;
}
}
}
}
//fetch manufactures data to populate the select field
$data['targets'] = $this->program_target_model>get_programTarget_by_status(2);
//fetch manufactures data to populate the select field
$data['categories'] = $this->program_category_model>get_programCategory_by_status(2);
//load the view
$data['main_content'] = 'admin/programs/add';
$this->load->view('admin/includes/template', $data);
}
/**
* Update item by his id
* @return void
*/
public function update()
{
//post id
$id = $this->uri->segment(4);
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
//form validation
$this->form_validation->set_rules('title', 'title', 'required');
if(!empty($img)){
$data_to_store = array(
'prog_category_id'
=> $category,
'prog_target_id'
=> $target,
'show_on_menu_list'
=> $show_on_menu,
'programs_name'
=> $title,
'programs_summary'
=> $summary,
'programs_content'
=> $content,
'programs_advantage'
=> $achive,
'programs_img'
=> $img
);
} else {
$data_to_store = array(
'prog_category_id'
=> $category,
'prog_target_id'
=> $target,
'show_on_menu_list'
=> $show_on_menu,
'programs_name'
=> $title,
'programs_summary'
=> $summary,
'programs_content'
=> $content,
'programs_advantage'
=> $achive
);
}
//if the insert has returned true then we show the flash message
if($this->programs_model->update_programs($id, $data_to_store) ==
TRUE){
$this->session->set_flashdata('flash_message', 'updated');
}else{
$this->session->set_flashdata('flash_message', 'not_updated');
}
redirect('admin/programs/update/'.$id);
}//validation run
}
//fetch manufactures data to populate the select field
$data['targets'] = $this->program_target_model>get_programTarget_by_status(2);
//fetch manufactures data to populate the select field
$data['categories'] = $this->program_category_model>get_programCategory_by_status(2);
//fetch category data to populate the select field
$data['programs'] = $this->programs_model->get_programs_by_id($id);
//load the view
$data['main_content'] = 'admin/programs/edit';
$this->load->view('admin/includes/template', $data);
}//update
/**
* Delete post by his id
* @return void
*/
public function delete()
{
$id = $this->uri->segment(4);
$this->programs_model->delete_programs($id);
redirect('admin/programs');
}
/**
* Publish post by his id
* @return void
*/
public function publish()
{
$id
= $this->uri->segment(4);
$stat = $this->uri->segment(5);
switch($stat){
case 'Published':
$stat = 1;
break;
case 'Pending':
$stat = 2;
break;
}
$this->programs_model->status($id, $stat);
redirect('admin/programs');
}
}
MODEL :
<?php
class Programs_model extends CI_Model {
/**
* Responsable for auto load the database
* @return void
*/
public function __construct()
{
$this->load->database();
}
/**
* Get post by his is
/**
* Get post by his is
* @param int $product_id
* @return array
*/
public function get_upcommingEvent()
{
/*
$this->db->select('*');
$this->db->from("programs_new");
*/
$this->db->select('*,
$this->db->group_by("programs_date_start");
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $product_id
* @return array
*/
public function get_allSeminarGroupByDate()
{
$this->db->select('*');
$this->db->from("programs");
$this->db->join("program_category",
"program_category.prog_category_id = programs_new.prog_category_id");
$this->db>where("program_category.prog_category_name",'Seminar');
$this->db->where("programs_status",2);
$this->db->group_by("programs_date_start");
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $where
* @return array
*/
public function get_programsWhere($where=null, $order=null,
$order_type='Asc', $limit_start, $limit_end)
{
//$this->db->distinct();
$this->db->select('*,
(SELECT category.prog_category_name FROM program_category AS
category WHERE category.prog_category_id like programs_new.prog_category_id)
AS category,
(SELECT target.prog_target_name FROM program_target AS target
WHERE target.prog_target_id like programs_new.prog_target_id) AS target',
FALSE);
$this->db->from('programs_new');
$this->db->join("program_category",
"program_category.prog_category_id = programs_new.prog_category_id");
//$this->db->join("program_target", "program_target.prog_target_id
= programs.prog_target_id");
if($where){
$this->db->where($where);
}
$this->db->where("programs_status",2);
$this->db->where("show_on_menu_list",1);
if($order){
$this->db->order_by('programs_new.programs_id',
$order_type);
}else{
$this->db->order_by('programs_new.programs_id', $order_type);
}
$this->db->limit($limit_start, $limit_end);
$this->db->group_by('programs_new.programs_name');
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $where
* @return array
*/
public function get_countProgramsWhere($where)
{
$this->db->select('*');
$this->db->from('programs_new');
//$this->db->join("program_target", "program_target.prog_target_id
= programs.prog_target_id");
if($where){
$this->db->where($where);
}
$this->db->where("programs_status",2);
$this->db->where("show_on_menu_list",1);
$this->db->group_by('programs_new.programs_name');
$query = $this->db->get();
return $query->num_rows();
}
/**
* Get post by his is
* @param int $where
* @return array
*/
public function get_programsInDate($date)
{
$startDate = date("Y-m-d 23:59:00", strtotime($date));
$endDate = date("Y-m-d 00:00:00", strtotime($date));
$this->db->select('*');
$this->db->from('programs_schedule');
if($date){
$this->db->where(array( 'programs_date_start <=' =>
$startDate, 'programs_date_end >=' => $endDate ));
}
$this->db->join("programs_new", "programs_new.programs_id =
programs_schedule.programs_id");
$this->db->join("program_category",
"program_category.prog_category_id = programs_new.prog_category_id");
$this->db->where("program_category.prog_category_name !
=","Seminar");
$this->db->where("programs_status",2);
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $where
* @return array
*/
public function get_seminarInDate($date)
{
$startDate = date("Y-m-d 23:59:00", strtotime($date));
$endDate = date("Y-m-d 00:00:00", strtotime($date));
$this->db->select('*');
$this->db->from('programs');
if($date){
$this->db->where(array( 'programs_date_start <=' =>
$startDate, 'programs_date_end >=' => $endDate ));
}
$this->db->join("program_category",
"program_category.prog_category_id = programs_new.prog_category_id");
$this->db>where("program_category.prog_category_name",'Seminar');
$this->db->where("programs_status",2);
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $title
* @return array
*/
public function get_programs_by_title($title)
{
$this->db->select('*');
$this->db->from('programs_new');
$this->db->where('programs_name', $title);
$this->db->where("programs_status",2);
$query = $this->db->get();
return $query->result_array();
}
public function get_seminar_by_title()
{
$this->db->select('*');
$this->db->from('programs_new');
$this->db->where('prog_category_id', 8);
$this->db->where("programs_status",2);
$this->db->order_by("programs_id", "asc");
$this->db->limit(1, 0);
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $category_id
* @return array
*/
public function get_programs_by_categoryId($category_id, $limit)
{
$this->db->select('*');
$this->db->from('programs_new');
$this->db->where('prog_category_id', $category_id);
$this->db->where("programs_status",2);
$this->db->order_by("programs_id", "asc");
$this->db->limit($limit);
$query = $this->db->get();
return $query->result_array();
}
/**
* Get post by his is
* @param int $post_id
* @return array
*/
public function get_programs_by_id($programs_id)
{
$this->db->select('*');
$this->db->from('programs_new');
$this->db->where('programs_id', $programs_id);
$this->db->where("programs_status",2);
$query = $this->db->get();
return $query->result_array();
}
/**
* Fetch categories data from the database
* possibility to mix search, filter and order
* @param string $search_string
* @param strong $order
* @param string $order_type
* @param int $limit_start
* @param int $limit_end
* @return array
*/
public function search_programs($search_string=null, $order=null,
$order_type='Asc', $limit_start, $limit_end)
{
$this->db->select('*,
(SELECT category.prog_category_name FROM program_category AS
category WHERE category.prog_category_id like programs_new.prog_category_id)
AS category,
(SELECT target.prog_target_name FROM program_target AS target
WHERE target.prog_target_id like programs_new.prog_target_id) AS target',
FALSE);
$this->db->from('programs_new');
if($search_string){
$this->db->like('programs_name', $search_string);
$this->db->like('programs_advantage', $search_string);
$this->db->like('programs_meta_desc', $search_string);
$this->db->like('programs_duration', $search_string);
}
if($order){
$this->db->order_by($order, $order_type);
}else{
$this->db->order_by('programs_id', $order_type);
}
//$this->db->limit($limit_start, $limit_end);
$query = $this->db->get();
return $query->result_array();
}
/**
$this->db->update('programs_new', $data);
$report = array();
$report['error'] = $this->db->_error_number();
$report['message'] = $this->db->_error_message();
if($report !== 0){
return true;
}else{
return false;
}
}
/**
* Delete post post
* @param int $id - post id
* @return boolean
*/
function delete_programs($id){
$this->db->where('programs_id', $id);
$this->db->delete('programs');
}
/**
* Delete post post
* @param int $id - post id
* @return boolean
*/
function status($id, $stat){
$this->db->where('programs_id', $id);
$this->db->update('programs', array( 'programs_status' =>
$stat ));
}
}
?>
VIEWS:
- Add
<div class="container top">
<ul class="breadcrumb">
<li>
<a href="<?php echo site_url("admin"); ?>">
<?php echo humanize($this->uri->segment(1));?>
</a>
<span class="divider">/</span>
</li>
<li>
<a href="<?php echo site_url("admin").'/'.$this->uri->segment(2); ?
>">
<?php echo humanize($this->uri->segment(2));?>
</a>
<span class="divider">/</span>
</li>
<li class="active">
<a href="#">New</a>
</li>
</ul>
<div class="page-header">
<h2>
Adding <?php echo humanize($this->uri->segment(2));?>
</h2>
</div>
<?php
//flash messages
if(isset($flash_message)){
if($flash_message == TRUE)
{
echo '<div class="alert alert-success">';
echo '<a class="close" data-dismiss="alert"></a>';
echo '<strong>Well done!</strong> new Post created with
success.';
echo '</div>';
}else{
echo '<div class="alert alert-error">';
echo '<a class="close" data-dismiss="alert"></a>';
echo '<strong>Oh snap!</strong> change a few things up and try
submitting again.';
echo '</div>';
}
}
?>
<?php
//form data
$attributes = array('class' => 'form-horizontal', 'id' => '');
$options_targets = array('' => "Select");
foreach ($targets as $row)
{
$options_targets[$row['prog_target_id']] = $row['prog_target_name'];
}
$options_category = array('' => "Select");
foreach ($categories as $row)
{
$options_category[$row['prog_category_id']] =
$row['prog_category_name'];
}
$options_show_on_menu = array(
'0' => 'No',
'1' => 'Yes',
);
//form validation
echo validation_errors();
echo form_open_multipart('admin/programs/add', $attributes);
?>
<fieldset>
<div class="control-group">
<label for="inputError" class="control-label">Title</label>
<div class="controls">
<input type="text" id="" name="title" value="<?php echo
set_value('title'); ?>" >
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<?php
echo '<div class="control-group">';
echo '<label for="category" class="control-label">Target</label>';
echo '<div class="controls">';
echo form_dropdown('target', $options_targets,
set_value('target'), 'class="span2"');
echo '</div>';
echo '</div>';
?>
<?php
echo '<div class="control-group">';
echo '<label for="category" class="controllabel">Category</label>';
echo '<div class="controls">';
echo form_dropdown('category', $options_category,
set_value('category'), 'class="span2"');
echo '</div>';
echo '</div>';
?>
<?php
echo '<div class="control-group">';
echo '<label for="showonmenu" class="control-label">Show On
Menu List</label>';
echo '<div class="controls">';
echo form_dropdown('showonmenu', $options_show_on_menu,
set_value('showonmenu'), 'class="span2"');
echo '</div>';
echo '</div>';
?>
<div class="control-group">
<label for="inputError" class="control-label">Meta
Description</label>
<div class="controls">
<textarea name="meta_desc"><?php echo
set_value('meta_desc'); ?></textarea>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="controllabel">Achievement</label>
<div class="controls">
<?php echo $this->ckeditor->editor("achievement",
set_value('achievement')); ?>
<!--<textarea name="achievement"><?php echo
set_value('achievement'); ?></textarea>-->
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Summary</label>
<div class="controls">
<?php echo $this->ckeditor->editor("summary",
set_value('summary')); ?>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Content</label>
<div class="controls">
<?php echo $this->ckeditor->editor("content",
set_value('content')); ?>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Image
Banner</label>
<div class="controls">
<input type="file" name="userfile" size="20" />
<?php
if(isset($upload_data)){
echo '<div class="post_banner"><img
src="'.base_url().'uploads/images/'.$upload_data['file_name'].'" /></div>';
}
?>
</div>
</div>
<div class="form-actions">
<input class="btn btn-primary" type="submit" value="Add
Post" />
<button class="btn" type="reset">Reset</button>
</div>
</fieldset>
<?php echo form_close(); ?>
</div>
-
Edit
<div class="container top">
<ul class="breadcrumb">
<li>
<a href="<?php echo site_url("admin"); ?>">
<?php echo humanize($this->uri->segment(1));?>
</a>
<span class="divider">/</span>
</li>
<li>
<a href="<?php echo site_url("admin").'/'.$this->uri->segment(2); ?
>">
<?php echo humanize($this->uri->segment(2));?>
</a>
<span class="divider">/</span>
</li>
<li class="active">
<a href="#">Update</a>
</li>
</ul>
<div class="page-header">
<h2>
Updating <?php echo humanize($this->uri->segment(2));?>
</h2>
</div>
<?php
//flash messages
if($this->session->flashdata('flash_message')){
if($this->session->flashdata('flash_message') == 'updated')
{
echo '<div class="alert alert-success">';
echo '<a class="close" data-dismiss="alert"></a>';
echo '<strong>Well done!</strong> product updated with
success.';
echo '</div>';
}else{
echo '<div class="alert alert-error">';
foreach($split_program_target as $i
=>$target_id) {
$i >0;
//echo $i.' '.$target_id .'</br>';
$selected_program_target_id[]=
$target_id;
}
}
else{
$selected_program_target_id[] =
$programs_target_id;
}
//echo form_dropdown('target', $options_targets, $programs[0]
['prog_target_id'], 'class="span2"');
echo form_dropdown('target', $options_targets,
$selected_program_target_id, 'class="span2"');
echo '</div>';
echo '</div>';
?>
<?php
echo '<div class="control-group">';
echo '<label for="category" class="controllabel">Category</label>';
echo '<div class="controls">';
$programs_category_id = $programs[0]
['prog_category_id'];
if(strpos($programs_category_id, ',') !== FALSE){
$split_program_category = explode(',' ,
$programs_category_id);
foreach($split_program_category as $x
=>$category_id) {
$i >0;
//echo $x.' '.$category_id .'</br>';
$selected_program_category_id[] =
$category_id;
}
}
else{
$selected_program_category_id[] =
$programs_category_id;
}
echo //form_dropdown('category', $options_category,
$programs[0]['prog_category_id'], 'class="span2"');
form_dropdown('category', $options_category,
$selected_program_category_id, 'class="span2"');
echo '</div>';
echo '</div>';
?>
<?php
echo '<div class="control-group">';
echo '<label for="showonmenu" class="control-label">Show On
Menu List</label>';
echo '<div class="controls">';
echo form_dropdown('showonmenu', $options_show_on_menu,
$programs[0]['show_on_menu_list'], 'class="span2"');
echo '</div>';
echo '</div>';
?>
<div class="control-group">
<label for="inputError" class="control-label">Meta
Description</label>
<div class="controls">
<textarea name="meta_desc"><?php echo $programs[0]
['programs_meta_desc']; ?></textarea>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="controllabel">Achievement</label>
<div class="controls">
<!--<textarea name="achievement"><?php echo
$programs[0]['programs_advantage']; ?></textarea>-->
<?php echo $this->ckeditor->editor("achievement",
htmlspecialchars_decode($programs[0]['programs_advantage'])); ?>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Summary</label>
<div class="controls">
<?php echo $this->ckeditor->editor("summary",
htmlspecialchars_decode($programs[0]['programs_summary'])); ?>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Content</label>
<div class="controls">
<?php echo $this->ckeditor->editor("content",
htmlspecialchars_decode($programs[0]['programs_content'])); ?>
<!--<span class="help-inline">Woohoo!</span>-->
</div>
</div>
<div class="control-group">
<label for="inputError" class="control-label">Image
Banner</label>
<div class="controls">
<input type="file" name="userfile" size="20" files="<?php echo
$programs[0]['programs_img']; ?>" />
<?php
if(!empty($programs[0]['programs_img'])){
echo '<div class="post_banner"><img
src="'.$programs[0]['programs_img'].'" /></div>';
}
?>
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary" type="submit">Save
changes</button>
<button class="btn" type="reset">Reset</button>
</div>
</fieldset>
<?php echo form_close(); ?>
-
</div>
List
<div class="container top">
<ul class="breadcrumb">
<li>
<a href="<?php echo site_url("admin"); ?>">
<?php echo humanize($this->uri->segment(1));?>
</a>
<span class="divider">/</span>
</li>
<li class="active">
<?php echo humanize($this->uri->segment(2));?>
</li>
</ul>
<div class="page-header users-header">
<h2>
<?php echo humanize($this->uri->segment(2));?>
<a href="<?php echo site_url("admin").'/'.$this->uri>segment(2); ?>/add" class="btn btn-success">Add a new</a>
</h2>
</div>
<div class="row">
<div class="span12 columns">
$i++;
}
?>
</tbody>
</table>
<?php //echo '<div class="pagination">'.$this->pagination>create_links().'</div>'; ?>
</div>
</div>