@@ -124,13 +124,13 @@ |
||
| 124 | 124 | <?php |
| 125 | 125 | $url = $_SERVER['REQUEST_URI']; |
| 126 | 126 | |
| 127 | - if (strpos($url,'computing-support') !== false) { |
|
| 127 | + if (strpos($url, 'computing-support') !== false) { |
|
| 128 | 128 | $dept_name = 'Computing Support'; |
| 129 | 129 | $dept_url = 'computing-support'; |
| 130 | - } elseif (strpos($url,'marketing') !== false) { |
|
| 130 | + } elseif (strpos($url, 'marketing') !== false) { |
|
| 131 | 131 | $dept_name = 'Marketing'; |
| 132 | 132 | $dept_url = 'marketing'; |
| 133 | - } elseif (strpos($url,'human-resources') !== false) { |
|
| 133 | + } elseif (strpos($url, 'human-resources') !== false) { |
|
| 134 | 134 | $dept_name = 'Human Resources'; |
| 135 | 135 | $dept_url = 'human-resources'; |
| 136 | 136 | } else { |
@@ -35,10 +35,10 @@ |
||
| 35 | 35 | <?php } ?> |
| 36 | 36 | <?php $controls = PageTypeComposerFormLayoutSetControl::getList($cfl); |
| 37 | 37 | |
| 38 | - foreach($controls as $con) { |
|
| 39 | - if (is_object($page)) { // we are loading content in |
|
| 40 | - $con->setPageObject($page); |
|
| 41 | - } |
|
| 38 | + foreach($controls as $con) { |
|
| 39 | + if (is_object($page)) { // we are loading content in |
|
| 40 | + $con->setPageObject($page); |
|
| 41 | + } |
|
| 42 | 42 | $con->setTargetParentPageID($targetParentPageID); |
| 43 | 43 | ?> |
| 44 | 44 | <?php $con->render(); ?> |
@@ -19,13 +19,13 @@ discard block |
||
| 19 | 19 | <div class="alert alert-info" style="display: none" id="ccm-page-type-composer-form-save-status"></div> |
| 20 | 20 | |
| 21 | 21 | <style>.form-group.ccm-composer-url-slug {display:none}</style> |
| 22 | -<?php $u = new User(); if($u->inGroup(Group::getByName('Administrators'))){ ?> |
|
| 22 | +<?php $u = new User(); if ($u->inGroup(Group::getByName('Administrators'))) { ?> |
|
| 23 | 23 | <style>.form-group.ccm-composer-url-slug {display:block !important}</style> |
| 24 | 24 | <?php } ?> |
| 25 | 25 | |
| 26 | 26 | <input type="hidden" name="ptID" value="<?php echo $pagetype->getPageTypeID()?>" /> |
| 27 | 27 | |
| 28 | -<?php foreach($fieldsets as $cfl) { ?> |
|
| 28 | +<?php foreach ($fieldsets as $cfl) { ?> |
|
| 29 | 29 | <fieldset> |
| 30 | 30 | <?php if ($cfl->getPageTypeComposerFormLayoutSetDisplayName()) { ?> |
| 31 | 31 | <legend><?php echo $cfl->getPageTypeComposerFormLayoutSetDisplayName()?></legend> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | <?php } ?> |
| 36 | 36 | <?php $controls = PageTypeComposerFormLayoutSetControl::getList($cfl); |
| 37 | 37 | |
| 38 | - foreach($controls as $con) { |
|
| 38 | + foreach ($controls as $con) { |
|
| 39 | 39 | if (is_object($page)) { // we are loading content in |
| 40 | 40 | $con->setPageObject($page); |
| 41 | 41 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | global $u; |
| 24 | 24 | |
| 25 | 25 | if ($u->isLoggedIn()) { |
| 26 | - echo '<p class="welcome-username">Welcome ' . $u->getUserName() . '</p>'; |
|
| 26 | + echo '<p class="welcome-username">Welcome '.$u->getUserName().'</p>'; |
|
| 27 | 27 | } else { |
| 28 | 28 | echo '<p class="welcome-username"><a href="/login">Click here to Login</a></p>'; |
| 29 | 29 | |
@@ -35,10 +35,10 @@ |
||
| 35 | 35 | <?php } ?> |
| 36 | 36 | <?php $controls = PageTypeComposerFormLayoutSetControl::getList($cfl); |
| 37 | 37 | |
| 38 | - foreach($controls as $con) { |
|
| 39 | - if (is_object($page)) { // we are loading content in |
|
| 40 | - $con->setPageObject($page); |
|
| 41 | - } |
|
| 38 | + foreach($controls as $con) { |
|
| 39 | + if (is_object($page)) { // we are loading content in |
|
| 40 | + $con->setPageObject($page); |
|
| 41 | + } |
|
| 42 | 42 | $con->setTargetParentPageID($targetParentPageID); |
| 43 | 43 | ?> |
| 44 | 44 | <?php $con->render(); ?> |
@@ -19,13 +19,13 @@ discard block |
||
| 19 | 19 | <div class="alert alert-info" style="display: none" id="ccm-page-type-composer-form-save-status"></div> |
| 20 | 20 | |
| 21 | 21 | <style>.form-group.ccm-composer-url-slug {display:none}</style> |
| 22 | -<?php $u = new User(); if($u->inGroup(Group::getByName('Administrators'))){ ?> |
|
| 22 | +<?php $u = new User(); if ($u->inGroup(Group::getByName('Administrators'))) { ?> |
|
| 23 | 23 | <style>.form-group.ccm-composer-url-slug {display:block !important}</style> |
| 24 | 24 | <?php } ?> |
| 25 | 25 | |
| 26 | 26 | <input type="hidden" name="ptID" value="<?php echo $pagetype->getPageTypeID()?>" /> |
| 27 | 27 | |
| 28 | -<?php foreach($fieldsets as $cfl) { ?> |
|
| 28 | +<?php foreach ($fieldsets as $cfl) { ?> |
|
| 29 | 29 | <fieldset> |
| 30 | 30 | <?php if ($cfl->getPageTypeComposerFormLayoutSetDisplayName()) { ?> |
| 31 | 31 | <legend><?php echo $cfl->getPageTypeComposerFormLayoutSetDisplayName()?></legend> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | <?php } ?> |
| 36 | 36 | <?php $controls = PageTypeComposerFormLayoutSetControl::getList($cfl); |
| 37 | 37 | |
| 38 | - foreach($controls as $con) { |
|
| 38 | + foreach ($controls as $con) { |
|
| 39 | 39 | if (is_object($page)) { // we are loading content in |
| 40 | 40 | $con->setPageObject($page); |
| 41 | 41 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | <div class="col-lg-12"> |
| 7 | 7 | <h1 class="page-header"><?php $page = Page::getCurrentPage(); echo $page->getCollectionName(); ?></h1> |
| 8 | 8 | <br> |
| 9 | - <?php $a= new Area('Page Content'); $a->display($c); ?> |
|
| 9 | + <?php $a = new Area('Page Content'); $a->display($c); ?> |
|
| 10 | 10 | </div> <!-- END col-lg-12 --> |
| 11 | 11 | </div> <!-- END row --> |
| 12 | 12 | </div> <!-- END container-fluid --> |
@@ -883,6 +883,9 @@ discard block |
||
| 883 | 883 | return $validation_result; |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | + /** |
|
| 887 | + * @return boolean |
|
| 888 | + */ |
|
| 886 | 889 | protected function db_insert($state_info) |
| 887 | 890 | { |
| 888 | 891 | $validation_result = $this->db_insert_validation(); |
@@ -1351,6 +1354,9 @@ discard block |
||
| 1351 | 1354 | return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); |
| 1352 | 1355 | } |
| 1353 | 1356 | |
| 1357 | + /** |
|
| 1358 | + * @param string $table_name |
|
| 1359 | + */ |
|
| 1354 | 1360 | protected function set_basic_db_table($table_name = null) |
| 1355 | 1361 | { |
| 1356 | 1362 | $this->basic_model->set_basic_table($table_name); |
@@ -1997,6 +2003,9 @@ discard block |
||
| 1997 | 2003 | $this->set_echo_and_die(); |
| 1998 | 2004 | } |
| 1999 | 2005 | |
| 2006 | + /** |
|
| 2007 | + * @param boolean $upload_result |
|
| 2008 | + */ |
|
| 2000 | 2009 | protected function delete_file_layout($upload_result) |
| 2001 | 2010 | { |
| 2002 | 2011 | @ob_end_clean(); |
@@ -2012,6 +2021,9 @@ discard block |
||
| 2012 | 2021 | $this->set_echo_and_die(); |
| 2013 | 2022 | } |
| 2014 | 2023 | |
| 2024 | + /** |
|
| 2025 | + * @param string $css_file |
|
| 2026 | + */ |
|
| 2015 | 2027 | public function set_css($css_file) |
| 2016 | 2028 | { |
| 2017 | 2029 | $this->css_files[sha1($css_file)] = base_url().$css_file; |
@@ -2022,12 +2034,18 @@ discard block |
||
| 2022 | 2034 | $this->js_files[sha1($js_file)] = base_url().$js_file; |
| 2023 | 2035 | } |
| 2024 | 2036 | |
| 2037 | + /** |
|
| 2038 | + * @param string $js_file |
|
| 2039 | + */ |
|
| 2025 | 2040 | public function set_js_lib($js_file) |
| 2026 | 2041 | { |
| 2027 | 2042 | $this->js_lib_files[sha1($js_file)] = base_url().$js_file; |
| 2028 | 2043 | $this->js_files[sha1($js_file)] = base_url().$js_file; |
| 2029 | 2044 | } |
| 2030 | 2045 | |
| 2046 | + /** |
|
| 2047 | + * @param string $js_file |
|
| 2048 | + */ |
|
| 2031 | 2049 | public function set_js_config($js_file) |
| 2032 | 2050 | { |
| 2033 | 2051 | $this->js_config_files[sha1($js_file)] = base_url().$js_file; |
@@ -2892,6 +2910,9 @@ discard block |
||
| 2892 | 2910 | return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
| 2893 | 2911 | } |
| 2894 | 2912 | |
| 2913 | + /** |
|
| 2914 | + * @param string $view |
|
| 2915 | + */ |
|
| 2895 | 2916 | protected function _theme_view($view, $vars = array(), $return = FALSE) |
| 2896 | 2917 | { |
| 2897 | 2918 | $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; |
@@ -3551,7 +3572,7 @@ discard block |
||
| 3551 | 3572 | * @access public |
| 3552 | 3573 | * @param string |
| 3553 | 3574 | * @param array |
| 3554 | - * @return void |
|
| 3575 | + * @return Grocery_CRUD |
|
| 3555 | 3576 | */ |
| 3556 | 3577 | public function columns() |
| 3557 | 3578 | { |
@@ -3576,7 +3597,7 @@ discard block |
||
| 3576 | 3597 | * @access public |
| 3577 | 3598 | * @param mixed |
| 3578 | 3599 | * @param string |
| 3579 | - * @return void |
|
| 3600 | + * @return Grocery_CRUD |
|
| 3580 | 3601 | */ |
| 3581 | 3602 | function set_rules($field, $label = '', $rules = '') |
| 3582 | 3603 | { |
@@ -3643,7 +3664,7 @@ discard block |
||
| 3643 | 3664 | * @access public |
| 3644 | 3665 | * @param string |
| 3645 | 3666 | * @param array |
| 3646 | - * @return void |
|
| 3667 | + * @return Grocery_CRUD |
|
| 3647 | 3668 | */ |
| 3648 | 3669 | public function unset_texteditor() |
| 3649 | 3670 | { |
@@ -3665,7 +3686,7 @@ discard block |
||
| 3665 | 3686 | * Unsets just the jquery library from the js. This function can be used if there is already a jquery included |
| 3666 | 3687 | * in the main template. This will avoid all jquery conflicts. |
| 3667 | 3688 | * |
| 3668 | - * @return void |
|
| 3689 | + * @return Grocery_CRUD |
|
| 3669 | 3690 | */ |
| 3670 | 3691 | public function unset_jquery() |
| 3671 | 3692 | { |
@@ -3679,7 +3700,7 @@ discard block |
||
| 3679 | 3700 | * when the jquery UI JavaScript and CSS are already included in the main template. |
| 3680 | 3701 | * This will avoid all jquery UI conflicts. |
| 3681 | 3702 | * |
| 3682 | - * @return void |
|
| 3703 | + * @return Grocery_CRUD |
|
| 3683 | 3704 | */ |
| 3684 | 3705 | public function unset_jquery_ui() |
| 3685 | 3706 | { |
@@ -3692,7 +3713,7 @@ discard block |
||
| 3692 | 3713 | * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included |
| 3693 | 3714 | * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. |
| 3694 | 3715 | * |
| 3695 | - * @return void |
|
| 3716 | + * @return Grocery_CRUD |
|
| 3696 | 3717 | */ |
| 3697 | 3718 | public function unset_bootstrap() |
| 3698 | 3719 | { |
@@ -3704,7 +3725,7 @@ discard block |
||
| 3704 | 3725 | /** |
| 3705 | 3726 | * Unsets the add operation from the list |
| 3706 | 3727 | * |
| 3707 | - * @return void |
|
| 3728 | + * @return Grocery_CRUD |
|
| 3708 | 3729 | */ |
| 3709 | 3730 | public function unset_add() |
| 3710 | 3731 | { |
@@ -3716,7 +3737,7 @@ discard block |
||
| 3716 | 3737 | /** |
| 3717 | 3738 | * Unsets the edit operation from the list |
| 3718 | 3739 | * |
| 3719 | - * @return void |
|
| 3740 | + * @return Grocery_CRUD |
|
| 3720 | 3741 | */ |
| 3721 | 3742 | public function unset_edit() |
| 3722 | 3743 | { |
@@ -3728,7 +3749,7 @@ discard block |
||
| 3728 | 3749 | /** |
| 3729 | 3750 | * Unsets the delete operation from the list |
| 3730 | 3751 | * |
| 3731 | - * @return void |
|
| 3752 | + * @return Grocery_CRUD |
|
| 3732 | 3753 | */ |
| 3733 | 3754 | public function unset_delete() |
| 3734 | 3755 | { |
@@ -3740,7 +3761,7 @@ discard block |
||
| 3740 | 3761 | /** |
| 3741 | 3762 | * Unsets the read operation from the list |
| 3742 | 3763 | * |
| 3743 | - * @return void |
|
| 3764 | + * @return Grocery_CRUD |
|
| 3744 | 3765 | */ |
| 3745 | 3766 | public function unset_read() |
| 3746 | 3767 | { |
@@ -3762,7 +3783,7 @@ discard block |
||
| 3762 | 3783 | /** |
| 3763 | 3784 | * Unsets the export button and functionality from the list |
| 3764 | 3785 | * |
| 3765 | - * @return void |
|
| 3786 | + * @return Grocery_CRUD |
|
| 3766 | 3787 | */ |
| 3767 | 3788 | public function unset_export() |
| 3768 | 3789 | { |
@@ -3775,7 +3796,7 @@ discard block |
||
| 3775 | 3796 | /** |
| 3776 | 3797 | * Unsets the print button and functionality from the list |
| 3777 | 3798 | * |
| 3778 | - * @return void |
|
| 3799 | + * @return Grocery_CRUD |
|
| 3779 | 3800 | */ |
| 3780 | 3801 | public function unset_print() |
| 3781 | 3802 | { |
@@ -3787,7 +3808,7 @@ discard block |
||
| 3787 | 3808 | /** |
| 3788 | 3809 | * Unsets all the operations from the list |
| 3789 | 3810 | * |
| 3790 | - * @return void |
|
| 3811 | + * @return Grocery_CRUD |
|
| 3791 | 3812 | */ |
| 3792 | 3813 | public function unset_operations() |
| 3793 | 3814 | { |
@@ -3889,7 +3910,7 @@ discard block |
||
| 3889 | 3910 | /** |
| 3890 | 3911 | * Unsets everything that has to do with buttons or links with go back to list message |
| 3891 | 3912 | * @access public |
| 3892 | - * @return void |
|
| 3913 | + * @return Grocery_CRUD |
|
| 3893 | 3914 | */ |
| 3894 | 3915 | public function unset_back_to_list() |
| 3895 | 3916 | { |
@@ -3905,7 +3926,7 @@ discard block |
||
| 3905 | 3926 | * @access public |
| 3906 | 3927 | * @param string |
| 3907 | 3928 | * @param array |
| 3908 | - * @return void |
|
| 3929 | + * @return Grocery_CRUD |
|
| 3909 | 3930 | */ |
| 3910 | 3931 | public function fields() |
| 3911 | 3932 | { |
@@ -3974,9 +3995,9 @@ discard block |
||
| 3974 | 3995 | /** |
| 3975 | 3996 | * |
| 3976 | 3997 | * Changes the displaying label of the field |
| 3977 | - * @param $field_name |
|
| 3978 | - * @param $display_as |
|
| 3979 | - * @return void |
|
| 3998 | + * @param string $field_name |
|
| 3999 | + * @param string $display_as |
|
| 4000 | + * @return Grocery_CRUD |
|
| 3980 | 4001 | */ |
| 3981 | 4002 | public function display_as($field_name, $display_as = null) |
| 3982 | 4003 | { |
@@ -4048,7 +4069,7 @@ discard block |
||
| 4048 | 4069 | * |
| 4049 | 4070 | * Set a language string directly |
| 4050 | 4071 | * @param string $handle |
| 4051 | - * @param string $string |
|
| 4072 | + * @param string $lang_string |
|
| 4052 | 4073 | */ |
| 4053 | 4074 | public function set_lang_string($handle, $lang_string){ |
| 4054 | 4075 | $this->lang_strings[$handle] = $lang_string; |
@@ -5157,7 +5178,6 @@ discard block |
||
| 5157 | 5178 | * Transform a field to an upload field |
| 5158 | 5179 | * |
| 5159 | 5180 | * @param string $field_name |
| 5160 | - * @param string $upload_path |
|
| 5161 | 5181 | * @return Grocery_CRUD |
| 5162 | 5182 | */ |
| 5163 | 5183 | public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
@@ -5273,6 +5293,9 @@ discard block |
||
| 5273 | 5293 | substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
| 5274 | 5294 | } |
| 5275 | 5295 | |
| 5296 | + /** |
|
| 5297 | + * @param string $file_name |
|
| 5298 | + */ |
|
| 5276 | 5299 | private function get_file_object($file_name) { |
| 5277 | 5300 | $file_path = $this->options['upload_dir'].$file_name; |
| 5278 | 5301 | if (is_file($file_path) && $file_name[0] !== '.') { |
@@ -5301,6 +5324,9 @@ discard block |
||
| 5301 | 5324 | ))); |
| 5302 | 5325 | } |
| 5303 | 5326 | |
| 5327 | + /** |
|
| 5328 | + * @param string $file_name |
|
| 5329 | + */ |
|
| 5304 | 5330 | private function create_scaled_image($file_name, $options) { |
| 5305 | 5331 | $file_path = $this->options['upload_dir'].$file_name; |
| 5306 | 5332 | $new_file_path = $options['upload_dir'].$file_name; |
@@ -5354,6 +5380,9 @@ discard block |
||
| 5354 | 5380 | return $success; |
| 5355 | 5381 | } |
| 5356 | 5382 | |
| 5383 | + /** |
|
| 5384 | + * @param stdClass $file |
|
| 5385 | + */ |
|
| 5357 | 5386 | private function has_error($uploaded_file, $file, $error) { |
| 5358 | 5387 | if ($error) { |
| 5359 | 5388 | switch($error) { |
@@ -5424,6 +5453,9 @@ discard block |
||
| 5424 | 5453 | return $file_name; |
| 5425 | 5454 | } |
| 5426 | 5455 | |
| 5456 | + /** |
|
| 5457 | + * @param string $file_name |
|
| 5458 | + */ |
|
| 5427 | 5459 | private function _transliterate_characters($file_name) |
| 5428 | 5460 | { |
| 5429 | 5461 | include($this->default_config_path.'/translit_chars.php'); |
@@ -5438,6 +5470,9 @@ discard block |
||
| 5438 | 5470 | return preg_replace('/\-+/', '-', trim($file_name, '-')); |
| 5439 | 5471 | } |
| 5440 | 5472 | |
| 5473 | + /** |
|
| 5474 | + * @param string $file_path |
|
| 5475 | + */ |
|
| 5441 | 5476 | private function orient_image($file_path) { |
| 5442 | 5477 | $exif = exif_read_data($file_path); |
| 5443 | 5478 | $orientation = intval(@$exif['Orientation']); |
@@ -34,429 +34,429 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | class grocery_CRUD_Field_Types |
| 36 | 36 | { |
| 37 | - /** |
|
| 38 | - * Gets the field types of the main table. |
|
| 39 | - * @return array |
|
| 40 | - */ |
|
| 41 | - public function get_field_types() |
|
| 42 | - { |
|
| 43 | - if ($this->field_types !== null) { |
|
| 44 | - return $this->field_types; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $types = array(); |
|
| 48 | - foreach($this->basic_model->get_field_types_basic_table() as $field_info) |
|
| 49 | - { |
|
| 50 | - $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; |
|
| 51 | - |
|
| 52 | - $field_info->display_as = |
|
| 53 | - isset($this->display_as[$field_info->name]) ? |
|
| 54 | - $this->display_as[$field_info->name] : |
|
| 55 | - ucfirst(str_replace("_"," ",$field_info->name)); |
|
| 56 | - |
|
| 57 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
| 58 | - { |
|
| 59 | - $field_type = $this->change_field_type[$field_info->name]; |
|
| 60 | - |
|
| 61 | - if (isset($this->relation[$field_info->name])) { |
|
| 62 | - $field_info->crud_type = "relation_".$field_type->type; |
|
| 63 | - } |
|
| 64 | - elseif (isset($this->upload_fields[$field_info->name])) { |
|
| 65 | - $field_info->crud_type = "upload_file_".$field_type->type; |
|
| 66 | - } else { |
|
| 67 | - $field_info->crud_type = $field_type->type; |
|
| 68 | - $field_info->extras = $field_type->extras; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $real_type = $field_info->crud_type; |
|
| 72 | - } |
|
| 73 | - elseif(isset($this->relation[$field_info->name])) |
|
| 74 | - { |
|
| 75 | - $real_type = 'relation'; |
|
| 76 | - $field_info->crud_type = 'relation'; |
|
| 77 | - } |
|
| 78 | - elseif(isset($this->upload_fields[$field_info->name])) |
|
| 79 | - { |
|
| 80 | - $real_type = 'upload_file'; |
|
| 81 | - $field_info->crud_type = 'upload_file'; |
|
| 82 | - } |
|
| 83 | - else |
|
| 84 | - { |
|
| 85 | - $real_type = $this->get_type($field_info); |
|
| 86 | - $field_info->crud_type = $real_type; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - switch ($real_type) { |
|
| 90 | - case 'text': |
|
| 91 | - if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
| 92 | - $field_info->extras = false; |
|
| 93 | - else |
|
| 94 | - $field_info->extras = 'text_editor'; |
|
| 95 | - break; |
|
| 96 | - |
|
| 97 | - case 'relation': |
|
| 98 | - case 'relation_readonly': |
|
| 99 | - $field_info->extras = $this->relation[$field_info->name]; |
|
| 100 | - break; |
|
| 101 | - |
|
| 102 | - case 'upload_file': |
|
| 103 | - case 'upload_file_readonly': |
|
| 104 | - $field_info->extras = $this->upload_fields[$field_info->name]; |
|
| 105 | - break; |
|
| 106 | - |
|
| 107 | - default: |
|
| 108 | - if(empty($field_info->extras)) |
|
| 109 | - $field_info->extras = false; |
|
| 110 | - break; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $types[$field_info->name] = $field_info; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if(!empty($this->relation_n_n)) |
|
| 117 | - { |
|
| 118 | - foreach($this->relation_n_n as $field_name => $field_extras) |
|
| 119 | - { |
|
| 120 | - $is_read_only = $this->change_field_type !== null |
|
| 121 | - && isset($this->change_field_type[$field_name]) |
|
| 122 | - && $this->change_field_type[$field_name]->type == 'readonly' |
|
| 123 | - ? true : false; |
|
| 124 | - $field_info = (object)array(); |
|
| 125 | - $field_info->name = $field_name; |
|
| 126 | - $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; |
|
| 127 | - $field_info->extras = $field_extras; |
|
| 128 | - $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; |
|
| 129 | - $field_info->display_as = |
|
| 130 | - isset($this->display_as[$field_name]) ? |
|
| 131 | - $this->display_as[$field_name] : |
|
| 132 | - ucfirst(str_replace("_"," ",$field_name)); |
|
| 133 | - |
|
| 134 | - $types[$field_name] = $field_info; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if(!empty($this->add_fields)) |
|
| 139 | - foreach($this->add_fields as $field_object) |
|
| 140 | - { |
|
| 141 | - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
| 142 | - |
|
| 143 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 144 | - { |
|
| 145 | - $extras = false; |
|
| 146 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 147 | - { |
|
| 148 | - $field_type = $this->change_field_type[$field_name]; |
|
| 149 | - $extras = $field_type->extras; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $field_info = (object)array( |
|
| 153 | - 'name' => $field_name, |
|
| 154 | - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
| 155 | - $this->change_field_type[$field_name]->type : |
|
| 156 | - 'string', |
|
| 157 | - 'display_as' => isset($this->display_as[$field_name]) ? |
|
| 158 | - $this->display_as[$field_name] : |
|
| 159 | - ucfirst(str_replace("_"," ",$field_name)), |
|
| 160 | - 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, |
|
| 161 | - 'extras' => $extras |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - $types[$field_name] = $field_info; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if(!empty($this->edit_fields)) |
|
| 169 | - foreach($this->edit_fields as $field_object) |
|
| 170 | - { |
|
| 171 | - $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
| 172 | - |
|
| 173 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 174 | - { |
|
| 175 | - $extras = false; |
|
| 176 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 177 | - { |
|
| 178 | - $field_type = $this->change_field_type[$field_name]; |
|
| 179 | - $extras = $field_type->extras; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $field_info = (object)array( |
|
| 183 | - 'name' => $field_name, |
|
| 184 | - 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
| 185 | - $this->change_field_type[$field_name]->type : |
|
| 186 | - 'string', |
|
| 187 | - 'display_as' => isset($this->display_as[$field_name]) ? |
|
| 188 | - $this->display_as[$field_name] : |
|
| 189 | - ucfirst(str_replace("_"," ",$field_name)), |
|
| 190 | - 'required' => in_array($field_name,$this->required_fields) ? true : false, |
|
| 191 | - 'extras' => $extras |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - $types[$field_name] = $field_info; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $this->field_types = $types; |
|
| 199 | - |
|
| 200 | - return $this->field_types; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public function get_primary_key() |
|
| 204 | - { |
|
| 205 | - return $this->basic_model->get_primary_key(); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get the html input for the specific field with the |
|
| 210 | - * current value |
|
| 211 | - * |
|
| 212 | - * @param object $field_info |
|
| 213 | - * @param string $value |
|
| 214 | - * @return object |
|
| 215 | - */ |
|
| 216 | - protected function get_field_input($field_info, $value = null) |
|
| 217 | - { |
|
| 218 | - $real_type = $field_info->crud_type; |
|
| 219 | - |
|
| 220 | - $types_array = array( |
|
| 221 | - 'integer', |
|
| 222 | - 'text', |
|
| 223 | - 'true_false', |
|
| 224 | - 'string', |
|
| 225 | - 'date', |
|
| 226 | - 'datetime', |
|
| 227 | - 'enum', |
|
| 228 | - 'set', |
|
| 229 | - 'relation', |
|
| 230 | - 'relation_readonly', |
|
| 231 | - 'relation_n_n', |
|
| 232 | - 'upload_file', |
|
| 233 | - 'upload_file_readonly', |
|
| 234 | - 'hidden', |
|
| 235 | - 'password', |
|
| 236 | - 'readonly', |
|
| 237 | - 'dropdown', |
|
| 238 | - 'multiselect' |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - if (in_array($real_type,$types_array)) { |
|
| 242 | - /* A quick way to go to an internal method of type $this->get_{type}_input . |
|
| 37 | + /** |
|
| 38 | + * Gets the field types of the main table. |
|
| 39 | + * @return array |
|
| 40 | + */ |
|
| 41 | + public function get_field_types() |
|
| 42 | + { |
|
| 43 | + if ($this->field_types !== null) { |
|
| 44 | + return $this->field_types; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $types = array(); |
|
| 48 | + foreach($this->basic_model->get_field_types_basic_table() as $field_info) |
|
| 49 | + { |
|
| 50 | + $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; |
|
| 51 | + |
|
| 52 | + $field_info->display_as = |
|
| 53 | + isset($this->display_as[$field_info->name]) ? |
|
| 54 | + $this->display_as[$field_info->name] : |
|
| 55 | + ucfirst(str_replace("_"," ",$field_info->name)); |
|
| 56 | + |
|
| 57 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
| 58 | + { |
|
| 59 | + $field_type = $this->change_field_type[$field_info->name]; |
|
| 60 | + |
|
| 61 | + if (isset($this->relation[$field_info->name])) { |
|
| 62 | + $field_info->crud_type = "relation_".$field_type->type; |
|
| 63 | + } |
|
| 64 | + elseif (isset($this->upload_fields[$field_info->name])) { |
|
| 65 | + $field_info->crud_type = "upload_file_".$field_type->type; |
|
| 66 | + } else { |
|
| 67 | + $field_info->crud_type = $field_type->type; |
|
| 68 | + $field_info->extras = $field_type->extras; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $real_type = $field_info->crud_type; |
|
| 72 | + } |
|
| 73 | + elseif(isset($this->relation[$field_info->name])) |
|
| 74 | + { |
|
| 75 | + $real_type = 'relation'; |
|
| 76 | + $field_info->crud_type = 'relation'; |
|
| 77 | + } |
|
| 78 | + elseif(isset($this->upload_fields[$field_info->name])) |
|
| 79 | + { |
|
| 80 | + $real_type = 'upload_file'; |
|
| 81 | + $field_info->crud_type = 'upload_file'; |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 85 | + $real_type = $this->get_type($field_info); |
|
| 86 | + $field_info->crud_type = $real_type; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + switch ($real_type) { |
|
| 90 | + case 'text': |
|
| 91 | + if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
| 92 | + $field_info->extras = false; |
|
| 93 | + else |
|
| 94 | + $field_info->extras = 'text_editor'; |
|
| 95 | + break; |
|
| 96 | + |
|
| 97 | + case 'relation': |
|
| 98 | + case 'relation_readonly': |
|
| 99 | + $field_info->extras = $this->relation[$field_info->name]; |
|
| 100 | + break; |
|
| 101 | + |
|
| 102 | + case 'upload_file': |
|
| 103 | + case 'upload_file_readonly': |
|
| 104 | + $field_info->extras = $this->upload_fields[$field_info->name]; |
|
| 105 | + break; |
|
| 106 | + |
|
| 107 | + default: |
|
| 108 | + if(empty($field_info->extras)) |
|
| 109 | + $field_info->extras = false; |
|
| 110 | + break; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $types[$field_info->name] = $field_info; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if(!empty($this->relation_n_n)) |
|
| 117 | + { |
|
| 118 | + foreach($this->relation_n_n as $field_name => $field_extras) |
|
| 119 | + { |
|
| 120 | + $is_read_only = $this->change_field_type !== null |
|
| 121 | + && isset($this->change_field_type[$field_name]) |
|
| 122 | + && $this->change_field_type[$field_name]->type == 'readonly' |
|
| 123 | + ? true : false; |
|
| 124 | + $field_info = (object)array(); |
|
| 125 | + $field_info->name = $field_name; |
|
| 126 | + $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; |
|
| 127 | + $field_info->extras = $field_extras; |
|
| 128 | + $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; |
|
| 129 | + $field_info->display_as = |
|
| 130 | + isset($this->display_as[$field_name]) ? |
|
| 131 | + $this->display_as[$field_name] : |
|
| 132 | + ucfirst(str_replace("_"," ",$field_name)); |
|
| 133 | + |
|
| 134 | + $types[$field_name] = $field_info; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if(!empty($this->add_fields)) |
|
| 139 | + foreach($this->add_fields as $field_object) |
|
| 140 | + { |
|
| 141 | + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
| 142 | + |
|
| 143 | + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 144 | + { |
|
| 145 | + $extras = false; |
|
| 146 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 147 | + { |
|
| 148 | + $field_type = $this->change_field_type[$field_name]; |
|
| 149 | + $extras = $field_type->extras; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $field_info = (object)array( |
|
| 153 | + 'name' => $field_name, |
|
| 154 | + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
| 155 | + $this->change_field_type[$field_name]->type : |
|
| 156 | + 'string', |
|
| 157 | + 'display_as' => isset($this->display_as[$field_name]) ? |
|
| 158 | + $this->display_as[$field_name] : |
|
| 159 | + ucfirst(str_replace("_"," ",$field_name)), |
|
| 160 | + 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, |
|
| 161 | + 'extras' => $extras |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + $types[$field_name] = $field_info; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if(!empty($this->edit_fields)) |
|
| 169 | + foreach($this->edit_fields as $field_object) |
|
| 170 | + { |
|
| 171 | + $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
|
| 172 | + |
|
| 173 | + if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 174 | + { |
|
| 175 | + $extras = false; |
|
| 176 | + if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 177 | + { |
|
| 178 | + $field_type = $this->change_field_type[$field_name]; |
|
| 179 | + $extras = $field_type->extras; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $field_info = (object)array( |
|
| 183 | + 'name' => $field_name, |
|
| 184 | + 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
|
| 185 | + $this->change_field_type[$field_name]->type : |
|
| 186 | + 'string', |
|
| 187 | + 'display_as' => isset($this->display_as[$field_name]) ? |
|
| 188 | + $this->display_as[$field_name] : |
|
| 189 | + ucfirst(str_replace("_"," ",$field_name)), |
|
| 190 | + 'required' => in_array($field_name,$this->required_fields) ? true : false, |
|
| 191 | + 'extras' => $extras |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + $types[$field_name] = $field_info; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $this->field_types = $types; |
|
| 199 | + |
|
| 200 | + return $this->field_types; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public function get_primary_key() |
|
| 204 | + { |
|
| 205 | + return $this->basic_model->get_primary_key(); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get the html input for the specific field with the |
|
| 210 | + * current value |
|
| 211 | + * |
|
| 212 | + * @param object $field_info |
|
| 213 | + * @param string $value |
|
| 214 | + * @return object |
|
| 215 | + */ |
|
| 216 | + protected function get_field_input($field_info, $value = null) |
|
| 217 | + { |
|
| 218 | + $real_type = $field_info->crud_type; |
|
| 219 | + |
|
| 220 | + $types_array = array( |
|
| 221 | + 'integer', |
|
| 222 | + 'text', |
|
| 223 | + 'true_false', |
|
| 224 | + 'string', |
|
| 225 | + 'date', |
|
| 226 | + 'datetime', |
|
| 227 | + 'enum', |
|
| 228 | + 'set', |
|
| 229 | + 'relation', |
|
| 230 | + 'relation_readonly', |
|
| 231 | + 'relation_n_n', |
|
| 232 | + 'upload_file', |
|
| 233 | + 'upload_file_readonly', |
|
| 234 | + 'hidden', |
|
| 235 | + 'password', |
|
| 236 | + 'readonly', |
|
| 237 | + 'dropdown', |
|
| 238 | + 'multiselect' |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + if (in_array($real_type,$types_array)) { |
|
| 242 | + /* A quick way to go to an internal method of type $this->get_{type}_input . |
|
| 243 | 243 | * For example if the real type is integer then we will use the method |
| 244 | 244 | * $this->get_integer_input |
| 245 | 245 | * */ |
| 246 | - $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
|
| 247 | - } |
|
| 248 | - else |
|
| 249 | - { |
|
| 250 | - $field_info->input = $this->get_string_input($field_info,$value); |
|
| 251 | - } |
|
| 246 | + $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
|
| 247 | + } |
|
| 248 | + else |
|
| 249 | + { |
|
| 250 | + $field_info->input = $this->get_string_input($field_info,$value); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - return $field_info; |
|
| 254 | - } |
|
| 253 | + return $field_info; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - protected function change_list_value($field_info, $value = null) |
|
| 257 | - { |
|
| 258 | - $real_type = $field_info->crud_type; |
|
| 256 | + protected function change_list_value($field_info, $value = null) |
|
| 257 | + { |
|
| 258 | + $real_type = $field_info->crud_type; |
|
| 259 | + |
|
| 260 | + switch ($real_type) { |
|
| 261 | + case 'hidden': |
|
| 262 | + case 'invisible': |
|
| 263 | + case 'integer': |
|
| 264 | + |
|
| 265 | + break; |
|
| 266 | + case 'true_false': |
|
| 267 | + if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { |
|
| 268 | + $value = $field_info->extras[$value]; |
|
| 269 | + } else if(isset($this->default_true_false_text[$value])) { |
|
| 270 | + $value = $this->default_true_false_text[$value]; |
|
| 271 | + } |
|
| 272 | + break; |
|
| 273 | + case 'string': |
|
| 274 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 275 | + break; |
|
| 276 | + case 'text': |
|
| 277 | + $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); |
|
| 278 | + break; |
|
| 279 | + case 'date': |
|
| 280 | + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 281 | + { |
|
| 282 | + list($year,$month,$day) = explode("-",$value); |
|
| 259 | 283 | |
| 260 | - switch ($real_type) { |
|
| 261 | - case 'hidden': |
|
| 262 | - case 'invisible': |
|
| 263 | - case 'integer': |
|
| 284 | + $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
|
| 285 | + } |
|
| 286 | + else |
|
| 287 | + { |
|
| 288 | + $value = ''; |
|
| 289 | + } |
|
| 290 | + break; |
|
| 291 | + case 'datetime': |
|
| 292 | + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
| 293 | + { |
|
| 294 | + list($year,$month,$day) = explode("-",$value); |
|
| 295 | + list($hours,$minutes) = explode(":",substr($value,11)); |
|
| 264 | 296 | |
| 265 | - break; |
|
| 266 | - case 'true_false': |
|
| 267 | - if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { |
|
| 268 | - $value = $field_info->extras[$value]; |
|
| 269 | - } else if(isset($this->default_true_false_text[$value])) { |
|
| 270 | - $value = $this->default_true_false_text[$value]; |
|
| 271 | - } |
|
| 272 | - break; |
|
| 273 | - case 'string': |
|
| 274 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 275 | - break; |
|
| 276 | - case 'text': |
|
| 277 | - $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); |
|
| 278 | - break; |
|
| 279 | - case 'date': |
|
| 280 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 281 | - { |
|
| 282 | - list($year,$month,$day) = explode("-",$value); |
|
| 283 | - |
|
| 284 | - $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
|
| 285 | - } |
|
| 286 | - else |
|
| 287 | - { |
|
| 288 | - $value = ''; |
|
| 289 | - } |
|
| 290 | - break; |
|
| 291 | - case 'datetime': |
|
| 292 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
| 293 | - { |
|
| 294 | - list($year,$month,$day) = explode("-",$value); |
|
| 295 | - list($hours,$minutes) = explode(":",substr($value,11)); |
|
| 296 | - |
|
| 297 | - $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
|
| 298 | - } |
|
| 299 | - else |
|
| 300 | - { |
|
| 301 | - $value = ''; |
|
| 302 | - } |
|
| 303 | - break; |
|
| 304 | - case 'enum': |
|
| 305 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 306 | - break; |
|
| 297 | + $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
|
| 298 | + } |
|
| 299 | + else |
|
| 300 | + { |
|
| 301 | + $value = ''; |
|
| 302 | + } |
|
| 303 | + break; |
|
| 304 | + case 'enum': |
|
| 305 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 306 | + break; |
|
| 307 | + |
|
| 308 | + case 'multiselect': |
|
| 309 | + $value_as_array = array(); |
|
| 310 | + foreach(explode(",",$value) as $row_value) |
|
| 311 | + { |
|
| 312 | + $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
| 313 | + } |
|
| 314 | + $value = implode(",",$value_as_array); |
|
| 315 | + break; |
|
| 307 | 316 | |
| 308 | - case 'multiselect': |
|
| 309 | - $value_as_array = array(); |
|
| 310 | - foreach(explode(",",$value) as $row_value) |
|
| 311 | - { |
|
| 312 | - $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
| 313 | - } |
|
| 314 | - $value = implode(",",$value_as_array); |
|
| 315 | - break; |
|
| 317 | + case 'relation_n_n': |
|
| 318 | + $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); |
|
| 319 | + break; |
|
| 316 | 320 | |
| 317 | - case 'relation_n_n': |
|
| 318 | - $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); |
|
| 319 | - break; |
|
| 321 | + case 'password': |
|
| 322 | + $value = '******'; |
|
| 323 | + break; |
|
| 320 | 324 | |
| 321 | - case 'password': |
|
| 322 | - $value = '******'; |
|
| 323 | - break; |
|
| 325 | + case 'dropdown': |
|
| 326 | + $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; |
|
| 327 | + break; |
|
| 324 | 328 | |
| 325 | - case 'dropdown': |
|
| 326 | - $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; |
|
| 327 | - break; |
|
| 329 | + case 'upload_file': |
|
| 330 | + if(empty($value)) |
|
| 331 | + { |
|
| 332 | + $value = ""; |
|
| 333 | + } |
|
| 334 | + else |
|
| 335 | + { |
|
| 336 | + $is_image = !empty($value) && |
|
| 337 | + ( substr($value,-4) == '.jpg' |
|
| 338 | + || substr($value,-4) == '.png' |
|
| 339 | + || substr($value,-5) == '.jpeg' |
|
| 340 | + || substr($value,-4) == '.gif' |
|
| 341 | + || substr($value,-5) == '.tiff') |
|
| 342 | + ? true : false; |
|
| 343 | + |
|
| 344 | + $file_url = base_url().$field_info->extras->upload_path."/$value"; |
|
| 345 | + |
|
| 346 | + $file_url_anchor = '<a href="'.$file_url.'"'; |
|
| 347 | + if($is_image) |
|
| 348 | + { |
|
| 349 | + $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
|
| 350 | + } |
|
| 351 | + else |
|
| 352 | + { |
|
| 353 | + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
|
| 354 | + } |
|
| 355 | + $file_url_anchor .= '</a>'; |
|
| 328 | 356 | |
| 329 | - case 'upload_file': |
|
| 330 | - if(empty($value)) |
|
| 331 | - { |
|
| 332 | - $value = ""; |
|
| 333 | - } |
|
| 334 | - else |
|
| 335 | - { |
|
| 336 | - $is_image = !empty($value) && |
|
| 337 | - ( substr($value,-4) == '.jpg' |
|
| 338 | - || substr($value,-4) == '.png' |
|
| 339 | - || substr($value,-5) == '.jpeg' |
|
| 340 | - || substr($value,-4) == '.gif' |
|
| 341 | - || substr($value,-5) == '.tiff') |
|
| 342 | - ? true : false; |
|
| 343 | - |
|
| 344 | - $file_url = base_url().$field_info->extras->upload_path."/$value"; |
|
| 345 | - |
|
| 346 | - $file_url_anchor = '<a href="'.$file_url.'"'; |
|
| 347 | - if($is_image) |
|
| 348 | - { |
|
| 349 | - $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
|
| 350 | - } |
|
| 351 | - else |
|
| 352 | - { |
|
| 353 | - $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
|
| 354 | - } |
|
| 355 | - $file_url_anchor .= '</a>'; |
|
| 356 | - |
|
| 357 | - $value = $file_url_anchor; |
|
| 358 | - } |
|
| 359 | - break; |
|
| 357 | + $value = $file_url_anchor; |
|
| 358 | + } |
|
| 359 | + break; |
|
| 360 | 360 | |
| 361 | - default: |
|
| 362 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 363 | - break; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $value; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Character Limiter of codeigniter (I just don't want to load the helper ) |
|
| 371 | - * |
|
| 372 | - * Limits the string based on the character count. Preserves complete words |
|
| 373 | - * so the character count may not be exactly as specified. |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @param string |
|
| 377 | - * @param integer |
|
| 378 | - * @param string the end character. Usually an ellipsis |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - function character_limiter($str, $n = 500, $end_char = '…') |
|
| 382 | - { |
|
| 383 | - if (strlen($str) < $n) |
|
| 384 | - { |
|
| 385 | - return $str; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - // a bit complicated, but faster than preg_replace with \s+ |
|
| 389 | - $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); |
|
| 390 | - |
|
| 391 | - if (strlen($str) <= $n) |
|
| 392 | - { |
|
| 393 | - return $str; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $out = ''; |
|
| 397 | - foreach (explode(' ', trim($str)) as $val) |
|
| 398 | - { |
|
| 399 | - $out .= $val.' '; |
|
| 400 | - |
|
| 401 | - if (strlen($out) >= $n) |
|
| 402 | - { |
|
| 403 | - $out = trim($out); |
|
| 404 | - return (strlen($out) === strlen($str)) ? $out : $out.$end_char; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - protected function get_type($db_type) |
|
| 410 | - { |
|
| 411 | - $type = false; |
|
| 412 | - if(!empty($db_type->type)) |
|
| 413 | - { |
|
| 414 | - switch ($db_type->type) { |
|
| 415 | - case '1': |
|
| 416 | - case '3': |
|
| 417 | - case 'int': |
|
| 418 | - case 'tinyint': |
|
| 419 | - case 'mediumint': |
|
| 420 | - case 'longint': |
|
| 421 | - if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
| 422 | - $type = 'true_false'; |
|
| 423 | - else |
|
| 424 | - $type = 'integer'; |
|
| 425 | - break; |
|
| 426 | - case '254': |
|
| 427 | - case 'string': |
|
| 428 | - case 'enum': |
|
| 429 | - if($db_type->db_type != 'enum') |
|
| 430 | - $type = 'string'; |
|
| 431 | - else |
|
| 432 | - $type = 'enum'; |
|
| 433 | - break; |
|
| 434 | - case 'set': |
|
| 435 | - if($db_type->db_type != 'set') |
|
| 436 | - $type = 'string'; |
|
| 437 | - else |
|
| 438 | - $type = 'set'; |
|
| 439 | - break; |
|
| 440 | - case '252': |
|
| 441 | - case 'blob': |
|
| 442 | - case 'text': |
|
| 443 | - case 'mediumtext': |
|
| 444 | - case 'longtext': |
|
| 445 | - $type = 'text'; |
|
| 446 | - break; |
|
| 447 | - case '10': |
|
| 448 | - case 'date': |
|
| 449 | - $type = 'date'; |
|
| 450 | - break; |
|
| 451 | - case '12': |
|
| 452 | - case 'datetime': |
|
| 453 | - case 'timestamp': |
|
| 454 | - $type = 'datetime'; |
|
| 455 | - break; |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - return $type; |
|
| 459 | - } |
|
| 361 | + default: |
|
| 362 | + $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 363 | + break; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $value; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Character Limiter of codeigniter (I just don't want to load the helper ) |
|
| 371 | + * |
|
| 372 | + * Limits the string based on the character count. Preserves complete words |
|
| 373 | + * so the character count may not be exactly as specified. |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @param string |
|
| 377 | + * @param integer |
|
| 378 | + * @param string the end character. Usually an ellipsis |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + function character_limiter($str, $n = 500, $end_char = '…') |
|
| 382 | + { |
|
| 383 | + if (strlen($str) < $n) |
|
| 384 | + { |
|
| 385 | + return $str; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + // a bit complicated, but faster than preg_replace with \s+ |
|
| 389 | + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); |
|
| 390 | + |
|
| 391 | + if (strlen($str) <= $n) |
|
| 392 | + { |
|
| 393 | + return $str; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $out = ''; |
|
| 397 | + foreach (explode(' ', trim($str)) as $val) |
|
| 398 | + { |
|
| 399 | + $out .= $val.' '; |
|
| 400 | + |
|
| 401 | + if (strlen($out) >= $n) |
|
| 402 | + { |
|
| 403 | + $out = trim($out); |
|
| 404 | + return (strlen($out) === strlen($str)) ? $out : $out.$end_char; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + protected function get_type($db_type) |
|
| 410 | + { |
|
| 411 | + $type = false; |
|
| 412 | + if(!empty($db_type->type)) |
|
| 413 | + { |
|
| 414 | + switch ($db_type->type) { |
|
| 415 | + case '1': |
|
| 416 | + case '3': |
|
| 417 | + case 'int': |
|
| 418 | + case 'tinyint': |
|
| 419 | + case 'mediumint': |
|
| 420 | + case 'longint': |
|
| 421 | + if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
| 422 | + $type = 'true_false'; |
|
| 423 | + else |
|
| 424 | + $type = 'integer'; |
|
| 425 | + break; |
|
| 426 | + case '254': |
|
| 427 | + case 'string': |
|
| 428 | + case 'enum': |
|
| 429 | + if($db_type->db_type != 'enum') |
|
| 430 | + $type = 'string'; |
|
| 431 | + else |
|
| 432 | + $type = 'enum'; |
|
| 433 | + break; |
|
| 434 | + case 'set': |
|
| 435 | + if($db_type->db_type != 'set') |
|
| 436 | + $type = 'string'; |
|
| 437 | + else |
|
| 438 | + $type = 'set'; |
|
| 439 | + break; |
|
| 440 | + case '252': |
|
| 441 | + case 'blob': |
|
| 442 | + case 'text': |
|
| 443 | + case 'mediumtext': |
|
| 444 | + case 'longtext': |
|
| 445 | + $type = 'text'; |
|
| 446 | + break; |
|
| 447 | + case '10': |
|
| 448 | + case 'date': |
|
| 449 | + $type = 'date'; |
|
| 450 | + break; |
|
| 451 | + case '12': |
|
| 452 | + case 'datetime': |
|
| 453 | + case 'timestamp': |
|
| 454 | + $type = 'datetime'; |
|
| 455 | + break; |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + return $type; |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // ------------------------------------------------------------------------ |
@@ -473,107 +473,107 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types |
| 475 | 475 | { |
| 476 | - /** |
|
| 477 | - * @var Grocery_crud_model |
|
| 478 | - */ |
|
| 479 | - public $basic_model = null; |
|
| 480 | - |
|
| 481 | - protected function set_default_Model() |
|
| 482 | - { |
|
| 483 | - $ci = &get_instance(); |
|
| 484 | - $ci->load->model('Grocery_crud_model'); |
|
| 485 | - |
|
| 486 | - $this->basic_model = new Grocery_crud_model(); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - protected function get_total_results() |
|
| 490 | - { |
|
| 491 | - if(!empty($this->where)) |
|
| 492 | - foreach($this->where as $where) |
|
| 493 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 494 | - |
|
| 495 | - if(!empty($this->or_where)) |
|
| 496 | - foreach($this->or_where as $or_where) |
|
| 497 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 498 | - |
|
| 499 | - if(!empty($this->like)) |
|
| 500 | - foreach($this->like as $like) |
|
| 501 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 502 | - |
|
| 503 | - if(!empty($this->or_like)) |
|
| 504 | - foreach($this->or_like as $or_like) |
|
| 505 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 506 | - |
|
| 507 | - if(!empty($this->having)) |
|
| 508 | - foreach($this->having as $having) |
|
| 509 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 510 | - |
|
| 511 | - if(!empty($this->or_having)) |
|
| 512 | - foreach($this->or_having as $or_having) |
|
| 513 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 514 | - |
|
| 515 | - if(!empty($this->relation)) |
|
| 516 | - foreach($this->relation as $relation) |
|
| 517 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 518 | - |
|
| 519 | - if(!empty($this->relation_n_n)) |
|
| 520 | - { |
|
| 521 | - $columns = $this->get_columns(); |
|
| 522 | - foreach($columns as $column) |
|
| 523 | - { |
|
| 524 | - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
| 525 | - if(isset($this->relation_n_n[$column->field_name])) |
|
| 526 | - { |
|
| 527 | - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return $this->basic_model->get_total_results(); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - public function set_model($model_name) |
|
| 537 | - { |
|
| 538 | - $ci = &get_instance(); |
|
| 539 | - $ci->load->model('Grocery_crud_model'); |
|
| 540 | - |
|
| 541 | - $ci->load->model($model_name); |
|
| 542 | - |
|
| 543 | - $temp = explode('/',$model_name); |
|
| 544 | - krsort($temp); |
|
| 545 | - foreach($temp as $t) |
|
| 546 | - { |
|
| 547 | - $real_model_name = $t; |
|
| 548 | - break; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - $this->basic_model = $ci->$real_model_name; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - protected function set_ajax_list_queries($state_info = null) |
|
| 555 | - { |
|
| 556 | - if(!empty($state_info->per_page)) |
|
| 557 | - { |
|
| 558 | - if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
| 559 | - $this->limit($state_info->per_page); |
|
| 560 | - else |
|
| 561 | - { |
|
| 562 | - $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
|
| 563 | - $this->limit($state_info->per_page, $limit_page); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - if(!empty($state_info->order_by)) |
|
| 568 | - { |
|
| 569 | - $this->order_by($state_info->order_by[0],$state_info->order_by[1]); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - if(!empty($state_info->search)) |
|
| 573 | - { |
|
| 574 | - if (!empty($this->relation)) { |
|
| 575 | - foreach ($this->relation as $relation_name => $relation_values) { |
|
| 576 | - $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); |
|
| 476 | + /** |
|
| 477 | + * @var Grocery_crud_model |
|
| 478 | + */ |
|
| 479 | + public $basic_model = null; |
|
| 480 | + |
|
| 481 | + protected function set_default_Model() |
|
| 482 | + { |
|
| 483 | + $ci = &get_instance(); |
|
| 484 | + $ci->load->model('Grocery_crud_model'); |
|
| 485 | + |
|
| 486 | + $this->basic_model = new Grocery_crud_model(); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + protected function get_total_results() |
|
| 490 | + { |
|
| 491 | + if(!empty($this->where)) |
|
| 492 | + foreach($this->where as $where) |
|
| 493 | + $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 494 | + |
|
| 495 | + if(!empty($this->or_where)) |
|
| 496 | + foreach($this->or_where as $or_where) |
|
| 497 | + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 498 | + |
|
| 499 | + if(!empty($this->like)) |
|
| 500 | + foreach($this->like as $like) |
|
| 501 | + $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 502 | + |
|
| 503 | + if(!empty($this->or_like)) |
|
| 504 | + foreach($this->or_like as $or_like) |
|
| 505 | + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 506 | + |
|
| 507 | + if(!empty($this->having)) |
|
| 508 | + foreach($this->having as $having) |
|
| 509 | + $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 510 | + |
|
| 511 | + if(!empty($this->or_having)) |
|
| 512 | + foreach($this->or_having as $or_having) |
|
| 513 | + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 514 | + |
|
| 515 | + if(!empty($this->relation)) |
|
| 516 | + foreach($this->relation as $relation) |
|
| 517 | + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 518 | + |
|
| 519 | + if(!empty($this->relation_n_n)) |
|
| 520 | + { |
|
| 521 | + $columns = $this->get_columns(); |
|
| 522 | + foreach($columns as $column) |
|
| 523 | + { |
|
| 524 | + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
| 525 | + if(isset($this->relation_n_n[$column->field_name])) |
|
| 526 | + { |
|
| 527 | + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return $this->basic_model->get_total_results(); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + public function set_model($model_name) |
|
| 537 | + { |
|
| 538 | + $ci = &get_instance(); |
|
| 539 | + $ci->load->model('Grocery_crud_model'); |
|
| 540 | + |
|
| 541 | + $ci->load->model($model_name); |
|
| 542 | + |
|
| 543 | + $temp = explode('/',$model_name); |
|
| 544 | + krsort($temp); |
|
| 545 | + foreach($temp as $t) |
|
| 546 | + { |
|
| 547 | + $real_model_name = $t; |
|
| 548 | + break; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + $this->basic_model = $ci->$real_model_name; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + protected function set_ajax_list_queries($state_info = null) |
|
| 555 | + { |
|
| 556 | + if(!empty($state_info->per_page)) |
|
| 557 | + { |
|
| 558 | + if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
| 559 | + $this->limit($state_info->per_page); |
|
| 560 | + else |
|
| 561 | + { |
|
| 562 | + $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
|
| 563 | + $this->limit($state_info->per_page, $limit_page); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + if(!empty($state_info->order_by)) |
|
| 568 | + { |
|
| 569 | + $this->order_by($state_info->order_by[0],$state_info->order_by[1]); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + if(!empty($state_info->search)) |
|
| 573 | + { |
|
| 574 | + if (!empty($this->relation)) { |
|
| 575 | + foreach ($this->relation as $relation_name => $relation_values) { |
|
| 576 | + $temp_relation[$this->_unique_field_name($relation_name)] = $this->_get_field_names_to_search($relation_values); |
|
| 577 | 577 | } |
| 578 | 578 | } |
| 579 | 579 | |
@@ -600,4036 +600,4036 @@ discard block |
||
| 600 | 600 | |
| 601 | 601 | } |
| 602 | 602 | } elseif ($state_info->search->field !== null) { |
| 603 | - if (isset($temp_relation[$state_info->search->field])) { |
|
| 604 | - if (is_array($temp_relation[$state_info->search->field])) { |
|
| 605 | - foreach ($temp_relation[$state_info->search->field] as $search_field) { |
|
| 606 | - $this->or_like($search_field , $state_info->search->text); |
|
| 603 | + if (isset($temp_relation[$state_info->search->field])) { |
|
| 604 | + if (is_array($temp_relation[$state_info->search->field])) { |
|
| 605 | + foreach ($temp_relation[$state_info->search->field] as $search_field) { |
|
| 606 | + $this->or_like($search_field , $state_info->search->text); |
|
| 607 | 607 | } |
| 608 | 608 | } else { |
| 609 | - $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); |
|
| 609 | + $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); |
|
| 610 | 610 | } |
| 611 | - } elseif(isset($this->relation_n_n[$state_info->search->field])) { |
|
| 612 | - $escaped_text = $this->basic_model->escape_str($state_info->search->text); |
|
| 613 | - $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); |
|
| 614 | - } else { |
|
| 615 | - $this->like($state_info->search->field , $state_info->search->text); |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - else |
|
| 619 | - { |
|
| 620 | - $columns = $this->get_columns(); |
|
| 621 | - |
|
| 622 | - $search_text = $state_info->search->text; |
|
| 623 | - |
|
| 624 | - if(!empty($this->where)) |
|
| 625 | - foreach($this->where as $where) |
|
| 626 | - $this->basic_model->having($where[0],$where[1],$where[2]); |
|
| 627 | - |
|
| 628 | - foreach($columns as $column) |
|
| 629 | - { |
|
| 630 | - if(isset($temp_relation[$column->field_name])) |
|
| 631 | - { |
|
| 632 | - if(is_array($temp_relation[$column->field_name])) |
|
| 633 | - { |
|
| 634 | - foreach($temp_relation[$column->field_name] as $search_field) |
|
| 635 | - { |
|
| 636 | - $this->or_like($search_field, $search_text); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - else |
|
| 640 | - { |
|
| 641 | - $this->or_like($temp_relation[$column->field_name], $search_text); |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - elseif(isset($this->relation_n_n[$column->field_name])) |
|
| 645 | - { |
|
| 646 | - //@todo have a where for the relation_n_n statement |
|
| 647 | - } |
|
| 648 | - else |
|
| 649 | - { |
|
| 650 | - $this->or_like($column->field_name, $search_text); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - protected function table_exists($table_name = null) |
|
| 658 | - { |
|
| 659 | - if($this->basic_model->db_table_exists($table_name)) |
|
| 660 | - return true; |
|
| 661 | - return false; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) |
|
| 665 | - { |
|
| 666 | - list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; |
|
| 667 | - |
|
| 668 | - if($primary_key_value !== null) |
|
| 669 | - { |
|
| 670 | - $primary_key = $this->basic_model->get_primary_key($related_table); |
|
| 671 | - |
|
| 672 | - //A where clause with the primary key is enough to take the selected key row |
|
| 673 | - $where_clause = array($primary_key => $primary_key_value); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); |
|
| 677 | - |
|
| 678 | - return $relation_array; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - protected function get_relation_total_rows($relation_info) |
|
| 682 | - { |
|
| 683 | - list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; |
|
| 684 | - |
|
| 685 | - $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); |
|
| 686 | - |
|
| 687 | - return $relation_array; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - protected function db_insert_validation() |
|
| 691 | - { |
|
| 692 | - $validation_result = (object)array('success'=>false); |
|
| 693 | - |
|
| 694 | - $field_types = $this->get_field_types(); |
|
| 695 | - $required_fields = $this->required_fields; |
|
| 696 | - $unique_fields = $this->_unique_fields; |
|
| 697 | - $add_fields = $this->get_add_fields(); |
|
| 698 | - |
|
| 699 | - if(!empty($required_fields)) |
|
| 700 | - { |
|
| 701 | - foreach($add_fields as $add_field) |
|
| 702 | - { |
|
| 703 | - $field_name = $add_field->field_name; |
|
| 704 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 705 | - { |
|
| 706 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** Checking for unique fields. If the field value is not unique then |
|
| 712 | - * return a validation error straight away, if not continue... */ |
|
| 713 | - if(!empty($unique_fields)) |
|
| 714 | - { |
|
| 715 | - $form_validation = $this->form_validation(); |
|
| 716 | - |
|
| 717 | - foreach($add_fields as $add_field) |
|
| 718 | - { |
|
| 719 | - $field_name = $add_field->field_name; |
|
| 720 | - if(in_array( $field_name, $unique_fields) ) |
|
| 721 | - { |
|
| 722 | - $form_validation->set_rules( $field_name, |
|
| 723 | - $field_types[$field_name]->display_as, |
|
| 724 | - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - if(!$form_validation->run()) |
|
| 729 | - { |
|
| 730 | - $validation_result->error_message = $form_validation->error_string(); |
|
| 731 | - $validation_result->error_fields = $form_validation->_error_array; |
|
| 732 | - |
|
| 733 | - return $validation_result; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - if(!empty($this->validation_rules)) |
|
| 738 | - { |
|
| 739 | - $form_validation = $this->form_validation(); |
|
| 740 | - |
|
| 741 | - $add_fields = $this->get_add_fields(); |
|
| 742 | - |
|
| 743 | - foreach($add_fields as $add_field) |
|
| 744 | - { |
|
| 745 | - $field_name = $add_field->field_name; |
|
| 746 | - if(isset($this->validation_rules[$field_name])) |
|
| 747 | - { |
|
| 748 | - $rule = $this->validation_rules[$field_name]; |
|
| 749 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 750 | - } |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - if($form_validation->run()) |
|
| 754 | - { |
|
| 755 | - $validation_result->success = true; |
|
| 756 | - } |
|
| 757 | - else |
|
| 758 | - { |
|
| 759 | - $validation_result->error_message = $form_validation->error_string(); |
|
| 760 | - $validation_result->error_fields = $form_validation->_error_array; |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - else |
|
| 764 | - { |
|
| 765 | - $validation_result->success = true; |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - return $validation_result; |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - protected function form_validation() |
|
| 772 | - { |
|
| 773 | - if($this->form_validation === null) |
|
| 774 | - { |
|
| 775 | - $this->form_validation = new grocery_CRUD_Form_validation(); |
|
| 776 | - $ci = &get_instance(); |
|
| 777 | - $ci->load->library('form_validation'); |
|
| 778 | - $ci->form_validation = $this->form_validation; |
|
| 779 | - } |
|
| 780 | - return $this->form_validation; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - protected function db_update_validation() |
|
| 784 | - { |
|
| 785 | - $validation_result = (object)array('success'=>false); |
|
| 786 | - |
|
| 787 | - $field_types = $this->get_field_types(); |
|
| 788 | - $required_fields = $this->required_fields; |
|
| 789 | - $unique_fields = $this->_unique_fields; |
|
| 790 | - $edit_fields = $this->get_edit_fields(); |
|
| 791 | - |
|
| 792 | - if(!empty($required_fields)) |
|
| 793 | - { |
|
| 794 | - foreach($edit_fields as $edit_field) |
|
| 795 | - { |
|
| 796 | - $field_name = $edit_field->field_name; |
|
| 797 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 798 | - { |
|
| 799 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** Checking for unique fields. If the field value is not unique then |
|
| 806 | - * return a validation error straight away, if not continue... */ |
|
| 807 | - if(!empty($unique_fields)) |
|
| 808 | - { |
|
| 809 | - $form_validation = $this->form_validation(); |
|
| 810 | - |
|
| 811 | - $form_validation_check = false; |
|
| 812 | - |
|
| 813 | - foreach($edit_fields as $edit_field) |
|
| 814 | - { |
|
| 815 | - $field_name = $edit_field->field_name; |
|
| 816 | - if(in_array( $field_name, $unique_fields) ) |
|
| 817 | - { |
|
| 818 | - $state_info = $this->getStateInfo(); |
|
| 819 | - $primary_key = $this->get_primary_key(); |
|
| 820 | - $field_name_value = $_POST[$field_name]; |
|
| 821 | - |
|
| 822 | - $this->basic_model->where($primary_key,$state_info->primary_key); |
|
| 823 | - $row = $this->basic_model->get_row(); |
|
| 824 | - |
|
| 825 | - if(!isset($row->$field_name)) { |
|
| 826 | - throw new Exception("The field name doesn't exist in the database. ". |
|
| 827 | - "Please use the unique fields only for fields ". |
|
| 828 | - "that exist in the database"); |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - $previous_field_name_value = $row->$field_name; |
|
| 832 | - |
|
| 833 | - if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
| 834 | - $form_validation->set_rules( $field_name, |
|
| 835 | - $field_types[$field_name]->display_as, |
|
| 836 | - 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
| 837 | - |
|
| 838 | - $form_validation_check = true; |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - if($form_validation_check && !$form_validation->run()) |
|
| 844 | - { |
|
| 845 | - $validation_result->error_message = $form_validation->error_string(); |
|
| 846 | - $validation_result->error_fields = $form_validation->_error_array; |
|
| 847 | - |
|
| 848 | - return $validation_result; |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - if(!empty($this->validation_rules)) |
|
| 853 | - { |
|
| 854 | - $form_validation = $this->form_validation(); |
|
| 855 | - |
|
| 856 | - $edit_fields = $this->get_edit_fields(); |
|
| 857 | - |
|
| 858 | - foreach($edit_fields as $edit_field) |
|
| 859 | - { |
|
| 860 | - $field_name = $edit_field->field_name; |
|
| 861 | - if(isset($this->validation_rules[$field_name])) |
|
| 862 | - { |
|
| 863 | - $rule = $this->validation_rules[$field_name]; |
|
| 864 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - if($form_validation->run()) |
|
| 869 | - { |
|
| 870 | - $validation_result->success = true; |
|
| 871 | - } |
|
| 872 | - else |
|
| 873 | - { |
|
| 874 | - $validation_result->error_message = $form_validation->error_string(); |
|
| 875 | - $validation_result->error_fields = $form_validation->_error_array; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - else |
|
| 879 | - { |
|
| 880 | - $validation_result->success = true; |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - return $validation_result; |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - protected function db_insert($state_info) |
|
| 887 | - { |
|
| 888 | - $validation_result = $this->db_insert_validation(); |
|
| 889 | - |
|
| 890 | - if($validation_result->success) |
|
| 891 | - { |
|
| 892 | - $post_data = $state_info->unwrapped_data; |
|
| 893 | - |
|
| 894 | - $add_fields = $this->get_add_fields(); |
|
| 895 | - |
|
| 896 | - if($this->callback_insert === null) |
|
| 897 | - { |
|
| 898 | - if($this->callback_before_insert !== null) |
|
| 899 | - { |
|
| 900 | - $callback_return = call_user_func($this->callback_before_insert, $post_data); |
|
| 901 | - |
|
| 902 | - if(!empty($callback_return) && is_array($callback_return)) |
|
| 903 | - $post_data = $callback_return; |
|
| 904 | - elseif($callback_return === false) |
|
| 905 | - return false; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - $insert_data = array(); |
|
| 909 | - $types = $this->get_field_types(); |
|
| 910 | - foreach($add_fields as $num_row => $field) |
|
| 911 | - { |
|
| 912 | - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
| 913 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 914 | - { |
|
| 915 | - $post_data[$field->field_name] = array(); |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 919 | - { |
|
| 920 | - 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])) |
|
| 921 | - { |
|
| 922 | - $insert_data[$field->field_name] = null; |
|
| 923 | - } |
|
| 924 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 925 | - { |
|
| 926 | - $insert_data[$field->field_name] = null; |
|
| 927 | - } |
|
| 928 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 929 | - { |
|
| 930 | - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
| 931 | - } |
|
| 932 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 933 | - { |
|
| 934 | - //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
| 935 | - } |
|
| 936 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 937 | - { |
|
| 938 | - $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 939 | - } |
|
| 940 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 941 | - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 942 | - substr($post_data[$field->field_name],10); |
|
| 943 | - } |
|
| 944 | - else |
|
| 945 | - { |
|
| 946 | - $insert_data[$field->field_name] = $post_data[$field->field_name]; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - $insert_result = $this->basic_model->db_insert($insert_data); |
|
| 952 | - |
|
| 953 | - if($insert_result !== false) |
|
| 954 | - { |
|
| 955 | - $insert_primary_key = $insert_result; |
|
| 956 | - } |
|
| 957 | - else |
|
| 958 | - { |
|
| 959 | - return false; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - if(!empty($this->relation_n_n)) |
|
| 963 | - { |
|
| 964 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 965 | - { |
|
| 966 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 967 | - $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); |
|
| 968 | - } |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - if($this->callback_after_insert !== null) |
|
| 972 | - { |
|
| 973 | - $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); |
|
| 974 | - |
|
| 975 | - if($callback_return === false) |
|
| 976 | - { |
|
| 977 | - return false; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - } |
|
| 981 | - }else |
|
| 982 | - { |
|
| 983 | - $callback_return = call_user_func($this->callback_insert, $post_data); |
|
| 984 | - |
|
| 985 | - if($callback_return === false) |
|
| 986 | - { |
|
| 987 | - return false; |
|
| 988 | - } |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - if(isset($insert_primary_key)) |
|
| 992 | - return $insert_primary_key; |
|
| 993 | - else |
|
| 994 | - return true; |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - return false; |
|
| 998 | - |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - protected function db_update($state_info) |
|
| 1002 | - { |
|
| 1003 | - $validation_result = $this->db_update_validation(); |
|
| 1004 | - |
|
| 1005 | - $edit_fields = $this->get_edit_fields(); |
|
| 1006 | - |
|
| 1007 | - if($validation_result->success) |
|
| 1008 | - { |
|
| 1009 | - $post_data = $state_info->unwrapped_data; |
|
| 1010 | - $primary_key = $state_info->primary_key; |
|
| 1011 | - |
|
| 1012 | - if($this->callback_update === null) |
|
| 1013 | - { |
|
| 1014 | - if($this->callback_before_update !== null) |
|
| 1015 | - { |
|
| 1016 | - $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); |
|
| 1017 | - |
|
| 1018 | - if(!empty($callback_return) && is_array($callback_return)) |
|
| 1019 | - { |
|
| 1020 | - $post_data = $callback_return; |
|
| 1021 | - } |
|
| 1022 | - elseif($callback_return === false) |
|
| 1023 | - { |
|
| 1024 | - return false; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - $update_data = array(); |
|
| 1030 | - $types = $this->get_field_types(); |
|
| 1031 | - foreach($edit_fields as $num_row => $field) |
|
| 1032 | - { |
|
| 1033 | - /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
| 1034 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 1035 | - { |
|
| 1036 | - $post_data[$field->field_name] = array(); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 1040 | - { |
|
| 1041 | - 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])) |
|
| 1042 | - { |
|
| 1043 | - $update_data[$field->field_name] = null; |
|
| 1044 | - } |
|
| 1045 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1046 | - { |
|
| 1047 | - $update_data[$field->field_name] = null; |
|
| 1048 | - } |
|
| 1049 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1050 | - { |
|
| 1051 | - $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
| 1052 | - } |
|
| 1053 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1054 | - { |
|
| 1055 | - //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
| 1056 | - } |
|
| 1057 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1058 | - { |
|
| 1059 | - $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 1060 | - } |
|
| 1061 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 1062 | - $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 1063 | - substr($post_data[$field->field_name],10); |
|
| 1064 | - } |
|
| 1065 | - else |
|
| 1066 | - { |
|
| 1067 | - $update_data[$field->field_name] = $post_data[$field->field_name]; |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - if($this->basic_model->db_update($update_data, $primary_key) === false) |
|
| 1073 | - { |
|
| 1074 | - return false; |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - if(!empty($this->relation_n_n)) |
|
| 1078 | - { |
|
| 1079 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1080 | - { |
|
| 1081 | - if ( $this->unset_edit_fields !== null |
|
| 1082 | - && is_array($this->unset_edit_fields) |
|
| 1083 | - && in_array($field_name,$this->unset_edit_fields) |
|
| 1084 | - ) { |
|
| 1085 | - continue; |
|
| 1086 | - } |
|
| 1087 | - |
|
| 1088 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 1089 | - $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); |
|
| 1090 | - } |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - if($this->callback_after_update !== null) |
|
| 1094 | - { |
|
| 1095 | - $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); |
|
| 1096 | - |
|
| 1097 | - if($callback_return === false) |
|
| 1098 | - { |
|
| 1099 | - return false; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - else |
|
| 1105 | - { |
|
| 1106 | - $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
|
| 1107 | - |
|
| 1108 | - if($callback_return === false) |
|
| 1109 | - { |
|
| 1110 | - return false; |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - return true; |
|
| 1115 | - } |
|
| 1116 | - else |
|
| 1117 | - { |
|
| 1118 | - return false; |
|
| 1119 | - } |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - protected function _convert_date_to_sql_date($date) |
|
| 1123 | - { |
|
| 1124 | - $date = substr($date,0,10); |
|
| 1125 | - if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) |
|
| 1126 | - { |
|
| 1127 | - //If it's already a sql-date don't convert it! |
|
| 1128 | - return $date; |
|
| 1129 | - }elseif(empty($date)) |
|
| 1130 | - { |
|
| 1131 | - return ''; |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - $date_array = preg_split( '/[-\.\/ ]/', $date); |
|
| 1135 | - if($this->php_date_format == 'd/m/Y') |
|
| 1136 | - { |
|
| 1137 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
|
| 1138 | - } |
|
| 1139 | - elseif($this->php_date_format == 'm/d/Y') |
|
| 1140 | - { |
|
| 1141 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
|
| 1142 | - } |
|
| 1143 | - else |
|
| 1144 | - { |
|
| 1145 | - $sql_date = $date; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $sql_date; |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - protected function _get_field_names_to_search(array $relation_values) |
|
| 1152 | - { |
|
| 1153 | - if(!strstr($relation_values[2],'{')) |
|
| 1154 | - return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
| 1155 | - else |
|
| 1156 | - { |
|
| 1157 | - $relation_values[2] = ' '.$relation_values[2].' '; |
|
| 1158 | - $temp1 = explode('{',$relation_values[2]); |
|
| 1159 | - unset($temp1[0]); |
|
| 1160 | - |
|
| 1161 | - $field_names_array = array(); |
|
| 1162 | - foreach($temp1 as $field) |
|
| 1163 | - list($field_names_array[]) = explode('}',$field); |
|
| 1164 | - |
|
| 1165 | - return $field_names_array; |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 611 | + } elseif(isset($this->relation_n_n[$state_info->search->field])) { |
|
| 612 | + $escaped_text = $this->basic_model->escape_str($state_info->search->text); |
|
| 613 | + $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); |
|
| 614 | + } else { |
|
| 615 | + $this->like($state_info->search->field , $state_info->search->text); |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + else |
|
| 619 | + { |
|
| 620 | + $columns = $this->get_columns(); |
|
| 1168 | 621 | |
| 1169 | - protected function _unique_join_name($field_name) |
|
| 1170 | - { |
|
| 1171 | - return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number |
|
| 622 | + $search_text = $state_info->search->text; |
|
| 623 | + |
|
| 624 | + if(!empty($this->where)) |
|
| 625 | + foreach($this->where as $where) |
|
| 626 | + $this->basic_model->having($where[0],$where[1],$where[2]); |
|
| 627 | + |
|
| 628 | + foreach($columns as $column) |
|
| 629 | + { |
|
| 630 | + if(isset($temp_relation[$column->field_name])) |
|
| 631 | + { |
|
| 632 | + if(is_array($temp_relation[$column->field_name])) |
|
| 633 | + { |
|
| 634 | + foreach($temp_relation[$column->field_name] as $search_field) |
|
| 635 | + { |
|
| 636 | + $this->or_like($search_field, $search_text); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + else |
|
| 640 | + { |
|
| 641 | + $this->or_like($temp_relation[$column->field_name], $search_text); |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + elseif(isset($this->relation_n_n[$column->field_name])) |
|
| 645 | + { |
|
| 646 | + //@todo have a where for the relation_n_n statement |
|
| 647 | + } |
|
| 648 | + else |
|
| 649 | + { |
|
| 650 | + $this->or_like($column->field_name, $search_text); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 1172 | 655 | } |
| 1173 | 656 | |
| 1174 | - protected function _unique_field_name($field_name) |
|
| 657 | + protected function table_exists($table_name = null) |
|
| 1175 | 658 | { |
| 1176 | - return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number |
|
| 659 | + if($this->basic_model->db_table_exists($table_name)) |
|
| 660 | + return true; |
|
| 661 | + return false; |
|
| 1177 | 662 | } |
| 1178 | 663 | |
| 1179 | - protected function db_multiple_delete($state_info) |
|
| 664 | + protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) |
|
| 1180 | 665 | { |
| 1181 | - foreach ($state_info->ids as $delete_id) { |
|
| 1182 | - $result = $this->db_delete((object)array('primary_key' => $delete_id)); |
|
| 1183 | - if (!$result) { |
|
| 1184 | - return false; |
|
| 1185 | - } |
|
| 666 | + list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; |
|
| 667 | + |
|
| 668 | + if($primary_key_value !== null) |
|
| 669 | + { |
|
| 670 | + $primary_key = $this->basic_model->get_primary_key($related_table); |
|
| 671 | + |
|
| 672 | + //A where clause with the primary key is enough to take the selected key row |
|
| 673 | + $where_clause = array($primary_key => $primary_key_value); |
|
| 1186 | 674 | } |
| 1187 | 675 | |
| 1188 | - return true; |
|
| 676 | + $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); |
|
| 677 | + |
|
| 678 | + return $relation_array; |
|
| 1189 | 679 | } |
| 1190 | 680 | |
| 1191 | - protected function db_delete($state_info) |
|
| 1192 | - { |
|
| 1193 | - $primary_key_value = $state_info->primary_key; |
|
| 1194 | - |
|
| 1195 | - if($this->callback_delete === null) |
|
| 1196 | - { |
|
| 1197 | - if($this->callback_before_delete !== null) |
|
| 1198 | - { |
|
| 1199 | - $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); |
|
| 1200 | - |
|
| 1201 | - if($callback_return === false) |
|
| 1202 | - { |
|
| 1203 | - return false; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - if(!empty($this->relation_n_n)) |
|
| 1209 | - { |
|
| 1210 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1211 | - { |
|
| 1212 | - $this->db_relation_n_n_delete( $field_info, $primary_key_value ); |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - $delete_result = $this->basic_model->db_delete($primary_key_value); |
|
| 1217 | - |
|
| 1218 | - if($delete_result === false) |
|
| 1219 | - { |
|
| 1220 | - return false; |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - if($this->callback_after_delete !== null) |
|
| 1224 | - { |
|
| 1225 | - $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); |
|
| 1226 | - |
|
| 1227 | - if($callback_return === false) |
|
| 1228 | - { |
|
| 1229 | - return false; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - else |
|
| 1235 | - { |
|
| 1236 | - $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
|
| 1237 | - |
|
| 1238 | - if($callback_return === false) |
|
| 1239 | - { |
|
| 1240 | - return false; |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - return true; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) |
|
| 1248 | - { |
|
| 1249 | - $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - protected function db_relation_n_n_delete($field_info, $primary_key_value) |
|
| 1253 | - { |
|
| 1254 | - $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - protected function get_list() |
|
| 1258 | - { |
|
| 1259 | - if(!empty($this->order_by)) |
|
| 1260 | - $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
| 1261 | - |
|
| 1262 | - if(!empty($this->where)) |
|
| 1263 | - foreach($this->where as $where) |
|
| 1264 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 1265 | - |
|
| 1266 | - if(!empty($this->or_where)) |
|
| 1267 | - foreach($this->or_where as $or_where) |
|
| 1268 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 1269 | - |
|
| 1270 | - if(!empty($this->like)) |
|
| 1271 | - foreach($this->like as $like) |
|
| 1272 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 1273 | - |
|
| 1274 | - if(!empty($this->or_like)) |
|
| 1275 | - foreach($this->or_like as $or_like) |
|
| 1276 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 1277 | - |
|
| 1278 | - if(!empty($this->having)) |
|
| 1279 | - foreach($this->having as $having) |
|
| 1280 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 1281 | - |
|
| 1282 | - if(!empty($this->or_having)) |
|
| 1283 | - foreach($this->or_having as $or_having) |
|
| 1284 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 1285 | - |
|
| 1286 | - if(!empty($this->relation)) |
|
| 1287 | - foreach($this->relation as $relation) |
|
| 1288 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 1289 | - |
|
| 1290 | - if(!empty($this->relation_n_n)) |
|
| 1291 | - { |
|
| 1292 | - $columns = $this->get_columns(); |
|
| 1293 | - foreach($columns as $column) |
|
| 1294 | - { |
|
| 1295 | - //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
| 1296 | - if(isset($this->relation_n_n[$column->field_name])) |
|
| 1297 | - { |
|
| 1298 | - $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - if($this->theme_config['crud_paging'] === true) |
|
| 1305 | - { |
|
| 1306 | - if($this->limit === null) |
|
| 1307 | - { |
|
| 1308 | - $default_per_page = $this->config->default_per_page; |
|
| 1309 | - if(is_numeric($default_per_page) && $default_per_page >1) |
|
| 1310 | - { |
|
| 1311 | - $this->basic_model->limit($default_per_page); |
|
| 1312 | - } |
|
| 1313 | - else |
|
| 1314 | - { |
|
| 1315 | - $this->basic_model->limit(10); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - else |
|
| 1319 | - { |
|
| 1320 | - $this->basic_model->limit($this->limit[0],$this->limit[1]); |
|
| 1321 | - } |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - $results = $this->basic_model->get_list(); |
|
| 1325 | - |
|
| 1326 | - return $results; |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - protected function get_edit_values($primary_key_value) |
|
| 1330 | - { |
|
| 1331 | - $values = $this->basic_model->get_edit_values($primary_key_value); |
|
| 1332 | - |
|
| 1333 | - if(!empty($this->relation_n_n)) |
|
| 1334 | - { |
|
| 1335 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1336 | - { |
|
| 1337 | - $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
| 1338 | - } |
|
| 1339 | - } |
|
| 1340 | - |
|
| 1341 | - return $values; |
|
| 1342 | - } |
|
| 1343 | - |
|
| 1344 | - protected function get_relation_n_n_selection_array($primary_key_value, $field_info) |
|
| 1345 | - { |
|
| 1346 | - return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - protected function get_relation_n_n_unselected_array($field_info, $selected_values) |
|
| 1350 | - { |
|
| 1351 | - return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - protected function set_basic_db_table($table_name = null) |
|
| 1355 | - { |
|
| 1356 | - $this->basic_model->set_basic_table($table_name); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - protected function upload_file($state_info) |
|
| 1360 | - { |
|
| 1361 | - if(isset($this->upload_fields[$state_info->field_name]) ) |
|
| 1362 | - { |
|
| 1363 | - if($this->callback_upload === null) |
|
| 1364 | - { |
|
| 1365 | - if($this->callback_before_upload !== null) |
|
| 1366 | - { |
|
| 1367 | - $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
| 1368 | - |
|
| 1369 | - if($callback_before_upload_response === false) |
|
| 1370 | - return false; |
|
| 1371 | - elseif(is_string($callback_before_upload_response)) |
|
| 1372 | - return $callback_before_upload_response; |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - $upload_info = $this->upload_fields[$state_info->field_name]; |
|
| 1376 | - |
|
| 1377 | - header('Pragma: no-cache'); |
|
| 1378 | - header('Cache-Control: private, no-cache'); |
|
| 1379 | - header('Content-Disposition: inline; filename="files.json"'); |
|
| 1380 | - header('X-Content-Type-Options: nosniff'); |
|
| 1381 | - header('Access-Control-Allow-Origin: *'); |
|
| 1382 | - header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); |
|
| 1383 | - header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); |
|
| 1384 | - |
|
| 1385 | - $allowed_files = $this->config->file_upload_allow_file_types; |
|
| 1386 | - |
|
| 1387 | - $reg_exp = ''; |
|
| 1388 | - if(!empty($upload_info->allowed_file_types)){ |
|
| 1389 | - $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
|
| 1390 | - }else{ |
|
| 1391 | - $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
| 1395 | - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
| 1396 | - |
|
| 1397 | - $options = array( |
|
| 1398 | - 'upload_dir' => $upload_info->upload_path.'/', |
|
| 1399 | - 'param_name' => $this->_unique_field_name($state_info->field_name), |
|
| 1400 | - 'upload_url' => base_url().$upload_info->upload_path.'/', |
|
| 1401 | - 'accept_file_types' => $reg_exp, |
|
| 1402 | - 'max_file_size' => $max_file_size_bytes |
|
| 1403 | - ); |
|
| 1404 | - $upload_handler = new UploadHandler($options); |
|
| 1405 | - $upload_handler->default_config_path = $this->default_config_path; |
|
| 1406 | - $uploader_response = $upload_handler->post(); |
|
| 1407 | - |
|
| 1408 | - if(is_array($uploader_response)) |
|
| 1409 | - { |
|
| 1410 | - foreach($uploader_response as &$response) |
|
| 1411 | - { |
|
| 1412 | - unset($response->delete_url); |
|
| 1413 | - unset($response->delete_type); |
|
| 1414 | - } |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - if($this->callback_after_upload !== null) |
|
| 1418 | - { |
|
| 1419 | - $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
|
| 1420 | - |
|
| 1421 | - if($callback_after_upload_response === false) |
|
| 1422 | - return false; |
|
| 1423 | - elseif(is_string($callback_after_upload_response)) |
|
| 1424 | - return $callback_after_upload_response; |
|
| 1425 | - elseif(is_array($callback_after_upload_response)) |
|
| 1426 | - $uploader_response = $callback_after_upload_response; |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - return $uploader_response; |
|
| 1430 | - } |
|
| 1431 | - else |
|
| 1432 | - { |
|
| 1433 | - $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
|
| 1434 | - |
|
| 1435 | - if($upload_response === false) |
|
| 1436 | - { |
|
| 1437 | - return false; |
|
| 1438 | - } |
|
| 1439 | - else |
|
| 1440 | - { |
|
| 1441 | - return $upload_response; |
|
| 1442 | - } |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - else |
|
| 1446 | - { |
|
| 1447 | - return false; |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - protected function delete_file($state_info) |
|
| 1452 | - { |
|
| 1453 | - |
|
| 1454 | - if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
| 1455 | - { |
|
| 1456 | - $upload_info = $this->upload_fields[$state_info->field_name]; |
|
| 1457 | - |
|
| 1458 | - if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
| 1459 | - { |
|
| 1460 | - if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) |
|
| 1461 | - { |
|
| 1462 | - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
| 1463 | - |
|
| 1464 | - return true; |
|
| 1465 | - } |
|
| 1466 | - else |
|
| 1467 | - { |
|
| 1468 | - return false; |
|
| 1469 | - } |
|
| 1470 | - } |
|
| 1471 | - else |
|
| 1472 | - { |
|
| 1473 | - $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
| 1474 | - return true; |
|
| 1475 | - } |
|
| 1476 | - } |
|
| 1477 | - else |
|
| 1478 | - { |
|
| 1479 | - return false; |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - protected function ajax_relation($state_info) |
|
| 1484 | - { |
|
| 1485 | - if(!isset($this->relation[$state_info->field_name])) |
|
| 1486 | - return false; |
|
| 1487 | - |
|
| 1488 | - list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
| 1489 | - |
|
| 1490 | - return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); |
|
| 1491 | - } |
|
| 1492 | -} |
|
| 681 | + protected function get_relation_total_rows($relation_info) |
|
| 682 | + { |
|
| 683 | + list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; |
|
| 1493 | 684 | |
| 685 | + $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); |
|
| 1494 | 686 | |
| 1495 | -/** |
|
| 1496 | - * PHP grocery CRUD |
|
| 1497 | - * |
|
| 1498 | - * LICENSE |
|
| 1499 | - * |
|
| 1500 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 1501 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 1502 | - * Please see the corresponding license file for details of these licenses. |
|
| 1503 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 1504 | - * |
|
| 1505 | - * @package grocery CRUD |
|
| 1506 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 1507 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 1508 | - * @author John Skoumbourdis <[email protected]> |
|
| 1509 | - */ |
|
| 687 | + return $relation_array; |
|
| 688 | + } |
|
| 1510 | 689 | |
| 1511 | -// ------------------------------------------------------------------------ |
|
| 690 | + protected function db_insert_validation() |
|
| 691 | + { |
|
| 692 | + $validation_result = (object)array('success'=>false); |
|
| 1512 | 693 | |
| 1513 | -/** |
|
| 1514 | - * PHP grocery Layout |
|
| 1515 | - * |
|
| 1516 | - * Here you manage all the HTML Layout |
|
| 1517 | - * |
|
| 1518 | - * @package grocery CRUD |
|
| 1519 | - * @author John Skoumbourdis <[email protected]> |
|
| 1520 | - * @version 1.5.6 |
|
| 1521 | - */ |
|
| 1522 | -class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver |
|
| 1523 | -{ |
|
| 1524 | - private $theme_path = null; |
|
| 1525 | - private $views_as_string = ''; |
|
| 1526 | - private $echo_and_die = false; |
|
| 1527 | - protected $theme = null; |
|
| 1528 | - protected $default_true_false_text = array('inactive' , 'active'); |
|
| 694 | + $field_types = $this->get_field_types(); |
|
| 695 | + $required_fields = $this->required_fields; |
|
| 696 | + $unique_fields = $this->_unique_fields; |
|
| 697 | + $add_fields = $this->get_add_fields(); |
|
| 1529 | 698 | |
| 1530 | - protected $css_files = array(); |
|
| 1531 | - protected $js_files = array(); |
|
| 1532 | - protected $js_lib_files = array(); |
|
| 1533 | - protected $js_config_files = array(); |
|
| 699 | + if(!empty($required_fields)) |
|
| 700 | + { |
|
| 701 | + foreach($add_fields as $add_field) |
|
| 702 | + { |
|
| 703 | + $field_name = $add_field->field_name; |
|
| 704 | + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 705 | + { |
|
| 706 | + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + } |
|
| 1534 | 710 | |
| 1535 | - protected function set_basic_Layout() |
|
| 1536 | - { |
|
| 1537 | - if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
| 1538 | - { |
|
| 1539 | - throw new Exception('The template does not exist. Please check your files and try again.', 12); |
|
| 1540 | - die(); |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 711 | + /** Checking for unique fields. If the field value is not unique then |
|
| 712 | + * return a validation error straight away, if not continue... */ |
|
| 713 | + if(!empty($unique_fields)) |
|
| 714 | + { |
|
| 715 | + $form_validation = $this->form_validation(); |
|
| 1543 | 716 | |
| 1544 | - protected function showList($ajax = false, $state_info = null) |
|
| 1545 | - { |
|
| 1546 | - $data = $this->get_common_data(); |
|
| 717 | + foreach($add_fields as $add_field) |
|
| 718 | + { |
|
| 719 | + $field_name = $add_field->field_name; |
|
| 720 | + if(in_array( $field_name, $unique_fields) ) |
|
| 721 | + { |
|
| 722 | + $form_validation->set_rules( $field_name, |
|
| 723 | + $field_types[$field_name]->display_as, |
|
| 724 | + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
| 725 | + } |
|
| 726 | + } |
|
| 1547 | 727 | |
| 1548 | - $data->order_by = $this->order_by; |
|
| 728 | + if(!$form_validation->run()) |
|
| 729 | + { |
|
| 730 | + $validation_result->error_message = $form_validation->error_string(); |
|
| 731 | + $validation_result->error_fields = $form_validation->_error_array; |
|
| 1549 | 732 | |
| 1550 | - $data->types = $this->get_field_types(); |
|
| 733 | + return $validation_result; |
|
| 734 | + } |
|
| 735 | + } |
|
| 1551 | 736 | |
| 1552 | - $data->list = $this->get_list(); |
|
| 1553 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1554 | - $data->list = $this->change_list_add_actions($data->list); |
|
| 737 | + if(!empty($this->validation_rules)) |
|
| 738 | + { |
|
| 739 | + $form_validation = $this->form_validation(); |
|
| 1555 | 740 | |
| 1556 | - $data->total_results = $this->get_total_results(); |
|
| 741 | + $add_fields = $this->get_add_fields(); |
|
| 1557 | 742 | |
| 1558 | - $data->columns = $this->get_columns(); |
|
| 743 | + foreach($add_fields as $add_field) |
|
| 744 | + { |
|
| 745 | + $field_name = $add_field->field_name; |
|
| 746 | + if(isset($this->validation_rules[$field_name])) |
|
| 747 | + { |
|
| 748 | + $rule = $this->validation_rules[$field_name]; |
|
| 749 | + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 750 | + } |
|
| 751 | + } |
|
| 1559 | 752 | |
| 1560 | - $data->success_message = $this->get_success_message_at_list($state_info); |
|
| 753 | + if($form_validation->run()) |
|
| 754 | + { |
|
| 755 | + $validation_result->success = true; |
|
| 756 | + } |
|
| 757 | + else |
|
| 758 | + { |
|
| 759 | + $validation_result->error_message = $form_validation->error_string(); |
|
| 760 | + $validation_result->error_fields = $form_validation->_error_array; |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + else |
|
| 764 | + { |
|
| 765 | + $validation_result->success = true; |
|
| 766 | + } |
|
| 1561 | 767 | |
| 1562 | - $data->primary_key = $this->get_primary_key(); |
|
| 1563 | - $data->add_url = $this->getAddUrl(); |
|
| 1564 | - $data->edit_url = $this->getEditUrl(); |
|
| 1565 | - $data->delete_url = $this->getDeleteUrl(); |
|
| 1566 | - $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
| 1567 | - $data->read_url = $this->getReadUrl(); |
|
| 1568 | - $data->ajax_list_url = $this->getAjaxListUrl(); |
|
| 1569 | - $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
| 1570 | - $data->export_url = $this->getExportToExcelUrl(); |
|
| 1571 | - $data->print_url = $this->getPrintUrl(); |
|
| 1572 | - $data->actions = $this->actions; |
|
| 1573 | - $data->unique_hash = $this->get_method_hash(); |
|
| 1574 | - $data->order_by = $this->order_by; |
|
| 1575 | - |
|
| 1576 | - $data->unset_add = $this->unset_add; |
|
| 1577 | - $data->unset_edit = $this->unset_edit; |
|
| 1578 | - $data->unset_read = $this->unset_read; |
|
| 1579 | - $data->unset_delete = $this->unset_delete; |
|
| 1580 | - $data->unset_export = $this->unset_export; |
|
| 1581 | - $data->unset_print = $this->unset_print; |
|
| 1582 | - |
|
| 1583 | - $default_per_page = $this->config->default_per_page; |
|
| 1584 | - $data->paging_options = $this->config->paging_options; |
|
| 1585 | - $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; |
|
| 1586 | - |
|
| 1587 | - if($data->list === false) |
|
| 1588 | - { |
|
| 1589 | - throw new Exception('It is impossible to get data. Please check your model and try again.', 13); |
|
| 1590 | - $data->list = array(); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - foreach($data->list as $num_row => $row) |
|
| 1594 | - { |
|
| 1595 | - $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; |
|
| 1596 | - $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; |
|
| 1597 | - $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; |
|
| 1598 | - $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - if(!$ajax) |
|
| 1602 | - { |
|
| 1603 | - $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); |
|
| 1604 | - |
|
| 1605 | - $data->list_view = $this->_theme_view('list.php',$data,true); |
|
| 1606 | - $this->_theme_view('list_template.php',$data); |
|
| 1607 | - } |
|
| 1608 | - else |
|
| 1609 | - { |
|
| 1610 | - $this->set_echo_and_die(); |
|
| 1611 | - $this->_theme_view('list.php',$data); |
|
| 1612 | - } |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - protected function exportToExcel($state_info = null) |
|
| 1616 | - { |
|
| 1617 | - $data = $this->get_common_data(); |
|
| 1618 | - |
|
| 1619 | - $data->order_by = $this->order_by; |
|
| 1620 | - $data->types = $this->get_field_types(); |
|
| 1621 | - |
|
| 1622 | - $data->list = $this->get_list(); |
|
| 1623 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1624 | - $data->list = $this->change_list_add_actions($data->list); |
|
| 1625 | - |
|
| 1626 | - $data->total_results = $this->get_total_results(); |
|
| 1627 | - |
|
| 1628 | - $data->columns = $this->get_columns(); |
|
| 1629 | - $data->primary_key = $this->get_primary_key(); |
|
| 1630 | - |
|
| 1631 | - @ob_end_clean(); |
|
| 1632 | - $this->_export_to_excel($data); |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - protected function _export_to_excel($data) |
|
| 1636 | - { |
|
| 1637 | - /** |
|
| 1638 | - * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining |
|
| 1639 | - * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. |
|
| 1640 | - * */ |
|
| 1641 | - |
|
| 1642 | - $string_to_export = ""; |
|
| 1643 | - foreach($data->columns as $column){ |
|
| 1644 | - $string_to_export .= $column->display_as."\t"; |
|
| 1645 | - } |
|
| 1646 | - $string_to_export .= "\n"; |
|
| 1647 | - |
|
| 1648 | - foreach($data->list as $num_row => $row){ |
|
| 1649 | - foreach($data->columns as $column){ |
|
| 1650 | - $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; |
|
| 1651 | - } |
|
| 1652 | - $string_to_export .= "\n"; |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - // Convert to UTF-16LE and Prepend BOM |
|
| 1656 | - $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
| 1657 | - |
|
| 1658 | - $filename = "export-".date("Y-m-d_H:i:s").".xls"; |
|
| 1659 | - |
|
| 1660 | - header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); |
|
| 1661 | - header('Content-Disposition: attachment; filename='.$filename); |
|
| 1662 | - header("Cache-Control: no-cache"); |
|
| 1663 | - echo $string_to_export; |
|
| 1664 | - die(); |
|
| 1665 | - } |
|
| 1666 | - |
|
| 1667 | - protected function print_webpage($state_info = null) |
|
| 1668 | - { |
|
| 1669 | - $data = $this->get_common_data(); |
|
| 1670 | - |
|
| 1671 | - $data->order_by = $this->order_by; |
|
| 1672 | - $data->types = $this->get_field_types(); |
|
| 1673 | - |
|
| 1674 | - $data->list = $this->get_list(); |
|
| 1675 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1676 | - $data->list = $this->change_list_add_actions($data->list); |
|
| 1677 | - |
|
| 1678 | - $data->total_results = $this->get_total_results(); |
|
| 1679 | - |
|
| 1680 | - $data->columns = $this->get_columns(); |
|
| 1681 | - $data->primary_key = $this->get_primary_key(); |
|
| 1682 | - |
|
| 1683 | - @ob_end_clean(); |
|
| 1684 | - $this->_print_webpage($data); |
|
| 1685 | - } |
|
| 1686 | - |
|
| 1687 | - protected function _print_webpage($data) |
|
| 1688 | - { |
|
| 1689 | - $string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" > |
|
| 1690 | - #print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;} |
|
| 1691 | - #print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px} |
|
| 1692 | - #print-table table{ border-bottom: 1px solid black; border-right: 1px solid black} |
|
| 1693 | - #print-table table tr th{text-align: left;background: #ddd} |
|
| 1694 | - #print-table table tr:nth-child(odd){background: #eee} |
|
| 1695 | - </style>"; |
|
| 1696 | - $string_to_print .= "<div id='print-table'>"; |
|
| 1697 | - |
|
| 1698 | - $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; |
|
| 1699 | - foreach($data->columns as $column){ |
|
| 1700 | - $string_to_print .= "<th>".$column->display_as."</th>"; |
|
| 1701 | - } |
|
| 1702 | - $string_to_print .= "</tr>"; |
|
| 1703 | - |
|
| 1704 | - foreach($data->list as $num_row => $row){ |
|
| 1705 | - $string_to_print .= "<tr>"; |
|
| 1706 | - foreach($data->columns as $column){ |
|
| 1707 | - $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; |
|
| 1708 | - } |
|
| 1709 | - $string_to_print .= "</tr>"; |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - $string_to_print .= "</table></div>"; |
|
| 1713 | - |
|
| 1714 | - echo $string_to_print; |
|
| 1715 | - die(); |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - protected function _trim_export_string($value) |
|
| 1719 | - { |
|
| 1720 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1721 | - return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - protected function _trim_print_string($value) |
|
| 1725 | - { |
|
| 1726 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1727 | - |
|
| 1728 | - //If the value has only spaces and nothing more then add the whitespace html character |
|
| 1729 | - if(str_replace(" ","",$value) == "") |
|
| 1730 | - $value = " "; |
|
| 1731 | - |
|
| 1732 | - return strip_tags($value); |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - protected function set_echo_and_die() |
|
| 1736 | - { |
|
| 1737 | - $this->echo_and_die = true; |
|
| 1738 | - } |
|
| 1739 | - |
|
| 1740 | - protected function unset_echo_and_die() |
|
| 1741 | - { |
|
| 1742 | - $this->echo_and_die = false; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - protected function showListInfo() |
|
| 1746 | - { |
|
| 1747 | - $this->set_echo_and_die(); |
|
| 1748 | - |
|
| 1749 | - $total_results = (int)$this->get_total_results(); |
|
| 1750 | - @ob_end_clean(); |
|
| 1751 | - echo json_encode(array('total_results' => $total_results)); |
|
| 1752 | - die(); |
|
| 1753 | - } |
|
| 1754 | - |
|
| 1755 | - protected function change_list_add_actions($list) |
|
| 1756 | - { |
|
| 1757 | - if(empty($this->actions)) |
|
| 1758 | - return $list; |
|
| 1759 | - |
|
| 1760 | - $primary_key = $this->get_primary_key(); |
|
| 1761 | - |
|
| 1762 | - foreach($list as $num_row => $row) |
|
| 1763 | - { |
|
| 1764 | - $actions_urls = array(); |
|
| 1765 | - foreach($this->actions as $unique_id => $action) |
|
| 1766 | - { |
|
| 1767 | - if(!empty($action->url_callback)) |
|
| 1768 | - { |
|
| 1769 | - $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
|
| 1770 | - } |
|
| 1771 | - else |
|
| 1772 | - { |
|
| 1773 | - $actions_urls[$unique_id] = |
|
| 1774 | - $action->url_has_http ? |
|
| 1775 | - $action->link_url.$row->$primary_key : |
|
| 1776 | - site_url($action->link_url.'/'.$row->$primary_key); |
|
| 1777 | - } |
|
| 1778 | - } |
|
| 1779 | - $row->action_urls = $actions_urls; |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - return $list; |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - protected function change_list($list,$types) |
|
| 1786 | - { |
|
| 1787 | - $primary_key = $this->get_primary_key(); |
|
| 1788 | - $has_callbacks = !empty($this->callback_column) ? true : false; |
|
| 1789 | - $output_columns = $this->get_columns(); |
|
| 1790 | - foreach($list as $num_row => $row) |
|
| 1791 | - { |
|
| 1792 | - foreach($output_columns as $column) |
|
| 1793 | - { |
|
| 1794 | - $field_name = $column->field_name; |
|
| 1795 | - $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
| 1796 | - if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
| 1797 | - $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
| 1798 | - elseif(isset($types[$field_name])) |
|
| 1799 | - $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
| 1800 | - else |
|
| 1801 | - $list[$num_row]->$field_name = $field_value; |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - return $list; |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - protected function showAddForm() |
|
| 1809 | - { |
|
| 1810 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1811 | - |
|
| 1812 | - $data = $this->get_common_data(); |
|
| 1813 | - $data->types = $this->get_field_types(); |
|
| 1814 | - |
|
| 1815 | - $data->list_url = $this->getListUrl(); |
|
| 1816 | - $data->insert_url = $this->getInsertUrl(); |
|
| 1817 | - $data->validation_url = $this->getValidationInsertUrl(); |
|
| 1818 | - $data->input_fields = $this->get_add_input_fields(); |
|
| 1819 | - |
|
| 1820 | - $data->fields = $this->get_add_fields(); |
|
| 1821 | - $data->hidden_fields = $this->get_add_hidden_fields(); |
|
| 1822 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1823 | - $data->unique_hash = $this->get_method_hash(); |
|
| 1824 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1825 | - |
|
| 1826 | - $this->_theme_view('add.php',$data); |
|
| 1827 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1828 | - |
|
| 1829 | - $this->_get_ajax_results(); |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - protected function showEditForm($state_info) |
|
| 1833 | - { |
|
| 1834 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1835 | - |
|
| 1836 | - $data = $this->get_common_data(); |
|
| 1837 | - $data->types = $this->get_field_types(); |
|
| 1838 | - |
|
| 1839 | - $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
| 1840 | - |
|
| 1841 | - $data->add_url = $this->getAddUrl(); |
|
| 1842 | - |
|
| 1843 | - $data->list_url = $this->getListUrl(); |
|
| 1844 | - $data->update_url = $this->getUpdateUrl($state_info); |
|
| 1845 | - $data->delete_url = $this->getDeleteUrl($state_info); |
|
| 1846 | - $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
| 1847 | - $data->input_fields = $this->get_edit_input_fields($data->field_values); |
|
| 1848 | - $data->unique_hash = $this->get_method_hash(); |
|
| 1849 | - |
|
| 1850 | - $data->fields = $this->get_edit_fields(); |
|
| 1851 | - $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
| 1852 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1853 | - |
|
| 1854 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1855 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1856 | - |
|
| 1857 | - $this->_theme_view('edit.php',$data); |
|
| 1858 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1859 | - |
|
| 1860 | - $this->_get_ajax_results(); |
|
| 1861 | - } |
|
| 1862 | - |
|
| 1863 | - protected function showReadForm($state_info) |
|
| 1864 | - { |
|
| 1865 | - $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1866 | - |
|
| 1867 | - $data = $this->get_common_data(); |
|
| 1868 | - $data->types = $this->get_field_types(); |
|
| 1869 | - |
|
| 1870 | - $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
| 1871 | - |
|
| 1872 | - $data->add_url = $this->getAddUrl(); |
|
| 1873 | - |
|
| 1874 | - $data->list_url = $this->getListUrl(); |
|
| 1875 | - $data->update_url = $this->getUpdateUrl($state_info); |
|
| 1876 | - $data->delete_url = $this->getDeleteUrl($state_info); |
|
| 1877 | - $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
| 1878 | - $data->input_fields = $this->get_read_input_fields($data->field_values); |
|
| 1879 | - $data->unique_hash = $this->get_method_hash(); |
|
| 1880 | - |
|
| 1881 | - $data->fields = $this->get_read_fields(); |
|
| 1882 | - $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
| 1883 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1884 | - |
|
| 1885 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1886 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1887 | - |
|
| 1888 | - $this->_theme_view('read.php',$data); |
|
| 1889 | - $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1890 | - |
|
| 1891 | - $this->_get_ajax_results(); |
|
| 1892 | - } |
|
| 1893 | - |
|
| 1894 | - protected function delete_layout($delete_result = true) |
|
| 1895 | - { |
|
| 1896 | - @ob_end_clean(); |
|
| 1897 | - if($delete_result === false) |
|
| 1898 | - { |
|
| 1899 | - $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
|
| 1900 | - |
|
| 1901 | - echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
|
| 1902 | - } |
|
| 1903 | - else |
|
| 1904 | - { |
|
| 1905 | - $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
|
| 1906 | - |
|
| 1907 | - echo json_encode(array('success' => true , 'success_message' => $success_message)); |
|
| 1908 | - } |
|
| 1909 | - $this->set_echo_and_die(); |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - protected function get_success_message_at_list($field_info = null) |
|
| 1913 | - { |
|
| 1914 | - if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
| 1915 | - { |
|
| 1916 | - if(!empty($field_info->primary_key) && !$this->unset_edit) |
|
| 1917 | - { |
|
| 1918 | - return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
| 1919 | - } |
|
| 1920 | - else |
|
| 1921 | - { |
|
| 1922 | - return $this->l('insert_success_message'); |
|
| 1923 | - } |
|
| 1924 | - } |
|
| 1925 | - else |
|
| 1926 | - { |
|
| 1927 | - return null; |
|
| 1928 | - } |
|
| 1929 | - } |
|
| 1930 | - |
|
| 1931 | - protected function insert_layout($insert_result = false) |
|
| 1932 | - { |
|
| 1933 | - @ob_end_clean(); |
|
| 1934 | - if($insert_result === false) |
|
| 1935 | - { |
|
| 1936 | - echo json_encode(array('success' => false)); |
|
| 1937 | - } |
|
| 1938 | - else |
|
| 1939 | - { |
|
| 1940 | - $success_message = '<p>'.$this->l('insert_success_message'); |
|
| 1941 | - |
|
| 1942 | - if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
| 1943 | - { |
|
| 1944 | - $success_message .= " <a class='go-to-edit-form' href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
| 1945 | - |
|
| 1946 | - if (!$this->_is_ajax()) { |
|
| 1947 | - $success_message .= $this->l('form_or'); |
|
| 1948 | - } |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 1952 | - { |
|
| 1953 | - $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
| 1954 | - } |
|
| 1955 | - |
|
| 1956 | - $success_message .= '</p>'; |
|
| 1957 | - |
|
| 1958 | - echo json_encode(array( |
|
| 1959 | - 'success' => true , |
|
| 1960 | - 'insert_primary_key' => $insert_result, |
|
| 1961 | - 'success_message' => $success_message, |
|
| 1962 | - 'success_list_url' => $this->getListSuccessUrl($insert_result) |
|
| 1963 | - )); |
|
| 1964 | - } |
|
| 1965 | - $this->set_echo_and_die(); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - protected function validation_layout($validation_result) |
|
| 1969 | - { |
|
| 1970 | - @ob_end_clean(); |
|
| 1971 | - echo json_encode($validation_result); |
|
| 1972 | - $this->set_echo_and_die(); |
|
| 1973 | - } |
|
| 1974 | - |
|
| 1975 | - protected function upload_layout($upload_result, $field_name) |
|
| 1976 | - { |
|
| 1977 | - @ob_end_clean(); |
|
| 1978 | - if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
| 1979 | - { |
|
| 1980 | - echo json_encode( |
|
| 1981 | - (object)array( |
|
| 1982 | - 'success' => true, |
|
| 1983 | - 'files' => $upload_result |
|
| 1984 | - )); |
|
| 1985 | - } |
|
| 1986 | - else |
|
| 1987 | - { |
|
| 1988 | - $result = (object)array('success' => false); |
|
| 1989 | - if(is_string($upload_result)) |
|
| 1990 | - $result->message = $upload_result; |
|
| 1991 | - if(!empty($upload_result[0]->error)) |
|
| 1992 | - $result->message = $upload_result[0]->error; |
|
| 1993 | - |
|
| 1994 | - echo json_encode($result); |
|
| 1995 | - } |
|
| 1996 | - |
|
| 1997 | - $this->set_echo_and_die(); |
|
| 1998 | - } |
|
| 1999 | - |
|
| 2000 | - protected function delete_file_layout($upload_result) |
|
| 2001 | - { |
|
| 2002 | - @ob_end_clean(); |
|
| 2003 | - if($upload_result !== false) |
|
| 2004 | - { |
|
| 2005 | - echo json_encode( (object)array( 'success' => true ) ); |
|
| 2006 | - } |
|
| 2007 | - else |
|
| 2008 | - { |
|
| 2009 | - echo json_encode((object)array('success' => false)); |
|
| 2010 | - } |
|
| 2011 | - |
|
| 2012 | - $this->set_echo_and_die(); |
|
| 2013 | - } |
|
| 2014 | - |
|
| 2015 | - public function set_css($css_file) |
|
| 2016 | - { |
|
| 2017 | - $this->css_files[sha1($css_file)] = base_url().$css_file; |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - public function set_js($js_file) |
|
| 2021 | - { |
|
| 2022 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2023 | - } |
|
| 2024 | - |
|
| 2025 | - public function set_js_lib($js_file) |
|
| 2026 | - { |
|
| 2027 | - $this->js_lib_files[sha1($js_file)] = base_url().$js_file; |
|
| 2028 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2029 | - } |
|
| 2030 | - |
|
| 2031 | - public function set_js_config($js_file) |
|
| 2032 | - { |
|
| 2033 | - $this->js_config_files[sha1($js_file)] = base_url().$js_file; |
|
| 2034 | - $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2035 | - } |
|
| 2036 | - |
|
| 2037 | - public function is_IE7() |
|
| 2038 | - { |
|
| 2039 | - return isset($_SERVER['HTTP_USER_AGENT']) |
|
| 2040 | - && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) |
|
| 2041 | - ? true : false; |
|
| 2042 | - } |
|
| 2043 | - |
|
| 2044 | - public function get_css_files() |
|
| 2045 | - { |
|
| 2046 | - return $this->css_files; |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - public function get_js_files() |
|
| 2050 | - { |
|
| 2051 | - return $this->js_files; |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - public function get_js_lib_files() |
|
| 2055 | - { |
|
| 2056 | - return $this->js_lib_files; |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - public function get_js_config_files() |
|
| 2060 | - { |
|
| 2061 | - return $this->js_config_files; |
|
| 2062 | - } |
|
| 2063 | - |
|
| 2064 | - /** |
|
| 2065 | - * Load Javascripts |
|
| 2066 | - **/ |
|
| 2067 | - protected function load_js_fancybox() |
|
| 2068 | - { |
|
| 2069 | - $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); |
|
| 2070 | - |
|
| 2071 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); |
|
| 2072 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); |
|
| 2073 | - } |
|
| 2074 | - |
|
| 2075 | - protected function load_js_chosen() |
|
| 2076 | - { |
|
| 2077 | - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
| 2078 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - protected function load_js_jqueryui() |
|
| 2082 | - { |
|
| 2083 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2084 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - protected function load_js_uploader() |
|
| 2088 | - { |
|
| 2089 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2090 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); |
|
| 2091 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); |
|
| 2092 | - |
|
| 2093 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2094 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); |
|
| 2095 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); |
|
| 2096 | - |
|
| 2097 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); |
|
| 2098 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); |
|
| 2099 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); |
|
| 2100 | - } |
|
| 2101 | - |
|
| 2102 | - protected function get_layout() |
|
| 2103 | - { |
|
| 2104 | - $js_files = $this->get_js_files(); |
|
| 2105 | - $css_files = $this->get_css_files(); |
|
| 2106 | - |
|
| 2107 | - $js_lib_files = $this->get_js_lib_files(); |
|
| 2108 | - $js_config_files = $this->get_js_config_files(); |
|
| 2109 | - |
|
| 2110 | - if ($this->unset_jquery) { |
|
| 2111 | - unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); |
|
| 2112 | - } |
|
| 2113 | - |
|
| 2114 | - if ($this->unset_jquery_ui) { |
|
| 2115 | - unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); |
|
| 2116 | - unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - if ($this->unset_bootstrap) { |
|
| 2120 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); |
|
| 2121 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); |
|
| 2122 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); |
|
| 2123 | - unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); |
|
| 2124 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); |
|
| 2125 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); |
|
| 2126 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); |
|
| 2127 | - unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - if($this->echo_and_die === false) |
|
| 2131 | - { |
|
| 2132 | - /** Initialize JavaScript variables */ |
|
| 2133 | - $js_vars = array( |
|
| 2134 | - 'default_javascript_path' => base_url().$this->default_javascript_path, |
|
| 2135 | - 'default_css_path' => base_url().$this->default_css_path, |
|
| 2136 | - 'default_texteditor_path' => base_url().$this->default_texteditor_path, |
|
| 2137 | - 'default_theme_path' => base_url().$this->default_theme_path, |
|
| 2138 | - 'base_url' => base_url() |
|
| 2139 | - ); |
|
| 2140 | - $this->_add_js_vars($js_vars); |
|
| 2141 | - |
|
| 2142 | - return (object)array( |
|
| 2143 | - 'js_files' => $js_files, |
|
| 2144 | - 'js_lib_files' => $js_lib_files, |
|
| 2145 | - 'js_config_files' => $js_config_files, |
|
| 2146 | - 'css_files' => $css_files, |
|
| 2147 | - 'output' => $this->views_as_string, |
|
| 2148 | - ); |
|
| 2149 | - } |
|
| 2150 | - elseif($this->echo_and_die === true) |
|
| 2151 | - { |
|
| 2152 | - echo $this->views_as_string; |
|
| 2153 | - die(); |
|
| 2154 | - } |
|
| 2155 | - } |
|
| 2156 | - |
|
| 2157 | - protected function update_layout($update_result = false, $state_info = null) |
|
| 2158 | - { |
|
| 2159 | - @ob_end_clean(); |
|
| 2160 | - if($update_result === false) |
|
| 2161 | - { |
|
| 2162 | - echo json_encode(array('success' => $update_result)); |
|
| 2163 | - } |
|
| 2164 | - else |
|
| 2165 | - { |
|
| 2166 | - $success_message = '<p>'.$this->l('update_success_message'); |
|
| 2167 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 2168 | - { |
|
| 2169 | - $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
| 2170 | - } |
|
| 2171 | - $success_message .= '</p>'; |
|
| 2172 | - |
|
| 2173 | - echo json_encode(array( |
|
| 2174 | - 'success' => true , |
|
| 2175 | - 'insert_primary_key' => $update_result, |
|
| 2176 | - 'success_message' => $success_message, |
|
| 2177 | - 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) |
|
| 2178 | - )); |
|
| 2179 | - } |
|
| 2180 | - $this->set_echo_and_die(); |
|
| 2181 | - } |
|
| 2182 | - |
|
| 2183 | - protected function get_integer_input($field_info,$value) |
|
| 2184 | - { |
|
| 2185 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
|
| 2186 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
|
| 2187 | - $extra_attributes = ''; |
|
| 2188 | - if(!empty($field_info->db_max_length)) |
|
| 2189 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2190 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
|
| 2191 | - return $input; |
|
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - protected function get_true_false_input($field_info,$value) |
|
| 2195 | - { |
|
| 2196 | - $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; |
|
| 2197 | - |
|
| 2198 | - $input = "<div class='pretty-radio-buttons'>"; |
|
| 2199 | - |
|
| 2200 | - $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
| 2201 | - $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; |
|
| 2202 | - $input .= |
|
| 2203 | - "<div class=\"radio\"><label> |
|
| 2204 | - <input id='field-{$field_info->name}-true' type=\"radio\" name=\"{$field_info->name}\" value=\"1\" $checked /> |
|
| 2205 | - $true_string |
|
| 2206 | - </label> </div>"; |
|
| 2207 | - |
|
| 2208 | - $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
| 2209 | - $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; |
|
| 2210 | - $input .= |
|
| 2211 | - "<div class=\"radio\"><label> |
|
| 2212 | - <input id='field-{$field_info->name}-false' type=\"radio\" name=\"{$field_info->name}\" value=\"0\" $checked /> |
|
| 2213 | - $false_string |
|
| 2214 | - </label> </div>"; |
|
| 2215 | - |
|
| 2216 | - $input .= "</div>"; |
|
| 2217 | - |
|
| 2218 | - return $input; |
|
| 2219 | - } |
|
| 768 | + return $validation_result; |
|
| 769 | + } |
|
| 2220 | 770 | |
| 2221 | - protected function get_string_input($field_info,$value) |
|
| 2222 | - { |
|
| 2223 | - $value = !is_string($value) ? '' : str_replace('"',""",$value); |
|
| 771 | + protected function form_validation() |
|
| 772 | + { |
|
| 773 | + if($this->form_validation === null) |
|
| 774 | + { |
|
| 775 | + $this->form_validation = new grocery_CRUD_Form_validation(); |
|
| 776 | + $ci = &get_instance(); |
|
| 777 | + $ci->load->library('form_validation'); |
|
| 778 | + $ci->form_validation = $this->form_validation; |
|
| 779 | + } |
|
| 780 | + return $this->form_validation; |
|
| 781 | + } |
|
| 2224 | 782 | |
| 2225 | - $extra_attributes = ''; |
|
| 2226 | - if (!empty($field_info->db_max_length)) { |
|
| 783 | + protected function db_update_validation() |
|
| 784 | + { |
|
| 785 | + $validation_result = (object)array('success'=>false); |
|
| 2227 | 786 | |
| 2228 | - if (in_array($field_info->type, array("decimal", "float"))) { |
|
| 2229 | - $decimal_lentgh = explode(",", $field_info->db_max_length); |
|
| 2230 | - $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; |
|
| 787 | + $field_types = $this->get_field_types(); |
|
| 788 | + $required_fields = $this->required_fields; |
|
| 789 | + $unique_fields = $this->_unique_fields; |
|
| 790 | + $edit_fields = $this->get_edit_fields(); |
|
| 2231 | 791 | |
| 2232 | - $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; |
|
| 2233 | - } else { |
|
| 2234 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 792 | + if(!empty($required_fields)) |
|
| 793 | + { |
|
| 794 | + foreach($edit_fields as $edit_field) |
|
| 795 | + { |
|
| 796 | + $field_name = $edit_field->field_name; |
|
| 797 | + if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 798 | + { |
|
| 799 | + $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 800 | + } |
|
| 2235 | 801 | } |
| 2236 | - |
|
| 2237 | 802 | } |
| 2238 | - $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />"; |
|
| 2239 | - return $input; |
|
| 2240 | - } |
|
| 2241 | - |
|
| 2242 | - protected function get_text_input($field_info,$value) |
|
| 2243 | - { |
|
| 2244 | - if($field_info->extras == 'text_editor') |
|
| 2245 | - { |
|
| 2246 | - $editor = $this->config->default_text_editor; |
|
| 2247 | - switch ($editor) { |
|
| 2248 | - case 'ckeditor': |
|
| 2249 | - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); |
|
| 2250 | - $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); |
|
| 2251 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); |
|
| 2252 | - break; |
|
| 2253 | - |
|
| 2254 | - case 'tinymce': |
|
| 2255 | - $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); |
|
| 2256 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); |
|
| 2257 | - break; |
|
| 2258 | - |
|
| 2259 | - case 'markitup': |
|
| 2260 | - $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); |
|
| 2261 | - $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); |
|
| 2262 | - |
|
| 2263 | - $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); |
|
| 2264 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); |
|
| 2265 | - break; |
|
| 2266 | - } |
|
| 2267 | - |
|
| 2268 | - $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; |
|
| 2269 | - |
|
| 2270 | - $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; |
|
| 2271 | - } |
|
| 2272 | - else |
|
| 2273 | - { |
|
| 2274 | - $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; |
|
| 2275 | - } |
|
| 2276 | - return $input; |
|
| 2277 | - } |
|
| 2278 | - |
|
| 2279 | - protected function get_datetime_input($field_info,$value) |
|
| 2280 | - { |
|
| 2281 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2282 | - $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); |
|
| 2283 | - $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); |
|
| 2284 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2285 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); |
|
| 2286 | - |
|
| 2287 | - if($this->language !== 'english') |
|
| 2288 | - { |
|
| 2289 | - include($this->default_config_path.'/language_alias.php'); |
|
| 2290 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2291 | - { |
|
| 2292 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
| 2293 | - if(file_exists($i18n_date_js_file)) |
|
| 2294 | - { |
|
| 2295 | - $this->set_js_lib($i18n_date_js_file); |
|
| 2296 | - } |
|
| 2297 | - |
|
| 2298 | - $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; |
|
| 2299 | - if(file_exists($i18n_datetime_js_file)) |
|
| 2300 | - { |
|
| 2301 | - $this->set_js_lib($i18n_datetime_js_file); |
|
| 2302 | - } |
|
| 2303 | - } |
|
| 2304 | - } |
|
| 2305 | - |
|
| 2306 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); |
|
| 2307 | - |
|
| 2308 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ |
|
| 2309 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2310 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2311 | - $datetime = $date.substr($value,10); |
|
| 2312 | - } |
|
| 2313 | - else |
|
| 2314 | - { |
|
| 2315 | - $datetime = ''; |
|
| 2316 | - } |
|
| 2317 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$datetime' maxlength='19' class='datetime-input form-control' /> |
|
| 2318 | - <a class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> |
|
| 2319 | - ({$this->ui_date_format}) hh:mm:ss"; |
|
| 2320 | - return $input; |
|
| 2321 | - } |
|
| 2322 | - |
|
| 2323 | - protected function get_hidden_input($field_info,$value) |
|
| 2324 | - { |
|
| 2325 | - if($field_info->extras !== null && $field_info->extras != false) |
|
| 2326 | - $value = $field_info->extras; |
|
| 2327 | - $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
|
| 2328 | - return $input; |
|
| 2329 | - } |
|
| 2330 | - |
|
| 2331 | - protected function get_password_input($field_info,$value) |
|
| 2332 | - { |
|
| 2333 | - $value = !is_string($value) ? '' : $value; |
|
| 2334 | - |
|
| 2335 | - $extra_attributes = ''; |
|
| 2336 | - if(!empty($field_info->db_max_length)) |
|
| 2337 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2338 | - $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
|
| 2339 | - return $input; |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - protected function get_date_input($field_info,$value) |
|
| 2343 | - { |
|
| 2344 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2345 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2346 | - |
|
| 2347 | - if($this->language !== 'english') |
|
| 2348 | - { |
|
| 2349 | - include($this->default_config_path.'/language_alias.php'); |
|
| 2350 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2351 | - { |
|
| 2352 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
| 2353 | - if(file_exists($i18n_date_js_file)) |
|
| 2354 | - { |
|
| 2355 | - $this->set_js_lib($i18n_date_js_file); |
|
| 2356 | - } |
|
| 2357 | - } |
|
| 2358 | - } |
|
| 2359 | - |
|
| 2360 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); |
|
| 2361 | - |
|
| 2362 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 2363 | - { |
|
| 2364 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2365 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2366 | - } |
|
| 2367 | - else |
|
| 2368 | - { |
|
| 2369 | - $date = ''; |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$date' maxlength='10' class='datepicker-input form-control' /> |
|
| 2373 | - <a class='datepicker-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> (".$this->ui_date_format.")"; |
|
| 2374 | - return $input; |
|
| 2375 | - } |
|
| 2376 | - |
|
| 2377 | - protected function get_dropdown_input($field_info,$value) |
|
| 2378 | - { |
|
| 2379 | - $this->load_js_chosen(); |
|
| 2380 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2381 | - |
|
| 2382 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2383 | - |
|
| 2384 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
| 2385 | - $options = array('' => '') + $field_info->extras; |
|
| 2386 | - foreach($options as $option_value => $option_label) |
|
| 2387 | - { |
|
| 2388 | - $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
| 2389 | - $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
| 2390 | - } |
|
| 2391 | - |
|
| 2392 | - $input .= "</select>"; |
|
| 2393 | - return $input; |
|
| 2394 | - } |
|
| 2395 | - |
|
| 2396 | - protected function get_enum_input($field_info,$value) |
|
| 2397 | - { |
|
| 2398 | - $this->load_js_chosen(); |
|
| 2399 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2400 | - |
|
| 2401 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2402 | - |
|
| 2403 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
| 2404 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2405 | - $options_array = array('' => '') + $options_array; |
|
| 2406 | - |
|
| 2407 | - foreach($options_array as $option) |
|
| 2408 | - { |
|
| 2409 | - $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; |
|
| 2410 | - $input .= "<option value='$option' $selected >$option</option>"; |
|
| 2411 | - } |
|
| 2412 | - |
|
| 2413 | - $input .= "</select>"; |
|
| 2414 | - return $input; |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - protected function get_readonly_input($field_info, $value) |
|
| 2418 | - { |
|
| 2419 | - $read_only_value = " "; |
|
| 2420 | - |
|
| 2421 | - if (!empty($value) && !is_array($value)) { |
|
| 2422 | - $read_only_value = $value; |
|
| 2423 | - } elseif (is_array($value)) { |
|
| 2424 | - $all_values = array_values($value); |
|
| 2425 | - $read_only_value = implode(", ",$all_values); |
|
| 2426 | - } |
|
| 2427 | - |
|
| 2428 | - return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$read_only_value.'</div>'; |
|
| 2429 | - } |
|
| 2430 | - |
|
| 2431 | - protected function get_set_input($field_info,$value) |
|
| 2432 | - { |
|
| 2433 | - $this->load_js_chosen(); |
|
| 2434 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2435 | - |
|
| 2436 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2437 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2438 | - |
|
| 2439 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2440 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
| 2441 | - |
|
| 2442 | - foreach($options_array as $option) |
|
| 2443 | - { |
|
| 2444 | - $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; |
|
| 2445 | - $input .= "<option value='$option' $selected >$option</option>"; |
|
| 2446 | - } |
|
| 2447 | 803 | |
| 2448 | - $input .= "</select>"; |
|
| 2449 | 804 | |
| 2450 | - return $input; |
|
| 2451 | - } |
|
| 805 | + /** Checking for unique fields. If the field value is not unique then |
|
| 806 | + * return a validation error straight away, if not continue... */ |
|
| 807 | + if(!empty($unique_fields)) |
|
| 808 | + { |
|
| 809 | + $form_validation = $this->form_validation(); |
|
| 2452 | 810 | |
| 2453 | - protected function get_multiselect_input($field_info,$value) |
|
| 2454 | - { |
|
| 2455 | - $this->load_js_chosen(); |
|
| 2456 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2457 | - |
|
| 2458 | - $options_array = $field_info->extras; |
|
| 2459 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2460 | - |
|
| 2461 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2462 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
| 2463 | - |
|
| 2464 | - foreach($options_array as $option_value => $option_label) |
|
| 2465 | - { |
|
| 2466 | - $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; |
|
| 2467 | - $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - $input .= "</select>"; |
|
| 2471 | - |
|
| 2472 | - return $input; |
|
| 2473 | - } |
|
| 2474 | - |
|
| 2475 | - protected function get_relation_input($field_info,$value) |
|
| 2476 | - { |
|
| 2477 | - $this->load_js_chosen(); |
|
| 2478 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2479 | - |
|
| 2480 | - $ajax_limitation = 10000; |
|
| 2481 | - $total_rows = $this->get_relation_total_rows($field_info->extras); |
|
| 2482 | - |
|
| 2483 | - |
|
| 2484 | - //Check if we will use ajax for our queries or just clien-side javascript |
|
| 2485 | - $using_ajax = $total_rows > $ajax_limitation ? true : false; |
|
| 2486 | - |
|
| 2487 | - //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 |
|
| 2488 | - $using_ajax = false; |
|
| 2489 | - |
|
| 2490 | - //If total rows are more than the limitation, use the ajax plugin |
|
| 2491 | - $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; |
|
| 2492 | - |
|
| 2493 | - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
| 2494 | - |
|
| 2495 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2496 | - $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; |
|
| 2497 | - $input .= "<option value=''></option>"; |
|
| 2498 | - |
|
| 2499 | - if(!$using_ajax) |
|
| 2500 | - { |
|
| 2501 | - $options_array = $this->get_relation_array($field_info->extras); |
|
| 2502 | - foreach($options_array as $option_value => $option) |
|
| 2503 | - { |
|
| 2504 | - $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
| 2505 | - $input .= "<option value='$option_value' $selected >$option</option>"; |
|
| 2506 | - } |
|
| 2507 | - } |
|
| 2508 | - elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
| 2509 | - { |
|
| 2510 | - $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
|
| 2511 | - foreach($selected_options_array as $option_value => $option) |
|
| 2512 | - { |
|
| 2513 | - $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
|
| 2514 | - } |
|
| 2515 | - } |
|
| 2516 | - |
|
| 2517 | - $input .= "</select>"; |
|
| 2518 | - return $input; |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - protected function get_relation_readonly_input($field_info,$value) |
|
| 2522 | - { |
|
| 2523 | - $options_array = $this->get_relation_array($field_info->extras); |
|
| 2524 | - |
|
| 2525 | - $value = isset($options_array[$value]) ? $options_array[$value] : ''; |
|
| 2526 | - |
|
| 2527 | - return $this->get_readonly_input($field_info, $value); |
|
| 2528 | - } |
|
| 2529 | - |
|
| 2530 | - protected function get_upload_file_readonly_input($field_info,$value) |
|
| 2531 | - { |
|
| 2532 | - $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
| 2533 | - |
|
| 2534 | - $value = !empty($value) ? '<a href="'.$file.'" target="_blank">'.$value.'</a>' : ''; |
|
| 2535 | - |
|
| 2536 | - return $this->get_readonly_input($field_info, $value); |
|
| 2537 | - } |
|
| 2538 | - |
|
| 2539 | - protected function get_relation_n_n_input($field_info_type, $selected_values) |
|
| 2540 | - { |
|
| 2541 | - $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; |
|
| 2542 | - $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; |
|
| 2543 | - |
|
| 2544 | - if($has_priority_field || $is_ie_7) |
|
| 2545 | - { |
|
| 2546 | - $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2547 | - $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); |
|
| 2548 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2549 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); |
|
| 2550 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); |
|
| 2551 | - |
|
| 2552 | - if($this->language !== 'english') |
|
| 2553 | - { |
|
| 2554 | - include($this->default_config_path.'/language_alias.php'); |
|
| 2555 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2556 | - { |
|
| 2557 | - $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; |
|
| 2558 | - if(file_exists($i18n_date_js_file)) |
|
| 2559 | - { |
|
| 2560 | - $this->set_js_lib($i18n_date_js_file); |
|
| 2561 | - } |
|
| 2562 | - } |
|
| 2563 | - } |
|
| 2564 | - } |
|
| 2565 | - else |
|
| 2566 | - { |
|
| 2567 | - $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
| 2568 | - $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
| 2569 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
| 2573 | - |
|
| 2574 | - $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
| 2575 | - $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 2576 | - |
|
| 2577 | - if(empty($unselected_values) && empty($selected_values)) |
|
| 2578 | - { |
|
| 2579 | - $input = "Please add {$field_info_type->display_as} first"; |
|
| 2580 | - } |
|
| 2581 | - else |
|
| 2582 | - { |
|
| 2583 | - $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
|
| 2584 | - $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
|
| 2585 | - |
|
| 2586 | - $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
|
| 2587 | - $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
|
| 2588 | - |
|
| 2589 | - if(!empty($unselected_values)) |
|
| 2590 | - foreach($unselected_values as $id => $name) |
|
| 2591 | - { |
|
| 2592 | - $input .= "<option value='$id'>$name</option>"; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - if(!empty($selected_values)) |
|
| 2596 | - foreach($selected_values as $id => $name) |
|
| 2597 | - { |
|
| 2598 | - $input .= "<option value='$id' selected='selected'>$name</option>"; |
|
| 2599 | - } |
|
| 2600 | - |
|
| 2601 | - $input .= "</select>"; |
|
| 2602 | - } |
|
| 2603 | - |
|
| 2604 | - return $input; |
|
| 2605 | - } |
|
| 2606 | - |
|
| 2607 | - protected function _convert_bytes_ui_to_bytes($bytes_ui) |
|
| 2608 | - { |
|
| 2609 | - $bytes_ui = str_replace(' ','',$bytes_ui); |
|
| 2610 | - if(strstr($bytes_ui,'MB')) |
|
| 2611 | - $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
| 2612 | - elseif(strstr($bytes_ui,'KB')) |
|
| 2613 | - $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
| 2614 | - elseif(strstr($bytes_ui,'B')) |
|
| 2615 | - $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
| 2616 | - else |
|
| 2617 | - $bytes = (int)($bytes_ui); |
|
| 2618 | - |
|
| 2619 | - return $bytes; |
|
| 2620 | - } |
|
| 2621 | - |
|
| 2622 | - protected function get_upload_file_input($field_info, $value) |
|
| 2623 | - { |
|
| 2624 | - $this->load_js_uploader(); |
|
| 2625 | - |
|
| 2626 | - //Fancybox |
|
| 2627 | - $this->load_js_fancybox(); |
|
| 2628 | - |
|
| 2629 | - $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); |
|
| 2630 | - |
|
| 2631 | - $unique = mt_rand(); |
|
| 2632 | - |
|
| 2633 | - $allowed_files = $this->config->file_upload_allow_file_types; |
|
| 2634 | - $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); |
|
| 2635 | - $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
| 2636 | - $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
| 2637 | - |
|
| 2638 | - $this->_inline_js(' |
|
| 2639 | - var upload_info_'.$unique.' = { |
|
| 2640 | - accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, |
|
| 2641 | - accepted_file_types_ui : "'.$allowed_files_ui.'", |
|
| 2642 | - max_file_size: '.$max_file_size_bytes.', |
|
| 2643 | - max_file_size_ui: "'.$max_file_size_ui.'" |
|
| 2644 | - }; |
|
| 2645 | - |
|
| 2646 | - var string_upload_file = "'.$this->l('form_upload_a_file').'"; |
|
| 2647 | - var string_delete_file = "'.$this->l('string_delete_file').'"; |
|
| 2648 | - var string_progress = "'.$this->l('string_progress').'"; |
|
| 2649 | - var error_on_uploading = "'.$this->l('error_on_uploading').'"; |
|
| 2650 | - var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; |
|
| 811 | + $form_validation_check = false; |
|
| 2651 | 812 | |
| 2652 | - var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; |
|
| 2653 | - var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; |
|
| 2654 | - var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; |
|
| 2655 | - var error_min_file_size = "'.$this->l('error_min_file_size').'"; |
|
| 813 | + foreach($edit_fields as $edit_field) |
|
| 814 | + { |
|
| 815 | + $field_name = $edit_field->field_name; |
|
| 816 | + if(in_array( $field_name, $unique_fields) ) |
|
| 817 | + { |
|
| 818 | + $state_info = $this->getStateInfo(); |
|
| 819 | + $primary_key = $this->get_primary_key(); |
|
| 820 | + $field_name_value = $_POST[$field_name]; |
|
| 2656 | 821 | |
| 2657 | - var base_url = "'.base_url().'"; |
|
| 2658 | - var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; |
|
| 2659 | - '); |
|
| 822 | + $this->basic_model->where($primary_key,$state_info->primary_key); |
|
| 823 | + $row = $this->basic_model->get_row(); |
|
| 2660 | 824 | |
| 2661 | - $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
| 2662 | - $file_display_none = empty($value) ? "display:none;" : ""; |
|
| 825 | + if(!isset($row->$field_name)) { |
|
| 826 | + throw new Exception("The field name doesn't exist in the database. ". |
|
| 827 | + "Please use the unique fields only for fields ". |
|
| 828 | + "that exist in the database"); |
|
| 829 | + } |
|
| 2663 | 830 | |
| 2664 | - $is_image = !empty($value) && |
|
| 2665 | - ( substr($value,-4) == '.jpg' |
|
| 2666 | - || substr($value,-4) == '.png' |
|
| 2667 | - || substr($value,-5) == '.jpeg' |
|
| 2668 | - || substr($value,-4) == '.gif' |
|
| 2669 | - || substr($value,-5) == '.tiff') |
|
| 2670 | - ? true : false; |
|
| 831 | + $previous_field_name_value = $row->$field_name; |
|
| 2671 | 832 | |
| 2672 | - $image_class = $is_image ? 'image-thumbnail' : ''; |
|
| 833 | + if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
| 834 | + $form_validation->set_rules( $field_name, |
|
| 835 | + $field_types[$field_name]->display_as, |
|
| 836 | + 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
|
| 2673 | 837 | |
| 2674 | - $input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'"> |
|
| 2675 | - <span>'.$this->l('form_upload_a_file').'</span> |
|
| 2676 | - <input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'"> |
|
| 2677 | - <input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" /> |
|
| 2678 | - </span>'; |
|
| 838 | + $form_validation_check = true; |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + } |
|
| 2679 | 842 | |
| 2680 | - $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); |
|
| 2681 | - |
|
| 2682 | - $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
| 2683 | - |
|
| 2684 | - $input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>"; |
|
| 2685 | - $input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>"; |
|
| 2686 | - $input .= "<a href='".$file_url."' id='file_$unique' class='open-file"; |
|
| 2687 | - $input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value"; |
|
| 2688 | - $input .= "</a> "; |
|
| 2689 | - $input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> "; |
|
| 2690 | - $input .= "</div><div style='clear:both'></div>"; |
|
| 2691 | - $input .= "<div id='loading-$unique' style='display:none'><span id='upload-state-message-$unique'></span> <span class='qq-upload-spinner'></span> <span id='progress-$unique'></span></div>"; |
|
| 2692 | - $input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>"; |
|
| 2693 | - $input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>"; |
|
| 2694 | - |
|
| 2695 | - return $input; |
|
| 2696 | - } |
|
| 2697 | - |
|
| 2698 | - protected function get_add_hidden_fields() |
|
| 2699 | - { |
|
| 2700 | - return $this->add_hidden_fields; |
|
| 2701 | - } |
|
| 2702 | - |
|
| 2703 | - protected function get_edit_hidden_fields() |
|
| 2704 | - { |
|
| 2705 | - return $this->edit_hidden_fields; |
|
| 2706 | - } |
|
| 2707 | - |
|
| 2708 | - protected function get_add_input_fields($field_values = null) |
|
| 2709 | - { |
|
| 2710 | - $fields = $this->get_add_fields(); |
|
| 2711 | - $types = $this->get_field_types(); |
|
| 2712 | - |
|
| 2713 | - $input_fields = array(); |
|
| 2714 | - |
|
| 2715 | - foreach($fields as $field_num => $field) |
|
| 2716 | - { |
|
| 2717 | - $field_info = $types[$field->field_name]; |
|
| 2718 | - |
|
| 2719 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2720 | - |
|
| 2721 | - if(!isset($this->callback_add_field[$field->field_name])) |
|
| 2722 | - { |
|
| 2723 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2724 | - } |
|
| 2725 | - else |
|
| 2726 | - { |
|
| 2727 | - $field_input = $field_info; |
|
| 2728 | - $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); |
|
| 2729 | - } |
|
| 2730 | - |
|
| 2731 | - switch ($field_info->crud_type) { |
|
| 2732 | - case 'invisible': |
|
| 2733 | - unset($this->add_fields[$field_num]); |
|
| 2734 | - unset($fields[$field_num]); |
|
| 2735 | - continue; |
|
| 2736 | - break; |
|
| 2737 | - case 'hidden': |
|
| 2738 | - $this->add_hidden_fields[] = $field_input; |
|
| 2739 | - unset($this->add_fields[$field_num]); |
|
| 2740 | - unset($fields[$field_num]); |
|
| 2741 | - continue; |
|
| 2742 | - break; |
|
| 2743 | - } |
|
| 2744 | - |
|
| 2745 | - $input_fields[$field->field_name] = $field_input; |
|
| 2746 | - } |
|
| 2747 | - |
|
| 2748 | - return $input_fields; |
|
| 2749 | - } |
|
| 2750 | - |
|
| 2751 | - protected function get_edit_input_fields($field_values = null) |
|
| 2752 | - { |
|
| 2753 | - $fields = $this->get_edit_fields(); |
|
| 2754 | - $types = $this->get_field_types(); |
|
| 2755 | - |
|
| 2756 | - $input_fields = array(); |
|
| 2757 | - |
|
| 2758 | - foreach($fields as $field_num => $field) |
|
| 2759 | - { |
|
| 2760 | - $field_info = $types[$field->field_name]; |
|
| 2761 | - |
|
| 2762 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2763 | - if(!isset($this->callback_edit_field[$field->field_name])) |
|
| 2764 | - { |
|
| 2765 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2766 | - } |
|
| 2767 | - else |
|
| 2768 | - { |
|
| 2769 | - $primary_key = $this->getStateInfo()->primary_key; |
|
| 2770 | - $field_input = $field_info; |
|
| 2771 | - $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
| 2772 | - } |
|
| 2773 | - |
|
| 2774 | - switch ($field_info->crud_type) { |
|
| 2775 | - case 'invisible': |
|
| 2776 | - unset($this->edit_fields[$field_num]); |
|
| 2777 | - unset($fields[$field_num]); |
|
| 2778 | - continue; |
|
| 2779 | - break; |
|
| 2780 | - case 'hidden': |
|
| 2781 | - $this->edit_hidden_fields[] = $field_input; |
|
| 2782 | - unset($this->edit_fields[$field_num]); |
|
| 2783 | - unset($fields[$field_num]); |
|
| 2784 | - continue; |
|
| 2785 | - break; |
|
| 2786 | - } |
|
| 2787 | - |
|
| 2788 | - $input_fields[$field->field_name] = $field_input; |
|
| 2789 | - } |
|
| 2790 | - |
|
| 2791 | - return $input_fields; |
|
| 2792 | - } |
|
| 2793 | - |
|
| 2794 | - protected function get_read_input_fields($field_values = null) |
|
| 2795 | - { |
|
| 2796 | - $read_fields = $this->get_read_fields(); |
|
| 2797 | - |
|
| 2798 | - $this->field_types = null; |
|
| 2799 | - $this->required_fields = null; |
|
| 2800 | - |
|
| 2801 | - $read_inputs = array(); |
|
| 2802 | - foreach ($read_fields as $field) { |
|
| 2803 | - if (!empty($this->change_field_type) |
|
| 2804 | - && isset($this->change_field_type[$field->field_name]) |
|
| 2805 | - && $this->change_field_type[$field->field_name]->type == 'hidden') { |
|
| 2806 | - continue; |
|
| 2807 | - } |
|
| 2808 | - $this->field_type($field->field_name, 'readonly'); |
|
| 2809 | - } |
|
| 2810 | - |
|
| 2811 | - $fields = $this->get_read_fields(); |
|
| 2812 | - $types = $this->get_field_types(); |
|
| 2813 | - |
|
| 2814 | - $input_fields = array(); |
|
| 2815 | - |
|
| 2816 | - foreach($fields as $field_num => $field) |
|
| 2817 | - { |
|
| 2818 | - $field_info = $types[$field->field_name]; |
|
| 2819 | - |
|
| 2820 | - $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2821 | - if(!isset($this->callback_read_field[$field->field_name])) |
|
| 2822 | - { |
|
| 2823 | - $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2824 | - } |
|
| 2825 | - else |
|
| 2826 | - { |
|
| 2827 | - $primary_key = $this->getStateInfo()->primary_key; |
|
| 2828 | - $field_input = $field_info; |
|
| 2829 | - $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
| 2830 | - } |
|
| 2831 | - |
|
| 2832 | - switch ($field_info->crud_type) { |
|
| 2833 | - case 'invisible': |
|
| 2834 | - unset($this->read_fields[$field_num]); |
|
| 2835 | - unset($fields[$field_num]); |
|
| 2836 | - continue; |
|
| 2837 | - break; |
|
| 2838 | - case 'hidden': |
|
| 2839 | - $this->read_hidden_fields[] = $field_input; |
|
| 2840 | - unset($this->read_fields[$field_num]); |
|
| 2841 | - unset($fields[$field_num]); |
|
| 2842 | - continue; |
|
| 2843 | - break; |
|
| 2844 | - } |
|
| 2845 | - |
|
| 2846 | - $input_fields[$field->field_name] = $field_input; |
|
| 2847 | - } |
|
| 2848 | - |
|
| 2849 | - return $input_fields; |
|
| 2850 | - } |
|
| 2851 | - |
|
| 2852 | - protected function setThemeBasics() |
|
| 2853 | - { |
|
| 2854 | - $this->theme_path = $this->default_theme_path; |
|
| 2855 | - if(substr($this->theme_path,-1) != '/') |
|
| 2856 | - $this->theme_path = $this->theme_path.'/'; |
|
| 2857 | - |
|
| 2858 | - include($this->theme_path.$this->theme.'/config.php'); |
|
| 2859 | - |
|
| 2860 | - $this->theme_config = $config; |
|
| 2861 | - } |
|
| 2862 | - |
|
| 2863 | - public function set_theme($theme = null) |
|
| 2864 | - { |
|
| 2865 | - $this->theme = $theme; |
|
| 2866 | - |
|
| 2867 | - return $this; |
|
| 2868 | - } |
|
| 2869 | - |
|
| 2870 | - protected function _get_ajax_results() |
|
| 2871 | - { |
|
| 2872 | - //This is a $_POST request rather that $_GET request , because |
|
| 2873 | - //Codeigniter doesn't like the $_GET requests so much! |
|
| 2874 | - if ($this->_is_ajax()) { |
|
| 2875 | - @ob_end_clean(); |
|
| 2876 | - $results= (object)array( |
|
| 2877 | - 'output' => $this->views_as_string, |
|
| 2878 | - 'js_files' => array_values($this->get_js_files()), |
|
| 2879 | - 'js_lib_files' => array_values($this->get_js_lib_files()), |
|
| 2880 | - 'js_config_files' => array_values($this->get_js_config_files()), |
|
| 2881 | - 'css_files' => array_values($this->get_css_files()) |
|
| 2882 | - ); |
|
| 2883 | - |
|
| 2884 | - echo json_encode($results); |
|
| 2885 | - die; |
|
| 2886 | - } |
|
| 2887 | - //else just continue |
|
| 2888 | - } |
|
| 2889 | - |
|
| 2890 | - protected function _is_ajax() |
|
| 2891 | - { |
|
| 2892 | - return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
|
| 2893 | - } |
|
| 2894 | - |
|
| 2895 | - protected function _theme_view($view, $vars = array(), $return = FALSE) |
|
| 2896 | - { |
|
| 2897 | - $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; |
|
| 2898 | - |
|
| 2899 | - $file_exists = FALSE; |
|
| 2900 | - |
|
| 2901 | - $ext = pathinfo($view, PATHINFO_EXTENSION); |
|
| 2902 | - $file = ($ext == '') ? $view.'.php' : $view; |
|
| 2903 | - |
|
| 2904 | - $view_file = $this->theme_path.$this->theme.'/views/'; |
|
| 2905 | - |
|
| 2906 | - if (file_exists($view_file.$file)) |
|
| 2907 | - { |
|
| 2908 | - $path = $view_file.$file; |
|
| 2909 | - $file_exists = TRUE; |
|
| 2910 | - } |
|
| 2911 | - |
|
| 2912 | - if ( ! $file_exists) |
|
| 2913 | - { |
|
| 2914 | - throw new Exception('Unable to load the requested file: '.$file, 16); |
|
| 2915 | - } |
|
| 2916 | - |
|
| 2917 | - extract($vars); |
|
| 2918 | - |
|
| 2919 | - #region buffering... |
|
| 2920 | - ob_start(); |
|
| 2921 | - |
|
| 2922 | - include($path); |
|
| 2923 | - |
|
| 2924 | - $buffer = ob_get_contents(); |
|
| 2925 | - @ob_end_clean(); |
|
| 2926 | - #endregion |
|
| 2927 | - |
|
| 2928 | - if ($return === TRUE) |
|
| 2929 | - { |
|
| 2930 | - return $buffer; |
|
| 2931 | - } |
|
| 2932 | - |
|
| 2933 | - $this->views_as_string .= $buffer; |
|
| 2934 | - } |
|
| 2935 | - |
|
| 2936 | - protected function _inline_js($inline_js = '') |
|
| 2937 | - { |
|
| 2938 | - $this->views_as_string .= "<script type=\"text/javascript\">\n{$inline_js}\n</script>\n"; |
|
| 2939 | - } |
|
| 2940 | - |
|
| 2941 | - protected function _add_js_vars($js_vars = array()) |
|
| 2942 | - { |
|
| 2943 | - $javascript_as_string = "<script type=\"text/javascript\">\n"; |
|
| 2944 | - foreach ($js_vars as $js_var => $js_value) { |
|
| 2945 | - $javascript_as_string .= "\tvar $js_var = '$js_value';\n"; |
|
| 2946 | - } |
|
| 2947 | - $javascript_as_string .= "\n</script>\n"; |
|
| 2948 | - $this->views_as_string .= $javascript_as_string; |
|
| 2949 | - } |
|
| 2950 | - |
|
| 2951 | - protected function get_views_as_string() |
|
| 2952 | - { |
|
| 2953 | - if(!empty($this->views_as_string)) |
|
| 2954 | - return $this->views_as_string; |
|
| 2955 | - else |
|
| 2956 | - return null; |
|
| 2957 | - } |
|
| 2958 | -} |
|
| 843 | + if($form_validation_check && !$form_validation->run()) |
|
| 844 | + { |
|
| 845 | + $validation_result->error_message = $form_validation->error_string(); |
|
| 846 | + $validation_result->error_fields = $form_validation->_error_array; |
|
| 2959 | 847 | |
| 848 | + return $validation_result; |
|
| 849 | + } |
|
| 850 | + } |
|
| 2960 | 851 | |
| 2961 | -/** |
|
| 2962 | - * PHP grocery CRUD |
|
| 2963 | - * |
|
| 2964 | - * LICENSE |
|
| 2965 | - * |
|
| 2966 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 2967 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 2968 | - * Please see the corresponding license file for details of these licenses. |
|
| 2969 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 2970 | - * |
|
| 2971 | - * @package grocery CRUD |
|
| 2972 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 2973 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 2974 | - * @author John Skoumbourdis <[email protected]> |
|
| 2975 | - */ |
|
| 852 | + if(!empty($this->validation_rules)) |
|
| 853 | + { |
|
| 854 | + $form_validation = $this->form_validation(); |
|
| 2976 | 855 | |
| 2977 | -// ------------------------------------------------------------------------ |
|
| 856 | + $edit_fields = $this->get_edit_fields(); |
|
| 2978 | 857 | |
| 2979 | -/** |
|
| 2980 | - * PHP grocery States |
|
| 2981 | - * |
|
| 2982 | - * States of grocery CRUD |
|
| 2983 | - * |
|
| 2984 | - * @package grocery CRUD |
|
| 2985 | - * @author John Skoumbourdis <[email protected]> |
|
| 2986 | - * @version 1.5.6 |
|
| 2987 | - */ |
|
| 2988 | -class grocery_CRUD_States extends grocery_CRUD_Layout |
|
| 2989 | -{ |
|
| 2990 | - const STATE_UNKNOWN = 0; |
|
| 2991 | - const STATE_LIST = 1; |
|
| 2992 | - const STATE_ADD = 2; |
|
| 2993 | - const STATE_EDIT = 3; |
|
| 2994 | - const STATE_DELETE = 4; |
|
| 2995 | - const STATE_INSERT = 5; |
|
| 858 | + foreach($edit_fields as $edit_field) |
|
| 859 | + { |
|
| 860 | + $field_name = $edit_field->field_name; |
|
| 861 | + if(isset($this->validation_rules[$field_name])) |
|
| 862 | + { |
|
| 863 | + $rule = $this->validation_rules[$field_name]; |
|
| 864 | + $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 865 | + } |
|
| 866 | + } |
|
| 2996 | 867 | |
| 2997 | - const STATE_READ = 18; |
|
| 2998 | - const STATE_DELETE_MULTIPLE = '19'; |
|
| 868 | + if($form_validation->run()) |
|
| 869 | + { |
|
| 870 | + $validation_result->success = true; |
|
| 871 | + } |
|
| 872 | + else |
|
| 873 | + { |
|
| 874 | + $validation_result->error_message = $form_validation->error_string(); |
|
| 875 | + $validation_result->error_fields = $form_validation->_error_array; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + else |
|
| 879 | + { |
|
| 880 | + $validation_result->success = true; |
|
| 881 | + } |
|
| 2999 | 882 | |
| 3000 | - protected $states = array( |
|
| 3001 | - 0 => 'unknown', |
|
| 3002 | - 1 => 'list', |
|
| 3003 | - 2 => 'add', |
|
| 3004 | - 3 => 'edit', |
|
| 3005 | - 4 => 'delete', |
|
| 3006 | - 5 => 'insert', |
|
| 3007 | - 6 => 'update', |
|
| 3008 | - 7 => 'ajax_list', |
|
| 3009 | - 8 => 'ajax_list_info', |
|
| 3010 | - 9 => 'insert_validation', |
|
| 3011 | - 10 => 'update_validation', |
|
| 3012 | - 11 => 'upload_file', |
|
| 3013 | - 12 => 'delete_file', |
|
| 3014 | - 13 => 'ajax_relation', |
|
| 3015 | - 14 => 'ajax_relation_n_n', |
|
| 3016 | - 15 => 'success', |
|
| 3017 | - 16 => 'export', |
|
| 3018 | - 17 => 'print', |
|
| 3019 | - 18 => 'read', |
|
| 3020 | - 19 => 'delete_multiple' |
|
| 3021 | - ); |
|
| 883 | + return $validation_result; |
|
| 884 | + } |
|
| 3022 | 885 | |
| 3023 | - public function getStateInfo() |
|
| 886 | + protected function db_insert($state_info) |
|
| 3024 | 887 | { |
| 3025 | - $state_code = $this->getStateCode(); |
|
| 3026 | - $segment_object = $this->get_state_info_from_url(); |
|
| 888 | + $validation_result = $this->db_insert_validation(); |
|
| 3027 | 889 | |
| 3028 | - $first_parameter = $segment_object->first_parameter; |
|
| 3029 | - $second_parameter = $segment_object->second_parameter; |
|
| 890 | + if($validation_result->success) |
|
| 891 | + { |
|
| 892 | + $post_data = $state_info->unwrapped_data; |
|
| 3030 | 893 | |
| 3031 | - $state_info = (object)array(); |
|
| 894 | + $add_fields = $this->get_add_fields(); |
|
| 3032 | 895 | |
| 3033 | - switch ($state_code) { |
|
| 3034 | - case self::STATE_LIST: |
|
| 3035 | - case self::STATE_ADD: |
|
| 3036 | - //for now... do nothing! Keeping this switch here in case we need any information at the future. |
|
| 3037 | - break; |
|
| 896 | + if($this->callback_insert === null) |
|
| 897 | + { |
|
| 898 | + if($this->callback_before_insert !== null) |
|
| 899 | + { |
|
| 900 | + $callback_return = call_user_func($this->callback_before_insert, $post_data); |
|
| 3038 | 901 | |
| 3039 | - case self::STATE_EDIT: |
|
| 3040 | - case self::STATE_READ: |
|
| 3041 | - if ($first_parameter !== null) { |
|
| 3042 | - $state_info = (object) array('primary_key' => $first_parameter); |
|
| 3043 | - } else { |
|
| 3044 | - throw new Exception('On the state "edit" the Primary key cannot be null', 6); |
|
| 3045 | - die(); |
|
| 902 | + if(!empty($callback_return) && is_array($callback_return)) |
|
| 903 | + $post_data = $callback_return; |
|
| 904 | + elseif($callback_return === false) |
|
| 905 | + return false; |
|
| 3046 | 906 | } |
| 3047 | - break; |
|
| 3048 | 907 | |
| 3049 | - case self::STATE_DELETE: |
|
| 3050 | - if ($first_parameter !== null) { |
|
| 3051 | - $state_info = (object) array('primary_key' => $first_parameter); |
|
| 3052 | - } else { |
|
| 3053 | - throw new Exception('On the state "delete" the Primary key cannot be null',7); |
|
| 3054 | - die(); |
|
| 3055 | - } |
|
| 3056 | - break; |
|
| 908 | + $insert_data = array(); |
|
| 909 | + $types = $this->get_field_types(); |
|
| 910 | + foreach($add_fields as $num_row => $field) |
|
| 911 | + { |
|
| 912 | + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
| 913 | + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 914 | + { |
|
| 915 | + $post_data[$field->field_name] = array(); |
|
| 916 | + } |
|
| 3057 | 917 | |
| 3058 | - case self::STATE_DELETE_MULTIPLE: |
|
| 3059 | - if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { |
|
| 3060 | - $state_info = (object) array('ids' => $_POST['ids']); |
|
| 3061 | - } else { |
|
| 3062 | - throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); |
|
| 3063 | - die(); |
|
| 918 | + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 919 | + { |
|
| 920 | + 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])) |
|
| 921 | + { |
|
| 922 | + $insert_data[$field->field_name] = null; |
|
| 923 | + } |
|
| 924 | + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 925 | + { |
|
| 926 | + $insert_data[$field->field_name] = null; |
|
| 927 | + } |
|
| 928 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 929 | + { |
|
| 930 | + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
| 931 | + } |
|
| 932 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 933 | + { |
|
| 934 | + //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
| 935 | + } |
|
| 936 | + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 937 | + { |
|
| 938 | + $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 939 | + } |
|
| 940 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 941 | + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 942 | + substr($post_data[$field->field_name],10); |
|
| 943 | + } |
|
| 944 | + else |
|
| 945 | + { |
|
| 946 | + $insert_data[$field->field_name] = $post_data[$field->field_name]; |
|
| 947 | + } |
|
| 948 | + } |
|
| 3064 | 949 | } |
| 3065 | - break; |
|
| 3066 | 950 | |
| 3067 | - case self::STATE_INSERT: |
|
| 3068 | - if(!empty($_POST)) |
|
| 951 | + $insert_result = $this->basic_model->db_insert($insert_data); |
|
| 952 | + |
|
| 953 | + if($insert_result !== false) |
|
| 3069 | 954 | { |
| 3070 | - $state_info = (object)array('unwrapped_data' => $_POST); |
|
| 955 | + $insert_primary_key = $insert_result; |
|
| 3071 | 956 | } |
| 3072 | 957 | else |
| 3073 | 958 | { |
| 3074 | - throw new Exception('On the state "insert" you must have post data',8); |
|
| 3075 | - die(); |
|
| 959 | + return false; |
|
| 3076 | 960 | } |
| 3077 | - break; |
|
| 3078 | 961 | |
| 3079 | - case 6: |
|
| 3080 | - if(!empty($_POST) && $first_parameter !== null) |
|
| 3081 | - { |
|
| 3082 | - $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
|
| 3083 | - } |
|
| 3084 | - elseif(empty($_POST)) |
|
| 962 | + if(!empty($this->relation_n_n)) |
|
| 3085 | 963 | { |
| 3086 | - throw new Exception('On the state "update" you must have post data',9); |
|
| 3087 | - die(); |
|
| 964 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
| 965 | + { |
|
| 966 | + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 967 | + $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); |
|
| 968 | + } |
|
| 3088 | 969 | } |
| 3089 | - else |
|
| 970 | + |
|
| 971 | + if($this->callback_after_insert !== null) |
|
| 3090 | 972 | { |
| 3091 | - throw new Exception('On the state "update" the Primary key cannot be null',10); |
|
| 3092 | - die(); |
|
| 973 | + $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); |
|
| 974 | + |
|
| 975 | + if($callback_return === false) |
|
| 976 | + { |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 979 | + |
|
| 3093 | 980 | } |
| 3094 | - break; |
|
| 981 | + }else |
|
| 982 | + { |
|
| 983 | + $callback_return = call_user_func($this->callback_insert, $post_data); |
|
| 3095 | 984 | |
| 3096 | - case 7: |
|
| 3097 | - case 8: |
|
| 3098 | - case 16: //export to excel |
|
| 3099 | - case 17: //print |
|
| 3100 | - $state_info = (object)array(); |
|
| 3101 | - if(!empty($_POST['per_page'])) |
|
| 985 | + if($callback_return === false) |
|
| 986 | + { |
|
| 987 | + return false; |
|
| 988 | + } |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + if(isset($insert_primary_key)) |
|
| 992 | + return $insert_primary_key; |
|
| 993 | + else |
|
| 994 | + return true; |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + return false; |
|
| 998 | + |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + protected function db_update($state_info) |
|
| 1002 | + { |
|
| 1003 | + $validation_result = $this->db_update_validation(); |
|
| 1004 | + |
|
| 1005 | + $edit_fields = $this->get_edit_fields(); |
|
| 1006 | + |
|
| 1007 | + if($validation_result->success) |
|
| 1008 | + { |
|
| 1009 | + $post_data = $state_info->unwrapped_data; |
|
| 1010 | + $primary_key = $state_info->primary_key; |
|
| 1011 | + |
|
| 1012 | + if($this->callback_update === null) |
|
| 1013 | + { |
|
| 1014 | + if($this->callback_before_update !== null) |
|
| 3102 | 1015 | { |
| 3103 | - $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; |
|
| 1016 | + $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); |
|
| 1017 | + |
|
| 1018 | + if(!empty($callback_return) && is_array($callback_return)) |
|
| 1019 | + { |
|
| 1020 | + $post_data = $callback_return; |
|
| 1021 | + } |
|
| 1022 | + elseif($callback_return === false) |
|
| 1023 | + { |
|
| 1024 | + return false; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 3104 | 1027 | } |
| 3105 | - if(!empty($_POST['page'])) |
|
| 1028 | + |
|
| 1029 | + $update_data = array(); |
|
| 1030 | + $types = $this->get_field_types(); |
|
| 1031 | + foreach($edit_fields as $num_row => $field) |
|
| 3106 | 1032 | { |
| 3107 | - $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; |
|
| 1033 | + /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
|
| 1034 | + if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 1035 | + { |
|
| 1036 | + $post_data[$field->field_name] = array(); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 1040 | + { |
|
| 1041 | + 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])) |
|
| 1042 | + { |
|
| 1043 | + $update_data[$field->field_name] = null; |
|
| 1044 | + } |
|
| 1045 | + elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1046 | + { |
|
| 1047 | + $update_data[$field->field_name] = null; |
|
| 1048 | + } |
|
| 1049 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1050 | + { |
|
| 1051 | + $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
|
| 1052 | + } |
|
| 1053 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1054 | + { |
|
| 1055 | + //This empty if statement is to make sure that a readonly field will never inserted/updated |
|
| 1056 | + } |
|
| 1057 | + elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1058 | + { |
|
| 1059 | + $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 1060 | + } |
|
| 1061 | + elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 1062 | + $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 1063 | + substr($post_data[$field->field_name],10); |
|
| 1064 | + } |
|
| 1065 | + else |
|
| 1066 | + { |
|
| 1067 | + $update_data[$field->field_name] = $post_data[$field->field_name]; |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 3108 | 1070 | } |
| 3109 | - //If we request an export or a print we don't care about what page we are |
|
| 3110 | - if($state_code === 16 || $state_code === 17) |
|
| 1071 | + |
|
| 1072 | + if($this->basic_model->db_update($update_data, $primary_key) === false) |
|
| 3111 | 1073 | { |
| 3112 | - $state_info->page = 1; |
|
| 3113 | - $state_info->per_page = 1000000; //a very big number! |
|
| 1074 | + return false; |
|
| 3114 | 1075 | } |
| 3115 | - if(!empty($_POST['order_by'][0])) |
|
| 1076 | + |
|
| 1077 | + if(!empty($this->relation_n_n)) |
|
| 3116 | 1078 | { |
| 3117 | - $state_info->order_by = $_POST['order_by']; |
|
| 1079 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1080 | + { |
|
| 1081 | + if ( $this->unset_edit_fields !== null |
|
| 1082 | + && is_array($this->unset_edit_fields) |
|
| 1083 | + && in_array($field_name,$this->unset_edit_fields) |
|
| 1084 | + ) { |
|
| 1085 | + continue; |
|
| 1086 | + } |
|
| 1087 | + |
|
| 1088 | + $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 1089 | + $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); |
|
| 1090 | + } |
|
| 3118 | 1091 | } |
| 3119 | - if(!empty($_POST['search_text'])) |
|
| 1092 | + |
|
| 1093 | + if($this->callback_after_update !== null) |
|
| 3120 | 1094 | { |
| 3121 | - if(empty($_POST['search_field'])) |
|
| 1095 | + $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); |
|
| 1096 | + |
|
| 1097 | + if($callback_return === false) |
|
| 3122 | 1098 | { |
| 3123 | - $search_text = strip_tags($_POST['search_field']); |
|
| 3124 | - $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
|
| 1099 | + return false; |
|
| 3125 | 1100 | } |
| 3126 | - else |
|
| 1101 | + |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + else |
|
| 1105 | + { |
|
| 1106 | + $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
|
| 1107 | + |
|
| 1108 | + if($callback_return === false) |
|
| 1109 | + { |
|
| 1110 | + return false; |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + return true; |
|
| 1115 | + } |
|
| 1116 | + else |
|
| 1117 | + { |
|
| 1118 | + return false; |
|
| 1119 | + } |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + protected function _convert_date_to_sql_date($date) |
|
| 1123 | + { |
|
| 1124 | + $date = substr($date,0,10); |
|
| 1125 | + if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) |
|
| 1126 | + { |
|
| 1127 | + //If it's already a sql-date don't convert it! |
|
| 1128 | + return $date; |
|
| 1129 | + }elseif(empty($date)) |
|
| 1130 | + { |
|
| 1131 | + return ''; |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + $date_array = preg_split( '/[-\.\/ ]/', $date); |
|
| 1135 | + if($this->php_date_format == 'd/m/Y') |
|
| 1136 | + { |
|
| 1137 | + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
|
| 1138 | + } |
|
| 1139 | + elseif($this->php_date_format == 'm/d/Y') |
|
| 1140 | + { |
|
| 1141 | + $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
|
| 1142 | + } |
|
| 1143 | + else |
|
| 1144 | + { |
|
| 1145 | + $sql_date = $date; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $sql_date; |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + protected function _get_field_names_to_search(array $relation_values) |
|
| 1152 | + { |
|
| 1153 | + if(!strstr($relation_values[2],'{')) |
|
| 1154 | + return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
| 1155 | + else |
|
| 1156 | + { |
|
| 1157 | + $relation_values[2] = ' '.$relation_values[2].' '; |
|
| 1158 | + $temp1 = explode('{',$relation_values[2]); |
|
| 1159 | + unset($temp1[0]); |
|
| 1160 | + |
|
| 1161 | + $field_names_array = array(); |
|
| 1162 | + foreach($temp1 as $field) |
|
| 1163 | + list($field_names_array[]) = explode('}',$field); |
|
| 1164 | + |
|
| 1165 | + return $field_names_array; |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + protected function _unique_join_name($field_name) |
|
| 1170 | + { |
|
| 1171 | + return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + protected function _unique_field_name($field_name) |
|
| 1175 | + { |
|
| 1176 | + return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + protected function db_multiple_delete($state_info) |
|
| 1180 | + { |
|
| 1181 | + foreach ($state_info->ids as $delete_id) { |
|
| 1182 | + $result = $this->db_delete((object)array('primary_key' => $delete_id)); |
|
| 1183 | + if (!$result) { |
|
| 1184 | + return false; |
|
| 1185 | + } |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + return true; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + protected function db_delete($state_info) |
|
| 1192 | + { |
|
| 1193 | + $primary_key_value = $state_info->primary_key; |
|
| 1194 | + |
|
| 1195 | + if($this->callback_delete === null) |
|
| 1196 | + { |
|
| 1197 | + if($this->callback_before_delete !== null) |
|
| 1198 | + { |
|
| 1199 | + $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); |
|
| 1200 | + |
|
| 1201 | + if($callback_return === false) |
|
| 1202 | + { |
|
| 1203 | + return false; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + if(!empty($this->relation_n_n)) |
|
| 1209 | + { |
|
| 1210 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1211 | + { |
|
| 1212 | + $this->db_relation_n_n_delete( $field_info, $primary_key_value ); |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + $delete_result = $this->basic_model->db_delete($primary_key_value); |
|
| 1217 | + |
|
| 1218 | + if($delete_result === false) |
|
| 1219 | + { |
|
| 1220 | + return false; |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + if($this->callback_after_delete !== null) |
|
| 1224 | + { |
|
| 1225 | + $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); |
|
| 1226 | + |
|
| 1227 | + if($callback_return === false) |
|
| 1228 | + { |
|
| 1229 | + return false; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + else |
|
| 1235 | + { |
|
| 1236 | + $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
|
| 1237 | + |
|
| 1238 | + if($callback_return === false) |
|
| 1239 | + { |
|
| 1240 | + return false; |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + return true; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) |
|
| 1248 | + { |
|
| 1249 | + $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + protected function db_relation_n_n_delete($field_info, $primary_key_value) |
|
| 1253 | + { |
|
| 1254 | + $this->basic_model->db_relation_n_n_delete($field_info, $primary_key_value); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + protected function get_list() |
|
| 1258 | + { |
|
| 1259 | + if(!empty($this->order_by)) |
|
| 1260 | + $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
| 1261 | + |
|
| 1262 | + if(!empty($this->where)) |
|
| 1263 | + foreach($this->where as $where) |
|
| 1264 | + $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 1265 | + |
|
| 1266 | + if(!empty($this->or_where)) |
|
| 1267 | + foreach($this->or_where as $or_where) |
|
| 1268 | + $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 1269 | + |
|
| 1270 | + if(!empty($this->like)) |
|
| 1271 | + foreach($this->like as $like) |
|
| 1272 | + $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 1273 | + |
|
| 1274 | + if(!empty($this->or_like)) |
|
| 1275 | + foreach($this->or_like as $or_like) |
|
| 1276 | + $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 1277 | + |
|
| 1278 | + if(!empty($this->having)) |
|
| 1279 | + foreach($this->having as $having) |
|
| 1280 | + $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 1281 | + |
|
| 1282 | + if(!empty($this->or_having)) |
|
| 1283 | + foreach($this->or_having as $or_having) |
|
| 1284 | + $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 1285 | + |
|
| 1286 | + if(!empty($this->relation)) |
|
| 1287 | + foreach($this->relation as $relation) |
|
| 1288 | + $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 1289 | + |
|
| 1290 | + if(!empty($this->relation_n_n)) |
|
| 1291 | + { |
|
| 1292 | + $columns = $this->get_columns(); |
|
| 1293 | + foreach($columns as $column) |
|
| 1294 | + { |
|
| 1295 | + //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
|
| 1296 | + if(isset($this->relation_n_n[$column->field_name])) |
|
| 1297 | + { |
|
| 1298 | + $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + if($this->theme_config['crud_paging'] === true) |
|
| 1305 | + { |
|
| 1306 | + if($this->limit === null) |
|
| 1307 | + { |
|
| 1308 | + $default_per_page = $this->config->default_per_page; |
|
| 1309 | + if(is_numeric($default_per_page) && $default_per_page >1) |
|
| 1310 | + { |
|
| 1311 | + $this->basic_model->limit($default_per_page); |
|
| 1312 | + } |
|
| 1313 | + else |
|
| 1314 | + { |
|
| 1315 | + $this->basic_model->limit(10); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + else |
|
| 1319 | + { |
|
| 1320 | + $this->basic_model->limit($this->limit[0],$this->limit[1]); |
|
| 1321 | + } |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + $results = $this->basic_model->get_list(); |
|
| 1325 | + |
|
| 1326 | + return $results; |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + protected function get_edit_values($primary_key_value) |
|
| 1330 | + { |
|
| 1331 | + $values = $this->basic_model->get_edit_values($primary_key_value); |
|
| 1332 | + |
|
| 1333 | + if(!empty($this->relation_n_n)) |
|
| 1334 | + { |
|
| 1335 | + foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1336 | + { |
|
| 1337 | + $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
| 1338 | + } |
|
| 1339 | + } |
|
| 1340 | + |
|
| 1341 | + return $values; |
|
| 1342 | + } |
|
| 1343 | + |
|
| 1344 | + protected function get_relation_n_n_selection_array($primary_key_value, $field_info) |
|
| 1345 | + { |
|
| 1346 | + return $this->basic_model->get_relation_n_n_selection_array($primary_key_value, $field_info); |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + protected function get_relation_n_n_unselected_array($field_info, $selected_values) |
|
| 1350 | + { |
|
| 1351 | + return $this->basic_model->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + protected function set_basic_db_table($table_name = null) |
|
| 1355 | + { |
|
| 1356 | + $this->basic_model->set_basic_table($table_name); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + protected function upload_file($state_info) |
|
| 1360 | + { |
|
| 1361 | + if(isset($this->upload_fields[$state_info->field_name]) ) |
|
| 1362 | + { |
|
| 1363 | + if($this->callback_upload === null) |
|
| 1364 | + { |
|
| 1365 | + if($this->callback_before_upload !== null) |
|
| 1366 | + { |
|
| 1367 | + $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
| 1368 | + |
|
| 1369 | + if($callback_before_upload_response === false) |
|
| 1370 | + return false; |
|
| 1371 | + elseif(is_string($callback_before_upload_response)) |
|
| 1372 | + return $callback_before_upload_response; |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + $upload_info = $this->upload_fields[$state_info->field_name]; |
|
| 1376 | + |
|
| 1377 | + header('Pragma: no-cache'); |
|
| 1378 | + header('Cache-Control: private, no-cache'); |
|
| 1379 | + header('Content-Disposition: inline; filename="files.json"'); |
|
| 1380 | + header('X-Content-Type-Options: nosniff'); |
|
| 1381 | + header('Access-Control-Allow-Origin: *'); |
|
| 1382 | + header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE'); |
|
| 1383 | + header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size'); |
|
| 1384 | + |
|
| 1385 | + $allowed_files = $this->config->file_upload_allow_file_types; |
|
| 1386 | + |
|
| 1387 | + $reg_exp = ''; |
|
| 1388 | + if(!empty($upload_info->allowed_file_types)){ |
|
| 1389 | + $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
|
| 1390 | + }else{ |
|
| 1391 | + $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
| 1395 | + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
| 1396 | + |
|
| 1397 | + $options = array( |
|
| 1398 | + 'upload_dir' => $upload_info->upload_path.'/', |
|
| 1399 | + 'param_name' => $this->_unique_field_name($state_info->field_name), |
|
| 1400 | + 'upload_url' => base_url().$upload_info->upload_path.'/', |
|
| 1401 | + 'accept_file_types' => $reg_exp, |
|
| 1402 | + 'max_file_size' => $max_file_size_bytes |
|
| 1403 | + ); |
|
| 1404 | + $upload_handler = new UploadHandler($options); |
|
| 1405 | + $upload_handler->default_config_path = $this->default_config_path; |
|
| 1406 | + $uploader_response = $upload_handler->post(); |
|
| 1407 | + |
|
| 1408 | + if(is_array($uploader_response)) |
|
| 1409 | + { |
|
| 1410 | + foreach($uploader_response as &$response) |
|
| 1411 | + { |
|
| 1412 | + unset($response->delete_url); |
|
| 1413 | + unset($response->delete_type); |
|
| 1414 | + } |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + if($this->callback_after_upload !== null) |
|
| 1418 | + { |
|
| 1419 | + $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
|
| 1420 | + |
|
| 1421 | + if($callback_after_upload_response === false) |
|
| 1422 | + return false; |
|
| 1423 | + elseif(is_string($callback_after_upload_response)) |
|
| 1424 | + return $callback_after_upload_response; |
|
| 1425 | + elseif(is_array($callback_after_upload_response)) |
|
| 1426 | + $uploader_response = $callback_after_upload_response; |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + return $uploader_response; |
|
| 1430 | + } |
|
| 1431 | + else |
|
| 1432 | + { |
|
| 1433 | + $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
|
| 1434 | + |
|
| 1435 | + if($upload_response === false) |
|
| 1436 | + { |
|
| 1437 | + return false; |
|
| 1438 | + } |
|
| 1439 | + else |
|
| 1440 | + { |
|
| 1441 | + return $upload_response; |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + else |
|
| 1446 | + { |
|
| 1447 | + return false; |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + protected function delete_file($state_info) |
|
| 1452 | + { |
|
| 1453 | + |
|
| 1454 | + if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
| 1455 | + { |
|
| 1456 | + $upload_info = $this->upload_fields[$state_info->field_name]; |
|
| 1457 | + |
|
| 1458 | + if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
| 1459 | + { |
|
| 1460 | + if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) |
|
| 1461 | + { |
|
| 1462 | + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
| 1463 | + |
|
| 1464 | + return true; |
|
| 1465 | + } |
|
| 1466 | + else |
|
| 1467 | + { |
|
| 1468 | + return false; |
|
| 1469 | + } |
|
| 1470 | + } |
|
| 1471 | + else |
|
| 1472 | + { |
|
| 1473 | + $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
|
| 1474 | + return true; |
|
| 1475 | + } |
|
| 1476 | + } |
|
| 1477 | + else |
|
| 1478 | + { |
|
| 1479 | + return false; |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + protected function ajax_relation($state_info) |
|
| 1484 | + { |
|
| 1485 | + if(!isset($this->relation[$state_info->field_name])) |
|
| 1486 | + return false; |
|
| 1487 | + |
|
| 1488 | + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
| 1489 | + |
|
| 1490 | + return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); |
|
| 1491 | + } |
|
| 1492 | +} |
|
| 1493 | + |
|
| 1494 | + |
|
| 1495 | +/** |
|
| 1496 | + * PHP grocery CRUD |
|
| 1497 | + * |
|
| 1498 | + * LICENSE |
|
| 1499 | + * |
|
| 1500 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 1501 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 1502 | + * Please see the corresponding license file for details of these licenses. |
|
| 1503 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 1504 | + * |
|
| 1505 | + * @package grocery CRUD |
|
| 1506 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 1507 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 1508 | + * @author John Skoumbourdis <[email protected]> |
|
| 1509 | + */ |
|
| 1510 | + |
|
| 1511 | +// ------------------------------------------------------------------------ |
|
| 1512 | + |
|
| 1513 | +/** |
|
| 1514 | + * PHP grocery Layout |
|
| 1515 | + * |
|
| 1516 | + * Here you manage all the HTML Layout |
|
| 1517 | + * |
|
| 1518 | + * @package grocery CRUD |
|
| 1519 | + * @author John Skoumbourdis <[email protected]> |
|
| 1520 | + * @version 1.5.6 |
|
| 1521 | + */ |
|
| 1522 | +class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver |
|
| 1523 | +{ |
|
| 1524 | + private $theme_path = null; |
|
| 1525 | + private $views_as_string = ''; |
|
| 1526 | + private $echo_and_die = false; |
|
| 1527 | + protected $theme = null; |
|
| 1528 | + protected $default_true_false_text = array('inactive' , 'active'); |
|
| 1529 | + |
|
| 1530 | + protected $css_files = array(); |
|
| 1531 | + protected $js_files = array(); |
|
| 1532 | + protected $js_lib_files = array(); |
|
| 1533 | + protected $js_config_files = array(); |
|
| 1534 | + |
|
| 1535 | + protected function set_basic_Layout() |
|
| 1536 | + { |
|
| 1537 | + if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
| 1538 | + { |
|
| 1539 | + throw new Exception('The template does not exist. Please check your files and try again.', 12); |
|
| 1540 | + die(); |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + protected function showList($ajax = false, $state_info = null) |
|
| 1545 | + { |
|
| 1546 | + $data = $this->get_common_data(); |
|
| 1547 | + |
|
| 1548 | + $data->order_by = $this->order_by; |
|
| 1549 | + |
|
| 1550 | + $data->types = $this->get_field_types(); |
|
| 1551 | + |
|
| 1552 | + $data->list = $this->get_list(); |
|
| 1553 | + $data->list = $this->change_list($data->list , $data->types); |
|
| 1554 | + $data->list = $this->change_list_add_actions($data->list); |
|
| 1555 | + |
|
| 1556 | + $data->total_results = $this->get_total_results(); |
|
| 1557 | + |
|
| 1558 | + $data->columns = $this->get_columns(); |
|
| 1559 | + |
|
| 1560 | + $data->success_message = $this->get_success_message_at_list($state_info); |
|
| 1561 | + |
|
| 1562 | + $data->primary_key = $this->get_primary_key(); |
|
| 1563 | + $data->add_url = $this->getAddUrl(); |
|
| 1564 | + $data->edit_url = $this->getEditUrl(); |
|
| 1565 | + $data->delete_url = $this->getDeleteUrl(); |
|
| 1566 | + $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
| 1567 | + $data->read_url = $this->getReadUrl(); |
|
| 1568 | + $data->ajax_list_url = $this->getAjaxListUrl(); |
|
| 1569 | + $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
| 1570 | + $data->export_url = $this->getExportToExcelUrl(); |
|
| 1571 | + $data->print_url = $this->getPrintUrl(); |
|
| 1572 | + $data->actions = $this->actions; |
|
| 1573 | + $data->unique_hash = $this->get_method_hash(); |
|
| 1574 | + $data->order_by = $this->order_by; |
|
| 1575 | + |
|
| 1576 | + $data->unset_add = $this->unset_add; |
|
| 1577 | + $data->unset_edit = $this->unset_edit; |
|
| 1578 | + $data->unset_read = $this->unset_read; |
|
| 1579 | + $data->unset_delete = $this->unset_delete; |
|
| 1580 | + $data->unset_export = $this->unset_export; |
|
| 1581 | + $data->unset_print = $this->unset_print; |
|
| 1582 | + |
|
| 1583 | + $default_per_page = $this->config->default_per_page; |
|
| 1584 | + $data->paging_options = $this->config->paging_options; |
|
| 1585 | + $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; |
|
| 1586 | + |
|
| 1587 | + if($data->list === false) |
|
| 1588 | + { |
|
| 1589 | + throw new Exception('It is impossible to get data. Please check your model and try again.', 13); |
|
| 1590 | + $data->list = array(); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + foreach($data->list as $num_row => $row) |
|
| 1594 | + { |
|
| 1595 | + $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; |
|
| 1596 | + $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; |
|
| 1597 | + $data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key}; |
|
| 1598 | + $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + if(!$ajax) |
|
| 1602 | + { |
|
| 1603 | + $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); |
|
| 1604 | + |
|
| 1605 | + $data->list_view = $this->_theme_view('list.php',$data,true); |
|
| 1606 | + $this->_theme_view('list_template.php',$data); |
|
| 1607 | + } |
|
| 1608 | + else |
|
| 1609 | + { |
|
| 1610 | + $this->set_echo_and_die(); |
|
| 1611 | + $this->_theme_view('list.php',$data); |
|
| 1612 | + } |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + protected function exportToExcel($state_info = null) |
|
| 1616 | + { |
|
| 1617 | + $data = $this->get_common_data(); |
|
| 1618 | + |
|
| 1619 | + $data->order_by = $this->order_by; |
|
| 1620 | + $data->types = $this->get_field_types(); |
|
| 1621 | + |
|
| 1622 | + $data->list = $this->get_list(); |
|
| 1623 | + $data->list = $this->change_list($data->list , $data->types); |
|
| 1624 | + $data->list = $this->change_list_add_actions($data->list); |
|
| 1625 | + |
|
| 1626 | + $data->total_results = $this->get_total_results(); |
|
| 1627 | + |
|
| 1628 | + $data->columns = $this->get_columns(); |
|
| 1629 | + $data->primary_key = $this->get_primary_key(); |
|
| 1630 | + |
|
| 1631 | + @ob_end_clean(); |
|
| 1632 | + $this->_export_to_excel($data); |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + protected function _export_to_excel($data) |
|
| 1636 | + { |
|
| 1637 | + /** |
|
| 1638 | + * No need to use an external library here. The only bad thing without using external library is that Microsoft Excel is complaining |
|
| 1639 | + * that the file is in a different format than specified by the file extension. If you press "Yes" everything will be just fine. |
|
| 1640 | + * */ |
|
| 1641 | + |
|
| 1642 | + $string_to_export = ""; |
|
| 1643 | + foreach($data->columns as $column){ |
|
| 1644 | + $string_to_export .= $column->display_as."\t"; |
|
| 1645 | + } |
|
| 1646 | + $string_to_export .= "\n"; |
|
| 1647 | + |
|
| 1648 | + foreach($data->list as $num_row => $row){ |
|
| 1649 | + foreach($data->columns as $column){ |
|
| 1650 | + $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; |
|
| 1651 | + } |
|
| 1652 | + $string_to_export .= "\n"; |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + // Convert to UTF-16LE and Prepend BOM |
|
| 1656 | + $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
| 1657 | + |
|
| 1658 | + $filename = "export-".date("Y-m-d_H:i:s").".xls"; |
|
| 1659 | + |
|
| 1660 | + header('Content-type: application/vnd.ms-excel;charset=UTF-16LE'); |
|
| 1661 | + header('Content-Disposition: attachment; filename='.$filename); |
|
| 1662 | + header("Cache-Control: no-cache"); |
|
| 1663 | + echo $string_to_export; |
|
| 1664 | + die(); |
|
| 1665 | + } |
|
| 1666 | + |
|
| 1667 | + protected function print_webpage($state_info = null) |
|
| 1668 | + { |
|
| 1669 | + $data = $this->get_common_data(); |
|
| 1670 | + |
|
| 1671 | + $data->order_by = $this->order_by; |
|
| 1672 | + $data->types = $this->get_field_types(); |
|
| 1673 | + |
|
| 1674 | + $data->list = $this->get_list(); |
|
| 1675 | + $data->list = $this->change_list($data->list , $data->types); |
|
| 1676 | + $data->list = $this->change_list_add_actions($data->list); |
|
| 1677 | + |
|
| 1678 | + $data->total_results = $this->get_total_results(); |
|
| 1679 | + |
|
| 1680 | + $data->columns = $this->get_columns(); |
|
| 1681 | + $data->primary_key = $this->get_primary_key(); |
|
| 1682 | + |
|
| 1683 | + @ob_end_clean(); |
|
| 1684 | + $this->_print_webpage($data); |
|
| 1685 | + } |
|
| 1686 | + |
|
| 1687 | + protected function _print_webpage($data) |
|
| 1688 | + { |
|
| 1689 | + $string_to_print = "<meta charset=\"utf-8\" /><style type=\"text/css\" > |
|
| 1690 | + #print-table{ color: #000; background: #fff; font-family: Verdana,Tahoma,Helvetica,sans-serif; font-size: 13px;} |
|
| 1691 | + #print-table table tr td, #print-table table tr th{ border: 1px solid black; border-bottom: none; border-right: none; padding: 4px 8px 4px 4px} |
|
| 1692 | + #print-table table{ border-bottom: 1px solid black; border-right: 1px solid black} |
|
| 1693 | + #print-table table tr th{text-align: left;background: #ddd} |
|
| 1694 | + #print-table table tr:nth-child(odd){background: #eee} |
|
| 1695 | + </style>"; |
|
| 1696 | + $string_to_print .= "<div id='print-table'>"; |
|
| 1697 | + |
|
| 1698 | + $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; |
|
| 1699 | + foreach($data->columns as $column){ |
|
| 1700 | + $string_to_print .= "<th>".$column->display_as."</th>"; |
|
| 1701 | + } |
|
| 1702 | + $string_to_print .= "</tr>"; |
|
| 1703 | + |
|
| 1704 | + foreach($data->list as $num_row => $row){ |
|
| 1705 | + $string_to_print .= "<tr>"; |
|
| 1706 | + foreach($data->columns as $column){ |
|
| 1707 | + $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; |
|
| 1708 | + } |
|
| 1709 | + $string_to_print .= "</tr>"; |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + $string_to_print .= "</table></div>"; |
|
| 1713 | + |
|
| 1714 | + echo $string_to_print; |
|
| 1715 | + die(); |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + protected function _trim_export_string($value) |
|
| 1719 | + { |
|
| 1720 | + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1721 | + return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + protected function _trim_print_string($value) |
|
| 1725 | + { |
|
| 1726 | + $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1727 | + |
|
| 1728 | + //If the value has only spaces and nothing more then add the whitespace html character |
|
| 1729 | + if(str_replace(" ","",$value) == "") |
|
| 1730 | + $value = " "; |
|
| 1731 | + |
|
| 1732 | + return strip_tags($value); |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + protected function set_echo_and_die() |
|
| 1736 | + { |
|
| 1737 | + $this->echo_and_die = true; |
|
| 1738 | + } |
|
| 1739 | + |
|
| 1740 | + protected function unset_echo_and_die() |
|
| 1741 | + { |
|
| 1742 | + $this->echo_and_die = false; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + protected function showListInfo() |
|
| 1746 | + { |
|
| 1747 | + $this->set_echo_and_die(); |
|
| 1748 | + |
|
| 1749 | + $total_results = (int)$this->get_total_results(); |
|
| 1750 | + @ob_end_clean(); |
|
| 1751 | + echo json_encode(array('total_results' => $total_results)); |
|
| 1752 | + die(); |
|
| 1753 | + } |
|
| 1754 | + |
|
| 1755 | + protected function change_list_add_actions($list) |
|
| 1756 | + { |
|
| 1757 | + if(empty($this->actions)) |
|
| 1758 | + return $list; |
|
| 1759 | + |
|
| 1760 | + $primary_key = $this->get_primary_key(); |
|
| 1761 | + |
|
| 1762 | + foreach($list as $num_row => $row) |
|
| 1763 | + { |
|
| 1764 | + $actions_urls = array(); |
|
| 1765 | + foreach($this->actions as $unique_id => $action) |
|
| 1766 | + { |
|
| 1767 | + if(!empty($action->url_callback)) |
|
| 1768 | + { |
|
| 1769 | + $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
|
| 1770 | + } |
|
| 1771 | + else |
|
| 1772 | + { |
|
| 1773 | + $actions_urls[$unique_id] = |
|
| 1774 | + $action->url_has_http ? |
|
| 1775 | + $action->link_url.$row->$primary_key : |
|
| 1776 | + site_url($action->link_url.'/'.$row->$primary_key); |
|
| 1777 | + } |
|
| 1778 | + } |
|
| 1779 | + $row->action_urls = $actions_urls; |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + return $list; |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + protected function change_list($list,$types) |
|
| 1786 | + { |
|
| 1787 | + $primary_key = $this->get_primary_key(); |
|
| 1788 | + $has_callbacks = !empty($this->callback_column) ? true : false; |
|
| 1789 | + $output_columns = $this->get_columns(); |
|
| 1790 | + foreach($list as $num_row => $row) |
|
| 1791 | + { |
|
| 1792 | + foreach($output_columns as $column) |
|
| 1793 | + { |
|
| 1794 | + $field_name = $column->field_name; |
|
| 1795 | + $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
| 1796 | + if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
| 1797 | + $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
| 1798 | + elseif(isset($types[$field_name])) |
|
| 1799 | + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
| 1800 | + else |
|
| 1801 | + $list[$num_row]->$field_name = $field_value; |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + return $list; |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + protected function showAddForm() |
|
| 1809 | + { |
|
| 1810 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1811 | + |
|
| 1812 | + $data = $this->get_common_data(); |
|
| 1813 | + $data->types = $this->get_field_types(); |
|
| 1814 | + |
|
| 1815 | + $data->list_url = $this->getListUrl(); |
|
| 1816 | + $data->insert_url = $this->getInsertUrl(); |
|
| 1817 | + $data->validation_url = $this->getValidationInsertUrl(); |
|
| 1818 | + $data->input_fields = $this->get_add_input_fields(); |
|
| 1819 | + |
|
| 1820 | + $data->fields = $this->get_add_fields(); |
|
| 1821 | + $data->hidden_fields = $this->get_add_hidden_fields(); |
|
| 1822 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1823 | + $data->unique_hash = $this->get_method_hash(); |
|
| 1824 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1825 | + |
|
| 1826 | + $this->_theme_view('add.php',$data); |
|
| 1827 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1828 | + |
|
| 1829 | + $this->_get_ajax_results(); |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + protected function showEditForm($state_info) |
|
| 1833 | + { |
|
| 1834 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1835 | + |
|
| 1836 | + $data = $this->get_common_data(); |
|
| 1837 | + $data->types = $this->get_field_types(); |
|
| 1838 | + |
|
| 1839 | + $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
| 1840 | + |
|
| 1841 | + $data->add_url = $this->getAddUrl(); |
|
| 1842 | + |
|
| 1843 | + $data->list_url = $this->getListUrl(); |
|
| 1844 | + $data->update_url = $this->getUpdateUrl($state_info); |
|
| 1845 | + $data->delete_url = $this->getDeleteUrl($state_info); |
|
| 1846 | + $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
| 1847 | + $data->input_fields = $this->get_edit_input_fields($data->field_values); |
|
| 1848 | + $data->unique_hash = $this->get_method_hash(); |
|
| 1849 | + |
|
| 1850 | + $data->fields = $this->get_edit_fields(); |
|
| 1851 | + $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
| 1852 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1853 | + |
|
| 1854 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1855 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1856 | + |
|
| 1857 | + $this->_theme_view('edit.php',$data); |
|
| 1858 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1859 | + |
|
| 1860 | + $this->_get_ajax_results(); |
|
| 1861 | + } |
|
| 1862 | + |
|
| 1863 | + protected function showReadForm($state_info) |
|
| 1864 | + { |
|
| 1865 | + $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
|
| 1866 | + |
|
| 1867 | + $data = $this->get_common_data(); |
|
| 1868 | + $data->types = $this->get_field_types(); |
|
| 1869 | + |
|
| 1870 | + $data->field_values = $this->get_edit_values($state_info->primary_key); |
|
| 1871 | + |
|
| 1872 | + $data->add_url = $this->getAddUrl(); |
|
| 1873 | + |
|
| 1874 | + $data->list_url = $this->getListUrl(); |
|
| 1875 | + $data->update_url = $this->getUpdateUrl($state_info); |
|
| 1876 | + $data->delete_url = $this->getDeleteUrl($state_info); |
|
| 1877 | + $data->read_url = $this->getReadUrl($state_info->primary_key); |
|
| 1878 | + $data->input_fields = $this->get_read_input_fields($data->field_values); |
|
| 1879 | + $data->unique_hash = $this->get_method_hash(); |
|
| 1880 | + |
|
| 1881 | + $data->fields = $this->get_read_fields(); |
|
| 1882 | + $data->hidden_fields = $this->get_edit_hidden_fields(); |
|
| 1883 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1884 | + |
|
| 1885 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1886 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1887 | + |
|
| 1888 | + $this->_theme_view('read.php',$data); |
|
| 1889 | + $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
|
| 1890 | + |
|
| 1891 | + $this->_get_ajax_results(); |
|
| 1892 | + } |
|
| 1893 | + |
|
| 1894 | + protected function delete_layout($delete_result = true) |
|
| 1895 | + { |
|
| 1896 | + @ob_end_clean(); |
|
| 1897 | + if($delete_result === false) |
|
| 1898 | + { |
|
| 1899 | + $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
|
| 1900 | + |
|
| 1901 | + echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
|
| 1902 | + } |
|
| 1903 | + else |
|
| 1904 | + { |
|
| 1905 | + $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
|
| 1906 | + |
|
| 1907 | + echo json_encode(array('success' => true , 'success_message' => $success_message)); |
|
| 1908 | + } |
|
| 1909 | + $this->set_echo_and_die(); |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + protected function get_success_message_at_list($field_info = null) |
|
| 1913 | + { |
|
| 1914 | + if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
| 1915 | + { |
|
| 1916 | + if(!empty($field_info->primary_key) && !$this->unset_edit) |
|
| 1917 | + { |
|
| 1918 | + return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
| 1919 | + } |
|
| 1920 | + else |
|
| 1921 | + { |
|
| 1922 | + return $this->l('insert_success_message'); |
|
| 1923 | + } |
|
| 1924 | + } |
|
| 1925 | + else |
|
| 1926 | + { |
|
| 1927 | + return null; |
|
| 1928 | + } |
|
| 1929 | + } |
|
| 1930 | + |
|
| 1931 | + protected function insert_layout($insert_result = false) |
|
| 1932 | + { |
|
| 1933 | + @ob_end_clean(); |
|
| 1934 | + if($insert_result === false) |
|
| 1935 | + { |
|
| 1936 | + echo json_encode(array('success' => false)); |
|
| 1937 | + } |
|
| 1938 | + else |
|
| 1939 | + { |
|
| 1940 | + $success_message = '<p>'.$this->l('insert_success_message'); |
|
| 1941 | + |
|
| 1942 | + if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
| 1943 | + { |
|
| 1944 | + $success_message .= " <a class='go-to-edit-form' href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
|
| 1945 | + |
|
| 1946 | + if (!$this->_is_ajax()) { |
|
| 1947 | + $success_message .= $this->l('form_or'); |
|
| 1948 | + } |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 1952 | + { |
|
| 1953 | + $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
| 1954 | + } |
|
| 1955 | + |
|
| 1956 | + $success_message .= '</p>'; |
|
| 1957 | + |
|
| 1958 | + echo json_encode(array( |
|
| 1959 | + 'success' => true , |
|
| 1960 | + 'insert_primary_key' => $insert_result, |
|
| 1961 | + 'success_message' => $success_message, |
|
| 1962 | + 'success_list_url' => $this->getListSuccessUrl($insert_result) |
|
| 1963 | + )); |
|
| 1964 | + } |
|
| 1965 | + $this->set_echo_and_die(); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + protected function validation_layout($validation_result) |
|
| 1969 | + { |
|
| 1970 | + @ob_end_clean(); |
|
| 1971 | + echo json_encode($validation_result); |
|
| 1972 | + $this->set_echo_and_die(); |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + protected function upload_layout($upload_result, $field_name) |
|
| 1976 | + { |
|
| 1977 | + @ob_end_clean(); |
|
| 1978 | + if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
| 1979 | + { |
|
| 1980 | + echo json_encode( |
|
| 1981 | + (object)array( |
|
| 1982 | + 'success' => true, |
|
| 1983 | + 'files' => $upload_result |
|
| 1984 | + )); |
|
| 1985 | + } |
|
| 1986 | + else |
|
| 1987 | + { |
|
| 1988 | + $result = (object)array('success' => false); |
|
| 1989 | + if(is_string($upload_result)) |
|
| 1990 | + $result->message = $upload_result; |
|
| 1991 | + if(!empty($upload_result[0]->error)) |
|
| 1992 | + $result->message = $upload_result[0]->error; |
|
| 1993 | + |
|
| 1994 | + echo json_encode($result); |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + $this->set_echo_and_die(); |
|
| 1998 | + } |
|
| 1999 | + |
|
| 2000 | + protected function delete_file_layout($upload_result) |
|
| 2001 | + { |
|
| 2002 | + @ob_end_clean(); |
|
| 2003 | + if($upload_result !== false) |
|
| 2004 | + { |
|
| 2005 | + echo json_encode( (object)array( 'success' => true ) ); |
|
| 2006 | + } |
|
| 2007 | + else |
|
| 2008 | + { |
|
| 2009 | + echo json_encode((object)array('success' => false)); |
|
| 2010 | + } |
|
| 2011 | + |
|
| 2012 | + $this->set_echo_and_die(); |
|
| 2013 | + } |
|
| 2014 | + |
|
| 2015 | + public function set_css($css_file) |
|
| 2016 | + { |
|
| 2017 | + $this->css_files[sha1($css_file)] = base_url().$css_file; |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + public function set_js($js_file) |
|
| 2021 | + { |
|
| 2022 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2023 | + } |
|
| 2024 | + |
|
| 2025 | + public function set_js_lib($js_file) |
|
| 2026 | + { |
|
| 2027 | + $this->js_lib_files[sha1($js_file)] = base_url().$js_file; |
|
| 2028 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2029 | + } |
|
| 2030 | + |
|
| 2031 | + public function set_js_config($js_file) |
|
| 2032 | + { |
|
| 2033 | + $this->js_config_files[sha1($js_file)] = base_url().$js_file; |
|
| 2034 | + $this->js_files[sha1($js_file)] = base_url().$js_file; |
|
| 2035 | + } |
|
| 2036 | + |
|
| 2037 | + public function is_IE7() |
|
| 2038 | + { |
|
| 2039 | + return isset($_SERVER['HTTP_USER_AGENT']) |
|
| 2040 | + && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) |
|
| 2041 | + ? true : false; |
|
| 2042 | + } |
|
| 2043 | + |
|
| 2044 | + public function get_css_files() |
|
| 2045 | + { |
|
| 2046 | + return $this->css_files; |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + public function get_js_files() |
|
| 2050 | + { |
|
| 2051 | + return $this->js_files; |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + public function get_js_lib_files() |
|
| 2055 | + { |
|
| 2056 | + return $this->js_lib_files; |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + public function get_js_config_files() |
|
| 2060 | + { |
|
| 2061 | + return $this->js_config_files; |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + /** |
|
| 2065 | + * Load Javascripts |
|
| 2066 | + **/ |
|
| 2067 | + protected function load_js_fancybox() |
|
| 2068 | + { |
|
| 2069 | + $this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css'); |
|
| 2070 | + |
|
| 2071 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fancybox-1.3.4.js'); |
|
| 2072 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js'); |
|
| 2073 | + } |
|
| 2074 | + |
|
| 2075 | + protected function load_js_chosen() |
|
| 2076 | + { |
|
| 2077 | + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
| 2078 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + protected function load_js_jqueryui() |
|
| 2082 | + { |
|
| 2083 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2084 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + protected function load_js_uploader() |
|
| 2088 | + { |
|
| 2089 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2090 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css'); |
|
| 2091 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css'); |
|
| 2092 | + |
|
| 2093 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2094 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/tmpl.min.js'); |
|
| 2095 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/load-image.min.js'); |
|
| 2096 | + |
|
| 2097 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js'); |
|
| 2098 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js'); |
|
| 2099 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js'); |
|
| 2100 | + } |
|
| 2101 | + |
|
| 2102 | + protected function get_layout() |
|
| 2103 | + { |
|
| 2104 | + $js_files = $this->get_js_files(); |
|
| 2105 | + $css_files = $this->get_css_files(); |
|
| 2106 | + |
|
| 2107 | + $js_lib_files = $this->get_js_lib_files(); |
|
| 2108 | + $js_config_files = $this->get_js_config_files(); |
|
| 2109 | + |
|
| 2110 | + if ($this->unset_jquery) { |
|
| 2111 | + unset($js_files[sha1($this->default_javascript_path.'/'.grocery_CRUD::JQUERY)]); |
|
| 2112 | + } |
|
| 2113 | + |
|
| 2114 | + if ($this->unset_jquery_ui) { |
|
| 2115 | + unset($css_files[sha1($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS)]); |
|
| 2116 | + unset($js_files[sha1($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS)]); |
|
| 2117 | + } |
|
| 2118 | + |
|
| 2119 | + if ($this->unset_bootstrap) { |
|
| 2120 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.js')]); |
|
| 2121 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.js')]); |
|
| 2122 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/dropdown.min.js')]); |
|
| 2123 | + unset($js_files[sha1($this->default_theme_path.'/bootstrap/js/bootstrap/modal.min.js')]); |
|
| 2124 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.css')]); |
|
| 2125 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap/css/bootstrap/bootstrap.min.css')]); |
|
| 2126 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.css')]); |
|
| 2127 | + unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + if($this->echo_and_die === false) |
|
| 2131 | + { |
|
| 2132 | + /** Initialize JavaScript variables */ |
|
| 2133 | + $js_vars = array( |
|
| 2134 | + 'default_javascript_path' => base_url().$this->default_javascript_path, |
|
| 2135 | + 'default_css_path' => base_url().$this->default_css_path, |
|
| 2136 | + 'default_texteditor_path' => base_url().$this->default_texteditor_path, |
|
| 2137 | + 'default_theme_path' => base_url().$this->default_theme_path, |
|
| 2138 | + 'base_url' => base_url() |
|
| 2139 | + ); |
|
| 2140 | + $this->_add_js_vars($js_vars); |
|
| 2141 | + |
|
| 2142 | + return (object)array( |
|
| 2143 | + 'js_files' => $js_files, |
|
| 2144 | + 'js_lib_files' => $js_lib_files, |
|
| 2145 | + 'js_config_files' => $js_config_files, |
|
| 2146 | + 'css_files' => $css_files, |
|
| 2147 | + 'output' => $this->views_as_string, |
|
| 2148 | + ); |
|
| 2149 | + } |
|
| 2150 | + elseif($this->echo_and_die === true) |
|
| 2151 | + { |
|
| 2152 | + echo $this->views_as_string; |
|
| 2153 | + die(); |
|
| 2154 | + } |
|
| 2155 | + } |
|
| 2156 | + |
|
| 2157 | + protected function update_layout($update_result = false, $state_info = null) |
|
| 2158 | + { |
|
| 2159 | + @ob_end_clean(); |
|
| 2160 | + if($update_result === false) |
|
| 2161 | + { |
|
| 2162 | + echo json_encode(array('success' => $update_result)); |
|
| 2163 | + } |
|
| 2164 | + else |
|
| 2165 | + { |
|
| 2166 | + $success_message = '<p>'.$this->l('update_success_message'); |
|
| 2167 | + if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 2168 | + { |
|
| 2169 | + $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
|
| 2170 | + } |
|
| 2171 | + $success_message .= '</p>'; |
|
| 2172 | + |
|
| 2173 | + echo json_encode(array( |
|
| 2174 | + 'success' => true , |
|
| 2175 | + 'insert_primary_key' => $update_result, |
|
| 2176 | + 'success_message' => $success_message, |
|
| 2177 | + 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) |
|
| 2178 | + )); |
|
| 2179 | + } |
|
| 2180 | + $this->set_echo_and_die(); |
|
| 2181 | + } |
|
| 2182 | + |
|
| 2183 | + protected function get_integer_input($field_info,$value) |
|
| 2184 | + { |
|
| 2185 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
|
| 2186 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
|
| 2187 | + $extra_attributes = ''; |
|
| 2188 | + if(!empty($field_info->db_max_length)) |
|
| 2189 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2190 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
|
| 2191 | + return $input; |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + protected function get_true_false_input($field_info,$value) |
|
| 2195 | + { |
|
| 2196 | + $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; |
|
| 2197 | + |
|
| 2198 | + $input = "<div class='pretty-radio-buttons'>"; |
|
| 2199 | + |
|
| 2200 | + $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
| 2201 | + $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; |
|
| 2202 | + $input .= |
|
| 2203 | + "<div class=\"radio\"><label> |
|
| 2204 | + <input id='field-{$field_info->name}-true' type=\"radio\" name=\"{$field_info->name}\" value=\"1\" $checked /> |
|
| 2205 | + $true_string |
|
| 2206 | + </label> </div>"; |
|
| 2207 | + |
|
| 2208 | + $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
| 2209 | + $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; |
|
| 2210 | + $input .= |
|
| 2211 | + "<div class=\"radio\"><label> |
|
| 2212 | + <input id='field-{$field_info->name}-false' type=\"radio\" name=\"{$field_info->name}\" value=\"0\" $checked /> |
|
| 2213 | + $false_string |
|
| 2214 | + </label> </div>"; |
|
| 2215 | + |
|
| 2216 | + $input .= "</div>"; |
|
| 2217 | + |
|
| 2218 | + return $input; |
|
| 2219 | + } |
|
| 2220 | + |
|
| 2221 | + protected function get_string_input($field_info,$value) |
|
| 2222 | + { |
|
| 2223 | + $value = !is_string($value) ? '' : str_replace('"',""",$value); |
|
| 2224 | + |
|
| 2225 | + $extra_attributes = ''; |
|
| 2226 | + if (!empty($field_info->db_max_length)) { |
|
| 2227 | + |
|
| 2228 | + if (in_array($field_info->type, array("decimal", "float"))) { |
|
| 2229 | + $decimal_lentgh = explode(",", $field_info->db_max_length); |
|
| 2230 | + $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; |
|
| 2231 | + |
|
| 2232 | + $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; |
|
| 2233 | + } else { |
|
| 2234 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + } |
|
| 2238 | + $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='text' value=\"$value\" $extra_attributes />"; |
|
| 2239 | + return $input; |
|
| 2240 | + } |
|
| 2241 | + |
|
| 2242 | + protected function get_text_input($field_info,$value) |
|
| 2243 | + { |
|
| 2244 | + if($field_info->extras == 'text_editor') |
|
| 2245 | + { |
|
| 2246 | + $editor = $this->config->default_text_editor; |
|
| 2247 | + switch ($editor) { |
|
| 2248 | + case 'ckeditor': |
|
| 2249 | + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/ckeditor.js'); |
|
| 2250 | + $this->set_js_lib($this->default_texteditor_path.'/ckeditor/adapters/jquery.js'); |
|
| 2251 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.ckeditor.config.js'); |
|
| 2252 | + break; |
|
| 2253 | + |
|
| 2254 | + case 'tinymce': |
|
| 2255 | + $this->set_js_lib($this->default_texteditor_path.'/tiny_mce/jquery.tinymce.js'); |
|
| 2256 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.tine_mce.config.js'); |
|
| 2257 | + break; |
|
| 2258 | + |
|
| 2259 | + case 'markitup': |
|
| 2260 | + $this->set_css($this->default_texteditor_path.'/markitup/skins/markitup/style.css'); |
|
| 2261 | + $this->set_css($this->default_texteditor_path.'/markitup/sets/default/style.css'); |
|
| 2262 | + |
|
| 2263 | + $this->set_js_lib($this->default_texteditor_path.'/markitup/jquery.markitup.js'); |
|
| 2264 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.markitup.config.js'); |
|
| 2265 | + break; |
|
| 2266 | + } |
|
| 2267 | + |
|
| 2268 | + $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; |
|
| 2269 | + |
|
| 2270 | + $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; |
|
| 2271 | + } |
|
| 2272 | + else |
|
| 2273 | + { |
|
| 2274 | + $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; |
|
| 2275 | + } |
|
| 2276 | + return $input; |
|
| 2277 | + } |
|
| 2278 | + |
|
| 2279 | + protected function get_datetime_input($field_info,$value) |
|
| 2280 | + { |
|
| 2281 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2282 | + $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); |
|
| 2283 | + $this->set_css($this->default_css_path.'/jquery_plugins/jquery-ui-timepicker-addon.css'); |
|
| 2284 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2285 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); |
|
| 2286 | + |
|
| 2287 | + if($this->language !== 'english') |
|
| 2288 | + { |
|
| 2289 | + include($this->default_config_path.'/language_alias.php'); |
|
| 2290 | + if(array_key_exists($this->language, $language_alias)) |
|
| 2291 | + { |
|
| 2292 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
| 2293 | + if(file_exists($i18n_date_js_file)) |
|
| 2294 | + { |
|
| 2295 | + $this->set_js_lib($i18n_date_js_file); |
|
| 2296 | + } |
|
| 2297 | + |
|
| 2298 | + $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; |
|
| 2299 | + if(file_exists($i18n_datetime_js_file)) |
|
| 2300 | + { |
|
| 2301 | + $this->set_js_lib($i18n_datetime_js_file); |
|
| 2302 | + } |
|
| 2303 | + } |
|
| 2304 | + } |
|
| 2305 | + |
|
| 2306 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); |
|
| 2307 | + |
|
| 2308 | + if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ |
|
| 2309 | + list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2310 | + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2311 | + $datetime = $date.substr($value,10); |
|
| 2312 | + } |
|
| 2313 | + else |
|
| 2314 | + { |
|
| 2315 | + $datetime = ''; |
|
| 2316 | + } |
|
| 2317 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$datetime' maxlength='19' class='datetime-input form-control' /> |
|
| 2318 | + <a class='datetime-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> |
|
| 2319 | + ({$this->ui_date_format}) hh:mm:ss"; |
|
| 2320 | + return $input; |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + protected function get_hidden_input($field_info,$value) |
|
| 2324 | + { |
|
| 2325 | + if($field_info->extras !== null && $field_info->extras != false) |
|
| 2326 | + $value = $field_info->extras; |
|
| 2327 | + $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
|
| 2328 | + return $input; |
|
| 2329 | + } |
|
| 2330 | + |
|
| 2331 | + protected function get_password_input($field_info,$value) |
|
| 2332 | + { |
|
| 2333 | + $value = !is_string($value) ? '' : $value; |
|
| 2334 | + |
|
| 2335 | + $extra_attributes = ''; |
|
| 2336 | + if(!empty($field_info->db_max_length)) |
|
| 2337 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2338 | + $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
|
| 2339 | + return $input; |
|
| 2340 | + } |
|
| 2341 | + |
|
| 2342 | + protected function get_date_input($field_info,$value) |
|
| 2343 | + { |
|
| 2344 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2345 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2346 | + |
|
| 2347 | + if($this->language !== 'english') |
|
| 2348 | + { |
|
| 2349 | + include($this->default_config_path.'/language_alias.php'); |
|
| 2350 | + if(array_key_exists($this->language, $language_alias)) |
|
| 2351 | + { |
|
| 2352 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
|
| 2353 | + if(file_exists($i18n_date_js_file)) |
|
| 2354 | + { |
|
| 2355 | + $this->set_js_lib($i18n_date_js_file); |
|
| 2356 | + } |
|
| 2357 | + } |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); |
|
| 2361 | + |
|
| 2362 | + if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 2363 | + { |
|
| 2364 | + list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2365 | + $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2366 | + } |
|
| 2367 | + else |
|
| 2368 | + { |
|
| 2369 | + $date = ''; |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$date' maxlength='10' class='datepicker-input form-control' /> |
|
| 2373 | + <a class='datepicker-input-clear' tabindex='-1'>".$this->l('form_button_clear')."</a> (".$this->ui_date_format.")"; |
|
| 2374 | + return $input; |
|
| 2375 | + } |
|
| 2376 | + |
|
| 2377 | + protected function get_dropdown_input($field_info,$value) |
|
| 2378 | + { |
|
| 2379 | + $this->load_js_chosen(); |
|
| 2380 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2381 | + |
|
| 2382 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2383 | + |
|
| 2384 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
| 2385 | + $options = array('' => '') + $field_info->extras; |
|
| 2386 | + foreach($options as $option_value => $option_label) |
|
| 2387 | + { |
|
| 2388 | + $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
| 2389 | + $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
| 2390 | + } |
|
| 2391 | + |
|
| 2392 | + $input .= "</select>"; |
|
| 2393 | + return $input; |
|
| 2394 | + } |
|
| 2395 | + |
|
| 2396 | + protected function get_enum_input($field_info,$value) |
|
| 2397 | + { |
|
| 2398 | + $this->load_js_chosen(); |
|
| 2399 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2400 | + |
|
| 2401 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2402 | + |
|
| 2403 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
|
| 2404 | + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2405 | + $options_array = array('' => '') + $options_array; |
|
| 2406 | + |
|
| 2407 | + foreach($options_array as $option) |
|
| 2408 | + { |
|
| 2409 | + $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; |
|
| 2410 | + $input .= "<option value='$option' $selected >$option</option>"; |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + $input .= "</select>"; |
|
| 2414 | + return $input; |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + protected function get_readonly_input($field_info, $value) |
|
| 2418 | + { |
|
| 2419 | + $read_only_value = " "; |
|
| 2420 | + |
|
| 2421 | + if (!empty($value) && !is_array($value)) { |
|
| 2422 | + $read_only_value = $value; |
|
| 2423 | + } elseif (is_array($value)) { |
|
| 2424 | + $all_values = array_values($value); |
|
| 2425 | + $read_only_value = implode(", ",$all_values); |
|
| 2426 | + } |
|
| 2427 | + |
|
| 2428 | + return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$read_only_value.'</div>'; |
|
| 2429 | + } |
|
| 2430 | + |
|
| 2431 | + protected function get_set_input($field_info,$value) |
|
| 2432 | + { |
|
| 2433 | + $this->load_js_chosen(); |
|
| 2434 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2435 | + |
|
| 2436 | + $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2437 | + $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2438 | + |
|
| 2439 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2440 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
| 2441 | + |
|
| 2442 | + foreach($options_array as $option) |
|
| 2443 | + { |
|
| 2444 | + $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; |
|
| 2445 | + $input .= "<option value='$option' $selected >$option</option>"; |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + $input .= "</select>"; |
|
| 2449 | + |
|
| 2450 | + return $input; |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + protected function get_multiselect_input($field_info,$value) |
|
| 2454 | + { |
|
| 2455 | + $this->load_js_chosen(); |
|
| 2456 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2457 | + |
|
| 2458 | + $options_array = $field_info->extras; |
|
| 2459 | + $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2460 | + |
|
| 2461 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2462 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
|
| 2463 | + |
|
| 2464 | + foreach($options_array as $option_value => $option_label) |
|
| 2465 | + { |
|
| 2466 | + $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; |
|
| 2467 | + $input .= "<option value='$option_value' $selected >$option_label</option>"; |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + $input .= "</select>"; |
|
| 2471 | + |
|
| 2472 | + return $input; |
|
| 2473 | + } |
|
| 2474 | + |
|
| 2475 | + protected function get_relation_input($field_info,$value) |
|
| 2476 | + { |
|
| 2477 | + $this->load_js_chosen(); |
|
| 2478 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2479 | + |
|
| 2480 | + $ajax_limitation = 10000; |
|
| 2481 | + $total_rows = $this->get_relation_total_rows($field_info->extras); |
|
| 2482 | + |
|
| 2483 | + |
|
| 2484 | + //Check if we will use ajax for our queries or just clien-side javascript |
|
| 2485 | + $using_ajax = $total_rows > $ajax_limitation ? true : false; |
|
| 2486 | + |
|
| 2487 | + //We will not use it for now. It is not ready yet. Probably we will have this functionality at version 1.4 |
|
| 2488 | + $using_ajax = false; |
|
| 2489 | + |
|
| 2490 | + //If total rows are more than the limitation, use the ajax plugin |
|
| 2491 | + $ajax_or_not_class = $using_ajax ? 'chosen-select' : 'chosen-select'; |
|
| 2492 | + |
|
| 2493 | + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
| 2494 | + |
|
| 2495 | + $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2496 | + $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; |
|
| 2497 | + $input .= "<option value=''></option>"; |
|
| 2498 | + |
|
| 2499 | + if(!$using_ajax) |
|
| 2500 | + { |
|
| 2501 | + $options_array = $this->get_relation_array($field_info->extras); |
|
| 2502 | + foreach($options_array as $option_value => $option) |
|
| 2503 | + { |
|
| 2504 | + $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
|
| 2505 | + $input .= "<option value='$option_value' $selected >$option</option>"; |
|
| 2506 | + } |
|
| 2507 | + } |
|
| 2508 | + elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
| 2509 | + { |
|
| 2510 | + $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
|
| 2511 | + foreach($selected_options_array as $option_value => $option) |
|
| 2512 | + { |
|
| 2513 | + $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
|
| 2514 | + } |
|
| 2515 | + } |
|
| 2516 | + |
|
| 2517 | + $input .= "</select>"; |
|
| 2518 | + return $input; |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + protected function get_relation_readonly_input($field_info,$value) |
|
| 2522 | + { |
|
| 2523 | + $options_array = $this->get_relation_array($field_info->extras); |
|
| 2524 | + |
|
| 2525 | + $value = isset($options_array[$value]) ? $options_array[$value] : ''; |
|
| 2526 | + |
|
| 2527 | + return $this->get_readonly_input($field_info, $value); |
|
| 2528 | + } |
|
| 2529 | + |
|
| 2530 | + protected function get_upload_file_readonly_input($field_info,$value) |
|
| 2531 | + { |
|
| 2532 | + $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
| 2533 | + |
|
| 2534 | + $value = !empty($value) ? '<a href="'.$file.'" target="_blank">'.$value.'</a>' : ''; |
|
| 2535 | + |
|
| 2536 | + return $this->get_readonly_input($field_info, $value); |
|
| 2537 | + } |
|
| 2538 | + |
|
| 2539 | + protected function get_relation_n_n_input($field_info_type, $selected_values) |
|
| 2540 | + { |
|
| 2541 | + $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; |
|
| 2542 | + $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; |
|
| 2543 | + |
|
| 2544 | + if($has_priority_field || $is_ie_7) |
|
| 2545 | + { |
|
| 2546 | + $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
|
| 2547 | + $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); |
|
| 2548 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
|
| 2549 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); |
|
| 2550 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); |
|
| 2551 | + |
|
| 2552 | + if($this->language !== 'english') |
|
| 2553 | + { |
|
| 2554 | + include($this->default_config_path.'/language_alias.php'); |
|
| 2555 | + if(array_key_exists($this->language, $language_alias)) |
|
| 2556 | + { |
|
| 2557 | + $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; |
|
| 2558 | + if(file_exists($i18n_date_js_file)) |
|
| 2559 | + { |
|
| 2560 | + $this->set_js_lib($i18n_date_js_file); |
|
| 2561 | + } |
|
| 2562 | + } |
|
| 2563 | + } |
|
| 2564 | + } |
|
| 2565 | + else |
|
| 2566 | + { |
|
| 2567 | + $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
|
| 2568 | + $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
|
| 2569 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
|
| 2573 | + |
|
| 2574 | + $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
| 2575 | + $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 2576 | + |
|
| 2577 | + if(empty($unselected_values) && empty($selected_values)) |
|
| 2578 | + { |
|
| 2579 | + $input = "Please add {$field_info_type->display_as} first"; |
|
| 2580 | + } |
|
| 2581 | + else |
|
| 2582 | + { |
|
| 2583 | + $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
|
| 2584 | + $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
|
| 2585 | + |
|
| 2586 | + $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
|
| 2587 | + $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
|
| 2588 | + |
|
| 2589 | + if(!empty($unselected_values)) |
|
| 2590 | + foreach($unselected_values as $id => $name) |
|
| 2591 | + { |
|
| 2592 | + $input .= "<option value='$id'>$name</option>"; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + if(!empty($selected_values)) |
|
| 2596 | + foreach($selected_values as $id => $name) |
|
| 2597 | + { |
|
| 2598 | + $input .= "<option value='$id' selected='selected'>$name</option>"; |
|
| 2599 | + } |
|
| 2600 | + |
|
| 2601 | + $input .= "</select>"; |
|
| 2602 | + } |
|
| 2603 | + |
|
| 2604 | + return $input; |
|
| 2605 | + } |
|
| 2606 | + |
|
| 2607 | + protected function _convert_bytes_ui_to_bytes($bytes_ui) |
|
| 2608 | + { |
|
| 2609 | + $bytes_ui = str_replace(' ','',$bytes_ui); |
|
| 2610 | + if(strstr($bytes_ui,'MB')) |
|
| 2611 | + $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
| 2612 | + elseif(strstr($bytes_ui,'KB')) |
|
| 2613 | + $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
| 2614 | + elseif(strstr($bytes_ui,'B')) |
|
| 2615 | + $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
| 2616 | + else |
|
| 2617 | + $bytes = (int)($bytes_ui); |
|
| 2618 | + |
|
| 2619 | + return $bytes; |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + protected function get_upload_file_input($field_info, $value) |
|
| 2623 | + { |
|
| 2624 | + $this->load_js_uploader(); |
|
| 2625 | + |
|
| 2626 | + //Fancybox |
|
| 2627 | + $this->load_js_fancybox(); |
|
| 2628 | + |
|
| 2629 | + $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js'); |
|
| 2630 | + |
|
| 2631 | + $unique = mt_rand(); |
|
| 2632 | + |
|
| 2633 | + $allowed_files = $this->config->file_upload_allow_file_types; |
|
| 2634 | + $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); |
|
| 2635 | + $max_file_size_ui = $this->config->file_upload_max_file_size; |
|
| 2636 | + $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
|
| 2637 | + |
|
| 2638 | + $this->_inline_js(' |
|
| 2639 | + var upload_info_'.$unique.' = { |
|
| 2640 | + accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, |
|
| 2641 | + accepted_file_types_ui : "'.$allowed_files_ui.'", |
|
| 2642 | + max_file_size: '.$max_file_size_bytes.', |
|
| 2643 | + max_file_size_ui: "'.$max_file_size_ui.'" |
|
| 2644 | + }; |
|
| 2645 | + |
|
| 2646 | + var string_upload_file = "'.$this->l('form_upload_a_file').'"; |
|
| 2647 | + var string_delete_file = "'.$this->l('string_delete_file').'"; |
|
| 2648 | + var string_progress = "'.$this->l('string_progress').'"; |
|
| 2649 | + var error_on_uploading = "'.$this->l('error_on_uploading').'"; |
|
| 2650 | + var message_prompt_delete_file = "'.$this->l('message_prompt_delete_file').'"; |
|
| 2651 | + |
|
| 2652 | + var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; |
|
| 2653 | + var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; |
|
| 2654 | + var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; |
|
| 2655 | + var error_min_file_size = "'.$this->l('error_min_file_size').'"; |
|
| 2656 | + |
|
| 2657 | + var base_url = "'.base_url().'"; |
|
| 2658 | + var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; |
|
| 2659 | + '); |
|
| 2660 | + |
|
| 2661 | + $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
| 2662 | + $file_display_none = empty($value) ? "display:none;" : ""; |
|
| 2663 | + |
|
| 2664 | + $is_image = !empty($value) && |
|
| 2665 | + ( substr($value,-4) == '.jpg' |
|
| 2666 | + || substr($value,-4) == '.png' |
|
| 2667 | + || substr($value,-5) == '.jpeg' |
|
| 2668 | + || substr($value,-4) == '.gif' |
|
| 2669 | + || substr($value,-5) == '.tiff') |
|
| 2670 | + ? true : false; |
|
| 2671 | + |
|
| 2672 | + $image_class = $is_image ? 'image-thumbnail' : ''; |
|
| 2673 | + |
|
| 2674 | + $input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'"> |
|
| 2675 | + <span>'.$this->l('form_upload_a_file').'</span> |
|
| 2676 | + <input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'"> |
|
| 2677 | + <input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" /> |
|
| 2678 | + </span>'; |
|
| 2679 | + |
|
| 2680 | + $this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css'); |
|
| 2681 | + |
|
| 2682 | + $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
|
| 2683 | + |
|
| 2684 | + $input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>"; |
|
| 2685 | + $input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>"; |
|
| 2686 | + $input .= "<a href='".$file_url."' id='file_$unique' class='open-file"; |
|
| 2687 | + $input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value"; |
|
| 2688 | + $input .= "</a> "; |
|
| 2689 | + $input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> "; |
|
| 2690 | + $input .= "</div><div style='clear:both'></div>"; |
|
| 2691 | + $input .= "<div id='loading-$unique' style='display:none'><span id='upload-state-message-$unique'></span> <span class='qq-upload-spinner'></span> <span id='progress-$unique'></span></div>"; |
|
| 2692 | + $input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>"; |
|
| 2693 | + $input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>"; |
|
| 2694 | + |
|
| 2695 | + return $input; |
|
| 2696 | + } |
|
| 2697 | + |
|
| 2698 | + protected function get_add_hidden_fields() |
|
| 2699 | + { |
|
| 2700 | + return $this->add_hidden_fields; |
|
| 2701 | + } |
|
| 2702 | + |
|
| 2703 | + protected function get_edit_hidden_fields() |
|
| 2704 | + { |
|
| 2705 | + return $this->edit_hidden_fields; |
|
| 2706 | + } |
|
| 2707 | + |
|
| 2708 | + protected function get_add_input_fields($field_values = null) |
|
| 2709 | + { |
|
| 2710 | + $fields = $this->get_add_fields(); |
|
| 2711 | + $types = $this->get_field_types(); |
|
| 2712 | + |
|
| 2713 | + $input_fields = array(); |
|
| 2714 | + |
|
| 2715 | + foreach($fields as $field_num => $field) |
|
| 2716 | + { |
|
| 2717 | + $field_info = $types[$field->field_name]; |
|
| 2718 | + |
|
| 2719 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2720 | + |
|
| 2721 | + if(!isset($this->callback_add_field[$field->field_name])) |
|
| 2722 | + { |
|
| 2723 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2724 | + } |
|
| 2725 | + else |
|
| 2726 | + { |
|
| 2727 | + $field_input = $field_info; |
|
| 2728 | + $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); |
|
| 2729 | + } |
|
| 2730 | + |
|
| 2731 | + switch ($field_info->crud_type) { |
|
| 2732 | + case 'invisible': |
|
| 2733 | + unset($this->add_fields[$field_num]); |
|
| 2734 | + unset($fields[$field_num]); |
|
| 2735 | + continue; |
|
| 2736 | + break; |
|
| 2737 | + case 'hidden': |
|
| 2738 | + $this->add_hidden_fields[] = $field_input; |
|
| 2739 | + unset($this->add_fields[$field_num]); |
|
| 2740 | + unset($fields[$field_num]); |
|
| 2741 | + continue; |
|
| 2742 | + break; |
|
| 2743 | + } |
|
| 2744 | + |
|
| 2745 | + $input_fields[$field->field_name] = $field_input; |
|
| 2746 | + } |
|
| 2747 | + |
|
| 2748 | + return $input_fields; |
|
| 2749 | + } |
|
| 2750 | + |
|
| 2751 | + protected function get_edit_input_fields($field_values = null) |
|
| 2752 | + { |
|
| 2753 | + $fields = $this->get_edit_fields(); |
|
| 2754 | + $types = $this->get_field_types(); |
|
| 2755 | + |
|
| 2756 | + $input_fields = array(); |
|
| 2757 | + |
|
| 2758 | + foreach($fields as $field_num => $field) |
|
| 2759 | + { |
|
| 2760 | + $field_info = $types[$field->field_name]; |
|
| 2761 | + |
|
| 2762 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2763 | + if(!isset($this->callback_edit_field[$field->field_name])) |
|
| 2764 | + { |
|
| 2765 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2766 | + } |
|
| 2767 | + else |
|
| 2768 | + { |
|
| 2769 | + $primary_key = $this->getStateInfo()->primary_key; |
|
| 2770 | + $field_input = $field_info; |
|
| 2771 | + $field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
| 2772 | + } |
|
| 2773 | + |
|
| 2774 | + switch ($field_info->crud_type) { |
|
| 2775 | + case 'invisible': |
|
| 2776 | + unset($this->edit_fields[$field_num]); |
|
| 2777 | + unset($fields[$field_num]); |
|
| 2778 | + continue; |
|
| 2779 | + break; |
|
| 2780 | + case 'hidden': |
|
| 2781 | + $this->edit_hidden_fields[] = $field_input; |
|
| 2782 | + unset($this->edit_fields[$field_num]); |
|
| 2783 | + unset($fields[$field_num]); |
|
| 2784 | + continue; |
|
| 2785 | + break; |
|
| 2786 | + } |
|
| 2787 | + |
|
| 2788 | + $input_fields[$field->field_name] = $field_input; |
|
| 2789 | + } |
|
| 2790 | + |
|
| 2791 | + return $input_fields; |
|
| 2792 | + } |
|
| 2793 | + |
|
| 2794 | + protected function get_read_input_fields($field_values = null) |
|
| 2795 | + { |
|
| 2796 | + $read_fields = $this->get_read_fields(); |
|
| 2797 | + |
|
| 2798 | + $this->field_types = null; |
|
| 2799 | + $this->required_fields = null; |
|
| 2800 | + |
|
| 2801 | + $read_inputs = array(); |
|
| 2802 | + foreach ($read_fields as $field) { |
|
| 2803 | + if (!empty($this->change_field_type) |
|
| 2804 | + && isset($this->change_field_type[$field->field_name]) |
|
| 2805 | + && $this->change_field_type[$field->field_name]->type == 'hidden') { |
|
| 2806 | + continue; |
|
| 2807 | + } |
|
| 2808 | + $this->field_type($field->field_name, 'readonly'); |
|
| 2809 | + } |
|
| 2810 | + |
|
| 2811 | + $fields = $this->get_read_fields(); |
|
| 2812 | + $types = $this->get_field_types(); |
|
| 2813 | + |
|
| 2814 | + $input_fields = array(); |
|
| 2815 | + |
|
| 2816 | + foreach($fields as $field_num => $field) |
|
| 2817 | + { |
|
| 2818 | + $field_info = $types[$field->field_name]; |
|
| 2819 | + |
|
| 2820 | + $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
|
| 2821 | + if(!isset($this->callback_read_field[$field->field_name])) |
|
| 2822 | + { |
|
| 2823 | + $field_input = $this->get_field_input($field_info, $field_value); |
|
| 2824 | + } |
|
| 2825 | + else |
|
| 2826 | + { |
|
| 2827 | + $primary_key = $this->getStateInfo()->primary_key; |
|
| 2828 | + $field_input = $field_info; |
|
| 2829 | + $field_input->input = call_user_func($this->callback_read_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values); |
|
| 2830 | + } |
|
| 2831 | + |
|
| 2832 | + switch ($field_info->crud_type) { |
|
| 2833 | + case 'invisible': |
|
| 2834 | + unset($this->read_fields[$field_num]); |
|
| 2835 | + unset($fields[$field_num]); |
|
| 2836 | + continue; |
|
| 2837 | + break; |
|
| 2838 | + case 'hidden': |
|
| 2839 | + $this->read_hidden_fields[] = $field_input; |
|
| 2840 | + unset($this->read_fields[$field_num]); |
|
| 2841 | + unset($fields[$field_num]); |
|
| 2842 | + continue; |
|
| 2843 | + break; |
|
| 2844 | + } |
|
| 2845 | + |
|
| 2846 | + $input_fields[$field->field_name] = $field_input; |
|
| 2847 | + } |
|
| 2848 | + |
|
| 2849 | + return $input_fields; |
|
| 2850 | + } |
|
| 2851 | + |
|
| 2852 | + protected function setThemeBasics() |
|
| 2853 | + { |
|
| 2854 | + $this->theme_path = $this->default_theme_path; |
|
| 2855 | + if(substr($this->theme_path,-1) != '/') |
|
| 2856 | + $this->theme_path = $this->theme_path.'/'; |
|
| 2857 | + |
|
| 2858 | + include($this->theme_path.$this->theme.'/config.php'); |
|
| 2859 | + |
|
| 2860 | + $this->theme_config = $config; |
|
| 2861 | + } |
|
| 2862 | + |
|
| 2863 | + public function set_theme($theme = null) |
|
| 2864 | + { |
|
| 2865 | + $this->theme = $theme; |
|
| 2866 | + |
|
| 2867 | + return $this; |
|
| 2868 | + } |
|
| 2869 | + |
|
| 2870 | + protected function _get_ajax_results() |
|
| 2871 | + { |
|
| 2872 | + //This is a $_POST request rather that $_GET request , because |
|
| 2873 | + //Codeigniter doesn't like the $_GET requests so much! |
|
| 2874 | + if ($this->_is_ajax()) { |
|
| 2875 | + @ob_end_clean(); |
|
| 2876 | + $results= (object)array( |
|
| 2877 | + 'output' => $this->views_as_string, |
|
| 2878 | + 'js_files' => array_values($this->get_js_files()), |
|
| 2879 | + 'js_lib_files' => array_values($this->get_js_lib_files()), |
|
| 2880 | + 'js_config_files' => array_values($this->get_js_config_files()), |
|
| 2881 | + 'css_files' => array_values($this->get_css_files()) |
|
| 2882 | + ); |
|
| 2883 | + |
|
| 2884 | + echo json_encode($results); |
|
| 2885 | + die; |
|
| 2886 | + } |
|
| 2887 | + //else just continue |
|
| 2888 | + } |
|
| 2889 | + |
|
| 2890 | + protected function _is_ajax() |
|
| 2891 | + { |
|
| 2892 | + return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
|
| 2893 | + } |
|
| 2894 | + |
|
| 2895 | + protected function _theme_view($view, $vars = array(), $return = FALSE) |
|
| 2896 | + { |
|
| 2897 | + $vars = (is_object($vars)) ? get_object_vars($vars) : $vars; |
|
| 2898 | + |
|
| 2899 | + $file_exists = FALSE; |
|
| 2900 | + |
|
| 2901 | + $ext = pathinfo($view, PATHINFO_EXTENSION); |
|
| 2902 | + $file = ($ext == '') ? $view.'.php' : $view; |
|
| 2903 | + |
|
| 2904 | + $view_file = $this->theme_path.$this->theme.'/views/'; |
|
| 2905 | + |
|
| 2906 | + if (file_exists($view_file.$file)) |
|
| 2907 | + { |
|
| 2908 | + $path = $view_file.$file; |
|
| 2909 | + $file_exists = TRUE; |
|
| 2910 | + } |
|
| 2911 | + |
|
| 2912 | + if ( ! $file_exists) |
|
| 2913 | + { |
|
| 2914 | + throw new Exception('Unable to load the requested file: '.$file, 16); |
|
| 2915 | + } |
|
| 2916 | + |
|
| 2917 | + extract($vars); |
|
| 2918 | + |
|
| 2919 | + #region buffering... |
|
| 2920 | + ob_start(); |
|
| 2921 | + |
|
| 2922 | + include($path); |
|
| 2923 | + |
|
| 2924 | + $buffer = ob_get_contents(); |
|
| 2925 | + @ob_end_clean(); |
|
| 2926 | + #endregion |
|
| 2927 | + |
|
| 2928 | + if ($return === TRUE) |
|
| 2929 | + { |
|
| 2930 | + return $buffer; |
|
| 2931 | + } |
|
| 2932 | + |
|
| 2933 | + $this->views_as_string .= $buffer; |
|
| 2934 | + } |
|
| 2935 | + |
|
| 2936 | + protected function _inline_js($inline_js = '') |
|
| 2937 | + { |
|
| 2938 | + $this->views_as_string .= "<script type=\"text/javascript\">\n{$inline_js}\n</script>\n"; |
|
| 2939 | + } |
|
| 2940 | + |
|
| 2941 | + protected function _add_js_vars($js_vars = array()) |
|
| 2942 | + { |
|
| 2943 | + $javascript_as_string = "<script type=\"text/javascript\">\n"; |
|
| 2944 | + foreach ($js_vars as $js_var => $js_value) { |
|
| 2945 | + $javascript_as_string .= "\tvar $js_var = '$js_value';\n"; |
|
| 2946 | + } |
|
| 2947 | + $javascript_as_string .= "\n</script>\n"; |
|
| 2948 | + $this->views_as_string .= $javascript_as_string; |
|
| 2949 | + } |
|
| 2950 | + |
|
| 2951 | + protected function get_views_as_string() |
|
| 2952 | + { |
|
| 2953 | + if(!empty($this->views_as_string)) |
|
| 2954 | + return $this->views_as_string; |
|
| 2955 | + else |
|
| 2956 | + return null; |
|
| 2957 | + } |
|
| 2958 | +} |
|
| 2959 | + |
|
| 2960 | + |
|
| 2961 | +/** |
|
| 2962 | + * PHP grocery CRUD |
|
| 2963 | + * |
|
| 2964 | + * LICENSE |
|
| 2965 | + * |
|
| 2966 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 2967 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 2968 | + * Please see the corresponding license file for details of these licenses. |
|
| 2969 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 2970 | + * |
|
| 2971 | + * @package grocery CRUD |
|
| 2972 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 2973 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 2974 | + * @author John Skoumbourdis <[email protected]> |
|
| 2975 | + */ |
|
| 2976 | + |
|
| 2977 | +// ------------------------------------------------------------------------ |
|
| 2978 | + |
|
| 2979 | +/** |
|
| 2980 | + * PHP grocery States |
|
| 2981 | + * |
|
| 2982 | + * States of grocery CRUD |
|
| 2983 | + * |
|
| 2984 | + * @package grocery CRUD |
|
| 2985 | + * @author John Skoumbourdis <[email protected]> |
|
| 2986 | + * @version 1.5.6 |
|
| 2987 | + */ |
|
| 2988 | +class grocery_CRUD_States extends grocery_CRUD_Layout |
|
| 2989 | +{ |
|
| 2990 | + const STATE_UNKNOWN = 0; |
|
| 2991 | + const STATE_LIST = 1; |
|
| 2992 | + const STATE_ADD = 2; |
|
| 2993 | + const STATE_EDIT = 3; |
|
| 2994 | + const STATE_DELETE = 4; |
|
| 2995 | + const STATE_INSERT = 5; |
|
| 2996 | + |
|
| 2997 | + const STATE_READ = 18; |
|
| 2998 | + const STATE_DELETE_MULTIPLE = '19'; |
|
| 2999 | + |
|
| 3000 | + protected $states = array( |
|
| 3001 | + 0 => 'unknown', |
|
| 3002 | + 1 => 'list', |
|
| 3003 | + 2 => 'add', |
|
| 3004 | + 3 => 'edit', |
|
| 3005 | + 4 => 'delete', |
|
| 3006 | + 5 => 'insert', |
|
| 3007 | + 6 => 'update', |
|
| 3008 | + 7 => 'ajax_list', |
|
| 3009 | + 8 => 'ajax_list_info', |
|
| 3010 | + 9 => 'insert_validation', |
|
| 3011 | + 10 => 'update_validation', |
|
| 3012 | + 11 => 'upload_file', |
|
| 3013 | + 12 => 'delete_file', |
|
| 3014 | + 13 => 'ajax_relation', |
|
| 3015 | + 14 => 'ajax_relation_n_n', |
|
| 3016 | + 15 => 'success', |
|
| 3017 | + 16 => 'export', |
|
| 3018 | + 17 => 'print', |
|
| 3019 | + 18 => 'read', |
|
| 3020 | + 19 => 'delete_multiple' |
|
| 3021 | + ); |
|
| 3022 | + |
|
| 3023 | + public function getStateInfo() |
|
| 3024 | + { |
|
| 3025 | + $state_code = $this->getStateCode(); |
|
| 3026 | + $segment_object = $this->get_state_info_from_url(); |
|
| 3027 | + |
|
| 3028 | + $first_parameter = $segment_object->first_parameter; |
|
| 3029 | + $second_parameter = $segment_object->second_parameter; |
|
| 3030 | + |
|
| 3031 | + $state_info = (object)array(); |
|
| 3032 | + |
|
| 3033 | + switch ($state_code) { |
|
| 3034 | + case self::STATE_LIST: |
|
| 3035 | + case self::STATE_ADD: |
|
| 3036 | + //for now... do nothing! Keeping this switch here in case we need any information at the future. |
|
| 3037 | + break; |
|
| 3038 | + |
|
| 3039 | + case self::STATE_EDIT: |
|
| 3040 | + case self::STATE_READ: |
|
| 3041 | + if ($first_parameter !== null) { |
|
| 3042 | + $state_info = (object) array('primary_key' => $first_parameter); |
|
| 3043 | + } else { |
|
| 3044 | + throw new Exception('On the state "edit" the Primary key cannot be null', 6); |
|
| 3045 | + die(); |
|
| 3046 | + } |
|
| 3047 | + break; |
|
| 3048 | + |
|
| 3049 | + case self::STATE_DELETE: |
|
| 3050 | + if ($first_parameter !== null) { |
|
| 3051 | + $state_info = (object) array('primary_key' => $first_parameter); |
|
| 3052 | + } else { |
|
| 3053 | + throw new Exception('On the state "delete" the Primary key cannot be null',7); |
|
| 3054 | + die(); |
|
| 3055 | + } |
|
| 3056 | + break; |
|
| 3057 | + |
|
| 3058 | + case self::STATE_DELETE_MULTIPLE: |
|
| 3059 | + if (!empty($_POST) && !empty($_POST['ids']) && is_array($_POST['ids'])) { |
|
| 3060 | + $state_info = (object) array('ids' => $_POST['ids']); |
|
| 3061 | + } else { |
|
| 3062 | + throw new Exception('On the state "Delete Multiple" you need send the ids as a post array.'); |
|
| 3063 | + die(); |
|
| 3064 | + } |
|
| 3065 | + break; |
|
| 3066 | + |
|
| 3067 | + case self::STATE_INSERT: |
|
| 3068 | + if(!empty($_POST)) |
|
| 3069 | + { |
|
| 3070 | + $state_info = (object)array('unwrapped_data' => $_POST); |
|
| 3071 | + } |
|
| 3072 | + else |
|
| 3073 | + { |
|
| 3074 | + throw new Exception('On the state "insert" you must have post data',8); |
|
| 3075 | + die(); |
|
| 3076 | + } |
|
| 3077 | + break; |
|
| 3078 | + |
|
| 3079 | + case 6: |
|
| 3080 | + if(!empty($_POST) && $first_parameter !== null) |
|
| 3081 | + { |
|
| 3082 | + $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
|
| 3083 | + } |
|
| 3084 | + elseif(empty($_POST)) |
|
| 3085 | + { |
|
| 3086 | + throw new Exception('On the state "update" you must have post data',9); |
|
| 3087 | + die(); |
|
| 3088 | + } |
|
| 3089 | + else |
|
| 3090 | + { |
|
| 3091 | + throw new Exception('On the state "update" the Primary key cannot be null',10); |
|
| 3092 | + die(); |
|
| 3093 | + } |
|
| 3094 | + break; |
|
| 3095 | + |
|
| 3096 | + case 7: |
|
| 3097 | + case 8: |
|
| 3098 | + case 16: //export to excel |
|
| 3099 | + case 17: //print |
|
| 3100 | + $state_info = (object)array(); |
|
| 3101 | + if(!empty($_POST['per_page'])) |
|
| 3102 | + { |
|
| 3103 | + $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; |
|
| 3104 | + } |
|
| 3105 | + if(!empty($_POST['page'])) |
|
| 3106 | + { |
|
| 3107 | + $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; |
|
| 3108 | + } |
|
| 3109 | + //If we request an export or a print we don't care about what page we are |
|
| 3110 | + if($state_code === 16 || $state_code === 17) |
|
| 3111 | + { |
|
| 3112 | + $state_info->page = 1; |
|
| 3113 | + $state_info->per_page = 1000000; //a very big number! |
|
| 3114 | + } |
|
| 3115 | + if(!empty($_POST['order_by'][0])) |
|
| 3116 | + { |
|
| 3117 | + $state_info->order_by = $_POST['order_by']; |
|
| 3118 | + } |
|
| 3119 | + if(!empty($_POST['search_text'])) |
|
| 3120 | + { |
|
| 3121 | + if(empty($_POST['search_field'])) |
|
| 3122 | + { |
|
| 3123 | + $search_text = strip_tags($_POST['search_field']); |
|
| 3124 | + $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
|
| 3125 | + } |
|
| 3126 | + else |
|
| 3127 | + { |
|
| 3128 | + if (is_array($_POST['search_field'])) { |
|
| 3129 | + $search_array = array(); |
|
| 3130 | + foreach ($_POST['search_field'] as $search_key => $search_field_name) { |
|
| 3131 | + $search_array[$search_field_name] = !empty($_POST['search_text'][$search_key]) ? $_POST['search_text'][$search_key] : ''; |
|
| 3132 | + } |
|
| 3133 | + $state_info->search = $search_array; |
|
| 3134 | + } else { |
|
| 3135 | + $state_info->search = (object)array( |
|
| 3136 | + 'field' => strip_tags($_POST['search_field']) , |
|
| 3137 | + 'text' => $_POST['search_text'] ); |
|
| 3138 | + } |
|
| 3139 | + } |
|
| 3140 | + } |
|
| 3141 | + break; |
|
| 3142 | + |
|
| 3143 | + case 9: |
|
| 3144 | + |
|
| 3145 | + break; |
|
| 3146 | + |
|
| 3147 | + case 10: |
|
| 3148 | + if($first_parameter !== null) |
|
| 3149 | + { |
|
| 3150 | + $state_info = (object)array('primary_key' => $first_parameter); |
|
| 3151 | + } |
|
| 3152 | + break; |
|
| 3153 | + |
|
| 3154 | + case 11: |
|
| 3155 | + $state_info->field_name = $first_parameter; |
|
| 3156 | + break; |
|
| 3157 | + |
|
| 3158 | + case 12: |
|
| 3159 | + $state_info->field_name = $first_parameter; |
|
| 3160 | + $state_info->file_name = $second_parameter; |
|
| 3161 | + break; |
|
| 3162 | + |
|
| 3163 | + case 13: |
|
| 3164 | + $state_info->field_name = $_POST['field_name']; |
|
| 3165 | + $state_info->search = $_POST['term']; |
|
| 3166 | + break; |
|
| 3167 | + |
|
| 3168 | + case 14: |
|
| 3169 | + $state_info->field_name = $_POST['field_name']; |
|
| 3170 | + $state_info->search = $_POST['term']; |
|
| 3171 | + break; |
|
| 3172 | + |
|
| 3173 | + case 15: |
|
| 3174 | + $state_info = (object)array( |
|
| 3175 | + 'primary_key' => $first_parameter, |
|
| 3176 | + 'success_message' => true |
|
| 3177 | + ); |
|
| 3178 | + break; |
|
| 3179 | + } |
|
| 3180 | + |
|
| 3181 | + return $state_info; |
|
| 3182 | + } |
|
| 3183 | + |
|
| 3184 | + protected function getStateCode() |
|
| 3185 | + { |
|
| 3186 | + $state_string = $this->get_state_info_from_url()->operation; |
|
| 3187 | + |
|
| 3188 | + if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
| 3189 | + $state_code = array_search($state_string, $this->states); |
|
| 3190 | + else |
|
| 3191 | + $state_code = 0; |
|
| 3192 | + |
|
| 3193 | + return $state_code; |
|
| 3194 | + } |
|
| 3195 | + |
|
| 3196 | + protected function state_url($url = '', $is_list_page = false) |
|
| 3197 | + { |
|
| 3198 | + //Easy scenario, we had set the crud_url_path |
|
| 3199 | + if (!empty($this->crud_url_path)) { |
|
| 3200 | + $state_url = !empty($this->list_url_path) && $is_list_page? |
|
| 3201 | + $this->list_url_path : |
|
| 3202 | + $this->crud_url_path.'/'.$url ; |
|
| 3203 | + } else { |
|
| 3204 | + //Complicated scenario. The crud_url_path is not specified so we are |
|
| 3205 | + //trying to understand what is going on from the URL. |
|
| 3206 | + $ci = &get_instance(); |
|
| 3207 | + |
|
| 3208 | + $segment_object = $this->get_state_info_from_url(); |
|
| 3209 | + $method_name = $this->get_method_name(); |
|
| 3210 | + $segment_position = $segment_object->segment_position; |
|
| 3211 | + |
|
| 3212 | + $state_url_array = array(); |
|
| 3213 | + |
|
| 3214 | + if( sizeof($ci->uri->segments) > 0 ) { |
|
| 3215 | + foreach($ci->uri->segments as $num => $value) |
|
| 3216 | + { |
|
| 3217 | + $state_url_array[$num] = $value; |
|
| 3218 | + if($num == ($segment_position - 1)) |
|
| 3219 | + break; |
|
| 3220 | + } |
|
| 3221 | + |
|
| 3222 | + if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
| 3223 | + $state_url_array[$num+1] = 'index'; |
|
| 3224 | + } |
|
| 3225 | + |
|
| 3226 | + $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
|
| 3227 | + } |
|
| 3228 | + |
|
| 3229 | + return $state_url; |
|
| 3230 | + } |
|
| 3231 | + |
|
| 3232 | + protected function get_state_info_from_url() |
|
| 3233 | + { |
|
| 3234 | + $ci = &get_instance(); |
|
| 3235 | + |
|
| 3236 | + $segment_position = count($ci->uri->segments) + 1; |
|
| 3237 | + $operation = 'list'; |
|
| 3238 | + |
|
| 3239 | + $segements = $ci->uri->segments; |
|
| 3240 | + foreach($segements as $num => $value) |
|
| 3241 | + { |
|
| 3242 | + if($value != 'unknown' && in_array($value, $this->states)) |
|
| 3243 | + { |
|
| 3244 | + $segment_position = (int)$num; |
|
| 3245 | + $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. |
|
| 3246 | + } |
|
| 3247 | + } |
|
| 3248 | + |
|
| 3249 | + $function_name = $this->get_method_name(); |
|
| 3250 | + |
|
| 3251 | + if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
| 3252 | + $segment_position++; |
|
| 3253 | + |
|
| 3254 | + $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
|
| 3255 | + $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
|
| 3256 | + |
|
| 3257 | + return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
| 3258 | + } |
|
| 3259 | + |
|
| 3260 | + protected function get_method_hash() |
|
| 3261 | + { |
|
| 3262 | + $ci = &get_instance(); |
|
| 3263 | + |
|
| 3264 | + $state_info = $this->get_state_info_from_url(); |
|
| 3265 | + $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; |
|
| 3266 | + |
|
| 3267 | + return $this->crud_url_path !== null |
|
| 3268 | + ? md5($this->crud_url_path) |
|
| 3269 | + : md5($this->get_controller_name().$this->get_method_name().$extra_values); |
|
| 3270 | + } |
|
| 3271 | + |
|
| 3272 | + protected function get_method_name() |
|
| 3273 | + { |
|
| 3274 | + $ci = &get_instance(); |
|
| 3275 | + return $ci->router->method; |
|
| 3276 | + } |
|
| 3277 | + |
|
| 3278 | + protected function get_controller_name() |
|
| 3279 | + { |
|
| 3280 | + $ci = &get_instance(); |
|
| 3281 | + return $ci->router->class; |
|
| 3282 | + } |
|
| 3283 | + |
|
| 3284 | + public function getState() |
|
| 3285 | + { |
|
| 3286 | + return $this->states[$this->getStateCode()]; |
|
| 3287 | + } |
|
| 3288 | + |
|
| 3289 | + protected function getListUrl() |
|
| 3290 | + { |
|
| 3291 | + return $this->state_url('',true); |
|
| 3292 | + } |
|
| 3293 | + |
|
| 3294 | + protected function getAjaxListUrl() |
|
| 3295 | + { |
|
| 3296 | + return $this->state_url('ajax_list'); |
|
| 3297 | + } |
|
| 3298 | + |
|
| 3299 | + protected function getExportToExcelUrl() |
|
| 3300 | + { |
|
| 3301 | + return $this->state_url('export'); |
|
| 3302 | + } |
|
| 3303 | + |
|
| 3304 | + protected function getPrintUrl() |
|
| 3305 | + { |
|
| 3306 | + return $this->state_url('print'); |
|
| 3307 | + } |
|
| 3308 | + |
|
| 3309 | + protected function getAjaxListInfoUrl() |
|
| 3310 | + { |
|
| 3311 | + return $this->state_url('ajax_list_info'); |
|
| 3312 | + } |
|
| 3313 | + |
|
| 3314 | + protected function getAddUrl() |
|
| 3315 | + { |
|
| 3316 | + return $this->state_url('add'); |
|
| 3317 | + } |
|
| 3318 | + |
|
| 3319 | + protected function getInsertUrl() |
|
| 3320 | + { |
|
| 3321 | + return $this->state_url('insert'); |
|
| 3322 | + } |
|
| 3323 | + |
|
| 3324 | + protected function getValidationInsertUrl() |
|
| 3325 | + { |
|
| 3326 | + return $this->state_url('insert_validation'); |
|
| 3327 | + } |
|
| 3328 | + |
|
| 3329 | + protected function getValidationUpdateUrl($primary_key = null) |
|
| 3330 | + { |
|
| 3331 | + if($primary_key === null) |
|
| 3332 | + return $this->state_url('update_validation'); |
|
| 3333 | + else |
|
| 3334 | + return $this->state_url('update_validation/'.$primary_key); |
|
| 3335 | + } |
|
| 3336 | + |
|
| 3337 | + protected function getEditUrl($primary_key = null) |
|
| 3338 | + { |
|
| 3339 | + if($primary_key === null) |
|
| 3340 | + return $this->state_url('edit'); |
|
| 3341 | + else |
|
| 3342 | + return $this->state_url('edit/'.$primary_key); |
|
| 3343 | + } |
|
| 3344 | + |
|
| 3345 | + protected function getReadUrl($primary_key = null) |
|
| 3346 | + { |
|
| 3347 | + if($primary_key === null) |
|
| 3348 | + return $this->state_url('read'); |
|
| 3349 | + else |
|
| 3350 | + return $this->state_url('read/'.$primary_key); |
|
| 3351 | + } |
|
| 3352 | + |
|
| 3353 | + protected function getUpdateUrl($state_info) |
|
| 3354 | + { |
|
| 3355 | + return $this->state_url('update/'.$state_info->primary_key); |
|
| 3356 | + } |
|
| 3357 | + |
|
| 3358 | + protected function getDeleteUrl($state_info = null) |
|
| 3359 | + { |
|
| 3360 | + if (empty($state_info)) { |
|
| 3361 | + return $this->state_url('delete'); |
|
| 3362 | + } else { |
|
| 3363 | + return $this->state_url('delete/'.$state_info->primary_key); |
|
| 3364 | + } |
|
| 3365 | + } |
|
| 3366 | + |
|
| 3367 | + protected function getDeleteMultipleUrl() |
|
| 3368 | + { |
|
| 3369 | + return $this->state_url('delete_multiple'); |
|
| 3370 | + } |
|
| 3371 | + |
|
| 3372 | + protected function getListSuccessUrl($primary_key = null) |
|
| 3373 | + { |
|
| 3374 | + if(empty($primary_key)) |
|
| 3375 | + return $this->state_url('success',true); |
|
| 3376 | + else |
|
| 3377 | + return $this->state_url('success/'.$primary_key,true); |
|
| 3378 | + } |
|
| 3379 | + |
|
| 3380 | + protected function getUploadUrl($field_name) |
|
| 3381 | + { |
|
| 3382 | + return $this->state_url('upload_file/'.$field_name); |
|
| 3383 | + } |
|
| 3384 | + |
|
| 3385 | + protected function getFileDeleteUrl($field_name) |
|
| 3386 | + { |
|
| 3387 | + return $this->state_url('delete_file/'.$field_name); |
|
| 3388 | + } |
|
| 3389 | + |
|
| 3390 | + protected function getAjaxRelationUrl() |
|
| 3391 | + { |
|
| 3392 | + return $this->state_url('ajax_relation'); |
|
| 3393 | + } |
|
| 3394 | + |
|
| 3395 | + protected function getAjaxRelationManytoManyUrl() |
|
| 3396 | + { |
|
| 3397 | + return $this->state_url('ajax_relation_n_n'); |
|
| 3398 | + } |
|
| 3399 | +} |
|
| 3400 | + |
|
| 3401 | + |
|
| 3402 | +/** |
|
| 3403 | + * PHP grocery CRUD |
|
| 3404 | + * |
|
| 3405 | + * LICENSE |
|
| 3406 | + * |
|
| 3407 | + * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 3408 | + * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 3409 | + * Please see the corresponding license file for details of these licenses. |
|
| 3410 | + * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 3411 | + * |
|
| 3412 | + * @package grocery CRUD |
|
| 3413 | + * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 3414 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 3415 | + * @version 1.5.6 |
|
| 3416 | + * @author John Skoumbourdis <[email protected]> |
|
| 3417 | + */ |
|
| 3418 | + |
|
| 3419 | +// ------------------------------------------------------------------------ |
|
| 3420 | + |
|
| 3421 | +/** |
|
| 3422 | + * PHP grocery CRUD |
|
| 3423 | + * |
|
| 3424 | + * Creates a full functional CRUD with few lines of code. |
|
| 3425 | + * |
|
| 3426 | + * @package grocery CRUD |
|
| 3427 | + * @author John Skoumbourdis <[email protected]> |
|
| 3428 | + * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 3429 | + * @link http://www.grocerycrud.com/documentation |
|
| 3430 | + */ |
|
| 3431 | +class Grocery_CRUD extends grocery_CRUD_States |
|
| 3432 | +{ |
|
| 3433 | + /** |
|
| 3434 | + * Grocery CRUD version |
|
| 3435 | + * |
|
| 3436 | + * @var string |
|
| 3437 | + */ |
|
| 3438 | + const VERSION = "1.5.6"; |
|
| 3439 | + |
|
| 3440 | + const JQUERY = "jquery-1.11.1.min.js"; |
|
| 3441 | + const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
| 3442 | + const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
| 3443 | + |
|
| 3444 | + protected $state_code = null; |
|
| 3445 | + protected $state_info = null; |
|
| 3446 | + protected $columns = null; |
|
| 3447 | + |
|
| 3448 | + private $basic_db_table_checked = false; |
|
| 3449 | + private $columns_checked = false; |
|
| 3450 | + private $add_fields_checked = false; |
|
| 3451 | + private $edit_fields_checked = false; |
|
| 3452 | + private $read_fields_checked = false; |
|
| 3453 | + |
|
| 3454 | + protected $default_theme = 'flexigrid'; |
|
| 3455 | + protected $language = null; |
|
| 3456 | + protected $lang_strings = array(); |
|
| 3457 | + protected $php_date_format = null; |
|
| 3458 | + protected $js_date_format = null; |
|
| 3459 | + protected $ui_date_format = null; |
|
| 3460 | + protected $character_limiter = null; |
|
| 3461 | + protected $config = null; |
|
| 3462 | + |
|
| 3463 | + protected $add_fields = null; |
|
| 3464 | + protected $edit_fields = null; |
|
| 3465 | + protected $read_fields = null; |
|
| 3466 | + protected $add_hidden_fields = array(); |
|
| 3467 | + protected $edit_hidden_fields = array(); |
|
| 3468 | + protected $field_types = null; |
|
| 3469 | + protected $basic_db_table = null; |
|
| 3470 | + protected $theme_config = array(); |
|
| 3471 | + protected $subject = null; |
|
| 3472 | + protected $subject_plural = null; |
|
| 3473 | + protected $display_as = array(); |
|
| 3474 | + protected $order_by = null; |
|
| 3475 | + protected $where = array(); |
|
| 3476 | + protected $like = array(); |
|
| 3477 | + protected $having = array(); |
|
| 3478 | + protected $or_having = array(); |
|
| 3479 | + protected $limit = null; |
|
| 3480 | + protected $required_fields = array(); |
|
| 3481 | + protected $_unique_fields = array(); |
|
| 3482 | + protected $validation_rules = array(); |
|
| 3483 | + protected $relation = array(); |
|
| 3484 | + protected $relation_n_n = array(); |
|
| 3485 | + protected $upload_fields = array(); |
|
| 3486 | + protected $actions = array(); |
|
| 3487 | + |
|
| 3488 | + protected $form_validation = null; |
|
| 3489 | + protected $change_field_type = null; |
|
| 3490 | + protected $primary_keys = array(); |
|
| 3491 | + protected $crud_url_path = null; |
|
| 3492 | + protected $list_url_path = null; |
|
| 3493 | + |
|
| 3494 | + /* The unsetters */ |
|
| 3495 | + protected $unset_texteditor = array(); |
|
| 3496 | + protected $unset_add = false; |
|
| 3497 | + protected $unset_edit = false; |
|
| 3498 | + protected $unset_delete = false; |
|
| 3499 | + protected $unset_read = false; |
|
| 3500 | + protected $unset_jquery = false; |
|
| 3501 | + protected $unset_jquery_ui = false; |
|
| 3502 | + protected $unset_bootstrap = false; |
|
| 3503 | + protected $unset_list = false; |
|
| 3504 | + protected $unset_export = false; |
|
| 3505 | + protected $unset_print = false; |
|
| 3506 | + protected $unset_back_to_list = false; |
|
| 3507 | + protected $unset_columns = null; |
|
| 3508 | + protected $unset_add_fields = null; |
|
| 3509 | + protected $unset_edit_fields = null; |
|
| 3510 | + protected $unset_read_fields = null; |
|
| 3511 | + |
|
| 3512 | + /* Callbacks */ |
|
| 3513 | + protected $callback_before_insert = null; |
|
| 3514 | + protected $callback_after_insert = null; |
|
| 3515 | + protected $callback_insert = null; |
|
| 3516 | + protected $callback_before_update = null; |
|
| 3517 | + protected $callback_after_update = null; |
|
| 3518 | + protected $callback_update = null; |
|
| 3519 | + protected $callback_before_delete = null; |
|
| 3520 | + protected $callback_after_delete = null; |
|
| 3521 | + protected $callback_delete = null; |
|
| 3522 | + protected $callback_column = array(); |
|
| 3523 | + protected $callback_add_field = array(); |
|
| 3524 | + protected $callback_edit_field = array(); |
|
| 3525 | + protected $callback_upload = null; |
|
| 3526 | + protected $callback_before_upload = null; |
|
| 3527 | + protected $callback_after_upload = null; |
|
| 3528 | + |
|
| 3529 | + protected $default_javascript_path = null; //autogenerate, please do not modify |
|
| 3530 | + protected $default_css_path = null; //autogenerate, please do not modify |
|
| 3531 | + protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
| 3532 | + protected $default_theme_path = null; //autogenerate, please do not modify |
|
| 3533 | + protected $default_language_path = 'assets/grocery_crud/languages'; |
|
| 3534 | + protected $default_config_path = 'assets/grocery_crud/config'; |
|
| 3535 | + protected $default_assets_path = 'assets/grocery_crud'; |
|
| 3536 | + |
|
| 3537 | + /** |
|
| 3538 | + * |
|
| 3539 | + * Constructor |
|
| 3540 | + * |
|
| 3541 | + * @access public |
|
| 3542 | + */ |
|
| 3543 | + public function __construct() |
|
| 3544 | + { |
|
| 3545 | + |
|
| 3546 | + } |
|
| 3547 | + |
|
| 3548 | + /** |
|
| 3549 | + * The displayed columns that user see |
|
| 3550 | + * |
|
| 3551 | + * @access public |
|
| 3552 | + * @param string |
|
| 3553 | + * @param array |
|
| 3554 | + * @return void |
|
| 3555 | + */ |
|
| 3556 | + public function columns() |
|
| 3557 | + { |
|
| 3558 | + $args = func_get_args(); |
|
| 3559 | + |
|
| 3560 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3561 | + { |
|
| 3562 | + $args = $args[0]; |
|
| 3563 | + } |
|
| 3564 | + |
|
| 3565 | + $this->columns = $args; |
|
| 3566 | + |
|
| 3567 | + return $this; |
|
| 3568 | + } |
|
| 3569 | + |
|
| 3570 | + |
|
| 3571 | + /** |
|
| 3572 | + * Set Validation Rules |
|
| 3573 | + * |
|
| 3574 | + * Important note: If the $field is an array then no automated crud fields will take apart |
|
| 3575 | + * |
|
| 3576 | + * @access public |
|
| 3577 | + * @param mixed |
|
| 3578 | + * @param string |
|
| 3579 | + * @return void |
|
| 3580 | + */ |
|
| 3581 | + function set_rules($field, $label = '', $rules = '') |
|
| 3582 | + { |
|
| 3583 | + if(is_string($field)) |
|
| 3584 | + { |
|
| 3585 | + $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
|
| 3586 | + }elseif(is_array($field)) |
|
| 3587 | + { |
|
| 3588 | + foreach($field as $num_field => $field_array) |
|
| 3589 | + { |
|
| 3590 | + $this->validation_rules[$field_array['field']] = $field_array; |
|
| 3591 | + } |
|
| 3592 | + } |
|
| 3593 | + return $this; |
|
| 3594 | + } |
|
| 3595 | + |
|
| 3596 | + /** |
|
| 3597 | + * |
|
| 3598 | + * Changes the default field type |
|
| 3599 | + * @param string $field |
|
| 3600 | + * @param string $type |
|
| 3601 | + * @param array|string $extras |
|
| 3602 | + */ |
|
| 3603 | + public function change_field_type($field , $type, $extras = null) |
|
| 3604 | + { |
|
| 3605 | + $field_type = (object)array('type' => $type); |
|
| 3606 | + |
|
| 3607 | + $field_type->extras = $extras; |
|
| 3608 | + |
|
| 3609 | + $this->change_field_type[$field] = $field_type; |
|
| 3610 | + |
|
| 3611 | + return $this; |
|
| 3612 | + } |
|
| 3613 | + |
|
| 3614 | + /** |
|
| 3615 | + * |
|
| 3616 | + * Just an alias to the change_field_type method |
|
| 3617 | + * @param string $field |
|
| 3618 | + * @param string $type |
|
| 3619 | + * @param array|string $extras |
|
| 3620 | + */ |
|
| 3621 | + public function field_type($field , $type, $extras = null) |
|
| 3622 | + { |
|
| 3623 | + return $this->change_field_type($field , $type, $extras); |
|
| 3624 | + } |
|
| 3625 | + |
|
| 3626 | + /** |
|
| 3627 | + * Change the default primary key for a specific table. |
|
| 3628 | + * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method |
|
| 3629 | + * |
|
| 3630 | + * @param string $primary_key_field |
|
| 3631 | + * @param string $table_name |
|
| 3632 | + */ |
|
| 3633 | + public function set_primary_key($primary_key_field, $table_name = null) |
|
| 3634 | + { |
|
| 3635 | + $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); |
|
| 3636 | + |
|
| 3637 | + return $this; |
|
| 3638 | + } |
|
| 3639 | + |
|
| 3640 | + /** |
|
| 3641 | + * Unsets the texteditor of the selected fields |
|
| 3642 | + * |
|
| 3643 | + * @access public |
|
| 3644 | + * @param string |
|
| 3645 | + * @param array |
|
| 3646 | + * @return void |
|
| 3647 | + */ |
|
| 3648 | + public function unset_texteditor() |
|
| 3649 | + { |
|
| 3650 | + $args = func_get_args(); |
|
| 3651 | + |
|
| 3652 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3653 | + { |
|
| 3654 | + $args = $args[0]; |
|
| 3655 | + } |
|
| 3656 | + foreach($args as $arg) |
|
| 3657 | + { |
|
| 3658 | + $this->unset_texteditor[] = $arg; |
|
| 3659 | + } |
|
| 3660 | + |
|
| 3661 | + return $this; |
|
| 3662 | + } |
|
| 3663 | + |
|
| 3664 | + /** |
|
| 3665 | + * Unsets just the jquery library from the js. This function can be used if there is already a jquery included |
|
| 3666 | + * in the main template. This will avoid all jquery conflicts. |
|
| 3667 | + * |
|
| 3668 | + * @return void |
|
| 3669 | + */ |
|
| 3670 | + public function unset_jquery() |
|
| 3671 | + { |
|
| 3672 | + $this->unset_jquery = true; |
|
| 3673 | + |
|
| 3674 | + return $this; |
|
| 3675 | + } |
|
| 3676 | + |
|
| 3677 | + /** |
|
| 3678 | + * Unsets the jquery UI Javascript and CSS. This function is really useful |
|
| 3679 | + * when the jquery UI JavaScript and CSS are already included in the main template. |
|
| 3680 | + * This will avoid all jquery UI conflicts. |
|
| 3681 | + * |
|
| 3682 | + * @return void |
|
| 3683 | + */ |
|
| 3684 | + public function unset_jquery_ui() |
|
| 3685 | + { |
|
| 3686 | + $this->unset_jquery_ui = true; |
|
| 3687 | + |
|
| 3688 | + return $this; |
|
| 3689 | + } |
|
| 3690 | + |
|
| 3691 | + /** |
|
| 3692 | + * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included |
|
| 3693 | + * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. |
|
| 3694 | + * |
|
| 3695 | + * @return void |
|
| 3696 | + */ |
|
| 3697 | + public function unset_bootstrap() |
|
| 3698 | + { |
|
| 3699 | + $this->unset_bootstrap = true; |
|
| 3700 | + |
|
| 3701 | + return $this; |
|
| 3702 | + } |
|
| 3703 | + |
|
| 3704 | + /** |
|
| 3705 | + * Unsets the add operation from the list |
|
| 3706 | + * |
|
| 3707 | + * @return void |
|
| 3708 | + */ |
|
| 3709 | + public function unset_add() |
|
| 3710 | + { |
|
| 3711 | + $this->unset_add = true; |
|
| 3712 | + |
|
| 3713 | + return $this; |
|
| 3714 | + } |
|
| 3715 | + |
|
| 3716 | + /** |
|
| 3717 | + * Unsets the edit operation from the list |
|
| 3718 | + * |
|
| 3719 | + * @return void |
|
| 3720 | + */ |
|
| 3721 | + public function unset_edit() |
|
| 3722 | + { |
|
| 3723 | + $this->unset_edit = true; |
|
| 3724 | + |
|
| 3725 | + return $this; |
|
| 3726 | + } |
|
| 3727 | + |
|
| 3728 | + /** |
|
| 3729 | + * Unsets the delete operation from the list |
|
| 3730 | + * |
|
| 3731 | + * @return void |
|
| 3732 | + */ |
|
| 3733 | + public function unset_delete() |
|
| 3734 | + { |
|
| 3735 | + $this->unset_delete = true; |
|
| 3736 | + |
|
| 3737 | + return $this; |
|
| 3738 | + } |
|
| 3739 | + |
|
| 3740 | + /** |
|
| 3741 | + * Unsets the read operation from the list |
|
| 3742 | + * |
|
| 3743 | + * @return void |
|
| 3744 | + */ |
|
| 3745 | + public function unset_read() |
|
| 3746 | + { |
|
| 3747 | + $this->unset_read = true; |
|
| 3748 | + |
|
| 3749 | + return $this; |
|
| 3750 | + } |
|
| 3751 | + |
|
| 3752 | + /** |
|
| 3753 | + * Just an alias to unset_read |
|
| 3754 | + * |
|
| 3755 | + * @return void |
|
| 3756 | + * */ |
|
| 3757 | + public function unset_view() |
|
| 3758 | + { |
|
| 3759 | + return unset_read(); |
|
| 3760 | + } |
|
| 3761 | + |
|
| 3762 | + /** |
|
| 3763 | + * Unsets the export button and functionality from the list |
|
| 3764 | + * |
|
| 3765 | + * @return void |
|
| 3766 | + */ |
|
| 3767 | + public function unset_export() |
|
| 3768 | + { |
|
| 3769 | + $this->unset_export = true; |
|
| 3770 | + |
|
| 3771 | + return $this; |
|
| 3772 | + } |
|
| 3773 | + |
|
| 3774 | + |
|
| 3775 | + /** |
|
| 3776 | + * Unsets the print button and functionality from the list |
|
| 3777 | + * |
|
| 3778 | + * @return void |
|
| 3779 | + */ |
|
| 3780 | + public function unset_print() |
|
| 3781 | + { |
|
| 3782 | + $this->unset_print = true; |
|
| 3783 | + |
|
| 3784 | + return $this; |
|
| 3785 | + } |
|
| 3786 | + |
|
| 3787 | + /** |
|
| 3788 | + * Unsets all the operations from the list |
|
| 3789 | + * |
|
| 3790 | + * @return void |
|
| 3791 | + */ |
|
| 3792 | + public function unset_operations() |
|
| 3793 | + { |
|
| 3794 | + $this->unset_add = true; |
|
| 3795 | + $this->unset_edit = true; |
|
| 3796 | + $this->unset_delete = true; |
|
| 3797 | + $this->unset_read = true; |
|
| 3798 | + $this->unset_export = true; |
|
| 3799 | + $this->unset_print = true; |
|
| 3800 | + |
|
| 3801 | + return $this; |
|
| 3802 | + } |
|
| 3803 | + |
|
| 3804 | + /** |
|
| 3805 | + * Unsets a column from the list |
|
| 3806 | + * |
|
| 3807 | + * @return void. |
|
| 3808 | + */ |
|
| 3809 | + public function unset_columns() |
|
| 3810 | + { |
|
| 3811 | + $args = func_get_args(); |
|
| 3812 | + |
|
| 3813 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3814 | + { |
|
| 3815 | + $args = $args[0]; |
|
| 3816 | + } |
|
| 3817 | + |
|
| 3818 | + $this->unset_columns = $args; |
|
| 3819 | + |
|
| 3820 | + return $this; |
|
| 3821 | + } |
|
| 3822 | + |
|
| 3823 | + public function unset_list() |
|
| 3824 | + { |
|
| 3825 | + $this->unset_list = true; |
|
| 3826 | + |
|
| 3827 | + return $this; |
|
| 3828 | + } |
|
| 3829 | + |
|
| 3830 | + public function unset_fields() |
|
| 3831 | + { |
|
| 3832 | + $args = func_get_args(); |
|
| 3833 | + |
|
| 3834 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3835 | + { |
|
| 3836 | + $args = $args[0]; |
|
| 3837 | + } |
|
| 3838 | + |
|
| 3839 | + $this->unset_add_fields = $args; |
|
| 3840 | + $this->unset_edit_fields = $args; |
|
| 3841 | + $this->unset_read_fields = $args; |
|
| 3842 | + |
|
| 3843 | + return $this; |
|
| 3844 | + } |
|
| 3845 | + |
|
| 3846 | + public function unset_add_fields() |
|
| 3847 | + { |
|
| 3848 | + $args = func_get_args(); |
|
| 3849 | + |
|
| 3850 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3851 | + { |
|
| 3852 | + $args = $args[0]; |
|
| 3853 | + } |
|
| 3854 | + |
|
| 3855 | + $this->unset_add_fields = $args; |
|
| 3856 | + |
|
| 3857 | + return $this; |
|
| 3858 | + } |
|
| 3859 | + |
|
| 3860 | + public function unset_edit_fields() |
|
| 3861 | + { |
|
| 3862 | + $args = func_get_args(); |
|
| 3863 | + |
|
| 3864 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3865 | + { |
|
| 3866 | + $args = $args[0]; |
|
| 3867 | + } |
|
| 3868 | + |
|
| 3869 | + $this->unset_edit_fields = $args; |
|
| 3870 | + |
|
| 3871 | + return $this; |
|
| 3872 | + } |
|
| 3873 | + |
|
| 3874 | + public function unset_read_fields() |
|
| 3875 | + { |
|
| 3876 | + $args = func_get_args(); |
|
| 3877 | + |
|
| 3878 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3879 | + { |
|
| 3880 | + $args = $args[0]; |
|
| 3881 | + } |
|
| 3882 | + |
|
| 3883 | + $this->unset_read_fields = $args; |
|
| 3884 | + |
|
| 3885 | + return $this; |
|
| 3886 | + } |
|
| 3887 | + |
|
| 3888 | + |
|
| 3889 | + /** |
|
| 3890 | + * Unsets everything that has to do with buttons or links with go back to list message |
|
| 3891 | + * @access public |
|
| 3892 | + * @return void |
|
| 3893 | + */ |
|
| 3894 | + public function unset_back_to_list() |
|
| 3895 | + { |
|
| 3896 | + $this->unset_back_to_list = true; |
|
| 3897 | + |
|
| 3898 | + return $this; |
|
| 3899 | + } |
|
| 3900 | + |
|
| 3901 | + /** |
|
| 3902 | + * |
|
| 3903 | + * The fields that user will see on add/edit |
|
| 3904 | + * |
|
| 3905 | + * @access public |
|
| 3906 | + * @param string |
|
| 3907 | + * @param array |
|
| 3908 | + * @return void |
|
| 3909 | + */ |
|
| 3910 | + public function fields() |
|
| 3911 | + { |
|
| 3912 | + $args = func_get_args(); |
|
| 3913 | + |
|
| 3914 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3915 | + { |
|
| 3916 | + $args = $args[0]; |
|
| 3917 | + } |
|
| 3918 | + |
|
| 3919 | + $this->add_fields = $args; |
|
| 3920 | + $this->edit_fields = $args; |
|
| 3921 | + |
|
| 3922 | + return $this; |
|
| 3923 | + } |
|
| 3924 | + |
|
| 3925 | + /** |
|
| 3926 | + * |
|
| 3927 | + * The fields that user can see . It is only for the add form |
|
| 3928 | + */ |
|
| 3929 | + public function add_fields() |
|
| 3930 | + { |
|
| 3931 | + $args = func_get_args(); |
|
| 3932 | + |
|
| 3933 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3934 | + { |
|
| 3935 | + $args = $args[0]; |
|
| 3936 | + } |
|
| 3937 | + |
|
| 3938 | + $this->add_fields = $args; |
|
| 3939 | + |
|
| 3940 | + return $this; |
|
| 3941 | + } |
|
| 3942 | + |
|
| 3943 | + /** |
|
| 3944 | + * |
|
| 3945 | + * The fields that user can see . It is only for the edit form |
|
| 3946 | + */ |
|
| 3947 | + public function edit_fields() |
|
| 3948 | + { |
|
| 3949 | + $args = func_get_args(); |
|
| 3950 | + |
|
| 3951 | + if(isset($args[0]) && is_array($args[0])) |
|
| 3952 | + { |
|
| 3953 | + $args = $args[0]; |
|
| 3954 | + } |
|
| 3955 | + |
|
| 3956 | + $this->edit_fields = $args; |
|
| 3957 | + |
|
| 3958 | + return $this; |
|
| 3959 | + } |
|
| 3960 | + |
|
| 3961 | + public function set_read_fields() |
|
| 3962 | + { |
|
| 3963 | + $args = func_get_args(); |
|
| 3964 | + |
|
| 3965 | + if(isset($args[0]) && is_array($args[0])) { |
|
| 3966 | + $args = $args[0]; |
|
| 3967 | + } |
|
| 3968 | + |
|
| 3969 | + $this->read_fields = $args; |
|
| 3970 | + |
|
| 3971 | + return $this; |
|
| 3972 | + } |
|
| 3973 | + |
|
| 3974 | + /** |
|
| 3975 | + * |
|
| 3976 | + * Changes the displaying label of the field |
|
| 3977 | + * @param $field_name |
|
| 3978 | + * @param $display_as |
|
| 3979 | + * @return void |
|
| 3980 | + */ |
|
| 3981 | + public function display_as($field_name, $display_as = null) |
|
| 3982 | + { |
|
| 3983 | + if(is_array($field_name)) |
|
| 3984 | + { |
|
| 3985 | + foreach($field_name as $field => $display_as) |
|
| 3986 | + { |
|
| 3987 | + $this->display_as[$field] = $display_as; |
|
| 3988 | + } |
|
| 3989 | + } |
|
| 3990 | + elseif($display_as !== null) |
|
| 3991 | + { |
|
| 3992 | + $this->display_as[$field_name] = $display_as; |
|
| 3993 | + } |
|
| 3994 | + return $this; |
|
| 3995 | + } |
|
| 3996 | + |
|
| 3997 | + /** |
|
| 3998 | + * |
|
| 3999 | + * Load the language strings array from the language file |
|
| 4000 | + */ |
|
| 4001 | + protected function _load_language() |
|
| 4002 | + { |
|
| 4003 | + if($this->language === null) |
|
| 4004 | + { |
|
| 4005 | + $this->language = strtolower($this->config->default_language); |
|
| 4006 | + } |
|
| 4007 | + include($this->default_language_path.'/'.$this->language.'.php'); |
|
| 4008 | + |
|
| 4009 | + foreach($lang as $handle => $lang_string) |
|
| 4010 | + if(!isset($this->lang_strings[$handle])) |
|
| 4011 | + $this->lang_strings[$handle] = $lang_string; |
|
| 4012 | + |
|
| 4013 | + $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
|
| 4014 | + $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
|
| 4015 | + |
|
| 4016 | + } |
|
| 4017 | + |
|
| 4018 | + protected function _load_date_format() |
|
| 4019 | + { |
|
| 4020 | + list($php_day, $php_month, $php_year) = array('d','m','Y'); |
|
| 4021 | + list($js_day, $js_month, $js_year) = array('dd','mm','yy'); |
|
| 4022 | + list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); |
|
| 4023 | + |
|
| 4024 | + $date_format = $this->config->date_format; |
|
| 4025 | + switch ($date_format) { |
|
| 4026 | + case 'uk-date': |
|
| 4027 | + $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
| 4028 | + $this->js_date_format = "$js_day/$js_month/$js_year"; |
|
| 4029 | + $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; |
|
| 4030 | + break; |
|
| 4031 | + |
|
| 4032 | + case 'us-date': |
|
| 4033 | + $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
| 4034 | + $this->js_date_format = "$js_month/$js_day/$js_year"; |
|
| 4035 | + $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; |
|
| 4036 | + break; |
|
| 4037 | + |
|
| 4038 | + case 'sql-date': |
|
| 4039 | + default: |
|
| 4040 | + $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
| 4041 | + $this->js_date_format = "$js_year-$js_month-$js_day"; |
|
| 4042 | + $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; |
|
| 4043 | + break; |
|
| 4044 | + } |
|
| 4045 | + } |
|
| 4046 | + |
|
| 4047 | + /** |
|
| 4048 | + * |
|
| 4049 | + * Set a language string directly |
|
| 4050 | + * @param string $handle |
|
| 4051 | + * @param string $string |
|
| 4052 | + */ |
|
| 4053 | + public function set_lang_string($handle, $lang_string){ |
|
| 4054 | + $this->lang_strings[$handle] = $lang_string; |
|
| 4055 | + |
|
| 4056 | + return $this; |
|
| 4057 | + } |
|
| 4058 | + |
|
| 4059 | + /** |
|
| 4060 | + * |
|
| 4061 | + * Just an alias to get_lang_string method |
|
| 4062 | + * @param string $handle |
|
| 4063 | + */ |
|
| 4064 | + public function l($handle) |
|
| 4065 | + { |
|
| 4066 | + return $this->get_lang_string($handle); |
|
| 4067 | + } |
|
| 4068 | + |
|
| 4069 | + /** |
|
| 4070 | + * |
|
| 4071 | + * Get the language string of the inserted string handle |
|
| 4072 | + * @param string $handle |
|
| 4073 | + */ |
|
| 4074 | + public function get_lang_string($handle) |
|
| 4075 | + { |
|
| 4076 | + return $this->lang_strings[$handle]; |
|
| 4077 | + } |
|
| 4078 | + |
|
| 4079 | + /** |
|
| 4080 | + * |
|
| 4081 | + * Simply set the language |
|
| 4082 | + * @example english |
|
| 4083 | + * @param string $language |
|
| 4084 | + */ |
|
| 4085 | + public function set_language($language) |
|
| 4086 | + { |
|
| 4087 | + $this->language = $language; |
|
| 4088 | + |
|
| 4089 | + return $this; |
|
| 4090 | + } |
|
| 4091 | + |
|
| 4092 | + /** |
|
| 4093 | + * |
|
| 4094 | + * Enter description here ... |
|
| 4095 | + */ |
|
| 4096 | + protected function get_columns() |
|
| 4097 | + { |
|
| 4098 | + if($this->columns_checked === false) |
|
| 4099 | + { |
|
| 4100 | + $field_types = $this->get_field_types(); |
|
| 4101 | + if(empty($this->columns)) |
|
| 4102 | + { |
|
| 4103 | + $this->columns = array(); |
|
| 4104 | + foreach($field_types as $field) |
|
| 4105 | + { |
|
| 4106 | + if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
| 4107 | + $this->columns[] = $field->name; |
|
| 4108 | + } |
|
| 4109 | + } |
|
| 4110 | + |
|
| 4111 | + foreach($this->columns as $col_num => $column) |
|
| 4112 | + { |
|
| 4113 | + |
|
| 4114 | + if(isset($this->relation[$column])) |
|
| 4115 | + { |
|
| 4116 | + |
|
| 4117 | + $new_column = $this->_unique_field_name($this->relation[$column][0]); |
|
| 4118 | + $this->columns[$col_num] = $new_column; |
|
| 4119 | + |
|
| 4120 | + if(isset($this->display_as[$column])) |
|
| 3127 | 4121 | { |
| 3128 | - if (is_array($_POST['search_field'])) { |
|
| 3129 | - $search_array = array(); |
|
| 3130 | - foreach ($_POST['search_field'] as $search_key => $search_field_name) { |
|
| 3131 | - $search_array[$search_field_name] = !empty($_POST['search_text'][$search_key]) ? $_POST['search_text'][$search_key] : ''; |
|
| 4122 | + $display_as = $this->display_as[$column]; |
|
| 4123 | + unset($this->display_as[$column]); |
|
| 4124 | + $this->display_as[$new_column] = $display_as; |
|
| 4125 | + } |
|
| 4126 | + else |
|
| 4127 | + { |
|
| 4128 | + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4129 | + } |
|
| 4130 | + |
|
| 4131 | + $column = $new_column; |
|
| 4132 | + $this->columns[$col_num] = $new_column; |
|
| 4133 | + } |
|
| 4134 | + else |
|
| 4135 | + { |
|
| 4136 | + if(!empty($this->relation)) |
|
| 4137 | + { |
|
| 4138 | + $table_name = $this->get_table(); |
|
| 4139 | + foreach($this->relation as $relation) |
|
| 4140 | + { |
|
| 4141 | + if( $relation[2] == $column ) |
|
| 4142 | + { |
|
| 4143 | + $new_column = $table_name.'.'.$column; |
|
| 4144 | + if(isset($this->display_as[$column])) |
|
| 4145 | + { |
|
| 4146 | + $display_as = $this->display_as[$column]; |
|
| 4147 | + unset($this->display_as[$column]); |
|
| 4148 | + $this->display_as[$new_column] = $display_as; |
|
| 4149 | + } |
|
| 4150 | + else |
|
| 4151 | + { |
|
| 4152 | + $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4153 | + } |
|
| 4154 | + |
|
| 4155 | + $column = $new_column; |
|
| 4156 | + $this->columns[$col_num] = $new_column; |
|
| 3132 | 4157 | } |
| 3133 | - $state_info->search = $search_array; |
|
| 3134 | - } else { |
|
| 3135 | - $state_info->search = (object)array( |
|
| 3136 | - 'field' => strip_tags($_POST['search_field']) , |
|
| 3137 | - 'text' => $_POST['search_text'] ); |
|
| 3138 | 4158 | } |
| 3139 | 4159 | } |
| 4160 | + |
|
| 3140 | 4161 | } |
| 3141 | - break; |
|
| 3142 | 4162 | |
| 3143 | - case 9: |
|
| 4163 | + if(isset($this->display_as[$column])) |
|
| 4164 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4165 | + elseif(isset($field_types[$column])) |
|
| 4166 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4167 | + else |
|
| 4168 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
| 4169 | + ucfirst(str_replace('_',' ',$column))); |
|
| 3144 | 4170 | |
| 3145 | - break; |
|
| 4171 | + if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
|
| 4172 | + { |
|
| 4173 | + unset($this->columns[$col_num]); |
|
| 4174 | + } |
|
| 4175 | + } |
|
| 3146 | 4176 | |
| 3147 | - case 10: |
|
| 3148 | - if($first_parameter !== null) |
|
| 4177 | + $this->columns_checked = true; |
|
| 4178 | + |
|
| 4179 | + } |
|
| 4180 | + |
|
| 4181 | + return $this->columns; |
|
| 4182 | + } |
|
| 4183 | + |
|
| 4184 | + /** |
|
| 4185 | + * |
|
| 4186 | + * Enter description here ... |
|
| 4187 | + */ |
|
| 4188 | + protected function get_add_fields() |
|
| 4189 | + { |
|
| 4190 | + if($this->add_fields_checked === false) |
|
| 4191 | + { |
|
| 4192 | + $field_types = $this->get_field_types(); |
|
| 4193 | + if(!empty($this->add_fields)) |
|
| 4194 | + { |
|
| 4195 | + foreach($this->add_fields as $field_num => $field) |
|
| 3149 | 4196 | { |
| 3150 | - $state_info = (object)array('primary_key' => $first_parameter); |
|
| 4197 | + if(isset($this->display_as[$field])) |
|
| 4198 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4199 | + elseif(isset($field_types[$field]->display_as)) |
|
| 4200 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4201 | + else |
|
| 4202 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
| 3151 | 4203 | } |
| 3152 | - break; |
|
| 4204 | + } |
|
| 4205 | + else |
|
| 4206 | + { |
|
| 4207 | + $this->add_fields = array(); |
|
| 4208 | + foreach($field_types as $field) |
|
| 4209 | + { |
|
| 4210 | + //Check if an unset_add_field is initialize for this field name |
|
| 4211 | + if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
| 4212 | + continue; |
|
| 3153 | 4213 | |
| 3154 | - case 11: |
|
| 3155 | - $state_info->field_name = $first_parameter; |
|
| 3156 | - break; |
|
| 4214 | + if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
|
| 4215 | + { |
|
| 4216 | + if(isset($this->display_as[$field->name])) |
|
| 4217 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4218 | + else |
|
| 4219 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4220 | + } |
|
| 4221 | + } |
|
| 4222 | + } |
|
| 3157 | 4223 | |
| 3158 | - case 12: |
|
| 3159 | - $state_info->field_name = $first_parameter; |
|
| 3160 | - $state_info->file_name = $second_parameter; |
|
| 3161 | - break; |
|
| 4224 | + $this->add_fields_checked = true; |
|
| 4225 | + } |
|
| 4226 | + return $this->add_fields; |
|
| 4227 | + } |
|
| 3162 | 4228 | |
| 3163 | - case 13: |
|
| 3164 | - $state_info->field_name = $_POST['field_name']; |
|
| 3165 | - $state_info->search = $_POST['term']; |
|
| 3166 | - break; |
|
| 4229 | + /** |
|
| 4230 | + * |
|
| 4231 | + * Enter description here ... |
|
| 4232 | + */ |
|
| 4233 | + protected function get_edit_fields() |
|
| 4234 | + { |
|
| 4235 | + if($this->edit_fields_checked === false) |
|
| 4236 | + { |
|
| 4237 | + $field_types = $this->get_field_types(); |
|
| 4238 | + if(!empty($this->edit_fields)) |
|
| 4239 | + { |
|
| 4240 | + foreach($this->edit_fields as $field_num => $field) |
|
| 4241 | + { |
|
| 4242 | + if(isset($this->display_as[$field])) |
|
| 4243 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4244 | + else |
|
| 4245 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4246 | + } |
|
| 4247 | + } |
|
| 4248 | + else |
|
| 4249 | + { |
|
| 4250 | + $this->edit_fields = array(); |
|
| 4251 | + foreach($field_types as $field) |
|
| 4252 | + { |
|
| 4253 | + //Check if an unset_edit_field is initialize for this field name |
|
| 4254 | + if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
| 4255 | + continue; |
|
| 3167 | 4256 | |
| 3168 | - case 14: |
|
| 3169 | - $state_info->field_name = $_POST['field_name']; |
|
| 3170 | - $state_info->search = $_POST['term']; |
|
| 3171 | - break; |
|
| 4257 | + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4258 | + { |
|
| 4259 | + if(isset($this->display_as[$field->name])) |
|
| 4260 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4261 | + else |
|
| 4262 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4263 | + } |
|
| 4264 | + } |
|
| 4265 | + } |
|
| 3172 | 4266 | |
| 3173 | - case 15: |
|
| 3174 | - $state_info = (object)array( |
|
| 3175 | - 'primary_key' => $first_parameter, |
|
| 3176 | - 'success_message' => true |
|
| 3177 | - ); |
|
| 3178 | - break; |
|
| 4267 | + $this->edit_fields_checked = true; |
|
| 3179 | 4268 | } |
| 4269 | + return $this->edit_fields; |
|
| 4270 | + } |
|
| 3180 | 4271 | |
| 3181 | - return $state_info; |
|
| 4272 | + /** |
|
| 4273 | + * |
|
| 4274 | + * Enter description here ... |
|
| 4275 | + */ |
|
| 4276 | + protected function get_read_fields() |
|
| 4277 | + { |
|
| 4278 | + if($this->read_fields_checked === false) |
|
| 4279 | + { |
|
| 4280 | + $field_types = $this->get_field_types(); |
|
| 4281 | + if(!empty($this->read_fields)) |
|
| 4282 | + { |
|
| 4283 | + foreach($this->read_fields as $field_num => $field) |
|
| 4284 | + { |
|
| 4285 | + if(isset($this->display_as[$field])) |
|
| 4286 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4287 | + else |
|
| 4288 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4289 | + } |
|
| 4290 | + } |
|
| 4291 | + else |
|
| 4292 | + { |
|
| 4293 | + $this->read_fields = array(); |
|
| 4294 | + foreach($field_types as $field) |
|
| 4295 | + { |
|
| 4296 | + //Check if an unset_read_field is initialize for this field name |
|
| 4297 | + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
| 4298 | + continue; |
|
| 4299 | + |
|
| 4300 | + if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4301 | + { |
|
| 4302 | + if(isset($this->display_as[$field->name])) |
|
| 4303 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4304 | + else |
|
| 4305 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4306 | + } |
|
| 4307 | + } |
|
| 4308 | + } |
|
| 4309 | + |
|
| 4310 | + $this->read_fields_checked = true; |
|
| 4311 | + } |
|
| 4312 | + return $this->read_fields; |
|
| 3182 | 4313 | } |
| 3183 | 4314 | |
| 3184 | - protected function getStateCode() |
|
| 3185 | - { |
|
| 3186 | - $state_string = $this->get_state_info_from_url()->operation; |
|
| 3187 | - |
|
| 3188 | - if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
| 3189 | - $state_code = array_search($state_string, $this->states); |
|
| 3190 | - else |
|
| 3191 | - $state_code = 0; |
|
| 3192 | - |
|
| 3193 | - return $state_code; |
|
| 3194 | - } |
|
| 3195 | - |
|
| 3196 | - protected function state_url($url = '', $is_list_page = false) |
|
| 3197 | - { |
|
| 3198 | - //Easy scenario, we had set the crud_url_path |
|
| 3199 | - if (!empty($this->crud_url_path)) { |
|
| 3200 | - $state_url = !empty($this->list_url_path) && $is_list_page? |
|
| 3201 | - $this->list_url_path : |
|
| 3202 | - $this->crud_url_path.'/'.$url ; |
|
| 3203 | - } else { |
|
| 3204 | - //Complicated scenario. The crud_url_path is not specified so we are |
|
| 3205 | - //trying to understand what is going on from the URL. |
|
| 3206 | - $ci = &get_instance(); |
|
| 3207 | - |
|
| 3208 | - $segment_object = $this->get_state_info_from_url(); |
|
| 3209 | - $method_name = $this->get_method_name(); |
|
| 3210 | - $segment_position = $segment_object->segment_position; |
|
| 3211 | - |
|
| 3212 | - $state_url_array = array(); |
|
| 3213 | - |
|
| 3214 | - if( sizeof($ci->uri->segments) > 0 ) { |
|
| 3215 | - foreach($ci->uri->segments as $num => $value) |
|
| 3216 | - { |
|
| 3217 | - $state_url_array[$num] = $value; |
|
| 3218 | - if($num == ($segment_position - 1)) |
|
| 3219 | - break; |
|
| 3220 | - } |
|
| 3221 | - |
|
| 3222 | - if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
| 3223 | - $state_url_array[$num+1] = 'index'; |
|
| 3224 | - } |
|
| 3225 | - |
|
| 3226 | - $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
|
| 3227 | - } |
|
| 3228 | - |
|
| 3229 | - return $state_url; |
|
| 3230 | - } |
|
| 3231 | - |
|
| 3232 | - protected function get_state_info_from_url() |
|
| 3233 | - { |
|
| 3234 | - $ci = &get_instance(); |
|
| 3235 | - |
|
| 3236 | - $segment_position = count($ci->uri->segments) + 1; |
|
| 3237 | - $operation = 'list'; |
|
| 3238 | - |
|
| 3239 | - $segements = $ci->uri->segments; |
|
| 3240 | - foreach($segements as $num => $value) |
|
| 3241 | - { |
|
| 3242 | - if($value != 'unknown' && in_array($value, $this->states)) |
|
| 3243 | - { |
|
| 3244 | - $segment_position = (int)$num; |
|
| 3245 | - $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. |
|
| 3246 | - } |
|
| 3247 | - } |
|
| 3248 | - |
|
| 3249 | - $function_name = $this->get_method_name(); |
|
| 3250 | - |
|
| 3251 | - if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
| 3252 | - $segment_position++; |
|
| 3253 | - |
|
| 3254 | - $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
|
| 3255 | - $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
|
| 3256 | - |
|
| 3257 | - return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
| 3258 | - } |
|
| 3259 | - |
|
| 3260 | - protected function get_method_hash() |
|
| 3261 | - { |
|
| 3262 | - $ci = &get_instance(); |
|
| 3263 | - |
|
| 3264 | - $state_info = $this->get_state_info_from_url(); |
|
| 3265 | - $extra_values = $ci->uri->segment($state_info->segment_position - 1) != $this->get_method_name() ? $ci->uri->segment($state_info->segment_position - 1) : ''; |
|
| 3266 | - |
|
| 3267 | - return $this->crud_url_path !== null |
|
| 3268 | - ? md5($this->crud_url_path) |
|
| 3269 | - : md5($this->get_controller_name().$this->get_method_name().$extra_values); |
|
| 3270 | - } |
|
| 3271 | - |
|
| 3272 | - protected function get_method_name() |
|
| 3273 | - { |
|
| 3274 | - $ci = &get_instance(); |
|
| 3275 | - return $ci->router->method; |
|
| 3276 | - } |
|
| 3277 | - |
|
| 3278 | - protected function get_controller_name() |
|
| 3279 | - { |
|
| 3280 | - $ci = &get_instance(); |
|
| 3281 | - return $ci->router->class; |
|
| 3282 | - } |
|
| 3283 | - |
|
| 3284 | - public function getState() |
|
| 3285 | - { |
|
| 3286 | - return $this->states[$this->getStateCode()]; |
|
| 3287 | - } |
|
| 3288 | - |
|
| 3289 | - protected function getListUrl() |
|
| 3290 | - { |
|
| 3291 | - return $this->state_url('',true); |
|
| 3292 | - } |
|
| 3293 | - |
|
| 3294 | - protected function getAjaxListUrl() |
|
| 3295 | - { |
|
| 3296 | - return $this->state_url('ajax_list'); |
|
| 3297 | - } |
|
| 3298 | - |
|
| 3299 | - protected function getExportToExcelUrl() |
|
| 3300 | - { |
|
| 3301 | - return $this->state_url('export'); |
|
| 3302 | - } |
|
| 3303 | - |
|
| 3304 | - protected function getPrintUrl() |
|
| 3305 | - { |
|
| 3306 | - return $this->state_url('print'); |
|
| 3307 | - } |
|
| 3308 | - |
|
| 3309 | - protected function getAjaxListInfoUrl() |
|
| 3310 | - { |
|
| 3311 | - return $this->state_url('ajax_list_info'); |
|
| 3312 | - } |
|
| 3313 | - |
|
| 3314 | - protected function getAddUrl() |
|
| 3315 | - { |
|
| 3316 | - return $this->state_url('add'); |
|
| 3317 | - } |
|
| 3318 | - |
|
| 3319 | - protected function getInsertUrl() |
|
| 3320 | - { |
|
| 3321 | - return $this->state_url('insert'); |
|
| 3322 | - } |
|
| 3323 | - |
|
| 3324 | - protected function getValidationInsertUrl() |
|
| 3325 | - { |
|
| 3326 | - return $this->state_url('insert_validation'); |
|
| 3327 | - } |
|
| 3328 | - |
|
| 3329 | - protected function getValidationUpdateUrl($primary_key = null) |
|
| 3330 | - { |
|
| 3331 | - if($primary_key === null) |
|
| 3332 | - return $this->state_url('update_validation'); |
|
| 3333 | - else |
|
| 3334 | - return $this->state_url('update_validation/'.$primary_key); |
|
| 3335 | - } |
|
| 3336 | - |
|
| 3337 | - protected function getEditUrl($primary_key = null) |
|
| 3338 | - { |
|
| 3339 | - if($primary_key === null) |
|
| 3340 | - return $this->state_url('edit'); |
|
| 3341 | - else |
|
| 3342 | - return $this->state_url('edit/'.$primary_key); |
|
| 3343 | - } |
|
| 3344 | - |
|
| 3345 | - protected function getReadUrl($primary_key = null) |
|
| 3346 | - { |
|
| 3347 | - if($primary_key === null) |
|
| 3348 | - return $this->state_url('read'); |
|
| 3349 | - else |
|
| 3350 | - return $this->state_url('read/'.$primary_key); |
|
| 3351 | - } |
|
| 3352 | - |
|
| 3353 | - protected function getUpdateUrl($state_info) |
|
| 3354 | - { |
|
| 3355 | - return $this->state_url('update/'.$state_info->primary_key); |
|
| 3356 | - } |
|
| 3357 | - |
|
| 3358 | - protected function getDeleteUrl($state_info = null) |
|
| 3359 | - { |
|
| 3360 | - if (empty($state_info)) { |
|
| 3361 | - return $this->state_url('delete'); |
|
| 3362 | - } else { |
|
| 3363 | - return $this->state_url('delete/'.$state_info->primary_key); |
|
| 4315 | + public function order_by($order_by, $direction = 'asc') |
|
| 4316 | + { |
|
| 4317 | + $this->order_by = array($order_by,$direction); |
|
| 4318 | + |
|
| 4319 | + return $this; |
|
| 4320 | + } |
|
| 4321 | + |
|
| 4322 | + public function where($key, $value = NULL, $escape = TRUE) |
|
| 4323 | + { |
|
| 4324 | + $this->where[] = array($key,$value,$escape); |
|
| 4325 | + |
|
| 4326 | + return $this; |
|
| 4327 | + } |
|
| 4328 | + |
|
| 4329 | + public function or_where($key, $value = NULL, $escape = TRUE) |
|
| 4330 | + { |
|
| 4331 | + $this->or_where[] = array($key,$value,$escape); |
|
| 4332 | + |
|
| 4333 | + return $this; |
|
| 4334 | + } |
|
| 4335 | + |
|
| 4336 | + public function like($field, $match = '', $side = 'both') |
|
| 4337 | + { |
|
| 4338 | + $this->like[] = array($field, $match, $side); |
|
| 4339 | + |
|
| 4340 | + return $this; |
|
| 4341 | + } |
|
| 4342 | + |
|
| 4343 | + protected function having($key, $value = '', $escape = TRUE) |
|
| 4344 | + { |
|
| 4345 | + $this->having[] = array($key, $value, $escape); |
|
| 4346 | + |
|
| 4347 | + return $this; |
|
| 4348 | + } |
|
| 4349 | + |
|
| 4350 | + protected function or_having($key, $value = '', $escape = TRUE) |
|
| 4351 | + { |
|
| 4352 | + $this->or_having[] = array($key, $value, $escape); |
|
| 4353 | + |
|
| 4354 | + return $this; |
|
| 4355 | + } |
|
| 4356 | + |
|
| 4357 | + public function or_like($field, $match = '', $side = 'both') |
|
| 4358 | + { |
|
| 4359 | + $this->or_like[] = array($field, $match, $side); |
|
| 4360 | + |
|
| 4361 | + return $this; |
|
| 4362 | + } |
|
| 4363 | + |
|
| 4364 | + public function limit($limit, $offset = '') |
|
| 4365 | + { |
|
| 4366 | + $this->limit = array($limit,$offset); |
|
| 4367 | + |
|
| 4368 | + return $this; |
|
| 4369 | + } |
|
| 4370 | + |
|
| 4371 | + protected function _initialize_helpers() |
|
| 4372 | + { |
|
| 4373 | + $ci = &get_instance(); |
|
| 4374 | + |
|
| 4375 | + $ci->load->helper('url'); |
|
| 4376 | + $ci->load->helper('form'); |
|
| 4377 | + } |
|
| 4378 | + |
|
| 4379 | + protected function _initialize_variables() |
|
| 4380 | + { |
|
| 4381 | + $ci = &get_instance(); |
|
| 4382 | + $ci->load->config('grocery_crud'); |
|
| 4383 | + |
|
| 4384 | + $this->config = (object)array(); |
|
| 4385 | + |
|
| 4386 | + /** Initialize all the config variables into this object */ |
|
| 4387 | + $this->config->default_language = $ci->config->item('grocery_crud_default_language'); |
|
| 4388 | + $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
| 4389 | + $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); |
|
| 4390 | + $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
| 4391 | + $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
| 4392 | + $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
| 4393 | + $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); |
|
| 4394 | + $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); |
|
| 4395 | + $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
| 4396 | + $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
| 4397 | + $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); |
|
| 4398 | + $this->config->environment = $ci->config->item('grocery_crud_environment'); |
|
| 4399 | + |
|
| 4400 | + /** Initialize default paths */ |
|
| 4401 | + $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
| 4402 | + $this->default_css_path = $this->default_assets_path.'/css'; |
|
| 4403 | + $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
| 4404 | + $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
| 4405 | + |
|
| 4406 | + $this->character_limiter = $this->config->character_limiter; |
|
| 4407 | + |
|
| 4408 | + if ($this->character_limiter === 0 || $this->character_limiter === '0') { |
|
| 4409 | + $this->character_limiter = 1000000; //a very big number |
|
| 4410 | + } elseif($this->character_limiter === null || $this->character_limiter === false) { |
|
| 4411 | + $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value |
|
| 4412 | + } |
|
| 4413 | + |
|
| 4414 | + if ($this->theme === null && !empty($this->config->default_theme)) { |
|
| 4415 | + $this->set_theme($this->config->default_theme); |
|
| 3364 | 4416 | } |
| 3365 | - } |
|
| 4417 | + } |
|
| 3366 | 4418 | |
| 3367 | - protected function getDeleteMultipleUrl() |
|
| 4419 | + protected function _set_primary_keys_to_model() |
|
| 3368 | 4420 | { |
| 3369 | - return $this->state_url('delete_multiple'); |
|
| 4421 | + if(!empty($this->primary_keys)) |
|
| 4422 | + { |
|
| 4423 | + foreach($this->primary_keys as $primary_key) |
|
| 4424 | + { |
|
| 4425 | + $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); |
|
| 4426 | + } |
|
| 4427 | + } |
|
| 3370 | 4428 | } |
| 3371 | 4429 | |
| 3372 | - protected function getListSuccessUrl($primary_key = null) |
|
| 3373 | - { |
|
| 3374 | - if(empty($primary_key)) |
|
| 3375 | - return $this->state_url('success',true); |
|
| 3376 | - else |
|
| 3377 | - return $this->state_url('success/'.$primary_key,true); |
|
| 3378 | - } |
|
| 3379 | - |
|
| 3380 | - protected function getUploadUrl($field_name) |
|
| 3381 | - { |
|
| 3382 | - return $this->state_url('upload_file/'.$field_name); |
|
| 3383 | - } |
|
| 3384 | - |
|
| 3385 | - protected function getFileDeleteUrl($field_name) |
|
| 3386 | - { |
|
| 3387 | - return $this->state_url('delete_file/'.$field_name); |
|
| 3388 | - } |
|
| 3389 | - |
|
| 3390 | - protected function getAjaxRelationUrl() |
|
| 3391 | - { |
|
| 3392 | - return $this->state_url('ajax_relation'); |
|
| 3393 | - } |
|
| 3394 | - |
|
| 3395 | - protected function getAjaxRelationManytoManyUrl() |
|
| 3396 | - { |
|
| 3397 | - return $this->state_url('ajax_relation_n_n'); |
|
| 3398 | - } |
|
| 3399 | -} |
|
| 3400 | - |
|
| 4430 | + /** |
|
| 4431 | + * Initialize all the required libraries and variables before rendering |
|
| 4432 | + */ |
|
| 4433 | + protected function pre_render() |
|
| 4434 | + { |
|
| 4435 | + $this->_initialize_variables(); |
|
| 4436 | + $this->_initialize_helpers(); |
|
| 4437 | + $this->_load_language(); |
|
| 4438 | + $this->state_code = $this->getStateCode(); |
|
| 3401 | 4439 | |
| 3402 | -/** |
|
| 3403 | - * PHP grocery CRUD |
|
| 3404 | - * |
|
| 3405 | - * LICENSE |
|
| 3406 | - * |
|
| 3407 | - * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt). |
|
| 3408 | - * You don't have to do anything special to choose one license or the other and you don't have to notify anyone which license you are using. |
|
| 3409 | - * Please see the corresponding license file for details of these licenses. |
|
| 3410 | - * You are free to use, modify and distribute this software, but all copyright information must remain. |
|
| 3411 | - * |
|
| 3412 | - * @package grocery CRUD |
|
| 3413 | - * @copyright Copyright (c) 2010 through 2014, John Skoumbourdis |
|
| 3414 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 3415 | - * @version 1.5.6 |
|
| 3416 | - * @author John Skoumbourdis <[email protected]> |
|
| 3417 | - */ |
|
| 4440 | + if($this->basic_model === null) |
|
| 4441 | + $this->set_default_Model(); |
|
| 3418 | 4442 | |
| 3419 | -// ------------------------------------------------------------------------ |
|
| 4443 | + $this->set_basic_db_table($this->get_table()); |
|
| 3420 | 4444 | |
| 3421 | -/** |
|
| 3422 | - * PHP grocery CRUD |
|
| 3423 | - * |
|
| 3424 | - * Creates a full functional CRUD with few lines of code. |
|
| 3425 | - * |
|
| 3426 | - * @package grocery CRUD |
|
| 3427 | - * @author John Skoumbourdis <[email protected]> |
|
| 3428 | - * @license https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt |
|
| 3429 | - * @link http://www.grocerycrud.com/documentation |
|
| 3430 | - */ |
|
| 3431 | -class Grocery_CRUD extends grocery_CRUD_States |
|
| 3432 | -{ |
|
| 3433 | - /** |
|
| 3434 | - * Grocery CRUD version |
|
| 3435 | - * |
|
| 3436 | - * @var string |
|
| 3437 | - */ |
|
| 3438 | - const VERSION = "1.5.6"; |
|
| 3439 | - |
|
| 3440 | - const JQUERY = "jquery-1.11.1.min.js"; |
|
| 3441 | - const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
| 3442 | - const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
| 3443 | - |
|
| 3444 | - protected $state_code = null; |
|
| 3445 | - protected $state_info = null; |
|
| 3446 | - protected $columns = null; |
|
| 3447 | - |
|
| 3448 | - private $basic_db_table_checked = false; |
|
| 3449 | - private $columns_checked = false; |
|
| 3450 | - private $add_fields_checked = false; |
|
| 3451 | - private $edit_fields_checked = false; |
|
| 3452 | - private $read_fields_checked = false; |
|
| 3453 | - |
|
| 3454 | - protected $default_theme = 'flexigrid'; |
|
| 3455 | - protected $language = null; |
|
| 3456 | - protected $lang_strings = array(); |
|
| 3457 | - protected $php_date_format = null; |
|
| 3458 | - protected $js_date_format = null; |
|
| 3459 | - protected $ui_date_format = null; |
|
| 3460 | - protected $character_limiter = null; |
|
| 3461 | - protected $config = null; |
|
| 3462 | - |
|
| 3463 | - protected $add_fields = null; |
|
| 3464 | - protected $edit_fields = null; |
|
| 3465 | - protected $read_fields = null; |
|
| 3466 | - protected $add_hidden_fields = array(); |
|
| 3467 | - protected $edit_hidden_fields = array(); |
|
| 3468 | - protected $field_types = null; |
|
| 3469 | - protected $basic_db_table = null; |
|
| 3470 | - protected $theme_config = array(); |
|
| 3471 | - protected $subject = null; |
|
| 3472 | - protected $subject_plural = null; |
|
| 3473 | - protected $display_as = array(); |
|
| 3474 | - protected $order_by = null; |
|
| 3475 | - protected $where = array(); |
|
| 3476 | - protected $like = array(); |
|
| 3477 | - protected $having = array(); |
|
| 3478 | - protected $or_having = array(); |
|
| 3479 | - protected $limit = null; |
|
| 3480 | - protected $required_fields = array(); |
|
| 3481 | - protected $_unique_fields = array(); |
|
| 3482 | - protected $validation_rules = array(); |
|
| 3483 | - protected $relation = array(); |
|
| 3484 | - protected $relation_n_n = array(); |
|
| 3485 | - protected $upload_fields = array(); |
|
| 3486 | - protected $actions = array(); |
|
| 3487 | - |
|
| 3488 | - protected $form_validation = null; |
|
| 3489 | - protected $change_field_type = null; |
|
| 3490 | - protected $primary_keys = array(); |
|
| 3491 | - protected $crud_url_path = null; |
|
| 3492 | - protected $list_url_path = null; |
|
| 3493 | - |
|
| 3494 | - /* The unsetters */ |
|
| 3495 | - protected $unset_texteditor = array(); |
|
| 3496 | - protected $unset_add = false; |
|
| 3497 | - protected $unset_edit = false; |
|
| 3498 | - protected $unset_delete = false; |
|
| 3499 | - protected $unset_read = false; |
|
| 3500 | - protected $unset_jquery = false; |
|
| 3501 | - protected $unset_jquery_ui = false; |
|
| 3502 | - protected $unset_bootstrap = false; |
|
| 3503 | - protected $unset_list = false; |
|
| 3504 | - protected $unset_export = false; |
|
| 3505 | - protected $unset_print = false; |
|
| 3506 | - protected $unset_back_to_list = false; |
|
| 3507 | - protected $unset_columns = null; |
|
| 3508 | - protected $unset_add_fields = null; |
|
| 3509 | - protected $unset_edit_fields = null; |
|
| 3510 | - protected $unset_read_fields = null; |
|
| 3511 | - |
|
| 3512 | - /* Callbacks */ |
|
| 3513 | - protected $callback_before_insert = null; |
|
| 3514 | - protected $callback_after_insert = null; |
|
| 3515 | - protected $callback_insert = null; |
|
| 3516 | - protected $callback_before_update = null; |
|
| 3517 | - protected $callback_after_update = null; |
|
| 3518 | - protected $callback_update = null; |
|
| 3519 | - protected $callback_before_delete = null; |
|
| 3520 | - protected $callback_after_delete = null; |
|
| 3521 | - protected $callback_delete = null; |
|
| 3522 | - protected $callback_column = array(); |
|
| 3523 | - protected $callback_add_field = array(); |
|
| 3524 | - protected $callback_edit_field = array(); |
|
| 3525 | - protected $callback_upload = null; |
|
| 3526 | - protected $callback_before_upload = null; |
|
| 3527 | - protected $callback_after_upload = null; |
|
| 3528 | - |
|
| 3529 | - protected $default_javascript_path = null; //autogenerate, please do not modify |
|
| 3530 | - protected $default_css_path = null; //autogenerate, please do not modify |
|
| 3531 | - protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
| 3532 | - protected $default_theme_path = null; //autogenerate, please do not modify |
|
| 3533 | - protected $default_language_path = 'assets/grocery_crud/languages'; |
|
| 3534 | - protected $default_config_path = 'assets/grocery_crud/config'; |
|
| 3535 | - protected $default_assets_path = 'assets/grocery_crud'; |
|
| 3536 | - |
|
| 3537 | - /** |
|
| 3538 | - * |
|
| 3539 | - * Constructor |
|
| 3540 | - * |
|
| 3541 | - * @access public |
|
| 3542 | - */ |
|
| 3543 | - public function __construct() |
|
| 3544 | - { |
|
| 3545 | - |
|
| 3546 | - } |
|
| 3547 | - |
|
| 3548 | - /** |
|
| 3549 | - * The displayed columns that user see |
|
| 3550 | - * |
|
| 3551 | - * @access public |
|
| 3552 | - * @param string |
|
| 3553 | - * @param array |
|
| 3554 | - * @return void |
|
| 3555 | - */ |
|
| 3556 | - public function columns() |
|
| 3557 | - { |
|
| 3558 | - $args = func_get_args(); |
|
| 3559 | - |
|
| 3560 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3561 | - { |
|
| 3562 | - $args = $args[0]; |
|
| 3563 | - } |
|
| 3564 | - |
|
| 3565 | - $this->columns = $args; |
|
| 3566 | - |
|
| 3567 | - return $this; |
|
| 3568 | - } |
|
| 3569 | - |
|
| 3570 | - |
|
| 3571 | - /** |
|
| 3572 | - * Set Validation Rules |
|
| 3573 | - * |
|
| 3574 | - * Important note: If the $field is an array then no automated crud fields will take apart |
|
| 3575 | - * |
|
| 3576 | - * @access public |
|
| 3577 | - * @param mixed |
|
| 3578 | - * @param string |
|
| 3579 | - * @return void |
|
| 3580 | - */ |
|
| 3581 | - function set_rules($field, $label = '', $rules = '') |
|
| 3582 | - { |
|
| 3583 | - if(is_string($field)) |
|
| 3584 | - { |
|
| 3585 | - $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
|
| 3586 | - }elseif(is_array($field)) |
|
| 3587 | - { |
|
| 3588 | - foreach($field as $num_field => $field_array) |
|
| 3589 | - { |
|
| 3590 | - $this->validation_rules[$field_array['field']] = $field_array; |
|
| 3591 | - } |
|
| 3592 | - } |
|
| 3593 | - return $this; |
|
| 3594 | - } |
|
| 3595 | - |
|
| 3596 | - /** |
|
| 3597 | - * |
|
| 3598 | - * Changes the default field type |
|
| 3599 | - * @param string $field |
|
| 3600 | - * @param string $type |
|
| 3601 | - * @param array|string $extras |
|
| 3602 | - */ |
|
| 3603 | - public function change_field_type($field , $type, $extras = null) |
|
| 3604 | - { |
|
| 3605 | - $field_type = (object)array('type' => $type); |
|
| 3606 | - |
|
| 3607 | - $field_type->extras = $extras; |
|
| 3608 | - |
|
| 3609 | - $this->change_field_type[$field] = $field_type; |
|
| 3610 | - |
|
| 3611 | - return $this; |
|
| 3612 | - } |
|
| 3613 | - |
|
| 3614 | - /** |
|
| 3615 | - * |
|
| 3616 | - * Just an alias to the change_field_type method |
|
| 3617 | - * @param string $field |
|
| 3618 | - * @param string $type |
|
| 3619 | - * @param array|string $extras |
|
| 3620 | - */ |
|
| 3621 | - public function field_type($field , $type, $extras = null) |
|
| 3622 | - { |
|
| 3623 | - return $this->change_field_type($field , $type, $extras); |
|
| 3624 | - } |
|
| 3625 | - |
|
| 3626 | - /** |
|
| 3627 | - * Change the default primary key for a specific table. |
|
| 3628 | - * If the $table_name is NULL then the primary key is for the default table name that we added at the set_table method |
|
| 3629 | - * |
|
| 3630 | - * @param string $primary_key_field |
|
| 3631 | - * @param string $table_name |
|
| 3632 | - */ |
|
| 3633 | - public function set_primary_key($primary_key_field, $table_name = null) |
|
| 3634 | - { |
|
| 3635 | - $this->primary_keys[] = array('field_name' => $primary_key_field, 'table_name' => $table_name); |
|
| 3636 | - |
|
| 3637 | - return $this; |
|
| 3638 | - } |
|
| 3639 | - |
|
| 3640 | - /** |
|
| 3641 | - * Unsets the texteditor of the selected fields |
|
| 3642 | - * |
|
| 3643 | - * @access public |
|
| 3644 | - * @param string |
|
| 3645 | - * @param array |
|
| 3646 | - * @return void |
|
| 3647 | - */ |
|
| 3648 | - public function unset_texteditor() |
|
| 3649 | - { |
|
| 3650 | - $args = func_get_args(); |
|
| 3651 | - |
|
| 3652 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3653 | - { |
|
| 3654 | - $args = $args[0]; |
|
| 3655 | - } |
|
| 3656 | - foreach($args as $arg) |
|
| 3657 | - { |
|
| 3658 | - $this->unset_texteditor[] = $arg; |
|
| 3659 | - } |
|
| 3660 | - |
|
| 3661 | - return $this; |
|
| 3662 | - } |
|
| 3663 | - |
|
| 3664 | - /** |
|
| 3665 | - * Unsets just the jquery library from the js. This function can be used if there is already a jquery included |
|
| 3666 | - * in the main template. This will avoid all jquery conflicts. |
|
| 3667 | - * |
|
| 3668 | - * @return void |
|
| 3669 | - */ |
|
| 3670 | - public function unset_jquery() |
|
| 3671 | - { |
|
| 3672 | - $this->unset_jquery = true; |
|
| 3673 | - |
|
| 3674 | - return $this; |
|
| 3675 | - } |
|
| 3676 | - |
|
| 3677 | - /** |
|
| 3678 | - * Unsets the jquery UI Javascript and CSS. This function is really useful |
|
| 3679 | - * when the jquery UI JavaScript and CSS are already included in the main template. |
|
| 3680 | - * This will avoid all jquery UI conflicts. |
|
| 3681 | - * |
|
| 3682 | - * @return void |
|
| 3683 | - */ |
|
| 3684 | - public function unset_jquery_ui() |
|
| 3685 | - { |
|
| 3686 | - $this->unset_jquery_ui = true; |
|
| 3687 | - |
|
| 3688 | - return $this; |
|
| 3689 | - } |
|
| 3690 | - |
|
| 3691 | - /** |
|
| 3692 | - * Unsets just the twitter bootstrap libraries from the js and css. This function can be used if there is already twitter bootstrap files included |
|
| 3693 | - * in the main template. If you are already using a bootstrap template then it's not necessary to load the files again. |
|
| 3694 | - * |
|
| 3695 | - * @return void |
|
| 3696 | - */ |
|
| 3697 | - public function unset_bootstrap() |
|
| 3698 | - { |
|
| 3699 | - $this->unset_bootstrap = true; |
|
| 3700 | - |
|
| 3701 | - return $this; |
|
| 3702 | - } |
|
| 3703 | - |
|
| 3704 | - /** |
|
| 3705 | - * Unsets the add operation from the list |
|
| 3706 | - * |
|
| 3707 | - * @return void |
|
| 3708 | - */ |
|
| 3709 | - public function unset_add() |
|
| 3710 | - { |
|
| 3711 | - $this->unset_add = true; |
|
| 3712 | - |
|
| 3713 | - return $this; |
|
| 3714 | - } |
|
| 3715 | - |
|
| 3716 | - /** |
|
| 3717 | - * Unsets the edit operation from the list |
|
| 3718 | - * |
|
| 3719 | - * @return void |
|
| 3720 | - */ |
|
| 3721 | - public function unset_edit() |
|
| 3722 | - { |
|
| 3723 | - $this->unset_edit = true; |
|
| 3724 | - |
|
| 3725 | - return $this; |
|
| 3726 | - } |
|
| 3727 | - |
|
| 3728 | - /** |
|
| 3729 | - * Unsets the delete operation from the list |
|
| 3730 | - * |
|
| 3731 | - * @return void |
|
| 3732 | - */ |
|
| 3733 | - public function unset_delete() |
|
| 3734 | - { |
|
| 3735 | - $this->unset_delete = true; |
|
| 3736 | - |
|
| 3737 | - return $this; |
|
| 3738 | - } |
|
| 3739 | - |
|
| 3740 | - /** |
|
| 3741 | - * Unsets the read operation from the list |
|
| 3742 | - * |
|
| 3743 | - * @return void |
|
| 3744 | - */ |
|
| 3745 | - public function unset_read() |
|
| 3746 | - { |
|
| 3747 | - $this->unset_read = true; |
|
| 3748 | - |
|
| 3749 | - return $this; |
|
| 3750 | - } |
|
| 3751 | - |
|
| 3752 | - /** |
|
| 3753 | - * Just an alias to unset_read |
|
| 3754 | - * |
|
| 3755 | - * @return void |
|
| 3756 | - * */ |
|
| 3757 | - public function unset_view() |
|
| 3758 | - { |
|
| 3759 | - return unset_read(); |
|
| 3760 | - } |
|
| 3761 | - |
|
| 3762 | - /** |
|
| 3763 | - * Unsets the export button and functionality from the list |
|
| 3764 | - * |
|
| 3765 | - * @return void |
|
| 3766 | - */ |
|
| 3767 | - public function unset_export() |
|
| 3768 | - { |
|
| 3769 | - $this->unset_export = true; |
|
| 3770 | - |
|
| 3771 | - return $this; |
|
| 3772 | - } |
|
| 3773 | - |
|
| 3774 | - |
|
| 3775 | - /** |
|
| 3776 | - * Unsets the print button and functionality from the list |
|
| 3777 | - * |
|
| 3778 | - * @return void |
|
| 3779 | - */ |
|
| 3780 | - public function unset_print() |
|
| 3781 | - { |
|
| 3782 | - $this->unset_print = true; |
|
| 3783 | - |
|
| 3784 | - return $this; |
|
| 3785 | - } |
|
| 3786 | - |
|
| 3787 | - /** |
|
| 3788 | - * Unsets all the operations from the list |
|
| 3789 | - * |
|
| 3790 | - * @return void |
|
| 3791 | - */ |
|
| 3792 | - public function unset_operations() |
|
| 3793 | - { |
|
| 3794 | - $this->unset_add = true; |
|
| 3795 | - $this->unset_edit = true; |
|
| 3796 | - $this->unset_delete = true; |
|
| 3797 | - $this->unset_read = true; |
|
| 3798 | - $this->unset_export = true; |
|
| 3799 | - $this->unset_print = true; |
|
| 3800 | - |
|
| 3801 | - return $this; |
|
| 3802 | - } |
|
| 3803 | - |
|
| 3804 | - /** |
|
| 3805 | - * Unsets a column from the list |
|
| 3806 | - * |
|
| 3807 | - * @return void. |
|
| 3808 | - */ |
|
| 3809 | - public function unset_columns() |
|
| 3810 | - { |
|
| 3811 | - $args = func_get_args(); |
|
| 3812 | - |
|
| 3813 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3814 | - { |
|
| 3815 | - $args = $args[0]; |
|
| 3816 | - } |
|
| 3817 | - |
|
| 3818 | - $this->unset_columns = $args; |
|
| 3819 | - |
|
| 3820 | - return $this; |
|
| 3821 | - } |
|
| 3822 | - |
|
| 3823 | - public function unset_list() |
|
| 3824 | - { |
|
| 3825 | - $this->unset_list = true; |
|
| 3826 | - |
|
| 3827 | - return $this; |
|
| 3828 | - } |
|
| 3829 | - |
|
| 3830 | - public function unset_fields() |
|
| 3831 | - { |
|
| 3832 | - $args = func_get_args(); |
|
| 3833 | - |
|
| 3834 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3835 | - { |
|
| 3836 | - $args = $args[0]; |
|
| 3837 | - } |
|
| 3838 | - |
|
| 3839 | - $this->unset_add_fields = $args; |
|
| 3840 | - $this->unset_edit_fields = $args; |
|
| 3841 | - $this->unset_read_fields = $args; |
|
| 3842 | - |
|
| 3843 | - return $this; |
|
| 3844 | - } |
|
| 3845 | - |
|
| 3846 | - public function unset_add_fields() |
|
| 3847 | - { |
|
| 3848 | - $args = func_get_args(); |
|
| 3849 | - |
|
| 3850 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3851 | - { |
|
| 3852 | - $args = $args[0]; |
|
| 3853 | - } |
|
| 3854 | - |
|
| 3855 | - $this->unset_add_fields = $args; |
|
| 3856 | - |
|
| 3857 | - return $this; |
|
| 3858 | - } |
|
| 3859 | - |
|
| 3860 | - public function unset_edit_fields() |
|
| 3861 | - { |
|
| 3862 | - $args = func_get_args(); |
|
| 3863 | - |
|
| 3864 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3865 | - { |
|
| 3866 | - $args = $args[0]; |
|
| 3867 | - } |
|
| 3868 | - |
|
| 3869 | - $this->unset_edit_fields = $args; |
|
| 3870 | - |
|
| 3871 | - return $this; |
|
| 3872 | - } |
|
| 3873 | - |
|
| 3874 | - public function unset_read_fields() |
|
| 3875 | - { |
|
| 3876 | - $args = func_get_args(); |
|
| 3877 | - |
|
| 3878 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3879 | - { |
|
| 3880 | - $args = $args[0]; |
|
| 3881 | - } |
|
| 3882 | - |
|
| 3883 | - $this->unset_read_fields = $args; |
|
| 3884 | - |
|
| 3885 | - return $this; |
|
| 3886 | - } |
|
| 3887 | - |
|
| 3888 | - |
|
| 3889 | - /** |
|
| 3890 | - * Unsets everything that has to do with buttons or links with go back to list message |
|
| 3891 | - * @access public |
|
| 3892 | - * @return void |
|
| 3893 | - */ |
|
| 3894 | - public function unset_back_to_list() |
|
| 3895 | - { |
|
| 3896 | - $this->unset_back_to_list = true; |
|
| 3897 | - |
|
| 3898 | - return $this; |
|
| 3899 | - } |
|
| 3900 | - |
|
| 3901 | - /** |
|
| 3902 | - * |
|
| 3903 | - * The fields that user will see on add/edit |
|
| 3904 | - * |
|
| 3905 | - * @access public |
|
| 3906 | - * @param string |
|
| 3907 | - * @param array |
|
| 3908 | - * @return void |
|
| 3909 | - */ |
|
| 3910 | - public function fields() |
|
| 3911 | - { |
|
| 3912 | - $args = func_get_args(); |
|
| 3913 | - |
|
| 3914 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3915 | - { |
|
| 3916 | - $args = $args[0]; |
|
| 3917 | - } |
|
| 3918 | - |
|
| 3919 | - $this->add_fields = $args; |
|
| 3920 | - $this->edit_fields = $args; |
|
| 3921 | - |
|
| 3922 | - return $this; |
|
| 3923 | - } |
|
| 3924 | - |
|
| 3925 | - /** |
|
| 3926 | - * |
|
| 3927 | - * The fields that user can see . It is only for the add form |
|
| 3928 | - */ |
|
| 3929 | - public function add_fields() |
|
| 3930 | - { |
|
| 3931 | - $args = func_get_args(); |
|
| 3932 | - |
|
| 3933 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3934 | - { |
|
| 3935 | - $args = $args[0]; |
|
| 3936 | - } |
|
| 3937 | - |
|
| 3938 | - $this->add_fields = $args; |
|
| 3939 | - |
|
| 3940 | - return $this; |
|
| 3941 | - } |
|
| 3942 | - |
|
| 3943 | - /** |
|
| 3944 | - * |
|
| 3945 | - * The fields that user can see . It is only for the edit form |
|
| 3946 | - */ |
|
| 3947 | - public function edit_fields() |
|
| 3948 | - { |
|
| 3949 | - $args = func_get_args(); |
|
| 3950 | - |
|
| 3951 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3952 | - { |
|
| 3953 | - $args = $args[0]; |
|
| 3954 | - } |
|
| 3955 | - |
|
| 3956 | - $this->edit_fields = $args; |
|
| 3957 | - |
|
| 3958 | - return $this; |
|
| 3959 | - } |
|
| 3960 | - |
|
| 3961 | - public function set_read_fields() |
|
| 3962 | - { |
|
| 3963 | - $args = func_get_args(); |
|
| 3964 | - |
|
| 3965 | - if(isset($args[0]) && is_array($args[0])) { |
|
| 3966 | - $args = $args[0]; |
|
| 3967 | - } |
|
| 3968 | - |
|
| 3969 | - $this->read_fields = $args; |
|
| 3970 | - |
|
| 3971 | - return $this; |
|
| 3972 | - } |
|
| 3973 | - |
|
| 3974 | - /** |
|
| 3975 | - * |
|
| 3976 | - * Changes the displaying label of the field |
|
| 3977 | - * @param $field_name |
|
| 3978 | - * @param $display_as |
|
| 3979 | - * @return void |
|
| 3980 | - */ |
|
| 3981 | - public function display_as($field_name, $display_as = null) |
|
| 3982 | - { |
|
| 3983 | - if(is_array($field_name)) |
|
| 3984 | - { |
|
| 3985 | - foreach($field_name as $field => $display_as) |
|
| 3986 | - { |
|
| 3987 | - $this->display_as[$field] = $display_as; |
|
| 3988 | - } |
|
| 3989 | - } |
|
| 3990 | - elseif($display_as !== null) |
|
| 3991 | - { |
|
| 3992 | - $this->display_as[$field_name] = $display_as; |
|
| 3993 | - } |
|
| 3994 | - return $this; |
|
| 3995 | - } |
|
| 3996 | - |
|
| 3997 | - /** |
|
| 3998 | - * |
|
| 3999 | - * Load the language strings array from the language file |
|
| 4000 | - */ |
|
| 4001 | - protected function _load_language() |
|
| 4002 | - { |
|
| 4003 | - if($this->language === null) |
|
| 4004 | - { |
|
| 4005 | - $this->language = strtolower($this->config->default_language); |
|
| 4006 | - } |
|
| 4007 | - include($this->default_language_path.'/'.$this->language.'.php'); |
|
| 4008 | - |
|
| 4009 | - foreach($lang as $handle => $lang_string) |
|
| 4010 | - if(!isset($this->lang_strings[$handle])) |
|
| 4011 | - $this->lang_strings[$handle] = $lang_string; |
|
| 4012 | - |
|
| 4013 | - $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
|
| 4014 | - $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
|
| 4015 | - |
|
| 4016 | - } |
|
| 4017 | - |
|
| 4018 | - protected function _load_date_format() |
|
| 4019 | - { |
|
| 4020 | - list($php_day, $php_month, $php_year) = array('d','m','Y'); |
|
| 4021 | - list($js_day, $js_month, $js_year) = array('dd','mm','yy'); |
|
| 4022 | - list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); |
|
| 4023 | - |
|
| 4024 | - $date_format = $this->config->date_format; |
|
| 4025 | - switch ($date_format) { |
|
| 4026 | - case 'uk-date': |
|
| 4027 | - $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
| 4028 | - $this->js_date_format = "$js_day/$js_month/$js_year"; |
|
| 4029 | - $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; |
|
| 4030 | - break; |
|
| 4445 | + $this->_load_date_format(); |
|
| 4031 | 4446 | |
| 4032 | - case 'us-date': |
|
| 4033 | - $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
| 4034 | - $this->js_date_format = "$js_month/$js_day/$js_year"; |
|
| 4035 | - $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; |
|
| 4036 | - break; |
|
| 4447 | + $this->_set_primary_keys_to_model(); |
|
| 4448 | + } |
|
| 4037 | 4449 | |
| 4038 | - case 'sql-date': |
|
| 4039 | - default: |
|
| 4040 | - $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
| 4041 | - $this->js_date_format = "$js_year-$js_month-$js_day"; |
|
| 4042 | - $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; |
|
| 4043 | - break; |
|
| 4044 | - } |
|
| 4045 | - } |
|
| 4046 | - |
|
| 4047 | - /** |
|
| 4048 | - * |
|
| 4049 | - * Set a language string directly |
|
| 4050 | - * @param string $handle |
|
| 4051 | - * @param string $string |
|
| 4052 | - */ |
|
| 4053 | - public function set_lang_string($handle, $lang_string){ |
|
| 4054 | - $this->lang_strings[$handle] = $lang_string; |
|
| 4055 | - |
|
| 4056 | - return $this; |
|
| 4057 | - } |
|
| 4058 | - |
|
| 4059 | - /** |
|
| 4060 | - * |
|
| 4061 | - * Just an alias to get_lang_string method |
|
| 4062 | - * @param string $handle |
|
| 4063 | - */ |
|
| 4064 | - public function l($handle) |
|
| 4065 | - { |
|
| 4066 | - return $this->get_lang_string($handle); |
|
| 4067 | - } |
|
| 4068 | - |
|
| 4069 | - /** |
|
| 4070 | - * |
|
| 4071 | - * Get the language string of the inserted string handle |
|
| 4072 | - * @param string $handle |
|
| 4073 | - */ |
|
| 4074 | - public function get_lang_string($handle) |
|
| 4075 | - { |
|
| 4076 | - return $this->lang_strings[$handle]; |
|
| 4077 | - } |
|
| 4078 | - |
|
| 4079 | - /** |
|
| 4080 | - * |
|
| 4081 | - * Simply set the language |
|
| 4082 | - * @example english |
|
| 4083 | - * @param string $language |
|
| 4084 | - */ |
|
| 4085 | - public function set_language($language) |
|
| 4086 | - { |
|
| 4087 | - $this->language = $language; |
|
| 4088 | - |
|
| 4089 | - return $this; |
|
| 4090 | - } |
|
| 4091 | - |
|
| 4092 | - /** |
|
| 4093 | - * |
|
| 4094 | - * Enter description here ... |
|
| 4095 | - */ |
|
| 4096 | - protected function get_columns() |
|
| 4097 | - { |
|
| 4098 | - if($this->columns_checked === false) |
|
| 4099 | - { |
|
| 4100 | - $field_types = $this->get_field_types(); |
|
| 4101 | - if(empty($this->columns)) |
|
| 4102 | - { |
|
| 4103 | - $this->columns = array(); |
|
| 4104 | - foreach($field_types as $field) |
|
| 4105 | - { |
|
| 4106 | - if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
| 4107 | - $this->columns[] = $field->name; |
|
| 4108 | - } |
|
| 4109 | - } |
|
| 4110 | - |
|
| 4111 | - foreach($this->columns as $col_num => $column) |
|
| 4112 | - { |
|
| 4113 | - |
|
| 4114 | - if(isset($this->relation[$column])) |
|
| 4115 | - { |
|
| 4116 | - |
|
| 4117 | - $new_column = $this->_unique_field_name($this->relation[$column][0]); |
|
| 4118 | - $this->columns[$col_num] = $new_column; |
|
| 4119 | - |
|
| 4120 | - if(isset($this->display_as[$column])) |
|
| 4121 | - { |
|
| 4122 | - $display_as = $this->display_as[$column]; |
|
| 4123 | - unset($this->display_as[$column]); |
|
| 4124 | - $this->display_as[$new_column] = $display_as; |
|
| 4125 | - } |
|
| 4126 | - else |
|
| 4127 | - { |
|
| 4128 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4129 | - } |
|
| 4130 | - |
|
| 4131 | - $column = $new_column; |
|
| 4132 | - $this->columns[$col_num] = $new_column; |
|
| 4133 | - } |
|
| 4134 | - else |
|
| 4135 | - { |
|
| 4136 | - if(!empty($this->relation)) |
|
| 4137 | - { |
|
| 4138 | - $table_name = $this->get_table(); |
|
| 4139 | - foreach($this->relation as $relation) |
|
| 4140 | - { |
|
| 4141 | - if( $relation[2] == $column ) |
|
| 4142 | - { |
|
| 4143 | - $new_column = $table_name.'.'.$column; |
|
| 4144 | - if(isset($this->display_as[$column])) |
|
| 4145 | - { |
|
| 4146 | - $display_as = $this->display_as[$column]; |
|
| 4147 | - unset($this->display_as[$column]); |
|
| 4148 | - $this->display_as[$new_column] = $display_as; |
|
| 4149 | - } |
|
| 4150 | - else |
|
| 4151 | - { |
|
| 4152 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4153 | - } |
|
| 4154 | - |
|
| 4155 | - $column = $new_column; |
|
| 4156 | - $this->columns[$col_num] = $new_column; |
|
| 4157 | - } |
|
| 4158 | - } |
|
| 4159 | - } |
|
| 4160 | - |
|
| 4161 | - } |
|
| 4162 | - |
|
| 4163 | - if(isset($this->display_as[$column])) |
|
| 4164 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4165 | - elseif(isset($field_types[$column])) |
|
| 4166 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4167 | - else |
|
| 4168 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
| 4169 | - ucfirst(str_replace('_',' ',$column))); |
|
| 4170 | - |
|
| 4171 | - if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
|
| 4172 | - { |
|
| 4173 | - unset($this->columns[$col_num]); |
|
| 4174 | - } |
|
| 4175 | - } |
|
| 4176 | - |
|
| 4177 | - $this->columns_checked = true; |
|
| 4178 | - |
|
| 4179 | - } |
|
| 4180 | - |
|
| 4181 | - return $this->columns; |
|
| 4182 | - } |
|
| 4183 | - |
|
| 4184 | - /** |
|
| 4185 | - * |
|
| 4186 | - * Enter description here ... |
|
| 4187 | - */ |
|
| 4188 | - protected function get_add_fields() |
|
| 4189 | - { |
|
| 4190 | - if($this->add_fields_checked === false) |
|
| 4191 | - { |
|
| 4192 | - $field_types = $this->get_field_types(); |
|
| 4193 | - if(!empty($this->add_fields)) |
|
| 4194 | - { |
|
| 4195 | - foreach($this->add_fields as $field_num => $field) |
|
| 4196 | - { |
|
| 4197 | - if(isset($this->display_as[$field])) |
|
| 4198 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4199 | - elseif(isset($field_types[$field]->display_as)) |
|
| 4200 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4201 | - else |
|
| 4202 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
| 4203 | - } |
|
| 4204 | - } |
|
| 4205 | - else |
|
| 4206 | - { |
|
| 4207 | - $this->add_fields = array(); |
|
| 4208 | - foreach($field_types as $field) |
|
| 4209 | - { |
|
| 4210 | - //Check if an unset_add_field is initialize for this field name |
|
| 4211 | - if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
| 4212 | - continue; |
|
| 4213 | - |
|
| 4214 | - if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
|
| 4215 | - { |
|
| 4216 | - if(isset($this->display_as[$field->name])) |
|
| 4217 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4218 | - else |
|
| 4219 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4220 | - } |
|
| 4221 | - } |
|
| 4222 | - } |
|
| 4223 | - |
|
| 4224 | - $this->add_fields_checked = true; |
|
| 4225 | - } |
|
| 4226 | - return $this->add_fields; |
|
| 4227 | - } |
|
| 4228 | - |
|
| 4229 | - /** |
|
| 4230 | - * |
|
| 4231 | - * Enter description here ... |
|
| 4232 | - */ |
|
| 4233 | - protected function get_edit_fields() |
|
| 4234 | - { |
|
| 4235 | - if($this->edit_fields_checked === false) |
|
| 4236 | - { |
|
| 4237 | - $field_types = $this->get_field_types(); |
|
| 4238 | - if(!empty($this->edit_fields)) |
|
| 4239 | - { |
|
| 4240 | - foreach($this->edit_fields as $field_num => $field) |
|
| 4241 | - { |
|
| 4242 | - if(isset($this->display_as[$field])) |
|
| 4243 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4244 | - else |
|
| 4245 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4246 | - } |
|
| 4247 | - } |
|
| 4248 | - else |
|
| 4249 | - { |
|
| 4250 | - $this->edit_fields = array(); |
|
| 4251 | - foreach($field_types as $field) |
|
| 4252 | - { |
|
| 4253 | - //Check if an unset_edit_field is initialize for this field name |
|
| 4254 | - if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
| 4255 | - continue; |
|
| 4256 | - |
|
| 4257 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4258 | - { |
|
| 4259 | - if(isset($this->display_as[$field->name])) |
|
| 4260 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4261 | - else |
|
| 4262 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4263 | - } |
|
| 4264 | - } |
|
| 4265 | - } |
|
| 4266 | - |
|
| 4267 | - $this->edit_fields_checked = true; |
|
| 4268 | - } |
|
| 4269 | - return $this->edit_fields; |
|
| 4270 | - } |
|
| 4271 | - |
|
| 4272 | - /** |
|
| 4273 | - * |
|
| 4274 | - * Enter description here ... |
|
| 4275 | - */ |
|
| 4276 | - protected function get_read_fields() |
|
| 4277 | - { |
|
| 4278 | - if($this->read_fields_checked === false) |
|
| 4279 | - { |
|
| 4280 | - $field_types = $this->get_field_types(); |
|
| 4281 | - if(!empty($this->read_fields)) |
|
| 4282 | - { |
|
| 4283 | - foreach($this->read_fields as $field_num => $field) |
|
| 4284 | - { |
|
| 4285 | - if(isset($this->display_as[$field])) |
|
| 4286 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4287 | - else |
|
| 4288 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4289 | - } |
|
| 4290 | - } |
|
| 4291 | - else |
|
| 4292 | - { |
|
| 4293 | - $this->read_fields = array(); |
|
| 4294 | - foreach($field_types as $field) |
|
| 4295 | - { |
|
| 4296 | - //Check if an unset_read_field is initialize for this field name |
|
| 4297 | - if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
| 4298 | - continue; |
|
| 4299 | - |
|
| 4300 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4301 | - { |
|
| 4302 | - if(isset($this->display_as[$field->name])) |
|
| 4303 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4304 | - else |
|
| 4305 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4306 | - } |
|
| 4307 | - } |
|
| 4308 | - } |
|
| 4309 | - |
|
| 4310 | - $this->read_fields_checked = true; |
|
| 4311 | - } |
|
| 4312 | - return $this->read_fields; |
|
| 4313 | - } |
|
| 4314 | - |
|
| 4315 | - public function order_by($order_by, $direction = 'asc') |
|
| 4316 | - { |
|
| 4317 | - $this->order_by = array($order_by,$direction); |
|
| 4318 | - |
|
| 4319 | - return $this; |
|
| 4320 | - } |
|
| 4321 | - |
|
| 4322 | - public function where($key, $value = NULL, $escape = TRUE) |
|
| 4323 | - { |
|
| 4324 | - $this->where[] = array($key,$value,$escape); |
|
| 4325 | - |
|
| 4326 | - return $this; |
|
| 4327 | - } |
|
| 4328 | - |
|
| 4329 | - public function or_where($key, $value = NULL, $escape = TRUE) |
|
| 4330 | - { |
|
| 4331 | - $this->or_where[] = array($key,$value,$escape); |
|
| 4332 | - |
|
| 4333 | - return $this; |
|
| 4334 | - } |
|
| 4335 | - |
|
| 4336 | - public function like($field, $match = '', $side = 'both') |
|
| 4337 | - { |
|
| 4338 | - $this->like[] = array($field, $match, $side); |
|
| 4339 | - |
|
| 4340 | - return $this; |
|
| 4341 | - } |
|
| 4342 | - |
|
| 4343 | - protected function having($key, $value = '', $escape = TRUE) |
|
| 4344 | - { |
|
| 4345 | - $this->having[] = array($key, $value, $escape); |
|
| 4346 | - |
|
| 4347 | - return $this; |
|
| 4348 | - } |
|
| 4349 | - |
|
| 4350 | - protected function or_having($key, $value = '', $escape = TRUE) |
|
| 4351 | - { |
|
| 4352 | - $this->or_having[] = array($key, $value, $escape); |
|
| 4353 | - |
|
| 4354 | - return $this; |
|
| 4355 | - } |
|
| 4356 | - |
|
| 4357 | - public function or_like($field, $match = '', $side = 'both') |
|
| 4358 | - { |
|
| 4359 | - $this->or_like[] = array($field, $match, $side); |
|
| 4360 | - |
|
| 4361 | - return $this; |
|
| 4362 | - } |
|
| 4363 | - |
|
| 4364 | - public function limit($limit, $offset = '') |
|
| 4365 | - { |
|
| 4366 | - $this->limit = array($limit,$offset); |
|
| 4367 | - |
|
| 4368 | - return $this; |
|
| 4369 | - } |
|
| 4370 | - |
|
| 4371 | - protected function _initialize_helpers() |
|
| 4372 | - { |
|
| 4373 | - $ci = &get_instance(); |
|
| 4374 | - |
|
| 4375 | - $ci->load->helper('url'); |
|
| 4376 | - $ci->load->helper('form'); |
|
| 4377 | - } |
|
| 4378 | - |
|
| 4379 | - protected function _initialize_variables() |
|
| 4380 | - { |
|
| 4381 | - $ci = &get_instance(); |
|
| 4382 | - $ci->load->config('grocery_crud'); |
|
| 4383 | - |
|
| 4384 | - $this->config = (object)array(); |
|
| 4385 | - |
|
| 4386 | - /** Initialize all the config variables into this object */ |
|
| 4387 | - $this->config->default_language = $ci->config->item('grocery_crud_default_language'); |
|
| 4388 | - $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
| 4389 | - $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); |
|
| 4390 | - $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
| 4391 | - $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
| 4392 | - $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
| 4393 | - $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); |
|
| 4394 | - $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); |
|
| 4395 | - $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
| 4396 | - $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
| 4397 | - $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); |
|
| 4398 | - $this->config->environment = $ci->config->item('grocery_crud_environment'); |
|
| 4450 | + /** |
|
| 4451 | + * |
|
| 4452 | + * Or else ... make it work! The web application takes decision of what to do and show it to the final user. |
|
| 4453 | + * Without this function nothing works. Here is the core of grocery CRUD project. |
|
| 4454 | + * |
|
| 4455 | + * @access public |
|
| 4456 | + */ |
|
| 4457 | + public function render() |
|
| 4458 | + { |
|
| 4459 | + $this->pre_render(); |
|
| 4399 | 4460 | |
| 4400 | - /** Initialize default paths */ |
|
| 4401 | - $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
| 4402 | - $this->default_css_path = $this->default_assets_path.'/css'; |
|
| 4403 | - $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
| 4404 | - $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
| 4461 | + if( $this->state_code != 0 ) |
|
| 4462 | + { |
|
| 4463 | + $this->state_info = $this->getStateInfo(); |
|
| 4464 | + } |
|
| 4465 | + else |
|
| 4466 | + { |
|
| 4467 | + throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); |
|
| 4468 | + die(); |
|
| 4469 | + } |
|
| 4405 | 4470 | |
| 4406 | - $this->character_limiter = $this->config->character_limiter; |
|
| 4471 | + switch ($this->state_code) { |
|
| 4472 | + case 15://success |
|
| 4473 | + case 1://list |
|
| 4474 | + if($this->unset_list) |
|
| 4475 | + { |
|
| 4476 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4477 | + die(); |
|
| 4478 | + } |
|
| 4407 | 4479 | |
| 4408 | - if ($this->character_limiter === 0 || $this->character_limiter === '0') { |
|
| 4409 | - $this->character_limiter = 1000000; //a very big number |
|
| 4410 | - } elseif($this->character_limiter === null || $this->character_limiter === false) { |
|
| 4411 | - $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value |
|
| 4412 | - } |
|
| 4480 | + if($this->theme === null) |
|
| 4481 | + $this->set_theme($this->default_theme); |
|
| 4482 | + $this->setThemeBasics(); |
|
| 4413 | 4483 | |
| 4414 | - if ($this->theme === null && !empty($this->config->default_theme)) { |
|
| 4415 | - $this->set_theme($this->config->default_theme); |
|
| 4416 | - } |
|
| 4417 | - } |
|
| 4418 | - |
|
| 4419 | - protected function _set_primary_keys_to_model() |
|
| 4420 | - { |
|
| 4421 | - if(!empty($this->primary_keys)) |
|
| 4422 | - { |
|
| 4423 | - foreach($this->primary_keys as $primary_key) |
|
| 4424 | - { |
|
| 4425 | - $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); |
|
| 4426 | - } |
|
| 4427 | - } |
|
| 4428 | - } |
|
| 4429 | - |
|
| 4430 | - /** |
|
| 4431 | - * Initialize all the required libraries and variables before rendering |
|
| 4432 | - */ |
|
| 4433 | - protected function pre_render() |
|
| 4434 | - { |
|
| 4435 | - $this->_initialize_variables(); |
|
| 4436 | - $this->_initialize_helpers(); |
|
| 4437 | - $this->_load_language(); |
|
| 4438 | - $this->state_code = $this->getStateCode(); |
|
| 4439 | - |
|
| 4440 | - if($this->basic_model === null) |
|
| 4441 | - $this->set_default_Model(); |
|
| 4442 | - |
|
| 4443 | - $this->set_basic_db_table($this->get_table()); |
|
| 4444 | - |
|
| 4445 | - $this->_load_date_format(); |
|
| 4446 | - |
|
| 4447 | - $this->_set_primary_keys_to_model(); |
|
| 4448 | - } |
|
| 4449 | - |
|
| 4450 | - /** |
|
| 4451 | - * |
|
| 4452 | - * Or else ... make it work! The web application takes decision of what to do and show it to the final user. |
|
| 4453 | - * Without this function nothing works. Here is the core of grocery CRUD project. |
|
| 4454 | - * |
|
| 4455 | - * @access public |
|
| 4456 | - */ |
|
| 4457 | - public function render() |
|
| 4458 | - { |
|
| 4459 | - $this->pre_render(); |
|
| 4460 | - |
|
| 4461 | - if( $this->state_code != 0 ) |
|
| 4462 | - { |
|
| 4463 | - $this->state_info = $this->getStateInfo(); |
|
| 4464 | - } |
|
| 4465 | - else |
|
| 4466 | - { |
|
| 4467 | - throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); |
|
| 4468 | - die(); |
|
| 4469 | - } |
|
| 4470 | - |
|
| 4471 | - switch ($this->state_code) { |
|
| 4472 | - case 15://success |
|
| 4473 | - case 1://list |
|
| 4474 | - if($this->unset_list) |
|
| 4475 | - { |
|
| 4476 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4477 | - die(); |
|
| 4478 | - } |
|
| 4479 | - |
|
| 4480 | - if($this->theme === null) |
|
| 4481 | - $this->set_theme($this->default_theme); |
|
| 4482 | - $this->setThemeBasics(); |
|
| 4483 | - |
|
| 4484 | - $this->set_basic_Layout(); |
|
| 4484 | + $this->set_basic_Layout(); |
|
| 4485 | 4485 | |
| 4486 | - $state_info = $this->getStateInfo(); |
|
| 4486 | + $state_info = $this->getStateInfo(); |
|
| 4487 | 4487 | |
| 4488 | - $this->showList(false,$state_info); |
|
| 4488 | + $this->showList(false,$state_info); |
|
| 4489 | 4489 | |
| 4490 | - break; |
|
| 4490 | + break; |
|
| 4491 | 4491 | |
| 4492 | - case 2://add |
|
| 4493 | - if($this->unset_add) |
|
| 4494 | - { |
|
| 4495 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4496 | - die(); |
|
| 4497 | - } |
|
| 4492 | + case 2://add |
|
| 4493 | + if($this->unset_add) |
|
| 4494 | + { |
|
| 4495 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4496 | + die(); |
|
| 4497 | + } |
|
| 4498 | 4498 | |
| 4499 | - if($this->theme === null) |
|
| 4500 | - $this->set_theme($this->default_theme); |
|
| 4501 | - $this->setThemeBasics(); |
|
| 4499 | + if($this->theme === null) |
|
| 4500 | + $this->set_theme($this->default_theme); |
|
| 4501 | + $this->setThemeBasics(); |
|
| 4502 | 4502 | |
| 4503 | - $this->set_basic_Layout(); |
|
| 4503 | + $this->set_basic_Layout(); |
|
| 4504 | 4504 | |
| 4505 | - $this->showAddForm(); |
|
| 4505 | + $this->showAddForm(); |
|
| 4506 | 4506 | |
| 4507 | - break; |
|
| 4507 | + break; |
|
| 4508 | 4508 | |
| 4509 | - case 3://edit |
|
| 4510 | - if($this->unset_edit) |
|
| 4511 | - { |
|
| 4512 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4513 | - die(); |
|
| 4514 | - } |
|
| 4509 | + case 3://edit |
|
| 4510 | + if($this->unset_edit) |
|
| 4511 | + { |
|
| 4512 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4513 | + die(); |
|
| 4514 | + } |
|
| 4515 | 4515 | |
| 4516 | - if($this->theme === null) |
|
| 4517 | - $this->set_theme($this->default_theme); |
|
| 4518 | - $this->setThemeBasics(); |
|
| 4516 | + if($this->theme === null) |
|
| 4517 | + $this->set_theme($this->default_theme); |
|
| 4518 | + $this->setThemeBasics(); |
|
| 4519 | 4519 | |
| 4520 | - $this->set_basic_Layout(); |
|
| 4520 | + $this->set_basic_Layout(); |
|
| 4521 | 4521 | |
| 4522 | - $state_info = $this->getStateInfo(); |
|
| 4522 | + $state_info = $this->getStateInfo(); |
|
| 4523 | 4523 | |
| 4524 | - $this->showEditForm($state_info); |
|
| 4524 | + $this->showEditForm($state_info); |
|
| 4525 | 4525 | |
| 4526 | - break; |
|
| 4526 | + break; |
|
| 4527 | 4527 | |
| 4528 | - case 4://delete |
|
| 4529 | - if($this->unset_delete) |
|
| 4530 | - { |
|
| 4531 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4532 | - die(); |
|
| 4533 | - } |
|
| 4528 | + case 4://delete |
|
| 4529 | + if($this->unset_delete) |
|
| 4530 | + { |
|
| 4531 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4532 | + die(); |
|
| 4533 | + } |
|
| 4534 | 4534 | |
| 4535 | - $state_info = $this->getStateInfo(); |
|
| 4536 | - $delete_result = $this->db_delete($state_info); |
|
| 4535 | + $state_info = $this->getStateInfo(); |
|
| 4536 | + $delete_result = $this->db_delete($state_info); |
|
| 4537 | 4537 | |
| 4538 | - $this->delete_layout( $delete_result ); |
|
| 4539 | - break; |
|
| 4538 | + $this->delete_layout( $delete_result ); |
|
| 4539 | + break; |
|
| 4540 | 4540 | |
| 4541 | - case 5://insert |
|
| 4542 | - if($this->unset_add) |
|
| 4543 | - { |
|
| 4544 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4545 | - die(); |
|
| 4546 | - } |
|
| 4541 | + case 5://insert |
|
| 4542 | + if($this->unset_add) |
|
| 4543 | + { |
|
| 4544 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4545 | + die(); |
|
| 4546 | + } |
|
| 4547 | 4547 | |
| 4548 | - $state_info = $this->getStateInfo(); |
|
| 4549 | - $insert_result = $this->db_insert($state_info); |
|
| 4548 | + $state_info = $this->getStateInfo(); |
|
| 4549 | + $insert_result = $this->db_insert($state_info); |
|
| 4550 | 4550 | |
| 4551 | - $this->insert_layout($insert_result); |
|
| 4552 | - break; |
|
| 4551 | + $this->insert_layout($insert_result); |
|
| 4552 | + break; |
|
| 4553 | 4553 | |
| 4554 | - case 6://update |
|
| 4555 | - if($this->unset_edit) |
|
| 4556 | - { |
|
| 4557 | - throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4558 | - die(); |
|
| 4559 | - } |
|
| 4554 | + case 6://update |
|
| 4555 | + if($this->unset_edit) |
|
| 4556 | + { |
|
| 4557 | + throw new Exception('This user is not allowed to do this operation', 14); |
|
| 4558 | + die(); |
|
| 4559 | + } |
|
| 4560 | 4560 | |
| 4561 | - $state_info = $this->getStateInfo(); |
|
| 4562 | - $update_result = $this->db_update($state_info); |
|
| 4561 | + $state_info = $this->getStateInfo(); |
|
| 4562 | + $update_result = $this->db_update($state_info); |
|
| 4563 | 4563 | |
| 4564 | - $this->update_layout( $update_result,$state_info); |
|
| 4565 | - break; |
|
| 4564 | + $this->update_layout( $update_result,$state_info); |
|
| 4565 | + break; |
|
| 4566 | 4566 | |
| 4567 | - case 7://ajax_list |
|
| 4567 | + case 7://ajax_list |
|
| 4568 | 4568 | |
| 4569 | - if($this->unset_list) |
|
| 4570 | - { |
|
| 4571 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4572 | - die(); |
|
| 4573 | - } |
|
| 4569 | + if($this->unset_list) |
|
| 4570 | + { |
|
| 4571 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4572 | + die(); |
|
| 4573 | + } |
|
| 4574 | 4574 | |
| 4575 | - if($this->theme === null) |
|
| 4576 | - $this->set_theme($this->default_theme); |
|
| 4577 | - $this->setThemeBasics(); |
|
| 4575 | + if($this->theme === null) |
|
| 4576 | + $this->set_theme($this->default_theme); |
|
| 4577 | + $this->setThemeBasics(); |
|
| 4578 | 4578 | |
| 4579 | - $this->set_basic_Layout(); |
|
| 4579 | + $this->set_basic_Layout(); |
|
| 4580 | 4580 | |
| 4581 | - $state_info = $this->getStateInfo(); |
|
| 4582 | - $this->set_ajax_list_queries($state_info); |
|
| 4581 | + $state_info = $this->getStateInfo(); |
|
| 4582 | + $this->set_ajax_list_queries($state_info); |
|
| 4583 | 4583 | |
| 4584 | - $this->showList(true); |
|
| 4584 | + $this->showList(true); |
|
| 4585 | 4585 | |
| 4586 | - break; |
|
| 4586 | + break; |
|
| 4587 | 4587 | |
| 4588 | - case 8://ajax_list_info |
|
| 4588 | + case 8://ajax_list_info |
|
| 4589 | 4589 | |
| 4590 | - if($this->theme === null) |
|
| 4591 | - $this->set_theme($this->default_theme); |
|
| 4592 | - $this->setThemeBasics(); |
|
| 4590 | + if($this->theme === null) |
|
| 4591 | + $this->set_theme($this->default_theme); |
|
| 4592 | + $this->setThemeBasics(); |
|
| 4593 | 4593 | |
| 4594 | - $this->set_basic_Layout(); |
|
| 4594 | + $this->set_basic_Layout(); |
|
| 4595 | 4595 | |
| 4596 | - $state_info = $this->getStateInfo(); |
|
| 4597 | - $this->set_ajax_list_queries($state_info); |
|
| 4596 | + $state_info = $this->getStateInfo(); |
|
| 4597 | + $this->set_ajax_list_queries($state_info); |
|
| 4598 | 4598 | |
| 4599 | - $this->showListInfo(); |
|
| 4600 | - break; |
|
| 4599 | + $this->showListInfo(); |
|
| 4600 | + break; |
|
| 4601 | 4601 | |
| 4602 | - case 9://insert_validation |
|
| 4602 | + case 9://insert_validation |
|
| 4603 | 4603 | |
| 4604 | - $validation_result = $this->db_insert_validation(); |
|
| 4604 | + $validation_result = $this->db_insert_validation(); |
|
| 4605 | 4605 | |
| 4606 | - $this->validation_layout($validation_result); |
|
| 4607 | - break; |
|
| 4606 | + $this->validation_layout($validation_result); |
|
| 4607 | + break; |
|
| 4608 | 4608 | |
| 4609 | - case 10://update_validation |
|
| 4609 | + case 10://update_validation |
|
| 4610 | 4610 | |
| 4611 | - $validation_result = $this->db_update_validation(); |
|
| 4611 | + $validation_result = $this->db_update_validation(); |
|
| 4612 | 4612 | |
| 4613 | - $this->validation_layout($validation_result); |
|
| 4614 | - break; |
|
| 4613 | + $this->validation_layout($validation_result); |
|
| 4614 | + break; |
|
| 4615 | 4615 | |
| 4616 | - case 11://upload_file |
|
| 4616 | + case 11://upload_file |
|
| 4617 | 4617 | |
| 4618 | - $state_info = $this->getStateInfo(); |
|
| 4618 | + $state_info = $this->getStateInfo(); |
|
| 4619 | 4619 | |
| 4620 | - $upload_result = $this->upload_file($state_info); |
|
| 4620 | + $upload_result = $this->upload_file($state_info); |
|
| 4621 | 4621 | |
| 4622 | - $this->upload_layout($upload_result, $state_info->field_name); |
|
| 4623 | - break; |
|
| 4622 | + $this->upload_layout($upload_result, $state_info->field_name); |
|
| 4623 | + break; |
|
| 4624 | 4624 | |
| 4625 | - case 12://delete_file |
|
| 4626 | - $state_info = $this->getStateInfo(); |
|
| 4625 | + case 12://delete_file |
|
| 4626 | + $state_info = $this->getStateInfo(); |
|
| 4627 | 4627 | |
| 4628 | - $delete_file_result = $this->delete_file($state_info); |
|
| 4628 | + $delete_file_result = $this->delete_file($state_info); |
|
| 4629 | 4629 | |
| 4630 | - $this->delete_file_layout($delete_file_result); |
|
| 4631 | - break; |
|
| 4632 | - /* |
|
| 4630 | + $this->delete_file_layout($delete_file_result); |
|
| 4631 | + break; |
|
| 4632 | + /* |
|
| 4633 | 4633 | case 13: //ajax_relation |
| 4634 | 4634 | $state_info = $this->getStateInfo(); |
| 4635 | 4635 | |
@@ -4646,559 +4646,559 @@ discard block |
||
| 4646 | 4646 | die(); |
| 4647 | 4647 | break; |
| 4648 | 4648 | */ |
| 4649 | - case 16: //export to excel |
|
| 4650 | - //a big number just to ensure that the table characters will not be cutted. |
|
| 4651 | - $this->character_limiter = 1000000; |
|
| 4649 | + case 16: //export to excel |
|
| 4650 | + //a big number just to ensure that the table characters will not be cutted. |
|
| 4651 | + $this->character_limiter = 1000000; |
|
| 4652 | 4652 | |
| 4653 | - if($this->unset_export) |
|
| 4654 | - { |
|
| 4655 | - throw new Exception('You don\'t have permissions for this operation', 15); |
|
| 4656 | - die(); |
|
| 4657 | - } |
|
| 4653 | + if($this->unset_export) |
|
| 4654 | + { |
|
| 4655 | + throw new Exception('You don\'t have permissions for this operation', 15); |
|
| 4656 | + die(); |
|
| 4657 | + } |
|
| 4658 | 4658 | |
| 4659 | - if($this->theme === null) |
|
| 4660 | - $this->set_theme($this->default_theme); |
|
| 4661 | - $this->setThemeBasics(); |
|
| 4659 | + if($this->theme === null) |
|
| 4660 | + $this->set_theme($this->default_theme); |
|
| 4661 | + $this->setThemeBasics(); |
|
| 4662 | 4662 | |
| 4663 | - $this->set_basic_Layout(); |
|
| 4663 | + $this->set_basic_Layout(); |
|
| 4664 | 4664 | |
| 4665 | - $state_info = $this->getStateInfo(); |
|
| 4666 | - $this->set_ajax_list_queries($state_info); |
|
| 4667 | - $this->exportToExcel($state_info); |
|
| 4668 | - break; |
|
| 4665 | + $state_info = $this->getStateInfo(); |
|
| 4666 | + $this->set_ajax_list_queries($state_info); |
|
| 4667 | + $this->exportToExcel($state_info); |
|
| 4668 | + break; |
|
| 4669 | 4669 | |
| 4670 | - case 17: //print |
|
| 4671 | - //a big number just to ensure that the table characters will not be cutted. |
|
| 4672 | - $this->character_limiter = 1000000; |
|
| 4670 | + case 17: //print |
|
| 4671 | + //a big number just to ensure that the table characters will not be cutted. |
|
| 4672 | + $this->character_limiter = 1000000; |
|
| 4673 | 4673 | |
| 4674 | - if($this->unset_print) |
|
| 4675 | - { |
|
| 4676 | - throw new Exception('You don\'t have permissions for this operation', 15); |
|
| 4677 | - die(); |
|
| 4678 | - } |
|
| 4674 | + if($this->unset_print) |
|
| 4675 | + { |
|
| 4676 | + throw new Exception('You don\'t have permissions for this operation', 15); |
|
| 4677 | + die(); |
|
| 4678 | + } |
|
| 4679 | 4679 | |
| 4680 | - if($this->theme === null) |
|
| 4681 | - $this->set_theme($this->default_theme); |
|
| 4682 | - $this->setThemeBasics(); |
|
| 4680 | + if($this->theme === null) |
|
| 4681 | + $this->set_theme($this->default_theme); |
|
| 4682 | + $this->setThemeBasics(); |
|
| 4683 | 4683 | |
| 4684 | - $this->set_basic_Layout(); |
|
| 4684 | + $this->set_basic_Layout(); |
|
| 4685 | 4685 | |
| 4686 | - $state_info = $this->getStateInfo(); |
|
| 4687 | - $this->set_ajax_list_queries($state_info); |
|
| 4688 | - $this->print_webpage($state_info); |
|
| 4689 | - break; |
|
| 4686 | + $state_info = $this->getStateInfo(); |
|
| 4687 | + $this->set_ajax_list_queries($state_info); |
|
| 4688 | + $this->print_webpage($state_info); |
|
| 4689 | + break; |
|
| 4690 | 4690 | |
| 4691 | - case grocery_CRUD_States::STATE_READ: |
|
| 4692 | - if($this->unset_read) |
|
| 4693 | - { |
|
| 4694 | - throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4695 | - die(); |
|
| 4696 | - } |
|
| 4691 | + case grocery_CRUD_States::STATE_READ: |
|
| 4692 | + if($this->unset_read) |
|
| 4693 | + { |
|
| 4694 | + throw new Exception('You don\'t have permissions for this operation', 14); |
|
| 4695 | + die(); |
|
| 4696 | + } |
|
| 4697 | 4697 | |
| 4698 | - if($this->theme === null) |
|
| 4699 | - $this->set_theme($this->default_theme); |
|
| 4700 | - $this->setThemeBasics(); |
|
| 4698 | + if($this->theme === null) |
|
| 4699 | + $this->set_theme($this->default_theme); |
|
| 4700 | + $this->setThemeBasics(); |
|
| 4701 | 4701 | |
| 4702 | - $this->set_basic_Layout(); |
|
| 4702 | + $this->set_basic_Layout(); |
|
| 4703 | 4703 | |
| 4704 | - $state_info = $this->getStateInfo(); |
|
| 4704 | + $state_info = $this->getStateInfo(); |
|
| 4705 | 4705 | |
| 4706 | - $this->showReadForm($state_info); |
|
| 4706 | + $this->showReadForm($state_info); |
|
| 4707 | 4707 | |
| 4708 | - break; |
|
| 4708 | + break; |
|
| 4709 | 4709 | |
| 4710 | 4710 | case grocery_CRUD_States::STATE_DELETE_MULTIPLE: |
| 4711 | 4711 | |
| 4712 | - if($this->unset_delete) |
|
| 4712 | + if($this->unset_delete) |
|
| 4713 | 4713 | { |
| 4714 | 4714 | throw new Exception('This user is not allowed to do this operation'); |
| 4715 | 4715 | die(); |
| 4716 | 4716 | } |
| 4717 | 4717 | |
| 4718 | - $state_info = $this->getStateInfo(); |
|
| 4719 | - $delete_result = $this->db_multiple_delete($state_info); |
|
| 4718 | + $state_info = $this->getStateInfo(); |
|
| 4719 | + $delete_result = $this->db_multiple_delete($state_info); |
|
| 4720 | 4720 | |
| 4721 | - $this->delete_layout($delete_result); |
|
| 4721 | + $this->delete_layout($delete_result); |
|
| 4722 | 4722 | |
| 4723 | 4723 | break; |
| 4724 | 4724 | |
| 4725 | - } |
|
| 4726 | - |
|
| 4727 | - return $this->get_layout(); |
|
| 4728 | - } |
|
| 4729 | - |
|
| 4730 | - protected function get_common_data() |
|
| 4731 | - { |
|
| 4732 | - $data = (object)array(); |
|
| 4733 | - |
|
| 4734 | - $data->subject = $this->subject; |
|
| 4735 | - $data->subject_plural = $this->subject_plural; |
|
| 4736 | - |
|
| 4737 | - return $data; |
|
| 4738 | - } |
|
| 4739 | - |
|
| 4740 | - /** |
|
| 4741 | - * |
|
| 4742 | - * Enter description here ... |
|
| 4743 | - */ |
|
| 4744 | - public function callback_before_insert($callback = null) |
|
| 4745 | - { |
|
| 4746 | - $this->callback_before_insert = $callback; |
|
| 4747 | - |
|
| 4748 | - return $this; |
|
| 4749 | - } |
|
| 4750 | - |
|
| 4751 | - /** |
|
| 4752 | - * |
|
| 4753 | - * Enter description here ... |
|
| 4754 | - */ |
|
| 4755 | - public function callback_after_insert($callback = null) |
|
| 4756 | - { |
|
| 4757 | - $this->callback_after_insert = $callback; |
|
| 4758 | - |
|
| 4759 | - return $this; |
|
| 4760 | - } |
|
| 4761 | - |
|
| 4762 | - /** |
|
| 4763 | - * |
|
| 4764 | - * Enter description here ... |
|
| 4765 | - */ |
|
| 4766 | - public function callback_insert($callback = null) |
|
| 4767 | - { |
|
| 4768 | - $this->callback_insert = $callback; |
|
| 4769 | - |
|
| 4770 | - return $this; |
|
| 4771 | - } |
|
| 4772 | - |
|
| 4773 | - |
|
| 4774 | - /** |
|
| 4775 | - * |
|
| 4776 | - * Enter description here ... |
|
| 4777 | - */ |
|
| 4778 | - public function callback_before_update($callback = null) |
|
| 4779 | - { |
|
| 4780 | - $this->callback_before_update = $callback; |
|
| 4781 | - |
|
| 4782 | - return $this; |
|
| 4783 | - } |
|
| 4784 | - |
|
| 4785 | - /** |
|
| 4786 | - * |
|
| 4787 | - * Enter description here ... |
|
| 4788 | - */ |
|
| 4789 | - public function callback_after_update($callback = null) |
|
| 4790 | - { |
|
| 4791 | - $this->callback_after_update = $callback; |
|
| 4792 | - |
|
| 4793 | - return $this; |
|
| 4794 | - } |
|
| 4795 | - |
|
| 4796 | - |
|
| 4797 | - /** |
|
| 4798 | - * |
|
| 4799 | - * Enter description here ... |
|
| 4800 | - * @param mixed $callback |
|
| 4801 | - */ |
|
| 4802 | - public function callback_update($callback = null) |
|
| 4803 | - { |
|
| 4804 | - $this->callback_update = $callback; |
|
| 4805 | - |
|
| 4806 | - return $this; |
|
| 4807 | - } |
|
| 4808 | - |
|
| 4809 | - /** |
|
| 4810 | - * |
|
| 4811 | - * Enter description here ... |
|
| 4812 | - */ |
|
| 4813 | - public function callback_before_delete($callback = null) |
|
| 4814 | - { |
|
| 4815 | - $this->callback_before_delete = $callback; |
|
| 4816 | - |
|
| 4817 | - return $this; |
|
| 4818 | - } |
|
| 4819 | - |
|
| 4820 | - /** |
|
| 4821 | - * |
|
| 4822 | - * Enter description here ... |
|
| 4823 | - */ |
|
| 4824 | - public function callback_after_delete($callback = null) |
|
| 4825 | - { |
|
| 4826 | - $this->callback_after_delete = $callback; |
|
| 4827 | - |
|
| 4828 | - return $this; |
|
| 4829 | - } |
|
| 4830 | - |
|
| 4831 | - /** |
|
| 4832 | - * |
|
| 4833 | - * Enter description here ... |
|
| 4834 | - */ |
|
| 4835 | - public function callback_delete($callback = null) |
|
| 4836 | - { |
|
| 4837 | - $this->callback_delete = $callback; |
|
| 4838 | - |
|
| 4839 | - return $this; |
|
| 4840 | - } |
|
| 4841 | - |
|
| 4842 | - /** |
|
| 4843 | - * |
|
| 4844 | - * Enter description here ... |
|
| 4845 | - * @param string $column |
|
| 4846 | - * @param mixed $callback |
|
| 4847 | - */ |
|
| 4848 | - public function callback_column($column ,$callback = null) |
|
| 4849 | - { |
|
| 4850 | - $this->callback_column[$column] = $callback; |
|
| 4851 | - |
|
| 4852 | - return $this; |
|
| 4853 | - } |
|
| 4854 | - |
|
| 4855 | - /** |
|
| 4856 | - * |
|
| 4857 | - * Enter description here ... |
|
| 4858 | - * @param string $field |
|
| 4859 | - * @param mixed $callback |
|
| 4860 | - */ |
|
| 4861 | - public function callback_field($field, $callback = null) |
|
| 4862 | - { |
|
| 4863 | - $this->callback_add_field[$field] = $callback; |
|
| 4864 | - $this->callback_edit_field[$field] = $callback; |
|
| 4865 | - |
|
| 4866 | - return $this; |
|
| 4867 | - } |
|
| 4868 | - |
|
| 4869 | - /** |
|
| 4870 | - * |
|
| 4871 | - * Enter description here ... |
|
| 4872 | - * @param string $field |
|
| 4873 | - * @param mixed $callback |
|
| 4874 | - */ |
|
| 4875 | - public function callback_add_field($field, $callback = null) |
|
| 4876 | - { |
|
| 4877 | - $this->callback_add_field[$field] = $callback; |
|
| 4878 | - |
|
| 4879 | - return $this; |
|
| 4880 | - } |
|
| 4881 | - |
|
| 4882 | - /** |
|
| 4883 | - * |
|
| 4884 | - * Enter description here ... |
|
| 4885 | - * @param string $field |
|
| 4886 | - * @param mixed $callback |
|
| 4887 | - */ |
|
| 4888 | - public function callback_edit_field($field, $callback = null) |
|
| 4889 | - { |
|
| 4890 | - $this->callback_edit_field[$field] = $callback; |
|
| 4891 | - |
|
| 4892 | - return $this; |
|
| 4893 | - } |
|
| 4894 | - |
|
| 4895 | - /** |
|
| 4896 | - * |
|
| 4897 | - * Callback that replace the default auto uploader |
|
| 4898 | - * |
|
| 4899 | - * @param mixed $callback |
|
| 4900 | - * @return grocery_CRUD |
|
| 4901 | - */ |
|
| 4902 | - public function callback_upload($callback = null) |
|
| 4903 | - { |
|
| 4904 | - $this->callback_upload = $callback; |
|
| 4905 | - |
|
| 4906 | - return $this; |
|
| 4907 | - } |
|
| 4908 | - |
|
| 4909 | - /** |
|
| 4910 | - * |
|
| 4911 | - * A callback that triggered before the upload functionality. This callback is suggested for validation checks |
|
| 4912 | - * @param mixed $callback |
|
| 4913 | - * @return grocery_CRUD |
|
| 4914 | - */ |
|
| 4915 | - public function callback_before_upload($callback = null) |
|
| 4916 | - { |
|
| 4917 | - $this->callback_before_upload = $callback; |
|
| 4918 | - |
|
| 4919 | - return $this; |
|
| 4920 | - } |
|
| 4921 | - |
|
| 4922 | - /** |
|
| 4923 | - * |
|
| 4924 | - * A callback that triggered after the upload functionality |
|
| 4925 | - * @param mixed $callback |
|
| 4926 | - * @return grocery_CRUD |
|
| 4927 | - */ |
|
| 4928 | - public function callback_after_upload($callback = null) |
|
| 4929 | - { |
|
| 4930 | - $this->callback_after_upload = $callback; |
|
| 4931 | - |
|
| 4932 | - return $this; |
|
| 4933 | - |
|
| 4934 | - } |
|
| 4935 | - |
|
| 4936 | - /** |
|
| 4937 | - * |
|
| 4938 | - * Gets the basic database table of our crud. |
|
| 4939 | - * @return string |
|
| 4940 | - */ |
|
| 4941 | - public function get_table() |
|
| 4942 | - { |
|
| 4943 | - if($this->basic_db_table_checked) |
|
| 4944 | - { |
|
| 4945 | - return $this->basic_db_table; |
|
| 4946 | - } |
|
| 4947 | - elseif( $this->basic_db_table !== null ) |
|
| 4948 | - { |
|
| 4949 | - if(!$this->table_exists($this->basic_db_table)) |
|
| 4950 | - { |
|
| 4951 | - throw new Exception('The table name does not exist. Please check you database and try again.',11); |
|
| 4952 | - die(); |
|
| 4953 | - } |
|
| 4954 | - $this->basic_db_table_checked = true; |
|
| 4955 | - return $this->basic_db_table; |
|
| 4956 | - } |
|
| 4957 | - else |
|
| 4958 | - { |
|
| 4959 | - //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
|
| 4960 | - $last_chance_table_name = $this->get_method_name(); |
|
| 4961 | - if($this->table_exists($last_chance_table_name)) |
|
| 4962 | - { |
|
| 4963 | - $this->set_table($last_chance_table_name); |
|
| 4964 | - } |
|
| 4965 | - $this->basic_db_table_checked = true; |
|
| 4966 | - return $this->basic_db_table; |
|
| 4967 | - |
|
| 4968 | - } |
|
| 4969 | - |
|
| 4970 | - return false; |
|
| 4971 | - } |
|
| 4972 | - |
|
| 4973 | - /** |
|
| 4974 | - * |
|
| 4975 | - * The field names of the required fields |
|
| 4976 | - */ |
|
| 4977 | - public function required_fields() |
|
| 4978 | - { |
|
| 4979 | - $args = func_get_args(); |
|
| 4980 | - |
|
| 4981 | - if(isset($args[0]) && is_array($args[0])) |
|
| 4982 | - { |
|
| 4983 | - $args = $args[0]; |
|
| 4984 | - } |
|
| 4985 | - |
|
| 4986 | - $this->required_fields = $args; |
|
| 4987 | - |
|
| 4988 | - return $this; |
|
| 4989 | - } |
|
| 4990 | - |
|
| 4991 | - /** |
|
| 4992 | - * Add the fields that they are as UNIQUE in the database structure |
|
| 4993 | - * |
|
| 4994 | - * @return grocery_CRUD |
|
| 4995 | - */ |
|
| 4996 | - public function unique_fields() |
|
| 4997 | - { |
|
| 4998 | - $args = func_get_args(); |
|
| 4999 | - |
|
| 5000 | - if(isset($args[0]) && is_array($args[0])) |
|
| 5001 | - { |
|
| 5002 | - $args = $args[0]; |
|
| 5003 | - } |
|
| 5004 | - |
|
| 5005 | - $this->_unique_fields = $args; |
|
| 5006 | - |
|
| 5007 | - return $this; |
|
| 5008 | - } |
|
| 5009 | - |
|
| 5010 | - /** |
|
| 5011 | - * |
|
| 5012 | - * Sets the basic database table that we will get our data. |
|
| 5013 | - * @param string $table_name |
|
| 5014 | - * @return grocery_CRUD |
|
| 5015 | - */ |
|
| 5016 | - public function set_table($table_name) |
|
| 5017 | - { |
|
| 5018 | - if(!empty($table_name) && $this->basic_db_table === null) |
|
| 5019 | - { |
|
| 5020 | - $this->basic_db_table = $table_name; |
|
| 5021 | - } |
|
| 5022 | - elseif(!empty($table_name)) |
|
| 5023 | - { |
|
| 5024 | - throw new Exception('You have already insert a table name once...', 1); |
|
| 5025 | - } |
|
| 5026 | - else |
|
| 5027 | - { |
|
| 5028 | - throw new Exception('The table name cannot be empty.', 2); |
|
| 5029 | - die(); |
|
| 5030 | - } |
|
| 5031 | - |
|
| 5032 | - return $this; |
|
| 5033 | - } |
|
| 5034 | - |
|
| 5035 | - /** |
|
| 5036 | - * Set a full URL path to this method. |
|
| 5037 | - * |
|
| 5038 | - * This method is useful when the path is not specified correctly. |
|
| 5039 | - * Especially when we are using routes. |
|
| 5040 | - * For example: |
|
| 5041 | - * Let's say we have the path http://www.example.com/ however the original url path is |
|
| 5042 | - * http://www.example.com/example/index . We have to specify the url so we can have |
|
| 5043 | - * all the CRUD operations correctly. |
|
| 5044 | - * The url path has to be set from this method like this: |
|
| 5045 | - * <code> |
|
| 5046 | - * $crud->set_crud_url_path(site_url('example/index')); |
|
| 5047 | - * </code> |
|
| 5048 | - * |
|
| 5049 | - * @param string $crud_url_path |
|
| 5050 | - * @param string $list_url_path |
|
| 5051 | - * @return grocery_CRUD |
|
| 5052 | - */ |
|
| 5053 | - public function set_crud_url_path($crud_url_path, $list_url_path = null) |
|
| 5054 | - { |
|
| 5055 | - $this->crud_url_path = $crud_url_path; |
|
| 5056 | - |
|
| 5057 | - //If the list_url_path is empty so we are guessing that the list_url_path |
|
| 5058 | - //will be the same with crud_url_path |
|
| 5059 | - $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; |
|
| 5060 | - |
|
| 5061 | - return $this; |
|
| 5062 | - } |
|
| 5063 | - |
|
| 5064 | - /** |
|
| 5065 | - * |
|
| 5066 | - * Set a subject to understand what type of CRUD you use. |
|
| 4725 | + } |
|
| 4726 | + |
|
| 4727 | + return $this->get_layout(); |
|
| 4728 | + } |
|
| 4729 | + |
|
| 4730 | + protected function get_common_data() |
|
| 4731 | + { |
|
| 4732 | + $data = (object)array(); |
|
| 4733 | + |
|
| 4734 | + $data->subject = $this->subject; |
|
| 4735 | + $data->subject_plural = $this->subject_plural; |
|
| 4736 | + |
|
| 4737 | + return $data; |
|
| 4738 | + } |
|
| 4739 | + |
|
| 4740 | + /** |
|
| 4741 | + * |
|
| 4742 | + * Enter description here ... |
|
| 4743 | + */ |
|
| 4744 | + public function callback_before_insert($callback = null) |
|
| 4745 | + { |
|
| 4746 | + $this->callback_before_insert = $callback; |
|
| 4747 | + |
|
| 4748 | + return $this; |
|
| 4749 | + } |
|
| 4750 | + |
|
| 4751 | + /** |
|
| 4752 | + * |
|
| 4753 | + * Enter description here ... |
|
| 4754 | + */ |
|
| 4755 | + public function callback_after_insert($callback = null) |
|
| 4756 | + { |
|
| 4757 | + $this->callback_after_insert = $callback; |
|
| 4758 | + |
|
| 4759 | + return $this; |
|
| 4760 | + } |
|
| 4761 | + |
|
| 4762 | + /** |
|
| 4763 | + * |
|
| 4764 | + * Enter description here ... |
|
| 4765 | + */ |
|
| 4766 | + public function callback_insert($callback = null) |
|
| 4767 | + { |
|
| 4768 | + $this->callback_insert = $callback; |
|
| 4769 | + |
|
| 4770 | + return $this; |
|
| 4771 | + } |
|
| 4772 | + |
|
| 4773 | + |
|
| 4774 | + /** |
|
| 4775 | + * |
|
| 4776 | + * Enter description here ... |
|
| 4777 | + */ |
|
| 4778 | + public function callback_before_update($callback = null) |
|
| 4779 | + { |
|
| 4780 | + $this->callback_before_update = $callback; |
|
| 4781 | + |
|
| 4782 | + return $this; |
|
| 4783 | + } |
|
| 4784 | + |
|
| 4785 | + /** |
|
| 4786 | + * |
|
| 4787 | + * Enter description here ... |
|
| 4788 | + */ |
|
| 4789 | + public function callback_after_update($callback = null) |
|
| 4790 | + { |
|
| 4791 | + $this->callback_after_update = $callback; |
|
| 4792 | + |
|
| 4793 | + return $this; |
|
| 4794 | + } |
|
| 4795 | + |
|
| 4796 | + |
|
| 4797 | + /** |
|
| 4798 | + * |
|
| 4799 | + * Enter description here ... |
|
| 4800 | + * @param mixed $callback |
|
| 4801 | + */ |
|
| 4802 | + public function callback_update($callback = null) |
|
| 4803 | + { |
|
| 4804 | + $this->callback_update = $callback; |
|
| 4805 | + |
|
| 4806 | + return $this; |
|
| 4807 | + } |
|
| 4808 | + |
|
| 4809 | + /** |
|
| 4810 | + * |
|
| 4811 | + * Enter description here ... |
|
| 4812 | + */ |
|
| 4813 | + public function callback_before_delete($callback = null) |
|
| 4814 | + { |
|
| 4815 | + $this->callback_before_delete = $callback; |
|
| 4816 | + |
|
| 4817 | + return $this; |
|
| 4818 | + } |
|
| 4819 | + |
|
| 4820 | + /** |
|
| 4821 | + * |
|
| 4822 | + * Enter description here ... |
|
| 4823 | + */ |
|
| 4824 | + public function callback_after_delete($callback = null) |
|
| 4825 | + { |
|
| 4826 | + $this->callback_after_delete = $callback; |
|
| 4827 | + |
|
| 4828 | + return $this; |
|
| 4829 | + } |
|
| 4830 | + |
|
| 4831 | + /** |
|
| 4832 | + * |
|
| 4833 | + * Enter description here ... |
|
| 4834 | + */ |
|
| 4835 | + public function callback_delete($callback = null) |
|
| 4836 | + { |
|
| 4837 | + $this->callback_delete = $callback; |
|
| 4838 | + |
|
| 4839 | + return $this; |
|
| 4840 | + } |
|
| 4841 | + |
|
| 4842 | + /** |
|
| 4843 | + * |
|
| 4844 | + * Enter description here ... |
|
| 4845 | + * @param string $column |
|
| 4846 | + * @param mixed $callback |
|
| 4847 | + */ |
|
| 4848 | + public function callback_column($column ,$callback = null) |
|
| 4849 | + { |
|
| 4850 | + $this->callback_column[$column] = $callback; |
|
| 4851 | + |
|
| 4852 | + return $this; |
|
| 4853 | + } |
|
| 4854 | + |
|
| 4855 | + /** |
|
| 4856 | + * |
|
| 4857 | + * Enter description here ... |
|
| 4858 | + * @param string $field |
|
| 4859 | + * @param mixed $callback |
|
| 4860 | + */ |
|
| 4861 | + public function callback_field($field, $callback = null) |
|
| 4862 | + { |
|
| 4863 | + $this->callback_add_field[$field] = $callback; |
|
| 4864 | + $this->callback_edit_field[$field] = $callback; |
|
| 4865 | + |
|
| 4866 | + return $this; |
|
| 4867 | + } |
|
| 4868 | + |
|
| 4869 | + /** |
|
| 4870 | + * |
|
| 4871 | + * Enter description here ... |
|
| 4872 | + * @param string $field |
|
| 4873 | + * @param mixed $callback |
|
| 4874 | + */ |
|
| 4875 | + public function callback_add_field($field, $callback = null) |
|
| 4876 | + { |
|
| 4877 | + $this->callback_add_field[$field] = $callback; |
|
| 4878 | + |
|
| 4879 | + return $this; |
|
| 4880 | + } |
|
| 4881 | + |
|
| 4882 | + /** |
|
| 4883 | + * |
|
| 4884 | + * Enter description here ... |
|
| 4885 | + * @param string $field |
|
| 4886 | + * @param mixed $callback |
|
| 4887 | + */ |
|
| 4888 | + public function callback_edit_field($field, $callback = null) |
|
| 4889 | + { |
|
| 4890 | + $this->callback_edit_field[$field] = $callback; |
|
| 4891 | + |
|
| 4892 | + return $this; |
|
| 4893 | + } |
|
| 4894 | + |
|
| 4895 | + /** |
|
| 4896 | + * |
|
| 4897 | + * Callback that replace the default auto uploader |
|
| 4898 | + * |
|
| 4899 | + * @param mixed $callback |
|
| 4900 | + * @return grocery_CRUD |
|
| 4901 | + */ |
|
| 4902 | + public function callback_upload($callback = null) |
|
| 4903 | + { |
|
| 4904 | + $this->callback_upload = $callback; |
|
| 4905 | + |
|
| 4906 | + return $this; |
|
| 4907 | + } |
|
| 4908 | + |
|
| 4909 | + /** |
|
| 4910 | + * |
|
| 4911 | + * A callback that triggered before the upload functionality. This callback is suggested for validation checks |
|
| 4912 | + * @param mixed $callback |
|
| 4913 | + * @return grocery_CRUD |
|
| 4914 | + */ |
|
| 4915 | + public function callback_before_upload($callback = null) |
|
| 4916 | + { |
|
| 4917 | + $this->callback_before_upload = $callback; |
|
| 4918 | + |
|
| 4919 | + return $this; |
|
| 4920 | + } |
|
| 4921 | + |
|
| 4922 | + /** |
|
| 4923 | + * |
|
| 4924 | + * A callback that triggered after the upload functionality |
|
| 4925 | + * @param mixed $callback |
|
| 4926 | + * @return grocery_CRUD |
|
| 4927 | + */ |
|
| 4928 | + public function callback_after_upload($callback = null) |
|
| 4929 | + { |
|
| 4930 | + $this->callback_after_upload = $callback; |
|
| 4931 | + |
|
| 4932 | + return $this; |
|
| 4933 | + |
|
| 4934 | + } |
|
| 4935 | + |
|
| 4936 | + /** |
|
| 4937 | + * |
|
| 4938 | + * Gets the basic database table of our crud. |
|
| 4939 | + * @return string |
|
| 4940 | + */ |
|
| 4941 | + public function get_table() |
|
| 4942 | + { |
|
| 4943 | + if($this->basic_db_table_checked) |
|
| 4944 | + { |
|
| 4945 | + return $this->basic_db_table; |
|
| 4946 | + } |
|
| 4947 | + elseif( $this->basic_db_table !== null ) |
|
| 4948 | + { |
|
| 4949 | + if(!$this->table_exists($this->basic_db_table)) |
|
| 4950 | + { |
|
| 4951 | + throw new Exception('The table name does not exist. Please check you database and try again.',11); |
|
| 4952 | + die(); |
|
| 4953 | + } |
|
| 4954 | + $this->basic_db_table_checked = true; |
|
| 4955 | + return $this->basic_db_table; |
|
| 4956 | + } |
|
| 4957 | + else |
|
| 4958 | + { |
|
| 4959 | + //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
|
| 4960 | + $last_chance_table_name = $this->get_method_name(); |
|
| 4961 | + if($this->table_exists($last_chance_table_name)) |
|
| 4962 | + { |
|
| 4963 | + $this->set_table($last_chance_table_name); |
|
| 4964 | + } |
|
| 4965 | + $this->basic_db_table_checked = true; |
|
| 4966 | + return $this->basic_db_table; |
|
| 4967 | + |
|
| 4968 | + } |
|
| 4969 | + |
|
| 4970 | + return false; |
|
| 4971 | + } |
|
| 4972 | + |
|
| 4973 | + /** |
|
| 4974 | + * |
|
| 4975 | + * The field names of the required fields |
|
| 4976 | + */ |
|
| 4977 | + public function required_fields() |
|
| 4978 | + { |
|
| 4979 | + $args = func_get_args(); |
|
| 4980 | + |
|
| 4981 | + if(isset($args[0]) && is_array($args[0])) |
|
| 4982 | + { |
|
| 4983 | + $args = $args[0]; |
|
| 4984 | + } |
|
| 4985 | + |
|
| 4986 | + $this->required_fields = $args; |
|
| 4987 | + |
|
| 4988 | + return $this; |
|
| 4989 | + } |
|
| 4990 | + |
|
| 4991 | + /** |
|
| 4992 | + * Add the fields that they are as UNIQUE in the database structure |
|
| 4993 | + * |
|
| 4994 | + * @return grocery_CRUD |
|
| 4995 | + */ |
|
| 4996 | + public function unique_fields() |
|
| 4997 | + { |
|
| 4998 | + $args = func_get_args(); |
|
| 4999 | + |
|
| 5000 | + if(isset($args[0]) && is_array($args[0])) |
|
| 5001 | + { |
|
| 5002 | + $args = $args[0]; |
|
| 5003 | + } |
|
| 5004 | + |
|
| 5005 | + $this->_unique_fields = $args; |
|
| 5006 | + |
|
| 5007 | + return $this; |
|
| 5008 | + } |
|
| 5009 | + |
|
| 5010 | + /** |
|
| 5011 | + * |
|
| 5012 | + * Sets the basic database table that we will get our data. |
|
| 5013 | + * @param string $table_name |
|
| 5014 | + * @return grocery_CRUD |
|
| 5015 | + */ |
|
| 5016 | + public function set_table($table_name) |
|
| 5017 | + { |
|
| 5018 | + if(!empty($table_name) && $this->basic_db_table === null) |
|
| 5019 | + { |
|
| 5020 | + $this->basic_db_table = $table_name; |
|
| 5021 | + } |
|
| 5022 | + elseif(!empty($table_name)) |
|
| 5023 | + { |
|
| 5024 | + throw new Exception('You have already insert a table name once...', 1); |
|
| 5025 | + } |
|
| 5026 | + else |
|
| 5027 | + { |
|
| 5028 | + throw new Exception('The table name cannot be empty.', 2); |
|
| 5029 | + die(); |
|
| 5030 | + } |
|
| 5031 | + |
|
| 5032 | + return $this; |
|
| 5033 | + } |
|
| 5034 | + |
|
| 5035 | + /** |
|
| 5036 | + * Set a full URL path to this method. |
|
| 5037 | + * |
|
| 5038 | + * This method is useful when the path is not specified correctly. |
|
| 5039 | + * Especially when we are using routes. |
|
| 5040 | + * For example: |
|
| 5041 | + * Let's say we have the path http://www.example.com/ however the original url path is |
|
| 5042 | + * http://www.example.com/example/index . We have to specify the url so we can have |
|
| 5043 | + * all the CRUD operations correctly. |
|
| 5044 | + * The url path has to be set from this method like this: |
|
| 5045 | + * <code> |
|
| 5046 | + * $crud->set_crud_url_path(site_url('example/index')); |
|
| 5047 | + * </code> |
|
| 5048 | + * |
|
| 5049 | + * @param string $crud_url_path |
|
| 5050 | + * @param string $list_url_path |
|
| 5051 | + * @return grocery_CRUD |
|
| 5052 | + */ |
|
| 5053 | + public function set_crud_url_path($crud_url_path, $list_url_path = null) |
|
| 5054 | + { |
|
| 5055 | + $this->crud_url_path = $crud_url_path; |
|
| 5056 | + |
|
| 5057 | + //If the list_url_path is empty so we are guessing that the list_url_path |
|
| 5058 | + //will be the same with crud_url_path |
|
| 5059 | + $this->list_url_path = !empty($list_url_path) ? $list_url_path : $crud_url_path; |
|
| 5060 | + |
|
| 5061 | + return $this; |
|
| 5062 | + } |
|
| 5063 | + |
|
| 5064 | + /** |
|
| 5065 | + * |
|
| 5066 | + * Set a subject to understand what type of CRUD you use. |
|
| 5067 | 5067 | * ---------------------------------------------------------------------------------------------- |
| 5068 | 5068 | * Subject_plural: Sets the subject to its plural form. For example the plural |
| 5069 | 5069 | * of "Customer" is "Customers", "Product" is "Products"... e.t.c. |
| 5070 | - * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' |
|
| 5070 | + * @example In this CRUD we work with the table db_categories. The $subject will be the 'Category' |
|
| 5071 | 5071 | * and the $subject_plural will be 'Categories' |
| 5072 | - * @param string $subject |
|
| 5073 | - * @param string $subject_plural |
|
| 5074 | - * @return grocery_CRUD |
|
| 5075 | - */ |
|
| 5076 | - public function set_subject($subject, $subject_plural = null) |
|
| 5077 | - { |
|
| 5078 | - $this->subject = $subject; |
|
| 5072 | + * @param string $subject |
|
| 5073 | + * @param string $subject_plural |
|
| 5074 | + * @return grocery_CRUD |
|
| 5075 | + */ |
|
| 5076 | + public function set_subject($subject, $subject_plural = null) |
|
| 5077 | + { |
|
| 5078 | + $this->subject = $subject; |
|
| 5079 | 5079 | $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; |
| 5080 | 5080 | |
| 5081 | - return $this; |
|
| 5082 | - } |
|
| 5083 | - |
|
| 5084 | - /** |
|
| 5085 | - * |
|
| 5086 | - * Enter description here ... |
|
| 5087 | - * @param $title |
|
| 5088 | - * @param $image_url |
|
| 5089 | - * @param $url |
|
| 5090 | - * @param $css_class |
|
| 5091 | - * @param $url_callback |
|
| 5092 | - */ |
|
| 5093 | - public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
| 5094 | - { |
|
| 5095 | - $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string |
|
| 5096 | - |
|
| 5097 | - $this->actions[$unique_id] = (object)array( |
|
| 5098 | - 'label' => $label, |
|
| 5099 | - 'image_url' => $image_url, |
|
| 5100 | - 'link_url' => $link_url, |
|
| 5101 | - 'css_class' => $css_class, |
|
| 5102 | - 'url_callback' => $url_callback, |
|
| 5103 | - 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false |
|
| 5104 | - ); |
|
| 5105 | - |
|
| 5106 | - return $this; |
|
| 5107 | - } |
|
| 5108 | - |
|
| 5109 | - /** |
|
| 5110 | - * |
|
| 5111 | - * Set a simple 1-n foreign key relation |
|
| 5112 | - * @param string $field_name |
|
| 5113 | - * @param string $related_table |
|
| 5114 | - * @param string $related_title_field |
|
| 5115 | - * @param mixed $where_clause |
|
| 5116 | - * @param string $order_by |
|
| 5081 | + return $this; |
|
| 5082 | + } |
|
| 5083 | + |
|
| 5084 | + /** |
|
| 5085 | + * |
|
| 5086 | + * Enter description here ... |
|
| 5087 | + * @param $title |
|
| 5088 | + * @param $image_url |
|
| 5089 | + * @param $url |
|
| 5090 | + * @param $css_class |
|
| 5091 | + * @param $url_callback |
|
| 5092 | + */ |
|
| 5093 | + public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
| 5094 | + { |
|
| 5095 | + $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string |
|
| 5096 | + |
|
| 5097 | + $this->actions[$unique_id] = (object)array( |
|
| 5098 | + 'label' => $label, |
|
| 5099 | + 'image_url' => $image_url, |
|
| 5100 | + 'link_url' => $link_url, |
|
| 5101 | + 'css_class' => $css_class, |
|
| 5102 | + 'url_callback' => $url_callback, |
|
| 5103 | + 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false |
|
| 5104 | + ); |
|
| 5105 | + |
|
| 5106 | + return $this; |
|
| 5107 | + } |
|
| 5108 | + |
|
| 5109 | + /** |
|
| 5110 | + * |
|
| 5111 | + * Set a simple 1-n foreign key relation |
|
| 5112 | + * @param string $field_name |
|
| 5113 | + * @param string $related_table |
|
| 5114 | + * @param string $related_title_field |
|
| 5115 | + * @param mixed $where_clause |
|
| 5116 | + * @param string $order_by |
|
| 5117 | 5117 | * @return Grocery_CRUD |
| 5118 | - */ |
|
| 5119 | - public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
| 5120 | - { |
|
| 5121 | - $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); |
|
| 5122 | - return $this; |
|
| 5123 | - } |
|
| 5124 | - |
|
| 5125 | - /** |
|
| 5126 | - * |
|
| 5127 | - * Sets a relation with n-n relationship. |
|
| 5128 | - * @param string $field_name |
|
| 5129 | - * @param string $relation_table |
|
| 5130 | - * @param string $selection_table |
|
| 5131 | - * @param string $primary_key_alias_to_this_table |
|
| 5132 | - * @param string $primary_key_alias_to_selection_table |
|
| 5133 | - * @param string $title_field_selection_table |
|
| 5134 | - * @param string $priority_field_relation_table |
|
| 5135 | - * @param mixed $where_clause |
|
| 5118 | + */ |
|
| 5119 | + public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
| 5120 | + { |
|
| 5121 | + $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); |
|
| 5122 | + return $this; |
|
| 5123 | + } |
|
| 5124 | + |
|
| 5125 | + /** |
|
| 5126 | + * |
|
| 5127 | + * Sets a relation with n-n relationship. |
|
| 5128 | + * @param string $field_name |
|
| 5129 | + * @param string $relation_table |
|
| 5130 | + * @param string $selection_table |
|
| 5131 | + * @param string $primary_key_alias_to_this_table |
|
| 5132 | + * @param string $primary_key_alias_to_selection_table |
|
| 5133 | + * @param string $title_field_selection_table |
|
| 5134 | + * @param string $priority_field_relation_table |
|
| 5135 | + * @param mixed $where_clause |
|
| 5136 | 5136 | * @return Grocery_CRUD |
| 5137 | - */ |
|
| 5138 | - public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) |
|
| 5139 | - { |
|
| 5140 | - $this->relation_n_n[$field_name] = |
|
| 5141 | - (object)array( |
|
| 5142 | - 'field_name' => $field_name, |
|
| 5143 | - 'relation_table' => $relation_table, |
|
| 5144 | - 'selection_table' => $selection_table, |
|
| 5145 | - 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, |
|
| 5146 | - 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , |
|
| 5147 | - 'title_field_selection_table' => $title_field_selection_table , |
|
| 5148 | - 'priority_field_relation_table' => $priority_field_relation_table, |
|
| 5149 | - 'where_clause' => $where_clause |
|
| 5150 | - ); |
|
| 5151 | - |
|
| 5152 | - return $this; |
|
| 5153 | - } |
|
| 5154 | - |
|
| 5155 | - /** |
|
| 5156 | - * |
|
| 5157 | - * Transform a field to an upload field |
|
| 5158 | - * |
|
| 5159 | - * @param string $field_name |
|
| 5160 | - * @param string $upload_path |
|
| 5137 | + */ |
|
| 5138 | + public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) |
|
| 5139 | + { |
|
| 5140 | + $this->relation_n_n[$field_name] = |
|
| 5141 | + (object)array( |
|
| 5142 | + 'field_name' => $field_name, |
|
| 5143 | + 'relation_table' => $relation_table, |
|
| 5144 | + 'selection_table' => $selection_table, |
|
| 5145 | + 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, |
|
| 5146 | + 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , |
|
| 5147 | + 'title_field_selection_table' => $title_field_selection_table , |
|
| 5148 | + 'priority_field_relation_table' => $priority_field_relation_table, |
|
| 5149 | + 'where_clause' => $where_clause |
|
| 5150 | + ); |
|
| 5151 | + |
|
| 5152 | + return $this; |
|
| 5153 | + } |
|
| 5154 | + |
|
| 5155 | + /** |
|
| 5156 | + * |
|
| 5157 | + * Transform a field to an upload field |
|
| 5158 | + * |
|
| 5159 | + * @param string $field_name |
|
| 5160 | + * @param string $upload_path |
|
| 5161 | 5161 | * @return Grocery_CRUD |
| 5162 | - */ |
|
| 5163 | - public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
|
| 5164 | - { |
|
| 5165 | - $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' |
|
| 5166 | - ? substr($upload_dir,0,-1) |
|
| 5167 | - : $upload_dir; |
|
| 5168 | - $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; |
|
| 5169 | - |
|
| 5170 | - /** Check if the upload Url folder exists. If not then throw an exception **/ |
|
| 5171 | - if (!is_dir(FCPATH.$upload_dir)) { |
|
| 5172 | - throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name |
|
| 5162 | + */ |
|
| 5163 | + public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
|
| 5164 | + { |
|
| 5165 | + $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' |
|
| 5166 | + ? substr($upload_dir,0,-1) |
|
| 5167 | + : $upload_dir; |
|
| 5168 | + $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; |
|
| 5169 | + |
|
| 5170 | + /** Check if the upload Url folder exists. If not then throw an exception **/ |
|
| 5171 | + if (!is_dir(FCPATH.$upload_dir)) { |
|
| 5172 | + throw new Exception("It seems that the folder \"".FCPATH.$upload_dir."\" for the field name |
|
| 5173 | 5173 | \"".$field_name."\" doesn't exists. Please create the folder and try again."); |
| 5174 | - } |
|
| 5175 | - |
|
| 5176 | - $this->upload_fields[$field_name] = (object) array( |
|
| 5177 | - 'field_name' => $field_name, |
|
| 5178 | - 'upload_path' => $upload_dir, |
|
| 5179 | - 'allowed_file_types' => $allowed_file_types, |
|
| 5180 | - 'encrypted_field_name' => $this->_unique_field_name($field_name)); |
|
| 5181 | - return $this; |
|
| 5182 | - } |
|
| 5174 | + } |
|
| 5175 | + |
|
| 5176 | + $this->upload_fields[$field_name] = (object) array( |
|
| 5177 | + 'field_name' => $field_name, |
|
| 5178 | + 'upload_path' => $upload_dir, |
|
| 5179 | + 'allowed_file_types' => $allowed_file_types, |
|
| 5180 | + 'encrypted_field_name' => $this->_unique_field_name($field_name)); |
|
| 5181 | + return $this; |
|
| 5182 | + } |
|
| 5183 | 5183 | } |
| 5184 | 5184 | |
| 5185 | 5185 | if(defined('CI_VERSION')) |
| 5186 | 5186 | { |
| 5187 | - $ci = &get_instance(); |
|
| 5188 | - $ci->load->library('Form_validation'); |
|
| 5189 | - |
|
| 5190 | - class grocery_CRUD_Form_validation extends CI_Form_validation{ |
|
| 5191 | - |
|
| 5192 | - public $CI; |
|
| 5193 | - public $_field_data = array(); |
|
| 5194 | - public $_config_rules = array(); |
|
| 5195 | - public $_error_array = array(); |
|
| 5196 | - public $_error_messages = array(); |
|
| 5197 | - public $_error_prefix = '<p>'; |
|
| 5198 | - public $_error_suffix = '</p>'; |
|
| 5199 | - public $error_string = ''; |
|
| 5200 | - public $_safe_form_data = FALSE; |
|
| 5201 | - } |
|
| 5187 | + $ci = &get_instance(); |
|
| 5188 | + $ci->load->library('Form_validation'); |
|
| 5189 | + |
|
| 5190 | + class grocery_CRUD_Form_validation extends CI_Form_validation{ |
|
| 5191 | + |
|
| 5192 | + public $CI; |
|
| 5193 | + public $_field_data = array(); |
|
| 5194 | + public $_config_rules = array(); |
|
| 5195 | + public $_error_array = array(); |
|
| 5196 | + public $_error_messages = array(); |
|
| 5197 | + public $_error_prefix = '<p>'; |
|
| 5198 | + public $_error_suffix = '</p>'; |
|
| 5199 | + public $error_string = ''; |
|
| 5200 | + public $_safe_form_data = FALSE; |
|
| 5201 | + } |
|
| 5202 | 5202 | } |
| 5203 | 5203 | |
| 5204 | 5204 | /* |
@@ -5258,19 +5258,19 @@ discard block |
||
| 5258 | 5258 | // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); |
| 5259 | 5259 | foreach($options as $option_name => $option) |
| 5260 | 5260 | { |
| 5261 | - $this->options[$option_name] = $option; |
|
| 5261 | + $this->options[$option_name] = $option; |
|
| 5262 | 5262 | } |
| 5263 | 5263 | } |
| 5264 | 5264 | } |
| 5265 | 5265 | |
| 5266 | 5266 | function getFullUrl() { |
| 5267 | - return |
|
| 5268 | - (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). |
|
| 5269 | - (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). |
|
| 5270 | - (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
|
| 5271 | - (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || |
|
| 5272 | - $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
|
| 5273 | - substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
| 5267 | + return |
|
| 5268 | + (isset($_SERVER['HTTPS']) ? 'https://' : 'http://'). |
|
| 5269 | + (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'].'@' : ''). |
|
| 5270 | + (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
|
| 5271 | + (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || |
|
| 5272 | + $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
|
| 5273 | + substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
| 5274 | 5274 | } |
| 5275 | 5275 | |
| 5276 | 5276 | private function get_file_object($file_name) { |
@@ -5356,26 +5356,26 @@ discard block |
||
| 5356 | 5356 | |
| 5357 | 5357 | private function has_error($uploaded_file, $file, $error) { |
| 5358 | 5358 | if ($error) { |
| 5359 | - switch($error) { |
|
| 5360 | - case UPLOAD_ERR_INI_SIZE: |
|
| 5361 | - return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
| 5362 | - break; |
|
| 5363 | - case UPLOAD_ERR_PARTIAL: |
|
| 5364 | - return 'The uploaded file was only partially uploaded.'; |
|
| 5365 | - break; |
|
| 5366 | - case UPLOAD_ERR_NO_FILE: |
|
| 5367 | - return 'No file was uploaded.'; |
|
| 5368 | - break; |
|
| 5369 | - case UPLOAD_ERR_CANT_WRITE: |
|
| 5370 | - return 'Failed to write file to disk.'; |
|
| 5371 | - break; |
|
| 5372 | - case UPLOAD_ERR_EXTENSION: |
|
| 5373 | - return 'File upload stopped by extension.'; |
|
| 5374 | - break; |
|
| 5375 | - default: |
|
| 5376 | - return $error; |
|
| 5377 | - break; |
|
| 5378 | - } |
|
| 5359 | + switch($error) { |
|
| 5360 | + case UPLOAD_ERR_INI_SIZE: |
|
| 5361 | + return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
|
| 5362 | + break; |
|
| 5363 | + case UPLOAD_ERR_PARTIAL: |
|
| 5364 | + return 'The uploaded file was only partially uploaded.'; |
|
| 5365 | + break; |
|
| 5366 | + case UPLOAD_ERR_NO_FILE: |
|
| 5367 | + return 'No file was uploaded.'; |
|
| 5368 | + break; |
|
| 5369 | + case UPLOAD_ERR_CANT_WRITE: |
|
| 5370 | + return 'Failed to write file to disk.'; |
|
| 5371 | + break; |
|
| 5372 | + case UPLOAD_ERR_EXTENSION: |
|
| 5373 | + return 'File upload stopped by extension.'; |
|
| 5374 | + break; |
|
| 5375 | + default: |
|
| 5376 | + return $error; |
|
| 5377 | + break; |
|
| 5378 | + } |
|
| 5379 | 5379 | } |
| 5380 | 5380 | if (!preg_match($this->options['accept_file_types'], $file->name)) { |
| 5381 | 5381 | return 'acceptFileTypes'; |
@@ -5425,43 +5425,43 @@ discard block |
||
| 5425 | 5425 | } |
| 5426 | 5426 | |
| 5427 | 5427 | private function _transliterate_characters($file_name) |
| 5428 | - { |
|
| 5429 | - include($this->default_config_path.'/translit_chars.php'); |
|
| 5430 | - if ( isset($translit_characters)) |
|
| 5431 | - { |
|
| 5432 | - $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); |
|
| 5433 | - } |
|
| 5428 | + { |
|
| 5429 | + include($this->default_config_path.'/translit_chars.php'); |
|
| 5430 | + if ( isset($translit_characters)) |
|
| 5431 | + { |
|
| 5432 | + $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); |
|
| 5433 | + } |
|
| 5434 | 5434 | |
| 5435 | - $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); |
|
| 5436 | - $file_name = str_replace(" ", "-", $file_name); |
|
| 5435 | + $file_name = preg_replace("/([^a-zA-Z0-9\.\-\_]+?){1}/i", '-', $file_name); |
|
| 5436 | + $file_name = str_replace(" ", "-", $file_name); |
|
| 5437 | 5437 | |
| 5438 | - return preg_replace('/\-+/', '-', trim($file_name, '-')); |
|
| 5439 | - } |
|
| 5438 | + return preg_replace('/\-+/', '-', trim($file_name, '-')); |
|
| 5439 | + } |
|
| 5440 | 5440 | |
| 5441 | 5441 | private function orient_image($file_path) { |
| 5442 | - $exif = exif_read_data($file_path); |
|
| 5443 | - $orientation = intval(@$exif['Orientation']); |
|
| 5444 | - if (!in_array($orientation, array(3, 6, 8))) { |
|
| 5445 | - return false; |
|
| 5446 | - } |
|
| 5447 | - $image = @imagecreatefromjpeg($file_path); |
|
| 5448 | - switch ($orientation) { |
|
| 5449 | - case 3: |
|
| 5450 | - $image = @imagerotate($image, 180, 0); |
|
| 5451 | - break; |
|
| 5452 | - case 6: |
|
| 5453 | - $image = @imagerotate($image, 270, 0); |
|
| 5454 | - break; |
|
| 5455 | - case 8: |
|
| 5456 | - $image = @imagerotate($image, 90, 0); |
|
| 5457 | - break; |
|
| 5458 | - default: |
|
| 5459 | - return false; |
|
| 5460 | - } |
|
| 5461 | - $success = imagejpeg($image, $file_path); |
|
| 5462 | - // Free up memory (imagedestroy does not delete files): |
|
| 5463 | - @imagedestroy($image); |
|
| 5464 | - return $success; |
|
| 5442 | + $exif = exif_read_data($file_path); |
|
| 5443 | + $orientation = intval(@$exif['Orientation']); |
|
| 5444 | + if (!in_array($orientation, array(3, 6, 8))) { |
|
| 5445 | + return false; |
|
| 5446 | + } |
|
| 5447 | + $image = @imagecreatefromjpeg($file_path); |
|
| 5448 | + switch ($orientation) { |
|
| 5449 | + case 3: |
|
| 5450 | + $image = @imagerotate($image, 180, 0); |
|
| 5451 | + break; |
|
| 5452 | + case 6: |
|
| 5453 | + $image = @imagerotate($image, 270, 0); |
|
| 5454 | + break; |
|
| 5455 | + case 8: |
|
| 5456 | + $image = @imagerotate($image, 90, 0); |
|
| 5457 | + break; |
|
| 5458 | + default: |
|
| 5459 | + return false; |
|
| 5460 | + } |
|
| 5461 | + $success = imagejpeg($image, $file_path); |
|
| 5462 | + // Free up memory (imagedestroy does not delete files): |
|
| 5463 | + @imagedestroy($image); |
|
| 5464 | + return $success; |
|
| 5465 | 5465 | } |
| 5466 | 5466 | |
| 5467 | 5467 | private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { |
@@ -5496,9 +5496,9 @@ discard block |
||
| 5496 | 5496 | } |
| 5497 | 5497 | $file_size = filesize($file_path); |
| 5498 | 5498 | if ($file_size === $file->size) { |
| 5499 | - if ($this->options['orient_image']) { |
|
| 5500 | - $this->orient_image($file_path); |
|
| 5501 | - } |
|
| 5499 | + if ($this->options['orient_image']) { |
|
| 5500 | + $this->orient_image($file_path); |
|
| 5501 | + } |
|
| 5502 | 5502 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
| 5503 | 5503 | foreach($this->options['image_versions'] as $version => $options) { |
| 5504 | 5504 | if ($this->create_scaled_image($file->name, $options)) { |
@@ -44,19 +44,18 @@ discard block |
||
| 44 | 44 | return $this->field_types; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - $types = array(); |
|
| 48 | - foreach($this->basic_model->get_field_types_basic_table() as $field_info) |
|
| 47 | + $types = array(); |
|
| 48 | + foreach ($this->basic_model->get_field_types_basic_table() as $field_info) |
|
| 49 | 49 | { |
| 50 | - $field_info->required = !empty($this->required_fields) && in_array($field_info->name,$this->required_fields) ? true : false; |
|
| 50 | + $field_info->required = !empty($this->required_fields) && in_array($field_info->name, $this->required_fields) ? true : false; |
|
| 51 | 51 | |
| 52 | 52 | $field_info->display_as = |
| 53 | 53 | isset($this->display_as[$field_info->name]) ? |
| 54 | - $this->display_as[$field_info->name] : |
|
| 55 | - ucfirst(str_replace("_"," ",$field_info->name)); |
|
| 54 | + $this->display_as[$field_info->name] : ucfirst(str_replace("_", " ", $field_info->name)); |
|
| 56 | 55 | |
| 57 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
| 56 | + if ($this->change_field_type !== null && isset($this->change_field_type[$field_info->name])) |
|
| 58 | 57 | { |
| 59 | - $field_type = $this->change_field_type[$field_info->name]; |
|
| 58 | + $field_type = $this->change_field_type[$field_info->name]; |
|
| 60 | 59 | |
| 61 | 60 | if (isset($this->relation[$field_info->name])) { |
| 62 | 61 | $field_info->crud_type = "relation_".$field_type->type; |
@@ -64,21 +63,21 @@ discard block |
||
| 64 | 63 | elseif (isset($this->upload_fields[$field_info->name])) { |
| 65 | 64 | $field_info->crud_type = "upload_file_".$field_type->type; |
| 66 | 65 | } else { |
| 67 | - $field_info->crud_type = $field_type->type; |
|
| 68 | - $field_info->extras = $field_type->extras; |
|
| 66 | + $field_info->crud_type = $field_type->type; |
|
| 67 | + $field_info->extras = $field_type->extras; |
|
| 69 | 68 | } |
| 70 | 69 | |
| 71 | - $real_type = $field_info->crud_type; |
|
| 70 | + $real_type = $field_info->crud_type; |
|
| 72 | 71 | } |
| 73 | - elseif(isset($this->relation[$field_info->name])) |
|
| 72 | + elseif (isset($this->relation[$field_info->name])) |
|
| 74 | 73 | { |
| 75 | - $real_type = 'relation'; |
|
| 76 | - $field_info->crud_type = 'relation'; |
|
| 74 | + $real_type = 'relation'; |
|
| 75 | + $field_info->crud_type = 'relation'; |
|
| 77 | 76 | } |
| 78 | - elseif(isset($this->upload_fields[$field_info->name])) |
|
| 77 | + elseif (isset($this->upload_fields[$field_info->name])) |
|
| 79 | 78 | { |
| 80 | - $real_type = 'upload_file'; |
|
| 81 | - $field_info->crud_type = 'upload_file'; |
|
| 79 | + $real_type = 'upload_file'; |
|
| 80 | + $field_info->crud_type = 'upload_file'; |
|
| 82 | 81 | } |
| 83 | 82 | else |
| 84 | 83 | { |
@@ -88,7 +87,7 @@ discard block |
||
| 88 | 87 | |
| 89 | 88 | switch ($real_type) { |
| 90 | 89 | case 'text': |
| 91 | - if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
| 90 | + if (!empty($this->unset_texteditor) && in_array($field_info->name, $this->unset_texteditor)) |
|
| 92 | 91 | $field_info->extras = false; |
| 93 | 92 | else |
| 94 | 93 | $field_info->extras = 'text_editor'; |
@@ -96,16 +95,16 @@ discard block |
||
| 96 | 95 | |
| 97 | 96 | case 'relation': |
| 98 | 97 | case 'relation_readonly': |
| 99 | - $field_info->extras = $this->relation[$field_info->name]; |
|
| 98 | + $field_info->extras = $this->relation[$field_info->name]; |
|
| 100 | 99 | break; |
| 101 | 100 | |
| 102 | 101 | case 'upload_file': |
| 103 | 102 | case 'upload_file_readonly': |
| 104 | - $field_info->extras = $this->upload_fields[$field_info->name]; |
|
| 103 | + $field_info->extras = $this->upload_fields[$field_info->name]; |
|
| 105 | 104 | break; |
| 106 | 105 | |
| 107 | 106 | default: |
| 108 | - if(empty($field_info->extras)) |
|
| 107 | + if (empty($field_info->extras)) |
|
| 109 | 108 | $field_info->extras = false; |
| 110 | 109 | break; |
| 111 | 110 | } |
@@ -113,51 +112,48 @@ discard block |
||
| 113 | 112 | $types[$field_info->name] = $field_info; |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | - if(!empty($this->relation_n_n)) |
|
| 115 | + if (!empty($this->relation_n_n)) |
|
| 117 | 116 | { |
| 118 | - foreach($this->relation_n_n as $field_name => $field_extras) |
|
| 117 | + foreach ($this->relation_n_n as $field_name => $field_extras) |
|
| 119 | 118 | { |
| 120 | 119 | $is_read_only = $this->change_field_type !== null |
| 121 | 120 | && isset($this->change_field_type[$field_name]) |
| 122 | 121 | && $this->change_field_type[$field_name]->type == 'readonly' |
| 123 | 122 | ? true : false; |
| 124 | - $field_info = (object)array(); |
|
| 125 | - $field_info->name = $field_name; |
|
| 123 | + $field_info = (object) array(); |
|
| 124 | + $field_info->name = $field_name; |
|
| 126 | 125 | $field_info->crud_type = $is_read_only ? 'readonly' : 'relation_n_n'; |
| 127 | - $field_info->extras = $field_extras; |
|
| 128 | - $field_info->required = !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false;; |
|
| 126 | + $field_info->extras = $field_extras; |
|
| 127 | + $field_info->required = !empty($this->required_fields) && in_array($field_name, $this->required_fields) ? true : false; ; |
|
| 129 | 128 | $field_info->display_as = |
| 130 | 129 | isset($this->display_as[$field_name]) ? |
| 131 | - $this->display_as[$field_name] : |
|
| 132 | - ucfirst(str_replace("_"," ",$field_name)); |
|
| 130 | + $this->display_as[$field_name] : ucfirst(str_replace("_", " ", $field_name)); |
|
| 133 | 131 | |
| 134 | 132 | $types[$field_name] = $field_info; |
| 135 | 133 | } |
| 136 | 134 | } |
| 137 | 135 | |
| 138 | - if(!empty($this->add_fields)) |
|
| 139 | - foreach($this->add_fields as $field_object) |
|
| 136 | + if (!empty($this->add_fields)) |
|
| 137 | + foreach ($this->add_fields as $field_object) |
|
| 140 | 138 | { |
| 141 | 139 | $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
| 142 | 140 | |
| 143 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 141 | + if (!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 144 | 142 | { |
| 145 | 143 | $extras = false; |
| 146 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 144 | + if ($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 147 | 145 | { |
| 148 | 146 | $field_type = $this->change_field_type[$field_name]; |
| 149 | - $extras = $field_type->extras; |
|
| 147 | + $extras = $field_type->extras; |
|
| 150 | 148 | } |
| 151 | 149 | |
| 152 | - $field_info = (object)array( |
|
| 150 | + $field_info = (object) array( |
|
| 153 | 151 | 'name' => $field_name, |
| 154 | 152 | 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
| 155 | - $this->change_field_type[$field_name]->type : |
|
| 156 | - 'string', |
|
| 153 | + $this->change_field_type[$field_name]->type : 'string', |
|
| 157 | 154 | 'display_as' => isset($this->display_as[$field_name]) ? |
| 158 | - $this->display_as[$field_name] : |
|
| 159 | - ucfirst(str_replace("_"," ",$field_name)), |
|
| 160 | - 'required' => !empty($this->required_fields) && in_array($field_name,$this->required_fields) ? true : false, |
|
| 155 | + $this->display_as[$field_name] : ucfirst(str_replace("_", " ", $field_name)), |
|
| 156 | + 'required' => !empty($this->required_fields) && in_array($field_name, $this->required_fields) ? true : false, |
|
| 161 | 157 | 'extras' => $extras |
| 162 | 158 | ); |
| 163 | 159 | |
@@ -165,29 +161,27 @@ discard block |
||
| 165 | 161 | } |
| 166 | 162 | } |
| 167 | 163 | |
| 168 | - if(!empty($this->edit_fields)) |
|
| 169 | - foreach($this->edit_fields as $field_object) |
|
| 164 | + if (!empty($this->edit_fields)) |
|
| 165 | + foreach ($this->edit_fields as $field_object) |
|
| 170 | 166 | { |
| 171 | 167 | $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
| 172 | 168 | |
| 173 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 169 | + if (!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 174 | 170 | { |
| 175 | 171 | $extras = false; |
| 176 | - if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 172 | + if ($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
|
| 177 | 173 | { |
| 178 | 174 | $field_type = $this->change_field_type[$field_name]; |
| 179 | - $extras = $field_type->extras; |
|
| 175 | + $extras = $field_type->extras; |
|
| 180 | 176 | } |
| 181 | 177 | |
| 182 | - $field_info = (object)array( |
|
| 178 | + $field_info = (object) array( |
|
| 183 | 179 | 'name' => $field_name, |
| 184 | 180 | 'crud_type' => $this->change_field_type !== null && isset($this->change_field_type[$field_name]) ? |
| 185 | - $this->change_field_type[$field_name]->type : |
|
| 186 | - 'string', |
|
| 181 | + $this->change_field_type[$field_name]->type : 'string', |
|
| 187 | 182 | 'display_as' => isset($this->display_as[$field_name]) ? |
| 188 | - $this->display_as[$field_name] : |
|
| 189 | - ucfirst(str_replace("_"," ",$field_name)), |
|
| 190 | - 'required' => in_array($field_name,$this->required_fields) ? true : false, |
|
| 183 | + $this->display_as[$field_name] : ucfirst(str_replace("_", " ", $field_name)), |
|
| 184 | + 'required' => in_array($field_name, $this->required_fields) ? true : false, |
|
| 191 | 185 | 'extras' => $extras |
| 192 | 186 | ); |
| 193 | 187 | |
@@ -238,16 +232,16 @@ discard block |
||
| 238 | 232 | 'multiselect' |
| 239 | 233 | ); |
| 240 | 234 | |
| 241 | - if (in_array($real_type,$types_array)) { |
|
| 235 | + if (in_array($real_type, $types_array)) { |
|
| 242 | 236 | /* A quick way to go to an internal method of type $this->get_{type}_input . |
| 243 | 237 | * For example if the real type is integer then we will use the method |
| 244 | 238 | * $this->get_integer_input |
| 245 | 239 | * */ |
| 246 | - $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
|
| 240 | + $field_info->input = $this->{"get_".$real_type."_input"}($field_info, $value); |
|
| 247 | 241 | } |
| 248 | 242 | else |
| 249 | 243 | { |
| 250 | - $field_info->input = $this->get_string_input($field_info,$value); |
|
| 244 | + $field_info->input = $this->get_string_input($field_info, $value); |
|
| 251 | 245 | } |
| 252 | 246 | |
| 253 | 247 | return $field_info; |
@@ -264,24 +258,24 @@ discard block |
||
| 264 | 258 | |
| 265 | 259 | break; |
| 266 | 260 | case 'true_false': |
| 267 | - if(is_array($field_info->extras) && array_key_exists($value,$field_info->extras)) { |
|
| 261 | + if (is_array($field_info->extras) && array_key_exists($value, $field_info->extras)) { |
|
| 268 | 262 | $value = $field_info->extras[$value]; |
| 269 | - } else if(isset($this->default_true_false_text[$value])) { |
|
| 263 | + } else if (isset($this->default_true_false_text[$value])) { |
|
| 270 | 264 | $value = $this->default_true_false_text[$value]; |
| 271 | 265 | } |
| 272 | 266 | break; |
| 273 | 267 | case 'string': |
| 274 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 268 | + $value = $this->character_limiter($value, $this->character_limiter, "..."); |
|
| 275 | 269 | break; |
| 276 | 270 | case 'text': |
| 277 | - $value = $this->character_limiter(strip_tags($value),$this->character_limiter,"..."); |
|
| 271 | + $value = $this->character_limiter(strip_tags($value), $this->character_limiter, "..."); |
|
| 278 | 272 | break; |
| 279 | 273 | case 'date': |
| 280 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 274 | + if (!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 281 | 275 | { |
| 282 | - list($year,$month,$day) = explode("-",$value); |
|
| 276 | + list($year, $month, $day) = explode("-", $value); |
|
| 283 | 277 | |
| 284 | - $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
|
| 278 | + $value = date($this->php_date_format, mktime(0, 0, 0, (int) $month, (int) $day, (int) $year)); |
|
| 285 | 279 | } |
| 286 | 280 | else |
| 287 | 281 | { |
@@ -289,12 +283,12 @@ discard block |
||
| 289 | 283 | } |
| 290 | 284 | break; |
| 291 | 285 | case 'datetime': |
| 292 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
| 286 | + if (!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') |
|
| 293 | 287 | { |
| 294 | - list($year,$month,$day) = explode("-",$value); |
|
| 295 | - list($hours,$minutes) = explode(":",substr($value,11)); |
|
| 288 | + list($year, $month, $day) = explode("-", $value); |
|
| 289 | + list($hours, $minutes) = explode(":", substr($value, 11)); |
|
| 296 | 290 | |
| 297 | - $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
|
| 291 | + $value = date($this->php_date_format." - H:i", mktime((int) $hours, (int) $minutes, 0, (int) $month, (int) $day, (int) $year)); |
|
| 298 | 292 | } |
| 299 | 293 | else |
| 300 | 294 | { |
@@ -302,20 +296,20 @@ discard block |
||
| 302 | 296 | } |
| 303 | 297 | break; |
| 304 | 298 | case 'enum': |
| 305 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 299 | + $value = $this->character_limiter($value, $this->character_limiter, "..."); |
|
| 306 | 300 | break; |
| 307 | 301 | |
| 308 | 302 | case 'multiselect': |
| 309 | 303 | $value_as_array = array(); |
| 310 | - foreach(explode(",",$value) as $row_value) |
|
| 304 | + foreach (explode(",", $value) as $row_value) |
|
| 311 | 305 | { |
| 312 | - $value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
| 306 | + $value_as_array[] = array_key_exists($row_value, $field_info->extras) ? $field_info->extras[$row_value] : $row_value; |
|
| 313 | 307 | } |
| 314 | - $value = implode(",",$value_as_array); |
|
| 308 | + $value = implode(",", $value_as_array); |
|
| 315 | 309 | break; |
| 316 | 310 | |
| 317 | 311 | case 'relation_n_n': |
| 318 | - $value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"..."); |
|
| 312 | + $value = $this->character_limiter(str_replace(',', ', ', $value), $this->character_limiter, "..."); |
|
| 319 | 313 | break; |
| 320 | 314 | |
| 321 | 315 | case 'password': |
@@ -323,34 +317,34 @@ discard block |
||
| 323 | 317 | break; |
| 324 | 318 | |
| 325 | 319 | case 'dropdown': |
| 326 | - $value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; |
|
| 320 | + $value = array_key_exists($value, $field_info->extras) ? $field_info->extras[$value] : $value; |
|
| 327 | 321 | break; |
| 328 | 322 | |
| 329 | 323 | case 'upload_file': |
| 330 | - if(empty($value)) |
|
| 324 | + if (empty($value)) |
|
| 331 | 325 | { |
| 332 | 326 | $value = ""; |
| 333 | 327 | } |
| 334 | 328 | else |
| 335 | 329 | { |
| 336 | 330 | $is_image = !empty($value) && |
| 337 | - ( substr($value,-4) == '.jpg' |
|
| 338 | - || substr($value,-4) == '.png' |
|
| 339 | - || substr($value,-5) == '.jpeg' |
|
| 340 | - || substr($value,-4) == '.gif' |
|
| 341 | - || substr($value,-5) == '.tiff') |
|
| 331 | + (substr($value, -4) == '.jpg' |
|
| 332 | + || substr($value, -4) == '.png' |
|
| 333 | + || substr($value, -5) == '.jpeg' |
|
| 334 | + || substr($value, -4) == '.gif' |
|
| 335 | + || substr($value, -5) == '.tiff') |
|
| 342 | 336 | ? true : false; |
| 343 | 337 | |
| 344 | 338 | $file_url = base_url().$field_info->extras->upload_path."/$value"; |
| 345 | 339 | |
| 346 | 340 | $file_url_anchor = '<a href="'.$file_url.'"'; |
| 347 | - if($is_image) |
|
| 341 | + if ($is_image) |
|
| 348 | 342 | { |
| 349 | 343 | $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
| 350 | 344 | } |
| 351 | 345 | else |
| 352 | 346 | { |
| 353 | - $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
|
| 347 | + $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value, $this->character_limiter, '...', true); |
|
| 354 | 348 | } |
| 355 | 349 | $file_url_anchor .= '</a>'; |
| 356 | 350 | |
@@ -359,7 +353,7 @@ discard block |
||
| 359 | 353 | break; |
| 360 | 354 | |
| 361 | 355 | default: |
| 362 | - $value = $this->character_limiter($value,$this->character_limiter,"..."); |
|
| 356 | + $value = $this->character_limiter($value, $this->character_limiter, "..."); |
|
| 363 | 357 | break; |
| 364 | 358 | } |
| 365 | 359 | |
@@ -409,7 +403,7 @@ discard block |
||
| 409 | 403 | protected function get_type($db_type) |
| 410 | 404 | { |
| 411 | 405 | $type = false; |
| 412 | - if(!empty($db_type->type)) |
|
| 406 | + if (!empty($db_type->type)) |
|
| 413 | 407 | { |
| 414 | 408 | switch ($db_type->type) { |
| 415 | 409 | case '1': |
@@ -418,7 +412,7 @@ discard block |
||
| 418 | 412 | case 'tinyint': |
| 419 | 413 | case 'mediumint': |
| 420 | 414 | case 'longint': |
| 421 | - if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
| 415 | + if ($db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
| 422 | 416 | $type = 'true_false'; |
| 423 | 417 | else |
| 424 | 418 | $type = 'integer'; |
@@ -426,13 +420,13 @@ discard block |
||
| 426 | 420 | case '254': |
| 427 | 421 | case 'string': |
| 428 | 422 | case 'enum': |
| 429 | - if($db_type->db_type != 'enum') |
|
| 423 | + if ($db_type->db_type != 'enum') |
|
| 430 | 424 | $type = 'string'; |
| 431 | 425 | else |
| 432 | 426 | $type = 'enum'; |
| 433 | 427 | break; |
| 434 | 428 | case 'set': |
| 435 | - if($db_type->db_type != 'set') |
|
| 429 | + if ($db_type->db_type != 'set') |
|
| 436 | 430 | $type = 'string'; |
| 437 | 431 | else |
| 438 | 432 | $type = 'set'; |
@@ -488,41 +482,41 @@ discard block |
||
| 488 | 482 | |
| 489 | 483 | protected function get_total_results() |
| 490 | 484 | { |
| 491 | - if(!empty($this->where)) |
|
| 492 | - foreach($this->where as $where) |
|
| 493 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 485 | + if (!empty($this->where)) |
|
| 486 | + foreach ($this->where as $where) |
|
| 487 | + $this->basic_model->where($where[0], $where[1], $where[2]); |
|
| 494 | 488 | |
| 495 | - if(!empty($this->or_where)) |
|
| 496 | - foreach($this->or_where as $or_where) |
|
| 497 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 489 | + if (!empty($this->or_where)) |
|
| 490 | + foreach ($this->or_where as $or_where) |
|
| 491 | + $this->basic_model->or_where($or_where[0], $or_where[1], $or_where[2]); |
|
| 498 | 492 | |
| 499 | - if(!empty($this->like)) |
|
| 500 | - foreach($this->like as $like) |
|
| 501 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 493 | + if (!empty($this->like)) |
|
| 494 | + foreach ($this->like as $like) |
|
| 495 | + $this->basic_model->like($like[0], $like[1], $like[2]); |
|
| 502 | 496 | |
| 503 | - if(!empty($this->or_like)) |
|
| 504 | - foreach($this->or_like as $or_like) |
|
| 505 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 497 | + if (!empty($this->or_like)) |
|
| 498 | + foreach ($this->or_like as $or_like) |
|
| 499 | + $this->basic_model->or_like($or_like[0], $or_like[1], $or_like[2]); |
|
| 506 | 500 | |
| 507 | - if(!empty($this->having)) |
|
| 508 | - foreach($this->having as $having) |
|
| 509 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 501 | + if (!empty($this->having)) |
|
| 502 | + foreach ($this->having as $having) |
|
| 503 | + $this->basic_model->having($having[0], $having[1], $having[2]); |
|
| 510 | 504 | |
| 511 | - if(!empty($this->or_having)) |
|
| 512 | - foreach($this->or_having as $or_having) |
|
| 513 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 505 | + if (!empty($this->or_having)) |
|
| 506 | + foreach ($this->or_having as $or_having) |
|
| 507 | + $this->basic_model->or_having($or_having[0], $or_having[1], $or_having[2]); |
|
| 514 | 508 | |
| 515 | - if(!empty($this->relation)) |
|
| 516 | - foreach($this->relation as $relation) |
|
| 517 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 509 | + if (!empty($this->relation)) |
|
| 510 | + foreach ($this->relation as $relation) |
|
| 511 | + $this->basic_model->join_relation($relation[0], $relation[1], $relation[2]); |
|
| 518 | 512 | |
| 519 | - if(!empty($this->relation_n_n)) |
|
| 513 | + if (!empty($this->relation_n_n)) |
|
| 520 | 514 | { |
| 521 | 515 | $columns = $this->get_columns(); |
| 522 | - foreach($columns as $column) |
|
| 516 | + foreach ($columns as $column) |
|
| 523 | 517 | { |
| 524 | 518 | //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
| 525 | - if(isset($this->relation_n_n[$column->field_name])) |
|
| 519 | + if (isset($this->relation_n_n[$column->field_name])) |
|
| 526 | 520 | { |
| 527 | 521 | $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
| 528 | 522 | } |
@@ -540,9 +534,9 @@ discard block |
||
| 540 | 534 | |
| 541 | 535 | $ci->load->model($model_name); |
| 542 | 536 | |
| 543 | - $temp = explode('/',$model_name); |
|
| 537 | + $temp = explode('/', $model_name); |
|
| 544 | 538 | krsort($temp); |
| 545 | - foreach($temp as $t) |
|
| 539 | + foreach ($temp as $t) |
|
| 546 | 540 | { |
| 547 | 541 | $real_model_name = $t; |
| 548 | 542 | break; |
@@ -553,23 +547,23 @@ discard block |
||
| 553 | 547 | |
| 554 | 548 | protected function set_ajax_list_queries($state_info = null) |
| 555 | 549 | { |
| 556 | - if(!empty($state_info->per_page)) |
|
| 550 | + if (!empty($state_info->per_page)) |
|
| 557 | 551 | { |
| 558 | - if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
| 552 | + if (empty($state_info->page) || !is_numeric($state_info->page)) |
|
| 559 | 553 | $this->limit($state_info->per_page); |
| 560 | 554 | else |
| 561 | 555 | { |
| 562 | - $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
|
| 556 | + $limit_page = (($state_info->page - 1) * $state_info->per_page); |
|
| 563 | 557 | $this->limit($state_info->per_page, $limit_page); |
| 564 | 558 | } |
| 565 | 559 | } |
| 566 | 560 | |
| 567 | - if(!empty($state_info->order_by)) |
|
| 561 | + if (!empty($state_info->order_by)) |
|
| 568 | 562 | { |
| 569 | - $this->order_by($state_info->order_by[0],$state_info->order_by[1]); |
|
| 563 | + $this->order_by($state_info->order_by[0], $state_info->order_by[1]); |
|
| 570 | 564 | } |
| 571 | 565 | |
| 572 | - if(!empty($state_info->search)) |
|
| 566 | + if (!empty($state_info->search)) |
|
| 573 | 567 | { |
| 574 | 568 | if (!empty($this->relation)) { |
| 575 | 569 | foreach ($this->relation as $relation_name => $relation_values) { |
@@ -584,12 +578,12 @@ discard block |
||
| 584 | 578 | if (isset($temp_relation[$search_field])) { |
| 585 | 579 | if (is_array($temp_relation[$search_field])) { |
| 586 | 580 | foreach ($temp_relation[$search_field] as $relation_field) { |
| 587 | - $this->or_like($relation_field , $search_text); |
|
| 581 | + $this->or_like($relation_field, $search_text); |
|
| 588 | 582 | } |
| 589 | 583 | } else { |
| 590 | - $this->like($temp_relation[$search_field] , $search_text); |
|
| 584 | + $this->like($temp_relation[$search_field], $search_text); |
|
| 591 | 585 | } |
| 592 | - } elseif(isset($this->relation_n_n[$search_field])) { |
|
| 586 | + } elseif (isset($this->relation_n_n[$search_field])) { |
|
| 593 | 587 | $escaped_text = $this->basic_model->escape_str($search_text); |
| 594 | 588 | $this->having($search_field." LIKE '%".$escaped_text."%'"); |
| 595 | 589 | } else { |
@@ -603,16 +597,16 @@ discard block |
||
| 603 | 597 | if (isset($temp_relation[$state_info->search->field])) { |
| 604 | 598 | if (is_array($temp_relation[$state_info->search->field])) { |
| 605 | 599 | foreach ($temp_relation[$state_info->search->field] as $search_field) { |
| 606 | - $this->or_like($search_field , $state_info->search->text); |
|
| 600 | + $this->or_like($search_field, $state_info->search->text); |
|
| 607 | 601 | } |
| 608 | 602 | } else { |
| 609 | - $this->like($temp_relation[$state_info->search->field] , $state_info->search->text); |
|
| 603 | + $this->like($temp_relation[$state_info->search->field], $state_info->search->text); |
|
| 610 | 604 | } |
| 611 | - } elseif(isset($this->relation_n_n[$state_info->search->field])) { |
|
| 605 | + } elseif (isset($this->relation_n_n[$state_info->search->field])) { |
|
| 612 | 606 | $escaped_text = $this->basic_model->escape_str($state_info->search->text); |
| 613 | 607 | $this->having($state_info->search->field." LIKE '%".$escaped_text."%'"); |
| 614 | 608 | } else { |
| 615 | - $this->like($state_info->search->field , $state_info->search->text); |
|
| 609 | + $this->like($state_info->search->field, $state_info->search->text); |
|
| 616 | 610 | } |
| 617 | 611 | } |
| 618 | 612 | else |
@@ -621,17 +615,17 @@ discard block |
||
| 621 | 615 | |
| 622 | 616 | $search_text = $state_info->search->text; |
| 623 | 617 | |
| 624 | - if(!empty($this->where)) |
|
| 625 | - foreach($this->where as $where) |
|
| 626 | - $this->basic_model->having($where[0],$where[1],$where[2]); |
|
| 618 | + if (!empty($this->where)) |
|
| 619 | + foreach ($this->where as $where) |
|
| 620 | + $this->basic_model->having($where[0], $where[1], $where[2]); |
|
| 627 | 621 | |
| 628 | - foreach($columns as $column) |
|
| 622 | + foreach ($columns as $column) |
|
| 629 | 623 | { |
| 630 | - if(isset($temp_relation[$column->field_name])) |
|
| 624 | + if (isset($temp_relation[$column->field_name])) |
|
| 631 | 625 | { |
| 632 | - if(is_array($temp_relation[$column->field_name])) |
|
| 626 | + if (is_array($temp_relation[$column->field_name])) |
|
| 633 | 627 | { |
| 634 | - foreach($temp_relation[$column->field_name] as $search_field) |
|
| 628 | + foreach ($temp_relation[$column->field_name] as $search_field) |
|
| 635 | 629 | { |
| 636 | 630 | $this->or_like($search_field, $search_text); |
| 637 | 631 | } |
@@ -641,7 +635,7 @@ discard block |
||
| 641 | 635 | $this->or_like($temp_relation[$column->field_name], $search_text); |
| 642 | 636 | } |
| 643 | 637 | } |
| 644 | - elseif(isset($this->relation_n_n[$column->field_name])) |
|
| 638 | + elseif (isset($this->relation_n_n[$column->field_name])) |
|
| 645 | 639 | { |
| 646 | 640 | //@todo have a where for the relation_n_n statement |
| 647 | 641 | } |
@@ -656,16 +650,16 @@ discard block |
||
| 656 | 650 | |
| 657 | 651 | protected function table_exists($table_name = null) |
| 658 | 652 | { |
| 659 | - if($this->basic_model->db_table_exists($table_name)) |
|
| 653 | + if ($this->basic_model->db_table_exists($table_name)) |
|
| 660 | 654 | return true; |
| 661 | 655 | return false; |
| 662 | 656 | } |
| 663 | 657 | |
| 664 | 658 | protected function get_relation_array($relation_info, $primary_key_value = null, $limit = null) |
| 665 | 659 | { |
| 666 | - list($field_name , $related_table , $related_field_title, $where_clause, $order_by) = $relation_info; |
|
| 660 | + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $relation_info; |
|
| 667 | 661 | |
| 668 | - if($primary_key_value !== null) |
|
| 662 | + if ($primary_key_value !== null) |
|
| 669 | 663 | { |
| 670 | 664 | $primary_key = $this->basic_model->get_primary_key($related_table); |
| 671 | 665 | |
@@ -673,59 +667,59 @@ discard block |
||
| 673 | 667 | $where_clause = array($primary_key => $primary_key_value); |
| 674 | 668 | } |
| 675 | 669 | |
| 676 | - $relation_array = $this->basic_model->get_relation_array($field_name , $related_table , $related_field_title, $where_clause, $order_by, $limit); |
|
| 670 | + $relation_array = $this->basic_model->get_relation_array($field_name, $related_table, $related_field_title, $where_clause, $order_by, $limit); |
|
| 677 | 671 | |
| 678 | 672 | return $relation_array; |
| 679 | 673 | } |
| 680 | 674 | |
| 681 | 675 | protected function get_relation_total_rows($relation_info) |
| 682 | 676 | { |
| 683 | - list($field_name , $related_table , $related_field_title, $where_clause) = $relation_info; |
|
| 677 | + list($field_name, $related_table, $related_field_title, $where_clause) = $relation_info; |
|
| 684 | 678 | |
| 685 | - $relation_array = $this->basic_model->get_relation_total_rows($field_name , $related_table , $related_field_title, $where_clause); |
|
| 679 | + $relation_array = $this->basic_model->get_relation_total_rows($field_name, $related_table, $related_field_title, $where_clause); |
|
| 686 | 680 | |
| 687 | 681 | return $relation_array; |
| 688 | 682 | } |
| 689 | 683 | |
| 690 | 684 | protected function db_insert_validation() |
| 691 | 685 | { |
| 692 | - $validation_result = (object)array('success'=>false); |
|
| 686 | + $validation_result = (object) array('success'=>false); |
|
| 693 | 687 | |
| 694 | 688 | $field_types = $this->get_field_types(); |
| 695 | 689 | $required_fields = $this->required_fields; |
| 696 | 690 | $unique_fields = $this->_unique_fields; |
| 697 | 691 | $add_fields = $this->get_add_fields(); |
| 698 | 692 | |
| 699 | - if(!empty($required_fields)) |
|
| 693 | + if (!empty($required_fields)) |
|
| 700 | 694 | { |
| 701 | - foreach($add_fields as $add_field) |
|
| 695 | + foreach ($add_fields as $add_field) |
|
| 702 | 696 | { |
| 703 | 697 | $field_name = $add_field->field_name; |
| 704 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 698 | + if (!isset($this->validation_rules[$field_name]) && in_array($field_name, $required_fields)) |
|
| 705 | 699 | { |
| 706 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 700 | + $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 707 | 701 | } |
| 708 | 702 | } |
| 709 | 703 | } |
| 710 | 704 | |
| 711 | 705 | /** Checking for unique fields. If the field value is not unique then |
| 712 | 706 | * return a validation error straight away, if not continue... */ |
| 713 | - if(!empty($unique_fields)) |
|
| 707 | + if (!empty($unique_fields)) |
|
| 714 | 708 | { |
| 715 | 709 | $form_validation = $this->form_validation(); |
| 716 | 710 | |
| 717 | - foreach($add_fields as $add_field) |
|
| 711 | + foreach ($add_fields as $add_field) |
|
| 718 | 712 | { |
| 719 | 713 | $field_name = $add_field->field_name; |
| 720 | - if(in_array( $field_name, $unique_fields) ) |
|
| 714 | + if (in_array($field_name, $unique_fields)) |
|
| 721 | 715 | { |
| 722 | - $form_validation->set_rules( $field_name, |
|
| 716 | + $form_validation->set_rules($field_name, |
|
| 723 | 717 | $field_types[$field_name]->display_as, |
| 724 | 718 | 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
| 725 | 719 | } |
| 726 | 720 | } |
| 727 | 721 | |
| 728 | - if(!$form_validation->run()) |
|
| 722 | + if (!$form_validation->run()) |
|
| 729 | 723 | { |
| 730 | 724 | $validation_result->error_message = $form_validation->error_string(); |
| 731 | 725 | $validation_result->error_fields = $form_validation->_error_array; |
@@ -734,23 +728,23 @@ discard block |
||
| 734 | 728 | } |
| 735 | 729 | } |
| 736 | 730 | |
| 737 | - if(!empty($this->validation_rules)) |
|
| 731 | + if (!empty($this->validation_rules)) |
|
| 738 | 732 | { |
| 739 | 733 | $form_validation = $this->form_validation(); |
| 740 | 734 | |
| 741 | 735 | $add_fields = $this->get_add_fields(); |
| 742 | 736 | |
| 743 | - foreach($add_fields as $add_field) |
|
| 737 | + foreach ($add_fields as $add_field) |
|
| 744 | 738 | { |
| 745 | 739 | $field_name = $add_field->field_name; |
| 746 | - if(isset($this->validation_rules[$field_name])) |
|
| 740 | + if (isset($this->validation_rules[$field_name])) |
|
| 747 | 741 | { |
| 748 | 742 | $rule = $this->validation_rules[$field_name]; |
| 749 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 743 | + $form_validation->set_rules($rule['field'], $rule['label'], $rule['rules']); |
|
| 750 | 744 | } |
| 751 | 745 | } |
| 752 | 746 | |
| 753 | - if($form_validation->run()) |
|
| 747 | + if ($form_validation->run()) |
|
| 754 | 748 | { |
| 755 | 749 | $validation_result->success = true; |
| 756 | 750 | } |
@@ -770,7 +764,7 @@ discard block |
||
| 770 | 764 | |
| 771 | 765 | protected function form_validation() |
| 772 | 766 | { |
| 773 | - if($this->form_validation === null) |
|
| 767 | + if ($this->form_validation === null) |
|
| 774 | 768 | { |
| 775 | 769 | $this->form_validation = new grocery_CRUD_Form_validation(); |
| 776 | 770 | $ci = &get_instance(); |
@@ -782,21 +776,21 @@ discard block |
||
| 782 | 776 | |
| 783 | 777 | protected function db_update_validation() |
| 784 | 778 | { |
| 785 | - $validation_result = (object)array('success'=>false); |
|
| 779 | + $validation_result = (object) array('success'=>false); |
|
| 786 | 780 | |
| 787 | 781 | $field_types = $this->get_field_types(); |
| 788 | 782 | $required_fields = $this->required_fields; |
| 789 | 783 | $unique_fields = $this->_unique_fields; |
| 790 | 784 | $edit_fields = $this->get_edit_fields(); |
| 791 | 785 | |
| 792 | - if(!empty($required_fields)) |
|
| 786 | + if (!empty($required_fields)) |
|
| 793 | 787 | { |
| 794 | - foreach($edit_fields as $edit_field) |
|
| 788 | + foreach ($edit_fields as $edit_field) |
|
| 795 | 789 | { |
| 796 | 790 | $field_name = $edit_field->field_name; |
| 797 | - if(!isset($this->validation_rules[$field_name]) && in_array( $field_name, $required_fields) ) |
|
| 791 | + if (!isset($this->validation_rules[$field_name]) && in_array($field_name, $required_fields)) |
|
| 798 | 792 | { |
| 799 | - $this->set_rules( $field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 793 | + $this->set_rules($field_name, $field_types[$field_name]->display_as, 'required'); |
|
| 800 | 794 | } |
| 801 | 795 | } |
| 802 | 796 | } |
@@ -804,25 +798,25 @@ discard block |
||
| 804 | 798 | |
| 805 | 799 | /** Checking for unique fields. If the field value is not unique then |
| 806 | 800 | * return a validation error straight away, if not continue... */ |
| 807 | - if(!empty($unique_fields)) |
|
| 801 | + if (!empty($unique_fields)) |
|
| 808 | 802 | { |
| 809 | 803 | $form_validation = $this->form_validation(); |
| 810 | 804 | |
| 811 | 805 | $form_validation_check = false; |
| 812 | 806 | |
| 813 | - foreach($edit_fields as $edit_field) |
|
| 807 | + foreach ($edit_fields as $edit_field) |
|
| 814 | 808 | { |
| 815 | 809 | $field_name = $edit_field->field_name; |
| 816 | - if(in_array( $field_name, $unique_fields) ) |
|
| 810 | + if (in_array($field_name, $unique_fields)) |
|
| 817 | 811 | { |
| 818 | 812 | $state_info = $this->getStateInfo(); |
| 819 | 813 | $primary_key = $this->get_primary_key(); |
| 820 | 814 | $field_name_value = $_POST[$field_name]; |
| 821 | 815 | |
| 822 | - $this->basic_model->where($primary_key,$state_info->primary_key); |
|
| 816 | + $this->basic_model->where($primary_key, $state_info->primary_key); |
|
| 823 | 817 | $row = $this->basic_model->get_row(); |
| 824 | 818 | |
| 825 | - if(!isset($row->$field_name)) { |
|
| 819 | + if (!isset($row->$field_name)) { |
|
| 826 | 820 | throw new Exception("The field name doesn't exist in the database. ". |
| 827 | 821 | "Please use the unique fields only for fields ". |
| 828 | 822 | "that exist in the database"); |
@@ -830,8 +824,8 @@ discard block |
||
| 830 | 824 | |
| 831 | 825 | $previous_field_name_value = $row->$field_name; |
| 832 | 826 | |
| 833 | - if(!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
| 834 | - $form_validation->set_rules( $field_name, |
|
| 827 | + if (!empty($previous_field_name_value) && $previous_field_name_value != $field_name_value) { |
|
| 828 | + $form_validation->set_rules($field_name, |
|
| 835 | 829 | $field_types[$field_name]->display_as, |
| 836 | 830 | 'is_unique['.$this->basic_db_table.'.'.$field_name.']'); |
| 837 | 831 | |
@@ -840,7 +834,7 @@ discard block |
||
| 840 | 834 | } |
| 841 | 835 | } |
| 842 | 836 | |
| 843 | - if($form_validation_check && !$form_validation->run()) |
|
| 837 | + if ($form_validation_check && !$form_validation->run()) |
|
| 844 | 838 | { |
| 845 | 839 | $validation_result->error_message = $form_validation->error_string(); |
| 846 | 840 | $validation_result->error_fields = $form_validation->_error_array; |
@@ -849,23 +843,23 @@ discard block |
||
| 849 | 843 | } |
| 850 | 844 | } |
| 851 | 845 | |
| 852 | - if(!empty($this->validation_rules)) |
|
| 846 | + if (!empty($this->validation_rules)) |
|
| 853 | 847 | { |
| 854 | 848 | $form_validation = $this->form_validation(); |
| 855 | 849 | |
| 856 | 850 | $edit_fields = $this->get_edit_fields(); |
| 857 | 851 | |
| 858 | - foreach($edit_fields as $edit_field) |
|
| 852 | + foreach ($edit_fields as $edit_field) |
|
| 859 | 853 | { |
| 860 | 854 | $field_name = $edit_field->field_name; |
| 861 | - if(isset($this->validation_rules[$field_name])) |
|
| 855 | + if (isset($this->validation_rules[$field_name])) |
|
| 862 | 856 | { |
| 863 | 857 | $rule = $this->validation_rules[$field_name]; |
| 864 | - $form_validation->set_rules($rule['field'],$rule['label'],$rule['rules']); |
|
| 858 | + $form_validation->set_rules($rule['field'], $rule['label'], $rule['rules']); |
|
| 865 | 859 | } |
| 866 | 860 | } |
| 867 | 861 | |
| 868 | - if($form_validation->run()) |
|
| 862 | + if ($form_validation->run()) |
|
| 869 | 863 | { |
| 870 | 864 | $validation_result->success = true; |
| 871 | 865 | } |
@@ -887,59 +881,59 @@ discard block |
||
| 887 | 881 | { |
| 888 | 882 | $validation_result = $this->db_insert_validation(); |
| 889 | 883 | |
| 890 | - if($validation_result->success) |
|
| 884 | + if ($validation_result->success) |
|
| 891 | 885 | { |
| 892 | 886 | $post_data = $state_info->unwrapped_data; |
| 893 | 887 | |
| 894 | 888 | $add_fields = $this->get_add_fields(); |
| 895 | 889 | |
| 896 | - if($this->callback_insert === null) |
|
| 890 | + if ($this->callback_insert === null) |
|
| 897 | 891 | { |
| 898 | - if($this->callback_before_insert !== null) |
|
| 892 | + if ($this->callback_before_insert !== null) |
|
| 899 | 893 | { |
| 900 | 894 | $callback_return = call_user_func($this->callback_before_insert, $post_data); |
| 901 | 895 | |
| 902 | - if(!empty($callback_return) && is_array($callback_return)) |
|
| 896 | + if (!empty($callback_return) && is_array($callback_return)) |
|
| 903 | 897 | $post_data = $callback_return; |
| 904 | - elseif($callback_return === false) |
|
| 898 | + elseif ($callback_return === false) |
|
| 905 | 899 | return false; |
| 906 | 900 | } |
| 907 | 901 | |
| 908 | 902 | $insert_data = array(); |
| 909 | 903 | $types = $this->get_field_types(); |
| 910 | - foreach($add_fields as $num_row => $field) |
|
| 904 | + foreach ($add_fields as $num_row => $field) |
|
| 911 | 905 | { |
| 912 | 906 | /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
| 913 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 907 | + if (isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 914 | 908 | { |
| 915 | 909 | $post_data[$field->field_name] = array(); |
| 916 | 910 | } |
| 917 | 911 | |
| 918 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 912 | + if (isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 919 | 913 | { |
| 920 | - 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])) |
|
| 914 | + 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])) |
|
| 921 | 915 | { |
| 922 | 916 | $insert_data[$field->field_name] = null; |
| 923 | 917 | } |
| 924 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 918 | + elseif (isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 925 | 919 | { |
| 926 | 920 | $insert_data[$field->field_name] = null; |
| 927 | 921 | } |
| 928 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 922 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 929 | 923 | { |
| 930 | 924 | $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
| 931 | 925 | } |
| 932 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 926 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 933 | 927 | { |
| 934 | 928 | //This empty if statement is to make sure that a readonly field will never inserted/updated |
| 935 | 929 | } |
| 936 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 930 | + elseif (isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 937 | 931 | { |
| 938 | - $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 932 | + $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',', $post_data[$field->field_name]) : ''; |
|
| 939 | 933 | } |
| 940 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 941 | - $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 942 | - substr($post_data[$field->field_name],10); |
|
| 934 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime') { |
|
| 935 | + $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name], 0, 10)). |
|
| 936 | + substr($post_data[$field->field_name], 10); |
|
| 943 | 937 | } |
| 944 | 938 | else |
| 945 | 939 | { |
@@ -948,9 +942,9 @@ discard block |
||
| 948 | 942 | } |
| 949 | 943 | } |
| 950 | 944 | |
| 951 | - $insert_result = $this->basic_model->db_insert($insert_data); |
|
| 945 | + $insert_result = $this->basic_model->db_insert($insert_data); |
|
| 952 | 946 | |
| 953 | - if($insert_result !== false) |
|
| 947 | + if ($insert_result !== false) |
|
| 954 | 948 | { |
| 955 | 949 | $insert_primary_key = $insert_result; |
| 956 | 950 | } |
@@ -959,36 +953,36 @@ discard block |
||
| 959 | 953 | return false; |
| 960 | 954 | } |
| 961 | 955 | |
| 962 | - if(!empty($this->relation_n_n)) |
|
| 956 | + if (!empty($this->relation_n_n)) |
|
| 963 | 957 | { |
| 964 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 958 | + foreach ($this->relation_n_n as $field_name => $field_info) |
|
| 965 | 959 | { |
| 966 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 967 | - $this->db_relation_n_n_update($field_info, $relation_data ,$insert_primary_key); |
|
| 960 | + $relation_data = isset($post_data[$field_name]) ? $post_data[$field_name] : array(); |
|
| 961 | + $this->db_relation_n_n_update($field_info, $relation_data, $insert_primary_key); |
|
| 968 | 962 | } |
| 969 | 963 | } |
| 970 | 964 | |
| 971 | - if($this->callback_after_insert !== null) |
|
| 965 | + if ($this->callback_after_insert !== null) |
|
| 972 | 966 | { |
| 973 | 967 | $callback_return = call_user_func($this->callback_after_insert, $post_data, $insert_primary_key); |
| 974 | 968 | |
| 975 | - if($callback_return === false) |
|
| 969 | + if ($callback_return === false) |
|
| 976 | 970 | { |
| 977 | 971 | return false; |
| 978 | 972 | } |
| 979 | 973 | |
| 980 | 974 | } |
| 981 | - }else |
|
| 975 | + } else |
|
| 982 | 976 | { |
| 983 | 977 | $callback_return = call_user_func($this->callback_insert, $post_data); |
| 984 | 978 | |
| 985 | - if($callback_return === false) |
|
| 979 | + if ($callback_return === false) |
|
| 986 | 980 | { |
| 987 | 981 | return false; |
| 988 | 982 | } |
| 989 | 983 | } |
| 990 | 984 | |
| 991 | - if(isset($insert_primary_key)) |
|
| 985 | + if (isset($insert_primary_key)) |
|
| 992 | 986 | return $insert_primary_key; |
| 993 | 987 | else |
| 994 | 988 | return true; |
@@ -1004,22 +998,22 @@ discard block |
||
| 1004 | 998 | |
| 1005 | 999 | $edit_fields = $this->get_edit_fields(); |
| 1006 | 1000 | |
| 1007 | - if($validation_result->success) |
|
| 1001 | + if ($validation_result->success) |
|
| 1008 | 1002 | { |
| 1009 | - $post_data = $state_info->unwrapped_data; |
|
| 1010 | - $primary_key = $state_info->primary_key; |
|
| 1003 | + $post_data = $state_info->unwrapped_data; |
|
| 1004 | + $primary_key = $state_info->primary_key; |
|
| 1011 | 1005 | |
| 1012 | - if($this->callback_update === null) |
|
| 1006 | + if ($this->callback_update === null) |
|
| 1013 | 1007 | { |
| 1014 | - if($this->callback_before_update !== null) |
|
| 1008 | + if ($this->callback_before_update !== null) |
|
| 1015 | 1009 | { |
| 1016 | 1010 | $callback_return = call_user_func($this->callback_before_update, $post_data, $primary_key); |
| 1017 | 1011 | |
| 1018 | - if(!empty($callback_return) && is_array($callback_return)) |
|
| 1012 | + if (!empty($callback_return) && is_array($callback_return)) |
|
| 1019 | 1013 | { |
| 1020 | 1014 | $post_data = $callback_return; |
| 1021 | 1015 | } |
| 1022 | - elseif($callback_return === false) |
|
| 1016 | + elseif ($callback_return === false) |
|
| 1023 | 1017 | { |
| 1024 | 1018 | return false; |
| 1025 | 1019 | } |
@@ -1028,39 +1022,39 @@ discard block |
||
| 1028 | 1022 | |
| 1029 | 1023 | $update_data = array(); |
| 1030 | 1024 | $types = $this->get_field_types(); |
| 1031 | - foreach($edit_fields as $num_row => $field) |
|
| 1025 | + foreach ($edit_fields as $num_row => $field) |
|
| 1032 | 1026 | { |
| 1033 | 1027 | /* If the multiselect or the set is empty then the browser doesn't send an empty array. Instead it sends nothing */ |
| 1034 | - if(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 1028 | + if (isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect') && !isset($post_data[$field->field_name])) |
|
| 1035 | 1029 | { |
| 1036 | 1030 | $post_data[$field->field_name] = array(); |
| 1037 | 1031 | } |
| 1038 | 1032 | |
| 1039 | - if(isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 1033 | + if (isset($post_data[$field->field_name]) && !isset($this->relation_n_n[$field->field_name])) |
|
| 1040 | 1034 | { |
| 1041 | - 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])) |
|
| 1035 | + 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])) |
|
| 1042 | 1036 | { |
| 1043 | 1037 | $update_data[$field->field_name] = null; |
| 1044 | 1038 | } |
| 1045 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1039 | + elseif (isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1046 | 1040 | { |
| 1047 | 1041 | $update_data[$field->field_name] = null; |
| 1048 | 1042 | } |
| 1049 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1043 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1050 | 1044 | { |
| 1051 | 1045 | $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
| 1052 | 1046 | } |
| 1053 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1047 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1054 | 1048 | { |
| 1055 | 1049 | //This empty if statement is to make sure that a readonly field will never inserted/updated |
| 1056 | 1050 | } |
| 1057 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1051 | + elseif (isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1058 | 1052 | { |
| 1059 | - $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
|
| 1053 | + $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',', $post_data[$field->field_name]) : ''; |
|
| 1060 | 1054 | } |
| 1061 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 1062 | - $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
|
| 1063 | - substr($post_data[$field->field_name],10); |
|
| 1055 | + elseif (isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime') { |
|
| 1056 | + $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name], 0, 10)). |
|
| 1057 | + substr($post_data[$field->field_name], 10); |
|
| 1064 | 1058 | } |
| 1065 | 1059 | else |
| 1066 | 1060 | { |
@@ -1069,32 +1063,32 @@ discard block |
||
| 1069 | 1063 | } |
| 1070 | 1064 | } |
| 1071 | 1065 | |
| 1072 | - if($this->basic_model->db_update($update_data, $primary_key) === false) |
|
| 1066 | + if ($this->basic_model->db_update($update_data, $primary_key) === false) |
|
| 1073 | 1067 | { |
| 1074 | 1068 | return false; |
| 1075 | 1069 | } |
| 1076 | 1070 | |
| 1077 | - if(!empty($this->relation_n_n)) |
|
| 1071 | + if (!empty($this->relation_n_n)) |
|
| 1078 | 1072 | { |
| 1079 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1073 | + foreach ($this->relation_n_n as $field_name => $field_info) |
|
| 1080 | 1074 | { |
| 1081 | - if ( $this->unset_edit_fields !== null |
|
| 1075 | + if ($this->unset_edit_fields !== null |
|
| 1082 | 1076 | && is_array($this->unset_edit_fields) |
| 1083 | - && in_array($field_name,$this->unset_edit_fields) |
|
| 1077 | + && in_array($field_name, $this->unset_edit_fields) |
|
| 1084 | 1078 | ) { |
| 1085 | 1079 | continue; |
| 1086 | 1080 | } |
| 1087 | 1081 | |
| 1088 | - $relation_data = isset( $post_data[$field_name] ) ? $post_data[$field_name] : array() ; |
|
| 1089 | - $this->db_relation_n_n_update($field_info, $relation_data ,$primary_key); |
|
| 1082 | + $relation_data = isset($post_data[$field_name]) ? $post_data[$field_name] : array(); |
|
| 1083 | + $this->db_relation_n_n_update($field_info, $relation_data, $primary_key); |
|
| 1090 | 1084 | } |
| 1091 | 1085 | } |
| 1092 | 1086 | |
| 1093 | - if($this->callback_after_update !== null) |
|
| 1087 | + if ($this->callback_after_update !== null) |
|
| 1094 | 1088 | { |
| 1095 | 1089 | $callback_return = call_user_func($this->callback_after_update, $post_data, $primary_key); |
| 1096 | 1090 | |
| 1097 | - if($callback_return === false) |
|
| 1091 | + if ($callback_return === false) |
|
| 1098 | 1092 | { |
| 1099 | 1093 | return false; |
| 1100 | 1094 | } |
@@ -1105,7 +1099,7 @@ discard block |
||
| 1105 | 1099 | { |
| 1106 | 1100 | $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
| 1107 | 1101 | |
| 1108 | - if($callback_return === false) |
|
| 1102 | + if ($callback_return === false) |
|
| 1109 | 1103 | { |
| 1110 | 1104 | return false; |
| 1111 | 1105 | } |
@@ -1121,24 +1115,24 @@ discard block |
||
| 1121 | 1115 | |
| 1122 | 1116 | protected function _convert_date_to_sql_date($date) |
| 1123 | 1117 | { |
| 1124 | - $date = substr($date,0,10); |
|
| 1125 | - if(preg_match('/\d{4}-\d{2}-\d{2}/',$date)) |
|
| 1118 | + $date = substr($date, 0, 10); |
|
| 1119 | + if (preg_match('/\d{4}-\d{2}-\d{2}/', $date)) |
|
| 1126 | 1120 | { |
| 1127 | 1121 | //If it's already a sql-date don't convert it! |
| 1128 | 1122 | return $date; |
| 1129 | - }elseif(empty($date)) |
|
| 1123 | + }elseif (empty($date)) |
|
| 1130 | 1124 | { |
| 1131 | 1125 | return ''; |
| 1132 | 1126 | } |
| 1133 | 1127 | |
| 1134 | - $date_array = preg_split( '/[-\.\/ ]/', $date); |
|
| 1135 | - if($this->php_date_format == 'd/m/Y') |
|
| 1128 | + $date_array = preg_split('/[-\.\/ ]/', $date); |
|
| 1129 | + if ($this->php_date_format == 'd/m/Y') |
|
| 1136 | 1130 | { |
| 1137 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
|
| 1131 | + $sql_date = date('Y-m-d', mktime(0, 0, 0, $date_array[1], $date_array[0], $date_array[2])); |
|
| 1138 | 1132 | } |
| 1139 | - elseif($this->php_date_format == 'm/d/Y') |
|
| 1133 | + elseif ($this->php_date_format == 'm/d/Y') |
|
| 1140 | 1134 | { |
| 1141 | - $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
|
| 1135 | + $sql_date = date('Y-m-d', mktime(0, 0, 0, $date_array[0], $date_array[1], $date_array[2])); |
|
| 1142 | 1136 | } |
| 1143 | 1137 | else |
| 1144 | 1138 | { |
@@ -1150,17 +1144,17 @@ discard block |
||
| 1150 | 1144 | |
| 1151 | 1145 | protected function _get_field_names_to_search(array $relation_values) |
| 1152 | 1146 | { |
| 1153 | - if(!strstr($relation_values[2],'{')) |
|
| 1147 | + if (!strstr($relation_values[2], '{')) |
|
| 1154 | 1148 | return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
| 1155 | 1149 | else |
| 1156 | 1150 | { |
| 1157 | 1151 | $relation_values[2] = ' '.$relation_values[2].' '; |
| 1158 | - $temp1 = explode('{',$relation_values[2]); |
|
| 1152 | + $temp1 = explode('{', $relation_values[2]); |
|
| 1159 | 1153 | unset($temp1[0]); |
| 1160 | 1154 | |
| 1161 | 1155 | $field_names_array = array(); |
| 1162 | - foreach($temp1 as $field) |
|
| 1163 | - list($field_names_array[]) = explode('}',$field); |
|
| 1156 | + foreach ($temp1 as $field) |
|
| 1157 | + list($field_names_array[]) = explode('}', $field); |
|
| 1164 | 1158 | |
| 1165 | 1159 | return $field_names_array; |
| 1166 | 1160 | } |
@@ -1168,18 +1162,18 @@ discard block |
||
| 1168 | 1162 | |
| 1169 | 1163 | protected function _unique_join_name($field_name) |
| 1170 | 1164 | { |
| 1171 | - return 'j'.substr(md5($field_name),0,8); //This j is because is better for a string to begin with a letter and not a number |
|
| 1165 | + return 'j'.substr(md5($field_name), 0, 8); //This j is because is better for a string to begin with a letter and not a number |
|
| 1172 | 1166 | } |
| 1173 | 1167 | |
| 1174 | 1168 | protected function _unique_field_name($field_name) |
| 1175 | 1169 | { |
| 1176 | - return 's'.substr(md5($field_name),0,8); //This s is because is better for a string to begin with a letter and not a number |
|
| 1170 | + return 's'.substr(md5($field_name), 0, 8); //This s is because is better for a string to begin with a letter and not a number |
|
| 1177 | 1171 | } |
| 1178 | 1172 | |
| 1179 | 1173 | protected function db_multiple_delete($state_info) |
| 1180 | 1174 | { |
| 1181 | 1175 | foreach ($state_info->ids as $delete_id) { |
| 1182 | - $result = $this->db_delete((object)array('primary_key' => $delete_id)); |
|
| 1176 | + $result = $this->db_delete((object) array('primary_key' => $delete_id)); |
|
| 1183 | 1177 | if (!$result) { |
| 1184 | 1178 | return false; |
| 1185 | 1179 | } |
@@ -1190,41 +1184,41 @@ discard block |
||
| 1190 | 1184 | |
| 1191 | 1185 | protected function db_delete($state_info) |
| 1192 | 1186 | { |
| 1193 | - $primary_key_value = $state_info->primary_key; |
|
| 1187 | + $primary_key_value = $state_info->primary_key; |
|
| 1194 | 1188 | |
| 1195 | - if($this->callback_delete === null) |
|
| 1189 | + if ($this->callback_delete === null) |
|
| 1196 | 1190 | { |
| 1197 | - if($this->callback_before_delete !== null) |
|
| 1191 | + if ($this->callback_before_delete !== null) |
|
| 1198 | 1192 | { |
| 1199 | 1193 | $callback_return = call_user_func($this->callback_before_delete, $primary_key_value); |
| 1200 | 1194 | |
| 1201 | - if($callback_return === false) |
|
| 1195 | + if ($callback_return === false) |
|
| 1202 | 1196 | { |
| 1203 | 1197 | return false; |
| 1204 | 1198 | } |
| 1205 | 1199 | |
| 1206 | 1200 | } |
| 1207 | 1201 | |
| 1208 | - if(!empty($this->relation_n_n)) |
|
| 1202 | + if (!empty($this->relation_n_n)) |
|
| 1209 | 1203 | { |
| 1210 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1204 | + foreach ($this->relation_n_n as $field_name => $field_info) |
|
| 1211 | 1205 | { |
| 1212 | - $this->db_relation_n_n_delete( $field_info, $primary_key_value ); |
|
| 1206 | + $this->db_relation_n_n_delete($field_info, $primary_key_value); |
|
| 1213 | 1207 | } |
| 1214 | 1208 | } |
| 1215 | 1209 | |
| 1216 | 1210 | $delete_result = $this->basic_model->db_delete($primary_key_value); |
| 1217 | 1211 | |
| 1218 | - if($delete_result === false) |
|
| 1212 | + if ($delete_result === false) |
|
| 1219 | 1213 | { |
| 1220 | 1214 | return false; |
| 1221 | 1215 | } |
| 1222 | 1216 | |
| 1223 | - if($this->callback_after_delete !== null) |
|
| 1217 | + if ($this->callback_after_delete !== null) |
|
| 1224 | 1218 | { |
| 1225 | 1219 | $callback_return = call_user_func($this->callback_after_delete, $primary_key_value); |
| 1226 | 1220 | |
| 1227 | - if($callback_return === false) |
|
| 1221 | + if ($callback_return === false) |
|
| 1228 | 1222 | { |
| 1229 | 1223 | return false; |
| 1230 | 1224 | } |
@@ -1235,7 +1229,7 @@ discard block |
||
| 1235 | 1229 | { |
| 1236 | 1230 | $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
| 1237 | 1231 | |
| 1238 | - if($callback_return === false) |
|
| 1232 | + if ($callback_return === false) |
|
| 1239 | 1233 | { |
| 1240 | 1234 | return false; |
| 1241 | 1235 | } |
@@ -1244,9 +1238,9 @@ discard block |
||
| 1244 | 1238 | return true; |
| 1245 | 1239 | } |
| 1246 | 1240 | |
| 1247 | - protected function db_relation_n_n_update($field_info, $post_data , $primary_key_value) |
|
| 1241 | + protected function db_relation_n_n_update($field_info, $post_data, $primary_key_value) |
|
| 1248 | 1242 | { |
| 1249 | - $this->basic_model->db_relation_n_n_update($field_info, $post_data , $primary_key_value); |
|
| 1243 | + $this->basic_model->db_relation_n_n_update($field_info, $post_data, $primary_key_value); |
|
| 1250 | 1244 | } |
| 1251 | 1245 | |
| 1252 | 1246 | protected function db_relation_n_n_delete($field_info, $primary_key_value) |
@@ -1256,44 +1250,44 @@ discard block |
||
| 1256 | 1250 | |
| 1257 | 1251 | protected function get_list() |
| 1258 | 1252 | { |
| 1259 | - if(!empty($this->order_by)) |
|
| 1260 | - $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
| 1253 | + if (!empty($this->order_by)) |
|
| 1254 | + $this->basic_model->order_by($this->order_by[0], $this->order_by[1]); |
|
| 1261 | 1255 | |
| 1262 | - if(!empty($this->where)) |
|
| 1263 | - foreach($this->where as $where) |
|
| 1264 | - $this->basic_model->where($where[0],$where[1],$where[2]); |
|
| 1256 | + if (!empty($this->where)) |
|
| 1257 | + foreach ($this->where as $where) |
|
| 1258 | + $this->basic_model->where($where[0], $where[1], $where[2]); |
|
| 1265 | 1259 | |
| 1266 | - if(!empty($this->or_where)) |
|
| 1267 | - foreach($this->or_where as $or_where) |
|
| 1268 | - $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
|
| 1260 | + if (!empty($this->or_where)) |
|
| 1261 | + foreach ($this->or_where as $or_where) |
|
| 1262 | + $this->basic_model->or_where($or_where[0], $or_where[1], $or_where[2]); |
|
| 1269 | 1263 | |
| 1270 | - if(!empty($this->like)) |
|
| 1271 | - foreach($this->like as $like) |
|
| 1272 | - $this->basic_model->like($like[0],$like[1],$like[2]); |
|
| 1264 | + if (!empty($this->like)) |
|
| 1265 | + foreach ($this->like as $like) |
|
| 1266 | + $this->basic_model->like($like[0], $like[1], $like[2]); |
|
| 1273 | 1267 | |
| 1274 | - if(!empty($this->or_like)) |
|
| 1275 | - foreach($this->or_like as $or_like) |
|
| 1276 | - $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
|
| 1268 | + if (!empty($this->or_like)) |
|
| 1269 | + foreach ($this->or_like as $or_like) |
|
| 1270 | + $this->basic_model->or_like($or_like[0], $or_like[1], $or_like[2]); |
|
| 1277 | 1271 | |
| 1278 | - if(!empty($this->having)) |
|
| 1279 | - foreach($this->having as $having) |
|
| 1280 | - $this->basic_model->having($having[0],$having[1],$having[2]); |
|
| 1272 | + if (!empty($this->having)) |
|
| 1273 | + foreach ($this->having as $having) |
|
| 1274 | + $this->basic_model->having($having[0], $having[1], $having[2]); |
|
| 1281 | 1275 | |
| 1282 | - if(!empty($this->or_having)) |
|
| 1283 | - foreach($this->or_having as $or_having) |
|
| 1284 | - $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
|
| 1276 | + if (!empty($this->or_having)) |
|
| 1277 | + foreach ($this->or_having as $or_having) |
|
| 1278 | + $this->basic_model->or_having($or_having[0], $or_having[1], $or_having[2]); |
|
| 1285 | 1279 | |
| 1286 | - if(!empty($this->relation)) |
|
| 1287 | - foreach($this->relation as $relation) |
|
| 1288 | - $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
|
| 1280 | + if (!empty($this->relation)) |
|
| 1281 | + foreach ($this->relation as $relation) |
|
| 1282 | + $this->basic_model->join_relation($relation[0], $relation[1], $relation[2]); |
|
| 1289 | 1283 | |
| 1290 | - if(!empty($this->relation_n_n)) |
|
| 1284 | + if (!empty($this->relation_n_n)) |
|
| 1291 | 1285 | { |
| 1292 | 1286 | $columns = $this->get_columns(); |
| 1293 | - foreach($columns as $column) |
|
| 1287 | + foreach ($columns as $column) |
|
| 1294 | 1288 | { |
| 1295 | 1289 | //Use the relation_n_n ONLY if the column is called . The set_relation_n_n are slow and it will make the table slower without any reason as we don't need those queries. |
| 1296 | - if(isset($this->relation_n_n[$column->field_name])) |
|
| 1290 | + if (isset($this->relation_n_n[$column->field_name])) |
|
| 1297 | 1291 | { |
| 1298 | 1292 | $this->basic_model->set_relation_n_n_field($this->relation_n_n[$column->field_name]); |
| 1299 | 1293 | } |
@@ -1301,12 +1295,12 @@ discard block |
||
| 1301 | 1295 | |
| 1302 | 1296 | } |
| 1303 | 1297 | |
| 1304 | - if($this->theme_config['crud_paging'] === true) |
|
| 1298 | + if ($this->theme_config['crud_paging'] === true) |
|
| 1305 | 1299 | { |
| 1306 | - if($this->limit === null) |
|
| 1300 | + if ($this->limit === null) |
|
| 1307 | 1301 | { |
| 1308 | 1302 | $default_per_page = $this->config->default_per_page; |
| 1309 | - if(is_numeric($default_per_page) && $default_per_page >1) |
|
| 1303 | + if (is_numeric($default_per_page) && $default_per_page > 1) |
|
| 1310 | 1304 | { |
| 1311 | 1305 | $this->basic_model->limit($default_per_page); |
| 1312 | 1306 | } |
@@ -1317,7 +1311,7 @@ discard block |
||
| 1317 | 1311 | } |
| 1318 | 1312 | else |
| 1319 | 1313 | { |
| 1320 | - $this->basic_model->limit($this->limit[0],$this->limit[1]); |
|
| 1314 | + $this->basic_model->limit($this->limit[0], $this->limit[1]); |
|
| 1321 | 1315 | } |
| 1322 | 1316 | } |
| 1323 | 1317 | |
@@ -1330,9 +1324,9 @@ discard block |
||
| 1330 | 1324 | { |
| 1331 | 1325 | $values = $this->basic_model->get_edit_values($primary_key_value); |
| 1332 | 1326 | |
| 1333 | - if(!empty($this->relation_n_n)) |
|
| 1327 | + if (!empty($this->relation_n_n)) |
|
| 1334 | 1328 | { |
| 1335 | - foreach($this->relation_n_n as $field_name => $field_info) |
|
| 1329 | + foreach ($this->relation_n_n as $field_name => $field_info) |
|
| 1336 | 1330 | { |
| 1337 | 1331 | $values->$field_name = $this->get_relation_n_n_selection_array($primary_key_value, $field_info); |
| 1338 | 1332 | } |
@@ -1358,17 +1352,17 @@ discard block |
||
| 1358 | 1352 | |
| 1359 | 1353 | protected function upload_file($state_info) |
| 1360 | 1354 | { |
| 1361 | - if(isset($this->upload_fields[$state_info->field_name]) ) |
|
| 1355 | + if (isset($this->upload_fields[$state_info->field_name])) |
|
| 1362 | 1356 | { |
| 1363 | - if($this->callback_upload === null) |
|
| 1357 | + if ($this->callback_upload === null) |
|
| 1364 | 1358 | { |
| 1365 | - if($this->callback_before_upload !== null) |
|
| 1359 | + if ($this->callback_before_upload !== null) |
|
| 1366 | 1360 | { |
| 1367 | - $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
| 1361 | + $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
| 1368 | 1362 | |
| 1369 | - if($callback_before_upload_response === false) |
|
| 1363 | + if ($callback_before_upload_response === false) |
|
| 1370 | 1364 | return false; |
| 1371 | - elseif(is_string($callback_before_upload_response)) |
|
| 1365 | + elseif (is_string($callback_before_upload_response)) |
|
| 1372 | 1366 | return $callback_before_upload_response; |
| 1373 | 1367 | } |
| 1374 | 1368 | |
@@ -1385,9 +1379,9 @@ discard block |
||
| 1385 | 1379 | $allowed_files = $this->config->file_upload_allow_file_types; |
| 1386 | 1380 | |
| 1387 | 1381 | $reg_exp = ''; |
| 1388 | - if(!empty($upload_info->allowed_file_types)){ |
|
| 1382 | + if (!empty($upload_info->allowed_file_types)) { |
|
| 1389 | 1383 | $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
| 1390 | - }else{ |
|
| 1384 | + } else { |
|
| 1391 | 1385 | $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
| 1392 | 1386 | } |
| 1393 | 1387 | |
@@ -1405,24 +1399,24 @@ discard block |
||
| 1405 | 1399 | $upload_handler->default_config_path = $this->default_config_path; |
| 1406 | 1400 | $uploader_response = $upload_handler->post(); |
| 1407 | 1401 | |
| 1408 | - if(is_array($uploader_response)) |
|
| 1402 | + if (is_array($uploader_response)) |
|
| 1409 | 1403 | { |
| 1410 | - foreach($uploader_response as &$response) |
|
| 1404 | + foreach ($uploader_response as &$response) |
|
| 1411 | 1405 | { |
| 1412 | 1406 | unset($response->delete_url); |
| 1413 | 1407 | unset($response->delete_type); |
| 1414 | 1408 | } |
| 1415 | 1409 | } |
| 1416 | 1410 | |
| 1417 | - if($this->callback_after_upload !== null) |
|
| 1411 | + if ($this->callback_after_upload !== null) |
|
| 1418 | 1412 | { |
| 1419 | - $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
|
| 1413 | + $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response, $this->upload_fields[$state_info->field_name], $_FILES); |
|
| 1420 | 1414 | |
| 1421 | - if($callback_after_upload_response === false) |
|
| 1415 | + if ($callback_after_upload_response === false) |
|
| 1422 | 1416 | return false; |
| 1423 | - elseif(is_string($callback_after_upload_response)) |
|
| 1417 | + elseif (is_string($callback_after_upload_response)) |
|
| 1424 | 1418 | return $callback_after_upload_response; |
| 1425 | - elseif(is_array($callback_after_upload_response)) |
|
| 1419 | + elseif (is_array($callback_after_upload_response)) |
|
| 1426 | 1420 | $uploader_response = $callback_after_upload_response; |
| 1427 | 1421 | } |
| 1428 | 1422 | |
@@ -1430,9 +1424,9 @@ discard block |
||
| 1430 | 1424 | } |
| 1431 | 1425 | else |
| 1432 | 1426 | { |
| 1433 | - $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
|
| 1427 | + $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
|
| 1434 | 1428 | |
| 1435 | - if($upload_response === false) |
|
| 1429 | + if ($upload_response === false) |
|
| 1436 | 1430 | { |
| 1437 | 1431 | return false; |
| 1438 | 1432 | } |
@@ -1451,13 +1445,13 @@ discard block |
||
| 1451 | 1445 | protected function delete_file($state_info) |
| 1452 | 1446 | { |
| 1453 | 1447 | |
| 1454 | - if(isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
| 1448 | + if (isset($state_info->field_name) && isset($this->upload_fields[$state_info->field_name])) |
|
| 1455 | 1449 | { |
| 1456 | 1450 | $upload_info = $this->upload_fields[$state_info->field_name]; |
| 1457 | 1451 | |
| 1458 | - if(file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
| 1452 | + if (file_exists("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
| 1459 | 1453 | { |
| 1460 | - if( unlink("{$upload_info->upload_path}/{$state_info->file_name}") ) |
|
| 1454 | + if (unlink("{$upload_info->upload_path}/{$state_info->file_name}")) |
|
| 1461 | 1455 | { |
| 1462 | 1456 | $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
| 1463 | 1457 | |
@@ -1482,10 +1476,10 @@ discard block |
||
| 1482 | 1476 | |
| 1483 | 1477 | protected function ajax_relation($state_info) |
| 1484 | 1478 | { |
| 1485 | - if(!isset($this->relation[$state_info->field_name])) |
|
| 1479 | + if (!isset($this->relation[$state_info->field_name])) |
|
| 1486 | 1480 | return false; |
| 1487 | 1481 | |
| 1488 | - list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
| 1482 | + list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
|
| 1489 | 1483 | |
| 1490 | 1484 | return $this->basic_model->get_ajax_relation_array($state_info->search, $field_name, $related_table, $related_field_title, $where_clause, $order_by); |
| 1491 | 1485 | } |
@@ -1521,20 +1515,20 @@ discard block |
||
| 1521 | 1515 | */ |
| 1522 | 1516 | class grocery_CRUD_Layout extends grocery_CRUD_Model_Driver |
| 1523 | 1517 | { |
| 1524 | - private $theme_path = null; |
|
| 1525 | - private $views_as_string = ''; |
|
| 1526 | - private $echo_and_die = false; |
|
| 1527 | - protected $theme = null; |
|
| 1528 | - protected $default_true_false_text = array('inactive' , 'active'); |
|
| 1518 | + private $theme_path = null; |
|
| 1519 | + private $views_as_string = ''; |
|
| 1520 | + private $echo_and_die = false; |
|
| 1521 | + protected $theme = null; |
|
| 1522 | + protected $default_true_false_text = array('inactive', 'active'); |
|
| 1529 | 1523 | |
| 1530 | 1524 | protected $css_files = array(); |
| 1531 | 1525 | protected $js_files = array(); |
| 1532 | - protected $js_lib_files = array(); |
|
| 1533 | - protected $js_config_files = array(); |
|
| 1526 | + protected $js_lib_files = array(); |
|
| 1527 | + protected $js_config_files = array(); |
|
| 1534 | 1528 | |
| 1535 | 1529 | protected function set_basic_Layout() |
| 1536 | 1530 | { |
| 1537 | - if(!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
| 1531 | + if (!file_exists($this->theme_path.$this->theme.'/views/list_template.php')) |
|
| 1538 | 1532 | { |
| 1539 | 1533 | throw new Exception('The template does not exist. Please check your files and try again.', 12); |
| 1540 | 1534 | die(); |
@@ -1545,32 +1539,32 @@ discard block |
||
| 1545 | 1539 | { |
| 1546 | 1540 | $data = $this->get_common_data(); |
| 1547 | 1541 | |
| 1548 | - $data->order_by = $this->order_by; |
|
| 1542 | + $data->order_by = $this->order_by; |
|
| 1549 | 1543 | |
| 1550 | - $data->types = $this->get_field_types(); |
|
| 1544 | + $data->types = $this->get_field_types(); |
|
| 1551 | 1545 | |
| 1552 | 1546 | $data->list = $this->get_list(); |
| 1553 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1547 | + $data->list = $this->change_list($data->list, $data->types); |
|
| 1554 | 1548 | $data->list = $this->change_list_add_actions($data->list); |
| 1555 | 1549 | |
| 1556 | 1550 | $data->total_results = $this->get_total_results(); |
| 1557 | 1551 | |
| 1558 | - $data->columns = $this->get_columns(); |
|
| 1552 | + $data->columns = $this->get_columns(); |
|
| 1559 | 1553 | |
| 1560 | - $data->success_message = $this->get_success_message_at_list($state_info); |
|
| 1554 | + $data->success_message = $this->get_success_message_at_list($state_info); |
|
| 1561 | 1555 | |
| 1562 | - $data->primary_key = $this->get_primary_key(); |
|
| 1563 | - $data->add_url = $this->getAddUrl(); |
|
| 1556 | + $data->primary_key = $this->get_primary_key(); |
|
| 1557 | + $data->add_url = $this->getAddUrl(); |
|
| 1564 | 1558 | $data->edit_url = $this->getEditUrl(); |
| 1565 | - $data->delete_url = $this->getDeleteUrl(); |
|
| 1566 | - $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
| 1559 | + $data->delete_url = $this->getDeleteUrl(); |
|
| 1560 | + $data->delete_multiple_url = $this->getDeleteMultipleUrl(); |
|
| 1567 | 1561 | $data->read_url = $this->getReadUrl(); |
| 1568 | - $data->ajax_list_url = $this->getAjaxListUrl(); |
|
| 1569 | - $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
| 1570 | - $data->export_url = $this->getExportToExcelUrl(); |
|
| 1562 | + $data->ajax_list_url = $this->getAjaxListUrl(); |
|
| 1563 | + $data->ajax_list_info_url = $this->getAjaxListInfoUrl(); |
|
| 1564 | + $data->export_url = $this->getExportToExcelUrl(); |
|
| 1571 | 1565 | $data->print_url = $this->getPrintUrl(); |
| 1572 | - $data->actions = $this->actions; |
|
| 1573 | - $data->unique_hash = $this->get_method_hash(); |
|
| 1566 | + $data->actions = $this->actions; |
|
| 1567 | + $data->unique_hash = $this->get_method_hash(); |
|
| 1574 | 1568 | $data->order_by = $this->order_by; |
| 1575 | 1569 | |
| 1576 | 1570 | $data->unset_add = $this->unset_add; |
@@ -1578,19 +1572,19 @@ discard block |
||
| 1578 | 1572 | $data->unset_read = $this->unset_read; |
| 1579 | 1573 | $data->unset_delete = $this->unset_delete; |
| 1580 | 1574 | $data->unset_export = $this->unset_export; |
| 1581 | - $data->unset_print = $this->unset_print; |
|
| 1575 | + $data->unset_print = $this->unset_print; |
|
| 1582 | 1576 | |
| 1583 | 1577 | $default_per_page = $this->config->default_per_page; |
| 1584 | 1578 | $data->paging_options = $this->config->paging_options; |
| 1585 | - $data->default_per_page = is_numeric($default_per_page) && $default_per_page >1 && in_array($default_per_page,$data->paging_options)? $default_per_page : 25; |
|
| 1579 | + $data->default_per_page = is_numeric($default_per_page) && $default_per_page > 1 && in_array($default_per_page, $data->paging_options) ? $default_per_page : 25; |
|
| 1586 | 1580 | |
| 1587 | - if($data->list === false) |
|
| 1581 | + if ($data->list === false) |
|
| 1588 | 1582 | { |
| 1589 | 1583 | throw new Exception('It is impossible to get data. Please check your model and try again.', 13); |
| 1590 | 1584 | $data->list = array(); |
| 1591 | 1585 | } |
| 1592 | 1586 | |
| 1593 | - foreach($data->list as $num_row => $row) |
|
| 1587 | + foreach ($data->list as $num_row => $row) |
|
| 1594 | 1588 | { |
| 1595 | 1589 | $data->list[$num_row]->primary_key_value = $row->{$data->primary_key}; |
| 1596 | 1590 | $data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key}; |
@@ -1598,17 +1592,17 @@ discard block |
||
| 1598 | 1592 | $data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key}; |
| 1599 | 1593 | } |
| 1600 | 1594 | |
| 1601 | - if(!$ajax) |
|
| 1595 | + if (!$ajax) |
|
| 1602 | 1596 | { |
| 1603 | 1597 | $this->_add_js_vars(array('dialog_forms' => $this->config->dialog_forms)); |
| 1604 | 1598 | |
| 1605 | - $data->list_view = $this->_theme_view('list.php',$data,true); |
|
| 1606 | - $this->_theme_view('list_template.php',$data); |
|
| 1599 | + $data->list_view = $this->_theme_view('list.php', $data, true); |
|
| 1600 | + $this->_theme_view('list_template.php', $data); |
|
| 1607 | 1601 | } |
| 1608 | 1602 | else |
| 1609 | 1603 | { |
| 1610 | 1604 | $this->set_echo_and_die(); |
| 1611 | - $this->_theme_view('list.php',$data); |
|
| 1605 | + $this->_theme_view('list.php', $data); |
|
| 1612 | 1606 | } |
| 1613 | 1607 | } |
| 1614 | 1608 | |
@@ -1616,17 +1610,17 @@ discard block |
||
| 1616 | 1610 | { |
| 1617 | 1611 | $data = $this->get_common_data(); |
| 1618 | 1612 | |
| 1619 | - $data->order_by = $this->order_by; |
|
| 1620 | - $data->types = $this->get_field_types(); |
|
| 1613 | + $data->order_by = $this->order_by; |
|
| 1614 | + $data->types = $this->get_field_types(); |
|
| 1621 | 1615 | |
| 1622 | 1616 | $data->list = $this->get_list(); |
| 1623 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1617 | + $data->list = $this->change_list($data->list, $data->types); |
|
| 1624 | 1618 | $data->list = $this->change_list_add_actions($data->list); |
| 1625 | 1619 | |
| 1626 | 1620 | $data->total_results = $this->get_total_results(); |
| 1627 | 1621 | |
| 1628 | - $data->columns = $this->get_columns(); |
|
| 1629 | - $data->primary_key = $this->get_primary_key(); |
|
| 1622 | + $data->columns = $this->get_columns(); |
|
| 1623 | + $data->primary_key = $this->get_primary_key(); |
|
| 1630 | 1624 | |
| 1631 | 1625 | @ob_end_clean(); |
| 1632 | 1626 | $this->_export_to_excel($data); |
@@ -1640,20 +1634,20 @@ discard block |
||
| 1640 | 1634 | * */ |
| 1641 | 1635 | |
| 1642 | 1636 | $string_to_export = ""; |
| 1643 | - foreach($data->columns as $column){ |
|
| 1637 | + foreach ($data->columns as $column) { |
|
| 1644 | 1638 | $string_to_export .= $column->display_as."\t"; |
| 1645 | 1639 | } |
| 1646 | 1640 | $string_to_export .= "\n"; |
| 1647 | 1641 | |
| 1648 | - foreach($data->list as $num_row => $row){ |
|
| 1649 | - foreach($data->columns as $column){ |
|
| 1642 | + foreach ($data->list as $num_row => $row) { |
|
| 1643 | + foreach ($data->columns as $column) { |
|
| 1650 | 1644 | $string_to_export .= $this->_trim_export_string($row->{$column->field_name})."\t"; |
| 1651 | 1645 | } |
| 1652 | 1646 | $string_to_export .= "\n"; |
| 1653 | 1647 | } |
| 1654 | 1648 | |
| 1655 | 1649 | // Convert to UTF-16LE and Prepend BOM |
| 1656 | - $string_to_export = "\xFF\xFE" .mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
| 1650 | + $string_to_export = "\xFF\xFE".mb_convert_encoding($string_to_export, 'UTF-16LE', 'UTF-8'); |
|
| 1657 | 1651 | |
| 1658 | 1652 | $filename = "export-".date("Y-m-d_H:i:s").".xls"; |
| 1659 | 1653 | |
@@ -1668,17 +1662,17 @@ discard block |
||
| 1668 | 1662 | { |
| 1669 | 1663 | $data = $this->get_common_data(); |
| 1670 | 1664 | |
| 1671 | - $data->order_by = $this->order_by; |
|
| 1672 | - $data->types = $this->get_field_types(); |
|
| 1665 | + $data->order_by = $this->order_by; |
|
| 1666 | + $data->types = $this->get_field_types(); |
|
| 1673 | 1667 | |
| 1674 | 1668 | $data->list = $this->get_list(); |
| 1675 | - $data->list = $this->change_list($data->list , $data->types); |
|
| 1669 | + $data->list = $this->change_list($data->list, $data->types); |
|
| 1676 | 1670 | $data->list = $this->change_list_add_actions($data->list); |
| 1677 | 1671 | |
| 1678 | 1672 | $data->total_results = $this->get_total_results(); |
| 1679 | 1673 | |
| 1680 | - $data->columns = $this->get_columns(); |
|
| 1681 | - $data->primary_key = $this->get_primary_key(); |
|
| 1674 | + $data->columns = $this->get_columns(); |
|
| 1675 | + $data->primary_key = $this->get_primary_key(); |
|
| 1682 | 1676 | |
| 1683 | 1677 | @ob_end_clean(); |
| 1684 | 1678 | $this->_print_webpage($data); |
@@ -1696,14 +1690,14 @@ discard block |
||
| 1696 | 1690 | $string_to_print .= "<div id='print-table'>"; |
| 1697 | 1691 | |
| 1698 | 1692 | $string_to_print .= '<table width="100%" cellpadding="0" cellspacing="0" ><tr>'; |
| 1699 | - foreach($data->columns as $column){ |
|
| 1693 | + foreach ($data->columns as $column) { |
|
| 1700 | 1694 | $string_to_print .= "<th>".$column->display_as."</th>"; |
| 1701 | 1695 | } |
| 1702 | 1696 | $string_to_print .= "</tr>"; |
| 1703 | 1697 | |
| 1704 | - foreach($data->list as $num_row => $row){ |
|
| 1698 | + foreach ($data->list as $num_row => $row) { |
|
| 1705 | 1699 | $string_to_print .= "<tr>"; |
| 1706 | - foreach($data->columns as $column){ |
|
| 1700 | + foreach ($data->columns as $column) { |
|
| 1707 | 1701 | $string_to_print .= "<td>".$this->_trim_print_string($row->{$column->field_name})."</td>"; |
| 1708 | 1702 | } |
| 1709 | 1703 | $string_to_print .= "</tr>"; |
@@ -1717,16 +1711,16 @@ discard block |
||
| 1717 | 1711 | |
| 1718 | 1712 | protected function _trim_export_string($value) |
| 1719 | 1713 | { |
| 1720 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1721 | - return strip_tags(str_replace(array("\t","\n","\r"),"",$value)); |
|
| 1714 | + $value = str_replace(array(" ", "&", ">", "<"), array(" ", "&", ">", "<"), $value); |
|
| 1715 | + return strip_tags(str_replace(array("\t", "\n", "\r"), "", $value)); |
|
| 1722 | 1716 | } |
| 1723 | 1717 | |
| 1724 | 1718 | protected function _trim_print_string($value) |
| 1725 | 1719 | { |
| 1726 | - $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
|
| 1720 | + $value = str_replace(array(" ", "&", ">", "<"), array(" ", "&", ">", "<"), $value); |
|
| 1727 | 1721 | |
| 1728 | 1722 | //If the value has only spaces and nothing more then add the whitespace html character |
| 1729 | - if(str_replace(" ","",$value) == "") |
|
| 1723 | + if (str_replace(" ", "", $value) == "") |
|
| 1730 | 1724 | $value = " "; |
| 1731 | 1725 | |
| 1732 | 1726 | return strip_tags($value); |
@@ -1746,7 +1740,7 @@ discard block |
||
| 1746 | 1740 | { |
| 1747 | 1741 | $this->set_echo_and_die(); |
| 1748 | 1742 | |
| 1749 | - $total_results = (int)$this->get_total_results(); |
|
| 1743 | + $total_results = (int) $this->get_total_results(); |
|
| 1750 | 1744 | @ob_end_clean(); |
| 1751 | 1745 | echo json_encode(array('total_results' => $total_results)); |
| 1752 | 1746 | die(); |
@@ -1754,17 +1748,17 @@ discard block |
||
| 1754 | 1748 | |
| 1755 | 1749 | protected function change_list_add_actions($list) |
| 1756 | 1750 | { |
| 1757 | - if(empty($this->actions)) |
|
| 1751 | + if (empty($this->actions)) |
|
| 1758 | 1752 | return $list; |
| 1759 | 1753 | |
| 1760 | 1754 | $primary_key = $this->get_primary_key(); |
| 1761 | 1755 | |
| 1762 | - foreach($list as $num_row => $row) |
|
| 1756 | + foreach ($list as $num_row => $row) |
|
| 1763 | 1757 | { |
| 1764 | 1758 | $actions_urls = array(); |
| 1765 | - foreach($this->actions as $unique_id => $action) |
|
| 1759 | + foreach ($this->actions as $unique_id => $action) |
|
| 1766 | 1760 | { |
| 1767 | - if(!empty($action->url_callback)) |
|
| 1761 | + if (!empty($action->url_callback)) |
|
| 1768 | 1762 | { |
| 1769 | 1763 | $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
| 1770 | 1764 | } |
@@ -1772,8 +1766,7 @@ discard block |
||
| 1772 | 1766 | { |
| 1773 | 1767 | $actions_urls[$unique_id] = |
| 1774 | 1768 | $action->url_has_http ? |
| 1775 | - $action->link_url.$row->$primary_key : |
|
| 1776 | - site_url($action->link_url.'/'.$row->$primary_key); |
|
| 1769 | + $action->link_url.$row->$primary_key : site_url($action->link_url.'/'.$row->$primary_key); |
|
| 1777 | 1770 | } |
| 1778 | 1771 | } |
| 1779 | 1772 | $row->action_urls = $actions_urls; |
@@ -1782,21 +1775,21 @@ discard block |
||
| 1782 | 1775 | return $list; |
| 1783 | 1776 | } |
| 1784 | 1777 | |
| 1785 | - protected function change_list($list,$types) |
|
| 1778 | + protected function change_list($list, $types) |
|
| 1786 | 1779 | { |
| 1787 | 1780 | $primary_key = $this->get_primary_key(); |
| 1788 | 1781 | $has_callbacks = !empty($this->callback_column) ? true : false; |
| 1789 | 1782 | $output_columns = $this->get_columns(); |
| 1790 | - foreach($list as $num_row => $row) |
|
| 1783 | + foreach ($list as $num_row => $row) |
|
| 1791 | 1784 | { |
| 1792 | - foreach($output_columns as $column) |
|
| 1785 | + foreach ($output_columns as $column) |
|
| 1793 | 1786 | { |
| 1794 | - $field_name = $column->field_name; |
|
| 1795 | - $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
| 1796 | - if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
| 1787 | + $field_name = $column->field_name; |
|
| 1788 | + $field_value = isset($row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
|
| 1789 | + if ($has_callbacks && isset($this->callback_column[$field_name])) |
|
| 1797 | 1790 | $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
| 1798 | - elseif(isset($types[$field_name])) |
|
| 1799 | - $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
| 1791 | + elseif (isset($types[$field_name])) |
|
| 1792 | + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name], $field_value); |
|
| 1800 | 1793 | else |
| 1801 | 1794 | $list[$num_row]->$field_name = $field_value; |
| 1802 | 1795 | } |
@@ -1809,21 +1802,21 @@ discard block |
||
| 1809 | 1802 | { |
| 1810 | 1803 | $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
| 1811 | 1804 | |
| 1812 | - $data = $this->get_common_data(); |
|
| 1813 | - $data->types = $this->get_field_types(); |
|
| 1805 | + $data = $this->get_common_data(); |
|
| 1806 | + $data->types = $this->get_field_types(); |
|
| 1814 | 1807 | |
| 1815 | - $data->list_url = $this->getListUrl(); |
|
| 1816 | - $data->insert_url = $this->getInsertUrl(); |
|
| 1817 | - $data->validation_url = $this->getValidationInsertUrl(); |
|
| 1808 | + $data->list_url = $this->getListUrl(); |
|
| 1809 | + $data->insert_url = $this->getInsertUrl(); |
|
| 1810 | + $data->validation_url = $this->getValidationInsertUrl(); |
|
| 1818 | 1811 | $data->input_fields = $this->get_add_input_fields(); |
| 1819 | 1812 | |
| 1820 | - $data->fields = $this->get_add_fields(); |
|
| 1813 | + $data->fields = $this->get_add_fields(); |
|
| 1821 | 1814 | $data->hidden_fields = $this->get_add_hidden_fields(); |
| 1822 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1815 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1823 | 1816 | $data->unique_hash = $this->get_method_hash(); |
| 1824 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1817 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1825 | 1818 | |
| 1826 | - $this->_theme_view('add.php',$data); |
|
| 1819 | + $this->_theme_view('add.php', $data); |
|
| 1827 | 1820 | $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
| 1828 | 1821 | |
| 1829 | 1822 | $this->_get_ajax_results(); |
@@ -1833,12 +1826,12 @@ discard block |
||
| 1833 | 1826 | { |
| 1834 | 1827 | $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
| 1835 | 1828 | |
| 1836 | - $data = $this->get_common_data(); |
|
| 1837 | - $data->types = $this->get_field_types(); |
|
| 1829 | + $data = $this->get_common_data(); |
|
| 1830 | + $data->types = $this->get_field_types(); |
|
| 1838 | 1831 | |
| 1839 | 1832 | $data->field_values = $this->get_edit_values($state_info->primary_key); |
| 1840 | 1833 | |
| 1841 | - $data->add_url = $this->getAddUrl(); |
|
| 1834 | + $data->add_url = $this->getAddUrl(); |
|
| 1842 | 1835 | |
| 1843 | 1836 | $data->list_url = $this->getListUrl(); |
| 1844 | 1837 | $data->update_url = $this->getUpdateUrl($state_info); |
@@ -1847,14 +1840,14 @@ discard block |
||
| 1847 | 1840 | $data->input_fields = $this->get_edit_input_fields($data->field_values); |
| 1848 | 1841 | $data->unique_hash = $this->get_method_hash(); |
| 1849 | 1842 | |
| 1850 | - $data->fields = $this->get_edit_fields(); |
|
| 1843 | + $data->fields = $this->get_edit_fields(); |
|
| 1851 | 1844 | $data->hidden_fields = $this->get_edit_hidden_fields(); |
| 1852 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1845 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1853 | 1846 | |
| 1854 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1855 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1847 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1848 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1856 | 1849 | |
| 1857 | - $this->_theme_view('edit.php',$data); |
|
| 1850 | + $this->_theme_view('edit.php', $data); |
|
| 1858 | 1851 | $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
| 1859 | 1852 | |
| 1860 | 1853 | $this->_get_ajax_results(); |
@@ -1864,12 +1857,12 @@ discard block |
||
| 1864 | 1857 | { |
| 1865 | 1858 | $this->set_js_lib($this->default_javascript_path.'/'.grocery_CRUD::JQUERY); |
| 1866 | 1859 | |
| 1867 | - $data = $this->get_common_data(); |
|
| 1868 | - $data->types = $this->get_field_types(); |
|
| 1860 | + $data = $this->get_common_data(); |
|
| 1861 | + $data->types = $this->get_field_types(); |
|
| 1869 | 1862 | |
| 1870 | 1863 | $data->field_values = $this->get_edit_values($state_info->primary_key); |
| 1871 | 1864 | |
| 1872 | - $data->add_url = $this->getAddUrl(); |
|
| 1865 | + $data->add_url = $this->getAddUrl(); |
|
| 1873 | 1866 | |
| 1874 | 1867 | $data->list_url = $this->getListUrl(); |
| 1875 | 1868 | $data->update_url = $this->getUpdateUrl($state_info); |
@@ -1878,14 +1871,14 @@ discard block |
||
| 1878 | 1871 | $data->input_fields = $this->get_read_input_fields($data->field_values); |
| 1879 | 1872 | $data->unique_hash = $this->get_method_hash(); |
| 1880 | 1873 | |
| 1881 | - $data->fields = $this->get_read_fields(); |
|
| 1874 | + $data->fields = $this->get_read_fields(); |
|
| 1882 | 1875 | $data->hidden_fields = $this->get_edit_hidden_fields(); |
| 1883 | - $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1876 | + $data->unset_back_to_list = $this->unset_back_to_list; |
|
| 1884 | 1877 | |
| 1885 | - $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1886 | - $data->is_ajax = $this->_is_ajax(); |
|
| 1878 | + $data->validation_url = $this->getValidationUpdateUrl($state_info->primary_key); |
|
| 1879 | + $data->is_ajax = $this->_is_ajax(); |
|
| 1887 | 1880 | |
| 1888 | - $this->_theme_view('read.php',$data); |
|
| 1881 | + $this->_theme_view('read.php', $data); |
|
| 1889 | 1882 | $this->_inline_js("var js_date_format = '".$this->js_date_format."';"); |
| 1890 | 1883 | |
| 1891 | 1884 | $this->_get_ajax_results(); |
@@ -1894,26 +1887,26 @@ discard block |
||
| 1894 | 1887 | protected function delete_layout($delete_result = true) |
| 1895 | 1888 | { |
| 1896 | 1889 | @ob_end_clean(); |
| 1897 | - if($delete_result === false) |
|
| 1890 | + if ($delete_result === false) |
|
| 1898 | 1891 | { |
| 1899 | 1892 | $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
| 1900 | 1893 | |
| 1901 | - echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
|
| 1894 | + echo json_encode(array('success' => $delete_result, 'error_message' => $error_message)); |
|
| 1902 | 1895 | } |
| 1903 | 1896 | else |
| 1904 | 1897 | { |
| 1905 | 1898 | $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
| 1906 | 1899 | |
| 1907 | - echo json_encode(array('success' => true , 'success_message' => $success_message)); |
|
| 1900 | + echo json_encode(array('success' => true, 'success_message' => $success_message)); |
|
| 1908 | 1901 | } |
| 1909 | 1902 | $this->set_echo_and_die(); |
| 1910 | 1903 | } |
| 1911 | 1904 | |
| 1912 | 1905 | protected function get_success_message_at_list($field_info = null) |
| 1913 | 1906 | { |
| 1914 | - if($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
| 1907 | + if ($field_info !== null && isset($field_info->success_message) && $field_info->success_message) |
|
| 1915 | 1908 | { |
| 1916 | - if(!empty($field_info->primary_key) && !$this->unset_edit) |
|
| 1909 | + if (!empty($field_info->primary_key) && !$this->unset_edit) |
|
| 1917 | 1910 | { |
| 1918 | 1911 | return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
| 1919 | 1912 | } |
@@ -1931,7 +1924,7 @@ discard block |
||
| 1931 | 1924 | protected function insert_layout($insert_result = false) |
| 1932 | 1925 | { |
| 1933 | 1926 | @ob_end_clean(); |
| 1934 | - if($insert_result === false) |
|
| 1927 | + if ($insert_result === false) |
|
| 1935 | 1928 | { |
| 1936 | 1929 | echo json_encode(array('success' => false)); |
| 1937 | 1930 | } |
@@ -1939,7 +1932,7 @@ discard block |
||
| 1939 | 1932 | { |
| 1940 | 1933 | $success_message = '<p>'.$this->l('insert_success_message'); |
| 1941 | 1934 | |
| 1942 | - if(!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
| 1935 | + if (!$this->unset_back_to_list && !empty($insert_result) && !$this->unset_edit) |
|
| 1943 | 1936 | { |
| 1944 | 1937 | $success_message .= " <a class='go-to-edit-form' href='".$this->getEditUrl($insert_result)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
| 1945 | 1938 | |
@@ -1948,7 +1941,7 @@ discard block |
||
| 1948 | 1941 | } |
| 1949 | 1942 | } |
| 1950 | 1943 | |
| 1951 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 1944 | + if (!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 1952 | 1945 | { |
| 1953 | 1946 | $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
| 1954 | 1947 | } |
@@ -1956,7 +1949,7 @@ discard block |
||
| 1956 | 1949 | $success_message .= '</p>'; |
| 1957 | 1950 | |
| 1958 | 1951 | echo json_encode(array( |
| 1959 | - 'success' => true , |
|
| 1952 | + 'success' => true, |
|
| 1960 | 1953 | 'insert_primary_key' => $insert_result, |
| 1961 | 1954 | 'success_message' => $success_message, |
| 1962 | 1955 | 'success_list_url' => $this->getListSuccessUrl($insert_result) |
@@ -1975,20 +1968,20 @@ discard block |
||
| 1975 | 1968 | protected function upload_layout($upload_result, $field_name) |
| 1976 | 1969 | { |
| 1977 | 1970 | @ob_end_clean(); |
| 1978 | - if($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
| 1971 | + if ($upload_result !== false && !is_string($upload_result) && empty($upload_result[0]->error)) |
|
| 1979 | 1972 | { |
| 1980 | 1973 | echo json_encode( |
| 1981 | - (object)array( |
|
| 1974 | + (object) array( |
|
| 1982 | 1975 | 'success' => true, |
| 1983 | 1976 | 'files' => $upload_result |
| 1984 | 1977 | )); |
| 1985 | 1978 | } |
| 1986 | 1979 | else |
| 1987 | 1980 | { |
| 1988 | - $result = (object)array('success' => false); |
|
| 1989 | - if(is_string($upload_result)) |
|
| 1981 | + $result = (object) array('success' => false); |
|
| 1982 | + if (is_string($upload_result)) |
|
| 1990 | 1983 | $result->message = $upload_result; |
| 1991 | - if(!empty($upload_result[0]->error)) |
|
| 1984 | + if (!empty($upload_result[0]->error)) |
|
| 1992 | 1985 | $result->message = $upload_result[0]->error; |
| 1993 | 1986 | |
| 1994 | 1987 | echo json_encode($result); |
@@ -2000,13 +1993,13 @@ discard block |
||
| 2000 | 1993 | protected function delete_file_layout($upload_result) |
| 2001 | 1994 | { |
| 2002 | 1995 | @ob_end_clean(); |
| 2003 | - if($upload_result !== false) |
|
| 1996 | + if ($upload_result !== false) |
|
| 2004 | 1997 | { |
| 2005 | - echo json_encode( (object)array( 'success' => true ) ); |
|
| 1998 | + echo json_encode((object) array('success' => true)); |
|
| 2006 | 1999 | } |
| 2007 | 2000 | else |
| 2008 | 2001 | { |
| 2009 | - echo json_encode((object)array('success' => false)); |
|
| 2002 | + echo json_encode((object) array('success' => false)); |
|
| 2010 | 2003 | } |
| 2011 | 2004 | |
| 2012 | 2005 | $this->set_echo_and_die(); |
@@ -2102,7 +2095,7 @@ discard block |
||
| 2102 | 2095 | protected function get_layout() |
| 2103 | 2096 | { |
| 2104 | 2097 | $js_files = $this->get_js_files(); |
| 2105 | - $css_files = $this->get_css_files(); |
|
| 2098 | + $css_files = $this->get_css_files(); |
|
| 2106 | 2099 | |
| 2107 | 2100 | $js_lib_files = $this->get_js_lib_files(); |
| 2108 | 2101 | $js_config_files = $this->get_js_config_files(); |
@@ -2127,10 +2120,10 @@ discard block |
||
| 2127 | 2120 | unset($css_files[sha1($this->default_theme_path.'/bootstrap-v4/css/bootstrap/bootstrap.min.css')]); |
| 2128 | 2121 | } |
| 2129 | 2122 | |
| 2130 | - if($this->echo_and_die === false) |
|
| 2123 | + if ($this->echo_and_die === false) |
|
| 2131 | 2124 | { |
| 2132 | 2125 | /** Initialize JavaScript variables */ |
| 2133 | - $js_vars = array( |
|
| 2126 | + $js_vars = array( |
|
| 2134 | 2127 | 'default_javascript_path' => base_url().$this->default_javascript_path, |
| 2135 | 2128 | 'default_css_path' => base_url().$this->default_css_path, |
| 2136 | 2129 | 'default_texteditor_path' => base_url().$this->default_texteditor_path, |
@@ -2139,7 +2132,7 @@ discard block |
||
| 2139 | 2132 | ); |
| 2140 | 2133 | $this->_add_js_vars($js_vars); |
| 2141 | 2134 | |
| 2142 | - return (object)array( |
|
| 2135 | + return (object) array( |
|
| 2143 | 2136 | 'js_files' => $js_files, |
| 2144 | 2137 | 'js_lib_files' => $js_lib_files, |
| 2145 | 2138 | 'js_config_files' => $js_config_files, |
@@ -2147,7 +2140,7 @@ discard block |
||
| 2147 | 2140 | 'output' => $this->views_as_string, |
| 2148 | 2141 | ); |
| 2149 | 2142 | } |
| 2150 | - elseif($this->echo_and_die === true) |
|
| 2143 | + elseif ($this->echo_and_die === true) |
|
| 2151 | 2144 | { |
| 2152 | 2145 | echo $this->views_as_string; |
| 2153 | 2146 | die(); |
@@ -2157,21 +2150,21 @@ discard block |
||
| 2157 | 2150 | protected function update_layout($update_result = false, $state_info = null) |
| 2158 | 2151 | { |
| 2159 | 2152 | @ob_end_clean(); |
| 2160 | - if($update_result === false) |
|
| 2153 | + if ($update_result === false) |
|
| 2161 | 2154 | { |
| 2162 | 2155 | echo json_encode(array('success' => $update_result)); |
| 2163 | 2156 | } |
| 2164 | 2157 | else |
| 2165 | 2158 | { |
| 2166 | 2159 | $success_message = '<p>'.$this->l('update_success_message'); |
| 2167 | - if(!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 2160 | + if (!$this->unset_back_to_list && !$this->_is_ajax()) |
|
| 2168 | 2161 | { |
| 2169 | 2162 | $success_message .= " <a href='".$this->getListUrl()."'>".$this->l('form_go_back_to_list')."</a>"; |
| 2170 | 2163 | } |
| 2171 | 2164 | $success_message .= '</p>'; |
| 2172 | 2165 | |
| 2173 | 2166 | echo json_encode(array( |
| 2174 | - 'success' => true , |
|
| 2167 | + 'success' => true, |
|
| 2175 | 2168 | 'insert_primary_key' => $update_result, |
| 2176 | 2169 | 'success_message' => $success_message, |
| 2177 | 2170 | 'success_list_url' => $this->getListSuccessUrl($state_info->primary_key) |
@@ -2180,24 +2173,24 @@ discard block |
||
| 2180 | 2173 | $this->set_echo_and_die(); |
| 2181 | 2174 | } |
| 2182 | 2175 | |
| 2183 | - protected function get_integer_input($field_info,$value) |
|
| 2176 | + protected function get_integer_input($field_info, $value) |
|
| 2184 | 2177 | { |
| 2185 | 2178 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
| 2186 | 2179 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
| 2187 | 2180 | $extra_attributes = ''; |
| 2188 | - if(!empty($field_info->db_max_length)) |
|
| 2181 | + if (!empty($field_info->db_max_length)) |
|
| 2189 | 2182 | $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
| 2190 | 2183 | $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
| 2191 | 2184 | return $input; |
| 2192 | 2185 | } |
| 2193 | 2186 | |
| 2194 | - protected function get_true_false_input($field_info,$value) |
|
| 2187 | + protected function get_true_false_input($field_info, $value) |
|
| 2195 | 2188 | { |
| 2196 | 2189 | $value_is_null = empty($value) && $value !== '0' && $value !== 0 ? true : false; |
| 2197 | 2190 | |
| 2198 | 2191 | $input = "<div class='pretty-radio-buttons'>"; |
| 2199 | 2192 | |
| 2200 | - $true_string = is_array($field_info->extras) && array_key_exists(1,$field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
| 2193 | + $true_string = is_array($field_info->extras) && array_key_exists(1, $field_info->extras) ? $field_info->extras[1] : $this->default_true_false_text[1]; |
|
| 2201 | 2194 | $checked = $value === '1' || ($value_is_null && $field_info->default === '1') ? "checked = 'checked'" : ""; |
| 2202 | 2195 | $input .= |
| 2203 | 2196 | "<div class=\"radio\"><label> |
@@ -2205,7 +2198,7 @@ discard block |
||
| 2205 | 2198 | $true_string |
| 2206 | 2199 | </label> </div>"; |
| 2207 | 2200 | |
| 2208 | - $false_string = is_array($field_info->extras) && array_key_exists(0,$field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
| 2201 | + $false_string = is_array($field_info->extras) && array_key_exists(0, $field_info->extras) ? $field_info->extras[0] : $this->default_true_false_text[0]; |
|
| 2209 | 2202 | $checked = $value === '0' || ($value_is_null && $field_info->default === '0') ? "checked = 'checked'" : ""; |
| 2210 | 2203 | $input .= |
| 2211 | 2204 | "<div class=\"radio\"><label> |
@@ -2218,18 +2211,18 @@ discard block |
||
| 2218 | 2211 | return $input; |
| 2219 | 2212 | } |
| 2220 | 2213 | |
| 2221 | - protected function get_string_input($field_info,$value) |
|
| 2214 | + protected function get_string_input($field_info, $value) |
|
| 2222 | 2215 | { |
| 2223 | - $value = !is_string($value) ? '' : str_replace('"',""",$value); |
|
| 2216 | + $value = !is_string($value) ? '' : str_replace('"', """, $value); |
|
| 2224 | 2217 | |
| 2225 | 2218 | $extra_attributes = ''; |
| 2226 | 2219 | if (!empty($field_info->db_max_length)) { |
| 2227 | 2220 | |
| 2228 | 2221 | if (in_array($field_info->type, array("decimal", "float"))) { |
| 2229 | 2222 | $decimal_lentgh = explode(",", $field_info->db_max_length); |
| 2230 | - $decimal_lentgh = ((int)$decimal_lentgh[0]) + 1; |
|
| 2223 | + $decimal_lentgh = ((int) $decimal_lentgh[0]) + 1; |
|
| 2231 | 2224 | |
| 2232 | - $extra_attributes .= "maxlength='" . $decimal_lentgh . "'"; |
|
| 2225 | + $extra_attributes .= "maxlength='".$decimal_lentgh."'"; |
|
| 2233 | 2226 | } else { |
| 2234 | 2227 | $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
| 2235 | 2228 | } |
@@ -2239,9 +2232,9 @@ discard block |
||
| 2239 | 2232 | return $input; |
| 2240 | 2233 | } |
| 2241 | 2234 | |
| 2242 | - protected function get_text_input($field_info,$value) |
|
| 2235 | + protected function get_text_input($field_info, $value) |
|
| 2243 | 2236 | { |
| 2244 | - if($field_info->extras == 'text_editor') |
|
| 2237 | + if ($field_info->extras == 'text_editor') |
|
| 2245 | 2238 | { |
| 2246 | 2239 | $editor = $this->config->default_text_editor; |
| 2247 | 2240 | switch ($editor) { |
@@ -2276,7 +2269,7 @@ discard block |
||
| 2276 | 2269 | return $input; |
| 2277 | 2270 | } |
| 2278 | 2271 | |
| 2279 | - protected function get_datetime_input($field_info,$value) |
|
| 2272 | + protected function get_datetime_input($field_info, $value) |
|
| 2280 | 2273 | { |
| 2281 | 2274 | $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
| 2282 | 2275 | $this->set_css($this->default_css_path.'/jquery_plugins/jquery.ui.datetime.css'); |
@@ -2284,19 +2277,19 @@ discard block |
||
| 2284 | 2277 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
| 2285 | 2278 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery-ui-timepicker-addon.js'); |
| 2286 | 2279 | |
| 2287 | - if($this->language !== 'english') |
|
| 2280 | + if ($this->language !== 'english') |
|
| 2288 | 2281 | { |
| 2289 | 2282 | include($this->default_config_path.'/language_alias.php'); |
| 2290 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2283 | + if (array_key_exists($this->language, $language_alias)) |
|
| 2291 | 2284 | { |
| 2292 | 2285 | $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
| 2293 | - if(file_exists($i18n_date_js_file)) |
|
| 2286 | + if (file_exists($i18n_date_js_file)) |
|
| 2294 | 2287 | { |
| 2295 | 2288 | $this->set_js_lib($i18n_date_js_file); |
| 2296 | 2289 | } |
| 2297 | 2290 | |
| 2298 | 2291 | $i18n_datetime_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/timepicker/jquery-ui-timepicker-'.$language_alias[$this->language].'.js'; |
| 2299 | - if(file_exists($i18n_datetime_js_file)) |
|
| 2292 | + if (file_exists($i18n_datetime_js_file)) |
|
| 2300 | 2293 | { |
| 2301 | 2294 | $this->set_js_lib($i18n_datetime_js_file); |
| 2302 | 2295 | } |
@@ -2305,10 +2298,10 @@ discard block |
||
| 2305 | 2298 | |
| 2306 | 2299 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery-ui-timepicker-addon.config.js'); |
| 2307 | 2300 | |
| 2308 | - if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00'){ |
|
| 2309 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2310 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2311 | - $datetime = $date.substr($value,10); |
|
| 2301 | + if (!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00') { |
|
| 2302 | + list($year, $month, $day) = explode('-', substr($value, 0, 10)); |
|
| 2303 | + $date = date($this->php_date_format, mktime(0, 0, 0, $month, $day, $year)); |
|
| 2304 | + $datetime = $date.substr($value, 10); |
|
| 2312 | 2305 | } |
| 2313 | 2306 | else |
| 2314 | 2307 | { |
@@ -2320,37 +2313,37 @@ discard block |
||
| 2320 | 2313 | return $input; |
| 2321 | 2314 | } |
| 2322 | 2315 | |
| 2323 | - protected function get_hidden_input($field_info,$value) |
|
| 2316 | + protected function get_hidden_input($field_info, $value) |
|
| 2324 | 2317 | { |
| 2325 | - if($field_info->extras !== null && $field_info->extras != false) |
|
| 2318 | + if ($field_info->extras !== null && $field_info->extras != false) |
|
| 2326 | 2319 | $value = $field_info->extras; |
| 2327 | 2320 | $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
| 2328 | 2321 | return $input; |
| 2329 | 2322 | } |
| 2330 | 2323 | |
| 2331 | - protected function get_password_input($field_info,$value) |
|
| 2324 | + protected function get_password_input($field_info, $value) |
|
| 2332 | 2325 | { |
| 2333 | 2326 | $value = !is_string($value) ? '' : $value; |
| 2334 | 2327 | |
| 2335 | 2328 | $extra_attributes = ''; |
| 2336 | - if(!empty($field_info->db_max_length)) |
|
| 2329 | + if (!empty($field_info->db_max_length)) |
|
| 2337 | 2330 | $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
| 2338 | 2331 | $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
| 2339 | 2332 | return $input; |
| 2340 | 2333 | } |
| 2341 | 2334 | |
| 2342 | - protected function get_date_input($field_info,$value) |
|
| 2335 | + protected function get_date_input($field_info, $value) |
|
| 2343 | 2336 | { |
| 2344 | 2337 | $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
| 2345 | 2338 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS); |
| 2346 | 2339 | |
| 2347 | - if($this->language !== 'english') |
|
| 2340 | + if ($this->language !== 'english') |
|
| 2348 | 2341 | { |
| 2349 | 2342 | include($this->default_config_path.'/language_alias.php'); |
| 2350 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2343 | + if (array_key_exists($this->language, $language_alias)) |
|
| 2351 | 2344 | { |
| 2352 | 2345 | $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/datepicker/jquery.ui.datepicker-'.$language_alias[$this->language].'.js'; |
| 2353 | - if(file_exists($i18n_date_js_file)) |
|
| 2346 | + if (file_exists($i18n_date_js_file)) |
|
| 2354 | 2347 | { |
| 2355 | 2348 | $this->set_js_lib($i18n_date_js_file); |
| 2356 | 2349 | } |
@@ -2359,10 +2352,10 @@ discard block |
||
| 2359 | 2352 | |
| 2360 | 2353 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.datepicker.config.js'); |
| 2361 | 2354 | |
| 2362 | - if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 2355 | + if (!empty($value) && $value != '0000-00-00' && $value != '1970-01-01') |
|
| 2363 | 2356 | { |
| 2364 | - list($year,$month,$day) = explode('-',substr($value,0,10)); |
|
| 2365 | - $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
|
| 2357 | + list($year, $month, $day) = explode('-', substr($value, 0, 10)); |
|
| 2358 | + $date = date($this->php_date_format, mktime(0, 0, 0, $month, $day, $year)); |
|
| 2366 | 2359 | } |
| 2367 | 2360 | else |
| 2368 | 2361 | { |
@@ -2374,16 +2367,16 @@ discard block |
||
| 2374 | 2367 | return $input; |
| 2375 | 2368 | } |
| 2376 | 2369 | |
| 2377 | - protected function get_dropdown_input($field_info,$value) |
|
| 2370 | + protected function get_dropdown_input($field_info, $value) |
|
| 2378 | 2371 | { |
| 2379 | 2372 | $this->load_js_chosen(); |
| 2380 | 2373 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
| 2381 | 2374 | |
| 2382 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2375 | + $select_title = str_replace('{field_display_as}', $field_info->display_as, $this->l('set_relation_title')); |
|
| 2383 | 2376 | |
| 2384 | 2377 | $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
| 2385 | 2378 | $options = array('' => '') + $field_info->extras; |
| 2386 | - foreach($options as $option_value => $option_label) |
|
| 2379 | + foreach ($options as $option_value => $option_label) |
|
| 2387 | 2380 | { |
| 2388 | 2381 | $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
| 2389 | 2382 | $input .= "<option value='$option_value' $selected >$option_label</option>"; |
@@ -2393,18 +2386,18 @@ discard block |
||
| 2393 | 2386 | return $input; |
| 2394 | 2387 | } |
| 2395 | 2388 | |
| 2396 | - protected function get_enum_input($field_info,$value) |
|
| 2389 | + protected function get_enum_input($field_info, $value) |
|
| 2397 | 2390 | { |
| 2398 | 2391 | $this->load_js_chosen(); |
| 2399 | 2392 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
| 2400 | 2393 | |
| 2401 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2394 | + $select_title = str_replace('{field_display_as}', $field_info->display_as, $this->l('set_relation_title')); |
|
| 2402 | 2395 | |
| 2403 | 2396 | $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='chosen-select' data-placeholder='".$select_title."'>"; |
| 2404 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2397 | + $options_array = $field_info->extras !== false && is_array($field_info->extras) ? $field_info->extras : explode("','", substr($field_info->db_max_length, 1, -1)); |
|
| 2405 | 2398 | $options_array = array('' => '') + $options_array; |
| 2406 | 2399 | |
| 2407 | - foreach($options_array as $option) |
|
| 2400 | + foreach ($options_array as $option) |
|
| 2408 | 2401 | { |
| 2409 | 2402 | $selected = !empty($value) && $value == $option ? "selected='selected'" : ''; |
| 2410 | 2403 | $input .= "<option value='$option' $selected >$option</option>"; |
@@ -2422,26 +2415,26 @@ discard block |
||
| 2422 | 2415 | $read_only_value = $value; |
| 2423 | 2416 | } elseif (is_array($value)) { |
| 2424 | 2417 | $all_values = array_values($value); |
| 2425 | - $read_only_value = implode(", ",$all_values); |
|
| 2418 | + $read_only_value = implode(", ", $all_values); |
|
| 2426 | 2419 | } |
| 2427 | 2420 | |
| 2428 | 2421 | return '<div id="field-'.$field_info->name.'" class="readonly_label">'.$read_only_value.'</div>'; |
| 2429 | 2422 | } |
| 2430 | 2423 | |
| 2431 | - protected function get_set_input($field_info,$value) |
|
| 2424 | + protected function get_set_input($field_info, $value) |
|
| 2432 | 2425 | { |
| 2433 | 2426 | $this->load_js_chosen(); |
| 2434 | 2427 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
| 2435 | 2428 | |
| 2436 | - $options_array = $field_info->extras !== false && is_array($field_info->extras)? $field_info->extras : explode("','",substr($field_info->db_max_length,1,-1)); |
|
| 2437 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2429 | + $options_array = $field_info->extras !== false && is_array($field_info->extras) ? $field_info->extras : explode("','", substr($field_info->db_max_length, 1, -1)); |
|
| 2430 | + $selected_values = !empty($value) ? explode(",", $value) : array(); |
|
| 2438 | 2431 | |
| 2439 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2432 | + $select_title = str_replace('{field_display_as}', $field_info->display_as, $this->l('set_relation_title')); |
|
| 2440 | 2433 | $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
| 2441 | 2434 | |
| 2442 | - foreach($options_array as $option) |
|
| 2435 | + foreach ($options_array as $option) |
|
| 2443 | 2436 | { |
| 2444 | - $selected = !empty($value) && in_array($option,$selected_values) ? "selected='selected'" : ''; |
|
| 2437 | + $selected = !empty($value) && in_array($option, $selected_values) ? "selected='selected'" : ''; |
|
| 2445 | 2438 | $input .= "<option value='$option' $selected >$option</option>"; |
| 2446 | 2439 | } |
| 2447 | 2440 | |
@@ -2450,20 +2443,20 @@ discard block |
||
| 2450 | 2443 | return $input; |
| 2451 | 2444 | } |
| 2452 | 2445 | |
| 2453 | - protected function get_multiselect_input($field_info,$value) |
|
| 2446 | + protected function get_multiselect_input($field_info, $value) |
|
| 2454 | 2447 | { |
| 2455 | 2448 | $this->load_js_chosen(); |
| 2456 | 2449 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
| 2457 | 2450 | |
| 2458 | 2451 | $options_array = $field_info->extras; |
| 2459 | - $selected_values = !empty($value) ? explode(",",$value) : array(); |
|
| 2452 | + $selected_values = !empty($value) ? explode(",", $value) : array(); |
|
| 2460 | 2453 | |
| 2461 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2454 | + $select_title = str_replace('{field_display_as}', $field_info->display_as, $this->l('set_relation_title')); |
|
| 2462 | 2455 | $input = "<select id='field-{$field_info->name}' name='{$field_info->name}[]' multiple='multiple' size='8' class='chosen-multiple-select' data-placeholder='$select_title' style='width:510px;' >"; |
| 2463 | 2456 | |
| 2464 | - foreach($options_array as $option_value => $option_label) |
|
| 2457 | + foreach ($options_array as $option_value => $option_label) |
|
| 2465 | 2458 | { |
| 2466 | - $selected = !empty($value) && in_array($option_value,$selected_values) ? "selected='selected'" : ''; |
|
| 2459 | + $selected = !empty($value) && in_array($option_value, $selected_values) ? "selected='selected'" : ''; |
|
| 2467 | 2460 | $input .= "<option value='$option_value' $selected >$option_label</option>"; |
| 2468 | 2461 | } |
| 2469 | 2462 | |
@@ -2472,7 +2465,7 @@ discard block |
||
| 2472 | 2465 | return $input; |
| 2473 | 2466 | } |
| 2474 | 2467 | |
| 2475 | - protected function get_relation_input($field_info,$value) |
|
| 2468 | + protected function get_relation_input($field_info, $value) |
|
| 2476 | 2469 | { |
| 2477 | 2470 | $this->load_js_chosen(); |
| 2478 | 2471 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.chosen.config.js'); |
@@ -2492,23 +2485,23 @@ discard block |
||
| 2492 | 2485 | |
| 2493 | 2486 | $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
| 2494 | 2487 | |
| 2495 | - $select_title = str_replace('{field_display_as}',$field_info->display_as,$this->l('set_relation_title')); |
|
| 2488 | + $select_title = str_replace('{field_display_as}', $field_info->display_as, $this->l('set_relation_title')); |
|
| 2496 | 2489 | $input = "<select id='field-{$field_info->name}' name='{$field_info->name}' class='$ajax_or_not_class' data-placeholder='$select_title' style='width:300px'>"; |
| 2497 | 2490 | $input .= "<option value=''></option>"; |
| 2498 | 2491 | |
| 2499 | - if(!$using_ajax) |
|
| 2492 | + if (!$using_ajax) |
|
| 2500 | 2493 | { |
| 2501 | 2494 | $options_array = $this->get_relation_array($field_info->extras); |
| 2502 | - foreach($options_array as $option_value => $option) |
|
| 2495 | + foreach ($options_array as $option_value => $option) |
|
| 2503 | 2496 | { |
| 2504 | 2497 | $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
| 2505 | 2498 | $input .= "<option value='$option_value' $selected >$option</option>"; |
| 2506 | 2499 | } |
| 2507 | 2500 | } |
| 2508 | - elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
| 2501 | + elseif (!empty($value) || (is_numeric($value) && $value == '0')) //If it's ajax then we only need the selected items and not all the items |
|
| 2509 | 2502 | { |
| 2510 | 2503 | $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
| 2511 | - foreach($selected_options_array as $option_value => $option) |
|
| 2504 | + foreach ($selected_options_array as $option_value => $option) |
|
| 2512 | 2505 | { |
| 2513 | 2506 | $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
| 2514 | 2507 | } |
@@ -2518,7 +2511,7 @@ discard block |
||
| 2518 | 2511 | return $input; |
| 2519 | 2512 | } |
| 2520 | 2513 | |
| 2521 | - protected function get_relation_readonly_input($field_info,$value) |
|
| 2514 | + protected function get_relation_readonly_input($field_info, $value) |
|
| 2522 | 2515 | { |
| 2523 | 2516 | $options_array = $this->get_relation_array($field_info->extras); |
| 2524 | 2517 | |
@@ -2527,7 +2520,7 @@ discard block |
||
| 2527 | 2520 | return $this->get_readonly_input($field_info, $value); |
| 2528 | 2521 | } |
| 2529 | 2522 | |
| 2530 | - protected function get_upload_file_readonly_input($field_info,$value) |
|
| 2523 | + protected function get_upload_file_readonly_input($field_info, $value) |
|
| 2531 | 2524 | { |
| 2532 | 2525 | $file = $file_url = base_url().$field_info->extras->upload_path.'/'.$value; |
| 2533 | 2526 | |
@@ -2541,7 +2534,7 @@ discard block |
||
| 2541 | 2534 | $has_priority_field = !empty($field_info_type->extras->priority_field_relation_table) ? true : false; |
| 2542 | 2535 | $is_ie_7 = isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7') !== false) ? true : false; |
| 2543 | 2536 | |
| 2544 | - if($has_priority_field || $is_ie_7) |
|
| 2537 | + if ($has_priority_field || $is_ie_7) |
|
| 2545 | 2538 | { |
| 2546 | 2539 | $this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS); |
| 2547 | 2540 | $this->set_css($this->default_css_path.'/jquery_plugins/ui.multiselect.css'); |
@@ -2549,13 +2542,13 @@ discard block |
||
| 2549 | 2542 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/ui.multiselect.min.js'); |
| 2550 | 2543 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.multiselect.js'); |
| 2551 | 2544 | |
| 2552 | - if($this->language !== 'english') |
|
| 2545 | + if ($this->language !== 'english') |
|
| 2553 | 2546 | { |
| 2554 | 2547 | include($this->default_config_path.'/language_alias.php'); |
| 2555 | - if(array_key_exists($this->language, $language_alias)) |
|
| 2548 | + if (array_key_exists($this->language, $language_alias)) |
|
| 2556 | 2549 | { |
| 2557 | 2550 | $i18n_date_js_file = $this->default_javascript_path.'/jquery_plugins/ui/i18n/multiselect/ui-multiselect-'.$language_alias[$this->language].'.js'; |
| 2558 | - if(file_exists($i18n_date_js_file)) |
|
| 2551 | + if (file_exists($i18n_date_js_file)) |
|
| 2559 | 2552 | { |
| 2560 | 2553 | $this->set_js_lib($i18n_date_js_file); |
| 2561 | 2554 | } |
@@ -2571,29 +2564,29 @@ discard block |
||
| 2571 | 2564 | |
| 2572 | 2565 | $this->_inline_js("var ajax_relation_url = '".$this->getAjaxRelationUrl()."';\n"); |
| 2573 | 2566 | |
| 2574 | - $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
| 2575 | - $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 2567 | + $field_info = $this->relation_n_n[$field_info_type->name]; //As we use this function the relation_n_n exists, so don't need to check |
|
| 2568 | + $unselected_values = $this->get_relation_n_n_unselected_array($field_info, $selected_values); |
|
| 2576 | 2569 | |
| 2577 | - if(empty($unselected_values) && empty($selected_values)) |
|
| 2570 | + if (empty($unselected_values) && empty($selected_values)) |
|
| 2578 | 2571 | { |
| 2579 | 2572 | $input = "Please add {$field_info_type->display_as} first"; |
| 2580 | 2573 | } |
| 2581 | 2574 | else |
| 2582 | 2575 | { |
| 2583 | - $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
|
| 2576 | + $css_class = $has_priority_field || $is_ie_7 ? 'multiselect' : 'chosen-multiple-select'; |
|
| 2584 | 2577 | $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
| 2585 | 2578 | |
| 2586 | - $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
|
| 2579 | + $select_title = str_replace('{field_display_as}', $field_info_type->display_as, $this->l('set_relation_title')); |
|
| 2587 | 2580 | $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
| 2588 | 2581 | |
| 2589 | - if(!empty($unselected_values)) |
|
| 2590 | - foreach($unselected_values as $id => $name) |
|
| 2582 | + if (!empty($unselected_values)) |
|
| 2583 | + foreach ($unselected_values as $id => $name) |
|
| 2591 | 2584 | { |
| 2592 | 2585 | $input .= "<option value='$id'>$name</option>"; |
| 2593 | 2586 | } |
| 2594 | 2587 | |
| 2595 | - if(!empty($selected_values)) |
|
| 2596 | - foreach($selected_values as $id => $name) |
|
| 2588 | + if (!empty($selected_values)) |
|
| 2589 | + foreach ($selected_values as $id => $name) |
|
| 2597 | 2590 | { |
| 2598 | 2591 | $input .= "<option value='$id' selected='selected'>$name</option>"; |
| 2599 | 2592 | } |
@@ -2606,15 +2599,15 @@ discard block |
||
| 2606 | 2599 | |
| 2607 | 2600 | protected function _convert_bytes_ui_to_bytes($bytes_ui) |
| 2608 | 2601 | { |
| 2609 | - $bytes_ui = str_replace(' ','',$bytes_ui); |
|
| 2610 | - if(strstr($bytes_ui,'MB')) |
|
| 2611 | - $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
| 2612 | - elseif(strstr($bytes_ui,'KB')) |
|
| 2613 | - $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
| 2614 | - elseif(strstr($bytes_ui,'B')) |
|
| 2615 | - $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
| 2602 | + $bytes_ui = str_replace(' ', '', $bytes_ui); |
|
| 2603 | + if (strstr($bytes_ui, 'MB')) |
|
| 2604 | + $bytes = (int) (str_replace('MB', '', $bytes_ui)) * 1024 * 1024; |
|
| 2605 | + elseif (strstr($bytes_ui, 'KB')) |
|
| 2606 | + $bytes = (int) (str_replace('KB', '', $bytes_ui)) * 1024; |
|
| 2607 | + elseif (strstr($bytes_ui, 'B')) |
|
| 2608 | + $bytes = (int) (str_replace('B', '', $bytes_ui)); |
|
| 2616 | 2609 | else |
| 2617 | - $bytes = (int)($bytes_ui); |
|
| 2610 | + $bytes = (int) ($bytes_ui); |
|
| 2618 | 2611 | |
| 2619 | 2612 | return $bytes; |
| 2620 | 2613 | } |
@@ -2631,7 +2624,7 @@ discard block |
||
| 2631 | 2624 | $unique = mt_rand(); |
| 2632 | 2625 | |
| 2633 | 2626 | $allowed_files = $this->config->file_upload_allow_file_types; |
| 2634 | - $allowed_files_ui = '.'.str_replace('|',',.',$allowed_files); |
|
| 2627 | + $allowed_files_ui = '.'.str_replace('|', ',.', $allowed_files); |
|
| 2635 | 2628 | $max_file_size_ui = $this->config->file_upload_max_file_size; |
| 2636 | 2629 | $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui); |
| 2637 | 2630 | |
@@ -2651,22 +2644,22 @@ discard block |
||
| 2651 | 2644 | |
| 2652 | 2645 | var error_max_number_of_files = "'.$this->l('error_max_number_of_files').'"; |
| 2653 | 2646 | var error_accept_file_types = "'.$this->l('error_accept_file_types').'"; |
| 2654 | - var error_max_file_size = "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'"; |
|
| 2647 | + var error_max_file_size = "'.str_replace("{max_file_size}", $max_file_size_ui, $this->l('error_max_file_size')).'"; |
|
| 2655 | 2648 | var error_min_file_size = "'.$this->l('error_min_file_size').'"; |
| 2656 | 2649 | |
| 2657 | 2650 | var base_url = "'.base_url().'"; |
| 2658 | 2651 | var upload_a_file_string = "'.$this->l('form_upload_a_file').'"; |
| 2659 | 2652 | '); |
| 2660 | 2653 | |
| 2661 | - $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
| 2662 | - $file_display_none = empty($value) ? "display:none;" : ""; |
|
| 2654 | + $uploader_display_none = empty($value) ? "" : "display:none;"; |
|
| 2655 | + $file_display_none = empty($value) ? "display:none;" : ""; |
|
| 2663 | 2656 | |
| 2664 | 2657 | $is_image = !empty($value) && |
| 2665 | - ( substr($value,-4) == '.jpg' |
|
| 2666 | - || substr($value,-4) == '.png' |
|
| 2667 | - || substr($value,-5) == '.jpeg' |
|
| 2668 | - || substr($value,-4) == '.gif' |
|
| 2669 | - || substr($value,-5) == '.tiff') |
|
| 2658 | + (substr($value, -4) == '.jpg' |
|
| 2659 | + || substr($value, -4) == '.png' |
|
| 2660 | + || substr($value, -5) == '.jpeg' |
|
| 2661 | + || substr($value, -4) == '.gif' |
|
| 2662 | + || substr($value, -5) == '.tiff') |
|
| 2670 | 2663 | ? true : false; |
| 2671 | 2664 | |
| 2672 | 2665 | $image_class = $is_image ? 'image-thumbnail' : ''; |
@@ -2712,13 +2705,13 @@ discard block |
||
| 2712 | 2705 | |
| 2713 | 2706 | $input_fields = array(); |
| 2714 | 2707 | |
| 2715 | - foreach($fields as $field_num => $field) |
|
| 2708 | + foreach ($fields as $field_num => $field) |
|
| 2716 | 2709 | { |
| 2717 | 2710 | $field_info = $types[$field->field_name]; |
| 2718 | 2711 | |
| 2719 | 2712 | $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
| 2720 | 2713 | |
| 2721 | - if(!isset($this->callback_add_field[$field->field_name])) |
|
| 2714 | + if (!isset($this->callback_add_field[$field->field_name])) |
|
| 2722 | 2715 | { |
| 2723 | 2716 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2724 | 2717 | } |
@@ -2755,12 +2748,12 @@ discard block |
||
| 2755 | 2748 | |
| 2756 | 2749 | $input_fields = array(); |
| 2757 | 2750 | |
| 2758 | - foreach($fields as $field_num => $field) |
|
| 2751 | + foreach ($fields as $field_num => $field) |
|
| 2759 | 2752 | { |
| 2760 | 2753 | $field_info = $types[$field->field_name]; |
| 2761 | 2754 | |
| 2762 | 2755 | $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
| 2763 | - if(!isset($this->callback_edit_field[$field->field_name])) |
|
| 2756 | + if (!isset($this->callback_edit_field[$field->field_name])) |
|
| 2764 | 2757 | { |
| 2765 | 2758 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2766 | 2759 | } |
@@ -2813,12 +2806,12 @@ discard block |
||
| 2813 | 2806 | |
| 2814 | 2807 | $input_fields = array(); |
| 2815 | 2808 | |
| 2816 | - foreach($fields as $field_num => $field) |
|
| 2809 | + foreach ($fields as $field_num => $field) |
|
| 2817 | 2810 | { |
| 2818 | 2811 | $field_info = $types[$field->field_name]; |
| 2819 | 2812 | |
| 2820 | 2813 | $field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null; |
| 2821 | - if(!isset($this->callback_read_field[$field->field_name])) |
|
| 2814 | + if (!isset($this->callback_read_field[$field->field_name])) |
|
| 2822 | 2815 | { |
| 2823 | 2816 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2824 | 2817 | } |
@@ -2852,7 +2845,7 @@ discard block |
||
| 2852 | 2845 | protected function setThemeBasics() |
| 2853 | 2846 | { |
| 2854 | 2847 | $this->theme_path = $this->default_theme_path; |
| 2855 | - if(substr($this->theme_path,-1) != '/') |
|
| 2848 | + if (substr($this->theme_path, -1) != '/') |
|
| 2856 | 2849 | $this->theme_path = $this->theme_path.'/'; |
| 2857 | 2850 | |
| 2858 | 2851 | include($this->theme_path.$this->theme.'/config.php'); |
@@ -2873,7 +2866,7 @@ discard block |
||
| 2873 | 2866 | //Codeigniter doesn't like the $_GET requests so much! |
| 2874 | 2867 | if ($this->_is_ajax()) { |
| 2875 | 2868 | @ob_end_clean(); |
| 2876 | - $results= (object)array( |
|
| 2869 | + $results = (object) array( |
|
| 2877 | 2870 | 'output' => $this->views_as_string, |
| 2878 | 2871 | 'js_files' => array_values($this->get_js_files()), |
| 2879 | 2872 | 'js_lib_files' => array_values($this->get_js_lib_files()), |
@@ -2889,7 +2882,7 @@ discard block |
||
| 2889 | 2882 | |
| 2890 | 2883 | protected function _is_ajax() |
| 2891 | 2884 | { |
| 2892 | - return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true: false; |
|
| 2885 | + return array_key_exists('is_ajax', $_POST) && $_POST['is_ajax'] == 'true' ? true : false; |
|
| 2893 | 2886 | } |
| 2894 | 2887 | |
| 2895 | 2888 | protected function _theme_view($view, $vars = array(), $return = FALSE) |
@@ -2909,7 +2902,7 @@ discard block |
||
| 2909 | 2902 | $file_exists = TRUE; |
| 2910 | 2903 | } |
| 2911 | 2904 | |
| 2912 | - if ( ! $file_exists) |
|
| 2905 | + if (!$file_exists) |
|
| 2913 | 2906 | { |
| 2914 | 2907 | throw new Exception('Unable to load the requested file: '.$file, 16); |
| 2915 | 2908 | } |
@@ -2950,7 +2943,7 @@ discard block |
||
| 2950 | 2943 | |
| 2951 | 2944 | protected function get_views_as_string() |
| 2952 | 2945 | { |
| 2953 | - if(!empty($this->views_as_string)) |
|
| 2946 | + if (!empty($this->views_as_string)) |
|
| 2954 | 2947 | return $this->views_as_string; |
| 2955 | 2948 | else |
| 2956 | 2949 | return null; |
@@ -3028,7 +3021,7 @@ discard block |
||
| 3028 | 3021 | $first_parameter = $segment_object->first_parameter; |
| 3029 | 3022 | $second_parameter = $segment_object->second_parameter; |
| 3030 | 3023 | |
| 3031 | - $state_info = (object)array(); |
|
| 3024 | + $state_info = (object) array(); |
|
| 3032 | 3025 | |
| 3033 | 3026 | switch ($state_code) { |
| 3034 | 3027 | case self::STATE_LIST: |
@@ -3050,7 +3043,7 @@ discard block |
||
| 3050 | 3043 | if ($first_parameter !== null) { |
| 3051 | 3044 | $state_info = (object) array('primary_key' => $first_parameter); |
| 3052 | 3045 | } else { |
| 3053 | - throw new Exception('On the state "delete" the Primary key cannot be null',7); |
|
| 3046 | + throw new Exception('On the state "delete" the Primary key cannot be null', 7); |
|
| 3054 | 3047 | die(); |
| 3055 | 3048 | } |
| 3056 | 3049 | break; |
@@ -3065,30 +3058,30 @@ discard block |
||
| 3065 | 3058 | break; |
| 3066 | 3059 | |
| 3067 | 3060 | case self::STATE_INSERT: |
| 3068 | - if(!empty($_POST)) |
|
| 3061 | + if (!empty($_POST)) |
|
| 3069 | 3062 | { |
| 3070 | - $state_info = (object)array('unwrapped_data' => $_POST); |
|
| 3063 | + $state_info = (object) array('unwrapped_data' => $_POST); |
|
| 3071 | 3064 | } |
| 3072 | 3065 | else |
| 3073 | 3066 | { |
| 3074 | - throw new Exception('On the state "insert" you must have post data',8); |
|
| 3067 | + throw new Exception('On the state "insert" you must have post data', 8); |
|
| 3075 | 3068 | die(); |
| 3076 | 3069 | } |
| 3077 | 3070 | break; |
| 3078 | 3071 | |
| 3079 | 3072 | case 6: |
| 3080 | - if(!empty($_POST) && $first_parameter !== null) |
|
| 3073 | + if (!empty($_POST) && $first_parameter !== null) |
|
| 3081 | 3074 | { |
| 3082 | - $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
|
| 3075 | + $state_info = (object) array('primary_key' => $first_parameter, 'unwrapped_data' => $_POST); |
|
| 3083 | 3076 | } |
| 3084 | - elseif(empty($_POST)) |
|
| 3077 | + elseif (empty($_POST)) |
|
| 3085 | 3078 | { |
| 3086 | - throw new Exception('On the state "update" you must have post data',9); |
|
| 3079 | + throw new Exception('On the state "update" you must have post data', 9); |
|
| 3087 | 3080 | die(); |
| 3088 | 3081 | } |
| 3089 | 3082 | else |
| 3090 | 3083 | { |
| 3091 | - throw new Exception('On the state "update" the Primary key cannot be null',10); |
|
| 3084 | + throw new Exception('On the state "update" the Primary key cannot be null', 10); |
|
| 3092 | 3085 | die(); |
| 3093 | 3086 | } |
| 3094 | 3087 | break; |
@@ -3097,31 +3090,31 @@ discard block |
||
| 3097 | 3090 | case 8: |
| 3098 | 3091 | case 16: //export to excel |
| 3099 | 3092 | case 17: //print |
| 3100 | - $state_info = (object)array(); |
|
| 3101 | - if(!empty($_POST['per_page'])) |
|
| 3093 | + $state_info = (object) array(); |
|
| 3094 | + if (!empty($_POST['per_page'])) |
|
| 3102 | 3095 | { |
| 3103 | 3096 | $state_info->per_page = is_numeric($_POST['per_page']) ? $_POST['per_page'] : null; |
| 3104 | 3097 | } |
| 3105 | - if(!empty($_POST['page'])) |
|
| 3098 | + if (!empty($_POST['page'])) |
|
| 3106 | 3099 | { |
| 3107 | 3100 | $state_info->page = is_numeric($_POST['page']) ? $_POST['page'] : null; |
| 3108 | 3101 | } |
| 3109 | 3102 | //If we request an export or a print we don't care about what page we are |
| 3110 | - if($state_code === 16 || $state_code === 17) |
|
| 3103 | + if ($state_code === 16 || $state_code === 17) |
|
| 3111 | 3104 | { |
| 3112 | 3105 | $state_info->page = 1; |
| 3113 | 3106 | $state_info->per_page = 1000000; //a very big number! |
| 3114 | 3107 | } |
| 3115 | - if(!empty($_POST['order_by'][0])) |
|
| 3108 | + if (!empty($_POST['order_by'][0])) |
|
| 3116 | 3109 | { |
| 3117 | 3110 | $state_info->order_by = $_POST['order_by']; |
| 3118 | 3111 | } |
| 3119 | - if(!empty($_POST['search_text'])) |
|
| 3112 | + if (!empty($_POST['search_text'])) |
|
| 3120 | 3113 | { |
| 3121 | - if(empty($_POST['search_field'])) |
|
| 3114 | + if (empty($_POST['search_field'])) |
|
| 3122 | 3115 | { |
| 3123 | 3116 | $search_text = strip_tags($_POST['search_field']); |
| 3124 | - $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
|
| 3117 | + $state_info->search = (object) array('field' => null, 'text' => $_POST['search_text']); |
|
| 3125 | 3118 | } |
| 3126 | 3119 | else |
| 3127 | 3120 | { |
@@ -3132,8 +3125,8 @@ discard block |
||
| 3132 | 3125 | } |
| 3133 | 3126 | $state_info->search = $search_array; |
| 3134 | 3127 | } else { |
| 3135 | - $state_info->search = (object)array( |
|
| 3136 | - 'field' => strip_tags($_POST['search_field']) , |
|
| 3128 | + $state_info->search = (object) array( |
|
| 3129 | + 'field' => strip_tags($_POST['search_field']), |
|
| 3137 | 3130 | 'text' => $_POST['search_text'] ); |
| 3138 | 3131 | } |
| 3139 | 3132 | } |
@@ -3145,9 +3138,9 @@ discard block |
||
| 3145 | 3138 | break; |
| 3146 | 3139 | |
| 3147 | 3140 | case 10: |
| 3148 | - if($first_parameter !== null) |
|
| 3141 | + if ($first_parameter !== null) |
|
| 3149 | 3142 | { |
| 3150 | - $state_info = (object)array('primary_key' => $first_parameter); |
|
| 3143 | + $state_info = (object) array('primary_key' => $first_parameter); |
|
| 3151 | 3144 | } |
| 3152 | 3145 | break; |
| 3153 | 3146 | |
@@ -3162,16 +3155,16 @@ discard block |
||
| 3162 | 3155 | |
| 3163 | 3156 | case 13: |
| 3164 | 3157 | $state_info->field_name = $_POST['field_name']; |
| 3165 | - $state_info->search = $_POST['term']; |
|
| 3158 | + $state_info->search = $_POST['term']; |
|
| 3166 | 3159 | break; |
| 3167 | 3160 | |
| 3168 | 3161 | case 14: |
| 3169 | 3162 | $state_info->field_name = $_POST['field_name']; |
| 3170 | - $state_info->search = $_POST['term']; |
|
| 3163 | + $state_info->search = $_POST['term']; |
|
| 3171 | 3164 | break; |
| 3172 | 3165 | |
| 3173 | 3166 | case 15: |
| 3174 | - $state_info = (object)array( |
|
| 3167 | + $state_info = (object) array( |
|
| 3175 | 3168 | 'primary_key' => $first_parameter, |
| 3176 | 3169 | 'success_message' => true |
| 3177 | 3170 | ); |
@@ -3185,8 +3178,8 @@ discard block |
||
| 3185 | 3178 | { |
| 3186 | 3179 | $state_string = $this->get_state_info_from_url()->operation; |
| 3187 | 3180 | |
| 3188 | - if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
| 3189 | - $state_code = array_search($state_string, $this->states); |
|
| 3181 | + if ($state_string != 'unknown' && in_array($state_string, $this->states)) |
|
| 3182 | + $state_code = array_search($state_string, $this->states); |
|
| 3190 | 3183 | else |
| 3191 | 3184 | $state_code = 0; |
| 3192 | 3185 | |
@@ -3197,9 +3190,8 @@ discard block |
||
| 3197 | 3190 | { |
| 3198 | 3191 | //Easy scenario, we had set the crud_url_path |
| 3199 | 3192 | if (!empty($this->crud_url_path)) { |
| 3200 | - $state_url = !empty($this->list_url_path) && $is_list_page? |
|
| 3201 | - $this->list_url_path : |
|
| 3202 | - $this->crud_url_path.'/'.$url ; |
|
| 3193 | + $state_url = !empty($this->list_url_path) && $is_list_page ? |
|
| 3194 | + $this->list_url_path : $this->crud_url_path.'/'.$url; |
|
| 3203 | 3195 | } else { |
| 3204 | 3196 | //Complicated scenario. The crud_url_path is not specified so we are |
| 3205 | 3197 | //trying to understand what is going on from the URL. |
@@ -3211,19 +3203,19 @@ discard block |
||
| 3211 | 3203 | |
| 3212 | 3204 | $state_url_array = array(); |
| 3213 | 3205 | |
| 3214 | - if( sizeof($ci->uri->segments) > 0 ) { |
|
| 3215 | - foreach($ci->uri->segments as $num => $value) |
|
| 3206 | + if (sizeof($ci->uri->segments) > 0) { |
|
| 3207 | + foreach ($ci->uri->segments as $num => $value) |
|
| 3216 | 3208 | { |
| 3217 | 3209 | $state_url_array[$num] = $value; |
| 3218 | - if($num == ($segment_position - 1)) |
|
| 3210 | + if ($num == ($segment_position - 1)) |
|
| 3219 | 3211 | break; |
| 3220 | 3212 | } |
| 3221 | 3213 | |
| 3222 | - if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
| 3223 | - $state_url_array[$num+1] = 'index'; |
|
| 3214 | + if ($method_name == 'index' && !in_array('index', $state_url_array)) //there is a scenario that you don't have the index to your url |
|
| 3215 | + $state_url_array[$num + 1] = 'index'; |
|
| 3224 | 3216 | } |
| 3225 | 3217 | |
| 3226 | - $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
|
| 3218 | + $state_url = site_url(implode('/', $state_url_array).'/'.$url); |
|
| 3227 | 3219 | } |
| 3228 | 3220 | |
| 3229 | 3221 | return $state_url; |
@@ -3237,24 +3229,24 @@ discard block |
||
| 3237 | 3229 | $operation = 'list'; |
| 3238 | 3230 | |
| 3239 | 3231 | $segements = $ci->uri->segments; |
| 3240 | - foreach($segements as $num => $value) |
|
| 3232 | + foreach ($segements as $num => $value) |
|
| 3241 | 3233 | { |
| 3242 | - if($value != 'unknown' && in_array($value, $this->states)) |
|
| 3234 | + if ($value != 'unknown' && in_array($value, $this->states)) |
|
| 3243 | 3235 | { |
| 3244 | - $segment_position = (int)$num; |
|
| 3236 | + $segment_position = (int) $num; |
|
| 3245 | 3237 | $operation = $value; //I don't have a "break" here because I want to ensure that is the LAST segment with name that is in the array. |
| 3246 | 3238 | } |
| 3247 | 3239 | } |
| 3248 | 3240 | |
| 3249 | 3241 | $function_name = $this->get_method_name(); |
| 3250 | 3242 | |
| 3251 | - if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
| 3243 | + if ($function_name == 'index' && !in_array('index', $ci->uri->segments)) |
|
| 3252 | 3244 | $segment_position++; |
| 3253 | 3245 | |
| 3254 | - $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
|
| 3255 | - $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
|
| 3246 | + $first_parameter = isset($segements[$segment_position + 1]) ? $segements[$segment_position + 1] : null; |
|
| 3247 | + $second_parameter = isset($segements[$segment_position + 2]) ? $segements[$segment_position + 2] : null; |
|
| 3256 | 3248 | |
| 3257 | - return (object)array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
| 3249 | + return (object) array('segment_position' => $segment_position, 'operation' => $operation, 'first_parameter' => $first_parameter, 'second_parameter' => $second_parameter); |
|
| 3258 | 3250 | } |
| 3259 | 3251 | |
| 3260 | 3252 | protected function get_method_hash() |
@@ -3288,7 +3280,7 @@ discard block |
||
| 3288 | 3280 | |
| 3289 | 3281 | protected function getListUrl() |
| 3290 | 3282 | { |
| 3291 | - return $this->state_url('',true); |
|
| 3283 | + return $this->state_url('', true); |
|
| 3292 | 3284 | } |
| 3293 | 3285 | |
| 3294 | 3286 | protected function getAjaxListUrl() |
@@ -3328,7 +3320,7 @@ discard block |
||
| 3328 | 3320 | |
| 3329 | 3321 | protected function getValidationUpdateUrl($primary_key = null) |
| 3330 | 3322 | { |
| 3331 | - if($primary_key === null) |
|
| 3323 | + if ($primary_key === null) |
|
| 3332 | 3324 | return $this->state_url('update_validation'); |
| 3333 | 3325 | else |
| 3334 | 3326 | return $this->state_url('update_validation/'.$primary_key); |
@@ -3336,7 +3328,7 @@ discard block |
||
| 3336 | 3328 | |
| 3337 | 3329 | protected function getEditUrl($primary_key = null) |
| 3338 | 3330 | { |
| 3339 | - if($primary_key === null) |
|
| 3331 | + if ($primary_key === null) |
|
| 3340 | 3332 | return $this->state_url('edit'); |
| 3341 | 3333 | else |
| 3342 | 3334 | return $this->state_url('edit/'.$primary_key); |
@@ -3344,7 +3336,7 @@ discard block |
||
| 3344 | 3336 | |
| 3345 | 3337 | protected function getReadUrl($primary_key = null) |
| 3346 | 3338 | { |
| 3347 | - if($primary_key === null) |
|
| 3339 | + if ($primary_key === null) |
|
| 3348 | 3340 | return $this->state_url('read'); |
| 3349 | 3341 | else |
| 3350 | 3342 | return $this->state_url('read/'.$primary_key); |
@@ -3371,10 +3363,10 @@ discard block |
||
| 3371 | 3363 | |
| 3372 | 3364 | protected function getListSuccessUrl($primary_key = null) |
| 3373 | 3365 | { |
| 3374 | - if(empty($primary_key)) |
|
| 3375 | - return $this->state_url('success',true); |
|
| 3366 | + if (empty($primary_key)) |
|
| 3367 | + return $this->state_url('success', true); |
|
| 3376 | 3368 | else |
| 3377 | - return $this->state_url('success/'.$primary_key,true); |
|
| 3369 | + return $this->state_url('success/'.$primary_key, true); |
|
| 3378 | 3370 | } |
| 3379 | 3371 | |
| 3380 | 3372 | protected function getUploadUrl($field_name) |
@@ -3437,73 +3429,73 @@ discard block |
||
| 3437 | 3429 | */ |
| 3438 | 3430 | const VERSION = "1.5.6"; |
| 3439 | 3431 | |
| 3440 | - const JQUERY = "jquery-1.11.1.min.js"; |
|
| 3441 | - const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
| 3442 | - const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
| 3432 | + const JQUERY = "jquery-1.11.1.min.js"; |
|
| 3433 | + const JQUERY_UI_JS = "jquery-ui-1.10.3.custom.min.js"; |
|
| 3434 | + const JQUERY_UI_CSS = "jquery-ui-1.10.1.custom.min.css"; |
|
| 3443 | 3435 | |
| 3444 | 3436 | protected $state_code = null; |
| 3445 | 3437 | protected $state_info = null; |
| 3446 | - protected $columns = null; |
|
| 3438 | + protected $columns = null; |
|
| 3447 | 3439 | |
| 3448 | 3440 | private $basic_db_table_checked = false; |
| 3449 | - private $columns_checked = false; |
|
| 3441 | + private $columns_checked = false; |
|
| 3450 | 3442 | private $add_fields_checked = false; |
| 3451 | 3443 | private $edit_fields_checked = false; |
| 3452 | 3444 | private $read_fields_checked = false; |
| 3453 | 3445 | |
| 3454 | 3446 | protected $default_theme = 'flexigrid'; |
| 3455 | - protected $language = null; |
|
| 3447 | + protected $language = null; |
|
| 3456 | 3448 | protected $lang_strings = array(); |
| 3457 | - protected $php_date_format = null; |
|
| 3449 | + protected $php_date_format = null; |
|
| 3458 | 3450 | protected $js_date_format = null; |
| 3459 | 3451 | protected $ui_date_format = null; |
| 3460 | - protected $character_limiter = null; |
|
| 3452 | + protected $character_limiter = null; |
|
| 3461 | 3453 | protected $config = null; |
| 3462 | 3454 | |
| 3463 | 3455 | protected $add_fields = null; |
| 3464 | 3456 | protected $edit_fields = null; |
| 3465 | 3457 | protected $read_fields = null; |
| 3466 | - protected $add_hidden_fields = array(); |
|
| 3467 | - protected $edit_hidden_fields = array(); |
|
| 3458 | + protected $add_hidden_fields = array(); |
|
| 3459 | + protected $edit_hidden_fields = array(); |
|
| 3468 | 3460 | protected $field_types = null; |
| 3469 | 3461 | protected $basic_db_table = null; |
| 3470 | 3462 | protected $theme_config = array(); |
| 3471 | 3463 | protected $subject = null; |
| 3472 | 3464 | protected $subject_plural = null; |
| 3473 | - protected $display_as = array(); |
|
| 3465 | + protected $display_as = array(); |
|
| 3474 | 3466 | protected $order_by = null; |
| 3475 | - protected $where = array(); |
|
| 3476 | - protected $like = array(); |
|
| 3477 | - protected $having = array(); |
|
| 3478 | - protected $or_having = array(); |
|
| 3479 | - protected $limit = null; |
|
| 3480 | - protected $required_fields = array(); |
|
| 3467 | + protected $where = array(); |
|
| 3468 | + protected $like = array(); |
|
| 3469 | + protected $having = array(); |
|
| 3470 | + protected $or_having = array(); |
|
| 3471 | + protected $limit = null; |
|
| 3472 | + protected $required_fields = array(); |
|
| 3481 | 3473 | protected $_unique_fields = array(); |
| 3482 | 3474 | protected $validation_rules = array(); |
| 3483 | - protected $relation = array(); |
|
| 3475 | + protected $relation = array(); |
|
| 3484 | 3476 | protected $relation_n_n = array(); |
| 3485 | 3477 | protected $upload_fields = array(); |
| 3486 | - protected $actions = array(); |
|
| 3478 | + protected $actions = array(); |
|
| 3487 | 3479 | |
| 3488 | - protected $form_validation = null; |
|
| 3489 | - protected $change_field_type = null; |
|
| 3480 | + protected $form_validation = null; |
|
| 3481 | + protected $change_field_type = null; |
|
| 3490 | 3482 | protected $primary_keys = array(); |
| 3491 | 3483 | protected $crud_url_path = null; |
| 3492 | 3484 | protected $list_url_path = null; |
| 3493 | 3485 | |
| 3494 | 3486 | /* The unsetters */ |
| 3495 | - protected $unset_texteditor = array(); |
|
| 3496 | - protected $unset_add = false; |
|
| 3487 | + protected $unset_texteditor = array(); |
|
| 3488 | + protected $unset_add = false; |
|
| 3497 | 3489 | protected $unset_edit = false; |
| 3498 | 3490 | protected $unset_delete = false; |
| 3499 | 3491 | protected $unset_read = false; |
| 3500 | 3492 | protected $unset_jquery = false; |
| 3501 | - protected $unset_jquery_ui = false; |
|
| 3502 | - protected $unset_bootstrap = false; |
|
| 3503 | - protected $unset_list = false; |
|
| 3493 | + protected $unset_jquery_ui = false; |
|
| 3494 | + protected $unset_bootstrap = false; |
|
| 3495 | + protected $unset_list = false; |
|
| 3504 | 3496 | protected $unset_export = false; |
| 3505 | - protected $unset_print = false; |
|
| 3506 | - protected $unset_back_to_list = false; |
|
| 3497 | + protected $unset_print = false; |
|
| 3498 | + protected $unset_back_to_list = false; |
|
| 3507 | 3499 | protected $unset_columns = null; |
| 3508 | 3500 | protected $unset_add_fields = null; |
| 3509 | 3501 | protected $unset_edit_fields = null; |
@@ -3520,17 +3512,17 @@ discard block |
||
| 3520 | 3512 | protected $callback_after_delete = null; |
| 3521 | 3513 | protected $callback_delete = null; |
| 3522 | 3514 | protected $callback_column = array(); |
| 3523 | - protected $callback_add_field = array(); |
|
| 3524 | - protected $callback_edit_field = array(); |
|
| 3515 | + protected $callback_add_field = array(); |
|
| 3516 | + protected $callback_edit_field = array(); |
|
| 3525 | 3517 | protected $callback_upload = null; |
| 3526 | - protected $callback_before_upload = null; |
|
| 3527 | - protected $callback_after_upload = null; |
|
| 3528 | - |
|
| 3529 | - protected $default_javascript_path = null; //autogenerate, please do not modify |
|
| 3530 | - protected $default_css_path = null; //autogenerate, please do not modify |
|
| 3531 | - protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
| 3532 | - protected $default_theme_path = null; //autogenerate, please do not modify |
|
| 3533 | - protected $default_language_path = 'assets/grocery_crud/languages'; |
|
| 3518 | + protected $callback_before_upload = null; |
|
| 3519 | + protected $callback_after_upload = null; |
|
| 3520 | + |
|
| 3521 | + protected $default_javascript_path = null; //autogenerate, please do not modify |
|
| 3522 | + protected $default_css_path = null; //autogenerate, please do not modify |
|
| 3523 | + protected $default_texteditor_path = null; //autogenerate, please do not modify |
|
| 3524 | + protected $default_theme_path = null; //autogenerate, please do not modify |
|
| 3525 | + protected $default_language_path = 'assets/grocery_crud/languages'; |
|
| 3534 | 3526 | protected $default_config_path = 'assets/grocery_crud/config'; |
| 3535 | 3527 | protected $default_assets_path = 'assets/grocery_crud'; |
| 3536 | 3528 | |
@@ -3557,7 +3549,7 @@ discard block |
||
| 3557 | 3549 | { |
| 3558 | 3550 | $args = func_get_args(); |
| 3559 | 3551 | |
| 3560 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3552 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3561 | 3553 | { |
| 3562 | 3554 | $args = $args[0]; |
| 3563 | 3555 | } |
@@ -3580,12 +3572,12 @@ discard block |
||
| 3580 | 3572 | */ |
| 3581 | 3573 | function set_rules($field, $label = '', $rules = '') |
| 3582 | 3574 | { |
| 3583 | - if(is_string($field)) |
|
| 3575 | + if (is_string($field)) |
|
| 3584 | 3576 | { |
| 3585 | 3577 | $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
| 3586 | - }elseif(is_array($field)) |
|
| 3578 | + }elseif (is_array($field)) |
|
| 3587 | 3579 | { |
| 3588 | - foreach($field as $num_field => $field_array) |
|
| 3580 | + foreach ($field as $num_field => $field_array) |
|
| 3589 | 3581 | { |
| 3590 | 3582 | $this->validation_rules[$field_array['field']] = $field_array; |
| 3591 | 3583 | } |
@@ -3600,9 +3592,9 @@ discard block |
||
| 3600 | 3592 | * @param string $type |
| 3601 | 3593 | * @param array|string $extras |
| 3602 | 3594 | */ |
| 3603 | - public function change_field_type($field , $type, $extras = null) |
|
| 3595 | + public function change_field_type($field, $type, $extras = null) |
|
| 3604 | 3596 | { |
| 3605 | - $field_type = (object)array('type' => $type); |
|
| 3597 | + $field_type = (object) array('type' => $type); |
|
| 3606 | 3598 | |
| 3607 | 3599 | $field_type->extras = $extras; |
| 3608 | 3600 | |
@@ -3618,9 +3610,9 @@ discard block |
||
| 3618 | 3610 | * @param string $type |
| 3619 | 3611 | * @param array|string $extras |
| 3620 | 3612 | */ |
| 3621 | - public function field_type($field , $type, $extras = null) |
|
| 3613 | + public function field_type($field, $type, $extras = null) |
|
| 3622 | 3614 | { |
| 3623 | - return $this->change_field_type($field , $type, $extras); |
|
| 3615 | + return $this->change_field_type($field, $type, $extras); |
|
| 3624 | 3616 | } |
| 3625 | 3617 | |
| 3626 | 3618 | /** |
@@ -3649,11 +3641,11 @@ discard block |
||
| 3649 | 3641 | { |
| 3650 | 3642 | $args = func_get_args(); |
| 3651 | 3643 | |
| 3652 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3644 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3653 | 3645 | { |
| 3654 | 3646 | $args = $args[0]; |
| 3655 | 3647 | } |
| 3656 | - foreach($args as $arg) |
|
| 3648 | + foreach ($args as $arg) |
|
| 3657 | 3649 | { |
| 3658 | 3650 | $this->unset_texteditor[] = $arg; |
| 3659 | 3651 | } |
@@ -3792,7 +3784,7 @@ discard block |
||
| 3792 | 3784 | public function unset_operations() |
| 3793 | 3785 | { |
| 3794 | 3786 | $this->unset_add = true; |
| 3795 | - $this->unset_edit = true; |
|
| 3787 | + $this->unset_edit = true; |
|
| 3796 | 3788 | $this->unset_delete = true; |
| 3797 | 3789 | $this->unset_read = true; |
| 3798 | 3790 | $this->unset_export = true; |
@@ -3810,7 +3802,7 @@ discard block |
||
| 3810 | 3802 | { |
| 3811 | 3803 | $args = func_get_args(); |
| 3812 | 3804 | |
| 3813 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3805 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3814 | 3806 | { |
| 3815 | 3807 | $args = $args[0]; |
| 3816 | 3808 | } |
@@ -3831,7 +3823,7 @@ discard block |
||
| 3831 | 3823 | { |
| 3832 | 3824 | $args = func_get_args(); |
| 3833 | 3825 | |
| 3834 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3826 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3835 | 3827 | { |
| 3836 | 3828 | $args = $args[0]; |
| 3837 | 3829 | } |
@@ -3847,7 +3839,7 @@ discard block |
||
| 3847 | 3839 | { |
| 3848 | 3840 | $args = func_get_args(); |
| 3849 | 3841 | |
| 3850 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3842 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3851 | 3843 | { |
| 3852 | 3844 | $args = $args[0]; |
| 3853 | 3845 | } |
@@ -3861,7 +3853,7 @@ discard block |
||
| 3861 | 3853 | { |
| 3862 | 3854 | $args = func_get_args(); |
| 3863 | 3855 | |
| 3864 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3856 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3865 | 3857 | { |
| 3866 | 3858 | $args = $args[0]; |
| 3867 | 3859 | } |
@@ -3875,7 +3867,7 @@ discard block |
||
| 3875 | 3867 | { |
| 3876 | 3868 | $args = func_get_args(); |
| 3877 | 3869 | |
| 3878 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3870 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3879 | 3871 | { |
| 3880 | 3872 | $args = $args[0]; |
| 3881 | 3873 | } |
@@ -3911,7 +3903,7 @@ discard block |
||
| 3911 | 3903 | { |
| 3912 | 3904 | $args = func_get_args(); |
| 3913 | 3905 | |
| 3914 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3906 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3915 | 3907 | { |
| 3916 | 3908 | $args = $args[0]; |
| 3917 | 3909 | } |
@@ -3930,7 +3922,7 @@ discard block |
||
| 3930 | 3922 | { |
| 3931 | 3923 | $args = func_get_args(); |
| 3932 | 3924 | |
| 3933 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3925 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3934 | 3926 | { |
| 3935 | 3927 | $args = $args[0]; |
| 3936 | 3928 | } |
@@ -3948,7 +3940,7 @@ discard block |
||
| 3948 | 3940 | { |
| 3949 | 3941 | $args = func_get_args(); |
| 3950 | 3942 | |
| 3951 | - if(isset($args[0]) && is_array($args[0])) |
|
| 3943 | + if (isset($args[0]) && is_array($args[0])) |
|
| 3952 | 3944 | { |
| 3953 | 3945 | $args = $args[0]; |
| 3954 | 3946 | } |
@@ -3962,7 +3954,7 @@ discard block |
||
| 3962 | 3954 | { |
| 3963 | 3955 | $args = func_get_args(); |
| 3964 | 3956 | |
| 3965 | - if(isset($args[0]) && is_array($args[0])) { |
|
| 3957 | + if (isset($args[0]) && is_array($args[0])) { |
|
| 3966 | 3958 | $args = $args[0]; |
| 3967 | 3959 | } |
| 3968 | 3960 | |
@@ -3980,14 +3972,14 @@ discard block |
||
| 3980 | 3972 | */ |
| 3981 | 3973 | public function display_as($field_name, $display_as = null) |
| 3982 | 3974 | { |
| 3983 | - if(is_array($field_name)) |
|
| 3975 | + if (is_array($field_name)) |
|
| 3984 | 3976 | { |
| 3985 | - foreach($field_name as $field => $display_as) |
|
| 3977 | + foreach ($field_name as $field => $display_as) |
|
| 3986 | 3978 | { |
| 3987 | 3979 | $this->display_as[$field] = $display_as; |
| 3988 | 3980 | } |
| 3989 | 3981 | } |
| 3990 | - elseif($display_as !== null) |
|
| 3982 | + elseif ($display_as !== null) |
|
| 3991 | 3983 | { |
| 3992 | 3984 | $this->display_as[$field_name] = $display_as; |
| 3993 | 3985 | } |
@@ -4000,44 +3992,44 @@ discard block |
||
| 4000 | 3992 | */ |
| 4001 | 3993 | protected function _load_language() |
| 4002 | 3994 | { |
| 4003 | - if($this->language === null) |
|
| 3995 | + if ($this->language === null) |
|
| 4004 | 3996 | { |
| 4005 | 3997 | $this->language = strtolower($this->config->default_language); |
| 4006 | 3998 | } |
| 4007 | 3999 | include($this->default_language_path.'/'.$this->language.'.php'); |
| 4008 | 4000 | |
| 4009 | - foreach($lang as $handle => $lang_string) |
|
| 4010 | - if(!isset($this->lang_strings[$handle])) |
|
| 4001 | + foreach ($lang as $handle => $lang_string) |
|
| 4002 | + if (!isset($this->lang_strings[$handle])) |
|
| 4011 | 4003 | $this->lang_strings[$handle] = $lang_string; |
| 4012 | 4004 | |
| 4013 | - $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
|
| 4005 | + $this->default_true_false_text = array($this->l('form_inactive'), $this->l('form_active')); |
|
| 4014 | 4006 | $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
| 4015 | 4007 | |
| 4016 | 4008 | } |
| 4017 | 4009 | |
| 4018 | 4010 | protected function _load_date_format() |
| 4019 | 4011 | { |
| 4020 | - list($php_day, $php_month, $php_year) = array('d','m','Y'); |
|
| 4021 | - list($js_day, $js_month, $js_year) = array('dd','mm','yy'); |
|
| 4012 | + list($php_day, $php_month, $php_year) = array('d', 'm', 'Y'); |
|
| 4013 | + list($js_day, $js_month, $js_year) = array('dd', 'mm', 'yy'); |
|
| 4022 | 4014 | list($ui_day, $ui_month, $ui_year) = array($this->l('ui_day'), $this->l('ui_month'), $this->l('ui_year')); |
| 4023 | 4015 | |
| 4024 | 4016 | $date_format = $this->config->date_format; |
| 4025 | 4017 | switch ($date_format) { |
| 4026 | 4018 | case 'uk-date': |
| 4027 | - $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
| 4019 | + $this->php_date_format = "$php_day/$php_month/$php_year"; |
|
| 4028 | 4020 | $this->js_date_format = "$js_day/$js_month/$js_year"; |
| 4029 | 4021 | $this->ui_date_format = "$ui_day/$ui_month/$ui_year"; |
| 4030 | 4022 | break; |
| 4031 | 4023 | |
| 4032 | 4024 | case 'us-date': |
| 4033 | - $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
| 4025 | + $this->php_date_format = "$php_month/$php_day/$php_year"; |
|
| 4034 | 4026 | $this->js_date_format = "$js_month/$js_day/$js_year"; |
| 4035 | 4027 | $this->ui_date_format = "$ui_month/$ui_day/$ui_year"; |
| 4036 | 4028 | break; |
| 4037 | 4029 | |
| 4038 | 4030 | case 'sql-date': |
| 4039 | 4031 | default: |
| 4040 | - $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
| 4032 | + $this->php_date_format = "$php_year-$php_month-$php_day"; |
|
| 4041 | 4033 | $this->js_date_format = "$js_year-$js_month-$js_day"; |
| 4042 | 4034 | $this->ui_date_format = "$ui_year-$ui_month-$ui_day"; |
| 4043 | 4035 | break; |
@@ -4050,7 +4042,7 @@ discard block |
||
| 4050 | 4042 | * @param string $handle |
| 4051 | 4043 | * @param string $string |
| 4052 | 4044 | */ |
| 4053 | - public function set_lang_string($handle, $lang_string){ |
|
| 4045 | + public function set_lang_string($handle, $lang_string) { |
|
| 4054 | 4046 | $this->lang_strings[$handle] = $lang_string; |
| 4055 | 4047 | |
| 4056 | 4048 | return $this; |
@@ -4095,29 +4087,29 @@ discard block |
||
| 4095 | 4087 | */ |
| 4096 | 4088 | protected function get_columns() |
| 4097 | 4089 | { |
| 4098 | - if($this->columns_checked === false) |
|
| 4090 | + if ($this->columns_checked === false) |
|
| 4099 | 4091 | { |
| 4100 | 4092 | $field_types = $this->get_field_types(); |
| 4101 | - if(empty($this->columns)) |
|
| 4093 | + if (empty($this->columns)) |
|
| 4102 | 4094 | { |
| 4103 | 4095 | $this->columns = array(); |
| 4104 | - foreach($field_types as $field) |
|
| 4096 | + foreach ($field_types as $field) |
|
| 4105 | 4097 | { |
| 4106 | - if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
| 4098 | + if (!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4107 | 4099 | $this->columns[] = $field->name; |
| 4108 | 4100 | } |
| 4109 | 4101 | } |
| 4110 | 4102 | |
| 4111 | - foreach($this->columns as $col_num => $column) |
|
| 4103 | + foreach ($this->columns as $col_num => $column) |
|
| 4112 | 4104 | { |
| 4113 | 4105 | |
| 4114 | - if(isset($this->relation[$column])) |
|
| 4106 | + if (isset($this->relation[$column])) |
|
| 4115 | 4107 | { |
| 4116 | 4108 | |
| 4117 | 4109 | $new_column = $this->_unique_field_name($this->relation[$column][0]); |
| 4118 | 4110 | $this->columns[$col_num] = $new_column; |
| 4119 | 4111 | |
| 4120 | - if(isset($this->display_as[$column])) |
|
| 4112 | + if (isset($this->display_as[$column])) |
|
| 4121 | 4113 | { |
| 4122 | 4114 | $display_as = $this->display_as[$column]; |
| 4123 | 4115 | unset($this->display_as[$column]); |
@@ -4125,7 +4117,7 @@ discard block |
||
| 4125 | 4117 | } |
| 4126 | 4118 | else |
| 4127 | 4119 | { |
| 4128 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4120 | + $this->display_as[$new_column] = ucfirst(str_replace('_', ' ', $column)); |
|
| 4129 | 4121 | } |
| 4130 | 4122 | |
| 4131 | 4123 | $column = $new_column; |
@@ -4133,15 +4125,15 @@ discard block |
||
| 4133 | 4125 | } |
| 4134 | 4126 | else |
| 4135 | 4127 | { |
| 4136 | - if(!empty($this->relation)) |
|
| 4128 | + if (!empty($this->relation)) |
|
| 4137 | 4129 | { |
| 4138 | - $table_name = $this->get_table(); |
|
| 4139 | - foreach($this->relation as $relation) |
|
| 4130 | + $table_name = $this->get_table(); |
|
| 4131 | + foreach ($this->relation as $relation) |
|
| 4140 | 4132 | { |
| 4141 | - if( $relation[2] == $column ) |
|
| 4133 | + if ($relation[2] == $column) |
|
| 4142 | 4134 | { |
| 4143 | 4135 | $new_column = $table_name.'.'.$column; |
| 4144 | - if(isset($this->display_as[$column])) |
|
| 4136 | + if (isset($this->display_as[$column])) |
|
| 4145 | 4137 | { |
| 4146 | 4138 | $display_as = $this->display_as[$column]; |
| 4147 | 4139 | unset($this->display_as[$column]); |
@@ -4149,7 +4141,7 @@ discard block |
||
| 4149 | 4141 | } |
| 4150 | 4142 | else |
| 4151 | 4143 | { |
| 4152 | - $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
|
| 4144 | + $this->display_as[$new_column] = ucfirst(str_replace('_', ' ', $column)); |
|
| 4153 | 4145 | } |
| 4154 | 4146 | |
| 4155 | 4147 | $column = $new_column; |
@@ -4160,15 +4152,15 @@ discard block |
||
| 4160 | 4152 | |
| 4161 | 4153 | } |
| 4162 | 4154 | |
| 4163 | - if(isset($this->display_as[$column])) |
|
| 4164 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4165 | - elseif(isset($field_types[$column])) |
|
| 4166 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4155 | + if (isset($this->display_as[$column])) |
|
| 4156 | + $this->columns[$col_num] = (object) array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4157 | + elseif (isset($field_types[$column])) |
|
| 4158 | + $this->columns[$col_num] = (object) array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4167 | 4159 | else |
| 4168 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
| 4169 | - ucfirst(str_replace('_',' ',$column))); |
|
| 4160 | + $this->columns[$col_num] = (object) array('field_name' => $column, 'display_as' => |
|
| 4161 | + ucfirst(str_replace('_', ' ', $column))); |
|
| 4170 | 4162 | |
| 4171 | - if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
|
| 4163 | + if (!empty($this->unset_columns) && in_array($column, $this->unset_columns)) |
|
| 4172 | 4164 | { |
| 4173 | 4165 | unset($this->columns[$col_num]); |
| 4174 | 4166 | } |
@@ -4187,36 +4179,36 @@ discard block |
||
| 4187 | 4179 | */ |
| 4188 | 4180 | protected function get_add_fields() |
| 4189 | 4181 | { |
| 4190 | - if($this->add_fields_checked === false) |
|
| 4182 | + if ($this->add_fields_checked === false) |
|
| 4191 | 4183 | { |
| 4192 | 4184 | $field_types = $this->get_field_types(); |
| 4193 | - if(!empty($this->add_fields)) |
|
| 4185 | + if (!empty($this->add_fields)) |
|
| 4194 | 4186 | { |
| 4195 | - foreach($this->add_fields as $field_num => $field) |
|
| 4187 | + foreach ($this->add_fields as $field_num => $field) |
|
| 4196 | 4188 | { |
| 4197 | - if(isset($this->display_as[$field])) |
|
| 4198 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4199 | - elseif(isset($field_types[$field]->display_as)) |
|
| 4200 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4189 | + if (isset($this->display_as[$field])) |
|
| 4190 | + $this->add_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4191 | + elseif (isset($field_types[$field]->display_as)) |
|
| 4192 | + $this->add_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4201 | 4193 | else |
| 4202 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
| 4194 | + $this->add_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => ucfirst(str_replace('_', ' ', $field))); |
|
| 4203 | 4195 | } |
| 4204 | 4196 | } |
| 4205 | 4197 | else |
| 4206 | 4198 | { |
| 4207 | 4199 | $this->add_fields = array(); |
| 4208 | - foreach($field_types as $field) |
|
| 4200 | + foreach ($field_types as $field) |
|
| 4209 | 4201 | { |
| 4210 | 4202 | //Check if an unset_add_field is initialize for this field name |
| 4211 | - if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
| 4203 | + if ($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name, $this->unset_add_fields)) |
|
| 4212 | 4204 | continue; |
| 4213 | 4205 | |
| 4214 | - if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
|
| 4206 | + if ((!isset($field->db_extra) || $field->db_extra != 'auto_increment')) |
|
| 4215 | 4207 | { |
| 4216 | - if(isset($this->display_as[$field->name])) |
|
| 4217 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4208 | + if (isset($this->display_as[$field->name])) |
|
| 4209 | + $this->add_fields[] = (object) array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4218 | 4210 | else |
| 4219 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4211 | + $this->add_fields[] = (object) array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4220 | 4212 | } |
| 4221 | 4213 | } |
| 4222 | 4214 | } |
@@ -4232,34 +4224,34 @@ discard block |
||
| 4232 | 4224 | */ |
| 4233 | 4225 | protected function get_edit_fields() |
| 4234 | 4226 | { |
| 4235 | - if($this->edit_fields_checked === false) |
|
| 4227 | + if ($this->edit_fields_checked === false) |
|
| 4236 | 4228 | { |
| 4237 | 4229 | $field_types = $this->get_field_types(); |
| 4238 | - if(!empty($this->edit_fields)) |
|
| 4230 | + if (!empty($this->edit_fields)) |
|
| 4239 | 4231 | { |
| 4240 | - foreach($this->edit_fields as $field_num => $field) |
|
| 4232 | + foreach ($this->edit_fields as $field_num => $field) |
|
| 4241 | 4233 | { |
| 4242 | - if(isset($this->display_as[$field])) |
|
| 4243 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4234 | + if (isset($this->display_as[$field])) |
|
| 4235 | + $this->edit_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4244 | 4236 | else |
| 4245 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4237 | + $this->edit_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4246 | 4238 | } |
| 4247 | 4239 | } |
| 4248 | 4240 | else |
| 4249 | 4241 | { |
| 4250 | 4242 | $this->edit_fields = array(); |
| 4251 | - foreach($field_types as $field) |
|
| 4243 | + foreach ($field_types as $field) |
|
| 4252 | 4244 | { |
| 4253 | 4245 | //Check if an unset_edit_field is initialize for this field name |
| 4254 | - if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
| 4246 | + if ($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name, $this->unset_edit_fields)) |
|
| 4255 | 4247 | continue; |
| 4256 | 4248 | |
| 4257 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4249 | + if (!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4258 | 4250 | { |
| 4259 | - if(isset($this->display_as[$field->name])) |
|
| 4260 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4251 | + if (isset($this->display_as[$field->name])) |
|
| 4252 | + $this->edit_fields[] = (object) array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4261 | 4253 | else |
| 4262 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4254 | + $this->edit_fields[] = (object) array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4263 | 4255 | } |
| 4264 | 4256 | } |
| 4265 | 4257 | } |
@@ -4275,34 +4267,34 @@ discard block |
||
| 4275 | 4267 | */ |
| 4276 | 4268 | protected function get_read_fields() |
| 4277 | 4269 | { |
| 4278 | - if($this->read_fields_checked === false) |
|
| 4270 | + if ($this->read_fields_checked === false) |
|
| 4279 | 4271 | { |
| 4280 | 4272 | $field_types = $this->get_field_types(); |
| 4281 | - if(!empty($this->read_fields)) |
|
| 4273 | + if (!empty($this->read_fields)) |
|
| 4282 | 4274 | { |
| 4283 | - foreach($this->read_fields as $field_num => $field) |
|
| 4275 | + foreach ($this->read_fields as $field_num => $field) |
|
| 4284 | 4276 | { |
| 4285 | - if(isset($this->display_as[$field])) |
|
| 4286 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4277 | + if (isset($this->display_as[$field])) |
|
| 4278 | + $this->read_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4287 | 4279 | else |
| 4288 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4280 | + $this->read_fields[$field_num] = (object) array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4289 | 4281 | } |
| 4290 | 4282 | } |
| 4291 | 4283 | else |
| 4292 | 4284 | { |
| 4293 | 4285 | $this->read_fields = array(); |
| 4294 | - foreach($field_types as $field) |
|
| 4286 | + foreach ($field_types as $field) |
|
| 4295 | 4287 | { |
| 4296 | 4288 | //Check if an unset_read_field is initialize for this field name |
| 4297 | - if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
| 4289 | + if ($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name, $this->unset_read_fields)) |
|
| 4298 | 4290 | continue; |
| 4299 | 4291 | |
| 4300 | - if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4292 | + if (!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
|
| 4301 | 4293 | { |
| 4302 | - if(isset($this->display_as[$field->name])) |
|
| 4303 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4294 | + if (isset($this->display_as[$field->name])) |
|
| 4295 | + $this->read_fields[] = (object) array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4304 | 4296 | else |
| 4305 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4297 | + $this->read_fields[] = (object) array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4306 | 4298 | } |
| 4307 | 4299 | } |
| 4308 | 4300 | } |
@@ -4314,21 +4306,21 @@ discard block |
||
| 4314 | 4306 | |
| 4315 | 4307 | public function order_by($order_by, $direction = 'asc') |
| 4316 | 4308 | { |
| 4317 | - $this->order_by = array($order_by,$direction); |
|
| 4309 | + $this->order_by = array($order_by, $direction); |
|
| 4318 | 4310 | |
| 4319 | 4311 | return $this; |
| 4320 | 4312 | } |
| 4321 | 4313 | |
| 4322 | 4314 | public function where($key, $value = NULL, $escape = TRUE) |
| 4323 | 4315 | { |
| 4324 | - $this->where[] = array($key,$value,$escape); |
|
| 4316 | + $this->where[] = array($key, $value, $escape); |
|
| 4325 | 4317 | |
| 4326 | 4318 | return $this; |
| 4327 | 4319 | } |
| 4328 | 4320 | |
| 4329 | 4321 | public function or_where($key, $value = NULL, $escape = TRUE) |
| 4330 | 4322 | { |
| 4331 | - $this->or_where[] = array($key,$value,$escape); |
|
| 4323 | + $this->or_where[] = array($key, $value, $escape); |
|
| 4332 | 4324 | |
| 4333 | 4325 | return $this; |
| 4334 | 4326 | } |
@@ -4363,7 +4355,7 @@ discard block |
||
| 4363 | 4355 | |
| 4364 | 4356 | public function limit($limit, $offset = '') |
| 4365 | 4357 | { |
| 4366 | - $this->limit = array($limit,$offset); |
|
| 4358 | + $this->limit = array($limit, $offset); |
|
| 4367 | 4359 | |
| 4368 | 4360 | return $this; |
| 4369 | 4361 | } |
@@ -4381,33 +4373,33 @@ discard block |
||
| 4381 | 4373 | $ci = &get_instance(); |
| 4382 | 4374 | $ci->load->config('grocery_crud'); |
| 4383 | 4375 | |
| 4384 | - $this->config = (object)array(); |
|
| 4376 | + $this->config = (object) array(); |
|
| 4385 | 4377 | |
| 4386 | 4378 | /** Initialize all the config variables into this object */ |
| 4387 | 4379 | $this->config->default_language = $ci->config->item('grocery_crud_default_language'); |
| 4388 | - $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
| 4380 | + $this->config->date_format = $ci->config->item('grocery_crud_date_format'); |
|
| 4389 | 4381 | $this->config->default_per_page = $ci->config->item('grocery_crud_default_per_page'); |
| 4390 | - $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
| 4391 | - $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
| 4392 | - $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
| 4382 | + $this->config->file_upload_allow_file_types = $ci->config->item('grocery_crud_file_upload_allow_file_types'); |
|
| 4383 | + $this->config->file_upload_max_file_size = $ci->config->item('grocery_crud_file_upload_max_file_size'); |
|
| 4384 | + $this->config->default_text_editor = $ci->config->item('grocery_crud_default_text_editor'); |
|
| 4393 | 4385 | $this->config->text_editor_type = $ci->config->item('grocery_crud_text_editor_type'); |
| 4394 | 4386 | $this->config->character_limiter = $ci->config->item('grocery_crud_character_limiter'); |
| 4395 | - $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
| 4396 | - $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
| 4387 | + $this->config->dialog_forms = $ci->config->item('grocery_crud_dialog_forms'); |
|
| 4388 | + $this->config->paging_options = $ci->config->item('grocery_crud_paging_options'); |
|
| 4397 | 4389 | $this->config->default_theme = $ci->config->item('grocery_crud_default_theme'); |
| 4398 | 4390 | $this->config->environment = $ci->config->item('grocery_crud_environment'); |
| 4399 | 4391 | |
| 4400 | 4392 | /** Initialize default paths */ |
| 4401 | - $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
| 4402 | - $this->default_css_path = $this->default_assets_path.'/css'; |
|
| 4403 | - $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
| 4404 | - $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
| 4393 | + $this->default_javascript_path = $this->default_assets_path.'/js'; |
|
| 4394 | + $this->default_css_path = $this->default_assets_path.'/css'; |
|
| 4395 | + $this->default_texteditor_path = $this->default_assets_path.'/texteditor'; |
|
| 4396 | + $this->default_theme_path = $this->default_assets_path.'/themes'; |
|
| 4405 | 4397 | |
| 4406 | 4398 | $this->character_limiter = $this->config->character_limiter; |
| 4407 | 4399 | |
| 4408 | 4400 | if ($this->character_limiter === 0 || $this->character_limiter === '0') { |
| 4409 | 4401 | $this->character_limiter = 1000000; //a very big number |
| 4410 | - } elseif($this->character_limiter === null || $this->character_limiter === false) { |
|
| 4402 | + } elseif ($this->character_limiter === null || $this->character_limiter === false) { |
|
| 4411 | 4403 | $this->character_limiter = 30; //is better to have the number 30 rather than the 0 value |
| 4412 | 4404 | } |
| 4413 | 4405 | |
@@ -4418,11 +4410,11 @@ discard block |
||
| 4418 | 4410 | |
| 4419 | 4411 | protected function _set_primary_keys_to_model() |
| 4420 | 4412 | { |
| 4421 | - if(!empty($this->primary_keys)) |
|
| 4413 | + if (!empty($this->primary_keys)) |
|
| 4422 | 4414 | { |
| 4423 | - foreach($this->primary_keys as $primary_key) |
|
| 4415 | + foreach ($this->primary_keys as $primary_key) |
|
| 4424 | 4416 | { |
| 4425 | - $this->basic_model->set_primary_key($primary_key['field_name'],$primary_key['table_name']); |
|
| 4417 | + $this->basic_model->set_primary_key($primary_key['field_name'], $primary_key['table_name']); |
|
| 4426 | 4418 | } |
| 4427 | 4419 | } |
| 4428 | 4420 | } |
@@ -4437,7 +4429,7 @@ discard block |
||
| 4437 | 4429 | $this->_load_language(); |
| 4438 | 4430 | $this->state_code = $this->getStateCode(); |
| 4439 | 4431 | |
| 4440 | - if($this->basic_model === null) |
|
| 4432 | + if ($this->basic_model === null) |
|
| 4441 | 4433 | $this->set_default_Model(); |
| 4442 | 4434 | |
| 4443 | 4435 | $this->set_basic_db_table($this->get_table()); |
@@ -4458,7 +4450,7 @@ discard block |
||
| 4458 | 4450 | { |
| 4459 | 4451 | $this->pre_render(); |
| 4460 | 4452 | |
| 4461 | - if( $this->state_code != 0 ) |
|
| 4453 | + if ($this->state_code != 0) |
|
| 4462 | 4454 | { |
| 4463 | 4455 | $this->state_info = $this->getStateInfo(); |
| 4464 | 4456 | } |
@@ -4471,13 +4463,13 @@ discard block |
||
| 4471 | 4463 | switch ($this->state_code) { |
| 4472 | 4464 | case 15://success |
| 4473 | 4465 | case 1://list |
| 4474 | - if($this->unset_list) |
|
| 4466 | + if ($this->unset_list) |
|
| 4475 | 4467 | { |
| 4476 | 4468 | throw new Exception('You don\'t have permissions for this operation', 14); |
| 4477 | 4469 | die(); |
| 4478 | 4470 | } |
| 4479 | 4471 | |
| 4480 | - if($this->theme === null) |
|
| 4472 | + if ($this->theme === null) |
|
| 4481 | 4473 | $this->set_theme($this->default_theme); |
| 4482 | 4474 | $this->setThemeBasics(); |
| 4483 | 4475 | |
@@ -4485,18 +4477,18 @@ discard block |
||
| 4485 | 4477 | |
| 4486 | 4478 | $state_info = $this->getStateInfo(); |
| 4487 | 4479 | |
| 4488 | - $this->showList(false,$state_info); |
|
| 4480 | + $this->showList(false, $state_info); |
|
| 4489 | 4481 | |
| 4490 | 4482 | break; |
| 4491 | 4483 | |
| 4492 | 4484 | case 2://add |
| 4493 | - if($this->unset_add) |
|
| 4485 | + if ($this->unset_add) |
|
| 4494 | 4486 | { |
| 4495 | 4487 | throw new Exception('You don\'t have permissions for this operation', 14); |
| 4496 | 4488 | die(); |
| 4497 | 4489 | } |
| 4498 | 4490 | |
| 4499 | - if($this->theme === null) |
|
| 4491 | + if ($this->theme === null) |
|
| 4500 | 4492 | $this->set_theme($this->default_theme); |
| 4501 | 4493 | $this->setThemeBasics(); |
| 4502 | 4494 | |
@@ -4507,13 +4499,13 @@ discard block |
||
| 4507 | 4499 | break; |
| 4508 | 4500 | |
| 4509 | 4501 | case 3://edit |
| 4510 | - if($this->unset_edit) |
|
| 4502 | + if ($this->unset_edit) |
|
| 4511 | 4503 | { |
| 4512 | 4504 | throw new Exception('You don\'t have permissions for this operation', 14); |
| 4513 | 4505 | die(); |
| 4514 | 4506 | } |
| 4515 | 4507 | |
| 4516 | - if($this->theme === null) |
|
| 4508 | + if ($this->theme === null) |
|
| 4517 | 4509 | $this->set_theme($this->default_theme); |
| 4518 | 4510 | $this->setThemeBasics(); |
| 4519 | 4511 | |
@@ -4526,7 +4518,7 @@ discard block |
||
| 4526 | 4518 | break; |
| 4527 | 4519 | |
| 4528 | 4520 | case 4://delete |
| 4529 | - if($this->unset_delete) |
|
| 4521 | + if ($this->unset_delete) |
|
| 4530 | 4522 | { |
| 4531 | 4523 | throw new Exception('This user is not allowed to do this operation', 14); |
| 4532 | 4524 | die(); |
@@ -4535,11 +4527,11 @@ discard block |
||
| 4535 | 4527 | $state_info = $this->getStateInfo(); |
| 4536 | 4528 | $delete_result = $this->db_delete($state_info); |
| 4537 | 4529 | |
| 4538 | - $this->delete_layout( $delete_result ); |
|
| 4530 | + $this->delete_layout($delete_result); |
|
| 4539 | 4531 | break; |
| 4540 | 4532 | |
| 4541 | 4533 | case 5://insert |
| 4542 | - if($this->unset_add) |
|
| 4534 | + if ($this->unset_add) |
|
| 4543 | 4535 | { |
| 4544 | 4536 | throw new Exception('This user is not allowed to do this operation', 14); |
| 4545 | 4537 | die(); |
@@ -4552,7 +4544,7 @@ discard block |
||
| 4552 | 4544 | break; |
| 4553 | 4545 | |
| 4554 | 4546 | case 6://update |
| 4555 | - if($this->unset_edit) |
|
| 4547 | + if ($this->unset_edit) |
|
| 4556 | 4548 | { |
| 4557 | 4549 | throw new Exception('This user is not allowed to do this operation', 14); |
| 4558 | 4550 | die(); |
@@ -4561,18 +4553,18 @@ discard block |
||
| 4561 | 4553 | $state_info = $this->getStateInfo(); |
| 4562 | 4554 | $update_result = $this->db_update($state_info); |
| 4563 | 4555 | |
| 4564 | - $this->update_layout( $update_result,$state_info); |
|
| 4556 | + $this->update_layout($update_result, $state_info); |
|
| 4565 | 4557 | break; |
| 4566 | 4558 | |
| 4567 | 4559 | case 7://ajax_list |
| 4568 | 4560 | |
| 4569 | - if($this->unset_list) |
|
| 4561 | + if ($this->unset_list) |
|
| 4570 | 4562 | { |
| 4571 | 4563 | throw new Exception('You don\'t have permissions for this operation', 14); |
| 4572 | 4564 | die(); |
| 4573 | 4565 | } |
| 4574 | 4566 | |
| 4575 | - if($this->theme === null) |
|
| 4567 | + if ($this->theme === null) |
|
| 4576 | 4568 | $this->set_theme($this->default_theme); |
| 4577 | 4569 | $this->setThemeBasics(); |
| 4578 | 4570 | |
@@ -4587,7 +4579,7 @@ discard block |
||
| 4587 | 4579 | |
| 4588 | 4580 | case 8://ajax_list_info |
| 4589 | 4581 | |
| 4590 | - if($this->theme === null) |
|
| 4582 | + if ($this->theme === null) |
|
| 4591 | 4583 | $this->set_theme($this->default_theme); |
| 4592 | 4584 | $this->setThemeBasics(); |
| 4593 | 4585 | |
@@ -4650,13 +4642,13 @@ discard block |
||
| 4650 | 4642 | //a big number just to ensure that the table characters will not be cutted. |
| 4651 | 4643 | $this->character_limiter = 1000000; |
| 4652 | 4644 | |
| 4653 | - if($this->unset_export) |
|
| 4645 | + if ($this->unset_export) |
|
| 4654 | 4646 | { |
| 4655 | 4647 | throw new Exception('You don\'t have permissions for this operation', 15); |
| 4656 | 4648 | die(); |
| 4657 | 4649 | } |
| 4658 | 4650 | |
| 4659 | - if($this->theme === null) |
|
| 4651 | + if ($this->theme === null) |
|
| 4660 | 4652 | $this->set_theme($this->default_theme); |
| 4661 | 4653 | $this->setThemeBasics(); |
| 4662 | 4654 | |
@@ -4671,13 +4663,13 @@ discard block |
||
| 4671 | 4663 | //a big number just to ensure that the table characters will not be cutted. |
| 4672 | 4664 | $this->character_limiter = 1000000; |
| 4673 | 4665 | |
| 4674 | - if($this->unset_print) |
|
| 4666 | + if ($this->unset_print) |
|
| 4675 | 4667 | { |
| 4676 | 4668 | throw new Exception('You don\'t have permissions for this operation', 15); |
| 4677 | 4669 | die(); |
| 4678 | 4670 | } |
| 4679 | 4671 | |
| 4680 | - if($this->theme === null) |
|
| 4672 | + if ($this->theme === null) |
|
| 4681 | 4673 | $this->set_theme($this->default_theme); |
| 4682 | 4674 | $this->setThemeBasics(); |
| 4683 | 4675 | |
@@ -4689,13 +4681,13 @@ discard block |
||
| 4689 | 4681 | break; |
| 4690 | 4682 | |
| 4691 | 4683 | case grocery_CRUD_States::STATE_READ: |
| 4692 | - if($this->unset_read) |
|
| 4684 | + if ($this->unset_read) |
|
| 4693 | 4685 | { |
| 4694 | 4686 | throw new Exception('You don\'t have permissions for this operation', 14); |
| 4695 | 4687 | die(); |
| 4696 | 4688 | } |
| 4697 | 4689 | |
| 4698 | - if($this->theme === null) |
|
| 4690 | + if ($this->theme === null) |
|
| 4699 | 4691 | $this->set_theme($this->default_theme); |
| 4700 | 4692 | $this->setThemeBasics(); |
| 4701 | 4693 | |
@@ -4709,7 +4701,7 @@ discard block |
||
| 4709 | 4701 | |
| 4710 | 4702 | case grocery_CRUD_States::STATE_DELETE_MULTIPLE: |
| 4711 | 4703 | |
| 4712 | - if($this->unset_delete) |
|
| 4704 | + if ($this->unset_delete) |
|
| 4713 | 4705 | { |
| 4714 | 4706 | throw new Exception('This user is not allowed to do this operation'); |
| 4715 | 4707 | die(); |
@@ -4729,10 +4721,10 @@ discard block |
||
| 4729 | 4721 | |
| 4730 | 4722 | protected function get_common_data() |
| 4731 | 4723 | { |
| 4732 | - $data = (object)array(); |
|
| 4724 | + $data = (object) array(); |
|
| 4733 | 4725 | |
| 4734 | - $data->subject = $this->subject; |
|
| 4735 | - $data->subject_plural = $this->subject_plural; |
|
| 4726 | + $data->subject = $this->subject; |
|
| 4727 | + $data->subject_plural = $this->subject_plural; |
|
| 4736 | 4728 | |
| 4737 | 4729 | return $data; |
| 4738 | 4730 | } |
@@ -4845,7 +4837,7 @@ discard block |
||
| 4845 | 4837 | * @param string $column |
| 4846 | 4838 | * @param mixed $callback |
| 4847 | 4839 | */ |
| 4848 | - public function callback_column($column ,$callback = null) |
|
| 4840 | + public function callback_column($column, $callback = null) |
|
| 4849 | 4841 | { |
| 4850 | 4842 | $this->callback_column[$column] = $callback; |
| 4851 | 4843 | |
@@ -4940,15 +4932,15 @@ discard block |
||
| 4940 | 4932 | */ |
| 4941 | 4933 | public function get_table() |
| 4942 | 4934 | { |
| 4943 | - if($this->basic_db_table_checked) |
|
| 4935 | + if ($this->basic_db_table_checked) |
|
| 4944 | 4936 | { |
| 4945 | 4937 | return $this->basic_db_table; |
| 4946 | 4938 | } |
| 4947 | - elseif( $this->basic_db_table !== null ) |
|
| 4939 | + elseif ($this->basic_db_table !== null) |
|
| 4948 | 4940 | { |
| 4949 | - if(!$this->table_exists($this->basic_db_table)) |
|
| 4941 | + if (!$this->table_exists($this->basic_db_table)) |
|
| 4950 | 4942 | { |
| 4951 | - throw new Exception('The table name does not exist. Please check you database and try again.',11); |
|
| 4943 | + throw new Exception('The table name does not exist. Please check you database and try again.', 11); |
|
| 4952 | 4944 | die(); |
| 4953 | 4945 | } |
| 4954 | 4946 | $this->basic_db_table_checked = true; |
@@ -4958,7 +4950,7 @@ discard block |
||
| 4958 | 4950 | { |
| 4959 | 4951 | //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
| 4960 | 4952 | $last_chance_table_name = $this->get_method_name(); |
| 4961 | - if($this->table_exists($last_chance_table_name)) |
|
| 4953 | + if ($this->table_exists($last_chance_table_name)) |
|
| 4962 | 4954 | { |
| 4963 | 4955 | $this->set_table($last_chance_table_name); |
| 4964 | 4956 | } |
@@ -4978,7 +4970,7 @@ discard block |
||
| 4978 | 4970 | { |
| 4979 | 4971 | $args = func_get_args(); |
| 4980 | 4972 | |
| 4981 | - if(isset($args[0]) && is_array($args[0])) |
|
| 4973 | + if (isset($args[0]) && is_array($args[0])) |
|
| 4982 | 4974 | { |
| 4983 | 4975 | $args = $args[0]; |
| 4984 | 4976 | } |
@@ -4997,7 +4989,7 @@ discard block |
||
| 4997 | 4989 | { |
| 4998 | 4990 | $args = func_get_args(); |
| 4999 | 4991 | |
| 5000 | - if(isset($args[0]) && is_array($args[0])) |
|
| 4992 | + if (isset($args[0]) && is_array($args[0])) |
|
| 5001 | 4993 | { |
| 5002 | 4994 | $args = $args[0]; |
| 5003 | 4995 | } |
@@ -5015,11 +5007,11 @@ discard block |
||
| 5015 | 5007 | */ |
| 5016 | 5008 | public function set_table($table_name) |
| 5017 | 5009 | { |
| 5018 | - if(!empty($table_name) && $this->basic_db_table === null) |
|
| 5010 | + if (!empty($table_name) && $this->basic_db_table === null) |
|
| 5019 | 5011 | { |
| 5020 | 5012 | $this->basic_db_table = $table_name; |
| 5021 | 5013 | } |
| 5022 | - elseif(!empty($table_name)) |
|
| 5014 | + elseif (!empty($table_name)) |
|
| 5023 | 5015 | { |
| 5024 | 5016 | throw new Exception('You have already insert a table name once...', 1); |
| 5025 | 5017 | } |
@@ -5076,7 +5068,7 @@ discard block |
||
| 5076 | 5068 | public function set_subject($subject, $subject_plural = null) |
| 5077 | 5069 | { |
| 5078 | 5070 | $this->subject = $subject; |
| 5079 | - $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; |
|
| 5071 | + $this->subject_plural = $subject_plural === null ? $subject : $subject_plural; |
|
| 5080 | 5072 | |
| 5081 | 5073 | return $this; |
| 5082 | 5074 | } |
@@ -5090,17 +5082,17 @@ discard block |
||
| 5090 | 5082 | * @param $css_class |
| 5091 | 5083 | * @param $url_callback |
| 5092 | 5084 | */ |
| 5093 | - public function add_action( $label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
| 5085 | + public function add_action($label, $image_url = '', $link_url = '', $css_class = '', $url_callback = null) |
|
| 5094 | 5086 | { |
| 5095 | - $unique_id = substr($label,0,1).substr(md5($label.$link_url),-8); //The unique id is used for class name so it must begin with a string |
|
| 5087 | + $unique_id = substr($label, 0, 1).substr(md5($label.$link_url), -8); //The unique id is used for class name so it must begin with a string |
|
| 5096 | 5088 | |
| 5097 | - $this->actions[$unique_id] = (object)array( |
|
| 5089 | + $this->actions[$unique_id] = (object) array( |
|
| 5098 | 5090 | 'label' => $label, |
| 5099 | 5091 | 'image_url' => $image_url, |
| 5100 | 5092 | 'link_url' => $link_url, |
| 5101 | 5093 | 'css_class' => $css_class, |
| 5102 | 5094 | 'url_callback' => $url_callback, |
| 5103 | - 'url_has_http' => substr($link_url,0,7) == 'http://' || substr($link_url,0,8) == 'https://' ? true : false |
|
| 5095 | + 'url_has_http' => substr($link_url, 0, 7) == 'http://' || substr($link_url, 0, 8) == 'https://' ? true : false |
|
| 5104 | 5096 | ); |
| 5105 | 5097 | |
| 5106 | 5098 | return $this; |
@@ -5116,9 +5108,9 @@ discard block |
||
| 5116 | 5108 | * @param string $order_by |
| 5117 | 5109 | * @return Grocery_CRUD |
| 5118 | 5110 | */ |
| 5119 | - public function set_relation($field_name , $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
| 5111 | + public function set_relation($field_name, $related_table, $related_title_field, $where_clause = null, $order_by = null) |
|
| 5120 | 5112 | { |
| 5121 | - $this->relation[$field_name] = array($field_name, $related_table,$related_title_field, $where_clause, $order_by); |
|
| 5113 | + $this->relation[$field_name] = array($field_name, $related_table, $related_title_field, $where_clause, $order_by); |
|
| 5122 | 5114 | return $this; |
| 5123 | 5115 | } |
| 5124 | 5116 | |
@@ -5135,16 +5127,16 @@ discard block |
||
| 5135 | 5127 | * @param mixed $where_clause |
| 5136 | 5128 | * @return Grocery_CRUD |
| 5137 | 5129 | */ |
| 5138 | - public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table , $title_field_selection_table , $priority_field_relation_table = null, $where_clause = null) |
|
| 5130 | + public function set_relation_n_n($field_name, $relation_table, $selection_table, $primary_key_alias_to_this_table, $primary_key_alias_to_selection_table, $title_field_selection_table, $priority_field_relation_table = null, $where_clause = null) |
|
| 5139 | 5131 | { |
| 5140 | 5132 | $this->relation_n_n[$field_name] = |
| 5141 | - (object)array( |
|
| 5133 | + (object) array( |
|
| 5142 | 5134 | 'field_name' => $field_name, |
| 5143 | 5135 | 'relation_table' => $relation_table, |
| 5144 | 5136 | 'selection_table' => $selection_table, |
| 5145 | 5137 | 'primary_key_alias_to_this_table' => $primary_key_alias_to_this_table, |
| 5146 | - 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table , |
|
| 5147 | - 'title_field_selection_table' => $title_field_selection_table , |
|
| 5138 | + 'primary_key_alias_to_selection_table' => $primary_key_alias_to_selection_table, |
|
| 5139 | + 'title_field_selection_table' => $title_field_selection_table, |
|
| 5148 | 5140 | 'priority_field_relation_table' => $priority_field_relation_table, |
| 5149 | 5141 | 'where_clause' => $where_clause |
| 5150 | 5142 | ); |
@@ -5162,8 +5154,8 @@ discard block |
||
| 5162 | 5154 | */ |
| 5163 | 5155 | public function set_field_upload($field_name, $upload_dir = '', $allowed_file_types = '') |
| 5164 | 5156 | { |
| 5165 | - $upload_dir = !empty($upload_dir) && substr($upload_dir,-1,1) == '/' |
|
| 5166 | - ? substr($upload_dir,0,-1) |
|
| 5157 | + $upload_dir = !empty($upload_dir) && substr($upload_dir, -1, 1) == '/' |
|
| 5158 | + ? substr($upload_dir, 0, -1) |
|
| 5167 | 5159 | : $upload_dir; |
| 5168 | 5160 | $upload_dir = !empty($upload_dir) ? $upload_dir : 'assets/uploads/files'; |
| 5169 | 5161 | |
@@ -5182,22 +5174,22 @@ discard block |
||
| 5182 | 5174 | } |
| 5183 | 5175 | } |
| 5184 | 5176 | |
| 5185 | -if(defined('CI_VERSION')) |
|
| 5177 | +if (defined('CI_VERSION')) |
|
| 5186 | 5178 | { |
| 5187 | 5179 | $ci = &get_instance(); |
| 5188 | 5180 | $ci->load->library('Form_validation'); |
| 5189 | 5181 | |
| 5190 | - class grocery_CRUD_Form_validation extends CI_Form_validation{ |
|
| 5182 | + class grocery_CRUD_Form_validation extends CI_Form_validation { |
|
| 5191 | 5183 | |
| 5192 | 5184 | public $CI; |
| 5193 | 5185 | public $_field_data = array(); |
| 5194 | 5186 | public $_config_rules = array(); |
| 5195 | 5187 | public $_error_array = array(); |
| 5196 | - public $_error_messages = array(); |
|
| 5188 | + public $_error_messages = array(); |
|
| 5197 | 5189 | public $_error_prefix = '<p>'; |
| 5198 | 5190 | public $_error_suffix = '</p>'; |
| 5199 | - public $error_string = ''; |
|
| 5200 | - public $_safe_form_data = FALSE; |
|
| 5191 | + public $error_string = ''; |
|
| 5192 | + public $_safe_form_data = FALSE; |
|
| 5201 | 5193 | } |
| 5202 | 5194 | } |
| 5203 | 5195 | |
@@ -5217,7 +5209,7 @@ discard block |
||
| 5217 | 5209 | private $options; |
| 5218 | 5210 | public $default_config_path = null; |
| 5219 | 5211 | |
| 5220 | - function __construct($options=null) { |
|
| 5212 | + function __construct($options = null) { |
|
| 5221 | 5213 | $this->options = array( |
| 5222 | 5214 | 'script_url' => $this->getFullUrl().'/'.basename(__FILE__), |
| 5223 | 5215 | 'upload_dir' => dirname(__FILE__).'/files/', |
@@ -5256,7 +5248,7 @@ discard block |
||
| 5256 | 5248 | ); |
| 5257 | 5249 | if ($options) { |
| 5258 | 5250 | // Or else for PHP >= 5.3.0 use: $this->options = array_replace_recursive($this->options, $options); |
| 5259 | - foreach($options as $option_name => $option) |
|
| 5251 | + foreach ($options as $option_name => $option) |
|
| 5260 | 5252 | { |
| 5261 | 5253 | $this->options[$option_name] = $option; |
| 5262 | 5254 | } |
@@ -5270,7 +5262,7 @@ discard block |
||
| 5270 | 5262 | (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME']. |
| 5271 | 5263 | (isset($_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] === 443 || |
| 5272 | 5264 | $_SERVER['SERVER_PORT'] === 80 ? '' : ':'.$_SERVER['SERVER_PORT']))). |
| 5273 | - substr($_SERVER['SCRIPT_NAME'],0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
| 5265 | + substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); |
|
| 5274 | 5266 | } |
| 5275 | 5267 | |
| 5276 | 5268 | private function get_file_object($file_name) { |
@@ -5280,7 +5272,7 @@ discard block |
||
| 5280 | 5272 | $file->name = $file_name; |
| 5281 | 5273 | $file->size = filesize($file_path); |
| 5282 | 5274 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
| 5283 | - foreach($this->options['image_versions'] as $version => $options) { |
|
| 5275 | + foreach ($this->options['image_versions'] as $version => $options) { |
|
| 5284 | 5276 | if (is_file($options['upload_dir'].$file_name)) { |
| 5285 | 5277 | $file->{$version.'_url'} = $options['upload_url'] |
| 5286 | 5278 | .rawurlencode($file->name); |
@@ -5356,7 +5348,7 @@ discard block |
||
| 5356 | 5348 | |
| 5357 | 5349 | private function has_error($uploaded_file, $file, $error) { |
| 5358 | 5350 | if ($error) { |
| 5359 | - switch($error) { |
|
| 5351 | + switch ($error) { |
|
| 5360 | 5352 | case UPLOAD_ERR_INI_SIZE: |
| 5361 | 5353 | return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.'; |
| 5362 | 5354 | break; |
@@ -5416,7 +5408,7 @@ discard block |
||
| 5416 | 5408 | } |
| 5417 | 5409 | |
| 5418 | 5410 | //Ensure that we don't have disallowed characters and add a unique id just to ensure that the file name will be unique |
| 5419 | - $file_name = substr(uniqid(),-5).'-'.$this->_transliterate_characters($file_name); |
|
| 5411 | + $file_name = substr(uniqid(), -5).'-'.$this->_transliterate_characters($file_name); |
|
| 5420 | 5412 | |
| 5421 | 5413 | //all the characters has to be lowercase |
| 5422 | 5414 | $file_name = strtolower($file_name); |
@@ -5427,7 +5419,7 @@ discard block |
||
| 5427 | 5419 | private function _transliterate_characters($file_name) |
| 5428 | 5420 | { |
| 5429 | 5421 | include($this->default_config_path.'/translit_chars.php'); |
| 5430 | - if ( isset($translit_characters)) |
|
| 5422 | + if (isset($translit_characters)) |
|
| 5431 | 5423 | { |
| 5432 | 5424 | $file_name = preg_replace(array_keys($translit_characters), array_values($translit_characters), $file_name); |
| 5433 | 5425 | } |
@@ -5500,7 +5492,7 @@ discard block |
||
| 5500 | 5492 | $this->orient_image($file_path); |
| 5501 | 5493 | } |
| 5502 | 5494 | $file->url = $this->options['upload_url'].rawurlencode($file->name); |
| 5503 | - foreach($this->options['image_versions'] as $version => $options) { |
|
| 5495 | + foreach ($this->options['image_versions'] as $version => $options) { |
|
| 5504 | 5496 | if ($this->create_scaled_image($file->name, $options)) { |
| 5505 | 5497 | $file->{$version.'_url'} = $options['upload_url'] |
| 5506 | 5498 | .rawurlencode($file->name); |
@@ -5587,7 +5579,7 @@ discard block |
||
| 5587 | 5579 | $file_path = $this->options['upload_dir'].$file_name; |
| 5588 | 5580 | $success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path); |
| 5589 | 5581 | if ($success) { |
| 5590 | - foreach($this->options['image_versions'] as $version => $options) { |
|
| 5582 | + foreach ($this->options['image_versions'] as $version => $options) { |
|
| 5591 | 5583 | $file = $options['upload_dir'].$file_name; |
| 5592 | 5584 | if (is_file($file)) { |
| 5593 | 5585 | unlink($file); |
@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | if (isset($this->relation[$field_info->name])) { |
| 62 | 62 | $field_info->crud_type = "relation_".$field_type->type; |
| 63 | - } |
|
| 64 | - elseif (isset($this->upload_fields[$field_info->name])) { |
|
| 63 | + } elseif (isset($this->upload_fields[$field_info->name])) { |
|
| 65 | 64 | $field_info->crud_type = "upload_file_".$field_type->type; |
| 66 | 65 | } else { |
| 67 | 66 | $field_info->crud_type = $field_type->type; |
@@ -69,18 +68,15 @@ discard block |
||
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | $real_type = $field_info->crud_type; |
| 72 | - } |
|
| 73 | - elseif(isset($this->relation[$field_info->name])) |
|
| 71 | + } elseif(isset($this->relation[$field_info->name])) |
|
| 74 | 72 | { |
| 75 | 73 | $real_type = 'relation'; |
| 76 | 74 | $field_info->crud_type = 'relation'; |
| 77 | - } |
|
| 78 | - elseif(isset($this->upload_fields[$field_info->name])) |
|
| 75 | + } elseif(isset($this->upload_fields[$field_info->name])) |
|
| 79 | 76 | { |
| 80 | 77 | $real_type = 'upload_file'; |
| 81 | 78 | $field_info->crud_type = 'upload_file'; |
| 82 | - } |
|
| 83 | - else |
|
| 79 | + } else |
|
| 84 | 80 | { |
| 85 | 81 | $real_type = $this->get_type($field_info); |
| 86 | 82 | $field_info->crud_type = $real_type; |
@@ -88,10 +84,11 @@ discard block |
||
| 88 | 84 | |
| 89 | 85 | switch ($real_type) { |
| 90 | 86 | case 'text': |
| 91 | - if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) |
|
| 92 | - $field_info->extras = false; |
|
| 93 | - else |
|
| 94 | - $field_info->extras = 'text_editor'; |
|
| 87 | + if(!empty($this->unset_texteditor) && in_array($field_info->name,$this->unset_texteditor)) { |
|
| 88 | + $field_info->extras = false; |
|
| 89 | + } else { |
|
| 90 | + $field_info->extras = 'text_editor'; |
|
| 91 | + } |
|
| 95 | 92 | break; |
| 96 | 93 | |
| 97 | 94 | case 'relation': |
@@ -105,8 +102,9 @@ discard block |
||
| 105 | 102 | break; |
| 106 | 103 | |
| 107 | 104 | default: |
| 108 | - if(empty($field_info->extras)) |
|
| 109 | - $field_info->extras = false; |
|
| 105 | + if(empty($field_info->extras)) { |
|
| 106 | + $field_info->extras = false; |
|
| 107 | + } |
|
| 110 | 108 | break; |
| 111 | 109 | } |
| 112 | 110 | |
@@ -135,14 +133,17 @@ discard block |
||
| 135 | 133 | } |
| 136 | 134 | } |
| 137 | 135 | |
| 138 | - if(!empty($this->add_fields)) |
|
| 139 | - foreach($this->add_fields as $field_object) |
|
| 136 | + if(!empty($this->add_fields)) { |
|
| 137 | + foreach($this->add_fields as $field_object) |
|
| 140 | 138 | { |
| 141 | 139 | $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
| 140 | + } |
|
| 142 | 141 | |
| 143 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 142 | + if(!isset($types[$field_name])) { |
|
| 143 | + //Doesn't exist in the database? Create it for the CRUD |
|
| 144 | 144 | { |
| 145 | 145 | $extras = false; |
| 146 | + } |
|
| 146 | 147 | if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
| 147 | 148 | { |
| 148 | 149 | $field_type = $this->change_field_type[$field_name]; |
@@ -165,14 +166,17 @@ discard block |
||
| 165 | 166 | } |
| 166 | 167 | } |
| 167 | 168 | |
| 168 | - if(!empty($this->edit_fields)) |
|
| 169 | - foreach($this->edit_fields as $field_object) |
|
| 169 | + if(!empty($this->edit_fields)) { |
|
| 170 | + foreach($this->edit_fields as $field_object) |
|
| 170 | 171 | { |
| 171 | 172 | $field_name = isset($field_object->field_name) ? $field_object->field_name : $field_object; |
| 173 | + } |
|
| 172 | 174 | |
| 173 | - if(!isset($types[$field_name]))//Doesn't exist in the database? Create it for the CRUD |
|
| 175 | + if(!isset($types[$field_name])) { |
|
| 176 | + //Doesn't exist in the database? Create it for the CRUD |
|
| 174 | 177 | { |
| 175 | 178 | $extras = false; |
| 179 | + } |
|
| 176 | 180 | if($this->change_field_type !== null && isset($this->change_field_type[$field_name])) |
| 177 | 181 | { |
| 178 | 182 | $field_type = $this->change_field_type[$field_name]; |
@@ -244,8 +248,7 @@ discard block |
||
| 244 | 248 | * $this->get_integer_input |
| 245 | 249 | * */ |
| 246 | 250 | $field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value); |
| 247 | - } |
|
| 248 | - else |
|
| 251 | + } else |
|
| 249 | 252 | { |
| 250 | 253 | $field_info->input = $this->get_string_input($field_info,$value); |
| 251 | 254 | } |
@@ -282,8 +285,7 @@ discard block |
||
| 282 | 285 | list($year,$month,$day) = explode("-",$value); |
| 283 | 286 | |
| 284 | 287 | $value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year)); |
| 285 | - } |
|
| 286 | - else |
|
| 288 | + } else |
|
| 287 | 289 | { |
| 288 | 290 | $value = ''; |
| 289 | 291 | } |
@@ -295,8 +297,7 @@ discard block |
||
| 295 | 297 | list($hours,$minutes) = explode(":",substr($value,11)); |
| 296 | 298 | |
| 297 | 299 | $value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year)); |
| 298 | - } |
|
| 299 | - else |
|
| 300 | + } else |
|
| 300 | 301 | { |
| 301 | 302 | $value = ''; |
| 302 | 303 | } |
@@ -330,8 +331,7 @@ discard block |
||
| 330 | 331 | if(empty($value)) |
| 331 | 332 | { |
| 332 | 333 | $value = ""; |
| 333 | - } |
|
| 334 | - else |
|
| 334 | + } else |
|
| 335 | 335 | { |
| 336 | 336 | $is_image = !empty($value) && |
| 337 | 337 | ( substr($value,-4) == '.jpg' |
@@ -347,8 +347,7 @@ discard block |
||
| 347 | 347 | if($is_image) |
| 348 | 348 | { |
| 349 | 349 | $file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">'; |
| 350 | - } |
|
| 351 | - else |
|
| 350 | + } else |
|
| 352 | 351 | { |
| 353 | 352 | $file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true); |
| 354 | 353 | } |
@@ -418,24 +417,27 @@ discard block |
||
| 418 | 417 | case 'tinyint': |
| 419 | 418 | case 'mediumint': |
| 420 | 419 | case 'longint': |
| 421 | - if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) |
|
| 422 | - $type = 'true_false'; |
|
| 423 | - else |
|
| 424 | - $type = 'integer'; |
|
| 420 | + if( $db_type->db_type == 'tinyint' && $db_type->db_max_length == 1) { |
|
| 421 | + $type = 'true_false'; |
|
| 422 | + } else { |
|
| 423 | + $type = 'integer'; |
|
| 424 | + } |
|
| 425 | 425 | break; |
| 426 | 426 | case '254': |
| 427 | 427 | case 'string': |
| 428 | 428 | case 'enum': |
| 429 | - if($db_type->db_type != 'enum') |
|
| 430 | - $type = 'string'; |
|
| 431 | - else |
|
| 432 | - $type = 'enum'; |
|
| 429 | + if($db_type->db_type != 'enum') { |
|
| 430 | + $type = 'string'; |
|
| 431 | + } else { |
|
| 432 | + $type = 'enum'; |
|
| 433 | + } |
|
| 433 | 434 | break; |
| 434 | 435 | case 'set': |
| 435 | - if($db_type->db_type != 'set') |
|
| 436 | - $type = 'string'; |
|
| 437 | - else |
|
| 438 | - $type = 'set'; |
|
| 436 | + if($db_type->db_type != 'set') { |
|
| 437 | + $type = 'string'; |
|
| 438 | + } else { |
|
| 439 | + $type = 'set'; |
|
| 440 | + } |
|
| 439 | 441 | break; |
| 440 | 442 | case '252': |
| 441 | 443 | case 'blob': |
@@ -488,33 +490,40 @@ discard block |
||
| 488 | 490 | |
| 489 | 491 | protected function get_total_results() |
| 490 | 492 | { |
| 491 | - if(!empty($this->where)) |
|
| 492 | - foreach($this->where as $where) |
|
| 493 | + if(!empty($this->where)) { |
|
| 494 | + foreach($this->where as $where) |
|
| 493 | 495 | $this->basic_model->where($where[0],$where[1],$where[2]); |
| 496 | + } |
|
| 494 | 497 | |
| 495 | - if(!empty($this->or_where)) |
|
| 496 | - foreach($this->or_where as $or_where) |
|
| 498 | + if(!empty($this->or_where)) { |
|
| 499 | + foreach($this->or_where as $or_where) |
|
| 497 | 500 | $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
| 501 | + } |
|
| 498 | 502 | |
| 499 | - if(!empty($this->like)) |
|
| 500 | - foreach($this->like as $like) |
|
| 503 | + if(!empty($this->like)) { |
|
| 504 | + foreach($this->like as $like) |
|
| 501 | 505 | $this->basic_model->like($like[0],$like[1],$like[2]); |
| 506 | + } |
|
| 502 | 507 | |
| 503 | - if(!empty($this->or_like)) |
|
| 504 | - foreach($this->or_like as $or_like) |
|
| 508 | + if(!empty($this->or_like)) { |
|
| 509 | + foreach($this->or_like as $or_like) |
|
| 505 | 510 | $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
| 511 | + } |
|
| 506 | 512 | |
| 507 | - if(!empty($this->having)) |
|
| 508 | - foreach($this->having as $having) |
|
| 513 | + if(!empty($this->having)) { |
|
| 514 | + foreach($this->having as $having) |
|
| 509 | 515 | $this->basic_model->having($having[0],$having[1],$having[2]); |
| 516 | + } |
|
| 510 | 517 | |
| 511 | - if(!empty($this->or_having)) |
|
| 512 | - foreach($this->or_having as $or_having) |
|
| 518 | + if(!empty($this->or_having)) { |
|
| 519 | + foreach($this->or_having as $or_having) |
|
| 513 | 520 | $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
| 521 | + } |
|
| 514 | 522 | |
| 515 | - if(!empty($this->relation)) |
|
| 516 | - foreach($this->relation as $relation) |
|
| 523 | + if(!empty($this->relation)) { |
|
| 524 | + foreach($this->relation as $relation) |
|
| 517 | 525 | $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
| 526 | + } |
|
| 518 | 527 | |
| 519 | 528 | if(!empty($this->relation_n_n)) |
| 520 | 529 | { |
@@ -555,9 +564,9 @@ discard block |
||
| 555 | 564 | { |
| 556 | 565 | if(!empty($state_info->per_page)) |
| 557 | 566 | { |
| 558 | - if(empty($state_info->page) || !is_numeric($state_info->page) ) |
|
| 559 | - $this->limit($state_info->per_page); |
|
| 560 | - else |
|
| 567 | + if(empty($state_info->page) || !is_numeric($state_info->page) ) { |
|
| 568 | + $this->limit($state_info->per_page); |
|
| 569 | + } else |
|
| 561 | 570 | { |
| 562 | 571 | $limit_page = ( ($state_info->page-1) * $state_info->per_page ); |
| 563 | 572 | $this->limit($state_info->per_page, $limit_page); |
@@ -614,16 +623,16 @@ discard block |
||
| 614 | 623 | } else { |
| 615 | 624 | $this->like($state_info->search->field , $state_info->search->text); |
| 616 | 625 | } |
| 617 | - } |
|
| 618 | - else |
|
| 626 | + } else |
|
| 619 | 627 | { |
| 620 | 628 | $columns = $this->get_columns(); |
| 621 | 629 | |
| 622 | 630 | $search_text = $state_info->search->text; |
| 623 | 631 | |
| 624 | - if(!empty($this->where)) |
|
| 625 | - foreach($this->where as $where) |
|
| 632 | + if(!empty($this->where)) { |
|
| 633 | + foreach($this->where as $where) |
|
| 626 | 634 | $this->basic_model->having($where[0],$where[1],$where[2]); |
| 635 | + } |
|
| 627 | 636 | |
| 628 | 637 | foreach($columns as $column) |
| 629 | 638 | { |
@@ -635,17 +644,14 @@ discard block |
||
| 635 | 644 | { |
| 636 | 645 | $this->or_like($search_field, $search_text); |
| 637 | 646 | } |
| 638 | - } |
|
| 639 | - else |
|
| 647 | + } else |
|
| 640 | 648 | { |
| 641 | 649 | $this->or_like($temp_relation[$column->field_name], $search_text); |
| 642 | 650 | } |
| 643 | - } |
|
| 644 | - elseif(isset($this->relation_n_n[$column->field_name])) |
|
| 651 | + } elseif(isset($this->relation_n_n[$column->field_name])) |
|
| 645 | 652 | { |
| 646 | 653 | //@todo have a where for the relation_n_n statement |
| 647 | - } |
|
| 648 | - else |
|
| 654 | + } else |
|
| 649 | 655 | { |
| 650 | 656 | $this->or_like($column->field_name, $search_text); |
| 651 | 657 | } |
@@ -656,8 +662,9 @@ discard block |
||
| 656 | 662 | |
| 657 | 663 | protected function table_exists($table_name = null) |
| 658 | 664 | { |
| 659 | - if($this->basic_model->db_table_exists($table_name)) |
|
| 660 | - return true; |
|
| 665 | + if($this->basic_model->db_table_exists($table_name)) { |
|
| 666 | + return true; |
|
| 667 | + } |
|
| 661 | 668 | return false; |
| 662 | 669 | } |
| 663 | 670 | |
@@ -753,14 +760,12 @@ discard block |
||
| 753 | 760 | if($form_validation->run()) |
| 754 | 761 | { |
| 755 | 762 | $validation_result->success = true; |
| 756 | - } |
|
| 757 | - else |
|
| 763 | + } else |
|
| 758 | 764 | { |
| 759 | 765 | $validation_result->error_message = $form_validation->error_string(); |
| 760 | 766 | $validation_result->error_fields = $form_validation->_error_array; |
| 761 | 767 | } |
| 762 | - } |
|
| 763 | - else |
|
| 768 | + } else |
|
| 764 | 769 | { |
| 765 | 770 | $validation_result->success = true; |
| 766 | 771 | } |
@@ -868,14 +873,12 @@ discard block |
||
| 868 | 873 | if($form_validation->run()) |
| 869 | 874 | { |
| 870 | 875 | $validation_result->success = true; |
| 871 | - } |
|
| 872 | - else |
|
| 876 | + } else |
|
| 873 | 877 | { |
| 874 | 878 | $validation_result->error_message = $form_validation->error_string(); |
| 875 | 879 | $validation_result->error_fields = $form_validation->_error_array; |
| 876 | 880 | } |
| 877 | - } |
|
| 878 | - else |
|
| 881 | + } else |
|
| 879 | 882 | { |
| 880 | 883 | $validation_result->success = true; |
| 881 | 884 | } |
@@ -899,10 +902,11 @@ discard block |
||
| 899 | 902 | { |
| 900 | 903 | $callback_return = call_user_func($this->callback_before_insert, $post_data); |
| 901 | 904 | |
| 902 | - if(!empty($callback_return) && is_array($callback_return)) |
|
| 903 | - $post_data = $callback_return; |
|
| 904 | - elseif($callback_return === false) |
|
| 905 | - return false; |
|
| 905 | + if(!empty($callback_return) && is_array($callback_return)) { |
|
| 906 | + $post_data = $callback_return; |
|
| 907 | + } elseif($callback_return === false) { |
|
| 908 | + return false; |
|
| 909 | + } |
|
| 906 | 910 | } |
| 907 | 911 | |
| 908 | 912 | $insert_data = array(); |
@@ -920,28 +924,22 @@ discard block |
||
| 920 | 924 | 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])) |
| 921 | 925 | { |
| 922 | 926 | $insert_data[$field->field_name] = null; |
| 923 | - } |
|
| 924 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 927 | + } elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 925 | 928 | { |
| 926 | 929 | $insert_data[$field->field_name] = null; |
| 927 | - } |
|
| 928 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 930 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 929 | 931 | { |
| 930 | 932 | $insert_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
| 931 | - } |
|
| 932 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 933 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 933 | 934 | { |
| 934 | 935 | //This empty if statement is to make sure that a readonly field will never inserted/updated |
| 935 | - } |
|
| 936 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 936 | + } elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 937 | 937 | { |
| 938 | 938 | $insert_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
| 939 | - } |
|
| 940 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 939 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 941 | 940 | $insert_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
| 942 | 941 | substr($post_data[$field->field_name],10); |
| 943 | - } |
|
| 944 | - else |
|
| 942 | + } else |
|
| 945 | 943 | { |
| 946 | 944 | $insert_data[$field->field_name] = $post_data[$field->field_name]; |
| 947 | 945 | } |
@@ -953,8 +951,7 @@ discard block |
||
| 953 | 951 | if($insert_result !== false) |
| 954 | 952 | { |
| 955 | 953 | $insert_primary_key = $insert_result; |
| 956 | - } |
|
| 957 | - else |
|
| 954 | + } else |
|
| 958 | 955 | { |
| 959 | 956 | return false; |
| 960 | 957 | } |
@@ -978,7 +975,7 @@ discard block |
||
| 978 | 975 | } |
| 979 | 976 | |
| 980 | 977 | } |
| 981 | - }else |
|
| 978 | + } else |
|
| 982 | 979 | { |
| 983 | 980 | $callback_return = call_user_func($this->callback_insert, $post_data); |
| 984 | 981 | |
@@ -988,10 +985,11 @@ discard block |
||
| 988 | 985 | } |
| 989 | 986 | } |
| 990 | 987 | |
| 991 | - if(isset($insert_primary_key)) |
|
| 992 | - return $insert_primary_key; |
|
| 993 | - else |
|
| 994 | - return true; |
|
| 988 | + if(isset($insert_primary_key)) { |
|
| 989 | + return $insert_primary_key; |
|
| 990 | + } else { |
|
| 991 | + return true; |
|
| 992 | + } |
|
| 995 | 993 | } |
| 996 | 994 | |
| 997 | 995 | return false; |
@@ -1018,8 +1016,7 @@ discard block |
||
| 1018 | 1016 | if(!empty($callback_return) && is_array($callback_return)) |
| 1019 | 1017 | { |
| 1020 | 1018 | $post_data = $callback_return; |
| 1021 | - } |
|
| 1022 | - elseif($callback_return === false) |
|
| 1019 | + } elseif($callback_return === false) |
|
| 1023 | 1020 | { |
| 1024 | 1021 | return false; |
| 1025 | 1022 | } |
@@ -1041,28 +1038,22 @@ discard block |
||
| 1041 | 1038 | 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])) |
| 1042 | 1039 | { |
| 1043 | 1040 | $update_data[$field->field_name] = null; |
| 1044 | - } |
|
| 1045 | - elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1041 | + } elseif(isset($types[$field->field_name]->db_null) && $types[$field->field_name]->db_null && $post_data[$field->field_name] === '') |
|
| 1046 | 1042 | { |
| 1047 | 1043 | $update_data[$field->field_name] = null; |
| 1048 | - } |
|
| 1049 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1044 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'date') |
|
| 1050 | 1045 | { |
| 1051 | 1046 | $update_data[$field->field_name] = $this->_convert_date_to_sql_date($post_data[$field->field_name]); |
| 1052 | - } |
|
| 1053 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1047 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'readonly') |
|
| 1054 | 1048 | { |
| 1055 | 1049 | //This empty if statement is to make sure that a readonly field will never inserted/updated |
| 1056 | - } |
|
| 1057 | - elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1050 | + } elseif(isset($types[$field->field_name]->crud_type) && ($types[$field->field_name]->crud_type == 'set' || $types[$field->field_name]->crud_type == 'multiselect')) |
|
| 1058 | 1051 | { |
| 1059 | 1052 | $update_data[$field->field_name] = !empty($post_data[$field->field_name]) ? implode(',',$post_data[$field->field_name]) : ''; |
| 1060 | - } |
|
| 1061 | - elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 1053 | + } elseif(isset($types[$field->field_name]->crud_type) && $types[$field->field_name]->crud_type == 'datetime'){ |
|
| 1062 | 1054 | $update_data[$field->field_name] = $this->_convert_date_to_sql_date(substr($post_data[$field->field_name],0,10)). |
| 1063 | 1055 | substr($post_data[$field->field_name],10); |
| 1064 | - } |
|
| 1065 | - else |
|
| 1056 | + } else |
|
| 1066 | 1057 | { |
| 1067 | 1058 | $update_data[$field->field_name] = $post_data[$field->field_name]; |
| 1068 | 1059 | } |
@@ -1100,8 +1091,7 @@ discard block |
||
| 1100 | 1091 | } |
| 1101 | 1092 | |
| 1102 | 1093 | } |
| 1103 | - } |
|
| 1104 | - else |
|
| 1094 | + } else |
|
| 1105 | 1095 | { |
| 1106 | 1096 | $callback_return = call_user_func($this->callback_update, $post_data, $primary_key); |
| 1107 | 1097 | |
@@ -1112,8 +1102,7 @@ discard block |
||
| 1112 | 1102 | } |
| 1113 | 1103 | |
| 1114 | 1104 | return true; |
| 1115 | - } |
|
| 1116 | - else |
|
| 1105 | + } else |
|
| 1117 | 1106 | { |
| 1118 | 1107 | return false; |
| 1119 | 1108 | } |
@@ -1126,7 +1115,7 @@ discard block |
||
| 1126 | 1115 | { |
| 1127 | 1116 | //If it's already a sql-date don't convert it! |
| 1128 | 1117 | return $date; |
| 1129 | - }elseif(empty($date)) |
|
| 1118 | + } elseif(empty($date)) |
|
| 1130 | 1119 | { |
| 1131 | 1120 | return ''; |
| 1132 | 1121 | } |
@@ -1135,12 +1124,10 @@ discard block |
||
| 1135 | 1124 | if($this->php_date_format == 'd/m/Y') |
| 1136 | 1125 | { |
| 1137 | 1126 | $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2])); |
| 1138 | - } |
|
| 1139 | - elseif($this->php_date_format == 'm/d/Y') |
|
| 1127 | + } elseif($this->php_date_format == 'm/d/Y') |
|
| 1140 | 1128 | { |
| 1141 | 1129 | $sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2])); |
| 1142 | - } |
|
| 1143 | - else |
|
| 1130 | + } else |
|
| 1144 | 1131 | { |
| 1145 | 1132 | $sql_date = $date; |
| 1146 | 1133 | } |
@@ -1150,17 +1137,18 @@ discard block |
||
| 1150 | 1137 | |
| 1151 | 1138 | protected function _get_field_names_to_search(array $relation_values) |
| 1152 | 1139 | { |
| 1153 | - if(!strstr($relation_values[2],'{')) |
|
| 1154 | - return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
| 1155 | - else |
|
| 1140 | + if(!strstr($relation_values[2],'{')) { |
|
| 1141 | + return $this->_unique_join_name($relation_values[0]).'.'.$relation_values[2]; |
|
| 1142 | + } else |
|
| 1156 | 1143 | { |
| 1157 | 1144 | $relation_values[2] = ' '.$relation_values[2].' '; |
| 1158 | 1145 | $temp1 = explode('{',$relation_values[2]); |
| 1159 | 1146 | unset($temp1[0]); |
| 1160 | 1147 | |
| 1161 | 1148 | $field_names_array = array(); |
| 1162 | - foreach($temp1 as $field) |
|
| 1163 | - list($field_names_array[]) = explode('}',$field); |
|
| 1149 | + foreach($temp1 as $field) { |
|
| 1150 | + list($field_names_array[]) = explode('}',$field); |
|
| 1151 | + } |
|
| 1164 | 1152 | |
| 1165 | 1153 | return $field_names_array; |
| 1166 | 1154 | } |
@@ -1230,8 +1218,7 @@ discard block |
||
| 1230 | 1218 | } |
| 1231 | 1219 | |
| 1232 | 1220 | } |
| 1233 | - } |
|
| 1234 | - else |
|
| 1221 | + } else |
|
| 1235 | 1222 | { |
| 1236 | 1223 | $callback_return = call_user_func($this->callback_delete, $primary_key_value); |
| 1237 | 1224 | |
@@ -1256,36 +1243,44 @@ discard block |
||
| 1256 | 1243 | |
| 1257 | 1244 | protected function get_list() |
| 1258 | 1245 | { |
| 1259 | - if(!empty($this->order_by)) |
|
| 1260 | - $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
| 1246 | + if(!empty($this->order_by)) { |
|
| 1247 | + $this->basic_model->order_by($this->order_by[0],$this->order_by[1]); |
|
| 1248 | + } |
|
| 1261 | 1249 | |
| 1262 | - if(!empty($this->where)) |
|
| 1263 | - foreach($this->where as $where) |
|
| 1250 | + if(!empty($this->where)) { |
|
| 1251 | + foreach($this->where as $where) |
|
| 1264 | 1252 | $this->basic_model->where($where[0],$where[1],$where[2]); |
| 1253 | + } |
|
| 1265 | 1254 | |
| 1266 | - if(!empty($this->or_where)) |
|
| 1267 | - foreach($this->or_where as $or_where) |
|
| 1255 | + if(!empty($this->or_where)) { |
|
| 1256 | + foreach($this->or_where as $or_where) |
|
| 1268 | 1257 | $this->basic_model->or_where($or_where[0],$or_where[1],$or_where[2]); |
| 1258 | + } |
|
| 1269 | 1259 | |
| 1270 | - if(!empty($this->like)) |
|
| 1271 | - foreach($this->like as $like) |
|
| 1260 | + if(!empty($this->like)) { |
|
| 1261 | + foreach($this->like as $like) |
|
| 1272 | 1262 | $this->basic_model->like($like[0],$like[1],$like[2]); |
| 1263 | + } |
|
| 1273 | 1264 | |
| 1274 | - if(!empty($this->or_like)) |
|
| 1275 | - foreach($this->or_like as $or_like) |
|
| 1265 | + if(!empty($this->or_like)) { |
|
| 1266 | + foreach($this->or_like as $or_like) |
|
| 1276 | 1267 | $this->basic_model->or_like($or_like[0],$or_like[1],$or_like[2]); |
| 1268 | + } |
|
| 1277 | 1269 | |
| 1278 | - if(!empty($this->having)) |
|
| 1279 | - foreach($this->having as $having) |
|
| 1270 | + if(!empty($this->having)) { |
|
| 1271 | + foreach($this->having as $having) |
|
| 1280 | 1272 | $this->basic_model->having($having[0],$having[1],$having[2]); |
| 1273 | + } |
|
| 1281 | 1274 | |
| 1282 | - if(!empty($this->or_having)) |
|
| 1283 | - foreach($this->or_having as $or_having) |
|
| 1275 | + if(!empty($this->or_having)) { |
|
| 1276 | + foreach($this->or_having as $or_having) |
|
| 1284 | 1277 | $this->basic_model->or_having($or_having[0],$or_having[1],$or_having[2]); |
| 1278 | + } |
|
| 1285 | 1279 | |
| 1286 | - if(!empty($this->relation)) |
|
| 1287 | - foreach($this->relation as $relation) |
|
| 1280 | + if(!empty($this->relation)) { |
|
| 1281 | + foreach($this->relation as $relation) |
|
| 1288 | 1282 | $this->basic_model->join_relation($relation[0],$relation[1],$relation[2]); |
| 1283 | + } |
|
| 1289 | 1284 | |
| 1290 | 1285 | if(!empty($this->relation_n_n)) |
| 1291 | 1286 | { |
@@ -1309,13 +1304,11 @@ discard block |
||
| 1309 | 1304 | if(is_numeric($default_per_page) && $default_per_page >1) |
| 1310 | 1305 | { |
| 1311 | 1306 | $this->basic_model->limit($default_per_page); |
| 1312 | - } |
|
| 1313 | - else |
|
| 1307 | + } else |
|
| 1314 | 1308 | { |
| 1315 | 1309 | $this->basic_model->limit(10); |
| 1316 | 1310 | } |
| 1317 | - } |
|
| 1318 | - else |
|
| 1311 | + } else |
|
| 1319 | 1312 | { |
| 1320 | 1313 | $this->basic_model->limit($this->limit[0],$this->limit[1]); |
| 1321 | 1314 | } |
@@ -1366,10 +1359,11 @@ discard block |
||
| 1366 | 1359 | { |
| 1367 | 1360 | $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]); |
| 1368 | 1361 | |
| 1369 | - if($callback_before_upload_response === false) |
|
| 1370 | - return false; |
|
| 1371 | - elseif(is_string($callback_before_upload_response)) |
|
| 1372 | - return $callback_before_upload_response; |
|
| 1362 | + if($callback_before_upload_response === false) { |
|
| 1363 | + return false; |
|
| 1364 | + } elseif(is_string($callback_before_upload_response)) { |
|
| 1365 | + return $callback_before_upload_response; |
|
| 1366 | + } |
|
| 1373 | 1367 | } |
| 1374 | 1368 | |
| 1375 | 1369 | $upload_info = $this->upload_fields[$state_info->field_name]; |
@@ -1387,7 +1381,7 @@ discard block |
||
| 1387 | 1381 | $reg_exp = ''; |
| 1388 | 1382 | if(!empty($upload_info->allowed_file_types)){ |
| 1389 | 1383 | $reg_exp = '/(\\.|\\/)('.$upload_info->allowed_file_types.')$/i'; |
| 1390 | - }else{ |
|
| 1384 | + } else{ |
|
| 1391 | 1385 | $reg_exp = '/(\\.|\\/)('.$allowed_files.')$/i'; |
| 1392 | 1386 | } |
| 1393 | 1387 | |
@@ -1418,31 +1412,29 @@ discard block |
||
| 1418 | 1412 | { |
| 1419 | 1413 | $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response , $this->upload_fields[$state_info->field_name] , $_FILES ); |
| 1420 | 1414 | |
| 1421 | - if($callback_after_upload_response === false) |
|
| 1422 | - return false; |
|
| 1423 | - elseif(is_string($callback_after_upload_response)) |
|
| 1424 | - return $callback_after_upload_response; |
|
| 1425 | - elseif(is_array($callback_after_upload_response)) |
|
| 1426 | - $uploader_response = $callback_after_upload_response; |
|
| 1415 | + if($callback_after_upload_response === false) { |
|
| 1416 | + return false; |
|
| 1417 | + } elseif(is_string($callback_after_upload_response)) { |
|
| 1418 | + return $callback_after_upload_response; |
|
| 1419 | + } elseif(is_array($callback_after_upload_response)) { |
|
| 1420 | + $uploader_response = $callback_after_upload_response; |
|
| 1421 | + } |
|
| 1427 | 1422 | } |
| 1428 | 1423 | |
| 1429 | 1424 | return $uploader_response; |
| 1430 | - } |
|
| 1431 | - else |
|
| 1425 | + } else |
|
| 1432 | 1426 | { |
| 1433 | 1427 | $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name] ); |
| 1434 | 1428 | |
| 1435 | 1429 | if($upload_response === false) |
| 1436 | 1430 | { |
| 1437 | 1431 | return false; |
| 1438 | - } |
|
| 1439 | - else |
|
| 1432 | + } else |
|
| 1440 | 1433 | { |
| 1441 | 1434 | return $upload_response; |
| 1442 | 1435 | } |
| 1443 | 1436 | } |
| 1444 | - } |
|
| 1445 | - else |
|
| 1437 | + } else |
|
| 1446 | 1438 | { |
| 1447 | 1439 | return false; |
| 1448 | 1440 | } |
@@ -1462,19 +1454,16 @@ discard block |
||
| 1462 | 1454 | $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
| 1463 | 1455 | |
| 1464 | 1456 | return true; |
| 1465 | - } |
|
| 1466 | - else |
|
| 1457 | + } else |
|
| 1467 | 1458 | { |
| 1468 | 1459 | return false; |
| 1469 | 1460 | } |
| 1470 | - } |
|
| 1471 | - else |
|
| 1461 | + } else |
|
| 1472 | 1462 | { |
| 1473 | 1463 | $this->basic_model->db_file_delete($state_info->field_name, $state_info->file_name); |
| 1474 | 1464 | return true; |
| 1475 | 1465 | } |
| 1476 | - } |
|
| 1477 | - else |
|
| 1466 | + } else |
|
| 1478 | 1467 | { |
| 1479 | 1468 | return false; |
| 1480 | 1469 | } |
@@ -1482,8 +1471,9 @@ discard block |
||
| 1482 | 1471 | |
| 1483 | 1472 | protected function ajax_relation($state_info) |
| 1484 | 1473 | { |
| 1485 | - if(!isset($this->relation[$state_info->field_name])) |
|
| 1486 | - return false; |
|
| 1474 | + if(!isset($this->relation[$state_info->field_name])) { |
|
| 1475 | + return false; |
|
| 1476 | + } |
|
| 1487 | 1477 | |
| 1488 | 1478 | list($field_name, $related_table, $related_field_title, $where_clause, $order_by) = $this->relation[$state_info->field_name]; |
| 1489 | 1479 | |
@@ -1604,8 +1594,7 @@ discard block |
||
| 1604 | 1594 | |
| 1605 | 1595 | $data->list_view = $this->_theme_view('list.php',$data,true); |
| 1606 | 1596 | $this->_theme_view('list_template.php',$data); |
| 1607 | - } |
|
| 1608 | - else |
|
| 1597 | + } else |
|
| 1609 | 1598 | { |
| 1610 | 1599 | $this->set_echo_and_die(); |
| 1611 | 1600 | $this->_theme_view('list.php',$data); |
@@ -1726,8 +1715,9 @@ discard block |
||
| 1726 | 1715 | $value = str_replace(array(" ","&",">","<"),array(" ","&",">","<"),$value); |
| 1727 | 1716 | |
| 1728 | 1717 | //If the value has only spaces and nothing more then add the whitespace html character |
| 1729 | - if(str_replace(" ","",$value) == "") |
|
| 1730 | - $value = " "; |
|
| 1718 | + if(str_replace(" ","",$value) == "") { |
|
| 1719 | + $value = " "; |
|
| 1720 | + } |
|
| 1731 | 1721 | |
| 1732 | 1722 | return strip_tags($value); |
| 1733 | 1723 | } |
@@ -1754,8 +1744,9 @@ discard block |
||
| 1754 | 1744 | |
| 1755 | 1745 | protected function change_list_add_actions($list) |
| 1756 | 1746 | { |
| 1757 | - if(empty($this->actions)) |
|
| 1758 | - return $list; |
|
| 1747 | + if(empty($this->actions)) { |
|
| 1748 | + return $list; |
|
| 1749 | + } |
|
| 1759 | 1750 | |
| 1760 | 1751 | $primary_key = $this->get_primary_key(); |
| 1761 | 1752 | |
@@ -1767,8 +1758,7 @@ discard block |
||
| 1767 | 1758 | if(!empty($action->url_callback)) |
| 1768 | 1759 | { |
| 1769 | 1760 | $actions_urls[$unique_id] = call_user_func($action->url_callback, $row->$primary_key, $row); |
| 1770 | - } |
|
| 1771 | - else |
|
| 1761 | + } else |
|
| 1772 | 1762 | { |
| 1773 | 1763 | $actions_urls[$unique_id] = |
| 1774 | 1764 | $action->url_has_http ? |
@@ -1793,12 +1783,13 @@ discard block |
||
| 1793 | 1783 | { |
| 1794 | 1784 | $field_name = $column->field_name; |
| 1795 | 1785 | $field_value = isset( $row->{$column->field_name} ) ? $row->{$column->field_name} : null; |
| 1796 | - if( $has_callbacks && isset($this->callback_column[$field_name]) ) |
|
| 1797 | - $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
| 1798 | - elseif(isset($types[$field_name])) |
|
| 1799 | - $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
| 1800 | - else |
|
| 1801 | - $list[$num_row]->$field_name = $field_value; |
|
| 1786 | + if( $has_callbacks && isset($this->callback_column[$field_name]) ) { |
|
| 1787 | + $list[$num_row]->$field_name = call_user_func($this->callback_column[$field_name], $field_value, $row); |
|
| 1788 | + } elseif(isset($types[$field_name])) { |
|
| 1789 | + $list[$num_row]->$field_name = $this->change_list_value($types[$field_name] , $field_value); |
|
| 1790 | + } else { |
|
| 1791 | + $list[$num_row]->$field_name = $field_value; |
|
| 1792 | + } |
|
| 1802 | 1793 | } |
| 1803 | 1794 | } |
| 1804 | 1795 | |
@@ -1899,8 +1890,7 @@ discard block |
||
| 1899 | 1890 | $error_message = '<p>'.$this->l('delete_error_message').'</p>'; |
| 1900 | 1891 | |
| 1901 | 1892 | echo json_encode(array('success' => $delete_result ,'error_message' => $error_message)); |
| 1902 | - } |
|
| 1903 | - else |
|
| 1893 | + } else |
|
| 1904 | 1894 | { |
| 1905 | 1895 | $success_message = '<p>'.$this->l('delete_success_message').'</p>'; |
| 1906 | 1896 | |
@@ -1916,13 +1906,11 @@ discard block |
||
| 1916 | 1906 | if(!empty($field_info->primary_key) && !$this->unset_edit) |
| 1917 | 1907 | { |
| 1918 | 1908 | return $this->l('insert_success_message')." <a class='go-to-edit-form' href='".$this->getEditUrl($field_info->primary_key)."'>".$this->l('form_edit')." {$this->subject}</a> "; |
| 1919 | - } |
|
| 1920 | - else |
|
| 1909 | + } else |
|
| 1921 | 1910 | { |
| 1922 | 1911 | return $this->l('insert_success_message'); |
| 1923 | 1912 | } |
| 1924 | - } |
|
| 1925 | - else |
|
| 1913 | + } else |
|
| 1926 | 1914 | { |
| 1927 | 1915 | return null; |
| 1928 | 1916 | } |
@@ -1934,8 +1922,7 @@ discard block |
||
| 1934 | 1922 | if($insert_result === false) |
| 1935 | 1923 | { |
| 1936 | 1924 | echo json_encode(array('success' => false)); |
| 1937 | - } |
|
| 1938 | - else |
|
| 1925 | + } else |
|
| 1939 | 1926 | { |
| 1940 | 1927 | $success_message = '<p>'.$this->l('insert_success_message'); |
| 1941 | 1928 | |
@@ -1982,14 +1969,15 @@ discard block |
||
| 1982 | 1969 | 'success' => true, |
| 1983 | 1970 | 'files' => $upload_result |
| 1984 | 1971 | )); |
| 1985 | - } |
|
| 1986 | - else |
|
| 1972 | + } else |
|
| 1987 | 1973 | { |
| 1988 | 1974 | $result = (object)array('success' => false); |
| 1989 | - if(is_string($upload_result)) |
|
| 1990 | - $result->message = $upload_result; |
|
| 1991 | - if(!empty($upload_result[0]->error)) |
|
| 1992 | - $result->message = $upload_result[0]->error; |
|
| 1975 | + if(is_string($upload_result)) { |
|
| 1976 | + $result->message = $upload_result; |
|
| 1977 | + } |
|
| 1978 | + if(!empty($upload_result[0]->error)) { |
|
| 1979 | + $result->message = $upload_result[0]->error; |
|
| 1980 | + } |
|
| 1993 | 1981 | |
| 1994 | 1982 | echo json_encode($result); |
| 1995 | 1983 | } |
@@ -2003,8 +1991,7 @@ discard block |
||
| 2003 | 1991 | if($upload_result !== false) |
| 2004 | 1992 | { |
| 2005 | 1993 | echo json_encode( (object)array( 'success' => true ) ); |
| 2006 | - } |
|
| 2007 | - else |
|
| 1994 | + } else |
|
| 2008 | 1995 | { |
| 2009 | 1996 | echo json_encode((object)array('success' => false)); |
| 2010 | 1997 | } |
@@ -2146,8 +2133,7 @@ discard block |
||
| 2146 | 2133 | 'css_files' => $css_files, |
| 2147 | 2134 | 'output' => $this->views_as_string, |
| 2148 | 2135 | ); |
| 2149 | - } |
|
| 2150 | - elseif($this->echo_and_die === true) |
|
| 2136 | + } elseif($this->echo_and_die === true) |
|
| 2151 | 2137 | { |
| 2152 | 2138 | echo $this->views_as_string; |
| 2153 | 2139 | die(); |
@@ -2160,8 +2146,7 @@ discard block |
||
| 2160 | 2146 | if($update_result === false) |
| 2161 | 2147 | { |
| 2162 | 2148 | echo json_encode(array('success' => $update_result)); |
| 2163 | - } |
|
| 2164 | - else |
|
| 2149 | + } else |
|
| 2165 | 2150 | { |
| 2166 | 2151 | $success_message = '<p>'.$this->l('update_success_message'); |
| 2167 | 2152 | if(!$this->unset_back_to_list && !$this->_is_ajax()) |
@@ -2185,8 +2170,9 @@ discard block |
||
| 2185 | 2170 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.numeric.min.js'); |
| 2186 | 2171 | $this->set_js_config($this->default_javascript_path.'/jquery_plugins/config/jquery.numeric.config.js'); |
| 2187 | 2172 | $extra_attributes = ''; |
| 2188 | - if(!empty($field_info->db_max_length)) |
|
| 2189 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2173 | + if(!empty($field_info->db_max_length)) { |
|
| 2174 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2175 | + } |
|
| 2190 | 2176 | $input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='text' value='$value' class='numeric form-control' $extra_attributes />"; |
| 2191 | 2177 | return $input; |
| 2192 | 2178 | } |
@@ -2268,8 +2254,7 @@ discard block |
||
| 2268 | 2254 | $class_name = $this->config->text_editor_type == 'minimal' ? 'mini-texteditor' : 'texteditor'; |
| 2269 | 2255 | |
| 2270 | 2256 | $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>"; |
| 2271 | - } |
|
| 2272 | - else |
|
| 2257 | + } else |
|
| 2273 | 2258 | { |
| 2274 | 2259 | $input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}'>$value</textarea>"; |
| 2275 | 2260 | } |
@@ -2309,8 +2294,7 @@ discard block |
||
| 2309 | 2294 | list($year,$month,$day) = explode('-',substr($value,0,10)); |
| 2310 | 2295 | $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
| 2311 | 2296 | $datetime = $date.substr($value,10); |
| 2312 | - } |
|
| 2313 | - else |
|
| 2297 | + } else |
|
| 2314 | 2298 | { |
| 2315 | 2299 | $datetime = ''; |
| 2316 | 2300 | } |
@@ -2322,8 +2306,9 @@ discard block |
||
| 2322 | 2306 | |
| 2323 | 2307 | protected function get_hidden_input($field_info,$value) |
| 2324 | 2308 | { |
| 2325 | - if($field_info->extras !== null && $field_info->extras != false) |
|
| 2326 | - $value = $field_info->extras; |
|
| 2309 | + if($field_info->extras !== null && $field_info->extras != false) { |
|
| 2310 | + $value = $field_info->extras; |
|
| 2311 | + } |
|
| 2327 | 2312 | $input = "<input id='field-{$field_info->name}' type='hidden' name='{$field_info->name}' value='$value' />"; |
| 2328 | 2313 | return $input; |
| 2329 | 2314 | } |
@@ -2333,8 +2318,9 @@ discard block |
||
| 2333 | 2318 | $value = !is_string($value) ? '' : $value; |
| 2334 | 2319 | |
| 2335 | 2320 | $extra_attributes = ''; |
| 2336 | - if(!empty($field_info->db_max_length)) |
|
| 2337 | - $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2321 | + if(!empty($field_info->db_max_length)) { |
|
| 2322 | + $extra_attributes .= "maxlength='{$field_info->db_max_length}'"; |
|
| 2323 | + } |
|
| 2338 | 2324 | $input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='password' value='$value' $extra_attributes />"; |
| 2339 | 2325 | return $input; |
| 2340 | 2326 | } |
@@ -2363,8 +2349,7 @@ discard block |
||
| 2363 | 2349 | { |
| 2364 | 2350 | list($year,$month,$day) = explode('-',substr($value,0,10)); |
| 2365 | 2351 | $date = date($this->php_date_format, mktime(0,0,0,$month,$day,$year)); |
| 2366 | - } |
|
| 2367 | - else |
|
| 2352 | + } else |
|
| 2368 | 2353 | { |
| 2369 | 2354 | $date = ''; |
| 2370 | 2355 | } |
@@ -2504,10 +2489,11 @@ discard block |
||
| 2504 | 2489 | $selected = !empty($value) && $value == $option_value ? "selected='selected'" : ''; |
| 2505 | 2490 | $input .= "<option value='$option_value' $selected >$option</option>"; |
| 2506 | 2491 | } |
| 2507 | - } |
|
| 2508 | - elseif(!empty($value) || (is_numeric($value) && $value == '0') ) //If it's ajax then we only need the selected items and not all the items |
|
| 2492 | + } elseif(!empty($value) || (is_numeric($value) && $value == '0') ) { |
|
| 2493 | + //If it's ajax then we only need the selected items and not all the items |
|
| 2509 | 2494 | { |
| 2510 | 2495 | $selected_options_array = $this->get_relation_array($field_info->extras, $value); |
| 2496 | + } |
|
| 2511 | 2497 | foreach($selected_options_array as $option_value => $option) |
| 2512 | 2498 | { |
| 2513 | 2499 | $input .= "<option value='$option_value'selected='selected' >$option</option>"; |
@@ -2561,8 +2547,7 @@ discard block |
||
| 2561 | 2547 | } |
| 2562 | 2548 | } |
| 2563 | 2549 | } |
| 2564 | - } |
|
| 2565 | - else |
|
| 2550 | + } else |
|
| 2566 | 2551 | { |
| 2567 | 2552 | $this->set_css($this->default_css_path.'/jquery_plugins/chosen/chosen.css'); |
| 2568 | 2553 | $this->set_js_lib($this->default_javascript_path.'/jquery_plugins/jquery.chosen.min.js'); |
@@ -2577,8 +2562,7 @@ discard block |
||
| 2577 | 2562 | if(empty($unselected_values) && empty($selected_values)) |
| 2578 | 2563 | { |
| 2579 | 2564 | $input = "Please add {$field_info_type->display_as} first"; |
| 2580 | - } |
|
| 2581 | - else |
|
| 2565 | + } else |
|
| 2582 | 2566 | { |
| 2583 | 2567 | $css_class = $has_priority_field || $is_ie_7 ? 'multiselect': 'chosen-multiple-select'; |
| 2584 | 2568 | $width_style = $has_priority_field || $is_ie_7 ? '' : 'width:510px;'; |
@@ -2586,16 +2570,18 @@ discard block |
||
| 2586 | 2570 | $select_title = str_replace('{field_display_as}',$field_info_type->display_as,$this->l('set_relation_title')); |
| 2587 | 2571 | $input = "<select id='field-{$field_info_type->name}' name='{$field_info_type->name}[]' multiple='multiple' size='8' class='$css_class' data-placeholder='$select_title' style='$width_style' >"; |
| 2588 | 2572 | |
| 2589 | - if(!empty($unselected_values)) |
|
| 2590 | - foreach($unselected_values as $id => $name) |
|
| 2573 | + if(!empty($unselected_values)) { |
|
| 2574 | + foreach($unselected_values as $id => $name) |
|
| 2591 | 2575 | { |
| 2592 | 2576 | $input .= "<option value='$id'>$name</option>"; |
| 2577 | + } |
|
| 2593 | 2578 | } |
| 2594 | 2579 | |
| 2595 | - if(!empty($selected_values)) |
|
| 2596 | - foreach($selected_values as $id => $name) |
|
| 2580 | + if(!empty($selected_values)) { |
|
| 2581 | + foreach($selected_values as $id => $name) |
|
| 2597 | 2582 | { |
| 2598 | 2583 | $input .= "<option value='$id' selected='selected'>$name</option>"; |
| 2584 | + } |
|
| 2599 | 2585 | } |
| 2600 | 2586 | |
| 2601 | 2587 | $input .= "</select>"; |
@@ -2607,14 +2593,15 @@ discard block |
||
| 2607 | 2593 | protected function _convert_bytes_ui_to_bytes($bytes_ui) |
| 2608 | 2594 | { |
| 2609 | 2595 | $bytes_ui = str_replace(' ','',$bytes_ui); |
| 2610 | - if(strstr($bytes_ui,'MB')) |
|
| 2611 | - $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
| 2612 | - elseif(strstr($bytes_ui,'KB')) |
|
| 2613 | - $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
| 2614 | - elseif(strstr($bytes_ui,'B')) |
|
| 2615 | - $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
| 2616 | - else |
|
| 2617 | - $bytes = (int)($bytes_ui); |
|
| 2596 | + if(strstr($bytes_ui,'MB')) { |
|
| 2597 | + $bytes = (int)(str_replace('MB','',$bytes_ui))*1024*1024; |
|
| 2598 | + } elseif(strstr($bytes_ui,'KB')) { |
|
| 2599 | + $bytes = (int)(str_replace('KB','',$bytes_ui))*1024; |
|
| 2600 | + } elseif(strstr($bytes_ui,'B')) { |
|
| 2601 | + $bytes = (int)(str_replace('B','',$bytes_ui)); |
|
| 2602 | + } else { |
|
| 2603 | + $bytes = (int)($bytes_ui); |
|
| 2604 | + } |
|
| 2618 | 2605 | |
| 2619 | 2606 | return $bytes; |
| 2620 | 2607 | } |
@@ -2721,8 +2708,7 @@ discard block |
||
| 2721 | 2708 | if(!isset($this->callback_add_field[$field->field_name])) |
| 2722 | 2709 | { |
| 2723 | 2710 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2724 | - } |
|
| 2725 | - else |
|
| 2711 | + } else |
|
| 2726 | 2712 | { |
| 2727 | 2713 | $field_input = $field_info; |
| 2728 | 2714 | $field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info); |
@@ -2763,8 +2749,7 @@ discard block |
||
| 2763 | 2749 | if(!isset($this->callback_edit_field[$field->field_name])) |
| 2764 | 2750 | { |
| 2765 | 2751 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2766 | - } |
|
| 2767 | - else |
|
| 2752 | + } else |
|
| 2768 | 2753 | { |
| 2769 | 2754 | $primary_key = $this->getStateInfo()->primary_key; |
| 2770 | 2755 | $field_input = $field_info; |
@@ -2821,8 +2806,7 @@ discard block |
||
| 2821 | 2806 | if(!isset($this->callback_read_field[$field->field_name])) |
| 2822 | 2807 | { |
| 2823 | 2808 | $field_input = $this->get_field_input($field_info, $field_value); |
| 2824 | - } |
|
| 2825 | - else |
|
| 2809 | + } else |
|
| 2826 | 2810 | { |
| 2827 | 2811 | $primary_key = $this->getStateInfo()->primary_key; |
| 2828 | 2812 | $field_input = $field_info; |
@@ -2852,8 +2836,9 @@ discard block |
||
| 2852 | 2836 | protected function setThemeBasics() |
| 2853 | 2837 | { |
| 2854 | 2838 | $this->theme_path = $this->default_theme_path; |
| 2855 | - if(substr($this->theme_path,-1) != '/') |
|
| 2856 | - $this->theme_path = $this->theme_path.'/'; |
|
| 2839 | + if(substr($this->theme_path,-1) != '/') { |
|
| 2840 | + $this->theme_path = $this->theme_path.'/'; |
|
| 2841 | + } |
|
| 2857 | 2842 | |
| 2858 | 2843 | include($this->theme_path.$this->theme.'/config.php'); |
| 2859 | 2844 | |
@@ -2950,10 +2935,11 @@ discard block |
||
| 2950 | 2935 | |
| 2951 | 2936 | protected function get_views_as_string() |
| 2952 | 2937 | { |
| 2953 | - if(!empty($this->views_as_string)) |
|
| 2954 | - return $this->views_as_string; |
|
| 2955 | - else |
|
| 2956 | - return null; |
|
| 2938 | + if(!empty($this->views_as_string)) { |
|
| 2939 | + return $this->views_as_string; |
|
| 2940 | + } else { |
|
| 2941 | + return null; |
|
| 2942 | + } |
|
| 2957 | 2943 | } |
| 2958 | 2944 | } |
| 2959 | 2945 | |
@@ -3068,8 +3054,7 @@ discard block |
||
| 3068 | 3054 | if(!empty($_POST)) |
| 3069 | 3055 | { |
| 3070 | 3056 | $state_info = (object)array('unwrapped_data' => $_POST); |
| 3071 | - } |
|
| 3072 | - else |
|
| 3057 | + } else |
|
| 3073 | 3058 | { |
| 3074 | 3059 | throw new Exception('On the state "insert" you must have post data',8); |
| 3075 | 3060 | die(); |
@@ -3080,13 +3065,11 @@ discard block |
||
| 3080 | 3065 | if(!empty($_POST) && $first_parameter !== null) |
| 3081 | 3066 | { |
| 3082 | 3067 | $state_info = (object)array('primary_key' => $first_parameter,'unwrapped_data' => $_POST); |
| 3083 | - } |
|
| 3084 | - elseif(empty($_POST)) |
|
| 3068 | + } elseif(empty($_POST)) |
|
| 3085 | 3069 | { |
| 3086 | 3070 | throw new Exception('On the state "update" you must have post data',9); |
| 3087 | 3071 | die(); |
| 3088 | - } |
|
| 3089 | - else |
|
| 3072 | + } else |
|
| 3090 | 3073 | { |
| 3091 | 3074 | throw new Exception('On the state "update" the Primary key cannot be null',10); |
| 3092 | 3075 | die(); |
@@ -3122,8 +3105,7 @@ discard block |
||
| 3122 | 3105 | { |
| 3123 | 3106 | $search_text = strip_tags($_POST['search_field']); |
| 3124 | 3107 | $state_info->search = (object)array('field' => null , 'text' => $_POST['search_text']); |
| 3125 | - } |
|
| 3126 | - else |
|
| 3108 | + } else |
|
| 3127 | 3109 | { |
| 3128 | 3110 | if (is_array($_POST['search_field'])) { |
| 3129 | 3111 | $search_array = array(); |
@@ -3185,10 +3167,11 @@ discard block |
||
| 3185 | 3167 | { |
| 3186 | 3168 | $state_string = $this->get_state_info_from_url()->operation; |
| 3187 | 3169 | |
| 3188 | - if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) |
|
| 3189 | - $state_code = array_search($state_string, $this->states); |
|
| 3190 | - else |
|
| 3191 | - $state_code = 0; |
|
| 3170 | + if( $state_string != 'unknown' && in_array( $state_string, $this->states ) ) { |
|
| 3171 | + $state_code = array_search($state_string, $this->states); |
|
| 3172 | + } else { |
|
| 3173 | + $state_code = 0; |
|
| 3174 | + } |
|
| 3192 | 3175 | |
| 3193 | 3176 | return $state_code; |
| 3194 | 3177 | } |
@@ -3215,12 +3198,15 @@ discard block |
||
| 3215 | 3198 | foreach($ci->uri->segments as $num => $value) |
| 3216 | 3199 | { |
| 3217 | 3200 | $state_url_array[$num] = $value; |
| 3218 | - if($num == ($segment_position - 1)) |
|
| 3219 | - break; |
|
| 3201 | + if($num == ($segment_position - 1)) { |
|
| 3202 | + break; |
|
| 3203 | + } |
|
| 3220 | 3204 | } |
| 3221 | 3205 | |
| 3222 | - if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) //there is a scenario that you don't have the index to your url |
|
| 3206 | + if( $method_name == 'index' && !in_array( 'index', $state_url_array ) ) { |
|
| 3207 | + //there is a scenario that you don't have the index to your url |
|
| 3223 | 3208 | $state_url_array[$num+1] = 'index'; |
| 3209 | + } |
|
| 3224 | 3210 | } |
| 3225 | 3211 | |
| 3226 | 3212 | $state_url = site_url(implode('/',$state_url_array).'/'.$url); |
@@ -3248,8 +3234,9 @@ discard block |
||
| 3248 | 3234 | |
| 3249 | 3235 | $function_name = $this->get_method_name(); |
| 3250 | 3236 | |
| 3251 | - if($function_name == 'index' && !in_array('index',$ci->uri->segments)) |
|
| 3252 | - $segment_position++; |
|
| 3237 | + if($function_name == 'index' && !in_array('index',$ci->uri->segments)) { |
|
| 3238 | + $segment_position++; |
|
| 3239 | + } |
|
| 3253 | 3240 | |
| 3254 | 3241 | $first_parameter = isset($segements[$segment_position+1]) ? $segements[$segment_position+1] : null; |
| 3255 | 3242 | $second_parameter = isset($segements[$segment_position+2]) ? $segements[$segment_position+2] : null; |
@@ -3328,26 +3315,29 @@ discard block |
||
| 3328 | 3315 | |
| 3329 | 3316 | protected function getValidationUpdateUrl($primary_key = null) |
| 3330 | 3317 | { |
| 3331 | - if($primary_key === null) |
|
| 3332 | - return $this->state_url('update_validation'); |
|
| 3333 | - else |
|
| 3334 | - return $this->state_url('update_validation/'.$primary_key); |
|
| 3318 | + if($primary_key === null) { |
|
| 3319 | + return $this->state_url('update_validation'); |
|
| 3320 | + } else { |
|
| 3321 | + return $this->state_url('update_validation/'.$primary_key); |
|
| 3322 | + } |
|
| 3335 | 3323 | } |
| 3336 | 3324 | |
| 3337 | 3325 | protected function getEditUrl($primary_key = null) |
| 3338 | 3326 | { |
| 3339 | - if($primary_key === null) |
|
| 3340 | - return $this->state_url('edit'); |
|
| 3341 | - else |
|
| 3342 | - return $this->state_url('edit/'.$primary_key); |
|
| 3327 | + if($primary_key === null) { |
|
| 3328 | + return $this->state_url('edit'); |
|
| 3329 | + } else { |
|
| 3330 | + return $this->state_url('edit/'.$primary_key); |
|
| 3331 | + } |
|
| 3343 | 3332 | } |
| 3344 | 3333 | |
| 3345 | 3334 | protected function getReadUrl($primary_key = null) |
| 3346 | 3335 | { |
| 3347 | - if($primary_key === null) |
|
| 3348 | - return $this->state_url('read'); |
|
| 3349 | - else |
|
| 3350 | - return $this->state_url('read/'.$primary_key); |
|
| 3336 | + if($primary_key === null) { |
|
| 3337 | + return $this->state_url('read'); |
|
| 3338 | + } else { |
|
| 3339 | + return $this->state_url('read/'.$primary_key); |
|
| 3340 | + } |
|
| 3351 | 3341 | } |
| 3352 | 3342 | |
| 3353 | 3343 | protected function getUpdateUrl($state_info) |
@@ -3371,10 +3361,11 @@ discard block |
||
| 3371 | 3361 | |
| 3372 | 3362 | protected function getListSuccessUrl($primary_key = null) |
| 3373 | 3363 | { |
| 3374 | - if(empty($primary_key)) |
|
| 3375 | - return $this->state_url('success',true); |
|
| 3376 | - else |
|
| 3377 | - return $this->state_url('success/'.$primary_key,true); |
|
| 3364 | + if(empty($primary_key)) { |
|
| 3365 | + return $this->state_url('success',true); |
|
| 3366 | + } else { |
|
| 3367 | + return $this->state_url('success/'.$primary_key,true); |
|
| 3368 | + } |
|
| 3378 | 3369 | } |
| 3379 | 3370 | |
| 3380 | 3371 | protected function getUploadUrl($field_name) |
@@ -3583,7 +3574,7 @@ discard block |
||
| 3583 | 3574 | if(is_string($field)) |
| 3584 | 3575 | { |
| 3585 | 3576 | $this->validation_rules[$field] = array('field' => $field, 'label' => $label, 'rules' => $rules); |
| 3586 | - }elseif(is_array($field)) |
|
| 3577 | + } elseif(is_array($field)) |
|
| 3587 | 3578 | { |
| 3588 | 3579 | foreach($field as $num_field => $field_array) |
| 3589 | 3580 | { |
@@ -3986,8 +3977,7 @@ discard block |
||
| 3986 | 3977 | { |
| 3987 | 3978 | $this->display_as[$field] = $display_as; |
| 3988 | 3979 | } |
| 3989 | - } |
|
| 3990 | - elseif($display_as !== null) |
|
| 3980 | + } elseif($display_as !== null) |
|
| 3991 | 3981 | { |
| 3992 | 3982 | $this->display_as[$field_name] = $display_as; |
| 3993 | 3983 | } |
@@ -4006,9 +3996,10 @@ discard block |
||
| 4006 | 3996 | } |
| 4007 | 3997 | include($this->default_language_path.'/'.$this->language.'.php'); |
| 4008 | 3998 | |
| 4009 | - foreach($lang as $handle => $lang_string) |
|
| 4010 | - if(!isset($this->lang_strings[$handle])) |
|
| 3999 | + foreach($lang as $handle => $lang_string) { |
|
| 4000 | + if(!isset($this->lang_strings[$handle])) |
|
| 4011 | 4001 | $this->lang_strings[$handle] = $lang_string; |
| 4002 | + } |
|
| 4012 | 4003 | |
| 4013 | 4004 | $this->default_true_false_text = array( $this->l('form_inactive') , $this->l('form_active')); |
| 4014 | 4005 | $this->subject = $this->subject === null ? $this->l('list_record') : $this->subject; |
@@ -4103,8 +4094,9 @@ discard block |
||
| 4103 | 4094 | $this->columns = array(); |
| 4104 | 4095 | foreach($field_types as $field) |
| 4105 | 4096 | { |
| 4106 | - if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) |
|
| 4107 | - $this->columns[] = $field->name; |
|
| 4097 | + if( !isset($field->db_extra) || $field->db_extra != 'auto_increment' ) { |
|
| 4098 | + $this->columns[] = $field->name; |
|
| 4099 | + } |
|
| 4108 | 4100 | } |
| 4109 | 4101 | } |
| 4110 | 4102 | |
@@ -4122,16 +4114,14 @@ discard block |
||
| 4122 | 4114 | $display_as = $this->display_as[$column]; |
| 4123 | 4115 | unset($this->display_as[$column]); |
| 4124 | 4116 | $this->display_as[$new_column] = $display_as; |
| 4125 | - } |
|
| 4126 | - else |
|
| 4117 | + } else |
|
| 4127 | 4118 | { |
| 4128 | 4119 | $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
| 4129 | 4120 | } |
| 4130 | 4121 | |
| 4131 | 4122 | $column = $new_column; |
| 4132 | 4123 | $this->columns[$col_num] = $new_column; |
| 4133 | - } |
|
| 4134 | - else |
|
| 4124 | + } else |
|
| 4135 | 4125 | { |
| 4136 | 4126 | if(!empty($this->relation)) |
| 4137 | 4127 | { |
@@ -4146,8 +4136,7 @@ discard block |
||
| 4146 | 4136 | $display_as = $this->display_as[$column]; |
| 4147 | 4137 | unset($this->display_as[$column]); |
| 4148 | 4138 | $this->display_as[$new_column] = $display_as; |
| 4149 | - } |
|
| 4150 | - else |
|
| 4139 | + } else |
|
| 4151 | 4140 | { |
| 4152 | 4141 | $this->display_as[$new_column] = ucfirst(str_replace('_',' ',$column)); |
| 4153 | 4142 | } |
@@ -4160,13 +4149,14 @@ discard block |
||
| 4160 | 4149 | |
| 4161 | 4150 | } |
| 4162 | 4151 | |
| 4163 | - if(isset($this->display_as[$column])) |
|
| 4164 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4165 | - elseif(isset($field_types[$column])) |
|
| 4166 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4167 | - else |
|
| 4168 | - $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
| 4152 | + if(isset($this->display_as[$column])) { |
|
| 4153 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $this->display_as[$column]); |
|
| 4154 | + } elseif(isset($field_types[$column])) { |
|
| 4155 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => $field_types[$column]->display_as); |
|
| 4156 | + } else { |
|
| 4157 | + $this->columns[$col_num] = (object)array('field_name' => $column, 'display_as' => |
|
| 4169 | 4158 | ucfirst(str_replace('_',' ',$column))); |
| 4159 | + } |
|
| 4170 | 4160 | |
| 4171 | 4161 | if(!empty($this->unset_columns) && in_array($column,$this->unset_columns)) |
| 4172 | 4162 | { |
@@ -4194,29 +4184,31 @@ discard block |
||
| 4194 | 4184 | { |
| 4195 | 4185 | foreach($this->add_fields as $field_num => $field) |
| 4196 | 4186 | { |
| 4197 | - if(isset($this->display_as[$field])) |
|
| 4198 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4199 | - elseif(isset($field_types[$field]->display_as)) |
|
| 4200 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4201 | - else |
|
| 4202 | - $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
| 4187 | + if(isset($this->display_as[$field])) { |
|
| 4188 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4189 | + } elseif(isset($field_types[$field]->display_as)) { |
|
| 4190 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4191 | + } else { |
|
| 4192 | + $this->add_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => ucfirst(str_replace('_',' ',$field))); |
|
| 4193 | + } |
|
| 4203 | 4194 | } |
| 4204 | - } |
|
| 4205 | - else |
|
| 4195 | + } else |
|
| 4206 | 4196 | { |
| 4207 | 4197 | $this->add_fields = array(); |
| 4208 | 4198 | foreach($field_types as $field) |
| 4209 | 4199 | { |
| 4210 | 4200 | //Check if an unset_add_field is initialize for this field name |
| 4211 | - if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) |
|
| 4212 | - continue; |
|
| 4201 | + if($this->unset_add_fields !== null && is_array($this->unset_add_fields) && in_array($field->name,$this->unset_add_fields)) { |
|
| 4202 | + continue; |
|
| 4203 | + } |
|
| 4213 | 4204 | |
| 4214 | 4205 | if( (!isset($field->db_extra) || $field->db_extra != 'auto_increment') ) |
| 4215 | 4206 | { |
| 4216 | - if(isset($this->display_as[$field->name])) |
|
| 4217 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4218 | - else |
|
| 4219 | - $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4207 | + if(isset($this->display_as[$field->name])) { |
|
| 4208 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4209 | + } else { |
|
| 4210 | + $this->add_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4211 | + } |
|
| 4220 | 4212 | } |
| 4221 | 4213 | } |
| 4222 | 4214 | } |
@@ -4239,27 +4231,29 @@ discard block |
||
| 4239 | 4231 | { |
| 4240 | 4232 | foreach($this->edit_fields as $field_num => $field) |
| 4241 | 4233 | { |
| 4242 | - if(isset($this->display_as[$field])) |
|
| 4243 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4244 | - else |
|
| 4245 | - $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4234 | + if(isset($this->display_as[$field])) { |
|
| 4235 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4236 | + } else { |
|
| 4237 | + $this->edit_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4238 | + } |
|
| 4246 | 4239 | } |
| 4247 | - } |
|
| 4248 | - else |
|
| 4240 | + } else |
|
| 4249 | 4241 | { |
| 4250 | 4242 | $this->edit_fields = array(); |
| 4251 | 4243 | foreach($field_types as $field) |
| 4252 | 4244 | { |
| 4253 | 4245 | //Check if an unset_edit_field is initialize for this field name |
| 4254 | - if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) |
|
| 4255 | - continue; |
|
| 4246 | + if($this->unset_edit_fields !== null && is_array($this->unset_edit_fields) && in_array($field->name,$this->unset_edit_fields)) { |
|
| 4247 | + continue; |
|
| 4248 | + } |
|
| 4256 | 4249 | |
| 4257 | 4250 | if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
| 4258 | 4251 | { |
| 4259 | - if(isset($this->display_as[$field->name])) |
|
| 4260 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4261 | - else |
|
| 4262 | - $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4252 | + if(isset($this->display_as[$field->name])) { |
|
| 4253 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4254 | + } else { |
|
| 4255 | + $this->edit_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4256 | + } |
|
| 4263 | 4257 | } |
| 4264 | 4258 | } |
| 4265 | 4259 | } |
@@ -4282,27 +4276,29 @@ discard block |
||
| 4282 | 4276 | { |
| 4283 | 4277 | foreach($this->read_fields as $field_num => $field) |
| 4284 | 4278 | { |
| 4285 | - if(isset($this->display_as[$field])) |
|
| 4286 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4287 | - else |
|
| 4288 | - $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4279 | + if(isset($this->display_as[$field])) { |
|
| 4280 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $this->display_as[$field]); |
|
| 4281 | + } else { |
|
| 4282 | + $this->read_fields[$field_num] = (object)array('field_name' => $field, 'display_as' => $field_types[$field]->display_as); |
|
| 4283 | + } |
|
| 4289 | 4284 | } |
| 4290 | - } |
|
| 4291 | - else |
|
| 4285 | + } else |
|
| 4292 | 4286 | { |
| 4293 | 4287 | $this->read_fields = array(); |
| 4294 | 4288 | foreach($field_types as $field) |
| 4295 | 4289 | { |
| 4296 | 4290 | //Check if an unset_read_field is initialize for this field name |
| 4297 | - if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) |
|
| 4298 | - continue; |
|
| 4291 | + if($this->unset_read_fields !== null && is_array($this->unset_read_fields) && in_array($field->name,$this->unset_read_fields)) { |
|
| 4292 | + continue; |
|
| 4293 | + } |
|
| 4299 | 4294 | |
| 4300 | 4295 | if(!isset($field->db_extra) || $field->db_extra != 'auto_increment') |
| 4301 | 4296 | { |
| 4302 | - if(isset($this->display_as[$field->name])) |
|
| 4303 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4304 | - else |
|
| 4305 | - $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4297 | + if(isset($this->display_as[$field->name])) { |
|
| 4298 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $this->display_as[$field->name]); |
|
| 4299 | + } else { |
|
| 4300 | + $this->read_fields[] = (object)array('field_name' => $field->name, 'display_as' => $field->display_as); |
|
| 4301 | + } |
|
| 4306 | 4302 | } |
| 4307 | 4303 | } |
| 4308 | 4304 | } |
@@ -4437,8 +4433,9 @@ discard block |
||
| 4437 | 4433 | $this->_load_language(); |
| 4438 | 4434 | $this->state_code = $this->getStateCode(); |
| 4439 | 4435 | |
| 4440 | - if($this->basic_model === null) |
|
| 4441 | - $this->set_default_Model(); |
|
| 4436 | + if($this->basic_model === null) { |
|
| 4437 | + $this->set_default_Model(); |
|
| 4438 | + } |
|
| 4442 | 4439 | |
| 4443 | 4440 | $this->set_basic_db_table($this->get_table()); |
| 4444 | 4441 | |
@@ -4461,8 +4458,7 @@ discard block |
||
| 4461 | 4458 | if( $this->state_code != 0 ) |
| 4462 | 4459 | { |
| 4463 | 4460 | $this->state_info = $this->getStateInfo(); |
| 4464 | - } |
|
| 4465 | - else |
|
| 4461 | + } else |
|
| 4466 | 4462 | { |
| 4467 | 4463 | throw new Exception('The state is unknown , I don\'t know what I will do with your data!', 4); |
| 4468 | 4464 | die(); |
@@ -4477,8 +4473,9 @@ discard block |
||
| 4477 | 4473 | die(); |
| 4478 | 4474 | } |
| 4479 | 4475 | |
| 4480 | - if($this->theme === null) |
|
| 4481 | - $this->set_theme($this->default_theme); |
|
| 4476 | + if($this->theme === null) { |
|
| 4477 | + $this->set_theme($this->default_theme); |
|
| 4478 | + } |
|
| 4482 | 4479 | $this->setThemeBasics(); |
| 4483 | 4480 | |
| 4484 | 4481 | $this->set_basic_Layout(); |
@@ -4496,8 +4493,9 @@ discard block |
||
| 4496 | 4493 | die(); |
| 4497 | 4494 | } |
| 4498 | 4495 | |
| 4499 | - if($this->theme === null) |
|
| 4500 | - $this->set_theme($this->default_theme); |
|
| 4496 | + if($this->theme === null) { |
|
| 4497 | + $this->set_theme($this->default_theme); |
|
| 4498 | + } |
|
| 4501 | 4499 | $this->setThemeBasics(); |
| 4502 | 4500 | |
| 4503 | 4501 | $this->set_basic_Layout(); |
@@ -4513,8 +4511,9 @@ discard block |
||
| 4513 | 4511 | die(); |
| 4514 | 4512 | } |
| 4515 | 4513 | |
| 4516 | - if($this->theme === null) |
|
| 4517 | - $this->set_theme($this->default_theme); |
|
| 4514 | + if($this->theme === null) { |
|
| 4515 | + $this->set_theme($this->default_theme); |
|
| 4516 | + } |
|
| 4518 | 4517 | $this->setThemeBasics(); |
| 4519 | 4518 | |
| 4520 | 4519 | $this->set_basic_Layout(); |
@@ -4572,8 +4571,9 @@ discard block |
||
| 4572 | 4571 | die(); |
| 4573 | 4572 | } |
| 4574 | 4573 | |
| 4575 | - if($this->theme === null) |
|
| 4576 | - $this->set_theme($this->default_theme); |
|
| 4574 | + if($this->theme === null) { |
|
| 4575 | + $this->set_theme($this->default_theme); |
|
| 4576 | + } |
|
| 4577 | 4577 | $this->setThemeBasics(); |
| 4578 | 4578 | |
| 4579 | 4579 | $this->set_basic_Layout(); |
@@ -4587,8 +4587,9 @@ discard block |
||
| 4587 | 4587 | |
| 4588 | 4588 | case 8://ajax_list_info |
| 4589 | 4589 | |
| 4590 | - if($this->theme === null) |
|
| 4591 | - $this->set_theme($this->default_theme); |
|
| 4590 | + if($this->theme === null) { |
|
| 4591 | + $this->set_theme($this->default_theme); |
|
| 4592 | + } |
|
| 4592 | 4593 | $this->setThemeBasics(); |
| 4593 | 4594 | |
| 4594 | 4595 | $this->set_basic_Layout(); |
@@ -4656,8 +4657,9 @@ discard block |
||
| 4656 | 4657 | die(); |
| 4657 | 4658 | } |
| 4658 | 4659 | |
| 4659 | - if($this->theme === null) |
|
| 4660 | - $this->set_theme($this->default_theme); |
|
| 4660 | + if($this->theme === null) { |
|
| 4661 | + $this->set_theme($this->default_theme); |
|
| 4662 | + } |
|
| 4661 | 4663 | $this->setThemeBasics(); |
| 4662 | 4664 | |
| 4663 | 4665 | $this->set_basic_Layout(); |
@@ -4677,8 +4679,9 @@ discard block |
||
| 4677 | 4679 | die(); |
| 4678 | 4680 | } |
| 4679 | 4681 | |
| 4680 | - if($this->theme === null) |
|
| 4681 | - $this->set_theme($this->default_theme); |
|
| 4682 | + if($this->theme === null) { |
|
| 4683 | + $this->set_theme($this->default_theme); |
|
| 4684 | + } |
|
| 4682 | 4685 | $this->setThemeBasics(); |
| 4683 | 4686 | |
| 4684 | 4687 | $this->set_basic_Layout(); |
@@ -4695,8 +4698,9 @@ discard block |
||
| 4695 | 4698 | die(); |
| 4696 | 4699 | } |
| 4697 | 4700 | |
| 4698 | - if($this->theme === null) |
|
| 4699 | - $this->set_theme($this->default_theme); |
|
| 4701 | + if($this->theme === null) { |
|
| 4702 | + $this->set_theme($this->default_theme); |
|
| 4703 | + } |
|
| 4700 | 4704 | $this->setThemeBasics(); |
| 4701 | 4705 | |
| 4702 | 4706 | $this->set_basic_Layout(); |
@@ -4943,8 +4947,7 @@ discard block |
||
| 4943 | 4947 | if($this->basic_db_table_checked) |
| 4944 | 4948 | { |
| 4945 | 4949 | return $this->basic_db_table; |
| 4946 | - } |
|
| 4947 | - elseif( $this->basic_db_table !== null ) |
|
| 4950 | + } elseif( $this->basic_db_table !== null ) |
|
| 4948 | 4951 | { |
| 4949 | 4952 | if(!$this->table_exists($this->basic_db_table)) |
| 4950 | 4953 | { |
@@ -4953,8 +4956,7 @@ discard block |
||
| 4953 | 4956 | } |
| 4954 | 4957 | $this->basic_db_table_checked = true; |
| 4955 | 4958 | return $this->basic_db_table; |
| 4956 | - } |
|
| 4957 | - else |
|
| 4959 | + } else |
|
| 4958 | 4960 | { |
| 4959 | 4961 | //Last try , try to find the table from your view / function name!!! Not suggested but it works . |
| 4960 | 4962 | $last_chance_table_name = $this->get_method_name(); |
@@ -5018,12 +5020,10 @@ discard block |
||
| 5018 | 5020 | if(!empty($table_name) && $this->basic_db_table === null) |
| 5019 | 5021 | { |
| 5020 | 5022 | $this->basic_db_table = $table_name; |
| 5021 | - } |
|
| 5022 | - elseif(!empty($table_name)) |
|
| 5023 | + } elseif(!empty($table_name)) |
|
| 5023 | 5024 | { |
| 5024 | 5025 | throw new Exception('You have already insert a table name once...', 1); |
| 5025 | - } |
|
| 5026 | - else |
|
| 5026 | + } else |
|
| 5027 | 5027 | { |
| 5028 | 5028 | throw new Exception('The table name cannot be empty.', 2); |
| 5029 | 5029 | die(); |
@@ -483,6 +483,7 @@ |
||
| 483 | 483 | /** |
| 484 | 484 | * Return path to ckeditor.js. |
| 485 | 485 | * \private |
| 486 | + * @return string |
|
| 486 | 487 | */ |
| 487 | 488 | function ckeditorPath() |
| 488 | 489 | {
|
@@ -17,550 +17,550 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class CKEditor |
| 19 | 19 | {
|
| 20 | - /** |
|
| 21 | - * The version of %CKEditor. |
|
| 22 | - * \private |
|
| 23 | - */ |
|
| 24 | - var $version = '3.6.5'; |
|
| 25 | - /** |
|
| 26 | - * A constant string unique for each release of %CKEditor. |
|
| 27 | - * \private |
|
| 28 | - */ |
|
| 29 | - var $_timestamp = 'C9A85WF'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * URL to the %CKEditor installation directory (absolute or relative to document root). |
|
| 33 | - * If not set, CKEditor will try to guess it's path. |
|
| 34 | - * |
|
| 35 | - * Example usage: |
|
| 36 | - * @code |
|
| 37 | - * $CKEditor->basePath = '/ckeditor/'; |
|
| 38 | - * @endcode |
|
| 39 | - */ |
|
| 40 | - var $basePath; |
|
| 41 | - /** |
|
| 42 | - * An array that holds the global %CKEditor configuration. |
|
| 43 | - * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html |
|
| 44 | - * |
|
| 45 | - * Example usage: |
|
| 46 | - * @code |
|
| 47 | - * $CKEditor->config['height'] = 400; |
|
| 48 | - * // Use @@ at the beggining of a string to ouput it without surrounding quotes. |
|
| 49 | - * $CKEditor->config['width'] = '@@screen.width * 0.8'; |
|
| 50 | - * @endcode |
|
| 51 | - */ |
|
| 52 | - var $config = array(); |
|
| 53 | - /** |
|
| 54 | - * A boolean variable indicating whether CKEditor has been initialized. |
|
| 55 | - * Set it to true only if you have already included |
|
| 56 | - * <script> tag loading ckeditor.js in your website. |
|
| 57 | - */ |
|
| 58 | - var $initialized = false; |
|
| 59 | - /** |
|
| 60 | - * Boolean variable indicating whether created code should be printed out or returned by a function. |
|
| 61 | - * |
|
| 62 | - * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function. |
|
| 63 | - * @code |
|
| 64 | - * $CKEditor = new CKEditor(); |
|
| 65 | - * $CKEditor->returnOutput = true; |
|
| 66 | - * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
|
|
| 67 | - * echo "<p>Editor 1:</p>"; |
|
| 68 | - * echo $code; |
|
| 69 | - * @endcode |
|
| 70 | - */ |
|
| 71 | - var $returnOutput = false; |
|
| 72 | - /** |
|
| 73 | - * An array with textarea attributes. |
|
| 74 | - * |
|
| 75 | - * When %CKEditor is created with the editor() method, a HTML <textarea> element is created, |
|
| 76 | - * it will be displayed to anyone with JavaScript disabled or with incompatible browser. |
|
| 77 | - */ |
|
| 78 | - var $textareaAttributes = array( "rows" => 8, "cols" => 60 ); |
|
| 79 | - /** |
|
| 80 | - * A string indicating the creation date of %CKEditor. |
|
| 81 | - * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor. |
|
| 82 | - */ |
|
| 83 | - var $timestamp = "C9A85WF"; |
|
| 84 | - /** |
|
| 85 | - * An array that holds event listeners. |
|
| 86 | - * \private |
|
| 87 | - */ |
|
| 88 | - var $_events = array(); |
|
| 89 | - /** |
|
| 90 | - * An array that holds global event listeners. |
|
| 91 | - * \private |
|
| 92 | - */ |
|
| 93 | - var $_globalEvents = array(); |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Main Constructor. |
|
| 97 | - * |
|
| 98 | - * @param $basePath (string) URL to the %CKEditor installation directory (optional). |
|
| 99 | - */ |
|
| 100 | - function CKEditor($basePath = null) {
|
|
| 101 | - if (!empty($basePath)) {
|
|
| 102 | - $this->basePath = $basePath; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Creates a %CKEditor instance. |
|
| 108 | - * In incompatible browsers %CKEditor will downgrade to plain HTML <textarea> element. |
|
| 109 | - * |
|
| 110 | - * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element). |
|
| 111 | - * @param $value (string) Initial value (optional). |
|
| 112 | - * @param $config (array) The specific configurations to apply to this editor instance (optional). |
|
| 113 | - * @param $events (array) Event listeners for this editor instance (optional). |
|
| 114 | - * |
|
| 115 | - * Example usage: |
|
| 116 | - * @code |
|
| 117 | - * $CKEditor = new CKEditor(); |
|
| 118 | - * $CKEditor->editor("field1", "<p>Initial value.</p>");
|
|
| 119 | - * @endcode |
|
| 120 | - * |
|
| 121 | - * Advanced example: |
|
| 122 | - * @code |
|
| 123 | - * $CKEditor = new CKEditor(); |
|
| 124 | - * $config = array(); |
|
| 125 | - * $config['toolbar'] = array( |
|
| 126 | - * array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ), |
|
| 127 | - * array( 'Image', 'Link', 'Unlink', 'Anchor' ) |
|
| 128 | - * ); |
|
| 129 | - * $events['instanceReady'] = 'function (ev) {
|
|
| 130 | - * alert("Loaded: " + ev.editor.name);
|
|
| 131 | - * }'; |
|
| 132 | - * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
|
|
| 133 | - * @endcode |
|
| 134 | - */ |
|
| 135 | - function editor($name, $value = "", $config = array(), $events = array()) |
|
| 136 | - {
|
|
| 137 | - $attr = ""; |
|
| 138 | - foreach ($this->textareaAttributes as $key => $val) {
|
|
| 139 | - $attr.= " " . $key . '="' . str_replace('"', '"', $val) . '"';
|
|
| 140 | - } |
|
| 141 | - $out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n"; |
|
| 142 | - if (!$this->initialized) {
|
|
| 143 | - $out .= $this->init(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $_config = $this->configSettings($config, $events); |
|
| 147 | - |
|
| 148 | - $js = $this->returnGlobalEvents(); |
|
| 149 | - if (!empty($_config)) |
|
| 150 | - $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
|
|
| 151 | - else |
|
| 152 | - $js .= "CKEDITOR.replace('".$name."');";
|
|
| 153 | - |
|
| 154 | - $out .= $this->script($js); |
|
| 155 | - |
|
| 156 | - if (!$this->returnOutput) {
|
|
| 157 | - print $out; |
|
| 158 | - $out = ""; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $out; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Replaces a <textarea> with a %CKEditor instance. |
|
| 166 | - * |
|
| 167 | - * @param $id (string) The id or name of textarea element. |
|
| 168 | - * @param $config (array) The specific configurations to apply to this editor instance (optional). |
|
| 169 | - * @param $events (array) Event listeners for this editor instance (optional). |
|
| 170 | - * |
|
| 171 | - * Example 1: adding %CKEditor to <textarea name="article"></textarea> element: |
|
| 172 | - * @code |
|
| 173 | - * $CKEditor = new CKEditor(); |
|
| 174 | - * $CKEditor->replace("article");
|
|
| 175 | - * @endcode |
|
| 176 | - */ |
|
| 177 | - function replace($id, $config = array(), $events = array()) |
|
| 178 | - {
|
|
| 179 | - $out = ""; |
|
| 180 | - if (!$this->initialized) {
|
|
| 181 | - $out .= $this->init(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $_config = $this->configSettings($config, $events); |
|
| 185 | - |
|
| 186 | - $js = $this->returnGlobalEvents(); |
|
| 187 | - if (!empty($_config)) {
|
|
| 188 | - $js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
|
|
| 189 | - } |
|
| 190 | - else {
|
|
| 191 | - $js .= "CKEDITOR.replace('".$id."');";
|
|
| 192 | - } |
|
| 193 | - $out .= $this->script($js); |
|
| 194 | - |
|
| 195 | - if (!$this->returnOutput) {
|
|
| 196 | - print $out; |
|
| 197 | - $out = ""; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $out; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Replace all <textarea> elements available in the document with editor instances. |
|
| 205 | - * |
|
| 206 | - * @param $className (string) If set, replace all textareas with class className in the page. |
|
| 207 | - * |
|
| 208 | - * Example 1: replace all <textarea> elements in the page. |
|
| 209 | - * @code |
|
| 210 | - * $CKEditor = new CKEditor(); |
|
| 211 | - * $CKEditor->replaceAll(); |
|
| 212 | - * @endcode |
|
| 213 | - * |
|
| 214 | - * Example 2: replace all <textarea class="myClassName"> elements in the page. |
|
| 215 | - * @code |
|
| 216 | - * $CKEditor = new CKEditor(); |
|
| 217 | - * $CKEditor->replaceAll( 'myClassName' ); |
|
| 218 | - * @endcode |
|
| 219 | - */ |
|
| 220 | - function replaceAll($className = null) |
|
| 221 | - {
|
|
| 222 | - $out = ""; |
|
| 223 | - if (!$this->initialized) {
|
|
| 224 | - $out .= $this->init(); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $_config = $this->configSettings(); |
|
| 228 | - |
|
| 229 | - $js = $this->returnGlobalEvents(); |
|
| 230 | - if (empty($_config)) {
|
|
| 231 | - if (empty($className)) {
|
|
| 232 | - $js .= "CKEDITOR.replaceAll();"; |
|
| 233 | - } |
|
| 234 | - else {
|
|
| 235 | - $js .= "CKEDITOR.replaceAll('".$className."');";
|
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - else {
|
|
| 239 | - $classDetection = ""; |
|
| 240 | - $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
|
|
| 241 | - if (!empty($className)) {
|
|
| 242 | - $js .= " var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
|
|
| 243 | - $js .= " if (!classRegex.test(textarea.className))\n"; |
|
| 244 | - $js .= " return false;\n"; |
|
| 245 | - } |
|
| 246 | - $js .= " CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);"; |
|
| 247 | - $js .= "} );"; |
|
| 248 | - |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $out .= $this->script($js); |
|
| 252 | - |
|
| 253 | - if (!$this->returnOutput) {
|
|
| 254 | - print $out; |
|
| 255 | - $out = ""; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $out; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Adds event listener. |
|
| 263 | - * Events are fired by %CKEditor in various situations. |
|
| 264 | - * |
|
| 265 | - * @param $event (string) Event name. |
|
| 266 | - * @param $javascriptCode (string) Javascript anonymous function or function name. |
|
| 267 | - * |
|
| 268 | - * Example usage: |
|
| 269 | - * @code |
|
| 270 | - * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
|
|
| 271 | - * alert("Loaded: " + ev.editor.name);
|
|
| 272 | - * }'); |
|
| 273 | - * @endcode |
|
| 274 | - */ |
|
| 275 | - function addEventHandler($event, $javascriptCode) |
|
| 276 | - {
|
|
| 277 | - if (!isset($this->_events[$event])) {
|
|
| 278 | - $this->_events[$event] = array(); |
|
| 279 | - } |
|
| 280 | - // Avoid duplicates. |
|
| 281 | - if (!in_array($javascriptCode, $this->_events[$event])) {
|
|
| 282 | - $this->_events[$event][] = $javascriptCode; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Clear registered event handlers. |
|
| 288 | - * Note: this function will have no effect on already created editor instances. |
|
| 289 | - * |
|
| 290 | - * @param $event (string) Event name, if not set all event handlers will be removed (optional). |
|
| 291 | - */ |
|
| 292 | - function clearEventHandlers($event = null) |
|
| 293 | - {
|
|
| 294 | - if (!empty($event)) {
|
|
| 295 | - $this->_events[$event] = array(); |
|
| 296 | - } |
|
| 297 | - else {
|
|
| 298 | - $this->_events = array(); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Adds global event listener. |
|
| 304 | - * |
|
| 305 | - * @param $event (string) Event name. |
|
| 306 | - * @param $javascriptCode (string) Javascript anonymous function or function name. |
|
| 307 | - * |
|
| 308 | - * Example usage: |
|
| 309 | - * @code |
|
| 310 | - * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
|
|
| 311 | - * alert("Loading dialog: " + ev.data.name);
|
|
| 312 | - * }'); |
|
| 313 | - * @endcode |
|
| 314 | - */ |
|
| 315 | - function addGlobalEventHandler($event, $javascriptCode) |
|
| 316 | - {
|
|
| 317 | - if (!isset($this->_globalEvents[$event])) {
|
|
| 318 | - $this->_globalEvents[$event] = array(); |
|
| 319 | - } |
|
| 320 | - // Avoid duplicates. |
|
| 321 | - if (!in_array($javascriptCode, $this->_globalEvents[$event])) {
|
|
| 322 | - $this->_globalEvents[$event][] = $javascriptCode; |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Clear registered global event handlers. |
|
| 328 | - * Note: this function will have no effect if the event handler has been already printed/returned. |
|
| 329 | - * |
|
| 330 | - * @param $event (string) Event name, if not set all event handlers will be removed (optional). |
|
| 331 | - */ |
|
| 332 | - function clearGlobalEventHandlers($event = null) |
|
| 333 | - {
|
|
| 334 | - if (!empty($event)) {
|
|
| 335 | - $this->_globalEvents[$event] = array(); |
|
| 336 | - } |
|
| 337 | - else {
|
|
| 338 | - $this->_globalEvents = array(); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Prints javascript code. |
|
| 344 | - * \private |
|
| 345 | - * |
|
| 346 | - * @param string $js |
|
| 347 | - */ |
|
| 348 | - function script($js) |
|
| 349 | - {
|
|
| 350 | - $out = "<script type=\"text/javascript\">"; |
|
| 351 | - $out .= "//<![CDATA[\n"; |
|
| 352 | - $out .= $js; |
|
| 353 | - $out .= "\n//]]>"; |
|
| 354 | - $out .= "</script>\n"; |
|
| 355 | - |
|
| 356 | - return $out; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Returns the configuration array (global and instance specific settings are merged into one array). |
|
| 361 | - * \private |
|
| 362 | - * |
|
| 363 | - * @param $config (array) The specific configurations to apply to editor instance. |
|
| 364 | - * @param $events (array) Event listeners for editor instance. |
|
| 365 | - */ |
|
| 366 | - function configSettings($config = array(), $events = array()) |
|
| 367 | - {
|
|
| 368 | - $_config = $this->config; |
|
| 369 | - $_events = $this->_events; |
|
| 370 | - |
|
| 371 | - if (is_array($config) && !empty($config)) {
|
|
| 372 | - $_config = array_merge($_config, $config); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if (is_array($events) && !empty($events)) {
|
|
| 376 | - foreach ($events as $eventName => $code) {
|
|
| 377 | - if (!isset($_events[$eventName])) {
|
|
| 378 | - $_events[$eventName] = array(); |
|
| 379 | - } |
|
| 380 | - if (!in_array($code, $_events[$eventName])) {
|
|
| 381 | - $_events[$eventName][] = $code; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - if (!empty($_events)) {
|
|
| 387 | - foreach($_events as $eventName => $handlers) {
|
|
| 388 | - if (empty($handlers)) {
|
|
| 389 | - continue; |
|
| 390 | - } |
|
| 391 | - else if (count($handlers) == 1) {
|
|
| 392 | - $_config['on'][$eventName] = '@@'.$handlers[0]; |
|
| 393 | - } |
|
| 394 | - else {
|
|
| 395 | - $_config['on'][$eventName] = '@@function (ev){';
|
|
| 396 | - foreach ($handlers as $handler => $code) {
|
|
| 397 | - $_config['on'][$eventName] .= '('.$code.')(ev);';
|
|
| 398 | - } |
|
| 399 | - $_config['on'][$eventName] .= '}'; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $_config; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Return global event handlers. |
|
| 409 | - * \private |
|
| 410 | - */ |
|
| 411 | - function returnGlobalEvents() |
|
| 412 | - {
|
|
| 413 | - static $returnedEvents; |
|
| 414 | - $out = ""; |
|
| 415 | - |
|
| 416 | - if (!isset($returnedEvents)) {
|
|
| 417 | - $returnedEvents = array(); |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - if (!empty($this->_globalEvents)) {
|
|
| 421 | - foreach ($this->_globalEvents as $eventName => $handlers) {
|
|
| 422 | - foreach ($handlers as $handler => $code) {
|
|
| 423 | - if (!isset($returnedEvents[$eventName])) {
|
|
| 424 | - $returnedEvents[$eventName] = array(); |
|
| 425 | - } |
|
| 426 | - // Return only new events |
|
| 427 | - if (!in_array($code, $returnedEvents[$eventName])) {
|
|
| 428 | - $out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
|
|
| 429 | - $returnedEvents[$eventName][] = $code; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - return $out; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Initializes CKEditor (executed only once). |
|
| 440 | - * \private |
|
| 441 | - */ |
|
| 442 | - function init() |
|
| 443 | - {
|
|
| 444 | - static $initComplete; |
|
| 445 | - $out = ""; |
|
| 446 | - |
|
| 447 | - if (!empty($initComplete)) {
|
|
| 448 | - return ""; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - if ($this->initialized) {
|
|
| 452 | - $initComplete = true; |
|
| 453 | - return ""; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - $args = ""; |
|
| 457 | - $ckeditorPath = $this->ckeditorPath(); |
|
| 458 | - |
|
| 459 | - if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
|
|
| 460 | - $args = '?t=' . $this->timestamp; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // Skip relative paths... |
|
| 464 | - if (strpos($ckeditorPath, '..') !== 0) {
|
|
| 465 | - $out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
|
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - $out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n"; |
|
| 469 | - |
|
| 470 | - $extraCode = ""; |
|
| 471 | - if ($this->timestamp != $this->_timestamp) {
|
|
| 472 | - $extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';"; |
|
| 473 | - } |
|
| 474 | - if ($extraCode) {
|
|
| 475 | - $out .= $this->script($extraCode); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $initComplete = $this->initialized = true; |
|
| 479 | - |
|
| 480 | - return $out; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Return path to ckeditor.js. |
|
| 485 | - * \private |
|
| 486 | - */ |
|
| 487 | - function ckeditorPath() |
|
| 488 | - {
|
|
| 489 | - if (!empty($this->basePath)) {
|
|
| 490 | - return $this->basePath; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * The absolute pathname of the currently executing script. |
|
| 495 | - * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, |
|
| 496 | - * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. |
|
| 497 | - */ |
|
| 498 | - if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
|
| 499 | - $realPath = dirname($_SERVER['SCRIPT_FILENAME']); |
|
| 500 | - } |
|
| 501 | - else {
|
|
| 502 | - /** |
|
| 503 | - * realpath - Returns canonicalized absolute pathname |
|
| 504 | - */ |
|
| 505 | - $realPath = realpath( './' ) ; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * The filename of the currently executing script, relative to the document root. |
|
| 510 | - * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar |
|
| 511 | - * would be /test.php/foo.bar. |
|
| 512 | - */ |
|
| 513 | - $selfPath = dirname($_SERVER['PHP_SELF']); |
|
| 514 | - $file = str_replace("\\", "/", __FILE__);
|
|
| 515 | - |
|
| 516 | - if (!$selfPath || !$realPath || !$file) {
|
|
| 517 | - return "/ckeditor/"; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath)); |
|
| 521 | - $fileUrl = substr($file, strlen($documentRoot)); |
|
| 522 | - $ckeditorUrl = str_replace("ckeditor_php4.php", "", $fileUrl);
|
|
| 523 | - |
|
| 524 | - return $ckeditorUrl; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * This little function provides a basic JSON support. |
|
| 529 | - * \private |
|
| 530 | - * |
|
| 531 | - * @param mixed $val |
|
| 532 | - * @return string |
|
| 533 | - */ |
|
| 534 | - function jsEncode($val) |
|
| 535 | - {
|
|
| 536 | - if (is_null($val)) {
|
|
| 537 | - return 'null'; |
|
| 538 | - } |
|
| 539 | - if (is_bool($val)) {
|
|
| 540 | - return $val ? 'true' : 'false'; |
|
| 541 | - } |
|
| 542 | - if (is_int($val)) {
|
|
| 543 | - return $val; |
|
| 544 | - } |
|
| 545 | - if (is_float($val)) {
|
|
| 546 | - return str_replace(',', '.', $val);
|
|
| 547 | - } |
|
| 548 | - if (is_array($val) || is_object($val)) {
|
|
| 549 | - if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
|
|
| 550 | - return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
|
|
| 551 | - } |
|
| 552 | - $temp = array(); |
|
| 553 | - foreach ($val as $k => $v){
|
|
| 554 | - $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
|
|
| 555 | - } |
|
| 556 | - return '{' . implode(',', $temp) . '}';
|
|
| 557 | - } |
|
| 558 | - // String otherwise |
|
| 559 | - if (strpos($val, '@@') === 0) |
|
| 560 | - return substr($val, 2); |
|
| 561 | - if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') |
|
| 562 | - return $val; |
|
| 563 | - |
|
| 564 | - return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
|
|
| 565 | - } |
|
| 20 | + /** |
|
| 21 | + * The version of %CKEditor. |
|
| 22 | + * \private |
|
| 23 | + */ |
|
| 24 | + var $version = '3.6.5'; |
|
| 25 | + /** |
|
| 26 | + * A constant string unique for each release of %CKEditor. |
|
| 27 | + * \private |
|
| 28 | + */ |
|
| 29 | + var $_timestamp = 'C9A85WF'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * URL to the %CKEditor installation directory (absolute or relative to document root). |
|
| 33 | + * If not set, CKEditor will try to guess it's path. |
|
| 34 | + * |
|
| 35 | + * Example usage: |
|
| 36 | + * @code |
|
| 37 | + * $CKEditor->basePath = '/ckeditor/'; |
|
| 38 | + * @endcode |
|
| 39 | + */ |
|
| 40 | + var $basePath; |
|
| 41 | + /** |
|
| 42 | + * An array that holds the global %CKEditor configuration. |
|
| 43 | + * For the list of available options, see http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html |
|
| 44 | + * |
|
| 45 | + * Example usage: |
|
| 46 | + * @code |
|
| 47 | + * $CKEditor->config['height'] = 400; |
|
| 48 | + * // Use @@ at the beggining of a string to ouput it without surrounding quotes. |
|
| 49 | + * $CKEditor->config['width'] = '@@screen.width * 0.8'; |
|
| 50 | + * @endcode |
|
| 51 | + */ |
|
| 52 | + var $config = array(); |
|
| 53 | + /** |
|
| 54 | + * A boolean variable indicating whether CKEditor has been initialized. |
|
| 55 | + * Set it to true only if you have already included |
|
| 56 | + * <script> tag loading ckeditor.js in your website. |
|
| 57 | + */ |
|
| 58 | + var $initialized = false; |
|
| 59 | + /** |
|
| 60 | + * Boolean variable indicating whether created code should be printed out or returned by a function. |
|
| 61 | + * |
|
| 62 | + * Example 1: get the code creating %CKEditor instance and print it on a page with the "echo" function. |
|
| 63 | + * @code |
|
| 64 | + * $CKEditor = new CKEditor(); |
|
| 65 | + * $CKEditor->returnOutput = true; |
|
| 66 | + * $code = $CKEditor->editor("editor1", "<p>Initial value.</p>");
|
|
| 67 | + * echo "<p>Editor 1:</p>"; |
|
| 68 | + * echo $code; |
|
| 69 | + * @endcode |
|
| 70 | + */ |
|
| 71 | + var $returnOutput = false; |
|
| 72 | + /** |
|
| 73 | + * An array with textarea attributes. |
|
| 74 | + * |
|
| 75 | + * When %CKEditor is created with the editor() method, a HTML <textarea> element is created, |
|
| 76 | + * it will be displayed to anyone with JavaScript disabled or with incompatible browser. |
|
| 77 | + */ |
|
| 78 | + var $textareaAttributes = array( "rows" => 8, "cols" => 60 ); |
|
| 79 | + /** |
|
| 80 | + * A string indicating the creation date of %CKEditor. |
|
| 81 | + * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor. |
|
| 82 | + */ |
|
| 83 | + var $timestamp = "C9A85WF"; |
|
| 84 | + /** |
|
| 85 | + * An array that holds event listeners. |
|
| 86 | + * \private |
|
| 87 | + */ |
|
| 88 | + var $_events = array(); |
|
| 89 | + /** |
|
| 90 | + * An array that holds global event listeners. |
|
| 91 | + * \private |
|
| 92 | + */ |
|
| 93 | + var $_globalEvents = array(); |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Main Constructor. |
|
| 97 | + * |
|
| 98 | + * @param $basePath (string) URL to the %CKEditor installation directory (optional). |
|
| 99 | + */ |
|
| 100 | + function CKEditor($basePath = null) {
|
|
| 101 | + if (!empty($basePath)) {
|
|
| 102 | + $this->basePath = $basePath; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Creates a %CKEditor instance. |
|
| 108 | + * In incompatible browsers %CKEditor will downgrade to plain HTML <textarea> element. |
|
| 109 | + * |
|
| 110 | + * @param $name (string) Name of the %CKEditor instance (this will be also the "name" attribute of textarea element). |
|
| 111 | + * @param $value (string) Initial value (optional). |
|
| 112 | + * @param $config (array) The specific configurations to apply to this editor instance (optional). |
|
| 113 | + * @param $events (array) Event listeners for this editor instance (optional). |
|
| 114 | + * |
|
| 115 | + * Example usage: |
|
| 116 | + * @code |
|
| 117 | + * $CKEditor = new CKEditor(); |
|
| 118 | + * $CKEditor->editor("field1", "<p>Initial value.</p>");
|
|
| 119 | + * @endcode |
|
| 120 | + * |
|
| 121 | + * Advanced example: |
|
| 122 | + * @code |
|
| 123 | + * $CKEditor = new CKEditor(); |
|
| 124 | + * $config = array(); |
|
| 125 | + * $config['toolbar'] = array( |
|
| 126 | + * array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike' ), |
|
| 127 | + * array( 'Image', 'Link', 'Unlink', 'Anchor' ) |
|
| 128 | + * ); |
|
| 129 | + * $events['instanceReady'] = 'function (ev) {
|
|
| 130 | + * alert("Loaded: " + ev.editor.name);
|
|
| 131 | + * }'; |
|
| 132 | + * $CKEditor->editor("field1", "<p>Initial value.</p>", $config, $events);
|
|
| 133 | + * @endcode |
|
| 134 | + */ |
|
| 135 | + function editor($name, $value = "", $config = array(), $events = array()) |
|
| 136 | + {
|
|
| 137 | + $attr = ""; |
|
| 138 | + foreach ($this->textareaAttributes as $key => $val) {
|
|
| 139 | + $attr.= " " . $key . '="' . str_replace('"', '"', $val) . '"';
|
|
| 140 | + } |
|
| 141 | + $out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n"; |
|
| 142 | + if (!$this->initialized) {
|
|
| 143 | + $out .= $this->init(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $_config = $this->configSettings($config, $events); |
|
| 147 | + |
|
| 148 | + $js = $this->returnGlobalEvents(); |
|
| 149 | + if (!empty($_config)) |
|
| 150 | + $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
|
|
| 151 | + else |
|
| 152 | + $js .= "CKEDITOR.replace('".$name."');";
|
|
| 153 | + |
|
| 154 | + $out .= $this->script($js); |
|
| 155 | + |
|
| 156 | + if (!$this->returnOutput) {
|
|
| 157 | + print $out; |
|
| 158 | + $out = ""; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $out; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Replaces a <textarea> with a %CKEditor instance. |
|
| 166 | + * |
|
| 167 | + * @param $id (string) The id or name of textarea element. |
|
| 168 | + * @param $config (array) The specific configurations to apply to this editor instance (optional). |
|
| 169 | + * @param $events (array) Event listeners for this editor instance (optional). |
|
| 170 | + * |
|
| 171 | + * Example 1: adding %CKEditor to <textarea name="article"></textarea> element: |
|
| 172 | + * @code |
|
| 173 | + * $CKEditor = new CKEditor(); |
|
| 174 | + * $CKEditor->replace("article");
|
|
| 175 | + * @endcode |
|
| 176 | + */ |
|
| 177 | + function replace($id, $config = array(), $events = array()) |
|
| 178 | + {
|
|
| 179 | + $out = ""; |
|
| 180 | + if (!$this->initialized) {
|
|
| 181 | + $out .= $this->init(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $_config = $this->configSettings($config, $events); |
|
| 185 | + |
|
| 186 | + $js = $this->returnGlobalEvents(); |
|
| 187 | + if (!empty($_config)) {
|
|
| 188 | + $js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
|
|
| 189 | + } |
|
| 190 | + else {
|
|
| 191 | + $js .= "CKEDITOR.replace('".$id."');";
|
|
| 192 | + } |
|
| 193 | + $out .= $this->script($js); |
|
| 194 | + |
|
| 195 | + if (!$this->returnOutput) {
|
|
| 196 | + print $out; |
|
| 197 | + $out = ""; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $out; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Replace all <textarea> elements available in the document with editor instances. |
|
| 205 | + * |
|
| 206 | + * @param $className (string) If set, replace all textareas with class className in the page. |
|
| 207 | + * |
|
| 208 | + * Example 1: replace all <textarea> elements in the page. |
|
| 209 | + * @code |
|
| 210 | + * $CKEditor = new CKEditor(); |
|
| 211 | + * $CKEditor->replaceAll(); |
|
| 212 | + * @endcode |
|
| 213 | + * |
|
| 214 | + * Example 2: replace all <textarea class="myClassName"> elements in the page. |
|
| 215 | + * @code |
|
| 216 | + * $CKEditor = new CKEditor(); |
|
| 217 | + * $CKEditor->replaceAll( 'myClassName' ); |
|
| 218 | + * @endcode |
|
| 219 | + */ |
|
| 220 | + function replaceAll($className = null) |
|
| 221 | + {
|
|
| 222 | + $out = ""; |
|
| 223 | + if (!$this->initialized) {
|
|
| 224 | + $out .= $this->init(); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $_config = $this->configSettings(); |
|
| 228 | + |
|
| 229 | + $js = $this->returnGlobalEvents(); |
|
| 230 | + if (empty($_config)) {
|
|
| 231 | + if (empty($className)) {
|
|
| 232 | + $js .= "CKEDITOR.replaceAll();"; |
|
| 233 | + } |
|
| 234 | + else {
|
|
| 235 | + $js .= "CKEDITOR.replaceAll('".$className."');";
|
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + else {
|
|
| 239 | + $classDetection = ""; |
|
| 240 | + $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
|
|
| 241 | + if (!empty($className)) {
|
|
| 242 | + $js .= " var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
|
|
| 243 | + $js .= " if (!classRegex.test(textarea.className))\n"; |
|
| 244 | + $js .= " return false;\n"; |
|
| 245 | + } |
|
| 246 | + $js .= " CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);"; |
|
| 247 | + $js .= "} );"; |
|
| 248 | + |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $out .= $this->script($js); |
|
| 252 | + |
|
| 253 | + if (!$this->returnOutput) {
|
|
| 254 | + print $out; |
|
| 255 | + $out = ""; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $out; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Adds event listener. |
|
| 263 | + * Events are fired by %CKEditor in various situations. |
|
| 264 | + * |
|
| 265 | + * @param $event (string) Event name. |
|
| 266 | + * @param $javascriptCode (string) Javascript anonymous function or function name. |
|
| 267 | + * |
|
| 268 | + * Example usage: |
|
| 269 | + * @code |
|
| 270 | + * $CKEditor->addEventHandler('instanceReady', 'function (ev) {
|
|
| 271 | + * alert("Loaded: " + ev.editor.name);
|
|
| 272 | + * }'); |
|
| 273 | + * @endcode |
|
| 274 | + */ |
|
| 275 | + function addEventHandler($event, $javascriptCode) |
|
| 276 | + {
|
|
| 277 | + if (!isset($this->_events[$event])) {
|
|
| 278 | + $this->_events[$event] = array(); |
|
| 279 | + } |
|
| 280 | + // Avoid duplicates. |
|
| 281 | + if (!in_array($javascriptCode, $this->_events[$event])) {
|
|
| 282 | + $this->_events[$event][] = $javascriptCode; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Clear registered event handlers. |
|
| 288 | + * Note: this function will have no effect on already created editor instances. |
|
| 289 | + * |
|
| 290 | + * @param $event (string) Event name, if not set all event handlers will be removed (optional). |
|
| 291 | + */ |
|
| 292 | + function clearEventHandlers($event = null) |
|
| 293 | + {
|
|
| 294 | + if (!empty($event)) {
|
|
| 295 | + $this->_events[$event] = array(); |
|
| 296 | + } |
|
| 297 | + else {
|
|
| 298 | + $this->_events = array(); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Adds global event listener. |
|
| 304 | + * |
|
| 305 | + * @param $event (string) Event name. |
|
| 306 | + * @param $javascriptCode (string) Javascript anonymous function or function name. |
|
| 307 | + * |
|
| 308 | + * Example usage: |
|
| 309 | + * @code |
|
| 310 | + * $CKEditor->addGlobalEventHandler('dialogDefinition', 'function (ev) {
|
|
| 311 | + * alert("Loading dialog: " + ev.data.name);
|
|
| 312 | + * }'); |
|
| 313 | + * @endcode |
|
| 314 | + */ |
|
| 315 | + function addGlobalEventHandler($event, $javascriptCode) |
|
| 316 | + {
|
|
| 317 | + if (!isset($this->_globalEvents[$event])) {
|
|
| 318 | + $this->_globalEvents[$event] = array(); |
|
| 319 | + } |
|
| 320 | + // Avoid duplicates. |
|
| 321 | + if (!in_array($javascriptCode, $this->_globalEvents[$event])) {
|
|
| 322 | + $this->_globalEvents[$event][] = $javascriptCode; |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Clear registered global event handlers. |
|
| 328 | + * Note: this function will have no effect if the event handler has been already printed/returned. |
|
| 329 | + * |
|
| 330 | + * @param $event (string) Event name, if not set all event handlers will be removed (optional). |
|
| 331 | + */ |
|
| 332 | + function clearGlobalEventHandlers($event = null) |
|
| 333 | + {
|
|
| 334 | + if (!empty($event)) {
|
|
| 335 | + $this->_globalEvents[$event] = array(); |
|
| 336 | + } |
|
| 337 | + else {
|
|
| 338 | + $this->_globalEvents = array(); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Prints javascript code. |
|
| 344 | + * \private |
|
| 345 | + * |
|
| 346 | + * @param string $js |
|
| 347 | + */ |
|
| 348 | + function script($js) |
|
| 349 | + {
|
|
| 350 | + $out = "<script type=\"text/javascript\">"; |
|
| 351 | + $out .= "//<![CDATA[\n"; |
|
| 352 | + $out .= $js; |
|
| 353 | + $out .= "\n//]]>"; |
|
| 354 | + $out .= "</script>\n"; |
|
| 355 | + |
|
| 356 | + return $out; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Returns the configuration array (global and instance specific settings are merged into one array). |
|
| 361 | + * \private |
|
| 362 | + * |
|
| 363 | + * @param $config (array) The specific configurations to apply to editor instance. |
|
| 364 | + * @param $events (array) Event listeners for editor instance. |
|
| 365 | + */ |
|
| 366 | + function configSettings($config = array(), $events = array()) |
|
| 367 | + {
|
|
| 368 | + $_config = $this->config; |
|
| 369 | + $_events = $this->_events; |
|
| 370 | + |
|
| 371 | + if (is_array($config) && !empty($config)) {
|
|
| 372 | + $_config = array_merge($_config, $config); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if (is_array($events) && !empty($events)) {
|
|
| 376 | + foreach ($events as $eventName => $code) {
|
|
| 377 | + if (!isset($_events[$eventName])) {
|
|
| 378 | + $_events[$eventName] = array(); |
|
| 379 | + } |
|
| 380 | + if (!in_array($code, $_events[$eventName])) {
|
|
| 381 | + $_events[$eventName][] = $code; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + if (!empty($_events)) {
|
|
| 387 | + foreach($_events as $eventName => $handlers) {
|
|
| 388 | + if (empty($handlers)) {
|
|
| 389 | + continue; |
|
| 390 | + } |
|
| 391 | + else if (count($handlers) == 1) {
|
|
| 392 | + $_config['on'][$eventName] = '@@'.$handlers[0]; |
|
| 393 | + } |
|
| 394 | + else {
|
|
| 395 | + $_config['on'][$eventName] = '@@function (ev){';
|
|
| 396 | + foreach ($handlers as $handler => $code) {
|
|
| 397 | + $_config['on'][$eventName] .= '('.$code.')(ev);';
|
|
| 398 | + } |
|
| 399 | + $_config['on'][$eventName] .= '}'; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $_config; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Return global event handlers. |
|
| 409 | + * \private |
|
| 410 | + */ |
|
| 411 | + function returnGlobalEvents() |
|
| 412 | + {
|
|
| 413 | + static $returnedEvents; |
|
| 414 | + $out = ""; |
|
| 415 | + |
|
| 416 | + if (!isset($returnedEvents)) {
|
|
| 417 | + $returnedEvents = array(); |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + if (!empty($this->_globalEvents)) {
|
|
| 421 | + foreach ($this->_globalEvents as $eventName => $handlers) {
|
|
| 422 | + foreach ($handlers as $handler => $code) {
|
|
| 423 | + if (!isset($returnedEvents[$eventName])) {
|
|
| 424 | + $returnedEvents[$eventName] = array(); |
|
| 425 | + } |
|
| 426 | + // Return only new events |
|
| 427 | + if (!in_array($code, $returnedEvents[$eventName])) {
|
|
| 428 | + $out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
|
|
| 429 | + $returnedEvents[$eventName][] = $code; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + return $out; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Initializes CKEditor (executed only once). |
|
| 440 | + * \private |
|
| 441 | + */ |
|
| 442 | + function init() |
|
| 443 | + {
|
|
| 444 | + static $initComplete; |
|
| 445 | + $out = ""; |
|
| 446 | + |
|
| 447 | + if (!empty($initComplete)) {
|
|
| 448 | + return ""; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + if ($this->initialized) {
|
|
| 452 | + $initComplete = true; |
|
| 453 | + return ""; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + $args = ""; |
|
| 457 | + $ckeditorPath = $this->ckeditorPath(); |
|
| 458 | + |
|
| 459 | + if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
|
|
| 460 | + $args = '?t=' . $this->timestamp; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // Skip relative paths... |
|
| 464 | + if (strpos($ckeditorPath, '..') !== 0) {
|
|
| 465 | + $out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
|
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + $out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n"; |
|
| 469 | + |
|
| 470 | + $extraCode = ""; |
|
| 471 | + if ($this->timestamp != $this->_timestamp) {
|
|
| 472 | + $extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';"; |
|
| 473 | + } |
|
| 474 | + if ($extraCode) {
|
|
| 475 | + $out .= $this->script($extraCode); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $initComplete = $this->initialized = true; |
|
| 479 | + |
|
| 480 | + return $out; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Return path to ckeditor.js. |
|
| 485 | + * \private |
|
| 486 | + */ |
|
| 487 | + function ckeditorPath() |
|
| 488 | + {
|
|
| 489 | + if (!empty($this->basePath)) {
|
|
| 490 | + return $this->basePath; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * The absolute pathname of the currently executing script. |
|
| 495 | + * Note: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php, |
|
| 496 | + * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user. |
|
| 497 | + */ |
|
| 498 | + if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
|
| 499 | + $realPath = dirname($_SERVER['SCRIPT_FILENAME']); |
|
| 500 | + } |
|
| 501 | + else {
|
|
| 502 | + /** |
|
| 503 | + * realpath - Returns canonicalized absolute pathname |
|
| 504 | + */ |
|
| 505 | + $realPath = realpath( './' ) ; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * The filename of the currently executing script, relative to the document root. |
|
| 510 | + * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar |
|
| 511 | + * would be /test.php/foo.bar. |
|
| 512 | + */ |
|
| 513 | + $selfPath = dirname($_SERVER['PHP_SELF']); |
|
| 514 | + $file = str_replace("\\", "/", __FILE__);
|
|
| 515 | + |
|
| 516 | + if (!$selfPath || !$realPath || !$file) {
|
|
| 517 | + return "/ckeditor/"; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $documentRoot = substr($realPath, 0, strlen($realPath) - strlen($selfPath)); |
|
| 521 | + $fileUrl = substr($file, strlen($documentRoot)); |
|
| 522 | + $ckeditorUrl = str_replace("ckeditor_php4.php", "", $fileUrl);
|
|
| 523 | + |
|
| 524 | + return $ckeditorUrl; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * This little function provides a basic JSON support. |
|
| 529 | + * \private |
|
| 530 | + * |
|
| 531 | + * @param mixed $val |
|
| 532 | + * @return string |
|
| 533 | + */ |
|
| 534 | + function jsEncode($val) |
|
| 535 | + {
|
|
| 536 | + if (is_null($val)) {
|
|
| 537 | + return 'null'; |
|
| 538 | + } |
|
| 539 | + if (is_bool($val)) {
|
|
| 540 | + return $val ? 'true' : 'false'; |
|
| 541 | + } |
|
| 542 | + if (is_int($val)) {
|
|
| 543 | + return $val; |
|
| 544 | + } |
|
| 545 | + if (is_float($val)) {
|
|
| 546 | + return str_replace(',', '.', $val);
|
|
| 547 | + } |
|
| 548 | + if (is_array($val) || is_object($val)) {
|
|
| 549 | + if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
|
|
| 550 | + return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
|
|
| 551 | + } |
|
| 552 | + $temp = array(); |
|
| 553 | + foreach ($val as $k => $v){
|
|
| 554 | + $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
|
|
| 555 | + } |
|
| 556 | + return '{' . implode(',', $temp) . '}';
|
|
| 557 | + } |
|
| 558 | + // String otherwise |
|
| 559 | + if (strpos($val, '@@') === 0) |
|
| 560 | + return substr($val, 2); |
|
| 561 | + if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') |
|
| 562 | + return $val; |
|
| 563 | + |
|
| 564 | + return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
|
|
| 565 | + } |
|
| 566 | 566 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * When %CKEditor is created with the editor() method, a HTML <textarea> element is created, |
| 76 | 76 | * it will be displayed to anyone with JavaScript disabled or with incompatible browser. |
| 77 | 77 | */ |
| 78 | - var $textareaAttributes = array( "rows" => 8, "cols" => 60 ); |
|
| 78 | + var $textareaAttributes = array("rows" => 8, "cols" => 60);
|
|
| 79 | 79 | /** |
| 80 | 80 | * A string indicating the creation date of %CKEditor. |
| 81 | 81 | * Do not change it unless you want to force browsers to not use previously cached version of %CKEditor. |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | {
|
| 137 | 137 | $attr = ""; |
| 138 | 138 | foreach ($this->textareaAttributes as $key => $val) {
|
| 139 | - $attr.= " " . $key . '="' . str_replace('"', '"', $val) . '"';
|
|
| 139 | + $attr .= " ".$key.'="'.str_replace('"', '"', $val).'"';
|
|
| 140 | 140 | } |
| 141 | - $out = "<textarea name=\"" . $name . "\"" . $attr . ">" . htmlspecialchars($value) . "</textarea>\n"; |
|
| 141 | + $out = "<textarea name=\"".$name."\"".$attr.">".htmlspecialchars($value)."</textarea>\n"; |
|
| 142 | 142 | if (!$this->initialized) {
|
| 143 | 143 | $out .= $this->init(); |
| 144 | 144 | } |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | $classDetection = ""; |
| 240 | 240 | $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
|
| 241 | 241 | if (!empty($className)) {
|
| 242 | - $js .= " var classRegex = new RegExp('(?:^| )' + '". $className ."' + '(?:$| )');\n";
|
|
| 242 | + $js .= " var classRegex = new RegExp('(?:^| )' + '".$className."' + '(?:$| )');\n";
|
|
| 243 | 243 | $js .= " if (!classRegex.test(textarea.className))\n"; |
| 244 | 244 | $js .= " return false;\n"; |
| 245 | 245 | } |
| 246 | - $js .= " CKEDITOR.tools.extend(config, ". $this->jsEncode($_config) .", true);"; |
|
| 246 | + $js .= " CKEDITOR.tools.extend(config, ".$this->jsEncode($_config).", true);"; |
|
| 247 | 247 | $js .= "} );"; |
| 248 | 248 | |
| 249 | 249 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | if (!empty($_events)) {
|
| 387 | - foreach($_events as $eventName => $handlers) {
|
|
| 387 | + foreach ($_events as $eventName => $handlers) {
|
|
| 388 | 388 | if (empty($handlers)) {
|
| 389 | 389 | continue; |
| 390 | 390 | } |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | // Return only new events |
| 427 | 427 | if (!in_array($code, $returnedEvents[$eventName])) {
|
| 428 | - $out .= ($code ? "\n" : "") . "CKEDITOR.on('". $eventName ."', $code);";
|
|
| 428 | + $out .= ($code ? "\n" : "")."CKEDITOR.on('".$eventName."', $code);";
|
|
| 429 | 429 | $returnedEvents[$eventName][] = $code; |
| 430 | 430 | } |
| 431 | 431 | } |
@@ -457,19 +457,19 @@ discard block |
||
| 457 | 457 | $ckeditorPath = $this->ckeditorPath(); |
| 458 | 458 | |
| 459 | 459 | if (!empty($this->timestamp) && $this->timestamp != "%"."TIMESTAMP%") {
|
| 460 | - $args = '?t=' . $this->timestamp; |
|
| 460 | + $args = '?t='.$this->timestamp; |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Skip relative paths... |
| 464 | 464 | if (strpos($ckeditorPath, '..') !== 0) {
|
| 465 | - $out .= $this->script("window.CKEDITOR_BASEPATH='". $ckeditorPath ."';");
|
|
| 465 | + $out .= $this->script("window.CKEDITOR_BASEPATH='".$ckeditorPath."';");
|
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - $out .= "<script type=\"text/javascript\" src=\"" . $ckeditorPath . 'ckeditor.js' . $args . "\"></script>\n"; |
|
| 468 | + $out .= "<script type=\"text/javascript\" src=\"".$ckeditorPath.'ckeditor.js'.$args."\"></script>\n"; |
|
| 469 | 469 | |
| 470 | 470 | $extraCode = ""; |
| 471 | 471 | if ($this->timestamp != $this->_timestamp) {
|
| 472 | - $extraCode .= ($extraCode ? "\n" : "") . "CKEDITOR.timestamp = '". $this->timestamp ."';"; |
|
| 472 | + $extraCode .= ($extraCode ? "\n" : "")."CKEDITOR.timestamp = '".$this->timestamp."';"; |
|
| 473 | 473 | } |
| 474 | 474 | if ($extraCode) {
|
| 475 | 475 | $out .= $this->script($extraCode); |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | /** |
| 503 | 503 | * realpath - Returns canonicalized absolute pathname |
| 504 | 504 | */ |
| 505 | - $realPath = realpath( './' ) ; |
|
| 505 | + $realPath = realpath('./');
|
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | return str_replace(',', '.', $val);
|
| 547 | 547 | } |
| 548 | 548 | if (is_array($val) || is_object($val)) {
|
| 549 | - if (is_array($val) && (array_keys($val) === range(0,count($val)-1))) {
|
|
| 550 | - return '[' . implode(',', array_map(array($this, 'jsEncode'), $val)) . ']';
|
|
| 549 | + if (is_array($val) && (array_keys($val) === range(0, count($val) - 1))) {
|
|
| 550 | + return '['.implode(',', array_map(array($this, 'jsEncode'), $val)).']';
|
|
| 551 | 551 | } |
| 552 | 552 | $temp = array(); |
| 553 | - foreach ($val as $k => $v){
|
|
| 554 | - $temp[] = $this->jsEncode("{$k}") . ':' . $this->jsEncode($v);
|
|
| 553 | + foreach ($val as $k => $v) {
|
|
| 554 | + $temp[] = $this->jsEncode("{$k}").':'.$this->jsEncode($v);
|
|
| 555 | 555 | } |
| 556 | - return '{' . implode(',', $temp) . '}';
|
|
| 556 | + return '{'.implode(',', $temp).'}';
|
|
| 557 | 557 | } |
| 558 | 558 | // String otherwise |
| 559 | 559 | if (strpos($val, '@@') === 0) |
@@ -561,6 +561,6 @@ discard block |
||
| 561 | 561 | if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') |
| 562 | 562 | return $val; |
| 563 | 563 | |
| 564 | - return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
|
|
| 564 | + return '"'.str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val).'"';
|
|
| 565 | 565 | } |
| 566 | 566 | } |
@@ -146,10 +146,11 @@ discard block |
||
| 146 | 146 | $_config = $this->configSettings($config, $events); |
| 147 | 147 | |
| 148 | 148 | $js = $this->returnGlobalEvents(); |
| 149 | - if (!empty($_config)) |
|
| 150 | - $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");";
|
|
| 151 | - else |
|
| 152 | - $js .= "CKEDITOR.replace('".$name."');";
|
|
| 149 | + if (!empty($_config)) { |
|
| 150 | + $js .= "CKEDITOR.replace('".$name."', ".$this->jsEncode($_config).");"; |
|
| 151 | + } else { |
|
| 152 | + $js .= "CKEDITOR.replace('".$name."');"; |
|
| 153 | + } |
|
| 153 | 154 | |
| 154 | 155 | $out .= $this->script($js); |
| 155 | 156 | |
@@ -186,8 +187,7 @@ discard block |
||
| 186 | 187 | $js = $this->returnGlobalEvents(); |
| 187 | 188 | if (!empty($_config)) {
|
| 188 | 189 | $js .= "CKEDITOR.replace('".$id."', ".$this->jsEncode($_config).");";
|
| 189 | - } |
|
| 190 | - else {
|
|
| 190 | + } else {
|
|
| 191 | 191 | $js .= "CKEDITOR.replace('".$id."');";
|
| 192 | 192 | } |
| 193 | 193 | $out .= $this->script($js); |
@@ -230,12 +230,10 @@ discard block |
||
| 230 | 230 | if (empty($_config)) {
|
| 231 | 231 | if (empty($className)) {
|
| 232 | 232 | $js .= "CKEDITOR.replaceAll();"; |
| 233 | - } |
|
| 234 | - else {
|
|
| 233 | + } else {
|
|
| 235 | 234 | $js .= "CKEDITOR.replaceAll('".$className."');";
|
| 236 | 235 | } |
| 237 | - } |
|
| 238 | - else {
|
|
| 236 | + } else {
|
|
| 239 | 237 | $classDetection = ""; |
| 240 | 238 | $js .= "CKEDITOR.replaceAll( function(textarea, config) {\n";
|
| 241 | 239 | if (!empty($className)) {
|
@@ -293,8 +291,7 @@ discard block |
||
| 293 | 291 | {
|
| 294 | 292 | if (!empty($event)) {
|
| 295 | 293 | $this->_events[$event] = array(); |
| 296 | - } |
|
| 297 | - else {
|
|
| 294 | + } else {
|
|
| 298 | 295 | $this->_events = array(); |
| 299 | 296 | } |
| 300 | 297 | } |
@@ -333,8 +330,7 @@ discard block |
||
| 333 | 330 | {
|
| 334 | 331 | if (!empty($event)) {
|
| 335 | 332 | $this->_globalEvents[$event] = array(); |
| 336 | - } |
|
| 337 | - else {
|
|
| 333 | + } else {
|
|
| 338 | 334 | $this->_globalEvents = array(); |
| 339 | 335 | } |
| 340 | 336 | } |
@@ -387,11 +383,9 @@ discard block |
||
| 387 | 383 | foreach($_events as $eventName => $handlers) {
|
| 388 | 384 | if (empty($handlers)) {
|
| 389 | 385 | continue; |
| 390 | - } |
|
| 391 | - else if (count($handlers) == 1) {
|
|
| 386 | + } else if (count($handlers) == 1) {
|
|
| 392 | 387 | $_config['on'][$eventName] = '@@'.$handlers[0]; |
| 393 | - } |
|
| 394 | - else {
|
|
| 388 | + } else {
|
|
| 395 | 389 | $_config['on'][$eventName] = '@@function (ev){';
|
| 396 | 390 | foreach ($handlers as $handler => $code) {
|
| 397 | 391 | $_config['on'][$eventName] .= '('.$code.')(ev);';
|
@@ -497,8 +491,7 @@ discard block |
||
| 497 | 491 | */ |
| 498 | 492 | if (isset($_SERVER['SCRIPT_FILENAME'])) {
|
| 499 | 493 | $realPath = dirname($_SERVER['SCRIPT_FILENAME']); |
| 500 | - } |
|
| 501 | - else {
|
|
| 494 | + } else {
|
|
| 502 | 495 | /** |
| 503 | 496 | * realpath - Returns canonicalized absolute pathname |
| 504 | 497 | */ |
@@ -556,10 +549,12 @@ discard block |
||
| 556 | 549 | return '{' . implode(',', $temp) . '}';
|
| 557 | 550 | } |
| 558 | 551 | // String otherwise |
| 559 | - if (strpos($val, '@@') === 0) |
|
| 560 | - return substr($val, 2); |
|
| 561 | - if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') |
|
| 562 | - return $val; |
|
| 552 | + if (strpos($val, '@@') === 0) { |
|
| 553 | + return substr($val, 2); |
|
| 554 | + } |
|
| 555 | + if (strtoupper(substr($val, 0, 9)) == 'CKEDITOR.') { |
|
| 556 | + return $val; |
|
| 557 | + } |
|
| 563 | 558 | |
| 564 | 559 | return '"' . str_replace(array("\\", "/", "\n", "\t", "\r", "\x08", "\x0c", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'), $val) . '"';
|
| 565 | 560 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | if (isset($_COOKIE['CI-CONCRETE5']) === FALSE) { |
| 68 | 68 | |
| 69 | 69 | $this->session->set_userdata('last_url', current_url()); |
| 70 | - redirect('/authentication/dashboard?url=' . current_url()); |
|
| 70 | + redirect('/authentication/dashboard?url='.current_url()); |
|
| 71 | 71 | } else { |
| 72 | 72 | |
| 73 | 73 | $cookie = $_COOKIE['CI-CONCRETE5']; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | //expire fake cookie |
| 80 | 80 | setcookie('CI-CONCRETE5', 'expired', time() - (1), "/"); |
| 81 | 81 | $this->session->set_userdata('last_url', current_url()); |
| 82 | - redirect('/authentication/dashboard?url=' . current_url()); |
|
| 82 | + redirect('/authentication/dashboard?url='.current_url()); |
|
| 83 | 83 | } else { |
| 84 | 84 | |
| 85 | 85 | $user_ldap = $this->user_model->user_ldap($username); |
@@ -208,8 +208,8 @@ |
||
| 208 | 208 | $wrapper_inline = explode("|", $CI->config->item('wrapper_inline')); |
| 209 | 209 | if ( ! $CI->config->item('use_wrapper')) |
| 210 | 210 | { |
| 211 | - $wrapper = array('', ''); |
|
| 212 | - $wrapper_inline = array('', ''); |
|
| 211 | + $wrapper = array('', ''); |
|
| 212 | + $wrapper_inline = array('', ''); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Begin writing breadcrumb string |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | 4 | * Breadcrumb helper |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | function array_replace(array &$array, array &$array1) |
| 61 | 61 | { |
| 62 | - foreach($array as $k=>$v) |
|
| 62 | + foreach ($array as $k=>$v) |
|
| 63 | 63 | { |
| 64 | - if(array_key_exists($k, $array1)) |
|
| 64 | + if (array_key_exists($k, $array1)) |
|
| 65 | 65 | { |
| 66 | 66 | $array[$k] = $array1[$k]; |
| 67 | 67 | } |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | -if ( ! function_exists('set_breadcrumb')) |
|
| 73 | +if (!function_exists('set_breadcrumb')) |
|
| 74 | 74 | { |
| 75 | - function set_breadcrumb($delimiter_config = '', $exclude = '', $config= array()) |
|
| 75 | + function set_breadcrumb($delimiter_config = '', $exclude = '', $config = array()) |
|
| 76 | 76 | { |
| 77 | - $CI =& get_instance(); |
|
| 77 | + $CI = & get_instance(); |
|
| 78 | 78 | $CI->load->helper('url'); |
| 79 | 79 | $CI->lang->load('breadcrumb'); |
| 80 | 80 | $CI->config->load('breadcrumb'); |
@@ -87,43 +87,43 @@ discard block |
||
| 87 | 87 | * for guidance. |
| 88 | 88 | * @author Chris Miller |
| 89 | 89 | */ |
| 90 | - $attr_home = ( isset( $config['attr_home'] ) |
|
| 90 | + $attr_home = (isset($config['attr_home']) |
|
| 91 | 91 | ? $config['attr_home'] |
| 92 | - : $CI->config->item('attr_home') ); |
|
| 92 | + : $CI->config->item('attr_home')); |
|
| 93 | 93 | |
| 94 | - $unlink_home = ( isset( $config['unlike_home'] ) |
|
| 94 | + $unlink_home = (isset($config['unlike_home']) |
|
| 95 | 95 | ? $config['unlike_home'] |
| 96 | - : $CI->config->item('unlike_home') ); |
|
| 96 | + : $CI->config->item('unlike_home')); |
|
| 97 | 97 | |
| 98 | 98 | if (empty($exclude)) |
| 99 | 99 | { |
| 100 | 100 | $exclude = $CI->config->item('exclude'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $exclude_segment = ( isset( $config['exclude_segment'] ) |
|
| 104 | - ? array_merge($CI->config->item('exclude_segment'),$config['exclude_segment']) |
|
| 105 | - : $CI->config->item('exclude_segment') ); |
|
| 103 | + $exclude_segment = (isset($config['exclude_segment']) |
|
| 104 | + ? array_merge($CI->config->item('exclude_segment'), $config['exclude_segment']) |
|
| 105 | + : $CI->config->item('exclude_segment')); |
|
| 106 | 106 | |
| 107 | - $replacer_default = ( isset( $config['replacer'] ) |
|
| 108 | - ? array_merge($CI->config->item('replacer'),$config['replacer']) |
|
| 109 | - : $CI->config->item('replacer') ); |
|
| 107 | + $replacer_default = (isset($config['replacer']) |
|
| 108 | + ? array_merge($CI->config->item('replacer'), $config['replacer']) |
|
| 109 | + : $CI->config->item('replacer')); |
|
| 110 | 110 | |
| 111 | - $replacer_embed = ( isset( $config['replacer_embed'] ) |
|
| 112 | - ? array_merge($CI->config->item('replacer_embed'),$config['replacer_embed']) |
|
| 113 | - : $CI->config->item('replacer_embed') ); |
|
| 111 | + $replacer_embed = (isset($config['replacer_embed']) |
|
| 112 | + ? array_merge($CI->config->item('replacer_embed'), $config['replacer_embed']) |
|
| 113 | + : $CI->config->item('replacer_embed')); |
|
| 114 | 114 | |
| 115 | - $partial_replace = ( isset( $config['partial_replace'] ) |
|
| 116 | - ? array_merge($CI->config->item('partial_replace'),$config['partial_replace']) |
|
| 117 | - : $CI->config->item('partial_replace') ); |
|
| 115 | + $partial_replace = (isset($config['partial_replace']) |
|
| 116 | + ? array_merge($CI->config->item('partial_replace'), $config['partial_replace']) |
|
| 117 | + : $CI->config->item('partial_replace')); |
|
| 118 | 118 | |
| 119 | 119 | /* --- End Patch --- */ |
| 120 | 120 | |
| 121 | - $uri = rtrim($CI->uri->uri_string(),'/'); |
|
| 121 | + $uri = rtrim($CI->uri->uri_string(), '/'); |
|
| 122 | 122 | $uri_array_original = explode("/", $uri); |
| 123 | 123 | |
| 124 | 124 | // cahva's fix (http://codeigniter.com/forums/viewreply/855097/) |
| 125 | 125 | $uri_array_cnt = count($uri_array_original); |
| 126 | - if (config_item('hide_number_on_last_segment') && isset($uri_array_original[$uri_array_cnt-1]) && is_numeric($uri_array_original[$uri_array_cnt-1])) |
|
| 126 | + if (config_item('hide_number_on_last_segment') && isset($uri_array_original[$uri_array_cnt - 1]) && is_numeric($uri_array_original[$uri_array_cnt - 1])) |
|
| 127 | 127 | { |
| 128 | 128 | array_pop($uri_array_original); |
| 129 | 129 | } |
@@ -132,22 +132,22 @@ discard block |
||
| 132 | 132 | // If last segment is a number ? |
| 133 | 133 | $show_last_number = -1; |
| 134 | 134 | $number_array = count($uri_array_original); |
| 135 | - if (! $CI->config->item('hide_number_on_last_segment')) |
|
| 135 | + if (!$CI->config->item('hide_number_on_last_segment')) |
|
| 136 | 136 | { |
| 137 | 137 | $l_array = $number_array - 1; // last array number |
| 138 | - if (preg_match("/^[0-9]/", $uri_array_original[$l_array]) AND ! preg_match("/[a-zA-Z]+/", $uri_array_original[$l_array])) |
|
| 138 | + if (preg_match("/^[0-9]/", $uri_array_original[$l_array]) AND !preg_match("/[a-zA-Z]+/", $uri_array_original[$l_array])) |
|
| 139 | 139 | { |
| 140 | 140 | $show_last_number = $l_array; |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Find segments uri that only contain a number |
| 145 | - foreach($uri_array_original as $key => $value) |
|
| 145 | + foreach ($uri_array_original as $key => $value) |
|
| 146 | 146 | { |
| 147 | 147 | // find number but keep number where positioned in the last segment |
| 148 | - if (preg_match("/^[0-9]/", $value) AND ! preg_match("/[a-zA-Z]+/", $value) AND $key != $show_last_number) |
|
| 148 | + if (preg_match("/^[0-9]/", $value) AND !preg_match("/[a-zA-Z]+/", $value) AND $key != $show_last_number) |
|
| 149 | 149 | { |
| 150 | - $uri_array_original[$key] = (int)$value; |
|
| 150 | + $uri_array_original[$key] = (int) $value; |
|
| 151 | 151 | |
| 152 | 152 | // If hide_number is TRUE then set the $exclude_segment array variable; |
| 153 | 153 | if ($CI->config->item('hide_number')) |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | $key_uri = array_search($key, $uri_array_original, TRUE); |
| 191 | 191 | |
| 192 | 192 | // Add multilanguage |
| 193 | - if (! is_array($value) && $CI->config->item('multilang')) |
|
| 193 | + if (!is_array($value) && $CI->config->item('multilang')) |
|
| 194 | 194 | { |
| 195 | 195 | if ($CI->lang->line($value)) { |
| 196 | 196 | $value = ucwords($CI->lang->line($value)); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | // Set wrapper |
| 207 | 207 | $wrapper = explode("|", $CI->config->item('wrapper')); |
| 208 | 208 | $wrapper_inline = explode("|", $CI->config->item('wrapper_inline')); |
| 209 | - if ( ! $CI->config->item('use_wrapper')) |
|
| 209 | + if (!$CI->config->item('use_wrapper')) |
|
| 210 | 210 | { |
| 211 | 211 | $wrapper = array('', ''); |
| 212 | 212 | $wrapper_inline = array('', ''); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $segment .= $uri_array_original[$i].'/'; |
| 242 | 242 | |
| 243 | 243 | // If replace value is an array |
| 244 | - if (! in_array($i, $skip_key, TRUE) && is_array($value)) // Skip link if replace value is null |
|
| 244 | + if (!in_array($i, $skip_key, TRUE) && is_array($value)) // Skip link if replace value is null |
|
| 245 | 245 | { |
| 246 | 246 | $number_added_value_array = count($value); |
| 247 | 247 | |
@@ -268,13 +268,13 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Look up for partial replace |
| 271 | - if (! empty($partial_replace)) |
|
| 271 | + if (!empty($partial_replace)) |
|
| 272 | 272 | { |
| 273 | 273 | foreach ($partial_replace as $pkey => $pvalue) |
| 274 | 274 | { |
| 275 | 275 | if ($CI->config->item('multilang')) |
| 276 | 276 | { |
| 277 | - $lang_pvalue = $CI->lang->line($pvalue)?$CI->lang->line($pvalue):$CI->lang->line($pkey); |
|
| 277 | + $lang_pvalue = $CI->lang->line($pvalue) ? $CI->lang->line($pvalue) : $CI->lang->line($pkey); |
|
| 278 | 278 | $preplace = ' '.$lang_pvalue.'_'; |
| 279 | 279 | |
| 280 | 280 | } else { |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | $str_name[] = ucwords($val_name); |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | - else if (! in_array($i, $skip_key, TRUE)) // If value is NOT an array |
|
| 309 | + else if (!in_array($i, $skip_key, TRUE)) // If value is NOT an array |
|
| 310 | 310 | { |
| 311 | 311 | // Add multilanguage |
| 312 | 312 | if ($CI->config->item('multilang')) |
@@ -317,13 +317,13 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Look up for partial replace |
| 320 | - if (! empty($partial_replace)) |
|
| 320 | + if (!empty($partial_replace)) |
|
| 321 | 321 | { |
| 322 | 322 | foreach ($partial_replace as $pkey => $pvalue) |
| 323 | 323 | { |
| 324 | 324 | if ($CI->config->item('multilang')) |
| 325 | 325 | { |
| 326 | - $lang_pvalue = $CI->lang->line($pvalue)?$CI->lang->line($pvalue):$CI->lang->line($pkey); |
|
| 326 | + $lang_pvalue = $CI->lang->line($pvalue) ? $CI->lang->line($pvalue) : $CI->lang->line($pkey); |
|
| 327 | 327 | $preplace = ' '.$lang_pvalue.'_'; |
| 328 | 328 | |
| 329 | 329 | } else { |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | $value = ucwords(strtolower(str_replace($char_to_replace, " ", $value))); |
| 344 | 344 | if ($CI->config->item('strip_regexp')) |
| 345 | 345 | { |
| 346 | - foreach($CI->config->item('strip_regexp') as $exp) |
|
| 346 | + foreach ($CI->config->item('strip_regexp') as $exp) |
|
| 347 | 347 | { |
| 348 | 348 | $value = preg_replace($exp, '', $value); |
| 349 | 349 | } |
@@ -359,13 +359,13 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | /* --- Chris Miller's Patch --- */ |
| 361 | 361 | // Check for custom additions |
| 362 | - if ( isset( $config['include_segments'] ) ) { |
|
| 362 | + if (isset($config['include_segments'])) { |
|
| 363 | 363 | |
| 364 | 364 | // Set our variable for usage |
| 365 | 365 | $include_segments = $config['include_segments']; |
| 366 | 366 | |
| 367 | 367 | // Loop our config array |
| 368 | - foreach ( $include_segments AS $k => $v ) { |
|
| 368 | + foreach ($include_segments AS $k => $v) { |
|
| 369 | 369 | $str_link[] = $k; |
| 370 | 370 | $str_name[] = ucwords($v); |
| 371 | 371 | } |
@@ -384,7 +384,7 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | foreach ($str_name as $key => $val) { |
| 386 | 386 | // If home is hidden then don't show first delimiter |
| 387 | - if ( $i == 0 && ($str == '' || $str == $wrapper[0]) ) { |
|
| 387 | + if ($i == 0 && ($str == '' || $str == $wrapper[0])) { |
|
| 388 | 388 | $delimiter = ''; |
| 389 | 389 | } elseif (empty($delimiter_config)) { |
| 390 | 390 | $delimiter = $CI->config->item('delimiter'); |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | if ($val != '') { |
| 396 | - if ($key == $breadcrumb_number-1 && $CI->config->item('unlink_last_segment')) |
|
| 396 | + if ($key == $breadcrumb_number - 1 && $CI->config->item('unlink_last_segment')) |
|
| 397 | 397 | { |
| 398 | 398 | $str .= $delimiter.$wrapper_inline[0].ucwords($val).$wrapper_inline[1]; |
| 399 | 399 | } else { |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | } |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | -if ( ! function_exists('clear_breadcrumb')) |
|
| 415 | +if (!function_exists('clear_breadcrumb')) |
|
| 416 | 416 | { |
| 417 | 417 | function clear_breadcrumb() |
| 418 | 418 | { |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('BASEPATH')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /** |
| 4 | 6 | * Breadcrumb helper |
@@ -241,9 +243,11 @@ discard block |
||
| 241 | 243 | $segment .= $uri_array_original[$i].'/'; |
| 242 | 244 | |
| 243 | 245 | // If replace value is an array |
| 244 | - if (! in_array($i, $skip_key, TRUE) && is_array($value)) // Skip link if replace value is null |
|
| 246 | + if (! in_array($i, $skip_key, TRUE) && is_array($value)) { |
|
| 247 | + // Skip link if replace value is null |
|
| 245 | 248 | { |
| 246 | 249 | $number_added_value_array = count($value); |
| 250 | + } |
|
| 247 | 251 | |
| 248 | 252 | foreach ($value as $pair_values) |
| 249 | 253 | { |
@@ -253,8 +257,7 @@ discard block |
||
| 253 | 257 | if ($number_pv_array == 1) |
| 254 | 258 | { |
| 255 | 259 | $val_name = $pv_array[0]; |
| 256 | - } |
|
| 257 | - else |
|
| 260 | + } else |
|
| 258 | 261 | { |
| 259 | 262 | $val_name = $pv_array[1]; |
| 260 | 263 | } |
@@ -292,12 +295,10 @@ discard block |
||
| 292 | 295 | if ($number_pv_array == 1 || $val_url == $uri_array_original[$i]) |
| 293 | 296 | { |
| 294 | 297 | $new_segment_url = $segment; |
| 295 | - } |
|
| 296 | - else if ($val_url[0] == '/') |
|
| 298 | + } else if ($val_url[0] == '/') |
|
| 297 | 299 | { |
| 298 | 300 | $new_segment_url = base_url().substr($val_url, 1); |
| 299 | - } |
|
| 300 | - else |
|
| 301 | + } else |
|
| 301 | 302 | { |
| 302 | 303 | $new_segment_url = $segment.$val_url; |
| 303 | 304 | } |
@@ -305,14 +306,15 @@ discard block |
||
| 305 | 306 | $str_link[] = $new_segment_url; |
| 306 | 307 | $str_name[] = ucwords($val_name); |
| 307 | 308 | } |
| 308 | - } |
|
| 309 | - else if (! in_array($i, $skip_key, TRUE)) // If value is NOT an array |
|
| 309 | + } else if (! in_array($i, $skip_key, TRUE)) { |
|
| 310 | + // If value is NOT an array |
|
| 310 | 311 | { |
| 311 | 312 | // Add multilanguage |
| 312 | 313 | if ($CI->config->item('multilang')) |
| 313 | 314 | { |
| 314 | 315 | if ($CI->lang->line($value)) { |
| 315 | 316 | $value = ucwords($CI->lang->line($value)); |
| 317 | + } |
|
| 316 | 318 | } |
| 317 | 319 | } |
| 318 | 320 | |