Fullcalendar not showing codeigniter file - codeigniter

My view load.php:
<?php
$all = $this->db->get_where('project', array('institution_id' => $this->session->userdata('institution_id')))->result_array();
$data = array();
foreach($all as $row)
{
$data[] = array(
'id' => $row["project_code"],
'title' => $row["description"],
'start' => date('d-M-Y H:i:s', $row["timestamp_start"]),
'end' => date('d-M-Y H:i:s', $row["timestamp_end"])
);
}
echo json_encode($data);
?>
However, it doesnt display with my Fullcalendar. Which is at:
events: 'https://xxxxxxx.com.au/index.php?staff/load/',
The view that you requested. The events is gotten from load.php which is at the start of this post.
<div id="calendar" class="fc-calendar"></div>
<script>
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
events: 'https://panel.strater.com.au/index.php?staff/load/',
});
});
</script>

Related

Lavacharts display 2 Piecharts, second chart has no data

I am trying to display 2 piechart in same view, this is my view code :
<div class="panel-body form-horizontal">
{{-- <div id="morris-donut-chart"></div> --}}
<div class="form-group">
<div id="chart-div"></div>
#piechart('tgt','chart-div')
</div>
<div class="form-group">
<div id="chart-div2"></div>
#piechart('capai','chart-div2')
</div>
</div>
both success display, but the second chart has no data.
Piechart
i think the variable of data table is not problem , when i use dd(), it's has data.
Data of Capai
my controller code :
public function statistik()
{
$lava = new Lavacharts;
$ket = array("totalTarget" => 0, "totalCapai" => 0);
$target_ = Target::select('grup')
->selectRaw("SUM(nilai) AS jumlah")
->groupBy('grup')
->get()
->toArray();
$data = \Lava::DataTable();
$data->addStringColumn('Target')
->addNumberColumn('Percent');
foreach($target_ as $row){
$data->addRow([$row['grup'], $row['jumlah'] ]);
$ket["totalTarget"] += $row['jumlah'];
}
\Lava::PieChart('tgt', $data, [
'title' => 'Target :',
'height' => '300',
'is3D' => true,
]);
$capai_ = Faktur::select('nama')
->selectRaw('SUM(qty) AS jumlah')
->groupBy('sub_group')
->get()
->toArray();
$data_capai = \Lava::DataTable();
$data_capai->addStringColumn('Pencapaian')
->addNumberColumn('Percent');
foreach($capai_ as $row_){
$data_capai->addRow([$row_['nama'], $row_['jumlah'] ]);
$ket["totalCapai"] += $row_['jumlah'];
}
// dd($data_capai);
\Lava::PieChart('capai', $data_capai, [
'title' => 'Pencapaian :',
'height' => '300',
'is3D' => true,
]);
return view('dashboard', compact('lava', 'ket'));
}
Is there something I miss?
I already fixed it.
All I need is to convert data to Float.

How to show variable value in Ajax callback function?

