Sunday, 14 November 2010

Packages required to run skype on Fedora 15,16,17

Just installed skype 2.2 on my Fedora 15 (x86_64) box and it works. The actual rpm can be downloaded from here. The rpm installs itself without checking for dependencies, so in order to run skype correctly you need the 32bit versions of the qt and alsa libraries. The actual command to install these packages is:


sudo yum -y install qt.i686 qt-x11.i686 libXScrnSaver.i686 alsa-lib.i686

... and away we go.

Update (2012-06-09). Verfied for fedora 17

Thursday, 19 August 2010

Friday, 9 July 2010

Hello T-SQL and ASP.NET

Half of me wishes things had gone the way I planned, so now we would be programming with CakePHP storing data in Oracle and calling remote enabled function modules in order to communicate with SAP. Then my other half says: "Ok, no more reading and mangling with ABAP spaghetti code written by somebody afraid to declare a single local variable and trying to figure out what all these magic tables with the enlightening four-letter names do!" Of course getting rid of ABAP is the bright side. The dark side said says "Hello from 1 Microsoft Way Redmond WA"

After the company I work for was sold out right before Christmas, the new management decided that SAP was too expensive and too complicated so from now the entire group we will be using a Greek ERP made by Entersoft SA. The new ERP is an N-Tier system running under Windows written in .NET and uses Microsoft SQL Server as data store. So what is left for us now is to learn and program in .NET

Being the Linux junkie I am, this development in my developer status triggered various comments from friends and neighbours. The most interesting was this video trailer which much like Sgt. Pepper's Lonely Hearts Club Band is ... guaranteed to raise a smile.

So Java vs .NET; the choice is not always yours sο sit back and enjoy

Stay tuned for more.

Wednesday, 14 April 2010

Flash player for 64 bit Linux

Thanks to Leigh's repository for Fedora, I almost forgot where to find the latest version of flash player.

So, to save a little bit of googling ...

Last update : August 11, 2011

Sunday, 7 February 2010

Linux: Mass rename of files

When people give me files, especially images, coming from windows machines I always have problems with capitalised extensions. JPEG format files for instance appear as image.JPG instead of image.jpg. Worst case is that in some collections some file extensions appear capitalised while others in lower case.

I have searched the web for some simple solution to this problem and ended up seeing sed commands and pipes that UNIX gurus are so fond off,

So, if you wanted to rename all the .php3 to .php, this would be the command:
ls -d *.php3 | sed 's/\(.*\).php3$/mv "&" "\1.php"/' | sh

As Fortune keeps reminding me, there is more than one way to skin a cat, so a more complete discussion on mass renaming with Linux can be found on Gareth Anderson's GNU/Linux Command-Line Tools Summary book article directly accessible from here.

Anyway, after a little bit of googling, it turned out to my surprise that the simplest way to do this was inside my own Fedora distro. The magic command is rename and the man entry is small, simple and accurate :

RENAME(1)                  Linux Programmer’s Manual                 RENAME(1)

NAME
       rename - Rename files

SYNOPSIS
       rename from to file...
       rename -V

DESCRIPTION
       rename will rename the specified files by replacing the first occurrence of from in their name by to.

       -V, --version
              Display version information and exit.

       For example, given the files
              foo1, ..., foo9, foo10, ..., foo278, the commands

              rename foo foo0 foo?
              rename foo foo0 foo??

       will turn them into foo001, ..., foo009, foo010, ..., foo278.

       And
              rename .htm .html *.htm

       will fix the extension of your html files.

SEE ALSO
       mmv(1), mv(1)

AVAILABILITY
       The   rename   command   is   part   of   the   util-linux-ng   package   and   is   available  from  ftp://ftp.ker-
       nel.org/pub/linux/utils/util-linux-ng/.

                                1 January 2000                       RENAME(1)

The rename command is also available on all EL clones like (CentOS and Oracle EL).

Wednesday, 20 January 2010

CakePHP: Calling Oracle stored procedures and functions

Our testing with Cake is almost complete. We have been able to read and write data correctly in our non UTF-8 Oracle database, managed to communicate with SAP, played enough with AJAX, so our users will not complain when dealing with tree like data and even managed to get authenticated by our MS-Windows 2003 active directory servers. So the last question left was how does one call an Oracle PL/SQL stored procedure or function from CakePHP ?

A little bit of googling and a little bit of digging into the CakePHP code revealed the following: The most common approach to calling stored procedures and functions is to create a member function in your model class and set up the call from there. In the simple case of calling a stored procedure with IN parameters only, the Model's query() method can be used to perform the actual call via the CALL PROC_NAME( ... ) SQL statement. The usual approach is to create a model method like this :

class MyModel extends AppModel {
    var $name = "MyModel";

    ...
    function callStoredProc( $param1, $param2)
    {
        $this->query("CALL my_stored_proc( $param1, $param2");
    }
    ...
}

If however you need to get data in and out of Oracle then you have to get your hands dirty and set up the call using low level oci_* functions. A simple example will clarify everything.

Let us suppose that you library users require that you display the average number of pages of the books stored in your library. A simple PL/SQL function to return this would probably be something like this: /p>

