I am building a scheduling app. I am able to sort the database using the CJuiDatePicker widget's "onSelect" option. Now I am trying to use the "beforeShow" option to ensure that only dates that have tasks can be selectable. Can anyone help?
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$dataProvider,
'attribute'=>'start_time',
'options'=>array(
'dateFormat' => 'yy-mm-dd',
'changeMonth' => true,
'changeYear' => true,
'beforeShowDay' => 'js:$.datepicker.noWeekends',
'beforeShow' => "js:function Check_Alert2(){
Check_Alert();
}
",
'onSelect' => "js:function SearchFunc() {
var data = $('input').serialize();
var url = document.URL;
var params = $.param(data);
url = url.substr(0, url.indexOf('?'));
window.History.pushState(null, document.title,$.param.querystring(url, data));
}"
),
'htmlOptions'=>array(
'style'=>'height:20px;',
'readonly' =>true,
),
));
i am still using the original code. I need an array generated within the beforeshowday. When i run your code it fails on the getdates() function call.
'beforeShowDay' => 'js:function(date){
var array = ["2013-10-30","2013-10-31","2013-12-18","2013-12-25"];
var string = jQuery.datepicker.formatDate("yy-mm-dd", date);
if (array.indexOf(string) == -1){
return [false,"", "No event"];
} else return [true,"", "Event"];
Related
Below is my code for showing an extra option in navigation-drawer of Moodle LMS account.
function local_report_extend_navigation(global_navigation $navigation)
{
$main_node = $navigation->add(get_string('pluginname', 'local_report'), '/local/report/');
$main_node->nodetype = 1;
$main_node->collapse = false;
$main_node->force_open = true;
$main_node->isexpandable = false;
$main_node->showinflatnavigation = true;
// $main_node->icon = new pix_icon('i/settings', get_string('pluginname', 'local_report'));
$main_node->icon = new pix_icon('i/files', get_string('pluginname', 'local_report'));
}
The output for it is :
This is the navigation-drawer. I want to show the Reports option to only admin, teacher and manager
Can anyone let me know how to make this done?
You will need to create a capability in your local plugin. In local/report/db/access.php
$capabilities = array(
'local/report:canview' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
),
),
);
Then use something like this in your function.
if (!has_capability('local/report:canview', \context_system::instance())) {
return;
}
Greeting everyone and especially to Senior of CodeIgniter Developer.
I have a problem with website that was built from CodeIgniter (I am not the developer inherited by previous epmployer). This website cannot working properly, especially when upload the image and shows warning about
Error Number: 1048 Column 'article_image' cannot be null
I did try with find the problem on the script and database, but nothing change and because no one change the codes & contents. Today, i try again with changing the "Null into yes" (previously is "No"), and tried to upload the article. It is miracle that it is working but the next problem is the image is gone (broken). I search at other and looking people with same problem with me says that i need to upgrade the CodeIgniter. Mine is 3.0.0 while the latest is 3.1.10. I copy paste the content inside /System and /views/error/cli not making better but make it worse, the image at the web page is gone(missing).
This is my Article_model
defined('BASEPATH') OR exit('No direct script access allowed');
class Article_model extends CI_Model {
public function get_all()
{
// $this->db->order_by('article_date', 'desc');
// $this->db->order_by('article_view', 'desc');
// $query = $this->db->get_where('article', array('flag !=' => 3));
// return $query->result_array();
$query = $this->db->query("SELECT A.*,B.*, A.id AS id_article FROM article AS A JOIN category B ON A.article_category = B.id WHERE A.flag != 3 ORDER BY article_date DESC, article_view DESC ");
return $query->result_array();
}
public function check($article_id)
{
$query = $this->db->get_where('article', array('flag !=' => 3, 'id' => $article_id));
return $query->row_array();
}
public function get_category()
{
$query = $this->db->order_by('category_name', 'ASC')->get_where('category', array('flag' => 1));
return $query->result_array();
}
public function get_tag()
{
$query = $this->db->order_by('tag_name', 'ASC')->get_where('tag', array('flag' => 1));
return $query->result_array();
}
public function get_selected_tag($article_id)
{
$query = $this->db
->select('tag.id, tag_name')
->join('article_tag', 'tag_id = tag.id')
->where(array('tag.flag' => 1, 'article_id' => $article_id))
->get('tag');
return $query->result_array();
}
public function insert()
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author' => $this->session->admin_id,
'article_title' => $this->input->post('article_title'),
'article_slug' => url_title($this->input->post('article_title'), '-', TRUE),
'article_category' => $this->input->post('article_category'),
'article_image' => $image['file_name'],
'article_content' => $this->input->post('article_content'),
'is_popup' => $this->input->post('is_poup'),
'article_date' => $this->input->post('article_date'),
);
$this->db->insert('article', $insert_data);
$article_id = $this->db->insert_id();
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
public function update($id)
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author' => $this->session->admin_id,
'article_title' => $this->input->post('article_title'),
'article_slug' => url_title($this->input->post('article_title'), '-', TRUE),
'article_category' => $this->input->post('article_category'),
'is_popup' => $this->input->post('is_popup'),
'article_content' => $this->input->post('article_content'),
'article_date' => $this->input->post('article_date'),
);
if ($image)
{
$insert_data['article_image'] = $image['file_name'];
}
$article_id = $id;
$this->db->where('id', $id);
$this->db->update('article', $insert_data);
$this->db->where('article_id', $id);
$this->db->delete('article_tag');
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
}
What should i do guys? i did backup but it remain same like after upgraded. Thank you. Web Url (http://www.hidupseimbangku.com/)
First. If you want to upgrade CI Version you must follow Upgrading Guide one by one. There may be break changes and you need to correct them, you can find this guide here:
https://www.codeigniter.com/userguide3/installation/upgrading.html
I suggest you rollback upgrade changes and start again doing one by one. It is not hard, it is just time consuming.
The error you're getting is probably related to an error of uploading process. What is file_upload?
I also suggest you read this, for properly file upload.
I have implemented a web service for update profile image using Codeigniter framework. But I have an issue while uploading png image. It always gives an error saying -
The filetype you are attempting to upload is not allowed.
Following is my config array:
$config = array(
'upload_path' => BASEPATH .'../assets/uploads/profile_images',
'allowed_types' => 'jpg|png|jpeg',
'overwrite' => TRUE,
'max_size' => "2048000",
);
I have added "png" in allowed types, still it is showing error.
Please guide.
Instead of using
config['allowed_types'] = 'jpg|png|jpeg'
I changed my config array to
$config = array(
'upload_path' => BASEPATH .'../assets/uploads/profile_images',
'allowed_types' => '*',
'overwrite' => TRUE,
'max_size' => "2048000",
);
And added custom form validation rule
$this->form_validation->set_rules('profile_image', '', 'callback_file_check');
and its corresponding function named file_check(). Here I will be checking file type and will return an error if it is not an image.
/**
Function: file_check
Description: file value and type check during validation
Date: 6th July 2018
**/
public function file_check($str)
{
$allowed_mime_type_arr = array('image/gif','image/jpeg','image/pjpeg','image/png','image/x-png');
$mime = mime_content_type($_FILES['profile_image']['tmp_name']);
if(isset($_FILES['profile_image']['tmp_name']) && $_FILES['profile_image']['tmp_name']!="")
{
if(in_array($mime, $allowed_mime_type_arr))
{
return true;
} else {
$this->form_validation->set_message('file_check', 'Please select only jpg/jpeg/png file.');
return false;
}
}else{
$this->form_validation->set_message('file_check', 'Please choose a file to upload.');
return false;
}
}
So my upload function will look like this
if($this->form_validation->run() == true) {
if (!$this->upload->do_upload('profile_image')) {
return $this->response(['msg'=>$this->upload->display_errors(),'success'=>false,'code'=>400]);
} else {
$fileName = $this->upload->data();
$name = $fileName['file_name'];
}
//Save into database
$image = $this->Api_model->update_profile_image('assets/uploads/profile_images/'.$name, $request_data['user_id']);
if($image)
return $this->response(['msg'=>'Image updated successfully','success'=>true,'code'=>200, 'image_path' => base_url().$image]);
else
return $this->response(['msg'=>'Image updated failed','success'=>false,'code'=>400]);
} else {
return $this->response(['msg' => validation_errors(), 'success' => false, 'code' => 401]);
}
I'm using drupal 7 module date (date_popup). I have 2 datepickers. I need to update minDate on the second datepicker on "onSelect" event by click on the first one. It works but only for the second click. If I click on the first datepicker and select date nothing happens and minDate is not updated. When I select the second time it works well. Why doesn't it work from my first click?
Here is my datepicker init php code for my module.
<?php
$form['leave'] = array(
'#type' => 'date_popup', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
'#title' => t('Leave'),
'#default_value' => date('Y-m-d'),
'#date_format' => $format,
'#required' => TRUE, // Added
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3', // Optional, used to set the year range (back 3 years and forward 3 years is the default).
'#datepicker_options' => array(
'changeMonth' => false,
'changeYear' => false,
'altField' => '#edit-leave-alt',
'showOtherMonths' =>true,
'selectOtherMonths' =>false,
'altFormat' => 'D, M d, yy',
'minDate' => 0,
), // Optional, as of 7.x-2.6+, used to pass in additional parameters from the jQuery Datepicker widget.
'#attributes' => array('readonly' => 'readonly')
);
$form['leave'] = array(
'#type' => 'date_popup', // types 'date_popup', 'date_text' and 'date_timezone' are also supported. See .inc file.
'#title' => t('Leave'),
'#default_value' => date('Y-m-d'),
'#date_format' => $format,
'#required' => TRUE, // Added
'#date_label_position' => 'within', // See other available attributes and what they do in date_api_elements.inc
'#date_increment' => 15, // Optional, used by the date_select and date_popup elements to increment minutes and seconds.
'#date_year_range' => '-3:+3', // Optional, used to set the year range (back 3 years and forward 3 years is the default).
'#datepicker_options' => array(
'changeMonth' => false,
'changeYear' => false,
'altField' => '#edit-leave-alt',
'showOtherMonths' =>true,
'selectOtherMonths' =>false,
'altFormat' => 'D, M d, yy',
'minDate' => 0,
), // Optional, as of 7.x-2.6+, used to pass in additional parameters from the jQuery Datepicker widget.
'#attributes' => array('readonly' => 'readonly')
);
?>
Here is my js code
(function($) {
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.currentYear, param.currentMonth, param.currentDay);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};
})(jQuery);
Just to flesh out my comment. Try this instead:
(function($) {
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-return-datepicker-popup-0").datepicker({minDate: new Date()});
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.selectedYear, param.selectedMonth, param.selectedDay);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};
})(jQuery);
Skarist, thank you a lot!
Here is the working code:
Drupal.behaviors.ifly_search = {
attach: function (context, settings) {
$("#edit-leave-datepicker-popup-0").datepicker({
onSelect: function(date,param) {
var data = new Date(param.selectedYear, param.selectedMonth, param.selectedDay);
$("#edit-return-datepicker-popup-0").datepicker({minDate: data}).val(date);
$("#edit-return-datepicker-popup-0").datepicker("option", "minDate", data).val(date);
},
});
}
};
My Goal is if user is submitting this form with "Product Name" value as "YYY". On submit page should reload but this time "Product Name" should show previous valye as default as in this case "YYY".
Here is my code...
function addnewproduct_page () {
return drupal_get_form('addnewproduct_form',&$form_state);
}
function addnewproduct_form(&$form_state) {
$form = array();
$formproductname['productname'] = array (
'#type' => 'textfield',
'#title' => t('Product Name'),
'#required' => TRUE,
'#size' => '20',
);
if (isset($form_state['values']['productname']))
{
$form['productname']['#default_value'] = $form_state['values']['productname'];
}
//a "submit" button
$form['submit'] = array (
'#type' => 'submit',
'#value' => t('Add new Product'),
);
return $form;
}
You can use $form_state['storage'] in your submit handler to hoard values between steps. So add a submit function like so:
function addnewproduct_form_submit ($form, &$form_state) {
// Store values
$form_state['storage']['addnewproduct_productname'] = $form_state['values']['productname'];
// Rebuild the form
$form_state['rebuild'] = TRUE;
}
Then your form builder function would become:
function addnewproduct_form(&$form_state) {
$form = array();
$form['productname'] = array (
'#type' => 'textfield',
'#title' => t('Product Name'),
'#required' => TRUE,
'#size' => '20',
);
if (isset($form_state['storage']['addnewproduct_productname'])) {
$form['productname']['#default_value'] = $form_state['storage']['addnewproduct_productname'];
}
return $form;
}
Just remember that your form will keep being generated as long as your $form_state['storage'] is stuffed. So you will need to adjust your submit handler and unset($form_state['storage']) when are ready to save values to the database etc.
If your form is more like a filter ie. used for displaying rather than storing info, then you can get away with just
function addnewproduct_form_submit ($form, &$form_state) {
// Rebuild the form
$form_state['rebuild'] = TRUE;
}
When the form rebuilds it will have access to $form_state['values'] from the previous iteration.
Drupal will do this by default if you include:
$formproductname['#redirect'] = FALSE;
In your $formproductname array.
I prefer to save all values in one time when we are speaking about complex forms :
foreach ($form_state['values'] as $form_state_key => $form_state_value) {
$form_state['storage'][$form_state_key] = $form_state['values'][$form_state_value];
}
simply adding rebuilt = true will do the job:
$form_state['rebuild'] = TRUE;
version: Drupal 7
For anyone looking for an answer here while using webform (which I just struggled through), here's what I ended up doing:
//in hook_form_alter
$form['#submit'][] = custom_booking_form_submit;
function custom_booking_form_submit($form, &$form_state) {
// drupal_set_message("in form submit");
// dpm($form_state, 'form_state');
foreach ($form_state['values']['submitted_tree'] as $form_state_key => $form_state_value) {
$form_state['storage'][$form_state_key] = $form_state_value;
}
}
Note: added the ' as it was lost
In my case I had a couple of drop-downs. Submitting the form posted back to the same page, where I could filter a view and I wanted to show the previously selected options. On submitting the form I built a query string in the submit hook:
function myform_submit($form, &$form_state) {
$CourseCat = $form_state['values']['coursecat'];
drupal_goto("courses" , array('query' =>
array('cat'=>$CourseCat))
);
}
In the form build hook, all I did was get the current query string and used those as default values, like so:
function myform_form($form, &$form_state) {
$Params = drupal_get_query_parameters ();
$CatTree = taxonomy_get_tree(taxonomy_vocabulary_machine_name_load ('category')->vid);
$Options = array ();
$Options ['all'] = 'Select Category';
foreach ($CatTree as $term) {
$Options [$term->tid] = $term->name;
}
$form['cat'] = array(
'#type' => 'select',
'#default_value' => $Params['cat'],
'#options' => $Options
);
$form['submit'] = array(
'#type' => 'submit',
'#default_value' => 'all',
'#value' => t('Filter'),
);
return $form;
}
I usually solve this by putting the submitted value in the $_SESSION variable in the submit hook. Then the next time the form is loaded, I check the $_SESSION variable for the appropriate key, and put the value into the #default_value slot if there's anything present.
Not sure if this would work for you, but you could try adding the #default_value key to the form array
$form['productname'] = array (
'#type' => 'textfield',
'#title' => t('Product Name'),
'#required' => TRUE,
'#size' => '20',
'#default_value' => variable_get('productname', ''),
);
That way if the variable is set it will grab whatever it is, but if not you can use a default value.