I am very new to Ajax.In ajax function, I cannot show the variable $competition_id content.I am using following codes but it show the ID only.
function custom_fixture_template(){
$competition_id = $_POST[ 'competion' ];
echo $competition_id;
$args = array(
'post_type' => array( 'football_fixture' ), // profile and letter are CPTs
'posts_per_page'=>5,
'meta_key' => 'pb_match_date',
'orderby' => 'meta_value',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'competition',
'field' => 'id',
'terms' => $competition_id
),
),
'meta_query' => array(
array(
'key' => 'pb_match_status',
'value' => 'fixture'
),
)
);
$my_query = null;
$my_query = new WP_Query($args); ?>
}
add_action("wp_ajax_my_custom_fixture_template", "custom_fixture_template");
add_action("wp_ajax_norpiv_my_custom_fixture_template", "custom_fixture_template");
Ajax Code :
jQuery(".fixture-competition").change(
function(){
jQuery.ajax({
url:"<?php echo admin_url();?>admin-ajax.php",
type:"post",
data:{"action":"my_custom_fixture_template",competion:jQuery(this).val()},
success:function(res){
jQuery('.competition-container').remove();
jQuery('.new-fixture').html('');
jQuery('.new-fixture').append(res);
}
});
});
HTML Codes:
<select name="fixture-competition" class="fixture-competition">
<?php
$args = array(
'type' => 'football_fixture',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'competition',
'pad_counts' => false );
$competition_fixture = get_categories($args); ?>
<option value="Select All">--Select--</option>
<?php
foreach ($competition_fixture as $competition) { ?>
<option value="<?php echo $competition->term_id; ?>">
<?php $url = get_term_link($competition);?>
<?php echo $competition->name; ?>
</option>
<?php
}
?>
</select>
Your php function doesn't return anything. So the jQuery script has nothing to append to .new-fixture.
You can do something like
$my_query = new WP_Query($args); // be carefull of typo (a php closing tag)
echo json_encode($my_query);
then in the ajax response, you'll be able to parse the json response.
success:function(res){
var json = $.parseJSON(res);
console.log(json);
...
}
Hope it gives you some hints...
I have solved it by myself using following codes:
<div class="team-league-name-top">
<?php
$competition_name = get_term( $competition_id, 'competition' );
echo $competition_name->name;
?>
</div>

How to show error message from do_upload using codigniter

i create image module and i edit image more then 1mb then can not show errormsg.
i used codigniter fremwork.
controller:
public function edit($id) {
$this->edit_status_check($id);
$this->form_validation->set_rules('agent_name', 'Agent Name', 'required');
$this->form_validation->set_rules('mobile', 'Mobile No.', 'required');
$this->form_validation->set_rules('agent_vehicle', 'Agent Vehicle', 'required');
if ($this->form_validation->run() == FALSE) {
$data = array(
'page_title' => 'Edit Agent',
'page_name' => 'agent/edit',
'result' => $this->agent_model->select_id($id),
'result_vehicle' => $this->vehicle_model->list_all(),
'error' => validation_errors(),
'id' => $id
);
$this->load->view('template', $data);
} else {
$config['upload_path'] = '../uploads/agent/';
$config['allowed_types'] = 'jpg|jpeg';
$config['encrypt_name'] = TRUE;
$config['max_size'] = 1000; // 1 mb
$this->load->library('upload', $config);
if (!empty($_FILES['agent_image']['name'])) {
if ($this->upload->do_upload('agent_image')) {
$_POST['agent_img_url'] = 'uploads/agent/' . $this->upload->data('file_name');
} else {
$data = array(
'page_title' => 'Edit Agent',
'page_name' => 'agent/edit',
'result' => $this->agent_model->select_id($id),
'result_vehicle' => $this->vehicle_model->list_all(),
'error' => $this->upload->display_errors(),
'id' => $id
);
$this->load->view('template', $data);
}
}
$this->agent_model->update($_POST, $id);
alert('Update', $_POST['agent_name']);
redirect('agent');
}
}
Model:
public function update($data, $id) {
$updatedata = array(
'name' => $data['agent_name'],
'mobile' => $data['mobile'],
'password' => sha1($data['password']),
'vehicle' => $data['agent_vehicle'],
'address' => $data['agent_address'],
'category' => $data['category'],
'created_on' => date('Y-m-d h:i:sa')
);
if (!empty($data['agent_img_url'])) {
$updatedata['img_url'] = $data['agent_img_url'];
}
$this->db->where('id', $id);
$this->db->update('agent', $updatedata);
}
View:
<div class="form-group">
<img src="/<?= $result['img_url']; ?>" class="img-responsive" name="old_agent_image" width="133" height="100">
</div>
<div class="form-group">
<label>Agent Image</label>
<input type="file" name="agent_image">
</div>
MY question: I edit image for particular user then image uploaded,but if image size more then 1mb ,then image can not upload and display error message.
so my question how to show errormsg.
$uploaded = $this->upload->do_upload('file'); //'file' is input field name
if($uploaded) {
$upload_data = $this->upload->data();
// do database stuff
} else {
$data['errors'] = array("error" => $this->upload->display_errors());
}

