Archive

Author Archive

Remove all the items in a drop down list except the first using Jquery

November 6, 2009 Wes Leave a comment

I needed a drop down list to be populated from a selection in another drop down list. Each select should change the options listed in the second list. Using Jquery it was easy to remove all the options and rebuild the list, but I wanted to keep the first option. I finally found the solution searching the Jquery site and it’s quite simple.

selection.children('option:not(:first)').remove();

Where selection is the id of the drop down list. I hope this helps somebody not spend the hour it took me to figure it out.

Categories: jquery

Hide borders for an input box

November 6, 2009 Wes Leave a comment

I wanted to have a form with read only input boxes that were populated by Ajax calls. The problem is there was a border around the box in IE7 and FF 3.5. In IE6 border=0 solved the issue but not in the other browsers. Thanks to this site for the inspiration I was able to remove the borders using the this css style:

.hiddenlabel[type="text"] {
border:none;
display:inline;
vertical-align:middle;
}

The key is the [type="text"], this applies the style to the input box. Just in case your wondering why I need to do this it is because I need the information in the form to be submitted and need to update the information using Ajax. This was easier than using hidden fields.

 

Categories: CSS Tags:

Snow Leopard Install

September 13, 2009 Wes Leave a comment

I updated my MacBook Pro to Apple’s latest operating system Snow Leopard 10.6. This is how I did it and my install went fine.
First, check to make sure any programs that you need are compatible or have been updated to work with 10.6. The best place I have found was this wiki http://snowleopard.wikidot.com/. I had some software that was not compatible but for me, but the software was not that big of a deal and I could wait for updates.
The next thing I did was run a full maintenance on my computer using Maintenance. This clean a lot of stuff out and repaired any permissions.
After that I just rebooted to the install disk and followed the onscreen instructions. Everything was fine. I got back about 6GB of space.
I did have to uninstall the software for my HP AIO 2570 printer and add it using the Printers & Faxes, but everything works including scanning. Scanning directly from Preview is nice.
Well that’s how I did it and it worked for me.

Categories: Mac, Software

Save an email attachment using Zend Mail

June 10, 2009 Wes Leave a comment

To do some automated billing I needed to grab an email attachment off the exchange server. The Zend framework made it very easy to connect to the mail server and navigate files, and that part of the code came directly from the Zend Framework documentation. The issue that took the longest was saving the attachment. I could not figure out how to decode the attachment using the Zend framework. Let me know if you have a better way or if it helps you out.
NOTE: If you getting the mail from the INBOX you do not have to use the getFolders() function.

// Connecting with Imap
$mail = new Zend_Mail_Storage_Imap(
        array('host'     => 'SERVER',
              'user'     => 'USERNAME',
              'password' => 'PASSWORD'));

// Navigate to desired folder
$folder = $mail->getFolders()->INBOX->Info;

// Change to folder
$mail->selectFolder($folder);

// Loop through messages
foreach ($mail as $message)
{
 // Find desired message subject
 if($message->subject == 'SUBJECT')
 {
 // Check for attachment
 if($message->isMultipart())
 {
    $part = $message->getPart(2);
 }

 // Get the attacment file name
 $fileName = $part->getHeader('content-description');

 // Get the attachement and decode
 $attachment = base64_decode($part->getContent());

 // Save the attachment
 $fh = fopen($fileName, 'w');

 fwrite($fh, $attachment);

 fclose($fh);
 }
}
Categories: PHP, Zend Framework

Getting the root node from an XML string

June 3, 2009 Wes Leave a comment

PHPs SimpleXML is great for parsing xml files. The downside is that it does not return the root node name. I wrote this function that gets the name.


/**
 * function getXMLRootNode
 * @param string An xml string
 * @return string Return XML root node name
 */

function getXMLRootNode($xmlstr)
{
 // Create DOM model
 $doc = new DOMDocument();

 // Load the XML string
 if(!$doc->loadXML($xmlstr))
 {
 throw new Exception('Unable to parse XML string');
 }

 // Find the root tag name
 $root = $doc->documentElement;

 if(!isset($root))
 {
 throw new Exception('Unable to find XML root node');
 }

 if(!isset($root->nodeName))
 {
 throw new Exception('Unable to find XML root node name');
 }

 return $root->nodeName;
}
Categories: PHP, Programming