CREATE OR REPLACE FUNCTION average_book_pages RETURN NUMBER
IS
   page_avg NUMBER;   
BEGIN
   SELECT avg( num_pages) 
      INTO page_avg
      FROM books;
   RETURN page_avg;   
END AVERAGE_BOOK_PAGES;

The next thing to do would be to create a getAvergaeBookPages() function in our Book model class :

<?php
class Book extends AppModel {
    var $name = 'Book';
    var $belongsTo = ...
    var $validate = array( ...

    function getAverageBookPages()
    {
        // every model has a datasource
        $dataSource = $this->getDataSource();
        // and every datasource has a  database connection handle
        $connection = $dataSource->connection;
        if (!$connection)
            return -1;

        // from now you need this Oracle specific approach 
        $statement = oci_parse( $connection,
                "begin :ret := AVERAGE_BOOK_PAGES(); end;");
        oci_bind_by_name($statement, ':ret', $r, 100);
        oci_execute($statement);
        return $r;
    }
}
?>

The last parameter of oci_bind_by_name is the number of bytes to allocate for returning the string representation of the bind variable. Just make sure that you allocate enough memory for that. My test data yield an average of 762,666666666666666666666666666666666667 pages per book (Thank you Mr. Minasi) and so oci_execute kept giving me ORA-06502: PL/SQL: numeric or value error: character string buffer too small until I raised the value to 100.

So that does it. Now calling this from you controller code is as easy as :

<?php
class BooksController extends AppController {
    var $name = 'Books';

    ...

    function index()
    {
        $this->Book->recursive = 0;
        $this->set('books', $this->paginate());
        $this->set('averagePages', $this->Book->getAverageBookPages());
    }

    ...
}

Thursday, 7 January 2010

CakePHP: The dependent listboxes problem

Note: This example is outdated. I have a newer blog post that addresses the same issue using more up to date methods and functionality.

When creating dynamic web-sites, sooner or later you are going to face the problem of providing dependent list boxes. Imagine the case where one wishes to select a city from a list grouped by region, or a user from a group, an invoice from an order etc. Grouping things into categories is very common in real life and as far as I am concerned, it is almost always a must for your application to be able to utilize such groupings.
In CakePHP -- as far as I know -- there are two ways you can help your users pick up a value from a list of grouped items. One is to create a select box whose items are organized in selection groups sorted in some logical way. the other way in to use dependent AJAX triggered combo or list boxes where selection on the first will filter the items displayed on the second.
In this posting I will provide code that handles both cases.

The sample data

As an exercise for learning Cake, I developed a small application that manages the IT department books. Each Book belongs to a BookCategory and each BookCategory belongs to a BookCategoryGroup. Reversely, each BookCategoryGroup has many BookCategory and each BookCategory has many Book. The corresponding tables have foreign keys adhering to the CakePHP conventions, so I am not going to waste any more time explaining the data structure.
The goal here is to help our users, when adding or editing book records, to find the right category for each book given the organization of book categories in book category groups. Like I said in the introduction there are two ways we can accomplish this

One combo box organized in selection groups

The way is very easy to implement and may become particularly handy whenever the total number of list items is relatively small. Cake's Form::imput method will create option groups if the array containing the options for a select box is organized into sub arrays so if we add the following function in our BooksController ....
    private function prepareCategoriesCombo()
    {
        // gain access to the BookCategoryGroups model class
        $this->loadModel('BookCategoryGroup');
        // prepare a list of all book category groups
        $this->BookCategoryGroup->recursive = 0;
        $bookCategoryGroups = $this->BookCategoryGroup->find(
                                'all',
                                array(
                                    'conditions' => array(),
                                    'order' => array('BookCategoryGroup.name')
                                )
                            );

        // create an empty array to hold the combo box options
        $bookCategories = array();
        foreach( $bookCategoryGroups as $bookCategoryGroup) {
            $groupId = $bookCategoryGroup['BookCategoryGroup']['id'];
            $groupName = $bookCategoryGroup['BookCategoryGroup']['name'];
            // create a sub array for each group category
            $bookCategories[] = $groupName;
            // fill the array with the categories corresponding to the group
            $bookCategories[$groupName] = $this->Book->BookCategory->find(
                                'list',
                                array (
                                    'conditions' => array(
                                        'BookCategory.book_category_group_id' => $groupId
                                        ),
                                    'order' => array(
                                        'BookCategory.name'
                                        )
                                )
                                    );
        }
        return $bookCategories;
    }
Supposing that you have baked your original controller and view code with the cake script, your add() or edit() controller actions need to have the following in order to use the option grouped combo:
   ...
   $bookCategories = $this->prepareCategoriesCombo();
   ...
while the view template will require no change at all (i.e. a simple echo $form->input('book_category_id'); will suffice). As I said earlier on, this method is simple enough and unless you intent to let your users pick a US zip code organized by state, this may be the preferred solution for many cases. If however you have lots of data and an untamable desire for ajax, read on; fear not however CakePHP's approach to AJAX makes this look also like a piece of cake.

The AJAX way: Two combos with one auto filtering the other

The basic idea behind AJAX is the following: You start by defining an area in you web page identifiable via the the HTML id attribute. Then when the user clicks on a button or changes the value of some control (edit, list or combo), you make an asynchronous call to the web server -- that is without having to reload the page -- and the server returns HTML code that is ready to be placed inside that area. The actual way you implement this depends on the libraries and the AJAX framework you use. Cake does that using the prototype and the Scriptaculus frameworks.
So to get things started, download prototype and scriptaculus and place the following files in your APP/webroot/js folder:
builder.js   dragdrop.js  prototype.js      slider.js  unittest.js
controls.js  effects.js   scriptaculous.js  sound.js
Having done that, modify you application layout in order to include them. Open APP/view/layouts/default.ctp and change the HTML head part so it looks like this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>
      <?php echo $title_for_layout; ?>
    </title>
    <?php echo $html->css('it-library'); ?>
    <meta name="Generator" content="Quanta Plus" />
    <meta name="Author" content="Thanassis Bakalidis" />
    <?php if (isset($javascript)) : ?>
      <?php echo $javascript->link('prototype.js'); ?>
      <?php echo $javascript->link('scriptaculous.js'); ?>;
    <?php endif; ?>
    <?php echo $scripts_for_layout; ?>
  </head>
The next thing to do is to modify our controller in order to provide Javascript and AJAX support: Our books controller now looks like the following:
class BooksController extends AppController {

