Skip to main content

How to create a new module for vtiger...

Recently, I had to create a new module for vtigerCRM for my client in current working place. I did search in many places including the official vtiger sites, but couldn’t find a better documentation for my purpose. The latest vtiger version at that time was 5.0.3. Because I had some experience doing lots of core modifications for this system, I did decide to read the source code and find how to add a new module. Finally, I could create a new module and started the project. So, I thought it will be a good thing to write some thing on my blog about this topic, so that others who want to do this thing can read. Given below is a brief description about how to create a new module for vtiger CRM 5.0.3. Source code of this example module is also available to Download.

Step 01: Creating the module directory and minimum required files.


Create a directory called “newModule” inside your vtiger modules directory, or any other name that you prefer. Now, module index file should be created. Create a new file called “index.php” inside the “newModule” directory and insert following code.



And next the “ListView.php” file should be created. This name “ListView” is not compulsory. In fact, you can include any script that you prefer to run when the users are entering to the module. The content of the “ListView.php” is as below.



And now we should create the newModule class file which act as the Model for this module. Actually you can develop this module without following the MVC pattern. But it’s strongly recommended to follow these design patterns if your project is a real one. The content of the “newModule.php” is as follows.



At this point, we have finished developing the Model and Controller. Now the view file (at least one) should be created. Vtiger uses Smarty as a presentation framework. So, the view is a Smarty template. In our example – “newModule.tpl” , and it’s content is given below.



All the required files for our new module were created now. The next thing we should do is attach this module to the System.

Step 02: Attach new module to the vtiger.


At the moment, there is not any automated module management (install, uninstall etc...) facilities in vtiger. Therefore, you can follow the steps given below to attach our new module to the system.

Basically, we should edit following files and inset the some data to the following tables to achieve this goal.

Files->

parent_tabdata.php

tabdata.php

include/language/en_us.lang.php

Tables->

vtiger_tab, vtiger_parenttab, vtiger_parenttabrel

parent_tabdata.php:

In this file, there is an array called “$parent_tab_info_array”. An element should be entered to this array to show our module in the menu. For this example I will edit the array as given below.

Befor:

$parent_tab_info_array=array(1=>'My Home Page',2=>'Marketing',3=>'Sales',4=>'Support',

5=>'Analytics',6=>'Inventory',7=>'Tools',8=>'Settings',9=>'Nadeeth',10=>'newModule');

After:

$parent_tab_info_array=array(1=>'My Home Page',2=>'Marketing',3=>'Sales',4=>'Support',5=>'Analytics',

6=>'Inventory',7=>'Tools',8=>'Settings',9=>'Nadeeth',10=>'newModule');

At the end, new element “10=>'newModule'” is added.

Tabdata.php:

In this file there is an array called “$tab_info_array” which contains the details about sub menus. New element should be added into this array for our new module.

Before:

$tab_info_array=array('Home'=>3,'Leads'=>7,'Accounts'=>6,'Contacts'=>4,

'Potentials'=>2,'Notes'=>8,'Calendar'=>9,'Emails'=>10,'HelpDesk'=>13,

'Products'=>14,'Dashboard'=>1,'Faq'=>15,'Events'=>16,'Vendors'=>18,

'PriceBooks'=>19,'Quotes'=>20,'PurchaseOrder'=>21,'SalesOrder'=>22,

'Invoice'=>23,'Rss'=>24,'Reports'=>25,'Campaigns'=>26,'Portal'=>27,

'Webmails'=>28,'Users'=>29, 'Nadeeth'=>30);

After:

$tab_info_array=array('Home'=>3,'Leads'=>7,'Accounts'=>6,'Contacts'=>4,

'Potentials'=>2,'Notes'=>8,'Calendar'=>9,'Emails'=>10,'HelpDesk'=>13,

'Products'=>14,'Dashboard'=>1,'Faq'=>15,'Events'=>16,'Vendors'=>18,

'PriceBooks'=>19,'Quotes'=>20,'PurchaseOrder'=>21,'SalesOrder'=>22,

'Invoice'=>23,'Rss'=>24,'Reports'=>25,'Campaigns'=>26,'Portal'=>27,

'Webmails'=>28,'Users'=>29, 'Nadeeth'=>30, 'newModule'=>31);

See, the element 'newModule'=>31 is added to the end. Remember, these indexes (in this case 31) should be modified according to the values in your system.

include/language/en_us.lang.php:

Now the language file should be modified. Just enter a new element for $app_strings array. For our example, please add the element given below.

'newModule' => 'newModule',

Next step is to add the data related to our module to the tables - vtiger_tab, vtiger_parenttab, vtiger_parenttabrel. The queries given below will do that for you. Here also, please remember to change the values to match with the existing data of your system.

