Jump to content


ezgoen

Member Since 21 Mar 2013
Offline Last Active May 20 2013 08:17 AM
-----

#7179 Active / Inactive bit field on add

Posted ezgoen on 05 May 2013 - 11:49 PM

I have posted this in github now - and since 

have discovered that defaults are not set for successive adds for any fields.

Perhaps this is why the default value feature is only partially implemented??

 

I must admit I didnt check the multi add functionality either when I built my own default value feature.

 

I think the way to go is to pass a javascript array of default values and have the fields set to these on add.

The problem here is it could get nasty, how far is it worth going for default values?

One might want to have the default value increment - would need to tell js thats what we want.

OR we might want next index id from the database - we would have to return that inside the ajax/json 

form post. But there's no reliable way to get next insert id - should be ok because we should be using auto increment feature of the database and therefor NOT need a default value.

 

Still bears some thinking as to the best way forward

 

 

Cheers

 

 

Ez




#6925 Superfish Menu CI plugin

Posted ezgoen on 19 April 2013 - 02:57 AM

Hi Folks:

 

Here is a New Version 1.1 - includes breadcrumbs!

Also includes code cleanup, some things done a little better.

Better comments and documentation.

 

Here's a link to the file Attached File  phpSuperFish_v1.1.zip   23.74K   349 downloads

 

