diff --git a/application/libraries/Grocery_CRUD.php b/application/libraries/Grocery_CRUD.php index cade205d..fb0a6aeb 100755 --- a/application/libraries/Grocery_CRUD.php +++ b/application/libraries/Grocery_CRUD.php @@ -16,7 +16,7 @@ * @package grocery CRUD * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @version 1.5.8 + * @version 1.6.1 * @author John Skoumbourdis */ @@ -366,6 +366,127 @@ protected function change_list_value($field_info, $value = null) return $value; } + + + protected function change_read_value($field_info, $value = null) + { + $real_type = $field_info->crud_type; + + switch ($real_type) { + case 'hidden': + case 'invisible': + case 'integer': + + break; + case 'true_false': + if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { + $value = $field_info->extras[$value]; + } else if(isset($this->default_true_false_text[$value])) { + $value = $this->default_true_false_text[$value]; + } + break; + case 'string': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + case 'text': + //$value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); + break; + case 'date': + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') + { + list($year,$month,$day) = explode("-",$value); + + $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); + } + else + { + $value = ''; + } + break; + case 'datetime': + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') + { + list($year,$month,$day) = explode("-",$value); + list($hours,$minutes) = explode(":",substr($value,11)); + + $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); + } + else + { + $value = ''; + } + break; + case 'enum': + $value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + + case 'multiselect': + $value_as_array = array(); + foreach(explode(",",$value) as $row_value) + { + $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; + } + $value = implode(",",$value_as_array); + break; + + case 'relation': + $value_arr = $this->get_relation_array($field_info->extras); + if(isset($value_arr[$value])) + $value = $value_arr[$value]; + break; + + case 'relation_n_n': + //$value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); + break; + + case 'password': + $value = '******'; + break; + + case 'dropdown': + $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; + break; + + case 'upload_file': + if(empty($value)) + { + $value = ""; + } + else + { + $is_image = !empty($value) && + ( substr($value,-4) == '.jpg' + || substr($value,-4) == '.png' + || substr($value,-5) == '.jpeg' + || substr($value,-4) == '.gif' + || substr($value,-5) == '.tiff') + ? true : false; + + $file_url = base_url().$field_info->extras->upload_path."/$value"; + + $file_url_anchor = ''; + } + else + { + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); + } + $file_url_anchor .= ''; + + $value = $file_url_anchor; + } + break; + + default: + //$value = $this->character_limiter($value,$this->character_limiter,"..."); + break; + } + + return $value; + } + /** * Character Limiter of codeigniter (I just don't want to load the helper ) * @@ -468,7 +589,7 @@ protected function get_type($db_type) * * @package grocery CRUD * @author John Skoumbourdis - * @version 1.5.8 + * @version 1.6.1 * @link http://www.grocerycrud.com/documentation */ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types @@ -504,6 +625,15 @@ protected function get_total_results() foreach($this->or_like as $or_like) $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + if(!empty($this->or_like_group)) + foreach($this->or_like_group as $or_like_group){ + $this->basic_model->group_start(); + foreach($or_like_group as $or_like){ + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + } + $this->basic_model->group_end(); + } + if(!empty($this->having)) foreach($this->having as $having) $this->basic_model->having($having[0],$having[1],$having[2]); @@ -512,6 +642,18 @@ protected function get_total_results() foreach($this->or_having as $or_having) $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + if(!empty($this->group_by)) + foreach($this->group_by as $group_by) + $this->basic_model->group_by($group_by[0]); + + if(!empty($this->join)) + foreach($this->join as $join) + $this->basic_model->join($join[0],$join[1],$join[2]); + + if(!empty($this->select)) + foreach($this->select as $select) + $this->basic_model->select($select[0],$select[1]); + if(!empty($this->relation)) foreach($this->relation as $relation) $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); @@ -580,7 +722,7 @@ protected function set_ajax_list_queries($state_info = null) $this->order_by($state_info->order_by[0],$state_info->order_by[1]); } - if(!empty($state_info->search)) + if(isset($state_info->search) && $state_info->search !== '') { if (!empty($this->relation)) { foreach ($this->relation as $relation_name => $relation_values) { @@ -594,8 +736,15 @@ protected function set_ajax_list_queries($state_info = null) if (isset($temp_relation[$search_field])) { if (is_array($temp_relation[$search_field])) { + $temp_where_query_array = array(); + foreach ($temp_relation[$search_field] as $relation_field) { $this->or_like($relation_field , $search_text); + $escaped_text = $this->basic_model->escape_str($search_text); + $temp_where_query_array[] = $relation_field . ' LIKE \'%' . $escaped_text . '%\''; + } + if (!empty($temp_where_query_array)) { + $this->where('(' . implode(' OR ', $temp_where_query_array) . ')', null); } } else { $this->like($temp_relation[$search_field] , $search_text); @@ -604,7 +753,7 @@ protected function set_ajax_list_queries($state_info = null) $escaped_text = $this->basic_model->escape_str($search_text); $this->having($search_field." LIKE '%".$escaped_text."%'"); } else { - $this->like($search_field, $search_text); + $this->like((strpos($search_field,".")!=false?'':$this->basic_db_table.'.').$search_field, $search_text); } @@ -623,9 +772,10 @@ protected function set_ajax_list_queries($state_info = null) $escaped_text = $this->basic_model->escape_str($state_info->search->text); $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); } else { - $this->like($state_info->search->field , $state_info->search->text); + $this->like((strpos($state_info->search->field,".")!==false?'':$this->basic_db_table.'.').$state_info->search->field , $state_info->search->text); } } + // Search all field else { $columns = $this->get_columns(); @@ -636,6 +786,8 @@ protected function set_ajax_list_queries($state_info = null) foreach($this->where as $where) $this->basic_model->having($where[0],$where[1],$where[2]); + $temp_where_query_array = array(); + foreach($columns as $column) { if(isset($temp_relation[$column->field_name])) @@ -644,24 +796,32 @@ protected function set_ajax_list_queries($state_info = null) { foreach($temp_relation[$column->field_name] as $search_field) { - $this->or_like($search_field, $search_text); + $escaped_text = $this->basic_model->escape_str($search_text); + $temp_where_query_array[] = $search_field . ' LIKE \'%' . $escaped_text . '%\''; } } else { - $this->or_like($temp_relation[$column->field_name], $search_text); + $escaped_text = $this->basic_model->escape_str($search_text); + $temp_where_query_array[] = $temp_relation[$column->field_name] . ' LIKE \'%' . $escaped_text . '%\''; } } elseif(isset($this->relation_n_n[$column->field_name])) { //@todo have a where for the relation_n_n statement } - elseif (isset($field_types[$column->field_name]) - && !in_array($field_types[$column->field_name]->type, array('date', 'datetime', 'timestamp'))) - { - $this->or_like($column->field_name, $search_text); - } - } + elseif ( + isset($field_types[$column->field_name]) && + !in_array($field_types[$column->field_name]->type, array('date', 'datetime', 'timestamp')) + ) { + $escaped_text = $this->basic_model->escape_str($search_text); + $temp_where_query_array[] = $column->field_name . ' LIKE \'%' . $escaped_text . '%\''; + } + } + + if (!empty($temp_where_query_array)) { + $this->where('(' . implode(' OR ', $temp_where_query_array) . ')', null); + } } } } @@ -834,7 +994,7 @@ protected function db_update_validation() $this->basic_model->where($primary_key,$state_info->primary_key); $row = $this->basic_model->get_row(); - if(!isset($row->$field_name)) { + if(!property_exists($row, $field_name)) { throw new Exception("The field name doesn't exist in the database. ". "Please use the unique fields only for fields ". "that exist in the database"); @@ -921,6 +1081,7 @@ protected function db_insert($state_info) return false; } + $insert_data = array(); $types = $this->get_field_types(); foreach($add_fields as $num_row => $field) @@ -931,7 +1092,7 @@ protected function db_insert($state_info) $post_data[$field->field_name] = array(); } - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) + if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) { if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) { @@ -1056,7 +1217,7 @@ protected function db_update($state_info) $post_data[$field->field_name] = array(); } - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) + if(array_key_exists($field->field_name, $post_data) && !isset($this->relation_n_n[$field->field_name])) { if(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && is_array($post_data[$field->field_name]) && empty($post_data[$field->field_name])) { @@ -1294,8 +1455,18 @@ protected function get_list() $this->basic_model->like($like[0],$like[1],$like[2]); if(!empty($this->or_like)) - foreach($this->or_like as $or_like) + foreach($this->or_like as $or_like){ $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + } + + if(!empty($this->or_like_group)) + foreach($this->or_like_group as $or_like_group){ + $this->basic_model->group_start(); + foreach($or_like_group as $or_like){ + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); + } + $this->basic_model->group_end(); + } if(!empty($this->having)) foreach($this->having as $having) @@ -1305,6 +1476,18 @@ protected function get_list() foreach($this->or_having as $or_having) $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); + if(!empty($this->group_by)) + foreach($this->group_by as $group_by) + $this->basic_model->group_by($group_by[0]); + + if(!empty($this->join)) + foreach($this->join as $join) + $this->basic_model->join($join[0],$join[1],$join[2]); + + if(!empty($this->select)) + foreach($this->select as $select) + $this->basic_model->select($select[0],$select[1]); + if(!empty($this->relation)) foreach($this->relation as $relation) $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); @@ -1363,6 +1546,32 @@ protected function get_edit_values($primary_key_value) return $values; } + protected function get_clone_values($primary_key_value) + { + $values = $this->basic_model->get_edit_values($primary_key_value); + + $types = $this->get_field_types(); + //print_r($types['file1']); + //print_r($types); + //die; + foreach($values as $k=>$v){ + if($types[$k.'']->crud_type=="upload_file"){ + //print_r($values->$k); + $values->$k = ""; + } + } + + if(!empty($this->relation_n_n)) + { + foreach($this->relation_n_n as $field_name => $field_info) + { + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); + } + } + + return $values; + } + protected function get_relation_n_n_selection_array($primary_key_value, $field_info) { return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); @@ -1539,7 +1748,7 @@ protected function ajax_relation($state_info) * * @package grocery CRUD * @author John Skoumbourdis - * @version 1.5.8 + * @version 1.6.1 */ class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver { @@ -1585,6 +1794,7 @@ protected function showList($ajax = false, $state_info = null) $data->primary_key = $this->get_primary_key(); $data->add_url = $this->getAddUrl(); $data->edit_url = $this->getEditUrl(); + $data->clone_url = $this->getCloneUrl(); $data->delete_url = $this->getDeleteUrl(); $data->delete_multiple_url = $this->getDeleteMultipleUrl(); $data->read_url = $this->getReadUrl(); @@ -1598,6 +1808,7 @@ protected function showList($ajax = false, $state_info = null) $data->unset_add = $this->unset_add; $data->unset_edit = $this->unset_edit; + $data->unset_clone = $this->unset_clone; $data->unset_read = $this->unset_read; $data->unset_delete = $this->unset_delete; $data->unset_export = $this->unset_export; @@ -1619,6 +1830,7 @@ protected function showList($ajax = false, $state_info = null) $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; + $data->list[$num_row]->clone_url = $data->clone_url.'/'.$row->{$data->primary_key}; } if(!$ajax) @@ -1633,6 +1845,9 @@ protected function showList($ajax = false, $state_info = null) $this->set_echo_and_die(); $this->_theme_view('list.php',$data); } + if (!empty($this->upload_fields)) { + $this->load_js_fancybox(); + } } protected function exportToExcel($state_info = null) @@ -1852,19 +2067,29 @@ protected function showAddForm() $this->_get_ajax_results(); } - protected function showEditForm($state_info) + protected function showEditForm($state_info,$type="edit") { + //IF $type IS CLONE THEN ACT LIKE THAT + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); $data = $this->get_common_data(); $data->types = $this->get_field_types(); - $data->field_values = $this->get_edit_values($state_info->primary_key); + $data->type = $type; + $data->field_values = $this->get_edit_values($state_info->primary_key); + if($type=="clone"){ + $data->field_values = $this->get_clone_values($state_info->primary_key); + } $data->add_url = $this->getAddUrl(); + $data->clone_url = $this->getCloneUrl($state_info); $data->list_url = $this->getListUrl(); $data->update_url = $this->getUpdateUrl($state_info); + if($type=="clone"){ + $data->update_url = $this->getInsertUrl(); + } $data->delete_url = $this->getDeleteUrl($state_info); $data->read_url = $this->getReadUrl($state_info->primary_key); $data->input_fields = $this->get_edit_input_fields($data->field_values); @@ -1873,6 +2098,7 @@ protected function showEditForm($state_info) $data->fields = $this->get_edit_fields(); $data->hidden_fields = $this->get_edit_hidden_fields(); $data->unset_back_to_list = $this->unset_back_to_list; + $data->unset_clone = $this->unset_clone; $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); $data->is_ajax = $this->_is_ajax(); @@ -1896,6 +2122,8 @@ protected function showReadForm($state_info) $data->list_url = $this->getListUrl(); $data->update_url = $this->getUpdateUrl($state_info); + $data->edit_url = $this->getEditUrl($state_info->primary_key); + $data->clone_url = $this->getCloneUrl($state_info); $data->delete_url = $this->getDeleteUrl($state_info); $data->read_url = $this->getReadUrl($state_info->primary_key); $data->input_fields = $this->get_read_input_fields($data->field_values); @@ -2828,7 +3056,7 @@ protected function get_read_input_fields($field_values = null) && $this->change_field_type[$field->field_name]->type == 'hidden') { continue; } - $this->field_type($field->field_name, 'readonly'); + //$this->field_type($field->field_name, 'readonly'); } $fields = $this->get_read_fields(); @@ -2836,20 +3064,27 @@ protected function get_read_input_fields($field_values = null) $input_fields = array(); - foreach($fields as $field_num => $field) + foreach($fields as $field) { $field_info = $types[$field->field_name]; $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; - if(!isset($this->callback_read_field[$field->field_name])) + if(isset($this->callback_read_field[$field->field_name])) { - $field_input = $this->get_field_input($field_info, $field_value); + $primary_key = $this->getStateInfo()->primary_key; + $field_input = $field_info; + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); } - else + elseif(isset($this->callback_column[$field->field_name])) { $primary_key = $this->getStateInfo()->primary_key; $field_input = $field_info; - $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); + $field_input->input = call_user_func($this->callback_column[$field->field_name], $field_value, $field_values); + } + else + { + $field_input = $this->get_field_input($field_info, $field_value); + $field_input->input = $this->change_read_value($field_info, $field_value); } switch ($field_info->crud_type) { @@ -2859,11 +3094,13 @@ protected function get_read_input_fields($field_values = null) continue; break; case 'hidden': - $this->read_hidden_fields[] = $field_input; - unset($this->read_fields[$field_num]); - unset($fields[$field_num]); - continue; - break; + if(isset($field_num)){ + $this->read_hidden_fields[] = $field_input; + unset($this->read_fields[$field_num]); + unset($fields[$field_num]); + continue; + break; + } } $input_fields[$field->field_name] = $field_input; @@ -3006,7 +3243,7 @@ protected function get_views_as_string() * * @package grocery CRUD * @author John Skoumbourdis - * @version 1.5.8 + * @version 1.6.1 */ class grocery_CRUD_States extends grocery_CRUD_Layout { @@ -3016,6 +3253,7 @@ class grocery_CRUD_States extends grocery_CRUD_Layout const STATE_EDIT = 3; const STATE_DELETE = 4; const STATE_INSERT = 5; + const STATE_CLONE = 20; const STATE_READ = 18; const STATE_DELETE_MULTIPLE = '19'; @@ -3040,7 +3278,8 @@ class grocery_CRUD_States extends grocery_CRUD_Layout 16 => 'export', 17 => 'print', 18 => 'read', - 19 => 'delete_multiple' + 19 => 'delete_multiple', + 20 => 'clone' ); public function getStateInfo() @@ -3069,6 +3308,15 @@ public function getStateInfo() } break; + case self::STATE_CLONE: + if ($first_parameter !== null) { + $state_info = (object) array('primary_key' => $first_parameter); + } else { + throw new Exception('On the state "clone" the Primary key cannot be null', 6); + die(); + } + break; + case self::STATE_DELETE: if ($first_parameter !== null) { $state_info = (object) array('primary_key' => $first_parameter); @@ -3141,7 +3389,7 @@ public function getStateInfo() { $state_info->order_by = $data['order_by']; } - if(!empty($data['search_text'])) + if(isset($data['search_text']) && $data['search_text'] !== '') { if(empty($data['search_field'])) { @@ -3153,7 +3401,7 @@ public function getStateInfo() if (is_array($data['search_field'])) { $search_array = array(); foreach ($data['search_field'] as $search_key => $search_field_name) { - $search_array[$search_field_name] = !empty($data['search_text'][$search_key]) ? $data['search_text'][$search_key] : ''; + $search_array[$search_field_name] = isset($data['search_text'][$search_key]) ? $data['search_text'][$search_key] : ''; } $state_info->search = $search_array; } else { @@ -3367,6 +3615,14 @@ protected function getEditUrl($primary_key = null) return $this->state_url('edit/'.$primary_key); } + protected function getCloneUrl($primary_key = null) + { + if($primary_key === null) + return $this->state_url('clone'); + else + return $this->state_url('clone/'.$primary_key->primary_key); + } + protected function getReadUrl($primary_key = null) { if($primary_key === null) @@ -3437,7 +3693,7 @@ protected function getAjaxRelationManytoManyUrl() * @package grocery CRUD * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt - * @version 1.5.8 + * @version 1.6.1 * @author John Skoumbourdis */ @@ -3460,7 +3716,7 @@ class Grocery_CRUD extends grocery_CRUD_States * * @var string */ - const VERSION = "1.5.8"; + const VERSION = "1.6.1"; const JQUERY = "jquery-1.11.1.min.js"; const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; @@ -3498,9 +3754,13 @@ class Grocery_CRUD extends grocery_CRUD_States protected $display_as = array(); protected $order_by = null; protected $where = array(); + protected $or_where = array(); protected $like = array(); protected $having = array(); protected $or_having = array(); + protected $group_by = array(); + protected $join = array(); + protected $select = array(); protected $limit = null; protected $required_fields = array(); protected $_unique_fields = array(); @@ -3529,9 +3789,11 @@ class Grocery_CRUD extends grocery_CRUD_States protected $unset_export = false; protected $unset_print = false; protected $unset_back_to_list = false; + protected $unset_clone = false; protected $unset_columns = null; protected $unset_add_fields = null; protected $unset_edit_fields = null; + protected $unset_clone_fields = null; protected $unset_read_fields = null; /* Callbacks */ @@ -3544,9 +3806,14 @@ class Grocery_CRUD extends grocery_CRUD_States protected $callback_before_delete = null; protected $callback_after_delete = null; protected $callback_delete = null; + protected $callback_before_clone = null; + protected $callback_after_clone = null; + protected $callback_clone = null; protected $callback_column = array(); protected $callback_add_field = array(); protected $callback_edit_field = array(); + protected $callback_read_field = array(); + protected $callback_clone_field = array(); protected $callback_upload = null; protected $callback_before_upload = null; protected $callback_after_upload = null; @@ -3819,6 +4086,7 @@ public function unset_operations() { $this->unset_add = true; $this->unset_edit = true; + $this->unset_clone = true; $this->unset_delete = true; $this->unset_read = true; $this->unset_export = true; @@ -3864,6 +4132,7 @@ public function unset_fields() $this->unset_add_fields = $args; $this->unset_edit_fields = $args; + $this->unset_clone_fields = $args; $this->unset_read_fields = $args; return $this; @@ -3897,6 +4166,20 @@ public function unset_edit_fields() return $this; } + public function unset_clone_fields() + { + $args = func_get_args(); + + if(isset($args[0]) && is_array($args[0])) + { + $args = $args[0]; + } + + $this->unset_clone_fields = $args; + + return $this; + } + public function unset_read_fields() { $args = func_get_args(); @@ -3924,6 +4207,19 @@ public function unset_back_to_list() return $this; } + + /** + * Unsets everything that has to do with buttons or links with clone + * @access public + * @return void + */ + public function unset_clone() + { + $this->unset_clone = true; + + return $this; + } + /** * * The fields that user will see on add/edit @@ -4366,20 +4662,41 @@ public function like($field, $match = '', $side = 'both') return $this; } - protected function having($key, $value = '', $escape = TRUE) + public function having($key, $value = '', $escape = TRUE) { $this->having[] = array($key, $value, $escape); return $this; } - protected function or_having($key, $value = '', $escape = TRUE) + public function or_having($key, $value = '', $escape = TRUE) { $this->or_having[] = array($key, $value, $escape); return $this; } + public function group_by($field) + { + $this->group_by[] = array($field); + + return $this; + } + + public function join($table, $where = '', $type = "left") + { + $this->join[] = array($table, $where, $type); + + return $this; + } + + public function select($select, $escape = NULL) + { + $this->select[] = array($select, $escape); + + return $this; + } + public function or_like($field, $match = '', $side = 'both') { $this->or_like[] = array($field, $match, $side); @@ -4387,6 +4704,14 @@ public function or_like($field, $match = '', $side = 'both') return $this; } + public function or_like_group($field, $match = '', $side = 'both') + { + $tb_name = substr($field, 0, strpos($field,".")); + $this->or_like_group[$tb_name][] = array($field, $match, $side); + + return $this; + } + public function limit($limit, $offset = '') { $this->limit = array($limit,$offset); @@ -4749,6 +5074,25 @@ public function render() break; + case 20://clone + if($this->unset_clone) + { + throw new Exception('You don\'t have permissions for this operation', 14); + die(); + } + + if($this->theme === null) + $this->set_theme($this->default_theme); + $this->setThemeBasics(); + + $this->set_basic_Layout(); + + $state_info = $this->getStateInfo(); + + $this->showEditForm($state_info,"clone"); + + break; + } return $this->get_layout(); @@ -4866,6 +5210,39 @@ public function callback_delete($callback = null) return $this; } + /** + * + * Enter description here ... + */ + public function callback_before_clone($callback = null) + { + $this->callback_before_clone = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_after_clone($callback = null) + { + $this->callback_after_clone = $callback; + + return $this; + } + + /** + * + * Enter description here ... + */ + public function callback_clone($callback = null) + { + $this->callback_clone = $callback; + + return $this; + } + /** * * Enter description here ... @@ -4889,6 +5266,7 @@ public function callback_field($field, $callback = null) { $this->callback_add_field[$field] = $callback; $this->callback_edit_field[$field] = $callback; + $this->callback_read_field[$field] = $callback; return $this; } @@ -4919,6 +5297,19 @@ public function callback_edit_field($field, $callback = null) return $this; } + /** + * + * Enter description here ... + * @param string $field + * @param mixed $callback + */ + public function callback_read_field($field, $callback = null) + { + $this->callback_read_field[$field] = $callback; + + return $this; + } + /** * * Callback that replace the default auto uploader diff --git a/application/models/Grocery_crud_model.php b/application/models/Grocery_crud_model.php index 24930055..9c0d0bc1 100755 --- a/application/models/Grocery_crud_model.php +++ b/application/models/Grocery_crud_model.php @@ -63,7 +63,7 @@ function get_list() if(strstr($related_field_title,'{')) { - $related_field_title = str_replace(" "," ",$related_field_title); + //$related_field_title = str_replace(" "," ",$related_field_title); $select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name"; } else @@ -160,6 +160,16 @@ function or_having($key, $value = NULL, $escape = TRUE) $this->db->or_having( $key, $value, $escape); } + function join($table, $where, $type = "left") + { + $this->db->join( $table, $where, $type); + } + + function select($select, $escape = NULL) + { + $this->db->select( $select, $escape); + } + function like($field, $match = '', $side = 'both') { $this->db->like($field, $match, $side); @@ -175,6 +185,21 @@ function limit($value, $offset = '') $this->db->limit( $value , $offset ); } + function group_by($field) + { + $this->db->group_by( $field ); + } + + function group_start() + { + $this->db->group_start(); + } + + function group_end() + { + $this->db->group_end(); + } + function get_total_results() { // A fast way to calculate the total results @@ -190,7 +215,7 @@ function get_total_results() } else { $this->db->select($this->table_name . '.' . $key); } - + return $this->db->get($this->table_name)->num_rows(); } @@ -219,7 +244,11 @@ function join_relation($field_name , $related_table , $related_field_title) if($related_primary_key !== false) { $unique_name = $this->_unique_join_name($field_name); - $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = {$this->table_name}.$field_name",'left'); + $table = "{$this->table_name}."; + if(strpos($field_name, ".")!==false){ + $table = ""; + } + $this->db->join( $related_table.' as '.$unique_name , "$unique_name.$related_primary_key = $table$field_name",'left'); $this->relation[$field_name] = array($field_name , $related_table , $related_field_title); @@ -255,7 +284,7 @@ function get_relation_array($field_name , $related_table , $related_field_title, if(strstr($related_field_title,'{')) { - $related_field_title = str_replace(" ", " ", $related_field_title); + //$related_field_title = str_replace(" ", " ", $related_field_title); $select .= "CONCAT('".str_replace(array('{','}'),array("',COALESCE(",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $field_name_hash"; } else diff --git a/assets/grocery_crud/js/jquery_plugins/config/jquery.fancybox.config.js b/assets/grocery_crud/js/jquery_plugins/config/jquery.fancybox.config.js index b4333bf7..480dd554 100644 --- a/assets/grocery_crud/js/jquery_plugins/config/jquery.fancybox.config.js +++ b/assets/grocery_crud/js/jquery_plugins/config/jquery.fancybox.config.js @@ -1,9 +1,11 @@ -$(function(){ - $('.image-thumbnail').fancybox({ - 'transitionIn' : 'elastic', - 'transitionOut' : 'elastic', - 'speedIn' : 600, - 'speedOut' : 200, - 'overlayShow' : false - }); -}); \ No newline at end of file +$(function() { + if ($('.image-thumbnail').length > 0) { + $('.image-thumbnail').fancybox({ + 'transitionIn': 'elastic', + 'transitionOut': 'elastic', + 'speedIn': 600, + 'speedOut': 200, + 'overlayShow': false + }); + } +}); diff --git a/change_log.txt b/change_log.txt index e54492d7..50f78c8e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,12 @@ +v 1.6.2 + - #442: Searching in grid with value 0 is not working +v 1.6.1 + - #441 Adding clone functionality - contribution from @portapipe +v 1.6.0 + - #211: Bug if use where clause and try to "search all" the fields + - #432: Bootstrap Theme issues with filtering when we are using set_relation with multiple fields + - #353: Adding callback_read_field function + - #433: Preview click with fancybox to work the same across all the themes v 1.5.9 - #420: set_relation with brackets is causing ambiguous column name when the field name exists at the basic table - #413: Unexpected error when there are non english chars and a datetime field as column