Friday 25 February 2011

Getting Started with WordPress 3

This article will guide you through the process of setting up WordPress and customizing its basic features. You can choose between a couple of options regarding where your WordPress installation will live. Keep in mind that WordPress is relatively small (under 10 MB), easy to install, and easy to administer.

In this article, you will learn how to:

* Create a free blog on WordPress.com
* Install WordPress manually on your web host


WordPress is available in easily downloadable formats from its website, http://wordpress.org/download/. WordPress is a free, open source application, and is released under GNU General Public License (GPL). This means that anyone who produces a modified version of software released under the GPL is required to keep those same freedoms, that people buying or using the software may also modify and redistribute, attached to his or her modified version. This way, WordPress and other software released under GPL are kept open source.

Where to build your WordPress website

The first decision you have to make is where your blog is going to live. You have two basic options for the location where you will create your site. You can:
  • Use WordPress.com
  • Install on a server (hosted or your own)
Let's look at some of the advantages and disadvantages of each of these two choices.
The advantage of using WordPress.com is that they take care of all of the technical details for you. The software is already installed; they'll upgrade it for you whenever there's an upgrade; and you're not responsible for anything else. Just manage your content! The big disadvantage is that you lose almost all of the theme and plugin control you'd have otherwise. WordPress.com will not let you upload or edit your own theme, though it will let you (for a fee) edit the CSS of any theme you use. WordPress.com will not let you upload or manage plugins at all. Some plugins are installed by default (most notably Akismet, for spam blocking, and a fancy statistics plugin), but you can neither uninstall them nor install others. Additional features are available for a fee as well.
The following table is a brief overview of the essential differences between using WordPress.com versus installing WordPress on your own server:

WordPress.com Your own server
Installation You don't have to install anything, just sign up Install WordPress yourself, either manually or via your host's control panel (if offered)
Themes Use any theme made available by WordPress.com Use any theme available anywhere, written by anyone (including yourself)
Plugins No ability to choose or add plugins Use any plugin available anywhere, written by anyone (including yourself)
Upgrades WordPress.com provides automatic upgrades You have to upgrade it yourself when upgrades are available
Widgets Widget availability depends on available themes You can widgetize any theme yourself
Maintenance You don't have to do any maintenance You're responsible for the maintenance of your site
Advertising No advertising allowed Advertise anything

Using WordPress.com

WordPress.com (http://wordpress.com) is a free service provided by the WordPress developers, where you can register a blog or non-blog website easily and quickly with no hassle. However, because it is a hosted service, your control over some things will be more limited than it would be if you hosted your own WordPress website. As mentioned before, WordPress.com will not let you edit or upload your own themes or plugins. Aside from this, WordPress.com is a great place to maintain your personal site if you don't need to do anything fancy with a theme. To get started, go to http://wordpress.com, which will look something like the following:
WordPress 3 Complete
To register your free website, click on the loud orange-and-white Sign up now button. You will be taken to the signup page. In the following screenshot, I've entered my username (what I'll sign in with) and a password (note that the password measurement tool will tell you if your password is strong or weak), as well as my e-mail address. Be sure to check the Legal flotsam box and leave the Gimme a blog! radio button checked. Without it, you won't get a website.
WordPress 3 Complete
After providing this information and clicking on the Next button, WordPress will ask for other choices (Blog Domain, Blog Title, Language, and Privacy), as shown in following screenshot. You can also check if it's a private blog or not. Note that you cannot change the blog domain later! So be sure it's right.
WordPress 3 Complete
After providing this information and clicking on Signup, you will be sent to a page where you can enter some basic profile information. This page will also tell you that your account is set up, but your e-mail ID needs to be verified. Be sure to check your inbox for the e-mail with the link, and click on it. Then, you'll be truly done with the installation.

Installing WordPress manually

The WordPress application files can be downloaded for free if you want to do a manual installation. If you've got a website host, this process is extremely easy and requires no previous programming skills or advanced blog user experience.
Some web hosts offer automatic installation through the host's online control panel. However, be a little wary of this because some hosts offer automatic installation, but they do it in a way that makes updating your WordPress difficult or awkward, or restricts your ability to have free rein with your installation in the future.

Preparing the environment

A good first step is to make sure you have an environment setup that is ready for WordPress. This means two things: making sure that you verify that the server meets the minimum requirements, and making sure that your database is ready.
For WordPress to work, your web host must provide you with a server that does the following two things:
  • Support PHP, which must be at least Version 4.3.
  • Provide you with write access to a MySQL database. MySQL has to be at least Version 4.1.2.
You can find out if your host meets these two requirements by contacting your web host. If your web server meets these two basic requirements, you're ready to move on to the next step.
As far as web servers go, Apache is the best. However, WordPress will also run on a server running the Microsoft IIS server (though using permalinks will be difficult, if possible at all).
Enabling mod_rewrite to use pretty permalinks
If you want to use permalinks, your server must be running Unix, and Apache's mod_rewrite option must be enabled. Apache's mod_rewrite is enabled by default in most web hosting accounts. If you are hosting your own account, you can enable mod_rewrite by modifying the Apache web server configuration file. You can check the URL http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache to learn how to enable mod_rewrite on your web server. If you are running on shared hosting, then ask your system administrator to install it for you. However, it is more likely that you already have it installed on your hosting account.

Downloading WordPress