INSERT INTO `vtiger_tab` (`tabid`, `name`, `presence`, `tabsequence`, `tablabel`, `modifiedby`, `modifiedtime`, customized`, `ownedby`) VALUES(31, 'newModule', 1, 31, 'newModule', NULL, NULL, NULL, NULL);

INSERT INTO `vtiger_parenttab` (`parenttabid`, `parenttab_label`, `sequence`, `visible`) VALUES(10, 'newModule', 10, 0);

INSERT INTO `vtiger_parenttabrel` (`parenttabid`, `tabid`, `sequence`) VALUES(10, 31, 1);

Now, we have finished crating new module. Log into the system and you can see there is a new menu in the menu bar.



And new module is installed.

Comments

  1. Great article, but just one problem; why did you have to put the code examples as images? Surely copy-and-paste-able text would have been better...

    ReplyDelete
  2. Yes, what you say is correct. But you can download the source code of this example from the download link in the beginning of the article.

    http://nadeeth.info/blog/sites/default/files/newModule.zip

    Thanks for your comment.

    ReplyDelete
  3. I personally use Code Highlighter:

    http://code.google.com/p/syntaxhighlighter/

    It's javascript and it's fast. Give it a try ;)
    Bye!

    ReplyDelete
  4. Thanks Chris, I did see that. It's a nice tool.I will give it a try next time...

    ReplyDelete
  5. i am getting an error and new tab is not shown :

    Warning: Invalid argument supplied for foreach() in D:\wamp\www\v-tiger\include\utils\CommonUtils.php on line 1306

    kindly help

    deepsingh

    ReplyDelete
  6. Can you contact me in emails..? send your mail address using the contact form of this site... Thx...

    ReplyDelete
  7. Hi Nadeeth,

    First of all thank you very much for posting this article.

    While I was following your article for creating a Module in vtigerCRM 5.0.4, I got this strange error.

    Invalid argument supplied for foreach() in /var/www/vtigercrm/include/utils/CommonUtils.php on line 1306

    Can you please let me know where I went wrong.

    Thanks & Regards,
    Sreedhar

    ReplyDelete
  8. As I have mentioned in the beginning of this article, this module development tasks were done by me for vtiger 5.0.3 some time ago. And I haven't check it's compatibility with the newer versions. There may be some little differences, which can easily find reading the code and database.

    After all, I will try to find some time to do some works to find the changes in new version.

    Thanks for your comment. Keep in touch...

    ReplyDelete
  9. Thank you for you post, it's very useful.

    ReplyDelete
  10. thx...it helps me a lot....

    Regards,
    Kumar

    ReplyDelete
  11. in parent_tabdata.php file:
    one more to configure..

    $parent_child_tab_rel_array=array(1=>array(3,9,28,),2=>array(26,6,4,28,7,9,8,),3=>array(7,6,4,2,20,22,23,14,19,8,9,),4=>array(13,15,6,4,14,8,28,9,),5=>array(1,25,),6=>array(14,18,19,21,22,20,23,),7=>array(24,27,8,),8=>array(),10=>array(31,),);

    at the end, we added 10=>array(31,)

    ReplyDelete
  12. Thanks a ton Nadeeth,

    I have successfully installed the new module.. (with few tweaks because i am using vtiger 5.1.0)

    Cheers!!

    ReplyDelete
  13. it's a very good tutorial, thanks.

    ReplyDelete
  14. thanks u..
    it helps me a lot...

    ReplyDelete
  15. i spent my whole day trying to add a new tab in the crm but failed..
    until i found your guide thanks! keep it up

    ReplyDelete
  16. Hello
    My version: 5.1.
    I could install this well, once installed, I start the application , and I can see the "newModule" new menu option onto the menu bar, but, when I push this new link, an alert message appears:

    "newModule module is not active!"

    Please, could you tell me how should I activate the module?

    Thanks a lot.

    ReplyDelete
  17. display newMudual but click onthis link error will be generate
    "Module name is missing. Please check the module name."
    plz rep me

    ReplyDelete
  18. I appreciate your post to create a new module for vtiger, thanks for sharing the post, i would like to hear more about this in future

    ReplyDelete
  19. request help please

    I have followed all the steps as guide - but the final result says

    newModule module is not active

    could anyone advise as how to resolve this issue, am working on vtigercrm 5.2.0

    thanks

    ReplyDelete
  20. Thnx a lot...

    It was helpful... :)

    ReplyDelete
  21. Hi,
    I want to create 3 pieces of the accounts module.
    Possible?
    Are you can help me

    ReplyDelete
  22. Hi nadeeth,

    Your blog helped me a lot.

    Thanks and Regards
    Baibhav Singh

    ReplyDelete
  23. good job dude... but couldnt find the language and $app_string...
    please let me know the procedure ASAP
    thanks a lot

    ReplyDelete
  24. Thanks brother..........

    ReplyDelete
  25. Hi, i would like to ask the "insert into" query is supposed to be written in which script? thanks.

    ReplyDelete
  26. hi,i have tried to create a new module by using the above code,every thing is OK,but result will not come,it means,the newModule will not shown in menu am using vtigercrm5.4.0 ,please help me to completion of this work through email,my mail id is vtigercrmtool@gmail.com,plz send the answer to mail id ,if you have possible


    Thanks& Regards.

    ReplyDelete
  27. Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to MySQL server on 'localhost' (10061) in C:\Program Files\vtigercrm-5.4.0\apache\htdocs\vtigerCRM\adodb\drivers\adodb-mysql.inc.php on line 373
    i got this after sign in into vtiger

    ReplyDelete
  28. please tel me how
    to rectify that error

    ReplyDelete
  29. Whats wrong ? why do i get an error message
    Warning: Invalid argument supplied for foreach() in D:\wamp\www\v-tiger\include\utils\CommonUtils.php on line 1306 ??

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. Hi, I can't see the new module in the menu bar, what can i do, Im using vtiger 5.4.0
    thank you

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  32. Thank, i solved problem, by replacing
    this $app_strings = Array('HELLO_WORLD' => 'Hello World');
    by this
    $mod_strings = Array('HELLO_WORLD' => 'Hello World');
    in lang file

    ReplyDelete
  33. Thank, i solved problem, by replacing
    this $app_strings = Array('HELLO_WORLD' => 'Hello World');
    by this
    $mod_strings = Array('HELLO_WORLD' => 'Hello World');
    in lang file

    ReplyDelete
    Replies
    1. Thank you very much for sharing what you found...

      Delete
  34. Good, it's works on my vtiger 5.4.0
    How can i add my own field instead hello world!?
    for example text field, check box, and it's must work of couse with database
    Thank's

    ReplyDelete
    Replies
    1. Actually I did this five years ago.. :-) So, at the moment I don't remember the way I added new fields. But I remember I did many modifications like those. Let me figure it out and let you know when I am free.

      Thanks.

      Delete
  35. Hi, awesome tutorial, btw can't find the source code file :(

    ReplyDelete
  36. We are a team of experts who have a long and well experience in different open source systems, especially in vTiger ,

    Our long experience gave us the opportunity to start on creating and developing to make vTiger a better CRM and to help vTiger users to be able to organize their business what ever it was,

    By using our new modules and integrations you will be able to focus your manpower on bringing new opportunities and leave the rest to your CRM

    ReplyDelete
    Replies
    1. Hello Noor, I am looking forward for creating a Module for vTiger 6.1.
      If you can be of any help, please get in touch at jiteen@technoscore.net OR Skype me at : suntec.jiteen

      Delete
  37. http://nadeeth.info/blog/sites/default/files/newModule.zip
    ts not found

    ReplyDelete
  38. Hello Nadeth. First of all AWESOME TUTS.
    I am facing some issues in creating a vTiger Module for vTiger 6.1. I would appreciate if you can share your Email or Skype.
    Please get in touch at jiteen@technoscore.net or Skype : suntec.jiteen

    ReplyDelete
  39. Hi everyone
    I'm very confused that is where put these files ?. We put all files in C:\wamp\www\crm\modules\newModule but i don't no that location is right or wrong ?. and also talk me how it can be run ?

    ReplyDelete
  40. Hello there! I found your blog using on Google. This is a really well written article. I will be sure to bookmark it and return to read more of your useful information. I’ll definitely return. Thanks for the post.
    Handicap Tricycle Price
    Deluxe Tricycle Handicapped

    Keep Posting:)

    ReplyDelete

Post a Comment

Popular posts from this blog

De Morgan's Laws in Programming

Recently, while I was reviewing some codes, I saw there were some conditional statements that check for the same condition but written in different ways. Most of these statements were written with common sense without using any mathematical analysis, since those are too simple to go for a more formal approach. The two identical conditional statements that has been written in different ways are given below.

01)

if ($comment['deleted'] == '1' || $comment['approved'] == '0') {
                unset($conversationsArray[$key]);
} else {
               ++$count;
}

02)

if ($comment['deleted'] == '0' && $comment['approved'] == '1') {
               ++$count;             
} else {
             unset($conversationsArray[$key]);
}

Obviously, the above lines say that the inverse of the first condition is equals to the second condition and vice versa. That is...

 ($comment['deleted'] == '1' || $comment['ap…

How to create a simple Web Crawler

Web crawlers are used to extract information from web sites for many purposes.

The simple example given here accepts an URL and exposes some functions to query the content of the page.

To check out the source code of this example : https://github.com/nadeeth/crawler

If you are going to make any improvements to this code, I recommend you to follow TDD and use the unit test class in the code.

Step 1 : Create the class, init function and required attributes In this example, xpath is used for querying the given web page. There is an attribute to hold the page url, and another to hold the xpath object of the loaded page.

The init() function initializes the xpath object for the page URL assigned to url attribute.

class Crawler { public $url = false; protected $xpath = false; public function init() { $xmlDoc = new DOMDocument(); @$xmlDoc->loadHTML(file_get_contents($this->url)); $this->xpath = new DOMXPath(@$xmlDoc); } } In the next two ste…