This text is replaced by the Flash movie.

Archive for the ‘PHP’ Category

PNG upload/resize trouble

September 25th, 2010
While updating a component I got from cakePHP (Image Resize/Upload) I found out that it was not for my current version of PHP - it has trouble uploading PNG type image, I'm getting "Warning (2): imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib error" This error only occur on servers with PHP v5.1.x or newer... so the simple solution from the code...

from
imagepng($cropped,$filename,80);
to
imagepng($cropped,$filename,8);

The third parameter is for the quality of the image to be uploaded so for png it only supports from 0 - 9, above that it will cause warnings and errors.

Cake using Multiple Select Checkboxes

December 2nd, 2009

A sample on how to use multiple select checkbox within cakephp views and controller.

 

After reviewing the http://api.cakephp.org/file/cake/libs/view/helpers/form.php#method-FormHelperselect


1.) Inserting to database

-View Decleration Example.

1
2
3
4
5
6
7
8
9
10
11
 <?php 
//add.ctp for example
?>
     <em>How would you describe your job (mark as many as applies):   </em>
           <?php       echo $form->input('describeJob', array('label' => false,
                                                    'div' => false,
                                                    'type' => 'select',
                                                    'multiple'=>'checkbox',
                                                    'legend' => 'false',
                                                    'options' => array('Physical' => 'Physical','Mental' => 'Mental', 'Stressful' => 'Stressful',  'Easy-going' => 'Easy-going', 'Secure' => 'Secure', 'Non-secure' => 'Non-secure', 'Exhausting' => 'Exhausting', 'Relaxing' => 'Relaxing' )
                                                      )); ?>

-On your controller. Use implode php function and add a seperator that you like, for this example I use ","

1
2
3
4
5
6
 <?php 
 //job_controller @add() function
        if (!empty($this->data)) {
        $this->data['Job']['describeJob'] = implode(",",$this->data['Job']['describeJob']);
                $this->Job->create();
?>


2.) Editing part, Retrieving values of the datafield to mark check on those were choosen before. 
-View Decleration Example. In this example I used explode function of php directly in the view, notice the "selected" option added in to the $form->input helper, this will get the values, supposed to be check in that field.

1
2
3
4
5
6
7
8
9
10
<?
//edit.ctp for example
       $piecesJob = explode(",",  $this->data['Job']['describeJob']);
             echo $form->input('describeJob', array('label' => false,
                                                    'div' => false,
                                                    'type' => 'select',
                                                    'multiple'=>'checkbox',
                                                    'legend' => 'false',
                                                    'options' => array('Physical' => 'Physical','Mental' => 'Mental', 'Stressful' => 'Stressful',  'Easy-going' => 'Easy-going', 'Secure' => 'Secure', 'Non-secure' => 'Non-secure', 'Exhausting' => 'Exhausting', 'Relaxing' => 'Relaxing' ),
                                                    'selected' => $piecesJob   )); ?>

That's it :)

Cake Baking Models – Cannot see other tables

November 7th, 2009

Problem.
After I updated the database, I added 1 table; relate it to another table, and go to the command line to bake what I did, after typing "cake bake model" at the command prompt, I found out that the recently added table was not listed.

Cake PHP Bake Model Problem

 

Reason.
Cake caches your model schema. 

Solution.
1.) 
Clear your cache by deleting all files in your app's tmp/cache/models/
and tmp/cache/persistent/

2.) 
Disable caching in your app's config/core.php // make sure to enable back again in production setup

/**
 * Turn off all caching application-wide.  *  
 */  
Configure::write('Cache.disable', true);

After doing the solution, I can now successfully bake the new table.

Work Telephone: Paypal Sandbox

November 21st, 2008
Work Telephone: The phone number is not properly formatted.
And I'm only trying this for Registering  "Business Account" on sandbox.

This link would help click here


  Try using this format  xxx yyy zzzz (308 555 1234) to get past the code and get into the account. Then once in the account, you can update the account information to the correct phone number through Profile> phone number.

  Frank I.
  PayPal Certified Developer
  PayPal PayWatch Analyst
  http://www.paypaldeveloper.com
  PayPal, an eBay Company


The Social Security Number you entered cannot be validated.

This link would help click here


  A social security number needed to be added. This can be done by you, the number must start with '111'.

  Frank I.
  PayPal Certified Developer
  PayPal PayWatch Analyst
  http://www.paypaldeveloper.com
  PayPal, an eBay Company


CMSMS FrontEnd User Hack…

September 29th, 2008
CMSMS FrontEnd User Hack for Automatic Login
The following step by step method I did Integrating CMSMS and amember for automatic login

Current Version of FrontEndUsers plugin is 1.5.2
CMSMS Version 1.4.1

For Session - I used


    $_SESSION['fe_user_logged_in'] //- just passing a non sense string :) not important.
    $_SESSION['fe_int_username'] //- passing username value
    $_SESSION['fe_int_password'] //- passing password value
 

Note: I used Custom Session variables, cause on my current project I used 4 different apps to pass this session variables... If you are only integrating cmsms on amember, I advice that you get the session of amember username and password.

CMSMS

Front End User Login

-----------------------------------------------------------------------------------------------------
1.)at [index.php] root of cmsms
add session_start(); at the beginning

over modules folder find
FrontEndUsers folder

2.)Injecting the Sessions

on - [action.do_login.php]

find (could be) on line 80:

    
     $this->Audit( 0, $this->Lang('friendlyname'),
     $this->Lang('frontenduser_loggedin').": ".$params['feu_input_username'] );

     //
     // we're logged in
     //

put these following code at bottom of it:

    
     /* Custom Login Session */
     $_SESSION['fe_user_logged_in'] = "logged_in"; // store session data
     $_SESSION['fe_int_username'] = $params['feu_input_username']; //username
     $_SESSION['fe_int_password'] = $params['feu_input_password']; //password
     session_write_close();

3.)Erasing the Session

on - [action.logout.php]

find (could be) on line 53:

    
     $this->SendEvent( 'OnLogout', $parms );
     $this->_SendNotificationEmail('OnLogout',$parms);

     // we're logged out
     // redirect somewhere
     // todo, add more options here.

put these following code at bottom of it:


     /* Custom Logout Session */
     $_SESSION['fe_user_logged_in'] = NULL; // store session data as NULL
     $_SESSION['fe_int_username'] = NULL;
     $_SESSION['fe_int_password'] = NULL;
     session_write_close();
 

4.)This is not necessary but if you want to custom design or name on your login boxes you can edit the hard code at:

[function.user_loginform.php]

Like in this case I added some javascript on input boxes and also changed the class style.


/*
        $smarty->assign('input_username',
        $this->CreateInputText( $id, 'feu_input_username',
        $username,
        $this->GetPreference('usernamefldlength'),
        $this->GetPreference('max_usernamelength')));
*/                   

    $smarty->assign('input_label', $id );
    $smarty->assign('id_password',$id.'feu_input_password');
    $smarty->assign('prompt_password', $this->Lang('prompt_password'));

    $smarty->assign('input_password', '<input type="password" name = "' .$id.  'feu_input_password" class="passwordfield"

    onfocus="this.style.backgroundImage=\'none\'" onblur="if(this.value==\'\'){this.style.backgroundImage=\'url(images/login-password.gif)\'}" />');

/*