Results tagged “web development” from muse

Setup Yaws on Ubuntu 12.04

|

Install:

sudo apt-get install erlang yaws

Edit /etc/yaws/conf.d/localhost.conf and /etc/yaws/conf.d/localhost-ssl.conf to configure the site(s).

In /etc/yaws/yaws.conf, you can specify the directory for additional beam files, by default it is:

ebin_dir = /usr/lib/yaws/custom/ebin

To start a module when yaws starts, use runmod, for example:

runmod = start_mongodb

Note that the module should have an exported function start/0.

Gantticc

|

gantticc.png

Gantticc is a Gantt chart web app that I have been working on for the past few weeks. Essentially I made it to solve a problem of my own: visualizing projects. And hopefully it'll help some other people as well.

I needed a way to plan out tasks and allocate time for each task, and gantt chart seems to be the solution. So I went on a hunt for gantt chart apps. I tried several and they are either too bulky or not visually appealing, not to mention whether they work across multiple platforms. Then I came across the awesome Javascript SVG library BonsaiJS, which made it really easy to develop an interactive gantt chart in the browser and have it work for mobile devices at the same time.

At the beginning of this year I finally had some free time, so I spent a few weeks and developed the app. The code is not elegant per se but the app has all the features I needed. A friend of mine also directed me to the heat map approach to gantt chart, and I implemented it as the way to visualize multiple projects, which turned out to be very effective and is probably the most useful feature.

Finally this project is open source and you can get it on github.

This is a solution to mix public downloads and protected folders.

For this, you will need CCK, specifically CCK FileField and Content Permission. Also mod_rewrite should be enabld.

First, add a new file field to a content type, and configure its path to the directory that will be protected. For example, if /files/protected is the directory that will contain protected files, then you can either set that as the path or a folder within it.

If you have already set /files as your file system path, then there should be a .htaccess file created by drupal. You should copy that into each of the protected folders. If you don't, you may get 404 errors.

Open the .htaccess file in your root drupal directory, add the following line to the end of mod_rewrite rules:

RewriteRule ^files\/(protected\/.*)$ index.php?q=system/files/$1 [L,QSA]

Replace protected with your top-level protected folder name. If you have other custom rewrite rules you should be more careful about where you put the above line. Putting it at the end works for me.

Lastly, on your 403 page, you can examine if user is requesting a file in a protected directory using request_uri() and strpos().

Customize Ubercart Product Page

|

Here's a little snippet of code to customize ubercart product page template so that the contents are grouped into tabs.

You need Tabs and CCK Fieldgroups Tabs.

Go to yoursite/admin/content/node-type/product/fields and add some cck groups and fields, then display them properly (tabs for full node).

Create node-product.tpl.php. Paste the following php code in (enclose it with php tags):

$form = array();
$form['ptabs'] = array(
'#tabset_name' => 'ptabs',
'#type' => 'tabset',
);
$i = 0;

// shows a summary of the product
$summary;
$summary .= $node->content['weight']['#value'];
$summary .= $node->content['dimensions']['#value'];
$summary .= $node->content['body']['#value'];
$form['ptabs'][$i] = array(
'#type' => 'tabpage',
'#title' => t('Summary'),
'#content' => $summary,
);
$i++;

// add other tabs if applicable
if (!empty($node->content['fieldgroup_tabs'])) {
	foreach ($node->content['fieldgroup_tabs'] as $key => $value) {
		if (is_array($value)) {
			if ($value['#type'] == 'tabpage') {
				$form['ptabs'][$i] = array(
				'#type' => 'tabpage',
				'#title' => $value['group']['#title'],
				'#content' => $value['group']['#children'],
				);
				$i++;
			}
		}
	}
}

The page should always have a tab called Summary, and other tabs that you added for the content type if they are not empty (cck fieldgroup tabs module validates this). If you don't wish to have the Summary tab, simply delete that part of code.

Feel free to share the code.

Webform is a great module, but it doesn't send confirmation email, so here is a quick fix if you are running on Drupal 6.x.

To get the submitted value of a form component, you can use $form_values['submitted_tree']['component_key'] where component_key should be replaced by your component key. If the component is in a fieldset, access it by $form_values['submitted_tree']['fieldset_key']['component_key'] where fieldset_key should be replaced by your fieldset key.

To send the email I chose to use drupal_mail() function, of course there are other ways.

Here is an example:

$from = "example@example.com";
$to = $form_values['submitted_tree']['email'];
$user = $form_values['submitted_tree'['name'];
$body = "Hello " . $user . ",\nThis is a message.";
drupal_mail('webform_extra', 'confirmation_key', $to, language_default(), array('body' => $body), $from, TRUE);
function webform_extra_mail($key, &$message, $params) {
$message['subject'] = "Confirmation email";
$message['body'] = $params['body'];
}