Once you have checked out your environment, you need to download WordPress from http://wordpress.org/download/. Take a look at the following screenshot in which the download links are available on the right side:
WordPress 3 Complete
The .zip file is shown as a big blue button because that'll be the most useful format for the most people. If you are using Windows, Mac, or Linux operating systems, your computer will be able to unzip that downloaded file automatically. (The .tar.gz file is provided because some Unix users prefer it.)
A further note on location We're going to cover installing WordPress remotely. However, if you plan to develop themes or plugins, I suggest that you also install WordPress locally on your own computer's server. Testing and deploying themes and plugins directly to the remote server will be much more time-consuming than working locally. If you look at the screenshots I will be taking of my own WordPress installation, you'll notice that I'm working locally (for example, http://wpbook:8888/ is a local URL).
After you download the WordPress .zip file, extract the files, and you'll get a folder called wordpress. It will look like the following screenshot:

WordPress 3 Complete

Uploading the files

Now, we need to upload all these files to our web server using any FTP client (or simply put them in our local server directory on our local computer). FTP stands for File Transfer Protocol. There are several FTP clients available on the Internet, which are either freeware (no cost) or as shareware (a small fee). If you don't already have an FTP client, try one of these:
You can also use the popular web-based FTP application net2ftp at http://www.net2ftp.com. These services are useful if you don't want to install a desktop application on your computer. You can also check if your host provides browser-based FTP software.
In my screenshots you'll see that I'm using Transmit, which is the professional FTP software I use on my Mac. It works the same way as the examples above.
A note about security: whenever possible, you should use Secure FTP (called sFTP) rather than regular FTP. If you're using sFTP, all of the data sent and received are encrypted, whereas with FTP, data are sent in plain text and can be easily nabbed by hackers. Check both your FTP software and your hosting options, and select sFTP if it's available.
Using your FTP client or service, connect to your FTP server using the server address, username, and password provided to you by your host. Next, open the folder where you want WordPress to live. You may want to install WordPress in your root folder, which will mean that visitors will see your WordPress website's home page when they go to your main URL—for example, http://yoursite.com. Alternatively, you may want to install WordPress in a subfolder; for example: http://yoursite.com/blog/.
On the left side, you will see the files from your local folder, and on the right side you will see your remote folder. (Note: the FTP client you are using may have a slightly different layout, but this is the general idea):
(Move the mouse over the image to enlarge.)
Now select all of the WordPress files on your local machine from the left pane, and drag all of them to the right pane. You can watch as your FTP client uploads the files one at a time and they appear in the right panel. This could take a few minutes, so be patient!
If you're installing WordPress on your local server, just be sure to place the WordPress files in the correct webroot directory on your computer.
Once all of the files are done uploading, you're ready to do the installation.

Installing WordPress

Now it's time to install WordPress. For example, I will be working on my local server and just put brand-new WordPress files at http://wpbook:8888/. So, this is going to be the URL of my WordPress website. If you access your WordPress URL via your browser, it will look like the following:
WordPress 3 Complete
It says that you need to create a file named wp-config.php before proceeding further. WordPress (and I) recommend that you do this manually, rather than using the Create a Configuration File link. If you do choose to use the config creator, you'll need the information below as well (though there will be no opportunity for the security phrases).
Open the wordpress folder and find the file named wp-config-sample.php. Make a copy of this file and name it wp-config.php. We'll modify this file together. Don't worry; you need not be a PHP programmer. Just open this file with a simple editor such as Notepad. The following is the copied text from the original wp-config.php file. Note that I've removed most of the comments, so that we can focus on the items we need to change.
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

define('AUTH_KEY',                     'put your unique phrase here');
define('SECURE_AUTH_KEY',   'put your unique phrase here');
define('LOGGED_IN_KEY',         'put your unique phrase here');
define('NONCE_KEY',                 'put your unique phrase here');
define('AUTH_SALT',                   'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',       'put your unique phrase here');
define('NONCE_SALT',               'put your unique phrase here');

$table_prefix = 'wp_';
?>
One thing to know about PHP is that any text that comes after a double slash (//), or between a slash-star and star-slash (/* */), is a comment. It's not actual PHP code. Its purpose is to inform you what that line or that section is about.
As you can see from the previous code, there are a number of settings that you can insert here. Let's walk through the most important ones.
As I mentioned in an earlier section, you need to have write access to a database. Most large web hosts offer you a way to create your own databases, with usernames and passwords, via an online control panel. If you're not sure how to do this, just e-mail or call your hosting provider for this information. You'll need four pieces of information about your database for the WordPress configuration file. They are:
  • Database server—for example, localhost
  • Username—for example, localdbuser
  • Password—for example, 62dcx0hnm
  • Database name—for example, wpbookdb
Your database server might not be localhost. If it's not, you can ask your hosting provider, or take a look at this handy cheat sheet: http://codex.wordpress.org/Editing_wp-config.php#Possible_DB_HOST_values.
Once you have those four things, you can fill them into your wp-config.php file. For example, see how mine is filled out here:
// ** MySQL settings ** //
define('DB_NAME', 'wpbookdb');
define('DB_USER', 'localdbuser');
define('DB_PASSWORD', '62dcx0hnm');
define('DB_HOST', 'localhost');
Next, for security purposes, you really should put some unique phrases into the unique keys. The secret keys are used by WordPress to add random elements to your passwords and are also used in some other situations. This will help to keep your WordPress installation uniquely protected. No one else is likely to choose the same unique keys that you chose, and therefore, breaking or hacking into your site will be more difficult. You can get some secret keys generated by going to https://api.wordpress.org/secret-key/1.1/salt/. Once I did that, I got the following, which I can paste directly over the default code in wp-config.php:
define('AUTH_KEY', 'uu|6#00Pc/3h?Pg5:Zc#:S=;<3mdw-ai');
define('SECURE_AUTH_KEY', 'vy1.@Nr@Zb^G|0Vfz-|TH5&W');
define('LOGGED_IN_KEY', 'sryMVd`jVpiMWWQqx~!v XE5@fJMTt2[Z');
define('NONCE_KEY', 'i,+UPpMR>Mj3o}(B**^
define('AUTH_SALT', 'n.8Li=9OjV+_p|}e5yN2k
define('SECURE_AUTH_SALT', 'I#2vPT^u[5vLX|`MzPg/J*y]RTfr');
define('LOGGED_IN_SALT', 'gR%QP^c*jfFUy,iQ}-0g_%;%H)pN0B5');
define('NONCE_SALT', '&L);.IH`v{]zYLO2:h_t#J0D-p)cvyc');
The only other thing you may want to consider is the table prefix. I strongly recommend using a prefix. If you want to install WordPress more than once, you'll need to use different prefixes in your different installations. If you are using this same database for other things, it'll be handy if the tables are grouped based on what they're being used for. So either leave the following line as it is, or choose another prefix:
$table_prefix = 'wpbook_';
Learning more: The WordPress codex has a long and detailed page that describes everything about editing your wp-config.php file: http://codex.wordpress.org/Editing_wp-config.php.
Now, go back to your browser and reload the page that's pointing to your WordPress installation. If your configuration file makes sense to WordPress, you'll be taken directly to the installation page.
WordPress 3 Complete
(If you've ever installed an earlier version of WordPress, you'll notice some differences, like the ability to choose your first username and password!) Now, fill out the installation form (you will be able to change all of these later, so don't be too worried about getting locked into your choices):
  • Site title: Fill in the name of your blog (in my case it's 'Daily Cooking').
  • Username: Note that the default username is 'admin', but for security purposes, you're better off picking another username. If someone ever tries to hack your blog, they will be halfway there if they already know your username. I've chosen 'ahsilver'.
  • Password: Choose a secure password, one that has both upper and lowercase letters, a number or two, and even a few punctuation marks.
  • Your E-Mail: Double-check that this is correct, because this is the e-mail address WordPress will use to contact you about the blog, comments, and so on. If you do not get an e-mail from your WordPress site shortly after installing, check your spam folder.
Now, click on Install WordPress. You're done with the install!
WordPress 3 Complete
You can click on Log In to get to the login page. Or you can always enter your WordPress Admin panel (also known as the WP Admin) by pointing your browser to http://yoursite.com/wp-admin. If you're not already logged in, this URL will redirect you to the login page.

Learning more

If you'd like to see an even more detailed step-by-step guide for manual installation, take a look at this page in the WordPress Codex: http://codex.wordpress.org/Installing_WordPress.
Also, you can find more detailed installation instructions—as well as specifics on changing file permissions, using FTP, using languages, importing from other blogging engines, and more—in the WordPress Codex here: http://codex.wordpress.org/Getting_Started_with_WordPress#Installation.

Summary

In this article we took a look at how to create a blog on WordPress.com and install WordPress on a remote server.

Product Management with Compiere 3

Products are an integral part of the ERP transactional process, and thus require a detailed explanation in the setup process, not only from the master data point of view but also for transactional processes.

We will therefore describe how Compiere handles Product. In this article we shall learn:

* Give you an overview of the concept of a product
* Show you how to set up price lists and discount schemas

The product definition

The concept of a product in Compiere is that it is something that you buy or sell and has a price. It would include:
  • Inventory items (items that you store and track)
  • Non-stock items (still items, but you do not store or track them)
  • Services
  • Resources
  • Expense types
In addition to a product, Compiere allows for charges (account aliases), as well as customer assets on transactional lines.
When to use a charge and not a product: It's logical to use charges where a mere account entry is required and the many descriptions that a product requires are not required for the transaction. An example would be marketing or an admin expense.
When to use a customer asset and not a product: Customer assets are extended instances of a Compiere product. An example would be where a Desktop PC is sold or purchased and becomes an asset or equipment type that need to be tracked.Customer assets are therefore used for asset or equipment related business process information.
Products allow for many descriptive attributes in its master setup.

Describing a product

Product information and features can be extended and described in Compiere in the following manner:
  • Basic Product Information: Basic product information includes search key values, Descriptions, Unit of Measure, UPC, EAN. Critical for basic product information are Product categories, which group products into related products.
  • Product BOM (Bill of Material): More advanced products would include BOM kits that are made up of other products (referred to as BOM components).
  • Substitute / Related Products: This refers to products that may be related to the product being searched for.
  • Product Replenishment: This describes the rules of how a product would be replenished. This would, for instance, include minimum and maximum quantities to hold in stock.
  • Product Purchasing information: This refers to the set-up around how a product is purchased—for instance the default vendor and the vendor's product code.
  • Product Locator: Where products are currently located in the warehouse.
  • Product Business Partner: This describes additional information used when products are purchased.
  • Product Price: A product may have multiple price lists attached to it, and depending on the Business Partner or transactional document this can be defaulted as required.
  • Product Accounting: This describes which standard account elements are to be used for a transactional document. Usually, similar products have the same accounting rules and as such the accounting for Product Categories would be setup and maintained, rather than individual product categories.
  • Product Unit of Measure conversions: Where applicable, products may have conversions applicable to them—for instance converting a 6-pack quantity sold to an, each, quantity during purchasing.
  • Product Attributes: Attribute sets allow you to further extend the product information into, for example, instance sets such as lots and serial numbers.Non-instance sets are also catered for, such as colour or size sets that can be used for searching the products.

Setting up a Product

Prior to setting up a product, you should make sure that the following is set up:
  • Warehouse and Locators: The system logic here is that a Product must be sold/delivered from somewhere within the organization. Make sure that you set up your warehouse and Locators first. Use virtual warehouse and locators where they are not physical.
  • Units of Measure: Review the system standard units of measure and add your own units of measure if applicable.
  • Product Categories: Define your groupings prior to setting up products since it will reduce data maintenance time.
  • Tax Categories: Pre-define the applicable tax categories if they are product specific.
  • Price lists: In order to use a product it must have a price which is set up through Price Lists (it includes sales and/or purchase price lists).
The above set-up is performed through the Product Setup menu items, which are grouped as follows in the main menu:
You start entering a product through the Product window:
The additional Product Descriptions (listed above) are added through the following tabs in the Product window:

Price Lists

In order for products to be used in the sales or purchasing cycle, they must have prices. A product can have the following three line prices set up:
  • List Price: The list price before discounts of a product.
  • Standard Price: The standard price of a product.
  • Limit Price: The lowest price at which a product can be sold or purchased.Usually used by management as a pricing control limit for sales reps.
The product price information (in the context of the price list version) is accessed through the Product Price| window:

Pricing logic flow

Price lists determine the price to be used in the context of the transaction(sales / purchase) and the chosen Business Partner. The basic logic for determining the price is as follows:
  • A price list has a version, and the latest version of a price list is used during sales or purchasing (or both).
  • If a Business Partner (customer or vendor) is assigned a Price list, then this Price List is used to determine the price for the transaction.
  • If a Business Partner is not assigned a price list, then the Business Partner Group's defined price lists is used.
  • If the Business Partner Groups' price list is not defined, then the default sales or purchase price list is used (this is indicated throught the isDefault checkbox in the price list window header).
  • If a product is not assigned the relevant price list, an error is given and the user cannot continue.
  • The system also considers that a price list is Tenant and Organization specific.
In terms of price discounting, a product can be assigned to a Discount Schema. In such a case, the following discount schema options are available:
  • Price lists: This is the normal type of discount calculation, and is based on the price list-that is—a discount off the list price based on a distributor or reseller price list.
  • Flat Percentage: This refers to a flat percentage discount arrangement.
  • Quantity Discount Breaks: This discount schema refers to quantity breaks, where items purchased at different quantity levels attract more discount-for example,—100/10% or 1000/20%.

Setting Up a Price List and version

As mentioned, a price list can have one or more versions, which are time based. This is set up as follows:
  1. Enter a price list through the Price List window. Here, we enter a sales pricelist as follows:
  2. A price list may be set up to be inclusive of tax. In this case the accounts posting on the document is adjusted to reflect the inclusive tax accounting. Enforcing price limits ensures that the end-user cannot enter a price lower that the price lists, limit price for the product.
  3. Create one or many price list versions through the Price List | Version tab, with the following options:
    • Dicscount Schema: This specifies the discount rules to be applied when creating or updating the price list.
    • Base Price List: This indicates a price list upon which to base the discount schema rules.
    • Valid from date: The price list will be used for new order or invoice transactions from this date. Transactions prior to this date will not be affected.
A price list is either imported, manually entered, or updated based on another price list, through the discount schema.

Illustrating a price list increase

To illustrate the process of a applying a price list increase, we will create a new price list version with a 10 percent increase on the existing version.
  1. One enters the discount schema detail through the Discount Schema window. We will select a PriceList discount type, as the calculation will be based on the price list values:
    How to Handle Products using Compiere 3
  2. The next step is to create the Price List line calculation paramaters for the discount schema:
    How to Handle Products using Compiere 3
  3. The pricing discount line for the increase is entered as follows:
    1. Select the Price Base: This defines which price base is affected (List, /Standard / Limit).
    2. Enter the List price Discount: A discount is normally entered as a positive, but because we are performing a price increase we enter a negative amount.
    3. List Price Rounding option: Compiere allows different rounding methods, and as illustrated we selected the Rounding to the nearest Ten (10,20,30) option, for pricing policy reasons.
    How to Handle Products using Compiere 3
  4. Finally, we run the increase for the Price List version illustrated as follows:
    How to Handle Products using Compiere 3

Discount Breaks

Discount breaks are trade discounts applied through different quantity or value breaks/levels. Setting up a Discount Schema for discounts break based on a quantity sliding scale is entered through the Discount Schema window, as follows:
In a sliding scale discount break, Compiere applies the first discount break that meets the discount criteria, therefore for the example above, an order of 1000 or above would have a 40% discount, 500-999 would have 20% discount, an order of between 10 to 499 would have 4% discount, and 0-9 would have 0% discount

Pricing Decimal Precisions

Compiere allows for different pricing decimal precisions, which may be a requirement in the enterprise during different transaction types:
  • Unit of measure: You can define pricing decimal precisions for accounting and cost calculation separately
  • Currency: You can define pricing decimal precisions for accounting and cost calculation separately
  • Price List: You can define the price precision

Managing Products as Services

Service items are not treated as stock and are usually not purchased. Service items are managed as non-stocked items and have different accounting entry implications,by default. Service items are set up through the Product window as follows:

Summary

We covered the following in this article:
  • The basic characteristics of a product, and how to set up a product item
  • How to set up and use price lists and discount schemas

Developing a Simple Workflow within SugarCRM

Workflow is about getting the right work to the right people at the right time, repeatedly—and knowing you have done so. Workflow is human-centric. First and foremost, workflow is a human activity that is made by and for those who use it: workflow is something that can easily be handled and understood by human beings.
UK Enterprise Workflow National e-Government Project—Workflow from a Business Perspective
Well, that sounds good, but the problems start to occur when you ask people to consider workflow in their organization, and there are usually a few main issues to deal with:
  • You'll find that people are normally experts in their own fields—there are often very few people who have an overview of the whole process that you're trying to map.
  • Sections of a large organization will often have different ways of carrying out the same overall process.
  • People don't really like to be told how to do their jobs—they especially don't like to have any extra processes imposed on them for now obvious reason—well, would you?
  • Talk of 'improved utilization of resources', 'improved performance monitoring', and such like can soon alienate the staff who are going to be using the system. They'll soon start using terms such as 'Big Brother'.
How you are able to deal with these will depend on your organization and the people that are available to you. At least once you've read this article by Dr. Mark Alexander Bain, you'll know that, once you've overcome those problems, the workflow itself will be easy.

A Very Simple Workflow

In our simple workflow we'll assume that each task is carried out by one person at a time, and that all tasks are done sequentially (i.e. none are done in parallel). So, we'll look at the PPI Preliminary Investigation which, as you remember, maps to the standard SugarCRM Opportunity. Also, in this example, we're going to have a different person carrying out each one of the Investigation stages.

Setting up the Process Stages

If you look at SugarCRM then you'll see that by default none of the stages are related to investigations—they're all named using standard CRM terms:
Developing a Simple Workflow within SugarCRM
Obviously the first thing to do is to decide what the preliminary investigation stages actually are, and then map these to the SugarCRM stages. You'll realize that you'll need to edit the custom/include/langauge/en_us.lang.php file:
$app_list_strings['sales_stage_dom']=array (
  'Prospecting' => 'Fact Gathering',
  'Qualification' => 'Witness and Subject Location',
  'Needs Analysis' => 'Witness and Subject Interviews',
  'Value Proposition' => 'Scene Investigation',
  'Id. Decision Makers' => 'Financial and background Investigation',
  'Perception Analysis' => 'Document and evidence retrieval',
  'Proposal/Price Quote' => 'Covert Camera surveillance',
  'Negotiation/Review' => 'Wiretapping',
  'Closed Won' => 'Full Investigation required',
  'Closed Lost' => 'Insufficient Evidence',
);
Don't forget that you can also do this via Studio. However, once you've added your mapping into custom/include/langauge/en_us.lang.php file, and refresh your browser, then you'll see the new stages:
Developing a Simple Workflow within SugarCRM
Now that our stages are set up we need to know who'll be carrying out each one.

Deciding Who Does What

In our simple workflow there may not be the need to do anything further. Each person just needs to know who does what next:
For example, once Kurt finishes the 'Covert Camera surveillance' stage then he just needs to update the Preliminary Investigation so that the stage is set to 'Wiretapping' and the assigned user as 'dobbsm'.
However, things are rarely as simple as that. It's much more likely that:
  • Investigations may be based on geographical locations, so that the above table may only apply to investigations based in London. Investigations based in New York follow the same process but with a different set of staff.
  • On Mondays Fran does 'Witness and Subject Location' and William does 'Fact Gathering'.
This means, of course, that we need to be using some businesses rules.

Introducing Business Rules

There are six 'triggers' that will cause the logic hooks to fire:
  • after_retrieve
  • before_save
  • before_delete
  • after_delete
  • before_undelete
  • after_undelete
And the logic hooks are stored in custom/modules//logic_hook.php, so for 'Preliminary Inquiries' this will be custom/modules/Opportunities/logic_hook.php. You'll also remember, of course, that the logic hook file needs to contain:
  • The priority of the business rule
  • The name of the businesses rule
  • The file containing the business rule
  • The business rule class
  • The business rule function
So, custom/modules/Opportunities/logic_hook.php needs to contain something like:
#As always ensure that the file can only be accessed through SugarCRM
if(!defined('sugarEntry') || !sugarEntry) die(
     'Not A Valid Entry Point');
$hook_array = Array(); #Create an array

$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'ppi_workflow',
  'custom/include/ppi_workflow.php',
  'ppi_workflow', 'ppi_workflow');
?>
Next we'll need the file that logic hook will be calling, but to start with this can be very basic—so, custom/include/ppi_workflow.php just needs to contain something like:
#Define the entry point
if(!defined('sugarEntry') || !sugarEntry) die(
     'Not A Valid Entry Point');
#Load any required files
require_once('data/SugarBean.php');
require_once('modules/Opportunities/Opportunity.php');

#Define the class
class ppi_workflow
{
  function ppi_workflow (&$bean, $event, $arguments)
  {

  }
}
?>
With those two files set up as above nothing obvious will change in the operation of SugarCRM—the logic hook will fire, but we haven't told it to do anything, and so that what we'll do now.
When the logic hook does run (i.e. when any Primary Investigation is saved) we would want it to:
  • Check to see what stage we're now at
  • Define the assigned user accordingly
All of the relevant information (i.e. the new stage) is passed to the logic hook by means of the $bean object, and we can obtain the stage from $bean->sales_stage. Now all we have to do is combine this with PHP's switch statement into the ppi_workflow function:
switch ($bean->sales_stage)
{
    case "Prospecting":
      $assigned_user = "varadyf";
      break;
    case "Qualification":
      $assigned_user = "monkw";
      break;
    case "Needs Analysis":
      $assigned_user = "pittc";
      break;
    case "Value Proposition":
      $assigned_user = "brockd";
      break;
    case "Id. Decision Makers":
      $assigned_user = "brunettig";
      break;
    case "Perception Analysis":
      $assigned_user = "thanetl";
      break;
    case "Proposal/Price Quote":
      $assigned_user = "wallanderk";
      break;
    case "Negotiation/Review":
      $assigned_user = "dobbsm";
      break;
    case "Closed Won":
      $assigned_user = "bluek";
      break;
    case "Closed Lost":
      $assigned_user = "bluek";
      break;
}
You'll notice from the code that we must use the original SugarCRM sales stage terms and not our new mapping—that only appears on the screen.
Next we'll have to add the code to update $bean->assigned_user_id with the ID of our new user:
global $db;

$sql =
  "select id from users where user_name = '" . $assigned_user ."'";
$result = $db->query($sql);
$bean->assigned_user_id = mysql_result($result,0,0);
With the code in place, if you now change the Investigation (or Sales) stage, and then save the Preliminary Investigation (or Opportunity) then you'll see that the assigned user is automatically updated for you.
However, this is still only a semi-automatic process—the correct person for the stage is selected correctly, but only if the stage is selected manually. The process running correctly still depends on someone telling SugarCRM what that next stage is. Obviously the next step is to move from stage to stage automatically.

Completing the Automated Workflow

At the moment we're relying on a user telling the application which stage to move to next. However, it would be much better for the user to tell SugarCRM that the current stage has been completed, and then for the business rules to decide which stage should be carried out next. We want to keep it simple and therefore an 'Investigation Stage Complete' checkbox will do the job.
If you look at the edit view for any of the existing Opportunities then you'll see that there's nothing that can really be renamed to represent our 'Investigation Stage Complete':
Developing a Simple Workflow within SugarCRM
We can use the SugarCRM Studio to add the field that we're going to need:
Developing a Simple Workflow within SugarCRM
After adding the custom field itself we'll need to add text for the field label into custom/modules/Opportunities/language/en_us.lang.php:
And then we're ready to see the new edit view:
$mod_strings['lbl_chk_complete_c_10'] = "Investigation Stage 
Completed";
Developing a Simple Workflow within SugarCRM
We can now go back to our code (in custom/include/ppi_workflow.php), and we can place all of our functionality within an if statement:
if ( $bean->chk_complete_c == 1 )
{
  switch ($bean->sales_stage)
  {
    /* etc, etc, etc */
  }
}
Our logic hook will, of course, fire every time a save is made—but our business rule will only be implemented if the Investigation Stage Completed box is ticked. So now we need the code that will define the process itself, and you would need to place this before the code for deciding who the assigned user is:
switch ($bean->sales_stage)
{
  case "Prospecting":
    $bean->sales_stage = "Qualification";
    break;
  case "Qualification":
    $bean->sales_stage = "Needs Analysis";
    break;
  case "Needs Analysis":
    $bean->sales_stage = "Value Proposition";
    break;
  case "Value Proposition":
    $bean->sales_stage = "Id. Decision Makers";
    break;
  case "Id. Decision Makers":
    $bean->sales_stage = "Perception Analysis";
    break;
  case "Perception Analysis":
    $bean->sales_stage = "Proposal/Price Quote";
    break;
  case "Proposal/Price Quote":
    $bean->sales_stage = "Negotiation/Review";
    break;
  case "Negotiation/Review":
    $bean->sales_stage = "Closed Won";
    break;
}
//Now decide who the assigned user is...
And finally we need to reset the completed status back to 0:
$bean->chk_complete_c = 0;
You'll notice that we've not taken the process all the way to the final stage—this is because the final two stages are 'Closed won' or 'Closed lost' (in PPI speak—'Full Investigation required' and 'Insufficient Evidence'). Korora will need to make that decision herself.
However, the important thing is that you can see just how easy it is to set up a simple process (not that any process is ever simple).

Summary

Before you start work on your workflow, ensure that: the people who understand the processes in the organization are available to you; both managers and staff agree that the process plan is correct; staff don't feel that the process is being enforced on them; and that this isn't another case of 'Big Brother'.
When you do start building the work flow ensure that you've correctly mapped your organization's stages onto the SugarCRM stages and that you have a complete listing of who does what and when.
Business rules are created by making use of SugarCRM's logic hooks. The logic hook file contains the priority of the business rule, the name of the businesses rule, the file containing the business rule, the business rule class, and the business rule function.

Introduction to Developing Facebook Applications

In this article we will:
  • Learn what the big deal is about Facebook, and why you should be interested in developing an application for it
  • Get you set up with a web host, which you'll need for developing any online Facebook application
  • Establish how much AS3 you need to know already, and what to do if you don't
  • Find out how to deal with the debugging complications that arise when developing a "browser-only" application like this
So let's get on with it...

What's so great about Facebook?

Seems like everyone's on Facebook these days—people are on it to socialize; businesses are on it to try to attract those people's attention. But the same is true for other older social networks such as LinkedIn, Friendster, and MySpace. Facebook's reach goes far beyond these; my small town's high street car park proudly displays a "Like Us On Facebook" sign.
More and more Flash games and Rich Internet Applications (RIAs) are allowing users to log in using their Facebook account—it's a safe assumption that most users will have one. Companies are asking freelancers for deeper Facebook integration in their projects. It's practically a buzzword.
But why the big fuss?

It's popular

  • Facebook benefits from the snowball effect: it's big, so it gets bigger.
  • People sign up because most of their friends are already on it, which is generally not the case for, say, Twitter. Businesses sign up because they can reach so many people. It's a virtuous circle.
  • There's a low barrier to entry, too; it's not just for techies, or even people who are "pretty good with computers;" even old people and luddites use Facebook. In February 2010, the technology blog ReadWriteWeb published an article called "Facebook Wants to Be Your One True Login," about Facebook's attempts to become the de facto login system throughout the Web. Within minutes, the comments filled up with posts from confused Facebook users:
    Introduction to Developing Facebook Applications
    • Evidently, the ReadWriteWeb article had temporarily become the top search result for Facebook Login, leading hundreds of Facebook users, equating Google or Bing with the Internet, to believe that this blog post was actually a redesigned Facebook.com. The comment form, fittingly, had a Sign in with Facebook button that could be used instead of manually typing in a name and e-mail address to sign a comment—and of course, the Facebook users misinterpreted this as the new Log in button.
    • And yet… all of those people manage to use Facebook, keenly enough to throw a fit when it apparently became impossible to use. It's not just a site for geeks and students; it has serious mass market appeal.
  • Even "The Social Network"—a movie based on the creation of Facebook—held this level of appeal: it opened at #1 and remained there for its second weekend.

Numbers

  • According to Facebook's statistics page (http://www.facebook.com/press/info.php?statistics), over 500 million people log in to Facebook in any given month (as of November 2010). For perspective, the population of the entire world is just under 7,000 million.
  • Twitter is estimated to have 95 million monthly active users (according to the eMarketer.com September 2010 report), as is MySpace. FarmVille, the biggest game based on the Facebook platform, has over 50 million: more than half the population of either competing social network.
  • FarmVille has been reported to be hugely profitable, with some outsider reports claiming that its parent company, Zynga, has generated twice as much profit as Facebook itself (though take this with a grain of salt). Now, of course, not every Facebook game or application can be that successful, and FarmVille does benefit from the same snowball effect as Facebook itself, making it hard to compete with—but that almost doesn't matter; these numbers validate Facebook as a platform on which a money-making business can be built.

It's everywhere

As the aforementioned ReadWriteWeb article explained, Facebook has become a standard login across many websites. Why add yet another username/password combination to your browser's list (or your memory) if you can replace them all with one Facebook login?
This isn't restricted to posting blog comments. UK TV broadcaster, Channel 4, allows viewers to access their entire TV lineup on demand, with no need to sign up for a specific Channel 4 account:
Introduction to Developing Facebook Applications
Again, Facebook benefits from that snowball effect: as more sites enable a Facebook login, it becomes more of a standard, and yet more sites decide to add a Facebook login in order to keep up with everyone else.
Besides login capabilities, many sites also allow users to share their content via Facebook. Another UK TV broadcaster, the BBC, lets users post links for their recommended TV programs straight to Facebook:
Introduction to Developing Facebook Applications
Blogs—or, indeed, many websites with articles—allow readers to Like a post, publishing this fact on Facebook and on the site itself:
Introduction to Developing Facebook Applications
So half a billion people use the Facebook website every month, and at the same time, Facebook spreads further and further across the Internet—and even beyond. "Facebook Messages" stores user's entire conversational histories, across e-mail, SMS, chat, and Facebook itself; "Facebook Places" lets users check into a physical location, letting friends know that they're there.
No other network has this reach.

It's interesting to develop for

With all this expansion, it's difficult for a developer to keep up with the Facebook platform. And sometimes there are bugs, and undocumented areas, and periods of downtime, all of which can make development harder still.
But the underlying system—the Graph API, introduced in April 2010—is fascinating. The previous API had become bloated and cumbersome over its four years; the Graph API feels well-designed with plenty of room for expansion.

Have a go hero – get on Facebook

If you're not on Facebook already, sign up now (for free) at http://facebook.com. You'll need an account in order to develop applications that use it. Spend some time getting used to it:
  • Set up a personal profile.
  • Post messages to your friends on their Walls.
  • See what all the FarmVille fuss is about at http://apps.facebook.com/onthefarm.
  • Check in to a location using Facebook Places.
  • Log in to some blogs using your Facebook account.
  • Share some YouTube videos on your own Wall from the YouTube website.
  • "Like" something.
    Go native!

Web hosts

If you've already got a publicly accessible web server or are signed up to a web host to which you can upload SWFs and HTML pages via FTP, skip to the How much AS3 knowledge is required? section.

What's a web host?

I'll assume that you roughly know how the Internet works: when you type a URL into a web browser on your computer and hit Go, it retrieves all the pages and images it needs from another computer, the web server, and displays them. The exact methods it uses to find the web server and the protocols for how the information gets back to your computer aren't relevant here.
You could go out and buy a computer, install some server software, and hook it up to your Internet connection, and you'd have a functional web server. But you'd have to maintain it and keep it secure, and your ISP probably wouldn't be very happy about you sending all those pages and images to other people's browsers. A better option is to pay another company to take care of all of that for you—a web host.

Why do you need one?

  • In order to build an online SWF-based application or game that allows users to log in with their Facebook account (with the SWF being able to access their profile, list of friends, Wall, and so on), you will require control over a web page.
  • Technically, you could probably come up with some hack that would allow you to get around this—perhaps by hosting everything on Google sites and MegaSWF—but in the long run it's not going to be worth it. Splash out on a web host for the sake of learning; you will definitely need access to one if you do professional Facebook application development in the future.

How do you choose one?

  • There are a huge number of web hosts to choose from, and an even bigger number of configurable options between them. How much disk space do you need? How much bandwidth per month? How much processing power? Some hosts will give you a server all to yourself, while others will put your files on the same computer as other customers. And of course, you have to wonder how good the customer service is and how reliable the company is at keeping their servers online. Throw in a few terms such as "cloud hosting" and it's enough to make your head spin.
  • All you need is a host that allows you to upload HTML files and SWFs.
  • Want to just get started without wasting time comparing hosts? Go with Media Temple. The code was all tested using a Media Temple Grid Service account, available at http://mediatemple.net/webhosting/gs/. It provides much more than what you'll need for completing the projects, granted, and at $20/month. It's not the cheapest option available, but the extra service and features will definitely come in handy as you build your own Facebook applications and games.

Useful software

You'll need an HTML editor for editing web pages. FlashDevelop and Flash Builder both do good jobs at this; otherwise, try:
And in order to transfer your files from your computer to your web host, you'll probably need an FTP client. Check out FileZilla (it's free and available for both Windows and Mac) at http://filezilla-project.org/. Documentation for this is available at http://wiki.filezilla-project.org/Documentation, and your web host will almost certainly provide instructions on connecting to it via FTP (Media Temple's instructions can be found at http://kb.mediatemple.net/questions/131/Using+FTP+and+SFTP)

What about domain names?

Web hosts will generally assign you a very generic address, such as http://michaeljw.awesomewebhost2000.com/ or http://sites.awesomewebhost2000.com/michaeljw. If you want to have a more condensed personal address such as http://michaeljw.com/, you'll need to pay for it. This is called a domain name—in this specific example, michaeljw.com is the domain name.
Media Temple allows you to buy a domain name for $5/year at the point where you sign up to their web hosting package. If you go with another host, you may need to buy a domain name elsewhere; for this, you can use http://www.moniker.com/.

Have a go hero – get a web host, upload to it, test

Pick a web host, get your credit card out, and sign up for one of their packages.
  1. Create a new directory called /test/ in the public path of your web host.
  2. Create a new plain text file on your hard drive called index.html. (It's a good idea to create a new folder on your computer to store all your work, too.) Open this file in your HTML editor.
  3. Copy the HTML below into the file:
    Test
     
     
       

    Hello!

  4. Hopefully, you know enough HTML to understand that this just writes Hello! in big letters.
  5. Transfer index.html to the /text/ directory on your host. Again, you'll probably need to use an FTP client for this.
  6. Open a web browser and type http://host.com/test/index.html into the URL bar. Of course, you should replace http://host.com/ with the path to your public directory, as given to you by your web host. You should see Hello! appear in a glorious default font:
    Introduction to Developing Facebook Applications
  7. If not, check the documentation and support for your host.

How much AS3 knowledge is required?

Powered by…

In September 2010, Adobe released an official Adobe ActionScript 3 SDK for the Facebook Platform Graph API, which will remain fully supported by Adobe and Facebook. Read more about it at http://www.adobe.com/devnet/facebook.html.
Besides the Adobe AS3 SDK for Facebook Platform, two other code libraries are used heavily:

Debugging

There are a few tools that will help:

Watch out for caching

When you run a SWF using Flash Player on your desktop, it loads and runs the SWF. Well, of course, why wouldn't it?
When you run a SWF in a browser, this isn't always the case, though. Sometimes, browsers cache SWFs, meaning that they save a copy locally and then load that copy—rather than the online version—the next time you request it. In normal browsing, this is a great idea—it saves bandwidth and reduces loading times. You can lose huge amounts of time trying to figure out why your new code isn't working, only to finally realize that the new code isn't being run at all because you were seeing only a cached copy of your SWF.
Different browsers require different solutions. It's usually possible to disable caching for one browsing session, and it's always possible to delete some or all of the cache.
In Google Chrome, you can do this by clicking on [Spanner] | Tools | Clear Browsing Data…, selecting Empty the cache, and choosing an appropriate time period:
Introduction to Developing Facebook Applications
Introduction to Developing Facebook Applications
You should easily be able to find the equivalent option for your browser by searching Google for «browser name» delete cache.

Summary

Facebook's developers are always tweaking the platform. This can make it exciting to develop on because new features are being added all the time, but it can also make it very frustrating to develop on because old features can be removed, or their implementations changed; anything could be altered at any time.
The new Platform API (the Graph API) is a strong foundation, and looks likely to be around for a while—remember, the previous Platform API lasted four years. But it's modular, and individual pieces might change, or even be removed.