    var $name = 'Books';
    var $helpers = array('Html', 'Form', 'Javascript', 'Ajax');
    var $components = array('RequestHandler');

    ...
}
Next go to your view template -- may that be the add or edit.ctp -- and change the initial echo $form->input('Book.book_category_id'); line in order to look like the following:
        // here are the two list boxes displaying groups and categories
        // aim is to create an auto-filter effect with AJAX
        echo $form->label( 'BookCategory.book_category_group_id',
                            'Category Group');
        echo $form->select('BookCategory.book_category_group_id',
                            $bookCategoryGroups,
                            $bookCategoryGroupId,
                            array(
                                'id' => 'bookCategoryGroups'
                            ),
                            FALSE);
        echo $form->input('Book.book_category_id', array('id' => 'bookCategories' ));

        // each time the bookCategoryGroups element changes we are to
        // asynchronously call the updateSelect action of the current 
        // controller and insert whatever the action produces inside the 
        // html DOM element identified by bookCategories
        $ajaxOptions = array('url' => 'updateSelect','update' => 'bookCategories');
        echo $ajax->observeField('bookCategoryGroups',$ajaxOptions);
I believe that the code is self explanatory. Now let us add the updateSelect method of the BooksController class
    function updateSelect()
    {
        $groupId = $this->data['BookCategory']['book_category_group_id'];
        if (!empty( $groupId )) {
            $options = $this->getBookCategoriesForGroup( $groupId);
            // these are the combo box options to be used in the view file
            $this->set('options',$options);
        }
    }
There is one thing to mention here: the AJAX code produced by observeField() serializes the entire field that is supposed to observe, so this will be available in the controller action as $this->data['Model']['field'].
Next we need to create the actual view code. Create a file named update_select.ctp inside your APP/views/books directory and place the following code inside (Thanks HerbCSO):
<?php
    // create  tags coming from a $options variable
    // This is to be used by AJAX in order to fill the contents of a combo
    // box
    if(!empty($options)) {
        foreach($options as $key => $value) {
             echo "<option value=\"$key\">$value</option>";
        }
    }
?>
Now we have everything in place. The only thing left to do is to initialize the two combo boxes so that they contain the correct data, i.e. all the group categories for the top combo and the categories for the selected records category group on the second, during initial page load. To achieve this I have created two additional functions in the BooksController class:
    private function getBookCategoriesGroups()
    {
        $this->loadModel('BookCategoryGroup');
        $this->BookCategoryGroup->recursive = 0;
        return $this->BookCategoryGroup->find('list',
                                                array(
                                                    'conditions' => array(),
                                                    'order' => array(
                                                        'BookCategoryGroup.name'
                                                        )
                                                )
                                            );
    }

    private function getBookCategoriesForGroup( $groupId)
    {
        return $this->Book->BookCategory->find('list',
                                array(
                                    'conditions' => array (
                                        'book_category_group_id' => $groupId
                                        ),
                                    'order' => array(
                                            'BookCategory.name'
                                        )
                                )
                            );
    }
Now my controller's edit action -- which as I mentioned earlier, was baked by cake -- looks like the following.
    function edit($id = null)
    {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid Book', true));
            $this->redirect(array('action'=>'index'));
        }
        if (!empty($this->data)) {
            if ($this->Book->save($this->data)) {
                $this->Session->setFlash(__('The Book has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Book could not be saved. Please, try again.', true));
            }
        }

        if (empty($this->data)) {
            $this->data = $this->Book->read(null, $id);
        }

        // set up additional book record parameters
        $sites = $this->Book->Site->find('list');
        $bookTypes = $this->Book->BookType->find('list');
        $languages = $this->Book->Language->find('list');