-------------------------------------------------------------------------------

 

   PHP superfish 
 
   A Codeigniter library that creates a superfish menu automatically with just few lines of code.
 
   Copyright © 2013  E.z 
 
   LICENSE
 
   Superfish is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt).
   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.
   Please see the corresponding license file for details of these licenses.
   You are free to use, modify and distribute this software, but all copyright information must remain.
 
   @package        PHP Superfish
   @copyright      Copyright © 2013, E.z
   @license        As Above
   @version        1.1 ****** New version
   @author         E.z <ezgoen@gmail.com>
 
    Credits to 
                 - the creator of the jquery plugin SuperFish
 
                     http://users.tpg.com...gins/superfish/
                     http://archive.plugi...oject/Superfish
                     https://github.com/j...irch/superfish/
               
                 
                 Patrick Fitzgerald - the creater of csscolor.php
 
                     http://www.barelyfit...jects/csscolor/
     
     Installation:
    
        This Package : 
            
            If you're using CI extract it into your CI tree 
            Maybe your root or www - if you're using CI its the parent of the application folder
            assuming www - it should look like this :
            
            /www/
                sf_install.txt (this file)
                sf_readme.txt
            
            /www/application/libraries/
                superfish.php
                index.html
 
            /www/application/config/
                superfish.php
                index.html
                
            /www/assets/
                index.html
                
            /www/assets/superfish/
                index.html
 
            /www/assets/superfish/css
                superfish-crumb.css
                index.html
                
            /www/assets/superfish/images
                index.html
            
            /www/assets/superfish/js
                index.html
 
            /www/assets/superfish/js
                superfish_css.php
                csscolor.php
                index.html
        
    
        
    Superfish jQuery plugin :
  
        Download the latest version if the jquery plugin SuperFish from git
    
        
        extract it to assets/superfish
        when your done you should have 
        assets/superfish/
            changelog.txt
            example.html
            followed.html
            MIT-LICENSE.txt
            README.md
            superfish.jquery.json
            
        assets/superfish/css/
            superfish.css
            superfish-navbar.css
            superfish-vertical.css
            superfish-crumb.css       <-- our file - edit this to change the crumb style
            
        assets/superfish/images/
            arrows-ffffff.png
            
        assets/superfish/js/
            hoverIntent.js
            jquery-1.9.0.min.js 
            superfish.js
            supersubs.js
  
    
      csscolors.php colors library:
   
        You can download the latest version and remove the pear dependancies yourself
        or you can use the included version which has all pear dependancies removed
        
        to install it by creating assets/superfish/theme/
        and placing csscolor.php into there along with superfish_css.php
        so when your done you'll have:
                
        assets/superfish/theme/
            csscolor.php
            superfish_css.php            <-- our file - this controls the color scheme/theme of the menu
    
        to reduce processing superfish_css.php will cache copies if its css 
        and output that rather than computing a new theme.
     
 
    
    Usage :
    
    To load the library in CI 
    
        $this->load->library('superfish',
                            array('container_tag_id'=>'admin_menu', 
                                  'container_tag_id'=>'nav',
                                  'container_tag_class'=>'sf-menu',
                                  'pathLevels'=>0,       
                                  'home_url'=>'/admin',
                                  'base_ref'=>site_url(),
                                  'background_color'=>'FFD833',
                                  'highlight_color'=>'FAC101',
                                  'text_color'=>'670001',
                                  'SESSION'=>$this->session));    
                                
                                
    To build a menu
    
       

 

 /make a shortcut to superfish 
        $SuperFish=$this->superfish;  
        
        //if you're using CI you get your active url like this (remember to $this->load->helper('url')
        $active_item=$this->uri->uri_string();
        
        $SuperFish->set_menu_item('home','Home',$active_item);
        $SuperFish->set_menu_item('admin/usr_accounts','Administrative Tasks/Manage User Accounts',$active_item);
        $SuperFish->set_menu_item('admin/site_man','Administrative Tasks/Perform Site Management Tasks',$active_item);

 

 

    To get the rendered menu:
    
  

 

      $menu=$SuperFish->render();
 

 

        
    To get the menu rendered to your grocerycrud output:
    

 

      $output=$SuperFish->renderToCrud($output);
 

 

    
                                
    In your template put the following where you want the menu to appear                 
           

 

                 <div class="nav">
                     <?php print $menu; ?>
                     <div class="clear"> </div>
                 </div>
 

 

                
                
     The output will be :
                                 
 

 

              <div class="nav">
                     <!-- Start SuperFish Menu  //-->
                         <ul id="nav" class="sf-menu">
                             <li><a href="http://testing/index.php/home" title="Home">Home</a></li>
                             <li>
                                 <a href="#" title="Administrative Tasks" >Administrative Tasks</a>
                                 <ul>
                                     <li><a href="http://testing/index.php/admin/usr_accounts" title="Manage User Accounts">Manage User Accounts</a></li>
                                     <li><a href="http://testing/index.php/admin/site_man" title="Site Management">Site Management</a></li>
                                 </ul>
                             </li>
                         </ul>
                     <!-- End SuperFish Menu  //-->
                     <div class="clear"> </div>
                 </div>
 

 

    
     To render the breadcrumb trail just do this in your template
     a basic stylesheet is in /assets/superfish/css/superfish-crumb.css
    
     Note the breadcrumb trail is experimental - it works for me but I havent 
     texted it extensively and the code is pretty messy :(
    

 

                 <div class="crumb">
                      <?php print $bread_trail; ?>
                     <div class="clear"> </div>
                 </div>
 

 

    

                                     

 

Cheers

 

Ez




#6894 datebase column Comments as hints

Posted ezgoen on 18 April 2013 - 03:36 AM

This one was real easy folks - so I'll pass it on

 

Maybe someone will attach some JS or jQuery so they pop up or something??

 

anyhow this is how I did it, it was sooooo easy.

 

 

Create a custom GC MODEL

 

copy the code for

 

       get_field_types_basic_table()

 

code from grocery_crud_model into it 

 

then make the following changes

 

function get_field_types_basic_table()
    {
    	$db_field_types = array();
        //change this..
    	//foreach($this->db->query("SHOW COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type)
        //to this
        foreach($this->db->query("SHOW FULL COLUMNS FROM `{$this->table_name}`")->result() as $db_field_type)
and 
 
$db_field_types[$db_field_type->Field]['db_max_length'] = $length;
$db_field_types[$db_field_type->Field]['db_type'] = $db_type;
$db_field_types[$db_field_type->Field]['db_null'] = $db_field_type->Null == 'YES' ? true : false;
$db_field_types[$db_field_type->Field]['db_extra'] = $db_field_type->Extra;
 

 

add the following line
 

 

$db_field_types[$db_field_type->Field]['db_comment'] = $db_field_type->Comment;
 

 

 

Thats it - now just change your theme files edit.php and add.php

 

here's my change to /assets/grocerycrud/flexigrid/views/edit.php

 

 

            <div class='form-field-box <?php echo $even_odd?>' id="<?php echo $field->field_name; ?>_field_box">
                <div class='form-display-as-box' id="<?php echo $field->field_name; ?>_display_as_box">
                    <?php echo $input_fields[$field->field_name]->display_as?><?php echo ($input_fields[$field->field_name]->required)? "<span class='required'>*</span> " : ""?> :
                </div>
                <div class='form-input-box' id="<?php echo $field->field_name; ?>_input_box">
                    <?php echo $input_fields[$field->field_name]->input?>
<?php // **********My Changes**************************************************************************** ?>
                    <div class='form_hint_box' id="<?php echo $field->field_name; ?>_hint_box">
                        <?php echo $input_fields[$field->field_name]->db_comment?>
                    </div>
<?php // ************************************************************************************** ?>


                </div>
                <div class='clear'></div>    
            </div>

 

I also added the following to flexigrid.css

 

 

.form_hint_box
{
    padding: 5px 5px;
    margin: 0px 0px 0px 0px;    
    font-size:7px;
}
 

 

Thats it - no go back and put nice comments into your mysql column definitions 

and you'll have them show up on the add & edit forms.

I'm sure the idea could be easily incorperated into core gc at which time I'm sure someone will come up with a language file mechanism for it too .

 

Cheers

 

 

Enjoy

 

PS - sometimes code tags here in the forum throw some of the code outside them - dunno why??




#6892 Superfish Menu CI plugin

Posted ezgoen on 18 April 2013 - 12:50 AM

Thanks for that :)

 

I need to get my current effort finished and its only single login for the owner so I'm all good for now.

 

But a quick scan of the docs for ion http://benedmunds.com/ion_auth/

shows its pretty decent and supports a varied configuration. I will definitely take a more detailed

look at some time in the future

 

I still like my idea that grocerycrud provide the login screen in-keeping with whatever gc theme is curently set

and let the users/developers roll their own mechanism. (or use someone elses)

 

Cheers,

 

Ez




#6841 Superfish Menu CI plugin

Posted ezgoen on 15 April 2013 - 06:42 AM

 

Hi Folks,

 

There is a new version - now with a breadcrumb trail!

 

I've create a new post and attached the new file.

Full documentation is inside the archive! 

 

Please note, I've UPDATED the code and commented on it here.

 


While not strictly grocerycrud  I'm sharing here in an effort to give back a little.


 


I needed a simple menu system and I've used the Superfish jquery library before.


I did merge it into the fuelcms menu but I wasnt happy with it.


 


This is simpler to use and really easy to get a good looking menu out of a few lines of code.

 

here's all you have to do to use the library (after you've installed as per the included instructions)

 


 

$this->load->library('superfish',
                            array('container_tag_id'=>'admin_menu', 
                                  'container_tag_id'=>'nav',
                                  'container_tag_class'=>'sf-menu',
                                  'background_color'=>'FFD833',
                                  'highlight_color'=>'FAC101',
                                  'text_color'=>'670001'));    

//make a shortcut to superfish 
$SuperFish=$this->superfish;  //the same name as the load->library statement

