Hi,
I'm currently developing a module to interface Zoho Writer and Drupal. I am having trouble finding what the best solution to my problems would be.
I have to visit a secure URL to get a ticketID for a user:
How to generate Ticket ID ?
To generate the ticket ID, users have to send the authenticated request to Zoho Accounts over a secured connection in the following URL format:
Request:
https://accounts.zoho.com/login?servicename=[ZohoWriter/ZohoSheet/ZohoSh... ID/Email ID]&PASSWORD=[Password]
The web page returns Name Value Pairs in a string. One of the name value pairs is the Ticket ID. I need to somehow get these values into Drupal to use when I post the Zoho Document as this request needs to be issued:
To create a new document in your Zoho Writer account.
Request URL : POST Method
XML : http://export.writer.zoho.com/api/private/xml/newDocument/[documentName]... Key]&ticket=[Ticket]
JSON : http://export.writer.zoho.com/api/private/json/newDocument/[documentName... Key]&ticket=[Ticket]
Request parameters :
To create a new document in Zoho Writer account we need to submit a form data to Writer with the following fields:
Field
Description
Document Name
New document name to be created.
content
Specify the content of the document.
Sample Form (POST Method)
I have written the base of a module that has an install file that installs the relevant tables in the database. It also removes them when the module is uninstalled. Below is the contents of my module. I am looking at using workflow at the moment to carry out the actions when the node is created. I based this code on the blog module.
// $Id: zoho.module,v 1.271.2.3 2008/07/06 00:27:42 drumm Exp $
/**
* @file
* Enables keeping an easily and regularly updated web page or a zoho.
*/
/**
* Implementation of hook_node_info().
*/
function zoho_node_info() {
return array(
'zoho' => array(
'name' => t('zoho document'),
'module' => 'zoho',
'description' => t('A zoho document is a document that can be collaboratively edited using zoho. Each member of the site may create and maintain zoho documents.'),
)
);
}
/**
* Implementation of hook_perm().
*/
function zoho_perm() {
return array('edit own zoho documents', 'administer zoho settings');
}
/**
* Implementation of hook_access().
*/
function zoho_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('edit own zoho documents') && $user->uid;
}
if ($op == 'update' || $op == 'delete') {
if (user_access('edit own zoho documents') && ($user->uid == $node->uid)) {
return TRUE;
}
}
}
/**
* Implementation of hook_user().
*/
function zoho_user($type, &$edit, &$user) {
if ($type == 'view' && user_access('edit own zoho', $user)) {
$items['zoho'] = array('title' => t('zoho'),
'value' => l(t('View recent zoho entries'), "zoho/$user->uid", array('title' => t("Read @username's latest zoho documents.", array('@username' => $user->name)))),
'class' => 'zoho',
);
return array(t('History') => $items);
}
}
/**
* Implementation of hook_help().
*/
function zoho_help($section) {
switch ($section) {
case 'admin/help#zoho':
$output = '<p>'. t('The zoho module allows registered users to maintain an online list of zoho documents. Zoho documents are made up of individual posts that are time stamped and are viewed as a listing.') .'</p>';
$output .= '<p>'. t('The zoho module adds a <em>user zohos</em> navigation link to the site, which takes any visitor to a page that displays the most recent zoho entries from all the users on the site. The navigation menu has a <em>create a zoho entry</em> link (which takes you to a submission form) and a <em>view personal zoho</em> link (which displays your zoho entries as other people will see them). The zoho module also creates a <em>recent zoho posts</em> block that can be enabled.') .'</p>';
$output .= '<p>'. t('If a user has the ability to post zohos, then the import module (news aggregator) will display a zoho-it link next to each news item in its lists. Clicking on this takes the user to the zoho submission form, with the title, a link to the item, and a link to the source into the body text already in the text box, ready for the user to add a comment or explanation. This actively encourages people to add zoho entries about things they see and hear elsewhere in the website and from your syndicated partner sites.') .'</p>';
$output .= '<p>'. t('For more information please read the configuration and customization handbook <a href="@zoho">zoho page</a>.', array('@zoho' => 'http://drupal.org/handbook/modules/zoho/')) .'</p>';
return $output;
}
}
/**
* Displays an RSS feed containing recent zoho entries of a given user.
*/
function zoho_feed_user($uid = 0) {
global $user;
if ($uid) {
$account = user_load(array('uid' => $uid, 'status' => 1));
}
else {
$account = $user;
}
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'zoho' AND n.uid = %d AND n.status = 1 ORDER BY n.created DESC"), $uid, 0, variable_get('feed_default_items', 10));
$channel['title'] = $account->name ."'s Zoho documents";
$channel['link'] = url("zoho/$uid", NULL, NULL, TRUE);
$channel['description'] = $term->description;
node_feed($result, $channel);
}
/**
* Displays an RSS feed containing recent zoho entries of all users.
*/
function zoho_feed_last() {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'zoho' AND n.status = 1 ORDER BY n.created DESC"), 0, variable_get('feed_default_items', 10));
$channel['title'] = variable_get('site_name', 'Drupal') .' zohos';
$channel['link'] = url('zoho', NULL, NULL, TRUE);
$channel['description'] = $term->description;
node_feed($result, $channel);
}
/**
* Menu callback; displays a Drupal page containing recent zoho entries.
*/
function zoho_page($a = NULL, $b = NULL) {
if (is_numeric($a)) { // $a is a user ID
if ($b == 'feed') {
return zoho_feed_user($a);
}
else {
return zoho_page_user($a);
}
}
else if ($a == 'feed') {
return zoho_feed_last();
}
else if ($a === NULL) {
return zoho_page_last();
}
drupal_not_found();
}
/**
* Displays a Drupal page containing recent zoho entries of a given user.
*/
function zoho_page_user($uid) {
global $user;
$account = user_load(array((is_numeric($uid) ? 'uid' : 'name') => $uid, 'status' => 1));
if ($account->uid) {
drupal_set_title($title = t("@name's zoho documents", array('@name' => $account->name)));
if (($account->uid == $user->uid) && user_access('edit own zoho')) {
$output = '<li>'. l(t('Post new zoho document.'), "node/add/zoho") .'</li>';
}
else if ($account->uid == $user->uid) {
$output = '<li>'. t('You are not allowed to post a new zoho document.') .'</li>';
}
if ($output) {
$output = '<ul>'. $output .'</ul>';
}
else {
$output = '';
}
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.type = 'zoho' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
drupal_add_feed(url('zoho/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title)));
return $output;
}
else {
drupal_not_found();
}
}
/**
* Displays a Drupal page containing recent zoho entries of all users.
*/
function zoho_page_last() {
global $user;
$output = '';
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'zoho' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10));
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
drupal_add_feed(url('zoho/feed'), t('RSS - zohos'));
return $output;
}
/**
* Implementation of hook_form().
*/
function zoho_form(&$node) {
global $nid;
global $user;
$uidStore = $user->uid;
$iid = $_GET['iid'];
$type = node_get_types('type', $node);
if (empty($node->body)) {
/*
** If the user clicked a "zoho it" link, we load the data from the
** database and quote it in the zoho:
*/
if ($nid && $zoho = node_load($nid)) {
$node->body = '<em>'. $zoho->body .'</em> ['. l($zoho->name, "node/$nid") .']';
}
if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) {
$node->title = $item->title;
// Note: $item->description has been validated on aggregation.
$node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n";
}
}
/*
Check to see if the user has an account on zoho stored in the database
if they do log them in and display form for submitting a zoho document
if they don't display a form for the user to enter their zoho id and password
once the user logs in display form for submitting a zoho document
*/
$login = '';
$pass = '';
$result = db_query("SELECT login_id, password FROM zoho_users WHERE uid = $uidStore");
if (isset($result))
{
while ($node = db_fetch_object($result)) {
$login = $node->login_id;
$password = $node->password;
}
if ($login == '')
{
drupal_set_message('Please set your Zoho Documents login id and password. <a href="?q=zoho/settings/' . $uidStore . '">Click here</a> to set it.');
}
else
{
$form['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
$form['body_filter']['filter'] = filter_form($node->format);
$form['zoho_id'] = array('#type' => 'hidden', '#default_value' => '$login');
$form['zoho_password'] = array('#type' => 'hidden', '#default_value' => '$password');
return $form;
}
}
else
{
}
//sendValuesToZoho($form);
}
/**
* Implementation of hook_view().
*/
function zoho_view($node, $teaser = FALSE, $page = FALSE) {
if ($page) {
// Breadcrumb navigation
$breadcrumb[] = array('path' => 'zoho', 'title' => t('zoho documents'));
$breadcrumb[] = array('path' => 'zoho/'. $node->uid, 'title' => t("@name's zoho documents", array('@name' => $node->name)));
$breadcrumb[] = array('path' => 'node/'. $node->nid);
menu_set_location($breadcrumb);
}
return node_prepare($node, $teaser);
}
/**
* Implementation of hook_link().
*/
function zoho_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && $node->type == 'zoho') {
if (arg(0) != 'zoho' || arg(1) != $node->uid) {
$links['zoho_usernames_zoho'] = array(
'title' => t("@username's zoho documents", array('@username' => $node->name)),
'href' => "zoho/$node->uid",
'attributes' => array('title' => t("Read @username's latest zoho entries.", array('@username' => $node->name)))
);
}
}
return $links;
}
/**
* Implementation of hook_menu().
*/
function zoho_menu($may_cache) {
global $user;
$items = array();
$items[] = array(
'path' => 'admin/settings/zoho',
'callback' => 'drupal_get_form',
'callback arguments' => array('zoho_admin_settings'),
'title' => t('Zoho settings'),
'description' => t('Configure Zoho.'),
'access' => user_access('administer zoho settings')
);
if ($may_cache) {
$items[] = array('path' => 'zoho', 'title' => t('zoho documents'),
'callback' => 'zoho_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
$items[] = array('path' => 'zoho/'. $user->uid, 'title' => t('My Zoho documents'),
'access' => user_access('edit own zoho documents'),
'type' => MENU_DYNAMIC_ITEM);
}
$items[] = array('path' => 'zoho/settings/'. $user->uid, 'title' => t('My Zoho settings'),
'callback' => 'drupal_get_form',
'callback arguments' => array('zoho_user_settings'),
'access' => user_access('edit own zoho documents'),
'description' => t('Configure My Zoho Settings.'),
'type' => MENU_DYNAMIC_ITEM);
return $items;
}
/**
* Implementation of hook_block().
*
* Displays the most recent 10 zoho titles.
*/
function zoho_block($op = 'list', $delta = 0) {
global $user;
if ($op == 'list') {
$block[0]['info'] = t('Recent zoho documents');
return $block;
}
else if ($op == 'view') {
if (user_access('access content')) {
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = 'zoho' AND n.status = 1 ORDER BY n.created DESC"), 0, 10);
if (db_num_rows($result)) {
$block['content'] = node_title_list($result);
$block['content'] .= '<div class="more-link">'. l(t('more'), 'zoho', array('title' => t('Read the latest zoho documents.'))) .'</div>';
$block['subject'] = t('Recent zoho documents');
return $block;
}
}
}
}
function zoho_admin_settings() {
$form['zoho_api_key'] = array(
'#type' => 'textfield',
'#title' => t('Zoho API Key.'),
'#description' => t('The Zoho API key.'),
'#default_value' => variable_get('zoho_api_key', FALSE),
);
return system_settings_form($form);
}
function zoho_admin_settings_validate($form_id, $form_values) {
$path = file_directory_path();
$apikey = variable_get('zoho_api_key', FALSE);
if (file_check_directory($path, FILE_CREATE_DIRECTORY)) {
$path .= '/zoho';
drupal_set_message("Api key = " . $apikey);
//check to see if database is empty
$result = db_query("SELECT api FROM zoho_api");
while ($node = db_fetch_object($result)) {
$account_api = $node->api;
if ($account_api == '')
{
db_query("INSERT INTO zoho_api (api, account_id) VALUES ('$apikey', 1)");
}
else
{
db_query("UPDATE zoho_api SET api = '$apikey' WHERE account_id = 1");
}
}
//if it is insert entry
//if it's not update entry
}
}
function zoho_user_settings() {
$form['zoho_user_login'] = array(
'#type' => 'textfield',
'#title' => t('Zoho User Login ID.'),
'#description' => t('Your Zoho User Login ID.'),
'#default_value' => variable_get('zoho_user_login', FALSE),
);
$form['zoho_user_password'] = array(
'#type' => 'password',
'#title' => t('Zoho User Password.'),
'#description' => t('Your Zoho User Login Password.'),
'#default_value' => variable_get('zoho_user_password', FALSE),
);
return system_settings_form($form);
}
function zoho_user_settings_validate($form_id, $form_values) {
global $user;
$userUid = $user->uid;
$user_ID = variable_get('zoho_user_login', FALSE);
$user_pass = variable_get('zoho_user_password', FALSE);
$result = db_query("SELECT uid FROM zoho_users WHERE uid = $userUid");
while ($node = db_fetch_object($result)) {
$tempUid = $node->uid;
if ($tempUid == '')
{
db_query("INSERT INTO zoho_users (uid, login_id, password) VALUES ($userUid, '$user_ID', '$user_pass')");
}
else
{
db_query("UPDATE zoho_users SET login_id = '$user_ID' WHERE uid = $userUid");
db_query("UPDATE zoho_users SET password = '$user_pass' WHERE uid = $userUid");
}
}
drupal_set_message("Zoho user settings have been stored.");
}
function getApiKey()
{
$result = db_query("SELECT api FROM zoho_api");
while ($node = db_fetch_object($result)) {
$account_api = $node->api;
}
return $account_api;
}
/* this function is not in use */
function sendValuesToZoho($form_values)
{
global $user;
$uidStore = $user->uid;
$result = db_query("SELECT login_id, password FROM zoho_users WHERE uid = $uidStore");
if (isset($result))
{
while ($node = db_fetch_object($result)) {
$login = $node->login_id;
$password = $node->password;
}
}
for ($i = 0; $i < count($form_values); $i ++)
{
drupal_set_message($form_values[$i] . '<br />');
}
drupal_set_message("Values have been sent to Zoho");
drupal_set_message("zoho_id = " . $login);
drupal_set_message("zoho_pass = " . $password);
drupal_set_message("title = " . $title);
}
Any help or suggestions anyone has would be great.
Comments
i think i need to do it in this function but i'm not sure how
Am looking into this. Got a
Am looking into this. Got a few leads, but does this help? http://writer.zoho.com/public/help/writer.remoteapi/fullpage#PHP
Hi. This code works to get
Hi. This code works to get the ticket ID. You'd might want to tweak it for performance though:
Make sure you fillin the username/email and password.
Hope this helps. Let us know how it goes.
thanks so much for this i'll try it out now
:)
it worked
now i'm just trying to figure out how i can submit form values to a zoho url without redirecting the page to a zoho xml display. I have created a custom workflow with this code that triggers when a user submits a zoho document. When it submits it is redirecting the user to the xml doc with details of the record they have just submitted.
Please help me.
Trying out this code. Will
Trying out this code. Will get back to you soon. At which point in the code does the redirection happen? Do you know?
hey avadhutp
it occurs on the javascript submit that submits the form without the user having to press the button to submit. the workflow action occurs when the user submits a content piece of the type 'zoho document' but it could be triggered on the creation of any node based content type.
however
the database tables with the appropriate info would need to exist before hand. you could replace these variables with some other appropriate value to make the code work.
Is this still being worked on?
Hi scarer, is this still being worked on? Or have you abandoned development? If so, do you mind if i go ahead with this module?