vtiger Forum Index vtiger
The Honest Open Source CRM
 

Sequential Access for Accounts and Contacts
Click here to go to the original topic
Goto page 1, 2  Next
 
       vtiger Forum Index -> 3rd-Party Extensions
Previous topic :: Next topic  
Author Message
jamesmoey



Joined: 12 Aug 2005
Posts: 139
Location: Sydney, Australia

Posted: Thu Aug 07, 2008 5:47 am    Post subject: Sequential Access for Accounts and Contacts  

Hi all,

My client have just request me to release a minor feature into the community. Hopefully, you guys will like it.

The minor feature add 2 link in Accounts and Contacts Detailview screen. They are NEXT and PREVIOUS link. The patch will automatic generate these 2 link and place them in the Detailview screen. So user do not have to go back to the Listview to go to the next Accounts/Contacts.

The code is develop under 5.0.3, but should work fine in 5.0.4 (untested).

Code: Index: modules/Accounts/DetailView.php
===================================================================
--- modules/Accounts/DetailView.php   (revision 362)
+++ modules/Accounts/DetailView.php   (revision 365)
@@ -133,5 +133,10 @@
 
 $smarty->assign("SinglePane_View", $singlepane_view);
 
+require_once('include/SequenceLinkGenerator.php');
+$link = generateSequenceLink($_REQUEST['record']);
+if ($link['next']) $smarty->assign("NEXT_SEQUENCE_LINK", "<a href='index.php?module=Accounts&action=DetailView&record=".$link['next']."&parenttab=".$_REQUEST['parenttab']."'>Next</a>");
+if ($link['previous']) $smarty->assign("PREV_SEQUENCE_LINK", "<a href='index.php?module=Accounts&action=DetailView&record=".$link['previous']."&parenttab=".$_REQUEST['parenttab']."'>Previous</a>");
+
 $smarty->display("DetailView.tpl");
 ?>
Index: modules/Accounts/ListView.php
===================================================================
--- modules/Accounts/ListView.php   (revision 362)
+++ modules/Accounts/ListView.php   (revision 365)
@@ -203,7 +203,7 @@
 $start_rec = $navigation_array['start'];
 $end_rec = $navigation_array['end_val'];
 //By Raju Ends
-
+$_SESSION['SequenceLinkOFFSET'][$currentModule] = $start_rec;
 //limiting the query
 if ($start_rec ==0)
    $limit_start_rec = 0;
Index: modules/Contacts/DetailView.php
===================================================================
--- modules/Contacts/DetailView.php   (revision 362)
+++ modules/Contacts/DetailView.php   (revision 365)
@@ -149,6 +149,11 @@
 
 $smarty->assign("SinglePane_View", $singlepane_view);
 
+require_once('include/SequenceLinkGenerator.php');
+$link = generateSequenceLink($_REQUEST['record']);
+if ($link['next']) $smarty->assign("NEXT_SEQUENCE_LINK", "<a href='index.php?module=Contacts&action=DetailView&record=".$link['next']."&parenttab=".$_REQUEST['parenttab']."'>Next</a>");
+if ($link['previous']) $smarty->assign("PREV_SEQUENCE_LINK", "<a href='index.php?module=Contacts&action=DetailView&record=".$link['previous']."&parenttab=".$_REQUEST['parenttab']."'>Previous</a>");
+
 $smarty->display("DetailView.tpl");
 ?>
Index: modules/Contacts/ListView.php
===================================================================
--- modules/Contacts/ListView.php   (revision 362)
+++ modules/Contacts/ListView.php   (revision 365)
@@ -211,7 +211,7 @@
 $start_rec = $navigation_array['start'];
 $end_rec = $navigation_array['end_val'];
 //By Raju Ends
-
+$_SESSION['SequenceLinkOFFSET'][$currentModule] = $start_rec;
 //limiting the query
 if ($start_rec ==0)
    $limit_start_rec = 0;