$SuperFish->set_menu_item('home','Home',$active_item);
$SuperFish->set_menu_item('admin/usr_accounts','Administrative Tasks/Manage User Accounts',$active_item);
$SuperFish->set_menu_item('admin/site_man','Administrative Tasks/Perform Site Management Tasks',$active_item);

$menu=$SuperFish->render();


 

 


Note the change in my example - I made a small mistake  that Elgger picked up.  Thanks Elgger



 


the following is only necessary if you want to merge css and js with grocery crud


 

 


        //merge our includes 

        $arr=$menu->includes->css_files;

        foreach ($arr as $key => $value){

            $css_files[$key]=$value;

        }

        $arr=$menu->includes->js_files;

        foreach ($arr as $key => $value){

            $js_files[$key]=$value;

        }





        $output->inline.=$menu->includes->inline;

        $output->js_files=$js_files;

        $output->css_files=$css_files;

        

        $output->menu=$menu->output;
 

 

 



I've updated the code. (The attached file has been modified to include the change)


 


To do a vanilla render :


 

 

$menu=$this->superfish->render(); //or if you made a shortcut like above
//$menu=SuperFish->render();
 

 

 

 


To render AND merge with crud output


 


 

$output=$this->menu->renderToCrud($output);//or if you made a shortcut like above
//$output=$SuperFish->renderToCrud($output)
 

 



 


and in your template , if you've done the above merge :


 


 

<?php print $menu; ?>
 
 

 

 


Feedback is welcome but so is maintenance - if its broke feel free to fix it


if you need help just ask


 


Hope its useful to someone


 


Cheers


 


Ez

Attached Files




#6805 Default field values (for add form)

Posted ezgoen on 11 April 2013 - 12:48 AM

 

I've seen image crud.

 

I didn't need the extra complexity and I really don't like lookup tables in databases ( relation_n_n  )

 

Cheers and I will post a file next time

 

Ez




#6686 Default field values (for add form)

Posted ezgoen on 05 April 2013 - 04:46 AM

 

Hi again

 

I've made another enhancement to my subclass.

 

The facility to have dynamic where clauses.

 

here's an explanation :

 

Say I cave a catalogue item (table 1) that has images (table 2)

 

I want all my images - site wide - to be in my image table (table 2)

 

I may have other tables (collections) that have images

 

so clearly I need to have "image id" and "foreign_id" in my image table.

 

"Image id" identifies a unique image and "foreign_id" identifies a set of images.

 

I also have "collection_name" in my images table (table 2) so that I dont get any id collisions.

 

and I have an image title in the image table.

 

I also want to have an image id of my default image in the catalogue table

 

In this case my "foreign_id" would be the "catalogue_id" of my catalogue item.

and "collection_name" would be 'catalogue"

 

You still with me ??

 

so when I edit a catalogue item I want also to access a relationship 

show me all of the images in (table 2) where "collection_name" == 'catalogue' and "foreign_id" == "catalogue_id"

 

getting clearer??

 

we've all had to do this - in grocerycrud - using callbacks

 

because we cant set the "where part" in set_relation() to a value from the table in a controller

unless we do it in a callback - (which is fine - but this is easier)

 

so - to summarize:

 

when I edit a catalogue item - I want to be able to add images to it

I want to be able to set a default image

 

so what if for the above example we could do this :

 

for example:

   $crud->set_relation('Catalogue_Default_Image_id','Images','Images_Title',array('Images_Foreign_ID'=>'{Catalogue_ID}'));

 

The actual set_relation reads like this:

 

   $crud->set_relation('IMG_ID','Images','Title',array('F_ID'=>'{ID}'));

 

just like in the docs http://www.grocerycr...ns/set_relation

 

You can have as many fields you like to call from the other table and
the syntax is really simple. Just at the 3rd field you will have the
symbol { and } . So it will be for example:


 
$crud->set_relation('user_id','users','{username} - {last_name} {first_name}');
 

 

you can have the system replace values that are surrounded by curly braces "{}" in the where clause.

but ONLY in the value field - it doesnt make sense to change the key field at all.

 

 

so  example    $crud->set_relation('IMG_ID','Images','Title',array('F_ID'=>'{ID}','Image_Type'=>"Catalogue"));

 

and a row in the catalogue like this

 

ID=>2, IMG_ID->11, Text->'something about a catalogue item'

 

at run time the resulting where part would end up 

 

array('F_ID'=>'2','Image_Type'=>"Catalogue") 

 

Hope my explanation make sense to everyone

 

so here's my updated subclass

note -

I make the mods in a subclass so that I NEVER have to change the underlying library.

Also, I have to do some more reading to find out if I can do all this in a model which would take the hassle out of subclassing

 

I've also made some minor changes to the set_css and set_js functionality so that I can use them in my controller and other 

libraries.

 

anyway here you go - enjoy

 

its kinda big - hope thats ok  - maybe next time I'll just post a file

<?php
/**
 * PHP grocery CRUD
 *
 * A Codeigniter library that creates a CRUD automatically with just few lines of code.
 *
 * Copyright © 2010 - 2012  John Skoumbourdis. 
 *
 * LICENSE
 *
 * Grocery CRUD is released with dual licensing, using the GPL v3 (license-gpl3.txt) and the MIT license (license-mit.txt).
 * 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.
 * Please see the corresponding license file for details of these licenses.
 * You are free to use, modify and distribute this software, but all copyright information must remain.
 *
 * @package    	grocery CRUD
 * @copyright  	Copyright (c) 2010 through 2012, John Skoumbourdis
 * @license    	https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt
 * @version    	1.3
 * @author     	John Skoumbourdis <scoumbourdisj@gmail.com>
 */

// ------------------------------------------------------------------------
include_once(dirname(__FILE__)."/grocery_crud.php");


