Print

Managing documents with Box.net

Even though nuBuilder allows the upload of documents, storing them in a database isn't the most efficient way to manage them.

Using a third party like box.net is a much more elegant way.

This is how we have used box.net.

STEP 1.


Create 3 fields in zzsys_setup..



set_box_net will generally be '0' (parent directory)
set_box_net_key will hold the API Key you will need to get from box.net.
set_box_net_token will hold the Authoriy Token you will need to get from box.net.

This will require a bit of reading (But if I can do it..)

http://developers.box.com/ (external link)

STEP 2.


Create 1 field in zzsys_form..



To get the id for this field you will need to generate an id manually. We did it by running a php file called create_folder.php that contains this code..

<?php  
 
 
$key    = 'ffgfghvjr9lptc4mmr0cxntlcth6d';  //-- get this from box.net
$token  = 'e6glnj2yocjqqc3ysmffsqq89ecju';  //-- get this from box.net
 
$ur<x>l = "https://www.box.net/api/1.0/rest?action=create_folder&api_key=fhxic79ohvjr9lptc4mmr0cxntlcth6d&auth_token=e6glnj2yocjqqc3ysmsqq89ecjxg5fiu&parent_id=&name=14f99cb3981ebc&share=1";  
$ch = curl_init();  
 
// set URL and other appropriate options  
curl_setopt($ch, CURLOPT_URL, $ur<x>l);  
 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
 
// grab URL and pass it to the browser  
 
$output = curl_exec($ch);  
echo $output;  
 
$a = json_decode(json_encode((array) simplexml_load_string($output)),1); 
 
print_r($a);
 
// close curl resource, and free up system resources  
curl_close($ch);  
 
?>



STEP 3.


Create the same field in the table you want to save documents against eg. customer table..

You can then manage documents in a new form called "Customer".

(**Do step 2 before creating the new form called Customer) - This will create a directory on box.net that can hold subfolders for each customer record.)





STEP 4.


Insert the following code into sfo_custom_code_run_after_save of zzsys_form ONLY for the record.. WHERE zzsys_form_id = 'form'.


$setup       = nuSetup();
	$tbl         = nuRunQuery("SELECT * FROM zzsys_form WHERE zzsys_form_id = 'form'");
	$rec         = db_fetch_array($tbl);
 
	if($setup->set_box_net != '' and array_key_exists('sys_box_net', $rec) and '#recordID#' != '#newID#'){
		$ur<x>l     = "https://www.box.net/api/1.0/rest?action=create_folder&api_key=$setup->set_box_net_key&auth_token=$setup->set_box_net_token&parent_id=$setup->set_box_net&name=#newID#&share=1";  
		$ch      = curl_init();  
 
		// set URL and other appropriate options  
		curl_setopt($ch, CURLOPT_URL, $ur<x>l);  
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_HEADER, 0);  
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
 
		// grab URL and pass it to the browser  
		$output  = curl_exec($ch);  
		$array   = json_decode(json_encode((array) simplexml_load_string($output)),1); 
		curl_close($ch);  
 
		nuRunQuery("UPDATE zzsys_form SET sys_box_net = '" . $array['folder']['folder_id'] . "' WHERE zzsys_form_id = '#newID#'");
	}



STEP 5.


Insert the following code into sfo_custom_code_run_after_save of zzsys_form ONLY for the record.. WHERE zzsys_form_id = '(whatever the customer form id is)'.


$form         = formFields($_GET['f']);
	$setup        = nuSetup();
	$ur<x>l          = "https://www.box.net/api/1.0/rest?action=create_folder&api_key=$setup->set_box_net_key&auth_token=$setup->set_box_net_token&parent_id=$form->sys_box_net&name=#newID#&share=1";  
	$ch           = curl_init();  
 
	// set URL and other appropriate options  
	curl_setopt($ch, CURLOPT_URL, $ur<x>l);  
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($ch, CURLOPT_HEADER, 0);  
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
 
	// grab URL and pass it to the browser  
	$output       = curl_exec($ch);  
	$a            = json_decode(json_encode((array) simplexml_load_string($output)),1); 
	curl_close($ch);  
 
	$public_name  = $a['folder']['public_name'];
 
	nuRunQuery("UPDATE customer SET sys_box_net = '$public_name' WHERE customer_id = '#newID#'");



STEP 6.


Add a text object to the newly created Customer Form called sys_box_net (this can be set to hidden).


STEP 7.


Add a HTML object to the Customer Form (probably best on a new Tab) for the box.net widget


<em<x>bed src="https://www.box.com//static/flash/box_explorer.swf?widget_hash=#sys_box_net#&v=0&cl=0&s=0" width="460" height="345" wmode="transparent" type="application/x-shockwave-flash"></embed>


Notice the #sys_box_net# inside this html, this will now display a different subdirectory for each customer record.


This is how it will look.. http://seefor.info/boxnu (external link)




Created by: steven. Last Modification: Monday 30 of April, 2012 16:05:55 CST by steven.