        // setup the two AJAX operated combo boxes
        $bookCategoryGroups = $this->getBookCategoriesGroups();                
        $bookCategoryGroupId = $this->data['BookCategory']['book_category_group_id'];
        $bookCategories = $this->getBookCategoriesForGroup( $bookCategoryGroupId);

        $ratings = $this->Book->Rating->find('list');
        $publishers = $this->Book->Publisher->find('list');

        $this->set( compact( 'sites','bookTypes','languages',
                             'bookCategories', 'bookCategoryGroups', 'bookCategoryGroupId',
                             'ratings','publishers'));
    }
Needless to say that when adding a record, the initial $bookCategoryGroupId can be set to an initial value say 1 and then let your uses change to whatever seems appropriate.
I have tested this with CakePHP 1.2.5 on both Firefox (versions 3 and 3.5) and IE (version 8).
As a last statement, I would like to point out that I am by no means an expert on AJAX or CakePHP. I got my info from an earlier posting by DEVMOZ and the CakePHP AJAXHelper class info page. I have put this down as a working reference to a real problem, that anybody can copy -- hopefully -- easy to modify code.

Wednesday, 16 December 2009

CakePHP and Oracle on CentOS. My own how to guide

During the last couple of days I formated and set up from scratch my CakePHP development server, using CentOS, php 5.3 from Remi and the Oracle 11gR2 clients. The log of my actions in PDF can be downloaded from here.

During the following days I will setup one more server -- supposed to be the one that we will use productively -- following these same instructions. If I find any mistakes I will correct them and post back the orginal file here.

Update history

  • Dec-28-2009: Added information about setting up and running the cake scripts from the command line.
  • Jan-21-2010: Verified contents on a new installation and added reminder for configuring the firewall.

Tuesday, 15 December 2009

CakePHP: A behavior for acessing non UTF Oracle databases

The origins of our company's Oracle database date back at the beginning of the decade. At that time we had Oracle version 9i running on SuSE Linux 8.2 and the expected thing to do back then was to create a database using the EL8ISO8859P7 character set. After eight years we are still using Oracle. Now the database is 11g and the database server is OEL 5.4. Basic data structures however, are still the same as they were back in 2002.

During the evaluation of CakePHP as our next development environment we very soon run into the problem of trying to insert and retrieve Unicode data from a non-unicode database. Since the encoding key of $defualt array member of the DATABASE_CONFIG class (stored in app/config/database.php file) has no effect when connecting to Oracle databases, we ended up creating an additional translation layer, that would convert data to and from Unicode when reading from and writing to Oracle.

CakePHP's way of doing this kind of staff is to create behaviors. Ours is called CharsetConverter, so by CakePHP's standards it is implemented in a class named CharsetConverterBehavior that is stored in a file named charset_converter.php which is located in the APP/models/behaviors directory.

The approach here uses the mb_convert_encoding function provided with the php-mbstring package. The code implementation is the following

<?php
/**
 * A simple behavior that allows cake PHP to use single byte Oracle
 * and possibly other vendor -- databases
 * Tested with Oracle 11gR1
 *
 * @version 0.1
 * @author Thanassis Bakalidis
 */
class CharsetConverterBehavior extends ModelBehavior {
    // we have an Oracle database that dates back to 2002 so
    const DEFAULT_DB_LOCALE = 'ISO-8859-7';
    const DEFAULT_PAGE_LOCALE = 'UTF-8';

    const READING_FROM_DB = TRUE;
    const WRITING_TO_DB = FALSE;

    var $databaseLocale;
    var $webpageLocale;
    var $Model;

    function setup(&$model, $settings=array())
    {
        $this->Model = $model;

        $this->databaseLocale = isset($settings['databaseLocale']) ?
                                    $settings['databaseLocale'] :
                                    self::DEFAULT_DB_LOCALE;
        $this->webpageLocale = isset($settings['webpageLocale']) ?
                                    $settings['webpageLocale'] :
                                    self::DEFAULT_PAGE_LOCALE;
    }

    /**
     * Change the query where clause to the datbase native character set.
     */
    function beforeFind( &$queryData, $queryParams)
    {
        if (!isset( $queryParams['conditions']))
            return $queryParams;

        $queryParams['conditions'] = $this->recodeRecordArray(
                                                        $queryParams['conditions'],
                                                        self::WRITING_TO_DB);
        return $queryParams;
    }

    /**
     * Convert fetched data from single byte to utf-8
     */
    function afterFind(&$model, $results, $primary)
    {
        return $this->recodeRecordArray($results, self::READING_FROM_DB);
    }

    /**
     * Convert data to be saved into the database speciffic locale
     */
    function beforeSave()
    {
        $this->Model->data = $this->recodeRecordArray( $this->Model->data,
                                                       self::WRITING_TO_DB);
        return true;
    }