/**
 * PHP grocery CRUD - Customized
 *
 * Creates a full functional CRUD with few lines of code.
 *
 * @package    	grocery CRUD 
 * @author     	John Skoumbourdis <scoumbourdisj@gmail.com>
 * @license     https://github.com/scoumbourdis/grocery-crud/blob/master/license-grocery-crud.txt
 * @link		http://www.grocerycrud.com/documentation
 *
 * @hacker      Ez (ezgoen@gmail.com) - email me for my real identity
 */

class custom_grocery_crud extends grocery_CRUD{

	protected $field_default_values = array();
	protected $inline='';
	
	function __construct()
	{
		parent::__construct();
		
		//I need these BEFORE render - so we can add include files
		$this->_initialize_variables();
	}
	
	
	/**
	 * override get_layout
	 *
	 * Created by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				I've added functionality to add inline code - like 
	 *				<style type=\"text/css\" > Blah </style>
	 *				<script type=\"text/javascript\"> Blah </script>";
	 *				and so on
	 *
	 *				The gc only has this at the time of the call to render
	 *				so we have to handle it separately
	 *				This is the last function called by render()
	 *					 
	 */
	protected function get_layout()	{		
		//call the parent method
		$result = parent::get_layout();
		//add our stuff
		$result->inline=$this->inline;
		return $result;
	}
	
	/**	 * Helper Function
	 *
	 * Created by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 */
	protected function get_field_default_values($field){
		return array_key_exists($field,$this->field_default_values) ? $this->field_default_values[$field] : null;
	}

	/**
	 * Use this function exactly the same way you would use field_type()
	 * see : http://www.grocerycrud.com/documentation/options_functions/field_type
	 *
	 * Created by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				in the case of an ADD data form I want to provide default values to the fields.
	 *				I may also want to make the fields with default values readonly or completely hidden
	 *				The parent object does not allow/facilitate addidtion of default values to visible 
	 *				fields other than:
	 *					hidden
	 *					invisible
	 *					password
	 *					enum
	 *					set
	 *					dropdown
	 *					multiselect
	 *
	 *				I havent fooled around with invisible - so I cant comment on anything to do with that.
	 *				however I want my other fields - most commonly string and integer to have default values
	 *				additionally I may also want thos values to either editable OR readonly and visible at 
	 *				the same time AND I want my default values (if they are readonly) to go into the database
	 *				
	 */
	public function field_set_defaults($field,$type,$value){
		  $this->field_default_values[$field]=array('type'=>$type,'value'=>$value);
	}

	
	//for backward compatibility
	public function set_css($css_file)	{
		$this->add_include($css_file);
	}