Index: include/SequenceLinkGenerator.php
===================================================================
--- include/SequenceLinkGenerator.php   (revision 0)
+++ include/SequenceLinkGenerator.php   (revision 365)
@@ -0,0 +1,87 @@
+<?php
+
+/*********************************************************************************
+** The contents of this file are subject to the vtiger CRM Public License Version 1.0
+ * ("License"); You may not use this file except in compliance with the License
+ * Developer of the Code is James Moey <james#sitek.com.au>
+ * Copyright (C) Sitek.
+ * All Rights Reserved.
+ *
+ ********************************************************************************/
+
+  function generateSequenceLink($currentid) {
+    require_once('modules/CustomView/CustomView.php');
+    global $currentModule, $adb;
+    require_once("modules/$currentModule/$currentModule.php");
+   
+    $oCustomView = new CustomView($currentModule);
+    $viewid = $oCustomView->getViewId($currentModule);
+    if($viewid != "0") {
+      $listquery = getListQuery($currentModule);
+      $query = $oCustomView->getModifiedCvListQuery($viewid,$listquery,$currentModule);
+    } else {
+      $query = getListQuery($currentModule);
+    }
+   
+    $end = stripos($query, " FROM ");
+    $query = "SELECT vtiger_crmentity.crmid" . substr($query, $end);
+   
+    $focus = new $currentModule();
+    if($_SESSION['lvs'][$currentModule] && $_SESSION['lvs'][$currentModule]['sorder'] && $_SESSION['lvs'][$currentModule]['sortby']) {
+      $sorder = $_SESSION['lvs'][$currentModule]['sorder'];
+      $order_by = $_SESSION['lvs'][$currentModule]['sortby'];
+    } else {
+      $sorder = $focus->getSortOrder();
+      $order_by = $focus->getOrderBy();
+    }
+   
+    if(isset($order_by) && $order_by != '') { 
+      if($order_by == 'smownerid') {
+        if( $adb->dbType == "pgsql") $query .= ' GROUP BY user_name';
+        $query .= ' ORDER BY user_name '.$sorder;
+      } else {
+        $tablename = getTableNameForField($currentModule,$order_by);
+        $tablename = (($tablename != '')?($tablename."."):'');
+        if( $adb->dbType == "pgsql") $query .= ' GROUP BY '.$tablename.$order_by; 
+        $query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder;
+      }
+    }
+
+    if (isset($_SESSION['SequenceLinkOFFSET'][$currentModule])) {
+      $savequery = $query;
+      $query .= ' LIMIT ' . $_SESSION['SequenceLinkOFFSET'][$currentModule] . ',25 ';
+    }
+   
+    $result = generateSequenceLink_runQuery($query, $currentid);
+    if ($result === false) {
+      unset($_SESSION['SequenceLinkOFFSET'][$currentModule]);
+      return generateSequenceLink_runQuery($savequery, $currentid);
+    } else return $result;
+  }

+  function generateSequenceLink_runQuery($query, $currentid) {
+    global $currentModule, $adb;
+   
+    $list_result = $adb->query($query);
+    while($row = $adb->fetch_array($list_result)) {
+      $ids[] = $row["crmid"];
+    }
+   
+    $previousid = 0;
+    $nextid = 0;
+    $found = false;
+    foreach ($ids as $key=>$crmid) {
+      if ($crmid == $currentid) {
+        if (isset($ids[$key+1])) $nextid = $ids[$key+1];
+        if (isset($_SESSION['SequenceLinkOFFSET'][$currentModule])) $_SESSION['SequenceLinkOFFSET'][$currentModule] = $_SESSION['SequenceLinkOFFSET'][$currentModule] + $key - 2;
+        else $_SESSION['SequenceLinkOFFSET'][$currentModule] = $key - 2;
+        if ($_SESSION['SequenceLinkOFFSET'][$currentModule] < 0) $_SESSION['SequenceLinkOFFSET'][$currentModule] = 0;
+        $found = true;
+        break;
+      }
+      $previousid = $crmid;
+    }
+    if (! $found) return false;
+    else return array("previous"=>$previousid, "next"=>$nextid);
+  }
+?>

Index: Smarty/templates/DetailView.tpl
===================================================================
--- Smarty/templates/DetailView.tpl   (revision 362)
+++ Smarty/templates/DetailView.tpl   (revision 365)
@@ -127,10 +127,21 @@
       <!-- PUBLIC CONTENTS STARTS-->
       <div class="small" style="padding:10px" >
       