New autoloading with Zend Framework 1.8

May 15, 2009 Wes 2 comments

I love the fact that you can autoload classes using the ZF. I was a little shocked at the depreciation errors when I updated to ZF 1.8. Apparently, there is a new way to use the autoload class. It took a little reading but I came up with this solution. Let me know what you think!

/*
 * Set up Zend loader
 */
require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();

/*
 * Register Cisc Classes
 */
$autoloader->registerNamespace('Cisc_');

The registerNamespace function registers my own classes.

Categories: PHP Tags:

Creating a Soap Server using the Zend Framework

May 15, 2009 Wes Leave a comment

I decide to try my hand at creating a soap server using the Zend Framework. This was an exersice in getting me more familiar with ZF and web services. Hopefully this will help others. I think the code is pretty self explanitory but feel free to ask questions or provide comments.

Basically the WSDL is auto generated by php if the URL ends in ?wsdl, if not then the soap server is created and the request handled.


/*
* Check to see if soap call is to be handled
* or if the WSDL should be displayed
*/
if(isset($_GET['wsdl']))
{
    createWSDL();
}
else
{
   /*
    * Soap Server WSDL document
    */
    $wsdl = 'http://' . $_SERVER["SERVER_NAME"] .
    $_SERVER['PHP_SELF'] . '?wsdl';

   /*
    * Create a new soap server
    */
    $server = new Zend_Soap_Server($wsdl,
        array('soap_version' => SOAP_1_2)
    );

   /*
    * Set the server to cache the wsdl file
    */
    $server->setWsdlCache(1);

   /*
    * Set the class for the web service
    */
    $server->setClass('Cisc_Ws_Cs3webservice');

   /*
    * Set soap server persistance (For use with login feature)
    */
    $server->setPersistence(SOAP_PERSISTENCE_SESSION);

   /*
    * Register exceptions
    */
    $server->registerFaultException('Exception');
   /*
    * Handle the soap call
    */
    $server->handle();
}

/**
* Create the WSDL file for display
*
* @param none
* @return string The wsdl xml
*/
function createWSDL()
{
    $wsdl = new Zend_Soap_AutoDiscover();

    $wsdl->setClass('Cisc_Ws_Cs3webservice');

    $wsdl->handle();
}

The WSDL is created from the class file, so make sure you use proper documentation blocks for you code. The only issue I have seen so far is that if a function input in the class is a integer,
no matter what is inputted, an integer will be pass to the function. This makes it difficult to verify data, say that your getting an integer and not a float. The workaround is to pass an array
and check the values of the array.

Categories: PHP Tags:

Events created in iPod Touch do not appear in iCal after syncing

March 10, 2009 Wes Leave a comment

I had the problem of when I added new events on my iPod Touch they would not show up in iCal after syncing. The quick fix for me was to open iSync, go to Preferences, then click the Reset Sync History… button. This resolved the issue for me. Hope this helps somebody else.

Categories: Hardware, Mac, Software

Zend Server Community Edition Install

March 4, 2009 Wes 3 comments

So  I decided I would try out Zend Server CE. I have tried the installation on a server running Windows 2003 and XP Professional with PHP already installed using ISAPI. The install goes fine, but when I try to access the web page I get an FastCGI Access Denied error.

I have tried everything I can think of, including the suggestions on the web for changing permissions on several directories, but I still cannot resolve this issue. I am going to try and get it working but if anybody has any suggestions please let me know.

UPDATE: I was finally able to get Zend Sever installed. I had to remove IIS using add/remove programs, re-install it, then install Zend Server. I like it a lot.

Categories: PHP, Programming

Cross Domain Ajax

September 29, 2008 Wes Leave a comment

I found a nice simple way to do cross domain ajax calls reliably. I found this Yahoo page that gives a nice little tutorial on how to use php and curl to access other domains using a simple proxy. Simple and effective. The code that I tweeked for my own use is found here. Let me know if you have any comments or suggestions.

Categories: PHP, Programming