Saturday, October 24, 2009

Email Parsing and download attachment with IMAP in PHP

Last couple of days, i was working on a script where i need to download an attachment from a windows mail server and then read the contents inside the attachment and save it in database.

Tasks:
1- Read all unseen messages in the inbox.
2- Search for a specific subject.
3- Download the attachment(zip file) to local PC.
4- Unzip the file and extract the file inside it.
5- Read its contents inside the file.
6- Save the contents to a table(MySQL database).
7- Delete the extracted file after saving entries into table.
8- Move the zip file to a backup directory.
9- Do calculations on the data saved in the table.

Actually i had to do this for one of my project, where the sensors gateway will send mail to the windows server each hour, and i have to read the mail from a Linux machine.

As most of the work is completed on these scripts, i tested it under cron on local PC, and is working like a charm. So i am thinking to share the scripts with the community, maybe would help someone in the near future.

I have written 3 PHP scripts(pure PHP) with some MySQL tables to use for data saving.
I will start in the next post from the 1st script which is mail_parsing.php. I used PHP IMAP function to access the mail server.

Until then have a good time.
See you in the next post.

ANL

Friday, October 16, 2009

openSUSE 11.2 RC1 released.

Hi all,
openSUSE announced its 1st release candidate for 11.2 version, one more RC and then final version.
Here are some of the updates since M8:

* Linux kernel 2.6.31.3
* GNOME 2.28
* PulseAudio 0.9.19
* Evolution 2.28
* Qt 4.5.3
* SeaMonkey 2.0 RC 1

As i am still on M7, for me its quite stable and as i don't have much time to switch and install. So i am waiting for the final release.

download it from here:
gwdg mirror
and
openSUSE site

Follow up discussion here in openSUSE forum.

Have alot of fun!

ANL

Monday, October 12, 2009

Listbox values in PHP with MySql

Today got some free time to write a simple tutorial for PHP with MySql for listbox.
So lets start.

Mostly we use drop down on many occasions, populated from database dynamically or giving it values statically. And then use PHP code to parse it and store it in database or get our desired results.
One type of that dropdown is listbox, where we can select multiple entries.
Here is a sample example of it:


In the above code:
multiple: represent multiple list for values
size: will show 2 values in the list, and others will be shown by scrolling.
name: is holding name in array.

Now lets take a MySql example:


Now lets jump to PHP to get the desired results.
There are many ways to get the results like:
foreach, for and etc. As we know, POST is also an array. So the best bet is to use array.

$drop_list = $_POST['drop_list'];
$_SESSION['drop_list'] = $drop_list;
if (in_array(1, $drop_list)) { //id 1
$query1 = "SELECT * FROM test2 where id='1'";
$res1 = mysql_query($query1) or die(mysql_error());
//You can do some other stuff here too
}


You can use multiple if statements to verify the variable resulted value.
You can save the value in session to use it globally in your scripts.
Example:
if (in_array(2, $drop_list)) { //id 2
$query1 = "SELECT * FROM test3 where id='2'";
$res1 = mysql_query($query1) or die(mysql_error());
//You can do some other stuff here too
}
if (in_array(3, $drop_list)) { //id 3
$query1 = "SELECT * FROM test4 where id='3'";
$res1 = mysql_query($query1) or die(mysql_error());
//You can do some other stuff here too
}


Apart from the above example, there are many ways like foreach, if you don't want to just use one by one. Like:

foreach($_POST['drop_list'] as $drop_list){
//Do your stuff here like, updating multiple records at one shot.
}


Best of luck.
ANL

Friday, October 2, 2009

openSUSE11.2 M8 released.

openSUSE team announced the release of milestone 8.
As i had tested M7, and i am quite satisfied with it. Its still running on my lapy. Everything is working out of the box. Just sound need fixing for my lapy, other things works fine. Bluetooth is working.
I am not going to install and test M8, because has no time. But it looks decent than M7, the big/good change i saw is the theming. Boot and splash themes are changed since M7.

Here are some details:
* Linux kernel 2.6.31
* GNOME 2.28 RC
* OpenOffice.org 3.1.1
* openSUSE 11.2 theming is in place
* PulseAudio 0.9.17
* Samba 3.4.1
* postgresql 8.4.1
* KDE 4.3.1 (release 3)


Fast download link:
gwdg mirror

Information link:
openSUSE info link

openSUSE download link:
Download M8 from openSUSE site

Enjoy M8.

ANL