-      <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%"><tr><td>      
-       <span class="dvHeaderText">[ {$ID} ] {$NAME} -  {$APP[$SINGLE_MOD]} {$APP.LBL_INFORMATION}</span>&nbsp;&nbsp;<span id="vtbusy_info" style="display:none;" valign="bottom"><img src="{$IMAGE_PATH}vtbusy.gif" border="0"></span><span id="vtbusy_info" style="visibility:hidden;" valign="bottom"><img src="{$IMAGE_PATH}vtbusy.gif" border="0"></span></td><td>&nbsp;</td></tr>
-       <tr height=20><td>{$UPDATEINFO}</td></tr>
-       </table>         
+      <table align="center" border="0" cellpadding="0" cellspacing="0" width="95%">
+      <tr>
+        <td>      
+            <span class="dvHeaderText">[ {$ID} ] {$NAME} -  {$APP[$SINGLE_MOD]} {$APP.LBL_INFORMATION}</span>&nbsp;&nbsp;
+          <span id="vtbusy_info" style="display:none;" valign="bottom">
+            <img src="{$IMAGE_PATH}vtbusy.gif" border="0">
+          </span>
+          <span id="vtbusy_info" style="visibility:hidden;" valign="bottom">
+            <img src="{$IMAGE_PATH}vtbusy.gif" border="0">
+          </span>
+        </td>
+        <td>< {if $PREV_SEQUENCE_LINK}{$PREV_SEQUENCE_LINK}{else}Previous{/if} - {if $NEXT_SEQUENCE_LINK}{$NEXT_SEQUENCE_LINK}{else}Next{/if} ></td>
+      </tr>
+        <tr height=20><td>{$UPDATEINFO}</td></tr>
+      </table>         
       <br>
       
       <!-- Account details tabs -->
Back to top  
mvsn



Joined: 29 Oct 2006
Posts: 83
Location: Ontario, Canada

Posted: Thu Aug 07, 2008 1:01 pm    Post subject: Sequential Access for Accounts and Contacts  

Great work. Definitely a useful feature! When I have a moment, I will test if on 5.0.4
Back to top  
joebordes



Joined: 18 Aug 2006
Posts: 1100
Location: Alicante/Valencia, Spain

Posted: Thu Aug 07, 2008 4:33 pm    Post subject: Re: Sequential Access for Accounts and Contacts  

Hi,

Nice patch, thanks for sharing.
I have upgraded it to 5.0.4 with a few tweaks.
I have made it translatable and changed the text for the theme graphic buttons.
But I think I have found an error, or have created one. Can you please verify before I upload the code.

If you select the 2 item in the list view, the previous button is deactivated when I should be able to go to the first item. I then go forward and back and I can get to the first element.

Thanks, Joe
TSolucio
Back to top  
jamesmoey



Joined: 12 Aug 2005
Posts: 139
Location: Sydney, Australia

Posted: Fri Aug 08, 2008 5:01 am    Post subject: Re: Sequential Access for Accounts and Contacts  

You want to post your code here?
Back to top  
joebordes



Joined: 18 Aug 2006
Posts: 1100
Location: Alicante/Valencia, Spain

Posted: Fri Aug 08, 2008 7:21 am    Post subject: Re: Sequential Access for Accounts and Contacts  

Hi,

I was thinking of uploading the code to the timecards forge project and create a link here. But I have no problem in uploading it here as you did.

Could you reproduce the error on your site, or does that happen only on my code?

Joe
TSolucio
Back to top  
joebordes



Joined: 18 Aug 2006
Posts: 1100
Location: Alicante/Valencia, Spain

Posted: Fri Aug 08, 2008 7:22 am    Post subject: Re: Sequential Access for Accounts and Contacts  

Do you have any problem with me uploading the 5.0.4 adaption here?

Joe
TSolucio
Back to top  
jamesmoey



Joined: 12 Aug 2005
Posts: 139
Location: Sydney, Australia

Posted: Fri Aug 08, 2008 2:03 pm    Post subject: Re: Sequential Access for Accounts and Contacts  

No, I don't have the problem you just describe. Of course, it is fine, that you post the code yet. I have no problem with that.
Back to top  
joebordes



Joined: 18 Aug 2006
Posts: 1100
Location: Alicante/Valencia, Spain

Posted: Sun Aug 10, 2008 11:08 pm    Post subject: Re: Sequential Access for Accounts and Contacts  

Hi,

Adapted patch to 5.0.4
Changed the text for graphic buttons
Added Start and End buttons
Generalized the code to make it easily added to any other entity.

I will upload this code to the timecards forge project whenever I can.

Joe
TSolucio
Back to top  
hkalilinks



Joined: 04 Aug 2008
Posts: 9

Posted: Mon Aug 11, 2008 4:18 am    Post subject: This is what I'm looking for  

This is what I'm looking for, thank you
Back to top  
jamesmoey



Joined: 12 Aug 2005
Posts: 139
Location: Sydney, Australia

Posted: Mon Aug 11, 2008 4:42 am    Post subject: Re: Sequential Access for Accounts and Contacts  

Do you still have the problem you describe previously?
Back to top  
 
       vtiger Forum Index -> 3rd-Party Extensions Goto page 1, 2  Next
Page 1 of 2


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.15 © 2001, 2002 phpBB Group