Yii Refresh Grid On DropDown change

In YII views folder i have test module and admin.php file to manage contents are below and i render form here where i put the code of form and dropdown in it , i want that grid refresh value of status change in dropdown
Suppose i select "Approved" than Grid show the data where status is approved
<?php
Yii::app()->clientScript->registerScript('dropdown', "
$('.dropdown-form form').submit(function(){
$('#testimonial-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Testimonials</h1>
<div class="dropdown-form">
<?php $this->renderPartial('_dropdownform',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'testimonial-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'created_by',
'test_name',
'test_email',
'comments',
'created_at',
/*
'status',
'approved_on',
'approved_by',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Form below is _dropdownform , it contain a form and dropdown from this dropdown i am choosing the value of status
<div class="wide form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row">
<?php
echo CHtml::dropDownList('status', '', array(0 => 'New', 1 => 'Approved', 2 => 'Declined'), array(
'prompt' => 'Select Status',
'ajax' => array(
'type' => 'POST',
'url' => Yii::app()->createUrl('testimonial/loadthedata'),
//or $this->createUrl('loadcities') if '$this' extends CController
'update' => '#testimonial-grid', //or 'success' => 'function(data){...handle the data in the way you want...}',
'data' => array('status' => 'js:this.value'),
)));
?>
</div>
<div class="row buttons">
<?php //echo CHtml::submitButton('Search'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
AND THE CODE IN MY CONTROLLER OR URL GIVEN IN DROPDOWN TO FETCH DATA IS FOLLOWING ACTION BUT I DONT KNOW HOW TO FETCH DATA FROM THIS FUNCTION AND PASS TO GRID VIEW
public function actionloadthedata() {
if (isset($_POST['status'])) {
$status = $_POST['status'];
if($status==0){
$status='New';
}
if($status==1){
$status='Approved';
}
if($status==2){
$status='Declined';
}
Testimonial::model()->findByAttributes(array('status'=>$status));
}
}
You can use CGridView property filterCssClass to link the grid filter, for example
$this->widget('CGridView', array(
'id' => 'my-list',
'filterCssClass' => '#filterFormId .filter',
And there is filter form
<?php $form = $this->beginWidget('CActiveForm', array(
'id' => 'filter-fomr-id',
)); ?>
<div class="filter clearfix">
<?php echo $form->dropDownList($model, 'name', [0=>'all', '1'=>'some else']); ?>
</div>
Replace #filterFormId .filter on jquery selector specific to you form. In other words, set id attribute for filter form, then use "#THISID .row".
In your gridview file, make sure you have this code:
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#ad-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
then in the CGridView definition:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'testimonial-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
...
array(
'name'=>'Status',
'filter'=>CHtml::dropDownList('YourModel[status]', $model->status, array(0 => 'New', 1 => 'Approved', 2 => 'Declined'), array('empty' => '--all--') ),
'value'=>'( $data->status == 0) ? "New": ( $data->status == 1) ? "Approved" : "Declined"',
'htmlOptions' => array(
'style' => 'width: 40px; text-align: center;',
),
),
...
array(
'class'=>'CButtonColumn',
),
),
));
// CGridView
In order to save if/else in the 'value' section, you can implement a method in your model that returns the string associated to the integer.
It works great, just with the default Yii admin.php view, which you can edit as much as you need.
Update
Added support for empty status, does not filter query results
Thanks #Alex for your help but i am successful to make filterdropdown for grid , code is following but will you please tell me that i want that grid show only values where status=New , how i can do when page load grid show values where status is New
but first i paste the working code of dropdown filter for grid
Here is my admin.php file
<?php
$this->breadcrumbs = array(
'Testimonials' => array('index'),
'Manage',
);
$this->menu = array(
array('label' => 'List Testimonial', 'url' => array('index')),
array('label' => 'Create Testimonial', 'url' => array('create')),
);
?>
<h1>Manage Testimonials</h1>
<!-----------drop down form------------->
<?php
Yii::app()->clientScript->registerScript('dropdownfilter', "
$('.dropdown-form form #staticid').change(function(){
$.fn.yiiGridView.update('testimonial-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="dropdown-form">
<?php
$this->renderPartial('_dropdownfilter', array(
'model' => $model,
));
?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'testimonial-grid',
'dataProvider' => $model->search(),
// 'filter' => $model,
'columns' => array(
'id',
'created_by',
'test_name',
'test_email',
'comments',
'created_at',
'status',
array(
'class' => 'CButtonColumn',
),
),
));
?>
Here is my render partial form where i place the static drop dow
<div class="wide form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row">
<?php
echo CHtml::dropDownList('staticid', '', array('0' => 'New', '1' => 'Approved', '2' => 'Declined'), array(
// 'onChange' => 'this.form.submit()',
'ajax' => array(
'type' => 'POST', //request type
)));
?>
</div>
<?php $this->endWidget(); ?>
And Here is code of my adminaction in controller
public function actionAdmin() {
$model = new Testimonial('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['staticid'])) {
$getStatus = $_GET['staticid'];
if ($getStatus == 0)
$status = 'New';
if ($getStatus == 1)
$status = 'Approved';
if ($getStatus == 2)
$status = 'Declined';
$model->status = $status;
}
if (isset($_GET['Testimonial']))
$model->attributes = $_GET['Testimonial'];
$this->render('admin', array(
'model' => $model,
));
}
Now i want that when i actionadmin triggered first time it show status=New values

CodeIgniter 2 - captcha helper?

I cant seem to get CI2's captcha helper to work... Can someone point out what I am doing wrong?
I think I've followed all the steps on the doc's but Im not getting anything event a print_r(get_defined_vars()) isnt showing anything... :(
My Controller
function index()
{
$this->load->helper('form');
$this->load->helper('captcha');
$this->load->model('captcha');
$vals = array(
'word' => 'Random word',
'img_path' => '../images/captcha/',
'img_url' => 'http://mysite/images/captcha/',
'font' => '../../system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200,
"time" => time()
);
$data['cap'] = create_captcha($vals);
$cap = array(
'captcha_time' => $vals['time'],
'ip_address' => $this->input->ip_address(),
'word' => $vals['word']
);
$this->captcha_model->insert_captcha($cap);
//print_r(get_defined_vars());
$data['main_content'] = 'admin/landing.php';
$this->load->view('includes/template', $data);
}
My Model
function input_captcha($data)
{
$query = $this->db->insert_string('captcha', $data);
$this->db->query($query);
}
My View
<section>
<h3>You must captcha this captcha before proceeding to your demise!</h3>
<article>
<?php echo form_open('admin/auth');?>
<p>Who the F are you?</p>
<?php echo form_input('email', 'your real email!');?>
<br>
<?php echo 'Submit the word you see below:';?>
<br>
<?php echo $cap['image'];?>
<br>
<?php echo '<input type="text" name="captcha" value="" />'; ?>
<br>
<?php echo form_submit('submit', 'Send It!');?>
<?php echo form_close();?>
</article>
</section>
The problem was in the path's for images. One thing, even with the log threshold set to four, I was getting NO indication of any kind of problem. I set it to absolute paths and everything worked fine...
function index()
{
$this->load->helper('form');
$this->load->helper('captcha');
$this->load->model('captcha_model');
$vals = array(
'img_path' => '/var/www/mysite.com/images/captcha/',
'img_url' => 'http://mysite.com/images/captcha/',
'font' => '../../system/fonts/texb.ttf',
'img_width' => '150',
'img_height' => 30,
'expiration' => 7200,
"time" => time()
);
$data['cap'] = create_captcha($vals);
$cap = array(
'captcha_time' => $data['cap']['time'],
'ip_address' => $this->input->ip_address(),
'word' => $data['cap']['word']
);
$this->captcha_model->add_captcha($cap);
$data['main_content'] = 'admin/landing.php';
$this->load->view('includes/template', $data);
}

Resources