[eluser]Agung Wahyudiono[/eluser]
This is the implementation of jcrop library on the Controller
Code:
// UPLOAD SECTION
case 'upload':
$this->load->library('jcrop');
$prefix = 'f_';
$data['prefix'] = $prefix;
$data['target_w'] = 600;
$data['target_h'] = 400;
$setdata = array(
'prefix'=>$prefix,
'folder'=>'asset/picture/feature/',
'target_w'=>$data['target_w'],
'target_h'=>$data['target_h']
);
$this->jcrop->set_data($setdata);
$data['page'] = 'feature_upload';
$action_form = site_url('djawaadmin/feature/upload');
//Upload Process
if(isset($_POST[$prefix.'submit'])) {
$this->jcrop->uploading(& $status);
$data['status'] = $status;
}
//Cancelling Upload
if(isset($_POST[$prefix.'cancel'])) {
$this->jcrop->cancel();
}
//Saving data
if(isset($_POST[$prefix.'save'])) {
$this->form_validation->set_error_delimiters('<div style="color:red;margin-bottom:10px;">', '</div>');
$this->form_validation->set_rules($prefix.'title','"Feature"','required|max_length[50]');
$this->form_validation->set_rules($prefix.'desc','"Description"','required|max_length[150]');
if($this->form_validation->run() == false){
$data['error_notification'] = 'Im Sorry, there are some error occured. Please fill all the blank form';
}else{
$this->load->model('front/featuremodel','fm');
$this->jcrop->produce(& $pic_loc,& $pic_path);
$feature_data = array( 'name_feature' => $this->input->post($prefix.'title'),
'description' => $this->input->post($prefix.'desc'),
'picture' => $pic_loc,
'path' => $pic_path);
$this->fm->insert_feature($feature_data);
}
}
//Cek if image has uploaded
if($this->jcrop->is_uploaded(& $thepicture,& $orig_w,& $orig_h,& $ratio)){
$data['orig_w'] = $orig_w;
$data['orig_h'] = $orig_h;
$data['ratio'] = $ratio;
$data['thepicture'] = $thepicture;
$form = array ( 'form_input' =>array('name'=>$prefix.'title',
'class'=>'text-long',
'value'=>'Feature Title',
'onClick'=>'$(this).val(\'\');'),
'form_textarea'=>array('name'=>$prefix.'desc',
'id'=>'fdesc',
'value'=>'Type Your Description here',
'onClick'=>'$(\'#fdesc\').val(\'\');')
);
$this->jcrop->add_form($form);
$data['form'] = $this->jcrop->show_form($action_form,TRUE);
}else{
$data['form'] = $this->jcrop->show_form($action_form);
}
I cut the code only on the upload section. This is show you how to implementing jcrop library on controller.