    /**
     * Recursively traverse and convert the encoding of the array passed
     * as parameter.
     */
    function recodeRecordArray(&$recordArray, $loading = TRUE)
    {
        foreach( $recordArray as $key => $value)
            if (is_array($value))
                $recordArray[$key] = $this->recodeRecordArray($value, $loading);
            else {
                if (is_numeric($value))
                    continue;
                $recordArray[$key] = $loading ?
                                    mb_convert_encoding(
                                                $value,
                                                $this->webpageLocale,
                                                $this->databaseLocale)
                                    :
                                    mb_convert_encoding(
                                                $value,
                                                $this->databaseLocale,
                                                $this->webpageLocale);
            }
        return $recordArray;
    }
}
?>

Once we have this in place, using the new behavior in one of our models is as simple as setting the correct value of the $actAs variable. Here is a simple example of a model using the Character set convention and validation.

<?php
    class Task extends AppModel {
        var $name = 'Task';
        var $actsAs = array(
                    'CharsetConverter' => array(
                                            'databaseLocale' => 'ISO-8859-7',
                                            'webpageLocale' => 'UTF-8'
                                        )
                    );
        var $validate = array(
                    'title' => array(
                                'rule' => 'notEmpty',
                                'message' => 'Task title cannot be left blank'
                    )
                );
    }
?>

Almost all applications contain more than one model. Perhaps the best place to put the $actAs definition would be the AppModel class defined in the file app_model.php in the root of your app directory

I also understand that writing a behavior to accomplish the job of the database driver is not the best solution. Since I have nothing better for the moment, I guess I will have to start every new CakePHP project by first changing my app_model.php file.

Tuesday, 1 December 2009

How to set up the SAPRFC extension for PHP on CentOS 5

SAPRFC

SAPRFC is an extension module for PHP 4 and 5, that makes it possible to call ABAP function modules running on a SAP R/3 system from PHP scripts.

I always wanted to test how SAP's remote function calls work together with PHP and since I am already evaluating CakePHP as our next development platform, I decided that the occasion was right to give it a try.

Next thing I did was to get my hands on The SAP Developer's Guide to PHP book by Craig S. Cmehil, which is an $85 cost and 98 page long (indexes included) tutorial on how to set up and use SAPRFC for PHP. Unfortunately the second chapter that discusses setting up your development system focuses mainly on Windows, so this post will contain the steps I took to set up SAPRFC for PHP on my x86_64 CentOS 5.4 server.

Package Requirements and Downloads

To get the latest PHP packages for Enterprise Linux I have used Remi's repository.

# wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm

Remi's packages depend on the EPEL repository, so I am posting the installation procedure for EPEL as well. (if you haven't installed it yet, now will be a good time to do so.)

In addition to any other PHP packages that your application requires, in order for the SAPRFC to compile correctly, you will also require the php-devel package.

Next thing is the SAPRFC package itself. The method to install it will be to build the saprfc extension as a dynamic module without rebuilding PHP. (Remi has already done that for us.) The package itself can be downloaded from here.

Continue by installing SAP's Non Unicode RFC SDK version 6.20 or 6.40. This must be downloaded directly from the SAP Service Support Portal. You will need a customer SAP support ID

Be advised however, that SAP has implemented some form of a DNS transparent cluster for their WEB service, so each time you log in there, you end up accessing a server with a different DNS name (something like https://websmp104.sap-ag.de/support). That means that your browser will not be able to store your credentials because every time you attempt to connect to https://service.sap.com/support, the DNS name changes so it pops up a dialog asking for login data again and again... Perhaps this is SAP's way of implementing the ultimate security system but, as far as I can say it is very annoying.

Anyway, once you are there select "Download" from the top menu. Next click "Search on all categories" from the left menu and enter RFC SDK on the search box that appears. You will be given the chance to select SAP RFC SDK 6.40 from the results page. Be careful not to choose the UNICODE version. Select Linux on x86_64 64bit from the list of architectures and you will end up with an SAR file in your download basket. Now you can download it

There is one more problem though. The file you download is of type SAR. meaning SAP Archive. In order to unpack it you will need SAPCAR, SAP's unpacking program. You download this the same way you downloaded RFCSDK -- just type SAPCAR on the search box. Only thing is that the Linux x86_64 version does not run on CentOS. You will need to download a Windows version, unpack the archive on a Windows machine and then upload it again on you Linux system. At least that is what I had to do. (From what I was able to understand SAP's SAPCAR for Linux is compiled to run under SuSE, so if you have satch a machine, you can try unpacking the archive over there...)

Installation

So now let's assume that you have placed SAP's RFC SDK under /opt/SAP/rfcsdk and SAPRFC extention module for PHP under /usr/src/saprfc-1.4.1/. Type the following commands on your shell prompt or add them at the end of your startup file. (I put them in /etc/profile.)

# SAP RFC SDK
export SAPRFC_DIR=/opt/SAP/rfcsdk/
export PATH=$SAPRFC_DIR/bin:$PATH

If necessary, log out and back in again. Now move to the SAPRFC extension for PHP directory and issue the phpize command. This will create the configure script that needs to be run next. After configure completes, run make and make install (as root) to finish installation. When everything finishes the file saprfc.so will be placed in your /usr/lib64/php/modules folder. Open you php.ini file located in /etc and add a line line