	//for backward compatibility
	public function set_js($js_file){
		$this->add_include($js_file);
	}
	/**
	 * Use this function exactly the same way you would use set_js() or set_css
	 *
	 * Created by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				I wanted my controller to be able to do this too
	 *				I also use a menu library that I kinda adapted 
	 *				it uses some jquery as well - so its better everything uses the same function
	 *				to add js and script files so we dont :
	 *					end up with duplicates includes
	 *					degrade page load times
	 *				
	 *				This function also allows us to add files that are outside the grocerycrud 
	 *				dircetory tree
	 */
	public function add_include($inc_file){
		$fn = (strpos($inc_file,"/") === 0 ) ?  substr($inc_file, 1)  : $inc_file;
		if (strripos($fn,'.js',-3) !== False)  {  
			if (! file_exists("$fn")){
				$fn = $this->default_javascript_path."/$fn" ;
			}
			if(file_exists("$fn")){
				$this->js_files[sha1($fn)] = base_url().$fn;
			} else {
				throw new Exception("Missing JavaScript (.js) file. Tried : $inc_file and $fn");
			}
		} elseif (strripos($inc_file,'.css',-4) !== False) { 
			if (! file_exists("$fn")){
				$fn = $this->default_css_path."/$fn" ;
			}
			if(file_exists("$fn")){
				$this->css_files[sha1($fn)] = base_url().$fn;
			} else {
				throw new Exception("Missing Stylesheet (.css) file. Tried: $inc_file and $fn");
			}
		} else {
			throw new Exception("Request to include unknown file type: $inc_file");
		}
	}

	
	public function add_inline($str){
		$this->inline.="\n$str";
	}
	
	
	/**
	 * Work out what to do with input fields for add record
	 * 
	 *
	 * Modified/Hacked by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				in the case of an ADD data form I want to provide default values to the fields.
	 *				I may also want to make the fields with default values readonly or completely hidden
	 */
	protected function get_add_input_fields($field_values = null)
	{
		$fields = $this->get_add_fields();
		$types 	= $this->get_field_types();
		
		$input_fields = array();
		
		foreach($fields as $field_num => $field)
		{	
			$field_info = $types[$field->field_name];
			
			$field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null;
	

			$field_default_values=$this->get_field_default_values($field->field_name);
			if (! empty($field_default_values) and empty($field_value) ){
				//if $field_info is not set at this point we need to construct one
				if (!isset($field_info)){
						$field_info = (object)array();
				}
				$field_info->custom_default=True; //this is what we look for to ensure we only change the behaviour we want to
				$field_info->crud_type=$field_default_values['type'];
				$field_info->type=$field_default_values['type'];
				$field_info->default=$field_default_values['value'];
				$field_info->extras=$field_default_values['value'];
				$field_value=$field_default_values['value'];
			}
			
			//no changes below here
			if(!isset($this->callback_add_field[$field->field_name]))
			{
				$field_input = $this->get_field_input($field_info, $field_value);
			}
			else
			{
				$field_input = $field_info;
				$field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info);
				//make our little change
				//allow default field rendering behaviour if user returns false
				//in the callback
				if ($field_input->input === False) {
					$field_input = $this->get_field_input($field_info, $field_value);
				}
			}
			
			switch ($field_info->crud_type) {
				case 'invisible':
					unset($this->add_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;
				case 'hidden':
					$this->add_hidden_fields[] = $field_input;
					unset($this->add_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;
			}			
			
			$input_fields[$field->field_name] = $field_input; 
		}
		
		return $input_fields;
	}
	
	/**
	 * Get the html input for the specific field with the 
	 * current value
	 * 
	 * @param object $field_info
	 * @param string $value
	 * @return object
	 *
	 * Modified/Hacked by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				In the case of an ADD data form I want my readonly default values to go into
	 *				the database.
	 *				The default behaviour of 'readonly' fields is to not actually "be a form field"
	 *				they are instead just text in a div like this :
	 *					<div id="field-YOUR_FIELD" class="readonly_label">Your Default Value</div>
	 *				this modification adds a hidden form field that will put the default values you 
	 *				want into the database like this :
	 *					<div id="field-YOUR_FIELD" class="readonly_label">Your Default Value</div>
	 *					<input id='field-YOUR_FIELD' type='hidden' name='YOUR_FIELD' value='Your Default Value' />
	 *
	 * Dynamic Where Clause MOD 
	 * @explanation:
	 *	 			To Facilitate a call to set_relation like: 
	 *
	 *				$crud->set_relation('OUR_ID','Other_Table','Other_Table_Field1',
	 *									array('Other_Table_Field2'=>'{This_Table_Some_Field_Value}'));
	 *																 ^^ notice the curly braces  ^^
	 *
	 *				Changed the argument lists to include current row data
	 *				that we then pass on to get_relation_input()
	 */
	protected function get_field_input($field_info, $value = null,$row_values = null)
	{
			$real_type = $field_info->crud_type;
			
			$types_array = array(
					'integer', 
					'text',
					'true_false',
					'string', 
					'date',
					'datetime',
					'enum',
					'set',
					'relation', 
					'relation_n_n',
					'upload_file',
					'hidden',
					'password', 
					'readonly',
					'dropdown',
					'multiselect'
			);
			if (in_array($real_type,$types_array)) {
				/* A quick way to go to an internal method of type $this->get_{type}_input . 
				 * For example if the real type is integer then we will use the method
				 * $this->get_integer_input
				 *  */
				 
				//Dynamic Where Clause : added $row_values  to the call to get_relation_input()
				//here I'm just handling the relation type - could do more types later
				//not sure why I'd want to tho
				if (in_array($real_type,array('relation'))){
					$field_info->input = $this->{"get_".$real_type."_input"}($field_info, $value, $row_values ); 
				} else {
					$field_info->input = $this->{"get_".$real_type."_input"}($field_info,$value ); 
				}
				//Default Value mod here...
				if ((property_exists($field_info,'custom_default')) and ( $real_type=="readonly" )) {
					$field_info->crud_type='hidden';
					$field_info->type='hidden';
					$field_info->input .= $this->{"get_hidden_input"}($field_info,$value); 
					$field_info->crud_type=$real_type;
					$field_info->type=$real_type;
				}
				//no changes below here
			}
			else
			{
				$field_info->input = $this->get_string_input($field_info,$value);
			}
		
		return $field_info;
	}


	/**
	 * get_edit_input_fields()
	 * 
	 * @param object $field_values
	 * @return object
	 *
	 * Modified/Hacked by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				extend the functionality - so that a person can do processing
	 *				using the current row data - but still alow default rendering
	 *				by returning boolean False instead of a string.
	 *
	 * Dynamic Where Clause MOD 
	 * @explanation:
	 *	 			To Facilitate a call to set_relation like: 
	 *
	 *				$crud->set_relation('OUR_ID','Other_Table','Other_Table_Field1',
	 *									array('Other_Table_Field2'=>'{This_Table_Some_Field_Value}'));
	 *																 ^^ notice the curly braces  ^^
	 *
	 *				Changed the argument lists for get_field_input() to include current row data
	 *
	 *
	 */
	protected function get_edit_input_fields($field_values = null)
	{
		$fields = $this->get_edit_fields();
		$types 	= $this->get_field_types();
		
		$input_fields = array();
		
		foreach($fields as $field_num => $field)
		{
			$field_info = $types[$field->field_name];			
			
			$field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null;
			if(!isset($this->callback_edit_field[$field->field_name]))
			{			
			    // Dynamic Where Clause MOD - ADDDED $field_values to the call to get_field_input()
				$field_input = $this->get_field_input($field_info, $field_value, $field_values );
			}
			else
			{
				$primary_key = $this->getStateInfo()->primary_key;
				$field_input = $field_info;
				$field_input->input = call_user_func($this->callback_edit_field[$field->field_name], $field_value, $primary_key, $field_info, $field_values);
				//Default Values Mod
				//allow default field rendering behaviour if user returns false
				//in the callback
				if ($field_input->input === False) {
					// Dynamic Where Clause MOD - ADDDED $field_values to the call to get_field_input()
					$field_input = $this->get_field_input($field_info, $field_value, $field_values);
				}
			}
			
			switch ($field_info->crud_type) {
				case 'invisible':
					unset($this->edit_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;
				case 'hidden':
					$this->edit_hidden_fields[] = $field_input;
					unset($this->edit_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;				
			}			
			
			$input_fields[$field->field_name] = $field_input; 
		}
		
		return $input_fields;
	}	
	
	
	
	/**
	 * override get_relation_input
	 *
	 * Created by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				Dynamic Where clause Mod
	 *				This is where the magic (well, not really) happens 
	 *				we alter the where clause just before 
	 *				the call to th eparent get_relation_input()
	 *					 
	 */
	
	protected function get_relation_input($field_info, $value, $row_values){
		
		list($_field_name , $_related_table, $_related_title_field, $_where_clause , $_order_by ) = $field_info->extras;
		
		if (!empty($row_values) and !empty($_where_clause)){
			$wc=(array) $_where_clause;
			foreach ($wc as $where_key => $where_value){
				foreach ($row_values as $key => $value){
					if ($where_value=="{".$key."}") {
						$_where_clause[$where_key]=$value;
					}					
				}
			}
		}
		$field_info->extras= array($_field_name , $_related_table, $_related_title_field, $_where_clause , $_order_by ) ;
		
		//for some reason that still eludes me $value comes in as a different field value when there is a where clause
		//completely bewildered and no time to dig any deeper - is it a bug ????
		if ( !empty($row_values) ) {
			//this forces $value to be what its supposed to be
			$value = $row_values->$_field_name ;
		}
		
		return parent::get_relation_input($field_info,$value);
	}

	
	/**
	 * change_list_value
	 *
	 * Patched by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				There was a bug where images with uppercase file extensions
	 *				were'nt being displayed inline.
	 *
	 *				This, along with a change to get_upload_file_input
	 *				and /assets/grocery_crud/js/jquery_plugins/config/jquery.fileupload.config.js
	 *
	 *				fixes the behaviour					 
	 */
	protected function change_list_value($field_info, $value = null)	{
		$real_type = $field_info->crud_type;
		
		switch ($real_type) {
			case 'hidden':
			case 'invisible':
			case 'integer':
				
			break;
			case 'true_false':
				if(isset($this->default_true_false_text[$value]))
					$value = $this->default_true_false_text[$value];
			break;
			case 'string':
				$value = $this->character_limiter($value,$this->character_limiter,"...");
			break;
			case 'text':
				$value = $this->character_limiter(strip_tags($value),$this->character_limiter,"...");
			break;
			case 'date':
				if(!empty($value) && $value != '0000-00-00' && $value != '1970-01-01')
				{
					list($year,$month,$day) = explode("-",$value);
					
					$value = date($this->php_date_format, mktime (0, 0, 0, (int)$month , (int)$day , (int)$year));
				}
				else 
				{
					$value = '';
				}
			break;
			case 'datetime':
				if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00')
				{
					list($year,$month,$day) = explode("-",$value);
					list($hours,$minutes) = explode(":",substr($value,11));
					
					$value = date($this->php_date_format." - H:i", mktime ((int)$hours , (int)$minutes , 0, (int)$month , (int)$day ,(int)$year));
				}
				else 
				{
					$value = '';
				}
			break;
			case 'enum':
				$value = $this->character_limiter($value,$this->character_limiter,"...");
			break;

			case 'multiselect':
				$value_as_array = array();
				foreach(explode(",",$value) as $row_value)
				{
					$value_as_array[] = array_key_exists($row_value,$field_info->extras) ? $field_info->extras[$row_value] : $row_value;
				}
				$value = implode(",",$value_as_array);
			break;			
			
			case 'relation_n_n':
				$value = $this->character_limiter(str_replace(',',', ',$value),$this->character_limiter,"...");
			break;						
			
			case 'password':
				$value = '******';
			break;
			
			case 'dropdown':
				$value = array_key_exists($value,$field_info->extras) ? $field_info->extras[$value] : $value; 
			break;			
			
			case 'upload_file':
				if(empty($value))
				{
					$value = "";
				}
				else
				{
					//uppercase file extension fix :
					$is_image = !empty($value) &&
					(strripos($value,'.jpg',-4) !== False
							|| strripos($value,'.png',-4) !== False
							|| strripos($value,'.jpeg',-5) !== False
							|| strripos($value,'.gif',-4) !== False
							|| strripos($value,'.tiff',-5) !== False)
							? true : false;
					//: uppercase file extension fix
								
					$file_url = base_url().$field_info->extras->upload_path."/$value";
					
					$file_url_anchor = '<a href="'.$file_url.'"';
					if($is_image)
					{
						$file_url_anchor .= ' class="image-thumbnail"><img src="'.$file_url.'" height="50px">';
					}
					else
					{
						$file_url_anchor .= ' target="_blank">'.$this->character_limiter($value,$this->character_limiter,'...',true);
					}
					$file_url_anchor .= '</a>';
					
					$value = $file_url_anchor;
				}
			break;
			
			default:
				$value = $this->character_limiter($value,$this->character_limiter,"...");
			break;
		}
		
		return $value;
	}
	
	
	/**
	 * get_upload_file_input
	 *
	 * Patched by Ez (ezgoen@gmail.com) - email me for my real identity
	 *
	 * @explanation:
	 *				There was a bug where images with uppercase file extensions
	 *				were'nt being displayed inline.
	 *
	 *				This, along with a change to change_list_value
	 *				and /assets/grocery_crud/js/jquery_plugins/config/jquery.fileupload.config.js
	 *
	 *				fixes the behaviour					 
	 */
	
	protected function get_upload_file_input($field_info, $value){
		$this->set_css($this->default_css_path.'/ui/simple/'.grocery_CRUD::JQUERY_UI_CSS);
		$this->set_css($this->default_css_path.'/jquery_plugins/file_upload/file-uploader.css');
		$this->set_css($this->default_css_path.'/jquery_plugins/file_upload/jquery.fileupload-ui.css');

		$this->set_js($this->default_javascript_path.'/jquery_plugins/ui/'.grocery_CRUD::JQUERY_UI_JS);
		$this->set_js($this->default_javascript_path.'/jquery_plugins/tmpl.min.js');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/load-image.min.js');

		$this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.iframe-transport.js');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.fileupload.js');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.fileupload.config.js');
		
		//Fancybox
		$this->set_css($this->default_css_path.'/jquery_plugins/fancybox/jquery.fancybox.css');
		
		$this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.fancybox.pack.js');
		$this->set_js($this->default_javascript_path.'/jquery_plugins/jquery.easing-1.3.pack.js');	
		$this->set_js($this->default_javascript_path.'/jquery_plugins/config/jquery.fancybox.config.js');		
		
		$unique = uniqid();
		
		$allowed_files = $this->config->file_upload_allow_file_types;
		$allowed_files_ui = '.'.str_replace('|',',.',$allowed_files);
		$max_file_size_ui = $this->config->file_upload_max_file_size;
		$max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui);
		
		$this->_inline_js('
			var upload_info_'.$unique.' = { 
				accepted_file_types: /(\\.|\\/)('.$allowed_files.')$/i, 
				accepted_file_types_ui : "'.$allowed_files_ui.'", 
				max_file_size: '.$max_file_size_bytes.', 
				max_file_size_ui: "'.$max_file_size_ui.'" 
			};
				
			var string_upload_file 	= "'.$this->l('form_upload_a_file').'";
			var string_delete_file 	= "'.$this->l('string_delete_file').'";
			var string_progress 			= "'.$this->l('string_progress').'";
			var error_on_uploading 			= "'.$this->l('error_on_uploading').'";
			var message_prompt_delete_file 	= "'.$this->l('message_prompt_delete_file').'";
			
			var error_max_number_of_files 	= "'.$this->l('error_max_number_of_files').'";
			var error_accept_file_types 	= "'.$this->l('error_accept_file_types').'";
			var error_max_file_size 		= "'.str_replace("{max_file_size}",$max_file_size_ui,$this->l('error_max_file_size')).'";
			var error_min_file_size 		= "'.$this->l('error_min_file_size').'";

			var base_url = "'.base_url().'";
			var upload_a_file_string = "'.$this->l('form_upload_a_file').'";			
		');

		$uploader_display_none 	= empty($value) ? "" : "display:none;";
		$file_display_none  	= empty($value) ?  "display:none;" : "";
		
		//uppercase file extension fix :
		$is_image = !empty($value) &&
					(strripos($value,'.jpg',-4) !== False
							|| strripos($value,'.png',-4) !== False
							|| strripos($value,'.jpeg',-5) !== False
							|| strripos($value,'.gif',-4) !== False
							|| strripos($value,'.tiff',-5) !== False)
							? true : false;
		//: uppercase file extension fix
		$image_class = $is_image ? 'image-thumbnail' : '';
		
		$input = '<span class="fileinput-button qq-upload-button" id="upload-button-'.$unique.'" style="'.$uploader_display_none.'">
			<span>'.$this->l('form_upload_a_file').'</span>
			<input type="file" name="'.$this->_unique_field_name($field_info->name).'" class="gc-file-upload" rel="'.$this->getUploadUrl($field_info->name).'" id="'.$unique.'">
			<input class="hidden-upload-input" type="hidden" name="'.$field_info->name.'" value="'.$value.'" rel="'.$this->_unique_field_name($field_info->name).'" />
		</span>';
		
		$this->set_css($this->default_css_path.'/jquery_plugins/file_upload/fileuploader.css');
		
		$file_url = base_url().$field_info->extras->upload_path.'/'.$value;
		
		$input .= "<div id='uploader_$unique' rel='$unique' class='grocery-crud-uploader' style='$uploader_display_none'></div>";
		$input .= "<div id='success_$unique' class='upload-success-url' style='$file_display_none padding-top:7px;'>";
		$input .= "<a href='".$file_url."' id='file_$unique' class='open-file";
		$input .= $is_image ? " $image_class'><img src='".$file_url."' height='50px'>" : "' target='_blank'>$value";
		$input .= "</a> ";
		$input .= "<a href='javascript:void(0)' id='delete_$unique' class='delete-anchor'>".$this->l('form_upload_delete')."</a> ";
		$input .= "</div><div style='clear:both'></div>";
		$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>";
		$input .= "<div style='display:none'><a href='".$this->getUploadUrl($field_info->name)."' id='url_$unique'></a></div>";
		$input .= "<div style='display:none'><a href='".$this->getFileDeleteUrl($field_info->name)."' id='delete_url_$unique' rel='$value' ></a></div>";
		
		return $input;
	}
	
/*
 * /assets/grocery_crud/js/jquery_plugins/config/jquery.fileupload.config.js
 *
 * Patched by Ez (ezgoen@gmail.com) - email me for my real identity
 *
 * @explanation:
 *				There was a bug where images with uppercase file extensions
 *				were'nt being displayed inline.
 *
 *				This, along with a change to change_list_value
 *				and  get_upload_file_input
 *
 *				fixes the behaviour					 
 *
 *

function show_upload_button(unique_id, uploader_element)
{
	$('#upload-state-message-'+unique_id).html('');
	$("#loading-"+unique_id).hide();

	$('#upload-button-'+unique_id).slideDown('fast');
	$("input[rel="+uploader_element.attr('name')+"]").val('');
	$('#success_'+unique_id).slideUp('fast');	
}

function load_fancybox(elem)
{
	elem.fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});		
}

$(function(){
	$('.gc-file-upload').each(function(){
		var unique_id 	= $(this).attr('id');
		var uploader_url = $(this).attr('rel');
		var uploader_element = $(this);
		var delete_url 	= $('#delete_url_'+unique_id).attr('href');
		eval("var file_upload_info = upload_info_"+unique_id+"");
		
	    $(this).fileupload({
	        dataType: 'json',
	        url: uploader_url,
	        cache: false,
	        acceptFileTypes:  file_upload_info.accepted_file_types,
			beforeSend: function(){
	    		$('#upload-state-message-'+unique_id).html(string_upload_file);
				$("#loading-"+unique_id).show();
				$("#upload-button-"+unique_id).slideUp("fast");
			},
	        limitMultiFileUploads: 1,
	        maxFileSize: file_upload_info.max_file_size,			
			send: function (e, data) {						
				
				var errors = '';
				
			    if (data.files.length > 1) {
			    	errors += error_max_number_of_files + "\n" ;
			    }
				
	            $.each(data.files,function(index, file){
		            if (!(data.acceptFileTypes.test(file.type) || data.acceptFileTypes.test(file.name))) {
		            	errors += error_accept_file_types + "\n";
		            }
		            if (data.maxFileSize && file.size > data.maxFileSize) {
		            	errors +=  error_max_file_size + "\n";
		            }
		            if (typeof file.size === 'number' && file.size < data.minFileSize) {
		            	errors += error_min_file_size + "\n";
		            }			            	
	            });	
	            
	            if(errors != '')
	            {
	            	alert(errors);
	            	return false;
	            }
				
			    return true;
			},
	        done: function (e, data) {
				if(typeof data.result.success != 'undefined' && data.result.success)
				{
					$("#loading-"+unique_id).hide();
					$("#progress-"+unique_id).html('');
		            $.each(data.result.files, function (index, file) {
		            	$('#upload-state-message-'+unique_id).html('');
		            	$("input[rel="+uploader_element.attr('name')+"]").val(file.name);
		            	var file_name = file.name;
						//uppercase file extension fix :
		            	var is_image = (file_name.toLowerCase().substr(-4) == '.jpg'  
		            						|| file_name.toLowerCase().substr(-4) == '.png' 
		            						|| file_name.toLowerCase().substr(-5) == '.jpeg' 
		            						|| file_name.toLowerCase().substr(-4) == '.gif' 
		            						|| file_name.toLowerCase().substr(-5) == '.tiff')
							? true : false;
						//: uppercase file extension fix
		            	if(is_image)
		            	{
		            		$('#file_'+unique_id).addClass('image-thumbnail');
		            		load_fancybox($('#file_'+unique_id));
		            		$('#file_'+unique_id).html('<img src="'+file.url+'" height="50" />');
		            	}
		            	else
		            	{
		            		$('#file_'+unique_id).removeClass('image-thumbnail');
		            		$('#file_'+unique_id).unbind("click");
		            		$('#file_'+unique_id).html(file_name);
		            	}
		            	
						$('#file_'+unique_id).attr('href',file.url);
						$('#hidden_'+unique_id).val(file_name);

						$('#success_'+unique_id).fadeIn('slow');
						$('#delete_url_'+unique_id).attr('rel',file_name);
						$('#upload-button-'+unique_id).slideUp('fast');
		            });
				}
				else if(typeof data.result.message != 'undefined')
				{
					alert(data.result.message);
					show_upload_button(unique_id, uploader_element);
				}
				else
				{
					alert(error_on_uploading);
					show_upload_button(unique_id, uploader_element);
				}
	        },
	        autoUpload: true,
	        error: function()
	        {
	        	alert(error_on_uploading);
	        	show_upload_button(unique_id, uploader_element);
	        },
	        fail: function(e, data)
	        {
	            // data.errorThrown
	            // data.textStatus;
	            // data.jqXHR;	        	
	        	alert(error_on_uploading);
	        	show_upload_button(unique_id, uploader_element);
	        },	        
	        progress: function (e, data) {
                $("#progress-"+unique_id).html(string_progress + parseInt(data.loaded / data.total * 100, 10) + '%');
            }	        
	    });
		$('#delete_'+unique_id).click(function(){
			if( confirm(message_prompt_delete_file) )
			{
				var file_name = $('#delete_url_'+unique_id).attr('rel');
				$.ajax({
					url: delete_url+"/"+file_name,
					cache: false,
					success:function(){
						show_upload_button(unique_id, uploader_element);
					},
					beforeSend: function(){
						$('#upload-state-message-'+unique_id).html(string_delete_file);
						$('#success_'+unique_id).hide();
						$("#loading-"+unique_id).show();
						$("#upload-button-"+unique_id).slideUp("fast");
					}
				});
			}
			
			return false;
		});		    
	    
	});
});
*/
}
?>

 

 

 

 

 

 

Cheers

 

 

Ez




#6596 Image upload

Posted ezgoen on 29 March 2013 - 08:53 AM

 

Hi folks,

 

Thanks again for grocerycrud

 

There's a buglet - I was wondering why images I uploaded sometimes didn't display

 

here it is 

 

	$is_image = !empty($value) &&
	( substr($value,-4) == '.jpg'
		|| substr($value,-4) == '.png'
		|| substr($value,-5) == '.jpeg'
		|| substr($value,-4) == '.gif'
		|| substr($value,-5) == '.tiff')
		? true : false;		

 

its not checking for uppercase file extension.

 

one of my camera's uses uppercase file extensions.

I'm sure I'm not the only one.

 

 

Hope I got this right - it was just a quick - "OMG - I know why"  followed by a quick search of the code 

 

that got me here - I was manually displaying images in a callback until I found this.

 

 

function _cb_image_callback_column($value, $row){
		$imagepath=dirname(site_url())."/".$row->image_path."/".$row->main_image;
		$result ="<a href=\"$imagepath\" class=\"image-thumbnail\">";
		$result.="<img src=\"$imagepath\" height=\"50px\"/></a>";
		return $result;
	}

 

hope this can be fixed

 

 

Cheers everyone 

 

 

Have a happy easter or a great weekend 

 

 

Ez