extension=saprfc.so

in the Dynamic Extensions section, save it, restart http server and you are ready to go.

[root@barbara ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Verification and testing

The very first check will be as simple as looking at the saprfc section of your phpinfo() page. You should be seeing something like :

The next thing will be to write an actual program that does something more practical like connecting to an SAP R/3 system and fetching back some useful data. Since this already a rather lengthy post, I will prepare and provide a test program some time later.

One last comment: It took me a while to figure that out. All examples that come along with the SAPRFC module for PHP, as well as the examples on the "SAP Developer's Guide to PHP" book, use <? instead of <?php to introduce php code. This is going to give you a lot of trouble when attempting to use these files with php 5.3.1 so before trying anything else, go to the files in the installation directory -- especially saprfc.php that you will always include -- and perform the necessary changes.

Friday, 27 November 2009

Enterprise class hardware for Enterprise class software

We wanted to set up a portable LAMP server for a home project we are playing with and there it is :

Since the little monster uses two SD cards as hard drives, it takes around four minutes to boot, but once it does boot, then its 900MHz Celeron CPU with its 1GB of RAM can stand up against a multi-threaded Java program gathering information from the local Ethernet and a complete Apache, PHP and MySQL server accessed for reporting.

Only thing is that the book is almost three times thicker than the machine.

Thursday, 26 November 2009

SAP: All the little text tables

Even after 5 years of tampering with ABAP, I still have problems getting used to the way SAP name their production tables. All those four letter German abbreviated names are explanatory enough to scare away any newcomer. Even the English descriptive texts that SAP provides along with each object are so Spartan, that I very seldom can make any good use out of them.

Luckily enough, I have just the right person available who seems to know all the four -- or five -- letter permutations that yield SAP table and field identifiers. (Thanks again Marilena), so today I am going to steal a few of her knowledge and give us code fragments that show how to get descriptive texts for various material and production related key's like material names, groups, blocking statuses, MRP controllers, etc.

We will start with the names of storage locations. The field and the data type for those are named lgode. The table that stores related info is t001l.

   DATA :
     storage_location TYPE lgort_d, 
     storage_location_name TYPE lgobe.

    " storage_location = '...'.
    SELECT SINGLE lgobe
      INTO storage_location_name
      FROM t001l
      WHERE lgort = storage_location.

The next one is easy. Even I know by heart how to get the material description given the material number, but I will put it down anyway. The thing to mention however, is that most SAP text tables are language dependent, so to get the text for the key, you also need to specify the language

    DATA :
      material TYPE matnr,
      material_descr TYPE maktx.

    " material = '...'.
    SELECT SINGLE maktx
      INTO material_descr
      FROM makt
      WHERE matnr = material
        AND spras = sy-langu.

Material types are stored in table t134t which is also language dependent.

    DATA :
      material_type TYPE mtart,
      material_type_descr TYPE mtbez.

    " material_type = '...'.
    SELECT SINGLE mtbez
      INTO material_type_descr
      FROM t134t
      WHERE mtart = material_type
        AND spras = sy-langu.

Our next table is t141t, that stores the various texts for the material blocking statuses.

    DATA :
      mat_blocking_status TYPE mstae,
      mat_blocking_status_descr TYPE mstb.

 " Material blocking status descriptions
    SELECT SINGLE mtstb
      INTO mat_blocking_status_descr
      FROM t141t
      WHERE mmsta = mat_blocking_status
        AND spras = sy-langu.

We wil now move to the inspiringly named t023t table, that provides access to the short and long names of material groups.

    DATA :
      material_group TYPE matkl,
      mat_group_short_descr type wgbez,
      mat_group_long_descr TYPE wgbez60.
    
    " material_group = "...".
    SELECT SINGLE wgbez wgbez60
      INTO (mat_group_short_descr, mat_group_long_descr)
      FROM t023t
      WHERE matkl = material_group
        AND spras = sy-langu.

Product hierarchy descriptions are found in in t179t.

    DATA :
      mat_hierarchy TYPE prodh_d,
      mat_hierarchy_descr TYPE vtext.

    " mat_hierarchy = '...'.
    SELECT SINGLE vtext
      INTO mat_hierarchy_descr
      FROM t179t
      WHERE prodh = mat_hierarchy
        AND spras = sy-langu.

Table t438t stores MRP type descriptions.

    DATA :
      mrp_type TYPE dismm,
      mrp_type_descr TYPE disbez.

    SELECT SINGLE dibez
      INTO mrp_type_descr
      FROM t438t
      WHERE dismm = mrp_type
        AND spras = sy-langu.

Last table for today's post will be t024d. this one contains MRP Controller descriptions and is not language but plant organized.

    DATA :
      plant TYPE werks_d,
      mrp_controller type idspo,
      mrp_controller_descr TYPE disnam.

    SELECT SINGLE dsnam
      FROM t024d
      INTO mrp_controller_descr
      WHERE dispo = mrp_controller
        AND werks = plant.

... and that is enough for one day.

Thursday, 12 November 2009

The CakePHP manual in PDF

if anybody wants a PDF version of the entire CakePHP manual as it appears in http://book.cakephp.org/, the book is available from here.

I created this document by copying and pasting text from the book website into an OpenOffice text document, because I wanted to have something to print and browse like a normal book. I have also added a few Oracle specific instructions. It is therefore possible, that some things may have slipped me. I will try and change this document every time I find an error or add a correction. Please feel free to post any mistakes you may find.

Last uploading: January 5-2010

Saturday, 31 October 2009

How to split a music file (flac, wv ...) when given the corresponding .cue file.

This is the second time I needed to do this, so instead of googling again, I thought that I may post it here for future reference .....

Thanks to fl_bulgarelli from the Fedora Forum here is a small how to, when somebody gives you a complete album encoded in flac and a the corresponding .cue file, while what you want is to be able to split the album into smaller music files corresponding to the songs.

The magic command is:
cuebreakpoints album.cue | shnsplit -o flac album.flac
or
cuebreakpoints album.cue | shnsplit -o wv album.wv if you are using a wavpak file.

More details about how to set this up, can be found here. For the shake of completeness I will add that as of this writing (August 20th 2011) both the cuetools and shntool packages are available from the main fedora repository, so a simple yum install shntool cuetools, will work just fine. For Ubuntu, Mint etc try sudo apt-get install cuetools.

NOTE: For those with a bad attitude towards typing sh commands, try opening the .cue file with k3b. A few clicks and (perhaps) a visit to your distro's Add/remove Software application might get you to splitting your flac file as well :).

Tuesday, 29 September 2009

Fedora: Using and authenticating yum through a proxy

I have just finished a Fedora 11 installation here at the office. We needed a test bed for working with symfony and our EL machines did not provide php 5.2.

Next thing was to update the new machine and install additional software and that meant being able to go through a squid proxy server, that requires authentication.

A little bit of digging and the magic man yum.conf revealed the following :

Edit /etc/yum.conf and add the following lines:

proxy=http://proxy.domain.local:port
proxy_username=your_user_name
proxy_password=your_password

Needless to say that the same configuration works perfectly on CentOS 5.4 ...

When your machine is behind a proxy then, in order for many other programs -- like wget -- to function correctly, you also need to export the http_proxy variable. The correct format for it is :

export http_proxy=http://username:password@proxy.domain:port

Friday, 11 September 2009

Javascript : Yet an other email address validator.

I was building a Conduct us page the other day and run into the need for a JavaScript e-mail validator. I googled around a bit only to discover that the approaches were so many that I didn't know which one to choose.

So, eventually I did what every hard headed person would do, I sat down amd wrote my own validateEmail function. The code is a merge of ideas coming from the fifth edition of Tom Mergino's and Dori Smith's JavaScript for the World Wide Web, and Anita Sudhakar's approach from SmartWebby.

The resulted code looks like the following :

function validateMail(str)
{
  var at = "@";
  var dot = ".";
  var atPos = str.indexOf(at);    // position of '@' in the string
  var stringLength = str.length;  // position of '.' after the '@'
  var dotPos = str.indexOf(dot, atPos);
  var invalidChars = "~`/!#$%^&*()+={}[];:";
  var i;
  var badChar;

  // Step 1 Do not allow blank emails
  if ( str == "")
    return false;

  // Step 2 Make sure that the address does not contain invalid characters
  for (i = 0; i < invalidChars.length; i++) {
    badChar = invalidChars.charAt(i);
    if (str.indexOf( badChar) > -1)
      return false;
  }

  // Step 3: Make sure that the @ character is present and
  // that is not the first or the last character of the
  // email address string.
  if (atPos == -1 || atPos == 0 || atPos == stringLength)
     return false;

  // Step 4: Likewise make sure that a dot character exists and that
  // the distance between the @ and . is at least two characters apart
  if (dotPos == -1 || dotPos + 3 > stringLength)
      return false;

  // we have passed all tests let's hope that the email is valid
  return true;
}

The function should be called from an other function that will retrieve that value of an email filed and test it during form submit. A typical usage would be :


function validateEmailField( fieldID)
{
  var emailField = document.getElementById( eMailFieldID);
  var status = false;

  if (validateMail(emailField.value))
    status = true;
  else
    alert('Invalid email!');
  
  return status;
}

Friday, 4 September 2009

Windows: The ultimate way to get rid of stuck print jobs.

Sometimes print jobs get stuck for good. Users try to delete them and then the entire queue gets stuck too. I have many times tried to find a remedy for that and even attempted to reboot the Windows server in question without always achieving the desired result. Lately, my eyes were opened by a friend who showed me they way by following the steps shown below.

  1. Stop the Print Spooler service.
  2. Delete all files from %SystemRoot%\system32\spool\PRINTERS/.
  3. Start the Print Spooler Service again.

... and that does it.

Wednesday, 2 September 2009

Windows: Shutting down machines remotely

I have many times heard people complain about Windows machines freezing or being very slow to respond. The problem sometimes is so bad that not even the desktop user is able to close frozen applications or even shutdown her own machine. The remedy for 99% of all these cases, thank you Microsoft, -- as Mark Minasi would have said -- is the notorious shutdown command.

This posting will contain a brief overview of the command syntax. This command has been around since the days of Windows NT4 but Microsoft has changed it and now in Windows 2003 environments the arguments are not the same

So, to begin with the oldest version for those of us still stuck with NT4, the syntax for this platform is like this

shutdown \\machine_name /r /t:10 "Machine is going down in 10 seconds" /y /c

You can also use the /l switch to force a local shutdown. The /c, shown above, is very useful since it forces all running applications to close. The -t:N will display a message notifying the user that their machine is going down in N seconds. Here you can also provide an additional string explaining the reasons for the reboot, enclosed in double quotes. Finally if you forget the /r then the machine will just shutdown and then you 'll have to walk over there and power it down -- remember, this is NT4 we 're talking about -- and then up yourself. If after all you change your mind and you decide that the machine does not need to reboot, then -- if there is still enough time left -- use the command shutdown \\machine_name /A to abort the shutdown process.

Now with Windows 2003 the shutdown command has changed quite a bit. The equivalant command to shutdown a remote system now looks like this:

shutdown /r /m \\machine_name /t 10 /f /c "Machine is going down in 10 seconds"

The order of the arguments is significant. The /r switch can be replaced with /s to shutdown or /a to abort a shutdown in progress. The /t and the time interval are now separated by a space instead of a column ':' character. The /c switch now introduces the message for the shutdown reason and finally /f is now used to force closing of all running applications.

Shutdown for Windows 2003 has also an additional /d [p:]xx:yy switch that allows you to specify a coded reason for the shutdown, in exactly the same way you do when shutting down a Windows 2003 server via the GUI. The shutdown help screen provides detailed code listings about the meaning of each code. I never use them from the command line, so my most often issued command looks like this :

shutdown /r /m \\pc-bakalidis /t 0 /f 

Tuesday, 1 September 2009

CentOS: Problems updating python

I have been running into the same problem while trying to update my 5.3 CentOS machine.

Yum reported three packages that needed update :

 java-1.6.0-openjdk     x86_64     1:1.6.0.0-1.2.b09.el5      updates      27 M
 libxml2-python         x86_64     2.6.26-2.1.2.8             updates     713 k
 python                 x86_64     2.4.3-24.el5_3.6           updates     5.9 M

When yum update was issued however, the same error message kept popping up.

--> Missing Dependency: /usr/lib64/python2.4 is needed by package
libxslt-python-1.1.17-2.el5_2.2.x86_64 (installed)

I tried disabling almost all my repositories, I removed many packages, almost ended up un-installing half my entire and then I googled on it. As always,, the answer was right there in front of me. Frank Cox wrote on the CentOS mailing list:

yum clean all
yum update

And that works. Thank you Frank.

Friday, 12 June 2009

Linux: Safely deleting .rpmnew files

Just got on my hands on the new Fedora 11 today. I have to admit that I didn't get a chance to explore all the new things that Leonidas has brought along.

For starters, the feature that amazed me was the preupgrade script that magically downloaded everything, installed it and even changed my repos to point to correct ones for Fedora 11. And when I say repos, I do not mean only the basic ones, but also livna and RPM Fusion.

So the next thing that I had in my mind was to check all the .rpmnew files installed in my system and determine what was needed, so I started doing a search with a command like find / -name *.rpmnew -print, I ended up using diff and deleting the .rpmnew file that was identical to the original.

After comparing /usr/share/config/colors/Royal.colors.rpmnew, /usr/share/config/colors/40.colors.rpmnew, /usr/share/config/colors/Web.colors.rpmnew and /usr/share/config/colors/Rainbow.colors.rpmnew with their original versions and deleting all four of them, I decided that a little script could save me quit a lot of trouble. So after a little bit of digging I ended up with the following code:

#!/bin/bash

# Locate all *.rpmnew files in your system and compares them with the 
# original files without the rpmnew extention. 
# Files are then compared using diff. If their contents are the same, then
# the .rpmnew version is removed.

RPM_NEW_LIST=`find / -name "*.rpmnew" -print 2>/dev/null`

for RPMNEW_FILE in $RPM_NEW_LIST
do
    # Get the file without the .rpmnew extention
    ORIGINAL_FILE=${RPMNEW_FILE%".rpmnew"}
    # Compare it with the original
    DIFFERENT=`diff $RPMNEW_FILE $ORIGINAL_FILE`
    # If diff's answer is not empty ...
    if [ -n "$DIFFERENT" ]; then
        echo "Please examnine files $ORIGINAL_FILE and $RPMNEW_FILE "
    else
        # File is safe to remove
        # rm -f -v $RPMNEW_FILE
        echo "$RPMNEW_FILE file can safely be removed." 
    fi
done

I run this script as root on both my Fedora and CentOS 5.3 machines The simple version I have here will show you the files that are safe to delete and the files need your attention. If you like, you can uncomment the rm -fv line at the end of the script, but I would strongly advice against it.

Note: Sometimes rpm leaves out .rpmsave files as well so, if you are really into cleaning up your system, it is wise to search for these files also.